PluginProbe ʕ •ᴥ•ʔ
SiteOrigin CSS / 1.6.3
SiteOrigin CSS v1.6.3
1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.10 1.5.11 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0
so-css / js / css.js
so-css / js Last commit date
URI.js 9 years ago URI.min.js 6 years ago css.js 4 years ago css.min.js 4 years ago csslint.js 9 years ago csslint.min.js 1 year ago editor.js 2 years ago editor.min.js 1 year ago inspector.js 1 year ago inspector.min.js 1 year ago jquery.sizes.js 11 years ago jquery.sizes.min.js 6 years ago specificity.js 11 years ago specificity.min.js 6 years ago
css.js
9057 lines
1 (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 'use strict'
3
4 exports.byteLength = byteLength
5 exports.toByteArray = toByteArray
6 exports.fromByteArray = fromByteArray
7
8 var lookup = []
9 var revLookup = []
10 var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
11
12 var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
13 for (var i = 0, len = code.length; i < len; ++i) {
14 lookup[i] = code[i]
15 revLookup[code.charCodeAt(i)] = i
16 }
17
18 // Support decoding URL-safe base64 strings, as Node.js does.
19 // See: https://en.wikipedia.org/wiki/Base64#URL_applications
20 revLookup['-'.charCodeAt(0)] = 62
21 revLookup['_'.charCodeAt(0)] = 63
22
23 function getLens (b64) {
24 var len = b64.length
25
26 if (len % 4 > 0) {
27 throw new Error('Invalid string. Length must be a multiple of 4')
28 }
29
30 // Trim off extra bytes after placeholder bytes are found
31 // See: https://github.com/beatgammit/base64-js/issues/42
32 var validLen = b64.indexOf('=')
33 if (validLen === -1) validLen = len
34
35 var placeHoldersLen = validLen === len
36 ? 0
37 : 4 - (validLen % 4)
38
39 return [validLen, placeHoldersLen]
40 }
41
42 // base64 is 4/3 + up to two characters of the original data
43 function byteLength (b64) {
44 var lens = getLens(b64)
45 var validLen = lens[0]
46 var placeHoldersLen = lens[1]
47 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
48 }
49
50 function _byteLength (b64, validLen, placeHoldersLen) {
51 return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
52 }
53
54 function toByteArray (b64) {
55 var tmp
56 var lens = getLens(b64)
57 var validLen = lens[0]
58 var placeHoldersLen = lens[1]
59
60 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
61
62 var curByte = 0
63
64 // if there are placeholders, only get up to the last complete 4 chars
65 var len = placeHoldersLen > 0
66 ? validLen - 4
67 : validLen
68
69 var i
70 for (i = 0; i < len; i += 4) {
71 tmp =
72 (revLookup[b64.charCodeAt(i)] << 18) |
73 (revLookup[b64.charCodeAt(i + 1)] << 12) |
74 (revLookup[b64.charCodeAt(i + 2)] << 6) |
75 revLookup[b64.charCodeAt(i + 3)]
76 arr[curByte++] = (tmp >> 16) & 0xFF
77 arr[curByte++] = (tmp >> 8) & 0xFF
78 arr[curByte++] = tmp & 0xFF
79 }
80
81 if (placeHoldersLen === 2) {
82 tmp =
83 (revLookup[b64.charCodeAt(i)] << 2) |
84 (revLookup[b64.charCodeAt(i + 1)] >> 4)
85 arr[curByte++] = tmp & 0xFF
86 }
87
88 if (placeHoldersLen === 1) {
89 tmp =
90 (revLookup[b64.charCodeAt(i)] << 10) |
91 (revLookup[b64.charCodeAt(i + 1)] << 4) |
92 (revLookup[b64.charCodeAt(i + 2)] >> 2)
93 arr[curByte++] = (tmp >> 8) & 0xFF
94 arr[curByte++] = tmp & 0xFF
95 }
96
97 return arr
98 }
99
100 function tripletToBase64 (num) {
101 return lookup[num >> 18 & 0x3F] +
102 lookup[num >> 12 & 0x3F] +
103 lookup[num >> 6 & 0x3F] +
104 lookup[num & 0x3F]
105 }
106
107 function encodeChunk (uint8, start, end) {
108 var tmp
109 var output = []
110 for (var i = start; i < end; i += 3) {
111 tmp =
112 ((uint8[i] << 16) & 0xFF0000) +
113 ((uint8[i + 1] << 8) & 0xFF00) +
114 (uint8[i + 2] & 0xFF)
115 output.push(tripletToBase64(tmp))
116 }
117 return output.join('')
118 }
119
120 function fromByteArray (uint8) {
121 var tmp
122 var len = uint8.length
123 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
124 var parts = []
125 var maxChunkLength = 16383 // must be multiple of 3
126
127 // go through the array every three bytes, we'll deal with trailing stuff later
128 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
129 parts.push(encodeChunk(
130 uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
131 ))
132 }
133
134 // pad the end with zeros, but make sure to not forget the extra bytes
135 if (extraBytes === 1) {
136 tmp = uint8[len - 1]
137 parts.push(
138 lookup[tmp >> 2] +
139 lookup[(tmp << 4) & 0x3F] +
140 '=='
141 )
142 } else if (extraBytes === 2) {
143 tmp = (uint8[len - 2] << 8) + uint8[len - 1]
144 parts.push(
145 lookup[tmp >> 10] +
146 lookup[(tmp >> 4) & 0x3F] +
147 lookup[(tmp << 2) & 0x3F] +
148 '='
149 )
150 }
151
152 return parts.join('')
153 }
154
155 },{}],2:[function(require,module,exports){
156
157 },{}],3:[function(require,module,exports){
158 (function (Buffer){
159 /*!
160 * The buffer module from node.js, for the browser.
161 *
162 * @author Feross Aboukhadijeh <https://feross.org>
163 * @license MIT
164 */
165 /* eslint-disable no-proto */
166
167 'use strict'
168
169 var base64 = require('base64-js')
170 var ieee754 = require('ieee754')
171
172 exports.Buffer = Buffer
173 exports.SlowBuffer = SlowBuffer
174 exports.INSPECT_MAX_BYTES = 50
175
176 var K_MAX_LENGTH = 0x7fffffff
177 exports.kMaxLength = K_MAX_LENGTH
178
179 /**
180 * If `Buffer.TYPED_ARRAY_SUPPORT`:
181 * === true Use Uint8Array implementation (fastest)
182 * === false Print warning and recommend using `buffer` v4.x which has an Object
183 * implementation (most compatible, even IE6)
184 *
185 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
186 * Opera 11.6+, iOS 4.2+.
187 *
188 * We report that the browser does not support typed arrays if the are not subclassable
189 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
190 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
191 * for __proto__ and has a buggy typed array implementation.
192 */
193 Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
194
195 if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
196 typeof console.error === 'function') {
197 console.error(
198 'This browser lacks typed array (Uint8Array) support which is required by ' +
199 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
200 )
201 }
202
203 function typedArraySupport () {
204 // Can typed array instances can be augmented?
205 try {
206 var arr = new Uint8Array(1)
207 arr.__proto__ = { __proto__: Uint8Array.prototype, foo: function () { return 42 } }
208 return arr.foo() === 42
209 } catch (e) {
210 return false
211 }
212 }
213
214 Object.defineProperty(Buffer.prototype, 'parent', {
215 enumerable: true,
216 get: function () {
217 if (!Buffer.isBuffer(this)) return undefined
218 return this.buffer
219 }
220 })
221
222 Object.defineProperty(Buffer.prototype, 'offset', {
223 enumerable: true,
224 get: function () {
225 if (!Buffer.isBuffer(this)) return undefined
226 return this.byteOffset
227 }
228 })
229
230 function createBuffer (length) {
231 if (length > K_MAX_LENGTH) {
232 throw new RangeError('The value "' + length + '" is invalid for option "size"')
233 }
234 // Return an augmented `Uint8Array` instance
235 var buf = new Uint8Array(length)
236 buf.__proto__ = Buffer.prototype
237 return buf
238 }
239
240 /**
241 * The Buffer constructor returns instances of `Uint8Array` that have their
242 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
243 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
244 * and the `Uint8Array` methods. Square bracket notation works as expected -- it
245 * returns a single octet.
246 *
247 * The `Uint8Array` prototype remains unmodified.
248 */
249
250 function Buffer (arg, encodingOrOffset, length) {
251 // Common case.
252 if (typeof arg === 'number') {
253 if (typeof encodingOrOffset === 'string') {
254 throw new TypeError(
255 'The "string" argument must be of type string. Received type number'
256 )
257 }
258 return allocUnsafe(arg)
259 }
260 return from(arg, encodingOrOffset, length)
261 }
262
263 // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
264 if (typeof Symbol !== 'undefined' && Symbol.species != null &&
265 Buffer[Symbol.species] === Buffer) {
266 Object.defineProperty(Buffer, Symbol.species, {
267 value: null,
268 configurable: true,
269 enumerable: false,
270 writable: false
271 })
272 }
273
274 Buffer.poolSize = 8192 // not used by this implementation
275
276 function from (value, encodingOrOffset, length) {
277 if (typeof value === 'string') {
278 return fromString(value, encodingOrOffset)
279 }
280
281 if (ArrayBuffer.isView(value)) {
282 return fromArrayLike(value)
283 }
284
285 if (value == null) {
286 throw TypeError(
287 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
288 'or Array-like Object. Received type ' + (typeof value)
289 )
290 }
291
292 if (isInstance(value, ArrayBuffer) ||
293 (value && isInstance(value.buffer, ArrayBuffer))) {
294 return fromArrayBuffer(value, encodingOrOffset, length)
295 }
296
297 if (typeof value === 'number') {
298 throw new TypeError(
299 'The "value" argument must not be of type number. Received type number'
300 )
301 }
302
303 var valueOf = value.valueOf && value.valueOf()
304 if (valueOf != null && valueOf !== value) {
305 return Buffer.from(valueOf, encodingOrOffset, length)
306 }
307
308 var b = fromObject(value)
309 if (b) return b
310
311 if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
312 typeof value[Symbol.toPrimitive] === 'function') {
313 return Buffer.from(
314 value[Symbol.toPrimitive]('string'), encodingOrOffset, length
315 )
316 }
317
318 throw new TypeError(
319 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
320 'or Array-like Object. Received type ' + (typeof value)
321 )
322 }
323
324 /**
325 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
326 * if value is a number.
327 * Buffer.from(str[, encoding])
328 * Buffer.from(array)
329 * Buffer.from(buffer)
330 * Buffer.from(arrayBuffer[, byteOffset[, length]])
331 **/
332 Buffer.from = function (value, encodingOrOffset, length) {
333 return from(value, encodingOrOffset, length)
334 }
335
336 // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
337 // https://github.com/feross/buffer/pull/148
338 Buffer.prototype.__proto__ = Uint8Array.prototype
339 Buffer.__proto__ = Uint8Array
340
341 function assertSize (size) {
342 if (typeof size !== 'number') {
343 throw new TypeError('"size" argument must be of type number')
344 } else if (size < 0) {
345 throw new RangeError('The value "' + size + '" is invalid for option "size"')
346 }
347 }
348
349 function alloc (size, fill, encoding) {
350 assertSize(size)
351 if (size <= 0) {
352 return createBuffer(size)
353 }
354 if (fill !== undefined) {
355 // Only pay attention to encoding if it's a string. This
356 // prevents accidentally sending in a number that would
357 // be interpretted as a start offset.
358 return typeof encoding === 'string'
359 ? createBuffer(size).fill(fill, encoding)
360 : createBuffer(size).fill(fill)
361 }
362 return createBuffer(size)
363 }
364
365 /**
366 * Creates a new filled Buffer instance.
367 * alloc(size[, fill[, encoding]])
368 **/
369 Buffer.alloc = function (size, fill, encoding) {
370 return alloc(size, fill, encoding)
371 }
372
373 function allocUnsafe (size) {
374 assertSize(size)
375 return createBuffer(size < 0 ? 0 : checked(size) | 0)
376 }
377
378 /**
379 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
380 * */
381 Buffer.allocUnsafe = function (size) {
382 return allocUnsafe(size)
383 }
384 /**
385 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
386 */
387 Buffer.allocUnsafeSlow = function (size) {
388 return allocUnsafe(size)
389 }
390
391 function fromString (string, encoding) {
392 if (typeof encoding !== 'string' || encoding === '') {
393 encoding = 'utf8'
394 }
395
396 if (!Buffer.isEncoding(encoding)) {
397 throw new TypeError('Unknown encoding: ' + encoding)
398 }
399
400 var length = byteLength(string, encoding) | 0
401 var buf = createBuffer(length)
402
403 var actual = buf.write(string, encoding)
404
405 if (actual !== length) {
406 // Writing a hex string, for example, that contains invalid characters will
407 // cause everything after the first invalid character to be ignored. (e.g.
408 // 'abxxcd' will be treated as 'ab')
409 buf = buf.slice(0, actual)
410 }
411
412 return buf
413 }
414
415 function fromArrayLike (array) {
416 var length = array.length < 0 ? 0 : checked(array.length) | 0
417 var buf = createBuffer(length)
418 for (var i = 0; i < length; i += 1) {
419 buf[i] = array[i] & 255
420 }
421 return buf
422 }
423
424 function fromArrayBuffer (array, byteOffset, length) {
425 if (byteOffset < 0 || array.byteLength < byteOffset) {
426 throw new RangeError('"offset" is outside of buffer bounds')
427 }
428
429 if (array.byteLength < byteOffset + (length || 0)) {
430 throw new RangeError('"length" is outside of buffer bounds')
431 }
432
433 var buf
434 if (byteOffset === undefined && length === undefined) {
435 buf = new Uint8Array(array)
436 } else if (length === undefined) {
437 buf = new Uint8Array(array, byteOffset)
438 } else {
439 buf = new Uint8Array(array, byteOffset, length)
440 }
441
442 // Return an augmented `Uint8Array` instance
443 buf.__proto__ = Buffer.prototype
444 return buf
445 }
446
447 function fromObject (obj) {
448 if (Buffer.isBuffer(obj)) {
449 var len = checked(obj.length) | 0
450 var buf = createBuffer(len)
451
452 if (buf.length === 0) {
453 return buf
454 }
455
456 obj.copy(buf, 0, 0, len)
457 return buf
458 }
459
460 if (obj.length !== undefined) {
461 if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
462 return createBuffer(0)
463 }
464 return fromArrayLike(obj)
465 }
466
467 if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
468 return fromArrayLike(obj.data)
469 }
470 }
471
472 function checked (length) {
473 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
474 // length is NaN (which is otherwise coerced to zero.)
475 if (length >= K_MAX_LENGTH) {
476 throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
477 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
478 }
479 return length | 0
480 }
481
482 function SlowBuffer (length) {
483 if (+length != length) { // eslint-disable-line eqeqeq
484 length = 0
485 }
486 return Buffer.alloc(+length)
487 }
488
489 Buffer.isBuffer = function isBuffer (b) {
490 return b != null && b._isBuffer === true &&
491 b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
492 }
493
494 Buffer.compare = function compare (a, b) {
495 if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
496 if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
497 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
498 throw new TypeError(
499 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
500 )
501 }
502
503 if (a === b) return 0
504
505 var x = a.length
506 var y = b.length
507
508 for (var i = 0, len = Math.min(x, y); i < len; ++i) {
509 if (a[i] !== b[i]) {
510 x = a[i]
511 y = b[i]
512 break
513 }
514 }
515
516 if (x < y) return -1
517 if (y < x) return 1
518 return 0
519 }
520
521 Buffer.isEncoding = function isEncoding (encoding) {
522 switch (String(encoding).toLowerCase()) {
523 case 'hex':
524 case 'utf8':
525 case 'utf-8':
526 case 'ascii':
527 case 'latin1':
528 case 'binary':
529 case 'base64':
530 case 'ucs2':
531 case 'ucs-2':
532 case 'utf16le':
533 case 'utf-16le':
534 return true
535 default:
536 return false
537 }
538 }
539
540 Buffer.concat = function concat (list, length) {
541 if (!Array.isArray(list)) {
542 throw new TypeError('"list" argument must be an Array of Buffers')
543 }
544
545 if (list.length === 0) {
546 return Buffer.alloc(0)
547 }
548
549 var i
550 if (length === undefined) {
551 length = 0
552 for (i = 0; i < list.length; ++i) {
553 length += list[i].length
554 }
555 }
556
557 var buffer = Buffer.allocUnsafe(length)
558 var pos = 0
559 for (i = 0; i < list.length; ++i) {
560 var buf = list[i]
561 if (isInstance(buf, Uint8Array)) {
562 buf = Buffer.from(buf)
563 }
564 if (!Buffer.isBuffer(buf)) {
565 throw new TypeError('"list" argument must be an Array of Buffers')
566 }
567 buf.copy(buffer, pos)
568 pos += buf.length
569 }
570 return buffer
571 }
572
573 function byteLength (string, encoding) {
574 if (Buffer.isBuffer(string)) {
575 return string.length
576 }
577 if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
578 return string.byteLength
579 }
580 if (typeof string !== 'string') {
581 throw new TypeError(
582 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
583 'Received type ' + typeof string
584 )
585 }
586
587 var len = string.length
588 var mustMatch = (arguments.length > 2 && arguments[2] === true)
589 if (!mustMatch && len === 0) return 0
590
591 // Use a for loop to avoid recursion
592 var loweredCase = false
593 for (;;) {
594 switch (encoding) {
595 case 'ascii':
596 case 'latin1':
597 case 'binary':
598 return len
599 case 'utf8':
600 case 'utf-8':
601 return utf8ToBytes(string).length
602 case 'ucs2':
603 case 'ucs-2':
604 case 'utf16le':
605 case 'utf-16le':
606 return len * 2
607 case 'hex':
608 return len >>> 1
609 case 'base64':
610 return base64ToBytes(string).length
611 default:
612 if (loweredCase) {
613 return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
614 }
615 encoding = ('' + encoding).toLowerCase()
616 loweredCase = true
617 }
618 }
619 }
620 Buffer.byteLength = byteLength
621
622 function slowToString (encoding, start, end) {
623 var loweredCase = false
624
625 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
626 // property of a typed array.
627
628 // This behaves neither like String nor Uint8Array in that we set start/end
629 // to their upper/lower bounds if the value passed is out of range.
630 // undefined is handled specially as per ECMA-262 6th Edition,
631 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
632 if (start === undefined || start < 0) {
633 start = 0
634 }
635 // Return early if start > this.length. Done here to prevent potential uint32
636 // coercion fail below.
637 if (start > this.length) {
638 return ''
639 }
640
641 if (end === undefined || end > this.length) {
642 end = this.length
643 }
644
645 if (end <= 0) {
646 return ''
647 }
648
649 // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
650 end >>>= 0
651 start >>>= 0
652
653 if (end <= start) {
654 return ''
655 }
656
657 if (!encoding) encoding = 'utf8'
658
659 while (true) {
660 switch (encoding) {
661 case 'hex':
662 return hexSlice(this, start, end)
663
664 case 'utf8':
665 case 'utf-8':
666 return utf8Slice(this, start, end)
667
668 case 'ascii':
669 return asciiSlice(this, start, end)
670
671 case 'latin1':
672 case 'binary':
673 return latin1Slice(this, start, end)
674
675 case 'base64':
676 return base64Slice(this, start, end)
677
678 case 'ucs2':
679 case 'ucs-2':
680 case 'utf16le':
681 case 'utf-16le':
682 return utf16leSlice(this, start, end)
683
684 default:
685 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
686 encoding = (encoding + '').toLowerCase()
687 loweredCase = true
688 }
689 }
690 }
691
692 // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
693 // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
694 // reliably in a browserify context because there could be multiple different
695 // copies of the 'buffer' package in use. This method works even for Buffer
696 // instances that were created from another copy of the `buffer` package.
697 // See: https://github.com/feross/buffer/issues/154
698 Buffer.prototype._isBuffer = true
699
700 function swap (b, n, m) {
701 var i = b[n]
702 b[n] = b[m]
703 b[m] = i
704 }
705
706 Buffer.prototype.swap16 = function swap16 () {
707 var len = this.length
708 if (len % 2 !== 0) {
709 throw new RangeError('Buffer size must be a multiple of 16-bits')
710 }
711 for (var i = 0; i < len; i += 2) {
712 swap(this, i, i + 1)
713 }
714 return this
715 }
716
717 Buffer.prototype.swap32 = function swap32 () {
718 var len = this.length
719 if (len % 4 !== 0) {
720 throw new RangeError('Buffer size must be a multiple of 32-bits')
721 }
722 for (var i = 0; i < len; i += 4) {
723 swap(this, i, i + 3)
724 swap(this, i + 1, i + 2)
725 }
726 return this
727 }
728
729 Buffer.prototype.swap64 = function swap64 () {
730 var len = this.length
731 if (len % 8 !== 0) {
732 throw new RangeError('Buffer size must be a multiple of 64-bits')
733 }
734 for (var i = 0; i < len; i += 8) {
735 swap(this, i, i + 7)
736 swap(this, i + 1, i + 6)
737 swap(this, i + 2, i + 5)
738 swap(this, i + 3, i + 4)
739 }
740 return this
741 }
742
743 Buffer.prototype.toString = function toString () {
744 var length = this.length
745 if (length === 0) return ''
746 if (arguments.length === 0) return utf8Slice(this, 0, length)
747 return slowToString.apply(this, arguments)
748 }
749
750 Buffer.prototype.toLocaleString = Buffer.prototype.toString
751
752 Buffer.prototype.equals = function equals (b) {
753 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
754 if (this === b) return true
755 return Buffer.compare(this, b) === 0
756 }
757
758 Buffer.prototype.inspect = function inspect () {
759 var str = ''
760 var max = exports.INSPECT_MAX_BYTES
761 str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
762 if (this.length > max) str += ' ... '
763 return '<Buffer ' + str + '>'
764 }
765
766 Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
767 if (isInstance(target, Uint8Array)) {
768 target = Buffer.from(target, target.offset, target.byteLength)
769 }
770 if (!Buffer.isBuffer(target)) {
771 throw new TypeError(
772 'The "target" argument must be one of type Buffer or Uint8Array. ' +
773 'Received type ' + (typeof target)
774 )
775 }
776
777 if (start === undefined) {
778 start = 0
779 }
780 if (end === undefined) {
781 end = target ? target.length : 0
782 }
783 if (thisStart === undefined) {
784 thisStart = 0
785 }
786 if (thisEnd === undefined) {
787 thisEnd = this.length
788 }
789
790 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
791 throw new RangeError('out of range index')
792 }
793
794 if (thisStart >= thisEnd && start >= end) {
795 return 0
796 }
797 if (thisStart >= thisEnd) {
798 return -1
799 }
800 if (start >= end) {
801 return 1
802 }
803
804 start >>>= 0
805 end >>>= 0
806 thisStart >>>= 0
807 thisEnd >>>= 0
808
809 if (this === target) return 0
810
811 var x = thisEnd - thisStart
812 var y = end - start
813 var len = Math.min(x, y)
814
815 var thisCopy = this.slice(thisStart, thisEnd)
816 var targetCopy = target.slice(start, end)
817
818 for (var i = 0; i < len; ++i) {
819 if (thisCopy[i] !== targetCopy[i]) {
820 x = thisCopy[i]
821 y = targetCopy[i]
822 break
823 }
824 }
825
826 if (x < y) return -1
827 if (y < x) return 1
828 return 0
829 }
830
831 // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
832 // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
833 //
834 // Arguments:
835 // - buffer - a Buffer to search
836 // - val - a string, Buffer, or number
837 // - byteOffset - an index into `buffer`; will be clamped to an int32
838 // - encoding - an optional encoding, relevant is val is a string
839 // - dir - true for indexOf, false for lastIndexOf
840 function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
841 // Empty buffer means no match
842 if (buffer.length === 0) return -1
843
844 // Normalize byteOffset
845 if (typeof byteOffset === 'string') {
846 encoding = byteOffset
847 byteOffset = 0
848 } else if (byteOffset > 0x7fffffff) {
849 byteOffset = 0x7fffffff
850 } else if (byteOffset < -0x80000000) {
851 byteOffset = -0x80000000
852 }
853 byteOffset = +byteOffset // Coerce to Number.
854 if (numberIsNaN(byteOffset)) {
855 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
856 byteOffset = dir ? 0 : (buffer.length - 1)
857 }
858
859 // Normalize byteOffset: negative offsets start from the end of the buffer
860 if (byteOffset < 0) byteOffset = buffer.length + byteOffset
861 if (byteOffset >= buffer.length) {
862 if (dir) return -1
863 else byteOffset = buffer.length - 1
864 } else if (byteOffset < 0) {
865 if (dir) byteOffset = 0
866 else return -1
867 }
868
869 // Normalize val
870 if (typeof val === 'string') {
871 val = Buffer.from(val, encoding)
872 }
873
874 // Finally, search either indexOf (if dir is true) or lastIndexOf
875 if (Buffer.isBuffer(val)) {
876 // Special case: looking for empty string/buffer always fails
877 if (val.length === 0) {
878 return -1
879 }
880 return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
881 } else if (typeof val === 'number') {
882 val = val & 0xFF // Search for a byte value [0-255]
883 if (typeof Uint8Array.prototype.indexOf === 'function') {
884 if (dir) {
885 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
886 } else {
887 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
888 }
889 }
890 return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
891 }
892
893 throw new TypeError('val must be string, number or Buffer')
894 }
895
896 function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
897 var indexSize = 1
898 var arrLength = arr.length
899 var valLength = val.length
900
901 if (encoding !== undefined) {
902 encoding = String(encoding).toLowerCase()
903 if (encoding === 'ucs2' || encoding === 'ucs-2' ||
904 encoding === 'utf16le' || encoding === 'utf-16le') {
905 if (arr.length < 2 || val.length < 2) {
906 return -1
907 }
908 indexSize = 2
909 arrLength /= 2
910 valLength /= 2
911 byteOffset /= 2
912 }
913 }
914
915 function read (buf, i) {
916 if (indexSize === 1) {
917 return buf[i]
918 } else {
919 return buf.readUInt16BE(i * indexSize)
920 }
921 }
922
923 var i
924 if (dir) {
925 var foundIndex = -1
926 for (i = byteOffset; i < arrLength; i++) {
927 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
928 if (foundIndex === -1) foundIndex = i
929 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
930 } else {
931 if (foundIndex !== -1) i -= i - foundIndex
932 foundIndex = -1
933 }
934 }
935 } else {
936 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
937 for (i = byteOffset; i >= 0; i--) {
938 var found = true
939 for (var j = 0; j < valLength; j++) {
940 if (read(arr, i + j) !== read(val, j)) {
941 found = false
942 break
943 }
944 }
945 if (found) return i
946 }
947 }
948
949 return -1
950 }
951
952 Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
953 return this.indexOf(val, byteOffset, encoding) !== -1
954 }
955
956 Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
957 return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
958 }
959
960 Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
961 return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
962 }
963
964 function hexWrite (buf, string, offset, length) {
965 offset = Number(offset) || 0
966 var remaining = buf.length - offset
967 if (!length) {
968 length = remaining
969 } else {
970 length = Number(length)
971 if (length > remaining) {
972 length = remaining
973 }
974 }
975
976 var strLen = string.length
977
978 if (length > strLen / 2) {
979 length = strLen / 2
980 }
981 for (var i = 0; i < length; ++i) {
982 var parsed = parseInt(string.substr(i * 2, 2), 16)
983 if (numberIsNaN(parsed)) return i
984 buf[offset + i] = parsed
985 }
986 return i
987 }
988
989 function utf8Write (buf, string, offset, length) {
990 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
991 }
992
993 function asciiWrite (buf, string, offset, length) {
994 return blitBuffer(asciiToBytes(string), buf, offset, length)
995 }
996
997 function latin1Write (buf, string, offset, length) {
998 return asciiWrite(buf, string, offset, length)
999 }
1000
1001 function base64Write (buf, string, offset, length) {
1002 return blitBuffer(base64ToBytes(string), buf, offset, length)
1003 }
1004
1005 function ucs2Write (buf, string, offset, length) {
1006 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1007 }
1008
1009 Buffer.prototype.write = function write (string, offset, length, encoding) {
1010 // Buffer#write(string)
1011 if (offset === undefined) {
1012 encoding = 'utf8'
1013 length = this.length
1014 offset = 0
1015 // Buffer#write(string, encoding)
1016 } else if (length === undefined && typeof offset === 'string') {
1017 encoding = offset
1018 length = this.length
1019 offset = 0
1020 // Buffer#write(string, offset[, length][, encoding])
1021 } else if (isFinite(offset)) {
1022 offset = offset >>> 0
1023 if (isFinite(length)) {
1024 length = length >>> 0
1025 if (encoding === undefined) encoding = 'utf8'
1026 } else {
1027 encoding = length
1028 length = undefined
1029 }
1030 } else {
1031 throw new Error(
1032 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1033 )
1034 }
1035
1036 var remaining = this.length - offset
1037 if (length === undefined || length > remaining) length = remaining
1038
1039 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1040 throw new RangeError('Attempt to write outside buffer bounds')
1041 }
1042
1043 if (!encoding) encoding = 'utf8'
1044
1045 var loweredCase = false
1046 for (;;) {
1047 switch (encoding) {
1048 case 'hex':
1049 return hexWrite(this, string, offset, length)
1050
1051 case 'utf8':
1052 case 'utf-8':
1053 return utf8Write(this, string, offset, length)
1054
1055 case 'ascii':
1056 return asciiWrite(this, string, offset, length)
1057
1058 case 'latin1':
1059 case 'binary':
1060 return latin1Write(this, string, offset, length)
1061
1062 case 'base64':
1063 // Warning: maxLength not taken into account in base64Write
1064 return base64Write(this, string, offset, length)
1065
1066 case 'ucs2':
1067 case 'ucs-2':
1068 case 'utf16le':
1069 case 'utf-16le':
1070 return ucs2Write(this, string, offset, length)
1071
1072 default:
1073 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1074 encoding = ('' + encoding).toLowerCase()
1075 loweredCase = true
1076 }
1077 }
1078 }
1079
1080 Buffer.prototype.toJSON = function toJSON () {
1081 return {
1082 type: 'Buffer',
1083 data: Array.prototype.slice.call(this._arr || this, 0)
1084 }
1085 }
1086
1087 function base64Slice (buf, start, end) {
1088 if (start === 0 && end === buf.length) {
1089 return base64.fromByteArray(buf)
1090 } else {
1091 return base64.fromByteArray(buf.slice(start, end))
1092 }
1093 }
1094
1095 function utf8Slice (buf, start, end) {
1096 end = Math.min(buf.length, end)
1097 var res = []
1098
1099 var i = start
1100 while (i < end) {
1101 var firstByte = buf[i]
1102 var codePoint = null
1103 var bytesPerSequence = (firstByte > 0xEF) ? 4
1104 : (firstByte > 0xDF) ? 3
1105 : (firstByte > 0xBF) ? 2
1106 : 1
1107
1108 if (i + bytesPerSequence <= end) {
1109 var secondByte, thirdByte, fourthByte, tempCodePoint
1110
1111 switch (bytesPerSequence) {
1112 case 1:
1113 if (firstByte < 0x80) {
1114 codePoint = firstByte
1115 }
1116 break
1117 case 2:
1118 secondByte = buf[i + 1]
1119 if ((secondByte & 0xC0) === 0x80) {
1120 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
1121 if (tempCodePoint > 0x7F) {
1122 codePoint = tempCodePoint
1123 }
1124 }
1125 break
1126 case 3:
1127 secondByte = buf[i + 1]
1128 thirdByte = buf[i + 2]
1129 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1130 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
1131 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1132 codePoint = tempCodePoint
1133 }
1134 }
1135 break
1136 case 4:
1137 secondByte = buf[i + 1]
1138 thirdByte = buf[i + 2]
1139 fourthByte = buf[i + 3]
1140 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1141 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
1142 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1143 codePoint = tempCodePoint
1144 }
1145 }
1146 }
1147 }
1148
1149 if (codePoint === null) {
1150 // we did not generate a valid codePoint so insert a
1151 // replacement char (U+FFFD) and advance only 1 byte
1152 codePoint = 0xFFFD
1153 bytesPerSequence = 1
1154 } else if (codePoint > 0xFFFF) {
1155 // encode to utf16 (surrogate pair dance)
1156 codePoint -= 0x10000
1157 res.push(codePoint >>> 10 & 0x3FF | 0xD800)
1158 codePoint = 0xDC00 | codePoint & 0x3FF
1159 }
1160
1161 res.push(codePoint)
1162 i += bytesPerSequence
1163 }
1164
1165 return decodeCodePointsArray(res)
1166 }
1167
1168 // Based on http://stackoverflow.com/a/22747272/680742, the browser with
1169 // the lowest limit is Chrome, with 0x10000 args.
1170 // We go 1 magnitude less, for safety
1171 var MAX_ARGUMENTS_LENGTH = 0x1000
1172
1173 function decodeCodePointsArray (codePoints) {
1174 var len = codePoints.length
1175 if (len <= MAX_ARGUMENTS_LENGTH) {
1176 return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
1177 }
1178
1179 // Decode in chunks to avoid "call stack size exceeded".
1180 var res = ''
1181 var i = 0
1182 while (i < len) {
1183 res += String.fromCharCode.apply(
1184 String,
1185 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
1186 )
1187 }
1188 return res
1189 }
1190
1191 function asciiSlice (buf, start, end) {
1192 var ret = ''
1193 end = Math.min(buf.length, end)
1194
1195 for (var i = start; i < end; ++i) {
1196 ret += String.fromCharCode(buf[i] & 0x7F)
1197 }
1198 return ret
1199 }
1200
1201 function latin1Slice (buf, start, end) {
1202 var ret = ''
1203 end = Math.min(buf.length, end)
1204
1205 for (var i = start; i < end; ++i) {
1206 ret += String.fromCharCode(buf[i])
1207 }
1208 return ret
1209 }
1210
1211 function hexSlice (buf, start, end) {
1212 var len = buf.length
1213
1214 if (!start || start < 0) start = 0
1215 if (!end || end < 0 || end > len) end = len
1216
1217 var out = ''
1218 for (var i = start; i < end; ++i) {
1219 out += toHex(buf[i])
1220 }
1221 return out
1222 }
1223
1224 function utf16leSlice (buf, start, end) {
1225 var bytes = buf.slice(start, end)
1226 var res = ''
1227 for (var i = 0; i < bytes.length; i += 2) {
1228 res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
1229 }
1230 return res
1231 }
1232
1233 Buffer.prototype.slice = function slice (start, end) {
1234 var len = this.length
1235 start = ~~start
1236 end = end === undefined ? len : ~~end
1237
1238 if (start < 0) {
1239 start += len
1240 if (start < 0) start = 0
1241 } else if (start > len) {
1242 start = len
1243 }
1244
1245 if (end < 0) {
1246 end += len
1247 if (end < 0) end = 0
1248 } else if (end > len) {
1249 end = len
1250 }
1251
1252 if (end < start) end = start
1253
1254 var newBuf = this.subarray(start, end)
1255 // Return an augmented `Uint8Array` instance
1256 newBuf.__proto__ = Buffer.prototype
1257 return newBuf
1258 }
1259
1260 /*
1261 * Need to make sure that buffer isn't trying to write out of bounds.
1262 */
1263 function checkOffset (offset, ext, length) {
1264 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
1265 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
1266 }
1267
1268 Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
1269 offset = offset >>> 0
1270 byteLength = byteLength >>> 0
1271 if (!noAssert) checkOffset(offset, byteLength, this.length)
1272
1273 var val = this[offset]
1274 var mul = 1
1275 var i = 0
1276 while (++i < byteLength && (mul *= 0x100)) {
1277 val += this[offset + i] * mul
1278 }
1279
1280 return val
1281 }
1282
1283 Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
1284 offset = offset >>> 0
1285 byteLength = byteLength >>> 0
1286 if (!noAssert) {
1287 checkOffset(offset, byteLength, this.length)
1288 }
1289
1290 var val = this[offset + --byteLength]
1291 var mul = 1
1292 while (byteLength > 0 && (mul *= 0x100)) {
1293 val += this[offset + --byteLength] * mul
1294 }
1295
1296 return val
1297 }
1298
1299 Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
1300 offset = offset >>> 0
1301 if (!noAssert) checkOffset(offset, 1, this.length)
1302 return this[offset]
1303 }
1304
1305 Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
1306 offset = offset >>> 0
1307 if (!noAssert) checkOffset(offset, 2, this.length)
1308 return this[offset] | (this[offset + 1] << 8)
1309 }
1310
1311 Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
1312 offset = offset >>> 0
1313 if (!noAssert) checkOffset(offset, 2, this.length)
1314 return (this[offset] << 8) | this[offset + 1]
1315 }
1316
1317 Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
1318 offset = offset >>> 0
1319 if (!noAssert) checkOffset(offset, 4, this.length)
1320
1321 return ((this[offset]) |
1322 (this[offset + 1] << 8) |
1323 (this[offset + 2] << 16)) +
1324 (this[offset + 3] * 0x1000000)
1325 }
1326
1327 Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
1328 offset = offset >>> 0
1329 if (!noAssert) checkOffset(offset, 4, this.length)
1330
1331 return (this[offset] * 0x1000000) +
1332 ((this[offset + 1] << 16) |
1333 (this[offset + 2] << 8) |
1334 this[offset + 3])
1335 }
1336
1337 Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
1338 offset = offset >>> 0
1339 byteLength = byteLength >>> 0
1340 if (!noAssert) checkOffset(offset, byteLength, this.length)
1341
1342 var val = this[offset]
1343 var mul = 1
1344 var i = 0
1345 while (++i < byteLength && (mul *= 0x100)) {
1346 val += this[offset + i] * mul
1347 }
1348 mul *= 0x80
1349
1350 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
1351
1352 return val
1353 }
1354
1355 Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
1356 offset = offset >>> 0
1357 byteLength = byteLength >>> 0
1358 if (!noAssert) checkOffset(offset, byteLength, this.length)
1359
1360 var i = byteLength
1361 var mul = 1
1362 var val = this[offset + --i]
1363 while (i > 0 && (mul *= 0x100)) {
1364 val += this[offset + --i] * mul
1365 }
1366 mul *= 0x80
1367
1368 if (val >= mul) val -= Math.pow(2, 8 * byteLength)
1369
1370 return val
1371 }
1372
1373 Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
1374 offset = offset >>> 0
1375 if (!noAssert) checkOffset(offset, 1, this.length)
1376 if (!(this[offset] & 0x80)) return (this[offset])
1377 return ((0xff - this[offset] + 1) * -1)
1378 }
1379
1380 Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
1381 offset = offset >>> 0
1382 if (!noAssert) checkOffset(offset, 2, this.length)
1383 var val = this[offset] | (this[offset + 1] << 8)
1384 return (val & 0x8000) ? val | 0xFFFF0000 : val
1385 }
1386
1387 Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
1388 offset = offset >>> 0
1389 if (!noAssert) checkOffset(offset, 2, this.length)
1390 var val = this[offset + 1] | (this[offset] << 8)
1391 return (val & 0x8000) ? val | 0xFFFF0000 : val
1392 }
1393
1394 Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
1395 offset = offset >>> 0
1396 if (!noAssert) checkOffset(offset, 4, this.length)
1397
1398 return (this[offset]) |
1399 (this[offset + 1] << 8) |
1400 (this[offset + 2] << 16) |
1401 (this[offset + 3] << 24)
1402 }
1403
1404 Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
1405 offset = offset >>> 0
1406 if (!noAssert) checkOffset(offset, 4, this.length)
1407
1408 return (this[offset] << 24) |
1409 (this[offset + 1] << 16) |
1410 (this[offset + 2] << 8) |
1411 (this[offset + 3])
1412 }
1413
1414 Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
1415 offset = offset >>> 0
1416 if (!noAssert) checkOffset(offset, 4, this.length)
1417 return ieee754.read(this, offset, true, 23, 4)
1418 }
1419
1420 Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
1421 offset = offset >>> 0
1422 if (!noAssert) checkOffset(offset, 4, this.length)
1423 return ieee754.read(this, offset, false, 23, 4)
1424 }
1425
1426 Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
1427 offset = offset >>> 0
1428 if (!noAssert) checkOffset(offset, 8, this.length)
1429 return ieee754.read(this, offset, true, 52, 8)
1430 }
1431
1432 Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
1433 offset = offset >>> 0
1434 if (!noAssert) checkOffset(offset, 8, this.length)
1435 return ieee754.read(this, offset, false, 52, 8)
1436 }
1437
1438 function checkInt (buf, value, offset, ext, max, min) {
1439 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
1440 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
1441 if (offset + ext > buf.length) throw new RangeError('Index out of range')
1442 }
1443
1444 Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
1445 value = +value
1446 offset = offset >>> 0
1447 byteLength = byteLength >>> 0
1448 if (!noAssert) {
1449 var maxBytes = Math.pow(2, 8 * byteLength) - 1
1450 checkInt(this, value, offset, byteLength, maxBytes, 0)
1451 }
1452
1453 var mul = 1
1454 var i = 0
1455 this[offset] = value & 0xFF
1456 while (++i < byteLength && (mul *= 0x100)) {
1457 this[offset + i] = (value / mul) & 0xFF
1458 }
1459
1460 return offset + byteLength
1461 }
1462
1463 Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
1464 value = +value
1465 offset = offset >>> 0
1466 byteLength = byteLength >>> 0
1467 if (!noAssert) {
1468 var maxBytes = Math.pow(2, 8 * byteLength) - 1
1469 checkInt(this, value, offset, byteLength, maxBytes, 0)
1470 }
1471
1472 var i = byteLength - 1
1473 var mul = 1
1474 this[offset + i] = value & 0xFF
1475 while (--i >= 0 && (mul *= 0x100)) {
1476 this[offset + i] = (value / mul) & 0xFF
1477 }
1478
1479 return offset + byteLength
1480 }
1481
1482 Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
1483 value = +value
1484 offset = offset >>> 0
1485 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
1486 this[offset] = (value & 0xff)
1487 return offset + 1
1488 }
1489
1490 Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
1491 value = +value
1492 offset = offset >>> 0
1493 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
1494 this[offset] = (value & 0xff)
1495 this[offset + 1] = (value >>> 8)
1496 return offset + 2
1497 }
1498
1499 Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
1500 value = +value
1501 offset = offset >>> 0
1502 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
1503 this[offset] = (value >>> 8)
1504 this[offset + 1] = (value & 0xff)
1505 return offset + 2
1506 }
1507
1508 Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
1509 value = +value
1510 offset = offset >>> 0
1511 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
1512 this[offset + 3] = (value >>> 24)
1513 this[offset + 2] = (value >>> 16)
1514 this[offset + 1] = (value >>> 8)
1515 this[offset] = (value & 0xff)
1516 return offset + 4
1517 }
1518
1519 Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
1520 value = +value
1521 offset = offset >>> 0
1522 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
1523 this[offset] = (value >>> 24)
1524 this[offset + 1] = (value >>> 16)
1525 this[offset + 2] = (value >>> 8)
1526 this[offset + 3] = (value & 0xff)
1527 return offset + 4
1528 }
1529
1530 Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
1531 value = +value
1532 offset = offset >>> 0
1533 if (!noAssert) {
1534 var limit = Math.pow(2, (8 * byteLength) - 1)
1535
1536 checkInt(this, value, offset, byteLength, limit - 1, -limit)
1537 }
1538
1539 var i = 0
1540 var mul = 1
1541 var sub = 0
1542 this[offset] = value & 0xFF
1543 while (++i < byteLength && (mul *= 0x100)) {
1544 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
1545 sub = 1
1546 }
1547 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
1548 }
1549
1550 return offset + byteLength
1551 }
1552
1553 Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
1554 value = +value
1555 offset = offset >>> 0
1556 if (!noAssert) {
1557 var limit = Math.pow(2, (8 * byteLength) - 1)
1558
1559 checkInt(this, value, offset, byteLength, limit - 1, -limit)
1560 }
1561
1562 var i = byteLength - 1
1563 var mul = 1
1564 var sub = 0
1565 this[offset + i] = value & 0xFF
1566 while (--i >= 0 && (mul *= 0x100)) {
1567 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
1568 sub = 1
1569 }
1570 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
1571 }
1572
1573 return offset + byteLength
1574 }
1575
1576 Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
1577 value = +value
1578 offset = offset >>> 0
1579 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
1580 if (value < 0) value = 0xff + value + 1
1581 this[offset] = (value & 0xff)
1582 return offset + 1
1583 }
1584
1585 Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
1586 value = +value
1587 offset = offset >>> 0
1588 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
1589 this[offset] = (value & 0xff)
1590 this[offset + 1] = (value >>> 8)
1591 return offset + 2
1592 }
1593
1594 Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
1595 value = +value
1596 offset = offset >>> 0
1597 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
1598 this[offset] = (value >>> 8)
1599 this[offset + 1] = (value & 0xff)
1600 return offset + 2
1601 }
1602
1603 Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
1604 value = +value
1605 offset = offset >>> 0
1606 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
1607 this[offset] = (value & 0xff)
1608 this[offset + 1] = (value >>> 8)
1609 this[offset + 2] = (value >>> 16)
1610 this[offset + 3] = (value >>> 24)
1611 return offset + 4
1612 }
1613
1614 Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
1615 value = +value
1616 offset = offset >>> 0
1617 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
1618 if (value < 0) value = 0xffffffff + value + 1
1619 this[offset] = (value >>> 24)
1620 this[offset + 1] = (value >>> 16)
1621 this[offset + 2] = (value >>> 8)
1622 this[offset + 3] = (value & 0xff)
1623 return offset + 4
1624 }
1625
1626 function checkIEEE754 (buf, value, offset, ext, max, min) {
1627 if (offset + ext > buf.length) throw new RangeError('Index out of range')
1628 if (offset < 0) throw new RangeError('Index out of range')
1629 }
1630
1631 function writeFloat (buf, value, offset, littleEndian, noAssert) {
1632 value = +value
1633 offset = offset >>> 0
1634 if (!noAssert) {
1635 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
1636 }
1637 ieee754.write(buf, value, offset, littleEndian, 23, 4)
1638 return offset + 4
1639 }
1640
1641 Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
1642 return writeFloat(this, value, offset, true, noAssert)
1643 }
1644
1645 Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
1646 return writeFloat(this, value, offset, false, noAssert)
1647 }
1648
1649 function writeDouble (buf, value, offset, littleEndian, noAssert) {
1650 value = +value
1651 offset = offset >>> 0
1652 if (!noAssert) {
1653 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
1654 }
1655 ieee754.write(buf, value, offset, littleEndian, 52, 8)
1656 return offset + 8
1657 }
1658
1659 Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
1660 return writeDouble(this, value, offset, true, noAssert)
1661 }
1662
1663 Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
1664 return writeDouble(this, value, offset, false, noAssert)
1665 }
1666
1667 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
1668 Buffer.prototype.copy = function copy (target, targetStart, start, end) {
1669 if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
1670 if (!start) start = 0
1671 if (!end && end !== 0) end = this.length
1672 if (targetStart >= target.length) targetStart = target.length
1673 if (!targetStart) targetStart = 0
1674 if (end > 0 && end < start) end = start
1675
1676 // Copy 0 bytes; we're done
1677 if (end === start) return 0
1678 if (target.length === 0 || this.length === 0) return 0
1679
1680 // Fatal error conditions
1681 if (targetStart < 0) {
1682 throw new RangeError('targetStart out of bounds')
1683 }
1684 if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
1685 if (end < 0) throw new RangeError('sourceEnd out of bounds')
1686
1687 // Are we oob?
1688 if (end > this.length) end = this.length
1689 if (target.length - targetStart < end - start) {
1690 end = target.length - targetStart + start
1691 }
1692
1693 var len = end - start
1694
1695 if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
1696 // Use built-in when available, missing from IE11
1697 this.copyWithin(targetStart, start, end)
1698 } else if (this === target && start < targetStart && targetStart < end) {
1699 // descending copy from end
1700 for (var i = len - 1; i >= 0; --i) {
1701 target[i + targetStart] = this[i + start]
1702 }
1703 } else {
1704 Uint8Array.prototype.set.call(
1705 target,
1706 this.subarray(start, end),
1707 targetStart
1708 )
1709 }
1710
1711 return len
1712 }
1713
1714 // Usage:
1715 // buffer.fill(number[, offset[, end]])
1716 // buffer.fill(buffer[, offset[, end]])
1717 // buffer.fill(string[, offset[, end]][, encoding])
1718 Buffer.prototype.fill = function fill (val, start, end, encoding) {
1719 // Handle string cases:
1720 if (typeof val === 'string') {
1721 if (typeof start === 'string') {
1722 encoding = start
1723 start = 0
1724 end = this.length
1725 } else if (typeof end === 'string') {
1726 encoding = end
1727 end = this.length
1728 }
1729 if (encoding !== undefined && typeof encoding !== 'string') {
1730 throw new TypeError('encoding must be a string')
1731 }
1732 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
1733 throw new TypeError('Unknown encoding: ' + encoding)
1734 }
1735 if (val.length === 1) {
1736 var code = val.charCodeAt(0)
1737 if ((encoding === 'utf8' && code < 128) ||
1738 encoding === 'latin1') {
1739 // Fast path: If `val` fits into a single byte, use that numeric value.
1740 val = code
1741 }
1742 }
1743 } else if (typeof val === 'number') {
1744 val = val & 255
1745 }
1746
1747 // Invalid ranges are not set to a default, so can range check early.
1748 if (start < 0 || this.length < start || this.length < end) {
1749 throw new RangeError('Out of range index')
1750 }
1751
1752 if (end <= start) {
1753 return this
1754 }
1755
1756 start = start >>> 0
1757 end = end === undefined ? this.length : end >>> 0
1758
1759 if (!val) val = 0
1760
1761 var i
1762 if (typeof val === 'number') {
1763 for (i = start; i < end; ++i) {
1764 this[i] = val
1765 }
1766 } else {
1767 var bytes = Buffer.isBuffer(val)
1768 ? val
1769 : Buffer.from(val, encoding)
1770 var len = bytes.length
1771 if (len === 0) {
1772 throw new TypeError('The value "' + val +
1773 '" is invalid for argument "value"')
1774 }
1775 for (i = 0; i < end - start; ++i) {
1776 this[i + start] = bytes[i % len]
1777 }
1778 }
1779
1780 return this
1781 }
1782
1783 // HELPER FUNCTIONS
1784 // ================
1785
1786 var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
1787
1788 function base64clean (str) {
1789 // Node takes equal signs as end of the Base64 encoding
1790 str = str.split('=')[0]
1791 // Node strips out invalid characters like \n and \t from the string, base64-js does not
1792 str = str.trim().replace(INVALID_BASE64_RE, '')
1793 // Node converts strings with length < 2 to ''
1794 if (str.length < 2) return ''
1795 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
1796 while (str.length % 4 !== 0) {
1797 str = str + '='
1798 }
1799 return str
1800 }
1801
1802 function toHex (n) {
1803 if (n < 16) return '0' + n.toString(16)
1804 return n.toString(16)
1805 }
1806
1807 function utf8ToBytes (string, units) {
1808 units = units || Infinity
1809 var codePoint
1810 var length = string.length
1811 var leadSurrogate = null
1812 var bytes = []
1813
1814 for (var i = 0; i < length; ++i) {
1815 codePoint = string.charCodeAt(i)
1816
1817 // is surrogate component
1818 if (codePoint > 0xD7FF && codePoint < 0xE000) {
1819 // last char was a lead
1820 if (!leadSurrogate) {
1821 // no lead yet
1822 if (codePoint > 0xDBFF) {
1823 // unexpected trail
1824 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1825 continue
1826 } else if (i + 1 === length) {
1827 // unpaired lead
1828 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1829 continue
1830 }
1831
1832 // valid lead
1833 leadSurrogate = codePoint
1834
1835 continue
1836 }
1837
1838 // 2 leads in a row
1839 if (codePoint < 0xDC00) {
1840 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1841 leadSurrogate = codePoint
1842 continue
1843 }
1844
1845 // valid surrogate pair
1846 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
1847 } else if (leadSurrogate) {
1848 // valid bmp char, but last char was a lead
1849 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
1850 }
1851
1852 leadSurrogate = null
1853
1854 // encode utf8
1855 if (codePoint < 0x80) {
1856 if ((units -= 1) < 0) break
1857 bytes.push(codePoint)
1858 } else if (codePoint < 0x800) {
1859 if ((units -= 2) < 0) break
1860 bytes.push(
1861 codePoint >> 0x6 | 0xC0,
1862 codePoint & 0x3F | 0x80
1863 )
1864 } else if (codePoint < 0x10000) {
1865 if ((units -= 3) < 0) break
1866 bytes.push(
1867 codePoint >> 0xC | 0xE0,
1868 codePoint >> 0x6 & 0x3F | 0x80,
1869 codePoint & 0x3F | 0x80
1870 )
1871 } else if (codePoint < 0x110000) {
1872 if ((units -= 4) < 0) break
1873 bytes.push(
1874 codePoint >> 0x12 | 0xF0,
1875 codePoint >> 0xC & 0x3F | 0x80,
1876 codePoint >> 0x6 & 0x3F | 0x80,
1877 codePoint & 0x3F | 0x80
1878 )
1879 } else {
1880 throw new Error('Invalid code point')
1881 }
1882 }
1883
1884 return bytes
1885 }
1886
1887 function asciiToBytes (str) {
1888 var byteArray = []
1889 for (var i = 0; i < str.length; ++i) {
1890 // Node's code seems to be doing this and not & 0x7F..
1891 byteArray.push(str.charCodeAt(i) & 0xFF)
1892 }
1893 return byteArray
1894 }
1895
1896 function utf16leToBytes (str, units) {
1897 var c, hi, lo
1898 var byteArray = []
1899 for (var i = 0; i < str.length; ++i) {
1900 if ((units -= 2) < 0) break
1901
1902 c = str.charCodeAt(i)
1903 hi = c >> 8
1904 lo = c % 256
1905 byteArray.push(lo)
1906 byteArray.push(hi)
1907 }
1908
1909 return byteArray
1910 }
1911
1912 function base64ToBytes (str) {
1913 return base64.toByteArray(base64clean(str))
1914 }
1915
1916 function blitBuffer (src, dst, offset, length) {
1917 for (var i = 0; i < length; ++i) {
1918 if ((i + offset >= dst.length) || (i >= src.length)) break
1919 dst[i + offset] = src[i]
1920 }
1921 return i
1922 }
1923
1924 // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
1925 // the `instanceof` check but they should be treated as of that type.
1926 // See: https://github.com/feross/buffer/issues/166
1927 function isInstance (obj, type) {
1928 return obj instanceof type ||
1929 (obj != null && obj.constructor != null && obj.constructor.name != null &&
1930 obj.constructor.name === type.name)
1931 }
1932 function numberIsNaN (obj) {
1933 // For IE11 support
1934 return obj !== obj // eslint-disable-line no-self-compare
1935 }
1936
1937 }).call(this,require("buffer").Buffer)
1938 },{"base64-js":1,"buffer":3,"ieee754":4}],4:[function(require,module,exports){
1939 exports.read = function (buffer, offset, isLE, mLen, nBytes) {
1940 var e, m
1941 var eLen = (nBytes * 8) - mLen - 1
1942 var eMax = (1 << eLen) - 1
1943 var eBias = eMax >> 1
1944 var nBits = -7
1945 var i = isLE ? (nBytes - 1) : 0
1946 var d = isLE ? -1 : 1
1947 var s = buffer[offset + i]
1948
1949 i += d
1950
1951 e = s & ((1 << (-nBits)) - 1)
1952 s >>= (-nBits)
1953 nBits += eLen
1954 for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
1955
1956 m = e & ((1 << (-nBits)) - 1)
1957 e >>= (-nBits)
1958 nBits += mLen
1959 for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
1960
1961 if (e === 0) {
1962 e = 1 - eBias
1963 } else if (e === eMax) {
1964 return m ? NaN : ((s ? -1 : 1) * Infinity)
1965 } else {
1966 m = m + Math.pow(2, mLen)
1967 e = e - eBias
1968 }
1969 return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
1970 }
1971
1972 exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
1973 var e, m, c
1974 var eLen = (nBytes * 8) - mLen - 1
1975 var eMax = (1 << eLen) - 1
1976 var eBias = eMax >> 1
1977 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
1978 var i = isLE ? 0 : (nBytes - 1)
1979 var d = isLE ? 1 : -1
1980 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
1981
1982 value = Math.abs(value)
1983
1984 if (isNaN(value) || value === Infinity) {
1985 m = isNaN(value) ? 1 : 0
1986 e = eMax
1987 } else {
1988 e = Math.floor(Math.log(value) / Math.LN2)
1989 if (value * (c = Math.pow(2, -e)) < 1) {
1990 e--
1991 c *= 2
1992 }
1993 if (e + eBias >= 1) {
1994 value += rt / c
1995 } else {
1996 value += rt * Math.pow(2, 1 - eBias)
1997 }
1998 if (value * c >= 2) {
1999 e++
2000 c /= 2
2001 }
2002
2003 if (e + eBias >= eMax) {
2004 m = 0
2005 e = eMax
2006 } else if (e + eBias >= 1) {
2007 m = ((value * c) - 1) * Math.pow(2, mLen)
2008 e = e + eBias
2009 } else {
2010 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
2011 e = 0
2012 }
2013 }
2014
2015 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
2016
2017 e = (e << mLen) | m
2018 eLen += mLen
2019 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
2020
2021 buffer[offset + i - d] |= s * 128
2022 }
2023
2024 },{}],5:[function(require,module,exports){
2025 (function (process){
2026 // .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1,
2027 // backported and transplited with Babel, with backwards-compat fixes
2028
2029 // Copyright Joyent, Inc. and other Node contributors.
2030 //
2031 // Permission is hereby granted, free of charge, to any person obtaining a
2032 // copy of this software and associated documentation files (the
2033 // "Software"), to deal in the Software without restriction, including
2034 // without limitation the rights to use, copy, modify, merge, publish,
2035 // distribute, sublicense, and/or sell copies of the Software, and to permit
2036 // persons to whom the Software is furnished to do so, subject to the
2037 // following conditions:
2038 //
2039 // The above copyright notice and this permission notice shall be included
2040 // in all copies or substantial portions of the Software.
2041 //
2042 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2043 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2044 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
2045 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
2046 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2047 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2048 // USE OR OTHER DEALINGS IN THE SOFTWARE.
2049
2050 // resolves . and .. elements in a path array with directory names there
2051 // must be no slashes, empty elements, or device names (c:\) in the array
2052 // (so also no leading and trailing slashes - it does not distinguish
2053 // relative and absolute paths)
2054 function normalizeArray(parts, allowAboveRoot) {
2055 // if the path tries to go above the root, `up` ends up > 0
2056 var up = 0;
2057 for (var i = parts.length - 1; i >= 0; i--) {
2058 var last = parts[i];
2059 if (last === '.') {
2060 parts.splice(i, 1);
2061 } else if (last === '..') {
2062 parts.splice(i, 1);
2063 up++;
2064 } else if (up) {
2065 parts.splice(i, 1);
2066 up--;
2067 }
2068 }
2069
2070 // if the path is allowed to go above the root, restore leading ..s
2071 if (allowAboveRoot) {
2072 for (; up--; up) {
2073 parts.unshift('..');
2074 }
2075 }
2076
2077 return parts;
2078 }
2079
2080 // path.resolve([from ...], to)
2081 // posix version
2082 exports.resolve = function() {
2083 var resolvedPath = '',
2084 resolvedAbsolute = false;
2085
2086 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
2087 var path = (i >= 0) ? arguments[i] : process.cwd();
2088
2089 // Skip empty and invalid entries
2090 if (typeof path !== 'string') {
2091 throw new TypeError('Arguments to path.resolve must be strings');
2092 } else if (!path) {
2093 continue;
2094 }
2095
2096 resolvedPath = path + '/' + resolvedPath;
2097 resolvedAbsolute = path.charAt(0) === '/';
2098 }
2099
2100 // At this point the path should be resolved to a full absolute path, but
2101 // handle relative paths to be safe (might happen when process.cwd() fails)
2102
2103 // Normalize the path
2104 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
2105 return !!p;
2106 }), !resolvedAbsolute).join('/');
2107
2108 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
2109 };
2110
2111 // path.normalize(path)
2112 // posix version
2113 exports.normalize = function(path) {
2114 var isAbsolute = exports.isAbsolute(path),
2115 trailingSlash = substr(path, -1) === '/';
2116
2117 // Normalize the path
2118 path = normalizeArray(filter(path.split('/'), function(p) {
2119 return !!p;
2120 }), !isAbsolute).join('/');
2121
2122 if (!path && !isAbsolute) {
2123 path = '.';
2124 }
2125 if (path && trailingSlash) {
2126 path += '/';
2127 }
2128
2129 return (isAbsolute ? '/' : '') + path;
2130 };
2131
2132 // posix version
2133 exports.isAbsolute = function(path) {
2134 return path.charAt(0) === '/';
2135 };
2136
2137 // posix version
2138 exports.join = function() {
2139 var paths = Array.prototype.slice.call(arguments, 0);
2140 return exports.normalize(filter(paths, function(p, index) {
2141 if (typeof p !== 'string') {
2142 throw new TypeError('Arguments to path.join must be strings');
2143 }
2144 return p;
2145 }).join('/'));
2146 };
2147
2148
2149 // path.relative(from, to)
2150 // posix version
2151 exports.relative = function(from, to) {
2152 from = exports.resolve(from).substr(1);
2153 to = exports.resolve(to).substr(1);
2154
2155 function trim(arr) {
2156 var start = 0;
2157 for (; start < arr.length; start++) {
2158 if (arr[start] !== '') break;
2159 }
2160
2161 var end = arr.length - 1;
2162 for (; end >= 0; end--) {
2163 if (arr[end] !== '') break;
2164 }
2165
2166 if (start > end) return [];
2167 return arr.slice(start, end - start + 1);
2168 }
2169
2170 var fromParts = trim(from.split('/'));
2171 var toParts = trim(to.split('/'));
2172
2173 var length = Math.min(fromParts.length, toParts.length);
2174 var samePartsLength = length;
2175 for (var i = 0; i < length; i++) {
2176 if (fromParts[i] !== toParts[i]) {
2177 samePartsLength = i;
2178 break;
2179 }
2180 }
2181
2182 var outputParts = [];
2183 for (var i = samePartsLength; i < fromParts.length; i++) {
2184 outputParts.push('..');
2185 }
2186
2187 outputParts = outputParts.concat(toParts.slice(samePartsLength));
2188
2189 return outputParts.join('/');
2190 };
2191
2192 exports.sep = '/';
2193 exports.delimiter = ':';
2194
2195 exports.dirname = function (path) {
2196 if (typeof path !== 'string') path = path + '';
2197 if (path.length === 0) return '.';
2198 var code = path.charCodeAt(0);
2199 var hasRoot = code === 47 /*/*/;
2200 var end = -1;
2201 var matchedSlash = true;
2202 for (var i = path.length - 1; i >= 1; --i) {
2203 code = path.charCodeAt(i);
2204 if (code === 47 /*/*/) {
2205 if (!matchedSlash) {
2206 end = i;
2207 break;
2208 }
2209 } else {
2210 // We saw the first non-path separator
2211 matchedSlash = false;
2212 }
2213 }
2214
2215 if (end === -1) return hasRoot ? '/' : '.';
2216 if (hasRoot && end === 1) {
2217 // return '//';
2218 // Backwards-compat fix:
2219 return '/';
2220 }
2221 return path.slice(0, end);
2222 };
2223
2224 function basename(path) {
2225 if (typeof path !== 'string') path = path + '';
2226
2227 var start = 0;
2228 var end = -1;
2229 var matchedSlash = true;
2230 var i;
2231
2232 for (i = path.length - 1; i >= 0; --i) {
2233 if (path.charCodeAt(i) === 47 /*/*/) {
2234 // If we reached a path separator that was not part of a set of path
2235 // separators at the end of the string, stop now
2236 if (!matchedSlash) {
2237 start = i + 1;
2238 break;
2239 }
2240 } else if (end === -1) {
2241 // We saw the first non-path separator, mark this as the end of our
2242 // path component
2243 matchedSlash = false;
2244 end = i + 1;
2245 }
2246 }
2247
2248 if (end === -1) return '';
2249 return path.slice(start, end);
2250 }
2251
2252 // Uses a mixed approach for backwards-compatibility, as ext behavior changed
2253 // in new Node.js versions, so only basename() above is backported here
2254 exports.basename = function (path, ext) {
2255 var f = basename(path);
2256 if (ext && f.substr(-1 * ext.length) === ext) {
2257 f = f.substr(0, f.length - ext.length);
2258 }
2259 return f;
2260 };
2261
2262 exports.extname = function (path) {
2263 if (typeof path !== 'string') path = path + '';
2264 var startDot = -1;
2265 var startPart = 0;
2266 var end = -1;
2267 var matchedSlash = true;
2268 // Track the state of characters (if any) we see before our first dot and
2269 // after any path separator we find
2270 var preDotState = 0;
2271 for (var i = path.length - 1; i >= 0; --i) {
2272 var code = path.charCodeAt(i);
2273 if (code === 47 /*/*/) {
2274 // If we reached a path separator that was not part of a set of path
2275 // separators at the end of the string, stop now
2276 if (!matchedSlash) {
2277 startPart = i + 1;
2278 break;
2279 }
2280 continue;
2281 }
2282 if (end === -1) {
2283 // We saw the first non-path separator, mark this as the end of our
2284 // extension
2285 matchedSlash = false;
2286 end = i + 1;
2287 }
2288 if (code === 46 /*.*/) {
2289 // If this is our first dot, mark it as the start of our extension
2290 if (startDot === -1)
2291 startDot = i;
2292 else if (preDotState !== 1)
2293 preDotState = 1;
2294 } else if (startDot !== -1) {
2295 // We saw a non-dot and non-path separator before our dot, so we should
2296 // have a good chance at having a non-empty extension
2297 preDotState = -1;
2298 }
2299 }
2300
2301 if (startDot === -1 || end === -1 ||
2302 // We saw a non-dot character immediately before the dot
2303 preDotState === 0 ||
2304 // The (right-most) trimmed path component is exactly '..'
2305 preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
2306 return '';
2307 }
2308 return path.slice(startDot, end);
2309 };
2310
2311 function filter (xs, f) {
2312 if (xs.filter) return xs.filter(f);
2313 var res = [];
2314 for (var i = 0; i < xs.length; i++) {
2315 if (f(xs[i], i, xs)) res.push(xs[i]);
2316 }
2317 return res;
2318 }
2319
2320 // String.prototype.substr - negative index don't work in IE8
2321 var substr = 'ab'.substr(-1) === 'b'
2322 ? function (str, start, len) { return str.substr(start, len) }
2323 : function (str, start, len) {
2324 if (start < 0) start = str.length + start;
2325 return str.substr(start, len);
2326 }
2327 ;
2328
2329 }).call(this,require('_process'))
2330 },{"_process":6}],6:[function(require,module,exports){
2331 // shim for using process in browser
2332 var process = module.exports = {};
2333
2334 // cached from whatever global is present so that test runners that stub it
2335 // don't break things. But we need to wrap it in a try catch in case it is
2336 // wrapped in strict mode code which doesn't define any globals. It's inside a
2337 // function because try/catches deoptimize in certain engines.
2338
2339 var cachedSetTimeout;
2340 var cachedClearTimeout;
2341
2342 function defaultSetTimout() {
2343 throw new Error('setTimeout has not been defined');
2344 }
2345 function defaultClearTimeout () {
2346 throw new Error('clearTimeout has not been defined');
2347 }
2348 (function () {
2349 try {
2350 if (typeof setTimeout === 'function') {
2351 cachedSetTimeout = setTimeout;
2352 } else {
2353 cachedSetTimeout = defaultSetTimout;
2354 }
2355 } catch (e) {
2356 cachedSetTimeout = defaultSetTimout;
2357 }
2358 try {
2359 if (typeof clearTimeout === 'function') {
2360 cachedClearTimeout = clearTimeout;
2361 } else {
2362 cachedClearTimeout = defaultClearTimeout;
2363 }
2364 } catch (e) {
2365 cachedClearTimeout = defaultClearTimeout;
2366 }
2367 } ())
2368 function runTimeout(fun) {
2369 if (cachedSetTimeout === setTimeout) {
2370 //normal enviroments in sane situations
2371 return setTimeout(fun, 0);
2372 }
2373 // if setTimeout wasn't available but was latter defined
2374 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
2375 cachedSetTimeout = setTimeout;
2376 return setTimeout(fun, 0);
2377 }
2378 try {
2379 // when when somebody has screwed with setTimeout but no I.E. maddness
2380 return cachedSetTimeout(fun, 0);
2381 } catch(e){
2382 try {
2383 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
2384 return cachedSetTimeout.call(null, fun, 0);
2385 } catch(e){
2386 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
2387 return cachedSetTimeout.call(this, fun, 0);
2388 }
2389 }
2390
2391
2392 }
2393 function runClearTimeout(marker) {
2394 if (cachedClearTimeout === clearTimeout) {
2395 //normal enviroments in sane situations
2396 return clearTimeout(marker);
2397 }
2398 // if clearTimeout wasn't available but was latter defined
2399 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
2400 cachedClearTimeout = clearTimeout;
2401 return clearTimeout(marker);
2402 }
2403 try {
2404 // when when somebody has screwed with setTimeout but no I.E. maddness
2405 return cachedClearTimeout(marker);
2406 } catch (e){
2407 try {
2408 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
2409 return cachedClearTimeout.call(null, marker);
2410 } catch (e){
2411 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
2412 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
2413 return cachedClearTimeout.call(this, marker);
2414 }
2415 }
2416
2417
2418
2419 }
2420 var queue = [];
2421 var draining = false;
2422 var currentQueue;
2423 var queueIndex = -1;
2424
2425 function cleanUpNextTick() {
2426 if (!draining || !currentQueue) {
2427 return;
2428 }
2429 draining = false;
2430 if (currentQueue.length) {
2431 queue = currentQueue.concat(queue);
2432 } else {
2433 queueIndex = -1;
2434 }
2435 if (queue.length) {
2436 drainQueue();
2437 }
2438 }
2439
2440 function drainQueue() {
2441 if (draining) {
2442 return;
2443 }
2444 var timeout = runTimeout(cleanUpNextTick);
2445 draining = true;
2446
2447 var len = queue.length;
2448 while(len) {
2449 currentQueue = queue;
2450 queue = [];
2451 while (++queueIndex < len) {
2452 if (currentQueue) {
2453 currentQueue[queueIndex].run();
2454 }
2455 }
2456 queueIndex = -1;
2457 len = queue.length;
2458 }
2459 currentQueue = null;
2460 draining = false;
2461 runClearTimeout(timeout);
2462 }
2463
2464 process.nextTick = function (fun) {
2465 var args = new Array(arguments.length - 1);
2466 if (arguments.length > 1) {
2467 for (var i = 1; i < arguments.length; i++) {
2468 args[i - 1] = arguments[i];
2469 }
2470 }
2471 queue.push(new Item(fun, args));
2472 if (queue.length === 1 && !draining) {
2473 runTimeout(drainQueue);
2474 }
2475 };
2476
2477 // v8 likes predictible objects
2478 function Item(fun, array) {
2479 this.fun = fun;
2480 this.array = array;
2481 }
2482 Item.prototype.run = function () {
2483 this.fun.apply(null, this.array);
2484 };
2485 process.title = 'browser';
2486 process.browser = true;
2487 process.env = {};
2488 process.argv = [];
2489 process.version = ''; // empty string to avoid regexp issues
2490 process.versions = {};
2491
2492 function noop() {}
2493
2494 process.on = noop;
2495 process.addListener = noop;
2496 process.once = noop;
2497 process.off = noop;
2498 process.removeListener = noop;
2499 process.removeAllListeners = noop;
2500 process.emit = noop;
2501 process.prependListener = noop;
2502 process.prependOnceListener = noop;
2503
2504 process.listeners = function (name) { return [] }
2505
2506 process.binding = function (name) {
2507 throw new Error('process.binding is not supported');
2508 };
2509
2510 process.cwd = function () { return '/' };
2511 process.chdir = function (dir) {
2512 throw new Error('process.chdir is not supported');
2513 };
2514 process.umask = function() { return 0; };
2515
2516 },{}],7:[function(require,module,exports){
2517 (function (global){
2518 /*! https://mths.be/punycode v1.4.1 by @mathias */
2519 ;(function(root) {
2520
2521 /** Detect free variables */
2522 var freeExports = typeof exports == 'object' && exports &&
2523 !exports.nodeType && exports;
2524 var freeModule = typeof module == 'object' && module &&
2525 !module.nodeType && module;
2526 var freeGlobal = typeof global == 'object' && global;
2527 if (
2528 freeGlobal.global === freeGlobal ||
2529 freeGlobal.window === freeGlobal ||
2530 freeGlobal.self === freeGlobal
2531 ) {
2532 root = freeGlobal;
2533 }
2534
2535 /**
2536 * The `punycode` object.
2537 * @name punycode
2538 * @type Object
2539 */
2540 var punycode,
2541
2542 /** Highest positive signed 32-bit float value */
2543 maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
2544
2545 /** Bootstring parameters */
2546 base = 36,
2547 tMin = 1,
2548 tMax = 26,
2549 skew = 38,
2550 damp = 700,
2551 initialBias = 72,
2552 initialN = 128, // 0x80
2553 delimiter = '-', // '\x2D'
2554
2555 /** Regular expressions */
2556 regexPunycode = /^xn--/,
2557 regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
2558 regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
2559
2560 /** Error messages */
2561 errors = {
2562 'overflow': 'Overflow: input needs wider integers to process',
2563 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
2564 'invalid-input': 'Invalid input'
2565 },
2566
2567 /** Convenience shortcuts */
2568 baseMinusTMin = base - tMin,
2569 floor = Math.floor,
2570 stringFromCharCode = String.fromCharCode,
2571
2572 /** Temporary variable */
2573 key;
2574
2575 /*--------------------------------------------------------------------------*/
2576
2577 /**
2578 * A generic error utility function.
2579 * @private
2580 * @param {String} type The error type.
2581 * @returns {Error} Throws a `RangeError` with the applicable error message.
2582 */
2583 function error(type) {
2584 throw new RangeError(errors[type]);
2585 }
2586
2587 /**
2588 * A generic `Array#map` utility function.
2589 * @private
2590 * @param {Array} array The array to iterate over.
2591 * @param {Function} callback The function that gets called for every array
2592 * item.
2593 * @returns {Array} A new array of values returned by the callback function.
2594 */
2595 function map(array, fn) {
2596 var length = array.length;
2597 var result = [];
2598 while (length--) {
2599 result[length] = fn(array[length]);
2600 }
2601 return result;
2602 }
2603
2604 /**
2605 * A simple `Array#map`-like wrapper to work with domain name strings or email
2606 * addresses.
2607 * @private
2608 * @param {String} domain The domain name or email address.
2609 * @param {Function} callback The function that gets called for every
2610 * character.
2611 * @returns {Array} A new string of characters returned by the callback
2612 * function.
2613 */
2614 function mapDomain(string, fn) {
2615 var parts = string.split('@');
2616 var result = '';
2617 if (parts.length > 1) {
2618 // In email addresses, only the domain name should be punycoded. Leave
2619 // the local part (i.e. everything up to `@`) intact.
2620 result = parts[0] + '@';
2621 string = parts[1];
2622 }
2623 // Avoid `split(regex)` for IE8 compatibility. See #17.
2624 string = string.replace(regexSeparators, '\x2E');
2625 var labels = string.split('.');
2626 var encoded = map(labels, fn).join('.');
2627 return result + encoded;
2628 }
2629
2630 /**
2631 * Creates an array containing the numeric code points of each Unicode
2632 * character in the string. While JavaScript uses UCS-2 internally,
2633 * this function will convert a pair of surrogate halves (each of which
2634 * UCS-2 exposes as separate characters) into a single code point,
2635 * matching UTF-16.
2636 * @see `punycode.ucs2.encode`
2637 * @see <https://mathiasbynens.be/notes/javascript-encoding>
2638 * @memberOf punycode.ucs2
2639 * @name decode
2640 * @param {String} string The Unicode input string (UCS-2).
2641 * @returns {Array} The new array of code points.
2642 */
2643 function ucs2decode(string) {
2644 var output = [],
2645 counter = 0,
2646 length = string.length,
2647 value,
2648 extra;
2649 while (counter < length) {
2650 value = string.charCodeAt(counter++);
2651 if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
2652 // high surrogate, and there is a next character
2653 extra = string.charCodeAt(counter++);
2654 if ((extra & 0xFC00) == 0xDC00) { // low surrogate
2655 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
2656 } else {
2657 // unmatched surrogate; only append this code unit, in case the next
2658 // code unit is the high surrogate of a surrogate pair
2659 output.push(value);
2660 counter--;
2661 }
2662 } else {
2663 output.push(value);
2664 }
2665 }
2666 return output;
2667 }
2668
2669 /**
2670 * Creates a string based on an array of numeric code points.
2671 * @see `punycode.ucs2.decode`
2672 * @memberOf punycode.ucs2
2673 * @name encode
2674 * @param {Array} codePoints The array of numeric code points.
2675 * @returns {String} The new Unicode string (UCS-2).
2676 */
2677 function ucs2encode(array) {
2678 return map(array, function(value) {
2679 var output = '';
2680 if (value > 0xFFFF) {
2681 value -= 0x10000;
2682 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
2683 value = 0xDC00 | value & 0x3FF;
2684 }
2685 output += stringFromCharCode(value);
2686 return output;
2687 }).join('');
2688 }
2689
2690 /**
2691 * Converts a basic code point into a digit/integer.
2692 * @see `digitToBasic()`
2693 * @private
2694 * @param {Number} codePoint The basic numeric code point value.
2695 * @returns {Number} The numeric value of a basic code point (for use in
2696 * representing integers) in the range `0` to `base - 1`, or `base` if
2697 * the code point does not represent a value.
2698 */
2699 function basicToDigit(codePoint) {
2700 if (codePoint - 48 < 10) {
2701 return codePoint - 22;
2702 }
2703 if (codePoint - 65 < 26) {
2704 return codePoint - 65;
2705 }
2706 if (codePoint - 97 < 26) {
2707 return codePoint - 97;
2708 }
2709 return base;
2710 }
2711
2712 /**
2713 * Converts a digit/integer into a basic code point.
2714 * @see `basicToDigit()`
2715 * @private
2716 * @param {Number} digit The numeric value of a basic code point.
2717 * @returns {Number} The basic code point whose value (when used for
2718 * representing integers) is `digit`, which needs to be in the range
2719 * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
2720 * used; else, the lowercase form is used. The behavior is undefined
2721 * if `flag` is non-zero and `digit` has no uppercase form.
2722 */
2723 function digitToBasic(digit, flag) {
2724 // 0..25 map to ASCII a..z or A..Z
2725 // 26..35 map to ASCII 0..9
2726 return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
2727 }
2728
2729 /**
2730 * Bias adaptation function as per section 3.4 of RFC 3492.
2731 * https://tools.ietf.org/html/rfc3492#section-3.4
2732 * @private
2733 */
2734 function adapt(delta, numPoints, firstTime) {
2735 var k = 0;
2736 delta = firstTime ? floor(delta / damp) : delta >> 1;
2737 delta += floor(delta / numPoints);
2738 for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
2739 delta = floor(delta / baseMinusTMin);
2740 }
2741 return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
2742 }
2743
2744 /**
2745 * Converts a Punycode string of ASCII-only symbols to a string of Unicode
2746 * symbols.
2747 * @memberOf punycode
2748 * @param {String} input The Punycode string of ASCII-only symbols.
2749 * @returns {String} The resulting string of Unicode symbols.
2750 */
2751 function decode(input) {
2752 // Don't use UCS-2
2753 var output = [],
2754 inputLength = input.length,
2755 out,
2756 i = 0,
2757 n = initialN,
2758 bias = initialBias,
2759 basic,
2760 j,
2761 index,
2762 oldi,
2763 w,
2764 k,
2765 digit,
2766 t,
2767 /** Cached calculation results */
2768 baseMinusT;
2769
2770 // Handle the basic code points: let `basic` be the number of input code
2771 // points before the last delimiter, or `0` if there is none, then copy
2772 // the first basic code points to the output.
2773
2774 basic = input.lastIndexOf(delimiter);
2775 if (basic < 0) {
2776 basic = 0;
2777 }
2778
2779 for (j = 0; j < basic; ++j) {
2780 // if it's not a basic code point
2781 if (input.charCodeAt(j) >= 0x80) {
2782 error('not-basic');
2783 }
2784 output.push(input.charCodeAt(j));
2785 }
2786
2787 // Main decoding loop: start just after the last delimiter if any basic code
2788 // points were copied; start at the beginning otherwise.
2789
2790 for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
2791
2792 // `index` is the index of the next character to be consumed.
2793 // Decode a generalized variable-length integer into `delta`,
2794 // which gets added to `i`. The overflow checking is easier
2795 // if we increase `i` as we go, then subtract off its starting
2796 // value at the end to obtain `delta`.
2797 for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
2798
2799 if (index >= inputLength) {
2800 error('invalid-input');
2801 }
2802
2803 digit = basicToDigit(input.charCodeAt(index++));
2804
2805 if (digit >= base || digit > floor((maxInt - i) / w)) {
2806 error('overflow');
2807 }
2808
2809 i += digit * w;
2810 t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
2811
2812 if (digit < t) {
2813 break;
2814 }
2815
2816 baseMinusT = base - t;
2817 if (w > floor(maxInt / baseMinusT)) {
2818 error('overflow');
2819 }
2820
2821 w *= baseMinusT;
2822
2823 }
2824
2825 out = output.length + 1;
2826 bias = adapt(i - oldi, out, oldi == 0);
2827
2828 // `i` was supposed to wrap around from `out` to `0`,
2829 // incrementing `n` each time, so we'll fix that now:
2830 if (floor(i / out) > maxInt - n) {
2831 error('overflow');
2832 }
2833
2834 n += floor(i / out);
2835 i %= out;
2836
2837 // Insert `n` at position `i` of the output
2838 output.splice(i++, 0, n);
2839
2840 }
2841
2842 return ucs2encode(output);
2843 }
2844
2845 /**
2846 * Converts a string of Unicode symbols (e.g. a domain name label) to a
2847 * Punycode string of ASCII-only symbols.
2848 * @memberOf punycode
2849 * @param {String} input The string of Unicode symbols.
2850 * @returns {String} The resulting Punycode string of ASCII-only symbols.
2851 */
2852 function encode(input) {
2853 var n,
2854 delta,
2855 handledCPCount,
2856 basicLength,
2857 bias,
2858 j,
2859 m,
2860 q,
2861 k,
2862 t,
2863 currentValue,
2864 output = [],
2865 /** `inputLength` will hold the number of code points in `input`. */
2866 inputLength,
2867 /** Cached calculation results */
2868 handledCPCountPlusOne,
2869 baseMinusT,
2870 qMinusT;
2871
2872 // Convert the input in UCS-2 to Unicode
2873 input = ucs2decode(input);
2874
2875 // Cache the length
2876 inputLength = input.length;
2877
2878 // Initialize the state
2879 n = initialN;
2880 delta = 0;
2881 bias = initialBias;
2882
2883 // Handle the basic code points
2884 for (j = 0; j < inputLength; ++j) {
2885 currentValue = input[j];
2886 if (currentValue < 0x80) {
2887 output.push(stringFromCharCode(currentValue));
2888 }
2889 }
2890
2891 handledCPCount = basicLength = output.length;
2892
2893 // `handledCPCount` is the number of code points that have been handled;
2894 // `basicLength` is the number of basic code points.
2895
2896 // Finish the basic string - if it is not empty - with a delimiter
2897 if (basicLength) {
2898 output.push(delimiter);
2899 }
2900
2901 // Main encoding loop:
2902 while (handledCPCount < inputLength) {
2903
2904 // All non-basic code points < n have been handled already. Find the next
2905 // larger one:
2906 for (m = maxInt, j = 0; j < inputLength; ++j) {
2907 currentValue = input[j];
2908 if (currentValue >= n && currentValue < m) {
2909 m = currentValue;
2910 }
2911 }
2912
2913 // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
2914 // but guard against overflow
2915 handledCPCountPlusOne = handledCPCount + 1;
2916 if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
2917 error('overflow');
2918 }
2919
2920 delta += (m - n) * handledCPCountPlusOne;
2921 n = m;
2922
2923 for (j = 0; j < inputLength; ++j) {
2924 currentValue = input[j];
2925
2926 if (currentValue < n && ++delta > maxInt) {
2927 error('overflow');
2928 }
2929
2930 if (currentValue == n) {
2931 // Represent delta as a generalized variable-length integer
2932 for (q = delta, k = base; /* no condition */; k += base) {
2933 t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
2934 if (q < t) {
2935 break;
2936 }
2937 qMinusT = q - t;
2938 baseMinusT = base - t;
2939 output.push(
2940 stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
2941 );
2942 q = floor(qMinusT / baseMinusT);
2943 }
2944
2945 output.push(stringFromCharCode(digitToBasic(q, 0)));
2946 bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
2947 delta = 0;
2948 ++handledCPCount;
2949 }
2950 }
2951
2952 ++delta;
2953 ++n;
2954
2955 }
2956 return output.join('');
2957 }
2958
2959 /**
2960 * Converts a Punycode string representing a domain name or an email address
2961 * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
2962 * it doesn't matter if you call it on a string that has already been
2963 * converted to Unicode.
2964 * @memberOf punycode
2965 * @param {String} input The Punycoded domain name or email address to
2966 * convert to Unicode.
2967 * @returns {String} The Unicode representation of the given Punycode
2968 * string.
2969 */
2970 function toUnicode(input) {
2971 return mapDomain(input, function(string) {
2972 return regexPunycode.test(string)
2973 ? decode(string.slice(4).toLowerCase())
2974 : string;
2975 });
2976 }
2977
2978 /**
2979 * Converts a Unicode string representing a domain name or an email address to
2980 * Punycode. Only the non-ASCII parts of the domain name will be converted,
2981 * i.e. it doesn't matter if you call it with a domain that's already in
2982 * ASCII.
2983 * @memberOf punycode
2984 * @param {String} input The domain name or email address to convert, as a
2985 * Unicode string.
2986 * @returns {String} The Punycode representation of the given domain name or
2987 * email address.
2988 */
2989 function toASCII(input) {
2990 return mapDomain(input, function(string) {
2991 return regexNonASCII.test(string)
2992 ? 'xn--' + encode(string)
2993 : string;
2994 });
2995 }
2996
2997 /*--------------------------------------------------------------------------*/
2998
2999 /** Define the public API */
3000 punycode = {
3001 /**
3002 * A string representing the current Punycode.js version number.
3003 * @memberOf punycode
3004 * @type String
3005 */
3006 'version': '1.4.1',
3007 /**
3008 * An object of methods to convert from JavaScript's internal character
3009 * representation (UCS-2) to Unicode code points, and back.
3010 * @see <https://mathiasbynens.be/notes/javascript-encoding>
3011 * @memberOf punycode
3012 * @type Object
3013 */
3014 'ucs2': {
3015 'decode': ucs2decode,
3016 'encode': ucs2encode
3017 },
3018 'decode': decode,
3019 'encode': encode,
3020 'toASCII': toASCII,
3021 'toUnicode': toUnicode
3022 };
3023
3024 /** Expose `punycode` */
3025 // Some AMD build optimizers, like r.js, check for specific condition patterns
3026 // like the following:
3027 if (
3028 typeof define == 'function' &&
3029 typeof define.amd == 'object' &&
3030 define.amd
3031 ) {
3032 define('punycode', function() {
3033 return punycode;
3034 });
3035 } else if (freeExports && freeModule) {
3036 if (module.exports == freeExports) {
3037 // in Node.js, io.js, or RingoJS v0.8.0+
3038 freeModule.exports = punycode;
3039 } else {
3040 // in Narwhal or RingoJS v0.7.0-
3041 for (key in punycode) {
3042 punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
3043 }
3044 }
3045 } else {
3046 // in Rhino or a web browser
3047 root.punycode = punycode;
3048 }
3049
3050 }(this));
3051
3052 }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
3053 },{}],8:[function(require,module,exports){
3054 // Copyright Joyent, Inc. and other Node contributors.
3055 //
3056 // Permission is hereby granted, free of charge, to any person obtaining a
3057 // copy of this software and associated documentation files (the
3058 // "Software"), to deal in the Software without restriction, including
3059 // without limitation the rights to use, copy, modify, merge, publish,
3060 // distribute, sublicense, and/or sell copies of the Software, and to permit
3061 // persons to whom the Software is furnished to do so, subject to the
3062 // following conditions:
3063 //
3064 // The above copyright notice and this permission notice shall be included
3065 // in all copies or substantial portions of the Software.
3066 //
3067 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3068 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3069 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3070 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3071 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3072 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3073 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3074
3075 'use strict';
3076
3077 // If obj.hasOwnProperty has been overridden, then calling
3078 // obj.hasOwnProperty(prop) will break.
3079 // See: https://github.com/joyent/node/issues/1707
3080 function hasOwnProperty(obj, prop) {
3081 return Object.prototype.hasOwnProperty.call(obj, prop);
3082 }
3083
3084 module.exports = function(qs, sep, eq, options) {
3085 sep = sep || '&';
3086 eq = eq || '=';
3087 var obj = {};
3088
3089 if (typeof qs !== 'string' || qs.length === 0) {
3090 return obj;
3091 }
3092
3093 var regexp = /\+/g;
3094 qs = qs.split(sep);
3095
3096 var maxKeys = 1000;
3097 if (options && typeof options.maxKeys === 'number') {
3098 maxKeys = options.maxKeys;
3099 }
3100
3101 var len = qs.length;
3102 // maxKeys <= 0 means that we should not limit keys count
3103 if (maxKeys > 0 && len > maxKeys) {
3104 len = maxKeys;
3105 }
3106
3107 for (var i = 0; i < len; ++i) {
3108 var x = qs[i].replace(regexp, '%20'),
3109 idx = x.indexOf(eq),
3110 kstr, vstr, k, v;
3111
3112 if (idx >= 0) {
3113 kstr = x.substr(0, idx);
3114 vstr = x.substr(idx + 1);
3115 } else {
3116 kstr = x;
3117 vstr = '';
3118 }
3119
3120 k = decodeURIComponent(kstr);
3121 v = decodeURIComponent(vstr);
3122
3123 if (!hasOwnProperty(obj, k)) {
3124 obj[k] = v;
3125 } else if (isArray(obj[k])) {
3126 obj[k].push(v);
3127 } else {
3128 obj[k] = [obj[k], v];
3129 }
3130 }
3131
3132 return obj;
3133 };
3134
3135 var isArray = Array.isArray || function (xs) {
3136 return Object.prototype.toString.call(xs) === '[object Array]';
3137 };
3138
3139 },{}],9:[function(require,module,exports){
3140 // Copyright Joyent, Inc. and other Node contributors.
3141 //
3142 // Permission is hereby granted, free of charge, to any person obtaining a
3143 // copy of this software and associated documentation files (the
3144 // "Software"), to deal in the Software without restriction, including
3145 // without limitation the rights to use, copy, modify, merge, publish,
3146 // distribute, sublicense, and/or sell copies of the Software, and to permit
3147 // persons to whom the Software is furnished to do so, subject to the
3148 // following conditions:
3149 //
3150 // The above copyright notice and this permission notice shall be included
3151 // in all copies or substantial portions of the Software.
3152 //
3153 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3154 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3155 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3156 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3157 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3158 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3159 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3160
3161 'use strict';
3162
3163 var stringifyPrimitive = function(v) {
3164 switch (typeof v) {
3165 case 'string':
3166 return v;
3167
3168 case 'boolean':
3169 return v ? 'true' : 'false';
3170
3171 case 'number':
3172 return isFinite(v) ? v : '';
3173
3174 default:
3175 return '';
3176 }
3177 };
3178
3179 module.exports = function(obj, sep, eq, name) {
3180 sep = sep || '&';
3181 eq = eq || '=';
3182 if (obj === null) {
3183 obj = undefined;
3184 }
3185
3186 if (typeof obj === 'object') {
3187 return map(objectKeys(obj), function(k) {
3188 var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
3189 if (isArray(obj[k])) {
3190 return map(obj[k], function(v) {
3191 return ks + encodeURIComponent(stringifyPrimitive(v));
3192 }).join(sep);
3193 } else {
3194 return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
3195 }
3196 }).join(sep);
3197
3198 }
3199
3200 if (!name) return '';
3201 return encodeURIComponent(stringifyPrimitive(name)) + eq +
3202 encodeURIComponent(stringifyPrimitive(obj));
3203 };
3204
3205 var isArray = Array.isArray || function (xs) {
3206 return Object.prototype.toString.call(xs) === '[object Array]';
3207 };
3208
3209 function map (xs, f) {
3210 if (xs.map) return xs.map(f);
3211 var res = [];
3212 for (var i = 0; i < xs.length; i++) {
3213 res.push(f(xs[i], i));
3214 }
3215 return res;
3216 }
3217
3218 var objectKeys = Object.keys || function (obj) {
3219 var res = [];
3220 for (var key in obj) {
3221 if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
3222 }
3223 return res;
3224 };
3225
3226 },{}],10:[function(require,module,exports){
3227 'use strict';
3228
3229 exports.decode = exports.parse = require('./decode');
3230 exports.encode = exports.stringify = require('./encode');
3231
3232 },{"./decode":8,"./encode":9}],11:[function(require,module,exports){
3233 (function (setImmediate,clearImmediate){
3234 var nextTick = require('process/browser.js').nextTick;
3235 var apply = Function.prototype.apply;
3236 var slice = Array.prototype.slice;
3237 var immediateIds = {};
3238 var nextImmediateId = 0;
3239
3240 // DOM APIs, for completeness
3241
3242 exports.setTimeout = function() {
3243 return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
3244 };
3245 exports.setInterval = function() {
3246 return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
3247 };
3248 exports.clearTimeout =
3249 exports.clearInterval = function(timeout) { timeout.close(); };
3250
3251 function Timeout(id, clearFn) {
3252 this._id = id;
3253 this._clearFn = clearFn;
3254 }
3255 Timeout.prototype.unref = Timeout.prototype.ref = function() {};
3256 Timeout.prototype.close = function() {
3257 this._clearFn.call(window, this._id);
3258 };
3259
3260 // Does not start the time, just sets up the members needed.
3261 exports.enroll = function(item, msecs) {
3262 clearTimeout(item._idleTimeoutId);
3263 item._idleTimeout = msecs;
3264 };
3265
3266 exports.unenroll = function(item) {
3267 clearTimeout(item._idleTimeoutId);
3268 item._idleTimeout = -1;
3269 };
3270
3271 exports._unrefActive = exports.active = function(item) {
3272 clearTimeout(item._idleTimeoutId);
3273
3274 var msecs = item._idleTimeout;
3275 if (msecs >= 0) {
3276 item._idleTimeoutId = setTimeout(function onTimeout() {
3277 if (item._onTimeout)
3278 item._onTimeout();
3279 }, msecs);
3280 }
3281 };
3282
3283 // That's not how node.js implements it but the exposed api is the same.
3284 exports.setImmediate = typeof setImmediate === "function" ? setImmediate : function(fn) {
3285 var id = nextImmediateId++;
3286 var args = arguments.length < 2 ? false : slice.call(arguments, 1);
3287
3288 immediateIds[id] = true;
3289
3290 nextTick(function onNextTick() {
3291 if (immediateIds[id]) {
3292 // fn.call() is faster so we optimize for the common use-case
3293 // @see http://jsperf.com/call-apply-segu
3294 if (args) {
3295 fn.apply(null, args);
3296 } else {
3297 fn.call(null);
3298 }
3299 // Prevent ids from leaking
3300 exports.clearImmediate(id);
3301 }
3302 });
3303
3304 return id;
3305 };
3306
3307 exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate : function(id) {
3308 delete immediateIds[id];
3309 };
3310 }).call(this,require("timers").setImmediate,require("timers").clearImmediate)
3311 },{"process/browser.js":6,"timers":11}],12:[function(require,module,exports){
3312 // Copyright Joyent, Inc. and other Node contributors.
3313 //
3314 // Permission is hereby granted, free of charge, to any person obtaining a
3315 // copy of this software and associated documentation files (the
3316 // "Software"), to deal in the Software without restriction, including
3317 // without limitation the rights to use, copy, modify, merge, publish,
3318 // distribute, sublicense, and/or sell copies of the Software, and to permit
3319 // persons to whom the Software is furnished to do so, subject to the
3320 // following conditions:
3321 //
3322 // The above copyright notice and this permission notice shall be included
3323 // in all copies or substantial portions of the Software.
3324 //
3325 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
3326 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3327 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
3328 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
3329 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
3330 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
3331 // USE OR OTHER DEALINGS IN THE SOFTWARE.
3332
3333 'use strict';
3334
3335 var punycode = require('punycode');
3336 var util = require('./util');
3337
3338 exports.parse = urlParse;
3339 exports.resolve = urlResolve;
3340 exports.resolveObject = urlResolveObject;
3341 exports.format = urlFormat;
3342
3343 exports.Url = Url;
3344
3345 function Url() {
3346 this.protocol = null;
3347 this.slashes = null;
3348 this.auth = null;
3349 this.host = null;
3350 this.port = null;
3351 this.hostname = null;
3352 this.hash = null;
3353 this.search = null;
3354 this.query = null;
3355 this.pathname = null;
3356 this.path = null;
3357 this.href = null;
3358 }
3359
3360 // Reference: RFC 3986, RFC 1808, RFC 2396
3361
3362 // define these here so at least they only have to be
3363 // compiled once on the first module load.
3364 var protocolPattern = /^([a-z0-9.+-]+:)/i,
3365 portPattern = /:[0-9]*$/,
3366
3367 // Special case for a simple path URL
3368 simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
3369
3370 // RFC 2396: characters reserved for delimiting URLs.
3371 // We actually just auto-escape these.
3372 delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
3373
3374 // RFC 2396: characters not allowed for various reasons.
3375 unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
3376
3377 // Allowed by RFCs, but cause of XSS attacks. Always escape these.
3378 autoEscape = ['\''].concat(unwise),
3379 // Characters that are never ever allowed in a hostname.
3380 // Note that any invalid chars are also handled, but these
3381 // are the ones that are *expected* to be seen, so we fast-path
3382 // them.
3383 nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
3384 hostEndingChars = ['/', '?', '#'],
3385 hostnameMaxLen = 255,
3386 hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
3387 hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
3388 // protocols that can allow "unsafe" and "unwise" chars.
3389 unsafeProtocol = {
3390 'javascript': true,
3391 'javascript:': true
3392 },
3393 // protocols that never have a hostname.
3394 hostlessProtocol = {
3395 'javascript': true,
3396 'javascript:': true
3397 },
3398 // protocols that always contain a // bit.
3399 slashedProtocol = {
3400 'http': true,
3401 'https': true,
3402 'ftp': true,
3403 'gopher': true,
3404 'file': true,
3405 'http:': true,
3406 'https:': true,
3407 'ftp:': true,
3408 'gopher:': true,
3409 'file:': true
3410 },
3411 querystring = require('querystring');
3412
3413 function urlParse(url, parseQueryString, slashesDenoteHost) {
3414 if (url && util.isObject(url) && url instanceof Url) return url;
3415
3416 var u = new Url;
3417 u.parse(url, parseQueryString, slashesDenoteHost);
3418 return u;
3419 }
3420
3421 Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
3422 if (!util.isString(url)) {
3423 throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
3424 }
3425
3426 // Copy chrome, IE, opera backslash-handling behavior.
3427 // Back slashes before the query string get converted to forward slashes
3428 // See: https://code.google.com/p/chromium/issues/detail?id=25916
3429 var queryIndex = url.indexOf('?'),
3430 splitter =
3431 (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
3432 uSplit = url.split(splitter),
3433 slashRegex = /\\/g;
3434 uSplit[0] = uSplit[0].replace(slashRegex, '/');
3435 url = uSplit.join(splitter);
3436
3437 var rest = url;
3438
3439 // trim before proceeding.
3440 // This is to support parse stuff like " http://foo.com \n"
3441 rest = rest.trim();
3442
3443 if (!slashesDenoteHost && url.split('#').length === 1) {
3444 // Try fast path regexp
3445 var simplePath = simplePathPattern.exec(rest);
3446 if (simplePath) {
3447 this.path = rest;
3448 this.href = rest;
3449 this.pathname = simplePath[1];
3450 if (simplePath[2]) {
3451 this.search = simplePath[2];
3452 if (parseQueryString) {
3453 this.query = querystring.parse(this.search.substr(1));
3454 } else {
3455 this.query = this.search.substr(1);
3456 }
3457 } else if (parseQueryString) {
3458 this.search = '';
3459 this.query = {};
3460 }
3461 return this;
3462 }
3463 }
3464
3465 var proto = protocolPattern.exec(rest);
3466 if (proto) {
3467 proto = proto[0];
3468 var lowerProto = proto.toLowerCase();
3469 this.protocol = lowerProto;
3470 rest = rest.substr(proto.length);
3471 }
3472
3473 // figure out if it's got a host
3474 // user@server is *always* interpreted as a hostname, and url
3475 // resolution will treat //foo/bar as host=foo,path=bar because that's
3476 // how the browser resolves relative URLs.
3477 if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
3478 var slashes = rest.substr(0, 2) === '//';
3479 if (slashes && !(proto && hostlessProtocol[proto])) {
3480 rest = rest.substr(2);
3481 this.slashes = true;
3482 }
3483 }
3484
3485 if (!hostlessProtocol[proto] &&
3486 (slashes || (proto && !slashedProtocol[proto]))) {
3487
3488 // there's a hostname.
3489 // the first instance of /, ?, ;, or # ends the host.
3490 //
3491 // If there is an @ in the hostname, then non-host chars *are* allowed
3492 // to the left of the last @ sign, unless some host-ending character
3493 // comes *before* the @-sign.
3494 // URLs are obnoxious.
3495 //
3496 // ex:
3497 // http://a@b@c/ => user:a@b host:c
3498 // http://a@b?@c => user:a host:c path:/?@c
3499
3500 // v0.12 TODO(isaacs): This is not quite how Chrome does things.
3501 // Review our test case against browsers more comprehensively.
3502
3503 // find the first instance of any hostEndingChars
3504 var hostEnd = -1;
3505 for (var i = 0; i < hostEndingChars.length; i++) {
3506 var hec = rest.indexOf(hostEndingChars[i]);
3507 if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
3508 hostEnd = hec;
3509 }
3510
3511 // at this point, either we have an explicit point where the
3512 // auth portion cannot go past, or the last @ char is the decider.
3513 var auth, atSign;
3514 if (hostEnd === -1) {
3515 // atSign can be anywhere.
3516 atSign = rest.lastIndexOf('@');
3517 } else {
3518 // atSign must be in auth portion.
3519 // http://a@b/c@d => host:b auth:a path:/c@d
3520 atSign = rest.lastIndexOf('@', hostEnd);
3521 }
3522
3523 // Now we have a portion which is definitely the auth.
3524 // Pull that off.
3525 if (atSign !== -1) {
3526 auth = rest.slice(0, atSign);
3527 rest = rest.slice(atSign + 1);
3528 this.auth = decodeURIComponent(auth);
3529 }
3530
3531 // the host is the remaining to the left of the first non-host char
3532 hostEnd = -1;
3533 for (var i = 0; i < nonHostChars.length; i++) {
3534 var hec = rest.indexOf(nonHostChars[i]);
3535 if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
3536 hostEnd = hec;
3537 }
3538 // if we still have not hit it, then the entire thing is a host.
3539 if (hostEnd === -1)
3540 hostEnd = rest.length;
3541
3542 this.host = rest.slice(0, hostEnd);
3543 rest = rest.slice(hostEnd);
3544
3545 // pull out port.
3546 this.parseHost();
3547
3548 // we've indicated that there is a hostname,
3549 // so even if it's empty, it has to be present.
3550 this.hostname = this.hostname || '';
3551
3552 // if hostname begins with [ and ends with ]
3553 // assume that it's an IPv6 address.
3554 var ipv6Hostname = this.hostname[0] === '[' &&
3555 this.hostname[this.hostname.length - 1] === ']';
3556
3557 // validate a little.
3558 if (!ipv6Hostname) {
3559 var hostparts = this.hostname.split(/\./);
3560 for (var i = 0, l = hostparts.length; i < l; i++) {
3561 var part = hostparts[i];
3562 if (!part) continue;
3563 if (!part.match(hostnamePartPattern)) {
3564 var newpart = '';
3565 for (var j = 0, k = part.length; j < k; j++) {
3566 if (part.charCodeAt(j) > 127) {
3567 // we replace non-ASCII char with a temporary placeholder
3568 // we need this to make sure size of hostname is not
3569 // broken by replacing non-ASCII by nothing
3570 newpart += 'x';
3571 } else {
3572 newpart += part[j];
3573 }
3574 }
3575 // we test again with ASCII char only
3576 if (!newpart.match(hostnamePartPattern)) {
3577 var validParts = hostparts.slice(0, i);
3578 var notHost = hostparts.slice(i + 1);
3579 var bit = part.match(hostnamePartStart);
3580 if (bit) {
3581 validParts.push(bit[1]);
3582 notHost.unshift(bit[2]);
3583 }
3584 if (notHost.length) {
3585 rest = '/' + notHost.join('.') + rest;
3586 }
3587 this.hostname = validParts.join('.');
3588 break;
3589 }
3590 }
3591 }
3592 }
3593
3594 if (this.hostname.length > hostnameMaxLen) {
3595 this.hostname = '';
3596 } else {
3597 // hostnames are always lower case.
3598 this.hostname = this.hostname.toLowerCase();
3599 }
3600
3601 if (!ipv6Hostname) {
3602 // IDNA Support: Returns a punycoded representation of "domain".
3603 // It only converts parts of the domain name that
3604 // have non-ASCII characters, i.e. it doesn't matter if
3605 // you call it with a domain that already is ASCII-only.
3606 this.hostname = punycode.toASCII(this.hostname);
3607 }
3608
3609 var p = this.port ? ':' + this.port : '';
3610 var h = this.hostname || '';
3611 this.host = h + p;
3612 this.href += this.host;
3613
3614 // strip [ and ] from the hostname
3615 // the host field still retains them, though
3616 if (ipv6Hostname) {
3617 this.hostname = this.hostname.substr(1, this.hostname.length - 2);
3618 if (rest[0] !== '/') {
3619 rest = '/' + rest;
3620 }
3621 }
3622 }
3623
3624 // now rest is set to the post-host stuff.
3625 // chop off any delim chars.
3626 if (!unsafeProtocol[lowerProto]) {
3627
3628 // First, make 100% sure that any "autoEscape" chars get
3629 // escaped, even if encodeURIComponent doesn't think they
3630 // need to be.
3631 for (var i = 0, l = autoEscape.length; i < l; i++) {
3632 var ae = autoEscape[i];
3633 if (rest.indexOf(ae) === -1)
3634 continue;
3635 var esc = encodeURIComponent(ae);
3636 if (esc === ae) {
3637 esc = escape(ae);
3638 }
3639 rest = rest.split(ae).join(esc);
3640 }
3641 }
3642
3643
3644 // chop off from the tail first.
3645 var hash = rest.indexOf('#');
3646 if (hash !== -1) {
3647 // got a fragment string.
3648 this.hash = rest.substr(hash);
3649 rest = rest.slice(0, hash);
3650 }
3651 var qm = rest.indexOf('?');
3652 if (qm !== -1) {
3653 this.search = rest.substr(qm);
3654 this.query = rest.substr(qm + 1);
3655 if (parseQueryString) {
3656 this.query = querystring.parse(this.query);
3657 }
3658 rest = rest.slice(0, qm);
3659 } else if (parseQueryString) {
3660 // no query string, but parseQueryString still requested
3661 this.search = '';
3662 this.query = {};
3663 }
3664 if (rest) this.pathname = rest;
3665 if (slashedProtocol[lowerProto] &&
3666 this.hostname && !this.pathname) {
3667 this.pathname = '/';
3668 }
3669
3670 //to support http.request
3671 if (this.pathname || this.search) {
3672 var p = this.pathname || '';
3673 var s = this.search || '';
3674 this.path = p + s;
3675 }
3676
3677 // finally, reconstruct the href based on what has been validated.
3678 this.href = this.format();
3679 return this;
3680 };
3681
3682 // format a parsed object into a url string
3683 function urlFormat(obj) {
3684 // ensure it's an object, and not a string url.
3685 // If it's an obj, this is a no-op.
3686 // this way, you can call url_format() on strings
3687 // to clean up potentially wonky urls.
3688 if (util.isString(obj)) obj = urlParse(obj);
3689 if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
3690 return obj.format();
3691 }
3692
3693 Url.prototype.format = function() {
3694 var auth = this.auth || '';
3695 if (auth) {
3696 auth = encodeURIComponent(auth);
3697 auth = auth.replace(/%3A/i, ':');
3698 auth += '@';
3699 }
3700
3701 var protocol = this.protocol || '',
3702 pathname = this.pathname || '',
3703 hash = this.hash || '',
3704 host = false,
3705 query = '';
3706
3707 if (this.host) {
3708 host = auth + this.host;
3709 } else if (this.hostname) {
3710 host = auth + (this.hostname.indexOf(':') === -1 ?
3711 this.hostname :
3712 '[' + this.hostname + ']');
3713 if (this.port) {
3714 host += ':' + this.port;
3715 }
3716 }
3717
3718 if (this.query &&
3719 util.isObject(this.query) &&
3720 Object.keys(this.query).length) {
3721 query = querystring.stringify(this.query);
3722 }
3723
3724 var search = this.search || (query && ('?' + query)) || '';
3725
3726 if (protocol && protocol.substr(-1) !== ':') protocol += ':';
3727
3728 // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
3729 // unless they had them to begin with.
3730 if (this.slashes ||
3731 (!protocol || slashedProtocol[protocol]) && host !== false) {
3732 host = '//' + (host || '');
3733 if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
3734 } else if (!host) {
3735 host = '';
3736 }
3737
3738 if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
3739 if (search && search.charAt(0) !== '?') search = '?' + search;
3740
3741 pathname = pathname.replace(/[?#]/g, function(match) {
3742 return encodeURIComponent(match);
3743 });
3744 search = search.replace('#', '%23');
3745
3746 return protocol + host + pathname + search + hash;
3747 };
3748
3749 function urlResolve(source, relative) {
3750 return urlParse(source, false, true).resolve(relative);
3751 }
3752
3753 Url.prototype.resolve = function(relative) {
3754 return this.resolveObject(urlParse(relative, false, true)).format();
3755 };
3756
3757 function urlResolveObject(source, relative) {
3758 if (!source) return relative;
3759 return urlParse(source, false, true).resolveObject(relative);
3760 }
3761
3762 Url.prototype.resolveObject = function(relative) {
3763 if (util.isString(relative)) {
3764 var rel = new Url();
3765 rel.parse(relative, false, true);
3766 relative = rel;
3767 }
3768
3769 var result = new Url();
3770 var tkeys = Object.keys(this);
3771 for (var tk = 0; tk < tkeys.length; tk++) {
3772 var tkey = tkeys[tk];
3773 result[tkey] = this[tkey];
3774 }
3775
3776 // hash is always overridden, no matter what.
3777 // even href="" will remove it.
3778 result.hash = relative.hash;
3779
3780 // if the relative url is empty, then there's nothing left to do here.
3781 if (relative.href === '') {
3782 result.href = result.format();
3783 return result;
3784 }
3785
3786 // hrefs like //foo/bar always cut to the protocol.
3787 if (relative.slashes && !relative.protocol) {
3788 // take everything except the protocol from relative
3789 var rkeys = Object.keys(relative);
3790 for (var rk = 0; rk < rkeys.length; rk++) {
3791 var rkey = rkeys[rk];
3792 if (rkey !== 'protocol')
3793 result[rkey] = relative[rkey];
3794 }
3795
3796 //urlParse appends trailing / to urls like http://www.example.com
3797 if (slashedProtocol[result.protocol] &&
3798 result.hostname && !result.pathname) {
3799 result.path = result.pathname = '/';
3800 }
3801
3802 result.href = result.format();
3803 return result;
3804 }
3805
3806 if (relative.protocol && relative.protocol !== result.protocol) {
3807 // if it's a known url protocol, then changing
3808 // the protocol does weird things
3809 // first, if it's not file:, then we MUST have a host,
3810 // and if there was a path
3811 // to begin with, then we MUST have a path.
3812 // if it is file:, then the host is dropped,
3813 // because that's known to be hostless.
3814 // anything else is assumed to be absolute.
3815 if (!slashedProtocol[relative.protocol]) {
3816 var keys = Object.keys(relative);
3817 for (var v = 0; v < keys.length; v++) {
3818 var k = keys[v];
3819 result[k] = relative[k];
3820 }
3821 result.href = result.format();
3822 return result;
3823 }
3824
3825 result.protocol = relative.protocol;
3826 if (!relative.host && !hostlessProtocol[relative.protocol]) {
3827 var relPath = (relative.pathname || '').split('/');
3828 while (relPath.length && !(relative.host = relPath.shift()));
3829 if (!relative.host) relative.host = '';
3830 if (!relative.hostname) relative.hostname = '';
3831 if (relPath[0] !== '') relPath.unshift('');
3832 if (relPath.length < 2) relPath.unshift('');
3833 result.pathname = relPath.join('/');
3834 } else {
3835 result.pathname = relative.pathname;
3836 }
3837 result.search = relative.search;
3838 result.query = relative.query;
3839 result.host = relative.host || '';
3840 result.auth = relative.auth;
3841 result.hostname = relative.hostname || relative.host;
3842 result.port = relative.port;
3843 // to support http.request
3844 if (result.pathname || result.search) {
3845 var p = result.pathname || '';
3846 var s = result.search || '';
3847 result.path = p + s;
3848 }
3849 result.slashes = result.slashes || relative.slashes;
3850 result.href = result.format();
3851 return result;
3852 }
3853
3854 var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
3855 isRelAbs = (
3856 relative.host ||
3857 relative.pathname && relative.pathname.charAt(0) === '/'
3858 ),
3859 mustEndAbs = (isRelAbs || isSourceAbs ||
3860 (result.host && relative.pathname)),
3861 removeAllDots = mustEndAbs,
3862 srcPath = result.pathname && result.pathname.split('/') || [],
3863 relPath = relative.pathname && relative.pathname.split('/') || [],
3864 psychotic = result.protocol && !slashedProtocol[result.protocol];
3865
3866 // if the url is a non-slashed url, then relative
3867 // links like ../.. should be able
3868 // to crawl up to the hostname, as well. This is strange.
3869 // result.protocol has already been set by now.
3870 // Later on, put the first path part into the host field.
3871 if (psychotic) {
3872 result.hostname = '';
3873 result.port = null;
3874 if (result.host) {
3875 if (srcPath[0] === '') srcPath[0] = result.host;
3876 else srcPath.unshift(result.host);
3877 }
3878 result.host = '';
3879 if (relative.protocol) {
3880 relative.hostname = null;
3881 relative.port = null;
3882 if (relative.host) {
3883 if (relPath[0] === '') relPath[0] = relative.host;
3884 else relPath.unshift(relative.host);
3885 }
3886 relative.host = null;
3887 }
3888 mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
3889 }
3890
3891 if (isRelAbs) {
3892 // it's absolute.
3893 result.host = (relative.host || relative.host === '') ?
3894 relative.host : result.host;
3895 result.hostname = (relative.hostname || relative.hostname === '') ?
3896 relative.hostname : result.hostname;
3897 result.search = relative.search;
3898 result.query = relative.query;
3899 srcPath = relPath;
3900 // fall through to the dot-handling below.
3901 } else if (relPath.length) {
3902 // it's relative
3903 // throw away the existing file, and take the new path instead.
3904 if (!srcPath) srcPath = [];
3905 srcPath.pop();
3906 srcPath = srcPath.concat(relPath);
3907 result.search = relative.search;
3908 result.query = relative.query;
3909 } else if (!util.isNullOrUndefined(relative.search)) {
3910 // just pull out the search.
3911 // like href='?foo'.
3912 // Put this after the other two cases because it simplifies the booleans
3913 if (psychotic) {
3914 result.hostname = result.host = srcPath.shift();
3915 //occationaly the auth can get stuck only in host
3916 //this especially happens in cases like
3917 //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
3918 var authInHost = result.host && result.host.indexOf('@') > 0 ?
3919 result.host.split('@') : false;
3920 if (authInHost) {
3921 result.auth = authInHost.shift();
3922 result.host = result.hostname = authInHost.shift();
3923 }
3924 }
3925 result.search = relative.search;
3926 result.query = relative.query;
3927 //to support http.request
3928 if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
3929 result.path = (result.pathname ? result.pathname : '') +
3930 (result.search ? result.search : '');
3931 }
3932 result.href = result.format();
3933 return result;
3934 }
3935
3936 if (!srcPath.length) {
3937 // no path at all. easy.
3938 // we've already handled the other stuff above.
3939 result.pathname = null;
3940 //to support http.request
3941 if (result.search) {
3942 result.path = '/' + result.search;
3943 } else {
3944 result.path = null;
3945 }
3946 result.href = result.format();
3947 return result;
3948 }
3949
3950 // if a url ENDs in . or .., then it must get a trailing slash.
3951 // however, if it ends in anything else non-slashy,
3952 // then it must NOT get a trailing slash.
3953 var last = srcPath.slice(-1)[0];
3954 var hasTrailingSlash = (
3955 (result.host || relative.host || srcPath.length > 1) &&
3956 (last === '.' || last === '..') || last === '');
3957
3958 // strip single dots, resolve double dots to parent dir
3959 // if the path tries to go above the root, `up` ends up > 0
3960 var up = 0;
3961 for (var i = srcPath.length; i >= 0; i--) {
3962 last = srcPath[i];
3963 if (last === '.') {
3964 srcPath.splice(i, 1);
3965 } else if (last === '..') {
3966 srcPath.splice(i, 1);
3967 up++;
3968 } else if (up) {
3969 srcPath.splice(i, 1);
3970 up--;
3971 }
3972 }
3973
3974 // if the path is allowed to go above the root, restore leading ..s
3975 if (!mustEndAbs && !removeAllDots) {
3976 for (; up--; up) {
3977 srcPath.unshift('..');
3978 }
3979 }
3980
3981 if (mustEndAbs && srcPath[0] !== '' &&
3982 (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
3983 srcPath.unshift('');
3984 }
3985
3986 if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
3987 srcPath.push('');
3988 }
3989
3990 var isAbsolute = srcPath[0] === '' ||
3991 (srcPath[0] && srcPath[0].charAt(0) === '/');
3992
3993 // put the host back
3994 if (psychotic) {
3995 result.hostname = result.host = isAbsolute ? '' :
3996 srcPath.length ? srcPath.shift() : '';
3997 //occationaly the auth can get stuck only in host
3998 //this especially happens in cases like
3999 //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
4000 var authInHost = result.host && result.host.indexOf('@') > 0 ?
4001 result.host.split('@') : false;
4002 if (authInHost) {
4003 result.auth = authInHost.shift();
4004 result.host = result.hostname = authInHost.shift();
4005 }
4006 }
4007
4008 mustEndAbs = mustEndAbs || (result.host && srcPath.length);
4009
4010 if (mustEndAbs && !isAbsolute) {
4011 srcPath.unshift('');
4012 }
4013
4014 if (!srcPath.length) {
4015 result.pathname = null;
4016 result.path = null;
4017 } else {
4018 result.pathname = srcPath.join('/');
4019 }
4020
4021 //to support request.http
4022 if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
4023 result.path = (result.pathname ? result.pathname : '') +
4024 (result.search ? result.search : '');
4025 }
4026 result.auth = relative.auth || result.auth;
4027 result.slashes = result.slashes || relative.slashes;
4028 result.href = result.format();
4029 return result;
4030 };
4031
4032 Url.prototype.parseHost = function() {
4033 var host = this.host;
4034 var port = portPattern.exec(host);
4035 if (port) {
4036 port = port[0];
4037 if (port !== ':') {
4038 this.port = port.substr(1);
4039 }
4040 host = host.substr(0, host.length - port.length);
4041 }
4042 if (host) this.hostname = host;
4043 };
4044
4045 },{"./util":13,"punycode":7,"querystring":10}],13:[function(require,module,exports){
4046 'use strict';
4047
4048 module.exports = {
4049 isString: function(arg) {
4050 return typeof(arg) === 'string';
4051 },
4052 isObject: function(arg) {
4053 return typeof(arg) === 'object' && arg !== null;
4054 },
4055 isNull: function(arg) {
4056 return arg === null;
4057 },
4058 isNullOrUndefined: function(arg) {
4059 return arg == null;
4060 }
4061 };
4062
4063 },{}],14:[function(require,module,exports){
4064 //This is for browserify to build the required CSS module into something we can use in the browser.
4065 window.css = require('css');
4066
4067 },{"css":16}],15:[function(require,module,exports){
4068 (function (Buffer){
4069 (function (w) {
4070 "use strict";
4071
4072 function findBest(atobNative) {
4073 // normal window
4074 if ('function' === typeof atobNative) { return atobNative; }
4075
4076
4077 // browserify (web worker)
4078 if ('function' === typeof Buffer) {
4079 return function atobBrowserify(a) {
4080 //!! Deliberately using an API that's deprecated in node.js because
4081 //!! this file is for browsers and we expect them to cope with it.
4082 //!! Discussion: github.com/node-browser-compat/atob/pull/9
4083 return new Buffer(a, 'base64').toString('binary');
4084 };
4085 }
4086
4087 // ios web worker with base64js
4088 if ('object' === typeof w.base64js) {
4089 // bufferToBinaryString
4090 // https://git.coolaj86.com/coolaj86/unibabel.js/blob/master/index.js#L50
4091 return function atobWebWorker_iOS(a) {
4092 var buf = w.base64js.b64ToByteArray(a);
4093 return Array.prototype.map.call(buf, function (ch) {
4094 return String.fromCharCode(ch);
4095 }).join('');
4096 };
4097 }
4098
4099 return function () {
4100 // ios web worker without base64js
4101 throw new Error("You're probably in an old browser or an iOS webworker." +
4102 " It might help to include beatgammit's base64-js.");
4103 };
4104 }
4105
4106 var atobBest = findBest(w.atob);
4107 w.atob = atobBest;
4108
4109 if ((typeof module === 'object') && module && module.exports) {
4110 module.exports = atobBest;
4111 }
4112 }(window));
4113
4114 }).call(this,require("buffer").Buffer)
4115 },{"buffer":3}],16:[function(require,module,exports){
4116 exports.parse = require('./lib/parse');
4117 exports.stringify = require('./lib/stringify');
4118
4119 },{"./lib/parse":17,"./lib/stringify":21}],17:[function(require,module,exports){
4120 // http://www.w3.org/TR/CSS21/grammar.html
4121 // https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
4122 var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g
4123
4124 module.exports = function(css, options){
4125 options = options || {};
4126
4127 /**
4128 * Positional.
4129 */
4130
4131 var lineno = 1;
4132 var column = 1;
4133
4134 /**
4135 * Update lineno and column based on `str`.
4136 */
4137
4138 function updatePosition(str) {
4139 var lines = str.match(/\n/g);
4140 if (lines) lineno += lines.length;
4141 var i = str.lastIndexOf('\n');
4142 column = ~i ? str.length - i : column + str.length;
4143 }
4144
4145 /**
4146 * Mark position and patch `node.position`.
4147 */
4148
4149 function position() {
4150 var start = { line: lineno, column: column };
4151 return function(node){
4152 node.position = new Position(start);
4153 whitespace();
4154 return node;
4155 };
4156 }
4157
4158 /**
4159 * Store position information for a node
4160 */
4161
4162 function Position(start) {
4163 this.start = start;
4164 this.end = { line: lineno, column: column };
4165 this.source = options.source;
4166 }
4167
4168 /**
4169 * Non-enumerable source string
4170 */
4171
4172 Position.prototype.content = css;
4173
4174 /**
4175 * Error `msg`.
4176 */
4177
4178 var errorsList = [];
4179
4180 function error(msg) {
4181 var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
4182 err.reason = msg;
4183 err.filename = options.source;
4184 err.line = lineno;
4185 err.column = column;
4186 err.source = css;
4187
4188 if (options.silent) {
4189 errorsList.push(err);
4190 } else {
4191 throw err;
4192 }
4193 }
4194
4195 /**
4196 * Parse stylesheet.
4197 */
4198
4199 function stylesheet() {
4200 var rulesList = rules();
4201
4202 return {
4203 type: 'stylesheet',
4204 stylesheet: {
4205 source: options.source,
4206 rules: rulesList,
4207 parsingErrors: errorsList
4208 }
4209 };
4210 }
4211
4212 /**
4213 * Opening brace.
4214 */
4215
4216 function open() {
4217 return match(/^{\s*/);
4218 }
4219
4220 /**
4221 * Closing brace.
4222 */
4223
4224 function close() {
4225 return match(/^}/);
4226 }
4227
4228 /**
4229 * Parse ruleset.
4230 */
4231
4232 function rules() {
4233 var node;
4234 var rules = [];
4235 whitespace();
4236 comments(rules);
4237 while (css.length && css.charAt(0) != '}' && (node = atrule() || rule())) {
4238 if (node !== false) {
4239 rules.push(node);
4240 comments(rules);
4241 }
4242 }
4243 return rules;
4244 }
4245
4246 /**
4247 * Match `re` and return captures.
4248 */
4249
4250 function match(re) {
4251 var m = re.exec(css);
4252 if (!m) return;
4253 var str = m[0];
4254 updatePosition(str);
4255 css = css.slice(str.length);
4256 return m;
4257 }
4258
4259 /**
4260 * Parse whitespace.
4261 */
4262
4263 function whitespace() {
4264 match(/^\s*/);
4265 }
4266
4267 /**
4268 * Parse comments;
4269 */
4270
4271 function comments(rules) {
4272 var c;
4273 rules = rules || [];
4274 while (c = comment()) {
4275 if (c !== false) {
4276 rules.push(c);
4277 }
4278 }
4279 return rules;
4280 }
4281
4282 /**
4283 * Parse comment.
4284 */
4285
4286 function comment() {
4287 var pos = position();
4288 if ('/' != css.charAt(0) || '*' != css.charAt(1)) return;
4289
4290 var i = 2;
4291 while ("" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;
4292 i += 2;
4293
4294 if ("" === css.charAt(i-1)) {
4295 return error('End of comment missing');
4296 }
4297
4298 var str = css.slice(2, i - 2);
4299 column += 2;
4300 updatePosition(str);
4301 css = css.slice(i);
4302 column += 2;
4303
4304 return pos({
4305 type: 'comment',
4306 comment: str
4307 });
4308 }
4309
4310 /**
4311 * Parse selector.
4312 */
4313
4314 function selector() {
4315 var m = match(/^([^{]+)/);
4316 if (!m) return;
4317 /* @fix Remove all comments from selectors
4318 * http://ostermiller.org/findcomment.html */
4319 return trim(m[0])
4320 .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
4321 .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m) {
4322 return m.replace(/,/g, '\u200C');
4323 })
4324 .split(/\s*(?![^(]*\)),\s*/)
4325 .map(function(s) {
4326 return s.replace(/\u200C/g, ',');
4327 });
4328 }
4329
4330 /**
4331 * Parse declaration.
4332 */
4333
4334 function declaration() {
4335 var pos = position();
4336
4337 // prop
4338 var prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
4339 if (!prop) return;
4340 prop = trim(prop[0]);
4341
4342 // :
4343 if (!match(/^:\s*/)) return error("property missing ':'");
4344
4345 // val
4346 var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
4347
4348 var ret = pos({
4349 type: 'declaration',
4350 property: prop.replace(commentre, ''),
4351 value: val ? trim(val[0]).replace(commentre, '') : ''
4352 });
4353
4354 // ;
4355 match(/^[;\s]*/);
4356
4357 return ret;
4358 }
4359
4360 /**
4361 * Parse declarations.
4362 */
4363
4364 function declarations() {
4365 var decls = [];
4366
4367 if (!open()) return error("missing '{'");
4368 comments(decls);
4369
4370 // declarations
4371 var decl;
4372 while (decl = declaration()) {
4373 if (decl !== false) {
4374 decls.push(decl);
4375 comments(decls);
4376 }
4377 }
4378
4379 if (!close()) return error("missing '}'");
4380 return decls;
4381 }
4382
4383 /**
4384 * Parse keyframe.
4385 */
4386
4387 function keyframe() {
4388 var m;
4389 var vals = [];
4390 var pos = position();
4391
4392 while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
4393 vals.push(m[1]);
4394 match(/^,\s*/);
4395 }
4396
4397 if (!vals.length) return;
4398
4399 return pos({
4400 type: 'keyframe',
4401 values: vals,
4402 declarations: declarations()
4403 });
4404 }
4405
4406 /**
4407 * Parse keyframes.
4408 */
4409
4410 function atkeyframes() {
4411 var pos = position();
4412 var m = match(/^@([-\w]+)?keyframes\s*/);
4413
4414 if (!m) return;
4415 var vendor = m[1];
4416
4417 // identifier
4418 var m = match(/^([-\w]+)\s*/);
4419 if (!m) return error("@keyframes missing name");
4420 var name = m[1];
4421
4422 if (!open()) return error("@keyframes missing '{'");
4423
4424 var frame;
4425 var frames = comments();
4426 while (frame = keyframe()) {
4427 frames.push(frame);
4428 frames = frames.concat(comments());
4429 }
4430
4431 if (!close()) return error("@keyframes missing '}'");
4432
4433 return pos({
4434 type: 'keyframes',
4435 name: name,
4436 vendor: vendor,
4437 keyframes: frames
4438 });
4439 }
4440
4441 /**
4442 * Parse supports.
4443 */
4444
4445 function atsupports() {
4446 var pos = position();
4447 var m = match(/^@supports *([^{]+)/);
4448
4449 if (!m) return;
4450 var supports = trim(m[1]);
4451
4452 if (!open()) return error("@supports missing '{'");
4453
4454 var style = comments().concat(rules());
4455
4456 if (!close()) return error("@supports missing '}'");
4457
4458 return pos({
4459 type: 'supports',
4460 supports: supports,
4461 rules: style
4462 });
4463 }
4464
4465 /**
4466 * Parse host.
4467 */
4468
4469 function athost() {
4470 var pos = position();
4471 var m = match(/^@host\s*/);
4472
4473 if (!m) return;
4474
4475 if (!open()) return error("@host missing '{'");
4476
4477 var style = comments().concat(rules());
4478
4479 if (!close()) return error("@host missing '}'");
4480
4481 return pos({
4482 type: 'host',
4483 rules: style
4484 });
4485 }
4486
4487 /**
4488 * Parse media.
4489 */
4490
4491 function atmedia() {
4492 var pos = position();
4493 var m = match(/^@media *([^{]+)/);
4494
4495 if (!m) return;
4496 var media = trim(m[1]);
4497
4498 if (!open()) return error("@media missing '{'");
4499
4500 var style = comments().concat(rules());
4501
4502 if (!close()) return error("@media missing '}'");
4503
4504 return pos({
4505 type: 'media',
4506 media: media,
4507 rules: style
4508 });
4509 }
4510
4511
4512 /**
4513 * Parse custom-media.
4514 */
4515
4516 function atcustommedia() {
4517 var pos = position();
4518 var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
4519 if (!m) return;
4520
4521 return pos({
4522 type: 'custom-media',
4523 name: trim(m[1]),
4524 media: trim(m[2])
4525 });
4526 }
4527
4528 /**
4529 * Parse paged media.
4530 */
4531
4532 function atpage() {
4533 var pos = position();
4534 var m = match(/^@page */);
4535 if (!m) return;
4536
4537 var sel = selector() || [];
4538
4539 if (!open()) return error("@page missing '{'");
4540 var decls = comments();
4541
4542 // declarations
4543 var decl;
4544 while (decl = declaration()) {
4545 decls.push(decl);
4546 decls = decls.concat(comments());
4547 }
4548
4549 if (!close()) return error("@page missing '}'");
4550
4551 return pos({
4552 type: 'page',
4553 selectors: sel,
4554 declarations: decls
4555 });
4556 }
4557
4558 /**
4559 * Parse document.
4560 */
4561
4562 function atdocument() {
4563 var pos = position();
4564 var m = match(/^@([-\w]+)?document *([^{]+)/);
4565 if (!m) return;
4566
4567 var vendor = trim(m[1]);
4568 var doc = trim(m[2]);
4569
4570 if (!open()) return error("@document missing '{'");
4571
4572 var style = comments().concat(rules());
4573
4574 if (!close()) return error("@document missing '}'");
4575
4576 return pos({
4577 type: 'document',
4578 document: doc,
4579 vendor: vendor,
4580 rules: style
4581 });
4582 }
4583
4584 /**
4585 * Parse font-face.
4586 */
4587
4588 function atfontface() {
4589 var pos = position();
4590 var m = match(/^@font-face\s*/);
4591 if (!m) return;
4592
4593 if (!open()) return error("@font-face missing '{'");
4594 var decls = comments();
4595
4596 // declarations
4597 var decl;
4598 while (decl = declaration()) {
4599 decls.push(decl);
4600 decls = decls.concat(comments());
4601 }
4602
4603 if (!close()) return error("@font-face missing '}'");
4604
4605 return pos({
4606 type: 'font-face',
4607 declarations: decls
4608 });
4609 }
4610
4611 /**
4612 * Parse import
4613 */
4614
4615 var atimport = _compileAtrule('import');
4616
4617 /**
4618 * Parse charset
4619 */
4620
4621 var atcharset = _compileAtrule('charset');
4622
4623 /**
4624 * Parse namespace
4625 */
4626
4627 var atnamespace = _compileAtrule('namespace');
4628
4629 /**
4630 * Parse non-block at-rules
4631 */
4632
4633
4634 function _compileAtrule(name) {
4635 var re = new RegExp('^@' + name + '\\s*([^;]+);');
4636 return function() {
4637 var pos = position();
4638 var m = match(re);
4639 if (!m) return;
4640 var ret = { type: name };
4641 ret[name] = m[1].trim();
4642 return pos(ret);
4643 }
4644 }
4645
4646 /**
4647 * Parse at rule.
4648 */
4649
4650 function atrule() {
4651 if (css[0] != '@') return;
4652
4653 return atkeyframes()
4654 || atmedia()
4655 || atcustommedia()
4656 || atsupports()
4657 || atimport()
4658 || atcharset()
4659 || atnamespace()
4660 || atdocument()
4661 || atpage()
4662 || athost()
4663 || atfontface();
4664 }
4665
4666 /**
4667 * Parse rule.
4668 */
4669
4670 function rule() {
4671 var pos = position();
4672 var sel = selector();
4673
4674 if (!sel) return error('selector missing');
4675 comments();
4676
4677 return pos({
4678 type: 'rule',
4679 selectors: sel,
4680 declarations: declarations()
4681 });
4682 }
4683
4684 return addParent(stylesheet());
4685 };
4686
4687 /**
4688 * Trim `str`.
4689 */
4690
4691 function trim(str) {
4692 return str ? str.replace(/^\s+|\s+$/g, '') : '';
4693 }
4694
4695 /**
4696 * Adds non-enumerable parent node reference to each node.
4697 */
4698
4699 function addParent(obj, parent) {
4700 var isNode = obj && typeof obj.type === 'string';
4701 var childParent = isNode ? obj : parent;
4702
4703 for (var k in obj) {
4704 var value = obj[k];
4705 if (Array.isArray(value)) {
4706 value.forEach(function(v) { addParent(v, childParent); });
4707 } else if (value && typeof value === 'object') {
4708 addParent(value, childParent);
4709 }
4710 }
4711
4712 if (isNode) {
4713 Object.defineProperty(obj, 'parent', {
4714 configurable: true,
4715 writable: true,
4716 enumerable: false,
4717 value: parent || null
4718 });
4719 }
4720
4721 return obj;
4722 }
4723
4724 },{}],18:[function(require,module,exports){
4725
4726 /**
4727 * Expose `Compiler`.
4728 */
4729
4730 module.exports = Compiler;
4731
4732 /**
4733 * Initialize a compiler.
4734 *
4735 * @param {Type} name
4736 * @return {Type}
4737 * @api public
4738 */
4739
4740 function Compiler(opts) {
4741 this.options = opts || {};
4742 }
4743
4744 /**
4745 * Emit `str`
4746 */
4747
4748 Compiler.prototype.emit = function(str) {
4749 return str;
4750 };
4751
4752 /**
4753 * Visit `node`.
4754 */
4755
4756 Compiler.prototype.visit = function(node){
4757 return this[node.type](node);
4758 };
4759
4760 /**
4761 * Map visit over array of `nodes`, optionally using a `delim`
4762 */
4763
4764 Compiler.prototype.mapVisit = function(nodes, delim){
4765 var buf = '';
4766 delim = delim || '';
4767
4768 for (var i = 0, length = nodes.length; i < length; i++) {
4769 buf += this.visit(nodes[i]);
4770 if (delim && i < length - 1) buf += this.emit(delim);
4771 }
4772
4773 return buf;
4774 };
4775
4776 },{}],19:[function(require,module,exports){
4777
4778 /**
4779 * Module dependencies.
4780 */
4781
4782 var Base = require('./compiler');
4783 var inherits = require('inherits');
4784
4785 /**
4786 * Expose compiler.
4787 */
4788
4789 module.exports = Compiler;
4790
4791 /**
4792 * Initialize a new `Compiler`.
4793 */
4794
4795 function Compiler(options) {
4796 Base.call(this, options);
4797 }
4798
4799 /**
4800 * Inherit from `Base.prototype`.
4801 */
4802
4803 inherits(Compiler, Base);
4804
4805 /**
4806 * Compile `node`.
4807 */
4808
4809 Compiler.prototype.compile = function(node){
4810 return node.stylesheet
4811 .rules.map(this.visit, this)
4812 .join('');
4813 };
4814
4815 /**
4816 * Visit comment node.
4817 */
4818
4819 Compiler.prototype.comment = function(node){
4820 return this.emit('', node.position);
4821 };
4822
4823 /**
4824 * Visit import node.
4825 */
4826
4827 Compiler.prototype.import = function(node){
4828 return this.emit('@import ' + node.import + ';', node.position);
4829 };
4830
4831 /**
4832 * Visit media node.
4833 */
4834
4835 Compiler.prototype.media = function(node){
4836 return this.emit('@media ' + node.media, node.position)
4837 + this.emit('{')
4838 + this.mapVisit(node.rules)
4839 + this.emit('}');
4840 };
4841
4842 /**
4843 * Visit document node.
4844 */
4845
4846 Compiler.prototype.document = function(node){
4847 var doc = '@' + (node.vendor || '') + 'document ' + node.document;
4848
4849 return this.emit(doc, node.position)
4850 + this.emit('{')
4851 + this.mapVisit(node.rules)
4852 + this.emit('}');
4853 };
4854
4855 /**
4856 * Visit charset node.
4857 */
4858
4859 Compiler.prototype.charset = function(node){
4860 return this.emit('@charset ' + node.charset + ';', node.position);
4861 };
4862
4863 /**
4864 * Visit namespace node.
4865 */
4866
4867 Compiler.prototype.namespace = function(node){
4868 return this.emit('@namespace ' + node.namespace + ';', node.position);
4869 };
4870
4871 /**
4872 * Visit supports node.
4873 */
4874
4875 Compiler.prototype.supports = function(node){
4876 return this.emit('@supports ' + node.supports, node.position)
4877 + this.emit('{')
4878 + this.mapVisit(node.rules)
4879 + this.emit('}');
4880 };
4881
4882 /**
4883 * Visit keyframes node.
4884 */
4885
4886 Compiler.prototype.keyframes = function(node){
4887 return this.emit('@'
4888 + (node.vendor || '')
4889 + 'keyframes '
4890 + node.name, node.position)
4891 + this.emit('{')
4892 + this.mapVisit(node.keyframes)
4893 + this.emit('}');
4894 };
4895
4896 /**
4897 * Visit keyframe node.
4898 */
4899
4900 Compiler.prototype.keyframe = function(node){
4901 var decls = node.declarations;
4902
4903 return this.emit(node.values.join(','), node.position)
4904 + this.emit('{')
4905 + this.mapVisit(decls)
4906 + this.emit('}');
4907 };
4908
4909 /**
4910 * Visit page node.
4911 */
4912
4913 Compiler.prototype.page = function(node){
4914 var sel = node.selectors.length
4915 ? node.selectors.join(', ')
4916 : '';
4917
4918 return this.emit('@page ' + sel, node.position)
4919 + this.emit('{')
4920 + this.mapVisit(node.declarations)
4921 + this.emit('}');
4922 };
4923
4924 /**
4925 * Visit font-face node.
4926 */
4927
4928 Compiler.prototype['font-face'] = function(node){
4929 return this.emit('@font-face', node.position)
4930 + this.emit('{')
4931 + this.mapVisit(node.declarations)
4932 + this.emit('}');
4933 };
4934
4935 /**
4936 * Visit host node.
4937 */
4938
4939 Compiler.prototype.host = function(node){
4940 return this.emit('@host', node.position)
4941 + this.emit('{')
4942 + this.mapVisit(node.rules)
4943 + this.emit('}');
4944 };
4945
4946 /**
4947 * Visit custom-media node.
4948 */
4949
4950 Compiler.prototype['custom-media'] = function(node){
4951 return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
4952 };
4953
4954 /**
4955 * Visit rule node.
4956 */
4957
4958 Compiler.prototype.rule = function(node){
4959 var decls = node.declarations;
4960 if (!decls.length) return '';
4961
4962 return this.emit(node.selectors.join(','), node.position)
4963 + this.emit('{')
4964 + this.mapVisit(decls)
4965 + this.emit('}');
4966 };
4967
4968 /**
4969 * Visit declaration node.
4970 */
4971
4972 Compiler.prototype.declaration = function(node){
4973 return this.emit(node.property + ':' + node.value, node.position) + this.emit(';');
4974 };
4975
4976
4977 },{"./compiler":18,"inherits":24}],20:[function(require,module,exports){
4978
4979 /**
4980 * Module dependencies.
4981 */
4982
4983 var Base = require('./compiler');
4984 var inherits = require('inherits');
4985
4986 /**
4987 * Expose compiler.
4988 */
4989
4990 module.exports = Compiler;
4991
4992 /**
4993 * Initialize a new `Compiler`.
4994 */
4995
4996 function Compiler(options) {
4997 options = options || {};
4998 Base.call(this, options);
4999 this.indentation = options.indent;
5000 }
5001
5002 /**
5003 * Inherit from `Base.prototype`.
5004 */
5005
5006 inherits(Compiler, Base);
5007
5008 /**
5009 * Compile `node`.
5010 */
5011
5012 Compiler.prototype.compile = function(node){
5013 return this.stylesheet(node);
5014 };
5015
5016 /**
5017 * Visit stylesheet node.
5018 */
5019
5020 Compiler.prototype.stylesheet = function(node){
5021 return this.mapVisit(node.stylesheet.rules, '\n\n');
5022 };
5023
5024 /**
5025 * Visit comment node.
5026 */
5027
5028 Compiler.prototype.comment = function(node){
5029 return this.emit(this.indent() + '/*' + node.comment + '*/', node.position);
5030 };
5031
5032 /**
5033 * Visit import node.
5034 */
5035
5036 Compiler.prototype.import = function(node){
5037 return this.emit('@import ' + node.import + ';', node.position);
5038 };
5039
5040 /**
5041 * Visit media node.
5042 */
5043
5044 Compiler.prototype.media = function(node){
5045 return this.emit('@media ' + node.media, node.position)
5046 + this.emit(
5047 ' {\n'
5048 + this.indent(1))
5049 + this.mapVisit(node.rules, '\n\n')
5050 + this.emit(
5051 this.indent(-1)
5052 + '\n}');
5053 };
5054
5055 /**
5056 * Visit document node.
5057 */
5058
5059 Compiler.prototype.document = function(node){
5060 var doc = '@' + (node.vendor || '') + 'document ' + node.document;
5061
5062 return this.emit(doc, node.position)
5063 + this.emit(
5064 ' '
5065 + ' {\n'
5066 + this.indent(1))
5067 + this.mapVisit(node.rules, '\n\n')
5068 + this.emit(
5069 this.indent(-1)
5070 + '\n}');
5071 };
5072
5073 /**
5074 * Visit charset node.
5075 */
5076
5077 Compiler.prototype.charset = function(node){
5078 return this.emit('@charset ' + node.charset + ';', node.position);
5079 };
5080
5081 /**
5082 * Visit namespace node.
5083 */
5084
5085 Compiler.prototype.namespace = function(node){
5086 return this.emit('@namespace ' + node.namespace + ';', node.position);
5087 };
5088
5089 /**
5090 * Visit supports node.
5091 */
5092
5093 Compiler.prototype.supports = function(node){
5094 return this.emit('@supports ' + node.supports, node.position)
5095 + this.emit(
5096 ' {\n'
5097 + this.indent(1))
5098 + this.mapVisit(node.rules, '\n\n')
5099 + this.emit(
5100 this.indent(-1)
5101 + '\n}');
5102 };
5103
5104 /**
5105 * Visit keyframes node.
5106 */
5107
5108 Compiler.prototype.keyframes = function(node){
5109 return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position)
5110 + this.emit(
5111 ' {\n'
5112 + this.indent(1))
5113 + this.mapVisit(node.keyframes, '\n')
5114 + this.emit(
5115 this.indent(-1)
5116 + '}');
5117 };
5118
5119 /**
5120 * Visit keyframe node.
5121 */
5122
5123 Compiler.prototype.keyframe = function(node){
5124 var decls = node.declarations;
5125
5126 return this.emit(this.indent())
5127 + this.emit(node.values.join(', '), node.position)
5128 + this.emit(
5129 ' {\n'
5130 + this.indent(1))
5131 + this.mapVisit(decls, '\n')
5132 + this.emit(
5133 this.indent(-1)
5134 + '\n'
5135 + this.indent() + '}\n');
5136 };
5137
5138 /**
5139 * Visit page node.
5140 */
5141
5142 Compiler.prototype.page = function(node){
5143 var sel = node.selectors.length
5144 ? node.selectors.join(', ') + ' '
5145 : '';
5146
5147 return this.emit('@page ' + sel, node.position)
5148 + this.emit('{\n')
5149 + this.emit(this.indent(1))
5150 + this.mapVisit(node.declarations, '\n')
5151 + this.emit(this.indent(-1))
5152 + this.emit('\n}');
5153 };
5154
5155 /**
5156 * Visit font-face node.
5157 */
5158
5159 Compiler.prototype['font-face'] = function(node){
5160 return this.emit('@font-face ', node.position)
5161 + this.emit('{\n')
5162 + this.emit(this.indent(1))
5163 + this.mapVisit(node.declarations, '\n')
5164 + this.emit(this.indent(-1))
5165 + this.emit('\n}');
5166 };
5167
5168 /**
5169 * Visit host node.
5170 */
5171
5172 Compiler.prototype.host = function(node){
5173 return this.emit('@host', node.position)
5174 + this.emit(
5175 ' {\n'
5176 + this.indent(1))
5177 + this.mapVisit(node.rules, '\n\n')
5178 + this.emit(
5179 this.indent(-1)
5180 + '\n}');
5181 };
5182
5183 /**
5184 * Visit custom-media node.
5185 */
5186
5187 Compiler.prototype['custom-media'] = function(node){
5188 return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
5189 };
5190
5191 /**
5192 * Visit rule node.
5193 */
5194
5195 Compiler.prototype.rule = function(node){
5196 var indent = this.indent();
5197 var decls = node.declarations;
5198 if (!decls.length) return '';
5199
5200 return this.emit(node.selectors.map(function(s){ return indent + s }).join(',\n'), node.position)
5201 + this.emit(' {\n')
5202 + this.emit(this.indent(1))
5203 + this.mapVisit(decls, '\n')
5204 + this.emit(this.indent(-1))
5205 + this.emit('\n' + this.indent() + '}');
5206 };
5207
5208 /**
5209 * Visit declaration node.
5210 */
5211
5212 Compiler.prototype.declaration = function(node){
5213 return this.emit(this.indent())
5214 + this.emit(node.property + ': ' + node.value, node.position)
5215 + this.emit(';');
5216 };
5217
5218 /**
5219 * Increase, decrease or return current indentation.
5220 */
5221
5222 Compiler.prototype.indent = function(level) {
5223 this.level = this.level || 1;
5224
5225 if (null != level) {
5226 this.level += level;
5227 return '';
5228 }
5229
5230 return Array(this.level).join(this.indentation || ' ');
5231 };
5232
5233 },{"./compiler":18,"inherits":24}],21:[function(require,module,exports){
5234
5235 /**
5236 * Module dependencies.
5237 */
5238
5239 var Compressed = require('./compress');
5240 var Identity = require('./identity');
5241
5242 /**
5243 * Stringfy the given AST `node`.
5244 *
5245 * Options:
5246 *
5247 * - `compress` space-optimized output
5248 * - `sourcemap` return an object with `.code` and `.map`
5249 *
5250 * @param {Object} node
5251 * @param {Object} [options]
5252 * @return {String}
5253 * @api public
5254 */
5255
5256 module.exports = function(node, options){
5257 options = options || {};
5258
5259 var compiler = options.compress
5260 ? new Compressed(options)
5261 : new Identity(options);
5262
5263 // source maps
5264 if (options.sourcemap) {
5265 var sourcemaps = require('./source-map-support');
5266 sourcemaps(compiler);
5267
5268 var code = compiler.compile(node);
5269 compiler.applySourceMaps();
5270
5271 var map = options.sourcemap === 'generator'
5272 ? compiler.map
5273 : compiler.map.toJSON();
5274
5275 return { code: code, map: map };
5276 }
5277
5278 var code = compiler.compile(node);
5279 return code;
5280 };
5281
5282 },{"./compress":19,"./identity":20,"./source-map-support":22}],22:[function(require,module,exports){
5283
5284 /**
5285 * Module dependencies.
5286 */
5287
5288 var SourceMap = require('source-map').SourceMapGenerator;
5289 var SourceMapConsumer = require('source-map').SourceMapConsumer;
5290 var sourceMapResolve = require('source-map-resolve');
5291 var fs = require('fs');
5292 var path = require('path');
5293
5294 /**
5295 * Expose `mixin()`.
5296 */
5297
5298 module.exports = mixin;
5299
5300 /**
5301 * Ensure Windows-style paths are formatted properly
5302 */
5303
5304 const makeFriendlyPath = function(aPath) {
5305 return path.sep === "\\" ? aPath.replace(/\\/g, "/").replace(/^[a-z]:\/?/i, "/") : aPath;
5306 }
5307
5308 /**
5309 * Mixin source map support into `compiler`.
5310 *
5311 * @param {Compiler} compiler
5312 * @api public
5313 */
5314
5315 function mixin(compiler) {
5316 compiler._comment = compiler.comment;
5317 compiler.map = new SourceMap();
5318 compiler.position = { line: 1, column: 1 };
5319 compiler.files = {};
5320 for (var k in exports) compiler[k] = exports[k];
5321 }
5322
5323 /**
5324 * Update position.
5325 *
5326 * @param {String} str
5327 * @api private
5328 */
5329
5330 exports.updatePosition = function(str) {
5331 var lines = str.match(/\n/g);
5332 if (lines) this.position.line += lines.length;
5333 var i = str.lastIndexOf('\n');
5334 this.position.column = ~i ? str.length - i : this.position.column + str.length;
5335 };
5336
5337 /**
5338 * Emit `str`.
5339 *
5340 * @param {String} str
5341 * @param {Object} [pos]
5342 * @return {String}
5343 * @api private
5344 */
5345
5346 exports.emit = function(str, pos) {
5347 if (pos) {
5348 var sourceFile = makeFriendlyPath(pos.source || 'source.css');
5349
5350 this.map.addMapping({
5351 source: sourceFile,
5352 generated: {
5353 line: this.position.line,
5354 column: Math.max(this.position.column - 1, 0)
5355 },
5356 original: {
5357 line: pos.start.line,
5358 column: pos.start.column - 1
5359 }
5360 });
5361
5362 this.addFile(sourceFile, pos);
5363 }
5364
5365 this.updatePosition(str);
5366
5367 return str;
5368 };
5369
5370 /**
5371 * Adds a file to the source map output if it has not already been added
5372 * @param {String} file
5373 * @param {Object} pos
5374 */
5375
5376 exports.addFile = function(file, pos) {
5377 if (typeof pos.content !== 'string') return;
5378 if (Object.prototype.hasOwnProperty.call(this.files, file)) return;
5379
5380 this.files[file] = pos.content;
5381 };
5382
5383 /**
5384 * Applies any original source maps to the output and embeds the source file
5385 * contents in the source map.
5386 */
5387
5388 exports.applySourceMaps = function() {
5389 Object.keys(this.files).forEach(function(file) {
5390 var content = this.files[file];
5391 this.map.setSourceContent(file, content);
5392
5393 if (this.options.inputSourcemaps !== false) {
5394 var originalMap = sourceMapResolve.resolveSync(
5395 content, file, fs.readFileSync);
5396 if (originalMap) {
5397 var map = new SourceMapConsumer(originalMap.map);
5398 var relativeTo = originalMap.sourcesRelativeTo;
5399 this.map.applySourceMap(map, file, makeFriendlyPath(path.dirname(relativeTo)));
5400 }
5401 }
5402 }, this);
5403 };
5404
5405 /**
5406 * Process comments, drops sourceMap comments.
5407 * @param {Object} node
5408 */
5409
5410 exports.comment = function(node) {
5411 if (/^# sourceMappingURL=/.test(node.comment))
5412 return this.emit('', node.position);
5413 else
5414 return this._comment(node);
5415 };
5416
5417 },{"fs":2,"path":5,"source-map":36,"source-map-resolve":25}],23:[function(require,module,exports){
5418 'use strict';
5419 var token = '%[a-f0-9]{2}';
5420 var singleMatcher = new RegExp(token, 'gi');
5421 var multiMatcher = new RegExp('(' + token + ')+', 'gi');
5422
5423 function decodeComponents(components, split) {
5424 try {
5425 // Try to decode the entire string first
5426 return decodeURIComponent(components.join(''));
5427 } catch (err) {
5428 // Do nothing
5429 }
5430
5431 if (components.length === 1) {
5432 return components;
5433 }
5434
5435 split = split || 1;
5436
5437 // Split the array in 2 parts
5438 var left = components.slice(0, split);
5439 var right = components.slice(split);
5440
5441 return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
5442 }
5443
5444 function decode(input) {
5445 try {
5446 return decodeURIComponent(input);
5447 } catch (err) {
5448 var tokens = input.match(singleMatcher);
5449
5450 for (var i = 1; i < tokens.length; i++) {
5451 input = decodeComponents(tokens, i).join('');
5452
5453 tokens = input.match(singleMatcher);
5454 }
5455
5456 return input;
5457 }
5458 }
5459
5460 function customDecodeURIComponent(input) {
5461 // Keep track of all the replacements and prefill the map with the `BOM`
5462 var replaceMap = {
5463 '%FE%FF': '\uFFFD\uFFFD',
5464 '%FF%FE': '\uFFFD\uFFFD'
5465 };
5466
5467 var match = multiMatcher.exec(input);
5468 while (match) {
5469 try {
5470 // Decode as big chunks as possible
5471 replaceMap[match[0]] = decodeURIComponent(match[0]);
5472 } catch (err) {
5473 var result = decode(match[0]);
5474
5475 if (result !== match[0]) {
5476 replaceMap[match[0]] = result;
5477 }
5478 }
5479
5480 match = multiMatcher.exec(input);
5481 }
5482
5483 // Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
5484 replaceMap['%C2'] = '\uFFFD';
5485
5486 var entries = Object.keys(replaceMap);
5487
5488 for (var i = 0; i < entries.length; i++) {
5489 // Replace all decoded components
5490 var key = entries[i];
5491 input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
5492 }
5493
5494 return input;
5495 }
5496
5497 module.exports = function (encodedURI) {
5498 if (typeof encodedURI !== 'string') {
5499 throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`');
5500 }
5501
5502 try {
5503 encodedURI = encodedURI.replace(/\+/g, ' ');
5504
5505 // Try the built in decoder first
5506 return decodeURIComponent(encodedURI);
5507 } catch (err) {
5508 // Fallback to a more advanced decoder
5509 return customDecodeURIComponent(encodedURI);
5510 }
5511 };
5512
5513 },{}],24:[function(require,module,exports){
5514 if (typeof Object.create === 'function') {
5515 // implementation from standard node.js 'util' module
5516 module.exports = function inherits(ctor, superCtor) {
5517 if (superCtor) {
5518 ctor.super_ = superCtor
5519 ctor.prototype = Object.create(superCtor.prototype, {
5520 constructor: {
5521 value: ctor,
5522 enumerable: false,
5523 writable: true,
5524 configurable: true
5525 }
5526 })
5527 }
5528 };
5529 } else {
5530 // old school shim for old browsers
5531 module.exports = function inherits(ctor, superCtor) {
5532 if (superCtor) {
5533 ctor.super_ = superCtor
5534 var TempCtor = function () {}
5535 TempCtor.prototype = superCtor.prototype
5536 ctor.prototype = new TempCtor()
5537 ctor.prototype.constructor = ctor
5538 }
5539 }
5540 }
5541
5542 },{}],25:[function(require,module,exports){
5543 (function (setImmediate){
5544 var atob = require("atob")
5545 var urlLib = require("url")
5546 var pathLib = require("path")
5547 var decodeUriComponentLib = require("decode-uri-component")
5548
5549
5550
5551 function resolveUrl(/* ...urls */) {
5552 return Array.prototype.reduce.call(arguments, function(resolved, nextUrl) {
5553 return urlLib.resolve(resolved, nextUrl)
5554 })
5555 }
5556
5557 function convertWindowsPath(aPath) {
5558 return pathLib.sep === "\\" ? aPath.replace(/\\/g, "/").replace(/^[a-z]:\/?/i, "/") : aPath
5559 }
5560
5561 function customDecodeUriComponent(string) {
5562 // `decodeUriComponentLib` turns `+` into ` `, but that's not wanted.
5563 return decodeUriComponentLib(string.replace(/\+/g, "%2B"))
5564 }
5565
5566 function callbackAsync(callback, error, result) {
5567 setImmediate(function() { callback(error, result) })
5568 }
5569
5570 function parseMapToJSON(string, data) {
5571 try {
5572 return JSON.parse(string.replace(/^\)\]\}'/, ""))
5573 } catch (error) {
5574 error.sourceMapData = data
5575 throw error
5576 }
5577 }
5578
5579 function readSync(read, url, data) {
5580 var readUrl = customDecodeUriComponent(url)
5581 try {
5582 return String(read(readUrl))
5583 } catch (error) {
5584 error.sourceMapData = data
5585 throw error
5586 }
5587 }
5588
5589
5590
5591 var innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/
5592
5593 var sourceMappingURLRegex = RegExp(
5594 "(?:" +
5595 "/\\*" +
5596 "(?:\\s*\r?\n(?://)?)?" +
5597 "(?:" + innerRegex.source + ")" +
5598 "\\s*" +
5599 "\\*/" +
5600 "|" +
5601 "//(?:" + innerRegex.source + ")" +
5602 ")" +
5603 "\\s*"
5604 )
5605
5606 function getSourceMappingUrl(code) {
5607 var match = code.match(sourceMappingURLRegex)
5608 return match ? match[1] || match[2] || "" : null
5609 }
5610
5611
5612
5613 function resolveSourceMap(code, codeUrl, read, callback) {
5614 var mapData
5615 try {
5616 mapData = resolveSourceMapHelper(code, codeUrl)
5617 } catch (error) {
5618 return callbackAsync(callback, error)
5619 }
5620 if (!mapData || mapData.map) {
5621 return callbackAsync(callback, null, mapData)
5622 }
5623 var readUrl = customDecodeUriComponent(mapData.url)
5624 read(readUrl, function(error, result) {
5625 if (error) {
5626 error.sourceMapData = mapData
5627 return callback(error)
5628 }
5629 mapData.map = String(result)
5630 try {
5631 mapData.map = parseMapToJSON(mapData.map, mapData)
5632 } catch (error) {
5633 return callback(error)
5634 }
5635 callback(null, mapData)
5636 })
5637 }
5638
5639 function resolveSourceMapSync(code, codeUrl, read) {
5640 var mapData = resolveSourceMapHelper(code, codeUrl)
5641 if (!mapData || mapData.map) {
5642 return mapData
5643 }
5644 mapData.map = readSync(read, mapData.url, mapData)
5645 mapData.map = parseMapToJSON(mapData.map, mapData)
5646 return mapData
5647 }
5648
5649 var dataUriRegex = /^data:([^,;]*)(;[^,;]*)*(?:,(.*))?$/
5650
5651 /**
5652 * The media type for JSON text is application/json.
5653 *
5654 * {@link https://tools.ietf.org/html/rfc8259#section-11 | IANA Considerations }
5655 *
5656 * `text/json` is non-standard media type
5657 */
5658 var jsonMimeTypeRegex = /^(?:application|text)\/json$/
5659
5660 /**
5661 * JSON text exchanged between systems that are not part of a closed ecosystem
5662 * MUST be encoded using UTF-8.
5663 *
5664 * {@link https://tools.ietf.org/html/rfc8259#section-8.1 | Character Encoding}
5665 */
5666 var jsonCharacterEncoding = "utf-8"
5667
5668 function base64ToBuf(b64) {
5669 var binStr = atob(b64)
5670 var len = binStr.length
5671 var arr = new Uint8Array(len)
5672 for (var i = 0; i < len; i++) {
5673 arr[i] = binStr.charCodeAt(i)
5674 }
5675 return arr
5676 }
5677
5678 function decodeBase64String(b64) {
5679 if (typeof TextDecoder === "undefined" || typeof Uint8Array === "undefined") {
5680 return atob(b64)
5681 }
5682 var buf = base64ToBuf(b64);
5683 // Note: `decoder.decode` method will throw a `DOMException` with the
5684 // `"EncodingError"` value when an coding error is found.
5685 var decoder = new TextDecoder(jsonCharacterEncoding, {fatal: true})
5686 return decoder.decode(buf);
5687 }
5688
5689 function resolveSourceMapHelper(code, codeUrl) {
5690 codeUrl = convertWindowsPath(codeUrl)
5691
5692 var url = getSourceMappingUrl(code)
5693 if (!url) {
5694 return null
5695 }
5696
5697 var dataUri = url.match(dataUriRegex)
5698 if (dataUri) {
5699 var mimeType = dataUri[1] || "text/plain"
5700 var lastParameter = dataUri[2] || ""
5701 var encoded = dataUri[3] || ""
5702 var data = {
5703 sourceMappingURL: url,
5704 url: null,
5705 sourcesRelativeTo: codeUrl,
5706 map: encoded
5707 }
5708 if (!jsonMimeTypeRegex.test(mimeType)) {
5709 var error = new Error("Unuseful data uri mime type: " + mimeType)
5710 error.sourceMapData = data
5711 throw error
5712 }
5713 try {
5714 data.map = parseMapToJSON(
5715 lastParameter === ";base64" ? decodeBase64String(encoded) : decodeURIComponent(encoded),
5716 data
5717 )
5718 } catch (error) {
5719 error.sourceMapData = data
5720 throw error
5721 }
5722 return data
5723 }
5724
5725 var mapUrl = resolveUrl(codeUrl, url)
5726 return {
5727 sourceMappingURL: url,
5728 url: mapUrl,
5729 sourcesRelativeTo: mapUrl,
5730 map: null
5731 }
5732 }
5733
5734
5735
5736 function resolveSources(map, mapUrl, read, options, callback) {
5737 if (typeof options === "function") {
5738 callback = options
5739 options = {}
5740 }
5741 var pending = map.sources ? map.sources.length : 0
5742 var result = {
5743 sourcesResolved: [],
5744 sourcesContent: []
5745 }
5746
5747 if (pending === 0) {
5748 callbackAsync(callback, null, result)
5749 return
5750 }
5751
5752 var done = function() {
5753 pending--
5754 if (pending === 0) {
5755 callback(null, result)
5756 }
5757 }
5758
5759 resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) {
5760 result.sourcesResolved[index] = fullUrl
5761 if (typeof sourceContent === "string") {
5762 result.sourcesContent[index] = sourceContent
5763 callbackAsync(done, null)
5764 } else {
5765 var readUrl = customDecodeUriComponent(fullUrl)
5766 read(readUrl, function(error, source) {
5767 result.sourcesContent[index] = error ? error : String(source)
5768 done()
5769 })
5770 }
5771 })
5772 }
5773
5774 function resolveSourcesSync(map, mapUrl, read, options) {
5775 var result = {
5776 sourcesResolved: [],
5777 sourcesContent: []
5778 }
5779
5780 if (!map.sources || map.sources.length === 0) {
5781 return result
5782 }
5783
5784 resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) {
5785 result.sourcesResolved[index] = fullUrl
5786 if (read !== null) {
5787 if (typeof sourceContent === "string") {
5788 result.sourcesContent[index] = sourceContent
5789 } else {
5790 var readUrl = customDecodeUriComponent(fullUrl)
5791 try {
5792 result.sourcesContent[index] = String(read(readUrl))
5793 } catch (error) {
5794 result.sourcesContent[index] = error
5795 }
5796 }
5797 }
5798 })
5799
5800 return result
5801 }
5802
5803 var endingSlash = /\/?$/
5804
5805 function resolveSourcesHelper(map, mapUrl, options, fn) {
5806 options = options || {}
5807 mapUrl = convertWindowsPath(mapUrl)
5808 var fullUrl
5809 var sourceContent
5810 var sourceRoot
5811 for (var index = 0, len = map.sources.length; index < len; index++) {
5812 sourceRoot = null
5813 if (typeof options.sourceRoot === "string") {
5814 sourceRoot = options.sourceRoot
5815 } else if (typeof map.sourceRoot === "string" && options.sourceRoot !== false) {
5816 sourceRoot = map.sourceRoot
5817 }
5818 // If the sourceRoot is the empty string, it is equivalent to not setting
5819 // the property at all.
5820 if (sourceRoot === null || sourceRoot === '') {
5821 fullUrl = resolveUrl(mapUrl, map.sources[index])
5822 } else {
5823 // Make sure that the sourceRoot ends with a slash, so that `/scripts/subdir` becomes
5824 // `/scripts/subdir/<source>`, not `/scripts/<source>`. Pointing to a file as source root
5825 // does not make sense.
5826 fullUrl = resolveUrl(mapUrl, sourceRoot.replace(endingSlash, "/"), map.sources[index])
5827 }
5828 sourceContent = (map.sourcesContent || [])[index]
5829 fn(fullUrl, sourceContent, index)
5830 }
5831 }
5832
5833
5834
5835 function resolve(code, codeUrl, read, options, callback) {
5836 if (typeof options === "function") {
5837 callback = options
5838 options = {}
5839 }
5840 if (code === null) {
5841 var mapUrl = codeUrl
5842 var data = {
5843 sourceMappingURL: null,
5844 url: mapUrl,
5845 sourcesRelativeTo: mapUrl,
5846 map: null
5847 }
5848 var readUrl = customDecodeUriComponent(mapUrl)
5849 read(readUrl, function(error, result) {
5850 if (error) {
5851 error.sourceMapData = data
5852 return callback(error)
5853 }
5854 data.map = String(result)
5855 try {
5856 data.map = parseMapToJSON(data.map, data)
5857 } catch (error) {
5858 return callback(error)
5859 }
5860 _resolveSources(data)
5861 })
5862 } else {
5863 resolveSourceMap(code, codeUrl, read, function(error, mapData) {
5864 if (error) {
5865 return callback(error)
5866 }
5867 if (!mapData) {
5868 return callback(null, null)
5869 }
5870 _resolveSources(mapData)
5871 })
5872 }
5873
5874 function _resolveSources(mapData) {
5875 resolveSources(mapData.map, mapData.sourcesRelativeTo, read, options, function(error, result) {
5876 if (error) {
5877 return callback(error)
5878 }
5879 mapData.sourcesResolved = result.sourcesResolved
5880 mapData.sourcesContent = result.sourcesContent
5881 callback(null, mapData)
5882 })
5883 }
5884 }
5885
5886 function resolveSync(code, codeUrl, read, options) {
5887 var mapData
5888 if (code === null) {
5889 var mapUrl = codeUrl
5890 mapData = {
5891 sourceMappingURL: null,
5892 url: mapUrl,
5893 sourcesRelativeTo: mapUrl,
5894 map: null
5895 }
5896 mapData.map = readSync(read, mapUrl, mapData)
5897 mapData.map = parseMapToJSON(mapData.map, mapData)
5898 } else {
5899 mapData = resolveSourceMapSync(code, codeUrl, read)
5900 if (!mapData) {
5901 return null
5902 }
5903 }
5904 var result = resolveSourcesSync(mapData.map, mapData.sourcesRelativeTo, read, options)
5905 mapData.sourcesResolved = result.sourcesResolved
5906 mapData.sourcesContent = result.sourcesContent
5907 return mapData
5908 }
5909
5910
5911
5912 module.exports = {
5913 resolveSourceMap: resolveSourceMap,
5914 resolveSourceMapSync: resolveSourceMapSync,
5915 resolveSources: resolveSources,
5916 resolveSourcesSync: resolveSourcesSync,
5917 resolve: resolve,
5918 resolveSync: resolveSync,
5919 parseMapToJSON: parseMapToJSON
5920 }
5921
5922 }).call(this,require("timers").setImmediate)
5923 },{"atob":15,"decode-uri-component":23,"path":5,"timers":11,"url":12}],26:[function(require,module,exports){
5924 /* -*- Mode: js; js-indent-level: 2; -*- */
5925 /*
5926 * Copyright 2011 Mozilla Foundation and contributors
5927 * Licensed under the New BSD license. See LICENSE or:
5928 * http://opensource.org/licenses/BSD-3-Clause
5929 */
5930
5931 var util = require('./util');
5932 var has = Object.prototype.hasOwnProperty;
5933 var hasNativeMap = typeof Map !== "undefined";
5934
5935 /**
5936 * A data structure which is a combination of an array and a set. Adding a new
5937 * member is O(1), testing for membership is O(1), and finding the index of an
5938 * element is O(1). Removing elements from the set is not supported. Only
5939 * strings are supported for membership.
5940 */
5941 function ArraySet() {
5942 this._array = [];
5943 this._set = hasNativeMap ? new Map() : Object.create(null);
5944 }
5945
5946 /**
5947 * Static method for creating ArraySet instances from an existing array.
5948 */
5949 ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
5950 var set = new ArraySet();
5951 for (var i = 0, len = aArray.length; i < len; i++) {
5952 set.add(aArray[i], aAllowDuplicates);
5953 }
5954 return set;
5955 };
5956
5957 /**
5958 * Return how many unique items are in this ArraySet. If duplicates have been
5959 * added, than those do not count towards the size.
5960 *
5961 * @returns Number
5962 */
5963 ArraySet.prototype.size = function ArraySet_size() {
5964 return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
5965 };
5966
5967 /**
5968 * Add the given string to this set.
5969 *
5970 * @param String aStr
5971 */
5972 ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
5973 var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
5974 var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
5975 var idx = this._array.length;
5976 if (!isDuplicate || aAllowDuplicates) {
5977 this._array.push(aStr);
5978 }
5979 if (!isDuplicate) {
5980 if (hasNativeMap) {
5981 this._set.set(aStr, idx);
5982 } else {
5983 this._set[sStr] = idx;
5984 }
5985 }
5986 };
5987
5988 /**
5989 * Is the given string a member of this set?
5990 *
5991 * @param String aStr
5992 */
5993 ArraySet.prototype.has = function ArraySet_has(aStr) {
5994 if (hasNativeMap) {
5995 return this._set.has(aStr);
5996 } else {
5997 var sStr = util.toSetString(aStr);
5998 return has.call(this._set, sStr);
5999 }
6000 };
6001
6002 /**
6003 * What is the index of the given string in the array?
6004 *
6005 * @param String aStr
6006 */
6007 ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
6008 if (hasNativeMap) {
6009 var idx = this._set.get(aStr);
6010 if (idx >= 0) {
6011 return idx;
6012 }
6013 } else {
6014 var sStr = util.toSetString(aStr);
6015 if (has.call(this._set, sStr)) {
6016 return this._set[sStr];
6017 }
6018 }
6019
6020 throw new Error('"' + aStr + '" is not in the set.');
6021 };
6022
6023 /**
6024 * What is the element at the given index?
6025 *
6026 * @param Number aIdx
6027 */
6028 ArraySet.prototype.at = function ArraySet_at(aIdx) {
6029 if (aIdx >= 0 && aIdx < this._array.length) {
6030 return this._array[aIdx];
6031 }
6032 throw new Error('No element indexed by ' + aIdx);
6033 };
6034
6035 /**
6036 * Returns the array representation of this set (which has the proper indices
6037 * indicated by indexOf). Note that this is a copy of the internal array used
6038 * for storing the members so that no one can mess with internal state.
6039 */
6040 ArraySet.prototype.toArray = function ArraySet_toArray() {
6041 return this._array.slice();
6042 };
6043
6044 exports.ArraySet = ArraySet;
6045
6046 },{"./util":35}],27:[function(require,module,exports){
6047 /* -*- Mode: js; js-indent-level: 2; -*- */
6048 /*
6049 * Copyright 2011 Mozilla Foundation and contributors
6050 * Licensed under the New BSD license. See LICENSE or:
6051 * http://opensource.org/licenses/BSD-3-Clause
6052 *
6053 * Based on the Base 64 VLQ implementation in Closure Compiler:
6054 * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
6055 *
6056 * Copyright 2011 The Closure Compiler Authors. All rights reserved.
6057 * Redistribution and use in source and binary forms, with or without
6058 * modification, are permitted provided that the following conditions are
6059 * met:
6060 *
6061 * * Redistributions of source code must retain the above copyright
6062 * notice, this list of conditions and the following disclaimer.
6063 * * Redistributions in binary form must reproduce the above
6064 * copyright notice, this list of conditions and the following
6065 * disclaimer in the documentation and/or other materials provided
6066 * with the distribution.
6067 * * Neither the name of Google Inc. nor the names of its
6068 * contributors may be used to endorse or promote products derived
6069 * from this software without specific prior written permission.
6070 *
6071 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6072 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6073 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6074 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
6075 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
6076 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
6077 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
6078 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
6079 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
6080 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
6081 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6082 */
6083
6084 var base64 = require('./base64');
6085
6086 // A single base 64 digit can contain 6 bits of data. For the base 64 variable
6087 // length quantities we use in the source map spec, the first bit is the sign,
6088 // the next four bits are the actual value, and the 6th bit is the
6089 // continuation bit. The continuation bit tells us whether there are more
6090 // digits in this value following this digit.
6091 //
6092 // Continuation
6093 // | Sign
6094 // | |
6095 // V V
6096 // 101011
6097
6098 var VLQ_BASE_SHIFT = 5;
6099
6100 // binary: 100000
6101 var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
6102
6103 // binary: 011111
6104 var VLQ_BASE_MASK = VLQ_BASE - 1;
6105
6106 // binary: 100000
6107 var VLQ_CONTINUATION_BIT = VLQ_BASE;
6108
6109 /**
6110 * Converts from a two-complement value to a value where the sign bit is
6111 * placed in the least significant bit. For example, as decimals:
6112 * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
6113 * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
6114 */
6115 function toVLQSigned(aValue) {
6116 return aValue < 0
6117 ? ((-aValue) << 1) + 1
6118 : (aValue << 1) + 0;
6119 }
6120
6121 /**
6122 * Converts to a two-complement value from a value where the sign bit is
6123 * placed in the least significant bit. For example, as decimals:
6124 * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
6125 * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
6126 */
6127 function fromVLQSigned(aValue) {
6128 var isNegative = (aValue & 1) === 1;
6129 var shifted = aValue >> 1;
6130 return isNegative
6131 ? -shifted
6132 : shifted;
6133 }
6134
6135 /**
6136 * Returns the base 64 VLQ encoded value.
6137 */
6138 exports.encode = function base64VLQ_encode(aValue) {
6139 var encoded = "";
6140 var digit;
6141
6142 var vlq = toVLQSigned(aValue);
6143
6144 do {
6145 digit = vlq & VLQ_BASE_MASK;
6146 vlq >>>= VLQ_BASE_SHIFT;
6147 if (vlq > 0) {
6148 // There are still more digits in this value, so we must make sure the
6149 // continuation bit is marked.
6150 digit |= VLQ_CONTINUATION_BIT;
6151 }
6152 encoded += base64.encode(digit);
6153 } while (vlq > 0);
6154
6155 return encoded;
6156 };
6157
6158 /**
6159 * Decodes the next base 64 VLQ value from the given string and returns the
6160 * value and the rest of the string via the out parameter.
6161 */
6162 exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
6163 var strLen = aStr.length;
6164 var result = 0;
6165 var shift = 0;
6166 var continuation, digit;
6167
6168 do {
6169 if (aIndex >= strLen) {
6170 throw new Error("Expected more digits in base 64 VLQ value.");
6171 }
6172
6173 digit = base64.decode(aStr.charCodeAt(aIndex++));
6174 if (digit === -1) {
6175 throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
6176 }
6177
6178 continuation = !!(digit & VLQ_CONTINUATION_BIT);
6179 digit &= VLQ_BASE_MASK;
6180 result = result + (digit << shift);
6181 shift += VLQ_BASE_SHIFT;
6182 } while (continuation);
6183
6184 aOutParam.value = fromVLQSigned(result);
6185 aOutParam.rest = aIndex;
6186 };
6187
6188 },{"./base64":28}],28:[function(require,module,exports){
6189 /* -*- Mode: js; js-indent-level: 2; -*- */
6190 /*
6191 * Copyright 2011 Mozilla Foundation and contributors
6192 * Licensed under the New BSD license. See LICENSE or:
6193 * http://opensource.org/licenses/BSD-3-Clause
6194 */
6195
6196 var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
6197
6198 /**
6199 * Encode an integer in the range of 0 to 63 to a single base 64 digit.
6200 */
6201 exports.encode = function (number) {
6202 if (0 <= number && number < intToCharMap.length) {
6203 return intToCharMap[number];
6204 }
6205 throw new TypeError("Must be between 0 and 63: " + number);
6206 };
6207
6208 /**
6209 * Decode a single base 64 character code digit to an integer. Returns -1 on
6210 * failure.
6211 */
6212 exports.decode = function (charCode) {
6213 var bigA = 65; // 'A'
6214 var bigZ = 90; // 'Z'
6215
6216 var littleA = 97; // 'a'
6217 var littleZ = 122; // 'z'
6218
6219 var zero = 48; // '0'
6220 var nine = 57; // '9'
6221
6222 var plus = 43; // '+'
6223 var slash = 47; // '/'
6224
6225 var littleOffset = 26;
6226 var numberOffset = 52;
6227
6228 // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
6229 if (bigA <= charCode && charCode <= bigZ) {
6230 return (charCode - bigA);
6231 }
6232
6233 // 26 - 51: abcdefghijklmnopqrstuvwxyz
6234 if (littleA <= charCode && charCode <= littleZ) {
6235 return (charCode - littleA + littleOffset);
6236 }
6237
6238 // 52 - 61: 0123456789
6239 if (zero <= charCode && charCode <= nine) {
6240 return (charCode - zero + numberOffset);
6241 }
6242
6243 // 62: +
6244 if (charCode == plus) {
6245 return 62;
6246 }
6247
6248 // 63: /
6249 if (charCode == slash) {
6250 return 63;
6251 }
6252
6253 // Invalid base64 digit.
6254 return -1;
6255 };
6256
6257 },{}],29:[function(require,module,exports){
6258 /* -*- Mode: js; js-indent-level: 2; -*- */
6259 /*
6260 * Copyright 2011 Mozilla Foundation and contributors
6261 * Licensed under the New BSD license. See LICENSE or:
6262 * http://opensource.org/licenses/BSD-3-Clause
6263 */
6264
6265 exports.GREATEST_LOWER_BOUND = 1;
6266 exports.LEAST_UPPER_BOUND = 2;
6267
6268 /**
6269 * Recursive implementation of binary search.
6270 *
6271 * @param aLow Indices here and lower do not contain the needle.
6272 * @param aHigh Indices here and higher do not contain the needle.
6273 * @param aNeedle The element being searched for.
6274 * @param aHaystack The non-empty array being searched.
6275 * @param aCompare Function which takes two elements and returns -1, 0, or 1.
6276 * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
6277 * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
6278 * closest element that is smaller than or greater than the one we are
6279 * searching for, respectively, if the exact element cannot be found.
6280 */
6281 function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
6282 // This function terminates when one of the following is true:
6283 //
6284 // 1. We find the exact element we are looking for.
6285 //
6286 // 2. We did not find the exact element, but we can return the index of
6287 // the next-closest element.
6288 //
6289 // 3. We did not find the exact element, and there is no next-closest
6290 // element than the one we are searching for, so we return -1.
6291 var mid = Math.floor((aHigh - aLow) / 2) + aLow;
6292 var cmp = aCompare(aNeedle, aHaystack[mid], true);
6293 if (cmp === 0) {
6294 // Found the element we are looking for.
6295 return mid;
6296 }
6297 else if (cmp > 0) {
6298 // Our needle is greater than aHaystack[mid].
6299 if (aHigh - mid > 1) {
6300 // The element is in the upper half.
6301 return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
6302 }
6303
6304 // The exact needle element was not found in this haystack. Determine if
6305 // we are in termination case (3) or (2) and return the appropriate thing.
6306 if (aBias == exports.LEAST_UPPER_BOUND) {
6307 return aHigh < aHaystack.length ? aHigh : -1;
6308 } else {
6309 return mid;
6310 }
6311 }
6312 else {
6313 // Our needle is less than aHaystack[mid].
6314 if (mid - aLow > 1) {
6315 // The element is in the lower half.
6316 return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
6317 }
6318
6319 // we are in termination case (3) or (2) and return the appropriate thing.
6320 if (aBias == exports.LEAST_UPPER_BOUND) {
6321 return mid;
6322 } else {
6323 return aLow < 0 ? -1 : aLow;
6324 }
6325 }
6326 }
6327
6328 /**
6329 * This is an implementation of binary search which will always try and return
6330 * the index of the closest element if there is no exact hit. This is because
6331 * mappings between original and generated line/col pairs are single points,
6332 * and there is an implicit region between each of them, so a miss just means
6333 * that you aren't on the very start of a region.
6334 *
6335 * @param aNeedle The element you are looking for.
6336 * @param aHaystack The array that is being searched.
6337 * @param aCompare A function which takes the needle and an element in the
6338 * array and returns -1, 0, or 1 depending on whether the needle is less
6339 * than, equal to, or greater than the element, respectively.
6340 * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
6341 * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
6342 * closest element that is smaller than or greater than the one we are
6343 * searching for, respectively, if the exact element cannot be found.
6344 * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
6345 */
6346 exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
6347 if (aHaystack.length === 0) {
6348 return -1;
6349 }
6350
6351 var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
6352 aCompare, aBias || exports.GREATEST_LOWER_BOUND);
6353 if (index < 0) {
6354 return -1;
6355 }
6356
6357 // We have found either the exact element, or the next-closest element than
6358 // the one we are searching for. However, there may be more than one such
6359 // element. Make sure we always return the smallest of these.
6360 while (index - 1 >= 0) {
6361 if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
6362 break;
6363 }
6364 --index;
6365 }
6366
6367 return index;
6368 };
6369
6370 },{}],30:[function(require,module,exports){
6371 /* -*- Mode: js; js-indent-level: 2; -*- */
6372 /*
6373 * Copyright 2014 Mozilla Foundation and contributors
6374 * Licensed under the New BSD license. See LICENSE or:
6375 * http://opensource.org/licenses/BSD-3-Clause
6376 */
6377
6378 var util = require('./util');
6379
6380 /**
6381 * Determine whether mappingB is after mappingA with respect to generated
6382 * position.
6383 */
6384 function generatedPositionAfter(mappingA, mappingB) {
6385 // Optimized for most common case
6386 var lineA = mappingA.generatedLine;
6387 var lineB = mappingB.generatedLine;
6388 var columnA = mappingA.generatedColumn;
6389 var columnB = mappingB.generatedColumn;
6390 return lineB > lineA || lineB == lineA && columnB >= columnA ||
6391 util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
6392 }
6393
6394 /**
6395 * A data structure to provide a sorted view of accumulated mappings in a
6396 * performance conscious manner. It trades a neglibable overhead in general
6397 * case for a large speedup in case of mappings being added in order.
6398 */
6399 function MappingList() {
6400 this._array = [];
6401 this._sorted = true;
6402 // Serves as infimum
6403 this._last = {generatedLine: -1, generatedColumn: 0};
6404 }
6405
6406 /**
6407 * Iterate through internal items. This method takes the same arguments that
6408 * `Array.prototype.forEach` takes.
6409 *
6410 * NOTE: The order of the mappings is NOT guaranteed.
6411 */
6412 MappingList.prototype.unsortedForEach =
6413 function MappingList_forEach(aCallback, aThisArg) {
6414 this._array.forEach(aCallback, aThisArg);
6415 };
6416
6417 /**
6418 * Add the given source mapping.
6419 *
6420 * @param Object aMapping
6421 */
6422 MappingList.prototype.add = function MappingList_add(aMapping) {
6423 if (generatedPositionAfter(this._last, aMapping)) {
6424 this._last = aMapping;
6425 this._array.push(aMapping);
6426 } else {
6427 this._sorted = false;
6428 this._array.push(aMapping);
6429 }
6430 };
6431
6432 /**
6433 * Returns the flat, sorted array of mappings. The mappings are sorted by
6434 * generated position.
6435 *
6436 * WARNING: This method returns internal data without copying, for
6437 * performance. The return value must NOT be mutated, and should be treated as
6438 * an immutable borrow. If you want to take ownership, you must make your own
6439 * copy.
6440 */
6441 MappingList.prototype.toArray = function MappingList_toArray() {
6442 if (!this._sorted) {
6443 this._array.sort(util.compareByGeneratedPositionsInflated);
6444 this._sorted = true;
6445 }
6446 return this._array;
6447 };
6448
6449 exports.MappingList = MappingList;
6450
6451 },{"./util":35}],31:[function(require,module,exports){
6452 /* -*- Mode: js; js-indent-level: 2; -*- */
6453 /*
6454 * Copyright 2011 Mozilla Foundation and contributors
6455 * Licensed under the New BSD license. See LICENSE or:
6456 * http://opensource.org/licenses/BSD-3-Clause
6457 */
6458
6459 // It turns out that some (most?) JavaScript engines don't self-host
6460 // `Array.prototype.sort`. This makes sense because C++ will likely remain
6461 // faster than JS when doing raw CPU-intensive sorting. However, when using a
6462 // custom comparator function, calling back and forth between the VM's C++ and
6463 // JIT'd JS is rather slow *and* loses JIT type information, resulting in
6464 // worse generated code for the comparator function than would be optimal. In
6465 // fact, when sorting with a comparator, these costs outweigh the benefits of
6466 // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
6467 // a ~3500ms mean speed-up in `bench/bench.html`.
6468
6469 /**
6470 * Swap the elements indexed by `x` and `y` in the array `ary`.
6471 *
6472 * @param {Array} ary
6473 * The array.
6474 * @param {Number} x
6475 * The index of the first item.
6476 * @param {Number} y
6477 * The index of the second item.
6478 */
6479 function swap(ary, x, y) {
6480 var temp = ary[x];
6481 ary[x] = ary[y];
6482 ary[y] = temp;
6483 }
6484
6485 /**
6486 * Returns a random integer within the range `low .. high` inclusive.
6487 *
6488 * @param {Number} low
6489 * The lower bound on the range.
6490 * @param {Number} high
6491 * The upper bound on the range.
6492 */
6493 function randomIntInRange(low, high) {
6494 return Math.round(low + (Math.random() * (high - low)));
6495 }
6496
6497 /**
6498 * The Quick Sort algorithm.
6499 *
6500 * @param {Array} ary
6501 * An array to sort.
6502 * @param {function} comparator
6503 * Function to use to compare two items.
6504 * @param {Number} p
6505 * Start index of the array
6506 * @param {Number} r
6507 * End index of the array
6508 */
6509 function doQuickSort(ary, comparator, p, r) {
6510 // If our lower bound is less than our upper bound, we (1) partition the
6511 // array into two pieces and (2) recurse on each half. If it is not, this is
6512 // the empty array and our base case.
6513
6514 if (p < r) {
6515 // (1) Partitioning.
6516 //
6517 // The partitioning chooses a pivot between `p` and `r` and moves all
6518 // elements that are less than or equal to the pivot to the before it, and
6519 // all the elements that are greater than it after it. The effect is that
6520 // once partition is done, the pivot is in the exact place it will be when
6521 // the array is put in sorted order, and it will not need to be moved
6522 // again. This runs in O(n) time.
6523
6524 // Always choose a random pivot so that an input array which is reverse
6525 // sorted does not cause O(n^2) running time.
6526 var pivotIndex = randomIntInRange(p, r);
6527 var i = p - 1;
6528
6529 swap(ary, pivotIndex, r);
6530 var pivot = ary[r];
6531
6532 // Immediately after `j` is incremented in this loop, the following hold
6533 // true:
6534 //
6535 // * Every element in `ary[p .. i]` is less than or equal to the pivot.
6536 //
6537 // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
6538 for (var j = p; j < r; j++) {
6539 if (comparator(ary[j], pivot) <= 0) {
6540 i += 1;
6541 swap(ary, i, j);
6542 }
6543 }
6544
6545 swap(ary, i + 1, j);
6546 var q = i + 1;
6547
6548 // (2) Recurse on each half.
6549
6550 doQuickSort(ary, comparator, p, q - 1);
6551 doQuickSort(ary, comparator, q + 1, r);
6552 }
6553 }
6554
6555 /**
6556 * Sort the given array in-place with the given comparator function.
6557 *
6558 * @param {Array} ary
6559 * An array to sort.
6560 * @param {function} comparator
6561 * Function to use to compare two items.
6562 */
6563 exports.quickSort = function (ary, comparator) {
6564 doQuickSort(ary, comparator, 0, ary.length - 1);
6565 };
6566
6567 },{}],32:[function(require,module,exports){
6568 /* -*- Mode: js; js-indent-level: 2; -*- */
6569 /*
6570 * Copyright 2011 Mozilla Foundation and contributors
6571 * Licensed under the New BSD license. See LICENSE or:
6572 * http://opensource.org/licenses/BSD-3-Clause
6573 */
6574
6575 var util = require('./util');
6576 var binarySearch = require('./binary-search');
6577 var ArraySet = require('./array-set').ArraySet;
6578 var base64VLQ = require('./base64-vlq');
6579 var quickSort = require('./quick-sort').quickSort;
6580
6581 function SourceMapConsumer(aSourceMap, aSourceMapURL) {
6582 var sourceMap = aSourceMap;
6583 if (typeof aSourceMap === 'string') {
6584 sourceMap = util.parseSourceMapInput(aSourceMap);
6585 }
6586
6587 return sourceMap.sections != null
6588 ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
6589 : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
6590 }
6591
6592 SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
6593 return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
6594 }
6595
6596 /**
6597 * The version of the source mapping spec that we are consuming.
6598 */
6599 SourceMapConsumer.prototype._version = 3;
6600
6601 // `__generatedMappings` and `__originalMappings` are arrays that hold the
6602 // parsed mapping coordinates from the source map's "mappings" attribute. They
6603 // are lazily instantiated, accessed via the `_generatedMappings` and
6604 // `_originalMappings` getters respectively, and we only parse the mappings
6605 // and create these arrays once queried for a source location. We jump through
6606 // these hoops because there can be many thousands of mappings, and parsing
6607 // them is expensive, so we only want to do it if we must.
6608 //
6609 // Each object in the arrays is of the form:
6610 //
6611 // {
6612 // generatedLine: The line number in the generated code,
6613 // generatedColumn: The column number in the generated code,
6614 // source: The path to the original source file that generated this
6615 // chunk of code,
6616 // originalLine: The line number in the original source that
6617 // corresponds to this chunk of generated code,
6618 // originalColumn: The column number in the original source that
6619 // corresponds to this chunk of generated code,
6620 // name: The name of the original symbol which generated this chunk of
6621 // code.
6622 // }
6623 //
6624 // All properties except for `generatedLine` and `generatedColumn` can be
6625 // `null`.
6626 //
6627 // `_generatedMappings` is ordered by the generated positions.
6628 //
6629 // `_originalMappings` is ordered by the original positions.
6630
6631 SourceMapConsumer.prototype.__generatedMappings = null;
6632 Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
6633 configurable: true,
6634 enumerable: true,
6635 get: function () {
6636 if (!this.__generatedMappings) {
6637 this._parseMappings(this._mappings, this.sourceRoot);
6638 }
6639
6640 return this.__generatedMappings;
6641 }
6642 });
6643
6644 SourceMapConsumer.prototype.__originalMappings = null;
6645 Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
6646 configurable: true,
6647 enumerable: true,
6648 get: function () {
6649 if (!this.__originalMappings) {
6650 this._parseMappings(this._mappings, this.sourceRoot);
6651 }
6652
6653 return this.__originalMappings;
6654 }
6655 });
6656
6657 SourceMapConsumer.prototype._charIsMappingSeparator =
6658 function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
6659 var c = aStr.charAt(index);
6660 return c === ";" || c === ",";
6661 };
6662
6663 /**
6664 * Parse the mappings in a string in to a data structure which we can easily
6665 * query (the ordered arrays in the `this.__generatedMappings` and
6666 * `this.__originalMappings` properties).
6667 */
6668 SourceMapConsumer.prototype._parseMappings =
6669 function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
6670 throw new Error("Subclasses must implement _parseMappings");
6671 };
6672
6673 SourceMapConsumer.GENERATED_ORDER = 1;
6674 SourceMapConsumer.ORIGINAL_ORDER = 2;
6675
6676 SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
6677 SourceMapConsumer.LEAST_UPPER_BOUND = 2;
6678
6679 /**
6680 * Iterate over each mapping between an original source/line/column and a
6681 * generated line/column in this source map.
6682 *
6683 * @param Function aCallback
6684 * The function that is called with each mapping.
6685 * @param Object aContext
6686 * Optional. If specified, this object will be the value of `this` every
6687 * time that `aCallback` is called.
6688 * @param aOrder
6689 * Either `SourceMapConsumer.GENERATED_ORDER` or
6690 * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
6691 * iterate over the mappings sorted by the generated file's line/column
6692 * order or the original's source/line/column order, respectively. Defaults to
6693 * `SourceMapConsumer.GENERATED_ORDER`.
6694 */
6695 SourceMapConsumer.prototype.eachMapping =
6696 function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
6697 var context = aContext || null;
6698 var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
6699
6700 var mappings;
6701 switch (order) {
6702 case SourceMapConsumer.GENERATED_ORDER:
6703 mappings = this._generatedMappings;
6704 break;
6705 case SourceMapConsumer.ORIGINAL_ORDER:
6706 mappings = this._originalMappings;
6707 break;
6708 default:
6709 throw new Error("Unknown order of iteration.");
6710 }
6711
6712 var sourceRoot = this.sourceRoot;
6713 mappings.map(function (mapping) {
6714 var source = mapping.source === null ? null : this._sources.at(mapping.source);
6715 source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
6716 return {
6717 source: source,
6718 generatedLine: mapping.generatedLine,
6719 generatedColumn: mapping.generatedColumn,
6720 originalLine: mapping.originalLine,
6721 originalColumn: mapping.originalColumn,
6722 name: mapping.name === null ? null : this._names.at(mapping.name)
6723 };
6724 }, this).forEach(aCallback, context);
6725 };
6726
6727 /**
6728 * Returns all generated line and column information for the original source,
6729 * line, and column provided. If no column is provided, returns all mappings
6730 * corresponding to a either the line we are searching for or the next
6731 * closest line that has any mappings. Otherwise, returns all mappings
6732 * corresponding to the given line and either the column we are searching for
6733 * or the next closest column that has any offsets.
6734 *
6735 * The only argument is an object with the following properties:
6736 *
6737 * - source: The filename of the original source.
6738 * - line: The line number in the original source. The line number is 1-based.
6739 * - column: Optional. the column number in the original source.
6740 * The column number is 0-based.
6741 *
6742 * and an array of objects is returned, each with the following properties:
6743 *
6744 * - line: The line number in the generated source, or null. The
6745 * line number is 1-based.
6746 * - column: The column number in the generated source, or null.
6747 * The column number is 0-based.
6748 */
6749 SourceMapConsumer.prototype.allGeneratedPositionsFor =
6750 function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
6751 var line = util.getArg(aArgs, 'line');
6752
6753 // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
6754 // returns the index of the closest mapping less than the needle. By
6755 // setting needle.originalColumn to 0, we thus find the last mapping for
6756 // the given line, provided such a mapping exists.
6757 var needle = {
6758 source: util.getArg(aArgs, 'source'),
6759 originalLine: line,
6760 originalColumn: util.getArg(aArgs, 'column', 0)
6761 };
6762
6763 needle.source = this._findSourceIndex(needle.source);
6764 if (needle.source < 0) {
6765 return [];
6766 }
6767
6768 var mappings = [];
6769
6770 var index = this._findMapping(needle,
6771 this._originalMappings,
6772 "originalLine",
6773 "originalColumn",
6774 util.compareByOriginalPositions,
6775 binarySearch.LEAST_UPPER_BOUND);
6776 if (index >= 0) {
6777 var mapping = this._originalMappings[index];
6778
6779 if (aArgs.column === undefined) {
6780 var originalLine = mapping.originalLine;
6781
6782 // Iterate until either we run out of mappings, or we run into
6783 // a mapping for a different line than the one we found. Since
6784 // mappings are sorted, this is guaranteed to find all mappings for
6785 // the line we found.
6786 while (mapping && mapping.originalLine === originalLine) {
6787 mappings.push({
6788 line: util.getArg(mapping, 'generatedLine', null),
6789 column: util.getArg(mapping, 'generatedColumn', null),
6790 lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
6791 });
6792
6793 mapping = this._originalMappings[++index];
6794 }
6795 } else {
6796 var originalColumn = mapping.originalColumn;
6797
6798 // Iterate until either we run out of mappings, or we run into
6799 // a mapping for a different line than the one we were searching for.
6800 // Since mappings are sorted, this is guaranteed to find all mappings for
6801 // the line we are searching for.
6802 while (mapping &&
6803 mapping.originalLine === line &&
6804 mapping.originalColumn == originalColumn) {
6805 mappings.push({
6806 line: util.getArg(mapping, 'generatedLine', null),
6807 column: util.getArg(mapping, 'generatedColumn', null),
6808 lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
6809 });
6810
6811 mapping = this._originalMappings[++index];
6812 }
6813 }
6814 }
6815
6816 return mappings;
6817 };
6818
6819 exports.SourceMapConsumer = SourceMapConsumer;
6820
6821 /**
6822 * A BasicSourceMapConsumer instance represents a parsed source map which we can
6823 * query for information about the original file positions by giving it a file
6824 * position in the generated source.
6825 *
6826 * The first parameter is the raw source map (either as a JSON string, or
6827 * already parsed to an object). According to the spec, source maps have the
6828 * following attributes:
6829 *
6830 * - version: Which version of the source map spec this map is following.
6831 * - sources: An array of URLs to the original source files.
6832 * - names: An array of identifiers which can be referrenced by individual mappings.
6833 * - sourceRoot: Optional. The URL root from which all sources are relative.
6834 * - sourcesContent: Optional. An array of contents of the original source files.
6835 * - mappings: A string of base64 VLQs which contain the actual mappings.
6836 * - file: Optional. The generated file this source map is associated with.
6837 *
6838 * Here is an example source map, taken from the source map spec[0]:
6839 *
6840 * {
6841 * version : 3,
6842 * file: "out.js",
6843 * sourceRoot : "",
6844 * sources: ["foo.js", "bar.js"],
6845 * names: ["src", "maps", "are", "fun"],
6846 * mappings: "AA,AB;;ABCDE;"
6847 * }
6848 *
6849 * The second parameter, if given, is a string whose value is the URL
6850 * at which the source map was found. This URL is used to compute the
6851 * sources array.
6852 *
6853 * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
6854 */
6855 function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
6856 var sourceMap = aSourceMap;
6857 if (typeof aSourceMap === 'string') {
6858 sourceMap = util.parseSourceMapInput(aSourceMap);
6859 }
6860
6861 var version = util.getArg(sourceMap, 'version');
6862 var sources = util.getArg(sourceMap, 'sources');
6863 // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
6864 // requires the array) to play nice here.
6865 var names = util.getArg(sourceMap, 'names', []);
6866 var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
6867 var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
6868 var mappings = util.getArg(sourceMap, 'mappings');
6869 var file = util.getArg(sourceMap, 'file', null);
6870
6871 // Once again, Sass deviates from the spec and supplies the version as a
6872 // string rather than a number, so we use loose equality checking here.
6873 if (version != this._version) {
6874 throw new Error('Unsupported version: ' + version);
6875 }
6876
6877 if (sourceRoot) {
6878 sourceRoot = util.normalize(sourceRoot);
6879 }
6880
6881 sources = sources
6882 .map(String)
6883 // Some source maps produce relative source paths like "./foo.js" instead of
6884 // "foo.js". Normalize these first so that future comparisons will succeed.
6885 // See bugzil.la/1090768.
6886 .map(util.normalize)
6887 // Always ensure that absolute sources are internally stored relative to
6888 // the source root, if the source root is absolute. Not doing this would
6889 // be particularly problematic when the source root is a prefix of the
6890 // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
6891 .map(function (source) {
6892 return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
6893 ? util.relative(sourceRoot, source)
6894 : source;
6895 });
6896
6897 // Pass `true` below to allow duplicate names and sources. While source maps
6898 // are intended to be compressed and deduplicated, the TypeScript compiler
6899 // sometimes generates source maps with duplicates in them. See Github issue
6900 // #72 and bugzil.la/889492.
6901 this._names = ArraySet.fromArray(names.map(String), true);
6902 this._sources = ArraySet.fromArray(sources, true);
6903
6904 this._absoluteSources = this._sources.toArray().map(function (s) {
6905 return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
6906 });
6907
6908 this.sourceRoot = sourceRoot;
6909 this.sourcesContent = sourcesContent;
6910 this._mappings = mappings;
6911 this._sourceMapURL = aSourceMapURL;
6912 this.file = file;
6913 }
6914
6915 BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
6916 BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
6917
6918 /**
6919 * Utility function to find the index of a source. Returns -1 if not
6920 * found.
6921 */
6922 BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
6923 var relativeSource = aSource;
6924 if (this.sourceRoot != null) {
6925 relativeSource = util.relative(this.sourceRoot, relativeSource);
6926 }
6927
6928 if (this._sources.has(relativeSource)) {
6929 return this._sources.indexOf(relativeSource);
6930 }
6931
6932 // Maybe aSource is an absolute URL as returned by |sources|. In
6933 // this case we can't simply undo the transform.
6934 var i;
6935 for (i = 0; i < this._absoluteSources.length; ++i) {
6936 if (this._absoluteSources[i] == aSource) {
6937 return i;
6938 }
6939 }
6940
6941 return -1;
6942 };
6943
6944 /**
6945 * Create a BasicSourceMapConsumer from a SourceMapGenerator.
6946 *
6947 * @param SourceMapGenerator aSourceMap
6948 * The source map that will be consumed.
6949 * @param String aSourceMapURL
6950 * The URL at which the source map can be found (optional)
6951 * @returns BasicSourceMapConsumer
6952 */
6953 BasicSourceMapConsumer.fromSourceMap =
6954 function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
6955 var smc = Object.create(BasicSourceMapConsumer.prototype);
6956
6957 var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
6958 var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
6959 smc.sourceRoot = aSourceMap._sourceRoot;
6960 smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
6961 smc.sourceRoot);
6962 smc.file = aSourceMap._file;
6963 smc._sourceMapURL = aSourceMapURL;
6964 smc._absoluteSources = smc._sources.toArray().map(function (s) {
6965 return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
6966 });
6967
6968 // Because we are modifying the entries (by converting string sources and
6969 // names to indices into the sources and names ArraySets), we have to make
6970 // a copy of the entry or else bad things happen. Shared mutable state
6971 // strikes again! See github issue #191.
6972
6973 var generatedMappings = aSourceMap._mappings.toArray().slice();
6974 var destGeneratedMappings = smc.__generatedMappings = [];
6975 var destOriginalMappings = smc.__originalMappings = [];
6976
6977 for (var i = 0, length = generatedMappings.length; i < length; i++) {
6978 var srcMapping = generatedMappings[i];
6979 var destMapping = new Mapping;
6980 destMapping.generatedLine = srcMapping.generatedLine;
6981 destMapping.generatedColumn = srcMapping.generatedColumn;
6982
6983 if (srcMapping.source) {
6984 destMapping.source = sources.indexOf(srcMapping.source);
6985 destMapping.originalLine = srcMapping.originalLine;
6986 destMapping.originalColumn = srcMapping.originalColumn;
6987
6988 if (srcMapping.name) {
6989 destMapping.name = names.indexOf(srcMapping.name);
6990 }
6991
6992 destOriginalMappings.push(destMapping);
6993 }
6994
6995 destGeneratedMappings.push(destMapping);
6996 }
6997
6998 quickSort(smc.__originalMappings, util.compareByOriginalPositions);
6999
7000 return smc;
7001 };
7002
7003 /**
7004 * The version of the source mapping spec that we are consuming.
7005 */
7006 BasicSourceMapConsumer.prototype._version = 3;
7007
7008 /**
7009 * The list of original sources.
7010 */
7011 Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
7012 get: function () {
7013 return this._absoluteSources.slice();
7014 }
7015 });
7016
7017 /**
7018 * Provide the JIT with a nice shape / hidden class.
7019 */
7020 function Mapping() {
7021 this.generatedLine = 0;
7022 this.generatedColumn = 0;
7023 this.source = null;
7024 this.originalLine = null;
7025 this.originalColumn = null;
7026 this.name = null;
7027 }
7028
7029 /**
7030 * Parse the mappings in a string in to a data structure which we can easily
7031 * query (the ordered arrays in the `this.__generatedMappings` and
7032 * `this.__originalMappings` properties).
7033 */
7034 BasicSourceMapConsumer.prototype._parseMappings =
7035 function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
7036 var generatedLine = 1;
7037 var previousGeneratedColumn = 0;
7038 var previousOriginalLine = 0;
7039 var previousOriginalColumn = 0;
7040 var previousSource = 0;
7041 var previousName = 0;
7042 var length = aStr.length;
7043 var index = 0;
7044 var cachedSegments = {};
7045 var temp = {};
7046 var originalMappings = [];
7047 var generatedMappings = [];
7048 var mapping, str, segment, end, value;
7049
7050 while (index < length) {
7051 if (aStr.charAt(index) === ';') {
7052 generatedLine++;
7053 index++;
7054 previousGeneratedColumn = 0;
7055 }
7056 else if (aStr.charAt(index) === ',') {
7057 index++;
7058 }
7059 else {
7060 mapping = new Mapping();
7061 mapping.generatedLine = generatedLine;
7062
7063 // Because each offset is encoded relative to the previous one,
7064 // many segments often have the same encoding. We can exploit this
7065 // fact by caching the parsed variable length fields of each segment,
7066 // allowing us to avoid a second parse if we encounter the same
7067 // segment again.
7068 for (end = index; end < length; end++) {
7069 if (this._charIsMappingSeparator(aStr, end)) {
7070 break;
7071 }
7072 }
7073 str = aStr.slice(index, end);
7074
7075 segment = cachedSegments[str];
7076 if (segment) {
7077 index += str.length;
7078 } else {
7079 segment = [];
7080 while (index < end) {
7081 base64VLQ.decode(aStr, index, temp);
7082 value = temp.value;
7083 index = temp.rest;
7084 segment.push(value);
7085 }
7086
7087 if (segment.length === 2) {
7088 throw new Error('Found a source, but no line and column');
7089 }
7090
7091 if (segment.length === 3) {
7092 throw new Error('Found a source and line, but no column');
7093 }
7094
7095 cachedSegments[str] = segment;
7096 }
7097
7098 // Generated column.
7099 mapping.generatedColumn = previousGeneratedColumn + segment[0];
7100 previousGeneratedColumn = mapping.generatedColumn;
7101
7102 if (segment.length > 1) {
7103 // Original source.
7104 mapping.source = previousSource + segment[1];
7105 previousSource += segment[1];
7106
7107 // Original line.
7108 mapping.originalLine = previousOriginalLine + segment[2];
7109 previousOriginalLine = mapping.originalLine;
7110 // Lines are stored 0-based
7111 mapping.originalLine += 1;
7112
7113 // Original column.
7114 mapping.originalColumn = previousOriginalColumn + segment[3];
7115 previousOriginalColumn = mapping.originalColumn;
7116
7117 if (segment.length > 4) {
7118 // Original name.
7119 mapping.name = previousName + segment[4];
7120 previousName += segment[4];
7121 }
7122 }
7123
7124 generatedMappings.push(mapping);
7125 if (typeof mapping.originalLine === 'number') {
7126 originalMappings.push(mapping);
7127 }
7128 }
7129 }
7130
7131 quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
7132 this.__generatedMappings = generatedMappings;
7133
7134 quickSort(originalMappings, util.compareByOriginalPositions);
7135 this.__originalMappings = originalMappings;
7136 };
7137
7138 /**
7139 * Find the mapping that best matches the hypothetical "needle" mapping that
7140 * we are searching for in the given "haystack" of mappings.
7141 */
7142 BasicSourceMapConsumer.prototype._findMapping =
7143 function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
7144 aColumnName, aComparator, aBias) {
7145 // To return the position we are searching for, we must first find the
7146 // mapping for the given position and then return the opposite position it
7147 // points to. Because the mappings are sorted, we can use binary search to
7148 // find the best mapping.
7149
7150 if (aNeedle[aLineName] <= 0) {
7151 throw new TypeError('Line must be greater than or equal to 1, got '
7152 + aNeedle[aLineName]);
7153 }
7154 if (aNeedle[aColumnName] < 0) {
7155 throw new TypeError('Column must be greater than or equal to 0, got '
7156 + aNeedle[aColumnName]);
7157 }
7158
7159 return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
7160 };
7161
7162 /**
7163 * Compute the last column for each generated mapping. The last column is
7164 * inclusive.
7165 */
7166 BasicSourceMapConsumer.prototype.computeColumnSpans =
7167 function SourceMapConsumer_computeColumnSpans() {
7168 for (var index = 0; index < this._generatedMappings.length; ++index) {
7169 var mapping = this._generatedMappings[index];
7170
7171 // Mappings do not contain a field for the last generated columnt. We
7172 // can come up with an optimistic estimate, however, by assuming that
7173 // mappings are contiguous (i.e. given two consecutive mappings, the
7174 // first mapping ends where the second one starts).
7175 if (index + 1 < this._generatedMappings.length) {
7176 var nextMapping = this._generatedMappings[index + 1];
7177
7178 if (mapping.generatedLine === nextMapping.generatedLine) {
7179 mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
7180 continue;
7181 }
7182 }
7183
7184 // The last mapping for each line spans the entire line.
7185 mapping.lastGeneratedColumn = Infinity;
7186 }
7187 };
7188
7189 /**
7190 * Returns the original source, line, and column information for the generated
7191 * source's line and column positions provided. The only argument is an object
7192 * with the following properties:
7193 *
7194 * - line: The line number in the generated source. The line number
7195 * is 1-based.
7196 * - column: The column number in the generated source. The column
7197 * number is 0-based.
7198 * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
7199 * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
7200 * closest element that is smaller than or greater than the one we are
7201 * searching for, respectively, if the exact element cannot be found.
7202 * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
7203 *
7204 * and an object is returned with the following properties:
7205 *
7206 * - source: The original source file, or null.
7207 * - line: The line number in the original source, or null. The
7208 * line number is 1-based.
7209 * - column: The column number in the original source, or null. The
7210 * column number is 0-based.
7211 * - name: The original identifier, or null.
7212 */
7213 BasicSourceMapConsumer.prototype.originalPositionFor =
7214 function SourceMapConsumer_originalPositionFor(aArgs) {
7215 var needle = {
7216 generatedLine: util.getArg(aArgs, 'line'),
7217 generatedColumn: util.getArg(aArgs, 'column')
7218 };
7219
7220 var index = this._findMapping(
7221 needle,
7222 this._generatedMappings,
7223 "generatedLine",
7224 "generatedColumn",
7225 util.compareByGeneratedPositionsDeflated,
7226 util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
7227 );
7228
7229 if (index >= 0) {
7230 var mapping = this._generatedMappings[index];
7231
7232 if (mapping.generatedLine === needle.generatedLine) {
7233 var source = util.getArg(mapping, 'source', null);
7234 if (source !== null) {
7235 source = this._sources.at(source);
7236 source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
7237 }
7238 var name = util.getArg(mapping, 'name', null);
7239 if (name !== null) {
7240 name = this._names.at(name);
7241 }
7242 return {
7243 source: source,
7244 line: util.getArg(mapping, 'originalLine', null),
7245 column: util.getArg(mapping, 'originalColumn', null),
7246 name: name
7247 };
7248 }
7249 }
7250
7251 return {
7252 source: null,
7253 line: null,
7254 column: null,
7255 name: null
7256 };
7257 };
7258
7259 /**
7260 * Return true if we have the source content for every source in the source
7261 * map, false otherwise.
7262 */
7263 BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
7264 function BasicSourceMapConsumer_hasContentsOfAllSources() {
7265 if (!this.sourcesContent) {
7266 return false;
7267 }
7268 return this.sourcesContent.length >= this._sources.size() &&
7269 !this.sourcesContent.some(function (sc) { return sc == null; });
7270 };
7271
7272 /**
7273 * Returns the original source content. The only argument is the url of the
7274 * original source file. Returns null if no original source content is
7275 * available.
7276 */
7277 BasicSourceMapConsumer.prototype.sourceContentFor =
7278 function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
7279 if (!this.sourcesContent) {
7280 return null;
7281 }
7282
7283 var index = this._findSourceIndex(aSource);
7284 if (index >= 0) {
7285 return this.sourcesContent[index];
7286 }
7287
7288 var relativeSource = aSource;
7289 if (this.sourceRoot != null) {
7290 relativeSource = util.relative(this.sourceRoot, relativeSource);
7291 }
7292
7293 var url;
7294 if (this.sourceRoot != null
7295 && (url = util.urlParse(this.sourceRoot))) {
7296 // XXX: file:// URIs and absolute paths lead to unexpected behavior for
7297 // many users. We can help them out when they expect file:// URIs to
7298 // behave like it would if they were running a local HTTP server. See
7299 // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
7300 var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
7301 if (url.scheme == "file"
7302 && this._sources.has(fileUriAbsPath)) {
7303 return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
7304 }
7305
7306 if ((!url.path || url.path == "/")
7307 && this._sources.has("/" + relativeSource)) {
7308 return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
7309 }
7310 }
7311
7312 // This function is used recursively from
7313 // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
7314 // don't want to throw if we can't find the source - we just want to
7315 // return null, so we provide a flag to exit gracefully.
7316 if (nullOnMissing) {
7317 return null;
7318 }
7319 else {
7320 throw new Error('"' + relativeSource + '" is not in the SourceMap.');
7321 }
7322 };
7323
7324 /**
7325 * Returns the generated line and column information for the original source,
7326 * line, and column positions provided. The only argument is an object with
7327 * the following properties:
7328 *
7329 * - source: The filename of the original source.
7330 * - line: The line number in the original source. The line number
7331 * is 1-based.
7332 * - column: The column number in the original source. The column
7333 * number is 0-based.
7334 * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
7335 * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
7336 * closest element that is smaller than or greater than the one we are
7337 * searching for, respectively, if the exact element cannot be found.
7338 * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
7339 *
7340 * and an object is returned with the following properties:
7341 *
7342 * - line: The line number in the generated source, or null. The
7343 * line number is 1-based.
7344 * - column: The column number in the generated source, or null.
7345 * The column number is 0-based.
7346 */
7347 BasicSourceMapConsumer.prototype.generatedPositionFor =
7348 function SourceMapConsumer_generatedPositionFor(aArgs) {
7349 var source = util.getArg(aArgs, 'source');
7350 source = this._findSourceIndex(source);
7351 if (source < 0) {
7352 return {
7353 line: null,
7354 column: null,
7355 lastColumn: null
7356 };
7357 }
7358
7359 var needle = {
7360 source: source,
7361 originalLine: util.getArg(aArgs, 'line'),
7362 originalColumn: util.getArg(aArgs, 'column')
7363 };
7364
7365 var index = this._findMapping(
7366 needle,
7367 this._originalMappings,
7368 "originalLine",
7369 "originalColumn",
7370 util.compareByOriginalPositions,
7371 util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
7372 );
7373
7374 if (index >= 0) {
7375 var mapping = this._originalMappings[index];
7376
7377 if (mapping.source === needle.source) {
7378 return {
7379 line: util.getArg(mapping, 'generatedLine', null),
7380 column: util.getArg(mapping, 'generatedColumn', null),
7381 lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
7382 };
7383 }
7384 }
7385
7386 return {
7387 line: null,
7388 column: null,
7389 lastColumn: null
7390 };
7391 };
7392
7393 exports.BasicSourceMapConsumer = BasicSourceMapConsumer;
7394
7395 /**
7396 * An IndexedSourceMapConsumer instance represents a parsed source map which
7397 * we can query for information. It differs from BasicSourceMapConsumer in
7398 * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
7399 * input.
7400 *
7401 * The first parameter is a raw source map (either as a JSON string, or already
7402 * parsed to an object). According to the spec for indexed source maps, they
7403 * have the following attributes:
7404 *
7405 * - version: Which version of the source map spec this map is following.
7406 * - file: Optional. The generated file this source map is associated with.
7407 * - sections: A list of section definitions.
7408 *
7409 * Each value under the "sections" field has two fields:
7410 * - offset: The offset into the original specified at which this section
7411 * begins to apply, defined as an object with a "line" and "column"
7412 * field.
7413 * - map: A source map definition. This source map could also be indexed,
7414 * but doesn't have to be.
7415 *
7416 * Instead of the "map" field, it's also possible to have a "url" field
7417 * specifying a URL to retrieve a source map from, but that's currently
7418 * unsupported.
7419 *
7420 * Here's an example source map, taken from the source map spec[0], but
7421 * modified to omit a section which uses the "url" field.
7422 *
7423 * {
7424 * version : 3,
7425 * file: "app.js",
7426 * sections: [{
7427 * offset: {line:100, column:10},
7428 * map: {
7429 * version : 3,
7430 * file: "section.js",
7431 * sources: ["foo.js", "bar.js"],
7432 * names: ["src", "maps", "are", "fun"],
7433 * mappings: "AAAA,E;;ABCDE;"
7434 * }
7435 * }],
7436 * }
7437 *
7438 * The second parameter, if given, is a string whose value is the URL
7439 * at which the source map was found. This URL is used to compute the
7440 * sources array.
7441 *
7442 * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
7443 */
7444 function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
7445 var sourceMap = aSourceMap;
7446 if (typeof aSourceMap === 'string') {
7447 sourceMap = util.parseSourceMapInput(aSourceMap);
7448 }
7449
7450 var version = util.getArg(sourceMap, 'version');
7451 var sections = util.getArg(sourceMap, 'sections');
7452
7453 if (version != this._version) {
7454 throw new Error('Unsupported version: ' + version);
7455 }
7456
7457 this._sources = new ArraySet();
7458 this._names = new ArraySet();
7459
7460 var lastOffset = {
7461 line: -1,
7462 column: 0
7463 };
7464 this._sections = sections.map(function (s) {
7465 if (s.url) {
7466 // The url field will require support for asynchronicity.
7467 // See https://github.com/mozilla/source-map/issues/16
7468 throw new Error('Support for url field in sections not implemented.');
7469 }
7470 var offset = util.getArg(s, 'offset');
7471 var offsetLine = util.getArg(offset, 'line');
7472 var offsetColumn = util.getArg(offset, 'column');
7473
7474 if (offsetLine < lastOffset.line ||
7475 (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
7476 throw new Error('Section offsets must be ordered and non-overlapping.');
7477 }
7478 lastOffset = offset;
7479
7480 return {
7481 generatedOffset: {
7482 // The offset fields are 0-based, but we use 1-based indices when
7483 // encoding/decoding from VLQ.
7484 generatedLine: offsetLine + 1,
7485 generatedColumn: offsetColumn + 1
7486 },
7487 consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
7488 }
7489 });
7490 }
7491
7492 IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
7493 IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
7494
7495 /**
7496 * The version of the source mapping spec that we are consuming.
7497 */
7498 IndexedSourceMapConsumer.prototype._version = 3;
7499
7500 /**
7501 * The list of original sources.
7502 */
7503 Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
7504 get: function () {
7505 var sources = [];
7506 for (var i = 0; i < this._sections.length; i++) {
7507 for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
7508 sources.push(this._sections[i].consumer.sources[j]);
7509 }
7510 }
7511 return sources;
7512 }
7513 });
7514
7515 /**
7516 * Returns the original source, line, and column information for the generated
7517 * source's line and column positions provided. The only argument is an object
7518 * with the following properties:
7519 *
7520 * - line: The line number in the generated source. The line number
7521 * is 1-based.
7522 * - column: The column number in the generated source. The column
7523 * number is 0-based.
7524 *
7525 * and an object is returned with the following properties:
7526 *
7527 * - source: The original source file, or null.
7528 * - line: The line number in the original source, or null. The
7529 * line number is 1-based.
7530 * - column: The column number in the original source, or null. The
7531 * column number is 0-based.
7532 * - name: The original identifier, or null.
7533 */
7534 IndexedSourceMapConsumer.prototype.originalPositionFor =
7535 function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
7536 var needle = {
7537 generatedLine: util.getArg(aArgs, 'line'),
7538 generatedColumn: util.getArg(aArgs, 'column')
7539 };
7540
7541 // Find the section containing the generated position we're trying to map
7542 // to an original position.
7543 var sectionIndex = binarySearch.search(needle, this._sections,
7544 function(needle, section) {
7545 var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
7546 if (cmp) {
7547 return cmp;
7548 }
7549
7550 return (needle.generatedColumn -
7551 section.generatedOffset.generatedColumn);
7552 });
7553 var section = this._sections[sectionIndex];
7554
7555 if (!section) {
7556 return {
7557 source: null,
7558 line: null,
7559 column: null,
7560 name: null
7561 };
7562 }
7563
7564 return section.consumer.originalPositionFor({
7565 line: needle.generatedLine -
7566 (section.generatedOffset.generatedLine - 1),
7567 column: needle.generatedColumn -
7568 (section.generatedOffset.generatedLine === needle.generatedLine
7569 ? section.generatedOffset.generatedColumn - 1
7570 : 0),
7571 bias: aArgs.bias
7572 });
7573 };
7574
7575 /**
7576 * Return true if we have the source content for every source in the source
7577 * map, false otherwise.
7578 */
7579 IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
7580 function IndexedSourceMapConsumer_hasContentsOfAllSources() {
7581 return this._sections.every(function (s) {
7582 return s.consumer.hasContentsOfAllSources();
7583 });
7584 };
7585
7586 /**
7587 * Returns the original source content. The only argument is the url of the
7588 * original source file. Returns null if no original source content is
7589 * available.
7590 */
7591 IndexedSourceMapConsumer.prototype.sourceContentFor =
7592 function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
7593 for (var i = 0; i < this._sections.length; i++) {
7594 var section = this._sections[i];
7595
7596 var content = section.consumer.sourceContentFor(aSource, true);
7597 if (content) {
7598 return content;
7599 }
7600 }
7601 if (nullOnMissing) {
7602 return null;
7603 }
7604 else {
7605 throw new Error('"' + aSource + '" is not in the SourceMap.');
7606 }
7607 };
7608
7609 /**
7610 * Returns the generated line and column information for the original source,
7611 * line, and column positions provided. The only argument is an object with
7612 * the following properties:
7613 *
7614 * - source: The filename of the original source.
7615 * - line: The line number in the original source. The line number
7616 * is 1-based.
7617 * - column: The column number in the original source. The column
7618 * number is 0-based.
7619 *
7620 * and an object is returned with the following properties:
7621 *
7622 * - line: The line number in the generated source, or null. The
7623 * line number is 1-based.
7624 * - column: The column number in the generated source, or null.
7625 * The column number is 0-based.
7626 */
7627 IndexedSourceMapConsumer.prototype.generatedPositionFor =
7628 function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
7629 for (var i = 0; i < this._sections.length; i++) {
7630 var section = this._sections[i];
7631
7632 // Only consider this section if the requested source is in the list of
7633 // sources of the consumer.
7634 if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
7635 continue;
7636 }
7637 var generatedPosition = section.consumer.generatedPositionFor(aArgs);
7638 if (generatedPosition) {
7639 var ret = {
7640 line: generatedPosition.line +
7641 (section.generatedOffset.generatedLine - 1),
7642 column: generatedPosition.column +
7643 (section.generatedOffset.generatedLine === generatedPosition.line
7644 ? section.generatedOffset.generatedColumn - 1
7645 : 0)
7646 };
7647 return ret;
7648 }
7649 }
7650
7651 return {
7652 line: null,
7653 column: null
7654 };
7655 };
7656
7657 /**
7658 * Parse the mappings in a string in to a data structure which we can easily
7659 * query (the ordered arrays in the `this.__generatedMappings` and
7660 * `this.__originalMappings` properties).
7661 */
7662 IndexedSourceMapConsumer.prototype._parseMappings =
7663 function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
7664 this.__generatedMappings = [];
7665 this.__originalMappings = [];
7666 for (var i = 0; i < this._sections.length; i++) {
7667 var section = this._sections[i];
7668 var sectionMappings = section.consumer._generatedMappings;
7669 for (var j = 0; j < sectionMappings.length; j++) {
7670 var mapping = sectionMappings[j];
7671
7672 var source = section.consumer._sources.at(mapping.source);
7673 source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
7674 this._sources.add(source);
7675 source = this._sources.indexOf(source);
7676
7677 var name = null;
7678 if (mapping.name) {
7679 name = section.consumer._names.at(mapping.name);
7680 this._names.add(name);
7681 name = this._names.indexOf(name);
7682 }
7683
7684 // The mappings coming from the consumer for the section have
7685 // generated positions relative to the start of the section, so we
7686 // need to offset them to be relative to the start of the concatenated
7687 // generated file.
7688 var adjustedMapping = {
7689 source: source,
7690 generatedLine: mapping.generatedLine +
7691 (section.generatedOffset.generatedLine - 1),
7692 generatedColumn: mapping.generatedColumn +
7693 (section.generatedOffset.generatedLine === mapping.generatedLine
7694 ? section.generatedOffset.generatedColumn - 1
7695 : 0),
7696 originalLine: mapping.originalLine,
7697 originalColumn: mapping.originalColumn,
7698 name: name
7699 };
7700
7701 this.__generatedMappings.push(adjustedMapping);
7702 if (typeof adjustedMapping.originalLine === 'number') {
7703 this.__originalMappings.push(adjustedMapping);
7704 }
7705 }
7706 }
7707
7708 quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
7709 quickSort(this.__originalMappings, util.compareByOriginalPositions);
7710 };
7711
7712 exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
7713
7714 },{"./array-set":26,"./base64-vlq":27,"./binary-search":29,"./quick-sort":31,"./util":35}],33:[function(require,module,exports){
7715 /* -*- Mode: js; js-indent-level: 2; -*- */
7716 /*
7717 * Copyright 2011 Mozilla Foundation and contributors
7718 * Licensed under the New BSD license. See LICENSE or:
7719 * http://opensource.org/licenses/BSD-3-Clause
7720 */
7721
7722 var base64VLQ = require('./base64-vlq');
7723 var util = require('./util');
7724 var ArraySet = require('./array-set').ArraySet;
7725 var MappingList = require('./mapping-list').MappingList;
7726
7727 /**
7728 * An instance of the SourceMapGenerator represents a source map which is
7729 * being built incrementally. You may pass an object with the following
7730 * properties:
7731 *
7732 * - file: The filename of the generated source.
7733 * - sourceRoot: A root for all relative URLs in this source map.
7734 */
7735 function SourceMapGenerator(aArgs) {
7736 if (!aArgs) {
7737 aArgs = {};
7738 }
7739 this._file = util.getArg(aArgs, 'file', null);
7740 this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
7741 this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
7742 this._sources = new ArraySet();
7743 this._names = new ArraySet();
7744 this._mappings = new MappingList();
7745 this._sourcesContents = null;
7746 }
7747
7748 SourceMapGenerator.prototype._version = 3;
7749
7750 /**
7751 * Creates a new SourceMapGenerator based on a SourceMapConsumer
7752 *
7753 * @param aSourceMapConsumer The SourceMap.
7754 */
7755 SourceMapGenerator.fromSourceMap =
7756 function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
7757 var sourceRoot = aSourceMapConsumer.sourceRoot;
7758 var generator = new SourceMapGenerator({
7759 file: aSourceMapConsumer.file,
7760 sourceRoot: sourceRoot
7761 });
7762 aSourceMapConsumer.eachMapping(function (mapping) {
7763 var newMapping = {
7764 generated: {
7765 line: mapping.generatedLine,
7766 column: mapping.generatedColumn
7767 }
7768 };
7769
7770 if (mapping.source != null) {
7771 newMapping.source = mapping.source;
7772 if (sourceRoot != null) {
7773 newMapping.source = util.relative(sourceRoot, newMapping.source);
7774 }
7775
7776 newMapping.original = {
7777 line: mapping.originalLine,
7778 column: mapping.originalColumn
7779 };
7780
7781 if (mapping.name != null) {
7782 newMapping.name = mapping.name;
7783 }
7784 }
7785
7786 generator.addMapping(newMapping);
7787 });
7788 aSourceMapConsumer.sources.forEach(function (sourceFile) {
7789 var sourceRelative = sourceFile;
7790 if (sourceRoot !== null) {
7791 sourceRelative = util.relative(sourceRoot, sourceFile);
7792 }
7793
7794 if (!generator._sources.has(sourceRelative)) {
7795 generator._sources.add(sourceRelative);
7796 }
7797
7798 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
7799 if (content != null) {
7800 generator.setSourceContent(sourceFile, content);
7801 }
7802 });
7803 return generator;
7804 };
7805
7806 /**
7807 * Add a single mapping from original source line and column to the generated
7808 * source's line and column for this source map being created. The mapping
7809 * object should have the following properties:
7810 *
7811 * - generated: An object with the generated line and column positions.
7812 * - original: An object with the original line and column positions.
7813 * - source: The original source file (relative to the sourceRoot).
7814 * - name: An optional original token name for this mapping.
7815 */
7816 SourceMapGenerator.prototype.addMapping =
7817 function SourceMapGenerator_addMapping(aArgs) {
7818 var generated = util.getArg(aArgs, 'generated');
7819 var original = util.getArg(aArgs, 'original', null);
7820 var source = util.getArg(aArgs, 'source', null);
7821 var name = util.getArg(aArgs, 'name', null);
7822
7823 if (!this._skipValidation) {
7824 this._validateMapping(generated, original, source, name);
7825 }
7826
7827 if (source != null) {
7828 source = String(source);
7829 if (!this._sources.has(source)) {
7830 this._sources.add(source);
7831 }
7832 }
7833
7834 if (name != null) {
7835 name = String(name);
7836 if (!this._names.has(name)) {
7837 this._names.add(name);
7838 }
7839 }
7840
7841 this._mappings.add({
7842 generatedLine: generated.line,
7843 generatedColumn: generated.column,
7844 originalLine: original != null && original.line,
7845 originalColumn: original != null && original.column,
7846 source: source,
7847 name: name
7848 });
7849 };
7850
7851 /**
7852 * Set the source content for a source file.
7853 */
7854 SourceMapGenerator.prototype.setSourceContent =
7855 function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
7856 var source = aSourceFile;
7857 if (this._sourceRoot != null) {
7858 source = util.relative(this._sourceRoot, source);
7859 }
7860
7861 if (aSourceContent != null) {
7862 // Add the source content to the _sourcesContents map.
7863 // Create a new _sourcesContents map if the property is null.
7864 if (!this._sourcesContents) {
7865 this._sourcesContents = Object.create(null);
7866 }
7867 this._sourcesContents[util.toSetString(source)] = aSourceContent;
7868 } else if (this._sourcesContents) {
7869 // Remove the source file from the _sourcesContents map.
7870 // If the _sourcesContents map is empty, set the property to null.
7871 delete this._sourcesContents[util.toSetString(source)];
7872 if (Object.keys(this._sourcesContents).length === 0) {
7873 this._sourcesContents = null;
7874 }
7875 }
7876 };
7877
7878 /**
7879 * Applies the mappings of a sub-source-map for a specific source file to the
7880 * source map being generated. Each mapping to the supplied source file is
7881 * rewritten using the supplied source map. Note: The resolution for the
7882 * resulting mappings is the minimium of this map and the supplied map.
7883 *
7884 * @param aSourceMapConsumer The source map to be applied.
7885 * @param aSourceFile Optional. The filename of the source file.
7886 * If omitted, SourceMapConsumer's file property will be used.
7887 * @param aSourceMapPath Optional. The dirname of the path to the source map
7888 * to be applied. If relative, it is relative to the SourceMapConsumer.
7889 * This parameter is needed when the two source maps aren't in the same
7890 * directory, and the source map to be applied contains relative source
7891 * paths. If so, those relative source paths need to be rewritten
7892 * relative to the SourceMapGenerator.
7893 */
7894 SourceMapGenerator.prototype.applySourceMap =
7895 function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
7896 var sourceFile = aSourceFile;
7897 // If aSourceFile is omitted, we will use the file property of the SourceMap
7898 if (aSourceFile == null) {
7899 if (aSourceMapConsumer.file == null) {
7900 throw new Error(
7901 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
7902 'or the source map\'s "file" property. Both were omitted.'
7903 );
7904 }
7905 sourceFile = aSourceMapConsumer.file;
7906 }
7907 var sourceRoot = this._sourceRoot;
7908 // Make "sourceFile" relative if an absolute Url is passed.
7909 if (sourceRoot != null) {
7910 sourceFile = util.relative(sourceRoot, sourceFile);
7911 }
7912 // Applying the SourceMap can add and remove items from the sources and
7913 // the names array.
7914 var newSources = new ArraySet();
7915 var newNames = new ArraySet();
7916
7917 // Find mappings for the "sourceFile"
7918 this._mappings.unsortedForEach(function (mapping) {
7919 if (mapping.source === sourceFile && mapping.originalLine != null) {
7920 // Check if it can be mapped by the source map, then update the mapping.
7921 var original = aSourceMapConsumer.originalPositionFor({
7922 line: mapping.originalLine,
7923 column: mapping.originalColumn
7924 });
7925 if (original.source != null) {
7926 // Copy mapping
7927 mapping.source = original.source;
7928 if (aSourceMapPath != null) {
7929 mapping.source = util.join(aSourceMapPath, mapping.source)
7930 }
7931 if (sourceRoot != null) {
7932 mapping.source = util.relative(sourceRoot, mapping.source);
7933 }
7934 mapping.originalLine = original.line;
7935 mapping.originalColumn = original.column;
7936 if (original.name != null) {
7937 mapping.name = original.name;
7938 }
7939 }
7940 }
7941
7942 var source = mapping.source;
7943 if (source != null && !newSources.has(source)) {
7944 newSources.add(source);
7945 }
7946
7947 var name = mapping.name;
7948 if (name != null && !newNames.has(name)) {
7949 newNames.add(name);
7950 }
7951
7952 }, this);
7953 this._sources = newSources;
7954 this._names = newNames;
7955
7956 // Copy sourcesContents of applied map.
7957 aSourceMapConsumer.sources.forEach(function (sourceFile) {
7958 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
7959 if (content != null) {
7960 if (aSourceMapPath != null) {
7961 sourceFile = util.join(aSourceMapPath, sourceFile);
7962 }
7963 if (sourceRoot != null) {
7964 sourceFile = util.relative(sourceRoot, sourceFile);
7965 }
7966 this.setSourceContent(sourceFile, content);
7967 }
7968 }, this);
7969 };
7970
7971 /**
7972 * A mapping can have one of the three levels of data:
7973 *
7974 * 1. Just the generated position.
7975 * 2. The Generated position, original position, and original source.
7976 * 3. Generated and original position, original source, as well as a name
7977 * token.
7978 *
7979 * To maintain consistency, we validate that any new mapping being added falls
7980 * in to one of these categories.
7981 */
7982 SourceMapGenerator.prototype._validateMapping =
7983 function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
7984 aName) {
7985 // When aOriginal is truthy but has empty values for .line and .column,
7986 // it is most likely a programmer error. In this case we throw a very
7987 // specific error message to try to guide them the right way.
7988 // For example: https://github.com/Polymer/polymer-bundler/pull/519
7989 if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
7990 throw new Error(
7991 'original.line and original.column are not numbers -- you probably meant to omit ' +
7992 'the original mapping entirely and only map the generated position. If so, pass ' +
7993 'null for the original mapping instead of an object with empty or null values.'
7994 );
7995 }
7996
7997 if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
7998 && aGenerated.line > 0 && aGenerated.column >= 0
7999 && !aOriginal && !aSource && !aName) {
8000 // Case 1.
8001 return;
8002 }
8003 else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
8004 && aOriginal && 'line' in aOriginal && 'column' in aOriginal
8005 && aGenerated.line > 0 && aGenerated.column >= 0
8006 && aOriginal.line > 0 && aOriginal.column >= 0
8007 && aSource) {
8008 // Cases 2 and 3.
8009 return;
8010 }
8011 else {
8012 throw new Error('Invalid mapping: ' + JSON.stringify({
8013 generated: aGenerated,
8014 source: aSource,
8015 original: aOriginal,
8016 name: aName
8017 }));
8018 }
8019 };
8020
8021 /**
8022 * Serialize the accumulated mappings in to the stream of base 64 VLQs
8023 * specified by the source map format.
8024 */
8025 SourceMapGenerator.prototype._serializeMappings =
8026 function SourceMapGenerator_serializeMappings() {
8027 var previousGeneratedColumn = 0;
8028 var previousGeneratedLine = 1;
8029 var previousOriginalColumn = 0;
8030 var previousOriginalLine = 0;
8031 var previousName = 0;
8032 var previousSource = 0;
8033 var result = '';
8034 var next;
8035 var mapping;
8036 var nameIdx;
8037 var sourceIdx;
8038
8039 var mappings = this._mappings.toArray();
8040 for (var i = 0, len = mappings.length; i < len; i++) {
8041 mapping = mappings[i];
8042 next = ''
8043
8044 if (mapping.generatedLine !== previousGeneratedLine) {
8045 previousGeneratedColumn = 0;
8046 while (mapping.generatedLine !== previousGeneratedLine) {
8047 next += ';';
8048 previousGeneratedLine++;
8049 }
8050 }
8051 else {
8052 if (i > 0) {
8053 if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
8054 continue;
8055 }
8056 next += ',';
8057 }
8058 }
8059
8060 next += base64VLQ.encode(mapping.generatedColumn
8061 - previousGeneratedColumn);
8062 previousGeneratedColumn = mapping.generatedColumn;
8063
8064 if (mapping.source != null) {
8065 sourceIdx = this._sources.indexOf(mapping.source);
8066 next += base64VLQ.encode(sourceIdx - previousSource);
8067 previousSource = sourceIdx;
8068
8069 // lines are stored 0-based in SourceMap spec version 3
8070 next += base64VLQ.encode(mapping.originalLine - 1
8071 - previousOriginalLine);
8072 previousOriginalLine = mapping.originalLine - 1;
8073
8074 next += base64VLQ.encode(mapping.originalColumn
8075 - previousOriginalColumn);
8076 previousOriginalColumn = mapping.originalColumn;
8077
8078 if (mapping.name != null) {
8079 nameIdx = this._names.indexOf(mapping.name);
8080 next += base64VLQ.encode(nameIdx - previousName);
8081 previousName = nameIdx;
8082 }
8083 }
8084
8085 result += next;
8086 }
8087
8088 return result;
8089 };
8090
8091 SourceMapGenerator.prototype._generateSourcesContent =
8092 function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
8093 return aSources.map(function (source) {
8094 if (!this._sourcesContents) {
8095 return null;
8096 }
8097 if (aSourceRoot != null) {
8098 source = util.relative(aSourceRoot, source);
8099 }
8100 var key = util.toSetString(source);
8101 return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
8102 ? this._sourcesContents[key]
8103 : null;
8104 }, this);
8105 };
8106
8107 /**
8108 * Externalize the source map.
8109 */
8110 SourceMapGenerator.prototype.toJSON =
8111 function SourceMapGenerator_toJSON() {
8112 var map = {
8113 version: this._version,
8114 sources: this._sources.toArray(),
8115 names: this._names.toArray(),
8116 mappings: this._serializeMappings()
8117 };
8118 if (this._file != null) {
8119 map.file = this._file;
8120 }
8121 if (this._sourceRoot != null) {
8122 map.sourceRoot = this._sourceRoot;
8123 }
8124 if (this._sourcesContents) {
8125 map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
8126 }
8127
8128 return map;
8129 };
8130
8131 /**
8132 * Render the source map being generated to a string.
8133 */
8134 SourceMapGenerator.prototype.toString =
8135 function SourceMapGenerator_toString() {
8136 return JSON.stringify(this.toJSON());
8137 };
8138
8139 exports.SourceMapGenerator = SourceMapGenerator;
8140
8141 },{"./array-set":26,"./base64-vlq":27,"./mapping-list":30,"./util":35}],34:[function(require,module,exports){
8142 /* -*- Mode: js; js-indent-level: 2; -*- */
8143 /*
8144 * Copyright 2011 Mozilla Foundation and contributors
8145 * Licensed under the New BSD license. See LICENSE or:
8146 * http://opensource.org/licenses/BSD-3-Clause
8147 */
8148
8149 var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
8150 var util = require('./util');
8151
8152 // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
8153 // operating systems these days (capturing the result).
8154 var REGEX_NEWLINE = /(\r?\n)/;
8155
8156 // Newline character code for charCodeAt() comparisons
8157 var NEWLINE_CODE = 10;
8158
8159 // Private symbol for identifying `SourceNode`s when multiple versions of
8160 // the source-map library are loaded. This MUST NOT CHANGE across
8161 // versions!
8162 var isSourceNode = "$$$isSourceNode$$$";
8163
8164 /**
8165 * SourceNodes provide a way to abstract over interpolating/concatenating
8166 * snippets of generated JavaScript source code while maintaining the line and
8167 * column information associated with the original source code.
8168 *
8169 * @param aLine The original line number.
8170 * @param aColumn The original column number.
8171 * @param aSource The original source's filename.
8172 * @param aChunks Optional. An array of strings which are snippets of
8173 * generated JS, or other SourceNodes.
8174 * @param aName The original identifier.
8175 */
8176 function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
8177 this.children = [];
8178 this.sourceContents = {};
8179 this.line = aLine == null ? null : aLine;
8180 this.column = aColumn == null ? null : aColumn;
8181 this.source = aSource == null ? null : aSource;
8182 this.name = aName == null ? null : aName;
8183 this[isSourceNode] = true;
8184 if (aChunks != null) this.add(aChunks);
8185 }
8186
8187 /**
8188 * Creates a SourceNode from generated code and a SourceMapConsumer.
8189 *
8190 * @param aGeneratedCode The generated code
8191 * @param aSourceMapConsumer The SourceMap for the generated code
8192 * @param aRelativePath Optional. The path that relative sources in the
8193 * SourceMapConsumer should be relative to.
8194 */
8195 SourceNode.fromStringWithSourceMap =
8196 function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
8197 // The SourceNode we want to fill with the generated code
8198 // and the SourceMap
8199 var node = new SourceNode();
8200
8201 // All even indices of this array are one line of the generated code,
8202 // while all odd indices are the newlines between two adjacent lines
8203 // (since `REGEX_NEWLINE` captures its match).
8204 // Processed fragments are accessed by calling `shiftNextLine`.
8205 var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
8206 var remainingLinesIndex = 0;
8207 var shiftNextLine = function() {
8208 var lineContents = getNextLine();
8209 // The last line of a file might not have a newline.
8210 var newLine = getNextLine() || "";
8211 return lineContents + newLine;
8212
8213 function getNextLine() {
8214 return remainingLinesIndex < remainingLines.length ?
8215 remainingLines[remainingLinesIndex++] : undefined;
8216 }
8217 };
8218
8219 // We need to remember the position of "remainingLines"
8220 var lastGeneratedLine = 1, lastGeneratedColumn = 0;
8221
8222 // The generate SourceNodes we need a code range.
8223 // To extract it current and last mapping is used.
8224 // Here we store the last mapping.
8225 var lastMapping = null;
8226
8227 aSourceMapConsumer.eachMapping(function (mapping) {
8228 if (lastMapping !== null) {
8229 // We add the code from "lastMapping" to "mapping":
8230 // First check if there is a new line in between.
8231 if (lastGeneratedLine < mapping.generatedLine) {
8232 // Associate first line with "lastMapping"
8233 addMappingWithCode(lastMapping, shiftNextLine());
8234 lastGeneratedLine++;
8235 lastGeneratedColumn = 0;
8236 // The remaining code is added without mapping
8237 } else {
8238 // There is no new line in between.
8239 // Associate the code between "lastGeneratedColumn" and
8240 // "mapping.generatedColumn" with "lastMapping"
8241 var nextLine = remainingLines[remainingLinesIndex] || '';
8242 var code = nextLine.substr(0, mapping.generatedColumn -
8243 lastGeneratedColumn);
8244 remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
8245 lastGeneratedColumn);
8246 lastGeneratedColumn = mapping.generatedColumn;
8247 addMappingWithCode(lastMapping, code);
8248 // No more remaining code, continue
8249 lastMapping = mapping;
8250 return;
8251 }
8252 }
8253 // We add the generated code until the first mapping
8254 // to the SourceNode without any mapping.
8255 // Each line is added as separate string.
8256 while (lastGeneratedLine < mapping.generatedLine) {
8257 node.add(shiftNextLine());
8258 lastGeneratedLine++;
8259 }
8260 if (lastGeneratedColumn < mapping.generatedColumn) {
8261 var nextLine = remainingLines[remainingLinesIndex] || '';
8262 node.add(nextLine.substr(0, mapping.generatedColumn));
8263 remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
8264 lastGeneratedColumn = mapping.generatedColumn;
8265 }
8266 lastMapping = mapping;
8267 }, this);
8268 // We have processed all mappings.
8269 if (remainingLinesIndex < remainingLines.length) {
8270 if (lastMapping) {
8271 // Associate the remaining code in the current line with "lastMapping"
8272 addMappingWithCode(lastMapping, shiftNextLine());
8273 }
8274 // and add the remaining lines without any mapping
8275 node.add(remainingLines.splice(remainingLinesIndex).join(""));
8276 }
8277
8278 // Copy sourcesContent into SourceNode
8279 aSourceMapConsumer.sources.forEach(function (sourceFile) {
8280 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
8281 if (content != null) {
8282 if (aRelativePath != null) {
8283 sourceFile = util.join(aRelativePath, sourceFile);
8284 }
8285 node.setSourceContent(sourceFile, content);
8286 }
8287 });
8288
8289 return node;
8290
8291 function addMappingWithCode(mapping, code) {
8292 if (mapping === null || mapping.source === undefined) {
8293 node.add(code);
8294 } else {
8295 var source = aRelativePath
8296 ? util.join(aRelativePath, mapping.source)
8297 : mapping.source;
8298 node.add(new SourceNode(mapping.originalLine,
8299 mapping.originalColumn,
8300 source,
8301 code,
8302 mapping.name));
8303 }
8304 }
8305 };
8306
8307 /**
8308 * Add a chunk of generated JS to this source node.
8309 *
8310 * @param aChunk A string snippet of generated JS code, another instance of
8311 * SourceNode, or an array where each member is one of those things.
8312 */
8313 SourceNode.prototype.add = function SourceNode_add(aChunk) {
8314 if (Array.isArray(aChunk)) {
8315 aChunk.forEach(function (chunk) {
8316 this.add(chunk);
8317 }, this);
8318 }
8319 else if (aChunk[isSourceNode] || typeof aChunk === "string") {
8320 if (aChunk) {
8321 this.children.push(aChunk);
8322 }
8323 }
8324 else {
8325 throw new TypeError(
8326 "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
8327 );
8328 }
8329 return this;
8330 };
8331
8332 /**
8333 * Add a chunk of generated JS to the beginning of this source node.
8334 *
8335 * @param aChunk A string snippet of generated JS code, another instance of
8336 * SourceNode, or an array where each member is one of those things.
8337 */
8338 SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
8339 if (Array.isArray(aChunk)) {
8340 for (var i = aChunk.length-1; i >= 0; i--) {
8341 this.prepend(aChunk[i]);
8342 }
8343 }
8344 else if (aChunk[isSourceNode] || typeof aChunk === "string") {
8345 this.children.unshift(aChunk);
8346 }
8347 else {
8348 throw new TypeError(
8349 "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
8350 );
8351 }
8352 return this;
8353 };
8354
8355 /**
8356 * Walk over the tree of JS snippets in this node and its children. The
8357 * walking function is called once for each snippet of JS and is passed that
8358 * snippet and the its original associated source's line/column location.
8359 *
8360 * @param aFn The traversal function.
8361 */
8362 SourceNode.prototype.walk = function SourceNode_walk(aFn) {
8363 var chunk;
8364 for (var i = 0, len = this.children.length; i < len; i++) {
8365 chunk = this.children[i];
8366 if (chunk[isSourceNode]) {
8367 chunk.walk(aFn);
8368 }
8369 else {
8370 if (chunk !== '') {
8371 aFn(chunk, { source: this.source,
8372 line: this.line,
8373 column: this.column,
8374 name: this.name });
8375 }
8376 }
8377 }
8378 };
8379
8380 /**
8381 * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
8382 * each of `this.children`.
8383 *
8384 * @param aSep The separator.
8385 */
8386 SourceNode.prototype.join = function SourceNode_join(aSep) {
8387 var newChildren;
8388 var i;
8389 var len = this.children.length;
8390 if (len > 0) {
8391 newChildren = [];
8392 for (i = 0; i < len-1; i++) {
8393 newChildren.push(this.children[i]);
8394 newChildren.push(aSep);
8395 }
8396 newChildren.push(this.children[i]);
8397 this.children = newChildren;
8398 }
8399 return this;
8400 };
8401
8402 /**
8403 * Call String.prototype.replace on the very right-most source snippet. Useful
8404 * for trimming whitespace from the end of a source node, etc.
8405 *
8406 * @param aPattern The pattern to replace.
8407 * @param aReplacement The thing to replace the pattern with.
8408 */
8409 SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
8410 var lastChild = this.children[this.children.length - 1];
8411 if (lastChild[isSourceNode]) {
8412 lastChild.replaceRight(aPattern, aReplacement);
8413 }
8414 else if (typeof lastChild === 'string') {
8415 this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
8416 }
8417 else {
8418 this.children.push(''.replace(aPattern, aReplacement));
8419 }
8420 return this;
8421 };
8422
8423 /**
8424 * Set the source content for a source file. This will be added to the SourceMapGenerator
8425 * in the sourcesContent field.
8426 *
8427 * @param aSourceFile The filename of the source file
8428 * @param aSourceContent The content of the source file
8429 */
8430 SourceNode.prototype.setSourceContent =
8431 function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
8432 this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
8433 };
8434
8435 /**
8436 * Walk over the tree of SourceNodes. The walking function is called for each
8437 * source file content and is passed the filename and source content.
8438 *
8439 * @param aFn The traversal function.
8440 */
8441 SourceNode.prototype.walkSourceContents =
8442 function SourceNode_walkSourceContents(aFn) {
8443 for (var i = 0, len = this.children.length; i < len; i++) {
8444 if (this.children[i][isSourceNode]) {
8445 this.children[i].walkSourceContents(aFn);
8446 }
8447 }
8448
8449 var sources = Object.keys(this.sourceContents);
8450 for (var i = 0, len = sources.length; i < len; i++) {
8451 aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
8452 }
8453 };
8454
8455 /**
8456 * Return the string representation of this source node. Walks over the tree
8457 * and concatenates all the various snippets together to one string.
8458 */
8459 SourceNode.prototype.toString = function SourceNode_toString() {
8460 var str = "";
8461 this.walk(function (chunk) {
8462 str += chunk;
8463 });
8464 return str;
8465 };
8466
8467 /**
8468 * Returns the string representation of this source node along with a source
8469 * map.
8470 */
8471 SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
8472 var generated = {
8473 code: "",
8474 line: 1,
8475 column: 0
8476 };
8477 var map = new SourceMapGenerator(aArgs);
8478 var sourceMappingActive = false;
8479 var lastOriginalSource = null;
8480 var lastOriginalLine = null;
8481 var lastOriginalColumn = null;
8482 var lastOriginalName = null;
8483 this.walk(function (chunk, original) {
8484 generated.code += chunk;
8485 if (original.source !== null
8486 && original.line !== null
8487 && original.column !== null) {
8488 if(lastOriginalSource !== original.source
8489 || lastOriginalLine !== original.line
8490 || lastOriginalColumn !== original.column
8491 || lastOriginalName !== original.name) {
8492 map.addMapping({
8493 source: original.source,
8494 original: {
8495 line: original.line,
8496 column: original.column
8497 },
8498 generated: {
8499 line: generated.line,
8500 column: generated.column
8501 },
8502 name: original.name
8503 });
8504 }
8505 lastOriginalSource = original.source;
8506 lastOriginalLine = original.line;
8507 lastOriginalColumn = original.column;
8508 lastOriginalName = original.name;
8509 sourceMappingActive = true;
8510 } else if (sourceMappingActive) {
8511 map.addMapping({
8512 generated: {
8513 line: generated.line,
8514 column: generated.column
8515 }
8516 });
8517 lastOriginalSource = null;
8518 sourceMappingActive = false;
8519 }
8520 for (var idx = 0, length = chunk.length; idx < length; idx++) {
8521 if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
8522 generated.line++;
8523 generated.column = 0;
8524 // Mappings end at eol
8525 if (idx + 1 === length) {
8526 lastOriginalSource = null;
8527 sourceMappingActive = false;
8528 } else if (sourceMappingActive) {
8529 map.addMapping({
8530 source: original.source,
8531 original: {
8532 line: original.line,
8533 column: original.column
8534 },
8535 generated: {
8536 line: generated.line,
8537 column: generated.column
8538 },
8539 name: original.name
8540 });
8541 }
8542 } else {
8543 generated.column++;
8544 }
8545 }
8546 });
8547 this.walkSourceContents(function (sourceFile, sourceContent) {
8548 map.setSourceContent(sourceFile, sourceContent);
8549 });
8550
8551 return { code: generated.code, map: map };
8552 };
8553
8554 exports.SourceNode = SourceNode;
8555
8556 },{"./source-map-generator":33,"./util":35}],35:[function(require,module,exports){
8557 /* -*- Mode: js; js-indent-level: 2; -*- */
8558 /*
8559 * Copyright 2011 Mozilla Foundation and contributors
8560 * Licensed under the New BSD license. See LICENSE or:
8561 * http://opensource.org/licenses/BSD-3-Clause
8562 */
8563
8564 /**
8565 * This is a helper function for getting values from parameter/options
8566 * objects.
8567 *
8568 * @param args The object we are extracting values from
8569 * @param name The name of the property we are getting.
8570 * @param defaultValue An optional value to return if the property is missing
8571 * from the object. If this is not specified and the property is missing, an
8572 * error will be thrown.
8573 */
8574 function getArg(aArgs, aName, aDefaultValue) {
8575 if (aName in aArgs) {
8576 return aArgs[aName];
8577 } else if (arguments.length === 3) {
8578 return aDefaultValue;
8579 } else {
8580 throw new Error('"' + aName + '" is a required argument.');
8581 }
8582 }
8583 exports.getArg = getArg;
8584
8585 var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
8586 var dataUrlRegexp = /^data:.+\,.+$/;
8587
8588 function urlParse(aUrl) {
8589 var match = aUrl.match(urlRegexp);
8590 if (!match) {
8591 return null;
8592 }
8593 return {
8594 scheme: match[1],
8595 auth: match[2],
8596 host: match[3],
8597 port: match[4],
8598 path: match[5]
8599 };
8600 }
8601 exports.urlParse = urlParse;
8602
8603 function urlGenerate(aParsedUrl) {
8604 var url = '';
8605 if (aParsedUrl.scheme) {
8606 url += aParsedUrl.scheme + ':';
8607 }
8608 url += '//';
8609 if (aParsedUrl.auth) {
8610 url += aParsedUrl.auth + '@';
8611 }
8612 if (aParsedUrl.host) {
8613 url += aParsedUrl.host;
8614 }
8615 if (aParsedUrl.port) {
8616 url += ":" + aParsedUrl.port
8617 }
8618 if (aParsedUrl.path) {
8619 url += aParsedUrl.path;
8620 }
8621 return url;
8622 }
8623 exports.urlGenerate = urlGenerate;
8624
8625 /**
8626 * Normalizes a path, or the path portion of a URL:
8627 *
8628 * - Replaces consecutive slashes with one slash.
8629 * - Removes unnecessary '.' parts.
8630 * - Removes unnecessary '<dir>/..' parts.
8631 *
8632 * Based on code in the Node.js 'path' core module.
8633 *
8634 * @param aPath The path or url to normalize.
8635 */
8636 function normalize(aPath) {
8637 var path = aPath;
8638 var url = urlParse(aPath);
8639 if (url) {
8640 if (!url.path) {
8641 return aPath;
8642 }
8643 path = url.path;
8644 }
8645 var isAbsolute = exports.isAbsolute(path);
8646
8647 var parts = path.split(/\/+/);
8648 for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
8649 part = parts[i];
8650 if (part === '.') {
8651 parts.splice(i, 1);
8652 } else if (part === '..') {
8653 up++;
8654 } else if (up > 0) {
8655 if (part === '') {
8656 // The first part is blank if the path is absolute. Trying to go
8657 // above the root is a no-op. Therefore we can remove all '..' parts
8658 // directly after the root.
8659 parts.splice(i + 1, up);
8660 up = 0;
8661 } else {
8662 parts.splice(i, 2);
8663 up--;
8664 }
8665 }
8666 }
8667 path = parts.join('/');
8668
8669 if (path === '') {
8670 path = isAbsolute ? '/' : '.';
8671 }
8672
8673 if (url) {
8674 url.path = path;
8675 return urlGenerate(url);
8676 }
8677 return path;
8678 }
8679 exports.normalize = normalize;
8680
8681 /**
8682 * Joins two paths/URLs.
8683 *
8684 * @param aRoot The root path or URL.
8685 * @param aPath The path or URL to be joined with the root.
8686 *
8687 * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
8688 * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
8689 * first.
8690 * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
8691 * is updated with the result and aRoot is returned. Otherwise the result
8692 * is returned.
8693 * - If aPath is absolute, the result is aPath.
8694 * - Otherwise the two paths are joined with a slash.
8695 * - Joining for example 'http://' and 'www.example.com' is also supported.
8696 */
8697 function join(aRoot, aPath) {
8698 if (aRoot === "") {
8699 aRoot = ".";
8700 }
8701 if (aPath === "") {
8702 aPath = ".";
8703 }
8704 var aPathUrl = urlParse(aPath);
8705 var aRootUrl = urlParse(aRoot);
8706 if (aRootUrl) {
8707 aRoot = aRootUrl.path || '/';
8708 }
8709
8710 // `join(foo, '//www.example.org')`
8711 if (aPathUrl && !aPathUrl.scheme) {
8712 if (aRootUrl) {
8713 aPathUrl.scheme = aRootUrl.scheme;
8714 }
8715 return urlGenerate(aPathUrl);
8716 }
8717
8718 if (aPathUrl || aPath.match(dataUrlRegexp)) {
8719 return aPath;
8720 }
8721
8722 // `join('http://', 'www.example.com')`
8723 if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
8724 aRootUrl.host = aPath;
8725 return urlGenerate(aRootUrl);
8726 }
8727
8728 var joined = aPath.charAt(0) === '/'
8729 ? aPath
8730 : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
8731
8732 if (aRootUrl) {
8733 aRootUrl.path = joined;
8734 return urlGenerate(aRootUrl);
8735 }
8736 return joined;
8737 }
8738 exports.join = join;
8739
8740 exports.isAbsolute = function (aPath) {
8741 return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
8742 };
8743
8744 /**
8745 * Make a path relative to a URL or another path.
8746 *
8747 * @param aRoot The root path or URL.
8748 * @param aPath The path or URL to be made relative to aRoot.
8749 */
8750 function relative(aRoot, aPath) {
8751 if (aRoot === "") {
8752 aRoot = ".";
8753 }
8754
8755 aRoot = aRoot.replace(/\/$/, '');
8756
8757 // It is possible for the path to be above the root. In this case, simply
8758 // checking whether the root is a prefix of the path won't work. Instead, we
8759 // need to remove components from the root one by one, until either we find
8760 // a prefix that fits, or we run out of components to remove.
8761 var level = 0;
8762 while (aPath.indexOf(aRoot + '/') !== 0) {
8763 var index = aRoot.lastIndexOf("/");
8764 if (index < 0) {
8765 return aPath;
8766 }
8767
8768 // If the only part of the root that is left is the scheme (i.e. http://,
8769 // file:///, etc.), one or more slashes (/), or simply nothing at all, we
8770 // have exhausted all components, so the path is not relative to the root.
8771 aRoot = aRoot.slice(0, index);
8772 if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
8773 return aPath;
8774 }
8775
8776 ++level;
8777 }
8778
8779 // Make sure we add a "../" for each component we removed from the root.
8780 return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
8781 }
8782 exports.relative = relative;
8783
8784 var supportsNullProto = (function () {
8785 var obj = Object.create(null);
8786 return !('__proto__' in obj);
8787 }());
8788
8789 function identity (s) {
8790 return s;
8791 }
8792
8793 /**
8794 * Because behavior goes wacky when you set `__proto__` on objects, we
8795 * have to prefix all the strings in our set with an arbitrary character.
8796 *
8797 * See https://github.com/mozilla/source-map/pull/31 and
8798 * https://github.com/mozilla/source-map/issues/30
8799 *
8800 * @param String aStr
8801 */
8802 function toSetString(aStr) {
8803 if (isProtoString(aStr)) {
8804 return '$' + aStr;
8805 }
8806
8807 return aStr;
8808 }
8809 exports.toSetString = supportsNullProto ? identity : toSetString;
8810
8811 function fromSetString(aStr) {
8812 if (isProtoString(aStr)) {
8813 return aStr.slice(1);
8814 }
8815
8816 return aStr;
8817 }
8818 exports.fromSetString = supportsNullProto ? identity : fromSetString;
8819
8820 function isProtoString(s) {
8821 if (!s) {
8822 return false;
8823 }
8824
8825 var length = s.length;
8826
8827 if (length < 9 /* "__proto__".length */) {
8828 return false;
8829 }
8830
8831 if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
8832 s.charCodeAt(length - 2) !== 95 /* '_' */ ||
8833 s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
8834 s.charCodeAt(length - 4) !== 116 /* 't' */ ||
8835 s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
8836 s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
8837 s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
8838 s.charCodeAt(length - 8) !== 95 /* '_' */ ||
8839 s.charCodeAt(length - 9) !== 95 /* '_' */) {
8840 return false;
8841 }
8842
8843 for (var i = length - 10; i >= 0; i--) {
8844 if (s.charCodeAt(i) !== 36 /* '$' */) {
8845 return false;
8846 }
8847 }
8848
8849 return true;
8850 }
8851
8852 /**
8853 * Comparator between two mappings where the original positions are compared.
8854 *
8855 * Optionally pass in `true` as `onlyCompareGenerated` to consider two
8856 * mappings with the same original source/line/column, but different generated
8857 * line and column the same. Useful when searching for a mapping with a
8858 * stubbed out mapping.
8859 */
8860 function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
8861 var cmp = strcmp(mappingA.source, mappingB.source);
8862 if (cmp !== 0) {
8863 return cmp;
8864 }
8865
8866 cmp = mappingA.originalLine - mappingB.originalLine;
8867 if (cmp !== 0) {
8868 return cmp;
8869 }
8870
8871 cmp = mappingA.originalColumn - mappingB.originalColumn;
8872 if (cmp !== 0 || onlyCompareOriginal) {
8873 return cmp;
8874 }
8875
8876 cmp = mappingA.generatedColumn - mappingB.generatedColumn;
8877 if (cmp !== 0) {
8878 return cmp;
8879 }
8880
8881 cmp = mappingA.generatedLine - mappingB.generatedLine;
8882 if (cmp !== 0) {
8883 return cmp;
8884 }
8885
8886 return strcmp(mappingA.name, mappingB.name);
8887 }
8888 exports.compareByOriginalPositions = compareByOriginalPositions;
8889
8890 /**
8891 * Comparator between two mappings with deflated source and name indices where
8892 * the generated positions are compared.
8893 *
8894 * Optionally pass in `true` as `onlyCompareGenerated` to consider two
8895 * mappings with the same generated line and column, but different
8896 * source/name/original line and column the same. Useful when searching for a
8897 * mapping with a stubbed out mapping.
8898 */
8899 function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
8900 var cmp = mappingA.generatedLine - mappingB.generatedLine;
8901 if (cmp !== 0) {
8902 return cmp;
8903 }
8904
8905 cmp = mappingA.generatedColumn - mappingB.generatedColumn;
8906 if (cmp !== 0 || onlyCompareGenerated) {
8907 return cmp;
8908 }
8909
8910 cmp = strcmp(mappingA.source, mappingB.source);
8911 if (cmp !== 0) {
8912 return cmp;
8913 }
8914
8915 cmp = mappingA.originalLine - mappingB.originalLine;
8916 if (cmp !== 0) {
8917 return cmp;
8918 }
8919
8920 cmp = mappingA.originalColumn - mappingB.originalColumn;
8921 if (cmp !== 0) {
8922 return cmp;
8923 }
8924
8925 return strcmp(mappingA.name, mappingB.name);
8926 }
8927 exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
8928
8929 function strcmp(aStr1, aStr2) {
8930 if (aStr1 === aStr2) {
8931 return 0;
8932 }
8933
8934 if (aStr1 === null) {
8935 return 1; // aStr2 !== null
8936 }
8937
8938 if (aStr2 === null) {
8939 return -1; // aStr1 !== null
8940 }
8941
8942 if (aStr1 > aStr2) {
8943 return 1;
8944 }
8945
8946 return -1;
8947 }
8948
8949 /**
8950 * Comparator between two mappings with inflated source and name strings where
8951 * the generated positions are compared.
8952 */
8953 function compareByGeneratedPositionsInflated(mappingA, mappingB) {
8954 var cmp = mappingA.generatedLine - mappingB.generatedLine;
8955 if (cmp !== 0) {
8956 return cmp;
8957 }
8958
8959 cmp = mappingA.generatedColumn - mappingB.generatedColumn;
8960 if (cmp !== 0) {
8961 return cmp;
8962 }
8963
8964 cmp = strcmp(mappingA.source, mappingB.source);
8965 if (cmp !== 0) {
8966 return cmp;
8967 }
8968
8969 cmp = mappingA.originalLine - mappingB.originalLine;
8970 if (cmp !== 0) {
8971 return cmp;
8972 }
8973
8974 cmp = mappingA.originalColumn - mappingB.originalColumn;
8975 if (cmp !== 0) {
8976 return cmp;
8977 }
8978
8979 return strcmp(mappingA.name, mappingB.name);
8980 }
8981 exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
8982
8983 /**
8984 * Strip any JSON XSSI avoidance prefix from the string (as documented
8985 * in the source maps specification), and then parse the string as
8986 * JSON.
8987 */
8988 function parseSourceMapInput(str) {
8989 return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
8990 }
8991 exports.parseSourceMapInput = parseSourceMapInput;
8992
8993 /**
8994 * Compute the URL of a source given the the source root, the source's
8995 * URL, and the source map's URL.
8996 */
8997 function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
8998 sourceURL = sourceURL || '';
8999
9000 if (sourceRoot) {
9001 // This follows what Chrome does.
9002 if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
9003 sourceRoot += '/';
9004 }
9005 // The spec says:
9006 // Line 4: An optional source root, useful for relocating source
9007 // files on a server or removing repeated values in the
9008 // “sources” entry. This value is prepended to the individual
9009 // entries in the “source” field.
9010 sourceURL = sourceRoot + sourceURL;
9011 }
9012
9013 // Historically, SourceMapConsumer did not take the sourceMapURL as
9014 // a parameter. This mode is still somewhat supported, which is why
9015 // this code block is conditional. However, it's preferable to pass
9016 // the source map URL to SourceMapConsumer, so that this function
9017 // can implement the source URL resolution algorithm as outlined in
9018 // the spec. This block is basically the equivalent of:
9019 // new URL(sourceURL, sourceMapURL).toString()
9020 // ... except it avoids using URL, which wasn't available in the
9021 // older releases of node still supported by this library.
9022 //
9023 // The spec says:
9024 // If the sources are not absolute URLs after prepending of the
9025 // “sourceRoot”, the sources are resolved relative to the
9026 // SourceMap (like resolving script src in a html document).
9027 if (sourceMapURL) {
9028 var parsed = urlParse(sourceMapURL);
9029 if (!parsed) {
9030 throw new Error("sourceMapURL could not be parsed");
9031 }
9032 if (parsed.path) {
9033 // Strip the last path component, but keep the "/".
9034 var index = parsed.path.lastIndexOf('/');
9035 if (index >= 0) {
9036 parsed.path = parsed.path.substring(0, index + 1);
9037 }
9038 }
9039 sourceURL = join(urlGenerate(parsed), sourceURL);
9040 }
9041
9042 return normalize(sourceURL);
9043 }
9044 exports.computeSourceURL = computeSourceURL;
9045
9046 },{}],36:[function(require,module,exports){
9047 /*
9048 * Copyright 2009-2011 Mozilla Foundation and contributors
9049 * Licensed under the New BSD license. See LICENSE.txt or:
9050 * http://opensource.org/licenses/BSD-3-Clause
9051 */
9052 exports.SourceMapGenerator = require('./lib/source-map-generator').SourceMapGenerator;
9053 exports.SourceMapConsumer = require('./lib/source-map-consumer').SourceMapConsumer;
9054 exports.SourceNode = require('./lib/source-node').SourceNode;
9055
9056 },{"./lib/source-map-consumer":32,"./lib/source-map-generator":33,"./lib/source-node":34}]},{},[14]);
9057