1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-06-04 08:34:55 +02:00
php-web-maker/app/vendor.js
Kushagra Gour 6e907dbc70 build
2018-06-19 11:00:29 +05:30

55834 lines
2.3 MiB
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ var parentJsonpFunction = window["webpackJsonp"];
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, resolves = [], result;
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(installedChunks[chunkId]) {
/******/ resolves.push(installedChunks[chunkId][0]);
/******/ }
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/ for(moduleId in moreModules) {
/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
/******/ modules[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules);
/******/ while(resolves.length) {
/******/ resolves.shift()();
/******/ }
/******/ if(executeModules) {
/******/ for(i=0; i < executeModules.length; i++) {
/******/ result = __webpack_require__(__webpack_require__.s = executeModules[i]);
/******/ }
/******/ }
/******/ return result;
/******/ };
/******/
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // objects to store loaded and loading chunks
/******/ var installedChunks = {
/******/ 2: 0
/******/ };
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/";
/******/
/******/ // on error function for async loading
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };
/******/ })
/************************************************************************/
/******/ ({
/***/ "/QFk":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
// CONCATENATED MODULE: ../node_modules/@emmetio/config/dist/config.es.js
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var defaultSyntaxes = {
markup: 'html',
stylesheet: 'css'
};
var knownSyntaxes = {
markup: ['html', 'xml', 'xsl', 'jsx', 'js', 'pug', 'slim', 'haml'],
stylesheet: ['css', 'sass', 'scss', 'less', 'sss', 'stylus']
};
/**
* Config resolver: returns compiled config that can be used in
* `@emmetio/expand-abbreviation` module for expanding abbreviations
* @param {EmmetConfig} config Config object
* @param {EmmetConfigParams} [params] Additional params like `.syntax` and `.project` for
* config resolving
* @returns {Object}
*/
function compileConfig(config, params) {
params = createParams(config, params || {});
var resolved = resolveConfig(config, params);
// Copy extra fields from original config
var knownFields = ['globals', 'syntax', 'project'];
for (var p in config) {
if (knownFields.indexOf(p) === -1) {
resolved[p] = config[p];
}
}
return resolved;
}
/**
* Resolves config for markup syntax
* @param {EmmetConfig} config
* @param {EmmetConfigParams} params
* @return {Object}
*/
function resolveConfig(config, ref) {
var type = ref.type;
var syntax = ref.syntax;
var project = ref.project;
return {
syntax: syntax,
type: type,
project: project,
format: mergeConfig(config, 'format', type, syntax, project),
profile: mergeConfig(config, 'profile', type, syntax, project),
options: mergeConfig(config, 'options', type, syntax, project),
variables: mergeConfig(config, 'variables', type, syntax, project),
snippets: getConfig(config, 'snippets', type, syntax, project).filter(Boolean)
};
}
/**
* @param {EmmetConfig} config
* @param {EmmetConfigParams} params
* @returns {EmmetConfigParams}
*/
function createParams(config, params) {
var type = params.type;
var syntax = params.syntax;
if (!type && !syntax) {
type = 'markup';
syntax = defaultSyntaxes[type];
} else if (!type && syntax) {
if (knownSyntaxes.markup.indexOf(syntax) !== -1) {
type = 'markup';
} else if (knownSyntaxes.stylesheet.indexOf(syntax) !== -1) {
type = 'stylesheet';
} else {
type = get(config, ['syntax', syntax, 'type']) || get(config, ['project', params.project, 'syntax', syntax, 'type']);
}
} else if (!syntax) {
syntax = defaultSyntaxes[type];
}
return _extends({}, params, { type: type, syntax: syntax });
}
function mergeConfig(config, key, type, syntax, project) {
return getConfig(config, key, type, syntax, project).reduce(function (out, obj) {
return _extends({}, out, obj);
}, {});
}
function getConfig(config, key, type, syntax, project) {
return [get(config, ['globals', type, key]), get(config, ['project', project, 'globals', type, key]), get(config, ['syntax', syntax, key]), get(config, ['project', project, 'syntax', syntax, key])].filter(Boolean);
}
/**
* Safe dot-property getter for `obj`: returns value of `obj` by given `key`,
* separated by `.`, but doesnt throw error if any of the property key exists
* @param {Object} obj
* @param {String[]} key
* @param {*} [defaultValue]
* @return {*}
*/
function get(obj, key, defaultValue) {
var result = obj;
for (var i = 0; i < key.length; i++) {
if (result == null) {
break;
}
result = result[key[i]];
}
return result != null ? result : defaultValue;
}
/* harmony default export */ var config_es = (compileConfig);
//# sourceMappingURL=config.es.js.map
// CONCATENATED MODULE: ../node_modules/@emmetio/stream-reader/dist/stream-reader.es.js
/**
* A streaming, character code-based string reader
*/
let StreamReader = class StreamReader {
constructor(string, start, end) {
if (end == null && typeof string === 'string') {
end = string.length;
}
this.string = string;
this.pos = this.start = start || 0;
this.end = end;
}
/**
* Returns true only if the stream is at the end of the file.
* @returns {Boolean}
*/
eof() {
return this.pos >= this.end;
}
/**
* Creates a new stream instance which is limited to given `start` and `end`
* range. E.g. its `eof()` method will look at `end` property, not actual
* stream end
* @param {Point} start
* @param {Point} end
* @return {StreamReader}
*/
limit(start, end) {
return new this.constructor(this.string, start, end);
}
/**
* Returns the next character code in the stream without advancing it.
* Will return NaN at the end of the file.
* @returns {Number}
*/
peek() {
return this.string.charCodeAt(this.pos);
}
/**
* Returns the next character in the stream and advances it.
* Also returns <code>undefined</code> when no more characters are available.
* @returns {Number}
*/
next() {
if (this.pos < this.string.length) {
return this.string.charCodeAt(this.pos++);
}
}
/**
* `match` can be a character code or a function that takes a character code
* and returns a boolean. If the next character in the stream 'matches'
* the given argument, it is consumed and returned.
* Otherwise, `false` is returned.
* @param {Number|Function} match
* @returns {Boolean}
*/
eat(match) {
const ch = this.peek();
const ok = typeof match === 'function' ? match(ch) : ch === match;
if (ok) {
this.next();
}
return ok;
}
/**
* Repeatedly calls <code>eat</code> with the given argument, until it
* fails. Returns <code>true</code> if any characters were eaten.
* @param {Object} match
* @returns {Boolean}
*/
eatWhile(match) {
const start = this.pos;
while (!this.eof() && this.eat(match)) {}
return this.pos !== start;
}
/**
* Backs up the stream n characters. Backing it up further than the
* start of the current token will cause things to break, so be careful.
* @param {Number} n
*/
backUp(n) {
this.pos -= n || 1;
}
/**
* Get the string between the start of the current token and the
* current stream position.
* @returns {String}
*/
current() {
return this.substring(this.start, this.pos);
}
/**
* Returns substring for given range
* @param {Number} start
* @param {Number} [end]
* @return {String}
*/
substring(start, end) {
return this.string.slice(start, end);
}
/**
* Creates error object with current stream state
* @param {String} message
* @return {Error}
*/
error(message) {
const err = new Error(`${message} at char ${this.pos + 1}`);
err.originalMessage = message;
err.pos = this.pos;
err.string = this.string;
return err;
}
};
/* harmony default export */ var stream_reader_es = (StreamReader);
// CONCATENATED MODULE: ../node_modules/@emmetio/stream-reader-utils/dist/stream-reader-utils.es.js
var stream_reader_utils_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/**
* Methods for consuming quoted values
*/
const SINGLE_QUOTE = 39; // '
const DOUBLE_QUOTE = 34; // "
const defaultOptions = {
escape: 92, // \ character
throws: false
};
/**
* Consumes 'single' or "double"-quoted string from given string, if possible
* @param {StreamReader} stream
* @param {Number} options.escape A character code of quote-escape symbol
* @param {Boolean} options.throws Throw error if quotes string cant be properly consumed
* @return {Boolean} `true` if quoted string was consumed. The contents
* of quoted string will be availabe as `stream.current()`
*/
var eatQuoted = function (stream, options) {
options = options ? stream_reader_utils_es__extends({}, defaultOptions, options) : defaultOptions;
const start = stream.pos;
const quote = stream.peek();
if (stream.eat(isQuote)) {
while (!stream.eof()) {
switch (stream.next()) {
case quote:
stream.start = start;
return true;
case options.escape:
stream.next();
break;
}
}
// If were here then stream wasnt properly consumed.
// Revert stream and decide what to do
stream.pos = start;
if (options.throws) {
throw stream.error('Unable to consume quoted string');
}
}
return false;
};
function isQuote(code) {
return code === SINGLE_QUOTE || code === DOUBLE_QUOTE;
}
/**
* Check if given code is a number
* @param {Number} code
* @return {Boolean}
*/
function isNumber(code) {
return code > 47 && code < 58;
}
/**
* Check if given character code is alpha code (letter through A to Z)
* @param {Number} code
* @param {Number} [from]
* @param {Number} [to]
* @return {Boolean}
*/
function isAlpha(code, from, to) {
from = from || 65; // A
to = to || 90; // Z
code &= ~32; // quick hack to convert any char code to uppercase char code
return code >= from && code <= to;
}
/**
* Check if given character code is alpha-numeric (letter through A to Z or number)
* @param {Number} code
* @return {Boolean}
*/
function isAlphaNumeric(code) {
return isNumber(code) || isAlpha(code);
}
function isWhiteSpace(code) {
return code === 32 /* space */
|| code === 9 /* tab */
|| code === 160; /* non-breaking space */
}
/**
* Check if given character code is a space
* @param {Number} code
* @return {Boolean}
*/
function isSpace(code) {
return isWhiteSpace(code) || code === 10 /* LF */
|| code === 13; /* CR */
}
const defaultOptions$1 = {
escape: 92, // \ character
throws: false
};
/**
* Eats paired characters substring, for example `(foo)` or `[bar]`
* @param {StreamReader} stream
* @param {Number} open Character code of pair openinig
* @param {Number} close Character code of pair closing
* @param {Object} [options]
* @return {Boolean} Returns `true` if chacarter pair was successfully
* consumed, its content will be available as `stream.current()`
*/
function eatPair(stream, open, close, options) {
options = options ? stream_reader_utils_es__extends({}, defaultOptions$1, options) : defaultOptions$1;
const start = stream.pos;
if (stream.eat(open)) {
let stack = 1,
ch;
while (!stream.eof()) {
if (eatQuoted(stream, options)) {
continue;
}
ch = stream.next();
if (ch === open) {
stack++;
} else if (ch === close) {
stack--;
if (!stack) {
stream.start = start;
return true;
}
} else if (ch === options.escape) {
stream.next();
}
}
// If were here then paired character cant be consumed
stream.pos = start;
if (options.throws) {
throw stream.error(`Unable to find matching pair for ${String.fromCharCode(open)}`);
}
}
return false;
}
// CONCATENATED MODULE: ../node_modules/@emmetio/field-parser/dist/field-parser.es.js
const DOLLAR = 36; // $
const COLON = 58; // :
const ESCAPE = 92; // \
const OPEN_BRACE = 123; // {
const CLOSE_BRACE = 125; // }
/**
* Finds fields in given string and returns object with field-less string
* and array of fields found
* @param {String} string
* @return {Object}
*/
function parse(string) {
const stream = new stream_reader_es(string);
const fields = [];
let cleanString = '',
offset = 0,
pos = 0;
let code, field;
while (!stream.eof()) {
code = stream.peek();
pos = stream.pos;
if (code === ESCAPE) {
stream.next();
stream.next();
} else if (field = consumeField(stream, cleanString.length + pos - offset)) {
fields.push(field);
cleanString += stream.string.slice(offset, pos) + field.placeholder;
offset = stream.pos;
} else {
stream.next();
}
}
return new FieldString(cleanString + stream.string.slice(offset), fields);
}
/**
* Marks given `string` with `fields`: wraps each field range with
* `${index:placeholder}` (by default) or any other token produced by `token`
* function, if provided
* @param {String} string String to mark
* @param {Array} fields Array of field descriptor. A field descriptor is a
* `{index, location, length}` array. It is important that fields in array
* must be ordered by their location in string: some fields my refer the same
* location so they must appear in order that user expects.
* @param {Function} [token] Function that generates field token. This function
* received two arguments: `index` and `placeholder` and should return string
* @return {String} String with marked fields
*/
function mark(string, fields, token) {
token = token || createToken;
// order fields by their location and appearence
// NB field ranges should not overlap! (not supported yet)
const ordered = fields.map((field, order) => ({ order, field, end: field.location + field.length })).sort((a, b) => a.end - b.end || a.order - b.order);
// mark ranges in string
let offset = 0;
const result = ordered.map(item => {
const placeholder = string.substr(item.field.location, item.field.length);
const prefix = string.slice(offset, item.field.location);
offset = item.end;
return prefix + token(item.field.index, placeholder);
});
return result.join('') + string.slice(offset);
}
/**
* Creates field token for string
* @param {Number} index Field index
* @param {String} placeholder Field placeholder, could be empty string
* @return {String}
*/
function createToken(index, placeholder) {
return placeholder ? `\${${index}:${placeholder}}` : `\${${index}}`;
}
/**
* Consumes field from current stream position: it can be an `$index` or
* or `${index}` or `${index:placeholder}`
* @param {StreamReader} stream
* @param {Number} location Field location in *clean* string
* @return {Field} Object with `index` and `placeholder` properties if
* field was successfully consumed, `null` otherwise
*/
function consumeField(stream, location) {
const start = stream.pos;
if (stream.eat(DOLLAR)) {
// Possible start of field
let index = consumeIndex(stream);
let placeholder = '';
// consumed $index placeholder
if (index != null) {
return new Field(index, placeholder, location);
}
if (stream.eat(OPEN_BRACE)) {
index = consumeIndex(stream);
if (index != null) {
if (stream.eat(COLON)) {
placeholder = consumePlaceholder(stream);
}
if (stream.eat(CLOSE_BRACE)) {
return new Field(index, placeholder, location);
}
}
}
}
// If we reached here then theres no valid field here, revert
// back to starting position
stream.pos = start;
}
/**
* Consumes a placeholder: value right after `:` in field. Could be empty
* @param {StreamReader} stream
* @return {String}
*/
function consumePlaceholder(stream) {
let code;
const stack = [];
stream.start = stream.pos;
while (!stream.eof()) {
code = stream.peek();
if (code === OPEN_BRACE) {
stack.push(stream.pos);
} else if (code === CLOSE_BRACE) {
if (!stack.length) {
break;
}
stack.pop();
}
stream.next();
}
if (stack.length) {
throw stream.error('Unable to find matching "}" for curly brace at ' + stack.pop());
}
return stream.current();
}
/**
* Consumes integer from current stream position
* @param {StreamReader} stream
* @return {Number}
*/
function consumeIndex(stream) {
stream.start = stream.pos;
if (stream.eatWhile(isNumber)) {
return Number(stream.current());
}
}
let Field = class Field {
constructor(index, placeholder, location) {
this.index = index;
this.placeholder = placeholder;
this.location = location;
this.length = this.placeholder.length;
}
};
let FieldString = class FieldString {
/**
* @param {String} string
* @param {Field[]} fields
*/
constructor(string, fields) {
this.string = string;
this.fields = fields;
}
mark(token) {
return mark(this.string, this.fields, token);
}
toString() {
return this.string;
}
};
/* harmony default export */ var field_parser_es = (parse);
//# sourceMappingURL=field-parser.es.js.map
// CONCATENATED MODULE: ../node_modules/@emmetio/extract-abbreviation/dist/extract-abbreviation.es.js
var extract_abbreviation_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/**
* Minimalistic backwards stream reader
*/
let extract_abbreviation_es_StreamReader = class StreamReader {
constructor(string, start) {
this.string = string;
this.start = start || 0;
this.pos = this.string.length;
}
sol() {
return this.pos === this.start;
}
peek(offset) {
return this.string.charCodeAt(this.pos - 1 + (offset || 0));
}
prev() {
if (!this.sol()) {
return this.string.charCodeAt(--this.pos);
}
}
eat(match) {
if (this.sol()) {
return false;
}
const ok = typeof match === 'function' ? match(this.peek()) : match === this.peek();
if (ok) {
this.pos--;
}
return ok;
}
eatWhile(match) {
const start = this.pos;
while (this.eat(match)) {}
return this.pos < start;
}
};
/**
* Quotes-related utilities
*/
const extract_abbreviation_es_SINGLE_QUOTE = 39; // '
const extract_abbreviation_es_DOUBLE_QUOTE = 34; // "
const extract_abbreviation_es_ESCAPE = 92; // \
/**
* Check if given character code is a quote
* @param {Number} c
* @return {Boolean}
*/
function extract_abbreviation_es_isQuote(c) {
return c === extract_abbreviation_es_SINGLE_QUOTE || c === extract_abbreviation_es_DOUBLE_QUOTE;
}
/**
* Consumes quoted value, if possible
* @param {StreamReader} stream
* @return {Boolean} Returns `true` is value was consumed
*/
function extract_abbreviation_es_eatQuoted(stream) {
const start = stream.pos;
const quote = stream.prev();
if (extract_abbreviation_es_isQuote(quote)) {
while (!stream.sol()) {
if (stream.prev() === quote && stream.peek() !== extract_abbreviation_es_ESCAPE) {
return true;
}
}
}
stream.pos = start;
return false;
}
const TAB = 9;
const SPACE = 32;
const DASH = 45; // -
const SLASH = 47; // /
const extract_abbreviation_es_COLON = 58; // :
const EQUALS = 61; // =
const ANGLE_LEFT = 60; // <
const ANGLE_RIGHT = 62; // >
/**
* Check if given readers current position points at the end of HTML tag
* @param {StreamReader} stream
* @return {Boolean}
*/
var isAtHTMLTag = function (stream) {
const start = stream.pos;
if (!stream.eat(ANGLE_RIGHT)) {
return false;
}
let ok = false;
stream.eat(SLASH); // possibly self-closed element
while (!stream.sol()) {
stream.eatWhile(extract_abbreviation_es_isWhiteSpace);
if (eatIdent(stream)) {
// ate identifier: could be a tag name, boolean attribute or unquoted
// attribute value
if (stream.eat(SLASH)) {
// either closing tag or invalid tag
ok = stream.eat(ANGLE_LEFT);
break;
} else if (stream.eat(ANGLE_LEFT)) {
// opening tag
ok = true;
break;
} else if (stream.eat(extract_abbreviation_es_isWhiteSpace)) {
// boolean attribute
continue;
} else if (stream.eat(EQUALS)) {
// simple unquoted value or invalid attribute
if (eatIdent(stream)) {
continue;
}
break;
} else if (eatAttributeWithUnquotedValue(stream)) {
// identifier was a part of unquoted value
ok = true;
break;
}
// invalid tag
break;
}
if (eatAttribute(stream)) {
continue;
}
break;
}
stream.pos = start;
return ok;
};
/**
* Eats HTML attribute from given string.
* @param {StreamReader} state
* @return {Boolean} `true` if attribute was consumed.
*/
function eatAttribute(stream) {
return eatAttributeWithQuotedValue(stream) || eatAttributeWithUnquotedValue(stream);
}
/**
* @param {StreamReader} stream
* @return {Boolean}
*/
function eatAttributeWithQuotedValue(stream) {
const start = stream.pos;
if (extract_abbreviation_es_eatQuoted(stream) && stream.eat(EQUALS) && eatIdent(stream)) {
return true;
}
stream.pos = start;
return false;
}
/**
* @param {StreamReader} stream
* @return {Boolean}
*/
function eatAttributeWithUnquotedValue(stream) {
const start = stream.pos;
if (stream.eatWhile(isUnquotedValue) && stream.eat(EQUALS) && eatIdent(stream)) {
return true;
}
stream.pos = start;
return false;
}
/**
* Eats HTML identifier from stream
* @param {StreamReader} stream
* @return {Boolean}
*/
function eatIdent(stream) {
return stream.eatWhile(isIdent);
}
/**
* Check if given character code belongs to HTML identifier
* @param {Number} c
* @return {Boolean}
*/
function isIdent(c) {
return c === extract_abbreviation_es_COLON || c === DASH || extract_abbreviation_es_isAlpha(c) || extract_abbreviation_es_isNumber(c);
}
/**
* Check if given character code is alpha code (letter though A to Z)
* @param {Number} c
* @return {Boolean}
*/
function extract_abbreviation_es_isAlpha(c) {
c &= ~32; // quick hack to convert any char code to uppercase char code
return c >= 65 && c <= 90; // A-Z
}
/**
* Check if given code is a number
* @param {Number} c
* @return {Boolean}
*/
function extract_abbreviation_es_isNumber(c) {
return c > 47 && c < 58;
}
/**
* Check if given code is a whitespace
* @param {Number} c
* @return {Boolean}
*/
function extract_abbreviation_es_isWhiteSpace(c) {
return c === SPACE || c === TAB;
}
/**
* Check if given code may belong to unquoted attribute value
* @param {Number} c
* @return {Boolean}
*/
function isUnquotedValue(c) {
return c && c !== EQUALS && !extract_abbreviation_es_isWhiteSpace(c) && !extract_abbreviation_es_isQuote(c);
}
const extract_abbreviation_es_code = ch => ch.charCodeAt(0);
const SQUARE_BRACE_L = extract_abbreviation_es_code('[');
const SQUARE_BRACE_R = extract_abbreviation_es_code(']');
const ROUND_BRACE_L = extract_abbreviation_es_code('(');
const ROUND_BRACE_R = extract_abbreviation_es_code(')');
const CURLY_BRACE_L = extract_abbreviation_es_code('{');
const CURLY_BRACE_R = extract_abbreviation_es_code('}');
const specialChars = new Set('#.*:$-_!@%^+>/'.split('').map(extract_abbreviation_es_code));
const bracePairs = new Map().set(SQUARE_BRACE_L, SQUARE_BRACE_R).set(ROUND_BRACE_L, ROUND_BRACE_R).set(CURLY_BRACE_L, CURLY_BRACE_R);
const extract_abbreviation_es_defaultOptions = {
syntax: 'markup',
lookAhead: null,
prefix: ''
};
/**
* Extracts Emmet abbreviation from given string.
* The goal of this module is to extract abbreviation from current editors line,
* e.g. like this: `<span>.foo[title=bar|]</span>` -> `.foo[title=bar]`, where
* `|` is a current caret position.
* @param {String} line A text line where abbreviation should be expanded
* @param {Number} [pos] Caret position in line. If not given, uses end-of-line
* @param {Object} [options]
* @param {Boolean} [options.lookAhead] Allow parser to look ahead of `pos` index for
* searching of missing abbreviation parts. Most editors automatically inserts
* closing braces for `[`, `{` and `(`, which will most likely be right after
* current caret position. So in order to properly expand abbreviation, user
* must explicitly move caret right after auto-inserted braces. With this option
* enabled, parser will search for closing braces right after `pos`. Default is `true`
* @param {String} [options.syntax] Name of context syntax of expanded abbreviation.
* Either 'markup' (default) or 'stylesheet'. In 'stylesheet' syntax, braces `[]`
* and `{}` are not supported thus not extracted.
* @param {String} [options.prefix] A string that should precede abbreviation in
* order to make it successfully extracted. If given, the abbreviation will be
* extracted from the nearest `prefix` occurrence.
* @return {Object} Object with `abbreviation` and its `location` in given line
* if abbreviation can be extracted, `null` otherwise
*/
function extractAbbreviation(line, pos, options) {
// make sure `pos` is within line range
pos = Math.min(line.length, Math.max(0, pos == null ? line.length : pos));
if (typeof options === 'boolean') {
options = extract_abbreviation_es__extends({}, extract_abbreviation_es_defaultOptions, { lookAhead: options });
} else {
options = extract_abbreviation_es__extends({}, extract_abbreviation_es_defaultOptions, options);
}
if (options.lookAhead == null || options.lookAhead === true) {
pos = offsetPastAutoClosed(line, pos, options);
}
let c;
const start = getStartOffset(line, pos, options.prefix);
if (start === -1) {
return null;
}
const stream = new extract_abbreviation_es_StreamReader(line, start);
stream.pos = pos;
const stack = [];
while (!stream.sol()) {
c = stream.peek();
if (isCloseBrace(c, options.syntax)) {
stack.push(c);
} else if (isOpenBrace(c, options.syntax)) {
if (stack.pop() !== bracePairs.get(c)) {
// unexpected brace
break;
}
} else if (has(stack, SQUARE_BRACE_R) || has(stack, CURLY_BRACE_R)) {
// respect all characters inside attribute sets or text nodes
stream.pos--;
continue;
} else if (isAtHTMLTag(stream) || !isAbbreviation(c)) {
break;
}
stream.pos--;
}
if (!stack.length && stream.pos !== pos) {
// found something, remove some invalid symbols from the
// beginning and return abbreviation
const abbreviation = line.slice(stream.pos, pos).replace(/^[*+>^]+/, '');
return {
abbreviation,
location: pos - abbreviation.length,
start: options.prefix ? start - options.prefix.length : pos - abbreviation.length,
end: pos
};
}
}
/**
* Returns new `line` index which is right after characters beyound `pos` that
* editor will likely automatically close, e.g. }, ], and quotes
* @param {String} line
* @param {Number} pos
* @return {Number}
*/
function offsetPastAutoClosed(line, pos, options) {
// closing quote is allowed only as a next character
if (extract_abbreviation_es_isQuote(line.charCodeAt(pos))) {
pos++;
}
// offset pointer until non-autoclosed character is found
while (isCloseBrace(line.charCodeAt(pos), options.syntax)) {
pos++;
}
return pos;
}
/**
* Returns start offset (left limit) in `line` where we should stop looking for
* abbreviation: its nearest to `pos` location of `prefix` token
* @param {String} line
* @param {Number} pos
* @param {String} prefix
* @return {Number}
*/
function getStartOffset(line, pos, prefix) {
if (!prefix) {
return 0;
}
const stream = new extract_abbreviation_es_StreamReader(line);
const compiledPrefix = String(prefix).split('').map(extract_abbreviation_es_code);
stream.pos = pos;
let result;
while (!stream.sol()) {
if (consumePair(stream, SQUARE_BRACE_R, SQUARE_BRACE_L) || consumePair(stream, CURLY_BRACE_R, CURLY_BRACE_L)) {
continue;
}
result = stream.pos;
if (consumeArray(stream, compiledPrefix)) {
return result;
}
stream.pos--;
}
return -1;
}
/**
* Consumes full character pair, if possible
* @param {StreamReader} stream
* @param {Number} close
* @param {Number} open
* @return {Boolean}
*/
function consumePair(stream, close, open) {
const start = stream.pos;
if (stream.eat(close)) {
while (!stream.sol()) {
if (stream.eat(open)) {
return true;
}
stream.pos--;
}
}
stream.pos = start;
return false;
}
/**
* Consumes all character codes from given array, right-to-left, if possible
* @param {StreamReader} stream
* @param {Number[]} arr
*/
function consumeArray(stream, arr) {
const start = stream.pos;
let consumed = false;
for (let i = arr.length - 1; i >= 0 && !stream.sol(); i--) {
if (!stream.eat(arr[i])) {
break;
}
consumed = i === 0;
}
if (!consumed) {
stream.pos = start;
}
return consumed;
}
function has(arr, value) {
return arr.indexOf(value) !== -1;
}
function isAbbreviation(c) {
return c > 64 && c < 91 || // uppercase letter
c > 96 && c < 123 // lowercase letter
|| c > 47 && c < 58 // number
|| specialChars.has(c); // special character
}
function isOpenBrace(c, syntax) {
return c === ROUND_BRACE_L || syntax === 'markup' && (c === SQUARE_BRACE_L || c === CURLY_BRACE_L);
}
function isCloseBrace(c, syntax) {
return c === ROUND_BRACE_R || syntax === 'markup' && (c === SQUARE_BRACE_R || c === CURLY_BRACE_R);
}
/* harmony default export */ var extract_abbreviation_es = (extractAbbreviation);
// CONCATENATED MODULE: ../node_modules/@emmetio/node/dist/node.es.js
var node_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/**
* Attribute descriptor of parsed abbreviation node
* @param {String} name Attribute name
* @param {String} value Attribute value
* @param {Object} options Additional custom attribute options
* @param {Boolean} options.boolean Attribute is boolean (e.g. name equals value)
* @param {Boolean} options.implied Attribute is implied (e.g. must be outputted
* only if contains non-null value)
*/
let Attribute = class Attribute {
constructor(name, value, options) {
this.name = name;
this.value = value != null ? value : null;
this.options = options || {};
}
/**
* Create a copy of current attribute
* @return {Attribute}
*/
clone() {
return new Attribute(this.name, this.value, node_es__extends({}, this.options));
}
/**
* A string representation of current node
*/
valueOf() {
return `${this.name}="${this.value}"`;
}
};
/**
* A parsed abbreviation AST node. Nodes build up an abbreviation AST tree
*/
let Node = class Node {
/**
* Creates a new node
* @param {String} [name] Node name
* @param {Array} [attributes] Array of attributes to add
*/
constructor(name, attributes) {
// own properties
this.name = name || null;
this.value = null;
this.repeat = null;
this.selfClosing = false;
this.children = [];
/** @type {Node} Pointer to parent node */
this.parent = null;
/** @type {Node} Pointer to next sibling */
this.next = null;
/** @type {Node} Pointer to previous sibling */
this.previous = null;
this._attributes = [];
if (Array.isArray(attributes)) {
attributes.forEach(attr => this.setAttribute(attr));
}
}
/**
* Array of current node attributes
* @return {Attribute[]} Array of attributes
*/
get attributes() {
return this._attributes;
}
/**
* A shorthand to retreive node attributes as map
* @return {Object}
*/
get attributesMap() {
return this.attributes.reduce((out, attr) => {
out[attr.name] = attr.options.boolean ? attr.name : attr.value;
return out;
}, {});
}
/**
* Check if current node is a grouping one, e.g. has no actual representation
* and is used for grouping subsequent nodes only
* @return {Boolean}
*/
get isGroup() {
return !this.name && !this.value && !this._attributes.length;
}
/**
* Check if given node is a text-only node, e.g. contains only value
* @return {Boolean}
*/
get isTextOnly() {
return !this.name && !!this.value && !this._attributes.length;
}
/**
* Returns first child node
* @return {Node}
*/
get firstChild() {
return this.children[0];
}
/**
* Returns last child of current node
* @return {Node}
*/
get lastChild() {
return this.children[this.children.length - 1];
}
/**
* Return index of current node in its parent child list
* @return {Number} Returns -1 if current node is a root one
*/
get childIndex() {
return this.parent ? this.parent.children.indexOf(this) : -1;
}
/**
* Returns next sibling of current node
* @return {Node}
*/
get nextSibling() {
return this.next;
}
/**
* Returns previous sibling of current node
* @return {Node}
*/
get previousSibling() {
return this.previous;
}
/**
* Returns array of unique class names in current node
* @return {String[]}
*/
get classList() {
const attr = this.getAttribute('class');
return attr && attr.value ? attr.value.split(/\s+/g).filter(uniqueClass) : [];
}
/**
* Convenient alias to create a new node instance
* @param {String} [name] Node name
* @param {Object} [attributes] Attributes hash
* @return {Node}
*/
create(name, attributes) {
return new Node(name, attributes);
}
/**
* Sets given attribute for current node
* @param {String|Object|Attribute} name Attribute name or attribute object
* @param {String} [value] Attribute value
*/
setAttribute(name, value) {
const attr = createAttribute(name, value);
const curAttr = this.getAttribute(name);
if (curAttr) {
this.replaceAttribute(curAttr, attr);
} else {
this._attributes.push(attr);
}
}
/**
* Check if attribute with given name exists in node
* @param {String} name
* @return {Boolean}
*/
hasAttribute(name) {
return !!this.getAttribute(name);
}
/**
* Returns attribute object by given name
* @param {String} name
* @return {Attribute}
*/
getAttribute(name) {
if (typeof name === 'object') {
name = name.name;
}
for (var i = 0; i < this._attributes.length; i++) {
const attr = this._attributes[i];
if (attr.name === name) {
return attr;
}
}
}
/**
* Replaces attribute with new instance
* @param {String|Attribute} curAttribute Current attribute name or instance
* to replace
* @param {String|Object|Attribute} newName New attribute name or attribute object
* @param {String} [newValue] New attribute value
*/
replaceAttribute(curAttribute, newName, newValue) {
if (typeof curAttribute === 'string') {
curAttribute = this.getAttribute(curAttribute);
}
const ix = this._attributes.indexOf(curAttribute);
if (ix !== -1) {
this._attributes.splice(ix, 1, createAttribute(newName, newValue));
}
}
/**
* Removes attribute with given name
* @param {String|Attribute} attr Atrtibute name or instance
*/
removeAttribute(attr) {
if (typeof attr === 'string') {
attr = this.getAttribute(attr);
}
const ix = this._attributes.indexOf(attr);
if (ix !== -1) {
this._attributes.splice(ix, 1);
}
}
/**
* Removes all attributes from current node
*/
clearAttributes() {
this._attributes.length = 0;
}
/**
* Adds given class name to class attribute
* @param {String} token Class name token
*/
addClass(token) {
token = normalize(token);
if (!this.hasAttribute('class')) {
this.setAttribute('class', token);
} else if (token && !this.hasClass(token)) {
this.setAttribute('class', this.classList.concat(token).join(' '));
}
}
/**
* Check if current node contains given class name
* @param {String} token Class name token
* @return {Boolean}
*/
hasClass(token) {
return this.classList.indexOf(normalize(token)) !== -1;
}
/**
* Removes given class name from class attribute
* @param {String} token Class name token
*/
removeClass(token) {
token = normalize(token);
if (this.hasClass(token)) {
this.setAttribute('class', this.classList.filter(name => name !== token).join(' '));
}
}
/**
* Appends child to current node
* @param {Node} node
*/
appendChild(node) {
this.insertAt(node, this.children.length);
}
/**
* Inserts given `newNode` before `refNode` child node
* @param {Node} newNode
* @param {Node} refNode
*/
insertBefore(newNode, refNode) {
this.insertAt(newNode, this.children.indexOf(refNode));
}
/**
* Insert given `node` at `pos` position of child list
* @param {Node} node
* @param {Number} pos
*/
insertAt(node, pos) {
if (pos < 0 || pos > this.children.length) {
throw new Error('Unable to insert node: position is out of child list range');
}
const prev = this.children[pos - 1];
const next = this.children[pos];
node.remove();
node.parent = this;
this.children.splice(pos, 0, node);
if (prev) {
node.previous = prev;
prev.next = node;
}
if (next) {
node.next = next;
next.previous = node;
}
}
/**
* Removes given child from current node
* @param {Node} node
*/
removeChild(node) {
const ix = this.children.indexOf(node);
if (ix !== -1) {
this.children.splice(ix, 1);
if (node.previous) {
node.previous.next = node.next;
}
if (node.next) {
node.next.previous = node.previous;
}
node.parent = node.next = node.previous = null;
}
}
/**
* Removes current node from its parent
*/
remove() {
if (this.parent) {
this.parent.removeChild(this);
}
}
/**
* Creates a detached copy of current node
* @param {Boolean} deep Clone node contents as well
* @return {Node}
*/
clone(deep) {
const clone = new Node(this.name);
clone.value = this.value;
clone.selfClosing = this.selfClosing;
if (this.repeat) {
clone.repeat = node_es__extends({}, this.repeat);
}
this._attributes.forEach(attr => clone.setAttribute(attr.clone()));
if (deep) {
this.children.forEach(child => clone.appendChild(child.clone(true)));
}
return clone;
}
/**
* Walks on each descendant node and invokes given `fn` function on it.
* The function receives two arguments: the node itself and its depth level
* from current node. If function returns `false`, it stops walking
* @param {Function} fn
*/
walk(fn, _level) {
_level = _level || 0;
let ctx = this.firstChild;
while (ctx) {
// in case if context node will be detached during `fn` call
const next = ctx.next;
if (fn(ctx, _level) === false || ctx.walk(fn, _level + 1) === false) {
return false;
}
ctx = next;
}
}
/**
* A helper method for transformation chaining: runs given `fn` function on
* current node and returns the same node
*/
use(fn) {
const args = [this];
for (var i = 1; i < arguments.length; i++) {
args.push(arguments[i]);
}
fn.apply(null, args);
return this;
}
toString() {
const attrs = this.attributes.map(attr => {
attr = this.getAttribute(attr.name);
const opt = attr.options;
let out = `${opt && opt.implied ? '!' : ''}${attr.name || ''}`;
if (opt && opt.boolean) {
out += '.';
} else if (attr.value != null) {
out += `="${attr.value}"`;
}
return out;
});
let out = `${this.name || ''}`;
if (attrs.length) {
out += `[${attrs.join(' ')}]`;
}
if (this.value != null) {
out += `{${this.value}}`;
}
if (this.selfClosing) {
out += '/';
}
if (this.repeat) {
out += `*${this.repeat.count ? this.repeat.count : ''}`;
if (this.repeat.value != null) {
out += `@${this.repeat.value}`;
}
}
return out;
}
};
/**
* Attribute factory
* @param {String|Attribute|Object} name Attribute name or attribute descriptor
* @param {*} value Attribute value
* @return {Attribute}
*/
function createAttribute(name, value) {
if (name instanceof Attribute) {
return name;
}
if (typeof name === 'string') {
return new Attribute(name, value);
}
if (name && typeof name === 'object') {
return new Attribute(name.name, name.value, name.options);
}
}
/**
* @param {String} str
* @return {String}
*/
function normalize(str) {
return String(str).trim();
}
function uniqueClass(item, i, arr) {
return item && arr.indexOf(item) === i;
}
/* harmony default export */ var node_es = (Node);
// CONCATENATED MODULE: ../node_modules/@emmetio/abbreviation/dist/abbreviation.es.js
const ASTERISK = 42; // *
/**
* Consumes node repeat token from current stream position and returns its
* parsed value
* @param {StringReader} stream
* @return {Object}
*/
function consumeRepeat(stream) {
if (stream.eat(ASTERISK)) {
stream.start = stream.pos;
// XXX think about extending repeat syntax with through numbering
return { count: stream.eatWhile(isNumber) ? +stream.current() : null };
}
}
const opt = { throws: true };
/**
* Consumes quoted literal from current stream position and returns its inner,
* unquoted, value
* @param {StringReader} stream
* @return {String} Returns `null` if unable to consume quoted value from current
* position
*/
function consumeQuoted(stream) {
if (eatQuoted(stream, opt)) {
return stream.current().slice(1, -1);
}
}
const TEXT_START = 123; // {
const TEXT_END = 125; // }
const abbreviation_es_ESCAPE = 92; // \ character
/**
* Consumes text node `{...}` from stream
* @param {StreamReader} stream
* @return {String} Returns consumed text value (without surrounding braces) or
* `null` if theres no text at starting position
*/
function consumeText(stream) {
// NB using own implementation instead of `eatPair()` from @emmetio/stream-reader-utils
// to disable quoted value consuming
const start = stream.pos;
if (stream.eat(TEXT_START)) {
let stack = 1,
ch;
let result = '';
let offset = stream.pos;
while (!stream.eof()) {
ch = stream.next();
if (ch === TEXT_START) {
stack++;
} else if (ch === TEXT_END) {
stack--;
if (!stack) {
stream.start = start;
return result + stream.substring(offset, stream.pos - 1);
}
} else if (ch === abbreviation_es_ESCAPE) {
ch = stream.next();
if (ch === TEXT_START || ch === TEXT_END) {
result += stream.substring(offset, stream.pos - 2) + String.fromCharCode(ch);
offset = stream.pos;
}
}
}
// If were here then paired character cant be consumed
stream.pos = start;
throw stream.error(`Unable to find closing ${String.fromCharCode(TEXT_END)} for text start`);
}
return null;
}
const EXCL = 33; // .
const DOT = 46; // .
const abbreviation_es_EQUALS = 61; // =
const ATTR_OPEN = 91; // [
const ATTR_CLOSE = 93; // ]
const reAttributeName = /^\!?[\w\-:\$@]+\.?$/;
/**
* Consumes attributes defined in square braces from given stream.
* Example:
* [attr col=3 title="Quoted string" selected. support={react}]
* @param {StringReader} stream
* @returns {Array} Array of consumed attributes
*/
function consumeAttributes(stream) {
if (!stream.eat(ATTR_OPEN)) {
return null;
}
const result = [];
let token, attr;
while (!stream.eof()) {
stream.eatWhile(isWhiteSpace);
if (stream.eat(ATTR_CLOSE)) {
return result; // End of attribute set
} else if ((token = consumeQuoted(stream)) != null) {
// Consumed quoted value: anonymous attribute
result.push({
name: null,
value: token
});
} else if (eatUnquoted(stream)) {
// Consumed next word: could be either attribute name or unquoted default value
token = stream.current();
if (!reAttributeName.test(token)) {
// anonymous attribute
result.push({ name: null, value: token });
} else {
// Looks like a regular attribute
attr = parseAttributeName(token);
result.push(attr);
if (stream.eat(abbreviation_es_EQUALS)) {
// Explicitly defined value. Could be a word, a quoted string
// or React-like expression
if ((token = consumeQuoted(stream)) != null) {
attr.value = token;
} else if ((token = consumeText(stream)) != null) {
attr.value = token;
attr.options = {
before: '{',
after: '}'
};
} else if (eatUnquoted(stream)) {
attr.value = stream.current();
}
}
}
} else {
throw stream.error('Expected attribute name');
}
}
throw stream.error('Expected closing "]" brace');
}
function parseAttributeName(name) {
const options = {};
// If a first character in attribute name is `!` — its an implied
// default attribute
if (name.charCodeAt(0) === EXCL) {
name = name.slice(1);
options.implied = true;
}
// Check for last character: if its a `.`, user wants boolean attribute
if (name.charCodeAt(name.length - 1) === DOT) {
name = name.slice(0, name.length - 1);
options.boolean = true;
}
const attr = { name };
if (Object.keys(options).length) {
attr.options = options;
}
return attr;
}
/**
* Eats token that can be an unquoted value from given stream
* @param {StreamReader} stream
* @return {Boolean}
*/
function eatUnquoted(stream) {
const start = stream.pos;
if (stream.eatWhile(isUnquoted)) {
stream.start = start;
return true;
}
}
function isUnquoted(code) {
return !isSpace(code) && !isQuote(code) && code !== ATTR_OPEN && code !== ATTR_CLOSE && code !== abbreviation_es_EQUALS;
}
const HASH = 35; // #
const DOT$1 = 46; // .
const abbreviation_es_SLASH = 47; // /
/**
* Consumes a single element node from current abbreviation stream
* @param {StringReader} stream
* @return {Node}
*/
function consumeElement(stream) {
// consume element name, if provided
const start = stream.pos;
const node = new node_es(eatName(stream));
let next;
while (!stream.eof()) {
if (stream.eat(DOT$1)) {
node.addClass(eatName(stream));
} else if (stream.eat(HASH)) {
node.setAttribute('id', eatName(stream));
} else if (stream.eat(abbreviation_es_SLASH)) {
// A self-closing indicator must be at the end of non-grouping node
if (node.isGroup) {
stream.backUp(1);
throw stream.error('Unexpected self-closing indicator');
}
node.selfClosing = true;
if (next = consumeRepeat(stream)) {
node.repeat = next;
}
break;
} else if (next = consumeAttributes(stream)) {
for (let i = 0, il = next.length; i < il; i++) {
node.setAttribute(next[i]);
}
} else if ((next = consumeText(stream)) !== null) {
node.value = next;
} else if (next = consumeRepeat(stream)) {
node.repeat = next;
} else {
break;
}
}
if (start === stream.pos) {
throw stream.error(`Unable to consume abbreviation node, unexpected ${stream.peek()}`);
}
return node;
}
function eatName(stream) {
stream.start = stream.pos;
stream.eatWhile(isName);
return stream.current();
}
function isName(code) {
return isAlphaNumeric(code) || code === 45 /* - */
|| code === 58 /* : */
|| code === 36 /* $ */
|| code === 64 /* @ */
|| code === 33 /* ! */
|| code === 95 /* _ */
|| code === 37 /* % */;
}
const GROUP_START = 40; // (
const GROUP_END = 41; // )
const OP_SIBLING = 43; // +
const OP_CHILD = 62; // >
const OP_CLIMB = 94; // ^
/**
* Parses given string into a node tree
* @param {String} str Abbreviation to parse
* @return {Node}
*/
function abbreviation_es_parse(str) {
const stream = new stream_reader_es(str.trim());
const root = new node_es();
let ctx = root,
groupStack = [],
ch;
while (!stream.eof()) {
ch = stream.peek();
if (ch === GROUP_START) {
// start of group
// The grouping node should be detached to properly handle
// out-of-bounds `^` operator. Node will be attached right on group end
const node = new node_es();
groupStack.push([node, ctx, stream.pos]);
ctx = node;
stream.next();
continue;
} else if (ch === GROUP_END) {
// end of group
const lastGroup = groupStack.pop();
if (!lastGroup) {
throw stream.error('Unexpected ")" group end');
}
const node = lastGroup[0];
ctx = lastGroup[1];
stream.next();
// a group can have a repeater
if (node.repeat = consumeRepeat(stream)) {
ctx.appendChild(node);
} else {
// move all children of group into parent node
while (node.firstChild) {
ctx.appendChild(node.firstChild);
}
}
// for convenience, groups can be joined with optional `+` operator
stream.eat(OP_SIBLING);
continue;
}
const node = consumeElement(stream);
ctx.appendChild(node);
if (stream.eof()) {
break;
}
switch (stream.peek()) {
case OP_SIBLING:
stream.next();
continue;
case OP_CHILD:
stream.next();
ctx = node;
continue;
case OP_CLIMB:
// its perfectly valid to have multiple `^` operators
while (stream.eat(OP_CLIMB)) {
ctx = ctx.parent || ctx;
}
continue;
}
}
if (groupStack.length) {
stream.pos = groupStack.pop()[2];
throw stream.error('Expected group close');
}
return root;
}
/**
* Parses given abbreviation and un-rolls it into a full tree: recursively
* replaces repeated elements with actual nodes
* @param {String} abbr
* @return {Node}
*/
function index(abbr) {
const tree = abbreviation_es_parse(abbr);
tree.walk(unroll);
return tree;
}
function unroll(node) {
if (!node.repeat || !node.repeat.count) {
return;
}
const parent = node.parent;
let ix = parent.children.indexOf(node);
for (let i = 0; i < node.repeat.count; i++) {
const clone = node.clone(true);
clone.repeat.value = i + 1;
clone.walk(unroll);
if (clone.isGroup) {
while (clone.children.length > 0) {
clone.firstChild.repeat = clone.repeat;
parent.insertAt(clone.firstChild, ix++);
}
} else {
parent.insertAt(clone, ix++);
}
}
node.parent.removeChild(node);
}
/* harmony default export */ var abbreviation_es = (index);
//# sourceMappingURL=abbreviation.es.js.map
// CONCATENATED MODULE: ../node_modules/@emmetio/html-snippets-resolver/dist/html-snippets-resolver.es.js
var html_snippets_resolver_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/**
* For every node in given `tree`, finds matching snippet from `registry` and
* resolves it into a parsed abbreviation. Resolved node is then updated or
* replaced with matched abbreviation tree.
*
* A HTML registry basically contains aliases to another Emmet abbreviations,
* e.g. a predefined set of name, attribues and so on, possibly a complex
* abbreviation with multiple elements. So we have to get snippet, parse it
* and recursively resolve it.
*
* @param {Node} tree Parsed Emmet abbreviation
* @param {SnippetsRegistry} registry Registry with all available snippets
* @return {Node} Updated tree
*/
var html_snippets_resolver_es_index = function (tree, registry) {
tree.walk(node => resolveNode(node, registry));
return tree;
};
function resolveNode(node, registry) {
const stack = new Set();
const resolve = node => {
const snippet = registry.resolve(node.name);
// A snippet in stack means circular reference.
// It can be either a user error or a perfectly valid snippet like
// "img": "img[src alt]/", e.g. an element with predefined shape.
// In any case, simply stop parsing and keep element as is
if (!snippet || stack.has(snippet)) {
return;
}
// In case if matched snippet is a function, pass control into it
if (typeof snippet.value === 'function') {
return snippet.value(node, registry, resolve);
}
const tree = abbreviation_es(snippet.value);
stack.add(snippet);
tree.walk(resolve);
stack.delete(snippet);
// move current node contents into new tree
const childTarget = findDeepestNode(tree);
merge(childTarget, node);
while (tree.firstChild) {
node.parent.insertBefore(tree.firstChild, node);
}
childTarget.parent.insertBefore(node, childTarget);
childTarget.remove();
};
resolve(node);
}
/**
* Adds data from first node into second node and returns it
* @param {Node} from
* @param {Node} to
* @return {Node}
*/
function merge(from, to) {
to.name = from.name;
if (from.selfClosing) {
to.selfClosing = true;
}
if (from.value != null) {
to.value = from.value;
}
if (from.repeat) {
to.repeat = html_snippets_resolver_es__extends({}, from.repeat);
}
return mergeAttributes(from, to);
}
/**
* Transfer attributes from first element to second one and preserve first
* elements attributes order
* @param {Node} from
* @param {Node} to
* @return {Node}
*/
function mergeAttributes(from, to) {
mergeClassNames(from, to);
// Its important to preserve attributes order: ones in `from` have higher
// pripority than in `to`. Collect attributes in map in order they should
// appear in `to`
const attrMap = new Map();
let attrs = from.attributes;
for (let i = 0; i < attrs.length; i++) {
attrMap.set(attrs[i].name, attrs[i].clone());
}
attrs = to.attributes.slice();
for (let i = 0, attr, a; i < attrs.length; i++) {
attr = attrs[i];
if (attrMap.has(attr.name)) {
a = attrMap.get(attr.name);
a.value = attr.value;
// If user explicitly wrote attribute in abbreviation, its no longer
// implied and should be outputted even if value is empty
if (a.options.implied) {
a.options.implied = false;
}
} else {
attrMap.set(attr.name, attr);
}
to.removeAttribute(attr);
}
const newAttrs = Array.from(attrMap.values());
for (let i = 0; i < newAttrs.length; i++) {
to.setAttribute(newAttrs[i]);
}
return to;
}
/**
* Adds class names from first node to second one
* @param {Node} from
* @param {Node} to
* @return {Node}
*/
function mergeClassNames(from, to) {
const classNames = from.classList;
for (let i = 0; i < classNames.length; i++) {
to.addClass(classNames[i]);
}
return to;
}
/**
* Finds node which is the deepest for in current node or node iteself.
* @param {Node} node
* @return {Node}
*/
function findDeepestNode(node) {
while (node.children.length) {
node = node.children[node.children.length - 1];
}
return node;
}
/* harmony default export */ var html_snippets_resolver_es = (html_snippets_resolver_es_index);
// CONCATENATED MODULE: ../node_modules/@emmetio/implicit-tag/dist/implicit-tag.es.js
const inlineElements = new Set('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'.split(','));
const elementMap = {
p: 'span',
ul: 'li',
ol: 'li',
table: 'tr',
tr: 'td',
tbody: 'tr',
thead: 'tr',
tfoot: 'tr',
colgroup: 'col',
select: 'option',
optgroup: 'option',
audio: 'source',
video: 'source',
object: 'param',
map: 'area'
};
/**
* Returns best child node name for given parent node name
* @param {String} parentName Name of parent node
* @return {String}
*/
function resolveImplicitName(parentName) {
parentName = (parentName || '').toLowerCase();
return elementMap[parentName] || (inlineElements.has(parentName) ? 'span' : 'div');
}
/* harmony default export */ var implicit_tag_es = (resolveImplicitName);
// CONCATENATED MODULE: ../node_modules/@emmetio/html-transform/dist/html-transform.es.js
var html_transform_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/**
* Adds missing tag names for given tree depending on nodes parent name
*/
var implicitTags = function (tree) {
tree.walk(node => {
// resolve only nameless nodes without content
if (node.name == null && node.attributes.length) {
node.name = implicit_tag_es(node.parent.name);
}
});
return tree;
};
/**
* Locates all occurances of given `token` which are not escaped (e.g. are not
* preceded with `\`) given in `str`
* @param {String} str
* @return {Array} Array of token ranges
*/
function findUnescapedTokens(str, token) {
const result = new Set();
const tlen = token.length;
// 1. Find all occurances of tokens
let pos = 0;
while ((pos = str.indexOf(token, pos)) !== -1) {
result.add(pos);
pos += tlen;
}
if (result.size) {
// 2. Remove ones that escaped
let pos = 0;
const len = str.length;
while (pos < len) {
if (str[pos++] === '\\') {
result.delete(pos++);
}
}
}
return Array.from(result).map(ix => html_transform_es_range(ix, tlen));
}
/**
* Replaces `ranges`, generated by `range()` function, with given `value` in `str`
* @param {String} str Where to replace ranges
* @param {Array} ranges Ranes, created by `range()` function
* @param {String|Function} value Replacement value. If its a function, it
* will take a range value as argument and should return a new string
* @return {String}
*/
function replaceRanges(str, ranges, value) {
// should walk from the end of array to keep ranges valid after replacement
for (let i = ranges.length - 1; i >= 0; i--) {
const r = ranges[i];
let offset = 0;
let offsetLength = 0;
let descendingOrder = false;
if (str.substr(r[0] + r[1], 1) === '@') {
if (str.substr(r[0] + r[1] + 1, 1) === '-') {
descendingOrder = true;
}
const matches = str.substr(r[0] + r[1] + 1 + Number(descendingOrder)).match(/^(\d+)/);
if (matches) {
offsetLength = matches[1].length + 1 + Number(descendingOrder);
offset = parseInt(matches[1]) - 1;
} else {
offsetLength = 2;
}
}
str = str.substring(0, r[0]) + (typeof value === 'function' ? value(str.substr(r[0], r[1]), offset, descendingOrder) : value) + str.substring(r[0] + r[1] + offsetLength);
}
return str;
}
function html_transform_es_range(start, length) {
return [start, length];
}
const numberingToken = '$';
/**
* Numbering of expanded abbreviation: finds all nodes with `$` in value
* or attributes and replaces its occurances with repeater value
*/
var applyNumbering = function (tree) {
tree.walk(applyNumbering$1);
return tree;
};
/**
* Applies numbering for given node: replaces occurances of numbering token
* in nodes name, content and attributes
* @param {Node} node
* @return {Node}
*/
function applyNumbering$1(node) {
const repeater = findRepeater(node);
if (repeater && repeater.value != null) {
// NB replace numbering in nodes with explicit repeater only:
// it solves issues with abbreviations like `xsl:if[test=$foo]` where
// `$foo` is preferred output
const value = repeater.value;
const count = repeater.count;
node.name = replaceNumbering(node.name, value, count);
node.value = replaceNumbering(node.value, value, count);
node.attributes.forEach(attr => {
const copy = node.getAttribute(attr.name).clone();
copy.name = replaceNumbering(attr.name, value, count);
copy.value = replaceNumbering(attr.value, value, count);
node.replaceAttribute(attr.name, copy);
});
}
return node;
}
/**
* Returns repeater object for given node
* @param {Node} node
* @return {Object}
*/
function findRepeater(node) {
while (node) {
if (node.repeat) {
return node.repeat;
}
node = node.parent;
}
}
/**
* Replaces numbering in given string
* @param {String} str
* @param {Number} value
* @return {String}
*/
function replaceNumbering(str, value, count) {
// replace numbering in strings only: skip explicit wrappers that could
// contain unescaped numbering tokens
if (typeof str === 'string') {
const ranges = getNumberingRanges(str);
return replaceNumberingRanges(str, ranges, value, count);
}
return str;
}
/**
* Returns numbering ranges, e.g. ranges of `$` occurances, in given string.
* Multiple adjacent ranges are combined
* @param {String} str
* @return {Array}
*/
function getNumberingRanges(str) {
return findUnescapedTokens(str || '', numberingToken).reduce((out, range$$1) => {
// skip ranges that actually belongs to output placeholder or tabstops
if (!/[#{]/.test(str[range$$1[0] + 1] || '')) {
const lastRange = out[out.length - 1];
if (lastRange && lastRange[0] + lastRange[1] === range$$1[0]) {
lastRange[1] += range$$1[1];
} else {
out.push(range$$1);
}
}
return out;
}, []);
}
/**
* @param {String} str
* @param {Array} ranges
* @param {Number} value
* @return {String}
*/
function replaceNumberingRanges(str, ranges, value, count) {
const replaced = replaceRanges(str, ranges, (token, offset, descendingOrder) => {
let _value = descendingOrder ? String(offset + count - value + 1) : String(value + offset);
// pad values for multiple numbering tokens, e.g. 3 for $$$ becomes 003
while (_value.length < token.length) {
_value = '0' + _value;
}
return _value;
});
// unescape screened numbering tokens
return unescapeString(replaced);
}
/**
* Unescapes characters, screened with `\`, in given string
* @param {String} str
* @return {String}
*/
function unescapeString(str) {
let i = 0,
result = '';
const len = str.length;
while (i < len) {
const ch = str[i++];
result += ch === '\\' ? str[i++] || '' : ch;
}
return result;
}
/** Placeholder for inserted content */
const placeholder = '$#';
/** Placeholder for caret */
const caret = '|';
const reUrl = /^((?:https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
const reEmail = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
const reProto = /^([a-z]+:)?\/\//i;
/**
* Inserts content into node with implicit repeat count: this node is then
* duplicated for each content item and content itself is inserted either into
* deepest child or instead of a special token.
*
* This method uses two distinct steps: `prepare()` and `insert()` since most
* likely these steps will be used separately to properly insert content
* with unescaped `$` numbering markers.
*
* @param {Node} tree Parsed abbreviation
* @param {String[]} content Array of content items to insert
* @return {Node}
*/
/**
* Finds nodes with implicit repeat and creates `amount` copies of it in tree
* @param {Node} tree
* @param {Number} amount
* @return {Node}
*/
function prepare(tree, amount) {
amount = amount || 1;
tree.walk(node => {
if (node.repeat && node.repeat.count === null) {
for (let i = 0; i < amount; i++) {
const clone = node.clone(true);
clone.repeat.implicit = true;
clone.repeat.count = amount;
clone.repeat.value = i + 1;
clone.repeat.index = i;
node.parent.insertBefore(clone, node);
}
node.remove();
}
});
return tree;
}
/**
* Inserts content into implicitly repeated nodes, created by `prepare()` method
* @param {Node} tree
* @param {String[]} content
* @return {Node}
*/
function insert(tree, content) {
if (Array.isArray(content) && content.length) {
let updated = false;
tree.walk(node => {
if (node.repeat && node.repeat.implicit) {
updated = true;
insertContent(node, content[node.repeat.index]);
}
});
if (!updated) {
// no node with implicit repeat was found, insert content as
// deepest child
setNodeContent(html_transform_es_findDeepestNode(tree), content.join('\n'));
}
}
return tree;
}
/**
* Inserts `content` into given `node`: either replaces output placeholders
* or inserts it into deepest child node
* @param {Node} node
* @param {String} content
* @return {Node}
*/
function insertContent(node, content) {
let inserted = insertContentIntoPlaceholder(node, content);
node.walk(child => inserted |= insertContentIntoPlaceholder(child, content));
if (!inserted) {
// no placeholders were found in node, insert content into deepest child
setNodeContent(html_transform_es_findDeepestNode(node), content);
}
return node;
}
/**
* Inserts given `content` into placeholders for given `node`. Placeholders
* might be available in attribute values and node content
* @param {Node} node
* @param {String} content
* @return {Boolean} Returns `true` if placeholders were found and replaced in node
*/
function insertContentIntoPlaceholder(node, content) {
const state = { replaced: false };
node.value = replacePlaceholder(node.value, content, state);
node.attributes.forEach(attr => {
if (attr.value) {
node.setAttribute(attr.name, replacePlaceholder(attr.value, content, state));
}
});
return state.replaced;
}
/**
* Replaces all placeholder occurances in given `str` with `value`
* @param {String} str
* @param {String} value
* @param {Object} [_state] If provided, set `replaced` property of given
* object to `true` if placeholder was found and replaced
* @return {String}
*/
function replacePlaceholder(str, value, _state) {
if (typeof str === 'string') {
const ranges = findUnescapedTokens(str, placeholder);
if (ranges.length) {
if (_state) {
_state.replaced = true;
}
str = replaceRanges(str, ranges, value);
}
}
return str;
}
/**
* Finds node which is the deepest for in current node or node iteself.
* @param {Node} node
* @return {Node}
*/
function html_transform_es_findDeepestNode(node) {
while (node.children.length) {
node = node.children[node.children.length - 1];
}
return node;
}
/**
* Updates content of given node
* @param {Node} node
* @param {String} content
*/
function setNodeContent(node, content) {
// find caret position and replace it with content, if possible
if (node.value) {
const ranges = findUnescapedTokens(node.value, caret);
if (ranges.length) {
node.value = replaceRanges(node.value, ranges, content);
return;
}
}
if (node.name.toLowerCase() === 'a' || node.hasAttribute('href')) {
// special case: inserting content into `<a>` tag
if (reUrl.test(content)) {
node.setAttribute('href', (reProto.test(content) ? '' : 'http://') + content);
} else if (reEmail.test(content)) {
node.setAttribute('href', 'mailto:' + content);
}
}
node.value = content;
}
const html_transform_es_defaultOptions = {
element: '__',
modifier: '_'
};
const reElement = /^(-+)([a-z0-9]+[a-z0-9-]*)/i;
const reModifier = /^(_+)([a-z0-9]+[a-z0-9-_]*)/i;
const blockCandidates1 = className => /^[a-z]\-/i.test(className);
const blockCandidates2 = className => /^[a-z]/i.test(className);
/**
* BEM transformer: updates class names written as `-element` and
* `_modifier` into full class names as described in BEM specs. Also adds missing
* class names: fir example, if node contains `.block_modifier` class, ensures
* that element contains `.block` class as well
*/
var bem = function (tree, options) {
options = html_transform_es__extends({}, html_transform_es_defaultOptions, options);
tree.walk(node => expandClassNames(node, options));
const lookup = createBlockLookup(tree);
tree.walk(node => expandShortNotation(node, lookup, options));
return tree;
};
/**
* Expands existing class names in BEM notation in given `node`.
* For example, if node contains `b__el_mod` class name, this method ensures
* that element contains `b__el` class as well
* @param {Node} node
* @param {Object} options
* @return {Set}
*/
function expandClassNames(node, options) {
const classNames = node.classList.reduce((out, cl) => {
// remove all modifiers and element prefixes from class name to get a base element name
const ix = cl.indexOf('_');
if (ix > 0 && !cl.startsWith('-')) {
out.add(cl.slice(0, ix));
out.add(cl.slice(ix));
return out;
}
return out.add(cl);
}, new Set());
if (classNames.size) {
node.setAttribute('class', Array.from(classNames).join(' '));
}
}
/**
* Expands short BEM notation, e.g. `-element` and `_modifier`
* @param {Node} node Parsed Emmet abbreviation node
* @param {Map} lookup BEM block name lookup
* @param {Object} options
*/
function expandShortNotation(node, lookup, options) {
const classNames = node.classList.reduce((out, cl) => {
let prefix, m;
const originalClass = cl;
// parse element definition (could be only one)
if (m = cl.match(reElement)) {
prefix = getBlockName(node, lookup, m[1]) + options.element + m[2];
out.add(prefix);
cl = cl.slice(m[0].length);
}
// parse modifiers definitions
if (m = cl.match(reModifier)) {
if (!prefix) {
prefix = getBlockName(node, lookup, m[1]);
out.add(prefix);
}
out.add(`${prefix}${options.modifier}${m[2]}`);
cl = cl.slice(m[0].length);
}
if (cl === originalClass) {
// class name wasnt modified: its not a BEM-specific class,
// add it as-is into output
out.add(originalClass);
}
return out;
}, new Set());
const arrClassNames = Array.from(classNames).filter(Boolean);
if (arrClassNames.length) {
node.setAttribute('class', arrClassNames.join(' '));
}
}
/**
* Creates block name lookup for each node in given tree, e.g. finds block
* name explicitly for each node
* @param {Node} tree
* @return {Map}
*/
function createBlockLookup(tree) {
const lookup = new Map();
tree.walk(node => {
const classNames = node.classList;
if (classNames.length) {
// guess best block name from class or use parents block name
lookup.set(node, find(classNames, blockCandidates1) || find(classNames, blockCandidates2) || lookup.get(node.parent));
}
});
return lookup;
}
/**
* Returns block name for given `node` by `prefix`, which tells the depth of
* of parent node lookup
* @param {Node} node
* @param {Map} lookup
* @param {String} prefix
* @return {String}
*/
function getBlockName(node, lookup, prefix) {
let depth = prefix.length > 1 ? prefix.length : 0;
// NB dont walk up to root node, stay at first root child in case of
// too deep prefix
while (node.parent && node.parent.parent && depth--) {
node = node.parent;
}
return lookup.get(node) || '';
}
function find(arr, filter) {
for (let i = 0; i < arr.length; i++) {
if (reElement.test(arr[i]) || reModifier.test(arr[i])) {
break;
}
if (filter(arr[i])) {
return arr[i];
}
}
}
/**
* JSX transformer: replaces `class` and `for` attributes with `className` and
* `htmlFor` attributes respectively
*/
var jsx = function (tree) {
tree.walk(node => {
replace(node, 'class', 'className');
replace(node, 'for', 'htmlFor');
});
return tree;
};
function replace(node, oldName, newName) {
let attr = node.getAttribute(oldName);
if (attr) {
attr.name = newName;
}
}
const reSupporterNames = /^xsl:(variable|with\-param)$/i;
/**
* XSL transformer: removes `select` attributes from certain nodes that contain
* children
*/
var xsl = function (tree) {
tree.walk(node => {
if (reSupporterNames.test(node.name || '') && (node.children.length || node.value)) {
node.removeAttribute('select');
}
});
return tree;
};
const supportedAddons = { bem, jsx, xsl };
/**
* Runs additional transforms on given tree.
* These transforms may introduce side-effects and unexpected result
* so they are not applied by default, authors must specify which addons
* in `addons` argument as `{addonName: addonOptions}`
* @param {Node} tree Parsed Emmet abbreviation
* @param {Object} addons Add-ons to apply and their options
*/
var addons = function (tree, addons) {
Object.keys(addons || {}).forEach(key => {
if (key in supportedAddons) {
const addonOpt = typeof addons[key] === 'object' ? addons[key] : null;
tree = tree.use(supportedAddons[key], addonOpt);
}
});
return tree;
};
/**
* Applies basic HTML-specific transformations for given parsed abbreviation:
* resolve implied tag names
* insert repeated content
* resolve node numbering
*/
var html_transform_es_index = function (tree, content, appliedAddons) {
if (typeof content === 'string') {
content = [content];
} else if (content && typeof content === 'object' && !Array.isArray(content)) {
appliedAddons = content;
content = null;
}
return tree.use(implicitTags).use(prepare, Array.isArray(content) ? content.length : null).use(applyNumbering).use(insert, content).use(addons, appliedAddons);
};
/* harmony default export */ var html_transform_es = (html_transform_es_index);
// CONCATENATED MODULE: ../node_modules/@emmetio/variable-resolver/dist/variable-resolver.es.js
/**
* Replaces all unescaped ${variable} occurances in given parsed abbreviation
* `tree` with values provided in `variables` hash. Precede `$` with `\` to
* escape it and skip replacement
* @param {Node} tree Parsed abbreviation tree
* @param {Object} variables Variables values
* @return {Node}
*/
function replaceVariables(tree, variables) {
variables = variables || {};
tree.walk(node => replaceInNode(node, variables));
return tree;
}
function replaceInNode(node, variables) {
// Replace variables in attributes.
const attrs = node.attributes;
for (let i = 0, il = attrs.length; i < il; i++) {
const attr = attrs[i];
if (typeof attr.value === 'string') {
node.setAttribute(attr.name, replaceInString(attr.value, variables));
}
}
if (node.value != null) {
node.value = replaceInString(node.value, variables);
}
return node;
}
/**
* Replaces all unescaped `${variable}` occurances in given string with values
* from `variables` object
* @param {String} string
* @param {Object} variables
* @return {String}
*/
function replaceInString(string, variables) {
const model = createModel(string);
let offset = 0;
let output = '';
for (let i = 0, il = model.variables.length; i < il; i++) {
const v = model.variables[i];
let value = v.name in variables ? variables[v.name] : v.name;
if (typeof value === 'function') {
value = value(model.string, v, offset + v.location);
}
output += model.string.slice(offset, v.location) + value;
offset = v.location + v.length;
}
return output + model.string.slice(offset);
}
/**
* Creates variable model from given string. The model contains a `string` with
* all escaped variable tokens written without escape symbol and `variables`
* property with all unescaped variables and their ranges
* @param {String} string
* @return {Object}
*/
function createModel(string) {
const reVariable = /\$\{([a-z][\w\-]*)\}/ig;
const escapeCharCode = 92; // `\` symbol
const variables = [];
// We have to replace unescaped (e.g. not preceded with `\`) tokens.
// Instead of writing a stream parser, well cut some edges here:
// 1. Find all tokens
// 2. Walk string char-by-char and resolve only tokens that are not escaped
const tokens = new Map();
let m;
while (m = reVariable.exec(string)) {
tokens.set(m.index, m);
}
if (tokens.size) {
let start = 0,
pos = 0,
len = string.length;
let output = '';
while (pos < len) {
if (string.charCodeAt(pos) === escapeCharCode && tokens.has(pos + 1)) {
// Found escape symbol that escapes variable: we should
// omit this symbol in output string and skip variable
const token = tokens.get(pos + 1);
output += string.slice(start, pos) + token[0];
start = pos = token.index + token[0].length;
tokens.delete(pos + 1);
continue;
}
pos++;
}
string = output + string.slice(start);
// Not using `.map()` here to reduce memory allocations
const validMatches = Array.from(tokens.values());
for (let i = 0, il = validMatches.length; i < il; i++) {
const token = validMatches[i];
variables.push({
name: token[1],
location: token.index,
length: token[0].length
});
}
}
return { string, variables };
}
/* harmony default export */ var variable_resolver_es = (replaceVariables);
// CONCATENATED MODULE: ../node_modules/@emmetio/output-renderer/dist/output-renderer.es.js
var output_renderer_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
const defaultFieldsRenderer = text => text;
/**
* Output node is an object containing generated output for given Emmet
* abbreviation node. Output node can be passed to various processors that
* may shape-up final node output. The final output is simply a concatenation
* of `.open`, `.text` and `.close` properties and its `.before*` and `.after*`
* satellites
* @param {Node} node Parsed Emmet abbreviation node
* @param {Function} fieldsRenderer A function for rendering fielded text (text with
* tabstops) for current node. @see ./render.js for details
*/
let OutputNode = class OutputNode {
constructor(node, fieldsRenderer, options) {
if (typeof fieldsRenderer === 'object') {
options = fieldsRenderer;
fieldsRenderer = null;
}
this.node = node;
this._fieldsRenderer = fieldsRenderer || defaultFieldsRenderer;
this.open = null;
this.beforeOpen = '';
this.afterOpen = '';
this.close = null;
this.beforeClose = '';
this.afterClose = '';
this.text = null;
this.beforeText = '';
this.afterText = '';
this.indent = '';
this.newline = '';
if (options) {
output_renderer_es__extends(this, options);
}
}
clone() {
return new this.constructor(this.node, this);
}
/**
* Properly indents given multiline text
* @param {String} text
*/
indentText(text) {
const lines = splitByLines(text);
if (lines.length === 1) {
// no newlines, nothing to indent
return text;
}
// No newline and no indent means no formatting at all:
// in this case we should replace newlines with spaces
const nl = !this.newline && !this.indent ? ' ' : this.newline;
return lines.map((line, i) => i ? this.indent + line : line).join(nl);
}
/**
* Renders given text with fields
* @param {String} text
* @return {String}
*/
renderFields(text) {
return this._fieldsRenderer(text);
}
toString(children) {
const open = this._wrap(this.open, this.beforeOpen, this.afterOpen);
const close = this._wrap(this.close, this.beforeClose, this.afterClose);
const text = this._wrap(this.text, this.beforeText, this.afterText);
return open + text + (children != null ? children : '') + close;
}
_wrap(str, before, after) {
before = before != null ? before : '';
after = after != null ? after : '';
// automatically trim whitespace for non-empty wraps
if (str != null) {
str = before ? str.replace(/^\s+/, '') : str;
str = after ? str.replace(/\s+$/, '') : str;
return before + this.indentText(str) + after;
}
return '';
}
};
/**
* Splits given text by lines
* @param {String} text
* @return {String[]}
*/
function splitByLines(text) {
return (text || '').split(/\r\n|\r|\n/g);
}
/**
* Default output of field (tabstop)
* @param {Number} index Field index
* @param {String} placeholder Field placeholder, can be null
* @return {String}
*/
const defaultField = (index, placeholder) => placeholder || '';
/**
* Renders given parsed abbreviation `tree` via `formatter` function.
* @param {Node} tree Parsed Emmet abbreviation
* @param {Function} [field] Optional function to format field/tabstop (@see `defaultField`)
* @param {Function} formatter Output formatter function. It takes an output node—
* a special wrapper for parsed node that holds formatting and output properties—
* and updates its output properties to shape-up nodes output.
* Function arguments:
* `outNode`: OutputNode
* `renderFields`: a helper function that parses fields/tabstops from given
* text and replaces them with `field` function output.
* It also takes care about field indicies and ensures that the same indicies
* from different nodes wont collide
*/
function render(tree, field, formatter) {
if (typeof formatter === 'undefined') {
formatter = field;
field = null;
}
field = field || defaultField;
// Each node may contain fields like `${1:placeholder}`.
// Since most modern editors will link all fields with the same
// index, we have to ensure that different nodes has their own indicies.
// Well use this `fieldState` object to globally increment field indices
// during output
const fieldState = { index: 1 };
const fieldsRenderer = text => text == null ? field(fieldState.index++) : getFieldsModel(text, fieldState).mark(field);
return run(tree.children, formatter, fieldsRenderer);
}
function run(nodes, formatter, fieldsRenderer) {
return nodes.map(node => {
const outNode = formatter(new OutputNode(node, fieldsRenderer));
return outNode ? outNode.toString(run(node.children, formatter, fieldsRenderer)) : '';
}).join('');
}
/**
* Returns fields (tab-stops) model with properly updated indices that wont
* collide with fields in other nodes of foprmatted tree
* @param {String|Object} text Text to get fields model from or model itself
* @param {Object} fieldState Abbreviation tree-wide field state reference
* @return {Object} Field model
*/
function getFieldsModel(text, fieldState) {
const model = typeof text === 'object' ? text : field_parser_es(text);
let largestIndex = -1;
model.fields.forEach(field => {
field.index += fieldState.index;
if (field.index > largestIndex) {
largestIndex = field.index;
}
});
if (largestIndex !== -1) {
fieldState.index = largestIndex + 1;
}
return model;
}
/* harmony default export */ var output_renderer_es = (render);
// CONCATENATED MODULE: ../node_modules/@emmetio/markup-formatters/dist/markup-formatters.es.js
var markup_formatters_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
const TOKEN = /^(.*?)([A-Z_]+)(.*?)$/;
const TOKEN_OPEN = 91; // [
const TOKEN_CLOSE = 93; // ]
/**
* A basic templating engine.
* Takes every `[TOKEN]` from given string and replaces it with
* `TOKEN` value from given `data` attribute. The token itself may contain
* various characters between `[`, token name and `]`. Contents of `[...]` will
* be outputted only if `TOKEN` value is not empty. Also, only `TOKEN` name will
* be replaced with actual value, all other characters will remain as is.
*
* Example:
* ```
* template('[<NAME>]', {NAME: 'foo'}) -> "<foo>"
* template('[<NAME>]', {}) -> ""
* ```
*/
function template(str, data) {
if (str == null) {
return str;
}
// NB since token may contain inner `[` and `]`, we cant just use regexp
// for replacement, should manually parse string instead
const stack = [];
const replacer = (str, left, token, right) => data[token] != null ? left + data[token] + right : '';
let output = '';
let offset = 0,
i = 0;
let code, lastPos;
while (i < str.length) {
code = str.charCodeAt(i);
if (code === TOKEN_OPEN) {
stack.push(i);
} else if (code === TOKEN_CLOSE) {
lastPos = stack.pop();
if (!stack.length) {
output += str.slice(offset, lastPos) + str.slice(lastPos + 1, i).replace(TOKEN, replacer);
offset = i + 1;
}
}
i++;
}
return output + str.slice(offset);
}
/**
* Various utility methods used by formatters
*/
/**
* Splits given text by lines
* @param {String} text
* @return {String[]}
*/
function markup_formatters_es_splitByLines(text) {
return (text || '').split(/\r\n|\r|\n/g);
}
/**
* Check if given node is a first child in its parent
* @param {Node} node
* @return {Boolean}
*/
function isFirstChild(node) {
return node.parent.firstChild === node;
}
/**
* Check if given node is a root node
* @param {Node} node
* @return {Boolean}
*/
function isRoot(node) {
return node && !node.parent;
}
/**
* Check if given node is a pseudo-snippet: a text-only node with explicitly
* defined children
* @param {Node} node
* @return {Boolean}
*/
function isPseudoSnippet(node) {
return node.isTextOnly && !!node.children.length;
}
/**
* Handles pseudo-snippet node.
* A pseudo-snippet is a text-only node with explicitly defined children.
* For such case, we have to figure out if pseudo-snippet contains fields
* (tab-stops) in node value and “split” it: make contents before field with
* lowest index nodes “open” part and contents after lowest index — “close”
* part. With this trick a final output will look like nodes children
* are nested inside node value
* @param {OutputNode} outNode
* @return {Boolean} Returns “true” if given node is a pseudo-snippets,
* `false` otherwise
*/
function handlePseudoSnippet(outNode) {
const node = outNode.node; // original abbreviaiton node
if (isPseudoSnippet(node)) {
const fieldsModel = field_parser_es(node.value);
const field = findLowestIndexField(fieldsModel);
if (field) {
const parts = splitFieldsModel(fieldsModel, field);
outNode.open = outNode.renderFields(parts[0]);
outNode.close = outNode.renderFields(parts[1]);
} else {
outNode.text = outNode.renderFields(fieldsModel);
}
return true;
}
return false;
}
/**
* Finds field with lowest index in given text
* @param {Object} model
* @return {Object}
*/
function findLowestIndexField(model) {
return model.fields.reduce((result, field) => !result || field.index < result.index ? field : result, null);
}
/**
* Splits given fields model in two parts by given field
* @param {Object} model
* @param {Object} field
* @return {Array} Two-items array
*/
function splitFieldsModel(model, field) {
const ix = model.fields.indexOf(field);
const left = new model.constructor(model.string.slice(0, field.location), model.fields.slice(0, ix));
const right = new model.constructor(model.string.slice(field.location + field.length), model.fields.slice(ix + 1));
return [left, right];
}
const commentOptions = {
// enable node commenting
enabled: false,
// attributes that should trigger node commenting on specific node,
// if commenting is enabled
trigger: ['id', 'class'],
// comment before opening tag
before: '',
// comment after closing tag
after: '\n<!-- /[#ID][.CLASS] -->'
};
/**
* Renders given parsed Emmet abbreviation as HTML, formatted according to
* `profile` options
* @param {Node} tree Parsed Emmet abbreviation
* @param {Profile} profile Output profile
* @param {Object} [options] Additional formatter options
* @return {String}
*/
function html(tree, profile, options) {
options = markup_formatters_es__extends({}, options);
const format = getFormatOptions(options);
return output_renderer_es(tree, options.field, outNode => {
outNode = setFormatting(outNode, profile);
if (!handlePseudoSnippet(outNode)) {
const node = outNode.node;
if (node.name) {
const name = profile.name(node.name);
const attrs = formatAttributes(outNode, profile);
outNode.open = `<${name}${attrs}${node.selfClosing ? profile.selfClose() : ''}>`;
if (!node.selfClosing) {
outNode.close = `</${name}>`;
}
commentNode(outNode, format.comment);
}
// Do not generate fields for nodes with empty value and children
// or if node is self-closed
if (node.value || !node.children.length && !node.selfClosing) {
outNode.text = outNode.renderFields(node.value);
}
}
return outNode;
});
}
/**
* Updates formatting properties for given output node
* @param {OutputNode} outNode Output wrapper of farsed abbreviation node
* @param {Profile} profile Output profile
* @return {OutputNode}
*/
function setFormatting(outNode, profile) {
const node = outNode.node;
if (shouldFormatNode(node, profile)) {
outNode.indent = profile.indent(getIndentLevel(node, profile));
outNode.newline = '\n';
const prefix = outNode.newline + outNode.indent;
// do not format the very first node in output
if (!isRoot(node.parent) || !isFirstChild(node)) {
outNode.beforeOpen = prefix;
if (node.isTextOnly) {
outNode.beforeText = prefix;
}
}
if (hasInnerFormatting(node, profile)) {
if (!node.isTextOnly) {
outNode.beforeText = prefix + profile.indent(1);
}
outNode.beforeClose = prefix;
}
}
return outNode;
}
/**
* Check if given node should be formatted
* @param {Node} node
* @param {Profile} profile
* @return {Boolean}
*/
function shouldFormatNode(node, profile) {
if (!profile.get('format')) {
return false;
}
if (node.parent.isTextOnly && node.parent.children.length === 1 && field_parser_es(node.parent.value).fields.length) {
// Edge case: do not format the only child of text-only node,
// but only if parent contains fields
return false;
}
return isInline(node, profile) ? shouldFormatInline(node, profile) : true;
}
/**
* Check if given inline node should be formatted as well, e.g. it contains
* enough adjacent siblings that should force formatting
* @param {Node} node
* @param {Profile} profile
* @return {Boolean}
*/
function shouldFormatInline(node, profile) {
if (!isInline(node, profile)) {
return false;
}
if (isPseudoSnippet(node)) {
return true;
}
// check if inline node is the next sibling of block-level node
if (node.childIndex === 0) {
// first node in parent: format if its followed by a block-level element
let next = node;
while (next = next.nextSibling) {
if (!isInline(next, profile)) {
return true;
}
}
} else if (!isInline(node.previousSibling, profile)) {
// node is right after block-level element
return true;
}
if (profile.get('inlineBreak')) {
// check for adjacent inline elements before and after current element
let adjacentInline = 1;
let before = node,
after = node;
while (isInlineElement(before = before.previousSibling, profile)) {
adjacentInline++;
}
while (isInlineElement(after = after.nextSibling, profile)) {
adjacentInline++;
}
if (adjacentInline >= profile.get('inlineBreak')) {
return true;
}
}
// Another edge case: inline node contains node that should receive foramtting
for (let i = 0, il = node.children.length; i < il; i++) {
if (shouldFormatNode(node.children[i], profile)) {
return true;
}
}
return false;
}
/**
* Check if given node contains inner formatting, e.g. any of its children should
* be formatted
* @param {Node} node
* @param {Profile} profile
* @return {Boolean}
*/
function hasInnerFormatting(node, profile) {
// check if node if forced for inner formatting
const nodeName = (node.name || '').toLowerCase();
if (profile.get('formatForce').indexOf(nodeName) !== -1) {
return true;
}
// check if any of children should receive formatting
// NB dont use `childrent.some()` to reduce memory allocations
for (let i = 0; i < node.children.length; i++) {
if (shouldFormatNode(node.children[i], profile)) {
return true;
}
}
return false;
}
/**
* Outputs attributes of given abbreviation node as HTML attributes
* @param {OutputNode} outNode
* @param {Profile} profile
* @return {String}
*/
function formatAttributes(outNode, profile) {
const node = outNode.node;
return node.attributes.map(attr => {
if (attr.options.implied && attr.value == null) {
return null;
}
const attrName = profile.attribute(attr.name);
let attrValue = null;
// handle boolean attributes
if (attr.options.boolean || profile.get('booleanAttributes').indexOf(attrName.toLowerCase()) !== -1) {
if (profile.get('compactBooleanAttributes') && attr.value == null) {
return ` ${attrName}`;
} else if (attr.value == null) {
attrValue = attrName;
}
}
if (attrValue == null) {
attrValue = outNode.renderFields(attr.value);
}
return ` ${attrName}=${profile.quote(attrValue)}`;
}).join('');
}
/**
* Check if given node is inline-level
* @param {Node} node
* @param {Profile} profile
* @return {Boolean}
*/
function isInline(node, profile) {
return node && node.isTextOnly || isInlineElement(node, profile);
}
/**
* Check if given node is inline-level element, e.g. element with explicitly
* defined node name
* @param {Node} node
* @param {Profile} profile
* @return {Boolean}
*/
function isInlineElement(node, profile) {
return node && profile.isInline(node);
}
/**
* Computes indent level for given node
* @param {Node} node
* @param {Profile} profile
* @param {Number} level
* @return {Number}
*/
function getIndentLevel(node, profile) {
// Increase indent level IF NOT:
// * parent is text-only node
// * theres a parent node with a name that is explicitly set to decrease level
const skip = profile.get('formatSkip') || [];
let level = node.parent.isTextOnly ? -2 : -1;
let ctx = node;
while (ctx = ctx.parent) {
if (skip.indexOf((ctx.name || '').toLowerCase()) === -1) {
level++;
}
}
return level < 0 ? 0 : level;
}
/**
* Comments given output node, if required
* @param {OutputNode} outNode
* @param {Object} options
*/
function commentNode(outNode, options) {
const node = outNode.node;
if (!options.enabled || !options.trigger || !node.name) {
return;
}
const attrs = outNode.node.attributes.reduce((out, attr) => {
if (attr.name && attr.value != null) {
out[attr.name.toUpperCase().replace(/-/g, '_')] = attr.value;
}
return out;
}, {});
// add comment only if attribute trigger is present
for (let i = 0, il = options.trigger.length; i < il; i++) {
if (options.trigger[i].toUpperCase() in attrs) {
outNode.open = template(options.before, attrs) + outNode.open;
if (outNode.close) {
outNode.close += template(options.after, attrs);
}
break;
}
}
}
function getFormatOptions(options) {
const format = markup_formatters_es__extends({}, options && options.format);
format.comment = markup_formatters_es__extends({}, commentOptions, format.comment);
return format;
}
const reId = /^id$/i;
const reClass = /^class$/i;
const defaultAttrOptions = {
primary: attrs => attrs.join(''),
secondary: attrs => attrs.map(attr => attr.isBoolean ? attr.name : `${attr.name}=${attr.value}`).join(', ')
};
const defaultNodeOptions = {
open: null,
close: null,
omitName: /^div$/i,
attributes: defaultAttrOptions
};
function indentFormat(outNode, profile, options) {
options = markup_formatters_es__extends({}, defaultNodeOptions, options);
const node = outNode.node;
outNode.indent = profile.indent(getIndentLevel$1(node, profile));
outNode.newline = '\n';
// Do not format the very first node in output
if (!isRoot(node.parent) || !isFirstChild(node)) {
outNode.beforeOpen = outNode.newline + outNode.indent;
}
if (node.name) {
const data = markup_formatters_es__extends({
NAME: profile.name(node.name),
SELF_CLOSE: node.selfClosing ? options.selfClose : null
}, getAttributes(outNode, profile, options.attributes));
// omit tag name if node has primary attributes
if (options.omitName && options.omitName.test(data.NAME) && data.PRIMARY_ATTRS) {
data.NAME = null;
}
if (options.open != null) {
outNode.open = template(options.open, data);
}
if (options.close != null) {
outNode.close = template(options.close, data);
}
}
return outNode;
}
/**
* Formats attributes of given node into a string.
* @param {OutputNode} node Output node wrapper
* @param {Profile} profile Output profile
* @param {Object} options Additional formatting options
* @return {String}
*/
function getAttributes(outNode, profile, options) {
options = markup_formatters_es__extends({}, defaultAttrOptions, options);
const primary = [],
secondary = [];
const node = outNode.node;
node.attributes.forEach(attr => {
if (attr.options.implied && attr.value == null) {
return null;
}
const name = profile.attribute(attr.name);
const value = outNode.renderFields(attr.value);
if (reId.test(name)) {
value && primary.push(`#${value}`);
} else if (reClass.test(name)) {
value && primary.push(`.${value.replace(/\s+/g, '.')}`);
} else {
const isBoolean = attr.value == null && (attr.options.boolean || profile.get('booleanAttributes').indexOf(name.toLowerCase()) !== -1);
secondary.push({ name, value, isBoolean });
}
});
return {
PRIMARY_ATTRS: options.primary(primary) || null,
SECONDARY_ATTRS: options.secondary(secondary) || null
};
}
/**
* Computes indent level for given node
* @param {Node} node
* @return {Number}
*/
function getIndentLevel$1(node) {
let level = node.parent.isTextOnly ? -2 : -1;
let ctx = node;
while (ctx = ctx.parent) {
level++;
}
return level < 0 ? 0 : level;
}
const reNl = /\n|\r/;
/**
* Renders given parsed Emmet abbreviation as HAML, formatted according to
* `profile` options
* @param {Node} tree Parsed Emmet abbreviation
* @param {Profile} profile Output profile
* @param {Object} [options] Additional formatter options
* @return {String}
*/
function haml(tree, profile, options) {
options = options || {};
const nodeOptions = {
open: '[%NAME][PRIMARY_ATTRS][(SECONDARY_ATTRS)][SELF_CLOSE]',
selfClose: '/',
attributes: {
secondary(attrs) {
return attrs.map(attr => attr.isBoolean ? `${attr.name}${profile.get('compactBooleanAttributes') ? '' : '=true'}` : `${attr.name}=${profile.quote(attr.value)}`).join(' ');
}
}
};
return output_renderer_es(tree, options.field, outNode => {
outNode = indentFormat(outNode, profile, nodeOptions);
outNode = updateFormatting(outNode, profile);
if (!handlePseudoSnippet(outNode)) {
const node = outNode.node;
// Do not generate fields for nodes with empty value and children
// or if node is self-closed
if (node.value || !node.children.length && !node.selfClosing) {
outNode.text = outNode.renderFields(formatNodeValue(node, profile));
}
}
return outNode;
});
}
/**
* Updates formatting properties for given output node
* NB Unlike HTML, HAML is indent-based format so some formatting options from
* `profile` will not take effect, otherwise output will be broken
* @param {OutputNode} outNode Output wrapper of parsed abbreviation node
* @param {Profile} profile Output profile
* @return {OutputNode}
*/
function updateFormatting(outNode, profile) {
const node = outNode.node;
if (!node.isTextOnly && node.value) {
// node with text: put a space before single-line text
outNode.beforeText = reNl.test(node.value) ? outNode.newline + outNode.indent + profile.indent(1) : ' ';
}
return outNode;
}
/**
* Formats value of given node: for multiline text we should add a ` |` suffix
* at the end of each line. Also ensure that text is perfectly aligned.
* @param {Node} node
* @param {Profile} profile
* @return {String|null}
*/
function formatNodeValue(node, profile) {
if (node.value != null && reNl.test(node.value)) {
const lines = markup_formatters_es_splitByLines(node.value);
const indent = profile.indent(1);
const maxLength = lines.reduce((prev, line) => Math.max(prev, line.length), 0);
return lines.map((line, i) => `${i ? indent : ''}${pad(line, maxLength)} |`).join('\n');
}
return node.value;
}
function pad(text, len) {
while (text.length < len) {
text += ' ';
}
return text;
}
const reNl$1 = /\n|\r/;
const secondaryAttrs = {
none: '[ SECONDARY_ATTRS]',
round: '[(SECONDARY_ATTRS)]',
curly: '[{SECONDARY_ATTRS}]',
square: '[[SECONDARY_ATTRS]'
};
/**
* Renders given parsed Emmet abbreviation as Slim, formatted according to
* `profile` options
* @param {Node} tree Parsed Emmet abbreviation
* @param {Profile} profile Output profile
* @param {Object} [options] Additional formatter options
* @return {String}
*/
function slim(tree, profile, options) {
options = options || {};
const SECONDARY_ATTRS = options.attributeWrap && secondaryAttrs[options.attributeWrap] || secondaryAttrs.none;
const booleanAttr = SECONDARY_ATTRS === secondaryAttrs.none ? attr => `${attr.name}=true` : attr => attr.name;
const nodeOptions = {
open: `[NAME][PRIMARY_ATTRS]${SECONDARY_ATTRS}[SELF_CLOSE]`,
selfClose: '/',
attributes: {
secondary(attrs) {
return attrs.map(attr => attr.isBoolean ? booleanAttr(attr) : `${attr.name}=${profile.quote(attr.value)}`).join(' ');
}
}
};
return output_renderer_es(tree, options.field, outNode => {
outNode = indentFormat(outNode, profile, nodeOptions);
outNode = updateFormatting$1(outNode, profile);
if (!handlePseudoSnippet(outNode)) {
const node = outNode.node;
// Do not generate fields for nodes with empty value and children
// or if node is self-closed
if (node.value || !node.children.length && !node.selfClosing) {
outNode.text = outNode.renderFields(formatNodeValue$1(node, profile));
}
}
return outNode;
});
}
/**
* Updates formatting properties for given output node
* NB Unlike HTML, Slim is indent-based format so some formatting options from
* `profile` will not take effect, otherwise output will be broken
* @param {OutputNode} outNode Output wrapper of farsed abbreviation node
* @param {Profile} profile Output profile
* @return {OutputNode}
*/
function updateFormatting$1(outNode, profile) {
const node = outNode.node;
const parent = node.parent;
// Edge case: a single inline-level child inside node without text:
// allow it to be inlined
if (profile.get('inlineBreak') === 0 && isInline$1(node, profile) && !isRoot(parent) && parent.value == null && parent.children.length === 1) {
outNode.beforeOpen = ': ';
}
if (!node.isTextOnly && node.value) {
// node with text: put a space before single-line text
outNode.beforeText = reNl$1.test(node.value) ? outNode.newline + outNode.indent + profile.indent(1) : ' ';
}
return outNode;
}
/**
* Formats value of given node: for multiline text we should precede each
* line with `| ` with one-level deep indent
* @param {Node} node
* @param {Profile} profile
* @return {String|null}
*/
function formatNodeValue$1(node, profile) {
if (node.value != null && reNl$1.test(node.value)) {
const indent = profile.indent(1);
return markup_formatters_es_splitByLines(node.value).map((line, i) => `${indent}${i ? ' ' : '|'} ${line}`).join('\n');
}
return node.value;
}
/**
* Check if given node is inline-level
* @param {Node} node
* @param {Profile} profile
* @return {Boolean}
*/
function isInline$1(node, profile) {
return node && (node.isTextOnly || profile.isInline(node));
}
const reNl$2 = /\n|\r/;
/**
* Renders given parsed Emmet abbreviation as Pug, formatted according to
* `profile` options
* @param {Node} tree Parsed Emmet abbreviation
* @param {Profile} profile Output profile
* @param {Object} [options] Additional formatter options
* @return {String}
*/
function pug(tree, profile, options) {
options = options || {};
const nodeOptions = {
open: '[NAME][PRIMARY_ATTRS][(SECONDARY_ATTRS)]',
attributes: {
secondary(attrs) {
return attrs.map(attr => attr.isBoolean ? attr.name : `${attr.name}=${profile.quote(attr.value)}`).join(', ');
}
}
};
return output_renderer_es(tree, options.field, outNode => {
outNode = indentFormat(outNode, profile, nodeOptions);
outNode = updateFormatting$2(outNode, profile);
if (!handlePseudoSnippet(outNode)) {
const node = outNode.node;
// Do not generate fields for nodes with empty value and children
// or if node is self-closed
if (node.value || !node.children.length && !node.selfClosing) {
outNode.text = outNode.renderFields(formatNodeValue$2(node, profile));
}
}
return outNode;
});
}
/**
* Updates formatting properties for given output node
* NB Unlike HTML, Pug is indent-based format so some formatting options from
* `profile` will not take effect, otherwise output will be broken
* @param {OutputNode} outNode Output wrapper of parsed abbreviation node
* @param {Profile} profile Output profile
* @return {OutputNode}
*/
function updateFormatting$2(outNode, profile) {
const node = outNode.node;
if (!node.isTextOnly && node.value) {
// node with text: put a space before single-line text
outNode.beforeText = reNl$2.test(node.value) ? outNode.newline + outNode.indent + profile.indent(1) : ' ';
}
return outNode;
}
/**
* Formats value of given node: for multiline text we should precede each
* line with `| ` with one-level deep indent
* @param {Node} node
* @param {Profile} profile
* @return {String|null}
*/
function formatNodeValue$2(node, profile) {
if (node.value != null && reNl$2.test(node.value)) {
const indent = profile.indent(1);
return markup_formatters_es_splitByLines(node.value).map(line => `${indent}| ${line}`).join('\n');
}
return node.value;
}
const supportedSyntaxes = { html, haml, slim, pug };
/**
* Outputs given parsed abbreviation in specified syntax
* @param {Node} tree Parsed abbreviation tree
* @param {Profile} profile Output profile
* @param {String} [syntax] Output syntax. If not given, `html` syntax is used
* @param {Function} options.field A function to output field/tabstop for
* host editor. This function takes two arguments: `index` and `placeholder` and
* should return a string that represents tabstop in host editor. By default
* only a placeholder is returned
* @example
* {
* field(index, placeholder) {
* // return field in TextMate-style, e.g. ${1} or ${2:foo}
* return `\${${index}${placeholder ? ':' + placeholder : ''}}`;
* }
* }
* @return {String}
*/
function markup_formatters_es_index(tree, profile, syntax, options) {
if (typeof syntax === 'object') {
options = syntax;
syntax = null;
}
if (!supports(syntax)) {
// fallback to HTML if given syntax is not supported
syntax = 'html';
}
return supportedSyntaxes[syntax](tree, profile, options);
}
/**
* Check if given syntax is supported
* @param {String} syntax
* @return {Boolean}
*/
function supports(syntax) {
return !!syntax && syntax in supportedSyntaxes;
}
/* harmony default export */ var markup_formatters_es = (markup_formatters_es_index);
//# sourceMappingURL=markup-formatters.es.js.map
// CONCATENATED MODULE: ../node_modules/@emmetio/css-abbreviation/dist/css-abbreviation.es.js
/**
* A wrapper for holding CSS value
*/
let CSSValue = class CSSValue {
constructor() {
this.type = 'css-value';
this.value = [];
}
get size() {
return this.value.length;
}
add(value) {
this.value.push(value);
}
has(value) {
return this.value.indexOf(value) !== -1;
}
toString() {
return this.value.join(' ');
}
};
const css_abbreviation_es_HASH = 35; // #
const css_abbreviation_es_DOT = 46; // .
/**
* Consumes a color token from given string
* @param {StreamReader} stream
* @return {Color} Returns consumend color object, `undefined` otherwise
*/
function consumeColor(stream) {
// supported color variations:
// #abc → #aabbccc
// #0 → #000000
// #fff.5 → rgba(255, 255, 255, 0.5)
// #t → transparent
if (stream.peek() === css_abbreviation_es_HASH) {
stream.start = stream.pos;
stream.next();
stream.eat(116) /* t */ || stream.eatWhile(isHex);
const base = stream.current();
// a hex color can be followed by `.num` alpha value
stream.start = stream.pos;
if (stream.eat(css_abbreviation_es_DOT) && !stream.eatWhile(isNumber)) {
throw stream.error('Unexpected character for alpha value of color');
}
return new Color(base, stream.current());
}
}
let Color = class Color {
constructor(value, alpha) {
this.type = 'color';
this.raw = value;
this.alpha = Number(alpha != null && alpha !== '' ? alpha : 1);
value = value.slice(1); // remove #
let r = 0,
g = 0,
b = 0;
if (value === 't') {
this.alpha = 0;
} else {
switch (value.length) {
case 0:
break;
case 1:
r = g = b = value + value;
break;
case 2:
r = g = b = value;
break;
case 3:
r = value[0] + value[0];
g = value[1] + value[1];
b = value[2] + value[2];
break;
default:
value += value;
r = value.slice(0, 2);
g = value.slice(2, 4);
b = value.slice(4, 6);
}
}
this.r = parseInt(r, 16);
this.g = parseInt(g, 16);
this.b = parseInt(b, 16);
}
/**
* Output current color as hex value
* @param {Boolean} shor Produce short value (e.g. #fff instead of #ffffff), if possible
* @return {String}
*/
toHex(short) {
const fn = short && isShortHex(this.r) && isShortHex(this.g) && isShortHex(this.b) ? toShortHex : toHex;
return '#' + fn(this.r) + fn(this.g) + fn(this.b);
}
/**
* Output current color as `rgba?(...)` CSS color
* @return {String}
*/
toRGB() {
const values = [this.r, this.g, this.b];
if (this.alpha !== 1) {
values.push(this.alpha.toFixed(8).replace(/\.?0+$/, ''));
}
return `${values.length === 3 ? 'rgb' : 'rgba'}(${values.join(', ')})`;
}
toString(short) {
if (!this.r && !this.g && !this.b && !this.alpha) {
return 'transparent';
}
return this.alpha === 1 ? this.toHex(short) : this.toRGB();
}
};
/**
* Check if given code is a hex value (/0-9a-f/)
* @param {Number} code
* @return {Boolean}
*/
function isHex(code) {
return isNumber(code) || isAlpha(code, 65, 70); // A-F
}
function isShortHex(hex) {
return !(hex % 17);
}
function toShortHex(num) {
return (num >> 4).toString(16);
}
function toHex(num) {
return css_abbreviation_es_pad(num.toString(16), 2);
}
function css_abbreviation_es_pad(value, len) {
while (value.length < len) {
value = '0' + value;
}
return value;
}
/**
* @param {Number} code
* @return {Boolean}
*/
function isAlphaNumericWord(code) {
return isNumber(code) || isAlphaWord(code);
}
/**
* @param {Number} code
* @return {Boolean}
*/
function isAlphaWord(code) {
return code === 95 /* _ */ || isAlpha(code);
}
const PERCENT = 37; // %
const css_abbreviation_es_DOT$1 = 46; // .
const css_abbreviation_es_DASH = 45; // -
/**
* Consumes numeric CSS value (number with optional unit) from current stream,
* if possible
* @param {StreamReader} stream
* @return {NumericValue}
*/
function consumeNumericValue(stream) {
stream.start = stream.pos;
if (eatNumber(stream)) {
const num = stream.current();
stream.start = stream.pos;
// eat unit, which can be a % or alpha word
stream.eat(PERCENT) || stream.eatWhile(isAlphaWord);
return new NumericValue(num, stream.current());
}
}
/**
* A numeric CSS value with optional unit
*/
let NumericValue = class NumericValue {
constructor(value, unit) {
this.type = 'numeric';
this.value = Number(value);
this.unit = unit || '';
}
toString() {
return `${this.value}${this.unit}`;
}
};
/**
* Eats number value from given stream
* @param {StreamReader} stream
* @return {Boolean} Returns `true` if number was consumed
*/
function eatNumber(stream) {
const start = stream.pos;
const negative = stream.eat(css_abbreviation_es_DASH);
const afterNegative = stream.pos;
stream.eatWhile(isNumber);
const prevPos = stream.pos;
if (stream.eat(css_abbreviation_es_DOT$1) && !stream.eatWhile(isNumber)) {
// Number followed by a dot, but then no number
stream.pos = prevPos;
}
// Edge case: consumed dash only: not a number, bail-out
if (stream.pos === afterNegative) {
stream.pos = start;
}
return stream.pos !== start;
}
const css_abbreviation_es_DOLLAR = 36; // $
const DASH$1 = 45; // -
const AT = 64; // @
/**
* Consumes a keyword: either a variable (a word that starts with $ or @) or CSS
* keyword or shorthand
* @param {StreamReader} stream
* @param {Boolean} [short] Use short notation for consuming value.
* The difference between “short” and “full” notation is that first one uses
* alpha characters only and used for extracting keywords from abbreviation,
* while “full” notation also supports numbers and dashes
* @return {String} Consumed variable
*/
function consumeKeyword(stream, short) {
stream.start = stream.pos;
if (stream.eat(css_abbreviation_es_DOLLAR) || stream.eat(AT)) {
// SCSS or LESS variable
stream.eatWhile(isVariableName);
} else if (short) {
stream.eatWhile(isAlphaWord);
} else {
stream.eatWhile(isKeyword);
}
return stream.start !== stream.pos ? new Keyword(stream.current()) : null;
}
let Keyword = class Keyword {
constructor(value) {
this.type = 'keyword';
this.value = value;
}
toString() {
return this.value;
}
};
function isKeyword(code) {
return isAlphaNumericWord(code) || code === DASH$1;
}
function isVariableName(code) {
return code === 45 /* - */ || isAlphaNumericWord(code);
}
const css_abbreviation_es_opt = { throws: true };
/**
* Consumes 'single' or "double"-quoted string from given string, if possible
* @param {StreamReader} stream
* @return {String}
*/
function css_abbreviation_es_consumeQuoted(stream) {
if (eatQuoted(stream, css_abbreviation_es_opt)) {
return new QuotedString(stream.current());
}
}
let QuotedString = class QuotedString {
constructor(value) {
this.type = 'string';
this.value = value;
}
toString() {
return this.value;
}
};
const LBRACE = 40; // (
const RBRACE = 41; // )
const COMMA = 44; // ,
/**
* Consumes arguments from given string.
* Arguments are comma-separated list of CSS values inside round braces, e.g.
* `(1, a2, 'a3')`. Nested lists and quoted strings are supported
* @param {StreamReader} stream
* @return {Array} Array of arguments, `null` if arguments cannot be consumed
*/
function consumeArgumentList(stream) {
if (!stream.eat(LBRACE)) {
// not an argument list
return null;
}
let arg;
const argsList = [];
while (!stream.eof()) {
if (arg = consumeArgument(stream)) {
argsList.push(arg);
} else {
// didnt consumed argument, expect argument separator or end-of-arguments
stream.eatWhile(isWhiteSpace);
if (stream.eat(RBRACE)) {
// end of arguments list
break;
}
if (!stream.eat(COMMA)) {
throw stream.error('Expected , or )');
}
}
}
return argsList;
}
/**
* Consumes a single argument. An argument is a `CSSValue`, e.g. it could be
* a space-separated string of value
* @param {StreamReader} stream
* @return {CSSValue}
*/
function consumeArgument(stream) {
const result = new CSSValue();
let value;
while (!stream.eof()) {
stream.eatWhile(isWhiteSpace);
value = consumeNumericValue(stream) || consumeColor(stream) || css_abbreviation_es_consumeQuoted(stream) || consumeKeywordOrFunction(stream);
if (!value) {
break;
}
result.add(value);
}
return result.size ? result : null;
}
/**
* Consumes either function call like `foo()` or keyword like `foo`
* @param {StreamReader} stream
* @return {Keyword|FunctionCall}
*/
function consumeKeywordOrFunction(stream) {
const kw = consumeKeyword(stream);
if (kw) {
const args = consumeArgumentList(stream);
return args ? new FunctionCall(kw.toString(), args) : kw;
}
}
let FunctionCall = class FunctionCall {
/**
* @param {String} name Function name
* @param {Array} args Function arguments
*/
constructor(name, args) {
this.type = 'function';
this.name = name;
this.args = args || [];
}
toString() {
return `${this.name}(${this.args.join(', ')})`;
}
};
const css_abbreviation_es_EXCL = 33; // !
const DOLLAR$1 = 36; // $
const PLUS = 43; // +
const DASH$2 = 45; // -
const css_abbreviation_es_COLON = 58; // :
const AT$1 = 64; // @
/**
* Parses given Emmet CSS abbreviation and returns it as parsed Node tree
* @param {String} abbr
* @return {Node}
*/
function css_abbreviation_es_index(abbr) {
const root = new node_es();
const stream = new stream_reader_es(abbr);
while (!stream.eof()) {
let node = new node_es(consumeIdent(stream));
node.value = consumeValue(stream);
const args = consumeArgumentList(stream);
if (args) {
// technically, arguments in CSS are anonymous Emmet Node attributes,
// but since Emmet can support only one anonymous, `null`-name
// attribute (for good reasons), well use argument index as name
for (let i = 0; i < args.length; i++) {
node.setAttribute(String(i), args[i]);
}
}
// Consume `!important` modifier at the end of expression
if (stream.eat(css_abbreviation_es_EXCL)) {
node.value.add('!');
}
root.appendChild(node);
// CSS abbreviations cannot be nested, only listed
if (!stream.eat(PLUS)) {
break;
}
}
if (!stream.eof()) {
throw stream.error('Unexpected character');
}
return root;
}
/**
* Consumes CSS property identifier from given stream
* @param {StreamReader} stream
* @return {String}
*/
function consumeIdent(stream) {
stream.start = stream.pos;
stream.eatWhile(isIdentPrefix);
stream.eatWhile(css_abbreviation_es_isIdent);
return stream.start !== stream.pos ? stream.current() : null;
}
/**
* Consumes embedded value from Emmet CSS abbreviation stream
* @param {StreamReader} stream
* @return {CSSValue}
*/
function consumeValue(stream) {
const values = new CSSValue();
let value;
while (!stream.eof()) {
// use colon as value separator
stream.eat(css_abbreviation_es_COLON);
if (value = consumeNumericValue(stream) || consumeColor(stream)) {
// edge case: a dash after unit-less numeric value or color should
// be treated as value separator, not negative sign
if (!value.unit) {
stream.eat(DASH$2);
}
} else {
stream.eat(DASH$2);
value = consumeKeyword(stream, true);
}
if (!value) {
break;
}
values.add(value);
}
return values;
}
/**
* @param {Number} code
* @return {Boolean}
*/
function css_abbreviation_es_isIdent(code) {
return isAlphaWord(code);
}
/**
* @param {Number} code
* @return {Boolean}
*/
function isIdentPrefix(code) {
return code === AT$1 || code === DOLLAR$1 || code === css_abbreviation_es_EXCL;
}
/* harmony default export */ var css_abbreviation_es = (css_abbreviation_es_index);
// CONCATENATED MODULE: ../node_modules/@emmetio/expand-abbreviation/node_modules/@emmetio/css-snippets-resolver/dist/css-snippets-resolver.es.js
var css_snippets_resolver_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
const css_snippets_resolver_es_DASH = 45; // -
/**
* Calculates fuzzy match score of how close `abbr` matches given `string`.
* @param {String} abbr Abbreviation to score
* @param {String} string String to match
* @param {Number} [fuzziness] Fuzzy factor
* @return {Number} Match score
*/
function stringScore(abbr, string) {
abbr = abbr.toLowerCase();
string = string.toLowerCase();
if (abbr === string) {
return 1;
}
// a string MUST start with the same character as abbreviation
if (!string || abbr.charCodeAt(0) !== string.charCodeAt(0)) {
return 0;
}
const abbrLength = abbr.length;
const stringLength = string.length;
let i = 1,
j = 1,
score = stringLength;
let ch1, ch2, found, acronym;
while (i < abbrLength) {
ch1 = abbr.charCodeAt(i);
found = false;
acronym = false;
while (j < stringLength) {
ch2 = string.charCodeAt(j);
if (ch1 === ch2) {
found = true;
score += (stringLength - j) * (acronym ? 2 : 1);
break;
}
// add acronym bonus for exactly next match after unmatched `-`
acronym = ch2 === css_snippets_resolver_es_DASH;
j++;
}
if (!found) {
break;
}
i++;
}
return score && score * (i / abbrLength) / sum(stringLength);
}
/**
* Calculates sum of first `n` natural numbers, e.g. 1+2+3+...n
* @param {Number} n
* @return {Number}
*/
function sum(n) {
return n * (n + 1) / 2;
}
const reProperty = /^([a-z-]+)(?:\s*:\s*([^\n\r]+))?$/;
const css_snippets_resolver_es_DASH$1 = 45; // -
/**
* Creates a special structure for resolving CSS properties from plain CSS
* snippets.
* Almost all CSS snippets are aliases for real CSS properties with available
* value variants, optionally separated by `|`. Most values are keywords that
* can be fuzzy-resolved as well. Some CSS properties are shorthands for other,
* more specific properties, like `border` and `border-style`. For such cases
* keywords from more specific properties should be available in shorthands too.
* @param {Snippet[]} snippets
* @return {CSSSnippet[]}
*/
function cssSnippets(snippets) {
return nest(snippets.map(snippet => new CSSSnippet(snippet.key, snippet.value)));
}
let CSSSnippet = class CSSSnippet {
constructor(key, value) {
this.key = key;
this.value = value;
this.property = null;
// detect if given snippet is a property
const m = value && value.match(reProperty);
if (m) {
this.property = m[1];
this.value = m[2];
}
this.dependencies = [];
}
addDependency(dep) {
this.dependencies.push(dep);
}
get defaultValue() {
return this.value != null ? splitValue(this.value)[0] : null;
}
/**
* Returns list of unique keywords for current CSS snippet and its dependencies
* @return {String[]}
*/
keywords() {
const stack = [];
const keywords = new Set();
let i = 0,
item,
candidates;
if (this.property) {
// scan valid CSS-properties only
stack.push(this);
}
while (i < stack.length) {
// NB Keep items in stack instead of push/pop to avoid possible
// circular references
item = stack[i++];
if (item.value) {
candidates = splitValue(item.value).filter(css_snippets_resolver_es_isKeyword);
// extract possible keywords from snippet value
for (let j = 0; j < candidates.length; j++) {
keywords.add(candidates[j].trim());
}
// add dependencies into scan stack
for (let j = 0, deps = item.dependencies; j < deps.length; j++) {
if (stack.indexOf(deps[j]) === -1) {
stack.push(deps[j]);
}
}
}
}
return Array.from(keywords);
}
};
/**
* Nests more specific CSS properties into shorthand ones, e.g.
* background-position-x -> background-position -> background
* @param {CSSSnippet[]} snippets
* @return {CSSSnippet[]}
*/
function nest(snippets) {
snippets = snippets.sort(snippetsSort);
const stack = [];
// For sorted list of CSS properties, create dependency graph where each
// shorthand property contains its more specific one, e.g.
// background -> background-position -> background-position-x
for (let i = 0, cur, prev; i < snippets.length; i++) {
cur = snippets[i];
if (!cur.property) {
// not a CSS property, skip it
continue;
}
// Check if current property belongs to one from parent stack.
// Since `snippets` array is sorted, items are perfectly aligned
// from shorthands to more specific variants
while (stack.length) {
prev = stack[stack.length - 1];
if (cur.property.indexOf(prev.property) === 0 && cur.property.charCodeAt(prev.property.length) === css_snippets_resolver_es_DASH$1) {
prev.addDependency(cur);
stack.push(cur);
break;
}
stack.pop();
}
if (!stack.length) {
stack.push(cur);
}
}
return snippets;
}
/**
* A sorting function for array of snippets
* @param {CSSSnippet} a
* @param {CSSSnippet} b
* @return {Number}
*/
function snippetsSort(a, b) {
if (a.key === b.key) {
return 0;
}
return a.key < b.key ? -1 : 1;
}
/**
* Check if given string is a keyword candidate
* @param {String} str
* @return {Boolean}
*/
function css_snippets_resolver_es_isKeyword(str) {
return (/^\s*[\w-]+/.test(str)
);
}
function splitValue(value) {
return String(value).split('|');
}
const globalKeywords = ['auto', 'inherit', 'unset'];
const unitlessProperties = ['z-index', 'line-height', 'opacity', 'font-weight', 'zoom', 'flex', 'flex-grow', 'flex-shrink'];
const css_snippets_resolver_es_defaultOptions = {
intUnit: 'px',
floatUnit: 'em',
unitAliases: {
e: 'em',
p: '%',
x: 'ex',
r: 'rem'
},
fuzzySearchMinScore: 0
};
/**
* For every node in given `tree`, finds matching snippet from `registry` and
* updates node with snippet data.
*
* This resolver uses fuzzy matching for searching matched snippets and their
* keyword values.
*/
function css_snippets_resolver_es_index(tree, registry, options) {
options = css_snippets_resolver_es__extends({}, css_snippets_resolver_es_defaultOptions, options);
options.unitAliases = css_snippets_resolver_es__extends({}, css_snippets_resolver_es_defaultOptions.unitAliases, options && options.unitAliases);
const snippets = convertToCSSSnippets(registry);
tree.walk(node => css_snippets_resolver_es_resolveNode(node, snippets, options));
return tree;
}
function convertToCSSSnippets(registry) {
return cssSnippets(registry.all({ type: 'string' }));
}
/**
* Resolves given node: finds matched CSS snippets using fuzzy match and resolves
* keyword aliases from node value
* @param {Node} node
* @param {CSSSnippet[]} snippets
* @param {Object} options
* @return {Node}
*/
function css_snippets_resolver_es_resolveNode(node, snippets, options) {
if (options.property) {
// Resolve as value of given CSS property
return resolveAsPropertyValue(node, snippets.find(snippet => snippet.property === options.property), options);
}
const snippet = findBestMatch(node.name, snippets, 'key', options.fuzzySearchMinScore);
if (!snippet) {
// Edge case: `!important` snippet
return node.name === '!' ? setNodeAsText(node, '!important') : node;
}
return snippet.property ? resolveAsProperty(node, snippet, options) : resolveAsSnippet(node, snippet);
}
/**
* Resolves given parsed abbreviation node as CSS property
* @param {Node} node
* @param {CSSSnippet} snippet
* @param {Object} formatOptions
* @return {Node}
*/
function resolveAsProperty(node, snippet, formatOptions) {
const abbr = node.name;
node.name = snippet.property;
if (node.value && typeof node.value === 'object') {
// resolve keyword shortcuts
const keywords = snippet.keywords();
if (!node.value.size) {
// no value defined, try to resolve unmatched part as a keyword alias
let kw = findBestMatch(getUnmatchedPart(abbr, snippet.key), keywords);
if (!kw) {
// no matching value, try to get default one
kw = snippet.defaultValue;
if (kw && kw.indexOf('${') === -1) {
// Quick and dirty test for existing field. If not, wrap
// default value in a field
kw = `\${1:${kw}}`;
}
}
if (kw) {
node.value.add(kw);
}
} else {
// replace keyword aliases in current node value
for (let i = 0, token; i < node.value.value.length; i++) {
token = node.value.value[i];
if (token === '!') {
token = `${!i ? '${1} ' : ''}!important`;
} else if (isKeyword$1(token)) {
token = findBestMatch(token.value, keywords) || findBestMatch(token.value, globalKeywords) || token;
} else if (isNumericValue(token)) {
token = resolveNumericValue(node.name, token, formatOptions);
}
node.value.value[i] = token;
}
}
}
return node;
}
/**
* Resolves given parsed abbreviation node as a snippet: a plain code chunk
* @param {Node} node
* @param {CSSSnippet} snippet
* @return {Node}
*/
function resolveAsSnippet(node, snippet) {
return setNodeAsText(node, snippet.value);
}
/**
* Resolves given parsed abbreviation node as property value of given `snippet`:
* tries to find best matching keyword from CSS snippet
* @param {Node} node
* @param {CSSSnippet} snippet
* @param {Object} options
* @return {Node}
*/
function resolveAsPropertyValue(node, snippet, options) {
// Possible resolved result for CSS property:
// * matched snippet keyword
// * color (starts with #)
// Everything else should result the same as input abbreviation
let keywords = globalKeywords.slice();
if (snippet) {
keywords = keywords.concat(snippet.keywords());
}
const values = [node.name].concat(node.value.value).filter(Boolean).map(value => {
if (typeof value === 'string' || value.type === 'keyword') {
value = String(value);
return findBestMatch(value, keywords, null, options.fuzzySearchMinScore) || value;
}
return value;
});
node.name = null;
node.value.value = values;
return node;
}
/**
* Sets given parsed abbreviation node as a text snippet
* @param {Node} node
* @param {String} text
* @return {Node}
*/
function setNodeAsText(node, text) {
node.name = null;
node.value = text;
return node;
}
/**
* Finds best matching item from `items` array
* @param {String} abbr Abbreviation to match
* @param {Array} items List of items for match
* @param {String} [key] If `items` is a list of objects, use `key` as object
* property to test against
* @param {Number} fuzzySearchMinScore The minimum score the best matched item should have to be a valid match.
* @return {*}
*/
function findBestMatch(abbr, items, key, fuzzySearchMinScore) {
if (!abbr) {
return null;
}
let matchedItem = null;
let maxScore = 0;
fuzzySearchMinScore = fuzzySearchMinScore || 0;
for (let i = 0, item; i < items.length; i++) {
item = items[i];
const score = stringScore(abbr, getScoringPart(item, key));
if (score === 1) {
// direct hit, no need to look further
return item;
}
if (score && score >= maxScore) {
maxScore = score;
matchedItem = item;
}
}
return maxScore >= fuzzySearchMinScore ? matchedItem : null;
}
function getScoringPart(item, key) {
const value = item && typeof item === 'object' ? item[key] : item;
const m = (value || '').match(/^[\w-@]+/);
return m ? m[0] : value;
}
/**
* Returns a part of `abbr` that wasnt directly matched agains `string`.
* For example, if abbreviation `poas` is matched against `position`, the unmatched part will be `as`
* since `a` wasnt found in string stream
* @param {String} abbr
* @param {String} string
* @return {String}
*/
function getUnmatchedPart(abbr, string) {
for (let i = 0, lastPos = 0; i < abbr.length; i++) {
lastPos = string.indexOf(abbr[i], lastPos);
if (lastPos === -1) {
return abbr.slice(i);
}
lastPos++;
}
return '';
}
/**
* Check if given CSS value token is a keyword
* @param {*} token
* @return {Boolean}
*/
function isKeyword$1(token) {
return tokenTypeOf(token, 'keyword');
}
/**
* Check if given CSS value token is a numeric value
* @param {*} token
* @return {Boolean}
*/
function isNumericValue(token) {
return tokenTypeOf(token, 'numeric');
}
function tokenTypeOf(token, type) {
return token && typeof token === 'object' && token.type === type;
}
/**
* Resolves numeric value for given CSS property
* @param {String} property CSS property name
* @param {NumericValue} token CSS numeric value token
* @param {Object} formatOptions Formatting options for units
* @return {NumericValue}
*/
function resolveNumericValue(property, token, formatOptions) {
if (token.unit) {
token.unit = formatOptions.unitAliases[token.unit] || token.unit;
} else if (token.value !== 0 && unitlessProperties.indexOf(property) === -1) {
// use `px` for integers, `em` for floats
// NB: num|0 is a quick alternative to Math.round(0)
token.unit = token.value === (token.value | 0) ? formatOptions.intUnit : formatOptions.floatUnit;
}
return token;
}
/* harmony default export */ var css_snippets_resolver_es = (css_snippets_resolver_es_index);
//# sourceMappingURL=css-snippets-resolver.es.js.map
// CONCATENATED MODULE: ../node_modules/@emmetio/stylesheet-formatters/dist/stylesheet-formatters.es.js
var stylesheet_formatters_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
const defaultFormatOptions = {
shortHex: true,
between: ': ',
after: ';'
};
/**
* Renders given parsed Emmet CSS abbreviation as CSS-like
* stylesheet, formatted according to `profile` options
* @param {Node} tree Parsed Emmet abbreviation
* @param {Profile} profile Output profile
* @param {Object} [options] Additional formatter options
* @return {String}
*/
function css(tree, profile, options) {
options = options || {};
const formatOpt = stylesheet_formatters_es__extends({}, defaultFormatOptions, options && options.format);
return output_renderer_es(tree, options.field, outNode => {
const node = outNode.node;
let value = stringifyValue(node, formatOpt);
if (node.attributes.length) {
const fieldValues = node.attributes.map(attr => stringifyValue(attr, formatOpt));
value = injectFields(value, fieldValues);
}
outNode.open = node.name && profile.name(node.name);
outNode.afterOpen = formatOpt.between;
outNode.text = outNode.renderFields(value || null);
if (outNode.open && (!outNode.text || !outNode.text.endsWith(';'))) {
outNode.afterText = formatOpt.after;
}
if (profile.get('format')) {
outNode.newline = '\n';
if (tree.lastChild !== node) {
outNode.afterText += outNode.newline;
}
}
return outNode;
});
}
/**
* Injects given field values at each field of given string
* @param {String} string
* @param {String[]} attributes
* @return {FieldString}
*/
function injectFields(string, values) {
const fieldsModel = field_parser_es(string);
const fieldsAmount = fieldsModel.fields.length;
if (fieldsAmount) {
values = values.slice();
if (values.length > fieldsAmount) {
// More values that output fields: collapse rest values into
// a single token
values = values.slice(0, fieldsAmount - 1).concat(values.slice(fieldsAmount - 1).join(', '));
}
while (values.length) {
const value = values.shift();
const field = fieldsModel.fields.shift();
const delta = value.length - field.length;
fieldsModel.string = fieldsModel.string.slice(0, field.location) + value + fieldsModel.string.slice(field.location + field.length);
// Update location of the rest fields in string
for (let i = 0, il = fieldsModel.fields.length; i < il; i++) {
fieldsModel.fields[i].location += delta;
}
}
}
return fieldsModel;
}
function stringifyValue(node, options) {
if (node.value && typeof node.value === 'object' && node.value.type === 'css-value') {
return node.value.value.map(token => {
if (token && typeof token === 'object') {
return token.type === 'color' ? token.toString(options.shortHex) : token.toString();
}
return String(token);
}).join(' ');
}
return node.value != null ? String(node.value) : '';
}
const syntaxFormat = {
css: {
between: ': ',
after: ';'
},
scss: 'css',
less: 'css',
sass: {
between: ': ',
after: ''
},
stylus: {
between: ' ',
after: ''
}
};
/**
* Outputs given parsed abbreviation in specified stylesheet syntax
* @param {Node} tree Parsed abbreviation tree
* @param {Profile} profile Output profile
* @param {String} [syntax] Output syntax. If not given, `css` syntax is used
* @param {Function} options.field A function to output field/tabstop for
* host editor. This function takes two arguments: `index` and `placeholder` and
* should return a string that represents tabstop in host editor. By default
* only a placeholder is returned
* @example
* {
* field(index, placeholder) {
* // return field in TextMate-style, e.g. ${1} or ${2:foo}
* return `\${${index}${placeholder ? ':' + placeholder : ''}}`;
* }
* }
* @return {String}
*/
function stylesheet_formatters_es_index(tree, profile, syntax, options) {
if (typeof syntax === 'object') {
options = syntax;
syntax = null;
}
if (!stylesheet_formatters_es_supports(syntax)) {
// fallback to CSS if given syntax is not supported
syntax = 'css';
}
options = stylesheet_formatters_es__extends({}, options, {
format: getFormat(syntax, options)
});
// CSS abbreviations doesnt support nesting so simply
// output root node children
return css(tree, profile, options);
}
/**
* Check if given syntax is supported
* @param {String} syntax
* @return {Boolean}
*/
function stylesheet_formatters_es_supports(syntax) {
return !!syntax && syntax in syntaxFormat;
}
/**
* Returns formatter object for given syntax
* @param {String} syntax
* @param {Object} [options]
* @return {Object} Formatter object as defined in `syntaxFormat`
*/
function getFormat(syntax, options) {
let format = syntaxFormat[syntax];
if (typeof format === 'string') {
format = syntaxFormat[format];
}
return stylesheet_formatters_es__extends({}, format, options && options.format);
}
/* harmony default export */ var stylesheet_formatters_es = (stylesheet_formatters_es_index);
//# sourceMappingURL=stylesheet-formatters.es.js.map
// CONCATENATED MODULE: ../node_modules/@emmetio/snippets/dist/snippets.es.js
var snippets_es_html = {
"a": "a[href]",
"a:link": "a[href='http://${0}']",
"a:mail": "a[href='mailto:${0}']",
"a:tel": "a[href='tel:+${0}']",
"abbr": "abbr[title]",
"acr|acronym": "acronym[title]",
"base": "base[href]/",
"basefont": "basefont/",
"br": "br/",
"frame": "frame/",
"hr": "hr/",
"bdo": "bdo[dir]",
"bdo:r": "bdo[dir=rtl]",
"bdo:l": "bdo[dir=ltr]",
"col": "col/",
"link": "link[rel=stylesheet href]/",
"link:css": "link[href='${1:style}.css']",
"link:print": "link[href='${1:print}.css' media=print]",
"link:favicon": "link[rel='shortcut icon' type=image/x-icon href='${1:favicon.ico}']",
"link:touch": "link[rel=apple-touch-icon href='${1:favicon.png}']",
"link:rss": "link[rel=alternate type=application/rss+xml title=RSS href='${1:rss.xml}']",
"link:atom": "link[rel=alternate type=application/atom+xml title=Atom href='${1:atom.xml}']",
"link:im|link:import": "link[rel=import href='${1:component}.html']",
"meta": "meta/",
"meta:utf": "meta[http-equiv=Content-Type content='text/html;charset=UTF-8']",
"meta:vp": "meta[name=viewport content='width=${1:device-width}, initial-scale=${2:1.0}']",
"meta:compat": "meta[http-equiv=X-UA-Compatible content='${1:IE=7}']",
"meta:edge": "meta:compat[content='${1:ie=edge}']",
"meta:redirect": "meta[http-equiv=refresh content='0; url=${1:http://example.com}']",
"style": "style",
"script": "script[!src]",
"script:src": "script[src]",
"img": "img[src alt]/",
"img:s|img:srcset": "img[srcset src alt]",
"img:z|img:sizes": "img[sizes srcset src alt]",
"picture": "picture",
"src|source": "source/",
"src:sc|source:src": "source[src type]",
"src:s|source:srcset": "source[srcset]",
"src:t|source:type": "source[srcset type='${1:image/}']",
"src:z|source:sizes": "source[sizes srcset]",
"src:m|source:media": "source[media='(${1:min-width: })' srcset]",
"src:mt|source:media:type": "source:media[type='${2:image/}']",
"src:mz|source:media:sizes": "source:media[sizes srcset]",
"src:zt|source:sizes:type": "source[sizes srcset type='${1:image/}']",
"iframe": "iframe[src frameborder=0]",
"embed": "embed[src type]/",
"object": "object[data type]",
"param": "param[name value]/",
"map": "map[name]",
"area": "area[shape coords href alt]/",
"area:d": "area[shape=default]",
"area:c": "area[shape=circle]",
"area:r": "area[shape=rect]",
"area:p": "area[shape=poly]",
"form": "form[action]",
"form:get": "form[method=get]",
"form:post": "form[method=post]",
"label": "label[for]",
"input": "input[type=${1:text}]/",
"inp": "input[name=${1} id=${1}]",
"input:h|input:hidden": "input[type=hidden name]",
"input:t|input:text": "inp[type=text]",
"input:search": "inp[type=search]",
"input:email": "inp[type=email]",
"input:url": "inp[type=url]",
"input:p|input:password": "inp[type=password]",
"input:datetime": "inp[type=datetime]",
"input:date": "inp[type=date]",
"input:datetime-local": "inp[type=datetime-local]",
"input:month": "inp[type=month]",
"input:week": "inp[type=week]",
"input:time": "inp[type=time]",
"input:tel": "inp[type=tel]",
"input:number": "inp[type=number]",
"input:color": "inp[type=color]",
"input:c|input:checkbox": "inp[type=checkbox]",
"input:r|input:radio": "inp[type=radio]",
"input:range": "inp[type=range]",
"input:f|input:file": "inp[type=file]",
"input:s|input:submit": "input[type=submit value]",
"input:i|input:image": "input[type=image src alt]",
"input:b|input:button": "input[type=button value]",
"input:reset": "input:button[type=reset]",
"isindex": "isindex/",
"select": "select[name=${1} id=${1}]",
"select:d|select:disabled": "select[disabled.]",
"opt|option": "option[value]",
"textarea": "textarea[name=${1} id=${1} cols=${2:30} rows=${3:10}]",
"marquee": "marquee[behavior direction]",
"menu:c|menu:context": "menu[type=context]",
"menu:t|menu:toolbar": "menu[type=toolbar]",
"video": "video[src]",
"audio": "audio[src]",
"html:xml": "html[xmlns=http://www.w3.org/1999/xhtml]",
"keygen": "keygen/",
"command": "command/",
"btn:s|button:s|button:submit": "button[type=submit]",
"btn:r|button:r|button:reset": "button[type=reset]",
"btn:d|button:d|button:disabled": "button[disabled.]",
"fst:d|fset:d|fieldset:d|fieldset:disabled": "fieldset[disabled.]",
"bq": "blockquote",
"fig": "figure",
"figc": "figcaption",
"pic": "picture",
"ifr": "iframe",
"emb": "embed",
"obj": "object",
"cap": "caption",
"colg": "colgroup",
"fst": "fieldset",
"btn": "button",
"optg": "optgroup",
"tarea": "textarea",
"leg": "legend",
"sect": "section",
"art": "article",
"hdr": "header",
"ftr": "footer",
"adr": "address",
"dlg": "dialog",
"str": "strong",
"prog": "progress",
"mn": "main",
"tem": "template",
"fset": "fieldset",
"datag": "datagrid",
"datal": "datalist",
"kg": "keygen",
"out": "output",
"det": "details",
"cmd": "command",
"ri:d|ri:dpr": "img:s",
"ri:v|ri:viewport": "img:z",
"ri:a|ri:art": "pic>src:m+img",
"ri:t|ri:type": "pic>src:t+img",
"!!!": "{<!DOCTYPE html>}",
"doc": "html[lang=${lang}]>(head>meta[charset=${charset}]+meta:vp+meta:edge+title{${1:Document}})+body",
"!|html:5": "!!!+doc",
"c": "{<!-- ${0} -->}",
"cc:ie": "{<!--[if IE]>${0}<![endif]-->}",
"cc:noie": "{<!--[if !IE]><!-->${0}<!--<![endif]-->}"
};
var snippets_es_css = {
"@f": "@font-face {\n\tfont-family: ${1};\n\tsrc: url(${1});\n}",
"@ff": "@font-face {\n\tfont-family: '${1:FontName}';\n\tsrc: url('${2:FileName}.eot');\n\tsrc: url('${2:FileName}.eot?#iefix') format('embedded-opentype'),\n\t\t url('${2:FileName}.woff') format('woff'),\n\t\t url('${2:FileName}.ttf') format('truetype'),\n\t\t url('${2:FileName}.svg#${1:FontName}') format('svg');\n\tfont-style: ${3:normal};\n\tfont-weight: ${4:normal};\n}",
"@i|@import": "@import url(${0});",
"@kf": "@keyframes ${1:identifier} {\n\t${2}\n}",
"@m|@media": "@media ${1:screen} {\n\t${0}\n}",
"ac": "align-content:flex-start|flex-end|center|space-between|space-around|stretch",
"ai": "align-items:flex-start|flex-end|center|baseline|stretch",
"anim": "animation:${1:name} ${2:duration} ${3:timing-function} ${4:delay} ${5:iteration-count} ${6:direction} ${7:fill-mode}",
"animdel": "animation-delay:${1:time}",
"animdir": "animation-direction:normal|reverse|alternate|alternate-reverse",
"animdur": "animation-duration:${1:0}s",
"animfm": "animation-fill-mode:both|forwards|backwards",
"animic": "animation-iteration-count:1|infinite",
"animn": "animation-name",
"animps": "animation-play-state:running|paused",
"animtf": "animation-timing-function:linear|ease|ease-in|ease-out|ease-in-out|cubic-bezier(${1:0.1}, ${2:0.7}, ${3:1.0}, ${3:0.1})",
"ap": "appearance:none",
"as": "align-self:auto|flex-start|flex-end|center|baseline|stretch",
"b": "bottom",
"bd": "border:${1:1px} ${2:solid} ${3:#000}",
"bdb": "border-bottom:${1:1px} ${2:solid} ${3:#000}",
"bdbc": "border-bottom-color:#${1:000}",
"bdbi": "border-bottom-image:url(${0})",
"bdbk": "border-break:close",
"bdbli": "border-bottom-left-image:url(${0})|continue",
"bdblrs": "border-bottom-left-radius",
"bdbri": "border-bottom-right-image:url(${0})|continue",
"bdbrrs": "border-bottom-right-radius",
"bdbs": "border-bottom-style",
"bdbw": "border-bottom-width",
"bdc": "border-color:#${1:000}",
"bdci": "border-corner-image:url(${0})|continue",
"bdcl": "border-collapse:collapse|separate",
"bdf": "border-fit:repeat|clip|scale|stretch|overwrite|overflow|space",
"bdi": "border-image:url(${0})",
"bdl": "border-left:${1:1px} ${2:solid} ${3:#000}",
"bdlc": "border-left-color:#${1:000}",
"bdlen": "border-length",
"bdli": "border-left-image:url(${0})",
"bdls": "border-left-style",
"bdlw": "border-left-width",
"bdr": "border-right:${1:1px} ${2:solid} ${3:#000}",
"bdrc": "border-right-color:#${1:000}",
"bdri": "border-right-image:url(${0})",
"bdrs": "border-radius",
"bdrst": "border-right-style",
"bdrw": "border-right-width",
"bds": "border-style:none|hidden|dotted|dashed|solid|double|dot-dash|dot-dot-dash|wave|groove|ridge|inset|outset",
"bdsp": "border-spacing",
"bdt": "border-top:${1:1px} ${2:solid} ${3:#000}",
"bdtc": "border-top-color:#${1:000}",
"bdti": "border-top-image:url(${0})",
"bdtli": "border-top-left-image:url(${0})|continue",
"bdtlrs": "border-top-left-radius",
"bdtri": "border-top-right-image:url(${0})|continue",
"bdtrrs": "border-top-right-radius",
"bdts": "border-top-style",
"bdtw": "border-top-width",
"bdw": "border-width",
"bfv": "backface-visibility:hidden|visible",
"bg": "background:#${1:000}",
"bga": "background-attachment:fixed|scroll",
"bgbk": "background-break:bounding-box|each-box|continuous",
"bgc": "background-color:#${1:fff}",
"bgcp": "background-clip:padding-box|border-box|content-box|no-clip",
"bgi": "background-image:url(${0})",
"bgo": "background-origin:padding-box|border-box|content-box",
"bgp": "background-position:${1:0} ${2:0}",
"bgpx": "background-position-x",
"bgpy": "background-position-y",
"bgr": "background-repeat:no-repeat|repeat-x|repeat-y|space|round",
"bgsz": "background-size:contain|cover",
"bxsh": "box-shadow:${1:inset }${2:hoff} ${3:voff} ${4:blur} #${5:000}|none",
"bxsz": "box-sizing:border-box|content-box|border-box",
"c": "color:#${1:000}",
"cl": "clear:both|left|right|none",
"cm": "/* ${0} */",
"cnt": "content:'${0}'|normal|open-quote|no-open-quote|close-quote|no-close-quote|attr(${0})|counter(${0})|counters({$0})",
"coi": "counter-increment",
"colm": "columns",
"colmc": "column-count",
"colmf": "column-fill",
"colmg": "column-gap",
"colmr": "column-rule",
"colmrc": "column-rule-color",
"colmrs": "column-rule-style",
"colmrw": "column-rule-width",
"colms": "column-span",
"colmw": "column-width",
"cor": "counter-reset",
"cp": "clip:auto|rect(${1:top} ${2:right} ${3:bottom} ${4:left})",
"cps": "caption-side:top|bottom",
"cur": "cursor:pointer|auto|default|crosshair|hand|help|move|pointer|text",
"d": "display:block|none|flex|inline-flex|inline|inline-block|list-item|run-in|compact|table|inline-table|table-caption|table-column|table-column-group|table-header-group|table-footer-group|table-row|table-row-group|table-cell|ruby|ruby-base|ruby-base-group|ruby-text|ruby-text-group",
"ec": "empty-cells:show|hide",
"f": "font:${1:1em} ${2:sans-serif}",
"fef": "font-effect:none|engrave|emboss|outline",
"fem": "font-emphasize",
"femp": "font-emphasize-position:before|after",
"fems": "font-emphasize-style:none|accent|dot|circle|disc",
"ff": "font-family:serif|sans-serif|cursive|fantasy|monospace",
"fl": "float:left|right|none",
"fs": "font-style:italic|normal|oblique",
"fsm": "font-smoothing:antialiased|subpixel-antialiased|none",
"fst": "font-stretch:normal|ultra-condensed|extra-condensed|condensed|semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded",
"fv": "font-variant:normal|small-caps",
"fw": "font-weight:normal|bold|bolder|lighter",
"fx": "flex",
"fxb": "flex-basis:fill|max-content|min-content|fit-content|content",
"fxd": "flex-direction:row|row-reverse|column|column-reverse",
"fxf": "flex-flow",
"fxg": "flex-grow",
"fxsh": "flex-shrink",
"fxw": "flex-wrap:nowrap|wrap|wrap-reverse",
"fz": "font-size",
"fza": "font-size-adjust",
"h": "height",
"jc": "justify-content:flex-start|flex-end|center|space-between|space-around",
"l": "left",
"lg": "background-image:linear-gradient(${1})",
"lh": "line-height",
"lis": "list-style",
"lisi": "list-style-image",
"lisp": "list-style-position:inside|outside",
"list": "list-style-type:disc|circle|square|decimal|decimal-leading-zero|lower-roman|upper-roman",
"lts": "letter-spacing:normal",
"m": "margin",
"mah": "max-height",
"mar": "max-resolution",
"maw": "max-width",
"mb": "margin-bottom",
"mih": "min-height",
"mir": "min-resolution",
"miw": "min-width",
"ml": "margin-left",
"mr": "margin-right",
"mt": "margin-top",
"ol": "outline",
"olc": "outline-color:#${1:000}|invert",
"olo": "outline-offset",
"ols": "outline-style:none|dotted|dashed|solid|double|groove|ridge|inset|outset",
"olw": "outline-width|thin|medium|thick",
"op": "opacity",
"ord": "order",
"ori": "orientation:landscape|portrait",
"orp": "orphans",
"ov": "overflow:hidden|visible|hidden|scroll|auto",
"ovs": "overflow-style:scrollbar|auto|scrollbar|panner|move|marquee",
"ovx": "overflow-x:hidden|visible|hidden|scroll|auto",
"ovy": "overflow-y:hidden|visible|hidden|scroll|auto",
"p": "padding",
"pb": "padding-bottom",
"pgba": "page-break-after:auto|always|left|right",
"pgbb": "page-break-before:auto|always|left|right",
"pgbi": "page-break-inside:auto|avoid",
"pl": "padding-left",
"pos": "position:relative|absolute|relative|fixed|static",
"pr": "padding-right",
"pt": "padding-top",
"q": "quotes",
"qen": "quotes:'\\201C' '\\201D' '\\2018' '\\2019'",
"qru": "quotes:'\\00AB' '\\00BB' '\\201E' '\\201C'",
"r": "right",
"rsz": "resize:none|both|horizontal|vertical",
"t": "top",
"ta": "text-align:left|center|right|justify",
"tal": "text-align-last:left|center|right",
"tbl": "table-layout:fixed",
"td": "text-decoration:none|underline|overline|line-through",
"te": "text-emphasis:none|accent|dot|circle|disc|before|after",
"th": "text-height:auto|font-size|text-size|max-size",
"ti": "text-indent",
"tj": "text-justify:auto|inter-word|inter-ideograph|inter-cluster|distribute|kashida|tibetan",
"to": "text-outline:${1:0} ${2:0} ${3:#000}",
"tov": "text-overflow:ellipsis|clip",
"tr": "text-replace",
"trf": "transform:${1}|skewX(${1:angle})|skewY(${1:angle})|scale(${1:x}, ${2:y})|scaleX(${1:x})|scaleY(${1:y})|scaleZ(${1:z})|scale3d(${1:x}, ${2:y}, ${3:z})|rotate(${1:angle})|rotateX(${1:angle})|rotateY(${1:angle})|rotateZ(${1:angle})|translate(${1:x}, ${2:y})|translateX(${1:x})|translateY(${1:y})|translateZ(${1:z})|translate3d(${1:tx}, ${2:ty}, ${3:tz})",
"trfo": "transform-origin",
"trfs": "transform-style:preserve-3d",
"trs": "transition:${1:prop} ${2:time}",
"trsde": "transition-delay:${1:time}",
"trsdu": "transition-duration:${1:time}",
"trsp": "transition-property:${1:prop}",
"trstf": "transition-timing-function:${1:fn}",
"tsh": "text-shadow:${1:hoff} ${2:voff} ${3:blur} ${4:#000}",
"tt": "text-transform:uppercase|lowercase|capitalize|none",
"tw": "text-wrap:none|normal|unrestricted|suppress",
"us": "user-select:none",
"v": "visibility:hidden|visible|collapse",
"va": "vertical-align:top|super|text-top|middle|baseline|bottom|text-bottom|sub",
"w": "width",
"whs": "white-space:nowrap|pre|pre-wrap|pre-line|normal",
"whsc": "white-space-collapse:normal|keep-all|loose|break-strict|break-all",
"wid": "widows",
"wm": "writing-mode:lr-tb|lr-tb|lr-bt|rl-tb|rl-bt|tb-rl|tb-lr|bt-lr|bt-rl",
"wob": "word-break:normal|keep-all|break-all",
"wos": "word-spacing",
"wow": "word-wrap:none|unrestricted|suppress|break-word|normal",
"z": "z-index",
"zom": "zoom:1"
};
var snippets_es_xsl = {
"tm|tmatch": "xsl:template[match mode]",
"tn|tname": "xsl:template[name]",
"call": "xsl:call-template[name]",
"ap": "xsl:apply-templates[select mode]",
"api": "xsl:apply-imports",
"imp": "xsl:import[href]",
"inc": "xsl:include[href]",
"ch": "xsl:choose",
"wh|xsl:when": "xsl:when[test]",
"ot": "xsl:otherwise",
"if": "xsl:if[test]",
"par": "xsl:param[name]",
"pare": "xsl:param[name select]",
"var": "xsl:variable[name]",
"vare": "xsl:variable[name select]",
"wp": "xsl:with-param[name select]",
"key": "xsl:key[name match use]",
"elem": "xsl:element[name]",
"attr": "xsl:attribute[name]",
"attrs": "xsl:attribute-set[name]",
"cp": "xsl:copy[select]",
"co": "xsl:copy-of[select]",
"val": "xsl:value-of[select]",
"for|each": "xsl:for-each[select]",
"tex": "xsl:text",
"com": "xsl:comment",
"msg": "xsl:message[terminate=no]",
"fall": "xsl:fallback",
"num": "xsl:number[value]",
"nam": "namespace-alias[stylesheet-prefix result-prefix]",
"pres": "xsl:preserve-space[elements]",
"strip": "xsl:strip-space[elements]",
"proc": "xsl:processing-instruction[name]",
"sort": "xsl:sort[select order]",
"choose": "xsl:choose>xsl:when+xsl:otherwise",
"xsl": "!!!+xsl:stylesheet[version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform]>{\n|}",
"!!!": "{<?xml version=\"1.0\" encoding=\"UTF-8\"?>}"
};
var snippets_es_index = { html: snippets_es_html, css: snippets_es_css, xsl: snippets_es_xsl };
/* harmony default export */ var snippets_es = (snippets_es_index);
// CONCATENATED MODULE: ../node_modules/@emmetio/lorem/dist/lorem.es.js
var lorem_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var latin = {
"common": ["lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipisicing", "elit"],
"words": ["exercitationem", "perferendis", "perspiciatis", "laborum", "eveniet", "sunt", "iure", "nam", "nobis", "eum", "cum", "officiis", "excepturi", "odio", "consectetur", "quasi", "aut", "quisquam", "vel", "eligendi", "itaque", "non", "odit", "tempore", "quaerat", "dignissimos", "facilis", "neque", "nihil", "expedita", "vitae", "vero", "ipsum", "nisi", "animi", "cumque", "pariatur", "velit", "modi", "natus", "iusto", "eaque", "sequi", "illo", "sed", "ex", "et", "voluptatibus", "tempora", "veritatis", "ratione", "assumenda", "incidunt", "nostrum", "placeat", "aliquid", "fuga", "provident", "praesentium", "rem", "necessitatibus", "suscipit", "adipisci", "quidem", "possimus", "voluptas", "debitis", "sint", "accusantium", "unde", "sapiente", "voluptate", "qui", "aspernatur", "laudantium", "soluta", "amet", "quo", "aliquam", "saepe", "culpa", "libero", "ipsa", "dicta", "reiciendis", "nesciunt", "doloribus", "autem", "impedit", "minima", "maiores", "repudiandae", "ipsam", "obcaecati", "ullam", "enim", "totam", "delectus", "ducimus", "quis", "voluptates", "dolores", "molestiae", "harum", "dolorem", "quia", "voluptatem", "molestias", "magni", "distinctio", "omnis", "illum", "dolorum", "voluptatum", "ea", "quas", "quam", "corporis", "quae", "blanditiis", "atque", "deserunt", "laboriosam", "earum", "consequuntur", "hic", "cupiditate", "quibusdam", "accusamus", "ut", "rerum", "error", "minus", "eius", "ab", "ad", "nemo", "fugit", "officia", "at", "in", "id", "quos", "reprehenderit", "numquam", "iste", "fugiat", "sit", "inventore", "beatae", "repellendus", "magnam", "recusandae", "quod", "explicabo", "doloremque", "aperiam", "consequatur", "asperiores", "commodi", "optio", "dolor", "labore", "temporibus", "repellat", "veniam", "architecto", "est", "esse", "mollitia", "nulla", "a", "similique", "eos", "alias", "dolore", "tenetur", "deleniti", "porro", "facere", "maxime", "corrupti"]
};
var ru = {
"common": ["далеко-далеко", "за", "словесными", "горами", "в стране", "гласных", "и согласных", "живут", "рыбные", "тексты"],
"words": ["вдали", "от всех", "они", "буквенных", "домах", "на берегу", "семантика", "большого", "языкового", "океана", "маленький", "ручеек", "даль", "журчит", "по всей", "обеспечивает", "ее", "всеми", "необходимыми", "правилами", "эта", "парадигматическая", "страна", "которой", "жаренные", "предложения", "залетают", "прямо", "рот", "даже", "всемогущая", "пунктуация", "не", "имеет", "власти", "над", "рыбными", "текстами", "ведущими", "безорфографичный", "образ", "жизни", "однажды", "одна", "маленькая", "строчка", "рыбного", "текста", "имени", "lorem", "ipsum", "решила", "выйти", "большой", "мир", "грамматики", "великий", "оксмокс", "предупреждал", "о", "злых", "запятых", "диких", "знаках", "вопроса", "коварных", "точках", "запятой", "но", "текст", "дал", "сбить", "себя", "толку", "он", "собрал", "семь", "своих", "заглавных", "букв", "подпоясал", "инициал", "за", "пояс", "пустился", "дорогу", "взобравшись", "первую", "вершину", "курсивных", "гор", "бросил", "последний", "взгляд", "назад", "силуэт", "своего", "родного", "города", "буквоград", "заголовок", "деревни", "алфавит", "подзаголовок", "своего", "переулка", "грустный", "реторический", "вопрос", "скатился", "его", "щеке", "продолжил", "свой", "путь", "дороге", "встретил", "рукопись", "она", "предупредила", "моей", "все", "переписывается", "несколько", "раз", "единственное", "что", "меня", "осталось", "это", "приставка", "возвращайся", "ты", "лучше", "свою", "безопасную", "страну", "послушавшись", "рукописи", "наш", "продолжил", "свой", "путь", "вскоре", "ему", "повстречался", "коварный", "составитель", "рекламных", "текстов", "напоивший", "языком", "речью", "заманивший", "свое", "агентство", "которое", "использовало", "снова", "снова", "своих", "проектах", "если", "переписали", "то", "живет", "там", "до", "сих", "пор"]
};
var sp = {
"common": ["mujer", "uno", "dolor", "más", "de", "poder", "mismo", "si"],
"words": ["ejercicio", "preferencia", "perspicacia", "laboral", "paño", "suntuoso", "molde", "namibia", "planeador", "mirar", "demás", "oficinista", "excepción", "odio", "consecuencia", "casi", "auto", "chicharra", "velo", "elixir", "ataque", "no", "odio", "temporal", "cuórum", "dignísimo", "facilismo", "letra", "nihilista", "expedición", "alma", "alveolar", "aparte", "león", "animal", "como", "paria", "belleza", "modo", "natividad", "justo", "ataque", "séquito", "pillo", "sed", "ex", "y", "voluminoso", "temporalidad", "verdades", "racional", "asunción", "incidente", "marejada", "placenta", "amanecer", "fuga", "previsor", "presentación", "lejos", "necesariamente", "sospechoso", "adiposidad", "quindío", "pócima", "voluble", "débito", "sintió", "accesorio", "falda", "sapiencia", "volutas", "queso", "permacultura", "laudo", "soluciones", "entero", "pan", "litro", "tonelada", "culpa", "libertario", "mosca", "dictado", "reincidente", "nascimiento", "dolor", "escolar", "impedimento", "mínima", "mayores", "repugnante", "dulce", "obcecado", "montaña", "enigma", "total", "deletéreo", "décima", "cábala", "fotografía", "dolores", "molesto", "olvido", "paciencia", "resiliencia", "voluntad", "molestias", "magnífico", "distinción", "ovni", "marejada", "cerro", "torre", "y", "abogada", "manantial", "corporal", "agua", "crepúsculo", "ataque", "desierto", "laboriosamente", "angustia", "afortunado", "alma", "encefalograma", "materialidad", "cosas", "o", "renuncia", "error", "menos", "conejo", "abadía", "analfabeto", "remo", "fugacidad", "oficio", "en", "almácigo", "vos", "pan", "represión", "números", "triste", "refugiado", "trote", "inventor", "corchea", "repelente", "magma", "recusado", "patrón", "explícito", "paloma", "síndrome", "inmune", "autoinmune", "comodidad", "ley", "vietnamita", "demonio", "tasmania", "repeler", "apéndice", "arquitecto", "columna", "yugo", "computador", "mula", "a", "propósito", "fantasía", "alias", "rayo", "tenedor", "deleznable", "ventana", "cara", "anemia", "corrupto"]
};
const langs = { latin, ru, sp };
const lorem_es_defaultOptions = {
wordCount: 30,
skipCommon: false,
lang: 'latin'
};
/**
* Replaces given parsed Emmet abbreviation node with nodes filled with
* Lorem Ipsum stub text.
* @param {Node} node
* @return {Node}
*/
var lorem_es_index = function (node, options) {
options = lorem_es__extends({}, lorem_es_defaultOptions, options);
const dict = langs[options.lang] || langs.latin;
const startWithCommon = !options.skipCommon && !isRepeating(node);
if (!node.repeat && !lorem_es_isRoot(node.parent)) {
// non-repeating element, insert text stub as a content of parent node
// and remove current one
node.parent.value = paragraph(dict, options.wordCount, startWithCommon);
node.remove();
} else {
// Replace named node with generated content
node.value = paragraph(dict, options.wordCount, startWithCommon);
node.name = node.parent.name ? implicit_tag_es(node.parent.name) : null;
}
return node;
};
function lorem_es_isRoot(node) {
return !node.parent;
}
/**
* Returns random integer between <code>from</code> and <code>to</code> values
* @param {Number} from
* @param {Number} to
* @returns {Number}
*/
function rand(from, to) {
return Math.floor(Math.random() * (to - from) + from);
}
/**
* @param {Array} arr
* @param {Number} count
* @returns {Array}
*/
function sample(arr, count) {
const len = arr.length;
const iterations = Math.min(len, count);
const result = new Set();
while (result.size < iterations) {
result.add(arr[rand(0, len)]);
}
return Array.from(result);
}
function choice(val) {
return val[rand(0, val.length - 1)];
}
function sentence(words, end) {
if (words.length) {
words = [capitalize(words[0])].concat(words.slice(1));
}
return words.join(' ') + (end || choice('?!...')); // more dots than question marks
}
function capitalize(word) {
return word[0].toUpperCase() + word.slice(1);
}
/**
* Insert commas at randomly selected words. This function modifies values
* inside <code>words</code> array
* @param {Array} words
*/
function insertCommas(words) {
if (words.length < 2) {
return words;
}
words = words.slice();
const len = words.length;
const hasComma = /,$/;
let totalCommas = 0;
if (len > 3 && len <= 6) {
totalCommas = rand(0, 1);
} else if (len > 6 && len <= 12) {
totalCommas = rand(0, 2);
} else {
totalCommas = rand(1, 4);
}
for (let i = 0, pos, word; i < totalCommas; i++) {
pos = rand(0, len - 2);
if (!hasComma.test(words[pos])) {
words[pos] += ',';
}
}
return words;
}
/**
* Generate a paragraph of "Lorem ipsum" text
* @param {Object} dict Words dictionary (see `lang/*.json`)
* @param {Number} wordCount Words count in paragraph
* @param {Boolean} startWithCommon Should paragraph start with common
* "lorem ipsum" sentence.
* @returns {String}
*/
function paragraph(dict, wordCount, startWithCommon) {
const result = [];
let totalWords = 0;
let words;
if (startWithCommon && dict.common) {
words = dict.common.slice(0, wordCount);
totalWords += words.length;
result.push(sentence(insertCommas(words), '.'));
}
while (totalWords < wordCount) {
words = sample(dict.words, Math.min(rand(2, 30), wordCount - totalWords));
totalWords += words.length;
result.push(sentence(insertCommas(words)));
}
return result.join(' ');
}
/**
* Check if given node is in repeating context, e.g. node itself or one of its
* parent is repeated
* @param {Node} node
* @return {Boolean}
*/
function isRepeating(node) {
while (node.parent) {
if (node.repeat && node.repeat.value && node.repeat.value > 1) {
return true;
}
node = node.parent;
}
return false;
}
/* harmony default export */ var lorem_es = (lorem_es_index);
// CONCATENATED MODULE: ../node_modules/@emmetio/snippets-registry/dist/snippets-registry.es.js
let Snippet = class Snippet {
constructor(key, value) {
this.key = key;
this.value = value;
}
};
let SnippetsStorage = class SnippetsStorage {
constructor(data) {
this._string = new Map();
this._regexp = new Map();
this._disabled = false;
this.load(data);
}
get disabled() {
return this._disabled;
}
/**
* Disables current store. A disabled store always returns `undefined`
* on `get()` method
*/
disable() {
this._disabled = true;
}
/**
* Enables current store.
*/
enable() {
this._disabled = false;
}
/**
* Registers a new snippet item
* @param {String|Regexp} key
* @param {String|Function} value
*/
set(key, value) {
if (typeof key === 'string') {
key.split('|').forEach(k => this._string.set(k, new Snippet(k, value)));
} else if (key instanceof RegExp) {
this._regexp.set(key, new Snippet(key, value));
} else {
throw new Error('Unknow snippet key: ' + key);
}
return this;
}
/**
* Returns a snippet matching given key. It first tries to find snippet
* exact match in a string key map, then tries to match one with regexp key
* @param {String} key
* @return {Snippet}
*/
get(key) {
if (this.disabled) {
return undefined;
}
if (this._string.has(key)) {
return this._string.get(key);
}
const keys = Array.from(this._regexp.keys());
for (let i = 0, il = keys.length; i < il; i++) {
if (keys[i].test(key)) {
return this._regexp.get(keys[i]);
}
}
}
/**
* Batch load of snippets data
* @param {Object|Map} data
*/
load(data) {
this.reset();
if (data instanceof Map) {
data.forEach((value, key) => this.set(key, value));
} else if (data && typeof data === 'object') {
Object.keys(data).forEach(key => this.set(key, data[key]));
}
}
/**
* Clears all stored snippets
*/
reset() {
this._string.clear();
this._regexp.clear();
}
/**
* Returns all available snippets from given store
*/
values() {
if (this.disabled) {
return [];
}
const string = Array.from(this._string.values());
const regexp = Array.from(this._regexp.values());
return string.concat(regexp);
}
};
/**
* A snippets registry. Contains snippets, separated by store and sorted by
* priority: a store with higher priority takes precedence when resolving snippet
* for given key
*/
let SnippetsRegistry = class SnippetsRegistry {
/**
* Creates snippets registry, filled with given `data`
* @param {Object|Array} data Registry snippets. If array is given, adds items
* from array in order of precedence, registers global snippets otherwise
*/
constructor(data) {
this._registry = [];
if (Array.isArray(data)) {
data.forEach((snippets, level) => this.add(level, snippets));
} else if (typeof data === 'object') {
this.add(data);
}
}
/**
* Return store for given level
* @param {Number} level
* @return {SnippetsStorage}
*/
get(level) {
for (let i = 0; i < this._registry.length; i++) {
const item = this._registry[i];
if (item.level === level) {
return item.store;
}
}
}
/**
* Adds new store for given level
* @param {Number} [level] Store level (priority). Store with higher level
* takes precedence when resolving snippets
* @param {Object} [snippets] A snippets data for new store
* @return {SnipetsStorage}
*/
add(level, snippets) {
if (level != null && typeof level === 'object') {
snippets = level;
level = 0;
}
const store = new SnippetsStorage(snippets);
// remove previous store from same level
this.remove(level);
this._registry.push({ level, store });
this._registry.sort((a, b) => b.level - a.level);
return store;
}
/**
* Remove registry with given level or store
* @param {Number|SnippetsStorage} data Either level or snippets store
*/
remove(data) {
this._registry = this._registry.filter(item => item.level !== data && item.store !== data);
}
/**
* Returns snippet from registry that matches given name
* @param {String} name
* @return {Snippet}
*/
resolve(name) {
for (let i = 0; i < this._registry.length; i++) {
const snippet = this._registry[i].store.get(name);
if (snippet) {
return snippet;
}
}
}
/**
* Returns all available snippets from current registry. Snippets with the
* same key are resolved by their storage priority.
* @param {Object} options
* @param {Object} options.type Return snippets only of given type: 'string'
* or 'regexp'. Returns all snippets if not defined
* @return {Array}
*/
all(options) {
options = options || {};
const result = new Map();
const fillResult = snippet => {
const type = snippet.key instanceof RegExp ? 'regexp' : 'string';
if ((!options.type || options.type === type) && !result.has(snippet.key)) {
result.set(snippet.key, snippet);
}
};
this._registry.forEach(item => {
item.store.values().forEach(fillResult);
});
return Array.from(result.values());
}
/**
* Removes all stores from registry
*/
clear() {
this._registry.length = 0;
}
};
/* harmony default export */ var snippets_registry_es = (SnippetsRegistry);
// CONCATENATED MODULE: ../node_modules/@emmetio/output-profile/dist/output-profile.es.js
var output_profile_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/**
* @type {EmmetOutputProfile}
*/
var output_profile_es_defaultOptions = {
indent: '\t',
tagCase: '',
attributeCase: '',
attributeQuotes: 'double',
format: true,
formatSkip: ['html'],
formatForce: ['body'],
inlineBreak: 3,
compactBooleanAttributes: false,
booleanAttributes: ['contenteditable', 'seamless', 'async', 'autofocus', 'autoplay', 'checked', 'controls', 'defer', 'disabled', 'formnovalidate', 'hidden', 'ismap', 'loop', 'multiple', 'muted', 'novalidate', 'readonly', 'required', 'reversed', 'selected', 'typemustmatch'],
selfClosingStyle: 'html',
inlineElements: ['a', 'abbr', 'acronym', 'applet', 'b', 'basefont', 'bdo', 'big', 'br', 'button', 'cite', 'code', 'del', 'dfn', 'em', 'font', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'map', 'object', 'q', 's', 'samp', 'select', 'small', 'span', 'strike', 'strong', 'sub', 'sup', 'textarea', 'tt', 'u', 'var']
};
/**
* Creates output profile for given options
*/
let Profile = class Profile {
/**
* @param {EmmetOutputProfile} options
*/
constructor(options) {
/** @type {EmmetOutputProfile} */
this.options = output_profile_es__extends({}, output_profile_es_defaultOptions, options);
this.quoteChar = this.options.attributeQuotes === 'single' ? '\'' : '"';
}
/**
* Returns value of given option name
* @param {String} name
* @return {*}
*/
get(name) {
return this.options[name];
}
/**
* Quote given string according to profile
* @param {String} str String to quote
* @return {String}
*/
quote(str) {
return `${this.quoteChar}${str != null ? str : ''}${this.quoteChar}`;
}
/**
* Output given tag name according to options
* @param {String} name
* @return {String}
*/
name(name) {
return strcase(name, this.options.tagCase);
}
/**
* Outputs attribute name according to current settings
* @param {String} attr Attribute name
* @return {String}
*/
attribute(attr) {
return strcase(attr, this.options.attributeCase);
}
/**
* Check if given attribute is boolean
* @param {Object} attr
* @return {Boolean}
*/
isBooleanAttribute(attr) {
return attr.options.boolean || this.get('booleanAttributes').indexOf((attr.name || '').toLowerCase()) !== -1;
}
/**
* Returns a token for self-closing tag, depending on current options
* @return {String}
*/
selfClose() {
switch (this.options.selfClosingStyle) {
case 'xhtml':
return ' /';
case 'xml':
return '/';
default:
return '';
}
}
/**
* Returns indent for given level
* @param {Number} level Indentation level
* @return {String}
*/
indent(level) {
level = level || 0;
let output = '';
while (level--) {
output += this.options.indent;
}
return output;
}
/**
* Check if given tag name belongs to inline-level element
* @param {Object|String} node Parsed node or tag name
* @return {Boolean}
*/
isInline(node) {
if (typeof node === 'string') {
return this.get('inlineElements').indexOf(node.toLowerCase()) !== -1;
}
// inline node is a node either with inline-level name or text-only node
return node.name != null ? this.isInline(node.name) : node.isTextOnly;
}
/**
* Outputs formatted field for given params
* @param {Number} index Field index
* @param {String} [placeholder] Field placeholder, can be empty
* @return {String}
*/
field(index, placeholder) {
return this.options.field(index, placeholder);
}
};
function strcase(string, type) {
if (type) {
return type === 'upper' ? string.toUpperCase() : string.toLowerCase();
}
return string;
}
/* harmony default export */ var output_profile_es = (Profile);
// CONCATENATED MODULE: ../node_modules/@emmetio/expand-abbreviation/dist/expand.es.js
var expand_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
/**
* Expands given abbreviation into code
* @param {String|Node} abbr Abbreviation to parse or already parsed abbreviation
* @param {Object} config
* @return {String}
*/
function expand(abbr, config) {
config = expand_es__extends({}, config);
if (typeof abbr === 'string') {
abbr = expand_es_parse(abbr, config);
}
return markup_formatters_es(abbr, config.profile, config.syntax, config);
}
/**
* Parses given Emmet abbreviation into a final abbreviation tree with all
* required transformations applied
* @param {String} Abbreviation to parse
* @param {Object} config
* @return {Node}
*/
function expand_es_parse(abbr, config) {
return abbreviation_es(abbr).use(html_snippets_resolver_es, config.snippets).use(variable_resolver_es, config.variables).use(html_transform_es, config.text, config.options);
}
/**
* Expands given abbreviation into code
* @param {String|Node} abbr Abbreviation to parse or already parsed abbreviation
* @param {Object} config
* @return {String}
*/
function expand$1(abbr, config) {
config = config || {};
if (typeof abbr === 'string') {
abbr = parse$1(abbr, config);
}
return stylesheet_formatters_es(abbr, config.profile, config.syntax, config);
}
/**
* Parses given Emmet abbreviation into a final abbreviation tree with all
* required transformations applied
* @param {String|Node} abbr Abbreviation to parse or already parsed abbreviation
* @param {Object} config
* @return {Node}
*/
function parse$1(abbr, config) {
if (typeof abbr === 'string') {
abbr = css_abbreviation_es(abbr);
}
return abbr.use(css_snippets_resolver_es, config.snippets, config.options);
}
const reLorem = /^lorem([a-z]*)(\d*)$/i;
/**
* Constructs a snippets registry, filled with snippets, for given options
* @param {String} syntax Abbreviation syntax
* @param {Object|Object[]} snippets Additional snippets
* @return {SnippetsRegistry}
*/
function snippetsRegistryFactory(type, syntax, snippets) {
const registrySnippets = [];
if (type === 'markup') {
registrySnippets.push(snippets_es.html);
} else if (type === 'stylesheet') {
registrySnippets.push(snippets_es.css);
}
if (syntax in snippets_es && registrySnippets.indexOf(snippets_es[syntax]) === -1) {
registrySnippets.push(snippets_es[syntax]);
}
if (Array.isArray(snippets)) {
snippets.forEach(item => {
// if array item is a string, treat it as a reference to globally
// defined snippets
registrySnippets.push(typeof item === 'string' ? snippets_es[item] : item);
});
} else if (typeof snippets === 'object') {
registrySnippets.push(snippets);
}
const registry = new snippets_registry_es(registrySnippets.filter(Boolean));
// for non-stylesheet syntaxes add Lorem Ipsum generator
if (type !== 'stylesheet') {
registry.get(0).set(reLorem, loremGenerator);
}
return registry;
}
function loremGenerator(node) {
const options = {};
const m = node.name.match(reLorem);
if (m[1]) {
options.lang = m[1];
}
if (m[2]) {
options.wordCount = +m[2];
}
return lorem_es(node, options);
}
/**
* Default variables used in snippets to insert common values into predefined snippets
* @type {Object}
*/
const defaultVariables = {
lang: 'en',
locale: 'en-US',
charset: 'UTF-8'
};
/**
* A list of syntaxes that should use Emmet CSS abbreviations:
* a variations of default abbreviation that holds values right in abbreviation name
* @type {Array}
*/
const stylesheetSyntaxes = ['css', 'sass', 'scss', 'less', 'stylus', 'sss'];
const expand_es_defaultOptions = {
/**
* Type of abbreviation to parse: 'markup' or 'stylesheet'.
* Can be auto-detected from `syntax` property. Default is 'markup'
*/
type: null,
/**
* Abbreviation output syntax
* @type {String}
*/
syntax: 'html',
/**
* Field/tabstop generator for editor. Most editors support TextMate-style
* fields: ${0} or ${1:item}. So for TextMate-style fields this function
* will look like this:
* @example
* (index, placeholder) => `\${${index}${placeholder ? ':' + placeholder : ''}}`
*
* @param {Number} index Placeholder index. Fields with the same indices
* should be linked
* @param {String} [placeholder] Field placeholder
* @return {String}
*/
field: (index, placeholder) => placeholder || '',
/**
* Insert given text string(s) into expanded abbreviation
* If array of strings is given, the implicitly repeated element (e.g. `li*`)
* will be repeated by the amount of items in array
* @type {String|String[]}
*/
text: null,
/**
* Either predefined output profile or options for output profile. Used for
* abbreviation output
* @type {Profile|Object}
*/
profile: null,
/**
* Custom variables for variable resolver
* @see @emmetio/variable-resolver
* @type {Object}
*/
variables: {},
/**
* Custom predefined snippets for abbreviation. The expanded abbreviation
* will try to match given snippets that may contain custom elements,
* predefined attributes etc.
* May also contain array of items: either snippets (Object) or references
* to default syntax snippets (String; the key in default snippets hash)
* @see @emmetio/snippets
* @type {Object|SnippetsRegistry}
*/
snippets: {},
/**
* Hash of additional transformations that should be applied to expanded
* abbreviation, like BEM or JSX. Since these transformations introduce
* side-effect, they are disabled by default and should be enabled by
* providing a transform name as a key and transform options as value:
* @example
* {
* bem: {element: '--'},
* jsx: true // no options, just enable transform
* }
* @see @emmetio/html-transform/lib/addons
* @type {Object}
*/
options: null,
/**
* Additional options for syntax formatter
* @see @emmetio/markup-formatters
* @type {Object}
*/
format: null
};
/**
* Expands given abbreviation into string, formatted according to provided
* syntax and options
* @param {String|Node} abbr Abbreviation string or parsed abbreviation tree
* @param {String|Object} [config] Parsing and formatting options (object) or
* abbreviation syntax (string)
* @return {String}
*/
function expand$2(abbr, config) {
config = createOptions(config);
return getType(config.type, config.syntax) === 'stylesheet' ? expand$1(abbr, config) : expand(abbr, config);
}
/**
* Parses given abbreviation into AST tree. This tree can be later formatted to
* string with `expand` function
* @param {String} abbr Abbreviation to parse
* @param {String|Object} [options] Parsing and formatting options (object) or
* abbreviation syntax (string)
* @return {Node}
*/
function parse$2(abbr, options) {
options = createOptions(options);
return getType(options.type, options.syntax) === 'stylesheet' ? parse$1(abbr, options) : expand_es_parse(abbr, options);
}
/**
* Creates snippets registry for given syntax and additional `snippets`
* @param {String} type Abbreviation type, 'markup' or 'stylesheet'
* @param {String} syntax Snippets syntax, used for retrieving predefined snippets
* @param {SnippetsRegistry|Object|Object[]} [snippets] Additional snippets
* @return {SnippetsRegistry}
*/
function createSnippetsRegistry(type, syntax, snippets) {
// Backward-compatibility with <0.6
if (type && type !== 'markup' && type !== 'stylesheet') {
snippets = syntax;
syntax = type;
type = 'markup';
}
return snippets instanceof snippets_registry_es ? snippets : snippetsRegistryFactory(type, syntax, snippets);
}
function createOptions(options) {
if (typeof options === 'string') {
options = { syntax: options };
}
options = expand_es__extends({}, expand_es_defaultOptions, options);
if (options.type == null && options.syntax) {
options.type = isStylesheet(options.syntax) ? 'stylesheet' : 'markup';
}
options.format = expand_es__extends({ field: options.field }, options.format);
options.profile = createProfile(options);
options.variables = expand_es__extends({}, defaultVariables, options.variables);
options.snippets = createSnippetsRegistry(options.type, options.syntax, options.snippets);
return options;
}
/**
* Check if given syntax belongs to stylesheet markup.
* Emmet uses different abbreviation flavours: one is a default markup syntax,
* used for HTML, Slim, Pug etc, the other one is used for stylesheets and
* allows embedded values in abbreviation name
* @param {String} syntax
* @return {Boolean}
*/
function isStylesheet(syntax) {
return stylesheetSyntaxes.indexOf(syntax) !== -1;
}
/**
* Creates output profile from given options
* @param {Object} options
* @return {Profile}
*/
function createProfile(options) {
return options.profile instanceof output_profile_es ? options.profile : new output_profile_es(options.profile);
}
/**
* Returns type of abbreviation expander: either 'markup' or 'stylesheet'
* @param {String} type
* @param {String} [syntax]
*/
function getType(type, syntax) {
if (type) {
return type === 'stylesheet' ? 'stylesheet' : 'markup';
}
return isStylesheet(syntax) ? 'stylesheet' : 'markup';
}
//# sourceMappingURL=expand.es.js.map
// CONCATENATED MODULE: ../node_modules/@emmetio/css-snippets-resolver/dist/css-snippets-resolver.es.js
var dist_css_snippets_resolver_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
const dist_css_snippets_resolver_es_DASH = 45; // -
/**
* Calculates fuzzy match score of how close `abbr` matches given `string`.
* @param {String} abbr Abbreviation to score
* @param {String} string String to match
* @param {Number} [fuzziness] Fuzzy factor
* @return {Number} Match score
*/
function css_snippets_resolver_es_stringScore(abbr, string) {
abbr = abbr.toLowerCase();
string = string.toLowerCase();
if (abbr === string) {
return 1;
}
// a string MUST start with the same character as abbreviation
if (!string || abbr.charCodeAt(0) !== string.charCodeAt(0)) {
return 0;
}
const abbrLength = abbr.length;
const stringLength = string.length;
let i = 1,
j = 1,
score = stringLength;
let ch1, ch2, found, acronym;
while (i < abbrLength) {
ch1 = abbr.charCodeAt(i);
found = false;
acronym = false;
while (j < stringLength) {
ch2 = string.charCodeAt(j);
if (ch1 === ch2) {
found = true;
score += (stringLength - j) * (acronym ? 2 : 1);
break;
}
// add acronym bonus for exactly next match after unmatched `-`
acronym = ch2 === dist_css_snippets_resolver_es_DASH;
j++;
}
if (!found) {
break;
}
i++;
}
return score && score * (i / abbrLength) / css_snippets_resolver_es_sum(stringLength);
}
/**
* Calculates sum of first `n` natural numbers, e.g. 1+2+3+...n
* @param {Number} n
* @return {Number}
*/
function css_snippets_resolver_es_sum(n) {
return n * (n + 1) / 2;
}
const css_snippets_resolver_es_reProperty = /^([a-z\-]+)(?:\s*:\s*([^\n\r]+))?$/;
const dist_css_snippets_resolver_es_DASH$1 = 45; // -
/**
* Creates a special structure for resolving CSS properties from plain CSS
* snippets.
* Almost all CSS snippets are aliases for real CSS properties with available
* value variants, optionally separated by `|`. Most values are keywords that
* can be fuzzy-resolved as well. Some CSS properties are shorthands for other,
* more specific properties, like `border` and `border-style`. For such cases
* keywords from more specific properties should be available in shorthands too.
* @param {Snippet[]} snippets
* @return {CSSSnippet[]}
*/
function css_snippets_resolver_es_cssSnippets(snippets) {
return css_snippets_resolver_es_nest(snippets.map(snippet => new css_snippets_resolver_es_CSSSnippet(snippet.key, snippet.value)));
}
let css_snippets_resolver_es_CSSSnippet = class CSSSnippet {
constructor(key, value) {
this.key = key;
this.value = value;
this.property = null;
// detect if given snippet is a property
const m = value && value.match(css_snippets_resolver_es_reProperty);
if (m) {
this.property = m[1];
this.value = m[2];
}
this.dependencies = [];
}
addDependency(dep) {
this.dependencies.push(dep);
}
get defaultValue() {
return this.value != null ? css_snippets_resolver_es_splitValue(this.value)[0] : null;
}
/**
* Returns list of unique keywords for current CSS snippet and its dependencies
* @return {String[]}
*/
keywords() {
const stack = [];
const keywords = new Set();
let i = 0,
item,
candidates;
if (this.property) {
// scan valid CSS-properties only
stack.push(this);
}
while (i < stack.length) {
// NB Keep items in stack instead of push/pop to avoid possible
// circular references
item = stack[i++];
if (item.value) {
candidates = css_snippets_resolver_es_splitValue(item.value).filter(dist_css_snippets_resolver_es_isKeyword);
// extract possible keywords from snippet value
for (let j = 0; j < candidates.length; j++) {
keywords.add(candidates[j].trim());
}
// add dependencies into scan stack
for (let j = 0, deps = item.dependencies; j < deps.length; j++) {
if (stack.indexOf(deps[j]) === -1) {
stack.push(deps[j]);
}
}
}
}
return Array.from(keywords);
}
};
/**
* Nests more specific CSS properties into shorthand ones, e.g.
* background-position-x -> background-position -> background
* @param {CSSSnippet[]} snippets
* @return {CSSSnippet[]}
*/
function css_snippets_resolver_es_nest(snippets) {
snippets = snippets.sort(css_snippets_resolver_es_snippetsSort);
const stack = [];
// For sorted list of CSS properties, create dependency graph where each
// shorthand property contains its more specific one, e.g.
// backgound -> background-position -> background-position-x
for (let i = 0, cur, prev; i < snippets.length; i++) {
cur = snippets[i];
if (!cur.property) {
// not a CSS property, skip it
continue;
}
// Check if current property belongs to one from parent stack.
// Since `snippets` array is sorted, items are perfectly aligned
// from shorthands to more specific variants
while (stack.length) {
prev = stack[stack.length - 1];
if (cur.property.indexOf(prev.property) === 0 && cur.property.charCodeAt(prev.property.length) === dist_css_snippets_resolver_es_DASH$1) {
prev.addDependency(cur);
stack.push(cur);
break;
}
stack.pop();
}
if (!stack.length) {
stack.push(cur);
}
}
return snippets;
}
/**
* A sorting function for array of snippets
* @param {CSSSnippet} a
* @param {CSSSnippet} b
* @return {Number}
*/
function css_snippets_resolver_es_snippetsSort(a, b) {
if (a.key === b.key) {
return 0;
}
return a.key < b.key ? -1 : 1;
}
/**
* Check if given string is a keyword candidate
* @param {String} str
* @return {Boolean}
*/
function dist_css_snippets_resolver_es_isKeyword(str) {
return (/^\s*[\w-]+/.test(str)
);
}
function css_snippets_resolver_es_splitValue(value) {
return String(value).split('|');
}
const css_snippets_resolver_es_globalKeywords = ['auto', 'inherit', 'unset'];
const css_snippets_resolver_es_unitlessProperties = ['z-index', 'line-height', 'opacity', 'font-weight', 'zoom', 'flex', 'flex-grow', 'flex-shrink'];
const dist_css_snippets_resolver_es_defaultOptions = {
intUnit: 'px',
floatUnit: 'em',
unitAliases: {
e: 'em',
p: '%',
x: 'ex',
r: 'rem'
},
fuzzySearchMinScore: 0
};
/**
* For every node in given `tree`, finds matching snippet from `registry` and
* updates node with snippet data.
*
* This resolver uses fuzzy matching for searching matched snippets and their
* keyword values.
*/
function dist_css_snippets_resolver_es_index(tree, registry, options) {
options = dist_css_snippets_resolver_es__extends({}, dist_css_snippets_resolver_es_defaultOptions, options);
options.unitAliases = dist_css_snippets_resolver_es__extends({}, dist_css_snippets_resolver_es_defaultOptions.unitAliases, options && options.unitAliases);
const snippets = css_snippets_resolver_es_convertToCSSSnippets(registry);
tree.walk(node => dist_css_snippets_resolver_es_resolveNode(node, snippets, options));
return tree;
}
function css_snippets_resolver_es_convertToCSSSnippets(registry) {
return css_snippets_resolver_es_cssSnippets(registry.all({ type: 'string' }));
}
/**
* Resolves given node: finds matched CSS snippets using fuzzy match and resolves
* keyword aliases from node value
* @param {Node} node
* @param {CSSSnippet[]} snippets
* @param {Object} options
* @return {Node}
*/
function dist_css_snippets_resolver_es_resolveNode(node, snippets, options) {
const snippet = css_snippets_resolver_es_findBestMatch(node.name, snippets, 'key', options.fuzzySearchMinScore);
if (!snippet) {
// Edge case: `!important` snippet
return node.name === '!' ? css_snippets_resolver_es_setNodeAsText(node, '!important') : node;
}
return snippet.property ? css_snippets_resolver_es_resolveAsProperty(node, snippet, options) : css_snippets_resolver_es_resolveAsSnippet(node, snippet);
}
/**
* Resolves given parsed abbreviation node as CSS property
* @param {Node} node
* @param {CSSSnippet} snippet
* @param {Object} formatOptions
* @return {Node}
*/
function css_snippets_resolver_es_resolveAsProperty(node, snippet, formatOptions) {
const abbr = node.name;
node.name = snippet.property;
if (node.value && typeof node.value === 'object') {
// resolve keyword shortcuts
const keywords = snippet.keywords();
if (!node.value.size) {
// no value defined, try to resolve unmatched part as a keyword alias
let kw = css_snippets_resolver_es_findBestMatch(css_snippets_resolver_es_getUnmatchedPart(abbr, snippet.key), keywords);
if (!kw) {
// no matching value, try to get default one
kw = snippet.defaultValue;
if (kw && kw.indexOf('${') === -1) {
// Quick and dirty test for existing field. If not, wrap
// default value in a field
kw = `\${1:${kw}}`;
}
}
if (kw) {
node.value.add(kw);
}
} else {
// replace keyword aliases in current node value
for (let i = 0, token; i < node.value.value.length; i++) {
token = node.value.value[i];
if (token === '!') {
token = `${!i ? '${1} ' : ''}!important`;
} else if (css_snippets_resolver_es_isKeyword$1(token)) {
token = css_snippets_resolver_es_findBestMatch(token.value, keywords) || css_snippets_resolver_es_findBestMatch(token.value, css_snippets_resolver_es_globalKeywords) || token;
} else if (css_snippets_resolver_es_isNumericValue(token)) {
token = css_snippets_resolver_es_resolveNumericValue(node.name, token, formatOptions);
}
node.value.value[i] = token;
}
}
}
return node;
}
/**
* Resolves given parsed abbreviation node as a snippet: a plain code chunk
* @param {Node} node
* @param {CSSSnippet} snippet
* @return {Node}
*/
function css_snippets_resolver_es_resolveAsSnippet(node, snippet) {
return css_snippets_resolver_es_setNodeAsText(node, snippet.value);
}
/**
* Sets given parsed abbreviation node as a text snippet
* @param {Node} node
* @param {String} text
* @return {Node}
*/
function css_snippets_resolver_es_setNodeAsText(node, text) {
node.name = null;
node.value = text;
return node;
}
/**
* Finds best matching item from `items` array
* @param {String} abbr Abbreviation to match
* @param {Array} items List of items for match
* @param {String} [key] If `items` is a list of objects, use `key` as object
* property to test against
* @param {Number} fuzzySearchMinScore The minimum score the best matched item should have to be a valid match.
* @return {*}
*/
function css_snippets_resolver_es_findBestMatch(abbr, items, key, fuzzySearchMinScore) {
if (!abbr) {
return null;
}
let matchedItem = null;
let maxScore = 0;
fuzzySearchMinScore = fuzzySearchMinScore || 0;
for (let i = 0, item; i < items.length; i++) {
item = items[i];
const score = css_snippets_resolver_es_stringScore(abbr, css_snippets_resolver_es_getScoringPart(item, key));
if (score === 1) {
// direct hit, no need to look further
return item;
}
if (score && score >= maxScore) {
maxScore = score;
matchedItem = item;
}
}
return maxScore >= fuzzySearchMinScore ? matchedItem : null;
}
function css_snippets_resolver_es_getScoringPart(item, key) {
const value = item && typeof item === 'object' ? item[key] : item;
const m = (value || '').match(/^[\w-@]+/);
return m ? m[0] : value;
}
/**
* Returns a part of `abbr` that wasnt directly matched agains `string`.
* For example, if abbreviation `poas` is matched against `position`, the unmatched part will be `as`
* since `a` wasnt found in string stream
* @param {String} abbr
* @param {String} string
* @return {String}
*/
function css_snippets_resolver_es_getUnmatchedPart(abbr, string) {
for (let i = 0, lastPos = 0; i < abbr.length; i++) {
lastPos = string.indexOf(abbr[i], lastPos);
if (lastPos === -1) {
return abbr.slice(i);
}
lastPos++;
}
return '';
}
/**
* Check if given CSS value token is a keyword
* @param {*} token
* @return {Boolean}
*/
function css_snippets_resolver_es_isKeyword$1(token) {
return css_snippets_resolver_es_tokenTypeOf(token, 'keyword');
}
/**
* Check if given CSS value token is a numeric value
* @param {*} token
* @return {Boolean}
*/
function css_snippets_resolver_es_isNumericValue(token) {
return css_snippets_resolver_es_tokenTypeOf(token, 'numeric');
}
function css_snippets_resolver_es_tokenTypeOf(token, type) {
return token && typeof token === 'object' && token.type === type;
}
/**
* Resolves numeric value for given CSS property
* @param {String} property CSS property name
* @param {NumericValue} token CSS numeric value token
* @param {Object} formatOptions Formatting options for units
* @return {NumericValue}
*/
function css_snippets_resolver_es_resolveNumericValue(property, token, formatOptions) {
if (token.unit) {
token.unit = formatOptions.unitAliases[token.unit] || token.unit;
} else if (token.value !== 0 && css_snippets_resolver_es_unitlessProperties.indexOf(property) === -1) {
// use `px` for integers, `em` for floats
// NB: num|0 is a quick alternative to Math.round(0)
token.unit = token.value === (token.value | 0) ? formatOptions.intUnit : formatOptions.floatUnit;
}
return token;
}
/* harmony default export */ var dist_css_snippets_resolver_es = (dist_css_snippets_resolver_es_index);
//# sourceMappingURL=css-snippets-resolver.es.js.map
// CONCATENATED MODULE: ../node_modules/@emmetio/html-matcher/dist/html-matcher.es.js
var html_matcher_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
let html_matcher_es_Node = class Node {
constructor(stream, type, open, close) {
this.stream = stream;
this.type = type;
this.open = open;
this.close = close;
this.children = [];
this.parent = null;
}
/**
* Returns node name
* @return {String}
*/
get name() {
if (this.type === 'tag' && this.open) {
return this.open && this.open.name && this.open.name.value;
}
return '#' + this.type;
}
/**
* Returns attributes of current node
* @return {Array}
*/
get attributes() {
return this.open && this.open.attributes;
}
/**
* Returns nodes start position in stream
* @return {*}
*/
get start() {
return this.open && this.open.start;
}
/**
* Returns nodes start position in stream
* @return {*}
*/
get end() {
return this.close ? this.close.end : this.open && this.open.end;
}
get firstChild() {
return this.children[0];
}
get nextSibling() {
const ix = this.getIndex();
return ix !== -1 ? this.parent.children[ix + 1] : null;
}
get previousSibling() {
const ix = this.getIndex();
return ix !== -1 ? this.parent.children[ix - 1] : null;
}
/**
* Returns current elements index in parent list of child nodes
* @return {Number}
*/
getIndex() {
return this.parent ? this.parent.children.indexOf(this) : -1;
}
/**
* Adds given node as a child
* @param {Node} node
* @return {Node} Current node
*/
addChild(node) {
this.removeChild(node);
this.children.push(node);
node.parent = this;
return this;
}
/**
* Removes given node from current nodes child list
* @param {Node} node
* @return {Node} Current node
*/
removeChild(node) {
const ix = this.children.indexOf(node);
if (ix !== -1) {
this.children.splice(ix, 1);
node.parent = null;
}
return this;
}
};
/**
* A token factory method
* @param {StreamReader} stream
* @param {Point|Function} start Tokens start location or stream consumer
* @param {Point} [end] Tokens end location
* @return {Token}
*/
var html_matcher_es_token = function (stream, start, end) {
return typeof start === 'function' ? eatToken(stream, start) : new Token(stream, start, end);
};
/**
* Consumes characters from given stream that matches `fn` call and returns it
* as token, if consumed
* @param {StreamReader} stream
* @param {Function} test
* @return {Token}
*/
function eatToken(stream, test) {
const start = stream.pos;
if (stream.eatWhile(test)) {
return new Token(stream, start, stream.pos);
}
stream.pos = start;
}
/**
* A structure describing text fragment in content stream
*/
let Token = class Token {
/**
* @param {ContentStreamReader} stream
* @param {Point} start Tokens start location in content stream
* @param {Point} end Tokens end location in content stream
*/
constructor(stream, start, end) {
this.stream = stream;
this.start = start != null ? start : stream.start;
this.end = end != null ? end : stream.pos;
this._value = null;
}
/**
* Returns token textual value
* NB implemented as getter to reduce unnecessary memory allocations for
* strings that not required
* @return {String}
*/
get value() {
if (this._value === null) {
const start = this.stream.start;
const end = this.stream.pos;
this.stream.start = this.start;
this.stream.pos = this.end;
this._value = this.stream.current();
this.stream.start = start;
this.stream.pos = end;
}
return this._value;
}
toString() {
return this.value;
}
valueOf() {
return `${this.value} [${this.start}; ${this.end}]`;
}
};
const LANGLE = 60;
const RANGLE = 62; // < and >
const LSQUARE = 91;
const RSQUARE = 93; // [ and ]
const LROUND = 40;
const RROUND = 41; // ( and )
const LCURLY = 123;
const RCURLY = 125; // { and }
const html_matcher_es_opt = { throws: true };
/**
* Consumes paired tokens (like `[` and `]`) with respect of nesting and embedded
* quoted values
* @param {StreamReader} stream
* @return {Token} A token with consumed paired character
*/
var eatPaired = function (stream) {
const start = stream.pos;
const consumed = eatPair(stream, LANGLE, RANGLE, html_matcher_es_opt) || eatPair(stream, LSQUARE, RSQUARE, html_matcher_es_opt) || eatPair(stream, LROUND, RROUND, html_matcher_es_opt) || eatPair(stream, LCURLY, RCURLY, html_matcher_es_opt);
if (consumed) {
return html_matcher_es_token(stream, start);
}
};
const SLASH$1 = 47; // /
const html_matcher_es_EQUALS = 61; // =
const RIGHT_ANGLE$1 = 62; // >
/**
* Consumes attributes from given stream
* @param {StreamReader} stream
* @return {Array} Array of consumed attributes
*/
var eatAttributes = function (stream) {
const result = [];
let name, value, attr;
while (!stream.eof()) {
stream.eatWhile(isSpace);
attr = { start: stream.pos };
// A name could be a regular name or expression:
// React-style <div {...props}>
// Angular-style <div [ng-for]>
if (attr.name = eatAttributeName(stream)) {
// Consumed attribute name. Can be an attribute with name
// or boolean attribute. The value can be React-like expression
if (stream.eat(html_matcher_es_EQUALS)) {
attr.value = eatAttributeValue(stream);
} else {
attr.boolean = true;
}
attr.end = stream.pos;
result.push(attr);
} else if (isTerminator(stream.peek())) {
// look for tag terminator in order to skip any other possible characters
// (maybe junk)
break;
} else {
stream.next();
}
}
return result;
};
/**
* Consumes attribute name from current location
* @param {StreamReader} stream
* @return {Token}
*/
function eatAttributeName(stream) {
return eatPaired(stream) || html_matcher_es_token(stream, isAttributeName);
}
/**
* Consumes attribute value from given location
* @param {StreamReader} stream
* @return {Token}
*/
function eatAttributeValue(stream) {
const start = stream.pos;
if (eatQuoted(stream)) {
// Should return token that points to unquoted value.
// Use stream readers public API to traverse instead of direct
// manipulation
const current = stream.pos;
let valueStart, valueEnd;
stream.pos = start;
stream.next();
valueStart = stream.start = stream.pos;
stream.pos = current;
stream.backUp(1);
valueEnd = stream.pos;
const result = html_matcher_es_token(stream, valueStart, valueEnd);
stream.pos = current;
return result;
}
return eatPaired(stream) || html_matcher_es_eatUnquoted(stream);
}
/**
* Check if given code belongs to attribute name.
* NB some custom HTML variations allow non-default values in name, like `*ngFor`
* @param {Number} code
* @return {Boolean}
*/
function isAttributeName(code) {
return code !== html_matcher_es_EQUALS && !isTerminator(code) && !isSpace(code);
}
/**
* Check if given code is tag terminator
* @param {Number} code
* @return {Boolean}
*/
function isTerminator(code) {
return code === RIGHT_ANGLE$1 || code === SLASH$1;
}
/**
* Eats unquoted value from stream
* @param {StreamReader} stream
* @return {Token}
*/
function html_matcher_es_eatUnquoted(stream) {
return html_matcher_es_token(stream, html_matcher_es_isUnquoted);
}
/**
* Check if given character code is valid unquoted value
* @param {Number} code
* @return {Boolean}
*/
function html_matcher_es_isUnquoted(code) {
return !isNaN(code) && !isQuote(code) && !isSpace(code) && !isTerminator(code);
}
const html_matcher_es_DASH = 45; // -
const html_matcher_es_DOT = 46; // .
const html_matcher_es_SLASH = 47; // /
const html_matcher_es_COLON = 58; // :
const LEFT_ANGLE = 60; // <
const RIGHT_ANGLE = 62; // >
const UNDERSCORE = 95; // _
/**
* Parses tag definition (open or close tag) from given stream state
* @param {StreamReader} stream Content stream reader
* @return {Object}
*/
var tag = function (stream) {
const start = stream.pos;
if (stream.eat(LEFT_ANGLE)) {
const model = { type: stream.eat(html_matcher_es_SLASH) ? 'close' : 'open' };
if (model.name = eatTagName(stream)) {
if (model.type !== 'close') {
model.attributes = eatAttributes(stream);
stream.eatWhile(isSpace);
model.selfClosing = stream.eat(html_matcher_es_SLASH);
}
if (stream.eat(RIGHT_ANGLE)) {
// tag properly closed
return html_matcher_es__extends(html_matcher_es_token(stream, start), model);
}
}
}
// invalid tag, revert to original position
stream.pos = start;
return null;
};
/**
* Eats HTML identifier (tag or attribute name) from given stream
* @param {StreamReader} stream
* @return {Token}
*/
function eatTagName(stream) {
return html_matcher_es_token(stream, isTagName);
}
/**
* Check if given character code can be used as HTML/XML tag name
* @param {Number} code
* @return {Boolean}
*/
function isTagName(code) {
return isAlphaNumeric(code) || code === html_matcher_es_COLON // colon is used for namespaces
|| code === html_matcher_es_DOT // in rare cases declarative tag names may have dots in names
|| code === html_matcher_es_DASH || code === UNDERSCORE;
}
/**
* Eats array of character codes from given stream
* @param {StreamReader} stream
* @param {Number[]} codes Array of character codes
* @return {Boolean}
*/
function eatArray(stream, codes) {
const start = stream.pos;
for (let i = 0; i < codes.length; i++) {
if (!stream.eat(codes[i])) {
stream.pos = start;
return false;
}
}
stream.start = start;
return true;
}
/**
* Consumes section from given string which starts with `open` character codes
* and ends with `close` character codes
* @param {StreamReader} stream
* @param {Number[]} open
* @param {Number[]} close
* @return {Boolean} Returns `true` if section was consumed
*/
function eatSection(stream, open, close, allowUnclosed) {
const start = stream.pos;
if (eatArray(stream, open)) {
// consumed `<!--`, read next until we find ending part or reach the end of input
while (!stream.eof()) {
if (eatArray(stream, close)) {
return true;
}
stream.next();
}
// unclosed section is allowed
if (allowUnclosed) {
return true;
}
stream.pos = start;
return false;
}
// unable to find section, revert to initial position
stream.pos = start;
return null;
}
/**
* Converts given string into array of character codes
* @param {String} str
* @return {Number[]}
*/
function toCharCodes(str) {
return str.split('').map(ch => ch.charCodeAt(0));
}
const html_matcher_es_open = toCharCodes('<!--');
const html_matcher_es_close = toCharCodes('-->');
/**
* Consumes HTML comment from given stream
* @param {StreamReader} stream
* @return {Token}
*/
var comment = function (stream) {
const start = stream.pos;
if (eatSection(stream, html_matcher_es_open, html_matcher_es_close, true)) {
const result = html_matcher_es_token(stream, start);
result.type = 'comment';
return result;
}
return null;
};
const open$1 = toCharCodes('<![CDATA[');
const close$1 = toCharCodes(']]>');
/**
* Consumes CDATA from given stream
* @param {StreamReader} stream
* @return {Token}
*/
var cdata = function (stream) {
const start = stream.pos;
if (eatSection(stream, open$1, close$1, true)) {
const result = html_matcher_es_token(stream, start);
result.type = 'cdata';
return result;
}
return null;
};
const html_matcher_es_defaultOptions = {
/**
* Expect XML content in searching content. It alters how should-be-empty
* elements are treated: for example, in XML mode parser will try to locate
* closing pair for `<br>` tag
* @type {Boolean}
*/
xml: false,
special: ['script', 'style'],
/**
* List of elements that should be treated as empty (e.g. without closing tag)
* in non-XML syntax
* @type {Array}
*/
empty: ['img', 'meta', 'link', 'br', 'base', 'hr', 'area', 'wbr', 'col', 'embed', 'input', 'param', 'source', 'track']
};
/**
* Parses given content into a DOM-like structure
* @param {String|StreamReader} content
* @param {Object} options
* @return {Node}
*/
function html_matcher_es_parse(content, options) {
options = html_matcher_es__extends({}, html_matcher_es_defaultOptions, options);
const stream = typeof content === 'string' ? new stream_reader_es(content) : content;
const root = new html_matcher_es_Node(stream, 'root');
const empty = new Set(options.empty);
const special = options.special.reduce((map, name) => map.set(name, toCharCodes(`</${name}>`)), new Map());
const isEmpty = (token, name) => token.selfClosing || !options.xml && empty.has(name);
let m,
node,
name,
stack = [root];
while (!stream.eof()) {
if (m = match(stream)) {
name = getName(m);
if (m.type === 'open') {
// opening tag
node = new html_matcher_es_Node(stream, 'tag', m);
last(stack).addChild(node);
if (special.has(name)) {
node.close = consumeSpecial(stream, special.get(name));
} else if (!isEmpty(m, name)) {
stack.push(node);
}
} else if (m.type === 'close') {
// closing tag, find its matching opening tag
for (let i = stack.length - 1; i > 0; i--) {
if (stack[i].name.toLowerCase() === name) {
stack[i].close = m;
stack = stack.slice(0, i);
break;
}
}
} else {
last(stack).addChild(new html_matcher_es_Node(stream, m.type, m));
}
} else {
stream.next();
}
}
return root;
}
/**
* Matches known token in current state of given stream
* @param {ContentStreamReader} stream
* @return {Token}
*/
function match(stream) {
// fast-path optimization: check for `<` code
if (stream.peek() === 60 /* < */) {
return comment(stream) || cdata(stream) || tag(stream);
}
}
/**
* @param {StreamReader} stream
* @param {Number[]} codes
* @return {Token}
*/
function consumeSpecial(stream, codes) {
const start = stream.pos;
let m;
while (!stream.eof()) {
if (eatArray(stream, codes)) {
stream.pos = stream.start;
return tag(stream);
}
stream.next();
}
stream.pos = start;
return null;
}
/**
* Returns name of given matched token
* @param {Token} tag
* @return {String}
*/
function getName(tag$$1) {
return tag$$1.name ? tag$$1.name.value.toLowerCase() : `#${tag$$1.type}`;
}
function last(arr) {
return arr[arr.length - 1];
}
/* harmony default export */ var html_matcher_es = (html_matcher_es_parse);
// CONCATENATED MODULE: ../node_modules/@emmetio/codemirror-plugin/dist/emmet-codemirror-plugin.es.js
var emmet_codemirror_plugin_es__extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
const editorField = (index, placeholder = '') => `\${${index}${placeholder ? ':' + placeholder : ''}}`;
/**
* Returns resolved Emmet config for `pos` location of given editor
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} [pos] Point in editor where syntax should be detected.
* Uses `editor.getCursor()` if not given
* @param {Object} [options] Additional options to override before config resolve
* @return {Object}
*/
function createConfig(editor, pos, options) {
pos = pos || editor.getCursor();
const syntax = getSyntax(editor, pos);
/** @type {EmmetConfig} */
const config = config_es(emmet_codemirror_plugin_es__extends({ field: editorField }, editor.getOption('emmet'), options), { syntax });
const mode = editor.getModeAt(pos);
if (syntax === 'jsx') {
config.profile = emmet_codemirror_plugin_es__extends({ selfClosingStyle: 'xml' }, config.profile);
config.options = emmet_codemirror_plugin_es__extends({ jsx: true }, config.options);
} else if (mode.name === 'xml') {
config.profile = emmet_codemirror_plugin_es__extends({ selfClosingStyle: mode.configuration }, config.profile);
}
return config;
}
/**
* Detect Emmet syntax from given editors position.
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} [pos]
* @return {String} Returns `null` if Emmet syntax cant be detected
*/
function getSyntax(editor, pos) {
const rootMode = editor.getMode();
if (rootMode.name === 'jsx' || rootMode.name === 'javascript') {
return rootMode.name;
}
const mode = editor.getModeAt(pos);
return mode.name === 'xml' ? 'html' : mode.name;
}
const LINE_END = 10; // \n
/**
* A stream reader for CodeMirror editor
*/
let CodeMirrorStreamReader = class CodeMirrorStreamReader extends stream_reader_es {
/**
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} [pos]
* @param {CodeMirror.Range} [limit]
*/
constructor(editor, pos, limit) {
super();
const CodeMirror = editor.constructor;
this.editor = editor;
this.start = this.pos = pos || CodeMirror.Pos(0, 0);
const lastLine = editor.lastLine();
this._eof = limit ? limit.to : CodeMirror.Pos(lastLine, this._lineLength(lastLine));
this._sof = limit ? limit.from : CodeMirror.Pos(0, 0);
}
/**
* Returns true only if the stream is at the beginning of the file.
* @returns {Boolean}
*/
sof() {
return comparePos(this.pos, this._sof) <= 0;
}
/**
* Returns true only if the stream is at the end of the file.
* @returns {Boolean}
*/
eof() {
return comparePos(this.pos, this._eof) >= 0;
}
/**
* Creates a new stream instance which is limited to given `start` and `end`
* points for underlying buffer
* @param {CodeMirror.Pos} start
* @param {CodeMirror.Pos} end
* @return {CodeMirrorStreamReader}
*/
limit(from, to) {
return new this.constructor(this.editor, from, { from, to });
}
/**
* Returns the next character code in the stream without advancing it.
* Will return NaN at the end of the file.
* @returns {Number}
*/
peek() {
const { line, ch } = this.pos;
const lineStr = this.editor.getLine(line);
return ch < lineStr.length ? lineStr.charCodeAt(ch) : LINE_END;
}
/**
* Returns the next character in the stream and advances it.
* Also returns NaN when no more characters are available.
* @returns {Number}
*/
next() {
if (!this.eof()) {
const code = this.peek();
this.pos = emmet_codemirror_plugin_es__extends({}, this.pos, { ch: this.pos.ch + 1 });
if (this.pos.ch >= this._lineLength(this.pos.line)) {
this.pos.line++;
this.pos.ch = 0;
}
if (this.eof()) {
// handle edge case where position can move on next line
// after EOF
this.pos = emmet_codemirror_plugin_es__extends({}, this._eof);
}
return code;
}
return NaN;
}
/**
* Backs up the stream n characters. Backing it up further than the
* start of the current token will cause things to break, so be careful.
* @param {Number} n
*/
backUp(n) {
const CodeMirror = this.editor.constructor;
let { line, ch } = this.pos;
ch -= n || 1;
while (line >= 0 && ch < 0) {
line--;
ch += this._lineLength(line);
}
this.pos = line < 0 || ch < 0 ? CodeMirror.Pos(0, 0) : CodeMirror.Pos(line, ch);
return this.peek();
}
/**
* Get the string between the start of the current token and the
* current stream position.
* @returns {String}
*/
current() {
return this.substring(this.start, this.pos);
}
/**
* Returns contents for given range
* @param {Point} from
* @param {Point} to
* @return {String}
*/
substring(from, to) {
return this.editor.getRange(from, to);
}
/**
* Creates error object with current stream state
* @param {String} message
* @return {Error}
*/
error(message) {
const err = new Error(`${message} at line ${this.pos.line}, column ${this.pos.ch}`);
err.originalMessage = message;
err.pos = this.pos;
err.string = this.string;
return err;
}
/**
* Returns length of given line, including line ending
* @param {Number} line
* @return {Number}
*/
_lineLength(line) {
const isLast = line === this.editor.lastLine();
return this.editor.getLine(line).length + (isLast ? 0 : 1);
}
};
function comparePos(a, b) {
return a.line - b.line || a.ch - b.ch;
}
/**
* Returns token used for single indentation in given editor
* @param {CodeMirror.Editor} editor
* @return {String}
*/
function getIndentation(editor) {
if (!editor.getOption('indentWithTabs')) {
return repeatString(' ', editor.getOption('indentUnit'));
}
return '\t';
}
/**
* Normalizes text according to given CodeMirror instance indentation
* preferences
* @param {String} text
* @param {CodeMirror.Editor} editor
* @param {String} [indentation] Applies `indentText()` with given argument, if provided
* @return {String}
*/
function normalizeText(editor, text, indentation) {
let lines = emmet_codemirror_plugin_es_splitByLines(text);
const indent = getIndentation(editor);
if (indent !== '\t') {
lines = lines.map(line => line.replace(/^\t+/, tabs => repeatString(indent, tabs.length)));
}
if (indentation) {
lines = lines.map((line, i) => i ? indentation + line : line);
}
return lines.join('\n');
}
/**
* Splits given text by lines
* @param {String} text
* @return {String[]} Lines of text
*/
function emmet_codemirror_plugin_es_splitByLines(text) {
return Array.isArray(text) ? text : text.split(/\r\n|\r|\n/g);
}
function repeatString(str, count) {
let result = '';
while (0 < count--) {
result += str;
}
return result;
}
/**
* Quick and dirty way to remove fields from given string
* @param {String} str
* @return {String}
*/
function removeFields(str) {
return field_parser_es(str).string;
}
/**
* Check if given range contains point
* @param {CodeMirror.Range} range
* @param {CodeMirror.Position} pos
* @param {Boolean} [exclude] Exclude range and and start
* @return {Boolean}
*/
function containsPos(range, pos, exclude) {
return exclude ? comparePos$1(pos, range.from) > 0 && comparePos$1(pos, range.to) < 0 : comparePos$1(pos, range.from) >= 0 && comparePos$1(pos, range.to) <= 0;
}
function comparePos$1(a, b) {
return a.line - b.line || a.ch - b.ch;
}
function rangeFromNode(node) {
return {
from: node.start,
to: node.end
};
}
/**
* Narrows given `{from, to}` range to first non-whitespace characters in given
* editor content
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} from
* @param {CodeMirror.Position} [to]
* @returns {Object}
*/
function narrowToNonSpace(editor, from, to) {
const stream = new CodeMirrorStreamReader(editor, from);
stream.eatWhile(isSpace);
from = stream.pos;
if (to) {
stream.pos = to;
stream.backUp();
while (!stream.sof() && isSpace(stream.peek())) {
stream.backUp();
}
stream.next();
to = stream.pos;
} else {
to = from;
}
return { from, to };
}
/**
* Returns nearest CSS property name, left to given position
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} pos
* @returns {String}
*/
function getCSSPropertyName(editor, pos) {
const line = pos.line;
let ch = pos.ch,
token;
while (ch >= 0) {
token = editor.getTokenAt({ line, ch });
if (token.type === 'property') {
return token.string;
}
if (token.start !== ch) {
ch = token.start;
} else {
break;
}
}
}
/**
* Check if given position is inside CSS property value
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} pos
* @return {Boolean}
*/
function isCSSPropertyValue(editor, pos) {
const mode = editor.getModeAt(pos);
if (mode && mode.name === 'css') {
const token = editor.getTokenAt(pos);
const state = token.state && token.state.localState || token.state;
return state && state.context && state.context.type === 'prop';
}
return false;
}
/**
* Context-aware abbreviation extraction from given editor.
* Detects syntax context in `pos` editor location and, if it allows Emmet
* abbreviation to be extracted here, returns object with extracted abbreviation,
* its location and config.
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} pos
*/
function emmet_codemirror_plugin_es_extractAbbreviation(editor, pos, contextAware) {
const config = createConfig(editor, pos);
if (contextAware && !canExtract(editor, pos, config)) {
return null;
}
const extracted = extract_abbreviation_es(editor.getLine(pos.line), pos.ch, {
lookAhead: true,
syntax: config.type,
prefix: config.syntax === 'jsx' && editor.getOption('jsxBracket') ? '<' : ''
});
if (extracted) {
const from = {
line: pos.line,
ch: extracted.start
};
const to = {
line: pos.line,
ch: extracted.end
};
if (config.type === 'stylesheet' && contextAware) {
// In case of stylesheet syntaxes (CSS, LESS) we should narrow down
// expand context to property value, if possible
if (isCSSPropertyValue(editor, pos)) {
config.options = emmet_codemirror_plugin_es__extends({ property: getCSSPropertyName(editor, pos) }, config.options);
}
}
return {
abbreviation: extracted.abbreviation,
range: { from, to },
config
};
}
}
/**
* Check if abbreviation can be extracted from given position
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} pos
* @param {Object} config
* @return {Boolean}
*/
function canExtract(editor, pos, config) {
const tokenType = editor.getTokenTypeAt(pos);
if (config.type === 'stylesheet') {
return tokenType !== 'comment' && tokenType !== 'string';
}
if (config.syntax === 'html') {
return tokenType === null;
}
if (config.syntax === 'slim' || config.syntax === 'pug') {
return tokenType === null || tokenType === 'tag' || tokenType && /attribute/.test(tokenType);
}
if (config.syntax === 'haml') {
return tokenType === null || tokenType === 'attribute';
}
if (config.syntax === 'jsx') {
// JSX a bit tricky, delegate it to caller
return true;
}
return false;
}
/**
* Replaces `range` in `editor` with `text` snippet. A snippet is a string containing
* tabstops/fields like `${index:placeholder}`: this function will locate such
* fields and place cursor at first one.
* Inserted snippet will be automatically matched with current editor indentation
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Range} range
* @param {String} text
*/
function insertSnippet(editor, range, text) {
const line = editor.getLine(range.from.line);
const matchIndent = line.match(/^\s+/);
let snippet = normalizeText(editor, text, matchIndent && matchIndent[0]);
const fieldModel = field_parser_es(snippet);
return editor.operation(() => {
editor.replaceRange(fieldModel.string, range.from, range.to);
// Position cursor
const startIx = editor.indexFromPos(range.from);
if (fieldModel.fields.length) {
const field = fieldModel.fields[0];
const from = editor.posFromIndex(field.location + startIx);
const to = editor.posFromIndex(field.location + field.length + startIx);
editor.setSelection(from, to);
} else {
editor.setCursor(editor.posFromIndex(startIx + fieldModel.string.length));
}
return true;
});
}
const emmetMarkerClass = 'emmet-abbreviation';
/**
* Returns parsed abbreviation from given position in `editor`, if possible.
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} pos
* @param {Boolean} [contextAware] Use context-aware abbreviation detection
* @returns {Abbreviation}
*/
function abbreviationFromPosition(editor, pos, contextAware) {
// Try to find abbreviation marker from given position
const marker = findMarker(editor, pos);
if (marker && marker.model) {
return marker.model;
}
// Try to extract abbreviation from given position
const extracted = emmet_codemirror_plugin_es_extractAbbreviation(editor, pos, contextAware);
if (extracted) {
try {
const abbr = new emmet_codemirror_plugin_es_Abbreviation(extracted.abbreviation, extracted.range, extracted.config);
return abbr.valid(editor, contextAware) ? abbr : null;
} catch (err) {
// skip
// console.warn(err);
}
}
}
/**
* Returns *valid* Emmet abbreviation marker (if any) for given position of editor
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} [pos]
* @return {CodeMirror.TextMarker}
*/
function findMarker(editor, pos) {
const markers = editor.findMarksAt(pos);
for (let i = 0, marker; i < markers.length; i++) {
marker = markers[i];
if (marker.className === emmetMarkerClass) {
if (isValidMarker(editor, marker)) {
return marker;
}
marker.clear();
}
}
}
/**
* Removes Emmet abbreviation markers from given editor
* @param {CodeMirror.Editor} editor
*/
function clearMarkers(editor) {
const markers = editor.getAllMarks();
for (let i = 0; i < markers.length; i++) {
if (markers[i].className === emmetMarkerClass) {
markers[i].clear();
}
}
}
/**
* Marks Emmet abbreviation for given editor position, if possible
* @param {CodeMirror.Editor} editor Editor where abbreviation marker should be created
* @param {Abbreviation} model Parsed abbreviation model
* @return {CodeMirror.TextMarker} Returns `undefined` if no valid abbreviation under caret
*/
function createMarker(editor, model) {
const { from, to } = model.range;
const marker = editor.markText(from, to, {
inclusiveLeft: true,
inclusiveRight: true,
clearWhenEmpty: true,
className: emmetMarkerClass
});
marker.model = model;
return marker;
}
/**
* Ensures that given editor Emmet abbreviation marker contains valid Emmet abbreviation
* and updates abbreviation model if required
* @param {CodeMirror} editor
* @param {CodeMirror.TextMarket} marker
* @return {Boolean} `true` if marker contains valid abbreviation
*/
function isValidMarker(editor, marker) {
const range = marker.find();
// No newlines inside abbreviation
if (range.from.line !== range.to.line) {
return false;
}
// Make sure marker contains valid abbreviation
let text = editor.getRange(range.from, range.to);
if (!text || /^\s|\s$/g.test(text)) {
return false;
}
if (marker.model && marker.model.config.syntax === 'jsx' && text[0] === '<') {
text = text.slice(1);
}
if (!marker.model || marker.model.abbreviation !== text) {
// marker contents was updated, re-parse abbreviation
try {
marker.model = new emmet_codemirror_plugin_es_Abbreviation(text, range, marker.model.config);
if (!marker.model.valid(editor, true)) {
marker.model = null;
}
} catch (err) {
console.warn(err);
marker.model = null;
}
}
return Boolean(marker.model && marker.model.snippet);
}
let emmet_codemirror_plugin_es_Abbreviation = class Abbreviation {
/**
* @param {String} abbreviation Abbreviation string
* @param {CodeMirror.Range} range Abbreviation location in editor
* @param {Object} [config]
*/
constructor(abbreviation, range, config) {
this.abbreviation = abbreviation;
this.range = range;
this.config = config;
this.ast = parse$2(abbreviation, config);
this.snippet = expand$2(this.ast, config);
this.preview = removeFields(this.snippet);
}
/**
* Inserts current expanded abbreviation into given `editor` by replacing
* `range`
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Range} [range]
*/
insert(editor, range) {
return insertSnippet(editor, range || this.range, this.snippet);
}
/**
* Check if parsed abbreviation is valid
* @param {Boolean} [contextAware] Perform context-aware validation: ensure
* that expanded result is expected at abbreviation location
*/
valid(editor, contextAware) {
if (this.preview && this.abbreviation !== this.preview) {
return contextAware && this.config.type === 'stylesheet' ? this._isValidForStylesheet(editor) : true;
}
return false;
}
_isValidForStylesheet(editor) {
const pos = this.range.from;
const token = editor.getTokenAt(pos);
if (/^[#!]/.test(this.abbreviation)) {
// Abbreviation is a property value
return isCSSPropertyValue(editor, pos);
}
// All expanded nodes are properties? Properties has names, regular snippets dont.
const isProperty = this.ast.children.every(node => node.name);
const state = token.state && token.state.localState || token.state;
if (isProperty) {
// Expanded abbreviation consists of properties: make sure were inside
// block context
// NB: in Sass, no actual block context since its indetation-based
return this.config.syntax === 'sass' || state && state.context && state.context.type === 'block';
}
// Expanded abbreviations are basic snippets: allow them everywhere, but forbid
// if expanded result equals abbreviation (meaningless).
return true;
}
};
/**
* Expand abbreviation command
* @param {CodeMirror.Editor} editor
* @param {Boolean} contextAware
*/
function expandAbbreviation(editor, contextAware) {
if (editor.somethingSelected()) {
return editor.constructor.Pass;
}
const abbr = abbreviationFromPosition(editor, editor.getCursor(), contextAware);
if (abbr) {
abbr.insert(editor);
clearMarkers(editor);
return true;
}
// If no abbreviation was expanded, allow editor to handle different
// action for keyboard shortcut (Tab key mostly)
return editor.constructor.Pass;
}
function emmetInsertLineBreak(editor) {
const between = editor.listSelections().map(sel => betweenTags(editor, sel));
if (!between.some(Boolean)) {
return editor.constructor.Pass;
}
editor.operation(() => {
let sels = editor.listSelections();
const singleSep = editor.doc.lineSeparator();
const doubleSep = singleSep + singleSep;
// Step 1: insert newlines either single or double depending on selection
for (let i = sels.length - 1; i >= 0; i--) {
editor.replaceRange(between[i] ? doubleSep : singleSep, sels[i].anchor, sels[i].head, '+newline');
}
// Step 2: indent inserted lines
sels = editor.listSelections();
for (let i = 0; i < sels.length; i++) {
editor.indentLine(sels[i].from().line, null, true);
if (between[i]) {
editor.indentLine(sels[i].from().line - 1, null, true);
}
}
// Step 3: adjust caret positions
editor.setSelections(editor.listSelections().map((sel, i) => {
if (between[i]) {
const line = sel.from().line - 1;
const cursor = {
line,
ch: editor.getLine(line).length
};
return { anchor: cursor, head: cursor };
}
return sel;
}));
});
}
/**
* Check if given range is a single caret between tags
* @param {CodeMirror} editor
* @param {CodeMirror.range} range
*/
function betweenTags(editor, range) {
if (equalCursorPos(range.anchor, range.head)) {
const cursor = range.anchor;
const mode = editor.getModeAt(cursor);
if (mode.name === 'xml') {
const left = editor.getTokenAt(cursor);
const right = editor.getTokenAt(emmet_codemirror_plugin_es__extends({}, cursor, { ch: cursor.ch + 1 }));
return left.type === 'tag bracket' && left.string === '>' && right.type === 'tag bracket' && right.string === '</';
}
}
}
// Compare two positions, return 0 if they are the same, a negative
// number when a is less, and a positive number otherwise.
function cmp(a, b) {
return a.line - b.line || a.ch - b.ch;
}
function equalCursorPos(a, b) {
return a.sticky === b.sticky && cmp(a, b) === 0;
}
/**
* Marks selected text or matched node content with abbreviation
* @param {CodeMirror} editor
*/
function wrapWithAbbreviation(editor) {
const range = getWrappingContentRange(editor);
if (range) {
const prompt = editor.getOption('emmetPrompt') || defaultPrompt;
const text = editor.getRange(range.from, range.to, '\n').split('\n').map(line => line.trim());
prompt(editor, 'Enter abbreviation to wrap with:', abbr => {
if (abbr) {
const model = new emmet_codemirror_plugin_es_Abbreviation(abbr, range, createConfig(editor, range.from, { text }));
model.insert(editor);
}
});
} else {
console.warn('Nothing to wrap');
}
}
/**
* Returns content range that should be wrapped
* @param {CodeMirror} editor
*/
function getWrappingContentRange(editor) {
if (editor.somethingSelected()) {
const sel = editor.listSelections().filter(sel => sel.anchor !== sel.head)[0];
if (sel) {
return comparePos$1(sel.anchor, sel.head) < 0 ? { from: sel.anchor, to: sel.head } : { from: sel.head, to: sel.anchor };
}
}
// Nothing selected, find parent HTML node and return range for its content
return getTagRangeForPos(editor, editor.getCursor());
}
/**
* Returns either inner or outer tag range (depending on `pos` location)
* for given position
* @param {CodeMirror} editor
* @param {Object} pos
* @return {Object}
*/
function getTagRangeForPos(editor, pos) {
const model = editor.getEmmetDocumentModel();
const tag = model && model.nodeForPoint(pos);
if (!tag) {
return null;
}
// Depending on given position, return either outer or inner tag range
if (inRange(tag.open, pos) || inRange(tag.close, pos)) {
// Outer range
return rangeFromNode(tag);
}
// Inner range
const from = tag.open.end;
const to = tag.close ? tag.close.start : tag.open.end;
return narrowToNonSpace(editor, from, to);
}
function inRange(tag, pos) {
return tag && containsPos(rangeFromNode(tag), pos);
}
function defaultPrompt(editor, message, callback) {
callback(window.prompt(message));
}
/**
* Marks Emmet abbreviation for given editor position, if possible
* @param {CodeMirror.Editor} editor Editor where abbreviation marker should be created
* @param {CodeMirror.Position} pos Editor position where abbreviation marker
* should be created. Abbreviation will be automatically extracted from given position
* @return {CodeMirror.TextMarker} Returns `undefined` if no valid abbreviation under caret
*/
function markAbbreviation(editor, pos) {
const marker = findMarker(editor, pos);
if (marker) {
// theres active marker with valid abbreviation
return marker;
}
// No active marker: remove previous markers and create new one, if possible
clearMarkers(editor);
const model = abbreviationFromPosition(editor, pos, true);
if (model) {
return createMarker(editor, model);
}
}
/**
* Returns available completions from given editor
* @param {CodeMirror.Editor} editor
* @param {Abbreviation} abbrModel Parsed Emmet abbreviation model for which
* completions should be populated
* @param {CodeMirror.Position} abbrPos Abbreviation location in editor
* @param {CodeMirror.Position} [pos] Cursor position in editor
* @return {EmmetCompletion[]}
*/
function autocompleteProvider(editor, pos) {
pos = pos || editor.getCursor();
let completions = [];
// Provide two types of completions:
// 1. Expanded abbreviation
// 2. Snippets
const abbreviation = abbreviationFromPosition(editor, pos, true);
// NB: Check for edge case: expanded abbreviation equals to original
// abbreviation (for example, `li.item` expands to `li.item` in Slim),
// no need to provide completion for this case
if (abbreviation && abbreviation.abbreviation !== abbreviation.snippet) {
completions.push(expandedAbbreviationCompletion(editor, pos, abbreviation));
}
const config = abbreviation ? abbreviation.config : createConfig(editor, pos);
if (config.type === 'stylesheet') {
completions = completions.concat(getStylesheetCompletions(editor, pos, config));
} else {
completions = completions.concat(getMarkupCompletions(editor, pos, config));
}
return {
type: config.type,
syntax: config.syntax,
abbreviation,
completions: completions.filter(Boolean)
};
}
/**
* Returns completions for markup syntaxes (HTML, Slim, Pug etc.)
* @param {CodeMirror} editor
* @param {CodeMirror.Position} pos Cursor position in editor
* @param {Object} config Resolved Emmet config
* @return {EmmetCompletion[]}
*/
function getMarkupCompletions(editor, pos, config) {
const line = editor.getLine(pos.line).slice(0, pos.ch);
const prefix = extractPrefix(line, /[\w:\-$@]/);
// Make sure that current position precedes element name (e.g. not attribute,
// class, id etc.)
if (prefix) {
const prefixRange = {
from: { line: pos.line, ch: pos.ch - prefix.length },
to: pos
};
return getSnippetCompletions(editor, pos, config).filter(completion => completion.key !== prefix && completion.key.indexOf(prefix) === 0).map(completion => new EmmetCompletion('snippet', editor, prefixRange, completion.key, completion.preview, completion.snippet));
}
return [];
}
/**
* Returns completions for stylesheet syntaxes
* @param {CodeMirror} editor
* @param {CodeMirror.Position} pos Cursor position in editor
* @param {Object} config Resolved Emmet config
* @return {EmmetCompletion[]}
*/
function getStylesheetCompletions(editor, pos, config) {
const line = editor.getLine(pos.line).slice(0, pos.ch);
const prefix = extractPrefix(line, /[\w-@$]/);
if (prefix) {
// Make sure that current position precedes element name (e.g. not attribute,
// class, id etc.)
const prefixRange = {
from: { line: pos.line, ch: pos.ch - prefix.length },
to: pos
};
if (config.options && config.options.property) {
const lowerProp = config.options.property.toLowerCase();
// Find matching CSS property snippet for keyword completions
const completion = getSnippetCompletions(editor, pos, config).find(item => item.property && item.property === lowerProp);
if (completion && completion.keywords.length) {
return completion.keywords.map(kw => {
return kw.key.indexOf(prefix) === 0 && new EmmetCompletion('value', editor, prefixRange, kw.key, kw.preview, kw.snippet);
}).filter(Boolean);
}
} else {
return getSnippetCompletions(editor, pos, config).filter(completion => completion.key !== prefix && completion.key.indexOf(prefix) === 0).map(completion => new EmmetCompletion('snippet', editor, prefixRange, completion.key, completion.preview, completion.snippet));
}
}
return [];
}
/**
* Returns all possible snippets completions for given editor context.
* Completions are cached in editor for for re-use
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} pos
* @param {Object} config
* @return {Array}
*/
function getSnippetCompletions(editor, pos, config) {
const { type, syntax } = config;
if (!editor.state.emmetCompletions) {
editor.state.emmetCompletions = {};
}
const cache = editor.state.emmetCompletions;
if (!(syntax in cache)) {
const registry = createSnippetsRegistry(type, syntax, config.snippets);
cache[syntax] = type === 'stylesheet' ? getStylesheetSnippets(registry, config) : getMarkupSnippets(registry, config);
}
return cache[syntax];
}
/**
* Returns stylesheet snippets list
* @param {SnippetsRegistry} registry
* @return {Array}
*/
function getStylesheetSnippets(registry) {
return css_snippets_resolver_es_convertToCSSSnippets(registry).map(snippet => {
let preview = snippet.property;
const keywords = snippet.keywords();
if (keywords.length) {
preview += `: ${removeFields(keywords.join(' | '))}`;
} else if (snippet.value) {
preview += `: ${removeFields(snippet.value)}`;
}
return {
key: snippet.key,
value: snippet.value,
snippet: snippet.key,
property: snippet.property,
keywords: keywords.map(kw => {
const m = kw.match(/^[\w-]+/);
return m && {
key: m[0],
preview: removeFields(kw),
snippet: kw
};
}).filter(Boolean),
preview
};
});
}
/**
* Returns markup snippets list
* @param {SnippetsRegistry} registry
* @param {Object} config
* @return {Array}
*/
function getMarkupSnippets(registry, config) {
return registry.all({ type: 'string' }).map(snippet => ({
key: snippet.key,
value: snippet.value,
preview: removeFields(expand$2(snippet.value, config)),
snippet: snippet.key
}));
}
function expandedAbbreviationCompletion(editor, pos, abbrModel) {
let preview = abbrModel.preview;
if (preview.length > 500) {
preview = preview.slice(0, 500) + '...';
}
return new EmmetCompletion('expanded-abbreviation', editor, abbrModel.range, 'Expand abbreviation', preview, (editor, range) => abbrModel.insert(editor, range));
}
/**
* Extracts prefix from the end of given string that matches `match` regexp
* @param {String} str
* @param {RegExp} match
* @return {String} Extracted prefix
*/
function extractPrefix(str, match) {
let offset = str.length;
while (offset > 0) {
if (!match.test(str[offset - 1])) {
break;
}
offset--;
}
return str.slice(offset);
}
let EmmetCompletion = class EmmetCompletion {
/**
* @param {String} type
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Range} range
* @param {String} name
* @param {String} preview
* @param {Function} snippet
*/
constructor(type, editor, range, name, preview, snippet) {
this.type = type;
this.editor = editor;
this.range = range;
this.name = name;
this.preview = preview;
this.snippet = snippet;
this._inserted = false;
}
insert() {
if (!this._inserted) {
this._inserted = true;
if (typeof this.snippet === 'function') {
this.snippet(this.editor, this.range);
} else {
insertSnippet(this.editor, this.range, this.snippet);
}
clearMarkers(this.editor);
}
}
};
/**
* A syntax-specific model container, used to get unified access to underlying
* parsed document
*/
let SyntaxModel = class SyntaxModel {
/**
* @param {Object} dom Parsed document tree
* @param {String} type Type of document (html, stylesheet, etc.)
* @param {String} [syntax] Optional document syntax like html, xhtml or xml
*/
constructor(dom, type, syntax) {
this.dom = dom;
this.type = type;
this.syntax = syntax;
}
/**
* Returns best matching node for given point
* @param {CodeMirror.Pos} pos
* @param {Boolean} [exclude] Exclude nodes start and end positions from
* search
* @return {Node}
*/
nodeForPoint(pos, exclude) {
let ctx = this.dom.firstChild;
let found = null;
while (ctx) {
if (containsPos(rangeFromNode(ctx), pos, exclude)) {
// Found matching tag. Try to find deeper, more accurate match
found = ctx;
ctx = ctx.firstChild;
} else {
ctx = ctx.nextSibling;
}
}
return found;
}
};
/**
* Creates DOM-like model for given text editor
* @param {CodeMirror} editor
* @param {String} syntax
* @return {Node}
*/
function create(editor, syntax) {
const stream = new CodeMirrorStreamReader(editor);
const xml = syntax === 'xml';
try {
return new SyntaxModel(html_matcher_es(stream, { xml }), 'html', syntax || 'html');
} catch (err) {
console.warn(err);
}
}
function getModel(editor) {
const syntax = getSyntax$1(editor);
return create(editor, syntax);
}
function getCachedModel(editor) {
if (!editor.state._emmetModel) {
editor.state._emmetModel = getModel(editor);
}
return editor.state._emmetModel;
}
function resetCachedModel(editor) {
editor.state._emmetModel = null;
}
/**
* Returns parser-supported syntax of given editor (like 'html', 'css' etc.).
* Returns `null` if editors syntax is unsupported
* @param {CodeMirror} editor
* @return {String}
*/
function getSyntax$1(editor) {
const mode = editor.getMode();
if (mode.name === 'htmlmixed') {
return 'html';
}
return mode.name === 'xml' ? mode.configuration : mode.name;
}
const openTagMark = 'emmet-open-tag';
const closeTagMark = 'emmet-close-tag';
/**
* Finds matching tag pair for given position in editor
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} pos
* @return {Object}
*/
function matchTag(editor, pos) {
pos = pos || editor.getCursor();
// First, check if there are tag markers in editor
const marked = getMarkedTag(editor);
// If marks found, validate them: make sure cursor is either in open
// or close tag
if (marked) {
if (containsPos(marked.open.find(), pos)) {
// Point is inside open tag, make sure if theres a closing tag,
// it matches open tag content
if (!marked.close || emmet_codemirror_plugin_es_text(editor, marked.open) === emmet_codemirror_plugin_es_text(editor, marked.close)) {
return marked;
}
} else if (marked.close) {
// Theres a close tag, make sure pointer is inside it and it matches
// open tag
if (containsPos(marked.close.find(), pos) && emmet_codemirror_plugin_es_text(editor, marked.open) === emmet_codemirror_plugin_es_text(editor, marked.close)) {
return marked;
}
}
}
// Markers are not valid anymore, remove them
clearTagMatch(editor);
// Find new tag pair from parsed HTML model and mark them
const node = findTagPair(editor, pos);
if (node && node.type === 'tag') {
return {
open: createTagMark(editor, node.open.name, openTagMark),
close: node.close && createTagMark(editor, node.close.name, closeTagMark)
};
}
}
function getMarkedTag(editor) {
let open, close;
editor.getAllMarks().forEach(mark => {
if (mark.className === openTagMark) {
open = mark;
} else if (mark.className === closeTagMark) {
close = mark;
}
});
return open ? { open, close } : null;
}
/**
* Removes all matched tag pair markers from editor
* @param {CodeMirror.Editor} editor
*/
function clearTagMatch(editor) {
editor.getAllMarks().forEach(mark => {
if (mark.className === openTagMark || mark.className === closeTagMark) {
mark.clear();
}
});
}
/**
* Finds tag pair (open and close, if any) form parsed HTML model of given editor
* @param {CodeMirror.Editor} editor
* @param {CodeMirror.Position} pos
* @return {Object}
*/
function findTagPair(editor, pos) {
const model = editor.getEmmetDocumentModel();
return model && model.nodeForPoint(pos || editor.getCursor());
}
function createTagMark(editor, tag, className) {
return editor.markText(tag.start, tag.end, {
className,
inclusiveLeft: true,
inclusiveRight: true,
clearWhenEmpty: false
});
}
function emmet_codemirror_plugin_es_text(editor, mark) {
const range = mark.find();
return range ? editor.getRange(range.from, range.to) : '';
}
function renameTag(editor, obj) {
const tag = getMarkedTag(editor);
const pos = obj.from;
if (!tag) {
return;
}
if (containsPos(tag.open.find(), pos) && tag.close) {
// Update happened inside open tag, update close tag as well
updateTag(editor, tag.open, tag.close);
} else if (tag.close && containsPos(tag.close.find(), pos)) {
// Update happened inside close tag, update open tag as well
updateTag(editor, tag.close, tag.open);
}
}
function updateTag(editor, source, dest) {
const name = text$1(editor, source);
const range = dest.find();
const m = name.match(/[\w:.-]+/);
const newName = !name ? '' : m && m[0];
if (newName != null) {
if (editor.getRange(range.from, range.to) !== newName) {
editor.replaceRange(newName, range.from, range.to);
}
} else {
// User entered something that wasnt a valid tag name.
clearTagMatch(editor);
}
}
function text$1(editor, mark) {
const range = mark.find();
return range ? editor.getRange(range.from, range.to) : '';
}
/**
* Registers Emmet extension on given CodeMirror constructor.
* This file is designed to be imported somehow into the app (CommonJS, ES6,
* Rollup/Webpack/whatever). If you simply want to add a <script> into your page
* that registers Emmet extension on global CodeMirror constructor, use
* `browser.js` instead
*/
function registerEmmetExtension(CodeMirror) {
// Register Emmet commands
emmet_codemirror_plugin_es__extends(CodeMirror.commands, {
emmetExpandAbbreviation: editor => expandAbbreviation(editor, true),
emmetExpandAbbreviationAll: editor => expandAbbreviation(editor, false),
emmetInsertLineBreak,
emmetWrapWithAbbreviation: wrapWithAbbreviation
});
const markOnEditorChange = editor => markAbbreviation(editor, editor.getCursor());
// Defines options that allows abbreviation marking in text editor
CodeMirror.defineOption('markEmmetAbbreviation', true, (editor, value) => {
if (value) {
editor.on('change', markOnEditorChange);
} else {
editor.off('change', markOnEditorChange);
clearMarkers(editor);
}
});
CodeMirror.defineOption('autoRenameTags', true, (editor, value) => {
value ? editor.on('change', renameTag) : editor.off('change', renameTag);
});
// Enable/disable leading angle bracket for JSX abbreviations
CodeMirror.defineOption('jsxBracket', true);
CodeMirror.defineOption('markTagPairs', false, (editor, value) => {
if (value) {
editor.on('cursorActivity', matchTag);
editor.on('change', resetCachedModel);
} else {
editor.off('cursorActivity', matchTag);
editor.off('change', resetCachedModel);
resetCachedModel(editor);
clearTagMatch(editor);
}
});
// Emmet config: https://github.com/emmetio/config
CodeMirror.defineOption('emmet', {});
/**
* Returns Emmet completions for context from `pos` position.
* Abbreviations are calculated for marked abbreviation at given position.
* If no parsed abbreviation marker is available and `force` argument is
* given, tries to mark abbreviation and populate completions list again.
* @param {CodeMirror.Position} [pos]
* @param {Boolean} [force]
* @return {EmmetCompletion[]}
*/
CodeMirror.defineExtension('getEmmetCompletions', function (pos, force) {
const editor = this;
if (typeof pos === 'boolean') {
force = pos;
pos = null;
}
pos = pos || editor.getCursor();
const autocomplete = autocompleteProvider(editor, pos);
if (autocomplete && autocomplete.completions.length) {
if (editor.getOption('markEmmetAbbreviation')) {
// Ensure abbreviation marker exists
if (!findMarker(editor, pos) && force) {
clearMarkers(editor);
createMarker(autocomplete.model);
}
}
return {
from: autocomplete.abbreviation.range.from,
to: autocomplete.abbreviation.range.to,
list: autocomplete.completions
};
}
});
/**
* Returns valid Emmet abbreviation and its location in editor from given
* position
* @param {CodeMirror.Pos} [pos] Position from which abbreviation should be
* extracted. If not given, current cursor position is used
* @return {Abbreviation}
*/
CodeMirror.defineExtension('getEmmetAbbreviation', function (pos, contextAware) {
return abbreviationFromPosition(this, pos || this.getCursor(), contextAware);
});
CodeMirror.defineExtension('findEmmetMarker', function (pos) {
return findMarker(this, pos || this.getCursor());
});
CodeMirror.defineExtension('getEmmetDocumentModel', function () {
const editor = this;
return editor.getOption('markTagPairs') ? getCachedModel(editor) : getModel(editor);
});
}
/* harmony default export */ var emmet_codemirror_plugin_es = __webpack_exports__["a"] = (registerEmmetExtension);
//# sourceMappingURL=emmet-codemirror-plugin.es.js.map
/***/ }),
/***/ "1JcR":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var Pos = CodeMirror.Pos;
function cmp(a, b) {
return a.line - b.line || a.ch - b.ch;
}
var nameStartChar = "A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
var nameChar = nameStartChar + "\-\:\.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
var xmlTagStart = new RegExp("<(/?)([" + nameStartChar + "][" + nameChar + "]*)", "g");
function Iter(cm, line, ch, range) {
this.line = line;this.ch = ch;
this.cm = cm;this.text = cm.getLine(line);
this.min = range ? Math.max(range.from, cm.firstLine()) : cm.firstLine();
this.max = range ? Math.min(range.to - 1, cm.lastLine()) : cm.lastLine();
}
function tagAt(iter, ch) {
var type = iter.cm.getTokenTypeAt(Pos(iter.line, ch));
return type && /\btag\b/.test(type);
}
function nextLine(iter) {
if (iter.line >= iter.max) return;
iter.ch = 0;
iter.text = iter.cm.getLine(++iter.line);
return true;
}
function prevLine(iter) {
if (iter.line <= iter.min) return;
iter.text = iter.cm.getLine(--iter.line);
iter.ch = iter.text.length;
return true;
}
function toTagEnd(iter) {
for (;;) {
var gt = iter.text.indexOf(">", iter.ch);
if (gt == -1) {
if (nextLine(iter)) continue;else return;
}
if (!tagAt(iter, gt + 1)) {
iter.ch = gt + 1;continue;
}
var lastSlash = iter.text.lastIndexOf("/", gt);
var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt));
iter.ch = gt + 1;
return selfClose ? "selfClose" : "regular";
}
}
function toTagStart(iter) {
for (;;) {
var lt = iter.ch ? iter.text.lastIndexOf("<", iter.ch - 1) : -1;
if (lt == -1) {
if (prevLine(iter)) continue;else return;
}
if (!tagAt(iter, lt + 1)) {
iter.ch = lt;continue;
}
xmlTagStart.lastIndex = lt;
iter.ch = lt;
var match = xmlTagStart.exec(iter.text);
if (match && match.index == lt) return match;
}
}
function toNextTag(iter) {
for (;;) {
xmlTagStart.lastIndex = iter.ch;
var found = xmlTagStart.exec(iter.text);
if (!found) {
if (nextLine(iter)) continue;else return;
}
if (!tagAt(iter, found.index + 1)) {
iter.ch = found.index + 1;continue;
}
iter.ch = found.index + found[0].length;
return found;
}
}
function toPrevTag(iter) {
for (;;) {
var gt = iter.ch ? iter.text.lastIndexOf(">", iter.ch - 1) : -1;
if (gt == -1) {
if (prevLine(iter)) continue;else return;
}
if (!tagAt(iter, gt + 1)) {
iter.ch = gt;continue;
}
var lastSlash = iter.text.lastIndexOf("/", gt);
var selfClose = lastSlash > -1 && !/\S/.test(iter.text.slice(lastSlash + 1, gt));
iter.ch = gt + 1;
return selfClose ? "selfClose" : "regular";
}
}
function findMatchingClose(iter, tag) {
var stack = [];
for (;;) {
var next = toNextTag(iter),
end,
startLine = iter.line,
startCh = iter.ch - (next ? next[0].length : 0);
if (!next || !(end = toTagEnd(iter))) return;
if (end == "selfClose") continue;
if (next[1]) {
// closing tag
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == next[2]) {
stack.length = i;
break;
}
if (i < 0 && (!tag || tag == next[2])) return {
tag: next[2],
from: Pos(startLine, startCh),
to: Pos(iter.line, iter.ch)
};
} else {
// opening tag
stack.push(next[2]);
}
}
}
function findMatchingOpen(iter, tag) {
var stack = [];
for (;;) {
var prev = toPrevTag(iter);
if (!prev) return;
if (prev == "selfClose") {
toTagStart(iter);continue;
}
var endLine = iter.line,
endCh = iter.ch;
var start = toTagStart(iter);
if (!start) return;
if (start[1]) {
// closing tag
stack.push(start[2]);
} else {
// opening tag
for (var i = stack.length - 1; i >= 0; --i) if (stack[i] == start[2]) {
stack.length = i;
break;
}
if (i < 0 && (!tag || tag == start[2])) return {
tag: start[2],
from: Pos(iter.line, iter.ch),
to: Pos(endLine, endCh)
};
}
}
}
CodeMirror.registerHelper("fold", "xml", function (cm, start) {
var iter = new Iter(cm, start.line, 0);
for (;;) {
var openTag = toNextTag(iter);
if (!openTag || iter.line != start.line) return;
var end = toTagEnd(iter);
if (!end) return;
if (!openTag[1] && end != "selfClose") {
var startPos = Pos(iter.line, iter.ch);
var endPos = findMatchingClose(iter, openTag[2]);
return endPos && cmp(endPos.from, startPos) > 0 ? { from: startPos, to: endPos.from } : null;
}
}
});
CodeMirror.findMatchingTag = function (cm, pos, range) {
var iter = new Iter(cm, pos.line, pos.ch, range);
if (iter.text.indexOf(">") == -1 && iter.text.indexOf("<") == -1) return;
var end = toTagEnd(iter),
to = end && Pos(iter.line, iter.ch);
var start = end && toTagStart(iter);
if (!end || !start || cmp(iter, pos) > 0) return;
var here = { from: Pos(iter.line, iter.ch), to: to, tag: start[2] };
if (end == "selfClose") return { open: here, close: null, at: "open" };
if (start[1]) {
// closing tag
return { open: findMatchingOpen(iter, start[2]), close: here, at: "close" };
} else {
// opening tag
iter = new Iter(cm, to.line, to.ch, range);
return { open: here, close: findMatchingClose(iter, start[2]), at: "open" };
}
};
CodeMirror.findEnclosingTag = function (cm, pos, range, tag) {
var iter = new Iter(cm, pos.line, pos.ch, range);
for (;;) {
var open = findMatchingOpen(iter, tag);
if (!open) break;
var forward = new Iter(cm, pos.line, pos.ch, range);
var close = findMatchingClose(forward, open.tag);
if (close) return { open: open, close: close };
}
};
// Used by addon/edit/closetag.js
CodeMirror.scanForClosingTag = function (cm, pos, name, end) {
var iter = new Iter(cm, pos.line, pos.ch, end ? { from: 0, to: end } : null);
return findMatchingClose(iter, name);
};
});
/***/ }),
/***/ "29F7":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var Pos = CodeMirror.Pos;
function regexpFlags(regexp) {
var flags = regexp.flags;
return flags != null ? flags : (regexp.ignoreCase ? "i" : "") + (regexp.global ? "g" : "") + (regexp.multiline ? "m" : "");
}
function ensureFlags(regexp, flags) {
var current = regexpFlags(regexp),
target = current;
for (var i = 0; i < flags.length; i++) if (target.indexOf(flags.charAt(i)) == -1) target += flags.charAt(i);
return current == target ? regexp : new RegExp(regexp.source, target);
}
function maybeMultiline(regexp) {
return (/\\s|\\n|\n|\\W|\\D|\[\^/.test(regexp.source)
);
}
function searchRegexpForward(doc, regexp, start) {
regexp = ensureFlags(regexp, "g");
for (var line = start.line, ch = start.ch, last = doc.lastLine(); line <= last; line++, ch = 0) {
regexp.lastIndex = ch;
var string = doc.getLine(line),
match = regexp.exec(string);
if (match) return { from: Pos(line, match.index),
to: Pos(line, match.index + match[0].length),
match: match };
}
}
function searchRegexpForwardMultiline(doc, regexp, start) {
if (!maybeMultiline(regexp)) return searchRegexpForward(doc, regexp, start);
regexp = ensureFlags(regexp, "gm");
var string,
chunk = 1;
for (var line = start.line, last = doc.lastLine(); line <= last;) {
// This grows the search buffer in exponentially-sized chunks
// between matches, so that nearby matches are fast and don't
// require concatenating the whole document (in case we're
// searching for something that has tons of matches), but at the
// same time, the amount of retries is limited.
for (var i = 0; i < chunk; i++) {
if (line > last) break;
var curLine = doc.getLine(line++);
string = string == null ? curLine : string + "\n" + curLine;
}
chunk = chunk * 2;
regexp.lastIndex = start.ch;
var match = regexp.exec(string);
if (match) {
var before = string.slice(0, match.index).split("\n"),
inside = match[0].split("\n");
var startLine = start.line + before.length - 1,
startCh = before[before.length - 1].length;
return { from: Pos(startLine, startCh),
to: Pos(startLine + inside.length - 1, inside.length == 1 ? startCh + inside[0].length : inside[inside.length - 1].length),
match: match };
}
}
}
function lastMatchIn(string, regexp) {
var cutOff = 0,
match;
for (;;) {
regexp.lastIndex = cutOff;
var newMatch = regexp.exec(string);
if (!newMatch) return match;
match = newMatch;
cutOff = match.index + (match[0].length || 1);
if (cutOff == string.length) return match;
}
}
function searchRegexpBackward(doc, regexp, start) {
regexp = ensureFlags(regexp, "g");
for (var line = start.line, ch = start.ch, first = doc.firstLine(); line >= first; line--, ch = -1) {
var string = doc.getLine(line);
if (ch > -1) string = string.slice(0, ch);
var match = lastMatchIn(string, regexp);
if (match) return { from: Pos(line, match.index),
to: Pos(line, match.index + match[0].length),
match: match };
}
}
function searchRegexpBackwardMultiline(doc, regexp, start) {
regexp = ensureFlags(regexp, "gm");
var string,
chunk = 1;
for (var line = start.line, first = doc.firstLine(); line >= first;) {
for (var i = 0; i < chunk; i++) {
var curLine = doc.getLine(line--);
string = string == null ? curLine.slice(0, start.ch) : curLine + "\n" + string;
}
chunk *= 2;
var match = lastMatchIn(string, regexp);
if (match) {
var before = string.slice(0, match.index).split("\n"),
inside = match[0].split("\n");
var startLine = line + before.length,
startCh = before[before.length - 1].length;
return { from: Pos(startLine, startCh),
to: Pos(startLine + inside.length - 1, inside.length == 1 ? startCh + inside[0].length : inside[inside.length - 1].length),
match: match };
}
}
}
var doFold, noFold;
if (String.prototype.normalize) {
doFold = function (str) {
return str.normalize("NFD").toLowerCase();
};
noFold = function (str) {
return str.normalize("NFD");
};
} else {
doFold = function (str) {
return str.toLowerCase();
};
noFold = function (str) {
return str;
};
}
// Maps a position in a case-folded line back to a position in the original line
// (compensating for codepoints increasing in number during folding)
function adjustPos(orig, folded, pos, foldFunc) {
if (orig.length == folded.length) return pos;
for (var min = 0, max = pos + Math.max(0, orig.length - folded.length);;) {
if (min == max) return min;
var mid = min + max >> 1;
var len = foldFunc(orig.slice(0, mid)).length;
if (len == pos) return mid;else if (len > pos) max = mid;else min = mid + 1;
}
}
function searchStringForward(doc, query, start, caseFold) {
// Empty string would match anything and never progress, so we
// define it to match nothing instead.
if (!query.length) return null;
var fold = caseFold ? doFold : noFold;
var lines = fold(query).split(/\r|\n\r?/);
search: for (var line = start.line, ch = start.ch, last = doc.lastLine() + 1 - lines.length; line <= last; line++, ch = 0) {
var orig = doc.getLine(line).slice(ch),
string = fold(orig);
if (lines.length == 1) {
var found = string.indexOf(lines[0]);
if (found == -1) continue search;
var start = adjustPos(orig, string, found, fold) + ch;
return { from: Pos(line, adjustPos(orig, string, found, fold) + ch),
to: Pos(line, adjustPos(orig, string, found + lines[0].length, fold) + ch) };
} else {
var cutFrom = string.length - lines[0].length;
if (string.slice(cutFrom) != lines[0]) continue search;
for (var i = 1; i < lines.length - 1; i++) if (fold(doc.getLine(line + i)) != lines[i]) continue search;
var end = doc.getLine(line + lines.length - 1),
endString = fold(end),
lastLine = lines[lines.length - 1];
if (endString.slice(0, lastLine.length) != lastLine) continue search;
return { from: Pos(line, adjustPos(orig, string, cutFrom, fold) + ch),
to: Pos(line + lines.length - 1, adjustPos(end, endString, lastLine.length, fold)) };
}
}
}
function searchStringBackward(doc, query, start, caseFold) {
if (!query.length) return null;
var fold = caseFold ? doFold : noFold;
var lines = fold(query).split(/\r|\n\r?/);
search: for (var line = start.line, ch = start.ch, first = doc.firstLine() - 1 + lines.length; line >= first; line--, ch = -1) {
var orig = doc.getLine(line);
if (ch > -1) orig = orig.slice(0, ch);
var string = fold(orig);
if (lines.length == 1) {
var found = string.lastIndexOf(lines[0]);
if (found == -1) continue search;
return { from: Pos(line, adjustPos(orig, string, found, fold)),
to: Pos(line, adjustPos(orig, string, found + lines[0].length, fold)) };
} else {
var lastLine = lines[lines.length - 1];
if (string.slice(0, lastLine.length) != lastLine) continue search;
for (var i = 1, start = line - lines.length + 1; i < lines.length - 1; i++) if (fold(doc.getLine(start + i)) != lines[i]) continue search;
var top = doc.getLine(line + 1 - lines.length),
topString = fold(top);
if (topString.slice(topString.length - lines[0].length) != lines[0]) continue search;
return { from: Pos(line + 1 - lines.length, adjustPos(top, topString, top.length - lines[0].length, fold)),
to: Pos(line, adjustPos(orig, string, lastLine.length, fold)) };
}
}
}
function SearchCursor(doc, query, pos, options) {
this.atOccurrence = false;
this.doc = doc;
pos = pos ? doc.clipPos(pos) : Pos(0, 0);
this.pos = { from: pos, to: pos };
var caseFold;
if (typeof options == "object") {
caseFold = options.caseFold;
} else {
// Backwards compat for when caseFold was the 4th argument
caseFold = options;
options = null;
}
if (typeof query == "string") {
if (caseFold == null) caseFold = false;
this.matches = function (reverse, pos) {
return (reverse ? searchStringBackward : searchStringForward)(doc, query, pos, caseFold);
};
} else {
query = ensureFlags(query, "gm");
if (!options || options.multiline !== false) this.matches = function (reverse, pos) {
return (reverse ? searchRegexpBackwardMultiline : searchRegexpForwardMultiline)(doc, query, pos);
};else this.matches = function (reverse, pos) {
return (reverse ? searchRegexpBackward : searchRegexpForward)(doc, query, pos);
};
}
}
SearchCursor.prototype = {
findNext: function () {
return this.find(false);
},
findPrevious: function () {
return this.find(true);
},
find: function (reverse) {
var result = this.matches(reverse, this.doc.clipPos(reverse ? this.pos.from : this.pos.to));
// Implements weird auto-growing behavior on null-matches for
// backwards-compatiblity with the vim code (unfortunately)
while (result && CodeMirror.cmpPos(result.from, result.to) == 0) {
if (reverse) {
if (result.from.ch) result.from = Pos(result.from.line, result.from.ch - 1);else if (result.from.line == this.doc.firstLine()) result = null;else result = this.matches(reverse, this.doc.clipPos(Pos(result.from.line - 1)));
} else {
if (result.to.ch < this.doc.getLine(result.to.line).length) result.to = Pos(result.to.line, result.to.ch + 1);else if (result.to.line == this.doc.lastLine()) result = null;else result = this.matches(reverse, Pos(result.to.line + 1, 0));
}
}
if (result) {
this.pos = result;
this.atOccurrence = true;
return this.pos.match || true;
} else {
var end = Pos(reverse ? this.doc.firstLine() : this.doc.lastLine() + 1, 0);
this.pos = { from: end, to: end };
return this.atOccurrence = false;
}
},
from: function () {
if (this.atOccurrence) return this.pos.from;
},
to: function () {
if (this.atOccurrence) return this.pos.to;
},
replace: function (newText, origin) {
if (!this.atOccurrence) return;
var lines = CodeMirror.splitLines(newText);
this.doc.replaceRange(lines, this.pos.from, this.pos.to, origin);
this.pos.to = Pos(this.pos.from.line + lines.length - 1, lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
}
};
CodeMirror.defineExtension("getSearchCursor", function (query, pos, caseFold) {
return new SearchCursor(this.doc, query, pos, caseFold);
});
CodeMirror.defineDocExtension("getSearchCursor", function (query, pos, caseFold) {
return new SearchCursor(this, query, pos, caseFold);
});
CodeMirror.defineExtension("selectMatches", function (query, caseFold) {
var ranges = [];
var cur = this.getSearchCursor(query, this.getCursor("from"), caseFold);
while (cur.findNext()) {
if (CodeMirror.cmpPos(cur.to(), this.getCursor("to")) > 0) break;
ranges.push({ anchor: cur.from(), head: cur.to() });
}
if (ranges.length) this.setSelections(ranges, 0);
});
});
/***/ }),
/***/ "4Bm0":
/***/ (function(module, exports) {
if (typeof Object.create === 'function') {
// implementation from standard node.js 'util' module
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
};
} else {
// old school shim for old browsers
module.exports = function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
var TempCtor = function () {};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
};
}
/***/ }),
/***/ "4E2n":
/***/ (function(module, exports, __webpack_require__) {
(function webpackUniversalModuleDefinition(root, factory) {
/* istanbul ignore next */
if (true) module.exports = factory();else if (typeof define === 'function' && define.amd) define([], factory);
/* istanbul ignore next */
else if (typeof exports === 'object') exports["esprima"] = factory();else root["esprima"] = factory();
})(this, function () {
return (/******/function (modules) {
// webpackBootstrap
/******/ // The module cache
/******/var installedModules = {};
/******/ // The require function
/******/function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/* istanbul ignore if */
/******/if (installedModules[moduleId])
/******/return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/var module = installedModules[moduleId] = {
/******/exports: {},
/******/id: moduleId,
/******/loaded: false
/******/ };
/******/ // Execute the module function
/******/modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/module.loaded = true;
/******/ // Return the exports of the module
/******/return module.exports;
/******/
}
/******/ // expose the modules object (__webpack_modules__)
/******/__webpack_require__.m = modules;
/******/ // expose the module cache
/******/__webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/__webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/return __webpack_require__(0);
/******/
}(
/************************************************************************/
/******/[
/* 0 */
/***/function (module, exports, __webpack_require__) {
"use strict";
/*
Copyright JS Foundation and other contributors, https://js.foundation/
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var comment_handler_1 = __webpack_require__(1);
var jsx_parser_1 = __webpack_require__(3);
var parser_1 = __webpack_require__(8);
var tokenizer_1 = __webpack_require__(15);
function parse(code, options, delegate) {
var commentHandler = null;
var proxyDelegate = function (node, metadata) {
if (delegate) {
delegate(node, metadata);
}
if (commentHandler) {
commentHandler.visit(node, metadata);
}
};
var parserDelegate = typeof delegate === 'function' ? proxyDelegate : null;
var collectComment = false;
if (options) {
collectComment = typeof options.comment === 'boolean' && options.comment;
var attachComment = typeof options.attachComment === 'boolean' && options.attachComment;
if (collectComment || attachComment) {
commentHandler = new comment_handler_1.CommentHandler();
commentHandler.attach = attachComment;
options.comment = true;
parserDelegate = proxyDelegate;
}
}
var isModule = false;
if (options && typeof options.sourceType === 'string') {
isModule = options.sourceType === 'module';
}
var parser;
if (options && typeof options.jsx === 'boolean' && options.jsx) {
parser = new jsx_parser_1.JSXParser(code, options, parserDelegate);
} else {
parser = new parser_1.Parser(code, options, parserDelegate);
}
var program = isModule ? parser.parseModule() : parser.parseScript();
var ast = program;
if (collectComment && commentHandler) {
ast.comments = commentHandler.comments;
}
if (parser.config.tokens) {
ast.tokens = parser.tokens;
}
if (parser.config.tolerant) {
ast.errors = parser.errorHandler.errors;
}
return ast;
}
exports.parse = parse;
function parseModule(code, options, delegate) {
var parsingOptions = options || {};
parsingOptions.sourceType = 'module';
return parse(code, parsingOptions, delegate);
}
exports.parseModule = parseModule;
function parseScript(code, options, delegate) {
var parsingOptions = options || {};
parsingOptions.sourceType = 'script';
return parse(code, parsingOptions, delegate);
}
exports.parseScript = parseScript;
function tokenize(code, options, delegate) {
var tokenizer = new tokenizer_1.Tokenizer(code, options);
var tokens;
tokens = [];
try {
while (true) {
var token = tokenizer.getNextToken();
if (!token) {
break;
}
if (delegate) {
token = delegate(token);
}
tokens.push(token);
}
} catch (e) {
tokenizer.errorHandler.tolerate(e);
}
if (tokenizer.errorHandler.tolerant) {
tokens.errors = tokenizer.errors();
}
return tokens;
}
exports.tokenize = tokenize;
var syntax_1 = __webpack_require__(2);
exports.Syntax = syntax_1.Syntax;
// Sync with *.json manifests.
exports.version = '4.0.0';
/***/
},
/* 1 */
/***/function (module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var syntax_1 = __webpack_require__(2);
var CommentHandler = function () {
function CommentHandler() {
this.attach = false;
this.comments = [];
this.stack = [];
this.leading = [];
this.trailing = [];
}
CommentHandler.prototype.insertInnerComments = function (node, metadata) {
// innnerComments for properties empty block
// `function a() {/** comments **\/}`
if (node.type === syntax_1.Syntax.BlockStatement && node.body.length === 0) {
var innerComments = [];
for (var i = this.leading.length - 1; i >= 0; --i) {
var entry = this.leading[i];
if (metadata.end.offset >= entry.start) {
innerComments.unshift(entry.comment);
this.leading.splice(i, 1);
this.trailing.splice(i, 1);
}
}
if (innerComments.length) {
node.innerComments = innerComments;
}
}
};
CommentHandler.prototype.findTrailingComments = function (metadata) {
var trailingComments = [];
if (this.trailing.length > 0) {
for (var i = this.trailing.length - 1; i >= 0; --i) {
var entry_1 = this.trailing[i];
if (entry_1.start >= metadata.end.offset) {
trailingComments.unshift(entry_1.comment);
}
}
this.trailing.length = 0;
return trailingComments;
}
var entry = this.stack[this.stack.length - 1];
if (entry && entry.node.trailingComments) {
var firstComment = entry.node.trailingComments[0];
if (firstComment && firstComment.range[0] >= metadata.end.offset) {
trailingComments = entry.node.trailingComments;
delete entry.node.trailingComments;
}
}
return trailingComments;
};
CommentHandler.prototype.findLeadingComments = function (metadata) {
var leadingComments = [];
var target;
while (this.stack.length > 0) {
var entry = this.stack[this.stack.length - 1];
if (entry && entry.start >= metadata.start.offset) {
target = entry.node;
this.stack.pop();
} else {
break;
}
}
if (target) {
var count = target.leadingComments ? target.leadingComments.length : 0;
for (var i = count - 1; i >= 0; --i) {
var comment = target.leadingComments[i];
if (comment.range[1] <= metadata.start.offset) {
leadingComments.unshift(comment);
target.leadingComments.splice(i, 1);
}
}
if (target.leadingComments && target.leadingComments.length === 0) {
delete target.leadingComments;
}
return leadingComments;
}
for (var i = this.leading.length - 1; i >= 0; --i) {
var entry = this.leading[i];
if (entry.start <= metadata.start.offset) {
leadingComments.unshift(entry.comment);
this.leading.splice(i, 1);
}
}
return leadingComments;
};
CommentHandler.prototype.visitNode = function (node, metadata) {
if (node.type === syntax_1.Syntax.Program && node.body.length > 0) {
return;
}
this.insertInnerComments(node, metadata);
var trailingComments = this.findTrailingComments(metadata);
var leadingComments = this.findLeadingComments(metadata);
if (leadingComments.length > 0) {
node.leadingComments = leadingComments;
}
if (trailingComments.length > 0) {
node.trailingComments = trailingComments;
}
this.stack.push({
node: node,
start: metadata.start.offset
});
};
CommentHandler.prototype.visitComment = function (node, metadata) {
var type = node.type[0] === 'L' ? 'Line' : 'Block';
var comment = {
type: type,
value: node.value
};
if (node.range) {
comment.range = node.range;
}
if (node.loc) {
comment.loc = node.loc;
}
this.comments.push(comment);
if (this.attach) {
var entry = {
comment: {
type: type,
value: node.value,
range: [metadata.start.offset, metadata.end.offset]
},
start: metadata.start.offset
};
if (node.loc) {
entry.comment.loc = node.loc;
}
node.type = type;
this.leading.push(entry);
this.trailing.push(entry);
}
};
CommentHandler.prototype.visit = function (node, metadata) {
if (node.type === 'LineComment') {
this.visitComment(node, metadata);
} else if (node.type === 'BlockComment') {
this.visitComment(node, metadata);
} else if (this.attach) {
this.visitNode(node, metadata);
}
};
return CommentHandler;
}();
exports.CommentHandler = CommentHandler;
/***/
},
/* 2 */
/***/function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Syntax = {
AssignmentExpression: 'AssignmentExpression',
AssignmentPattern: 'AssignmentPattern',
ArrayExpression: 'ArrayExpression',
ArrayPattern: 'ArrayPattern',
ArrowFunctionExpression: 'ArrowFunctionExpression',
AwaitExpression: 'AwaitExpression',
BlockStatement: 'BlockStatement',
BinaryExpression: 'BinaryExpression',
BreakStatement: 'BreakStatement',
CallExpression: 'CallExpression',
CatchClause: 'CatchClause',
ClassBody: 'ClassBody',
ClassDeclaration: 'ClassDeclaration',
ClassExpression: 'ClassExpression',
ConditionalExpression: 'ConditionalExpression',
ContinueStatement: 'ContinueStatement',
DoWhileStatement: 'DoWhileStatement',
DebuggerStatement: 'DebuggerStatement',
EmptyStatement: 'EmptyStatement',
ExportAllDeclaration: 'ExportAllDeclaration',
ExportDefaultDeclaration: 'ExportDefaultDeclaration',
ExportNamedDeclaration: 'ExportNamedDeclaration',
ExportSpecifier: 'ExportSpecifier',
ExpressionStatement: 'ExpressionStatement',
ForStatement: 'ForStatement',
ForOfStatement: 'ForOfStatement',
ForInStatement: 'ForInStatement',
FunctionDeclaration: 'FunctionDeclaration',
FunctionExpression: 'FunctionExpression',
Identifier: 'Identifier',
IfStatement: 'IfStatement',
ImportDeclaration: 'ImportDeclaration',
ImportDefaultSpecifier: 'ImportDefaultSpecifier',
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier',
ImportSpecifier: 'ImportSpecifier',
Literal: 'Literal',
LabeledStatement: 'LabeledStatement',
LogicalExpression: 'LogicalExpression',
MemberExpression: 'MemberExpression',
MetaProperty: 'MetaProperty',
MethodDefinition: 'MethodDefinition',
NewExpression: 'NewExpression',
ObjectExpression: 'ObjectExpression',
ObjectPattern: 'ObjectPattern',
Program: 'Program',
Property: 'Property',
RestElement: 'RestElement',
ReturnStatement: 'ReturnStatement',
SequenceExpression: 'SequenceExpression',
SpreadElement: 'SpreadElement',
Super: 'Super',
SwitchCase: 'SwitchCase',
SwitchStatement: 'SwitchStatement',
TaggedTemplateExpression: 'TaggedTemplateExpression',
TemplateElement: 'TemplateElement',
TemplateLiteral: 'TemplateLiteral',
ThisExpression: 'ThisExpression',
ThrowStatement: 'ThrowStatement',
TryStatement: 'TryStatement',
UnaryExpression: 'UnaryExpression',
UpdateExpression: 'UpdateExpression',
VariableDeclaration: 'VariableDeclaration',
VariableDeclarator: 'VariableDeclarator',
WhileStatement: 'WhileStatement',
WithStatement: 'WithStatement',
YieldExpression: 'YieldExpression'
};
/***/
},
/* 3 */
/***/function (module, exports, __webpack_require__) {
"use strict";
/* istanbul ignore next */
var __extends = this && this.__extends || function () {
var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
return function (d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}();
Object.defineProperty(exports, "__esModule", { value: true });
var character_1 = __webpack_require__(4);
var JSXNode = __webpack_require__(5);
var jsx_syntax_1 = __webpack_require__(6);
var Node = __webpack_require__(7);
var parser_1 = __webpack_require__(8);
var token_1 = __webpack_require__(13);
var xhtml_entities_1 = __webpack_require__(14);
token_1.TokenName[100 /* Identifier */] = 'JSXIdentifier';
token_1.TokenName[101 /* Text */] = 'JSXText';
// Fully qualified element name, e.g. <svg:path> returns "svg:path"
function getQualifiedElementName(elementName) {
var qualifiedName;
switch (elementName.type) {
case jsx_syntax_1.JSXSyntax.JSXIdentifier:
var id = elementName;
qualifiedName = id.name;
break;
case jsx_syntax_1.JSXSyntax.JSXNamespacedName:
var ns = elementName;
qualifiedName = getQualifiedElementName(ns.namespace) + ':' + getQualifiedElementName(ns.name);
break;
case jsx_syntax_1.JSXSyntax.JSXMemberExpression:
var expr = elementName;
qualifiedName = getQualifiedElementName(expr.object) + '.' + getQualifiedElementName(expr.property);
break;
/* istanbul ignore next */
default:
break;
}
return qualifiedName;
}
var JSXParser = function (_super) {
__extends(JSXParser, _super);
function JSXParser(code, options, delegate) {
return _super.call(this, code, options, delegate) || this;
}
JSXParser.prototype.parsePrimaryExpression = function () {
return this.match('<') ? this.parseJSXRoot() : _super.prototype.parsePrimaryExpression.call(this);
};
JSXParser.prototype.startJSX = function () {
// Unwind the scanner before the lookahead token.
this.scanner.index = this.startMarker.index;
this.scanner.lineNumber = this.startMarker.line;
this.scanner.lineStart = this.startMarker.index - this.startMarker.column;
};
JSXParser.prototype.finishJSX = function () {
// Prime the next lookahead.
this.nextToken();
};
JSXParser.prototype.reenterJSX = function () {
this.startJSX();
this.expectJSX('}');
// Pop the closing '}' added from the lookahead.
if (this.config.tokens) {
this.tokens.pop();
}
};
JSXParser.prototype.createJSXNode = function () {
this.collectComments();
return {
index: this.scanner.index,
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
};
};
JSXParser.prototype.createJSXChildNode = function () {
return {
index: this.scanner.index,
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
};
};
JSXParser.prototype.scanXHTMLEntity = function (quote) {
var result = '&';
var valid = true;
var terminated = false;
var numeric = false;
var hex = false;
while (!this.scanner.eof() && valid && !terminated) {
var ch = this.scanner.source[this.scanner.index];
if (ch === quote) {
break;
}
terminated = ch === ';';
result += ch;
++this.scanner.index;
if (!terminated) {
switch (result.length) {
case 2:
// e.g. '&#123;'
numeric = ch === '#';
break;
case 3:
if (numeric) {
// e.g. '&#x41;'
hex = ch === 'x';
valid = hex || character_1.Character.isDecimalDigit(ch.charCodeAt(0));
numeric = numeric && !hex;
}
break;
default:
valid = valid && !(numeric && !character_1.Character.isDecimalDigit(ch.charCodeAt(0)));
valid = valid && !(hex && !character_1.Character.isHexDigit(ch.charCodeAt(0)));
break;
}
}
}
if (valid && terminated && result.length > 2) {
// e.g. '&#x41;' becomes just '#x41'
var str = result.substr(1, result.length - 2);
if (numeric && str.length > 1) {
result = String.fromCharCode(parseInt(str.substr(1), 10));
} else if (hex && str.length > 2) {
result = String.fromCharCode(parseInt('0' + str.substr(1), 16));
} else if (!numeric && !hex && xhtml_entities_1.XHTMLEntities[str]) {
result = xhtml_entities_1.XHTMLEntities[str];
}
}
return result;
};
// Scan the next JSX token. This replaces Scanner#lex when in JSX mode.
JSXParser.prototype.lexJSX = function () {
var cp = this.scanner.source.charCodeAt(this.scanner.index);
// < > / : = { }
if (cp === 60 || cp === 62 || cp === 47 || cp === 58 || cp === 61 || cp === 123 || cp === 125) {
var value = this.scanner.source[this.scanner.index++];
return {
type: 7 /* Punctuator */
, value: value,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: this.scanner.index - 1,
end: this.scanner.index
};
}
// " '
if (cp === 34 || cp === 39) {
var start = this.scanner.index;
var quote = this.scanner.source[this.scanner.index++];
var str = '';
while (!this.scanner.eof()) {
var ch = this.scanner.source[this.scanner.index++];
if (ch === quote) {
break;
} else if (ch === '&') {
str += this.scanXHTMLEntity(quote);
} else {
str += ch;
}
}
return {
type: 8 /* StringLiteral */
, value: str,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: start,
end: this.scanner.index
};
}
// ... or .
if (cp === 46) {
var n1 = this.scanner.source.charCodeAt(this.scanner.index + 1);
var n2 = this.scanner.source.charCodeAt(this.scanner.index + 2);
var value = n1 === 46 && n2 === 46 ? '...' : '.';
var start = this.scanner.index;
this.scanner.index += value.length;
return {
type: 7 /* Punctuator */
, value: value,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: start,
end: this.scanner.index
};
}
// `
if (cp === 96) {
// Only placeholder, since it will be rescanned as a real assignment expression.
return {
type: 10 /* Template */
, value: '',
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: this.scanner.index,
end: this.scanner.index
};
}
// Identifer can not contain backslash (char code 92).
if (character_1.Character.isIdentifierStart(cp) && cp !== 92) {
var start = this.scanner.index;
++this.scanner.index;
while (!this.scanner.eof()) {
var ch = this.scanner.source.charCodeAt(this.scanner.index);
if (character_1.Character.isIdentifierPart(ch) && ch !== 92) {
++this.scanner.index;
} else if (ch === 45) {
// Hyphen (char code 45) can be part of an identifier.
++this.scanner.index;
} else {
break;
}
}
var id = this.scanner.source.slice(start, this.scanner.index);
return {
type: 100 /* Identifier */
, value: id,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: start,
end: this.scanner.index
};
}
return this.scanner.lex();
};
JSXParser.prototype.nextJSXToken = function () {
this.collectComments();
this.startMarker.index = this.scanner.index;
this.startMarker.line = this.scanner.lineNumber;
this.startMarker.column = this.scanner.index - this.scanner.lineStart;
var token = this.lexJSX();
this.lastMarker.index = this.scanner.index;
this.lastMarker.line = this.scanner.lineNumber;
this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
if (this.config.tokens) {
this.tokens.push(this.convertToken(token));
}
return token;
};
JSXParser.prototype.nextJSXText = function () {
this.startMarker.index = this.scanner.index;
this.startMarker.line = this.scanner.lineNumber;
this.startMarker.column = this.scanner.index - this.scanner.lineStart;
var start = this.scanner.index;
var text = '';
while (!this.scanner.eof()) {
var ch = this.scanner.source[this.scanner.index];
if (ch === '{' || ch === '<') {
break;
}
++this.scanner.index;
text += ch;
if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
++this.scanner.lineNumber;
if (ch === '\r' && this.scanner.source[this.scanner.index] === '\n') {
++this.scanner.index;
}
this.scanner.lineStart = this.scanner.index;
}
}
this.lastMarker.index = this.scanner.index;
this.lastMarker.line = this.scanner.lineNumber;
this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
var token = {
type: 101 /* Text */
, value: text,
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: start,
end: this.scanner.index
};
if (text.length > 0 && this.config.tokens) {
this.tokens.push(this.convertToken(token));
}
return token;
};
JSXParser.prototype.peekJSXToken = function () {
var state = this.scanner.saveState();
this.scanner.scanComments();
var next = this.lexJSX();
this.scanner.restoreState(state);
return next;
};
// Expect the next JSX token to match the specified punctuator.
// If not, an exception will be thrown.
JSXParser.prototype.expectJSX = function (value) {
var token = this.nextJSXToken();
if (token.type !== 7 /* Punctuator */ || token.value !== value) {
this.throwUnexpectedToken(token);
}
};
// Return true if the next JSX token matches the specified punctuator.
JSXParser.prototype.matchJSX = function (value) {
var next = this.peekJSXToken();
return next.type === 7 /* Punctuator */ && next.value === value;
};
JSXParser.prototype.parseJSXIdentifier = function () {
var node = this.createJSXNode();
var token = this.nextJSXToken();
if (token.type !== 100 /* Identifier */) {
this.throwUnexpectedToken(token);
}
return this.finalize(node, new JSXNode.JSXIdentifier(token.value));
};
JSXParser.prototype.parseJSXElementName = function () {
var node = this.createJSXNode();
var elementName = this.parseJSXIdentifier();
if (this.matchJSX(':')) {
var namespace = elementName;
this.expectJSX(':');
var name_1 = this.parseJSXIdentifier();
elementName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_1));
} else if (this.matchJSX('.')) {
while (this.matchJSX('.')) {
var object = elementName;
this.expectJSX('.');
var property = this.parseJSXIdentifier();
elementName = this.finalize(node, new JSXNode.JSXMemberExpression(object, property));
}
}
return elementName;
};
JSXParser.prototype.parseJSXAttributeName = function () {
var node = this.createJSXNode();
var attributeName;
var identifier = this.parseJSXIdentifier();
if (this.matchJSX(':')) {
var namespace = identifier;
this.expectJSX(':');
var name_2 = this.parseJSXIdentifier();
attributeName = this.finalize(node, new JSXNode.JSXNamespacedName(namespace, name_2));
} else {
attributeName = identifier;
}
return attributeName;
};
JSXParser.prototype.parseJSXStringLiteralAttribute = function () {
var node = this.createJSXNode();
var token = this.nextJSXToken();
if (token.type !== 8 /* StringLiteral */) {
this.throwUnexpectedToken(token);
}
var raw = this.getTokenRaw(token);
return this.finalize(node, new Node.Literal(token.value, raw));
};
JSXParser.prototype.parseJSXExpressionAttribute = function () {
var node = this.createJSXNode();
this.expectJSX('{');
this.finishJSX();
if (this.match('}')) {
this.tolerateError('JSX attributes must only be assigned a non-empty expression');
}
var expression = this.parseAssignmentExpression();
this.reenterJSX();
return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
};
JSXParser.prototype.parseJSXAttributeValue = function () {
return this.matchJSX('{') ? this.parseJSXExpressionAttribute() : this.matchJSX('<') ? this.parseJSXElement() : this.parseJSXStringLiteralAttribute();
};
JSXParser.prototype.parseJSXNameValueAttribute = function () {
var node = this.createJSXNode();
var name = this.parseJSXAttributeName();
var value = null;
if (this.matchJSX('=')) {
this.expectJSX('=');
value = this.parseJSXAttributeValue();
}
return this.finalize(node, new JSXNode.JSXAttribute(name, value));
};
JSXParser.prototype.parseJSXSpreadAttribute = function () {
var node = this.createJSXNode();
this.expectJSX('{');
this.expectJSX('...');
this.finishJSX();
var argument = this.parseAssignmentExpression();
this.reenterJSX();
return this.finalize(node, new JSXNode.JSXSpreadAttribute(argument));
};
JSXParser.prototype.parseJSXAttributes = function () {
var attributes = [];
while (!this.matchJSX('/') && !this.matchJSX('>')) {
var attribute = this.matchJSX('{') ? this.parseJSXSpreadAttribute() : this.parseJSXNameValueAttribute();
attributes.push(attribute);
}
return attributes;
};
JSXParser.prototype.parseJSXOpeningElement = function () {
var node = this.createJSXNode();
this.expectJSX('<');
var name = this.parseJSXElementName();
var attributes = this.parseJSXAttributes();
var selfClosing = this.matchJSX('/');
if (selfClosing) {
this.expectJSX('/');
}
this.expectJSX('>');
return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
};
JSXParser.prototype.parseJSXBoundaryElement = function () {
var node = this.createJSXNode();
this.expectJSX('<');
if (this.matchJSX('/')) {
this.expectJSX('/');
var name_3 = this.parseJSXElementName();
this.expectJSX('>');
return this.finalize(node, new JSXNode.JSXClosingElement(name_3));
}
var name = this.parseJSXElementName();
var attributes = this.parseJSXAttributes();
var selfClosing = this.matchJSX('/');
if (selfClosing) {
this.expectJSX('/');
}
this.expectJSX('>');
return this.finalize(node, new JSXNode.JSXOpeningElement(name, selfClosing, attributes));
};
JSXParser.prototype.parseJSXEmptyExpression = function () {
var node = this.createJSXChildNode();
this.collectComments();
this.lastMarker.index = this.scanner.index;
this.lastMarker.line = this.scanner.lineNumber;
this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
return this.finalize(node, new JSXNode.JSXEmptyExpression());
};
JSXParser.prototype.parseJSXExpressionContainer = function () {
var node = this.createJSXNode();
this.expectJSX('{');
var expression;
if (this.matchJSX('}')) {
expression = this.parseJSXEmptyExpression();
this.expectJSX('}');
} else {
this.finishJSX();
expression = this.parseAssignmentExpression();
this.reenterJSX();
}
return this.finalize(node, new JSXNode.JSXExpressionContainer(expression));
};
JSXParser.prototype.parseJSXChildren = function () {
var children = [];
while (!this.scanner.eof()) {
var node = this.createJSXChildNode();
var token = this.nextJSXText();
if (token.start < token.end) {
var raw = this.getTokenRaw(token);
var child = this.finalize(node, new JSXNode.JSXText(token.value, raw));
children.push(child);
}
if (this.scanner.source[this.scanner.index] === '{') {
var container = this.parseJSXExpressionContainer();
children.push(container);
} else {
break;
}
}
return children;
};
JSXParser.prototype.parseComplexJSXElement = function (el) {
var stack = [];
while (!this.scanner.eof()) {
el.children = el.children.concat(this.parseJSXChildren());
var node = this.createJSXChildNode();
var element = this.parseJSXBoundaryElement();
if (element.type === jsx_syntax_1.JSXSyntax.JSXOpeningElement) {
var opening = element;
if (opening.selfClosing) {
var child = this.finalize(node, new JSXNode.JSXElement(opening, [], null));
el.children.push(child);
} else {
stack.push(el);
el = { node: node, opening: opening, closing: null, children: [] };
}
}
if (element.type === jsx_syntax_1.JSXSyntax.JSXClosingElement) {
el.closing = element;
var open_1 = getQualifiedElementName(el.opening.name);
var close_1 = getQualifiedElementName(el.closing.name);
if (open_1 !== close_1) {
this.tolerateError('Expected corresponding JSX closing tag for %0', open_1);
}
if (stack.length > 0) {
var child = this.finalize(el.node, new JSXNode.JSXElement(el.opening, el.children, el.closing));
el = stack[stack.length - 1];
el.children.push(child);
stack.pop();
} else {
break;
}
}
}
return el;
};
JSXParser.prototype.parseJSXElement = function () {
var node = this.createJSXNode();
var opening = this.parseJSXOpeningElement();
var children = [];
var closing = null;
if (!opening.selfClosing) {
var el = this.parseComplexJSXElement({ node: node, opening: opening, closing: closing, children: children });
children = el.children;
closing = el.closing;
}
return this.finalize(node, new JSXNode.JSXElement(opening, children, closing));
};
JSXParser.prototype.parseJSXRoot = function () {
// Pop the opening '<' added from the lookahead.
if (this.config.tokens) {
this.tokens.pop();
}
this.startJSX();
var element = this.parseJSXElement();
this.finishJSX();
return element;
};
JSXParser.prototype.isStartOfExpression = function () {
return _super.prototype.isStartOfExpression.call(this) || this.match('<');
};
return JSXParser;
}(parser_1.Parser);
exports.JSXParser = JSXParser;
/***/
},
/* 4 */
/***/function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// See also tools/generate-unicode-regex.js.
var Regex = {
// Unicode v8.0.0 NonAsciiIdentifierStart:
NonAsciiIdentifierStart: /[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B4\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309B-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]/,
// Unicode v8.0.0 NonAsciiIdentifierPart:
NonAsciiIdentifierPart: /[\xAA\xB5\xB7\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u08A0-\u08B4\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C81-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D01-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1369-\u1371\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1CD0-\u1CD2\u1CD4-\u1CF6\u1CF8\u1CF9\u1D00-\u1DF5\u1DFC-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200C\u200D\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2118-\u211D\u2124\u2126\u2128\u212A-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FD5\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AD\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C4\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF30-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/
};
exports.Character = {
/* tslint:disable:no-bitwise */
fromCodePoint: function (cp) {
return cp < 0x10000 ? String.fromCharCode(cp) : String.fromCharCode(0xD800 + (cp - 0x10000 >> 10)) + String.fromCharCode(0xDC00 + (cp - 0x10000 & 1023));
},
// https://tc39.github.io/ecma262/#sec-white-space
isWhiteSpace: function (cp) {
return cp === 0x20 || cp === 0x09 || cp === 0x0B || cp === 0x0C || cp === 0xA0 || cp >= 0x1680 && [0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x202F, 0x205F, 0x3000, 0xFEFF].indexOf(cp) >= 0;
},
// https://tc39.github.io/ecma262/#sec-line-terminators
isLineTerminator: function (cp) {
return cp === 0x0A || cp === 0x0D || cp === 0x2028 || cp === 0x2029;
},
// https://tc39.github.io/ecma262/#sec-names-and-keywords
isIdentifierStart: function (cp) {
return cp === 0x24 || cp === 0x5F || cp >= 0x41 && cp <= 0x5A || cp >= 0x61 && cp <= 0x7A || cp === 0x5C || cp >= 0x80 && Regex.NonAsciiIdentifierStart.test(exports.Character.fromCodePoint(cp));
},
isIdentifierPart: function (cp) {
return cp === 0x24 || cp === 0x5F || cp >= 0x41 && cp <= 0x5A || cp >= 0x61 && cp <= 0x7A || cp >= 0x30 && cp <= 0x39 || cp === 0x5C || cp >= 0x80 && Regex.NonAsciiIdentifierPart.test(exports.Character.fromCodePoint(cp));
},
// https://tc39.github.io/ecma262/#sec-literals-numeric-literals
isDecimalDigit: function (cp) {
return cp >= 0x30 && cp <= 0x39; // 0..9
},
isHexDigit: function (cp) {
return cp >= 0x30 && cp <= 0x39 || cp >= 0x41 && cp <= 0x46 || cp >= 0x61 && cp <= 0x66; // a..f
},
isOctalDigit: function (cp) {
return cp >= 0x30 && cp <= 0x37; // 0..7
}
};
/***/
},
/* 5 */
/***/function (module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_syntax_1 = __webpack_require__(6);
/* tslint:disable:max-classes-per-file */
var JSXClosingElement = function () {
function JSXClosingElement(name) {
this.type = jsx_syntax_1.JSXSyntax.JSXClosingElement;
this.name = name;
}
return JSXClosingElement;
}();
exports.JSXClosingElement = JSXClosingElement;
var JSXElement = function () {
function JSXElement(openingElement, children, closingElement) {
this.type = jsx_syntax_1.JSXSyntax.JSXElement;
this.openingElement = openingElement;
this.children = children;
this.closingElement = closingElement;
}
return JSXElement;
}();
exports.JSXElement = JSXElement;
var JSXEmptyExpression = function () {
function JSXEmptyExpression() {
this.type = jsx_syntax_1.JSXSyntax.JSXEmptyExpression;
}
return JSXEmptyExpression;
}();
exports.JSXEmptyExpression = JSXEmptyExpression;
var JSXExpressionContainer = function () {
function JSXExpressionContainer(expression) {
this.type = jsx_syntax_1.JSXSyntax.JSXExpressionContainer;
this.expression = expression;
}
return JSXExpressionContainer;
}();
exports.JSXExpressionContainer = JSXExpressionContainer;
var JSXIdentifier = function () {
function JSXIdentifier(name) {
this.type = jsx_syntax_1.JSXSyntax.JSXIdentifier;
this.name = name;
}
return JSXIdentifier;
}();
exports.JSXIdentifier = JSXIdentifier;
var JSXMemberExpression = function () {
function JSXMemberExpression(object, property) {
this.type = jsx_syntax_1.JSXSyntax.JSXMemberExpression;
this.object = object;
this.property = property;
}
return JSXMemberExpression;
}();
exports.JSXMemberExpression = JSXMemberExpression;
var JSXAttribute = function () {
function JSXAttribute(name, value) {
this.type = jsx_syntax_1.JSXSyntax.JSXAttribute;
this.name = name;
this.value = value;
}
return JSXAttribute;
}();
exports.JSXAttribute = JSXAttribute;
var JSXNamespacedName = function () {
function JSXNamespacedName(namespace, name) {
this.type = jsx_syntax_1.JSXSyntax.JSXNamespacedName;
this.namespace = namespace;
this.name = name;
}
return JSXNamespacedName;
}();
exports.JSXNamespacedName = JSXNamespacedName;
var JSXOpeningElement = function () {
function JSXOpeningElement(name, selfClosing, attributes) {
this.type = jsx_syntax_1.JSXSyntax.JSXOpeningElement;
this.name = name;
this.selfClosing = selfClosing;
this.attributes = attributes;
}
return JSXOpeningElement;
}();
exports.JSXOpeningElement = JSXOpeningElement;
var JSXSpreadAttribute = function () {
function JSXSpreadAttribute(argument) {
this.type = jsx_syntax_1.JSXSyntax.JSXSpreadAttribute;
this.argument = argument;
}
return JSXSpreadAttribute;
}();
exports.JSXSpreadAttribute = JSXSpreadAttribute;
var JSXText = function () {
function JSXText(value, raw) {
this.type = jsx_syntax_1.JSXSyntax.JSXText;
this.value = value;
this.raw = raw;
}
return JSXText;
}();
exports.JSXText = JSXText;
/***/
},
/* 6 */
/***/function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JSXSyntax = {
JSXAttribute: 'JSXAttribute',
JSXClosingElement: 'JSXClosingElement',
JSXElement: 'JSXElement',
JSXEmptyExpression: 'JSXEmptyExpression',
JSXExpressionContainer: 'JSXExpressionContainer',
JSXIdentifier: 'JSXIdentifier',
JSXMemberExpression: 'JSXMemberExpression',
JSXNamespacedName: 'JSXNamespacedName',
JSXOpeningElement: 'JSXOpeningElement',
JSXSpreadAttribute: 'JSXSpreadAttribute',
JSXText: 'JSXText'
};
/***/
},
/* 7 */
/***/function (module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var syntax_1 = __webpack_require__(2);
/* tslint:disable:max-classes-per-file */
var ArrayExpression = function () {
function ArrayExpression(elements) {
this.type = syntax_1.Syntax.ArrayExpression;
this.elements = elements;
}
return ArrayExpression;
}();
exports.ArrayExpression = ArrayExpression;
var ArrayPattern = function () {
function ArrayPattern(elements) {
this.type = syntax_1.Syntax.ArrayPattern;
this.elements = elements;
}
return ArrayPattern;
}();
exports.ArrayPattern = ArrayPattern;
var ArrowFunctionExpression = function () {
function ArrowFunctionExpression(params, body, expression) {
this.type = syntax_1.Syntax.ArrowFunctionExpression;
this.id = null;
this.params = params;
this.body = body;
this.generator = false;
this.expression = expression;
this.async = false;
}
return ArrowFunctionExpression;
}();
exports.ArrowFunctionExpression = ArrowFunctionExpression;
var AssignmentExpression = function () {
function AssignmentExpression(operator, left, right) {
this.type = syntax_1.Syntax.AssignmentExpression;
this.operator = operator;
this.left = left;
this.right = right;
}
return AssignmentExpression;
}();
exports.AssignmentExpression = AssignmentExpression;
var AssignmentPattern = function () {
function AssignmentPattern(left, right) {
this.type = syntax_1.Syntax.AssignmentPattern;
this.left = left;
this.right = right;
}
return AssignmentPattern;
}();
exports.AssignmentPattern = AssignmentPattern;
var AsyncArrowFunctionExpression = function () {
function AsyncArrowFunctionExpression(params, body, expression) {
this.type = syntax_1.Syntax.ArrowFunctionExpression;
this.id = null;
this.params = params;
this.body = body;
this.generator = false;
this.expression = expression;
this.async = true;
}
return AsyncArrowFunctionExpression;
}();
exports.AsyncArrowFunctionExpression = AsyncArrowFunctionExpression;
var AsyncFunctionDeclaration = function () {
function AsyncFunctionDeclaration(id, params, body) {
this.type = syntax_1.Syntax.FunctionDeclaration;
this.id = id;
this.params = params;
this.body = body;
this.generator = false;
this.expression = false;
this.async = true;
}
return AsyncFunctionDeclaration;
}();
exports.AsyncFunctionDeclaration = AsyncFunctionDeclaration;
var AsyncFunctionExpression = function () {
function AsyncFunctionExpression(id, params, body) {
this.type = syntax_1.Syntax.FunctionExpression;
this.id = id;
this.params = params;
this.body = body;
this.generator = false;
this.expression = false;
this.async = true;
}
return AsyncFunctionExpression;
}();
exports.AsyncFunctionExpression = AsyncFunctionExpression;
var AwaitExpression = function () {
function AwaitExpression(argument) {
this.type = syntax_1.Syntax.AwaitExpression;
this.argument = argument;
}
return AwaitExpression;
}();
exports.AwaitExpression = AwaitExpression;
var BinaryExpression = function () {
function BinaryExpression(operator, left, right) {
var logical = operator === '||' || operator === '&&';
this.type = logical ? syntax_1.Syntax.LogicalExpression : syntax_1.Syntax.BinaryExpression;
this.operator = operator;
this.left = left;
this.right = right;
}
return BinaryExpression;
}();
exports.BinaryExpression = BinaryExpression;
var BlockStatement = function () {
function BlockStatement(body) {
this.type = syntax_1.Syntax.BlockStatement;
this.body = body;
}
return BlockStatement;
}();
exports.BlockStatement = BlockStatement;
var BreakStatement = function () {
function BreakStatement(label) {
this.type = syntax_1.Syntax.BreakStatement;
this.label = label;
}
return BreakStatement;
}();
exports.BreakStatement = BreakStatement;
var CallExpression = function () {
function CallExpression(callee, args) {
this.type = syntax_1.Syntax.CallExpression;
this.callee = callee;
this.arguments = args;
}
return CallExpression;
}();
exports.CallExpression = CallExpression;
var CatchClause = function () {
function CatchClause(param, body) {
this.type = syntax_1.Syntax.CatchClause;
this.param = param;
this.body = body;
}
return CatchClause;
}();
exports.CatchClause = CatchClause;
var ClassBody = function () {
function ClassBody(body) {
this.type = syntax_1.Syntax.ClassBody;
this.body = body;
}
return ClassBody;
}();
exports.ClassBody = ClassBody;
var ClassDeclaration = function () {
function ClassDeclaration(id, superClass, body) {
this.type = syntax_1.Syntax.ClassDeclaration;
this.id = id;
this.superClass = superClass;
this.body = body;
}
return ClassDeclaration;
}();
exports.ClassDeclaration = ClassDeclaration;
var ClassExpression = function () {
function ClassExpression(id, superClass, body) {
this.type = syntax_1.Syntax.ClassExpression;
this.id = id;
this.superClass = superClass;
this.body = body;
}
return ClassExpression;
}();
exports.ClassExpression = ClassExpression;
var ComputedMemberExpression = function () {
function ComputedMemberExpression(object, property) {
this.type = syntax_1.Syntax.MemberExpression;
this.computed = true;
this.object = object;
this.property = property;
}
return ComputedMemberExpression;
}();
exports.ComputedMemberExpression = ComputedMemberExpression;
var ConditionalExpression = function () {
function ConditionalExpression(test, consequent, alternate) {
this.type = syntax_1.Syntax.ConditionalExpression;
this.test = test;
this.consequent = consequent;
this.alternate = alternate;
}
return ConditionalExpression;
}();
exports.ConditionalExpression = ConditionalExpression;
var ContinueStatement = function () {
function ContinueStatement(label) {
this.type = syntax_1.Syntax.ContinueStatement;
this.label = label;
}
return ContinueStatement;
}();
exports.ContinueStatement = ContinueStatement;
var DebuggerStatement = function () {
function DebuggerStatement() {
this.type = syntax_1.Syntax.DebuggerStatement;
}
return DebuggerStatement;
}();
exports.DebuggerStatement = DebuggerStatement;
var Directive = function () {
function Directive(expression, directive) {
this.type = syntax_1.Syntax.ExpressionStatement;
this.expression = expression;
this.directive = directive;
}
return Directive;
}();
exports.Directive = Directive;
var DoWhileStatement = function () {
function DoWhileStatement(body, test) {
this.type = syntax_1.Syntax.DoWhileStatement;
this.body = body;
this.test = test;
}
return DoWhileStatement;
}();
exports.DoWhileStatement = DoWhileStatement;
var EmptyStatement = function () {
function EmptyStatement() {
this.type = syntax_1.Syntax.EmptyStatement;
}
return EmptyStatement;
}();
exports.EmptyStatement = EmptyStatement;
var ExportAllDeclaration = function () {
function ExportAllDeclaration(source) {
this.type = syntax_1.Syntax.ExportAllDeclaration;
this.source = source;
}
return ExportAllDeclaration;
}();
exports.ExportAllDeclaration = ExportAllDeclaration;
var ExportDefaultDeclaration = function () {
function ExportDefaultDeclaration(declaration) {
this.type = syntax_1.Syntax.ExportDefaultDeclaration;
this.declaration = declaration;
}
return ExportDefaultDeclaration;
}();
exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
var ExportNamedDeclaration = function () {
function ExportNamedDeclaration(declaration, specifiers, source) {
this.type = syntax_1.Syntax.ExportNamedDeclaration;
this.declaration = declaration;
this.specifiers = specifiers;
this.source = source;
}
return ExportNamedDeclaration;
}();
exports.ExportNamedDeclaration = ExportNamedDeclaration;
var ExportSpecifier = function () {
function ExportSpecifier(local, exported) {
this.type = syntax_1.Syntax.ExportSpecifier;
this.exported = exported;
this.local = local;
}
return ExportSpecifier;
}();
exports.ExportSpecifier = ExportSpecifier;
var ExpressionStatement = function () {
function ExpressionStatement(expression) {
this.type = syntax_1.Syntax.ExpressionStatement;
this.expression = expression;
}
return ExpressionStatement;
}();
exports.ExpressionStatement = ExpressionStatement;
var ForInStatement = function () {
function ForInStatement(left, right, body) {
this.type = syntax_1.Syntax.ForInStatement;
this.left = left;
this.right = right;
this.body = body;
this.each = false;
}
return ForInStatement;
}();
exports.ForInStatement = ForInStatement;
var ForOfStatement = function () {
function ForOfStatement(left, right, body) {
this.type = syntax_1.Syntax.ForOfStatement;
this.left = left;
this.right = right;
this.body = body;
}
return ForOfStatement;
}();
exports.ForOfStatement = ForOfStatement;
var ForStatement = function () {
function ForStatement(init, test, update, body) {
this.type = syntax_1.Syntax.ForStatement;
this.init = init;
this.test = test;
this.update = update;
this.body = body;
}
return ForStatement;
}();
exports.ForStatement = ForStatement;
var FunctionDeclaration = function () {
function FunctionDeclaration(id, params, body, generator) {
this.type = syntax_1.Syntax.FunctionDeclaration;
this.id = id;
this.params = params;
this.body = body;
this.generator = generator;
this.expression = false;
this.async = false;
}
return FunctionDeclaration;
}();
exports.FunctionDeclaration = FunctionDeclaration;
var FunctionExpression = function () {
function FunctionExpression(id, params, body, generator) {
this.type = syntax_1.Syntax.FunctionExpression;
this.id = id;
this.params = params;
this.body = body;
this.generator = generator;
this.expression = false;
this.async = false;
}
return FunctionExpression;
}();
exports.FunctionExpression = FunctionExpression;
var Identifier = function () {
function Identifier(name) {
this.type = syntax_1.Syntax.Identifier;
this.name = name;
}
return Identifier;
}();
exports.Identifier = Identifier;
var IfStatement = function () {
function IfStatement(test, consequent, alternate) {
this.type = syntax_1.Syntax.IfStatement;
this.test = test;
this.consequent = consequent;
this.alternate = alternate;
}
return IfStatement;
}();
exports.IfStatement = IfStatement;
var ImportDeclaration = function () {
function ImportDeclaration(specifiers, source) {
this.type = syntax_1.Syntax.ImportDeclaration;
this.specifiers = specifiers;
this.source = source;
}
return ImportDeclaration;
}();
exports.ImportDeclaration = ImportDeclaration;
var ImportDefaultSpecifier = function () {
function ImportDefaultSpecifier(local) {
this.type = syntax_1.Syntax.ImportDefaultSpecifier;
this.local = local;
}
return ImportDefaultSpecifier;
}();
exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
var ImportNamespaceSpecifier = function () {
function ImportNamespaceSpecifier(local) {
this.type = syntax_1.Syntax.ImportNamespaceSpecifier;
this.local = local;
}
return ImportNamespaceSpecifier;
}();
exports.ImportNamespaceSpecifier = ImportNamespaceSpecifier;
var ImportSpecifier = function () {
function ImportSpecifier(local, imported) {
this.type = syntax_1.Syntax.ImportSpecifier;
this.local = local;
this.imported = imported;
}
return ImportSpecifier;
}();
exports.ImportSpecifier = ImportSpecifier;
var LabeledStatement = function () {
function LabeledStatement(label, body) {
this.type = syntax_1.Syntax.LabeledStatement;
this.label = label;
this.body = body;
}
return LabeledStatement;
}();
exports.LabeledStatement = LabeledStatement;
var Literal = function () {
function Literal(value, raw) {
this.type = syntax_1.Syntax.Literal;
this.value = value;
this.raw = raw;
}
return Literal;
}();
exports.Literal = Literal;
var MetaProperty = function () {
function MetaProperty(meta, property) {
this.type = syntax_1.Syntax.MetaProperty;
this.meta = meta;
this.property = property;
}
return MetaProperty;
}();
exports.MetaProperty = MetaProperty;
var MethodDefinition = function () {
function MethodDefinition(key, computed, value, kind, isStatic) {
this.type = syntax_1.Syntax.MethodDefinition;
this.key = key;
this.computed = computed;
this.value = value;
this.kind = kind;
this.static = isStatic;
}
return MethodDefinition;
}();
exports.MethodDefinition = MethodDefinition;
var Module = function () {
function Module(body) {
this.type = syntax_1.Syntax.Program;
this.body = body;
this.sourceType = 'module';
}
return Module;
}();
exports.Module = Module;
var NewExpression = function () {
function NewExpression(callee, args) {
this.type = syntax_1.Syntax.NewExpression;
this.callee = callee;
this.arguments = args;
}
return NewExpression;
}();
exports.NewExpression = NewExpression;
var ObjectExpression = function () {
function ObjectExpression(properties) {
this.type = syntax_1.Syntax.ObjectExpression;
this.properties = properties;
}
return ObjectExpression;
}();
exports.ObjectExpression = ObjectExpression;
var ObjectPattern = function () {
function ObjectPattern(properties) {
this.type = syntax_1.Syntax.ObjectPattern;
this.properties = properties;
}
return ObjectPattern;
}();
exports.ObjectPattern = ObjectPattern;
var Property = function () {
function Property(kind, key, computed, value, method, shorthand) {
this.type = syntax_1.Syntax.Property;
this.key = key;
this.computed = computed;
this.value = value;
this.kind = kind;
this.method = method;
this.shorthand = shorthand;
}
return Property;
}();
exports.Property = Property;
var RegexLiteral = function () {
function RegexLiteral(value, raw, pattern, flags) {
this.type = syntax_1.Syntax.Literal;
this.value = value;
this.raw = raw;
this.regex = { pattern: pattern, flags: flags };
}
return RegexLiteral;
}();
exports.RegexLiteral = RegexLiteral;
var RestElement = function () {
function RestElement(argument) {
this.type = syntax_1.Syntax.RestElement;
this.argument = argument;
}
return RestElement;
}();
exports.RestElement = RestElement;
var ReturnStatement = function () {
function ReturnStatement(argument) {
this.type = syntax_1.Syntax.ReturnStatement;
this.argument = argument;
}
return ReturnStatement;
}();
exports.ReturnStatement = ReturnStatement;
var Script = function () {
function Script(body) {
this.type = syntax_1.Syntax.Program;
this.body = body;
this.sourceType = 'script';
}
return Script;
}();
exports.Script = Script;
var SequenceExpression = function () {
function SequenceExpression(expressions) {
this.type = syntax_1.Syntax.SequenceExpression;
this.expressions = expressions;
}
return SequenceExpression;
}();
exports.SequenceExpression = SequenceExpression;
var SpreadElement = function () {
function SpreadElement(argument) {
this.type = syntax_1.Syntax.SpreadElement;
this.argument = argument;
}
return SpreadElement;
}();
exports.SpreadElement = SpreadElement;
var StaticMemberExpression = function () {
function StaticMemberExpression(object, property) {
this.type = syntax_1.Syntax.MemberExpression;
this.computed = false;
this.object = object;
this.property = property;
}
return StaticMemberExpression;
}();
exports.StaticMemberExpression = StaticMemberExpression;
var Super = function () {
function Super() {
this.type = syntax_1.Syntax.Super;
}
return Super;
}();
exports.Super = Super;
var SwitchCase = function () {
function SwitchCase(test, consequent) {
this.type = syntax_1.Syntax.SwitchCase;
this.test = test;
this.consequent = consequent;
}
return SwitchCase;
}();
exports.SwitchCase = SwitchCase;
var SwitchStatement = function () {
function SwitchStatement(discriminant, cases) {
this.type = syntax_1.Syntax.SwitchStatement;
this.discriminant = discriminant;
this.cases = cases;
}
return SwitchStatement;
}();
exports.SwitchStatement = SwitchStatement;
var TaggedTemplateExpression = function () {
function TaggedTemplateExpression(tag, quasi) {
this.type = syntax_1.Syntax.TaggedTemplateExpression;
this.tag = tag;
this.quasi = quasi;
}
return TaggedTemplateExpression;
}();
exports.TaggedTemplateExpression = TaggedTemplateExpression;
var TemplateElement = function () {
function TemplateElement(value, tail) {
this.type = syntax_1.Syntax.TemplateElement;
this.value = value;
this.tail = tail;
}
return TemplateElement;
}();
exports.TemplateElement = TemplateElement;
var TemplateLiteral = function () {
function TemplateLiteral(quasis, expressions) {
this.type = syntax_1.Syntax.TemplateLiteral;
this.quasis = quasis;
this.expressions = expressions;
}
return TemplateLiteral;
}();
exports.TemplateLiteral = TemplateLiteral;
var ThisExpression = function () {
function ThisExpression() {
this.type = syntax_1.Syntax.ThisExpression;
}
return ThisExpression;
}();
exports.ThisExpression = ThisExpression;
var ThrowStatement = function () {
function ThrowStatement(argument) {
this.type = syntax_1.Syntax.ThrowStatement;
this.argument = argument;
}
return ThrowStatement;
}();
exports.ThrowStatement = ThrowStatement;
var TryStatement = function () {
function TryStatement(block, handler, finalizer) {
this.type = syntax_1.Syntax.TryStatement;
this.block = block;
this.handler = handler;
this.finalizer = finalizer;
}
return TryStatement;
}();
exports.TryStatement = TryStatement;
var UnaryExpression = function () {
function UnaryExpression(operator, argument) {
this.type = syntax_1.Syntax.UnaryExpression;
this.operator = operator;
this.argument = argument;
this.prefix = true;
}
return UnaryExpression;
}();
exports.UnaryExpression = UnaryExpression;
var UpdateExpression = function () {
function UpdateExpression(operator, argument, prefix) {
this.type = syntax_1.Syntax.UpdateExpression;
this.operator = operator;
this.argument = argument;
this.prefix = prefix;
}
return UpdateExpression;
}();
exports.UpdateExpression = UpdateExpression;
var VariableDeclaration = function () {
function VariableDeclaration(declarations, kind) {
this.type = syntax_1.Syntax.VariableDeclaration;
this.declarations = declarations;
this.kind = kind;
}
return VariableDeclaration;
}();
exports.VariableDeclaration = VariableDeclaration;
var VariableDeclarator = function () {
function VariableDeclarator(id, init) {
this.type = syntax_1.Syntax.VariableDeclarator;
this.id = id;
this.init = init;
}
return VariableDeclarator;
}();
exports.VariableDeclarator = VariableDeclarator;
var WhileStatement = function () {
function WhileStatement(test, body) {
this.type = syntax_1.Syntax.WhileStatement;
this.test = test;
this.body = body;
}
return WhileStatement;
}();
exports.WhileStatement = WhileStatement;
var WithStatement = function () {
function WithStatement(object, body) {
this.type = syntax_1.Syntax.WithStatement;
this.object = object;
this.body = body;
}
return WithStatement;
}();
exports.WithStatement = WithStatement;
var YieldExpression = function () {
function YieldExpression(argument, delegate) {
this.type = syntax_1.Syntax.YieldExpression;
this.argument = argument;
this.delegate = delegate;
}
return YieldExpression;
}();
exports.YieldExpression = YieldExpression;
/***/
},
/* 8 */
/***/function (module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var assert_1 = __webpack_require__(9);
var error_handler_1 = __webpack_require__(10);
var messages_1 = __webpack_require__(11);
var Node = __webpack_require__(7);
var scanner_1 = __webpack_require__(12);
var syntax_1 = __webpack_require__(2);
var token_1 = __webpack_require__(13);
var ArrowParameterPlaceHolder = 'ArrowParameterPlaceHolder';
var Parser = function () {
function Parser(code, options, delegate) {
if (options === void 0) {
options = {};
}
this.config = {
range: typeof options.range === 'boolean' && options.range,
loc: typeof options.loc === 'boolean' && options.loc,
source: null,
tokens: typeof options.tokens === 'boolean' && options.tokens,
comment: typeof options.comment === 'boolean' && options.comment,
tolerant: typeof options.tolerant === 'boolean' && options.tolerant
};
if (this.config.loc && options.source && options.source !== null) {
this.config.source = String(options.source);
}
this.delegate = delegate;
this.errorHandler = new error_handler_1.ErrorHandler();
this.errorHandler.tolerant = this.config.tolerant;
this.scanner = new scanner_1.Scanner(code, this.errorHandler);
this.scanner.trackComment = this.config.comment;
this.operatorPrecedence = {
')': 0,
';': 0,
',': 0,
'=': 0,
']': 0,
'||': 1,
'&&': 2,
'|': 3,
'^': 4,
'&': 5,
'==': 6,
'!=': 6,
'===': 6,
'!==': 6,
'<': 7,
'>': 7,
'<=': 7,
'>=': 7,
'<<': 8,
'>>': 8,
'>>>': 8,
'+': 9,
'-': 9,
'*': 11,
'/': 11,
'%': 11
};
this.lookahead = {
type: 2 /* EOF */
, value: '',
lineNumber: this.scanner.lineNumber,
lineStart: 0,
start: 0,
end: 0
};
this.hasLineTerminator = false;
this.context = {
isModule: false,
await: false,
allowIn: true,
allowStrictDirective: true,
allowYield: true,
firstCoverInitializedNameError: null,
isAssignmentTarget: false,
isBindingElement: false,
inFunctionBody: false,
inIteration: false,
inSwitch: false,
labelSet: {},
strict: false
};
this.tokens = [];
this.startMarker = {
index: 0,
line: this.scanner.lineNumber,
column: 0
};
this.lastMarker = {
index: 0,
line: this.scanner.lineNumber,
column: 0
};
this.nextToken();
this.lastMarker = {
index: this.scanner.index,
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
};
}
Parser.prototype.throwError = function (messageFormat) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
var args = Array.prototype.slice.call(arguments, 1);
var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
assert_1.assert(idx < args.length, 'Message reference must be in range');
return args[idx];
});
var index = this.lastMarker.index;
var line = this.lastMarker.line;
var column = this.lastMarker.column + 1;
throw this.errorHandler.createError(index, line, column, msg);
};
Parser.prototype.tolerateError = function (messageFormat) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
var args = Array.prototype.slice.call(arguments, 1);
var msg = messageFormat.replace(/%(\d)/g, function (whole, idx) {
assert_1.assert(idx < args.length, 'Message reference must be in range');
return args[idx];
});
var index = this.lastMarker.index;
var line = this.scanner.lineNumber;
var column = this.lastMarker.column + 1;
this.errorHandler.tolerateError(index, line, column, msg);
};
// Throw an exception because of the token.
Parser.prototype.unexpectedTokenError = function (token, message) {
var msg = message || messages_1.Messages.UnexpectedToken;
var value;
if (token) {
if (!message) {
msg = token.type === 2 /* EOF */ ? messages_1.Messages.UnexpectedEOS : token.type === 3 /* Identifier */ ? messages_1.Messages.UnexpectedIdentifier : token.type === 6 /* NumericLiteral */ ? messages_1.Messages.UnexpectedNumber : token.type === 8 /* StringLiteral */ ? messages_1.Messages.UnexpectedString : token.type === 10 /* Template */ ? messages_1.Messages.UnexpectedTemplate : messages_1.Messages.UnexpectedToken;
if (token.type === 4 /* Keyword */) {
if (this.scanner.isFutureReservedWord(token.value)) {
msg = messages_1.Messages.UnexpectedReserved;
} else if (this.context.strict && this.scanner.isStrictModeReservedWord(token.value)) {
msg = messages_1.Messages.StrictReservedWord;
}
}
}
value = token.value;
} else {
value = 'ILLEGAL';
}
msg = msg.replace('%0', value);
if (token && typeof token.lineNumber === 'number') {
var index = token.start;
var line = token.lineNumber;
var lastMarkerLineStart = this.lastMarker.index - this.lastMarker.column;
var column = token.start - lastMarkerLineStart + 1;
return this.errorHandler.createError(index, line, column, msg);
} else {
var index = this.lastMarker.index;
var line = this.lastMarker.line;
var column = this.lastMarker.column + 1;
return this.errorHandler.createError(index, line, column, msg);
}
};
Parser.prototype.throwUnexpectedToken = function (token, message) {
throw this.unexpectedTokenError(token, message);
};
Parser.prototype.tolerateUnexpectedToken = function (token, message) {
this.errorHandler.tolerate(this.unexpectedTokenError(token, message));
};
Parser.prototype.collectComments = function () {
if (!this.config.comment) {
this.scanner.scanComments();
} else {
var comments = this.scanner.scanComments();
if (comments.length > 0 && this.delegate) {
for (var i = 0; i < comments.length; ++i) {
var e = comments[i];
var node = void 0;
node = {
type: e.multiLine ? 'BlockComment' : 'LineComment',
value: this.scanner.source.slice(e.slice[0], e.slice[1])
};
if (this.config.range) {
node.range = e.range;
}
if (this.config.loc) {
node.loc = e.loc;
}
var metadata = {
start: {
line: e.loc.start.line,
column: e.loc.start.column,
offset: e.range[0]
},
end: {
line: e.loc.end.line,
column: e.loc.end.column,
offset: e.range[1]
}
};
this.delegate(node, metadata);
}
}
}
};
// From internal representation to an external structure
Parser.prototype.getTokenRaw = function (token) {
return this.scanner.source.slice(token.start, token.end);
};
Parser.prototype.convertToken = function (token) {
var t = {
type: token_1.TokenName[token.type],
value: this.getTokenRaw(token)
};
if (this.config.range) {
t.range = [token.start, token.end];
}
if (this.config.loc) {
t.loc = {
start: {
line: this.startMarker.line,
column: this.startMarker.column
},
end: {
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
}
};
}
if (token.type === 9 /* RegularExpression */) {
var pattern = token.pattern;
var flags = token.flags;
t.regex = { pattern: pattern, flags: flags };
}
return t;
};
Parser.prototype.nextToken = function () {
var token = this.lookahead;
this.lastMarker.index = this.scanner.index;
this.lastMarker.line = this.scanner.lineNumber;
this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
this.collectComments();
if (this.scanner.index !== this.startMarker.index) {
this.startMarker.index = this.scanner.index;
this.startMarker.line = this.scanner.lineNumber;
this.startMarker.column = this.scanner.index - this.scanner.lineStart;
}
var next = this.scanner.lex();
this.hasLineTerminator = token.lineNumber !== next.lineNumber;
if (next && this.context.strict && next.type === 3 /* Identifier */) {
if (this.scanner.isStrictModeReservedWord(next.value)) {
next.type = 4 /* Keyword */;
}
}
this.lookahead = next;
if (this.config.tokens && next.type !== 2 /* EOF */) {
this.tokens.push(this.convertToken(next));
}
return token;
};
Parser.prototype.nextRegexToken = function () {
this.collectComments();
var token = this.scanner.scanRegExp();
if (this.config.tokens) {
// Pop the previous token, '/' or '/='
// This is added from the lookahead token.
this.tokens.pop();
this.tokens.push(this.convertToken(token));
}
// Prime the next lookahead.
this.lookahead = token;
this.nextToken();
return token;
};
Parser.prototype.createNode = function () {
return {
index: this.startMarker.index,
line: this.startMarker.line,
column: this.startMarker.column
};
};
Parser.prototype.startNode = function (token) {
return {
index: token.start,
line: token.lineNumber,
column: token.start - token.lineStart
};
};
Parser.prototype.finalize = function (marker, node) {
if (this.config.range) {
node.range = [marker.index, this.lastMarker.index];
}
if (this.config.loc) {
node.loc = {
start: {
line: marker.line,
column: marker.column
},
end: {
line: this.lastMarker.line,
column: this.lastMarker.column
}
};
if (this.config.source) {
node.loc.source = this.config.source;
}
}
if (this.delegate) {
var metadata = {
start: {
line: marker.line,
column: marker.column,
offset: marker.index
},
end: {
line: this.lastMarker.line,
column: this.lastMarker.column,
offset: this.lastMarker.index
}
};
this.delegate(node, metadata);
}
return node;
};
// Expect the next token to match the specified punctuator.
// If not, an exception will be thrown.
Parser.prototype.expect = function (value) {
var token = this.nextToken();
if (token.type !== 7 /* Punctuator */ || token.value !== value) {
this.throwUnexpectedToken(token);
}
};
// Quietly expect a comma when in tolerant mode, otherwise delegates to expect().
Parser.prototype.expectCommaSeparator = function () {
if (this.config.tolerant) {
var token = this.lookahead;
if (token.type === 7 /* Punctuator */ && token.value === ',') {
this.nextToken();
} else if (token.type === 7 /* Punctuator */ && token.value === ';') {
this.nextToken();
this.tolerateUnexpectedToken(token);
} else {
this.tolerateUnexpectedToken(token, messages_1.Messages.UnexpectedToken);
}
} else {
this.expect(',');
}
};
// Expect the next token to match the specified keyword.
// If not, an exception will be thrown.
Parser.prototype.expectKeyword = function (keyword) {
var token = this.nextToken();
if (token.type !== 4 /* Keyword */ || token.value !== keyword) {
this.throwUnexpectedToken(token);
}
};
// Return true if the next token matches the specified punctuator.
Parser.prototype.match = function (value) {
return this.lookahead.type === 7 /* Punctuator */ && this.lookahead.value === value;
};
// Return true if the next token matches the specified keyword
Parser.prototype.matchKeyword = function (keyword) {
return this.lookahead.type === 4 /* Keyword */ && this.lookahead.value === keyword;
};
// Return true if the next token matches the specified contextual keyword
// (where an identifier is sometimes a keyword depending on the context)
Parser.prototype.matchContextualKeyword = function (keyword) {
return this.lookahead.type === 3 /* Identifier */ && this.lookahead.value === keyword;
};
// Return true if the next token is an assignment operator
Parser.prototype.matchAssign = function () {
if (this.lookahead.type !== 7 /* Punctuator */) {
return false;
}
var op = this.lookahead.value;
return op === '=' || op === '*=' || op === '**=' || op === '/=' || op === '%=' || op === '+=' || op === '-=' || op === '<<=' || op === '>>=' || op === '>>>=' || op === '&=' || op === '^=' || op === '|=';
};
// Cover grammar support.
//
// When an assignment expression position starts with an left parenthesis, the determination of the type
// of the syntax is to be deferred arbitrarily long until the end of the parentheses pair (plus a lookahead)
// or the first comma. This situation also defers the determination of all the expressions nested in the pair.
//
// There are three productions that can be parsed in a parentheses pair that needs to be determined
// after the outermost pair is closed. They are:
//
// 1. AssignmentExpression
// 2. BindingElements
// 3. AssignmentTargets
//
// In order to avoid exponential backtracking, we use two flags to denote if the production can be
// binding element or assignment target.
//
// The three productions have the relationship:
//
// BindingElements ⊆ AssignmentTargets ⊆ AssignmentExpression
//
// with a single exception that CoverInitializedName when used directly in an Expression, generates
// an early error. Therefore, we need the third state, firstCoverInitializedNameError, to track the
// first usage of CoverInitializedName and report it when we reached the end of the parentheses pair.
//
// isolateCoverGrammar function runs the given parser function with a new cover grammar context, and it does not
// effect the current flags. This means the production the parser parses is only used as an expression. Therefore
// the CoverInitializedName check is conducted.
//
// inheritCoverGrammar function runs the given parse function with a new cover grammar context, and it propagates
// the flags outside of the parser. This means the production the parser parses is used as a part of a potential
// pattern. The CoverInitializedName check is deferred.
Parser.prototype.isolateCoverGrammar = function (parseFunction) {
var previousIsBindingElement = this.context.isBindingElement;
var previousIsAssignmentTarget = this.context.isAssignmentTarget;
var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
this.context.isBindingElement = true;
this.context.isAssignmentTarget = true;
this.context.firstCoverInitializedNameError = null;
var result = parseFunction.call(this);
if (this.context.firstCoverInitializedNameError !== null) {
this.throwUnexpectedToken(this.context.firstCoverInitializedNameError);
}
this.context.isBindingElement = previousIsBindingElement;
this.context.isAssignmentTarget = previousIsAssignmentTarget;
this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError;
return result;
};
Parser.prototype.inheritCoverGrammar = function (parseFunction) {
var previousIsBindingElement = this.context.isBindingElement;
var previousIsAssignmentTarget = this.context.isAssignmentTarget;
var previousFirstCoverInitializedNameError = this.context.firstCoverInitializedNameError;
this.context.isBindingElement = true;
this.context.isAssignmentTarget = true;
this.context.firstCoverInitializedNameError = null;
var result = parseFunction.call(this);
this.context.isBindingElement = this.context.isBindingElement && previousIsBindingElement;
this.context.isAssignmentTarget = this.context.isAssignmentTarget && previousIsAssignmentTarget;
this.context.firstCoverInitializedNameError = previousFirstCoverInitializedNameError || this.context.firstCoverInitializedNameError;
return result;
};
Parser.prototype.consumeSemicolon = function () {
if (this.match(';')) {
this.nextToken();
} else if (!this.hasLineTerminator) {
if (this.lookahead.type !== 2 /* EOF */ && !this.match('}')) {
this.throwUnexpectedToken(this.lookahead);
}
this.lastMarker.index = this.startMarker.index;
this.lastMarker.line = this.startMarker.line;
this.lastMarker.column = this.startMarker.column;
}
};
// https://tc39.github.io/ecma262/#sec-primary-expression
Parser.prototype.parsePrimaryExpression = function () {
var node = this.createNode();
var expr;
var token, raw;
switch (this.lookahead.type) {
case 3 /* Identifier */:
if ((this.context.isModule || this.context.await) && this.lookahead.value === 'await') {
this.tolerateUnexpectedToken(this.lookahead);
}
expr = this.matchAsyncFunction() ? this.parseFunctionExpression() : this.finalize(node, new Node.Identifier(this.nextToken().value));
break;
case 6 /* NumericLiteral */:
case 8 /* StringLiteral */:
if (this.context.strict && this.lookahead.octal) {
this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.StrictOctalLiteral);
}
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
token = this.nextToken();
raw = this.getTokenRaw(token);
expr = this.finalize(node, new Node.Literal(token.value, raw));
break;
case 1 /* BooleanLiteral */:
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
token = this.nextToken();
raw = this.getTokenRaw(token);
expr = this.finalize(node, new Node.Literal(token.value === 'true', raw));
break;
case 5 /* NullLiteral */:
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
token = this.nextToken();
raw = this.getTokenRaw(token);
expr = this.finalize(node, new Node.Literal(null, raw));
break;
case 10 /* Template */:
expr = this.parseTemplateLiteral();
break;
case 7 /* Punctuator */:
switch (this.lookahead.value) {
case '(':
this.context.isBindingElement = false;
expr = this.inheritCoverGrammar(this.parseGroupExpression);
break;
case '[':
expr = this.inheritCoverGrammar(this.parseArrayInitializer);
break;
case '{':
expr = this.inheritCoverGrammar(this.parseObjectInitializer);
break;
case '/':
case '/=':
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
this.scanner.index = this.startMarker.index;
token = this.nextRegexToken();
raw = this.getTokenRaw(token);
expr = this.finalize(node, new Node.RegexLiteral(token.regex, raw, token.pattern, token.flags));
break;
default:
expr = this.throwUnexpectedToken(this.nextToken());
}
break;
case 4 /* Keyword */:
if (!this.context.strict && this.context.allowYield && this.matchKeyword('yield')) {
expr = this.parseIdentifierName();
} else if (!this.context.strict && this.matchKeyword('let')) {
expr = this.finalize(node, new Node.Identifier(this.nextToken().value));
} else {
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
if (this.matchKeyword('function')) {
expr = this.parseFunctionExpression();
} else if (this.matchKeyword('this')) {
this.nextToken();
expr = this.finalize(node, new Node.ThisExpression());
} else if (this.matchKeyword('class')) {
expr = this.parseClassExpression();
} else {
expr = this.throwUnexpectedToken(this.nextToken());
}
}
break;
default:
expr = this.throwUnexpectedToken(this.nextToken());
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-array-initializer
Parser.prototype.parseSpreadElement = function () {
var node = this.createNode();
this.expect('...');
var arg = this.inheritCoverGrammar(this.parseAssignmentExpression);
return this.finalize(node, new Node.SpreadElement(arg));
};
Parser.prototype.parseArrayInitializer = function () {
var node = this.createNode();
var elements = [];
this.expect('[');
while (!this.match(']')) {
if (this.match(',')) {
this.nextToken();
elements.push(null);
} else if (this.match('...')) {
var element = this.parseSpreadElement();
if (!this.match(']')) {
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
this.expect(',');
}
elements.push(element);
} else {
elements.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
if (!this.match(']')) {
this.expect(',');
}
}
}
this.expect(']');
return this.finalize(node, new Node.ArrayExpression(elements));
};
// https://tc39.github.io/ecma262/#sec-object-initializer
Parser.prototype.parsePropertyMethod = function (params) {
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var previousStrict = this.context.strict;
var previousAllowStrictDirective = this.context.allowStrictDirective;
this.context.allowStrictDirective = params.simple;
var body = this.isolateCoverGrammar(this.parseFunctionSourceElements);
if (this.context.strict && params.firstRestricted) {
this.tolerateUnexpectedToken(params.firstRestricted, params.message);
}
if (this.context.strict && params.stricted) {
this.tolerateUnexpectedToken(params.stricted, params.message);
}
this.context.strict = previousStrict;
this.context.allowStrictDirective = previousAllowStrictDirective;
return body;
};
Parser.prototype.parsePropertyMethodFunction = function () {
var isGenerator = false;
var node = this.createNode();
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
var params = this.parseFormalParameters();
var method = this.parsePropertyMethod(params);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
};
Parser.prototype.parsePropertyMethodAsyncFunction = function () {
var node = this.createNode();
var previousAllowYield = this.context.allowYield;
var previousAwait = this.context.await;
this.context.allowYield = false;
this.context.await = true;
var params = this.parseFormalParameters();
var method = this.parsePropertyMethod(params);
this.context.allowYield = previousAllowYield;
this.context.await = previousAwait;
return this.finalize(node, new Node.AsyncFunctionExpression(null, params.params, method));
};
Parser.prototype.parseObjectPropertyKey = function () {
var node = this.createNode();
var token = this.nextToken();
var key;
switch (token.type) {
case 8 /* StringLiteral */:
case 6 /* NumericLiteral */:
if (this.context.strict && token.octal) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictOctalLiteral);
}
var raw = this.getTokenRaw(token);
key = this.finalize(node, new Node.Literal(token.value, raw));
break;
case 3 /* Identifier */:
case 1 /* BooleanLiteral */:
case 5 /* NullLiteral */:
case 4 /* Keyword */:
key = this.finalize(node, new Node.Identifier(token.value));
break;
case 7 /* Punctuator */:
if (token.value === '[') {
key = this.isolateCoverGrammar(this.parseAssignmentExpression);
this.expect(']');
} else {
key = this.throwUnexpectedToken(token);
}
break;
default:
key = this.throwUnexpectedToken(token);
}
return key;
};
Parser.prototype.isPropertyKey = function (key, value) {
return key.type === syntax_1.Syntax.Identifier && key.name === value || key.type === syntax_1.Syntax.Literal && key.value === value;
};
Parser.prototype.parseObjectProperty = function (hasProto) {
var node = this.createNode();
var token = this.lookahead;
var kind;
var key = null;
var value = null;
var computed = false;
var method = false;
var shorthand = false;
var isAsync = false;
if (token.type === 3 /* Identifier */) {
var id = token.value;
this.nextToken();
computed = this.match('[');
isAsync = !this.hasLineTerminator && id === 'async' && !this.match(':') && !this.match('(') && !this.match('*');
key = isAsync ? this.parseObjectPropertyKey() : this.finalize(node, new Node.Identifier(id));
} else if (this.match('*')) {
this.nextToken();
} else {
computed = this.match('[');
key = this.parseObjectPropertyKey();
}
var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'get' && lookaheadPropertyKey) {
kind = 'get';
computed = this.match('[');
key = this.parseObjectPropertyKey();
this.context.allowYield = false;
value = this.parseGetterMethod();
} else if (token.type === 3 /* Identifier */ && !isAsync && token.value === 'set' && lookaheadPropertyKey) {
kind = 'set';
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseSetterMethod();
} else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
kind = 'init';
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseGeneratorMethod();
method = true;
} else {
if (!key) {
this.throwUnexpectedToken(this.lookahead);
}
kind = 'init';
if (this.match(':') && !isAsync) {
if (!computed && this.isPropertyKey(key, '__proto__')) {
if (hasProto.value) {
this.tolerateError(messages_1.Messages.DuplicateProtoProperty);
}
hasProto.value = true;
}
this.nextToken();
value = this.inheritCoverGrammar(this.parseAssignmentExpression);
} else if (this.match('(')) {
value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
method = true;
} else if (token.type === 3 /* Identifier */) {
var id = this.finalize(node, new Node.Identifier(token.value));
if (this.match('=')) {
this.context.firstCoverInitializedNameError = this.lookahead;
this.nextToken();
shorthand = true;
var init = this.isolateCoverGrammar(this.parseAssignmentExpression);
value = this.finalize(node, new Node.AssignmentPattern(id, init));
} else {
shorthand = true;
value = id;
}
} else {
this.throwUnexpectedToken(this.nextToken());
}
}
return this.finalize(node, new Node.Property(kind, key, computed, value, method, shorthand));
};
Parser.prototype.parseObjectInitializer = function () {
var node = this.createNode();
this.expect('{');
var properties = [];
var hasProto = { value: false };
while (!this.match('}')) {
properties.push(this.parseObjectProperty(hasProto));
if (!this.match('}')) {
this.expectCommaSeparator();
}
}
this.expect('}');
return this.finalize(node, new Node.ObjectExpression(properties));
};
// https://tc39.github.io/ecma262/#sec-template-literals
Parser.prototype.parseTemplateHead = function () {
assert_1.assert(this.lookahead.head, 'Template literal must start with a template head');
var node = this.createNode();
var token = this.nextToken();
var raw = token.value;
var cooked = token.cooked;
return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
};
Parser.prototype.parseTemplateElement = function () {
if (this.lookahead.type !== 10 /* Template */) {
this.throwUnexpectedToken();
}
var node = this.createNode();
var token = this.nextToken();
var raw = token.value;
var cooked = token.cooked;
return this.finalize(node, new Node.TemplateElement({ raw: raw, cooked: cooked }, token.tail));
};
Parser.prototype.parseTemplateLiteral = function () {
var node = this.createNode();
var expressions = [];
var quasis = [];
var quasi = this.parseTemplateHead();
quasis.push(quasi);
while (!quasi.tail) {
expressions.push(this.parseExpression());
quasi = this.parseTemplateElement();
quasis.push(quasi);
}
return this.finalize(node, new Node.TemplateLiteral(quasis, expressions));
};
// https://tc39.github.io/ecma262/#sec-grouping-operator
Parser.prototype.reinterpretExpressionAsPattern = function (expr) {
switch (expr.type) {
case syntax_1.Syntax.Identifier:
case syntax_1.Syntax.MemberExpression:
case syntax_1.Syntax.RestElement:
case syntax_1.Syntax.AssignmentPattern:
break;
case syntax_1.Syntax.SpreadElement:
expr.type = syntax_1.Syntax.RestElement;
this.reinterpretExpressionAsPattern(expr.argument);
break;
case syntax_1.Syntax.ArrayExpression:
expr.type = syntax_1.Syntax.ArrayPattern;
for (var i = 0; i < expr.elements.length; i++) {
if (expr.elements[i] !== null) {
this.reinterpretExpressionAsPattern(expr.elements[i]);
}
}
break;
case syntax_1.Syntax.ObjectExpression:
expr.type = syntax_1.Syntax.ObjectPattern;
for (var i = 0; i < expr.properties.length; i++) {
this.reinterpretExpressionAsPattern(expr.properties[i].value);
}
break;
case syntax_1.Syntax.AssignmentExpression:
expr.type = syntax_1.Syntax.AssignmentPattern;
delete expr.operator;
this.reinterpretExpressionAsPattern(expr.left);
break;
default:
// Allow other node type for tolerant parsing.
break;
}
};
Parser.prototype.parseGroupExpression = function () {
var expr;
this.expect('(');
if (this.match(')')) {
this.nextToken();
if (!this.match('=>')) {
this.expect('=>');
}
expr = {
type: ArrowParameterPlaceHolder,
params: [],
async: false
};
} else {
var startToken = this.lookahead;
var params = [];
if (this.match('...')) {
expr = this.parseRestElement(params);
this.expect(')');
if (!this.match('=>')) {
this.expect('=>');
}
expr = {
type: ArrowParameterPlaceHolder,
params: [expr],
async: false
};
} else {
var arrow = false;
this.context.isBindingElement = true;
expr = this.inheritCoverGrammar(this.parseAssignmentExpression);
if (this.match(',')) {
var expressions = [];
this.context.isAssignmentTarget = false;
expressions.push(expr);
while (this.lookahead.type !== 2 /* EOF */) {
if (!this.match(',')) {
break;
}
this.nextToken();
if (this.match(')')) {
this.nextToken();
for (var i = 0; i < expressions.length; i++) {
this.reinterpretExpressionAsPattern(expressions[i]);
}
arrow = true;
expr = {
type: ArrowParameterPlaceHolder,
params: expressions,
async: false
};
} else if (this.match('...')) {
if (!this.context.isBindingElement) {
this.throwUnexpectedToken(this.lookahead);
}
expressions.push(this.parseRestElement(params));
this.expect(')');
if (!this.match('=>')) {
this.expect('=>');
}
this.context.isBindingElement = false;
for (var i = 0; i < expressions.length; i++) {
this.reinterpretExpressionAsPattern(expressions[i]);
}
arrow = true;
expr = {
type: ArrowParameterPlaceHolder,
params: expressions,
async: false
};
} else {
expressions.push(this.inheritCoverGrammar(this.parseAssignmentExpression));
}
if (arrow) {
break;
}
}
if (!arrow) {
expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
}
}
if (!arrow) {
this.expect(')');
if (this.match('=>')) {
if (expr.type === syntax_1.Syntax.Identifier && expr.name === 'yield') {
arrow = true;
expr = {
type: ArrowParameterPlaceHolder,
params: [expr],
async: false
};
}
if (!arrow) {
if (!this.context.isBindingElement) {
this.throwUnexpectedToken(this.lookahead);
}
if (expr.type === syntax_1.Syntax.SequenceExpression) {
for (var i = 0; i < expr.expressions.length; i++) {
this.reinterpretExpressionAsPattern(expr.expressions[i]);
}
} else {
this.reinterpretExpressionAsPattern(expr);
}
var parameters = expr.type === syntax_1.Syntax.SequenceExpression ? expr.expressions : [expr];
expr = {
type: ArrowParameterPlaceHolder,
params: parameters,
async: false
};
}
}
this.context.isBindingElement = false;
}
}
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-left-hand-side-expressions
Parser.prototype.parseArguments = function () {
this.expect('(');
var args = [];
if (!this.match(')')) {
while (true) {
var expr = this.match('...') ? this.parseSpreadElement() : this.isolateCoverGrammar(this.parseAssignmentExpression);
args.push(expr);
if (this.match(')')) {
break;
}
this.expectCommaSeparator();
if (this.match(')')) {
break;
}
}
}
this.expect(')');
return args;
};
Parser.prototype.isIdentifierName = function (token) {
return token.type === 3 /* Identifier */ || token.type === 4 /* Keyword */ || token.type === 1 /* BooleanLiteral */ || token.type === 5 /* NullLiteral */;
};
Parser.prototype.parseIdentifierName = function () {
var node = this.createNode();
var token = this.nextToken();
if (!this.isIdentifierName(token)) {
this.throwUnexpectedToken(token);
}
return this.finalize(node, new Node.Identifier(token.value));
};
Parser.prototype.parseNewExpression = function () {
var node = this.createNode();
var id = this.parseIdentifierName();
assert_1.assert(id.name === 'new', 'New expression must start with `new`');
var expr;
if (this.match('.')) {
this.nextToken();
if (this.lookahead.type === 3 /* Identifier */ && this.context.inFunctionBody && this.lookahead.value === 'target') {
var property = this.parseIdentifierName();
expr = new Node.MetaProperty(id, property);
} else {
this.throwUnexpectedToken(this.lookahead);
}
} else {
var callee = this.isolateCoverGrammar(this.parseLeftHandSideExpression);
var args = this.match('(') ? this.parseArguments() : [];
expr = new Node.NewExpression(callee, args);
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
}
return this.finalize(node, expr);
};
Parser.prototype.parseAsyncArgument = function () {
var arg = this.parseAssignmentExpression();
this.context.firstCoverInitializedNameError = null;
return arg;
};
Parser.prototype.parseAsyncArguments = function () {
this.expect('(');
var args = [];
if (!this.match(')')) {
while (true) {
var expr = this.match('...') ? this.parseSpreadElement() : this.isolateCoverGrammar(this.parseAsyncArgument);
args.push(expr);
if (this.match(')')) {
break;
}
this.expectCommaSeparator();
if (this.match(')')) {
break;
}
}
}
this.expect(')');
return args;
};
Parser.prototype.parseLeftHandSideExpressionAllowCall = function () {
var startToken = this.lookahead;
var maybeAsync = this.matchContextualKeyword('async');
var previousAllowIn = this.context.allowIn;
this.context.allowIn = true;
var expr;
if (this.matchKeyword('super') && this.context.inFunctionBody) {
expr = this.createNode();
this.nextToken();
expr = this.finalize(expr, new Node.Super());
if (!this.match('(') && !this.match('.') && !this.match('[')) {
this.throwUnexpectedToken(this.lookahead);
}
} else {
expr = this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
}
while (true) {
if (this.match('.')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
this.expect('.');
var property = this.parseIdentifierName();
expr = this.finalize(this.startNode(startToken), new Node.StaticMemberExpression(expr, property));
} else if (this.match('(')) {
var asyncArrow = maybeAsync && startToken.lineNumber === this.lookahead.lineNumber;
this.context.isBindingElement = false;
this.context.isAssignmentTarget = false;
var args = asyncArrow ? this.parseAsyncArguments() : this.parseArguments();
expr = this.finalize(this.startNode(startToken), new Node.CallExpression(expr, args));
if (asyncArrow && this.match('=>')) {
for (var i = 0; i < args.length; ++i) {
this.reinterpretExpressionAsPattern(args[i]);
}
expr = {
type: ArrowParameterPlaceHolder,
params: args,
async: true
};
}
} else if (this.match('[')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
this.expect('[');
var property = this.isolateCoverGrammar(this.parseExpression);
this.expect(']');
expr = this.finalize(this.startNode(startToken), new Node.ComputedMemberExpression(expr, property));
} else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
var quasi = this.parseTemplateLiteral();
expr = this.finalize(this.startNode(startToken), new Node.TaggedTemplateExpression(expr, quasi));
} else {
break;
}
}
this.context.allowIn = previousAllowIn;
return expr;
};
Parser.prototype.parseSuper = function () {
var node = this.createNode();
this.expectKeyword('super');
if (!this.match('[') && !this.match('.')) {
this.throwUnexpectedToken(this.lookahead);
}
return this.finalize(node, new Node.Super());
};
Parser.prototype.parseLeftHandSideExpression = function () {
assert_1.assert(this.context.allowIn, 'callee of new expression always allow in keyword.');
var node = this.startNode(this.lookahead);
var expr = this.matchKeyword('super') && this.context.inFunctionBody ? this.parseSuper() : this.inheritCoverGrammar(this.matchKeyword('new') ? this.parseNewExpression : this.parsePrimaryExpression);
while (true) {
if (this.match('[')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
this.expect('[');
var property = this.isolateCoverGrammar(this.parseExpression);
this.expect(']');
expr = this.finalize(node, new Node.ComputedMemberExpression(expr, property));
} else if (this.match('.')) {
this.context.isBindingElement = false;
this.context.isAssignmentTarget = true;
this.expect('.');
var property = this.parseIdentifierName();
expr = this.finalize(node, new Node.StaticMemberExpression(expr, property));
} else if (this.lookahead.type === 10 /* Template */ && this.lookahead.head) {
var quasi = this.parseTemplateLiteral();
expr = this.finalize(node, new Node.TaggedTemplateExpression(expr, quasi));
} else {
break;
}
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-update-expressions
Parser.prototype.parseUpdateExpression = function () {
var expr;
var startToken = this.lookahead;
if (this.match('++') || this.match('--')) {
var node = this.startNode(startToken);
var token = this.nextToken();
expr = this.inheritCoverGrammar(this.parseUnaryExpression);
if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
this.tolerateError(messages_1.Messages.StrictLHSPrefix);
}
if (!this.context.isAssignmentTarget) {
this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
}
var prefix = true;
expr = this.finalize(node, new Node.UpdateExpression(token.value, expr, prefix));
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
} else {
expr = this.inheritCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
if (!this.hasLineTerminator && this.lookahead.type === 7 /* Punctuator */) {
if (this.match('++') || this.match('--')) {
if (this.context.strict && expr.type === syntax_1.Syntax.Identifier && this.scanner.isRestrictedWord(expr.name)) {
this.tolerateError(messages_1.Messages.StrictLHSPostfix);
}
if (!this.context.isAssignmentTarget) {
this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
}
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var operator = this.nextToken().value;
var prefix = false;
expr = this.finalize(this.startNode(startToken), new Node.UpdateExpression(operator, expr, prefix));
}
}
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-unary-operators
Parser.prototype.parseAwaitExpression = function () {
var node = this.createNode();
this.nextToken();
var argument = this.parseUnaryExpression();
return this.finalize(node, new Node.AwaitExpression(argument));
};
Parser.prototype.parseUnaryExpression = function () {
var expr;
if (this.match('+') || this.match('-') || this.match('~') || this.match('!') || this.matchKeyword('delete') || this.matchKeyword('void') || this.matchKeyword('typeof')) {
var node = this.startNode(this.lookahead);
var token = this.nextToken();
expr = this.inheritCoverGrammar(this.parseUnaryExpression);
expr = this.finalize(node, new Node.UnaryExpression(token.value, expr));
if (this.context.strict && expr.operator === 'delete' && expr.argument.type === syntax_1.Syntax.Identifier) {
this.tolerateError(messages_1.Messages.StrictDelete);
}
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
} else if (this.context.await && this.matchContextualKeyword('await')) {
expr = this.parseAwaitExpression();
} else {
expr = this.parseUpdateExpression();
}
return expr;
};
Parser.prototype.parseExponentiationExpression = function () {
var startToken = this.lookahead;
var expr = this.inheritCoverGrammar(this.parseUnaryExpression);
if (expr.type !== syntax_1.Syntax.UnaryExpression && this.match('**')) {
this.nextToken();
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var left = expr;
var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
expr = this.finalize(this.startNode(startToken), new Node.BinaryExpression('**', left, right));
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-exp-operator
// https://tc39.github.io/ecma262/#sec-multiplicative-operators
// https://tc39.github.io/ecma262/#sec-additive-operators
// https://tc39.github.io/ecma262/#sec-bitwise-shift-operators
// https://tc39.github.io/ecma262/#sec-relational-operators
// https://tc39.github.io/ecma262/#sec-equality-operators
// https://tc39.github.io/ecma262/#sec-binary-bitwise-operators
// https://tc39.github.io/ecma262/#sec-binary-logical-operators
Parser.prototype.binaryPrecedence = function (token) {
var op = token.value;
var precedence;
if (token.type === 7 /* Punctuator */) {
precedence = this.operatorPrecedence[op] || 0;
} else if (token.type === 4 /* Keyword */) {
precedence = op === 'instanceof' || this.context.allowIn && op === 'in' ? 7 : 0;
} else {
precedence = 0;
}
return precedence;
};
Parser.prototype.parseBinaryExpression = function () {
var startToken = this.lookahead;
var expr = this.inheritCoverGrammar(this.parseExponentiationExpression);
var token = this.lookahead;
var prec = this.binaryPrecedence(token);
if (prec > 0) {
this.nextToken();
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var markers = [startToken, this.lookahead];
var left = expr;
var right = this.isolateCoverGrammar(this.parseExponentiationExpression);
var stack = [left, token.value, right];
var precedences = [prec];
while (true) {
prec = this.binaryPrecedence(this.lookahead);
if (prec <= 0) {
break;
}
// Reduce: make a binary expression from the three topmost entries.
while (stack.length > 2 && prec <= precedences[precedences.length - 1]) {
right = stack.pop();
var operator = stack.pop();
precedences.pop();
left = stack.pop();
markers.pop();
var node = this.startNode(markers[markers.length - 1]);
stack.push(this.finalize(node, new Node.BinaryExpression(operator, left, right)));
}
// Shift.
stack.push(this.nextToken().value);
precedences.push(prec);
markers.push(this.lookahead);
stack.push(this.isolateCoverGrammar(this.parseExponentiationExpression));
}
// Final reduce to clean-up the stack.
var i = stack.length - 1;
expr = stack[i];
markers.pop();
while (i > 1) {
var node = this.startNode(markers.pop());
var operator = stack[i - 1];
expr = this.finalize(node, new Node.BinaryExpression(operator, stack[i - 2], expr));
i -= 2;
}
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-conditional-operator
Parser.prototype.parseConditionalExpression = function () {
var startToken = this.lookahead;
var expr = this.inheritCoverGrammar(this.parseBinaryExpression);
if (this.match('?')) {
this.nextToken();
var previousAllowIn = this.context.allowIn;
this.context.allowIn = true;
var consequent = this.isolateCoverGrammar(this.parseAssignmentExpression);
this.context.allowIn = previousAllowIn;
this.expect(':');
var alternate = this.isolateCoverGrammar(this.parseAssignmentExpression);
expr = this.finalize(this.startNode(startToken), new Node.ConditionalExpression(expr, consequent, alternate));
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-assignment-operators
Parser.prototype.checkPatternParam = function (options, param) {
switch (param.type) {
case syntax_1.Syntax.Identifier:
this.validateParam(options, param, param.name);
break;
case syntax_1.Syntax.RestElement:
this.checkPatternParam(options, param.argument);
break;
case syntax_1.Syntax.AssignmentPattern:
this.checkPatternParam(options, param.left);
break;
case syntax_1.Syntax.ArrayPattern:
for (var i = 0; i < param.elements.length; i++) {
if (param.elements[i] !== null) {
this.checkPatternParam(options, param.elements[i]);
}
}
break;
case syntax_1.Syntax.ObjectPattern:
for (var i = 0; i < param.properties.length; i++) {
this.checkPatternParam(options, param.properties[i].value);
}
break;
default:
break;
}
options.simple = options.simple && param instanceof Node.Identifier;
};
Parser.prototype.reinterpretAsCoverFormalsList = function (expr) {
var params = [expr];
var options;
var asyncArrow = false;
switch (expr.type) {
case syntax_1.Syntax.Identifier:
break;
case ArrowParameterPlaceHolder:
params = expr.params;
asyncArrow = expr.async;
break;
default:
return null;
}
options = {
simple: true,
paramSet: {}
};
for (var i = 0; i < params.length; ++i) {
var param = params[i];
if (param.type === syntax_1.Syntax.AssignmentPattern) {
if (param.right.type === syntax_1.Syntax.YieldExpression) {
if (param.right.argument) {
this.throwUnexpectedToken(this.lookahead);
}
param.right.type = syntax_1.Syntax.Identifier;
param.right.name = 'yield';
delete param.right.argument;
delete param.right.delegate;
}
} else if (asyncArrow && param.type === syntax_1.Syntax.Identifier && param.name === 'await') {
this.throwUnexpectedToken(this.lookahead);
}
this.checkPatternParam(options, param);
params[i] = param;
}
if (this.context.strict || !this.context.allowYield) {
for (var i = 0; i < params.length; ++i) {
var param = params[i];
if (param.type === syntax_1.Syntax.YieldExpression) {
this.throwUnexpectedToken(this.lookahead);
}
}
}
if (options.message === messages_1.Messages.StrictParamDupe) {
var token = this.context.strict ? options.stricted : options.firstRestricted;
this.throwUnexpectedToken(token, options.message);
}
return {
simple: options.simple,
params: params,
stricted: options.stricted,
firstRestricted: options.firstRestricted,
message: options.message
};
};
Parser.prototype.parseAssignmentExpression = function () {
var expr;
if (!this.context.allowYield && this.matchKeyword('yield')) {
expr = this.parseYieldExpression();
} else {
var startToken = this.lookahead;
var token = startToken;
expr = this.parseConditionalExpression();
if (token.type === 3 /* Identifier */ && token.lineNumber === this.lookahead.lineNumber && token.value === 'async') {
if (this.lookahead.type === 3 /* Identifier */ || this.matchKeyword('yield')) {
var arg = this.parsePrimaryExpression();
this.reinterpretExpressionAsPattern(arg);
expr = {
type: ArrowParameterPlaceHolder,
params: [arg],
async: true
};
}
}
if (expr.type === ArrowParameterPlaceHolder || this.match('=>')) {
// https://tc39.github.io/ecma262/#sec-arrow-function-definitions
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
var isAsync = expr.async;
var list = this.reinterpretAsCoverFormalsList(expr);
if (list) {
if (this.hasLineTerminator) {
this.tolerateUnexpectedToken(this.lookahead);
}
this.context.firstCoverInitializedNameError = null;
var previousStrict = this.context.strict;
var previousAllowStrictDirective = this.context.allowStrictDirective;
this.context.allowStrictDirective = list.simple;
var previousAllowYield = this.context.allowYield;
var previousAwait = this.context.await;
this.context.allowYield = true;
this.context.await = isAsync;
var node = this.startNode(startToken);
this.expect('=>');
var body = void 0;
if (this.match('{')) {
var previousAllowIn = this.context.allowIn;
this.context.allowIn = true;
body = this.parseFunctionSourceElements();
this.context.allowIn = previousAllowIn;
} else {
body = this.isolateCoverGrammar(this.parseAssignmentExpression);
}
var expression = body.type !== syntax_1.Syntax.BlockStatement;
if (this.context.strict && list.firstRestricted) {
this.throwUnexpectedToken(list.firstRestricted, list.message);
}
if (this.context.strict && list.stricted) {
this.tolerateUnexpectedToken(list.stricted, list.message);
}
expr = isAsync ? this.finalize(node, new Node.AsyncArrowFunctionExpression(list.params, body, expression)) : this.finalize(node, new Node.ArrowFunctionExpression(list.params, body, expression));
this.context.strict = previousStrict;
this.context.allowStrictDirective = previousAllowStrictDirective;
this.context.allowYield = previousAllowYield;
this.context.await = previousAwait;
}
} else {
if (this.matchAssign()) {
if (!this.context.isAssignmentTarget) {
this.tolerateError(messages_1.Messages.InvalidLHSInAssignment);
}
if (this.context.strict && expr.type === syntax_1.Syntax.Identifier) {
var id = expr;
if (this.scanner.isRestrictedWord(id.name)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictLHSAssignment);
}
if (this.scanner.isStrictModeReservedWord(id.name)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
}
}
if (!this.match('=')) {
this.context.isAssignmentTarget = false;
this.context.isBindingElement = false;
} else {
this.reinterpretExpressionAsPattern(expr);
}
token = this.nextToken();
var operator = token.value;
var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
expr = this.finalize(this.startNode(startToken), new Node.AssignmentExpression(operator, expr, right));
this.context.firstCoverInitializedNameError = null;
}
}
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-comma-operator
Parser.prototype.parseExpression = function () {
var startToken = this.lookahead;
var expr = this.isolateCoverGrammar(this.parseAssignmentExpression);
if (this.match(',')) {
var expressions = [];
expressions.push(expr);
while (this.lookahead.type !== 2 /* EOF */) {
if (!this.match(',')) {
break;
}
this.nextToken();
expressions.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
}
expr = this.finalize(this.startNode(startToken), new Node.SequenceExpression(expressions));
}
return expr;
};
// https://tc39.github.io/ecma262/#sec-block
Parser.prototype.parseStatementListItem = function () {
var statement;
this.context.isAssignmentTarget = true;
this.context.isBindingElement = true;
if (this.lookahead.type === 4 /* Keyword */) {
switch (this.lookahead.value) {
case 'export':
if (!this.context.isModule) {
this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalExportDeclaration);
}
statement = this.parseExportDeclaration();
break;
case 'import':
if (!this.context.isModule) {
this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.IllegalImportDeclaration);
}
statement = this.parseImportDeclaration();
break;
case 'const':
statement = this.parseLexicalDeclaration({ inFor: false });
break;
case 'function':
statement = this.parseFunctionDeclaration();
break;
case 'class':
statement = this.parseClassDeclaration();
break;
case 'let':
statement = this.isLexicalDeclaration() ? this.parseLexicalDeclaration({ inFor: false }) : this.parseStatement();
break;
default:
statement = this.parseStatement();
break;
}
} else {
statement = this.parseStatement();
}
return statement;
};
Parser.prototype.parseBlock = function () {
var node = this.createNode();
this.expect('{');
var block = [];
while (true) {
if (this.match('}')) {
break;
}
block.push(this.parseStatementListItem());
}
this.expect('}');
return this.finalize(node, new Node.BlockStatement(block));
};
// https://tc39.github.io/ecma262/#sec-let-and-const-declarations
Parser.prototype.parseLexicalBinding = function (kind, options) {
var node = this.createNode();
var params = [];
var id = this.parsePattern(params, kind);
if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
if (this.scanner.isRestrictedWord(id.name)) {
this.tolerateError(messages_1.Messages.StrictVarName);
}
}
var init = null;
if (kind === 'const') {
if (!this.matchKeyword('in') && !this.matchContextualKeyword('of')) {
if (this.match('=')) {
this.nextToken();
init = this.isolateCoverGrammar(this.parseAssignmentExpression);
} else {
this.throwError(messages_1.Messages.DeclarationMissingInitializer, 'const');
}
}
} else if (!options.inFor && id.type !== syntax_1.Syntax.Identifier || this.match('=')) {
this.expect('=');
init = this.isolateCoverGrammar(this.parseAssignmentExpression);
}
return this.finalize(node, new Node.VariableDeclarator(id, init));
};
Parser.prototype.parseBindingList = function (kind, options) {
var list = [this.parseLexicalBinding(kind, options)];
while (this.match(',')) {
this.nextToken();
list.push(this.parseLexicalBinding(kind, options));
}
return list;
};
Parser.prototype.isLexicalDeclaration = function () {
var state = this.scanner.saveState();
this.scanner.scanComments();
var next = this.scanner.lex();
this.scanner.restoreState(state);
return next.type === 3 /* Identifier */ || next.type === 7 /* Punctuator */ && next.value === '[' || next.type === 7 /* Punctuator */ && next.value === '{' || next.type === 4 /* Keyword */ && next.value === 'let' || next.type === 4 /* Keyword */ && next.value === 'yield';
};
Parser.prototype.parseLexicalDeclaration = function (options) {
var node = this.createNode();
var kind = this.nextToken().value;
assert_1.assert(kind === 'let' || kind === 'const', 'Lexical declaration must be either let or const');
var declarations = this.parseBindingList(kind, options);
this.consumeSemicolon();
return this.finalize(node, new Node.VariableDeclaration(declarations, kind));
};
// https://tc39.github.io/ecma262/#sec-destructuring-binding-patterns
Parser.prototype.parseBindingRestElement = function (params, kind) {
var node = this.createNode();
this.expect('...');
var arg = this.parsePattern(params, kind);
return this.finalize(node, new Node.RestElement(arg));
};
Parser.prototype.parseArrayPattern = function (params, kind) {
var node = this.createNode();
this.expect('[');
var elements = [];
while (!this.match(']')) {
if (this.match(',')) {
this.nextToken();
elements.push(null);
} else {
if (this.match('...')) {
elements.push(this.parseBindingRestElement(params, kind));
break;
} else {
elements.push(this.parsePatternWithDefault(params, kind));
}
if (!this.match(']')) {
this.expect(',');
}
}
}
this.expect(']');
return this.finalize(node, new Node.ArrayPattern(elements));
};
Parser.prototype.parsePropertyPattern = function (params, kind) {
var node = this.createNode();
var computed = false;
var shorthand = false;
var method = false;
var key;
var value;
if (this.lookahead.type === 3 /* Identifier */) {
var keyToken = this.lookahead;
key = this.parseVariableIdentifier();
var init = this.finalize(node, new Node.Identifier(keyToken.value));
if (this.match('=')) {
params.push(keyToken);
shorthand = true;
this.nextToken();
var expr = this.parseAssignmentExpression();
value = this.finalize(this.startNode(keyToken), new Node.AssignmentPattern(init, expr));
} else if (!this.match(':')) {
params.push(keyToken);
shorthand = true;
value = init;
} else {
this.expect(':');
value = this.parsePatternWithDefault(params, kind);
}
} else {
computed = this.match('[');
key = this.parseObjectPropertyKey();
this.expect(':');
value = this.parsePatternWithDefault(params, kind);
}
return this.finalize(node, new Node.Property('init', key, computed, value, method, shorthand));
};
Parser.prototype.parseObjectPattern = function (params, kind) {
var node = this.createNode();
var properties = [];
this.expect('{');
while (!this.match('}')) {
properties.push(this.parsePropertyPattern(params, kind));
if (!this.match('}')) {
this.expect(',');
}
}
this.expect('}');
return this.finalize(node, new Node.ObjectPattern(properties));
};
Parser.prototype.parsePattern = function (params, kind) {
var pattern;
if (this.match('[')) {
pattern = this.parseArrayPattern(params, kind);
} else if (this.match('{')) {
pattern = this.parseObjectPattern(params, kind);
} else {
if (this.matchKeyword('let') && (kind === 'const' || kind === 'let')) {
this.tolerateUnexpectedToken(this.lookahead, messages_1.Messages.LetInLexicalBinding);
}
params.push(this.lookahead);
pattern = this.parseVariableIdentifier(kind);
}
return pattern;
};
Parser.prototype.parsePatternWithDefault = function (params, kind) {
var startToken = this.lookahead;
var pattern = this.parsePattern(params, kind);
if (this.match('=')) {
this.nextToken();
var previousAllowYield = this.context.allowYield;
this.context.allowYield = true;
var right = this.isolateCoverGrammar(this.parseAssignmentExpression);
this.context.allowYield = previousAllowYield;
pattern = this.finalize(this.startNode(startToken), new Node.AssignmentPattern(pattern, right));
}
return pattern;
};
// https://tc39.github.io/ecma262/#sec-variable-statement
Parser.prototype.parseVariableIdentifier = function (kind) {
var node = this.createNode();
var token = this.nextToken();
if (token.type === 4 /* Keyword */ && token.value === 'yield') {
if (this.context.strict) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
} else if (!this.context.allowYield) {
this.throwUnexpectedToken(token);
}
} else if (token.type !== 3 /* Identifier */) {
if (this.context.strict && token.type === 4 /* Keyword */ && this.scanner.isStrictModeReservedWord(token.value)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictReservedWord);
} else {
if (this.context.strict || token.value !== 'let' || kind !== 'var') {
this.throwUnexpectedToken(token);
}
}
} else if ((this.context.isModule || this.context.await) && token.type === 3 /* Identifier */ && token.value === 'await') {
this.tolerateUnexpectedToken(token);
}
return this.finalize(node, new Node.Identifier(token.value));
};
Parser.prototype.parseVariableDeclaration = function (options) {
var node = this.createNode();
var params = [];
var id = this.parsePattern(params, 'var');
if (this.context.strict && id.type === syntax_1.Syntax.Identifier) {
if (this.scanner.isRestrictedWord(id.name)) {
this.tolerateError(messages_1.Messages.StrictVarName);
}
}
var init = null;
if (this.match('=')) {
this.nextToken();
init = this.isolateCoverGrammar(this.parseAssignmentExpression);
} else if (id.type !== syntax_1.Syntax.Identifier && !options.inFor) {
this.expect('=');
}
return this.finalize(node, new Node.VariableDeclarator(id, init));
};
Parser.prototype.parseVariableDeclarationList = function (options) {
var opt = { inFor: options.inFor };
var list = [];
list.push(this.parseVariableDeclaration(opt));
while (this.match(',')) {
this.nextToken();
list.push(this.parseVariableDeclaration(opt));
}
return list;
};
Parser.prototype.parseVariableStatement = function () {
var node = this.createNode();
this.expectKeyword('var');
var declarations = this.parseVariableDeclarationList({ inFor: false });
this.consumeSemicolon();
return this.finalize(node, new Node.VariableDeclaration(declarations, 'var'));
};
// https://tc39.github.io/ecma262/#sec-empty-statement
Parser.prototype.parseEmptyStatement = function () {
var node = this.createNode();
this.expect(';');
return this.finalize(node, new Node.EmptyStatement());
};
// https://tc39.github.io/ecma262/#sec-expression-statement
Parser.prototype.parseExpressionStatement = function () {
var node = this.createNode();
var expr = this.parseExpression();
this.consumeSemicolon();
return this.finalize(node, new Node.ExpressionStatement(expr));
};
// https://tc39.github.io/ecma262/#sec-if-statement
Parser.prototype.parseIfClause = function () {
if (this.context.strict && this.matchKeyword('function')) {
this.tolerateError(messages_1.Messages.StrictFunction);
}
return this.parseStatement();
};
Parser.prototype.parseIfStatement = function () {
var node = this.createNode();
var consequent;
var alternate = null;
this.expectKeyword('if');
this.expect('(');
var test = this.parseExpression();
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
consequent = this.finalize(this.createNode(), new Node.EmptyStatement());
} else {
this.expect(')');
consequent = this.parseIfClause();
if (this.matchKeyword('else')) {
this.nextToken();
alternate = this.parseIfClause();
}
}
return this.finalize(node, new Node.IfStatement(test, consequent, alternate));
};
// https://tc39.github.io/ecma262/#sec-do-while-statement
Parser.prototype.parseDoWhileStatement = function () {
var node = this.createNode();
this.expectKeyword('do');
var previousInIteration = this.context.inIteration;
this.context.inIteration = true;
var body = this.parseStatement();
this.context.inIteration = previousInIteration;
this.expectKeyword('while');
this.expect('(');
var test = this.parseExpression();
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
} else {
this.expect(')');
if (this.match(';')) {
this.nextToken();
}
}
return this.finalize(node, new Node.DoWhileStatement(body, test));
};
// https://tc39.github.io/ecma262/#sec-while-statement
Parser.prototype.parseWhileStatement = function () {
var node = this.createNode();
var body;
this.expectKeyword('while');
this.expect('(');
var test = this.parseExpression();
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
body = this.finalize(this.createNode(), new Node.EmptyStatement());
} else {
this.expect(')');
var previousInIteration = this.context.inIteration;
this.context.inIteration = true;
body = this.parseStatement();
this.context.inIteration = previousInIteration;
}
return this.finalize(node, new Node.WhileStatement(test, body));
};
// https://tc39.github.io/ecma262/#sec-for-statement
// https://tc39.github.io/ecma262/#sec-for-in-and-for-of-statements
Parser.prototype.parseForStatement = function () {
var init = null;
var test = null;
var update = null;
var forIn = true;
var left, right;
var node = this.createNode();
this.expectKeyword('for');
this.expect('(');
if (this.match(';')) {
this.nextToken();
} else {
if (this.matchKeyword('var')) {
init = this.createNode();
this.nextToken();
var previousAllowIn = this.context.allowIn;
this.context.allowIn = false;
var declarations = this.parseVariableDeclarationList({ inFor: true });
this.context.allowIn = previousAllowIn;
if (declarations.length === 1 && this.matchKeyword('in')) {
var decl = declarations[0];
if (decl.init && (decl.id.type === syntax_1.Syntax.ArrayPattern || decl.id.type === syntax_1.Syntax.ObjectPattern || this.context.strict)) {
this.tolerateError(messages_1.Messages.ForInOfLoopInitializer, 'for-in');
}
init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
this.nextToken();
left = init;
right = this.parseExpression();
init = null;
} else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
this.nextToken();
left = init;
right = this.parseAssignmentExpression();
init = null;
forIn = false;
} else {
init = this.finalize(init, new Node.VariableDeclaration(declarations, 'var'));
this.expect(';');
}
} else if (this.matchKeyword('const') || this.matchKeyword('let')) {
init = this.createNode();
var kind = this.nextToken().value;
if (!this.context.strict && this.lookahead.value === 'in') {
init = this.finalize(init, new Node.Identifier(kind));
this.nextToken();
left = init;
right = this.parseExpression();
init = null;
} else {
var previousAllowIn = this.context.allowIn;
this.context.allowIn = false;
var declarations = this.parseBindingList(kind, { inFor: true });
this.context.allowIn = previousAllowIn;
if (declarations.length === 1 && declarations[0].init === null && this.matchKeyword('in')) {
init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
this.nextToken();
left = init;
right = this.parseExpression();
init = null;
} else if (declarations.length === 1 && declarations[0].init === null && this.matchContextualKeyword('of')) {
init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
this.nextToken();
left = init;
right = this.parseAssignmentExpression();
init = null;
forIn = false;
} else {
this.consumeSemicolon();
init = this.finalize(init, new Node.VariableDeclaration(declarations, kind));
}
}
} else {
var initStartToken = this.lookahead;
var previousAllowIn = this.context.allowIn;
this.context.allowIn = false;
init = this.inheritCoverGrammar(this.parseAssignmentExpression);
this.context.allowIn = previousAllowIn;
if (this.matchKeyword('in')) {
if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
this.tolerateError(messages_1.Messages.InvalidLHSInForIn);
}
this.nextToken();
this.reinterpretExpressionAsPattern(init);
left = init;
right = this.parseExpression();
init = null;
} else if (this.matchContextualKeyword('of')) {
if (!this.context.isAssignmentTarget || init.type === syntax_1.Syntax.AssignmentExpression) {
this.tolerateError(messages_1.Messages.InvalidLHSInForLoop);
}
this.nextToken();
this.reinterpretExpressionAsPattern(init);
left = init;
right = this.parseAssignmentExpression();
init = null;
forIn = false;
} else {
if (this.match(',')) {
var initSeq = [init];
while (this.match(',')) {
this.nextToken();
initSeq.push(this.isolateCoverGrammar(this.parseAssignmentExpression));
}
init = this.finalize(this.startNode(initStartToken), new Node.SequenceExpression(initSeq));
}
this.expect(';');
}
}
}
if (typeof left === 'undefined') {
if (!this.match(';')) {
test = this.parseExpression();
}
this.expect(';');
if (!this.match(')')) {
update = this.parseExpression();
}
}
var body;
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
body = this.finalize(this.createNode(), new Node.EmptyStatement());
} else {
this.expect(')');
var previousInIteration = this.context.inIteration;
this.context.inIteration = true;
body = this.isolateCoverGrammar(this.parseStatement);
this.context.inIteration = previousInIteration;
}
return typeof left === 'undefined' ? this.finalize(node, new Node.ForStatement(init, test, update, body)) : forIn ? this.finalize(node, new Node.ForInStatement(left, right, body)) : this.finalize(node, new Node.ForOfStatement(left, right, body));
};
// https://tc39.github.io/ecma262/#sec-continue-statement
Parser.prototype.parseContinueStatement = function () {
var node = this.createNode();
this.expectKeyword('continue');
var label = null;
if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) {
var id = this.parseVariableIdentifier();
label = id;
var key = '$' + id.name;
if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
this.throwError(messages_1.Messages.UnknownLabel, id.name);
}
}
this.consumeSemicolon();
if (label === null && !this.context.inIteration) {
this.throwError(messages_1.Messages.IllegalContinue);
}
return this.finalize(node, new Node.ContinueStatement(label));
};
// https://tc39.github.io/ecma262/#sec-break-statement
Parser.prototype.parseBreakStatement = function () {
var node = this.createNode();
this.expectKeyword('break');
var label = null;
if (this.lookahead.type === 3 /* Identifier */ && !this.hasLineTerminator) {
var id = this.parseVariableIdentifier();
var key = '$' + id.name;
if (!Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
this.throwError(messages_1.Messages.UnknownLabel, id.name);
}
label = id;
}
this.consumeSemicolon();
if (label === null && !this.context.inIteration && !this.context.inSwitch) {
this.throwError(messages_1.Messages.IllegalBreak);
}
return this.finalize(node, new Node.BreakStatement(label));
};
// https://tc39.github.io/ecma262/#sec-return-statement
Parser.prototype.parseReturnStatement = function () {
if (!this.context.inFunctionBody) {
this.tolerateError(messages_1.Messages.IllegalReturn);
}
var node = this.createNode();
this.expectKeyword('return');
var hasArgument = !this.match(';') && !this.match('}') && !this.hasLineTerminator && this.lookahead.type !== 2 /* EOF */;
var argument = hasArgument ? this.parseExpression() : null;
this.consumeSemicolon();
return this.finalize(node, new Node.ReturnStatement(argument));
};
// https://tc39.github.io/ecma262/#sec-with-statement
Parser.prototype.parseWithStatement = function () {
if (this.context.strict) {
this.tolerateError(messages_1.Messages.StrictModeWith);
}
var node = this.createNode();
var body;
this.expectKeyword('with');
this.expect('(');
var object = this.parseExpression();
if (!this.match(')') && this.config.tolerant) {
this.tolerateUnexpectedToken(this.nextToken());
body = this.finalize(this.createNode(), new Node.EmptyStatement());
} else {
this.expect(')');
body = this.parseStatement();
}
return this.finalize(node, new Node.WithStatement(object, body));
};
// https://tc39.github.io/ecma262/#sec-switch-statement
Parser.prototype.parseSwitchCase = function () {
var node = this.createNode();
var test;
if (this.matchKeyword('default')) {
this.nextToken();
test = null;
} else {
this.expectKeyword('case');
test = this.parseExpression();
}
this.expect(':');
var consequent = [];
while (true) {
if (this.match('}') || this.matchKeyword('default') || this.matchKeyword('case')) {
break;
}
consequent.push(this.parseStatementListItem());
}
return this.finalize(node, new Node.SwitchCase(test, consequent));
};
Parser.prototype.parseSwitchStatement = function () {
var node = this.createNode();
this.expectKeyword('switch');
this.expect('(');
var discriminant = this.parseExpression();
this.expect(')');
var previousInSwitch = this.context.inSwitch;
this.context.inSwitch = true;
var cases = [];
var defaultFound = false;
this.expect('{');
while (true) {
if (this.match('}')) {
break;
}
var clause = this.parseSwitchCase();
if (clause.test === null) {
if (defaultFound) {
this.throwError(messages_1.Messages.MultipleDefaultsInSwitch);
}
defaultFound = true;
}
cases.push(clause);
}
this.expect('}');
this.context.inSwitch = previousInSwitch;
return this.finalize(node, new Node.SwitchStatement(discriminant, cases));
};
// https://tc39.github.io/ecma262/#sec-labelled-statements
Parser.prototype.parseLabelledStatement = function () {
var node = this.createNode();
var expr = this.parseExpression();
var statement;
if (expr.type === syntax_1.Syntax.Identifier && this.match(':')) {
this.nextToken();
var id = expr;
var key = '$' + id.name;
if (Object.prototype.hasOwnProperty.call(this.context.labelSet, key)) {
this.throwError(messages_1.Messages.Redeclaration, 'Label', id.name);
}
this.context.labelSet[key] = true;
var body = void 0;
if (this.matchKeyword('class')) {
this.tolerateUnexpectedToken(this.lookahead);
body = this.parseClassDeclaration();
} else if (this.matchKeyword('function')) {
var token = this.lookahead;
var declaration = this.parseFunctionDeclaration();
if (this.context.strict) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunction);
} else if (declaration.generator) {
this.tolerateUnexpectedToken(token, messages_1.Messages.GeneratorInLegacyContext);
}
body = declaration;
} else {
body = this.parseStatement();
}
delete this.context.labelSet[key];
statement = new Node.LabeledStatement(id, body);
} else {
this.consumeSemicolon();
statement = new Node.ExpressionStatement(expr);
}
return this.finalize(node, statement);
};
// https://tc39.github.io/ecma262/#sec-throw-statement
Parser.prototype.parseThrowStatement = function () {
var node = this.createNode();
this.expectKeyword('throw');
if (this.hasLineTerminator) {
this.throwError(messages_1.Messages.NewlineAfterThrow);
}
var argument = this.parseExpression();
this.consumeSemicolon();
return this.finalize(node, new Node.ThrowStatement(argument));
};
// https://tc39.github.io/ecma262/#sec-try-statement
Parser.prototype.parseCatchClause = function () {
var node = this.createNode();
this.expectKeyword('catch');
this.expect('(');
if (this.match(')')) {
this.throwUnexpectedToken(this.lookahead);
}
var params = [];
var param = this.parsePattern(params);
var paramMap = {};
for (var i = 0; i < params.length; i++) {
var key = '$' + params[i].value;
if (Object.prototype.hasOwnProperty.call(paramMap, key)) {
this.tolerateError(messages_1.Messages.DuplicateBinding, params[i].value);
}
paramMap[key] = true;
}
if (this.context.strict && param.type === syntax_1.Syntax.Identifier) {
if (this.scanner.isRestrictedWord(param.name)) {
this.tolerateError(messages_1.Messages.StrictCatchVariable);
}
}
this.expect(')');
var body = this.parseBlock();
return this.finalize(node, new Node.CatchClause(param, body));
};
Parser.prototype.parseFinallyClause = function () {
this.expectKeyword('finally');
return this.parseBlock();
};
Parser.prototype.parseTryStatement = function () {
var node = this.createNode();
this.expectKeyword('try');
var block = this.parseBlock();
var handler = this.matchKeyword('catch') ? this.parseCatchClause() : null;
var finalizer = this.matchKeyword('finally') ? this.parseFinallyClause() : null;
if (!handler && !finalizer) {
this.throwError(messages_1.Messages.NoCatchOrFinally);
}
return this.finalize(node, new Node.TryStatement(block, handler, finalizer));
};
// https://tc39.github.io/ecma262/#sec-debugger-statement
Parser.prototype.parseDebuggerStatement = function () {
var node = this.createNode();
this.expectKeyword('debugger');
this.consumeSemicolon();
return this.finalize(node, new Node.DebuggerStatement());
};
// https://tc39.github.io/ecma262/#sec-ecmascript-language-statements-and-declarations
Parser.prototype.parseStatement = function () {
var statement;
switch (this.lookahead.type) {
case 1 /* BooleanLiteral */:
case 5 /* NullLiteral */:
case 6 /* NumericLiteral */:
case 8 /* StringLiteral */:
case 10 /* Template */:
case 9 /* RegularExpression */:
statement = this.parseExpressionStatement();
break;
case 7 /* Punctuator */:
var value = this.lookahead.value;
if (value === '{') {
statement = this.parseBlock();
} else if (value === '(') {
statement = this.parseExpressionStatement();
} else if (value === ';') {
statement = this.parseEmptyStatement();
} else {
statement = this.parseExpressionStatement();
}
break;
case 3 /* Identifier */:
statement = this.matchAsyncFunction() ? this.parseFunctionDeclaration() : this.parseLabelledStatement();
break;
case 4 /* Keyword */:
switch (this.lookahead.value) {
case 'break':
statement = this.parseBreakStatement();
break;
case 'continue':
statement = this.parseContinueStatement();
break;
case 'debugger':
statement = this.parseDebuggerStatement();
break;
case 'do':
statement = this.parseDoWhileStatement();
break;
case 'for':
statement = this.parseForStatement();
break;
case 'function':
statement = this.parseFunctionDeclaration();
break;
case 'if':
statement = this.parseIfStatement();
break;
case 'return':
statement = this.parseReturnStatement();
break;
case 'switch':
statement = this.parseSwitchStatement();
break;
case 'throw':
statement = this.parseThrowStatement();
break;
case 'try':
statement = this.parseTryStatement();
break;
case 'var':
statement = this.parseVariableStatement();
break;
case 'while':
statement = this.parseWhileStatement();
break;
case 'with':
statement = this.parseWithStatement();
break;
default:
statement = this.parseExpressionStatement();
break;
}
break;
default:
statement = this.throwUnexpectedToken(this.lookahead);
}
return statement;
};
// https://tc39.github.io/ecma262/#sec-function-definitions
Parser.prototype.parseFunctionSourceElements = function () {
var node = this.createNode();
this.expect('{');
var body = this.parseDirectivePrologues();
var previousLabelSet = this.context.labelSet;
var previousInIteration = this.context.inIteration;
var previousInSwitch = this.context.inSwitch;
var previousInFunctionBody = this.context.inFunctionBody;
this.context.labelSet = {};
this.context.inIteration = false;
this.context.inSwitch = false;
this.context.inFunctionBody = true;
while (this.lookahead.type !== 2 /* EOF */) {
if (this.match('}')) {
break;
}
body.push(this.parseStatementListItem());
}
this.expect('}');
this.context.labelSet = previousLabelSet;
this.context.inIteration = previousInIteration;
this.context.inSwitch = previousInSwitch;
this.context.inFunctionBody = previousInFunctionBody;
return this.finalize(node, new Node.BlockStatement(body));
};
Parser.prototype.validateParam = function (options, param, name) {
var key = '$' + name;
if (this.context.strict) {
if (this.scanner.isRestrictedWord(name)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamName;
}
if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamDupe;
}
} else if (!options.firstRestricted) {
if (this.scanner.isRestrictedWord(name)) {
options.firstRestricted = param;
options.message = messages_1.Messages.StrictParamName;
} else if (this.scanner.isStrictModeReservedWord(name)) {
options.firstRestricted = param;
options.message = messages_1.Messages.StrictReservedWord;
} else if (Object.prototype.hasOwnProperty.call(options.paramSet, key)) {
options.stricted = param;
options.message = messages_1.Messages.StrictParamDupe;
}
}
/* istanbul ignore next */
if (typeof Object.defineProperty === 'function') {
Object.defineProperty(options.paramSet, key, { value: true, enumerable: true, writable: true, configurable: true });
} else {
options.paramSet[key] = true;
}
};
Parser.prototype.parseRestElement = function (params) {
var node = this.createNode();
this.expect('...');
var arg = this.parsePattern(params);
if (this.match('=')) {
this.throwError(messages_1.Messages.DefaultRestParameter);
}
if (!this.match(')')) {
this.throwError(messages_1.Messages.ParameterAfterRestParameter);
}
return this.finalize(node, new Node.RestElement(arg));
};
Parser.prototype.parseFormalParameter = function (options) {
var params = [];
var param = this.match('...') ? this.parseRestElement(params) : this.parsePatternWithDefault(params);
for (var i = 0; i < params.length; i++) {
this.validateParam(options, params[i], params[i].value);
}
options.simple = options.simple && param instanceof Node.Identifier;
options.params.push(param);
};
Parser.prototype.parseFormalParameters = function (firstRestricted) {
var options;
options = {
simple: true,
params: [],
firstRestricted: firstRestricted
};
this.expect('(');
if (!this.match(')')) {
options.paramSet = {};
while (this.lookahead.type !== 2 /* EOF */) {
this.parseFormalParameter(options);
if (this.match(')')) {
break;
}
this.expect(',');
if (this.match(')')) {
break;
}
}
}
this.expect(')');
return {
simple: options.simple,
params: options.params,
stricted: options.stricted,
firstRestricted: options.firstRestricted,
message: options.message
};
};
Parser.prototype.matchAsyncFunction = function () {
var match = this.matchContextualKeyword('async');
if (match) {
var state = this.scanner.saveState();
this.scanner.scanComments();
var next = this.scanner.lex();
this.scanner.restoreState(state);
match = state.lineNumber === next.lineNumber && next.type === 4 /* Keyword */ && next.value === 'function';
}
return match;
};
Parser.prototype.parseFunctionDeclaration = function (identifierIsOptional) {
var node = this.createNode();
var isAsync = this.matchContextualKeyword('async');
if (isAsync) {
this.nextToken();
}
this.expectKeyword('function');
var isGenerator = isAsync ? false : this.match('*');
if (isGenerator) {
this.nextToken();
}
var message;
var id = null;
var firstRestricted = null;
if (!identifierIsOptional || !this.match('(')) {
var token = this.lookahead;
id = this.parseVariableIdentifier();
if (this.context.strict) {
if (this.scanner.isRestrictedWord(token.value)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
}
} else {
if (this.scanner.isRestrictedWord(token.value)) {
firstRestricted = token;
message = messages_1.Messages.StrictFunctionName;
} else if (this.scanner.isStrictModeReservedWord(token.value)) {
firstRestricted = token;
message = messages_1.Messages.StrictReservedWord;
}
}
}
var previousAllowAwait = this.context.await;
var previousAllowYield = this.context.allowYield;
this.context.await = isAsync;
this.context.allowYield = !isGenerator;
var formalParameters = this.parseFormalParameters(firstRestricted);
var params = formalParameters.params;
var stricted = formalParameters.stricted;
firstRestricted = formalParameters.firstRestricted;
if (formalParameters.message) {
message = formalParameters.message;
}
var previousStrict = this.context.strict;
var previousAllowStrictDirective = this.context.allowStrictDirective;
this.context.allowStrictDirective = formalParameters.simple;
var body = this.parseFunctionSourceElements();
if (this.context.strict && firstRestricted) {
this.throwUnexpectedToken(firstRestricted, message);
}
if (this.context.strict && stricted) {
this.tolerateUnexpectedToken(stricted, message);
}
this.context.strict = previousStrict;
this.context.allowStrictDirective = previousAllowStrictDirective;
this.context.await = previousAllowAwait;
this.context.allowYield = previousAllowYield;
return isAsync ? this.finalize(node, new Node.AsyncFunctionDeclaration(id, params, body)) : this.finalize(node, new Node.FunctionDeclaration(id, params, body, isGenerator));
};
Parser.prototype.parseFunctionExpression = function () {
var node = this.createNode();
var isAsync = this.matchContextualKeyword('async');
if (isAsync) {
this.nextToken();
}
this.expectKeyword('function');
var isGenerator = isAsync ? false : this.match('*');
if (isGenerator) {
this.nextToken();
}
var message;
var id = null;
var firstRestricted;
var previousAllowAwait = this.context.await;
var previousAllowYield = this.context.allowYield;
this.context.await = isAsync;
this.context.allowYield = !isGenerator;
if (!this.match('(')) {
var token = this.lookahead;
id = !this.context.strict && !isGenerator && this.matchKeyword('yield') ? this.parseIdentifierName() : this.parseVariableIdentifier();
if (this.context.strict) {
if (this.scanner.isRestrictedWord(token.value)) {
this.tolerateUnexpectedToken(token, messages_1.Messages.StrictFunctionName);
}
} else {
if (this.scanner.isRestrictedWord(token.value)) {
firstRestricted = token;
message = messages_1.Messages.StrictFunctionName;
} else if (this.scanner.isStrictModeReservedWord(token.value)) {
firstRestricted = token;
message = messages_1.Messages.StrictReservedWord;
}
}
}
var formalParameters = this.parseFormalParameters(firstRestricted);
var params = formalParameters.params;
var stricted = formalParameters.stricted;
firstRestricted = formalParameters.firstRestricted;
if (formalParameters.message) {
message = formalParameters.message;
}
var previousStrict = this.context.strict;
var previousAllowStrictDirective = this.context.allowStrictDirective;
this.context.allowStrictDirective = formalParameters.simple;
var body = this.parseFunctionSourceElements();
if (this.context.strict && firstRestricted) {
this.throwUnexpectedToken(firstRestricted, message);
}
if (this.context.strict && stricted) {
this.tolerateUnexpectedToken(stricted, message);
}
this.context.strict = previousStrict;
this.context.allowStrictDirective = previousAllowStrictDirective;
this.context.await = previousAllowAwait;
this.context.allowYield = previousAllowYield;
return isAsync ? this.finalize(node, new Node.AsyncFunctionExpression(id, params, body)) : this.finalize(node, new Node.FunctionExpression(id, params, body, isGenerator));
};
// https://tc39.github.io/ecma262/#sec-directive-prologues-and-the-use-strict-directive
Parser.prototype.parseDirective = function () {
var token = this.lookahead;
var node = this.createNode();
var expr = this.parseExpression();
var directive = expr.type === syntax_1.Syntax.Literal ? this.getTokenRaw(token).slice(1, -1) : null;
this.consumeSemicolon();
return this.finalize(node, directive ? new Node.Directive(expr, directive) : new Node.ExpressionStatement(expr));
};
Parser.prototype.parseDirectivePrologues = function () {
var firstRestricted = null;
var body = [];
while (true) {
var token = this.lookahead;
if (token.type !== 8 /* StringLiteral */) {
break;
}
var statement = this.parseDirective();
body.push(statement);
var directive = statement.directive;
if (typeof directive !== 'string') {
break;
}
if (directive === 'use strict') {
this.context.strict = true;
if (firstRestricted) {
this.tolerateUnexpectedToken(firstRestricted, messages_1.Messages.StrictOctalLiteral);
}
if (!this.context.allowStrictDirective) {
this.tolerateUnexpectedToken(token, messages_1.Messages.IllegalLanguageModeDirective);
}
} else {
if (!firstRestricted && token.octal) {
firstRestricted = token;
}
}
}
return body;
};
// https://tc39.github.io/ecma262/#sec-method-definitions
Parser.prototype.qualifiedPropertyName = function (token) {
switch (token.type) {
case 3 /* Identifier */:
case 8 /* StringLiteral */:
case 1 /* BooleanLiteral */:
case 5 /* NullLiteral */:
case 6 /* NumericLiteral */:
case 4 /* Keyword */:
return true;
case 7 /* Punctuator */:
return token.value === '[';
default:
break;
}
return false;
};
Parser.prototype.parseGetterMethod = function () {
var node = this.createNode();
var isGenerator = false;
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
var formalParameters = this.parseFormalParameters();
if (formalParameters.params.length > 0) {
this.tolerateError(messages_1.Messages.BadGetterArity);
}
var method = this.parsePropertyMethod(formalParameters);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
};
Parser.prototype.parseSetterMethod = function () {
var node = this.createNode();
var isGenerator = false;
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
var formalParameters = this.parseFormalParameters();
if (formalParameters.params.length !== 1) {
this.tolerateError(messages_1.Messages.BadSetterArity);
} else if (formalParameters.params[0] instanceof Node.RestElement) {
this.tolerateError(messages_1.Messages.BadSetterRestParameter);
}
var method = this.parsePropertyMethod(formalParameters);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, formalParameters.params, method, isGenerator));
};
Parser.prototype.parseGeneratorMethod = function () {
var node = this.createNode();
var isGenerator = true;
var previousAllowYield = this.context.allowYield;
this.context.allowYield = true;
var params = this.parseFormalParameters();
this.context.allowYield = false;
var method = this.parsePropertyMethod(params);
this.context.allowYield = previousAllowYield;
return this.finalize(node, new Node.FunctionExpression(null, params.params, method, isGenerator));
};
// https://tc39.github.io/ecma262/#sec-generator-function-definitions
Parser.prototype.isStartOfExpression = function () {
var start = true;
var value = this.lookahead.value;
switch (this.lookahead.type) {
case 7 /* Punctuator */:
start = value === '[' || value === '(' || value === '{' || value === '+' || value === '-' || value === '!' || value === '~' || value === '++' || value === '--' || value === '/' || value === '/='; // regular expression literal
break;
case 4 /* Keyword */:
start = value === 'class' || value === 'delete' || value === 'function' || value === 'let' || value === 'new' || value === 'super' || value === 'this' || value === 'typeof' || value === 'void' || value === 'yield';
break;
default:
break;
}
return start;
};
Parser.prototype.parseYieldExpression = function () {
var node = this.createNode();
this.expectKeyword('yield');
var argument = null;
var delegate = false;
if (!this.hasLineTerminator) {
var previousAllowYield = this.context.allowYield;
this.context.allowYield = false;
delegate = this.match('*');
if (delegate) {
this.nextToken();
argument = this.parseAssignmentExpression();
} else if (this.isStartOfExpression()) {
argument = this.parseAssignmentExpression();
}
this.context.allowYield = previousAllowYield;
}
return this.finalize(node, new Node.YieldExpression(argument, delegate));
};
// https://tc39.github.io/ecma262/#sec-class-definitions
Parser.prototype.parseClassElement = function (hasConstructor) {
var token = this.lookahead;
var node = this.createNode();
var kind = '';
var key = null;
var value = null;
var computed = false;
var method = false;
var isStatic = false;
var isAsync = false;
if (this.match('*')) {
this.nextToken();
} else {
computed = this.match('[');
key = this.parseObjectPropertyKey();
var id = key;
if (id.name === 'static' && (this.qualifiedPropertyName(this.lookahead) || this.match('*'))) {
token = this.lookahead;
isStatic = true;
computed = this.match('[');
if (this.match('*')) {
this.nextToken();
} else {
key = this.parseObjectPropertyKey();
}
}
if (token.type === 3 /* Identifier */ && !this.hasLineTerminator && token.value === 'async') {
var punctuator = this.lookahead.value;
if (punctuator !== ':' && punctuator !== '(' && punctuator !== '*') {
isAsync = true;
token = this.lookahead;
key = this.parseObjectPropertyKey();
if (token.type === 3 /* Identifier */) {
if (token.value === 'get' || token.value === 'set') {
this.tolerateUnexpectedToken(token);
} else if (token.value === 'constructor') {
this.tolerateUnexpectedToken(token, messages_1.Messages.ConstructorIsAsync);
}
}
}
}
}
var lookaheadPropertyKey = this.qualifiedPropertyName(this.lookahead);
if (token.type === 3 /* Identifier */) {
if (token.value === 'get' && lookaheadPropertyKey) {
kind = 'get';
computed = this.match('[');
key = this.parseObjectPropertyKey();
this.context.allowYield = false;
value = this.parseGetterMethod();
} else if (token.value === 'set' && lookaheadPropertyKey) {
kind = 'set';
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseSetterMethod();
}
} else if (token.type === 7 /* Punctuator */ && token.value === '*' && lookaheadPropertyKey) {
kind = 'init';
computed = this.match('[');
key = this.parseObjectPropertyKey();
value = this.parseGeneratorMethod();
method = true;
}
if (!kind && key && this.match('(')) {
kind = 'init';
value = isAsync ? this.parsePropertyMethodAsyncFunction() : this.parsePropertyMethodFunction();
method = true;
}
if (!kind) {
this.throwUnexpectedToken(this.lookahead);
}
if (kind === 'init') {
kind = 'method';
}
if (!computed) {
if (isStatic && this.isPropertyKey(key, 'prototype')) {
this.throwUnexpectedToken(token, messages_1.Messages.StaticPrototype);
}
if (!isStatic && this.isPropertyKey(key, 'constructor')) {
if (kind !== 'method' || !method || value && value.generator) {
this.throwUnexpectedToken(token, messages_1.Messages.ConstructorSpecialMethod);
}
if (hasConstructor.value) {
this.throwUnexpectedToken(token, messages_1.Messages.DuplicateConstructor);
} else {
hasConstructor.value = true;
}
kind = 'constructor';
}
}
return this.finalize(node, new Node.MethodDefinition(key, computed, value, kind, isStatic));
};
Parser.prototype.parseClassElementList = function () {
var body = [];
var hasConstructor = { value: false };
this.expect('{');
while (!this.match('}')) {
if (this.match(';')) {
this.nextToken();
} else {
body.push(this.parseClassElement(hasConstructor));
}
}
this.expect('}');
return body;
};
Parser.prototype.parseClassBody = function () {
var node = this.createNode();
var elementList = this.parseClassElementList();
return this.finalize(node, new Node.ClassBody(elementList));
};
Parser.prototype.parseClassDeclaration = function (identifierIsOptional) {
var node = this.createNode();
var previousStrict = this.context.strict;
this.context.strict = true;
this.expectKeyword('class');
var id = identifierIsOptional && this.lookahead.type !== 3 /* Identifier */ ? null : this.parseVariableIdentifier();
var superClass = null;
if (this.matchKeyword('extends')) {
this.nextToken();
superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
}
var classBody = this.parseClassBody();
this.context.strict = previousStrict;
return this.finalize(node, new Node.ClassDeclaration(id, superClass, classBody));
};
Parser.prototype.parseClassExpression = function () {
var node = this.createNode();
var previousStrict = this.context.strict;
this.context.strict = true;
this.expectKeyword('class');
var id = this.lookahead.type === 3 /* Identifier */ ? this.parseVariableIdentifier() : null;
var superClass = null;
if (this.matchKeyword('extends')) {
this.nextToken();
superClass = this.isolateCoverGrammar(this.parseLeftHandSideExpressionAllowCall);
}
var classBody = this.parseClassBody();
this.context.strict = previousStrict;
return this.finalize(node, new Node.ClassExpression(id, superClass, classBody));
};
// https://tc39.github.io/ecma262/#sec-scripts
// https://tc39.github.io/ecma262/#sec-modules
Parser.prototype.parseModule = function () {
this.context.strict = true;
this.context.isModule = true;
var node = this.createNode();
var body = this.parseDirectivePrologues();
while (this.lookahead.type !== 2 /* EOF */) {
body.push(this.parseStatementListItem());
}
return this.finalize(node, new Node.Module(body));
};
Parser.prototype.parseScript = function () {
var node = this.createNode();
var body = this.parseDirectivePrologues();
while (this.lookahead.type !== 2 /* EOF */) {
body.push(this.parseStatementListItem());
}
return this.finalize(node, new Node.Script(body));
};
// https://tc39.github.io/ecma262/#sec-imports
Parser.prototype.parseModuleSpecifier = function () {
var node = this.createNode();
if (this.lookahead.type !== 8 /* StringLiteral */) {
this.throwError(messages_1.Messages.InvalidModuleSpecifier);
}
var token = this.nextToken();
var raw = this.getTokenRaw(token);
return this.finalize(node, new Node.Literal(token.value, raw));
};
// import {<foo as bar>} ...;
Parser.prototype.parseImportSpecifier = function () {
var node = this.createNode();
var imported;
var local;
if (this.lookahead.type === 3 /* Identifier */) {
imported = this.parseVariableIdentifier();
local = imported;
if (this.matchContextualKeyword('as')) {
this.nextToken();
local = this.parseVariableIdentifier();
}
} else {
imported = this.parseIdentifierName();
local = imported;
if (this.matchContextualKeyword('as')) {
this.nextToken();
local = this.parseVariableIdentifier();
} else {
this.throwUnexpectedToken(this.nextToken());
}
}
return this.finalize(node, new Node.ImportSpecifier(local, imported));
};
// {foo, bar as bas}
Parser.prototype.parseNamedImports = function () {
this.expect('{');
var specifiers = [];
while (!this.match('}')) {
specifiers.push(this.parseImportSpecifier());
if (!this.match('}')) {
this.expect(',');
}
}
this.expect('}');
return specifiers;
};
// import <foo> ...;
Parser.prototype.parseImportDefaultSpecifier = function () {
var node = this.createNode();
var local = this.parseIdentifierName();
return this.finalize(node, new Node.ImportDefaultSpecifier(local));
};
// import <* as foo> ...;
Parser.prototype.parseImportNamespaceSpecifier = function () {
var node = this.createNode();
this.expect('*');
if (!this.matchContextualKeyword('as')) {
this.throwError(messages_1.Messages.NoAsAfterImportNamespace);
}
this.nextToken();
var local = this.parseIdentifierName();
return this.finalize(node, new Node.ImportNamespaceSpecifier(local));
};
Parser.prototype.parseImportDeclaration = function () {
if (this.context.inFunctionBody) {
this.throwError(messages_1.Messages.IllegalImportDeclaration);
}
var node = this.createNode();
this.expectKeyword('import');
var src;
var specifiers = [];
if (this.lookahead.type === 8 /* StringLiteral */) {
// import 'foo';
src = this.parseModuleSpecifier();
} else {
if (this.match('{')) {
// import {bar}
specifiers = specifiers.concat(this.parseNamedImports());
} else if (this.match('*')) {
// import * as foo
specifiers.push(this.parseImportNamespaceSpecifier());
} else if (this.isIdentifierName(this.lookahead) && !this.matchKeyword('default')) {
// import foo
specifiers.push(this.parseImportDefaultSpecifier());
if (this.match(',')) {
this.nextToken();
if (this.match('*')) {
// import foo, * as foo
specifiers.push(this.parseImportNamespaceSpecifier());
} else if (this.match('{')) {
// import foo, {bar}
specifiers = specifiers.concat(this.parseNamedImports());
} else {
this.throwUnexpectedToken(this.lookahead);
}
}
} else {
this.throwUnexpectedToken(this.nextToken());
}
if (!this.matchContextualKeyword('from')) {
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
}
this.nextToken();
src = this.parseModuleSpecifier();
}
this.consumeSemicolon();
return this.finalize(node, new Node.ImportDeclaration(specifiers, src));
};
// https://tc39.github.io/ecma262/#sec-exports
Parser.prototype.parseExportSpecifier = function () {
var node = this.createNode();
var local = this.parseIdentifierName();
var exported = local;
if (this.matchContextualKeyword('as')) {
this.nextToken();
exported = this.parseIdentifierName();
}
return this.finalize(node, new Node.ExportSpecifier(local, exported));
};
Parser.prototype.parseExportDeclaration = function () {
if (this.context.inFunctionBody) {
this.throwError(messages_1.Messages.IllegalExportDeclaration);
}
var node = this.createNode();
this.expectKeyword('export');
var exportDeclaration;
if (this.matchKeyword('default')) {
// export default ...
this.nextToken();
if (this.matchKeyword('function')) {
// export default function foo () {}
// export default function () {}
var declaration = this.parseFunctionDeclaration(true);
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
} else if (this.matchKeyword('class')) {
// export default class foo {}
var declaration = this.parseClassDeclaration(true);
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
} else if (this.matchContextualKeyword('async')) {
// export default async function f () {}
// export default async function () {}
// export default async x => x
var declaration = this.matchAsyncFunction() ? this.parseFunctionDeclaration(true) : this.parseAssignmentExpression();
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
} else {
if (this.matchContextualKeyword('from')) {
this.throwError(messages_1.Messages.UnexpectedToken, this.lookahead.value);
}
// export default {};
// export default [];
// export default (1 + 2);
var declaration = this.match('{') ? this.parseObjectInitializer() : this.match('[') ? this.parseArrayInitializer() : this.parseAssignmentExpression();
this.consumeSemicolon();
exportDeclaration = this.finalize(node, new Node.ExportDefaultDeclaration(declaration));
}
} else if (this.match('*')) {
// export * from 'foo';
this.nextToken();
if (!this.matchContextualKeyword('from')) {
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
}
this.nextToken();
var src = this.parseModuleSpecifier();
this.consumeSemicolon();
exportDeclaration = this.finalize(node, new Node.ExportAllDeclaration(src));
} else if (this.lookahead.type === 4 /* Keyword */) {
// export var f = 1;
var declaration = void 0;
switch (this.lookahead.value) {
case 'let':
case 'const':
declaration = this.parseLexicalDeclaration({ inFor: false });
break;
case 'var':
case 'class':
case 'function':
declaration = this.parseStatementListItem();
break;
default:
this.throwUnexpectedToken(this.lookahead);
}
exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
} else if (this.matchAsyncFunction()) {
var declaration = this.parseFunctionDeclaration();
exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(declaration, [], null));
} else {
var specifiers = [];
var source = null;
var isExportFromIdentifier = false;
this.expect('{');
while (!this.match('}')) {
isExportFromIdentifier = isExportFromIdentifier || this.matchKeyword('default');
specifiers.push(this.parseExportSpecifier());
if (!this.match('}')) {
this.expect(',');
}
}
this.expect('}');
if (this.matchContextualKeyword('from')) {
// export {default} from 'foo';
// export {foo} from 'foo';
this.nextToken();
source = this.parseModuleSpecifier();
this.consumeSemicolon();
} else if (isExportFromIdentifier) {
// export {default}; // missing fromClause
var message = this.lookahead.value ? messages_1.Messages.UnexpectedToken : messages_1.Messages.MissingFromClause;
this.throwError(message, this.lookahead.value);
} else {
// export {foo};
this.consumeSemicolon();
}
exportDeclaration = this.finalize(node, new Node.ExportNamedDeclaration(null, specifiers, source));
}
return exportDeclaration;
};
return Parser;
}();
exports.Parser = Parser;
/***/
},
/* 9 */
/***/function (module, exports) {
"use strict";
// Ensure the condition is true, otherwise throw an error.
// This is only to have a better contract semantic, i.e. another safety net
// to catch a logic error. The condition shall be fulfilled in normal case.
// Do NOT use this to enforce a certain condition on any user input.
Object.defineProperty(exports, "__esModule", { value: true });
function assert(condition, message) {
/* istanbul ignore if */
if (!condition) {
throw new Error('ASSERT: ' + message);
}
}
exports.assert = assert;
/***/
},
/* 10 */
/***/function (module, exports) {
"use strict";
/* tslint:disable:max-classes-per-file */
Object.defineProperty(exports, "__esModule", { value: true });
var ErrorHandler = function () {
function ErrorHandler() {
this.errors = [];
this.tolerant = false;
}
ErrorHandler.prototype.recordError = function (error) {
this.errors.push(error);
};
ErrorHandler.prototype.tolerate = function (error) {
if (this.tolerant) {
this.recordError(error);
} else {
throw error;
}
};
ErrorHandler.prototype.constructError = function (msg, column) {
var error = new Error(msg);
try {
throw error;
} catch (base) {
/* istanbul ignore else */
if (Object.create && Object.defineProperty) {
error = Object.create(base);
Object.defineProperty(error, 'column', { value: column });
}
}
/* istanbul ignore next */
return error;
};
ErrorHandler.prototype.createError = function (index, line, col, description) {
var msg = 'Line ' + line + ': ' + description;
var error = this.constructError(msg, col);
error.index = index;
error.lineNumber = line;
error.description = description;
return error;
};
ErrorHandler.prototype.throwError = function (index, line, col, description) {
throw this.createError(index, line, col, description);
};
ErrorHandler.prototype.tolerateError = function (index, line, col, description) {
var error = this.createError(index, line, col, description);
if (this.tolerant) {
this.recordError(error);
} else {
throw error;
}
};
return ErrorHandler;
}();
exports.ErrorHandler = ErrorHandler;
/***/
},
/* 11 */
/***/function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Error messages should be identical to V8.
exports.Messages = {
BadGetterArity: 'Getter must not have any formal parameters',
BadSetterArity: 'Setter must have exactly one formal parameter',
BadSetterRestParameter: 'Setter function argument must not be a rest parameter',
ConstructorIsAsync: 'Class constructor may not be an async method',
ConstructorSpecialMethod: 'Class constructor may not be an accessor',
DeclarationMissingInitializer: 'Missing initializer in %0 declaration',
DefaultRestParameter: 'Unexpected token =',
DuplicateBinding: 'Duplicate binding %0',
DuplicateConstructor: 'A class may only have one constructor',
DuplicateProtoProperty: 'Duplicate __proto__ fields are not allowed in object literals',
ForInOfLoopInitializer: '%0 loop variable declaration may not have an initializer',
GeneratorInLegacyContext: 'Generator declarations are not allowed in legacy contexts',
IllegalBreak: 'Illegal break statement',
IllegalContinue: 'Illegal continue statement',
IllegalExportDeclaration: 'Unexpected token',
IllegalImportDeclaration: 'Unexpected token',
IllegalLanguageModeDirective: 'Illegal \'use strict\' directive in function with non-simple parameter list',
IllegalReturn: 'Illegal return statement',
InvalidEscapedReservedWord: 'Keyword must not contain escaped characters',
InvalidHexEscapeSequence: 'Invalid hexadecimal escape sequence',
InvalidLHSInAssignment: 'Invalid left-hand side in assignment',
InvalidLHSInForIn: 'Invalid left-hand side in for-in',
InvalidLHSInForLoop: 'Invalid left-hand side in for-loop',
InvalidModuleSpecifier: 'Unexpected token',
InvalidRegExp: 'Invalid regular expression',
LetInLexicalBinding: 'let is disallowed as a lexically bound name',
MissingFromClause: 'Unexpected token',
MultipleDefaultsInSwitch: 'More than one default clause in switch statement',
NewlineAfterThrow: 'Illegal newline after throw',
NoAsAfterImportNamespace: 'Unexpected token',
NoCatchOrFinally: 'Missing catch or finally after try',
ParameterAfterRestParameter: 'Rest parameter must be last formal parameter',
Redeclaration: '%0 \'%1\' has already been declared',
StaticPrototype: 'Classes may not have static property named prototype',
StrictCatchVariable: 'Catch variable may not be eval or arguments in strict mode',
StrictDelete: 'Delete of an unqualified identifier in strict mode.',
StrictFunction: 'In strict mode code, functions can only be declared at top level or inside a block',
StrictFunctionName: 'Function name may not be eval or arguments in strict mode',
StrictLHSAssignment: 'Assignment to eval or arguments is not allowed in strict mode',
StrictLHSPostfix: 'Postfix increment/decrement may not have eval or arguments operand in strict mode',
StrictLHSPrefix: 'Prefix increment/decrement may not have eval or arguments operand in strict mode',
StrictModeWith: 'Strict mode code may not include a with statement',
StrictOctalLiteral: 'Octal literals are not allowed in strict mode.',
StrictParamDupe: 'Strict mode function may not have duplicate parameter names',
StrictParamName: 'Parameter name eval or arguments is not allowed in strict mode',
StrictReservedWord: 'Use of future reserved word in strict mode',
StrictVarName: 'Variable name may not be eval or arguments in strict mode',
TemplateOctalLiteral: 'Octal literals are not allowed in template strings.',
UnexpectedEOS: 'Unexpected end of input',
UnexpectedIdentifier: 'Unexpected identifier',
UnexpectedNumber: 'Unexpected number',
UnexpectedReserved: 'Unexpected reserved word',
UnexpectedString: 'Unexpected string',
UnexpectedTemplate: 'Unexpected quasi %0',
UnexpectedToken: 'Unexpected token %0',
UnexpectedTokenIllegal: 'Unexpected token ILLEGAL',
UnknownLabel: 'Undefined label \'%0\'',
UnterminatedRegExp: 'Invalid regular expression: missing /'
};
/***/
},
/* 12 */
/***/function (module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var assert_1 = __webpack_require__(9);
var character_1 = __webpack_require__(4);
var messages_1 = __webpack_require__(11);
function hexValue(ch) {
return '0123456789abcdef'.indexOf(ch.toLowerCase());
}
function octalValue(ch) {
return '01234567'.indexOf(ch);
}
var Scanner = function () {
function Scanner(code, handler) {
this.source = code;
this.errorHandler = handler;
this.trackComment = false;
this.length = code.length;
this.index = 0;
this.lineNumber = code.length > 0 ? 1 : 0;
this.lineStart = 0;
this.curlyStack = [];
}
Scanner.prototype.saveState = function () {
return {
index: this.index,
lineNumber: this.lineNumber,
lineStart: this.lineStart
};
};
Scanner.prototype.restoreState = function (state) {
this.index = state.index;
this.lineNumber = state.lineNumber;
this.lineStart = state.lineStart;
};
Scanner.prototype.eof = function () {
return this.index >= this.length;
};
Scanner.prototype.throwUnexpectedToken = function (message) {
if (message === void 0) {
message = messages_1.Messages.UnexpectedTokenIllegal;
}
return this.errorHandler.throwError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
};
Scanner.prototype.tolerateUnexpectedToken = function (message) {
if (message === void 0) {
message = messages_1.Messages.UnexpectedTokenIllegal;
}
this.errorHandler.tolerateError(this.index, this.lineNumber, this.index - this.lineStart + 1, message);
};
// https://tc39.github.io/ecma262/#sec-comments
Scanner.prototype.skipSingleLineComment = function (offset) {
var comments = [];
var start, loc;
if (this.trackComment) {
comments = [];
start = this.index - offset;
loc = {
start: {
line: this.lineNumber,
column: this.index - this.lineStart - offset
},
end: {}
};
}
while (!this.eof()) {
var ch = this.source.charCodeAt(this.index);
++this.index;
if (character_1.Character.isLineTerminator(ch)) {
if (this.trackComment) {
loc.end = {
line: this.lineNumber,
column: this.index - this.lineStart - 1
};
var entry = {
multiLine: false,
slice: [start + offset, this.index - 1],
range: [start, this.index - 1],
loc: loc
};
comments.push(entry);
}
if (ch === 13 && this.source.charCodeAt(this.index) === 10) {
++this.index;
}
++this.lineNumber;
this.lineStart = this.index;
return comments;
}
}
if (this.trackComment) {
loc.end = {
line: this.lineNumber,
column: this.index - this.lineStart
};
var entry = {
multiLine: false,
slice: [start + offset, this.index],
range: [start, this.index],
loc: loc
};
comments.push(entry);
}
return comments;
};
Scanner.prototype.skipMultiLineComment = function () {
var comments = [];
var start, loc;
if (this.trackComment) {
comments = [];
start = this.index - 2;
loc = {
start: {
line: this.lineNumber,
column: this.index - this.lineStart - 2
},
end: {}
};
}
while (!this.eof()) {
var ch = this.source.charCodeAt(this.index);
if (character_1.Character.isLineTerminator(ch)) {
if (ch === 0x0D && this.source.charCodeAt(this.index + 1) === 0x0A) {
++this.index;
}
++this.lineNumber;
++this.index;
this.lineStart = this.index;
} else if (ch === 0x2A) {
// Block comment ends with '*/'.
if (this.source.charCodeAt(this.index + 1) === 0x2F) {
this.index += 2;
if (this.trackComment) {
loc.end = {
line: this.lineNumber,
column: this.index - this.lineStart
};
var entry = {
multiLine: true,
slice: [start + 2, this.index - 2],
range: [start, this.index],
loc: loc
};
comments.push(entry);
}
return comments;
}
++this.index;
} else {
++this.index;
}
}
// Ran off the end of the file - the whole thing is a comment
if (this.trackComment) {
loc.end = {
line: this.lineNumber,
column: this.index - this.lineStart
};
var entry = {
multiLine: true,
slice: [start + 2, this.index],
range: [start, this.index],
loc: loc
};
comments.push(entry);
}
this.tolerateUnexpectedToken();
return comments;
};
Scanner.prototype.scanComments = function () {
var comments;
if (this.trackComment) {
comments = [];
}
var start = this.index === 0;
while (!this.eof()) {
var ch = this.source.charCodeAt(this.index);
if (character_1.Character.isWhiteSpace(ch)) {
++this.index;
} else if (character_1.Character.isLineTerminator(ch)) {
++this.index;
if (ch === 0x0D && this.source.charCodeAt(this.index) === 0x0A) {
++this.index;
}
++this.lineNumber;
this.lineStart = this.index;
start = true;
} else if (ch === 0x2F) {
ch = this.source.charCodeAt(this.index + 1);
if (ch === 0x2F) {
this.index += 2;
var comment = this.skipSingleLineComment(2);
if (this.trackComment) {
comments = comments.concat(comment);
}
start = true;
} else if (ch === 0x2A) {
this.index += 2;
var comment = this.skipMultiLineComment();
if (this.trackComment) {
comments = comments.concat(comment);
}
} else {
break;
}
} else if (start && ch === 0x2D) {
// U+003E is '>'
if (this.source.charCodeAt(this.index + 1) === 0x2D && this.source.charCodeAt(this.index + 2) === 0x3E) {
// '-->' is a single-line comment
this.index += 3;
var comment = this.skipSingleLineComment(3);
if (this.trackComment) {
comments = comments.concat(comment);
}
} else {
break;
}
} else if (ch === 0x3C) {
if (this.source.slice(this.index + 1, this.index + 4) === '!--') {
this.index += 4; // `<!--`
var comment = this.skipSingleLineComment(4);
if (this.trackComment) {
comments = comments.concat(comment);
}
} else {
break;
}
} else {
break;
}
}
return comments;
};
// https://tc39.github.io/ecma262/#sec-future-reserved-words
Scanner.prototype.isFutureReservedWord = function (id) {
switch (id) {
case 'enum':
case 'export':
case 'import':
case 'super':
return true;
default:
return false;
}
};
Scanner.prototype.isStrictModeReservedWord = function (id) {
switch (id) {
case 'implements':
case 'interface':
case 'package':
case 'private':
case 'protected':
case 'public':
case 'static':
case 'yield':
case 'let':
return true;
default:
return false;
}
};
Scanner.prototype.isRestrictedWord = function (id) {
return id === 'eval' || id === 'arguments';
};
// https://tc39.github.io/ecma262/#sec-keywords
Scanner.prototype.isKeyword = function (id) {
switch (id.length) {
case 2:
return id === 'if' || id === 'in' || id === 'do';
case 3:
return id === 'var' || id === 'for' || id === 'new' || id === 'try' || id === 'let';
case 4:
return id === 'this' || id === 'else' || id === 'case' || id === 'void' || id === 'with' || id === 'enum';
case 5:
return id === 'while' || id === 'break' || id === 'catch' || id === 'throw' || id === 'const' || id === 'yield' || id === 'class' || id === 'super';
case 6:
return id === 'return' || id === 'typeof' || id === 'delete' || id === 'switch' || id === 'export' || id === 'import';
case 7:
return id === 'default' || id === 'finally' || id === 'extends';
case 8:
return id === 'function' || id === 'continue' || id === 'debugger';
case 10:
return id === 'instanceof';
default:
return false;
}
};
Scanner.prototype.codePointAt = function (i) {
var cp = this.source.charCodeAt(i);
if (cp >= 0xD800 && cp <= 0xDBFF) {
var second = this.source.charCodeAt(i + 1);
if (second >= 0xDC00 && second <= 0xDFFF) {
var first = cp;
cp = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
}
}
return cp;
};
Scanner.prototype.scanHexEscape = function (prefix) {
var len = prefix === 'u' ? 4 : 2;
var code = 0;
for (var i = 0; i < len; ++i) {
if (!this.eof() && character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
code = code * 16 + hexValue(this.source[this.index++]);
} else {
return null;
}
}
return String.fromCharCode(code);
};
Scanner.prototype.scanUnicodeCodePointEscape = function () {
var ch = this.source[this.index];
var code = 0;
// At least, one hex digit is required.
if (ch === '}') {
this.throwUnexpectedToken();
}
while (!this.eof()) {
ch = this.source[this.index++];
if (!character_1.Character.isHexDigit(ch.charCodeAt(0))) {
break;
}
code = code * 16 + hexValue(ch);
}
if (code > 0x10FFFF || ch !== '}') {
this.throwUnexpectedToken();
}
return character_1.Character.fromCodePoint(code);
};
Scanner.prototype.getIdentifier = function () {
var start = this.index++;
while (!this.eof()) {
var ch = this.source.charCodeAt(this.index);
if (ch === 0x5C) {
// Blackslash (U+005C) marks Unicode escape sequence.
this.index = start;
return this.getComplexIdentifier();
} else if (ch >= 0xD800 && ch < 0xDFFF) {
// Need to handle surrogate pairs.
this.index = start;
return this.getComplexIdentifier();
}
if (character_1.Character.isIdentifierPart(ch)) {
++this.index;
} else {
break;
}
}
return this.source.slice(start, this.index);
};
Scanner.prototype.getComplexIdentifier = function () {
var cp = this.codePointAt(this.index);
var id = character_1.Character.fromCodePoint(cp);
this.index += id.length;
// '\u' (U+005C, U+0075) denotes an escaped character.
var ch;
if (cp === 0x5C) {
if (this.source.charCodeAt(this.index) !== 0x75) {
this.throwUnexpectedToken();
}
++this.index;
if (this.source[this.index] === '{') {
++this.index;
ch = this.scanUnicodeCodePointEscape();
} else {
ch = this.scanHexEscape('u');
if (ch === null || ch === '\\' || !character_1.Character.isIdentifierStart(ch.charCodeAt(0))) {
this.throwUnexpectedToken();
}
}
id = ch;
}
while (!this.eof()) {
cp = this.codePointAt(this.index);
if (!character_1.Character.isIdentifierPart(cp)) {
break;
}
ch = character_1.Character.fromCodePoint(cp);
id += ch;
this.index += ch.length;
// '\u' (U+005C, U+0075) denotes an escaped character.
if (cp === 0x5C) {
id = id.substr(0, id.length - 1);
if (this.source.charCodeAt(this.index) !== 0x75) {
this.throwUnexpectedToken();
}
++this.index;
if (this.source[this.index] === '{') {
++this.index;
ch = this.scanUnicodeCodePointEscape();
} else {
ch = this.scanHexEscape('u');
if (ch === null || ch === '\\' || !character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
this.throwUnexpectedToken();
}
}
id += ch;
}
}
return id;
};
Scanner.prototype.octalToDecimal = function (ch) {
// \0 is not octal escape sequence
var octal = ch !== '0';
var code = octalValue(ch);
if (!this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
octal = true;
code = code * 8 + octalValue(this.source[this.index++]);
// 3 digits are only allowed when string starts
// with 0, 1, 2, 3
if ('0123'.indexOf(ch) >= 0 && !this.eof() && character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
code = code * 8 + octalValue(this.source[this.index++]);
}
}
return {
code: code,
octal: octal
};
};
// https://tc39.github.io/ecma262/#sec-names-and-keywords
Scanner.prototype.scanIdentifier = function () {
var type;
var start = this.index;
// Backslash (U+005C) starts an escaped character.
var id = this.source.charCodeAt(start) === 0x5C ? this.getComplexIdentifier() : this.getIdentifier();
// There is no keyword or literal with only one character.
// Thus, it must be an identifier.
if (id.length === 1) {
type = 3 /* Identifier */;
} else if (this.isKeyword(id)) {
type = 4 /* Keyword */;
} else if (id === 'null') {
type = 5 /* NullLiteral */;
} else if (id === 'true' || id === 'false') {
type = 1 /* BooleanLiteral */;
} else {
type = 3 /* Identifier */;
}
if (type !== 3 /* Identifier */ && start + id.length !== this.index) {
var restore = this.index;
this.index = start;
this.tolerateUnexpectedToken(messages_1.Messages.InvalidEscapedReservedWord);
this.index = restore;
}
return {
type: type,
value: id,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
// https://tc39.github.io/ecma262/#sec-punctuators
Scanner.prototype.scanPunctuator = function () {
var start = this.index;
// Check for most common single-character punctuators.
var str = this.source[this.index];
switch (str) {
case '(':
case '{':
if (str === '{') {
this.curlyStack.push('{');
}
++this.index;
break;
case '.':
++this.index;
if (this.source[this.index] === '.' && this.source[this.index + 1] === '.') {
// Spread operator: ...
this.index += 2;
str = '...';
}
break;
case '}':
++this.index;
this.curlyStack.pop();
break;
case ')':
case ';':
case ',':
case '[':
case ']':
case ':':
case '?':
case '~':
++this.index;
break;
default:
// 4-character punctuator.
str = this.source.substr(this.index, 4);
if (str === '>>>=') {
this.index += 4;
} else {
// 3-character punctuators.
str = str.substr(0, 3);
if (str === '===' || str === '!==' || str === '>>>' || str === '<<=' || str === '>>=' || str === '**=') {
this.index += 3;
} else {
// 2-character punctuators.
str = str.substr(0, 2);
if (str === '&&' || str === '||' || str === '==' || str === '!=' || str === '+=' || str === '-=' || str === '*=' || str === '/=' || str === '++' || str === '--' || str === '<<' || str === '>>' || str === '&=' || str === '|=' || str === '^=' || str === '%=' || str === '<=' || str === '>=' || str === '=>' || str === '**') {
this.index += 2;
} else {
// 1-character punctuators.
str = this.source[this.index];
if ('<>=!+-*%&|^/'.indexOf(str) >= 0) {
++this.index;
}
}
}
}
}
if (this.index === start) {
this.throwUnexpectedToken();
}
return {
type: 7 /* Punctuator */
, value: str,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
// https://tc39.github.io/ecma262/#sec-literals-numeric-literals
Scanner.prototype.scanHexLiteral = function (start) {
var num = '';
while (!this.eof()) {
if (!character_1.Character.isHexDigit(this.source.charCodeAt(this.index))) {
break;
}
num += this.source[this.index++];
}
if (num.length === 0) {
this.throwUnexpectedToken();
}
if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
this.throwUnexpectedToken();
}
return {
type: 6 /* NumericLiteral */
, value: parseInt('0x' + num, 16),
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
Scanner.prototype.scanBinaryLiteral = function (start) {
var num = '';
var ch;
while (!this.eof()) {
ch = this.source[this.index];
if (ch !== '0' && ch !== '1') {
break;
}
num += this.source[this.index++];
}
if (num.length === 0) {
// only 0b or 0B
this.throwUnexpectedToken();
}
if (!this.eof()) {
ch = this.source.charCodeAt(this.index);
/* istanbul ignore else */
if (character_1.Character.isIdentifierStart(ch) || character_1.Character.isDecimalDigit(ch)) {
this.throwUnexpectedToken();
}
}
return {
type: 6 /* NumericLiteral */
, value: parseInt(num, 2),
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
Scanner.prototype.scanOctalLiteral = function (prefix, start) {
var num = '';
var octal = false;
if (character_1.Character.isOctalDigit(prefix.charCodeAt(0))) {
octal = true;
num = '0' + this.source[this.index++];
} else {
++this.index;
}
while (!this.eof()) {
if (!character_1.Character.isOctalDigit(this.source.charCodeAt(this.index))) {
break;
}
num += this.source[this.index++];
}
if (!octal && num.length === 0) {
// only 0o or 0O
this.throwUnexpectedToken();
}
if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index)) || character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
this.throwUnexpectedToken();
}
return {
type: 6 /* NumericLiteral */
, value: parseInt(num, 8),
octal: octal,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
Scanner.prototype.isImplicitOctalLiteral = function () {
// Implicit octal, unless there is a non-octal digit.
// (Annex B.1.1 on Numeric Literals)
for (var i = this.index + 1; i < this.length; ++i) {
var ch = this.source[i];
if (ch === '8' || ch === '9') {
return false;
}
if (!character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
return true;
}
}
return true;
};
Scanner.prototype.scanNumericLiteral = function () {
var start = this.index;
var ch = this.source[start];
assert_1.assert(character_1.Character.isDecimalDigit(ch.charCodeAt(0)) || ch === '.', 'Numeric literal must start with a decimal digit or a decimal point');
var num = '';
if (ch !== '.') {
num = this.source[this.index++];
ch = this.source[this.index];
// Hex number starts with '0x'.
// Octal number starts with '0'.
// Octal number in ES6 starts with '0o'.
// Binary number in ES6 starts with '0b'.
if (num === '0') {
if (ch === 'x' || ch === 'X') {
++this.index;
return this.scanHexLiteral(start);
}
if (ch === 'b' || ch === 'B') {
++this.index;
return this.scanBinaryLiteral(start);
}
if (ch === 'o' || ch === 'O') {
return this.scanOctalLiteral(ch, start);
}
if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
if (this.isImplicitOctalLiteral()) {
return this.scanOctalLiteral(ch, start);
}
}
}
while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
num += this.source[this.index++];
}
ch = this.source[this.index];
}
if (ch === '.') {
num += this.source[this.index++];
while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
num += this.source[this.index++];
}
ch = this.source[this.index];
}
if (ch === 'e' || ch === 'E') {
num += this.source[this.index++];
ch = this.source[this.index];
if (ch === '+' || ch === '-') {
num += this.source[this.index++];
}
if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
while (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
num += this.source[this.index++];
}
} else {
this.throwUnexpectedToken();
}
}
if (character_1.Character.isIdentifierStart(this.source.charCodeAt(this.index))) {
this.throwUnexpectedToken();
}
return {
type: 6 /* NumericLiteral */
, value: parseFloat(num),
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
// https://tc39.github.io/ecma262/#sec-literals-string-literals
Scanner.prototype.scanStringLiteral = function () {
var start = this.index;
var quote = this.source[start];
assert_1.assert(quote === '\'' || quote === '"', 'String literal must starts with a quote');
++this.index;
var octal = false;
var str = '';
while (!this.eof()) {
var ch = this.source[this.index++];
if (ch === quote) {
quote = '';
break;
} else if (ch === '\\') {
ch = this.source[this.index++];
if (!ch || !character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
switch (ch) {
case 'u':
if (this.source[this.index] === '{') {
++this.index;
str += this.scanUnicodeCodePointEscape();
} else {
var unescaped_1 = this.scanHexEscape(ch);
if (unescaped_1 === null) {
this.throwUnexpectedToken();
}
str += unescaped_1;
}
break;
case 'x':
var unescaped = this.scanHexEscape(ch);
if (unescaped === null) {
this.throwUnexpectedToken(messages_1.Messages.InvalidHexEscapeSequence);
}
str += unescaped;
break;
case 'n':
str += '\n';
break;
case 'r':
str += '\r';
break;
case 't':
str += '\t';
break;
case 'b':
str += '\b';
break;
case 'f':
str += '\f';
break;
case 'v':
str += '\x0B';
break;
case '8':
case '9':
str += ch;
this.tolerateUnexpectedToken();
break;
default:
if (ch && character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
var octToDec = this.octalToDecimal(ch);
octal = octToDec.octal || octal;
str += String.fromCharCode(octToDec.code);
} else {
str += ch;
}
break;
}
} else {
++this.lineNumber;
if (ch === '\r' && this.source[this.index] === '\n') {
++this.index;
}
this.lineStart = this.index;
}
} else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
break;
} else {
str += ch;
}
}
if (quote !== '') {
this.index = start;
this.throwUnexpectedToken();
}
return {
type: 8 /* StringLiteral */
, value: str,
octal: octal,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
// https://tc39.github.io/ecma262/#sec-template-literal-lexical-components
Scanner.prototype.scanTemplate = function () {
var cooked = '';
var terminated = false;
var start = this.index;
var head = this.source[start] === '`';
var tail = false;
var rawOffset = 2;
++this.index;
while (!this.eof()) {
var ch = this.source[this.index++];
if (ch === '`') {
rawOffset = 1;
tail = true;
terminated = true;
break;
} else if (ch === '$') {
if (this.source[this.index] === '{') {
this.curlyStack.push('${');
++this.index;
terminated = true;
break;
}
cooked += ch;
} else if (ch === '\\') {
ch = this.source[this.index++];
if (!character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
switch (ch) {
case 'n':
cooked += '\n';
break;
case 'r':
cooked += '\r';
break;
case 't':
cooked += '\t';
break;
case 'u':
if (this.source[this.index] === '{') {
++this.index;
cooked += this.scanUnicodeCodePointEscape();
} else {
var restore = this.index;
var unescaped_2 = this.scanHexEscape(ch);
if (unescaped_2 !== null) {
cooked += unescaped_2;
} else {
this.index = restore;
cooked += ch;
}
}
break;
case 'x':
var unescaped = this.scanHexEscape(ch);
if (unescaped === null) {
this.throwUnexpectedToken(messages_1.Messages.InvalidHexEscapeSequence);
}
cooked += unescaped;
break;
case 'b':
cooked += '\b';
break;
case 'f':
cooked += '\f';
break;
case 'v':
cooked += '\v';
break;
default:
if (ch === '0') {
if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index))) {
// Illegal: \01 \02 and so on
this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
}
cooked += '\0';
} else if (character_1.Character.isOctalDigit(ch.charCodeAt(0))) {
// Illegal: \1 \2
this.throwUnexpectedToken(messages_1.Messages.TemplateOctalLiteral);
} else {
cooked += ch;
}
break;
}
} else {
++this.lineNumber;
if (ch === '\r' && this.source[this.index] === '\n') {
++this.index;
}
this.lineStart = this.index;
}
} else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
++this.lineNumber;
if (ch === '\r' && this.source[this.index] === '\n') {
++this.index;
}
this.lineStart = this.index;
cooked += '\n';
} else {
cooked += ch;
}
}
if (!terminated) {
this.throwUnexpectedToken();
}
if (!head) {
this.curlyStack.pop();
}
return {
type: 10 /* Template */
, value: this.source.slice(start + 1, this.index - rawOffset),
cooked: cooked,
head: head,
tail: tail,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
// https://tc39.github.io/ecma262/#sec-literals-regular-expression-literals
Scanner.prototype.testRegExp = function (pattern, flags) {
// The BMP character to use as a replacement for astral symbols when
// translating an ES6 "u"-flagged pattern to an ES5-compatible
// approximation.
// Note: replacing with '\uFFFF' enables false positives in unlikely
// scenarios. For example, `[\u{1044f}-\u{10440}]` is an invalid
// pattern that would not be detected by this substitution.
var astralSubstitute = '\uFFFF';
var tmp = pattern;
var self = this;
if (flags.indexOf('u') >= 0) {
tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}|\\u([a-fA-F0-9]{4})/g, function ($0, $1, $2) {
var codePoint = parseInt($1 || $2, 16);
if (codePoint > 0x10FFFF) {
self.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
}
if (codePoint <= 0xFFFF) {
return String.fromCharCode(codePoint);
}
return astralSubstitute;
}).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, astralSubstitute);
}
// First, detect invalid regular expressions.
try {
RegExp(tmp);
} catch (e) {
this.throwUnexpectedToken(messages_1.Messages.InvalidRegExp);
}
// Return a regular expression object for this pattern-flag pair, or
// `null` in case the current environment doesn't support the flags it
// uses.
try {
return new RegExp(pattern, flags);
} catch (exception) {
/* istanbul ignore next */
return null;
}
};
Scanner.prototype.scanRegExpBody = function () {
var ch = this.source[this.index];
assert_1.assert(ch === '/', 'Regular expression literal must start with a slash');
var str = this.source[this.index++];
var classMarker = false;
var terminated = false;
while (!this.eof()) {
ch = this.source[this.index++];
str += ch;
if (ch === '\\') {
ch = this.source[this.index++];
// https://tc39.github.io/ecma262/#sec-literals-regular-expression-literals
if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
}
str += ch;
} else if (character_1.Character.isLineTerminator(ch.charCodeAt(0))) {
this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
} else if (classMarker) {
if (ch === ']') {
classMarker = false;
}
} else {
if (ch === '/') {
terminated = true;
break;
} else if (ch === '[') {
classMarker = true;
}
}
}
if (!terminated) {
this.throwUnexpectedToken(messages_1.Messages.UnterminatedRegExp);
}
// Exclude leading and trailing slash.
return str.substr(1, str.length - 2);
};
Scanner.prototype.scanRegExpFlags = function () {
var str = '';
var flags = '';
while (!this.eof()) {
var ch = this.source[this.index];
if (!character_1.Character.isIdentifierPart(ch.charCodeAt(0))) {
break;
}
++this.index;
if (ch === '\\' && !this.eof()) {
ch = this.source[this.index];
if (ch === 'u') {
++this.index;
var restore = this.index;
var char = this.scanHexEscape('u');
if (char !== null) {
flags += char;
for (str += '\\u'; restore < this.index; ++restore) {
str += this.source[restore];
}
} else {
this.index = restore;
flags += 'u';
str += '\\u';
}
this.tolerateUnexpectedToken();
} else {
str += '\\';
this.tolerateUnexpectedToken();
}
} else {
flags += ch;
str += ch;
}
}
return flags;
};
Scanner.prototype.scanRegExp = function () {
var start = this.index;
var pattern = this.scanRegExpBody();
var flags = this.scanRegExpFlags();
var value = this.testRegExp(pattern, flags);
return {
type: 9 /* RegularExpression */
, value: '',
pattern: pattern,
flags: flags,
regex: value,
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: start,
end: this.index
};
};
Scanner.prototype.lex = function () {
if (this.eof()) {
return {
type: 2 /* EOF */
, value: '',
lineNumber: this.lineNumber,
lineStart: this.lineStart,
start: this.index,
end: this.index
};
}
var cp = this.source.charCodeAt(this.index);
if (character_1.Character.isIdentifierStart(cp)) {
return this.scanIdentifier();
}
// Very common: ( and ) and ;
if (cp === 0x28 || cp === 0x29 || cp === 0x3B) {
return this.scanPunctuator();
}
// String literal starts with single quote (U+0027) or double quote (U+0022).
if (cp === 0x27 || cp === 0x22) {
return this.scanStringLiteral();
}
// Dot (.) U+002E can also start a floating-point number, hence the need
// to check the next character.
if (cp === 0x2E) {
if (character_1.Character.isDecimalDigit(this.source.charCodeAt(this.index + 1))) {
return this.scanNumericLiteral();
}
return this.scanPunctuator();
}
if (character_1.Character.isDecimalDigit(cp)) {
return this.scanNumericLiteral();
}
// Template literals start with ` (U+0060) for template head
// or } (U+007D) for template middle or template tail.
if (cp === 0x60 || cp === 0x7D && this.curlyStack[this.curlyStack.length - 1] === '${') {
return this.scanTemplate();
}
// Possible identifier start in a surrogate pair.
if (cp >= 0xD800 && cp < 0xDFFF) {
if (character_1.Character.isIdentifierStart(this.codePointAt(this.index))) {
return this.scanIdentifier();
}
}
return this.scanPunctuator();
};
return Scanner;
}();
exports.Scanner = Scanner;
/***/
},
/* 13 */
/***/function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenName = {};
exports.TokenName[1 /* BooleanLiteral */] = 'Boolean';
exports.TokenName[2 /* EOF */] = '<end>';
exports.TokenName[3 /* Identifier */] = 'Identifier';
exports.TokenName[4 /* Keyword */] = 'Keyword';
exports.TokenName[5 /* NullLiteral */] = 'Null';
exports.TokenName[6 /* NumericLiteral */] = 'Numeric';
exports.TokenName[7 /* Punctuator */] = 'Punctuator';
exports.TokenName[8 /* StringLiteral */] = 'String';
exports.TokenName[9 /* RegularExpression */] = 'RegularExpression';
exports.TokenName[10 /* Template */] = 'Template';
/***/
},
/* 14 */
/***/function (module, exports) {
"use strict";
// Generated by generate-xhtml-entities.js. DO NOT MODIFY!
Object.defineProperty(exports, "__esModule", { value: true });
exports.XHTMLEntities = {
quot: '\u0022',
amp: '\u0026',
apos: '\u0027',
gt: '\u003E',
nbsp: '\u00A0',
iexcl: '\u00A1',
cent: '\u00A2',
pound: '\u00A3',
curren: '\u00A4',
yen: '\u00A5',
brvbar: '\u00A6',
sect: '\u00A7',
uml: '\u00A8',
copy: '\u00A9',
ordf: '\u00AA',
laquo: '\u00AB',
not: '\u00AC',
shy: '\u00AD',
reg: '\u00AE',
macr: '\u00AF',
deg: '\u00B0',
plusmn: '\u00B1',
sup2: '\u00B2',
sup3: '\u00B3',
acute: '\u00B4',
micro: '\u00B5',
para: '\u00B6',
middot: '\u00B7',
cedil: '\u00B8',
sup1: '\u00B9',
ordm: '\u00BA',
raquo: '\u00BB',
frac14: '\u00BC',
frac12: '\u00BD',
frac34: '\u00BE',
iquest: '\u00BF',
Agrave: '\u00C0',
Aacute: '\u00C1',
Acirc: '\u00C2',
Atilde: '\u00C3',
Auml: '\u00C4',
Aring: '\u00C5',
AElig: '\u00C6',
Ccedil: '\u00C7',
Egrave: '\u00C8',
Eacute: '\u00C9',
Ecirc: '\u00CA',
Euml: '\u00CB',
Igrave: '\u00CC',
Iacute: '\u00CD',
Icirc: '\u00CE',
Iuml: '\u00CF',
ETH: '\u00D0',
Ntilde: '\u00D1',
Ograve: '\u00D2',
Oacute: '\u00D3',
Ocirc: '\u00D4',
Otilde: '\u00D5',
Ouml: '\u00D6',
times: '\u00D7',
Oslash: '\u00D8',
Ugrave: '\u00D9',
Uacute: '\u00DA',
Ucirc: '\u00DB',
Uuml: '\u00DC',
Yacute: '\u00DD',
THORN: '\u00DE',
szlig: '\u00DF',
agrave: '\u00E0',
aacute: '\u00E1',
acirc: '\u00E2',
atilde: '\u00E3',
auml: '\u00E4',
aring: '\u00E5',
aelig: '\u00E6',
ccedil: '\u00E7',
egrave: '\u00E8',
eacute: '\u00E9',
ecirc: '\u00EA',
euml: '\u00EB',
igrave: '\u00EC',
iacute: '\u00ED',
icirc: '\u00EE',
iuml: '\u00EF',
eth: '\u00F0',
ntilde: '\u00F1',
ograve: '\u00F2',
oacute: '\u00F3',
ocirc: '\u00F4',
otilde: '\u00F5',
ouml: '\u00F6',
divide: '\u00F7',
oslash: '\u00F8',
ugrave: '\u00F9',
uacute: '\u00FA',
ucirc: '\u00FB',
uuml: '\u00FC',
yacute: '\u00FD',
thorn: '\u00FE',
yuml: '\u00FF',
OElig: '\u0152',
oelig: '\u0153',
Scaron: '\u0160',
scaron: '\u0161',
Yuml: '\u0178',
fnof: '\u0192',
circ: '\u02C6',
tilde: '\u02DC',
Alpha: '\u0391',
Beta: '\u0392',
Gamma: '\u0393',
Delta: '\u0394',
Epsilon: '\u0395',
Zeta: '\u0396',
Eta: '\u0397',
Theta: '\u0398',
Iota: '\u0399',
Kappa: '\u039A',
Lambda: '\u039B',
Mu: '\u039C',
Nu: '\u039D',
Xi: '\u039E',
Omicron: '\u039F',
Pi: '\u03A0',
Rho: '\u03A1',
Sigma: '\u03A3',
Tau: '\u03A4',
Upsilon: '\u03A5',
Phi: '\u03A6',
Chi: '\u03A7',
Psi: '\u03A8',
Omega: '\u03A9',
alpha: '\u03B1',
beta: '\u03B2',
gamma: '\u03B3',
delta: '\u03B4',
epsilon: '\u03B5',
zeta: '\u03B6',
eta: '\u03B7',
theta: '\u03B8',
iota: '\u03B9',
kappa: '\u03BA',
lambda: '\u03BB',
mu: '\u03BC',
nu: '\u03BD',
xi: '\u03BE',
omicron: '\u03BF',
pi: '\u03C0',
rho: '\u03C1',
sigmaf: '\u03C2',
sigma: '\u03C3',
tau: '\u03C4',
upsilon: '\u03C5',
phi: '\u03C6',
chi: '\u03C7',
psi: '\u03C8',
omega: '\u03C9',
thetasym: '\u03D1',
upsih: '\u03D2',
piv: '\u03D6',
ensp: '\u2002',
emsp: '\u2003',
thinsp: '\u2009',
zwnj: '\u200C',
zwj: '\u200D',
lrm: '\u200E',
rlm: '\u200F',
ndash: '\u2013',
mdash: '\u2014',
lsquo: '\u2018',
rsquo: '\u2019',
sbquo: '\u201A',
ldquo: '\u201C',
rdquo: '\u201D',
bdquo: '\u201E',
dagger: '\u2020',
Dagger: '\u2021',
bull: '\u2022',
hellip: '\u2026',
permil: '\u2030',
prime: '\u2032',
Prime: '\u2033',
lsaquo: '\u2039',
rsaquo: '\u203A',
oline: '\u203E',
frasl: '\u2044',
euro: '\u20AC',
image: '\u2111',
weierp: '\u2118',
real: '\u211C',
trade: '\u2122',
alefsym: '\u2135',
larr: '\u2190',
uarr: '\u2191',
rarr: '\u2192',
darr: '\u2193',
harr: '\u2194',
crarr: '\u21B5',
lArr: '\u21D0',
uArr: '\u21D1',
rArr: '\u21D2',
dArr: '\u21D3',
hArr: '\u21D4',
forall: '\u2200',
part: '\u2202',
exist: '\u2203',
empty: '\u2205',
nabla: '\u2207',
isin: '\u2208',
notin: '\u2209',
ni: '\u220B',
prod: '\u220F',
sum: '\u2211',
minus: '\u2212',
lowast: '\u2217',
radic: '\u221A',
prop: '\u221D',
infin: '\u221E',
ang: '\u2220',
and: '\u2227',
or: '\u2228',
cap: '\u2229',
cup: '\u222A',
int: '\u222B',
there4: '\u2234',
sim: '\u223C',
cong: '\u2245',
asymp: '\u2248',
ne: '\u2260',
equiv: '\u2261',
le: '\u2264',
ge: '\u2265',
sub: '\u2282',
sup: '\u2283',
nsub: '\u2284',
sube: '\u2286',
supe: '\u2287',
oplus: '\u2295',
otimes: '\u2297',
perp: '\u22A5',
sdot: '\u22C5',
lceil: '\u2308',
rceil: '\u2309',
lfloor: '\u230A',
rfloor: '\u230B',
loz: '\u25CA',
spades: '\u2660',
clubs: '\u2663',
hearts: '\u2665',
diams: '\u2666',
lang: '\u27E8',
rang: '\u27E9'
};
/***/
},
/* 15 */
/***/function (module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var error_handler_1 = __webpack_require__(10);
var scanner_1 = __webpack_require__(12);
var token_1 = __webpack_require__(13);
var Reader = function () {
function Reader() {
this.values = [];
this.curly = this.paren = -1;
}
// A function following one of those tokens is an expression.
Reader.prototype.beforeFunctionExpression = function (t) {
return ['(', '{', '[', 'in', 'typeof', 'instanceof', 'new', 'return', 'case', 'delete', 'throw', 'void',
// assignment operators
'=', '+=', '-=', '*=', '**=', '/=', '%=', '<<=', '>>=', '>>>=', '&=', '|=', '^=', ',',
// binary/unary operators
'+', '-', '*', '**', '/', '%', '++', '--', '<<', '>>', '>>>', '&', '|', '^', '!', '~', '&&', '||', '?', ':', '===', '==', '>=', '<=', '<', '>', '!=', '!=='].indexOf(t) >= 0;
};
// Determine if forward slash (/) is an operator or part of a regular expression
// https://github.com/mozilla/sweet.js/wiki/design
Reader.prototype.isRegexStart = function () {
var previous = this.values[this.values.length - 1];
var regex = previous !== null;
switch (previous) {
case 'this':
case ']':
regex = false;
break;
case ')':
var keyword = this.values[this.paren - 1];
regex = keyword === 'if' || keyword === 'while' || keyword === 'for' || keyword === 'with';
break;
case '}':
// Dividing a function by anything makes little sense,
// but we have to check for that.
regex = false;
if (this.values[this.curly - 3] === 'function') {
// Anonymous function, e.g. function(){} /42
var check = this.values[this.curly - 4];
regex = check ? !this.beforeFunctionExpression(check) : false;
} else if (this.values[this.curly - 4] === 'function') {
// Named function, e.g. function f(){} /42/
var check = this.values[this.curly - 5];
regex = check ? !this.beforeFunctionExpression(check) : true;
}
break;
default:
break;
}
return regex;
};
Reader.prototype.push = function (token) {
if (token.type === 7 /* Punctuator */ || token.type === 4 /* Keyword */) {
if (token.value === '{') {
this.curly = this.values.length;
} else if (token.value === '(') {
this.paren = this.values.length;
}
this.values.push(token.value);
} else {
this.values.push(null);
}
};
return Reader;
}();
var Tokenizer = function () {
function Tokenizer(code, config) {
this.errorHandler = new error_handler_1.ErrorHandler();
this.errorHandler.tolerant = config ? typeof config.tolerant === 'boolean' && config.tolerant : false;
this.scanner = new scanner_1.Scanner(code, this.errorHandler);
this.scanner.trackComment = config ? typeof config.comment === 'boolean' && config.comment : false;
this.trackRange = config ? typeof config.range === 'boolean' && config.range : false;
this.trackLoc = config ? typeof config.loc === 'boolean' && config.loc : false;
this.buffer = [];
this.reader = new Reader();
}
Tokenizer.prototype.errors = function () {
return this.errorHandler.errors;
};
Tokenizer.prototype.getNextToken = function () {
if (this.buffer.length === 0) {
var comments = this.scanner.scanComments();
if (this.scanner.trackComment) {
for (var i = 0; i < comments.length; ++i) {
var e = comments[i];
var value = this.scanner.source.slice(e.slice[0], e.slice[1]);
var comment = {
type: e.multiLine ? 'BlockComment' : 'LineComment',
value: value
};
if (this.trackRange) {
comment.range = e.range;
}
if (this.trackLoc) {
comment.loc = e.loc;
}
this.buffer.push(comment);
}
}
if (!this.scanner.eof()) {
var loc = void 0;
if (this.trackLoc) {
loc = {
start: {
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
},
end: {}
};
}
var startRegex = this.scanner.source[this.scanner.index] === '/' && this.reader.isRegexStart();
var token = startRegex ? this.scanner.scanRegExp() : this.scanner.lex();
this.reader.push(token);
var entry = {
type: token_1.TokenName[token.type],
value: this.scanner.source.slice(token.start, token.end)
};
if (this.trackRange) {
entry.range = [token.start, token.end];
}
if (this.trackLoc) {
loc.end = {
line: this.scanner.lineNumber,
column: this.scanner.index - this.scanner.lineStart
};
entry.loc = loc;
}
if (token.type === 9 /* RegularExpression */) {
var pattern = token.pattern;
var flags = token.flags;
entry.regex = { pattern: pattern, flags: flags };
}
this.buffer.push(entry);
}
}
return this.buffer.shift();
};
return Tokenizer;
}();
exports.Tokenizer = Tokenizer;
/***/
}
/******/])
);
});
;
/***/ }),
/***/ "4e7A":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Open simple dialogs on top of an editor. Relies on dialog.css.
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
function dialogDiv(cm, template, bottom) {
var wrap = cm.getWrapperElement();
var dialog;
dialog = wrap.appendChild(document.createElement("div"));
if (bottom) dialog.className = "CodeMirror-dialog CodeMirror-dialog-bottom";else dialog.className = "CodeMirror-dialog CodeMirror-dialog-top";
if (typeof template == "string") {
dialog.innerHTML = template;
} else {
// Assuming it's a detached DOM element.
dialog.appendChild(template);
}
CodeMirror.addClass(wrap, 'dialog-opened');
return dialog;
}
function closeNotification(cm, newVal) {
if (cm.state.currentNotificationClose) cm.state.currentNotificationClose();
cm.state.currentNotificationClose = newVal;
}
CodeMirror.defineExtension("openDialog", function (template, callback, options) {
if (!options) options = {};
closeNotification(this, null);
var dialog = dialogDiv(this, template, options.bottom);
var closed = false,
me = this;
function close(newVal) {
if (typeof newVal == 'string') {
inp.value = newVal;
} else {
if (closed) return;
closed = true;
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog);
me.focus();
if (options.onClose) options.onClose(dialog);
}
}
var inp = dialog.getElementsByTagName("input")[0],
button;
if (inp) {
inp.focus();
if (options.value) {
inp.value = options.value;
if (options.selectValueOnOpen !== false) {
inp.select();
}
}
if (options.onInput) CodeMirror.on(inp, "input", function (e) {
options.onInput(e, inp.value, close);
});
if (options.onKeyUp) CodeMirror.on(inp, "keyup", function (e) {
options.onKeyUp(e, inp.value, close);
});
CodeMirror.on(inp, "keydown", function (e) {
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) {
return;
}
if (e.keyCode == 27 || options.closeOnEnter !== false && e.keyCode == 13) {
inp.blur();
CodeMirror.e_stop(e);
close();
}
if (e.keyCode == 13) callback(inp.value, e);
});
if (options.closeOnBlur !== false) CodeMirror.on(inp, "blur", close);
} else if (button = dialog.getElementsByTagName("button")[0]) {
CodeMirror.on(button, "click", function () {
close();
me.focus();
});
if (options.closeOnBlur !== false) CodeMirror.on(button, "blur", close);
button.focus();
}
return close;
});
CodeMirror.defineExtension("openConfirm", function (template, callbacks, options) {
closeNotification(this, null);
var dialog = dialogDiv(this, template, options && options.bottom);
var buttons = dialog.getElementsByTagName("button");
var closed = false,
me = this,
blurring = 1;
function close() {
if (closed) return;
closed = true;
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog);
me.focus();
}
buttons[0].focus();
for (var i = 0; i < buttons.length; ++i) {
var b = buttons[i];
(function (callback) {
CodeMirror.on(b, "click", function (e) {
CodeMirror.e_preventDefault(e);
close();
if (callback) callback(me);
});
})(callbacks[i]);
CodeMirror.on(b, "blur", function () {
--blurring;
setTimeout(function () {
if (blurring <= 0) close();
}, 200);
});
CodeMirror.on(b, "focus", function () {
++blurring;
});
}
});
/*
* openNotification
* Opens a notification, that can be closed with an optional timer
* (default 5000ms timer) and always closes on click.
*
* If a notification is opened while another is opened, it will close the
* currently opened one and open the new one immediately.
*/
CodeMirror.defineExtension("openNotification", function (template, options) {
closeNotification(this, close);
var dialog = dialogDiv(this, template, options && options.bottom);
var closed = false,
doneTimer;
var duration = options && typeof options.duration !== "undefined" ? options.duration : 5000;
function close() {
if (closed) return;
closed = true;
clearTimeout(doneTimer);
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog);
}
CodeMirror.on(dialog, 'click', function (e) {
CodeMirror.e_preventDefault(e);
close();
});
if (duration) doneTimer = setTimeout(close, duration);
return close;
});
});
/***/ }),
/***/ "58xA":
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, '__esModule', { value: true });
var tslib_1 = __webpack_require__("vCxL");
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Firebase constants. Some of these (@defines) can be overridden at compile-time.
*/
var CONSTANTS = {
/**
* @define {boolean} Whether this is the client Node.js SDK.
*/
NODE_CLIENT: false,
/**
* @define {boolean} Whether this is the Admin Node.js SDK.
*/
NODE_ADMIN: false,
/**
* Firebase SDK Version
*/
SDK_VERSION: '${JSCORE_VERSION}'
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Throws an error if the provided assertion is falsy
* @param {*} assertion The assertion to be tested for falsiness
* @param {!string} message The message to display if the check fails
*/
var assert = function (assertion, message) {
if (!assertion) {
throw assertionError(message);
}
};
/**
* Returns an Error object suitable for throwing.
* @param {string} message
* @return {!Error}
*/
var assertionError = function (message) {
return new Error('Firebase Database (' + CONSTANTS.SDK_VERSION + ') INTERNAL ASSERT FAILED: ' + message);
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var stringToByteArray = function (str) {
// TODO(user): Use native implementations if/when available
var out = [],
p = 0;
for (var i = 0; i < str.length; i++) {
var c = str.charCodeAt(i);
if (c < 128) {
out[p++] = c;
} else if (c < 2048) {
out[p++] = c >> 6 | 192;
out[p++] = c & 63 | 128;
} else if ((c & 0xfc00) == 0xd800 && i + 1 < str.length && (str.charCodeAt(i + 1) & 0xfc00) == 0xdc00) {
// Surrogate Pair
c = 0x10000 + ((c & 0x03ff) << 10) + (str.charCodeAt(++i) & 0x03ff);
out[p++] = c >> 18 | 240;
out[p++] = c >> 12 & 63 | 128;
out[p++] = c >> 6 & 63 | 128;
out[p++] = c & 63 | 128;
} else {
out[p++] = c >> 12 | 224;
out[p++] = c >> 6 & 63 | 128;
out[p++] = c & 63 | 128;
}
}
return out;
};
/**
* Turns an array of numbers into the string given by the concatenation of the
* characters to which the numbers correspond.
* @param {Array<number>} bytes Array of numbers representing characters.
* @return {string} Stringification of the array.
*/
var byteArrayToString = function (bytes) {
// TODO(user): Use native implementations if/when available
var out = [],
pos = 0,
c = 0;
while (pos < bytes.length) {
var c1 = bytes[pos++];
if (c1 < 128) {
out[c++] = String.fromCharCode(c1);
} else if (c1 > 191 && c1 < 224) {
var c2 = bytes[pos++];
out[c++] = String.fromCharCode((c1 & 31) << 6 | c2 & 63);
} else if (c1 > 239 && c1 < 365) {
// Surrogate Pair
var c2 = bytes[pos++];
var c3 = bytes[pos++];
var c4 = bytes[pos++];
var u = ((c1 & 7) << 18 | (c2 & 63) << 12 | (c3 & 63) << 6 | c4 & 63) - 0x10000;
out[c++] = String.fromCharCode(0xd800 + (u >> 10));
out[c++] = String.fromCharCode(0xdc00 + (u & 1023));
} else {
var c2 = bytes[pos++];
var c3 = bytes[pos++];
out[c++] = String.fromCharCode((c1 & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
}
}
return out.join('');
};
// Static lookup maps, lazily populated by init_()
var base64 = {
/**
* Maps bytes to characters.
* @type {Object}
* @private
*/
byteToCharMap_: null,
/**
* Maps characters to bytes.
* @type {Object}
* @private
*/
charToByteMap_: null,
/**
* Maps bytes to websafe characters.
* @type {Object}
* @private
*/
byteToCharMapWebSafe_: null,
/**
* Maps websafe characters to bytes.
* @type {Object}
* @private
*/
charToByteMapWebSafe_: null,
/**
* Our default alphabet, shared between
* ENCODED_VALS and ENCODED_VALS_WEBSAFE
* @type {string}
*/
ENCODED_VALS_BASE: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789',
/**
* Our default alphabet. Value 64 (=) is special; it means "nothing."
* @type {string}
*/
get ENCODED_VALS() {
return this.ENCODED_VALS_BASE + '+/=';
},
/**
* Our websafe alphabet.
* @type {string}
*/
get ENCODED_VALS_WEBSAFE() {
return this.ENCODED_VALS_BASE + '-_.';
},
/**
* Whether this browser supports the atob and btoa functions. This extension
* started at Mozilla but is now implemented by many browsers. We use the
* ASSUME_* variables to avoid pulling in the full useragent detection library
* but still allowing the standard per-browser compilations.
*
* @type {boolean}
*/
HAS_NATIVE_SUPPORT: typeof atob === 'function',
/**
* Base64-encode an array of bytes.
*
* @param {Array<number>|Uint8Array} input An array of bytes (numbers with
* value in [0, 255]) to encode.
* @param {boolean=} opt_webSafe Boolean indicating we should use the
* alternative alphabet.
* @return {string} The base64 encoded string.
*/
encodeByteArray: function (input, opt_webSafe) {
if (!Array.isArray(input)) {
throw Error('encodeByteArray takes an array as a parameter');
}
this.init_();
var byteToCharMap = opt_webSafe ? this.byteToCharMapWebSafe_ : this.byteToCharMap_;
var output = [];
for (var i = 0; i < input.length; i += 3) {
var byte1 = input[i];
var haveByte2 = i + 1 < input.length;
var byte2 = haveByte2 ? input[i + 1] : 0;
var haveByte3 = i + 2 < input.length;
var byte3 = haveByte3 ? input[i + 2] : 0;
var outByte1 = byte1 >> 2;
var outByte2 = (byte1 & 0x03) << 4 | byte2 >> 4;
var outByte3 = (byte2 & 0x0f) << 2 | byte3 >> 6;
var outByte4 = byte3 & 0x3f;
if (!haveByte3) {
outByte4 = 64;
if (!haveByte2) {
outByte3 = 64;
}
}
output.push(byteToCharMap[outByte1], byteToCharMap[outByte2], byteToCharMap[outByte3], byteToCharMap[outByte4]);
}
return output.join('');
},
/**
* Base64-encode a string.
*
* @param {string} input A string to encode.
* @param {boolean=} opt_webSafe If true, we should use the
* alternative alphabet.
* @return {string} The base64 encoded string.
*/
encodeString: function (input, opt_webSafe) {
// Shortcut for Mozilla browsers that implement
// a native base64 encoder in the form of "btoa/atob"
if (this.HAS_NATIVE_SUPPORT && !opt_webSafe) {
return btoa(input);
}
return this.encodeByteArray(stringToByteArray(input), opt_webSafe);
},
/**
* Base64-decode a string.
*
* @param {string} input to decode.
* @param {boolean=} opt_webSafe True if we should use the
* alternative alphabet.
* @return {string} string representing the decoded value.
*/
decodeString: function (input, opt_webSafe) {
// Shortcut for Mozilla browsers that implement
// a native base64 encoder in the form of "btoa/atob"
if (this.HAS_NATIVE_SUPPORT && !opt_webSafe) {
return atob(input);
}
return byteArrayToString(this.decodeStringToByteArray(input, opt_webSafe));
},
/**
* Base64-decode a string.
*
* In base-64 decoding, groups of four characters are converted into three
* bytes. If the encoder did not apply padding, the input length may not
* be a multiple of 4.
*
* In this case, the last group will have fewer than 4 characters, and
* padding will be inferred. If the group has one or two characters, it decodes
* to one byte. If the group has three characters, it decodes to two bytes.
*
* @param {string} input Input to decode.
* @param {boolean=} opt_webSafe True if we should use the web-safe alphabet.
* @return {!Array<number>} bytes representing the decoded value.
*/
decodeStringToByteArray: function (input, opt_webSafe) {
this.init_();
var charToByteMap = opt_webSafe ? this.charToByteMapWebSafe_ : this.charToByteMap_;
var output = [];
for (var i = 0; i < input.length;) {
var byte1 = charToByteMap[input.charAt(i++)];
var haveByte2 = i < input.length;
var byte2 = haveByte2 ? charToByteMap[input.charAt(i)] : 0;
++i;
var haveByte3 = i < input.length;
var byte3 = haveByte3 ? charToByteMap[input.charAt(i)] : 64;
++i;
var haveByte4 = i < input.length;
var byte4 = haveByte4 ? charToByteMap[input.charAt(i)] : 64;
++i;
if (byte1 == null || byte2 == null || byte3 == null || byte4 == null) {
throw Error();
}
var outByte1 = byte1 << 2 | byte2 >> 4;
output.push(outByte1);
if (byte3 != 64) {
var outByte2 = byte2 << 4 & 0xf0 | byte3 >> 2;
output.push(outByte2);
if (byte4 != 64) {
var outByte3 = byte3 << 6 & 0xc0 | byte4;
output.push(outByte3);
}
}
}
return output;
},
/**
* Lazy static initialization function. Called before
* accessing any of the static map variables.
* @private
*/
init_: function () {
if (!this.byteToCharMap_) {
this.byteToCharMap_ = {};
this.charToByteMap_ = {};
this.byteToCharMapWebSafe_ = {};
this.charToByteMapWebSafe_ = {};
// We want quick mappings back and forth, so we precompute two maps.
for (var i = 0; i < this.ENCODED_VALS.length; i++) {
this.byteToCharMap_[i] = this.ENCODED_VALS.charAt(i);
this.charToByteMap_[this.byteToCharMap_[i]] = i;
this.byteToCharMapWebSafe_[i] = this.ENCODED_VALS_WEBSAFE.charAt(i);
this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[i]] = i;
// Be forgiving when decoding and correctly decode both encodings.
if (i >= this.ENCODED_VALS_BASE.length) {
this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(i)] = i;
this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(i)] = i;
}
}
}
}
};
/**
* URL-safe base64 encoding
* @param {!string} str
* @return {!string}
*/
var base64Encode = function (str) {
var utf8Bytes = stringToByteArray(str);
return base64.encodeByteArray(utf8Bytes, true);
};
/**
* URL-safe base64 decoding
*
* NOTE: DO NOT use the global atob() function - it does NOT support the
* base64Url variant encoding.
*
* @param {string} str To be decoded
* @return {?string} Decoded result, if possible
*/
var base64Decode = function (str) {
try {
return base64.decodeString(str, true);
} catch (e) {
console.error('base64Decode failed: ', e);
}
return null;
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Do a deep-copy of basic JavaScript Objects or Arrays.
*/
function deepCopy(value) {
return deepExtend(undefined, value);
}
/**
* Copy properties from source to target (recursively allows extension
* of Objects and Arrays). Scalar values in the target are over-written.
* If target is undefined, an object of the appropriate type will be created
* (and returned).
*
* We recursively copy all child properties of plain Objects in the source- so
* that namespace- like dictionaries are merged.
*
* Note that the target can be a function, in which case the properties in
* the source Object are copied onto it as static properties of the Function.
*/
function deepExtend(target, source) {
if (!(source instanceof Object)) {
return source;
}
switch (source.constructor) {
case Date:
// Treat Dates like scalars; if the target date object had any child
// properties - they will be lost!
var dateValue = source;
return new Date(dateValue.getTime());
case Object:
if (target === undefined) {
target = {};
}
break;
case Array:
// Always copy the array source and overwrite the target.
target = [];
break;
default:
// Not a plain Object - treat it as a scalar.
return source;
}
for (var prop in source) {
if (!source.hasOwnProperty(prop)) {
continue;
}
target[prop] = deepExtend(target[prop], source[prop]);
}
return target;
}
// TODO: Really needed (for JSCompiler type checking)?
function patchProperty(obj, prop, value) {
obj[prop] = value;
}
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Deferred = /** @class */function () {
function Deferred() {
var _this = this;
this.promise = new Promise(function (resolve, reject) {
_this.resolve = resolve;
_this.reject = reject;
});
}
/**
* Our API internals are not promiseified and cannot because our callback APIs have subtle expectations around
* invoking promises inline, which Promises are forbidden to do. This method accepts an optional node-style callback
* and returns a node-style callback which will resolve or reject the Deferred's promise.
* @param {((?function(?(Error)): (?|undefined))| (?function(?(Error),?=): (?|undefined)))=} callback
* @return {!function(?(Error), ?=)}
*/
Deferred.prototype.wrapCallback = function (callback) {
var _this = this;
return function (error, value) {
if (error) {
_this.reject(error);
} else {
_this.resolve(value);
}
if (typeof callback === 'function') {
// Attaching noop handler just in case developer wasn't expecting
// promises
_this.promise.catch(function () {});
// Some of our callbacks don't expect a value and our own tests
// assert that the parameter length is 1
if (callback.length === 1) {
callback(error);
} else {
callback(error, value);
}
}
};
};
return Deferred;
}();
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Returns navigator.userAgent string or '' if it's not defined.
* @return {string} user agent string
*/
var getUA = function () {
if (typeof navigator !== 'undefined' && typeof navigator['userAgent'] === 'string') {
return navigator['userAgent'];
} else {
return '';
}
};
/**
* Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
*
* Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap in the Ripple emulator) nor
* Cordova `onDeviceReady`, which would normally wait for a callback.
*
* @return {boolean} isMobileCordova
*/
var isMobileCordova = function () {
return typeof window !== 'undefined' && !!(window['cordova'] || window['phonegap'] || window['PhoneGap']) && /ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(getUA());
};
/**
* Detect React Native.
*
* @return {boolean} True if ReactNative environment is detected.
*/
var isReactNative = function () {
return typeof navigator === 'object' && navigator['product'] === 'ReactNative';
};
/**
* Detect Node.js.
*
* @return {boolean} True if Node.js environment is detected.
*/
var isNodeSdk = function () {
return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;
};
var ERROR_NAME = 'FirebaseError';
var captureStackTrace = Error.captureStackTrace;
// Export for faking in tests
function patchCapture(captureFake) {
var result = captureStackTrace;
captureStackTrace = captureFake;
return result;
}
var FirebaseError = /** @class */function () {
function FirebaseError(code, message) {
this.code = code;
this.message = message;
// We want the stack value, if implemented by Error
if (captureStackTrace) {
// Patches this.stack, omitted calls above ErrorFactory#create
captureStackTrace(this, ErrorFactory.prototype.create);
} else {
try {
// In case of IE11, stack will be set only after error is raised.
// https://docs.microsoft.com/en-us/scripting/javascript/reference/stack-property-error-javascript
throw Error.apply(this, arguments);
} catch (err) {
this.name = ERROR_NAME;
// Make non-enumerable getter for the property.
Object.defineProperty(this, 'stack', {
get: function () {
return err.stack;
}
});
}
}
}
return FirebaseError;
}();
// Back-door inheritance
FirebaseError.prototype = Object.create(Error.prototype);
FirebaseError.prototype.constructor = FirebaseError;
FirebaseError.prototype.name = ERROR_NAME;
var ErrorFactory = /** @class */function () {
function ErrorFactory(service, serviceName, errors) {
this.service = service;
this.serviceName = serviceName;
this.errors = errors;
// Matches {$name}, by default.
this.pattern = /\{\$([^}]+)}/g;
// empty
}
ErrorFactory.prototype.create = function (code, data) {
if (data === undefined) {
data = {};
}
var template = this.errors[code];
var fullCode = this.service + '/' + code;
var message;
if (template === undefined) {
message = 'Error';
} else {
message = template.replace(this.pattern, function (match, key) {
var value = data[key];
return value !== undefined ? value.toString() : '<' + key + '?>';
});
}
// Service: Error message (service/code).
message = this.serviceName + ': ' + message + ' (' + fullCode + ').';
var err = new FirebaseError(fullCode, message);
// Populate the Error object with message parts for programmatic
// accesses (e.g., e.file).
for (var prop in data) {
if (!data.hasOwnProperty(prop) || prop.slice(-1) === '_') {
continue;
}
err[prop] = data[prop];
}
return err;
};
return ErrorFactory;
}();
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Evaluates a JSON string into a javascript object.
*
* @param {string} str A string containing JSON.
* @return {*} The javascript object representing the specified JSON.
*/
function jsonEval(str) {
return JSON.parse(str);
}
/**
* Returns JSON representing a javascript object.
* @param {*} data Javascript object to be stringified.
* @return {string} The JSON contents of the object.
*/
function stringify(data) {
return JSON.stringify(data);
}
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Decodes a Firebase auth. token into constituent parts.
*
* Notes:
* - May return with invalid / incomplete claims if there's no native base64 decoding support.
* - Doesn't check if the token is actually valid.
*
* @param {?string} token
* @return {{header: *, claims: *, data: *, signature: string}}
*/
var decode = function (token) {
var header = {},
claims = {},
data = {},
signature = '';
try {
var parts = token.split('.');
header = jsonEval(base64Decode(parts[0]) || '');
claims = jsonEval(base64Decode(parts[1]) || '');
signature = parts[2];
data = claims['d'] || {};
delete claims['d'];
} catch (e) {}
return {
header: header,
claims: claims,
data: data,
signature: signature
};
};
/**
* Decodes a Firebase auth. token and checks the validity of its time-based claims. Will return true if the
* token is within the time window authorized by the 'nbf' (not-before) and 'iat' (issued-at) claims.
*
* Notes:
* - May return a false negative if there's no native base64 decoding support.
* - Doesn't check if the token is actually valid.
*
* @param {?string} token
* @return {boolean}
*/
var isValidTimestamp = function (token) {
var claims = decode(token).claims,
now = Math.floor(new Date().getTime() / 1000),
validSince,
validUntil;
if (typeof claims === 'object') {
if (claims.hasOwnProperty('nbf')) {
validSince = claims['nbf'];
} else if (claims.hasOwnProperty('iat')) {
validSince = claims['iat'];
}
if (claims.hasOwnProperty('exp')) {
validUntil = claims['exp'];
} else {
// token will expire after 24h by default
validUntil = validSince + 86400;
}
}
return now && validSince && validUntil && now >= validSince && now <= validUntil;
};
/**
* Decodes a Firebase auth. token and returns its issued at time if valid, null otherwise.
*
* Notes:
* - May return null if there's no native base64 decoding support.
* - Doesn't check if the token is actually valid.
*
* @param {?string} token
* @return {?number}
*/
var issuedAtTime = function (token) {
var claims = decode(token).claims;
if (typeof claims === 'object' && claims.hasOwnProperty('iat')) {
return claims['iat'];
}
return null;
};
/**
* Decodes a Firebase auth. token and checks the validity of its format. Expects a valid issued-at time and non-empty
* signature.
*
* Notes:
* - May return a false negative if there's no native base64 decoding support.
* - Doesn't check if the token is actually valid.
*
* @param {?string} token
* @return {boolean}
*/
var isValidFormat = function (token) {
var decoded = decode(token),
claims = decoded.claims;
return !!decoded.signature && !!claims && typeof claims === 'object' && claims.hasOwnProperty('iat');
};
/**
* Attempts to peer into an auth token and determine if it's an admin auth token by looking at the claims portion.
*
* Notes:
* - May return a false negative if there's no native base64 decoding support.
* - Doesn't check if the token is actually valid.
*
* @param {?string} token
* @return {boolean}
*/
var isAdmin = function (token) {
var claims = decode(token).claims;
return typeof claims === 'object' && claims['admin'] === true;
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// See http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/
var contains = function (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
};
var safeGet = function (obj, key) {
if (Object.prototype.hasOwnProperty.call(obj, key)) return obj[key];
// else return undefined.
};
/**
* Enumerates the keys/values in an object, excluding keys defined on the prototype.
*
* @param {?Object.<K,V>} obj Object to enumerate.
* @param {!function(K, V)} fn Function to call for each key and value.
* @template K,V
*/
var forEach = function (obj, fn) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
fn(key, obj[key]);
}
}
};
/**
* Copies all the (own) properties from one object to another.
* @param {!Object} objTo
* @param {!Object} objFrom
* @return {!Object} objTo
*/
var extend = function (objTo, objFrom) {
forEach(objFrom, function (key, value) {
objTo[key] = value;
});
return objTo;
};
/**
* Returns a clone of the specified object.
* @param {!Object} obj
* @return {!Object} cloned obj.
*/
var clone = function (obj) {
return extend({}, obj);
};
/**
* Returns true if obj has typeof "object" and is not null. Unlike goog.isObject(), does not return true
* for functions.
*
* @param obj {*} A potential object.
* @returns {boolean} True if it's an object.
*/
var isNonNullObject = function (obj) {
return typeof obj === 'object' && obj !== null;
};
var isEmpty = function (obj) {
for (var key in obj) {
return false;
}
return true;
};
var getCount = function (obj) {
var rv = 0;
for (var key in obj) {
rv++;
}
return rv;
};
var map = function (obj, f, opt_obj) {
var res = {};
for (var key in obj) {
res[key] = f.call(opt_obj, obj[key], key, obj);
}
return res;
};
var findKey = function (obj, fn, opt_this) {
for (var key in obj) {
if (fn.call(opt_this, obj[key], key, obj)) {
return key;
}
}
return undefined;
};
var findValue = function (obj, fn, opt_this) {
var key = findKey(obj, fn, opt_this);
return key && obj[key];
};
var getAnyKey = function (obj) {
for (var key in obj) {
return key;
}
};
var getValues = function (obj) {
var res = [];
var i = 0;
for (var key in obj) {
res[i++] = obj[key];
}
return res;
};
/**
* Tests whether every key/value pair in an object pass the test implemented
* by the provided function
*
* @param {?Object.<K,V>} obj Object to test.
* @param {!function(K, V)} fn Function to call for each key and value.
* @template K,V
*/
var every = function (obj, fn) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
if (!fn(key, obj[key])) {
return false;
}
}
}
return true;
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Returns a querystring-formatted string (e.g. &arg=val&arg2=val2) from a params
* object (e.g. {arg: 'val', arg2: 'val2'})
* Note: You must prepend it with ? when adding it to a URL.
*
* @param {!Object} querystringParams
* @return {string}
*/
var querystring = function (querystringParams) {
var params = [];
forEach(querystringParams, function (key, value) {
if (Array.isArray(value)) {
value.forEach(function (arrayVal) {
params.push(encodeURIComponent(key) + '=' + encodeURIComponent(arrayVal));
});
} else {
params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
}
});
return params.length ? '&' + params.join('&') : '';
};
/**
* Decodes a querystring (e.g. ?arg=val&arg2=val2) into a params object (e.g. {arg: 'val', arg2: 'val2'})
*
* @param {string} querystring
* @return {!Object}
*/
var querystringDecode = function (querystring) {
var obj = {};
var tokens = querystring.replace(/^\?/, '').split('&');
tokens.forEach(function (token) {
if (token) {
var key = token.split('=');
obj[key[0]] = key[1];
}
});
return obj;
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2011 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Abstract cryptographic hash interface.
*
* See Sha1 and Md5 for sample implementations.
*
*/
/**
* Create a cryptographic hash instance.
*
* @constructor
* @struct
*/
var Hash = /** @class */function () {
function Hash() {
/**
* The block size for the hasher.
* @type {number}
*/
this.blockSize = -1;
}
return Hash;
}();
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview SHA-1 cryptographic hash.
* Variable names follow the notation in FIPS PUB 180-3:
* http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf.
*
* Usage:
* var sha1 = new sha1();
* sha1.update(bytes);
* var hash = sha1.digest();
*
* Performance:
* Chrome 23: ~400 Mbit/s
* Firefox 16: ~250 Mbit/s
*
*/
/**
* SHA-1 cryptographic hash constructor.
*
* The properties declared here are discussed in the above algorithm document.
* @constructor
* @extends {Hash}
* @final
* @struct
*/
var Sha1 = /** @class */function (_super) {
tslib_1.__extends(Sha1, _super);
function Sha1() {
var _this = _super.call(this) || this;
/**
* Holds the previous values of accumulated variables a-e in the compress_
* function.
* @type {!Array<number>}
* @private
*/
_this.chain_ = [];
/**
* A buffer holding the partially computed hash result.
* @type {!Array<number>}
* @private
*/
_this.buf_ = [];
/**
* An array of 80 bytes, each a part of the message to be hashed. Referred to
* as the message schedule in the docs.
* @type {!Array<number>}
* @private
*/
_this.W_ = [];
/**
* Contains data needed to pad messages less than 64 bytes.
* @type {!Array<number>}
* @private
*/
_this.pad_ = [];
/**
* @private {number}
*/
_this.inbuf_ = 0;
/**
* @private {number}
*/
_this.total_ = 0;
_this.blockSize = 512 / 8;
_this.pad_[0] = 128;
for (var i = 1; i < _this.blockSize; ++i) {
_this.pad_[i] = 0;
}
_this.reset();
return _this;
}
Sha1.prototype.reset = function () {
this.chain_[0] = 0x67452301;
this.chain_[1] = 0xefcdab89;
this.chain_[2] = 0x98badcfe;
this.chain_[3] = 0x10325476;
this.chain_[4] = 0xc3d2e1f0;
this.inbuf_ = 0;
this.total_ = 0;
};
/**
* Internal compress helper function.
* @param {!Array<number>|!Uint8Array|string} buf Block to compress.
* @param {number=} opt_offset Offset of the block in the buffer.
* @private
*/
Sha1.prototype.compress_ = function (buf, opt_offset) {
if (!opt_offset) {
opt_offset = 0;
}
var W = this.W_;
// get 16 big endian words
if (typeof buf === 'string') {
for (var i = 0; i < 16; i++) {
// TODO(user): [bug 8140122] Recent versions of Safari for Mac OS and iOS
// have a bug that turns the post-increment ++ operator into pre-increment
// during JIT compilation. We have code that depends heavily on SHA-1 for
// correctness and which is affected by this bug, so I've removed all uses
// of post-increment ++ in which the result value is used. We can revert
// this change once the Safari bug
// (https://bugs.webkit.org/show_bug.cgi?id=109036) has been fixed and
// most clients have been updated.
W[i] = buf.charCodeAt(opt_offset) << 24 | buf.charCodeAt(opt_offset + 1) << 16 | buf.charCodeAt(opt_offset + 2) << 8 | buf.charCodeAt(opt_offset + 3);
opt_offset += 4;
}
} else {
for (var i = 0; i < 16; i++) {
W[i] = buf[opt_offset] << 24 | buf[opt_offset + 1] << 16 | buf[opt_offset + 2] << 8 | buf[opt_offset + 3];
opt_offset += 4;
}
}
// expand to 80 words
for (var i = 16; i < 80; i++) {
var t = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
W[i] = (t << 1 | t >>> 31) & 0xffffffff;
}
var a = this.chain_[0];
var b = this.chain_[1];
var c = this.chain_[2];
var d = this.chain_[3];
var e = this.chain_[4];
var f, k;
// TODO(user): Try to unroll this loop to speed up the computation.
for (var i = 0; i < 80; i++) {
if (i < 40) {
if (i < 20) {
f = d ^ b & (c ^ d);
k = 0x5a827999;
} else {
f = b ^ c ^ d;
k = 0x6ed9eba1;
}
} else {
if (i < 60) {
f = b & c | d & (b | c);
k = 0x8f1bbcdc;
} else {
f = b ^ c ^ d;
k = 0xca62c1d6;
}
}
var t = (a << 5 | a >>> 27) + f + e + k + W[i] & 0xffffffff;
e = d;
d = c;
c = (b << 30 | b >>> 2) & 0xffffffff;
b = a;
a = t;
}
this.chain_[0] = this.chain_[0] + a & 0xffffffff;
this.chain_[1] = this.chain_[1] + b & 0xffffffff;
this.chain_[2] = this.chain_[2] + c & 0xffffffff;
this.chain_[3] = this.chain_[3] + d & 0xffffffff;
this.chain_[4] = this.chain_[4] + e & 0xffffffff;
};
Sha1.prototype.update = function (bytes, opt_length) {
// TODO(johnlenz): tighten the function signature and remove this check
if (bytes == null) {
return;
}
if (opt_length === undefined) {
opt_length = bytes.length;
}
var lengthMinusBlock = opt_length - this.blockSize;
var n = 0;
// Using local instead of member variables gives ~5% speedup on Firefox 16.
var buf = this.buf_;
var inbuf = this.inbuf_;
// The outer while loop should execute at most twice.
while (n < opt_length) {
// When we have no data in the block to top up, we can directly process the
// input buffer (assuming it contains sufficient data). This gives ~25%
// speedup on Chrome 23 and ~15% speedup on Firefox 16, but requires that
// the data is provided in large chunks (or in multiples of 64 bytes).
if (inbuf == 0) {
while (n <= lengthMinusBlock) {
this.compress_(bytes, n);
n += this.blockSize;
}
}
if (typeof bytes === 'string') {
while (n < opt_length) {
buf[inbuf] = bytes.charCodeAt(n);
++inbuf;
++n;
if (inbuf == this.blockSize) {
this.compress_(buf);
inbuf = 0;
// Jump to the outer loop so we use the full-block optimization.
break;
}
}
} else {
while (n < opt_length) {
buf[inbuf] = bytes[n];
++inbuf;
++n;
if (inbuf == this.blockSize) {
this.compress_(buf);
inbuf = 0;
// Jump to the outer loop so we use the full-block optimization.
break;
}
}
}
}
this.inbuf_ = inbuf;
this.total_ += opt_length;
};
/** @override */
Sha1.prototype.digest = function () {
var digest = [];
var totalBits = this.total_ * 8;
// Add pad 0x80 0x00*.
if (this.inbuf_ < 56) {
this.update(this.pad_, 56 - this.inbuf_);
} else {
this.update(this.pad_, this.blockSize - (this.inbuf_ - 56));
}
// Add # bits.
for (var i = this.blockSize - 1; i >= 56; i--) {
this.buf_[i] = totalBits & 255;
totalBits /= 256; // Don't use bit-shifting here!
}
this.compress_(this.buf_);
var n = 0;
for (var i = 0; i < 5; i++) {
for (var j = 24; j >= 0; j -= 8) {
digest[n] = this.chain_[i] >> j & 255;
++n;
}
}
return digest;
};
return Sha1;
}(Hash);
/**
* Helper to make a Subscribe function (just like Promise helps make a
* Thenable).
*
* @param executor Function which can make calls to a single Observer
* as a proxy.
* @param onNoObservers Callback when count of Observers goes to zero.
*/
function createSubscribe(executor, onNoObservers) {
var proxy = new ObserverProxy(executor, onNoObservers);
return proxy.subscribe.bind(proxy);
}
/**
* Implement fan-out for any number of Observers attached via a subscribe
* function.
*/
var ObserverProxy = /** @class */function () {
/**
* @param executor Function which can make calls to a single Observer
* as a proxy.
* @param onNoObservers Callback when count of Observers goes to zero.
*/
function ObserverProxy(executor, onNoObservers) {
var _this = this;
this.observers = [];
this.unsubscribes = [];
this.observerCount = 0;
// Micro-task scheduling by calling task.then().
this.task = Promise.resolve();
this.finalized = false;
this.onNoObservers = onNoObservers;
// Call the executor asynchronously so subscribers that are called
// synchronously after the creation of the subscribe function
// can still receive the very first value generated in the executor.
this.task.then(function () {
executor(_this);
}).catch(function (e) {
_this.error(e);
});
}
ObserverProxy.prototype.next = function (value) {
this.forEachObserver(function (observer) {
observer.next(value);
});
};
ObserverProxy.prototype.error = function (error) {
this.forEachObserver(function (observer) {
observer.error(error);
});
this.close(error);
};
ObserverProxy.prototype.complete = function () {
this.forEachObserver(function (observer) {
observer.complete();
});
this.close();
};
/**
* Subscribe function that can be used to add an Observer to the fan-out list.
*
* - We require that no event is sent to a subscriber sychronously to their
* call to subscribe().
*/
ObserverProxy.prototype.subscribe = function (nextOrObserver, error, complete) {
var _this = this;
var observer;
if (nextOrObserver === undefined && error === undefined && complete === undefined) {
throw new Error('Missing Observer.');
}
// Assemble an Observer object when passed as callback functions.
if (implementsAnyMethods(nextOrObserver, ['next', 'error', 'complete'])) {
observer = nextOrObserver;
} else {
observer = {
next: nextOrObserver,
error: error,
complete: complete
};
}
if (observer.next === undefined) {
observer.next = noop;
}
if (observer.error === undefined) {
observer.error = noop;
}
if (observer.complete === undefined) {
observer.complete = noop;
}
var unsub = this.unsubscribeOne.bind(this, this.observers.length);
// Attempt to subscribe to a terminated Observable - we
// just respond to the Observer with the final error or complete
// event.
if (this.finalized) {
this.task.then(function () {
try {
if (_this.finalError) {
observer.error(_this.finalError);
} else {
observer.complete();
}
} catch (e) {
// nothing
}
return;
});
}
this.observers.push(observer);
return unsub;
};
// Unsubscribe is synchronous - we guarantee that no events are sent to
// any unsubscribed Observer.
ObserverProxy.prototype.unsubscribeOne = function (i) {
if (this.observers === undefined || this.observers[i] === undefined) {
return;
}
delete this.observers[i];
this.observerCount -= 1;
if (this.observerCount === 0 && this.onNoObservers !== undefined) {
this.onNoObservers(this);
}
};
ObserverProxy.prototype.forEachObserver = function (fn) {
if (this.finalized) {
// Already closed by previous event....just eat the additional values.
return;
}
// Since sendOne calls asynchronously - there is no chance that
// this.observers will become undefined.
for (var i = 0; i < this.observers.length; i++) {
this.sendOne(i, fn);
}
};
// Call the Observer via one of it's callback function. We are careful to
// confirm that the observe has not been unsubscribed since this asynchronous
// function had been queued.
ObserverProxy.prototype.sendOne = function (i, fn) {
var _this = this;
// Execute the callback asynchronously
this.task.then(function () {
if (_this.observers !== undefined && _this.observers[i] !== undefined) {
try {
fn(_this.observers[i]);
} catch (e) {
// Ignore exceptions raised in Observers or missing methods of an
// Observer.
// Log error to console. b/31404806
if (typeof console !== 'undefined' && console.error) {
console.error(e);
}
}
}
});
};
ObserverProxy.prototype.close = function (err) {
var _this = this;
if (this.finalized) {
return;
}
this.finalized = true;
if (err !== undefined) {
this.finalError = err;
}
// Proxy is no longer needed - garbage collect references
this.task.then(function () {
_this.observers = undefined;
_this.onNoObservers = undefined;
});
};
return ObserverProxy;
}();
/** Turn synchronous function into one called asynchronously. */
function async(fn, onError) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
Promise.resolve(true).then(function () {
fn.apply(void 0, args);
}).catch(function (error) {
if (onError) {
onError(error);
}
});
};
}
/**
* Return true if the object passed in implements any of the named methods.
*/
function implementsAnyMethods(obj, methods) {
if (typeof obj !== 'object' || obj === null) {
return false;
}
for (var _i = 0, methods_1 = methods; _i < methods_1.length; _i++) {
var method = methods_1[_i];
if (method in obj && typeof obj[method] === 'function') {
return true;
}
}
return false;
}
function noop() {}
// do nothing
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Check to make sure the appropriate number of arguments are provided for a public function.
* Throws an error if it fails.
*
* @param {!string} fnName The function name
* @param {!number} minCount The minimum number of arguments to allow for the function call
* @param {!number} maxCount The maximum number of argument to allow for the function call
* @param {!number} argCount The actual number of arguments provided.
*/
var validateArgCount = function (fnName, minCount, maxCount, argCount) {
var argError;
if (argCount < minCount) {
argError = 'at least ' + minCount;
} else if (argCount > maxCount) {
argError = maxCount === 0 ? 'none' : 'no more than ' + maxCount;
}
if (argError) {
var error = fnName + ' failed: Was called with ' + argCount + (argCount === 1 ? ' argument.' : ' arguments.') + ' Expects ' + argError + '.';
throw new Error(error);
}
};
/**
* Generates a string to prefix an error message about failed argument validation
*
* @param {!string} fnName The function name
* @param {!number} argumentNumber The index of the argument
* @param {boolean} optional Whether or not the argument is optional
* @return {!string} The prefix to add to the error thrown for validation.
*/
function errorPrefix(fnName, argumentNumber, optional) {
var argName = '';
switch (argumentNumber) {
case 1:
argName = optional ? 'first' : 'First';
break;
case 2:
argName = optional ? 'second' : 'Second';
break;
case 3:
argName = optional ? 'third' : 'Third';
break;
case 4:
argName = optional ? 'fourth' : 'Fourth';
break;
default:
throw new Error('errorPrefix called with argumentNumber > 4. Need to update it?');
}
var error = fnName + ' failed: ';
error += argName + ' argument ';
return error;
}
/**
* @param {!string} fnName
* @param {!number} argumentNumber
* @param {!string} namespace
* @param {boolean} optional
*/
function validateNamespace(fnName, argumentNumber, namespace, optional) {
if (optional && !namespace) return;
if (typeof namespace !== 'string') {
//TODO: I should do more validation here. We only allow certain chars in namespaces.
throw new Error(errorPrefix(fnName, argumentNumber, optional) + 'must be a valid firebase namespace.');
}
}
function validateCallback(fnName, argumentNumber, callback, optional) {
if (optional && !callback) return;
if (typeof callback !== 'function') throw new Error(errorPrefix(fnName, argumentNumber, optional) + 'must be a valid function.');
}
function validateContextObject(fnName, argumentNumber, context, optional) {
if (optional && !context) return;
if (typeof context !== 'object' || context === null) throw new Error(errorPrefix(fnName, argumentNumber, optional) + 'must be a valid context object.');
}
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Code originally came from goog.crypt.stringToUtf8ByteArray, but for some reason they
// automatically replaced '\r\n' with '\n', and they didn't handle surrogate pairs,
// so it's been modified.
// Note that not all Unicode characters appear as single characters in JavaScript strings.
// fromCharCode returns the UTF-16 encoding of a character - so some Unicode characters
// use 2 characters in Javascript. All 4-byte UTF-8 characters begin with a first
// character in the range 0xD800 - 0xDBFF (the first character of a so-called surrogate
// pair).
// See http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3
/**
* @param {string} str
* @return {Array}
*/
var stringToByteArray$1 = function (str) {
var out = [],
p = 0;
for (var i = 0; i < str.length; i++) {
var c = str.charCodeAt(i);
// Is this the lead surrogate in a surrogate pair?
if (c >= 0xd800 && c <= 0xdbff) {
var high = c - 0xd800; // the high 10 bits.
i++;
assert(i < str.length, 'Surrogate pair missing trail surrogate.');
var low = str.charCodeAt(i) - 0xdc00; // the low 10 bits.
c = 0x10000 + (high << 10) + low;
}
if (c < 128) {
out[p++] = c;
} else if (c < 2048) {
out[p++] = c >> 6 | 192;
out[p++] = c & 63 | 128;
} else if (c < 65536) {
out[p++] = c >> 12 | 224;
out[p++] = c >> 6 & 63 | 128;
out[p++] = c & 63 | 128;
} else {
out[p++] = c >> 18 | 240;
out[p++] = c >> 12 & 63 | 128;
out[p++] = c >> 6 & 63 | 128;
out[p++] = c & 63 | 128;
}
}
return out;
};
/**
* Calculate length without actually converting; useful for doing cheaper validation.
* @param {string} str
* @return {number}
*/
var stringLength = function (str) {
var p = 0;
for (var i = 0; i < str.length; i++) {
var c = str.charCodeAt(i);
if (c < 128) {
p++;
} else if (c < 2048) {
p += 2;
} else if (c >= 0xd800 && c <= 0xdbff) {
// Lead surrogate of a surrogate pair. The pair together will take 4 bytes to represent.
p += 4;
i++; // skip trail surrogate.
} else {
p += 3;
}
}
return p;
};
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
exports.assert = assert;
exports.assertionError = assertionError;
exports.base64 = base64;
exports.base64Decode = base64Decode;
exports.base64Encode = base64Encode;
exports.CONSTANTS = CONSTANTS;
exports.deepCopy = deepCopy;
exports.deepExtend = deepExtend;
exports.patchProperty = patchProperty;
exports.Deferred = Deferred;
exports.getUA = getUA;
exports.isMobileCordova = isMobileCordova;
exports.isNodeSdk = isNodeSdk;
exports.isReactNative = isReactNative;
exports.ErrorFactory = ErrorFactory;
exports.FirebaseError = FirebaseError;
exports.patchCapture = patchCapture;
exports.jsonEval = jsonEval;
exports.stringify = stringify;
exports.decode = decode;
exports.isAdmin = isAdmin;
exports.issuedAtTime = issuedAtTime;
exports.isValidFormat = isValidFormat;
exports.isValidTimestamp = isValidTimestamp;
exports.clone = clone;
exports.contains = contains;
exports.every = every;
exports.extend = extend;
exports.findKey = findKey;
exports.findValue = findValue;
exports.forEach = forEach;
exports.getAnyKey = getAnyKey;
exports.getCount = getCount;
exports.getValues = getValues;
exports.isEmpty = isEmpty;
exports.isNonNullObject = isNonNullObject;
exports.map = map;
exports.safeGet = safeGet;
exports.querystring = querystring;
exports.querystringDecode = querystringDecode;
exports.Sha1 = Sha1;
exports.async = async;
exports.createSubscribe = createSubscribe;
exports.errorPrefix = errorPrefix;
exports.validateArgCount = validateArgCount;
exports.validateCallback = validateCallback;
exports.validateContextObject = validateContextObject;
exports.validateNamespace = validateNamespace;
exports.stringLength = stringLength;
exports.stringToByteArray = stringToByteArray$1;
/***/ }),
/***/ "5gBI":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
function lineIndent(cm, lineNo) {
var text = cm.getLine(lineNo);
var spaceTo = text.search(/\S/);
if (spaceTo == -1 || /\bcomment\b/.test(cm.getTokenTypeAt(CodeMirror.Pos(lineNo, spaceTo + 1)))) return -1;
return CodeMirror.countColumn(text, null, cm.getOption("tabSize"));
}
CodeMirror.registerHelper("fold", "indent", function (cm, start) {
var myIndent = lineIndent(cm, start.line);
if (myIndent < 0) return;
var lastLineInFold = null;
// Go through lines until we find a line that definitely doesn't belong in
// the block we're folding, or to the end.
for (var i = start.line + 1, end = cm.lastLine(); i <= end; ++i) {
var indent = lineIndent(cm, i);
if (indent == -1) {} else if (indent > myIndent) {
// Lines with a greater indent are considered part of the block.
lastLineInFold = i;
} else {
// If this line has non-space, non-comment content, and is
// indented less or equal to the start line, it is the start of
// another block.
break;
}
}
if (lastLineInFold) return {
from: CodeMirror.Pos(start.line, cm.getLine(start.line).length),
to: CodeMirror.Pos(lastLineInFold, cm.getLine(lastLineInFold).length)
};
});
});
/***/ }),
/***/ "6r0S":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
var Pos = CodeMirror.Pos;
function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
function arrayContains(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
if (arr[i] === item) {
return true;
}
}
return false;
}
return arr.indexOf(item) != -1;
}
function scriptHint(editor, keywords, getToken, options) {
// Find the token at the cursor
var cur = editor.getCursor(),
token = getToken(editor, cur);
if (/\b(?:string|comment)\b/.test(token.type)) return;
var innerMode = CodeMirror.innerMode(editor.getMode(), token.state);
if (innerMode.mode.helperType === "json") return;
token.state = innerMode.state;
// If it's not a 'word-style' token, ignore the token.
if (!/^[\w$_]*$/.test(token.string)) {
token = { start: cur.ch, end: cur.ch, string: "", state: token.state,
type: token.string == "." ? "property" : null };
} else if (token.end > cur.ch) {
token.end = cur.ch;
token.string = token.string.slice(0, cur.ch - token.start);
}
var tprop = token;
// If it is a property, find out what it is a property of.
while (tprop.type == "property") {
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (tprop.string != ".") return;
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (!context) var context = [];
context.push(tprop);
}
return { list: getCompletions(token, context, keywords, options),
from: Pos(cur.line, token.start),
to: Pos(cur.line, token.end) };
}
function javascriptHint(editor, options) {
return scriptHint(editor, javascriptKeywords, function (e, cur) {
return e.getTokenAt(cur);
}, options);
};
CodeMirror.registerHelper("hint", "javascript", javascriptHint);
function getCoffeeScriptToken(editor, cur) {
// This getToken, it is for coffeescript, imitates the behavior of
// getTokenAt method in javascript.js, that is, returning "property"
// type and treat "." as indepenent token.
var token = editor.getTokenAt(cur);
if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
token.end = token.start;
token.string = '.';
token.type = "property";
} else if (/^\.[\w$_]*$/.test(token.string)) {
token.type = "property";
token.start++;
token.string = token.string.replace(/\./, '');
}
return token;
}
function coffeescriptHint(editor, options) {
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
}
CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint);
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " + "toUpperCase toLowerCase split concat match replace search").split(" ");
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " + "lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
var funcProps = "prototype apply call bind".split(" ");
var javascriptKeywords = ("break case catch class const continue debugger default delete do else export extends false finally for function " + "if in import instanceof new null return super switch this throw true try typeof var void while with yield").split(" ");
var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " + "if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
function forAllProps(obj, callback) {
if (!Object.getOwnPropertyNames || !Object.getPrototypeOf) {
for (var name in obj) callback(name);
} else {
for (var o = obj; o; o = Object.getPrototypeOf(o)) Object.getOwnPropertyNames(o).forEach(callback);
}
}
function getCompletions(token, context, keywords, options) {
var found = [],
start = token.string,
global = options && options.globalScope || window;
function maybeAdd(str) {
if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
}
function gatherCompletions(obj) {
if (typeof obj == "string") forEach(stringProps, maybeAdd);else if (obj instanceof Array) forEach(arrayProps, maybeAdd);else if (obj instanceof Function) forEach(funcProps, maybeAdd);
forAllProps(obj, maybeAdd);
}
if (context && context.length) {
// If this is a property, see if it belongs to some object we can
// find in the current environment.
var obj = context.pop(),
base;
if (obj.type && obj.type.indexOf("variable") === 0) {
if (options && options.additionalContext) base = options.additionalContext[obj.string];
if (!options || options.useGlobalScope !== false) base = base || global[obj.string];
} else if (obj.type == "string") {
base = "";
} else if (obj.type == "atom") {
base = 1;
} else if (obj.type == "function") {
if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') && typeof global.jQuery == 'function') base = global.jQuery();else if (global._ != null && obj.string == '_' && typeof global._ == 'function') base = global._();
}
while (base != null && context.length) base = base[context.pop().string];
if (base != null) gatherCompletions(base);
} else {
// If not, just look in the global object and any local scope
// (reading into JS mode internals to get at the local and global variables)
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
if (!options || options.useGlobalScope !== false) gatherCompletions(global);
forEach(keywords, maybeAdd);
}
return found;
}
});
/***/ }),
/***/ "7vHL":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__firebase_firestore__ = __webpack_require__("eA7g");
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__firebase_firestore___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__firebase_firestore__);
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/***/ }),
/***/ "AIXc":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("HeB0"), __webpack_require__("qqFR"), __webpack_require__("ggoL"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var defaultTags = {
script: [["lang", /(javascript|babel)/i, "javascript"], ["type", /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i, "javascript"], ["type", /./, "text/plain"], [null, null, "javascript"]],
style: [["lang", /^css$/i, "css"], ["type", /^(text\/)?(x-)?(stylesheet|css)$/i, "css"], ["type", /./, "text/plain"], [null, null, "css"]]
};
function maybeBackup(stream, pat, style) {
var cur = stream.current(),
close = cur.search(pat);
if (close > -1) {
stream.backUp(cur.length - close);
} else if (cur.match(/<\/?$/)) {
stream.backUp(cur.length);
if (!stream.match(pat, false)) stream.match(cur);
}
return style;
}
var attrRegexpCache = {};
function getAttrRegexp(attr) {
var regexp = attrRegexpCache[attr];
if (regexp) return regexp;
return attrRegexpCache[attr] = new RegExp("\\s+" + attr + "\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*");
}
function getAttrValue(text, attr) {
var match = text.match(getAttrRegexp(attr));
return match ? /^\s*(.*?)\s*$/.exec(match[2])[1] : "";
}
function getTagRegexp(tagName, anchored) {
return new RegExp((anchored ? "^" : "") + "<\/\s*" + tagName + "\s*>", "i");
}
function addTags(from, to) {
for (var tag in from) {
var dest = to[tag] || (to[tag] = []);
var source = from[tag];
for (var i = source.length - 1; i >= 0; i--) dest.unshift(source[i]);
}
}
function findMatchingMode(tagInfo, tagText) {
for (var i = 0; i < tagInfo.length; i++) {
var spec = tagInfo[i];
if (!spec[0] || spec[1].test(getAttrValue(tagText, spec[0]))) return spec[2];
}
}
CodeMirror.defineMode("htmlmixed", function (config, parserConfig) {
var htmlMode = CodeMirror.getMode(config, {
name: "xml",
htmlMode: true,
multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,
multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag
});
var tags = {};
var configTags = parserConfig && parserConfig.tags,
configScript = parserConfig && parserConfig.scriptTypes;
addTags(defaultTags, tags);
if (configTags) addTags(configTags, tags);
if (configScript) for (var i = configScript.length - 1; i >= 0; i--) tags.script.unshift(["type", configScript[i].matches, configScript[i].mode]);
function html(stream, state) {
var style = htmlMode.token(stream, state.htmlState),
tag = /\btag\b/.test(style),
tagName;
if (tag && !/[<>\s\/]/.test(stream.current()) && (tagName = state.htmlState.tagName && state.htmlState.tagName.toLowerCase()) && tags.hasOwnProperty(tagName)) {
state.inTag = tagName + " ";
} else if (state.inTag && tag && />$/.test(stream.current())) {
var inTag = /^([\S]+) (.*)/.exec(state.inTag);
state.inTag = null;
var modeSpec = stream.current() == ">" && findMatchingMode(tags[inTag[1]], inTag[2]);
var mode = CodeMirror.getMode(config, modeSpec);
var endTagA = getTagRegexp(inTag[1], true),
endTag = getTagRegexp(inTag[1], false);
state.token = function (stream, state) {
if (stream.match(endTagA, false)) {
state.token = html;
state.localState = state.localMode = null;
return null;
}
return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState));
};
state.localMode = mode;
state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, ""));
} else if (state.inTag) {
state.inTag += stream.current();
if (stream.eol()) state.inTag += " ";
}
return style;
};
return {
startState: function () {
var state = CodeMirror.startState(htmlMode);
return { token: html, inTag: null, localMode: null, localState: null, htmlState: state };
},
copyState: function (state) {
var local;
if (state.localState) {
local = CodeMirror.copyState(state.localMode, state.localState);
}
return { token: state.token, inTag: state.inTag,
localMode: state.localMode, localState: local,
htmlState: CodeMirror.copyState(htmlMode, state.htmlState) };
},
token: function (stream, state) {
return state.token(stream, state);
},
indent: function (state, textAfter, line) {
if (!state.localMode || /^\s*<\//.test(textAfter)) return htmlMode.indent(state.htmlState, textAfter);else if (state.localMode.indent) return state.localMode.indent(state.localState, textAfter, line);else return CodeMirror.Pass;
},
innerMode: function (state) {
return { state: state.localState || state.htmlState, mode: state.localMode || htmlMode };
}
};
}, "xml", "javascript", "css");
CodeMirror.defineMIME("text/html", "htmlmixed");
});
/***/ }),
/***/ "AhD2":
/***/ (function(module, exports) {
/*
Based on Joel Besada's lovely experiment
https://twitter.com/JoelBesada/status/670343885655293952
*/
;(function () {
var shakeTime = 0,
shakeTimeMax = 0,
shakeIntensity = 5,
lastTime = 0,
particles = [],
particlePointer = 0,
MAX_PARTICLES = 100,
PARTICLE_NUM_RANGE = { min: 2, max: 7 },
PARTICLE_GRAVITY = 0.08,
PARTICLE_ALPHA_FADEOUT = 0.96,
PARTICLE_VELOCITY_RANGE = {
x: [-1, 1],
y: [-3.5, -1.5]
},
w = window.innerWidth,
h = window.innerHeight,
effect,
isActive = false;
var codemirrors = [],
cmNode;
var canvas, ctx;
var current_time, dt, magnitude, shakeX, shakeY; // loop vars
var throttledShake = throttle(shake, 100);
var throttledSpawnParticles = throttle(spawnParticles, 100);
function getRGBComponents(node) {
var color = getComputedStyle(node).color;
if (color) {
try {
return color.match(/(\d+), (\d+), (\d+)/).slice(1);
} catch (e) {
return [255, 255, 255];
}
} else {
return [255, 255, 255];
}
}
function spawnParticles(cm, type) {
var cursorPos = cm.getCursor();
var pos = cm.cursorCoords();
var node = document.elementFromPoint(pos.left - 5, pos.top + 5);
type = cm.getTokenAt(cursorPos);
if (type) {
type = type.type;
};
var numParticles = random(PARTICLE_NUM_RANGE.min, PARTICLE_NUM_RANGE.max);
var color = getRGBComponents(node);
for (var i = numParticles; i--;) {
particles[particlePointer] = createParticle(pos.left + 10, pos.top, color);
particlePointer = (particlePointer + 1) % MAX_PARTICLES;
}
}
function createParticle(x, y, color) {
var p = {
x: x,
y: y + 10,
alpha: 1,
color: color
};
if (effect === 1) {
p.size = random(2, 4);
p.vx = PARTICLE_VELOCITY_RANGE.x[0] + Math.random() * (PARTICLE_VELOCITY_RANGE.x[1] - PARTICLE_VELOCITY_RANGE.x[0]);
p.vy = PARTICLE_VELOCITY_RANGE.y[0] + Math.random() * (PARTICLE_VELOCITY_RANGE.y[1] - PARTICLE_VELOCITY_RANGE.y[0]);
} else if (effect === 2) {
p.size = random(2, 8);
p.drag = 0.92;
p.vx = random(-3, 3);
p.vy = random(-3, 3);
p.wander = 0.15;
p.theta = random(0, 360) * Math.PI / 180;
}
return p;
}
function effect1(particle) {
particle.vy += PARTICLE_GRAVITY;
particle.x += particle.vx;
particle.y += particle.vy;
particle.alpha *= PARTICLE_ALPHA_FADEOUT;
ctx.fillStyle = 'rgba(' + particle.color[0] + ',' + particle.color[1] + ',' + particle.color[2] + ',' + particle.alpha + ')';
ctx.fillRect(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, particle.size);
}
// Effect based on Soulwire's demo: http://codepen.io/soulwire/pen/foktm
function effect2(particle) {
particle.x += particle.vx;
particle.y += particle.vy;
particle.vx *= particle.drag;
particle.vy *= particle.drag;
particle.theta += random(-0.5, 0.5);
particle.vx += Math.sin(particle.theta) * 0.1;
particle.vy += Math.cos(particle.theta) * 0.1;
particle.size *= 0.96;
ctx.fillStyle = 'rgba(' + particle.color[0] + ',' + particle.color[1] + ',' + particle.color[2] + ',' + particle.alpha + ')';
ctx.beginPath();
ctx.arc(Math.round(particle.x - 1), Math.round(particle.y - 1), particle.size, 0, 2 * Math.PI);
ctx.fill();
}
function drawParticles(timeDelta) {
var particle;
for (var i = particles.length; i--;) {
particle = particles[i];
if (!particle || particle.alpha < 0.01 || particle.size <= 0.5) {
continue;
}
if (effect === 1) {
effect1(particle);
} else if (effect === 2) {
effect2(particle);
}
}
}
function shake(editor, time) {
cmNode = editor.getWrapperElement();
shakeTime = shakeTimeMax = time;
}
function random(min, max) {
if (!max) {
max = min;min = 0;
}
return min + ~~(Math.random() * (max - min + 1));
}
function throttle(callback, limit) {
var wait = false;
return function () {
if (!wait) {
callback.apply(this, arguments);
wait = true;
setTimeout(function () {
wait = false;
}, limit);
}
};
}
function loop() {
if (!isActive) {
return;
}
ctx.clearRect(0, 0, w, h);
// get the time past the previous frame
current_time = new Date().getTime();
if (!lastTime) lastTime = current_time;
dt = (current_time - lastTime) / 1000;
lastTime = current_time;
if (shakeTime > 0) {
shakeTime -= dt;
magnitude = shakeTime / shakeTimeMax * shakeIntensity;
shakeX = random(-magnitude, magnitude);
shakeY = random(-magnitude, magnitude);
cmNode.style.transform = 'translate(' + shakeX + 'px,' + shakeY + 'px)';
}
drawParticles();
requestAnimationFrame(loop);
}
function onCodeMirrorChange(editor, change) {
if (change.origin !== '+input' && change.origin !== '+delete') {
return;
}
if (editor.getOption('blastCode') === true || editor.getOption('blastCode').shake === undefined) {
throttledShake(editor, 0.3);
}
throttledSpawnParticles(editor);
}
function init(editor) {
isActive = true;
if (!canvas) {
canvas = document.createElement('canvas');
ctx = canvas.getContext('2d'), canvas.id = 'code-blast-canvas';
canvas.style.position = 'absolute';
canvas.style.top = 0;
canvas.style.left = 0;
canvas.style.zIndex = 1;
canvas.style.pointerEvents = 'none';
canvas.width = w;
canvas.height = h;
document.body.appendChild(canvas);
loop();
}
editor.on("change", onCodeMirrorChange);
}
function destroy(editor) {
editor.off('change', onCodeMirrorChange);
codemirrors.splice(codemirrors.indexOf(editor), 1);
if (!codemirrors.length) {
isActive = false;
if (canvas) {
canvas.remove();
canvas = null;
}
}
}
CodeMirror.defineOption('blastCode', false, function (editor, val, old) {
if (val) {
codemirrors.push(editor);
effect = val.effect || 2;
init(editor);
} else {
destroy(editor);
}
});
})();
/***/ }),
/***/ "BVSg":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
/**
* Tag-closer extension for CodeMirror.
*
* This extension adds an "autoCloseTags" option that can be set to
* either true to get the default behavior, or an object to further
* configure its behavior.
*
* These are supported options:
*
* `whenClosing` (default true)
* Whether to autoclose when the '/' of a closing tag is typed.
* `whenOpening` (default true)
* Whether to autoclose the tag when the final '>' of an opening
* tag is typed.
* `dontCloseTags` (default is empty tags for HTML, none for XML)
* An array of tag names that should not be autoclosed.
* `indentTags` (default is block tags for HTML, none for XML)
* An array of tag names that should, when opened, cause a
* blank line to be added inside the tag, and the blank line and
* closing line to be indented.
*
* See demos/closetag.html for a usage example.
*/
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("1JcR"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../fold/xml-fold"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
CodeMirror.defineOption("autoCloseTags", false, function (cm, val, old) {
if (old != CodeMirror.Init && old) cm.removeKeyMap("autoCloseTags");
if (!val) return;
var map = { name: "autoCloseTags" };
if (typeof val != "object" || val.whenClosing) map["'/'"] = function (cm) {
return autoCloseSlash(cm);
};
if (typeof val != "object" || val.whenOpening) map["'>'"] = function (cm) {
return autoCloseGT(cm);
};
cm.addKeyMap(map);
});
var htmlDontClose = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"];
var htmlIndent = ["applet", "blockquote", "body", "button", "div", "dl", "fieldset", "form", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "html", "iframe", "layer", "legend", "object", "ol", "p", "select", "table", "ul"];
function autoCloseGT(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections(),
replacements = [];
var opt = cm.getOption("autoCloseTags");
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var pos = ranges[i].head,
tok = cm.getTokenAt(pos);
var inner = CodeMirror.innerMode(cm.getMode(), tok.state),
state = inner.state;
if (inner.mode.name != "xml" || !state.tagName) return CodeMirror.Pass;
var html = inner.mode.configuration == "html";
var dontCloseTags = typeof opt == "object" && opt.dontCloseTags || html && htmlDontClose;
var indentTags = typeof opt == "object" && opt.indentTags || html && htmlIndent;
var tagName = state.tagName;
if (tok.end > pos.ch) tagName = tagName.slice(0, tagName.length - tok.end + pos.ch);
var lowerTagName = tagName.toLowerCase();
// Don't process the '>' at the end of an end-tag or self-closing tag
if (!tagName || tok.type == "string" && (tok.end != pos.ch || !/[\"\']/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1) || tok.type == "tag" && state.type == "closeTag" || tok.string.indexOf("/") == tok.string.length - 1 || // match something like <someTagName />
dontCloseTags && indexOf(dontCloseTags, lowerTagName) > -1 || closingTagExists(cm, tagName, pos, state, true)) return CodeMirror.Pass;
var indent = indentTags && indexOf(indentTags, lowerTagName) > -1;
replacements[i] = { indent: indent,
text: ">" + (indent ? "\n\n" : "") + "</" + tagName + ">",
newPos: indent ? CodeMirror.Pos(pos.line + 1, 0) : CodeMirror.Pos(pos.line, pos.ch + 1) };
}
var dontIndentOnAutoClose = typeof opt == "object" && opt.dontIndentOnAutoClose;
for (var i = ranges.length - 1; i >= 0; i--) {
var info = replacements[i];
cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, "+insert");
var sel = cm.listSelections().slice(0);
sel[i] = { head: info.newPos, anchor: info.newPos };
cm.setSelections(sel);
if (!dontIndentOnAutoClose && info.indent) {
cm.indentLine(info.newPos.line, null, true);
cm.indentLine(info.newPos.line + 1, null, true);
}
}
}
function autoCloseCurrent(cm, typingSlash) {
var ranges = cm.listSelections(),
replacements = [];
var head = typingSlash ? "/" : "</";
var opt = cm.getOption("autoCloseTags");
var dontIndentOnAutoClose = typeof opt == "object" && opt.dontIndentOnSlash;
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var pos = ranges[i].head,
tok = cm.getTokenAt(pos);
var inner = CodeMirror.innerMode(cm.getMode(), tok.state),
state = inner.state;
if (typingSlash && (tok.type == "string" || tok.string.charAt(0) != "<" || tok.start != pos.ch - 1)) return CodeMirror.Pass;
// Kludge to get around the fact that we are not in XML mode
// when completing in JS/CSS snippet in htmlmixed mode. Does not
// work for other XML embedded languages (there is no general
// way to go from a mixed mode to its current XML state).
var replacement;
if (inner.mode.name != "xml") {
if (cm.getMode().name == "htmlmixed" && inner.mode.name == "javascript") replacement = head + "script";else if (cm.getMode().name == "htmlmixed" && inner.mode.name == "css") replacement = head + "style";else return CodeMirror.Pass;
} else {
if (!state.context || !state.context.tagName || closingTagExists(cm, state.context.tagName, pos, state)) return CodeMirror.Pass;
replacement = head + state.context.tagName;
}
if (cm.getLine(pos.line).charAt(tok.end) != ">") replacement += ">";
replacements[i] = replacement;
}
cm.replaceSelections(replacements);
ranges = cm.listSelections();
if (!dontIndentOnAutoClose) {
for (var i = 0; i < ranges.length; i++) if (i == ranges.length - 1 || ranges[i].head.line < ranges[i + 1].head.line) cm.indentLine(ranges[i].head.line);
}
}
function autoCloseSlash(cm) {
if (cm.getOption("disableInput")) return CodeMirror.Pass;
return autoCloseCurrent(cm, true);
}
CodeMirror.commands.closeTag = function (cm) {
return autoCloseCurrent(cm);
};
function indexOf(collection, elt) {
if (collection.indexOf) return collection.indexOf(elt);
for (var i = 0, e = collection.length; i < e; ++i) if (collection[i] == elt) return i;
return -1;
}
// If xml-fold is loaded, we use its functionality to try and verify
// whether a given tag is actually unclosed.
function closingTagExists(cm, tagName, pos, state, newTag) {
if (!CodeMirror.scanForClosingTag) return false;
var end = Math.min(cm.lastLine() + 1, pos.line + 500);
var nextClose = CodeMirror.scanForClosingTag(cm, pos, null, end);
if (!nextClose || nextClose.tag != tagName) return false;
var cx = state.context;
// If the immediate wrapping context contains onCx instances of
// the same tag, a closing tag only exists if there are at least
// that many closing tags of that type following.
for (var onCx = newTag ? 1 : 0; cx && cx.tagName == tagName; cx = cx.prev) ++onCx;
pos = nextClose.to;
for (var i = 1; i < onCx; i++) {
var next = CodeMirror.scanForClosingTag(cm, pos, null, end);
if (!next || next.tag != tagName) return false;
pos = next.to;
}
return true;
}
});
/***/ }),
/***/ "BtxX":
/***/ (function(module, exports) {
(function (root) {
// Store setTimeout reference so promise-polyfill will be unaffected by
// other code modifying setTimeout (like sinon.useFakeTimers())
var setTimeoutFunc = setTimeout;
function noop() {}
// Polyfill for Function.prototype.bind
function bind(fn, thisArg) {
return function () {
fn.apply(thisArg, arguments);
};
}
function Promise(fn) {
if (!(this instanceof Promise)) throw new TypeError('Promises must be constructed via new');
if (typeof fn !== 'function') throw new TypeError('not a function');
this._state = 0;
this._handled = false;
this._value = undefined;
this._deferreds = [];
doResolve(fn, this);
}
function handle(self, deferred) {
while (self._state === 3) {
self = self._value;
}
if (self._state === 0) {
self._deferreds.push(deferred);
return;
}
self._handled = true;
Promise._immediateFn(function () {
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
if (cb === null) {
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
return;
}
var ret;
try {
ret = cb(self._value);
} catch (e) {
reject(deferred.promise, e);
return;
}
resolve(deferred.promise, ret);
});
}
function resolve(self, newValue) {
try {
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.');
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
var then = newValue.then;
if (newValue instanceof Promise) {
self._state = 3;
self._value = newValue;
finale(self);
return;
} else if (typeof then === 'function') {
doResolve(bind(then, newValue), self);
return;
}
}
self._state = 1;
self._value = newValue;
finale(self);
} catch (e) {
reject(self, e);
}
}
function reject(self, newValue) {
self._state = 2;
self._value = newValue;
finale(self);
}
function finale(self) {
if (self._state === 2 && self._deferreds.length === 0) {
Promise._immediateFn(function () {
if (!self._handled) {
Promise._unhandledRejectionFn(self._value);
}
});
}
for (var i = 0, len = self._deferreds.length; i < len; i++) {
handle(self, self._deferreds[i]);
}
self._deferreds = null;
}
function Handler(onFulfilled, onRejected, promise) {
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
this.promise = promise;
}
/**
* Take a potentially misbehaving resolver function and make sure
* onFulfilled and onRejected are only called once.
*
* Makes no guarantees about asynchrony.
*/
function doResolve(fn, self) {
var done = false;
try {
fn(function (value) {
if (done) return;
done = true;
resolve(self, value);
}, function (reason) {
if (done) return;
done = true;
reject(self, reason);
});
} catch (ex) {
if (done) return;
done = true;
reject(self, ex);
}
}
Promise.prototype['catch'] = function (onRejected) {
return this.then(null, onRejected);
};
Promise.prototype.then = function (onFulfilled, onRejected) {
var prom = new this.constructor(noop);
handle(this, new Handler(onFulfilled, onRejected, prom));
return prom;
};
Promise.all = function (arr) {
return new Promise(function (resolve, reject) {
if (!arr || typeof arr.length === 'undefined') throw new TypeError('Promise.all accepts an array');
var args = Array.prototype.slice.call(arr);
if (args.length === 0) return resolve([]);
var remaining = args.length;
function res(i, val) {
try {
if (val && (typeof val === 'object' || typeof val === 'function')) {
var then = val.then;
if (typeof then === 'function') {
then.call(val, function (val) {
res(i, val);
}, reject);
return;
}
}
args[i] = val;
if (--remaining === 0) {
resolve(args);
}
} catch (ex) {
reject(ex);
}
}
for (var i = 0; i < args.length; i++) {
res(i, args[i]);
}
});
};
Promise.resolve = function (value) {
if (value && typeof value === 'object' && value.constructor === Promise) {
return value;
}
return new Promise(function (resolve) {
resolve(value);
});
};
Promise.reject = function (value) {
return new Promise(function (resolve, reject) {
reject(value);
});
};
Promise.race = function (values) {
return new Promise(function (resolve, reject) {
for (var i = 0, len = values.length; i < len; i++) {
values[i].then(resolve, reject);
}
});
};
// Use polyfill for setImmediate for performance gains
Promise._immediateFn = typeof setImmediate === 'function' && function (fn) {
setImmediate(fn);
} || function (fn) {
setTimeoutFunc(fn, 0);
};
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
if (typeof console !== 'undefined' && console) {
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
}
};
/**
* Set the immediate function to execute callbacks
* @param fn {function} Function to execute
* @deprecated
*/
Promise._setImmediateFn = function _setImmediateFn(fn) {
Promise._immediateFn = fn;
};
/**
* Change the function to execute on unhandled rejection
* @param {function} fn Function to execute on unhandled rejection
* @deprecated
*/
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
Promise._unhandledRejectionFn = fn;
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = Promise;
} else if (!root.Promise) {
root.Promise = Promise;
}
})(this);
/***/ }),
/***/ "H+g/":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
function doFold(cm, pos, options, force) {
if (options && options.call) {
var finder = options;
options = null;
} else {
var finder = getOption(cm, options, "rangeFinder");
}
if (typeof pos == "number") pos = CodeMirror.Pos(pos, 0);
var minSize = getOption(cm, options, "minFoldSize");
function getRange(allowFolded) {
var range = finder(cm, pos);
if (!range || range.to.line - range.from.line < minSize) return null;
var marks = cm.findMarksAt(range.from);
for (var i = 0; i < marks.length; ++i) {
if (marks[i].__isFold && force !== "fold") {
if (!allowFolded) return null;
range.cleared = true;
marks[i].clear();
}
}
return range;
}
var range = getRange(true);
if (getOption(cm, options, "scanUp")) while (!range && pos.line > cm.firstLine()) {
pos = CodeMirror.Pos(pos.line - 1, 0);
range = getRange(false);
}
if (!range || range.cleared || force === "unfold") return;
var myWidget = makeWidget(cm, options);
CodeMirror.on(myWidget, "mousedown", function (e) {
myRange.clear();
CodeMirror.e_preventDefault(e);
});
var myRange = cm.markText(range.from, range.to, {
replacedWith: myWidget,
clearOnEnter: getOption(cm, options, "clearOnEnter"),
__isFold: true
});
myRange.on("clear", function (from, to) {
CodeMirror.signal(cm, "unfold", cm, from, to);
});
CodeMirror.signal(cm, "fold", cm, range.from, range.to);
}
function makeWidget(cm, options) {
var widget = getOption(cm, options, "widget");
if (typeof widget == "string") {
var text = document.createTextNode(widget);
widget = document.createElement("span");
widget.appendChild(text);
widget.className = "CodeMirror-foldmarker";
} else if (widget) {
widget = widget.cloneNode(true);
}
return widget;
}
// Clumsy backwards-compatible interface
CodeMirror.newFoldFunction = function (rangeFinder, widget) {
return function (cm, pos) {
doFold(cm, pos, { rangeFinder: rangeFinder, widget: widget });
};
};
// New-style interface
CodeMirror.defineExtension("foldCode", function (pos, options, force) {
doFold(this, pos, options, force);
});
CodeMirror.defineExtension("isFolded", function (pos) {
var marks = this.findMarksAt(pos);
for (var i = 0; i < marks.length; ++i) if (marks[i].__isFold) return true;
});
CodeMirror.commands.toggleFold = function (cm) {
cm.foldCode(cm.getCursor());
};
CodeMirror.commands.fold = function (cm) {
cm.foldCode(cm.getCursor(), null, "fold");
};
CodeMirror.commands.unfold = function (cm) {
cm.foldCode(cm.getCursor(), null, "unfold");
};
CodeMirror.commands.foldAll = function (cm) {
cm.operation(function () {
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++) cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
});
};
CodeMirror.commands.unfoldAll = function (cm) {
cm.operation(function () {
for (var i = cm.firstLine(), e = cm.lastLine(); i <= e; i++) cm.foldCode(CodeMirror.Pos(i, 0), null, "unfold");
});
};
CodeMirror.registerHelper("fold", "combine", function () {
var funcs = Array.prototype.slice.call(arguments, 0);
return function (cm, start) {
for (var i = 0; i < funcs.length; ++i) {
var found = funcs[i](cm, start);
if (found) return found;
}
};
});
CodeMirror.registerHelper("fold", "auto", function (cm, start) {
var helpers = cm.getHelpers(start, "fold");
for (var i = 0; i < helpers.length; i++) {
var cur = helpers[i](cm, start);
if (cur) return cur;
}
});
var defaultOptions = {
rangeFinder: CodeMirror.fold.auto,
widget: "\u2194",
minFoldSize: 0,
scanUp: false,
clearOnEnter: true
};
CodeMirror.defineOption("foldOptions", null);
function getOption(cm, options, name) {
if (options && options[name] !== undefined) return options[name];
var editorOptions = cm.options.foldOptions;
if (editorOptions && editorOptions[name] !== undefined) return editorOptions[name];
return defaultOptions[name];
}
CodeMirror.defineExtension("foldOption", function (options, name) {
return getOption(this, options, name);
});
});
/***/ }),
/***/ "HeB0":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var htmlConfig = {
autoSelfClosers: { 'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
'track': true, 'wbr': true, 'menuitem': true },
implicitlyClosed: { 'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
'th': true, 'tr': true },
contextGrabbers: {
'dd': { 'dd': true, 'dt': true },
'dt': { 'dd': true, 'dt': true },
'li': { 'li': true },
'option': { 'option': true, 'optgroup': true },
'optgroup': { 'optgroup': true },
'p': { 'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true },
'rp': { 'rp': true, 'rt': true },
'rt': { 'rp': true, 'rt': true },
'tbody': { 'tbody': true, 'tfoot': true },
'td': { 'td': true, 'th': true },
'tfoot': { 'tbody': true },
'th': { 'td': true, 'th': true },
'thead': { 'tbody': true, 'tfoot': true },
'tr': { 'tr': true }
},
doNotIndent: { "pre": true },
allowUnquoted: true,
allowMissing: true,
caseFold: true
};
var xmlConfig = {
autoSelfClosers: {},
implicitlyClosed: {},
contextGrabbers: {},
doNotIndent: {},
allowUnquoted: false,
allowMissing: false,
allowMissingTagName: false,
caseFold: false
};
CodeMirror.defineMode("xml", function (editorConf, config_) {
var indentUnit = editorConf.indentUnit;
var config = {};
var defaults = config_.htmlMode ? htmlConfig : xmlConfig;
for (var prop in defaults) config[prop] = defaults[prop];
for (var prop in config_) config[prop] = config_[prop];
// Return variables for tokenizers
var type, setStyle;
function inText(stream, state) {
function chain(parser) {
state.tokenize = parser;
return parser(stream, state);
}
var ch = stream.next();
if (ch == "<") {
if (stream.eat("!")) {
if (stream.eat("[")) {
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));else return null;
} else if (stream.match("--")) {
return chain(inBlock("comment", "-->"));
} else if (stream.match("DOCTYPE", true, true)) {
stream.eatWhile(/[\w\._\-]/);
return chain(doctype(1));
} else {
return null;
}
} else if (stream.eat("?")) {
stream.eatWhile(/[\w\._\-]/);
state.tokenize = inBlock("meta", "?>");
return "meta";
} else {
type = stream.eat("/") ? "closeTag" : "openTag";
state.tokenize = inTag;
return "tag bracket";
}
} else if (ch == "&") {
var ok;
if (stream.eat("#")) {
if (stream.eat("x")) {
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
} else {
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
}
} else {
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
}
return ok ? "atom" : "error";
} else {
stream.eatWhile(/[^&<]/);
return null;
}
}
inText.isInText = true;
function inTag(stream, state) {
var ch = stream.next();
if (ch == ">" || ch == "/" && stream.eat(">")) {
state.tokenize = inText;
type = ch == ">" ? "endTag" : "selfcloseTag";
return "tag bracket";
} else if (ch == "=") {
type = "equals";
return null;
} else if (ch == "<") {
state.tokenize = inText;
state.state = baseState;
state.tagName = state.tagStart = null;
var next = state.tokenize(stream, state);
return next ? next + " tag error" : "tag error";
} else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch);
state.stringStartCol = stream.column();
return state.tokenize(stream, state);
} else {
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
return "word";
}
}
function inAttribute(quote) {
var closure = function (stream, state) {
while (!stream.eol()) {
if (stream.next() == quote) {
state.tokenize = inTag;
break;
}
}
return "string";
};
closure.isInAttribute = true;
return closure;
}
function inBlock(style, terminator) {
return function (stream, state) {
while (!stream.eol()) {
if (stream.match(terminator)) {
state.tokenize = inText;
break;
}
stream.next();
}
return style;
};
}
function doctype(depth) {
return function (stream, state) {
var ch;
while ((ch = stream.next()) != null) {
if (ch == "<") {
state.tokenize = doctype(depth + 1);
return state.tokenize(stream, state);
} else if (ch == ">") {
if (depth == 1) {
state.tokenize = inText;
break;
} else {
state.tokenize = doctype(depth - 1);
return state.tokenize(stream, state);
}
}
}
return "meta";
};
}
function Context(state, tagName, startOfLine) {
this.prev = state.context;
this.tagName = tagName;
this.indent = state.indented;
this.startOfLine = startOfLine;
if (config.doNotIndent.hasOwnProperty(tagName) || state.context && state.context.noIndent) this.noIndent = true;
}
function popContext(state) {
if (state.context) state.context = state.context.prev;
}
function maybePopContext(state, nextTagName) {
var parentTagName;
while (true) {
if (!state.context) {
return;
}
parentTagName = state.context.tagName;
if (!config.contextGrabbers.hasOwnProperty(parentTagName) || !config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
return;
}
popContext(state);
}
}
function baseState(type, stream, state) {
if (type == "openTag") {
state.tagStart = stream.column();
return tagNameState;
} else if (type == "closeTag") {
return closeTagNameState;
} else {
return baseState;
}
}
function tagNameState(type, stream, state) {
if (type == "word") {
state.tagName = stream.current();
setStyle = "tag";
return attrState;
} else if (config.allowMissingTagName && type == "endTag") {
setStyle = "tag bracket";
return attrState(type, stream, state);
} else {
setStyle = "error";
return tagNameState;
}
}
function closeTagNameState(type, stream, state) {
if (type == "word") {
var tagName = stream.current();
if (state.context && state.context.tagName != tagName && config.implicitlyClosed.hasOwnProperty(state.context.tagName)) popContext(state);
if (state.context && state.context.tagName == tagName || config.matchClosing === false) {
setStyle = "tag";
return closeState;
} else {
setStyle = "tag error";
return closeStateErr;
}
} else if (config.allowMissingTagName && type == "endTag") {
setStyle = "tag bracket";
return closeState(type, stream, state);
} else {
setStyle = "error";
return closeStateErr;
}
}
function closeState(type, _stream, state) {
if (type != "endTag") {
setStyle = "error";
return closeState;
}
popContext(state);
return baseState;
}
function closeStateErr(type, stream, state) {
setStyle = "error";
return closeState(type, stream, state);
}
function attrState(type, _stream, state) {
if (type == "word") {
setStyle = "attribute";
return attrEqState;
} else if (type == "endTag" || type == "selfcloseTag") {
var tagName = state.tagName,
tagStart = state.tagStart;
state.tagName = state.tagStart = null;
if (type == "selfcloseTag" || config.autoSelfClosers.hasOwnProperty(tagName)) {
maybePopContext(state, tagName);
} else {
maybePopContext(state, tagName);
state.context = new Context(state, tagName, tagStart == state.indented);
}
return baseState;
}
setStyle = "error";
return attrState;
}
function attrEqState(type, stream, state) {
if (type == "equals") return attrValueState;
if (!config.allowMissing) setStyle = "error";
return attrState(type, stream, state);
}
function attrValueState(type, stream, state) {
if (type == "string") return attrContinuedState;
if (type == "word" && config.allowUnquoted) {
setStyle = "string";return attrState;
}
setStyle = "error";
return attrState(type, stream, state);
}
function attrContinuedState(type, stream, state) {
if (type == "string") return attrContinuedState;
return attrState(type, stream, state);
}
return {
startState: function (baseIndent) {
var state = { tokenize: inText,
state: baseState,
indented: baseIndent || 0,
tagName: null, tagStart: null,
context: null };
if (baseIndent != null) state.baseIndent = baseIndent;
return state;
},
token: function (stream, state) {
if (!state.tagName && stream.sol()) state.indented = stream.indentation();
if (stream.eatSpace()) return null;
type = null;
var style = state.tokenize(stream, state);
if ((style || type) && style != "comment") {
setStyle = null;
state.state = state.state(type || style, stream, state);
if (setStyle) style = setStyle == "error" ? style + " error" : setStyle;
}
return style;
},
indent: function (state, textAfter, fullLine) {
var context = state.context;
// Indent multi-line strings (e.g. css).
if (state.tokenize.isInAttribute) {
if (state.tagStart == state.indented) return state.stringStartCol + 1;else return state.indented + indentUnit;
}
if (context && context.noIndent) return CodeMirror.Pass;
if (state.tokenize != inTag && state.tokenize != inText) return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
// Indent the starts of attribute names.
if (state.tagName) {
if (config.multilineTagIndentPastTag !== false) return state.tagStart + state.tagName.length + 2;else return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);
}
if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
if (tagAfter && tagAfter[1]) {
// Closing tag spotted
while (context) {
if (context.tagName == tagAfter[2]) {
context = context.prev;
break;
} else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) {
context = context.prev;
} else {
break;
}
}
} else if (tagAfter) {
// Opening tag spotted
while (context) {
var grabbers = config.contextGrabbers[context.tagName];
if (grabbers && grabbers.hasOwnProperty(tagAfter[2])) context = context.prev;else break;
}
}
while (context && context.prev && !context.startOfLine) context = context.prev;
if (context) return context.indent + indentUnit;else return state.baseIndent || 0;
},
electricInput: /<\/[\s\w:]+>$/,
blockCommentStart: "<!--",
blockCommentEnd: "-->",
configuration: config.htmlMode ? "html" : "xml",
helperType: config.htmlMode ? "html" : "xml",
skipAttribute: function (state) {
if (state.state == attrValueState) state.state = attrState;
}
};
});
CodeMirror.defineMIME("text/xml", "xml");
CodeMirror.defineMIME("application/xml", "xml");
if (!CodeMirror.mimeModes.hasOwnProperty("text/html")) CodeMirror.defineMIME("text/html", { name: "xml", htmlMode: true });
});
/***/ }),
/***/ "IIoC":
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {(function () {
var g,
goog = goog || {},
k = this;function l(a) {
return "string" == typeof a;
}function n(a, b) {
a = a.split(".");b = b || k;for (var c = 0; c < a.length; c++) if (b = b[a[c]], null == b) return null;return b;
}function aa() {}
function ba(a) {
var b = typeof a;if ("object" == b) {
if (a) {
if (a instanceof Array) return "array";if (a instanceof Object) return b;var c = Object.prototype.toString.call(a);if ("[object Window]" == c) return "object";if ("[object Array]" == c || "number" == typeof a.length && "undefined" != typeof a.splice && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("splice")) return "array";if ("[object Function]" == c || "undefined" != typeof a.call && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("call")) return "function";
} else return "null";
} else if ("function" == b && "undefined" == typeof a.call) return "object";return b;
}function p(a) {
return "array" == ba(a);
}function ca(a) {
var b = ba(a);return "array" == b || "object" == b && "number" == typeof a.length;
}function da(a) {
return "function" == ba(a);
}function ea(a) {
var b = typeof a;return "object" == b && null != a || "function" == b;
}var q = "closure_uid_" + (1E9 * Math.random() >>> 0),
fa = 0;function ha(a, b, c) {
return a.call.apply(a.bind, arguments);
}
function ia(a, b, c) {
if (!a) throw Error();if (2 < arguments.length) {
var d = Array.prototype.slice.call(arguments, 2);return function () {
var c = Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c, d);return a.apply(b, c);
};
}return function () {
return a.apply(b, arguments);
};
}function r(a, b, c) {
Function.prototype.bind && -1 != Function.prototype.bind.toString().indexOf("native code") ? r = ha : r = ia;return r.apply(null, arguments);
}
function ja(a, b) {
var c = Array.prototype.slice.call(arguments, 1);return function () {
var b = c.slice();b.push.apply(b, arguments);return a.apply(this, b);
};
}var t = Date.now || function () {
return +new Date();
};function u(a, b) {
function c() {}c.prototype = b.prototype;a.H = b.prototype;a.prototype = new c();a.prototype.constructor = a;a.Ib = function (a, c, f) {
for (var d = Array(arguments.length - 2), e = 2; e < arguments.length; e++) d[e - 2] = arguments[e];return b.prototype[c].apply(a, d);
};
};function ka(a) {
if (Error.captureStackTrace) Error.captureStackTrace(this, ka);else {
var b = Error().stack;b && (this.stack = b);
}a && (this.message = String(a));
}u(ka, Error);ka.prototype.name = "CustomError";function la(a, b) {
a = a.split("%s");for (var c = "", d = a.length - 1, e = 0; e < d; e++) c += a[e] + (e < b.length ? b[e] : "%s");ka.call(this, c + a[d]);
}u(la, ka);la.prototype.name = "AssertionError";function ma(a, b) {
throw new la("Failure" + (a ? ": " + a : ""), Array.prototype.slice.call(arguments, 1));
};function w() {
0 != na && (pa[this[q] || (this[q] = ++fa)] = this);this.i = this.i;this.m = this.m;
}var na = 0,
pa = {};w.prototype.i = !1;w.prototype.$ = function () {
if (!this.i && (this.i = !0, this.w(), 0 != na)) {
var a = this[q] || (this[q] = ++fa);if (0 != na && this.m && 0 < this.m.length) throw Error(this + " did not empty its onDisposeCallbacks queue. This probably means it overrode dispose() or disposeInternal() without calling the superclass' method.");delete pa[a];
}
};w.prototype.w = function () {
if (this.m) for (; this.m.length;) this.m.shift()();
};var qa = Array.prototype.indexOf ? function (a, b) {
return Array.prototype.indexOf.call(a, b, void 0);
} : function (a, b) {
if (l(a)) return l(b) && 1 == b.length ? a.indexOf(b, 0) : -1;for (var c = 0; c < a.length; c++) if (c in a && a[c] === b) return c;return -1;
},
ra = Array.prototype.forEach ? function (a, b, c) {
Array.prototype.forEach.call(a, b, c);
} : function (a, b, c) {
for (var d = a.length, e = l(a) ? a.split("") : a, f = 0; f < d; f++) f in e && b.call(c, e[f], f, a);
};
function sa(a) {
a: {
var b = ta;for (var c = a.length, d = l(a) ? a.split("") : a, e = 0; e < c; e++) if (e in d && b.call(void 0, d[e], e, a)) {
b = e;break a;
}b = -1;
}return 0 > b ? null : l(a) ? a.charAt(b) : a[b];
}function ua(a) {
if (!p(a)) for (var b = a.length - 1; 0 <= b; b--) delete a[b];a.length = 0;
}function va(a) {
return Array.prototype.concat.apply([], arguments);
}function wa(a) {
var b = a.length;if (0 < b) {
for (var c = Array(b), d = 0; d < b; d++) c[d] = a[d];return c;
}return [];
};function xa(a) {
return (/^[\s\xa0]*$/.test(a)
);
}var ya = String.prototype.trim ? function (a) {
return a.trim();
} : function (a) {
return (/^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(a)[1]
);
};function za(a, b) {
return a < b ? -1 : a > b ? 1 : 0;
};var x;a: {
var Aa = k.navigator;if (Aa) {
var Ba = Aa.userAgent;if (Ba) {
x = Ba;break a;
}
}x = "";
}function y(a) {
return -1 != x.indexOf(a);
};function Ca(a, b, c) {
for (var d in a) b.call(c, a[d], d, a);
}function Da(a) {
var b = [],
c = 0,
d;for (d in a) b[c++] = a[d];return b;
}function Ea(a) {
var b = [],
c = 0,
d;for (d in a) b[c++] = d;return b;
}function Fa(a) {
var b = {},
c;for (c in a) b[c] = a[c];return b;
}var Ga = "constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");
function Ha(a, b) {
for (var c, d, e = 1; e < arguments.length; e++) {
d = arguments[e];for (c in d) a[c] = d[c];for (var f = 0; f < Ga.length; f++) c = Ga[f], Object.prototype.hasOwnProperty.call(d, c) && (a[c] = d[c]);
}
};function Ia(a) {
Ia[" "](a);return a;
}Ia[" "] = aa;function Ja(a, b) {
var c = Ka;return Object.prototype.hasOwnProperty.call(c, a) ? c[a] : c[a] = b(a);
};var La = y("Opera"),
z = y("Trident") || y("MSIE"),
Ma = y("Edge"),
Na = Ma || z,
Oa = y("Gecko") && !(-1 != x.toLowerCase().indexOf("webkit") && !y("Edge")) && !(y("Trident") || y("MSIE")) && !y("Edge"),
Pa = -1 != x.toLowerCase().indexOf("webkit") && !y("Edge");function Qa() {
var a = k.document;return a ? a.documentMode : void 0;
}var Ra;
a: {
var Sa = "",
Ta = function () {
var a = x;if (Oa) return (/rv:([^\);]+)(\)|;)/.exec(a)
);if (Ma) return (/Edge\/([\d\.]+)/.exec(a)
);if (z) return (/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(a)
);if (Pa) return (/WebKit\/(\S+)/.exec(a)
);if (La) return (/(?:Version)[ \/]?(\S+)/.exec(a)
);
}();Ta && (Sa = Ta ? Ta[1] : "");if (z) {
var Ua = Qa();if (null != Ua && Ua > parseFloat(Sa)) {
Ra = String(Ua);break a;
}
}Ra = Sa;
}var Ka = {};
function Va(a) {
return Ja(a, function () {
for (var b = 0, c = ya(String(Ra)).split("."), d = ya(String(a)).split("."), e = Math.max(c.length, d.length), f = 0; 0 == b && f < e; f++) {
var h = c[f] || "",
m = d[f] || "";do {
h = /(\d*)(\D*)(.*)/.exec(h) || ["", "", "", ""];m = /(\d*)(\D*)(.*)/.exec(m) || ["", "", "", ""];if (0 == h[0].length && 0 == m[0].length) break;b = za(0 == h[1].length ? 0 : parseInt(h[1], 10), 0 == m[1].length ? 0 : parseInt(m[1], 10)) || za(0 == h[2].length, 0 == m[2].length) || za(h[2], m[2]);h = h[3];m = m[3];
} while (0 == b);
}return 0 <= b;
});
}var Wa;var Xa = k.document;
Wa = Xa && z ? Qa() || ("CSS1Compat" == Xa.compatMode ? parseInt(Ra, 10) : 5) : void 0;var Ya = Object.freeze || function (a) {
return a;
};var Za = !z || 9 <= Number(Wa),
$a = z && !Va("9"),
ab = function () {
if (!k.addEventListener || !Object.defineProperty) return !1;var a = !1,
b = Object.defineProperty({}, "passive", { get: function () {
a = !0;
} });k.addEventListener("test", aa, b);k.removeEventListener("test", aa, b);return a;
}();function A(a, b) {
this.type = a;this.a = this.target = b;this.Ra = !0;
}A.prototype.b = function () {
this.Ra = !1;
};function bb(a, b) {
A.call(this, a ? a.type : "");this.relatedTarget = this.a = this.target = null;this.button = this.screenY = this.screenX = this.clientY = this.clientX = 0;this.key = "";this.metaKey = this.shiftKey = this.altKey = this.ctrlKey = !1;this.pointerId = 0;this.pointerType = "";this.c = null;if (a) {
var c = this.type = a.type,
d = a.changedTouches ? a.changedTouches[0] : null;this.target = a.target || a.srcElement;this.a = b;if (b = a.relatedTarget) {
if (Oa) {
a: {
try {
Ia(b.nodeName);var e = !0;break a;
} catch (f) {}e = !1;
}e || (b = null);
}
} else "mouseover" == c ? b = a.fromElement : "mouseout" == c && (b = a.toElement);this.relatedTarget = b;null === d ? (this.clientX = void 0 !== a.clientX ? a.clientX : a.pageX, this.clientY = void 0 !== a.clientY ? a.clientY : a.pageY, this.screenX = a.screenX || 0, this.screenY = a.screenY || 0) : (this.clientX = void 0 !== d.clientX ? d.clientX : d.pageX, this.clientY = void 0 !== d.clientY ? d.clientY : d.pageY, this.screenX = d.screenX || 0, this.screenY = d.screenY || 0);this.button = a.button;this.key = a.key || "";this.ctrlKey = a.ctrlKey;this.altKey = a.altKey;this.shiftKey = a.shiftKey;this.metaKey = a.metaKey;this.pointerId = a.pointerId || 0;this.pointerType = l(a.pointerType) ? a.pointerType : cb[a.pointerType] || "";this.c = a;a.defaultPrevented && this.b();
}
}u(bb, A);var cb = Ya({ 2: "touch", 3: "pen", 4: "mouse" });bb.prototype.b = function () {
bb.H.b.call(this);var a = this.c;if (a.preventDefault) a.preventDefault();else if (a.returnValue = !1, $a) try {
if (a.ctrlKey || 112 <= a.keyCode && 123 >= a.keyCode) a.keyCode = -1;
} catch (b) {}
};var db = "closure_listenable_" + (1E6 * Math.random() | 0),
eb = 0;function fb(a, b, c, d, e) {
this.listener = a;this.proxy = null;this.src = b;this.type = c;this.capture = !!d;this.ga = e;this.key = ++eb;this.Z = this.ba = !1;
}function gb(a) {
a.Z = !0;a.listener = null;a.proxy = null;a.src = null;a.ga = null;
};function hb(a) {
this.src = a;this.a = {};this.b = 0;
}hb.prototype.add = function (a, b, c, d, e) {
var f = a.toString();a = this.a[f];a || (a = this.a[f] = [], this.b++);var h = ib(a, b, d, e);-1 < h ? (b = a[h], c || (b.ba = !1)) : (b = new fb(b, this.src, f, !!d, e), b.ba = c, a.push(b));return b;
};function jb(a, b) {
var c = b.type;if (c in a.a) {
var d = a.a[c],
e = qa(d, b),
f;(f = 0 <= e) && Array.prototype.splice.call(d, e, 1);f && (gb(b), 0 == a.a[c].length && (delete a.a[c], a.b--));
}
}
function ib(a, b, c, d) {
for (var e = 0; e < a.length; ++e) {
var f = a[e];if (!f.Z && f.listener == b && f.capture == !!c && f.ga == d) return e;
}return -1;
};var kb = "closure_lm_" + (1E6 * Math.random() | 0),
lb = {},
mb = 0;function nb(a, b, c, d, e) {
if (d && d.once) return ob(a, b, c, d, e);if (p(b)) {
for (var f = 0; f < b.length; f++) nb(a, b[f], c, d, e);return null;
}c = pb(c);return a && a[db] ? a.Ia(b, c, ea(d) ? !!d.capture : !!d, e) : qb(a, b, c, !1, d, e);
}
function qb(a, b, c, d, e, f) {
if (!b) throw Error("Invalid event type");var h = ea(e) ? !!e.capture : !!e,
m = rb(a);m || (a[kb] = m = new hb(a));c = m.add(b, c, d, h, f);if (c.proxy) return c;d = sb();c.proxy = d;d.src = a;d.listener = c;if (a.addEventListener) ab || (e = h), void 0 === e && (e = !1), a.addEventListener(b.toString(), d, e);else if (a.attachEvent) a.attachEvent(tb(b.toString()), d);else if (a.addListener && a.removeListener) a.addListener(d);else throw Error("addEventListener and attachEvent are unavailable.");mb++;return c;
}
function sb() {
var a = ub,
b = Za ? function (c) {
return a.call(b.src, b.listener, c);
} : function (c) {
c = a.call(b.src, b.listener, c);if (!c) return c;
};return b;
}function ob(a, b, c, d, e) {
if (p(b)) {
for (var f = 0; f < b.length; f++) ob(a, b[f], c, d, e);return null;
}c = pb(c);return a && a[db] ? a.Ja(b, c, ea(d) ? !!d.capture : !!d, e) : qb(a, b, c, !0, d, e);
}
function vb(a, b, c, d, e) {
if (p(b)) for (var f = 0; f < b.length; f++) vb(a, b[f], c, d, e);else (d = ea(d) ? !!d.capture : !!d, c = pb(c), a && a[db]) ? (a = a.f, b = String(b).toString(), b in a.a && (f = a.a[b], c = ib(f, c, d, e), -1 < c && (gb(f[c]), Array.prototype.splice.call(f, c, 1), 0 == f.length && (delete a.a[b], a.b--)))) : a && (a = rb(a)) && (b = a.a[b.toString()], a = -1, b && (a = ib(b, c, d, e)), (c = -1 < a ? b[a] : null) && wb(c));
}
function wb(a) {
if ("number" != typeof a && a && !a.Z) {
var b = a.src;if (b && b[db]) jb(b.f, a);else {
var c = a.type,
d = a.proxy;b.removeEventListener ? b.removeEventListener(c, d, a.capture) : b.detachEvent ? b.detachEvent(tb(c), d) : b.addListener && b.removeListener && b.removeListener(d);mb--;(c = rb(b)) ? (jb(c, a), 0 == c.b && (c.src = null, b[kb] = null)) : gb(a);
}
}
}function tb(a) {
return a in lb ? lb[a] : lb[a] = "on" + a;
}
function xb(a, b, c, d) {
var e = !0;if (a = rb(a)) if (b = a.a[b.toString()]) for (b = b.concat(), a = 0; a < b.length; a++) {
var f = b[a];f && f.capture == c && !f.Z && (f = yb(f, d), e = e && !1 !== f);
}return e;
}function yb(a, b) {
var c = a.listener,
d = a.ga || a.src;a.ba && wb(a);return c.call(d, b);
}
function ub(a, b) {
if (a.Z) return !0;if (!Za) {
var c = b || n("window.event");b = new bb(c, this);var d = !0;if (!(0 > c.keyCode || void 0 != c.returnValue)) {
a: {
var e = !1;if (0 == c.keyCode) try {
c.keyCode = -1;break a;
} catch (h) {
e = !0;
}if (e || void 0 == c.returnValue) c.returnValue = !0;
}c = [];for (e = b.a; e; e = e.parentNode) c.push(e);a = a.type;for (e = c.length - 1; 0 <= e; e--) {
b.a = c[e];var f = xb(c[e], a, !0, b);d = d && f;
}for (e = 0; e < c.length; e++) b.a = c[e], f = xb(c[e], a, !1, b), d = d && f;
}return d;
}return yb(a, new bb(b, this));
}
function rb(a) {
a = a[kb];return a instanceof hb ? a : null;
}var zb = "__closure_events_fn_" + (1E9 * Math.random() >>> 0);function pb(a) {
if (da(a)) return a;a[zb] || (a[zb] = function (b) {
return a.handleEvent(b);
});return a[zb];
};function B() {
w.call(this);this.f = new hb(this);this.N = this;this.J = null;
}u(B, w);B.prototype[db] = !0;g = B.prototype;g.addEventListener = function (a, b, c, d) {
nb(this, a, b, c, d);
};g.removeEventListener = function (a, b, c, d) {
vb(this, a, b, c, d);
};
g.dispatchEvent = function (a) {
var b,
c = this.J;if (c) for (b = []; c; c = c.J) b.push(c);c = this.N;var d = a.type || a;if (l(a)) a = new A(a, c);else if (a instanceof A) a.target = a.target || c;else {
var e = a;a = new A(d, c);Ha(a, e);
}e = !0;if (b) for (var f = b.length - 1; 0 <= f; f--) {
var h = a.a = b[f];e = Ab(h, d, !0, a) && e;
}h = a.a = c;e = Ab(h, d, !0, a) && e;e = Ab(h, d, !1, a) && e;if (b) for (f = 0; f < b.length; f++) h = a.a = b[f], e = Ab(h, d, !1, a) && e;return e;
};
g.w = function () {
B.H.w.call(this);if (this.f) {
var a = this.f,
b = 0,
c;for (c in a.a) {
for (var d = a.a[c], e = 0; e < d.length; e++) ++b, gb(d[e]);delete a.a[c];a.b--;
}
}this.J = null;
};g.Ia = function (a, b, c, d) {
return this.f.add(String(a), b, !1, c, d);
};g.Ja = function (a, b, c, d) {
return this.f.add(String(a), b, !0, c, d);
};
function Ab(a, b, c, d) {
b = a.f.a[String(b)];if (!b) return !0;b = b.concat();for (var e = !0, f = 0; f < b.length; ++f) {
var h = b[f];if (h && !h.Z && h.capture == c) {
var m = h.listener,
v = h.ga || h.src;h.ba && jb(a.f, h);e = !1 !== m.call(v, d) && e;
}
}return e && 0 != d.Ra;
};function Bb(a) {
return (/^\s*$/.test(a) ? !1 : /^[\],:{}\s\u2028\u2029]*$/.test(a.replace(/\\["\\\/bfnrtu]/g, "@").replace(/(?:"[^"\\\n\r\u2028\u2029\x00-\x08\x0a-\x1f]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)[\s\u2028\u2029]*(?=:|,|]|}|$)/g, "]").replace(/(?:^|:|,)(?:[\s\u2028\u2029]*\[)+/g, ""))
);
}function Cb(a) {
a = String(a);if (Bb(a)) try {
return eval("(" + a + ")");
} catch (b) {}throw Error("Invalid JSON string: " + a);
}function Db(a) {
var b = [];Eb(new Fb(), a, b);return b.join("");
}function Fb() {}
function Eb(a, b, c) {
if (null == b) c.push("null");else {
if ("object" == typeof b) {
if (p(b)) {
var d = b;b = d.length;c.push("[");for (var e = "", f = 0; f < b; f++) c.push(e), Eb(a, d[f], c), e = ",";c.push("]");return;
}if (b instanceof String || b instanceof Number || b instanceof Boolean) b = b.valueOf();else {
c.push("{");e = "";for (d in b) Object.prototype.hasOwnProperty.call(b, d) && (f = b[d], "function" != typeof f && (c.push(e), Gb(d, c), c.push(":"), Eb(a, f, c), e = ","));c.push("}");return;
}
}switch (typeof b) {case "string":
Gb(b, c);break;case "number":
c.push(isFinite(b) && !isNaN(b) ? String(b) : "null");break;case "boolean":
c.push(String(b));break;case "function":
c.push("null");break;default:
throw Error("Unknown type: " + typeof b);}
}
}var Hb = { '"': '\\"', "\\": "\\\\", "/": "\\/", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", "\t": "\\t", "\x0B": "\\u000b" },
Ib = /\uffff/.test("\uffff") ? /[\\"\x00-\x1f\x7f-\uffff]/g : /[\\"\x00-\x1f\x7f-\xff]/g;
function Gb(a, b) {
b.push('"', a.replace(Ib, function (a) {
var b = Hb[a];b || (b = "\\u" + (a.charCodeAt(0) | 65536).toString(16).substr(1), Hb[a] = b);return b;
}), '"');
};function Jb(a, b) {
this.c = a;this.f = b;this.b = 0;this.a = null;
}Jb.prototype.get = function () {
if (0 < this.b) {
this.b--;var a = this.a;this.a = a.next;a.next = null;
} else a = this.c();return a;
};function Kb() {
this.b = this.a = null;
}var Nb = new Jb(function () {
return new Lb();
}, function (a) {
a.reset();
});Kb.prototype.add = function (a, b) {
var c = Nb.get();c.set(a, b);this.b ? this.b.next = c : this.a = c;this.b = c;
};function Ob() {
var a = Pb,
b = null;a.a && (b = a.a, a.a = a.a.next, a.a || (a.b = null), b.next = null);return b;
}function Lb() {
this.next = this.b = this.a = null;
}Lb.prototype.set = function (a, b) {
this.a = a;this.b = b;this.next = null;
};Lb.prototype.reset = function () {
this.next = this.b = this.a = null;
};function Qb(a) {
k.setTimeout(function () {
throw a;
}, 0);
}var Rb;
function Sb() {
var a = k.MessageChannel;"undefined" === typeof a && "undefined" !== typeof window && window.postMessage && window.addEventListener && !y("Presto") && (a = function () {
var a = document.createElement("IFRAME");a.style.display = "none";a.src = "";document.documentElement.appendChild(a);var b = a.contentWindow;a = b.document;a.open();a.write("");a.close();var c = "callImmediate" + Math.random(),
d = "file:" == b.location.protocol ? "*" : b.location.protocol + "//" + b.location.host;a = r(function (a) {
if (("*" == d || a.origin == d) && a.data == c) this.port1.onmessage();
}, this);b.addEventListener("message", a, !1);this.port1 = {};this.port2 = { postMessage: function () {
b.postMessage(c, d);
} };
});if ("undefined" !== typeof a && !y("Trident") && !y("MSIE")) {
var b = new a(),
c = {},
d = c;b.port1.onmessage = function () {
if (void 0 !== c.next) {
c = c.next;var a = c.za;c.za = null;a();
}
};return function (a) {
d.next = { za: a };d = d.next;b.port2.postMessage(0);
};
}return "undefined" !== typeof document && "onreadystatechange" in document.createElement("SCRIPT") ? function (a) {
var b = document.createElement("SCRIPT");
b.onreadystatechange = function () {
b.onreadystatechange = null;b.parentNode.removeChild(b);b = null;a();a = null;
};document.documentElement.appendChild(b);
} : function (a) {
k.setTimeout(a, 0);
};
};var Tb;function Ub() {
if (-1 != String(k.Promise).indexOf("[native code]")) {
var a = k.Promise.resolve(void 0);Tb = function () {
a.then(Vb);
};
} else Tb = function () {
var a = Vb;!da(k.setImmediate) || k.Window && k.Window.prototype && !y("Edge") && k.Window.prototype.setImmediate == k.setImmediate ? (Rb || (Rb = Sb()), Rb(a)) : k.setImmediate(a);
};
}var Wb = !1,
Pb = new Kb();function Vb() {
for (var a; a = Ob();) {
try {
a.a.call(a.b);
} catch (c) {
Qb(c);
}var b = Nb;b.f(a);100 > b.b && (b.b++, a.next = b.a, b.a = a);
}Wb = !1;
};function Xb(a, b) {
B.call(this);this.b = a || 1;this.a = b || k;this.c = r(this.qb, this);this.g = t();
}u(Xb, B);g = Xb.prototype;g.ea = !1;g.O = null;g.qb = function () {
if (this.ea) {
var a = t() - this.g;0 < a && a < .8 * this.b ? this.O = this.a.setTimeout(this.c, this.b - a) : (this.O && (this.a.clearTimeout(this.O), this.O = null), this.dispatchEvent("tick"), this.ea && (this.O = this.a.setTimeout(this.c, this.b), this.g = t()));
}
};g.start = function () {
this.ea = !0;this.O || (this.O = this.a.setTimeout(this.c, this.b), this.g = t());
};
function Yb(a) {
a.ea = !1;a.O && (a.a.clearTimeout(a.O), a.O = null);
}g.w = function () {
Xb.H.w.call(this);Yb(this);delete this.a;
};function Zb(a, b, c) {
if (da(a)) c && (a = r(a, c));else if (a && "function" == typeof a.handleEvent) a = r(a.handleEvent, a);else throw Error("Invalid listener argument");return 2147483647 < Number(b) ? -1 : k.setTimeout(a, b || 0);
};function $b(a, b, c) {
w.call(this);this.f = null != c ? r(a, c) : a;this.c = b;this.b = r(this.kb, this);this.a = [];
}u($b, w);g = $b.prototype;g.ha = !1;g.Y = null;g.cb = function (a) {
this.a = arguments;this.Y ? this.ha = !0 : ac(this);
};g.w = function () {
$b.H.w.call(this);this.Y && (k.clearTimeout(this.Y), this.Y = null, this.ha = !1, this.a = []);
};g.kb = function () {
this.Y = null;this.ha && (this.ha = !1, ac(this));
};function ac(a) {
a.Y = Zb(a.b, a.c);a.f.apply(null, a.a);
};function bc(a) {
w.call(this);this.b = a;this.a = {};
}u(bc, w);var cc = [];function dc(a, b, c, d) {
p(c) || (c && (cc[0] = c.toString()), c = cc);for (var e = 0; e < c.length; e++) {
var f = nb(b, c[e], d || a.handleEvent, !1, a.b || a);if (!f) break;a.a[f.key] = f;
}
}function ec(a) {
Ca(a.a, function (a, c) {
this.a.hasOwnProperty(c) && wb(a);
}, a);a.a = {};
}bc.prototype.w = function () {
bc.H.w.call(this);ec(this);
};bc.prototype.handleEvent = function () {
throw Error("EventHandler.handleEvent not implemented");
};function fc(a, b, c) {
this.reset(a, b, c, void 0, void 0);
}fc.prototype.a = null;var gc = 0;fc.prototype.reset = function (a, b, c, d, e) {
"number" == typeof e || gc++;d || t();delete this.a;
};function hc(a) {
this.f = a;this.b = this.c = this.a = null;
}function C(a, b) {
this.name = a;this.value = b;
}C.prototype.toString = function () {
return this.name;
};var ic = new C("SEVERE", 1E3),
jc = new C("WARNING", 900),
kc = new C("INFO", 800),
lc = new C("CONFIG", 700),
mc = new C("FINE", 500);function nc(a) {
if (a.c) return a.c;if (a.a) return nc(a.a);ma("Root logger has no level set.");return null;
}hc.prototype.log = function (a, b, c) {
if (a.value >= nc(this).value) for (da(b) && (b = b()), a = new fc(a, String(b), this.f), c && (a.a = c), c = this; c;) c = c.a;
};
var oc = {},
pc = null;function qc(a) {
pc || (pc = new hc(""), oc[""] = pc, pc.c = lc);var b;if (!(b = oc[a])) {
b = new hc(a);var c = a.lastIndexOf("."),
d = a.substr(c + 1);c = qc(a.substr(0, c));c.b || (c.b = {});c.b[d] = b;b.a = c;oc[a] = b;
}return b;
};function D(a, b) {
a && a.log(jc, b, void 0);
}function rc(a, b) {
a && a.log(kc, b, void 0);
}function E(a, b) {
a && a.log(mc, b, void 0);
};function sc() {
this.a = qc("goog.labs.net.webChannel.WebChannelDebug");this.b = !0;
}sc.prototype.Fa = function () {
this.b = !1;
};function tc(a, b, c, d, e, f) {
F(a, function () {
if (a.b) {
if (f) {
var h = "";for (var m = f.split("&"), v = 0; v < m.length; v++) {
var I = m[v].split("=");if (1 < I.length) {
var X = I[0];I = I[1];var Mb = X.split("_");h = 2 <= Mb.length && "type" == Mb[1] ? h + (X + "=" + I + "&") : h + (X + "=redacted&");
}
}
} else h = null;
} else h = f;return "XMLHTTP REQ (" + d + ") [attempt " + e + "]: " + b + "\n" + c + "\n" + h;
});
}
function uc(a, b, c, d, e, f, h) {
F(a, function () {
return "XMLHTTP RESP (" + d + ") [ attempt " + e + "]: " + b + "\n" + c + "\n" + f + " " + h;
});
}function G(a, b, c, d) {
F(a, function () {
return "XMLHTTP TEXT (" + b + "): " + vc(a, c) + (d ? " " + d : "");
});
}function wc(a, b) {
F(a, function () {
return "TIMEOUT: " + b;
});
}function H(a, b) {
E(a.a, b);
}function xc(a, b, c) {
(a = a.a) && a.log(ic, c || "Exception", b);
}function F(a, b) {
rc(a.a, b);
}function J(a, b) {
(a = a.a) && a.log(ic, b, void 0);
}
function vc(a, b) {
if (!a.b) return b;if (!b) return null;try {
var c = JSON.parse(b);if (c) for (var d = 0; d < c.length; d++) if (p(c[d])) {
var e = c[d];if (!(2 > e.length)) {
var f = e[1];if (p(f) && !(1 > f.length)) {
var h = f[0];if ("noop" != h && "stop" != h && "close" != h) for (var m = 1; m < f.length; m++) f[m] = "";
}
}
}return Db(c);
} catch (v) {
return H(a, "Exception parsing expected JS array - probably was not JS"), b;
}
};var yc = new B();function zc(a) {
A.call(this, "serverreachability", a);
}u(zc, A);function Ac(a) {
yc.dispatchEvent(new zc(yc, a));
}function Bc(a) {
A.call(this, "statevent", a);
}u(Bc, A);function K(a) {
yc.dispatchEvent(new Bc(yc, a));
}function Cc(a) {
A.call(this, "timingevent", a);
}u(Cc, A);function Dc(a, b, c) {
yc.dispatchEvent(new Cc(yc, a, b, c));
}function Ec(a, b) {
if (!da(a)) throw Error("Fn must not be null and must be a function");return k.setTimeout(function () {
a();
}, b);
};var Fc = { NO_ERROR: 0, rb: 1, yb: 2, xb: 3, ub: 4, wb: 5, zb: 6, Ua: 7, TIMEOUT: 8, Cb: 9 };var Gc = { tb: "complete", Gb: "success", Va: "error", Ua: "abort", Eb: "ready", Fb: "readystatechange", TIMEOUT: "timeout", Ab: "incrementaldata", Db: "progress", vb: "downloadprogress", Hb: "uploadprogress" };function Hc() {}Hc.prototype.a = null;function Ic(a) {
var b;(b = a.a) || (b = {}, Jc(a) && (b[0] = !0, b[1] = !0), b = a.a = b);return b;
};function Kc() {}var Lc = { OPEN: "a", sb: "b", Va: "c", Bb: "d" };function Mc() {
A.call(this, "d");
}u(Mc, A);function Nc() {
A.call(this, "c");
}u(Nc, A);var Oc;function Pc() {}u(Pc, Hc);function Qc(a) {
return (a = Jc(a)) ? new ActiveXObject(a) : new XMLHttpRequest();
}function Jc(a) {
if (!a.b && "undefined" == typeof XMLHttpRequest && "undefined" != typeof ActiveXObject) {
for (var b = ["MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], c = 0; c < b.length; c++) {
var d = b[c];try {
return new ActiveXObject(d), a.b = d;
} catch (e) {}
}throw Error("Could not create ActiveXObject. ActiveX might be disabled, or MSXML might not be installed");
}return a.b;
}Oc = new Pc();function L(a, b, c, d) {
this.i = a;this.b = b;this.c = c;this.T = d || 1;this.L = new bc(this);this.R = Rc;a = Na ? 125 : void 0;this.S = new Xb(a);this.j = null;this.f = !1;this.l = this.g = this.h = this.J = this.D = this.U = this.s = null;this.u = [];this.a = null;this.G = 0;this.m = this.o = null;this.C = -1;this.B = !1;this.N = 0;this.I = null;this.v = this.X = this.K = !1;
}var Rc = 45E3;
function Sc(a, b) {
switch (a) {case 0:
return "Non-200 return code (" + b + ")";case 1:
return "XMLHTTP failure (no data)";case 2:
return "HttpConnection timeout";default:
return "Unknown error";}
}var Tc = {},
Uc = {};g = L.prototype;g.setTimeout = function (a) {
this.R = a;
};function Vc(a, b, c) {
a.J = 1;a.h = Wc(M(b));a.l = c;a.K = !0;Xc(a, null);
}function Yc(a, b, c, d) {
a.J = 1;a.h = Wc(M(b));a.l = null;a.K = c;Xc(a, d);
}
function Xc(a, b) {
a.D = t();Zc(a);a.g = M(a.h);$c(a.g, "t", a.T);a.G = 0;a.a = a.i.ca(a.i.ia() ? b : null);0 < a.N && (a.I = new $b(r(a.Sa, a, a.a), a.N));dc(a.L, a.a, "readystatechange", a.nb);b = a.j ? Fa(a.j) : {};a.l ? (a.o || (a.o = "POST"), b["Content-Type"] = "application/x-www-form-urlencoded", a.a.fa(a.g, a.o, a.l, b)) : (a.o = "GET", a.a.fa(a.g, a.o, null, b));Ac(1);tc(a.b, a.o, a.g, a.c, a.T, a.l);
}g.nb = function (a) {
a = a.target;var b = this.I;b && 3 == N(a) ? (H(this.b, "Throttling readystatechange."), b.cb()) : this.Sa(a);
};
g.Sa = function (a) {
try {
a == this.a ? ad(this) : D(this.b.a, "Called back with an unexpected xmlhttp");
} catch (c) {
if (H(this.b, "Failed call to OnXmlHttpReadyStateChanged_"), this.a && this.a.V()) {
var b = this;xc(this.b, c, function () {
return "ResponseText: " + b.a.V();
});
} else xc(this.b, c, "No response text");
} finally {}
};
function ad(a) {
var b = N(a.a),
c = a.a.Ga(),
d = a.a.W();if (!(3 > b || 3 == b && !Na && !a.a.V())) {
a.B || 4 != b || 7 == c || (8 == c || 0 >= d ? Ac(3) : Ac(2));bd(a);var e = a.a.W();a.C = e;(c = a.a.V()) || H(a.b, function () {
return "No response text for uri " + a.g + " status " + e;
});a.f = 200 == e;uc(a.b, a.o, a.g, a.c, a.T, b, e);if (a.f) {
if (d = cd(a)) G(a.b, a.c, d, "Initial handshake response via X-HTTP-Initial-Response"), a.v = !0, dd(a, d);a.K ? (ed(a, b, c), Na && a.f && 3 == b && fd(a)) : (G(a.b, a.c, c, null), dd(a, c));4 == b && gd(a);a.f && !a.B && (4 == b ? a.i.ta(a) : (a.f = !1, Zc(a)));
} else 400 == e && 0 < c.indexOf("Unknown SID") ? (a.m = 3, K(12), D(a.b.a, "XMLHTTP Unknown SID (" + a.c + ")")) : (a.m = 0, K(13), D(a.b.a, "XMLHTTP Bad status " + e + " (" + a.c + ")")), gd(a), hd(a);
}
}function cd(a) {
return !a.X || a.v ? null : a.a && (a = id(a.a, "X-HTTP-Initial-Response")) && !xa(a) ? a : null;
}
function ed(a, b, c) {
for (var d = !0; !a.B && a.G < c.length;) {
var e = jd(a, c);if (e == Uc) {
4 == b && (a.m = 4, K(14), d = !1);G(a.b, a.c, null, "[Incomplete Response]");break;
} else if (e == Tc) {
a.m = 4;K(15);G(a.b, a.c, c, "[Invalid Chunk]");d = !1;break;
} else G(a.b, a.c, e, null), dd(a, e);
}4 == b && 0 == c.length && (a.m = 1, K(16), d = !1);a.f = a.f && d;d || (G(a.b, a.c, c, "[Invalid Chunked Response]"), gd(a), hd(a));
}g.mb = function () {
if (this.a) {
var a = N(this.a),
b = this.a.V();this.G < b.length && (bd(this), ed(this, a, b), this.f && 4 != a && Zc(this));
}
};
function fd(a) {
dc(a.L, a.S, "tick", a.mb);a.S.start();
}function jd(a, b) {
var c = a.G,
d = b.indexOf("\n", c);if (-1 == d) return Uc;c = Number(b.substring(c, d));if (isNaN(c)) return Tc;d += 1;if (d + c > b.length) return Uc;b = b.substr(d, c);a.G = d + c;return b;
}g.cancel = function () {
this.B = !0;gd(this);
};function Zc(a) {
a.U = t() + a.R;kd(a, a.R);
}function kd(a, b) {
if (null != a.s) throw Error("WatchDog timer not null");a.s = Ec(r(a.lb, a), b);
}function bd(a) {
a.s && (k.clearTimeout(a.s), a.s = null);
}
g.lb = function () {
this.s = null;var a = t();0 <= a - this.U ? (this.f && J(this.b, "Received watchdog timeout even though request loaded successfully"), wc(this.b, this.g), 2 != this.J && (Ac(3), K(17)), gd(this), this.m = 2, hd(this)) : (D(this.b.a, "WatchDog timer called too early"), kd(this, this.U - a));
};function hd(a) {
a.i.La() || a.B || a.i.ta(a);
}function gd(a) {
bd(a);var b = a.I;b && "function" == typeof b.$ && b.$();a.I = null;Yb(a.S);ec(a.L);a.a && (b = a.a, a.a = null, b.abort(), b.$());
}
function dd(a, b) {
try {
a.i.Oa(a, b), Ac(4);
} catch (c) {
xc(a.b, c, "Error in httprequest callback");
}
};function ld(a) {
if (a.A && "function" == typeof a.A) return a.A();if (l(a)) return a.split("");if (ca(a)) {
for (var b = [], c = a.length, d = 0; d < c; d++) b.push(a[d]);return b;
}return Da(a);
}
function md(a, b) {
if (a.forEach && "function" == typeof a.forEach) a.forEach(b, void 0);else if (ca(a) || l(a)) ra(a, b, void 0);else {
if (a.M && "function" == typeof a.M) var c = a.M();else if (a.A && "function" == typeof a.A) c = void 0;else if (ca(a) || l(a)) {
c = [];for (var d = a.length, e = 0; e < d; e++) c.push(e);
} else c = Ea(a);d = ld(a);e = d.length;for (var f = 0; f < e; f++) b.call(void 0, d[f], c && c[f], a);
}
};function O(a, b) {
this.b = {};this.a = [];this.c = 0;var c = arguments.length;if (1 < c) {
if (c % 2) throw Error("Uneven number of arguments");for (var d = 0; d < c; d += 2) this.set(arguments[d], arguments[d + 1]);
} else if (a) if (a instanceof O) for (c = a.M(), d = 0; d < c.length; d++) this.set(c[d], a.get(c[d]));else for (d in a) this.set(d, a[d]);
}g = O.prototype;g.A = function () {
nd(this);for (var a = [], b = 0; b < this.a.length; b++) a.push(this.b[this.a[b]]);return a;
};g.M = function () {
nd(this);return this.a.concat();
};
function od(a) {
a.b = {};a.a.length = 0;a.c = 0;
}function pd(a, b) {
return P(a.b, b) ? (delete a.b[b], a.c--, a.a.length > 2 * a.c && nd(a), !0) : !1;
}function nd(a) {
if (a.c != a.a.length) {
for (var b = 0, c = 0; b < a.a.length;) {
var d = a.a[b];P(a.b, d) && (a.a[c++] = d);b++;
}a.a.length = c;
}if (a.c != a.a.length) {
var e = {};for (c = b = 0; b < a.a.length;) d = a.a[b], P(e, d) || (a.a[c++] = d, e[d] = 1), b++;a.a.length = c;
}
}g.get = function (a, b) {
return P(this.b, a) ? this.b[a] : b;
};g.set = function (a, b) {
P(this.b, a) || (this.c++, this.a.push(a));this.b[a] = b;
};
g.forEach = function (a, b) {
for (var c = this.M(), d = 0; d < c.length; d++) {
var e = c[d],
f = this.get(e);a.call(b, f, e, this);
}
};function P(a, b) {
return Object.prototype.hasOwnProperty.call(a, b);
};var qd = /^(?:([^:/?#.]+):)?(?:\/\/(?:([^/?#]*)@)?([^/#?]*?)(?::([0-9]+))?(?=[/#?]|$))?([^?#]+)?(?:\?([^#]*))?(?:#([\s\S]*))?$/;function rd(a, b) {
if (a) {
a = a.split("&");for (var c = 0; c < a.length; c++) {
var d = a[c].indexOf("="),
e = null;if (0 <= d) {
var f = a[c].substring(0, d);e = a[c].substring(d + 1);
} else f = a[c];b(f, e ? decodeURIComponent(e.replace(/\+/g, " ")) : "");
}
}
};function Q(a, b) {
this.b = this.j = this.f = "";this.i = null;this.g = this.a = "";this.h = !1;var c;a instanceof Q ? (this.h = void 0 !== b ? b : a.h, sd(this, a.f), this.j = a.j, td(this, a.b), ud(this, a.i), this.a = a.a, vd(this, wd(a.c)), this.g = a.g) : a && (c = String(a).match(qd)) ? (this.h = !!b, sd(this, c[1] || "", !0), this.j = xd(c[2] || ""), td(this, c[3] || "", !0), ud(this, c[4]), this.a = xd(c[5] || "", !0), vd(this, c[6] || "", !0), this.g = xd(c[7] || "")) : (this.h = !!b, this.c = new yd(null, this.h));
}
Q.prototype.toString = function () {
var a = [],
b = this.f;b && a.push(zd(b, Ad, !0), ":");var c = this.b;if (c || "file" == b) a.push("//"), (b = this.j) && a.push(zd(b, Ad, !0), "@"), a.push(encodeURIComponent(String(c)).replace(/%25([0-9a-fA-F]{2})/g, "%$1")), c = this.i, null != c && a.push(":", String(c));if (c = this.a) this.b && "/" != c.charAt(0) && a.push("/"), a.push(zd(c, "/" == c.charAt(0) ? Bd : Cd, !0));(c = this.c.toString()) && a.push("?", c);(c = this.g) && a.push("#", zd(c, Dd));return a.join("");
};
Q.prototype.resolve = function (a) {
var b = M(this),
c = !!a.f;c ? sd(b, a.f) : c = !!a.j;c ? b.j = a.j : c = !!a.b;c ? td(b, a.b) : c = null != a.i;var d = a.a;if (c) ud(b, a.i);else if (c = !!a.a) {
if ("/" != d.charAt(0)) if (this.b && !this.a) d = "/" + d;else {
var e = b.a.lastIndexOf("/");-1 != e && (d = b.a.substr(0, e + 1) + d);
}e = d;if (".." == e || "." == e) d = "";else if (-1 != e.indexOf("./") || -1 != e.indexOf("/.")) {
d = 0 == e.lastIndexOf("/", 0);e = e.split("/");for (var f = [], h = 0; h < e.length;) {
var m = e[h++];"." == m ? d && h == e.length && f.push("") : ".." == m ? ((1 < f.length || 1 == f.length && "" != f[0]) && f.pop(), d && h == e.length && f.push("")) : (f.push(m), d = !0);
}d = f.join("/");
} else d = e;
}c ? b.a = d : c = "" !== a.c.toString();c ? vd(b, wd(a.c)) : c = !!a.g;c && (b.g = a.g);return b;
};function M(a) {
return new Q(a);
}function sd(a, b, c) {
a.f = c ? xd(b, !0) : b;a.f && (a.f = a.f.replace(/:$/, ""));
}function td(a, b, c) {
a.b = c ? xd(b, !0) : b;
}function ud(a, b) {
if (b) {
b = Number(b);if (isNaN(b) || 0 > b) throw Error("Bad port number " + b);a.i = b;
} else a.i = null;
}function vd(a, b, c) {
b instanceof yd ? (a.c = b, Ed(a.c, a.h)) : (c || (b = zd(b, Fd)), a.c = new yd(b, a.h));
}
function R(a, b, c) {
a.c.set(b, c);
}function $c(a, b, c) {
p(c) || (c = [String(c)]);Gd(a.c, b, c);
}function Wc(a) {
R(a, "zx", Math.floor(2147483648 * Math.random()).toString(36) + Math.abs(Math.floor(2147483648 * Math.random()) ^ t()).toString(36));return a;
}function Hd(a) {
return a instanceof Q ? M(a) : new Q(a, void 0);
}function Id(a, b, c, d) {
var e = new Q(null, void 0);a && sd(e, a);b && td(e, b);c && ud(e, c);d && (e.a = d);return e;
}function xd(a, b) {
return a ? b ? decodeURI(a.replace(/%25/g, "%2525")) : decodeURIComponent(a) : "";
}
function zd(a, b, c) {
return l(a) ? (a = encodeURI(a).replace(b, Jd), c && (a = a.replace(/%25([0-9a-fA-F]{2})/g, "%$1")), a) : null;
}function Jd(a) {
a = a.charCodeAt(0);return "%" + (a >> 4 & 15).toString(16) + (a & 15).toString(16);
}var Ad = /[#\/\?@]/g,
Cd = /[#\?:]/g,
Bd = /[#\?]/g,
Fd = /[#\?@]/g,
Dd = /#/g;function yd(a, b) {
this.b = this.a = null;this.c = a || null;this.f = !!b;
}function S(a) {
a.a || (a.a = new O(), a.b = 0, a.c && rd(a.c, function (b, c) {
a.add(decodeURIComponent(b.replace(/\+/g, " ")), c);
}));
}g = yd.prototype;
g.add = function (a, b) {
S(this);this.c = null;a = Kd(this, a);var c = this.a.get(a);c || this.a.set(a, c = []);c.push(b);this.b += 1;return this;
};function Ld(a, b) {
S(a);b = Kd(a, b);P(a.a.b, b) && (a.c = null, a.b -= a.a.get(b).length, pd(a.a, b));
}function Md(a, b) {
S(a);b = Kd(a, b);return P(a.a.b, b);
}g.forEach = function (a, b) {
S(this);this.a.forEach(function (c, d) {
ra(c, function (c) {
a.call(b, c, d, this);
}, this);
}, this);
};
g.M = function () {
S(this);for (var a = this.a.A(), b = this.a.M(), c = [], d = 0; d < b.length; d++) for (var e = a[d], f = 0; f < e.length; f++) c.push(b[d]);return c;
};g.A = function (a) {
S(this);var b = [];if (l(a)) Md(this, a) && (b = va(b, this.a.get(Kd(this, a))));else {
a = this.a.A();for (var c = 0; c < a.length; c++) b = va(b, a[c]);
}return b;
};g.set = function (a, b) {
S(this);this.c = null;a = Kd(this, a);Md(this, a) && (this.b -= this.a.get(a).length);this.a.set(a, [b]);this.b += 1;return this;
};g.get = function (a, b) {
a = a ? this.A(a) : [];return 0 < a.length ? String(a[0]) : b;
};
function Gd(a, b, c) {
Ld(a, b);0 < c.length && (a.c = null, a.a.set(Kd(a, b), wa(c)), a.b += c.length);
}g.toString = function () {
if (this.c) return this.c;if (!this.a) return "";for (var a = [], b = this.a.M(), c = 0; c < b.length; c++) {
var d = b[c],
e = encodeURIComponent(String(d));d = this.A(d);for (var f = 0; f < d.length; f++) {
var h = e;"" !== d[f] && (h += "=" + encodeURIComponent(String(d[f])));a.push(h);
}
}return this.c = a.join("&");
};function wd(a) {
var b = new yd();b.c = a.c;a.a && (b.a = new O(a.a), b.b = a.b);return b;
}
function Kd(a, b) {
b = String(b);a.f && (b = b.toLowerCase());return b;
}function Ed(a, b) {
b && !a.f && (S(a), a.c = null, a.a.forEach(function (a, b) {
var c = b.toLowerCase();b != c && (Ld(this, b), Gd(this, c, a));
}, a));a.f = b;
};function Nd() {
this.a = t();
}var Od = null;Nd.prototype.set = function (a) {
this.a = a;
};Nd.prototype.reset = function () {
this.set(t());
};Nd.prototype.get = function () {
return this.a;
};function Pd() {
Od || (Od = new Nd());
}function Qd() {
Od || (Od = new Nd());
}u(Qd, Pd);function Rd(a, b) {
this.a = a;this.b = b;this.c = this.i = null;this.h = !1;this.m = null;this.f = -1;this.l = this.g = null;
}g = Rd.prototype;g.P = null;
function Sd(a) {
H(a.b, "TestConnection: starting stage 2");var b = a.a.I.a;if (null != b) H(a.b, function () {
return true ? "Buffered" : "Unbuffered";
}), K(4), b ? (K(10), Td(a.a, a, !1)) : (K(11), Td(a.a, a, !0));else {
a.c = new L(a, a.b, void 0, void 0);a.c.j = a.i;var c = Ud(a.a, a.g, a.m);K(4);$c(c, "TYPE", "xmlhttp");var d = a.a.j,
e = a.a.K;d && e && R(c, d, e);Yc(a.c, c, !1, a.g);
}
}g.ca = function (a) {
return this.a.ca(a);
};g.abort = function () {
this.c && (this.c.cancel(), this.c = null);this.f = -1;
};
g.La = function () {
return !1;
};
g.Oa = function (a, b) {
this.f = a.C;if (0 == this.P) {
H(this.b, "TestConnection: Got data for stage 1");if (!this.a.o && (a = a.a)) {
var c = id(a, "X-Client-Wire-Protocol");this.l = c ? c : null;this.a.j && ((a = id(a, "X-HTTP-Session-Id")) ? this.a.K = a : D(this.b.a, "Missing X_HTTP_SESSION_ID in the handshake response"));
}if (b) {
try {
var d = this.a.la.a.parse(b);
} catch (e) {
xc(this.b, e);Vd(this.a, this);return;
}this.g = d[0];
} else H(this.b, "TestConnection: Null responseText"), Vd(this.a, this);
} else if (1 == this.P) if (this.h) K(6);else if ("11111" == b) {
if (K(5), this.h = !0, !z || 10 <= Number(Wa)) this.f = 200, this.c.cancel(), H(this.b, "Test connection succeeded; using streaming connection"), K(11), Td(this.a, this, !0);
} else K(7), this.h = !1;
};
g.ta = function () {
this.f = this.c.C;this.c.f ? 0 == this.P ? (this.P = 1, H(this.b, "TestConnection: request complete for initial check"), Sd(this)) : 1 == this.P && (H(this.b, "TestConnection: request complete for stage 2"), this.h ? (H(this.b, "Test connection succeeded; using streaming connection"), K(11), Td(this.a, this, !0)) : (H(this.b, "Test connection failed; not using streaming"), K(10), Td(this.a, this, !1))) : (H(this.b, "TestConnection: request failed, in state " + this.P), 0 == this.P ? K(8) : 1 == this.P && K(9), Vd(this.a, this));
};
g.ia = function () {
return this.a.ia();
};g.qa = function () {
return this.a.qa();
};function Wd() {
this.a = this.b = null;
};function Xd() {
this.a = new O();
}function Yd(a) {
var b = typeof a;return "object" == b && a || "function" == b ? "o" + (a[q] || (a[q] = ++fa)) : b.charAt(0) + a;
}Xd.prototype.add = function (a) {
this.a.set(Yd(a), a);
};Xd.prototype.A = function () {
return this.a.A();
};function Zd(a, b) {
this.a = a;this.b = b;
};function $d(a) {
this.g = a || ae;k.PerformanceNavigationTiming ? (a = k.performance.getEntriesByType("navigation"), a = 0 < a.length && ("hq" == a[0].nextHopProtocol || "h2" == a[0].nextHopProtocol)) : a = !!(k.oa && k.oa.Ma && k.oa.Ma() && k.oa.Ma().Jb);this.f = a ? this.g : 1;this.a = null;1 < this.f && (this.a = new Xd());this.b = null;this.c = [];
}var ae = 10;function be(a, b) {
a.a || -1 == b.indexOf("spdy") && -1 == b.indexOf("quic") && -1 == b.indexOf("h2") || (a.f = a.g, a.a = new Xd(), a.b && (ce(a, a.b), a.b = null));
}function de(a) {
return a.b ? !0 : a.a ? a.a.a.c >= a.f : !1;
}
function ee(a, b) {
a.b ? a = a.b == b : a.a ? (b = Yd(b), a = P(a.a.a.b, b)) : a = !1;return a;
}function ce(a, b) {
a.a ? a.a.add(b) : a.b = b;
}function fe(a, b) {
if (a.b && a.b == b) a.b = null;else {
var c;if (c = a.a) c = Yd(b), c = P(a.a.a.b, c);c && pd(a.a.a, Yd(b));
}
}$d.prototype.cancel = function () {
this.c = ge(this);this.b ? (this.b.cancel(), this.b = null) : this.a && 0 != this.a.a.c && (ra(this.a.A(), function (a) {
a.cancel();
}), od(this.a.a));
};
function ge(a) {
if (null != a.b) return a.c.concat(a.b.u);if (null != a.a && 0 != a.a.a.c) {
var b = a.c;ra(a.a.A(), function (a) {
b = b.concat(a.u);
});return b;
}return wa(a.c);
}function he(a, b) {
a.c = a.c.concat(b);
};function ie() {}ie.prototype.stringify = function (a) {
return k.JSON.stringify(a, void 0);
};ie.prototype.parse = function (a) {
return k.JSON.parse(a, void 0);
};function je() {
this.a = new ie();
}function ke(a, b, c) {
var d = c || "";try {
md(a, function (a, c) {
var e = a;ea(a) && (e = Db(a));b.push(d + c + "=" + encodeURIComponent(e));
});
} catch (e) {
throw b.push(d + "type=" + encodeURIComponent("_badmap")), e;
}
};function le(a, b) {
var c = new sc();H(c, "TestLoadImage: loading " + a);var d = new Image();d.onload = ja(me, c, d, "TestLoadImage: loaded", !0, b);d.onerror = ja(me, c, d, "TestLoadImage: error", !1, b);d.onabort = ja(me, c, d, "TestLoadImage: abort", !1, b);d.ontimeout = ja(me, c, d, "TestLoadImage: timeout", !1, b);k.setTimeout(function () {
if (d.ontimeout) d.ontimeout();
}, 1E4);d.src = a;
}function me(a, b, c, d, e) {
try {
H(a, c), b.onload = null, b.onerror = null, b.onabort = null, b.ontimeout = null, e(d);
} catch (f) {
xc(a, f);
}
};function T(a) {
B.call(this);this.headers = new O();this.s = a || null;this.c = !1;this.D = this.a = null;this.K = this.B = "";this.j = 0;this.g = "";this.h = this.I = this.u = this.G = !1;this.l = 0;this.C = null;this.L = ne;this.v = this.o = !1;
}u(T, B);var ne = "";T.prototype.b = qc("goog.net.XhrIo");var oe = /^https?$/i,
pe = ["POST", "PUT"];g = T.prototype;
g.fa = function (a, b, c, d) {
if (this.a) throw Error("[goog.net.XhrIo] Object is active with another request=" + this.B + "; newUri=" + a);b = b ? b.toUpperCase() : "GET";this.B = a;this.g = "";this.j = 0;this.K = b;this.G = !1;this.c = !0;this.a = this.s ? Qc(this.s) : Qc(Oc);this.D = this.s ? Ic(this.s) : Ic(Oc);this.a.onreadystatechange = r(this.Na, this);try {
E(this.b, U(this, "Opening Xhr")), this.I = !0, this.a.open(b, String(a), !0), this.I = !1;
} catch (f) {
E(this.b, U(this, "Error opening Xhr: " + f.message));qe(this, f);return;
}a = c || "";var e = new O(this.headers);
d && md(d, function (a, b) {
e.set(b, a);
});d = sa(e.M());c = k.FormData && a instanceof k.FormData;!(0 <= qa(pe, b)) || d || c || e.set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");e.forEach(function (a, b) {
this.a.setRequestHeader(b, a);
}, this);this.L && (this.a.responseType = this.L);"withCredentials" in this.a && this.a.withCredentials !== this.o && (this.a.withCredentials = this.o);try {
re(this), 0 < this.l && (this.v = se(this.a), E(this.b, U(this, "Will abort after " + this.l + "ms if incomplete, xhr2 " + this.v)), this.v ? (this.a.timeout = this.l, this.a.ontimeout = r(this.Ka, this)) : this.C = Zb(this.Ka, this.l, this)), E(this.b, U(this, "Sending request")), this.u = !0, this.a.send(a), this.u = !1;
} catch (f) {
E(this.b, U(this, "Send error: " + f.message)), qe(this, f);
}
};function se(a) {
return z && Va(9) && "number" == typeof a.timeout && void 0 !== a.ontimeout;
}function ta(a) {
return "content-type" == a.toLowerCase();
}
g.Ka = function () {
"undefined" != typeof goog && this.a && (this.g = "Timed out after " + this.l + "ms, aborting", this.j = 8, E(this.b, U(this, this.g)), this.dispatchEvent("timeout"), this.abort(8));
};function qe(a, b) {
a.c = !1;a.a && (a.h = !0, a.a.abort(), a.h = !1);a.g = b;a.j = 5;te(a);ue(a);
}function te(a) {
a.G || (a.G = !0, a.dispatchEvent("complete"), a.dispatchEvent("error"));
}
g.abort = function (a) {
this.a && this.c && (E(this.b, U(this, "Aborting")), this.c = !1, this.h = !0, this.a.abort(), this.h = !1, this.j = a || 7, this.dispatchEvent("complete"), this.dispatchEvent("abort"), ue(this));
};g.w = function () {
this.a && (this.c && (this.c = !1, this.h = !0, this.a.abort(), this.h = !1), ue(this, !0));T.H.w.call(this);
};g.Na = function () {
this.i || (this.I || this.u || this.h ? ve(this) : this.jb());
};g.jb = function () {
ve(this);
};
function ve(a) {
if (a.c && "undefined" != typeof goog) if (a.D[1] && 4 == N(a) && 2 == a.W()) E(a.b, U(a, "Local request error detected and ignored"));else if (a.u && 4 == N(a)) Zb(a.Na, 0, a);else if (a.dispatchEvent("readystatechange"), 4 == N(a)) {
E(a.b, U(a, "Request complete"));a.c = !1;try {
var b = a.W();a: switch (b) {case 200:case 201:case 202:case 204:case 206:case 304:case 1223:
var c = !0;break a;default:
c = !1;}var d;if (!(d = c)) {
var e;if (e = 0 === b) {
var f = String(a.B).match(qd)[1] || null;if (!f && k.self && k.self.location) {
var h = k.self.location.protocol;
f = h.substr(0, h.length - 1);
}e = !oe.test(f ? f.toLowerCase() : "");
}d = e;
}d ? (a.dispatchEvent("complete"), a.dispatchEvent("success")) : (a.j = 6, a.g = a.Ha() + " [" + a.W() + "]", te(a));
} finally {
ue(a);
}
}
}function ue(a, b) {
if (a.a) {
re(a);var c = a.a,
d = a.D[0] ? aa : null;a.a = null;a.D = null;b || a.dispatchEvent("ready");try {
c.onreadystatechange = d;
} catch (e) {
(a = a.b) && a.log(ic, "Problem encountered resetting onreadystatechange: " + e.message, void 0);
}
}
}function re(a) {
a.a && a.v && (a.a.ontimeout = null);a.C && (k.clearTimeout(a.C), a.C = null);
}
function N(a) {
return a.a ? a.a.readyState : 0;
}g.W = function () {
try {
return 2 < N(this) ? this.a.status : -1;
} catch (a) {
return -1;
}
};g.Ha = function () {
try {
return 2 < N(this) ? this.a.statusText : "";
} catch (a) {
return E(this.b, "Can not get status: " + a.message), "";
}
};g.V = function () {
try {
return this.a ? this.a.responseText : "";
} catch (a) {
return E(this.b, "Can not get responseText: " + a.message), "";
}
};
g.eb = function (a) {
if (this.a) {
var b = this.a.responseText;a && 0 == b.indexOf(a) && (b = b.substring(a.length));a: {
a = b;if (k.JSON) try {
var c = k.JSON.parse(a);break a;
} catch (d) {}c = Cb(a);
}return c;
}
};function id(a, b) {
return a.a ? a.a.getResponseHeader(b) : null;
}g.Ga = function () {
return this.j;
};g.hb = function () {
return l(this.g) ? this.g : String(this.g);
};function U(a, b) {
return b + " [" + a.K + " " + a.B + " " + a.W() + "]";
};function we(a) {
var b = "";Ca(a, function (a, d) {
b += d;b += ":";b += a;b += "\r\n";
});return b;
}function xe(a, b, c) {
a: {
for (d in c) {
var d = !1;break a;
}d = !0;
}if (d) return a;c = we(c);if (l(a)) {
b = encodeURIComponent(String(b));c = null != c ? "=" + encodeURIComponent(String(c)) : "";if (b += c) {
c = a.indexOf("#");0 > c && (c = a.length);d = a.indexOf("?");if (0 > d || d > c) {
d = c;var e = "";
} else e = a.substring(d + 1, c);a = [a.substr(0, d), e, a.substr(c)];c = a[1];a[1] = b ? c ? c + "&" + b : b : c;a = a[0] + (a[1] ? "?" + a[1] : "") + a[2];
}return a;
}R(a, b, c);return a;
};function ye(a) {
this.ya = 0;this.g = [];this.a = new sc();this.I = new Wd();this.X = this.ua = this.D = this.ja = this.b = this.K = this.j = this.U = this.h = this.L = this.i = null;this.Za = this.R = 0;this.Xa = !!n("internalChannelParams.failFast", a);this.ka = this.C = this.s = this.l = this.m = this.f = null;this.u = this.xa = this.N = -1;this.T = this.B = this.v = 0;this.Wa = n("internalChannelParams.baseRetryDelayMs", a) || 5E3;this.$a = n("internalChannelParams.retryDelaySeedMs", a) || 1E4;this.Ya = n("internalChannelParams.forwardChannelMaxRetries", a) || 2;this.wa = n("internalChannelParams.forwardChannelRequestTimeoutMs", a) || 2E4;this.Ta = a && a.Kb || void 0;this.G = void 0;this.S = a && a.supportsCrossDomainXhr || !1;this.J = "";this.c = new $d(a && a.concurrentRequestLimit);this.la = new je();this.o = a && void 0 !== a.backgroundChannelTest ? a.backgroundChannelTest : !0;(this.va = a && a.fastHandshake || !1) && !this.o && (D(this.a.a, "Force backgroundChannelTest when fastHandshake is enabled."), this.o = !0);a && a.Fa && this.a.Fa();
}g = ye.prototype;g.na = 8;g.F = 1;
function ze(a) {
H(a.a, "disconnect()");Ae(a);if (3 == a.F) {
var b = a.R++,
c = M(a.D);R(c, "SID", a.J);R(c, "RID", b);R(c, "TYPE", "terminate");Be(a, c);b = new L(a, a.a, b, void 0);b.J = 2;b.h = Wc(M(c));c = !1;k.navigator && k.navigator.sendBeacon && (c = k.navigator.sendBeacon(b.h.toString(), ""));!c && k.Image && (new Image().src = b.h, c = !0);c || (b.a = b.i.ca(null), b.a.fa(b.h));b.D = t();Zc(b);
}Ce(a);
}
function Ae(a) {
a.C && (a.C.abort(), a.C = null);a.b && (a.b.cancel(), a.b = null);a.l && (k.clearTimeout(a.l), a.l = null);De(a);a.c.cancel();a.m && (k.clearTimeout(a.m), a.m = null);
}function Ee(a, b) {
1E3 == a.g.length && J(a.a, function () {
return "Already have 1000 queued maps upon queueing " + Db(b);
});a.g.push(new Zd(a.Za++, b));3 == a.F && Fe(a);
}g.La = function () {
return 0 == this.F;
};function Fe(a) {
de(a.c) || a.m || (a.m = Ec(r(a.Qa, a), 0), a.v = 0);
}
function Ge(a, b) {
var c = a.c;if ((c.b ? 1 : c.a ? c.a.a.c : 0) >= a.c.f - (a.m ? 1 : 0)) return J(a.a, "Unexpected retry request is scheduled."), !1;if (a.m) return H(a.a, "Use the retry request that is already scheduled."), a.g = b.u.concat(a.g), !0;if (1 == a.F || 2 == a.F || a.v >= (a.Xa ? 0 : a.Ya)) return !1;H(a.a, "Going to retry POST");a.m = Ec(r(a.Qa, a, b), He(a, a.v));a.v++;return !0;
}
g.Qa = function (a) {
this.m = null;H(this.a, "startForwardChannel_");if (1 == this.F) {
if (a) J(this.a, "Not supposed to retry the open");else {
H(this.a, "open_()");this.R = Math.floor(1E5 * Math.random());a = this.R++;var b = new L(this, this.a, a, void 0),
c = this.i;this.L && (c ? (c = Fa(c), Ha(c, this.L)) : c = this.L);null === this.h && (b.j = c);var d = Ie(this, b),
e = M(this.D);R(e, "RID", a);R(e, "CVER", 22);this.o && this.j && R(e, "X-HTTP-Session-Id", this.j);Be(this, e);this.h && c && xe(e, this.h, c);ce(this.c, b);this.va ? (R(e, "$req", d), R(e, "SID", "null"), b.X = !0, Vc(b, e, null)) : Vc(b, e, d);this.F = 2;
}
} else 3 == this.F && (a ? Je(this, a) : 0 == this.g.length ? H(this.a, "startForwardChannel_ returned: nothing to send") : de(this.c) ? J(this.a, "startForwardChannel_ returned: connection already in progress") : (Je(this), H(this.a, "startForwardChannel_ finished, sent request")));
};
function Je(a, b) {
var c;b ? c = b.c : c = a.R++;var d = M(a.D);R(d, "SID", a.J);R(d, "RID", c);R(d, "AID", a.N);Be(a, d);a.h && a.i && xe(d, a.h, a.i);c = new L(a, a.a, c, a.v + 1);null === a.h && (c.j = a.i);b && (a.g = b.u.concat(a.g));b = Ie(a, c);c.setTimeout(Math.round(.5 * a.wa) + Math.round(.5 * a.wa * Math.random()));ce(a.c, c);Vc(c, d, b);
}function Be(a, b) {
a.f && md({}, function (a, d) {
R(b, d, a);
});
}
function Ie(a, b) {
var c = Math.min(a.g.length, 1E3),
d = a.f ? r(a.f.ab, a.f, a) : null;a: for (var e = a.g, f = -1;;) {
var h = ["count=" + c];-1 == f ? 0 < c ? (f = e[0].a, h.push("ofs=" + f)) : f = 0 : h.push("ofs=" + f);for (var m = !0, v = 0; v < c; v++) {
var I = e[v].a,
X = e[v].b;I -= f;if (0 > I) f = Math.max(0, e[v].a - 100), m = !1;else try {
ke(X, h, "req" + I + "_");
} catch (Mb) {
d && d(X);
}
}if (m) {
d = h.join("&");break a;
}
}a = a.g.splice(0, c);b.u = a;return d;
}function Ke(a) {
if (!a.b && !a.l) {
a.T = 1;var b = a.Pa;Tb || Ub();Wb || (Tb(), Wb = !0);Pb.add(b, a);a.B = 0;
}
}
function Le(a) {
if (a.b || a.l) return J(a.a, "Request already in progress"), !1;if (3 <= a.B) return !1;H(a.a, "Going to retry GET");a.T++;a.l = Ec(r(a.Pa, a), He(a, a.B));a.B++;return !0;
}
g.Pa = function () {
this.l = null;H(this.a, "Creating new HttpRequest");this.b = new L(this, this.a, "rpc", this.T);null === this.h && (this.b.j = this.i);this.b.N = 0;var a = M(this.ua);R(a, "RID", "rpc");R(a, "SID", this.J);R(a, "CI", this.ka ? "0" : "1");R(a, "AID", this.N);Be(this, a);R(a, "TYPE", "xmlhttp");this.h && this.i && xe(a, this.h, this.i);this.G && this.b.setTimeout(this.G);Yc(this.b, a, !0, this.X);H(this.a, "New Request created");
};
function Td(a, b, c) {
H(a.a, "Test Connection Finished");var d = b.l;d && be(a.c, d);a.ka = c;a.u = b.f;H(a.a, "connectChannel_()");a.D = Me(a, a.ja);Fe(a);
}function Vd(a, b) {
H(a.a, "Test Connection Failed");a.u = b.f;V(a, 2);
}
g.Oa = function (a, b) {
if (0 != this.F && (this.b == a || ee(this.c, a))) if (this.u = a.C, !a.v && ee(this.c, a) && 3 == this.F) {
try {
var c = this.la.a.parse(b);
} catch (f) {
c = null;
}if (p(c) && 3 == c.length) {
if (b = c, 0 == b[0]) {
a: if (H(this.a, "Server claims our backchannel is missing."), this.l) H(this.a, "But we are currently starting the request.");else {
if (this.b) {
if (this.b.D + 3E3 < a.D) De(this), this.b.cancel(), this.b = null;else break a;
} else D(this.a.a, "We do not have a BackChannel established");Le(this);K(18);
}
} else this.xa = b[1], a = this.xa - this.N, 0 < a && (b = b[2], H(this.a, b + " bytes (in " + a + " arrays) are outstanding on the BackChannel"), 37500 > b && this.ka && 0 == this.B && !this.s && (this.s = Ec(r(this.ib, this), 6E3)));
} else H(this.a, "Bad POST response data returned"), V(this, 11);
} else if ((a.v || this.b == a) && De(this), !xa(b)) for (b = c = this.la.a.parse(b), c = 0; c < b.length; c++) {
var d = b[c];this.N = d[0];d = d[1];if (2 == this.F) {
if ("c" == d[0]) {
this.J = d[1];this.X = d[2];var e = d[3];null != e && (this.na = e, F(this.a, "VER=" + this.na));e = d[4];null != e && (this.ya = e, F(this.a, "SVER=" + this.ya));d = d[5];null != d && "number" == typeof d && 0 < d && (this.G = d *= 1.5, F(this.a, "backChannelRequestTimeoutMs_=" + d));this.o && (d = a.a) && ((e = id(d, "X-Client-Wire-Protocol")) && be(this.c, e), this.j && ((d = id(d, "X-HTTP-Session-Id")) ? (this.K = d, R(this.D, this.j, d)) : D(this.a.a, "Missing X_HTTP_SESSION_ID in the handshake response")));this.F = 3;this.f && this.f.Da();d = a;this.ua = Ud(this, this.X, this.ja);d.v ? (H(this.a, "Upgrade the handshake request to a backchannel."), fe(this.c, d), (e = this.G) && d.setTimeout(e), d.s && (bd(d), Zc(d)), this.b = d) : Ke(this);
} else "stop" != d[0] && "close" != d[0] || V(this, 7);
} else 3 == this.F && ("stop" == d[0] || "close" == d[0] ? "stop" == d[0] ? V(this, 7) : ze(this) : "noop" != d[0] && this.f && this.f.Ca(d), this.B = 0);
}
};g.ib = function () {
null != this.s && (this.s = null, this.b.cancel(), this.b = null, Le(this), K(19));
};function De(a) {
null != a.s && (k.clearTimeout(a.s), a.s = null);
}
g.ta = function (a) {
H(this.a, "Request complete");var b = null;if (this.b == a) {
De(this);this.b = null;var c = 2;
} else if (ee(this.c, a)) b = a.u, fe(this.c, a), c = 1;else return;this.u = a.C;if (0 != this.F) if (a.f) 1 == c ? (Dc(a.l ? a.l.length : 0, t() - a.D, this.v), Fe(this)) : Ke(this);else {
var d = a.m;if (3 == d || 0 == d && 0 < this.u) H(this.a, "Not retrying due to error type");else {
var e = this;H(this.a, function () {
return "Maybe retrying, last error: " + Sc(d, e.u);
});if (1 == c && Ge(this, a) || 2 == c && Le(this)) return;H(this.a, "Exceeded max number of retries");
}b && 0 < b.length && he(this.c, b);H(this.a, "Error: HTTP request failed");switch (d) {case 1:
V(this, 5);break;case 4:
V(this, 10);break;case 3:
V(this, 6);break;default:
V(this, 2);}
}
};function He(a, b) {
var c = a.Wa + Math.floor(Math.random() * a.$a);a.qa() || (H(a.a, "Inactive channel"), c *= 2);return c * b;
}
function V(a, b) {
F(a.a, "Error code " + b);if (2 == b) {
var c = null;a.f && (c = null);var d = r(a.pb, a);c || (c = new Q("//www.google.com/images/cleardot.gif"), k.location && "http" == k.location.protocol || sd(c, "https"), Wc(c));le(c.toString(), d);
} else K(2);H(a.a, "HttpChannel: error - " + b);a.F = 0;a.f && a.f.Ba(b);Ce(a);Ae(a);
}g.pb = function (a) {
a ? (F(this.a, "Successfully pinged google.com"), K(2)) : (F(this.a, "Failed to ping google.com"), K(1));
};
function Ce(a) {
a.F = 0;a.u = -1;if (a.f) {
var b = ge(a.c);if (0 != b.length || 0 != a.g.length) H(a.a, function () {
return "Number of undelivered maps, pending: " + b.length + ", outgoing: " + a.g.length;
}), a.c.c.length = 0, wa(a.g), a.g.length = 0;a.f.Aa();
}
}function Me(a, b) {
b = Ne(a, null, b);H(a.a, "GetForwardChannelUri: " + b);return b;
}function Ud(a, b, c) {
b = Ne(a, a.ia() ? b : null, c);H(a.a, "GetBackChannelUri: " + b);return b;
}
function Ne(a, b, c) {
var d = Hd(c);if ("" != d.b) b && td(d, b + "." + d.b), ud(d, d.i);else {
var e = k.location,
f;b ? f = b + "." + e.hostname : f = e.hostname;d = Id(e.protocol, f, e.port, c);
}a.U && Ca(a.U, function (a, b) {
R(d, b, a);
});b = a.j;c = a.K;b && c && R(d, b, c);R(d, "VER", a.na);Be(a, d);return d;
}g.ca = function (a) {
if (a && !this.S) throw Error("Can't create secondary domain capable XhrIo object.");a = new T(this.Ta);a.o = this.S;return a;
};g.qa = function () {
return !!this.f && !0;
};g.ia = function () {
return this.S;
};new Qd();function Oe() {}g = Oe.prototype;g.Da = function () {};
g.Ca = function () {};g.Ba = function () {};g.Aa = function () {};g.ab = function () {};function Pe(a) {
for (var b = arguments[0], c = 1; c < arguments.length; c++) {
var d = arguments[c];if (0 == d.lastIndexOf("/", 0)) b = d;else {
var e;(e = "" == b) || (e = b.length - 1, e = 0 <= e && b.indexOf("/", e) == e);e ? b += d : b += "/" + d;
}
}return b;
};function Qe() {
if (z && !(10 <= Number(Wa))) throw Error("Environmental error: no available transport.");
}Qe.prototype.a = function (a, b) {
return new W(a, b);
};
function W(a, b) {
B.call(this);this.a = new ye(b);this.b = a;this.o = b && b.testUrl ? b.testUrl : Pe(this.b, "test");this.c = qc("goog.labs.net.webChannel.WebChannelBaseTransport");this.g = b && b.messageUrlParams || null;a = b && b.messageHeaders || null;b && b.clientProtocolHeaderRequired && (a ? a["X-Client-Protocol"] = "webchannel" : a = { "X-Client-Protocol": "webchannel" });this.a.i = a;a = b && b.initMessageHeaders || null;b && b.messageContentType && (a ? a["X-WebChannel-Content-Type"] = b.messageContentType : a = { "X-WebChannel-Content-Type": b.messageContentType });
b && b.Ea && (a ? a["X-WebChannel-Client-Profile"] = b.Ea : a = { "X-WebChannel-Client-Profile": b.Ea });this.a.L = a;(a = b && b.httpHeadersOverwriteParam) && !xa(a) && (this.a.h = a);this.l = b && b.supportsCrossDomainXhr || !1;this.j = b && b.sendRawJson || !1;(b = b && b.httpSessionIdParam) && !xa(b) && (this.a.j = b, a = this.g, null !== a && b in a && (a = this.g, b in a && delete a[b], D(this.c, "Ignore httpSessionIdParam also specified with messageUrlParams: " + b)));this.h = new Re(this);
}u(W, B);g = W.prototype;
g.addEventListener = function (a, b, c, d) {
W.H.addEventListener.call(this, a, b, c, d);
};g.removeEventListener = function (a, b, c, d) {
W.H.removeEventListener.call(this, a, b, c, d);
};
g.fb = function () {
this.a.f = this.h;this.l && (this.a.S = !0);var a = this.a,
b = this.o,
c = this.b,
d = this.g || void 0;H(a.a, "connect()");K(0);a.ja = c;a.U = d || {};a.o && (H(a.a, "connect() bypassed channel-test."), a.I.b = [], a.I.a = !1);H(a.a, "connectTest_()");a.C = new Rd(a, a.a);null === a.h && (a.C.i = a.i);c = b;a.h && a.i && (c = xe(b, a.h, a.i));a = a.C;a.m = c;b = Me(a.a, a.m);K(3);c = a.a.I.b;null != c ? (a.g = c[0], a.P = 1, Sd(a)) : ($c(b, "MODE", "init"), !a.a.o && a.a.j && $c(b, "X-HTTP-Session-Id", a.a.j), a.c = new L(a, a.b, void 0, void 0), a.c.j = a.i, Yc(a.c, b, !1, null), a.P = 0);
};g.close = function () {
ze(this.a);
};g.gb = function (a) {
if (l(a)) {
var b = {};b.__data__ = a;Ee(this.a, b);
} else this.j ? (b = {}, b.__data__ = Db(a), Ee(this.a, b)) : Ee(this.a, a);
};g.w = function () {
this.a.f = null;delete this.h;ze(this.a);delete this.a;W.H.w.call(this);
};function Se(a) {
Mc.call(this);var b = a.__sm__;if (b) {
a: {
for (var c in b) {
a = c;break a;
}a = void 0;
}(this.c = a) ? (a = this.c, this.data = null !== b && a in b ? b[a] : void 0) : this.data = b;
} else this.data = a;
}u(Se, Mc);function Te() {
Nc.call(this);this.status = 1;
}u(Te, Nc);
function Re(a) {
this.a = a;
}u(Re, Oe);Re.prototype.Da = function () {
rc(this.a.c, "WebChannel opened on " + this.a.b);this.a.dispatchEvent("a");
};Re.prototype.Ca = function (a) {
this.a.dispatchEvent(new Se(a));
};Re.prototype.Ba = function (a) {
rc(this.a.c, "WebChannel aborted on " + this.a.b + " due to channel error: " + a);this.a.dispatchEvent(new Te(a));
};Re.prototype.Aa = function () {
rc(this.a.c, "WebChannel closed on " + this.a.b);this.a.dispatchEvent("b");
};var Ue = ja(function (a, b) {
function c() {}c.prototype = a.prototype;var d = new c();a.apply(d, Array.prototype.slice.call(arguments, 1));return d;
}, Qe);function Ve() {
this.b = [];this.a = [];
}function We(a) {
0 == a.b.length && (a.b = a.a, a.b.reverse(), a.a = []);return a.b.pop();
}function Xe(a) {
return a.b.length + a.a.length;
}Ve.prototype.A = function () {
for (var a = [], b = this.b.length - 1; 0 <= b; --b) a.push(this.b[b]);var c = this.a.length;for (b = 0; b < c; ++b) a.push(this.a[b]);return a;
};function Ye(a, b) {
w.call(this);this.h = a || 0;this.c = b || 10;if (this.h > this.c) throw Error(Ze);this.a = new Ve();this.b = new Xd();this.g = null;this.aa();
}u(Ye, w);var Ze = "[goog.structs.Pool] Min can not be greater than max";g = Ye.prototype;g.da = function () {
var a = t();if (!(null != this.g && 0 > a - this.g)) {
for (var b; 0 < Xe(this.a) && (b = We(this.a), !this.sa(b));) this.aa();!b && $e(this) < this.c && (b = this.pa());b && (this.g = a, this.b.add(b));return b;
}
};g.ob = function (a) {
return pd(this.b.a, Yd(a)) ? (this.ma(a), !0) : !1;
};
g.ma = function (a) {
pd(this.b.a, Yd(a));this.sa(a) && $e(this) < this.c ? this.a.a.push(a) : af(a);
};g.aa = function () {
for (var a = this.a; $e(this) < this.h;) {
var b = this.pa();a.a.push(b);
}for (; $e(this) > this.c && 0 < Xe(this.a);) af(We(a));
};g.pa = function () {
return {};
};function af(a) {
if ("function" == typeof a.$) a.$();else for (var b in a) a[b] = null;
}g.sa = function (a) {
return "function" == typeof a.bb ? a.bb() : !0;
};function $e(a) {
return Xe(a.a) + a.b.a.c;
}
g.w = function () {
Ye.H.w.call(this);if (0 < this.b.a.c) throw Error("[goog.structs.Pool] Objects not released");delete this.b;for (var a = this.a; 0 != a.b.length || 0 != a.a.length;) af(We(a));delete this.a;
};function bf(a, b) {
this.a = a;this.b = b;
};function cf(a) {
this.a = [];if (a) a: {
if (a instanceof cf) {
var b = a.M();a = a.A();if (0 >= this.a.length) {
for (var c = this.a, d = 0; d < b.length; d++) c.push(new bf(b[d], a[d]));break a;
}
} else b = Ea(a), a = Da(a);for (d = 0; d < b.length; d++) df(this, b[d], a[d]);
}
}function df(a, b, c) {
var d = a.a;d.push(new bf(b, c));b = d.length - 1;a = a.a;for (c = a[b]; 0 < b;) if (d = b - 1 >> 1, a[d].a > c.a) a[b] = a[d], b = d;else break;a[b] = c;
}cf.prototype.A = function () {
for (var a = this.a, b = [], c = a.length, d = 0; d < c; d++) b.push(a[d].b);return b;
};
cf.prototype.M = function () {
for (var a = this.a, b = [], c = a.length, d = 0; d < c; d++) b.push(a[d].a);return b;
};function ef() {
cf.call(this);
}u(ef, cf);function Y(a, b) {
this.f = new ef();Ye.call(this, a, b);
}u(Y, Ye);g = Y.prototype;g.da = function (a, b) {
if (!a) return Y.H.da.call(this);df(this.f, void 0 !== b ? b : 100, a);this.ra();
};g.ra = function () {
for (var a = this.f; 0 < a.a.length;) {
var b = this.da();if (b) {
var c = a,
d = c.a,
e = d.length;var f = d[0];if (0 >= e) f = void 0;else {
if (1 == e) ua(d);else {
d[0] = d.pop();d = 0;c = c.a;e = c.length;for (var h = c[d]; d < e >> 1;) {
var m = 2 * d + 1,
v = 2 * d + 2;m = v < e && c[v].a < c[m].a ? v : m;if (c[m].a > h.a) break;c[d] = c[m];d = m;
}c[d] = h;
}f = f.b;
}f.apply(this, [b]);
} else break;
}
};
g.ma = function (a) {
Y.H.ma.call(this, a);this.ra();
};g.aa = function () {
Y.H.aa.call(this);this.ra();
};g.w = function () {
Y.H.w.call(this);k.clearTimeout(void 0);ua(this.f.a);this.f = null;
};function Z(a, b, c, d) {
this.l = a;this.j = !!d;Y.call(this, b, c);
}u(Z, Y);Z.prototype.pa = function () {
var a = new T(),
b = this.l;b && b.forEach(function (b, d) {
a.headers.set(d, b);
});this.j && (a.o = !0);return a;
};Z.prototype.sa = function (a) {
return !a.i && !a.a;
};Qe.prototype.createWebChannel = Qe.prototype.a;W.prototype.send = W.prototype.gb;W.prototype.open = W.prototype.fb;W.prototype.close = W.prototype.close;Fc.NO_ERROR = 0;Fc.TIMEOUT = 8;Fc.HTTP_ERROR = 6;Gc.COMPLETE = "complete";Kc.EventType = Lc;Lc.OPEN = "a";Lc.CLOSE = "b";Lc.ERROR = "c";Lc.MESSAGE = "d";B.prototype.listen = B.prototype.Ia;Z.prototype.getObject = Z.prototype.da;Z.prototype.releaseObject = Z.prototype.ob;T.prototype.listenOnce = T.prototype.Ja;T.prototype.getLastError = T.prototype.hb;T.prototype.getLastErrorCode = T.prototype.Ga;
T.prototype.getStatus = T.prototype.W;T.prototype.getStatusText = T.prototype.Ha;T.prototype.getResponseJson = T.prototype.eb;T.prototype.getResponseText = T.prototype.V;T.prototype.getResponseText = T.prototype.V;T.prototype.send = T.prototype.fa;module.exports = { createWebChannelTransport: Ue, ErrorCode: Fc, EventType: Gc, WebChannel: Kc, XhrIoPool: Z };
}).call(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__("h6ac")))
/***/ }),
/***/ "IYZm":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("LiPu"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "./xml-hint"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var langs = "ab aa af ak sq am ar an hy as av ae ay az bm ba eu be bn bh bi bs br bg my ca ch ce ny zh cv kw co cr hr cs da dv nl dz en eo et ee fo fj fi fr ff gl ka de el gn gu ht ha he hz hi ho hu ia id ie ga ig ik io is it iu ja jv kl kn kr ks kk km ki rw ky kv kg ko ku kj la lb lg li ln lo lt lu lv gv mk mg ms ml mt mi mr mh mn na nv nb nd ne ng nn no ii nr oc oj cu om or os pa pi fa pl ps pt qu rm rn ro ru sa sc sd se sm sg sr gd sn si sk sl so st es su sw ss sv ta te tg th ti bo tk tl tn to tr ts tt tw ty ug uk ur uz ve vi vo wa cy wo fy xh yi yo za zu".split(" ");
var targets = ["_blank", "_self", "_top", "_parent"];
var charsets = ["ascii", "utf-8", "utf-16", "latin1", "latin1"];
var methods = ["get", "post", "put", "delete"];
var encs = ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"];
var media = ["all", "screen", "print", "embossed", "braille", "handheld", "print", "projection", "screen", "tty", "tv", "speech", "3d-glasses", "resolution [>][<][=] [X]", "device-aspect-ratio: X/Y", "orientation:portrait", "orientation:landscape", "device-height: [X]", "device-width: [X]"];
var s = { attrs: {} }; // Simple tag, reused for a whole lot of tags
var data = {
a: {
attrs: {
href: null, ping: null, type: null,
media: media,
target: targets,
hreflang: langs
}
},
abbr: s,
acronym: s,
address: s,
applet: s,
area: {
attrs: {
alt: null, coords: null, href: null, target: null, ping: null,
media: media, hreflang: langs, type: null,
shape: ["default", "rect", "circle", "poly"]
}
},
article: s,
aside: s,
audio: {
attrs: {
src: null, mediagroup: null,
crossorigin: ["anonymous", "use-credentials"],
preload: ["none", "metadata", "auto"],
autoplay: ["", "autoplay"],
loop: ["", "loop"],
controls: ["", "controls"]
}
},
b: s,
base: { attrs: { href: null, target: targets } },
basefont: s,
bdi: s,
bdo: s,
big: s,
blockquote: { attrs: { cite: null } },
body: s,
br: s,
button: {
attrs: {
form: null, formaction: null, name: null, value: null,
autofocus: ["", "autofocus"],
disabled: ["", "autofocus"],
formenctype: encs,
formmethod: methods,
formnovalidate: ["", "novalidate"],
formtarget: targets,
type: ["submit", "reset", "button"]
}
},
canvas: { attrs: { width: null, height: null } },
caption: s,
center: s,
cite: s,
code: s,
col: { attrs: { span: null } },
colgroup: { attrs: { span: null } },
command: {
attrs: {
type: ["command", "checkbox", "radio"],
label: null, icon: null, radiogroup: null, command: null, title: null,
disabled: ["", "disabled"],
checked: ["", "checked"]
}
},
data: { attrs: { value: null } },
datagrid: { attrs: { disabled: ["", "disabled"], multiple: ["", "multiple"] } },
datalist: { attrs: { data: null } },
dd: s,
del: { attrs: { cite: null, datetime: null } },
details: { attrs: { open: ["", "open"] } },
dfn: s,
dir: s,
div: s,
dl: s,
dt: s,
em: s,
embed: { attrs: { src: null, type: null, width: null, height: null } },
eventsource: { attrs: { src: null } },
fieldset: { attrs: { disabled: ["", "disabled"], form: null, name: null } },
figcaption: s,
figure: s,
font: s,
footer: s,
form: {
attrs: {
action: null, name: null,
"accept-charset": charsets,
autocomplete: ["on", "off"],
enctype: encs,
method: methods,
novalidate: ["", "novalidate"],
target: targets
}
},
frame: s,
frameset: s,
h1: s, h2: s, h3: s, h4: s, h5: s, h6: s,
head: {
attrs: {},
children: ["title", "base", "link", "style", "meta", "script", "noscript", "command"]
},
header: s,
hgroup: s,
hr: s,
html: {
attrs: { manifest: null },
children: ["head", "body"]
},
i: s,
iframe: {
attrs: {
src: null, srcdoc: null, name: null, width: null, height: null,
sandbox: ["allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts"],
seamless: ["", "seamless"]
}
},
img: {
attrs: {
alt: null, src: null, ismap: null, usemap: null, width: null, height: null,
crossorigin: ["anonymous", "use-credentials"]
}
},
input: {
attrs: {
alt: null, dirname: null, form: null, formaction: null,
height: null, list: null, max: null, maxlength: null, min: null,
name: null, pattern: null, placeholder: null, size: null, src: null,
step: null, value: null, width: null,
accept: ["audio/*", "video/*", "image/*"],
autocomplete: ["on", "off"],
autofocus: ["", "autofocus"],
checked: ["", "checked"],
disabled: ["", "disabled"],
formenctype: encs,
formmethod: methods,
formnovalidate: ["", "novalidate"],
formtarget: targets,
multiple: ["", "multiple"],
readonly: ["", "readonly"],
required: ["", "required"],
type: ["hidden", "text", "search", "tel", "url", "email", "password", "datetime", "date", "month", "week", "time", "datetime-local", "number", "range", "color", "checkbox", "radio", "file", "submit", "image", "reset", "button"]
}
},
ins: { attrs: { cite: null, datetime: null } },
kbd: s,
keygen: {
attrs: {
challenge: null, form: null, name: null,
autofocus: ["", "autofocus"],
disabled: ["", "disabled"],
keytype: ["RSA"]
}
},
label: { attrs: { "for": null, form: null } },
legend: s,
li: { attrs: { value: null } },
link: {
attrs: {
href: null, type: null,
hreflang: langs,
media: media,
sizes: ["all", "16x16", "16x16 32x32", "16x16 32x32 64x64"]
}
},
map: { attrs: { name: null } },
mark: s,
menu: { attrs: { label: null, type: ["list", "context", "toolbar"] } },
meta: {
attrs: {
content: null,
charset: charsets,
name: ["viewport", "application-name", "author", "description", "generator", "keywords"],
"http-equiv": ["content-language", "content-type", "default-style", "refresh"]
}
},
meter: { attrs: { value: null, min: null, low: null, high: null, max: null, optimum: null } },
nav: s,
noframes: s,
noscript: s,
object: {
attrs: {
data: null, type: null, name: null, usemap: null, form: null, width: null, height: null,
typemustmatch: ["", "typemustmatch"]
}
},
ol: { attrs: { reversed: ["", "reversed"], start: null, type: ["1", "a", "A", "i", "I"] } },
optgroup: { attrs: { disabled: ["", "disabled"], label: null } },
option: { attrs: { disabled: ["", "disabled"], label: null, selected: ["", "selected"], value: null } },
output: { attrs: { "for": null, form: null, name: null } },
p: s,
param: { attrs: { name: null, value: null } },
pre: s,
progress: { attrs: { value: null, max: null } },
q: { attrs: { cite: null } },
rp: s,
rt: s,
ruby: s,
s: s,
samp: s,
script: {
attrs: {
type: ["text/javascript"],
src: null,
async: ["", "async"],
defer: ["", "defer"],
charset: charsets
}
},
section: s,
select: {
attrs: {
form: null, name: null, size: null,
autofocus: ["", "autofocus"],
disabled: ["", "disabled"],
multiple: ["", "multiple"]
}
},
small: s,
source: { attrs: { src: null, type: null, media: null } },
span: s,
strike: s,
strong: s,
style: {
attrs: {
type: ["text/css"],
media: media,
scoped: null
}
},
sub: s,
summary: s,
sup: s,
table: s,
tbody: s,
td: { attrs: { colspan: null, rowspan: null, headers: null } },
textarea: {
attrs: {
dirname: null, form: null, maxlength: null, name: null, placeholder: null,
rows: null, cols: null,
autofocus: ["", "autofocus"],
disabled: ["", "disabled"],
readonly: ["", "readonly"],
required: ["", "required"],
wrap: ["soft", "hard"]
}
},
tfoot: s,
th: { attrs: { colspan: null, rowspan: null, headers: null, scope: ["row", "col", "rowgroup", "colgroup"] } },
thead: s,
time: { attrs: { datetime: null } },
title: s,
tr: s,
track: {
attrs: {
src: null, label: null, "default": null,
kind: ["subtitles", "captions", "descriptions", "chapters", "metadata"],
srclang: langs
}
},
tt: s,
u: s,
ul: s,
"var": s,
video: {
attrs: {
src: null, poster: null, width: null, height: null,
crossorigin: ["anonymous", "use-credentials"],
preload: ["auto", "metadata", "none"],
autoplay: ["", "autoplay"],
mediagroup: ["movie"],
muted: ["", "muted"],
controls: ["", "controls"]
}
},
wbr: s
};
var globalAttrs = {
accesskey: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
"class": null,
contenteditable: ["true", "false"],
contextmenu: null,
dir: ["ltr", "rtl", "auto"],
draggable: ["true", "false", "auto"],
dropzone: ["copy", "move", "link", "string:", "file:"],
hidden: ["hidden"],
id: null,
inert: ["inert"],
itemid: null,
itemprop: null,
itemref: null,
itemscope: ["itemscope"],
itemtype: null,
lang: ["en", "es"],
spellcheck: ["true", "false"],
style: null,
tabindex: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
title: null,
translate: ["yes", "no"],
onclick: null,
rel: ["stylesheet", "alternate", "author", "bookmark", "help", "license", "next", "nofollow", "noreferrer", "prefetch", "prev", "search", "tag"]
};
function populate(obj) {
for (var attr in globalAttrs) if (globalAttrs.hasOwnProperty(attr)) obj.attrs[attr] = globalAttrs[attr];
}
populate(s);
for (var tag in data) if (data.hasOwnProperty(tag) && data[tag] != s) populate(data[tag]);
CodeMirror.htmlSchema = data;
function htmlHint(cm, options) {
var local = { schemaInfo: data };
if (options) for (var opt in options) local[opt] = options[opt];
return CodeMirror.hint.xml(cm, local);
}
CodeMirror.registerHelper("hint", "html", htmlHint);
});
/***/ }),
/***/ "Jo/m":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Define search commands. Depends on dialog.js or another
// implementation of the openDialog method.
// Replace works a little oddly -- it will do the replace on the next
// Ctrl-G (or whatever is bound to findNext) press. You prevent a
// replace by making sure the match is no longer selected when hitting
// Ctrl-G.
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("29F7"), __webpack_require__("4e7A"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "./searchcursor", "../dialog/dialog"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
function searchOverlay(query, caseInsensitive) {
if (typeof query == "string") query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");else if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
return { token: function (stream) {
query.lastIndex = stream.pos;
var match = query.exec(stream.string);
if (match && match.index == stream.pos) {
stream.pos += match[0].length || 1;
return "searching";
} else if (match) {
stream.pos = match.index;
} else {
stream.skipToEnd();
}
} };
}
function SearchState() {
this.posFrom = this.posTo = this.lastQuery = this.query = null;
this.overlay = null;
}
function getSearchState(cm) {
return cm.state.search || (cm.state.search = new SearchState());
}
function queryCaseInsensitive(query) {
return typeof query == "string" && query == query.toLowerCase();
}
function getSearchCursor(cm, query, pos) {
// Heuristic: if the query string is all lowercase, do a case insensitive search.
return cm.getSearchCursor(query, pos, { caseFold: queryCaseInsensitive(query), multiline: true });
}
function persistentDialog(cm, text, deflt, onEnter, onKeyDown) {
cm.openDialog(text, onEnter, {
value: deflt,
selectValueOnOpen: true,
closeOnEnter: false,
onClose: function () {
clearSearch(cm);
},
onKeyDown: onKeyDown
});
}
function dialog(cm, text, shortText, deflt, f) {
if (cm.openDialog) cm.openDialog(text, f, { value: deflt, selectValueOnOpen: true });else f(prompt(shortText, deflt));
}
function confirmDialog(cm, text, shortText, fs) {
if (cm.openConfirm) cm.openConfirm(text, fs);else if (confirm(shortText)) fs[0]();
}
function parseString(string) {
return string.replace(/\\(.)/g, function (_, ch) {
if (ch == "n") return "\n";
if (ch == "r") return "\r";
return ch;
});
}
function parseQuery(query) {
var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
if (isRE) {
try {
query = new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i");
} catch (e) {} // Not a regular expression after all, do a string search
} else {
query = parseString(query);
}
if (typeof query == "string" ? query == "" : query.test("")) query = /x^/;
return query;
}
var queryDialog = '<span class="CodeMirror-search-label">Search:</span> <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
function startSearch(cm, state, query) {
state.queryText = query;
state.query = parseQuery(query);
cm.removeOverlay(state.overlay, queryCaseInsensitive(state.query));
state.overlay = searchOverlay(state.query, queryCaseInsensitive(state.query));
cm.addOverlay(state.overlay);
if (cm.showMatchesOnScrollbar) {
if (state.annotate) {
state.annotate.clear();state.annotate = null;
}
state.annotate = cm.showMatchesOnScrollbar(state.query, queryCaseInsensitive(state.query));
}
}
function doSearch(cm, rev, persistent, immediate) {
var state = getSearchState(cm);
if (state.query) return findNext(cm, rev);
var q = cm.getSelection() || state.lastQuery;
if (q instanceof RegExp && q.source == "x^") q = null;
if (persistent && cm.openDialog) {
var hiding = null;
var searchNext = function (query, event) {
CodeMirror.e_stop(event);
if (!query) return;
if (query != state.queryText) {
startSearch(cm, state, query);
state.posFrom = state.posTo = cm.getCursor();
}
if (hiding) hiding.style.opacity = 1;
findNext(cm, event.shiftKey, function (_, to) {
var dialog;
if (to.line < 3 && document.querySelector && (dialog = cm.display.wrapper.querySelector(".CodeMirror-dialog")) && dialog.getBoundingClientRect().bottom - 4 > cm.cursorCoords(to, "window").top) (hiding = dialog).style.opacity = .4;
});
};
persistentDialog(cm, queryDialog, q, searchNext, function (event, query) {
var keyName = CodeMirror.keyName(event);
var extra = cm.getOption('extraKeys'),
cmd = extra && extra[keyName] || CodeMirror.keyMap[cm.getOption("keyMap")][keyName];
if (cmd == "findNext" || cmd == "findPrev" || cmd == "findPersistentNext" || cmd == "findPersistentPrev") {
CodeMirror.e_stop(event);
startSearch(cm, getSearchState(cm), query);
cm.execCommand(cmd);
} else if (cmd == "find" || cmd == "findPersistent") {
CodeMirror.e_stop(event);
searchNext(query, event);
}
});
if (immediate && q) {
startSearch(cm, state, q);
findNext(cm, rev);
}
} else {
dialog(cm, queryDialog, "Search for:", q, function (query) {
if (query && !state.query) cm.operation(function () {
startSearch(cm, state, query);
state.posFrom = state.posTo = cm.getCursor();
findNext(cm, rev);
});
});
}
}
function findNext(cm, rev, callback) {
cm.operation(function () {
var state = getSearchState(cm);
var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
if (!cursor.find(rev)) {
cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
if (!cursor.find(rev)) return;
}
cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({ from: cursor.from(), to: cursor.to() }, 20);
state.posFrom = cursor.from();state.posTo = cursor.to();
if (callback) callback(cursor.from(), cursor.to());
});
}
function clearSearch(cm) {
cm.operation(function () {
var state = getSearchState(cm);
state.lastQuery = state.query;
if (!state.query) return;
state.query = state.queryText = null;
cm.removeOverlay(state.overlay);
if (state.annotate) {
state.annotate.clear();state.annotate = null;
}
});
}
var replaceQueryDialog = ' <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
var replacementQueryDialog = '<span class="CodeMirror-search-label">With:</span> <input type="text" style="width: 10em" class="CodeMirror-search-field"/>';
var doReplaceConfirm = '<span class="CodeMirror-search-label">Replace?</span> <button>Yes</button> <button>No</button> <button>All</button> <button>Stop</button>';
function replaceAll(cm, query, text) {
cm.operation(function () {
for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
if (typeof query != "string") {
var match = cm.getRange(cursor.from(), cursor.to()).match(query);
cursor.replace(text.replace(/\$(\d)/g, function (_, i) {
return match[i];
}));
} else cursor.replace(text);
}
});
}
function replace(cm, all) {
if (cm.getOption("readOnly")) return;
var query = cm.getSelection() || getSearchState(cm).lastQuery;
var dialogText = '<span class="CodeMirror-search-label">' + (all ? 'Replace all:' : 'Replace:') + '</span>';
dialog(cm, dialogText + replaceQueryDialog, dialogText, query, function (query) {
if (!query) return;
query = parseQuery(query);
dialog(cm, replacementQueryDialog, "Replace with:", "", function (text) {
text = parseString(text);
if (all) {
replaceAll(cm, query, text);
} else {
clearSearch(cm);
var cursor = getSearchCursor(cm, query, cm.getCursor("from"));
var advance = function () {
var start = cursor.from(),
match;
if (!(match = cursor.findNext())) {
cursor = getSearchCursor(cm, query);
if (!(match = cursor.findNext()) || start && cursor.from().line == start.line && cursor.from().ch == start.ch) return;
}
cm.setSelection(cursor.from(), cursor.to());
cm.scrollIntoView({ from: cursor.from(), to: cursor.to() });
confirmDialog(cm, doReplaceConfirm, "Replace?", [function () {
doReplace(match);
}, advance, function () {
replaceAll(cm, query, text);
}]);
};
var doReplace = function (match) {
cursor.replace(typeof query == "string" ? text : text.replace(/\$(\d)/g, function (_, i) {
return match[i];
}));
advance();
};
advance();
}
});
});
}
CodeMirror.commands.find = function (cm) {
clearSearch(cm);doSearch(cm);
};
CodeMirror.commands.findPersistent = function (cm) {
clearSearch(cm);doSearch(cm, false, true);
};
CodeMirror.commands.findPersistentNext = function (cm) {
doSearch(cm, false, true, true);
};
CodeMirror.commands.findPersistentPrev = function (cm) {
doSearch(cm, true, true, true);
};
CodeMirror.commands.findNext = doSearch;
CodeMirror.commands.findPrev = function (cm) {
doSearch(cm, true);
};
CodeMirror.commands.clearSearch = clearSearch;
CodeMirror.commands.replace = replace;
CodeMirror.commands.replaceAll = function (cm) {
replace(cm, true);
};
});
/***/ }),
/***/ "KM04":
/***/ (function(module, exports, __webpack_require__) {
!function () {
"use strict";
function e() {}function t(t, n) {
var o,
r,
i,
l,
a = E;for (l = arguments.length; l-- > 2;) W.push(arguments[l]);n && null != n.children && (W.length || W.push(n.children), delete n.children);while (W.length) if ((r = W.pop()) && void 0 !== r.pop) for (l = r.length; l--;) W.push(r[l]);else "boolean" == typeof r && (r = null), (i = "function" != typeof t) && (null == r ? r = "" : "number" == typeof r ? r += "" : "string" != typeof r && (i = !1)), i && o ? a[a.length - 1] += r : a === E ? a = [r] : a.push(r), o = i;var u = new e();return u.nodeName = t, u.children = a, u.attributes = null == n ? void 0 : n, u.key = null == n ? void 0 : n.key, void 0 !== S.vnode && S.vnode(u), u;
}function n(e, t) {
for (var n in t) e[n] = t[n];return e;
}function o(e, o) {
return t(e.nodeName, n(n({}, e.attributes), o), arguments.length > 2 ? [].slice.call(arguments, 2) : e.children);
}function r(e) {
!e.__d && (e.__d = !0) && 1 == A.push(e) && (S.debounceRendering || P)(i);
}function i() {
var e,
t = A;A = [];while (e = t.pop()) e.__d && k(e);
}function l(e, t, n) {
return "string" == typeof t || "number" == typeof t ? void 0 !== e.splitText : "string" == typeof t.nodeName ? !e._componentConstructor && a(e, t.nodeName) : n || e._componentConstructor === t.nodeName;
}function a(e, t) {
return e.__n === t || e.nodeName.toLowerCase() === t.toLowerCase();
}function u(e) {
var t = n({}, e.attributes);t.children = e.children;var o = e.nodeName.defaultProps;if (void 0 !== o) for (var r in o) void 0 === t[r] && (t[r] = o[r]);return t;
}function _(e, t) {
var n = t ? document.createElementNS("http://www.w3.org/2000/svg", e) : document.createElement(e);return n.__n = e, n;
}function p(e) {
var t = e.parentNode;t && t.removeChild(e);
}function c(e, t, n, o, r) {
if ("className" === t && (t = "class"), "key" === t) ;else if ("ref" === t) n && n(null), o && o(e);else if ("class" !== t || r) {
if ("style" === t) {
if (o && "string" != typeof o && "string" != typeof n || (e.style.cssText = o || ""), o && "object" == typeof o) {
if ("string" != typeof n) for (var i in n) i in o || (e.style[i] = "");for (var i in o) e.style[i] = "number" == typeof o[i] && !1 === V.test(i) ? o[i] + "px" : o[i];
}
} else if ("dangerouslySetInnerHTML" === t) o && (e.innerHTML = o.__html || "");else if ("o" == t[0] && "n" == t[1]) {
var l = t !== (t = t.replace(/Capture$/, ""));t = t.toLowerCase().substring(2), o ? n || e.addEventListener(t, f, l) : e.removeEventListener(t, f, l), (e.__l || (e.__l = {}))[t] = o;
} else if ("list" !== t && "type" !== t && !r && t in e) s(e, t, null == o ? "" : o), null != o && !1 !== o || e.removeAttribute(t);else {
var a = r && t !== (t = t.replace(/^xlink:?/, ""));null == o || !1 === o ? a ? e.removeAttributeNS("http://www.w3.org/1999/xlink", t.toLowerCase()) : e.removeAttribute(t) : "function" != typeof o && (a ? e.setAttributeNS("http://www.w3.org/1999/xlink", t.toLowerCase(), o) : e.setAttribute(t, o));
}
} else e.className = o || "";
}function s(e, t, n) {
try {
e[t] = n;
} catch (e) {}
}function f(e) {
return this.__l[e.type](S.event && S.event(e) || e);
}function d() {
var e;while (e = D.pop()) S.afterMount && S.afterMount(e), e.componentDidMount && e.componentDidMount();
}function h(e, t, n, o, r, i) {
H++ || (R = null != r && void 0 !== r.ownerSVGElement, j = null != e && !("__preactattr_" in e));var l = m(e, t, n, o, i);return r && l.parentNode !== r && r.appendChild(l), --H || (j = !1, i || d()), l;
}function m(e, t, n, o, r) {
var i = e,
l = R;if (null != t && "boolean" != typeof t || (t = ""), "string" == typeof t || "number" == typeof t) return e && void 0 !== e.splitText && e.parentNode && (!e._component || r) ? e.nodeValue != t && (e.nodeValue = t) : (i = document.createTextNode(t), e && (e.parentNode && e.parentNode.replaceChild(i, e), b(e, !0))), i.__preactattr_ = !0, i;var u = t.nodeName;if ("function" == typeof u) return U(e, t, n, o);if (R = "svg" === u || "foreignObject" !== u && R, u += "", (!e || !a(e, u)) && (i = _(u, R), e)) {
while (e.firstChild) i.appendChild(e.firstChild);e.parentNode && e.parentNode.replaceChild(i, e), b(e, !0);
}var p = i.firstChild,
c = i.__preactattr_,
s = t.children;if (null == c) {
c = i.__preactattr_ = {};for (var f = i.attributes, d = f.length; d--;) c[f[d].name] = f[d].value;
}return !j && s && 1 === s.length && "string" == typeof s[0] && null != p && void 0 !== p.splitText && null == p.nextSibling ? p.nodeValue != s[0] && (p.nodeValue = s[0]) : (s && s.length || null != p) && v(i, s, n, o, j || null != c.dangerouslySetInnerHTML), g(i, t.attributes, c), R = l, i;
}function v(e, t, n, o, r) {
var i,
a,
u,
_,
c,
s = e.childNodes,
f = [],
d = {},
h = 0,
v = 0,
y = s.length,
g = 0,
w = t ? t.length : 0;if (0 !== y) for (var C = 0; C < y; C++) {
var x = s[C],
N = x.__preactattr_,
k = w && N ? x._component ? x._component.__k : N.key : null;null != k ? (h++, d[k] = x) : (N || (void 0 !== x.splitText ? !r || x.nodeValue.trim() : r)) && (f[g++] = x);
}if (0 !== w) for (var C = 0; C < w; C++) {
_ = t[C], c = null;var k = _.key;if (null != k) h && void 0 !== d[k] && (c = d[k], d[k] = void 0, h--);else if (!c && v < g) for (i = v; i < g; i++) if (void 0 !== f[i] && l(a = f[i], _, r)) {
c = a, f[i] = void 0, i === g - 1 && g--, i === v && v++;break;
}c = m(c, _, n, o), u = s[C], c && c !== e && c !== u && (null == u ? e.appendChild(c) : c === u.nextSibling ? p(u) : e.insertBefore(c, u));
}if (h) for (var C in d) void 0 !== d[C] && b(d[C], !1);while (v <= g) void 0 !== (c = f[g--]) && b(c, !1);
}function b(e, t) {
var n = e._component;n ? L(n) : (null != e.__preactattr_ && e.__preactattr_.ref && e.__preactattr_.ref(null), !1 !== t && null != e.__preactattr_ || p(e), y(e));
}function y(e) {
e = e.lastChild;while (e) {
var t = e.previousSibling;b(e, !0), e = t;
}
}function g(e, t, n) {
var o;for (o in n) t && null != t[o] || null == n[o] || c(e, o, n[o], n[o] = void 0, R);for (o in t) "children" === o || "innerHTML" === o || o in n && t[o] === ("value" === o || "checked" === o ? e[o] : n[o]) || c(e, o, n[o], n[o] = t[o], R);
}function w(e) {
var t = e.constructor.name;(I[t] || (I[t] = [])).push(e);
}function C(e, t, n) {
var o,
r = I[e.name];if (e.prototype && e.prototype.render ? (o = new e(t, n), T.call(o, t, n)) : (o = new T(t, n), o.constructor = e, o.render = x), r) for (var i = r.length; i--;) if (r[i].constructor === e) {
o.__b = r[i].__b, r.splice(i, 1);break;
}return o;
}function x(e, t, n) {
return this.constructor(e, n);
}function N(e, t, n, o, i) {
e.__x || (e.__x = !0, (e.__r = t.ref) && delete t.ref, (e.__k = t.key) && delete t.key, !e.base || i ? e.componentWillMount && e.componentWillMount() : e.componentWillReceiveProps && e.componentWillReceiveProps(t, o), o && o !== e.context && (e.__c || (e.__c = e.context), e.context = o), e.__p || (e.__p = e.props), e.props = t, e.__x = !1, 0 !== n && (1 !== n && !1 === S.syncComponentUpdates && e.base ? r(e) : k(e, 1, i)), e.__r && e.__r(e));
}function k(e, t, o, r) {
if (!e.__x) {
var i,
l,
a,
_ = e.props,
p = e.state,
c = e.context,
s = e.__p || _,
f = e.__s || p,
m = e.__c || c,
v = e.base,
y = e.__b,
g = v || y,
w = e._component,
x = !1;if (v && (e.props = s, e.state = f, e.context = m, 2 !== t && e.shouldComponentUpdate && !1 === e.shouldComponentUpdate(_, p, c) ? x = !0 : e.componentWillUpdate && e.componentWillUpdate(_, p, c), e.props = _, e.state = p, e.context = c), e.__p = e.__s = e.__c = e.__b = null, e.__d = !1, !x) {
i = e.render(_, p, c), e.getChildContext && (c = n(n({}, c), e.getChildContext()));var U,
T,
M = i && i.nodeName;if ("function" == typeof M) {
var W = u(i);l = w, l && l.constructor === M && W.key == l.__k ? N(l, W, 1, c, !1) : (U = l, e._component = l = C(M, W, c), l.__b = l.__b || y, l.__u = e, N(l, W, 0, c, !1), k(l, 1, o, !0)), T = l.base;
} else a = g, U = w, U && (a = e._component = null), (g || 1 === t) && (a && (a._component = null), T = h(a, i, c, o || !v, g && g.parentNode, !0));if (g && T !== g && l !== w) {
var E = g.parentNode;E && T !== E && (E.replaceChild(T, g), U || (g._component = null, b(g, !1)));
}if (U && L(U), e.base = T, T && !r) {
var P = e,
V = e;while (V = V.__u) (P = V).base = T;T._component = P, T._componentConstructor = P.constructor;
}
}if (!v || o ? D.unshift(e) : x || (e.componentDidUpdate && e.componentDidUpdate(s, f, m), S.afterUpdate && S.afterUpdate(e)), null != e.__h) while (e.__h.length) e.__h.pop().call(e);H || r || d();
}
}function U(e, t, n, o) {
var r = e && e._component,
i = r,
l = e,
a = r && e._componentConstructor === t.nodeName,
_ = a,
p = u(t);while (r && !_ && (r = r.__u)) _ = r.constructor === t.nodeName;return r && _ && (!o || r._component) ? (N(r, p, 3, n, o), e = r.base) : (i && !a && (L(i), e = l = null), r = C(t.nodeName, p, n), e && !r.__b && (r.__b = e, l = null), N(r, p, 1, n, o), e = r.base, l && e !== l && (l._component = null, b(l, !1))), e;
}function L(e) {
S.beforeUnmount && S.beforeUnmount(e);var t = e.base;e.__x = !0, e.componentWillUnmount && e.componentWillUnmount(), e.base = null;var n = e._component;n ? L(n) : t && (t.__preactattr_ && t.__preactattr_.ref && t.__preactattr_.ref(null), e.__b = t, p(t), w(e), y(t)), e.__r && e.__r(null);
}function T(e, t) {
this.__d = !0, this.context = t, this.props = e, this.state = this.state || {};
}function M(e, t, n) {
return h(n, e, {}, !1, t, !1);
}var S = {},
W = [],
E = [],
P = "function" == typeof Promise ? Promise.resolve().then.bind(Promise.resolve()) : setTimeout,
V = /acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,
A = [],
D = [],
H = 0,
R = !1,
j = !1,
I = {};n(T.prototype, { setState: function (e, t) {
var o = this.state;this.__s || (this.__s = n({}, o)), n(o, "function" == typeof e ? e(o, this.props) : e), t && (this.__h = this.__h || []).push(t), r(this);
}, forceUpdate: function (e) {
e && (this.__h = this.__h || []).push(e), k(this, 2);
}, render: function () {} });var $ = { h: t, createElement: t, cloneElement: o, Component: T, render: M, rerender: i, options: S }; true ? module.exports = $ : self.preact = $;
}();
//# sourceMappingURL=preact.min.js.map
/***/ }),
/***/ "LiPu":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var Pos = CodeMirror.Pos;
function getHints(cm, options) {
var tags = options && options.schemaInfo;
var quote = options && options.quoteChar || '"';
if (!tags) return;
var cur = cm.getCursor(),
token = cm.getTokenAt(cur);
if (token.end > cur.ch) {
token.end = cur.ch;
token.string = token.string.slice(0, cur.ch - token.start);
}
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
if (inner.mode.name != "xml") return;
var result = [],
replaceToken = false,
prefix;
var tag = /\btag\b/.test(token.type) && !/>$/.test(token.string);
var tagName = tag && /^\w/.test(token.string),
tagStart;
if (tagName) {
var before = cm.getLine(cur.line).slice(Math.max(0, token.start - 2), token.start);
var tagType = /<\/$/.test(before) ? "close" : /<$/.test(before) ? "open" : null;
if (tagType) tagStart = token.start - (tagType == "close" ? 2 : 1);
} else if (tag && token.string == "<") {
tagType = "open";
} else if (tag && token.string == "</") {
tagType = "close";
}
if (!tag && !inner.state.tagName || tagType) {
if (tagName) prefix = token.string;
replaceToken = tagType;
var cx = inner.state.context,
curTag = cx && tags[cx.tagName];
var childList = cx ? curTag && curTag.children : tags["!top"];
if (childList && tagType != "close") {
for (var i = 0; i < childList.length; ++i) if (!prefix || childList[i].lastIndexOf(prefix, 0) == 0) result.push("<" + childList[i]);
} else if (tagType != "close") {
for (var name in tags) if (tags.hasOwnProperty(name) && name != "!top" && name != "!attrs" && (!prefix || name.lastIndexOf(prefix, 0) == 0)) result.push("<" + name);
}
if (cx && (!prefix || tagType == "close" && cx.tagName.lastIndexOf(prefix, 0) == 0)) result.push("</" + cx.tagName + ">");
} else {
// Attribute completion
var curTag = tags[inner.state.tagName],
attrs = curTag && curTag.attrs;
var globalAttrs = tags["!attrs"];
if (!attrs && !globalAttrs) return;
if (!attrs) {
attrs = globalAttrs;
} else if (globalAttrs) {
// Combine tag-local and global attributes
var set = {};
for (var nm in globalAttrs) if (globalAttrs.hasOwnProperty(nm)) set[nm] = globalAttrs[nm];
for (var nm in attrs) if (attrs.hasOwnProperty(nm)) set[nm] = attrs[nm];
attrs = set;
}
if (token.type == "string" || token.string == "=") {
// A value
var before = cm.getRange(Pos(cur.line, Math.max(0, cur.ch - 60)), Pos(cur.line, token.type == "string" ? token.start : token.end));
var atName = before.match(/([^\s\u00a0=<>\"\']+)=$/),
atValues;
if (!atName || !attrs.hasOwnProperty(atName[1]) || !(atValues = attrs[atName[1]])) return;
if (typeof atValues == 'function') atValues = atValues.call(this, cm); // Functions can be used to supply values for autocomplete widget
if (token.type == "string") {
prefix = token.string;
var n = 0;
if (/['"]/.test(token.string.charAt(0))) {
quote = token.string.charAt(0);
prefix = token.string.slice(1);
n++;
}
var len = token.string.length;
if (/['"]/.test(token.string.charAt(len - 1))) {
quote = token.string.charAt(len - 1);
prefix = token.string.substr(n, len - 2);
}
replaceToken = true;
}
for (var i = 0; i < atValues.length; ++i) if (!prefix || atValues[i].lastIndexOf(prefix, 0) == 0) result.push(quote + atValues[i] + quote);
} else {
// An attribute name
if (token.type == "attribute") {
prefix = token.string;
replaceToken = true;
}
for (var attr in attrs) if (attrs.hasOwnProperty(attr) && (!prefix || attr.lastIndexOf(prefix, 0) == 0)) result.push(attr);
}
}
return {
list: result,
from: replaceToken ? Pos(cur.line, tagStart == null ? token.start : tagStart) : cur,
to: replaceToken ? Pos(cur.line, token.end) : cur
};
}
CodeMirror.registerHelper("hint", "xml", getHints);
});
/***/ }),
/***/ "MCp7":
/***/ (function(module, exports) {
(function (self) {
'use strict';
if (self.fetch) {
return;
}
var support = {
searchParams: 'URLSearchParams' in self,
iterable: 'Symbol' in self && 'iterator' in Symbol,
blob: 'FileReader' in self && 'Blob' in self && function () {
try {
new Blob();
return true;
} catch (e) {
return false;
}
}(),
formData: 'FormData' in self,
arrayBuffer: 'ArrayBuffer' in self
};
if (support.arrayBuffer) {
var viewClasses = ['[object Int8Array]', '[object Uint8Array]', '[object Uint8ClampedArray]', '[object Int16Array]', '[object Uint16Array]', '[object Int32Array]', '[object Uint32Array]', '[object Float32Array]', '[object Float64Array]'];
var isDataView = function (obj) {
return obj && DataView.prototype.isPrototypeOf(obj);
};
var isArrayBufferView = ArrayBuffer.isView || function (obj) {
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1;
};
}
function normalizeName(name) {
if (typeof name !== 'string') {
name = String(name);
}
if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
throw new TypeError('Invalid character in header field name');
}
return name.toLowerCase();
}
function normalizeValue(value) {
if (typeof value !== 'string') {
value = String(value);
}
return value;
}
// Build a destructive iterator for the value list
function iteratorFor(items) {
var iterator = {
next: function () {
var value = items.shift();
return { done: value === undefined, value: value };
}
};
if (support.iterable) {
iterator[Symbol.iterator] = function () {
return iterator;
};
}
return iterator;
}
function Headers(headers) {
this.map = {};
if (headers instanceof Headers) {
headers.forEach(function (value, name) {
this.append(name, value);
}, this);
} else if (Array.isArray(headers)) {
headers.forEach(function (header) {
this.append(header[0], header[1]);
}, this);
} else if (headers) {
Object.getOwnPropertyNames(headers).forEach(function (name) {
this.append(name, headers[name]);
}, this);
}
}
Headers.prototype.append = function (name, value) {
name = normalizeName(name);
value = normalizeValue(value);
var oldValue = this.map[name];
this.map[name] = oldValue ? oldValue + ',' + value : value;
};
Headers.prototype['delete'] = function (name) {
delete this.map[normalizeName(name)];
};
Headers.prototype.get = function (name) {
name = normalizeName(name);
return this.has(name) ? this.map[name] : null;
};
Headers.prototype.has = function (name) {
return this.map.hasOwnProperty(normalizeName(name));
};
Headers.prototype.set = function (name, value) {
this.map[normalizeName(name)] = normalizeValue(value);
};
Headers.prototype.forEach = function (callback, thisArg) {
for (var name in this.map) {
if (this.map.hasOwnProperty(name)) {
callback.call(thisArg, this.map[name], name, this);
}
}
};
Headers.prototype.keys = function () {
var items = [];
this.forEach(function (value, name) {
items.push(name);
});
return iteratorFor(items);
};
Headers.prototype.values = function () {
var items = [];
this.forEach(function (value) {
items.push(value);
});
return iteratorFor(items);
};
Headers.prototype.entries = function () {
var items = [];
this.forEach(function (value, name) {
items.push([name, value]);
});
return iteratorFor(items);
};
if (support.iterable) {
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
}
function consumed(body) {
if (body.bodyUsed) {
return Promise.reject(new TypeError('Already read'));
}
body.bodyUsed = true;
}
function fileReaderReady(reader) {
return new Promise(function (resolve, reject) {
reader.onload = function () {
resolve(reader.result);
};
reader.onerror = function () {
reject(reader.error);
};
});
}
function readBlobAsArrayBuffer(blob) {
var reader = new FileReader();
var promise = fileReaderReady(reader);
reader.readAsArrayBuffer(blob);
return promise;
}
function readBlobAsText(blob) {
var reader = new FileReader();
var promise = fileReaderReady(reader);
reader.readAsText(blob);
return promise;
}
function readArrayBufferAsText(buf) {
var view = new Uint8Array(buf);
var chars = new Array(view.length);
for (var i = 0; i < view.length; i++) {
chars[i] = String.fromCharCode(view[i]);
}
return chars.join('');
}
function bufferClone(buf) {
if (buf.slice) {
return buf.slice(0);
} else {
var view = new Uint8Array(buf.byteLength);
view.set(new Uint8Array(buf));
return view.buffer;
}
}
function Body() {
this.bodyUsed = false;
this._initBody = function (body) {
this._bodyInit = body;
if (!body) {
this._bodyText = '';
} else if (typeof body === 'string') {
this._bodyText = body;
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
this._bodyBlob = body;
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body;
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this._bodyText = body.toString();
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
this._bodyArrayBuffer = bufferClone(body.buffer);
// IE 10-11 can't handle a DataView body.
this._bodyInit = new Blob([this._bodyArrayBuffer]);
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
this._bodyArrayBuffer = bufferClone(body);
} else {
throw new Error('unsupported BodyInit type');
}
if (!this.headers.get('content-type')) {
if (typeof body === 'string') {
this.headers.set('content-type', 'text/plain;charset=UTF-8');
} else if (this._bodyBlob && this._bodyBlob.type) {
this.headers.set('content-type', this._bodyBlob.type);
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
}
}
};
if (support.blob) {
this.blob = function () {
var rejected = consumed(this);
if (rejected) {
return rejected;
}
if (this._bodyBlob) {
return Promise.resolve(this._bodyBlob);
} else if (this._bodyArrayBuffer) {
return Promise.resolve(new Blob([this._bodyArrayBuffer]));
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as blob');
} else {
return Promise.resolve(new Blob([this._bodyText]));
}
};
this.arrayBuffer = function () {
if (this._bodyArrayBuffer) {
return consumed(this) || Promise.resolve(this._bodyArrayBuffer);
} else {
return this.blob().then(readBlobAsArrayBuffer);
}
};
}
this.text = function () {
var rejected = consumed(this);
if (rejected) {
return rejected;
}
if (this._bodyBlob) {
return readBlobAsText(this._bodyBlob);
} else if (this._bodyArrayBuffer) {
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
} else if (this._bodyFormData) {
throw new Error('could not read FormData body as text');
} else {
return Promise.resolve(this._bodyText);
}
};
if (support.formData) {
this.formData = function () {
return this.text().then(decode);
};
}
this.json = function () {
return this.text().then(JSON.parse);
};
return this;
}
// HTTP methods whose capitalization should be normalized
var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
function normalizeMethod(method) {
var upcased = method.toUpperCase();
return methods.indexOf(upcased) > -1 ? upcased : method;
}
function Request(input, options) {
options = options || {};
var body = options.body;
if (input instanceof Request) {
if (input.bodyUsed) {
throw new TypeError('Already read');
}
this.url = input.url;
this.credentials = input.credentials;
if (!options.headers) {
this.headers = new Headers(input.headers);
}
this.method = input.method;
this.mode = input.mode;
if (!body && input._bodyInit != null) {
body = input._bodyInit;
input.bodyUsed = true;
}
} else {
this.url = String(input);
}
this.credentials = options.credentials || this.credentials || 'omit';
if (options.headers || !this.headers) {
this.headers = new Headers(options.headers);
}
this.method = normalizeMethod(options.method || this.method || 'GET');
this.mode = options.mode || this.mode || null;
this.referrer = null;
if ((this.method === 'GET' || this.method === 'HEAD') && body) {
throw new TypeError('Body not allowed for GET or HEAD requests');
}
this._initBody(body);
}
Request.prototype.clone = function () {
return new Request(this, { body: this._bodyInit });
};
function decode(body) {
var form = new FormData();
body.trim().split('&').forEach(function (bytes) {
if (bytes) {
var split = bytes.split('=');
var name = split.shift().replace(/\+/g, ' ');
var value = split.join('=').replace(/\+/g, ' ');
form.append(decodeURIComponent(name), decodeURIComponent(value));
}
});
return form;
}
function parseHeaders(rawHeaders) {
var headers = new Headers();
// Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
// https://tools.ietf.org/html/rfc7230#section-3.2
var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
preProcessedHeaders.split(/\r?\n/).forEach(function (line) {
var parts = line.split(':');
var key = parts.shift().trim();
if (key) {
var value = parts.join(':').trim();
headers.append(key, value);
}
});
return headers;
}
Body.call(Request.prototype);
function Response(bodyInit, options) {
if (!options) {
options = {};
}
this.type = 'default';
this.status = options.status === undefined ? 200 : options.status;
this.ok = this.status >= 200 && this.status < 300;
this.statusText = 'statusText' in options ? options.statusText : 'OK';
this.headers = new Headers(options.headers);
this.url = options.url || '';
this._initBody(bodyInit);
}
Body.call(Response.prototype);
Response.prototype.clone = function () {
return new Response(this._bodyInit, {
status: this.status,
statusText: this.statusText,
headers: new Headers(this.headers),
url: this.url
});
};
Response.error = function () {
var response = new Response(null, { status: 0, statusText: '' });
response.type = 'error';
return response;
};
var redirectStatuses = [301, 302, 303, 307, 308];
Response.redirect = function (url, status) {
if (redirectStatuses.indexOf(status) === -1) {
throw new RangeError('Invalid status code');
}
return new Response(null, { status: status, headers: { location: url } });
};
self.Headers = Headers;
self.Request = Request;
self.Response = Response;
self.fetch = function (input, init) {
return new Promise(function (resolve, reject) {
var request = new Request(input, init);
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var options = {
status: xhr.status,
statusText: xhr.statusText,
headers: parseHeaders(xhr.getAllResponseHeaders() || '')
};
options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
var body = 'response' in xhr ? xhr.response : xhr.responseText;
resolve(new Response(body, options));
};
xhr.onerror = function () {
reject(new TypeError('Network request failed'));
};
xhr.ontimeout = function () {
reject(new TypeError('Network request failed'));
};
xhr.open(request.method, request.url, true);
if (request.credentials === 'include') {
xhr.withCredentials = true;
} else if (request.credentials === 'omit') {
xhr.withCredentials = false;
}
if ('responseType' in xhr && support.blob) {
xhr.responseType = 'blob';
}
request.headers.forEach(function (value, name) {
xhr.setRequestHeader(name, value);
});
xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
});
};
self.fetch.polyfill = true;
})(typeof self !== 'undefined' ? self : this);
/***/ }),
/***/ "QAmr":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
var index = typeof fetch == 'function' ? fetch.bind() : function (url, options) {
options = options || {};
return new Promise(function (resolve, reject) {
var request = new XMLHttpRequest();
request.open(options.method || 'get', url);
for (var i in options.headers) {
request.setRequestHeader(i, options.headers[i]);
}
request.withCredentials = options.credentials == 'include';
request.onload = function () {
resolve(response());
};
request.onerror = reject;
request.send(options.body);
function response() {
var keys = [],
all = [],
headers = {},
header;
request.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm, function (m, key, value) {
keys.push(key = key.toLowerCase());
all.push([key, value]);
header = headers[key];
headers[key] = header ? header + "," + value : value;
});
return {
ok: (request.status / 200 | 0) == 1, // 200-299
status: request.status,
statusText: request.statusText,
url: request.responseURL,
clone: response,
text: function () {
return Promise.resolve(request.responseText);
},
json: function () {
return Promise.resolve(request.responseText).then(JSON.parse);
},
blob: function () {
return Promise.resolve(new Blob([request.response]));
},
headers: {
keys: function () {
return keys;
},
entries: function () {
return all;
},
get: function (n) {
return headers[n.toLowerCase()];
},
has: function (n) {
return n.toLowerCase() in headers;
}
}
};
}
});
};
/* harmony default export */ __webpack_exports__["default"] = (index);
//# sourceMappingURL=unfetch.es.js.map
/***/ }),
/***/ "RJVP":
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {(function () {
var firebase = __webpack_require__("dP58").default;
var g,
aa = aa || {},
k = this;function l(a) {
return "string" == typeof a;
}function ba(a) {
return "boolean" == typeof a;
}function ca() {}
function da(a) {
var b = typeof a;if ("object" == b) {
if (a) {
if (a instanceof Array) return "array";if (a instanceof Object) return b;var c = Object.prototype.toString.call(a);if ("[object Window]" == c) return "object";if ("[object Array]" == c || "number" == typeof a.length && "undefined" != typeof a.splice && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("splice")) return "array";if ("[object Function]" == c || "undefined" != typeof a.call && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("call")) return "function";
} else return "null";
} else if ("function" == b && "undefined" == typeof a.call) return "object";return b;
}function ea(a) {
return null === a;
}function fa(a) {
return "array" == da(a);
}function ha(a) {
var b = da(a);return "array" == b || "object" == b && "number" == typeof a.length;
}function n(a) {
return "function" == da(a);
}function q(a) {
var b = typeof a;return "object" == b && null != a || "function" == b;
}var ia = "closure_uid_" + (1E9 * Math.random() >>> 0),
ja = 0;function ka(a, b, c) {
return a.call.apply(a.bind, arguments);
}
function la(a, b, c) {
if (!a) throw Error();if (2 < arguments.length) {
var d = Array.prototype.slice.call(arguments, 2);return function () {
var c = Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c, d);return a.apply(b, c);
};
}return function () {
return a.apply(b, arguments);
};
}function r(a, b, c) {
Function.prototype.bind && -1 != Function.prototype.bind.toString().indexOf("native code") ? r = ka : r = la;return r.apply(null, arguments);
}
function ma(a, b) {
var c = Array.prototype.slice.call(arguments, 1);return function () {
var b = c.slice();b.push.apply(b, arguments);return a.apply(this, b);
};
}var na = Date.now || function () {
return +new Date();
};function t(a, b) {
function c() {}c.prototype = b.prototype;a.lb = b.prototype;a.prototype = new c();a.prototype.constructor = a;a.cd = function (a, c, f) {
for (var d = Array(arguments.length - 2), e = 2; e < arguments.length; e++) d[e - 2] = arguments[e];return b.prototype[c].apply(a, d);
};
};function oa(a) {
a.prototype.then = a.prototype.then;a.prototype.$goog_Thenable = !0;
}function pa(a) {
if (!a) return !1;try {
return !!a.$goog_Thenable;
} catch (b) {
return !1;
}
};function u(a) {
if (Error.captureStackTrace) Error.captureStackTrace(this, u);else {
var b = Error().stack;b && (this.stack = b);
}a && (this.message = String(a));
}t(u, Error);u.prototype.name = "CustomError";function qa(a, b) {
a = a.split("%s");for (var c = "", d = a.length - 1, e = 0; e < d; e++) c += a[e] + (e < b.length ? b[e] : "%s");u.call(this, c + a[d]);
}t(qa, u);qa.prototype.name = "AssertionError";function ra(a, b) {
throw new qa("Failure" + (a ? ": " + a : ""), Array.prototype.slice.call(arguments, 1));
};function sa(a, b) {
this.c = a;this.f = b;this.b = 0;this.a = null;
}sa.prototype.get = function () {
if (0 < this.b) {
this.b--;var a = this.a;this.a = a.next;a.next = null;
} else a = this.c();return a;
};function ta(a, b) {
a.f(b);100 > a.b && (a.b++, b.next = a.a, a.a = b);
};function ua() {
this.b = this.a = null;
}var wa = new sa(function () {
return new va();
}, function (a) {
a.reset();
});ua.prototype.add = function (a, b) {
var c = wa.get();c.set(a, b);this.b ? this.b.next = c : this.a = c;this.b = c;
};function xa() {
var a = ya,
b = null;a.a && (b = a.a, a.a = a.a.next, a.a || (a.b = null), b.next = null);return b;
}function va() {
this.next = this.b = this.a = null;
}va.prototype.set = function (a, b) {
this.a = a;this.b = b;this.next = null;
};va.prototype.reset = function () {
this.next = this.b = this.a = null;
};var za = Array.prototype.indexOf ? function (a, b) {
return Array.prototype.indexOf.call(a, b, void 0);
} : function (a, b) {
if (l(a)) return l(b) && 1 == b.length ? a.indexOf(b, 0) : -1;for (var c = 0; c < a.length; c++) if (c in a && a[c] === b) return c;return -1;
},
v = Array.prototype.forEach ? function (a, b, c) {
Array.prototype.forEach.call(a, b, c);
} : function (a, b, c) {
for (var d = a.length, e = l(a) ? a.split("") : a, f = 0; f < d; f++) f in e && b.call(c, e[f], f, a);
};
function Aa(a, b) {
var c = a.length,
d = l(a) ? a.split("") : a;for (--c; 0 <= c; --c) c in d && b.call(void 0, d[c], c, a);
}
var Ba = Array.prototype.map ? function (a, b) {
return Array.prototype.map.call(a, b, void 0);
} : function (a, b) {
for (var c = a.length, d = Array(c), e = l(a) ? a.split("") : a, f = 0; f < c; f++) f in e && (d[f] = b.call(void 0, e[f], f, a));return d;
},
Ca = Array.prototype.some ? function (a, b) {
return Array.prototype.some.call(a, b, void 0);
} : function (a, b) {
for (var c = a.length, d = l(a) ? a.split("") : a, e = 0; e < c; e++) if (e in d && b.call(void 0, d[e], e, a)) return !0;return !1;
};
function Da(a) {
a: {
var b = Ea;for (var c = a.length, d = l(a) ? a.split("") : a, e = 0; e < c; e++) if (e in d && b.call(void 0, d[e], e, a)) {
b = e;break a;
}b = -1;
}return 0 > b ? null : l(a) ? a.charAt(b) : a[b];
}function Fa(a, b) {
return 0 <= za(a, b);
}function Ga(a, b) {
b = za(a, b);var c;(c = 0 <= b) && Array.prototype.splice.call(a, b, 1);return c;
}function Ha(a, b) {
var c = 0;Aa(a, function (d, e) {
b.call(void 0, d, e, a) && 1 == Array.prototype.splice.call(a, e, 1).length && c++;
});
}function Ia(a) {
return Array.prototype.concat.apply([], arguments);
}
function Ja(a) {
var b = a.length;if (0 < b) {
for (var c = Array(b), d = 0; d < b; d++) c[d] = a[d];return c;
}return [];
};function Ka(a, b) {
for (var c = a.split("%s"), d = "", e = Array.prototype.slice.call(arguments, 1); e.length && 1 < c.length;) d += c.shift() + e.shift();return d + c.join("%s");
}var La = String.prototype.trim ? function (a) {
return a.trim();
} : function (a) {
return (/^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(a)[1]
);
};
function Ma(a) {
if (!Na.test(a)) return a;-1 != a.indexOf("&") && (a = a.replace(Oa, "&amp;"));-1 != a.indexOf("<") && (a = a.replace(Pa, "&lt;"));-1 != a.indexOf(">") && (a = a.replace(Qa, "&gt;"));-1 != a.indexOf('"') && (a = a.replace(Ra, "&quot;"));-1 != a.indexOf("'") && (a = a.replace(Sa, "&#39;"));-1 != a.indexOf("\x00") && (a = a.replace(Ta, "&#0;"));return a;
}var Oa = /&/g,
Pa = /</g,
Qa = />/g,
Ra = /"/g,
Sa = /'/g,
Ta = /\x00/g,
Na = /[\x00&<>"']/;function w(a, b) {
return -1 != a.indexOf(b);
}function Ua(a, b) {
return a < b ? -1 : a > b ? 1 : 0;
};var Va;a: {
var Wa = k.navigator;if (Wa) {
var Xa = Wa.userAgent;if (Xa) {
Va = Xa;break a;
}
}Va = "";
}function x(a) {
return w(Va, a);
};function Ya(a, b) {
for (var c in a) b.call(void 0, a[c], c, a);
}function Za(a) {
for (var b in a) return !1;return !0;
}function $a(a) {
var b = {},
c;for (c in a) b[c] = a[c];return b;
}var ab = "constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");function bb(a, b) {
for (var c, d, e = 1; e < arguments.length; e++) {
d = arguments[e];for (c in d) a[c] = d[c];for (var f = 0; f < ab.length; f++) c = ab[f], Object.prototype.hasOwnProperty.call(d, c) && (a[c] = d[c]);
}
};function cb(a) {
k.setTimeout(function () {
throw a;
}, 0);
}var db;
function eb() {
var a = k.MessageChannel;"undefined" === typeof a && "undefined" !== typeof window && window.postMessage && window.addEventListener && !x("Presto") && (a = function () {
var a = document.createElement("IFRAME");a.style.display = "none";a.src = "";document.documentElement.appendChild(a);var b = a.contentWindow;a = b.document;a.open();a.write("");a.close();var c = "callImmediate" + Math.random(),
d = "file:" == b.location.protocol ? "*" : b.location.protocol + "//" + b.location.host;a = r(function (a) {
if (("*" == d || a.origin == d) && a.data == c) this.port1.onmessage();
}, this);b.addEventListener("message", a, !1);this.port1 = {};this.port2 = { postMessage: function () {
b.postMessage(c, d);
} };
});if ("undefined" !== typeof a && !x("Trident") && !x("MSIE")) {
var b = new a(),
c = {},
d = c;b.port1.onmessage = function () {
if (void 0 !== c.next) {
c = c.next;var a = c.tb;c.tb = null;a();
}
};return function (a) {
d.next = { tb: a };d = d.next;b.port2.postMessage(0);
};
}return "undefined" !== typeof document && "onreadystatechange" in document.createElement("SCRIPT") ? function (a) {
var b = document.createElement("SCRIPT");
b.onreadystatechange = function () {
b.onreadystatechange = null;b.parentNode.removeChild(b);b = null;a();a = null;
};document.documentElement.appendChild(b);
} : function (a) {
k.setTimeout(a, 0);
};
};function fb(a, b) {
gb || hb();ib || (gb(), ib = !0);ya.add(a, b);
}var gb;function hb() {
if (k.Promise && k.Promise.resolve) {
var a = k.Promise.resolve(void 0);gb = function () {
a.then(jb);
};
} else gb = function () {
var a = jb;!n(k.setImmediate) || k.Window && k.Window.prototype && !x("Edge") && k.Window.prototype.setImmediate == k.setImmediate ? (db || (db = eb()), db(a)) : k.setImmediate(a);
};
}var ib = !1,
ya = new ua();function jb() {
for (var a; a = xa();) {
try {
a.a.call(a.b);
} catch (b) {
cb(b);
}ta(wa, a);
}ib = !1;
};function y(a, b) {
this.a = kb;this.i = void 0;this.f = this.b = this.c = null;this.g = this.h = !1;if (a != ca) try {
var c = this;a.call(b, function (a) {
lb(c, mb, a);
}, function (a) {
if (!(a instanceof nb)) try {
if (a instanceof Error) throw a;throw Error("Promise rejected.");
} catch (e) {}lb(c, ob, a);
});
} catch (d) {
lb(this, ob, d);
}
}var kb = 0,
mb = 2,
ob = 3;function pb() {
this.next = this.f = this.b = this.g = this.a = null;this.c = !1;
}pb.prototype.reset = function () {
this.f = this.b = this.g = this.a = null;this.c = !1;
};var qb = new sa(function () {
return new pb();
}, function (a) {
a.reset();
});
function rb(a, b, c) {
var d = qb.get();d.g = a;d.b = b;d.f = c;return d;
}function A(a) {
if (a instanceof y) return a;var b = new y(ca);lb(b, mb, a);return b;
}function B(a) {
return new y(function (b, c) {
c(a);
});
}function sb(a, b, c) {
tb(a, b, c, null) || fb(ma(b, a));
}function ub(a) {
return new y(function (b, c) {
var d = a.length,
e = [];if (d) for (var f = function (a, c) {
d--;e[a] = c;0 == d && b(e);
}, h = function (a) {
c(a);
}, m = 0, p; m < a.length; m++) p = a[m], sb(p, ma(f, m), h);else b(e);
});
}
function vb(a) {
return new y(function (b) {
var c = a.length,
d = [];if (c) for (var e = function (a, e, f) {
c--;d[a] = e ? { Zb: !0, value: f } : { Zb: !1, reason: f };0 == c && b(d);
}, f = 0, h; f < a.length; f++) h = a[f], sb(h, ma(e, f, !0), ma(e, f, !1));else b(d);
});
}y.prototype.then = function (a, b, c) {
return wb(this, n(a) ? a : null, n(b) ? b : null, c);
};oa(y);g = y.prototype;g.ia = function (a, b) {
a = rb(a, a, b);a.c = !0;xb(this, a);return this;
};g.s = function (a, b) {
return wb(this, null, a, b);
};g.cancel = function (a) {
this.a == kb && fb(function () {
var b = new nb(a);yb(this, b);
}, this);
};
function yb(a, b) {
if (a.a == kb) if (a.c) {
var c = a.c;if (c.b) {
for (var d = 0, e = null, f = null, h = c.b; h && (h.c || (d++, h.a == a && (e = h), !(e && 1 < d))); h = h.next) e || (f = h);e && (c.a == kb && 1 == d ? yb(c, b) : (f ? (d = f, d.next == c.f && (c.f = d), d.next = d.next.next) : zb(c), Ab(c, e, ob, b)));
}a.c = null;
} else lb(a, ob, b);
}function xb(a, b) {
a.b || a.a != mb && a.a != ob || Bb(a);a.f ? a.f.next = b : a.b = b;a.f = b;
}
function wb(a, b, c, d) {
var e = rb(null, null, null);e.a = new y(function (a, h) {
e.g = b ? function (c) {
try {
var e = b.call(d, c);a(e);
} catch (z) {
h(z);
}
} : a;e.b = c ? function (b) {
try {
var e = c.call(d, b);void 0 === e && b instanceof nb ? h(b) : a(e);
} catch (z) {
h(z);
}
} : h;
});e.a.c = a;xb(a, e);return e.a;
}g.Lc = function (a) {
this.a = kb;lb(this, mb, a);
};g.Mc = function (a) {
this.a = kb;lb(this, ob, a);
};
function lb(a, b, c) {
a.a == kb && (a === c && (b = ob, c = new TypeError("Promise cannot resolve to itself")), a.a = 1, tb(c, a.Lc, a.Mc, a) || (a.i = c, a.a = b, a.c = null, Bb(a), b != ob || c instanceof nb || Cb(a, c)));
}function tb(a, b, c, d) {
if (a instanceof y) return xb(a, rb(b || ca, c || null, d)), !0;if (pa(a)) return a.then(b, c, d), !0;if (q(a)) try {
var e = a.then;if (n(e)) return Db(a, e, b, c, d), !0;
} catch (f) {
return c.call(d, f), !0;
}return !1;
}
function Db(a, b, c, d, e) {
function f(a) {
m || (m = !0, d.call(e, a));
}function h(a) {
m || (m = !0, c.call(e, a));
}var m = !1;try {
b.call(a, h, f);
} catch (p) {
f(p);
}
}function Bb(a) {
a.h || (a.h = !0, fb(a.Ub, a));
}function zb(a) {
var b = null;a.b && (b = a.b, a.b = b.next, b.next = null);a.b || (a.f = null);return b;
}g.Ub = function () {
for (var a; a = zb(this);) Ab(this, a, this.a, this.i);this.h = !1;
};
function Ab(a, b, c, d) {
if (c == ob && b.b && !b.c) for (; a && a.g; a = a.c) a.g = !1;if (b.a) b.a.c = null, Eb(b, c, d);else try {
b.c ? b.g.call(b.f) : Eb(b, c, d);
} catch (e) {
Fb.call(null, e);
}ta(qb, b);
}function Eb(a, b, c) {
b == mb ? a.g.call(a.f, c) : a.b && a.b.call(a.f, c);
}function Cb(a, b) {
a.g = !0;fb(function () {
a.g && Fb.call(null, b);
});
}var Fb = cb;function nb(a) {
u.call(this, a);
}t(nb, u);nb.prototype.name = "cancel";function Gb() {
0 != Hb && (Ib[this[ia] || (this[ia] = ++ja)] = this);this.pa = this.pa;this.ja = this.ja;
}var Hb = 0,
Ib = {};Gb.prototype.pa = !1;function Jb(a) {
if (!a.pa && (a.pa = !0, a.ua(), 0 != Hb)) {
var b = a[ia] || (a[ia] = ++ja);if (0 != Hb && a.ja && 0 < a.ja.length) throw Error(a + " did not empty its onDisposeCallbacks queue. This probably means it overrode dispose() or disposeInternal() without calling the superclass' method.");delete Ib[b];
}
}Gb.prototype.ua = function () {
if (this.ja) for (; this.ja.length;) this.ja.shift()();
};function Kb(a) {
Kb[" "](a);return a;
}Kb[" "] = ca;function Lb(a, b) {
var c = Mb;return Object.prototype.hasOwnProperty.call(c, a) ? c[a] : c[a] = b(a);
};var Nb = x("Opera"),
Ob = x("Trident") || x("MSIE"),
Pb = x("Edge"),
Qb = Pb || Ob,
Rb = x("Gecko") && !(w(Va.toLowerCase(), "webkit") && !x("Edge")) && !(x("Trident") || x("MSIE")) && !x("Edge"),
Sb = w(Va.toLowerCase(), "webkit") && !x("Edge");function Tb() {
var a = k.document;return a ? a.documentMode : void 0;
}var Ub;
a: {
var Vb = "",
Wb = function () {
var a = Va;if (Rb) return (/rv:([^\);]+)(\)|;)/.exec(a)
);if (Pb) return (/Edge\/([\d\.]+)/.exec(a)
);if (Ob) return (/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(a)
);if (Sb) return (/WebKit\/(\S+)/.exec(a)
);if (Nb) return (/(?:Version)[ \/]?(\S+)/.exec(a)
);
}();Wb && (Vb = Wb ? Wb[1] : "");if (Ob) {
var Xb = Tb();if (null != Xb && Xb > parseFloat(Vb)) {
Ub = String(Xb);break a;
}
}Ub = Vb;
}var Mb = {};
function Yb(a) {
return Lb(a, function () {
for (var b = 0, c = La(String(Ub)).split("."), d = La(String(a)).split("."), e = Math.max(c.length, d.length), f = 0; 0 == b && f < e; f++) {
var h = c[f] || "",
m = d[f] || "";do {
h = /(\d*)(\D*)(.*)/.exec(h) || ["", "", "", ""];m = /(\d*)(\D*)(.*)/.exec(m) || ["", "", "", ""];if (0 == h[0].length && 0 == m[0].length) break;b = Ua(0 == h[1].length ? 0 : parseInt(h[1], 10), 0 == m[1].length ? 0 : parseInt(m[1], 10)) || Ua(0 == h[2].length, 0 == m[2].length) || Ua(h[2], m[2]);h = h[3];m = m[3];
} while (0 == b);
}return 0 <= b;
});
}var Zb;var $b = k.document;
Zb = $b && Ob ? Tb() || ("CSS1Compat" == $b.compatMode ? parseInt(Ub, 10) : 5) : void 0;var ac = Object.freeze || function (a) {
return a;
};var bc = !Ob || 9 <= Number(Zb),
cc = Ob && !Yb("9"),
dc = function () {
if (!k.addEventListener || !Object.defineProperty) return !1;var a = !1,
b = Object.defineProperty({}, "passive", { get: function () {
a = !0;
} });k.addEventListener("test", ca, b);k.removeEventListener("test", ca, b);return a;
}();function C(a, b) {
this.type = a;this.b = this.target = b;this.Gb = !0;
}C.prototype.preventDefault = function () {
this.Gb = !1;
};function ec(a, b) {
C.call(this, a ? a.type : "");this.relatedTarget = this.b = this.target = null;this.button = this.screenY = this.screenX = this.clientY = this.clientX = 0;this.key = "";this.metaKey = this.shiftKey = this.altKey = this.ctrlKey = !1;this.pointerId = 0;this.pointerType = "";this.a = null;if (a) {
var c = this.type = a.type,
d = a.changedTouches ? a.changedTouches[0] : null;this.target = a.target || a.srcElement;this.b = b;if (b = a.relatedTarget) {
if (Rb) {
a: {
try {
Kb(b.nodeName);var e = !0;break a;
} catch (f) {}e = !1;
}e || (b = null);
}
} else "mouseover" == c ? b = a.fromElement : "mouseout" == c && (b = a.toElement);this.relatedTarget = b;null === d ? (this.clientX = void 0 !== a.clientX ? a.clientX : a.pageX, this.clientY = void 0 !== a.clientY ? a.clientY : a.pageY, this.screenX = a.screenX || 0, this.screenY = a.screenY || 0) : (this.clientX = void 0 !== d.clientX ? d.clientX : d.pageX, this.clientY = void 0 !== d.clientY ? d.clientY : d.pageY, this.screenX = d.screenX || 0, this.screenY = d.screenY || 0);this.button = a.button;this.key = a.key || "";this.ctrlKey = a.ctrlKey;this.altKey = a.altKey;this.shiftKey = a.shiftKey;this.metaKey = a.metaKey;this.pointerId = a.pointerId || 0;this.pointerType = l(a.pointerType) ? a.pointerType : fc[a.pointerType] || "";this.a = a;a.defaultPrevented && this.preventDefault();
}
}t(ec, C);var fc = ac({ 2: "touch", 3: "pen", 4: "mouse" });ec.prototype.preventDefault = function () {
ec.lb.preventDefault.call(this);var a = this.a;if (a.preventDefault) a.preventDefault();else if (a.returnValue = !1, cc) try {
if (a.ctrlKey || 112 <= a.keyCode && 123 >= a.keyCode) a.keyCode = -1;
} catch (b) {}
};ec.prototype.f = function () {
return this.a;
};var gc = "closure_listenable_" + (1E6 * Math.random() | 0),
hc = 0;function ic(a, b, c, d, e) {
this.listener = a;this.proxy = null;this.src = b;this.type = c;this.capture = !!d;this.La = e;this.key = ++hc;this.na = this.Ia = !1;
}function jc(a) {
a.na = !0;a.listener = null;a.proxy = null;a.src = null;a.La = null;
};function kc(a) {
this.src = a;this.a = {};this.b = 0;
}kc.prototype.add = function (a, b, c, d, e) {
var f = a.toString();a = this.a[f];a || (a = this.a[f] = [], this.b++);var h = lc(a, b, d, e);-1 < h ? (b = a[h], c || (b.Ia = !1)) : (b = new ic(b, this.src, f, !!d, e), b.Ia = c, a.push(b));return b;
};function mc(a, b) {
var c = b.type;c in a.a && Ga(a.a[c], b) && (jc(b), 0 == a.a[c].length && (delete a.a[c], a.b--));
}function lc(a, b, c, d) {
for (var e = 0; e < a.length; ++e) {
var f = a[e];if (!f.na && f.listener == b && f.capture == !!c && f.La == d) return e;
}return -1;
};var nc = "closure_lm_" + (1E6 * Math.random() | 0),
oc = {},
qc = 0;function rc(a, b, c, d, e) {
if (d && d.once) sc(a, b, c, d, e);else if (fa(b)) for (var f = 0; f < b.length; f++) rc(a, b[f], c, d, e);else c = tc(c), a && a[gc] ? uc(a, b, c, q(d) ? !!d.capture : !!d, e) : vc(a, b, c, !1, d, e);
}
function vc(a, b, c, d, e, f) {
if (!b) throw Error("Invalid event type");var h = q(e) ? !!e.capture : !!e,
m = wc(a);m || (a[nc] = m = new kc(a));c = m.add(b, c, d, h, f);if (!c.proxy) {
d = xc();c.proxy = d;d.src = a;d.listener = c;if (a.addEventListener) dc || (e = h), void 0 === e && (e = !1), a.addEventListener(b.toString(), d, e);else if (a.attachEvent) a.attachEvent(yc(b.toString()), d);else if (a.addListener && a.removeListener) a.addListener(d);else throw Error("addEventListener and attachEvent are unavailable.");qc++;
}
}
function xc() {
var a = zc,
b = bc ? function (c) {
return a.call(b.src, b.listener, c);
} : function (c) {
c = a.call(b.src, b.listener, c);if (!c) return c;
};return b;
}function sc(a, b, c, d, e) {
if (fa(b)) for (var f = 0; f < b.length; f++) sc(a, b[f], c, d, e);else c = tc(c), a && a[gc] ? Ac(a, b, c, q(d) ? !!d.capture : !!d, e) : vc(a, b, c, !0, d, e);
}
function D(a, b, c, d, e) {
if (fa(b)) for (var f = 0; f < b.length; f++) D(a, b[f], c, d, e);else (d = q(d) ? !!d.capture : !!d, c = tc(c), a && a[gc]) ? (a = a.m, b = String(b).toString(), b in a.a && (f = a.a[b], c = lc(f, c, d, e), -1 < c && (jc(f[c]), Array.prototype.splice.call(f, c, 1), 0 == f.length && (delete a.a[b], a.b--)))) : a && (a = wc(a)) && (b = a.a[b.toString()], a = -1, b && (a = lc(b, c, d, e)), (c = -1 < a ? b[a] : null) && Bc(c));
}
function Bc(a) {
if ("number" != typeof a && a && !a.na) {
var b = a.src;if (b && b[gc]) mc(b.m, a);else {
var c = a.type,
d = a.proxy;b.removeEventListener ? b.removeEventListener(c, d, a.capture) : b.detachEvent ? b.detachEvent(yc(c), d) : b.addListener && b.removeListener && b.removeListener(d);qc--;(c = wc(b)) ? (mc(c, a), 0 == c.b && (c.src = null, b[nc] = null)) : jc(a);
}
}
}function yc(a) {
return a in oc ? oc[a] : oc[a] = "on" + a;
}
function Cc(a, b, c, d) {
var e = !0;if (a = wc(a)) if (b = a.a[b.toString()]) for (b = b.concat(), a = 0; a < b.length; a++) {
var f = b[a];f && f.capture == c && !f.na && (f = Dc(f, d), e = e && !1 !== f);
}return e;
}function Dc(a, b) {
var c = a.listener,
d = a.La || a.src;a.Ia && Bc(a);return c.call(d, b);
}
function zc(a, b) {
if (a.na) return !0;if (!bc) {
if (!b) a: {
b = ["window", "event"];for (var c = k, d = 0; d < b.length; d++) if (c = c[b[d]], null == c) {
b = null;break a;
}b = c;
}d = b;b = new ec(d, this);c = !0;if (!(0 > d.keyCode || void 0 != d.returnValue)) {
a: {
var e = !1;if (0 == d.keyCode) try {
d.keyCode = -1;break a;
} catch (h) {
e = !0;
}if (e || void 0 == d.returnValue) d.returnValue = !0;
}d = [];for (e = b.b; e; e = e.parentNode) d.push(e);a = a.type;for (e = d.length - 1; 0 <= e; e--) {
b.b = d[e];var f = Cc(d[e], a, !0, b);c = c && f;
}for (e = 0; e < d.length; e++) b.b = d[e], f = Cc(d[e], a, !1, b), c = c && f;
}return c;
}return Dc(a, new ec(b, this));
}function wc(a) {
a = a[nc];return a instanceof kc ? a : null;
}var Ec = "__closure_events_fn_" + (1E9 * Math.random() >>> 0);function tc(a) {
if (n(a)) return a;a[Ec] || (a[Ec] = function (b) {
return a.handleEvent(b);
});return a[Ec];
};function E() {
Gb.call(this);this.m = new kc(this);this.Nb = this;this.Ua = null;
}t(E, Gb);E.prototype[gc] = !0;E.prototype.addEventListener = function (a, b, c, d) {
rc(this, a, b, c, d);
};E.prototype.removeEventListener = function (a, b, c, d) {
D(this, a, b, c, d);
};
E.prototype.dispatchEvent = function (a) {
var b,
c = this.Ua;if (c) for (b = []; c; c = c.Ua) b.push(c);c = this.Nb;var d = a.type || a;if (l(a)) a = new C(a, c);else if (a instanceof C) a.target = a.target || c;else {
var e = a;a = new C(d, c);bb(a, e);
}e = !0;if (b) for (var f = b.length - 1; 0 <= f; f--) {
var h = a.b = b[f];e = Fc(h, d, !0, a) && e;
}h = a.b = c;e = Fc(h, d, !0, a) && e;e = Fc(h, d, !1, a) && e;if (b) for (f = 0; f < b.length; f++) h = a.b = b[f], e = Fc(h, d, !1, a) && e;return e;
};
E.prototype.ua = function () {
E.lb.ua.call(this);if (this.m) {
var a = this.m,
b = 0,
c;for (c in a.a) {
for (var d = a.a[c], e = 0; e < d.length; e++) ++b, jc(d[e]);delete a.a[c];a.b--;
}
}this.Ua = null;
};function uc(a, b, c, d, e) {
a.m.add(String(b), c, !1, d, e);
}function Ac(a, b, c, d, e) {
a.m.add(String(b), c, !0, d, e);
}
function Fc(a, b, c, d) {
b = a.m.a[String(b)];if (!b) return !0;b = b.concat();for (var e = !0, f = 0; f < b.length; ++f) {
var h = b[f];if (h && !h.na && h.capture == c) {
var m = h.listener,
p = h.La || h.src;h.Ia && mc(a.m, h);e = !1 !== m.call(p, d) && e;
}
}return e && 0 != d.Gb;
};function Gc(a, b, c) {
if (n(a)) c && (a = r(a, c));else if (a && "function" == typeof a.handleEvent) a = r(a.handleEvent, a);else throw Error("Invalid listener argument");return 2147483647 < Number(b) ? -1 : k.setTimeout(a, b || 0);
}function Hc(a) {
var b = null;return new y(function (c, d) {
b = Gc(function () {
c(void 0);
}, a);-1 == b && d(Error("Failed to schedule timer."));
}).s(function (a) {
k.clearTimeout(b);throw a;
});
};function Ic(a) {
if (a.S && "function" == typeof a.S) return a.S();if (l(a)) return a.split("");if (ha(a)) {
for (var b = [], c = a.length, d = 0; d < c; d++) b.push(a[d]);return b;
}b = [];c = 0;for (d in a) b[c++] = a[d];return b;
}function Jc(a) {
if (a.U && "function" == typeof a.U) return a.U();if (!a.S || "function" != typeof a.S) {
if (ha(a) || l(a)) {
var b = [];a = a.length;for (var c = 0; c < a; c++) b.push(c);return b;
}b = [];c = 0;for (var d in a) b[c++] = d;return b;
}
}
function Kc(a, b) {
if (a.forEach && "function" == typeof a.forEach) a.forEach(b, void 0);else if (ha(a) || l(a)) v(a, b, void 0);else for (var c = Jc(a), d = Ic(a), e = d.length, f = 0; f < e; f++) b.call(void 0, d[f], c && c[f], a);
};function Lc(a, b) {
this.b = {};this.a = [];this.c = 0;var c = arguments.length;if (1 < c) {
if (c % 2) throw Error("Uneven number of arguments");for (var d = 0; d < c; d += 2) this.set(arguments[d], arguments[d + 1]);
} else if (a) if (a instanceof Lc) for (c = a.U(), d = 0; d < c.length; d++) this.set(c[d], a.get(c[d]));else for (d in a) this.set(d, a[d]);
}g = Lc.prototype;g.S = function () {
Mc(this);for (var a = [], b = 0; b < this.a.length; b++) a.push(this.b[this.a[b]]);return a;
};g.U = function () {
Mc(this);return this.a.concat();
};
g.clear = function () {
this.b = {};this.c = this.a.length = 0;
};function Mc(a) {
if (a.c != a.a.length) {
for (var b = 0, c = 0; b < a.a.length;) {
var d = a.a[b];Nc(a.b, d) && (a.a[c++] = d);b++;
}a.a.length = c;
}if (a.c != a.a.length) {
var e = {};for (c = b = 0; b < a.a.length;) d = a.a[b], Nc(e, d) || (a.a[c++] = d, e[d] = 1), b++;a.a.length = c;
}
}g.get = function (a, b) {
return Nc(this.b, a) ? this.b[a] : b;
};g.set = function (a, b) {
Nc(this.b, a) || (this.c++, this.a.push(a));this.b[a] = b;
};
g.forEach = function (a, b) {
for (var c = this.U(), d = 0; d < c.length; d++) {
var e = c[d],
f = this.get(e);a.call(b, f, e, this);
}
};function Nc(a, b) {
return Object.prototype.hasOwnProperty.call(a, b);
};var Oc = /^(?:([^:/?#.]+):)?(?:\/\/(?:([^/?#]*)@)?([^/#?]*?)(?::([0-9]+))?(?=[/#?]|$))?([^?#]+)?(?:\?([^#]*))?(?:#([\s\S]*))?$/;function Qc(a, b) {
if (a) {
a = a.split("&");for (var c = 0; c < a.length; c++) {
var d = a[c].indexOf("="),
e = null;if (0 <= d) {
var f = a[c].substring(0, d);e = a[c].substring(d + 1);
} else f = a[c];b(f, e ? decodeURIComponent(e.replace(/\+/g, " ")) : "");
}
}
};function Rc(a, b) {
this.b = this.m = this.c = "";this.i = null;this.h = this.g = "";this.f = !1;if (a instanceof Rc) {
this.f = void 0 !== b ? b : a.f;Sc(this, a.c);this.m = a.m;this.b = a.b;Tc(this, a.i);this.g = a.g;b = a.a;var c = new Uc();c.c = b.c;b.a && (c.a = new Lc(b.a), c.b = b.b);Vc(this, c);this.h = a.h;
} else a && (c = String(a).match(Oc)) ? (this.f = !!b, Sc(this, c[1] || "", !0), this.m = Wc(c[2] || ""), this.b = Wc(c[3] || "", !0), Tc(this, c[4]), this.g = Wc(c[5] || "", !0), Vc(this, c[6] || "", !0), this.h = Wc(c[7] || "")) : (this.f = !!b, this.a = new Uc(null, this.f));
}
Rc.prototype.toString = function () {
var a = [],
b = this.c;b && a.push(Xc(b, Yc, !0), ":");var c = this.b;if (c || "file" == b) a.push("//"), (b = this.m) && a.push(Xc(b, Yc, !0), "@"), a.push(encodeURIComponent(String(c)).replace(/%25([0-9a-fA-F]{2})/g, "%$1")), c = this.i, null != c && a.push(":", String(c));if (c = this.g) this.b && "/" != c.charAt(0) && a.push("/"), a.push(Xc(c, "/" == c.charAt(0) ? Zc : $c, !0));(c = this.a.toString()) && a.push("?", c);(c = this.h) && a.push("#", Xc(c, ad));return a.join("");
};
function Sc(a, b, c) {
a.c = c ? Wc(b, !0) : b;a.c && (a.c = a.c.replace(/:$/, ""));
}function Tc(a, b) {
if (b) {
b = Number(b);if (isNaN(b) || 0 > b) throw Error("Bad port number " + b);a.i = b;
} else a.i = null;
}function Vc(a, b, c) {
b instanceof Uc ? (a.a = b, bd(a.a, a.f)) : (c || (b = Xc(b, cd)), a.a = new Uc(b, a.f));
}function F(a, b, c) {
a.a.set(b, c);
}function dd(a, b) {
return a.a.get(b);
}function ed(a) {
return a instanceof Rc ? new Rc(a) : new Rc(a, void 0);
}function fd(a, b) {
var c = new Rc(null, void 0);Sc(c, "https");a && (c.b = a);b && (c.g = b);return c;
}
function Wc(a, b) {
return a ? b ? decodeURI(a.replace(/%25/g, "%2525")) : decodeURIComponent(a) : "";
}function Xc(a, b, c) {
return l(a) ? (a = encodeURI(a).replace(b, gd), c && (a = a.replace(/%25([0-9a-fA-F]{2})/g, "%$1")), a) : null;
}function gd(a) {
a = a.charCodeAt(0);return "%" + (a >> 4 & 15).toString(16) + (a & 15).toString(16);
}var Yc = /[#\/\?@]/g,
$c = /[#\?:]/g,
Zc = /[#\?]/g,
cd = /[#\?@]/g,
ad = /#/g;function Uc(a, b) {
this.b = this.a = null;this.c = a || null;this.f = !!b;
}
function hd(a) {
a.a || (a.a = new Lc(), a.b = 0, a.c && Qc(a.c, function (b, c) {
a.add(decodeURIComponent(b.replace(/\+/g, " ")), c);
}));
}function id(a) {
var b = Jc(a);if ("undefined" == typeof b) throw Error("Keys are undefined");var c = new Uc(null, void 0);a = Ic(a);for (var d = 0; d < b.length; d++) {
var e = b[d],
f = a[d];fa(f) ? jd(c, e, f) : c.add(e, f);
}return c;
}g = Uc.prototype;g.add = function (a, b) {
hd(this);this.c = null;a = kd(this, a);var c = this.a.get(a);c || this.a.set(a, c = []);c.push(b);this.b += 1;return this;
};
function ld(a, b) {
hd(a);b = kd(a, b);Nc(a.a.b, b) && (a.c = null, a.b -= a.a.get(b).length, a = a.a, Nc(a.b, b) && (delete a.b[b], a.c--, a.a.length > 2 * a.c && Mc(a)));
}g.clear = function () {
this.a = this.c = null;this.b = 0;
};function md(a, b) {
hd(a);b = kd(a, b);return Nc(a.a.b, b);
}g.forEach = function (a, b) {
hd(this);this.a.forEach(function (c, d) {
v(c, function (c) {
a.call(b, c, d, this);
}, this);
}, this);
};g.U = function () {
hd(this);for (var a = this.a.S(), b = this.a.U(), c = [], d = 0; d < b.length; d++) for (var e = a[d], f = 0; f < e.length; f++) c.push(b[d]);return c;
};
g.S = function (a) {
hd(this);var b = [];if (l(a)) md(this, a) && (b = Ia(b, this.a.get(kd(this, a))));else {
a = this.a.S();for (var c = 0; c < a.length; c++) b = Ia(b, a[c]);
}return b;
};g.set = function (a, b) {
hd(this);this.c = null;a = kd(this, a);md(this, a) && (this.b -= this.a.get(a).length);this.a.set(a, [b]);this.b += 1;return this;
};g.get = function (a, b) {
a = a ? this.S(a) : [];return 0 < a.length ? String(a[0]) : b;
};function jd(a, b, c) {
ld(a, b);0 < c.length && (a.c = null, a.a.set(kd(a, b), Ja(c)), a.b += c.length);
}
g.toString = function () {
if (this.c) return this.c;if (!this.a) return "";for (var a = [], b = this.a.U(), c = 0; c < b.length; c++) {
var d = b[c],
e = encodeURIComponent(String(d));d = this.S(d);for (var f = 0; f < d.length; f++) {
var h = e;"" !== d[f] && (h += "=" + encodeURIComponent(String(d[f])));a.push(h);
}
}return this.c = a.join("&");
};function kd(a, b) {
b = String(b);a.f && (b = b.toLowerCase());return b;
}function bd(a, b) {
b && !a.f && (hd(a), a.c = null, a.a.forEach(function (a, b) {
var c = b.toLowerCase();b != c && (ld(this, b), jd(this, c, a));
}, a));a.f = b;
};var nd = !Ob || 9 <= Number(Zb);function od() {
this.a = "";this.b = pd;
}od.prototype.ma = !0;od.prototype.la = function () {
return this.a;
};od.prototype.toString = function () {
return "Const{" + this.a + "}";
};function qd(a) {
if (a instanceof od && a.constructor === od && a.b === pd) return a.a;ra("expected object of type Const, got '" + a + "'");return "type_error:Const";
}var pd = {};function rd(a) {
var b = new od();b.a = a;return b;
}rd("");function sd() {
this.a = "";this.b = td;
}sd.prototype.ma = !0;sd.prototype.la = function () {
return this.a;
};sd.prototype.toString = function () {
return "TrustedResourceUrl{" + this.a + "}";
};function ud(a) {
if (a instanceof sd && a.constructor === sd && a.b === td) return a.a;ra("expected object of type TrustedResourceUrl, got '" + a + "' of type " + da(a));return "type_error:TrustedResourceUrl";
}
function vd(a, b) {
var c = qd(a);if (!wd.test(c)) throw Error("Invalid TrustedResourceUrl format: " + c);a = c.replace(xd, function (a, e) {
if (!Object.prototype.hasOwnProperty.call(b, e)) throw Error('Found marker, "' + e + '", in format string, "' + c + '", but no valid label mapping found in args: ' + JSON.stringify(b));a = b[e];return a instanceof od ? qd(a) : encodeURIComponent(String(a));
});return yd(a);
}var xd = /%{(\w+)}/g,
wd = /^(?:https:)?\/\/[0-9a-z.:[\]-]+\/|^\/[^\/\\]|^about:blank#/i,
td = {};
function yd(a) {
var b = new sd();b.a = a;return b;
};function zd() {
this.a = "";this.b = Ad;
}zd.prototype.ma = !0;zd.prototype.la = function () {
return this.a;
};zd.prototype.toString = function () {
return "SafeUrl{" + this.a + "}";
};function Bd(a) {
if (a instanceof zd && a.constructor === zd && a.b === Ad) return a.a;ra("expected object of type SafeUrl, got '" + a + "' of type " + da(a));return "type_error:SafeUrl";
}var Cd = /^(?:(?:https?|mailto|ftp):|[^:/?#]*(?:[/?#]|$))/i;
function Dd(a) {
if (a instanceof zd) return a;a = a.ma ? a.la() : String(a);Cd.test(a) || (a = "about:invalid#zClosurez");return Ed(a);
}var Ad = {};function Ed(a) {
var b = new zd();b.a = a;return b;
}Ed("about:blank");function Fd() {
this.a = "";this.b = Gd;
}Fd.prototype.ma = !0;Fd.prototype.la = function () {
return this.a;
};Fd.prototype.toString = function () {
return "SafeHtml{" + this.a + "}";
};function Hd(a) {
if (a instanceof Fd && a.constructor === Fd && a.b === Gd) return a.a;ra("expected object of type SafeHtml, got '" + a + "' of type " + da(a));return "type_error:SafeHtml";
}var Gd = {};function Id(a) {
var b = new Fd();b.a = a;return b;
}Id("<!DOCTYPE html>");Id("");Id("<br>");function Jd(a) {
var b = document;return l(a) ? b.getElementById(a) : a;
}function Kd(a, b) {
Ya(b, function (b, d) {
b && b.ma && (b = b.la());"style" == d ? a.style.cssText = b : "class" == d ? a.className = b : "for" == d ? a.htmlFor = b : Ld.hasOwnProperty(d) ? a.setAttribute(Ld[d], b) : 0 == d.lastIndexOf("aria-", 0) || 0 == d.lastIndexOf("data-", 0) ? a.setAttribute(d, b) : a[d] = b;
});
}
var Ld = { cellpadding: "cellPadding", cellspacing: "cellSpacing", colspan: "colSpan", frameborder: "frameBorder", height: "height", maxlength: "maxLength", nonce: "nonce", role: "role", rowspan: "rowSpan", type: "type", usemap: "useMap", valign: "vAlign", width: "width" };
function Md(a, b, c) {
var d = arguments,
e = document,
f = String(d[0]),
h = d[1];if (!nd && h && (h.name || h.type)) {
f = ["<", f];h.name && f.push(' name="', Ma(h.name), '"');if (h.type) {
f.push(' type="', Ma(h.type), '"');var m = {};bb(m, h);delete m.type;h = m;
}f.push(">");f = f.join("");
}f = e.createElement(f);h && (l(h) ? f.className = h : fa(h) ? f.className = h.join(" ") : Kd(f, h));2 < d.length && Nd(e, f, d);return f;
}
function Nd(a, b, c) {
function d(c) {
c && b.appendChild(l(c) ? a.createTextNode(c) : c);
}for (var e = 2; e < c.length; e++) {
var f = c[e];!ha(f) || q(f) && 0 < f.nodeType ? d(f) : v(Od(f) ? Ja(f) : f, d);
}
}function Od(a) {
if (a && "number" == typeof a.length) {
if (q(a)) return "function" == typeof a.item || "string" == typeof a.item;if (n(a)) return "function" == typeof a.item;
}return !1;
};function Pd(a) {
var b = [];Qd(new Rd(), a, b);return b.join("");
}function Rd() {}
function Qd(a, b, c) {
if (null == b) c.push("null");else {
if ("object" == typeof b) {
if (fa(b)) {
var d = b;b = d.length;c.push("[");for (var e = "", f = 0; f < b; f++) c.push(e), Qd(a, d[f], c), e = ",";c.push("]");return;
}if (b instanceof String || b instanceof Number || b instanceof Boolean) b = b.valueOf();else {
c.push("{");e = "";for (d in b) Object.prototype.hasOwnProperty.call(b, d) && (f = b[d], "function" != typeof f && (c.push(e), Sd(d, c), c.push(":"), Qd(a, f, c), e = ","));c.push("}");return;
}
}switch (typeof b) {case "string":
Sd(b, c);break;case "number":
c.push(isFinite(b) && !isNaN(b) ? String(b) : "null");break;case "boolean":
c.push(String(b));break;case "function":
c.push("null");break;default:
throw Error("Unknown type: " + typeof b);}
}
}var Td = { '"': '\\"', "\\": "\\\\", "/": "\\/", "\b": "\\b", "\f": "\\f", "\n": "\\n", "\r": "\\r", "\t": "\\t", "\x0B": "\\u000b" },
Ud = /\uffff/.test("\uffff") ? /[\\"\x00-\x1f\x7f-\uffff]/g : /[\\"\x00-\x1f\x7f-\xff]/g;
function Sd(a, b) {
b.push('"', a.replace(Ud, function (a) {
var b = Td[a];b || (b = "\\u" + (a.charCodeAt(0) | 65536).toString(16).substr(1), Td[a] = b);return b;
}), '"');
};function Vd() {
var a = G();return Ob && !!Zb && 11 == Zb || /Edge\/\d+/.test(a);
}function Wd() {
return k.window && k.window.location.href || self && self.location && self.location.href || "";
}function Xd(a, b) {
b = b || k.window;var c = "about:blank";a && (c = Bd(Dd(a)));b.location.href = c;
}function Yd(a, b) {
var c = [],
d;for (d in a) d in b ? typeof a[d] != typeof b[d] ? c.push(d) : "object" == typeof a[d] && null != a[d] && null != b[d] ? 0 < Yd(a[d], b[d]).length && c.push(d) : a[d] !== b[d] && c.push(d) : c.push(d);for (d in b) d in a || c.push(d);return c;
}
function Zd() {
var a = G();a = $d(a) != ae ? null : (a = a.match(/\sChrome\/(\d+)/i)) && 2 == a.length ? parseInt(a[1], 10) : null;return a && 30 > a ? !1 : !Ob || !Zb || 9 < Zb;
}function be(a) {
a = (a || G()).toLowerCase();return a.match(/android/) || a.match(/webos/) || a.match(/iphone|ipad|ipod/) || a.match(/blackberry/) || a.match(/windows phone/) || a.match(/iemobile/) ? !0 : !1;
}function ce(a) {
a = a || k.window;try {
a.close();
} catch (b) {}
}
function de(a, b, c) {
var d = Math.floor(1E9 * Math.random()).toString();b = b || 500;c = c || 600;var e = (window.screen.availHeight - c) / 2,
f = (window.screen.availWidth - b) / 2;b = { width: b, height: c, top: 0 < e ? e : 0, left: 0 < f ? f : 0, location: !0, resizable: !0, statusbar: !0, toolbar: !1 };c = G().toLowerCase();d && (b.target = d, w(c, "crios/") && (b.target = "_blank"));$d(G()) == ee && (a = a || "http://localhost", b.scrollbars = !0);c = a || "";(a = b) || (a = {});d = window;b = c instanceof zd ? c : Dd("undefined" != typeof c.href ? c.href : String(c));c = a.target || c.target;e = [];
for (h in a) switch (h) {case "width":case "height":case "top":case "left":
e.push(h + "=" + a[h]);break;case "target":case "noopener":case "noreferrer":
break;default:
e.push(h + "=" + (a[h] ? 1 : 0));}var h = e.join(",");(x("iPhone") && !x("iPod") && !x("iPad") || x("iPad") || x("iPod")) && d.navigator && d.navigator.standalone && c && "_self" != c ? (h = d.document.createElement("A"), b instanceof zd || b instanceof zd || (b = b.ma ? b.la() : String(b), Cd.test(b) || (b = "about:invalid#zClosurez"), b = Ed(b)), h.href = Bd(b), h.setAttribute("target", c), a.noreferrer && h.setAttribute("rel", "noreferrer"), a = document.createEvent("MouseEvent"), a.initMouseEvent("click", !0, !0, d, 1), h.dispatchEvent(a), h = {}) : a.noreferrer ? (h = d.open("", c, h), a = Bd(b), h && (Qb && w(a, ";") && (a = "'" + a.replace(/'/g, "%27") + "'"), h.opener = null, rd("b/12014412, meta tag with sanitized URL"), a = '<meta name="referrer" content="no-referrer"><meta http-equiv="refresh" content="0; url=' + Ma(a) + '">', a = Id(a), h.document.write(Hd(a)), h.document.close())) : (h = d.open(Bd(b), c, h)) && a.noopener && (h.opener = null);if (h) try {
h.focus();
} catch (m) {}return h;
}
function fe(a) {
return new y(function (b) {
function c() {
Hc(2E3).then(function () {
if (!a || a.closed) b();else return c();
});
}return c();
});
}var ge = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;function he() {
var a = null;return new y(function (b) {
"complete" == k.document.readyState ? b() : (a = function () {
b();
}, sc(window, "load", a));
}).s(function (b) {
D(window, "load", a);throw b;
});
}
function ie() {
return je(void 0) ? he().then(function () {
return new y(function (a, b) {
var c = k.document,
d = setTimeout(function () {
b(Error("Cordova framework is not ready."));
}, 1E3);c.addEventListener("deviceready", function () {
clearTimeout(d);a();
}, !1);
});
}) : B(Error("Cordova must run in an Android or iOS file scheme."));
}function je(a) {
a = a || G();return !("file:" !== ke() || !a.toLowerCase().match(/iphone|ipad|ipod|android/));
}function le() {
var a = k.window;try {
return !(!a || a == a.top);
} catch (b) {
return !1;
}
}
function me() {
return "object" !== typeof k.window && "function" === typeof k.importScripts;
}function ne() {
return firebase.INTERNAL.hasOwnProperty("reactNative") ? "ReactNative" : firebase.INTERNAL.hasOwnProperty("node") ? "Node" : me() ? "Worker" : "Browser";
}function oe() {
var a = ne();return "ReactNative" === a || "Node" === a;
}function pe() {
for (var a = 50, b = []; 0 < a;) b.push("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Math.floor(62 * Math.random()))), a--;return b.join("");
}var ee = "Firefox",
ae = "Chrome";
function $d(a) {
var b = a.toLowerCase();if (w(b, "opera/") || w(b, "opr/") || w(b, "opios/")) return "Opera";if (w(b, "iemobile")) return "IEMobile";if (w(b, "msie") || w(b, "trident/")) return "IE";if (w(b, "edge/")) return "Edge";if (w(b, "firefox/")) return ee;if (w(b, "silk/")) return "Silk";if (w(b, "blackberry")) return "Blackberry";if (w(b, "webos")) return "Webos";if (!w(b, "safari/") || w(b, "chrome/") || w(b, "crios/") || w(b, "android")) {
if (!w(b, "chrome/") && !w(b, "crios/") || w(b, "edge/")) {
if (w(b, "android")) return "Android";if ((a = a.match(/([a-zA-Z\d\.]+)\/[a-zA-Z\d\.]*$/)) && 2 == a.length) return a[1];
} else return ae;
} else return "Safari";return "Other";
}var qe = { Sc: "FirebaseCore-web", Uc: "FirebaseUI-web" };function re(a, b) {
b = b || [];var c = [],
d = {},
e;for (e in qe) d[qe[e]] = !0;for (e = 0; e < b.length; e++) "undefined" !== typeof d[b[e]] && (delete d[b[e]], c.push(b[e]));c.sort();b = c;b.length || (b = ["FirebaseCore-web"]);c = ne();"Browser" === c ? (d = G(), c = $d(d)) : "Worker" === c && (d = G(), c = $d(d) + "-" + c);return c + "/JsCore/" + a + "/" + b.join(",");
}function G() {
return k.navigator && k.navigator.userAgent || "";
}
function H(a, b) {
a = a.split(".");b = b || k;for (var c = 0; c < a.length && "object" == typeof b && null != b; c++) b = b[a[c]];c != a.length && (b = void 0);return b;
}function se() {
try {
var a = k.localStorage,
b = te();if (a) return a.setItem(b, "1"), a.removeItem(b), Vd() ? !!k.indexedDB : !0;
} catch (c) {
return me() && !!k.indexedDB;
}return !1;
}function ue() {
return (ve() || "chrome-extension:" === ke() || je()) && !oe() && se() && !me();
}function ve() {
return "http:" === ke() || "https:" === ke();
}function ke() {
return k.location && k.location.protocol || null;
}
function we(a) {
a = a || G();return be(a) || $d(a) == ee ? !1 : !0;
}function xe(a) {
return "undefined" === typeof a ? null : Pd(a);
}function ye(a) {
var b = {},
c;for (c in a) a.hasOwnProperty(c) && null !== a[c] && void 0 !== a[c] && (b[c] = a[c]);return b;
}function ze(a) {
if (null !== a) return JSON.parse(a);
}function te(a) {
return a ? a : Math.floor(1E9 * Math.random()).toString();
}function Ae(a) {
a = a || G();return "Safari" == $d(a) || a.toLowerCase().match(/iphone|ipad|ipod/) ? !1 : !0;
}
function Be() {
var a = k.___jsl;if (a && a.H) for (var b in a.H) if (a.H[b].r = a.H[b].r || [], a.H[b].L = a.H[b].L || [], a.H[b].r = a.H[b].L.concat(), a.CP) for (var c = 0; c < a.CP.length; c++) a.CP[c] = null;
}function Ce(a, b) {
if (a > b) throw Error("Short delay should be less than long delay!");this.a = a;this.c = b;a = G();b = ne();this.b = be(a) || "ReactNative" === b;
}
Ce.prototype.get = function () {
var a = k.navigator;return (a && "boolean" === typeof a.onLine && (ve() || "chrome-extension:" === ke() || "undefined" !== typeof a.connection) ? a.onLine : 1) ? this.b ? this.c : this.a : Math.min(5E3, this.a);
};function De() {
var a = k.document;return a && "undefined" !== typeof a.visibilityState ? "visible" == a.visibilityState : !0;
}
function Ee() {
var a = k.document,
b = null;return De() || !a ? A() : new y(function (c) {
b = function () {
De() && (a.removeEventListener("visibilitychange", b, !1), c());
};a.addEventListener("visibilitychange", b, !1);
}).s(function (c) {
a.removeEventListener("visibilitychange", b, !1);throw c;
});
}function Fe(a) {
try {
var b = new Date(parseInt(a, 10));if (!isNaN(b.getTime()) && !/[^0-9]/.test(a)) return b.toUTCString();
} catch (c) {}return null;
}function Ge() {
return !(!H("fireauth.oauthhelper", k) && !H("fireauth.iframe", k));
};var He = {};function Ie(a) {
He[a] || (He[a] = !0, "undefined" !== typeof console && "function" === typeof console.warn && console.warn(a));
};var Je;try {
var Ke = {};Object.defineProperty(Ke, "abcd", { configurable: !0, enumerable: !0, value: 1 });Object.defineProperty(Ke, "abcd", { configurable: !0, enumerable: !0, value: 2 });Je = 2 == Ke.abcd;
} catch (a) {
Je = !1;
}function I(a, b, c) {
Je ? Object.defineProperty(a, b, { configurable: !0, enumerable: !0, value: c }) : a[b] = c;
}function J(a, b) {
if (b) for (var c in b) b.hasOwnProperty(c) && I(a, c, b[c]);
}function Le(a) {
var b = {};J(b, a);return b;
}function Me(a) {
var b = {},
c;for (c in a) a.hasOwnProperty(c) && (b[c] = a[c]);return b;
}
function Ne(a, b) {
if (!b || !b.length) return !0;if (!a) return !1;for (var c = 0; c < b.length; c++) {
var d = a[b[c]];if (void 0 === d || null === d || "" === d) return !1;
}return !0;
}function Oe(a) {
var b = a;if ("object" == typeof a && null != a) {
b = "length" in a ? [] : {};for (var c in a) I(b, c, Oe(a[c]));
}return b;
};function Pe(a) {
var b = {},
c = a[Qe],
d = a[Re];a = a[Se];if (!a || a != Te && !c) throw Error("Invalid provider user info!");b[Ue] = d || null;b[Ve] = c || null;I(this, We, a);I(this, Xe, Oe(b));
}var Te = "EMAIL_SIGNIN",
Qe = "email",
Re = "newEmail",
Se = "requestType",
Ve = "email",
Ue = "fromEmail",
Xe = "data",
We = "operation";function K(a, b) {
this.code = Ye + a;this.message = b || Ze[a] || "";
}t(K, Error);K.prototype.D = function () {
return { code: this.code, message: this.message };
};K.prototype.toJSON = function () {
return this.D();
};function $e(a) {
var b = a && a.code;return b ? new K(b.substring(Ye.length), a.message) : null;
}
var Ye = "auth/",
Ze = { "argument-error": "", "app-not-authorized": "This app, identified by the domain where it's hosted, is not authorized to use Firebase Authentication with the provided API key. Review your key configuration in the Google API console.", "app-not-installed": "The requested mobile application corresponding to the identifier (Android package name or iOS bundle ID) provided is not installed on this device.", "captcha-check-failed": "The reCAPTCHA response token provided is either invalid, expired, already used or the domain associated with it does not match the list of whitelisted domains.",
"code-expired": "The SMS code has expired. Please re-send the verification code to try again.", "cordova-not-ready": "Cordova framework is not ready.", "cors-unsupported": "This browser is not supported.", "credential-already-in-use": "This credential is already associated with a different user account.", "custom-token-mismatch": "The custom token corresponds to a different audience.", "requires-recent-login": "This operation is sensitive and requires recent authentication. Log in again before retrying this request.",
"dynamic-link-not-activated": "Please activate Dynamic Links in the Firebase Console and agree to the terms and conditions.", "email-already-in-use": "The email address is already in use by another account.", "expired-action-code": "The action code has expired. ", "cancelled-popup-request": "This operation has been cancelled due to another conflicting popup being opened.", "internal-error": "An internal error has occurred.", "invalid-app-credential": "The phone verification request contains an invalid application verifier. The reCAPTCHA token response is either invalid or expired.",
"invalid-app-id": "The mobile app identifier is not registed for the current project.", "invalid-user-token": "This user's credential isn't valid for this project. This can happen if the user's token has been tampered with, or if the user isn't for the project associated with this API key.", "invalid-auth-event": "An internal error has occurred.", "invalid-verification-code": "The SMS verification code used to create the phone auth credential is invalid. Please resend the verification code sms and be sure use the verification code provided by the user.",
"invalid-continue-uri": "The continue URL provided in the request is invalid.", "invalid-cordova-configuration": "The following Cordova plugins must be installed to enable OAuth sign-in: cordova-plugin-buildinfo, cordova-universal-links-plugin, cordova-plugin-browsertab, cordova-plugin-inappbrowser and cordova-plugin-customurlscheme.", "invalid-custom-token": "The custom token format is incorrect. Please check the documentation.", "invalid-email": "The email address is badly formatted.", "invalid-api-key": "Your API key is invalid, please check you have copied it correctly.",
"invalid-cert-hash": "The SHA-1 certificate hash provided is invalid.", "invalid-credential": "The supplied auth credential is malformed or has expired.", "invalid-persistence-type": "The specified persistence type is invalid. It can only be local, session or none.", "invalid-message-payload": "The email template corresponding to this action contains invalid characters in its message. Please fix by going to the Auth email templates section in the Firebase Console.", "invalid-oauth-provider": "EmailAuthProvider is not supported for this operation. This operation only supports OAuth providers.",
"invalid-oauth-client-id": "The OAuth client ID provided is either invalid or does not match the specified API key.", "unauthorized-domain": "This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.", "invalid-action-code": "The action code is invalid. This can happen if the code is malformed, expired, or has already been used.", "wrong-password": "The password is invalid or the user does not have a password.", "invalid-phone-number": "The format of the phone number provided is incorrect. Please enter the phone number in a format that can be parsed into E.164 format. E.164 phone numbers are written in the format [+][country code][subscriber number including area code].",
"invalid-recipient-email": "The email corresponding to this action failed to send as the provided recipient email address is invalid.", "invalid-sender": "The email template corresponding to this action contains an invalid sender email or name. Please fix by going to the Auth email templates section in the Firebase Console.", "invalid-verification-id": "The verification ID used to create the phone auth credential is invalid.", "missing-android-pkg-name": "An Android Package Name must be provided if the Android App is required to be installed.",
"auth-domain-config-required": "Be sure to include authDomain when calling firebase.initializeApp(), by following the instructions in the Firebase console.", "missing-app-credential": "The phone verification request is missing an application verifier assertion. A reCAPTCHA response token needs to be provided.", "missing-verification-code": "The phone auth credential was created with an empty SMS verification code.", "missing-continue-uri": "A continue URL must be provided in the request.", "missing-iframe-start": "An internal error has occurred.",
"missing-ios-bundle-id": "An iOS Bundle ID must be provided if an App Store ID is provided.", "missing-phone-number": "To send verification codes, provide a phone number for the recipient.", "missing-verification-id": "The phone auth credential was created with an empty verification ID.", "app-deleted": "This instance of FirebaseApp has been deleted.", "account-exists-with-different-credential": "An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.",
"network-request-failed": "A network error (such as timeout, interrupted connection or unreachable host) has occurred.", "no-auth-event": "An internal error has occurred.", "no-such-provider": "User was not linked to an account with the given provider.", "null-user": "A null user object was provided as the argument for an operation which requires a non-null user object.", "operation-not-allowed": "The given sign-in provider is disabled for this Firebase project. Enable it in the Firebase console, under the sign-in method tab of the Auth section.",
"operation-not-supported-in-this-environment": 'This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled.', "popup-blocked": "Unable to establish a connection with the popup. It may have been blocked by the browser.", "popup-closed-by-user": "The popup has been closed by the user before finalizing the operation.", "provider-already-linked": "User can only be linked to one identity for the given provider.",
"quota-exceeded": "The project's quota for this operation has been exceeded.", "redirect-cancelled-by-user": "The redirect operation has been cancelled by the user before finalizing.", "redirect-operation-pending": "A redirect sign-in operation is already pending.", timeout: "The operation has timed out.", "user-token-expired": "The user's credential is no longer valid. The user must sign in again.", "too-many-requests": "We have blocked all requests from this device due to unusual activity. Try again later.",
"unauthorized-continue-uri": "The domain of the continue URL is not whitelisted. Please whitelist the domain in the Firebase console.", "unsupported-persistence-type": "The current environment does not support the specified persistence type.", "user-cancelled": "User did not grant your application the permissions it requested.", "user-not-found": "There is no user record corresponding to this identifier. The user may have been deleted.", "user-disabled": "The user account has been disabled by an administrator.",
"user-mismatch": "The supplied credentials do not correspond to the previously signed in user.", "user-signed-out": "", "weak-password": "The password must be 6 characters long or more.", "web-storage-unsupported": "This browser is not supported or 3rd party cookies and data may be disabled." };function af(a) {
var b = a[bf];if ("undefined" === typeof b) throw new K("missing-continue-uri");if ("string" !== typeof b || "string" === typeof b && !b.length) throw new K("invalid-continue-uri");this.h = b;this.b = this.a = null;this.g = !1;var c = a[cf];if (c && "object" === typeof c) {
b = c[df];var d = c[ef];c = c[ff];if ("string" === typeof b && b.length) {
this.a = b;if ("undefined" !== typeof d && "boolean" !== typeof d) throw new K("argument-error", ef + " property must be a boolean when specified.");this.g = !!d;if ("undefined" !== typeof c && ("string" !== typeof c || "string" === typeof c && !c.length)) throw new K("argument-error", ff + " property must be a non empty string when specified.");this.b = c || null;
} else {
if ("undefined" !== typeof b) throw new K("argument-error", df + " property must be a non empty string when specified.");if ("undefined" !== typeof d || "undefined" !== typeof c) throw new K("missing-android-pkg-name");
}
} else if ("undefined" !== typeof c) throw new K("argument-error", cf + " property must be a non null object when specified.");this.f = null;if ((b = a[gf]) && "object" === typeof b) {
if (b = b[hf], "string" === typeof b && b.length) this.f = b;else {
if ("undefined" !== typeof b) throw new K("argument-error", hf + " property must be a non empty string when specified.");
}
} else if ("undefined" !== typeof b) throw new K("argument-error", gf + " property must be a non null object when specified.");a = a[jf];if ("undefined" !== typeof a && "boolean" !== typeof a) throw new K("argument-error", jf + " property must be a boolean when specified.");this.c = !!a;
}
var cf = "android",
jf = "handleCodeInApp",
gf = "iOS",
bf = "url",
ef = "installApp",
ff = "minimumVersion",
df = "packageName",
hf = "bundleId";function kf(a) {
var b = {};b.continueUrl = a.h;b.canHandleCodeInApp = a.c;if (b.androidPackageName = a.a) b.androidMinimumVersion = a.b, b.androidInstallApp = a.g;b.iOSBundleId = a.f;for (var c in b) null === b[c] && delete b[c];return b;
};function lf(a) {
return Ba(a, function (a) {
a = a.toString(16);return 1 < a.length ? a : "0" + a;
}).join("");
};var mf = null,
nf = null;function of(a) {
var b = "";pf(a, function (a) {
b += String.fromCharCode(a);
});return b;
}function pf(a, b) {
function c(b) {
for (; d < a.length;) {
var c = a.charAt(d++),
e = nf[c];if (null != e) return e;if (!/^[\s\xa0]*$/.test(c)) throw Error("Unknown base64 encoding at char: " + c);
}return b;
}qf();for (var d = 0;;) {
var e = c(-1),
f = c(0),
h = c(64),
m = c(64);if (64 === m && -1 === e) break;b(e << 2 | f >> 4);64 != h && (b(f << 4 & 240 | h >> 2), 64 != m && b(h << 6 & 192 | m));
}
}
function qf() {
if (!mf) {
mf = {};nf = {};for (var a = 0; 65 > a; a++) mf[a] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(a), nf[mf[a]] = a, 62 <= a && (nf["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.".charAt(a)] = a);
}
};function rf(a) {
this.c = a.sub;na();this.a = a.provider_id || a.firebase && a.firebase.sign_in_provider || null;this.b = !!a.is_anonymous || "anonymous" == this.a;
}rf.prototype.f = function () {
return this.b;
};function sf(a) {
return (a = tf(a)) && a.sub && a.iss && a.aud && a.exp ? new rf(a) : null;
}function tf(a) {
if (!a) return null;a = a.split(".");if (3 != a.length) return null;a = a[1];for (var b = (4 - a.length % 4) % 4, c = 0; c < b; c++) a += ".";try {
return JSON.parse(of(a));
} catch (d) {}return null;
};var uf = "oauth_consumer_key oauth_nonce oauth_signature oauth_signature_method oauth_timestamp oauth_token oauth_version".split(" "),
vf = ["client_id", "response_type", "scope", "redirect_uri", "state"],
wf = { Tc: { Ma: "locale", Ba: 500, Aa: 600, Na: "facebook.com", eb: vf }, Vc: { Ma: null, Ba: 500, Aa: 620, Na: "github.com", eb: vf }, Wc: { Ma: "hl", Ba: 515, Aa: 680, Na: "google.com", eb: vf }, bd: { Ma: "lang", Ba: 485, Aa: 705, Na: "twitter.com", eb: uf } };function xf(a) {
for (var b in wf) if (wf[b].Na == a) return wf[b];return null;
};function yf(a) {
var b = {};b["facebook.com"] = zf;b["google.com"] = Af;b["github.com"] = Bf;b["twitter.com"] = Cf;var c = a && a[Df];try {
if (c) return b[c] ? new b[c](a) : new Ef(a);if ("undefined" !== typeof a[Ff]) return new Gf(a);
} catch (d) {}return null;
}var Ff = "idToken",
Df = "providerId";
function Gf(a) {
var b = a[Df];if (!b && a[Ff]) {
var c = sf(a[Ff]);c && c.a && (b = c.a);
}if (!b) throw Error("Invalid additional user info!");if ("anonymous" == b || "custom" == b) b = null;c = !1;"undefined" !== typeof a.isNewUser ? c = !!a.isNewUser : "identitytoolkit#SignupNewUserResponse" === a.kind && (c = !0);I(this, "providerId", b);I(this, "isNewUser", c);
}function Ef(a) {
Gf.call(this, a);a = ze(a.rawUserInfo || "{}");I(this, "profile", Oe(a || {}));
}t(Ef, Gf);
function zf(a) {
Ef.call(this, a);if ("facebook.com" != this.providerId) throw Error("Invalid provider ID!");
}t(zf, Ef);function Bf(a) {
Ef.call(this, a);if ("github.com" != this.providerId) throw Error("Invalid provider ID!");I(this, "username", this.profile && this.profile.login || null);
}t(Bf, Ef);function Af(a) {
Ef.call(this, a);if ("google.com" != this.providerId) throw Error("Invalid provider ID!");
}t(Af, Ef);
function Cf(a) {
Ef.call(this, a);if ("twitter.com" != this.providerId) throw Error("Invalid provider ID!");I(this, "username", a.screenName || null);
}t(Cf, Ef);function Hf(a) {
this.a = ed(a);
};function If(a) {
var b = ed(a),
c = dd(b, "link"),
d = dd(ed(c), "link");b = dd(b, "deep_link_id");return dd(ed(b), "link") || b || d || c || a;
};function Jf(a, b) {
return a.then(function (a) {
if (a[L]) {
var c = sf(a[L]);if (!c || b != c.c) throw new K("user-mismatch");return a;
}throw new K("user-mismatch");
}).s(function (a) {
throw a && a.code && a.code == Ye + "user-not-found" ? new K("user-mismatch") : a;
});
}
function Kf(a, b, c) {
if (b.idToken || b.accessToken) b.idToken && I(this, "idToken", b.idToken), b.accessToken && I(this, "accessToken", b.accessToken);else if (b.oauthToken && b.oauthTokenSecret) I(this, "accessToken", b.oauthToken), I(this, "secret", b.oauthTokenSecret);else throw new K("internal-error", "failed to construct a credential");I(this, "providerId", a);I(this, "signInMethod", c);
}Kf.prototype.ya = function (a) {
return Lf(a, Mf(this));
};Kf.prototype.c = function (a, b) {
var c = Mf(this);c.idToken = b;return Nf(a, c);
};
Kf.prototype.f = function (a, b) {
var c = Mf(this);return Jf(Of(a, c), b);
};function Mf(a) {
var b = {};a.idToken && (b.id_token = a.idToken);a.accessToken && (b.access_token = a.accessToken);a.secret && (b.oauth_token_secret = a.secret);b.providerId = a.providerId;return { postBody: id(b).toString(), requestUri: "http://localhost" };
}
Kf.prototype.D = function () {
var a = { providerId: this.providerId, signInMethod: this.signInMethod };this.idToken && (a.oauthIdToken = this.idToken);this.accessToken && (a.oauthAccessToken = this.accessToken);this.secret && (a.oauthTokenSecret = this.secret);return a;
};function Pf(a, b) {
this.Ac = b || [];J(this, { providerId: a, isOAuthProvider: !0 });this.vb = {};this.$a = (xf(a) || {}).Ma || null;this.Ya = null;
}Pf.prototype.Da = function (a) {
this.vb = $a(a);return this;
};function M(a) {
Pf.call(this, a, vf);this.a = [];
}t(M, Pf);
M.prototype.ta = function (a) {
Fa(this.a, a) || this.a.push(a);return this;
};M.prototype.Ab = function () {
return Ja(this.a);
};M.prototype.credential = function (a, b) {
if (!a && !b) throw new K("argument-error", "credential failed: must provide the ID token and/or the access token.");return new Kf(this.providerId, { idToken: a || null, accessToken: b || null }, this.providerId);
};function Qf() {
M.call(this, "facebook.com");
}t(Qf, M);I(Qf, "PROVIDER_ID", "facebook.com");I(Qf, "FACEBOOK_SIGN_IN_METHOD", "facebook.com");
function Rf(a) {
if (!a) throw new K("argument-error", "credential failed: expected 1 argument (the OAuth access token).");var b = a;q(a) && (b = a.accessToken);return new Qf().credential(null, b);
}function Sf() {
M.call(this, "github.com");
}t(Sf, M);I(Sf, "PROVIDER_ID", "github.com");I(Sf, "GITHUB_SIGN_IN_METHOD", "github.com");function Tf(a) {
if (!a) throw new K("argument-error", "credential failed: expected 1 argument (the OAuth access token).");var b = a;q(a) && (b = a.accessToken);return new Sf().credential(null, b);
}
function Uf() {
M.call(this, "google.com");this.ta("profile");
}t(Uf, M);I(Uf, "PROVIDER_ID", "google.com");I(Uf, "GOOGLE_SIGN_IN_METHOD", "google.com");function Vf(a, b) {
var c = a;q(a) && (c = a.idToken, b = a.accessToken);return new Uf().credential(c, b);
}function Wf() {
Pf.call(this, "twitter.com", uf);
}t(Wf, Pf);I(Wf, "PROVIDER_ID", "twitter.com");I(Wf, "TWITTER_SIGN_IN_METHOD", "twitter.com");
function Xf(a, b) {
var c = a;q(c) || (c = { oauthToken: a, oauthTokenSecret: b });if (!c.oauthToken || !c.oauthTokenSecret) throw new K("argument-error", "credential failed: expected 2 arguments (the OAuth access token and secret).");return new Kf("twitter.com", c, "twitter.com");
}function Yf(a, b, c) {
this.a = a;this.b = b;I(this, "providerId", "password");I(this, "signInMethod", c === N.EMAIL_LINK_SIGN_IN_METHOD ? N.EMAIL_LINK_SIGN_IN_METHOD : N.EMAIL_PASSWORD_SIGN_IN_METHOD);
}
Yf.prototype.ya = function (a) {
return this.signInMethod == N.EMAIL_LINK_SIGN_IN_METHOD ? O(a, Zf, { email: this.a, oobCode: this.b }) : O(a, $f, { email: this.a, password: this.b });
};Yf.prototype.c = function (a, b) {
return this.signInMethod == N.EMAIL_LINK_SIGN_IN_METHOD ? O(a, ag, { idToken: b, email: this.a, oobCode: this.b }) : O(a, bg, { idToken: b, email: this.a, password: this.b });
};Yf.prototype.f = function (a, b) {
return Jf(this.ya(a), b);
};Yf.prototype.D = function () {
return { email: this.a, password: this.b, signInMethod: this.signInMethod };
};
function N() {
J(this, { providerId: "password", isOAuthProvider: !1 });
}function cg(a, b) {
b = dg(b);if (!b) throw new K("argument-error", "Invalid email link!");return new Yf(a, b, N.EMAIL_LINK_SIGN_IN_METHOD);
}function dg(a) {
a = If(a);a = new Hf(a);var b = dd(a.a, "oobCode") || null;return "signIn" === (dd(a.a, "mode") || null) && b ? b : null;
}J(N, { PROVIDER_ID: "password" });J(N, { EMAIL_LINK_SIGN_IN_METHOD: "emailLink" });J(N, { EMAIL_PASSWORD_SIGN_IN_METHOD: "password" });
function eg(a) {
if (!(a.Sa && a.Ra || a.Fa && a.$)) throw new K("internal-error");this.a = a;I(this, "providerId", "phone");I(this, "signInMethod", "phone");
}eg.prototype.ya = function (a) {
return a.Ta(fg(this));
};eg.prototype.c = function (a, b) {
var c = fg(this);c.idToken = b;return O(a, gg, c);
};eg.prototype.f = function (a, b) {
var c = fg(this);c.operation = "REAUTH";a = O(a, hg, c);return Jf(a, b);
};
eg.prototype.D = function () {
var a = { providerId: "phone" };this.a.Sa && (a.verificationId = this.a.Sa);this.a.Ra && (a.verificationCode = this.a.Ra);this.a.Fa && (a.temporaryProof = this.a.Fa);this.a.$ && (a.phoneNumber = this.a.$);return a;
};function fg(a) {
return a.a.Fa && a.a.$ ? { temporaryProof: a.a.Fa, phoneNumber: a.a.$ } : { sessionInfo: a.a.Sa, code: a.a.Ra };
}
function ig(a) {
try {
this.a = a || firebase.auth();
} catch (b) {
throw new K("argument-error", "Either an instance of firebase.auth.Auth must be passed as an argument to the firebase.auth.PhoneAuthProvider constructor, or the default firebase App instance must be initialized via firebase.initializeApp().");
}J(this, { providerId: "phone", isOAuthProvider: !1 });
}
ig.prototype.Ta = function (a, b) {
var c = this.a.b;return A(b.verify()).then(function (d) {
if (!l(d)) throw new K("argument-error", "An implementation of firebase.auth.ApplicationVerifier.prototype.verify() must return a firebase.Promise that resolves with a string.");switch (b.type) {case "recaptcha":
return jg(c, { phoneNumber: a, recaptchaToken: d }).then(function (a) {
"function" === typeof b.reset && b.reset();return a;
}, function (a) {
"function" === typeof b.reset && b.reset();throw a;
});default:
throw new K("argument-error", 'Only firebase.auth.ApplicationVerifiers with type="recaptcha" are currently supported.');}
});
};function kg(a, b) {
if (!a) throw new K("missing-verification-id");if (!b) throw new K("missing-verification-code");return new eg({ Sa: a, Ra: b });
}J(ig, { PROVIDER_ID: "phone" });J(ig, { PHONE_SIGN_IN_METHOD: "phone" });
function lg(a) {
if (a.temporaryProof && a.phoneNumber) return new eg({ Fa: a.temporaryProof, $: a.phoneNumber });var b = a && a.providerId;if (!b || "password" === b) return null;var c = a && a.oauthAccessToken,
d = a && a.oauthTokenSecret;a = a && a.oauthIdToken;try {
switch (b) {case "google.com":
return Vf(a, c);case "facebook.com":
return Rf(c);case "github.com":
return Tf(c);case "twitter.com":
return Xf(c, d);default:
return new M(b).credential(a, c);}
} catch (e) {
return null;
}
}
function mg(a) {
if (!a.isOAuthProvider) throw new K("invalid-oauth-provider");
};function ng(a, b, c, d, e) {
this.b = a;this.c = b || null;this.f = c || null;this.g = d || null;this.a = e || null;if (this.f || this.a) {
if (this.f && this.a) throw new K("invalid-auth-event");if (this.f && !this.g) throw new K("invalid-auth-event");
} else throw new K("invalid-auth-event");
}ng.prototype.D = function () {
return { type: this.b, eventId: this.c, urlResponse: this.f, sessionId: this.g, error: this.a && this.a.D() };
};function og(a) {
a = a || {};return a.type ? new ng(a.type, a.eventId, a.urlResponse, a.sessionId, a.error && $e(a.error)) : null;
};function pg() {
this.b = null;this.a = [];
}var qg = null;pg.prototype.subscribe = function (a) {
var b = this;this.a.push(a);this.b || (this.b = function (a) {
for (var c = 0; c < b.a.length; c++) b.a[c](a);
}, a = H("universalLinks.subscribe", k), "function" === typeof a && a(null, this.b));
};pg.prototype.unsubscribe = function (a) {
Ha(this.a, function (b) {
return b == a;
});
};function rg(a) {
var b = "unauthorized-domain",
c = void 0,
d = ed(a);a = d.b;d = d.c;"chrome-extension" == d ? c = Ka("This chrome extension ID (chrome-extension://%s) is not authorized to run this operation. Add it to the OAuth redirect domains list in the Firebase console -> Auth section -> Sign in method tab.", a) : "http" == d || "https" == d ? c = Ka("This domain (%s) is not authorized to run this operation. Add it to the OAuth redirect domains list in the Firebase console -> Auth section -> Sign in method tab.", a) : b = "operation-not-supported-in-this-environment";
K.call(this, b, c);
}t(rg, K);function sg(a, b, c) {
K.call(this, a, c);a = b || {};a.wb && I(this, "email", a.wb);a.$ && I(this, "phoneNumber", a.$);a.credential && I(this, "credential", a.credential);
}t(sg, K);sg.prototype.D = function () {
var a = { code: this.code, message: this.message };this.email && (a.email = this.email);this.phoneNumber && (a.phoneNumber = this.phoneNumber);var b = this.credential && this.credential.D();b && bb(a, b);return a;
};sg.prototype.toJSON = function () {
return this.D();
};
function tg(a) {
if (a.code) {
var b = a.code || "";0 == b.indexOf(Ye) && (b = b.substring(Ye.length));var c = { credential: lg(a) };if (a.email) c.wb = a.email;else if (a.phoneNumber) c.$ = a.phoneNumber;else return new K(b, a.message || void 0);return new sg(b, c, a.message);
}return null;
};var ug = /^[+a-zA-Z0-9_.!#$%&'*\/=?^`{|}~-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,63}$/;function vg() {}vg.prototype.c = null;function wg(a) {
return a.c || (a.c = a.b());
};var xg;function yg() {}t(yg, vg);yg.prototype.a = function () {
var a = zg(this);return a ? new ActiveXObject(a) : new XMLHttpRequest();
};yg.prototype.b = function () {
var a = {};zg(this) && (a[0] = !0, a[1] = !0);return a;
};
function zg(a) {
if (!a.f && "undefined" == typeof XMLHttpRequest && "undefined" != typeof ActiveXObject) {
for (var b = ["MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], c = 0; c < b.length; c++) {
var d = b[c];try {
return new ActiveXObject(d), a.f = d;
} catch (e) {}
}throw Error("Could not create ActiveXObject. ActiveX might be disabled, or MSXML might not be installed");
}return a.f;
}xg = new yg();function Ag() {}t(Ag, vg);Ag.prototype.a = function () {
var a = new XMLHttpRequest();if ("withCredentials" in a) return a;if ("undefined" != typeof XDomainRequest) return new Bg();throw Error("Unsupported browser");
};Ag.prototype.b = function () {
return {};
};
function Bg() {
this.a = new XDomainRequest();this.readyState = 0;this.onreadystatechange = null;this.responseText = "";this.status = -1;this.statusText = "";this.a.onload = r(this.bc, this);this.a.onerror = r(this.Bb, this);this.a.onprogress = r(this.cc, this);this.a.ontimeout = r(this.fc, this);
}g = Bg.prototype;g.open = function (a, b, c) {
if (null != c && !c) throw Error("Only async requests are supported.");this.a.open(a, b);
};
g.send = function (a) {
if (a) {
if ("string" == typeof a) this.a.send(a);else throw Error("Only string data is supported");
} else this.a.send();
};g.abort = function () {
this.a.abort();
};g.setRequestHeader = function () {};g.getResponseHeader = function (a) {
return "content-type" == a.toLowerCase() ? this.a.contentType : "";
};g.bc = function () {
this.status = 200;this.responseText = this.a.responseText;Cg(this, 4);
};g.Bb = function () {
this.status = 500;this.responseText = "";Cg(this, 4);
};g.fc = function () {
this.Bb();
};
g.cc = function () {
this.status = 200;Cg(this, 1);
};function Cg(a, b) {
a.readyState = b;if (a.onreadystatechange) a.onreadystatechange();
}g.getAllResponseHeaders = function () {
return "content-type: " + this.a.contentType;
};function Dg(a, b, c) {
this.reset(a, b, c, void 0, void 0);
}Dg.prototype.a = null;var Eg = 0;Dg.prototype.reset = function (a, b, c, d, e) {
"number" == typeof e || Eg++;d || na();delete this.a;
};function Fg(a) {
this.f = a;this.b = this.c = this.a = null;
}function Gg(a, b) {
this.name = a;this.value = b;
}Gg.prototype.toString = function () {
return this.name;
};var Hg = new Gg("SEVERE", 1E3),
Ig = new Gg("WARNING", 900),
Jg = new Gg("CONFIG", 700),
Kg = new Gg("FINE", 500);function Lg(a) {
if (a.c) return a.c;if (a.a) return Lg(a.a);ra("Root logger has no level set.");return null;
}Fg.prototype.log = function (a, b, c) {
if (a.value >= Lg(this).value) for (n(b) && (b = b()), a = new Dg(a, String(b), this.f), c && (a.a = c), c = this; c;) c = c.a;
};var Mg = {},
Ng = null;
function Og(a) {
Ng || (Ng = new Fg(""), Mg[""] = Ng, Ng.c = Jg);var b;if (!(b = Mg[a])) {
b = new Fg(a);var c = a.lastIndexOf("."),
d = a.substr(c + 1);c = Og(a.substr(0, c));c.b || (c.b = {});c.b[d] = b;b.a = c;Mg[a] = b;
}return b;
};function P(a, b) {
a && a.log(Kg, b, void 0);
};function Pg(a) {
this.f = a;
}t(Pg, vg);Pg.prototype.a = function () {
return new Qg(this.f);
};Pg.prototype.b = function (a) {
return function () {
return a;
};
}({});function Qg(a) {
E.call(this);this.i = a;this.readyState = Rg;this.status = 0;this.responseText = this.statusText = "";this.onreadystatechange = null;this.g = new Headers();this.b = null;this.h = "GET";this.c = "";this.a = !1;this.f = Og("goog.net.FetchXmlHttp");
}t(Qg, E);var Rg = 0;g = Qg.prototype;
g.open = function (a, b) {
if (this.readyState != Rg) throw this.abort(), Error("Error reopening a connection");this.h = a;this.c = b;this.readyState = 1;Sg(this);
};g.send = function (a) {
if (1 != this.readyState) throw this.abort(), Error("need to call open() first. ");this.a = !0;var b = { headers: this.g, method: this.h, credentials: void 0, cache: void 0 };a && (b.body = a);this.i.fetch(new Request(this.c, b)).then(this.ec.bind(this), this.Cb.bind(this));
};
g.abort = function () {
this.responseText = "";this.g = new Headers();this.status = 0;1 <= this.readyState && this.a && 4 != this.readyState && (this.readyState = 4, this.a = !1, Sg(this));this.readyState = Rg;
};g.ec = function (a) {
this.a && (this.b || (this.b = a.headers, this.readyState = 2, Sg(this)), this.a && (this.readyState = 3, Sg(this), this.a && a.text().then(this.dc.bind(this, a), this.Cb.bind(this))));
};g.dc = function (a, b) {
this.a && (this.status = a.status, this.statusText = a.statusText, this.responseText = b, this.readyState = 4, Sg(this));
};
g.Cb = function (a) {
var b = this.f;b && b.log(Ig, "Failed to fetch url " + this.c, a instanceof Error ? a : Error(a));this.a && (this.readyState = 4, Sg(this));
};g.setRequestHeader = function (a, b) {
this.g.append(a, b);
};g.getResponseHeader = function (a) {
return this.b ? this.b.get(a.toLowerCase()) || "" : ((a = this.f) && a.log(Ig, "Attempting to get response header but no headers have been received for url: " + this.c, void 0), "");
};
g.getAllResponseHeaders = function () {
if (!this.b) {
var a = this.f;a && a.log(Ig, "Attempting to get all response headers but no headers have been received for url: " + this.c, void 0);return "";
}a = [];for (var b = this.b.entries(), c = b.next(); !c.done;) c = c.value, a.push(c[0] + ": " + c[1]), c = b.next();return a.join("\r\n");
};function Sg(a) {
a.onreadystatechange && a.onreadystatechange.call(a);
};function Tg(a) {
E.call(this);this.headers = new Lc();this.C = a || null;this.c = !1;this.w = this.a = null;this.h = this.N = this.l = "";this.f = this.I = this.i = this.G = !1;this.g = 0;this.u = null;this.o = Ug;this.v = this.O = !1;
}t(Tg, E);var Ug = "";Tg.prototype.b = Og("goog.net.XhrIo");var Vg = /^https?$/i,
Wg = ["POST", "PUT"];
function Xg(a, b, c, d, e) {
if (a.a) throw Error("[goog.net.XhrIo] Object is active with another request=" + a.l + "; newUri=" + b);c = c ? c.toUpperCase() : "GET";a.l = b;a.h = "";a.N = c;a.G = !1;a.c = !0;a.a = a.C ? a.C.a() : xg.a();a.w = a.C ? wg(a.C) : wg(xg);a.a.onreadystatechange = r(a.Fb, a);try {
P(a.b, Yg(a, "Opening Xhr")), a.I = !0, a.a.open(c, String(b), !0), a.I = !1;
} catch (h) {
P(a.b, Yg(a, "Error opening Xhr: " + h.message));Zg(a, h);return;
}b = d || "";var f = new Lc(a.headers);e && Kc(e, function (a, b) {
f.set(b, a);
});e = Da(f.U());d = k.FormData && b instanceof k.FormData;!Fa(Wg, c) || e || d || f.set("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");f.forEach(function (a, b) {
this.a.setRequestHeader(b, a);
}, a);a.o && (a.a.responseType = a.o);"withCredentials" in a.a && a.a.withCredentials !== a.O && (a.a.withCredentials = a.O);try {
$g(a), 0 < a.g && (a.v = ah(a.a), P(a.b, Yg(a, "Will abort after " + a.g + "ms if incomplete, xhr2 " + a.v)), a.v ? (a.a.timeout = a.g, a.a.ontimeout = r(a.Ga, a)) : a.u = Gc(a.Ga, a.g, a)), P(a.b, Yg(a, "Sending request")), a.i = !0, a.a.send(b), a.i = !1;
} catch (h) {
P(a.b, Yg(a, "Send error: " + h.message)), Zg(a, h);
}
}function ah(a) {
return Ob && Yb(9) && "number" == typeof a.timeout && void 0 !== a.ontimeout;
}function Ea(a) {
return "content-type" == a.toLowerCase();
}g = Tg.prototype;g.Ga = function () {
"undefined" != typeof aa && this.a && (this.h = "Timed out after " + this.g + "ms, aborting", P(this.b, Yg(this, this.h)), this.dispatchEvent("timeout"), this.abort(8));
};function Zg(a, b) {
a.c = !1;a.a && (a.f = !0, a.a.abort(), a.f = !1);a.h = b;bh(a);ch(a);
}
function bh(a) {
a.G || (a.G = !0, a.dispatchEvent("complete"), a.dispatchEvent("error"));
}g.abort = function () {
this.a && this.c && (P(this.b, Yg(this, "Aborting")), this.c = !1, this.f = !0, this.a.abort(), this.f = !1, this.dispatchEvent("complete"), this.dispatchEvent("abort"), ch(this));
};g.ua = function () {
this.a && (this.c && (this.c = !1, this.f = !0, this.a.abort(), this.f = !1), ch(this, !0));Tg.lb.ua.call(this);
};g.Fb = function () {
this.pa || (this.I || this.i || this.f ? dh(this) : this.tc());
};g.tc = function () {
dh(this);
};
function dh(a) {
if (a.c && "undefined" != typeof aa) if (a.w[1] && 4 == eh(a) && 2 == fh(a)) P(a.b, Yg(a, "Local request error detected and ignored"));else if (a.i && 4 == eh(a)) Gc(a.Fb, 0, a);else if (a.dispatchEvent("readystatechange"), 4 == eh(a)) {
P(a.b, Yg(a, "Request complete"));a.c = !1;try {
var b = fh(a);a: switch (b) {case 200:case 201:case 202:case 204:case 206:case 304:case 1223:
var c = !0;break a;default:
c = !1;}var d;if (!(d = c)) {
var e;if (e = 0 === b) {
var f = String(a.l).match(Oc)[1] || null;if (!f && k.self && k.self.location) {
var h = k.self.location.protocol;
f = h.substr(0, h.length - 1);
}e = !Vg.test(f ? f.toLowerCase() : "");
}d = e;
}if (d) a.dispatchEvent("complete"), a.dispatchEvent("success");else {
try {
var m = 2 < eh(a) ? a.a.statusText : "";
} catch (p) {
P(a.b, "Can not get status: " + p.message), m = "";
}a.h = m + " [" + fh(a) + "]";bh(a);
}
} finally {
ch(a);
}
}
}function ch(a, b) {
if (a.a) {
$g(a);var c = a.a,
d = a.w[0] ? ca : null;a.a = null;a.w = null;b || a.dispatchEvent("ready");try {
c.onreadystatechange = d;
} catch (e) {
(a = a.b) && a.log(Hg, "Problem encountered resetting onreadystatechange: " + e.message, void 0);
}
}
}
function $g(a) {
a.a && a.v && (a.a.ontimeout = null);a.u && (k.clearTimeout(a.u), a.u = null);
}function eh(a) {
return a.a ? a.a.readyState : 0;
}function fh(a) {
try {
return 2 < eh(a) ? a.a.status : -1;
} catch (b) {
return -1;
}
}function gh(a) {
try {
return a.a ? a.a.responseText : "";
} catch (b) {
return P(a.b, "Can not get responseText: " + b.message), "";
}
}
g.getResponse = function () {
try {
if (!this.a) return null;if ("response" in this.a) return this.a.response;switch (this.o) {case Ug:case "text":
return this.a.responseText;case "arraybuffer":
if ("mozResponseArrayBuffer" in this.a) return this.a.mozResponseArrayBuffer;}var a = this.b;a && a.log(Hg, "Response type " + this.o + " is not supported on this browser", void 0);return null;
} catch (b) {
return P(this.b, "Can not get response: " + b.message), null;
}
};function Yg(a, b) {
return b + " [" + a.N + " " + a.l + " " + fh(a) + "]";
}; /*
Portions of this code are from MochiKit, received by
The Closure Authors under the MIT license. All other code is Copyright
2005-2009 The Closure Authors. All Rights Reserved.
*/
function hh(a, b) {
this.g = [];this.v = a;this.u = b || null;this.f = this.a = !1;this.c = void 0;this.l = this.w = this.i = !1;this.h = 0;this.b = null;this.m = 0;
}hh.prototype.cancel = function (a) {
if (this.a) this.c instanceof hh && this.c.cancel();else {
if (this.b) {
var b = this.b;delete this.b;a ? b.cancel(a) : (b.m--, 0 >= b.m && b.cancel());
}this.v ? this.v.call(this.u, this) : this.l = !0;this.a || (a = new ih(this), jh(this), kh(this, !1, a));
}
};hh.prototype.o = function (a, b) {
this.i = !1;kh(this, a, b);
};function kh(a, b, c) {
a.a = !0;a.c = c;a.f = !b;lh(a);
}
function jh(a) {
if (a.a) {
if (!a.l) throw new mh(a);a.l = !1;
}
}hh.prototype.C = function () {
jh(this);kh(this, !0, null);
};function nh(a, b) {
oh(a, null, b, void 0);
}function oh(a, b, c, d) {
a.g.push([b, c, d]);a.a && lh(a);
}hh.prototype.then = function (a, b, c) {
var d,
e,
f = new y(function (a, b) {
d = a;e = b;
});oh(this, d, function (a) {
a instanceof ih ? f.cancel() : e(a);
});return f.then(a, b, c);
};oa(hh);function ph(a) {
return Ca(a.g, function (a) {
return n(a[1]);
});
}
function lh(a) {
if (a.h && a.a && ph(a)) {
var b = a.h,
c = qh[b];c && (k.clearTimeout(c.a), delete qh[b]);a.h = 0;
}a.b && (a.b.m--, delete a.b);b = a.c;for (var d = c = !1; a.g.length && !a.i;) {
var e = a.g.shift(),
f = e[0],
h = e[1];e = e[2];if (f = a.f ? h : f) try {
var m = f.call(e || a.u, b);void 0 !== m && (a.f = a.f && (m == b || m instanceof Error), a.c = b = m);if (pa(b) || "function" === typeof k.Promise && b instanceof k.Promise) d = !0, a.i = !0;
} catch (p) {
b = p, a.f = !0, ph(a) || (c = !0);
}
}a.c = b;d && (m = r(a.o, a, !0), d = r(a.o, a, !1), b instanceof hh ? (oh(b, m, d), b.w = !0) : b.then(m, d));c && (b = new rh(b), qh[b.a] = b, a.h = b.a);
}function mh() {
u.call(this);
}t(mh, u);mh.prototype.message = "Deferred has already fired";mh.prototype.name = "AlreadyCalledError";function ih() {
u.call(this);
}t(ih, u);ih.prototype.message = "Deferred was canceled";ih.prototype.name = "CanceledError";function rh(a) {
this.a = k.setTimeout(r(this.c, this), 0);this.b = a;
}rh.prototype.c = function () {
delete qh[this.a];throw this.b;
};var qh = {};function sh(a) {
var b = {},
c = b.document || document,
d = ud(a),
e = document.createElement("SCRIPT"),
f = { Hb: e, Ga: void 0 },
h = new hh(th, f),
m = null,
p = null != b.timeout ? b.timeout : 5E3;0 < p && (m = window.setTimeout(function () {
uh(e, !0);var a = new vh(wh, "Timeout reached for loading script " + d);jh(h);kh(h, !1, a);
}, p), f.Ga = m);e.onload = e.onreadystatechange = function () {
e.readyState && "loaded" != e.readyState && "complete" != e.readyState || (uh(e, b.dd || !1, m), h.C());
};e.onerror = function () {
uh(e, !0, m);var a = new vh(xh, "Error while loading script " + d);jh(h);kh(h, !1, a);
};f = b.attributes || {};bb(f, { type: "text/javascript", charset: "UTF-8" });Kd(e, f);e.src = ud(a);yh(c).appendChild(e);return h;
}function yh(a) {
var b;return (b = (a || document).getElementsByTagName("HEAD")) && 0 != b.length ? b[0] : a.documentElement;
}function th() {
if (this && this.Hb) {
var a = this.Hb;a && "SCRIPT" == a.tagName && uh(a, !0, this.Ga);
}
}
function uh(a, b, c) {
null != c && k.clearTimeout(c);a.onload = ca;a.onerror = ca;a.onreadystatechange = ca;b && window.setTimeout(function () {
a && a.parentNode && a.parentNode.removeChild(a);
}, 0);
}var xh = 0,
wh = 1;function vh(a, b) {
var c = "Jsloader error (code #" + a + ")";b && (c += ": " + b);u.call(this, c);this.code = a;
}t(vh, u);function zh(a) {
this.f = a;
}t(zh, vg);zh.prototype.a = function () {
return new this.f();
};zh.prototype.b = function () {
return {};
};
function Ah(a, b, c) {
this.b = a;a = b || {};this.i = a.secureTokenEndpoint || "https://securetoken.googleapis.com/v1/token";this.m = a.secureTokenTimeout || Bh;this.f = $a(a.secureTokenHeaders || Ch);this.g = a.firebaseEndpoint || "https://www.googleapis.com/identitytoolkit/v3/relyingparty/";this.h = a.firebaseTimeout || Dh;this.a = $a(a.firebaseHeaders || Eh);c && (this.a["X-Client-Version"] = c, this.f["X-Client-Version"] = c);c = "Node" == ne();c = k.XMLHttpRequest || c && firebase.INTERNAL.node && firebase.INTERNAL.node.XMLHttpRequest;if (!c && !me()) throw new K("internal-error", "The XMLHttpRequest compatibility library was not found.");this.c = void 0;me() ? this.c = new Pg(self) : oe() ? this.c = new zh(c) : this.c = new Ag();
}var Fh,
L = "idToken",
Bh = new Ce(3E4, 6E4),
Ch = { "Content-Type": "application/x-www-form-urlencoded" },
Dh = new Ce(3E4, 6E4),
Eh = { "Content-Type": "application/json" };function Gh(a, b) {
b ? a.a["X-Firebase-Locale"] = b : delete a.a["X-Firebase-Locale"];
}
function Hh(a, b) {
b ? (a.a["X-Client-Version"] = b, a.f["X-Client-Version"] = b) : (delete a.a["X-Client-Version"], delete a.f["X-Client-Version"]);
}function Ih(a, b, c, d, e, f, h) {
Zd() || me() ? a = r(a.o, a) : (Fh || (Fh = new y(function (a, b) {
Jh(a, b);
})), a = r(a.l, a));a(b, c, d, e, f, h);
}
Ah.prototype.o = function (a, b, c, d, e, f) {
if (me() && ("undefined" === typeof k.fetch || "undefined" === typeof k.Headers || "undefined" === typeof k.Request)) throw new K("operation-not-supported-in-this-environment", "fetch, Headers and Request native APIs or equivalent Polyfills must be available to support HTTP requests from a Worker environment.");var h = new Tg(this.c);if (f) {
h.g = Math.max(0, f);var m = setTimeout(function () {
h.dispatchEvent("timeout");
}, f);
}uc(h, "complete", function () {
m && clearTimeout(m);var a = null;try {
a = JSON.parse(gh(this)) || null;
} catch (z) {
a = null;
}b && b(a);
});Ac(h, "ready", function () {
m && clearTimeout(m);Jb(this);
});Ac(h, "timeout", function () {
m && clearTimeout(m);Jb(this);b && b(null);
});Xg(h, a, c, d, e);
};var Kh = rd("https://apis.google.com/js/client.js?onload=%{onload}"),
Lh = "__fcb" + Math.floor(1E6 * Math.random()).toString();
function Jh(a, b) {
if (((window.gapi || {}).client || {}).request) a();else {
k[Lh] = function () {
((window.gapi || {}).client || {}).request ? a() : b(Error("CORS_UNSUPPORTED"));
};var c = vd(Kh, { onload: Lh });nh(sh(c), function () {
b(Error("CORS_UNSUPPORTED"));
});
}
}
Ah.prototype.l = function (a, b, c, d, e) {
var f = this;Fh.then(function () {
window.gapi.client.setApiKey(f.b);var h = window.gapi.auth.getToken();window.gapi.auth.setToken(null);window.gapi.client.request({ path: a, method: c, body: d, headers: e, authType: "none", callback: function (a) {
window.gapi.auth.setToken(h);b && b(a);
} });
}).s(function (a) {
b && b({ error: { message: a && a.message || "CORS_UNSUPPORTED" } });
});
};
function Mh(a, b) {
return new y(function (c, d) {
"refresh_token" == b.grant_type && b.refresh_token || "authorization_code" == b.grant_type && b.code ? Ih(a, a.i + "?key=" + encodeURIComponent(a.b), function (a) {
a ? a.error ? d(Nh(a)) : a.access_token && a.refresh_token ? c(a) : d(new K("internal-error")) : d(new K("network-request-failed"));
}, "POST", id(b).toString(), a.f, a.m.get()) : d(new K("internal-error"));
});
}
function Oh(a, b, c, d, e, f) {
var h = ed(a.g + b);F(h, "key", a.b);f && F(h, "cb", na().toString());var m = "GET" == c;if (m) for (var p in d) d.hasOwnProperty(p) && F(h, p, d[p]);return new y(function (b, f) {
Ih(a, h.toString(), function (a) {
a ? a.error ? f(Nh(a, e || {})) : b(a) : f(new K("network-request-failed"));
}, c, m ? void 0 : Pd(ye(d)), a.a, a.h.get());
});
}function Ph(a) {
if (!ug.test(a.email)) throw new K("invalid-email");
}function Qh(a) {
"email" in a && Ph(a);
}
function Rh(a, b) {
return O(a, Sh, { identifier: b, continueUri: ve() ? Wd() : "http://localhost" }).then(function (a) {
return a.allProviders || [];
});
}function Th(a, b) {
return O(a, Sh, { identifier: b, continueUri: ve() ? Wd() : "http://localhost" }).then(function (a) {
return a.signinMethods || [];
});
}function Uh(a) {
return O(a, Vh, {}).then(function (a) {
return a.authorizedDomains || [];
});
}function Wh(a) {
if (!a[L]) throw new K("internal-error");
}
function Xh(a) {
if (a.phoneNumber || a.temporaryProof) {
if (!a.phoneNumber || !a.temporaryProof) throw new K("internal-error");
} else {
if (!a.sessionInfo) throw new K("missing-verification-id");if (!a.code) throw new K("missing-verification-code");
}
}Ah.prototype.Pa = function () {
return O(this, Yh, {});
};Ah.prototype.mb = function (a, b) {
return O(this, Zh, { idToken: a, email: b });
};Ah.prototype.nb = function (a, b) {
return O(this, bg, { idToken: a, password: b });
};var $h = { displayName: "DISPLAY_NAME", photoUrl: "PHOTO_URL" };g = Ah.prototype;
g.ob = function (a, b) {
var c = { idToken: a },
d = [];Ya($h, function (a, f) {
var e = b[f];null === e ? d.push(a) : f in b && (c[f] = e);
});d.length && (c.deleteAttribute = d);return O(this, Zh, c);
};g.hb = function (a, b) {
a = { requestType: "PASSWORD_RESET", email: a };bb(a, b);return O(this, ai, a);
};g.ib = function (a, b) {
a = { requestType: "EMAIL_SIGNIN", email: a };bb(a, b);return O(this, bi, a);
};g.gb = function (a, b) {
a = { requestType: "VERIFY_EMAIL", idToken: a };bb(a, b);return O(this, ci, a);
};function jg(a, b) {
return O(a, di, b);
}g.Ta = function (a) {
return O(this, ei, a);
};
function fi(a, b, c) {
return O(a, gi, { idToken: b, deleteProvider: c });
}function hi(a) {
if (!a.requestUri || !a.sessionId && !a.postBody) throw new K("internal-error");
}
function ii(a) {
var b = null;a.needConfirmation ? (a.code = "account-exists-with-different-credential", b = tg(a)) : "FEDERATED_USER_ID_ALREADY_LINKED" == a.errorMessage ? (a.code = "credential-already-in-use", b = tg(a)) : "EMAIL_EXISTS" == a.errorMessage ? (a.code = "email-already-in-use", b = tg(a)) : a.errorMessage && (b = ji(a.errorMessage));if (b) throw b;if (!a[L]) throw new K("internal-error");
}function Lf(a, b) {
b.returnIdpCredential = !0;return O(a, ki, b);
}function Nf(a, b) {
b.returnIdpCredential = !0;return O(a, li, b);
}
function Of(a, b) {
b.returnIdpCredential = !0;b.autoCreate = !1;return O(a, mi, b);
}function ni(a) {
if (!a.oobCode) throw new K("invalid-action-code");
}g.Xa = function (a, b) {
return O(this, oi, { oobCode: a, newPassword: b });
};g.Ja = function (a) {
return O(this, pi, { oobCode: a });
};g.Va = function (a) {
return O(this, qi, { oobCode: a });
};
var qi = { endpoint: "setAccountInfo", B: ni, da: "email" },
pi = { endpoint: "resetPassword", B: ni, J: function (a) {
var b = a.requestType;if (!b || !a.email && "EMAIL_SIGNIN" != b) throw new K("internal-error");
} },
ri = { endpoint: "signupNewUser", B: function (a) {
Ph(a);if (!a.password) throw new K("weak-password");
}, J: Wh, R: !0 },
Sh = { endpoint: "createAuthUri" },
si = { endpoint: "deleteAccount", T: ["idToken"] },
gi = { endpoint: "setAccountInfo", T: ["idToken", "deleteProvider"], B: function (a) {
if (!fa(a.deleteProvider)) throw new K("internal-error");
} },
Zf = { endpoint: "emailLinkSignin", T: ["email", "oobCode"], B: Ph, J: Wh, R: !0 },
ag = { endpoint: "emailLinkSignin", T: ["idToken", "email", "oobCode"], B: Ph, J: Wh, R: !0 },
ti = { endpoint: "getAccountInfo" },
bi = { endpoint: "getOobConfirmationCode", T: ["requestType"], B: function (a) {
if ("EMAIL_SIGNIN" != a.requestType) throw new K("internal-error");Ph(a);
}, da: "email" },
ci = { endpoint: "getOobConfirmationCode", T: ["idToken", "requestType"], B: function (a) {
if ("VERIFY_EMAIL" != a.requestType) throw new K("internal-error");
}, da: "email" },
ai = { endpoint: "getOobConfirmationCode",
T: ["requestType"], B: function (a) {
if ("PASSWORD_RESET" != a.requestType) throw new K("internal-error");Ph(a);
}, da: "email" },
Vh = { rb: !0, endpoint: "getProjectConfig", Eb: "GET" },
ui = { rb: !0, endpoint: "getRecaptchaParam", Eb: "GET", J: function (a) {
if (!a.recaptchaSiteKey) throw new K("internal-error");
} },
oi = { endpoint: "resetPassword", B: ni, da: "email" },
di = { endpoint: "sendVerificationCode", T: ["phoneNumber", "recaptchaToken"], da: "sessionInfo" },
Zh = { endpoint: "setAccountInfo", T: ["idToken"], B: Qh, R: !0 },
bg = { endpoint: "setAccountInfo",
T: ["idToken"], B: function (a) {
Qh(a);if (!a.password) throw new K("weak-password");
}, J: Wh, R: !0 },
Yh = { endpoint: "signupNewUser", J: Wh, R: !0 },
ki = { endpoint: "verifyAssertion", B: hi, J: ii, R: !0 },
mi = { endpoint: "verifyAssertion", B: hi, J: function (a) {
if (a.errorMessage && "USER_NOT_FOUND" == a.errorMessage) throw new K("user-not-found");if (a.errorMessage) throw ji(a.errorMessage);if (!a[L]) throw new K("internal-error");
}, R: !0 },
li = { endpoint: "verifyAssertion", B: function (a) {
hi(a);if (!a.idToken) throw new K("internal-error");
}, J: ii,
R: !0 },
vi = { endpoint: "verifyCustomToken", B: function (a) {
if (!a.token) throw new K("invalid-custom-token");
}, J: Wh, R: !0 },
$f = { endpoint: "verifyPassword", B: function (a) {
Ph(a);if (!a.password) throw new K("wrong-password");
}, J: Wh, R: !0 },
ei = { endpoint: "verifyPhoneNumber", B: Xh, J: Wh },
gg = { endpoint: "verifyPhoneNumber", B: function (a) {
if (!a.idToken) throw new K("internal-error");Xh(a);
}, J: function (a) {
if (a.temporaryProof) throw a.code = "credential-already-in-use", tg(a);Wh(a);
} },
hg = { Tb: { USER_NOT_FOUND: "user-not-found" }, endpoint: "verifyPhoneNumber",
B: Xh, J: Wh };function O(a, b, c) {
if (!Ne(c, b.T)) return B(new K("internal-error"));var d = b.Eb || "POST",
e;return A(c).then(b.B).then(function () {
b.R && (c.returnSecureToken = !0);return Oh(a, b.endpoint, d, c, b.Tb, b.rb || !1);
}).then(function (a) {
return e = a;
}).then(b.J).then(function () {
if (!b.da) return e;if (!(b.da in e)) throw new K("internal-error");return e[b.da];
});
}function ji(a) {
return Nh({ error: { errors: [{ message: a }], code: 400, message: a } });
}
function Nh(a, b) {
var c = (a.error && a.error.errors && a.error.errors[0] || {}).reason || "";var d = { keyInvalid: "invalid-api-key", ipRefererBlocked: "app-not-authorized" };if (c = d[c] ? new K(d[c]) : null) return c;c = a.error && a.error.message || "";d = { INVALID_CUSTOM_TOKEN: "invalid-custom-token", CREDENTIAL_MISMATCH: "custom-token-mismatch", MISSING_CUSTOM_TOKEN: "internal-error", INVALID_IDENTIFIER: "invalid-email", MISSING_CONTINUE_URI: "internal-error", INVALID_EMAIL: "invalid-email", INVALID_PASSWORD: "wrong-password", USER_DISABLED: "user-disabled",
MISSING_PASSWORD: "internal-error", EMAIL_EXISTS: "email-already-in-use", PASSWORD_LOGIN_DISABLED: "operation-not-allowed", INVALID_IDP_RESPONSE: "invalid-credential", FEDERATED_USER_ID_ALREADY_LINKED: "credential-already-in-use", INVALID_MESSAGE_PAYLOAD: "invalid-message-payload", INVALID_RECIPIENT_EMAIL: "invalid-recipient-email", INVALID_SENDER: "invalid-sender", EMAIL_NOT_FOUND: "user-not-found", EXPIRED_OOB_CODE: "expired-action-code", INVALID_OOB_CODE: "invalid-action-code", MISSING_OOB_CODE: "internal-error", CREDENTIAL_TOO_OLD_LOGIN_AGAIN: "requires-recent-login",
INVALID_ID_TOKEN: "invalid-user-token", TOKEN_EXPIRED: "user-token-expired", USER_NOT_FOUND: "user-token-expired", CORS_UNSUPPORTED: "cors-unsupported", DYNAMIC_LINK_NOT_ACTIVATED: "dynamic-link-not-activated", INVALID_APP_ID: "invalid-app-id", TOO_MANY_ATTEMPTS_TRY_LATER: "too-many-requests", WEAK_PASSWORD: "weak-password", OPERATION_NOT_ALLOWED: "operation-not-allowed", USER_CANCELLED: "user-cancelled", CAPTCHA_CHECK_FAILED: "captcha-check-failed", INVALID_APP_CREDENTIAL: "invalid-app-credential", INVALID_CODE: "invalid-verification-code",
INVALID_PHONE_NUMBER: "invalid-phone-number", INVALID_SESSION_INFO: "invalid-verification-id", INVALID_TEMPORARY_PROOF: "invalid-credential", MISSING_APP_CREDENTIAL: "missing-app-credential", MISSING_CODE: "missing-verification-code", MISSING_PHONE_NUMBER: "missing-phone-number", MISSING_SESSION_INFO: "missing-verification-id", QUOTA_EXCEEDED: "quota-exceeded", SESSION_EXPIRED: "code-expired", INVALID_CONTINUE_URI: "invalid-continue-uri", MISSING_ANDROID_PACKAGE_NAME: "missing-android-pkg-name", MISSING_IOS_BUNDLE_ID: "missing-ios-bundle-id",
UNAUTHORIZED_DOMAIN: "unauthorized-continue-uri", INVALID_OAUTH_CLIENT_ID: "invalid-oauth-client-id", INVALID_CERT_HASH: "invalid-cert-hash" };bb(d, b || {});b = (b = c.match(/^[^\s]+\s*:\s*(.*)$/)) && 1 < b.length ? b[1] : void 0;for (var e in d) if (0 === c.indexOf(e)) return new K(d[e], b);!b && a && (b = xe(a));return new K("internal-error", b);
};var wi = { Yc: { Za: "https://www.googleapis.com/identitytoolkit/v3/relyingparty/", fb: "https://securetoken.googleapis.com/v1/token", id: "p" }, $c: { Za: "https://staging-www.sandbox.googleapis.com/identitytoolkit/v3/relyingparty/", fb: "https://staging-securetoken.sandbox.googleapis.com/v1/token", id: "s" }, ad: { Za: "https://www-googleapis-test.sandbox.google.com/identitytoolkit/v3/relyingparty/", fb: "https://test-securetoken.sandbox.googleapis.com/v1/token", id: "t" } };
function xi(a) {
for (var b in wi) if (wi[b].id === a) return a = wi[b], { firebaseEndpoint: a.Za, secureTokenEndpoint: a.fb };return null;
}var yi;yi = xi("__EID__") ? "__EID__" : void 0;function zi(a) {
this.b = a;this.a = null;this.bb = Ai(this);
}
function Ai(a) {
return Bi().then(function () {
return new y(function (b, c) {
H("gapi.iframes.getContext")().open({ where: document.body, url: a.b, messageHandlersFilter: H("gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER"), attributes: { style: { position: "absolute", top: "-100px", width: "1px", height: "1px" } }, dontclear: !0 }, function (d) {
function e() {
clearTimeout(f);b();
}a.a = d;a.a.restyle({ setHideOnLeave: !1 });var f = setTimeout(function () {
c(Error("Network Error"));
}, Ci.get());d.ping(e).then(e, function () {
c(Error("Network Error"));
});
});
});
});
}
function Di(a, b) {
return a.bb.then(function () {
return new y(function (c) {
a.a.send(b.type, b, c, H("gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER"));
});
});
}function Ei(a, b) {
a.bb.then(function () {
a.a.register("authEvent", b, H("gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER"));
});
}var Fi = rd("https://apis.google.com/js/api.js?onload=%{onload}"),
Gi = new Ce(3E4, 6E4),
Ci = new Ce(5E3, 15E3),
Hi = null;
function Bi() {
return Hi ? Hi : Hi = new y(function (a, b) {
function c() {
Be();H("gapi.load")("gapi.iframes", { callback: a, ontimeout: function () {
Be();b(Error("Network Error"));
}, timeout: Gi.get() });
}if (H("gapi.iframes.Iframe")) a();else if (H("gapi.load")) c();else {
var d = "__iframefcb" + Math.floor(1E6 * Math.random()).toString();k[d] = function () {
H("gapi.load") ? c() : b(Error("Network Error"));
};d = vd(Fi, { onload: d });A(sh(d)).s(function () {
b(Error("Network Error"));
});
}
}).s(function (a) {
Hi = null;throw a;
});
};function Ii(a, b, c) {
this.i = a;this.g = b;this.h = c;this.f = null;this.a = fd(this.i, "/__/auth/iframe");F(this.a, "apiKey", this.g);F(this.a, "appName", this.h);this.b = null;this.c = [];
}Ii.prototype.toString = function () {
this.f ? F(this.a, "v", this.f) : ld(this.a.a, "v");this.b ? F(this.a, "eid", this.b) : ld(this.a.a, "eid");this.c.length ? F(this.a, "fw", this.c.join(",")) : ld(this.a.a, "fw");return this.a.toString();
};function Ji(a, b, c, d, e) {
this.o = a;this.l = b;this.c = c;this.m = d;this.h = this.g = this.i = null;this.a = e;this.f = null;
}
Ji.prototype.toString = function () {
var a = fd(this.o, "/__/auth/handler");F(a, "apiKey", this.l);F(a, "appName", this.c);F(a, "authType", this.m);if (this.a.isOAuthProvider) {
var b = this.a;try {
var c = firebase.app(this.c).auth().ea();
} catch (m) {
c = null;
}b.Ya = c;F(a, "providerId", this.a.providerId);b = this.a;c = ye(b.vb);for (var d in c) c[d] = c[d].toString();d = b.Ac;c = $a(c);for (var e = 0; e < d.length; e++) {
var f = d[e];f in c && delete c[f];
}b.$a && b.Ya && !c[b.$a] && (c[b.$a] = b.Ya);Za(c) || F(a, "customParameters", xe(c));
}"function" === typeof this.a.Ab && (b = this.a.Ab(), b.length && F(a, "scopes", b.join(",")));this.i ? F(a, "redirectUrl", this.i) : ld(a.a, "redirectUrl");this.g ? F(a, "eventId", this.g) : ld(a.a, "eventId");this.h ? F(a, "v", this.h) : ld(a.a, "v");if (this.b) for (var h in this.b) this.b.hasOwnProperty(h) && !dd(a, h) && F(a, h, this.b[h]);this.f ? F(a, "eid", this.f) : ld(a.a, "eid");h = Ki(this.c);h.length && F(a, "fw", h.join(","));return a.toString();
};function Ki(a) {
try {
return firebase.app(a).auth().xa();
} catch (b) {
return [];
}
}
function Li(a, b, c, d, e) {
this.l = a;this.f = b;this.b = c;this.c = d || null;this.h = e || null;this.o = this.u = this.v = null;this.g = [];this.m = this.a = null;
}
function Mi(a) {
var b = Wd();return Uh(a).then(function (a) {
a: {
var c = ed(b),
e = c.c;c = c.b;for (var f = 0; f < a.length; f++) {
var h = a[f];var m = c;var p = e;0 == h.indexOf("chrome-extension://") ? m = ed(h).b == m && "chrome-extension" == p : "http" != p && "https" != p ? m = !1 : ge.test(h) ? m = m == h : (h = h.split(".").join("\\."), m = new RegExp("^(.+\\." + h + "|" + h + ")$", "i").test(m));if (m) {
a = !0;break a;
}
}a = !1;
}if (!a) throw new rg(Wd());
});
}
function Ni(a) {
if (a.m) return a.m;a.m = he().then(function () {
if (!a.u) {
var b = a.c,
c = a.h,
d = Ki(a.b),
e = new Ii(a.l, a.f, a.b);e.f = b;e.b = c;e.c = Ja(d || []);a.u = e.toString();
}a.i = new zi(a.u);Oi(a);
});return a.m;
}g = Li.prototype;g.Ea = function (a, b, c) {
var d = new K("popup-closed-by-user"),
e = new K("web-storage-unsupported"),
f = this,
h = !1;return this.ga().then(function () {
Pi(f).then(function (c) {
c || (a && ce(a), b(e), h = !0);
});
}).s(function () {}).then(function () {
if (!h) return fe(a);
}).then(function () {
if (!h) return Hc(c).then(function () {
b(d);
});
});
};
g.Ib = function () {
var a = G();return !we(a) && !Ae(a);
};g.Db = function () {
return !1;
};
g.zb = function (a, b, c, d, e, f, h) {
if (!a) return B(new K("popup-blocked"));if (h && !we()) return this.ga().s(function (b) {
ce(a);e(b);
}), d(), A();this.a || (this.a = Mi(Qi(this)));var m = this;return this.a.then(function () {
var b = m.ga().s(function (b) {
ce(a);e(b);throw b;
});d();return b;
}).then(function () {
mg(c);if (!h) {
var d = Ri(m.l, m.f, m.b, b, c, null, f, m.c, void 0, m.h);Xd(d, a);
}
}).s(function (a) {
"auth/network-request-failed" == a.code && (m.a = null);throw a;
});
};
function Qi(a) {
a.o || (a.v = a.c ? re(a.c, Ki(a.b)) : null, a.o = new Ah(a.f, xi(a.h), a.v));return a.o;
}g.Ca = function (a, b, c) {
this.a || (this.a = Mi(Qi(this)));var d = this;return this.a.then(function () {
mg(b);var e = Ri(d.l, d.f, d.b, a, b, Wd(), c, d.c, void 0, d.h);Xd(e);
}).s(function (a) {
"auth/network-request-failed" == a.code && (d.a = null);throw a;
});
};g.ga = function () {
var a = this;return Ni(this).then(function () {
return a.i.bb;
}).s(function () {
a.a = null;throw new K("network-request-failed");
});
};g.Mb = function () {
return !0;
};
function Ri(a, b, c, d, e, f, h, m, p, z) {
a = new Ji(a, b, c, d, e);a.i = f;a.g = h;a.h = m;a.b = $a(p || null);a.f = z;return a.toString();
}function Oi(a) {
if (!a.i) throw Error("IfcHandler must be initialized!");Ei(a.i, function (b) {
var c = {};if (b && b.authEvent) {
var d = !1;b = og(b.authEvent);for (c = 0; c < a.g.length; c++) d = a.g[c](b) || d;c = {};c.status = d ? "ACK" : "ERROR";return A(c);
}c.status = "ERROR";return A(c);
});
}
function Pi(a) {
var b = { type: "webStorageSupport" };return Ni(a).then(function () {
return Di(a.i, b);
}).then(function (a) {
if (a && a.length && "undefined" !== typeof a[0].webStorageSupport) return a[0].webStorageSupport;throw Error();
});
}g.va = function (a) {
this.g.push(a);
};g.Ka = function (a) {
Ha(this.g, function (b) {
return b == a;
});
};function Si(a) {
this.a = a || firebase.INTERNAL.reactNative && firebase.INTERNAL.reactNative.AsyncStorage;if (!this.a) throw new K("internal-error", "The React Native compatibility library was not found.");this.type = "asyncStorage";
}g = Si.prototype;g.get = function (a) {
return A(this.a.getItem(a)).then(function (a) {
return a && ze(a);
});
};g.set = function (a, b) {
return A(this.a.setItem(a, xe(b)));
};g.P = function (a) {
return A(this.a.removeItem(a));
};g.Y = function () {};g.ca = function () {};function Ti() {
if (!Ui()) throw new K("web-storage-unsupported");this.f = {};this.a = [];this.b = 0;this.g = k.indexedDB;this.type = "indexedDB";
}var Vi;function Wi(a) {
return new y(function (b, c) {
var d = a.g.deleteDatabase("firebaseLocalStorageDb");d.onsuccess = function () {
b();
};d.onerror = function (a) {
c(Error(a.target.error));
};
});
}
function Xi(a) {
return new y(function (b, c) {
var d = a.g.open("firebaseLocalStorageDb", 1);d.onerror = function (a) {
try {
a.preventDefault();
} catch (f) {}c(Error(a.target.error));
};d.onupgradeneeded = function (a) {
a = a.target.result;try {
a.createObjectStore("firebaseLocalStorage", { keyPath: "fbase_key" });
} catch (f) {
c(f);
}
};d.onsuccess = function (d) {
d = d.target.result;d.objectStoreNames.contains("firebaseLocalStorage") ? b(d) : Wi(a).then(function () {
return Xi(a);
}).then(function (a) {
b(a);
}).s(function (a) {
c(a);
});
};
});
}
function Yi(a) {
a.h || (a.h = Xi(a));return a.h;
}function Ui() {
try {
return !!k.indexedDB;
} catch (a) {
return !1;
}
}function Zi(a) {
return a.objectStore("firebaseLocalStorage");
}function $i(a, b) {
return a.transaction(["firebaseLocalStorage"], b ? "readwrite" : "readonly");
}function aj(a) {
return new y(function (b, c) {
a.onsuccess = function (a) {
a && a.target ? b(a.target.result) : b();
};a.onerror = function (a) {
c(Error(a.target.errorCode));
};
});
}g = Ti.prototype;
g.set = function (a, b) {
var c = !1,
d,
e = this;return Yi(this).then(function (b) {
d = b;b = Zi($i(d, !0));return aj(b.get(a));
}).then(function (f) {
var h = Zi($i(d, !0));if (f) return f.value = b, aj(h.put(f));e.b++;c = !0;f = {};f.fbase_key = a;f.value = b;return aj(h.add(f));
}).then(function () {
e.f[a] = b;
}).ia(function () {
c && e.b--;
});
};g.get = function (a) {
return Yi(this).then(function (b) {
return aj(Zi($i(b, !1)).get(a));
}).then(function (a) {
return a && a.value;
});
};
g.P = function (a) {
var b = !1,
c = this;return Yi(this).then(function (d) {
b = !0;c.b++;return aj(Zi($i(d, !0))["delete"](a));
}).then(function () {
delete c.f[a];
}).ia(function () {
b && c.b--;
});
};
g.Kc = function () {
var a = this;return Yi(this).then(function (a) {
var b = Zi($i(a, !1));return b.getAll ? aj(b.getAll()) : new y(function (a, c) {
var d = [],
e = b.openCursor();e.onsuccess = function (b) {
(b = b.target.result) ? (d.push(b.value), b["continue"]()) : a(d);
};e.onerror = function (a) {
c(Error(a.target.errorCode));
};
});
}).then(function (b) {
var c = {},
d = [];if (0 == a.b) {
for (d = 0; d < b.length; d++) c[b[d].fbase_key] = b[d].value;d = Yd(a.f, c);a.f = c;
}return d;
});
};g.Y = function (a) {
0 == this.a.length && bj(this);this.a.push(a);
};
g.ca = function (a) {
Ha(this.a, function (b) {
return b == a;
});0 == this.a.length && this.c && this.c.cancel("STOP_EVENT");
};function bj(a) {
function b() {
a.c = Hc(800).then(r(a.Kc, a)).then(function (b) {
0 < b.length && v(a.a, function (a) {
a(b);
});
}).then(b).s(function (a) {
"STOP_EVENT" != a.message && b();
});return a.c;
}a.c && a.c.cancel("STOP_EVENT");b();
};function cj(a) {
var b = this,
c = null;this.a = [];this.type = "indexedDB";this.c = a;this.b = A().then(function () {
return Ui() ? (Vi || (Vi = new Ti()), c = Vi, c.set("__sak", "!").then(function () {
return c.get("__sak");
}).then(function (a) {
if ("!" !== a) throw Error("indexedDB not supported!");return c.P("__sak");
}).then(function () {
return c;
}).s(function () {
return b.c;
})) : b.c;
}).then(function (a) {
b.type = a.type;a.Y(function (a) {
v(b.a, function (b) {
b(a);
});
});return a;
});
}g = cj.prototype;g.get = function (a) {
return this.b.then(function (b) {
return b.get(a);
});
};
g.set = function (a, b) {
return this.b.then(function (c) {
return c.set(a, b);
});
};g.P = function (a) {
return this.b.then(function (b) {
return b.P(a);
});
};g.Y = function (a) {
this.a.push(a);
};g.ca = function (a) {
Ha(this.a, function (b) {
return b == a;
});
};function dj() {
this.a = {};this.type = "inMemory";
}g = dj.prototype;g.get = function (a) {
return A(this.a[a]);
};g.set = function (a, b) {
this.a[a] = b;return A();
};g.P = function (a) {
delete this.a[a];return A();
};g.Y = function () {};g.ca = function () {};function ej() {
if (!fj()) {
if ("Node" == ne()) throw new K("internal-error", "The LocalStorage compatibility library was not found.");throw new K("web-storage-unsupported");
}this.a = gj() || firebase.INTERNAL.node.localStorage;this.type = "localStorage";
}function gj() {
try {
var a = k.localStorage,
b = te();a && (a.setItem(b, "1"), a.removeItem(b));return a;
} catch (c) {
return null;
}
}
function fj() {
var a = "Node" == ne();a = gj() || a && firebase.INTERNAL.node && firebase.INTERNAL.node.localStorage;if (!a) return !1;try {
return a.setItem("__sak", "1"), a.removeItem("__sak"), !0;
} catch (b) {
return !1;
}
}g = ej.prototype;g.get = function (a) {
var b = this;return A().then(function () {
var c = b.a.getItem(a);return ze(c);
});
};g.set = function (a, b) {
var c = this;return A().then(function () {
var d = xe(b);null === d ? c.P(a) : c.a.setItem(a, d);
});
};g.P = function (a) {
var b = this;return A().then(function () {
b.a.removeItem(a);
});
};
g.Y = function (a) {
k.window && rc(k.window, "storage", a);
};g.ca = function (a) {
k.window && D(k.window, "storage", a);
};function hj() {
this.type = "nullStorage";
}g = hj.prototype;g.get = function () {
return A(null);
};g.set = function () {
return A();
};g.P = function () {
return A();
};g.Y = function () {};g.ca = function () {};function ij() {
if (!jj()) {
if ("Node" == ne()) throw new K("internal-error", "The SessionStorage compatibility library was not found.");throw new K("web-storage-unsupported");
}this.a = kj() || firebase.INTERNAL.node.sessionStorage;this.type = "sessionStorage";
}function kj() {
try {
var a = k.sessionStorage,
b = te();a && (a.setItem(b, "1"), a.removeItem(b));return a;
} catch (c) {
return null;
}
}
function jj() {
var a = "Node" == ne();a = kj() || a && firebase.INTERNAL.node && firebase.INTERNAL.node.sessionStorage;if (!a) return !1;try {
return a.setItem("__sak", "1"), a.removeItem("__sak"), !0;
} catch (b) {
return !1;
}
}g = ij.prototype;g.get = function (a) {
var b = this;return A().then(function () {
var c = b.a.getItem(a);return ze(c);
});
};g.set = function (a, b) {
var c = this;return A().then(function () {
var d = xe(b);null === d ? c.P(a) : c.a.setItem(a, d);
});
};g.P = function (a) {
var b = this;return A().then(function () {
b.a.removeItem(a);
});
};g.Y = function () {};
g.ca = function () {};function lj() {
var a = {};a.Browser = mj;a.Node = nj;a.ReactNative = oj;a.Worker = pj;this.a = a[ne()];
}var qj,
mj = { A: ej, Qa: ij },
nj = { A: ej, Qa: ij },
oj = { A: Si, Qa: hj },
pj = { A: ej, Qa: hj };var rj = { Xc: "local", NONE: "none", Zc: "session" };function sj(a) {
var b = new K("invalid-persistence-type"),
c = new K("unsupported-persistence-type");a: {
for (d in rj) if (rj[d] == a) {
var d = !0;break a;
}d = !1;
}if (!d || "string" !== typeof a) throw b;switch (ne()) {case "ReactNative":
if ("session" === a) throw c;break;case "Node":
if ("none" !== a) throw c;break;default:
if (!se() && "none" !== a) throw c;}
}
function tj() {
var a = !Ae(G()) && le() ? !0 : !1,
b = we(),
c = se();this.o = a;this.h = b;this.m = c;this.a = {};qj || (qj = new lj());a = qj;try {
this.g = !Vd() && Ge() || !k.indexedDB ? new a.a.A() : new cj(me() ? new dj() : new a.a.A());
} catch (d) {
this.g = new dj(), this.h = !0;
}try {
this.i = new a.a.Qa();
} catch (d) {
this.i = new dj();
}this.l = new dj();this.f = r(this.Lb, this);this.b = {};
}var uj;function vj() {
uj || (uj = new tj());return uj;
}function wj(a, b) {
switch (b) {case "session":
return a.i;case "none":
return a.l;default:
return a.g;}
}
function xj(a, b) {
return "firebase:" + a.name + (b ? ":" + b : "");
}function yj(a, b, c) {
var d = xj(b, c),
e = wj(a, b.A);return a.get(b, c).then(function (f) {
var h = null;try {
h = ze(k.localStorage.getItem(d));
} catch (m) {}if (h && !f) return k.localStorage.removeItem(d), a.set(b, h, c);h && f && "localStorage" != e.type && k.localStorage.removeItem(d);
});
}g = tj.prototype;g.get = function (a, b) {
return wj(this, a.A).get(xj(a, b));
};function zj(a, b, c) {
c = xj(b, c);"local" == b.A && (a.b[c] = null);return wj(a, b.A).P(c);
}
g.set = function (a, b, c) {
var d = xj(a, c),
e = this,
f = wj(this, a.A);return f.set(d, b).then(function () {
return f.get(d);
}).then(function (b) {
"local" == a.A && (e.b[d] = b);
});
};g.addListener = function (a, b, c) {
a = xj(a, b);this.m && (this.b[a] = k.localStorage.getItem(a));Za(this.a) && (wj(this, "local").Y(this.f), this.h || (Vd() || !Ge()) && k.indexedDB || !this.m || Aj(this));this.a[a] || (this.a[a] = []);this.a[a].push(c);
};
g.removeListener = function (a, b, c) {
a = xj(a, b);this.a[a] && (Ha(this.a[a], function (a) {
return a == c;
}), 0 == this.a[a].length && delete this.a[a]);Za(this.a) && (wj(this, "local").ca(this.f), Bj(this));
};function Aj(a) {
Bj(a);a.c = setInterval(function () {
for (var b in a.a) {
var c = k.localStorage.getItem(b),
d = a.b[b];c != d && (a.b[b] = c, c = new ec({ type: "storage", key: b, target: window, oldValue: d, newValue: c, a: !0 }), a.Lb(c));
}
}, 1E3);
}function Bj(a) {
a.c && (clearInterval(a.c), a.c = null);
}
g.Lb = function (a) {
if (a && a.f) {
var b = a.a.key;if (null == b) for (var c in this.a) {
var d = this.b[c];"undefined" === typeof d && (d = null);var e = k.localStorage.getItem(c);e !== d && (this.b[c] = e, this.Wa(c));
} else if (0 == b.indexOf("firebase:") && this.a[b]) {
"undefined" !== typeof a.a.a ? wj(this, "local").ca(this.f) : Bj(this);if (this.o) if (c = k.localStorage.getItem(b), d = a.a.newValue, d !== c) null !== d ? k.localStorage.setItem(b, d) : k.localStorage.removeItem(b);else if (this.b[b] === d && "undefined" === typeof a.a.a) return;var f = this;c = function () {
if ("undefined" !== typeof a.a.a || f.b[b] !== k.localStorage.getItem(b)) f.b[b] = k.localStorage.getItem(b), f.Wa(b);
};Ob && Zb && 10 == Zb && k.localStorage.getItem(b) !== a.a.newValue && a.a.newValue !== a.a.oldValue ? setTimeout(c, 10) : c();
}
} else v(a, r(this.Wa, this));
};g.Wa = function (a) {
this.a[a] && v(this.a[a], function (a) {
a();
});
};function Cj(a) {
this.a = a;this.b = vj();
}var Dj = { name: "authEvent", A: "local" };function Ej(a) {
return a.b.get(Dj, a.a).then(function (a) {
return og(a);
});
};function Fj() {
this.a = vj();
};function Gj() {
this.b = -1;
};function Hj(a, b) {
this.b = -1;this.b = Ij;this.f = k.Uint8Array ? new Uint8Array(this.b) : Array(this.b);this.g = this.c = 0;this.a = [];this.i = a;this.h = b;this.m = k.Int32Array ? new Int32Array(64) : Array(64);void 0 !== Jj || (k.Int32Array ? Jj = new Int32Array(Kj) : Jj = Kj);this.reset();
}var Jj;t(Hj, Gj);for (var Ij = 64, Lj = Ij - 1, Mj = [], Nj = 0; Nj < Lj; Nj++) Mj[Nj] = 0;var Oj = Ia(128, Mj);Hj.prototype.reset = function () {
this.g = this.c = 0;this.a = k.Int32Array ? new Int32Array(this.h) : Ja(this.h);
};
function Pj(a) {
for (var b = a.f, c = a.m, d = 0, e = 0; e < b.length;) c[d++] = b[e] << 24 | b[e + 1] << 16 | b[e + 2] << 8 | b[e + 3], e = 4 * d;for (b = 16; 64 > b; b++) {
e = c[b - 15] | 0;d = c[b - 2] | 0;var f = (c[b - 16] | 0) + ((e >>> 7 | e << 25) ^ (e >>> 18 | e << 14) ^ e >>> 3) | 0,
h = (c[b - 7] | 0) + ((d >>> 17 | d << 15) ^ (d >>> 19 | d << 13) ^ d >>> 10) | 0;c[b] = f + h | 0;
}d = a.a[0] | 0;e = a.a[1] | 0;var m = a.a[2] | 0,
p = a.a[3] | 0,
z = a.a[4] | 0,
pc = a.a[5] | 0,
Pc = a.a[6] | 0;f = a.a[7] | 0;for (b = 0; 64 > b; b++) {
var Rl = ((d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10)) + (d & e ^ d & m ^ e & m) | 0;h = z & pc ^ ~z & Pc;f = f + ((z >>> 6 | z << 26) ^ (z >>> 11 | z << 21) ^ (z >>> 25 | z << 7)) | 0;h = h + (Jj[b] | 0) | 0;h = f + (h + (c[b] | 0) | 0) | 0;f = Pc;Pc = pc;pc = z;z = p + h | 0;p = m;m = e;e = d;d = h + Rl | 0;
}a.a[0] = a.a[0] + d | 0;a.a[1] = a.a[1] + e | 0;a.a[2] = a.a[2] + m | 0;a.a[3] = a.a[3] + p | 0;a.a[4] = a.a[4] + z | 0;a.a[5] = a.a[5] + pc | 0;a.a[6] = a.a[6] + Pc | 0;a.a[7] = a.a[7] + f | 0;
}
function Qj(a, b, c) {
void 0 === c && (c = b.length);var d = 0,
e = a.c;if (l(b)) for (; d < c;) a.f[e++] = b.charCodeAt(d++), e == a.b && (Pj(a), e = 0);else if (ha(b)) for (; d < c;) {
var f = b[d++];if (!("number" == typeof f && 0 <= f && 255 >= f && f == (f | 0))) throw Error("message must be a byte array");a.f[e++] = f;e == a.b && (Pj(a), e = 0);
} else throw Error("message must be string or array");a.c = e;a.g += c;
}
var Kj = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298];function Rj() {
Hj.call(this, 8, Sj);
}t(Rj, Hj);var Sj = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225];function Tj(a, b, c, d, e) {
this.l = a;this.i = b;this.m = c;this.o = d || null;this.u = e || null;this.h = b + ":" + c;this.v = new Fj();this.g = new Cj(this.h);this.f = null;this.b = [];this.a = this.c = null;
}function Uj(a) {
return new K("invalid-cordova-configuration", a);
}g = Tj.prototype;
g.ga = function () {
return this.za ? this.za : this.za = ie().then(function () {
if ("function" !== typeof H("universalLinks.subscribe", k)) throw Uj("cordova-universal-links-plugin is not installed");if ("undefined" === typeof H("BuildInfo.packageName", k)) throw Uj("cordova-plugin-buildinfo is not installed");if ("function" !== typeof H("cordova.plugins.browsertab.openUrl", k)) throw Uj("cordova-plugin-browsertab is not installed");if ("function" !== typeof H("cordova.InAppBrowser.open", k)) throw Uj("cordova-plugin-inappbrowser is not installed");
}, function () {
throw new K("cordova-not-ready");
});
};function Vj() {
for (var a = 20, b = []; 0 < a;) b.push("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(Math.floor(62 * Math.random()))), a--;return b.join("");
}function Wj(a) {
var b = new Rj();Qj(b, a);a = [];var c = 8 * b.g;56 > b.c ? Qj(b, Oj, 56 - b.c) : Qj(b, Oj, b.b - (b.c - 56));for (var d = 63; 56 <= d; d--) b.f[d] = c & 255, c /= 256;Pj(b);for (d = c = 0; d < b.i; d++) for (var e = 24; 0 <= e; e -= 8) a[c++] = b.a[d] >> e & 255;return lf(a);
}
g.Ea = function (a, b) {
b(new K("operation-not-supported-in-this-environment"));return A();
};g.zb = function () {
return B(new K("operation-not-supported-in-this-environment"));
};g.Mb = function () {
return !1;
};g.Ib = function () {
return !0;
};g.Db = function () {
return !0;
};
g.Ca = function (a, b, c) {
if (this.c) return B(new K("redirect-operation-pending"));var d = this,
e = k.document,
f = null,
h = null,
m = null,
p = null;return this.c = A().then(function () {
mg(b);return Xj(d);
}).then(function () {
return Yj(d, a, b, c);
}).then(function () {
return new y(function (a, b) {
h = function () {
var b = H("cordova.plugins.browsertab.close", k);a();"function" === typeof b && b();d.a && "function" === typeof d.a.close && (d.a.close(), d.a = null);return !1;
};d.va(h);m = function () {
f || (f = Hc(2E3).then(function () {
b(new K("redirect-cancelled-by-user"));
}));
};
p = function () {
De() && m();
};e.addEventListener("resume", m, !1);G().toLowerCase().match(/android/) || e.addEventListener("visibilitychange", p, !1);
}).s(function (a) {
return Zj(d).then(function () {
throw a;
});
});
}).ia(function () {
m && e.removeEventListener("resume", m, !1);p && e.removeEventListener("visibilitychange", p, !1);f && f.cancel();h && d.Ka(h);d.c = null;
});
};
function Yj(a, b, c, d) {
var e = Vj(),
f = new ng(b, d, null, e, new K("no-auth-event")),
h = H("BuildInfo.packageName", k);if ("string" !== typeof h) throw new K("invalid-cordova-configuration");var m = H("BuildInfo.displayName", k),
p = {};if (G().toLowerCase().match(/iphone|ipad|ipod/)) p.ibi = h;else if (G().toLowerCase().match(/android/)) p.apn = h;else return B(new K("operation-not-supported-in-this-environment"));m && (p.appDisplayName = m);e = Wj(e);p.sessionId = e;var z = Ri(a.l, a.i, a.m, b, c, null, d, a.o, p, a.u);return a.ga().then(function () {
var b = a.h;return a.v.a.set(Dj, f.D(), b);
}).then(function () {
var b = H("cordova.plugins.browsertab.isAvailable", k);if ("function" !== typeof b) throw new K("invalid-cordova-configuration");var c = null;b(function (b) {
if (b) {
c = H("cordova.plugins.browsertab.openUrl", k);if ("function" !== typeof c) throw new K("invalid-cordova-configuration");c(z);
} else {
c = H("cordova.InAppBrowser.open", k);if ("function" !== typeof c) throw new K("invalid-cordova-configuration");b = G();b = !(!b.match(/(iPad|iPhone|iPod).*OS 7_\d/i) && !b.match(/(iPad|iPhone|iPod).*OS 8_\d/i));
a.a = c(z, b ? "_blank" : "_system", "location=yes");
}
});
});
}function ak(a, b) {
for (var c = 0; c < a.b.length; c++) try {
a.b[c](b);
} catch (d) {}
}function Xj(a) {
a.f || (a.f = a.ga().then(function () {
return new y(function (b) {
function c(d) {
b(d);a.Ka(c);return !1;
}a.va(c);bk(a);
});
}));return a.f;
}function Zj(a) {
var b = null;return Ej(a.g).then(function (c) {
b = c;c = a.g;return zj(c.b, Dj, c.a);
}).then(function () {
return b;
});
}
function bk(a) {
function b(b) {
d = !0;e && e.cancel();Zj(a).then(function (d) {
var e = c;if (d && b && b.url) {
var f = null;e = If(b.url);-1 != e.indexOf("/__/auth/callback") && (f = ed(e), f = ze(dd(f, "firebaseError") || null), f = (f = "object" === typeof f ? $e(f) : null) ? new ng(d.b, d.c, null, null, f) : new ng(d.b, d.c, e, d.g));e = f || c;
}ak(a, e);
});
}var c = new ng("unknown", null, null, null, new K("no-auth-event")),
d = !1,
e = Hc(500).then(function () {
return Zj(a).then(function () {
d || ak(a, c);
});
}),
f = k.handleOpenURL;k.handleOpenURL = function (a) {
0 == a.toLowerCase().indexOf(H("BuildInfo.packageName", k).toLowerCase() + "://") && b({ url: a });if ("function" === typeof f) try {
f(a);
} catch (m) {
console.error(m);
}
};qg || (qg = new pg());qg.subscribe(b);
}g.va = function (a) {
this.b.push(a);Xj(this).s(function (b) {
"auth/invalid-cordova-configuration" === b.code && (b = new ng("unknown", null, null, null, new K("no-auth-event")), a(b));
});
};g.Ka = function (a) {
Ha(this.b, function (b) {
return b == a;
});
};function ck(a) {
this.a = a;this.b = vj();
}var dk = { name: "pendingRedirect", A: "session" };function ek(a) {
return a.b.set(dk, "pending", a.a);
}function fk(a) {
return zj(a.b, dk, a.a);
}function gk(a) {
return a.b.get(dk, a.a).then(function (a) {
return "pending" == a;
});
};function hk(a, b, c) {
this.v = a;this.m = b;this.l = c;this.h = [];this.f = !1;this.i = r(this.o, this);this.c = new ik();this.u = new jk();this.g = new ck(this.m + ":" + this.l);this.b = {};this.b.unknown = this.c;this.b.signInViaRedirect = this.c;this.b.linkViaRedirect = this.c;this.b.reauthViaRedirect = this.c;this.b.signInViaPopup = this.u;this.b.linkViaPopup = this.u;this.b.reauthViaPopup = this.u;this.a = kk(this.v, this.m, this.l, yi);
}function kk(a, b, c, d) {
var e = firebase.SDK_VERSION || null;return je() ? new Tj(a, b, c, e, d) : new Li(a, b, c, e, d);
}
hk.prototype.reset = function () {
this.f = !1;this.a.Ka(this.i);this.a = kk(this.v, this.m, this.l);
};function lk(a) {
a.f || (a.f = !0, a.a.va(a.i));var b = a.a;return a.a.ga().s(function (c) {
a.a == b && a.reset();throw c;
});
}function mk(a) {
a.a.Ib() && lk(a).s(function (b) {
var c = new ng("unknown", null, null, null, new K("operation-not-supported-in-this-environment"));nk(b) && a.o(c);
});a.a.Db() || ok(a.c);
}
hk.prototype.subscribe = function (a) {
Fa(this.h, a) || this.h.push(a);if (!this.f) {
var b = this;gk(this.g).then(function (a) {
a ? fk(b.g).then(function () {
lk(b).s(function (a) {
var c = new ng("unknown", null, null, null, new K("operation-not-supported-in-this-environment"));nk(a) && b.o(c);
});
}) : mk(b);
}).s(function () {
mk(b);
});
}
};hk.prototype.unsubscribe = function (a) {
Ha(this.h, function (b) {
return b == a;
});
};
hk.prototype.o = function (a) {
if (!a) throw new K("invalid-auth-event");for (var b = !1, c = 0; c < this.h.length; c++) {
var d = this.h[c];if (d.sb(a.b, a.c)) {
(b = this.b[a.b]) && b.h(a, d);b = !0;break;
}
}ok(this.c);return b;
};var pk = new Ce(2E3, 1E4),
qk = new Ce(3E4, 6E4);hk.prototype.fa = function () {
return this.c.fa();
};function rk(a, b, c, d, e, f) {
return a.a.zb(b, c, d, function () {
a.f || (a.f = !0, a.a.va(a.i));
}, function () {
a.reset();
}, e, f);
}function nk(a) {
return a && "auth/cordova-not-ready" == a.code ? !0 : !1;
}
hk.prototype.Ca = function (a, b, c) {
var d = this,
e;return ek(this.g).then(function () {
return d.a.Ca(a, b, c).s(function (a) {
if (nk(a)) throw new K("operation-not-supported-in-this-environment");e = a;return fk(d.g).then(function () {
throw e;
});
}).then(function () {
return d.a.Mb() ? new y(function () {}) : fk(d.g).then(function () {
return d.fa();
}).then(function () {}).s(function () {});
});
});
};hk.prototype.Ea = function (a, b, c, d) {
return this.a.Ea(c, function (c) {
a.ha(b, null, c, d);
}, pk.get());
};var sk = {};
function tk(a, b, c) {
var d = b + ":" + c;sk[d] || (sk[d] = new hk(a, b, c));return sk[d];
}function ik() {
this.b = null;this.f = [];this.c = [];this.a = null;this.g = !1;
}ik.prototype.reset = function () {
this.b = null;this.a && (this.a.cancel(), this.a = null);
};
ik.prototype.h = function (a, b) {
if (a) {
this.reset();this.g = !0;var c = a.b,
d = a.c,
e = a.a && "auth/web-storage-unsupported" == a.a.code,
f = a.a && "auth/operation-not-supported-in-this-environment" == a.a.code;"unknown" != c || e || f ? a.a ? (uk(this, !0, null, a.a), A()) : b.wa(c, d) ? vk(this, a, b) : B(new K("invalid-auth-event")) : (uk(this, !1, null, null), A());
} else B(new K("invalid-auth-event"));
};function ok(a) {
a.g || (a.g = !0, uk(a, !1, null, null));
}
function vk(a, b, c) {
c = c.wa(b.b, b.c);var d = b.f,
e = b.g,
f = !!b.b.match(/Redirect$/);c(d, e).then(function (b) {
uk(a, f, b, null);
}).s(function (b) {
uk(a, f, null, b);
});
}function wk(a, b) {
a.b = function () {
return B(b);
};if (a.c.length) for (var c = 0; c < a.c.length; c++) a.c[c](b);
}function xk(a, b) {
a.b = function () {
return A(b);
};if (a.f.length) for (var c = 0; c < a.f.length; c++) a.f[c](b);
}function uk(a, b, c, d) {
b ? d ? wk(a, d) : xk(a, c) : xk(a, { user: null });a.f = [];a.c = [];
}
ik.prototype.fa = function () {
var a = this;return new y(function (b, c) {
a.b ? a.b().then(b, c) : (a.f.push(b), a.c.push(c), yk(a));
});
};function yk(a) {
var b = new K("timeout");a.a && a.a.cancel();a.a = Hc(qk.get()).then(function () {
a.b || uk(a, !0, null, b);
});
}function jk() {}jk.prototype.h = function (a, b) {
if (a) {
var c = a.b,
d = a.c;a.a ? (b.ha(a.b, null, a.a, a.c), A()) : b.wa(c, d) ? zk(a, b) : B(new K("invalid-auth-event"));
} else B(new K("invalid-auth-event"));
};
function zk(a, b) {
var c = a.c,
d = a.b;b.wa(d, c)(a.f, a.g).then(function (a) {
b.ha(d, a, null, c);
}).s(function (a) {
b.ha(d, null, a, c);
});
};function Ak() {
this.pb = !1;Object.defineProperty(this, "appVerificationDisabled", { get: function () {
return this.pb;
}, set: function (a) {
this.pb = a;
}, enumerable: !1 });
};function Bk(a, b) {
this.a = b;I(this, "verificationId", a);
}Bk.prototype.confirm = function (a) {
a = kg(this.verificationId, a);return this.a(a);
};function Ck(a, b, c, d) {
return new ig(a).Ta(b, c).then(function (a) {
return new Bk(a, d);
});
};function Dk(a) {
var b = tf(a);if (!(b && b.exp && b.auth_time && b.iat)) throw new K("internal-error", "An internal error occurred. The token obtained by Firebase appears to be malformed. Please retry the operation.");J(this, { token: a, expirationTime: Fe(1E3 * b.exp), authTime: Fe(1E3 * b.auth_time), issuedAtTime: Fe(1E3 * b.iat), signInProvider: b.firebase && b.firebase.sign_in_provider ? b.firebase.sign_in_provider : null, claims: b });
};function Ek(a, b, c) {
this.h = a;this.i = b;this.g = c;this.c = 3E4;this.f = 96E4;this.b = null;this.a = this.c;if (this.f < this.c) throw Error("Proactive refresh lower bound greater than upper bound!");
}Ek.prototype.start = function () {
this.a = this.c;Fk(this, !0);
};function Gk(a, b) {
if (b) return a.a = a.c, a.g();b = a.a;a.a *= 2;a.a > a.f && (a.a = a.f);return b;
}function Fk(a, b) {
a.stop();a.b = Hc(Gk(a, b)).then(function () {
return Ee();
}).then(function () {
return a.h();
}).then(function () {
Fk(a, !0);
}).s(function (b) {
a.i(b) && Fk(a, !1);
});
}
Ek.prototype.stop = function () {
this.b && (this.b.cancel(), this.b = null);
};function Hk(a) {
this.f = a;this.b = this.a = null;this.c = 0;
}Hk.prototype.D = function () {
return { apiKey: this.f.b, refreshToken: this.a, accessToken: this.b, expirationTime: this.c };
};function Ik(a, b) {
var c = b[L],
d = b.refreshToken;b = Jk(b.expiresIn);a.b = c;a.c = b;a.a = d;
}function Kk(a, b) {
a.b = b.b;a.a = b.a;a.c = b.c;
}function Jk(a) {
return na() + 1E3 * parseInt(a, 10);
}
function Lk(a, b) {
return Mh(a.f, b).then(function (b) {
a.b = b.access_token;a.c = Jk(b.expires_in);a.a = b.refresh_token;return { accessToken: a.b, expirationTime: a.c, refreshToken: a.a };
}).s(function (b) {
"auth/user-token-expired" == b.code && (a.a = null);throw b;
});
}Hk.prototype.getToken = function (a) {
a = !!a;return this.b && !this.a ? B(new K("user-token-expired")) : a || !this.b || na() > this.c - 3E4 ? this.a ? Lk(this, { grant_type: "refresh_token", refresh_token: this.a }) : A(null) : A({ accessToken: this.b, expirationTime: this.c, refreshToken: this.a });
};function Mk(a, b) {
this.a = a || null;this.b = b || null;J(this, { lastSignInTime: Fe(b || null), creationTime: Fe(a || null) });
}function Nk(a) {
return new Mk(a.a, a.b);
}Mk.prototype.D = function () {
return { lastLoginAt: this.b, createdAt: this.a };
};function Ok(a, b, c, d, e, f) {
J(this, { uid: a, displayName: d || null, photoURL: e || null, email: c || null, phoneNumber: f || null, providerId: b });
}function Pk(a, b) {
C.call(this, a);for (var c in b) this[c] = b[c];
}t(Pk, C);
function Q(a, b, c) {
this.G = [];this.l = a.apiKey;this.o = a.appName;this.u = a.authDomain || null;a = firebase.SDK_VERSION ? re(firebase.SDK_VERSION) : null;this.b = new Ah(this.l, xi(yi), a);this.h = new Hk(this.b);Qk(this, b[L]);Ik(this.h, b);I(this, "refreshToken", this.h.a);Rk(this, c || {});E.call(this);this.I = !1;this.u && ue() && (this.a = tk(this.u, this.l, this.o));this.N = [];this.i = null;this.w = Sk(this);this.V = r(this.Ha, this);var d = this;this.ka = null;this.sa = function (a) {
d.oa(a.g);
};this.X = null;this.O = [];this.ra = function (a) {
Tk(d, a.c);
};this.W = null;
}t(Q, E);Q.prototype.oa = function (a) {
this.ka = a;Gh(this.b, a);
};Q.prototype.ea = function () {
return this.ka;
};function Uk(a, b) {
a.X && D(a.X, "languageCodeChanged", a.sa);(a.X = b) && rc(b, "languageCodeChanged", a.sa);
}function Tk(a, b) {
a.O = b;Hh(a.b, firebase.SDK_VERSION ? re(firebase.SDK_VERSION, a.O) : null);
}Q.prototype.xa = function () {
return Ja(this.O);
};function Vk(a, b) {
a.W && D(a.W, "frameworkChanged", a.ra);(a.W = b) && rc(b, "frameworkChanged", a.ra);
}Q.prototype.Ha = function () {
this.w.b && (this.w.stop(), this.w.start());
};
function Wk(a) {
try {
return firebase.app(a.o).auth();
} catch (b) {
throw new K("internal-error", "No firebase.auth.Auth instance is available for the Firebase App '" + a.o + "'!");
}
}function Sk(a) {
return new Ek(function () {
return a.F(!0);
}, function (a) {
return a && "auth/network-request-failed" == a.code ? !0 : !1;
}, function () {
var b = a.h.c - na() - 3E5;return 0 < b ? b : 0;
});
}function Xk(a) {
a.C || a.w.b || (a.w.start(), D(a, "tokenChanged", a.V), rc(a, "tokenChanged", a.V));
}function Yk(a) {
D(a, "tokenChanged", a.V);a.w.stop();
}
function Qk(a, b) {
a.qa = b;I(a, "_lat", b);
}function Zk(a, b) {
Ha(a.N, function (a) {
return a == b;
});
}function $k(a) {
for (var b = [], c = 0; c < a.N.length; c++) b.push(a.N[c](a));return vb(b).then(function () {
return a;
});
}function al(a) {
a.a && !a.I && (a.I = !0, a.a.subscribe(a));
}
function Rk(a, b) {
J(a, { uid: b.uid, displayName: b.displayName || null, photoURL: b.photoURL || null, email: b.email || null, emailVerified: b.emailVerified || !1, phoneNumber: b.phoneNumber || null, isAnonymous: b.isAnonymous || !1, metadata: new Mk(b.createdAt, b.lastLoginAt), providerData: [] });
}I(Q.prototype, "providerId", "firebase");function bl() {}function cl(a) {
return A().then(function () {
if (a.C) throw new K("app-deleted");
});
}function dl(a) {
return Ba(a.providerData, function (a) {
return a.providerId;
});
}
function el(a, b) {
b && (fl(a, b.providerId), a.providerData.push(b));
}function fl(a, b) {
Ha(a.providerData, function (a) {
return a.providerId == b;
});
}function gl(a, b, c) {
("uid" != b || c) && a.hasOwnProperty(b) && I(a, b, c);
}
function hl(a, b) {
a != b && (J(a, { uid: b.uid, displayName: b.displayName, photoURL: b.photoURL, email: b.email, emailVerified: b.emailVerified, phoneNumber: b.phoneNumber, isAnonymous: b.isAnonymous, providerData: [] }), b.metadata ? I(a, "metadata", Nk(b.metadata)) : I(a, "metadata", new Mk()), v(b.providerData, function (b) {
el(a, b);
}), Kk(a.h, b.h), I(a, "refreshToken", a.h.a));
}g = Q.prototype;g.reload = function () {
var a = this;return R(this, cl(this).then(function () {
return il(a).then(function () {
return $k(a);
}).then(bl);
}));
};
function il(a) {
return a.F().then(function (b) {
var c = a.isAnonymous;return jl(a, b).then(function () {
c || gl(a, "isAnonymous", !1);return b;
});
});
}g.ac = function (a) {
return this.F(a).then(function (a) {
return new Dk(a);
});
};g.F = function (a) {
var b = this;return R(this, cl(this).then(function () {
return b.h.getToken(a);
}).then(function (a) {
if (!a) throw new K("internal-error");a.accessToken != b.qa && (Qk(b, a.accessToken), b.dispatchEvent(new Pk("tokenChanged")));gl(b, "refreshToken", a.refreshToken);return a.accessToken;
}));
};
function kl(a, b) {
b[L] && a.qa != b[L] && (Ik(a.h, b), a.dispatchEvent(new Pk("tokenChanged")), Qk(a, b[L]), gl(a, "refreshToken", a.h.a));
}function jl(a, b) {
return O(a.b, ti, { idToken: b }).then(r(a.uc, a));
}
g.uc = function (a) {
a = a.users;if (!a || !a.length) throw new K("internal-error");a = a[0];Rk(this, { uid: a.localId, displayName: a.displayName, photoURL: a.photoUrl, email: a.email, emailVerified: !!a.emailVerified, phoneNumber: a.phoneNumber, lastLoginAt: a.lastLoginAt, createdAt: a.createdAt });for (var b = ll(a), c = 0; c < b.length; c++) el(this, b[c]);gl(this, "isAnonymous", !(this.email && a.passwordHash) && !(this.providerData && this.providerData.length));
};
function ll(a) {
return (a = a.providerUserInfo) && a.length ? Ba(a, function (a) {
return new Ok(a.rawId, a.providerId, a.email, a.displayName, a.photoUrl, a.phoneNumber);
}) : [];
}g.cb = function (a) {
var b = this,
c = null;return R(this, a.f(this.b, this.uid).then(function (a) {
kl(b, a);c = ml(b, a, "reauthenticate");b.i = null;return b.reload();
}).then(function () {
return c;
}), !0);
};
g.vc = function (a) {
Ie("firebase.User.prototype.reauthenticateWithCredential is deprecated. Please use firebase.User.prototype.reauthenticateAndRetrieveDataWithCredential instead.");return this.cb(a).then(function () {});
};function nl(a, b) {
return il(a).then(function () {
if (Fa(dl(a), b)) return $k(a).then(function () {
throw new K("provider-already-linked");
});
});
}
g.ab = function (a) {
var b = this,
c = null;return R(this, nl(this, a.providerId).then(function () {
return b.F();
}).then(function (c) {
return a.c(b.b, c);
}).then(function (a) {
c = ml(b, a, "link");return ol(b, a);
}).then(function () {
return c;
}));
};g.mc = function (a) {
Ie("firebase.User.prototype.linkWithCredential is deprecated. Please use firebase.User.prototype.linkAndRetrieveDataWithCredential instead.");return this.ab(a).then(function (a) {
return a.user;
});
};
g.nc = function (a, b) {
var c = this;return R(this, nl(this, "phone").then(function () {
return Ck(Wk(c), a, b, r(c.ab, c));
}));
};g.wc = function (a, b) {
var c = this;return R(this, A().then(function () {
return Ck(Wk(c), a, b, r(c.cb, c));
}), !0);
};function ml(a, b, c) {
var d = lg(b);b = yf(b);return Le({ user: a, credential: d, additionalUserInfo: b, operationType: c });
}function ol(a, b) {
kl(a, b);return a.reload().then(function () {
return a;
});
}
g.mb = function (a) {
var b = this;return R(this, this.F().then(function (c) {
return b.b.mb(c, a);
}).then(function (a) {
kl(b, a);return b.reload();
}));
};g.Pc = function (a) {
var b = this;return R(this, this.F().then(function (c) {
return a.c(b.b, c);
}).then(function (a) {
kl(b, a);return b.reload();
}));
};g.nb = function (a) {
var b = this;return R(this, this.F().then(function (c) {
return b.b.nb(c, a);
}).then(function (a) {
kl(b, a);return b.reload();
}));
};
g.ob = function (a) {
if (void 0 === a.displayName && void 0 === a.photoURL) return cl(this);var b = this;return R(this, this.F().then(function (c) {
return b.b.ob(c, { displayName: a.displayName, photoUrl: a.photoURL });
}).then(function (a) {
kl(b, a);gl(b, "displayName", a.displayName || null);gl(b, "photoURL", a.photoUrl || null);v(b.providerData, function (a) {
"password" === a.providerId && (I(a, "displayName", b.displayName), I(a, "photoURL", b.photoURL));
});return $k(b);
}).then(bl));
};
g.Nc = function (a) {
var b = this;return R(this, il(this).then(function (c) {
return Fa(dl(b), a) ? fi(b.b, c, [a]).then(function (a) {
var c = {};v(a.providerUserInfo || [], function (a) {
c[a.providerId] = !0;
});v(dl(b), function (a) {
c[a] || fl(b, a);
});c[ig.PROVIDER_ID] || I(b, "phoneNumber", null);return $k(b);
}) : $k(b).then(function () {
throw new K("no-such-provider");
});
}));
};
g.delete = function () {
var a = this;return R(this, this.F().then(function (b) {
return O(a.b, si, { idToken: b });
}).then(function () {
a.dispatchEvent(new Pk("userDeleted"));
})).then(function () {
for (var b = 0; b < a.G.length; b++) a.G[b].cancel("app-deleted");Uk(a, null);Vk(a, null);a.G = [];a.C = !0;Yk(a);I(a, "refreshToken", null);a.a && a.a.unsubscribe(a);
});
};
g.sb = function (a, b) {
return "linkViaPopup" == a && (this.g || null) == b && this.f || "reauthViaPopup" == a && (this.g || null) == b && this.f || "linkViaRedirect" == a && (this.aa || null) == b || "reauthViaRedirect" == a && (this.aa || null) == b ? !0 : !1;
};g.ha = function (a, b, c, d) {
"linkViaPopup" != a && "reauthViaPopup" != a || d != (this.g || null) || (c && this.v ? this.v(c) : b && !c && this.f && this.f(b), this.c && (this.c.cancel(), this.c = null), delete this.f, delete this.v);
};
g.wa = function (a, b) {
return "linkViaPopup" == a && b == (this.g || null) ? r(this.xb, this) : "reauthViaPopup" == a && b == (this.g || null) ? r(this.yb, this) : "linkViaRedirect" == a && (this.aa || null) == b ? r(this.xb, this) : "reauthViaRedirect" == a && (this.aa || null) == b ? r(this.yb, this) : null;
};g.oc = function (a) {
var b = this;return pl(this, "linkViaPopup", a, function () {
return nl(b, a.providerId).then(function () {
return $k(b);
});
}, !1);
};g.xc = function (a) {
return pl(this, "reauthViaPopup", a, function () {
return A();
}, !0);
};
function pl(a, b, c, d, e) {
if (!ue()) return B(new K("operation-not-supported-in-this-environment"));if (a.i && !e) return B(a.i);var f = xf(c.providerId),
h = te(a.uid + ":::"),
m = null;(!we() || le()) && a.u && c.isOAuthProvider && (m = Ri(a.u, a.l, a.o, b, c, null, h, firebase.SDK_VERSION || null));var p = de(m, f && f.Ba, f && f.Aa);d = d().then(function () {
ql(a);if (!e) return a.F().then(function () {});
}).then(function () {
return rk(a.a, p, b, c, h, !!m);
}).then(function () {
return new y(function (c, d) {
a.ha(b, null, new K("cancelled-popup-request"), a.g || null);
a.f = c;a.v = d;a.g = h;a.c = a.a.Ea(a, b, p, h);
});
}).then(function (a) {
p && ce(p);return a ? Le(a) : null;
}).s(function (a) {
p && ce(p);throw a;
});return R(a, d, e);
}g.pc = function (a) {
var b = this;return rl(this, "linkViaRedirect", a, function () {
return nl(b, a.providerId);
}, !1);
};g.yc = function (a) {
return rl(this, "reauthViaRedirect", a, function () {
return A();
}, !0);
};
function rl(a, b, c, d, e) {
if (!ue()) return B(new K("operation-not-supported-in-this-environment"));if (a.i && !e) return B(a.i);var f = null,
h = te(a.uid + ":::");d = d().then(function () {
ql(a);if (!e) return a.F().then(function () {});
}).then(function () {
a.aa = h;return $k(a);
}).then(function (b) {
a.ba && (b = a.ba, b = b.b.set(sl, a.D(), b.a));return b;
}).then(function () {
return a.a.Ca(b, c, h);
}).s(function (b) {
f = b;if (a.ba) return tl(a.ba);throw f;
}).then(function () {
if (f) throw f;
});return R(a, d, e);
}
function ql(a) {
if (!a.a || !a.I) {
if (a.a && !a.I) throw new K("internal-error");throw new K("auth-domain-config-required");
}
}g.xb = function (a, b) {
var c = this;this.c && (this.c.cancel(), this.c = null);var d = null,
e = this.F().then(function (d) {
return Nf(c.b, { requestUri: a, sessionId: b, idToken: d });
}).then(function (a) {
d = ml(c, a, "link");return ol(c, a);
}).then(function () {
return d;
});return R(this, e);
};
g.yb = function (a, b) {
var c = this;this.c && (this.c.cancel(), this.c = null);var d = null,
e = A().then(function () {
return Jf(Of(c.b, { requestUri: a, sessionId: b }), c.uid);
}).then(function (a) {
d = ml(c, a, "reauthenticate");kl(c, a);c.i = null;return c.reload();
}).then(function () {
return d;
});return R(this, e, !0);
};g.gb = function (a) {
var b = this,
c = null;return R(this, this.F().then(function (b) {
c = b;return "undefined" === typeof a || Za(a) ? {} : kf(new af(a));
}).then(function (a) {
return b.b.gb(c, a);
}).then(function (a) {
if (b.email != a) return b.reload();
}).then(function () {}));
};
function R(a, b, c) {
var d = ul(a, b, c);a.G.push(d);d.ia(function () {
Ga(a.G, d);
});return d;
}function ul(a, b, c) {
return a.i && !c ? (b.cancel(), B(a.i)) : b.s(function (b) {
!b || "auth/user-disabled" != b.code && "auth/user-token-expired" != b.code || (a.i || a.dispatchEvent(new Pk("userInvalidated")), a.i = b);throw b;
});
}g.toJSON = function () {
return this.D();
};
g.D = function () {
var a = { uid: this.uid, displayName: this.displayName, photoURL: this.photoURL, email: this.email, emailVerified: this.emailVerified, phoneNumber: this.phoneNumber, isAnonymous: this.isAnonymous, providerData: [], apiKey: this.l, appName: this.o, authDomain: this.u, stsTokenManager: this.h.D(), redirectEventId: this.aa || null };this.metadata && bb(a, this.metadata.D());v(this.providerData, function (b) {
a.providerData.push(Me(b));
});return a;
};
function vl(a) {
if (!a.apiKey) return null;var b = { apiKey: a.apiKey, authDomain: a.authDomain, appName: a.appName },
c = {};if (a.stsTokenManager && a.stsTokenManager.accessToken && a.stsTokenManager.expirationTime) c[L] = a.stsTokenManager.accessToken, c.refreshToken = a.stsTokenManager.refreshToken || null, c.expiresIn = (a.stsTokenManager.expirationTime - na()) / 1E3;else return null;var d = new Q(b, c, a);a.providerData && v(a.providerData, function (a) {
a && el(d, Le(a));
});a.redirectEventId && (d.aa = a.redirectEventId);return d;
}
function wl(a, b, c, d) {
var e = new Q(a, b);c && (e.ba = c);d && Tk(e, d);return e.reload().then(function () {
return e;
});
}function xl(a, b, c, d) {
b = b || { apiKey: a.l, authDomain: a.u, appName: a.o };var e = a.h,
f = {};f[L] = e.b;f.refreshToken = e.a;f.expiresIn = (e.c - na()) / 1E3;b = new Q(b, f);c && (b.ba = c);d && Tk(b, d);hl(b, a);return b;
};function yl(a) {
this.a = a;this.b = vj();
}var sl = { name: "redirectUser", A: "session" };function tl(a) {
return zj(a.b, sl, a.a);
}function zl(a, b) {
return a.b.get(sl, a.a).then(function (a) {
a && b && (a.authDomain = b);return vl(a || {});
});
};function Al(a) {
this.a = a;this.b = vj();this.c = null;this.f = Bl(this);this.b.addListener(Cl("local"), this.a, r(this.g, this));
}Al.prototype.g = function () {
var a = this,
b = Cl("local");Dl(this, function () {
return A().then(function () {
return a.c && "local" != a.c.A ? a.b.get(b, a.a) : null;
}).then(function (c) {
if (c) return El(a, "local").then(function () {
a.c = b;
});
});
});
};function El(a, b) {
var c = [],
d;for (d in rj) rj[d] !== b && c.push(zj(a.b, Cl(rj[d]), a.a));c.push(zj(a.b, Fl, a.a));return ub(c);
}
function Bl(a) {
var b = Cl("local"),
c = Cl("session"),
d = Cl("none");return yj(a.b, b, a.a).then(function () {
return a.b.get(c, a.a);
}).then(function (e) {
return e ? c : a.b.get(d, a.a).then(function (c) {
return c ? d : a.b.get(b, a.a).then(function (c) {
return c ? b : a.b.get(Fl, a.a).then(function (a) {
return a ? Cl(a) : b;
});
});
});
}).then(function (b) {
a.c = b;return El(a, b.A);
}).s(function () {
a.c || (a.c = b);
});
}var Fl = { name: "persistence", A: "session" };function Cl(a) {
return { name: "authUser", A: a };
}
Al.prototype.jb = function (a) {
var b = null,
c = this;sj(a);return Dl(this, function () {
return a != c.c.A ? c.b.get(c.c, c.a).then(function (d) {
b = d;return El(c, a);
}).then(function () {
c.c = Cl(a);if (b) return c.b.set(c.c, b, c.a);
}) : A();
});
};function Gl(a) {
return Dl(a, function () {
return a.b.set(Fl, a.c.A, a.a);
});
}function Hl(a, b) {
return Dl(a, function () {
return a.b.set(a.c, b.D(), a.a);
});
}function Il(a) {
return Dl(a, function () {
return zj(a.b, a.c, a.a);
});
}
function Jl(a, b) {
return Dl(a, function () {
return a.b.get(a.c, a.a).then(function (a) {
a && b && (a.authDomain = b);return vl(a || {});
});
});
}function Dl(a, b) {
a.f = a.f.then(b, b);return a.f;
};function Kl(a) {
this.l = !1;I(this, "settings", new Ak());I(this, "app", a);if (S(this).options && S(this).options.apiKey) a = firebase.SDK_VERSION ? re(firebase.SDK_VERSION) : null, this.b = new Ah(S(this).options && S(this).options.apiKey, xi(yi), a);else throw new K("invalid-api-key");this.N = [];this.o = [];this.I = [];this.Pb = firebase.INTERNAL.createSubscribe(r(this.ic, this));this.O = void 0;this.Qb = firebase.INTERNAL.createSubscribe(r(this.jc, this));Ll(this, null);this.h = new Al(S(this).options.apiKey + ":" + S(this).name);this.w = new yl(S(this).options.apiKey + ":" + S(this).name);this.V = T(this, Ml(this));this.i = T(this, Nl(this));this.X = !1;this.ka = r(this.Jc, this);this.Ha = r(this.Z, this);this.qa = r(this.Yb, this);this.ra = r(this.gc, this);this.sa = r(this.hc, this);Ol(this);this.INTERNAL = {};this.INTERNAL["delete"] = r(this.delete, this);this.INTERNAL.logFramework = r(this.qc, this);this.u = 0;E.call(this);Pl(this);this.G = [];
}t(Kl, E);function Ql(a) {
C.call(this, "languageCodeChanged");this.g = a;
}t(Ql, C);
function Sl(a) {
C.call(this, "frameworkChanged");this.c = a;
}t(Sl, C);g = Kl.prototype;g.jb = function (a) {
a = this.h.jb(a);return T(this, a);
};g.oa = function (a) {
this.W === a || this.l || (this.W = a, Gh(this.b, this.W), this.dispatchEvent(new Ql(this.ea())));
};g.ea = function () {
return this.W;
};g.Qc = function () {
var a = k.navigator;this.oa(a ? a.languages && a.languages[0] || a.language || a.userLanguage || null : null);
};g.qc = function (a) {
this.G.push(a);Hh(this.b, firebase.SDK_VERSION ? re(firebase.SDK_VERSION, this.G) : null);this.dispatchEvent(new Sl(this.G));
};
g.xa = function () {
return Ja(this.G);
};function Pl(a) {
Object.defineProperty(a, "lc", { get: function () {
return this.ea();
}, set: function (a) {
this.oa(a);
}, enumerable: !1 });a.W = null;
}g.toJSON = function () {
return { apiKey: S(this).options.apiKey, authDomain: S(this).options.authDomain, appName: S(this).name, currentUser: U(this) && U(this).D() };
};function Tl(a) {
return a.Ob || B(new K("auth-domain-config-required"));
}
function Ol(a) {
var b = S(a).options.authDomain,
c = S(a).options.apiKey;b && ue() && (a.Ob = a.V.then(function () {
if (!a.l) {
a.a = tk(b, c, S(a).name);a.a.subscribe(a);U(a) && al(U(a));if (a.C) {
al(a.C);var d = a.C;d.oa(a.ea());Uk(d, a);d = a.C;Tk(d, a.G);Vk(d, a);a.C = null;
}return a.a;
}
}));
}g.sb = function (a, b) {
switch (a) {case "unknown":case "signInViaRedirect":
return !0;case "signInViaPopup":
return this.g == b && !!this.f;default:
return !1;}
};
g.ha = function (a, b, c, d) {
"signInViaPopup" == a && this.g == d && (c && this.v ? this.v(c) : b && !c && this.f && this.f(b), this.c && (this.c.cancel(), this.c = null), delete this.f, delete this.v);
};g.wa = function (a, b) {
return "signInViaRedirect" == a || "signInViaPopup" == a && this.g == b && this.f ? r(this.Xb, this) : null;
};
g.Xb = function (a, b) {
var c = this;a = { requestUri: a, sessionId: b };this.c && (this.c.cancel(), this.c = null);var d = null,
e = null,
f = Lf(c.b, a).then(function (a) {
d = lg(a);e = yf(a);return a;
});a = c.V.then(function () {
return f;
}).then(function (a) {
return Ul(c, a);
}).then(function () {
return Le({ user: U(c), credential: d, additionalUserInfo: e, operationType: "signIn" });
});return T(this, a);
};
g.Hc = function (a) {
if (!ue()) return B(new K("operation-not-supported-in-this-environment"));var b = this,
c = xf(a.providerId),
d = te(),
e = null;(!we() || le()) && S(this).options.authDomain && a.isOAuthProvider && (e = Ri(S(this).options.authDomain, S(this).options.apiKey, S(this).name, "signInViaPopup", a, null, d, firebase.SDK_VERSION || null));var f = de(e, c && c.Ba, c && c.Aa);c = Tl(this).then(function (b) {
return rk(b, f, "signInViaPopup", a, d, !!e);
}).then(function () {
return new y(function (a, c) {
b.ha("signInViaPopup", null, new K("cancelled-popup-request"), b.g);b.f = a;b.v = c;b.g = d;b.c = b.a.Ea(b, "signInViaPopup", f, d);
});
}).then(function (a) {
f && ce(f);return a ? Le(a) : null;
}).s(function (a) {
f && ce(f);throw a;
});return T(this, c);
};g.Ic = function (a) {
if (!ue()) return B(new K("operation-not-supported-in-this-environment"));var b = this,
c = Tl(this).then(function () {
return Gl(b.h);
}).then(function () {
return b.a.Ca("signInViaRedirect", a);
});return T(this, c);
};
g.fa = function () {
if (!ue()) return B(new K("operation-not-supported-in-this-environment"));var a = this,
b = Tl(this).then(function () {
return a.a.fa();
}).then(function (a) {
return a ? Le(a) : null;
});return T(this, b);
};
g.Oc = function (a) {
if (!a) return B(new K("null-user"));var b = this,
c = {};c.apiKey = S(this).options.apiKey;c.authDomain = S(this).options.authDomain;c.appName = S(this).name;var d = xl(a, c, b.w, b.xa());return T(this, this.i.then(function () {
if (S(b).options.apiKey != a.l) return d.reload();
}).then(function () {
if (U(b) && a.uid == U(b).uid) return hl(U(b), a), b.Z(a);Ll(b, d);al(d);return b.Z(d);
}).then(function () {
Vl(b);
}));
};
function Ul(a, b) {
var c = {};c.apiKey = S(a).options.apiKey;c.authDomain = S(a).options.authDomain;c.appName = S(a).name;return a.V.then(function () {
return wl(c, b, a.w, a.xa());
}).then(function (b) {
if (U(a) && b.uid == U(a).uid) return hl(U(a), b), a.Z(b);Ll(a, b);al(b);return a.Z(b);
}).then(function () {
Vl(a);
});
}
function Ll(a, b) {
U(a) && (Zk(U(a), a.Ha), D(U(a), "tokenChanged", a.qa), D(U(a), "userDeleted", a.ra), D(U(a), "userInvalidated", a.sa), Yk(U(a)));b && (b.N.push(a.Ha), rc(b, "tokenChanged", a.qa), rc(b, "userDeleted", a.ra), rc(b, "userInvalidated", a.sa), 0 < a.u && Xk(b));I(a, "currentUser", b);b && (b.oa(a.ea()), Uk(b, a), Tk(b, a.G), Vk(b, a));
}g.kb = function () {
var a = this,
b = this.i.then(function () {
if (!U(a)) return A();Ll(a, null);return Il(a.h).then(function () {
Vl(a);
});
});return T(this, b);
};
function Wl(a) {
var b = zl(a.w, S(a).options.authDomain).then(function (b) {
if (a.C = b) b.ba = a.w;return tl(a.w);
});return T(a, b);
}function Ml(a) {
var b = S(a).options.authDomain,
c = Wl(a).then(function () {
return Jl(a.h, b);
}).then(function (b) {
return b ? (b.ba = a.w, a.C && (a.C.aa || null) == (b.aa || null) ? b : b.reload().then(function () {
return Hl(a.h, b).then(function () {
return b;
});
}).s(function (c) {
return "auth/network-request-failed" == c.code ? b : Il(a.h);
})) : null;
}).then(function (b) {
Ll(a, b || null);
});return T(a, c);
}
function Nl(a) {
return a.V.then(function () {
return a.fa();
}).s(function () {}).then(function () {
if (!a.l) return a.ka();
}).s(function () {}).then(function () {
if (!a.l) {
a.X = !0;var b = a.h;b.b.addListener(Cl("local"), b.a, a.ka);
}
});
}
g.Jc = function () {
var a = this;return Jl(this.h, S(this).options.authDomain).then(function (b) {
if (!a.l) {
var c;if (c = U(a) && b) {
c = U(a).uid;var d = b.uid;c = void 0 === c || null === c || "" === c || void 0 === d || null === d || "" === d ? !1 : c == d;
}if (c) return hl(U(a), b), U(a).F();if (U(a) || b) Ll(a, b), b && (al(b), b.ba = a.w), a.a && a.a.subscribe(a), Vl(a);
}
});
};g.Z = function (a) {
return Hl(this.h, a);
};g.Yb = function () {
Vl(this);this.Z(U(this));
};g.gc = function () {
this.kb();
};g.hc = function () {
this.kb();
};
function Xl(a, b) {
var c = null,
d = null;return T(a, b.then(function (b) {
c = lg(b);d = yf(b);return Ul(a, b);
}).then(function () {
return Le({ user: U(a), credential: c, additionalUserInfo: d, operationType: "signIn" });
}));
}g.ic = function (a) {
var b = this;this.addAuthTokenListener(function () {
a.next(U(b));
});
};g.jc = function (a) {
var b = this;Yl(this, function () {
a.next(U(b));
});
};g.sc = function (a, b, c) {
var d = this;this.X && firebase.Promise.resolve().then(function () {
n(a) ? a(U(d)) : n(a.next) && a.next(U(d));
});return this.Pb(a, b, c);
};
g.rc = function (a, b, c) {
var d = this;this.X && firebase.Promise.resolve().then(function () {
d.O = d.getUid();n(a) ? a(U(d)) : n(a.next) && a.next(U(d));
});return this.Qb(a, b, c);
};g.$b = function (a) {
var b = this,
c = this.i.then(function () {
return U(b) ? U(b).F(a).then(function (a) {
return { accessToken: a };
}) : null;
});return T(this, c);
};g.Jb = function (a) {
var b = this;return this.i.then(function () {
return Xl(b, O(b.b, vi, { token: a }));
}).then(function (a) {
var c = a.user;gl(c, "isAnonymous", !1);b.Z(c);return a;
});
};
g.Bc = function (a) {
Ie("firebase.auth.Auth.prototype.signInAndRetrieveDataWithCustomToken is deprecated. Please use firebase.auth.Auth.prototype.signInWithCustomToken instead.");return this.Jb(a);
};g.Cc = function (a, b) {
Ie("firebase.auth.Auth.prototype.signInAndRetrieveDataWithEmailAndPassword is deprecated. Please use firebase.auth.Auth.prototype.signInWithEmailAndPassword instead.");return this.Kb(a, b);
};g.Kb = function (a, b) {
var c = this;return this.i.then(function () {
return Xl(c, O(c.b, $f, { email: a, password: b }));
});
};
g.ub = function (a, b) {
var c = this;return this.i.then(function () {
return Xl(c, O(c.b, ri, { email: a, password: b }));
});
};g.Sb = function (a, b) {
Ie("firebase.auth.Auth.prototype.createUserAndRetrieveDataWithEmailAndPassword is deprecated. Please use firebase.auth.Auth.prototype.createUserWithEmailAndPassword instead.");return this.ub(a, b);
};g.Ec = function (a) {
Ie("firebase.auth.Auth.prototype.signInWithCredential is deprecated. Please use firebase.auth.Auth.prototype.signInAndRetrieveDataWithCredential instead.");return this.Oa(a).then(function (a) {
return a.user;
});
};
g.Oa = function (a) {
var b = this;return this.i.then(function () {
return Xl(b, a.ya(b.b));
});
};g.Pa = function () {
var a = this;return this.i.then(function () {
var b = U(a);if (b && b.isAnonymous) {
var c = Le({ providerId: null, isNewUser: !1 });return Le({ user: b, credential: null, additionalUserInfo: c, operationType: "signIn" });
}return Xl(a, a.b.Pa()).then(function (b) {
var c = b.user;gl(c, "isAnonymous", !0);a.Z(c);return b;
});
});
};
g.Dc = function () {
Ie("firebase.auth.Auth.prototype.signInAnonymouslyAndRetrieveData is deprecated. Please use firebase.auth.Auth.prototype.signInAnonymously instead.");return this.Pa();
};function S(a) {
return a.app;
}function U(a) {
return a.currentUser;
}g.getUid = function () {
return U(this) && U(this).uid || null;
};function Zl(a) {
return U(a) && U(a)._lat || null;
}
function Vl(a) {
if (a.X) {
for (var b = 0; b < a.o.length; b++) if (a.o[b]) a.o[b](Zl(a));if (a.O !== a.getUid() && a.I.length) for (a.O = a.getUid(), b = 0; b < a.I.length; b++) if (a.I[b]) a.I[b](Zl(a));
}
}g.Rb = function (a) {
this.addAuthTokenListener(a);this.u++;0 < this.u && U(this) && Xk(U(this));
};g.zc = function (a) {
var b = this;v(this.o, function (c) {
c == a && b.u--;
});0 > this.u && (this.u = 0);0 == this.u && U(this) && Yk(U(this));this.removeAuthTokenListener(a);
};
g.addAuthTokenListener = function (a) {
var b = this;this.o.push(a);T(this, this.i.then(function () {
b.l || Fa(b.o, a) && a(Zl(b));
}));
};g.removeAuthTokenListener = function (a) {
Ha(this.o, function (b) {
return b == a;
});
};function Yl(a, b) {
a.I.push(b);T(a, a.i.then(function () {
!a.l && Fa(a.I, b) && a.O !== a.getUid() && (a.O = a.getUid(), b(Zl(a)));
}));
}
g.delete = function () {
this.l = !0;for (var a = 0; a < this.N.length; a++) this.N[a].cancel("app-deleted");this.N = [];this.h && (a = this.h, a.b.removeListener(Cl("local"), a.a, this.ka));this.a && this.a.unsubscribe(this);return firebase.Promise.resolve();
};function T(a, b) {
a.N.push(b);b.ia(function () {
Ga(a.N, b);
});return b;
}g.Vb = function (a) {
Ie("firebase.auth.Auth.prototype.fetchProvidersForEmail is deprecated. Please use firebase.auth.Auth.prototype.fetchSignInMethodsForEmail instead.");return T(this, Rh(this.b, a));
};
g.Wb = function (a) {
return T(this, Th(this.b, a));
};g.kc = function (a) {
return !!dg(a);
};g.ib = function (a, b) {
var c = this;return T(this, A().then(function () {
var a = new af(b);if (!a.c) throw new K("argument-error", jf + " must be true when sending sign in link to email");return kf(a);
}).then(function (b) {
return c.b.ib(a, b);
}).then(function () {}));
};g.Rc = function (a) {
return this.Ja(a).then(function (a) {
return a.data.email;
});
};g.Xa = function (a, b) {
return T(this, this.b.Xa(a, b).then(function () {}));
};g.Ja = function (a) {
return T(this, this.b.Ja(a).then(function (a) {
return new Pe(a);
}));
};
g.Va = function (a) {
return T(this, this.b.Va(a).then(function () {}));
};g.hb = function (a, b) {
var c = this;return T(this, A().then(function () {
return "undefined" === typeof b || Za(b) ? {} : kf(new af(b));
}).then(function (b) {
return c.b.hb(a, b);
}).then(function () {}));
};g.Gc = function (a, b) {
return T(this, Ck(this, a, b, r(this.Oa, this)));
};g.Fc = function (a, b) {
var c = this;return T(this, A().then(function () {
var d = cg(a, b || Wd());return c.Oa(d);
}));
};function $l() {}$l.prototype.render = function () {};$l.prototype.reset = function () {};$l.prototype.getResponse = function () {};$l.prototype.execute = function () {};function am() {
this.a = {};this.b = 1E12;
}var bm = null;am.prototype.render = function (a, b) {
this.a[this.b.toString()] = new cm(a, b);return this.b++;
};am.prototype.reset = function (a) {
var b = dm(this, a);a = em(a);b && a && (b.delete(), delete this.a[a]);
};am.prototype.getResponse = function (a) {
return (a = dm(this, a)) ? a.getResponse() : null;
};am.prototype.execute = function (a) {
(a = dm(this, a)) && a.execute();
};function dm(a, b) {
return (b = em(b)) ? a.a[b] || null : null;
}function em(a) {
return (a = "undefined" === typeof a ? 1E12 : a) ? a.toString() : null;
}
function cm(a, b) {
this.g = !1;this.c = b;this.a = this.b = null;this.h = "invisible" !== this.c.size;this.f = Jd(a);var c = this;this.i = function () {
c.execute();
};this.h ? this.execute() : rc(this.f, "click", this.i);
}cm.prototype.getResponse = function () {
fm(this);return this.b;
};
cm.prototype.execute = function () {
fm(this);var a = this;this.a || (this.a = setTimeout(function () {
a.b = pe();var b = a.c.callback,
c = a.c["expired-callback"];if (b) try {
b(a.b);
} catch (d) {}a.a = setTimeout(function () {
a.a = null;a.b = null;if (c) try {
c();
} catch (d) {}a.h && a.execute();
}, 6E4);
}, 500));
};cm.prototype.delete = function () {
fm(this);this.g = !0;clearTimeout(this.a);this.a = null;D(this.f, "click", this.i);
};function fm(a) {
if (a.g) throw Error("reCAPTCHA mock was already deleted!");
};function gm() {}gm.prototype.g = function () {
bm || (bm = new am());return A(bm);
};gm.prototype.c = function () {};var hm = null;function im() {
this.b = k.grecaptcha ? Infinity : 0;this.f = null;this.a = "__rcb" + Math.floor(1E6 * Math.random()).toString();
}var jm = rd("https://www.google.com/recaptcha/api.js?onload=%{onload}&render=explicit&hl=%{hl}"),
km = new Ce(3E4, 6E4);
im.prototype.g = function (a) {
var b = this;return new y(function (c, d) {
var e = setTimeout(function () {
d(new K("network-request-failed"));
}, km.get());if (!k.grecaptcha || a !== b.f && !b.b) {
k[b.a] = function () {
if (k.grecaptcha) {
b.f = a;var f = k.grecaptcha.render;k.grecaptcha.render = function (a, c) {
a = f(a, c);b.b++;return a;
};clearTimeout(e);c(k.grecaptcha);
} else clearTimeout(e), d(new K("internal-error"));delete k[b.a];
};var f = vd(jm, { onload: b.a, hl: a || "" });A(sh(f)).s(function () {
clearTimeout(e);d(new K("internal-error", "Unable to load external reCAPTCHA dependencies!"));
});
} else clearTimeout(e), c(k.grecaptcha);
});
};im.prototype.c = function () {
this.b--;
};var lm = null;function mm(a, b, c, d, e, f, h) {
I(this, "type", "recaptcha");this.c = this.f = null;this.C = !1;this.l = b;this.g = null;h ? (hm || (hm = new gm()), h = hm) : (lm || (lm = new im()), h = lm);this.o = h;this.a = c || { theme: "light", type: "image" };this.h = [];if (this.a[nm]) throw new K("argument-error", "sitekey should not be provided for reCAPTCHA as one is automatically provisioned for the current project.");this.i = "invisible" === this.a[om];if (!k.document) throw new K("operation-not-supported-in-this-environment", "RecaptchaVerifier is only supported in a browser HTTP/HTTPS environment with DOM support.");
if (!Jd(b) || !this.i && Jd(b).hasChildNodes()) throw new K("argument-error", "reCAPTCHA container is either not found or already contains inner elements!");this.u = new Ah(a, f || null, e || null);this.v = d || function () {
return null;
};var m = this;this.m = [];var p = this.a[pm];this.a[pm] = function (a) {
qm(m, a);if ("function" === typeof p) p(a);else if ("string" === typeof p) {
var b = H(p, k);"function" === typeof b && b(a);
}
};var z = this.a[rm];this.a[rm] = function () {
qm(m, null);if ("function" === typeof z) z();else if ("string" === typeof z) {
var a = H(z, k);"function" === typeof a && a();
}
};
}var pm = "callback",
rm = "expired-callback",
nm = "sitekey",
om = "size";function qm(a, b) {
for (var c = 0; c < a.m.length; c++) try {
a.m[c](b);
} catch (d) {}
}function sm(a, b) {
Ha(a.m, function (a) {
return a == b;
});
}function tm(a, b) {
a.h.push(b);b.ia(function () {
Ga(a.h, b);
});return b;
}g = mm.prototype;
g.za = function () {
var a = this;return this.f ? this.f : this.f = tm(this, A().then(function () {
if (ve() && !me()) return he();throw new K("operation-not-supported-in-this-environment", "RecaptchaVerifier is only supported in a browser HTTP/HTTPS environment.");
}).then(function () {
return a.o.g(a.v());
}).then(function (b) {
a.g = b;return O(a.u, ui, {});
}).then(function (b) {
a.a[nm] = b.recaptchaSiteKey;
}).s(function (b) {
a.f = null;throw b;
}));
};
g.render = function () {
um(this);var a = this;return tm(this, this.za().then(function () {
if (null === a.c) {
var b = a.l;if (!a.i) {
var c = Jd(b);b = Md("DIV");c.appendChild(b);
}a.c = a.g.render(b, a.a);
}return a.c;
}));
};g.verify = function () {
um(this);var a = this;return tm(this, this.render().then(function (b) {
return new y(function (c) {
var d = a.g.getResponse(b);if (d) c(d);else {
var e = function (b) {
b && (sm(a, e), c(b));
};a.m.push(e);a.i && a.g.execute(a.c);
}
});
}));
};g.reset = function () {
um(this);null !== this.c && this.g.reset(this.c);
};
function um(a) {
if (a.C) throw new K("internal-error", "RecaptchaVerifier instance has been destroyed.");
}g.clear = function () {
um(this);this.C = !0;this.o.c();for (var a = 0; a < this.h.length; a++) this.h[a].cancel("RecaptchaVerifier instance has been destroyed.");if (!this.i) {
a = Jd(this.l);for (var b; b = a.firstChild;) a.removeChild(b);
}
};
function vm(a, b, c) {
var d = !1;try {
this.b = c || firebase.app();
} catch (h) {
throw new K("argument-error", "No firebase.app.App instance is currently initialized.");
}if (this.b.options && this.b.options.apiKey) c = this.b.options.apiKey;else throw new K("invalid-api-key");var e = this,
f = null;try {
f = this.b.auth().xa();
} catch (h) {}try {
d = this.b.auth().settings.appVerificationDisabledForTesting;
} catch (h) {}f = firebase.SDK_VERSION ? re(firebase.SDK_VERSION, f) : null;mm.call(this, c, a, b, function () {
try {
var a = e.b.auth().ea();
} catch (m) {
a = null;
}return a;
}, f, xi(yi), d);
}t(vm, mm);function wm(a, b, c, d) {
a: {
c = Array.prototype.slice.call(c);var e = 0;for (var f = !1, h = 0; h < b.length; h++) if (b[h].optional) f = !0;else {
if (f) throw new K("internal-error", "Argument validator encountered a required argument after an optional argument.");e++;
}f = b.length;if (c.length < e || f < c.length) d = "Expected " + (e == f ? 1 == e ? "1 argument" : e + " arguments" : e + "-" + f + " arguments") + " but got " + c.length + ".";else {
for (e = 0; e < c.length; e++) if (f = b[e].optional && void 0 === c[e], !b[e].M(c[e]) && !f) {
b = b[e];if (0 > e || e >= xm.length) throw new K("internal-error", "Argument validator received an unsupported number of arguments.");c = xm[e];d = (d ? "" : c + " argument ") + (b.name ? '"' + b.name + '" ' : "") + "must be " + b.K + ".";break a;
}d = null;
}
}if (d) throw new K("argument-error", a + " failed: " + d);
}var xm = "First Second Third Fourth Fifth Sixth Seventh Eighth Ninth".split(" ");function V(a, b) {
return { name: a || "", K: "a valid string", optional: !!b, M: l };
}function ym(a, b) {
return { name: a || "", K: "a boolean", optional: !!b, M: ba };
}
function W(a, b) {
return { name: a || "", K: "a valid object", optional: !!b, M: q };
}function zm(a, b) {
return { name: a || "", K: "a function", optional: !!b, M: n };
}function Am(a, b) {
return { name: a || "", K: "null", optional: !!b, M: ea };
}function Bm() {
return { name: "", K: "an HTML element", optional: !1, M: function (a) {
return !!(a && a instanceof Element);
} };
}function Cm() {
return { name: "auth", K: "an instance of Firebase Auth", optional: !0, M: function (a) {
return !!(a && a instanceof Kl);
} };
}
function Dm() {
return { name: "app", K: "an instance of Firebase App", optional: !0, M: function (a) {
return !!(a && a instanceof firebase.app.App);
} };
}function Em(a) {
return { name: a ? a + "Credential" : "credential", K: a ? "a valid " + a + " credential" : "a valid credential", optional: !1, M: function (b) {
if (!b) return !1;var c = !a || b.providerId === a;return !(!b.ya || !c);
} };
}
function Fm() {
return { name: "authProvider", K: "a valid Auth provider", optional: !1, M: function (a) {
return !!(a && a.providerId && a.hasOwnProperty && a.hasOwnProperty("isOAuthProvider"));
} };
}function Gm() {
return { name: "applicationVerifier", K: "an implementation of firebase.auth.ApplicationVerifier", optional: !1, M: function (a) {
return !!(a && l(a.type) && n(a.verify));
} };
}function X(a, b, c, d) {
return { name: c || "", K: a.K + " or " + b.K, optional: !!d, M: function (c) {
return a.M(c) || b.M(c);
} };
};function Y(a, b) {
for (var c in b) {
var d = b[c].name;a[d] = Hm(d, a[c], b[c].j);
}
}function Im(a, b) {
for (var c in b) {
var d = b[c].name;if (d !== c) {
var e = b[c].qb;Object.defineProperty(a, d, { get: function () {
return this[c];
}, set: function (a) {
wm(d, [e], [a], !0);this[c] = a;
}, enumerable: !0 });
}
}
}function Z(a, b, c, d) {
a[b] = Hm(b, c, d);
}
function Hm(a, b, c) {
function d() {
var a = Array.prototype.slice.call(arguments);wm(e, c, a);return b.apply(this, a);
}if (!c) return b;var e = Jm(a),
f;for (f in b) d[f] = b[f];for (f in b.prototype) d.prototype[f] = b.prototype[f];return d;
}function Jm(a) {
a = a.split(".");return a[a.length - 1];
};Y(Kl.prototype, { Va: { name: "applyActionCode", j: [V("code")] }, Ja: { name: "checkActionCode", j: [V("code")] }, Xa: { name: "confirmPasswordReset", j: [V("code"), V("newPassword")] }, ub: { name: "createUserWithEmailAndPassword", j: [V("email"), V("password")] }, Sb: { name: "createUserAndRetrieveDataWithEmailAndPassword", j: [V("email"), V("password")] }, Vb: { name: "fetchProvidersForEmail", j: [V("email")] }, Wb: { name: "fetchSignInMethodsForEmail", j: [V("email")] }, fa: { name: "getRedirectResult", j: [] }, kc: { name: "isSignInWithEmailLink", j: [V("emailLink")] },
rc: { name: "onAuthStateChanged", j: [X(W(), zm(), "nextOrObserver"), zm("opt_error", !0), zm("opt_completed", !0)] }, sc: { name: "onIdTokenChanged", j: [X(W(), zm(), "nextOrObserver"), zm("opt_error", !0), zm("opt_completed", !0)] }, hb: { name: "sendPasswordResetEmail", j: [V("email"), X(W("opt_actionCodeSettings", !0), Am(null, !0), "opt_actionCodeSettings", !0)] }, ib: { name: "sendSignInLinkToEmail", j: [V("email"), W("actionCodeSettings")] }, jb: { name: "setPersistence", j: [V("persistence")] }, Oa: { name: "signInAndRetrieveDataWithCredential",
j: [Em()] }, Pa: { name: "signInAnonymously", j: [] }, Dc: { name: "signInAnonymouslyAndRetrieveData", j: [] }, Ec: { name: "signInWithCredential", j: [Em()] }, Jb: { name: "signInWithCustomToken", j: [V("token")] }, Bc: { name: "signInAndRetrieveDataWithCustomToken", j: [V("token")] }, Kb: { name: "signInWithEmailAndPassword", j: [V("email"), V("password")] }, Fc: { name: "signInWithEmailLink", j: [V("email"), V("emailLink", !0)] }, Cc: { name: "signInAndRetrieveDataWithEmailAndPassword", j: [V("email"), V("password")] }, Gc: { name: "signInWithPhoneNumber", j: [V("phoneNumber"), Gm()] }, Hc: { name: "signInWithPopup", j: [Fm()] }, Ic: { name: "signInWithRedirect", j: [Fm()] }, Oc: { name: "updateCurrentUser", j: [X(function (a) {
return { name: "user", K: "an instance of Firebase User", optional: !!a, M: function (a) {
return !!(a && a instanceof Q);
} };
}(), Am(), "user")] }, kb: { name: "signOut", j: [] }, toJSON: { name: "toJSON", j: [V(null, !0)] }, Qc: { name: "useDeviceLanguage", j: [] }, Rc: { name: "verifyPasswordResetCode", j: [V("code")] } });Im(Kl.prototype, { lc: { name: "languageCode", qb: X(V(), Am(), "languageCode") } });Kl.Persistence = rj;
Kl.Persistence.LOCAL = "local";Kl.Persistence.SESSION = "session";Kl.Persistence.NONE = "none";
Y(Q.prototype, { "delete": { name: "delete", j: [] }, ac: { name: "getIdTokenResult", j: [ym("opt_forceRefresh", !0)] }, F: { name: "getIdToken", j: [ym("opt_forceRefresh", !0)] }, ab: { name: "linkAndRetrieveDataWithCredential", j: [Em()] }, mc: { name: "linkWithCredential", j: [Em()] }, nc: { name: "linkWithPhoneNumber", j: [V("phoneNumber"), Gm()] }, oc: { name: "linkWithPopup", j: [Fm()] }, pc: { name: "linkWithRedirect", j: [Fm()] }, cb: { name: "reauthenticateAndRetrieveDataWithCredential", j: [Em()] }, vc: { name: "reauthenticateWithCredential", j: [Em()] }, wc: { name: "reauthenticateWithPhoneNumber",
j: [V("phoneNumber"), Gm()] }, xc: { name: "reauthenticateWithPopup", j: [Fm()] }, yc: { name: "reauthenticateWithRedirect", j: [Fm()] }, reload: { name: "reload", j: [] }, gb: { name: "sendEmailVerification", j: [X(W("opt_actionCodeSettings", !0), Am(null, !0), "opt_actionCodeSettings", !0)] }, toJSON: { name: "toJSON", j: [V(null, !0)] }, Nc: { name: "unlink", j: [V("provider")] }, mb: { name: "updateEmail", j: [V("email")] }, nb: { name: "updatePassword", j: [V("password")] }, Pc: { name: "updatePhoneNumber", j: [Em("phone")] }, ob: { name: "updateProfile", j: [W("profile")] } });
Y(am.prototype, { execute: { name: "execute" }, render: { name: "render" }, reset: { name: "reset" }, getResponse: { name: "getResponse" } });Y($l.prototype, { execute: { name: "execute" }, render: { name: "render" }, reset: { name: "reset" }, getResponse: { name: "getResponse" } });Y(y.prototype, { ia: { name: "finally" }, s: { name: "catch" }, then: { name: "then" } });Im(Ak.prototype, { appVerificationDisabled: { name: "appVerificationDisabledForTesting", qb: ym("appVerificationDisabledForTesting") } });Y(Bk.prototype, { confirm: { name: "confirm", j: [V("verificationCode")] } });
Z(N, "credential", function (a, b) {
return new Yf(a, b);
}, [V("email"), V("password")]);Y(Qf.prototype, { ta: { name: "addScope", j: [V("scope")] }, Da: { name: "setCustomParameters", j: [W("customOAuthParameters")] } });Z(Qf, "credential", Rf, [X(V(), W(), "token")]);Z(N, "credentialWithLink", cg, [V("email"), V("emailLink")]);Y(Sf.prototype, { ta: { name: "addScope", j: [V("scope")] }, Da: { name: "setCustomParameters", j: [W("customOAuthParameters")] } });Z(Sf, "credential", Tf, [X(V(), W(), "token")]);
Y(Uf.prototype, { ta: { name: "addScope", j: [V("scope")] }, Da: { name: "setCustomParameters", j: [W("customOAuthParameters")] } });Z(Uf, "credential", Vf, [X(V(), X(W(), Am()), "idToken"), X(V(), Am(), "accessToken", !0)]);Y(Wf.prototype, { Da: { name: "setCustomParameters", j: [W("customOAuthParameters")] } });Z(Wf, "credential", Xf, [X(V(), W(), "token"), V("secret", !0)]);
Y(M.prototype, { ta: { name: "addScope", j: [V("scope")] }, credential: { name: "credential", j: [X(V(), Am(), "idToken", !0), X(V(), Am(), "accessToken", !0)] }, Da: { name: "setCustomParameters", j: [W("customOAuthParameters")] } });Z(ig, "credential", kg, [V("verificationId"), V("verificationCode")]);Y(ig.prototype, { Ta: { name: "verifyPhoneNumber", j: [V("phoneNumber"), Gm()] } });Y(K.prototype, { toJSON: { name: "toJSON", j: [V(null, !0)] } });Y(sg.prototype, { toJSON: { name: "toJSON", j: [V(null, !0)] } });
Y(rg.prototype, { toJSON: { name: "toJSON", j: [V(null, !0)] } });Y(vm.prototype, { clear: { name: "clear", j: [] }, render: { name: "render", j: [] }, verify: { name: "verify", j: [] } });
(function () {
if ("undefined" !== typeof firebase && firebase.INTERNAL && firebase.INTERNAL.registerService) {
var a = { Auth: Kl, Error: K };Z(a, "EmailAuthProvider", N, []);Z(a, "FacebookAuthProvider", Qf, []);Z(a, "GithubAuthProvider", Sf, []);Z(a, "GoogleAuthProvider", Uf, []);Z(a, "TwitterAuthProvider", Wf, []);Z(a, "OAuthProvider", M, [V("providerId")]);Z(a, "PhoneAuthProvider", ig, [Cm()]);Z(a, "RecaptchaVerifier", vm, [X(V(), Bm(), "recaptchaContainer"), W("recaptchaParameters", !0), Dm()]);firebase.INTERNAL.registerService("auth", function (a, c) {
a = new Kl(a);c({ INTERNAL: { getUid: r(a.getUid, a), getToken: r(a.$b, a), addAuthTokenListener: r(a.Rb, a), removeAuthTokenListener: r(a.zc, a) } });return a;
}, a, function (a, c) {
if ("create" === a) try {
c.auth();
} catch (d) {}
});firebase.INTERNAL.extendNamespace({ User: Q });
} else throw Error("Cannot find the firebase namespace; be sure to include firebase-app.js before this library.");
})();
}).call(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__("h6ac")))
/***/ }),
/***/ "SUmx":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("ggoL"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../../mode/css/css"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var pseudoClasses = { link: 1, visited: 1, active: 1, hover: 1, focus: 1,
"first-letter": 1, "first-line": 1, "first-child": 1,
before: 1, after: 1, lang: 1 };
CodeMirror.registerHelper("hint", "css", function (cm) {
var cur = cm.getCursor(),
token = cm.getTokenAt(cur);
var inner = CodeMirror.innerMode(cm.getMode(), token.state);
if (inner.mode.name != "css") return;
if (token.type == "keyword" && "!important".indexOf(token.string) == 0) return { list: ["!important"], from: CodeMirror.Pos(cur.line, token.start),
to: CodeMirror.Pos(cur.line, token.end) };
var start = token.start,
end = cur.ch,
word = token.string.slice(0, end - start);
if (/[^\w$_-]/.test(word)) {
word = "";start = end = cur.ch;
}
var spec = CodeMirror.resolveMode("text/css");
var result = [];
function add(keywords) {
for (var name in keywords) if (!word || name.lastIndexOf(word, 0) == 0) result.push(name);
}
var st = inner.state.state;
if (st == "pseudo" || token.type == "variable-3") {
add(pseudoClasses);
} else if (st == "block" || st == "maybeprop") {
add(spec.propertyKeywords);
} else if (st == "prop" || st == "parens" || st == "at" || st == "params") {
add(spec.valueKeywords);
add(spec.colorKeywords);
} else if (st == "media" || st == "media_parens") {
add(spec.mediaTypes);
add(spec.mediaFeatures);
}
if (result.length) return {
list: result,
from: CodeMirror.Pos(cur.line, start),
to: CodeMirror.Pos(cur.line, end)
};
});
});
/***/ }),
/***/ "TUpU":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setLogLevel", function() { return setLogLevel; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Logger", function() { return Logger; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "LogLevel", function() { return LogLevel; });
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* A container for all of the Logger instances
*/
var instances = [];
/**
* The JS SDK supports 5 log levels and also allows a user the ability to
* silence the logs altogether.
*
* The order is a follows:
* DEBUG < VERBOSE < INFO < WARN < ERROR
*
* All of the log types above the current log level will be captured (i.e. if
* you set the log level to `INFO`, errors will still be logged, but `DEBUG` and
* `VERBOSE` logs will not)
*/
var LogLevel;
(function (LogLevel) {
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
LogLevel[LogLevel["VERBOSE"] = 1] = "VERBOSE";
LogLevel[LogLevel["INFO"] = 2] = "INFO";
LogLevel[LogLevel["WARN"] = 3] = "WARN";
LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
LogLevel[LogLevel["SILENT"] = 5] = "SILENT";
})(LogLevel || (LogLevel = {}));
/**
* The default log level
*/
var defaultLogLevel = LogLevel.INFO;
/**
* The default log handler will forward DEBUG, VERBOSE, INFO, WARN, and ERROR
* messages on to their corresponding console counterparts (if the log method
* is supported by the current log level)
*/
var defaultLogHandler = function (instance, logType) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
if (logType < instance.logLevel) return;
var now = new Date().toISOString();
switch (logType) {
/**
* By default, `console.debug` is not displayed in the developer console (in
* chrome). To avoid forcing users to have to opt-in to these logs twice
* (i.e. once for firebase, and once in the console), we are sending `DEBUG`
* logs to the `console.log` function.
*/
case LogLevel.DEBUG:
console.log.apply(console, ["[" + now + "] " + instance.name + ":"].concat(args));
break;
case LogLevel.VERBOSE:
console.log.apply(console, ["[" + now + "] " + instance.name + ":"].concat(args));
break;
case LogLevel.INFO:
console.info.apply(console, ["[" + now + "] " + instance.name + ":"].concat(args));
break;
case LogLevel.WARN:
console.warn.apply(console, ["[" + now + "] " + instance.name + ":"].concat(args));
break;
case LogLevel.ERROR:
console.error.apply(console, ["[" + now + "] " + instance.name + ":"].concat(args));
break;
default:
throw new Error("Attempted to log a message with an invalid logType (value: " + logType + ")");
}
};
var Logger = /** @class */function () {
/**
* Gives you an instance of a Logger to capture messages according to
* Firebase's logging scheme.
*
* @param name The name that the logs will be associated with
*/
function Logger(name) {
this.name = name;
/**
* The log level of the given Logger instance.
*/
this._logLevel = defaultLogLevel;
/**
* The log handler for the Logger instance.
*/
this._logHandler = defaultLogHandler;
/**
* Capture the current instance for later use
*/
instances.push(this);
}
Object.defineProperty(Logger.prototype, "logLevel", {
get: function () {
return this._logLevel;
},
set: function (val) {
if (!(val in LogLevel)) {
throw new TypeError('Invalid value assigned to `logLevel`');
}
this._logLevel = val;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Logger.prototype, "logHandler", {
get: function () {
return this._logHandler;
},
set: function (val) {
if (typeof val !== 'function') {
throw new TypeError('Value assigned to `logHandler` must be a function');
}
this._logHandler = val;
},
enumerable: true,
configurable: true
});
/**
* The functions below are all based on the `console` interface
*/
Logger.prototype.debug = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this._logHandler.apply(this, [this, LogLevel.DEBUG].concat(args));
};
Logger.prototype.log = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this._logHandler.apply(this, [this, LogLevel.VERBOSE].concat(args));
};
Logger.prototype.info = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this._logHandler.apply(this, [this, LogLevel.INFO].concat(args));
};
Logger.prototype.warn = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this._logHandler.apply(this, [this, LogLevel.WARN].concat(args));
};
Logger.prototype.error = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this._logHandler.apply(this, [this, LogLevel.ERROR].concat(args));
};
return Logger;
}();
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function setLogLevel(level) {
instances.forEach(function (inst) {
inst.logLevel = level;
});
}
/***/ }),
/***/ "VS7n":
/***/ (function(module, exports, __webpack_require__) {
module.exports = window.fetch || (window.fetch = __webpack_require__("QAmr").default || __webpack_require__("QAmr"));
/***/ }),
/***/ "X7my":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var noOptions = {};
var nonWS = /[^\s\u00a0]/;
var Pos = CodeMirror.Pos;
function firstNonWS(str) {
var found = str.search(nonWS);
return found == -1 ? 0 : found;
}
CodeMirror.commands.toggleComment = function (cm) {
cm.toggleComment();
};
CodeMirror.defineExtension("toggleComment", function (options) {
if (!options) options = noOptions;
var cm = this;
var minLine = Infinity,
ranges = this.listSelections(),
mode = null;
for (var i = ranges.length - 1; i >= 0; i--) {
var from = ranges[i].from(),
to = ranges[i].to();
if (from.line >= minLine) continue;
if (to.line >= minLine) to = Pos(minLine, 0);
minLine = from.line;
if (mode == null) {
if (cm.uncomment(from, to, options)) mode = "un";else {
cm.lineComment(from, to, options);mode = "line";
}
} else if (mode == "un") {
cm.uncomment(from, to, options);
} else {
cm.lineComment(from, to, options);
}
}
});
// Rough heuristic to try and detect lines that are part of multi-line string
function probablyInsideString(cm, pos, line) {
return (/\bstring\b/.test(cm.getTokenTypeAt(Pos(pos.line, 0))) && !/^[\'\"\`]/.test(line)
);
}
function getMode(cm, pos) {
var mode = cm.getMode();
return mode.useInnerComments === false || !mode.innerMode ? mode : cm.getModeAt(pos);
}
CodeMirror.defineExtension("lineComment", function (from, to, options) {
if (!options) options = noOptions;
var self = this,
mode = getMode(self, from);
var firstLine = self.getLine(from.line);
if (firstLine == null || probablyInsideString(self, from, firstLine)) return;
var commentString = options.lineComment || mode.lineComment;
if (!commentString) {
if (options.blockCommentStart || mode.blockCommentStart) {
options.fullLines = true;
self.blockComment(from, to, options);
}
return;
}
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1);
var pad = options.padding == null ? " " : options.padding;
var blankLines = options.commentBlankLines || from.line == to.line;
self.operation(function () {
if (options.indent) {
var baseString = null;
for (var i = from.line; i < end; ++i) {
var line = self.getLine(i);
var whitespace = line.slice(0, firstNonWS(line));
if (baseString == null || baseString.length > whitespace.length) {
baseString = whitespace;
}
}
for (var i = from.line; i < end; ++i) {
var line = self.getLine(i),
cut = baseString.length;
if (!blankLines && !nonWS.test(line)) continue;
if (line.slice(0, cut) != baseString) cut = firstNonWS(line);
self.replaceRange(baseString + commentString + pad, Pos(i, 0), Pos(i, cut));
}
} else {
for (var i = from.line; i < end; ++i) {
if (blankLines || nonWS.test(self.getLine(i))) self.replaceRange(commentString + pad, Pos(i, 0));
}
}
});
});
CodeMirror.defineExtension("blockComment", function (from, to, options) {
if (!options) options = noOptions;
var self = this,
mode = getMode(self, from);
var startString = options.blockCommentStart || mode.blockCommentStart;
var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) {
if ((options.lineComment || mode.lineComment) && options.fullLines != false) self.lineComment(from, to, options);
return;
}
if (/\bcomment\b/.test(self.getTokenTypeAt(Pos(from.line, 0)))) return;
var end = Math.min(to.line, self.lastLine());
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end;
var pad = options.padding == null ? " " : options.padding;
if (from.line > end) return;
self.operation(function () {
if (options.fullLines != false) {
var lastLineHasText = nonWS.test(self.getLine(end));
self.replaceRange(pad + endString, Pos(end));
self.replaceRange(startString + pad, Pos(from.line, 0));
var lead = options.blockCommentLead || mode.blockCommentLead;
if (lead != null) for (var i = from.line + 1; i <= end; ++i) if (i != end || lastLineHasText) self.replaceRange(lead + pad, Pos(i, 0));
} else {
self.replaceRange(endString, to);
self.replaceRange(startString, from);
}
});
});
CodeMirror.defineExtension("uncomment", function (from, to, options) {
if (!options) options = noOptions;
var self = this,
mode = getMode(self, from);
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()),
start = Math.min(from.line, end);
// Try finding line comments
var lineString = options.lineComment || mode.lineComment,
lines = [];
var pad = options.padding == null ? " " : options.padding,
didSomething;
lineComment: {
if (!lineString) break lineComment;
for (var i = start; i <= end; ++i) {
var line = self.getLine(i);
var found = line.indexOf(lineString);
if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1;
if (found == -1 && nonWS.test(line)) break lineComment;
if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment;
lines.push(line);
}
self.operation(function () {
for (var i = start; i <= end; ++i) {
var line = lines[i - start];
var pos = line.indexOf(lineString),
endPos = pos + lineString.length;
if (pos < 0) continue;
if (line.slice(endPos, endPos + pad.length) == pad) endPos += pad.length;
didSomething = true;
self.replaceRange("", Pos(i, pos), Pos(i, endPos));
}
});
if (didSomething) return true;
}
// Try block comments
var startString = options.blockCommentStart || mode.blockCommentStart;
var endString = options.blockCommentEnd || mode.blockCommentEnd;
if (!startString || !endString) return false;
var lead = options.blockCommentLead || mode.blockCommentLead;
var startLine = self.getLine(start),
open = startLine.indexOf(startString);
if (open == -1) return false;
var endLine = end == start ? startLine : self.getLine(end);
var close = endLine.indexOf(endString, end == start ? open + startString.length : 0);
var insideStart = Pos(start, open + 1),
insideEnd = Pos(end, close + 1);
if (close == -1 || !/comment/.test(self.getTokenTypeAt(insideStart)) || !/comment/.test(self.getTokenTypeAt(insideEnd)) || self.getRange(insideStart, insideEnd, "\n").indexOf(endString) > -1) return false;
// Avoid killing block comments completely outside the selection.
// Positions of the last startString before the start of the selection, and the first endString after it.
var lastStart = startLine.lastIndexOf(startString, from.ch);
var firstEnd = lastStart == -1 ? -1 : startLine.slice(0, from.ch).indexOf(endString, lastStart + startString.length);
if (lastStart != -1 && firstEnd != -1 && firstEnd + endString.length != from.ch) return false;
// Positions of the first endString after the end of the selection, and the last startString before it.
firstEnd = endLine.indexOf(endString, to.ch);
var almostLastStart = endLine.slice(to.ch).lastIndexOf(startString, firstEnd - to.ch);
lastStart = firstEnd == -1 || almostLastStart == -1 ? -1 : to.ch + almostLastStart;
if (firstEnd != -1 && lastStart != -1 && lastStart != to.ch) return false;
self.operation(function () {
self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.length, close) == pad ? pad.length : 0)), Pos(end, close + endString.length));
var openEnd = open + startString.length;
if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd += pad.length;
self.replaceRange("", Pos(start, open), Pos(start, openEnd));
if (lead) for (var i = start + 1; i <= end; ++i) {
var line = self.getLine(i),
found = line.indexOf(lead);
if (found == -1 || nonWS.test(line.slice(0, found))) continue;
var foundEnd = found + lead.length;
if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd += pad.length;
self.replaceRange("", Pos(i, found), Pos(i, foundEnd));
}
});
return true;
});
});
/***/ }),
/***/ "Xc2M":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// A rough approximation of Sublime Text's keybindings
// Depends on addon/search/searchcursor.js and optionally addon/dialog/dialogs.js
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("29F7"), __webpack_require__("uQIK"));else if (typeof define == "function" && define.amd) // AMD
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/edit/matchbrackets"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var cmds = CodeMirror.commands;
var Pos = CodeMirror.Pos;
// This is not exactly Sublime's algorithm. I couldn't make heads or tails of that.
function findPosSubword(doc, start, dir) {
if (dir < 0 && start.ch == 0) return doc.clipPos(Pos(start.line - 1));
var line = doc.getLine(start.line);
if (dir > 0 && start.ch >= line.length) return doc.clipPos(Pos(start.line + 1, 0));
var state = "start",
type;
for (var pos = start.ch, e = dir < 0 ? 0 : line.length, i = 0; pos != e; pos += dir, i++) {
var next = line.charAt(dir < 0 ? pos - 1 : pos);
var cat = next != "_" && CodeMirror.isWordChar(next) ? "w" : "o";
if (cat == "w" && next.toUpperCase() == next) cat = "W";
if (state == "start") {
if (cat != "o") {
state = "in";type = cat;
}
} else if (state == "in") {
if (type != cat) {
if (type == "w" && cat == "W" && dir < 0) pos--;
if (type == "W" && cat == "w" && dir > 0) {
type = "w";continue;
}
break;
}
}
}
return Pos(start.line, pos);
}
function moveSubword(cm, dir) {
cm.extendSelectionsBy(function (range) {
if (cm.display.shift || cm.doc.extend || range.empty()) return findPosSubword(cm.doc, range.head, dir);else return dir < 0 ? range.from() : range.to();
});
}
cmds.goSubwordLeft = function (cm) {
moveSubword(cm, -1);
};
cmds.goSubwordRight = function (cm) {
moveSubword(cm, 1);
};
cmds.scrollLineUp = function (cm) {
var info = cm.getScrollInfo();
if (!cm.somethingSelected()) {
var visibleBottomLine = cm.lineAtHeight(info.top + info.clientHeight, "local");
if (cm.getCursor().line >= visibleBottomLine) cm.execCommand("goLineUp");
}
cm.scrollTo(null, info.top - cm.defaultTextHeight());
};
cmds.scrollLineDown = function (cm) {
var info = cm.getScrollInfo();
if (!cm.somethingSelected()) {
var visibleTopLine = cm.lineAtHeight(info.top, "local") + 1;
if (cm.getCursor().line <= visibleTopLine) cm.execCommand("goLineDown");
}
cm.scrollTo(null, info.top + cm.defaultTextHeight());
};
cmds.splitSelectionByLine = function (cm) {
var ranges = cm.listSelections(),
lineRanges = [];
for (var i = 0; i < ranges.length; i++) {
var from = ranges[i].from(),
to = ranges[i].to();
for (var line = from.line; line <= to.line; ++line) if (!(to.line > from.line && line == to.line && to.ch == 0)) lineRanges.push({ anchor: line == from.line ? from : Pos(line, 0),
head: line == to.line ? to : Pos(line) });
}
cm.setSelections(lineRanges, 0);
};
cmds.singleSelectionTop = function (cm) {
var range = cm.listSelections()[0];
cm.setSelection(range.anchor, range.head, { scroll: false });
};
cmds.selectLine = function (cm) {
var ranges = cm.listSelections(),
extended = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
extended.push({ anchor: Pos(range.from().line, 0),
head: Pos(range.to().line + 1, 0) });
}
cm.setSelections(extended);
};
function insertLine(cm, above) {
if (cm.isReadOnly()) return CodeMirror.Pass;
cm.operation(function () {
var len = cm.listSelections().length,
newSelection = [],
last = -1;
for (var i = 0; i < len; i++) {
var head = cm.listSelections()[i].head;
if (head.line <= last) continue;
var at = Pos(head.line + (above ? 0 : 1), 0);
cm.replaceRange("\n", at, null, "+insertLine");
cm.indentLine(at.line, null, true);
newSelection.push({ head: at, anchor: at });
last = head.line + 1;
}
cm.setSelections(newSelection);
});
cm.execCommand("indentAuto");
}
cmds.insertLineAfter = function (cm) {
return insertLine(cm, false);
};
cmds.insertLineBefore = function (cm) {
return insertLine(cm, true);
};
function wordAt(cm, pos) {
var start = pos.ch,
end = start,
line = cm.getLine(pos.line);
while (start && CodeMirror.isWordChar(line.charAt(start - 1))) --start;
while (end < line.length && CodeMirror.isWordChar(line.charAt(end))) ++end;
return { from: Pos(pos.line, start), to: Pos(pos.line, end), word: line.slice(start, end) };
}
cmds.selectNextOccurrence = function (cm) {
var from = cm.getCursor("from"),
to = cm.getCursor("to");
var fullWord = cm.state.sublimeFindFullWord == cm.doc.sel;
if (CodeMirror.cmpPos(from, to) == 0) {
var word = wordAt(cm, from);
if (!word.word) return;
cm.setSelection(word.from, word.to);
fullWord = true;
} else {
var text = cm.getRange(from, to);
var query = fullWord ? new RegExp("\\b" + text + "\\b") : text;
var cur = cm.getSearchCursor(query, to);
var found = cur.findNext();
if (!found) {
cur = cm.getSearchCursor(query, Pos(cm.firstLine(), 0));
found = cur.findNext();
}
if (!found || isSelectedRange(cm.listSelections(), cur.from(), cur.to())) return CodeMirror.Pass;
cm.addSelection(cur.from(), cur.to());
}
if (fullWord) cm.state.sublimeFindFullWord = cm.doc.sel;
};
function addCursorToSelection(cm, dir) {
var ranges = cm.listSelections(),
newRanges = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
var newAnchor = cm.findPosV(range.anchor, dir, "line", range.anchor.goalColumn);
var newHead = cm.findPosV(range.head, dir, "line", range.head.goalColumn);
newAnchor.goalColumn = range.anchor.goalColumn != null ? range.anchor.goalColumn : cm.cursorCoords(range.anchor, "div").left;
newHead.goalColumn = range.head.goalColumn != null ? range.head.goalColumn : cm.cursorCoords(range.head, "div").left;
var newRange = { anchor: newAnchor, head: newHead };
newRanges.push(range);
newRanges.push(newRange);
}
cm.setSelections(newRanges);
}
cmds.addCursorToPrevLine = function (cm) {
addCursorToSelection(cm, -1);
};
cmds.addCursorToNextLine = function (cm) {
addCursorToSelection(cm, 1);
};
function isSelectedRange(ranges, from, to) {
for (var i = 0; i < ranges.length; i++) if (ranges[i].from() == from && ranges[i].to() == to) return true;
return false;
}
var mirror = "(){}[]";
function selectBetweenBrackets(cm) {
var ranges = cm.listSelections(),
newRanges = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i],
pos = range.head,
opening = cm.scanForBracket(pos, -1);
if (!opening) return false;
for (;;) {
var closing = cm.scanForBracket(pos, 1);
if (!closing) return false;
if (closing.ch == mirror.charAt(mirror.indexOf(opening.ch) + 1)) {
var startPos = Pos(opening.pos.line, opening.pos.ch + 1);
if (CodeMirror.cmpPos(startPos, range.from()) == 0 && CodeMirror.cmpPos(closing.pos, range.to()) == 0) {
opening = cm.scanForBracket(opening.pos, -1);
if (!opening) return false;
} else {
newRanges.push({ anchor: startPos, head: closing.pos });
break;
}
}
pos = Pos(closing.pos.line, closing.pos.ch + 1);
}
}
cm.setSelections(newRanges);
return true;
}
cmds.selectScope = function (cm) {
selectBetweenBrackets(cm) || cm.execCommand("selectAll");
};
cmds.selectBetweenBrackets = function (cm) {
if (!selectBetweenBrackets(cm)) return CodeMirror.Pass;
};
cmds.goToBracket = function (cm) {
cm.extendSelectionsBy(function (range) {
var next = cm.scanForBracket(range.head, 1);
if (next && CodeMirror.cmpPos(next.pos, range.head) != 0) return next.pos;
var prev = cm.scanForBracket(range.head, -1);
return prev && Pos(prev.pos.line, prev.pos.ch + 1) || range.head;
});
};
cmds.swapLineUp = function (cm) {
if (cm.isReadOnly()) return CodeMirror.Pass;
var ranges = cm.listSelections(),
linesToMove = [],
at = cm.firstLine() - 1,
newSels = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i],
from = range.from().line - 1,
to = range.to().line;
newSels.push({ anchor: Pos(range.anchor.line - 1, range.anchor.ch),
head: Pos(range.head.line - 1, range.head.ch) });
if (range.to().ch == 0 && !range.empty()) --to;
if (from > at) linesToMove.push(from, to);else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
at = to;
}
cm.operation(function () {
for (var i = 0; i < linesToMove.length; i += 2) {
var from = linesToMove[i],
to = linesToMove[i + 1];
var line = cm.getLine(from);
cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
if (to > cm.lastLine()) cm.replaceRange("\n" + line, Pos(cm.lastLine()), null, "+swapLine");else cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
}
cm.setSelections(newSels);
cm.scrollIntoView();
});
};
cmds.swapLineDown = function (cm) {
if (cm.isReadOnly()) return CodeMirror.Pass;
var ranges = cm.listSelections(),
linesToMove = [],
at = cm.lastLine() + 1;
for (var i = ranges.length - 1; i >= 0; i--) {
var range = ranges[i],
from = range.to().line + 1,
to = range.from().line;
if (range.to().ch == 0 && !range.empty()) from--;
if (from < at) linesToMove.push(from, to);else if (linesToMove.length) linesToMove[linesToMove.length - 1] = to;
at = to;
}
cm.operation(function () {
for (var i = linesToMove.length - 2; i >= 0; i -= 2) {
var from = linesToMove[i],
to = linesToMove[i + 1];
var line = cm.getLine(from);
if (from == cm.lastLine()) cm.replaceRange("", Pos(from - 1), Pos(from), "+swapLine");else cm.replaceRange("", Pos(from, 0), Pos(from + 1, 0), "+swapLine");
cm.replaceRange(line + "\n", Pos(to, 0), null, "+swapLine");
}
cm.scrollIntoView();
});
};
cmds.toggleCommentIndented = function (cm) {
cm.toggleComment({ indent: true });
};
cmds.joinLines = function (cm) {
var ranges = cm.listSelections(),
joined = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i],
from = range.from();
var start = from.line,
end = range.to().line;
while (i < ranges.length - 1 && ranges[i + 1].from().line == end) end = ranges[++i].to().line;
joined.push({ start: start, end: end, anchor: !range.empty() && from });
}
cm.operation(function () {
var offset = 0,
ranges = [];
for (var i = 0; i < joined.length; i++) {
var obj = joined[i];
var anchor = obj.anchor && Pos(obj.anchor.line - offset, obj.anchor.ch),
head;
for (var line = obj.start; line <= obj.end; line++) {
var actual = line - offset;
if (line == obj.end) head = Pos(actual, cm.getLine(actual).length + 1);
if (actual < cm.lastLine()) {
cm.replaceRange(" ", Pos(actual), Pos(actual + 1, /^\s*/.exec(cm.getLine(actual + 1))[0].length));
++offset;
}
}
ranges.push({ anchor: anchor || head, head: head });
}
cm.setSelections(ranges, 0);
});
};
cmds.duplicateLine = function (cm) {
cm.operation(function () {
var rangeCount = cm.listSelections().length;
for (var i = 0; i < rangeCount; i++) {
var range = cm.listSelections()[i];
if (range.empty()) cm.replaceRange(cm.getLine(range.head.line) + "\n", Pos(range.head.line, 0));else cm.replaceRange(cm.getRange(range.from(), range.to()), range.from());
}
cm.scrollIntoView();
});
};
function sortLines(cm, caseSensitive) {
if (cm.isReadOnly()) return CodeMirror.Pass;
var ranges = cm.listSelections(),
toSort = [],
selected;
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (range.empty()) continue;
var from = range.from().line,
to = range.to().line;
while (i < ranges.length - 1 && ranges[i + 1].from().line == to) to = ranges[++i].to().line;
if (!ranges[i].to().ch) to--;
toSort.push(from, to);
}
if (toSort.length) selected = true;else toSort.push(cm.firstLine(), cm.lastLine());
cm.operation(function () {
var ranges = [];
for (var i = 0; i < toSort.length; i += 2) {
var from = toSort[i],
to = toSort[i + 1];
var start = Pos(from, 0),
end = Pos(to);
var lines = cm.getRange(start, end, false);
if (caseSensitive) lines.sort();else lines.sort(function (a, b) {
var au = a.toUpperCase(),
bu = b.toUpperCase();
if (au != bu) {
a = au;b = bu;
}
return a < b ? -1 : a == b ? 0 : 1;
});
cm.replaceRange(lines, start, end);
if (selected) ranges.push({ anchor: start, head: Pos(to + 1, 0) });
}
if (selected) cm.setSelections(ranges, 0);
});
}
cmds.sortLines = function (cm) {
sortLines(cm, true);
};
cmds.sortLinesInsensitive = function (cm) {
sortLines(cm, false);
};
cmds.nextBookmark = function (cm) {
var marks = cm.state.sublimeBookmarks;
if (marks) while (marks.length) {
var current = marks.shift();
var found = current.find();
if (found) {
marks.push(current);
return cm.setSelection(found.from, found.to);
}
}
};
cmds.prevBookmark = function (cm) {
var marks = cm.state.sublimeBookmarks;
if (marks) while (marks.length) {
marks.unshift(marks.pop());
var found = marks[marks.length - 1].find();
if (!found) marks.pop();else return cm.setSelection(found.from, found.to);
}
};
cmds.toggleBookmark = function (cm) {
var ranges = cm.listSelections();
var marks = cm.state.sublimeBookmarks || (cm.state.sublimeBookmarks = []);
for (var i = 0; i < ranges.length; i++) {
var from = ranges[i].from(),
to = ranges[i].to();
var found = ranges[i].empty() ? cm.findMarksAt(from) : cm.findMarks(from, to);
for (var j = 0; j < found.length; j++) {
if (found[j].sublimeBookmark) {
found[j].clear();
for (var k = 0; k < marks.length; k++) if (marks[k] == found[j]) marks.splice(k--, 1);
break;
}
}
if (j == found.length) marks.push(cm.markText(from, to, { sublimeBookmark: true, clearWhenEmpty: false }));
}
};
cmds.clearBookmarks = function (cm) {
var marks = cm.state.sublimeBookmarks;
if (marks) for (var i = 0; i < marks.length; i++) marks[i].clear();
marks.length = 0;
};
cmds.selectBookmarks = function (cm) {
var marks = cm.state.sublimeBookmarks,
ranges = [];
if (marks) for (var i = 0; i < marks.length; i++) {
var found = marks[i].find();
if (!found) marks.splice(i--, 0);else ranges.push({ anchor: found.from, head: found.to });
}
if (ranges.length) cm.setSelections(ranges, 0);
};
function modifyWordOrSelection(cm, mod) {
cm.operation(function () {
var ranges = cm.listSelections(),
indices = [],
replacements = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (range.empty()) {
indices.push(i);replacements.push("");
} else replacements.push(mod(cm.getRange(range.from(), range.to())));
}
cm.replaceSelections(replacements, "around", "case");
for (var i = indices.length - 1, at; i >= 0; i--) {
var range = ranges[indices[i]];
if (at && CodeMirror.cmpPos(range.head, at) > 0) continue;
var word = wordAt(cm, range.head);
at = word.from;
cm.replaceRange(mod(word.word), word.from, word.to);
}
});
}
cmds.smartBackspace = function (cm) {
if (cm.somethingSelected()) return CodeMirror.Pass;
cm.operation(function () {
var cursors = cm.listSelections();
var indentUnit = cm.getOption("indentUnit");
for (var i = cursors.length - 1; i >= 0; i--) {
var cursor = cursors[i].head;
var toStartOfLine = cm.getRange({ line: cursor.line, ch: 0 }, cursor);
var column = CodeMirror.countColumn(toStartOfLine, null, cm.getOption("tabSize"));
// Delete by one character by default
var deletePos = cm.findPosH(cursor, -1, "char", false);
if (toStartOfLine && !/\S/.test(toStartOfLine) && column % indentUnit == 0) {
var prevIndent = new Pos(cursor.line, CodeMirror.findColumn(toStartOfLine, column - indentUnit, indentUnit));
// Smart delete only if we found a valid prevIndent location
if (prevIndent.ch != cursor.ch) deletePos = prevIndent;
}
cm.replaceRange("", deletePos, cursor, "+delete");
}
});
};
cmds.delLineRight = function (cm) {
cm.operation(function () {
var ranges = cm.listSelections();
for (var i = ranges.length - 1; i >= 0; i--) cm.replaceRange("", ranges[i].anchor, Pos(ranges[i].to().line), "+delete");
cm.scrollIntoView();
});
};
cmds.upcaseAtCursor = function (cm) {
modifyWordOrSelection(cm, function (str) {
return str.toUpperCase();
});
};
cmds.downcaseAtCursor = function (cm) {
modifyWordOrSelection(cm, function (str) {
return str.toLowerCase();
});
};
cmds.setSublimeMark = function (cm) {
if (cm.state.sublimeMark) cm.state.sublimeMark.clear();
cm.state.sublimeMark = cm.setBookmark(cm.getCursor());
};
cmds.selectToSublimeMark = function (cm) {
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
if (found) cm.setSelection(cm.getCursor(), found);
};
cmds.deleteToSublimeMark = function (cm) {
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
if (found) {
var from = cm.getCursor(),
to = found;
if (CodeMirror.cmpPos(from, to) > 0) {
var tmp = to;to = from;from = tmp;
}
cm.state.sublimeKilled = cm.getRange(from, to);
cm.replaceRange("", from, to);
}
};
cmds.swapWithSublimeMark = function (cm) {
var found = cm.state.sublimeMark && cm.state.sublimeMark.find();
if (found) {
cm.state.sublimeMark.clear();
cm.state.sublimeMark = cm.setBookmark(cm.getCursor());
cm.setCursor(found);
}
};
cmds.sublimeYank = function (cm) {
if (cm.state.sublimeKilled != null) cm.replaceSelection(cm.state.sublimeKilled, null, "paste");
};
cmds.showInCenter = function (cm) {
var pos = cm.cursorCoords(null, "local");
cm.scrollTo(null, (pos.top + pos.bottom) / 2 - cm.getScrollInfo().clientHeight / 2);
};
function getTarget(cm) {
var from = cm.getCursor("from"),
to = cm.getCursor("to");
if (CodeMirror.cmpPos(from, to) == 0) {
var word = wordAt(cm, from);
if (!word.word) return;
from = word.from;
to = word.to;
}
return { from: from, to: to, query: cm.getRange(from, to), word: word };
}
function findAndGoTo(cm, forward) {
var target = getTarget(cm);
if (!target) return;
var query = target.query;
var cur = cm.getSearchCursor(query, forward ? target.to : target.from);
if (forward ? cur.findNext() : cur.findPrevious()) {
cm.setSelection(cur.from(), cur.to());
} else {
cur = cm.getSearchCursor(query, forward ? Pos(cm.firstLine(), 0) : cm.clipPos(Pos(cm.lastLine())));
if (forward ? cur.findNext() : cur.findPrevious()) cm.setSelection(cur.from(), cur.to());else if (target.word) cm.setSelection(target.from, target.to);
}
};
cmds.findUnder = function (cm) {
findAndGoTo(cm, true);
};
cmds.findUnderPrevious = function (cm) {
findAndGoTo(cm, false);
};
cmds.findAllUnder = function (cm) {
var target = getTarget(cm);
if (!target) return;
var cur = cm.getSearchCursor(target.query);
var matches = [];
var primaryIndex = -1;
while (cur.findNext()) {
matches.push({ anchor: cur.from(), head: cur.to() });
if (cur.from().line <= target.from.line && cur.from().ch <= target.from.ch) primaryIndex++;
}
cm.setSelections(matches, primaryIndex);
};
var keyMap = CodeMirror.keyMap;
keyMap.macSublime = {
"Cmd-Left": "goLineStartSmart",
"Shift-Tab": "indentLess",
"Shift-Ctrl-K": "deleteLine",
"Alt-Q": "wrapLines",
"Ctrl-Left": "goSubwordLeft",
"Ctrl-Right": "goSubwordRight",
"Ctrl-Alt-Up": "scrollLineUp",
"Ctrl-Alt-Down": "scrollLineDown",
"Cmd-L": "selectLine",
"Shift-Cmd-L": "splitSelectionByLine",
"Esc": "singleSelectionTop",
"Cmd-Enter": "insertLineAfter",
"Shift-Cmd-Enter": "insertLineBefore",
"Cmd-D": "selectNextOccurrence",
"Shift-Cmd-Space": "selectScope",
"Shift-Cmd-M": "selectBetweenBrackets",
"Cmd-M": "goToBracket",
"Cmd-Ctrl-Up": "swapLineUp",
"Cmd-Ctrl-Down": "swapLineDown",
"Cmd-/": "toggleCommentIndented",
"Cmd-J": "joinLines",
"Shift-Cmd-D": "duplicateLine",
"F9": "sortLines",
"Cmd-F9": "sortLinesInsensitive",
"F2": "nextBookmark",
"Shift-F2": "prevBookmark",
"Cmd-F2": "toggleBookmark",
"Shift-Cmd-F2": "clearBookmarks",
"Alt-F2": "selectBookmarks",
"Backspace": "smartBackspace",
"Cmd-K Cmd-K": "delLineRight",
"Cmd-K Cmd-U": "upcaseAtCursor",
"Cmd-K Cmd-L": "downcaseAtCursor",
"Cmd-K Cmd-Space": "setSublimeMark",
"Cmd-K Cmd-A": "selectToSublimeMark",
"Cmd-K Cmd-W": "deleteToSublimeMark",
"Cmd-K Cmd-X": "swapWithSublimeMark",
"Cmd-K Cmd-Y": "sublimeYank",
"Cmd-K Cmd-C": "showInCenter",
"Cmd-K Cmd-G": "clearBookmarks",
"Cmd-K Cmd-Backspace": "delLineLeft",
"Cmd-K Cmd-0": "unfoldAll",
"Cmd-K Cmd-J": "unfoldAll",
"Ctrl-Shift-Up": "addCursorToPrevLine",
"Ctrl-Shift-Down": "addCursorToNextLine",
"Cmd-F3": "findUnder",
"Shift-Cmd-F3": "findUnderPrevious",
"Alt-F3": "findAllUnder",
"Shift-Cmd-[": "fold",
"Shift-Cmd-]": "unfold",
"Cmd-I": "findIncremental",
"Shift-Cmd-I": "findIncrementalReverse",
"Cmd-H": "replace",
"F3": "findNext",
"Shift-F3": "findPrev",
"fallthrough": "macDefault"
};
CodeMirror.normalizeKeyMap(keyMap.macSublime);
keyMap.pcSublime = {
"Shift-Tab": "indentLess",
"Shift-Ctrl-K": "deleteLine",
"Alt-Q": "wrapLines",
"Ctrl-T": "transposeChars",
"Alt-Left": "goSubwordLeft",
"Alt-Right": "goSubwordRight",
"Ctrl-Up": "scrollLineUp",
"Ctrl-Down": "scrollLineDown",
"Ctrl-L": "selectLine",
"Shift-Ctrl-L": "splitSelectionByLine",
"Esc": "singleSelectionTop",
"Ctrl-Enter": "insertLineAfter",
"Shift-Ctrl-Enter": "insertLineBefore",
"Ctrl-D": "selectNextOccurrence",
"Shift-Ctrl-Space": "selectScope",
"Shift-Ctrl-M": "selectBetweenBrackets",
"Ctrl-M": "goToBracket",
"Shift-Ctrl-Up": "swapLineUp",
"Shift-Ctrl-Down": "swapLineDown",
"Ctrl-/": "toggleCommentIndented",
"Ctrl-J": "joinLines",
"Shift-Ctrl-D": "duplicateLine",
"F9": "sortLines",
"Ctrl-F9": "sortLinesInsensitive",
"F2": "nextBookmark",
"Shift-F2": "prevBookmark",
"Ctrl-F2": "toggleBookmark",
"Shift-Ctrl-F2": "clearBookmarks",
"Alt-F2": "selectBookmarks",
"Backspace": "smartBackspace",
"Ctrl-K Ctrl-K": "delLineRight",
"Ctrl-K Ctrl-U": "upcaseAtCursor",
"Ctrl-K Ctrl-L": "downcaseAtCursor",
"Ctrl-K Ctrl-Space": "setSublimeMark",
"Ctrl-K Ctrl-A": "selectToSublimeMark",
"Ctrl-K Ctrl-W": "deleteToSublimeMark",
"Ctrl-K Ctrl-X": "swapWithSublimeMark",
"Ctrl-K Ctrl-Y": "sublimeYank",
"Ctrl-K Ctrl-C": "showInCenter",
"Ctrl-K Ctrl-G": "clearBookmarks",
"Ctrl-K Ctrl-Backspace": "delLineLeft",
"Ctrl-K Ctrl-0": "unfoldAll",
"Ctrl-K Ctrl-J": "unfoldAll",
"Ctrl-Alt-Up": "addCursorToPrevLine",
"Ctrl-Alt-Down": "addCursorToNextLine",
"Ctrl-F3": "findUnder",
"Shift-Ctrl-F3": "findUnderPrevious",
"Alt-F3": "findAllUnder",
"Shift-Ctrl-[": "fold",
"Shift-Ctrl-]": "unfold",
"Ctrl-I": "findIncremental",
"Shift-Ctrl-I": "findIncrementalReverse",
"Ctrl-H": "replace",
"F3": "findNext",
"Shift-F3": "findPrev",
"fallthrough": "pcDefault"
};
CodeMirror.normalizeKeyMap(keyMap.pcSublime);
var mac = keyMap.default == keyMap.macDefault;
keyMap.sublime = mac ? keyMap.macSublime : keyMap.pcSublime;
});
/***/ }),
/***/ "ZUoI":
/***/ (function(module, exports, __webpack_require__) {
"use strict";
function _interopDefault(ex) {
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
}
__webpack_require__("wGjj");
var firebase = _interopDefault(__webpack_require__("dP58"));
/**
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = firebase;
/***/ }),
/***/ "bU21":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
CodeMirror.registerGlobalHelper("fold", "comment", function (mode) {
return mode.blockCommentStart && mode.blockCommentEnd;
}, function (cm, start) {
var mode = cm.getModeAt(start),
startToken = mode.blockCommentStart,
endToken = mode.blockCommentEnd;
if (!startToken || !endToken) return;
var line = start.line,
lineText = cm.getLine(line);
var startCh;
for (var at = start.ch, pass = 0;;) {
var found = at <= 0 ? -1 : lineText.lastIndexOf(startToken, at - 1);
if (found == -1) {
if (pass == 1) return;
pass = 1;
at = lineText.length;
continue;
}
if (pass == 1 && found < start.ch) return;
if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1))) && (found == 0 || lineText.slice(found - endToken.length, found) == endToken || !/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found))))) {
startCh = found + startToken.length;
break;
}
at = found - 1;
}
var depth = 1,
lastLine = cm.lastLine(),
end,
endCh;
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i),
pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(startToken, pos),
nextClose = text.indexOf(endToken, pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (pos == nextOpen) ++depth;else if (! --depth) {
end = i;endCh = pos;break outer;
}
++pos;
}
}
if (end == null || line == end && endCh == startCh) return;
return { from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh) };
});
});
/***/ }),
/***/ "dP58":
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, '__esModule', { value: true });
var util = __webpack_require__("58xA");
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var contains = function (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
};
var DEFAULT_ENTRY_NAME = '[DEFAULT]';
// An array to capture listeners before the true auth functions
// exist
var tokenListeners = [];
/**
* Global context object for a collection of services using
* a shared authentication state.
*/
var FirebaseAppImpl = /** @class */function () {
function FirebaseAppImpl(options, config, firebase_) {
this.firebase_ = firebase_;
this.isDeleted_ = false;
this.services_ = {};
this.name_ = config.name;
this._automaticDataCollectionEnabled = config.automaticDataCollectionEnabled || false;
this.options_ = util.deepCopy(options);
this.INTERNAL = {
getUid: function () {
return null;
},
getToken: function () {
return Promise.resolve(null);
},
addAuthTokenListener: function (callback) {
tokenListeners.push(callback);
// Make sure callback is called, asynchronously, in the absence of the auth module
setTimeout(function () {
return callback(null);
}, 0);
},
removeAuthTokenListener: function (callback) {
tokenListeners = tokenListeners.filter(function (listener) {
return listener !== callback;
});
}
};
}
Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", {
get: function () {
this.checkDestroyed_();
return this._automaticDataCollectionEnabled;
},
set: function (val) {
this.checkDestroyed_();
this._automaticDataCollectionEnabled = val;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirebaseAppImpl.prototype, "name", {
get: function () {
this.checkDestroyed_();
return this.name_;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirebaseAppImpl.prototype, "options", {
get: function () {
this.checkDestroyed_();
return this.options_;
},
enumerable: true,
configurable: true
});
FirebaseAppImpl.prototype.delete = function () {
var _this = this;
return new Promise(function (resolve) {
_this.checkDestroyed_();
resolve();
}).then(function () {
_this.firebase_.INTERNAL.removeApp(_this.name_);
var services = [];
Object.keys(_this.services_).forEach(function (serviceKey) {
Object.keys(_this.services_[serviceKey]).forEach(function (instanceKey) {
services.push(_this.services_[serviceKey][instanceKey]);
});
});
return Promise.all(services.map(function (service) {
return service.INTERNAL.delete();
}));
}).then(function () {
_this.isDeleted_ = true;
_this.services_ = {};
});
};
/**
* Return a service instance associated with this app (creating it
* on demand), identified by the passed instanceIdentifier.
*
* NOTE: Currently storage is the only one that is leveraging this
* functionality. They invoke it by calling:
*
* ```javascript
* firebase.app().storage('STORAGE BUCKET ID')
* ```
*
* The service name is passed to this already
* @internal
*/
FirebaseAppImpl.prototype._getService = function (name, instanceIdentifier) {
if (instanceIdentifier === void 0) {
instanceIdentifier = DEFAULT_ENTRY_NAME;
}
this.checkDestroyed_();
if (!this.services_[name]) {
this.services_[name] = {};
}
if (!this.services_[name][instanceIdentifier]) {
/**
* If a custom instance has been defined (i.e. not '[DEFAULT]')
* then we will pass that instance on, otherwise we pass `null`
*/
var instanceSpecifier = instanceIdentifier !== DEFAULT_ENTRY_NAME ? instanceIdentifier : undefined;
var service = this.firebase_.INTERNAL.factories[name](this, this.extendApp.bind(this), instanceSpecifier);
this.services_[name][instanceIdentifier] = service;
}
return this.services_[name][instanceIdentifier];
};
/**
* Callback function used to extend an App instance at the time
* of service instance creation.
*/
FirebaseAppImpl.prototype.extendApp = function (props) {
var _this = this;
// Copy the object onto the FirebaseAppImpl prototype
util.deepExtend(this, props);
/**
* If the app has overwritten the addAuthTokenListener stub, forward
* the active token listeners on to the true fxn.
*
* TODO: This function is required due to our current module
* structure. Once we are able to rely strictly upon a single module
* implementation, this code should be refactored and Auth should
* provide these stubs and the upgrade logic
*/
if (props.INTERNAL && props.INTERNAL.addAuthTokenListener) {
tokenListeners.forEach(function (listener) {
_this.INTERNAL.addAuthTokenListener(listener);
});
tokenListeners = [];
}
};
/**
* This function will throw an Error if the App has already been deleted -
* use before performing API actions on the App.
*/
FirebaseAppImpl.prototype.checkDestroyed_ = function () {
if (this.isDeleted_) {
error('app-deleted', { name: this.name_ });
}
};
return FirebaseAppImpl;
}();
// Prevent dead-code elimination of these methods w/o invalid property
// copying.
FirebaseAppImpl.prototype.name && FirebaseAppImpl.prototype.options || FirebaseAppImpl.prototype.delete || console.log('dc');
/**
* Return a firebase namespace object.
*
* In production, this will be called exactly once and the result
* assigned to the 'firebase' global. It may be called multiple times
* in unit tests.
*/
function createFirebaseNamespace() {
var apps_ = {};
var factories = {};
var appHooks = {};
// A namespace is a plain JavaScript Object.
var namespace = {
// Hack to prevent Babel from modifying the object returned
// as the firebase namespace.
__esModule: true,
initializeApp: initializeApp,
app: app,
apps: null,
Promise: Promise,
SDK_VERSION: '5.0.4',
INTERNAL: {
registerService: registerService,
createFirebaseNamespace: createFirebaseNamespace,
extendNamespace: extendNamespace,
createSubscribe: util.createSubscribe,
ErrorFactory: util.ErrorFactory,
removeApp: removeApp,
factories: factories,
useAsService: useAsService,
Promise: Promise,
deepExtend: util.deepExtend
}
};
// Inject a circular default export to allow Babel users who were previously
// using:
//
// import firebase from 'firebase';
// which becomes: var firebase = require('firebase').default;
//
// instead of
//
// import * as firebase from 'firebase';
// which becomes: var firebase = require('firebase');
util.patchProperty(namespace, 'default', namespace);
// firebase.apps is a read-only getter.
Object.defineProperty(namespace, 'apps', {
get: getApps
});
/**
* Called by App.delete() - but before any services associated with the App
* are deleted.
*/
function removeApp(name) {
var app = apps_[name];
callAppHooks(app, 'delete');
delete apps_[name];
}
/**
* Get the App object for a given name (or DEFAULT).
*/
function app(name) {
name = name || DEFAULT_ENTRY_NAME;
if (!contains(apps_, name)) {
error('no-app', { name: name });
}
return apps_[name];
}
util.patchProperty(app, 'App', FirebaseAppImpl);
function initializeApp(options, rawConfig) {
if (rawConfig === void 0) {
rawConfig = {};
}
if (typeof rawConfig !== 'object' || rawConfig === null) {
var name_1 = rawConfig;
rawConfig = { name: name_1 };
}
var config = rawConfig;
if (config.name === undefined) {
config.name = DEFAULT_ENTRY_NAME;
}
var name = config.name;
if (typeof name !== 'string' || !name) {
error('bad-app-name', { name: name + '' });
}
if (contains(apps_, name)) {
error('duplicate-app', { name: name });
}
var app = new FirebaseAppImpl(options, config, namespace);
apps_[name] = app;
callAppHooks(app, 'create');
return app;
}
/*
* Return an array of all the non-deleted FirebaseApps.
*/
function getApps() {
// Make a copy so caller cannot mutate the apps list.
return Object.keys(apps_).map(function (name) {
return apps_[name];
});
}
/*
* Register a Firebase Service.
*
* firebase.INTERNAL.registerService()
*
* TODO: Implement serviceProperties.
*/
function registerService(name, createService, serviceProperties, appHook, allowMultipleInstances) {
// Cannot re-register a service that already exists
if (factories[name]) {
error('duplicate-service', { name: name });
}
// Capture the service factory for later service instantiation
factories[name] = createService;
// Capture the appHook, if passed
if (appHook) {
appHooks[name] = appHook;
// Run the **new** app hook on all existing apps
getApps().forEach(function (app) {
appHook('create', app);
});
}
// The Service namespace is an accessor function ...
var serviceNamespace = function (appArg) {
if (appArg === void 0) {
appArg = app();
}
if (typeof appArg[name] !== 'function') {
// Invalid argument.
// This happens in the following case: firebase.storage('gs:/')
error('invalid-app-argument', { name: name });
}
// Forward service instance lookup to the FirebaseApp.
return appArg[name]();
};
// ... and a container for service-level properties.
if (serviceProperties !== undefined) {
util.deepExtend(serviceNamespace, serviceProperties);
}
// Monkey-patch the serviceNamespace onto the firebase namespace
namespace[name] = serviceNamespace;
// Patch the FirebaseAppImpl prototype
FirebaseAppImpl.prototype[name] = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var serviceFxn = this._getService.bind(this, name);
return serviceFxn.apply(this, allowMultipleInstances ? args : []);
};
return serviceNamespace;
}
/**
* Patch the top-level firebase namespace with additional properties.
*
* firebase.INTERNAL.extendNamespace()
*/
function extendNamespace(props) {
util.deepExtend(namespace, props);
}
function callAppHooks(app, eventName) {
Object.keys(factories).forEach(function (serviceName) {
// Ignore virtual services
var factoryName = useAsService(app, serviceName);
if (factoryName === null) {
return;
}
if (appHooks[factoryName]) {
appHooks[factoryName](eventName, app);
}
});
}
// Map the requested service to a registered service name
// (used to map auth to serverAuth service when needed).
function useAsService(app, name) {
if (name === 'serverAuth') {
return null;
}
var useService = name;
var options = app.options;
return useService;
}
return namespace;
}
function error(code, args) {
throw appErrors.create(code, args);
}
// TypeScript does not support non-string indexes!
// let errors: {[code: AppError: string} = {
var errors = {
'no-app': "No Firebase App '{$name}' has been created - " + 'call Firebase App.initializeApp()',
'bad-app-name': "Illegal App name: '{$name}",
'duplicate-app': "Firebase App named '{$name}' already exists",
'app-deleted': "Firebase App named '{$name}' already deleted",
'duplicate-service': "Firebase service named '{$name}' already registered",
'sa-not-supported': 'Initializing the Firebase SDK with a service ' + 'account is only allowed in a Node.js environment. On client ' + 'devices, you should instead initialize the SDK with an api key and ' + 'auth domain',
'invalid-app-argument': 'firebase.{$name}() takes either no argument or a ' + 'Firebase App instance.'
};
var appErrors = new util.ErrorFactory('app', 'Firebase', errors);
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var firebase = createFirebaseNamespace();
exports.firebase = firebase;
exports.default = firebase;
/***/ }),
/***/ "eA7g":
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports,'__esModule',{value:true});function _interopDefault(ex){return ex&&typeof ex==='object'&&'default'in ex?ex['default']:ex;}var firebase=_interopDefault(__webpack_require__("dP58"));var logger=__webpack_require__("TUpU");var tslib_1=__webpack_require__("vCxL");var webchannelWrapper=__webpack_require__("IIoC");/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//** The semver (www.semver.org) version of the SDK. */var SDK_VERSION=firebase.SDK_VERSION;/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var logClient=new logger.Logger('@firebase/firestore');var LogLevel;(function(LogLevel){LogLevel[LogLevel["DEBUG"]=0]="DEBUG";LogLevel[LogLevel["ERROR"]=1]="ERROR";LogLevel[LogLevel["SILENT"]=2]="SILENT";})(LogLevel||(LogLevel={}));// Helper methods are needed because variables can't be exported as read/write
function getLogLevel(){if(logClient.logLevel===logger.LogLevel.DEBUG){return LogLevel.DEBUG;}else if(logClient.logLevel===logger.LogLevel.SILENT){return LogLevel.SILENT;}else{return LogLevel.ERROR;}}function setLogLevel(newLevel){/**
* Map the new log level to the associated Firebase Log Level
*/switch(newLevel){case LogLevel.DEBUG:logClient.logLevel=logger.LogLevel.DEBUG;break;case LogLevel.ERROR:logClient.logLevel=logger.LogLevel.ERROR;break;case LogLevel.SILENT:logClient.logLevel=logger.LogLevel.SILENT;break;default:logClient.error("Firestore ("+SDK_VERSION+"): Invalid value passed to `setLogLevel`");}}function debug(tag,msg){var obj=[];for(var _i=2;_i<arguments.length;_i++){obj[_i-2]=arguments[_i];}if(logClient.logLevel<=logger.LogLevel.DEBUG){var args=obj.map(argToString);logClient.debug.apply(logClient,["Firestore ("+SDK_VERSION+") ["+tag+"]: "+msg].concat(args));}}function error(msg){var obj=[];for(var _i=1;_i<arguments.length;_i++){obj[_i-1]=arguments[_i];}if(logClient.logLevel<=logger.LogLevel.ERROR){var args=obj.map(argToString);logClient.error.apply(logClient,["Firestore ("+SDK_VERSION+"): "+msg].concat(args));}}/**
* Converts an additional log parameter to a string representation.
*/function argToString(obj){if(typeof obj==='string'){return obj;}else{var platform=PlatformSupport.getPlatform();try{return platform.formatJSON(obj);}catch(e){// Converting to JSON failed, just log the object directly
return obj;}}}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Unconditionally fails, throwing an Error with the given message.
*
* Returns any so it can be used in expressions:
* @example
* let futureVar = fail('not implemented yet');
*/function fail(failure){// Log the failure in addition to throw an exception, just in case the
// exception is swallowed.
var message="FIRESTORE ("+SDK_VERSION+") INTERNAL ASSERTION FAILED: "+failure;error(message);// NOTE: We don't use FirestoreError here because these are internal failures
// that cannot be handled by the user. (Also it would create a circular
// dependency between the error and assert modules which doesn't work.)
throw new Error(message);}/**
* Fails if the given assertion condition is false, throwing an Error with the
* given message if it did.
*/function assert(assertion,message){if(!assertion){fail(message);}}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Provides singleton helpers where setup code can inject a platform at runtime.
* setPlatform needs to be set before Firestore is used and must be set exactly
* once.
*/var PlatformSupport=/** @class */function(){function PlatformSupport(){}PlatformSupport.setPlatform=function(platform){if(PlatformSupport.platform){fail('Platform already defined');}PlatformSupport.platform=platform;};PlatformSupport.getPlatform=function(){if(!PlatformSupport.platform){fail('Platform not set');}return PlatformSupport.platform;};return PlatformSupport;}();/**
* Returns the representation of an empty "proto" byte string for the
* platform.
*/function emptyByteString(){return PlatformSupport.getPlatform().emptyByteString;}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/// TODO(mcg): Change to a string enum once we've upgraded to typescript 2.4.
// tslint:disable-next-line:variable-name Intended to look like a TS 2.4 enum
var Code={// Causes are copied from:
// https://github.com/grpc/grpc/blob/bceec94ea4fc5f0085d81235d8e1c06798dc341a/include/grpc%2B%2B/impl/codegen/status_code_enum.h
/** Not an error; returned on success. */OK:'ok',/** The operation was cancelled (typically by the caller). */CANCELLED:'cancelled',/** Unknown error or an error from a different error domain. */UNKNOWN:'unknown',/**
* Client specified an invalid argument. Note that this differs from
* FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are
* problematic regardless of the state of the system (e.g., a malformed file
* name).
*/INVALID_ARGUMENT:'invalid-argument',/**
* Deadline expired before operation could complete. For operations that
* change the state of the system, this error may be returned even if the
* operation has completed successfully. For example, a successful response
* from a server could have been delayed long enough for the deadline to
* expire.
*/DEADLINE_EXCEEDED:'deadline-exceeded',/** Some requested entity (e.g., file or directory) was not found. */NOT_FOUND:'not-found',/**
* Some entity that we attempted to create (e.g., file or directory) already
* exists.
*/ALREADY_EXISTS:'already-exists',/**
* The caller does not have permission to execute the specified operation.
* PERMISSION_DENIED must not be used for rejections caused by exhausting
* some resource (use RESOURCE_EXHAUSTED instead for those errors).
* PERMISSION_DENIED must not be used if the caller can not be identified
* (use UNAUTHENTICATED instead for those errors).
*/PERMISSION_DENIED:'permission-denied',/**
* The request does not have valid authentication credentials for the
* operation.
*/UNAUTHENTICATED:'unauthenticated',/**
* Some resource has been exhausted, perhaps a per-user quota, or perhaps the
* entire file system is out of space.
*/RESOURCE_EXHAUSTED:'resource-exhausted',/**
* Operation was rejected because the system is not in a state required for
* the operation's execution. For example, directory to be deleted may be
* non-empty, an rmdir operation is applied to a non-directory, etc.
*
* A litmus test that may help a service implementor in deciding
* between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
* (a) Use UNAVAILABLE if the client can retry just the failing call.
* (b) Use ABORTED if the client should retry at a higher-level
* (e.g., restarting a read-modify-write sequence).
* (c) Use FAILED_PRECONDITION if the client should not retry until
* the system state has been explicitly fixed. E.g., if an "rmdir"
* fails because the directory is non-empty, FAILED_PRECONDITION
* should be returned since the client should not retry unless
* they have first fixed up the directory by deleting files from it.
* (d) Use FAILED_PRECONDITION if the client performs conditional
* REST Get/Update/Delete on a resource and the resource on the
* server does not match the condition. E.g., conflicting
* read-modify-write on the same resource.
*/FAILED_PRECONDITION:'failed-precondition',/**
* The operation was aborted, typically due to a concurrency issue like
* sequencer check failures, transaction aborts, etc.
*
* See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
* and UNAVAILABLE.
*/ABORTED:'aborted',/**
* Operation was attempted past the valid range. E.g., seeking or reading
* past end of file.
*
* Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed
* if the system state changes. For example, a 32-bit file system will
* generate INVALID_ARGUMENT if asked to read at an offset that is not in the
* range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to read from
* an offset past the current file size.
*
* There is a fair bit of overlap between FAILED_PRECONDITION and
* OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error)
* when it applies so that callers who are iterating through a space can
* easily look for an OUT_OF_RANGE error to detect when they are done.
*/OUT_OF_RANGE:'out-of-range',/** Operation is not implemented or not supported/enabled in this service. */UNIMPLEMENTED:'unimplemented',/**
* Internal errors. Means some invariants expected by underlying System has
* been broken. If you see one of these errors, Something is very broken.
*/INTERNAL:'internal',/**
* The service is currently unavailable. This is a most likely a transient
* condition and may be corrected by retrying with a backoff.
*
* See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
* and UNAVAILABLE.
*/UNAVAILABLE:'unavailable',/** Unrecoverable data loss or corruption. */DATA_LOSS:'data-loss'};/**
* An error class used for Firestore-generated errors. Ideally we should be
* using FirebaseError, but integrating with it is overly arduous at the moment,
* so we define our own compatible error class (with a `name` of 'FirebaseError'
* and compatible `code` and `message` fields.)
*/var FirestoreError=/** @class */function(_super){tslib_1.__extends(FirestoreError,_super);function FirestoreError(code,message){var _this=_super.call(this,message)||this;_this.code=code;_this.message=message;_this.name='FirebaseError';// HACK: We write a toString property directly because Error is not a real
// class and so inheritance does not work correctly. We could alternatively
// do the same "back-door inheritance" trick that FirebaseError does.
_this.toString=function(){return _this.name+": [code="+_this.code+"]: "+_this.message;};return _this;}return FirestoreError;}(Error);/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Helper function to prevent instantiation through the constructor.
*
* This method creates a new constructor that throws when it's invoked.
* The prototype of that constructor is then set to the prototype of the hidden
* "class" to expose all the prototype methods and allow for instanceof
* checks.
*
* To also make all the static methods available, all properties of the
* original constructor are copied to the new constructor.
*/function makeConstructorPrivate(cls,optionalMessage){function PublicConstructor(){var error='This constructor is private.';if(optionalMessage){error+=' ';error+=optionalMessage;}throw new FirestoreError(Code.INVALID_ARGUMENT,error);}// Make sure instanceof checks work and all methods are exposed on the public
// constructor
PublicConstructor.prototype=cls.prototype;// Copy any static methods/members
for(var staticProperty in cls){if(cls.hasOwnProperty(staticProperty)){PublicConstructor[staticProperty]=cls[staticProperty];}}return PublicConstructor;}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function contains(obj,key){return Object.prototype.hasOwnProperty.call(obj,key);}/** Returns the given value if it's defined or the defaultValue otherwise. */function defaulted(value,defaultValue){return value!==undefined?value:defaultValue;}function forEachNumber(obj,fn){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){var num=Number(key);if(!isNaN(num)){fn(num,obj[key]);}}}}function forEach(obj,fn){for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){fn(key,obj[key]);}}}function isEmpty(obj){assert(obj!=null&&typeof obj==='object','isEmpty() expects object parameter.');for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){return false;}}return true;}function shallowCopy(obj){assert(obj&&typeof obj==='object','shallowCopy() expects object parameter.');var result={};for(var key in obj){if(Object.prototype.hasOwnProperty.call(obj,key)){result[key]=obj[key];}}return result;}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Validates the invocation of functionName has the exact number of arguments.
*
* Forward the magic "arguments" variable as second parameter on which the
* parameter validation is performed:
* validateExactNumberOfArgs('myFunction', arguments, 2);
*/function validateExactNumberOfArgs(functionName,args,numberOfArgs){if(args.length!==numberOfArgs){throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires "+formatPlural(numberOfArgs,'argument')+', but was called with '+formatPlural(args.length,'argument')+'.');}}/**
* Validates the invocation of functionName has at least the provided number of
* arguments (but can have many more).
*
* Forward the magic "arguments" variable as second parameter on which the
* parameter validation is performed:
* validateAtLeastNumberOfArgs('myFunction', arguments, 2);
*/function validateAtLeastNumberOfArgs(functionName,args,minNumberOfArgs){if(args.length<minNumberOfArgs){throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires at least "+formatPlural(minNumberOfArgs,'argument')+', but was called with '+formatPlural(args.length,'argument')+'.');}}/**
* Validates the invocation of functionName has number of arguments between
* the values provided.
*
* Forward the magic "arguments" variable as second parameter on which the
* parameter validation is performed:
* validateBetweenNumberOfArgs('myFunction', arguments, 2, 3);
*/function validateBetweenNumberOfArgs(functionName,args,minNumberOfArgs,maxNumberOfArgs){if(args.length<minNumberOfArgs||args.length>maxNumberOfArgs){throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires between "+minNumberOfArgs+" and "+(maxNumberOfArgs+" arguments, but was called with ")+formatPlural(args.length,'argument')+'.');}}/**
* Validates the provided argument is an array and has as least the expected
* number of elements.
*/function validateNamedArrayAtLeastNumberOfElements(functionName,value,name,minNumberOfElements){if(!(value instanceof Array)||value.length<minNumberOfElements){throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires its "+name+" argument to be an "+'array with at least '+(formatPlural(minNumberOfElements,'element')+"."));}}/**
* Validates the provided positional argument has the native JavaScript type
* using typeof checks.
*/function validateArgType(functionName,type,position,argument){validateType(functionName,type,ordinal(position)+" argument",argument);}/**
* Validates the provided argument has the native JavaScript type using
* typeof checks or is undefined.
*/function validateOptionalArgType(functionName,type,position,argument){if(argument!==undefined){validateArgType(functionName,type,position,argument);}}/**
* Validates the provided named option has the native JavaScript type using
* typeof checks.
*/function validateNamedType(functionName,type,optionName,argument){validateType(functionName,type,optionName+" option",argument);}/**
* Validates the provided named option has the native JavaScript type using
* typeof checks or is undefined.
*/function validateNamedOptionalType(functionName,type,optionName,argument){if(argument!==undefined){validateNamedType(functionName,type,optionName,argument);}}function validateArrayElements(functionName,optionName,typeDescription,argument,validator){if(!(argument instanceof Array)){throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires its "+optionName+" "+("option to be an array, but it was: "+valueDescription(argument)));}for(var i=0;i<argument.length;++i){if(!validator(argument[i])){throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires all "+optionName+" "+("elements to be "+typeDescription+", but the value at index "+i+" ")+("was: "+valueDescription(argument[i])));}}}function validateOptionalArrayElements(functionName,optionName,typeDescription,argument,validator){if(argument!==undefined){validateArrayElements(functionName,optionName,typeDescription,argument,validator);}}/**
* Validates that the provided named option equals one of the expected values.
*/function validateNamedPropertyEquals(functionName,inputName,optionName,input,expected){var expectedDescription=[];for(var _i=0,expected_1=expected;_i<expected_1.length;_i++){var val=expected_1[_i];if(val===input){return;}expectedDescription.push(valueDescription(val));}var actualDescription=valueDescription(input);throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid value "+actualDescription+" provided to function "+functionName+"() for option \""+optionName+"\". Acceptable values: "+expectedDescription.join(', '));}/**
* Validates that the provided named option equals one of the expected values or
* is undefined.
*/function validateNamedOptionalPropertyEquals(functionName,inputName,optionName,input,expected){if(input!==undefined){validateNamedPropertyEquals(functionName,inputName,optionName,input,expected);}}/** Helper to validate the type of a provided input. */function validateType(functionName,type,inputName,input){if(typeof input!==type||type==='object'&&!isPlainObject(input)){var description=valueDescription(input);throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires its "+inputName+" "+("to be of type "+type+", but it was: "+description));}}/**
* Returns true if it's a non-null object without a custom prototype
* (i.e. excludes Array, Date, etc.).
*/function isPlainObject(input){return typeof input==='object'&&input!==null&&(Object.getPrototypeOf(input)===Object.prototype||Object.getPrototypeOf(input)===null);}/** Returns a string describing the type / value of the provided input. */function valueDescription(input){if(input===undefined){return'undefined';}else if(input===null){return'null';}else if(typeof input==='string'){if(input.length>20){input=input.substring(0,20)+"...";}return JSON.stringify(input);}else if(typeof input==='number'||typeof input==='boolean'){return''+input;}else if(typeof input==='object'){if(input instanceof Array){return'an array';}else{var customObjectName=tryGetCustomObjectType(input);if(customObjectName){return"a custom "+customObjectName+" object";}else{return'an object';}}}else if(typeof input==='function'){return'a function';}else{return fail('Unknown wrong type: '+typeof input);}}/** Hacky method to try to get the constructor name for an object. */function tryGetCustomObjectType(input){if(input.constructor){var funcNameRegex=/function\s+([^\s(]+)\s*\(/;var results=funcNameRegex.exec(input.constructor.toString());if(results&&results.length>1){return results[1];}}return null;}/** Validates the provided argument is defined. */function validateDefined(functionName,position,argument){if(argument===undefined){throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires a valid "+ordinal(position)+" "+"argument, but it was undefined.");}}/**
* Validates the provided positional argument is an object, and its keys and
* values match the expected keys and types provided in optionTypes.
*/function validateOptionNames(functionName,options,optionNames){forEach(options,function(key,_){if(optionNames.indexOf(key)<0){throw new FirestoreError(Code.INVALID_ARGUMENT,"Unknown option '"+key+"' passed to function "+functionName+"(). "+'Available options: '+optionNames.join(', '));}});}/**
* Helper method to throw an error that the provided argument did not pass
* an instanceof check.
*/function invalidClassError(functionName,type,position,argument){var description=valueDescription(argument);return new FirestoreError(Code.INVALID_ARGUMENT,"Function "+functionName+"() requires its "+ordinal(position)+" "+("argument to be a "+type+", but it was: "+description));}/** Converts a number to its english word representation */function ordinal(num){switch(num){case 1:return'first';case 2:return'second';case 3:return'third';default:return num+'th';}}/**
* Formats the given word as plural conditionally given the preceding number.
*/function formatPlural(num,str){return num+" "+str+(num===1?'':'s');}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/// tslint:disable-next-line:class-as-namespace
var AutoId=/** @class */function(){function AutoId(){}AutoId.newId=function(){// Alphanumeric characters
var chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';var autoId='';for(var i=0;i<20;i++){autoId+=chars.charAt(Math.floor(Math.random()*chars.length));}assert(autoId.length===20,'Invalid auto ID: '+autoId);return autoId;};return AutoId;}();function primitiveComparator(left,right){if(left<right)return-1;if(left>right)return 1;return 0;}/** Helper to compare nullable (or undefined-able) objects using isEqual(). */function equals(left,right){if(left!==null&&left!==undefined){return!!(right&&left.isEqual(right));}else{// HACK: Explicitly cast since TypeScript's type narrowing apparently isn't
// smart enough.
return left===right;}}/** Helper to compare arrays using isEqual(). */function arrayEquals(left,right){if(left.length!==right.length){return false;}for(var i=0;i<left.length;i++){if(!left[i].isEqual(right[i])){return false;}}return true;}/**
* Returns the largest lexicographically smaller string of equal or smaller
* length. Returns an empty string if there is no such predecessor (if the input
* is empty).
*
* Strings returned from this method can be invalid UTF-16 but this is sufficent
* in use for indexeddb because that depends on lexicographical ordering but
* shouldn't be used elsewhere.
*/function immediatePredecessor(s){// We can decrement the last character in the string and be done
// unless that character is 0 (0x0000), in which case we have to erase the
// last character.
var lastIndex=s.length-1;if(s.length===0){// Special case the empty string.
return'';}else if(s.charAt(lastIndex)==='\0'){return s.substring(0,lastIndex);}else{return s.substring(0,lastIndex)+String.fromCharCode(s.charCodeAt(lastIndex)-1);}}/**
* Returns the immediate lexicographically-following string. This is useful to
* construct an inclusive range for indexeddb iterators.
*/function immediateSuccessor(s){// Return the input string, with an additional NUL byte appended.
return s+'\0';}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//** Helper function to assert Uint8Array is available at runtime. */function assertUint8ArrayAvailable(){if(typeof Uint8Array==='undefined'){throw new FirestoreError(Code.UNIMPLEMENTED,'Uint8Arrays are not available in this environment.');}}/** Helper function to assert Base64 functions are available at runtime. */function assertBase64Available(){if(!PlatformSupport.getPlatform().base64Available){throw new FirestoreError(Code.UNIMPLEMENTED,'Blobs are unavailable in Firestore in this environment.');}}/**
* Immutable class holding a blob (binary data).
* This class is directly exposed in the public API.
*
* Note that while you can't hide the constructor in JavaScript code, we are
* using the hack above to make sure no-one outside this module can call it.
*/var Blob=/** @class */function(){function Blob(binaryString){assertBase64Available();this._binaryString=binaryString;}Blob.fromBase64String=function(base64){validateExactNumberOfArgs('Blob.fromBase64String',arguments,1);validateArgType('Blob.fromBase64String','string',1,base64);assertBase64Available();try{var binaryString=PlatformSupport.getPlatform().atob(base64);return new Blob(binaryString);}catch(e){throw new FirestoreError(Code.INVALID_ARGUMENT,'Failed to construct Blob from Base64 string: '+e);}};Blob.fromUint8Array=function(array){validateExactNumberOfArgs('Blob.fromUint8Array',arguments,1);assertUint8ArrayAvailable();if(!(array instanceof Uint8Array)){throw invalidClassError('Blob.fromUint8Array','Uint8Array',1,array);}// We can't call array.map directly because it expects the return type to
// be a Uint8Array, whereas we can convert it to a regular array by invoking
// map on the Array prototype.
var binaryString=Array.prototype.map.call(array,function(char){return String.fromCharCode(char);}).join('');return new Blob(binaryString);};Blob.prototype.toBase64=function(){validateExactNumberOfArgs('Blob.toBase64',arguments,0);assertBase64Available();return PlatformSupport.getPlatform().btoa(this._binaryString);};Blob.prototype.toUint8Array=function(){validateExactNumberOfArgs('Blob.toUint8Array',arguments,0);assertUint8ArrayAvailable();var buffer=new Uint8Array(this._binaryString.length);for(var i=0;i<this._binaryString.length;i++){buffer[i]=this._binaryString.charCodeAt(i);}return buffer;};Blob.prototype.toString=function(){return'Blob(base64: '+this.toBase64()+')';};Blob.prototype.isEqual=function(other){return this._binaryString===other._binaryString;};/**
* Actually private to JS consumers of our API, so this function is prefixed
* with an underscore.
*/Blob.prototype._compareTo=function(other){return primitiveComparator(this._binaryString,other._binaryString);};return Blob;}();// Public instance that disallows construction at runtime. This constructor is
// used when exporting Blob on firebase.firestore.Blob and will be called Blob
// publicly. Internally we still use Blob which has a type checked private
// constructor. Note that Blob and PublicBlob can be used interchangeably in
// instanceof checks.
// For our internal TypeScript code PublicBlob doesn't exist as a type, and so
// we need to use Blob as type and export it too.
// tslint:disable-next-line:variable-name We're treating this as a class name.
var PublicBlob=makeConstructorPrivate(Blob,'Use Blob.fromUint8Array() or Blob.fromBase64String() instead.');/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Immutable class representing a geo point as latitude-longitude pair.
* This class is directly exposed in the public API, including its constructor.
*/var GeoPoint=/** @class */function(){function GeoPoint(latitude,longitude){validateExactNumberOfArgs('GeoPoint',arguments,2);validateArgType('GeoPoint','number',1,latitude);validateArgType('GeoPoint','number',2,longitude);if(!isFinite(latitude)||latitude<-90||latitude>90){throw new FirestoreError(Code.INVALID_ARGUMENT,'Latitude must be a number between -90 and 90, but was: '+latitude);}if(!isFinite(longitude)||longitude<-180||longitude>180){throw new FirestoreError(Code.INVALID_ARGUMENT,'Longitude must be a number between -180 and 180, but was: '+longitude);}this._lat=latitude;this._long=longitude;}Object.defineProperty(GeoPoint.prototype,"latitude",{/**
* Returns the latitude of this geo point, a number between -90 and 90.
*/get:function(){return this._lat;},enumerable:true,configurable:true});Object.defineProperty(GeoPoint.prototype,"longitude",{/**
* Returns the longitude of this geo point, a number between -180 and 180.
*/get:function(){return this._long;},enumerable:true,configurable:true});GeoPoint.prototype.isEqual=function(other){return this._lat===other._lat&&this._long===other._long;};/**
* Actually private to JS consumers of our API, so this function is prefixed
* with an underscore.
*/GeoPoint.prototype._compareTo=function(other){return primitiveComparator(this._lat,other._lat)||primitiveComparator(this._long,other._long);};return GeoPoint;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var Timestamp=/** @class */function(){function Timestamp(seconds,nanoseconds){this.seconds=seconds;this.nanoseconds=nanoseconds;if(nanoseconds<0){throw new FirestoreError(Code.INVALID_ARGUMENT,'Timestamp nanoseconds out of range: '+nanoseconds);}if(nanoseconds>=1e9){throw new FirestoreError(Code.INVALID_ARGUMENT,'Timestamp nanoseconds out of range: '+nanoseconds);}// Midnight at the beginning of 1/1/1 is the earliest Firestore supports.
if(seconds<-62135596800){throw new FirestoreError(Code.INVALID_ARGUMENT,'Timestamp seconds out of range: '+seconds);}// This will break in the year 10,000.
if(seconds>=253402300800){throw new FirestoreError(Code.INVALID_ARGUMENT,'Timestamp seconds out of range: '+seconds);}}Timestamp.now=function(){return Timestamp.fromMillis(Date.now());};Timestamp.fromDate=function(date){return Timestamp.fromMillis(date.getTime());};Timestamp.fromMillis=function(milliseconds){var seconds=Math.floor(milliseconds/1000);var nanos=(milliseconds-seconds*1000)*1e6;return new Timestamp(seconds,nanos);};Timestamp.prototype.toDate=function(){return new Date(this.toMillis());};Timestamp.prototype.toMillis=function(){return this.seconds*1000+this.nanoseconds/1e6;};Timestamp.prototype._compareTo=function(other){if(this.seconds===other.seconds){return primitiveComparator(this.nanoseconds,other.nanoseconds);}return primitiveComparator(this.seconds,other.seconds);};Timestamp.prototype.isEqual=function(other){return other.seconds===this.seconds&&other.nanoseconds===this.nanoseconds;};Timestamp.prototype.toString=function(){return'Timestamp(seconds='+this.seconds+', nanoseconds='+this.nanoseconds+')';};return Timestamp;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var DatabaseInfo=/** @class */function(){/**
* Constructs a DatabaseInfo using the provided host, databaseId and
* persistenceKey.
*
* @param databaseId The database to use.
* @param persistenceKey A unique identifier for this Firestore's local
* storage (used in conjunction with the databaseId).
* @param host The Firestore backend host to connect to.
* @param ssl Whether to use SSL when connecting.
*/function DatabaseInfo(databaseId,persistenceKey,host,ssl){this.databaseId=databaseId;this.persistenceKey=persistenceKey;this.host=host;this.ssl=ssl;}return DatabaseInfo;}();/** The default database name for a project. */var DEFAULT_DATABASE_NAME='(default)';/** Represents the database ID a Firestore client is associated with. */var DatabaseId=/** @class */function(){function DatabaseId(projectId,database){this.projectId=projectId;this.database=database?database:DEFAULT_DATABASE_NAME;}Object.defineProperty(DatabaseId.prototype,"isDefaultDatabase",{get:function(){return this.database===DEFAULT_DATABASE_NAME;},enumerable:true,configurable:true});DatabaseId.prototype.isEqual=function(other){return other instanceof DatabaseId&&other.projectId===this.projectId&&other.database===this.database;};DatabaseId.prototype.compareTo=function(other){return primitiveComparator(this.projectId,other.projectId)||primitiveComparator(this.database,other.database);};return DatabaseId;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var DOCUMENT_KEY_NAME='__name__';/**
* Path represents an ordered sequence of string segments.
*/var Path=/** @class */function(){function Path(segments,offset,length){this.init(segments,offset,length);}/**
* An initialization method that can be called from outside the constructor.
* We need this so that we can have a non-static construct method that returns
* the polymorphic `this` type.
*/Path.prototype.init=function(segments,offset,length){if(offset===undefined){offset=0;}else if(offset>segments.length){fail('offset '+offset+' out of range '+segments.length);}if(length===undefined){length=segments.length-offset;}else if(length>segments.length-offset){fail('length '+length+' out of range '+(segments.length-offset));}this.segments=segments;this.offset=offset;this.len=length;};/**
* Constructs a new instance of Path using the same concrete type as `this`.
* We need this instead of using the normal constructor, because polymorphic
* `this` doesn't work on static methods.
*/Path.prototype.construct=function(segments,offset,length){var path=Object.create(Object.getPrototypeOf(this));path.init(segments,offset,length);return path;};Object.defineProperty(Path.prototype,"length",{get:function(){return this.len;},enumerable:true,configurable:true});Path.prototype.isEqual=function(other){return Path.comparator(this,other)===0;};Path.prototype.child=function(nameOrPath){var segments=this.segments.slice(this.offset,this.limit());if(nameOrPath instanceof Path){nameOrPath.forEach(function(segment){segments.push(segment);});}else if(typeof nameOrPath==='string'){segments.push(nameOrPath);}else{fail('Unknown parameter type for Path.child(): '+nameOrPath);}return this.construct(segments);};/** The index of one past the last segment of the path. */Path.prototype.limit=function(){return this.offset+this.length;};Path.prototype.popFirst=function(size){size=size===undefined?1:size;assert(this.length>=size,"Can't call popFirst() with less segments");return this.construct(this.segments,this.offset+size,this.length-size);};Path.prototype.popLast=function(){assert(!this.isEmpty(),"Can't call popLast() on empty path");return this.construct(this.segments,this.offset,this.length-1);};Path.prototype.firstSegment=function(){assert(!this.isEmpty(),"Can't call firstSegment() on empty path");return this.segments[this.offset];};Path.prototype.lastSegment=function(){assert(!this.isEmpty(),"Can't call lastSegment() on empty path");return this.segments[this.limit()-1];};Path.prototype.get=function(index){assert(index<this.length,'Index out of range');return this.segments[this.offset+index];};Path.prototype.isEmpty=function(){return this.length===0;};Path.prototype.isPrefixOf=function(other){if(other.length<this.length){return false;}for(var i=0;i<this.length;i++){if(this.get(i)!==other.get(i)){return false;}}return true;};Path.prototype.forEach=function(fn){for(var i=this.offset,end=this.limit();i<end;i++){fn(this.segments[i]);}};Path.prototype.toArray=function(){return this.segments.slice(this.offset,this.limit());};Path.comparator=function(p1,p2){var len=Math.min(p1.length,p2.length);for(var i=0;i<len;i++){var left=p1.get(i);var right=p2.get(i);if(left<right)return-1;if(left>right)return 1;}if(p1.length<p2.length)return-1;if(p1.length>p2.length)return 1;return 0;};return Path;}();/**
* A slash-separated path for navigating resources (documents and collections)
* within Firestore.
*/var ResourcePath=/** @class */function(_super){tslib_1.__extends(ResourcePath,_super);function ResourcePath(){return _super!==null&&_super.apply(this,arguments)||this;}ResourcePath.prototype.canonicalString=function(){// NOTE: The client is ignorant of any path segments containing escape
// sequences (e.g. __id123__) and just passes them through raw (they exist
// for legacy reasons and should not be used frequently).
return this.toArray().join('/');};ResourcePath.prototype.toString=function(){return this.canonicalString();};/**
* Creates a resource path from the given slash-delimited string.
*/ResourcePath.fromString=function(path){// NOTE: The client is ignorant of any path segments containing escape
// sequences (e.g. __id123__) and just passes them through raw (they exist
// for legacy reasons and should not be used frequently).
if(path.indexOf('//')>=0){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid path ("+path+"). Paths must not contain // in them.");}// We may still have an empty segment at the beginning or end if they had a
// leading or trailing slash (which we allow).
var segments=path.split('/').filter(function(segment){return segment.length>0;});return new ResourcePath(segments);};ResourcePath.EMPTY_PATH=new ResourcePath([]);return ResourcePath;}(Path);var identifierRegExp=/^[_a-zA-Z][_a-zA-Z0-9]*$/;/** A dot-separated path for navigating sub-objects within a document. */var FieldPath=/** @class */function(_super){tslib_1.__extends(FieldPath,_super);function FieldPath(){return _super!==null&&_super.apply(this,arguments)||this;}/**
* Returns true if the string could be used as a segment in a field path
* without escaping.
*/FieldPath.isValidIdentifier=function(segment){return identifierRegExp.test(segment);};FieldPath.prototype.canonicalString=function(){return this.toArray().map(function(str){str=str.replace('\\','\\\\').replace('`','\\`');if(!FieldPath.isValidIdentifier(str)){str='`'+str+'`';}return str;}).join('.');};FieldPath.prototype.toString=function(){return this.canonicalString();};/**
* Returns true if this field references the key of a document.
*/FieldPath.prototype.isKeyField=function(){return this.length===1&&this.get(0)===DOCUMENT_KEY_NAME;};/**
* The field designating the key of a document.
*/FieldPath.keyField=function(){return new FieldPath([DOCUMENT_KEY_NAME]);};/**
* Parses a field string from the given server-formatted string.
*
* - Splitting the empty string is not allowed (for now at least).
* - Empty segments within the string (e.g. if there are two consecutive
* separators) are not allowed.
*
* TODO(b/37244157): we should make this more strict. Right now, it allows
* non-identifier path components, even if they aren't escaped.
*/FieldPath.fromServerFormat=function(path){var segments=[];var current='';var i=0;var addCurrentSegment=function(){if(current.length===0){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid field path ("+path+"). Paths must not be empty, begin "+"with '.', end with '.', or contain '..'");}segments.push(current);current='';};var inBackticks=false;while(i<path.length){var c=path[i];if(c==='\\'){if(i+1===path.length){throw new FirestoreError(Code.INVALID_ARGUMENT,'Path has trailing escape character: '+path);}var next=path[i+1];if(!(next==='\\'||next==='.'||next==='`')){throw new FirestoreError(Code.INVALID_ARGUMENT,'Path has invalid escape sequence: '+path);}current+=next;i+=2;}else if(c==='`'){inBackticks=!inBackticks;i++;}else if(c==='.'&&!inBackticks){addCurrentSegment();i++;}else{current+=c;i++;}}addCurrentSegment();if(inBackticks){throw new FirestoreError(Code.INVALID_ARGUMENT,'Unterminated ` in path: '+path);}return new FieldPath(segments);};FieldPath.EMPTY_PATH=new FieldPath([]);return FieldPath;}(Path);/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var DocumentKey=/** @class */function(){function DocumentKey(path){this.path=path;assert(DocumentKey.isDocumentKey(path),'Invalid DocumentKey with an odd number of segments: '+path.toArray().join('/'));}DocumentKey.prototype.isEqual=function(other){return other!==null&&ResourcePath.comparator(this.path,other.path)===0;};DocumentKey.prototype.toString=function(){return this.path.toString();};DocumentKey.comparator=function(k1,k2){return ResourcePath.comparator(k1.path,k2.path);};DocumentKey.isDocumentKey=function(path){return path.length%2===0;};/**
* Creates and returns a new document key with the given segments.
*
* @param path The segments of the path to the document
* @return A new instance of DocumentKey
*/DocumentKey.fromSegments=function(segments){return new DocumentKey(new ResourcePath(segments.slice()));};/**
* Creates and returns a new document key using '/' to split the string into
* segments.
*
* @param path The slash-separated path string to the document
* @return A new instance of DocumentKey
*/DocumentKey.fromPathString=function(path){return new DocumentKey(ResourcePath.fromString(path));};DocumentKey.EMPTY=new DocumentKey(new ResourcePath([]));return DocumentKey;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var Document=/** @class */function(){function Document(key,version,data,options){this.key=key;this.version=version;this.data=data;this.hasLocalMutations=options.hasLocalMutations;}Document.prototype.field=function(path){return this.data.field(path);};Document.prototype.fieldValue=function(path){var field=this.field(path);return field?field.value():undefined;};Document.prototype.value=function(){return this.data.value();};Document.prototype.isEqual=function(other){return other instanceof Document&&this.key.isEqual(other.key)&&this.version.isEqual(other.version)&&this.data.isEqual(other.data)&&this.hasLocalMutations===other.hasLocalMutations;};Document.prototype.toString=function(){return"Document("+this.key+", "+this.version+", "+this.data.toString()+", "+("{hasLocalMutations: "+this.hasLocalMutations+"})");};Document.compareByKey=function(d1,d2){return DocumentKey.comparator(d1.key,d2.key);};Document.compareByField=function(field,d1,d2){var v1=d1.field(field);var v2=d2.field(field);if(v1!==undefined&&v2!==undefined){return v1.compareTo(v2);}else{return fail("Trying to compare documents on fields that don't exist");}};return Document;}();/**
* A class representing a deleted document.
* Version is set to 0 if we don't point to any specific time, otherwise it
* denotes time we know it didn't exist at.
*/var NoDocument=/** @class */function(){function NoDocument(key,version){this.key=key;this.version=version;}NoDocument.prototype.toString=function(){return"NoDocument("+this.key+", "+this.version+")";};NoDocument.prototype.isEqual=function(other){return other&&other.version.isEqual(this.version)&&other.key.isEqual(this.key);};NoDocument.compareByKey=function(d1,d2){return DocumentKey.comparator(d1.key,d2.key);};return NoDocument;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/// An immutable sorted map implementation, based on a Left-leaning Red-Black
// tree.
var SortedMap=/** @class */function(){function SortedMap(comparator,root){this.comparator=comparator;this.root=root?root:LLRBNode.EMPTY;}// Returns a copy of the map, with the specified key/value added or replaced.
SortedMap.prototype.insert=function(key,value){return new SortedMap(this.comparator,this.root.insert(key,value,this.comparator).copy(null,null,LLRBNode.BLACK,null,null));};// Returns a copy of the map, with the specified key removed.
SortedMap.prototype.remove=function(key){return new SortedMap(this.comparator,this.root.remove(key,this.comparator).copy(null,null,LLRBNode.BLACK,null,null));};// Returns the value of the node with the given key, or null.
SortedMap.prototype.get=function(key){var node=this.root;while(!node.isEmpty()){var cmp=this.comparator(key,node.key);if(cmp===0){return node.value;}else if(cmp<0){node=node.left;}else if(cmp>0){node=node.right;}}return null;};// Returns the index of the element in this sorted map, or -1 if it doesn't
// exist.
SortedMap.prototype.indexOf=function(key){// Number of nodes that were pruned when descending right
var prunedNodes=0;var node=this.root;while(!node.isEmpty()){var cmp=this.comparator(key,node.key);if(cmp===0){return prunedNodes+node.left.size;}else if(cmp<0){node=node.left;}else{// Count all nodes left of the node plus the node itself
prunedNodes+=node.left.size+1;node=node.right;}}// Node not found
return-1;};SortedMap.prototype.isEmpty=function(){return this.root.isEmpty();};Object.defineProperty(SortedMap.prototype,"size",{// Returns the total number of nodes in the map.
get:function(){return this.root.size;},enumerable:true,configurable:true});// Returns the minimum key in the map.
SortedMap.prototype.minKey=function(){return this.root.minKey();};// Returns the maximum key in the map.
SortedMap.prototype.maxKey=function(){return this.root.maxKey();};// Traverses the map in key order and calls the specified action function
// for each key/value pair. If action returns true, traversal is aborted.
// Returns the first truthy value returned by action, or the last falsey
// value returned by action.
SortedMap.prototype.inorderTraversal=function(action){return this.root.inorderTraversal(action);};SortedMap.prototype.forEach=function(fn){this.inorderTraversal(function(k,v){fn(k,v);return false;});};// Traverses the map in reverse key order and calls the specified action
// function for each key/value pair. If action returns true, traversal is
// aborted.
// Returns the first truthy value returned by action, or the last falsey
// value returned by action.
SortedMap.prototype.reverseTraversal=function(action){return this.root.reverseTraversal(action);};// Returns an iterator over the SortedMap.
SortedMap.prototype.getIterator=function(){return new SortedMapIterator(this.root,null,this.comparator,false);};SortedMap.prototype.getIteratorFrom=function(key){return new SortedMapIterator(this.root,key,this.comparator,false);};SortedMap.prototype.getReverseIterator=function(){return new SortedMapIterator(this.root,null,this.comparator,true);};SortedMap.prototype.getReverseIteratorFrom=function(key){return new SortedMapIterator(this.root,key,this.comparator,true);};return SortedMap;}();// end SortedMap
// An iterator over an LLRBNode.
var SortedMapIterator=/** @class */function(){function SortedMapIterator(node,startKey,comparator,isReverse){this.isReverse=isReverse;this.nodeStack=[];var cmp=1;while(!node.isEmpty()){cmp=startKey?comparator(node.key,startKey):1;// flip the comparison if we're going in reverse
if(isReverse)cmp*=-1;if(cmp<0){// This node is less than our start key. ignore it
if(this.isReverse){node=node.left;}else{node=node.right;}}else if(cmp===0){// This node is exactly equal to our start key. Push it on the stack,
// but stop iterating;
this.nodeStack.push(node);break;}else{// This node is greater than our start key, add it to the stack and move
// to the next one
this.nodeStack.push(node);if(this.isReverse){node=node.right;}else{node=node.left;}}}}SortedMapIterator.prototype.getNext=function(){assert(this.nodeStack.length>0,'getNext() called on iterator when hasNext() is false.');var node=this.nodeStack.pop();var result={key:node.key,value:node.value};if(this.isReverse){node=node.left;while(!node.isEmpty()){this.nodeStack.push(node);node=node.right;}}else{node=node.right;while(!node.isEmpty()){this.nodeStack.push(node);node=node.left;}}return result;};SortedMapIterator.prototype.hasNext=function(){return this.nodeStack.length>0;};SortedMapIterator.prototype.peek=function(){if(this.nodeStack.length===0)return null;var node=this.nodeStack[this.nodeStack.length-1];return{key:node.key,value:node.value};};return SortedMapIterator;}();// end SortedMapIterator
// Represents a node in a Left-leaning Red-Black tree.
var LLRBNode=/** @class */function(){function LLRBNode(key,value,color,left,right){this.key=key;this.value=value;this.color=color!=null?color:LLRBNode.RED;this.left=left!=null?left:LLRBNode.EMPTY;this.right=right!=null?right:LLRBNode.EMPTY;this.size=this.left.size+1+this.right.size;}// Returns a copy of the current node, optionally replacing pieces of it.
LLRBNode.prototype.copy=function(key,value,color,left,right){return new LLRBNode(key!=null?key:this.key,value!=null?value:this.value,color!=null?color:this.color,left!=null?left:this.left,right!=null?right:this.right);};LLRBNode.prototype.isEmpty=function(){return false;};// Traverses the tree in key order and calls the specified action function
// for each node. If action returns true, traversal is aborted.
// Returns the first truthy value returned by action, or the last falsey
// value returned by action.
LLRBNode.prototype.inorderTraversal=function(action){return this.left.inorderTraversal(action)||action(this.key,this.value)||this.right.inorderTraversal(action);};// Traverses the tree in reverse key order and calls the specified action
// function for each node. If action returns true, traversal is aborted.
// Returns the first truthy value returned by action, or the last falsey
// value returned by action.
LLRBNode.prototype.reverseTraversal=function(action){return this.right.reverseTraversal(action)||action(this.key,this.value)||this.left.reverseTraversal(action);};// Returns the minimum node in the tree.
LLRBNode.prototype.min=function(){if(this.left.isEmpty()){return this;}else{return this.left.min();}};// Returns the maximum key in the tree.
LLRBNode.prototype.minKey=function(){return this.min().key;};// Returns the maximum key in the tree.
LLRBNode.prototype.maxKey=function(){if(this.right.isEmpty()){return this.key;}else{return this.right.maxKey();}};// Returns new tree, with the key/value added.
LLRBNode.prototype.insert=function(key,value,comparator){var n=this;var cmp=comparator(key,n.key);if(cmp<0){n=n.copy(null,null,null,n.left.insert(key,value,comparator),null);}else if(cmp===0){n=n.copy(null,value,null,null,null);}else{n=n.copy(null,null,null,null,n.right.insert(key,value,comparator));}return n.fixUp();};LLRBNode.prototype.removeMin=function(){if(this.left.isEmpty()){return LLRBNode.EMPTY;}var n=this;if(!n.left.isRed()&&!n.left.left.isRed())n=n.moveRedLeft();n=n.copy(null,null,null,n.left.removeMin(),null);return n.fixUp();};// Returns new tree, with the specified item removed.
LLRBNode.prototype.remove=function(key,comparator){var smallest;var n=this;if(comparator(key,n.key)<0){if(!n.left.isEmpty()&&!n.left.isRed()&&!n.left.left.isRed()){n=n.moveRedLeft();}n=n.copy(null,null,null,n.left.remove(key,comparator),null);}else{if(n.left.isRed())n=n.rotateRight();if(!n.right.isEmpty()&&!n.right.isRed()&&!n.right.left.isRed()){n=n.moveRedRight();}if(comparator(key,n.key)===0){if(n.right.isEmpty()){return LLRBNode.EMPTY;}else{smallest=n.right.min();n=n.copy(smallest.key,smallest.value,null,null,n.right.removeMin());}}n=n.copy(null,null,null,null,n.right.remove(key,comparator));}return n.fixUp();};LLRBNode.prototype.isRed=function(){return this.color;};// Returns new tree after performing any needed rotations.
LLRBNode.prototype.fixUp=function(){var n=this;if(n.right.isRed()&&!n.left.isRed())n=n.rotateLeft();if(n.left.isRed()&&n.left.left.isRed())n=n.rotateRight();if(n.left.isRed()&&n.right.isRed())n=n.colorFlip();return n;};LLRBNode.prototype.moveRedLeft=function(){var n=this.colorFlip();if(n.right.left.isRed()){n=n.copy(null,null,null,null,n.right.rotateRight());n=n.rotateLeft();n=n.colorFlip();}return n;};LLRBNode.prototype.moveRedRight=function(){var n=this.colorFlip();if(n.left.left.isRed()){n=n.rotateRight();n=n.colorFlip();}return n;};LLRBNode.prototype.rotateLeft=function(){var nl=this.copy(null,null,LLRBNode.RED,null,this.right.left);return this.right.copy(null,null,this.color,nl,null);};LLRBNode.prototype.rotateRight=function(){var nr=this.copy(null,null,LLRBNode.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,nr);};LLRBNode.prototype.colorFlip=function(){var left=this.left.copy(null,null,!this.left.color,null,null);var right=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,left,right);};// For testing.
LLRBNode.prototype.checkMaxDepth=function(){var blackDepth=this.check();if(Math.pow(2.0,blackDepth)<=this.size+1){return true;}else{return false;}};// In a balanced RB tree, the black-depth (number of black nodes) from root to
// leaves is equal on both sides. This function verifies that or asserts.
LLRBNode.prototype.check=function(){if(this.isRed()&&this.left.isRed()){throw fail('Red node has red child('+this.key+','+this.value+')');}if(this.right.isRed()){throw fail('Right child of ('+this.key+','+this.value+') is red');}var blackDepth=this.left.check();if(blackDepth!==this.right.check()){throw fail('Black depths differ');}else{return blackDepth+(this.isRed()?0:1);}};// tslint:disable-next-line:no-any Empty node is shared between all LLRB trees.
LLRBNode.EMPTY=null;LLRBNode.RED=true;LLRBNode.BLACK=false;return LLRBNode;}();// end LLRBNode
// Represents an empty node (a leaf node in the Red-Black Tree).
var LLRBEmptyNode=/** @class */function(){function LLRBEmptyNode(){this.size=0;}// Returns a copy of the current node.
LLRBEmptyNode.prototype.copy=function(key,value,color,left,right){return this;};// Returns a copy of the tree, with the specified key/value added.
LLRBEmptyNode.prototype.insert=function(key,value,comparator){return new LLRBNode(key,value);};// Returns a copy of the tree, with the specified key removed.
LLRBEmptyNode.prototype.remove=function(key,comparator){return this;};LLRBEmptyNode.prototype.isEmpty=function(){return true;};LLRBEmptyNode.prototype.inorderTraversal=function(action){return false;};LLRBEmptyNode.prototype.reverseTraversal=function(action){return false;};LLRBEmptyNode.prototype.minKey=function(){return null;};LLRBEmptyNode.prototype.maxKey=function(){return null;};LLRBEmptyNode.prototype.isRed=function(){return false;};// For testing.
LLRBEmptyNode.prototype.checkMaxDepth=function(){return true;};LLRBEmptyNode.prototype.check=function(){return 0;};return LLRBEmptyNode;}();// end LLRBEmptyNode
LLRBNode.EMPTY=new LLRBEmptyNode();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var TypeOrder;(function(TypeOrder){// This order is defined by the backend.
TypeOrder[TypeOrder["NullValue"]=0]="NullValue";TypeOrder[TypeOrder["BooleanValue"]=1]="BooleanValue";TypeOrder[TypeOrder["NumberValue"]=2]="NumberValue";TypeOrder[TypeOrder["TimestampValue"]=3]="TimestampValue";TypeOrder[TypeOrder["StringValue"]=4]="StringValue";TypeOrder[TypeOrder["BlobValue"]=5]="BlobValue";TypeOrder[TypeOrder["RefValue"]=6]="RefValue";TypeOrder[TypeOrder["GeoPointValue"]=7]="GeoPointValue";TypeOrder[TypeOrder["ArrayValue"]=8]="ArrayValue";TypeOrder[TypeOrder["ObjectValue"]=9]="ObjectValue";})(TypeOrder||(TypeOrder={}));/** Defines the return value for pending server timestamps. */var ServerTimestampBehavior;(function(ServerTimestampBehavior){ServerTimestampBehavior[ServerTimestampBehavior["Default"]=0]="Default";ServerTimestampBehavior[ServerTimestampBehavior["Estimate"]=1]="Estimate";ServerTimestampBehavior[ServerTimestampBehavior["Previous"]=2]="Previous";})(ServerTimestampBehavior||(ServerTimestampBehavior={}));/** Holds properties that define field value deserialization options. */var FieldValueOptions=/** @class */function(){function FieldValueOptions(serverTimestampBehavior,timestampsInSnapshots){this.serverTimestampBehavior=serverTimestampBehavior;this.timestampsInSnapshots=timestampsInSnapshots;}FieldValueOptions.fromSnapshotOptions=function(options,timestampsInSnapshots){switch(options.serverTimestamps){case'estimate':return new FieldValueOptions(ServerTimestampBehavior.Estimate,timestampsInSnapshots);case'previous':return new FieldValueOptions(ServerTimestampBehavior.Previous,timestampsInSnapshots);case'none':// Fall-through intended.
case undefined:return new FieldValueOptions(ServerTimestampBehavior.Default,timestampsInSnapshots);default:return fail('fromSnapshotOptions() called with invalid options.');}};return FieldValueOptions;}();/**
* A field value represents a datatype as stored by Firestore.
*/var FieldValue=/** @class */function(){function FieldValue(){}FieldValue.prototype.toString=function(){var val=this.value();return val===null?'null':val.toString();};FieldValue.prototype.defaultCompareTo=function(other){assert(this.typeOrder!==other.typeOrder,'Default compareTo should not be used for values of same type.');var cmp=primitiveComparator(this.typeOrder,other.typeOrder);return cmp;};return FieldValue;}();var NullValue=/** @class */function(_super){tslib_1.__extends(NullValue,_super);function NullValue(){var _this=_super.call(this)||this;_this.typeOrder=TypeOrder.NullValue;// internalValue is unused but we add it to work around
// https://github.com/Microsoft/TypeScript/issues/15585
_this.internalValue=null;return _this;}NullValue.prototype.value=function(options){return null;};NullValue.prototype.isEqual=function(other){return other instanceof NullValue;};NullValue.prototype.compareTo=function(other){if(other instanceof NullValue){return 0;}return this.defaultCompareTo(other);};NullValue.INSTANCE=new NullValue();return NullValue;}(FieldValue);var BooleanValue=/** @class */function(_super){tslib_1.__extends(BooleanValue,_super);function BooleanValue(internalValue){var _this=_super.call(this)||this;_this.internalValue=internalValue;_this.typeOrder=TypeOrder.BooleanValue;return _this;}BooleanValue.prototype.value=function(options){return this.internalValue;};BooleanValue.prototype.isEqual=function(other){return other instanceof BooleanValue&&this.internalValue===other.internalValue;};BooleanValue.prototype.compareTo=function(other){if(other instanceof BooleanValue){return primitiveComparator(this,other);}return this.defaultCompareTo(other);};BooleanValue.of=function(value){return value?BooleanValue.TRUE:BooleanValue.FALSE;};BooleanValue.TRUE=new BooleanValue(true);BooleanValue.FALSE=new BooleanValue(false);return BooleanValue;}(FieldValue);/** Base class for IntegerValue and DoubleValue. */var NumberValue=/** @class */function(_super){tslib_1.__extends(NumberValue,_super);function NumberValue(internalValue){var _this=_super.call(this)||this;_this.internalValue=internalValue;_this.typeOrder=TypeOrder.NumberValue;return _this;}NumberValue.prototype.value=function(options){return this.internalValue;};NumberValue.prototype.compareTo=function(other){if(other instanceof NumberValue){return numericComparator(this.internalValue,other.internalValue);}return this.defaultCompareTo(other);};return NumberValue;}(FieldValue);/** Utility function to compare doubles (using Firestore semantics for NaN). */function numericComparator(left,right){if(left<right){return-1;}else if(left>right){return 1;}else if(left===right){return 0;}else{// one or both are NaN.
if(isNaN(left)){return isNaN(right)?0:-1;}else{return 1;}}}/**
* Utility function to check numbers for equality using Firestore semantics
* (NaN === NaN, -0.0 !== 0.0).
*/function numericEquals(left,right){// Implemented based on Object.is() polyfill from
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
if(left===right){// +0 != -0
return left!==0||1/left===1/right;}else{// NaN == NaN
return left!==left&&right!==right;}}var IntegerValue=/** @class */function(_super){tslib_1.__extends(IntegerValue,_super);function IntegerValue(internalValue){return _super.call(this,internalValue)||this;}IntegerValue.prototype.isEqual=function(other){// NOTE: DoubleValue and IntegerValue instances may compareTo() the same,
// but that doesn't make them equal via isEqual().
if(other instanceof IntegerValue){return numericEquals(this.internalValue,other.internalValue);}else{return false;}};return IntegerValue;}(NumberValue);var DoubleValue=/** @class */function(_super){tslib_1.__extends(DoubleValue,_super);function DoubleValue(internalValue){var _this=_super.call(this,internalValue)||this;_this.internalValue=internalValue;return _this;}DoubleValue.prototype.isEqual=function(other){// NOTE: DoubleValue and IntegerValue instances may compareTo() the same,
// but that doesn't make them equal via isEqual().
if(other instanceof DoubleValue){return numericEquals(this.internalValue,other.internalValue);}else{return false;}};DoubleValue.NAN=new DoubleValue(NaN);DoubleValue.POSITIVE_INFINITY=new DoubleValue(Infinity);DoubleValue.NEGATIVE_INFINITY=new DoubleValue(-Infinity);return DoubleValue;}(NumberValue);// TODO(b/37267885): Add truncation support
var StringValue=/** @class */function(_super){tslib_1.__extends(StringValue,_super);function StringValue(internalValue){var _this=_super.call(this)||this;_this.internalValue=internalValue;_this.typeOrder=TypeOrder.StringValue;return _this;}StringValue.prototype.value=function(options){return this.internalValue;};StringValue.prototype.isEqual=function(other){return other instanceof StringValue&&this.internalValue===other.internalValue;};StringValue.prototype.compareTo=function(other){if(other instanceof StringValue){return primitiveComparator(this.internalValue,other.internalValue);}return this.defaultCompareTo(other);};return StringValue;}(FieldValue);var TimestampValue=/** @class */function(_super){tslib_1.__extends(TimestampValue,_super);function TimestampValue(internalValue){var _this=_super.call(this)||this;_this.internalValue=internalValue;_this.typeOrder=TypeOrder.TimestampValue;return _this;}TimestampValue.prototype.value=function(options){if(options&&options.timestampsInSnapshots){return this.internalValue;}else{return this.internalValue.toDate();}};TimestampValue.prototype.isEqual=function(other){return other instanceof TimestampValue&&this.internalValue.isEqual(other.internalValue);};TimestampValue.prototype.compareTo=function(other){if(other instanceof TimestampValue){return this.internalValue._compareTo(other.internalValue);}else if(other instanceof ServerTimestampValue){// Concrete timestamps come before server timestamps.
return-1;}else{return this.defaultCompareTo(other);}};return TimestampValue;}(FieldValue);/**
* Represents a locally-applied ServerTimestamp.
*
* Notes:
* - ServerTimestampValue instances are created as the result of applying a
* TransformMutation (see TransformMutation.applyTo()). They can only exist in
* the local view of a document. Therefore they do not need to be parsed or
* serialized.
* - When evaluated locally (e.g. for snapshot.data()), they by default
* evaluate to `null`. This behavior can be configured by passing custom
* FieldValueOptions to value().
* - With respect to other ServerTimestampValues, they sort by their
* localWriteTime.
*/var ServerTimestampValue=/** @class */function(_super){tslib_1.__extends(ServerTimestampValue,_super);function ServerTimestampValue(localWriteTime,previousValue){var _this=_super.call(this)||this;_this.localWriteTime=localWriteTime;_this.previousValue=previousValue;_this.typeOrder=TypeOrder.TimestampValue;return _this;}ServerTimestampValue.prototype.value=function(options){if(options&&options.serverTimestampBehavior===ServerTimestampBehavior.Estimate){return new TimestampValue(this.localWriteTime).value(options);}else if(options&&options.serverTimestampBehavior===ServerTimestampBehavior.Previous){return this.previousValue?this.previousValue.value(options):null;}else{return null;}};ServerTimestampValue.prototype.isEqual=function(other){return other instanceof ServerTimestampValue&&this.localWriteTime.isEqual(other.localWriteTime);};ServerTimestampValue.prototype.compareTo=function(other){if(other instanceof ServerTimestampValue){return this.localWriteTime._compareTo(other.localWriteTime);}else if(other instanceof TimestampValue){// Server timestamps come after all concrete timestamps.
return 1;}else{return this.defaultCompareTo(other);}};ServerTimestampValue.prototype.toString=function(){return'<ServerTimestamp localTime='+this.localWriteTime.toString()+'>';};return ServerTimestampValue;}(FieldValue);var BlobValue=/** @class */function(_super){tslib_1.__extends(BlobValue,_super);function BlobValue(internalValue){var _this=_super.call(this)||this;_this.internalValue=internalValue;_this.typeOrder=TypeOrder.BlobValue;return _this;}BlobValue.prototype.value=function(options){return this.internalValue;};BlobValue.prototype.isEqual=function(other){return other instanceof BlobValue&&this.internalValue.isEqual(other.internalValue);};BlobValue.prototype.compareTo=function(other){if(other instanceof BlobValue){return this.internalValue._compareTo(other.internalValue);}return this.defaultCompareTo(other);};return BlobValue;}(FieldValue);var RefValue=/** @class */function(_super){tslib_1.__extends(RefValue,_super);function RefValue(databaseId,key){var _this=_super.call(this)||this;_this.databaseId=databaseId;_this.key=key;_this.typeOrder=TypeOrder.RefValue;return _this;}RefValue.prototype.value=function(options){return this.key;};RefValue.prototype.isEqual=function(other){if(other instanceof RefValue){return this.key.isEqual(other.key)&&this.databaseId.isEqual(other.databaseId);}else{return false;}};RefValue.prototype.compareTo=function(other){if(other instanceof RefValue){var cmp=this.databaseId.compareTo(other.databaseId);return cmp!==0?cmp:DocumentKey.comparator(this.key,other.key);}return this.defaultCompareTo(other);};return RefValue;}(FieldValue);var GeoPointValue=/** @class */function(_super){tslib_1.__extends(GeoPointValue,_super);function GeoPointValue(internalValue){var _this=_super.call(this)||this;_this.internalValue=internalValue;_this.typeOrder=TypeOrder.GeoPointValue;return _this;}GeoPointValue.prototype.value=function(options){return this.internalValue;};GeoPointValue.prototype.isEqual=function(other){return other instanceof GeoPointValue&&this.internalValue.isEqual(other.internalValue);};GeoPointValue.prototype.compareTo=function(other){if(other instanceof GeoPointValue){return this.internalValue._compareTo(other.internalValue);}return this.defaultCompareTo(other);};return GeoPointValue;}(FieldValue);var ObjectValue=/** @class */function(_super){tslib_1.__extends(ObjectValue,_super);function ObjectValue(internalValue){var _this=_super.call(this)||this;_this.internalValue=internalValue;_this.typeOrder=TypeOrder.ObjectValue;return _this;}ObjectValue.prototype.value=function(options){var result={};this.internalValue.inorderTraversal(function(key,val){result[key]=val.value(options);});return result;};ObjectValue.prototype.forEach=function(action){this.internalValue.inorderTraversal(action);};ObjectValue.prototype.isEqual=function(other){if(other instanceof ObjectValue){var it1=this.internalValue.getIterator();var it2=other.internalValue.getIterator();while(it1.hasNext()&&it2.hasNext()){var next1=it1.getNext();var next2=it2.getNext();if(next1.key!==next2.key||!next1.value.isEqual(next2.value)){return false;}}return!it1.hasNext()&&!it2.hasNext();}return false;};ObjectValue.prototype.compareTo=function(other){if(other instanceof ObjectValue){var it1=this.internalValue.getIterator();var it2=other.internalValue.getIterator();while(it1.hasNext()&&it2.hasNext()){var next1=it1.getNext();var next2=it2.getNext();var cmp=primitiveComparator(next1.key,next2.key)||next1.value.compareTo(next2.value);if(cmp){return cmp;}}// Only equal if both iterators are exhausted
return primitiveComparator(it1.hasNext(),it2.hasNext());}else{return this.defaultCompareTo(other);}};ObjectValue.prototype.set=function(path,to){assert(!path.isEmpty(),'Cannot set field for empty path on ObjectValue');if(path.length===1){return this.setChild(path.firstSegment(),to);}else{var child=this.child(path.firstSegment());if(!(child instanceof ObjectValue)){child=ObjectValue.EMPTY;}var newChild=child.set(path.popFirst(),to);return this.setChild(path.firstSegment(),newChild);}};ObjectValue.prototype.delete=function(path){assert(!path.isEmpty(),'Cannot delete field for empty path on ObjectValue');if(path.length===1){return new ObjectValue(this.internalValue.remove(path.firstSegment()));}else{// nested field
var child=this.child(path.firstSegment());if(child instanceof ObjectValue){var newChild=child.delete(path.popFirst());return new ObjectValue(this.internalValue.insert(path.firstSegment(),newChild));}else{// Don't actually change a primitive value to an object for a delete
return this;}}};ObjectValue.prototype.contains=function(path){return this.field(path)!==undefined;};ObjectValue.prototype.field=function(path){assert(!path.isEmpty(),"Can't get field of empty path");var field=this;path.forEach(function(pathSegment){if(field instanceof ObjectValue){field=field.internalValue.get(pathSegment)||undefined;}else{field=undefined;}});return field;};ObjectValue.prototype.toString=function(){return JSON.stringify(this.value());};ObjectValue.prototype.child=function(childName){return this.internalValue.get(childName)||undefined;};ObjectValue.prototype.setChild=function(childName,value){return new ObjectValue(this.internalValue.insert(childName,value));};ObjectValue.EMPTY=new ObjectValue(new SortedMap(primitiveComparator));return ObjectValue;}(FieldValue);var ArrayValue=/** @class */function(_super){tslib_1.__extends(ArrayValue,_super);function ArrayValue(internalValue){var _this=_super.call(this)||this;_this.internalValue=internalValue;_this.typeOrder=TypeOrder.ArrayValue;return _this;}ArrayValue.prototype.value=function(options){return this.internalValue.map(function(v){return v.value(options);});};ArrayValue.prototype.forEach=function(action){this.internalValue.forEach(action);};ArrayValue.prototype.isEqual=function(other){if(other instanceof ArrayValue){if(this.internalValue.length!==other.internalValue.length){return false;}for(var i=0;i<this.internalValue.length;i++){if(!this.internalValue[i].isEqual(other.internalValue[i])){return false;}}return true;}return false;};ArrayValue.prototype.compareTo=function(other){if(other instanceof ArrayValue){var minLength=Math.min(this.internalValue.length,other.internalValue.length);for(var i=0;i<minLength;i++){var cmp=this.internalValue[i].compareTo(other.internalValue[i]);if(cmp){return cmp;}}return primitiveComparator(this.internalValue.length,other.internalValue.length);}else{return this.defaultCompareTo(other);}};ArrayValue.prototype.toString=function(){return JSON.stringify(this.value());};return ArrayValue;}(FieldValue);/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/// Untyped Number alias we can use to check for ES6 methods / properties.
// tslint:disable-next-line:no-any variable-name
var NumberAsAny=Number;/**
* Minimum safe integer in Javascript because of floating point precision.
* Added to not rely on ES6 features.
*/var MIN_SAFE_INTEGER=NumberAsAny.MIN_SAFE_INTEGER||-(Math.pow(2,53)-1);/**
* Maximum safe integer in Javascript because of floating point precision.
* Added to not rely on ES6 features.
*/var MAX_SAFE_INTEGER=NumberAsAny.MAX_SAFE_INTEGER||Math.pow(2,53)-1;/**
* Returns whether an number is an integer, uses native implementation if
* available.
* Added to not rely on ES6 features.
* @param value The value to test for being an integer
*/var isInteger=NumberAsAny.isInteger||function(value){return typeof value==='number'&&isFinite(value)&&Math.floor(value)===value;};/**
* Returns whether a variable is either undefined or null.
*/function isNullOrUndefined(value){return value===null||value===undefined;}/**
* Returns whether a value is an integer and in the safe integer range
* @param value The value to test for being an integer and in the safe range
*/function isSafeInteger(value){return isInteger(value)&&value<=MAX_SAFE_INTEGER&&value>=MIN_SAFE_INTEGER;}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var Query=/** @class */function(){function Query(path,explicitOrderBy,filters,limit,startAt,endAt){if(explicitOrderBy===void 0){explicitOrderBy=[];}if(filters===void 0){filters=[];}if(limit===void 0){limit=null;}if(startAt===void 0){startAt=null;}if(endAt===void 0){endAt=null;}this.path=path;this.explicitOrderBy=explicitOrderBy;this.filters=filters;this.limit=limit;this.startAt=startAt;this.endAt=endAt;this.memoizedCanonicalId=null;this.memoizedOrderBy=null;if(this.startAt){this.assertValidBound(this.startAt);}if(this.endAt){this.assertValidBound(this.endAt);}}Query.atPath=function(path){return new Query(path);};Object.defineProperty(Query.prototype,"orderBy",{get:function(){if(this.memoizedOrderBy===null){var inequalityField=this.getInequalityFilterField();var firstOrderByField=this.getFirstOrderByField();if(inequalityField!==null&&firstOrderByField===null){// In order to implicitly add key ordering, we must also add the
// inequality filter field for it to be a valid query.
// Note that the default inequality field and key ordering is ascending.
if(inequalityField.isKeyField()){this.memoizedOrderBy=[KEY_ORDERING_ASC];}else{this.memoizedOrderBy=[new OrderBy(inequalityField),KEY_ORDERING_ASC];}}else{assert(inequalityField===null||firstOrderByField!==null&&inequalityField.isEqual(firstOrderByField),'First orderBy should match inequality field.');this.memoizedOrderBy=[];var foundKeyOrdering=false;for(var _i=0,_a=this.explicitOrderBy;_i<_a.length;_i++){var orderBy=_a[_i];this.memoizedOrderBy.push(orderBy);if(orderBy.field.isKeyField()){foundKeyOrdering=true;}}if(!foundKeyOrdering){// The order of the implicit key ordering always matches the last
// explicit order by
var lastDirection=this.explicitOrderBy.length>0?this.explicitOrderBy[this.explicitOrderBy.length-1].dir:Direction.ASCENDING;this.memoizedOrderBy.push(lastDirection===Direction.ASCENDING?KEY_ORDERING_ASC:KEY_ORDERING_DESC);}}}return this.memoizedOrderBy;},enumerable:true,configurable:true});Query.prototype.addFilter=function(filter){assert(this.getInequalityFilterField()==null||!(filter instanceof RelationFilter)||!filter.isInequality()||filter.field.isEqual(this.getInequalityFilterField()),'Query must only have one inequality field.');assert(!DocumentKey.isDocumentKey(this.path),'No filtering allowed for document query');var newFilters=this.filters.concat([filter]);return new Query(this.path,this.explicitOrderBy.slice(),newFilters,this.limit,this.startAt,this.endAt);};Query.prototype.addOrderBy=function(orderBy){assert(!DocumentKey.isDocumentKey(this.path),'No ordering allowed for document query');assert(!this.startAt&&!this.endAt,'Bounds must be set after orderBy');// TODO(dimond): validate that orderBy does not list the same key twice.
var newOrderBy=this.explicitOrderBy.concat([orderBy]);return new Query(this.path,newOrderBy,this.filters.slice(),this.limit,this.startAt,this.endAt);};Query.prototype.withLimit=function(limit){return new Query(this.path,this.explicitOrderBy.slice(),this.filters.slice(),limit,this.startAt,this.endAt);};Query.prototype.withStartAt=function(bound){return new Query(this.path,this.explicitOrderBy.slice(),this.filters.slice(),this.limit,bound,this.endAt);};Query.prototype.withEndAt=function(bound){return new Query(this.path,this.explicitOrderBy.slice(),this.filters.slice(),this.limit,this.startAt,bound);};// TODO(b/29183165): This is used to get a unique string from a query to, for
// example, use as a dictionary key, but the implementation is subject to
// collisions. Make it collision-free.
Query.prototype.canonicalId=function(){if(this.memoizedCanonicalId===null){var canonicalId=this.path.canonicalString();canonicalId+='|f:';for(var _i=0,_a=this.filters;_i<_a.length;_i++){var filter=_a[_i];canonicalId+=filter.canonicalId();canonicalId+=',';}canonicalId+='|ob:';// TODO(dimond): make this collision resistant
for(var _b=0,_c=this.orderBy;_b<_c.length;_b++){var orderBy=_c[_b];canonicalId+=orderBy.canonicalId();canonicalId+=',';}if(!isNullOrUndefined(this.limit)){canonicalId+='|l:';canonicalId+=this.limit;}if(this.startAt){canonicalId+='|lb:';canonicalId+=this.startAt.canonicalId();}if(this.endAt){canonicalId+='|ub:';canonicalId+=this.endAt.canonicalId();}this.memoizedCanonicalId=canonicalId;}return this.memoizedCanonicalId;};Query.prototype.toString=function(){var str='Query('+this.path.canonicalString();if(this.filters.length>0){str+=", filters: ["+this.filters.join(', ')+"]";}if(!isNullOrUndefined(this.limit)){str+=', limit: '+this.limit;}if(this.explicitOrderBy.length>0){str+=", orderBy: ["+this.explicitOrderBy.join(', ')+"]";}if(this.startAt){str+=', startAt: '+this.startAt.canonicalId();}if(this.endAt){str+=', endAt: '+this.endAt.canonicalId();}return str+')';};Query.prototype.isEqual=function(other){if(this.limit!==other.limit){return false;}if(this.orderBy.length!==other.orderBy.length){return false;}for(var i=0;i<this.orderBy.length;i++){if(!this.orderBy[i].isEqual(other.orderBy[i])){return false;}}if(this.filters.length!==other.filters.length){return false;}for(var i=0;i<this.filters.length;i++){if(!this.filters[i].isEqual(other.filters[i])){return false;}}if(!this.path.isEqual(other.path)){return false;}if(this.startAt!==null?!this.startAt.isEqual(other.startAt):other.startAt!==null){return false;}return this.endAt!==null?this.endAt.isEqual(other.endAt):other.endAt===null;};Query.prototype.docComparator=function(d1,d2){var comparedOnKeyField=false;for(var _i=0,_a=this.orderBy;_i<_a.length;_i++){var orderBy=_a[_i];var comp=orderBy.compare(d1,d2);if(comp!==0)return comp;comparedOnKeyField=comparedOnKeyField||orderBy.field.isKeyField();}// Assert that we actually compared by key
assert(comparedOnKeyField,"orderBy used that doesn't compare on key field");return 0;};Query.prototype.matches=function(doc){return this.matchesAncestor(doc)&&this.matchesOrderBy(doc)&&this.matchesFilters(doc)&&this.matchesBounds(doc);};Query.prototype.hasLimit=function(){return!isNullOrUndefined(this.limit);};Query.prototype.getFirstOrderByField=function(){return this.explicitOrderBy.length>0?this.explicitOrderBy[0].field:null;};Query.prototype.getInequalityFilterField=function(){for(var _i=0,_a=this.filters;_i<_a.length;_i++){var filter=_a[_i];if(filter instanceof RelationFilter&&filter.isInequality()){return filter.field;}}return null;};Query.prototype.hasArrayContainsFilter=function(){return this.filters.find(function(filter){return filter instanceof RelationFilter&&filter.op===RelationOp.ARRAY_CONTAINS;})!==undefined;};Query.prototype.isDocumentQuery=function(){return DocumentKey.isDocumentKey(this.path)&&this.filters.length===0;};Query.prototype.matchesAncestor=function(doc){var docPath=doc.key.path;if(DocumentKey.isDocumentKey(this.path)){// exact match for document queries
return this.path.isEqual(docPath);}else{// shallow ancestor queries by default
return this.path.isPrefixOf(docPath)&&this.path.length===docPath.length-1;}};/**
* A document must have a value for every ordering clause in order to show up
* in the results.
*/Query.prototype.matchesOrderBy=function(doc){for(var _i=0,_a=this.explicitOrderBy;_i<_a.length;_i++){var orderBy=_a[_i];// order by key always matches
if(!orderBy.field.isKeyField()&&doc.field(orderBy.field)===undefined){return false;}}return true;};Query.prototype.matchesFilters=function(doc){for(var _i=0,_a=this.filters;_i<_a.length;_i++){var filter=_a[_i];if(!filter.matches(doc)){return false;}}return true;};/**
* Makes sure a document is within the bounds, if provided.
*/Query.prototype.matchesBounds=function(doc){if(this.startAt&&!this.startAt.sortsBeforeDocument(this.orderBy,doc)){return false;}if(this.endAt&&this.endAt.sortsBeforeDocument(this.orderBy,doc)){return false;}return true;};Query.prototype.assertValidBound=function(bound){assert(bound.position.length<=this.orderBy.length,'Bound is longer than orderBy');};return Query;}();var RelationOp=/** @class */function(){function RelationOp(name){this.name=name;}RelationOp.fromString=function(op){switch(op){case'<':return RelationOp.LESS_THAN;case'<=':return RelationOp.LESS_THAN_OR_EQUAL;case'==':return RelationOp.EQUAL;case'>=':return RelationOp.GREATER_THAN_OR_EQUAL;case'>':return RelationOp.GREATER_THAN;case'array-contains':return RelationOp.ARRAY_CONTAINS;default:return fail('Unknown relation: '+op);}};RelationOp.prototype.toString=function(){return this.name;};RelationOp.prototype.isEqual=function(other){return this.name===other.name;};RelationOp.LESS_THAN=new RelationOp('<');RelationOp.LESS_THAN_OR_EQUAL=new RelationOp('<=');RelationOp.EQUAL=new RelationOp('==');RelationOp.GREATER_THAN=new RelationOp('>');RelationOp.GREATER_THAN_OR_EQUAL=new RelationOp('>=');RelationOp.ARRAY_CONTAINS=new RelationOp('array-contains');return RelationOp;}();var RelationFilter=/** @class */function(){function RelationFilter(field,op,value){this.field=field;this.op=op;this.value=value;}RelationFilter.prototype.matches=function(doc){if(this.field.isKeyField()){assert(this.value instanceof RefValue,'Comparing on key, but filter value not a RefValue');assert(this.op!==RelationOp.ARRAY_CONTAINS,"array-contains queries don't make sense on document keys.");var refValue=this.value;var comparison=DocumentKey.comparator(doc.key,refValue.key);return this.matchesComparison(comparison);}else{var val=doc.field(this.field);return val!==undefined&&this.matchesValue(val);}};RelationFilter.prototype.matchesValue=function(value){var _this=this;if(this.op===RelationOp.ARRAY_CONTAINS){return value instanceof ArrayValue&&value.internalValue.find(function(element){return element.isEqual(_this.value);})!==undefined;}else{// Only compare types with matching backend order (such as double and int).
return this.value.typeOrder===value.typeOrder&&this.matchesComparison(value.compareTo(this.value));}};RelationFilter.prototype.matchesComparison=function(comparison){switch(this.op){case RelationOp.LESS_THAN:return comparison<0;case RelationOp.LESS_THAN_OR_EQUAL:return comparison<=0;case RelationOp.EQUAL:return comparison===0;case RelationOp.GREATER_THAN:return comparison>0;case RelationOp.GREATER_THAN_OR_EQUAL:return comparison>=0;default:return fail('Unknown relation op'+this.op);}};RelationFilter.prototype.isInequality=function(){return this.op!==RelationOp.EQUAL&&this.op!==RelationOp.ARRAY_CONTAINS;};RelationFilter.prototype.canonicalId=function(){// TODO(b/29183165): Technically, this won't be unique if two values have
// the same description, such as the int 3 and the string "3". So we should
// add the types in here somehow, too.
return this.field.canonicalString()+this.op.toString()+this.value.toString();};RelationFilter.prototype.isEqual=function(other){if(other instanceof RelationFilter){return this.op.isEqual(other.op)&&this.field.isEqual(other.field)&&this.value.isEqual(other.value);}else{return false;}};RelationFilter.prototype.toString=function(){return this.field.canonicalString()+" "+this.op+" "+this.value.value();};return RelationFilter;}();/**
* Filter that matches 'null' values.
*/var NullFilter=/** @class */function(){function NullFilter(field){this.field=field;}NullFilter.prototype.matches=function(doc){var val=doc.field(this.field);return val!==undefined&&val.value()===null;};NullFilter.prototype.canonicalId=function(){return this.field.canonicalString()+' IS null';};NullFilter.prototype.toString=function(){return this.field.canonicalString()+" IS null";};NullFilter.prototype.isEqual=function(other){if(other instanceof NullFilter){return this.field.isEqual(other.field);}else{return false;}};return NullFilter;}();/**
* Filter that matches 'NaN' values.
*/var NanFilter=/** @class */function(){function NanFilter(field){this.field=field;}NanFilter.prototype.matches=function(doc){var val=doc.field(this.field).value();return typeof val==='number'&&isNaN(val);};NanFilter.prototype.canonicalId=function(){return this.field.canonicalString()+' IS NaN';};NanFilter.prototype.toString=function(){return this.field.canonicalString()+" IS NaN";};NanFilter.prototype.isEqual=function(other){if(other instanceof NanFilter){return this.field.isEqual(other.field);}else{return false;}};return NanFilter;}();/**
* Creates a filter based on the provided arguments.
*/function fieldFilter(field,op,value){if(value.isEqual(NullValue.INSTANCE)){if(op!==RelationOp.EQUAL){throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid query. You can only perform equals '+'comparisons on null.');}return new NullFilter(field);}else if(value.isEqual(DoubleValue.NAN)){if(op!==RelationOp.EQUAL){throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid query. You can only perform equals '+'comparisons on NaN.');}return new NanFilter(field);}else{return new RelationFilter(field,op,value);}}/**
* The direction of sorting in an order by.
*/var Direction=/** @class */function(){function Direction(name){this.name=name;}Direction.prototype.toString=function(){return this.name;};Direction.ASCENDING=new Direction('asc');Direction.DESCENDING=new Direction('desc');return Direction;}();/**
* Represents a bound of a query.
*
* The bound is specified with the given components representing a position and
* whether it's just before or just after the position (relative to whatever the
* query order is).
*
* The position represents a logical index position for a query. It's a prefix
* of values for the (potentially implicit) order by clauses of a query.
*
* Bound provides a function to determine whether a document comes before or
* after a bound. This is influenced by whether the position is just before or
* just after the provided values.
*/var Bound=/** @class */function(){function Bound(position,before){this.position=position;this.before=before;}Bound.prototype.canonicalId=function(){// TODO(b/29183165): Make this collision robust.
var canonicalId=this.before?'b:':'a:';for(var _i=0,_a=this.position;_i<_a.length;_i++){var component=_a[_i];canonicalId+=component.toString();}return canonicalId;};/**
* Returns true if a document sorts before a bound using the provided sort
* order.
*/Bound.prototype.sortsBeforeDocument=function(orderBy,doc){assert(this.position.length<=orderBy.length,"Bound has more components than query's orderBy");var comparison=0;for(var i=0;i<this.position.length;i++){var orderByComponent=orderBy[i];var component=this.position[i];if(orderByComponent.field.isKeyField()){assert(component instanceof RefValue,'Bound has a non-key value where the key path is being used.');comparison=DocumentKey.comparator(component.key,doc.key);}else{var docValue=doc.field(orderByComponent.field);assert(docValue!==undefined,'Field should exist since document matched the orderBy already.');comparison=component.compareTo(docValue);}if(orderByComponent.dir===Direction.DESCENDING){comparison=comparison*-1;}if(comparison!==0){break;}}return this.before?comparison<=0:comparison<0;};Bound.prototype.isEqual=function(other){if(other===null){return false;}if(this.before!==other.before||this.position.length!==other.position.length){return false;}for(var i=0;i<this.position.length;i++){var thisPosition=this.position[i];var otherPosition=other.position[i];return thisPosition.isEqual(otherPosition);}return true;};return Bound;}();/**
* An ordering on a field, in some Direction. Direction defaults to ASCENDING.
*/var OrderBy=/** @class */function(){function OrderBy(field,dir){this.field=field;if(dir===undefined){dir=Direction.ASCENDING;}this.dir=dir;this.isKeyOrderBy=field.isKeyField();}OrderBy.prototype.compare=function(d1,d2){var comparison=this.isKeyOrderBy?Document.compareByKey(d1,d2):Document.compareByField(this.field,d1,d2);switch(this.dir){case Direction.ASCENDING:return comparison;case Direction.DESCENDING:return-1*comparison;default:return fail('Unknown direction: '+this.dir);}};OrderBy.prototype.canonicalId=function(){// TODO(b/29183165): Make this collision robust.
return this.field.canonicalString()+this.dir.toString();};OrderBy.prototype.toString=function(){return this.field.canonicalString()+" ("+this.dir+")";};OrderBy.prototype.isEqual=function(other){return this.dir===other.dir&&this.field.isEqual(other.field);};return OrderBy;}();var KEY_ORDERING_ASC=new OrderBy(FieldPath.keyField(),Direction.ASCENDING);var KEY_ORDERING_DESC=new OrderBy(FieldPath.keyField(),Direction.DESCENDING);/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* A version of a document in Firestore. This corresponds to the version
* timestamp, such as update_time or read_time.
*/var SnapshotVersion=/** @class */function(){function SnapshotVersion(timestamp){this.timestamp=timestamp;}// TODO(b/34176344): Once we no longer need to use the old alpha protos,
// delete this constructor and use a timestamp-backed version everywhere.
SnapshotVersion.fromMicroseconds=function(value){var seconds=Math.floor(value/1e6);var nanos=value%1e6*1e3;return new SnapshotVersion(new Timestamp(seconds,nanos));};SnapshotVersion.fromTimestamp=function(value){return new SnapshotVersion(value);};SnapshotVersion.forDeletedDoc=function(){return SnapshotVersion.MIN;};SnapshotVersion.prototype.compareTo=function(other){return this.timestamp._compareTo(other.timestamp);};SnapshotVersion.prototype.isEqual=function(other){return this.timestamp.isEqual(other.timestamp);};/** Returns a number representation of the version for use in spec tests. */SnapshotVersion.prototype.toMicroseconds=function(){// Convert to microseconds.
return this.timestamp.seconds*1e6+this.timestamp.nanoseconds/1000;};SnapshotVersion.prototype.toString=function(){return'SnapshotVersion('+this.timestamp.toString()+')';};SnapshotVersion.prototype.toTimestamp=function(){return this.timestamp;};SnapshotVersion.MIN=new SnapshotVersion(new Timestamp(0,0));return SnapshotVersion;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//** An enumeration of the different purposes we have for queries. */var QueryPurpose;(function(QueryPurpose){/** A regular, normal query. */QueryPurpose[QueryPurpose["Listen"]=0]="Listen";/**
* The query was used to refill a query after an existence filter mismatch.
*/QueryPurpose[QueryPurpose["ExistenceFilterMismatch"]=1]="ExistenceFilterMismatch";/** The query was used to resolve a limbo document. */QueryPurpose[QueryPurpose["LimboResolution"]=2]="LimboResolution";})(QueryPurpose||(QueryPurpose={}));/**
* An immutable set of metadata that the local store tracks for each query.
*/var QueryData=/** @class */function(){function QueryData(/** The query being listened to. */query,/**
* The target ID to which the query corresponds; Assigned by the
* LocalStore for user listens and by the SyncEngine for limbo watches.
*/targetId,/** The purpose of the query. */purpose,/** The latest snapshot version seen for this target. */snapshotVersion,/**
* An opaque, server-assigned token that allows watching a query to be
* resumed after disconnecting without retransmitting all the data that
* matches the query. The resume token essentially identifies a point in
* time from which the server should resume sending results.
*/resumeToken){if(snapshotVersion===void 0){snapshotVersion=SnapshotVersion.MIN;}if(resumeToken===void 0){resumeToken=emptyByteString();}this.query=query;this.targetId=targetId;this.purpose=purpose;this.snapshotVersion=snapshotVersion;this.resumeToken=resumeToken;}/**
* Creates a new query data instance with an updated snapshot version and
* resume token.
*/QueryData.prototype.update=function(updated){return new QueryData(this.query,this.targetId,this.purpose,updated.snapshotVersion,updated.resumeToken);};QueryData.prototype.isEqual=function(other){return this.targetId===other.targetId&&this.purpose===other.purpose&&this.snapshotVersion.isEqual(other.snapshotVersion)&&this.resumeToken===other.resumeToken&&this.query.isEqual(other.query);};return QueryData;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Provides a set of fields that can be used to partially patch a document.
* FieldMask is used in conjunction with ObjectValue.
* Examples:
* foo - Overwrites foo entirely with the provided value. If foo is not
* present in the companion ObjectValue, the field is deleted.
* foo.bar - Overwrites only the field bar of the object foo.
* If foo is not an object, foo is replaced with an object
* containing foo
*/var FieldMask=/** @class */function(){function FieldMask(fields){this.fields=fields;// TODO(dimond): validation of FieldMask
}/**
* Verifies that `fieldPath` is included by at least one field in this field
* mask.
*
* This is an O(n) operation, where `n` is the size of the field mask.
*/FieldMask.prototype.covers=function(fieldPath){for(var _i=0,_a=this.fields;_i<_a.length;_i++){var fieldMaskPath=_a[_i];if(fieldMaskPath.isPrefixOf(fieldPath)){return true;}}return false;};FieldMask.prototype.isEqual=function(other){return arrayEquals(this.fields,other.fields);};return FieldMask;}();/** A field path and the TransformOperation to perform upon it. */var FieldTransform=/** @class */function(){function FieldTransform(field,transform){this.field=field;this.transform=transform;}FieldTransform.prototype.isEqual=function(other){return this.field.isEqual(other.field)&&this.transform.isEqual(other.transform);};return FieldTransform;}();/** The result of successfully applying a mutation to the backend. */var MutationResult=/** @class */function(){function MutationResult(/**
* The version at which the mutation was committed or null for a delete.
*/version,/**
* The resulting fields returned from the backend after a
* TransformMutation has been committed. Contains one FieldValue for each
* FieldTransform that was in the mutation.
*
* Will be null if the mutation was not a TransformMutation.
*/transformResults){this.version=version;this.transformResults=transformResults;}return MutationResult;}();var MutationType;(function(MutationType){MutationType[MutationType["Set"]=0]="Set";MutationType[MutationType["Patch"]=1]="Patch";MutationType[MutationType["Transform"]=2]="Transform";MutationType[MutationType["Delete"]=3]="Delete";})(MutationType||(MutationType={}));/**
* Encodes a precondition for a mutation. This follows the model that the
* backend accepts with the special case of an explicit "empty" precondition
* (meaning no precondition).
*/var Precondition=/** @class */function(){function Precondition(updateTime,exists){this.updateTime=updateTime;this.exists=exists;assert(updateTime===undefined||exists===undefined,'Precondition can specify "exists" or "updateTime" but not both');}/** Creates a new Precondition with an exists flag. */Precondition.exists=function(exists){return new Precondition(undefined,exists);};/** Creates a new Precondition based on a version a document exists at. */Precondition.updateTime=function(version){return new Precondition(version);};Object.defineProperty(Precondition.prototype,"isNone",{/** Returns whether this Precondition is empty. */get:function(){return this.updateTime===undefined&&this.exists===undefined;},enumerable:true,configurable:true});/**
* Returns true if the preconditions is valid for the given document
* (or null if no document is available).
*/Precondition.prototype.isValidFor=function(maybeDoc){if(this.updateTime!==undefined){return maybeDoc instanceof Document&&maybeDoc.version.isEqual(this.updateTime);}else if(this.exists!==undefined){if(this.exists){return maybeDoc instanceof Document;}else{return maybeDoc===null||maybeDoc instanceof NoDocument;}}else{assert(this.isNone,'Precondition should be empty');return true;}};Precondition.prototype.isEqual=function(other){return equals(this.updateTime,other.updateTime)&&this.exists===other.exists;};Precondition.NONE=new Precondition();return Precondition;}();/**
* A mutation describes a self-contained change to a document. Mutations can
* create, replace, delete, and update subsets of documents.
*
* Mutations not only act on the value of the document but also it version.
* In the case of Set, Patch, and Transform mutations we preserve the existing
* version. In the case of Delete mutations, we reset the version to 0.
*
* Here's the expected transition table.
*
* MUTATION APPLIED TO RESULTS IN
*
* SetMutation Document(v3) Document(v3)
* SetMutation NoDocument(v3) Document(v0)
* SetMutation null Document(v0)
* PatchMutation Document(v3) Document(v3)
* PatchMutation NoDocument(v3) NoDocument(v3)
* PatchMutation null null
* TransformMutation Document(v3) Document(v3)
* TransformMutation NoDocument(v3) NoDocument(v3)
* TransformMutation null null
* DeleteMutation Document(v3) NoDocument(v0)
* DeleteMutation NoDocument(v3) NoDocument(v0)
* DeleteMutation null NoDocument(v0)
*
* Note that TransformMutations don't create Documents (in the case of being
* applied to a NoDocument), even though they would on the backend. This is
* because the client always combines the TransformMutation with a SetMutation
* or PatchMutation and we only want to apply the transform if the prior
* mutation resulted in a Document (always true for a SetMutation, but not
* necessarily for a PatchMutation).
*
* ## Subclassing Notes
*
* Subclasses of Mutation need to implement applyToRemoteDocument() and
* applyToLocalView() to implement the actual behavior of applying the mutation
* to some source document.
*/var Mutation=/** @class */function(){function Mutation(){}Mutation.prototype.verifyKeyMatches=function(maybeDoc){if(maybeDoc!=null){assert(maybeDoc.key.isEqual(this.key),'Can only apply a mutation to a document with the same key');}};/**
* Returns the version from the given document for use as the result of a
* mutation. Mutations are defined to return the version of the base document
* only if it is an existing document. Deleted and unknown documents have a
* post-mutation version of SnapshotVersion.MIN.
*/Mutation.getPostMutationVersion=function(maybeDoc){if(maybeDoc instanceof Document){return maybeDoc.version;}else{return SnapshotVersion.MIN;}};return Mutation;}();/**
* A mutation that creates or replaces the document at the given key with the
* object value contents.
*/var SetMutation=/** @class */function(_super){tslib_1.__extends(SetMutation,_super);function SetMutation(key,value,precondition){var _this=_super.call(this)||this;_this.key=key;_this.value=value;_this.precondition=precondition;_this.type=MutationType.Set;return _this;}SetMutation.prototype.applyToRemoteDocument=function(maybeDoc,mutationResult){this.verifyKeyMatches(maybeDoc);assert(mutationResult.transformResults==null,'Transform results received by SetMutation.');// Unlike applyToLocalView, if we're applying a mutation to a remote
// document the server has accepted the mutation so the precondition must
// have held.
var version=Mutation.getPostMutationVersion(maybeDoc);return new Document(this.key,version,this.value,{hasLocalMutations:false});};SetMutation.prototype.applyToLocalView=function(maybeDoc,baseDoc,localWriteTime){this.verifyKeyMatches(maybeDoc);if(!this.precondition.isValidFor(maybeDoc)){return maybeDoc;}var version=Mutation.getPostMutationVersion(maybeDoc);return new Document(this.key,version,this.value,{hasLocalMutations:true});};SetMutation.prototype.isEqual=function(other){return other instanceof SetMutation&&this.key.isEqual(other.key)&&this.value.isEqual(other.value)&&this.precondition.isEqual(other.precondition);};return SetMutation;}(Mutation);/**
* A mutation that modifies fields of the document at the given key with the
* given values. The values are applied through a field mask:
*
* * When a field is in both the mask and the values, the corresponding field
* is updated.
* * When a field is in neither the mask nor the values, the corresponding
* field is unmodified.
* * When a field is in the mask but not in the values, the corresponding field
* is deleted.
* * When a field is not in the mask but is in the values, the values map is
* ignored.
*/var PatchMutation=/** @class */function(_super){tslib_1.__extends(PatchMutation,_super);function PatchMutation(key,data,fieldMask,precondition){var _this=_super.call(this)||this;_this.key=key;_this.data=data;_this.fieldMask=fieldMask;_this.precondition=precondition;_this.type=MutationType.Patch;return _this;}PatchMutation.prototype.applyToRemoteDocument=function(maybeDoc,mutationResult){this.verifyKeyMatches(maybeDoc);assert(mutationResult.transformResults==null,'Transform results received by PatchMutation.');// TODO(mcg): Relax enforcement of this precondition
//
// We shouldn't actually enforce the precondition since it already passed on
// the backend, but we may not have a local version of the document to
// patch, so we use the precondition to prevent incorrectly putting a
// partial document into our cache.
if(!this.precondition.isValidFor(maybeDoc)){return maybeDoc;}var version=Mutation.getPostMutationVersion(maybeDoc);var newData=this.patchDocument(maybeDoc);return new Document(this.key,version,newData,{hasLocalMutations:false});};PatchMutation.prototype.applyToLocalView=function(maybeDoc,baseDoc,localWriteTime){this.verifyKeyMatches(maybeDoc);if(!this.precondition.isValidFor(maybeDoc)){return maybeDoc;}var version=Mutation.getPostMutationVersion(maybeDoc);var newData=this.patchDocument(maybeDoc);return new Document(this.key,version,newData,{hasLocalMutations:true});};PatchMutation.prototype.isEqual=function(other){return other instanceof PatchMutation&&this.key.isEqual(other.key)&&this.fieldMask.isEqual(other.fieldMask)&&this.precondition.isEqual(other.precondition);};/**
* Patches the data of document if available or creates a new document. Note
* that this does not check whether or not the precondition of this patch
* holds.
*/PatchMutation.prototype.patchDocument=function(maybeDoc){var data;if(maybeDoc instanceof Document){data=maybeDoc.data;}else{data=ObjectValue.EMPTY;}return this.patchObject(data);};PatchMutation.prototype.patchObject=function(data){for(var _i=0,_a=this.fieldMask.fields;_i<_a.length;_i++){var fieldPath=_a[_i];var newValue=this.data.field(fieldPath);if(newValue!==undefined){data=data.set(fieldPath,newValue);}else{data=data.delete(fieldPath);}}return data;};return PatchMutation;}(Mutation);/**
* A mutation that modifies specific fields of the document with transform
* operations. Currently the only supported transform is a server timestamp, but
* IP Address, increment(n), etc. could be supported in the future.
*
* It is somewhat similar to a PatchMutation in that it patches specific fields
* and has no effect when applied to a null or NoDocument (see comment on
* Mutation for rationale).
*/var TransformMutation=/** @class */function(_super){tslib_1.__extends(TransformMutation,_super);function TransformMutation(key,fieldTransforms){var _this=_super.call(this)||this;_this.key=key;_this.fieldTransforms=fieldTransforms;_this.type=MutationType.Transform;// NOTE: We set a precondition of exists: true as a safety-check, since we
// always combine TransformMutations with a SetMutation or PatchMutation which
// (if successful) should end up with an existing document.
_this.precondition=Precondition.exists(true);return _this;}TransformMutation.prototype.applyToRemoteDocument=function(maybeDoc,mutationResult){this.verifyKeyMatches(maybeDoc);assert(mutationResult.transformResults!=null,'Transform results missing for TransformMutation.');// TODO(mcg): Relax enforcement of this precondition
//
// We shouldn't actually enforce the precondition since it already passed on
// the backend, but we may not have a local version of the document to
// patch, so we use the precondition to prevent incorrectly putting a
// partial document into our cache.
if(!this.precondition.isValidFor(maybeDoc)){return maybeDoc;}var doc=this.requireDocument(maybeDoc);var transformResults=this.serverTransformResults(maybeDoc,mutationResult.transformResults);var newData=this.transformObject(doc.data,transformResults);return new Document(this.key,doc.version,newData,{hasLocalMutations:false});};TransformMutation.prototype.applyToLocalView=function(maybeDoc,baseDoc,localWriteTime){this.verifyKeyMatches(maybeDoc);if(!this.precondition.isValidFor(maybeDoc)){return maybeDoc;}var doc=this.requireDocument(maybeDoc);var transformResults=this.localTransformResults(localWriteTime,baseDoc);var newData=this.transformObject(doc.data,transformResults);return new Document(this.key,doc.version,newData,{hasLocalMutations:true});};TransformMutation.prototype.isEqual=function(other){return other instanceof TransformMutation&&this.key.isEqual(other.key)&&arrayEquals(this.fieldTransforms,other.fieldTransforms)&&this.precondition.isEqual(other.precondition);};/**
* Asserts that the given MaybeDocument is actually a Document and verifies
* that it matches the key for this mutation. Since we only support
* transformations with precondition exists this method is guaranteed to be
* safe.
*/TransformMutation.prototype.requireDocument=function(maybeDoc){assert(maybeDoc instanceof Document,'Unknown MaybeDocument type '+maybeDoc);var doc=maybeDoc;assert(doc.key.isEqual(this.key),'Can only transform a document with the same key');return doc;};/**
* Creates a list of "transform results" (a transform result is a field value
* representing the result of applying a transform) for use after a
* TransformMutation has been acknowledged by the server.
*
* @param baseDoc The document prior to applying this mutation batch.
* @param serverTransformResults The transform results received by the server.
* @return The transform results list.
*/TransformMutation.prototype.serverTransformResults=function(baseDoc,serverTransformResults){var transformResults=[];assert(this.fieldTransforms.length===serverTransformResults.length,"server transform result count ("+serverTransformResults.length+") "+("should match field transform count ("+this.fieldTransforms.length+")"));for(var i=0;i<serverTransformResults.length;i++){var fieldTransform=this.fieldTransforms[i];var transform=fieldTransform.transform;var previousValue=null;if(baseDoc instanceof Document){previousValue=baseDoc.field(fieldTransform.field)||null;}transformResults.push(transform.applyToRemoteDocument(previousValue,serverTransformResults[i]));}return transformResults;};/**
* Creates a list of "transform results" (a transform result is a field value
* representing the result of applying a transform) for use when applying a
* TransformMutation locally.
*
* @param localWriteTime The local time of the transform mutation (used to
* generate ServerTimestampValues).
* @param baseDoc The document prior to applying this mutation batch.
* @return The transform results list.
*/TransformMutation.prototype.localTransformResults=function(localWriteTime,baseDoc){var transformResults=[];for(var _i=0,_a=this.fieldTransforms;_i<_a.length;_i++){var fieldTransform=_a[_i];var transform=fieldTransform.transform;var previousValue=null;if(baseDoc instanceof Document){previousValue=baseDoc.field(fieldTransform.field)||null;}transformResults.push(transform.applyToLocalView(previousValue,localWriteTime));}return transformResults;};TransformMutation.prototype.transformObject=function(data,transformResults){assert(transformResults.length===this.fieldTransforms.length,'TransformResults length mismatch.');for(var i=0;i<this.fieldTransforms.length;i++){var fieldTransform=this.fieldTransforms[i];var fieldPath=fieldTransform.field;data=data.set(fieldPath,transformResults[i]);}return data;};return TransformMutation;}(Mutation);/** A mutation that deletes the document at the given key. */var DeleteMutation=/** @class */function(_super){tslib_1.__extends(DeleteMutation,_super);function DeleteMutation(key,precondition){var _this=_super.call(this)||this;_this.key=key;_this.precondition=precondition;_this.type=MutationType.Delete;return _this;}DeleteMutation.prototype.applyToRemoteDocument=function(maybeDoc,mutationResult){this.verifyKeyMatches(maybeDoc);assert(mutationResult.transformResults==null,'Transform results received by DeleteMutation.');// Unlike applyToLocalView, if we're applying a mutation to a remote
// document the server has accepted the mutation so the precondition must
// have held.
return new NoDocument(this.key,SnapshotVersion.MIN);};DeleteMutation.prototype.applyToLocalView=function(maybeDoc,baseDoc,localWriteTime){this.verifyKeyMatches(maybeDoc);if(!this.precondition.isValidFor(maybeDoc)){return maybeDoc;}if(maybeDoc){assert(maybeDoc.key.isEqual(this.key),'Can only apply mutation to document with same key');}return new NoDocument(this.key,SnapshotVersion.forDeletedDoc());};DeleteMutation.prototype.isEqual=function(other){return other instanceof DeleteMutation&&this.key.isEqual(other.key)&&this.precondition.isEqual(other.precondition);};return DeleteMutation;}(Mutation);/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var ExistenceFilter=/** @class */function(){// TODO(b/33078163): just use simplest form of existence filter for now
function ExistenceFilter(count){this.count=count;}ExistenceFilter.prototype.isEqual=function(other){return other&&other.count===this.count;};return ExistenceFilter;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Error Codes describing the different ways GRPC can fail. These are copied
* directly from GRPC's sources here:
*
* https://github.com/grpc/grpc/blob/bceec94ea4fc5f0085d81235d8e1c06798dc341a/include/grpc%2B%2B/impl/codegen/status_code_enum.h
*
* Important! The names of these identifiers matter because the string forms
* are used for reverse lookups from the webchannel stream. Do NOT change the
* names of these identifiers.
*/var RpcCode;(function(RpcCode){RpcCode[RpcCode["OK"]=0]="OK";RpcCode[RpcCode["CANCELLED"]=1]="CANCELLED";RpcCode[RpcCode["UNKNOWN"]=2]="UNKNOWN";RpcCode[RpcCode["INVALID_ARGUMENT"]=3]="INVALID_ARGUMENT";RpcCode[RpcCode["DEADLINE_EXCEEDED"]=4]="DEADLINE_EXCEEDED";RpcCode[RpcCode["NOT_FOUND"]=5]="NOT_FOUND";RpcCode[RpcCode["ALREADY_EXISTS"]=6]="ALREADY_EXISTS";RpcCode[RpcCode["PERMISSION_DENIED"]=7]="PERMISSION_DENIED";RpcCode[RpcCode["UNAUTHENTICATED"]=16]="UNAUTHENTICATED";RpcCode[RpcCode["RESOURCE_EXHAUSTED"]=8]="RESOURCE_EXHAUSTED";RpcCode[RpcCode["FAILED_PRECONDITION"]=9]="FAILED_PRECONDITION";RpcCode[RpcCode["ABORTED"]=10]="ABORTED";RpcCode[RpcCode["OUT_OF_RANGE"]=11]="OUT_OF_RANGE";RpcCode[RpcCode["UNIMPLEMENTED"]=12]="UNIMPLEMENTED";RpcCode[RpcCode["INTERNAL"]=13]="INTERNAL";RpcCode[RpcCode["UNAVAILABLE"]=14]="UNAVAILABLE";RpcCode[RpcCode["DATA_LOSS"]=15]="DATA_LOSS";})(RpcCode||(RpcCode={}));function isPermanentError(code){switch(code){case Code.OK:return fail('Treated status OK as error');case Code.CANCELLED:case Code.UNKNOWN:case Code.DEADLINE_EXCEEDED:case Code.RESOURCE_EXHAUSTED:case Code.INTERNAL:case Code.UNAVAILABLE:// Unauthenticated means something went wrong with our token and we need
// to retry with new credentials which will happen automatically.
// TODO(b/37325376): Give up after second unauthenticated error.
case Code.UNAUTHENTICATED:return false;case Code.INVALID_ARGUMENT:case Code.NOT_FOUND:case Code.ALREADY_EXISTS:case Code.PERMISSION_DENIED:case Code.FAILED_PRECONDITION:// Aborted might be retried in some scenarios, but that is dependant on
// the context and should handled individually by the calling code.
// See https://cloud.google.com/apis/design/errors.
case Code.ABORTED:case Code.OUT_OF_RANGE:case Code.UNIMPLEMENTED:case Code.DATA_LOSS:return true;default:return fail('Unknown status code: '+code);}}/**
* Maps an error Code from a GRPC status identifier like 'NOT_FOUND'.
*
* @returns The Code equivalent to the given status string or undefined if
* there is no match.
*/function mapCodeFromRpcStatus(status){// tslint:disable-next-line:no-any lookup by string
var code=RpcCode[status];if(code===undefined){return undefined;}return mapCodeFromRpcCode(code);}/**
* Maps an error Code from GRPC status code number, like 0, 1, or 14. These
* are not the same as HTTP status codes.
*
* @returns The Code equivalent to the given GRPC status code. Fails if there
* is no match.
*/function mapCodeFromRpcCode(code){if(code===undefined){// This shouldn't normally happen, but in certain error cases (like trying
// to send invalid proto messages) we may get an error with no GRPC code.
error('GRPC error has no .code');return Code.UNKNOWN;}switch(code){case RpcCode.OK:return Code.OK;case RpcCode.CANCELLED:return Code.CANCELLED;case RpcCode.UNKNOWN:return Code.UNKNOWN;case RpcCode.DEADLINE_EXCEEDED:return Code.DEADLINE_EXCEEDED;case RpcCode.RESOURCE_EXHAUSTED:return Code.RESOURCE_EXHAUSTED;case RpcCode.INTERNAL:return Code.INTERNAL;case RpcCode.UNAVAILABLE:return Code.UNAVAILABLE;case RpcCode.UNAUTHENTICATED:return Code.UNAUTHENTICATED;case RpcCode.INVALID_ARGUMENT:return Code.INVALID_ARGUMENT;case RpcCode.NOT_FOUND:return Code.NOT_FOUND;case RpcCode.ALREADY_EXISTS:return Code.ALREADY_EXISTS;case RpcCode.PERMISSION_DENIED:return Code.PERMISSION_DENIED;case RpcCode.FAILED_PRECONDITION:return Code.FAILED_PRECONDITION;case RpcCode.ABORTED:return Code.ABORTED;case RpcCode.OUT_OF_RANGE:return Code.OUT_OF_RANGE;case RpcCode.UNIMPLEMENTED:return Code.UNIMPLEMENTED;case RpcCode.DATA_LOSS:return Code.DATA_LOSS;default:return fail('Unknown status code: '+code);}}/**
* Maps an RPC code from a Code. This is the reverse operation from
* mapCodeFromRpcCode and should really only be used in tests.
*/function mapRpcCodeFromCode(code){if(code===undefined){return RpcCode.OK;}switch(code){case Code.OK:return RpcCode.OK;case Code.CANCELLED:return RpcCode.CANCELLED;case Code.UNKNOWN:return RpcCode.UNKNOWN;case Code.DEADLINE_EXCEEDED:return RpcCode.DEADLINE_EXCEEDED;case Code.RESOURCE_EXHAUSTED:return RpcCode.RESOURCE_EXHAUSTED;case Code.INTERNAL:return RpcCode.INTERNAL;case Code.UNAVAILABLE:return RpcCode.UNAVAILABLE;case Code.UNAUTHENTICATED:return RpcCode.UNAUTHENTICATED;case Code.INVALID_ARGUMENT:return RpcCode.INVALID_ARGUMENT;case Code.NOT_FOUND:return RpcCode.NOT_FOUND;case Code.ALREADY_EXISTS:return RpcCode.ALREADY_EXISTS;case Code.PERMISSION_DENIED:return RpcCode.PERMISSION_DENIED;case Code.FAILED_PRECONDITION:return RpcCode.FAILED_PRECONDITION;case Code.ABORTED:return RpcCode.ABORTED;case Code.OUT_OF_RANGE:return RpcCode.OUT_OF_RANGE;case Code.UNIMPLEMENTED:return RpcCode.UNIMPLEMENTED;case Code.DATA_LOSS:return RpcCode.DATA_LOSS;default:return fail('Unknown status code: '+code);}}/**
* Converts an HTTP Status Code to the equivalent error code.
*
* @param status An HTTP Status Code, like 200, 404, 503, etc.
* @returns The equivalent Code. Unknown status codes are mapped to
* Code.UNKNOWN.
*/function mapCodeFromHttpStatus(status){// The canonical error codes for Google APIs [1] specify mapping onto HTTP
// status codes but the mapping is not bijective. In each case of ambiguity
// this function chooses a primary error.
//
// [1]
// https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
switch(status){case 200:// OK
return Code.OK;case 400:// Bad Request
return Code.INVALID_ARGUMENT;// Other possibilities based on the forward mapping
// return Code.FAILED_PRECONDITION;
// return Code.OUT_OF_RANGE;
case 401:// Unauthorized
return Code.UNAUTHENTICATED;case 403:// Forbidden
return Code.PERMISSION_DENIED;case 404:// Not Found
return Code.NOT_FOUND;case 409:// Conflict
return Code.ABORTED;// Other possibilities:
// return Code.ALREADY_EXISTS;
case 416:// Range Not Satisfiable
return Code.OUT_OF_RANGE;case 429:// Too Many Requests
return Code.RESOURCE_EXHAUSTED;case 499:// Client Closed Request
return Code.CANCELLED;case 500:// Internal Server Error
return Code.UNKNOWN;// Other possibilities:
// return Code.INTERNAL;
// return Code.DATA_LOSS;
case 501:// Unimplemented
return Code.UNIMPLEMENTED;case 503:// Service Unavailable
return Code.UNAVAILABLE;case 504:// Gateway Timeout
return Code.DEADLINE_EXCEEDED;default:if(status>=200&&status<300)return Code.OK;if(status>=400&&status<500)return Code.FAILED_PRECONDITION;if(status>=500&&status<600)return Code.INTERNAL;return Code.UNKNOWN;}}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* SortedSet is an immutable (copy-on-write) collection that holds elements
* in order specified by the provided comparator.
*
* NOTE: if provided comparator returns 0 for two elements, we consider them to
* be equal!
*/var SortedSet=/** @class */function(){function SortedSet(comparator){this.comparator=comparator;this.data=new SortedMap(this.comparator);}/**
* Creates a SortedSet from the keys of the map.
* This is currently implemented as an O(n) copy.
*/SortedSet.fromMapKeys=function(map){var keys=new SortedSet(map.comparator);map.forEach(function(key){keys=keys.add(key);});return keys;};SortedSet.prototype.has=function(elem){return this.data.get(elem)!==null;};SortedSet.prototype.first=function(){return this.data.minKey();};SortedSet.prototype.last=function(){return this.data.maxKey();};Object.defineProperty(SortedSet.prototype,"size",{get:function(){return this.data.size;},enumerable:true,configurable:true});SortedSet.prototype.indexOf=function(elem){return this.data.indexOf(elem);};/** Iterates elements in order defined by "comparator" */SortedSet.prototype.forEach=function(cb){this.data.inorderTraversal(function(k,v){cb(k);return false;});};/** Iterates over `elem`s such that: range[0] <= elem < range[1]. */SortedSet.prototype.forEachInRange=function(range,cb){var iter=this.data.getIteratorFrom(range[0]);while(iter.hasNext()){var elem=iter.getNext();if(this.comparator(elem.key,range[1])>=0)return;cb(elem.key);}};/**
* Iterates over `elem`s such that: start <= elem until false is returned.
*/SortedSet.prototype.forEachWhile=function(cb,start){var iter;if(start!==undefined){iter=this.data.getIteratorFrom(start);}else{iter=this.data.getIterator();}while(iter.hasNext()){var elem=iter.getNext();var result=cb(elem.key);if(!result)return;}};/** Finds the least element greater than or equal to `elem`. */SortedSet.prototype.firstAfterOrEqual=function(elem){var iter=this.data.getIteratorFrom(elem);return iter.hasNext()?iter.getNext().key:null;};/** Inserts or updates an element */SortedSet.prototype.add=function(elem){return this.copy(this.data.remove(elem).insert(elem,true));};/** Deletes an element */SortedSet.prototype.delete=function(elem){if(!this.has(elem))return this;return this.copy(this.data.remove(elem));};SortedSet.prototype.isEmpty=function(){return this.data.isEmpty();};SortedSet.prototype.unionWith=function(other){var result=this;other.forEach(function(elem){result=result.add(elem);});return result;};SortedSet.prototype.isEqual=function(other){if(!(other instanceof SortedSet))return false;if(this.size!==other.size)return false;var thisIt=this.data.getIterator();var otherIt=other.data.getIterator();while(thisIt.hasNext()){var thisElem=thisIt.getNext().key;var otherElem=otherIt.getNext().key;if(this.comparator(thisElem,otherElem)!==0)return false;}return true;};SortedSet.prototype.toString=function(){var result=[];this.forEach(function(elem){return result.push(elem);});return'SortedSet('+result.toString()+')';};SortedSet.prototype.copy=function(data){var result=new SortedSet(this.comparator);result.data=data;return result;};return SortedSet;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var EMPTY_MAYBE_DOCUMENT_MAP=new SortedMap(DocumentKey.comparator);function maybeDocumentMap(){return EMPTY_MAYBE_DOCUMENT_MAP;}var EMPTY_DOCUMENT_MAP=new SortedMap(DocumentKey.comparator);function documentMap(){return EMPTY_DOCUMENT_MAP;}var EMPTY_DOCUMENT_VERSION_MAP=new SortedMap(DocumentKey.comparator);function documentVersionMap(){return EMPTY_DOCUMENT_VERSION_MAP;}var EMPTY_DOCUMENT_KEY_SET=new SortedSet(DocumentKey.comparator);function documentKeySet(){return EMPTY_DOCUMENT_KEY_SET;}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* An event from the RemoteStore. It is split into targetChanges (changes to the
* state or the set of documents in our watched targets) and documentUpdates
* (changes to the actual documents).
*/var RemoteEvent=/** @class */function(){function RemoteEvent(/**
* The snapshot version this event brings us up to, or MIN if not set.
*/snapshotVersion,/**
* A map from target to changes to the target. See TargetChange.
*/targetChanges,/**
* A set of which documents have changed or been deleted, along with the
* doc's new values (if not deleted).
*/documentUpdates,/**
* A set of which document updates are due only to limbo resolution targets.
*/limboDocuments){this.snapshotVersion=snapshotVersion;this.targetChanges=targetChanges;this.documentUpdates=documentUpdates;this.limboDocuments=limboDocuments;}RemoteEvent.prototype.addDocumentUpdate=function(doc){this.documentUpdates=this.documentUpdates.insert(doc.key,doc);};RemoteEvent.prototype.handleExistenceFilterMismatch=function(targetId){/*
* An existence filter mismatch will reset the query and we need to reset
* the mapping to contain no documents and an empty resume token.
*
* Note:
* * The reset mapping is empty, specifically forcing the consumer of the
* change to forget all keys for this targetID;
* * The resume snapshot for this target must be reset
* * The target must be unacked because unwatching and rewatching
* introduces a race for changes.
*/this.targetChanges[targetId]={mapping:new ResetMapping(),snapshotVersion:SnapshotVersion.MIN,currentStatusUpdate:CurrentStatusUpdate.MarkNotCurrent,resumeToken:emptyByteString()};};/**
* Synthesize a delete change if necessary for the given limbo target.
*/RemoteEvent.prototype.synthesizeDeleteForLimboTargetChange=function(targetChange,key){if(targetChange.currentStatusUpdate===CurrentStatusUpdate.MarkCurrent&&!this.documentUpdates.get(key)){// When listening to a query the server responds with a snapshot
// containing documents matching the query and a current marker
// telling us we're now in sync. It's possible for these to arrive
// as separate remote events or as a single remote event.
// For a document query, there will be no documents sent in the
// response if the document doesn't exist.
//
// If the snapshot arrives separately from the current marker,
// we handle it normally and updateTrackedLimbos will resolve the
// limbo status of the document, removing it from limboDocumentRefs.
// This works because clients only initiate limbo resolution when
// a target is current and because all current targets are
// always at a consistent snapshot.
//
// However, if the document doesn't exist and the current marker
// arrives, the document is not present in the snapshot and our
// normal view handling would consider the document to remain in
// limbo indefinitely because there are no updates to the document.
// To avoid this, we specially handle this case here:
// synthesizing a delete.
//
// TODO(dimond): Ideally we would have an explicit lookup query
// instead resulting in an explicit delete message and we could
// remove this special logic.
this.documentUpdates=this.documentUpdates.insert(key,new NoDocument(key,this.snapshotVersion));this.limboDocuments=this.limboDocuments.add(key);}};return RemoteEvent;}();/**
* Represents an update to the current status of a target, either explicitly
* having no new state, or the new value to set. Note "current" has special
* meaning for in the RPC protocol that implies that a target is both up-to-date
* and consistent with the rest of the watch stream.
*/var CurrentStatusUpdate;(function(CurrentStatusUpdate){/** The current status is not affected and should not be modified. */CurrentStatusUpdate[CurrentStatusUpdate["None"]=0]="None";/** The target must be marked as no longer "current". */CurrentStatusUpdate[CurrentStatusUpdate["MarkNotCurrent"]=1]="MarkNotCurrent";/** The target must be marked as "current". */CurrentStatusUpdate[CurrentStatusUpdate["MarkCurrent"]=2]="MarkCurrent";})(CurrentStatusUpdate||(CurrentStatusUpdate={}));var EMPTY_KEY_SET=documentKeySet();var ResetMapping=/** @class */function(){function ResetMapping(){this.docs=EMPTY_KEY_SET;}Object.defineProperty(ResetMapping.prototype,"documents",{get:function(){return this.docs;},enumerable:true,configurable:true});ResetMapping.prototype.add=function(key){this.docs=this.docs.add(key);};ResetMapping.prototype.delete=function(key){this.docs=this.docs.delete(key);};ResetMapping.prototype.isEqual=function(other){return other!==null&&this.docs.isEqual(other.docs);};ResetMapping.prototype.filterUpdates=function(existingKeys){// No-op. Resets don't get filtered.
};return ResetMapping;}();var UpdateMapping=/** @class */function(){function UpdateMapping(){this.addedDocuments=EMPTY_KEY_SET;this.removedDocuments=EMPTY_KEY_SET;}UpdateMapping.prototype.applyToKeySet=function(keys){var result=keys;this.addedDocuments.forEach(function(key){return result=result.add(key);});this.removedDocuments.forEach(function(key){return result=result.delete(key);});return result;};UpdateMapping.prototype.add=function(key){this.addedDocuments=this.addedDocuments.add(key);this.removedDocuments=this.removedDocuments.delete(key);};UpdateMapping.prototype.delete=function(key){this.addedDocuments=this.addedDocuments.delete(key);this.removedDocuments=this.removedDocuments.add(key);};UpdateMapping.prototype.isEqual=function(other){return other!==null&&this.addedDocuments.isEqual(other.addedDocuments)&&this.removedDocuments.isEqual(other.removedDocuments);};/**
* Strips out mapping changes that aren't actually changes. That is, if the document already
* existed in the target, and is being added in the target, and this is not a reset, we can
* skip doing the work to associate the document with the target because it has already been done.
*/UpdateMapping.prototype.filterUpdates=function(existingKeys){var results=this.addedDocuments;this.addedDocuments.forEach(function(docKey){if(existingKeys.has(docKey)){results=results.delete(docKey);}});this.addedDocuments=results;};return UpdateMapping;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Represents a changed document and a list of target ids to which this change
* applies.
*
* If document has been deleted NoDocument will be provided.
*/var DocumentWatchChange=/** @class */function(){function DocumentWatchChange(/** The new document applies to all of these targets. */updatedTargetIds,/** The new document is removed from all of these targets. */removedTargetIds,/** The key of the document for this change. */key,/**
* The new document or NoDocument if it was deleted. Is null if the
* document went out of view without the server sending a new document.
*/newDoc){this.updatedTargetIds=updatedTargetIds;this.removedTargetIds=removedTargetIds;this.key=key;this.newDoc=newDoc;}return DocumentWatchChange;}();var ExistenceFilterChange=/** @class */function(){function ExistenceFilterChange(targetId,existenceFilter){this.targetId=targetId;this.existenceFilter=existenceFilter;}return ExistenceFilterChange;}();var WatchTargetChangeState;(function(WatchTargetChangeState){WatchTargetChangeState[WatchTargetChangeState["NoChange"]=0]="NoChange";WatchTargetChangeState[WatchTargetChangeState["Added"]=1]="Added";WatchTargetChangeState[WatchTargetChangeState["Removed"]=2]="Removed";WatchTargetChangeState[WatchTargetChangeState["Current"]=3]="Current";WatchTargetChangeState[WatchTargetChangeState["Reset"]=4]="Reset";})(WatchTargetChangeState||(WatchTargetChangeState={}));var WatchTargetChange=/** @class */function(){function WatchTargetChange(/** What kind of change occurred to the watch target. */state,/** The target IDs that were added/removed/set. */targetIds,/**
* An opaque, server-assigned token that allows watching a query to be
* resumed after disconnecting without retransmitting all the data that
* matches the query. The resume token essentially identifies a point in
* time from which the server should resume sending results.
*/resumeToken,/** An RPC error indicating why the watch failed. */cause){if(resumeToken===void 0){resumeToken=emptyByteString();}if(cause===void 0){cause=null;}this.state=state;this.targetIds=targetIds;this.resumeToken=resumeToken;this.cause=cause;}return WatchTargetChange;}();/**
* A helper class to accumulate watch changes into a RemoteEvent and other
* target information.
*/var WatchChangeAggregator=/** @class */function(){function WatchChangeAggregator(snapshotVersion,listenTargets,pendingTargetResponses){this.snapshotVersion=snapshotVersion;this.listenTargets=listenTargets;/** The existence filter - if any - for the given target IDs. */this.existenceFilters={};/** Keeps track of the current target mappings */this.targetChanges={};/** Keeps track of document to update */this.documentUpdates=maybeDocumentMap();/** Whether this aggregator was frozen and can no longer be modified */this.frozen=false;/** Tracks which document updates are due only to limbo target resolution */this.limboDocuments=documentKeySet();this.pendingTargetResponses=shallowCopy(pendingTargetResponses);}/** Aggregates a watch change into the current state */WatchChangeAggregator.prototype.add=function(watchChange){assert(!this.frozen,'Trying to modify frozen WatchChangeAggregator.');if(watchChange instanceof DocumentWatchChange){this.addDocumentChange(watchChange);}else if(watchChange instanceof WatchTargetChange){this.addTargetChange(watchChange);}else if(watchChange instanceof ExistenceFilterChange){this.addExistenceFilterChange(watchChange);}else{fail('Unknown watch change: '+watchChange);}};/** Aggregates all provided watch changes to the current state in order */WatchChangeAggregator.prototype.addChanges=function(watchChanges){var _this=this;assert(!this.frozen,'Trying to modify frozen WatchChangeAggregator.');watchChanges.forEach(function(change){return _this.add(change);});};/**
* Converts the current state into a remote event with the snapshot version
* provided via the constructor.
*/WatchChangeAggregator.prototype.createRemoteEvent=function(){var _this=this;var targetChanges=this.targetChanges;// Remove all the non-active targets from the remote event.
forEachNumber(this.targetChanges,function(targetId){if(!_this.isActiveTarget(targetId)){delete targetChanges[targetId];}});// Mark this aggregator as frozen so no further modifications are made
this.frozen=true;return new RemoteEvent(this.snapshotVersion,targetChanges,this.documentUpdates,this.limboDocuments);};WatchChangeAggregator.prototype.ensureTargetChange=function(targetId){var change=this.targetChanges[targetId];if(!change){// Create an UpdateMapping by default, since resets are always explicit.
change={currentStatusUpdate:CurrentStatusUpdate.None,snapshotVersion:this.snapshotVersion,mapping:new UpdateMapping(),resumeToken:emptyByteString()};this.targetChanges[targetId]=change;}return change;};/**
* Returns the QueryData instance for the given targetId if the target is
* active, or null otherwise. For a target to be considered active there must
* be no pending acks we're waiting for and it must be in the current list of
* targets that the client cares about.
*/WatchChangeAggregator.prototype.queryDataForActiveTarget=function(targetId){var queryData=this.listenTargets[targetId];return queryData&&!contains(this.pendingTargetResponses,targetId)?queryData:null;};/**
* Defers to queryForActiveTarget to determine if the given targetId
* corresponds to an active target.
*
* This method is visible for testing.
*/WatchChangeAggregator.prototype.isActiveTarget=function(targetId){return this.queryDataForActiveTarget(targetId)!==null;};/**
* Updates limbo document tracking for a given target-document mapping change.
* If the target is a limbo target, and the change for the document has only
* seen limbo targets so far, and we are not already tracking a change for
* this document, then consider this document a limbo document update.
* Otherwise, ensure that we don't consider this document a limbo document.
* Returns true if the change still has only seen limbo resolution changes.
*/WatchChangeAggregator.prototype.updateLimboDocuments=function(key,queryData,isOnlyLimbo){if(!isOnlyLimbo){// It wasn't a limbo doc before, so it definitely isn't now.
return false;}if(!this.documentUpdates.get(key)){// We haven't seen the document update for this key yet.
if(queryData.purpose===QueryPurpose.LimboResolution){this.limboDocuments=this.limboDocuments.add(key);return true;}else{// We haven't seen the document before, but this is a non-limbo target.
// Since we haven't seen it, we know it's not in our set of limbo docs.
// Return false to ensure that this key is marked as non-limbo.
return false;}}else if(queryData.purpose===QueryPurpose.LimboResolution){// We have only seen limbo targets so far for this document, and this is
// another limbo target.
return true;}else{// We haven't marked this as non-limbo yet, but this target is not a limbo
// target. Mark the key as non-limbo and make sure it isn't in our set.
this.limboDocuments=this.limboDocuments.delete(key);return false;}};WatchChangeAggregator.prototype.addDocumentChange=function(docChange){var relevant=false;var isOnlyLimbo=true;for(var _i=0,_a=docChange.updatedTargetIds;_i<_a.length;_i++){var targetId=_a[_i];var queryData=this.queryDataForActiveTarget(targetId);if(queryData){var change=this.ensureTargetChange(targetId);isOnlyLimbo=this.updateLimboDocuments(docChange.key,queryData,isOnlyLimbo);change.mapping.add(docChange.key);relevant=true;}}for(var _b=0,_c=docChange.removedTargetIds;_b<_c.length;_b++){var targetId=_c[_b];var queryData=this.queryDataForActiveTarget(targetId);if(queryData){var change=this.ensureTargetChange(targetId);isOnlyLimbo=this.updateLimboDocuments(docChange.key,queryData,isOnlyLimbo);change.mapping.delete(docChange.key);relevant=true;}}// Only update the document if there is a new document to replace to an
// active target that is being listened to, this might be just a target
// update instead.
if(docChange.newDoc&&relevant){this.documentUpdates=this.documentUpdates.insert(docChange.key,docChange.newDoc);}};WatchChangeAggregator.prototype.addTargetChange=function(targetChange){var _this=this;targetChange.targetIds.forEach(function(targetId){var change=_this.ensureTargetChange(targetId);switch(targetChange.state){case WatchTargetChangeState.NoChange:if(_this.isActiveTarget(targetId)){// Creating the change above satisfies the semantics of no-change.
applyResumeToken(change,targetChange.resumeToken);}break;case WatchTargetChangeState.Added:// We need to decrement the number of pending acks needed from watch
// for this targetId.
_this.recordTargetResponse(targetId);if(!contains(_this.pendingTargetResponses,targetId)){// We have a freshly added target, so we need to reset any state
// that we had previously This can happen e.g. when remove and add
// back a target for existence filter mismatches.
change.mapping=new UpdateMapping();change.currentStatusUpdate=CurrentStatusUpdate.None;delete _this.existenceFilters[targetId];}applyResumeToken(change,targetChange.resumeToken);break;case WatchTargetChangeState.Removed:// We need to keep track of removed targets to we can
// post-filter and remove any target changes.
// We need to decrement the number of pending acks needed from watch
// for this targetId.
_this.recordTargetResponse(targetId);assert(!targetChange.cause,'WatchChangeAggregator does not handle errored targets');break;case WatchTargetChangeState.Current:if(_this.isActiveTarget(targetId)){change.currentStatusUpdate=CurrentStatusUpdate.MarkCurrent;applyResumeToken(change,targetChange.resumeToken);}break;case WatchTargetChangeState.Reset:if(_this.isActiveTarget(targetId)){// Overwrite any existing target mapping with a reset
// mapping. Every subsequent update will modify the reset
// mapping, not an update mapping.
change.mapping=new ResetMapping();applyResumeToken(change,targetChange.resumeToken);}break;default:fail('Unknown target watch change state: '+targetChange.state);}});};/**
* Record that we get a watch target add/remove by decrementing the number of
* pending target responses that we have.
*/WatchChangeAggregator.prototype.recordTargetResponse=function(targetId){var newCount=(this.pendingTargetResponses[targetId]||0)-1;if(newCount===0){delete this.pendingTargetResponses[targetId];}else{this.pendingTargetResponses[targetId]=newCount;}};WatchChangeAggregator.prototype.addExistenceFilterChange=function(change){if(this.isActiveTarget(change.targetId)){this.existenceFilters[change.targetId]=change.existenceFilter;}};return WatchChangeAggregator;}();/**
* Applies the resume token to the TargetChange, but only when it has a new
* value. null and empty resumeTokens are discarded.
*/function applyResumeToken(change,resumeToken){if(resumeToken.length>0){change.resumeToken=resumeToken;}}/**
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//** Transforms a value into a server-generated timestamp. */var ServerTimestampTransform=/** @class */function(){function ServerTimestampTransform(){}ServerTimestampTransform.prototype.applyToLocalView=function(previousValue,localWriteTime){return new ServerTimestampValue(localWriteTime,previousValue);};ServerTimestampTransform.prototype.applyToRemoteDocument=function(previousValue,transformResult){return transformResult;};ServerTimestampTransform.prototype.isEqual=function(other){return other instanceof ServerTimestampTransform;};ServerTimestampTransform.instance=new ServerTimestampTransform();return ServerTimestampTransform;}();/** Transforms an array value via a union operation. */var ArrayUnionTransformOperation=/** @class */function(){function ArrayUnionTransformOperation(elements){this.elements=elements;}ArrayUnionTransformOperation.prototype.applyToLocalView=function(previousValue,localWriteTime){return this.apply(previousValue);};ArrayUnionTransformOperation.prototype.applyToRemoteDocument=function(previousValue,transformResult){// The server just sends null as the transform result for array operations,
// so we have to calculate a result the same as we do for local
// applications.
return this.apply(previousValue);};ArrayUnionTransformOperation.prototype.apply=function(previousValue){var result=coercedFieldValuesArray(previousValue);var _loop_1=function(toUnion){if(!result.find(function(element){return element.isEqual(toUnion);})){result.push(toUnion);}};for(var _i=0,_a=this.elements;_i<_a.length;_i++){var toUnion=_a[_i];_loop_1(toUnion);}return new ArrayValue(result);};ArrayUnionTransformOperation.prototype.isEqual=function(other){return other instanceof ArrayUnionTransformOperation&&arrayEquals(other.elements,this.elements);};return ArrayUnionTransformOperation;}();/** Transforms an array value via a remove operation. */var ArrayRemoveTransformOperation=/** @class */function(){function ArrayRemoveTransformOperation(elements){this.elements=elements;}ArrayRemoveTransformOperation.prototype.applyToLocalView=function(previousValue,localWriteTime){return this.apply(previousValue);};ArrayRemoveTransformOperation.prototype.applyToRemoteDocument=function(previousValue,transformResult){// The server just sends null as the transform result for array operations,
// so we have to calculate a result the same as we do for local
// applications.
return this.apply(previousValue);};ArrayRemoveTransformOperation.prototype.apply=function(previousValue){var result=coercedFieldValuesArray(previousValue);var _loop_2=function(toRemove){result=result.filter(function(element){return!element.isEqual(toRemove);});};for(var _i=0,_a=this.elements;_i<_a.length;_i++){var toRemove=_a[_i];_loop_2(toRemove);}return new ArrayValue(result);};ArrayRemoveTransformOperation.prototype.isEqual=function(other){return other instanceof ArrayRemoveTransformOperation&&arrayEquals(other.elements,this.elements);};return ArrayRemoveTransformOperation;}();function coercedFieldValuesArray(value){if(value instanceof ArrayValue){return value.internalValue.slice();}else{// coerce to empty array.
return[];}}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var DIRECTIONS=function(){var dirs={};dirs[Direction.ASCENDING.name]='ASCENDING';dirs[Direction.DESCENDING.name]='DESCENDING';return dirs;}();var OPERATORS=function(){var ops={};ops[RelationOp.LESS_THAN.name]='LESS_THAN';ops[RelationOp.LESS_THAN_OR_EQUAL.name]='LESS_THAN_OR_EQUAL';ops[RelationOp.GREATER_THAN.name]='GREATER_THAN';ops[RelationOp.GREATER_THAN_OR_EQUAL.name]='GREATER_THAN_OR_EQUAL';ops[RelationOp.EQUAL.name]='EQUAL';ops[RelationOp.ARRAY_CONTAINS.name]='ARRAY_CONTAINS';return ops;}();// A RegExp matching ISO 8601 UTC timestamps with optional fraction.
var ISO_REG_EXP=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function assertPresent(value,description){assert(!isNullOrUndefined(value),description+' is missing');}function parseInt64(value){// TODO(bjornick): Handle int64 greater than 53 bits.
if(typeof value==='number'){return value;}else if(typeof value==='string'){return Number(value);}else{return fail("can't parse "+value);}}/**
* Generates JsonObject values for the Datastore API suitable for sending to
* either GRPC stub methods or via the JSON/HTTP REST API.
* TODO(klimt): We can remove the databaseId argument if we keep the full
* resource name in documents.
*/var JsonProtoSerializer=/** @class */function(){function JsonProtoSerializer(databaseId,options){this.databaseId=databaseId;this.options=options;}JsonProtoSerializer.prototype.emptyByteString=function(){if(this.options.useProto3Json){return'';}else{return new Uint8Array(0);}};JsonProtoSerializer.prototype.unsafeCastProtoByteString=function(byteString){// byteStrings can be either string or UInt8Array, but the typings say
// it's always a string. Cast as string to avoid type check failing
return byteString;};JsonProtoSerializer.prototype.fromRpcStatus=function(status){var code=status.code===undefined?Code.UNKNOWN:mapCodeFromRpcCode(status.code);return new FirestoreError(code,status.message||'');};/**
* Returns a value for a number (or undefined) that's appropriate to put into
* a google.protobuf.Int32Value proto.
* DO NOT USE THIS FOR ANYTHING ELSE.
* This method cheats. It's typed as returning "number" because that's what
* our generated proto interfaces say Int32Value must be. But GRPC actually
* expects a { value: <number> } struct.
*/JsonProtoSerializer.prototype.toInt32Value=function(val){if(!isNullOrUndefined(val)){// tslint:disable-next-line:no-any We need to match generated Proto types.
return{value:val};}else{return undefined;}};/**
* Returns a number (or null) from a google.protobuf.Int32Value proto.
* DO NOT USE THIS FOR ANYTHING ELSE.
* This method cheats. It's typed as accepting "number" because that's what
* our generated proto interfaces say Int32Value must be, but it actually
* accepts { value: number } to match our serialization in toInt32Value().
*/JsonProtoSerializer.prototype.fromInt32Value=function(val){var result;if(typeof val==='object'){// tslint:disable-next-line:no-any We need to match generated Proto types.
result=val.value;}else{// We accept raw numbers (without the {value: ... } wrapper) for
// compatibility with legacy persisted data.
result=val;}return isNullOrUndefined(result)?null:result;};/**
* Returns a value for a Date that's appropriate to put into a proto.
* DO NOT USE THIS FOR ANYTHING ELSE.
* This method cheats. It's typed as returning "string" because that's what
* our generated proto interfaces say dates must be. But it's easier and safer
* to actually return a Timestamp proto.
*/JsonProtoSerializer.prototype.toTimestamp=function(timestamp){return{seconds:timestamp.seconds,nanos:timestamp.nanoseconds// tslint:disable-next-line:no-any
};};JsonProtoSerializer.prototype.fromTimestamp=function(date){// The json interface (for the browser) will return an iso timestamp string,
// while the proto js library (for node) will return a
// google.protobuf.Timestamp instance.
if(typeof date==='string'){// TODO(b/37282237): Use strings for Proto3 timestamps
// assert(this.options.useProto3Json,
// 'The timestamp string format requires Proto3.');
return this.fromIso8601String(date);}else{assert(!!date,'Cannot deserialize null or undefined timestamp.');// TODO(b/37282237): Use strings for Proto3 timestamps
// assert(!this.options.useProto3Json,
// 'The timestamp instance format requires Proto JS.');
var seconds=parseInt64(date.seconds||'0');var nanos=date.nanos||0;return new Timestamp(seconds,nanos);}};JsonProtoSerializer.prototype.fromIso8601String=function(utc){// The date string can have higher precision (nanos) than the Date class
// (millis), so we do some custom parsing here.
// Parse the nanos right out of the string.
var nanos=0;var fraction=ISO_REG_EXP.exec(utc);assert(!!fraction,'invalid timestamp: '+utc);if(fraction[1]){// Pad the fraction out to 9 digits (nanos).
var nanoStr=fraction[1];nanoStr=(nanoStr+'000000000').substr(0,9);nanos=Number(nanoStr);}// Parse the date to get the seconds.
var date=new Date(utc);var seconds=Math.floor(date.getTime()/1000);return new Timestamp(seconds,nanos);};/**
* Returns a value for bytes that's appropriate to put in a proto.
* DO NOT USE THIS FOR ANYTHING ELSE.
* This method cheats. It's typed as returning "string" because that's what
* our generated proto interfaces say bytes must be. But it should return
* an Uint8Array in Node.
*/JsonProtoSerializer.prototype.toBytes=function(bytes){if(this.options.useProto3Json){return bytes.toBase64();}else{// The typings say it's a string, but it needs to be a Uint8Array in Node.
return this.unsafeCastProtoByteString(bytes.toUint8Array());}};/**
* Parse the blob from the protos into the internal Blob class. Note that the
* typings assume all blobs are strings, but they are actually Uint8Arrays
* on Node.
*/JsonProtoSerializer.prototype.fromBlob=function(blob){if(typeof blob==='string'){assert(this.options.useProto3Json,'Expected bytes to be passed in as Uint8Array, but got a string instead.');return Blob.fromBase64String(blob);}else{assert(!this.options.useProto3Json,'Expected bytes to be passed in as string, but got something else instead.');return Blob.fromUint8Array(blob);}};JsonProtoSerializer.prototype.toVersion=function(version){return this.toTimestamp(version.toTimestamp());};JsonProtoSerializer.prototype.fromVersion=function(version){assert(!!version,"Trying to deserialize version that isn't set");return SnapshotVersion.fromTimestamp(this.fromTimestamp(version));};JsonProtoSerializer.prototype.toResourceName=function(databaseId,path){return this.fullyQualifiedPrefixPath(databaseId).child('documents').child(path).canonicalString();};JsonProtoSerializer.prototype.fromResourceName=function(name){var resource=ResourcePath.fromString(name);assert(this.isValidResourceName(resource),'Tried to deserialize invalid key '+resource.toString());return resource;};JsonProtoSerializer.prototype.toName=function(key){return this.toResourceName(this.databaseId,key.path);};JsonProtoSerializer.prototype.fromName=function(name){var resource=this.fromResourceName(name);assert(resource.get(1)===this.databaseId.projectId,'Tried to deserialize key from different project: '+resource.get(1)+' vs '+this.databaseId.projectId);assert(!resource.get(3)&&!this.databaseId.database||resource.get(3)===this.databaseId.database,'Tried to deserialize key from different database: '+resource.get(3)+' vs '+this.databaseId.database);return new DocumentKey(this.extractLocalPathFromResourceName(resource));};JsonProtoSerializer.prototype.toQueryPath=function(path){if(path.length===0){// If the path is empty, the backend requires we leave off the /documents
// at the end.
return this.encodedDatabaseId;}return this.toResourceName(this.databaseId,path);};JsonProtoSerializer.prototype.fromQueryPath=function(name){var resourceName=this.fromResourceName(name);if(resourceName.length===4){return ResourcePath.EMPTY_PATH;}return this.extractLocalPathFromResourceName(resourceName);};Object.defineProperty(JsonProtoSerializer.prototype,"encodedDatabaseId",{get:function(){var path=new ResourcePath(['projects',this.databaseId.projectId,'databases',this.databaseId.database]);return path.canonicalString();},enumerable:true,configurable:true});JsonProtoSerializer.prototype.fullyQualifiedPrefixPath=function(databaseId){return new ResourcePath(['projects',databaseId.projectId,'databases',databaseId.database]);};JsonProtoSerializer.prototype.extractLocalPathFromResourceName=function(resourceName){assert(resourceName.length>4&&resourceName.get(4)==='documents','tried to deserialize invalid key '+resourceName.toString());return resourceName.popFirst(5);};JsonProtoSerializer.prototype.isValidResourceName=function(path){// Resource names have at least 4 components (project ID, database ID)
return path.length>=4&&path.get(0)==='projects'&&path.get(2)==='databases';};JsonProtoSerializer.prototype.toValue=function(val){if(val instanceof NullValue){return{nullValue:'NULL_VALUE'};}else if(val instanceof BooleanValue){return{booleanValue:val.value()};}else if(val instanceof IntegerValue){return{integerValue:''+val.value()};}else if(val instanceof DoubleValue){var doubleValue=val.value();if(this.options.useProto3Json){// Proto 3 let's us encode NaN and Infinity as string values as
// expected by the backend. This is currently not checked by our unit
// tests because they rely on protobuf.js.
if(isNaN(doubleValue)){return{doubleValue:'NaN'};}else if(doubleValue===Infinity){return{doubleValue:'Infinity'};}else if(doubleValue===-Infinity){return{doubleValue:'-Infinity'};}}return{doubleValue:val.value()};}else if(val instanceof StringValue){return{stringValue:val.value()};}else if(val instanceof ObjectValue){return{mapValue:this.toMapValue(val)};}else if(val instanceof ArrayValue){return{arrayValue:this.toArrayValue(val)};}else if(val instanceof TimestampValue){return{timestampValue:this.toTimestamp(val.internalValue)};}else if(val instanceof GeoPointValue){return{geoPointValue:{latitude:val.value().latitude,longitude:val.value().longitude}};}else if(val instanceof BlobValue){return{bytesValue:this.toBytes(val.value())};}else if(val instanceof RefValue){return{referenceValue:this.toResourceName(val.databaseId,val.key.path)};}else{return fail('Unknown FieldValue '+JSON.stringify(val));}};JsonProtoSerializer.prototype.fromValue=function(obj){var _this=this;// tslint:disable-next-line:no-any
var type=obj['value_type'];if(hasTag(obj,type,'nullValue')){return NullValue.INSTANCE;}else if(hasTag(obj,type,'booleanValue')){return BooleanValue.of(obj.booleanValue);}else if(hasTag(obj,type,'integerValue')){return new IntegerValue(parseInt64(obj.integerValue));}else if(hasTag(obj,type,'doubleValue')){if(this.options.useProto3Json){// Proto 3 uses the string values 'NaN' and 'Infinity'.
if(obj.doubleValue==='NaN'){return DoubleValue.NAN;}else if(obj.doubleValue==='Infinity'){return DoubleValue.POSITIVE_INFINITY;}else if(obj.doubleValue==='-Infinity'){return DoubleValue.NEGATIVE_INFINITY;}}return new DoubleValue(obj.doubleValue);}else if(hasTag(obj,type,'stringValue')){return new StringValue(obj.stringValue);}else if(hasTag(obj,type,'mapValue')){return this.fromFields(obj.mapValue.fields||{});}else if(hasTag(obj,type,'arrayValue')){// "values" is not present if the array is empty
assertPresent(obj.arrayValue,'arrayValue');var values=obj.arrayValue.values||[];return new ArrayValue(values.map(function(v){return _this.fromValue(v);}));}else if(hasTag(obj,type,'timestampValue')){assertPresent(obj.timestampValue,'timestampValue');return new TimestampValue(this.fromTimestamp(obj.timestampValue));}else if(hasTag(obj,type,'geoPointValue')){assertPresent(obj.geoPointValue,'geoPointValue');var latitude=obj.geoPointValue.latitude||0;var longitude=obj.geoPointValue.longitude||0;return new GeoPointValue(new GeoPoint(latitude,longitude));}else if(hasTag(obj,type,'bytesValue')){assertPresent(obj.bytesValue,'bytesValue');var blob=this.fromBlob(obj.bytesValue);return new BlobValue(blob);}else if(hasTag(obj,type,'referenceValue')){assertPresent(obj.referenceValue,'referenceValue');var resourceName=this.fromResourceName(obj.referenceValue);var dbId=new DatabaseId(resourceName.get(1),resourceName.get(3));var key=new DocumentKey(this.extractLocalPathFromResourceName(resourceName));return new RefValue(dbId,key);}else{return fail('Unknown Value proto '+JSON.stringify(obj));}};/** Creates an api.Document from key and fields (but no create/update time) */JsonProtoSerializer.prototype.toMutationDocument=function(key,fields){return{name:this.toName(key),fields:this.toFields(fields)};};JsonProtoSerializer.prototype.toDocument=function(document){assert(!document.hasLocalMutations,"Can't serialize documents with mutations.");return{name:this.toName(document.key),fields:this.toFields(document.data),updateTime:this.toTimestamp(document.version.toTimestamp())};};JsonProtoSerializer.prototype.fromDocument=function(document){return new Document(this.fromName(document.name),this.fromVersion(document.updateTime),this.fromFields(document.fields||{}),{hasLocalMutations:false});};JsonProtoSerializer.prototype.toFields=function(fields){var _this=this;var result={};fields.forEach(function(key,value){result[key]=_this.toValue(value);});return result;};JsonProtoSerializer.prototype.fromFields=function(object){var _this=this;// Proto map<string, Value> gets mapped to Object, so cast it.
var map=object;var result=ObjectValue.EMPTY;forEach(map,function(key,value){result=result.set(new FieldPath([key]),_this.fromValue(value));});return result;};JsonProtoSerializer.prototype.toMapValue=function(map){return{fields:this.toFields(map)};};JsonProtoSerializer.prototype.toArrayValue=function(array){var _this=this;var result=[];array.forEach(function(value){result.push(_this.toValue(value));});return{values:result};};JsonProtoSerializer.prototype.fromFound=function(doc){assert(!!doc.found,'Tried to deserialize a found document from a missing document.');assertPresent(doc.found.name,'doc.found.name');assertPresent(doc.found.updateTime,'doc.found.updateTime');var key=this.fromName(doc.found.name);var version=this.fromVersion(doc.found.updateTime);var fields=this.fromFields(doc.found.fields||{});return new Document(key,version,fields,{hasLocalMutations:false});};JsonProtoSerializer.prototype.fromMissing=function(result){assert(!!result.missing,'Tried to deserialize a missing document from a found document.');assert(!!result.readTime,'Tried to deserialize a missing document without a read time.');var key=this.fromName(result.missing);var version=this.fromVersion(result.readTime);return new NoDocument(key,version);};JsonProtoSerializer.prototype.fromMaybeDocument=function(result){// tslint:disable-next-line:no-any
var type=result['result'];if(hasTag(result,type,'found')){return this.fromFound(result);}else if(hasTag(result,type,'missing')){return this.fromMissing(result);}return fail('invalid batch get response: '+JSON.stringify(result));};JsonProtoSerializer.prototype.toWatchTargetChangeState=function(state){switch(state){case WatchTargetChangeState.Added:return'ADD';case WatchTargetChangeState.Current:return'CURRENT';case WatchTargetChangeState.NoChange:return'NO_CHANGE';case WatchTargetChangeState.Removed:return'REMOVE';case WatchTargetChangeState.Reset:return'RESET';default:return fail('Unknown WatchTargetChangeState: '+state);}};JsonProtoSerializer.prototype.toTestWatchChange=function(watchChange){if(watchChange instanceof ExistenceFilterChange){return{filter:{count:watchChange.existenceFilter.count,targetId:watchChange.targetId}};}if(watchChange instanceof DocumentWatchChange){if(watchChange.newDoc instanceof Document){var doc=watchChange.newDoc;return{documentChange:{document:{name:this.toName(doc.key),fields:this.toFields(doc.data),updateTime:this.toVersion(doc.version)},targetIds:watchChange.updatedTargetIds,removedTargetIds:watchChange.removedTargetIds}};}else if(watchChange.newDoc instanceof NoDocument){var doc=watchChange.newDoc;return{documentDelete:{document:this.toName(doc.key),readTime:this.toVersion(doc.version),removedTargetIds:watchChange.removedTargetIds}};}else if(watchChange.newDoc===null){return{documentRemove:{document:this.toName(watchChange.key),removedTargetIds:watchChange.removedTargetIds}};}}if(watchChange instanceof WatchTargetChange){var cause=undefined;if(watchChange.cause){cause={code:mapRpcCodeFromCode(watchChange.cause.code),message:watchChange.cause.message};}return{targetChange:{targetChangeType:this.toWatchTargetChangeState(watchChange.state),targetIds:watchChange.targetIds,resumeToken:this.unsafeCastProtoByteString(watchChange.resumeToken),cause:cause}};}return fail('Unrecognized watch change: '+JSON.stringify(watchChange));};JsonProtoSerializer.prototype.fromWatchChange=function(change){// tslint:disable-next-line:no-any
var type=change['response_type'];var watchChange;if(hasTag(change,type,'targetChange')){assertPresent(change.targetChange,'targetChange');// proto3 default value is unset in JSON (undefined), so use 'NO_CHANGE'
// if unset
var state=this.fromWatchTargetChangeState(change.targetChange.targetChangeType||'NO_CHANGE');var targetIds=change.targetChange.targetIds||[];var resumeToken=change.targetChange.resumeToken||this.emptyByteString();var causeProto=change.targetChange.cause;var cause=causeProto&&this.fromRpcStatus(causeProto);watchChange=new WatchTargetChange(state,targetIds,resumeToken,cause||null);}else if(hasTag(change,type,'documentChange')){assertPresent(change.documentChange,'documentChange');assertPresent(change.documentChange.document,'documentChange.name');assertPresent(change.documentChange.document.name,'documentChange.document.name');assertPresent(change.documentChange.document.updateTime,'documentChange.document.updateTime');var entityChange=change.documentChange;var key=this.fromName(entityChange.document.name);var version=this.fromVersion(entityChange.document.updateTime);var fields=this.fromFields(entityChange.document.fields||{});var doc=new Document(key,version,fields,{hasLocalMutations:false});var updatedTargetIds=entityChange.targetIds||[];var removedTargetIds=entityChange.removedTargetIds||[];watchChange=new DocumentWatchChange(updatedTargetIds,removedTargetIds,doc.key,doc);}else if(hasTag(change,type,'documentDelete')){assertPresent(change.documentDelete,'documentDelete');assertPresent(change.documentDelete.document,'documentDelete.document');var docDelete=change.documentDelete;var key=this.fromName(docDelete.document);var version=docDelete.readTime?this.fromVersion(docDelete.readTime):SnapshotVersion.forDeletedDoc();var doc=new NoDocument(key,version);var removedTargetIds=docDelete.removedTargetIds||[];watchChange=new DocumentWatchChange([],removedTargetIds,doc.key,doc);}else if(hasTag(change,type,'documentRemove')){assertPresent(change.documentRemove,'documentRemove');assertPresent(change.documentRemove.document,'documentRemove');var docRemove=change.documentRemove;var key=this.fromName(docRemove.document);var removedTargetIds=docRemove.removedTargetIds||[];watchChange=new DocumentWatchChange([],removedTargetIds,key,null);}else if(hasTag(change,type,'filter')){// TODO(dimond): implement existence filter parsing with strategy.
assertPresent(change.filter,'filter');assertPresent(change.filter.targetId,'filter.targetId');var filter=change.filter;var count=filter.count||0;var existenceFilter=new ExistenceFilter(count);var targetId=filter.targetId;watchChange=new ExistenceFilterChange(targetId,existenceFilter);}else{return fail('Unknown change type '+JSON.stringify(change));}return watchChange;};JsonProtoSerializer.prototype.fromWatchTargetChangeState=function(state){if(state==='NO_CHANGE'){return WatchTargetChangeState.NoChange;}else if(state==='ADD'){return WatchTargetChangeState.Added;}else if(state==='REMOVE'){return WatchTargetChangeState.Removed;}else if(state==='CURRENT'){return WatchTargetChangeState.Current;}else if(state==='RESET'){return WatchTargetChangeState.Reset;}else{return fail('Got unexpected TargetChange.state: '+state);}};JsonProtoSerializer.prototype.versionFromListenResponse=function(change){// We have only reached a consistent snapshot for the entire stream if there
// is a read_time set and it applies to all targets (i.e. the list of
// targets is empty). The backend is guaranteed to send such responses.
// tslint:disable-next-line:no-any
var type=change['response_type'];if(!hasTag(change,type,'targetChange')){return SnapshotVersion.MIN;}var targetChange=change.targetChange;if(targetChange.targetIds&&targetChange.targetIds.length){return SnapshotVersion.MIN;}if(!targetChange.readTime){return SnapshotVersion.MIN;}return this.fromVersion(targetChange.readTime);};JsonProtoSerializer.prototype.toMutation=function(mutation){var _this=this;var result;if(mutation instanceof SetMutation){result={update:this.toMutationDocument(mutation.key,mutation.value)};}else if(mutation instanceof DeleteMutation){result={delete:this.toName(mutation.key)};}else if(mutation instanceof PatchMutation){result={update:this.toMutationDocument(mutation.key,mutation.data),updateMask:this.toDocumentMask(mutation.fieldMask)};}else if(mutation instanceof TransformMutation){result={transform:{document:this.toName(mutation.key),fieldTransforms:mutation.fieldTransforms.map(function(transform){return _this.toFieldTransform(transform);})}};}else{return fail('Unknown mutation type '+mutation.type);}if(!mutation.precondition.isNone){result.currentDocument=this.toPrecondition(mutation.precondition);}return result;};JsonProtoSerializer.prototype.fromMutation=function(proto){var _this=this;var precondition=proto.currentDocument?this.fromPrecondition(proto.currentDocument):Precondition.NONE;if(proto.update){assertPresent(proto.update.name,'name');var key=this.fromName(proto.update.name);var value=this.fromFields(proto.update.fields||{});if(proto.updateMask){var fieldMask=this.fromDocumentMask(proto.updateMask);return new PatchMutation(key,value,fieldMask,precondition);}else{return new SetMutation(key,value,precondition);}}else if(proto.delete){var key=this.fromName(proto.delete);return new DeleteMutation(key,precondition);}else if(proto.transform){var key=this.fromName(proto.transform.document);var fieldTransforms=proto.transform.fieldTransforms.map(function(transform){return _this.fromFieldTransform(transform);});assert(precondition.exists===true,'Transforms only support precondition "exists == true"');return new TransformMutation(key,fieldTransforms);}else{return fail('unknown mutation proto: '+JSON.stringify(proto));}};JsonProtoSerializer.prototype.toPrecondition=function(precondition){assert(!precondition.isNone,"Can't serialize an empty precondition");if(precondition.updateTime!==undefined){return{updateTime:this.toVersion(precondition.updateTime)};}else if(precondition.exists!==undefined){return{exists:precondition.exists};}else{return fail('Unknown precondition');}};JsonProtoSerializer.prototype.fromPrecondition=function(precondition){if(precondition.updateTime!==undefined){return Precondition.updateTime(this.fromVersion(precondition.updateTime));}else if(precondition.exists!==undefined){return Precondition.exists(precondition.exists);}else{return Precondition.NONE;}};JsonProtoSerializer.prototype.fromWriteResult=function(proto){var _this=this;// NOTE: Deletes don't have an updateTime.
var version=proto.updateTime?this.fromVersion(proto.updateTime):null;var transformResults=null;if(proto.transformResults&&proto.transformResults.length>0){transformResults=proto.transformResults.map(function(result){return _this.fromValue(result);});}return new MutationResult(version,transformResults);};JsonProtoSerializer.prototype.fromWriteResults=function(protos){var _this=this;return(protos||[]).map(function(proto){return _this.fromWriteResult(proto);});};JsonProtoSerializer.prototype.toFieldTransform=function(fieldTransform){var _this=this;var transform=fieldTransform.transform;if(transform instanceof ServerTimestampTransform){return{fieldPath:fieldTransform.field.canonicalString(),setToServerValue:'REQUEST_TIME'};}else if(transform instanceof ArrayUnionTransformOperation){return{fieldPath:fieldTransform.field.canonicalString(),appendMissingElements:{values:transform.elements.map(function(v){return _this.toValue(v);})}};}else if(transform instanceof ArrayRemoveTransformOperation){return{fieldPath:fieldTransform.field.canonicalString(),removeAllFromArray:{values:transform.elements.map(function(v){return _this.toValue(v);})}};}else{fail('Unknown transform: '+fieldTransform.transform);}};JsonProtoSerializer.prototype.fromFieldTransform=function(proto){var _this=this;// tslint:disable-next-line:no-any We need to match generated Proto types.
var type=proto['transform_type'];var transform=null;if(hasTag(proto,type,'setToServerValue')){assert(proto.setToServerValue==='REQUEST_TIME','Unknown server value transform proto: '+JSON.stringify(proto));transform=ServerTimestampTransform.instance;}else if(hasTag(proto,type,'appendMissingElements')){var values=proto.appendMissingElements.values||[];transform=new ArrayUnionTransformOperation(values.map(function(v){return _this.fromValue(v);}));}else if(hasTag(proto,type,'removeAllFromArray')){var values=proto.removeAllFromArray.values||[];transform=new ArrayRemoveTransformOperation(values.map(function(v){return _this.fromValue(v);}));}else{fail('Unknown transform proto: '+JSON.stringify(proto));}var fieldPath=FieldPath.fromServerFormat(proto.fieldPath);return new FieldTransform(fieldPath,transform);};JsonProtoSerializer.prototype.toDocumentsTarget=function(query){return{documents:[this.toQueryPath(query.path)]};};JsonProtoSerializer.prototype.fromDocumentsTarget=function(documentsTarget){var count=documentsTarget.documents.length;assert(count===1,'DocumentsTarget contained other than 1 document: '+count);var name=documentsTarget.documents[0];return Query.atPath(this.fromQueryPath(name));};JsonProtoSerializer.prototype.toQueryTarget=function(query){// Dissect the path into parent, collectionId, and optional key filter.
var result={structuredQuery:{}};if(query.path.isEmpty()){result.parent=this.toQueryPath(ResourcePath.EMPTY_PATH);}else{var path=query.path;assert(path.length%2!==0,'Document queries with filters are not supported.');result.parent=this.toQueryPath(path.popLast());result.structuredQuery.from=[{collectionId:path.lastSegment()}];}var where=this.toFilter(query.filters);if(where){result.structuredQuery.where=where;}var orderBy=this.toOrder(query.orderBy);if(orderBy){result.structuredQuery.orderBy=orderBy;}var limit=this.toInt32Value(query.limit);if(limit!==undefined){result.structuredQuery.limit=limit;}if(query.startAt){result.structuredQuery.startAt=this.toCursor(query.startAt);}if(query.endAt){result.structuredQuery.endAt=this.toCursor(query.endAt);}return result;};JsonProtoSerializer.prototype.fromQueryTarget=function(target){var path=this.fromQueryPath(target.parent);var query=target.structuredQuery;var fromCount=query.from?query.from.length:0;if(fromCount>0){assert(fromCount===1,'StructuredQuery.from with more than one collection is not supported.');var from=query.from[0];path=path.child(from.collectionId);}var filterBy=[];if(query.where){filterBy=this.fromFilter(query.where);}var orderBy=[];if(query.orderBy){orderBy=this.fromOrder(query.orderBy);}var limit=null;if(query.limit){limit=this.fromInt32Value(query.limit);}var startAt=null;if(query.startAt){startAt=this.fromCursor(query.startAt);}var endAt=null;if(query.endAt){endAt=this.fromCursor(query.endAt);}return new Query(path,orderBy,filterBy,limit,startAt,endAt);};JsonProtoSerializer.prototype.toListenRequestLabels=function(queryData){var value=this.toLabel(queryData.purpose);if(value==null){return null;}else{return{'goog-listen-tags':value};}};JsonProtoSerializer.prototype.toLabel=function(purpose){switch(purpose){case QueryPurpose.Listen:return null;case QueryPurpose.ExistenceFilterMismatch:return'existence-filter-mismatch';case QueryPurpose.LimboResolution:return'limbo-document';default:return fail('Unrecognized query purpose: '+purpose);}};JsonProtoSerializer.prototype.toTarget=function(queryData){var result;var query=queryData.query;if(query.isDocumentQuery()){result={documents:this.toDocumentsTarget(query)};}else{result={query:this.toQueryTarget(query)};}result.targetId=queryData.targetId;if(queryData.resumeToken.length>0){result.resumeToken=this.unsafeCastProtoByteString(queryData.resumeToken);}return result;};JsonProtoSerializer.prototype.toFilter=function(filters){var _this=this;if(filters.length===0)return;var protos=filters.map(function(filter){return filter instanceof RelationFilter?_this.toRelationFilter(filter):_this.toUnaryFilter(filter);});if(protos.length===1){return protos[0];}return{compositeFilter:{op:'AND',filters:protos}};};JsonProtoSerializer.prototype.fromFilter=function(filter){var _this=this;if(!filter){return[];}else if(filter.unaryFilter!==undefined){return[this.fromUnaryFilter(filter)];}else if(filter.fieldFilter!==undefined){return[this.fromRelationFilter(filter)];}else if(filter.compositeFilter!==undefined){return filter.compositeFilter.filters.map(function(f){return _this.fromFilter(f);}).reduce(function(accum,current){return accum.concat(current);});}else{return fail('Unknown filter: '+JSON.stringify(filter));}};JsonProtoSerializer.prototype.toOrder=function(orderBys){var _this=this;if(orderBys.length===0)return;return orderBys.map(function(order){return _this.toPropertyOrder(order);});};JsonProtoSerializer.prototype.fromOrder=function(orderBys){var _this=this;return orderBys.map(function(order){return _this.fromPropertyOrder(order);});};JsonProtoSerializer.prototype.toCursor=function(cursor){var _this=this;return{before:cursor.before,values:cursor.position.map(function(component){return _this.toValue(component);})};};JsonProtoSerializer.prototype.fromCursor=function(cursor){var _this=this;var before=!!cursor.before;var position=cursor.values.map(function(component){return _this.fromValue(component);});return new Bound(position,before);};// visible for testing
JsonProtoSerializer.prototype.toDirection=function(dir){return DIRECTIONS[dir.name];};// visible for testing
JsonProtoSerializer.prototype.fromDirection=function(dir){switch(dir){case'ASCENDING':return Direction.ASCENDING;case'DESCENDING':return Direction.DESCENDING;default:return undefined;}};// visible for testing
JsonProtoSerializer.prototype.toOperatorName=function(op){return OPERATORS[op.name];};JsonProtoSerializer.prototype.fromOperatorName=function(op){switch(op){case'EQUAL':return RelationOp.EQUAL;case'GREATER_THAN':return RelationOp.GREATER_THAN;case'GREATER_THAN_OR_EQUAL':return RelationOp.GREATER_THAN_OR_EQUAL;case'LESS_THAN':return RelationOp.LESS_THAN;case'LESS_THAN_OR_EQUAL':return RelationOp.LESS_THAN_OR_EQUAL;case'ARRAY_CONTAINS':return RelationOp.ARRAY_CONTAINS;case'OPERATOR_UNSPECIFIED':return fail('Unspecified relation');default:return fail('Unknown relation');}};JsonProtoSerializer.prototype.toFieldPathReference=function(path){return{fieldPath:path.canonicalString()};};JsonProtoSerializer.prototype.fromFieldPathReference=function(fieldReference){return FieldPath.fromServerFormat(fieldReference.fieldPath);};// visible for testing
JsonProtoSerializer.prototype.toPropertyOrder=function(orderBy){return{field:this.toFieldPathReference(orderBy.field),direction:this.toDirection(orderBy.dir)};};JsonProtoSerializer.prototype.fromPropertyOrder=function(orderBy){return new OrderBy(this.fromFieldPathReference(orderBy.field),this.fromDirection(orderBy.direction));};// visible for testing
JsonProtoSerializer.prototype.toRelationFilter=function(filter){if(filter instanceof RelationFilter){return{fieldFilter:{field:this.toFieldPathReference(filter.field),op:this.toOperatorName(filter.op),value:this.toValue(filter.value)}};}else{return fail('Unrecognized filter: '+JSON.stringify(filter));}};JsonProtoSerializer.prototype.fromRelationFilter=function(filter){return new RelationFilter(this.fromFieldPathReference(filter.fieldFilter.field),this.fromOperatorName(filter.fieldFilter.op),this.fromValue(filter.fieldFilter.value));};// visible for testing
JsonProtoSerializer.prototype.toUnaryFilter=function(filter){if(filter instanceof NanFilter){return{unaryFilter:{field:this.toFieldPathReference(filter.field),op:'IS_NAN'}};}else if(filter instanceof NullFilter){return{unaryFilter:{field:this.toFieldPathReference(filter.field),op:'IS_NULL'}};}else{return fail('Unrecognized filter: '+JSON.stringify(filter));}};JsonProtoSerializer.prototype.fromUnaryFilter=function(filter){switch(filter.unaryFilter.op){case'IS_NAN':var nanField=this.fromFieldPathReference(filter.unaryFilter.field);return new NanFilter(nanField);case'IS_NULL':var nullField=this.fromFieldPathReference(filter.unaryFilter.field);return new NullFilter(nullField);case'OPERATOR_UNSPECIFIED':return fail('Unspecified filter');default:return fail('Unknown filter');}};JsonProtoSerializer.prototype.toDocumentMask=function(fieldMask){return{fieldPaths:fieldMask.fields.map(function(field){return field.canonicalString();})};};JsonProtoSerializer.prototype.fromDocumentMask=function(proto){var paths=proto.fieldPaths||[];var fields=paths.map(function(path){return FieldPath.fromServerFormat(path);});return new FieldMask(fields);};return JsonProtoSerializer;}();/**
* Checks for a specific oneof tag in a protocol buffer message.
*
* This intentionally accommodates two distinct cases:
*
* 1) Messages containing a type tag: these are the format produced by GRPC in
* return values. These may contain default-value mappings for all tags in the
* oneof but the type tag specifies which one was actually set.
*
* 2) Messages that don't contain a type tag: these are the format required by
* GRPC as inputs. If we emitted objects with type tags, ProtoBuf.js would
* choke claiming that the tags aren't fields in the Message.
*
* Allowing both formats here makes the serializer able to consume the outputs
* it produces: for all messages it supports, fromX(toX(value)) == value.
*
* Note that case 2 suffers from ambiguity: if multiple tags are present
* without a type tag then the callers are structured in such a way that the
* first invocation will win. Since we only parse in this mode when parsing
* the output of a serialize method this works, but it's not a general
* solution.
*
* Unfortunately there is no general solution here because proto3 makes it
* impossible to distinguish unset from explicitly set fields: both have the
* default value for the type. Without the type tag but multiple value tags
* it's possible to have default values for each tag in the oneof and not be
* able to know which was actually in effect.
*/function hasTag(obj,type,tag){return type===tag||!type&&tag in obj;}/**
* Detect React Native.
*
* @return {boolean} True if ReactNative environment is detected.
*/var isReactNative=function(){return typeof navigator==='object'&&navigator['product']==='ReactNative';};var ERROR_NAME='FirebaseError';var captureStackTrace=Error.captureStackTrace;var FirebaseError=/** @class */function(){function FirebaseError(code,message){this.code=code;this.message=message;// We want the stack value, if implemented by Error
if(captureStackTrace){// Patches this.stack, omitted calls above ErrorFactory#create
captureStackTrace(this,ErrorFactory.prototype.create);}else{try{// In case of IE11, stack will be set only after error is raised.
// https://docs.microsoft.com/en-us/scripting/javascript/reference/stack-property-error-javascript
throw Error.apply(this,arguments);}catch(err){this.name=ERROR_NAME;// Make non-enumerable getter for the property.
Object.defineProperty(this,'stack',{get:function(){return err.stack;}});}}}return FirebaseError;}();// Back-door inheritance
FirebaseError.prototype=Object.create(Error.prototype);FirebaseError.prototype.constructor=FirebaseError;FirebaseError.prototype.name=ERROR_NAME;var ErrorFactory=/** @class */function(){function ErrorFactory(service,serviceName,errors){this.service=service;this.serviceName=serviceName;this.errors=errors;// Matches {$name}, by default.
this.pattern=/\{\$([^}]+)}/g;// empty
}ErrorFactory.prototype.create=function(code,data){if(data===undefined){data={};}var template=this.errors[code];var fullCode=this.service+'/'+code;var message;if(template===undefined){message='Error';}else{message=template.replace(this.pattern,function(match,key){var value=data[key];return value!==undefined?value.toString():'<'+key+'?>';});}// Service: Error message (service/code).
message=this.serviceName+': '+message+' ('+fullCode+').';var err=new FirebaseError(fullCode,message);// Populate the Error object with message parts for programmatic
// accesses (e.g., e.file).
for(var prop in data){if(!data.hasOwnProperty(prop)||prop.slice(-1)==='_'){continue;}err[prop]=data[prop];}return err;};return ErrorFactory;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/// Copyright 2011 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Abstract cryptographic hash interface.
*
* See Sha1 and Md5 for sample implementations.
*
*//**
* Create a cryptographic hash instance.
*
* @constructor
* @struct
*/var Hash=/** @class */function(){function Hash(){/**
* The block size for the hasher.
* @type {number}
*/this.blockSize=-1;}return Hash;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* @fileoverview SHA-1 cryptographic hash.
* Variable names follow the notation in FIPS PUB 180-3:
* http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf.
*
* Usage:
* var sha1 = new sha1();
* sha1.update(bytes);
* var hash = sha1.digest();
*
* Performance:
* Chrome 23: ~400 Mbit/s
* Firefox 16: ~250 Mbit/s
*
*//**
* SHA-1 cryptographic hash constructor.
*
* The properties declared here are discussed in the above algorithm document.
* @constructor
* @extends {Hash}
* @final
* @struct
*/var Sha1=/** @class */function(_super){tslib_1.__extends(Sha1,_super);function Sha1(){var _this=_super.call(this)||this;/**
* Holds the previous values of accumulated variables a-e in the compress_
* function.
* @type {!Array<number>}
* @private
*/_this.chain_=[];/**
* A buffer holding the partially computed hash result.
* @type {!Array<number>}
* @private
*/_this.buf_=[];/**
* An array of 80 bytes, each a part of the message to be hashed. Referred to
* as the message schedule in the docs.
* @type {!Array<number>}
* @private
*/_this.W_=[];/**
* Contains data needed to pad messages less than 64 bytes.
* @type {!Array<number>}
* @private
*/_this.pad_=[];/**
* @private {number}
*/_this.inbuf_=0;/**
* @private {number}
*/_this.total_=0;_this.blockSize=512/8;_this.pad_[0]=128;for(var i=1;i<_this.blockSize;++i){_this.pad_[i]=0;}_this.reset();return _this;}Sha1.prototype.reset=function(){this.chain_[0]=0x67452301;this.chain_[1]=0xefcdab89;this.chain_[2]=0x98badcfe;this.chain_[3]=0x10325476;this.chain_[4]=0xc3d2e1f0;this.inbuf_=0;this.total_=0;};/**
* Internal compress helper function.
* @param {!Array<number>|!Uint8Array|string} buf Block to compress.
* @param {number=} opt_offset Offset of the block in the buffer.
* @private
*/Sha1.prototype.compress_=function(buf,opt_offset){if(!opt_offset){opt_offset=0;}var W=this.W_;// get 16 big endian words
if(typeof buf==='string'){for(var i=0;i<16;i++){// TODO(user): [bug 8140122] Recent versions of Safari for Mac OS and iOS
// have a bug that turns the post-increment ++ operator into pre-increment
// during JIT compilation. We have code that depends heavily on SHA-1 for
// correctness and which is affected by this bug, so I've removed all uses
// of post-increment ++ in which the result value is used. We can revert
// this change once the Safari bug
// (https://bugs.webkit.org/show_bug.cgi?id=109036) has been fixed and
// most clients have been updated.
W[i]=buf.charCodeAt(opt_offset)<<24|buf.charCodeAt(opt_offset+1)<<16|buf.charCodeAt(opt_offset+2)<<8|buf.charCodeAt(opt_offset+3);opt_offset+=4;}}else{for(var i=0;i<16;i++){W[i]=buf[opt_offset]<<24|buf[opt_offset+1]<<16|buf[opt_offset+2]<<8|buf[opt_offset+3];opt_offset+=4;}}// expand to 80 words
for(var i=16;i<80;i++){var t=W[i-3]^W[i-8]^W[i-14]^W[i-16];W[i]=(t<<1|t>>>31)&0xffffffff;}var a=this.chain_[0];var b=this.chain_[1];var c=this.chain_[2];var d=this.chain_[3];var e=this.chain_[4];var f,k;// TODO(user): Try to unroll this loop to speed up the computation.
for(var i=0;i<80;i++){if(i<40){if(i<20){f=d^b&(c^d);k=0x5a827999;}else{f=b^c^d;k=0x6ed9eba1;}}else{if(i<60){f=b&c|d&(b|c);k=0x8f1bbcdc;}else{f=b^c^d;k=0xca62c1d6;}}var t=(a<<5|a>>>27)+f+e+k+W[i]&0xffffffff;e=d;d=c;c=(b<<30|b>>>2)&0xffffffff;b=a;a=t;}this.chain_[0]=this.chain_[0]+a&0xffffffff;this.chain_[1]=this.chain_[1]+b&0xffffffff;this.chain_[2]=this.chain_[2]+c&0xffffffff;this.chain_[3]=this.chain_[3]+d&0xffffffff;this.chain_[4]=this.chain_[4]+e&0xffffffff;};Sha1.prototype.update=function(bytes,opt_length){// TODO(johnlenz): tighten the function signature and remove this check
if(bytes==null){return;}if(opt_length===undefined){opt_length=bytes.length;}var lengthMinusBlock=opt_length-this.blockSize;var n=0;// Using local instead of member variables gives ~5% speedup on Firefox 16.
var buf=this.buf_;var inbuf=this.inbuf_;// The outer while loop should execute at most twice.
while(n<opt_length){// When we have no data in the block to top up, we can directly process the
// input buffer (assuming it contains sufficient data). This gives ~25%
// speedup on Chrome 23 and ~15% speedup on Firefox 16, but requires that
// the data is provided in large chunks (or in multiples of 64 bytes).
if(inbuf==0){while(n<=lengthMinusBlock){this.compress_(bytes,n);n+=this.blockSize;}}if(typeof bytes==='string'){while(n<opt_length){buf[inbuf]=bytes.charCodeAt(n);++inbuf;++n;if(inbuf==this.blockSize){this.compress_(buf);inbuf=0;// Jump to the outer loop so we use the full-block optimization.
break;}}}else{while(n<opt_length){buf[inbuf]=bytes[n];++inbuf;++n;if(inbuf==this.blockSize){this.compress_(buf);inbuf=0;// Jump to the outer loop so we use the full-block optimization.
break;}}}}this.inbuf_=inbuf;this.total_+=opt_length;};/** @override */Sha1.prototype.digest=function(){var digest=[];var totalBits=this.total_*8;// Add pad 0x80 0x00*.
if(this.inbuf_<56){this.update(this.pad_,56-this.inbuf_);}else{this.update(this.pad_,this.blockSize-(this.inbuf_-56));}// Add # bits.
for(var i=this.blockSize-1;i>=56;i--){this.buf_[i]=totalBits&255;totalBits/=256;// Don't use bit-shifting here!
}this.compress_(this.buf_);var n=0;for(var i=0;i<5;i++){for(var j=24;j>=0;j-=8){digest[n]=this.chain_[i]>>j&255;++n;}}return digest;};return Sha1;}(Hash);/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Provides a simple helper class that implements the Stream interface to
* bridge to other implementations that are streams but do not implement the
* interface. The stream callbacks are invoked with the callOn... methods.
*/var StreamBridge=/** @class */function(){function StreamBridge(args){this.sendFn=args.sendFn;this.closeFn=args.closeFn;}StreamBridge.prototype.onOpen=function(callback){assert(!this.wrappedOnOpen,'Called onOpen on stream twice!');this.wrappedOnOpen=callback;};StreamBridge.prototype.onClose=function(callback){assert(!this.wrappedOnClose,'Called onClose on stream twice!');this.wrappedOnClose=callback;};StreamBridge.prototype.onMessage=function(callback){assert(!this.wrappedOnMessage,'Called onMessage on stream twice!');this.wrappedOnMessage=callback;};StreamBridge.prototype.close=function(){this.closeFn();};StreamBridge.prototype.send=function(msg){this.sendFn(msg);};StreamBridge.prototype.callOnOpen=function(){assert(this.wrappedOnOpen!==undefined,'Cannot call onOpen because no callback was set');this.wrappedOnOpen();};StreamBridge.prototype.callOnClose=function(err){assert(this.wrappedOnClose!==undefined,'Cannot call onClose because no callback was set');this.wrappedOnClose(err);};StreamBridge.prototype.callOnMessage=function(msg){assert(this.wrappedOnMessage!==undefined,'Cannot call onMessage because no callback was set');this.wrappedOnMessage(msg);};return StreamBridge;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG='Connection';var RPC_STREAM_SERVICE='google.firestore.v1beta1.Firestore';var RPC_URL_VERSION='v1beta1';/** Maps RPC names to the corresponding REST endpoint name. */var RPC_NAME_REST_MAPPING={BatchGetDocuments:'batchGet',Commit:'commit'};// TODO(b/38203344): The SDK_VERSION is set independently from Firebase because
// we are doing out-of-band releases. Once we release as part of Firebase, we
// should use the Firebase version instead.
var X_GOOG_API_CLIENT_VALUE='gl-js/ fire/'+SDK_VERSION;var XHR_TIMEOUT_SECS=15;var WebChannelConnection=/** @class */function(){function WebChannelConnection(info){this.databaseId=info.databaseId;this.pool=new webchannelWrapper.XhrIoPool();var proto=info.ssl?'https':'http';this.baseUrl=proto+'://'+info.host;}/**
* Modifies the headers for a request, adding any authorization token if
* present and any additional headers for the request.
*/WebChannelConnection.prototype.modifyHeadersForRequest=function(headers,token){if(token){for(var header in token.authHeaders){if(token.authHeaders.hasOwnProperty(header)){headers[header]=token.authHeaders[header];}}}headers['X-Goog-Api-Client']=X_GOOG_API_CLIENT_VALUE;};WebChannelConnection.prototype.invokeRPC=function(rpcName,request,token){var _this=this;var url=this.makeUrl(rpcName);return new Promise(function(resolve,reject){// tslint:disable-next-line:no-any XhrIoPool doesn't have TS typings.
_this.pool.getObject(function(xhr){xhr.listenOnce(webchannelWrapper.EventType.COMPLETE,function(){try{switch(xhr.getLastErrorCode()){case webchannelWrapper.ErrorCode.NO_ERROR:var json=xhr.getResponseJson();debug(LOG_TAG,'XHR received:',JSON.stringify(json));resolve(json);break;case webchannelWrapper.ErrorCode.TIMEOUT:debug(LOG_TAG,'RPC "'+rpcName+'" timed out');reject(new FirestoreError(Code.DEADLINE_EXCEEDED,'Request time out'));break;case webchannelWrapper.ErrorCode.HTTP_ERROR:var status_1=xhr.getStatus();debug(LOG_TAG,'RPC "'+rpcName+'" failed with status:',status_1,'response text:',xhr.getResponseText());if(status_1>0){reject(new FirestoreError(mapCodeFromHttpStatus(status_1),'Server responded with status '+xhr.getStatusText()));}else{// If we received an HTTP_ERROR but there's no status code,
// it's most probably a connection issue
debug(LOG_TAG,'RPC "'+rpcName+'" failed');reject(new FirestoreError(Code.UNAVAILABLE,'Connection failed.'));}break;default:fail('RPC "'+rpcName+'" failed with unanticipated '+'webchannel error '+xhr.getLastErrorCode()+': '+xhr.getLastError()+', giving up.');}}finally{debug(LOG_TAG,'RPC "'+rpcName+'" completed.');_this.pool.releaseObject(xhr);}});var requestString=JSON.stringify(request);debug(LOG_TAG,'XHR sending: ',url+' '+requestString);// Content-Type: text/plain will avoid preflight requests which might
// mess with CORS and redirects by proxies. If we add custom headers
// we will need to change this code to potentially use the
// $httpOverwrite parameter supported by ESF to avoid
// triggering preflight requests.
var headers={'Content-Type':'text/plain'};_this.modifyHeadersForRequest(headers,token);xhr.send(url,'POST',requestString,headers,XHR_TIMEOUT_SECS);});});};WebChannelConnection.prototype.invokeStreamingRPC=function(rpcName,request,token){// The REST API automatically aggregates all of the streamed results, so we
// can just use the normal invoke() method.
return this.invokeRPC(rpcName,request,token);};WebChannelConnection.prototype.openStream=function(rpcName,token){var urlParts=[this.baseUrl,'/',RPC_STREAM_SERVICE,'/',rpcName,'/channel'];var webchannelTransport=webchannelWrapper.createWebChannelTransport();var request={// Background channel test avoids the initial two test calls and decreases
// initial cold start time.
// TODO(dimond): wenboz@ mentioned this might affect use with proxies and
// we should monitor closely for any reports.
backgroundChannelTest:true,// Required for backend stickiness, routing behavior is based on this
// parameter.
httpSessionIdParam:'gsessionid',initMessageHeaders:{},messageUrlParams:{// This param is used to improve routing and project isolation by the
// backend and must be included in every request.
database:"projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database},sendRawJson:true,supportsCrossDomainXhr:true};this.modifyHeadersForRequest(request.initMessageHeaders,token);// Sending the custom headers we just added to request.initMessageHeaders
// (Authorization, etc.) will trigger the browser to make a CORS preflight
// request because the XHR will no longer meet the criteria for a "simple"
// CORS request:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests
//
// Therefore to avoid the CORS preflight request (an extra network
// roundtrip), we use the httpHeadersOverwriteParam option to specify that
// the headers should instead be encoded into a special "$httpHeaders" query
// parameter, which is recognized by the webchannel backend. This is
// formally defined here:
// https://github.com/google/closure-library/blob/b0e1815b13fb92a46d7c9b3c30de5d6a396a3245/closure/goog/net/rpc/httpcors.js#L32
//
// But for some unclear reason (see
// https://github.com/firebase/firebase-js-sdk/issues/703), this breaks
// ReactNative and so we exclude it, which just means ReactNative may be
// subject to the extra network roundtrip for CORS preflight.
if(!isReactNative()){request['httpHeadersOverwriteParam']='$httpHeaders';}var url=urlParts.join('');debug(LOG_TAG,'Creating WebChannel: '+url+' '+request);// tslint:disable-next-line:no-any Because listen isn't defined on it.
var channel=webchannelTransport.createWebChannel(url,request);// WebChannel supports sending the first message with the handshake - saving
// a network round trip. However, it will have to call send in the same
// JS event loop as open. In order to enforce this, we delay actually
// opening the WebChannel until send is called. Whether we have called
// open is tracked with this variable.
var opened=false;// A flag to determine whether the stream was closed (by us or through an
// error/close event) to avoid delivering multiple close events or sending
// on a closed stream
var closed=false;var streamBridge=new StreamBridge({sendFn:function(msg){if(!closed){if(!opened){debug(LOG_TAG,'Opening WebChannel transport.');channel.open();opened=true;}debug(LOG_TAG,'WebChannel sending:',msg);channel.send(msg);}else{debug(LOG_TAG,'Not sending because WebChannel is closed:',msg);}},closeFn:function(){return channel.close();}});// Closure events are guarded and exceptions are swallowed, so catch any
// exception and rethrow using a setTimeout so they become visible again.
// Note that eventually this function could go away if we are confident
// enough the code is exception free.
var unguardedEventListen=function(type,fn){// TODO(dimond): closure typing seems broken because WebChannel does
// not implement goog.events.Listenable
channel.listen(type,function(param){try{fn(param);}catch(e){setTimeout(function(){throw e;},0);}});};unguardedEventListen(webchannelWrapper.WebChannel.EventType.OPEN,function(){if(!closed){debug(LOG_TAG,'WebChannel transport opened.');}});unguardedEventListen(webchannelWrapper.WebChannel.EventType.CLOSE,function(){if(!closed){closed=true;debug(LOG_TAG,'WebChannel transport closed');streamBridge.callOnClose();}});unguardedEventListen(webchannelWrapper.WebChannel.EventType.ERROR,function(err){if(!closed){closed=true;debug(LOG_TAG,'WebChannel transport errored:',err);streamBridge.callOnClose(new FirestoreError(Code.UNAVAILABLE,'The operation could not be completed'));}});unguardedEventListen(webchannelWrapper.WebChannel.EventType.MESSAGE,function(msg){if(!closed){var msgData=msg.data[0];assert(!!msgData,'Got a webchannel message without data.');// TODO(b/35143891): There is a bug in One Platform that caused errors
// (and only errors) to be wrapped in an extra array. To be forward
// compatible with the bug we need to check either condition. The latter
// can be removed once the fix has been rolled out.
var error$$1=// tslint:disable-next-line:no-any msgData.error is not typed.
msgData.error||msgData[0]&&msgData[0].error;if(error$$1){debug(LOG_TAG,'WebChannel received error:',error$$1);// error.status will be a string like 'OK' or 'NOT_FOUND'.
var status_2=error$$1.status;var code=mapCodeFromRpcStatus(status_2);var message=error$$1.message;if(code===undefined){code=Code.INTERNAL;message='Unknown error status: '+status_2+' with message '+error$$1.message;}// Mark closed so no further events are propagated
closed=true;streamBridge.callOnClose(new FirestoreError(code,message));channel.close();}else{debug(LOG_TAG,'WebChannel received:',msgData);streamBridge.callOnMessage(msgData);}}});setTimeout(function(){// Technically we could/should wait for the WebChannel opened event,
// but because we want to send the first message with the WebChannel
// handshake we pretend the channel opened here (asynchronously), and
// then delay the actual open until the first message is sent.
streamBridge.callOnOpen();},0);return streamBridge;};// visible for testing
WebChannelConnection.prototype.makeUrl=function(rpcName){var urlRpcName=RPC_NAME_REST_MAPPING[rpcName];assert(urlRpcName!==undefined,'Unknown REST mapping for: '+rpcName);var url=[this.baseUrl,'/',RPC_URL_VERSION];url.push('/projects/');url.push(this.databaseId.projectId);url.push('/databases/');url.push(this.databaseId.database);url.push('/documents');url.push(':');url.push(urlRpcName);return url.join('');};return WebChannelConnection;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var BrowserPlatform=/** @class */function(){function BrowserPlatform(){this.emptyByteString='';this.base64Available=typeof atob!=='undefined';}BrowserPlatform.prototype.loadConnection=function(databaseInfo){return Promise.resolve(new WebChannelConnection(databaseInfo));};BrowserPlatform.prototype.newSerializer=function(databaseId){return new JsonProtoSerializer(databaseId,{useProto3Json:true});};BrowserPlatform.prototype.formatJSON=function(value){return JSON.stringify(value);};BrowserPlatform.prototype.atob=function(encoded){return atob(encoded);};BrowserPlatform.prototype.btoa=function(raw){return btoa(raw);};return BrowserPlatform;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* This code needs to run before Firestore is used. This can be achieved in
* several ways:
* 1) Through the JSCompiler compiling this code and then (automatically)
* executing it before exporting the Firestore symbols.
* 2) Through importing this module first in a Firestore main module
*/PlatformSupport.setPlatform(new BrowserPlatform());/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/// The objects that are a part of this API are exposed to third-parties as
// compiled javascript so we want to flag our private members with a leading
// underscore to discourage their use.
// tslint:disable:strip-private-property-underscore
/**
* A FieldPath refers to a field in a document. The path may consist of a single
* field name (referring to a top-level field in the document), or a list of
* field names (referring to a nested field in the document).
*/var FieldPath$1=/** @class */function(){/**
* Creates a FieldPath from the provided field names. If more than one field
* name is provided, the path will point to a nested field in a document.
*
* @param fieldNames A list of field names.
*/function FieldPath$$1(){var fieldNames=[];for(var _i=0;_i<arguments.length;_i++){fieldNames[_i]=arguments[_i];}validateNamedArrayAtLeastNumberOfElements('FieldPath',fieldNames,'fieldNames',1);for(var i=0;i<fieldNames.length;++i){validateArgType('FieldPath','string',i,fieldNames[i]);if(fieldNames[i].length===0){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). "+'Field names must not be empty.');}}this._internalPath=new FieldPath(fieldNames);}FieldPath$$1.documentId=function(){return FieldPath$$1._DOCUMENT_ID;};FieldPath$$1.prototype.isEqual=function(other){if(!(other instanceof FieldPath$$1)){throw invalidClassError('isEqual','FieldPath',1,other);}return this._internalPath.isEqual(other._internalPath);};/**
* Internal Note: The backend doesn't technically support querying by
* document ID. Instead it queries by the entire document name (full path
* included), but in the cases we currently support documentId(), the net
* effect is the same.
*/FieldPath$$1._DOCUMENT_ID=new FieldPath$$1(FieldPath.keyField().canonicalString());return FieldPath$$1;}();/**
* Matches any characters in a field path string that are reserved.
*/var RESERVED=new RegExp('[~\\*/\\[\\]]');/**
* Parses a field path string into a FieldPath, treating dots as separators.
*/function fromDotSeparatedString(path){var found=path.search(RESERVED);if(found>=0){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid field path ("+path+"). Paths must not contain "+"'~', '*', '/', '[', or ']'");}try{return new(FieldPath$1.bind.apply(FieldPath$1,[void 0].concat(path.split('.'))))();}catch(e){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid field path ("+path+"). Paths must not be empty, "+"begin with '.', end with '.', or contain '..'");}}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Describes the online state of the Firestore client. Note that this does not
* indicate whether or not the remote store is trying to connect or not. This is
* primarily used by the View / EventManager code to change their behavior while
* offline (e.g. get() calls shouldn't wait for data from the server and
* snapshot events should set metadata.isFromCache=true).
*/var OnlineState;(function(OnlineState){/**
* The Firestore client is in an unknown online state. This means the client
* is either not actively trying to establish a connection or it is currently
* trying to establish a connection, but it has not succeeded or failed yet.
* Higher-level components should not operate in offline mode.
*/OnlineState[OnlineState["Unknown"]=0]="Unknown";/**
* The client is connected and the connections are healthy. This state is
* reached after a successful connection and there has been at least one
* successful message received from the backends.
*/OnlineState[OnlineState["Online"]=1]="Online";/**
* The client is either trying to establish a connection but failing, or it
* has been explicitly marked offline via a call to disableNetwork().
* Higher-level components should operate in offline mode.
*/OnlineState[OnlineState["Offline"]=2]="Offline";})(OnlineState||(OnlineState={}));/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var ChangeType;(function(ChangeType){ChangeType[ChangeType["Added"]=0]="Added";ChangeType[ChangeType["Removed"]=1]="Removed";ChangeType[ChangeType["Modified"]=2]="Modified";ChangeType[ChangeType["Metadata"]=3]="Metadata";})(ChangeType||(ChangeType={}));var SyncState;(function(SyncState){SyncState[SyncState["Local"]=0]="Local";SyncState[SyncState["Synced"]=1]="Synced";})(SyncState||(SyncState={}));/**
* DocumentChangeSet keeps track of a set of changes to docs in a query, merging
* duplicate events for the same doc.
*/var DocumentChangeSet=/** @class */function(){function DocumentChangeSet(){this.changeMap=new SortedMap(DocumentKey.comparator);}DocumentChangeSet.prototype.track=function(change){var key=change.doc.key;var oldChange=this.changeMap.get(key);if(!oldChange){this.changeMap=this.changeMap.insert(key,change);return;}// Merge the new change with the existing change.
if(change.type!==ChangeType.Added&&oldChange.type===ChangeType.Metadata){this.changeMap=this.changeMap.insert(key,change);}else if(change.type===ChangeType.Metadata&&oldChange.type!==ChangeType.Removed){this.changeMap=this.changeMap.insert(key,{type:oldChange.type,doc:change.doc});}else if(change.type===ChangeType.Modified&&oldChange.type===ChangeType.Modified){this.changeMap=this.changeMap.insert(key,{type:ChangeType.Modified,doc:change.doc});}else if(change.type===ChangeType.Modified&&oldChange.type===ChangeType.Added){this.changeMap=this.changeMap.insert(key,{type:ChangeType.Added,doc:change.doc});}else if(change.type===ChangeType.Removed&&oldChange.type===ChangeType.Added){this.changeMap=this.changeMap.remove(key);}else if(change.type===ChangeType.Removed&&oldChange.type===ChangeType.Modified){this.changeMap=this.changeMap.insert(key,{type:ChangeType.Removed,doc:oldChange.doc});}else if(change.type===ChangeType.Added&&oldChange.type===ChangeType.Removed){this.changeMap=this.changeMap.insert(key,{type:ChangeType.Modified,doc:change.doc});}else{// This includes these cases, which don't make sense:
// Added->Added
// Removed->Removed
// Modified->Added
// Removed->Modified
// Metadata->Added
// Removed->Metadata
fail('unsupported combination of changes: '+JSON.stringify(change)+' after '+JSON.stringify(oldChange));}};DocumentChangeSet.prototype.getChanges=function(){var changes=[];this.changeMap.inorderTraversal(function(key,change){changes.push(change);});return changes;};return DocumentChangeSet;}();var ViewSnapshot=/** @class */function(){function ViewSnapshot(query,docs,oldDocs,docChanges,fromCache,hasPendingWrites,syncStateChanged,excludesMetadataChanges){this.query=query;this.docs=docs;this.oldDocs=oldDocs;this.docChanges=docChanges;this.fromCache=fromCache;this.hasPendingWrites=hasPendingWrites;this.syncStateChanged=syncStateChanged;this.excludesMetadataChanges=excludesMetadataChanges;}ViewSnapshot.prototype.isEqual=function(other){if(this.fromCache!==other.fromCache||this.hasPendingWrites!==other.hasPendingWrites||this.syncStateChanged!==other.syncStateChanged||!this.query.isEqual(other.query)||!this.docs.isEqual(other.docs)||!this.oldDocs.isEqual(other.oldDocs)){return false;}var changes=this.docChanges;var otherChanges=other.docChanges;if(changes.length!==otherChanges.length){return false;}for(var i=0;i<changes.length;i++){if(changes[i].type!==otherChanges[i].type||!changes[i].doc.isEqual(otherChanges[i].doc)){return false;}}return true;};return ViewSnapshot;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* DocumentSet is an immutable (copy-on-write) collection that holds documents
* in order specified by the provided comparator. We always add a document key
* comparator on top of what is provided to guarantee document equality based on
* the key.
*/var DocumentSet=/** @class */function(){/** The default ordering is by key if the comparator is omitted */function DocumentSet(comp){// We are adding document key comparator to the end as it's the only
// guaranteed unique property of a document.
if(comp){this.comparator=function(d1,d2){return comp(d1,d2)||DocumentKey.comparator(d1.key,d2.key);};}else{this.comparator=function(d1,d2){return DocumentKey.comparator(d1.key,d2.key);};}this.keyedMap=documentMap();this.sortedSet=new SortedMap(this.comparator);}/**
* Returns an empty copy of the existing DocumentSet, using the same
* comparator.
*/DocumentSet.emptySet=function(oldSet){return new DocumentSet(oldSet.comparator);};DocumentSet.prototype.has=function(key){return this.keyedMap.get(key)!=null;};DocumentSet.prototype.get=function(key){return this.keyedMap.get(key);};DocumentSet.prototype.first=function(){return this.sortedSet.minKey();};DocumentSet.prototype.last=function(){return this.sortedSet.maxKey();};DocumentSet.prototype.isEmpty=function(){return this.sortedSet.isEmpty();};/**
* Returns the index of the provided key in the document set, or -1 if the
* document key is not present in the set;
*/DocumentSet.prototype.indexOf=function(key){var doc=this.keyedMap.get(key);return doc?this.sortedSet.indexOf(doc):-1;};Object.defineProperty(DocumentSet.prototype,"size",{get:function(){return this.sortedSet.size;},enumerable:true,configurable:true});/** Iterates documents in order defined by "comparator" */DocumentSet.prototype.forEach=function(cb){this.sortedSet.inorderTraversal(function(k,v){cb(k);return false;});};/** Inserts or updates a document with the same key */DocumentSet.prototype.add=function(doc){// First remove the element if we have it.
var set=this.delete(doc.key);return set.copy(set.keyedMap.insert(doc.key,doc),set.sortedSet.insert(doc,null));};/** Deletes a document with a given key */DocumentSet.prototype.delete=function(key){var doc=this.get(key);if(!doc){return this;}return this.copy(this.keyedMap.remove(key),this.sortedSet.remove(doc));};DocumentSet.prototype.isEqual=function(other){if(!(other instanceof DocumentSet))return false;if(this.size!==other.size)return false;var thisIt=this.sortedSet.getIterator();var otherIt=other.sortedSet.getIterator();while(thisIt.hasNext()){var thisDoc=thisIt.getNext().key;var otherDoc=otherIt.getNext().key;if(!thisDoc.isEqual(otherDoc))return false;}return true;};DocumentSet.prototype.toString=function(){var docStrings=[];this.forEach(function(doc){docStrings.push(doc.toString());});if(docStrings.length===0){return'DocumentSet ()';}else{return'DocumentSet (\n '+docStrings.join(' \n')+'\n)';}};DocumentSet.prototype.copy=function(keyedMap,sortedSet){var newSet=new DocumentSet();newSet.comparator=this.comparator;newSet.keyedMap=keyedMap;newSet.sortedSet=sortedSet;return newSet;};return DocumentSet;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* A map implementation that uses objects as keys. Objects must implement the
* Equatable interface and must be immutable. Entries in the map are stored
* together with the key being produced from the mapKeyFn. This map
* automatically handles collisions of keys.
*/var ObjectMap=/** @class */function(){function ObjectMap(mapKeyFn){this.mapKeyFn=mapKeyFn;/**
* The inner map for a key -> value pair. Due to the possibility of
* collisions we keep a list of entries that we do a linear search through
* to find an actual match. Note that collisions should be rare, so we still
* expect near constant time lookups in practice.
*/this.inner={};}/** Get a value for this key, or undefined if it does not exist. */ObjectMap.prototype.get=function(key){var id=this.mapKeyFn(key);var matches=this.inner[id];if(matches===undefined){return undefined;}for(var _i=0,matches_1=matches;_i<matches_1.length;_i++){var _a=matches_1[_i],otherKey=_a[0],value=_a[1];if(otherKey.isEqual(key)){return value;}}return undefined;};ObjectMap.prototype.has=function(key){return this.get(key)!==undefined;};/** Put this key and value in the map. */ObjectMap.prototype.set=function(key,value){var id=this.mapKeyFn(key);var matches=this.inner[id];if(matches===undefined){this.inner[id]=[[key,value]];return;}for(var i=0;i<matches.length;i++){if(matches[i][0].isEqual(key)){matches[i]=[key,value];return;}}matches.push([key,value]);};/**
* Remove this key from the map. Returns a boolean if anything was deleted.
*/ObjectMap.prototype.delete=function(key){var id=this.mapKeyFn(key);var matches=this.inner[id];if(matches===undefined){return false;}for(var i=0;i<matches.length;i++){if(matches[i][0].isEqual(key)){if(matches.length===1){delete this.inner[id];}else{matches.splice(i,1);}return true;}}return false;};ObjectMap.prototype.forEach=function(fn){forEach(this.inner,function(_,entries){for(var _i=0,entries_1=entries;_i<entries_1.length;_i++){var _a=entries_1[_i],k=_a[0],v=_a[1];fn(k,v);}});};ObjectMap.prototype.isEmpty=function(){return isEmpty(this.inner);};return ObjectMap;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Holds the listeners and the last received ViewSnapshot for a query being
* tracked by EventManager.
*/var QueryListenersInfo=/** @class */function(){function QueryListenersInfo(){this.listeners=[];}return QueryListenersInfo;}();/**
* EventManager is responsible for mapping queries to query event emitters.
* It handles "fan-out". -- Identical queries will re-use the same watch on the
* backend.
*/var EventManager=/** @class */function(){function EventManager(syncEngine){this.syncEngine=syncEngine;this.queries=new ObjectMap(function(q){return q.canonicalId();});this.onlineState=OnlineState.Unknown;this.syncEngine.subscribe(this.onChange.bind(this),this.onError.bind(this));}EventManager.prototype.listen=function(listener){var query=listener.query;var firstListen=false;var queryInfo=this.queries.get(query);if(!queryInfo){firstListen=true;queryInfo=new QueryListenersInfo();this.queries.set(query,queryInfo);}queryInfo.listeners.push(listener);listener.applyOnlineStateChange(this.onlineState);if(queryInfo.viewSnap)listener.onViewSnapshot(queryInfo.viewSnap);if(firstListen){return this.syncEngine.listen(query).then(function(targetId){queryInfo.targetId=targetId;return targetId;});}else{return Promise.resolve(queryInfo.targetId);}};EventManager.prototype.unlisten=function(listener){return tslib_1.__awaiter(this,void 0,void 0,function(){var query,lastListen,queryInfo,i;return tslib_1.__generator(this,function(_a){query=listener.query;lastListen=false;queryInfo=this.queries.get(query);if(queryInfo){i=queryInfo.listeners.indexOf(listener);if(i>=0){queryInfo.listeners.splice(i,1);lastListen=queryInfo.listeners.length===0;}}if(lastListen){this.queries.delete(query);return[2/*return*/,this.syncEngine.unlisten(query)];}return[2/*return*/];});});};EventManager.prototype.onChange=function(viewSnaps){for(var _i=0,viewSnaps_1=viewSnaps;_i<viewSnaps_1.length;_i++){var viewSnap=viewSnaps_1[_i];var query=viewSnap.query;var queryInfo=this.queries.get(query);if(queryInfo){for(var _a=0,_b=queryInfo.listeners;_a<_b.length;_a++){var listener=_b[_a];listener.onViewSnapshot(viewSnap);}queryInfo.viewSnap=viewSnap;}}};EventManager.prototype.onError=function(query,error){var queryInfo=this.queries.get(query);if(queryInfo){for(var _i=0,_a=queryInfo.listeners;_i<_a.length;_i++){var listener=_a[_i];listener.onError(error);}}// Remove all listeners. NOTE: We don't need to call syncEngine.unlisten()
// after an error.
this.queries.delete(query);};EventManager.prototype.applyOnlineStateChange=function(onlineState){this.onlineState=onlineState;this.queries.forEach(function(_,queryInfo){for(var _i=0,_a=queryInfo.listeners;_i<_a.length;_i++){var listener=_a[_i];listener.applyOnlineStateChange(onlineState);}});};return EventManager;}();/**
* QueryListener takes a series of internal view snapshots and determines
* when to raise the event.
*
* It uses an Observer to dispatch events.
*/var QueryListener=/** @class */function(){function QueryListener(query,queryObserver,options){this.query=query;this.queryObserver=queryObserver;/**
* Initial snapshots (e.g. from cache) may not be propagated to the wrapped
* observer. This flag is set to true once we've actually raised an event.
*/this.raisedInitialEvent=false;this.onlineState=OnlineState.Unknown;this.options=options||{};}QueryListener.prototype.onViewSnapshot=function(snap){assert(snap.docChanges.length>0||snap.syncStateChanged,'We got a new snapshot with no changes?');if(!this.options.includeMetadataChanges){// Remove the metadata only changes.
var docChanges=[];for(var _i=0,_a=snap.docChanges;_i<_a.length;_i++){var docChange=_a[_i];if(docChange.type!==ChangeType.Metadata){docChanges.push(docChange);}}snap=new ViewSnapshot(snap.query,snap.docs,snap.oldDocs,docChanges,snap.fromCache,snap.hasPendingWrites,snap.syncStateChanged,/* excludesMetadataChanges= */true);}if(!this.raisedInitialEvent){if(this.shouldRaiseInitialEvent(snap,this.onlineState)){this.raiseInitialEvent(snap);}}else if(this.shouldRaiseEvent(snap)){this.queryObserver.next(snap);}this.snap=snap;};QueryListener.prototype.onError=function(error){this.queryObserver.error(error);};QueryListener.prototype.applyOnlineStateChange=function(onlineState){this.onlineState=onlineState;if(this.snap&&!this.raisedInitialEvent&&this.shouldRaiseInitialEvent(this.snap,onlineState)){this.raiseInitialEvent(this.snap);}};QueryListener.prototype.shouldRaiseInitialEvent=function(snap,onlineState){assert(!this.raisedInitialEvent,'Determining whether to raise first event but already had first event');// Always raise the first event when we're synced
if(!snap.fromCache){return true;}// NOTE: We consider OnlineState.Unknown as online (it should become Offline
// or Online if we wait long enough).
var maybeOnline=onlineState!==OnlineState.Offline;// Don't raise the event if we're online, aren't synced yet (checked
// above) and are waiting for a sync.
if(this.options.waitForSyncWhenOnline&&maybeOnline){assert(snap.fromCache,'Waiting for sync, but snapshot is not from cache');return false;}// Raise data from cache if we have any documents or we are offline
return!snap.docs.isEmpty()||onlineState===OnlineState.Offline;};QueryListener.prototype.shouldRaiseEvent=function(snap){// We don't need to handle includeDocumentMetadataChanges here because
// the Metadata only changes have already been stripped out if needed.
// At this point the only changes we will see are the ones we should
// propagate.
if(snap.docChanges.length>0){return true;}var hasPendingWritesChanged=this.snap&&this.snap.hasPendingWrites!==snap.hasPendingWrites;if(snap.syncStateChanged||hasPendingWritesChanged){return this.options.includeMetadataChanges===true;}// Generally we should have hit one of the cases above, but it's possible
// to get here if there were only metadata docChanges and they got
// stripped out.
return false;};QueryListener.prototype.raiseInitialEvent=function(snap){assert(!this.raisedInitialEvent,'Trying to raise initial events for second time');snap=new ViewSnapshot(snap.query,snap.docs,DocumentSet.emptySet(snap.docs),QueryListener.getInitialViewChanges(snap),snap.fromCache,snap.hasPendingWrites,/* syncChangesState= */true,/* excludesMetadataChanges= */false);this.raisedInitialEvent=true;this.queryObserver.next(snap);};/** Returns changes as if all documents in the snap were added. */QueryListener.getInitialViewChanges=function(snap){var result=[];snap.docs.forEach(function(doc){result.push({type:ChangeType.Added,doc:doc});});return result;};return QueryListener;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* PersistencePromise<> is essentially a re-implementation of Promise<> except
* it has a .next() method instead of .then() and .next() and .catch() callbacks
* are executed synchronously when a PersistencePromise resolves rather than
* asynchronously (Promise<> implementations use setImmediate() or similar).
*
* This is necessary to interoperate with IndexedDB which will automatically
* commit transactions if control is returned to the event loop without
* synchronously initiating another operation on the transaction.
*
* NOTE: .then() and .catch() only allow a single consumer, unlike normal
* Promises.
*/var PersistencePromise=/** @class */function(){function PersistencePromise(callback){var _this=this;// NOTE: next/catchCallback will always point to our own wrapper functions,
// not the user's raw next() or catch() callbacks.
// tslint:disable-next-line:no-any Accept any result type for the next call in the Promise chain.
this.nextCallback=null;// tslint:disable-next-line:no-any Accept any result type for the error handler.
this.catchCallback=null;// When the operation resolves, we'll set result or error and mark isDone.
this.result=undefined;this.error=undefined;this.isDone=false;// Set to true when .then() or .catch() are called and prevents additional
// chaining.
this.callbackAttached=false;callback(function(value){_this.isDone=true;_this.result=value;if(_this.nextCallback){// value should be defined unless T is Void, but we can't express
// that in the type system.
_this.nextCallback(value);}},function(error){_this.isDone=true;_this.error=error;if(_this.catchCallback){_this.catchCallback(error);}});}PersistencePromise.prototype.catch=function(fn){return this.next(undefined,fn);};PersistencePromise.prototype.next=function(nextFn,catchFn){var _this=this;if(this.callbackAttached){fail('Called next() or catch() twice for PersistencePromise');}this.callbackAttached=true;if(this.isDone){if(!this.error){return this.wrapSuccess(nextFn,this.result);}else{return this.wrapFailure(catchFn,this.error);}}else{return new PersistencePromise(function(resolve,reject){_this.nextCallback=function(value){_this.wrapSuccess(nextFn,value).next(resolve,reject);};_this.catchCallback=function(error){_this.wrapFailure(catchFn,error).next(resolve,reject);};});}};PersistencePromise.prototype.toPromise=function(){var _this=this;return new Promise(function(resolve,reject){_this.next(resolve,reject);});};PersistencePromise.prototype.wrapUserFunction=function(fn){try{var result=fn();if(result instanceof PersistencePromise){return result;}else{return PersistencePromise.resolve(result);}}catch(e){return PersistencePromise.reject(e);}};PersistencePromise.prototype.wrapSuccess=function(nextFn,value){if(nextFn){return this.wrapUserFunction(function(){return nextFn(value);});}else{// If there's no nextFn, then R must be the same as T but we
// can't express that in the type system.
// tslint:disable-next-line:no-any
return PersistencePromise.resolve(value);}};PersistencePromise.prototype.wrapFailure=function(catchFn,error){if(catchFn){return this.wrapUserFunction(function(){return catchFn(error);});}else{return PersistencePromise.reject(error);}};PersistencePromise.resolve=function(result){return new PersistencePromise(function(resolve,reject){resolve(result);});};PersistencePromise.reject=function(error){return new PersistencePromise(function(resolve,reject){reject(error);});};PersistencePromise.waitFor=function(// tslint:disable-next-line:no-any Accept all Promise types in waitFor().
all){var expectedCount=all.length;if(expectedCount===0){return PersistencePromise.resolve();}var resolvedCount=0;return new PersistencePromise(function(resolve,reject){for(var _i=0,all_1=all;_i<all_1.length;_i++){var promise=all_1[_i];promise.next(function(){++resolvedCount;if(resolvedCount===expectedCount){resolve();}},function(err){return reject(err);});}});};PersistencePromise.map=function(all){var results=[];var promises=[];var _loop_1=function(i){promises[i]=all[i].next(function(result){results[i]=result;});};for(var i=0;i<all.length;++i){_loop_1(i);}return PersistencePromise.waitFor(promises).next(function(){return results;});};return PersistencePromise;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* A garbage collector implementation that eagerly collects documents as soon as
* they're no longer referenced in any of its registered GarbageSources.
*
* This implementation keeps track of a set of keys that are potentially garbage
* without keeping an exact reference count. During collectGarbage, the
* collector verifies that all potential garbage keys actually have no
* references by consulting its list of garbage sources.
*/var EagerGarbageCollector=/** @class */function(){function EagerGarbageCollector(){this.isEager=true;/**
* The garbage collectible sources to double-check during garbage collection.
*/this.sources=[];/**
* A set of potentially garbage keys.
* PORTING NOTE: This would be a mutable set if Javascript had one.
*/this.potentialGarbage=documentKeySet();}EagerGarbageCollector.prototype.addGarbageSource=function(garbageSource){this.sources.push(garbageSource);garbageSource.setGarbageCollector(this);};EagerGarbageCollector.prototype.removeGarbageSource=function(garbageSource){this.sources.splice(this.sources.indexOf(garbageSource),1);garbageSource.setGarbageCollector(null);};EagerGarbageCollector.prototype.addPotentialGarbageKey=function(key){this.potentialGarbage=this.potentialGarbage.add(key);};EagerGarbageCollector.prototype.collectGarbage=function(txn){var _this=this;var promises=[];var garbageKeys=documentKeySet();this.potentialGarbage.forEach(function(key){var hasRefsPromise=_this.documentHasAnyReferences(txn,key);promises.push(hasRefsPromise.next(function(hasRefs){// If there are no references, get the key.
if(!hasRefs){garbageKeys=garbageKeys.add(key);}return PersistencePromise.resolve();}));});// Clear locally retained potential keys and returned confirmed garbage.
this.potentialGarbage=documentKeySet();return PersistencePromise.waitFor(promises).next(function(){return garbageKeys;});};EagerGarbageCollector.prototype.documentHasAnyReferences=function(txn,key){var initial=PersistencePromise.resolve(false);return this.sources.map(function(source){return function(){return source.containsKey(txn,key);};}).reduce(function(promise,nextPromise){return promise.next(function(result){if(result){return PersistencePromise.resolve(true);}else{return nextPromise();}});},initial);};return EagerGarbageCollector;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* A set of changes to what documents are currently in view and out of view for
* a given query. These changes are sent to the LocalStore by the View (via
* the SyncEngine) and are used to pin / unpin documents as appropriate.
*/var LocalViewChanges=/** @class */function(){function LocalViewChanges(query,addedKeys,removedKeys){this.query=query;this.addedKeys=addedKeys;this.removedKeys=removedKeys;}LocalViewChanges.fromSnapshot=function(viewSnapshot){var addedKeys=documentKeySet();var removedKeys=documentKeySet();for(var _i=0,_a=viewSnapshot.docChanges;_i<_a.length;_i++){var docChange=_a[_i];switch(docChange.type){case ChangeType.Added:addedKeys=addedKeys.add(docChange.doc.key);break;case ChangeType.Removed:removedKeys=removedKeys.add(docChange.doc.key);break;default:// do nothing
}}return new LocalViewChanges(viewSnapshot.query,addedKeys,removedKeys);};return LocalViewChanges;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* A collection of references to a document from some kind of numbered entity
* (either a target ID or batch ID). As references are added to or removed from
* the set corresponding events are emitted to a registered garbage collector.
*
* Each reference is represented by a DocumentReference object. Each of them
* contains enough information to uniquely identify the reference. They are all
* stored primarily in a set sorted by key. A document is considered garbage if
* there's no references in that set (this can be efficiently checked thanks to
* sorting by key).
*
* ReferenceSet also keeps a secondary set that contains references sorted by
* IDs. This one is used to efficiently implement removal of all references by
* some target ID.
*/var ReferenceSet=/** @class */function(){function ReferenceSet(){// A set of outstanding references to a document sorted by key.
this.refsByKey=new SortedSet(DocReference.compareByKey);// A set of outstanding references to a document sorted by target id.
this.refsByTarget=new SortedSet(DocReference.compareByTargetId);/** Keeps track of keys that have references */this.garbageCollector=null;}/** Returns true if the reference set contains no references. */ReferenceSet.prototype.isEmpty=function(){return this.refsByKey.isEmpty();};/** Adds a reference to the given document key for the given ID. */ReferenceSet.prototype.addReference=function(key,id){var ref=new DocReference(key,id);this.refsByKey=this.refsByKey.add(ref);this.refsByTarget=this.refsByTarget.add(ref);};/** Add references to the given document keys for the given ID. */ReferenceSet.prototype.addReferences=function(keys,id){var _this=this;keys.forEach(function(key){return _this.addReference(key,id);});};/**
* Removes a reference to the given document key for the given
* ID.
*/ReferenceSet.prototype.removeReference=function(key,id){this.removeRef(new DocReference(key,id));};ReferenceSet.prototype.removeReferences=function(keys,id){var _this=this;keys.forEach(function(key){return _this.removeReference(key,id);});};/**
* Clears all references with a given ID. Calls removeRef() for each key
* removed.
*/ReferenceSet.prototype.removeReferencesForId=function(id){var _this=this;var emptyKey=DocumentKey.EMPTY;var startRef=new DocReference(emptyKey,id);var endRef=new DocReference(emptyKey,id+1);this.refsByTarget.forEachInRange([startRef,endRef],function(ref){_this.removeRef(ref);});};ReferenceSet.prototype.removeAllReferences=function(){var _this=this;this.refsByKey.forEach(function(ref){return _this.removeRef(ref);});};ReferenceSet.prototype.removeRef=function(ref){this.refsByKey=this.refsByKey.delete(ref);this.refsByTarget=this.refsByTarget.delete(ref);if(this.garbageCollector!==null){this.garbageCollector.addPotentialGarbageKey(ref.key);}};ReferenceSet.prototype.referencesForId=function(id){var emptyKey=DocumentKey.EMPTY;var startRef=new DocReference(emptyKey,id);var endRef=new DocReference(emptyKey,id+1);var keys=documentKeySet();this.refsByTarget.forEachInRange([startRef,endRef],function(ref){keys=keys.add(ref.key);});return keys;};ReferenceSet.prototype.setGarbageCollector=function(garbageCollector){this.garbageCollector=garbageCollector;};ReferenceSet.prototype.containsKey=function(txn,key){var ref=new DocReference(key,0);var firstRef=this.refsByKey.firstAfterOrEqual(ref);return PersistencePromise.resolve(firstRef!==null&&key.isEqual(firstRef.key));};return ReferenceSet;}();var DocReference=/** @class */function(){function DocReference(key,targetOrBatchId){this.key=key;this.targetOrBatchId=targetOrBatchId;}/** Compare by key then by ID */DocReference.compareByKey=function(left,right){return DocumentKey.comparator(left.key,right.key)||primitiveComparator(left.targetOrBatchId,right.targetOrBatchId);};/** Compare by ID then by key */DocReference.compareByTargetId=function(left,right){return primitiveComparator(left.targetOrBatchId,right.targetOrBatchId)||DocumentKey.comparator(left.key,right.key);};return DocReference;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var RESERVED_BITS=1;var GeneratorIds;(function(GeneratorIds){GeneratorIds[GeneratorIds["LocalStore"]=0]="LocalStore";GeneratorIds[GeneratorIds["SyncEngine"]=1]="SyncEngine";})(GeneratorIds||(GeneratorIds={}));/**
* TargetIdGenerator generates monotonically increasing integer IDs. There are
* separate generators for different scopes. While these generators will operate
* independently of each other, they are scoped, such that no two generators
* will ever produce the same ID. This is useful, because sometimes the backend
* may group IDs from separate parts of the client into the same ID space.
*/var TargetIdGenerator=/** @class */function(){function TargetIdGenerator(generatorId,initAfter){if(initAfter===void 0){initAfter=0;}this.generatorId=generatorId;// Replace the generator part of initAfter with this generator's ID.
var afterWithoutGenerator=initAfter>>RESERVED_BITS<<RESERVED_BITS;var afterGenerator=initAfter-afterWithoutGenerator;if(afterGenerator>=generatorId){// For example, if:
// this.generatorId = 0b0000
// after = 0b1011
// afterGenerator = 0b0001
// Then:
// previous = 0b1010
// next = 0b1100
this.previousId=afterWithoutGenerator|this.generatorId;}else{// For example, if:
// this.generatorId = 0b0001
// after = 0b1010
// afterGenerator = 0b0000
// Then:
// previous = 0b1001
// next = 0b1011
this.previousId=(afterWithoutGenerator|this.generatorId)-(1<<RESERVED_BITS);}}TargetIdGenerator.prototype.next=function(){this.previousId+=1<<RESERVED_BITS;return this.previousId;};TargetIdGenerator.forLocalStore=function(initAfter){if(initAfter===void 0){initAfter=0;}return new TargetIdGenerator(GeneratorIds.LocalStore,initAfter);};TargetIdGenerator.forSyncEngine=function(){return new TargetIdGenerator(GeneratorIds.SyncEngine);};return TargetIdGenerator;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var AddedLimboDocument=/** @class */function(){function AddedLimboDocument(key){this.key=key;}return AddedLimboDocument;}();var RemovedLimboDocument=/** @class */function(){function RemovedLimboDocument(key){this.key=key;}return RemovedLimboDocument;}();/**
* View is responsible for computing the final merged truth of what docs are in
* a query. It gets notified of local and remote changes to docs, and applies
* the query filters and limits to determine the most correct possible results.
*/var View=/** @class */function(){function View(query,/** Documents included in the remote target */_syncedDocuments){this.query=query;this._syncedDocuments=_syncedDocuments;this.syncState=null;/**
* A flag whether the view is current with the backend. A view is considered
* current after it has seen the current flag from the backend and did not
* lose consistency within the watch stream (e.g. because of an existence
* filter mismatch).
*/this.current=false;/** Documents in the view but not in the remote target */this.limboDocuments=documentKeySet();/** Document Keys that have local changes */this.mutatedKeys=documentKeySet();this.documentSet=new DocumentSet(query.docComparator.bind(query));}Object.defineProperty(View.prototype,"syncedDocuments",{/**
* The set of remote documents that the server has told us belongs to the target associated with
* this view.
*/get:function(){return this._syncedDocuments;},enumerable:true,configurable:true});/**
* Iterates over a set of doc changes, applies the query limit, and computes
* what the new results should be, what the changes were, and whether we may
* need to go back to the local cache for more results. Does not make any
* changes to the view.
* @param docChanges The doc changes to apply to this view.
* @param previousChanges If this is being called with a refill, then start
* with this set of docs and changes instead of the current view.
* @return a new set of docs, changes, and refill flag.
*/View.prototype.computeDocChanges=function(docChanges,previousChanges){var _this=this;var changeSet=previousChanges?previousChanges.changeSet:new DocumentChangeSet();var oldDocumentSet=previousChanges?previousChanges.documentSet:this.documentSet;var newMutatedKeys=previousChanges?previousChanges.mutatedKeys:this.mutatedKeys;var newDocumentSet=oldDocumentSet;var needsRefill=false;// Track the last doc in a (full) limit. This is necessary, because some
// update (a delete, or an update moving a doc past the old limit) might
// mean there is some other document in the local cache that either should
// come (1) between the old last limit doc and the new last document, in the
// case of updates, or (2) after the new last document, in the case of
// deletes. So we keep this doc at the old limit to compare the updates to.
//
// Note that this should never get used in a refill (when previousChanges is
// set), because there will only be adds -- no deletes or updates.
var lastDocInLimit=this.query.hasLimit()&&oldDocumentSet.size===this.query.limit?oldDocumentSet.last():null;docChanges.inorderTraversal(function(key,newMaybeDoc){var oldDoc=oldDocumentSet.get(key);var newDoc=newMaybeDoc instanceof Document?newMaybeDoc:null;if(newDoc){assert(key.isEqual(newDoc.key),'Mismatching keys found in document changes: '+key+' != '+newDoc.key);newDoc=_this.query.matches(newDoc)?newDoc:null;}if(newDoc){newDocumentSet=newDocumentSet.add(newDoc);if(newDoc.hasLocalMutations){newMutatedKeys=newMutatedKeys.add(key);}else{newMutatedKeys=newMutatedKeys.delete(key);}}else{newDocumentSet=newDocumentSet.delete(key);newMutatedKeys=newMutatedKeys.delete(key);}// Calculate change
if(oldDoc&&newDoc){var docsEqual=oldDoc.data.isEqual(newDoc.data);if(!docsEqual||oldDoc.hasLocalMutations!==newDoc.hasLocalMutations){// only report a change if document actually changed
if(docsEqual){changeSet.track({type:ChangeType.Metadata,doc:newDoc});}else{changeSet.track({type:ChangeType.Modified,doc:newDoc});}if(lastDocInLimit&&_this.query.docComparator(newDoc,lastDocInLimit)>0){// This doc moved from inside the limit to after the limit.
// That means there may be some doc in the local cache that's
// actually less than this one.
needsRefill=true;}}}else if(!oldDoc&&newDoc){changeSet.track({type:ChangeType.Added,doc:newDoc});}else if(oldDoc&&!newDoc){changeSet.track({type:ChangeType.Removed,doc:oldDoc});if(lastDocInLimit){// A doc was removed from a full limit query. We'll need to
// requery from the local cache to see if we know about some other
// doc that should be in the results.
needsRefill=true;}}});if(this.query.hasLimit()){// TODO(klimt): Make DocumentSet size be constant time.
while(newDocumentSet.size>this.query.limit){var oldDoc=newDocumentSet.last();newDocumentSet=newDocumentSet.delete(oldDoc.key);changeSet.track({type:ChangeType.Removed,doc:oldDoc});}}assert(!needsRefill||!previousChanges,'View was refilled using docs that themselves needed refilling.');return{documentSet:newDocumentSet,changeSet:changeSet,needsRefill:needsRefill,mutatedKeys:newMutatedKeys};};/**
* Updates the view with the given ViewDocumentChanges and updates limbo docs
* and sync state from the given (optional) target change.
* @param docChanges The set of changes to make to the view's docs.
* @param targetChange A target change to apply for computing limbo docs and
* sync state.
* @return A new ViewChange with the given docs, changes, and sync state.
*/View.prototype.applyChanges=function(docChanges,targetChange){var _this=this;assert(!docChanges.needsRefill,'Cannot apply changes that need a refill');var oldDocs=this.documentSet;this.documentSet=docChanges.documentSet;this.mutatedKeys=docChanges.mutatedKeys;// Sort changes based on type and query comparator
var changes=docChanges.changeSet.getChanges();changes.sort(function(c1,c2){return compareChangeType(c1.type,c2.type)||_this.query.docComparator(c1.doc,c2.doc);});this.applyTargetChange(targetChange);var limboChanges=this.updateLimboDocuments();var synced=this.limboDocuments.size===0&&this.current;var newSyncState=synced?SyncState.Synced:SyncState.Local;var syncStateChanged=newSyncState!==this.syncState;this.syncState=newSyncState;if(changes.length===0&&!syncStateChanged){// no changes
return{limboChanges:limboChanges};}else{var snap=new ViewSnapshot(this.query,docChanges.documentSet,oldDocs,changes,newSyncState===SyncState.Local,!docChanges.mutatedKeys.isEmpty(),syncStateChanged,/* excludesMetadataChanges= */false);return{snapshot:snap,limboChanges:limboChanges};}};/**
* Applies an OnlineState change to the view, potentially generating a
* ViewChange if the view's syncState changes as a result.
*/View.prototype.applyOnlineStateChange=function(onlineState){if(this.current&&onlineState===OnlineState.Offline){// If we're offline, set `current` to false and then call applyChanges()
// to refresh our syncState and generate a ViewChange as appropriate. We
// are guaranteed to get a new TargetChange that sets `current` back to
// true once the client is back online.
this.current=false;return this.applyChanges({documentSet:this.documentSet,changeSet:new DocumentChangeSet(),mutatedKeys:this.mutatedKeys,needsRefill:false});}else{// No effect, just return a no-op ViewChange.
return{limboChanges:[]};}};/**
* Returns whether the doc for the given key should be in limbo.
*/View.prototype.shouldBeInLimbo=function(key){// If the remote end says it's part of this query, it's not in limbo.
if(this._syncedDocuments.has(key)){return false;}// The local store doesn't think it's a result, so it shouldn't be in limbo.
if(!this.documentSet.has(key)){return false;}// If there are local changes to the doc, they might explain why the server
// doesn't know that it's part of the query. So don't put it in limbo.
// TODO(klimt): Ideally, we would only consider changes that might actually
// affect this specific query.
if(this.documentSet.get(key).hasLocalMutations){return false;}// Everything else is in limbo.
return true;};/**
* Updates syncedDocuments, current, and limbo docs based on the given change.
* Returns the list of changes to which docs are in limbo.
*/View.prototype.applyTargetChange=function(targetChange){if(targetChange){var targetMapping=targetChange.mapping;if(targetMapping instanceof ResetMapping){this._syncedDocuments=targetMapping.documents;}else if(targetMapping instanceof UpdateMapping){this._syncedDocuments=targetMapping.applyToKeySet(this._syncedDocuments);}switch(targetChange.currentStatusUpdate){case CurrentStatusUpdate.MarkCurrent:this.current=true;break;case CurrentStatusUpdate.MarkNotCurrent:this.current=false;break;case CurrentStatusUpdate.None:break;default:fail('Unknown current status update: '+targetChange.currentStatusUpdate);}}};View.prototype.updateLimboDocuments=function(){var _this=this;// We can only determine limbo documents when we're in-sync with the server.
if(!this.current){return[];}// TODO(klimt): Do this incrementally so that it's not quadratic when
// updating many documents.
var oldLimboDocuments=this.limboDocuments;this.limboDocuments=documentKeySet();this.documentSet.forEach(function(doc){if(_this.shouldBeInLimbo(doc.key)){_this.limboDocuments=_this.limboDocuments.add(doc.key);}});// Diff the new limbo docs with the old limbo docs.
var changes=[];oldLimboDocuments.forEach(function(key){if(!_this.limboDocuments.has(key)){changes.push(new RemovedLimboDocument(key));}});this.limboDocuments.forEach(function(key){if(!oldLimboDocuments.has(key)){changes.push(new AddedLimboDocument(key));}});return changes;};return View;}();function compareChangeType(c1,c2){var order=function(change){switch(change){case ChangeType.Added:return 1;case ChangeType.Modified:return 2;case ChangeType.Metadata:// A metadata change is converted to a modified change at the public
// api layer. Since we sort by document key and then change type,
// metadata and modified changes must be sorted equivalently.
return 2;case ChangeType.Removed:return 0;default:return fail('Unknown ChangeType: '+change);}};return order(c1)-order(c2);}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$1='SyncEngine';/**
* QueryView contains all of the data that SyncEngine needs to keep track of for
* a particular query.
*/var QueryView=/** @class */function(){function QueryView(/**
* The query itself.
*/query,/**
* The target number created by the client that is used in the watch
* stream to identify this query.
*/targetId,/**
* An identifier from the datastore backend that indicates the last state
* of the results that was received. This can be used to indicate where
* to continue receiving new doc changes for the query.
*/resumeToken,/**
* The view is responsible for computing the final merged truth of what
* docs are in the query. It gets notified of local and remote changes,
* and applies the query filters and limits to determine the most correct
* possible results.
*/view){this.query=query;this.targetId=targetId;this.resumeToken=resumeToken;this.view=view;}return QueryView;}();/**
* SyncEngine is the central controller in the client SDK architecture. It is
* the glue code between the EventManager, LocalStore, and RemoteStore. Some of
* SyncEngine's responsibilities include:
* 1. Coordinating client requests and remote events between the EventManager
* and the local and remote data stores.
* 2. Managing a View object for each query, providing the unified view between
* the local and remote data stores.
* 3. Notifying the RemoteStore when the LocalStore has new mutations in its
* queue that need sending to the backend.
*
* The SyncEngines methods should only ever be called by methods running in the
* global async queue.
*/var SyncEngine=/** @class */function(){function SyncEngine(localStore,remoteStore,currentUser){this.localStore=localStore;this.remoteStore=remoteStore;this.currentUser=currentUser;this.viewHandler=null;this.errorHandler=null;this.queryViewsByQuery=new ObjectMap(function(q){return q.canonicalId();});this.queryViewsByTarget={};this.limboTargetsByKey=new SortedMap(DocumentKey.comparator);this.limboKeysByTarget={};this.limboDocumentRefs=new ReferenceSet();this.limboCollector=new EagerGarbageCollector();/** Stores user completion handlers, indexed by User and BatchId. */this.mutationUserCallbacks={};this.targetIdGenerator=TargetIdGenerator.forSyncEngine();}/** Subscribes view and error handler. Can be called only once. */SyncEngine.prototype.subscribe=function(viewHandler,errorHandler){assert(viewHandler!==null&&errorHandler!==null,'View and error handlers cannot be null');assert(this.viewHandler===null&&this.errorHandler===null,'SyncEngine already has a subscriber.');this.viewHandler=viewHandler;this.errorHandler=errorHandler;this.limboCollector.addGarbageSource(this.limboDocumentRefs);};/**
* Initiates the new listen, resolves promise when listen enqueued to the
* server. All the subsequent view snapshots or errors are sent to the
* subscribed handlers. Returns the targetId of the query.
*/SyncEngine.prototype.listen=function(query){var _this=this;this.assertSubscribed('listen()');assert(!this.queryViewsByQuery.has(query),'We already listen to the query: '+query);return this.localStore.allocateQuery(query).then(function(queryData){return _this.localStore.executeQuery(query).then(function(docs){return _this.localStore.remoteDocumentKeys(queryData.targetId).then(function(remoteKeys){var view=new View(query,remoteKeys);var viewDocChanges=view.computeDocChanges(docs);var viewChange=view.applyChanges(viewDocChanges);assert(viewChange.limboChanges.length===0,'View returned limbo docs before target ack from the server.');assert(!!viewChange.snapshot,'applyChanges for new view should always return a snapshot');var data=new QueryView(query,queryData.targetId,queryData.resumeToken,view);_this.queryViewsByQuery.set(query,data);_this.queryViewsByTarget[queryData.targetId]=data;_this.viewHandler([viewChange.snapshot]);_this.remoteStore.listen(queryData);});}).then(function(){return queryData.targetId;});});};/** Stops listening to the query. */SyncEngine.prototype.unlisten=function(query){var _this=this;this.assertSubscribed('unlisten()');var queryView=this.queryViewsByQuery.get(query);assert(!!queryView,'Trying to unlisten on query not found:'+query);return this.localStore.releaseQuery(query).then(function(){_this.remoteStore.unlisten(queryView.targetId);return _this.removeAndCleanupQuery(queryView).then(function(){return _this.localStore.collectGarbage();});});};/**
* Initiates the write of local mutation batch which involves adding the
* writes to the mutation queue, notifying the remote store about new
* mutations and raising events for any changes this write caused.
*
* The promise returned by this call is resolved when the above steps
* have completed, *not* when the write was acked by the backend. The
* userCallback is resolved once the write was acked/rejected by the
* backend (or failed locally for any other reason).
*/SyncEngine.prototype.write=function(batch,userCallback){var _this=this;this.assertSubscribed('write()');return this.localStore.localWrite(batch).then(function(result){_this.addMutationCallback(result.batchId,userCallback);return _this.emitNewSnapsAndNotifyLocalStore(result.changes);}).then(function(){return _this.remoteStore.fillWritePipeline();});};// TODO(klimt): Wrap the given error in a standard Firestore error object.
SyncEngine.prototype.wrapUpdateFunctionError=function(error$$1){return error$$1;};/**
* Takes an updateFunction in which a set of reads and writes can be performed
* atomically. In the updateFunction, the client can read and write values
* using the supplied transaction object. After the updateFunction, all
* changes will be committed. If some other client has changed any of the data
* referenced, then the updateFunction will be called again. If the
* updateFunction still fails after the given number of retries, then the
* transaction will be rejection.
*
* The transaction object passed to the updateFunction contains methods for
* accessing documents and collections. Unlike other datastore access, data
* accessed with the transaction will not reflect local changes that have not
* been committed. For this reason, it is required that all reads are
* performed before any writes. Transactions must be performed while online.
*
* The promise returned is resolved when the transaction is fully committed.
*/SyncEngine.prototype.runTransaction=function(updateFunction,retries){var _this=this;if(retries===void 0){retries=5;}assert(retries>=0,'Got negative number of retries for transaction.');var transaction=this.remoteStore.createTransaction();var wrappedUpdateFunction=function(){try{var userPromise=updateFunction(transaction);if(isNullOrUndefined(userPromise)||!userPromise.catch||!userPromise.then){return Promise.reject(Error('Transaction callback must return a Promise'));}return userPromise.catch(function(e){return Promise.reject(_this.wrapUpdateFunctionError(e));});}catch(e){return Promise.reject(_this.wrapUpdateFunctionError(e));}};return wrappedUpdateFunction().then(function(result){return transaction.commit().then(function(){return result;}).catch(function(error$$1){if(retries===0){return Promise.reject(error$$1);}// TODO(klimt): Put in a retry delay?
return _this.runTransaction(updateFunction,retries-1);});});};SyncEngine.prototype.applyRemoteEvent=function(remoteEvent){var _this=this;this.assertSubscribed('applyRemoteEvent()');// Make sure limbo documents are deleted if there were no results.
// Filter out document additions to targets that they already belong to.
forEachNumber(remoteEvent.targetChanges,function(targetId,targetChange){var limboKey=_this.limboKeysByTarget[targetId];if(!limboKey){var qv=_this.queryViewsByTarget[targetId];assert(!!qv,'Missing QueryView for non-limbo query: '+targetId);targetChange.mapping.filterUpdates(qv.view.syncedDocuments);}else{remoteEvent.synthesizeDeleteForLimboTargetChange(targetChange,limboKey);}});return this.localStore.applyRemoteEvent(remoteEvent).then(function(changes){return _this.emitNewSnapsAndNotifyLocalStore(changes,remoteEvent);});};/**
* Applies an OnlineState change to the sync engine and notifies any views of
* the change.
*/SyncEngine.prototype.applyOnlineStateChange=function(onlineState){var newViewSnapshots=[];this.queryViewsByQuery.forEach(function(query,queryView){var viewChange=queryView.view.applyOnlineStateChange(onlineState);assert(viewChange.limboChanges.length===0,'OnlineState should not affect limbo documents.');if(viewChange.snapshot){newViewSnapshots.push(viewChange.snapshot);}});this.viewHandler(newViewSnapshots);};SyncEngine.prototype.rejectListen=function(targetId,err){var _this=this;this.assertSubscribed('rejectListens()');var limboKey=this.limboKeysByTarget[targetId];if(limboKey){// Since this query failed, we won't want to manually unlisten to it.
// So go ahead and remove it from bookkeeping.
this.limboTargetsByKey=this.limboTargetsByKey.remove(limboKey);delete this.limboKeysByTarget[targetId];// TODO(klimt): We really only should do the following on permission
// denied errors, but we don't have the cause code here.
// It's a limbo doc. Create a synthetic event saying it was deleted.
// This is kind of a hack. Ideally, we would have a method in the local
// store to purge a document. However, it would be tricky to keep all of
// the local store's invariants with another method.
var docMap=new SortedMap(DocumentKey.comparator);docMap=docMap.insert(limboKey,new NoDocument(limboKey,SnapshotVersion.forDeletedDoc()));var limboDocuments=documentKeySet().add(limboKey);var event_1=new RemoteEvent(SnapshotVersion.MIN,{},docMap,limboDocuments);return this.applyRemoteEvent(event_1);}else{var queryView_1=this.queryViewsByTarget[targetId];assert(!!queryView_1,'Unknown targetId: '+targetId);return this.localStore.releaseQuery(queryView_1.query).then(function(){return _this.removeAndCleanupQuery(queryView_1).then(function(){_this.errorHandler(queryView_1.query,err);});});}};SyncEngine.prototype.applySuccessfulWrite=function(mutationBatchResult){var _this=this;this.assertSubscribed('applySuccessfulWrite()');// The local store may or may not be able to apply the write result and
// raise events immediately (depending on whether the watcher is caught
// up), so we raise user callbacks first so that they consistently happen
// before listen events.
this.processUserCallback(mutationBatchResult.batch.batchId,/*error=*/null);return this.localStore.acknowledgeBatch(mutationBatchResult).then(function(changes){return _this.emitNewSnapsAndNotifyLocalStore(changes);});};SyncEngine.prototype.rejectFailedWrite=function(batchId,error$$1){var _this=this;this.assertSubscribed('rejectFailedWrite()');// The local store may or may not be able to apply the write result and
// raise events immediately (depending on whether the watcher is caught up),
// so we raise user callbacks first so that they consistently happen before
// listen events.
this.processUserCallback(batchId,error$$1);return this.localStore.rejectBatch(batchId).then(function(changes){return _this.emitNewSnapsAndNotifyLocalStore(changes);});};SyncEngine.prototype.addMutationCallback=function(batchId,callback){var newCallbacks=this.mutationUserCallbacks[this.currentUser.toKey()];if(!newCallbacks){newCallbacks=new SortedMap(primitiveComparator);}newCallbacks=newCallbacks.insert(batchId,callback);this.mutationUserCallbacks[this.currentUser.toKey()]=newCallbacks;};/**
* Resolves or rejects the user callback for the given batch and then discards
* it.
*/SyncEngine.prototype.processUserCallback=function(batchId,error$$1){var newCallbacks=this.mutationUserCallbacks[this.currentUser.toKey()];// NOTE: Mutations restored from persistence won't have callbacks, so it's
// okay for there to be no callback for this ID.
if(newCallbacks){var callback=newCallbacks.get(batchId);if(callback){assert(batchId===newCallbacks.minKey(),'Mutation callbacks processed out-of-order?');if(error$$1){callback.reject(error$$1);}else{callback.resolve();}newCallbacks=newCallbacks.remove(batchId);}this.mutationUserCallbacks[this.currentUser.toKey()]=newCallbacks;}};SyncEngine.prototype.removeAndCleanupQuery=function(queryView){this.queryViewsByQuery.delete(queryView.query);delete this.queryViewsByTarget[queryView.targetId];this.limboDocumentRefs.removeReferencesForId(queryView.targetId);return this.gcLimboDocuments();};SyncEngine.prototype.updateTrackedLimbos=function(targetId,limboChanges){for(var _i=0,limboChanges_1=limboChanges;_i<limboChanges_1.length;_i++){var limboChange=limboChanges_1[_i];if(limboChange instanceof AddedLimboDocument){this.limboDocumentRefs.addReference(limboChange.key,targetId);this.trackLimboChange(limboChange);}else if(limboChange instanceof RemovedLimboDocument){debug(LOG_TAG$1,'Document no longer in limbo: '+limboChange.key);this.limboDocumentRefs.removeReference(limboChange.key,targetId);}else{fail('Unknown limbo change: '+JSON.stringify(limboChange));}}return this.gcLimboDocuments();};SyncEngine.prototype.trackLimboChange=function(limboChange){var key=limboChange.key;if(!this.limboTargetsByKey.get(key)){debug(LOG_TAG$1,'New document in limbo: '+key);var limboTargetId=this.targetIdGenerator.next();var query=Query.atPath(key.path);this.limboKeysByTarget[limboTargetId]=key;this.remoteStore.listen(new QueryData(query,limboTargetId,QueryPurpose.Listen));this.limboTargetsByKey=this.limboTargetsByKey.insert(key,limboTargetId);}};SyncEngine.prototype.gcLimboDocuments=function(){var _this=this;// HACK: We can use a null transaction here, because we know that the
// reference set is entirely within memory and doesn't need a store engine.
return this.limboCollector.collectGarbage(null).next(function(keys){keys.forEach(function(key){var limboTargetId=_this.limboTargetsByKey.get(key);if(limboTargetId===null){// This target already got removed, because the query failed.
return;}_this.remoteStore.unlisten(limboTargetId);_this.limboTargetsByKey=_this.limboTargetsByKey.remove(key);delete _this.limboKeysByTarget[limboTargetId];});}).toPromise();};// Visible for testing
SyncEngine.prototype.currentLimboDocs=function(){return this.limboTargetsByKey;};SyncEngine.prototype.emitNewSnapsAndNotifyLocalStore=function(changes,remoteEvent){var _this=this;var newSnaps=[];var docChangesInAllViews=[];var queriesProcessed=[];this.queryViewsByQuery.forEach(function(_,queryView){queriesProcessed.push(Promise.resolve().then(function(){var viewDocChanges=queryView.view.computeDocChanges(changes);if(!viewDocChanges.needsRefill){return viewDocChanges;}// The query has a limit and some docs were removed, so we need
// to re-run the query against the local store to make sure we
// didn't lose any good docs that had been past the limit.
return _this.localStore.executeQuery(queryView.query).then(function(docs){return queryView.view.computeDocChanges(docs,viewDocChanges);});}).then(function(viewDocChanges){var targetChange=remoteEvent&&remoteEvent.targetChanges[queryView.targetId];var viewChange=queryView.view.applyChanges(viewDocChanges,targetChange);return _this.updateTrackedLimbos(queryView.targetId,viewChange.limboChanges).then(function(){if(viewChange.snapshot){newSnaps.push(viewChange.snapshot);var docChanges=LocalViewChanges.fromSnapshot(viewChange.snapshot);docChangesInAllViews.push(docChanges);}});}));});return Promise.all(queriesProcessed).then(function(){_this.viewHandler(newSnaps);return _this.localStore.notifyLocalViewChanges(docChangesInAllViews);}).then(function(){return _this.localStore.collectGarbage();});};SyncEngine.prototype.assertSubscribed=function(fnName){assert(this.viewHandler!==null&&this.errorHandler!==null,'Trying to call '+fnName+' before calling subscribe().');};SyncEngine.prototype.handleUserChange=function(user){var _this=this;this.currentUser=user;return this.localStore.handleUserChange(user).then(function(changes){return _this.emitNewSnapsAndNotifyLocalStore(changes);}).then(function(){return _this.remoteStore.handleUserChange(user);});};return SyncEngine;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var BATCHID_UNKNOWN=-1;/**
* A batch of mutations that will be sent as one unit to the backend.
*/var MutationBatch=/** @class */function(){function MutationBatch(batchId,localWriteTime,mutations){this.batchId=batchId;this.localWriteTime=localWriteTime;this.mutations=mutations;}/**
* Applies all the mutations in this MutationBatch to the specified document
* to create a new remote document
*
* @param docKey The key of the document to apply mutations to.
* @param maybeDoc The document to apply mutations to.
* @param batchResult The result of applying the MutationBatch to the
* backend.
*/MutationBatch.prototype.applyToRemoteDocument=function(docKey,maybeDoc,batchResult){if(maybeDoc){assert(maybeDoc.key.isEqual(docKey),"applyToRemoteDocument: key "+docKey+" should match maybeDoc key\n "+maybeDoc.key);}var mutationResults=batchResult.mutationResults;assert(mutationResults.length===this.mutations.length,"Mismatch between mutations length\n ("+this.mutations.length+") and mutation results length\n ("+mutationResults.length+").");for(var i=0;i<this.mutations.length;i++){var mutation=this.mutations[i];if(mutation.key.isEqual(docKey)){var mutationResult=mutationResults[i];maybeDoc=mutation.applyToRemoteDocument(maybeDoc,mutationResult);}}return maybeDoc;};/**
* Computes the local view of a document given all the mutations in this
* batch.
*
* @param docKey The key of the document to apply mutations to.
* @param maybeDoc The document to apply mutations to.
*/MutationBatch.prototype.applyToLocalView=function(docKey,maybeDoc){if(maybeDoc){assert(maybeDoc.key.isEqual(docKey),"applyToLocalDocument: key "+docKey+" should match maybeDoc key\n "+maybeDoc.key);}var baseDoc=maybeDoc;for(var i=0;i<this.mutations.length;i++){var mutation=this.mutations[i];if(mutation.key.isEqual(docKey)){maybeDoc=mutation.applyToLocalView(maybeDoc,baseDoc,this.localWriteTime);}}return maybeDoc;};MutationBatch.prototype.keys=function(){var keySet=documentKeySet();for(var _i=0,_a=this.mutations;_i<_a.length;_i++){var mutation=_a[_i];keySet=keySet.add(mutation.key);}return keySet;};MutationBatch.prototype.isEqual=function(other){return this.batchId===other.batchId&&arrayEquals(this.mutations,other.mutations);};/**
* Returns true if this mutation batch has already been removed from the
* mutation queue.
*
* Note that not all implementations of the MutationQueue necessarily use
* tombstones as part of their implementation and generally speaking no code
* outside the mutation queues should really care about this.
*/MutationBatch.prototype.isTombstone=function(){return this.mutations.length===0;};/** Converts this batch into a tombstone */MutationBatch.prototype.toTombstone=function(){return new MutationBatch(this.batchId,this.localWriteTime,[]);};return MutationBatch;}();/** The result of applying a mutation batch to the backend. */var MutationBatchResult=/** @class */function(){function MutationBatchResult(batch,commitVersion,mutationResults,streamToken,/**
* A pre-computed mapping from each mutated document to the resulting
* version.
*/docVersions){this.batch=batch;this.commitVersion=commitVersion;this.mutationResults=mutationResults;this.streamToken=streamToken;this.docVersions=docVersions;}/**
* Creates a new MutationBatchResult for the given batch and results. There
* must be one result for each mutation in the batch. This static factory
* caches a document=>version mapping (docVersions).
*/MutationBatchResult.from=function(batch,commitVersion,results,streamToken){assert(batch.mutations.length===results.length,'Mutations sent '+batch.mutations.length+' must equal results received '+results.length);var versionMap=documentVersionMap();var mutations=batch.mutations;for(var i=0;i<mutations.length;i++){var version=results[i].version;if(version===null){// deletes don't have a version, so we substitute the commitVersion
// of the entire batch.
version=commitVersion;}versionMap=versionMap.insert(mutations[i].key,version);}return new MutationBatchResult(batch,commitVersion,results,streamToken,versionMap);};return MutationBatchResult;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var escapeChar='\u0001';var encodedSeparatorChar='\u0001';var encodedNul='\u0010';var encodedEscape='\u0011';/**
* Encodes a resource path into a IndexedDb-compatible string form.
*/function encode(path){var result='';for(var i=0;i<path.length;i++){if(result.length>0){result=encodeSeparator(result);}result=encodeSegment(path.get(i),result);}return encodeSeparator(result);}/** Encodes a single segment of a resource path into the given result */function encodeSegment(segment,resultBuf){var result=resultBuf;var length=segment.length;for(var i=0;i<length;i++){var c=segment.charAt(i);switch(c){case'\0':result+=escapeChar+encodedNul;break;case escapeChar:result+=escapeChar+encodedEscape;break;default:result+=c;}}return result;}/** Encodes a path separator into the given result */function encodeSeparator(result){return result+escapeChar+encodedSeparatorChar;}/**
* Decodes the given IndexedDb-compatible string form of a resource path into
* a ResourcePath instance. Note that this method is not suitable for use with
* decoding resource names from the server; those are One Platform format
* strings.
*/function decode$1(path){// Event the empty path must encode as a path of at least length 2. A path
// with exactly 2 must be the empty path.
var length=path.length;assert(length>=2,'Invalid path '+path);if(length===2){assert(path.charAt(0)===escapeChar&&path.charAt(1)===encodedSeparatorChar,'Non-empty path '+path+' had length 2');return ResourcePath.EMPTY_PATH;}// Escape characters cannot exist past the second-to-last position in the
// source value.
var lastReasonableEscapeIndex=length-2;var segments=[];var segmentBuilder='';for(var start=0;start<length;){// The last two characters of a valid encoded path must be a separator, so
// there must be an end to this segment.
var end=path.indexOf(escapeChar,start);if(end<0||end>lastReasonableEscapeIndex){fail('Invalid encoded resource path: "'+path+'"');}var next=path.charAt(end+1);switch(next){case encodedSeparatorChar:var currentPiece=path.substring(start,end);var segment=void 0;if(segmentBuilder.length===0){// Avoid copying for the common case of a segment that excludes \0
// and \001
segment=currentPiece;}else{segmentBuilder+=currentPiece;segment=segmentBuilder;segmentBuilder='';}segments.push(segment);break;case encodedNul:segmentBuilder+=path.substring(start,end);segmentBuilder+='\0';break;case encodedEscape:// The escape character can be used in the output to encode itself.
segmentBuilder+=path.substring(start,end+1);break;default:fail('Invalid encoded resource path: "'+path+'"');}start=end+2;}return new ResourcePath(segments);}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Schema Version for the Web client:
* 1. Initial version including Mutation Queue, Query Cache, and Remote Document
* Cache
* 2. Added targetCount to targetGlobal row.
*/var SCHEMA_VERSION=2;/**
* Performs database creation and schema upgrades.
*
* Note that in production, this method is only ever used to upgrade the schema
* to SCHEMA_VERSION. Different values of toVersion are only used for testing
* and local feature development.
*/function createOrUpgradeDb(db,txn,fromVersion,toVersion){// This function currently supports migrating to schema version 1 (Mutation
// Queue, Query and Remote Document Cache) and schema version 2 (Query
// counting).
assert(fromVersion<toVersion&&fromVersion>=0&&toVersion<=2,'Unexpected schema upgrade from v${fromVersion} to v{toVersion}.');if(fromVersion<1&&toVersion>=1){createOwnerStore(db);createMutationQueue(db);createQueryCache(db);createRemoteDocumentCache(db);}var p=PersistencePromise.resolve();if(fromVersion<2&&toVersion>=2){p=ensureTargetGlobalExists(txn).next(function(targetGlobal){return saveTargetCount(txn,targetGlobal);});}return p;}/**
* Wrapper class to store timestamps (seconds and nanos) in IndexedDb objects.
*/var DbTimestamp=/** @class */function(){function DbTimestamp(seconds,nanoseconds){this.seconds=seconds;this.nanoseconds=nanoseconds;}return DbTimestamp;}();/**
* A singleton object to be stored in the 'owner' store in IndexedDb.
*
* A given database can be owned by a single tab at a given time. That tab
* must validate that it is still the owner before every write operation and
* should regularly write an updated timestamp to prevent other tabs from
* "stealing" ownership of the db.
*/var DbOwner=/** @class */function(){function DbOwner(ownerId,leaseTimestampMs){this.ownerId=ownerId;this.leaseTimestampMs=leaseTimestampMs;}/** Name of the IndexedDb object store. */DbOwner.store='owner';return DbOwner;}();function createOwnerStore(db){db.createObjectStore(DbOwner.store);}/**
* An object to be stored in the 'mutationQueues' store in IndexedDb.
*
* Each user gets a single queue of MutationBatches to apply to the server.
* DbMutationQueue tracks the metadata about the queue.
*/var DbMutationQueue=/** @class */function(){function DbMutationQueue(/**
* The normalized user ID to which this queue belongs.
*/userId,/**
* An identifier for the highest numbered batch that has been acknowledged
* by the server. All MutationBatches in this queue with batchIds less
* than or equal to this value are considered to have been acknowledged by
* the server.
*/lastAcknowledgedBatchId,/**
* A stream token that was previously sent by the server.
*
* See StreamingWriteRequest in datastore.proto for more details about
* usage.
*
* After sending this token, earlier tokens may not be used anymore so
* only a single stream token is retained.
*/lastStreamToken){this.userId=userId;this.lastAcknowledgedBatchId=lastAcknowledgedBatchId;this.lastStreamToken=lastStreamToken;}/** Name of the IndexedDb object store. */DbMutationQueue.store='mutationQueues';/** Keys are automatically assigned via the userId property. */DbMutationQueue.keyPath='userId';return DbMutationQueue;}();/**
* An object to be stored in the 'mutations' store in IndexedDb.
*
* Represents a batch of user-level mutations intended to be sent to the server
* in a single write. Each user-level batch gets a separate DbMutationBatch
* with a new batchId.
*/var DbMutationBatch=/** @class */function(){function DbMutationBatch(/**
* The normalized user ID to which this batch belongs.
*/userId,/**
* An identifier for this batch, allocated by the mutation queue in a
* monotonically increasing manner.
*/batchId,/**
* The local write time of the batch, stored as milliseconds since the
* epoch.
*/localWriteTimeMs,/**
* A list of mutations to apply. All mutations will be applied atomically.
*
* Mutations are serialized via JsonProtoSerializer.toMutation().
*/mutations){this.userId=userId;this.batchId=batchId;this.localWriteTimeMs=localWriteTimeMs;this.mutations=mutations;}/** Name of the IndexedDb object store. */DbMutationBatch.store='mutations';/** Keys are automatically assigned via the userId, batchId properties. */DbMutationBatch.keyPath=['userId','batchId'];return DbMutationBatch;}();function createMutationQueue(db){db.createObjectStore(DbMutationQueue.store,{keyPath:DbMutationQueue.keyPath});db.createObjectStore(DbMutationBatch.store,{keyPath:DbMutationBatch.keyPath});db.createObjectStore(DbDocumentMutation.store);}/**
* An object to be stored in the 'documentMutations' store in IndexedDb.
*
* A manually maintained index of all the mutation batches that affect a given
* document key. The rows in this table are references based on the contents of
* DbMutationBatch.mutations.
*/var DbDocumentMutation=/** @class */function(){function DbDocumentMutation(){}/**
* Creates a [userId] key for use in the DbDocumentMutations index to iterate
* over all of a user's document mutations.
*/DbDocumentMutation.prefixForUser=function(userId){return[userId];};/**
* Creates a [userId, encodedPath] key for use in the DbDocumentMutations
* index to iterate over all at document mutations for a given path or lower.
*/DbDocumentMutation.prefixForPath=function(userId,path){return[userId,encode(path)];};/**
* Creates a full index key of [userId, encodedPath, batchId] for inserting
* and deleting into the DbDocumentMutations index.
*/DbDocumentMutation.key=function(userId,path,batchId){return[userId,encode(path),batchId];};DbDocumentMutation.store='documentMutations';/**
* Because we store all the useful information for this store in the key,
* there is no useful information to store as the value. The raw (unencoded)
* path cannot be stored because IndexedDb doesn't store prototype
* information.
*/DbDocumentMutation.PLACEHOLDER=new DbDocumentMutation();return DbDocumentMutation;}();function createRemoteDocumentCache(db){db.createObjectStore(DbRemoteDocument.store);}/**
* Represents the known absence of a document at a particular version.
* Stored in IndexedDb as part of a DbRemoteDocument object.
*/var DbNoDocument=/** @class */function(){function DbNoDocument(path,readTime){this.path=path;this.readTime=readTime;}return DbNoDocument;}();/**
* An object to be stored in the 'remoteDocuments' store in IndexedDb. It
* represents either a cached document (if it exists) or a cached "no-document"
* (if it is known to not exist).
*
* Note: This is the persisted equivalent of a MaybeDocument and could perhaps
* be made more general if necessary.
*/var DbRemoteDocument=/** @class */function(){function DbRemoteDocument(/**
* Set to an instance of a DbNoDocument if it is known that no document
* exists.
*/noDocument,/**
* Set to an instance of a Document if there's a cached version of the
* document.
*/document){this.noDocument=noDocument;this.document=document;}DbRemoteDocument.store='remoteDocuments';return DbRemoteDocument;}();/**
* An object to be stored in the 'targets' store in IndexedDb.
*
* This is based on and should be kept in sync with the proto used in the iOS
* client.
*
* Each query the client listens to against the server is tracked on disk so
* that the query can be efficiently resumed on restart.
*/var DbTarget=/** @class */function(){function DbTarget(/**
* An auto-generated sequential numeric identifier for the query.
*
* Queries are stored using their canonicalId as the key, but these
* canonicalIds can be quite long so we additionally assign a unique
* queryId which can be used by referenced data structures (e.g.
* indexes) to minimize the on-disk cost.
*/targetId,/**
* The canonical string representing this query. This is not unique.
*/canonicalId,/**
* The last readTime received from the Watch Service for this query.
*
* This is the same value as TargetChange.read_time in the protos.
*/readTime,/**
* An opaque, server-assigned token that allows watching a query to be
* resumed after disconnecting without retransmitting all the data
* that matches the query. The resume token essentially identifies a
* point in time from which the server should resume sending results.
*
* This is related to the snapshotVersion in that the resumeToken
* effectively also encodes that value, but the resumeToken is opaque
* and sometimes encodes additional information.
*
* A consequence of this is that the resumeToken should be used when
* asking the server to reason about where this client is in the watch
* stream, but the client should use the snapshotVersion for its own
* purposes.
*
* This is the same value as TargetChange.resume_token in the protos.
*/resumeToken,/**
* A sequence number representing the last time this query was
* listened to, used for garbage collection purposes.
*
* Conventionally this would be a timestamp value, but device-local
* clocks are unreliable and they must be able to create new listens
* even while disconnected. Instead this should be a monotonically
* increasing number that's incremented on each listen call.
*
* This is different from the queryId since the queryId is an
* immutable identifier assigned to the Query on first use while
* lastListenSequenceNumber is updated every time the query is
* listened to.
*/lastListenSequenceNumber,/**
* The query for this target.
*
* Because canonical ids are not unique we must store the actual query. We
* use the proto to have an object we can persist without having to
* duplicate translation logic to and from a `Query` object.
*/query){this.targetId=targetId;this.canonicalId=canonicalId;this.readTime=readTime;this.resumeToken=resumeToken;this.lastListenSequenceNumber=lastListenSequenceNumber;this.query=query;}DbTarget.store='targets';/** Keys are automatically assigned via the targetId property. */DbTarget.keyPath='targetId';/** The name of the queryTargets index. */DbTarget.queryTargetsIndexName='queryTargetsIndex';/**
* The index of all canonicalIds to the targets that they match. This is not
* a unique mapping because canonicalId does not promise a unique name for all
* possible queries, so we append the targetId to make the mapping unique.
*/DbTarget.queryTargetsKeyPath=['canonicalId','targetId'];return DbTarget;}();/**
* An object representing an association between a target and a document.
* Stored in the targetDocument object store to store the documents tracked by a
* particular target.
*/var DbTargetDocument=/** @class */function(){function DbTargetDocument(/**
* The targetId identifying a target.
*/targetId,/**
* The path to the document, as encoded in the key.
*/path){this.targetId=targetId;this.path=path;}/** Name of the IndexedDb object store. */DbTargetDocument.store='targetDocuments';/** Keys are automatically assigned via the targetId, path properties. */DbTargetDocument.keyPath=['targetId','path'];/** The index name for the reverse index. */DbTargetDocument.documentTargetsIndex='documentTargetsIndex';/** We also need to create the reverse index for these properties. */DbTargetDocument.documentTargetsKeyPath=['path','targetId'];return DbTargetDocument;}();/**
* A record of global state tracked across all Targets, tracked separately
* to avoid the need for extra indexes.
*
* This should be kept in-sync with the proto used in the iOS client.
*/var DbTargetGlobal=/** @class */function(){function DbTargetGlobal(/**
* The highest numbered target id across all targets.
*
* See DbTarget.targetId.
*/highestTargetId,/**
* The highest numbered lastListenSequenceNumber across all targets.
*
* See DbTarget.lastListenSequenceNumber.
*/highestListenSequenceNumber,/**
* A global snapshot version representing the last consistent snapshot we
* received from the backend. This is monotonically increasing and any
* snapshots received from the backend prior to this version (e.g. for
* targets resumed with a resumeToken) should be suppressed (buffered)
* until the backend has caught up to this snapshot version again. This
* prevents our cache from ever going backwards in time.
*/lastRemoteSnapshotVersion,/**
* The number of targets persisted.
*/targetCount){this.highestTargetId=highestTargetId;this.highestListenSequenceNumber=highestListenSequenceNumber;this.lastRemoteSnapshotVersion=lastRemoteSnapshotVersion;this.targetCount=targetCount;}/**
* The key string used for the single object that exists in the
* DbTargetGlobal store.
*/DbTargetGlobal.key='targetGlobalKey';DbTargetGlobal.store='targetGlobal';return DbTargetGlobal;}();function createQueryCache(db){var targetDocumentsStore=db.createObjectStore(DbTargetDocument.store,{keyPath:DbTargetDocument.keyPath});targetDocumentsStore.createIndex(DbTargetDocument.documentTargetsIndex,DbTargetDocument.documentTargetsKeyPath,{unique:true});var targetStore=db.createObjectStore(DbTarget.store,{keyPath:DbTarget.keyPath});// NOTE: This is unique only because the TargetId is the suffix.
targetStore.createIndex(DbTarget.queryTargetsIndexName,DbTarget.queryTargetsKeyPath,{unique:true});db.createObjectStore(DbTargetGlobal.store);}/**
* Counts the number of targets persisted and adds that value to the target
* global singleton.
*/function saveTargetCount(txn,metadata){var globalStore=txn.store(DbTargetGlobal.store);var targetStore=txn.store(DbTarget.store);return targetStore.count().next(function(count){metadata.targetCount=count;return globalStore.put(DbTargetGlobal.key,metadata);});}/**
* Ensures that the target global singleton row exists by adding it if it's
* missing.
*
* @param {IDBTransaction} txn The version upgrade transaction for indexeddb
*/function ensureTargetGlobalExists(txn){var globalStore=txn.store(DbTargetGlobal.store);return globalStore.get(DbTargetGlobal.key).next(function(metadata){if(metadata!=null){return PersistencePromise.resolve(metadata);}else{metadata=new DbTargetGlobal(/*highestTargetId=*/0,/*lastListenSequenceNumber=*/0,SnapshotVersion.MIN.toTimestamp(),/*targetCount=*/0);return globalStore.put(DbTargetGlobal.key,metadata).next(function(){return metadata;});}});}/**
* The list of all default IndexedDB stores used throughout the SDK. This is
* used when creating transactions so that access across all stores is done
* atomically.
*/var ALL_STORES=[DbMutationQueue.store,DbMutationBatch.store,DbDocumentMutation.store,DbRemoteDocument.store,DbTarget.store,DbOwner.store,DbTargetGlobal.store,DbTargetDocument.store];/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var Deferred$1=/** @class */function(){function Deferred(){var _this=this;this.promise=new Promise(function(resolve,reject){_this.resolve=resolve;_this.reject=reject;});}return Deferred;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$2='SimpleDb';/**
* Provides a wrapper around IndexedDb with a simplified interface that uses
* Promise-like return values to chain operations. Real promises cannot be used
* since .then() continuations are executed asynchronously (e.g. via
* .setImmediate), which would cause IndexedDB to end the transaction.
* See PersistencePromise for more details.
*/var SimpleDb=/** @class */function(){function SimpleDb(db){this.db=db;}/** Opens the specified database, creating or upgrading it if necessary. */SimpleDb.openOrCreate=function(name,version,runUpgrade){assert(SimpleDb.isAvailable(),'IndexedDB not supported in current environment.');debug(LOG_TAG$2,'Opening database:',name);return new PersistencePromise(function(resolve,reject){// TODO(mikelehen): Investigate browser compatibility.
// https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
// suggests IE9 and older WebKit browsers handle upgrade
// differently. They expect setVersion, as described here:
// https://developer.mozilla.org/en-US/docs/Web/API/IDBVersionChangeRequest/setVersion
var request=window.indexedDB.open(name,version);request.onsuccess=function(event){var db=event.target.result;resolve(new SimpleDb(db));};request.onerror=function(event){reject(event.target.error);};request.onupgradeneeded=function(event){debug(LOG_TAG$2,'Database "'+name+'" requires upgrade from version:',event.oldVersion);var db=event.target.result;// We are provided a version upgrade transaction from the request, so
// we wrap that in a SimpleDbTransaction to allow use of our friendlier
// API for schema migration operations.
var txn=new SimpleDbTransaction(request.transaction);runUpgrade(db,txn,event.oldVersion,SCHEMA_VERSION).next(function(){debug(LOG_TAG$2,'Database upgrade to version '+SCHEMA_VERSION+' complete');});};}).toPromise();};/** Deletes the specified database. */SimpleDb.delete=function(name){debug(LOG_TAG$2,'Removing database:',name);return wrapRequest(window.indexedDB.deleteDatabase(name)).toPromise();};/** Returns true if IndexedDB is available in the current environment. */SimpleDb.isAvailable=function(){if(typeof window==='undefined'||window.indexedDB==null){return false;}// We extensively use indexed array values and compound keys,
// which IE and Edge do not support. However, they still have indexedDB
// defined on the window, so we need to check for them here and make sure
// to return that persistence is not enabled for those browsers.
// For tracking support of this feature, see here:
// https://developer.microsoft.com/en-us/microsoft-edge/platform/status/indexeddbarraysandmultientrysupport/
// If we are running in Node using the IndexedDBShim, `window` is defined,
// but `window.navigator` is not. In this case, we support IndexedDB and
// return `true`.
if(window.navigator===undefined){return process.env.USE_MOCK_PERSISTENCE==='YES';}// Check the UA string to find out the browser.
// TODO(mikelehen): Move this logic into packages/util/environment.ts
var ua=window.navigator.userAgent;// IE 10
// ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';
// IE 11
// ua = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
// Edge
// ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML,
// like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0';
if(ua.indexOf('MSIE ')>0||ua.indexOf('Trident/')>0||ua.indexOf('Edge/')>0){return false;}else{return true;}};SimpleDb.prototype.runTransaction=function(mode,objectStores,transactionFn){var transaction=SimpleDbTransaction.open(this.db,mode,objectStores);var transactionFnResult=transactionFn(transaction).catch(function(error$$1){// Abort the transaction if there was an error.
transaction.abort(error$$1);}).toPromise();// Wait for the transaction to complete (i.e. IndexedDb's onsuccess event to
// fire), but still return the original transactionFnResult back to the
// caller.
return transaction.completionPromise.then(function(){return transactionFnResult;});};SimpleDb.prototype.close=function(){this.db.close();};return SimpleDb;}();/**
* A controller for iterating over a key range or index. It allows an iterate
* callback to delete the currently-referenced object, or jump to a new key
* within the key range or index.
*/var IterationController=/** @class */function(){function IterationController(dbCursor){this.dbCursor=dbCursor;this.shouldStop=false;this.nextKey=null;}Object.defineProperty(IterationController.prototype,"isDone",{get:function(){return this.shouldStop;},enumerable:true,configurable:true});Object.defineProperty(IterationController.prototype,"skipToKey",{get:function(){return this.nextKey;},enumerable:true,configurable:true});Object.defineProperty(IterationController.prototype,"cursor",{set:function(value){this.dbCursor=value;},enumerable:true,configurable:true});/**
* This function can be called to stop iteration at any point.
*/IterationController.prototype.done=function(){this.shouldStop=true;};/**
* This function can be called to skip to that next key, which could be
* an index or a primary key.
*/IterationController.prototype.skip=function(key){this.nextKey=key;};/**
* Delete the current cursor value from the object store.
*
* NOTE: You CANNOT do this with a keysOnly query.
*/IterationController.prototype.delete=function(){return wrapRequest(this.dbCursor.delete());};return IterationController;}();/**
* Wraps an IDBTransaction and exposes a store() method to get a handle to a
* specific object store.
*/var SimpleDbTransaction=/** @class */function(){function SimpleDbTransaction(transaction){var _this=this;this.transaction=transaction;this.aborted=false;/**
* A promise that resolves with the result of the IndexedDb transaction.
*/this.completionDeferred=new Deferred$1();this.transaction.oncomplete=function(){_this.completionDeferred.resolve();};this.transaction.onabort=function(){if(transaction.error){_this.completionDeferred.reject(transaction.error);}else{_this.completionDeferred.resolve();}};this.transaction.onerror=function(event){_this.completionDeferred.reject(event.target.error);};}SimpleDbTransaction.open=function(db,mode,objectStoreNames){return new SimpleDbTransaction(db.transaction(objectStoreNames,mode));};Object.defineProperty(SimpleDbTransaction.prototype,"completionPromise",{get:function(){return this.completionDeferred.promise;},enumerable:true,configurable:true});SimpleDbTransaction.prototype.abort=function(error$$1){if(error$$1){this.completionDeferred.reject(error$$1);}if(!this.aborted){debug(LOG_TAG$2,'Aborting transaction: %s',error$$1?error$$1.message:'Client-initiated abort');this.aborted=true;this.transaction.abort();}};/**
* Returns a SimpleDbStore<KeyType, ValueType> for the specified store. All
* operations performed on the SimpleDbStore happen within the context of this
* transaction and it cannot be used anymore once the transaction is
* completed.
*
* Note that we can't actually enforce that the KeyType and ValueType are
* correct, but they allow type safety through the rest of the consuming code.
*/SimpleDbTransaction.prototype.store=function(storeName){var store=this.transaction.objectStore(storeName);assert(!!store,'Object store not part of transaction: '+storeName);return new SimpleDbStore(store);};return SimpleDbTransaction;}();/**
* A wrapper around an IDBObjectStore providing an API that:
*
* 1) Has generic KeyType / ValueType parameters to provide strongly-typed
* methods for acting against the object store.
* 2) Deals with IndexedDB's onsuccess / onerror event callbacks, making every
* method return a PersistencePromise instead.
* 3) Provides a higher-level API to avoid needing to do excessive wrapping of
* intermediate IndexedDB types (IDBCursorWithValue, etc.)
*/var SimpleDbStore=/** @class */function(){function SimpleDbStore(store){this.store=store;}SimpleDbStore.prototype.put=function(keyOrValue,value){var request;if(value!==undefined){debug(LOG_TAG$2,'PUT',this.store.name,keyOrValue,value);request=this.store.put(value,keyOrValue);}else{debug(LOG_TAG$2,'PUT',this.store.name,'<auto-key>',keyOrValue);request=this.store.put(keyOrValue);}return wrapRequest(request);};/**
* Gets the object with the specified key from the specified store, or null
* if no object exists with the specified key.
*
* @key The key of the object to get.
* @return The object with the specified key or null if no object exists.
*/SimpleDbStore.prototype.get=function(key){var _this=this;var request=this.store.get(key);// tslint:disable-next-line:no-any We're doing an unsafe cast to ValueType.
return wrapRequest(request).next(function(result){// Normalize nonexistence to null.
if(result===undefined){result=null;}debug(LOG_TAG$2,'GET',_this.store.name,key,result);return result;});};SimpleDbStore.prototype.delete=function(key){debug(LOG_TAG$2,'DELETE',this.store.name,key);var request=this.store.delete(key);return wrapRequest(request);};/**
* If we ever need more of the count variants, we can add overloads. For now,
* all we need is to count everything in a store.
*
* Returns the number of rows in the store.
*/SimpleDbStore.prototype.count=function(){debug(LOG_TAG$2,'COUNT',this.store.name);var request=this.store.count();return wrapRequest(request);};SimpleDbStore.prototype.loadAll=function(indexOrRange,range){var cursor=this.cursor(this.options(indexOrRange,range));var results=[];return this.iterateCursor(cursor,function(key,value){results.push(value);}).next(function(){return results;});};SimpleDbStore.prototype.deleteAll=function(indexOrRange,range){debug(LOG_TAG$2,'DELETE ALL',this.store.name);var options=this.options(indexOrRange,range);options.keysOnly=false;var cursor=this.cursor(options);return this.iterateCursor(cursor,function(key,value,control){// NOTE: Calling delete() on a cursor is documented as more efficient than
// calling delete() on an object store with a single key
// (https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/delete),
// however, this requires us *not* to use a keysOnly cursor
// (https://developer.mozilla.org/en-US/docs/Web/API/IDBCursor/delete). We
// may want to compare the performance of each method.
return control.delete();});};SimpleDbStore.prototype.iterate=function(optionsOrCallback,callback){var options;if(!callback){options={};callback=optionsOrCallback;}else{options=optionsOrCallback;}var cursor=this.cursor(options);return this.iterateCursor(cursor,callback);};SimpleDbStore.prototype.iterateCursor=function(cursorRequest,fn){var results=[];return new PersistencePromise(function(resolve,reject){cursorRequest.onerror=function(event){reject(event.target.error);};cursorRequest.onsuccess=function(event){var cursor=event.target.result;if(!cursor){resolve();return;}var controller=new IterationController(cursor);var userResult=fn(cursor.primaryKey,cursor.value,controller);if(userResult instanceof PersistencePromise){results.push(userResult);}if(controller.isDone){resolve();}else if(controller.skipToKey===null){cursor.continue();}else{cursor.continue(controller.skipToKey);}};}).next(function(){return PersistencePromise.waitFor(results);});};SimpleDbStore.prototype.options=function(indexOrRange,range){var indexName=undefined;if(indexOrRange!==undefined){if(typeof indexOrRange==='string'){indexName=indexOrRange;}else{assert(range===undefined,'3rd argument must not be defined if 2nd is a range.');range=indexOrRange;}}return{index:indexName,range:range};};SimpleDbStore.prototype.cursor=function(options){var direction='next';if(options.reverse){direction='prev';}if(options.index){var index=this.store.index(options.index);if(options.keysOnly){return index.openKeyCursor(options.range,direction);}else{return index.openCursor(options.range,direction);}}else{return this.store.openCursor(options.range,direction);}};return SimpleDbStore;}();/**
* Wraps an IDBRequest in a PersistencePromise, using the onsuccess / onerror
* handlers to resolve / reject the PersistencePromise as appropriate.
*/function wrapRequest(request){return new PersistencePromise(function(resolve,reject){request.onsuccess=function(event){var result=event.target.result;resolve(result);};request.onerror=function(event){reject(event.target.error);};});}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//** A mutation queue for a specific user, backed by IndexedDB. */var IndexedDbMutationQueue=/** @class */function(){function IndexedDbMutationQueue(/**
* The normalized userId (e.g. null UID => "" userId) used to store /
* retrieve mutations.
*/userId,serializer){this.userId=userId;this.serializer=serializer;this.garbageCollector=null;}/**
* Creates a new mutation queue for the given user.
* @param user The user for which to create a mutation queue.
* @param serializer The serializer to use when persisting to IndexedDb.
*/IndexedDbMutationQueue.forUser=function(user,serializer){// TODO(mcg): Figure out what constraints there are on userIDs
// In particular, are there any reserved characters? are empty ids allowed?
// For the moment store these together in the same mutations table assuming
// that empty userIDs aren't allowed.
assert(user.uid!=='','UserID must not be an empty string.');var userId=user.isAuthenticated()?user.uid:'';return new IndexedDbMutationQueue(userId,serializer);};IndexedDbMutationQueue.prototype.start=function(transaction){var _this=this;return IndexedDbMutationQueue.loadNextBatchIdFromDb(transaction).next(function(nextBatchId){_this.nextBatchId=nextBatchId;return mutationQueuesStore(transaction).get(_this.userId);}).next(function(metadata){if(!metadata){metadata=new DbMutationQueue(_this.userId,BATCHID_UNKNOWN,/*lastStreamToken=*/'');}_this.metadata=metadata;// On restart, nextBatchId may end up lower than
// lastAcknowledgedBatchId since it's computed from the queue
// contents, and there may be no mutations in the queue. In this
// case, we need to reset lastAcknowledgedBatchId (which is safe
// since the queue must be empty).
if(_this.metadata.lastAcknowledgedBatchId>=_this.nextBatchId){return _this.checkEmpty(transaction).next(function(empty){assert(empty,'Reset nextBatchID is only possible when the queue is empty');_this.metadata.lastAcknowledgedBatchId=BATCHID_UNKNOWN;return mutationQueuesStore(transaction).put(_this.metadata);});}else{return PersistencePromise.resolve();}});};/**
* Returns one larger than the largest batch ID that has been stored. If there
* are no mutations returns 0. Note that batch IDs are global.
*/IndexedDbMutationQueue.loadNextBatchIdFromDb=function(txn){var maxBatchId=BATCHID_UNKNOWN;return mutationsStore(txn).iterate({reverse:true},function(key,batch,control){var userId=key[0],batchId=key[1];if(batchId>maxBatchId){maxBatchId=batch.batchId;}if(userId===''){// We can't compute a predecessor for the empty string, since it
// is lexographically first. That also means that no other
// userIds can come before this one, so we can just exit early.
control.done();}else{var nextUser=immediatePredecessor(userId);control.skip([nextUser]);}}).next(function(){return maxBatchId+1;});};IndexedDbMutationQueue.prototype.checkEmpty=function(transaction){var empty=true;var range=IDBKeyRange.bound(this.keyForBatchId(Number.NEGATIVE_INFINITY),this.keyForBatchId(Number.POSITIVE_INFINITY));return mutationsStore(transaction).iterate({range:range},function(key,value,control){empty=false;control.done();}).next(function(){return empty;});};IndexedDbMutationQueue.prototype.getNextBatchId=function(transaction){return PersistencePromise.resolve(this.nextBatchId);};IndexedDbMutationQueue.prototype.getHighestAcknowledgedBatchId=function(transaction){return PersistencePromise.resolve(this.metadata.lastAcknowledgedBatchId);};IndexedDbMutationQueue.prototype.acknowledgeBatch=function(transaction,batch,streamToken){var batchId=batch.batchId;assert(batchId>this.metadata.lastAcknowledgedBatchId,'Mutation batchIDs must be acknowledged in order');this.metadata.lastAcknowledgedBatchId=batchId;this.metadata.lastStreamToken=convertStreamToken(streamToken);return mutationQueuesStore(transaction).put(this.metadata);};IndexedDbMutationQueue.prototype.getLastStreamToken=function(transaction){return PersistencePromise.resolve(this.metadata.lastStreamToken);};IndexedDbMutationQueue.prototype.setLastStreamToken=function(transaction,streamToken){this.metadata.lastStreamToken=convertStreamToken(streamToken);return mutationQueuesStore(transaction).put(this.metadata);};IndexedDbMutationQueue.prototype.addMutationBatch=function(transaction,localWriteTime,mutations){var _this=this;var batchId=this.nextBatchId;this.nextBatchId++;var batch=new MutationBatch(batchId,localWriteTime,mutations);var dbBatch=this.serializer.toDbMutationBatch(this.userId,batch);return mutationsStore(transaction).put(dbBatch).next(function(){var promises=[];for(var _i=0,mutations_1=mutations;_i<mutations_1.length;_i++){var mutation=mutations_1[_i];var indexKey=DbDocumentMutation.key(_this.userId,mutation.key.path,batchId);promises.push(documentMutationsStore(transaction).put(indexKey,DbDocumentMutation.PLACEHOLDER));}return PersistencePromise.waitFor(promises);}).next(function(){return batch;});};IndexedDbMutationQueue.prototype.lookupMutationBatch=function(transaction,batchId){var _this=this;return mutationsStore(transaction).get(this.keyForBatchId(batchId)).next(function(dbBatch){return dbBatch?_this.serializer.fromDbMutationBatch(dbBatch):null;});};IndexedDbMutationQueue.prototype.getNextMutationBatchAfterBatchId=function(transaction,batchId){var _this=this;// All batches with batchId <= this.metadata.lastAcknowledgedBatchId have
// been acknowledged so the first unacknowledged batch after batchID will
// have a batchID larger than both of these values.
var nextBatchId=Math.max(batchId,this.metadata.lastAcknowledgedBatchId)+1;var range=IDBKeyRange.lowerBound(this.keyForBatchId(nextBatchId));var foundBatch=null;return mutationsStore(transaction).iterate({range:range},function(key,dbBatch,control){if(dbBatch.userId===_this.userId){assert(dbBatch.batchId>=nextBatchId,'Should have found mutation after '+nextBatchId);foundBatch=_this.serializer.fromDbMutationBatch(dbBatch);}control.done();}).next(function(){return foundBatch;});};IndexedDbMutationQueue.prototype.getAllMutationBatches=function(transaction){var _this=this;var range=IDBKeyRange.bound(this.keyForBatchId(BATCHID_UNKNOWN),this.keyForBatchId(Number.POSITIVE_INFINITY));return mutationsStore(transaction).loadAll(range).next(function(dbBatches){return dbBatches.map(function(dbBatch){return _this.serializer.fromDbMutationBatch(dbBatch);});});};IndexedDbMutationQueue.prototype.getAllMutationBatchesThroughBatchId=function(transaction,batchId){var _this=this;var range=IDBKeyRange.bound(this.keyForBatchId(BATCHID_UNKNOWN),this.keyForBatchId(batchId));return mutationsStore(transaction).loadAll(range).next(function(dbBatches){return dbBatches.map(function(dbBatch){return _this.serializer.fromDbMutationBatch(dbBatch);});});};IndexedDbMutationQueue.prototype.getAllMutationBatchesAffectingDocumentKey=function(transaction,documentKey){var _this=this;// Scan the document-mutation index starting with a prefix starting with
// the given documentKey.
var indexPrefix=DbDocumentMutation.prefixForPath(this.userId,documentKey.path);var indexStart=IDBKeyRange.lowerBound(indexPrefix);var results=[];return documentMutationsStore(transaction).iterate({range:indexStart},function(indexKey,_,control){var userID=indexKey[0],encodedPath=indexKey[1],batchID=indexKey[2];// Only consider rows matching exactly the specific key of
// interest. Note that because we order by path first, and we
// order terminators before path separators, we'll encounter all
// the index rows for documentKey contiguously. In particular, all
// the rows for documentKey will occur before any rows for
// documents nested in a subcollection beneath documentKey so we
// can stop as soon as we hit any such row.
var path=decode$1(encodedPath);if(userID!==_this.userId||!documentKey.path.isEqual(path)){control.done();return;}var mutationKey=_this.keyForBatchId(batchID);// Look up the mutation batch in the store.
// PORTING NOTE: because iteration is callback driven in the web,
// we just look up the key instead of keeping an open iterator
// like iOS.
return mutationsStore(transaction).get(mutationKey).next(function(dbBatch){if(dbBatch===null){fail('Dangling document-mutation reference found: '+indexKey+' which points to '+mutationKey);}results.push(_this.serializer.fromDbMutationBatch(dbBatch));});}).next(function(){return results;});};IndexedDbMutationQueue.prototype.getAllMutationBatchesAffectingQuery=function(transaction,query){var _this=this;assert(!query.isDocumentQuery(),"Document queries shouldn't go down this path");var queryPath=query.path;var immediateChildrenLength=queryPath.length+1;// TODO(mcg): Actually implement a single-collection query
//
// This is actually executing an ancestor query, traversing the whole
// subtree below the collection which can be horrifically inefficient for
// some structures. The right way to solve this is to implement the full
// value index, but that's not in the cards in the near future so this is
// the best we can do for the moment.
//
// Since we don't yet index the actual properties in the mutations, our
// current approach is to just return all mutation batches that affect
// documents in the collection being queried.
var indexPrefix=DbDocumentMutation.prefixForPath(this.userId,queryPath);var indexStart=IDBKeyRange.lowerBound(indexPrefix);// Collect up unique batchIDs encountered during a scan of the index. Use a
// SortedSet to accumulate batch IDs so they can be traversed in order in a
// scan of the main table.
var uniqueBatchIDs=new SortedSet(primitiveComparator);return documentMutationsStore(transaction).iterate({range:indexStart},function(indexKey,_,control){var userID=indexKey[0],encodedPath=indexKey[1],batchID=indexKey[2];var path=decode$1(encodedPath);if(userID!==_this.userId||!queryPath.isPrefixOf(path)){control.done();return;}// Rows with document keys more than one segment longer than the
// query path can't be matches. For example, a query on 'rooms'
// can't match the document /rooms/abc/messages/xyx.
// TODO(mcg): we'll need a different scanner when we implement
// ancestor queries.
if(path.length!==immediateChildrenLength){return;}uniqueBatchIDs=uniqueBatchIDs.add(batchID);}).next(function(){var results=[];var promises=[];// TODO(rockwood): Implement this using iterate.
uniqueBatchIDs.forEach(function(batchID){var mutationKey=_this.keyForBatchId(batchID);promises.push(mutationsStore(transaction).get(mutationKey).next(function(mutation){if(mutation===null){fail('Dangling document-mutation reference found, '+'which points to '+mutationKey);}results.push(_this.serializer.fromDbMutationBatch(mutation));}));});return PersistencePromise.waitFor(promises).next(function(){return results;});});};IndexedDbMutationQueue.prototype.removeMutationBatches=function(transaction,batches){var txn=mutationsStore(transaction);var indexTxn=documentMutationsStore(transaction);var promises=[];var _loop_1=function(batch){var range=IDBKeyRange.only(this_1.keyForBatchId(batch.batchId));var numDeleted=0;var removePromise=txn.iterate({range:range},function(key,value,control){numDeleted++;return control.delete();});promises.push(removePromise.next(function(){assert(numDeleted===1,'Dangling document-mutation reference found: Missing batch '+batch.batchId);}));for(var _i=0,_a=batch.mutations;_i<_a.length;_i++){var mutation=_a[_i];var indexKey=DbDocumentMutation.key(this_1.userId,mutation.key.path,batch.batchId);promises.push(indexTxn.delete(indexKey));if(this_1.garbageCollector!==null){this_1.garbageCollector.addPotentialGarbageKey(mutation.key);}}};var this_1=this;for(var _i=0,batches_1=batches;_i<batches_1.length;_i++){var batch=batches_1[_i];_loop_1(batch);}return PersistencePromise.waitFor(promises);};IndexedDbMutationQueue.prototype.performConsistencyCheck=function(txn){var _this=this;return this.checkEmpty(txn).next(function(empty){if(!empty){return PersistencePromise.resolve();}// Verify that there are no entries in the documentMutations index if
// the queue is empty.
var startRange=IDBKeyRange.lowerBound(DbDocumentMutation.prefixForUser(_this.userId));var danglingMutationReferences=[];return documentMutationsStore(txn).iterate({range:startRange},function(key,_,control){var userID=key[0];if(userID!==_this.userId){control.done();return;}else{var path=decode$1(key[1]);danglingMutationReferences.push(path);}}).next(function(){assert(danglingMutationReferences.length===0,'Document leak -- detected dangling mutation references when queue is empty. Dangling keys: '+danglingMutationReferences.map(function(p){return p.canonicalString();}));});});};IndexedDbMutationQueue.prototype.setGarbageCollector=function(gc){this.garbageCollector=gc;};IndexedDbMutationQueue.prototype.containsKey=function(txn,key){var _this=this;var indexKey=DbDocumentMutation.prefixForPath(this.userId,key.path);var encodedPath=indexKey[1];var startRange=IDBKeyRange.lowerBound(indexKey);var containsKey=false;return documentMutationsStore(txn).iterate({range:startRange,keysOnly:true},function(key,value,control){var userID=key[0],keyPath=key[1],/*batchID*/_=key[2];if(userID===_this.userId&&keyPath===encodedPath){containsKey=true;}control.done();}).next(function(){return containsKey;});};/**
* Creates a [userId, batchId] key for use with the DbMutationQueue object
* store.
*/IndexedDbMutationQueue.prototype.keyForBatchId=function(batchId){return[this.userId,batchId];};return IndexedDbMutationQueue;}();function convertStreamToken(token){if(token instanceof Uint8Array){// TODO(b/78771403): Convert tokens to strings during deserialization
assert(process.env.USE_MOCK_PERSISTENCE==='YES','Persisting non-string stream tokens is only supported with mock persistence .');return token.toString();}else{return token;}}/**
* Helper to get a typed SimpleDbStore for the mutations object store.
*/function mutationsStore(txn){return getStore(txn,DbMutationBatch.store);}/**
* Helper to get a typed SimpleDbStore for the mutationQueues object store.
*/function documentMutationsStore(txn){return getStore(txn,DbDocumentMutation.store);}/**
* Helper to get a typed SimpleDbStore for the mutationQueues object store.
*/function mutationQueuesStore(txn){return getStore(txn,DbMutationQueue.store);}/**
* Helper to get a typed SimpleDbStore from a transaction.
*/function getStore(txn,store){if(txn instanceof SimpleDbTransaction){return txn.store(store);}else{return fail('Invalid transaction object provided!');}}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var IndexedDbQueryCache=/** @class */function(){function IndexedDbQueryCache(serializer){this.serializer=serializer;/**
* The last received snapshot version. We store this seperately from the
* metadata to avoid the extra conversion to/from DbTimestamp.
*/this.lastRemoteSnapshotVersion=SnapshotVersion.MIN;/**
* A cached copy of the metadata for the query cache.
*/this.metadata=null;/** The garbage collector to notify about potential garbage keys. */this.garbageCollector=null;}IndexedDbQueryCache.prototype.start=function(transaction){var _this=this;return globalTargetStore(transaction).get(DbTargetGlobal.key).next(function(metadata){assert(metadata!==null,'Missing metadata row that should be added by schema migration.');_this.metadata=metadata;var lastSavedVersion=metadata.lastRemoteSnapshotVersion;_this.lastRemoteSnapshotVersion=SnapshotVersion.fromTimestamp(new Timestamp(lastSavedVersion.seconds,lastSavedVersion.nanoseconds));return PersistencePromise.resolve();});};IndexedDbQueryCache.prototype.getHighestTargetId=function(){return this.metadata.highestTargetId;};IndexedDbQueryCache.prototype.getLastRemoteSnapshotVersion=function(){return this.lastRemoteSnapshotVersion;};IndexedDbQueryCache.prototype.setLastRemoteSnapshotVersion=function(transaction,snapshotVersion){this.lastRemoteSnapshotVersion=snapshotVersion;this.metadata.lastRemoteSnapshotVersion=snapshotVersion.toTimestamp();return globalTargetStore(transaction).put(DbTargetGlobal.key,this.metadata);};IndexedDbQueryCache.prototype.addQueryData=function(transaction,queryData){var _this=this;return this.saveQueryData(transaction,queryData).next(function(){_this.metadata.targetCount+=1;_this.updateMetadataFromQueryData(queryData);return _this.saveMetadata(transaction);});};IndexedDbQueryCache.prototype.updateQueryData=function(transaction,queryData){var _this=this;return this.saveQueryData(transaction,queryData).next(function(){if(_this.updateMetadataFromQueryData(queryData)){return _this.saveMetadata(transaction);}else{return PersistencePromise.resolve();}});};IndexedDbQueryCache.prototype.removeQueryData=function(transaction,queryData){var _this=this;assert(this.metadata.targetCount>0,'Removing from an empty query cache');return this.removeMatchingKeysForTargetId(transaction,queryData.targetId).next(function(){return targetsStore(transaction).delete(queryData.targetId);}).next(function(){_this.metadata.targetCount-=1;return _this.saveMetadata(transaction);});};IndexedDbQueryCache.prototype.saveMetadata=function(transaction){return globalTargetStore(transaction).put(DbTargetGlobal.key,this.metadata);};IndexedDbQueryCache.prototype.saveQueryData=function(transaction,queryData){return targetsStore(transaction).put(this.serializer.toDbTarget(queryData));};/**
* Updates the in-memory version of the metadata to account for values in the
* given QueryData. Saving is done separately. Returns true if there were any
* changes to the metadata.
*/IndexedDbQueryCache.prototype.updateMetadataFromQueryData=function(queryData){var needsUpdate=false;if(queryData.targetId>this.metadata.highestTargetId){this.metadata.highestTargetId=queryData.targetId;needsUpdate=true;}// TODO(GC): add sequence number check
return needsUpdate;};Object.defineProperty(IndexedDbQueryCache.prototype,"count",{get:function(){return this.metadata.targetCount;},enumerable:true,configurable:true});IndexedDbQueryCache.prototype.getQueryData=function(transaction,query){var _this=this;// Iterating by the canonicalId may yield more than one result because
// canonicalId values are not required to be unique per target. This query
// depends on the queryTargets index to be efficent.
var canonicalId=query.canonicalId();var range=IDBKeyRange.bound([canonicalId,Number.NEGATIVE_INFINITY],[canonicalId,Number.POSITIVE_INFINITY]);var result=null;return targetsStore(transaction).iterate({range:range,index:DbTarget.queryTargetsIndexName},function(key,value,control){var found=_this.serializer.fromDbTarget(value);// After finding a potential match, check that the query is
// actually equal to the requested query.
if(query.isEqual(found.query)){result=found;control.done();}}).next(function(){return result;});};IndexedDbQueryCache.prototype.addMatchingKeys=function(txn,keys,targetId){// PORTING NOTE: The reverse index (documentsTargets) is maintained by
// Indexeddb.
var promises=[];var store=documentTargetStore(txn);keys.forEach(function(key){var path=encode(key.path);promises.push(store.put(new DbTargetDocument(targetId,path)));});return PersistencePromise.waitFor(promises);};IndexedDbQueryCache.prototype.removeMatchingKeys=function(txn,keys,targetId){var _this=this;// PORTING NOTE: The reverse index (documentsTargets) is maintained by
// IndexedDb.
var promises=[];var store=documentTargetStore(txn);keys.forEach(function(key){var path=encode(key.path);promises.push(store.delete([targetId,path]));if(_this.garbageCollector!==null){_this.garbageCollector.addPotentialGarbageKey(key);}});return PersistencePromise.waitFor(promises);};IndexedDbQueryCache.prototype.removeMatchingKeysForTargetId=function(txn,targetId){var store=documentTargetStore(txn);var range=IDBKeyRange.bound([targetId],[targetId+1],/*lowerOpen=*/false,/*upperOpen=*/true);return this.notifyGCForRemovedKeys(txn,range).next(function(){return store.delete(range);});};IndexedDbQueryCache.prototype.notifyGCForRemovedKeys=function(txn,range){var _this=this;var store=documentTargetStore(txn);if(this.garbageCollector!==null&&this.garbageCollector.isEager){// In order to generate garbage events properly, we need to read these
// keys before deleting.
return store.iterate({range:range,keysOnly:true},function(key,_,control){var path=decode$1(key[1]);var docKey=new DocumentKey(path);// Paranoid assertion in case the the collector is set to null
// during the iteration.
assert(_this.garbageCollector!==null,'GarbageCollector for query cache set to null during key removal.');_this.garbageCollector.addPotentialGarbageKey(docKey);});}else{return PersistencePromise.resolve();}};IndexedDbQueryCache.prototype.getMatchingKeysForTargetId=function(txn,targetId){var range=IDBKeyRange.bound([targetId],[targetId+1],/*lowerOpen=*/false,/*upperOpen=*/true);var store=documentTargetStore(txn);var result=documentKeySet();return store.iterate({range:range,keysOnly:true},function(key,_,control){var path=decode$1(key[1]);var docKey=new DocumentKey(path);result=result.add(docKey);}).next(function(){return result;});};IndexedDbQueryCache.prototype.setGarbageCollector=function(gc){this.garbageCollector=gc;};IndexedDbQueryCache.prototype.containsKey=function(txn,key){assert(txn!==null,'Persistence Transaction cannot be null for query cache containsKey');var path=encode(key.path);var range=IDBKeyRange.bound([path],[immediateSuccessor(path)],/*lowerOpen=*/false,/*upperOpen=*/true);var count=0;return documentTargetStore(txn).iterate({index:DbTargetDocument.documentTargetsIndex,keysOnly:true,range:range},function(key,_,control){count++;control.done();}).next(function(){return count>0;});};return IndexedDbQueryCache;}();/**
* Helper to get a typed SimpleDbStore for the queries object store.
*/function targetsStore(txn){return getStore$1(txn,DbTarget.store);}/**
* Helper to get a typed SimpleDbStore for the target globals object store.
*/function globalTargetStore(txn){return getStore$1(txn,DbTargetGlobal.store);}/**
* Helper to get a typed SimpleDbStore for the document target object store.
*/function documentTargetStore(txn){return getStore$1(txn,DbTargetDocument.store);}/**
* Helper to get a typed SimpleDbStore from a transaction.
*/function getStore$1(txn,store){if(txn instanceof SimpleDbTransaction){return txn.store(store);}else{return fail('Invalid transaction object provided!');}}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var IndexedDbRemoteDocumentCache=/** @class */function(){function IndexedDbRemoteDocumentCache(serializer){this.serializer=serializer;}IndexedDbRemoteDocumentCache.prototype.addEntry=function(transaction,maybeDocument){return remoteDocumentsStore(transaction).put(dbKey(maybeDocument.key),this.serializer.toDbRemoteDocument(maybeDocument));};IndexedDbRemoteDocumentCache.prototype.removeEntry=function(transaction,documentKey){return remoteDocumentsStore(transaction).delete(dbKey(documentKey));};IndexedDbRemoteDocumentCache.prototype.getEntry=function(transaction,documentKey){var _this=this;return remoteDocumentsStore(transaction).get(dbKey(documentKey)).next(function(dbRemoteDoc){return dbRemoteDoc?_this.serializer.fromDbRemoteDocument(dbRemoteDoc):null;});};IndexedDbRemoteDocumentCache.prototype.getDocumentsMatchingQuery=function(transaction,query){var _this=this;var results=documentMap();// Documents are ordered by key, so we can use a prefix scan to narrow down
// the documents we need to match the query against.
var startKey=query.path.toArray();var range=IDBKeyRange.lowerBound(startKey);return remoteDocumentsStore(transaction).iterate({range:range},function(key,dbRemoteDoc,control){var maybeDoc=_this.serializer.fromDbRemoteDocument(dbRemoteDoc);if(!query.path.isPrefixOf(maybeDoc.key.path)){control.done();}else if(maybeDoc instanceof Document&&query.matches(maybeDoc)){results=results.insert(maybeDoc.key,maybeDoc);}}).next(function(){return results;});};return IndexedDbRemoteDocumentCache;}();/**
* Helper to get a typed SimpleDbStore for the remoteDocuments object store.
*/function remoteDocumentsStore(txn){if(txn instanceof SimpleDbTransaction){return txn.store(DbRemoteDocument.store);}else{return fail('Invalid transaction object provided!');}}function dbKey(docKey){return docKey.path.toArray();}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//** Serializer for values stored in the LocalStore. */var LocalSerializer=/** @class */function(){function LocalSerializer(remoteSerializer){this.remoteSerializer=remoteSerializer;}/** Decodes a remote document from storage locally to a Document. */LocalSerializer.prototype.fromDbRemoteDocument=function(remoteDoc){if(remoteDoc.document){return this.remoteSerializer.fromDocument(remoteDoc.document);}else if(remoteDoc.noDocument){var key=DocumentKey.fromSegments(remoteDoc.noDocument.path);var readTime=remoteDoc.noDocument.readTime;var timestamp=new Timestamp(readTime.seconds,readTime.nanoseconds);return new NoDocument(key,SnapshotVersion.fromTimestamp(timestamp));}else{return fail('Unexpected DbRemoteDocument');}};/** Encodes a document for storage locally. */LocalSerializer.prototype.toDbRemoteDocument=function(maybeDoc){if(maybeDoc instanceof Document){var doc=this.remoteSerializer.toDocument(maybeDoc);return new DbRemoteDocument(null,doc);}else{var path=maybeDoc.key.path.toArray();var timestamp=maybeDoc.version.toTimestamp();var readTime=new DbTimestamp(timestamp.seconds,timestamp.nanoseconds);return new DbRemoteDocument(new DbNoDocument(path,readTime),null);}};/** Encodes a batch of mutations into a DbMutationBatch for local storage. */LocalSerializer.prototype.toDbMutationBatch=function(userId,batch){var _this=this;var serializedMutations=batch.mutations.map(function(m){return _this.remoteSerializer.toMutation(m);});return new DbMutationBatch(userId,batch.batchId,batch.localWriteTime.toMillis(),serializedMutations);};/** Decodes a DbMutationBatch into a MutationBatch */LocalSerializer.prototype.fromDbMutationBatch=function(dbBatch){var _this=this;var mutations=dbBatch.mutations.map(function(m){return _this.remoteSerializer.fromMutation(m);});var timestamp=Timestamp.fromMillis(dbBatch.localWriteTimeMs);return new MutationBatch(dbBatch.batchId,timestamp,mutations);};/** Decodes a DbTarget into QueryData */LocalSerializer.prototype.fromDbTarget=function(dbTarget){var readTime=new Timestamp(dbTarget.readTime.seconds,dbTarget.readTime.nanoseconds);var version=SnapshotVersion.fromTimestamp(readTime);var query;if(isDocumentQuery(dbTarget.query)){query=this.remoteSerializer.fromDocumentsTarget(dbTarget.query);}else{query=this.remoteSerializer.fromQueryTarget(dbTarget.query);}return new QueryData(query,dbTarget.targetId,QueryPurpose.Listen,version,dbTarget.resumeToken);};/** Encodes QueryData into a DbTarget for storage locally. */LocalSerializer.prototype.toDbTarget=function(queryData){assert(QueryPurpose.Listen===queryData.purpose,'Only queries with purpose '+QueryPurpose.Listen+' may be stored, got '+queryData.purpose);var timestamp=queryData.snapshotVersion.toTimestamp();var dbTimestamp=new DbTimestamp(timestamp.seconds,timestamp.nanoseconds);var queryProto;if(queryData.query.isDocumentQuery()){queryProto=this.remoteSerializer.toDocumentsTarget(queryData.query);}else{queryProto=this.remoteSerializer.toQueryTarget(queryData.query);}var resumeToken;if(queryData.resumeToken instanceof Uint8Array){// TODO(b/78771403): Convert tokens to strings during deserialization
assert(process.env.USE_MOCK_PERSISTENCE==='YES','Persisting non-string stream tokens is only supported with mock persistence .');resumeToken=queryData.resumeToken.toString();}else{resumeToken=queryData.resumeToken;}// lastListenSequenceNumber is always 0 until we do real GC.
return new DbTarget(queryData.targetId,queryData.query.canonicalId(),dbTimestamp,resumeToken,0,queryProto);};return LocalSerializer;}();/**
* A helper function for figuring out what kind of query has been stored.
*/function isDocumentQuery(dbQuery){return dbQuery.documents!==undefined;}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$3='IndexedDbPersistence';/** If the owner lease is older than 5 seconds, try to take ownership. */var OWNER_LEASE_MAX_AGE_MS=5000;/** Refresh the owner lease every 4 seconds while owner. */var OWNER_LEASE_REFRESH_INTERVAL_MS=4000;/** LocalStorage location to indicate a zombied ownerId (see class comment). */var ZOMBIE_OWNER_LOCALSTORAGE_SUFFIX='zombiedOwnerId';/** Error when the owner lease cannot be acquired or is lost. */var EXISTING_OWNER_ERROR_MSG='There is another tab open with offline'+' persistence enabled. Only one such tab is allowed at a time. The'+' other tab must be closed or persistence must be disabled.';var UNSUPPORTED_PLATFORM_ERROR_MSG='This platform is either missing'+' IndexedDB or is known to have an incomplete implementation. Offline'+' persistence has been disabled.';/**
* An IndexedDB-backed instance of Persistence. Data is stored persistently
* across sessions.
*
* Currently the Firestore SDK only supports a single consumer of the database,
* but browsers obviously support multiple tabs. IndexedDbPersistence ensures a
* single consumer of the database via an "owner lease" stored in the database.
*
* On startup, IndexedDbPersistence assigns itself a random "ownerId" and writes
* it to a special "owner" object in the database (if no entry exists already or
* the current entry is expired). This owner lease is then verified inside every
* transaction to ensure the lease has not been lost.
*
* If a tab opts not to acquire the owner lease (because there's an existing
* non-expired owner) or loses the owner lease, IndexedDbPersistence enters a
* failed state and all subsequent operations will automatically fail.
*
* The current owner regularly refreshes the owner lease with new timestamps to
* prevent newly-opened tabs from taking over ownership.
*
* Additionally there is an optimization so that when a tab is closed, the owner
* lease is released immediately (this is especially important to make sure that
* a refreshed tab is able to immediately re-acquire the owner lease).
* Unfortunately, IndexedDB cannot be reliably used in window.unload since it is
* an asynchronous API. So in addition to attempting to give up the lease,
* the owner writes its ownerId to a "zombiedOwnerId" entry in LocalStorage
* which acts as an indicator that another tab should go ahead and take the
* owner lease immediately regardless of the current lease timestamp.
*/var IndexedDbPersistence=/** @class */function(){function IndexedDbPersistence(prefix,serializer){this.ownerId=this.generateOwnerId();this.dbName=prefix+IndexedDbPersistence.MAIN_DATABASE;this.serializer=new LocalSerializer(serializer);this.localStoragePrefix=prefix;}IndexedDbPersistence.prototype.start=function(){var _this=this;if(!IndexedDbPersistence.isAvailable()){this.persistenceError=new FirestoreError(Code.UNIMPLEMENTED,UNSUPPORTED_PLATFORM_ERROR_MSG);return Promise.reject(this.persistenceError);}assert(!this.started,'IndexedDbPersistence double-started!');this.started=true;return SimpleDb.openOrCreate(this.dbName,SCHEMA_VERSION,createOrUpgradeDb).then(function(db){_this.simpleDb=db;}).then(function(){return _this.tryAcquireOwnerLease();}).then(function(){_this.scheduleOwnerLeaseRefreshes();_this.attachWindowUnloadHook();});};IndexedDbPersistence.prototype.shutdown=function(deleteData){var _this=this;assert(this.started,'IndexedDbPersistence shutdown without start!');this.started=false;this.detachWindowUnloadHook();this.stopOwnerLeaseRefreshes();return this.releaseOwnerLease().then(function(){_this.simpleDb.close();if(deleteData){return SimpleDb.delete(_this.dbName);}});};IndexedDbPersistence.prototype.getMutationQueue=function(user){return IndexedDbMutationQueue.forUser(user,this.serializer);};IndexedDbPersistence.prototype.getQueryCache=function(){return new IndexedDbQueryCache(this.serializer);};IndexedDbPersistence.prototype.getRemoteDocumentCache=function(){return new IndexedDbRemoteDocumentCache(this.serializer);};IndexedDbPersistence.prototype.runTransaction=function(action,operation){var _this=this;if(this.persistenceError){return Promise.reject(this.persistenceError);}debug(LOG_TAG$3,'Starting transaction:',action);// Do all transactions as readwrite against all object stores, since we
// are the only reader/writer.
return this.simpleDb.runTransaction('readwrite',ALL_STORES,function(txn){// Verify that we still have the owner lease as part of every transaction.
return _this.ensureOwnerLease(txn).next(function(){return operation(txn);});});};IndexedDbPersistence.isAvailable=function(){return SimpleDb.isAvailable();};/**
* Generates a string used as a prefix when storing data in IndexedDB and
* LocalStorage.
*/IndexedDbPersistence.buildStoragePrefix=function(databaseInfo){// Use two different prefix formats:
//
// * firestore / persistenceKey / projectID . databaseID / ...
// * firestore / persistenceKey / projectID / ...
//
// projectIDs are DNS-compatible names and cannot contain dots
// so there's no danger of collisions.
var database=databaseInfo.databaseId.projectId;if(!databaseInfo.databaseId.isDefaultDatabase){database+='.'+databaseInfo.databaseId.database;}return'firestore/'+databaseInfo.persistenceKey+'/'+database+'/';};/**
* Acquires the owner lease if there's no valid owner. Else returns a rejected
* promise.
*/IndexedDbPersistence.prototype.tryAcquireOwnerLease=function(){var _this=this;// NOTE: Don't use this.runTransaction, since it requires us to already
// have the lease.
return this.simpleDb.runTransaction('readwrite',[DbOwner.store],function(txn){var store=txn.store(DbOwner.store);return store.get('owner').next(function(dbOwner){if(!_this.validOwner(dbOwner)){var newDbOwner=new DbOwner(_this.ownerId,Date.now());debug(LOG_TAG$3,'No valid owner. Acquiring owner lease. Current owner:',dbOwner,'New owner:',newDbOwner);return store.put('owner',newDbOwner);}else{debug(LOG_TAG$3,'Valid owner already. Failing. Current owner:',dbOwner);_this.persistenceError=new FirestoreError(Code.FAILED_PRECONDITION,EXISTING_OWNER_ERROR_MSG);return PersistencePromise.reject(_this.persistenceError);}});});};/** Checks the owner lease and deletes it if we are the current owner. */IndexedDbPersistence.prototype.releaseOwnerLease=function(){var _this=this;// NOTE: Don't use this.runTransaction, since it requires us to already
// have the lease.
return this.simpleDb.runTransaction('readwrite',[DbOwner.store],function(txn){var store=txn.store(DbOwner.store);return store.get('owner').next(function(dbOwner){if(dbOwner!==null&&dbOwner.ownerId===_this.ownerId){debug(LOG_TAG$3,'Releasing owner lease.');return store.delete('owner');}else{return PersistencePromise.resolve();}});});};/**
* Checks the owner lease and returns a rejected promise if we are not the
* current owner. This should be included in every transaction to guard
* against losing the owner lease.
*/IndexedDbPersistence.prototype.ensureOwnerLease=function(txn){var _this=this;var store=txn.store(DbOwner.store);return store.get('owner').next(function(dbOwner){if(dbOwner===null||dbOwner.ownerId!==_this.ownerId){_this.persistenceError=new FirestoreError(Code.FAILED_PRECONDITION,EXISTING_OWNER_ERROR_MSG);return PersistencePromise.reject(_this.persistenceError);}else{return PersistencePromise.resolve();}});};/**
* Returns true if the provided owner exists, has a recent timestamp, and
* isn't zombied.
*
* NOTE: To determine if the owner is zombied, this method reads from
* LocalStorage which could be mildly expensive.
*/IndexedDbPersistence.prototype.validOwner=function(dbOwner){var now=Date.now();var minAcceptable=now-OWNER_LEASE_MAX_AGE_MS;var maxAcceptable=now;if(dbOwner===null){return false;// no owner.
}else if(dbOwner.leaseTimestampMs<minAcceptable){return false;// owner lease has expired.
}else if(dbOwner.leaseTimestampMs>maxAcceptable){error('Persistence owner-lease is in the future. Discarding.',dbOwner);return false;}else if(dbOwner.ownerId===this.getZombiedOwnerId()){return false;// owner's tab closed.
}else{return true;}};/**
* Schedules a recurring timer to update the owner lease timestamp to prevent
* other tabs from taking the lease.
*/IndexedDbPersistence.prototype.scheduleOwnerLeaseRefreshes=function(){var _this=this;// NOTE: This doesn't need to be scheduled on the async queue and doing so
// would increase the chances of us not refreshing on time if the queue is
// backed up for some reason.
this.ownerLeaseRefreshHandle=setInterval(function(){var txResult=_this.runTransaction('Refresh owner timestamp',function(txn){// NOTE: We don't need to validate the current owner contents, since
// runTransaction does that automatically.
var store=txn.store(DbOwner.store);return store.put('owner',new DbOwner(_this.ownerId,Date.now()));});txResult.catch(function(reason){// Probably means we lost the lease. Report the error and stop trying to
// refresh the lease.
error(reason);_this.stopOwnerLeaseRefreshes();});},OWNER_LEASE_REFRESH_INTERVAL_MS);};IndexedDbPersistence.prototype.stopOwnerLeaseRefreshes=function(){if(this.ownerLeaseRefreshHandle){clearInterval(this.ownerLeaseRefreshHandle);this.ownerLeaseRefreshHandle=null;}};/**
* Attaches a window.unload handler that will synchronously write our
* ownerId to a "zombie owner id" location in localstorage. This can be used
* by tabs trying to acquire the lease to determine that the lease should be
* acquired immediately even if the timestamp is recent. This is particularly
* important for the refresh case (so the tab correctly re-acquires the owner
* lease). LocalStorage is used for this rather than IndexedDb because it is
* a synchronous API and so can be used reliably from an unload handler.
*/IndexedDbPersistence.prototype.attachWindowUnloadHook=function(){var _this=this;if(typeof window==='object'&&typeof window.addEventListener==='function'){this.windowUnloadHandler=function(){// Record that we're zombied.
_this.setZombiedOwnerId(_this.ownerId);// Attempt graceful shutdown (including releasing our owner lease), but
// there's no guarantee it will complete.
_this.shutdown();};window.addEventListener('unload',this.windowUnloadHandler);}};IndexedDbPersistence.prototype.detachWindowUnloadHook=function(){if(this.windowUnloadHandler){assert(typeof window==='object'&&typeof window.removeEventListener==='function',"Expected 'window.removeEventListener' to be a function");window.removeEventListener('unload',this.windowUnloadHandler);this.windowUnloadHandler=null;}};/**
* Returns any recorded "zombied owner" (i.e. a previous owner that became
* zombied due to their tab closing) from LocalStorage, or null if no such
* record exists.
*/IndexedDbPersistence.prototype.getZombiedOwnerId=function(){try{var zombiedOwnerId=window.localStorage.getItem(this.zombiedOwnerLocalStorageKey());debug(LOG_TAG$3,'Zombied ownerID from LocalStorage:',zombiedOwnerId);return zombiedOwnerId;}catch(e){// Gracefully handle if LocalStorage isn't available / working.
error('Failed to get zombie owner id.',e);return null;}};/**
* Records a zombied owner (an owner that had its tab closed) in LocalStorage
* or, if passed null, deletes any recorded zombied owner.
*/IndexedDbPersistence.prototype.setZombiedOwnerId=function(zombieOwnerId){try{if(zombieOwnerId===null){window.localStorage.removeItem(this.zombiedOwnerLocalStorageKey());}else{window.localStorage.setItem(this.zombiedOwnerLocalStorageKey(),zombieOwnerId);}}catch(e){// Gracefully handle if LocalStorage isn't available / working.
error('Failed to set zombie owner id.',e);}};IndexedDbPersistence.prototype.zombiedOwnerLocalStorageKey=function(){return this.localStoragePrefix+ZOMBIE_OWNER_LOCALSTORAGE_SUFFIX;};IndexedDbPersistence.prototype.generateOwnerId=function(){// For convenience, just use an AutoId.
return AutoId.newId();};/**
* The name of the main (and currently only) IndexedDB database. this name is
* appended to the prefix provided to the IndexedDbPersistence constructor.
*/IndexedDbPersistence.MAIN_DATABASE='main';return IndexedDbPersistence;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* A readonly view of the local state of all documents we're tracking (i.e. we
* have a cached version in remoteDocumentCache or local mutations for the
* document). The view is computed by applying the mutations in the
* MutationQueue to the RemoteDocumentCache.
*/var LocalDocumentsView=/** @class */function(){function LocalDocumentsView(remoteDocumentCache,mutationQueue){this.remoteDocumentCache=remoteDocumentCache;this.mutationQueue=mutationQueue;}/**
* Get the local view of the document identified by `key`.
*
* @return Local view of the document or null if we don't have any cached
* state for it.
*/LocalDocumentsView.prototype.getDocument=function(transaction,key){var _this=this;return this.remoteDocumentCache.getEntry(transaction,key).next(function(remoteDoc){return _this.computeLocalDocument(transaction,key,remoteDoc);});};/**
* Gets the local view of the documents identified by `keys`.
*
* If we don't have cached state for a document in `keys`, a NoDocument will
* be stored for that key in the resulting set.
*/LocalDocumentsView.prototype.getDocuments=function(transaction,keys){var _this=this;var promises=[];var results=maybeDocumentMap();keys.forEach(function(key){promises.push(_this.getDocument(transaction,key).next(function(maybeDoc){// TODO(http://b/32275378): Don't conflate missing / deleted.
if(!maybeDoc){maybeDoc=new NoDocument(key,SnapshotVersion.forDeletedDoc());}results=results.insert(key,maybeDoc);}));});return PersistencePromise.waitFor(promises).next(function(){return results;});};/** Performs a query against the local view of all documents. */LocalDocumentsView.prototype.getDocumentsMatchingQuery=function(transaction,query){if(DocumentKey.isDocumentKey(query.path)){return this.getDocumentsMatchingDocumentQuery(transaction,query.path);}else{return this.getDocumentsMatchingCollectionQuery(transaction,query);}};LocalDocumentsView.prototype.getDocumentsMatchingDocumentQuery=function(transaction,docPath){// Just do a simple document lookup.
return this.getDocument(transaction,new DocumentKey(docPath)).next(function(maybeDoc){var result=documentMap();if(maybeDoc instanceof Document){result=result.insert(maybeDoc.key,maybeDoc);}return result;});};LocalDocumentsView.prototype.getDocumentsMatchingCollectionQuery=function(transaction,query){var _this=this;// Query the remote documents and overlay mutations.
// TODO(mikelehen): There may be significant overlap between the mutations
// affecting these remote documents and the
// getAllMutationBatchesAffectingQuery() mutations. Consider optimizing.
var results;return this.remoteDocumentCache.getDocumentsMatchingQuery(transaction,query).next(function(queryResults){return _this.computeLocalDocuments(transaction,queryResults);}).next(function(promisedResults){results=promisedResults;// Now use the mutation queue to discover any other documents that may
// match the query after applying mutations.
return _this.mutationQueue.getAllMutationBatchesAffectingQuery(transaction,query);}).next(function(matchingMutationBatches){var matchingKeys=documentKeySet();for(var _i=0,matchingMutationBatches_1=matchingMutationBatches;_i<matchingMutationBatches_1.length;_i++){var batch=matchingMutationBatches_1[_i];for(var _a=0,_b=batch.mutations;_a<_b.length;_a++){var mutation=_b[_a];// TODO(mikelehen): PERF: Check if this mutation actually
// affects the query to reduce work.
if(!results.get(mutation.key)){matchingKeys=matchingKeys.add(mutation.key);}}}// Now add in the results for the matchingKeys.
var promises=[];matchingKeys.forEach(function(key){promises.push(_this.getDocument(transaction,key).next(function(doc){if(doc instanceof Document){results=results.insert(doc.key,doc);}}));});return PersistencePromise.waitFor(promises);}).next(function(){// Finally, filter out any documents that don't actually match
// the query.
results.forEach(function(key,doc){if(!query.matches(doc)){results=results.remove(key);}});return results;});};/**
* Takes a remote document and applies local mutations to generate the local
* view of the document.
* @param transaction The transaction in which to perform any persistence
* operations.
* @param documentKey The key of the document (necessary when remoteDocument
* is null).
* @param document The base remote document to apply mutations to or null.
*/LocalDocumentsView.prototype.computeLocalDocument=function(transaction,documentKey,document){return this.mutationQueue.getAllMutationBatchesAffectingDocumentKey(transaction,documentKey).next(function(batches){for(var _i=0,batches_1=batches;_i<batches_1.length;_i++){var batch=batches_1[_i];document=batch.applyToLocalView(documentKey,document);}return document;});};/**
* Takes a set of remote documents and applies local mutations to generate the
* local view of the documents.
* @param transaction The transaction in which to perform any persistence
* operations.
* @param documents The base remote documents to apply mutations to.
* @return The local view of the documents.
*/LocalDocumentsView.prototype.computeLocalDocuments=function(transaction,documents){var _this=this;var promises=[];documents.forEach(function(key,doc){promises.push(_this.computeLocalDocument(transaction,key,doc).next(function(mutatedDoc){if(mutatedDoc instanceof Document){documents=documents.insert(mutatedDoc.key,mutatedDoc);}else if(mutatedDoc instanceof NoDocument){documents=documents.remove(mutatedDoc.key);}else{fail('Unknown MaybeDocument: '+mutatedDoc);}}));});return PersistencePromise.waitFor(promises).next(function(){return documents;});};return LocalDocumentsView;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* An in-memory buffer of entries to be written to a RemoteDocumentCache.
* It can be used to batch up a set of changes to be written to the cache, but
* additionally supports reading entries back with the `getEntry()` method,
* falling back to the underlying RemoteDocumentCache if no entry is
* buffered.
*
* NOTE: This class was introduced in iOS to work around a limitation in
* LevelDB. Given IndexedDb has full transaction support with
* read-your-own-writes capability, this class is not technically needed, but
* has been preserved as a convenience and to aid portability.
*/var RemoteDocumentChangeBuffer=/** @class */function(){function RemoteDocumentChangeBuffer(remoteDocumentCache){this.remoteDocumentCache=remoteDocumentCache;this.changes=maybeDocumentMap();}/** Buffers a `RemoteDocumentCache.addEntry()` call. */RemoteDocumentChangeBuffer.prototype.addEntry=function(maybeDocument){var changes=this.assertChanges();this.changes=changes.insert(maybeDocument.key,maybeDocument);};// NOTE: removeEntry() is not presently necessary and so is omitted.
/**
* Looks up an entry in the cache. The buffered changes will first be checked,
* and if no buffered change applies, this will forward to
* `RemoteDocumentCache.getEntry()`.
*
* @param transaction The transaction in which to perform any persistence
* operations.
* @param documentKey The key of the entry to look up.
* @return The cached Document or NoDocument entry, or null if we have nothing
* cached.
*/RemoteDocumentChangeBuffer.prototype.getEntry=function(transaction,documentKey){var changes=this.assertChanges();var bufferedEntry=changes.get(documentKey);if(bufferedEntry){return PersistencePromise.resolve(bufferedEntry);}else{return this.remoteDocumentCache.getEntry(transaction,documentKey);}};/**
* Applies buffered changes to the underlying RemoteDocumentCache, using
* the provided transaction.
*/RemoteDocumentChangeBuffer.prototype.apply=function(transaction){var _this=this;var changes=this.assertChanges();var promises=[];changes.forEach(function(key,maybeDoc){promises.push(_this.remoteDocumentCache.addEntry(transaction,maybeDoc));});// We should not be used to buffer any more changes.
this.changes=null;return PersistencePromise.waitFor(promises);};/** Helper to assert this.changes is not null and return it. */RemoteDocumentChangeBuffer.prototype.assertChanges=function(){assert(this.changes!==null,'Changes have already been applied.');return this.changes;};return RemoteDocumentChangeBuffer;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$4='LocalStore';/**
* Local storage in the Firestore client. Coordinates persistence components
* like the mutation queue and remote document cache to present a
* latency-compensated view of stored data.
*
* The LocalStore is responsible for accepting mutations from the Sync Engine.
* Writes from the client are put into a queue as provisional Mutations until
* they are processed by the RemoteStore and confirmed as having been written
* to the server.
*
* The local store provides the local version of documents that have been
* modified locally. It maintains the constraint:
*
* LocalDocument = RemoteDocument + Active(LocalMutations)
*
* (Active mutations are those that are enqueued and have not been previously
* acknowledged or rejected).
*
* The RemoteDocument ("ground truth") state is provided via the
* applyChangeBatch method. It will be some version of a server-provided
* document OR will be a server-provided document PLUS acknowledged mutations:
*
* RemoteDocument' = RemoteDocument + Acknowledged(LocalMutations)
*
* Note that this "dirty" version of a RemoteDocument will not be identical to a
* server base version, since it has LocalMutations added to it pending getting
* an authoritative copy from the server.
*
* Since LocalMutations can be rejected by the server, we have to be able to
* revert a LocalMutation that has already been applied to the LocalDocument
* (typically done by replaying all remaining LocalMutations to the
* RemoteDocument to re-apply).
*
* The LocalStore is responsible for the garbage collection of the documents it
* contains. For now, it every doc referenced by a view, the mutation queue, or
* the RemoteStore.
*
* It also maintains the persistence of mapping queries to resume tokens and
* target ids. It needs to know this data about queries to properly know what
* docs it would be allowed to garbage collect.
*
* The LocalStore must be able to efficiently execute queries against its local
* cache of the documents, to provide the initial set of results before any
* remote changes have been received.
*
* Note: In TypeScript, most methods return Promises since the implementation
* may rely on fetching data from IndexedDB which is async.
* These Promises will only be rejected on an I/O error or other internal
* (unexpected) failure (e.g. failed assert) and always represent an
* unrecoverable error (should be caught / reported by the async_queue).
*/var LocalStore=/** @class */function(){function LocalStore(/** Manages our in-memory or durable persistence. */persistence,initialUser,/**
* The garbage collector collects documents that should no longer be
* cached (e.g. if they are no longer retained by the above reference sets
* and the garbage collector is performing eager collection).
*/garbageCollector){this.persistence=persistence;this.garbageCollector=garbageCollector;/**
* The set of document references maintained by any local views.
*/this.localViewReferences=new ReferenceSet();/** Maps a targetID to data about its query. */this.targetIds={};/** Used to generate targetIDs for queries tracked locally. */this.targetIdGenerator=TargetIdGenerator.forLocalStore();/**
* A heldBatchResult is a mutation batch result (from a write acknowledgement)
* that arrived before the watch stream got notified of a snapshot that
* includes the write.So we "hold" it until the watch stream catches up. It
* ensures that the local write remains visible (latency compensation) and
* doesn't temporarily appear reverted because the watch stream is slower than
* the write stream and so wasn't reflecting it.
*
* NOTE: Eventually we want to move this functionality into the remote store.
*/this.heldBatchResults=[];this.mutationQueue=persistence.getMutationQueue(initialUser);this.remoteDocuments=persistence.getRemoteDocumentCache();this.queryCache=persistence.getQueryCache();this.localDocuments=new LocalDocumentsView(this.remoteDocuments,this.mutationQueue);this.garbageCollector.addGarbageSource(this.localViewReferences);this.garbageCollector.addGarbageSource(this.queryCache);this.garbageCollector.addGarbageSource(this.mutationQueue);}/** Performs any initial startup actions required by the local store. */LocalStore.prototype.start=function(){var _this=this;return this.persistence.runTransaction('Start LocalStore',function(txn){return _this.startMutationQueue(txn).next(function(){return _this.startQueryCache(txn);});});};/**
* Tells the LocalStore that the currently authenticated user has changed.
*
* In response the local store switches the mutation queue to the new user and
* returns any resulting document changes.
*/LocalStore.prototype.handleUserChange=function(user){var _this=this;return this.persistence.runTransaction('Handle user change',function(txn){// Swap out the mutation queue, grabbing the pending mutation batches
// before and after.
var oldBatches;return _this.mutationQueue.getAllMutationBatches(txn).next(function(promisedOldBatches){oldBatches=promisedOldBatches;_this.garbageCollector.removeGarbageSource(_this.mutationQueue);_this.mutationQueue=_this.persistence.getMutationQueue(user);_this.garbageCollector.addGarbageSource(_this.mutationQueue);return _this.startMutationQueue(txn);}).next(function(){// Recreate our LocalDocumentsView using the new
// MutationQueue.
_this.localDocuments=new LocalDocumentsView(_this.remoteDocuments,_this.mutationQueue);return _this.mutationQueue.getAllMutationBatches(txn);}).next(function(newBatches){// Union the old/new changed keys.
var changedKeys=documentKeySet();for(var _i=0,_a=[oldBatches,newBatches];_i<_a.length;_i++){var batches=_a[_i];for(var _b=0,batches_1=batches;_b<batches_1.length;_b++){var batch=batches_1[_b];for(var _c=0,_d=batch.mutations;_c<_d.length;_c++){var mutation=_d[_c];changedKeys=changedKeys.add(mutation.key);}}}// Return the set of all (potentially) changed documents as the
// result of the user change.
return _this.localDocuments.getDocuments(txn,changedKeys);});});};LocalStore.prototype.startQueryCache=function(txn){var _this=this;return this.queryCache.start(txn).next(function(){var targetId=_this.queryCache.getHighestTargetId();_this.targetIdGenerator=TargetIdGenerator.forLocalStore(targetId);});};LocalStore.prototype.startMutationQueue=function(txn){var _this=this;return this.mutationQueue.start(txn).next(function(){// If we have any leftover mutation batch results from a prior run,
// just drop them.
// TODO(http://b/33446471): We probably need to repopulate
// heldBatchResults or similar instead, but that is not
// straightforward since we're not persisting the write ack versions.
_this.heldBatchResults=[];return _this.mutationQueue.getHighestAcknowledgedBatchId(txn);}).next(function(highestAck){// TODO(mikelehen): This is the only usage of
// getAllMutationBatchesThroughBatchId(). Consider removing it in
// favor of a getAcknowledgedBatches() method.
if(highestAck!==BATCHID_UNKNOWN){return _this.mutationQueue.getAllMutationBatchesThroughBatchId(txn,highestAck);}else{return PersistencePromise.resolve([]);}}).next(function(ackedBatches){if(ackedBatches.length>0){return _this.mutationQueue.removeMutationBatches(txn,ackedBatches);}else{return PersistencePromise.resolve();}});};/* Accept locally generated Mutations and commit them to storage. */LocalStore.prototype.localWrite=function(mutations){var _this=this;return this.persistence.runTransaction('Locally write mutations',function(txn){var batch;var localWriteTime=Timestamp.now();return _this.mutationQueue.addMutationBatch(txn,localWriteTime,mutations).next(function(promisedBatch){batch=promisedBatch;// TODO(koss): This is doing an N^2 update by replaying ALL the
// mutations on each document (instead of just the ones added) in
// this batch.
var keys=batch.keys();return _this.localDocuments.getDocuments(txn,keys);}).next(function(changedDocuments){return{batchId:batch.batchId,changes:changedDocuments};});});};/**
* Acknowledge the given batch.
*
* On the happy path when a batch is acknowledged, the local store will
*
* + remove the batch from the mutation queue;
* + apply the changes to the remote document cache;
* + recalculate the latency compensated view implied by those changes (there
* may be mutations in the queue that affect the documents but haven't been
* acknowledged yet); and
* + give the changed documents back the sync engine
*
* @returns The resulting (modified) documents.
*/LocalStore.prototype.acknowledgeBatch=function(batchResult){var _this=this;return this.persistence.runTransaction('Acknowledge batch',function(txn){var affected;return _this.mutationQueue.acknowledgeBatch(txn,batchResult.batch,batchResult.streamToken).next(function(){if(_this.shouldHoldBatchResult(batchResult.commitVersion)){_this.heldBatchResults.push(batchResult);affected=documentKeySet();return PersistencePromise.resolve();}else{var documentBuffer_1=new RemoteDocumentChangeBuffer(_this.remoteDocuments);return _this.releaseBatchResults(txn,[batchResult],documentBuffer_1).next(function(promisedAffectedKeys){affected=promisedAffectedKeys;return documentBuffer_1.apply(txn);});}}).next(function(){return _this.mutationQueue.performConsistencyCheck(txn);}).next(function(){return _this.localDocuments.getDocuments(txn,affected);});});};/**
* Remove mutations from the MutationQueue for the specified batch;
* LocalDocuments will be recalculated.
*
* @returns The resulting modified documents.
*/LocalStore.prototype.rejectBatch=function(batchId){var _this=this;return this.persistence.runTransaction('Reject batch',function(txn){var toReject;var affectedKeys;return _this.mutationQueue.lookupMutationBatch(txn,batchId).next(function(promisedToReject){assert(promisedToReject!=null,'Attempt to reject nonexistent batch!');toReject=promisedToReject;return _this.mutationQueue.getHighestAcknowledgedBatchId(txn).next(function(lastAcked){assert(batchId>lastAcked,"Acknowledged batches can't be rejected.");return toReject;});}).next(function(){return _this.removeMutationBatch(txn,toReject);}).next(function(promisedAffectedKeys){affectedKeys=promisedAffectedKeys;return _this.mutationQueue.performConsistencyCheck(txn);}).next(function(){return _this.localDocuments.getDocuments(txn,affectedKeys);});});};/** Returns the last recorded stream token for the current user. */LocalStore.prototype.getLastStreamToken=function(){var _this=this;return this.persistence.runTransaction('Get last stream token',function(txn){return _this.mutationQueue.getLastStreamToken(txn);});};/**
* Sets the stream token for the current user without acknowledging any
* mutation batch. This is usually only useful after a stream handshake or in
* response to an error that requires clearing the stream token.
*/LocalStore.prototype.setLastStreamToken=function(streamToken){var _this=this;return this.persistence.runTransaction('Set last stream token',function(txn){return _this.mutationQueue.setLastStreamToken(txn,streamToken);});};/**
* Returns the last consistent snapshot processed (used by the RemoteStore to
* determine whether to buffer incoming snapshots from the backend).
*/LocalStore.prototype.getLastRemoteSnapshotVersion=function(){return this.queryCache.getLastRemoteSnapshotVersion();};/**
* Update the "ground-state" (remote) documents. We assume that the remote
* event reflects any write batches that have been acknowledged or rejected
* (i.e. we do not re-apply local mutations to updates from this event).
*
* LocalDocuments are re-calculated if there are remaining mutations in the
* queue.
*/LocalStore.prototype.applyRemoteEvent=function(remoteEvent){var _this=this;var documentBuffer=new RemoteDocumentChangeBuffer(this.remoteDocuments);return this.persistence.runTransaction('Apply remote event',function(txn){var promises=[];forEachNumber(remoteEvent.targetChanges,function(targetId,change){// Do not ref/unref unassigned targetIds - it may lead to leaks.
var queryData=_this.targetIds[targetId];if(!queryData)return;var mapping=change.mapping;if(mapping){// First make sure that all references are deleted
if(mapping instanceof ResetMapping){promises.push(_this.queryCache.removeMatchingKeysForTargetId(txn,targetId).next(function(){return _this.queryCache.addMatchingKeys(txn,mapping.documents,targetId);}));}else if(mapping instanceof UpdateMapping){promises.push(_this.queryCache.removeMatchingKeys(txn,mapping.removedDocuments,targetId).next(function(){return _this.queryCache.addMatchingKeys(txn,mapping.addedDocuments,targetId);}));}else{return fail('Unknown mapping type: '+JSON.stringify(mapping));}}// Update the resume token if the change includes one. Don't clear
// any preexisting value.
var resumeToken=change.resumeToken;if(resumeToken.length>0){queryData=queryData.update({resumeToken:resumeToken,snapshotVersion:change.snapshotVersion});_this.targetIds[targetId]=queryData;promises.push(_this.queryCache.updateQueryData(txn,queryData));}});var changedDocKeys=documentKeySet();remoteEvent.documentUpdates.forEach(function(key,doc){changedDocKeys=changedDocKeys.add(key);promises.push(documentBuffer.getEntry(txn,key).next(function(existingDoc){// Make sure we don't apply an old document version to the remote
// cache, though we make an exception for SnapshotVersion.MIN which
// can happen for manufactured events (e.g. in the case of a limbo
// document resolution failing).
if(existingDoc==null||doc.version.isEqual(SnapshotVersion.MIN)||doc.version.compareTo(existingDoc.version)>=0){documentBuffer.addEntry(doc);}else{debug(LOG_TAG$4,'Ignoring outdated watch update for ',key,'. Current version:',existingDoc.version,' Watch version:',doc.version);}// The document might be garbage because it was unreferenced by
// everything. Make sure to mark it as garbage if it is...
_this.garbageCollector.addPotentialGarbageKey(key);}));});// HACK: The only reason we allow a null snapshot version is so that we
// can synthesize remote events when we get permission denied errors while
// trying to resolve the state of a locally cached document that is in
// limbo.
var lastRemoteVersion=_this.queryCache.getLastRemoteSnapshotVersion();var remoteVersion=remoteEvent.snapshotVersion;if(!remoteVersion.isEqual(SnapshotVersion.MIN)){assert(remoteVersion.compareTo(lastRemoteVersion)>=0,'Watch stream reverted to previous snapshot?? '+remoteVersion+' < '+lastRemoteVersion);promises.push(_this.queryCache.setLastRemoteSnapshotVersion(txn,remoteVersion));}var releasedWriteKeys;return PersistencePromise.waitFor(promises).next(function(){return _this.releaseHeldBatchResults(txn,documentBuffer);}).next(function(promisedReleasedWriteKeys){releasedWriteKeys=promisedReleasedWriteKeys;return documentBuffer.apply(txn);}).next(function(){return _this.localDocuments.getDocuments(txn,changedDocKeys.unionWith(releasedWriteKeys));});});};/**
* Notify local store of the changed views to locally pin documents.
*/LocalStore.prototype.notifyLocalViewChanges=function(viewChanges){var _this=this;return this.persistence.runTransaction('Notify local view changes',function(txn){var promises=[];var _loop_1=function(view){promises.push(_this.queryCache.getQueryData(txn,view.query).next(function(queryData){assert(queryData!==null,'Local view changes contain unallocated query.');var targetId=queryData.targetId;_this.localViewReferences.addReferences(view.addedKeys,targetId);_this.localViewReferences.removeReferences(view.removedKeys,targetId);}));};for(var _i=0,viewChanges_1=viewChanges;_i<viewChanges_1.length;_i++){var view=viewChanges_1[_i];_loop_1(view);}return PersistencePromise.waitFor(promises);});};/**
* Gets the mutation batch after the passed in batchId in the mutation queue
* or null if empty.
* @param afterBatchId If provided, the batch to search after.
* @returns The next mutation or null if there wasn't one.
*/LocalStore.prototype.nextMutationBatch=function(afterBatchId){var _this=this;return this.persistence.runTransaction('Get next mutation batch',function(txn){if(afterBatchId===undefined){afterBatchId=BATCHID_UNKNOWN;}return _this.mutationQueue.getNextMutationBatchAfterBatchId(txn,afterBatchId);});};/**
* Read the current value of a Document with a given key or null if not
* found - used for testing.
*/LocalStore.prototype.readDocument=function(key){var _this=this;return this.persistence.runTransaction('read document',function(txn){return _this.localDocuments.getDocument(txn,key);});};/**
* Assigns the given query an internal ID so that its results can be pinned so
* they don't get GC'd. A query must be allocated in the local store before
* the store can be used to manage its view.
*/LocalStore.prototype.allocateQuery=function(query){var _this=this;return this.persistence.runTransaction('Allocate query',function(txn){var queryData;return _this.queryCache.getQueryData(txn,query).next(function(cached){if(cached){// This query has been listened to previously, so reuse the
// previous targetID.
// TODO(mcg): freshen last accessed date?
queryData=cached;return PersistencePromise.resolve();}else{var targetId=_this.targetIdGenerator.next();queryData=new QueryData(query,targetId,QueryPurpose.Listen);return _this.queryCache.addQueryData(txn,queryData);}}).next(function(){assert(!_this.targetIds[queryData.targetId],'Tried to allocate an already allocated query: '+query);_this.targetIds[queryData.targetId]=queryData;return queryData;});});};/** Unpin all the documents associated with the given query. */LocalStore.prototype.releaseQuery=function(query){var _this=this;return this.persistence.runTransaction('Release query',function(txn){return _this.queryCache.getQueryData(txn,query).next(function(queryData){assert(queryData!=null,'Tried to release nonexistent query: '+query);_this.localViewReferences.removeReferencesForId(queryData.targetId);delete _this.targetIds[queryData.targetId];if(_this.garbageCollector.isEager){return _this.queryCache.removeQueryData(txn,queryData);}else{return PersistencePromise.resolve();}}).next(function(){// If this was the last watch target, then we won't get any more
// watch snapshots, so we should release any held batch results.
if(isEmpty(_this.targetIds)){var documentBuffer_2=new RemoteDocumentChangeBuffer(_this.remoteDocuments);return _this.releaseHeldBatchResults(txn,documentBuffer_2).next(function(){documentBuffer_2.apply(txn);});}else{return PersistencePromise.resolve();}});});};/**
* Runs the specified query against all the documents in the local store and
* returns the results.
*/LocalStore.prototype.executeQuery=function(query){var _this=this;return this.persistence.runTransaction('Execute query',function(txn){return _this.localDocuments.getDocumentsMatchingQuery(txn,query);});};/**
* Returns the keys of the documents that are associated with the given
* target id in the remote table.
*/LocalStore.prototype.remoteDocumentKeys=function(targetId){var _this=this;return this.persistence.runTransaction('Remote document keys',function(txn){return _this.queryCache.getMatchingKeysForTargetId(txn,targetId);});};/**
* Collect garbage if necessary.
* Should be called periodically by Sync Engine to recover resources. The
* implementation must guarantee that GC won't happen in other places than
* this method call.
*/LocalStore.prototype.collectGarbage=function(){var _this=this;// Call collectGarbage regardless of whether isGCEnabled so the referenceSet
// doesn't continue to accumulate the garbage keys.
return this.persistence.runTransaction('Garbage collection',function(txn){return _this.garbageCollector.collectGarbage(txn).next(function(garbage){var promises=[];garbage.forEach(function(key){promises.push(_this.remoteDocuments.removeEntry(txn,key));});return PersistencePromise.waitFor(promises);});});};LocalStore.prototype.releaseHeldBatchResults=function(txn,documentBuffer){var toRelease=[];for(var _i=0,_a=this.heldBatchResults;_i<_a.length;_i++){var batchResult=_a[_i];if(!this.isRemoteUpToVersion(batchResult.commitVersion)){break;}toRelease.push(batchResult);}if(toRelease.length===0){return PersistencePromise.resolve(documentKeySet());}else{this.heldBatchResults.splice(0,toRelease.length);return this.releaseBatchResults(txn,toRelease,documentBuffer);}};LocalStore.prototype.isRemoteUpToVersion=function(version){// If there are no watch targets, then we won't get remote snapshots, and
// we are always "up-to-date."
var lastRemoteVersion=this.queryCache.getLastRemoteSnapshotVersion();return version.compareTo(lastRemoteVersion)<=0||isEmpty(this.targetIds);};LocalStore.prototype.shouldHoldBatchResult=function(version){// Check if watcher isn't up to date or prior results are already held.
return!this.isRemoteUpToVersion(version)||this.heldBatchResults.length>0;};LocalStore.prototype.releaseBatchResults=function(txn,batchResults,documentBuffer){var _this=this;var promiseChain=PersistencePromise.resolve();var _loop_2=function(batchResult){promiseChain=promiseChain.next(function(){return _this.applyWriteToRemoteDocuments(txn,batchResult,documentBuffer);});};for(var _i=0,batchResults_1=batchResults;_i<batchResults_1.length;_i++){var batchResult=batchResults_1[_i];_loop_2(batchResult);}return promiseChain.next(function(){return _this.removeMutationBatches(txn,batchResults.map(function(result){return result.batch;}));});};LocalStore.prototype.removeMutationBatch=function(txn,batch){return this.removeMutationBatches(txn,[batch]);};/** Removes all the mutation batches named in the given array. */LocalStore.prototype.removeMutationBatches=function(txn,batches){var affectedDocs=documentKeySet();for(var _i=0,batches_2=batches;_i<batches_2.length;_i++){var batch=batches_2[_i];for(var _a=0,_b=batch.mutations;_a<_b.length;_a++){var mutation=_b[_a];var key=mutation.key;affectedDocs=affectedDocs.add(key);}}return this.mutationQueue.removeMutationBatches(txn,batches).next(function(){return affectedDocs;});};LocalStore.prototype.applyWriteToRemoteDocuments=function(txn,batchResult,documentBuffer){var batch=batchResult.batch;var docKeys=batch.keys();var promiseChain=PersistencePromise.resolve();docKeys.forEach(function(docKey){promiseChain=promiseChain.next(function(){return documentBuffer.getEntry(txn,docKey);}).next(function(remoteDoc){var doc=remoteDoc;var ackVersion=batchResult.docVersions.get(docKey);assert(ackVersion!==null,'ackVersions should contain every doc in the write.');if(!doc||doc.version.compareTo(ackVersion)<0){doc=batch.applyToRemoteDocument(docKey,doc,batchResult);if(!doc){assert(!remoteDoc,'Mutation batch '+batch+' applied to document '+remoteDoc+' resulted in null');}else{documentBuffer.addEntry(doc);}}});});return promiseChain;};return LocalStore;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var MemoryMutationQueue=/** @class */function(){function MemoryMutationQueue(){/**
* The set of all mutations that have been sent but not yet been applied to
* the backend.
*/this.mutationQueue=[];/** Next value to use when assigning sequential IDs to each mutation batch. */this.nextBatchId=1;/** The highest acknowledged mutation in the queue. */this.highestAcknowledgedBatchId=BATCHID_UNKNOWN;/** The last received stream token from the server, used to acknowledge which
* responses the client has processed. Stream tokens are opaque checkpoint
* markers whose only real value is their inclusion in the next request.
*/this.lastStreamToken=emptyByteString();/** The garbage collector to notify about potential garbage keys. */this.garbageCollector=null;/** An ordered mapping between documents and the mutations batch IDs. */this.batchesByDocumentKey=new SortedSet(DocReference.compareByKey);}MemoryMutationQueue.prototype.start=function(transaction){// NOTE: The queue may be shutdown / started multiple times, since we
// maintain the queue for the duration of the app session in case a user
// logs out / back in. To behave like the LevelDB-backed MutationQueue (and
// accommodate tests that expect as much), we reset nextBatchId and
// highestAcknowledgedBatchId if the queue is empty.
if(this.mutationQueue.length===0){this.nextBatchId=1;this.highestAcknowledgedBatchId=BATCHID_UNKNOWN;}assert(this.highestAcknowledgedBatchId<this.nextBatchId,'highestAcknowledgedBatchId must be less than the nextBatchId');return PersistencePromise.resolve();};MemoryMutationQueue.prototype.checkEmpty=function(transaction){return PersistencePromise.resolve(this.mutationQueue.length===0);};MemoryMutationQueue.prototype.getNextBatchId=function(transaction){return PersistencePromise.resolve(this.nextBatchId);};MemoryMutationQueue.prototype.getHighestAcknowledgedBatchId=function(transaction){return PersistencePromise.resolve(this.highestAcknowledgedBatchId);};MemoryMutationQueue.prototype.acknowledgeBatch=function(transaction,batch,streamToken){var batchId=batch.batchId;assert(batchId>this.highestAcknowledgedBatchId,'Mutation batchIDs must be acknowledged in order');var batchIndex=this.indexOfExistingBatchId(batchId,'acknowledged');// Verify that the batch in the queue is the one to be acknowledged.
var check=this.mutationQueue[batchIndex];assert(batchId===check.batchId,'Queue ordering failure: expected batch '+batchId+', got batch '+check.batchId);assert(!check.isTombstone(),"Can't acknowledge a previously removed batch");this.highestAcknowledgedBatchId=batchId;this.lastStreamToken=streamToken;return PersistencePromise.resolve();};MemoryMutationQueue.prototype.getLastStreamToken=function(transaction){return PersistencePromise.resolve(this.lastStreamToken);};MemoryMutationQueue.prototype.setLastStreamToken=function(transaction,streamToken){this.lastStreamToken=streamToken;return PersistencePromise.resolve();};MemoryMutationQueue.prototype.addMutationBatch=function(transaction,localWriteTime,mutations){assert(mutations.length!==0,'Mutation batches should not be empty');var batchId=this.nextBatchId;this.nextBatchId++;if(this.mutationQueue.length>0){var prior=this.mutationQueue[this.mutationQueue.length-1];assert(prior.batchId<batchId,'Mutation batchIDs must be monotonically increasing order');}var batch=new MutationBatch(batchId,localWriteTime,mutations);this.mutationQueue.push(batch);// Track references by document key.
for(var _i=0,mutations_1=mutations;_i<mutations_1.length;_i++){var mutation=mutations_1[_i];this.batchesByDocumentKey=this.batchesByDocumentKey.add(new DocReference(mutation.key,batchId));}return PersistencePromise.resolve(batch);};MemoryMutationQueue.prototype.lookupMutationBatch=function(transaction,batchId){return PersistencePromise.resolve(this.findMutationBatch(batchId));};MemoryMutationQueue.prototype.getNextMutationBatchAfterBatchId=function(transaction,batchId){var size=this.mutationQueue.length;// All batches with batchId <= this.highestAcknowledgedBatchId have been
// acknowledged so the first unacknowledged batch after batchID will have a
// batchID larger than both of these values.
var nextBatchId=Math.max(batchId,this.highestAcknowledgedBatchId)+1;// The requested batchId may still be out of range so normalize it to the
// start of the queue.
var rawIndex=this.indexOfBatchId(nextBatchId);var index=rawIndex<0?0:rawIndex;// Finally return the first non-tombstone batch.
for(;index<size;index++){var batch=this.mutationQueue[index];if(!batch.isTombstone()){return PersistencePromise.resolve(batch);}}return PersistencePromise.resolve(null);};MemoryMutationQueue.prototype.getAllMutationBatches=function(transaction){return PersistencePromise.resolve(this.getAllLiveMutationBatchesBeforeIndex(this.mutationQueue.length));};MemoryMutationQueue.prototype.getAllMutationBatchesThroughBatchId=function(transaction,batchId){var count=this.mutationQueue.length;var endIndex=this.indexOfBatchId(batchId);if(endIndex<0){endIndex=0;}else if(endIndex>=count){endIndex=count;}else{// The endIndex is in the queue so increment to pull everything in the
// queue including it.
endIndex++;}return PersistencePromise.resolve(this.getAllLiveMutationBatchesBeforeIndex(endIndex));};MemoryMutationQueue.prototype.getAllMutationBatchesAffectingDocumentKey=function(transaction,documentKey){var _this=this;var start=new DocReference(documentKey,0);var end=new DocReference(documentKey,Number.POSITIVE_INFINITY);var result=[];this.batchesByDocumentKey.forEachInRange([start,end],function(ref){assert(documentKey.isEqual(ref.key),"Should only iterate over a single key's batches");var batch=_this.findMutationBatch(ref.targetOrBatchId);assert(batch!==null,'Batches in the index must exist in the main table');result.push(batch);});return PersistencePromise.resolve(result);};MemoryMutationQueue.prototype.getAllMutationBatchesAffectingQuery=function(transaction,query){var _this=this;// Use the query path as a prefix for testing if a document matches the
// query.
var prefix=query.path;var immediateChildrenPathLength=prefix.length+1;// Construct a document reference for actually scanning the index. Unlike
// the prefix the document key in this reference must have an even number of
// segments. The empty segment can be used a suffix of the query path
// because it precedes all other segments in an ordered traversal.
var startPath=prefix;if(!DocumentKey.isDocumentKey(startPath)){startPath=startPath.child('');}var start=new DocReference(new DocumentKey(startPath),0);// Find unique batchIDs referenced by all documents potentially matching the
// query.
var uniqueBatchIDs=new SortedSet(primitiveComparator);this.batchesByDocumentKey.forEachWhile(function(ref){var rowKeyPath=ref.key.path;if(!prefix.isPrefixOf(rowKeyPath)){return false;}else{// Rows with document keys more than one segment longer than the query
// path can't be matches. For example, a query on 'rooms' can't match
// the document /rooms/abc/messages/xyx.
// TODO(mcg): we'll need a different scanner when we implement
// ancestor queries.
if(rowKeyPath.length===immediateChildrenPathLength){uniqueBatchIDs=uniqueBatchIDs.add(ref.targetOrBatchId);}return true;}},start);// Construct an array of matching batches, sorted by batchID to ensure that
// multiple mutations affecting the same document key are applied in order.
var result=[];uniqueBatchIDs.forEach(function(batchId){var batch=_this.findMutationBatch(batchId);if(batch!==null){result.push(batch);}});return PersistencePromise.resolve(result);};MemoryMutationQueue.prototype.removeMutationBatches=function(transaction,batches){var batchCount=batches.length;assert(batchCount>0,'Should not remove mutations when none exist.');var firstBatchId=batches[0].batchId;var queueCount=this.mutationQueue.length;// Find the position of the first batch for removal. This need not be the
// first entry in the queue.
var startIndex=this.indexOfExistingBatchId(firstBatchId,'removed');assert(this.mutationQueue[startIndex].batchId===firstBatchId,'Removed batches must exist in the queue');// Check that removed batches are contiguous (while excluding tombstones).
var batchIndex=1;var queueIndex=startIndex+1;while(batchIndex<batchCount&&queueIndex<queueCount){var batch=this.mutationQueue[queueIndex];if(batch.isTombstone()){queueIndex++;continue;}assert(batch.batchId===batches[batchIndex].batchId,'Removed batches must be contiguous in the queue');batchIndex++;queueIndex++;}// Only actually remove batches if removing at the front of the queue.
// Previously rejected batches may have left tombstones in the queue, so
// expand the removal range to include any tombstones.
if(startIndex===0){for(;queueIndex<queueCount;queueIndex++){var batch=this.mutationQueue[queueIndex];if(!batch.isTombstone()){break;}}var length_1=queueIndex-startIndex;this.mutationQueue.splice(startIndex,length_1);}else{// Mark the tombstones
for(var i=startIndex;i<queueIndex;i++){this.mutationQueue[i]=this.mutationQueue[i].toTombstone();}}var references=this.batchesByDocumentKey;for(var _i=0,batches_1=batches;_i<batches_1.length;_i++){var batch=batches_1[_i];var batchId=batch.batchId;for(var _a=0,_b=batch.mutations;_a<_b.length;_a++){var mutation=_b[_a];var key=mutation.key;if(this.garbageCollector!==null){this.garbageCollector.addPotentialGarbageKey(key);}var ref=new DocReference(key,batchId);references=references.delete(ref);}}this.batchesByDocumentKey=references;return PersistencePromise.resolve();};MemoryMutationQueue.prototype.setGarbageCollector=function(garbageCollector){this.garbageCollector=garbageCollector;};MemoryMutationQueue.prototype.containsKey=function(txn,key){var ref=new DocReference(key,0);var firstRef=this.batchesByDocumentKey.firstAfterOrEqual(ref);return PersistencePromise.resolve(key.isEqual(firstRef&&firstRef.key));};MemoryMutationQueue.prototype.performConsistencyCheck=function(txn){if(this.mutationQueue.length===0){assert(this.batchesByDocumentKey.isEmpty(),'Document leak -- detected dangling mutation references when queue is empty.');}return PersistencePromise.resolve();};/**
* A private helper that collects all the mutations batches in the queue up to
* but not including the given endIndex. All tombstones in the queue are
* excluded.
*/MemoryMutationQueue.prototype.getAllLiveMutationBatchesBeforeIndex=function(endIndex){var result=[];for(var i=0;i<endIndex;i++){var batch=this.mutationQueue[i];if(!batch.isTombstone()){result.push(batch);}}return result;};/**
* Finds the index of the given batchId in the mutation queue and asserts that
* the resulting index is within the bounds of the queue.
*
* @param batchId The batchId to search for
* @param action A description of what the caller is doing, phrased in passive
* form (e.g. "acknowledged" in a routine that acknowledges batches).
*/MemoryMutationQueue.prototype.indexOfExistingBatchId=function(batchId,action){var index=this.indexOfBatchId(batchId);assert(index>=0&&index<this.mutationQueue.length,'Batches must exist to be '+action);return index;};/**
* Finds the index of the given batchId in the mutation queue. This operation
* is O(1).
*
* @return The computed index of the batch with the given batchId, based on
* the state of the queue. Note this index can be negative if the requested
* batchId has already been remvoed from the queue or past the end of the
* queue if the batchId is larger than the last added batch.
*/MemoryMutationQueue.prototype.indexOfBatchId=function(batchId){if(this.mutationQueue.length===0){// As an index this is past the end of the queue
return 0;}// Examine the front of the queue to figure out the difference between the
// batchId and indexes in the array. Note that since the queue is ordered
// by batchId, if the first batch has a larger batchId then the requested
// batchId doesn't exist in the queue.
var firstBatchId=this.mutationQueue[0].batchId;return batchId-firstBatchId;};/**
* A version of lookupMutationBatch that doesn't return a promise, this makes
* other functions that uses this code easier to read and more efficent.
*/MemoryMutationQueue.prototype.findMutationBatch=function(batchId){var index=this.indexOfBatchId(batchId);if(index<0||index>=this.mutationQueue.length){return null;}var batch=this.mutationQueue[index];assert(batch.batchId===batchId,'If found batch must match');return batch.isTombstone()?null:batch;};return MemoryMutationQueue;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var MemoryQueryCache=/** @class */function(){function MemoryQueryCache(){/**
* Maps a query to the data about that query
*/this.queries=new ObjectMap(function(q){return q.canonicalId();});/** The last received snapshot version. */this.lastRemoteSnapshotVersion=SnapshotVersion.MIN;/** The highest numbered target ID encountered. */this.highestTargetId=0;/**
* A ordered bidirectional mapping between documents and the remote target
* IDs.
*/this.references=new ReferenceSet();this.targetCount=0;}MemoryQueryCache.prototype.start=function(transaction){// Nothing to do.
return PersistencePromise.resolve();};MemoryQueryCache.prototype.getLastRemoteSnapshotVersion=function(){return this.lastRemoteSnapshotVersion;};MemoryQueryCache.prototype.getHighestTargetId=function(){return this.highestTargetId;};MemoryQueryCache.prototype.setLastRemoteSnapshotVersion=function(transaction,snapshotVersion){this.lastRemoteSnapshotVersion=snapshotVersion;return PersistencePromise.resolve();};MemoryQueryCache.prototype.saveQueryData=function(queryData){this.queries.set(queryData.query,queryData);var targetId=queryData.targetId;if(targetId>this.highestTargetId){this.highestTargetId=targetId;}// TODO(GC): track sequence number
};MemoryQueryCache.prototype.addQueryData=function(transaction,queryData){assert(!this.queries.has(queryData.query),'Adding a query that already exists');this.saveQueryData(queryData);this.targetCount+=1;return PersistencePromise.resolve();};MemoryQueryCache.prototype.updateQueryData=function(transaction,queryData){assert(this.queries.has(queryData.query),'Updating a non-existent query');this.saveQueryData(queryData);return PersistencePromise.resolve();};MemoryQueryCache.prototype.removeQueryData=function(transaction,queryData){assert(this.targetCount>0,'Removing a target from an empty cache');assert(this.queries.has(queryData.query),'Removing a non-existent target from the cache');this.queries.delete(queryData.query);this.references.removeReferencesForId(queryData.targetId);this.targetCount-=1;return PersistencePromise.resolve();};Object.defineProperty(MemoryQueryCache.prototype,"count",{get:function(){return this.targetCount;},enumerable:true,configurable:true});MemoryQueryCache.prototype.getQueryData=function(transaction,query){var queryData=this.queries.get(query)||null;return PersistencePromise.resolve(queryData);};MemoryQueryCache.prototype.addMatchingKeys=function(txn,keys,targetId){this.references.addReferences(keys,targetId);return PersistencePromise.resolve();};MemoryQueryCache.prototype.removeMatchingKeys=function(txn,keys,targetId){this.references.removeReferences(keys,targetId);return PersistencePromise.resolve();};MemoryQueryCache.prototype.removeMatchingKeysForTargetId=function(txn,targetId){this.references.removeReferencesForId(targetId);return PersistencePromise.resolve();};MemoryQueryCache.prototype.getMatchingKeysForTargetId=function(txn,targetId){var matchingKeys=this.references.referencesForId(targetId);return PersistencePromise.resolve(matchingKeys);};MemoryQueryCache.prototype.setGarbageCollector=function(gc){this.references.setGarbageCollector(gc);};MemoryQueryCache.prototype.containsKey=function(txn,key){return this.references.containsKey(txn,key);};return MemoryQueryCache;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var MemoryRemoteDocumentCache=/** @class */function(){function MemoryRemoteDocumentCache(){this.docs=maybeDocumentMap();}MemoryRemoteDocumentCache.prototype.addEntry=function(transaction,maybeDocument){this.docs=this.docs.insert(maybeDocument.key,maybeDocument);return PersistencePromise.resolve();};MemoryRemoteDocumentCache.prototype.removeEntry=function(transaction,documentKey){this.docs=this.docs.remove(documentKey);return PersistencePromise.resolve();};MemoryRemoteDocumentCache.prototype.getEntry=function(transaction,documentKey){return PersistencePromise.resolve(this.docs.get(documentKey));};MemoryRemoteDocumentCache.prototype.getDocumentsMatchingQuery=function(transaction,query){var results=documentMap();// Documents are ordered by key, so we can use a prefix scan to narrow down
// the documents we need to match the query against.
var prefix=new DocumentKey(query.path.child(''));var iterator=this.docs.getIteratorFrom(prefix);while(iterator.hasNext()){var _a=iterator.getNext(),key=_a.key,maybeDoc=_a.value;if(!query.path.isPrefixOf(key.path)){break;}if(maybeDoc instanceof Document&&query.matches(maybeDoc)){results=results.insert(maybeDoc.key,maybeDoc);}}return PersistencePromise.resolve(results);};return MemoryRemoteDocumentCache;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$5='MemoryPersistence';/**
* A memory-backed instance of Persistence. Data is stored only in RAM and
* not persisted across sessions.
*/var MemoryPersistence=/** @class */function(){function MemoryPersistence(){/**
* Note that these are retained here to make it easier to write tests
* affecting both the in-memory and IndexedDB-backed persistence layers. Tests
* can create a new LocalStore wrapping this Persistence instance and this
* will make the in-memory persistence layer behave as if it were actually
* persisting values.
*/this.mutationQueues={};this.remoteDocumentCache=new MemoryRemoteDocumentCache();this.queryCache=new MemoryQueryCache();this.started=false;}MemoryPersistence.prototype.start=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){// No durable state to read on startup.
assert(!this.started,'MemoryPersistence double-started!');this.started=true;return[2/*return*/];});});};MemoryPersistence.prototype.shutdown=function(deleteData){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){// No durable state to ensure is closed on shutdown.
assert(this.started,'MemoryPersistence shutdown without start!');this.started=false;return[2/*return*/];});});};MemoryPersistence.prototype.getMutationQueue=function(user){var queue=this.mutationQueues[user.toKey()];if(!queue){queue=new MemoryMutationQueue();this.mutationQueues[user.toKey()]=queue;}return queue;};MemoryPersistence.prototype.getQueryCache=function(){return this.queryCache;};MemoryPersistence.prototype.getRemoteDocumentCache=function(){return this.remoteDocumentCache;};MemoryPersistence.prototype.runTransaction=function(action,operation){debug(LOG_TAG$5,'Starting transaction:',action);return operation(new MemoryPersistenceTransaction()).toPromise();};return MemoryPersistence;}();/** Dummy class since memory persistence doesn't actually use transactions. */var MemoryPersistenceTransaction=/** @class */function(){function MemoryPersistenceTransaction(){}return MemoryPersistenceTransaction;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* A garbage collector implementation that does absolutely nothing. It ignores
* all addGarbageSource and addPotentialGarbageKey messages and and never
* produces any garbage.
*/var NoOpGarbageCollector=/** @class */function(){function NoOpGarbageCollector(){this.isEager=false;}NoOpGarbageCollector.prototype.addGarbageSource=function(garbageSource){// Not tracking garbage so don't track sources.
};NoOpGarbageCollector.prototype.removeGarbageSource=function(garbageSource){// Not tracking garbage so don't track sources.
};NoOpGarbageCollector.prototype.addPotentialGarbageKey=function(key){// Not tracking garbage so ignore.
};NoOpGarbageCollector.prototype.collectGarbage=function(txn){return PersistencePromise.resolve(documentKeySet());};return NoOpGarbageCollector;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Wellknown "timer" IDs used when scheduling delayed operations on the
* AsyncQueue. These IDs can then be used from tests to check for the presence
* of operations or to run them early.
*
* The string values are used when encoding these timer IDs in JSON spec tests.
*/var TimerId;(function(TimerId){/** All can be used with runDelayedOperationsEarly() to run all timers. */TimerId["All"]="all";/**
* The following 4 timers are used in persistent_stream.ts for the listen and
* write streams. The "Idle" timer is used to close the stream due to
* inactivity. The "ConnectionBackoff" timer is used to restart a stream once
* the appropriate backoff delay has elapsed.
*/TimerId["ListenStreamIdle"]="listen_stream_idle";TimerId["ListenStreamConnectionBackoff"]="listen_stream_connection_backoff";TimerId["WriteStreamIdle"]="write_stream_idle";TimerId["WriteStreamConnectionBackoff"]="write_stream_connection_backoff";/**
* A timer used in online_state_tracker.ts to transition from
* OnlineState.Unknown to Offline after a set timeout, rather than waiting
* indefinitely for success or failure.
*/TimerId["OnlineStateTimeout"]="online_state_timeout";})(TimerId||(TimerId={}));/**
* Represents an operation scheduled to be run in the future on an AsyncQueue.
*
* It is created via DelayedOperation.createAndSchedule().
*
* Supports cancellation (via cancel()) and early execution (via skipDelay()).
*/var DelayedOperation=/** @class */function(){function DelayedOperation(asyncQueue,timerId,targetTimeMs,op,removalCallback){this.asyncQueue=asyncQueue;this.timerId=timerId;this.targetTimeMs=targetTimeMs;this.op=op;this.removalCallback=removalCallback;this.deferred=new Deferred$1();this.then=this.deferred.promise.then.bind(this.deferred.promise);this.catch=this.deferred.promise.catch.bind(this.deferred.promise);// It's normal for the deferred promise to be canceled (due to cancellation)
// and so we attach a dummy catch callback to avoid
// 'UnhandledPromiseRejectionWarning' log spam.
this.deferred.promise.catch(function(err){});}/**
* Creates and returns a DelayedOperation that has been scheduled to be
* executed on the provided asyncQueue after the provided delayMs.
*
* @param asyncQueue The queue to schedule the operation on.
* @param id A Timer ID identifying the type of operation this is.
* @param delayMs The delay (ms) before the operation should be scheduled.
* @param op The operation to run.
* @param removalCallback A callback to be called synchronously once the
* operation is executed or canceled, notifying the AsyncQueue to remove it
* from its delayedOperations list.
* PORTING NOTE: This exists to prevent making removeDelayedOperation() and
* the DelayedOperation class public.
*/DelayedOperation.createAndSchedule=function(asyncQueue,timerId,delayMs,op,removalCallback){var targetTime=Date.now()+delayMs;var delayedOp=new DelayedOperation(asyncQueue,timerId,targetTime,op,removalCallback);delayedOp.start(delayMs);return delayedOp;};/**
* Starts the timer. This is called immediately after construction by
* createAndSchedule().
*/DelayedOperation.prototype.start=function(delayMs){var _this=this;this.timerHandle=setTimeout(function(){return _this.handleDelayElapsed();},delayMs);};/**
* Queues the operation to run immediately (if it hasn't already been run or
* canceled).
*/DelayedOperation.prototype.skipDelay=function(){return this.handleDelayElapsed();};/**
* Cancels the operation if it hasn't already been executed or canceled. The
* promise will be rejected.
*
* As long as the operation has not yet been run, calling cancel() provides a
* guarantee that the operation will not be run.
*/DelayedOperation.prototype.cancel=function(reason){if(this.timerHandle!==null){this.clearTimeout();this.deferred.reject(new FirestoreError(Code.CANCELLED,'Operation cancelled'+(reason?': '+reason:'')));}};DelayedOperation.prototype.handleDelayElapsed=function(){var _this=this;this.asyncQueue.enqueue(function(){if(_this.timerHandle!==null){_this.clearTimeout();return _this.op().then(function(result){return _this.deferred.resolve(result);});}else{return Promise.resolve();}});};DelayedOperation.prototype.clearTimeout=function(){if(this.timerHandle!==null){this.removalCallback(this);clearTimeout(this.timerHandle);this.timerHandle=null;}};return DelayedOperation;}();var AsyncQueue=/** @class */function(){function AsyncQueue(){// The last promise in the queue.
this.tail=Promise.resolve();// Operations scheduled to be queued in the future. Operations are
// automatically removed after they are run or canceled.
this.delayedOperations=[];// Flag set while there's an outstanding AsyncQueue operation, used for
// assertion sanity-checks.
this.operationInProgress=false;}/**
* Adds a new operation to the queue. Returns a promise that will be resolved
* when the promise returned by the new operation is (with its value).
*/AsyncQueue.prototype.enqueue=function(op){var _this=this;this.verifyNotFailed();var newTail=this.tail.then(function(){_this.operationInProgress=true;return op().catch(function(error$$1){_this.failure=error$$1;_this.operationInProgress=false;var message=error$$1.stack||error$$1.message||'';error('INTERNAL UNHANDLED ERROR: ',message);// Escape the promise chain and throw the error globally so that
// e.g. any global crash reporting library detects and reports it.
// (but not for simulated errors in our tests since this breaks mocha)
if(message.indexOf('Firestore Test Simulated Error')<0){setTimeout(function(){throw error$$1;},0);}// Re-throw the error so that this.tail becomes a rejected Promise and
// all further attempts to chain (via .then) will just short-circuit
// and return the rejected Promise.
throw error$$1;}).then(function(result){_this.operationInProgress=false;return result;});});this.tail=newTail;return newTail;};/**
* Schedules an operation to be queued on the AsyncQueue once the specified
* `delayMs` has elapsed. The returned CancelablePromise can be used to cancel
* the operation prior to its running.
*/AsyncQueue.prototype.enqueueAfterDelay=function(timerId,delayMs,op){var _this=this;this.verifyNotFailed();// While not necessarily harmful, we currently don't expect to have multiple
// ops with the same timer id in the queue, so defensively reject them.
assert(!this.containsDelayedOperation(timerId),"Attempted to schedule multiple operations with timer id "+timerId+".");var delayedOp=DelayedOperation.createAndSchedule(this,timerId,delayMs,op,function(op){return _this.removeDelayedOperation(op);});this.delayedOperations.push(delayedOp);return delayedOp;};AsyncQueue.prototype.verifyNotFailed=function(){if(this.failure){fail('AsyncQueue is already failed: '+(this.failure.stack||this.failure.message));}};/**
* Verifies there's an operation currently in-progress on the AsyncQueue.
* Unfortunately we can't verify that the running code is in the promise chain
* of that operation, so this isn't a foolproof check, but it should be enough
* to catch some bugs.
*/AsyncQueue.prototype.verifyOperationInProgress=function(){assert(this.operationInProgress,'verifyOpInProgress() called when no op in progress on this queue.');};/**
* Waits until all currently queued tasks are finished executing. Delayed
* operations are not run.
*/AsyncQueue.prototype.drain=function(){return this.enqueue(function(){return Promise.resolve();});};/**
* For Tests: Determine if a delayed operation with a particular TimerId
* exists.
*/AsyncQueue.prototype.containsDelayedOperation=function(timerId){return this.delayedOperations.findIndex(function(op){return op.timerId===timerId;})>=0;};/**
* For Tests: Runs some or all delayed operations early.
*
* @param lastTimerId Delayed operations up to and including this TimerId will
* be drained. Throws if no such operation exists. Pass TimerId.All to run
* all delayed operations.
* @returns a Promise that resolves once all operations have been run.
*/AsyncQueue.prototype.runDelayedOperationsEarly=function(lastTimerId){var _this=this;// Note that draining may generate more delayed ops, so we do that first.
return this.drain().then(function(){assert(lastTimerId===TimerId.All||_this.containsDelayedOperation(lastTimerId),"Attempted to drain to missing operation "+lastTimerId);// Run ops in the same order they'd run if they ran naturally.
_this.delayedOperations.sort(function(a,b){return a.targetTimeMs-b.targetTimeMs;});for(var _i=0,_a=_this.delayedOperations;_i<_a.length;_i++){var op=_a[_i];op.skipDelay();if(lastTimerId!==TimerId.All&&op.timerId===lastTimerId){break;}}return _this.drain();});};/** Called once a DelayedOperation is run or canceled. */AsyncQueue.prototype.removeDelayedOperation=function(op){// NOTE: indexOf / slice are O(n), but delayedOperations is expected to be small.
var index=this.delayedOperations.indexOf(op);assert(index>=0,'Delayed operation not found.');this.delayedOperations.splice(index,1);};return AsyncQueue;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$6='ExponentialBackoff';/**
* A helper for running delayed tasks following an exponential backoff curve
* between attempts.
*
* Each delay is made up of a "base" delay which follows the exponential
* backoff curve, and a +/- 50% "jitter" that is calculated and added to the
* base delay. This prevents clients from accidentally synchronizing their
* delays causing spikes of load to the backend.
*/var ExponentialBackoff=/** @class */function(){function ExponentialBackoff(/**
* The AsyncQueue to run backoff operations on.
*/queue,/**
* The ID to use when scheduling backoff operations on the AsyncQueue.
*/timerId,/**
* The initial delay (used as the base delay on the first retry attempt).
* Note that jitter will still be applied, so the actual delay could be as
* little as 0.5*initialDelayMs.
*/initialDelayMs,/**
* The multiplier to use to determine the extended base delay after each
* attempt.
*/backoffFactor,/**
* The maximum base delay after which no further backoff is performed.
* Note that jitter will still be applied, so the actual delay could be as
* much as 1.5*maxDelayMs.
*/maxDelayMs){this.queue=queue;this.timerId=timerId;this.initialDelayMs=initialDelayMs;this.backoffFactor=backoffFactor;this.maxDelayMs=maxDelayMs;this.timerPromise=null;this.reset();}/**
* Resets the backoff delay.
*
* The very next backoffAndWait() will have no delay. If it is called again
* (i.e. due to an error), initialDelayMs (plus jitter) will be used, and
* subsequent ones will increase according to the backoffFactor.
*/ExponentialBackoff.prototype.reset=function(){this.currentBaseMs=0;};/**
* Resets the backoff delay to the maximum delay (e.g. for use after a
* RESOURCE_EXHAUSTED error).
*/ExponentialBackoff.prototype.resetToMax=function(){this.currentBaseMs=this.maxDelayMs;};/**
* Returns a promise that resolves after currentDelayMs, and increases the
* delay for any subsequent attempts. If there was a pending backoff operation
* already, it will be canceled.
*/ExponentialBackoff.prototype.backoffAndRun=function(op){// Cancel any pending backoff operation.
this.cancel();// First schedule using the current base (which may be 0 and should be
// honored as such).
var delayWithJitterMs=this.currentBaseMs+this.jitterDelayMs();if(this.currentBaseMs>0){debug(LOG_TAG$6,"Backing off for "+delayWithJitterMs+" ms "+("(base delay: "+this.currentBaseMs+" ms)"));}this.timerPromise=this.queue.enqueueAfterDelay(this.timerId,delayWithJitterMs,op);// Apply backoff factor to determine next delay and ensure it is within
// bounds.
this.currentBaseMs*=this.backoffFactor;if(this.currentBaseMs<this.initialDelayMs){this.currentBaseMs=this.initialDelayMs;}if(this.currentBaseMs>this.maxDelayMs){this.currentBaseMs=this.maxDelayMs;}};ExponentialBackoff.prototype.cancel=function(){if(this.timerPromise!==null){this.timerPromise.cancel();this.timerPromise=null;}};/** Returns a random value in the range [-currentBaseMs/2, currentBaseMs/2] */ExponentialBackoff.prototype.jitterDelayMs=function(){return(Math.random()-0.5)*this.currentBaseMs;};return ExponentialBackoff;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$7='PersistentStream';var PersistentStreamState;(function(PersistentStreamState){/**
* The streaming RPC is not running and there's no error condition.
* Calling `start` will start the stream immediately without backoff.
* While in this state isStarted will return false.
*/PersistentStreamState[PersistentStreamState["Initial"]=0]="Initial";/**
* The stream is starting, and is waiting for an auth token to attach to
* the initial request. While in this state, isStarted will return
* true but isOpen will return false.
*/PersistentStreamState[PersistentStreamState["Auth"]=1]="Auth";/**
* The streaming RPC is up and running. Requests and responses can flow
* freely. Both isStarted and isOpen will return true.
*/PersistentStreamState[PersistentStreamState["Open"]=2]="Open";/**
* The stream encountered an error. The next start attempt will back off.
* While in this state isStarted() will return false.
*
*/PersistentStreamState[PersistentStreamState["Error"]=3]="Error";/**
* An in-between state after an error where the stream is waiting before
* re-starting. After
* waiting is complete, the stream will try to open. While in this
* state isStarted() will return YES but isOpen will return false.
*/PersistentStreamState[PersistentStreamState["Backoff"]=4]="Backoff";/**
* The stream has been explicitly stopped; no further events will be emitted.
*/PersistentStreamState[PersistentStreamState["Stopped"]=5]="Stopped";})(PersistentStreamState||(PersistentStreamState={}));/**
* Initial backoff time in milliseconds after an error.
* Set to 1s according to https://cloud.google.com/apis/design/errors.
*/var BACKOFF_INITIAL_DELAY_MS=1000;/** Maximum backoff time in milliseconds */var BACKOFF_MAX_DELAY_MS=60*1000;var BACKOFF_FACTOR=1.5;/** The time a stream stays open after it is marked idle. */var IDLE_TIMEOUT_MS=60*1000;/**
* A PersistentStream is an abstract base class that represents a streaming RPC
* to the Firestore backend. It's built on top of the connections own support
* for streaming RPCs, and adds several critical features for our clients:
*
* - Exponential backoff on failure
* - Authentication via CredentialsProvider
* - Dispatching all callbacks into the shared worker queue
*
* Subclasses of PersistentStream implement serialization of models to and
* from the JSON representation of the protocol buffers for a specific
* streaming RPC.
*
* ## Starting and Stopping
*
* Streaming RPCs are stateful and need to be `start`ed before messages can
* be sent and received. The PersistentStream will call the onOpen function
* of the listener once the stream is ready to accept requests.
*
* Should a `start` fail, PersistentStream will call the registered
* onClose with a FirestoreError indicating what went wrong.
*
* A PersistentStream can be started and stopped repeatedly.
*
* Generic types:
* SendType: The type of the outgoing message of the underlying
* connection stream
* ReceiveType: The type of the incoming message of the underlying
* connection stream
* ListenerType: The type of the listener that will be used for callbacks
*/var PersistentStream=/** @class */function(){function PersistentStream(queue,connectionTimerId,idleTimerId,connection,credentialsProvider){this.queue=queue;this.idleTimerId=idleTimerId;this.connection=connection;this.credentialsProvider=credentialsProvider;this.inactivityTimerPromise=null;this.stream=null;this.listener=null;this.backoff=new ExponentialBackoff(queue,connectionTimerId,BACKOFF_INITIAL_DELAY_MS,BACKOFF_FACTOR,BACKOFF_MAX_DELAY_MS);this.state=PersistentStreamState.Initial;}/**
* Returns true if `start` has been called and no error has occurred. True
* indicates the stream is open or in the process of opening (which
* encompasses respecting backoff, getting auth tokens, and starting the
* actual RPC). Use `isOpen` to determine if the stream is open and ready for
* outbound requests.
*/PersistentStream.prototype.isStarted=function(){return this.state===PersistentStreamState.Backoff||this.state===PersistentStreamState.Auth||this.state===PersistentStreamState.Open;};/**
* Returns true if the underlying RPC is open (the openHandler has been
* called) and the stream is ready for outbound requests.
*/PersistentStream.prototype.isOpen=function(){return this.state===PersistentStreamState.Open;};/**
* Starts the RPC. Only allowed if isStarted returns false. The stream is
* not immediately ready for use: onOpen will be invoked when the RPC is ready
* for outbound requests, at which point isOpen will return true.
*
* When start returns, isStarted will return true.
*/PersistentStream.prototype.start=function(listener){if(this.state===PersistentStreamState.Error){this.performBackoff(listener);return;}assert(this.state===PersistentStreamState.Initial,'Already started');this.listener=listener;this.auth();};/**
* Stops the RPC. This call is idempotent and allowed regardless of the
* current isStarted state.
*
* When stop returns, isStarted and isOpen will both return false.
*/PersistentStream.prototype.stop=function(){if(this.isStarted()){this.close(PersistentStreamState.Stopped);}};/**
* After an error the stream will usually back off on the next attempt to
* start it. If the error warrants an immediate restart of the stream, the
* sender can use this to indicate that the receiver should not back off.
*
* Each error will call the onClose function. That function can decide to
* inhibit backoff if required.
*/PersistentStream.prototype.inhibitBackoff=function(){assert(!this.isStarted(),'Can only inhibit backoff in a stopped state');this.state=PersistentStreamState.Initial;this.backoff.reset();};/**
* Marks this stream as idle. If no further actions are performed on the
* stream for one minute, the stream will automatically close itself and
* notify the stream's onClose() handler with Status.OK. The stream will then
* be in a !isStarted() state, requiring the caller to start the stream again
* before further use.
*
* Only streams that are in state 'Open' can be marked idle, as all other
* states imply pending network operations.
*/PersistentStream.prototype.markIdle=function(){var _this=this;// Starts the idle time if we are in state 'Open' and are not yet already
// running a timer (in which case the previous idle timeout still applies).
if(this.isOpen()&&this.inactivityTimerPromise===null){this.inactivityTimerPromise=this.queue.enqueueAfterDelay(this.idleTimerId,IDLE_TIMEOUT_MS,function(){return _this.handleIdleCloseTimer();});}};/** Sends a message to the underlying stream. */PersistentStream.prototype.sendRequest=function(msg){this.cancelIdleCheck();this.stream.send(msg);};/** Called by the idle timer when the stream should close due to inactivity. */PersistentStream.prototype.handleIdleCloseTimer=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){if(this.isOpen()){// When timing out an idle stream there's no reason to force the stream into backoff when
// it restarts so set the stream state to Initial instead of Error.
return[2/*return*/,this.close(PersistentStreamState.Initial)];}return[2/*return*/];});});};/** Marks the stream as active again. */PersistentStream.prototype.cancelIdleCheck=function(){if(this.inactivityTimerPromise){this.inactivityTimerPromise.cancel();this.inactivityTimerPromise=null;}};/**
* Closes the stream and cleans up as necessary:
*
* * closes the underlying GRPC stream;
* * calls the onClose handler with the given 'error';
* * sets internal stream state to 'finalState';
* * adjusts the backoff timer based on the error
*
* A new stream can be opened by calling `start` unless `finalState` is set to
* `PersistentStreamState.Stopped`.
*
* @param finalState the intended state of the stream after closing.
* @param error the error the connection was closed with.
*/PersistentStream.prototype.close=function(finalState,error$$1){return tslib_1.__awaiter(this,void 0,void 0,function(){var listener;return tslib_1.__generator(this,function(_a){assert(finalState===PersistentStreamState.Error||isNullOrUndefined(error$$1),"Can't provide an error when not in an error state.");// The stream will be closed so we don't need our idle close timer anymore.
this.cancelIdleCheck();// Ensure we don't leave a pending backoff operation queued (in case close()
// was called while we were waiting to reconnect).
this.backoff.cancel();if(finalState!==PersistentStreamState.Error){// If this is an intentional close ensure we don't delay our next connection attempt.
this.backoff.reset();}else if(error$$1&&error$$1.code===Code.RESOURCE_EXHAUSTED){// Log the error. (Probably either 'quota exceeded' or 'max queue length reached'.)
error(error$$1.toString());error('Using maximum backoff delay to prevent overloading the backend.');this.backoff.resetToMax();}// Clean up the underlying stream because we are no longer interested in events.
if(this.stream!==null){this.tearDown();this.stream.close();this.stream=null;}// This state must be assigned before calling onClose() to allow the callback to
// inhibit backoff or otherwise manipulate the state in its non-started state.
this.state=finalState;listener=this.listener;// Clear the listener to avoid bleeding of events from the underlying streams.
this.listener=null;// If the caller explicitly requested a stream stop, don't notify them of a closing stream (it
// could trigger undesirable recovery logic, etc.).
if(finalState!==PersistentStreamState.Stopped){return[2/*return*/,listener.onClose(error$$1)];}return[2/*return*/];});});};/**
* Can be overridden to perform additional cleanup before the stream is closed.
* Calling super.tearDown() is not required.
*/PersistentStream.prototype.tearDown=function(){};PersistentStream.prototype.auth=function(){var _this=this;assert(this.state===PersistentStreamState.Initial,'Must be in initial state to auth');this.state=PersistentStreamState.Auth;this.credentialsProvider.getToken(/*forceRefresh=*/false).then(function(token){// Normally we'd have to schedule the callback on the AsyncQueue.
// However, the following calls are safe to be called outside the
// AsyncQueue since they don't chain asynchronous calls
_this.startStream(token);},function(error$$1){_this.queue.enqueue(function(){return tslib_1.__awaiter(_this,void 0,void 0,function(){var rpcError;return tslib_1.__generator(this,function(_a){if(this.state!==PersistentStreamState.Stopped){rpcError=new FirestoreError(Code.UNKNOWN,'Fetching auth token failed: '+error$$1.message);return[2/*return*/,this.handleStreamClose(rpcError)];}return[2/*return*/];});});});});};PersistentStream.prototype.startStream=function(token){var _this=this;if(this.state===PersistentStreamState.Stopped){// Stream can be stopped while waiting for authorization.
return;}assert(this.state===PersistentStreamState.Auth,'Trying to start stream in a non-auth state');// Helper function to dispatch to AsyncQueue and make sure that any
// close will seem instantaneous and events are prevented from being
// raised after the close call
var dispatchIfStillActive=function(stream,fn){_this.queue.enqueue(function(){return tslib_1.__awaiter(_this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){// Only raise events if the stream instance has not changed
if(this.stream===stream){return[2/*return*/,fn()];}return[2/*return*/];});});});};// Only start stream if listener has not changed
if(this.listener!==null){var currentStream_1=this.startRpc(token);this.stream=currentStream_1;this.stream.onOpen(function(){dispatchIfStillActive(currentStream_1,function(){assert(_this.state===PersistentStreamState.Auth,'Expected stream to be in state auth, but was '+_this.state);_this.state=PersistentStreamState.Open;return _this.listener.onOpen();});});this.stream.onClose(function(error$$1){dispatchIfStillActive(currentStream_1,function(){return _this.handleStreamClose(error$$1);});});this.stream.onMessage(function(msg){dispatchIfStillActive(currentStream_1,function(){return _this.onMessage(msg);});});}};PersistentStream.prototype.performBackoff=function(listener){var _this=this;assert(this.state===PersistentStreamState.Error,'Should only perform backoff in an error case');this.state=PersistentStreamState.Backoff;this.backoff.backoffAndRun(function(){return tslib_1.__awaiter(_this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){if(this.state===PersistentStreamState.Stopped){// We should have canceled the backoff timer when the stream was
// closed, but just in case we make this a no-op.
return[2/*return*/];}this.state=PersistentStreamState.Initial;this.start(listener);assert(this.isStarted(),'PersistentStream should have started');return[2/*return*/];});});});};PersistentStream.prototype.handleStreamClose=function(error$$1){assert(this.isStarted(),"Can't handle server close on non-started stream");debug(LOG_TAG$7,"close with error: "+error$$1);this.stream=null;// In theory the stream could close cleanly, however, in our current model
// we never expect this to happen because if we stop a stream ourselves,
// this callback will never be called. To prevent cases where we retry
// without a backoff accidentally, we set the stream to error in all cases.
return this.close(PersistentStreamState.Error,error$$1);};return PersistentStream;}();/**
* A PersistentStream that implements the Listen RPC.
*
* Once the Listen stream has called the openHandler, any number of listen and
* unlisten calls calls can be sent to control what changes will be sent from
* the server for ListenResponses.
*/var PersistentListenStream=/** @class */function(_super){tslib_1.__extends(PersistentListenStream,_super);function PersistentListenStream(queue,connection,credentials,serializer){var _this=_super.call(this,queue,TimerId.ListenStreamConnectionBackoff,TimerId.ListenStreamIdle,connection,credentials)||this;_this.serializer=serializer;return _this;}PersistentListenStream.prototype.startRpc=function(token){return this.connection.openStream('Listen',token);};PersistentListenStream.prototype.onMessage=function(watchChangeProto){// A successful response means the stream is healthy
this.backoff.reset();var watchChange=this.serializer.fromWatchChange(watchChangeProto);var snapshot=this.serializer.versionFromListenResponse(watchChangeProto);return this.listener.onWatchChange(watchChange,snapshot);};/**
* Registers interest in the results of the given query. If the query
* includes a resumeToken it will be included in the request. Results that
* affect the query will be streamed back as WatchChange messages that
* reference the targetId.
*/PersistentListenStream.prototype.watch=function(queryData){var request={};request.database=this.serializer.encodedDatabaseId;request.addTarget=this.serializer.toTarget(queryData);var labels=this.serializer.toListenRequestLabels(queryData);if(labels){request.labels=labels;}this.sendRequest(request);};/**
* Unregisters interest in the results of the query associated with the
* given targetId.
*/PersistentListenStream.prototype.unwatch=function(targetId){var request={};request.database=this.serializer.encodedDatabaseId;request.removeTarget=targetId;this.sendRequest(request);};return PersistentListenStream;}(PersistentStream);/**
* A Stream that implements the Write RPC.
*
* The Write RPC requires the caller to maintain special streamToken
* state in between calls, to help the server understand which responses the
* client has processed by the time the next request is made. Every response
* will contain a streamToken; this value must be passed to the next
* request.
*
* After calling start() on this stream, the next request must be a handshake,
* containing whatever streamToken is on hand. Once a response to this
* request is received, all pending mutations may be submitted. When
* submitting multiple batches of mutations at the same time, it's
* okay to use the same streamToken for the calls to writeMutations.
*
* TODO(b/33271235): Use proto types
*/var PersistentWriteStream=/** @class */function(_super){tslib_1.__extends(PersistentWriteStream,_super);function PersistentWriteStream(queue,connection,credentials,serializer){var _this=_super.call(this,queue,TimerId.WriteStreamConnectionBackoff,TimerId.WriteStreamIdle,connection,credentials)||this;_this.serializer=serializer;_this.handshakeComplete_=false;return _this;}Object.defineProperty(PersistentWriteStream.prototype,"handshakeComplete",{/**
* Tracks whether or not a handshake has been successfully exchanged and
* the stream is ready to accept mutations.
*/get:function(){return this.handshakeComplete_;},enumerable:true,configurable:true});// Override of PersistentStream.start
PersistentWriteStream.prototype.start=function(listener){this.handshakeComplete_=false;_super.prototype.start.call(this,listener);};PersistentWriteStream.prototype.tearDown=function(){if(this.handshakeComplete_){this.writeMutations([]);}};PersistentWriteStream.prototype.startRpc=function(token){return this.connection.openStream('Write',token);};PersistentWriteStream.prototype.onMessage=function(responseProto){// Always capture the last stream token.
assert(!!responseProto.streamToken,'Got a write response without a stream token');this.lastStreamToken=responseProto.streamToken;if(!this.handshakeComplete_){// The first response is always the handshake response
assert(!responseProto.writeResults||responseProto.writeResults.length===0,'Got mutation results for handshake');this.handshakeComplete_=true;return this.listener.onHandshakeComplete();}else{// A successful first write response means the stream is healthy,
// Note, that we could consider a successful handshake healthy, however,
// the write itself might be causing an error we want to back off from.
this.backoff.reset();var results=this.serializer.fromWriteResults(responseProto.writeResults);var commitVersion=this.serializer.fromVersion(responseProto.commitTime);return this.listener.onMutationResult(commitVersion,results);}};/**
* Sends an initial streamToken to the server, performing the handshake
* required to make the StreamingWrite RPC work. Subsequent
* calls should wait until onHandshakeComplete was called.
*/PersistentWriteStream.prototype.writeHandshake=function(){assert(this.isOpen(),'Writing handshake requires an opened stream');assert(!this.handshakeComplete_,'Handshake already completed');// TODO(dimond): Support stream resumption. We intentionally do not set the
// stream token on the handshake, ignoring any stream token we might have.
var request={};request.database=this.serializer.encodedDatabaseId;this.sendRequest(request);};/** Sends a group of mutations to the Firestore backend to apply. */PersistentWriteStream.prototype.writeMutations=function(mutations){var _this=this;assert(this.isOpen(),'Writing mutations requires an opened stream');assert(this.handshakeComplete_,'Handshake must be complete before writing mutations');assert(this.lastStreamToken.length>0,'Trying to write mutation without a token');var request={// Protos are typed with string, but we support UInt8Array on Node
// tslint:disable-next-line:no-any
streamToken:this.lastStreamToken,writes:mutations.map(function(mutation){return _this.serializer.toMutation(mutation);})};this.sendRequest(request);};return PersistentWriteStream;}(PersistentStream);/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Datastore is a wrapper around the external Google Cloud Datastore grpc API,
* which provides an interface that is more convenient for the rest of the
* client SDK architecture to consume.
*/var Datastore=/** @class */function(){function Datastore(queue,connection,credentials,serializer){this.queue=queue;this.connection=connection;this.credentials=credentials;this.serializer=serializer;}Datastore.prototype.newPersistentWriteStream=function(){return new PersistentWriteStream(this.queue,this.connection,this.credentials,this.serializer);};Datastore.prototype.newPersistentWatchStream=function(){return new PersistentListenStream(this.queue,this.connection,this.credentials,this.serializer);};Datastore.prototype.commit=function(mutations){var _this=this;var params={database:this.serializer.encodedDatabaseId,writes:mutations.map(function(m){return _this.serializer.toMutation(m);})};return this.invokeRPC('Commit',params).then(function(response){return _this.serializer.fromWriteResults(response.writeResults);});};Datastore.prototype.lookup=function(keys){var _this=this;var params={database:this.serializer.encodedDatabaseId,documents:keys.map(function(k){return _this.serializer.toName(k);})};return this.invokeStreamingRPC('BatchGetDocuments',params).then(function(response){var docs=maybeDocumentMap();response.forEach(function(proto){var doc=_this.serializer.fromMaybeDocument(proto);docs=docs.insert(doc.key,doc);});var result=[];keys.forEach(function(key){var doc=docs.get(key);assert(!!doc,'Missing entity in write response for '+key);result.push(doc);});return result;});};/** Gets an auth token and invokes the provided RPC. */Datastore.prototype.invokeRPC=function(rpcName,request){var _this=this;// TODO(mikelehen): Retry (with backoff) on token failures?
return this.credentials.getToken(/*forceRefresh=*/false).then(function(token){return _this.connection.invokeRPC(rpcName,request,token);});};/** Gets an auth token and invokes the provided RPC with streamed results. */Datastore.prototype.invokeStreamingRPC=function(rpcName,request){var _this=this;// TODO(mikelehen): Retry (with backoff) on token failures?
return this.credentials.getToken(/*forceRefresh=*/false).then(function(token){return _this.connection.invokeStreamingRPC(rpcName,request,token);});};return Datastore;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Internal transaction object responsible for accumulating the mutations to
* perform and the base versions for any documents read.
*/var Transaction=/** @class */function(){function Transaction(datastore){this.datastore=datastore;// The version of each document that was read during this transaction.
this.readVersions=documentVersionMap();this.mutations=[];this.committed=false;}Transaction.prototype.recordVersion=function(doc){var docVersion=doc.version;if(doc instanceof NoDocument){// For deleted docs, we must use baseVersion 0 when we overwrite them.
docVersion=SnapshotVersion.forDeletedDoc();}var existingVersion=this.readVersions.get(doc.key);if(existingVersion!==null){if(!docVersion.isEqual(existingVersion)){// This transaction will fail no matter what.
throw new FirestoreError(Code.ABORTED,'Document version changed between two reads.');}}else{this.readVersions=this.readVersions.insert(doc.key,docVersion);}};Transaction.prototype.lookup=function(keys){var _this=this;if(this.committed){return Promise.reject('Transaction has already completed.');}if(this.mutations.length>0){return Promise.reject('Transactions lookups are invalid after writes.');}return this.datastore.lookup(keys).then(function(docs){docs.forEach(function(doc){return _this.recordVersion(doc);});return docs;});};Transaction.prototype.write=function(mutations){if(this.committed){throw new FirestoreError(Code.FAILED_PRECONDITION,'Transaction has already completed.');}this.mutations=this.mutations.concat(mutations);};/**
* Returns the version of this document when it was read in this transaction,
* as a precondition, or no precondition if it was not read.
*/Transaction.prototype.precondition=function(key){var version=this.readVersions.get(key);if(version){return Precondition.updateTime(version);}else{return Precondition.NONE;}};/**
* Returns the precondition for a document if the operation is an update.
*/Transaction.prototype.preconditionForUpdate=function(key){var version=this.readVersions.get(key);if(version&&version.isEqual(SnapshotVersion.forDeletedDoc())){// The document doesn't exist, so fail the transaction.
throw new FirestoreError(Code.FAILED_PRECONDITION,"Can't update a document that doesn't exist.");}else if(version){// Document exists, base precondition on document update time.
return Precondition.updateTime(version);}else{// Document was not read, so we just use the preconditions for a blind
// update.
return Precondition.exists(true);}};Transaction.prototype.set=function(key,data){this.write(data.toMutations(key,this.precondition(key)));};Transaction.prototype.update=function(key,data){this.write(data.toMutations(key,this.preconditionForUpdate(key)));};Transaction.prototype.delete=function(key){this.write([new DeleteMutation(key,this.precondition(key))]);// Since the delete will be applied before all following writes, we need to
// ensure that the precondition for the next write will be exists: false.
this.readVersions=this.readVersions.insert(key,SnapshotVersion.forDeletedDoc());};Transaction.prototype.commit=function(){var _this=this;var unwritten=this.readVersions;// For each mutation, note that the doc was written.
this.mutations.forEach(function(mutation){unwritten=unwritten.remove(mutation.key);});if(!unwritten.isEmpty()){return Promise.reject(Error('Every document read in a transaction must also be written.'));}return this.datastore.commit(this.mutations).then(function(){_this.committed=true;});};return Transaction;}();/**
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$8='OnlineStateTracker';// To deal with transient failures, we allow multiple stream attempts before
// giving up and transitioning from OnlineState.Unknown to Offline.
var MAX_WATCH_STREAM_FAILURES=2;// To deal with stream attempts that don't succeed or fail in a timely manner,
// we have a timeout for OnlineState to reach Online or Offline.
// If the timeout is reached, we transition to Offline rather than waiting
// indefinitely.
var ONLINE_STATE_TIMEOUT_MS=10*1000;/**
* A component used by the RemoteStore to track the OnlineState (that is,
* whether or not the client as a whole should be considered to be online or
* offline), implementing the appropriate heuristics.
*
* In particular, when the client is trying to connect to the backend, we
* allow up to MAX_WATCH_STREAM_FAILURES within ONLINE_STATE_TIMEOUT_MS for
* a connection to succeed. If we have too many failures or the timeout elapses,
* then we set the OnlineState to Offline, and the client will behave as if
* it is offline (get()s will return cached data, etc.).
*/var OnlineStateTracker=/** @class */function(){function OnlineStateTracker(asyncQueue,onlineStateHandler){this.asyncQueue=asyncQueue;this.onlineStateHandler=onlineStateHandler;/** The current OnlineState. */this.state=OnlineState.Unknown;/**
* A count of consecutive failures to open the stream. If it reaches the
* maximum defined by MAX_WATCH_STREAM_FAILURES, we'll set the OnlineState to
* Offline.
*/this.watchStreamFailures=0;/**
* A timer that elapses after ONLINE_STATE_TIMEOUT_MS, at which point we
* transition from OnlineState.Unknown to OnlineState.Offline without waiting
* for the stream to actually fail (MAX_WATCH_STREAM_FAILURES times).
*/this.onlineStateTimer=null;/**
* Whether the client should log a warning message if it fails to connect to
* the backend (initially true, cleared after a successful stream, or if we've
* logged the message already).
*/this.shouldWarnClientIsOffline=true;}/**
* Called by RemoteStore when a watch stream is started (including on each
* backoff attempt).
*
* If this is the first attempt, it sets the OnlineState to Unknown and starts
* the onlineStateTimer.
*/OnlineStateTracker.prototype.handleWatchStreamStart=function(){var _this=this;if(this.watchStreamFailures===0){this.setAndBroadcast(OnlineState.Unknown);assert(this.onlineStateTimer===null,"onlineStateTimer shouldn't be started yet");this.onlineStateTimer=this.asyncQueue.enqueueAfterDelay(TimerId.OnlineStateTimeout,ONLINE_STATE_TIMEOUT_MS,function(){_this.onlineStateTimer=null;assert(_this.state===OnlineState.Unknown,'Timer should be canceled if we transitioned to a different state.');_this.logClientOfflineWarningIfNecessary("Backend didn't respond within "+ONLINE_STATE_TIMEOUT_MS/1000+" "+"seconds.");_this.setAndBroadcast(OnlineState.Offline);// NOTE: handleWatchStreamFailure() will continue to increment
// watchStreamFailures even though we are already marked Offline,
// but this is non-harmful.
return Promise.resolve();});}};/**
* Updates our OnlineState as appropriate after the watch stream reports a
* failure. The first failure moves us to the 'Unknown' state. We then may
* allow multiple failures (based on MAX_WATCH_STREAM_FAILURES) before we
* actually transition to the 'Offline' state.
*/OnlineStateTracker.prototype.handleWatchStreamFailure=function(error$$1){if(this.state===OnlineState.Online){this.setAndBroadcast(OnlineState.Unknown);// To get to OnlineState.Online, set() must have been called which would
// have reset our heuristics.
assert(this.watchStreamFailures===0,'watchStreamFailures must be 0');assert(this.onlineStateTimer===null,'onlineStateTimer must be null');}else{this.watchStreamFailures++;if(this.watchStreamFailures>=MAX_WATCH_STREAM_FAILURES){this.clearOnlineStateTimer();this.logClientOfflineWarningIfNecessary("Connection failed "+MAX_WATCH_STREAM_FAILURES+" "+("times. Most recent error: "+error$$1.toString()));this.setAndBroadcast(OnlineState.Offline);}}};/**
* Explicitly sets the OnlineState to the specified state.
*
* Note that this resets our timers / failure counters, etc. used by our
* Offline heuristics, so must not be used in place of
* handleWatchStreamStart() and handleWatchStreamFailure().
*/OnlineStateTracker.prototype.set=function(newState){this.clearOnlineStateTimer();this.watchStreamFailures=0;if(newState===OnlineState.Online){// We've connected to watch at least once. Don't warn the developer
// about being offline going forward.
this.shouldWarnClientIsOffline=false;}this.setAndBroadcast(newState);};OnlineStateTracker.prototype.setAndBroadcast=function(newState){if(newState!==this.state){this.state=newState;this.onlineStateHandler(newState);}};OnlineStateTracker.prototype.logClientOfflineWarningIfNecessary=function(details){var message="Could not reach Cloud Firestore backend. "+details+"\n"+"This typically indicates that your device does not have a healthy "+"Internet connection at the moment. The client will operate in offline "+"mode until it is able to successfully connect to the backend.";if(this.shouldWarnClientIsOffline){error(message);this.shouldWarnClientIsOffline=false;}else{debug(LOG_TAG$8,message);}};OnlineStateTracker.prototype.clearOnlineStateTimer=function(){if(this.onlineStateTimer!==null){this.onlineStateTimer.cancel();this.onlineStateTimer=null;}};return OnlineStateTracker;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$9='RemoteStore';// TODO(b/35853402): Negotiate this with the stream.
var MAX_PENDING_WRITES=10;/**
* RemoteStore - An interface to remotely stored data, basically providing a
* wrapper around the Datastore that is more reliable for the rest of the
* system.
*
* RemoteStore is responsible for maintaining the connection to the server.
* - maintaining a list of active listens.
* - reconnecting when the connection is dropped.
* - resuming all the active listens on reconnect.
*
* RemoteStore handles all incoming events from the Datastore.
* - listening to the watch stream and repackaging the events as RemoteEvents
* - notifying SyncEngine of any changes to the active listens.
*
* RemoteStore takes writes from other components and handles them reliably.
* - pulling pending mutations from LocalStore and sending them to Datastore.
* - retrying mutations that failed because of network problems.
* - acking mutations to the SyncEngine once they are accepted or rejected.
*/var RemoteStore=/** @class */function(){function RemoteStore(/**
* The local store, used to fill the write pipeline with outbound
* mutations and resolve existence filter mismatches.
*/localStore,/** The client-side proxy for interacting with the backend. */datastore,asyncQueue,onlineStateHandler){this.localStore=localStore;this.datastore=datastore;this.pendingWrites=[];this.lastBatchSeen=BATCHID_UNKNOWN;/**
* A mapping of watched targets that the client cares about tracking and the
* user has explicitly called a 'listen' for this target.
*
* These targets may or may not have been sent to or acknowledged by the
* server. On re-establishing the listen stream, these targets should be sent
* to the server. The targets removed with unlistens are removed eagerly
* without waiting for confirmation from the listen stream.
*/this.listenTargets={};/**
* A mapping of targetId to pending acks needed.
*
* If a targetId is present in this map, then we're waiting for watch to
* acknowledge a removal or addition of the target. If a target is not in this
* mapping, and it's in the listenTargets map, then we consider the target to
* be active.
*
* We increment the count here every time we issue a request over the stream
* to watch or unwatch. We then decrement the count every time we get a target
* added or target removed message from the server. Once the count is equal to
* 0 we know that the client and server are in the same state (once this state
* is reached the targetId is removed from the map to free the memory).
*/this.pendingTargetResponses={};this.accumulatedWatchChanges=[];this.watchStream=null;this.writeStream=null;this.onlineStateTracker=new OnlineStateTracker(asyncQueue,onlineStateHandler);}/**
* Starts up the remote store, creating streams, restoring state from
* LocalStore, etc.
*/RemoteStore.prototype.start=function(){return this.enableNetwork();};RemoteStore.prototype.isNetworkEnabled=function(){assert(this.watchStream==null===(this.writeStream==null),'WatchStream and WriteStream should both be null or non-null');return this.watchStream!=null;};/** Re-enables the network. Idempotent. */RemoteStore.prototype.enableNetwork=function(){var _this=this;if(this.isNetworkEnabled()){return Promise.resolve();}// Create new streams (but note they're not started yet).
this.watchStream=this.datastore.newPersistentWatchStream();this.writeStream=this.datastore.newPersistentWriteStream();// Load any saved stream token from persistent storage
return this.localStore.getLastStreamToken().then(function(token){_this.writeStream.lastStreamToken=token;if(_this.shouldStartWatchStream()){_this.startWatchStream();}else{_this.onlineStateTracker.set(OnlineState.Unknown);}return _this.fillWritePipeline();// This may start the writeStream.
});};/**
* Temporarily disables the network. The network can be re-enabled using
* enableNetwork().
*/RemoteStore.prototype.disableNetwork=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){this.disableNetworkInternal();// Set the OnlineState to Offline so get()s return from cache, etc.
this.onlineStateTracker.set(OnlineState.Offline);return[2/*return*/];});});};/**
* Disables the network, if it is currently enabled.
*/RemoteStore.prototype.disableNetworkInternal=function(){if(this.isNetworkEnabled()){// NOTE: We're guaranteed not to get any further events from these streams (not even a close
// event).
this.watchStream.stop();this.writeStream.stop();this.cleanUpWatchStreamState();this.cleanUpWriteStreamState();this.writeStream=null;this.watchStream=null;}};RemoteStore.prototype.shutdown=function(){debug(LOG_TAG$9,'RemoteStore shutting down.');this.disableNetworkInternal();// Set the OnlineState to Unknown (rather than Offline) to avoid potentially
// triggering spurious listener events with cached data, etc.
this.onlineStateTracker.set(OnlineState.Unknown);return Promise.resolve();};/** Starts new listen for the given query. Uses resume token if provided */RemoteStore.prototype.listen=function(queryData){assert(!contains(this.listenTargets,queryData.targetId),'listen called with duplicate targetId!');// Mark this as something the client is currently listening for.
this.listenTargets[queryData.targetId]=queryData;if(this.shouldStartWatchStream()){// The listen will be sent in onWatchStreamOpen
this.startWatchStream();}else if(this.isNetworkEnabled()&&this.watchStream.isOpen()){this.sendWatchRequest(queryData);}};/** Removes the listen from server */RemoteStore.prototype.unlisten=function(targetId){assert(contains(this.listenTargets,targetId),'unlisten called without assigned target ID!');delete this.listenTargets[targetId];if(this.isNetworkEnabled()&&this.watchStream.isOpen()){this.sendUnwatchRequest(targetId);if(isEmpty(this.listenTargets)){this.watchStream.markIdle();}}};/**
* We need to increment the the expected number of pending responses we're due
* from watch so we wait for the ack to process any messages from this target.
*/RemoteStore.prototype.sendWatchRequest=function(queryData){this.recordPendingTargetRequest(queryData.targetId);this.watchStream.watch(queryData);};/**
* We need to increment the expected number of pending responses we're due
* from watch so we wait for the removal on the server before we process any
* messages from this target.
*/RemoteStore.prototype.sendUnwatchRequest=function(targetId){this.recordPendingTargetRequest(targetId);this.watchStream.unwatch(targetId);};/**
* Increment the mapping of how many acks are needed from watch before we can
* consider the server to be 'in-sync' with the client's active targets.
*/RemoteStore.prototype.recordPendingTargetRequest=function(targetId){// For each request we get we need to record we need a response for it.
this.pendingTargetResponses[targetId]=(this.pendingTargetResponses[targetId]||0)+1;};RemoteStore.prototype.startWatchStream=function(){assert(this.shouldStartWatchStream(),'startWriteStream() called when shouldStartWatchStream() is false.');this.watchStream.start({onOpen:this.onWatchStreamOpen.bind(this),onClose:this.onWatchStreamClose.bind(this),onWatchChange:this.onWatchStreamChange.bind(this)});this.onlineStateTracker.handleWatchStreamStart();};/**
* Returns whether the watch stream should be started because it's necessary
* and has not yet been started.
*/RemoteStore.prototype.shouldStartWatchStream=function(){return this.isNetworkEnabled()&&!this.watchStream.isStarted()&&!isEmpty(this.listenTargets);};RemoteStore.prototype.cleanUpWatchStreamState=function(){// If the connection is closed then we'll never get a snapshot version for
// the accumulated changes and so we'll never be able to complete the batch.
// When we start up again the server is going to resend these changes
// anyway, so just toss the accumulated state.
this.accumulatedWatchChanges=[];this.pendingTargetResponses={};};RemoteStore.prototype.onWatchStreamOpen=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){var _this=this;return tslib_1.__generator(this,function(_a){// TODO(b/35852690): close the stream again (with some timeout?) if no watch
// targets are active
forEachNumber(this.listenTargets,function(targetId,queryData){_this.sendWatchRequest(queryData);});return[2/*return*/];});});};RemoteStore.prototype.onWatchStreamClose=function(error$$1){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){assert(this.isNetworkEnabled(),'onWatchStreamClose() should only be called when the network is enabled');this.cleanUpWatchStreamState();// If we still need the watch stream, retry the connection.
if(this.shouldStartWatchStream()){// There should generally be an error if the watch stream was closed when
// it's still needed, but it's not quite worth asserting.
if(error$$1){this.onlineStateTracker.handleWatchStreamFailure(error$$1);}this.startWatchStream();}else{// No need to restart watch stream because there are no active targets.
// The online state is set to unknown because there is no active attempt
// at establishing a connection
this.onlineStateTracker.set(OnlineState.Unknown);}return[2/*return*/];});});};RemoteStore.prototype.onWatchStreamChange=function(watchChange,snapshotVersion){return tslib_1.__awaiter(this,void 0,void 0,function(){var changes;return tslib_1.__generator(this,function(_a){// Mark the client as online since we got a message from the server
this.onlineStateTracker.set(OnlineState.Online);if(watchChange instanceof WatchTargetChange&&watchChange.state===WatchTargetChangeState.Removed&&watchChange.cause){// There was an error on a target, don't wait for a consistent snapshot
// to raise events
return[2/*return*/,this.handleTargetError(watchChange)];}// Accumulate watch changes but don't process them if there's no
// snapshotVersion or it's older than a previous snapshot we've processed
// (can happen after we resume a target using a resume token).
this.accumulatedWatchChanges.push(watchChange);if(!snapshotVersion.isEqual(SnapshotVersion.MIN)&&snapshotVersion.compareTo(this.localStore.getLastRemoteSnapshotVersion())>=0){changes=this.accumulatedWatchChanges;this.accumulatedWatchChanges=[];return[2/*return*/,this.handleWatchChangeBatch(snapshotVersion,changes)];}return[2/*return*/];});});};/**
* Takes a batch of changes from the Datastore, repackages them as a
* RemoteEvent, and passes that on to the listener, which is typically the
* SyncEngine.
*/RemoteStore.prototype.handleWatchChangeBatch=function(snapshotVersion,changes){var _this=this;var aggregator=new WatchChangeAggregator(snapshotVersion,this.listenTargets,this.pendingTargetResponses);aggregator.addChanges(changes);var remoteEvent=aggregator.createRemoteEvent();// Get the new response counts from the aggregator
this.pendingTargetResponses=aggregator.pendingTargetResponses;var promises=[];// Handle existence filters and existence filter mismatches.
forEachNumber(aggregator.existenceFilters,function(targetId,filter){var queryData=_this.listenTargets[targetId];if(!queryData){// A watched target might have been removed already.
return;}var query=queryData.query;if(query.isDocumentQuery()){if(filter.count===0){// The existence filter told us the document does not exist.
// We need to deduce that this document does not exist and apply
// a deleted document to our updates. Without applying a deleted
// document there might be another query that will raise this
// document as part of a snapshot until it is resolved,
// essentially exposing inconsistency between queries.
var key=new DocumentKey(query.path);var deletedDoc=new NoDocument(key,snapshotVersion);remoteEvent.addDocumentUpdate(deletedDoc);}else{assert(filter.count===1,'Single document existence filter with count: '+filter.count);}}else{// Not a document query.
var promise=_this.localStore.remoteDocumentKeys(targetId).then(function(trackedRemote){if(remoteEvent.targetChanges[targetId]){var mapping=remoteEvent.targetChanges[targetId].mapping;if(mapping!==null){if(mapping instanceof UpdateMapping){trackedRemote=mapping.applyToKeySet(trackedRemote);}else{assert(mapping instanceof ResetMapping,'Expected either reset or update mapping but got something else: '+mapping);trackedRemote=mapping.documents;}}}if(trackedRemote.size!==filter.count){// Existence filter mismatch, resetting mapping.
// Make sure the mismatch is exposed in the remote event.
remoteEvent.handleExistenceFilterMismatch(targetId);// Clear the resume token for the query, since we're in a
// known mismatch state.
var newQueryData=new QueryData(query,targetId,queryData.purpose);_this.listenTargets[targetId]=newQueryData;// Cause a hard reset by unwatching and rewatching
// immediately, but deliberately don't send a resume token
// so that we get a full update.
// Make sure we expect that this acks are going to happen.
_this.sendUnwatchRequest(targetId);// Mark the query we send as being on behalf of an existence
// filter mismatch, but don't actually retain that in
// listenTargets. This ensures that we flag the first
// re-listen this way without impacting future listens of
// this target (that might happen e.g. on reconnect).
var requestQueryData=new QueryData(query,targetId,QueryPurpose.ExistenceFilterMismatch);_this.sendWatchRequest(requestQueryData);}});promises.push(promise);}});return Promise.all(promises).then(function(){// Update in-memory resume tokens. LocalStore will update the
// persistent view of these when applying the completed RemoteEvent.
forEachNumber(remoteEvent.targetChanges,function(targetId,change){if(change.resumeToken.length>0){var queryData=_this.listenTargets[targetId];// A watched target might have been removed already.
if(queryData){_this.listenTargets[targetId]=queryData.update({resumeToken:change.resumeToken,snapshotVersion:change.snapshotVersion});}}});// Finally handle remote event
return _this.syncEngine.applyRemoteEvent(remoteEvent);});};/** Handles an error on a target */RemoteStore.prototype.handleTargetError=function(watchChange){var _this=this;assert(!!watchChange.cause,'Handling target error without a cause');var error$$1=watchChange.cause;var promiseChain=Promise.resolve();watchChange.targetIds.forEach(function(targetId){promiseChain=promiseChain.then(function(){return tslib_1.__awaiter(_this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){// A watched target might have been removed already.
if(contains(this.listenTargets,targetId)){delete this.listenTargets[targetId];return[2/*return*/,this.syncEngine.rejectListen(targetId,error$$1)];}return[2/*return*/];});});});});return promiseChain;};RemoteStore.prototype.cleanUpWriteStreamState=function(){this.lastBatchSeen=BATCHID_UNKNOWN;debug(LOG_TAG$9,'Stopping write stream with '+this.pendingWrites.length+' pending writes');this.pendingWrites=[];};/**
* Notifies that there are new mutations to process in the queue. This is
* typically called by SyncEngine after it has sent mutations to LocalStore.
*/RemoteStore.prototype.fillWritePipeline=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){var _this=this;return tslib_1.__generator(this,function(_a){if(this.canWriteMutations()){return[2/*return*/,this.localStore.nextMutationBatch(this.lastBatchSeen).then(function(batch){if(batch===null){if(_this.pendingWrites.length===0){_this.writeStream.markIdle();}}else{_this.commit(batch);return _this.fillWritePipeline();}})];}return[2/*return*/];});});};/**
* Returns true if the backend can accept additional write requests.
*
* When sending mutations to the write stream (e.g. in fillWritePipeline),
* call this method first to check if more mutations can be sent.
*
* Currently the only thing that can prevent the backend from accepting
* write requests is if there are too many requests already outstanding. As
* writes complete the backend will be able to accept more.
*/RemoteStore.prototype.canWriteMutations=function(){return this.isNetworkEnabled()&&this.pendingWrites.length<MAX_PENDING_WRITES;};// For testing
RemoteStore.prototype.outstandingWrites=function(){return this.pendingWrites.length;};/**
* Given mutations to commit, actually commits them to the Datastore. Note
* that this does *not* return a Promise specifically because the AsyncQueue
* should not block operations for this.
*/RemoteStore.prototype.commit=function(batch){assert(this.canWriteMutations(),"commit called when batches can't be written");this.lastBatchSeen=batch.batchId;this.pendingWrites.push(batch);if(this.shouldStartWriteStream()){this.startWriteStream();}else if(this.isNetworkEnabled()&&this.writeStream.handshakeComplete){this.writeStream.writeMutations(batch.mutations);}};RemoteStore.prototype.shouldStartWriteStream=function(){return this.isNetworkEnabled()&&!this.writeStream.isStarted()&&this.pendingWrites.length>0;};RemoteStore.prototype.startWriteStream=function(){assert(this.shouldStartWriteStream(),'startWriteStream() called when shouldStartWriteStream() is false.');this.writeStream.start({onOpen:this.onWriteStreamOpen.bind(this),onClose:this.onWriteStreamClose.bind(this),onHandshakeComplete:this.onWriteHandshakeComplete.bind(this),onMutationResult:this.onMutationResult.bind(this)});};RemoteStore.prototype.onWriteStreamOpen=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){this.writeStream.writeHandshake();return[2/*return*/];});});};RemoteStore.prototype.onWriteHandshakeComplete=function(){var _this=this;// Record the stream token.
return this.localStore.setLastStreamToken(this.writeStream.lastStreamToken).then(function(){// Drain any pending writes.
//
// Note that at this point pendingWrites contains mutations that
// have already been accepted by fillWritePipeline/commitBatch. If
// the pipeline is full, canWriteMutations will be false, despite
// the fact that we actually need to send mutations over.
//
// This also means that this method indirectly respects the limits
// imposed by canWriteMutations since writes can't be added to the
// pendingWrites array when canWriteMutations is false. If the
// limits imposed by canWriteMutations actually protect us from
// DOSing ourselves then those limits won't be exceeded here and
// we'll continue to make progress.
for(var _i=0,_a=_this.pendingWrites;_i<_a.length;_i++){var batch=_a[_i];_this.writeStream.writeMutations(batch.mutations);}});};RemoteStore.prototype.onMutationResult=function(commitVersion,results){var _this=this;// This is a response to a write containing mutations and should be
// correlated to the first pending write.
assert(this.pendingWrites.length>0,'Got result for empty pending writes');var batch=this.pendingWrites.shift();var success=MutationBatchResult.from(batch,commitVersion,results,this.writeStream.lastStreamToken);return this.syncEngine.applySuccessfulWrite(success).then(function(){// It's possible that with the completion of this mutation another
// slot has freed up.
return _this.fillWritePipeline();});};RemoteStore.prototype.onWriteStreamClose=function(error$$1){return tslib_1.__awaiter(this,void 0,void 0,function(){var _this=this;var errorHandling;return tslib_1.__generator(this,function(_a){assert(this.isNetworkEnabled(),'onWriteStreamClose() should only be called when the network is enabled');// If the write stream closed due to an error, invoke the error callbacks if
// there are pending writes.
if(error$$1&&this.pendingWrites.length>0){assert(!!error$$1,'We have pending writes, but the write stream closed without an error');errorHandling=void 0;if(this.writeStream.handshakeComplete){// This error affects the actual write.
errorHandling=this.handleWriteError(error$$1);}else{// If there was an error before the handshake has finished, it's
// possible that the server is unable to process the stream token
// we're sending. (Perhaps it's too old?)
errorHandling=this.handleHandshakeError(error$$1);}return[2/*return*/,errorHandling.then(function(){// The write stream might have been started by refilling the write
// pipeline for failed writes
if(_this.shouldStartWriteStream()){_this.startWriteStream();}})];}return[2/*return*/];});});};RemoteStore.prototype.handleHandshakeError=function(error$$1){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){// Reset the token if it's a permanent error or the error code is
// ABORTED, signaling the write stream is no longer valid.
if(isPermanentError(error$$1.code)||error$$1.code===Code.ABORTED){debug(LOG_TAG$9,'RemoteStore error before completed handshake; resetting stream token: ',this.writeStream.lastStreamToken);this.writeStream.lastStreamToken=emptyByteString();return[2/*return*/,this.localStore.setLastStreamToken(emptyByteString())];}else{// Some other error, don't reset stream token. Our stream logic will
// just retry with exponential backoff.
}return[2/*return*/];});});};RemoteStore.prototype.handleWriteError=function(error$$1){return tslib_1.__awaiter(this,void 0,void 0,function(){var _this=this;var batch;return tslib_1.__generator(this,function(_a){if(isPermanentError(error$$1.code)){batch=this.pendingWrites.shift();// In this case it's also unlikely that the server itself is melting
// down -- this was just a bad request so inhibit backoff on the next
// restart.
this.writeStream.inhibitBackoff();return[2/*return*/,this.syncEngine.rejectFailedWrite(batch.batchId,error$$1).then(function(){// It's possible that with the completion of this mutation
// another slot has freed up.
return _this.fillWritePipeline();})];}else{// Transient error, just let the retry logic kick in.
}return[2/*return*/];});});};RemoteStore.prototype.createTransaction=function(){return new Transaction(this.datastore);};RemoteStore.prototype.handleUserChange=function(user){debug(LOG_TAG$9,'RemoteStore changing users: uid=',user.uid);// If the network has been explicitly disabled, make sure we don't
// accidentally re-enable it.
if(this.isNetworkEnabled()){// Tear down and re-create our network streams. This will ensure we get a fresh auth token
// for the new user and re-fill the write pipeline with new mutations from the LocalStore
// (since mutations are per-user).
this.disableNetworkInternal();this.onlineStateTracker.set(OnlineState.Unknown);return this.enableNetwork();}};return RemoteStore;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var LOG_TAG$10='FirestoreClient';/** The DOMException code for an aborted operation. */var DOM_EXCEPTION_ABORTED=20;/** The DOMException code for quota exceeded. */var DOM_EXCEPTION_QUOTA_EXCEEDED=22;/**
* FirestoreClient is a top-level class that constructs and owns all of the
* pieces of the client SDK architecture. It is responsible for creating the
* async queue that is shared by all of the other components in the system.
*/var FirestoreClient=/** @class */function(){function FirestoreClient(platform,databaseInfo,credentials,/**
* Asynchronous queue responsible for all of our internal processing. When
* we get incoming work from the user (via public API) or the network
* (incoming GRPC messages), we should always schedule onto this queue.
* This ensures all of our work is properly serialized (e.g. we don't
* start processing a new operation while the previous one is waiting for
* an async I/O to complete).
*/asyncQueue){this.platform=platform;this.databaseInfo=databaseInfo;this.credentials=credentials;this.asyncQueue=asyncQueue;}/**
* Starts up the FirestoreClient, returning only whether or not enabling
* persistence succeeded.
*
* The intent here is to "do the right thing" as far as users are concerned.
* Namely, in cases where offline persistence is requested and possible,
* enable it, but otherwise fall back to persistence disabled. For the most
* part we expect this to succeed one way or the other so we don't expect our
* users to actually wait on the firestore.enablePersistence Promise since
* they generally won't care.
*
* Of course some users actually do care about whether or not persistence
* was successfully enabled, so the Promise returned from this method
* indicates this outcome.
*
* This presents a problem though: even before enablePersistence resolves or
* rejects, users may have made calls to e.g. firestore.collection() which
* means that the FirestoreClient in there will be available and will be
* enqueuing actions on the async queue.
*
* Meanwhile any failure of an operation on the async queue causes it to
* panic and reject any further work, on the premise that unhandled errors
* are fatal.
*
* Consequently the fallback is handled internally here in start, and if the
* fallback succeeds we signal success to the async queue even though the
* start() itself signals failure.
*
* @param usePersistence Whether or not to attempt to enable persistence.
* @returns A deferred result indicating the user-visible result of enabling
* offline persistence. This method will reject this if IndexedDB fails to
* start for any reason. If usePersistence is false this is
* unconditionally resolved.
*/FirestoreClient.prototype.start=function(usePersistence){var _this=this;// We defer our initialization until we get the current user from
// setUserChangeListener(). We block the async queue until we got the
// initial user and the initialization is completed. This will prevent
// any scheduled work from happening before initialization is completed.
//
// If initializationDone resolved then the FirestoreClient is in a usable
// state.
var initializationDone=new Deferred$1();// If usePersistence is true, certain classes of errors while starting are
// recoverable but only by falling back to persistence disabled.
//
// If there's an error in the first case but not in recovery we cannot
// reject the promise blocking the async queue because this will cause the
// async queue to panic.
var persistenceResult=new Deferred$1();var initialized=false;this.credentials.setUserChangeListener(function(user){if(!initialized){initialized=true;_this.initializePersistence(usePersistence,persistenceResult).then(function(){return _this.initializeRest(user);}).then(initializationDone.resolve,initializationDone.reject);}else{_this.asyncQueue.enqueue(function(){return _this.handleUserChange(user);});}});// Block the async queue until initialization is done
this.asyncQueue.enqueue(function(){return initializationDone.promise;});// Return only the result of enabling persistence. Note that this does not
// need to await the completion of initializationDone because the result of
// this method should not reflect any other kind of failure to start.
return persistenceResult.promise;};/** Enables the network connection and requeues all pending operations. */FirestoreClient.prototype.enableNetwork=function(){var _this=this;return this.asyncQueue.enqueue(function(){return _this.remoteStore.enableNetwork();});};/**
* Initializes persistent storage, attempting to use IndexedDB if
* usePersistence is true or memory-only if false.
*
* If IndexedDB fails because it's already open in another tab or because the
* platform can't possibly support our implementation then this method rejects
* the persistenceResult and falls back on memory-only persistence.
*
* @param usePersistence indicates whether or not to use offline persistence
* @param persistenceResult A deferred result indicating the user-visible
* result of enabling offline persistence. This method will reject this if
* IndexedDB fails to start for any reason. If usePersistence is false
* this is unconditionally resolved.
* @returns a Promise indicating whether or not initialization should
* continue, i.e. that one of the persistence implementations actually
* succeeded.
*/FirestoreClient.prototype.initializePersistence=function(usePersistence,persistenceResult){var _this=this;if(usePersistence){return this.startIndexedDbPersistence().then(persistenceResult.resolve).catch(function(error$$1){// Regardless of whether or not the retry succeeds, from an user
// perspective, offline persistence has failed.
persistenceResult.reject(error$$1);// An unknown failure on the first stage shuts everything down.
if(!_this.canFallback(error$$1)){return Promise.reject(error$$1);}console.warn('Error enabling offline storage. Falling back to'+' storage disabled: '+error$$1);return _this.startMemoryPersistence();});}else{// When usePersistence == false, enabling offline persistence is defined
// to unconditionally succeed. This allows start() to have the same
// signature for both cases, despite the fact that the returned promise
// is only used in the enablePersistence call.
persistenceResult.resolve();return this.startMemoryPersistence();}};/**
* Decides whether the provided error allows us to gracefully disable
* persistence (as opposed to crashing the client).
*/FirestoreClient.prototype.canFallback=function(error$$1){if(error$$1 instanceof FirestoreError){return error$$1.code===Code.FAILED_PRECONDITION||error$$1.code===Code.UNIMPLEMENTED;}else if(typeof DOMException!=='undefined'&&error$$1 instanceof DOMException){// We fall back to memory persistence if we cannot acquire an owner lease.
// This can happen can during a schema migration, or during the initial
// write of the `owner` lease.
// For both the `QuotaExceededError` and the `AbortError`, it is safe to
// fall back to memory persistence since all modifications to IndexedDb
// failed to commit.
return error$$1.code===DOM_EXCEPTION_QUOTA_EXCEEDED||error$$1.code===DOM_EXCEPTION_ABORTED;}return true;};/**
* Starts IndexedDB-based persistence.
*
* @returns A promise indicating success or failure.
*/FirestoreClient.prototype.startIndexedDbPersistence=function(){// TODO(http://b/33384523): For now we just disable garbage collection
// when persistence is enabled.
this.garbageCollector=new NoOpGarbageCollector();var storagePrefix=IndexedDbPersistence.buildStoragePrefix(this.databaseInfo);// Opt to use proto3 JSON in case the platform doesn't support Uint8Array.
var serializer=new JsonProtoSerializer(this.databaseInfo.databaseId,{useProto3Json:true});this.persistence=new IndexedDbPersistence(storagePrefix,serializer);return this.persistence.start();};/**
* Starts Memory-backed persistence. In practice this cannot fail.
*
* @returns A promise that will successfully resolve.
*/FirestoreClient.prototype.startMemoryPersistence=function(){this.garbageCollector=new EagerGarbageCollector();this.persistence=new MemoryPersistence();return this.persistence.start();};/**
* Initializes the rest of the FirestoreClient, assuming the initial user
* has been obtained from the credential provider and some persistence
* implementation is available in this.persistence.
*/FirestoreClient.prototype.initializeRest=function(user){var _this=this;return this.platform.loadConnection(this.databaseInfo).then(function(connection){_this.localStore=new LocalStore(_this.persistence,user,_this.garbageCollector);var serializer=_this.platform.newSerializer(_this.databaseInfo.databaseId);var datastore=new Datastore(_this.asyncQueue,connection,_this.credentials,serializer);var onlineStateChangedHandler=function(onlineState){_this.syncEngine.applyOnlineStateChange(onlineState);_this.eventMgr.applyOnlineStateChange(onlineState);};_this.remoteStore=new RemoteStore(_this.localStore,datastore,_this.asyncQueue,onlineStateChangedHandler);_this.syncEngine=new SyncEngine(_this.localStore,_this.remoteStore,user);// Setup wiring between sync engine and remote store
_this.remoteStore.syncEngine=_this.syncEngine;_this.eventMgr=new EventManager(_this.syncEngine);// NOTE: RemoteStore depends on LocalStore (for persisting stream
// tokens, refilling mutation queue, etc.) so must be started after
// LocalStore.
return _this.localStore.start();}).then(function(){return _this.remoteStore.start();});};FirestoreClient.prototype.handleUserChange=function(user){this.asyncQueue.verifyOperationInProgress();debug(LOG_TAG$10,'User Changed: '+user.uid);return this.syncEngine.handleUserChange(user);};/** Disables the network connection. Pending operations will not complete. */FirestoreClient.prototype.disableNetwork=function(){var _this=this;return this.asyncQueue.enqueue(function(){return _this.remoteStore.disableNetwork();});};FirestoreClient.prototype.shutdown=function(options){var _this=this;return this.asyncQueue.enqueue(function(){_this.credentials.removeUserChangeListener();return _this.remoteStore.shutdown();}).then(function(){// PORTING NOTE: LocalStore does not need an explicit shutdown on web.
return _this.persistence.shutdown(options&&options.purgePersistenceWithDataLoss);});};FirestoreClient.prototype.listen=function(query,observer,options){var _this=this;var listener=new QueryListener(query,observer,options);this.asyncQueue.enqueue(function(){return _this.eventMgr.listen(listener);});return listener;};FirestoreClient.prototype.unlisten=function(listener){var _this=this;this.asyncQueue.enqueue(function(){return _this.eventMgr.unlisten(listener);});};FirestoreClient.prototype.getDocumentFromLocalCache=function(docKey){var _this=this;return this.asyncQueue.enqueue(function(){return _this.localStore.readDocument(docKey);}).then(function(maybeDoc){if(maybeDoc instanceof Document){return maybeDoc;}else{throw new FirestoreError(Code.UNAVAILABLE,'Failed to get document from cache. (However, this document may '+"exist on the server. Run again without setting 'source' in "+'the GetOptions to attempt to retrieve the document from the '+'server.)');}});};FirestoreClient.prototype.getDocumentsFromLocalCache=function(query){var _this=this;return this.asyncQueue.enqueue(function(){return _this.localStore.executeQuery(query);}).then(function(docs){var remoteKeys=documentKeySet();var view=new View(query,remoteKeys);var viewDocChanges=view.computeDocChanges(docs);return view.applyChanges(viewDocChanges).snapshot;});};FirestoreClient.prototype.write=function(mutations){var _this=this;var deferred=new Deferred$1();this.asyncQueue.enqueue(function(){return _this.syncEngine.write(mutations,deferred);});return deferred.promise;};FirestoreClient.prototype.databaseId=function(){return this.databaseInfo.databaseId;};FirestoreClient.prototype.transaction=function(updateFunction){var _this=this;// We have to wait for the async queue to be sure syncEngine is initialized.
return this.asyncQueue.enqueue(function(){return tslib_1.__awaiter(_this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){return[2/*return*/];});});}).then(function(){return _this.syncEngine.runTransaction(updateFunction);});};return FirestoreClient;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//*
* A wrapper implementation of Observer<T> that will dispatch events
* asynchronously. To allow immediate silencing, a mute call is added which
* causes events scheduled to no longer be raised.
*/var AsyncObserver=/** @class */function(){function AsyncObserver(observer){this.observer=observer;/**
* When set to true, will not raise future events. Necessary to deal with
* async detachment of listener.
*/this.muted=false;}AsyncObserver.prototype.next=function(value){this.scheduleEvent(this.observer.next,value);};AsyncObserver.prototype.error=function(error){this.scheduleEvent(this.observer.error,error);};AsyncObserver.prototype.mute=function(){this.muted=true;};AsyncObserver.prototype.scheduleEvent=function(eventHandler,event){var _this=this;if(!this.muted){setTimeout(function(){if(!_this.muted){eventHandler(event);}},0);}};return AsyncObserver;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* Simple wrapper around a nullable UID. Mostly exists to make code more
* readable.
*/var User=/** @class */function(){function User(uid){this.uid=uid;}User.prototype.isAuthenticated=function(){return this.uid!=null;};/**
* Returns a key representing this user, suitable for inclusion in a
* dictionary.
*/User.prototype.toKey=function(){if(this.isAuthenticated()){return'uid:'+this.uid;}else{return'anonymous-user';}};User.prototype.isEqual=function(otherUser){return otherUser.uid===this.uid;};/** A user with a null UID. */User.UNAUTHENTICATED=new User(null);// TODO(mikelehen): Look into getting a proper uid-equivalent for
// non-FirebaseAuth providers.
User.GOOGLE_CREDENTIALS=new User('google-credentials-uid');User.FIRST_PARTY=new User('first-party-uid');return User;}();/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var OAuthToken=/** @class */function(){function OAuthToken(value,user){this.user=user;this.type='OAuth';this.authHeaders={Authorization:"Bearer "+value};}return OAuthToken;}();/** A CredentialsProvider that always yields an empty token. */var EmptyCredentialsProvider=/** @class */function(){function EmptyCredentialsProvider(){/**
* Stores the User listener registered with setUserChangeListener()
* This isn't actually necessary since the UID never changes, but we use this
* to verify the listen contract is adhered to in tests.
*/this.userListener=null;}EmptyCredentialsProvider.prototype.getToken=function(forceRefresh){return Promise.resolve(null);};EmptyCredentialsProvider.prototype.setUserChangeListener=function(listener){assert(!this.userListener,'Can only call setUserChangeListener() once.');this.userListener=listener;// Fire with initial user.
listener(User.UNAUTHENTICATED);};EmptyCredentialsProvider.prototype.removeUserChangeListener=function(){assert(this.userListener!==null,'removeUserChangeListener() when no listener registered');this.userListener=null;};return EmptyCredentialsProvider;}();var FirebaseCredentialsProvider=/** @class */function(){function FirebaseCredentialsProvider(app){var _this=this;this.app=app;/**
* The auth token listener registered with FirebaseApp, retained here so we
* can unregister it.
*/this.tokenListener=null;/**
* Counter used to detect if the user changed while a getToken request was
* outstanding.
*/this.userCounter=0;/** The User listener registered with setUserChangeListener(). */this.userListener=null;// We listen for token changes but all we really care about is knowing when
// the uid may have changed.
this.tokenListener=function(){var newUser=_this.getUser();if(!_this.currentUser||!newUser.isEqual(_this.currentUser)){_this.currentUser=newUser;_this.userCounter++;if(_this.userListener){_this.userListener(_this.currentUser);}}};this.userCounter=0;// Will fire at least once where we set this.currentUser
this.app.INTERNAL.addAuthTokenListener(this.tokenListener);}FirebaseCredentialsProvider.prototype.getToken=function(forceRefresh){var _this=this;assert(this.tokenListener!=null,'getToken cannot be called after listener removed.');// Take note of the current value of the userCounter so that this method can
// fail (with an ABORTED error) if there is a user change while the request
// is outstanding.
var initialUserCounter=this.userCounter;return this.app.INTERNAL.getToken(forceRefresh).then(function(tokenData){// Cancel the request since the user changed while the request was
// outstanding so the response is likely for a previous user (which
// user, we can't be sure).
if(_this.userCounter!==initialUserCounter){throw new FirestoreError(Code.ABORTED,'getToken aborted due to uid change.');}else{if(tokenData){assert(typeof tokenData.accessToken==='string','Invalid tokenData returned from getToken():'+tokenData);return new OAuthToken(tokenData.accessToken,_this.currentUser);}else{return null;}}});};FirebaseCredentialsProvider.prototype.setUserChangeListener=function(listener){assert(!this.userListener,'Can only call setUserChangeListener() once.');this.userListener=listener;// Fire the initial event, but only if we received the initial user
if(this.currentUser){listener(this.currentUser);}};FirebaseCredentialsProvider.prototype.removeUserChangeListener=function(){assert(this.tokenListener!=null,'removeUserChangeListener() called twice');assert(this.userListener!==null,'removeUserChangeListener() called when no listener registered');this.app.INTERNAL.removeAuthTokenListener(this.tokenListener);this.tokenListener=null;this.userListener=null;};FirebaseCredentialsProvider.prototype.getUser=function(){// TODO(mikelehen): Remove this check once we're shipping with firebase.js.
if(typeof this.app.INTERNAL.getUid!=='function'){fail('This version of the Firestore SDK requires at least version'+' 3.7.0 of firebase.js.');}var currentUid=this.app.INTERNAL.getUid();assert(currentUid===null||typeof currentUid==='string','Received invalid UID: '+currentUid);return new User(currentUid);};return FirebaseCredentialsProvider;}();/*
* FirstPartyToken provides a fresh token each time its value
* is requested, because if the token is too old, requests will be rejected.
* TODO(b/33147818) this implementation violates the current assumption that
* tokens are immutable. We need to either revisit this assumption or come
* up with some way for FPA to use the listen/unlisten interface.
*/var FirstPartyToken=/** @class */function(){function FirstPartyToken(gapi,sessionIndex){this.gapi=gapi;this.sessionIndex=sessionIndex;this.type='FirstParty';this.user=User.FIRST_PARTY;assert(this.gapi&&this.gapi['auth']&&this.gapi['auth']['getAuthHeaderValueForFirstParty'],'unexpected gapi interface');}Object.defineProperty(FirstPartyToken.prototype,"authHeaders",{get:function(){return{Authorization:this.gapi['auth']['getAuthHeaderValueForFirstParty']([]),'X-Goog-AuthUser':this.sessionIndex};},enumerable:true,configurable:true});return FirstPartyToken;}();/*
* Provides user credentials required for the Firestore JavaScript SDK
* to authenticate the user, using technique that is only available
* to applications hosted by Google.
*/var FirstPartyCredentialsProvider=/** @class */function(){function FirstPartyCredentialsProvider(gapi,sessionIndex){this.gapi=gapi;this.sessionIndex=sessionIndex;assert(this.gapi&&this.gapi['auth']&&this.gapi['auth']['getAuthHeaderValueForFirstParty'],'unexpected gapi interface');}FirstPartyCredentialsProvider.prototype.getToken=function(forceRefresh){return Promise.resolve(new FirstPartyToken(this.gapi,this.sessionIndex));};// TODO(33108925): can someone switch users w/o a page refresh?
// TODO(33110621): need to understand token/session lifecycle
FirstPartyCredentialsProvider.prototype.setUserChangeListener=function(listener){// Fire with initial uid.
listener(User.FIRST_PARTY);};FirstPartyCredentialsProvider.prototype.removeUserChangeListener=function(){};return FirstPartyCredentialsProvider;}();/**
* Builds a CredentialsProvider depending on the type of
* the credentials passed in.
*/function makeCredentialsProvider(credentials){if(!credentials){return new EmptyCredentialsProvider();}switch(credentials.type){case'gapi':return new FirstPartyCredentialsProvider(credentials.client,credentials.sessionIndex||'0');case'provider':return credentials.client;default:throw new FirestoreError(Code.INVALID_ARGUMENT,'makeCredentialsProvider failed due to invalid credential type');}}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function isPartialObserver(obj){return implementsAnyMethods$1(obj,['next','error','complete']);}/**
* Returns true if obj is an object and contains at least one of the specified
* methods.
*/function implementsAnyMethods$1(obj,methods){if(typeof obj!=='object'||obj===null){return false;}var object=obj;for(var _i=0,methods_1=methods;_i<methods_1.length;_i++){var method=methods_1[_i];if(method in object&&typeof object[method]==='function'){return true;}}return false;}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*//**
* An opaque base class for FieldValue sentinel objects in our public API,
* with public static methods for creating said sentinel objects.
*/// tslint:disable-next-line:class-as-namespace We use this as a base class.
var FieldValueImpl=/** @class */function(){function FieldValueImpl(methodName){this.methodName=methodName;}FieldValueImpl.delete=function(){return DeleteFieldValueImpl.instance;};FieldValueImpl.serverTimestamp=function(){return ServerTimestampFieldValueImpl.instance;};// TODO(array-features): Expose this once backend support lands.
FieldValueImpl._arrayUnion=function(){var elements=[];for(var _i=0;_i<arguments.length;_i++){elements[_i]=arguments[_i];}validateAtLeastNumberOfArgs('FieldValue.arrayUnion',arguments,1);// NOTE: We don't actually parse the data until it's used in set() or
// update() since we need access to the Firestore instance.
return new ArrayUnionFieldValueImpl(elements);};// TODO(array-features): Expose this once backend support lands.
FieldValueImpl._arrayRemove=function(){var elements=[];for(var _i=0;_i<arguments.length;_i++){elements[_i]=arguments[_i];}validateAtLeastNumberOfArgs('FieldValue.arrayRemove',arguments,1);// NOTE: We don't actually parse the data until it's used in set() or
// update() since we need access to the Firestore instance.
return new ArrayRemoveFieldValueImpl(elements);};FieldValueImpl.prototype.isEqual=function(other){return this===other;};return FieldValueImpl;}();var DeleteFieldValueImpl=/** @class */function(_super){tslib_1.__extends(DeleteFieldValueImpl,_super);function DeleteFieldValueImpl(){return _super.call(this,'FieldValue.delete')||this;}/** Singleton instance. */DeleteFieldValueImpl.instance=new DeleteFieldValueImpl();return DeleteFieldValueImpl;}(FieldValueImpl);var ServerTimestampFieldValueImpl=/** @class */function(_super){tslib_1.__extends(ServerTimestampFieldValueImpl,_super);function ServerTimestampFieldValueImpl(){return _super.call(this,'FieldValue.serverTimestamp')||this;}/** Singleton instance. */ServerTimestampFieldValueImpl.instance=new ServerTimestampFieldValueImpl();return ServerTimestampFieldValueImpl;}(FieldValueImpl);var ArrayUnionFieldValueImpl=/** @class */function(_super){tslib_1.__extends(ArrayUnionFieldValueImpl,_super);function ArrayUnionFieldValueImpl(_elements){var _this=_super.call(this,'FieldValue.arrayUnion')||this;_this._elements=_elements;return _this;}return ArrayUnionFieldValueImpl;}(FieldValueImpl);var ArrayRemoveFieldValueImpl=/** @class */function(_super){tslib_1.__extends(ArrayRemoveFieldValueImpl,_super);function ArrayRemoveFieldValueImpl(_elements){var _this=_super.call(this,'FieldValue.arrayRemove')||this;_this._elements=_elements;return _this;}return ArrayRemoveFieldValueImpl;}(FieldValueImpl);// Public instance that disallows construction at runtime. This constructor is
// used when exporting FieldValueImpl on firebase.firestore.FieldValue and will
// be called FieldValue publicly. Internally we still use FieldValueImpl which
// has a type-checked private constructor. Note that FieldValueImpl and
// PublicFieldValue can be used interchangeably in instanceof checks.
// For our internal TypeScript code PublicFieldValue doesn't exist as a type,
// and so we need to use FieldValueImpl as type and export it too.
// tslint:disable-next-line:variable-name We treat this as a class name.
var PublicFieldValue=makeConstructorPrivate(FieldValueImpl,'Use FieldValue.<field>() instead.');/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var RESERVED_FIELD_REGEX=/^__.*__$/;/** The result of parsing document data (e.g. for a setData call). */var ParsedSetData=/** @class */function(){function ParsedSetData(data,fieldMask,fieldTransforms){this.data=data;this.fieldMask=fieldMask;this.fieldTransforms=fieldTransforms;}ParsedSetData.prototype.toMutations=function(key,precondition){var mutations=[];if(this.fieldMask!==null){mutations.push(new PatchMutation(key,this.data,this.fieldMask,precondition));}else{mutations.push(new SetMutation(key,this.data,precondition));}if(this.fieldTransforms.length>0){mutations.push(new TransformMutation(key,this.fieldTransforms));}return mutations;};return ParsedSetData;}();/** The result of parsing "update" data (i.e. for an updateData call). */var ParsedUpdateData=/** @class */function(){function ParsedUpdateData(data,fieldMask,fieldTransforms){this.data=data;this.fieldMask=fieldMask;this.fieldTransforms=fieldTransforms;}ParsedUpdateData.prototype.toMutations=function(key,precondition){var mutations=[new PatchMutation(key,this.data,this.fieldMask,precondition)];if(this.fieldTransforms.length>0){mutations.push(new TransformMutation(key,this.fieldTransforms));}return mutations;};return ParsedUpdateData;}();/*
* Represents what type of API method provided the data being parsed; useful
* for determining which error conditions apply during parsing and providing
* better error messages.
*/var UserDataSource;(function(UserDataSource){UserDataSource[UserDataSource["Set"]=0]="Set";UserDataSource[UserDataSource["Update"]=1]="Update";UserDataSource[UserDataSource["MergeSet"]=2]="MergeSet";/**
* Indicates the source is a where clause, cursor bound, arrayUnion()
* element, etc. Of note, isWrite(source) will return false.
*/UserDataSource[UserDataSource["Argument"]=3]="Argument";})(UserDataSource||(UserDataSource={}));function isWrite(dataSource){switch(dataSource){case UserDataSource.Set:// fall through
case UserDataSource.MergeSet:// fall through
case UserDataSource.Update:return true;case UserDataSource.Argument:return false;default:throw fail("Unexpected case for UserDataSource: "+dataSource);}}/** A "context" object passed around while parsing user data. */var ParseContext=/** @class */function(){/**
* Initializes a ParseContext with the given source and path.
*
* @param dataSource Indicates what kind of API method this data came from.
* @param methodName The name of the method the user called to create this
* ParseContext.
* @param path A path within the object being parsed. This could be an empty
* path (in which case the context represents the root of the data being
* parsed), or a nonempty path (indicating the context represents a nested
* location within the data).
* @param arrayElement Whether or not this context corresponds to an element
* of an array.
* @param fieldTransforms A mutable list of field transforms encountered while
* parsing the data.
* @param fieldMask A mutable list of field paths encountered while parsing
* the data.
*
* TODO(b/34871131): We don't support array paths right now, so path can be
* null to indicate the context represents any location within an array (in
* which case certain features will not work and errors will be somewhat
* compromised).
*/function ParseContext(dataSource,methodName,path,arrayElement,fieldTransforms,fieldMask){this.dataSource=dataSource;this.methodName=methodName;this.path=path;this.arrayElement=arrayElement;// Minor hack: If fieldTransforms is undefined, we assume this is an
// external call and we need to validate the entire path.
if(fieldTransforms===undefined){this.validatePath();}this.arrayElement=arrayElement!==undefined?arrayElement:false;this.fieldTransforms=fieldTransforms||[];this.fieldMask=fieldMask||[];}ParseContext.prototype.childContextForField=function(field){var childPath=this.path==null?null:this.path.child(field);var context=new ParseContext(this.dataSource,this.methodName,childPath,/*arrayElement=*/false,this.fieldTransforms,this.fieldMask);context.validatePathSegment(field);return context;};ParseContext.prototype.childContextForFieldPath=function(field){var childPath=this.path==null?null:this.path.child(field);var context=new ParseContext(this.dataSource,this.methodName,childPath,/*arrayElement=*/false,this.fieldTransforms,this.fieldMask);context.validatePath();return context;};ParseContext.prototype.childContextForArray=function(index){// TODO(b/34871131): We don't support array paths right now; so make path
// null.
return new ParseContext(this.dataSource,this.methodName,/*path=*/null,/*arrayElement=*/true,this.fieldTransforms,this.fieldMask);};ParseContext.prototype.createError=function(reason){var fieldDescription=this.path===null||this.path.isEmpty()?'':" (found in field "+this.path.toString()+")";return new FirestoreError(Code.INVALID_ARGUMENT,"Function "+this.methodName+"() called with invalid data. "+reason+fieldDescription);};ParseContext.prototype.validatePath=function(){// TODO(b/34871131): Remove null check once we have proper paths for fields
// within arrays.
if(this.path===null){return;}for(var i=0;i<this.path.length;i++){this.validatePathSegment(this.path.get(i));}};ParseContext.prototype.validatePathSegment=function(segment){if(isWrite(this.dataSource)&&RESERVED_FIELD_REGEX.test(segment)){throw this.createError('Document fields cannot begin and end with __');}};return ParseContext;}();/**
* A placeholder object for DocumentReferences in this file, in order to
* avoid a circular dependency. See the comments for `DataPreConverter` for
* the full context.
*/var DocumentKeyReference=/** @class */function(){function DocumentKeyReference(databaseId,key){this.databaseId=databaseId;this.key=key;}return DocumentKeyReference;}();/**
* Helper for parsing raw user input (provided via the API) into internal model
* classes.
*/var UserDataConverter=/** @class */function(){function UserDataConverter(preConverter){this.preConverter=preConverter;}/** Parse document data from a non-merge set() call. */UserDataConverter.prototype.parseSetData=function(methodName,input){var context=new ParseContext(UserDataSource.Set,methodName,FieldPath.EMPTY_PATH);validatePlainObject('Data must be an object, but it was:',context,input);var updateData=this.parseData(input,context);return new ParsedSetData(updateData,/* fieldMask= */null,context.fieldTransforms);};/** Parse document data from a set() call with '{merge:true}'. */UserDataConverter.prototype.parseMergeData=function(methodName,input,fieldPaths){var context=new ParseContext(UserDataSource.MergeSet,methodName,FieldPath.EMPTY_PATH);validatePlainObject('Data must be an object, but it was:',context,input);var updateData=this.parseData(input,context);var fieldMask;var fieldTransforms;if(!fieldPaths){fieldMask=new FieldMask(context.fieldMask);fieldTransforms=context.fieldTransforms;}else{var validatedFieldPaths=[];for(var _i=0,fieldPaths_1=fieldPaths;_i<fieldPaths_1.length;_i++){var stringOrFieldPath=fieldPaths_1[_i];var fieldPath=void 0;if(stringOrFieldPath instanceof FieldPath$1){fieldPath=stringOrFieldPath;}else if(typeof stringOrFieldPath==='string'){fieldPath=fieldPathFromDotSeparatedString(methodName,stringOrFieldPath);}else{fail('Expected stringOrFieldPath to be a string or a FieldPath');}if(!updateData.contains(fieldPath)){throw new FirestoreError(Code.INVALID_ARGUMENT,"Field '"+fieldPath+"' is specified in your field mask but missing from your input data.");}validatedFieldPaths.push(fieldPath);}fieldMask=new FieldMask(validatedFieldPaths);fieldTransforms=context.fieldTransforms.filter(function(transform){return fieldMask.covers(transform.field);});}return new ParsedSetData(updateData,fieldMask,fieldTransforms);};/** Parse update data from an update() call. */UserDataConverter.prototype.parseUpdateData=function(methodName,input){var _this=this;var context=new ParseContext(UserDataSource.Update,methodName,FieldPath.EMPTY_PATH);validatePlainObject('Data must be an object, but it was:',context,input);var fieldMaskPaths=[];var updateData=ObjectValue.EMPTY;forEach(input,function(key,value){var path=fieldPathFromDotSeparatedString(methodName,key);var childContext=context.childContextForFieldPath(path);value=_this.runPreConverter(value,childContext);if(value instanceof DeleteFieldValueImpl){// Add it to the field mask, but don't add anything to updateData.
fieldMaskPaths.push(path);}else{var parsedValue=_this.parseData(value,childContext);if(parsedValue!=null){fieldMaskPaths.push(path);updateData=updateData.set(path,parsedValue);}}});var mask=new FieldMask(fieldMaskPaths);return new ParsedUpdateData(updateData,mask,context.fieldTransforms);};/** Parse update data from a list of field/value arguments. */UserDataConverter.prototype.parseUpdateVarargs=function(methodName,field,value,moreFieldsAndValues){var context=new ParseContext(UserDataSource.Update,methodName,FieldPath.EMPTY_PATH);var keys=[fieldPathFromArgument(methodName,field)];var values=[value];if(moreFieldsAndValues.length%2!==0){throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+methodName+"() needs to be called with an even number "+'of arguments that alternate between field names and values.');}for(var i=0;i<moreFieldsAndValues.length;i+=2){keys.push(fieldPathFromArgument(methodName,moreFieldsAndValues[i]));values.push(moreFieldsAndValues[i+1]);}var fieldMaskPaths=[];var updateData=ObjectValue.EMPTY;for(var i=0;i<keys.length;++i){var path=keys[i];var childContext=context.childContextForFieldPath(path);var value_1=this.runPreConverter(values[i],childContext);if(value_1 instanceof DeleteFieldValueImpl){// Add it to the field mask, but don't add anything to updateData.
fieldMaskPaths.push(path);}else{var parsedValue=this.parseData(value_1,childContext);if(parsedValue!=null){fieldMaskPaths.push(path);updateData=updateData.set(path,parsedValue);}}}var mask=new FieldMask(fieldMaskPaths);return new ParsedUpdateData(updateData,mask,context.fieldTransforms);};/**
* Parse a "query value" (e.g. value in a where filter or a value in a cursor
* bound).
*/UserDataConverter.prototype.parseQueryValue=function(methodName,input){var context=new ParseContext(UserDataSource.Argument,methodName,FieldPath.EMPTY_PATH);var parsed=this.parseData(input,context);assert(parsed!=null,'Parsed data should not be null.');assert(context.fieldTransforms.length===0,'Field transforms should have been disallowed.');return parsed;};/** Sends data through this.preConverter, handling any thrown errors. */UserDataConverter.prototype.runPreConverter=function(input,context){try{return this.preConverter(input);}catch(e){var message=errorMessage(e);throw context.createError(message);}};/**
* Internal helper for parsing user data.
*
* @param input Data to be parsed.
* @param context A context object representing the current path being parsed,
* the source of the data being parsed, etc.
* @return The parsed value, or null if the value was a FieldValue sentinel
* that should not be included in the resulting parsed data.
*/UserDataConverter.prototype.parseData=function(input,context){input=this.runPreConverter(input,context);if(looksLikeJsonObject(input)){validatePlainObject('Unsupported field value:',context,input);return this.parseObject(input,context);}else if(input instanceof FieldValueImpl){// FieldValues usually parse into transforms (except FieldValue.delete())
// in which case we do not want to include this field in our parsed data
// (as doing so will overwrite the field directly prior to the transform
// trying to transform it). So we don't add this location to
// context.fieldMask and we return null as our parsing result.
this.parseSentinelFieldValue(input,context);return null;}else{// If context.path is null we are inside an array and we don't support
// field mask paths more granular than the top-level array.
if(context.path){context.fieldMask.push(context.path);}if(input instanceof Array){// TODO(b/34871131): Include the path containing the array in the error
// message.
if(context.arrayElement){throw context.createError('Nested arrays are not supported');}return this.parseArray(input,context);}else{return this.parseScalarValue(input,context);}}};UserDataConverter.prototype.parseObject=function(obj,context){var _this=this;var result=new SortedMap(primitiveComparator);forEach(obj,function(key,val){var parsedValue=_this.parseData(val,context.childContextForField(key));if(parsedValue!=null){result=result.insert(key,parsedValue);}});return new ObjectValue(result);};UserDataConverter.prototype.parseArray=function(array,context){var result=[];var entryIndex=0;for(var _i=0,array_1=array;_i<array_1.length;_i++){var entry=array_1[_i];var parsedEntry=this.parseData(entry,context.childContextForArray(entryIndex));if(parsedEntry==null){// Just include nulls in the array for fields being replaced with a
// sentinel.
parsedEntry=NullValue.INSTANCE;}result.push(parsedEntry);entryIndex++;}return new ArrayValue(result);};/**
* "Parses" the provided FieldValueImpl, adding any necessary transforms to
* context.fieldTransforms.
*/UserDataConverter.prototype.parseSentinelFieldValue=function(value,context){// Sentinels are only supported with writes, and not within arrays.
if(!isWrite(context.dataSource)){throw context.createError(value.methodName+"() can only be used with update() and set()");}if(context.path===null){throw context.createError(value.methodName+"() is not currently supported inside arrays");}if(value instanceof DeleteFieldValueImpl){if(context.dataSource===UserDataSource.MergeSet){// No transform to add for a delete, but we need to add it to our
// fieldMask so it gets deleted.
context.fieldMask.push(context.path);}else if(context.dataSource===UserDataSource.Update){assert(context.path.length>0,'FieldValue.delete() at the top level should have already'+' been handled.');throw context.createError('FieldValue.delete() can only appear at the top level '+'of your update data');}else{// We shouldn't encounter delete sentinels for queries or non-merge set() calls.
throw context.createError('FieldValue.delete() cannot be used with set() unless you pass '+'{merge:true}');}}else if(value instanceof ServerTimestampFieldValueImpl){context.fieldTransforms.push(new FieldTransform(context.path,ServerTimestampTransform.instance));}else if(value instanceof ArrayUnionFieldValueImpl){var parsedElements=this.parseArrayTransformElements(value.methodName,value._elements);var arrayUnion=new ArrayUnionTransformOperation(parsedElements);context.fieldTransforms.push(new FieldTransform(context.path,arrayUnion));}else if(value instanceof ArrayRemoveFieldValueImpl){var parsedElements=this.parseArrayTransformElements(value.methodName,value._elements);var arrayRemove=new ArrayRemoveTransformOperation(parsedElements);context.fieldTransforms.push(new FieldTransform(context.path,arrayRemove));}else{fail('Unknown FieldValue type: '+value);}};/**
* Helper to parse a scalar value (i.e. not an Object, Array, or FieldValue)
*
* @return The parsed value
*/UserDataConverter.prototype.parseScalarValue=function(value,context){if(value===null){return NullValue.INSTANCE;}else if(typeof value==='number'){if(isSafeInteger(value)){return new IntegerValue(value);}else{return new DoubleValue(value);}}else if(typeof value==='boolean'){return BooleanValue.of(value);}else if(typeof value==='string'){return new StringValue(value);}else if(value instanceof Date){return new TimestampValue(Timestamp.fromDate(value));}else if(value instanceof Timestamp){// Firestore backend truncates precision down to microseconds. To ensure
// offline mode works the same with regards to truncation, perform the
// truncation immediately without waiting for the backend to do that.
return new TimestampValue(new Timestamp(value.seconds,Math.floor(value.nanoseconds/1000)*1000));}else if(value instanceof GeoPoint){return new GeoPointValue(value);}else if(value instanceof Blob){return new BlobValue(value);}else if(value instanceof DocumentKeyReference){return new RefValue(value.databaseId,value.key);}else{throw context.createError("Unsupported field value: "+valueDescription(value));}};UserDataConverter.prototype.parseArrayTransformElements=function(methodName,elements){var _this=this;return elements.map(function(element,i){// Although array transforms are used with writes, the actual elements
// being unioned or removed are not considered writes since they cannot
// contain any FieldValue sentinels, etc.
var context=new ParseContext(UserDataSource.Argument,methodName,FieldPath.EMPTY_PATH);return _this.parseData(element,context.childContextForArray(i));});};return UserDataConverter;}();/**
* Checks whether an object looks like a JSON object that should be converted
* into a struct. Normal class/prototype instances are considered to look like
* JSON objects since they should be converted to a struct value. Arrays, Dates,
* GeoPoints, etc. are not considered to look like JSON objects since they map
* to specific FieldValue types other than ObjectValue.
*/function looksLikeJsonObject(input){return typeof input==='object'&&input!==null&&!(input instanceof Array)&&!(input instanceof Date)&&!(input instanceof Timestamp)&&!(input instanceof GeoPoint)&&!(input instanceof Blob)&&!(input instanceof DocumentKeyReference)&&!(input instanceof FieldValueImpl);}function validatePlainObject(message,context,input){if(!looksLikeJsonObject(input)||!isPlainObject(input)){var description=valueDescription(input);if(description==='an object'){// Massage the error if it was an object.
throw context.createError(message+' a custom object');}else{throw context.createError(message+' '+description);}}}/**
* Helper that calls fromDotSeparatedString() but wraps any error thrown.
*/function fieldPathFromArgument(methodName,path){if(path instanceof FieldPath$1){return path._internalPath;}else if(typeof path==='string'){return fieldPathFromDotSeparatedString(methodName,path);}else{var message='Field path arguments must be of type string or FieldPath.';throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+methodName+"() called with invalid data. "+message);}}/**
* Wraps fromDotSeparatedString with an error message about the method that
* was thrown.
* @param methodName The publicly visible method name
* @param path The dot-separated string form of a field path which will be split
* on dots.
*/function fieldPathFromDotSeparatedString(methodName,path){try{return fromDotSeparatedString(path)._internalPath;}catch(e){var message=errorMessage(e);throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+methodName+"() called with invalid data. "+message);}}/**
* Extracts the message from a caught exception, which should be an Error object
* though JS doesn't guarantee that.
*/function errorMessage(error){return error instanceof Error?error.message:error.toString();}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/// The objects that are a part of this API are exposed to third-parties as
// compiled javascript so we want to flag our private members with a leading
// underscore to discourage their use.
// tslint:disable:strip-private-property-underscore
var DEFAULT_HOST='firestore.googleapis.com';var DEFAULT_SSL=true;var DEFAULT_TIMESTAMPS_IN_SNAPSHOTS=false;/**
* A concrete type describing all the values that can be applied via a
* user-supplied firestore.Settings object. This is a separate type so that
* defaults can be supplied and the value can be checked for equality.
*/var FirestoreSettings=/** @class */function(){function FirestoreSettings(settings){if(settings.host===undefined){if(settings.ssl!==undefined){throw new FirestoreError(Code.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");}this.host=DEFAULT_HOST;this.ssl=DEFAULT_SSL;}else{validateNamedType('settings','string','host',settings.host);this.host=settings.host;validateNamedOptionalType('settings','boolean','ssl',settings.ssl);this.ssl=defaulted(settings.ssl,DEFAULT_SSL);}validateOptionNames('settings',settings,['host','ssl','credentials','timestampsInSnapshots']);validateNamedOptionalType('settings','object','credentials',settings.credentials);this.credentials=settings.credentials;validateNamedOptionalType('settings','boolean','timestampsInSnapshots',settings.timestampsInSnapshots);this.timestampsInSnapshots=defaulted(settings.timestampsInSnapshots,DEFAULT_TIMESTAMPS_IN_SNAPSHOTS);}FirestoreSettings.prototype.isEqual=function(other){return this.host===other.host&&this.ssl===other.ssl&&this.timestampsInSnapshots===other.timestampsInSnapshots&&this.credentials===other.credentials;};return FirestoreSettings;}();var FirestoreConfig=/** @class */function(){function FirestoreConfig(){}return FirestoreConfig;}();/**
* The root reference to the database.
*/var Firestore=/** @class */function(){function Firestore(databaseIdOrApp){var _this=this;// Public for use in tests.
// TODO(mikelehen): Use modularized initialization instead.
this._queue=new AsyncQueue();this.INTERNAL={delete:function(options){return tslib_1.__awaiter(_this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){if(this._firestoreClient){return[2/*return*/,this._firestoreClient.shutdown(options)];}return[2/*return*/];});});}};var config=new FirestoreConfig();if(typeof databaseIdOrApp.options==='object'){// This is very likely a Firebase app object
// TODO(b/34177605): Can we somehow use instanceof?
var app=databaseIdOrApp;config.firebaseApp=app;config.databaseId=Firestore.databaseIdFromApp(app);config.persistenceKey=config.firebaseApp.name;config.credentials=new FirebaseCredentialsProvider(app);}else{var external_1=databaseIdOrApp;if(!external_1.projectId){throw new FirestoreError(Code.INVALID_ARGUMENT,'Must provide projectId');}config.databaseId=new DatabaseId(external_1.projectId,external_1.database);// Use a default persistenceKey that lines up with FirebaseApp.
config.persistenceKey='[DEFAULT]';config.credentials=new EmptyCredentialsProvider();}config.settings=new FirestoreSettings({});this._config=config;this._databaseId=config.databaseId;}Firestore.prototype.settings=function(settingsLiteral){validateExactNumberOfArgs('Firestore.settings',arguments,1);validateArgType('Firestore.settings','object',1,settingsLiteral);if(contains(settingsLiteral,'persistence')){throw new FirestoreError(Code.INVALID_ARGUMENT,'"persistence" is now specified with a separate call to '+'firestore.enablePersistence().');}var newSettings=new FirestoreSettings(settingsLiteral);if(this._firestoreClient&&!this._config.settings.isEqual(newSettings)){throw new FirestoreError(Code.FAILED_PRECONDITION,'Firestore has already been started and its settings can no longer '+'be changed. You can only call settings() before calling any other '+'methods on a Firestore object.');}this._config.settings=newSettings;if(newSettings.credentials!==undefined){this._config.credentials=makeCredentialsProvider(newSettings.credentials);}};Firestore.prototype.enableNetwork=function(){this.ensureClientConfigured();return this._firestoreClient.enableNetwork();};Firestore.prototype.disableNetwork=function(){this.ensureClientConfigured();return this._firestoreClient.disableNetwork();};Firestore.prototype.enablePersistence=function(){if(this._firestoreClient){throw new FirestoreError(Code.FAILED_PRECONDITION,'Firestore has already been started and persistence can no longer '+'be enabled. You can only call enablePersistence() before calling '+'any other methods on a Firestore object.');}return this.configureClient(/* persistence= */true);};Firestore.prototype.ensureClientConfigured=function(){if(!this._firestoreClient){this.configureClient(/* persistence= */false);}return this._firestoreClient;};Firestore.prototype.configureClient=function(persistence){var _this=this;assert(!!this._config.settings.host,'FirestoreSettings.host cannot be falsey');if(!this._config.settings.timestampsInSnapshots){error("\nThe behavior for Date objects stored in Firestore is going to change\nAND YOUR APP MAY BREAK.\nTo hide this warning and ensure your app does not break, you need to add the\nfollowing code to your app before calling any other Cloud Firestore methods:\n\n const firestore = firebase.firestore();\n const settings = {/* your settings... */ timestampsInSnapshots: true};\n firestore.settings(settings);\n\nWith this change, timestamps stored in Cloud Firestore will be read back as\nFirebase Timestamp objects instead of as system Date objects. So you will also\nneed to update code expecting a Date to instead expect a Timestamp. For example:\n\n // Old:\n const date = snapshot.get('created_at');\n // New:\n const timestamp = snapshot.get('created_at');\n const date = timestamp.toDate();\n\nPlease audit all existing usages of Date when you enable the new behavior. In a\nfuture release, the behavior will change to the new behavior, so if you do not\nfollow these steps, YOUR APP MAY BREAK.");}assert(!this._firestoreClient,'configureClient() called multiple times');var databaseInfo=new DatabaseInfo(this._config.databaseId,this._config.persistenceKey,this._config.settings.host,this._config.settings.ssl);var preConverter=function(value){if(value instanceof DocumentReference){var thisDb=_this._config.databaseId;var otherDb=value.firestore._config.databaseId;if(!otherDb.isEqual(thisDb)){throw new FirestoreError(Code.INVALID_ARGUMENT,'Document reference is for database '+(otherDb.projectId+"/"+otherDb.database+" but should be ")+("for database "+thisDb.projectId+"/"+thisDb.database));}return new DocumentKeyReference(_this._config.databaseId,value._key);}else{return value;}};this._dataConverter=new UserDataConverter(preConverter);this._firestoreClient=new FirestoreClient(PlatformSupport.getPlatform(),databaseInfo,this._config.credentials,this._queue);return this._firestoreClient.start(persistence);};Firestore.databaseIdFromApp=function(app){var options=app.options;if(!contains(options,'projectId')){// TODO(b/62673263): We can safely remove the special handling of
// 'firestoreId' once alpha testers have upgraded.
if(contains(options,'firestoreId')){throw new FirestoreError(Code.INVALID_ARGUMENT,'"firestoreId" is now specified as "projectId" in '+'firebase.initializeApp.');}throw new FirestoreError(Code.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');}if(contains(options,'firestoreOptions')){// TODO(b/62673263): We can safely remove the special handling of
// 'firestoreOptions' once alpha testers have upgraded.
throw new FirestoreError(Code.INVALID_ARGUMENT,'"firestoreOptions" values are now specified with '+'Firestore.settings()');}var projectId=options['projectId'];if(!projectId||typeof projectId!=='string'){throw new FirestoreError(Code.INVALID_ARGUMENT,'projectId must be a string in FirebaseApp.options');}return new DatabaseId(projectId);};Object.defineProperty(Firestore.prototype,"app",{get:function(){if(!this._config.firebaseApp){throw new FirestoreError(Code.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is "+'not available');}return this._config.firebaseApp;},enumerable:true,configurable:true});Firestore.prototype.collection=function(pathString){validateExactNumberOfArgs('Firestore.collection',arguments,1);validateArgType('Firestore.collection','string',1,pathString);if(!pathString){throw new FirestoreError(Code.INVALID_ARGUMENT,'Must provide a non-empty collection path to collection()');}this.ensureClientConfigured();return new CollectionReference(ResourcePath.fromString(pathString),this);};Firestore.prototype.doc=function(pathString){validateExactNumberOfArgs('Firestore.doc',arguments,1);validateArgType('Firestore.doc','string',1,pathString);if(!pathString){throw new FirestoreError(Code.INVALID_ARGUMENT,'Must provide a non-empty document path to doc()');}this.ensureClientConfigured();return DocumentReference.forPath(ResourcePath.fromString(pathString),this);};Firestore.prototype.runTransaction=function(updateFunction){var _this=this;validateExactNumberOfArgs('Firestore.runTransaction',arguments,1);validateArgType('Firestore.runTransaction','function',1,updateFunction);return this.ensureClientConfigured().transaction(function(transaction){return updateFunction(new Transaction$1(_this,transaction));});};Firestore.prototype.batch=function(){this.ensureClientConfigured();return new WriteBatch(this);};Object.defineProperty(Firestore,"logLevel",{get:function(){switch(getLogLevel()){case LogLevel.DEBUG:return'debug';case LogLevel.ERROR:return'error';case LogLevel.SILENT:return'silent';default:return fail('Unknown log level: '+getLogLevel());}},enumerable:true,configurable:true});Firestore.setLogLevel=function(level){validateExactNumberOfArgs('Firestore.setLogLevel',arguments,1);validateArgType('Firestore.setLogLevel','string',1,level);switch(level){case'debug':setLogLevel(LogLevel.DEBUG);break;case'error':setLogLevel(LogLevel.ERROR);break;case'silent':setLogLevel(LogLevel.SILENT);break;default:throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid log level: '+level);}};// Note: this is not a property because the minifier can't work correctly with
// the way TypeScript compiler outputs properties.
Firestore.prototype._areTimestampsInSnapshotsEnabled=function(){return this._config.settings.timestampsInSnapshots;};return Firestore;}();/**
* A reference to a transaction.
*/var Transaction$1=/** @class */function(){function Transaction(_firestore,_transaction){this._firestore=_firestore;this._transaction=_transaction;}Transaction.prototype.get=function(documentRef){var _this=this;validateExactNumberOfArgs('Transaction.get',arguments,1);var ref=validateReference('Transaction.get',documentRef,this._firestore);return this._transaction.lookup([ref._key]).then(function(docs){if(!docs||docs.length!==1){return fail('Mismatch in docs returned from document lookup.');}var doc=docs[0];if(doc instanceof NoDocument){return new DocumentSnapshot(_this._firestore,ref._key,null,false);}return new DocumentSnapshot(_this._firestore,ref._key,doc,false);});};Transaction.prototype.set=function(documentRef,value,options){validateBetweenNumberOfArgs('Transaction.set',arguments,2,3);var ref=validateReference('Transaction.set',documentRef,this._firestore);options=validateSetOptions('Transaction.set',options);var parsed=options.merge||options.mergeFields?this._firestore._dataConverter.parseMergeData('Transaction.set',value,options.mergeFields):this._firestore._dataConverter.parseSetData('Transaction.set',value);this._transaction.set(ref._key,parsed);return this;};Transaction.prototype.update=function(documentRef,fieldOrUpdateData,value){var moreFieldsAndValues=[];for(var _i=3;_i<arguments.length;_i++){moreFieldsAndValues[_i-3]=arguments[_i];}var ref;var parsed;if(typeof fieldOrUpdateData==='string'||fieldOrUpdateData instanceof FieldPath$1){validateAtLeastNumberOfArgs('Transaction.update',arguments,3);ref=validateReference('Transaction.update',documentRef,this._firestore);parsed=this._firestore._dataConverter.parseUpdateVarargs('Transaction.update',fieldOrUpdateData,value,moreFieldsAndValues);}else{validateExactNumberOfArgs('Transaction.update',arguments,2);ref=validateReference('Transaction.update',documentRef,this._firestore);parsed=this._firestore._dataConverter.parseUpdateData('Transaction.update',fieldOrUpdateData);}this._transaction.update(ref._key,parsed);return this;};Transaction.prototype.delete=function(documentRef){validateExactNumberOfArgs('Transaction.delete',arguments,1);var ref=validateReference('Transaction.delete',documentRef,this._firestore);this._transaction.delete(ref._key);return this;};return Transaction;}();var WriteBatch=/** @class */function(){function WriteBatch(_firestore){this._firestore=_firestore;this._mutations=[];this._committed=false;}WriteBatch.prototype.set=function(documentRef,value,options){validateBetweenNumberOfArgs('WriteBatch.set',arguments,2,3);this.verifyNotCommitted();var ref=validateReference('WriteBatch.set',documentRef,this._firestore);options=validateSetOptions('WriteBatch.set',options);var parsed=options.merge||options.mergeFields?this._firestore._dataConverter.parseMergeData('WriteBatch.set',value,options.mergeFields):this._firestore._dataConverter.parseSetData('WriteBatch.set',value);this._mutations=this._mutations.concat(parsed.toMutations(ref._key,Precondition.NONE));return this;};WriteBatch.prototype.update=function(documentRef,fieldOrUpdateData,value){var moreFieldsAndValues=[];for(var _i=3;_i<arguments.length;_i++){moreFieldsAndValues[_i-3]=arguments[_i];}this.verifyNotCommitted();var ref;var parsed;if(typeof fieldOrUpdateData==='string'||fieldOrUpdateData instanceof FieldPath$1){validateAtLeastNumberOfArgs('WriteBatch.update',arguments,3);ref=validateReference('WriteBatch.update',documentRef,this._firestore);parsed=this._firestore._dataConverter.parseUpdateVarargs('WriteBatch.update',fieldOrUpdateData,value,moreFieldsAndValues);}else{validateExactNumberOfArgs('WriteBatch.update',arguments,2);ref=validateReference('WriteBatch.update',documentRef,this._firestore);parsed=this._firestore._dataConverter.parseUpdateData('WriteBatch.update',fieldOrUpdateData);}this._mutations=this._mutations.concat(parsed.toMutations(ref._key,Precondition.exists(true)));return this;};WriteBatch.prototype.delete=function(documentRef){validateExactNumberOfArgs('WriteBatch.delete',arguments,1);this.verifyNotCommitted();var ref=validateReference('WriteBatch.delete',documentRef,this._firestore);this._mutations=this._mutations.concat(new DeleteMutation(ref._key,Precondition.NONE));return this;};WriteBatch.prototype.commit=function(){return tslib_1.__awaiter(this,void 0,void 0,function(){return tslib_1.__generator(this,function(_a){this.verifyNotCommitted();this._committed=true;if(this._mutations.length>0){return[2/*return*/,this._firestore.ensureClientConfigured().write(this._mutations)];}return[2/*return*/];});});};WriteBatch.prototype.verifyNotCommitted=function(){if(this._committed){throw new FirestoreError(Code.FAILED_PRECONDITION,'A write batch can no longer be used after commit() '+'has been called.');}};return WriteBatch;}();/**
* A reference to a particular document in a collection in the database.
*/var DocumentReference=/** @class */function(){function DocumentReference(_key,firestore){this._key=_key;this.firestore=firestore;this._firestoreClient=this.firestore.ensureClientConfigured();}DocumentReference.forPath=function(path,firestore){if(path.length%2!==0){throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid document reference. Document '+'references must have an even number of segments, but '+(path.canonicalString()+" has "+path.length));}return new DocumentReference(new DocumentKey(path),firestore);};Object.defineProperty(DocumentReference.prototype,"id",{get:function(){return this._key.path.lastSegment();},enumerable:true,configurable:true});Object.defineProperty(DocumentReference.prototype,"parent",{get:function(){return new CollectionReference(this._key.path.popLast(),this.firestore);},enumerable:true,configurable:true});Object.defineProperty(DocumentReference.prototype,"path",{get:function(){return this._key.path.canonicalString();},enumerable:true,configurable:true});DocumentReference.prototype.collection=function(pathString){validateExactNumberOfArgs('DocumentReference.collection',arguments,1);validateArgType('DocumentReference.collection','string',1,pathString);if(!pathString){throw new FirestoreError(Code.INVALID_ARGUMENT,'Must provide a non-empty collection name to collection()');}var path=ResourcePath.fromString(pathString);return new CollectionReference(this._key.path.child(path),this.firestore);};DocumentReference.prototype.isEqual=function(other){if(!(other instanceof DocumentReference)){throw invalidClassError('isEqual','DocumentReference',1,other);}return this.firestore===other.firestore&&this._key.isEqual(other._key);};DocumentReference.prototype.set=function(value,options){validateBetweenNumberOfArgs('DocumentReference.set',arguments,1,2);options=validateSetOptions('DocumentReference.set',options);var parsed=options.merge||options.mergeFields?this.firestore._dataConverter.parseMergeData('DocumentReference.set',value,options.mergeFields):this.firestore._dataConverter.parseSetData('DocumentReference.set',value);return this._firestoreClient.write(parsed.toMutations(this._key,Precondition.NONE));};DocumentReference.prototype.update=function(fieldOrUpdateData,value){var moreFieldsAndValues=[];for(var _i=2;_i<arguments.length;_i++){moreFieldsAndValues[_i-2]=arguments[_i];}var parsed;if(typeof fieldOrUpdateData==='string'||fieldOrUpdateData instanceof FieldPath$1){validateAtLeastNumberOfArgs('DocumentReference.update',arguments,2);parsed=this.firestore._dataConverter.parseUpdateVarargs('DocumentReference.update',fieldOrUpdateData,value,moreFieldsAndValues);}else{validateExactNumberOfArgs('DocumentReference.update',arguments,1);parsed=this.firestore._dataConverter.parseUpdateData('DocumentReference.update',fieldOrUpdateData);}return this._firestoreClient.write(parsed.toMutations(this._key,Precondition.exists(true)));};DocumentReference.prototype.delete=function(){validateExactNumberOfArgs('DocumentReference.delete',arguments,0);return this._firestoreClient.write([new DeleteMutation(this._key,Precondition.NONE)]);};DocumentReference.prototype.onSnapshot=function(){var args=[];for(var _i=0;_i<arguments.length;_i++){args[_i]=arguments[_i];}validateBetweenNumberOfArgs('DocumentReference.onSnapshot',arguments,1,4);var options={includeMetadataChanges:false};var observer;var currArg=0;if(typeof args[currArg]==='object'&&!isPartialObserver(args[currArg])){options=args[currArg];validateOptionNames('DocumentReference.onSnapshot',options,['includeMetadataChanges']);validateNamedOptionalType('DocumentReference.onSnapshot','boolean','includeMetadataChanges',options.includeMetadataChanges);currArg++;}var internalOptions={includeMetadataChanges:options.includeMetadataChanges};if(isPartialObserver(args[currArg])){observer=args[currArg];}else{validateArgType('DocumentReference.onSnapshot','function',currArg,args[currArg]);validateOptionalArgType('DocumentReference.onSnapshot','function',currArg+1,args[currArg+1]);validateOptionalArgType('DocumentReference.onSnapshot','function',currArg+2,args[currArg+2]);observer={next:args[currArg],error:args[currArg+1],complete:args[currArg+2]};}return this.onSnapshotInternal(internalOptions,observer);};DocumentReference.prototype.onSnapshotInternal=function(options,observer){var _this=this;var errHandler=function(err){console.error('Uncaught Error in onSnapshot:',err);};if(observer.error){errHandler=observer.error.bind(observer);}var asyncObserver=new AsyncObserver({next:function(snapshot){if(observer.next){assert(snapshot.docs.size<=1,'Too many documents returned on a document query');var doc=snapshot.docs.get(_this._key);observer.next(new DocumentSnapshot(_this.firestore,_this._key,doc,snapshot.fromCache));}},error:errHandler});var internalListener=this._firestoreClient.listen(Query.atPath(this._key.path),asyncObserver,options);return function(){asyncObserver.mute();_this._firestoreClient.unlisten(internalListener);};};DocumentReference.prototype.get=function(options){var _this=this;validateOptionNames('DocumentReference.get',options,['source']);if(options){validateNamedOptionalPropertyEquals('DocumentReference.get','options','source',options.source,['default','server','cache']);}return new Promise(function(resolve,reject){if(options&&options.source==='cache'){_this.firestore.ensureClientConfigured().getDocumentFromLocalCache(_this._key).then(function(doc){resolve(new DocumentSnapshot(_this.firestore,_this._key,doc,/*fromCache=*/true));},reject);}else{_this.getViaSnapshotListener(resolve,reject,options);}});};DocumentReference.prototype.getViaSnapshotListener=function(resolve,reject,options){var unlisten=this.onSnapshotInternal({includeMetadataChanges:true,waitForSyncWhenOnline:true},{next:function(snap){// Remove query first before passing event to user to avoid
// user actions affecting the now stale query.
unlisten();if(!snap.exists&&snap.metadata.fromCache){// TODO(dimond): If we're online and the document doesn't
// exist then we resolve with a doc.exists set to false. If
// we're offline however, we reject the Promise in this
// case. Two options: 1) Cache the negative response from
// the server so we can deliver that even when you're
// offline 2) Actually reject the Promise in the online case
// if the document doesn't exist.
reject(new FirestoreError(Code.UNAVAILABLE,'Failed to get document because the client is '+'offline.'));}else if(snap.exists&&snap.metadata.fromCache&&options&&options.source==='server'){reject(new FirestoreError(Code.UNAVAILABLE,'Failed to get document from server. (However, this '+'document does exist in the local cache. Run again '+'without setting source to "server" to '+'retrieve the cached document.)'));}else{resolve(snap);}},error:reject});};return DocumentReference;}();var SnapshotMetadata=/** @class */function(){function SnapshotMetadata(hasPendingWrites,fromCache){this.hasPendingWrites=hasPendingWrites;this.fromCache=fromCache;}SnapshotMetadata.prototype.isEqual=function(other){return this.hasPendingWrites===other.hasPendingWrites&&this.fromCache===other.fromCache;};return SnapshotMetadata;}();var DocumentSnapshot=/** @class */function(){function DocumentSnapshot(_firestore,_key,_document,_fromCache){this._firestore=_firestore;this._key=_key;this._document=_document;this._fromCache=_fromCache;}DocumentSnapshot.prototype.data=function(options){validateBetweenNumberOfArgs('DocumentSnapshot.data',arguments,0,1);options=validateSnapshotOptions('DocumentSnapshot.data',options);return!this._document?undefined:this.convertObject(this._document.data,FieldValueOptions.fromSnapshotOptions(options,this._firestore._areTimestampsInSnapshotsEnabled()));};DocumentSnapshot.prototype.get=function(fieldPath,options){validateBetweenNumberOfArgs('DocumentSnapshot.get',arguments,1,2);options=validateSnapshotOptions('DocumentSnapshot.get',options);if(this._document){var value=this._document.data.field(fieldPathFromArgument('DocumentSnapshot.get',fieldPath));if(value!==undefined){return this.convertValue(value,FieldValueOptions.fromSnapshotOptions(options,this._firestore._areTimestampsInSnapshotsEnabled()));}}return undefined;};Object.defineProperty(DocumentSnapshot.prototype,"id",{get:function(){return this._key.path.lastSegment();},enumerable:true,configurable:true});Object.defineProperty(DocumentSnapshot.prototype,"ref",{get:function(){return new DocumentReference(this._key,this._firestore);},enumerable:true,configurable:true});Object.defineProperty(DocumentSnapshot.prototype,"exists",{get:function(){return this._document!==null;},enumerable:true,configurable:true});Object.defineProperty(DocumentSnapshot.prototype,"metadata",{get:function(){return new SnapshotMetadata(this._document!==null&&this._document.hasLocalMutations,this._fromCache);},enumerable:true,configurable:true});DocumentSnapshot.prototype.isEqual=function(other){if(!(other instanceof DocumentSnapshot)){throw invalidClassError('isEqual','DocumentSnapshot',1,other);}return this._firestore===other._firestore&&this._fromCache===other._fromCache&&this._key.isEqual(other._key)&&(this._document===null?other._document===null:this._document.isEqual(other._document));};DocumentSnapshot.prototype.convertObject=function(data,options){var _this=this;var result={};data.forEach(function(key,value){result[key]=_this.convertValue(value,options);});return result;};DocumentSnapshot.prototype.convertValue=function(value,options){if(value instanceof ObjectValue){return this.convertObject(value,options);}else if(value instanceof ArrayValue){return this.convertArray(value,options);}else if(value instanceof RefValue){var key=value.value(options);var database=this._firestore.ensureClientConfigured().databaseId();if(!value.databaseId.isEqual(database)){// TODO(b/64130202): Somehow support foreign references.
error("Document "+this._key.path+" contains a document "+"reference within a different database ("+(value.databaseId.projectId+"/"+value.databaseId.database+") which is not ")+"supported. It will be treated as a reference in the current "+("database ("+database.projectId+"/"+database.database+") ")+"instead.");}return new DocumentReference(key,this._firestore);}else{return value.value(options);}};DocumentSnapshot.prototype.convertArray=function(data,options){var _this=this;return data.internalValue.map(function(value){return _this.convertValue(value,options);});};return DocumentSnapshot;}();var QueryDocumentSnapshot=/** @class */function(_super){tslib_1.__extends(QueryDocumentSnapshot,_super);function QueryDocumentSnapshot(firestore,key,document,fromCache){return _super.call(this,firestore,key,document,fromCache)||this;}QueryDocumentSnapshot.prototype.data=function(options){var data=_super.prototype.data.call(this,options);assert(typeof data==='object','Document in a QueryDocumentSnapshot should exist');return data;};return QueryDocumentSnapshot;}(DocumentSnapshot);var Query$1=/** @class */function(){function Query$$1(_query,firestore){this._query=_query;this.firestore=firestore;}Query$$1.prototype.where=function(field,opStr,value){validateExactNumberOfArgs('Query.where',arguments,3);validateArgType('Query.where','string',2,opStr);validateDefined('Query.where',3,value);var fieldValue;var fieldPath=fieldPathFromArgument('Query.where',field);var relationOp=RelationOp.fromString(opStr);if(fieldPath.isKeyField()){if(relationOp===RelationOp.ARRAY_CONTAINS){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid Query. You can't perform array-contains queries on "+'FieldPath.documentId() since document IDs are not arrays.');}if(typeof value==='string'){if(value.indexOf('/')!==-1){// TODO(dimond): Allow slashes once ancestor queries are supported
throw new FirestoreError(Code.INVALID_ARGUMENT,'Function Query.where() requires its third parameter to be a '+'valid document ID if the first parameter is '+'FieldPath.documentId(), but it contains a slash.');}if(value===''){throw new FirestoreError(Code.INVALID_ARGUMENT,'Function Query.where() requires its third parameter to be a '+'valid document ID if the first parameter is '+'FieldPath.documentId(), but it was an empty string.');}var path=this._query.path.child(new ResourcePath([value]));assert(path.length%2===0,'Path should be a document key');fieldValue=new RefValue(this.firestore._databaseId,new DocumentKey(path));}else if(value instanceof DocumentReference){var ref=value;fieldValue=new RefValue(this.firestore._databaseId,ref._key);}else{throw new FirestoreError(Code.INVALID_ARGUMENT,"Function Query.where() requires its third parameter to be a "+"string or a DocumentReference if the first parameter is "+"FieldPath.documentId(), but it was: "+(valueDescription(value)+"."));}}else{fieldValue=this.firestore._dataConverter.parseQueryValue('Query.where',value);}var filter=fieldFilter(fieldPath,relationOp,fieldValue);this.validateNewFilter(filter);return new Query$$1(this._query.addFilter(filter),this.firestore);};Query$$1.prototype.orderBy=function(field,directionStr){validateBetweenNumberOfArgs('Query.orderBy',arguments,1,2);validateOptionalArgType('Query.orderBy','string',2,directionStr);var direction;if(directionStr===undefined||directionStr==='asc'){direction=Direction.ASCENDING;}else if(directionStr==='desc'){direction=Direction.DESCENDING;}else{throw new FirestoreError(Code.INVALID_ARGUMENT,"Function Query.orderBy() has unknown direction '"+directionStr+"', "+"expected 'asc' or 'desc'.");}if(this._query.startAt!==null){throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid query. You must not call Query.startAt() or '+'Query.startAfter() before calling Query.orderBy().');}if(this._query.endAt!==null){throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid query. You must not call Query.endAt() or '+'Query.endBefore() before calling Query.orderBy().');}var fieldPath=fieldPathFromArgument('Query.orderBy',field);var orderBy=new OrderBy(fieldPath,direction);this.validateNewOrderBy(orderBy);return new Query$$1(this._query.addOrderBy(orderBy),this.firestore);};Query$$1.prototype.limit=function(n){validateExactNumberOfArgs('Query.limit',arguments,1);validateArgType('Query.limit','number',1,n);if(n<=0){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid Query. Query limit ("+n+") is invalid. Limit must be "+'positive.');}return new Query$$1(this._query.withLimit(n),this.firestore);};Query$$1.prototype.startAt=function(docOrField){var fields=[];for(var _i=1;_i<arguments.length;_i++){fields[_i-1]=arguments[_i];}validateAtLeastNumberOfArgs('Query.startAt',arguments,1);var bound=this.boundFromDocOrFields('Query.startAt',docOrField,fields,/*before=*/true);return new Query$$1(this._query.withStartAt(bound),this.firestore);};Query$$1.prototype.startAfter=function(docOrField){var fields=[];for(var _i=1;_i<arguments.length;_i++){fields[_i-1]=arguments[_i];}validateAtLeastNumberOfArgs('Query.startAfter',arguments,1);var bound=this.boundFromDocOrFields('Query.startAfter',docOrField,fields,/*before=*/false);return new Query$$1(this._query.withStartAt(bound),this.firestore);};Query$$1.prototype.endBefore=function(docOrField){var fields=[];for(var _i=1;_i<arguments.length;_i++){fields[_i-1]=arguments[_i];}validateAtLeastNumberOfArgs('Query.endBefore',arguments,1);var bound=this.boundFromDocOrFields('Query.endBefore',docOrField,fields,/*before=*/true);return new Query$$1(this._query.withEndAt(bound),this.firestore);};Query$$1.prototype.endAt=function(docOrField){var fields=[];for(var _i=1;_i<arguments.length;_i++){fields[_i-1]=arguments[_i];}validateAtLeastNumberOfArgs('Query.endAt',arguments,1);var bound=this.boundFromDocOrFields('Query.endAt',docOrField,fields,/*before=*/false);return new Query$$1(this._query.withEndAt(bound),this.firestore);};Query$$1.prototype.isEqual=function(other){if(!(other instanceof Query$$1)){throw invalidClassError('isEqual','Query',1,other);}return this.firestore===other.firestore&&this._query.isEqual(other._query);};/** Helper function to create a bound from a document or fields */Query$$1.prototype.boundFromDocOrFields=function(methodName,docOrField,fields,before){validateDefined(methodName,1,docOrField);if(docOrField instanceof DocumentSnapshot){if(fields.length>0){throw new FirestoreError(Code.INVALID_ARGUMENT,"Too many arguments provided to "+methodName+"().");}var snap=docOrField;if(!snap.exists){throw new FirestoreError(Code.NOT_FOUND,"Can't use a DocumentSnapshot that doesn't exist for "+(methodName+"()."));}return this.boundFromDocument(methodName,snap._document,before);}else{var allFields=[docOrField].concat(fields);return this.boundFromFields(methodName,allFields,before);}};/**
* Create a Bound from a query and a document.
*
* Note that the Bound will always include the key of the document
* and so only the provided document will compare equal to the returned
* position.
*
* Will throw if the document does not contain all fields of the order by
* of the query.
*/Query$$1.prototype.boundFromDocument=function(methodName,doc,before){var components=[];// Because people expect to continue/end a query at the exact document
// provided, we need to use the implicit sort order rather than the explicit
// sort order, because it's guaranteed to contain the document key. That way
// the position becomes unambiguous and the query continues/ends exactly at
// the provided document. Without the key (by using the explicit sort
// orders), multiple documents could match the position, yielding duplicate
// results.
for(var _i=0,_a=this._query.orderBy;_i<_a.length;_i++){var orderBy=_a[_i];if(orderBy.field.isKeyField()){components.push(new RefValue(this.firestore._databaseId,doc.key));}else{var value=doc.field(orderBy.field);if(value!==undefined){components.push(value);}else{var field=orderBy.field.canonicalString();throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. You are trying to start or end a query using a "+("document for which the field '"+field+"' (used as the ")+"orderBy) does not exist.");}}}return new Bound(components,before);};/**
* Converts a list of field values to a Bound for the given query.
*/Query$$1.prototype.boundFromFields=function(methodName,values,before){// Use explicit order by's because it has to match the query the user made
var orderBy=this._query.explicitOrderBy;if(values.length>orderBy.length){throw new FirestoreError(Code.INVALID_ARGUMENT,"Too many arguments provided to "+methodName+"(). "+"The number of arguments must be less than or equal to the "+"number of Query.orderBy() clauses");}var components=[];for(var i=0;i<values.length;i++){var rawValue=values[i];var orderByComponent=orderBy[i];if(orderByComponent.field.isKeyField()){if(typeof rawValue!=='string'){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. Expected a string for document ID in "+(methodName+"(), but got a "+typeof rawValue));}if(rawValue.indexOf('/')!==-1){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. Document ID '"+rawValue+"' contains a slash in "+(methodName+"()"));}var key=new DocumentKey(this._query.path.child(rawValue));components.push(new RefValue(this.firestore._databaseId,key));}else{var wrapped=this.firestore._dataConverter.parseQueryValue(methodName,rawValue);components.push(wrapped);}}return new Bound(components,before);};Query$$1.prototype.onSnapshot=function(){var args=[];for(var _i=0;_i<arguments.length;_i++){args[_i]=arguments[_i];}validateBetweenNumberOfArgs('Query.onSnapshot',arguments,1,4);var options={};var observer;var currArg=0;if(typeof args[currArg]==='object'&&!isPartialObserver(args[currArg])){options=args[currArg];validateOptionNames('Query.onSnapshot',options,['includeMetadataChanges']);validateNamedOptionalType('Query.onSnapshot','boolean','includeMetadataChanges',options.includeMetadataChanges);currArg++;}if(isPartialObserver(args[currArg])){observer=args[currArg];}else{validateArgType('Query.onSnapshot','function',currArg,args[currArg]);validateOptionalArgType('Query.onSnapshot','function',currArg+1,args[currArg+1]);validateOptionalArgType('Query.onSnapshot','function',currArg+2,args[currArg+2]);observer={next:args[currArg],error:args[currArg+1],complete:args[currArg+2]};}return this.onSnapshotInternal(options,observer);};Query$$1.prototype.onSnapshotInternal=function(options,observer){var _this=this;var errHandler=function(err){console.error('Uncaught Error in onSnapshot:',err);};if(observer.error){errHandler=observer.error.bind(observer);}var asyncObserver=new AsyncObserver({next:function(result){if(observer.next){observer.next(new QuerySnapshot(_this.firestore,_this._query,result));}},error:errHandler});var firestoreClient=this.firestore.ensureClientConfigured();var internalListener=firestoreClient.listen(this._query,asyncObserver,options);return function(){asyncObserver.mute();firestoreClient.unlisten(internalListener);};};Query$$1.prototype.get=function(options){var _this=this;validateBetweenNumberOfArgs('Query.get',arguments,0,1);return new Promise(function(resolve,reject){if(options&&options.source==='cache'){_this.firestore.ensureClientConfigured().getDocumentsFromLocalCache(_this._query).then(function(viewSnap){resolve(new QuerySnapshot(_this.firestore,_this._query,viewSnap));},reject);}else{_this.getViaSnapshotListener(resolve,reject,options);}});};Query$$1.prototype.getViaSnapshotListener=function(resolve,reject,options){var unlisten=this.onSnapshotInternal({includeMetadataChanges:true,waitForSyncWhenOnline:true},{next:function(result){// Remove query first before passing event to user to avoid
// user actions affecting the now stale query.
unlisten();if(result.metadata.fromCache&&options&&options.source==='server'){reject(new FirestoreError(Code.UNAVAILABLE,'Failed to get documents from server. (However, these '+'documents may exist in the local cache. Run again '+'without setting source to "server" to '+'retrieve the cached documents.)'));}else{resolve(result);}},error:reject});};Query$$1.prototype.validateNewFilter=function(filter){if(filter instanceof RelationFilter){if(filter.isInequality()){var existingField=this._query.getInequalityFilterField();if(existingField!==null&&!existingField.isEqual(filter.field)){throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid query. All where filters with an inequality'+' (<, <=, >, or >=) must be on the same field. But you have'+(" inequality filters on '"+existingField.toString()+"'")+(" and '"+filter.field.toString()+"'"));}var firstOrderByField=this._query.getFirstOrderByField();if(firstOrderByField!==null){this.validateOrderByAndInequalityMatch(filter.field,firstOrderByField);}}else if(filter.op===RelationOp.ARRAY_CONTAINS){if(this._query.hasArrayContainsFilter()){throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid query. Queries only support a single array-contains '+'filter.');}}}};Query$$1.prototype.validateNewOrderBy=function(orderBy){if(this._query.getFirstOrderByField()===null){// This is the first order by. It must match any inequality.
var inequalityField=this._query.getInequalityFilterField();if(inequalityField!==null){this.validateOrderByAndInequalityMatch(inequalityField,orderBy.field);}}};Query$$1.prototype.validateOrderByAndInequalityMatch=function(inequality,orderBy){if(!orderBy.isEqual(inequality)){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. You have a where filter with an inequality "+("(<, <=, >, or >=) on field '"+inequality.toString()+"' ")+("and so you must also use '"+inequality.toString()+"' ")+"as your first Query.orderBy(), but your first Query.orderBy() "+("is on field '"+orderBy.toString()+"' instead."));}};return Query$$1;}();var QuerySnapshot=/** @class */function(){function QuerySnapshot(_firestore,_originalQuery,_snapshot){this._firestore=_firestore;this._originalQuery=_originalQuery;this._snapshot=_snapshot;this._cachedChanges=null;this._cachedChangesIncludeMetadataChanges=null;this.metadata=new SnapshotMetadata(_snapshot.hasPendingWrites,_snapshot.fromCache);}Object.defineProperty(QuerySnapshot.prototype,"docs",{get:function(){var result=[];this.forEach(function(doc){return result.push(doc);});return result;},enumerable:true,configurable:true});Object.defineProperty(QuerySnapshot.prototype,"empty",{get:function(){return this._snapshot.docs.isEmpty();},enumerable:true,configurable:true});Object.defineProperty(QuerySnapshot.prototype,"size",{get:function(){return this._snapshot.docs.size;},enumerable:true,configurable:true});QuerySnapshot.prototype.forEach=function(callback,thisArg){var _this=this;validateBetweenNumberOfArgs('QuerySnapshot.forEach',arguments,1,2);validateArgType('QuerySnapshot.forEach','function',1,callback);this._snapshot.docs.forEach(function(doc){callback.call(thisArg,_this.convertToDocumentImpl(doc));});};Object.defineProperty(QuerySnapshot.prototype,"query",{get:function(){return new Query$1(this._originalQuery,this._firestore);},enumerable:true,configurable:true});QuerySnapshot.prototype.docChanges=function(options){validateOptionNames('QuerySnapshot.docChanges',options,['includeMetadataChanges']);if(options){validateNamedOptionalType('QuerySnapshot.docChanges','boolean','includeMetadataChanges',options.includeMetadataChanges);}var includeMetadataChanges=options&&options.includeMetadataChanges;if(includeMetadataChanges&&this._snapshot.excludesMetadataChanges){throw new FirestoreError(Code.INVALID_ARGUMENT,'To include metadata changes with your document changes, you must '+'also pass { includeMetadataChanges:true } to onSnapshot().');}if(!this._cachedChanges||this._cachedChangesIncludeMetadataChanges!==includeMetadataChanges){this._cachedChanges=changesFromSnapshot(this._firestore,includeMetadataChanges,this._snapshot);this._cachedChangesIncludeMetadataChanges=includeMetadataChanges;}return this._cachedChanges;};/** Check the equality. The call can be very expensive. */QuerySnapshot.prototype.isEqual=function(other){if(!(other instanceof QuerySnapshot)){throw invalidClassError('isEqual','QuerySnapshot',1,other);}return this._firestore===other._firestore&&this._originalQuery.isEqual(other._originalQuery)&&this._snapshot.isEqual(other._snapshot);};QuerySnapshot.prototype.convertToDocumentImpl=function(doc){return new QueryDocumentSnapshot(this._firestore,doc.key,doc,this.metadata.fromCache);};return QuerySnapshot;}();// TODO(2018/11/01): As of 2018/04/17 we're changing docChanges from an array
// into a method. Because this is a runtime breaking change and somewhat subtle
// (both Array and Function have a .length, etc.), we'll replace commonly-used
// properties (including Symbol.iterator) to throw a custom error message. In
// ~6 months we can delete the custom error as most folks will have hopefully
// migrated.
function throwDocChangesMethodError(){throw new FirestoreError(Code.INVALID_ARGUMENT,'QuerySnapshot.docChanges has been changed from a property into a '+'method, so usages like "querySnapshot.docChanges" should become '+'"querySnapshot.docChanges()"');}var docChangesPropertiesToOverride=['length','forEach','map'].concat(typeof Symbol!=='undefined'?[Symbol.iterator]:[]);docChangesPropertiesToOverride.forEach(function(property){/**
* We are (re-)defining properties on QuerySnapshot.prototype.docChanges which
* is a Function. This could fail, in particular in the case of 'length' which
* already exists on Function.prototype and on IE11 is improperly defined with
* `{ configurable: false }`. So we wrap this in a try/catch to ensure that we
* still have a functional SDK.
*/try{Object.defineProperty(QuerySnapshot.prototype.docChanges,property,{get:function(){return throwDocChangesMethodError();}});}catch(err){}// Ignore this failure intentionally
});var CollectionReference=/** @class */function(_super){tslib_1.__extends(CollectionReference,_super);function CollectionReference(path,firestore){var _this=_super.call(this,Query.atPath(path),firestore)||this;if(path.length%2!==1){throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid collection reference. Collection '+'references must have an odd number of segments, but '+(path.canonicalString()+" has "+path.length));}return _this;}Object.defineProperty(CollectionReference.prototype,"id",{get:function(){return this._query.path.lastSegment();},enumerable:true,configurable:true});Object.defineProperty(CollectionReference.prototype,"parent",{get:function(){var parentPath=this._query.path.popLast();if(parentPath.isEmpty()){return null;}else{return new DocumentReference(new DocumentKey(parentPath),this.firestore);}},enumerable:true,configurable:true});Object.defineProperty(CollectionReference.prototype,"path",{get:function(){return this._query.path.canonicalString();},enumerable:true,configurable:true});CollectionReference.prototype.doc=function(pathString){validateBetweenNumberOfArgs('CollectionReference.doc',arguments,0,1);// We allow omission of 'pathString' but explicitly prohibit passing in both
// 'undefined' and 'null'.
if(arguments.length===0){pathString=AutoId.newId();}validateArgType('CollectionReference.doc','string',1,pathString);if(pathString===''){throw new FirestoreError(Code.INVALID_ARGUMENT,'Document path must be a non-empty string');}var path=ResourcePath.fromString(pathString);return DocumentReference.forPath(this._query.path.child(path),this.firestore);};CollectionReference.prototype.add=function(value){validateExactNumberOfArgs('CollectionReference.add',arguments,1);validateArgType('CollectionReference.add','object',1,value);var docRef=this.doc();return docRef.set(value).then(function(){return docRef;});};return CollectionReference;}(Query$1);function validateSetOptions(methodName,options){if(options===undefined){return{merge:false};}validateOptionNames(methodName,options,['merge','mergeFields']);validateNamedOptionalType(methodName,'boolean','merge',options.merge);validateOptionalArrayElements(methodName,'mergeFields','a string or a FieldPath',options.mergeFields,function(element){return typeof element==='string'||element instanceof FieldPath$1;});if(options.mergeFields!==undefined&&options.merge!==undefined){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid options passed to function "+methodName+"(): You cannot specify both \"merge\" and \"mergeFields\".");}return options;}function validateSnapshotOptions(methodName,options){if(options===undefined){return{};}validateOptionNames(methodName,options,['serverTimestamps']);validateNamedOptionalPropertyEquals(methodName,'options','serverTimestamps',options.serverTimestamps,['estimate','previous','none']);return options;}function validateReference(methodName,documentRef,firestore){if(!(documentRef instanceof DocumentReference)){throw invalidClassError(methodName,'DocumentReference',1,documentRef);}else if(documentRef.firestore!==firestore){throw new FirestoreError(Code.INVALID_ARGUMENT,'Provided document reference is from a different Firestore instance.');}else{return documentRef;}}/**
* Calculates the array of firestore.DocumentChange's for a given ViewSnapshot.
*
* Exported for testing.
*/function changesFromSnapshot(firestore,includeMetadataChanges,snapshot){if(snapshot.oldDocs.isEmpty()){// Special case the first snapshot because index calculation is easy and
// fast
var lastDoc_1;var index_1=0;return snapshot.docChanges.map(function(change){var doc=new QueryDocumentSnapshot(firestore,change.doc.key,change.doc,snapshot.fromCache);assert(change.type===ChangeType.Added,'Invalid event type for first snapshot');assert(!lastDoc_1||snapshot.query.docComparator(lastDoc_1,change.doc)<0,'Got added events in wrong order');lastDoc_1=change.doc;return{type:'added',doc:doc,oldIndex:-1,newIndex:index_1++};});}else{// A DocumentSet that is updated incrementally as changes are applied to use
// to lookup the index of a document.
var indexTracker_1=snapshot.oldDocs;return snapshot.docChanges.filter(function(change){return includeMetadataChanges||change.type!==ChangeType.Metadata;}).map(function(change){var doc=new QueryDocumentSnapshot(firestore,change.doc.key,change.doc,snapshot.fromCache);var oldIndex=-1;var newIndex=-1;if(change.type!==ChangeType.Added){oldIndex=indexTracker_1.indexOf(change.doc.key);assert(oldIndex>=0,'Index for document not found');indexTracker_1=indexTracker_1.delete(change.doc.key);}if(change.type!==ChangeType.Removed){indexTracker_1=indexTracker_1.add(change.doc);newIndex=indexTracker_1.indexOf(change.doc.key);}return{type:resultChangeType(change.type),doc:doc,oldIndex:oldIndex,newIndex:newIndex};});}}function resultChangeType(type){switch(type){case ChangeType.Added:return'added';case ChangeType.Modified:case ChangeType.Metadata:return'modified';case ChangeType.Removed:return'removed';default:return fail('Unknown change type: '+type);}}// Export the classes with a private constructor (it will fail if invoked
// at runtime). Note that this still allows instanceof checks.
// We're treating the variables as class names, so disable checking for lower
// case variable names.
// tslint:disable:variable-name
var PublicFirestore=makeConstructorPrivate(Firestore,'Use firebase.firestore() instead.');var PublicTransaction=makeConstructorPrivate(Transaction$1,'Use firebase.firestore().runTransaction() instead.');var PublicWriteBatch=makeConstructorPrivate(WriteBatch,'Use firebase.firestore().batch() instead.');var PublicDocumentReference=makeConstructorPrivate(DocumentReference,'Use firebase.firestore().doc() instead.');var PublicDocumentSnapshot=makeConstructorPrivate(DocumentSnapshot);var PublicQueryDocumentSnapshot=makeConstructorPrivate(QueryDocumentSnapshot);var PublicQuery=makeConstructorPrivate(Query$1);var PublicQuerySnapshot=makeConstructorPrivate(QuerySnapshot);var PublicCollectionReference=makeConstructorPrivate(CollectionReference,'Use firebase.firestore().collection() instead.');// tslint:enable:variable-name
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/var firestoreNamespace={Firestore:PublicFirestore,GeoPoint:GeoPoint,Timestamp:Timestamp,Blob:PublicBlob,Transaction:PublicTransaction,WriteBatch:PublicWriteBatch,DocumentReference:PublicDocumentReference,DocumentSnapshot:PublicDocumentSnapshot,Query:PublicQuery,QueryDocumentSnapshot:PublicQueryDocumentSnapshot,QuerySnapshot:PublicQuerySnapshot,CollectionReference:PublicCollectionReference,FieldPath:FieldPath$1,FieldValue:PublicFieldValue,setLogLevel:Firestore.setLogLevel};/**
* Configures Firestore as part of the Firebase SDK by calling registerService.
*/function configureForFirebase(firebase$$1){firebase$$1.INTERNAL.registerService('firestore',function(app){return new Firestore(app);},shallowCopy(firestoreNamespace));}/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function registerFirestore(instance){configureForFirebase(instance);}registerFirestore(firebase);exports.registerFirestore=registerFirestore;
/***/ }),
/***/ "ew/s":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Defines jumpToLine command. Uses dialog.js if present.
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("4e7A"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../dialog/dialog"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
function dialog(cm, text, shortText, deflt, f) {
if (cm.openDialog) cm.openDialog(text, f, { value: deflt, selectValueOnOpen: true });else f(prompt(shortText, deflt));
}
var jumpDialog = 'Jump to line: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use line:column or scroll% syntax)</span>';
function interpretLine(cm, string) {
var num = Number(string);
if (/^[-+]/.test(string)) return cm.getCursor().line + num;else return num - 1;
}
CodeMirror.commands.jumpToLine = function (cm) {
var cur = cm.getCursor();
dialog(cm, jumpDialog, "Jump to line:", cur.line + 1 + ":" + cur.ch, function (posStr) {
if (!posStr) return;
var match;
if (match = /^\s*([\+\-]?\d+)\s*\:\s*(\d+)\s*$/.exec(posStr)) {
cm.setCursor(interpretLine(cm, match[1]), Number(match[2]));
} else if (match = /^\s*([\+\-]?\d+(\.\d+)?)\%\s*/.exec(posStr)) {
var line = Math.round(cm.lineCount() * Number(match[1]) / 100);
if (/^[-+]/.test(match[1])) line = cur.line + line + 1;
cm.setCursor(line - 1, cur.ch);
} else if (match = /^\s*\:?\s*([\+\-]?\d+)\s*/.exec(posStr)) {
cm.setCursor(interpretLine(cm, match[1]), cur.ch);
}
});
};
CodeMirror.keyMap["default"]["Alt-G"] = "jumpToLine";
});
/***/ }),
/***/ "gPKv":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var WRAP_CLASS = "CodeMirror-activeline";
var BACK_CLASS = "CodeMirror-activeline-background";
var GUTT_CLASS = "CodeMirror-activeline-gutter";
CodeMirror.defineOption("styleActiveLine", false, function (cm, val, old) {
var prev = old == CodeMirror.Init ? false : old;
if (val == prev) return;
if (prev) {
cm.off("beforeSelectionChange", selectionChange);
clearActiveLines(cm);
delete cm.state.activeLines;
}
if (val) {
cm.state.activeLines = [];
updateActiveLines(cm, cm.listSelections());
cm.on("beforeSelectionChange", selectionChange);
}
});
function clearActiveLines(cm) {
for (var i = 0; i < cm.state.activeLines.length; i++) {
cm.removeLineClass(cm.state.activeLines[i], "wrap", WRAP_CLASS);
cm.removeLineClass(cm.state.activeLines[i], "background", BACK_CLASS);
cm.removeLineClass(cm.state.activeLines[i], "gutter", GUTT_CLASS);
}
}
function sameArray(a, b) {
if (a.length != b.length) return false;
for (var i = 0; i < a.length; i++) if (a[i] != b[i]) return false;
return true;
}
function updateActiveLines(cm, ranges) {
var active = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
var option = cm.getOption("styleActiveLine");
if (typeof option == "object" && option.nonEmpty ? range.anchor.line != range.head.line : !range.empty()) continue;
var line = cm.getLineHandleVisualStart(range.head.line);
if (active[active.length - 1] != line) active.push(line);
}
if (sameArray(cm.state.activeLines, active)) return;
cm.operation(function () {
clearActiveLines(cm);
for (var i = 0; i < active.length; i++) {
cm.addLineClass(active[i], "wrap", WRAP_CLASS);
cm.addLineClass(active[i], "background", BACK_CLASS);
cm.addLineClass(active[i], "gutter", GUTT_CLASS);
}
cm.state.activeLines = active;
});
}
function selectionChange(cm, sel) {
updateActiveLines(cm, sel.ranges);
}
});
/***/ }),
/***/ "gfUn":
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var formatRegExp = /%[sdj%]/g;
exports.format = function (f) {
if (!isString(f)) {
var objects = [];
for (var i = 0; i < arguments.length; i++) {
objects.push(inspect(arguments[i]));
}
return objects.join(' ');
}
var i = 1;
var args = arguments;
var len = args.length;
var str = String(f).replace(formatRegExp, function (x) {
if (x === '%%') return '%';
if (i >= len) return x;
switch (x) {
case '%s':
return String(args[i++]);
case '%d':
return Number(args[i++]);
case '%j':
try {
return JSON.stringify(args[i++]);
} catch (_) {
return '[Circular]';
}
default:
return x;
}
});
for (var x = args[i]; i < len; x = args[++i]) {
if (isNull(x) || !isObject(x)) {
str += ' ' + x;
} else {
str += ' ' + inspect(x);
}
}
return str;
};
// Mark that a method should not be used.
// Returns a modified function which warns once by default.
// If --no-deprecation is set, then it is a no-op.
exports.deprecate = function (fn, msg) {
// Allow for deprecating things in the process of starting up.
if (isUndefined(global.process)) {
return function () {
return exports.deprecate(fn, msg).apply(this, arguments);
};
}
if (process.noDeprecation === true) {
return fn;
}
var warned = false;
function deprecated() {
if (!warned) {
if (process.throwDeprecation) {
throw new Error(msg);
} else if (process.traceDeprecation) {
console.trace(msg);
} else {
console.error(msg);
}
warned = true;
}
return fn.apply(this, arguments);
}
return deprecated;
};
var debugs = {};
var debugEnviron;
exports.debuglog = function (set) {
if (isUndefined(debugEnviron)) debugEnviron = process.env.NODE_DEBUG || '';
set = set.toUpperCase();
if (!debugs[set]) {
if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
var pid = process.pid;
debugs[set] = function () {
var msg = exports.format.apply(exports, arguments);
console.error('%s %d: %s', set, pid, msg);
};
} else {
debugs[set] = function () {};
}
}
return debugs[set];
};
/**
* Echos the value of a value. Trys to print the value out
* in the best way possible given the different types.
*
* @param {Object} obj The object to print out.
* @param {Object} opts Optional options object that alters the output.
*/
/* legacy: obj, showHidden, depth, colors*/
function inspect(obj, opts) {
// default options
var ctx = {
seen: [],
stylize: stylizeNoColor
};
// legacy...
if (arguments.length >= 3) ctx.depth = arguments[2];
if (arguments.length >= 4) ctx.colors = arguments[3];
if (isBoolean(opts)) {
// legacy...
ctx.showHidden = opts;
} else if (opts) {
// got an "options" object
exports._extend(ctx, opts);
}
// set default options
if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
if (isUndefined(ctx.depth)) ctx.depth = 2;
if (isUndefined(ctx.colors)) ctx.colors = false;
if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
if (ctx.colors) ctx.stylize = stylizeWithColor;
return formatValue(ctx, obj, ctx.depth);
}
exports.inspect = inspect;
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
inspect.colors = {
'bold': [1, 22],
'italic': [3, 23],
'underline': [4, 24],
'inverse': [7, 27],
'white': [37, 39],
'grey': [90, 39],
'black': [30, 39],
'blue': [34, 39],
'cyan': [36, 39],
'green': [32, 39],
'magenta': [35, 39],
'red': [31, 39],
'yellow': [33, 39]
};
// Don't use 'blue' not visible on cmd.exe
inspect.styles = {
'special': 'cyan',
'number': 'yellow',
'boolean': 'yellow',
'undefined': 'grey',
'null': 'bold',
'string': 'green',
'date': 'magenta',
// "name": intentionally not styling
'regexp': 'red'
};
function stylizeWithColor(str, styleType) {
var style = inspect.styles[styleType];
if (style) {
return '\u001b[' + inspect.colors[style][0] + 'm' + str + '\u001b[' + inspect.colors[style][1] + 'm';
} else {
return str;
}
}
function stylizeNoColor(str, styleType) {
return str;
}
function arrayToHash(array) {
var hash = {};
array.forEach(function (val, idx) {
hash[val] = true;
});
return hash;
}
function formatValue(ctx, value, recurseTimes) {
// Provide a hook for user-specified inspect functions.
// Check that value is an object with an inspect function on it
if (ctx.customInspect && value && isFunction(value.inspect) &&
// Filter out the util module, it's inspect function is special
value.inspect !== exports.inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
var ret = value.inspect(recurseTimes, ctx);
if (!isString(ret)) {
ret = formatValue(ctx, ret, recurseTimes);
}
return ret;
}
// Primitive types cannot have properties
var primitive = formatPrimitive(ctx, value);
if (primitive) {
return primitive;
}
// Look up the keys of the object.
var keys = Object.keys(value);
var visibleKeys = arrayToHash(keys);
if (ctx.showHidden) {
keys = Object.getOwnPropertyNames(value);
}
// IE doesn't make error fields non-enumerable
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
return formatError(value);
}
// Some type of object without properties can be shortcutted.
if (keys.length === 0) {
if (isFunction(value)) {
var name = value.name ? ': ' + value.name : '';
return ctx.stylize('[Function' + name + ']', 'special');
}
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
}
if (isDate(value)) {
return ctx.stylize(Date.prototype.toString.call(value), 'date');
}
if (isError(value)) {
return formatError(value);
}
}
var base = '',
array = false,
braces = ['{', '}'];
// Make Array say that they are Array
if (isArray(value)) {
array = true;
braces = ['[', ']'];
}
// Make functions say that they are functions
if (isFunction(value)) {
var n = value.name ? ': ' + value.name : '';
base = ' [Function' + n + ']';
}
// Make RegExps say that they are RegExps
if (isRegExp(value)) {
base = ' ' + RegExp.prototype.toString.call(value);
}
// Make dates with properties first say the date
if (isDate(value)) {
base = ' ' + Date.prototype.toUTCString.call(value);
}
// Make error with message first say the error
if (isError(value)) {
base = ' ' + formatError(value);
}
if (keys.length === 0 && (!array || value.length == 0)) {
return braces[0] + base + braces[1];
}
if (recurseTimes < 0) {
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
} else {
return ctx.stylize('[Object]', 'special');
}
}
ctx.seen.push(value);
var output;
if (array) {
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
} else {
output = keys.map(function (key) {
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
});
}
ctx.seen.pop();
return reduceToSingleString(output, base, braces);
}
function formatPrimitive(ctx, value) {
if (isUndefined(value)) return ctx.stylize('undefined', 'undefined');
if (isString(value)) {
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
return ctx.stylize(simple, 'string');
}
if (isNumber(value)) return ctx.stylize('' + value, 'number');
if (isBoolean(value)) return ctx.stylize('' + value, 'boolean');
// For some reason typeof null is "object", so special case here.
if (isNull(value)) return ctx.stylize('null', 'null');
}
function formatError(value) {
return '[' + Error.prototype.toString.call(value) + ']';
}
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
var output = [];
for (var i = 0, l = value.length; i < l; ++i) {
if (hasOwnProperty(value, String(i))) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
} else {
output.push('');
}
}
keys.forEach(function (key) {
if (!key.match(/^\d+$/)) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
}
});
return output;
}
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
var name, str, desc;
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
if (desc.get) {
if (desc.set) {
str = ctx.stylize('[Getter/Setter]', 'special');
} else {
str = ctx.stylize('[Getter]', 'special');
}
} else {
if (desc.set) {
str = ctx.stylize('[Setter]', 'special');
}
}
if (!hasOwnProperty(visibleKeys, key)) {
name = '[' + key + ']';
}
if (!str) {
if (ctx.seen.indexOf(desc.value) < 0) {
if (isNull(recurseTimes)) {
str = formatValue(ctx, desc.value, null);
} else {
str = formatValue(ctx, desc.value, recurseTimes - 1);
}
if (str.indexOf('\n') > -1) {
if (array) {
str = str.split('\n').map(function (line) {
return ' ' + line;
}).join('\n').substr(2);
} else {
str = '\n' + str.split('\n').map(function (line) {
return ' ' + line;
}).join('\n');
}
}
} else {
str = ctx.stylize('[Circular]', 'special');
}
}
if (isUndefined(name)) {
if (array && key.match(/^\d+$/)) {
return str;
}
name = JSON.stringify('' + key);
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
name = name.substr(1, name.length - 2);
name = ctx.stylize(name, 'name');
} else {
name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
name = ctx.stylize(name, 'string');
}
}
return name + ': ' + str;
}
function reduceToSingleString(output, base, braces) {
var numLinesEst = 0;
var length = output.reduce(function (prev, cur) {
numLinesEst++;
if (cur.indexOf('\n') >= 0) numLinesEst++;
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
}, 0);
if (length > 60) {
return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
}
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
}
// NOTE: These type checking functions intentionally don't use `instanceof`
// because it is fragile and can be easily faked with `Object.create()`.
function isArray(ar) {
return Array.isArray(ar);
}
exports.isArray = isArray;
function isBoolean(arg) {
return typeof arg === 'boolean';
}
exports.isBoolean = isBoolean;
function isNull(arg) {
return arg === null;
}
exports.isNull = isNull;
function isNullOrUndefined(arg) {
return arg == null;
}
exports.isNullOrUndefined = isNullOrUndefined;
function isNumber(arg) {
return typeof arg === 'number';
}
exports.isNumber = isNumber;
function isString(arg) {
return typeof arg === 'string';
}
exports.isString = isString;
function isSymbol(arg) {
return typeof arg === 'symbol';
}
exports.isSymbol = isSymbol;
function isUndefined(arg) {
return arg === void 0;
}
exports.isUndefined = isUndefined;
function isRegExp(re) {
return isObject(re) && objectToString(re) === '[object RegExp]';
}
exports.isRegExp = isRegExp;
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
exports.isObject = isObject;
function isDate(d) {
return isObject(d) && objectToString(d) === '[object Date]';
}
exports.isDate = isDate;
function isError(e) {
return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error);
}
exports.isError = isError;
function isFunction(arg) {
return typeof arg === 'function';
}
exports.isFunction = isFunction;
function isPrimitive(arg) {
return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || typeof arg === 'symbol' || // ES6 symbol
typeof arg === 'undefined';
}
exports.isPrimitive = isPrimitive;
exports.isBuffer = __webpack_require__("vexR");
function objectToString(o) {
return Object.prototype.toString.call(o);
}
function pad(n) {
return n < 10 ? '0' + n.toString(10) : n.toString(10);
}
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
// 26 Feb 16:19:34
function timestamp() {
var d = new Date();
var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
return [d.getDate(), months[d.getMonth()], time].join(' ');
}
// log is just a thin wrapper to console.log that prepends a timestamp
exports.log = function () {
console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
};
/**
* Inherit the prototype methods from one constructor into another.
*
* The Function.prototype.inherits from lang.js rewritten as a standalone
* function (not on Function.prototype). NOTE: If this file is to be loaded
* during bootstrapping this function needs to be rewritten using some native
* functions as prototype setup using normal JavaScript does not work as
* expected during bootstrapping (see mirror.js in r114903).
*
* @param {function} ctor Constructor function which needs to inherit the
* prototype.
* @param {function} superCtor Constructor function to inherit prototype from.
*/
exports.inherits = __webpack_require__("4Bm0");
exports._extend = function (origin, add) {
// Don't do anything if add isn't an object
if (!add || !isObject(add)) return origin;
var keys = Object.keys(add);
var i = keys.length;
while (i--) {
origin[keys[i]] = add[keys[i]];
}
return origin;
};
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__("h6ac")))
/***/ }),
/***/ "ggoL":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
CodeMirror.defineMode("css", function (config, parserConfig) {
var inline = parserConfig.inline;
if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
var indentUnit = config.indentUnit,
tokenHooks = parserConfig.tokenHooks,
documentTypes = parserConfig.documentTypes || {},
mediaTypes = parserConfig.mediaTypes || {},
mediaFeatures = parserConfig.mediaFeatures || {},
mediaValueKeywords = parserConfig.mediaValueKeywords || {},
propertyKeywords = parserConfig.propertyKeywords || {},
nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
fontProperties = parserConfig.fontProperties || {},
counterDescriptors = parserConfig.counterDescriptors || {},
colorKeywords = parserConfig.colorKeywords || {},
valueKeywords = parserConfig.valueKeywords || {},
allowNested = parserConfig.allowNested,
lineComment = parserConfig.lineComment,
supportsAtComponent = parserConfig.supportsAtComponent === true;
var type, override;
function ret(style, tp) {
type = tp;return style;
}
// Tokenizers
function tokenBase(stream, state) {
var ch = stream.next();
if (tokenHooks[ch]) {
var result = tokenHooks[ch](stream, state);
if (result !== false) return result;
}
if (ch == "@") {
stream.eatWhile(/[\w\\\-]/);
return ret("def", stream.current());
} else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
return ret(null, "compare");
} else if (ch == "\"" || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
} else if (ch == "#") {
stream.eatWhile(/[\w\\\-]/);
return ret("atom", "hash");
} else if (ch == "!") {
stream.match(/^\s*\w*/);
return ret("keyword", "important");
} else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
} else if (ch === "-") {
if (/[\d.]/.test(stream.peek())) {
stream.eatWhile(/[\w.%]/);
return ret("number", "unit");
} else if (stream.match(/^-[\w\\\-]+/)) {
stream.eatWhile(/[\w\\\-]/);
if (stream.match(/^\s*:/, false)) return ret("variable-2", "variable-definition");
return ret("variable-2", "variable");
} else if (stream.match(/^\w+-/)) {
return ret("meta", "meta");
}
} else if (/[,+>*\/]/.test(ch)) {
return ret(null, "select-op");
} else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
return ret("qualifier", "qualifier");
} else if (/[:;{}\[\]\(\)]/.test(ch)) {
return ret(null, ch);
} else if ((ch == "u" || ch == "U") && stream.match(/rl(-prefix)?\(/i) || (ch == "d" || ch == "D") && stream.match("omain(", true, true) || (ch == "r" || ch == "R") && stream.match("egexp(", true, true)) {
stream.backUp(1);
state.tokenize = tokenParenthesized;
return ret("property", "word");
} else if (/[\w\\\-]/.test(ch)) {
stream.eatWhile(/[\w\\\-]/);
return ret("property", "word");
} else {
return ret(null, null);
}
}
function tokenString(quote) {
return function (stream, state) {
var escaped = false,
ch;
while ((ch = stream.next()) != null) {
if (ch == quote && !escaped) {
if (quote == ")") stream.backUp(1);
break;
}
escaped = !escaped && ch == "\\";
}
if (ch == quote || !escaped && quote != ")") state.tokenize = null;
return ret("string", "string");
};
}
function tokenParenthesized(stream, state) {
stream.next(); // Must be '('
if (!stream.match(/\s*[\"\')]/, false)) state.tokenize = tokenString(")");else state.tokenize = null;
return ret(null, "(");
}
// Context management
function Context(type, indent, prev) {
this.type = type;
this.indent = indent;
this.prev = prev;
}
function pushContext(state, stream, type, indent) {
state.context = new Context(type, stream.indentation() + (indent === false ? 0 : indentUnit), state.context);
return type;
}
function popContext(state) {
if (state.context.prev) state.context = state.context.prev;
return state.context.type;
}
function pass(type, stream, state) {
return states[state.context.type](type, stream, state);
}
function popAndPass(type, stream, state, n) {
for (var i = n || 1; i > 0; i--) state.context = state.context.prev;
return pass(type, stream, state);
}
// Parser
function wordAsValue(stream) {
var word = stream.current().toLowerCase();
if (valueKeywords.hasOwnProperty(word)) override = "atom";else if (colorKeywords.hasOwnProperty(word)) override = "keyword";else override = "variable";
}
var states = {};
states.top = function (type, stream, state) {
if (type == "{") {
return pushContext(state, stream, "block");
} else if (type == "}" && state.context.prev) {
return popContext(state);
} else if (supportsAtComponent && /@component/i.test(type)) {
return pushContext(state, stream, "atComponentBlock");
} else if (/^@(-moz-)?document$/i.test(type)) {
return pushContext(state, stream, "documentTypes");
} else if (/^@(media|supports|(-moz-)?document|import)$/i.test(type)) {
return pushContext(state, stream, "atBlock");
} else if (/^@(font-face|counter-style)/i.test(type)) {
state.stateArg = type;
return "restricted_atBlock_before";
} else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/i.test(type)) {
return "keyframes";
} else if (type && type.charAt(0) == "@") {
return pushContext(state, stream, "at");
} else if (type == "hash") {
override = "builtin";
} else if (type == "word") {
override = "tag";
} else if (type == "variable-definition") {
return "maybeprop";
} else if (type == "interpolation") {
return pushContext(state, stream, "interpolation");
} else if (type == ":") {
return "pseudo";
} else if (allowNested && type == "(") {
return pushContext(state, stream, "parens");
}
return state.context.type;
};
states.block = function (type, stream, state) {
if (type == "word") {
var word = stream.current().toLowerCase();
if (propertyKeywords.hasOwnProperty(word)) {
override = "property";
return "maybeprop";
} else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
override = "string-2";
return "maybeprop";
} else if (allowNested) {
override = stream.match(/^\s*:(?:\s|$)/, false) ? "property" : "tag";
return "block";
} else {
override += " error";
return "maybeprop";
}
} else if (type == "meta") {
return "block";
} else if (!allowNested && (type == "hash" || type == "qualifier")) {
override = "error";
return "block";
} else {
return states.top(type, stream, state);
}
};
states.maybeprop = function (type, stream, state) {
if (type == ":") return pushContext(state, stream, "prop");
return pass(type, stream, state);
};
states.prop = function (type, stream, state) {
if (type == ";") return popContext(state);
if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
if (type == "}" || type == "{") return popAndPass(type, stream, state);
if (type == "(") return pushContext(state, stream, "parens");
if (type == "hash" && !/^#([0-9a-fA-f]{3,4}|[0-9a-fA-f]{6}|[0-9a-fA-f]{8})$/.test(stream.current())) {
override += " error";
} else if (type == "word") {
wordAsValue(stream);
} else if (type == "interpolation") {
return pushContext(state, stream, "interpolation");
}
return "prop";
};
states.propBlock = function (type, _stream, state) {
if (type == "}") return popContext(state);
if (type == "word") {
override = "property";return "maybeprop";
}
return state.context.type;
};
states.parens = function (type, stream, state) {
if (type == "{" || type == "}") return popAndPass(type, stream, state);
if (type == ")") return popContext(state);
if (type == "(") return pushContext(state, stream, "parens");
if (type == "interpolation") return pushContext(state, stream, "interpolation");
if (type == "word") wordAsValue(stream);
return "parens";
};
states.pseudo = function (type, stream, state) {
if (type == "meta") return "pseudo";
if (type == "word") {
override = "variable-3";
return state.context.type;
}
return pass(type, stream, state);
};
states.documentTypes = function (type, stream, state) {
if (type == "word" && documentTypes.hasOwnProperty(stream.current())) {
override = "tag";
return state.context.type;
} else {
return states.atBlock(type, stream, state);
}
};
states.atBlock = function (type, stream, state) {
if (type == "(") return pushContext(state, stream, "atBlock_parens");
if (type == "}" || type == ";") return popAndPass(type, stream, state);
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
if (type == "interpolation") return pushContext(state, stream, "interpolation");
if (type == "word") {
var word = stream.current().toLowerCase();
if (word == "only" || word == "not" || word == "and" || word == "or") override = "keyword";else if (mediaTypes.hasOwnProperty(word)) override = "attribute";else if (mediaFeatures.hasOwnProperty(word)) override = "property";else if (mediaValueKeywords.hasOwnProperty(word)) override = "keyword";else if (propertyKeywords.hasOwnProperty(word)) override = "property";else if (nonStandardPropertyKeywords.hasOwnProperty(word)) override = "string-2";else if (valueKeywords.hasOwnProperty(word)) override = "atom";else if (colorKeywords.hasOwnProperty(word)) override = "keyword";else override = "error";
}
return state.context.type;
};
states.atComponentBlock = function (type, stream, state) {
if (type == "}") return popAndPass(type, stream, state);
if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top", false);
if (type == "word") override = "error";
return state.context.type;
};
states.atBlock_parens = function (type, stream, state) {
if (type == ")") return popContext(state);
if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
return states.atBlock(type, stream, state);
};
states.restricted_atBlock_before = function (type, stream, state) {
if (type == "{") return pushContext(state, stream, "restricted_atBlock");
if (type == "word" && state.stateArg == "@counter-style") {
override = "variable";
return "restricted_atBlock_before";
}
return pass(type, stream, state);
};
states.restricted_atBlock = function (type, stream, state) {
if (type == "}") {
state.stateArg = null;
return popContext(state);
}
if (type == "word") {
if (state.stateArg == "@font-face" && !fontProperties.hasOwnProperty(stream.current().toLowerCase()) || state.stateArg == "@counter-style" && !counterDescriptors.hasOwnProperty(stream.current().toLowerCase())) override = "error";else override = "property";
return "maybeprop";
}
return "restricted_atBlock";
};
states.keyframes = function (type, stream, state) {
if (type == "word") {
override = "variable";return "keyframes";
}
if (type == "{") return pushContext(state, stream, "top");
return pass(type, stream, state);
};
states.at = function (type, stream, state) {
if (type == ";") return popContext(state);
if (type == "{" || type == "}") return popAndPass(type, stream, state);
if (type == "word") override = "tag";else if (type == "hash") override = "builtin";
return "at";
};
states.interpolation = function (type, stream, state) {
if (type == "}") return popContext(state);
if (type == "{" || type == ";") return popAndPass(type, stream, state);
if (type == "word") override = "variable";else if (type != "variable" && type != "(" && type != ")") override = "error";
return "interpolation";
};
return {
startState: function (base) {
return { tokenize: null,
state: inline ? "block" : "top",
stateArg: null,
context: new Context(inline ? "block" : "top", base || 0, null) };
},
token: function (stream, state) {
if (!state.tokenize && stream.eatSpace()) return null;
var style = (state.tokenize || tokenBase)(stream, state);
if (style && typeof style == "object") {
type = style[1];
style = style[0];
}
override = style;
if (type != "comment") state.state = states[state.state](type, stream, state);
return override;
},
indent: function (state, textAfter) {
var cx = state.context,
ch = textAfter && textAfter.charAt(0);
var indent = cx.indent;
if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
if (cx.prev) {
if (ch == "}" && (cx.type == "block" || cx.type == "top" || cx.type == "interpolation" || cx.type == "restricted_atBlock")) {
// Resume indentation from parent context.
cx = cx.prev;
indent = cx.indent;
} else if (ch == ")" && (cx.type == "parens" || cx.type == "atBlock_parens") || ch == "{" && (cx.type == "at" || cx.type == "atBlock")) {
// Dedent relative to current context.
indent = Math.max(0, cx.indent - indentUnit);
}
}
return indent;
},
electricChars: "}",
blockCommentStart: "/*",
blockCommentEnd: "*/",
blockCommentContinue: " * ",
lineComment: lineComment,
fold: "brace"
};
});
function keySet(array) {
var keys = {};
for (var i = 0; i < array.length; ++i) {
keys[array[i].toLowerCase()] = true;
}
return keys;
}
var documentTypes_ = ["domain", "regexp", "url", "url-prefix"],
documentTypes = keySet(documentTypes_);
var mediaTypes_ = ["all", "aural", "braille", "handheld", "print", "projection", "screen", "tty", "tv", "embossed"],
mediaTypes = keySet(mediaTypes_);
var mediaFeatures_ = ["width", "min-width", "max-width", "height", "min-height", "max-height", "device-width", "min-device-width", "max-device-width", "device-height", "min-device-height", "max-device-height", "aspect-ratio", "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio", "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color", "max-color", "color-index", "min-color-index", "max-color-index", "monochrome", "min-monochrome", "max-monochrome", "resolution", "min-resolution", "max-resolution", "scan", "grid", "orientation", "device-pixel-ratio", "min-device-pixel-ratio", "max-device-pixel-ratio", "pointer", "any-pointer", "hover", "any-hover"],
mediaFeatures = keySet(mediaFeatures_);
var mediaValueKeywords_ = ["landscape", "portrait", "none", "coarse", "fine", "on-demand", "hover", "interlace", "progressive"],
mediaValueKeywords = keySet(mediaValueKeywords_);
var propertyKeywords_ = ["align-content", "align-items", "align-self", "alignment-adjust", "alignment-baseline", "anchor-point", "animation", "animation-delay", "animation-direction", "animation-duration", "animation-fill-mode", "animation-iteration-count", "animation-name", "animation-play-state", "animation-timing-function", "appearance", "azimuth", "backface-visibility", "background", "background-attachment", "background-blend-mode", "background-clip", "background-color", "background-image", "background-origin", "background-position", "background-repeat", "background-size", "baseline-shift", "binding", "bleed", "bookmark-label", "bookmark-level", "bookmark-state", "bookmark-target", "border", "border-bottom", "border-bottom-color", "border-bottom-left-radius", "border-bottom-right-radius", "border-bottom-style", "border-bottom-width", "border-collapse", "border-color", "border-image", "border-image-outset", "border-image-repeat", "border-image-slice", "border-image-source", "border-image-width", "border-left", "border-left-color", "border-left-style", "border-left-width", "border-radius", "border-right", "border-right-color", "border-right-style", "border-right-width", "border-spacing", "border-style", "border-top", "border-top-color", "border-top-left-radius", "border-top-right-radius", "border-top-style", "border-top-width", "border-width", "bottom", "box-decoration-break", "box-shadow", "box-sizing", "break-after", "break-before", "break-inside", "caption-side", "caret-color", "clear", "clip", "color", "color-profile", "column-count", "column-fill", "column-gap", "column-rule", "column-rule-color", "column-rule-style", "column-rule-width", "column-span", "column-width", "columns", "content", "counter-increment", "counter-reset", "crop", "cue", "cue-after", "cue-before", "cursor", "direction", "display", "dominant-baseline", "drop-initial-after-adjust", "drop-initial-after-align", "drop-initial-before-adjust", "drop-initial-before-align", "drop-initial-size", "drop-initial-value", "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis", "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap", "float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings", "font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-synthesis", "font-variant", "font-variant-alternates", "font-variant-caps", "font-variant-east-asian", "font-variant-ligatures", "font-variant-numeric", "font-variant-position", "font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow", "grid-auto-rows", "grid-column", "grid-column-end", "grid-column-gap", "grid-column-start", "grid-gap", "grid-row", "grid-row-end", "grid-row-gap", "grid-row-start", "grid-template", "grid-template-areas", "grid-template-columns", "grid-template-rows", "hanging-punctuation", "height", "hyphens", "icon", "image-orientation", "image-rendering", "image-resolution", "inline-box-align", "justify-content", "justify-items", "justify-self", "left", "letter-spacing", "line-break", "line-height", "line-stacking", "line-stacking-ruby", "line-stacking-shift", "line-stacking-strategy", "list-style", "list-style-image", "list-style-position", "list-style-type", "margin", "margin-bottom", "margin-left", "margin-right", "margin-top", "marks", "marquee-direction", "marquee-loop", "marquee-play-count", "marquee-speed", "marquee-style", "max-height", "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index", "nav-left", "nav-right", "nav-up", "object-fit", "object-position", "opacity", "order", "orphans", "outline", "outline-color", "outline-offset", "outline-style", "outline-width", "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y", "padding", "padding-bottom", "padding-left", "padding-right", "padding-top", "page", "page-break-after", "page-break-before", "page-break-inside", "page-policy", "pause", "pause-after", "pause-before", "perspective", "perspective-origin", "pitch", "pitch-range", "place-content", "place-items", "place-self", "play-during", "position", "presentation-level", "punctuation-trim", "quotes", "region-break-after", "region-break-before", "region-break-inside", "region-fragment", "rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness", "right", "rotation", "rotation-point", "ruby-align", "ruby-overhang", "ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin", "shape-outside", "size", "speak", "speak-as", "speak-header", "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set", "tab-size", "table-layout", "target", "target-name", "target-new", "target-position", "text-align", "text-align-last", "text-decoration", "text-decoration-color", "text-decoration-line", "text-decoration-skip", "text-decoration-style", "text-emphasis", "text-emphasis-color", "text-emphasis-position", "text-emphasis-style", "text-height", "text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow", "text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position", "text-wrap", "top", "transform", "transform-origin", "transform-style", "transition", "transition-delay", "transition-duration", "transition-property", "transition-timing-function", "unicode-bidi", "user-select", "vertical-align", "visibility", "voice-balance", "voice-duration", "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress", "voice-volume", "volume", "white-space", "widows", "width", "will-change", "word-break", "word-spacing", "word-wrap", "z-index",
// SVG-specific
"clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color", "flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events", "color-interpolation", "color-interpolation-filters", "color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering", "marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering", "baseline-shift", "dominant-baseline", "glyph-orientation-horizontal", "glyph-orientation-vertical", "text-anchor", "writing-mode"],
propertyKeywords = keySet(propertyKeywords_);
var nonStandardPropertyKeywords_ = ["scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color", "scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color", "scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside", "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button", "searchfield-results-decoration", "zoom"],
nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
var fontProperties_ = ["font-family", "src", "unicode-range", "font-variant", "font-feature-settings", "font-stretch", "font-weight", "font-style"],
fontProperties = keySet(fontProperties_);
var counterDescriptors_ = ["additive-symbols", "fallback", "negative", "pad", "prefix", "range", "speak-as", "suffix", "symbols", "system"],
counterDescriptors = keySet(counterDescriptors_);
var colorKeywords_ = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen"],
colorKeywords = keySet(colorKeywords_);
var valueKeywords_ = ["above", "absolute", "activeborder", "additive", "activecaption", "afar", "after-white-space", "ahead", "alias", "all", "all-scroll", "alphabetic", "alternate", "always", "amharic", "amharic-abegede", "antialiased", "appworkspace", "arabic-indic", "armenian", "asterisks", "attr", "auto", "auto-flow", "avoid", "avoid-column", "avoid-page", "avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary", "bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box", "both", "bottom", "break", "break-all", "break-word", "bullets", "button", "button-bevel", "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "calc", "cambodian", "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret", "cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch", "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote", "col-resize", "collapse", "color", "color-burn", "color-dodge", "column", "column-reverse", "compact", "condensed", "contain", "content", "contents", "content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop", "cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal", "decimal-leading-zero", "default", "default-button", "dense", "destination-atop", "destination-in", "destination-out", "destination-over", "devanagari", "difference", "disc", "discard", "disclosure-closed", "disclosure-open", "document", "dot-dash", "dot-dot-dash", "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", "element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede", "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er", "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er", "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et", "ethiopic-halehame-gez", "ethiopic-halehame-om-et", "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et", "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig", "ethiopic-numeric", "ew-resize", "exclusion", "expanded", "extends", "extra-condensed", "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes", "forwards", "from", "geometricPrecision", "georgian", "graytext", "grid", "groove", "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hard-light", "hebrew", "help", "hidden", "hide", "higher", "highlight", "highlighttext", "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "hue", "icon", "ignore", "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis", "inline-block", "inline-flex", "inline-grid", "inline-table", "inset", "inside", "intrinsic", "invert", "italic", "japanese-formal", "japanese-informal", "justify", "kannada", "katakana", "katakana-iroha", "keep-all", "khmer", "korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal", "landscape", "lao", "large", "larger", "left", "level", "lighter", "lighten", "line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem", "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian", "lower-roman", "lowercase", "ltr", "luminosity", "malayalam", "match", "matrix", "matrix3d", "media-controls-background", "media-current-time-display", "media-fullscreen-button", "media-mute-button", "media-play-button", "media-return-to-realtime-button", "media-rewind-button", "media-seek-back-button", "media-seek-forward-button", "media-slider", "media-sliderthumb", "media-time-remaining-display", "media-volume-slider", "media-volume-slider-container", "media-volume-sliderthumb", "medium", "menu", "menulist", "menulist-button", "menulist-text", "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", "mix", "mongolian", "monospace", "move", "multiple", "multiply", "myanmar", "n-resize", "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap", "ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "opacity", "open-quote", "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset", "outside", "outside-shape", "overlay", "overline", "padding", "padding-box", "painted", "page", "paused", "persian", "perspective", "plus-darker", "plus-lighter", "pointer", "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button", "radial-gradient", "radio", "read-only", "read-write", "read-write-plaintext-only", "rectangle", "region", "relative", "repeat", "repeating-linear-gradient", "repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY", "rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running", "s-resize", "sans-serif", "saturation", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "screen", "scroll", "scrollbar", "scroll-position", "se-resize", "searchfield", "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button", "searchfield-results-decoration", "self-start", "self-end", "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama", "simp-chinese-formal", "simp-chinese-informal", "single", "skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal", "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow", "small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "somali", "source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "space-evenly", "spell-out", "square", "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub", "subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "system-ui", "table", "table-caption", "table-cell", "table-column", "table-column-group", "table-footer-group", "table-header-group", "table-row", "table-row-group", "tamil", "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai", "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight", "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er", "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top", "trad-chinese-formal", "trad-chinese-informal", "transform", "translate", "translate3d", "translateX", "translateY", "translateZ", "transparent", "ultra-condensed", "ultra-expanded", "underline", "unset", "up", "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal", "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", "var", "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted", "visibleStroke", "visual", "w-resize", "wait", "wave", "wider", "window", "windowframe", "windowtext", "words", "wrap", "wrap-reverse", "x-large", "x-small", "xor", "xx-large", "xx-small"],
valueKeywords = keySet(valueKeywords_);
var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(mediaValueKeywords_).concat(propertyKeywords_).concat(nonStandardPropertyKeywords_).concat(colorKeywords_).concat(valueKeywords_);
CodeMirror.registerHelper("hintWords", "css", allWords);
function tokenCComment(stream, state) {
var maybeEnd = false,
ch;
while ((ch = stream.next()) != null) {
if (maybeEnd && ch == "/") {
state.tokenize = null;
break;
}
maybeEnd = ch == "*";
}
return ["comment", "comment"];
}
CodeMirror.defineMIME("text/css", {
documentTypes: documentTypes,
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
mediaValueKeywords: mediaValueKeywords,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
fontProperties: fontProperties,
counterDescriptors: counterDescriptors,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
tokenHooks: {
"/": function (stream, state) {
if (!stream.eat("*")) return false;
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
}
},
name: "css"
});
CodeMirror.defineMIME("text/x-scss", {
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
mediaValueKeywords: mediaValueKeywords,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
fontProperties: fontProperties,
allowNested: true,
lineComment: "//",
tokenHooks: {
"/": function (stream, state) {
if (stream.eat("/")) {
stream.skipToEnd();
return ["comment", "comment"];
} else if (stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
} else {
return ["operator", "operator"];
}
},
":": function (stream) {
if (stream.match(/\s*\{/, false)) return [null, null];
return false;
},
"$": function (stream) {
stream.match(/^[\w-]+/);
if (stream.match(/^\s*:/, false)) return ["variable-2", "variable-definition"];
return ["variable-2", "variable"];
},
"#": function (stream) {
if (!stream.eat("{")) return false;
return [null, "interpolation"];
}
},
name: "css",
helperType: "scss"
});
CodeMirror.defineMIME("text/x-less", {
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
mediaValueKeywords: mediaValueKeywords,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
fontProperties: fontProperties,
allowNested: true,
lineComment: "//",
tokenHooks: {
"/": function (stream, state) {
if (stream.eat("/")) {
stream.skipToEnd();
return ["comment", "comment"];
} else if (stream.eat("*")) {
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
} else {
return ["operator", "operator"];
}
},
"@": function (stream) {
if (stream.eat("{")) return [null, "interpolation"];
if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/i, false)) return false;
stream.eatWhile(/[\w\\\-]/);
if (stream.match(/^\s*:/, false)) return ["variable-2", "variable-definition"];
return ["variable-2", "variable"];
},
"&": function () {
return ["atom", "atom"];
}
},
name: "css",
helperType: "less"
});
CodeMirror.defineMIME("text/x-gss", {
documentTypes: documentTypes,
mediaTypes: mediaTypes,
mediaFeatures: mediaFeatures,
propertyKeywords: propertyKeywords,
nonStandardPropertyKeywords: nonStandardPropertyKeywords,
fontProperties: fontProperties,
counterDescriptors: counterDescriptors,
colorKeywords: colorKeywords,
valueKeywords: valueKeywords,
supportsAtComponent: true,
tokenHooks: {
"/": function (stream, state) {
if (!stream.eat("*")) return false;
state.tokenize = tokenCComment;
return tokenCComment(stream, state);
}
},
name: "css",
helperType: "gss"
});
});
/***/ }),
/***/ "h6ac":
/***/ (function(module, exports) {
var g;
// This works in non-strict mode
g = function () {
return this;
}();
try {
// This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1, eval)("this");
} catch (e) {
// This works if the window reference is available
if (typeof window === "object") g = window;
}
// g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}
module.exports = g;
/***/ }),
/***/ "m+Gh":
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(global) {
if (!global.Promise) global.Promise = __webpack_require__("BtxX");
if (!global.fetch) global.fetch = __webpack_require__("VS7n");
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__("h6ac")))
/***/ }),
/***/ "mSND":
/***/ (function(module, exports, __webpack_require__) {
/*! Split.js - v1.3.5 */
(function (global, factory) {
true ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.Split = factory();
})(this, function () {
'use strict';
// The programming goals of Split.js are to deliver readable, understandable and
// maintainable code, while at the same time manually optimizing for tiny minified file size,
// browser compatibility without additional requirements, graceful fallback (IE8 is supported)
// and very few assumptions about the user's page layout.
var global = window;
var document = global.document;
// Save a couple long function names that are used frequently.
// This optimization saves around 400 bytes.
var addEventListener = 'addEventListener';
var removeEventListener = 'removeEventListener';
var getBoundingClientRect = 'getBoundingClientRect';
var NOOP = function () {
return false;
};
// Figure out if we're in IE8 or not. IE8 will still render correctly,
// but will be static instead of draggable.
var isIE8 = global.attachEvent && !global[addEventListener];
// This library only needs two helper functions:
//
// The first determines which prefixes of CSS calc we need.
// We only need to do this once on startup, when this anonymous function is called.
//
// Tests -webkit, -moz and -o prefixes. Modified from StackOverflow:
// http://stackoverflow.com/questions/16625140/js-feature-detection-to-detect-the-usage-of-webkit-calc-over-calc/16625167#16625167
var calc = ['', '-webkit-', '-moz-', '-o-'].filter(function (prefix) {
var el = document.createElement('div');
el.style.cssText = "width:" + prefix + "calc(9px)";
return !!el.style.length;
}).shift() + "calc";
// The second helper function allows elements and string selectors to be used
// interchangeably. In either case an element is returned. This allows us to
// do `Split([elem1, elem2])` as well as `Split(['#id1', '#id2'])`.
var elementOrSelector = function (el) {
if (typeof el === 'string' || el instanceof String) {
return document.querySelector(el);
}
return el;
};
// The main function to initialize a split. Split.js thinks about each pair
// of elements as an independant pair. Dragging the gutter between two elements
// only changes the dimensions of elements in that pair. This is key to understanding
// how the following functions operate, since each function is bound to a pair.
//
// A pair object is shaped like this:
//
// {
// a: DOM element,
// b: DOM element,
// aMin: Number,
// bMin: Number,
// dragging: Boolean,
// parent: DOM element,
// isFirst: Boolean,
// isLast: Boolean,
// direction: 'horizontal' | 'vertical'
// }
//
// The basic sequence:
//
// 1. Set defaults to something sane. `options` doesn't have to be passed at all.
// 2. Initialize a bunch of strings based on the direction we're splitting.
// A lot of the behavior in the rest of the library is paramatized down to
// rely on CSS strings and classes.
// 3. Define the dragging helper functions, and a few helpers to go with them.
// 4. Loop through the elements while pairing them off. Every pair gets an
// `pair` object, a gutter, and special isFirst/isLast properties.
// 5. Actually size the pair elements, insert gutters and attach event listeners.
var Split = function (ids, options) {
if (options === void 0) options = {};
var dimension;
var clientDimension;
var clientAxis;
var position;
var paddingA;
var paddingB;
var elements;
// All DOM elements in the split should have a common parent. We can grab
// the first elements parent and hope users read the docs because the
// behavior will be whacky otherwise.
var parent = elementOrSelector(ids[0]).parentNode;
var parentFlexDirection = global.getComputedStyle(parent).flexDirection;
// Set default options.sizes to equal percentages of the parent element.
var sizes = options.sizes || ids.map(function () {
return 100 / ids.length;
});
// Standardize minSize to an array if it isn't already. This allows minSize
// to be passed as a number.
var minSize = options.minSize !== undefined ? options.minSize : 100;
var minSizes = Array.isArray(minSize) ? minSize : ids.map(function () {
return minSize;
});
var gutterSize = options.gutterSize !== undefined ? options.gutterSize : 10;
var snapOffset = options.snapOffset !== undefined ? options.snapOffset : 30;
var direction = options.direction || 'horizontal';
var cursor = options.cursor || (direction === 'horizontal' ? 'ew-resize' : 'ns-resize');
var gutter = options.gutter || function (i, gutterDirection) {
var gut = document.createElement('div');
gut.className = "gutter gutter-" + gutterDirection;
return gut;
};
var elementStyle = options.elementStyle || function (dim, size, gutSize) {
var style = {};
if (typeof size !== 'string' && !(size instanceof String)) {
if (!isIE8) {
style[dim] = calc + "(" + size + "% - " + gutSize + "px)";
} else {
style[dim] = size + "%";
}
} else {
style[dim] = size;
}
return style;
};
var gutterStyle = options.gutterStyle || function (dim, gutSize) {
return obj = {}, obj[dim] = gutSize + "px", obj;
var obj;
};
// 2. Initialize a bunch of strings based on the direction we're splitting.
// A lot of the behavior in the rest of the library is paramatized down to
// rely on CSS strings and classes.
if (direction === 'horizontal') {
dimension = 'width';
clientDimension = 'clientWidth';
clientAxis = 'clientX';
position = 'left';
paddingA = 'paddingLeft';
paddingB = 'paddingRight';
} else if (direction === 'vertical') {
dimension = 'height';
clientDimension = 'clientHeight';
clientAxis = 'clientY';
position = 'top';
paddingA = 'paddingTop';
paddingB = 'paddingBottom';
}
// 3. Define the dragging helper functions, and a few helpers to go with them.
// Each helper is bound to a pair object that contains it's metadata. This
// also makes it easy to store references to listeners that that will be
// added and removed.
//
// Even though there are no other functions contained in them, aliasing
// this to self saves 50 bytes or so since it's used so frequently.
//
// The pair object saves metadata like dragging state, position and
// event listener references.
function setElementSize(el, size, gutSize) {
// Split.js allows setting sizes via numbers (ideally), or if you must,
// by string, like '300px'. This is less than ideal, because it breaks
// the fluid layout that `calc(% - px)` provides. You're on your own if you do that,
// make sure you calculate the gutter size by hand.
var style = elementStyle(dimension, size, gutSize);
// eslint-disable-next-line no-param-reassign
Object.keys(style).forEach(function (prop) {
return el.style[prop] = style[prop];
});
}
function setGutterSize(gutterElement, gutSize) {
var style = gutterStyle(dimension, gutSize);
// eslint-disable-next-line no-param-reassign
Object.keys(style).forEach(function (prop) {
return gutterElement.style[prop] = style[prop];
});
}
// Actually adjust the size of elements `a` and `b` to `offset` while dragging.
// calc is used to allow calc(percentage + gutterpx) on the whole split instance,
// which allows the viewport to be resized without additional logic.
// Element a's size is the same as offset. b's size is total size - a size.
// Both sizes are calculated from the initial parent percentage,
// then the gutter size is subtracted.
function adjust(offset) {
var a = elements[this.a];
var b = elements[this.b];
var percentage = a.size + b.size;
a.size = offset / this.size * percentage;
b.size = percentage - offset / this.size * percentage;
setElementSize(a.element, a.size, this.aGutterSize);
setElementSize(b.element, b.size, this.bGutterSize);
}
// drag, where all the magic happens. The logic is really quite simple:
//
// 1. Ignore if the pair is not dragging.
// 2. Get the offset of the event.
// 3. Snap offset to min if within snappable range (within min + snapOffset).
// 4. Actually adjust each element in the pair to offset.
//
// ---------------------------------------------------------------------
// | | <- a.minSize || b.minSize -> | |
// | | | <- this.snapOffset || this.snapOffset -> | | |
// | | | || | | |
// | | | || | | |
// ---------------------------------------------------------------------
// | <- this.start this.size -> |
function drag(e) {
var offset;
if (!this.dragging) {
return;
}
// Get the offset of the event from the first side of the
// pair `this.start`. Supports touch events, but not multitouch, so only the first
// finger `touches[0]` is counted.
if ('touches' in e) {
offset = e.touches[0][clientAxis] - this.start;
} else {
offset = e[clientAxis] - this.start;
}
// If within snapOffset of min or max, set offset to min or max.
// snapOffset buffers a.minSize and b.minSize, so logic is opposite for both.
// Include the appropriate gutter sizes to prevent overflows.
if (offset <= elements[this.a].minSize + snapOffset + this.aGutterSize) {
offset = elements[this.a].minSize + this.aGutterSize;
} else if (offset >= this.size - (elements[this.b].minSize + snapOffset + this.bGutterSize)) {
offset = this.size - (elements[this.b].minSize + this.bGutterSize);
}
// Actually adjust the size.
adjust.call(this, offset);
// Call the drag callback continously. Don't do anything too intensive
// in this callback.
if (options.onDrag) {
options.onDrag();
}
}
// Cache some important sizes when drag starts, so we don't have to do that
// continously:
//
// `size`: The total size of the pair. First + second + first gutter + second gutter.
// `start`: The leading side of the first element.
//
// ------------------------------------------------
// | aGutterSize -> ||| |
// | ||| |
// | ||| |
// | ||| <- bGutterSize |
// ------------------------------------------------
// | <- start size -> |
function calculateSizes() {
// Figure out the parent size minus padding.
var a = elements[this.a].element;
var b = elements[this.b].element;
this.size = a[getBoundingClientRect]()[dimension] + b[getBoundingClientRect]()[dimension] + this.aGutterSize + this.bGutterSize;
this.start = a[getBoundingClientRect]()[position];
}
// stopDragging is very similar to startDragging in reverse.
function stopDragging() {
var self = this;
var a = elements[self.a].element;
var b = elements[self.b].element;
if (self.dragging && options.onDragEnd) {
options.onDragEnd();
}
self.dragging = false;
// Remove the stored event listeners. This is why we store them.
global[removeEventListener]('mouseup', self.stop);
global[removeEventListener]('touchend', self.stop);
global[removeEventListener]('touchcancel', self.stop);
self.parent[removeEventListener]('mousemove', self.move);
self.parent[removeEventListener]('touchmove', self.move);
// Delete them once they are removed. I think this makes a difference
// in memory usage with a lot of splits on one page. But I don't know for sure.
delete self.stop;
delete self.move;
a[removeEventListener]('selectstart', NOOP);
a[removeEventListener]('dragstart', NOOP);
b[removeEventListener]('selectstart', NOOP);
b[removeEventListener]('dragstart', NOOP);
a.style.userSelect = '';
a.style.webkitUserSelect = '';
a.style.MozUserSelect = '';
a.style.pointerEvents = '';
b.style.userSelect = '';
b.style.webkitUserSelect = '';
b.style.MozUserSelect = '';
b.style.pointerEvents = '';
self.gutter.style.cursor = '';
self.parent.style.cursor = '';
}
// startDragging calls `calculateSizes` to store the inital size in the pair object.
// It also adds event listeners for mouse/touch events,
// and prevents selection while dragging so avoid the selecting text.
function startDragging(e) {
// Alias frequently used variables to save space. 200 bytes.
var self = this;
var a = elements[self.a].element;
var b = elements[self.b].element;
// Call the onDragStart callback.
if (!self.dragging && options.onDragStart) {
options.onDragStart();
}
// Don't actually drag the element. We emulate that in the drag function.
e.preventDefault();
// Set the dragging property of the pair object.
self.dragging = true;
// Create two event listeners bound to the same pair object and store
// them in the pair object.
self.move = drag.bind(self);
self.stop = stopDragging.bind(self);
// All the binding. `window` gets the stop events in case we drag out of the elements.
global[addEventListener]('mouseup', self.stop);
global[addEventListener]('touchend', self.stop);
global[addEventListener]('touchcancel', self.stop);
self.parent[addEventListener]('mousemove', self.move);
self.parent[addEventListener]('touchmove', self.move);
// Disable selection. Disable!
a[addEventListener]('selectstart', NOOP);
a[addEventListener]('dragstart', NOOP);
b[addEventListener]('selectstart', NOOP);
b[addEventListener]('dragstart', NOOP);
a.style.userSelect = 'none';
a.style.webkitUserSelect = 'none';
a.style.MozUserSelect = 'none';
a.style.pointerEvents = 'none';
b.style.userSelect = 'none';
b.style.webkitUserSelect = 'none';
b.style.MozUserSelect = 'none';
b.style.pointerEvents = 'none';
// Set the cursor, both on the gutter and the parent element.
// Doing only a, b and gutter causes flickering.
self.gutter.style.cursor = cursor;
self.parent.style.cursor = cursor;
// Cache the initial sizes of the pair.
calculateSizes.call(self);
}
// 5. Create pair and element objects. Each pair has an index reference to
// elements `a` and `b` of the pair (first and second elements).
// Loop through the elements while pairing them off. Every pair gets a
// `pair` object, a gutter, and isFirst/isLast properties.
//
// Basic logic:
//
// - Starting with the second element `i > 0`, create `pair` objects with
// `a = i - 1` and `b = i`
// - Set gutter sizes based on the _pair_ being first/last. The first and last
// pair have gutterSize / 2, since they only have one half gutter, and not two.
// - Create gutter elements and add event listeners.
// - Set the size of the elements, minus the gutter sizes.
//
// -----------------------------------------------------------------------
// | i=0 | i=1 | i=2 | i=3 |
// | | isFirst | | isLast |
// | pair 0 pair 1 pair 2 |
// | | | | |
// -----------------------------------------------------------------------
var pairs = [];
elements = ids.map(function (id, i) {
// Create the element object.
var element = {
element: elementOrSelector(id),
size: sizes[i],
minSize: minSizes[i]
};
var pair;
if (i > 0) {
// Create the pair object with it's metadata.
pair = {
a: i - 1,
b: i,
dragging: false,
isFirst: i === 1,
isLast: i === ids.length - 1,
direction: direction,
parent: parent
};
// For first and last pairs, first and last gutter width is half.
pair.aGutterSize = gutterSize;
pair.bGutterSize = gutterSize;
if (pair.isFirst) {
pair.aGutterSize = gutterSize / 2;
}
if (pair.isLast) {
pair.bGutterSize = gutterSize / 2;
}
// if the parent has a reverse flex-direction, switch the pair elements.
if (parentFlexDirection === 'row-reverse' || parentFlexDirection === 'column-reverse') {
var temp = pair.a;
pair.a = pair.b;
pair.b = temp;
}
}
// Determine the size of the current element. IE8 is supported by
// staticly assigning sizes without draggable gutters. Assigns a string
// to `size`.
//
// IE9 and above
if (!isIE8) {
// Create gutter elements for each pair.
if (i > 0) {
var gutterElement = gutter(i, direction);
setGutterSize(gutterElement, gutterSize);
gutterElement[addEventListener]('mousedown', startDragging.bind(pair));
gutterElement[addEventListener]('touchstart', startDragging.bind(pair));
parent.insertBefore(gutterElement, element.element);
pair.gutter = gutterElement;
}
}
// Set the element size to our determined size.
// Half-size gutters for first and last elements.
if (i === 0 || i === ids.length - 1) {
setElementSize(element.element, element.size, gutterSize / 2);
} else {
setElementSize(element.element, element.size, gutterSize);
}
var computedSize = element.element[getBoundingClientRect]()[dimension];
if (computedSize < element.minSize) {
element.minSize = computedSize;
}
// After the first iteration, and we have a pair object, append it to the
// list of pairs.
if (i > 0) {
pairs.push(pair);
}
return element;
});
function setSizes(newSizes) {
newSizes.forEach(function (newSize, i) {
if (i > 0) {
var pair = pairs[i - 1];
var a = elements[pair.a];
var b = elements[pair.b];
a.size = newSizes[i - 1];
b.size = newSize;
setElementSize(a.element, a.size, pair.aGutterSize);
setElementSize(b.element, b.size, pair.bGutterSize);
}
});
}
function destroy() {
pairs.forEach(function (pair) {
pair.parent.removeChild(pair.gutter);
elements[pair.a].element.style[dimension] = '';
elements[pair.b].element.style[dimension] = '';
});
}
if (isIE8) {
return {
setSizes: setSizes,
destroy: destroy
};
}
return {
setSizes: setSizes,
getSizes: function getSizes() {
return elements.map(function (element) {
return element.size;
});
},
collapse: function collapse(i) {
if (i === pairs.length) {
var pair = pairs[i - 1];
calculateSizes.call(pair);
if (!isIE8) {
adjust.call(pair, pair.size - pair.bGutterSize);
}
} else {
var pair$1 = pairs[i];
calculateSizes.call(pair$1);
if (!isIE8) {
adjust.call(pair$1, pair$1.aGutterSize);
}
}
},
destroy: destroy
};
};
return Split;
});
/***/ }),
/***/ "pTe4":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
var defaults = {
pairs: "()[]{}''\"\"",
triples: "",
explode: "[]{}"
};
var Pos = CodeMirror.Pos;
CodeMirror.defineOption("autoCloseBrackets", false, function (cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.removeKeyMap(keyMap);
cm.state.closeBrackets = null;
}
if (val) {
ensureBound(getOption(val, "pairs"));
cm.state.closeBrackets = val;
cm.addKeyMap(keyMap);
}
});
function getOption(conf, name) {
if (name == "pairs" && typeof conf == "string") return conf;
if (typeof conf == "object" && conf[name] != null) return conf[name];
return defaults[name];
}
var keyMap = { Backspace: handleBackspace, Enter: handleEnter };
function ensureBound(chars) {
for (var i = 0; i < chars.length; i++) {
var ch = chars.charAt(i),
key = "'" + ch + "'";
if (!keyMap[key]) keyMap[key] = handler(ch);
}
}
ensureBound(defaults.pairs + "`");
function handler(ch) {
return function (cm) {
return handleChar(cm, ch);
};
}
function getConfig(cm) {
var deflt = cm.state.closeBrackets;
if (!deflt || deflt.override) return deflt;
var mode = cm.getModeAt(cm.getCursor());
return mode.closeBrackets || deflt;
}
function handleBackspace(cm) {
var conf = getConfig(cm);
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
var pairs = getOption(conf, "pairs");
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var around = charsAround(cm, ranges[i].head);
if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
}
for (var i = ranges.length - 1; i >= 0; i--) {
var cur = ranges[i].head;
cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1), "+delete");
}
}
function handleEnter(cm) {
var conf = getConfig(cm);
var explode = conf && getOption(conf, "explode");
if (!explode || cm.getOption("disableInput")) return CodeMirror.Pass;
var ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) return CodeMirror.Pass;
var around = charsAround(cm, ranges[i].head);
if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass;
}
cm.operation(function () {
var linesep = cm.lineSeparator() || "\n";
cm.replaceSelection(linesep + linesep, null);
cm.execCommand("goCharLeft");
ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var line = ranges[i].head.line;
cm.indentLine(line, null, true);
cm.indentLine(line + 1, null, true);
}
});
}
function contractSelection(sel) {
var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
return { anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)),
head: new Pos(sel.head.line, sel.head.ch + (inverted ? 1 : -1)) };
}
function handleChar(cm, ch) {
var conf = getConfig(cm);
if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
var pairs = getOption(conf, "pairs");
var pos = pairs.indexOf(ch);
if (pos == -1) return CodeMirror.Pass;
var triples = getOption(conf, "triples");
var identical = pairs.charAt(pos + 1) == ch;
var ranges = cm.listSelections();
var opening = pos % 2 == 0;
var type;
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i],
cur = range.head,
curType;
var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
if (opening && !range.empty()) {
curType = "surround";
} else if ((identical || !opening) && next == ch) {
if (identical && stringStartsAfter(cm, cur)) curType = "both";else if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch) curType = "skipThree";else curType = "skip";
} else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 && cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch) {
if (cur.ch > 2 && /\bstring/.test(cm.getTokenTypeAt(Pos(cur.line, cur.ch - 2)))) return CodeMirror.Pass;
curType = "addFour";
} else if (identical) {
var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur);
if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both";else return CodeMirror.Pass;
} else if (opening && (cm.getLine(cur.line).length == cur.ch || isClosingBracket(next, pairs) || /\s/.test(next))) {
curType = "both";
} else {
return CodeMirror.Pass;
}
if (!type) type = curType;else if (type != curType) return CodeMirror.Pass;
}
var left = pos % 2 ? pairs.charAt(pos - 1) : ch;
var right = pos % 2 ? ch : pairs.charAt(pos + 1);
cm.operation(function () {
if (type == "skip") {
cm.execCommand("goCharRight");
} else if (type == "skipThree") {
for (var i = 0; i < 3; i++) cm.execCommand("goCharRight");
} else if (type == "surround") {
var sels = cm.getSelections();
for (var i = 0; i < sels.length; i++) sels[i] = left + sels[i] + right;
cm.replaceSelections(sels, "around");
sels = cm.listSelections().slice();
for (var i = 0; i < sels.length; i++) sels[i] = contractSelection(sels[i]);
cm.setSelections(sels);
} else if (type == "both") {
cm.replaceSelection(left + right, null);
cm.triggerElectric(left + right);
cm.execCommand("goCharLeft");
} else if (type == "addFour") {
cm.replaceSelection(left + left + left + left, "before");
cm.execCommand("goCharRight");
}
});
}
function isClosingBracket(ch, pairs) {
var pos = pairs.lastIndexOf(ch);
return pos > -1 && pos % 2 == 1;
}
function charsAround(cm, pos) {
var str = cm.getRange(Pos(pos.line, pos.ch - 1), Pos(pos.line, pos.ch + 1));
return str.length == 2 ? str : null;
}
function stringStartsAfter(cm, pos) {
var token = cm.getTokenAt(Pos(pos.line, pos.ch + 1));
return (/\bstring/.test(token.type) && token.start == pos.ch && (pos.ch == 0 || !/\bstring/.test(cm.getTokenTypeAt(pos)))
);
}
});
/***/ }),
/***/ "pwNi":
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var _preact = __webpack_require__("KM04");
if (false) {
require('preact/devtools');
} else if (true && 'serviceWorker' in navigator && location.protocol === 'https:') {
navigator.serviceWorker.register(__webpack_require__.p + 'sw.js');
}
const interopDefault = m => m && m.default ? m.default : m;
let app = interopDefault(__webpack_require__("JkW7"));
if (typeof app === 'function') {
let root = document.body.firstElementChild;
let init = () => {
let app = interopDefault(__webpack_require__("JkW7"));
root = (0, _preact.render)((0, _preact.h)(app), document.body, root);
};
if (false) module.hot.accept('preact-cli-entrypoint', init);
init();
}
/***/ }),
/***/ "q6qL":
/***/ (function(module, exports, __webpack_require__) {
(function (global, factory) {
true ? module.exports = factory(__webpack_require__("KM04")) : typeof define === 'function' && define.amd ? define(['preact'], factory) : global.preactPortal = factory(global.preact);
})(this, function (preact) {
'use strict';
var asyncGenerator = function () {
function AwaitValue(value) {
this.value = value;
}
function AsyncGenerator(gen) {
var front, back;
function send(key, arg) {
return new Promise(function (resolve, reject) {
var request = {
key: key,
arg: arg,
resolve: resolve,
reject: reject,
next: null
};
if (back) {
back = back.next = request;
} else {
front = back = request;
resume(key, arg);
}
});
}
function resume(key, arg) {
try {
var result = gen[key](arg);
var value = result.value;
if (value instanceof AwaitValue) {
Promise.resolve(value.value).then(function (arg) {
resume("next", arg);
}, function (arg) {
resume("throw", arg);
});
} else {
settle(result.done ? "return" : "normal", result.value);
}
} catch (err) {
settle("throw", err);
}
}
function settle(type, value) {
switch (type) {
case "return":
front.resolve({
value: value,
done: true
});
break;
case "throw":
front.reject(value);
break;
default:
front.resolve({
value: value,
done: false
});
break;
}
front = front.next;
if (front) {
resume(front.key, front.arg);
} else {
back = null;
}
}
this._invoke = send;
if (typeof gen.return !== "function") {
this.return = undefined;
}
}
if (typeof Symbol === "function" && Symbol.asyncIterator) {
AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
return this;
};
}
AsyncGenerator.prototype.next = function (arg) {
return this._invoke("next", arg);
};
AsyncGenerator.prototype.throw = function (arg) {
return this._invoke("throw", arg);
};
AsyncGenerator.prototype.return = function (arg) {
return this._invoke("return", arg);
};
return {
wrap: function (fn) {
return function () {
return new AsyncGenerator(fn.apply(this, arguments));
};
},
await: function (value) {
return new AwaitValue(value);
}
};
}();
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var Portal = function (_Component) {
inherits(Portal, _Component);
function Portal() {
classCallCheck(this, Portal);
return possibleConstructorReturn(this, _Component.apply(this, arguments));
}
Portal.prototype.componentDidUpdate = function componentDidUpdate(props) {
for (var i in props) {
if (props[i] !== this.props[i]) {
return setTimeout(this.renderLayer);
}
}
};
Portal.prototype.componentDidMount = function componentDidMount() {
this.isMounted = true;
this.renderLayer = this.renderLayer.bind(this);
this.renderLayer();
};
Portal.prototype.componentWillUnmount = function componentWillUnmount() {
this.renderLayer(false);
this.isMounted = false;
if (this.remote) this.remote.parentNode.removeChild(this.remote);
};
Portal.prototype.findNode = function findNode(node) {
return typeof node === 'string' ? document.querySelector(node) : node;
};
Portal.prototype.renderLayer = function renderLayer() {
var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
if (!this.isMounted) return;
if (this.props.into !== this.intoPointer) {
this.intoPointer = this.props.into;
if (this.into && this.remote) {
this.remote = preact.render(preact.h(PortalProxy, null), this.into, this.remote);
}
this.into = this.findNode(this.props.into);
}
this.remote = preact.render(preact.h(PortalProxy, { context: this.context }, show && this.props.children || null), this.into, this.remote);
};
Portal.prototype.render = function render() {
return null;
};
return Portal;
}(preact.Component);
var PortalProxy = function (_Component2) {
inherits(PortalProxy, _Component2);
function PortalProxy() {
classCallCheck(this, PortalProxy);
return possibleConstructorReturn(this, _Component2.apply(this, arguments));
}
PortalProxy.prototype.getChildContext = function getChildContext() {
return this.props.context;
};
PortalProxy.prototype.render = function render(_ref) {
var children = _ref.children;
return children && children[0] || null;
};
return PortalProxy;
}(preact.Component);
return Portal;
});
//# sourceMappingURL=preact-portal.js.map
/***/ }),
/***/ "qqFR":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
CodeMirror.defineMode("javascript", function (config, parserConfig) {
var indentUnit = config.indentUnit;
var statementIndent = parserConfig.statementIndent;
var jsonldMode = parserConfig.jsonld;
var jsonMode = parserConfig.json || jsonldMode;
var isTS = parserConfig.typescript;
var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
// Tokenizer
var keywords = function () {
function kw(type) {
return { type: type, style: "keyword" };
}
var A = kw("keyword a"),
B = kw("keyword b"),
C = kw("keyword c"),
D = kw("keyword d");
var operator = kw("operator"),
atom = { type: "atom", style: "atom" };
return {
"if": kw("if"), "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
"return": D, "break": D, "continue": D, "new": kw("new"), "delete": C, "void": C, "throw": C,
"debugger": kw("debugger"), "var": kw("var"), "const": kw("var"), "let": kw("var"),
"function": kw("function"), "catch": kw("catch"),
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
"in": operator, "typeof": operator, "instanceof": operator,
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom,
"this": kw("this"), "class": kw("class"), "super": kw("atom"),
"yield": C, "export": kw("export"), "import": kw("import"), "extends": C,
"await": C
};
}();
var isOperatorChar = /[+\-*&%=<>!?|~^@]/;
var isJsonldKeyword = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)"/;
function readRegexp(stream) {
var escaped = false,
next,
inSet = false;
while ((next = stream.next()) != null) {
if (!escaped) {
if (next == "/" && !inSet) return;
if (next == "[") inSet = true;else if (inSet && next == "]") inSet = false;
}
escaped = !escaped && next == "\\";
}
}
// Used as scratch variables to communicate multiple values without
// consing up tons of objects.
var type, content;
function ret(tp, style, cont) {
type = tp;content = cont;
return style;
}
function tokenBase(stream, state) {
var ch = stream.next();
if (ch == '"' || ch == "'") {
state.tokenize = tokenString(ch);
return state.tokenize(stream, state);
} else if (ch == "." && stream.match(/^\d+(?:[eE][+\-]?\d+)?/)) {
return ret("number", "number");
} else if (ch == "." && stream.match("..")) {
return ret("spread", "meta");
} else if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
return ret(ch);
} else if (ch == "=" && stream.eat(">")) {
return ret("=>", "operator");
} else if (ch == "0" && stream.match(/^(?:x[\da-f]+|o[0-7]+|b[01]+)n?/i)) {
return ret("number", "number");
} else if (/\d/.test(ch)) {
stream.match(/^\d*(?:n|(?:\.\d*)?(?:[eE][+\-]?\d+)?)?/);
return ret("number", "number");
} else if (ch == "/") {
if (stream.eat("*")) {
state.tokenize = tokenComment;
return tokenComment(stream, state);
} else if (stream.eat("/")) {
stream.skipToEnd();
return ret("comment", "comment");
} else if (expressionAllowed(stream, state, 1)) {
readRegexp(stream);
stream.match(/^\b(([gimyus])(?![gimyus]*\2))+\b/);
return ret("regexp", "string-2");
} else {
stream.eat("=");
return ret("operator", "operator", stream.current());
}
} else if (ch == "`") {
state.tokenize = tokenQuasi;
return tokenQuasi(stream, state);
} else if (ch == "#") {
stream.skipToEnd();
return ret("error", "error");
} else if (isOperatorChar.test(ch)) {
if (ch != ">" || !state.lexical || state.lexical.type != ">") {
if (stream.eat("=")) {
if (ch == "!" || ch == "=") stream.eat("=");
} else if (/[<>*+\-]/.test(ch)) {
stream.eat(ch);
if (ch == ">") stream.eat(ch);
}
}
return ret("operator", "operator", stream.current());
} else if (wordRE.test(ch)) {
stream.eatWhile(wordRE);
var word = stream.current();
if (state.lastType != ".") {
if (keywords.propertyIsEnumerable(word)) {
var kw = keywords[word];
return ret(kw.type, kw.style, word);
}
if (word == "async" && stream.match(/^(\s|\/\*.*?\*\/)*[\[\(\w]/, false)) return ret("async", "keyword", word);
}
return ret("variable", "variable", word);
}
}
function tokenString(quote) {
return function (stream, state) {
var escaped = false,
next;
if (jsonldMode && stream.peek() == "@" && stream.match(isJsonldKeyword)) {
state.tokenize = tokenBase;
return ret("jsonld-keyword", "meta");
}
while ((next = stream.next()) != null) {
if (next == quote && !escaped) break;
escaped = !escaped && next == "\\";
}
if (!escaped) state.tokenize = tokenBase;
return ret("string", "string");
};
}
function tokenComment(stream, state) {
var maybeEnd = false,
ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
break;
}
maybeEnd = ch == "*";
}
return ret("comment", "comment");
}
function tokenQuasi(stream, state) {
var escaped = false,
next;
while ((next = stream.next()) != null) {
if (!escaped && (next == "`" || next == "$" && stream.eat("{"))) {
state.tokenize = tokenBase;
break;
}
escaped = !escaped && next == "\\";
}
return ret("quasi", "string-2", stream.current());
}
var brackets = "([{}])";
// This is a crude lookahead trick to try and notice that we're
// parsing the argument patterns for a fat-arrow function before we
// actually hit the arrow token. It only works if the arrow is on
// the same line as the arguments and there's no strange noise
// (comments) in between. Fallback is to only notice when we hit the
// arrow, and not declare the arguments as locals for the arrow
// body.
function findFatArrow(stream, state) {
if (state.fatArrowAt) state.fatArrowAt = null;
var arrow = stream.string.indexOf("=>", stream.start);
if (arrow < 0) return;
if (isTS) {
// Try to skip TypeScript return type declarations after the arguments
var m = /:\s*(?:\w+(?:<[^>]*>|\[\])?|\{[^}]*\})\s*$/.exec(stream.string.slice(stream.start, arrow));
if (m) arrow = m.index;
}
var depth = 0,
sawSomething = false;
for (var pos = arrow - 1; pos >= 0; --pos) {
var ch = stream.string.charAt(pos);
var bracket = brackets.indexOf(ch);
if (bracket >= 0 && bracket < 3) {
if (!depth) {
++pos;break;
}
if (--depth == 0) {
if (ch == "(") sawSomething = true;break;
}
} else if (bracket >= 3 && bracket < 6) {
++depth;
} else if (wordRE.test(ch)) {
sawSomething = true;
} else if (/["'\/]/.test(ch)) {
return;
} else if (sawSomething && !depth) {
++pos;
break;
}
}
if (sawSomething && !depth) state.fatArrowAt = pos;
}
// Parser
var atomicTypes = { "atom": true, "number": true, "variable": true, "string": true, "regexp": true, "this": true, "jsonld-keyword": true };
function JSLexical(indented, column, type, align, prev, info) {
this.indented = indented;
this.column = column;
this.type = type;
this.prev = prev;
this.info = info;
if (align != null) this.align = align;
}
function inScope(state, varname) {
for (var v = state.localVars; v; v = v.next) if (v.name == varname) return true;
for (var cx = state.context; cx; cx = cx.prev) {
for (var v = cx.vars; v; v = v.next) if (v.name == varname) return true;
}
}
function parseJS(state, style, type, content, stream) {
var cc = state.cc;
// Communicate our context to the combinators.
// (Less wasteful than consing up a hundred closures on every call.)
cx.state = state;cx.stream = stream;cx.marked = null, cx.cc = cc;cx.style = style;
if (!state.lexical.hasOwnProperty("align")) state.lexical.align = true;
while (true) {
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
if (combinator(type, content)) {
while (cc.length && cc[cc.length - 1].lex) cc.pop()();
if (cx.marked) return cx.marked;
if (type == "variable" && inScope(state, content)) return "variable-2";
return style;
}
}
}
// Combinator utils
var cx = { state: null, column: null, marked: null, cc: null };
function pass() {
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
}
function cont() {
pass.apply(null, arguments);
return true;
}
function inList(name, list) {
for (var v = list; v; v = v.next) if (v.name == name) return true;
return false;
}
function register(varname) {
var state = cx.state;
cx.marked = "def";
if (state.context) {
if (state.lexical.info == "var" && state.context && state.context.block) {
// FIXME function decls are also not block scoped
var newContext = registerVarScoped(varname, state.context);
if (newContext != null) {
state.context = newContext;
return;
}
} else if (!inList(varname, state.localVars)) {
state.localVars = new Var(varname, state.localVars);
return;
}
}
// Fall through means this is global
if (parserConfig.globalVars && !inList(varname, state.globalVars)) state.globalVars = new Var(varname, state.globalVars);
}
function registerVarScoped(varname, context) {
if (!context) {
return null;
} else if (context.block) {
var inner = registerVarScoped(varname, context.prev);
if (!inner) return null;
if (inner == context.prev) return context;
return new Context(inner, context.vars, true);
} else if (inList(varname, context.vars)) {
return context;
} else {
return new Context(context.prev, new Var(varname, context.vars), false);
}
}
function isModifier(name) {
return name == "public" || name == "private" || name == "protected" || name == "abstract" || name == "readonly";
}
// Combinators
function Context(prev, vars, block) {
this.prev = prev;this.vars = vars;this.block = block;
}
function Var(name, next) {
this.name = name;this.next = next;
}
var defaultVars = new Var("this", new Var("arguments", null));
function pushcontext() {
cx.state.context = new Context(cx.state.context, cx.state.localVars, false);
cx.state.localVars = defaultVars;
}
function pushblockcontext() {
cx.state.context = new Context(cx.state.context, cx.state.localVars, true);
cx.state.localVars = null;
}
function popcontext() {
cx.state.localVars = cx.state.context.vars;
cx.state.context = cx.state.context.prev;
}
popcontext.lex = true;
function pushlex(type, info) {
var result = function () {
var state = cx.state,
indent = state.indented;
if (state.lexical.type == "stat") indent = state.lexical.indented;else for (var outer = state.lexical; outer && outer.type == ")" && outer.align; outer = outer.prev) indent = outer.indented;
state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
};
result.lex = true;
return result;
}
function poplex() {
var state = cx.state;
if (state.lexical.prev) {
if (state.lexical.type == ")") state.indented = state.lexical.indented;
state.lexical = state.lexical.prev;
}
}
poplex.lex = true;
function expect(wanted) {
function exp(type) {
if (type == wanted) return cont();else if (wanted == ";") return pass();else return cont(exp);
};
return exp;
}
function statement(type, value) {
if (type == "var") return cont(pushlex("vardef", value), vardef, expect(";"), poplex);
if (type == "keyword a") return cont(pushlex("form"), parenExpr, statement, poplex);
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
if (type == "keyword d") return cx.stream.match(/^\s*$/, false) ? cont() : cont(pushlex("stat"), maybeexpression, expect(";"), poplex);
if (type == "debugger") return cont(expect(";"));
if (type == "{") return cont(pushlex("}"), pushblockcontext, block, poplex, popcontext);
if (type == ";") return cont();
if (type == "if") {
if (cx.state.lexical.info == "else" && cx.state.cc[cx.state.cc.length - 1] == poplex) cx.state.cc.pop()();
return cont(pushlex("form"), parenExpr, statement, poplex, maybeelse);
}
if (type == "function") return cont(functiondef);
if (type == "for") return cont(pushlex("form"), forspec, statement, poplex);
if (type == "class" || isTS && value == "interface") {
cx.marked = "keyword";return cont(pushlex("form"), className, poplex);
}
if (type == "variable") {
if (isTS && value == "declare") {
cx.marked = "keyword";
return cont(statement);
} else if (isTS && (value == "module" || value == "enum" || value == "type") && cx.stream.match(/^\s*\w/, false)) {
cx.marked = "keyword";
if (value == "enum") return cont(enumdef);else if (value == "type") return cont(typeexpr, expect("operator"), typeexpr, expect(";"));else return cont(pushlex("form"), pattern, expect("{"), pushlex("}"), block, poplex, poplex);
} else if (isTS && value == "namespace") {
cx.marked = "keyword";
return cont(pushlex("form"), expression, block, poplex);
} else if (isTS && value == "abstract") {
cx.marked = "keyword";
return cont(statement);
} else {
return cont(pushlex("stat"), maybelabel);
}
}
if (type == "switch") return cont(pushlex("form"), parenExpr, expect("{"), pushlex("}", "switch"), pushblockcontext, block, poplex, poplex, popcontext);
if (type == "case") return cont(expression, expect(":"));
if (type == "default") return cont(expect(":"));
if (type == "catch") return cont(pushlex("form"), pushcontext, maybeCatchBinding, statement, poplex, popcontext);
if (type == "export") return cont(pushlex("stat"), afterExport, poplex);
if (type == "import") return cont(pushlex("stat"), afterImport, poplex);
if (type == "async") return cont(statement);
if (value == "@") return cont(expression, statement);
return pass(pushlex("stat"), expression, expect(";"), poplex);
}
function maybeCatchBinding(type) {
if (type == "(") return cont(funarg, expect(")"));
}
function expression(type, value) {
return expressionInner(type, value, false);
}
function expressionNoComma(type, value) {
return expressionInner(type, value, true);
}
function parenExpr(type) {
if (type != "(") return pass();
return cont(pushlex(")"), expression, expect(")"), poplex);
}
function expressionInner(type, value, noComma) {
if (cx.state.fatArrowAt == cx.stream.start) {
var body = noComma ? arrowBodyNoComma : arrowBody;
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, expect("=>"), body, popcontext);else if (type == "variable") return pass(pushcontext, pattern, expect("=>"), body, popcontext);
}
var maybeop = noComma ? maybeoperatorNoComma : maybeoperatorComma;
if (atomicTypes.hasOwnProperty(type)) return cont(maybeop);
if (type == "function") return cont(functiondef, maybeop);
if (type == "class" || isTS && value == "interface") {
cx.marked = "keyword";return cont(pushlex("form"), classExpression, poplex);
}
if (type == "keyword c" || type == "async") return cont(noComma ? expressionNoComma : expression);
if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeop);
if (type == "operator" || type == "spread") return cont(noComma ? expressionNoComma : expression);
if (type == "[") return cont(pushlex("]"), arrayLiteral, poplex, maybeop);
if (type == "{") return contCommasep(objprop, "}", null, maybeop);
if (type == "quasi") return pass(quasi, maybeop);
if (type == "new") return cont(maybeTarget(noComma));
if (type == "import") return cont(expression);
return cont();
}
function maybeexpression(type) {
if (type.match(/[;\}\)\],]/)) return pass();
return pass(expression);
}
function maybeoperatorComma(type, value) {
if (type == ",") return cont(expression);
return maybeoperatorNoComma(type, value, false);
}
function maybeoperatorNoComma(type, value, noComma) {
var me = noComma == false ? maybeoperatorComma : maybeoperatorNoComma;
var expr = noComma == false ? expression : expressionNoComma;
if (type == "=>") return cont(pushcontext, noComma ? arrowBodyNoComma : arrowBody, popcontext);
if (type == "operator") {
if (/\+\+|--/.test(value) || isTS && value == "!") return cont(me);
if (isTS && value == "<" && cx.stream.match(/^([^>]|<.*?>)*>\s*\(/, false)) return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, me);
if (value == "?") return cont(expression, expect(":"), expr);
return cont(expr);
}
if (type == "quasi") {
return pass(quasi, me);
}
if (type == ";") return;
if (type == "(") return contCommasep(expressionNoComma, ")", "call", me);
if (type == ".") return cont(property, me);
if (type == "[") return cont(pushlex("]"), maybeexpression, expect("]"), poplex, me);
if (isTS && value == "as") {
cx.marked = "keyword";return cont(typeexpr, me);
}
if (type == "regexp") {
cx.state.lastType = cx.marked = "operator";
cx.stream.backUp(cx.stream.pos - cx.stream.start - 1);
return cont(expr);
}
}
function quasi(type, value) {
if (type != "quasi") return pass();
if (value.slice(value.length - 2) != "${") return cont(quasi);
return cont(expression, continueQuasi);
}
function continueQuasi(type) {
if (type == "}") {
cx.marked = "string-2";
cx.state.tokenize = tokenQuasi;
return cont(quasi);
}
}
function arrowBody(type) {
findFatArrow(cx.stream, cx.state);
return pass(type == "{" ? statement : expression);
}
function arrowBodyNoComma(type) {
findFatArrow(cx.stream, cx.state);
return pass(type == "{" ? statement : expressionNoComma);
}
function maybeTarget(noComma) {
return function (type) {
if (type == ".") return cont(noComma ? targetNoComma : target);else if (type == "variable" && isTS) return cont(maybeTypeArgs, noComma ? maybeoperatorNoComma : maybeoperatorComma);else return pass(noComma ? expressionNoComma : expression);
};
}
function target(_, value) {
if (value == "target") {
cx.marked = "keyword";return cont(maybeoperatorComma);
}
}
function targetNoComma(_, value) {
if (value == "target") {
cx.marked = "keyword";return cont(maybeoperatorNoComma);
}
}
function maybelabel(type) {
if (type == ":") return cont(poplex, statement);
return pass(maybeoperatorComma, expect(";"), poplex);
}
function property(type) {
if (type == "variable") {
cx.marked = "property";return cont();
}
}
function objprop(type, value) {
if (type == "async") {
cx.marked = "property";
return cont(objprop);
} else if (type == "variable" || cx.style == "keyword") {
cx.marked = "property";
if (value == "get" || value == "set") return cont(getterSetter);
var m; // Work around fat-arrow-detection complication for detecting typescript typed arrow params
if (isTS && cx.state.fatArrowAt == cx.stream.start && (m = cx.stream.match(/^\s*:\s*/, false))) cx.state.fatArrowAt = cx.stream.pos + m[0].length;
return cont(afterprop);
} else if (type == "number" || type == "string") {
cx.marked = jsonldMode ? "property" : cx.style + " property";
return cont(afterprop);
} else if (type == "jsonld-keyword") {
return cont(afterprop);
} else if (isTS && isModifier(value)) {
cx.marked = "keyword";
return cont(objprop);
} else if (type == "[") {
return cont(expression, maybetype, expect("]"), afterprop);
} else if (type == "spread") {
return cont(expressionNoComma, afterprop);
} else if (value == "*") {
cx.marked = "keyword";
return cont(objprop);
} else if (type == ":") {
return pass(afterprop);
}
}
function getterSetter(type) {
if (type != "variable") return pass(afterprop);
cx.marked = "property";
return cont(functiondef);
}
function afterprop(type) {
if (type == ":") return cont(expressionNoComma);
if (type == "(") return pass(functiondef);
}
function commasep(what, end, sep) {
function proceed(type, value) {
if (sep ? sep.indexOf(type) > -1 : type == ",") {
var lex = cx.state.lexical;
if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
return cont(function (type, value) {
if (type == end || value == end) return pass();
return pass(what);
}, proceed);
}
if (type == end || value == end) return cont();
return cont(expect(end));
}
return function (type, value) {
if (type == end || value == end) return cont();
return pass(what, proceed);
};
}
function contCommasep(what, end, info) {
for (var i = 3; i < arguments.length; i++) cx.cc.push(arguments[i]);
return cont(pushlex(end, info), commasep(what, end), poplex);
}
function block(type) {
if (type == "}") return cont();
return pass(statement, block);
}
function maybetype(type, value) {
if (isTS) {
if (type == ":") return cont(typeexpr);
if (value == "?") return cont(maybetype);
}
}
function mayberettype(type) {
if (isTS && type == ":") {
if (cx.stream.match(/^\s*\w+\s+is\b/, false)) return cont(expression, isKW, typeexpr);else return cont(typeexpr);
}
}
function isKW(_, value) {
if (value == "is") {
cx.marked = "keyword";
return cont();
}
}
function typeexpr(type, value) {
if (value == "keyof" || value == "typeof") {
cx.marked = "keyword";
return cont(value == "keyof" ? typeexpr : expressionNoComma);
}
if (type == "variable" || value == "void") {
cx.marked = "type";
return cont(afterType);
}
if (type == "string" || type == "number" || type == "atom") return cont(afterType);
if (type == "[") return cont(pushlex("]"), commasep(typeexpr, "]", ","), poplex, afterType);
if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), poplex, afterType);
if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType);
if (type == "<") return cont(commasep(typeexpr, ">"), typeexpr);
}
function maybeReturnType(type) {
if (type == "=>") return cont(typeexpr);
}
function typeprop(type, value) {
if (type == "variable" || cx.style == "keyword") {
cx.marked = "property";
return cont(typeprop);
} else if (value == "?") {
return cont(typeprop);
} else if (type == ":") {
return cont(typeexpr);
} else if (type == "[") {
return cont(expression, maybetype, expect("]"), typeprop);
}
}
function typearg(type, value) {
if (type == "variable" && cx.stream.match(/^\s*[?:]/, false) || value == "?") return cont(typearg);
if (type == ":") return cont(typeexpr);
return pass(typeexpr);
}
function afterType(type, value) {
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType);
if (value == "|" || type == "." || value == "&") return cont(typeexpr);
if (type == "[") return cont(expect("]"), afterType);
if (value == "extends" || value == "implements") {
cx.marked = "keyword";return cont(typeexpr);
}
}
function maybeTypeArgs(_, value) {
if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType);
}
function typeparam() {
return pass(typeexpr, maybeTypeDefault);
}
function maybeTypeDefault(_, value) {
if (value == "=") return cont(typeexpr);
}
function vardef(_, value) {
if (value == "enum") {
cx.marked = "keyword";return cont(enumdef);
}
return pass(pattern, maybetype, maybeAssign, vardefCont);
}
function pattern(type, value) {
if (isTS && isModifier(value)) {
cx.marked = "keyword";return cont(pattern);
}
if (type == "variable") {
register(value);return cont();
}
if (type == "spread") return cont(pattern);
if (type == "[") return contCommasep(pattern, "]");
if (type == "{") return contCommasep(proppattern, "}");
}
function proppattern(type, value) {
if (type == "variable" && !cx.stream.match(/^\s*:/, false)) {
register(value);
return cont(maybeAssign);
}
if (type == "variable") cx.marked = "property";
if (type == "spread") return cont(pattern);
if (type == "}") return pass();
return cont(expect(":"), pattern, maybeAssign);
}
function maybeAssign(_type, value) {
if (value == "=") return cont(expressionNoComma);
}
function vardefCont(type) {
if (type == ",") return cont(vardef);
}
function maybeelse(type, value) {
if (type == "keyword b" && value == "else") return cont(pushlex("form", "else"), statement, poplex);
}
function forspec(type, value) {
if (value == "await") return cont(forspec);
if (type == "(") return cont(pushlex(")"), forspec1, expect(")"), poplex);
}
function forspec1(type) {
if (type == "var") return cont(vardef, expect(";"), forspec2);
if (type == ";") return cont(forspec2);
if (type == "variable") return cont(formaybeinof);
return pass(expression, expect(";"), forspec2);
}
function formaybeinof(_type, value) {
if (value == "in" || value == "of") {
cx.marked = "keyword";return cont(expression);
}
return cont(maybeoperatorComma, forspec2);
}
function forspec2(type, value) {
if (type == ";") return cont(forspec3);
if (value == "in" || value == "of") {
cx.marked = "keyword";return cont(expression);
}
return pass(expression, expect(";"), forspec3);
}
function forspec3(type) {
if (type != ")") cont(expression);
}
function functiondef(type, value) {
if (value == "*") {
cx.marked = "keyword";return cont(functiondef);
}
if (type == "variable") {
register(value);return cont(functiondef);
}
if (type == "(") return cont(pushcontext, pushlex(")"), commasep(funarg, ")"), poplex, mayberettype, statement, popcontext);
if (isTS && value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, functiondef);
}
function funarg(type, value) {
if (value == "@") cont(expression, funarg);
if (type == "spread") return cont(funarg);
if (isTS && isModifier(value)) {
cx.marked = "keyword";return cont(funarg);
}
return pass(pattern, maybetype, maybeAssign);
}
function classExpression(type, value) {
// Class expressions may have an optional name.
if (type == "variable") return className(type, value);
return classNameAfter(type, value);
}
function className(type, value) {
if (type == "variable") {
register(value);return cont(classNameAfter);
}
}
function classNameAfter(type, value) {
if (value == "<") return cont(pushlex(">"), commasep(typeparam, ">"), poplex, classNameAfter);
if (value == "extends" || value == "implements" || isTS && type == ",") {
if (value == "implements") cx.marked = "keyword";
return cont(isTS ? typeexpr : expression, classNameAfter);
}
if (type == "{") return cont(pushlex("}"), classBody, poplex);
}
function classBody(type, value) {
if (type == "async" || type == "variable" && (value == "static" || value == "get" || value == "set" || isTS && isModifier(value)) && cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
cx.marked = "keyword";
return cont(classBody);
}
if (type == "variable" || cx.style == "keyword") {
cx.marked = "property";
return cont(isTS ? classfield : functiondef, classBody);
}
if (type == "[") return cont(expression, maybetype, expect("]"), isTS ? classfield : functiondef, classBody);
if (value == "*") {
cx.marked = "keyword";
return cont(classBody);
}
if (type == ";") return cont(classBody);
if (type == "}") return cont();
if (value == "@") return cont(expression, classBody);
}
function classfield(type, value) {
if (value == "?") return cont(classfield);
if (type == ":") return cont(typeexpr, maybeAssign);
if (value == "=") return cont(expressionNoComma);
return pass(functiondef);
}
function afterExport(type, value) {
if (value == "*") {
cx.marked = "keyword";return cont(maybeFrom, expect(";"));
}
if (value == "default") {
cx.marked = "keyword";return cont(expression, expect(";"));
}
if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(";"));
return pass(statement);
}
function exportField(type, value) {
if (value == "as") {
cx.marked = "keyword";return cont(expect("variable"));
}
if (type == "variable") return pass(expressionNoComma, exportField);
}
function afterImport(type) {
if (type == "string") return cont();
if (type == "(") return pass(expression);
return pass(importSpec, maybeMoreImports, maybeFrom);
}
function importSpec(type, value) {
if (type == "{") return contCommasep(importSpec, "}");
if (type == "variable") register(value);
if (value == "*") cx.marked = "keyword";
return cont(maybeAs);
}
function maybeMoreImports(type) {
if (type == ",") return cont(importSpec, maybeMoreImports);
}
function maybeAs(_type, value) {
if (value == "as") {
cx.marked = "keyword";return cont(importSpec);
}
}
function maybeFrom(_type, value) {
if (value == "from") {
cx.marked = "keyword";return cont(expression);
}
}
function arrayLiteral(type) {
if (type == "]") return cont();
return pass(commasep(expressionNoComma, "]"));
}
function enumdef() {
return pass(pushlex("form"), pattern, expect("{"), pushlex("}"), commasep(enummember, "}"), poplex, poplex);
}
function enummember() {
return pass(pattern, maybeAssign);
}
function isContinuedStatement(state, textAfter) {
return state.lastType == "operator" || state.lastType == "," || isOperatorChar.test(textAfter.charAt(0)) || /[,.]/.test(textAfter.charAt(0));
}
function expressionAllowed(stream, state, backUp) {
return state.tokenize == tokenBase && /^(?:operator|sof|keyword [bcd]|case|new|export|default|spread|[\[{}\(,;:]|=>)$/.test(state.lastType) || state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.pos - (backUp || 0)));
}
// Interface
return {
startState: function (basecolumn) {
var state = {
tokenize: tokenBase,
lastType: "sof",
cc: [],
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
localVars: parserConfig.localVars,
context: parserConfig.localVars && new Context(null, null, false),
indented: basecolumn || 0
};
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object") state.globalVars = parserConfig.globalVars;
return state;
},
token: function (stream, state) {
if (stream.sol()) {
if (!state.lexical.hasOwnProperty("align")) state.lexical.align = false;
state.indented = stream.indentation();
findFatArrow(stream, state);
}
if (state.tokenize != tokenComment && stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
if (type == "comment") return style;
state.lastType = type == "operator" && (content == "++" || content == "--") ? "incdec" : type;
return parseJS(state, style, type, content, stream);
},
indent: function (state, textAfter) {
if (state.tokenize == tokenComment) return CodeMirror.Pass;
if (state.tokenize != tokenBase) return 0;
var firstChar = textAfter && textAfter.charAt(0),
lexical = state.lexical,
top;
// Kludge to prevent 'maybelse' from blocking lexical scope pops
if (!/^\s*else\b/.test(textAfter)) for (var i = state.cc.length - 1; i >= 0; --i) {
var c = state.cc[i];
if (c == poplex) lexical = lexical.prev;else if (c != maybeelse) break;
}
while ((lexical.type == "stat" || lexical.type == "form") && (firstChar == "}" || (top = state.cc[state.cc.length - 1]) && (top == maybeoperatorComma || top == maybeoperatorNoComma) && !/^[,\.=+\-*:?[\(]/.test(textAfter))) lexical = lexical.prev;
if (statementIndent && lexical.type == ")" && lexical.prev.type == "stat") lexical = lexical.prev;
var type = lexical.type,
closing = firstChar == type;
if (type == "vardef") return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? lexical.info.length + 1 : 0);else if (type == "form" && firstChar == "{") return lexical.indented;else if (type == "form") return lexical.indented + indentUnit;else if (type == "stat") return lexical.indented + (isContinuedStatement(state, textAfter) ? statementIndent || indentUnit : 0);else if (lexical.info == "switch" && !closing && parserConfig.doubleIndentSwitch != false) return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);else if (lexical.align) return lexical.column + (closing ? 0 : 1);else return lexical.indented + (closing ? 0 : indentUnit);
},
electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
blockCommentStart: jsonMode ? null : "/*",
blockCommentEnd: jsonMode ? null : "*/",
blockCommentContinue: jsonMode ? null : " * ",
lineComment: jsonMode ? null : "//",
fold: "brace",
closeBrackets: "()[]{}''\"\"``",
helperType: jsonMode ? "json" : "javascript",
jsonldMode: jsonldMode,
jsonMode: jsonMode,
expressionAllowed: expressionAllowed,
skipExpression: function (state) {
var top = state.cc[state.cc.length - 1];
if (top == expression || top == expressionNoComma) state.cc.pop();
}
};
});
CodeMirror.registerHelper("wordChars", "javascript", /[\w$]/);
CodeMirror.defineMIME("text/javascript", "javascript");
CodeMirror.defineMIME("text/ecmascript", "javascript");
CodeMirror.defineMIME("application/javascript", "javascript");
CodeMirror.defineMIME("application/x-javascript", "javascript");
CodeMirror.defineMIME("application/ecmascript", "javascript");
CodeMirror.defineMIME("application/json", { name: "javascript", json: true });
CodeMirror.defineMIME("application/x-json", { name: "javascript", json: true });
CodeMirror.defineMIME("application/ld+json", { name: "javascript", jsonld: true });
CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript: true });
});
/***/ }),
/***/ "rbVD":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
// This is the old interface, kept around for now to stay
// backwards-compatible.
CodeMirror.showHint = function (cm, getHints, options) {
if (!getHints) return cm.showHint(options);
if (options && options.async) getHints.async = true;
var newOpts = { hint: getHints };
if (options) for (var prop in options) newOpts[prop] = options[prop];
return cm.showHint(newOpts);
};
CodeMirror.defineExtension("showHint", function (options) {
options = parseOptions(this, this.getCursor("start"), options);
var selections = this.listSelections();
if (selections.length > 1) return;
// By default, don't allow completion when something is selected.
// A hint function can have a `supportsSelection` property to
// indicate that it can handle selections.
if (this.somethingSelected()) {
if (!options.hint.supportsSelection) return;
// Don't try with cross-line selections
for (var i = 0; i < selections.length; i++) if (selections[i].head.line != selections[i].anchor.line) return;
}
if (this.state.completionActive) this.state.completionActive.close();
var completion = this.state.completionActive = new Completion(this, options);
if (!completion.options.hint) return;
CodeMirror.signal(this, "startCompletion", this);
completion.update(true);
});
function Completion(cm, options) {
this.cm = cm;
this.options = options;
this.widget = null;
this.debounce = 0;
this.tick = 0;
this.startPos = this.cm.getCursor("start");
this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
var self = this;
cm.on("cursorActivity", this.activityFunc = function () {
self.cursorActivity();
});
}
var requestAnimationFrame = window.requestAnimationFrame || function (fn) {
return setTimeout(fn, 1000 / 60);
};
var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
Completion.prototype = {
close: function () {
if (!this.active()) return;
this.cm.state.completionActive = null;
this.tick = null;
this.cm.off("cursorActivity", this.activityFunc);
if (this.widget && this.data) CodeMirror.signal(this.data, "close");
if (this.widget) this.widget.close();
CodeMirror.signal(this.cm, "endCompletion", this.cm);
},
active: function () {
return this.cm.state.completionActive == this;
},
pick: function (data, i) {
var completion = data.list[i];
if (completion.hint) completion.hint(this.cm, data, completion);else this.cm.replaceRange(getText(completion), completion.from || data.from, completion.to || data.to, "complete");
CodeMirror.signal(data, "pick", completion);
this.close();
},
cursorActivity: function () {
if (this.debounce) {
cancelAnimationFrame(this.debounce);
this.debounce = 0;
}
var pos = this.cm.getCursor(),
line = this.cm.getLine(pos.line);
if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch || pos.ch < this.startPos.ch || this.cm.somethingSelected() || pos.ch && this.options.closeCharacters.test(line.charAt(pos.ch - 1))) {
this.close();
} else {
var self = this;
this.debounce = requestAnimationFrame(function () {
self.update();
});
if (this.widget) this.widget.disable();
}
},
update: function (first) {
if (this.tick == null) return;
var self = this,
myTick = ++this.tick;
fetchHints(this.options.hint, this.cm, this.options, function (data) {
if (self.tick == myTick) self.finishUpdate(data, first);
});
},
finishUpdate: function (data, first) {
if (this.data) CodeMirror.signal(this.data, "update");
var picked = this.widget && this.widget.picked || first && this.options.completeSingle;
if (this.widget) this.widget.close();
this.data = data;
if (data && data.list.length) {
if (picked && data.list.length == 1) {
this.pick(data, 0);
} else {
this.widget = new Widget(this, data);
CodeMirror.signal(data, "shown");
}
}
}
};
function parseOptions(cm, pos, options) {
var editor = cm.options.hintOptions;
var out = {};
for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
if (editor) for (var prop in editor) if (editor[prop] !== undefined) out[prop] = editor[prop];
if (options) for (var prop in options) if (options[prop] !== undefined) out[prop] = options[prop];
if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos);
return out;
}
function getText(completion) {
if (typeof completion == "string") return completion;else return completion.text;
}
function buildKeyMap(completion, handle) {
var baseMap = {
Up: function () {
handle.moveFocus(-1);
},
Down: function () {
handle.moveFocus(1);
},
PageUp: function () {
handle.moveFocus(-handle.menuSize() + 1, true);
},
PageDown: function () {
handle.moveFocus(handle.menuSize() - 1, true);
},
Home: function () {
handle.setFocus(0);
},
End: function () {
handle.setFocus(handle.length - 1);
},
Enter: handle.pick,
Tab: handle.pick,
Esc: handle.close
};
var custom = completion.options.customKeys;
var ourMap = custom ? {} : baseMap;
function addBinding(key, val) {
var bound;
if (typeof val != "string") bound = function (cm) {
return val(cm, handle);
};
// This mechanism is deprecated
else if (baseMap.hasOwnProperty(val)) bound = baseMap[val];else bound = val;
ourMap[key] = bound;
}
if (custom) for (var key in custom) if (custom.hasOwnProperty(key)) addBinding(key, custom[key]);
var extra = completion.options.extraKeys;
if (extra) for (var key in extra) if (extra.hasOwnProperty(key)) addBinding(key, extra[key]);
return ourMap;
}
function getHintElement(hintsElement, el) {
while (el && el != hintsElement) {
if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
el = el.parentNode;
}
}
function Widget(completion, data) {
this.completion = completion;
this.data = data;
this.picked = false;
var widget = this,
cm = completion.cm;
var hints = this.hints = document.createElement("ul");
hints.className = "CodeMirror-hints";
this.selectedHint = data.selectedHint || 0;
var completions = data.list;
for (var i = 0; i < completions.length; ++i) {
var elt = hints.appendChild(document.createElement("li")),
cur = completions[i];
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
if (cur.className != null) className = cur.className + " " + className;
elt.className = className;
if (cur.render) cur.render(elt, data, cur);else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
elt.hintId = i;
}
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
var left = pos.left,
top = pos.bottom,
below = true;
hints.style.left = left + "px";
hints.style.top = top + "px";
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
(completion.options.container || document.body).appendChild(hints);
var box = hints.getBoundingClientRect(),
overlapY = box.bottom - winH;
var scrolls = hints.scrollHeight > hints.clientHeight + 1;
var startScroll = cm.getScrollInfo();
if (overlapY > 0) {
var height = box.bottom - box.top,
curTop = pos.top - (pos.bottom - box.top);
if (curTop - height > 0) {
// Fits above cursor
hints.style.top = (top = pos.top - height) + "px";
below = false;
} else if (height > winH) {
hints.style.height = winH - 5 + "px";
hints.style.top = (top = pos.bottom - box.top) + "px";
var cursor = cm.getCursor();
if (data.from.ch != cursor.ch) {
pos = cm.cursorCoords(cursor);
hints.style.left = (left = pos.left) + "px";
box = hints.getBoundingClientRect();
}
}
}
var overlapX = box.right - winW;
if (overlapX > 0) {
if (box.right - box.left > winW) {
hints.style.width = winW - 5 + "px";
overlapX -= box.right - box.left - winW;
}
hints.style.left = (left = pos.left - overlapX) + "px";
}
if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling) node.style.paddingRight = cm.display.nativeBarWidth + "px";
cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
moveFocus: function (n, avoidWrap) {
widget.changeActive(widget.selectedHint + n, avoidWrap);
},
setFocus: function (n) {
widget.changeActive(n);
},
menuSize: function () {
return widget.screenAmount();
},
length: completions.length,
close: function () {
completion.close();
},
pick: function () {
widget.pick();
},
data: data
}));
if (completion.options.closeOnUnfocus) {
var closingOnBlur;
cm.on("blur", this.onBlur = function () {
closingOnBlur = setTimeout(function () {
completion.close();
}, 100);
});
cm.on("focus", this.onFocus = function () {
clearTimeout(closingOnBlur);
});
}
cm.on("scroll", this.onScroll = function () {
var curScroll = cm.getScrollInfo(),
editor = cm.getWrapperElement().getBoundingClientRect();
var newTop = top + startScroll.top - curScroll.top;
var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
if (!below) point += hints.offsetHeight;
if (point <= editor.top || point >= editor.bottom) return completion.close();
hints.style.top = newTop + "px";
hints.style.left = left + startScroll.left - curScroll.left + "px";
});
CodeMirror.on(hints, "dblclick", function (e) {
var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) {
widget.changeActive(t.hintId);widget.pick();
}
});
CodeMirror.on(hints, "click", function (e) {
var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) {
widget.changeActive(t.hintId);
if (completion.options.completeOnSingleClick) widget.pick();
}
});
CodeMirror.on(hints, "mousedown", function () {
setTimeout(function () {
cm.focus();
}, 20);
});
CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
return true;
}
Widget.prototype = {
close: function () {
if (this.completion.widget != this) return;
this.completion.widget = null;
this.hints.parentNode.removeChild(this.hints);
this.completion.cm.removeKeyMap(this.keyMap);
var cm = this.completion.cm;
if (this.completion.options.closeOnUnfocus) {
cm.off("blur", this.onBlur);
cm.off("focus", this.onFocus);
}
cm.off("scroll", this.onScroll);
},
disable: function () {
this.completion.cm.removeKeyMap(this.keyMap);
var widget = this;
this.keyMap = { Enter: function () {
widget.picked = true;
} };
this.completion.cm.addKeyMap(this.keyMap);
},
pick: function () {
this.completion.pick(this.data, this.selectedHint);
},
changeActive: function (i, avoidWrap) {
if (i >= this.data.list.length) i = avoidWrap ? this.data.list.length - 1 : 0;else if (i < 0) i = avoidWrap ? 0 : this.data.list.length - 1;
if (this.selectedHint == i) return;
var node = this.hints.childNodes[this.selectedHint];
if (node) node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
node = this.hints.childNodes[this.selectedHint = i];
node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
if (node.offsetTop < this.hints.scrollTop) this.hints.scrollTop = node.offsetTop - 3;else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight) this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
},
screenAmount: function () {
return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
}
};
function applicableHelpers(cm, helpers) {
if (!cm.somethingSelected()) return helpers;
var result = [];
for (var i = 0; i < helpers.length; i++) if (helpers[i].supportsSelection) result.push(helpers[i]);
return result;
}
function fetchHints(hint, cm, options, callback) {
if (hint.async) {
hint(cm, callback, options);
} else {
var result = hint(cm, options);
if (result && result.then) result.then(callback);else callback(result);
}
}
function resolveAutoHints(cm, pos) {
var helpers = cm.getHelpers(pos, "hint"),
words;
if (helpers.length) {
var resolved = function (cm, callback, options) {
var app = applicableHelpers(cm, helpers);
function run(i) {
if (i == app.length) return callback(null);
fetchHints(app[i], cm, options, function (result) {
if (result && result.list.length > 0) callback(result);else run(i + 1);
});
}
run(0);
};
resolved.async = true;
resolved.supportsSelection = true;
return resolved;
} else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
return function (cm) {
return CodeMirror.hint.fromList(cm, { words: words });
};
} else if (CodeMirror.hint.anyword) {
return function (cm, options) {
return CodeMirror.hint.anyword(cm, options);
};
} else {
return function () {};
}
}
CodeMirror.registerHelper("hint", "auto", {
resolve: resolveAutoHints
});
CodeMirror.registerHelper("hint", "fromList", function (cm, options) {
var cur = cm.getCursor(),
token = cm.getTokenAt(cur);
var term,
from = CodeMirror.Pos(cur.line, token.start),
to = cur;
if (token.start < cur.ch && /\w/.test(token.string.charAt(cur.ch - token.start - 1))) {
term = token.string.substr(0, cur.ch - token.start);
} else {
term = "";
from = cur;
}
var found = [];
for (var i = 0; i < options.words.length; i++) {
var word = options.words[i];
if (word.slice(0, term.length) == term) found.push(word);
}
if (found.length) return { list: found, from: from, to: to };
});
CodeMirror.commands.autocomplete = CodeMirror.showHint;
var defaultOptions = {
hint: CodeMirror.hint.auto,
completeSingle: true,
alignWithWord: true,
closeCharacters: /[\s()\[\]{};:>,]/,
closeOnUnfocus: true,
completeOnSingleClick: true,
container: null,
customKeys: null,
extraKeys: null
};
CodeMirror.defineOption("hintOptions", null);
});
/***/ }),
/***/ "tMLt":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("H+g/"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "./foldcode"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
CodeMirror.defineOption("foldGutter", false, function (cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.clearGutter(cm.state.foldGutter.options.gutter);
cm.state.foldGutter = null;
cm.off("gutterClick", onGutterClick);
cm.off("change", onChange);
cm.off("viewportChange", onViewportChange);
cm.off("fold", onFold);
cm.off("unfold", onFold);
cm.off("swapDoc", onChange);
}
if (val) {
cm.state.foldGutter = new State(parseOptions(val));
updateInViewport(cm);
cm.on("gutterClick", onGutterClick);
cm.on("change", onChange);
cm.on("viewportChange", onViewportChange);
cm.on("fold", onFold);
cm.on("unfold", onFold);
cm.on("swapDoc", onChange);
}
});
var Pos = CodeMirror.Pos;
function State(options) {
this.options = options;
this.from = this.to = 0;
}
function parseOptions(opts) {
if (opts === true) opts = {};
if (opts.gutter == null) opts.gutter = "CodeMirror-foldgutter";
if (opts.indicatorOpen == null) opts.indicatorOpen = "CodeMirror-foldgutter-open";
if (opts.indicatorFolded == null) opts.indicatorFolded = "CodeMirror-foldgutter-folded";
return opts;
}
function isFolded(cm, line) {
var marks = cm.findMarks(Pos(line, 0), Pos(line + 1, 0));
for (var i = 0; i < marks.length; ++i) if (marks[i].__isFold && marks[i].find().from.line == line) return marks[i];
}
function marker(spec) {
if (typeof spec == "string") {
var elt = document.createElement("div");
elt.className = spec + " CodeMirror-guttermarker-subtle";
return elt;
} else {
return spec.cloneNode(true);
}
}
function updateFoldInfo(cm, from, to) {
var opts = cm.state.foldGutter.options,
cur = from;
var minSize = cm.foldOption(opts, "minFoldSize");
var func = cm.foldOption(opts, "rangeFinder");
cm.eachLine(from, to, function (line) {
var mark = null;
if (isFolded(cm, cur)) {
mark = marker(opts.indicatorFolded);
} else {
var pos = Pos(cur, 0);
var range = func && func(cm, pos);
if (range && range.to.line - range.from.line >= minSize) mark = marker(opts.indicatorOpen);
}
cm.setGutterMarker(line, opts.gutter, mark);
++cur;
});
}
function updateInViewport(cm) {
var vp = cm.getViewport(),
state = cm.state.foldGutter;
if (!state) return;
cm.operation(function () {
updateFoldInfo(cm, vp.from, vp.to);
});
state.from = vp.from;state.to = vp.to;
}
function onGutterClick(cm, line, gutter) {
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
if (gutter != opts.gutter) return;
var folded = isFolded(cm, line);
if (folded) folded.clear();else cm.foldCode(Pos(line, 0), opts.rangeFinder);
}
function onChange(cm) {
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
state.from = state.to = 0;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function () {
updateInViewport(cm);
}, opts.foldOnChangeTimeSpan || 600);
}
function onViewportChange(cm) {
var state = cm.state.foldGutter;
if (!state) return;
var opts = state.options;
clearTimeout(state.changeUpdate);
state.changeUpdate = setTimeout(function () {
var vp = cm.getViewport();
if (state.from == state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
updateInViewport(cm);
} else {
cm.operation(function () {
if (vp.from < state.from) {
updateFoldInfo(cm, vp.from, state.from);
state.from = vp.from;
}
if (vp.to > state.to) {
updateFoldInfo(cm, state.to, vp.to);
state.to = vp.to;
}
});
}
}, opts.updateViewportTimeSpan || 400);
}
function onFold(cm, from) {
var state = cm.state.foldGutter;
if (!state) return;
var line = from.line;
if (line >= state.from && line < state.to) updateFoldInfo(cm, line, line + 1);
}
});
/***/ }),
/***/ "tQq4":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// This is CodeMirror (http://codemirror.net), a code editor
// implemented in JavaScript on top of the browser's DOM.
//
// You can find some technical background for some of the code below
// at http://marijnhaverbeke.nl/blog/#cm-internals .
(function (global, factory) {
true ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.CodeMirror = factory();
})(this, function () {
'use strict';
// Kludges for bugs and behavior differences that can't be feature
// detected are enabled based on userAgent etc sniffing.
var userAgent = navigator.userAgent;
var platform = navigator.platform;
var gecko = /gecko\/\d/i.test(userAgent);
var ie_upto10 = /MSIE \d/.test(userAgent);
var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
var edge = /Edge\/(\d+)/.exec(userAgent);
var ie = ie_upto10 || ie_11up || edge;
var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);
var webkit = !edge && /WebKit\//.test(userAgent);
var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
var chrome = !edge && /Chrome\//.test(userAgent);
var presto = /Opera\//.test(userAgent);
var safari = /Apple Computer/.test(navigator.vendor);
var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
var phantom = /PhantomJS/.test(userAgent);
var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
var android = /Android/.test(userAgent);
// This is woefully incomplete. Suggestions for alternative methods welcome.
var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
var mac = ios || /Mac/.test(platform);
var chromeOS = /\bCrOS\b/.test(userAgent);
var windows = /win/i.test(platform);
var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
if (presto_version) {
presto_version = Number(presto_version[1]);
}
if (presto_version && presto_version >= 15) {
presto = false;webkit = true;
}
// Some browsers use the wrong event properties to signal cmd/ctrl on OS X
var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
var captureRightClick = gecko || ie && ie_version >= 9;
function classTest(cls) {
return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*");
}
var rmClass = function (node, cls) {
var current = node.className;
var match = classTest(cls).exec(current);
if (match) {
var after = current.slice(match.index + match[0].length);
node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
}
};
function removeChildren(e) {
for (var count = e.childNodes.length; count > 0; --count) {
e.removeChild(e.firstChild);
}
return e;
}
function removeChildrenAndAdd(parent, e) {
return removeChildren(parent).appendChild(e);
}
function elt(tag, content, className, style) {
var e = document.createElement(tag);
if (className) {
e.className = className;
}
if (style) {
e.style.cssText = style;
}
if (typeof content == "string") {
e.appendChild(document.createTextNode(content));
} else if (content) {
for (var i = 0; i < content.length; ++i) {
e.appendChild(content[i]);
}
}
return e;
}
// wrapper for elt, which removes the elt from the accessibility tree
function eltP(tag, content, className, style) {
var e = elt(tag, content, className, style);
e.setAttribute("role", "presentation");
return e;
}
var range;
if (document.createRange) {
range = function (node, start, end, endNode) {
var r = document.createRange();
r.setEnd(endNode || node, end);
r.setStart(node, start);
return r;
};
} else {
range = function (node, start, end) {
var r = document.body.createTextRange();
try {
r.moveToElementText(node.parentNode);
} catch (e) {
return r;
}
r.collapse(true);
r.moveEnd("character", end);
r.moveStart("character", start);
return r;
};
}
function contains(parent, child) {
if (child.nodeType == 3) // Android browser always returns false when child is a textnode
{
child = child.parentNode;
}
if (parent.contains) {
return parent.contains(child);
}
do {
if (child.nodeType == 11) {
child = child.host;
}
if (child == parent) {
return true;
}
} while (child = child.parentNode);
}
function activeElt() {
// IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
// IE < 10 will throw when accessed while the page is loading or in an iframe.
// IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
var activeElement;
try {
activeElement = document.activeElement;
} catch (e) {
activeElement = document.body || null;
}
while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) {
activeElement = activeElement.shadowRoot.activeElement;
}
return activeElement;
}
function addClass(node, cls) {
var current = node.className;
if (!classTest(cls).test(current)) {
node.className += (current ? " " : "") + cls;
}
}
function joinClasses(a, b) {
var as = a.split(" ");
for (var i = 0; i < as.length; i++) {
if (as[i] && !classTest(as[i]).test(b)) {
b += " " + as[i];
}
}
return b;
}
var selectInput = function (node) {
node.select();
};
if (ios) // Mobile Safari apparently has a bug where select() is broken.
{
selectInput = function (node) {
node.selectionStart = 0;node.selectionEnd = node.value.length;
};
} else if (ie) // Suppress mysterious IE10 errors
{
selectInput = function (node) {
try {
node.select();
} catch (_e) {}
};
}
function bind(f) {
var args = Array.prototype.slice.call(arguments, 1);
return function () {
return f.apply(null, args);
};
}
function copyObj(obj, target, overwrite) {
if (!target) {
target = {};
}
for (var prop in obj) {
if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop))) {
target[prop] = obj[prop];
}
}
return target;
}
// Counts the column offset in a string, taking tabs into account.
// Used mostly to find indentation.
function countColumn(string, end, tabSize, startIndex, startValue) {
if (end == null) {
end = string.search(/[^\s\u00a0]/);
if (end == -1) {
end = string.length;
}
}
for (var i = startIndex || 0, n = startValue || 0;;) {
var nextTab = string.indexOf("\t", i);
if (nextTab < 0 || nextTab >= end) {
return n + (end - i);
}
n += nextTab - i;
n += tabSize - n % tabSize;
i = nextTab + 1;
}
}
var Delayed = function () {
this.id = null;
};
Delayed.prototype.set = function (ms, f) {
clearTimeout(this.id);
this.id = setTimeout(f, ms);
};
function indexOf(array, elt) {
for (var i = 0; i < array.length; ++i) {
if (array[i] == elt) {
return i;
}
}
return -1;
}
// Number of pixels added to scroller and sizer to hide scrollbar
var scrollerGap = 30;
// Returned or thrown by various protocols to signal 'I'm not
// handling this'.
var Pass = { toString: function () {
return "CodeMirror.Pass";
} };
// Reused option objects for setSelection & friends
var sel_dontScroll = { scroll: false };
var sel_mouse = { origin: "*mouse" };
var sel_move = { origin: "+move" };
// The inverse of countColumn -- find the offset that corresponds to
// a particular column.
function findColumn(string, goal, tabSize) {
for (var pos = 0, col = 0;;) {
var nextTab = string.indexOf("\t", pos);
if (nextTab == -1) {
nextTab = string.length;
}
var skipped = nextTab - pos;
if (nextTab == string.length || col + skipped >= goal) {
return pos + Math.min(skipped, goal - col);
}
col += nextTab - pos;
col += tabSize - col % tabSize;
pos = nextTab + 1;
if (col >= goal) {
return pos;
}
}
}
var spaceStrs = [""];
function spaceStr(n) {
while (spaceStrs.length <= n) {
spaceStrs.push(lst(spaceStrs) + " ");
}
return spaceStrs[n];
}
function lst(arr) {
return arr[arr.length - 1];
}
function map(array, f) {
var out = [];
for (var i = 0; i < array.length; i++) {
out[i] = f(array[i], i);
}
return out;
}
function insertSorted(array, value, score) {
var pos = 0,
priority = score(value);
while (pos < array.length && score(array[pos]) <= priority) {
pos++;
}
array.splice(pos, 0, value);
}
function nothing() {}
function createObj(base, props) {
var inst;
if (Object.create) {
inst = Object.create(base);
} else {
nothing.prototype = base;
inst = new nothing();
}
if (props) {
copyObj(props, inst);
}
return inst;
}
var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
function isWordCharBasic(ch) {
return (/\w/.test(ch) || ch > "\x80" && (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
);
}
function isWordChar(ch, helper) {
if (!helper) {
return isWordCharBasic(ch);
}
if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) {
return true;
}
return helper.test(ch);
}
function isEmpty(obj) {
for (var n in obj) {
if (obj.hasOwnProperty(n) && obj[n]) {
return false;
}
}
return true;
}
// Extending unicode characters. A series of a non-extending char +
// any number of extending chars is treated as a single unit as far
// as editing and measuring is concerned. This is not fully correct,
// since some scripts/fonts/browsers also treat other configurations
// of code points as a group.
var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
function isExtendingChar(ch) {
return ch.charCodeAt(0) >= 768 && extendingChars.test(ch);
}
// Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
function skipExtendingChars(str, pos, dir) {
while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) {
pos += dir;
}
return pos;
}
// Returns the value from the range [`from`; `to`] that satisfies
// `pred` and is closest to `from`. Assumes that at least `to`
// satisfies `pred`. Supports `from` being greater than `to`.
function findFirst(pred, from, to) {
// At any point we are certain `to` satisfies `pred`, don't know
// whether `from` does.
var dir = from > to ? -1 : 1;
for (;;) {
if (from == to) {
return from;
}
var midF = (from + to) / 2,
mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF);
if (mid == from) {
return pred(mid) ? from : to;
}
if (pred(mid)) {
to = mid;
} else {
from = mid + dir;
}
}
}
// The display handles the DOM integration, both for input reading
// and content drawing. It holds references to DOM nodes and
// display-related state.
function Display(place, doc, input) {
var d = this;
this.input = input;
// Covers bottom-right square when both scrollbars are present.
d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
d.scrollbarFiller.setAttribute("cm-not-content", "true");
// Covers bottom of gutter when coverGutterNextToScrollbar is on
// and h scrollbar is present.
d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
d.gutterFiller.setAttribute("cm-not-content", "true");
// Will contain the actual code, positioned to cover the viewport.
d.lineDiv = eltP("div", null, "CodeMirror-code");
// Elements are added to these to represent selection and cursors.
d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
d.cursorDiv = elt("div", null, "CodeMirror-cursors");
// A visibility: hidden element used to find the size of things.
d.measure = elt("div", null, "CodeMirror-measure");
// When lines outside of the viewport are measured, they are drawn in this.
d.lineMeasure = elt("div", null, "CodeMirror-measure");
// Wraps everything that needs to exist inside the vertically-padded coordinate system
d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv], null, "position: relative; outline: none");
var lines = eltP("div", [d.lineSpace], "CodeMirror-lines");
// Moved around its parent to cover visible view.
d.mover = elt("div", [lines], null, "position: relative");
// Set to the height of the document, allowing scrolling.
d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
d.sizerWidth = null;
// Behavior of elts with overflow: auto and padding is
// inconsistent across browsers. This is used to ensure the
// scrollable area is big enough.
d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
// Will contain the gutters, if any.
d.gutters = elt("div", null, "CodeMirror-gutters");
d.lineGutter = null;
// Actual scrollable element.
d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
d.scroller.setAttribute("tabIndex", "-1");
// The element in which the editor lives.
d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
// Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
if (ie && ie_version < 8) {
d.gutters.style.zIndex = -1;d.scroller.style.paddingRight = 0;
}
if (!webkit && !(gecko && mobile)) {
d.scroller.draggable = true;
}
if (place) {
if (place.appendChild) {
place.appendChild(d.wrapper);
} else {
place(d.wrapper);
}
}
// Current rendered range (may be bigger than the view window).
d.viewFrom = d.viewTo = doc.first;
d.reportedViewFrom = d.reportedViewTo = doc.first;
// Information about the rendered lines.
d.view = [];
d.renderedView = null;
// Holds info about a single rendered line when it was rendered
// for measurement, while not in view.
d.externalMeasured = null;
// Empty space (in pixels) above the view
d.viewOffset = 0;
d.lastWrapHeight = d.lastWrapWidth = 0;
d.updateLineNumbers = null;
d.nativeBarWidth = d.barHeight = d.barWidth = 0;
d.scrollbarsClipped = false;
// Used to only resize the line number gutter when necessary (when
// the amount of lines crosses a boundary that makes its width change)
d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
// Set to true when a non-horizontal-scrolling line widget is
// added. As an optimization, line widget aligning is skipped when
// this is false.
d.alignWidgets = false;
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
// Tracks the maximum line length so that the horizontal scrollbar
// can be kept static when scrolling.
d.maxLine = null;
d.maxLineLength = 0;
d.maxLineChanged = false;
// Used for measuring wheel scrolling granularity
d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
// True when shift is held down.
d.shift = false;
// Used to track whether anything happened since the context menu
// was opened.
d.selForContextMenu = null;
d.activeTouch = null;
input.init(d);
}
// Find the line object corresponding to the given line number.
function getLine(doc, n) {
n -= doc.first;
if (n < 0 || n >= doc.size) {
throw new Error("There is no line " + (n + doc.first) + " in the document.");
}
var chunk = doc;
while (!chunk.lines) {
for (var i = 0;; ++i) {
var child = chunk.children[i],
sz = child.chunkSize();
if (n < sz) {
chunk = child;break;
}
n -= sz;
}
}
return chunk.lines[n];
}
// Get the part of a document between two positions, as an array of
// strings.
function getBetween(doc, start, end) {
var out = [],
n = start.line;
doc.iter(start.line, end.line + 1, function (line) {
var text = line.text;
if (n == end.line) {
text = text.slice(0, end.ch);
}
if (n == start.line) {
text = text.slice(start.ch);
}
out.push(text);
++n;
});
return out;
}
// Get the lines between from and to, as array of strings.
function getLines(doc, from, to) {
var out = [];
doc.iter(from, to, function (line) {
out.push(line.text);
}); // iter aborts when callback returns truthy value
return out;
}
// Update the height of a line, propagating the height change
// upwards to parent nodes.
function updateLineHeight(line, height) {
var diff = height - line.height;
if (diff) {
for (var n = line; n; n = n.parent) {
n.height += diff;
}
}
}
// Given a line object, find its line number by walking up through
// its parent links.
function lineNo(line) {
if (line.parent == null) {
return null;
}
var cur = line.parent,
no = indexOf(cur.lines, line);
for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
for (var i = 0;; ++i) {
if (chunk.children[i] == cur) {
break;
}
no += chunk.children[i].chunkSize();
}
}
return no + cur.first;
}
// Find the line at the given vertical position, using the height
// information in the document tree.
function lineAtHeight(chunk, h) {
var n = chunk.first;
outer: do {
for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
var child = chunk.children[i$1],
ch = child.height;
if (h < ch) {
chunk = child;continue outer;
}
h -= ch;
n += child.chunkSize();
}
return n;
} while (!chunk.lines);
var i = 0;
for (; i < chunk.lines.length; ++i) {
var line = chunk.lines[i],
lh = line.height;
if (h < lh) {
break;
}
h -= lh;
}
return n + i;
}
function isLine(doc, l) {
return l >= doc.first && l < doc.first + doc.size;
}
function lineNumberFor(options, i) {
return String(options.lineNumberFormatter(i + options.firstLineNumber));
}
// A Pos instance represents a position within the text.
function Pos(line, ch, sticky) {
if (sticky === void 0) sticky = null;
if (!(this instanceof Pos)) {
return new Pos(line, ch, sticky);
}
this.line = line;
this.ch = ch;
this.sticky = sticky;
}
// Compare two positions, return 0 if they are the same, a negative
// number when a is less, and a positive number otherwise.
function cmp(a, b) {
return a.line - b.line || a.ch - b.ch;
}
function equalCursorPos(a, b) {
return a.sticky == b.sticky && cmp(a, b) == 0;
}
function copyPos(x) {
return Pos(x.line, x.ch);
}
function maxPos(a, b) {
return cmp(a, b) < 0 ? b : a;
}
function minPos(a, b) {
return cmp(a, b) < 0 ? a : b;
}
// Most of the external API clips given positions to make sure they
// actually exist within the document.
function clipLine(doc, n) {
return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));
}
function clipPos(doc, pos) {
if (pos.line < doc.first) {
return Pos(doc.first, 0);
}
var last = doc.first + doc.size - 1;
if (pos.line > last) {
return Pos(last, getLine(doc, last).text.length);
}
return clipToLen(pos, getLine(doc, pos.line).text.length);
}
function clipToLen(pos, linelen) {
var ch = pos.ch;
if (ch == null || ch > linelen) {
return Pos(pos.line, linelen);
} else if (ch < 0) {
return Pos(pos.line, 0);
} else {
return pos;
}
}
function clipPosArray(doc, array) {
var out = [];
for (var i = 0; i < array.length; i++) {
out[i] = clipPos(doc, array[i]);
}
return out;
}
// Optimize some code when these features are not used.
var sawReadOnlySpans = false;
var sawCollapsedSpans = false;
function seeReadOnlySpans() {
sawReadOnlySpans = true;
}
function seeCollapsedSpans() {
sawCollapsedSpans = true;
}
// TEXTMARKER SPANS
function MarkedSpan(marker, from, to) {
this.marker = marker;
this.from = from;this.to = to;
}
// Search an array of spans for a span matching the given marker.
function getMarkedSpanFor(spans, marker) {
if (spans) {
for (var i = 0; i < spans.length; ++i) {
var span = spans[i];
if (span.marker == marker) {
return span;
}
}
}
}
// Remove a span from an array, returning undefined if no spans are
// left (we don't store arrays for lines without spans).
function removeMarkedSpan(spans, span) {
var r;
for (var i = 0; i < spans.length; ++i) {
if (spans[i] != span) {
(r || (r = [])).push(spans[i]);
}
}
return r;
}
// Add a span to a line.
function addMarkedSpan(line, span) {
line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
span.marker.attachLine(line);
}
// Used for the algorithm that adjusts markers for a change in the
// document. These functions cut an array of spans at a given
// character position, returning an array of remaining chunks (or
// undefined if nothing remains).
function markedSpansBefore(old, startCh, isInsert) {
var nw;
if (old) {
for (var i = 0; i < old.length; ++i) {
var span = old[i],
marker = span.marker;
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
}
}
}
return nw;
}
function markedSpansAfter(old, endCh, isInsert) {
var nw;
if (old) {
for (var i = 0; i < old.length; ++i) {
var span = old[i],
marker = span.marker;
var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh, span.to == null ? null : span.to - endCh));
}
}
}
return nw;
}
// Given a change object, compute the new set of marker spans that
// cover the line in which the change took place. Removes spans
// entirely within the change, reconnects spans belonging to the
// same marker that appear on both sides of the change, and cuts off
// spans partially within the change. Returns an array of span
// arrays with one element for each line in (after) the change.
function stretchSpansOverChange(doc, change) {
if (change.full) {
return null;
}
var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
if (!oldFirst && !oldLast) {
return null;
}
var startCh = change.from.ch,
endCh = change.to.ch,
isInsert = cmp(change.from, change.to) == 0;
// Get the spans that 'stick out' on both sides
var first = markedSpansBefore(oldFirst, startCh, isInsert);
var last = markedSpansAfter(oldLast, endCh, isInsert);
// Next, merge those two ends
var sameLine = change.text.length == 1,
offset = lst(change.text).length + (sameLine ? startCh : 0);
if (first) {
// Fix up .to properties of first
for (var i = 0; i < first.length; ++i) {
var span = first[i];
if (span.to == null) {
var found = getMarkedSpanFor(last, span.marker);
if (!found) {
span.to = startCh;
} else if (sameLine) {
span.to = found.to == null ? null : found.to + offset;
}
}
}
}
if (last) {
// Fix up .from in last (or move them into first in case of sameLine)
for (var i$1 = 0; i$1 < last.length; ++i$1) {
var span$1 = last[i$1];
if (span$1.to != null) {
span$1.to += offset;
}
if (span$1.from == null) {
var found$1 = getMarkedSpanFor(first, span$1.marker);
if (!found$1) {
span$1.from = offset;
if (sameLine) {
(first || (first = [])).push(span$1);
}
}
} else {
span$1.from += offset;
if (sameLine) {
(first || (first = [])).push(span$1);
}
}
}
}
// Make sure we didn't create any zero-length spans
if (first) {
first = clearEmptySpans(first);
}
if (last && last != first) {
last = clearEmptySpans(last);
}
var newMarkers = [first];
if (!sameLine) {
// Fill gap with whole-line-spans
var gap = change.text.length - 2,
gapMarkers;
if (gap > 0 && first) {
for (var i$2 = 0; i$2 < first.length; ++i$2) {
if (first[i$2].to == null) {
(gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null));
}
}
}
for (var i$3 = 0; i$3 < gap; ++i$3) {
newMarkers.push(gapMarkers);
}
newMarkers.push(last);
}
return newMarkers;
}
// Remove spans that are empty and don't have a clearWhenEmpty
// option of false.
function clearEmptySpans(spans) {
for (var i = 0; i < spans.length; ++i) {
var span = spans[i];
if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false) {
spans.splice(i--, 1);
}
}
if (!spans.length) {
return null;
}
return spans;
}
// Used to 'clip' out readOnly ranges when making a change.
function removeReadOnlyRanges(doc, from, to) {
var markers = null;
doc.iter(from.line, to.line + 1, function (line) {
if (line.markedSpans) {
for (var i = 0; i < line.markedSpans.length; ++i) {
var mark = line.markedSpans[i].marker;
if (mark.readOnly && (!markers || indexOf(markers, mark) == -1)) {
(markers || (markers = [])).push(mark);
}
}
}
});
if (!markers) {
return null;
}
var parts = [{ from: from, to: to }];
for (var i = 0; i < markers.length; ++i) {
var mk = markers[i],
m = mk.find(0);
for (var j = 0; j < parts.length; ++j) {
var p = parts[j];
if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) {
continue;
}
var newParts = [j, 1],
dfrom = cmp(p.from, m.from),
dto = cmp(p.to, m.to);
if (dfrom < 0 || !mk.inclusiveLeft && !dfrom) {
newParts.push({ from: p.from, to: m.from });
}
if (dto > 0 || !mk.inclusiveRight && !dto) {
newParts.push({ from: m.to, to: p.to });
}
parts.splice.apply(parts, newParts);
j += newParts.length - 3;
}
}
return parts;
}
// Connect or disconnect spans from a line.
function detachMarkedSpans(line) {
var spans = line.markedSpans;
if (!spans) {
return;
}
for (var i = 0; i < spans.length; ++i) {
spans[i].marker.detachLine(line);
}
line.markedSpans = null;
}
function attachMarkedSpans(line, spans) {
if (!spans) {
return;
}
for (var i = 0; i < spans.length; ++i) {
spans[i].marker.attachLine(line);
}
line.markedSpans = spans;
}
// Helpers used when computing which overlapping collapsed span
// counts as the larger one.
function extraLeft(marker) {
return marker.inclusiveLeft ? -1 : 0;
}
function extraRight(marker) {
return marker.inclusiveRight ? 1 : 0;
}
// Returns a number indicating which of two overlapping collapsed
// spans is larger (and thus includes the other). Falls back to
// comparing ids when the spans cover exactly the same range.
function compareCollapsedMarkers(a, b) {
var lenDiff = a.lines.length - b.lines.length;
if (lenDiff != 0) {
return lenDiff;
}
var aPos = a.find(),
bPos = b.find();
var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
if (fromCmp) {
return -fromCmp;
}
var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
if (toCmp) {
return toCmp;
}
return b.id - a.id;
}
// Find out whether a line ends or starts in a collapsed span. If
// so, return the marker for that span.
function collapsedSpanAtSide(line, start) {
var sps = sawCollapsedSpans && line.markedSpans,
found;
if (sps) {
for (var sp = void 0, i = 0; i < sps.length; ++i) {
sp = sps[i];
if (sp.marker.collapsed && (start ? sp.from : sp.to) == null && (!found || compareCollapsedMarkers(found, sp.marker) < 0)) {
found = sp.marker;
}
}
}
return found;
}
function collapsedSpanAtStart(line) {
return collapsedSpanAtSide(line, true);
}
function collapsedSpanAtEnd(line) {
return collapsedSpanAtSide(line, false);
}
function collapsedSpanAround(line, ch) {
var sps = sawCollapsedSpans && line.markedSpans,
found;
if (sps) {
for (var i = 0; i < sps.length; ++i) {
var sp = sps[i];
if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) && (!found || compareCollapsedMarkers(found, sp.marker) < 0)) {
found = sp.marker;
}
}
}
return found;
}
// Test whether there exists a collapsed span that partially
// overlaps (covers the start or end, but not both) of a new span.
// Such overlap is not allowed.
function conflictingCollapsedRange(doc, lineNo$$1, from, to, marker) {
var line = getLine(doc, lineNo$$1);
var sps = sawCollapsedSpans && line.markedSpans;
if (sps) {
for (var i = 0; i < sps.length; ++i) {
var sp = sps[i];
if (!sp.marker.collapsed) {
continue;
}
var found = sp.marker.find(0);
var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) {
continue;
}
if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) || fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0)) {
return true;
}
}
}
}
// A visual line is a line as drawn on the screen. Folding, for
// example, can cause multiple logical lines to appear on the same
// visual line. This finds the start of the visual line that the
// given line is part of (usually that is the line itself).
function visualLine(line) {
var merged;
while (merged = collapsedSpanAtStart(line)) {
line = merged.find(-1, true).line;
}
return line;
}
function visualLineEnd(line) {
var merged;
while (merged = collapsedSpanAtEnd(line)) {
line = merged.find(1, true).line;
}
return line;
}
// Returns an array of logical lines that continue the visual line
// started by the argument, or undefined if there are no such lines.
function visualLineContinued(line) {
var merged, lines;
while (merged = collapsedSpanAtEnd(line)) {
line = merged.find(1, true).line;(lines || (lines = [])).push(line);
}
return lines;
}
// Get the line number of the start of the visual line that the
// given line number is part of.
function visualLineNo(doc, lineN) {
var line = getLine(doc, lineN),
vis = visualLine(line);
if (line == vis) {
return lineN;
}
return lineNo(vis);
}
// Get the line number of the start of the next visual line after
// the given line.
function visualLineEndNo(doc, lineN) {
if (lineN > doc.lastLine()) {
return lineN;
}
var line = getLine(doc, lineN),
merged;
if (!lineIsHidden(doc, line)) {
return lineN;
}
while (merged = collapsedSpanAtEnd(line)) {
line = merged.find(1, true).line;
}
return lineNo(line) + 1;
}
// Compute whether a line is hidden. Lines count as hidden when they
// are part of a visual line that starts with another line, or when
// they are entirely covered by collapsed, non-widget span.
function lineIsHidden(doc, line) {
var sps = sawCollapsedSpans && line.markedSpans;
if (sps) {
for (var sp = void 0, i = 0; i < sps.length; ++i) {
sp = sps[i];
if (!sp.marker.collapsed) {
continue;
}
if (sp.from == null) {
return true;
}
if (sp.marker.widgetNode) {
continue;
}
if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp)) {
return true;
}
}
}
}
function lineIsHiddenInner(doc, line, span) {
if (span.to == null) {
var end = span.marker.find(1, true);
return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker));
}
if (span.marker.inclusiveRight && span.to == line.text.length) {
return true;
}
for (var sp = void 0, i = 0; i < line.markedSpans.length; ++i) {
sp = line.markedSpans[i];
if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to && (sp.to == null || sp.to != span.from) && (sp.marker.inclusiveLeft || span.marker.inclusiveRight) && lineIsHiddenInner(doc, line, sp)) {
return true;
}
}
}
// Find the height above the given line.
function heightAtLine(lineObj) {
lineObj = visualLine(lineObj);
var h = 0,
chunk = lineObj.parent;
for (var i = 0; i < chunk.lines.length; ++i) {
var line = chunk.lines[i];
if (line == lineObj) {
break;
} else {
h += line.height;
}
}
for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
var cur = p.children[i$1];
if (cur == chunk) {
break;
} else {
h += cur.height;
}
}
}
return h;
}
// Compute the character length of a line, taking into account
// collapsed ranges (see markText) that might hide parts, and join
// other lines onto it.
function lineLength(line) {
if (line.height == 0) {
return 0;
}
var len = line.text.length,
merged,
cur = line;
while (merged = collapsedSpanAtStart(cur)) {
var found = merged.find(0, true);
cur = found.from.line;
len += found.from.ch - found.to.ch;
}
cur = line;
while (merged = collapsedSpanAtEnd(cur)) {
var found$1 = merged.find(0, true);
len -= cur.text.length - found$1.from.ch;
cur = found$1.to.line;
len += cur.text.length - found$1.to.ch;
}
return len;
}
// Find the longest line in the document.
function findMaxLine(cm) {
var d = cm.display,
doc = cm.doc;
d.maxLine = getLine(doc, doc.first);
d.maxLineLength = lineLength(d.maxLine);
d.maxLineChanged = true;
doc.iter(function (line) {
var len = lineLength(line);
if (len > d.maxLineLength) {
d.maxLineLength = len;
d.maxLine = line;
}
});
}
// BIDI HELPERS
function iterateBidiSections(order, from, to, f) {
if (!order) {
return f(from, to, "ltr", 0);
}
var found = false;
for (var i = 0; i < order.length; ++i) {
var part = order[i];
if (part.from < to && part.to > from || from == to && part.to == from) {
f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i);
found = true;
}
}
if (!found) {
f(from, to, "ltr");
}
}
var bidiOther = null;
function getBidiPartAt(order, ch, sticky) {
var found;
bidiOther = null;
for (var i = 0; i < order.length; ++i) {
var cur = order[i];
if (cur.from < ch && cur.to > ch) {
return i;
}
if (cur.to == ch) {
if (cur.from != cur.to && sticky == "before") {
found = i;
} else {
bidiOther = i;
}
}
if (cur.from == ch) {
if (cur.from != cur.to && sticky != "before") {
found = i;
} else {
bidiOther = i;
}
}
}
return found != null ? found : bidiOther;
}
// Bidirectional ordering algorithm
// See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
// that this (partially) implements.
// One-char codes used for character types:
// L (L): Left-to-Right
// R (R): Right-to-Left
// r (AL): Right-to-Left Arabic
// 1 (EN): European Number
// + (ES): European Number Separator
// % (ET): European Number Terminator
// n (AN): Arabic Number
// , (CS): Common Number Separator
// m (NSM): Non-Spacing Mark
// b (BN): Boundary Neutral
// s (B): Paragraph Separator
// t (S): Segment Separator
// w (WS): Whitespace
// N (ON): Other Neutrals
// Returns null if characters are ordered as they appear
// (left-to-right), or an array of sections ({from, to, level}
// objects) in the order in which they occur visually.
var bidiOrdering = function () {
// Character types for codepoints 0 to 0xff
var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
// Character types for codepoints 0x600 to 0x6f9
var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
function charType(code) {
if (code <= 0xf7) {
return lowTypes.charAt(code);
} else if (0x590 <= code && code <= 0x5f4) {
return "R";
} else if (0x600 <= code && code <= 0x6f9) {
return arabicTypes.charAt(code - 0x600);
} else if (0x6ee <= code && code <= 0x8ac) {
return "r";
} else if (0x2000 <= code && code <= 0x200b) {
return "w";
} else if (code == 0x200c) {
return "b";
} else {
return "L";
}
}
var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
var isNeutral = /[stwN]/,
isStrong = /[LRr]/,
countsAsLeft = /[Lb1n]/,
countsAsNum = /[1n]/;
function BidiSpan(level, from, to) {
this.level = level;
this.from = from;this.to = to;
}
return function (str, direction) {
var outerType = direction == "ltr" ? "L" : "R";
if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) {
return false;
}
var len = str.length,
types = [];
for (var i = 0; i < len; ++i) {
types.push(charType(str.charCodeAt(i)));
}
// W1. Examine each non-spacing mark (NSM) in the level run, and
// change the type of the NSM to the type of the previous
// character. If the NSM is at the start of the level run, it will
// get the type of sor.
for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
var type = types[i$1];
if (type == "m") {
types[i$1] = prev;
} else {
prev = type;
}
}
// W2. Search backwards from each instance of a European number
// until the first strong type (R, L, AL, or sor) is found. If an
// AL is found, change the type of the European number to Arabic
// number.
// W3. Change all ALs to R.
for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
var type$1 = types[i$2];
if (type$1 == "1" && cur == "r") {
types[i$2] = "n";
} else if (isStrong.test(type$1)) {
cur = type$1;if (type$1 == "r") {
types[i$2] = "R";
}
}
}
// W4. A single European separator between two European numbers
// changes to a European number. A single common separator between
// two numbers of the same type changes to that type.
for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
var type$2 = types[i$3];
if (type$2 == "+" && prev$1 == "1" && types[i$3 + 1] == "1") {
types[i$3] = "1";
} else if (type$2 == "," && prev$1 == types[i$3 + 1] && (prev$1 == "1" || prev$1 == "n")) {
types[i$3] = prev$1;
}
prev$1 = type$2;
}
// W5. A sequence of European terminators adjacent to European
// numbers changes to all European numbers.
// W6. Otherwise, separators and terminators change to Other
// Neutral.
for (var i$4 = 0; i$4 < len; ++i$4) {
var type$3 = types[i$4];
if (type$3 == ",") {
types[i$4] = "N";
} else if (type$3 == "%") {
var end = void 0;
for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
var replace = i$4 && types[i$4 - 1] == "!" || end < len && types[end] == "1" ? "1" : "N";
for (var j = i$4; j < end; ++j) {
types[j] = replace;
}
i$4 = end - 1;
}
}
// W7. Search backwards from each instance of a European number
// until the first strong type (R, L, or sor) is found. If an L is
// found, then change the type of the European number to L.
for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
var type$4 = types[i$5];
if (cur$1 == "L" && type$4 == "1") {
types[i$5] = "L";
} else if (isStrong.test(type$4)) {
cur$1 = type$4;
}
}
// N1. A sequence of neutrals takes the direction of the
// surrounding strong text if the text on both sides has the same
// direction. European and Arabic numbers act as if they were R in
// terms of their influence on neutrals. Start-of-level-run (sor)
// and end-of-level-run (eor) are used at level run boundaries.
// N2. Any remaining neutrals take the embedding direction.
for (var i$6 = 0; i$6 < len; ++i$6) {
if (isNeutral.test(types[i$6])) {
var end$1 = void 0;
for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
var before = (i$6 ? types[i$6 - 1] : outerType) == "L";
var after = (end$1 < len ? types[end$1] : outerType) == "L";
var replace$1 = before == after ? before ? "L" : "R" : outerType;
for (var j$1 = i$6; j$1 < end$1; ++j$1) {
types[j$1] = replace$1;
}
i$6 = end$1 - 1;
}
}
// Here we depart from the documented algorithm, in order to avoid
// building up an actual levels array. Since there are only three
// levels (0, 1, 2) in an implementation that doesn't take
// explicit embedding into account, we can build up the order on
// the fly, without following the level-based algorithm.
var order = [],
m;
for (var i$7 = 0; i$7 < len;) {
if (countsAsLeft.test(types[i$7])) {
var start = i$7;
for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
order.push(new BidiSpan(0, start, i$7));
} else {
var pos = i$7,
at = order.length;
for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
for (var j$2 = pos; j$2 < i$7;) {
if (countsAsNum.test(types[j$2])) {
if (pos < j$2) {
order.splice(at, 0, new BidiSpan(1, pos, j$2));
}
var nstart = j$2;
for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
order.splice(at, 0, new BidiSpan(2, nstart, j$2));
pos = j$2;
} else {
++j$2;
}
}
if (pos < i$7) {
order.splice(at, 0, new BidiSpan(1, pos, i$7));
}
}
}
if (direction == "ltr") {
if (order[0].level == 1 && (m = str.match(/^\s+/))) {
order[0].from = m[0].length;
order.unshift(new BidiSpan(0, 0, m[0].length));
}
if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
lst(order).to -= m[0].length;
order.push(new BidiSpan(0, len - m[0].length, len));
}
}
return direction == "rtl" ? order.reverse() : order;
};
}();
// Get the bidi ordering for the given line (and cache it). Returns
// false for lines that are fully left-to-right, and an array of
// BidiSpan objects otherwise.
function getOrder(line, direction) {
var order = line.order;
if (order == null) {
order = line.order = bidiOrdering(line.text, direction);
}
return order;
}
// EVENT HANDLING
// Lightweight event framework. on/off also work on DOM nodes,
// registering native DOM handlers.
var noHandlers = [];
var on = function (emitter, type, f) {
if (emitter.addEventListener) {
emitter.addEventListener(type, f, false);
} else if (emitter.attachEvent) {
emitter.attachEvent("on" + type, f);
} else {
var map$$1 = emitter._handlers || (emitter._handlers = {});
map$$1[type] = (map$$1[type] || noHandlers).concat(f);
}
};
function getHandlers(emitter, type) {
return emitter._handlers && emitter._handlers[type] || noHandlers;
}
function off(emitter, type, f) {
if (emitter.removeEventListener) {
emitter.removeEventListener(type, f, false);
} else if (emitter.detachEvent) {
emitter.detachEvent("on" + type, f);
} else {
var map$$1 = emitter._handlers,
arr = map$$1 && map$$1[type];
if (arr) {
var index = indexOf(arr, f);
if (index > -1) {
map$$1[type] = arr.slice(0, index).concat(arr.slice(index + 1));
}
}
}
}
function signal(emitter, type /*, values...*/) {
var handlers = getHandlers(emitter, type);
if (!handlers.length) {
return;
}
var args = Array.prototype.slice.call(arguments, 2);
for (var i = 0; i < handlers.length; ++i) {
handlers[i].apply(null, args);
}
}
// The DOM events that CodeMirror handles can be overridden by
// registering a (non-DOM) handler on the editor for the event name,
// and preventDefault-ing the event in that handler.
function signalDOMEvent(cm, e, override) {
if (typeof e == "string") {
e = { type: e, preventDefault: function () {
this.defaultPrevented = true;
} };
}
signal(cm, override || e.type, cm, e);
return e_defaultPrevented(e) || e.codemirrorIgnore;
}
function signalCursorActivity(cm) {
var arr = cm._handlers && cm._handlers.cursorActivity;
if (!arr) {
return;
}
var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
for (var i = 0; i < arr.length; ++i) {
if (indexOf(set, arr[i]) == -1) {
set.push(arr[i]);
}
}
}
function hasHandler(emitter, type) {
return getHandlers(emitter, type).length > 0;
}
// Add on and off methods to a constructor's prototype, to make
// registering events on such objects more convenient.
function eventMixin(ctor) {
ctor.prototype.on = function (type, f) {
on(this, type, f);
};
ctor.prototype.off = function (type, f) {
off(this, type, f);
};
}
// Due to the fact that we still support jurassic IE versions, some
// compatibility wrappers are needed.
function e_preventDefault(e) {
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}
function e_stopPropagation(e) {
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
}
function e_defaultPrevented(e) {
return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
}
function e_stop(e) {
e_preventDefault(e);e_stopPropagation(e);
}
function e_target(e) {
return e.target || e.srcElement;
}
function e_button(e) {
var b = e.which;
if (b == null) {
if (e.button & 1) {
b = 1;
} else if (e.button & 2) {
b = 3;
} else if (e.button & 4) {
b = 2;
}
}
if (mac && e.ctrlKey && b == 1) {
b = 3;
}
return b;
}
// Detect drag-and-drop
var dragAndDrop = function () {
// There is *some* kind of drag-and-drop support in IE6-8, but I
// couldn't get it to work yet.
if (ie && ie_version < 9) {
return false;
}
var div = elt('div');
return "draggable" in div || "dragDrop" in div;
}();
var zwspSupported;
function zeroWidthElement(measure) {
if (zwspSupported == null) {
var test = elt("span", "\u200b");
removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
if (measure.firstChild.offsetHeight != 0) {
zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8);
}
}
var node = zwspSupported ? elt("span", "\u200b") : elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
node.setAttribute("cm-text", "");
return node;
}
// Feature-detect IE's crummy client rect reporting for bidi text
var badBidiRects;
function hasBadBidiRects(measure) {
if (badBidiRects != null) {
return badBidiRects;
}
var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
var r0 = range(txt, 0, 1).getBoundingClientRect();
var r1 = range(txt, 1, 2).getBoundingClientRect();
removeChildren(measure);
if (!r0 || r0.left == r0.right) {
return false;
} // Safari returns null in some cases (#2780)
return badBidiRects = r1.right - r0.right < 3;
}
// See if "".split is the broken IE version, if so, provide an
// alternative way to split lines.
var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
var pos = 0,
result = [],
l = string.length;
while (pos <= l) {
var nl = string.indexOf("\n", pos);
if (nl == -1) {
nl = string.length;
}
var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
var rt = line.indexOf("\r");
if (rt != -1) {
result.push(line.slice(0, rt));
pos += rt + 1;
} else {
result.push(line);
pos = nl + 1;
}
}
return result;
} : function (string) {
return string.split(/\r\n?|\n/);
};
var hasSelection = window.getSelection ? function (te) {
try {
return te.selectionStart != te.selectionEnd;
} catch (e) {
return false;
}
} : function (te) {
var range$$1;
try {
range$$1 = te.ownerDocument.selection.createRange();
} catch (e) {}
if (!range$$1 || range$$1.parentElement() != te) {
return false;
}
return range$$1.compareEndPoints("StartToEnd", range$$1) != 0;
};
var hasCopyEvent = function () {
var e = elt("div");
if ("oncopy" in e) {
return true;
}
e.setAttribute("oncopy", "return;");
return typeof e.oncopy == "function";
}();
var badZoomedRects = null;
function hasBadZoomedRects(measure) {
if (badZoomedRects != null) {
return badZoomedRects;
}
var node = removeChildrenAndAdd(measure, elt("span", "x"));
var normal = node.getBoundingClientRect();
var fromRange = range(node, 0, 1).getBoundingClientRect();
return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1;
}
// Known modes, by name and by MIME
var modes = {};
var mimeModes = {};
// Extra arguments are stored as the mode's dependencies, which is
// used by (legacy) mechanisms like loadmode.js to automatically
// load a mode. (Preferred mechanism is the require/define calls.)
function defineMode(name, mode) {
if (arguments.length > 2) {
mode.dependencies = Array.prototype.slice.call(arguments, 2);
}
modes[name] = mode;
}
function defineMIME(mime, spec) {
mimeModes[mime] = spec;
}
// Given a MIME type, a {name, ...options} config object, or a name
// string, return a mode config object.
function resolveMode(spec) {
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
spec = mimeModes[spec];
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
var found = mimeModes[spec.name];
if (typeof found == "string") {
found = { name: found };
}
spec = createObj(found, spec);
spec.name = found.name;
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
return resolveMode("application/xml");
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
return resolveMode("application/json");
}
if (typeof spec == "string") {
return { name: spec };
} else {
return spec || { name: "null" };
}
}
// Given a mode spec (anything that resolveMode accepts), find and
// initialize an actual mode object.
function getMode(options, spec) {
spec = resolveMode(spec);
var mfactory = modes[spec.name];
if (!mfactory) {
return getMode(options, "text/plain");
}
var modeObj = mfactory(options, spec);
if (modeExtensions.hasOwnProperty(spec.name)) {
var exts = modeExtensions[spec.name];
for (var prop in exts) {
if (!exts.hasOwnProperty(prop)) {
continue;
}
if (modeObj.hasOwnProperty(prop)) {
modeObj["_" + prop] = modeObj[prop];
}
modeObj[prop] = exts[prop];
}
}
modeObj.name = spec.name;
if (spec.helperType) {
modeObj.helperType = spec.helperType;
}
if (spec.modeProps) {
for (var prop$1 in spec.modeProps) {
modeObj[prop$1] = spec.modeProps[prop$1];
}
}
return modeObj;
}
// This can be used to attach properties to mode objects from
// outside the actual mode definition.
var modeExtensions = {};
function extendMode(mode, properties) {
var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : modeExtensions[mode] = {};
copyObj(properties, exts);
}
function copyState(mode, state) {
if (state === true) {
return state;
}
if (mode.copyState) {
return mode.copyState(state);
}
var nstate = {};
for (var n in state) {
var val = state[n];
if (val instanceof Array) {
val = val.concat([]);
}
nstate[n] = val;
}
return nstate;
}
// Given a mode and a state (for that mode), find the inner mode and
// state at the position that the state refers to.
function innerMode(mode, state) {
var info;
while (mode.innerMode) {
info = mode.innerMode(state);
if (!info || info.mode == mode) {
break;
}
state = info.state;
mode = info.mode;
}
return info || { mode: mode, state: state };
}
function startState(mode, a1, a2) {
return mode.startState ? mode.startState(a1, a2) : true;
}
// STRING STREAM
// Fed to the mode parsers, provides helper functions to make
// parsers more succinct.
var StringStream = function (string, tabSize, lineOracle) {
this.pos = this.start = 0;
this.string = string;
this.tabSize = tabSize || 8;
this.lastColumnPos = this.lastColumnValue = 0;
this.lineStart = 0;
this.lineOracle = lineOracle;
};
StringStream.prototype.eol = function () {
return this.pos >= this.string.length;
};
StringStream.prototype.sol = function () {
return this.pos == this.lineStart;
};
StringStream.prototype.peek = function () {
return this.string.charAt(this.pos) || undefined;
};
StringStream.prototype.next = function () {
if (this.pos < this.string.length) {
return this.string.charAt(this.pos++);
}
};
StringStream.prototype.eat = function (match) {
var ch = this.string.charAt(this.pos);
var ok;
if (typeof match == "string") {
ok = ch == match;
} else {
ok = ch && (match.test ? match.test(ch) : match(ch));
}
if (ok) {
++this.pos;return ch;
}
};
StringStream.prototype.eatWhile = function (match) {
var start = this.pos;
while (this.eat(match)) {}
return this.pos > start;
};
StringStream.prototype.eatSpace = function () {
var this$1 = this;
var start = this.pos;
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) {
++this$1.pos;
}
return this.pos > start;
};
StringStream.prototype.skipToEnd = function () {
this.pos = this.string.length;
};
StringStream.prototype.skipTo = function (ch) {
var found = this.string.indexOf(ch, this.pos);
if (found > -1) {
this.pos = found;return true;
}
};
StringStream.prototype.backUp = function (n) {
this.pos -= n;
};
StringStream.prototype.column = function () {
if (this.lastColumnPos < this.start) {
this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
this.lastColumnPos = this.start;
}
return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
};
StringStream.prototype.indentation = function () {
return countColumn(this.string, null, this.tabSize) - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
};
StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
if (typeof pattern == "string") {
var cased = function (str) {
return caseInsensitive ? str.toLowerCase() : str;
};
var substr = this.string.substr(this.pos, pattern.length);
if (cased(substr) == cased(pattern)) {
if (consume !== false) {
this.pos += pattern.length;
}
return true;
}
} else {
var match = this.string.slice(this.pos).match(pattern);
if (match && match.index > 0) {
return null;
}
if (match && consume !== false) {
this.pos += match[0].length;
}
return match;
}
};
StringStream.prototype.current = function () {
return this.string.slice(this.start, this.pos);
};
StringStream.prototype.hideFirstChars = function (n, inner) {
this.lineStart += n;
try {
return inner();
} finally {
this.lineStart -= n;
}
};
StringStream.prototype.lookAhead = function (n) {
var oracle = this.lineOracle;
return oracle && oracle.lookAhead(n);
};
StringStream.prototype.baseToken = function () {
var oracle = this.lineOracle;
return oracle && oracle.baseToken(this.pos);
};
var SavedContext = function (state, lookAhead) {
this.state = state;
this.lookAhead = lookAhead;
};
var Context = function (doc, state, line, lookAhead) {
this.state = state;
this.doc = doc;
this.line = line;
this.maxLookAhead = lookAhead || 0;
this.baseTokens = null;
this.baseTokenPos = 1;
};
Context.prototype.lookAhead = function (n) {
var line = this.doc.getLine(this.line + n);
if (line != null && n > this.maxLookAhead) {
this.maxLookAhead = n;
}
return line;
};
Context.prototype.baseToken = function (n) {
var this$1 = this;
if (!this.baseTokens) {
return null;
}
while (this.baseTokens[this.baseTokenPos] <= n) {
this$1.baseTokenPos += 2;
}
var type = this.baseTokens[this.baseTokenPos + 1];
return { type: type && type.replace(/( |^)overlay .*/, ""),
size: this.baseTokens[this.baseTokenPos] - n };
};
Context.prototype.nextLine = function () {
this.line++;
if (this.maxLookAhead > 0) {
this.maxLookAhead--;
}
};
Context.fromSaved = function (doc, saved, line) {
if (saved instanceof SavedContext) {
return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead);
} else {
return new Context(doc, copyState(doc.mode, saved), line);
}
};
Context.prototype.save = function (copy) {
var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state;
return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state;
};
// Compute a style array (an array starting with a mode generation
// -- for invalidation -- followed by pairs of end positions and
// style strings), which is used to highlight the tokens on the
// line.
function highlightLine(cm, line, context, forceToEnd) {
// A styles array always starts with a number identifying the
// mode/overlays that it is based on (for easy invalidation).
var st = [cm.state.modeGen],
lineClasses = {};
// Compute the base array of styles
runMode(cm, line.text, cm.doc.mode, context, function (end, style) {
return st.push(end, style);
}, lineClasses, forceToEnd);
var state = context.state;
// Run overlays, adjust style array.
var loop = function (o) {
context.baseTokens = st;
var overlay = cm.state.overlays[o],
i = 1,
at = 0;
context.state = true;
runMode(cm, line.text, overlay.mode, context, function (end, style) {
var start = i;
// Ensure there's a token end at the current position, and that i points at it
while (at < end) {
var i_end = st[i];
if (i_end > end) {
st.splice(i, 1, end, st[i + 1], i_end);
}
i += 2;
at = Math.min(end, i_end);
}
if (!style) {
return;
}
if (overlay.opaque) {
st.splice(start, i - start, end, "overlay " + style);
i = start + 2;
} else {
for (; start < i; start += 2) {
var cur = st[start + 1];
st[start + 1] = (cur ? cur + " " : "") + "overlay " + style;
}
}
}, lineClasses);
context.state = state;
context.baseTokens = null;
context.baseTokenPos = 1;
};
for (var o = 0; o < cm.state.overlays.length; ++o) loop(o);
return { styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null };
}
function getLineStyles(cm, line, updateFrontier) {
if (!line.styles || line.styles[0] != cm.state.modeGen) {
var context = getContextBefore(cm, lineNo(line));
var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state);
var result = highlightLine(cm, line, context);
if (resetState) {
context.state = resetState;
}
line.stateAfter = context.save(!resetState);
line.styles = result.styles;
if (result.classes) {
line.styleClasses = result.classes;
} else if (line.styleClasses) {
line.styleClasses = null;
}
if (updateFrontier === cm.doc.highlightFrontier) {
cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier);
}
}
return line.styles;
}
function getContextBefore(cm, n, precise) {
var doc = cm.doc,
display = cm.display;
if (!doc.mode.startState) {
return new Context(doc, true, n);
}
var start = findStartLine(cm, n, precise);
var saved = start > doc.first && getLine(doc, start - 1).stateAfter;
var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start);
doc.iter(start, n, function (line) {
processLine(cm, line.text, context);
var pos = context.line;
line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null;
context.nextLine();
});
if (precise) {
doc.modeFrontier = context.line;
}
return context;
}
// Lightweight form of highlight -- proceed over this line and
// update state, but don't save a style array. Used for lines that
// aren't currently visible.
function processLine(cm, text, context, startAt) {
var mode = cm.doc.mode;
var stream = new StringStream(text, cm.options.tabSize, context);
stream.start = stream.pos = startAt || 0;
if (text == "") {
callBlankLine(mode, context.state);
}
while (!stream.eol()) {
readToken(mode, stream, context.state);
stream.start = stream.pos;
}
}
function callBlankLine(mode, state) {
if (mode.blankLine) {
return mode.blankLine(state);
}
if (!mode.innerMode) {
return;
}
var inner = innerMode(mode, state);
if (inner.mode.blankLine) {
return inner.mode.blankLine(inner.state);
}
}
function readToken(mode, stream, state, inner) {
for (var i = 0; i < 10; i++) {
if (inner) {
inner[0] = innerMode(mode, state).mode;
}
var style = mode.token(stream, state);
if (stream.pos > stream.start) {
return style;
}
}
throw new Error("Mode " + mode.name + " failed to advance stream.");
}
var Token = function (stream, type, state) {
this.start = stream.start;this.end = stream.pos;
this.string = stream.current();
this.type = type || null;
this.state = state;
};
// Utility for getTokenAt and getLineTokens
function takeToken(cm, pos, precise, asArray) {
var doc = cm.doc,
mode = doc.mode,
style;
pos = clipPos(doc, pos);
var line = getLine(doc, pos.line),
context = getContextBefore(cm, pos.line, precise);
var stream = new StringStream(line.text, cm.options.tabSize, context),
tokens;
if (asArray) {
tokens = [];
}
while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
stream.start = stream.pos;
style = readToken(mode, stream, context.state);
if (asArray) {
tokens.push(new Token(stream, style, copyState(doc.mode, context.state)));
}
}
return asArray ? tokens : new Token(stream, style, context.state);
}
function extractLineClasses(type, output) {
if (type) {
for (;;) {
var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
if (!lineClass) {
break;
}
type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
var prop = lineClass[1] ? "bgClass" : "textClass";
if (output[prop] == null) {
output[prop] = lineClass[2];
} else if (!new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)").test(output[prop])) {
output[prop] += " " + lineClass[2];
}
}
}
return type;
}
// Run the given mode's parser over a line, calling f for each token.
function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
var flattenSpans = mode.flattenSpans;
if (flattenSpans == null) {
flattenSpans = cm.options.flattenSpans;
}
var curStart = 0,
curStyle = null;
var stream = new StringStream(text, cm.options.tabSize, context),
style;
var inner = cm.options.addModeClass && [null];
if (text == "") {
extractLineClasses(callBlankLine(mode, context.state), lineClasses);
}
while (!stream.eol()) {
if (stream.pos > cm.options.maxHighlightLength) {
flattenSpans = false;
if (forceToEnd) {
processLine(cm, text, context, stream.pos);
}
stream.pos = text.length;
style = null;
} else {
style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses);
}
if (inner) {
var mName = inner[0].name;
if (mName) {
style = "m-" + (style ? mName + " " + style : mName);
}
}
if (!flattenSpans || curStyle != style) {
while (curStart < stream.start) {
curStart = Math.min(stream.start, curStart + 5000);
f(curStart, curStyle);
}
curStyle = style;
}
stream.start = stream.pos;
}
while (curStart < stream.pos) {
// Webkit seems to refuse to render text nodes longer than 57444
// characters, and returns inaccurate measurements in nodes
// starting around 5000 chars.
var pos = Math.min(stream.pos, curStart + 5000);
f(pos, curStyle);
curStart = pos;
}
}
// Finds the line to start with when starting a parse. Tries to
// find a line with a stateAfter, so that it can start with a
// valid state. If that fails, it returns the line with the
// smallest indentation, which tends to need the least context to
// parse correctly.
function findStartLine(cm, n, precise) {
var minindent,
minline,
doc = cm.doc;
var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
for (var search = n; search > lim; --search) {
if (search <= doc.first) {
return doc.first;
}
var line = getLine(doc, search - 1),
after = line.stateAfter;
if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier)) {
return search;
}
var indented = countColumn(line.text, null, cm.options.tabSize);
if (minline == null || minindent > indented) {
minline = search - 1;
minindent = indented;
}
}
return minline;
}
function retreatFrontier(doc, n) {
doc.modeFrontier = Math.min(doc.modeFrontier, n);
if (doc.highlightFrontier < n - 10) {
return;
}
var start = doc.first;
for (var line = n - 1; line > start; line--) {
var saved = getLine(doc, line).stateAfter;
// change is on 3
// state on line 1 looked ahead 2 -- so saw 3
// test 1 + 2 < 3 should cover this
if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
start = line + 1;
break;
}
}
doc.highlightFrontier = Math.min(doc.highlightFrontier, start);
}
// LINE DATA STRUCTURE
// Line objects. These hold state related to a line, including
// highlighting info (the styles array).
var Line = function (text, markedSpans, estimateHeight) {
this.text = text;
attachMarkedSpans(this, markedSpans);
this.height = estimateHeight ? estimateHeight(this) : 1;
};
Line.prototype.lineNo = function () {
return lineNo(this);
};
eventMixin(Line);
// Change the content (text, markers) of a line. Automatically
// invalidates cached information and tries to re-estimate the
// line's height.
function updateLine(line, text, markedSpans, estimateHeight) {
line.text = text;
if (line.stateAfter) {
line.stateAfter = null;
}
if (line.styles) {
line.styles = null;
}
if (line.order != null) {
line.order = null;
}
detachMarkedSpans(line);
attachMarkedSpans(line, markedSpans);
var estHeight = estimateHeight ? estimateHeight(line) : 1;
if (estHeight != line.height) {
updateLineHeight(line, estHeight);
}
}
// Detach a line from the document tree and its markers.
function cleanUpLine(line) {
line.parent = null;
detachMarkedSpans(line);
}
// Convert a style as returned by a mode (either null, or a string
// containing one or more styles) to a CSS style. This is cached,
// and also looks for line-wide styles.
var styleToClassCache = {};
var styleToClassCacheWithMode = {};
function interpretTokenStyle(style, options) {
if (!style || /^\s*$/.test(style)) {
return null;
}
var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
return cache[style] || (cache[style] = style.replace(/\S+/g, "cm-$&"));
}
// Render the DOM representation of the text of a line. Also builds
// up a 'line map', which points at the DOM nodes that represent
// specific stretches of text, and is used by the measuring code.
// The returned object contains the DOM node, this map, and
// information about line-wide styles that were set by the mode.
function buildLineContent(cm, lineView) {
// The padding-right forces the element to have a 'border', which
// is needed on Webkit to be able to get line-level bounding
// rectangles for it (in measureChar).
var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null);
var builder = { pre: eltP("pre", [content], "CodeMirror-line"), content: content,
col: 0, pos: 0, cm: cm,
trailingSpace: false,
splitSpaces: (ie || webkit) && cm.getOption("lineWrapping") };
lineView.measure = {};
// Iterate over the logical lines that make up this visual line.
for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
var line = i ? lineView.rest[i - 1] : lineView.line,
order = void 0;
builder.pos = 0;
builder.addToken = buildToken;
// Optionally wire in some hacks into the token-rendering
// algorithm, to deal with browser quirks.
if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction))) {
builder.addToken = buildTokenBadBidi(builder.addToken, order);
}
builder.map = [];
var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
if (line.styleClasses) {
if (line.styleClasses.bgClass) {
builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "");
}
if (line.styleClasses.textClass) {
builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "");
}
}
// Ensure at least a single node is present, for measuring.
if (builder.map.length == 0) {
builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));
}
// Store the map and a cache object for the current logical line
if (i == 0) {
lineView.measure.map = builder.map;
lineView.measure.cache = {};
} else {
(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);(lineView.measure.caches || (lineView.measure.caches = [])).push({});
}
}
// See issue #2901
if (webkit) {
var last = builder.content.lastChild;
if (/\bcm-tab\b/.test(last.className) || last.querySelector && last.querySelector(".cm-tab")) {
builder.content.className = "cm-tab-wrap-hack";
}
}
signal(cm, "renderLine", cm, lineView.line, builder.pre);
if (builder.pre.className) {
builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
}
return builder;
}
function defaultSpecialCharPlaceholder(ch) {
var token = elt("span", "\u2022", "cm-invalidchar");
token.title = "\\u" + ch.charCodeAt(0).toString(16);
token.setAttribute("aria-label", token.title);
return token;
}
// Build up the DOM representation for a single token, and add it to
// the line map. Takes care to render special characters separately.
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
if (!text) {
return;
}
var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
var special = builder.cm.state.specialChars,
mustWrap = false;
var content;
if (!special.test(text)) {
builder.col += text.length;
content = document.createTextNode(displayText);
builder.map.push(builder.pos, builder.pos + text.length, content);
if (ie && ie_version < 9) {
mustWrap = true;
}
builder.pos += text.length;
} else {
content = document.createDocumentFragment();
var pos = 0;
while (true) {
special.lastIndex = pos;
var m = special.exec(text);
var skipped = m ? m.index - pos : text.length - pos;
if (skipped) {
var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
if (ie && ie_version < 9) {
content.appendChild(elt("span", [txt]));
} else {
content.appendChild(txt);
}
builder.map.push(builder.pos, builder.pos + skipped, txt);
builder.col += skipped;
builder.pos += skipped;
}
if (!m) {
break;
}
pos += skipped + 1;
var txt$1 = void 0;
if (m[0] == "\t") {
var tabSize = builder.cm.options.tabSize,
tabWidth = tabSize - builder.col % tabSize;
txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
txt$1.setAttribute("role", "presentation");
txt$1.setAttribute("cm-text", "\t");
builder.col += tabWidth;
} else if (m[0] == "\r" || m[0] == "\n") {
txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
txt$1.setAttribute("cm-text", m[0]);
builder.col += 1;
} else {
txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
txt$1.setAttribute("cm-text", m[0]);
if (ie && ie_version < 9) {
content.appendChild(elt("span", [txt$1]));
} else {
content.appendChild(txt$1);
}
builder.col += 1;
}
builder.map.push(builder.pos, builder.pos + 1, txt$1);
builder.pos++;
}
}
builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
if (style || startStyle || endStyle || mustWrap || css) {
var fullStyle = style || "";
if (startStyle) {
fullStyle += startStyle;
}
if (endStyle) {
fullStyle += endStyle;
}
var token = elt("span", [content], fullStyle, css);
if (title) {
token.title = title;
}
return builder.content.appendChild(token);
}
builder.content.appendChild(content);
}
function splitSpaces(text, trailingBefore) {
if (text.length > 1 && !/ /.test(text)) {
return text;
}
var spaceBefore = trailingBefore,
result = "";
for (var i = 0; i < text.length; i++) {
var ch = text.charAt(i);
if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) {
ch = "\u00a0";
}
result += ch;
spaceBefore = ch == " ";
}
return result;
}
// Work around nonsense dimensions being reported for stretches of
// right-to-left text.
function buildTokenBadBidi(inner, order) {
return function (builder, text, style, startStyle, endStyle, title, css) {
style = style ? style + " cm-force-border" : "cm-force-border";
var start = builder.pos,
end = start + text.length;
for (;;) {
// Find the part that overlaps with the start of this text
var part = void 0;
for (var i = 0; i < order.length; i++) {
part = order[i];
if (part.to > start && part.from <= start) {
break;
}
}
if (part.to >= end) {
return inner(builder, text, style, startStyle, endStyle, title, css);
}
inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css);
startStyle = null;
text = text.slice(part.to - start);
start = part.to;
}
};
}
function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
var widget = !ignoreWidget && marker.widgetNode;
if (widget) {
builder.map.push(builder.pos, builder.pos + size, widget);
}
if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
if (!widget) {
widget = builder.content.appendChild(document.createElement("span"));
}
widget.setAttribute("cm-marker", marker.id);
}
if (widget) {
builder.cm.display.input.setUneditable(widget);
builder.content.appendChild(widget);
}
builder.pos += size;
builder.trailingSpace = false;
}
// Outputs a number of spans to make up a line, taking highlighting
// and marked text into account.
function insertLineContent(line, builder, styles) {
var spans = line.markedSpans,
allText = line.text,
at = 0;
if (!spans) {
for (var i$1 = 1; i$1 < styles.length; i$1 += 2) {
builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1 + 1], builder.cm.options));
}
return;
}
var len = allText.length,
pos = 0,
i = 1,
text = "",
style,
css;
var nextChange = 0,
spanStyle,
spanEndStyle,
spanStartStyle,
title,
collapsed;
for (;;) {
if (nextChange == pos) {
// Update current marker set
spanStyle = spanEndStyle = spanStartStyle = title = css = "";
collapsed = null;nextChange = Infinity;
var foundBookmarks = [],
endStyles = void 0;
for (var j = 0; j < spans.length; ++j) {
var sp = spans[j],
m = sp.marker;
if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
foundBookmarks.push(m);
} else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
if (sp.to != null && sp.to != pos && nextChange > sp.to) {
nextChange = sp.to;
spanEndStyle = "";
}
if (m.className) {
spanStyle += " " + m.className;
}
if (m.css) {
css = (css ? css + ";" : "") + m.css;
}
if (m.startStyle && sp.from == pos) {
spanStartStyle += " " + m.startStyle;
}
if (m.endStyle && sp.to == nextChange) {
(endStyles || (endStyles = [])).push(m.endStyle, sp.to);
}
if (m.title && !title) {
title = m.title;
}
if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0)) {
collapsed = sp;
}
} else if (sp.from > pos && nextChange > sp.from) {
nextChange = sp.from;
}
}
if (endStyles) {
for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2) {
if (endStyles[j$1 + 1] == nextChange) {
spanEndStyle += " " + endStyles[j$1];
}
}
}
if (!collapsed || collapsed.from == pos) {
for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2) {
buildCollapsedSpan(builder, 0, foundBookmarks[j$2]);
}
}
if (collapsed && (collapsed.from || 0) == pos) {
buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos, collapsed.marker, collapsed.from == null);
if (collapsed.to == null) {
return;
}
if (collapsed.to == pos) {
collapsed = false;
}
}
}
if (pos >= len) {
break;
}
var upto = Math.min(len, nextChange);
while (true) {
if (text) {
var end = pos + text.length;
if (!collapsed) {
var tokenText = end > upto ? text.slice(0, upto - pos) : text;
builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle, spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css);
}
if (end >= upto) {
text = text.slice(upto - pos);pos = upto;break;
}
pos = end;
spanStartStyle = "";
}
text = allText.slice(at, at = styles[i++]);
style = interpretTokenStyle(styles[i++], builder.cm.options);
}
}
}
// These objects are used to represent the visible (currently drawn)
// part of the document. A LineView may correspond to multiple
// logical lines, if those are connected by collapsed ranges.
function LineView(doc, line, lineN) {
// The starting line
this.line = line;
// Continuing lines, if any
this.rest = visualLineContinued(line);
// Number of logical lines in this visual line
this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
this.node = this.text = null;
this.hidden = lineIsHidden(doc, line);
}
// Create a range of LineView objects for the given lines.
function buildViewArray(cm, from, to) {
var array = [],
nextPos;
for (var pos = from; pos < to; pos = nextPos) {
var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
nextPos = pos + view.size;
array.push(view);
}
return array;
}
var operationGroup = null;
function pushOperation(op) {
if (operationGroup) {
operationGroup.ops.push(op);
} else {
op.ownsGroup = operationGroup = {
ops: [op],
delayedCallbacks: []
};
}
}
function fireCallbacksForOps(group) {
// Calls delayed callbacks and cursorActivity handlers until no
// new ones appear
var callbacks = group.delayedCallbacks,
i = 0;
do {
for (; i < callbacks.length; i++) {
callbacks[i].call(null);
}
for (var j = 0; j < group.ops.length; j++) {
var op = group.ops[j];
if (op.cursorActivityHandlers) {
while (op.cursorActivityCalled < op.cursorActivityHandlers.length) {
op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm);
}
}
}
} while (i < callbacks.length);
}
function finishOperation(op, endCb) {
var group = op.ownsGroup;
if (!group) {
return;
}
try {
fireCallbacksForOps(group);
} finally {
operationGroup = null;
endCb(group);
}
}
var orphanDelayedCallbacks = null;
// Often, we want to signal events at a point where we are in the
// middle of some work, but don't want the handler to start calling
// other methods on the editor, which might be in an inconsistent
// state or simply not expect any other events to happen.
// signalLater looks whether there are any handlers, and schedules
// them to be executed when the last operation ends, or, if no
// operation is active, when a timeout fires.
function signalLater(emitter, type /*, values...*/) {
var arr = getHandlers(emitter, type);
if (!arr.length) {
return;
}
var args = Array.prototype.slice.call(arguments, 2),
list;
if (operationGroup) {
list = operationGroup.delayedCallbacks;
} else if (orphanDelayedCallbacks) {
list = orphanDelayedCallbacks;
} else {
list = orphanDelayedCallbacks = [];
setTimeout(fireOrphanDelayed, 0);
}
var loop = function (i) {
list.push(function () {
return arr[i].apply(null, args);
});
};
for (var i = 0; i < arr.length; ++i) loop(i);
}
function fireOrphanDelayed() {
var delayed = orphanDelayedCallbacks;
orphanDelayedCallbacks = null;
for (var i = 0; i < delayed.length; ++i) {
delayed[i]();
}
}
// When an aspect of a line changes, a string is added to
// lineView.changes. This updates the relevant part of the line's
// DOM structure.
function updateLineForChanges(cm, lineView, lineN, dims) {
for (var j = 0; j < lineView.changes.length; j++) {
var type = lineView.changes[j];
if (type == "text") {
updateLineText(cm, lineView);
} else if (type == "gutter") {
updateLineGutter(cm, lineView, lineN, dims);
} else if (type == "class") {
updateLineClasses(cm, lineView);
} else if (type == "widget") {
updateLineWidgets(cm, lineView, dims);
}
}
lineView.changes = null;
}
// Lines with gutter elements, widgets or a background class need to
// be wrapped, and have the extra elements added to the wrapper div
function ensureLineWrapped(lineView) {
if (lineView.node == lineView.text) {
lineView.node = elt("div", null, null, "position: relative");
if (lineView.text.parentNode) {
lineView.text.parentNode.replaceChild(lineView.node, lineView.text);
}
lineView.node.appendChild(lineView.text);
if (ie && ie_version < 8) {
lineView.node.style.zIndex = 2;
}
}
return lineView.node;
}
function updateLineBackground(cm, lineView) {
var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
if (cls) {
cls += " CodeMirror-linebackground";
}
if (lineView.background) {
if (cls) {
lineView.background.className = cls;
} else {
lineView.background.parentNode.removeChild(lineView.background);lineView.background = null;
}
} else if (cls) {
var wrap = ensureLineWrapped(lineView);
lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
cm.display.input.setUneditable(lineView.background);
}
}
// Wrapper around buildLineContent which will reuse the structure
// in display.externalMeasured when possible.
function getLineContent(cm, lineView) {
var ext = cm.display.externalMeasured;
if (ext && ext.line == lineView.line) {
cm.display.externalMeasured = null;
lineView.measure = ext.measure;
return ext.built;
}
return buildLineContent(cm, lineView);
}
// Redraw the line's text. Interacts with the background and text
// classes because the mode may output tokens that influence these
// classes.
function updateLineText(cm, lineView) {
var cls = lineView.text.className;
var built = getLineContent(cm, lineView);
if (lineView.text == lineView.node) {
lineView.node = built.pre;
}
lineView.text.parentNode.replaceChild(built.pre, lineView.text);
lineView.text = built.pre;
if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
lineView.bgClass = built.bgClass;
lineView.textClass = built.textClass;
updateLineClasses(cm, lineView);
} else if (cls) {
lineView.text.className = cls;
}
}
function updateLineClasses(cm, lineView) {
updateLineBackground(cm, lineView);
if (lineView.line.wrapClass) {
ensureLineWrapped(lineView).className = lineView.line.wrapClass;
} else if (lineView.node != lineView.text) {
lineView.node.className = "";
}
var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
lineView.text.className = textClass || "";
}
function updateLineGutter(cm, lineView, lineN, dims) {
if (lineView.gutter) {
lineView.node.removeChild(lineView.gutter);
lineView.gutter = null;
}
if (lineView.gutterBackground) {
lineView.node.removeChild(lineView.gutterBackground);
lineView.gutterBackground = null;
}
if (lineView.line.gutterClass) {
var wrap = ensureLineWrapped(lineView);
lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass, "left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + dims.gutterTotalWidth + "px");
cm.display.input.setUneditable(lineView.gutterBackground);
wrap.insertBefore(lineView.gutterBackground, lineView.text);
}
var markers = lineView.line.gutterMarkers;
if (cm.options.lineNumbers || markers) {
var wrap$1 = ensureLineWrapped(lineView);
var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", "left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px");
cm.display.input.setUneditable(gutterWrap);
wrap$1.insertBefore(gutterWrap, lineView.text);
if (lineView.line.gutterClass) {
gutterWrap.className += " " + lineView.line.gutterClass;
}
if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"])) {
lineView.lineNumber = gutterWrap.appendChild(elt("div", lineNumberFor(cm.options, lineN), "CodeMirror-linenumber CodeMirror-gutter-elt", "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: " + cm.display.lineNumInnerWidth + "px"));
}
if (markers) {
for (var k = 0; k < cm.options.gutters.length; ++k) {
var id = cm.options.gutters[k],
found = markers.hasOwnProperty(id) && markers[id];
if (found) {
gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " + dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
}
}
}
}
}
function updateLineWidgets(cm, lineView, dims) {
if (lineView.alignable) {
lineView.alignable = null;
}
for (var node = lineView.node.firstChild, next = void 0; node; node = next) {
next = node.nextSibling;
if (node.className == "CodeMirror-linewidget") {
lineView.node.removeChild(node);
}
}
insertLineWidgets(cm, lineView, dims);
}
// Build a line's DOM representation from scratch
function buildLineElement(cm, lineView, lineN, dims) {
var built = getLineContent(cm, lineView);
lineView.text = lineView.node = built.pre;
if (built.bgClass) {
lineView.bgClass = built.bgClass;
}
if (built.textClass) {
lineView.textClass = built.textClass;
}
updateLineClasses(cm, lineView);
updateLineGutter(cm, lineView, lineN, dims);
insertLineWidgets(cm, lineView, dims);
return lineView.node;
}
// A lineView may contain multiple logical lines (when merged by
// collapsed spans). The widgets for all of them need to be drawn.
function insertLineWidgets(cm, lineView, dims) {
insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
if (lineView.rest) {
for (var i = 0; i < lineView.rest.length; i++) {
insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false);
}
}
}
function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
if (!line.widgets) {
return;
}
var wrap = ensureLineWrapped(lineView);
for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
var widget = ws[i],
node = elt("div", [widget.node], "CodeMirror-linewidget");
if (!widget.handleMouseEvents) {
node.setAttribute("cm-ignore-events", "true");
}
positionLineWidget(widget, node, lineView, dims);
cm.display.input.setUneditable(node);
if (allowAbove && widget.above) {
wrap.insertBefore(node, lineView.gutter || lineView.text);
} else {
wrap.appendChild(node);
}
signalLater(widget, "redraw");
}
}
function positionLineWidget(widget, node, lineView, dims) {
if (widget.noHScroll) {
(lineView.alignable || (lineView.alignable = [])).push(node);
var width = dims.wrapperWidth;
node.style.left = dims.fixedPos + "px";
if (!widget.coverGutter) {
width -= dims.gutterTotalWidth;
node.style.paddingLeft = dims.gutterTotalWidth + "px";
}
node.style.width = width + "px";
}
if (widget.coverGutter) {
node.style.zIndex = 5;
node.style.position = "relative";
if (!widget.noHScroll) {
node.style.marginLeft = -dims.gutterTotalWidth + "px";
}
}
}
function widgetHeight(widget) {
if (widget.height != null) {
return widget.height;
}
var cm = widget.doc.cm;
if (!cm) {
return 0;
}
if (!contains(document.body, widget.node)) {
var parentStyle = "position: relative;";
if (widget.coverGutter) {
parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;";
}
if (widget.noHScroll) {
parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;";
}
removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
}
return widget.height = widget.node.parentNode.offsetHeight;
}
// Return true when the given mouse event happened in a widget
function eventInWidget(display, e) {
for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
if (!n || n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true" || n.parentNode == display.sizer && n != display.mover) {
return true;
}
}
}
// POSITION MEASUREMENT
function paddingTop(display) {
return display.lineSpace.offsetTop;
}
function paddingVert(display) {
return display.mover.offsetHeight - display.lineSpace.offsetHeight;
}
function paddingH(display) {
if (display.cachedPaddingH) {
return display.cachedPaddingH;
}
var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
var data = { left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight) };
if (!isNaN(data.left) && !isNaN(data.right)) {
display.cachedPaddingH = data;
}
return data;
}
function scrollGap(cm) {
return scrollerGap - cm.display.nativeBarWidth;
}
function displayWidth(cm) {
return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth;
}
function displayHeight(cm) {
return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight;
}
// Ensure the lineView.wrapping.heights array is populated. This is
// an array of bottom offsets for the lines that make up a drawn
// line. When lineWrapping is on, there might be more than one
// height.
function ensureLineHeights(cm, lineView, rect) {
var wrapping = cm.options.lineWrapping;
var curWidth = wrapping && displayWidth(cm);
if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
var heights = lineView.measure.heights = [];
if (wrapping) {
lineView.measure.width = curWidth;
var rects = lineView.text.firstChild.getClientRects();
for (var i = 0; i < rects.length - 1; i++) {
var cur = rects[i],
next = rects[i + 1];
if (Math.abs(cur.bottom - next.bottom) > 2) {
heights.push((cur.bottom + next.top) / 2 - rect.top);
}
}
}
heights.push(rect.bottom - rect.top);
}
}
// Find a line map (mapping character offsets to text nodes) and a
// measurement cache for the given line number. (A line view might
// contain multiple lines when collapsed ranges are present.)
function mapFromLineView(lineView, line, lineN) {
if (lineView.line == line) {
return { map: lineView.measure.map, cache: lineView.measure.cache };
}
for (var i = 0; i < lineView.rest.length; i++) {
if (lineView.rest[i] == line) {
return { map: lineView.measure.maps[i], cache: lineView.measure.caches[i] };
}
}
for (var i$1 = 0; i$1 < lineView.rest.length; i$1++) {
if (lineNo(lineView.rest[i$1]) > lineN) {
return { map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true };
}
}
}
// Render a line into the hidden node display.externalMeasured. Used
// when measurement is needed for a line that's not in the viewport.
function updateExternalMeasurement(cm, line) {
line = visualLine(line);
var lineN = lineNo(line);
var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
view.lineN = lineN;
var built = view.built = buildLineContent(cm, view);
view.text = built.pre;
removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
return view;
}
// Get a {top, bottom, left, right} box (in line-local coordinates)
// for a given character.
function measureChar(cm, line, ch, bias) {
return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
}
// Find a line view that corresponds to the given line number.
function findViewForLine(cm, lineN) {
if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo) {
return cm.display.view[findViewIndex(cm, lineN)];
}
var ext = cm.display.externalMeasured;
if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size) {
return ext;
}
}
// Measurement can be split in two steps, the set-up work that
// applies to the whole line, and the measurement of the actual
// character. Functions like coordsChar, that need to do a lot of
// measurements in a row, can thus ensure that the set-up work is
// only done once.
function prepareMeasureForLine(cm, line) {
var lineN = lineNo(line);
var view = findViewForLine(cm, lineN);
if (view && !view.text) {
view = null;
} else if (view && view.changes) {
updateLineForChanges(cm, view, lineN, getDimensions(cm));
cm.curOp.forceUpdate = true;
}
if (!view) {
view = updateExternalMeasurement(cm, line);
}
var info = mapFromLineView(view, line, lineN);
return {
line: line, view: view, rect: null,
map: info.map, cache: info.cache, before: info.before,
hasHeights: false
};
}
// Given a prepared measurement object, measures the position of an
// actual character (or fetches it from the cache).
function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
if (prepared.before) {
ch = -1;
}
var key = ch + (bias || ""),
found;
if (prepared.cache.hasOwnProperty(key)) {
found = prepared.cache[key];
} else {
if (!prepared.rect) {
prepared.rect = prepared.view.text.getBoundingClientRect();
}
if (!prepared.hasHeights) {
ensureLineHeights(cm, prepared.view, prepared.rect);
prepared.hasHeights = true;
}
found = measureCharInner(cm, prepared, ch, bias);
if (!found.bogus) {
prepared.cache[key] = found;
}
}
return { left: found.left, right: found.right,
top: varHeight ? found.rtop : found.top,
bottom: varHeight ? found.rbottom : found.bottom };
}
var nullRect = { left: 0, right: 0, top: 0, bottom: 0 };
function nodeAndOffsetInLineMap(map$$1, ch, bias) {
var node, start, end, collapse, mStart, mEnd;
// First, search the line map for the text node corresponding to,
// or closest to, the target character.
for (var i = 0; i < map$$1.length; i += 3) {
mStart = map$$1[i];
mEnd = map$$1[i + 1];
if (ch < mStart) {
start = 0;end = 1;
collapse = "left";
} else if (ch < mEnd) {
start = ch - mStart;
end = start + 1;
} else if (i == map$$1.length - 3 || ch == mEnd && map$$1[i + 3] > ch) {
end = mEnd - mStart;
start = end - 1;
if (ch >= mEnd) {
collapse = "right";
}
}
if (start != null) {
node = map$$1[i + 2];
if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right")) {
collapse = bias;
}
if (bias == "left" && start == 0) {
while (i && map$$1[i - 2] == map$$1[i - 3] && map$$1[i - 1].insertLeft) {
node = map$$1[(i -= 3) + 2];
collapse = "left";
}
}
if (bias == "right" && start == mEnd - mStart) {
while (i < map$$1.length - 3 && map$$1[i + 3] == map$$1[i + 4] && !map$$1[i + 5].insertLeft) {
node = map$$1[(i += 3) + 2];
collapse = "right";
}
}
break;
}
}
return { node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd };
}
function getUsefulRect(rects, bias) {
var rect = nullRect;
if (bias == "left") {
for (var i = 0; i < rects.length; i++) {
if ((rect = rects[i]).left != rect.right) {
break;
}
}
} else {
for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
if ((rect = rects[i$1]).left != rect.right) {
break;
}
}
}
return rect;
}
function measureCharInner(cm, prepared, ch, bias) {
var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
var node = place.node,
start = place.start,
end = place.end,
collapse = place.collapse;
var rect;
if (node.nodeType == 3) {
// If it is a text node, use a range to retrieve the coordinates.
for (var i$1 = 0; i$1 < 4; i$1++) {
// Retry a maximum of 4 times when nonsense rectangles are returned
while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) {
--start;
}
while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) {
++end;
}
if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) {
rect = node.parentNode.getBoundingClientRect();
} else {
rect = getUsefulRect(range(node, start, end).getClientRects(), bias);
}
if (rect.left || rect.right || start == 0) {
break;
}
end = start;
start = start - 1;
collapse = "right";
}
if (ie && ie_version < 11) {
rect = maybeUpdateRectForZooming(cm.display.measure, rect);
}
} else {
// If it is a widget, simply get the box for the whole widget.
if (start > 0) {
collapse = bias = "right";
}
var rects;
if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1) {
rect = rects[bias == "right" ? rects.length - 1 : 0];
} else {
rect = node.getBoundingClientRect();
}
}
if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
var rSpan = node.parentNode.getClientRects()[0];
if (rSpan) {
rect = { left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom };
} else {
rect = nullRect;
}
}
var rtop = rect.top - prepared.rect.top,
rbot = rect.bottom - prepared.rect.top;
var mid = (rtop + rbot) / 2;
var heights = prepared.view.measure.heights;
var i = 0;
for (; i < heights.length - 1; i++) {
if (mid < heights[i]) {
break;
}
}
var top = i ? heights[i - 1] : 0,
bot = heights[i];
var result = { left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
top: top, bottom: bot };
if (!rect.left && !rect.right) {
result.bogus = true;
}
if (!cm.options.singleCursorHeightPerLine) {
result.rtop = rtop;result.rbottom = rbot;
}
return result;
}
// Work around problem with bounding client rects on ranges being
// returned incorrectly when zoomed on IE10 and below.
function maybeUpdateRectForZooming(measure, rect) {
if (!window.screen || screen.logicalXDPI == null || screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure)) {
return rect;
}
var scaleX = screen.logicalXDPI / screen.deviceXDPI;
var scaleY = screen.logicalYDPI / screen.deviceYDPI;
return { left: rect.left * scaleX, right: rect.right * scaleX,
top: rect.top * scaleY, bottom: rect.bottom * scaleY };
}
function clearLineMeasurementCacheFor(lineView) {
if (lineView.measure) {
lineView.measure.cache = {};
lineView.measure.heights = null;
if (lineView.rest) {
for (var i = 0; i < lineView.rest.length; i++) {
lineView.measure.caches[i] = {};
}
}
}
}
function clearLineMeasurementCache(cm) {
cm.display.externalMeasure = null;
removeChildren(cm.display.lineMeasure);
for (var i = 0; i < cm.display.view.length; i++) {
clearLineMeasurementCacheFor(cm.display.view[i]);
}
}
function clearCaches(cm) {
clearLineMeasurementCache(cm);
cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
if (!cm.options.lineWrapping) {
cm.display.maxLineChanged = true;
}
cm.display.lineNumChars = null;
}
function pageScrollX() {
// Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206
// which causes page_Offset and bounding client rects to use
// different reference viewports and invalidate our calculations.
if (chrome && android) {
return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft));
}
return window.pageXOffset || (document.documentElement || document.body).scrollLeft;
}
function pageScrollY() {
if (chrome && android) {
return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop));
}
return window.pageYOffset || (document.documentElement || document.body).scrollTop;
}
function widgetTopHeight(lineObj) {
var height = 0;
if (lineObj.widgets) {
for (var i = 0; i < lineObj.widgets.length; ++i) {
if (lineObj.widgets[i].above) {
height += widgetHeight(lineObj.widgets[i]);
}
}
}
return height;
}
// Converts a {top, bottom, left, right} box from line-local
// coordinates into another coordinate system. Context may be one of
// "line", "div" (display.lineDiv), "local"./null (editor), "window",
// or "page".
function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
if (!includeWidgets) {
var height = widgetTopHeight(lineObj);
rect.top += height;rect.bottom += height;
}
if (context == "line") {
return rect;
}
if (!context) {
context = "local";
}
var yOff = heightAtLine(lineObj);
if (context == "local") {
yOff += paddingTop(cm.display);
} else {
yOff -= cm.display.viewOffset;
}
if (context == "page" || context == "window") {
var lOff = cm.display.lineSpace.getBoundingClientRect();
yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
rect.left += xOff;rect.right += xOff;
}
rect.top += yOff;rect.bottom += yOff;
return rect;
}
// Coverts a box from "div" coords to another coordinate system.
// Context may be "window", "page", "div", or "local"./null.
function fromCoordSystem(cm, coords, context) {
if (context == "div") {
return coords;
}
var left = coords.left,
top = coords.top;
// First move into "page" coordinate system
if (context == "page") {
left -= pageScrollX();
top -= pageScrollY();
} else if (context == "local" || !context) {
var localBox = cm.display.sizer.getBoundingClientRect();
left += localBox.left;
top += localBox.top;
}
var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
return { left: left - lineSpaceBox.left, top: top - lineSpaceBox.top };
}
function charCoords(cm, pos, context, lineObj, bias) {
if (!lineObj) {
lineObj = getLine(cm.doc, pos.line);
}
return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);
}
// Returns a box for a given cursor position, which may have an
// 'other' property containing the position of the secondary cursor
// on a bidi boundary.
// A cursor Pos(line, char, "before") is on the same visual line as `char - 1`
// and after `char - 1` in writing order of `char - 1`
// A cursor Pos(line, char, "after") is on the same visual line as `char`
// and before `char` in writing order of `char`
// Examples (upper-case letters are RTL, lower-case are LTR):
// Pos(0, 1, ...)
// before after
// ab a|b a|b
// aB a|B aB|
// Ab |Ab A|b
// AB B|A B|A
// Every position after the last character on a line is considered to stick
// to the last character on the line.
function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
lineObj = lineObj || getLine(cm.doc, pos.line);
if (!preparedMeasure) {
preparedMeasure = prepareMeasureForLine(cm, lineObj);
}
function get(ch, right) {
var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
if (right) {
m.left = m.right;
} else {
m.right = m.left;
}
return intoCoordSystem(cm, lineObj, m, context);
}
var order = getOrder(lineObj, cm.doc.direction),
ch = pos.ch,
sticky = pos.sticky;
if (ch >= lineObj.text.length) {
ch = lineObj.text.length;
sticky = "before";
} else if (ch <= 0) {
ch = 0;
sticky = "after";
}
if (!order) {
return get(sticky == "before" ? ch - 1 : ch, sticky == "before");
}
function getBidi(ch, partPos, invert) {
var part = order[partPos],
right = part.level == 1;
return get(invert ? ch - 1 : ch, right != invert);
}
var partPos = getBidiPartAt(order, ch, sticky);
var other = bidiOther;
var val = getBidi(ch, partPos, sticky == "before");
if (other != null) {
val.other = getBidi(ch, other, sticky != "before");
}
return val;
}
// Used to cheaply estimate the coordinates for a position. Used for
// intermediate scroll updates.
function estimateCoords(cm, pos) {
var left = 0;
pos = clipPos(cm.doc, pos);
if (!cm.options.lineWrapping) {
left = charWidth(cm.display) * pos.ch;
}
var lineObj = getLine(cm.doc, pos.line);
var top = heightAtLine(lineObj) + paddingTop(cm.display);
return { left: left, right: left, top: top, bottom: top + lineObj.height };
}
// Positions returned by coordsChar contain some extra information.
// xRel is the relative x position of the input coordinates compared
// to the found position (so xRel > 0 means the coordinates are to
// the right of the character position, for example). When outside
// is true, that means the coordinates lie outside the line's
// vertical range.
function PosWithInfo(line, ch, sticky, outside, xRel) {
var pos = Pos(line, ch, sticky);
pos.xRel = xRel;
if (outside) {
pos.outside = true;
}
return pos;
}
// Compute the character position closest to the given coordinates.
// Input must be lineSpace-local ("div" coordinate system).
function coordsChar(cm, x, y) {
var doc = cm.doc;
y += cm.display.viewOffset;
if (y < 0) {
return PosWithInfo(doc.first, 0, null, true, -1);
}
var lineN = lineAtHeight(doc, y),
last = doc.first + doc.size - 1;
if (lineN > last) {
return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, true, 1);
}
if (x < 0) {
x = 0;
}
var lineObj = getLine(doc, lineN);
for (;;) {
var found = coordsCharInner(cm, lineObj, lineN, x, y);
var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 ? 1 : 0));
if (!collapsed) {
return found;
}
var rangeEnd = collapsed.find(1);
if (rangeEnd.line == lineN) {
return rangeEnd;
}
lineObj = getLine(doc, lineN = rangeEnd.line);
}
}
function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
y -= widgetTopHeight(lineObj);
var end = lineObj.text.length;
var begin = findFirst(function (ch) {
return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y;
}, end, 0);
end = findFirst(function (ch) {
return measureCharPrepared(cm, preparedMeasure, ch).top > y;
}, begin, end);
return { begin: begin, end: end };
}
function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
if (!preparedMeasure) {
preparedMeasure = prepareMeasureForLine(cm, lineObj);
}
var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top;
return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop);
}
// Returns true if the given side of a box is after the given
// coordinates, in top-to-bottom, left-to-right order.
function boxIsAfter(box, x, y, left) {
return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x;
}
function coordsCharInner(cm, lineObj, lineNo$$1, x, y) {
// Move y into line-local coordinate space
y -= heightAtLine(lineObj);
var preparedMeasure = prepareMeasureForLine(cm, lineObj);
// When directly calling `measureCharPrepared`, we have to adjust
// for the widgets at this line.
var widgetHeight$$1 = widgetTopHeight(lineObj);
var begin = 0,
end = lineObj.text.length,
ltr = true;
var order = getOrder(lineObj, cm.doc.direction);
// If the line isn't plain left-to-right text, first figure out
// which bidi section the coordinates fall into.
if (order) {
var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)(cm, lineObj, lineNo$$1, preparedMeasure, order, x, y);
ltr = part.level != 1;
// The awkward -1 offsets are needed because findFirst (called
// on these below) will treat its first bound as inclusive,
// second as exclusive, but we want to actually address the
// characters in the part's range
begin = ltr ? part.from : part.to - 1;
end = ltr ? part.to : part.from - 1;
}
// A binary search to find the first character whose bounding box
// starts after the coordinates. If we run across any whose box wrap
// the coordinates, store that.
var chAround = null,
boxAround = null;
var ch = findFirst(function (ch) {
var box = measureCharPrepared(cm, preparedMeasure, ch);
box.top += widgetHeight$$1;box.bottom += widgetHeight$$1;
if (!boxIsAfter(box, x, y, false)) {
return false;
}
if (box.top <= y && box.left <= x) {
chAround = ch;
boxAround = box;
}
return true;
}, begin, end);
var baseX,
sticky,
outside = false;
// If a box around the coordinates was found, use that
if (boxAround) {
// Distinguish coordinates nearer to the left or right side of the box
var atLeft = x - boxAround.left < boxAround.right - x,
atStart = atLeft == ltr;
ch = chAround + (atStart ? 0 : 1);
sticky = atStart ? "after" : "before";
baseX = atLeft ? boxAround.left : boxAround.right;
} else {
// (Adjust for extended bound, if necessary.)
if (!ltr && (ch == end || ch == begin)) {
ch++;
}
// To determine which side to associate with, get the box to the
// left of the character and compare it's vertical position to the
// coordinates
sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" : measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight$$1 <= y == ltr ? "after" : "before";
// Now get accurate coordinates for this place, in order to get a
// base X position
var coords = cursorCoords(cm, Pos(lineNo$$1, ch, sticky), "line", lineObj, preparedMeasure);
baseX = coords.left;
outside = y < coords.top || y >= coords.bottom;
}
ch = skipExtendingChars(lineObj.text, ch, 1);
return PosWithInfo(lineNo$$1, ch, sticky, outside, x - baseX);
}
function coordsBidiPart(cm, lineObj, lineNo$$1, preparedMeasure, order, x, y) {
// Bidi parts are sorted left-to-right, and in a non-line-wrapping
// situation, we can take this ordering to correspond to the visual
// ordering. This finds the first part whose end is after the given
// coordinates.
var index = findFirst(function (i) {
var part = order[i],
ltr = part.level != 1;
return boxIsAfter(cursorCoords(cm, Pos(lineNo$$1, ltr ? part.to : part.from, ltr ? "before" : "after"), "line", lineObj, preparedMeasure), x, y, true);
}, 0, order.length - 1);
var part = order[index];
// If this isn't the first part, the part's start is also after
// the coordinates, and the coordinates aren't on the same line as
// that start, move one part back.
if (index > 0) {
var ltr = part.level != 1;
var start = cursorCoords(cm, Pos(lineNo$$1, ltr ? part.from : part.to, ltr ? "after" : "before"), "line", lineObj, preparedMeasure);
if (boxIsAfter(start, x, y, true) && start.top > y) {
part = order[index - 1];
}
}
return part;
}
function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
// In a wrapped line, rtl text on wrapping boundaries can do things
// that don't correspond to the ordering in our `order` array at
// all, so a binary search doesn't work, and we want to return a
// part that only spans one line so that the binary search in
// coordsCharInner is safe. As such, we first find the extent of the
// wrapped line, and then do a flat search in which we discard any
// spans that aren't on the line.
var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
var begin = ref.begin;
var end = ref.end;
if (/\s/.test(lineObj.text.charAt(end - 1))) {
end--;
}
var part = null,
closestDist = null;
for (var i = 0; i < order.length; i++) {
var p = order[i];
if (p.from >= end || p.to <= begin) {
continue;
}
var ltr = p.level != 1;
var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right;
// Weigh against spans ending before this, so that they are only
// picked if nothing ends after
var dist = endX < x ? x - endX + 1e9 : endX - x;
if (!part || closestDist > dist) {
part = p;
closestDist = dist;
}
}
if (!part) {
part = order[order.length - 1];
}
// Clip the part to the wrapped line.
if (part.from < begin) {
part = { from: begin, to: part.to, level: part.level };
}
if (part.to > end) {
part = { from: part.from, to: end, level: part.level };
}
return part;
}
var measureText;
// Compute the default text height.
function textHeight(display) {
if (display.cachedTextHeight != null) {
return display.cachedTextHeight;
}
if (measureText == null) {
measureText = elt("pre");
// Measure a bunch of lines, for browsers that compute
// fractional heights.
for (var i = 0; i < 49; ++i) {
measureText.appendChild(document.createTextNode("x"));
measureText.appendChild(elt("br"));
}
measureText.appendChild(document.createTextNode("x"));
}
removeChildrenAndAdd(display.measure, measureText);
var height = measureText.offsetHeight / 50;
if (height > 3) {
display.cachedTextHeight = height;
}
removeChildren(display.measure);
return height || 1;
}
// Compute the default character width.
function charWidth(display) {
if (display.cachedCharWidth != null) {
return display.cachedCharWidth;
}
var anchor = elt("span", "xxxxxxxxxx");
var pre = elt("pre", [anchor]);
removeChildrenAndAdd(display.measure, pre);
var rect = anchor.getBoundingClientRect(),
width = (rect.right - rect.left) / 10;
if (width > 2) {
display.cachedCharWidth = width;
}
return width || 10;
}
// Do a bulk-read of the DOM positions and sizes needed to draw the
// view, so that we don't interleave reading and writing to the DOM.
function getDimensions(cm) {
var d = cm.display,
left = {},
width = {};
var gutterLeft = d.gutters.clientLeft;
for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
width[cm.options.gutters[i]] = n.clientWidth;
}
return { fixedPos: compensateForHScroll(d),
gutterTotalWidth: d.gutters.offsetWidth,
gutterLeft: left,
gutterWidth: width,
wrapperWidth: d.wrapper.clientWidth };
}
// Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
// but using getBoundingClientRect to get a sub-pixel-accurate
// result.
function compensateForHScroll(display) {
return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
}
// Returns a function that estimates the height of a line, to use as
// first approximation until the line becomes visible (and is thus
// properly measurable).
function estimateHeight(cm) {
var th = textHeight(cm.display),
wrapping = cm.options.lineWrapping;
var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
return function (line) {
if (lineIsHidden(cm.doc, line)) {
return 0;
}
var widgetsHeight = 0;
if (line.widgets) {
for (var i = 0; i < line.widgets.length; i++) {
if (line.widgets[i].height) {
widgetsHeight += line.widgets[i].height;
}
}
}
if (wrapping) {
return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
} else {
return widgetsHeight + th;
}
};
}
function estimateLineHeights(cm) {
var doc = cm.doc,
est = estimateHeight(cm);
doc.iter(function (line) {
var estHeight = est(line);
if (estHeight != line.height) {
updateLineHeight(line, estHeight);
}
});
}
// Given a mouse event, find the corresponding position. If liberal
// is false, it checks whether a gutter or scrollbar was clicked,
// and returns null if it was. forRect is used by rectangular
// selections, and tries to estimate a character position even for
// coordinates beyond the right of the text.
function posFromMouse(cm, e, liberal, forRect) {
var display = cm.display;
if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") {
return null;
}
var x,
y,
space = display.lineSpace.getBoundingClientRect();
// Fails unpredictably on IE[67] when mouse is dragged around quickly.
try {
x = e.clientX - space.left;y = e.clientY - space.top;
} catch (e) {
return null;
}
var coords = coordsChar(cm, x, y),
line;
if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
}
return coords;
}
// Find the view element corresponding to a given line. Return null
// when the line isn't visible.
function findViewIndex(cm, n) {
if (n >= cm.display.viewTo) {
return null;
}
n -= cm.display.viewFrom;
if (n < 0) {
return null;
}
var view = cm.display.view;
for (var i = 0; i < view.length; i++) {
n -= view[i].size;
if (n < 0) {
return i;
}
}
}
function updateSelection(cm) {
cm.display.input.showSelection(cm.display.input.prepareSelection());
}
function prepareSelection(cm, primary) {
if (primary === void 0) primary = true;
var doc = cm.doc,
result = {};
var curFragment = result.cursors = document.createDocumentFragment();
var selFragment = result.selection = document.createDocumentFragment();
for (var i = 0; i < doc.sel.ranges.length; i++) {
if (!primary && i == doc.sel.primIndex) {
continue;
}
var range$$1 = doc.sel.ranges[i];
if (range$$1.from().line >= cm.display.viewTo || range$$1.to().line < cm.display.viewFrom) {
continue;
}
var collapsed = range$$1.empty();
if (collapsed || cm.options.showCursorWhenSelecting) {
drawSelectionCursor(cm, range$$1.head, curFragment);
}
if (!collapsed) {
drawSelectionRange(cm, range$$1, selFragment);
}
}
return result;
}
// Draws a cursor for the given range
function drawSelectionCursor(cm, head, output) {
var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
cursor.style.left = pos.left + "px";
cursor.style.top = pos.top + "px";
cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
if (pos.other) {
// Secondary cursor, shown when on a 'jump' in bi-directional text
var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
otherCursor.style.display = "";
otherCursor.style.left = pos.other.left + "px";
otherCursor.style.top = pos.other.top + "px";
otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
}
}
function cmpCoords(a, b) {
return a.top - b.top || a.left - b.left;
}
// Draws the given range as a highlighted selection
function drawSelectionRange(cm, range$$1, output) {
var display = cm.display,
doc = cm.doc;
var fragment = document.createDocumentFragment();
var padding = paddingH(cm.display),
leftSide = padding.left;
var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
var docLTR = doc.direction == "ltr";
function add(left, top, width, bottom) {
if (top < 0) {
top = 0;
}
top = Math.round(top);
bottom = Math.round(bottom);
fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px"));
}
function drawForLine(line, fromArg, toArg) {
var lineObj = getLine(doc, line);
var lineLen = lineObj.text.length;
var start, end;
function coords(ch, bias) {
return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
}
function wrapX(pos, dir, side) {
var extent = wrappedLineExtentChar(cm, lineObj, null, pos);
var prop = dir == "ltr" == (side == "after") ? "left" : "right";
var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);
return coords(ch, prop)[prop];
}
var order = getOrder(lineObj, doc.direction);
iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
var ltr = dir == "ltr";
var fromPos = coords(from, ltr ? "left" : "right");
var toPos = coords(to - 1, ltr ? "right" : "left");
var openStart = fromArg == null && from == 0,
openEnd = toArg == null && to == lineLen;
var first = i == 0,
last = !order || i == order.length - 1;
if (toPos.top - fromPos.top <= 3) {
// Single line
var openLeft = (docLTR ? openStart : openEnd) && first;
var openRight = (docLTR ? openEnd : openStart) && last;
var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;
var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;
add(left, fromPos.top, right - left, fromPos.bottom);
} else {
// Multiple lines
var topLeft, topRight, botLeft, botRight;
if (ltr) {
topLeft = docLTR && openStart && first ? leftSide : fromPos.left;
topRight = docLTR ? rightSide : wrapX(from, dir, "before");
botLeft = docLTR ? leftSide : wrapX(to, dir, "after");
botRight = docLTR && openEnd && last ? rightSide : toPos.right;
} else {
topLeft = !docLTR ? leftSide : wrapX(from, dir, "before");
topRight = !docLTR && openStart && first ? rightSide : fromPos.right;
botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;
botRight = !docLTR ? rightSide : wrapX(to, dir, "after");
}
add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);
if (fromPos.bottom < toPos.top) {
add(leftSide, fromPos.bottom, null, toPos.top);
}
add(botLeft, toPos.top, botRight - botLeft, toPos.bottom);
}
if (!start || cmpCoords(fromPos, start) < 0) {
start = fromPos;
}
if (cmpCoords(toPos, start) < 0) {
start = toPos;
}
if (!end || cmpCoords(fromPos, end) < 0) {
end = fromPos;
}
if (cmpCoords(toPos, end) < 0) {
end = toPos;
}
});
return { start: start, end: end };
}
var sFrom = range$$1.from(),
sTo = range$$1.to();
if (sFrom.line == sTo.line) {
drawForLine(sFrom.line, sFrom.ch, sTo.ch);
} else {
var fromLine = getLine(doc, sFrom.line),
toLine = getLine(doc, sTo.line);
var singleVLine = visualLine(fromLine) == visualLine(toLine);
var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
if (singleVLine) {
if (leftEnd.top < rightStart.top - 2) {
add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
} else {
add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
}
}
if (leftEnd.bottom < rightStart.top) {
add(leftSide, leftEnd.bottom, null, rightStart.top);
}
}
output.appendChild(fragment);
}
// Cursor-blinking
function restartBlink(cm) {
if (!cm.state.focused) {
return;
}
var display = cm.display;
clearInterval(display.blinker);
var on = true;
display.cursorDiv.style.visibility = "";
if (cm.options.cursorBlinkRate > 0) {
display.blinker = setInterval(function () {
return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden";
}, cm.options.cursorBlinkRate);
} else if (cm.options.cursorBlinkRate < 0) {
display.cursorDiv.style.visibility = "hidden";
}
}
function ensureFocus(cm) {
if (!cm.state.focused) {
cm.display.input.focus();onFocus(cm);
}
}
function delayBlurEvent(cm) {
cm.state.delayingBlurEvent = true;
setTimeout(function () {
if (cm.state.delayingBlurEvent) {
cm.state.delayingBlurEvent = false;
onBlur(cm);
}
}, 100);
}
function onFocus(cm, e) {
if (cm.state.delayingBlurEvent) {
cm.state.delayingBlurEvent = false;
}
if (cm.options.readOnly == "nocursor") {
return;
}
if (!cm.state.focused) {
signal(cm, "focus", cm, e);
cm.state.focused = true;
addClass(cm.display.wrapper, "CodeMirror-focused");
// This test prevents this from firing when a context
// menu is closed (since the input reset would kill the
// select-all detection hack)
if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
cm.display.input.reset();
if (webkit) {
setTimeout(function () {
return cm.display.input.reset(true);
}, 20);
} // Issue #1730
}
cm.display.input.receivedFocus();
}
restartBlink(cm);
}
function onBlur(cm, e) {
if (cm.state.delayingBlurEvent) {
return;
}
if (cm.state.focused) {
signal(cm, "blur", cm, e);
cm.state.focused = false;
rmClass(cm.display.wrapper, "CodeMirror-focused");
}
clearInterval(cm.display.blinker);
setTimeout(function () {
if (!cm.state.focused) {
cm.display.shift = false;
}
}, 150);
}
// Read the actual heights of the rendered lines, and update their
// stored heights to match.
function updateHeightsInViewport(cm) {
var display = cm.display;
var prevBottom = display.lineDiv.offsetTop;
for (var i = 0; i < display.view.length; i++) {
var cur = display.view[i],
height = void 0;
if (cur.hidden) {
continue;
}
if (ie && ie_version < 8) {
var bot = cur.node.offsetTop + cur.node.offsetHeight;
height = bot - prevBottom;
prevBottom = bot;
} else {
var box = cur.node.getBoundingClientRect();
height = box.bottom - box.top;
}
var diff = cur.line.height - height;
if (height < 2) {
height = textHeight(display);
}
if (diff > .005 || diff < -.005) {
updateLineHeight(cur.line, height);
updateWidgetHeight(cur.line);
if (cur.rest) {
for (var j = 0; j < cur.rest.length; j++) {
updateWidgetHeight(cur.rest[j]);
}
}
}
}
}
// Read and store the height of line widgets associated with the
// given line.
function updateWidgetHeight(line) {
if (line.widgets) {
for (var i = 0; i < line.widgets.length; ++i) {
var w = line.widgets[i],
parent = w.node.parentNode;
if (parent) {
w.height = parent.offsetHeight;
}
}
}
}
// Compute the lines that are visible in a given viewport (defaults
// the the current scroll position). viewport may contain top,
// height, and ensure (see op.scrollToPos) properties.
function visibleLines(display, doc, viewport) {
var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
top = Math.floor(top - paddingTop(display));
var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
var from = lineAtHeight(doc, top),
to = lineAtHeight(doc, bottom);
// Ensure is a {from: {line, ch}, to: {line, ch}} object, and
// forces those lines into the viewport (if possible).
if (viewport && viewport.ensure) {
var ensureFrom = viewport.ensure.from.line,
ensureTo = viewport.ensure.to.line;
if (ensureFrom < from) {
from = ensureFrom;
to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
} else if (Math.min(ensureTo, doc.lastLine()) >= to) {
from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
to = ensureTo;
}
}
return { from: from, to: Math.max(to, from + 1) };
}
// Re-align line numbers and gutter marks to compensate for
// horizontal scrolling.
function alignHorizontally(cm) {
var display = cm.display,
view = display.view;
if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) {
return;
}
var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
var gutterW = display.gutters.offsetWidth,
left = comp + "px";
for (var i = 0; i < view.length; i++) {
if (!view[i].hidden) {
if (cm.options.fixedGutter) {
if (view[i].gutter) {
view[i].gutter.style.left = left;
}
if (view[i].gutterBackground) {
view[i].gutterBackground.style.left = left;
}
}
var align = view[i].alignable;
if (align) {
for (var j = 0; j < align.length; j++) {
align[j].style.left = left;
}
}
}
}
if (cm.options.fixedGutter) {
display.gutters.style.left = comp + gutterW + "px";
}
}
// Used to ensure that the line number gutter is still the right
// size for the current document size. Returns true when an update
// is needed.
function maybeUpdateLineNumberWidth(cm) {
if (!cm.options.lineNumbers) {
return false;
}
var doc = cm.doc,
last = lineNumberFor(cm.options, doc.first + doc.size - 1),
display = cm.display;
if (last.length != display.lineNumChars) {
var test = display.measure.appendChild(elt("div", [elt("div", last)], "CodeMirror-linenumber CodeMirror-gutter-elt"));
var innerW = test.firstChild.offsetWidth,
padding = test.offsetWidth - innerW;
display.lineGutter.style.width = "";
display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
display.lineNumWidth = display.lineNumInnerWidth + padding;
display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
display.lineGutter.style.width = display.lineNumWidth + "px";
updateGutterSpace(cm);
return true;
}
return false;
}
// SCROLLING THINGS INTO VIEW
// If an editor sits on the top or bottom of the window, partially
// scrolled out of view, this ensures that the cursor is visible.
function maybeScrollWindow(cm, rect) {
if (signalDOMEvent(cm, "scrollCursorIntoView")) {
return;
}
var display = cm.display,
box = display.sizer.getBoundingClientRect(),
doScroll = null;
if (rect.top + box.top < 0) {
doScroll = true;
} else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) {
doScroll = false;
}
if (doScroll != null && !phantom) {
var scrollNode = elt("div", "\u200b", null, "position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + rect.left + "px; width: " + Math.max(2, rect.right - rect.left) + "px;");
cm.display.lineSpace.appendChild(scrollNode);
scrollNode.scrollIntoView(doScroll);
cm.display.lineSpace.removeChild(scrollNode);
}
}
// Scroll a given position into view (immediately), verifying that
// it actually became visible (as line heights are accurately
// measured, the position of something may 'drift' during drawing).
function scrollPosIntoView(cm, pos, end, margin) {
if (margin == null) {
margin = 0;
}
var rect;
if (!cm.options.lineWrapping && pos == end) {
// Set pos and end to the cursor positions around the character pos sticks to
// If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
// If pos == Pos(_, 0, "before"), pos and end are unchanged
pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos;
end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos;
}
for (var limit = 0; limit < 5; limit++) {
var changed = false;
var coords = cursorCoords(cm, pos);
var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
rect = { left: Math.min(coords.left, endCoords.left),
top: Math.min(coords.top, endCoords.top) - margin,
right: Math.max(coords.left, endCoords.left),
bottom: Math.max(coords.bottom, endCoords.bottom) + margin };
var scrollPos = calculateScrollPos(cm, rect);
var startTop = cm.doc.scrollTop,
startLeft = cm.doc.scrollLeft;
if (scrollPos.scrollTop != null) {
updateScrollTop(cm, scrollPos.scrollTop);
if (Math.abs(cm.doc.scrollTop - startTop) > 1) {
changed = true;
}
}
if (scrollPos.scrollLeft != null) {
setScrollLeft(cm, scrollPos.scrollLeft);
if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) {
changed = true;
}
}
if (!changed) {
break;
}
}
return rect;
}
// Scroll a given set of coordinates into view (immediately).
function scrollIntoView(cm, rect) {
var scrollPos = calculateScrollPos(cm, rect);
if (scrollPos.scrollTop != null) {
updateScrollTop(cm, scrollPos.scrollTop);
}
if (scrollPos.scrollLeft != null) {
setScrollLeft(cm, scrollPos.scrollLeft);
}
}
// Calculate a new scroll position needed to scroll the given
// rectangle into view. Returns an object with scrollTop and
// scrollLeft properties. When these are undefined, the
// vertical/horizontal position does not need to be adjusted.
function calculateScrollPos(cm, rect) {
var display = cm.display,
snapMargin = textHeight(cm.display);
if (rect.top < 0) {
rect.top = 0;
}
var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
var screen = displayHeight(cm),
result = {};
if (rect.bottom - rect.top > screen) {
rect.bottom = rect.top + screen;
}
var docBottom = cm.doc.height + paddingVert(display);
var atTop = rect.top < snapMargin,
atBottom = rect.bottom > docBottom - snapMargin;
if (rect.top < screentop) {
result.scrollTop = atTop ? 0 : rect.top;
} else if (rect.bottom > screentop + screen) {
var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen);
if (newTop != screentop) {
result.scrollTop = newTop;
}
}
var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
var tooWide = rect.right - rect.left > screenw;
if (tooWide) {
rect.right = rect.left + screenw;
}
if (rect.left < 10) {
result.scrollLeft = 0;
} else if (rect.left < screenleft) {
result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10));
} else if (rect.right > screenw + screenleft - 3) {
result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw;
}
return result;
}
// Store a relative adjustment to the scroll position in the current
// operation (to be applied when the operation finishes).
function addToScrollTop(cm, top) {
if (top == null) {
return;
}
resolveScrollToPos(cm);
cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
}
// Make sure that at the end of the operation the current cursor is
// shown.
function ensureCursorVisible(cm) {
resolveScrollToPos(cm);
var cur = cm.getCursor();
cm.curOp.scrollToPos = { from: cur, to: cur, margin: cm.options.cursorScrollMargin };
}
function scrollToCoords(cm, x, y) {
if (x != null || y != null) {
resolveScrollToPos(cm);
}
if (x != null) {
cm.curOp.scrollLeft = x;
}
if (y != null) {
cm.curOp.scrollTop = y;
}
}
function scrollToRange(cm, range$$1) {
resolveScrollToPos(cm);
cm.curOp.scrollToPos = range$$1;
}
// When an operation has its scrollToPos property set, and another
// scroll action is applied before the end of the operation, this
// 'simulates' scrolling that position into view in a cheap way, so
// that the effect of intermediate scroll commands is not ignored.
function resolveScrollToPos(cm) {
var range$$1 = cm.curOp.scrollToPos;
if (range$$1) {
cm.curOp.scrollToPos = null;
var from = estimateCoords(cm, range$$1.from),
to = estimateCoords(cm, range$$1.to);
scrollToCoordsRange(cm, from, to, range$$1.margin);
}
}
function scrollToCoordsRange(cm, from, to, margin) {
var sPos = calculateScrollPos(cm, {
left: Math.min(from.left, to.left),
top: Math.min(from.top, to.top) - margin,
right: Math.max(from.right, to.right),
bottom: Math.max(from.bottom, to.bottom) + margin
});
scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop);
}
// Sync the scrollable area and scrollbars, ensure the viewport
// covers the visible area.
function updateScrollTop(cm, val) {
if (Math.abs(cm.doc.scrollTop - val) < 2) {
return;
}
if (!gecko) {
updateDisplaySimple(cm, { top: val });
}
setScrollTop(cm, val, true);
if (gecko) {
updateDisplaySimple(cm);
}
startWorker(cm, 100);
}
function setScrollTop(cm, val, forceScroll) {
val = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val);
if (cm.display.scroller.scrollTop == val && !forceScroll) {
return;
}
cm.doc.scrollTop = val;
cm.display.scrollbars.setScrollTop(val);
if (cm.display.scroller.scrollTop != val) {
cm.display.scroller.scrollTop = val;
}
}
// Sync scroller and scrollbar, ensure the gutter elements are
// aligned.
function setScrollLeft(cm, val, isScroller, forceScroll) {
val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) {
return;
}
cm.doc.scrollLeft = val;
alignHorizontally(cm);
if (cm.display.scroller.scrollLeft != val) {
cm.display.scroller.scrollLeft = val;
}
cm.display.scrollbars.setScrollLeft(val);
}
// SCROLLBARS
// Prepare DOM reads needed to update the scrollbars. Done in one
// shot to minimize update/measure roundtrips.
function measureForScrollbars(cm) {
var d = cm.display,
gutterW = d.gutters.offsetWidth;
var docH = Math.round(cm.doc.height + paddingVert(cm.display));
return {
clientHeight: d.scroller.clientHeight,
viewHeight: d.wrapper.clientHeight,
scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
viewWidth: d.wrapper.clientWidth,
barLeft: cm.options.fixedGutter ? gutterW : 0,
docHeight: docH,
scrollHeight: docH + scrollGap(cm) + d.barHeight,
nativeBarWidth: d.nativeBarWidth,
gutterWidth: gutterW
};
}
var NativeScrollbars = function (place, scroll, cm) {
this.cm = cm;
var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
vert.tabIndex = horiz.tabIndex = -1;
place(vert);place(horiz);
on(vert, "scroll", function () {
if (vert.clientHeight) {
scroll(vert.scrollTop, "vertical");
}
});
on(horiz, "scroll", function () {
if (horiz.clientWidth) {
scroll(horiz.scrollLeft, "horizontal");
}
});
this.checkedZeroWidth = false;
// Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
if (ie && ie_version < 8) {
this.horiz.style.minHeight = this.vert.style.minWidth = "18px";
}
};
NativeScrollbars.prototype.update = function (measure) {
var needsH = measure.scrollWidth > measure.clientWidth + 1;
var needsV = measure.scrollHeight > measure.clientHeight + 1;
var sWidth = measure.nativeBarWidth;
if (needsV) {
this.vert.style.display = "block";
this.vert.style.bottom = needsH ? sWidth + "px" : "0";
var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
// A bug in IE8 can cause this value to be negative, so guard it.
this.vert.firstChild.style.height = Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
} else {
this.vert.style.display = "";
this.vert.firstChild.style.height = "0";
}
if (needsH) {
this.horiz.style.display = "block";
this.horiz.style.right = needsV ? sWidth + "px" : "0";
this.horiz.style.left = measure.barLeft + "px";
var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
this.horiz.firstChild.style.width = Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
} else {
this.horiz.style.display = "";
this.horiz.firstChild.style.width = "0";
}
if (!this.checkedZeroWidth && measure.clientHeight > 0) {
if (sWidth == 0) {
this.zeroWidthHack();
}
this.checkedZeroWidth = true;
}
return { right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0 };
};
NativeScrollbars.prototype.setScrollLeft = function (pos) {
if (this.horiz.scrollLeft != pos) {
this.horiz.scrollLeft = pos;
}
if (this.disableHoriz) {
this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz");
}
};
NativeScrollbars.prototype.setScrollTop = function (pos) {
if (this.vert.scrollTop != pos) {
this.vert.scrollTop = pos;
}
if (this.disableVert) {
this.enableZeroWidthBar(this.vert, this.disableVert, "vert");
}
};
NativeScrollbars.prototype.zeroWidthHack = function () {
var w = mac && !mac_geMountainLion ? "12px" : "18px";
this.horiz.style.height = this.vert.style.width = w;
this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
this.disableHoriz = new Delayed();
this.disableVert = new Delayed();
};
NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {
bar.style.pointerEvents = "auto";
function maybeDisable() {
// To find out whether the scrollbar is still visible, we
// check whether the element under the pixel in the bottom
// right corner of the scrollbar box is the scrollbar box
// itself (when the bar is still visible) or its filler child
// (when the bar is hidden). If it is still visible, we keep
// it enabled, if it's hidden, we disable pointer events.
var box = bar.getBoundingClientRect();
var elt$$1 = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2) : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1);
if (elt$$1 != bar) {
bar.style.pointerEvents = "none";
} else {
delay.set(1000, maybeDisable);
}
}
delay.set(1000, maybeDisable);
};
NativeScrollbars.prototype.clear = function () {
var parent = this.horiz.parentNode;
parent.removeChild(this.horiz);
parent.removeChild(this.vert);
};
var NullScrollbars = function () {};
NullScrollbars.prototype.update = function () {
return { bottom: 0, right: 0 };
};
NullScrollbars.prototype.setScrollLeft = function () {};
NullScrollbars.prototype.setScrollTop = function () {};
NullScrollbars.prototype.clear = function () {};
function updateScrollbars(cm, measure) {
if (!measure) {
measure = measureForScrollbars(cm);
}
var startWidth = cm.display.barWidth,
startHeight = cm.display.barHeight;
updateScrollbarsInner(cm, measure);
for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
if (startWidth != cm.display.barWidth && cm.options.lineWrapping) {
updateHeightsInViewport(cm);
}
updateScrollbarsInner(cm, measureForScrollbars(cm));
startWidth = cm.display.barWidth;startHeight = cm.display.barHeight;
}
}
// Re-synchronize the fake scrollbars with the actual size of the
// content.
function updateScrollbarsInner(cm, measure) {
var d = cm.display;
var sizes = d.scrollbars.update(measure);
d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent";
if (sizes.right && sizes.bottom) {
d.scrollbarFiller.style.display = "block";
d.scrollbarFiller.style.height = sizes.bottom + "px";
d.scrollbarFiller.style.width = sizes.right + "px";
} else {
d.scrollbarFiller.style.display = "";
}
if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
d.gutterFiller.style.display = "block";
d.gutterFiller.style.height = sizes.bottom + "px";
d.gutterFiller.style.width = measure.gutterWidth + "px";
} else {
d.gutterFiller.style.display = "";
}
}
var scrollbarModel = { "native": NativeScrollbars, "null": NullScrollbars };
function initScrollbars(cm) {
if (cm.display.scrollbars) {
cm.display.scrollbars.clear();
if (cm.display.scrollbars.addClass) {
rmClass(cm.display.wrapper, cm.display.scrollbars.addClass);
}
}
cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
// Prevent clicks in the scrollbars from killing focus
on(node, "mousedown", function () {
if (cm.state.focused) {
setTimeout(function () {
return cm.display.input.focus();
}, 0);
}
});
node.setAttribute("cm-not-content", "true");
}, function (pos, axis) {
if (axis == "horizontal") {
setScrollLeft(cm, pos);
} else {
updateScrollTop(cm, pos);
}
}, cm);
if (cm.display.scrollbars.addClass) {
addClass(cm.display.wrapper, cm.display.scrollbars.addClass);
}
}
// Operations are used to wrap a series of changes to the editor
// state in such a way that each change won't have to update the
// cursor and display (which would be awkward, slow, and
// error-prone). Instead, display updates are batched and then all
// combined and executed at once.
var nextOpId = 0;
// Start a new operation.
function startOperation(cm) {
cm.curOp = {
cm: cm,
viewChanged: false, // Flag that indicates that lines might need to be redrawn
startHeight: cm.doc.height, // Used to detect need to update scrollbar
forceUpdate: false, // Used to force a redraw
updateInput: null, // Whether to reset the input textarea
typing: false, // Whether this reset should be careful to leave existing text (for compositing)
changeObjs: null, // Accumulated changes, for firing change events
cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
selectionChanged: false, // Whether the selection needs to be redrawn
updateMaxLine: false, // Set when the widest line needs to be determined anew
scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
scrollToPos: null, // Used to scroll to a specific position
focus: false,
id: ++nextOpId // Unique ID
};
pushOperation(cm.curOp);
}
// Finish an operation, updating the display and signalling delayed events
function endOperation(cm) {
var op = cm.curOp;
finishOperation(op, function (group) {
for (var i = 0; i < group.ops.length; i++) {
group.ops[i].cm.curOp = null;
}
endOperations(group);
});
}
// The DOM updates done when an operation finishes are batched so
// that the minimum number of relayouts are required.
function endOperations(group) {
var ops = group.ops;
for (var i = 0; i < ops.length; i++) // Read DOM
{
endOperation_R1(ops[i]);
}
for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
{
endOperation_W1(ops[i$1]);
}
for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
{
endOperation_R2(ops[i$2]);
}
for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
{
endOperation_W2(ops[i$3]);
}
for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
{
endOperation_finish(ops[i$4]);
}
}
function endOperation_R1(op) {
var cm = op.cm,
display = cm.display;
maybeClipScrollbars(cm);
if (op.updateMaxLine) {
findMaxLine(cm);
}
op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null || op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom || op.scrollToPos.to.line >= display.viewTo) || display.maxLineChanged && cm.options.lineWrapping;
op.update = op.mustUpdate && new DisplayUpdate(cm, op.mustUpdate && { top: op.scrollTop, ensure: op.scrollToPos }, op.forceUpdate);
}
function endOperation_W1(op) {
op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
}
function endOperation_R2(op) {
var cm = op.cm,
display = cm.display;
if (op.updatedDisplay) {
updateHeightsInViewport(cm);
}
op.barMeasure = measureForScrollbars(cm);
// If the max line changed since it was last measured, measure it,
// and ensure the document's width matches it.
// updateDisplay_W2 will use these properties to do the actual resizing
if (display.maxLineChanged && !cm.options.lineWrapping) {
op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
cm.display.sizerWidth = op.adjustWidthTo;
op.barMeasure.scrollWidth = Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
}
if (op.updatedDisplay || op.selectionChanged) {
op.preparedSelection = display.input.prepareSelection();
}
}
function endOperation_W2(op) {
var cm = op.cm;
if (op.adjustWidthTo != null) {
cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
if (op.maxScrollLeft < cm.doc.scrollLeft) {
setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);
}
cm.display.maxLineChanged = false;
}
var takeFocus = op.focus && op.focus == activeElt();
if (op.preparedSelection) {
cm.display.input.showSelection(op.preparedSelection, takeFocus);
}
if (op.updatedDisplay || op.startHeight != cm.doc.height) {
updateScrollbars(cm, op.barMeasure);
}
if (op.updatedDisplay) {
setDocumentHeight(cm, op.barMeasure);
}
if (op.selectionChanged) {
restartBlink(cm);
}
if (cm.state.focused && op.updateInput) {
cm.display.input.reset(op.typing);
}
if (takeFocus) {
ensureFocus(op.cm);
}
}
function endOperation_finish(op) {
var cm = op.cm,
display = cm.display,
doc = cm.doc;
if (op.updatedDisplay) {
postUpdateDisplay(cm, op.update);
}
// Abort mouse wheel delta measurement, when scrolling explicitly
if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos)) {
display.wheelStartX = display.wheelStartY = null;
}
// Propagate the scroll position to the actual DOM scroller
if (op.scrollTop != null) {
setScrollTop(cm, op.scrollTop, op.forceScroll);
}
if (op.scrollLeft != null) {
setScrollLeft(cm, op.scrollLeft, true, true);
}
// If we need to scroll a specific position into view, do so.
if (op.scrollToPos) {
var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from), clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
maybeScrollWindow(cm, rect);
}
// Fire events for markers that are hidden/unidden by editing or
// undoing
var hidden = op.maybeHiddenMarkers,
unhidden = op.maybeUnhiddenMarkers;
if (hidden) {
for (var i = 0; i < hidden.length; ++i) {
if (!hidden[i].lines.length) {
signal(hidden[i], "hide");
}
}
}
if (unhidden) {
for (var i$1 = 0; i$1 < unhidden.length; ++i$1) {
if (unhidden[i$1].lines.length) {
signal(unhidden[i$1], "unhide");
}
}
}
if (display.wrapper.offsetHeight) {
doc.scrollTop = cm.display.scroller.scrollTop;
}
// Fire change events, and delayed event handlers
if (op.changeObjs) {
signal(cm, "changes", cm, op.changeObjs);
}
if (op.update) {
op.update.finish();
}
}
// Run the given function in an operation
function runInOp(cm, f) {
if (cm.curOp) {
return f();
}
startOperation(cm);
try {
return f();
} finally {
endOperation(cm);
}
}
// Wraps a function in an operation. Returns the wrapped function.
function operation(cm, f) {
return function () {
if (cm.curOp) {
return f.apply(cm, arguments);
}
startOperation(cm);
try {
return f.apply(cm, arguments);
} finally {
endOperation(cm);
}
};
}
// Used to add methods to editor and doc instances, wrapping them in
// operations.
function methodOp(f) {
return function () {
if (this.curOp) {
return f.apply(this, arguments);
}
startOperation(this);
try {
return f.apply(this, arguments);
} finally {
endOperation(this);
}
};
}
function docMethodOp(f) {
return function () {
var cm = this.cm;
if (!cm || cm.curOp) {
return f.apply(this, arguments);
}
startOperation(cm);
try {
return f.apply(this, arguments);
} finally {
endOperation(cm);
}
};
}
// Updates the display.view data structure for a given change to the
// document. From and to are in pre-change coordinates. Lendiff is
// the amount of lines added or subtracted by the change. This is
// used for changes that span multiple lines, or change the way
// lines are divided into visual lines. regLineChange (below)
// registers single-line changes.
function regChange(cm, from, to, lendiff) {
if (from == null) {
from = cm.doc.first;
}
if (to == null) {
to = cm.doc.first + cm.doc.size;
}
if (!lendiff) {
lendiff = 0;
}
var display = cm.display;
if (lendiff && to < display.viewTo && (display.updateLineNumbers == null || display.updateLineNumbers > from)) {
display.updateLineNumbers = from;
}
cm.curOp.viewChanged = true;
if (from >= display.viewTo) {
// Change after
if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo) {
resetView(cm);
}
} else if (to <= display.viewFrom) {
// Change before
if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
resetView(cm);
} else {
display.viewFrom += lendiff;
display.viewTo += lendiff;
}
} else if (from <= display.viewFrom && to >= display.viewTo) {
// Full overlap
resetView(cm);
} else if (from <= display.viewFrom) {
// Top overlap
var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
if (cut) {
display.view = display.view.slice(cut.index);
display.viewFrom = cut.lineN;
display.viewTo += lendiff;
} else {
resetView(cm);
}
} else if (to >= display.viewTo) {
// Bottom overlap
var cut$1 = viewCuttingPoint(cm, from, from, -1);
if (cut$1) {
display.view = display.view.slice(0, cut$1.index);
display.viewTo = cut$1.lineN;
} else {
resetView(cm);
}
} else {
// Gap in the middle
var cutTop = viewCuttingPoint(cm, from, from, -1);
var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
if (cutTop && cutBot) {
display.view = display.view.slice(0, cutTop.index).concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN)).concat(display.view.slice(cutBot.index));
display.viewTo += lendiff;
} else {
resetView(cm);
}
}
var ext = display.externalMeasured;
if (ext) {
if (to < ext.lineN) {
ext.lineN += lendiff;
} else if (from < ext.lineN + ext.size) {
display.externalMeasured = null;
}
}
}
// Register a change to a single line. Type must be one of "text",
// "gutter", "class", "widget"
function regLineChange(cm, line, type) {
cm.curOp.viewChanged = true;
var display = cm.display,
ext = cm.display.externalMeasured;
if (ext && line >= ext.lineN && line < ext.lineN + ext.size) {
display.externalMeasured = null;
}
if (line < display.viewFrom || line >= display.viewTo) {
return;
}
var lineView = display.view[findViewIndex(cm, line)];
if (lineView.node == null) {
return;
}
var arr = lineView.changes || (lineView.changes = []);
if (indexOf(arr, type) == -1) {
arr.push(type);
}
}
// Clear the view.
function resetView(cm) {
cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
cm.display.view = [];
cm.display.viewOffset = 0;
}
function viewCuttingPoint(cm, oldN, newN, dir) {
var index = findViewIndex(cm, oldN),
diff,
view = cm.display.view;
if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size) {
return { index: index, lineN: newN };
}
var n = cm.display.viewFrom;
for (var i = 0; i < index; i++) {
n += view[i].size;
}
if (n != oldN) {
if (dir > 0) {
if (index == view.length - 1) {
return null;
}
diff = n + view[index].size - oldN;
index++;
} else {
diff = n - oldN;
}
oldN += diff;newN += diff;
}
while (visualLineNo(cm.doc, newN) != newN) {
if (index == (dir < 0 ? 0 : view.length - 1)) {
return null;
}
newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
index += dir;
}
return { index: index, lineN: newN };
}
// Force the view to cover a given range, adding empty view element
// or clipping off existing ones as needed.
function adjustView(cm, from, to) {
var display = cm.display,
view = display.view;
if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
display.view = buildViewArray(cm, from, to);
display.viewFrom = from;
} else {
if (display.viewFrom > from) {
display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);
} else if (display.viewFrom < from) {
display.view = display.view.slice(findViewIndex(cm, from));
}
display.viewFrom = from;
if (display.viewTo < to) {
display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));
} else if (display.viewTo > to) {
display.view = display.view.slice(0, findViewIndex(cm, to));
}
}
display.viewTo = to;
}
// Count the number of lines in the view whose DOM representation is
// out of date (or nonexistent).
function countDirtyView(cm) {
var view = cm.display.view,
dirty = 0;
for (var i = 0; i < view.length; i++) {
var lineView = view[i];
if (!lineView.hidden && (!lineView.node || lineView.changes)) {
++dirty;
}
}
return dirty;
}
// HIGHLIGHT WORKER
function startWorker(cm, time) {
if (cm.doc.highlightFrontier < cm.display.viewTo) {
cm.state.highlight.set(time, bind(highlightWorker, cm));
}
}
function highlightWorker(cm) {
var doc = cm.doc;
if (doc.highlightFrontier >= cm.display.viewTo) {
return;
}
var end = +new Date() + cm.options.workTime;
var context = getContextBefore(cm, doc.highlightFrontier);
var changedLines = [];
doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
if (context.line >= cm.display.viewFrom) {
// Visible
var oldStyles = line.styles;
var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null;
var highlighted = highlightLine(cm, line, context, true);
if (resetState) {
context.state = resetState;
}
line.styles = highlighted.styles;
var oldCls = line.styleClasses,
newCls = highlighted.classes;
if (newCls) {
line.styleClasses = newCls;
} else if (oldCls) {
line.styleClasses = null;
}
var ischange = !oldStyles || oldStyles.length != line.styles.length || oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
for (var i = 0; !ischange && i < oldStyles.length; ++i) {
ischange = oldStyles[i] != line.styles[i];
}
if (ischange) {
changedLines.push(context.line);
}
line.stateAfter = context.save();
context.nextLine();
} else {
if (line.text.length <= cm.options.maxHighlightLength) {
processLine(cm, line.text, context);
}
line.stateAfter = context.line % 5 == 0 ? context.save() : null;
context.nextLine();
}
if (+new Date() > end) {
startWorker(cm, cm.options.workDelay);
return true;
}
});
doc.highlightFrontier = context.line;
doc.modeFrontier = Math.max(doc.modeFrontier, context.line);
if (changedLines.length) {
runInOp(cm, function () {
for (var i = 0; i < changedLines.length; i++) {
regLineChange(cm, changedLines[i], "text");
}
});
}
}
// DISPLAY DRAWING
var DisplayUpdate = function (cm, viewport, force) {
var display = cm.display;
this.viewport = viewport;
// Store some values that we'll need later (but don't want to force a relayout for)
this.visible = visibleLines(display, cm.doc, viewport);
this.editorIsHidden = !display.wrapper.offsetWidth;
this.wrapperHeight = display.wrapper.clientHeight;
this.wrapperWidth = display.wrapper.clientWidth;
this.oldDisplayWidth = displayWidth(cm);
this.force = force;
this.dims = getDimensions(cm);
this.events = [];
};
DisplayUpdate.prototype.signal = function (emitter, type) {
if (hasHandler(emitter, type)) {
this.events.push(arguments);
}
};
DisplayUpdate.prototype.finish = function () {
var this$1 = this;
for (var i = 0; i < this.events.length; i++) {
signal.apply(null, this$1.events[i]);
}
};
function maybeClipScrollbars(cm) {
var display = cm.display;
if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
display.heightForcer.style.height = scrollGap(cm) + "px";
display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
display.scrollbarsClipped = true;
}
}
function selectionSnapshot(cm) {
if (cm.hasFocus()) {
return null;
}
var active = activeElt();
if (!active || !contains(cm.display.lineDiv, active)) {
return null;
}
var result = { activeElt: active };
if (window.getSelection) {
var sel = window.getSelection();
if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
result.anchorNode = sel.anchorNode;
result.anchorOffset = sel.anchorOffset;
result.focusNode = sel.focusNode;
result.focusOffset = sel.focusOffset;
}
}
return result;
}
function restoreSelection(snapshot) {
if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) {
return;
}
snapshot.activeElt.focus();
if (snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
var sel = window.getSelection(),
range$$1 = document.createRange();
range$$1.setEnd(snapshot.anchorNode, snapshot.anchorOffset);
range$$1.collapse(false);
sel.removeAllRanges();
sel.addRange(range$$1);
sel.extend(snapshot.focusNode, snapshot.focusOffset);
}
}
// Does the actual updating of the line display. Bails out
// (returning false) when there is nothing to be done and forced is
// false.
function updateDisplayIfNeeded(cm, update) {
var display = cm.display,
doc = cm.doc;
if (update.editorIsHidden) {
resetView(cm);
return false;
}
// Bail out if the visible area is already rendered and nothing changed.
if (!update.force && update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) && display.renderedView == display.view && countDirtyView(cm) == 0) {
return false;
}
if (maybeUpdateLineNumberWidth(cm)) {
resetView(cm);
update.dims = getDimensions(cm);
}
// Compute a suitable new viewport (from & to)
var end = doc.first + doc.size;
var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
if (display.viewFrom < from && from - display.viewFrom < 20) {
from = Math.max(doc.first, display.viewFrom);
}
if (display.viewTo > to && display.viewTo - to < 20) {
to = Math.min(end, display.viewTo);
}
if (sawCollapsedSpans) {
from = visualLineNo(cm.doc, from);
to = visualLineEndNo(cm.doc, to);
}
var different = from != display.viewFrom || to != display.viewTo || display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
adjustView(cm, from, to);
display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
// Position the mover div to align with the current scroll position
cm.display.mover.style.top = display.viewOffset + "px";
var toUpdate = countDirtyView(cm);
if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view && (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo)) {
return false;
}
// For big changes, we hide the enclosing element during the
// update, since that speeds up the operations on most browsers.
var selSnapshot = selectionSnapshot(cm);
if (toUpdate > 4) {
display.lineDiv.style.display = "none";
}
patchDisplay(cm, display.updateLineNumbers, update.dims);
if (toUpdate > 4) {
display.lineDiv.style.display = "";
}
display.renderedView = display.view;
// There might have been a widget with a focused element that got
// hidden or updated, if so re-focus it.
restoreSelection(selSnapshot);
// Prevent selection and cursors from interfering with the scroll
// width and height.
removeChildren(display.cursorDiv);
removeChildren(display.selectionDiv);
display.gutters.style.height = display.sizer.style.minHeight = 0;
if (different) {
display.lastWrapHeight = update.wrapperHeight;
display.lastWrapWidth = update.wrapperWidth;
startWorker(cm, 400);
}
display.updateLineNumbers = null;
return true;
}
function postUpdateDisplay(cm, update) {
var viewport = update.viewport;
for (var first = true;; first = false) {
if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
// Clip forced viewport to actual scrollable area.
if (viewport && viewport.top != null) {
viewport = { top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top) };
}
// Updated line heights might result in the drawn area not
// actually covering the viewport. Keep looping until it does.
update.visible = visibleLines(cm.display, cm.doc, viewport);
if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo) {
break;
}
}
if (!updateDisplayIfNeeded(cm, update)) {
break;
}
updateHeightsInViewport(cm);
var barMeasure = measureForScrollbars(cm);
updateSelection(cm);
updateScrollbars(cm, barMeasure);
setDocumentHeight(cm, barMeasure);
update.force = false;
}
update.signal(cm, "update", cm);
if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
cm.display.reportedViewFrom = cm.display.viewFrom;cm.display.reportedViewTo = cm.display.viewTo;
}
}
function updateDisplaySimple(cm, viewport) {
var update = new DisplayUpdate(cm, viewport);
if (updateDisplayIfNeeded(cm, update)) {
updateHeightsInViewport(cm);
postUpdateDisplay(cm, update);
var barMeasure = measureForScrollbars(cm);
updateSelection(cm);
updateScrollbars(cm, barMeasure);
setDocumentHeight(cm, barMeasure);
update.finish();
}
}
// Sync the actual display DOM structure with display.view, removing
// nodes for lines that are no longer in view, and creating the ones
// that are not there yet, and updating the ones that are out of
// date.
function patchDisplay(cm, updateNumbersFrom, dims) {
var display = cm.display,
lineNumbers = cm.options.lineNumbers;
var container = display.lineDiv,
cur = container.firstChild;
function rm(node) {
var next = node.nextSibling;
// Works around a throw-scroll bug in OS X Webkit
if (webkit && mac && cm.display.currentWheelTarget == node) {
node.style.display = "none";
} else {
node.parentNode.removeChild(node);
}
return next;
}
var view = display.view,
lineN = display.viewFrom;
// Loop over the elements in the view, syncing cur (the DOM nodes
// in display.lineDiv) with the view as we go.
for (var i = 0; i < view.length; i++) {
var lineView = view[i];
if (lineView.hidden) {} else if (!lineView.node || lineView.node.parentNode != container) {
// Not drawn yet
var node = buildLineElement(cm, lineView, lineN, dims);
container.insertBefore(node, cur);
} else {
// Already drawn
while (cur != lineView.node) {
cur = rm(cur);
}
var updateNumber = lineNumbers && updateNumbersFrom != null && updateNumbersFrom <= lineN && lineView.lineNumber;
if (lineView.changes) {
if (indexOf(lineView.changes, "gutter") > -1) {
updateNumber = false;
}
updateLineForChanges(cm, lineView, lineN, dims);
}
if (updateNumber) {
removeChildren(lineView.lineNumber);
lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
}
cur = lineView.node.nextSibling;
}
lineN += lineView.size;
}
while (cur) {
cur = rm(cur);
}
}
function updateGutterSpace(cm) {
var width = cm.display.gutters.offsetWidth;
cm.display.sizer.style.marginLeft = width + "px";
}
function setDocumentHeight(cm, measure) {
cm.display.sizer.style.minHeight = measure.docHeight + "px";
cm.display.heightForcer.style.top = measure.docHeight + "px";
cm.display.gutters.style.height = measure.docHeight + cm.display.barHeight + scrollGap(cm) + "px";
}
// Rebuild the gutter elements, ensure the margin to the left of the
// code matches their width.
function updateGutters(cm) {
var gutters = cm.display.gutters,
specs = cm.options.gutters;
removeChildren(gutters);
var i = 0;
for (; i < specs.length; ++i) {
var gutterClass = specs[i];
var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
if (gutterClass == "CodeMirror-linenumbers") {
cm.display.lineGutter = gElt;
gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
}
}
gutters.style.display = i ? "" : "none";
updateGutterSpace(cm);
}
// Make sure the gutters options contains the element
// "CodeMirror-linenumbers" when the lineNumbers option is true.
function setGuttersForLineNumbers(options) {
var found = indexOf(options.gutters, "CodeMirror-linenumbers");
if (found == -1 && options.lineNumbers) {
options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
} else if (found > -1 && !options.lineNumbers) {
options.gutters = options.gutters.slice(0);
options.gutters.splice(found, 1);
}
}
// Since the delta values reported on mouse wheel events are
// unstandardized between browsers and even browser versions, and
// generally horribly unpredictable, this code starts by measuring
// the scroll effect that the first few mouse wheel events have,
// and, from that, detects the way it can convert deltas to pixel
// offsets afterwards.
//
// The reason we want to know the amount a wheel event will scroll
// is that it gives us a chance to update the display before the
// actual scrolling happens, reducing flickering.
var wheelSamples = 0;
var wheelPixelsPerUnit = null;
// Fill in a browser-detected starting value on browsers where we
// know one. These don't have to be accurate -- the result of them
// being wrong would just be a slight flicker on the first wheel
// scroll (if it is large enough).
if (ie) {
wheelPixelsPerUnit = -.53;
} else if (gecko) {
wheelPixelsPerUnit = 15;
} else if (chrome) {
wheelPixelsPerUnit = -.7;
} else if (safari) {
wheelPixelsPerUnit = -1 / 3;
}
function wheelEventDelta(e) {
var dx = e.wheelDeltaX,
dy = e.wheelDeltaY;
if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) {
dx = e.detail;
}
if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) {
dy = e.detail;
} else if (dy == null) {
dy = e.wheelDelta;
}
return { x: dx, y: dy };
}
function wheelEventPixels(e) {
var delta = wheelEventDelta(e);
delta.x *= wheelPixelsPerUnit;
delta.y *= wheelPixelsPerUnit;
return delta;
}
function onScrollWheel(cm, e) {
var delta = wheelEventDelta(e),
dx = delta.x,
dy = delta.y;
var display = cm.display,
scroll = display.scroller;
// Quit if there's nothing to scroll here
var canScrollX = scroll.scrollWidth > scroll.clientWidth;
var canScrollY = scroll.scrollHeight > scroll.clientHeight;
if (!(dx && canScrollX || dy && canScrollY)) {
return;
}
// Webkit browsers on OS X abort momentum scrolls when the target
// of the scroll event is removed from the scrollable element.
// This hack (see related code in patchDisplay) makes sure the
// element is kept around.
if (dy && mac && webkit) {
outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
for (var i = 0; i < view.length; i++) {
if (view[i].node == cur) {
cm.display.currentWheelTarget = cur;
break outer;
}
}
}
}
// On some browsers, horizontal scrolling will cause redraws to
// happen before the gutter has been realigned, causing it to
// wriggle around in a most unseemly way. When we have an
// estimated pixels/delta value, we just handle horizontal
// scrolling entirely here. It'll be slightly off from native, but
// better than glitching out.
if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
if (dy && canScrollY) {
updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit));
}
setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit));
// Only prevent default scrolling if vertical scrolling is
// actually possible. Otherwise, it causes vertical scroll
// jitter on OSX trackpads when deltaX is small and deltaY
// is large (issue #3579)
if (!dy || dy && canScrollY) {
e_preventDefault(e);
}
display.wheelStartX = null; // Abort measurement, if in progress
return;
}
// 'Project' the visible viewport to cover the area that is being
// scrolled into view (if we know enough to estimate it).
if (dy && wheelPixelsPerUnit != null) {
var pixels = dy * wheelPixelsPerUnit;
var top = cm.doc.scrollTop,
bot = top + display.wrapper.clientHeight;
if (pixels < 0) {
top = Math.max(0, top + pixels - 50);
} else {
bot = Math.min(cm.doc.height, bot + pixels + 50);
}
updateDisplaySimple(cm, { top: top, bottom: bot });
}
if (wheelSamples < 20) {
if (display.wheelStartX == null) {
display.wheelStartX = scroll.scrollLeft;display.wheelStartY = scroll.scrollTop;
display.wheelDX = dx;display.wheelDY = dy;
setTimeout(function () {
if (display.wheelStartX == null) {
return;
}
var movedX = scroll.scrollLeft - display.wheelStartX;
var movedY = scroll.scrollTop - display.wheelStartY;
var sample = movedY && display.wheelDY && movedY / display.wheelDY || movedX && display.wheelDX && movedX / display.wheelDX;
display.wheelStartX = display.wheelStartY = null;
if (!sample) {
return;
}
wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
++wheelSamples;
}, 200);
} else {
display.wheelDX += dx;display.wheelDY += dy;
}
}
}
// Selection objects are immutable. A new one is created every time
// the selection changes. A selection is one or more non-overlapping
// (and non-touching) ranges, sorted, and an integer that indicates
// which one is the primary selection (the one that's scrolled into
// view, that getCursor returns, etc).
var Selection = function (ranges, primIndex) {
this.ranges = ranges;
this.primIndex = primIndex;
};
Selection.prototype.primary = function () {
return this.ranges[this.primIndex];
};
Selection.prototype.equals = function (other) {
var this$1 = this;
if (other == this) {
return true;
}
if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) {
return false;
}
for (var i = 0; i < this.ranges.length; i++) {
var here = this$1.ranges[i],
there = other.ranges[i];
if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) {
return false;
}
}
return true;
};
Selection.prototype.deepCopy = function () {
var this$1 = this;
var out = [];
for (var i = 0; i < this.ranges.length; i++) {
out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head));
}
return new Selection(out, this.primIndex);
};
Selection.prototype.somethingSelected = function () {
var this$1 = this;
for (var i = 0; i < this.ranges.length; i++) {
if (!this$1.ranges[i].empty()) {
return true;
}
}
return false;
};
Selection.prototype.contains = function (pos, end) {
var this$1 = this;
if (!end) {
end = pos;
}
for (var i = 0; i < this.ranges.length; i++) {
var range = this$1.ranges[i];
if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0) {
return i;
}
}
return -1;
};
var Range = function (anchor, head) {
this.anchor = anchor;this.head = head;
};
Range.prototype.from = function () {
return minPos(this.anchor, this.head);
};
Range.prototype.to = function () {
return maxPos(this.anchor, this.head);
};
Range.prototype.empty = function () {
return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
};
// Take an unsorted, potentially overlapping set of ranges, and
// build a selection out of it. 'Consumes' ranges array (modifying
// it).
function normalizeSelection(ranges, primIndex) {
var prim = ranges[primIndex];
ranges.sort(function (a, b) {
return cmp(a.from(), b.from());
});
primIndex = indexOf(ranges, prim);
for (var i = 1; i < ranges.length; i++) {
var cur = ranges[i],
prev = ranges[i - 1];
if (cmp(prev.to(), cur.from()) >= 0) {
var from = minPos(prev.from(), cur.from()),
to = maxPos(prev.to(), cur.to());
var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
if (i <= primIndex) {
--primIndex;
}
ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
}
}
return new Selection(ranges, primIndex);
}
function simpleSelection(anchor, head) {
return new Selection([new Range(anchor, head || anchor)], 0);
}
// Compute the position of the end of a change (its 'to' property
// refers to the pre-change end).
function changeEnd(change) {
if (!change.text) {
return change.to;
}
return Pos(change.from.line + change.text.length - 1, lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
}
// Adjust a position to refer to the post-change position of the
// same text, or the end of the change if the change covers it.
function adjustForChange(pos, change) {
if (cmp(pos, change.from) < 0) {
return pos;
}
if (cmp(pos, change.to) <= 0) {
return changeEnd(change);
}
var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1,
ch = pos.ch;
if (pos.line == change.to.line) {
ch += changeEnd(change).ch - change.to.ch;
}
return Pos(line, ch);
}
function computeSelAfterChange(doc, change) {
var out = [];
for (var i = 0; i < doc.sel.ranges.length; i++) {
var range = doc.sel.ranges[i];
out.push(new Range(adjustForChange(range.anchor, change), adjustForChange(range.head, change)));
}
return normalizeSelection(out, doc.sel.primIndex);
}
function offsetPos(pos, old, nw) {
if (pos.line == old.line) {
return Pos(nw.line, pos.ch - old.ch + nw.ch);
} else {
return Pos(nw.line + (pos.line - old.line), pos.ch);
}
}
// Used by replaceSelections to allow moving the selection to the
// start or around the replaced test. Hint may be "start" or "around".
function computeReplacedSel(doc, changes, hint) {
var out = [];
var oldPrev = Pos(doc.first, 0),
newPrev = oldPrev;
for (var i = 0; i < changes.length; i++) {
var change = changes[i];
var from = offsetPos(change.from, oldPrev, newPrev);
var to = offsetPos(changeEnd(change), oldPrev, newPrev);
oldPrev = change.to;
newPrev = to;
if (hint == "around") {
var range = doc.sel.ranges[i],
inv = cmp(range.head, range.anchor) < 0;
out[i] = new Range(inv ? to : from, inv ? from : to);
} else {
out[i] = new Range(from, from);
}
}
return new Selection(out, doc.sel.primIndex);
}
// Used to get the editor into a consistent state again when options change.
function loadMode(cm) {
cm.doc.mode = getMode(cm.options, cm.doc.modeOption);
resetModeState(cm);
}
function resetModeState(cm) {
cm.doc.iter(function (line) {
if (line.stateAfter) {
line.stateAfter = null;
}
if (line.styles) {
line.styles = null;
}
});
cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first;
startWorker(cm, 100);
cm.state.modeGen++;
if (cm.curOp) {
regChange(cm);
}
}
// DOCUMENT DATA STRUCTURE
// By default, updates that start and end at the beginning of a line
// are treated specially, in order to make the association of line
// widgets and marker elements with the text behave more intuitive.
function isWholeLineUpdate(doc, change) {
return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" && (!doc.cm || doc.cm.options.wholeLineUpdateBefore);
}
// Perform a change on the document data structure.
function updateDoc(doc, change, markedSpans, estimateHeight$$1) {
function spansFor(n) {
return markedSpans ? markedSpans[n] : null;
}
function update(line, text, spans) {
updateLine(line, text, spans, estimateHeight$$1);
signalLater(line, "change", line, change);
}
function linesFor(start, end) {
var result = [];
for (var i = start; i < end; ++i) {
result.push(new Line(text[i], spansFor(i), estimateHeight$$1));
}
return result;
}
var from = change.from,
to = change.to,
text = change.text;
var firstLine = getLine(doc, from.line),
lastLine = getLine(doc, to.line);
var lastText = lst(text),
lastSpans = spansFor(text.length - 1),
nlines = to.line - from.line;
// Adjust the line structure
if (change.full) {
doc.insert(0, linesFor(0, text.length));
doc.remove(text.length, doc.size - text.length);
} else if (isWholeLineUpdate(doc, change)) {
// This is a whole-line replace. Treated specially to make
// sure line objects move the way they are supposed to.
var added = linesFor(0, text.length - 1);
update(lastLine, lastLine.text, lastSpans);
if (nlines) {
doc.remove(from.line, nlines);
}
if (added.length) {
doc.insert(from.line, added);
}
} else if (firstLine == lastLine) {
if (text.length == 1) {
update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
} else {
var added$1 = linesFor(1, text.length - 1);
added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight$$1));
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
doc.insert(from.line + 1, added$1);
}
} else if (text.length == 1) {
update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
doc.remove(from.line + 1, nlines);
} else {
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
var added$2 = linesFor(1, text.length - 1);
if (nlines > 1) {
doc.remove(from.line + 1, nlines - 1);
}
doc.insert(from.line + 1, added$2);
}
signalLater(doc, "change", doc, change);
}
// Call f for all linked documents.
function linkedDocs(doc, f, sharedHistOnly) {
function propagate(doc, skip, sharedHist) {
if (doc.linked) {
for (var i = 0; i < doc.linked.length; ++i) {
var rel = doc.linked[i];
if (rel.doc == skip) {
continue;
}
var shared = sharedHist && rel.sharedHist;
if (sharedHistOnly && !shared) {
continue;
}
f(rel.doc, shared);
propagate(rel.doc, doc, shared);
}
}
}
propagate(doc, null, true);
}
// Attach a document to an editor.
function attachDoc(cm, doc) {
if (doc.cm) {
throw new Error("This document is already in use.");
}
cm.doc = doc;
doc.cm = cm;
estimateLineHeights(cm);
loadMode(cm);
setDirectionClass(cm);
if (!cm.options.lineWrapping) {
findMaxLine(cm);
}
cm.options.mode = doc.modeOption;
regChange(cm);
}
function setDirectionClass(cm) {
(cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl");
}
function directionChanged(cm) {
runInOp(cm, function () {
setDirectionClass(cm);
regChange(cm);
});
}
function History(startGen) {
// Arrays of change events and selections. Doing something adds an
// event to done and clears undo. Undoing moves events from done
// to undone, redoing moves them in the other direction.
this.done = [];this.undone = [];
this.undoDepth = Infinity;
// Used to track when changes can be merged into a single undo
// event
this.lastModTime = this.lastSelTime = 0;
this.lastOp = this.lastSelOp = null;
this.lastOrigin = this.lastSelOrigin = null;
// Used by the isClean() method
this.generation = this.maxGeneration = startGen || 1;
}
// Create a history change event from an updateDoc-style change
// object.
function historyChangeFromChange(doc, change) {
var histChange = { from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to) };
attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
linkedDocs(doc, function (doc) {
return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
}, true);
return histChange;
}
// Pop all selection events off the end of a history array. Stop at
// a change event.
function clearSelectionEvents(array) {
while (array.length) {
var last = lst(array);
if (last.ranges) {
array.pop();
} else {
break;
}
}
}
// Find the top change event in the history. Pop off selection
// events that are in the way.
function lastChangeEvent(hist, force) {
if (force) {
clearSelectionEvents(hist.done);
return lst(hist.done);
} else if (hist.done.length && !lst(hist.done).ranges) {
return lst(hist.done);
} else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
hist.done.pop();
return lst(hist.done);
}
}
// Register a change in the history. Merges changes that are within
// a single operation, or are close together with an origin that
// allows merging (starting with "+") into a single event.
function addChangeToHistory(doc, change, selAfter, opId) {
var hist = doc.history;
hist.undone.length = 0;
var time = +new Date(),
cur;
var last;
if ((hist.lastOp == opId || hist.lastOrigin == change.origin && change.origin && (change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500) || change.origin.charAt(0) == "*")) && (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
// Merge this change into the last event
last = lst(cur.changes);
if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
// Optimized case for simple insertion -- don't want to add
// new changesets for every character typed
last.to = changeEnd(change);
} else {
// Add new sub-event
cur.changes.push(historyChangeFromChange(doc, change));
}
} else {
// Can not be merged, start a new event.
var before = lst(hist.done);
if (!before || !before.ranges) {
pushSelectionToHistory(doc.sel, hist.done);
}
cur = { changes: [historyChangeFromChange(doc, change)],
generation: hist.generation };
hist.done.push(cur);
while (hist.done.length > hist.undoDepth) {
hist.done.shift();
if (!hist.done[0].ranges) {
hist.done.shift();
}
}
}
hist.done.push(selAfter);
hist.generation = ++hist.maxGeneration;
hist.lastModTime = hist.lastSelTime = time;
hist.lastOp = hist.lastSelOp = opId;
hist.lastOrigin = hist.lastSelOrigin = change.origin;
if (!last) {
signal(doc, "historyAdded");
}
}
function selectionEventCanBeMerged(doc, origin, prev, sel) {
var ch = origin.charAt(0);
return ch == "*" || ch == "+" && prev.ranges.length == sel.ranges.length && prev.somethingSelected() == sel.somethingSelected() && new Date() - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500);
}
// Called whenever the selection changes, sets the new selection as
// the pending selection in the history, and pushes the old pending
// selection into the 'done' array when it was significantly
// different (in number of selected ranges, emptiness, or time).
function addSelectionToHistory(doc, sel, opId, options) {
var hist = doc.history,
origin = options && options.origin;
// A new event is started when the previous origin does not match
// the current, or the origins don't allow matching. Origins
// starting with * are always merged, those starting with + are
// merged when similar and close together in time.
if (opId == hist.lastSelOp || origin && hist.lastSelOrigin == origin && (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin || selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))) {
hist.done[hist.done.length - 1] = sel;
} else {
pushSelectionToHistory(sel, hist.done);
}
hist.lastSelTime = +new Date();
hist.lastSelOrigin = origin;
hist.lastSelOp = opId;
if (options && options.clearRedo !== false) {
clearSelectionEvents(hist.undone);
}
}
function pushSelectionToHistory(sel, dest) {
var top = lst(dest);
if (!(top && top.ranges && top.equals(sel))) {
dest.push(sel);
}
}
// Used to store marked span information in the history.
function attachLocalSpans(doc, change, from, to) {
var existing = change["spans_" + doc.id],
n = 0;
doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
if (line.markedSpans) {
(existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans;
}
++n;
});
}
// When un/re-doing restores text containing marked spans, those
// that have been explicitly cleared should not be restored.
function removeClearedSpans(spans) {
if (!spans) {
return null;
}
var out;
for (var i = 0; i < spans.length; ++i) {
if (spans[i].marker.explicitlyCleared) {
if (!out) {
out = spans.slice(0, i);
}
} else if (out) {
out.push(spans[i]);
}
}
return !out ? spans : out.length ? out : null;
}
// Retrieve and filter the old marked spans stored in a change event.
function getOldSpans(doc, change) {
var found = change["spans_" + doc.id];
if (!found) {
return null;
}
var nw = [];
for (var i = 0; i < change.text.length; ++i) {
nw.push(removeClearedSpans(found[i]));
}
return nw;
}
// Used for un/re-doing changes from the history. Combines the
// result of computing the existing spans with the set of spans that
// existed in the history (so that deleting around a span and then
// undoing brings back the span).
function mergeOldSpans(doc, change) {
var old = getOldSpans(doc, change);
var stretched = stretchSpansOverChange(doc, change);
if (!old) {
return stretched;
}
if (!stretched) {
return old;
}
for (var i = 0; i < old.length; ++i) {
var oldCur = old[i],
stretchCur = stretched[i];
if (oldCur && stretchCur) {
spans: for (var j = 0; j < stretchCur.length; ++j) {
var span = stretchCur[j];
for (var k = 0; k < oldCur.length; ++k) {
if (oldCur[k].marker == span.marker) {
continue spans;
}
}
oldCur.push(span);
}
} else if (stretchCur) {
old[i] = stretchCur;
}
}
return old;
}
// Used both to provide a JSON-safe object in .getHistory, and, when
// detaching a document, to split the history in two
function copyHistoryArray(events, newGroup, instantiateSel) {
var copy = [];
for (var i = 0; i < events.length; ++i) {
var event = events[i];
if (event.ranges) {
copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
continue;
}
var changes = event.changes,
newChanges = [];
copy.push({ changes: newChanges });
for (var j = 0; j < changes.length; ++j) {
var change = changes[j],
m = void 0;
newChanges.push({ from: change.from, to: change.to, text: change.text });
if (newGroup) {
for (var prop in change) {
if (m = prop.match(/^spans_(\d+)$/)) {
if (indexOf(newGroup, Number(m[1])) > -1) {
lst(newChanges)[prop] = change[prop];
delete change[prop];
}
}
}
}
}
}
return copy;
}
// The 'scroll' parameter given to many of these indicated whether
// the new cursor position should be scrolled into view after
// modifying the selection.
// If shift is held or the extend flag is set, extends a range to
// include a given position (and optionally a second position).
// Otherwise, simply returns the range between the given positions.
// Used for cursor motion and such.
function extendRange(range, head, other, extend) {
if (extend) {
var anchor = range.anchor;
if (other) {
var posBefore = cmp(head, anchor) < 0;
if (posBefore != cmp(other, anchor) < 0) {
anchor = head;
head = other;
} else if (posBefore != cmp(head, other) < 0) {
head = other;
}
}
return new Range(anchor, head);
} else {
return new Range(other || head, head);
}
}
// Extend the primary selection range, discard the rest.
function extendSelection(doc, head, other, options, extend) {
if (extend == null) {
extend = doc.cm && (doc.cm.display.shift || doc.extend);
}
setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options);
}
// Extend all selections (pos is an array of selections with length
// equal the number of selections)
function extendSelections(doc, heads, options) {
var out = [];
var extend = doc.cm && (doc.cm.display.shift || doc.extend);
for (var i = 0; i < doc.sel.ranges.length; i++) {
out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend);
}
var newSel = normalizeSelection(out, doc.sel.primIndex);
setSelection(doc, newSel, options);
}
// Updates a single range in the selection.
function replaceOneSelection(doc, i, range, options) {
var ranges = doc.sel.ranges.slice(0);
ranges[i] = range;
setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options);
}
// Reset the selection to a single range.
function setSimpleSelection(doc, anchor, head, options) {
setSelection(doc, simpleSelection(anchor, head), options);
}
// Give beforeSelectionChange handlers a change to influence a
// selection update.
function filterSelectionChange(doc, sel, options) {
var obj = {
ranges: sel.ranges,
update: function (ranges) {
var this$1 = this;
this.ranges = [];
for (var i = 0; i < ranges.length; i++) {
this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor), clipPos(doc, ranges[i].head));
}
},
origin: options && options.origin
};
signal(doc, "beforeSelectionChange", doc, obj);
if (doc.cm) {
signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
}
if (obj.ranges != sel.ranges) {
return normalizeSelection(obj.ranges, obj.ranges.length - 1);
} else {
return sel;
}
}
function setSelectionReplaceHistory(doc, sel, options) {
var done = doc.history.done,
last = lst(done);
if (last && last.ranges) {
done[done.length - 1] = sel;
setSelectionNoUndo(doc, sel, options);
} else {
setSelection(doc, sel, options);
}
}
// Set a new selection.
function setSelection(doc, sel, options) {
setSelectionNoUndo(doc, sel, options);
addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
}
function setSelectionNoUndo(doc, sel, options) {
if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange")) {
sel = filterSelectionChange(doc, sel, options);
}
var bias = options && options.bias || (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
if (!(options && options.scroll === false) && doc.cm) {
ensureCursorVisible(doc.cm);
}
}
function setSelectionInner(doc, sel) {
if (sel.equals(doc.sel)) {
return;
}
doc.sel = sel;
if (doc.cm) {
doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
signalCursorActivity(doc.cm);
}
signalLater(doc, "cursorActivity", doc);
}
// Verify that the selection does not partially select any atomic
// marked ranges.
function reCheckSelection(doc) {
setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false));
}
// Return a selection that does not partially select any atomic
// ranges.
function skipAtomicInSelection(doc, sel, bias, mayClear) {
var out;
for (var i = 0; i < sel.ranges.length; i++) {
var range = sel.ranges[i];
var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];
var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);
var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);
if (out || newAnchor != range.anchor || newHead != range.head) {
if (!out) {
out = sel.ranges.slice(0, i);
}
out[i] = new Range(newAnchor, newHead);
}
}
return out ? normalizeSelection(out, sel.primIndex) : sel;
}
function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
var line = getLine(doc, pos.line);
if (line.markedSpans) {
for (var i = 0; i < line.markedSpans.length; ++i) {
var sp = line.markedSpans[i],
m = sp.marker;
if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) && (sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
if (mayClear) {
signal(m, "beforeCursorEnter");
if (m.explicitlyCleared) {
if (!line.markedSpans) {
break;
} else {
--i;continue;
}
}
}
if (!m.atomic) {
continue;
}
if (oldPos) {
var near = m.find(dir < 0 ? 1 : -1),
diff = void 0;
if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft) {
near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null);
}
if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0)) {
return skipAtomicInner(doc, near, pos, dir, mayClear);
}
}
var far = m.find(dir < 0 ? -1 : 1);
if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight) {
far = movePos(doc, far, dir, far.line == pos.line ? line : null);
}
return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null;
}
}
}
return pos;
}
// Ensure a given position is not inside an atomic range.
function skipAtomic(doc, pos, oldPos, bias, mayClear) {
var dir = bias || 1;
var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) || !mayClear && skipAtomicInner(doc, pos, oldPos, dir, true) || skipAtomicInner(doc, pos, oldPos, -dir, mayClear) || !mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true);
if (!found) {
doc.cantEdit = true;
return Pos(doc.first, 0);
}
return found;
}
function movePos(doc, pos, dir, line) {
if (dir < 0 && pos.ch == 0) {
if (pos.line > doc.first) {
return clipPos(doc, Pos(pos.line - 1));
} else {
return null;
}
} else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
if (pos.line < doc.first + doc.size - 1) {
return Pos(pos.line + 1, 0);
} else {
return null;
}
} else {
return new Pos(pos.line, pos.ch + dir);
}
}
function selectAll(cm) {
cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);
}
// UPDATING
// Allow "beforeChange" event handlers to influence a change
function filterChange(doc, change, update) {
var obj = {
canceled: false,
from: change.from,
to: change.to,
text: change.text,
origin: change.origin,
cancel: function () {
return obj.canceled = true;
}
};
if (update) {
obj.update = function (from, to, text, origin) {
if (from) {
obj.from = clipPos(doc, from);
}
if (to) {
obj.to = clipPos(doc, to);
}
if (text) {
obj.text = text;
}
if (origin !== undefined) {
obj.origin = origin;
}
};
}
signal(doc, "beforeChange", doc, obj);
if (doc.cm) {
signal(doc.cm, "beforeChange", doc.cm, obj);
}
if (obj.canceled) {
return null;
}
return { from: obj.from, to: obj.to, text: obj.text, origin: obj.origin };
}
// Apply a change to a document, and add it to the document's
// history, and propagating it to all linked documents.
function makeChange(doc, change, ignoreReadOnly) {
if (doc.cm) {
if (!doc.cm.curOp) {
return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly);
}
if (doc.cm.state.suppressEdits) {
return;
}
}
if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
change = filterChange(doc, change, true);
if (!change) {
return;
}
}
// Possibly split or suppress the update based on the presence
// of read-only spans in its range.
var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
if (split) {
for (var i = split.length - 1; i >= 0; --i) {
makeChangeInner(doc, { from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin });
}
} else {
makeChangeInner(doc, change);
}
}
function makeChangeInner(doc, change) {
if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) {
return;
}
var selAfter = computeSelAfterChange(doc, change);
addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
var rebased = [];
linkedDocs(doc, function (doc, sharedHist) {
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
rebaseHist(doc.history, change);
rebased.push(doc.history);
}
makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
});
}
// Revert a change stored in a document's history.
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
var suppress = doc.cm && doc.cm.state.suppressEdits;
if (suppress && !allowSelectionOnly) {
return;
}
var hist = doc.history,
event,
selAfter = doc.sel;
var source = type == "undo" ? hist.done : hist.undone,
dest = type == "undo" ? hist.undone : hist.done;
// Verify that there is a useable event (so that ctrl-z won't
// needlessly clear selection events)
var i = 0;
for (; i < source.length; i++) {
event = source[i];
if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges) {
break;
}
}
if (i == source.length) {
return;
}
hist.lastOrigin = hist.lastSelOrigin = null;
for (;;) {
event = source.pop();
if (event.ranges) {
pushSelectionToHistory(event, dest);
if (allowSelectionOnly && !event.equals(doc.sel)) {
setSelection(doc, event, { clearRedo: false });
return;
}
selAfter = event;
} else if (suppress) {
source.push(event);
return;
} else {
break;
}
}
// Build up a reverse change object to add to the opposite history
// stack (redo when undoing, and vice versa).
var antiChanges = [];
pushSelectionToHistory(selAfter, dest);
dest.push({ changes: antiChanges, generation: hist.generation });
hist.generation = event.generation || ++hist.maxGeneration;
var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
var loop = function (i) {
var change = event.changes[i];
change.origin = type;
if (filter && !filterChange(doc, change, false)) {
source.length = 0;
return {};
}
antiChanges.push(historyChangeFromChange(doc, change));
var after = i ? computeSelAfterChange(doc, change) : lst(source);
makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
if (!i && doc.cm) {
doc.cm.scrollIntoView({ from: change.from, to: changeEnd(change) });
}
var rebased = [];
// Propagate to the linked documents
linkedDocs(doc, function (doc, sharedHist) {
if (!sharedHist && indexOf(rebased, doc.history) == -1) {
rebaseHist(doc.history, change);
rebased.push(doc.history);
}
makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
});
};
for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
var returned = loop(i$1);
if (returned) return returned.v;
}
}
// Sub-views need their line numbers shifted when text is added
// above or below them in the parent document.
function shiftDoc(doc, distance) {
if (distance == 0) {
return;
}
doc.first += distance;
doc.sel = new Selection(map(doc.sel.ranges, function (range) {
return new Range(Pos(range.anchor.line + distance, range.anchor.ch), Pos(range.head.line + distance, range.head.ch));
}), doc.sel.primIndex);
if (doc.cm) {
regChange(doc.cm, doc.first, doc.first - distance, distance);
for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++) {
regLineChange(doc.cm, l, "gutter");
}
}
}
// More lower-level change function, handling only a single document
// (not linked ones).
function makeChangeSingleDoc(doc, change, selAfter, spans) {
if (doc.cm && !doc.cm.curOp) {
return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
}
if (change.to.line < doc.first) {
shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
return;
}
if (change.from.line > doc.lastLine()) {
return;
}
// Clip the change to the size of this doc
if (change.from.line < doc.first) {
var shift = change.text.length - 1 - (doc.first - change.from.line);
shiftDoc(doc, shift);
change = { from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
text: [lst(change.text)], origin: change.origin };
}
var last = doc.lastLine();
if (change.to.line > last) {
change = { from: change.from, to: Pos(last, getLine(doc, last).text.length),
text: [change.text[0]], origin: change.origin };
}
change.removed = getBetween(doc, change.from, change.to);
if (!selAfter) {
selAfter = computeSelAfterChange(doc, change);
}
if (doc.cm) {
makeChangeSingleDocInEditor(doc.cm, change, spans);
} else {
updateDoc(doc, change, spans);
}
setSelectionNoUndo(doc, selAfter, sel_dontScroll);
}
// Handle the interaction of a change to a document with the editor
// that this document is part of.
function makeChangeSingleDocInEditor(cm, change, spans) {
var doc = cm.doc,
display = cm.display,
from = change.from,
to = change.to;
var recomputeMaxLength = false,
checkWidthStart = from.line;
if (!cm.options.lineWrapping) {
checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
doc.iter(checkWidthStart, to.line + 1, function (line) {
if (line == display.maxLine) {
recomputeMaxLength = true;
return true;
}
});
}
if (doc.sel.contains(change.from, change.to) > -1) {
signalCursorActivity(cm);
}
updateDoc(doc, change, spans, estimateHeight(cm));
if (!cm.options.lineWrapping) {
doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
var len = lineLength(line);
if (len > display.maxLineLength) {
display.maxLine = line;
display.maxLineLength = len;
display.maxLineChanged = true;
recomputeMaxLength = false;
}
});
if (recomputeMaxLength) {
cm.curOp.updateMaxLine = true;
}
}
retreatFrontier(doc, from.line);
startWorker(cm, 400);
var lendiff = change.text.length - (to.line - from.line) - 1;
// Remember that these lines changed, for updating the display
if (change.full) {
regChange(cm);
} else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change)) {
regLineChange(cm, from.line, "text");
} else {
regChange(cm, from.line, to.line + 1, lendiff);
}
var changesHandler = hasHandler(cm, "changes"),
changeHandler = hasHandler(cm, "change");
if (changeHandler || changesHandler) {
var obj = {
from: from, to: to,
text: change.text,
removed: change.removed,
origin: change.origin
};
if (changeHandler) {
signalLater(cm, "change", cm, obj);
}
if (changesHandler) {
(cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
}
}
cm.display.selForContextMenu = null;
}
function replaceRange(doc, code, from, to, origin) {
if (!to) {
to = from;
}
if (cmp(to, from) < 0) {
var assign;
assign = [to, from], from = assign[0], to = assign[1];
}
if (typeof code == "string") {
code = doc.splitLines(code);
}
makeChange(doc, { from: from, to: to, text: code, origin: origin });
}
// Rebasing/resetting history to deal with externally-sourced changes
function rebaseHistSelSingle(pos, from, to, diff) {
if (to < pos.line) {
pos.line += diff;
} else if (from < pos.line) {
pos.line = from;
pos.ch = 0;
}
}
// Tries to rebase an array of history events given a change in the
// document. If the change touches the same lines as the event, the
// event, and everything 'behind' it, is discarded. If the change is
// before the event, the event's positions are updated. Uses a
// copy-on-write scheme for the positions, to avoid having to
// reallocate them all on every rebase, but also avoid problems with
// shared position objects being unsafely updated.
function rebaseHistArray(array, from, to, diff) {
for (var i = 0; i < array.length; ++i) {
var sub = array[i],
ok = true;
if (sub.ranges) {
if (!sub.copied) {
sub = array[i] = sub.deepCopy();sub.copied = true;
}
for (var j = 0; j < sub.ranges.length; j++) {
rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
}
continue;
}
for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
var cur = sub.changes[j$1];
if (to < cur.from.line) {
cur.from = Pos(cur.from.line + diff, cur.from.ch);
cur.to = Pos(cur.to.line + diff, cur.to.ch);
} else if (from <= cur.to.line) {
ok = false;
break;
}
}
if (!ok) {
array.splice(0, i + 1);
i = 0;
}
}
}
function rebaseHist(hist, change) {
var from = change.from.line,
to = change.to.line,
diff = change.text.length - (to - from) - 1;
rebaseHistArray(hist.done, from, to, diff);
rebaseHistArray(hist.undone, from, to, diff);
}
// Utility for applying a change to a line by handle or number,
// returning the number and optionally registering the line as
// changed.
function changeLine(doc, handle, changeType, op) {
var no = handle,
line = handle;
if (typeof handle == "number") {
line = getLine(doc, clipLine(doc, handle));
} else {
no = lineNo(handle);
}
if (no == null) {
return null;
}
if (op(line, no) && doc.cm) {
regLineChange(doc.cm, no, changeType);
}
return line;
}
// The document is represented as a BTree consisting of leaves, with
// chunk of lines in them, and branches, with up to ten leaves or
// other branch nodes below them. The top node is always a branch
// node, and is the document object itself (meaning it has
// additional methods and properties).
//
// All nodes have parent links. The tree is used both to go from
// line numbers to line objects, and to go from objects to numbers.
// It also indexes by height, and is used to convert between height
// and line object, and to find the total height of the document.
//
// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
function LeafChunk(lines) {
var this$1 = this;
this.lines = lines;
this.parent = null;
var height = 0;
for (var i = 0; i < lines.length; ++i) {
lines[i].parent = this$1;
height += lines[i].height;
}
this.height = height;
}
LeafChunk.prototype = {
chunkSize: function () {
return this.lines.length;
},
// Remove the n lines at offset 'at'.
removeInner: function (at, n) {
var this$1 = this;
for (var i = at, e = at + n; i < e; ++i) {
var line = this$1.lines[i];
this$1.height -= line.height;
cleanUpLine(line);
signalLater(line, "delete");
}
this.lines.splice(at, n);
},
// Helper used to collapse a small branch into a single leaf.
collapse: function (lines) {
lines.push.apply(lines, this.lines);
},
// Insert the given array of lines at offset 'at', count them as
// having the given height.
insertInner: function (at, lines, height) {
var this$1 = this;
this.height += height;
this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
for (var i = 0; i < lines.length; ++i) {
lines[i].parent = this$1;
}
},
// Used to iterate over a part of the tree.
iterN: function (at, n, op) {
var this$1 = this;
for (var e = at + n; at < e; ++at) {
if (op(this$1.lines[at])) {
return true;
}
}
}
};
function BranchChunk(children) {
var this$1 = this;
this.children = children;
var size = 0,
height = 0;
for (var i = 0; i < children.length; ++i) {
var ch = children[i];
size += ch.chunkSize();height += ch.height;
ch.parent = this$1;
}
this.size = size;
this.height = height;
this.parent = null;
}
BranchChunk.prototype = {
chunkSize: function () {
return this.size;
},
removeInner: function (at, n) {
var this$1 = this;
this.size -= n;
for (var i = 0; i < this.children.length; ++i) {
var child = this$1.children[i],
sz = child.chunkSize();
if (at < sz) {
var rm = Math.min(n, sz - at),
oldHeight = child.height;
child.removeInner(at, rm);
this$1.height -= oldHeight - child.height;
if (sz == rm) {
this$1.children.splice(i--, 1);child.parent = null;
}
if ((n -= rm) == 0) {
break;
}
at = 0;
} else {
at -= sz;
}
}
// If the result is smaller than 25 lines, ensure that it is a
// single leaf node.
if (this.size - n < 25 && (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
var lines = [];
this.collapse(lines);
this.children = [new LeafChunk(lines)];
this.children[0].parent = this;
}
},
collapse: function (lines) {
var this$1 = this;
for (var i = 0; i < this.children.length; ++i) {
this$1.children[i].collapse(lines);
}
},
insertInner: function (at, lines, height) {
var this$1 = this;
this.size += lines.length;
this.height += height;
for (var i = 0; i < this.children.length; ++i) {
var child = this$1.children[i],
sz = child.chunkSize();
if (at <= sz) {
child.insertInner(at, lines, height);
if (child.lines && child.lines.length > 50) {
// To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
// Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
var remaining = child.lines.length % 25 + 25;
for (var pos = remaining; pos < child.lines.length;) {
var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
child.height -= leaf.height;
this$1.children.splice(++i, 0, leaf);
leaf.parent = this$1;
}
child.lines = child.lines.slice(0, remaining);
this$1.maybeSpill();
}
break;
}
at -= sz;
}
},
// When a node has grown, check whether it should be split.
maybeSpill: function () {
if (this.children.length <= 10) {
return;
}
var me = this;
do {
var spilled = me.children.splice(me.children.length - 5, 5);
var sibling = new BranchChunk(spilled);
if (!me.parent) {
// Become the parent node
var copy = new BranchChunk(me.children);
copy.parent = me;
me.children = [copy, sibling];
me = copy;
} else {
me.size -= sibling.size;
me.height -= sibling.height;
var myIndex = indexOf(me.parent.children, me);
me.parent.children.splice(myIndex + 1, 0, sibling);
}
sibling.parent = me.parent;
} while (me.children.length > 10);
me.parent.maybeSpill();
},
iterN: function (at, n, op) {
var this$1 = this;
for (var i = 0; i < this.children.length; ++i) {
var child = this$1.children[i],
sz = child.chunkSize();
if (at < sz) {
var used = Math.min(n, sz - at);
if (child.iterN(at, used, op)) {
return true;
}
if ((n -= used) == 0) {
break;
}
at = 0;
} else {
at -= sz;
}
}
}
};
// Line widgets are block elements displayed above or below a line.
var LineWidget = function (doc, node, options) {
var this$1 = this;
if (options) {
for (var opt in options) {
if (options.hasOwnProperty(opt)) {
this$1[opt] = options[opt];
}
}
}
this.doc = doc;
this.node = node;
};
LineWidget.prototype.clear = function () {
var this$1 = this;
var cm = this.doc.cm,
ws = this.line.widgets,
line = this.line,
no = lineNo(line);
if (no == null || !ws) {
return;
}
for (var i = 0; i < ws.length; ++i) {
if (ws[i] == this$1) {
ws.splice(i--, 1);
}
}
if (!ws.length) {
line.widgets = null;
}
var height = widgetHeight(this);
updateLineHeight(line, Math.max(0, line.height - height));
if (cm) {
runInOp(cm, function () {
adjustScrollWhenAboveVisible(cm, line, -height);
regLineChange(cm, no, "widget");
});
signalLater(cm, "lineWidgetCleared", cm, this, no);
}
};
LineWidget.prototype.changed = function () {
var this$1 = this;
var oldH = this.height,
cm = this.doc.cm,
line = this.line;
this.height = null;
var diff = widgetHeight(this) - oldH;
if (!diff) {
return;
}
updateLineHeight(line, line.height + diff);
if (cm) {
runInOp(cm, function () {
cm.curOp.forceUpdate = true;
adjustScrollWhenAboveVisible(cm, line, diff);
signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line));
});
}
};
eventMixin(LineWidget);
function adjustScrollWhenAboveVisible(cm, line, diff) {
if (heightAtLine(line) < (cm.curOp && cm.curOp.scrollTop || cm.doc.scrollTop)) {
addToScrollTop(cm, diff);
}
}
function addLineWidget(doc, handle, node, options) {
var widget = new LineWidget(doc, node, options);
var cm = doc.cm;
if (cm && widget.noHScroll) {
cm.display.alignWidgets = true;
}
changeLine(doc, handle, "widget", function (line) {
var widgets = line.widgets || (line.widgets = []);
if (widget.insertAt == null) {
widgets.push(widget);
} else {
widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
}
widget.line = line;
if (cm && !lineIsHidden(doc, line)) {
var aboveVisible = heightAtLine(line) < doc.scrollTop;
updateLineHeight(line, line.height + widgetHeight(widget));
if (aboveVisible) {
addToScrollTop(cm, widget.height);
}
cm.curOp.forceUpdate = true;
}
return true;
});
if (cm) {
signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle));
}
return widget;
}
// TEXTMARKERS
// Created with markText and setBookmark methods. A TextMarker is a
// handle that can be used to clear or find a marked position in the
// document. Line objects hold arrays (markedSpans) containing
// {from, to, marker} object pointing to such marker objects, and
// indicating that such a marker is present on that line. Multiple
// lines may point to the same marker when it spans across lines.
// The spans will have null for their from/to properties when the
// marker continues beyond the start/end of the line. Markers have
// links back to the lines they currently touch.
// Collapsed markers have unique ids, in order to be able to order
// them, which is needed for uniquely determining an outer marker
// when they overlap (they may nest, but not partially overlap).
var nextMarkerId = 0;
var TextMarker = function (doc, type) {
this.lines = [];
this.type = type;
this.doc = doc;
this.id = ++nextMarkerId;
};
// Clear the marker.
TextMarker.prototype.clear = function () {
var this$1 = this;
if (this.explicitlyCleared) {
return;
}
var cm = this.doc.cm,
withOp = cm && !cm.curOp;
if (withOp) {
startOperation(cm);
}
if (hasHandler(this, "clear")) {
var found = this.find();
if (found) {
signalLater(this, "clear", found.from, found.to);
}
}
var min = null,
max = null;
for (var i = 0; i < this.lines.length; ++i) {
var line = this$1.lines[i];
var span = getMarkedSpanFor(line.markedSpans, this$1);
if (cm && !this$1.collapsed) {
regLineChange(cm, lineNo(line), "text");
} else if (cm) {
if (span.to != null) {
max = lineNo(line);
}
if (span.from != null) {
min = lineNo(line);
}
}
line.markedSpans = removeMarkedSpan(line.markedSpans, span);
if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm) {
updateLineHeight(line, textHeight(cm.display));
}
}
if (cm && this.collapsed && !cm.options.lineWrapping) {
for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
var visual = visualLine(this$1.lines[i$1]),
len = lineLength(visual);
if (len > cm.display.maxLineLength) {
cm.display.maxLine = visual;
cm.display.maxLineLength = len;
cm.display.maxLineChanged = true;
}
}
}
if (min != null && cm && this.collapsed) {
regChange(cm, min, max + 1);
}
this.lines.length = 0;
this.explicitlyCleared = true;
if (this.atomic && this.doc.cantEdit) {
this.doc.cantEdit = false;
if (cm) {
reCheckSelection(cm.doc);
}
}
if (cm) {
signalLater(cm, "markerCleared", cm, this, min, max);
}
if (withOp) {
endOperation(cm);
}
if (this.parent) {
this.parent.clear();
}
};
// Find the position of the marker in the document. Returns a {from,
// to} object by default. Side can be passed to get a specific side
// -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
// Pos objects returned contain a line object, rather than a line
// number (used to prevent looking up the same line twice).
TextMarker.prototype.find = function (side, lineObj) {
var this$1 = this;
if (side == null && this.type == "bookmark") {
side = 1;
}
var from, to;
for (var i = 0; i < this.lines.length; ++i) {
var line = this$1.lines[i];
var span = getMarkedSpanFor(line.markedSpans, this$1);
if (span.from != null) {
from = Pos(lineObj ? line : lineNo(line), span.from);
if (side == -1) {
return from;
}
}
if (span.to != null) {
to = Pos(lineObj ? line : lineNo(line), span.to);
if (side == 1) {
return to;
}
}
}
return from && { from: from, to: to };
};
// Signals that the marker's widget changed, and surrounding layout
// should be recomputed.
TextMarker.prototype.changed = function () {
var this$1 = this;
var pos = this.find(-1, true),
widget = this,
cm = this.doc.cm;
if (!pos || !cm) {
return;
}
runInOp(cm, function () {
var line = pos.line,
lineN = lineNo(pos.line);
var view = findViewForLine(cm, lineN);
if (view) {
clearLineMeasurementCacheFor(view);
cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
}
cm.curOp.updateMaxLine = true;
if (!lineIsHidden(widget.doc, line) && widget.height != null) {
var oldHeight = widget.height;
widget.height = null;
var dHeight = widgetHeight(widget) - oldHeight;
if (dHeight) {
updateLineHeight(line, line.height + dHeight);
}
}
signalLater(cm, "markerChanged", cm, this$1);
});
};
TextMarker.prototype.attachLine = function (line) {
if (!this.lines.length && this.doc.cm) {
var op = this.doc.cm.curOp;
if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1) {
(op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
}
}
this.lines.push(line);
};
TextMarker.prototype.detachLine = function (line) {
this.lines.splice(indexOf(this.lines, line), 1);
if (!this.lines.length && this.doc.cm) {
var op = this.doc.cm.curOp;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
}
};
eventMixin(TextMarker);
// Create a marker, wire it up to the right lines, and
function markText(doc, from, to, options, type) {
// Shared markers (across linked documents) are handled separately
// (markTextShared will call out to this again, once per
// document).
if (options && options.shared) {
return markTextShared(doc, from, to, options, type);
}
// Ensure we are in an operation.
if (doc.cm && !doc.cm.curOp) {
return operation(doc.cm, markText)(doc, from, to, options, type);
}
var marker = new TextMarker(doc, type),
diff = cmp(from, to);
if (options) {
copyObj(options, marker, false);
}
// Don't connect empty markers unless clearWhenEmpty is false
if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false) {
return marker;
}
if (marker.replacedWith) {
// Showing up as a widget implies collapsed (widget replaces text)
marker.collapsed = true;
marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
if (!options.handleMouseEvents) {
marker.widgetNode.setAttribute("cm-ignore-events", "true");
}
if (options.insertLeft) {
marker.widgetNode.insertLeft = true;
}
}
if (marker.collapsed) {
if (conflictingCollapsedRange(doc, from.line, from, to, marker) || from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker)) {
throw new Error("Inserting collapsed marker partially overlapping an existing one");
}
seeCollapsedSpans();
}
if (marker.addToHistory) {
addChangeToHistory(doc, { from: from, to: to, origin: "markText" }, doc.sel, NaN);
}
var curLine = from.line,
cm = doc.cm,
updateMaxLine;
doc.iter(curLine, to.line + 1, function (line) {
if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine) {
updateMaxLine = true;
}
if (marker.collapsed && curLine != from.line) {
updateLineHeight(line, 0);
}
addMarkedSpan(line, new MarkedSpan(marker, curLine == from.line ? from.ch : null, curLine == to.line ? to.ch : null));
++curLine;
});
// lineIsHidden depends on the presence of the spans, so needs a second pass
if (marker.collapsed) {
doc.iter(from.line, to.line + 1, function (line) {
if (lineIsHidden(doc, line)) {
updateLineHeight(line, 0);
}
});
}
if (marker.clearOnEnter) {
on(marker, "beforeCursorEnter", function () {
return marker.clear();
});
}
if (marker.readOnly) {
seeReadOnlySpans();
if (doc.history.done.length || doc.history.undone.length) {
doc.clearHistory();
}
}
if (marker.collapsed) {
marker.id = ++nextMarkerId;
marker.atomic = true;
}
if (cm) {
// Sync editor state
if (updateMaxLine) {
cm.curOp.updateMaxLine = true;
}
if (marker.collapsed) {
regChange(cm, from.line, to.line + 1);
} else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css) {
for (var i = from.line; i <= to.line; i++) {
regLineChange(cm, i, "text");
}
}
if (marker.atomic) {
reCheckSelection(cm.doc);
}
signalLater(cm, "markerAdded", cm, marker);
}
return marker;
}
// SHARED TEXTMARKERS
// A shared marker spans multiple linked documents. It is
// implemented as a meta-marker-object controlling multiple normal
// markers.
var SharedTextMarker = function (markers, primary) {
var this$1 = this;
this.markers = markers;
this.primary = primary;
for (var i = 0; i < markers.length; ++i) {
markers[i].parent = this$1;
}
};
SharedTextMarker.prototype.clear = function () {
var this$1 = this;
if (this.explicitlyCleared) {
return;
}
this.explicitlyCleared = true;
for (var i = 0; i < this.markers.length; ++i) {
this$1.markers[i].clear();
}
signalLater(this, "clear");
};
SharedTextMarker.prototype.find = function (side, lineObj) {
return this.primary.find(side, lineObj);
};
eventMixin(SharedTextMarker);
function markTextShared(doc, from, to, options, type) {
options = copyObj(options);
options.shared = false;
var markers = [markText(doc, from, to, options, type)],
primary = markers[0];
var widget = options.widgetNode;
linkedDocs(doc, function (doc) {
if (widget) {
options.widgetNode = widget.cloneNode(true);
}
markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
for (var i = 0; i < doc.linked.length; ++i) {
if (doc.linked[i].isParent) {
return;
}
}
primary = lst(markers);
});
return new SharedTextMarker(markers, primary);
}
function findSharedMarkers(doc) {
return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) {
return m.parent;
});
}
function copySharedMarkers(doc, markers) {
for (var i = 0; i < markers.length; i++) {
var marker = markers[i],
pos = marker.find();
var mFrom = doc.clipPos(pos.from),
mTo = doc.clipPos(pos.to);
if (cmp(mFrom, mTo)) {
var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
marker.markers.push(subMark);
subMark.parent = marker;
}
}
}
function detachSharedMarkers(markers) {
var loop = function (i) {
var marker = markers[i],
linked = [marker.primary.doc];
linkedDocs(marker.primary.doc, function (d) {
return linked.push(d);
});
for (var j = 0; j < marker.markers.length; j++) {
var subMarker = marker.markers[j];
if (indexOf(linked, subMarker.doc) == -1) {
subMarker.parent = null;
marker.markers.splice(j--, 1);
}
}
};
for (var i = 0; i < markers.length; i++) loop(i);
}
var nextDocId = 0;
var Doc = function (text, mode, firstLine, lineSep, direction) {
if (!(this instanceof Doc)) {
return new Doc(text, mode, firstLine, lineSep, direction);
}
if (firstLine == null) {
firstLine = 0;
}
BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
this.first = firstLine;
this.scrollTop = this.scrollLeft = 0;
this.cantEdit = false;
this.cleanGeneration = 1;
this.modeFrontier = this.highlightFrontier = firstLine;
var start = Pos(firstLine, 0);
this.sel = simpleSelection(start);
this.history = new History(null);
this.id = ++nextDocId;
this.modeOption = mode;
this.lineSep = lineSep;
this.direction = direction == "rtl" ? "rtl" : "ltr";
this.extend = false;
if (typeof text == "string") {
text = this.splitLines(text);
}
updateDoc(this, { from: start, to: start, text: text });
setSelection(this, simpleSelection(start), sel_dontScroll);
};
Doc.prototype = createObj(BranchChunk.prototype, {
constructor: Doc,
// Iterate over the document. Supports two forms -- with only one
// argument, it calls that for each line in the document. With
// three, it iterates over the range given by the first two (with
// the second being non-inclusive).
iter: function (from, to, op) {
if (op) {
this.iterN(from - this.first, to - from, op);
} else {
this.iterN(this.first, this.first + this.size, from);
}
},
// Non-public interface for adding and removing lines.
insert: function (at, lines) {
var height = 0;
for (var i = 0; i < lines.length; ++i) {
height += lines[i].height;
}
this.insertInner(at - this.first, lines, height);
},
remove: function (at, n) {
this.removeInner(at - this.first, n);
},
// From here, the methods are part of the public interface. Most
// are also available from CodeMirror (editor) instances.
getValue: function (lineSep) {
var lines = getLines(this, this.first, this.first + this.size);
if (lineSep === false) {
return lines;
}
return lines.join(lineSep || this.lineSeparator());
},
setValue: docMethodOp(function (code) {
var top = Pos(this.first, 0),
last = this.first + this.size - 1;
makeChange(this, { from: top, to: Pos(last, getLine(this, last).text.length),
text: this.splitLines(code), origin: "setValue", full: true }, true);
if (this.cm) {
scrollToCoords(this.cm, 0, 0);
}
setSelection(this, simpleSelection(top), sel_dontScroll);
}),
replaceRange: function (code, from, to, origin) {
from = clipPos(this, from);
to = to ? clipPos(this, to) : from;
replaceRange(this, code, from, to, origin);
},
getRange: function (from, to, lineSep) {
var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
if (lineSep === false) {
return lines;
}
return lines.join(lineSep || this.lineSeparator());
},
getLine: function (line) {
var l = this.getLineHandle(line);return l && l.text;
},
getLineHandle: function (line) {
if (isLine(this, line)) {
return getLine(this, line);
}
},
getLineNumber: function (line) {
return lineNo(line);
},
getLineHandleVisualStart: function (line) {
if (typeof line == "number") {
line = getLine(this, line);
}
return visualLine(line);
},
lineCount: function () {
return this.size;
},
firstLine: function () {
return this.first;
},
lastLine: function () {
return this.first + this.size - 1;
},
clipPos: function (pos) {
return clipPos(this, pos);
},
getCursor: function (start) {
var range$$1 = this.sel.primary(),
pos;
if (start == null || start == "head") {
pos = range$$1.head;
} else if (start == "anchor") {
pos = range$$1.anchor;
} else if (start == "end" || start == "to" || start === false) {
pos = range$$1.to();
} else {
pos = range$$1.from();
}
return pos;
},
listSelections: function () {
return this.sel.ranges;
},
somethingSelected: function () {
return this.sel.somethingSelected();
},
setCursor: docMethodOp(function (line, ch, options) {
setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
}),
setSelection: docMethodOp(function (anchor, head, options) {
setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
}),
extendSelection: docMethodOp(function (head, other, options) {
extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
}),
extendSelections: docMethodOp(function (heads, options) {
extendSelections(this, clipPosArray(this, heads), options);
}),
extendSelectionsBy: docMethodOp(function (f, options) {
var heads = map(this.sel.ranges, f);
extendSelections(this, clipPosArray(this, heads), options);
}),
setSelections: docMethodOp(function (ranges, primary, options) {
var this$1 = this;
if (!ranges.length) {
return;
}
var out = [];
for (var i = 0; i < ranges.length; i++) {
out[i] = new Range(clipPos(this$1, ranges[i].anchor), clipPos(this$1, ranges[i].head));
}
if (primary == null) {
primary = Math.min(ranges.length - 1, this.sel.primIndex);
}
setSelection(this, normalizeSelection(out, primary), options);
}),
addSelection: docMethodOp(function (anchor, head, options) {
var ranges = this.sel.ranges.slice(0);
ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
setSelection(this, normalizeSelection(ranges, ranges.length - 1), options);
}),
getSelection: function (lineSep) {
var this$1 = this;
var ranges = this.sel.ranges,
lines;
for (var i = 0; i < ranges.length; i++) {
var sel = getBetween(this$1, ranges[i].from(), ranges[i].to());
lines = lines ? lines.concat(sel) : sel;
}
if (lineSep === false) {
return lines;
} else {
return lines.join(lineSep || this.lineSeparator());
}
},
getSelections: function (lineSep) {
var this$1 = this;
var parts = [],
ranges = this.sel.ranges;
for (var i = 0; i < ranges.length; i++) {
var sel = getBetween(this$1, ranges[i].from(), ranges[i].to());
if (lineSep !== false) {
sel = sel.join(lineSep || this$1.lineSeparator());
}
parts[i] = sel;
}
return parts;
},
replaceSelection: function (code, collapse, origin) {
var dup = [];
for (var i = 0; i < this.sel.ranges.length; i++) {
dup[i] = code;
}
this.replaceSelections(dup, collapse, origin || "+input");
},
replaceSelections: docMethodOp(function (code, collapse, origin) {
var this$1 = this;
var changes = [],
sel = this.sel;
for (var i = 0; i < sel.ranges.length; i++) {
var range$$1 = sel.ranges[i];
changes[i] = { from: range$$1.from(), to: range$$1.to(), text: this$1.splitLines(code[i]), origin: origin };
}
var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
for (var i$1 = changes.length - 1; i$1 >= 0; i$1--) {
makeChange(this$1, changes[i$1]);
}
if (newSel) {
setSelectionReplaceHistory(this, newSel);
} else if (this.cm) {
ensureCursorVisible(this.cm);
}
}),
undo: docMethodOp(function () {
makeChangeFromHistory(this, "undo");
}),
redo: docMethodOp(function () {
makeChangeFromHistory(this, "redo");
}),
undoSelection: docMethodOp(function () {
makeChangeFromHistory(this, "undo", true);
}),
redoSelection: docMethodOp(function () {
makeChangeFromHistory(this, "redo", true);
}),
setExtending: function (val) {
this.extend = val;
},
getExtending: function () {
return this.extend;
},
historySize: function () {
var hist = this.history,
done = 0,
undone = 0;
for (var i = 0; i < hist.done.length; i++) {
if (!hist.done[i].ranges) {
++done;
}
}
for (var i$1 = 0; i$1 < hist.undone.length; i$1++) {
if (!hist.undone[i$1].ranges) {
++undone;
}
}
return { undo: done, redo: undone };
},
clearHistory: function () {
this.history = new History(this.history.maxGeneration);
},
markClean: function () {
this.cleanGeneration = this.changeGeneration(true);
},
changeGeneration: function (forceSplit) {
if (forceSplit) {
this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null;
}
return this.history.generation;
},
isClean: function (gen) {
return this.history.generation == (gen || this.cleanGeneration);
},
getHistory: function () {
return { done: copyHistoryArray(this.history.done),
undone: copyHistoryArray(this.history.undone) };
},
setHistory: function (histData) {
var hist = this.history = new History(this.history.maxGeneration);
hist.done = copyHistoryArray(histData.done.slice(0), null, true);
hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
},
setGutterMarker: docMethodOp(function (line, gutterID, value) {
return changeLine(this, line, "gutter", function (line) {
var markers = line.gutterMarkers || (line.gutterMarkers = {});
markers[gutterID] = value;
if (!value && isEmpty(markers)) {
line.gutterMarkers = null;
}
return true;
});
}),
clearGutter: docMethodOp(function (gutterID) {
var this$1 = this;
this.iter(function (line) {
if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
changeLine(this$1, line, "gutter", function () {
line.gutterMarkers[gutterID] = null;
if (isEmpty(line.gutterMarkers)) {
line.gutterMarkers = null;
}
return true;
});
}
});
}),
lineInfo: function (line) {
var n;
if (typeof line == "number") {
if (!isLine(this, line)) {
return null;
}
n = line;
line = getLine(this, line);
if (!line) {
return null;
}
} else {
n = lineNo(line);
if (n == null) {
return null;
}
}
return { line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
widgets: line.widgets };
},
addLineClass: docMethodOp(function (handle, where, cls) {
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : where == "gutter" ? "gutterClass" : "wrapClass";
if (!line[prop]) {
line[prop] = cls;
} else if (classTest(cls).test(line[prop])) {
return false;
} else {
line[prop] += " " + cls;
}
return true;
});
}),
removeLineClass: docMethodOp(function (handle, where, cls) {
return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : where == "gutter" ? "gutterClass" : "wrapClass";
var cur = line[prop];
if (!cur) {
return false;
} else if (cls == null) {
line[prop] = null;
} else {
var found = cur.match(classTest(cls));
if (!found) {
return false;
}
var end = found.index + found[0].length;
line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
}
return true;
});
}),
addLineWidget: docMethodOp(function (handle, node, options) {
return addLineWidget(this, handle, node, options);
}),
removeLineWidget: function (widget) {
widget.clear();
},
markText: function (from, to, options) {
return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range");
},
setBookmark: function (pos, options) {
var realOpts = { replacedWith: options && (options.nodeType == null ? options.widget : options),
insertLeft: options && options.insertLeft,
clearWhenEmpty: false, shared: options && options.shared,
handleMouseEvents: options && options.handleMouseEvents };
pos = clipPos(this, pos);
return markText(this, pos, pos, realOpts, "bookmark");
},
findMarksAt: function (pos) {
pos = clipPos(this, pos);
var markers = [],
spans = getLine(this, pos.line).markedSpans;
if (spans) {
for (var i = 0; i < spans.length; ++i) {
var span = spans[i];
if ((span.from == null || span.from <= pos.ch) && (span.to == null || span.to >= pos.ch)) {
markers.push(span.marker.parent || span.marker);
}
}
}
return markers;
},
findMarks: function (from, to, filter) {
from = clipPos(this, from);to = clipPos(this, to);
var found = [],
lineNo$$1 = from.line;
this.iter(from.line, to.line + 1, function (line) {
var spans = line.markedSpans;
if (spans) {
for (var i = 0; i < spans.length; i++) {
var span = spans[i];
if (!(span.to != null && lineNo$$1 == from.line && from.ch >= span.to || span.from == null && lineNo$$1 != from.line || span.from != null && lineNo$$1 == to.line && span.from >= to.ch) && (!filter || filter(span.marker))) {
found.push(span.marker.parent || span.marker);
}
}
}
++lineNo$$1;
});
return found;
},
getAllMarks: function () {
var markers = [];
this.iter(function (line) {
var sps = line.markedSpans;
if (sps) {
for (var i = 0; i < sps.length; ++i) {
if (sps[i].from != null) {
markers.push(sps[i].marker);
}
}
}
});
return markers;
},
posFromIndex: function (off) {
var ch,
lineNo$$1 = this.first,
sepSize = this.lineSeparator().length;
this.iter(function (line) {
var sz = line.text.length + sepSize;
if (sz > off) {
ch = off;return true;
}
off -= sz;
++lineNo$$1;
});
return clipPos(this, Pos(lineNo$$1, ch));
},
indexFromPos: function (coords) {
coords = clipPos(this, coords);
var index = coords.ch;
if (coords.line < this.first || coords.ch < 0) {
return 0;
}
var sepSize = this.lineSeparator().length;
this.iter(this.first, coords.line, function (line) {
// iter aborts when callback returns a truthy value
index += line.text.length + sepSize;
});
return index;
},
copy: function (copyHistory) {
var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first, this.lineSep, this.direction);
doc.scrollTop = this.scrollTop;doc.scrollLeft = this.scrollLeft;
doc.sel = this.sel;
doc.extend = false;
if (copyHistory) {
doc.history.undoDepth = this.history.undoDepth;
doc.setHistory(this.getHistory());
}
return doc;
},
linkedDoc: function (options) {
if (!options) {
options = {};
}
var from = this.first,
to = this.first + this.size;
if (options.from != null && options.from > from) {
from = options.from;
}
if (options.to != null && options.to < to) {
to = options.to;
}
var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);
if (options.sharedHist) {
copy.history = this.history;
}(this.linked || (this.linked = [])).push({ doc: copy, sharedHist: options.sharedHist });
copy.linked = [{ doc: this, isParent: true, sharedHist: options.sharedHist }];
copySharedMarkers(copy, findSharedMarkers(this));
return copy;
},
unlinkDoc: function (other) {
var this$1 = this;
if (other instanceof CodeMirror$1) {
other = other.doc;
}
if (this.linked) {
for (var i = 0; i < this.linked.length; ++i) {
var link = this$1.linked[i];
if (link.doc != other) {
continue;
}
this$1.linked.splice(i, 1);
other.unlinkDoc(this$1);
detachSharedMarkers(findSharedMarkers(this$1));
break;
}
}
// If the histories were shared, split them again
if (other.history == this.history) {
var splitIds = [other.id];
linkedDocs(other, function (doc) {
return splitIds.push(doc.id);
}, true);
other.history = new History(null);
other.history.done = copyHistoryArray(this.history.done, splitIds);
other.history.undone = copyHistoryArray(this.history.undone, splitIds);
}
},
iterLinkedDocs: function (f) {
linkedDocs(this, f);
},
getMode: function () {
return this.mode;
},
getEditor: function () {
return this.cm;
},
splitLines: function (str) {
if (this.lineSep) {
return str.split(this.lineSep);
}
return splitLinesAuto(str);
},
lineSeparator: function () {
return this.lineSep || "\n";
},
setDirection: docMethodOp(function (dir) {
if (dir != "rtl") {
dir = "ltr";
}
if (dir == this.direction) {
return;
}
this.direction = dir;
this.iter(function (line) {
return line.order = null;
});
if (this.cm) {
directionChanged(this.cm);
}
})
});
// Public alias.
Doc.prototype.eachLine = Doc.prototype.iter;
// Kludge to work around strange IE behavior where it'll sometimes
// re-fire a series of drag-related events right after the drop (#1551)
var lastDrop = 0;
function onDrop(e) {
var cm = this;
clearDragCursor(cm);
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) {
return;
}
e_preventDefault(e);
if (ie) {
lastDrop = +new Date();
}
var pos = posFromMouse(cm, e, true),
files = e.dataTransfer.files;
if (!pos || cm.isReadOnly()) {
return;
}
// Might be a file drop, in which case we simply extract the text
// and insert it.
if (files && files.length && window.FileReader && window.File) {
var n = files.length,
text = Array(n),
read = 0;
var loadFile = function (file, i) {
if (cm.options.allowDropFileTypes && indexOf(cm.options.allowDropFileTypes, file.type) == -1) {
return;
}
var reader = new FileReader();
reader.onload = operation(cm, function () {
var content = reader.result;
if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) {
content = "";
}
text[i] = content;
if (++read == n) {
pos = clipPos(cm.doc, pos);
var change = { from: pos, to: pos,
text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
origin: "paste" };
makeChange(cm.doc, change);
setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
}
});
reader.readAsText(file);
};
for (var i = 0; i < n; ++i) {
loadFile(files[i], i);
}
} else {
// Normal drop
// Don't do a replace if the drop happened inside of the selected text.
if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
cm.state.draggingText(e);
// Ensure the editor is re-focused
setTimeout(function () {
return cm.display.input.focus();
}, 20);
return;
}
try {
var text$1 = e.dataTransfer.getData("Text");
if (text$1) {
var selected;
if (cm.state.draggingText && !cm.state.draggingText.copy) {
selected = cm.listSelections();
}
setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
if (selected) {
for (var i$1 = 0; i$1 < selected.length; ++i$1) {
replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag");
}
}
cm.replaceSelection(text$1, "around", "paste");
cm.display.input.focus();
}
} catch (e) {}
}
}
function onDragStart(cm, e) {
if (ie && (!cm.state.draggingText || +new Date() - lastDrop < 100)) {
e_stop(e);return;
}
if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) {
return;
}
e.dataTransfer.setData("Text", cm.getSelection());
e.dataTransfer.effectAllowed = "copyMove";
// Use dummy image instead of default browsers image.
// Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
if (e.dataTransfer.setDragImage && !safari) {
var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
if (presto) {
img.width = img.height = 1;
cm.display.wrapper.appendChild(img);
// Force a relayout, or Opera won't use our image for some obscure reason
img._top = img.offsetTop;
}
e.dataTransfer.setDragImage(img, 0, 0);
if (presto) {
img.parentNode.removeChild(img);
}
}
}
function onDragOver(cm, e) {
var pos = posFromMouse(cm, e);
if (!pos) {
return;
}
var frag = document.createDocumentFragment();
drawSelectionCursor(cm, pos, frag);
if (!cm.display.dragCursor) {
cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
}
removeChildrenAndAdd(cm.display.dragCursor, frag);
}
function clearDragCursor(cm) {
if (cm.display.dragCursor) {
cm.display.lineSpace.removeChild(cm.display.dragCursor);
cm.display.dragCursor = null;
}
}
// These must be handled carefully, because naively registering a
// handler for each editor will cause the editors to never be
// garbage collected.
function forEachCodeMirror(f) {
if (!document.getElementsByClassName) {
return;
}
var byClass = document.getElementsByClassName("CodeMirror");
for (var i = 0; i < byClass.length; i++) {
var cm = byClass[i].CodeMirror;
if (cm) {
f(cm);
}
}
}
var globalsRegistered = false;
function ensureGlobalHandlers() {
if (globalsRegistered) {
return;
}
registerGlobalHandlers();
globalsRegistered = true;
}
function registerGlobalHandlers() {
// When the window resizes, we need to refresh active editors.
var resizeTimer;
on(window, "resize", function () {
if (resizeTimer == null) {
resizeTimer = setTimeout(function () {
resizeTimer = null;
forEachCodeMirror(onResize);
}, 100);
}
});
// When the window loses focus, we want to show the editor as blurred
on(window, "blur", function () {
return forEachCodeMirror(onBlur);
});
}
// Called when the window resizes
function onResize(cm) {
var d = cm.display;
if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth) {
return;
}
// Might be a text scaling operation, clear size caches.
d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
d.scrollbarsClipped = false;
cm.setSize();
}
var keyNames = {
3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete", 145: "ScrollLock",
173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
};
// Number keys
for (var i = 0; i < 10; i++) {
keyNames[i + 48] = keyNames[i + 96] = String(i);
}
// Alphabetic keys
for (var i$1 = 65; i$1 <= 90; i$1++) {
keyNames[i$1] = String.fromCharCode(i$1);
}
// Function keys
for (var i$2 = 1; i$2 <= 12; i$2++) {
keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2;
}
var keyMap = {};
keyMap.basic = {
"Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
"End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
"Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
"Tab": "defaultTab", "Shift-Tab": "indentAuto",
"Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
"Esc": "singleSelection"
};
// Note that the save and find-related commands aren't defined by
// default. User code or addons can define them. Unknown commands
// are simply ignored.
keyMap.pcDefault = {
"Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
"Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
"Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
"Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
"Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
"Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
"Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
fallthrough: "basic"
};
// Very basic readline/emacs-style bindings, which are standard on Mac.
keyMap.emacsy = {
"Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
"Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
"Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
"Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
"Ctrl-O": "openLine"
};
keyMap.macDefault = {
"Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
"Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
"Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
"Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
"Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
"Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
"Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
fallthrough: ["basic", "emacsy"]
};
keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
// KEYMAP DISPATCH
function normalizeKeyName(name) {
var parts = name.split(/-(?!$)/);
name = parts[parts.length - 1];
var alt, ctrl, shift, cmd;
for (var i = 0; i < parts.length - 1; i++) {
var mod = parts[i];
if (/^(cmd|meta|m)$/i.test(mod)) {
cmd = true;
} else if (/^a(lt)?$/i.test(mod)) {
alt = true;
} else if (/^(c|ctrl|control)$/i.test(mod)) {
ctrl = true;
} else if (/^s(hift)?$/i.test(mod)) {
shift = true;
} else {
throw new Error("Unrecognized modifier name: " + mod);
}
}
if (alt) {
name = "Alt-" + name;
}
if (ctrl) {
name = "Ctrl-" + name;
}
if (cmd) {
name = "Cmd-" + name;
}
if (shift) {
name = "Shift-" + name;
}
return name;
}
// This is a kludge to keep keymaps mostly working as raw objects
// (backwards compatibility) while at the same time support features
// like normalization and multi-stroke key bindings. It compiles a
// new normalized keymap, and then updates the old object to reflect
// this.
function normalizeKeyMap(keymap) {
var copy = {};
for (var keyname in keymap) {
if (keymap.hasOwnProperty(keyname)) {
var value = keymap[keyname];
if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) {
continue;
}
if (value == "...") {
delete keymap[keyname];continue;
}
var keys = map(keyname.split(" "), normalizeKeyName);
for (var i = 0; i < keys.length; i++) {
var val = void 0,
name = void 0;
if (i == keys.length - 1) {
name = keys.join(" ");
val = value;
} else {
name = keys.slice(0, i + 1).join(" ");
val = "...";
}
var prev = copy[name];
if (!prev) {
copy[name] = val;
} else if (prev != val) {
throw new Error("Inconsistent bindings for " + name);
}
}
delete keymap[keyname];
}
}
for (var prop in copy) {
keymap[prop] = copy[prop];
}
return keymap;
}
function lookupKey(key, map$$1, handle, context) {
map$$1 = getKeyMap(map$$1);
var found = map$$1.call ? map$$1.call(key, context) : map$$1[key];
if (found === false) {
return "nothing";
}
if (found === "...") {
return "multi";
}
if (found != null && handle(found)) {
return "handled";
}
if (map$$1.fallthrough) {
if (Object.prototype.toString.call(map$$1.fallthrough) != "[object Array]") {
return lookupKey(key, map$$1.fallthrough, handle, context);
}
for (var i = 0; i < map$$1.fallthrough.length; i++) {
var result = lookupKey(key, map$$1.fallthrough[i], handle, context);
if (result) {
return result;
}
}
}
}
// Modifier key presses don't count as 'real' key presses for the
// purpose of keymap fallthrough.
function isModifierKey(value) {
var name = typeof value == "string" ? value : keyNames[value.keyCode];
return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
}
function addModifierNames(name, event, noShift) {
var base = name;
if (event.altKey && base != "Alt") {
name = "Alt-" + name;
}
if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") {
name = "Ctrl-" + name;
}
if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") {
name = "Cmd-" + name;
}
if (!noShift && event.shiftKey && base != "Shift") {
name = "Shift-" + name;
}
return name;
}
// Look up the name of a key as indicated by an event object.
function keyName(event, noShift) {
if (presto && event.keyCode == 34 && event["char"]) {
return false;
}
var name = keyNames[event.keyCode];
if (name == null || event.altGraphKey) {
return false;
}
// Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
// so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
if (event.keyCode == 3 && event.code) {
name = event.code;
}
return addModifierNames(name, event, noShift);
}
function getKeyMap(val) {
return typeof val == "string" ? keyMap[val] : val;
}
// Helper for deleting text near the selection(s), used to implement
// backspace, delete, and similar functionality.
function deleteNearSelection(cm, compute) {
var ranges = cm.doc.sel.ranges,
kill = [];
// Build up a set of ranges to kill first, merging overlapping
// ranges.
for (var i = 0; i < ranges.length; i++) {
var toKill = compute(ranges[i]);
while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
var replaced = kill.pop();
if (cmp(replaced.from, toKill.from) < 0) {
toKill.from = replaced.from;
break;
}
}
kill.push(toKill);
}
// Next, remove those actual ranges.
runInOp(cm, function () {
for (var i = kill.length - 1; i >= 0; i--) {
replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
}
ensureCursorVisible(cm);
});
}
function moveCharLogically(line, ch, dir) {
var target = skipExtendingChars(line.text, ch + dir, dir);
return target < 0 || target > line.text.length ? null : target;
}
function moveLogically(line, start, dir) {
var ch = moveCharLogically(line, start.ch, dir);
return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before");
}
function endOfLine(visually, cm, lineObj, lineNo, dir) {
if (visually) {
var order = getOrder(lineObj, cm.doc.direction);
if (order) {
var part = dir < 0 ? lst(order) : order[0];
var moveInStorageOrder = dir < 0 == (part.level == 1);
var sticky = moveInStorageOrder ? "after" : "before";
var ch;
// With a wrapped rtl chunk (possibly spanning multiple bidi parts),
// it could be that the last bidi part is not on the last visual line,
// since visual lines contain content order-consecutive chunks.
// Thus, in rtl, we are looking for the first (content-order) character
// in the rtl chunk that is on the last line (that is, the same line
// as the last (content-order) character).
if (part.level > 0 || cm.doc.direction == "rtl") {
var prep = prepareMeasureForLine(cm, lineObj);
ch = dir < 0 ? lineObj.text.length - 1 : 0;
var targetTop = measureCharPrepared(cm, prep, ch).top;
ch = findFirst(function (ch) {
return measureCharPrepared(cm, prep, ch).top == targetTop;
}, dir < 0 == (part.level == 1) ? part.from : part.to - 1, ch);
if (sticky == "before") {
ch = moveCharLogically(lineObj, ch, 1);
}
} else {
ch = dir < 0 ? part.to : part.from;
}
return new Pos(lineNo, ch, sticky);
}
}
return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after");
}
function moveVisually(cm, line, start, dir) {
var bidi = getOrder(line, cm.doc.direction);
if (!bidi) {
return moveLogically(line, start, dir);
}
if (start.ch >= line.text.length) {
start.ch = line.text.length;
start.sticky = "before";
} else if (start.ch <= 0) {
start.ch = 0;
start.sticky = "after";
}
var partPos = getBidiPartAt(bidi, start.ch, start.sticky),
part = bidi[partPos];
if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
// Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
// nothing interesting happens.
return moveLogically(line, start, dir);
}
var mv = function (pos, dir) {
return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir);
};
var prep;
var getWrappedLineExtent = function (ch) {
if (!cm.options.lineWrapping) {
return { begin: 0, end: line.text.length };
}
prep = prep || prepareMeasureForLine(cm, line);
return wrappedLineExtentChar(cm, line, prep, ch);
};
var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch);
if (cm.doc.direction == "rtl" || part.level == 1) {
var moveInStorageOrder = part.level == 1 == dir < 0;
var ch = mv(start, moveInStorageOrder ? 1 : -1);
if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
// Case 2: We move within an rtl part or in an rtl editor on the same visual line
var sticky = moveInStorageOrder ? "before" : "after";
return new Pos(start.line, ch, sticky);
}
}
// Case 3: Could not move within this bidi part in this visual line, so leave
// the current bidi part
var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
var getRes = function (ch, moveInStorageOrder) {
return moveInStorageOrder ? new Pos(start.line, mv(ch, 1), "before") : new Pos(start.line, ch, "after");
};
for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
var part = bidi[partPos];
var moveInStorageOrder = dir > 0 == (part.level != 1);
var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1);
if (part.from <= ch && ch < part.to) {
return getRes(ch, moveInStorageOrder);
}
ch = moveInStorageOrder ? part.from : mv(part.to, -1);
if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) {
return getRes(ch, moveInStorageOrder);
}
}
};
// Case 3a: Look for other bidi parts on the same visual line
var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent);
if (res) {
return res;
}
// Case 3b: Look for other bidi parts on the next visual line
var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1);
if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));
if (res) {
return res;
}
}
// Case 4: Nowhere to move
return null;
}
// Commands are parameter-less actions that can be performed on an
// editor, mostly used for keybindings.
var commands = {
selectAll: selectAll,
singleSelection: function (cm) {
return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll);
},
killLine: function (cm) {
return deleteNearSelection(cm, function (range) {
if (range.empty()) {
var len = getLine(cm.doc, range.head.line).text.length;
if (range.head.ch == len && range.head.line < cm.lastLine()) {
return { from: range.head, to: Pos(range.head.line + 1, 0) };
} else {
return { from: range.head, to: Pos(range.head.line, len) };
}
} else {
return { from: range.from(), to: range.to() };
}
});
},
deleteLine: function (cm) {
return deleteNearSelection(cm, function (range) {
return {
from: Pos(range.from().line, 0),
to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
};
});
},
delLineLeft: function (cm) {
return deleteNearSelection(cm, function (range) {
return {
from: Pos(range.from().line, 0), to: range.from()
};
});
},
delWrappedLineLeft: function (cm) {
return deleteNearSelection(cm, function (range) {
var top = cm.charCoords(range.head, "div").top + 5;
var leftPos = cm.coordsChar({ left: 0, top: top }, "div");
return { from: leftPos, to: range.from() };
});
},
delWrappedLineRight: function (cm) {
return deleteNearSelection(cm, function (range) {
var top = cm.charCoords(range.head, "div").top + 5;
var rightPos = cm.coordsChar({ left: cm.display.lineDiv.offsetWidth + 100, top: top }, "div");
return { from: range.from(), to: rightPos };
});
},
undo: function (cm) {
return cm.undo();
},
redo: function (cm) {
return cm.redo();
},
undoSelection: function (cm) {
return cm.undoSelection();
},
redoSelection: function (cm) {
return cm.redoSelection();
},
goDocStart: function (cm) {
return cm.extendSelection(Pos(cm.firstLine(), 0));
},
goDocEnd: function (cm) {
return cm.extendSelection(Pos(cm.lastLine()));
},
goLineStart: function (cm) {
return cm.extendSelectionsBy(function (range) {
return lineStart(cm, range.head.line);
}, { origin: "+move", bias: 1 });
},
goLineStartSmart: function (cm) {
return cm.extendSelectionsBy(function (range) {
return lineStartSmart(cm, range.head);
}, { origin: "+move", bias: 1 });
},
goLineEnd: function (cm) {
return cm.extendSelectionsBy(function (range) {
return lineEnd(cm, range.head.line);
}, { origin: "+move", bias: -1 });
},
goLineRight: function (cm) {
return cm.extendSelectionsBy(function (range) {
var top = cm.cursorCoords(range.head, "div").top + 5;
return cm.coordsChar({ left: cm.display.lineDiv.offsetWidth + 100, top: top }, "div");
}, sel_move);
},
goLineLeft: function (cm) {
return cm.extendSelectionsBy(function (range) {
var top = cm.cursorCoords(range.head, "div").top + 5;
return cm.coordsChar({ left: 0, top: top }, "div");
}, sel_move);
},
goLineLeftSmart: function (cm) {
return cm.extendSelectionsBy(function (range) {
var top = cm.cursorCoords(range.head, "div").top + 5;
var pos = cm.coordsChar({ left: 0, top: top }, "div");
if (pos.ch < cm.getLine(pos.line).search(/\S/)) {
return lineStartSmart(cm, range.head);
}
return pos;
}, sel_move);
},
goLineUp: function (cm) {
return cm.moveV(-1, "line");
},
goLineDown: function (cm) {
return cm.moveV(1, "line");
},
goPageUp: function (cm) {
return cm.moveV(-1, "page");
},
goPageDown: function (cm) {
return cm.moveV(1, "page");
},
goCharLeft: function (cm) {
return cm.moveH(-1, "char");
},
goCharRight: function (cm) {
return cm.moveH(1, "char");
},
goColumnLeft: function (cm) {
return cm.moveH(-1, "column");
},
goColumnRight: function (cm) {
return cm.moveH(1, "column");
},
goWordLeft: function (cm) {
return cm.moveH(-1, "word");
},
goGroupRight: function (cm) {
return cm.moveH(1, "group");
},
goGroupLeft: function (cm) {
return cm.moveH(-1, "group");
},
goWordRight: function (cm) {
return cm.moveH(1, "word");
},
delCharBefore: function (cm) {
return cm.deleteH(-1, "char");
},
delCharAfter: function (cm) {
return cm.deleteH(1, "char");
},
delWordBefore: function (cm) {
return cm.deleteH(-1, "word");
},
delWordAfter: function (cm) {
return cm.deleteH(1, "word");
},
delGroupBefore: function (cm) {
return cm.deleteH(-1, "group");
},
delGroupAfter: function (cm) {
return cm.deleteH(1, "group");
},
indentAuto: function (cm) {
return cm.indentSelection("smart");
},
indentMore: function (cm) {
return cm.indentSelection("add");
},
indentLess: function (cm) {
return cm.indentSelection("subtract");
},
insertTab: function (cm) {
return cm.replaceSelection("\t");
},
insertSoftTab: function (cm) {
var spaces = [],
ranges = cm.listSelections(),
tabSize = cm.options.tabSize;
for (var i = 0; i < ranges.length; i++) {
var pos = ranges[i].from();
var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
spaces.push(spaceStr(tabSize - col % tabSize));
}
cm.replaceSelections(spaces);
},
defaultTab: function (cm) {
if (cm.somethingSelected()) {
cm.indentSelection("add");
} else {
cm.execCommand("insertTab");
}
},
// Swap the two chars left and right of each selection's head.
// Move cursor behind the two swapped characters afterwards.
//
// Doesn't consider line feeds a character.
// Doesn't scan more than one line above to find a character.
// Doesn't do anything on an empty line.
// Doesn't do anything with non-empty selections.
transposeChars: function (cm) {
return runInOp(cm, function () {
var ranges = cm.listSelections(),
newSel = [];
for (var i = 0; i < ranges.length; i++) {
if (!ranges[i].empty()) {
continue;
}
var cur = ranges[i].head,
line = getLine(cm.doc, cur.line).text;
if (line) {
if (cur.ch == line.length) {
cur = new Pos(cur.line, cur.ch - 1);
}
if (cur.ch > 0) {
cur = new Pos(cur.line, cur.ch + 1);
cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2), Pos(cur.line, cur.ch - 2), cur, "+transpose");
} else if (cur.line > cm.doc.first) {
var prev = getLine(cm.doc, cur.line - 1).text;
if (prev) {
cur = new Pos(cur.line, 1);
cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() + prev.charAt(prev.length - 1), Pos(cur.line - 1, prev.length - 1), cur, "+transpose");
}
}
}
newSel.push(new Range(cur, cur));
}
cm.setSelections(newSel);
});
},
newlineAndIndent: function (cm) {
return runInOp(cm, function () {
var sels = cm.listSelections();
for (var i = sels.length - 1; i >= 0; i--) {
cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input");
}
sels = cm.listSelections();
for (var i$1 = 0; i$1 < sels.length; i$1++) {
cm.indentLine(sels[i$1].from().line, null, true);
}
ensureCursorVisible(cm);
});
},
openLine: function (cm) {
return cm.replaceSelection("\n", "start");
},
toggleOverwrite: function (cm) {
return cm.toggleOverwrite();
}
};
function lineStart(cm, lineN) {
var line = getLine(cm.doc, lineN);
var visual = visualLine(line);
if (visual != line) {
lineN = lineNo(visual);
}
return endOfLine(true, cm, visual, lineN, 1);
}
function lineEnd(cm, lineN) {
var line = getLine(cm.doc, lineN);
var visual = visualLineEnd(line);
if (visual != line) {
lineN = lineNo(visual);
}
return endOfLine(true, cm, line, lineN, -1);
}
function lineStartSmart(cm, pos) {
var start = lineStart(cm, pos.line);
var line = getLine(cm.doc, start.line);
var order = getOrder(line, cm.doc.direction);
if (!order || order[0].level == 0) {
var firstNonWS = Math.max(0, line.text.search(/\S/));
var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky);
}
return start;
}
// Run a handler that was bound to a key.
function doHandleBinding(cm, bound, dropShift) {
if (typeof bound == "string") {
bound = commands[bound];
if (!bound) {
return false;
}
}
// Ensure previous input has been read, so that the handler sees a
// consistent view of the document
cm.display.input.ensurePolled();
var prevShift = cm.display.shift,
done = false;
try {
if (cm.isReadOnly()) {
cm.state.suppressEdits = true;
}
if (dropShift) {
cm.display.shift = false;
}
done = bound(cm) != Pass;
} finally {
cm.display.shift = prevShift;
cm.state.suppressEdits = false;
}
return done;
}
function lookupKeyForEditor(cm, name, handle) {
for (var i = 0; i < cm.state.keyMaps.length; i++) {
var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
if (result) {
return result;
}
}
return cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm) || lookupKey(name, cm.options.keyMap, handle, cm);
}
// Note that, despite the name, this function is also used to check
// for bound mouse clicks.
var stopSeq = new Delayed();
function dispatchKey(cm, name, e, handle) {
var seq = cm.state.keySeq;
if (seq) {
if (isModifierKey(name)) {
return "handled";
}
if (/\'$/.test(name)) {
cm.state.keySeq = null;
} else {
stopSeq.set(50, function () {
if (cm.state.keySeq == seq) {
cm.state.keySeq = null;
cm.display.input.reset();
}
});
}
if (dispatchKeyInner(cm, seq + " " + name, e, handle)) {
return true;
}
}
return dispatchKeyInner(cm, name, e, handle);
}
function dispatchKeyInner(cm, name, e, handle) {
var result = lookupKeyForEditor(cm, name, handle);
if (result == "multi") {
cm.state.keySeq = name;
}
if (result == "handled") {
signalLater(cm, "keyHandled", cm, name, e);
}
if (result == "handled" || result == "multi") {
e_preventDefault(e);
restartBlink(cm);
}
return !!result;
}
// Handle a key from the keydown event.
function handleKeyBinding(cm, e) {
var name = keyName(e, true);
if (!name) {
return false;
}
if (e.shiftKey && !cm.state.keySeq) {
// First try to resolve full name (including 'Shift-'). Failing
// that, see if there is a cursor-motion command (starting with
// 'go') bound to the keyname without 'Shift-'.
return dispatchKey(cm, "Shift-" + name, e, function (b) {
return doHandleBinding(cm, b, true);
}) || dispatchKey(cm, name, e, function (b) {
if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion) {
return doHandleBinding(cm, b);
}
});
} else {
return dispatchKey(cm, name, e, function (b) {
return doHandleBinding(cm, b);
});
}
}
// Handle a key from the keypress event
function handleCharBinding(cm, e, ch) {
return dispatchKey(cm, "'" + ch + "'", e, function (b) {
return doHandleBinding(cm, b, true);
});
}
var lastStoppedKey = null;
function onKeyDown(e) {
var cm = this;
cm.curOp.focus = activeElt();
if (signalDOMEvent(cm, e)) {
return;
}
// IE does strange things with escape.
if (ie && ie_version < 11 && e.keyCode == 27) {
e.returnValue = false;
}
var code = e.keyCode;
cm.display.shift = code == 16 || e.shiftKey;
var handled = handleKeyBinding(cm, e);
if (presto) {
lastStoppedKey = handled ? code : null;
// Opera has no cut event... we try to at least catch the key combo
if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey)) {
cm.replaceSelection("", null, "cut");
}
}
// Turn mouse into crosshair when Alt is held on Mac.
if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className)) {
showCrossHair(cm);
}
}
function showCrossHair(cm) {
var lineDiv = cm.display.lineDiv;
addClass(lineDiv, "CodeMirror-crosshair");
function up(e) {
if (e.keyCode == 18 || !e.altKey) {
rmClass(lineDiv, "CodeMirror-crosshair");
off(document, "keyup", up);
off(document, "mouseover", up);
}
}
on(document, "keyup", up);
on(document, "mouseover", up);
}
function onKeyUp(e) {
if (e.keyCode == 16) {
this.doc.sel.shift = false;
}
signalDOMEvent(this, e);
}
function onKeyPress(e) {
var cm = this;
if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) {
return;
}
var keyCode = e.keyCode,
charCode = e.charCode;
if (presto && keyCode == lastStoppedKey) {
lastStoppedKey = null;e_preventDefault(e);return;
}
if (presto && (!e.which || e.which < 10) && handleKeyBinding(cm, e)) {
return;
}
var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
// Some browsers fire keypress events for backspace
if (ch == "\x08") {
return;
}
if (handleCharBinding(cm, e, ch)) {
return;
}
cm.display.input.onKeyPress(e);
}
var DOUBLECLICK_DELAY = 400;
var PastClick = function (time, pos, button) {
this.time = time;
this.pos = pos;
this.button = button;
};
PastClick.prototype.compare = function (time, pos, button) {
return this.time + DOUBLECLICK_DELAY > time && cmp(pos, this.pos) == 0 && button == this.button;
};
var lastClick;
var lastDoubleClick;
function clickRepeat(pos, button) {
var now = +new Date();
if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
lastClick = lastDoubleClick = null;
return "triple";
} else if (lastClick && lastClick.compare(now, pos, button)) {
lastDoubleClick = new PastClick(now, pos, button);
lastClick = null;
return "double";
} else {
lastClick = new PastClick(now, pos, button);
lastDoubleClick = null;
return "single";
}
}
// A mouse down can be a single click, double click, triple click,
// start of selection drag, start of text drag, new cursor
// (ctrl-click), rectangle drag (alt-drag), or xwin
// middle-click-paste. Or it might be a click on something we should
// not interfere with, such as a scrollbar or widget.
function onMouseDown(e) {
var cm = this,
display = cm.display;
if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) {
return;
}
display.input.ensurePolled();
display.shift = e.shiftKey;
if (eventInWidget(display, e)) {
if (!webkit) {
// Briefly turn off draggability, to allow widgets to do
// normal dragging things.
display.scroller.draggable = false;
setTimeout(function () {
return display.scroller.draggable = true;
}, 100);
}
return;
}
if (clickInGutter(cm, e)) {
return;
}
var pos = posFromMouse(cm, e),
button = e_button(e),
repeat = pos ? clickRepeat(pos, button) : "single";
window.focus();
// #3261: make sure, that we're not starting a second selection
if (button == 1 && cm.state.selectingText) {
cm.state.selectingText(e);
}
if (pos && handleMappedButton(cm, button, pos, repeat, e)) {
return;
}
if (button == 1) {
if (pos) {
leftButtonDown(cm, pos, repeat, e);
} else if (e_target(e) == display.scroller) {
e_preventDefault(e);
}
} else if (button == 2) {
if (pos) {
extendSelection(cm.doc, pos);
}
setTimeout(function () {
return display.input.focus();
}, 20);
} else if (button == 3) {
if (captureRightClick) {
onContextMenu(cm, e);
} else {
delayBlurEvent(cm);
}
}
}
function handleMappedButton(cm, button, pos, repeat, event) {
var name = "Click";
if (repeat == "double") {
name = "Double" + name;
} else if (repeat == "triple") {
name = "Triple" + name;
}
name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name;
return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {
if (typeof bound == "string") {
bound = commands[bound];
}
if (!bound) {
return false;
}
var done = false;
try {
if (cm.isReadOnly()) {
cm.state.suppressEdits = true;
}
done = bound(cm, pos) != Pass;
} finally {
cm.state.suppressEdits = false;
}
return done;
});
}
function configureMouse(cm, repeat, event) {
var option = cm.getOption("configureMouse");
var value = option ? option(cm, repeat, event) : {};
if (value.unit == null) {
var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey;
value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line";
}
if (value.extend == null || cm.doc.extend) {
value.extend = cm.doc.extend || event.shiftKey;
}
if (value.addNew == null) {
value.addNew = mac ? event.metaKey : event.ctrlKey;
}
if (value.moveOnDrag == null) {
value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey);
}
return value;
}
function leftButtonDown(cm, pos, repeat, event) {
if (ie) {
setTimeout(bind(ensureFocus, cm), 0);
} else {
cm.curOp.focus = activeElt();
}
var behavior = configureMouse(cm, repeat, event);
var sel = cm.doc.sel,
contained;
if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() && repeat == "single" && (contained = sel.contains(pos)) > -1 && (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) && (cmp(contained.to(), pos) > 0 || pos.xRel < 0)) {
leftButtonStartDrag(cm, event, pos, behavior);
} else {
leftButtonSelect(cm, event, pos, behavior);
}
}
// Start a text drag. When it ends, see if any dragging actually
// happen, and treat as a click if it didn't.
function leftButtonStartDrag(cm, event, pos, behavior) {
var display = cm.display,
moved = false;
var dragEnd = operation(cm, function (e) {
if (webkit) {
display.scroller.draggable = false;
}
cm.state.draggingText = false;
off(display.wrapper.ownerDocument, "mouseup", dragEnd);
off(display.wrapper.ownerDocument, "mousemove", mouseMove);
off(display.scroller, "dragstart", dragStart);
off(display.scroller, "drop", dragEnd);
if (!moved) {
e_preventDefault(e);
if (!behavior.addNew) {
extendSelection(cm.doc, pos, null, null, behavior.extend);
}
// Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
if (webkit || ie && ie_version == 9) {
setTimeout(function () {
display.wrapper.ownerDocument.body.focus();display.input.focus();
}, 20);
} else {
display.input.focus();
}
}
});
var mouseMove = function (e2) {
moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10;
};
var dragStart = function () {
return moved = true;
};
// Let the drag handler handle this.
if (webkit) {
display.scroller.draggable = true;
}
cm.state.draggingText = dragEnd;
dragEnd.copy = !behavior.moveOnDrag;
// IE's approach to draggable
if (display.scroller.dragDrop) {
display.scroller.dragDrop();
}
on(display.wrapper.ownerDocument, "mouseup", dragEnd);
on(display.wrapper.ownerDocument, "mousemove", mouseMove);
on(display.scroller, "dragstart", dragStart);
on(display.scroller, "drop", dragEnd);
delayBlurEvent(cm);
setTimeout(function () {
return display.input.focus();
}, 20);
}
function rangeForUnit(cm, pos, unit) {
if (unit == "char") {
return new Range(pos, pos);
}
if (unit == "word") {
return cm.findWordAt(pos);
}
if (unit == "line") {
return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)));
}
var result = unit(cm, pos);
return new Range(result.from, result.to);
}
// Normal selection, as opposed to text dragging.
function leftButtonSelect(cm, event, start, behavior) {
var display = cm.display,
doc = cm.doc;
e_preventDefault(event);
var ourRange,
ourIndex,
startSel = doc.sel,
ranges = startSel.ranges;
if (behavior.addNew && !behavior.extend) {
ourIndex = doc.sel.contains(start);
if (ourIndex > -1) {
ourRange = ranges[ourIndex];
} else {
ourRange = new Range(start, start);
}
} else {
ourRange = doc.sel.primary();
ourIndex = doc.sel.primIndex;
}
if (behavior.unit == "rectangle") {
if (!behavior.addNew) {
ourRange = new Range(start, start);
}
start = posFromMouse(cm, event, true, true);
ourIndex = -1;
} else {
var range$$1 = rangeForUnit(cm, start, behavior.unit);
if (behavior.extend) {
ourRange = extendRange(ourRange, range$$1.anchor, range$$1.head, behavior.extend);
} else {
ourRange = range$$1;
}
}
if (!behavior.addNew) {
ourIndex = 0;
setSelection(doc, new Selection([ourRange], 0), sel_mouse);
startSel = doc.sel;
} else if (ourIndex == -1) {
ourIndex = ranges.length;
setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex), { scroll: false, origin: "*mouse" });
} else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), { scroll: false, origin: "*mouse" });
startSel = doc.sel;
} else {
replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
}
var lastPos = start;
function extendTo(pos) {
if (cmp(lastPos, pos) == 0) {
return;
}
lastPos = pos;
if (behavior.unit == "rectangle") {
var ranges = [],
tabSize = cm.options.tabSize;
var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
var left = Math.min(startCol, posCol),
right = Math.max(startCol, posCol);
for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); line <= end; line++) {
var text = getLine(doc, line).text,
leftPos = findColumn(text, left, tabSize);
if (left == right) {
ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
} else if (text.length > leftPos) {
ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
}
}
if (!ranges.length) {
ranges.push(new Range(start, start));
}
setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), { origin: "*mouse", scroll: false });
cm.scrollIntoView(pos);
} else {
var oldRange = ourRange;
var range$$1 = rangeForUnit(cm, pos, behavior.unit);
var anchor = oldRange.anchor,
head;
if (cmp(range$$1.anchor, anchor) > 0) {
head = range$$1.head;
anchor = minPos(oldRange.from(), range$$1.anchor);
} else {
head = range$$1.anchor;
anchor = maxPos(oldRange.to(), range$$1.head);
}
var ranges$1 = startSel.ranges.slice(0);
ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head));
setSelection(doc, normalizeSelection(ranges$1, ourIndex), sel_mouse);
}
}
var editorSize = display.wrapper.getBoundingClientRect();
// Used to ensure timeout re-tries don't fire when another extend
// happened in the meantime (clearTimeout isn't reliable -- at
// least on Chrome, the timeouts still happen even when cleared,
// if the clear happens after their scheduled firing time).
var counter = 0;
function extend(e) {
var curCount = ++counter;
var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
if (!cur) {
return;
}
if (cmp(cur, lastPos) != 0) {
cm.curOp.focus = activeElt();
extendTo(cur);
var visible = visibleLines(display, doc);
if (cur.line >= visible.to || cur.line < visible.from) {
setTimeout(operation(cm, function () {
if (counter == curCount) {
extend(e);
}
}), 150);
}
} else {
var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
if (outside) {
setTimeout(operation(cm, function () {
if (counter != curCount) {
return;
}
display.scroller.scrollTop += outside;
extend(e);
}), 50);
}
}
}
function done(e) {
cm.state.selectingText = false;
counter = Infinity;
e_preventDefault(e);
display.input.focus();
off(display.wrapper.ownerDocument, "mousemove", move);
off(display.wrapper.ownerDocument, "mouseup", up);
doc.history.lastSelOrigin = null;
}
var move = operation(cm, function (e) {
if (e.buttons === 0 || !e_button(e)) {
done(e);
} else {
extend(e);
}
});
var up = operation(cm, done);
cm.state.selectingText = up;
on(display.wrapper.ownerDocument, "mousemove", move);
on(display.wrapper.ownerDocument, "mouseup", up);
}
// Used when mouse-selecting to adjust the anchor to the proper side
// of a bidi jump depending on the visual position of the head.
function bidiSimplify(cm, range$$1) {
var anchor = range$$1.anchor;
var head = range$$1.head;
var anchorLine = getLine(cm.doc, anchor.line);
if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) {
return range$$1;
}
var order = getOrder(anchorLine);
if (!order) {
return range$$1;
}
var index = getBidiPartAt(order, anchor.ch, anchor.sticky),
part = order[index];
if (part.from != anchor.ch && part.to != anchor.ch) {
return range$$1;
}
var boundary = index + (part.from == anchor.ch == (part.level != 1) ? 0 : 1);
if (boundary == 0 || boundary == order.length) {
return range$$1;
}
// Compute the relative visual position of the head compared to the
// anchor (<0 is to the left, >0 to the right)
var leftSide;
if (head.line != anchor.line) {
leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0;
} else {
var headIndex = getBidiPartAt(order, head.ch, head.sticky);
var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);
if (headIndex == boundary - 1 || headIndex == boundary) {
leftSide = dir < 0;
} else {
leftSide = dir > 0;
}
}
var usePart = order[boundary + (leftSide ? -1 : 0)];
var from = leftSide == (usePart.level == 1);
var ch = from ? usePart.from : usePart.to,
sticky = from ? "after" : "before";
return anchor.ch == ch && anchor.sticky == sticky ? range$$1 : new Range(new Pos(anchor.line, ch, sticky), head);
}
// Determines whether an event happened in the gutter, and fires the
// handlers for the corresponding event.
function gutterEvent(cm, e, type, prevent) {
var mX, mY;
if (e.touches) {
mX = e.touches[0].clientX;
mY = e.touches[0].clientY;
} else {
try {
mX = e.clientX;mY = e.clientY;
} catch (e) {
return false;
}
}
if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) {
return false;
}
if (prevent) {
e_preventDefault(e);
}
var display = cm.display;
var lineBox = display.lineDiv.getBoundingClientRect();
if (mY > lineBox.bottom || !hasHandler(cm, type)) {
return e_defaultPrevented(e);
}
mY -= lineBox.top - display.viewOffset;
for (var i = 0; i < cm.options.gutters.length; ++i) {
var g = display.gutters.childNodes[i];
if (g && g.getBoundingClientRect().right >= mX) {
var line = lineAtHeight(cm.doc, mY);
var gutter = cm.options.gutters[i];
signal(cm, type, cm, line, gutter, e);
return e_defaultPrevented(e);
}
}
}
function clickInGutter(cm, e) {
return gutterEvent(cm, e, "gutterClick", true);
}
// CONTEXT MENU HANDLING
// To make the context menu work, we need to briefly unhide the
// textarea (making it as unobtrusive as possible) to let the
// right-click take effect on it.
function onContextMenu(cm, e) {
if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) {
return;
}
if (signalDOMEvent(cm, e, "contextmenu")) {
return;
}
cm.display.input.onContextMenu(e);
}
function contextMenuInGutter(cm, e) {
if (!hasHandler(cm, "gutterContextMenu")) {
return false;
}
return gutterEvent(cm, e, "gutterContextMenu", false);
}
function themeChanged(cm) {
cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") + cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
clearCaches(cm);
}
var Init = { toString: function () {
return "CodeMirror.Init";
} };
var defaults = {};
var optionHandlers = {};
function defineOptions(CodeMirror) {
var optionHandlers = CodeMirror.optionHandlers;
function option(name, deflt, handle, notOnInit) {
CodeMirror.defaults[name] = deflt;
if (handle) {
optionHandlers[name] = notOnInit ? function (cm, val, old) {
if (old != Init) {
handle(cm, val, old);
}
} : handle;
}
}
CodeMirror.defineOption = option;
// Passed to option handlers when there is no old value.
CodeMirror.Init = Init;
// These two are, on init, called from the constructor because they
// have to be initialized before the editor can start at all.
option("value", "", function (cm, val) {
return cm.setValue(val);
}, true);
option("mode", null, function (cm, val) {
cm.doc.modeOption = val;
loadMode(cm);
}, true);
option("indentUnit", 2, loadMode, true);
option("indentWithTabs", false);
option("smartIndent", true);
option("tabSize", 4, function (cm) {
resetModeState(cm);
clearCaches(cm);
regChange(cm);
}, true);
option("lineSeparator", null, function (cm, val) {
cm.doc.lineSep = val;
if (!val) {
return;
}
var newBreaks = [],
lineNo = cm.doc.first;
cm.doc.iter(function (line) {
for (var pos = 0;;) {
var found = line.text.indexOf(val, pos);
if (found == -1) {
break;
}
pos = found + val.length;
newBreaks.push(Pos(lineNo, found));
}
lineNo++;
});
for (var i = newBreaks.length - 1; i >= 0; i--) {
replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length));
}
});
option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g, function (cm, val, old) {
cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
if (old != Init) {
cm.refresh();
}
});
option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) {
return cm.refresh();
}, true);
option("electricChars", true);
option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
throw new Error("inputStyle can not (yet) be changed in a running editor"); // FIXME
}, true);
option("spellcheck", false, function (cm, val) {
return cm.getInputField().spellcheck = val;
}, true);
option("rtlMoveVisually", !windows);
option("wholeLineUpdateBefore", true);
option("theme", "default", function (cm) {
themeChanged(cm);
guttersChanged(cm);
}, true);
option("keyMap", "default", function (cm, val, old) {
var next = getKeyMap(val);
var prev = old != Init && getKeyMap(old);
if (prev && prev.detach) {
prev.detach(cm, next);
}
if (next.attach) {
next.attach(cm, prev || null);
}
});
option("extraKeys", null);
option("configureMouse", null);
option("lineWrapping", false, wrappingChanged, true);
option("gutters", [], function (cm) {
setGuttersForLineNumbers(cm.options);
guttersChanged(cm);
}, true);
option("fixedGutter", true, function (cm, val) {
cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
cm.refresh();
}, true);
option("coverGutterNextToScrollbar", false, function (cm) {
return updateScrollbars(cm);
}, true);
option("scrollbarStyle", "native", function (cm) {
initScrollbars(cm);
updateScrollbars(cm);
cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
}, true);
option("lineNumbers", false, function (cm) {
setGuttersForLineNumbers(cm.options);
guttersChanged(cm);
}, true);
option("firstLineNumber", 1, guttersChanged, true);
option("lineNumberFormatter", function (integer) {
return integer;
}, guttersChanged, true);
option("showCursorWhenSelecting", false, updateSelection, true);
option("resetSelectionOnContextMenu", true);
option("lineWiseCopyCut", true);
option("pasteLinesPerSelection", true);
option("readOnly", false, function (cm, val) {
if (val == "nocursor") {
onBlur(cm);
cm.display.input.blur();
}
cm.display.input.readOnlyChanged(val);
});
option("disableInput", false, function (cm, val) {
if (!val) {
cm.display.input.reset();
}
}, true);
option("dragDrop", true, dragDropChanged);
option("allowDropFileTypes", null);
option("cursorBlinkRate", 530);
option("cursorScrollMargin", 0);
option("cursorHeight", 1, updateSelection, true);
option("singleCursorHeightPerLine", true, updateSelection, true);
option("workTime", 100);
option("workDelay", 100);
option("flattenSpans", true, resetModeState, true);
option("addModeClass", false, resetModeState, true);
option("pollInterval", 100);
option("undoDepth", 200, function (cm, val) {
return cm.doc.history.undoDepth = val;
});
option("historyEventDelay", 1250);
option("viewportMargin", 10, function (cm) {
return cm.refresh();
}, true);
option("maxHighlightLength", 10000, resetModeState, true);
option("moveInputWithCursor", true, function (cm, val) {
if (!val) {
cm.display.input.resetPosition();
}
});
option("tabindex", null, function (cm, val) {
return cm.display.input.getField().tabIndex = val || "";
});
option("autofocus", null);
option("direction", "ltr", function (cm, val) {
return cm.doc.setDirection(val);
}, true);
}
function guttersChanged(cm) {
updateGutters(cm);
regChange(cm);
alignHorizontally(cm);
}
function dragDropChanged(cm, value, old) {
var wasOn = old && old != Init;
if (!value != !wasOn) {
var funcs = cm.display.dragFunctions;
var toggle = value ? on : off;
toggle(cm.display.scroller, "dragstart", funcs.start);
toggle(cm.display.scroller, "dragenter", funcs.enter);
toggle(cm.display.scroller, "dragover", funcs.over);
toggle(cm.display.scroller, "dragleave", funcs.leave);
toggle(cm.display.scroller, "drop", funcs.drop);
}
}
function wrappingChanged(cm) {
if (cm.options.lineWrapping) {
addClass(cm.display.wrapper, "CodeMirror-wrap");
cm.display.sizer.style.minWidth = "";
cm.display.sizerWidth = null;
} else {
rmClass(cm.display.wrapper, "CodeMirror-wrap");
findMaxLine(cm);
}
estimateLineHeights(cm);
regChange(cm);
clearCaches(cm);
setTimeout(function () {
return updateScrollbars(cm);
}, 100);
}
// A CodeMirror instance represents an editor. This is the object
// that user code is usually dealing with.
function CodeMirror$1(place, options) {
var this$1 = this;
if (!(this instanceof CodeMirror$1)) {
return new CodeMirror$1(place, options);
}
this.options = options = options ? copyObj(options) : {};
// Determine effective options based on given values and defaults.
copyObj(defaults, options, false);
setGuttersForLineNumbers(options);
var doc = options.value;
if (typeof doc == "string") {
doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction);
}
this.doc = doc;
var input = new CodeMirror$1.inputStyles[options.inputStyle](this);
var display = this.display = new Display(place, doc, input);
display.wrapper.CodeMirror = this;
updateGutters(this);
themeChanged(this);
if (options.lineWrapping) {
this.display.wrapper.className += " CodeMirror-wrap";
}
initScrollbars(this);
this.state = {
keyMaps: [], // stores maps added by addKeyMap
overlays: [], // highlighting overlays, as added by addOverlay
modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
overwrite: false,
delayingBlurEvent: false,
focused: false,
suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
selectingText: false,
draggingText: false,
highlight: new Delayed(), // stores highlight worker timeout
keySeq: null, // Unfinished key sequence
specialChars: null
};
if (options.autofocus && !mobile) {
display.input.focus();
}
// Override magic textarea content restore that IE sometimes does
// on our hidden textarea on reload
if (ie && ie_version < 11) {
setTimeout(function () {
return this$1.display.input.reset(true);
}, 20);
}
registerEventHandlers(this);
ensureGlobalHandlers();
startOperation(this);
this.curOp.forceUpdate = true;
attachDoc(this, doc);
if (options.autofocus && !mobile || this.hasFocus()) {
setTimeout(bind(onFocus, this), 20);
} else {
onBlur(this);
}
for (var opt in optionHandlers) {
if (optionHandlers.hasOwnProperty(opt)) {
optionHandlers[opt](this$1, options[opt], Init);
}
}
maybeUpdateLineNumberWidth(this);
if (options.finishInit) {
options.finishInit(this);
}
for (var i = 0; i < initHooks.length; ++i) {
initHooks[i](this$1);
}
endOperation(this);
// Suppress optimizelegibility in Webkit, since it breaks text
// measuring on line wrapping boundaries.
if (webkit && options.lineWrapping && getComputedStyle(display.lineDiv).textRendering == "optimizelegibility") {
display.lineDiv.style.textRendering = "auto";
}
}
// The default configuration options.
CodeMirror$1.defaults = defaults;
// Functions to run when options are changed.
CodeMirror$1.optionHandlers = optionHandlers;
// Attach the necessary event handlers when initializing the editor
function registerEventHandlers(cm) {
var d = cm.display;
on(d.scroller, "mousedown", operation(cm, onMouseDown));
// Older IE's will not fire a second mousedown for a double click
if (ie && ie_version < 11) {
on(d.scroller, "dblclick", operation(cm, function (e) {
if (signalDOMEvent(cm, e)) {
return;
}
var pos = posFromMouse(cm, e);
if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) {
return;
}
e_preventDefault(e);
var word = cm.findWordAt(pos);
extendSelection(cm.doc, word.anchor, word.head);
}));
} else {
on(d.scroller, "dblclick", function (e) {
return signalDOMEvent(cm, e) || e_preventDefault(e);
});
}
// Some browsers fire contextmenu *after* opening the menu, at
// which point we can't mess with it anymore. Context menu is
// handled in onMouseDown for these browsers.
if (!captureRightClick) {
on(d.scroller, "contextmenu", function (e) {
return onContextMenu(cm, e);
});
}
// Used to suppress mouse event handling when a touch happens
var touchFinished,
prevTouch = { end: 0 };
function finishTouch() {
if (d.activeTouch) {
touchFinished = setTimeout(function () {
return d.activeTouch = null;
}, 1000);
prevTouch = d.activeTouch;
prevTouch.end = +new Date();
}
}
function isMouseLikeTouchEvent(e) {
if (e.touches.length != 1) {
return false;
}
var touch = e.touches[0];
return touch.radiusX <= 1 && touch.radiusY <= 1;
}
function farAway(touch, other) {
if (other.left == null) {
return true;
}
var dx = other.left - touch.left,
dy = other.top - touch.top;
return dx * dx + dy * dy > 20 * 20;
}
on(d.scroller, "touchstart", function (e) {
if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
d.input.ensurePolled();
clearTimeout(touchFinished);
var now = +new Date();
d.activeTouch = { start: now, moved: false,
prev: now - prevTouch.end <= 300 ? prevTouch : null };
if (e.touches.length == 1) {
d.activeTouch.left = e.touches[0].pageX;
d.activeTouch.top = e.touches[0].pageY;
}
}
});
on(d.scroller, "touchmove", function () {
if (d.activeTouch) {
d.activeTouch.moved = true;
}
});
on(d.scroller, "touchend", function (e) {
var touch = d.activeTouch;
if (touch && !eventInWidget(d, e) && touch.left != null && !touch.moved && new Date() - touch.start < 300) {
var pos = cm.coordsChar(d.activeTouch, "page"),
range;
if (!touch.prev || farAway(touch, touch.prev)) // Single tap
{
range = new Range(pos, pos);
} else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
{
range = cm.findWordAt(pos);
} else // Triple tap
{
range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)));
}
cm.setSelection(range.anchor, range.head);
cm.focus();
e_preventDefault(e);
}
finishTouch();
});
on(d.scroller, "touchcancel", finishTouch);
// Sync scrolling between fake scrollbars and real scrollable
// area, ensure viewport is updated when scrolling.
on(d.scroller, "scroll", function () {
if (d.scroller.clientHeight) {
updateScrollTop(cm, d.scroller.scrollTop);
setScrollLeft(cm, d.scroller.scrollLeft, true);
signal(cm, "scroll", cm);
}
});
// Listen to wheel events in order to try and update the viewport on time.
on(d.scroller, "mousewheel", function (e) {
return onScrollWheel(cm, e);
});
on(d.scroller, "DOMMouseScroll", function (e) {
return onScrollWheel(cm, e);
});
// Prevent wrapper from ever scrolling
on(d.wrapper, "scroll", function () {
return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0;
});
d.dragFunctions = {
enter: function (e) {
if (!signalDOMEvent(cm, e)) {
e_stop(e);
}
},
over: function (e) {
if (!signalDOMEvent(cm, e)) {
onDragOver(cm, e);e_stop(e);
}
},
start: function (e) {
return onDragStart(cm, e);
},
drop: operation(cm, onDrop),
leave: function (e) {
if (!signalDOMEvent(cm, e)) {
clearDragCursor(cm);
}
}
};
var inp = d.input.getField();
on(inp, "keyup", function (e) {
return onKeyUp.call(cm, e);
});
on(inp, "keydown", operation(cm, onKeyDown));
on(inp, "keypress", operation(cm, onKeyPress));
on(inp, "focus", function (e) {
return onFocus(cm, e);
});
on(inp, "blur", function (e) {
return onBlur(cm, e);
});
}
var initHooks = [];
CodeMirror$1.defineInitHook = function (f) {
return initHooks.push(f);
};
// Indent the given line. The how parameter can be "smart",
// "add"/null, "subtract", or "prev". When aggressive is false
// (typically set to true for forced single-line indents), empty
// lines are not indented, and places where the mode returns Pass
// are left alone.
function indentLine(cm, n, how, aggressive) {
var doc = cm.doc,
state;
if (how == null) {
how = "add";
}
if (how == "smart") {
// Fall back to "prev" when the mode doesn't have an indentation
// method.
if (!doc.mode.indent) {
how = "prev";
} else {
state = getContextBefore(cm, n).state;
}
}
var tabSize = cm.options.tabSize;
var line = getLine(doc, n),
curSpace = countColumn(line.text, null, tabSize);
if (line.stateAfter) {
line.stateAfter = null;
}
var curSpaceString = line.text.match(/^\s*/)[0],
indentation;
if (!aggressive && !/\S/.test(line.text)) {
indentation = 0;
how = "not";
} else if (how == "smart") {
indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
if (indentation == Pass || indentation > 150) {
if (!aggressive) {
return;
}
how = "prev";
}
}
if (how == "prev") {
if (n > doc.first) {
indentation = countColumn(getLine(doc, n - 1).text, null, tabSize);
} else {
indentation = 0;
}
} else if (how == "add") {
indentation = curSpace + cm.options.indentUnit;
} else if (how == "subtract") {
indentation = curSpace - cm.options.indentUnit;
} else if (typeof how == "number") {
indentation = curSpace + how;
}
indentation = Math.max(0, indentation);
var indentString = "",
pos = 0;
if (cm.options.indentWithTabs) {
for (var i = Math.floor(indentation / tabSize); i; --i) {
pos += tabSize;indentString += "\t";
}
}
if (pos < indentation) {
indentString += spaceStr(indentation - pos);
}
if (indentString != curSpaceString) {
replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
line.stateAfter = null;
return true;
} else {
// Ensure that, if the cursor was in the whitespace at the start
// of the line, it is moved to the end of that space.
for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
var range = doc.sel.ranges[i$1];
if (range.head.line == n && range.head.ch < curSpaceString.length) {
var pos$1 = Pos(n, curSpaceString.length);
replaceOneSelection(doc, i$1, new Range(pos$1, pos$1));
break;
}
}
}
}
// This will be set to a {lineWise: bool, text: [string]} object, so
// that, when pasting, we know what kind of selections the copied
// text was made out of.
var lastCopied = null;
function setLastCopied(newLastCopied) {
lastCopied = newLastCopied;
}
function applyTextInput(cm, inserted, deleted, sel, origin) {
var doc = cm.doc;
cm.display.shift = false;
if (!sel) {
sel = doc.sel;
}
var paste = cm.state.pasteIncoming || origin == "paste";
var textLines = splitLinesAuto(inserted),
multiPaste = null;
// When pasting N lines into N selections, insert one line per selection
if (paste && sel.ranges.length > 1) {
if (lastCopied && lastCopied.text.join("\n") == inserted) {
if (sel.ranges.length % lastCopied.text.length == 0) {
multiPaste = [];
for (var i = 0; i < lastCopied.text.length; i++) {
multiPaste.push(doc.splitLines(lastCopied.text[i]));
}
}
} else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
multiPaste = map(textLines, function (l) {
return [l];
});
}
}
var updateInput;
// Normal behavior is to insert the new text into every selection
for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
var range$$1 = sel.ranges[i$1];
var from = range$$1.from(),
to = range$$1.to();
if (range$$1.empty()) {
if (deleted && deleted > 0) // Handle deletion
{
from = Pos(from.line, from.ch - deleted);
} else if (cm.state.overwrite && !paste) // Handle overwrite
{
to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
} else if (lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted) {
from = to = Pos(from.line, 0);
}
}
updateInput = cm.curOp.updateInput;
var changeEvent = { from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input") };
makeChange(cm.doc, changeEvent);
signalLater(cm, "inputRead", cm, changeEvent);
}
if (inserted && !paste) {
triggerElectric(cm, inserted);
}
ensureCursorVisible(cm);
cm.curOp.updateInput = updateInput;
cm.curOp.typing = true;
cm.state.pasteIncoming = cm.state.cutIncoming = false;
}
function handlePaste(e, cm) {
var pasted = e.clipboardData && e.clipboardData.getData("Text");
if (pasted) {
e.preventDefault();
if (!cm.isReadOnly() && !cm.options.disableInput) {
runInOp(cm, function () {
return applyTextInput(cm, pasted, 0, null, "paste");
});
}
return true;
}
}
function triggerElectric(cm, inserted) {
// When an 'electric' character is inserted, immediately trigger a reindent
if (!cm.options.electricChars || !cm.options.smartIndent) {
return;
}
var sel = cm.doc.sel;
for (var i = sel.ranges.length - 1; i >= 0; i--) {
var range$$1 = sel.ranges[i];
if (range$$1.head.ch > 100 || i && sel.ranges[i - 1].head.line == range$$1.head.line) {
continue;
}
var mode = cm.getModeAt(range$$1.head);
var indented = false;
if (mode.electricChars) {
for (var j = 0; j < mode.electricChars.length; j++) {
if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
indented = indentLine(cm, range$$1.head.line, "smart");
break;
}
}
} else if (mode.electricInput) {
if (mode.electricInput.test(getLine(cm.doc, range$$1.head.line).text.slice(0, range$$1.head.ch))) {
indented = indentLine(cm, range$$1.head.line, "smart");
}
}
if (indented) {
signalLater(cm, "electricInput", cm, range$$1.head.line);
}
}
}
function copyableRanges(cm) {
var text = [],
ranges = [];
for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
var line = cm.doc.sel.ranges[i].head.line;
var lineRange = { anchor: Pos(line, 0), head: Pos(line + 1, 0) };
ranges.push(lineRange);
text.push(cm.getRange(lineRange.anchor, lineRange.head));
}
return { text: text, ranges: ranges };
}
function disableBrowserMagic(field, spellcheck) {
field.setAttribute("autocorrect", "off");
field.setAttribute("autocapitalize", "off");
field.setAttribute("spellcheck", !!spellcheck);
}
function hiddenTextarea() {
var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none");
var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
// The textarea is kept positioned near the cursor to prevent the
// fact that it'll be scrolled into view on input from scrolling
// our fake cursor out of view. On webkit, when wrap=off, paste is
// very slow. So make the area wide instead.
if (webkit) {
te.style.width = "1000px";
} else {
te.setAttribute("wrap", "off");
}
// If border: 0; -- iOS fails to open keyboard (issue #1287)
if (ios) {
te.style.border = "1px solid black";
}
disableBrowserMagic(te);
return div;
}
// The publicly visible API. Note that methodOp(f) means
// 'wrap f in an operation, performed on its `this` parameter'.
// This is not the complete set of editor methods. Most of the
// methods defined on the Doc type are also injected into
// CodeMirror.prototype, for backwards compatibility and
// convenience.
var addEditorMethods = function (CodeMirror) {
var optionHandlers = CodeMirror.optionHandlers;
var helpers = CodeMirror.helpers = {};
CodeMirror.prototype = {
constructor: CodeMirror,
focus: function () {
window.focus();this.display.input.focus();
},
setOption: function (option, value) {
var options = this.options,
old = options[option];
if (options[option] == value && option != "mode") {
return;
}
options[option] = value;
if (optionHandlers.hasOwnProperty(option)) {
operation(this, optionHandlers[option])(this, value, old);
}
signal(this, "optionChange", this, option);
},
getOption: function (option) {
return this.options[option];
},
getDoc: function () {
return this.doc;
},
addKeyMap: function (map$$1, bottom) {
this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map$$1));
},
removeKeyMap: function (map$$1) {
var maps = this.state.keyMaps;
for (var i = 0; i < maps.length; ++i) {
if (maps[i] == map$$1 || maps[i].name == map$$1) {
maps.splice(i, 1);
return true;
}
}
},
addOverlay: methodOp(function (spec, options) {
var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
if (mode.startState) {
throw new Error("Overlays may not be stateful.");
}
insertSorted(this.state.overlays, { mode: mode, modeSpec: spec, opaque: options && options.opaque,
priority: options && options.priority || 0 }, function (overlay) {
return overlay.priority;
});
this.state.modeGen++;
regChange(this);
}),
removeOverlay: methodOp(function (spec) {
var this$1 = this;
var overlays = this.state.overlays;
for (var i = 0; i < overlays.length; ++i) {
var cur = overlays[i].modeSpec;
if (cur == spec || typeof spec == "string" && cur.name == spec) {
overlays.splice(i, 1);
this$1.state.modeGen++;
regChange(this$1);
return;
}
}
}),
indentLine: methodOp(function (n, dir, aggressive) {
if (typeof dir != "string" && typeof dir != "number") {
if (dir == null) {
dir = this.options.smartIndent ? "smart" : "prev";
} else {
dir = dir ? "add" : "subtract";
}
}
if (isLine(this.doc, n)) {
indentLine(this, n, dir, aggressive);
}
}),
indentSelection: methodOp(function (how) {
var this$1 = this;
var ranges = this.doc.sel.ranges,
end = -1;
for (var i = 0; i < ranges.length; i++) {
var range$$1 = ranges[i];
if (!range$$1.empty()) {
var from = range$$1.from(),
to = range$$1.to();
var start = Math.max(end, from.line);
end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
for (var j = start; j < end; ++j) {
indentLine(this$1, j, how);
}
var newRanges = this$1.doc.sel.ranges;
if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0) {
replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll);
}
} else if (range$$1.head.line > end) {
indentLine(this$1, range$$1.head.line, how, true);
end = range$$1.head.line;
if (i == this$1.doc.sel.primIndex) {
ensureCursorVisible(this$1);
}
}
}
}),
// Fetch the parser token for a given character. Useful for hacks
// that want to inspect the mode state (say, for completion).
getTokenAt: function (pos, precise) {
return takeToken(this, pos, precise);
},
getLineTokens: function (line, precise) {
return takeToken(this, Pos(line), precise, true);
},
getTokenTypeAt: function (pos) {
pos = clipPos(this.doc, pos);
var styles = getLineStyles(this, getLine(this.doc, pos.line));
var before = 0,
after = (styles.length - 1) / 2,
ch = pos.ch;
var type;
if (ch == 0) {
type = styles[2];
} else {
for (;;) {
var mid = before + after >> 1;
if ((mid ? styles[mid * 2 - 1] : 0) >= ch) {
after = mid;
} else if (styles[mid * 2 + 1] < ch) {
before = mid + 1;
} else {
type = styles[mid * 2 + 2];break;
}
}
}
var cut = type ? type.indexOf("overlay ") : -1;
return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1);
},
getModeAt: function (pos) {
var mode = this.doc.mode;
if (!mode.innerMode) {
return mode;
}
return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;
},
getHelper: function (pos, type) {
return this.getHelpers(pos, type)[0];
},
getHelpers: function (pos, type) {
var this$1 = this;
var found = [];
if (!helpers.hasOwnProperty(type)) {
return found;
}
var help = helpers[type],
mode = this.getModeAt(pos);
if (typeof mode[type] == "string") {
if (help[mode[type]]) {
found.push(help[mode[type]]);
}
} else if (mode[type]) {
for (var i = 0; i < mode[type].length; i++) {
var val = help[mode[type][i]];
if (val) {
found.push(val);
}
}
} else if (mode.helperType && help[mode.helperType]) {
found.push(help[mode.helperType]);
} else if (help[mode.name]) {
found.push(help[mode.name]);
}
for (var i$1 = 0; i$1 < help._global.length; i$1++) {
var cur = help._global[i$1];
if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1) {
found.push(cur.val);
}
}
return found;
},
getStateAfter: function (line, precise) {
var doc = this.doc;
line = clipLine(doc, line == null ? doc.first + doc.size - 1 : line);
return getContextBefore(this, line + 1, precise).state;
},
cursorCoords: function (start, mode) {
var pos,
range$$1 = this.doc.sel.primary();
if (start == null) {
pos = range$$1.head;
} else if (typeof start == "object") {
pos = clipPos(this.doc, start);
} else {
pos = start ? range$$1.from() : range$$1.to();
}
return cursorCoords(this, pos, mode || "page");
},
charCoords: function (pos, mode) {
return charCoords(this, clipPos(this.doc, pos), mode || "page");
},
coordsChar: function (coords, mode) {
coords = fromCoordSystem(this, coords, mode || "page");
return coordsChar(this, coords.left, coords.top);
},
lineAtHeight: function (height, mode) {
height = fromCoordSystem(this, { top: height, left: 0 }, mode || "page").top;
return lineAtHeight(this.doc, height + this.display.viewOffset);
},
heightAtLine: function (line, mode, includeWidgets) {
var end = false,
lineObj;
if (typeof line == "number") {
var last = this.doc.first + this.doc.size - 1;
if (line < this.doc.first) {
line = this.doc.first;
} else if (line > last) {
line = last;end = true;
}
lineObj = getLine(this.doc, line);
} else {
lineObj = line;
}
return intoCoordSystem(this, lineObj, { top: 0, left: 0 }, mode || "page", includeWidgets || end).top + (end ? this.doc.height - heightAtLine(lineObj) : 0);
},
defaultTextHeight: function () {
return textHeight(this.display);
},
defaultCharWidth: function () {
return charWidth(this.display);
},
getViewport: function () {
return { from: this.display.viewFrom, to: this.display.viewTo };
},
addWidget: function (pos, node, scroll, vert, horiz) {
var display = this.display;
pos = cursorCoords(this, clipPos(this.doc, pos));
var top = pos.bottom,
left = pos.left;
node.style.position = "absolute";
node.setAttribute("cm-ignore-events", "true");
this.display.input.setUneditable(node);
display.sizer.appendChild(node);
if (vert == "over") {
top = pos.top;
} else if (vert == "above" || vert == "near") {
var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
// Default to positioning above (if specified and possible); otherwise default to positioning below
if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight) {
top = pos.top - node.offsetHeight;
} else if (pos.bottom + node.offsetHeight <= vspace) {
top = pos.bottom;
}
if (left + node.offsetWidth > hspace) {
left = hspace - node.offsetWidth;
}
}
node.style.top = top + "px";
node.style.left = node.style.right = "";
if (horiz == "right") {
left = display.sizer.clientWidth - node.offsetWidth;
node.style.right = "0px";
} else {
if (horiz == "left") {
left = 0;
} else if (horiz == "middle") {
left = (display.sizer.clientWidth - node.offsetWidth) / 2;
}
node.style.left = left + "px";
}
if (scroll) {
scrollIntoView(this, { left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight });
}
},
triggerOnKeyDown: methodOp(onKeyDown),
triggerOnKeyPress: methodOp(onKeyPress),
triggerOnKeyUp: onKeyUp,
triggerOnMouseDown: methodOp(onMouseDown),
execCommand: function (cmd) {
if (commands.hasOwnProperty(cmd)) {
return commands[cmd].call(null, this);
}
},
triggerElectric: methodOp(function (text) {
triggerElectric(this, text);
}),
findPosH: function (from, amount, unit, visually) {
var this$1 = this;
var dir = 1;
if (amount < 0) {
dir = -1;amount = -amount;
}
var cur = clipPos(this.doc, from);
for (var i = 0; i < amount; ++i) {
cur = findPosH(this$1.doc, cur, dir, unit, visually);
if (cur.hitSide) {
break;
}
}
return cur;
},
moveH: methodOp(function (dir, unit) {
var this$1 = this;
this.extendSelectionsBy(function (range$$1) {
if (this$1.display.shift || this$1.doc.extend || range$$1.empty()) {
return findPosH(this$1.doc, range$$1.head, dir, unit, this$1.options.rtlMoveVisually);
} else {
return dir < 0 ? range$$1.from() : range$$1.to();
}
}, sel_move);
}),
deleteH: methodOp(function (dir, unit) {
var sel = this.doc.sel,
doc = this.doc;
if (sel.somethingSelected()) {
doc.replaceSelection("", null, "+delete");
} else {
deleteNearSelection(this, function (range$$1) {
var other = findPosH(doc, range$$1.head, dir, unit, false);
return dir < 0 ? { from: other, to: range$$1.head } : { from: range$$1.head, to: other };
});
}
}),
findPosV: function (from, amount, unit, goalColumn) {
var this$1 = this;
var dir = 1,
x = goalColumn;
if (amount < 0) {
dir = -1;amount = -amount;
}
var cur = clipPos(this.doc, from);
for (var i = 0; i < amount; ++i) {
var coords = cursorCoords(this$1, cur, "div");
if (x == null) {
x = coords.left;
} else {
coords.left = x;
}
cur = findPosV(this$1, coords, dir, unit);
if (cur.hitSide) {
break;
}
}
return cur;
},
moveV: methodOp(function (dir, unit) {
var this$1 = this;
var doc = this.doc,
goals = [];
var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected();
doc.extendSelectionsBy(function (range$$1) {
if (collapse) {
return dir < 0 ? range$$1.from() : range$$1.to();
}
var headPos = cursorCoords(this$1, range$$1.head, "div");
if (range$$1.goalColumn != null) {
headPos.left = range$$1.goalColumn;
}
goals.push(headPos.left);
var pos = findPosV(this$1, headPos, dir, unit);
if (unit == "page" && range$$1 == doc.sel.primary()) {
addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top);
}
return pos;
}, sel_move);
if (goals.length) {
for (var i = 0; i < doc.sel.ranges.length; i++) {
doc.sel.ranges[i].goalColumn = goals[i];
}
}
}),
// Find the word at the given position (as returned by coordsChar).
findWordAt: function (pos) {
var doc = this.doc,
line = getLine(doc, pos.line).text;
var start = pos.ch,
end = pos.ch;
if (line) {
var helper = this.getHelper(pos, "wordChars");
if ((pos.sticky == "before" || end == line.length) && start) {
--start;
} else {
++end;
}
var startChar = line.charAt(start);
var check = isWordChar(startChar, helper) ? function (ch) {
return isWordChar(ch, helper);
} : /\s/.test(startChar) ? function (ch) {
return (/\s/.test(ch)
);
} : function (ch) {
return !/\s/.test(ch) && !isWordChar(ch);
};
while (start > 0 && check(line.charAt(start - 1))) {
--start;
}
while (end < line.length && check(line.charAt(end))) {
++end;
}
}
return new Range(Pos(pos.line, start), Pos(pos.line, end));
},
toggleOverwrite: function (value) {
if (value != null && value == this.state.overwrite) {
return;
}
if (this.state.overwrite = !this.state.overwrite) {
addClass(this.display.cursorDiv, "CodeMirror-overwrite");
} else {
rmClass(this.display.cursorDiv, "CodeMirror-overwrite");
}
signal(this, "overwriteToggle", this, this.state.overwrite);
},
hasFocus: function () {
return this.display.input.getField() == activeElt();
},
isReadOnly: function () {
return !!(this.options.readOnly || this.doc.cantEdit);
},
scrollTo: methodOp(function (x, y) {
scrollToCoords(this, x, y);
}),
getScrollInfo: function () {
var scroller = this.display.scroller;
return { left: scroller.scrollLeft, top: scroller.scrollTop,
height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
clientHeight: displayHeight(this), clientWidth: displayWidth(this) };
},
scrollIntoView: methodOp(function (range$$1, margin) {
if (range$$1 == null) {
range$$1 = { from: this.doc.sel.primary().head, to: null };
if (margin == null) {
margin = this.options.cursorScrollMargin;
}
} else if (typeof range$$1 == "number") {
range$$1 = { from: Pos(range$$1, 0), to: null };
} else if (range$$1.from == null) {
range$$1 = { from: range$$1, to: null };
}
if (!range$$1.to) {
range$$1.to = range$$1.from;
}
range$$1.margin = margin || 0;
if (range$$1.from.line != null) {
scrollToRange(this, range$$1);
} else {
scrollToCoordsRange(this, range$$1.from, range$$1.to, range$$1.margin);
}
}),
setSize: methodOp(function (width, height) {
var this$1 = this;
var interpret = function (val) {
return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
};
if (width != null) {
this.display.wrapper.style.width = interpret(width);
}
if (height != null) {
this.display.wrapper.style.height = interpret(height);
}
if (this.options.lineWrapping) {
clearLineMeasurementCache(this);
}
var lineNo$$1 = this.display.viewFrom;
this.doc.iter(lineNo$$1, this.display.viewTo, function (line) {
if (line.widgets) {
for (var i = 0; i < line.widgets.length; i++) {
if (line.widgets[i].noHScroll) {
regLineChange(this$1, lineNo$$1, "widget");break;
}
}
}
++lineNo$$1;
});
this.curOp.forceUpdate = true;
signal(this, "refresh", this);
}),
operation: function (f) {
return runInOp(this, f);
},
startOperation: function () {
return startOperation(this);
},
endOperation: function () {
return endOperation(this);
},
refresh: methodOp(function () {
var oldHeight = this.display.cachedTextHeight;
regChange(this);
this.curOp.forceUpdate = true;
clearCaches(this);
scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop);
updateGutterSpace(this);
if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5) {
estimateLineHeights(this);
}
signal(this, "refresh", this);
}),
swapDoc: methodOp(function (doc) {
var old = this.doc;
old.cm = null;
attachDoc(this, doc);
clearCaches(this);
this.display.input.reset();
scrollToCoords(this, doc.scrollLeft, doc.scrollTop);
this.curOp.forceScroll = true;
signalLater(this, "swapDoc", this, old);
return old;
}),
getInputField: function () {
return this.display.input.getField();
},
getWrapperElement: function () {
return this.display.wrapper;
},
getScrollerElement: function () {
return this.display.scroller;
},
getGutterElement: function () {
return this.display.gutters;
}
};
eventMixin(CodeMirror);
CodeMirror.registerHelper = function (type, name, value) {
if (!helpers.hasOwnProperty(type)) {
helpers[type] = CodeMirror[type] = { _global: [] };
}
helpers[type][name] = value;
};
CodeMirror.registerGlobalHelper = function (type, name, predicate, value) {
CodeMirror.registerHelper(type, name, value);
helpers[type]._global.push({ pred: predicate, val: value });
};
};
// Used for horizontal relative motion. Dir is -1 or 1 (left or
// right), unit can be "char", "column" (like char, but doesn't
// cross line boundaries), "word" (across next word), or "group" (to
// the start of next group of word or non-word-non-whitespace
// chars). The visually param controls whether, in right-to-left
// text, direction 1 means to move towards the next index in the
// string, or towards the character to the right of the current
// position. The resulting position will have a hitSide=true
// property if it reached the end of the document.
function findPosH(doc, pos, dir, unit, visually) {
var oldPos = pos;
var origDir = dir;
var lineObj = getLine(doc, pos.line);
function findNextLine() {
var l = pos.line + dir;
if (l < doc.first || l >= doc.first + doc.size) {
return false;
}
pos = new Pos(l, pos.ch, pos.sticky);
return lineObj = getLine(doc, l);
}
function moveOnce(boundToLine) {
var next;
if (visually) {
next = moveVisually(doc.cm, lineObj, pos, dir);
} else {
next = moveLogically(lineObj, pos, dir);
}
if (next == null) {
if (!boundToLine && findNextLine()) {
pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir);
} else {
return false;
}
} else {
pos = next;
}
return true;
}
if (unit == "char") {
moveOnce();
} else if (unit == "column") {
moveOnce(true);
} else if (unit == "word" || unit == "group") {
var sawType = null,
group = unit == "group";
var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
for (var first = true;; first = false) {
if (dir < 0 && !moveOnce(!first)) {
break;
}
var cur = lineObj.text.charAt(pos.ch) || "\n";
var type = isWordChar(cur, helper) ? "w" : group && cur == "\n" ? "n" : !group || /\s/.test(cur) ? null : "p";
if (group && !first && !type) {
type = "s";
}
if (sawType && sawType != type) {
if (dir < 0) {
dir = 1;moveOnce();pos.sticky = "after";
}
break;
}
if (type) {
sawType = type;
}
if (dir > 0 && !moveOnce(!first)) {
break;
}
}
}
var result = skipAtomic(doc, pos, oldPos, origDir, true);
if (equalCursorPos(oldPos, result)) {
result.hitSide = true;
}
return result;
}
// For relative vertical movement. Dir may be -1 or 1. Unit can be
// "page" or "line". The resulting position will have a hitSide=true
// property if it reached the end of the document.
function findPosV(cm, pos, dir, unit) {
var doc = cm.doc,
x = pos.left,
y;
if (unit == "page") {
var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);
y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;
} else if (unit == "line") {
y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
}
var target;
for (;;) {
target = coordsChar(cm, x, y);
if (!target.outside) {
break;
}
if (dir < 0 ? y <= 0 : y >= doc.height) {
target.hitSide = true;break;
}
y += dir * 5;
}
return target;
}
// CONTENTEDITABLE INPUT STYLE
var ContentEditableInput = function (cm) {
this.cm = cm;
this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
this.polling = new Delayed();
this.composing = null;
this.gracePeriod = false;
this.readDOMTimeout = null;
};
ContentEditableInput.prototype.init = function (display) {
var this$1 = this;
var input = this,
cm = input.cm;
var div = input.div = display.lineDiv;
disableBrowserMagic(div, cm.options.spellcheck);
on(div, "paste", function (e) {
if (signalDOMEvent(cm, e) || handlePaste(e, cm)) {
return;
}
// IE doesn't fire input events, so we schedule a read for the pasted content in this way
if (ie_version <= 11) {
setTimeout(operation(cm, function () {
return this$1.updateFromDOM();
}), 20);
}
});
on(div, "compositionstart", function (e) {
this$1.composing = { data: e.data, done: false };
});
on(div, "compositionupdate", function (e) {
if (!this$1.composing) {
this$1.composing = { data: e.data, done: false };
}
});
on(div, "compositionend", function (e) {
if (this$1.composing) {
if (e.data != this$1.composing.data) {
this$1.readFromDOMSoon();
}
this$1.composing.done = true;
}
});
on(div, "touchstart", function () {
return input.forceCompositionEnd();
});
on(div, "input", function () {
if (!this$1.composing) {
this$1.readFromDOMSoon();
}
});
function onCopyCut(e) {
if (signalDOMEvent(cm, e)) {
return;
}
if (cm.somethingSelected()) {
setLastCopied({ lineWise: false, text: cm.getSelections() });
if (e.type == "cut") {
cm.replaceSelection("", null, "cut");
}
} else if (!cm.options.lineWiseCopyCut) {
return;
} else {
var ranges = copyableRanges(cm);
setLastCopied({ lineWise: true, text: ranges.text });
if (e.type == "cut") {
cm.operation(function () {
cm.setSelections(ranges.ranges, 0, sel_dontScroll);
cm.replaceSelection("", null, "cut");
});
}
}
if (e.clipboardData) {
e.clipboardData.clearData();
var content = lastCopied.text.join("\n");
// iOS exposes the clipboard API, but seems to discard content inserted into it
e.clipboardData.setData("Text", content);
if (e.clipboardData.getData("Text") == content) {
e.preventDefault();
return;
}
}
// Old-fashioned briefly-focus-a-textarea hack
var kludge = hiddenTextarea(),
te = kludge.firstChild;
cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
te.value = lastCopied.text.join("\n");
var hadFocus = document.activeElement;
selectInput(te);
setTimeout(function () {
cm.display.lineSpace.removeChild(kludge);
hadFocus.focus();
if (hadFocus == div) {
input.showPrimarySelection();
}
}, 50);
}
on(div, "copy", onCopyCut);
on(div, "cut", onCopyCut);
};
ContentEditableInput.prototype.prepareSelection = function () {
var result = prepareSelection(this.cm, false);
result.focus = this.cm.state.focused;
return result;
};
ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
if (!info || !this.cm.display.view.length) {
return;
}
if (info.focus || takeFocus) {
this.showPrimarySelection();
}
this.showMultipleSelections(info);
};
ContentEditableInput.prototype.getSelection = function () {
return this.cm.display.wrapper.ownerDocument.getSelection();
};
ContentEditableInput.prototype.showPrimarySelection = function () {
var sel = this.getSelection(),
cm = this.cm,
prim = cm.doc.sel.primary();
var from = prim.from(),
to = prim.to();
if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
sel.removeAllRanges();
return;
}
var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset);
if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad && cmp(minPos(curAnchor, curFocus), from) == 0 && cmp(maxPos(curAnchor, curFocus), to) == 0) {
return;
}
var view = cm.display.view;
var start = from.line >= cm.display.viewFrom && posToDOM(cm, from) || { node: view[0].measure.map[2], offset: 0 };
var end = to.line < cm.display.viewTo && posToDOM(cm, to);
if (!end) {
var measure = view[view.length - 1].measure;
var map$$1 = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
end = { node: map$$1[map$$1.length - 1], offset: map$$1[map$$1.length - 2] - map$$1[map$$1.length - 3] };
}
if (!start || !end) {
sel.removeAllRanges();
return;
}
var old = sel.rangeCount && sel.getRangeAt(0),
rng;
try {
rng = range(start.node, start.offset, end.offset, end.node);
} catch (e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
if (rng) {
if (!gecko && cm.state.focused) {
sel.collapse(start.node, start.offset);
if (!rng.collapsed) {
sel.removeAllRanges();
sel.addRange(rng);
}
} else {
sel.removeAllRanges();
sel.addRange(rng);
}
if (old && sel.anchorNode == null) {
sel.addRange(old);
} else if (gecko) {
this.startGracePeriod();
}
}
this.rememberSelection();
};
ContentEditableInput.prototype.startGracePeriod = function () {
var this$1 = this;
clearTimeout(this.gracePeriod);
this.gracePeriod = setTimeout(function () {
this$1.gracePeriod = false;
if (this$1.selectionChanged()) {
this$1.cm.operation(function () {
return this$1.cm.curOp.selectionChanged = true;
});
}
}, 20);
};
ContentEditableInput.prototype.showMultipleSelections = function (info) {
removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
};
ContentEditableInput.prototype.rememberSelection = function () {
var sel = this.getSelection();
this.lastAnchorNode = sel.anchorNode;this.lastAnchorOffset = sel.anchorOffset;
this.lastFocusNode = sel.focusNode;this.lastFocusOffset = sel.focusOffset;
};
ContentEditableInput.prototype.selectionInEditor = function () {
var sel = this.getSelection();
if (!sel.rangeCount) {
return false;
}
var node = sel.getRangeAt(0).commonAncestorContainer;
return contains(this.div, node);
};
ContentEditableInput.prototype.focus = function () {
if (this.cm.options.readOnly != "nocursor") {
if (!this.selectionInEditor()) {
this.showSelection(this.prepareSelection(), true);
}
this.div.focus();
}
};
ContentEditableInput.prototype.blur = function () {
this.div.blur();
};
ContentEditableInput.prototype.getField = function () {
return this.div;
};
ContentEditableInput.prototype.supportsTouch = function () {
return true;
};
ContentEditableInput.prototype.receivedFocus = function () {
var input = this;
if (this.selectionInEditor()) {
this.pollSelection();
} else {
runInOp(this.cm, function () {
return input.cm.curOp.selectionChanged = true;
});
}
function poll() {
if (input.cm.state.focused) {
input.pollSelection();
input.polling.set(input.cm.options.pollInterval, poll);
}
}
this.polling.set(this.cm.options.pollInterval, poll);
};
ContentEditableInput.prototype.selectionChanged = function () {
var sel = this.getSelection();
return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset || sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset;
};
ContentEditableInput.prototype.pollSelection = function () {
if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) {
return;
}
var sel = this.getSelection(),
cm = this.cm;
// On Android Chrome (version 56, at least), backspacing into an
// uneditable block element will put the cursor in that element,
// and then, because it's not editable, hide the virtual keyboard.
// Because Android doesn't allow us to actually detect backspace
// presses in a sane way, this code checks for when that happens
// and simulates a backspace press in this case.
if (android && chrome && this.cm.options.gutters.length && isInGutter(sel.anchorNode)) {
this.cm.triggerOnKeyDown({ type: "keydown", keyCode: 8, preventDefault: Math.abs });
this.blur();
this.focus();
return;
}
if (this.composing) {
return;
}
this.rememberSelection();
var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
var head = domToPos(cm, sel.focusNode, sel.focusOffset);
if (anchor && head) {
runInOp(cm, function () {
setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
if (anchor.bad || head.bad) {
cm.curOp.selectionChanged = true;
}
});
}
};
ContentEditableInput.prototype.pollContent = function () {
if (this.readDOMTimeout != null) {
clearTimeout(this.readDOMTimeout);
this.readDOMTimeout = null;
}
var cm = this.cm,
display = cm.display,
sel = cm.doc.sel.primary();
var from = sel.from(),
to = sel.to();
if (from.ch == 0 && from.line > cm.firstLine()) {
from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length);
}
if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine()) {
to = Pos(to.line + 1, 0);
}
if (from.line < display.viewFrom || to.line > display.viewTo - 1) {
return false;
}
var fromIndex, fromLine, fromNode;
if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
fromLine = lineNo(display.view[0].line);
fromNode = display.view[0].node;
} else {
fromLine = lineNo(display.view[fromIndex].line);
fromNode = display.view[fromIndex - 1].node.nextSibling;
}
var toIndex = findViewIndex(cm, to.line);
var toLine, toNode;
if (toIndex == display.view.length - 1) {
toLine = display.viewTo - 1;
toNode = display.lineDiv.lastChild;
} else {
toLine = lineNo(display.view[toIndex + 1].line) - 1;
toNode = display.view[toIndex + 1].node.previousSibling;
}
if (!fromNode) {
return false;
}
var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
while (newText.length > 1 && oldText.length > 1) {
if (lst(newText) == lst(oldText)) {
newText.pop();oldText.pop();toLine--;
} else if (newText[0] == oldText[0]) {
newText.shift();oldText.shift();fromLine++;
} else {
break;
}
}
var cutFront = 0,
cutEnd = 0;
var newTop = newText[0],
oldTop = oldText[0],
maxCutFront = Math.min(newTop.length, oldTop.length);
while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront)) {
++cutFront;
}
var newBot = lst(newText),
oldBot = lst(oldText);
var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0), oldBot.length - (oldText.length == 1 ? cutFront : 0));
while (cutEnd < maxCutEnd && newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
++cutEnd;
}
// Try to move start of change to start of selection if ambiguous
if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
while (cutFront && cutFront > from.ch && newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
cutFront--;
cutEnd++;
}
}
newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "");
newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "");
var chFrom = Pos(fromLine, cutFront);
var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
replaceRange(cm.doc, newText, chFrom, chTo, "+input");
return true;
}
};
ContentEditableInput.prototype.ensurePolled = function () {
this.forceCompositionEnd();
};
ContentEditableInput.prototype.reset = function () {
this.forceCompositionEnd();
};
ContentEditableInput.prototype.forceCompositionEnd = function () {
if (!this.composing) {
return;
}
clearTimeout(this.readDOMTimeout);
this.composing = null;
this.updateFromDOM();
this.div.blur();
this.div.focus();
};
ContentEditableInput.prototype.readFromDOMSoon = function () {
var this$1 = this;
if (this.readDOMTimeout != null) {
return;
}
this.readDOMTimeout = setTimeout(function () {
this$1.readDOMTimeout = null;
if (this$1.composing) {
if (this$1.composing.done) {
this$1.composing = null;
} else {
return;
}
}
this$1.updateFromDOM();
}, 80);
};
ContentEditableInput.prototype.updateFromDOM = function () {
var this$1 = this;
if (this.cm.isReadOnly() || !this.pollContent()) {
runInOp(this.cm, function () {
return regChange(this$1.cm);
});
}
};
ContentEditableInput.prototype.setUneditable = function (node) {
node.contentEditable = "false";
};
ContentEditableInput.prototype.onKeyPress = function (e) {
if (e.charCode == 0 || this.composing) {
return;
}
e.preventDefault();
if (!this.cm.isReadOnly()) {
operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
}
};
ContentEditableInput.prototype.readOnlyChanged = function (val) {
this.div.contentEditable = String(val != "nocursor");
};
ContentEditableInput.prototype.onContextMenu = function () {};
ContentEditableInput.prototype.resetPosition = function () {};
ContentEditableInput.prototype.needsContentAttribute = true;
function posToDOM(cm, pos) {
var view = findViewForLine(cm, pos.line);
if (!view || view.hidden) {
return null;
}
var line = getLine(cm.doc, pos.line);
var info = mapFromLineView(view, line, pos.line);
var order = getOrder(line, cm.doc.direction),
side = "left";
if (order) {
var partPos = getBidiPartAt(order, pos.ch);
side = partPos % 2 ? "right" : "left";
}
var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
result.offset = result.collapse == "right" ? result.end : result.start;
return result;
}
function isInGutter(node) {
for (var scan = node; scan; scan = scan.parentNode) {
if (/CodeMirror-gutter-wrapper/.test(scan.className)) {
return true;
}
}
return false;
}
function badPos(pos, bad) {
if (bad) {
pos.bad = true;
}return pos;
}
function domTextBetween(cm, from, to, fromLine, toLine) {
var text = "",
closing = false,
lineSep = cm.doc.lineSeparator(),
extraLinebreak = false;
function recognizeMarker(id) {
return function (marker) {
return marker.id == id;
};
}
function close() {
if (closing) {
text += lineSep;
if (extraLinebreak) {
text += lineSep;
}
closing = extraLinebreak = false;
}
}
function addText(str) {
if (str) {
close();
text += str;
}
}
function walk(node) {
if (node.nodeType == 1) {
var cmText = node.getAttribute("cm-text");
if (cmText) {
addText(cmText);
return;
}
var markerID = node.getAttribute("cm-marker"),
range$$1;
if (markerID) {
var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
if (found.length && (range$$1 = found[0].find(0))) {
addText(getBetween(cm.doc, range$$1.from, range$$1.to).join(lineSep));
}
return;
}
if (node.getAttribute("contenteditable") == "false") {
return;
}
var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName);
if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) {
return;
}
if (isBlock) {
close();
}
for (var i = 0; i < node.childNodes.length; i++) {
walk(node.childNodes[i]);
}
if (/^(pre|p)$/i.test(node.nodeName)) {
extraLinebreak = true;
}
if (isBlock) {
closing = true;
}
} else if (node.nodeType == 3) {
addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
}
}
for (;;) {
walk(from);
if (from == to) {
break;
}
from = from.nextSibling;
extraLinebreak = false;
}
return text;
}
function domToPos(cm, node, offset) {
var lineNode;
if (node == cm.display.lineDiv) {
lineNode = cm.display.lineDiv.childNodes[offset];
if (!lineNode) {
return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true);
}
node = null;offset = 0;
} else {
for (lineNode = node;; lineNode = lineNode.parentNode) {
if (!lineNode || lineNode == cm.display.lineDiv) {
return null;
}
if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) {
break;
}
}
}
for (var i = 0; i < cm.display.view.length; i++) {
var lineView = cm.display.view[i];
if (lineView.node == lineNode) {
return locateNodeInLineView(lineView, node, offset);
}
}
}
function locateNodeInLineView(lineView, node, offset) {
var wrapper = lineView.text.firstChild,
bad = false;
if (!node || !contains(wrapper, node)) {
return badPos(Pos(lineNo(lineView.line), 0), true);
}
if (node == wrapper) {
bad = true;
node = wrapper.childNodes[offset];
offset = 0;
if (!node) {
var line = lineView.rest ? lst(lineView.rest) : lineView.line;
return badPos(Pos(lineNo(line), line.text.length), bad);
}
}
var textNode = node.nodeType == 3 ? node : null,
topNode = node;
if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
textNode = node.firstChild;
if (offset) {
offset = textNode.nodeValue.length;
}
}
while (topNode.parentNode != wrapper) {
topNode = topNode.parentNode;
}
var measure = lineView.measure,
maps = measure.maps;
function find(textNode, topNode, offset) {
for (var i = -1; i < (maps ? maps.length : 0); i++) {
var map$$1 = i < 0 ? measure.map : maps[i];
for (var j = 0; j < map$$1.length; j += 3) {
var curNode = map$$1[j + 2];
if (curNode == textNode || curNode == topNode) {
var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
var ch = map$$1[j] + offset;
if (offset < 0 || curNode != textNode) {
ch = map$$1[j + (offset ? 1 : 0)];
}
return Pos(line, ch);
}
}
}
}
var found = find(textNode, topNode, offset);
if (found) {
return badPos(found, bad);
}
// FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
found = find(after, after.firstChild, 0);
if (found) {
return badPos(Pos(found.line, found.ch - dist), bad);
} else {
dist += after.textContent.length;
}
}
for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
found = find(before, before.firstChild, -1);
if (found) {
return badPos(Pos(found.line, found.ch + dist$1), bad);
} else {
dist$1 += before.textContent.length;
}
}
}
// TEXTAREA INPUT STYLE
var TextareaInput = function (cm) {
this.cm = cm;
// See input.poll and input.reset
this.prevInput = "";
// Flag that indicates whether we expect input to appear real soon
// now (after some event like 'keypress' or 'input') and are
// polling intensively.
this.pollingFast = false;
// Self-resetting timeout for the poller
this.polling = new Delayed();
// Used to work around IE issue with selection being forgotten when focus moves away from textarea
this.hasSelection = false;
this.composing = null;
};
TextareaInput.prototype.init = function (display) {
var this$1 = this;
var input = this,
cm = this.cm;
this.createField(display);
var te = this.textarea;
display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild);
// Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
if (ios) {
te.style.width = "0px";
}
on(te, "input", function () {
if (ie && ie_version >= 9 && this$1.hasSelection) {
this$1.hasSelection = null;
}
input.poll();
});
on(te, "paste", function (e) {
if (signalDOMEvent(cm, e) || handlePaste(e, cm)) {
return;
}
cm.state.pasteIncoming = true;
input.fastPoll();
});
function prepareCopyCut(e) {
if (signalDOMEvent(cm, e)) {
return;
}
if (cm.somethingSelected()) {
setLastCopied({ lineWise: false, text: cm.getSelections() });
} else if (!cm.options.lineWiseCopyCut) {
return;
} else {
var ranges = copyableRanges(cm);
setLastCopied({ lineWise: true, text: ranges.text });
if (e.type == "cut") {
cm.setSelections(ranges.ranges, null, sel_dontScroll);
} else {
input.prevInput = "";
te.value = ranges.text.join("\n");
selectInput(te);
}
}
if (e.type == "cut") {
cm.state.cutIncoming = true;
}
}
on(te, "cut", prepareCopyCut);
on(te, "copy", prepareCopyCut);
on(display.scroller, "paste", function (e) {
if (eventInWidget(display, e) || signalDOMEvent(cm, e)) {
return;
}
cm.state.pasteIncoming = true;
input.focus();
});
// Prevent normal selection in the editor (we handle our own)
on(display.lineSpace, "selectstart", function (e) {
if (!eventInWidget(display, e)) {
e_preventDefault(e);
}
});
on(te, "compositionstart", function () {
var start = cm.getCursor("from");
if (input.composing) {
input.composing.range.clear();
}
input.composing = {
start: start,
range: cm.markText(start, cm.getCursor("to"), { className: "CodeMirror-composing" })
};
});
on(te, "compositionend", function () {
if (input.composing) {
input.poll();
input.composing.range.clear();
input.composing = null;
}
});
};
TextareaInput.prototype.createField = function (_display) {
// Wraps and hides input textarea
this.wrapper = hiddenTextarea();
// The semihidden textarea that is focused when the editor is
// focused, and receives input.
this.textarea = this.wrapper.firstChild;
};
TextareaInput.prototype.prepareSelection = function () {
// Redraw the selection and/or cursor
var cm = this.cm,
display = cm.display,
doc = cm.doc;
var result = prepareSelection(cm);
// Move the hidden textarea near the cursor to prevent scrolling artifacts
if (cm.options.moveInputWithCursor) {
var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
var wrapOff = display.wrapper.getBoundingClientRect(),
lineOff = display.lineDiv.getBoundingClientRect();
result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10, headPos.top + lineOff.top - wrapOff.top));
result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10, headPos.left + lineOff.left - wrapOff.left));
}
return result;
};
TextareaInput.prototype.showSelection = function (drawn) {
var cm = this.cm,
display = cm.display;
removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
removeChildrenAndAdd(display.selectionDiv, drawn.selection);
if (drawn.teTop != null) {
this.wrapper.style.top = drawn.teTop + "px";
this.wrapper.style.left = drawn.teLeft + "px";
}
};
// Reset the input to correspond to the selection (or to be empty,
// when not typing and nothing is selected)
TextareaInput.prototype.reset = function (typing) {
if (this.contextMenuPending || this.composing) {
return;
}
var cm = this.cm;
if (cm.somethingSelected()) {
this.prevInput = "";
var content = cm.getSelection();
this.textarea.value = content;
if (cm.state.focused) {
selectInput(this.textarea);
}
if (ie && ie_version >= 9) {
this.hasSelection = content;
}
} else if (!typing) {
this.prevInput = this.textarea.value = "";
if (ie && ie_version >= 9) {
this.hasSelection = null;
}
}
};
TextareaInput.prototype.getField = function () {
return this.textarea;
};
TextareaInput.prototype.supportsTouch = function () {
return false;
};
TextareaInput.prototype.focus = function () {
if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
try {
this.textarea.focus();
} catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
}
};
TextareaInput.prototype.blur = function () {
this.textarea.blur();
};
TextareaInput.prototype.resetPosition = function () {
this.wrapper.style.top = this.wrapper.style.left = 0;
};
TextareaInput.prototype.receivedFocus = function () {
this.slowPoll();
};
// Poll for input changes, using the normal rate of polling. This
// runs as long as the editor is focused.
TextareaInput.prototype.slowPoll = function () {
var this$1 = this;
if (this.pollingFast) {
return;
}
this.polling.set(this.cm.options.pollInterval, function () {
this$1.poll();
if (this$1.cm.state.focused) {
this$1.slowPoll();
}
});
};
// When an event has just come in that is likely to add or change
// something in the input textarea, we poll faster, to ensure that
// the change appears on the screen quickly.
TextareaInput.prototype.fastPoll = function () {
var missed = false,
input = this;
input.pollingFast = true;
function p() {
var changed = input.poll();
if (!changed && !missed) {
missed = true;input.polling.set(60, p);
} else {
input.pollingFast = false;input.slowPoll();
}
}
input.polling.set(20, p);
};
// Read input from the textarea, and update the document to match.
// When something is selected, it is present in the textarea, and
// selected (unless it is huge, in which case a placeholder is
// used). When nothing is selected, the cursor sits after previously
// seen text (can be empty), which is stored in prevInput (we must
// not reset the textarea when typing, because that breaks IME).
TextareaInput.prototype.poll = function () {
var this$1 = this;
var cm = this.cm,
input = this.textarea,
prevInput = this.prevInput;
// Since this is called a *lot*, try to bail out as cheaply as
// possible when it is clear that nothing happened. hasSelection
// will be the case when there is a lot of text in the textarea,
// in which case reading its value would be expensive.
if (this.contextMenuPending || !cm.state.focused || hasSelection(input) && !prevInput && !this.composing || cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq) {
return false;
}
var text = input.value;
// If nothing changed, bail.
if (text == prevInput && !cm.somethingSelected()) {
return false;
}
// Work around nonsensical selection resetting in IE9/10, and
// inexplicable appearance of private area unicode characters on
// some key combos in Mac (#2689).
if (ie && ie_version >= 9 && this.hasSelection === text || mac && /[\uf700-\uf7ff]/.test(text)) {
cm.display.input.reset();
return false;
}
if (cm.doc.sel == cm.display.selForContextMenu) {
var first = text.charCodeAt(0);
if (first == 0x200b && !prevInput) {
prevInput = "\u200b";
}
if (first == 0x21da) {
this.reset();return this.cm.execCommand("undo");
}
}
// Find the part of the input that is actually new
var same = 0,
l = Math.min(prevInput.length, text.length);
while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) {
++same;
}
runInOp(cm, function () {
applyTextInput(cm, text.slice(same), prevInput.length - same, null, this$1.composing ? "*compose" : null);
// Don't leave long text in the textarea, since it makes further polling slow
if (text.length > 1000 || text.indexOf("\n") > -1) {
input.value = this$1.prevInput = "";
} else {
this$1.prevInput = text;
}
if (this$1.composing) {
this$1.composing.range.clear();
this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"), { className: "CodeMirror-composing" });
}
});
return true;
};
TextareaInput.prototype.ensurePolled = function () {
if (this.pollingFast && this.poll()) {
this.pollingFast = false;
}
};
TextareaInput.prototype.onKeyPress = function () {
if (ie && ie_version >= 9) {
this.hasSelection = null;
}
this.fastPoll();
};
TextareaInput.prototype.onContextMenu = function (e) {
var input = this,
cm = input.cm,
display = cm.display,
te = input.textarea;
var pos = posFromMouse(cm, e),
scrollPos = display.scroller.scrollTop;
if (!pos || presto) {
return;
} // Opera is difficult.
// Reset the current text selection only if the click is done outside of the selection
// and 'resetSelectionOnContextMenu' option is true.
var reset = cm.options.resetSelectionOnContextMenu;
if (reset && cm.doc.sel.contains(pos) == -1) {
operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);
}
var oldCSS = te.style.cssText,
oldWrapperCSS = input.wrapper.style.cssText;
input.wrapper.style.cssText = "position: absolute";
var wrapperBox = input.wrapper.getBoundingClientRect();
te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
var oldScrollY;
if (webkit) {
oldScrollY = window.scrollY;
} // Work around Chrome issue (#2712)
display.input.focus();
if (webkit) {
window.scrollTo(null, oldScrollY);
}
display.input.reset();
// Adds "Select all" to context menu in FF
if (!cm.somethingSelected()) {
te.value = input.prevInput = " ";
}
input.contextMenuPending = true;
display.selForContextMenu = cm.doc.sel;
clearTimeout(display.detectingSelectAll);
// Select-all will be greyed out if there's nothing to select, so
// this adds a zero-width space so that we can later check whether
// it got selected.
function prepareSelectAllHack() {
if (te.selectionStart != null) {
var selected = cm.somethingSelected();
var extval = "\u200b" + (selected ? te.value : "");
te.value = "\u21da"; // Used to catch context-menu undo
te.value = extval;
input.prevInput = selected ? "" : "\u200b";
te.selectionStart = 1;te.selectionEnd = extval.length;
// Re-set this, in case some other handler touched the
// selection in the meantime.
display.selForContextMenu = cm.doc.sel;
}
}
function rehide() {
input.contextMenuPending = false;
input.wrapper.style.cssText = oldWrapperCSS;
te.style.cssText = oldCSS;
if (ie && ie_version < 9) {
display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos);
}
// Try to detect the user choosing select-all
if (te.selectionStart != null) {
if (!ie || ie && ie_version < 9) {
prepareSelectAllHack();
}
var i = 0,
poll = function () {
if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 && te.selectionEnd > 0 && input.prevInput == "\u200b") {
operation(cm, selectAll)(cm);
} else if (i++ < 10) {
display.detectingSelectAll = setTimeout(poll, 500);
} else {
display.selForContextMenu = null;
display.input.reset();
}
};
display.detectingSelectAll = setTimeout(poll, 200);
}
}
if (ie && ie_version >= 9) {
prepareSelectAllHack();
}
if (captureRightClick) {
e_stop(e);
var mouseup = function () {
off(window, "mouseup", mouseup);
setTimeout(rehide, 20);
};
on(window, "mouseup", mouseup);
} else {
setTimeout(rehide, 50);
}
};
TextareaInput.prototype.readOnlyChanged = function (val) {
if (!val) {
this.reset();
}
this.textarea.disabled = val == "nocursor";
};
TextareaInput.prototype.setUneditable = function () {};
TextareaInput.prototype.needsContentAttribute = false;
function fromTextArea(textarea, options) {
options = options ? copyObj(options) : {};
options.value = textarea.value;
if (!options.tabindex && textarea.tabIndex) {
options.tabindex = textarea.tabIndex;
}
if (!options.placeholder && textarea.placeholder) {
options.placeholder = textarea.placeholder;
}
// Set autofocus to true if this textarea is focused, or if it has
// autofocus and no other element is focused.
if (options.autofocus == null) {
var hasFocus = activeElt();
options.autofocus = hasFocus == textarea || textarea.getAttribute("autofocus") != null && hasFocus == document.body;
}
function save() {
textarea.value = cm.getValue();
}
var realSubmit;
if (textarea.form) {
on(textarea.form, "submit", save);
// Deplorable hack to make the submit method do the right thing.
if (!options.leaveSubmitMethodAlone) {
var form = textarea.form;
realSubmit = form.submit;
try {
var wrappedSubmit = form.submit = function () {
save();
form.submit = realSubmit;
form.submit();
form.submit = wrappedSubmit;
};
} catch (e) {}
}
}
options.finishInit = function (cm) {
cm.save = save;
cm.getTextArea = function () {
return textarea;
};
cm.toTextArea = function () {
cm.toTextArea = isNaN; // Prevent this from being ran twice
save();
textarea.parentNode.removeChild(cm.getWrapperElement());
textarea.style.display = "";
if (textarea.form) {
off(textarea.form, "submit", save);
if (typeof textarea.form.submit == "function") {
textarea.form.submit = realSubmit;
}
}
};
};
textarea.style.display = "none";
var cm = CodeMirror$1(function (node) {
return textarea.parentNode.insertBefore(node, textarea.nextSibling);
}, options);
return cm;
}
function addLegacyProps(CodeMirror) {
CodeMirror.off = off;
CodeMirror.on = on;
CodeMirror.wheelEventPixels = wheelEventPixels;
CodeMirror.Doc = Doc;
CodeMirror.splitLines = splitLinesAuto;
CodeMirror.countColumn = countColumn;
CodeMirror.findColumn = findColumn;
CodeMirror.isWordChar = isWordCharBasic;
CodeMirror.Pass = Pass;
CodeMirror.signal = signal;
CodeMirror.Line = Line;
CodeMirror.changeEnd = changeEnd;
CodeMirror.scrollbarModel = scrollbarModel;
CodeMirror.Pos = Pos;
CodeMirror.cmpPos = cmp;
CodeMirror.modes = modes;
CodeMirror.mimeModes = mimeModes;
CodeMirror.resolveMode = resolveMode;
CodeMirror.getMode = getMode;
CodeMirror.modeExtensions = modeExtensions;
CodeMirror.extendMode = extendMode;
CodeMirror.copyState = copyState;
CodeMirror.startState = startState;
CodeMirror.innerMode = innerMode;
CodeMirror.commands = commands;
CodeMirror.keyMap = keyMap;
CodeMirror.keyName = keyName;
CodeMirror.isModifierKey = isModifierKey;
CodeMirror.lookupKey = lookupKey;
CodeMirror.normalizeKeyMap = normalizeKeyMap;
CodeMirror.StringStream = StringStream;
CodeMirror.SharedTextMarker = SharedTextMarker;
CodeMirror.TextMarker = TextMarker;
CodeMirror.LineWidget = LineWidget;
CodeMirror.e_preventDefault = e_preventDefault;
CodeMirror.e_stopPropagation = e_stopPropagation;
CodeMirror.e_stop = e_stop;
CodeMirror.addClass = addClass;
CodeMirror.contains = contains;
CodeMirror.rmClass = rmClass;
CodeMirror.keyNames = keyNames;
}
// EDITOR CONSTRUCTOR
defineOptions(CodeMirror$1);
addEditorMethods(CodeMirror$1);
// Set up methods on CodeMirror's prototype to redirect to the editor's document.
var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
for (var prop in Doc.prototype) {
if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0) {
CodeMirror$1.prototype[prop] = function (method) {
return function () {
return method.apply(this.doc, arguments);
};
}(Doc.prototype[prop]);
}
}
eventMixin(Doc);
// INPUT HANDLING
CodeMirror$1.inputStyles = { "textarea": TextareaInput, "contenteditable": ContentEditableInput };
// MODE DEFINITION AND QUERYING
// Extra arguments are stored as the mode's dependencies, which is
// used by (legacy) mechanisms like loadmode.js to automatically
// load a mode. (Preferred mechanism is the require/define calls.)
CodeMirror$1.defineMode = function (name /*, mode, …*/) {
if (!CodeMirror$1.defaults.mode && name != "null") {
CodeMirror$1.defaults.mode = name;
}
defineMode.apply(this, arguments);
};
CodeMirror$1.defineMIME = defineMIME;
// Minimal default mode.
CodeMirror$1.defineMode("null", function () {
return { token: function (stream) {
return stream.skipToEnd();
} };
});
CodeMirror$1.defineMIME("text/plain", "null");
// EXTENSIONS
CodeMirror$1.defineExtension = function (name, func) {
CodeMirror$1.prototype[name] = func;
};
CodeMirror$1.defineDocExtension = function (name, func) {
Doc.prototype[name] = func;
};
CodeMirror$1.fromTextArea = fromTextArea;
addLegacyProps(CodeMirror$1);
CodeMirror$1.version = "5.38.0";
return CodeMirror$1;
});
/***/ }),
/***/ "uQIK":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
var ie_lt8 = /MSIE \d/.test(navigator.userAgent) && (document.documentMode == null || document.documentMode < 8);
var Pos = CodeMirror.Pos;
var matching = { "(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<" };
function findMatchingBracket(cm, where, config) {
var line = cm.getLineHandle(where.line),
pos = where.ch - 1;
var afterCursor = config && config.afterCursor;
if (afterCursor == null) afterCursor = /(^| )cm-fat-cursor($| )/.test(cm.getWrapperElement().className);
// A cursor is defined as between two characters, but in in vim command mode
// (i.e. not insert mode), the cursor is visually represented as a
// highlighted box on top of the 2nd character. Otherwise, we allow matches
// from before or after the cursor.
var match = !afterCursor && pos >= 0 && matching[line.text.charAt(pos)] || matching[line.text.charAt(++pos)];
if (!match) return null;
var dir = match.charAt(1) == ">" ? 1 : -1;
if (config && config.strict && dir > 0 != (pos == where.ch)) return null;
var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
if (found == null) return null;
return { from: Pos(where.line, pos), to: found && found.pos,
match: found && found.ch == match.charAt(0), forward: dir > 0 };
}
// bracketRegex is used to specify which type of bracket to scan
// should be a regexp, e.g. /[[\]]/
//
// Note: If "where" is on an open bracket, then this bracket is ignored.
//
// Returns false when no bracket was found, null when it reached
// maxScanLines and gave up
function scanForBracket(cm, where, dir, style, config) {
var maxScanLen = config && config.maxScanLineLength || 10000;
var maxScanLines = config && config.maxScanLines || 1000;
var stack = [];
var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1) : Math.max(cm.firstLine() - 1, where.line - maxScanLines);
for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
var line = cm.getLine(lineNo);
if (!line) continue;
var pos = dir > 0 ? 0 : line.length - 1,
end = dir > 0 ? line.length : -1;
if (line.length > maxScanLen) continue;
if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
for (; pos != end; pos += dir) {
var ch = line.charAt(pos);
if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) {
var match = matching[ch];
if (match.charAt(1) == ">" == dir > 0) stack.push(ch);else if (!stack.length) return { pos: Pos(lineNo, pos), ch: ch };else stack.pop();
}
}
}
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
}
function matchBrackets(cm, autoclear, config) {
// Disable brace matching in long lines, since it'll cause hugely slow updates
var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
var marks = [],
ranges = cm.listSelections();
for (var i = 0; i < ranges.length; i++) {
var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config);
if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), { className: style }));
if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen) marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), { className: style }));
}
}
if (marks.length) {
// Kludge to work around the IE bug from issue #1193, where text
// input stops going to the textare whever this fires.
if (ie_lt8 && cm.state.focused) cm.focus();
var clear = function () {
cm.operation(function () {
for (var i = 0; i < marks.length; i++) marks[i].clear();
});
};
if (autoclear) setTimeout(clear, 800);else return clear;
}
}
function doMatchBrackets(cm) {
cm.operation(function () {
if (cm.state.matchBrackets.currentlyHighlighted) {
cm.state.matchBrackets.currentlyHighlighted();
cm.state.matchBrackets.currentlyHighlighted = null;
}
cm.state.matchBrackets.currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
});
}
CodeMirror.defineOption("matchBrackets", false, function (cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.off("cursorActivity", doMatchBrackets);
if (cm.state.matchBrackets && cm.state.matchBrackets.currentlyHighlighted) {
cm.state.matchBrackets.currentlyHighlighted();
cm.state.matchBrackets.currentlyHighlighted = null;
}
}
if (val) {
cm.state.matchBrackets = typeof val == "object" ? val : {};
cm.on("cursorActivity", doMatchBrackets);
}
});
CodeMirror.defineExtension("matchBrackets", function () {
matchBrackets(this, true);
});
CodeMirror.defineExtension("findMatchingBracket", function (pos, config, oldConfig) {
// Backwards-compatibility kludge
if (oldConfig || typeof config == "boolean") {
if (!oldConfig) {
config = config ? { strict: true } : null;
} else {
oldConfig.strict = config;
config = oldConfig;
}
}
return findMatchingBracket(this, pos, config);
});
CodeMirror.defineExtension("scanForBracket", function (pos, dir, style, config) {
return scanForBracket(this, pos, dir, style, config);
});
});
/***/ }),
/***/ "vCxL":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (immutable) */ __webpack_exports__["__extends"] = __extends;
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
/* harmony export (immutable) */ __webpack_exports__["__rest"] = __rest;
/* harmony export (immutable) */ __webpack_exports__["__decorate"] = __decorate;
/* harmony export (immutable) */ __webpack_exports__["__param"] = __param;
/* harmony export (immutable) */ __webpack_exports__["__metadata"] = __metadata;
/* harmony export (immutable) */ __webpack_exports__["__awaiter"] = __awaiter;
/* harmony export (immutable) */ __webpack_exports__["__generator"] = __generator;
/* harmony export (immutable) */ __webpack_exports__["__exportStar"] = __exportStar;
/* harmony export (immutable) */ __webpack_exports__["__values"] = __values;
/* harmony export (immutable) */ __webpack_exports__["__read"] = __read;
/* harmony export (immutable) */ __webpack_exports__["__spread"] = __spread;
/* harmony export (immutable) */ __webpack_exports__["__await"] = __await;
/* harmony export (immutable) */ __webpack_exports__["__asyncGenerator"] = __asyncGenerator;
/* harmony export (immutable) */ __webpack_exports__["__asyncDelegator"] = __asyncDelegator;
/* harmony export (immutable) */ __webpack_exports__["__asyncValues"] = __asyncValues;
/* harmony export (immutable) */ __webpack_exports__["__makeTemplateObject"] = __makeTemplateObject;
/* harmony export (immutable) */ __webpack_exports__["__importStar"] = __importStar;
/* harmony export (immutable) */ __webpack_exports__["__importDefault"] = __importDefault;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
};
function __extends(d, b) {
extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) {
decorator(target, key, paramIndex);
};
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () {
if (t[0] & 1) throw t[1];return t[1];
}, trys: [], ops: [] },
f,
y,
t,
g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
return this;
}), g;
function verb(n) {
return function (v) {
return step([n, v]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0:case 1:
t = op;break;
case 4:
_.label++;return { value: op[1], done: false };
case 5:
_.label++;y = op[1];op = [0];continue;
case 7:
op = _.ops.pop();_.trys.pop();continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];t = op;break;
}
if (t && _.label < t[2]) {
_.label = t[2];_.ops.push(op);break;
}
if (t[2]) _.ops.pop();
_.trys.pop();continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [6, e];y = 0;
} finally {
f = t = 0;
}
if (op[0] & 5) throw op[1];return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator],
i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
} catch (error) {
e = { error: error };
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []),
i,
q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
return this;
}, i;
function verb(n) {
if (g[n]) i[n] = function (v) {
return new Promise(function (a, b) {
q.push([n, v, a, b]) > 1 || resume(n, v);
});
};
}
function resume(n, v) {
try {
step(g[n](v));
} catch (e) {
settle(q[0][3], e);
}
}
function step(r) {
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
}
function fulfill(value) {
resume("next", value);
}
function reject(value) {
resume("throw", value);
}
function settle(f, v) {
if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
}
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) {
throw e;
}), verb("return"), i[Symbol.iterator] = function () {
return this;
}, i;
function verb(n, f) {
if (o[n]) i[n] = function (v) {
return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
};
}
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator];
return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator]();
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
} else {
cooked.raw = raw;
}
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return mod && mod.__esModule ? mod : { default: mod };
}
/***/ }),
/***/ "vexR":
/***/ (function(module, exports) {
module.exports = function isBuffer(arg) {
return arg && typeof arg === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function';
};
/***/ }),
/***/ "wGjj":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* WEBPACK VAR INJECTION */(function(global) {/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_whatwg_fetch__ = __webpack_require__("MCp7");
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_whatwg_fetch___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_whatwg_fetch__);
// Store setTimeout reference so promise-polyfill will be unaffected by
// other code modifying setTimeout (like sinon.useFakeTimers())
var setTimeoutFunc = setTimeout;
function noop() {}
// Polyfill for Function.prototype.bind
function bind(fn, thisArg) {
return function () {
fn.apply(thisArg, arguments);
};
}
function Promise(fn) {
if (!(this instanceof Promise)) throw new TypeError('Promises must be constructed via new');
if (typeof fn !== 'function') throw new TypeError('not a function');
this._state = 0;
this._handled = false;
this._value = undefined;
this._deferreds = [];
doResolve(fn, this);
}
function handle(self, deferred) {
while (self._state === 3) {
self = self._value;
}
if (self._state === 0) {
self._deferreds.push(deferred);
return;
}
self._handled = true;
Promise._immediateFn(function () {
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
if (cb === null) {
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
return;
}
var ret;
try {
ret = cb(self._value);
} catch (e) {
reject(deferred.promise, e);
return;
}
resolve(deferred.promise, ret);
});
}
function resolve(self, newValue) {
try {
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.');
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
var then = newValue.then;
if (newValue instanceof Promise) {
self._state = 3;
self._value = newValue;
finale(self);
return;
} else if (typeof then === 'function') {
doResolve(bind(then, newValue), self);
return;
}
}
self._state = 1;
self._value = newValue;
finale(self);
} catch (e) {
reject(self, e);
}
}
function reject(self, newValue) {
self._state = 2;
self._value = newValue;
finale(self);
}
function finale(self) {
if (self._state === 2 && self._deferreds.length === 0) {
Promise._immediateFn(function () {
if (!self._handled) {
Promise._unhandledRejectionFn(self._value);
}
});
}
for (var i = 0, len = self._deferreds.length; i < len; i++) {
handle(self, self._deferreds[i]);
}
self._deferreds = null;
}
function Handler(onFulfilled, onRejected, promise) {
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
this.promise = promise;
}
/**
* Take a potentially misbehaving resolver function and make sure
* onFulfilled and onRejected are only called once.
*
* Makes no guarantees about asynchrony.
*/
function doResolve(fn, self) {
var done = false;
try {
fn(function (value) {
if (done) return;
done = true;
resolve(self, value);
}, function (reason) {
if (done) return;
done = true;
reject(self, reason);
});
} catch (ex) {
if (done) return;
done = true;
reject(self, ex);
}
}
Promise.prototype['catch'] = function (onRejected) {
return this.then(null, onRejected);
};
Promise.prototype.then = function (onFulfilled, onRejected) {
var prom = new this.constructor(noop);
handle(this, new Handler(onFulfilled, onRejected, prom));
return prom;
};
Promise.prototype['finally'] = function (callback) {
var constructor = this.constructor;
return this.then(function (value) {
return constructor.resolve(callback()).then(function () {
return value;
});
}, function (reason) {
return constructor.resolve(callback()).then(function () {
return constructor.reject(reason);
});
});
};
Promise.all = function (arr) {
return new Promise(function (resolve, reject) {
if (!arr || typeof arr.length === 'undefined') throw new TypeError('Promise.all accepts an array');
var args = Array.prototype.slice.call(arr);
if (args.length === 0) return resolve([]);
var remaining = args.length;
function res(i, val) {
try {
if (val && (typeof val === 'object' || typeof val === 'function')) {
var then = val.then;
if (typeof then === 'function') {
then.call(val, function (val) {
res(i, val);
}, reject);
return;
}
}
args[i] = val;
if (--remaining === 0) {
resolve(args);
}
} catch (ex) {
reject(ex);
}
}
for (var i = 0; i < args.length; i++) {
res(i, args[i]);
}
});
};
Promise.resolve = function (value) {
if (value && typeof value === 'object' && value.constructor === Promise) {
return value;
}
return new Promise(function (resolve) {
resolve(value);
});
};
Promise.reject = function (value) {
return new Promise(function (resolve, reject) {
reject(value);
});
};
Promise.race = function (values) {
return new Promise(function (resolve, reject) {
for (var i = 0, len = values.length; i < len; i++) {
values[i].then(resolve, reject);
}
});
};
// Use polyfill for setImmediate for performance gains
Promise._immediateFn = typeof setImmediate === 'function' && function (fn) {
setImmediate(fn);
} || function (fn) {
setTimeoutFunc(fn, 0);
};
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
if (typeof console !== 'undefined' && console) {
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console
}
};
var globalNS = function () {
// the only reliable means to get the global object is
// `Function('return this')()`
// However, this causes CSP violations in Chrome apps.
if (typeof self !== 'undefined') {
return self;
}
if (typeof window !== 'undefined') {
return window;
}
if (typeof global !== 'undefined') {
return global;
}
throw new Error('unable to locate global object');
}();
if (!globalNS.Promise) {
globalNS.Promise = Promise;
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var _global = createCommonjsModule(function (module) {
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var global = module.exports = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self
// eslint-disable-next-line no-new-func
: Function('return this')();
if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
});
var _core = createCommonjsModule(function (module) {
var core = module.exports = { version: '2.5.5' };
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
});
var _core_1 = _core.version;
var _isObject = function (it) {
return typeof it === 'object' ? it !== null : typeof it === 'function';
};
var _anObject = function (it) {
if (!_isObject(it)) throw TypeError(it + ' is not an object!');
return it;
};
var _fails = function (exec) {
try {
return !!exec();
} catch (e) {
return true;
}
};
// Thank's IE8 for his funny defineProperty
var _descriptors = !_fails(function () {
return Object.defineProperty({}, 'a', { get: function () {
return 7;
} }).a != 7;
});
var document = _global.document;
// typeof document.createElement is 'object' in old IE
var is = _isObject(document) && _isObject(document.createElement);
var _domCreate = function (it) {
return is ? document.createElement(it) : {};
};
var _ie8DomDefine = !_descriptors && !_fails(function () {
return Object.defineProperty(_domCreate('div'), 'a', { get: function () {
return 7;
} }).a != 7;
});
// 7.1.1 ToPrimitive(input [, PreferredType])
// instead of the ES6 spec version, we didn't implement @@toPrimitive case
// and the second argument - flag - preferred type is a string
var _toPrimitive = function (it, S) {
if (!_isObject(it)) return it;
var fn, val;
if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val;
if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
throw TypeError("Can't convert object to primitive value");
};
var dP = Object.defineProperty;
var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) {
_anObject(O);
P = _toPrimitive(P, true);
_anObject(Attributes);
if (_ie8DomDefine) try {
return dP(O, P, Attributes);
} catch (e) {/* empty */}
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!');
if ('value' in Attributes) O[P] = Attributes.value;
return O;
};
var _objectDp = {
f: f
};
var _propertyDesc = function (bitmap, value) {
return {
enumerable: !(bitmap & 1),
configurable: !(bitmap & 2),
writable: !(bitmap & 4),
value: value
};
};
var _hide = _descriptors ? function (object, key, value) {
return _objectDp.f(object, key, _propertyDesc(1, value));
} : function (object, key, value) {
object[key] = value;
return object;
};
var hasOwnProperty = {}.hasOwnProperty;
var _has = function (it, key) {
return hasOwnProperty.call(it, key);
};
var id = 0;
var px = Math.random();
var _uid = function (key) {
return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
};
var _redefine = createCommonjsModule(function (module) {
var SRC = _uid('src');
var TO_STRING = 'toString';
var $toString = Function[TO_STRING];
var TPL = ('' + $toString).split(TO_STRING);
_core.inspectSource = function (it) {
return $toString.call(it);
};
(module.exports = function (O, key, val, safe) {
var isFunction = typeof val == 'function';
if (isFunction) _has(val, 'name') || _hide(val, 'name', key);
if (O[key] === val) return;
if (isFunction) _has(val, SRC) || _hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
if (O === _global) {
O[key] = val;
} else if (!safe) {
delete O[key];
_hide(O, key, val);
} else if (O[key]) {
O[key] = val;
} else {
_hide(O, key, val);
}
// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
})(Function.prototype, TO_STRING, function toString() {
return typeof this == 'function' && this[SRC] || $toString.call(this);
});
});
var _aFunction = function (it) {
if (typeof it != 'function') throw TypeError(it + ' is not a function!');
return it;
};
// optional / simple context binding
var _ctx = function (fn, that, length) {
_aFunction(fn);
if (that === undefined) return fn;
switch (length) {
case 1:
return function (a) {
return fn.call(that, a);
};
case 2:
return function (a, b) {
return fn.call(that, a, b);
};
case 3:
return function (a, b, c) {
return fn.call(that, a, b, c);
};
}
return function () /* ...args */{
return fn.apply(that, arguments);
};
};
var PROTOTYPE = 'prototype';
var $export = function (type, name, source) {
var IS_FORCED = type & $export.F;
var IS_GLOBAL = type & $export.G;
var IS_STATIC = type & $export.S;
var IS_PROTO = type & $export.P;
var IS_BIND = type & $export.B;
var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] || (_global[name] = {}) : (_global[name] || {})[PROTOTYPE];
var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {});
var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {});
var key, own, out, exp;
if (IS_GLOBAL) source = name;
for (key in source) {
// contains in native
own = !IS_FORCED && target && target[key] !== undefined;
// export native or passed
out = (own ? target : source)[key];
// bind timers to global for call from export context
exp = IS_BIND && own ? _ctx(out, _global) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out;
// extend global
if (target) _redefine(target, key, out, type & $export.U);
// export
if (exports[key] != out) _hide(exports, key, exp);
if (IS_PROTO && expProto[key] != out) expProto[key] = out;
}
};
_global.core = _core;
// type bitmap
$export.F = 1; // forced
$export.G = 2; // global
$export.S = 4; // static
$export.P = 8; // proto
$export.B = 16; // bind
$export.W = 32; // wrap
$export.U = 64; // safe
$export.R = 128; // real proto method for `library`
var _export = $export;
var toString = {}.toString;
var _cof = function (it) {
return toString.call(it).slice(8, -1);
};
// fallback for non-array-like ES3 and non-enumerable old V8 strings
// eslint-disable-next-line no-prototype-builtins
var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) {
return _cof(it) == 'String' ? it.split('') : Object(it);
};
// 7.2.1 RequireObjectCoercible(argument)
var _defined = function (it) {
if (it == undefined) throw TypeError("Can't call method on " + it);
return it;
};
// 7.1.13 ToObject(argument)
var _toObject = function (it) {
return Object(_defined(it));
};
// 7.1.4 ToInteger
var ceil = Math.ceil;
var floor = Math.floor;
var _toInteger = function (it) {
return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
};
// 7.1.15 ToLength
var min = Math.min;
var _toLength = function (it) {
return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
};
// 7.2.2 IsArray(argument)
var _isArray = Array.isArray || function isArray(arg) {
return _cof(arg) == 'Array';
};
var SHARED = '__core-js_shared__';
var store = _global[SHARED] || (_global[SHARED] = {});
var _shared = function (key) {
return store[key] || (store[key] = {});
};
var _wks = createCommonjsModule(function (module) {
var store = _shared('wks');
var Symbol = _global.Symbol;
var USE_SYMBOL = typeof Symbol == 'function';
var $exports = module.exports = function (name) {
return store[name] || (store[name] = USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name));
};
$exports.store = store;
});
var SPECIES = _wks('species');
var _arraySpeciesConstructor = function (original) {
var C;
if (_isArray(original)) {
C = original.constructor;
// cross-realm fallback
if (typeof C == 'function' && (C === Array || _isArray(C.prototype))) C = undefined;
if (_isObject(C)) {
C = C[SPECIES];
if (C === null) C = undefined;
}
}return C === undefined ? Array : C;
};
// 9.4.2.3 ArraySpeciesCreate(originalArray, length)
var _arraySpeciesCreate = function (original, length) {
return new (_arraySpeciesConstructor(original))(length);
};
// 0 -> Array#forEach
// 1 -> Array#map
// 2 -> Array#filter
// 3 -> Array#some
// 4 -> Array#every
// 5 -> Array#find
// 6 -> Array#findIndex
var _arrayMethods = function (TYPE, $create) {
var IS_MAP = TYPE == 1;
var IS_FILTER = TYPE == 2;
var IS_SOME = TYPE == 3;
var IS_EVERY = TYPE == 4;
var IS_FIND_INDEX = TYPE == 6;
var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
var create = $create || _arraySpeciesCreate;
return function ($this, callbackfn, that) {
var O = _toObject($this);
var self = _iobject(O);
var f = _ctx(callbackfn, that, 3);
var length = _toLength(self.length);
var index = 0;
var result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
var val, res;
for (; length > index; index++) if (NO_HOLES || index in self) {
val = self[index];
res = f(val, index, O);
if (TYPE) {
if (IS_MAP) result[index] = res; // map
else if (res) switch (TYPE) {
case 3:
return true; // some
case 5:
return val; // find
case 6:
return index; // findIndex
case 2:
result.push(val); // filter
} else if (IS_EVERY) return false; // every
}
}
return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result;
};
};
// 22.1.3.31 Array.prototype[@@unscopables]
var UNSCOPABLES = _wks('unscopables');
var ArrayProto = Array.prototype;
if (ArrayProto[UNSCOPABLES] == undefined) _hide(ArrayProto, UNSCOPABLES, {});
var _addToUnscopables = function (key) {
ArrayProto[UNSCOPABLES][key] = true;
};
// 22.1.3.8 Array.prototype.find(predicate, thisArg = undefined)
var $find = _arrayMethods(5);
var KEY = 'find';
var forced = true;
// Shouldn't skip holes
if (KEY in []) Array(1)[KEY](function () {
forced = false;
});
_export(_export.P + _export.F * forced, 'Array', {
find: function find(callbackfn /* , that = undefined */) {
return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
}
});
_addToUnscopables(KEY);
var find = _core.Array.find;
// 22.1.3.9 Array.prototype.findIndex(predicate, thisArg = undefined)
var $find$1 = _arrayMethods(6);
var KEY$1 = 'findIndex';
var forced$1 = true;
// Shouldn't skip holes
if (KEY$1 in []) Array(1)[KEY$1](function () {
forced$1 = false;
});
_export(_export.P + _export.F * forced$1, 'Array', {
findIndex: function findIndex(callbackfn /* , that = undefined */) {
return $find$1(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
}
});
_addToUnscopables(KEY$1);
var findIndex = _core.Array.findIndex;
// to indexed object, toObject with fallback for non-array-like ES3 strings
var _toIobject = function (it) {
return _iobject(_defined(it));
};
var max = Math.max;
var min$1 = Math.min;
var _toAbsoluteIndex = function (index, length) {
index = _toInteger(index);
return index < 0 ? max(index + length, 0) : min$1(index, length);
};
// false -> Array#indexOf
// true -> Array#includes
var _arrayIncludes = function (IS_INCLUDES) {
return function ($this, el, fromIndex) {
var O = _toIobject($this);
var length = _toLength(O.length);
var index = _toAbsoluteIndex(fromIndex, length);
var value;
// Array#includes uses SameValueZero equality algorithm
// eslint-disable-next-line no-self-compare
if (IS_INCLUDES && el != el) while (length > index) {
value = O[index++];
// eslint-disable-next-line no-self-compare
if (value != value) return true;
// Array#indexOf ignores holes, Array#includes - not
} else for (; length > index; index++) if (IS_INCLUDES || index in O) {
if (O[index] === el) return IS_INCLUDES || index || 0;
}return !IS_INCLUDES && -1;
};
};
var shared = _shared('keys');
var _sharedKey = function (key) {
return shared[key] || (shared[key] = _uid(key));
};
var arrayIndexOf = _arrayIncludes(false);
var IE_PROTO = _sharedKey('IE_PROTO');
var _objectKeysInternal = function (object, names) {
var O = _toIobject(object);
var i = 0;
var result = [];
var key;
for (key in O) if (key != IE_PROTO) _has(O, key) && result.push(key);
// Don't enum bug & hidden keys
while (names.length > i) if (_has(O, key = names[i++])) {
~arrayIndexOf(result, key) || result.push(key);
}
return result;
};
// IE 8- don't enum bug keys
var _enumBugKeys = 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'.split(',');
// 19.1.2.14 / 15.2.3.14 Object.keys(O)
var _objectKeys = Object.keys || function keys(O) {
return _objectKeysInternal(O, _enumBugKeys);
};
var f$1 = Object.getOwnPropertySymbols;
var _objectGops = {
f: f$1
};
var f$2 = {}.propertyIsEnumerable;
var _objectPie = {
f: f$2
};
// 19.1.2.1 Object.assign(target, source, ...)
var $assign = Object.assign;
// should work with symbols and should have deterministic property order (V8 bug)
var _objectAssign = !$assign || _fails(function () {
var A = {};
var B = {};
// eslint-disable-next-line no-undef
var S = Symbol();
var K = 'abcdefghijklmnopqrst';
A[S] = 7;
K.split('').forEach(function (k) {
B[k] = k;
});
return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
}) ? function assign(target, source) {
// eslint-disable-line no-unused-vars
var T = _toObject(target);
var aLen = arguments.length;
var index = 1;
var getSymbols = _objectGops.f;
var isEnum = _objectPie.f;
while (aLen > index) {
var S = _iobject(arguments[index++]);
var keys = getSymbols ? _objectKeys(S).concat(getSymbols(S)) : _objectKeys(S);
var length = keys.length;
var j = 0;
var key;
while (length > j) if (isEnum.call(S, key = keys[j++])) T[key] = S[key];
}return T;
} : $assign;
// 19.1.3.1 Object.assign(target, source)
_export(_export.S + _export.F, 'Object', { assign: _objectAssign });
var assign = _core.Object.assign;
// 7.2.8 IsRegExp(argument)
var MATCH = _wks('match');
var _isRegexp = function (it) {
var isRegExp;
return _isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : _cof(it) == 'RegExp');
};
// helper for String#{startsWith, endsWith, includes}
var _stringContext = function (that, searchString, NAME) {
if (_isRegexp(searchString)) throw TypeError('String#' + NAME + " doesn't accept regex!");
return String(_defined(that));
};
var MATCH$1 = _wks('match');
var _failsIsRegexp = function (KEY) {
var re = /./;
try {
'/./'[KEY](re);
} catch (e) {
try {
re[MATCH$1] = false;
return !'/./'[KEY](re);
} catch (f) {/* empty */}
}return true;
};
var STARTS_WITH = 'startsWith';
var $startsWith = ''[STARTS_WITH];
_export(_export.P + _export.F * _failsIsRegexp(STARTS_WITH), 'String', {
startsWith: function startsWith(searchString /* , position = 0 */) {
var that = _stringContext(this, searchString, STARTS_WITH);
var index = _toLength(Math.min(arguments.length > 1 ? arguments[1] : undefined, that.length));
var search = String(searchString);
return $startsWith ? $startsWith.call(that, search, index) : that.slice(index, index + search.length) === search;
}
});
var startsWith = _core.String.startsWith;
var _stringRepeat = function repeat(count) {
var str = String(_defined(this));
var res = '';
var n = _toInteger(count);
if (n < 0 || n == Infinity) throw RangeError("Count can't be negative");
for (; n > 0; (n >>>= 1) && (str += str)) if (n & 1) res += str;
return res;
};
_export(_export.P, 'String', {
// 21.1.3.13 String.prototype.repeat(count)
repeat: _stringRepeat
});
var repeat = _core.String.repeat;
var _meta = createCommonjsModule(function (module) {
var META = _uid('meta');
var setDesc = _objectDp.f;
var id = 0;
var isExtensible = Object.isExtensible || function () {
return true;
};
var FREEZE = !_fails(function () {
return isExtensible(Object.preventExtensions({}));
});
var setMeta = function (it) {
setDesc(it, META, { value: {
i: 'O' + ++id, // object ID
w: {} // weak collections IDs
} });
};
var fastKey = function (it, create) {
// return primitive with prefix
if (!_isObject(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it;
if (!_has(it, META)) {
// can't set metadata to uncaught frozen object
if (!isExtensible(it)) return 'F';
// not necessary to add metadata
if (!create) return 'E';
// add missing metadata
setMeta(it);
// return object ID
}return it[META].i;
};
var getWeak = function (it, create) {
if (!_has(it, META)) {
// can't set metadata to uncaught frozen object
if (!isExtensible(it)) return true;
// not necessary to add metadata
if (!create) return false;
// add missing metadata
setMeta(it);
// return hash weak collections IDs
}return it[META].w;
};
// add metadata on freeze-family methods calling
var onFreeze = function (it) {
if (FREEZE && meta.NEED && isExtensible(it) && !_has(it, META)) setMeta(it);
return it;
};
var meta = module.exports = {
KEY: META,
NEED: false,
fastKey: fastKey,
getWeak: getWeak,
onFreeze: onFreeze
};
});
var _meta_1 = _meta.KEY;
var _meta_2 = _meta.NEED;
var _meta_3 = _meta.fastKey;
var _meta_4 = _meta.getWeak;
var _meta_5 = _meta.onFreeze;
var def = _objectDp.f;
var TAG = _wks('toStringTag');
var _setToStringTag = function (it, tag, stat) {
if (it && !_has(it = stat ? it : it.prototype, TAG)) def(it, TAG, { configurable: true, value: tag });
};
var f$3 = _wks;
var _wksExt = {
f: f$3
};
var _library = false;
var defineProperty = _objectDp.f;
var _wksDefine = function (name) {
var $Symbol = _core.Symbol || (_core.Symbol = _library ? {} : _global.Symbol || {});
if (name.charAt(0) != '_' && !(name in $Symbol)) defineProperty($Symbol, name, { value: _wksExt.f(name) });
};
// all enumerable object keys, includes symbols
var _enumKeys = function (it) {
var result = _objectKeys(it);
var getSymbols = _objectGops.f;
if (getSymbols) {
var symbols = getSymbols(it);
var isEnum = _objectPie.f;
var i = 0;
var key;
while (symbols.length > i) if (isEnum.call(it, key = symbols[i++])) result.push(key);
}return result;
};
var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
_anObject(O);
var keys = _objectKeys(Properties);
var length = keys.length;
var i = 0;
var P;
while (length > i) _objectDp.f(O, P = keys[i++], Properties[P]);
return O;
};
var document$1 = _global.document;
var _html = document$1 && document$1.documentElement;
// 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
var IE_PROTO$1 = _sharedKey('IE_PROTO');
var Empty = function () {/* empty */};
var PROTOTYPE$1 = 'prototype';
// Create object with fake `null` prototype: use iframe Object with cleared prototype
var createDict = function () {
// Thrash, waste and sodomy: IE GC bug
var iframe = _domCreate('iframe');
var i = _enumBugKeys.length;
var lt = '<';
var gt = '>';
var iframeDocument;
iframe.style.display = 'none';
_html.appendChild(iframe);
iframe.src = 'javascript:'; // eslint-disable-line no-script-url
// createDict = iframe.contentWindow.Object;
// html.removeChild(iframe);
iframeDocument = iframe.contentWindow.document;
iframeDocument.open();
iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
iframeDocument.close();
createDict = iframeDocument.F;
while (i--) delete createDict[PROTOTYPE$1][_enumBugKeys[i]];
return createDict();
};
var _objectCreate = Object.create || function create(O, Properties) {
var result;
if (O !== null) {
Empty[PROTOTYPE$1] = _anObject(O);
result = new Empty();
Empty[PROTOTYPE$1] = null;
// add "__proto__" for Object.getPrototypeOf polyfill
result[IE_PROTO$1] = O;
} else result = createDict();
return Properties === undefined ? result : _objectDps(result, Properties);
};
// 19.1.2.7 / 15.2.3.4 Object.getOwnPropertyNames(O)
var hiddenKeys = _enumBugKeys.concat('length', 'prototype');
var f$4 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
return _objectKeysInternal(O, hiddenKeys);
};
var _objectGopn = {
f: f$4
};
// fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window
var gOPN = _objectGopn.f;
var toString$1 = {}.toString;
var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames ? Object.getOwnPropertyNames(window) : [];
var getWindowNames = function (it) {
try {
return gOPN(it);
} catch (e) {
return windowNames.slice();
}
};
var f$5 = function getOwnPropertyNames(it) {
return windowNames && toString$1.call(it) == '[object Window]' ? getWindowNames(it) : gOPN(_toIobject(it));
};
var _objectGopnExt = {
f: f$5
};
var gOPD = Object.getOwnPropertyDescriptor;
var f$6 = _descriptors ? gOPD : function getOwnPropertyDescriptor(O, P) {
O = _toIobject(O);
P = _toPrimitive(P, true);
if (_ie8DomDefine) try {
return gOPD(O, P);
} catch (e) {/* empty */}
if (_has(O, P)) return _propertyDesc(!_objectPie.f.call(O, P), O[P]);
};
var _objectGopd = {
f: f$6
};
// ECMAScript 6 symbols shim
var META = _meta.KEY;
var gOPD$1 = _objectGopd.f;
var dP$1 = _objectDp.f;
var gOPN$1 = _objectGopnExt.f;
var $Symbol = _global.Symbol;
var $JSON = _global.JSON;
var _stringify = $JSON && $JSON.stringify;
var PROTOTYPE$2 = 'prototype';
var HIDDEN = _wks('_hidden');
var TO_PRIMITIVE = _wks('toPrimitive');
var isEnum = {}.propertyIsEnumerable;
var SymbolRegistry = _shared('symbol-registry');
var AllSymbols = _shared('symbols');
var OPSymbols = _shared('op-symbols');
var ObjectProto = Object[PROTOTYPE$2];
var USE_NATIVE = typeof $Symbol == 'function';
var QObject = _global.QObject;
// Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
var setter = !QObject || !QObject[PROTOTYPE$2] || !QObject[PROTOTYPE$2].findChild;
// fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
var setSymbolDesc = _descriptors && _fails(function () {
return _objectCreate(dP$1({}, 'a', {
get: function () {
return dP$1(this, 'a', { value: 7 }).a;
}
})).a != 7;
}) ? function (it, key, D) {
var protoDesc = gOPD$1(ObjectProto, key);
if (protoDesc) delete ObjectProto[key];
dP$1(it, key, D);
if (protoDesc && it !== ObjectProto) dP$1(ObjectProto, key, protoDesc);
} : dP$1;
var wrap = function (tag) {
var sym = AllSymbols[tag] = _objectCreate($Symbol[PROTOTYPE$2]);
sym._k = tag;
return sym;
};
var isSymbol = USE_NATIVE && typeof $Symbol.iterator == 'symbol' ? function (it) {
return typeof it == 'symbol';
} : function (it) {
return it instanceof $Symbol;
};
var $defineProperty = function defineProperty(it, key, D) {
if (it === ObjectProto) $defineProperty(OPSymbols, key, D);
_anObject(it);
key = _toPrimitive(key, true);
_anObject(D);
if (_has(AllSymbols, key)) {
if (!D.enumerable) {
if (!_has(it, HIDDEN)) dP$1(it, HIDDEN, _propertyDesc(1, {}));
it[HIDDEN][key] = true;
} else {
if (_has(it, HIDDEN) && it[HIDDEN][key]) it[HIDDEN][key] = false;
D = _objectCreate(D, { enumerable: _propertyDesc(0, false) });
}return setSymbolDesc(it, key, D);
}return dP$1(it, key, D);
};
var $defineProperties = function defineProperties(it, P) {
_anObject(it);
var keys = _enumKeys(P = _toIobject(P));
var i = 0;
var l = keys.length;
var key;
while (l > i) $defineProperty(it, key = keys[i++], P[key]);
return it;
};
var $create = function create(it, P) {
return P === undefined ? _objectCreate(it) : $defineProperties(_objectCreate(it), P);
};
var $propertyIsEnumerable = function propertyIsEnumerable(key) {
var E = isEnum.call(this, key = _toPrimitive(key, true));
if (this === ObjectProto && _has(AllSymbols, key) && !_has(OPSymbols, key)) return false;
return E || !_has(this, key) || !_has(AllSymbols, key) || _has(this, HIDDEN) && this[HIDDEN][key] ? E : true;
};
var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(it, key) {
it = _toIobject(it);
key = _toPrimitive(key, true);
if (it === ObjectProto && _has(AllSymbols, key) && !_has(OPSymbols, key)) return;
var D = gOPD$1(it, key);
if (D && _has(AllSymbols, key) && !(_has(it, HIDDEN) && it[HIDDEN][key])) D.enumerable = true;
return D;
};
var $getOwnPropertyNames = function getOwnPropertyNames(it) {
var names = gOPN$1(_toIobject(it));
var result = [];
var i = 0;
var key;
while (names.length > i) {
if (!_has(AllSymbols, key = names[i++]) && key != HIDDEN && key != META) result.push(key);
}return result;
};
var $getOwnPropertySymbols = function getOwnPropertySymbols(it) {
var IS_OP = it === ObjectProto;
var names = gOPN$1(IS_OP ? OPSymbols : _toIobject(it));
var result = [];
var i = 0;
var key;
while (names.length > i) {
if (_has(AllSymbols, key = names[i++]) && (IS_OP ? _has(ObjectProto, key) : true)) result.push(AllSymbols[key]);
}return result;
};
// 19.4.1.1 Symbol([description])
if (!USE_NATIVE) {
$Symbol = function Symbol() {
if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor!');
var tag = _uid(arguments.length > 0 ? arguments[0] : undefined);
var $set = function (value) {
if (this === ObjectProto) $set.call(OPSymbols, value);
if (_has(this, HIDDEN) && _has(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
setSymbolDesc(this, tag, _propertyDesc(1, value));
};
if (_descriptors && setter) setSymbolDesc(ObjectProto, tag, { configurable: true, set: $set });
return wrap(tag);
};
_redefine($Symbol[PROTOTYPE$2], 'toString', function toString() {
return this._k;
});
_objectGopd.f = $getOwnPropertyDescriptor;
_objectDp.f = $defineProperty;
_objectGopn.f = _objectGopnExt.f = $getOwnPropertyNames;
_objectPie.f = $propertyIsEnumerable;
_objectGops.f = $getOwnPropertySymbols;
if (_descriptors && !_library) {
_redefine(ObjectProto, 'propertyIsEnumerable', $propertyIsEnumerable, true);
}
_wksExt.f = function (name) {
return wrap(_wks(name));
};
}
_export(_export.G + _export.W + _export.F * !USE_NATIVE, { Symbol: $Symbol });
for (var es6Symbols =
// 19.4.2.2, 19.4.2.3, 19.4.2.4, 19.4.2.6, 19.4.2.8, 19.4.2.9, 19.4.2.10, 19.4.2.11, 19.4.2.12, 19.4.2.13, 19.4.2.14
'hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables'.split(','), j = 0; es6Symbols.length > j;) _wks(es6Symbols[j++]);
for (var wellKnownSymbols = _objectKeys(_wks.store), k = 0; wellKnownSymbols.length > k;) _wksDefine(wellKnownSymbols[k++]);
_export(_export.S + _export.F * !USE_NATIVE, 'Symbol', {
// 19.4.2.1 Symbol.for(key)
'for': function (key) {
return _has(SymbolRegistry, key += '') ? SymbolRegistry[key] : SymbolRegistry[key] = $Symbol(key);
},
// 19.4.2.5 Symbol.keyFor(sym)
keyFor: function keyFor(sym) {
if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol!');
for (var key in SymbolRegistry) if (SymbolRegistry[key] === sym) return key;
},
useSetter: function () {
setter = true;
},
useSimple: function () {
setter = false;
}
});
_export(_export.S + _export.F * !USE_NATIVE, 'Object', {
// 19.1.2.2 Object.create(O [, Properties])
create: $create,
// 19.1.2.4 Object.defineProperty(O, P, Attributes)
defineProperty: $defineProperty,
// 19.1.2.3 Object.defineProperties(O, Properties)
defineProperties: $defineProperties,
// 19.1.2.6 Object.getOwnPropertyDescriptor(O, P)
getOwnPropertyDescriptor: $getOwnPropertyDescriptor,
// 19.1.2.7 Object.getOwnPropertyNames(O)
getOwnPropertyNames: $getOwnPropertyNames,
// 19.1.2.8 Object.getOwnPropertySymbols(O)
getOwnPropertySymbols: $getOwnPropertySymbols
});
// 24.3.2 JSON.stringify(value [, replacer [, space]])
$JSON && _export(_export.S + _export.F * (!USE_NATIVE || _fails(function () {
var S = $Symbol();
// MS Edge converts symbol values to JSON as {}
// WebKit converts symbol values to JSON as null
// V8 throws on boxed symbols
return _stringify([S]) != '[null]' || _stringify({ a: S }) != '{}' || _stringify(Object(S)) != '{}';
})), 'JSON', {
stringify: function stringify(it) {
var args = [it];
var i = 1;
var replacer, $replacer;
while (arguments.length > i) args.push(arguments[i++]);
$replacer = replacer = args[1];
if (!_isObject(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined
if (!_isArray(replacer)) replacer = function (key, value) {
if (typeof $replacer == 'function') value = $replacer.call(this, key, value);
if (!isSymbol(value)) return value;
};
args[1] = replacer;
return _stringify.apply($JSON, args);
}
});
// 19.4.3.4 Symbol.prototype[@@toPrimitive](hint)
$Symbol[PROTOTYPE$2][TO_PRIMITIVE] || _hide($Symbol[PROTOTYPE$2], TO_PRIMITIVE, $Symbol[PROTOTYPE$2].valueOf);
// 19.4.3.5 Symbol.prototype[@@toStringTag]
_setToStringTag($Symbol, 'Symbol');
// 20.2.1.9 Math[@@toStringTag]
_setToStringTag(Math, 'Math', true);
// 24.3.3 JSON[@@toStringTag]
_setToStringTag(_global.JSON, 'JSON', true);
// getting tag from 19.1.3.6 Object.prototype.toString()
var TAG$1 = _wks('toStringTag');
// ES3 wrong here
var ARG = _cof(function () {
return arguments;
}()) == 'Arguments';
// fallback for IE11 Script Access Denied error
var tryGet = function (it, key) {
try {
return it[key];
} catch (e) {/* empty */}
};
var _classof = function (it) {
var O, T, B;
return it === undefined ? 'Undefined' : it === null ? 'Null'
// @@toStringTag case
: typeof (T = tryGet(O = Object(it), TAG$1)) == 'string' ? T
// builtinTag case
: ARG ? _cof(O)
// ES3 arguments fallback
: (B = _cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B;
};
// 19.1.3.6 Object.prototype.toString()
var test = {};
test[_wks('toStringTag')] = 'z';
if (test + '' != '[object z]') {
_redefine(Object.prototype, 'toString', function toString() {
return '[object ' + _classof(this) + ']';
}, true);
}
_wksDefine('asyncIterator');
_wksDefine('observable');
var symbol = _core.Symbol;
// true -> String#at
// false -> String#codePointAt
var _stringAt = function (TO_STRING) {
return function (that, pos) {
var s = String(_defined(that));
var i = _toInteger(pos);
var l = s.length;
var a, b;
if (i < 0 || i >= l) return TO_STRING ? '' : undefined;
a = s.charCodeAt(i);
return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff ? TO_STRING ? s.charAt(i) : a : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000;
};
};
var _iterators = {};
var IteratorPrototype = {};
// 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
_hide(IteratorPrototype, _wks('iterator'), function () {
return this;
});
var _iterCreate = function (Constructor, NAME, next) {
Constructor.prototype = _objectCreate(IteratorPrototype, { next: _propertyDesc(1, next) });
_setToStringTag(Constructor, NAME + ' Iterator');
};
// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
var IE_PROTO$2 = _sharedKey('IE_PROTO');
var ObjectProto$1 = Object.prototype;
var _objectGpo = Object.getPrototypeOf || function (O) {
O = _toObject(O);
if (_has(O, IE_PROTO$2)) return O[IE_PROTO$2];
if (typeof O.constructor == 'function' && O instanceof O.constructor) {
return O.constructor.prototype;
}return O instanceof Object ? ObjectProto$1 : null;
};
var ITERATOR = _wks('iterator');
var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next`
var FF_ITERATOR = '@@iterator';
var KEYS = 'keys';
var VALUES = 'values';
var returnThis = function () {
return this;
};
var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) {
_iterCreate(Constructor, NAME, next);
var getMethod = function (kind) {
if (!BUGGY && kind in proto) return proto[kind];
switch (kind) {
case KEYS:
return function keys() {
return new Constructor(this, kind);
};
case VALUES:
return function values() {
return new Constructor(this, kind);
};
}return function entries() {
return new Constructor(this, kind);
};
};
var TAG = NAME + ' Iterator';
var DEF_VALUES = DEFAULT == VALUES;
var VALUES_BUG = false;
var proto = Base.prototype;
var $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT];
var $default = $native || getMethod(DEFAULT);
var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined;
var $anyNative = NAME == 'Array' ? proto.entries || $native : $native;
var methods, key, IteratorPrototype;
// Fix native
if ($anyNative) {
IteratorPrototype = _objectGpo($anyNative.call(new Base()));
if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) {
// Set @@toStringTag to native iterators
_setToStringTag(IteratorPrototype, TAG, true);
// fix for some old engines
if (!_library && typeof IteratorPrototype[ITERATOR] != 'function') _hide(IteratorPrototype, ITERATOR, returnThis);
}
}
// fix Array#{values, @@iterator}.name in V8 / FF
if (DEF_VALUES && $native && $native.name !== VALUES) {
VALUES_BUG = true;
$default = function values() {
return $native.call(this);
};
}
// Define iterator
if ((!_library || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])) {
_hide(proto, ITERATOR, $default);
}
// Plug for library
_iterators[NAME] = $default;
_iterators[TAG] = returnThis;
if (DEFAULT) {
methods = {
values: DEF_VALUES ? $default : getMethod(VALUES),
keys: IS_SET ? $default : getMethod(KEYS),
entries: $entries
};
if (FORCED) for (key in methods) {
if (!(key in proto)) _redefine(proto, key, methods[key]);
} else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods);
}
return methods;
};
var $at = _stringAt(true);
// 21.1.3.27 String.prototype[@@iterator]()
_iterDefine(String, 'String', function (iterated) {
this._t = String(iterated); // target
this._i = 0; // next index
// 21.1.5.2.1 %StringIteratorPrototype%.next()
}, function () {
var O = this._t;
var index = this._i;
var point;
if (index >= O.length) return { value: undefined, done: true };
point = $at(O, index);
this._i += point.length;
return { value: point, done: false };
});
var _iterStep = function (done, value) {
return { value: value, done: !!done };
};
// 22.1.3.4 Array.prototype.entries()
// 22.1.3.13 Array.prototype.keys()
// 22.1.3.29 Array.prototype.values()
// 22.1.3.30 Array.prototype[@@iterator]()
var es6_array_iterator = _iterDefine(Array, 'Array', function (iterated, kind) {
this._t = _toIobject(iterated); // target
this._i = 0; // next index
this._k = kind; // kind
// 22.1.5.2.1 %ArrayIteratorPrototype%.next()
}, function () {
var O = this._t;
var kind = this._k;
var index = this._i++;
if (!O || index >= O.length) {
this._t = undefined;
return _iterStep(1);
}
if (kind == 'keys') return _iterStep(0, index);
if (kind == 'values') return _iterStep(0, O[index]);
return _iterStep(0, [index, O[index]]);
}, 'values');
// argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7)
_iterators.Arguments = _iterators.Array;
_addToUnscopables('keys');
_addToUnscopables('values');
_addToUnscopables('entries');
var ITERATOR$1 = _wks('iterator');
var TO_STRING_TAG = _wks('toStringTag');
var ArrayValues = _iterators.Array;
var DOMIterables = {
CSSRuleList: true, // TODO: Not spec compliant, should be false.
CSSStyleDeclaration: false,
CSSValueList: false,
ClientRectList: false,
DOMRectList: false,
DOMStringList: false,
DOMTokenList: true,
DataTransferItemList: false,
FileList: false,
HTMLAllCollection: false,
HTMLCollection: false,
HTMLFormElement: false,
HTMLSelectElement: false,
MediaList: true, // TODO: Not spec compliant, should be false.
MimeTypeArray: false,
NamedNodeMap: false,
NodeList: true,
PaintRequestList: false,
Plugin: false,
PluginArray: false,
SVGLengthList: false,
SVGNumberList: false,
SVGPathSegList: false,
SVGPointList: false,
SVGStringList: false,
SVGTransformList: false,
SourceBufferList: false,
StyleSheetList: true, // TODO: Not spec compliant, should be false.
TextTrackCueList: false,
TextTrackList: false,
TouchList: false
};
for (var collections = _objectKeys(DOMIterables), i = 0; i < collections.length; i++) {
var NAME = collections[i];
var explicit = DOMIterables[NAME];
var Collection = _global[NAME];
var proto = Collection && Collection.prototype;
var key;
if (proto) {
if (!proto[ITERATOR$1]) _hide(proto, ITERATOR$1, ArrayValues);
if (!proto[TO_STRING_TAG]) _hide(proto, TO_STRING_TAG, NAME);
_iterators[NAME] = ArrayValues;
if (explicit) for (key in es6_array_iterator) if (!proto[key]) _redefine(proto, key, es6_array_iterator[key], true);
}
}
var iterator = _wksExt.f('iterator');
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* WEBPACK VAR INJECTION */}.call(__webpack_exports__, __webpack_require__("h6ac")))
/***/ }),
/***/ "xdvC":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("1JcR"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../fold/xml-fold"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
CodeMirror.defineOption("matchTags", false, function (cm, val, old) {
if (old && old != CodeMirror.Init) {
cm.off("cursorActivity", doMatchTags);
cm.off("viewportChange", maybeUpdateMatch);
clear(cm);
}
if (val) {
cm.state.matchBothTags = typeof val == "object" && val.bothTags;
cm.on("cursorActivity", doMatchTags);
cm.on("viewportChange", maybeUpdateMatch);
doMatchTags(cm);
}
});
function clear(cm) {
if (cm.state.tagHit) cm.state.tagHit.clear();
if (cm.state.tagOther) cm.state.tagOther.clear();
cm.state.tagHit = cm.state.tagOther = null;
}
function doMatchTags(cm) {
cm.state.failedTagMatch = false;
cm.operation(function () {
clear(cm);
if (cm.somethingSelected()) return;
var cur = cm.getCursor(),
range = cm.getViewport();
range.from = Math.min(range.from, cur.line);range.to = Math.max(cur.line + 1, range.to);
var match = CodeMirror.findMatchingTag(cm, cur, range);
if (!match) return;
if (cm.state.matchBothTags) {
var hit = match.at == "open" ? match.open : match.close;
if (hit) cm.state.tagHit = cm.markText(hit.from, hit.to, { className: "CodeMirror-matchingtag" });
}
var other = match.at == "close" ? match.open : match.close;
if (other) cm.state.tagOther = cm.markText(other.from, other.to, { className: "CodeMirror-matchingtag" });else cm.state.failedTagMatch = true;
});
}
function maybeUpdateMatch(cm) {
if (cm.state.failedTagMatch) doMatchTags(cm);
}
CodeMirror.commands.toMatchingTag = function (cm) {
var found = CodeMirror.findMatchingTag(cm, cm.getCursor());
if (found) {
var other = found.at == "close" ? found.open : found.close;
if (other) cm.extendSelection(other.to, other.from);
}
};
});
/***/ }),
/***/ "yLr7":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
/**
* Supported keybindings:
* Too many to list. Refer to defaultKeyMap below.
*
* Supported Ex commands:
* Refer to defaultExCommandMap below.
*
* Registers: unnamed, -, a-z, A-Z, 0-9
* (Does not respect the special case for number registers when delete
* operator is made with these commands: %, (, ), , /, ?, n, N, {, } )
* TODO: Implement the remaining registers.
*
* Marks: a-z, A-Z, and 0-9
* TODO: Implement the remaining special marks. They have more complex
* behavior.
*
* Events:
* 'vim-mode-change' - raised on the editor anytime the current mode changes,
* Event object: {mode: "visual", subMode: "linewise"}
*
* Code structure:
* 1. Default keymap
* 2. Variable declarations and short basic helpers
* 3. Instance (External API) implementation
* 4. Internal state tracking objects (input state, counter) implementation
* and instantiation
* 5. Key handler (the main command dispatcher) implementation
* 6. Motion, operator, and action implementations
* 7. Helper functions for the key handler, motions, operators, and actions
* 8. Set up Vim to work as a keymap for CodeMirror.
* 9. Ex command implementations.
*/
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"), __webpack_require__("29F7"), __webpack_require__("4e7A"), __webpack_require__("uQIK"));else if (typeof define == "function" && define.amd) // AMD
define(["../lib/codemirror", "../addon/search/searchcursor", "../addon/dialog/dialog", "../addon/edit/matchbrackets"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
'use strict';
var defaultKeymap = [
// Key to key mapping. This goes first to make it possible to override
// existing mappings.
{ keys: '<Left>', type: 'keyToKey', toKeys: 'h' }, { keys: '<Right>', type: 'keyToKey', toKeys: 'l' }, { keys: '<Up>', type: 'keyToKey', toKeys: 'k' }, { keys: '<Down>', type: 'keyToKey', toKeys: 'j' }, { keys: '<Space>', type: 'keyToKey', toKeys: 'l' }, { keys: '<BS>', type: 'keyToKey', toKeys: 'h', context: 'normal' }, { keys: '<C-Space>', type: 'keyToKey', toKeys: 'W' }, { keys: '<C-BS>', type: 'keyToKey', toKeys: 'B', context: 'normal' }, { keys: '<S-Space>', type: 'keyToKey', toKeys: 'w' }, { keys: '<S-BS>', type: 'keyToKey', toKeys: 'b', context: 'normal' }, { keys: '<C-n>', type: 'keyToKey', toKeys: 'j' }, { keys: '<C-p>', type: 'keyToKey', toKeys: 'k' }, { keys: '<C-[>', type: 'keyToKey', toKeys: '<Esc>' }, { keys: '<C-c>', type: 'keyToKey', toKeys: '<Esc>' }, { keys: '<C-[>', type: 'keyToKey', toKeys: '<Esc>', context: 'insert' }, { keys: '<C-c>', type: 'keyToKey', toKeys: '<Esc>', context: 'insert' }, { keys: 's', type: 'keyToKey', toKeys: 'cl', context: 'normal' }, { keys: 's', type: 'keyToKey', toKeys: 'c', context: 'visual' }, { keys: 'S', type: 'keyToKey', toKeys: 'cc', context: 'normal' }, { keys: 'S', type: 'keyToKey', toKeys: 'VdO', context: 'visual' }, { keys: '<Home>', type: 'keyToKey', toKeys: '0' }, { keys: '<End>', type: 'keyToKey', toKeys: '$' }, { keys: '<PageUp>', type: 'keyToKey', toKeys: '<C-b>' }, { keys: '<PageDown>', type: 'keyToKey', toKeys: '<C-f>' }, { keys: '<CR>', type: 'keyToKey', toKeys: 'j^', context: 'normal' }, { keys: '<Ins>', type: 'action', action: 'toggleOverwrite', context: 'insert' },
// Motions
{ keys: 'H', type: 'motion', motion: 'moveToTopLine', motionArgs: { linewise: true, toJumplist: true } }, { keys: 'M', type: 'motion', motion: 'moveToMiddleLine', motionArgs: { linewise: true, toJumplist: true } }, { keys: 'L', type: 'motion', motion: 'moveToBottomLine', motionArgs: { linewise: true, toJumplist: true } }, { keys: 'h', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: false } }, { keys: 'l', type: 'motion', motion: 'moveByCharacters', motionArgs: { forward: true } }, { keys: 'j', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, linewise: true } }, { keys: 'k', type: 'motion', motion: 'moveByLines', motionArgs: { forward: false, linewise: true } }, { keys: 'gj', type: 'motion', motion: 'moveByDisplayLines', motionArgs: { forward: true } }, { keys: 'gk', type: 'motion', motion: 'moveByDisplayLines', motionArgs: { forward: false } }, { keys: 'w', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: false } }, { keys: 'W', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: false, bigWord: true } }, { keys: 'e', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: true, inclusive: true } }, { keys: 'E', type: 'motion', motion: 'moveByWords', motionArgs: { forward: true, wordEnd: true, bigWord: true, inclusive: true } }, { keys: 'b', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false } }, { keys: 'B', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false, bigWord: true } }, { keys: 'ge', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: true, inclusive: true } }, { keys: 'gE', type: 'motion', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: true, bigWord: true, inclusive: true } }, { keys: '{', type: 'motion', motion: 'moveByParagraph', motionArgs: { forward: false, toJumplist: true } }, { keys: '}', type: 'motion', motion: 'moveByParagraph', motionArgs: { forward: true, toJumplist: true } }, { keys: '(', type: 'motion', motion: 'moveBySentence', motionArgs: { forward: false } }, { keys: ')', type: 'motion', motion: 'moveBySentence', motionArgs: { forward: true } }, { keys: '<C-f>', type: 'motion', motion: 'moveByPage', motionArgs: { forward: true } }, { keys: '<C-b>', type: 'motion', motion: 'moveByPage', motionArgs: { forward: false } }, { keys: '<C-d>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: true, explicitRepeat: true } }, { keys: '<C-u>', type: 'motion', motion: 'moveByScroll', motionArgs: { forward: false, explicitRepeat: true } }, { keys: 'gg', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: false, explicitRepeat: true, linewise: true, toJumplist: true } }, { keys: 'G', type: 'motion', motion: 'moveToLineOrEdgeOfDocument', motionArgs: { forward: true, explicitRepeat: true, linewise: true, toJumplist: true } }, { keys: '0', type: 'motion', motion: 'moveToStartOfLine' }, { keys: '^', type: 'motion', motion: 'moveToFirstNonWhiteSpaceCharacter' }, { keys: '+', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar: true } }, { keys: '-', type: 'motion', motion: 'moveByLines', motionArgs: { forward: false, toFirstChar: true } }, { keys: '_', type: 'motion', motion: 'moveByLines', motionArgs: { forward: true, toFirstChar: true, repeatOffset: -1 } }, { keys: '$', type: 'motion', motion: 'moveToEol', motionArgs: { inclusive: true } }, { keys: '%', type: 'motion', motion: 'moveToMatchedSymbol', motionArgs: { inclusive: true, toJumplist: true } }, { keys: 'f<character>', type: 'motion', motion: 'moveToCharacter', motionArgs: { forward: true, inclusive: true } }, { keys: 'F<character>', type: 'motion', motion: 'moveToCharacter', motionArgs: { forward: false } }, { keys: 't<character>', type: 'motion', motion: 'moveTillCharacter', motionArgs: { forward: true, inclusive: true } }, { keys: 'T<character>', type: 'motion', motion: 'moveTillCharacter', motionArgs: { forward: false } }, { keys: ';', type: 'motion', motion: 'repeatLastCharacterSearch', motionArgs: { forward: true } }, { keys: ',', type: 'motion', motion: 'repeatLastCharacterSearch', motionArgs: { forward: false } }, { keys: '\'<character>', type: 'motion', motion: 'goToMark', motionArgs: { toJumplist: true, linewise: true } }, { keys: '`<character>', type: 'motion', motion: 'goToMark', motionArgs: { toJumplist: true } }, { keys: ']`', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true } }, { keys: '[`', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false } }, { keys: ']\'', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: true, linewise: true } }, { keys: '[\'', type: 'motion', motion: 'jumpToMark', motionArgs: { forward: false, linewise: true } },
// the next two aren't motions but must come before more general motion declarations
{ keys: ']p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true, matchIndent: true } }, { keys: '[p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true, matchIndent: true } }, { keys: ']<character>', type: 'motion', motion: 'moveToSymbol', motionArgs: { forward: true, toJumplist: true } }, { keys: '[<character>', type: 'motion', motion: 'moveToSymbol', motionArgs: { forward: false, toJumplist: true } }, { keys: '|', type: 'motion', motion: 'moveToColumn' }, { keys: 'o', type: 'motion', motion: 'moveToOtherHighlightedEnd', context: 'visual' }, { keys: 'O', type: 'motion', motion: 'moveToOtherHighlightedEnd', motionArgs: { sameLine: true }, context: 'visual' },
// Operators
{ keys: 'd', type: 'operator', operator: 'delete' }, { keys: 'y', type: 'operator', operator: 'yank' }, { keys: 'c', type: 'operator', operator: 'change' }, { keys: '>', type: 'operator', operator: 'indent', operatorArgs: { indentRight: true } }, { keys: '<', type: 'operator', operator: 'indent', operatorArgs: { indentRight: false } }, { keys: 'g~', type: 'operator', operator: 'changeCase' }, { keys: 'gu', type: 'operator', operator: 'changeCase', operatorArgs: { toLower: true }, isEdit: true }, { keys: 'gU', type: 'operator', operator: 'changeCase', operatorArgs: { toLower: false }, isEdit: true }, { keys: 'n', type: 'motion', motion: 'findNext', motionArgs: { forward: true, toJumplist: true } }, { keys: 'N', type: 'motion', motion: 'findNext', motionArgs: { forward: false, toJumplist: true } },
// Operator-Motion dual commands
{ keys: 'x', type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', motionArgs: { forward: true }, operatorMotionArgs: { visualLine: false } }, { keys: 'X', type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', motionArgs: { forward: false }, operatorMotionArgs: { visualLine: true } }, { keys: 'D', type: 'operatorMotion', operator: 'delete', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal' }, { keys: 'D', type: 'operator', operator: 'delete', operatorArgs: { linewise: true }, context: 'visual' }, { keys: 'Y', type: 'operatorMotion', operator: 'yank', motion: 'expandToLine', motionArgs: { linewise: true }, context: 'normal' }, { keys: 'Y', type: 'operator', operator: 'yank', operatorArgs: { linewise: true }, context: 'visual' }, { keys: 'C', type: 'operatorMotion', operator: 'change', motion: 'moveToEol', motionArgs: { inclusive: true }, context: 'normal' }, { keys: 'C', type: 'operator', operator: 'change', operatorArgs: { linewise: true }, context: 'visual' }, { keys: '~', type: 'operatorMotion', operator: 'changeCase', motion: 'moveByCharacters', motionArgs: { forward: true }, operatorArgs: { shouldMoveCursor: true }, context: 'normal' }, { keys: '~', type: 'operator', operator: 'changeCase', context: 'visual' }, { keys: '<C-w>', type: 'operatorMotion', operator: 'delete', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false }, context: 'insert' },
// Actions
{ keys: '<C-i>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: true } }, { keys: '<C-o>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: false } }, { keys: '<C-e>', type: 'action', action: 'scroll', actionArgs: { forward: true, linewise: true } }, { keys: '<C-y>', type: 'action', action: 'scroll', actionArgs: { forward: false, linewise: true } }, { keys: 'a', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'charAfter' }, context: 'normal' }, { keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'eol' }, context: 'normal' }, { keys: 'A', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'endOfSelectedArea' }, context: 'visual' }, { keys: 'i', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'inplace' }, context: 'normal' }, { keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'firstNonBlank' }, context: 'normal' }, { keys: 'I', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { insertAt: 'startOfSelectedArea' }, context: 'visual' }, { keys: 'o', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: true }, context: 'normal' }, { keys: 'O', type: 'action', action: 'newLineAndEnterInsertMode', isEdit: true, interlaceInsertRepeat: true, actionArgs: { after: false }, context: 'normal' }, { keys: 'v', type: 'action', action: 'toggleVisualMode' }, { keys: 'V', type: 'action', action: 'toggleVisualMode', actionArgs: { linewise: true } }, { keys: '<C-v>', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true } }, { keys: '<C-q>', type: 'action', action: 'toggleVisualMode', actionArgs: { blockwise: true } }, { keys: 'gv', type: 'action', action: 'reselectLastSelection' }, { keys: 'J', type: 'action', action: 'joinLines', isEdit: true }, { keys: 'p', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: true, isEdit: true } }, { keys: 'P', type: 'action', action: 'paste', isEdit: true, actionArgs: { after: false, isEdit: true } }, { keys: 'r<character>', type: 'action', action: 'replace', isEdit: true }, { keys: '@<character>', type: 'action', action: 'replayMacro' }, { keys: 'q<character>', type: 'action', action: 'enterMacroRecordMode' },
// Handle Replace-mode as a special case of insert mode.
{ keys: 'R', type: 'action', action: 'enterInsertMode', isEdit: true, actionArgs: { replace: true } }, { keys: 'u', type: 'action', action: 'undo', context: 'normal' }, { keys: 'u', type: 'operator', operator: 'changeCase', operatorArgs: { toLower: true }, context: 'visual', isEdit: true }, { keys: 'U', type: 'operator', operator: 'changeCase', operatorArgs: { toLower: false }, context: 'visual', isEdit: true }, { keys: '<C-r>', type: 'action', action: 'redo' }, { keys: 'm<character>', type: 'action', action: 'setMark' }, { keys: '"<character>', type: 'action', action: 'setRegister' }, { keys: 'zz', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' } }, { keys: 'z.', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }, motion: 'moveToFirstNonWhiteSpaceCharacter' }, { keys: 'zt', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' } }, { keys: 'z<CR>', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' }, motion: 'moveToFirstNonWhiteSpaceCharacter' }, { keys: 'z-', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'bottom' } }, { keys: 'zb', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'bottom' }, motion: 'moveToFirstNonWhiteSpaceCharacter' }, { keys: '.', type: 'action', action: 'repeatLastEdit' }, { keys: '<C-a>', type: 'action', action: 'incrementNumberToken', isEdit: true, actionArgs: { increase: true, backtrack: false } }, { keys: '<C-x>', type: 'action', action: 'incrementNumberToken', isEdit: true, actionArgs: { increase: false, backtrack: false } }, { keys: '<C-t>', type: 'action', action: 'indent', actionArgs: { indentRight: true }, context: 'insert' }, { keys: '<C-d>', type: 'action', action: 'indent', actionArgs: { indentRight: false }, context: 'insert' },
// Text object motions
{ keys: 'a<character>', type: 'motion', motion: 'textObjectManipulation' }, { keys: 'i<character>', type: 'motion', motion: 'textObjectManipulation', motionArgs: { textObjectInner: true } },
// Search
{ keys: '/', type: 'search', searchArgs: { forward: true, querySrc: 'prompt', toJumplist: true } }, { keys: '?', type: 'search', searchArgs: { forward: false, querySrc: 'prompt', toJumplist: true } }, { keys: '*', type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true } }, { keys: '#', type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', wholeWordOnly: true, toJumplist: true } }, { keys: 'g*', type: 'search', searchArgs: { forward: true, querySrc: 'wordUnderCursor', toJumplist: true } }, { keys: 'g#', type: 'search', searchArgs: { forward: false, querySrc: 'wordUnderCursor', toJumplist: true } },
// Ex command
{ keys: ':', type: 'ex' }];
/**
* Ex commands
* Care must be taken when adding to the default Ex command map. For any
* pair of commands that have a shared prefix, at least one of their
* shortNames must not match the prefix of the other command.
*/
var defaultExCommandMap = [{ name: 'colorscheme', shortName: 'colo' }, { name: 'map' }, { name: 'imap', shortName: 'im' }, { name: 'nmap', shortName: 'nm' }, { name: 'vmap', shortName: 'vm' }, { name: 'unmap' }, { name: 'write', shortName: 'w' }, { name: 'undo', shortName: 'u' }, { name: 'redo', shortName: 'red' }, { name: 'set', shortName: 'se' }, { name: 'set', shortName: 'se' }, { name: 'setlocal', shortName: 'setl' }, { name: 'setglobal', shortName: 'setg' }, { name: 'sort', shortName: 'sor' }, { name: 'substitute', shortName: 's', possiblyAsync: true }, { name: 'nohlsearch', shortName: 'noh' }, { name: 'yank', shortName: 'y' }, { name: 'delmarks', shortName: 'delm' }, { name: 'registers', shortName: 'reg', excludeFromCommandHistory: true }, { name: 'global', shortName: 'g' }];
var Pos = CodeMirror.Pos;
var Vim = function () {
function enterVimMode(cm) {
cm.setOption('disableInput', true);
cm.setOption('showCursorWhenSelecting', false);
CodeMirror.signal(cm, "vim-mode-change", { mode: "normal" });
cm.on('cursorActivity', onCursorActivity);
maybeInitVimState(cm);
CodeMirror.on(cm.getInputField(), 'paste', getOnPasteFn(cm));
}
function leaveVimMode(cm) {
cm.setOption('disableInput', false);
cm.off('cursorActivity', onCursorActivity);
CodeMirror.off(cm.getInputField(), 'paste', getOnPasteFn(cm));
cm.state.vim = null;
}
function detachVimMap(cm, next) {
if (this == CodeMirror.keyMap.vim) {
CodeMirror.rmClass(cm.getWrapperElement(), "cm-fat-cursor");
if (cm.getOption("inputStyle") == "contenteditable" && document.body.style.caretColor != null) {
disableFatCursorMark(cm);
cm.getInputField().style.caretColor = "";
}
}
if (!next || next.attach != attachVimMap) leaveVimMode(cm);
}
function attachVimMap(cm, prev) {
if (this == CodeMirror.keyMap.vim) {
CodeMirror.addClass(cm.getWrapperElement(), "cm-fat-cursor");
if (cm.getOption("inputStyle") == "contenteditable" && document.body.style.caretColor != null) {
enableFatCursorMark(cm);
cm.getInputField().style.caretColor = "transparent";
}
}
if (!prev || prev.attach != attachVimMap) enterVimMode(cm);
}
function fatCursorMarks(cm) {
var ranges = cm.listSelections(),
result = [];
for (var i = 0; i < ranges.length; i++) {
var range = ranges[i];
if (range.empty()) {
if (range.anchor.ch < cm.getLine(range.anchor.line).length) {
result.push(cm.markText(range.anchor, Pos(range.anchor.line, range.anchor.ch + 1), { className: "cm-fat-cursor-mark" }));
} else {
var widget = document.createElement("span");
widget.textContent = "\u00a0";
widget.className = "cm-fat-cursor-mark";
result.push(cm.setBookmark(range.anchor, { widget: widget }));
}
}
}
return result;
}
function updateFatCursorMark(cm) {
var marks = cm.state.fatCursorMarks;
if (marks) for (var i = 0; i < marks.length; i++) marks[i].clear();
cm.state.fatCursorMarks = fatCursorMarks(cm);
}
function enableFatCursorMark(cm) {
cm.state.fatCursorMarks = fatCursorMarks(cm);
cm.on("cursorActivity", updateFatCursorMark);
}
function disableFatCursorMark(cm) {
var marks = cm.state.fatCursorMarks;
if (marks) for (var i = 0; i < marks.length; i++) marks[i].clear();
cm.state.fatCursorMarks = null;
cm.off("cursorActivity", updateFatCursorMark);
}
// Deprecated, simply setting the keymap works again.
CodeMirror.defineOption('vimMode', false, function (cm, val, prev) {
if (val && cm.getOption("keyMap") != "vim") cm.setOption("keyMap", "vim");else if (!val && prev != CodeMirror.Init && /^vim/.test(cm.getOption("keyMap"))) cm.setOption("keyMap", "default");
});
function cmKey(key, cm) {
if (!cm) {
return undefined;
}
if (this[key]) {
return this[key];
}
var vimKey = cmKeyToVimKey(key);
if (!vimKey) {
return false;
}
var cmd = CodeMirror.Vim.findKey(cm, vimKey);
if (typeof cmd == 'function') {
CodeMirror.signal(cm, 'vim-keypress', vimKey);
}
return cmd;
}
var modifiers = { 'Shift': 'S', 'Ctrl': 'C', 'Alt': 'A', 'Cmd': 'D', 'Mod': 'A' };
var specialKeys = { Enter: 'CR', Backspace: 'BS', Delete: 'Del', Insert: 'Ins' };
function cmKeyToVimKey(key) {
if (key.charAt(0) == '\'') {
// Keypress character binding of format "'a'"
return key.charAt(1);
}
var pieces = key.split(/-(?!$)/);
var lastPiece = pieces[pieces.length - 1];
if (pieces.length == 1 && pieces[0].length == 1) {
// No-modifier bindings use literal character bindings above. Skip.
return false;
} else if (pieces.length == 2 && pieces[0] == 'Shift' && lastPiece.length == 1) {
// Ignore Shift+char bindings as they should be handled by literal character.
return false;
}
var hasCharacter = false;
for (var i = 0; i < pieces.length; i++) {
var piece = pieces[i];
if (piece in modifiers) {
pieces[i] = modifiers[piece];
} else {
hasCharacter = true;
}
if (piece in specialKeys) {
pieces[i] = specialKeys[piece];
}
}
if (!hasCharacter) {
// Vim does not support modifier only keys.
return false;
}
// TODO: Current bindings expect the character to be lower case, but
// it looks like vim key notation uses upper case.
if (isUpperCase(lastPiece)) {
pieces[pieces.length - 1] = lastPiece.toLowerCase();
}
return '<' + pieces.join('-') + '>';
}
function getOnPasteFn(cm) {
var vim = cm.state.vim;
if (!vim.onPasteFn) {
vim.onPasteFn = function () {
if (!vim.insertMode) {
cm.setCursor(offsetCursor(cm.getCursor(), 0, 1));
actions.enterInsertMode(cm, {}, vim);
}
};
}
return vim.onPasteFn;
}
var numberRegex = /[\d]/;
var wordCharTest = [CodeMirror.isWordChar, function (ch) {
return ch && !CodeMirror.isWordChar(ch) && !/\s/.test(ch);
}],
bigWordCharTest = [function (ch) {
return (/\S/.test(ch)
);
}];
function makeKeyRange(start, size) {
var keys = [];
for (var i = start; i < start + size; i++) {
keys.push(String.fromCharCode(i));
}
return keys;
}
var upperCaseAlphabet = makeKeyRange(65, 26);
var lowerCaseAlphabet = makeKeyRange(97, 26);
var numbers = makeKeyRange(48, 10);
var validMarks = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['<', '>']);
var validRegisters = [].concat(upperCaseAlphabet, lowerCaseAlphabet, numbers, ['-', '"', '.', ':', '/']);
function isLine(cm, line) {
return line >= cm.firstLine() && line <= cm.lastLine();
}
function isLowerCase(k) {
return (/^[a-z]$/.test(k)
);
}
function isMatchableSymbol(k) {
return '()[]{}'.indexOf(k) != -1;
}
function isNumber(k) {
return numberRegex.test(k);
}
function isUpperCase(k) {
return (/^[A-Z]$/.test(k)
);
}
function isWhiteSpaceString(k) {
return (/^\s*$/.test(k)
);
}
function isEndOfSentenceSymbol(k) {
return '.?!'.indexOf(k) != -1;
}
function inArray(val, arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == val) {
return true;
}
}
return false;
}
var options = {};
function defineOption(name, defaultValue, type, aliases, callback) {
if (defaultValue === undefined && !callback) {
throw Error('defaultValue is required unless callback is provided');
}
if (!type) {
type = 'string';
}
options[name] = {
type: type,
defaultValue: defaultValue,
callback: callback
};
if (aliases) {
for (var i = 0; i < aliases.length; i++) {
options[aliases[i]] = options[name];
}
}
if (defaultValue) {
setOption(name, defaultValue);
}
}
function setOption(name, value, cm, cfg) {
var option = options[name];
cfg = cfg || {};
var scope = cfg.scope;
if (!option) {
return new Error('Unknown option: ' + name);
}
if (option.type == 'boolean') {
if (value && value !== true) {
return new Error('Invalid argument: ' + name + '=' + value);
} else if (value !== false) {
// Boolean options are set to true if value is not defined.
value = true;
}
}
if (option.callback) {
if (scope !== 'local') {
option.callback(value, undefined);
}
if (scope !== 'global' && cm) {
option.callback(value, cm);
}
} else {
if (scope !== 'local') {
option.value = option.type == 'boolean' ? !!value : value;
}
if (scope !== 'global' && cm) {
cm.state.vim.options[name] = { value: value };
}
}
}
function getOption(name, cm, cfg) {
var option = options[name];
cfg = cfg || {};
var scope = cfg.scope;
if (!option) {
return new Error('Unknown option: ' + name);
}
if (option.callback) {
var local = cm && option.callback(undefined, cm);
if (scope !== 'global' && local !== undefined) {
return local;
}
if (scope !== 'local') {
return option.callback();
}
return;
} else {
var local = scope !== 'global' && cm && cm.state.vim.options[name];
return (local || scope !== 'local' && option || {}).value;
}
}
defineOption('filetype', undefined, 'string', ['ft'], function (name, cm) {
// Option is local. Do nothing for global.
if (cm === undefined) {
return;
}
// The 'filetype' option proxies to the CodeMirror 'mode' option.
if (name === undefined) {
var mode = cm.getOption('mode');
return mode == 'null' ? '' : mode;
} else {
var mode = name == '' ? 'null' : name;
cm.setOption('mode', mode);
}
});
var createCircularJumpList = function () {
var size = 100;
var pointer = -1;
var head = 0;
var tail = 0;
var buffer = new Array(size);
function add(cm, oldCur, newCur) {
var current = pointer % size;
var curMark = buffer[current];
function useNextSlot(cursor) {
var next = ++pointer % size;
var trashMark = buffer[next];
if (trashMark) {
trashMark.clear();
}
buffer[next] = cm.setBookmark(cursor);
}
if (curMark) {
var markPos = curMark.find();
// avoid recording redundant cursor position
if (markPos && !cursorEqual(markPos, oldCur)) {
useNextSlot(oldCur);
}
} else {
useNextSlot(oldCur);
}
useNextSlot(newCur);
head = pointer;
tail = pointer - size + 1;
if (tail < 0) {
tail = 0;
}
}
function move(cm, offset) {
pointer += offset;
if (pointer > head) {
pointer = head;
} else if (pointer < tail) {
pointer = tail;
}
var mark = buffer[(size + pointer) % size];
// skip marks that are temporarily removed from text buffer
if (mark && !mark.find()) {
var inc = offset > 0 ? 1 : -1;
var newCur;
var oldCur = cm.getCursor();
do {
pointer += inc;
mark = buffer[(size + pointer) % size];
// skip marks that are the same as current position
if (mark && (newCur = mark.find()) && !cursorEqual(oldCur, newCur)) {
break;
}
} while (pointer < head && pointer > tail);
}
return mark;
}
return {
cachedCursor: undefined, //used for # and * jumps
add: add,
move: move
};
};
// Returns an object to track the changes associated insert mode. It
// clones the object that is passed in, or creates an empty object one if
// none is provided.
var createInsertModeChanges = function (c) {
if (c) {
// Copy construction
return {
changes: c.changes,
expectCursorActivityForChange: c.expectCursorActivityForChange
};
}
return {
// Change list
changes: [],
// Set to true on change, false on cursorActivity.
expectCursorActivityForChange: false
};
};
function MacroModeState() {
this.latestRegister = undefined;
this.isPlaying = false;
this.isRecording = false;
this.replaySearchQueries = [];
this.onRecordingDone = undefined;
this.lastInsertModeChanges = createInsertModeChanges();
}
MacroModeState.prototype = {
exitMacroRecordMode: function () {
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.onRecordingDone) {
macroModeState.onRecordingDone(); // close dialog
}
macroModeState.onRecordingDone = undefined;
macroModeState.isRecording = false;
},
enterMacroRecordMode: function (cm, registerName) {
var register = vimGlobalState.registerController.getRegister(registerName);
if (register) {
register.clear();
this.latestRegister = registerName;
if (cm.openDialog) {
this.onRecordingDone = cm.openDialog('(recording)[' + registerName + ']', null, { bottom: true });
}
this.isRecording = true;
}
}
};
function maybeInitVimState(cm) {
if (!cm.state.vim) {
// Store instance state in the CodeMirror object.
cm.state.vim = {
inputState: new InputState(),
// Vim's input state that triggered the last edit, used to repeat
// motions and operators with '.'.
lastEditInputState: undefined,
// Vim's action command before the last edit, used to repeat actions
// with '.' and insert mode repeat.
lastEditActionCommand: undefined,
// When using jk for navigation, if you move from a longer line to a
// shorter line, the cursor may clip to the end of the shorter line.
// If j is pressed again and cursor goes to the next line, the
// cursor should go back to its horizontal position on the longer
// line if it can. This is to keep track of the horizontal position.
lastHPos: -1,
// Doing the same with screen-position for gj/gk
lastHSPos: -1,
// The last motion command run. Cleared if a non-motion command gets
// executed in between.
lastMotion: null,
marks: {},
// Mark for rendering fake cursor for visual mode.
fakeCursor: null,
insertMode: false,
// Repeat count for changes made in insert mode, triggered by key
// sequences like 3,i. Only exists when insertMode is true.
insertModeRepeat: undefined,
visualMode: false,
// If we are in visual line mode. No effect if visualMode is false.
visualLine: false,
visualBlock: false,
lastSelection: null,
lastPastedText: null,
sel: {},
// Buffer-local/window-local values of vim options.
options: {}
};
}
return cm.state.vim;
}
var vimGlobalState;
function resetVimGlobalState() {
vimGlobalState = {
// The current search query.
searchQuery: null,
// Whether we are searching backwards.
searchIsReversed: false,
// Replace part of the last substituted pattern
lastSubstituteReplacePart: undefined,
jumpList: createCircularJumpList(),
macroModeState: new MacroModeState(),
// Recording latest f, t, F or T motion command.
lastCharacterSearch: { increment: 0, forward: true, selectedCharacter: '' },
registerController: new RegisterController({}),
// search history buffer
searchHistoryController: new HistoryController(),
// ex Command history buffer
exCommandHistoryController: new HistoryController()
};
for (var optionName in options) {
var option = options[optionName];
option.value = option.defaultValue;
}
}
var lastInsertModeKeyTimer;
var vimApi = {
buildKeyMap: function () {
// TODO: Convert keymap into dictionary format for fast lookup.
},
// Testing hook, though it might be useful to expose the register
// controller anyways.
getRegisterController: function () {
return vimGlobalState.registerController;
},
// Testing hook.
resetVimGlobalState_: resetVimGlobalState,
// Testing hook.
getVimGlobalState_: function () {
return vimGlobalState;
},
// Testing hook.
maybeInitVimState_: maybeInitVimState,
suppressErrorLogging: false,
InsertModeKey: InsertModeKey,
map: function (lhs, rhs, ctx) {
// Add user defined key bindings.
exCommandDispatcher.map(lhs, rhs, ctx);
},
unmap: function (lhs, ctx) {
exCommandDispatcher.unmap(lhs, ctx);
},
// TODO: Expose setOption and getOption as instance methods. Need to decide how to namespace
// them, or somehow make them work with the existing CodeMirror setOption/getOption API.
setOption: setOption,
getOption: getOption,
defineOption: defineOption,
defineEx: function (name, prefix, func) {
if (!prefix) {
prefix = name;
} else if (name.indexOf(prefix) !== 0) {
throw new Error('(Vim.defineEx) "' + prefix + '" is not a prefix of "' + name + '", command not registered');
}
exCommands[name] = func;
exCommandDispatcher.commandMap_[prefix] = { name: name, shortName: prefix, type: 'api' };
},
handleKey: function (cm, key, origin) {
var command = this.findKey(cm, key, origin);
if (typeof command === 'function') {
return command();
}
},
/**
* This is the outermost function called by CodeMirror, after keys have
* been mapped to their Vim equivalents.
*
* Finds a command based on the key (and cached keys if there is a
* multi-key sequence). Returns `undefined` if no key is matched, a noop
* function if a partial match is found (multi-key), and a function to
* execute the bound command if a a key is matched. The function always
* returns true.
*/
findKey: function (cm, key, origin) {
var vim = maybeInitVimState(cm);
function handleMacroRecording() {
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isRecording) {
if (key == 'q') {
macroModeState.exitMacroRecordMode();
clearInputState(cm);
return true;
}
if (origin != 'mapping') {
logKey(macroModeState, key);
}
}
}
function handleEsc() {
if (key == '<Esc>') {
// Clear input state and get back to normal mode.
clearInputState(cm);
if (vim.visualMode) {
exitVisualMode(cm);
} else if (vim.insertMode) {
exitInsertMode(cm);
}
return true;
}
}
function doKeyToKey(keys) {
// TODO: prevent infinite recursion.
var match;
while (keys) {
// Pull off one command key, which is either a single character
// or a special sequence wrapped in '<' and '>', e.g. '<Space>'.
match = /<\w+-.+?>|<\w+>|./.exec(keys);
key = match[0];
keys = keys.substring(match.index + key.length);
CodeMirror.Vim.handleKey(cm, key, 'mapping');
}
}
function handleKeyInsertMode() {
if (handleEsc()) {
return true;
}
var keys = vim.inputState.keyBuffer = vim.inputState.keyBuffer + key;
var keysAreChars = key.length == 1;
var match = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
// Need to check all key substrings in insert mode.
while (keys.length > 1 && match.type != 'full') {
var keys = vim.inputState.keyBuffer = keys.slice(1);
var thisMatch = commandDispatcher.matchCommand(keys, defaultKeymap, vim.inputState, 'insert');
if (thisMatch.type != 'none') {
match = thisMatch;
}
}
if (match.type == 'none') {
clearInputState(cm);return false;
} else if (match.type == 'partial') {
if (lastInsertModeKeyTimer) {
window.clearTimeout(lastInsertModeKeyTimer);
}
lastInsertModeKeyTimer = window.setTimeout(function () {
if (vim.insertMode && vim.inputState.keyBuffer) {
clearInputState(cm);
}
}, getOption('insertModeEscKeysTimeout'));
return !keysAreChars;
}
if (lastInsertModeKeyTimer) {
window.clearTimeout(lastInsertModeKeyTimer);
}
if (keysAreChars) {
var selections = cm.listSelections();
for (var i = 0; i < selections.length; i++) {
var here = selections[i].head;
cm.replaceRange('', offsetCursor(here, 0, -(keys.length - 1)), here, '+input');
}
vimGlobalState.macroModeState.lastInsertModeChanges.changes.pop();
}
clearInputState(cm);
return match.command;
}
function handleKeyNonInsertMode() {
if (handleMacroRecording() || handleEsc()) {
return true;
}
var keys = vim.inputState.keyBuffer = vim.inputState.keyBuffer + key;
if (/^[1-9]\d*$/.test(keys)) {
return true;
}
var keysMatcher = /^(\d*)(.*)$/.exec(keys);
if (!keysMatcher) {
clearInputState(cm);return false;
}
var context = vim.visualMode ? 'visual' : 'normal';
var match = commandDispatcher.matchCommand(keysMatcher[2] || keysMatcher[1], defaultKeymap, vim.inputState, context);
if (match.type == 'none') {
clearInputState(cm);return false;
} else if (match.type == 'partial') {
return true;
}
vim.inputState.keyBuffer = '';
var keysMatcher = /^(\d*)(.*)$/.exec(keys);
if (keysMatcher[1] && keysMatcher[1] != '0') {
vim.inputState.pushRepeatDigit(keysMatcher[1]);
}
return match.command;
}
var command;
if (vim.insertMode) {
command = handleKeyInsertMode();
} else {
command = handleKeyNonInsertMode();
}
if (command === false) {
return !vim.insertMode && key.length === 1 ? function () {
return true;
} : undefined;
} else if (command === true) {
// TODO: Look into using CodeMirror's multi-key handling.
// Return no-op since we are caching the key. Counts as handled, but
// don't want act on it just yet.
return function () {
return true;
};
} else {
return function () {
return cm.operation(function () {
cm.curOp.isVimOp = true;
try {
if (command.type == 'keyToKey') {
doKeyToKey(command.toKeys);
} else {
commandDispatcher.processCommand(cm, vim, command);
}
} catch (e) {
// clear VIM state in case it's in a bad state.
cm.state.vim = undefined;
maybeInitVimState(cm);
if (!CodeMirror.Vim.suppressErrorLogging) {
console['log'](e);
}
throw e;
}
return true;
});
};
}
},
handleEx: function (cm, input) {
exCommandDispatcher.processCommand(cm, input);
},
defineMotion: defineMotion,
defineAction: defineAction,
defineOperator: defineOperator,
mapCommand: mapCommand,
_mapCommand: _mapCommand,
defineRegister: defineRegister,
exitVisualMode: exitVisualMode,
exitInsertMode: exitInsertMode
};
// Represents the current input state.
function InputState() {
this.prefixRepeat = [];
this.motionRepeat = [];
this.operator = null;
this.operatorArgs = null;
this.motion = null;
this.motionArgs = null;
this.keyBuffer = []; // For matching multi-key commands.
this.registerName = null; // Defaults to the unnamed register.
}
InputState.prototype.pushRepeatDigit = function (n) {
if (!this.operator) {
this.prefixRepeat = this.prefixRepeat.concat(n);
} else {
this.motionRepeat = this.motionRepeat.concat(n);
}
};
InputState.prototype.getRepeat = function () {
var repeat = 0;
if (this.prefixRepeat.length > 0 || this.motionRepeat.length > 0) {
repeat = 1;
if (this.prefixRepeat.length > 0) {
repeat *= parseInt(this.prefixRepeat.join(''), 10);
}
if (this.motionRepeat.length > 0) {
repeat *= parseInt(this.motionRepeat.join(''), 10);
}
}
return repeat;
};
function clearInputState(cm, reason) {
cm.state.vim.inputState = new InputState();
CodeMirror.signal(cm, 'vim-command-done', reason);
}
/*
* Register stores information about copy and paste registers. Besides
* text, a register must store whether it is linewise (i.e., when it is
* pasted, should it insert itself into a new line, or should the text be
* inserted at the cursor position.)
*/
function Register(text, linewise, blockwise) {
this.clear();
this.keyBuffer = [text || ''];
this.insertModeChanges = [];
this.searchQueries = [];
this.linewise = !!linewise;
this.blockwise = !!blockwise;
}
Register.prototype = {
setText: function (text, linewise, blockwise) {
this.keyBuffer = [text || ''];
this.linewise = !!linewise;
this.blockwise = !!blockwise;
},
pushText: function (text, linewise) {
// if this register has ever been set to linewise, use linewise.
if (linewise) {
if (!this.linewise) {
this.keyBuffer.push('\n');
}
this.linewise = true;
}
this.keyBuffer.push(text);
},
pushInsertModeChanges: function (changes) {
this.insertModeChanges.push(createInsertModeChanges(changes));
},
pushSearchQuery: function (query) {
this.searchQueries.push(query);
},
clear: function () {
this.keyBuffer = [];
this.insertModeChanges = [];
this.searchQueries = [];
this.linewise = false;
},
toString: function () {
return this.keyBuffer.join('');
}
};
/**
* Defines an external register.
*
* The name should be a single character that will be used to reference the register.
* The register should support setText, pushText, clear, and toString(). See Register
* for a reference implementation.
*/
function defineRegister(name, register) {
var registers = vimGlobalState.registerController.registers;
if (!name || name.length != 1) {
throw Error('Register name must be 1 character');
}
if (registers[name]) {
throw Error('Register already defined ' + name);
}
registers[name] = register;
validRegisters.push(name);
}
/*
* vim registers allow you to keep many independent copy and paste buffers.
* See http://usevim.com/2012/04/13/registers/ for an introduction.
*
* RegisterController keeps the state of all the registers. An initial
* state may be passed in. The unnamed register '"' will always be
* overridden.
*/
function RegisterController(registers) {
this.registers = registers;
this.unnamedRegister = registers['"'] = new Register();
registers['.'] = new Register();
registers[':'] = new Register();
registers['/'] = new Register();
}
RegisterController.prototype = {
pushText: function (registerName, operator, text, linewise, blockwise) {
if (linewise && text.charAt(text.length - 1) !== '\n') {
text += '\n';
}
// Lowercase and uppercase registers refer to the same register.
// Uppercase just means append.
var register = this.isValidRegister(registerName) ? this.getRegister(registerName) : null;
// if no register/an invalid register was specified, things go to the
// default registers
if (!register) {
switch (operator) {
case 'yank':
// The 0 register contains the text from the most recent yank.
this.registers['0'] = new Register(text, linewise, blockwise);
break;
case 'delete':
case 'change':
if (text.indexOf('\n') == -1) {
// Delete less than 1 line. Update the small delete register.
this.registers['-'] = new Register(text, linewise);
} else {
// Shift down the contents of the numbered registers and put the
// deleted text into register 1.
this.shiftNumericRegisters_();
this.registers['1'] = new Register(text, linewise);
}
break;
}
// Make sure the unnamed register is set to what just happened
this.unnamedRegister.setText(text, linewise, blockwise);
return;
}
// If we've gotten to this point, we've actually specified a register
var append = isUpperCase(registerName);
if (append) {
register.pushText(text, linewise);
} else {
register.setText(text, linewise, blockwise);
}
// The unnamed register always has the same value as the last used
// register.
this.unnamedRegister.setText(register.toString(), linewise);
},
// Gets the register named @name. If one of @name doesn't already exist,
// create it. If @name is invalid, return the unnamedRegister.
getRegister: function (name) {
if (!this.isValidRegister(name)) {
return this.unnamedRegister;
}
name = name.toLowerCase();
if (!this.registers[name]) {
this.registers[name] = new Register();
}
return this.registers[name];
},
isValidRegister: function (name) {
return name && inArray(name, validRegisters);
},
shiftNumericRegisters_: function () {
for (var i = 9; i >= 2; i--) {
this.registers[i] = this.getRegister('' + (i - 1));
}
}
};
function HistoryController() {
this.historyBuffer = [];
this.iterator = 0;
this.initialPrefix = null;
}
HistoryController.prototype = {
// the input argument here acts a user entered prefix for a small time
// until we start autocompletion in which case it is the autocompleted.
nextMatch: function (input, up) {
var historyBuffer = this.historyBuffer;
var dir = up ? -1 : 1;
if (this.initialPrefix === null) this.initialPrefix = input;
for (var i = this.iterator + dir; up ? i >= 0 : i < historyBuffer.length; i += dir) {
var element = historyBuffer[i];
for (var j = 0; j <= element.length; j++) {
if (this.initialPrefix == element.substring(0, j)) {
this.iterator = i;
return element;
}
}
}
// should return the user input in case we reach the end of buffer.
if (i >= historyBuffer.length) {
this.iterator = historyBuffer.length;
return this.initialPrefix;
}
// return the last autocompleted query or exCommand as it is.
if (i < 0) return input;
},
pushInput: function (input) {
var index = this.historyBuffer.indexOf(input);
if (index > -1) this.historyBuffer.splice(index, 1);
if (input.length) this.historyBuffer.push(input);
},
reset: function () {
this.initialPrefix = null;
this.iterator = this.historyBuffer.length;
}
};
var commandDispatcher = {
matchCommand: function (keys, keyMap, inputState, context) {
var matches = commandMatches(keys, keyMap, context, inputState);
if (!matches.full && !matches.partial) {
return { type: 'none' };
} else if (!matches.full && matches.partial) {
return { type: 'partial' };
}
var bestMatch;
for (var i = 0; i < matches.full.length; i++) {
var match = matches.full[i];
if (!bestMatch) {
bestMatch = match;
}
}
if (bestMatch.keys.slice(-11) == '<character>') {
var character = lastChar(keys);
if (!character) return { type: 'none' };
inputState.selectedCharacter = character;
}
return { type: 'full', command: bestMatch };
},
processCommand: function (cm, vim, command) {
vim.inputState.repeatOverride = command.repeatOverride;
switch (command.type) {
case 'motion':
this.processMotion(cm, vim, command);
break;
case 'operator':
this.processOperator(cm, vim, command);
break;
case 'operatorMotion':
this.processOperatorMotion(cm, vim, command);
break;
case 'action':
this.processAction(cm, vim, command);
break;
case 'search':
this.processSearch(cm, vim, command);
break;
case 'ex':
case 'keyToEx':
this.processEx(cm, vim, command);
break;
default:
break;
}
},
processMotion: function (cm, vim, command) {
vim.inputState.motion = command.motion;
vim.inputState.motionArgs = copyArgs(command.motionArgs);
this.evalInput(cm, vim);
},
processOperator: function (cm, vim, command) {
var inputState = vim.inputState;
if (inputState.operator) {
if (inputState.operator == command.operator) {
// Typing an operator twice like 'dd' makes the operator operate
// linewise
inputState.motion = 'expandToLine';
inputState.motionArgs = { linewise: true };
this.evalInput(cm, vim);
return;
} else {
// 2 different operators in a row doesn't make sense.
clearInputState(cm);
}
}
inputState.operator = command.operator;
inputState.operatorArgs = copyArgs(command.operatorArgs);
if (vim.visualMode) {
// Operating on a selection in visual mode. We don't need a motion.
this.evalInput(cm, vim);
}
},
processOperatorMotion: function (cm, vim, command) {
var visualMode = vim.visualMode;
var operatorMotionArgs = copyArgs(command.operatorMotionArgs);
if (operatorMotionArgs) {
// Operator motions may have special behavior in visual mode.
if (visualMode && operatorMotionArgs.visualLine) {
vim.visualLine = true;
}
}
this.processOperator(cm, vim, command);
if (!visualMode) {
this.processMotion(cm, vim, command);
}
},
processAction: function (cm, vim, command) {
var inputState = vim.inputState;
var repeat = inputState.getRepeat();
var repeatIsExplicit = !!repeat;
var actionArgs = copyArgs(command.actionArgs) || {};
if (inputState.selectedCharacter) {
actionArgs.selectedCharacter = inputState.selectedCharacter;
}
// Actions may or may not have motions and operators. Do these first.
if (command.operator) {
this.processOperator(cm, vim, command);
}
if (command.motion) {
this.processMotion(cm, vim, command);
}
if (command.motion || command.operator) {
this.evalInput(cm, vim);
}
actionArgs.repeat = repeat || 1;
actionArgs.repeatIsExplicit = repeatIsExplicit;
actionArgs.registerName = inputState.registerName;
clearInputState(cm);
vim.lastMotion = null;
if (command.isEdit) {
this.recordLastEdit(vim, inputState, command);
}
actions[command.action](cm, actionArgs, vim);
},
processSearch: function (cm, vim, command) {
if (!cm.getSearchCursor) {
// Search depends on SearchCursor.
return;
}
var forward = command.searchArgs.forward;
var wholeWordOnly = command.searchArgs.wholeWordOnly;
getSearchState(cm).setReversed(!forward);
var promptPrefix = forward ? '/' : '?';
var originalQuery = getSearchState(cm).getQuery();
var originalScrollPos = cm.getScrollInfo();
function handleQuery(query, ignoreCase, smartCase) {
vimGlobalState.searchHistoryController.pushInput(query);
vimGlobalState.searchHistoryController.reset();
try {
updateSearchQuery(cm, query, ignoreCase, smartCase);
} catch (e) {
showConfirm(cm, 'Invalid regex: ' + query);
clearInputState(cm);
return;
}
commandDispatcher.processMotion(cm, vim, {
type: 'motion',
motion: 'findNext',
motionArgs: { forward: true, toJumplist: command.searchArgs.toJumplist }
});
}
function onPromptClose(query) {
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
handleQuery(query, true /** ignoreCase */, true /** smartCase */);
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isRecording) {
logSearchQuery(macroModeState, query);
}
}
function onPromptKeyUp(e, query, close) {
var keyName = CodeMirror.keyName(e),
up,
offset;
if (keyName == 'Up' || keyName == 'Down') {
up = keyName == 'Up' ? true : false;
offset = e.target ? e.target.selectionEnd : 0;
query = vimGlobalState.searchHistoryController.nextMatch(query, up) || '';
close(query);
if (offset && e.target) e.target.selectionEnd = e.target.selectionStart = Math.min(offset, e.target.value.length);
} else {
if (keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift') vimGlobalState.searchHistoryController.reset();
}
var parsedQuery;
try {
parsedQuery = updateSearchQuery(cm, query, true /** ignoreCase */, true /** smartCase */);
} catch (e) {
// Swallow bad regexes for incremental search.
}
if (parsedQuery) {
cm.scrollIntoView(findNext(cm, !forward, parsedQuery), 30);
} else {
clearSearchHighlight(cm);
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
}
}
function onPromptKeyDown(e, query, close) {
var keyName = CodeMirror.keyName(e);
if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' || keyName == 'Backspace' && query == '') {
vimGlobalState.searchHistoryController.pushInput(query);
vimGlobalState.searchHistoryController.reset();
updateSearchQuery(cm, originalQuery);
clearSearchHighlight(cm);
cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
CodeMirror.e_stop(e);
clearInputState(cm);
close();
cm.focus();
} else if (keyName == 'Up' || keyName == 'Down') {
CodeMirror.e_stop(e);
} else if (keyName == 'Ctrl-U') {
// Ctrl-U clears input.
CodeMirror.e_stop(e);
close('');
}
}
switch (command.searchArgs.querySrc) {
case 'prompt':
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) {
var query = macroModeState.replaySearchQueries.shift();
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
} else {
showPrompt(cm, {
onClose: onPromptClose,
prefix: promptPrefix,
desc: searchPromptDesc,
onKeyUp: onPromptKeyUp,
onKeyDown: onPromptKeyDown
});
}
break;
case 'wordUnderCursor':
var word = expandWordUnderCursor(cm, false /** inclusive */
, true /** forward */, false /** bigWord */
, true /** noSymbol */);
var isKeyword = true;
if (!word) {
word = expandWordUnderCursor(cm, false /** inclusive */
, true /** forward */, false /** bigWord */
, false /** noSymbol */);
isKeyword = false;
}
if (!word) {
return;
}
var query = cm.getLine(word.start.line).substring(word.start.ch, word.end.ch);
if (isKeyword && wholeWordOnly) {
query = '\\b' + query + '\\b';
} else {
query = escapeRegex(query);
}
// cachedCursor is used to save the old position of the cursor
// when * or # causes vim to seek for the nearest word and shift
// the cursor before entering the motion.
vimGlobalState.jumpList.cachedCursor = cm.getCursor();
cm.setCursor(word.start);
handleQuery(query, true /** ignoreCase */, false /** smartCase */);
break;
}
},
processEx: function (cm, vim, command) {
function onPromptClose(input) {
// Give the prompt some time to close so that if processCommand shows
// an error, the elements don't overlap.
vimGlobalState.exCommandHistoryController.pushInput(input);
vimGlobalState.exCommandHistoryController.reset();
exCommandDispatcher.processCommand(cm, input);
}
function onPromptKeyDown(e, input, close) {
var keyName = CodeMirror.keyName(e),
up,
offset;
if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' || keyName == 'Backspace' && input == '') {
vimGlobalState.exCommandHistoryController.pushInput(input);
vimGlobalState.exCommandHistoryController.reset();
CodeMirror.e_stop(e);
clearInputState(cm);
close();
cm.focus();
}
if (keyName == 'Up' || keyName == 'Down') {
CodeMirror.e_stop(e);
up = keyName == 'Up' ? true : false;
offset = e.target ? e.target.selectionEnd : 0;
input = vimGlobalState.exCommandHistoryController.nextMatch(input, up) || '';
close(input);
if (offset && e.target) e.target.selectionEnd = e.target.selectionStart = Math.min(offset, e.target.value.length);
} else if (keyName == 'Ctrl-U') {
// Ctrl-U clears input.
CodeMirror.e_stop(e);
close('');
} else {
if (keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift') vimGlobalState.exCommandHistoryController.reset();
}
}
if (command.type == 'keyToEx') {
// Handle user defined Ex to Ex mappings
exCommandDispatcher.processCommand(cm, command.exArgs.input);
} else {
if (vim.visualMode) {
showPrompt(cm, { onClose: onPromptClose, prefix: ':', value: '\'<,\'>',
onKeyDown: onPromptKeyDown, selectValueOnOpen: false });
} else {
showPrompt(cm, { onClose: onPromptClose, prefix: ':',
onKeyDown: onPromptKeyDown });
}
}
},
evalInput: function (cm, vim) {
// If the motion command is set, execute both the operator and motion.
// Otherwise return.
var inputState = vim.inputState;
var motion = inputState.motion;
var motionArgs = inputState.motionArgs || {};
var operator = inputState.operator;
var operatorArgs = inputState.operatorArgs || {};
var registerName = inputState.registerName;
var sel = vim.sel;
// TODO: Make sure cm and vim selections are identical outside visual mode.
var origHead = copyCursor(vim.visualMode ? clipCursorToContent(cm, sel.head) : cm.getCursor('head'));
var origAnchor = copyCursor(vim.visualMode ? clipCursorToContent(cm, sel.anchor) : cm.getCursor('anchor'));
var oldHead = copyCursor(origHead);
var oldAnchor = copyCursor(origAnchor);
var newHead, newAnchor;
var repeat;
if (operator) {
this.recordLastEdit(vim, inputState);
}
if (inputState.repeatOverride !== undefined) {
// If repeatOverride is specified, that takes precedence over the
// input state's repeat. Used by Ex mode and can be user defined.
repeat = inputState.repeatOverride;
} else {
repeat = inputState.getRepeat();
}
if (repeat > 0 && motionArgs.explicitRepeat) {
motionArgs.repeatIsExplicit = true;
} else if (motionArgs.noRepeat || !motionArgs.explicitRepeat && repeat === 0) {
repeat = 1;
motionArgs.repeatIsExplicit = false;
}
if (inputState.selectedCharacter) {
// If there is a character input, stick it in all of the arg arrays.
motionArgs.selectedCharacter = operatorArgs.selectedCharacter = inputState.selectedCharacter;
}
motionArgs.repeat = repeat;
clearInputState(cm);
if (motion) {
var motionResult = motions[motion](cm, origHead, motionArgs, vim);
vim.lastMotion = motions[motion];
if (!motionResult) {
return;
}
if (motionArgs.toJumplist) {
var jumpList = vimGlobalState.jumpList;
// if the current motion is # or *, use cachedCursor
var cachedCursor = jumpList.cachedCursor;
if (cachedCursor) {
recordJumpPosition(cm, cachedCursor, motionResult);
delete jumpList.cachedCursor;
} else {
recordJumpPosition(cm, origHead, motionResult);
}
}
if (motionResult instanceof Array) {
newAnchor = motionResult[0];
newHead = motionResult[1];
} else {
newHead = motionResult;
}
// TODO: Handle null returns from motion commands better.
if (!newHead) {
newHead = copyCursor(origHead);
}
if (vim.visualMode) {
if (!(vim.visualBlock && newHead.ch === Infinity)) {
newHead = clipCursorToContent(cm, newHead, vim.visualBlock);
}
if (newAnchor) {
newAnchor = clipCursorToContent(cm, newAnchor, true);
}
newAnchor = newAnchor || oldAnchor;
sel.anchor = newAnchor;
sel.head = newHead;
updateCmSelection(cm);
updateMark(cm, vim, '<', cursorIsBefore(newAnchor, newHead) ? newAnchor : newHead);
updateMark(cm, vim, '>', cursorIsBefore(newAnchor, newHead) ? newHead : newAnchor);
} else if (!operator) {
newHead = clipCursorToContent(cm, newHead);
cm.setCursor(newHead.line, newHead.ch);
}
}
if (operator) {
if (operatorArgs.lastSel) {
// Replaying a visual mode operation
newAnchor = oldAnchor;
var lastSel = operatorArgs.lastSel;
var lineOffset = Math.abs(lastSel.head.line - lastSel.anchor.line);
var chOffset = Math.abs(lastSel.head.ch - lastSel.anchor.ch);
if (lastSel.visualLine) {
// Linewise Visual mode: The same number of lines.
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch);
} else if (lastSel.visualBlock) {
// Blockwise Visual mode: The same number of lines and columns.
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch + chOffset);
} else if (lastSel.head.line == lastSel.anchor.line) {
// Normal Visual mode within one line: The same number of characters.
newHead = Pos(oldAnchor.line, oldAnchor.ch + chOffset);
} else {
// Normal Visual mode with several lines: The same number of lines, in the
// last line the same number of characters as in the last line the last time.
newHead = Pos(oldAnchor.line + lineOffset, oldAnchor.ch);
}
vim.visualMode = true;
vim.visualLine = lastSel.visualLine;
vim.visualBlock = lastSel.visualBlock;
sel = vim.sel = {
anchor: newAnchor,
head: newHead
};
updateCmSelection(cm);
} else if (vim.visualMode) {
operatorArgs.lastSel = {
anchor: copyCursor(sel.anchor),
head: copyCursor(sel.head),
visualBlock: vim.visualBlock,
visualLine: vim.visualLine
};
}
var curStart, curEnd, linewise, mode;
var cmSel;
if (vim.visualMode) {
// Init visual op
curStart = cursorMin(sel.head, sel.anchor);
curEnd = cursorMax(sel.head, sel.anchor);
linewise = vim.visualLine || operatorArgs.linewise;
mode = vim.visualBlock ? 'block' : linewise ? 'line' : 'char';
cmSel = makeCmSelection(cm, {
anchor: curStart,
head: curEnd
}, mode);
if (linewise) {
var ranges = cmSel.ranges;
if (mode == 'block') {
// Linewise operators in visual block mode extend to end of line
for (var i = 0; i < ranges.length; i++) {
ranges[i].head.ch = lineLength(cm, ranges[i].head.line);
}
} else if (mode == 'line') {
ranges[0].head = Pos(ranges[0].head.line + 1, 0);
}
}
} else {
// Init motion op
curStart = copyCursor(newAnchor || oldAnchor);
curEnd = copyCursor(newHead || oldHead);
if (cursorIsBefore(curEnd, curStart)) {
var tmp = curStart;
curStart = curEnd;
curEnd = tmp;
}
linewise = motionArgs.linewise || operatorArgs.linewise;
if (linewise) {
// Expand selection to entire line.
expandSelectionToLine(cm, curStart, curEnd);
} else if (motionArgs.forward) {
// Clip to trailing newlines only if the motion goes forward.
clipToLine(cm, curStart, curEnd);
}
mode = 'char';
var exclusive = !motionArgs.inclusive || linewise;
cmSel = makeCmSelection(cm, {
anchor: curStart,
head: curEnd
}, mode, exclusive);
}
cm.setSelections(cmSel.ranges, cmSel.primary);
vim.lastMotion = null;
operatorArgs.repeat = repeat; // For indent in visual mode.
operatorArgs.registerName = registerName;
// Keep track of linewise as it affects how paste and change behave.
operatorArgs.linewise = linewise;
var operatorMoveTo = operators[operator](cm, operatorArgs, cmSel.ranges, oldAnchor, newHead);
if (vim.visualMode) {
exitVisualMode(cm, operatorMoveTo != null);
}
if (operatorMoveTo) {
cm.setCursor(operatorMoveTo);
}
}
},
recordLastEdit: function (vim, inputState, actionCommand) {
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) {
return;
}
vim.lastEditInputState = inputState;
vim.lastEditActionCommand = actionCommand;
macroModeState.lastInsertModeChanges.changes = [];
macroModeState.lastInsertModeChanges.expectCursorActivityForChange = false;
}
};
/**
* typedef {Object{line:number,ch:number}} Cursor An object containing the
* position of the cursor.
*/
// All of the functions below return Cursor objects.
var motions = {
moveToTopLine: function (cm, _head, motionArgs) {
var line = getUserVisibleLines(cm).top + motionArgs.repeat - 1;
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
},
moveToMiddleLine: function (cm) {
var range = getUserVisibleLines(cm);
var line = Math.floor((range.top + range.bottom) * 0.5);
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
},
moveToBottomLine: function (cm, _head, motionArgs) {
var line = getUserVisibleLines(cm).bottom - motionArgs.repeat + 1;
return Pos(line, findFirstNonWhiteSpaceCharacter(cm.getLine(line)));
},
expandToLine: function (_cm, head, motionArgs) {
// Expands forward to end of line, and then to next line if repeat is
// >1. Does not handle backward motion!
var cur = head;
return Pos(cur.line + motionArgs.repeat - 1, Infinity);
},
findNext: function (cm, _head, motionArgs) {
var state = getSearchState(cm);
var query = state.getQuery();
if (!query) {
return;
}
var prev = !motionArgs.forward;
// If search is initiated with ? instead of /, negate direction.
prev = state.isReversed() ? !prev : prev;
highlightSearchMatches(cm, query);
return findNext(cm, prev /** prev */, query, motionArgs.repeat);
},
goToMark: function (cm, _head, motionArgs, vim) {
var pos = getMarkPos(cm, vim, motionArgs.selectedCharacter);
if (pos) {
return motionArgs.linewise ? { line: pos.line, ch: findFirstNonWhiteSpaceCharacter(cm.getLine(pos.line)) } : pos;
}
return null;
},
moveToOtherHighlightedEnd: function (cm, _head, motionArgs, vim) {
if (vim.visualBlock && motionArgs.sameLine) {
var sel = vim.sel;
return [clipCursorToContent(cm, Pos(sel.anchor.line, sel.head.ch)), clipCursorToContent(cm, Pos(sel.head.line, sel.anchor.ch))];
} else {
return [vim.sel.head, vim.sel.anchor];
}
},
jumpToMark: function (cm, head, motionArgs, vim) {
var best = head;
for (var i = 0; i < motionArgs.repeat; i++) {
var cursor = best;
for (var key in vim.marks) {
if (!isLowerCase(key)) {
continue;
}
var mark = vim.marks[key].find();
var isWrongDirection = motionArgs.forward ? cursorIsBefore(mark, cursor) : cursorIsBefore(cursor, mark);
if (isWrongDirection) {
continue;
}
if (motionArgs.linewise && mark.line == cursor.line) {
continue;
}
var equal = cursorEqual(cursor, best);
var between = motionArgs.forward ? cursorIsBetween(cursor, mark, best) : cursorIsBetween(best, mark, cursor);
if (equal || between) {
best = mark;
}
}
}
if (motionArgs.linewise) {
// Vim places the cursor on the first non-whitespace character of
// the line if there is one, else it places the cursor at the end
// of the line, regardless of whether a mark was found.
best = Pos(best.line, findFirstNonWhiteSpaceCharacter(cm.getLine(best.line)));
}
return best;
},
moveByCharacters: function (_cm, head, motionArgs) {
var cur = head;
var repeat = motionArgs.repeat;
var ch = motionArgs.forward ? cur.ch + repeat : cur.ch - repeat;
return Pos(cur.line, ch);
},
moveByLines: function (cm, head, motionArgs, vim) {
var cur = head;
var endCh = cur.ch;
// Depending what our last motion was, we may want to do different
// things. If our last motion was moving vertically, we want to
// preserve the HPos from our last horizontal move. If our last motion
// was going to the end of a line, moving vertically we should go to
// the end of the line, etc.
switch (vim.lastMotion) {
case this.moveByLines:
case this.moveByDisplayLines:
case this.moveByScroll:
case this.moveToColumn:
case this.moveToEol:
endCh = vim.lastHPos;
break;
default:
vim.lastHPos = endCh;
}
var repeat = motionArgs.repeat + (motionArgs.repeatOffset || 0);
var line = motionArgs.forward ? cur.line + repeat : cur.line - repeat;
var first = cm.firstLine();
var last = cm.lastLine();
// Vim go to line begin or line end when cursor at first/last line and
// move to previous/next line is triggered.
if (line < first && cur.line == first) {
return this.moveToStartOfLine(cm, head, motionArgs, vim);
} else if (line > last && cur.line == last) {
return this.moveToEol(cm, head, motionArgs, vim);
}
if (motionArgs.toFirstChar) {
endCh = findFirstNonWhiteSpaceCharacter(cm.getLine(line));
vim.lastHPos = endCh;
}
vim.lastHSPos = cm.charCoords(Pos(line, endCh), 'div').left;
return Pos(line, endCh);
},
moveByDisplayLines: function (cm, head, motionArgs, vim) {
var cur = head;
switch (vim.lastMotion) {
case this.moveByDisplayLines:
case this.moveByScroll:
case this.moveByLines:
case this.moveToColumn:
case this.moveToEol:
break;
default:
vim.lastHSPos = cm.charCoords(cur, 'div').left;
}
var repeat = motionArgs.repeat;
var res = cm.findPosV(cur, motionArgs.forward ? repeat : -repeat, 'line', vim.lastHSPos);
if (res.hitSide) {
if (motionArgs.forward) {
var lastCharCoords = cm.charCoords(res, 'div');
var goalCoords = { top: lastCharCoords.top + 8, left: vim.lastHSPos };
var res = cm.coordsChar(goalCoords, 'div');
} else {
var resCoords = cm.charCoords(Pos(cm.firstLine(), 0), 'div');
resCoords.left = vim.lastHSPos;
res = cm.coordsChar(resCoords, 'div');
}
}
vim.lastHPos = res.ch;
return res;
},
moveByPage: function (cm, head, motionArgs) {
// CodeMirror only exposes functions that move the cursor page down, so
// doing this bad hack to move the cursor and move it back. evalInput
// will move the cursor to where it should be in the end.
var curStart = head;
var repeat = motionArgs.repeat;
return cm.findPosV(curStart, motionArgs.forward ? repeat : -repeat, 'page');
},
moveByParagraph: function (cm, head, motionArgs) {
var dir = motionArgs.forward ? 1 : -1;
return findParagraph(cm, head, motionArgs.repeat, dir);
},
moveBySentence: function (cm, head, motionArgs) {
var dir = motionArgs.forward ? 1 : -1;
return findSentence(cm, head, motionArgs.repeat, dir);
},
moveByScroll: function (cm, head, motionArgs, vim) {
var scrollbox = cm.getScrollInfo();
var curEnd = null;
var repeat = motionArgs.repeat;
if (!repeat) {
repeat = scrollbox.clientHeight / (2 * cm.defaultTextHeight());
}
var orig = cm.charCoords(head, 'local');
motionArgs.repeat = repeat;
var curEnd = motions.moveByDisplayLines(cm, head, motionArgs, vim);
if (!curEnd) {
return null;
}
var dest = cm.charCoords(curEnd, 'local');
cm.scrollTo(null, scrollbox.top + dest.top - orig.top);
return curEnd;
},
moveByWords: function (cm, head, motionArgs) {
return moveToWord(cm, head, motionArgs.repeat, !!motionArgs.forward, !!motionArgs.wordEnd, !!motionArgs.bigWord);
},
moveTillCharacter: function (cm, _head, motionArgs) {
var repeat = motionArgs.repeat;
var curEnd = moveToCharacter(cm, repeat, motionArgs.forward, motionArgs.selectedCharacter);
var increment = motionArgs.forward ? -1 : 1;
recordLastCharacterSearch(increment, motionArgs);
if (!curEnd) return null;
curEnd.ch += increment;
return curEnd;
},
moveToCharacter: function (cm, head, motionArgs) {
var repeat = motionArgs.repeat;
recordLastCharacterSearch(0, motionArgs);
return moveToCharacter(cm, repeat, motionArgs.forward, motionArgs.selectedCharacter) || head;
},
moveToSymbol: function (cm, head, motionArgs) {
var repeat = motionArgs.repeat;
return findSymbol(cm, repeat, motionArgs.forward, motionArgs.selectedCharacter) || head;
},
moveToColumn: function (cm, head, motionArgs, vim) {
var repeat = motionArgs.repeat;
// repeat is equivalent to which column we want to move to!
vim.lastHPos = repeat - 1;
vim.lastHSPos = cm.charCoords(head, 'div').left;
return moveToColumn(cm, repeat);
},
moveToEol: function (cm, head, motionArgs, vim) {
var cur = head;
vim.lastHPos = Infinity;
var retval = Pos(cur.line + motionArgs.repeat - 1, Infinity);
var end = cm.clipPos(retval);
end.ch--;
vim.lastHSPos = cm.charCoords(end, 'div').left;
return retval;
},
moveToFirstNonWhiteSpaceCharacter: function (cm, head) {
// Go to the start of the line where the text begins, or the end for
// whitespace-only lines
var cursor = head;
return Pos(cursor.line, findFirstNonWhiteSpaceCharacter(cm.getLine(cursor.line)));
},
moveToMatchedSymbol: function (cm, head) {
var cursor = head;
var line = cursor.line;
var ch = cursor.ch;
var lineText = cm.getLine(line);
var symbol;
for (; ch < lineText.length; ch++) {
symbol = lineText.charAt(ch);
if (symbol && isMatchableSymbol(symbol)) {
var style = cm.getTokenTypeAt(Pos(line, ch + 1));
if (style !== "string" && style !== "comment") {
break;
}
}
}
if (ch < lineText.length) {
var matched = cm.findMatchingBracket(Pos(line, ch));
return matched.to;
} else {
return cursor;
}
},
moveToStartOfLine: function (_cm, head) {
return Pos(head.line, 0);
},
moveToLineOrEdgeOfDocument: function (cm, _head, motionArgs) {
var lineNum = motionArgs.forward ? cm.lastLine() : cm.firstLine();
if (motionArgs.repeatIsExplicit) {
lineNum = motionArgs.repeat - cm.getOption('firstLineNumber');
}
return Pos(lineNum, findFirstNonWhiteSpaceCharacter(cm.getLine(lineNum)));
},
textObjectManipulation: function (cm, head, motionArgs, vim) {
// TODO: lots of possible exceptions that can be thrown here. Try da(
// outside of a () block.
// TODO: adding <> >< to this map doesn't work, presumably because
// they're operators
var mirroredPairs = { '(': ')', ')': '(',
'{': '}', '}': '{',
'[': ']', ']': '[' };
var selfPaired = { '\'': true, '"': true };
var character = motionArgs.selectedCharacter;
// 'b' refers to '()' block.
// 'B' refers to '{}' block.
if (character == 'b') {
character = '(';
} else if (character == 'B') {
character = '{';
}
// Inclusive is the difference between a and i
// TODO: Instead of using the additional text object map to perform text
// object operations, merge the map into the defaultKeyMap and use
// motionArgs to define behavior. Define separate entries for 'aw',
// 'iw', 'a[', 'i[', etc.
var inclusive = !motionArgs.textObjectInner;
var tmp;
if (mirroredPairs[character]) {
tmp = selectCompanionObject(cm, head, character, inclusive);
} else if (selfPaired[character]) {
tmp = findBeginningAndEnd(cm, head, character, inclusive);
} else if (character === 'W') {
tmp = expandWordUnderCursor(cm, inclusive, true /** forward */
, true /** bigWord */);
} else if (character === 'w') {
tmp = expandWordUnderCursor(cm, inclusive, true /** forward */
, false /** bigWord */);
} else if (character === 'p') {
tmp = findParagraph(cm, head, motionArgs.repeat, 0, inclusive);
motionArgs.linewise = true;
if (vim.visualMode) {
if (!vim.visualLine) {
vim.visualLine = true;
}
} else {
var operatorArgs = vim.inputState.operatorArgs;
if (operatorArgs) {
operatorArgs.linewise = true;
}
tmp.end.line--;
}
} else {
// No text object defined for this, don't move.
return null;
}
if (!cm.state.vim.visualMode) {
return [tmp.start, tmp.end];
} else {
return expandSelection(cm, tmp.start, tmp.end);
}
},
repeatLastCharacterSearch: function (cm, head, motionArgs) {
var lastSearch = vimGlobalState.lastCharacterSearch;
var repeat = motionArgs.repeat;
var forward = motionArgs.forward === lastSearch.forward;
var increment = (lastSearch.increment ? 1 : 0) * (forward ? -1 : 1);
cm.moveH(-increment, 'char');
motionArgs.inclusive = forward ? true : false;
var curEnd = moveToCharacter(cm, repeat, forward, lastSearch.selectedCharacter);
if (!curEnd) {
cm.moveH(increment, 'char');
return head;
}
curEnd.ch += increment;
return curEnd;
}
};
function defineMotion(name, fn) {
motions[name] = fn;
}
function fillArray(val, times) {
var arr = [];
for (var i = 0; i < times; i++) {
arr.push(val);
}
return arr;
}
/**
* An operator acts on a text selection. It receives the list of selections
* as input. The corresponding CodeMirror selection is guaranteed to
* match the input selection.
*/
var operators = {
change: function (cm, args, ranges) {
var finalHead, text;
var vim = cm.state.vim;
vimGlobalState.macroModeState.lastInsertModeChanges.inVisualBlock = vim.visualBlock;
if (!vim.visualMode) {
var anchor = ranges[0].anchor,
head = ranges[0].head;
text = cm.getRange(anchor, head);
var lastState = vim.lastEditInputState || {};
if (lastState.motion == "moveByWords" && !isWhiteSpaceString(text)) {
// Exclude trailing whitespace if the range is not all whitespace.
var match = /\s+$/.exec(text);
if (match && lastState.motionArgs && lastState.motionArgs.forward) {
head = offsetCursor(head, 0, -match[0].length);
text = text.slice(0, -match[0].length);
}
}
var prevLineEnd = new Pos(anchor.line - 1, Number.MAX_VALUE);
var wasLastLine = cm.firstLine() == cm.lastLine();
if (head.line > cm.lastLine() && args.linewise && !wasLastLine) {
cm.replaceRange('', prevLineEnd, head);
} else {
cm.replaceRange('', anchor, head);
}
if (args.linewise) {
// Push the next line back down, if there is a next line.
if (!wasLastLine) {
cm.setCursor(prevLineEnd);
CodeMirror.commands.newlineAndIndent(cm);
}
// make sure cursor ends up at the end of the line.
anchor.ch = Number.MAX_VALUE;
}
finalHead = anchor;
} else {
text = cm.getSelection();
var replacement = fillArray('', ranges.length);
cm.replaceSelections(replacement);
finalHead = cursorMin(ranges[0].head, ranges[0].anchor);
}
vimGlobalState.registerController.pushText(args.registerName, 'change', text, args.linewise, ranges.length > 1);
actions.enterInsertMode(cm, { head: finalHead }, cm.state.vim);
},
// delete is a javascript keyword.
'delete': function (cm, args, ranges) {
var finalHead, text;
var vim = cm.state.vim;
if (!vim.visualBlock) {
var anchor = ranges[0].anchor,
head = ranges[0].head;
if (args.linewise && head.line != cm.firstLine() && anchor.line == cm.lastLine() && anchor.line == head.line - 1) {
// Special case for dd on last line (and first line).
if (anchor.line == cm.firstLine()) {
anchor.ch = 0;
} else {
anchor = Pos(anchor.line - 1, lineLength(cm, anchor.line - 1));
}
}
text = cm.getRange(anchor, head);
cm.replaceRange('', anchor, head);
finalHead = anchor;
if (args.linewise) {
finalHead = motions.moveToFirstNonWhiteSpaceCharacter(cm, anchor);
}
} else {
text = cm.getSelection();
var replacement = fillArray('', ranges.length);
cm.replaceSelections(replacement);
finalHead = ranges[0].anchor;
}
vimGlobalState.registerController.pushText(args.registerName, 'delete', text, args.linewise, vim.visualBlock);
var includeLineBreak = vim.insertMode;
return clipCursorToContent(cm, finalHead, includeLineBreak);
},
indent: function (cm, args, ranges) {
var vim = cm.state.vim;
var startLine = ranges[0].anchor.line;
var endLine = vim.visualBlock ? ranges[ranges.length - 1].anchor.line : ranges[0].head.line;
// In visual mode, n> shifts the selection right n times, instead of
// shifting n lines right once.
var repeat = vim.visualMode ? args.repeat : 1;
if (args.linewise) {
// The only way to delete a newline is to delete until the start of
// the next line, so in linewise mode evalInput will include the next
// line. We don't want this in indent, so we go back a line.
endLine--;
}
for (var i = startLine; i <= endLine; i++) {
for (var j = 0; j < repeat; j++) {
cm.indentLine(i, args.indentRight);
}
}
return motions.moveToFirstNonWhiteSpaceCharacter(cm, ranges[0].anchor);
},
changeCase: function (cm, args, ranges, oldAnchor, newHead) {
var selections = cm.getSelections();
var swapped = [];
var toLower = args.toLower;
for (var j = 0; j < selections.length; j++) {
var toSwap = selections[j];
var text = '';
if (toLower === true) {
text = toSwap.toLowerCase();
} else if (toLower === false) {
text = toSwap.toUpperCase();
} else {
for (var i = 0; i < toSwap.length; i++) {
var character = toSwap.charAt(i);
text += isUpperCase(character) ? character.toLowerCase() : character.toUpperCase();
}
}
swapped.push(text);
}
cm.replaceSelections(swapped);
if (args.shouldMoveCursor) {
return newHead;
} else if (!cm.state.vim.visualMode && args.linewise && ranges[0].anchor.line + 1 == ranges[0].head.line) {
return motions.moveToFirstNonWhiteSpaceCharacter(cm, oldAnchor);
} else if (args.linewise) {
return oldAnchor;
} else {
return cursorMin(ranges[0].anchor, ranges[0].head);
}
},
yank: function (cm, args, ranges, oldAnchor) {
var vim = cm.state.vim;
var text = cm.getSelection();
var endPos = vim.visualMode ? cursorMin(vim.sel.anchor, vim.sel.head, ranges[0].head, ranges[0].anchor) : oldAnchor;
vimGlobalState.registerController.pushText(args.registerName, 'yank', text, args.linewise, vim.visualBlock);
return endPos;
}
};
function defineOperator(name, fn) {
operators[name] = fn;
}
var actions = {
jumpListWalk: function (cm, actionArgs, vim) {
if (vim.visualMode) {
return;
}
var repeat = actionArgs.repeat;
var forward = actionArgs.forward;
var jumpList = vimGlobalState.jumpList;
var mark = jumpList.move(cm, forward ? repeat : -repeat);
var markPos = mark ? mark.find() : undefined;
markPos = markPos ? markPos : cm.getCursor();
cm.setCursor(markPos);
},
scroll: function (cm, actionArgs, vim) {
if (vim.visualMode) {
return;
}
var repeat = actionArgs.repeat || 1;
var lineHeight = cm.defaultTextHeight();
var top = cm.getScrollInfo().top;
var delta = lineHeight * repeat;
var newPos = actionArgs.forward ? top + delta : top - delta;
var cursor = copyCursor(cm.getCursor());
var cursorCoords = cm.charCoords(cursor, 'local');
if (actionArgs.forward) {
if (newPos > cursorCoords.top) {
cursor.line += (newPos - cursorCoords.top) / lineHeight;
cursor.line = Math.ceil(cursor.line);
cm.setCursor(cursor);
cursorCoords = cm.charCoords(cursor, 'local');
cm.scrollTo(null, cursorCoords.top);
} else {
// Cursor stays within bounds. Just reposition the scroll window.
cm.scrollTo(null, newPos);
}
} else {
var newBottom = newPos + cm.getScrollInfo().clientHeight;
if (newBottom < cursorCoords.bottom) {
cursor.line -= (cursorCoords.bottom - newBottom) / lineHeight;
cursor.line = Math.floor(cursor.line);
cm.setCursor(cursor);
cursorCoords = cm.charCoords(cursor, 'local');
cm.scrollTo(null, cursorCoords.bottom - cm.getScrollInfo().clientHeight);
} else {
// Cursor stays within bounds. Just reposition the scroll window.
cm.scrollTo(null, newPos);
}
}
},
scrollToCursor: function (cm, actionArgs) {
var lineNum = cm.getCursor().line;
var charCoords = cm.charCoords(Pos(lineNum, 0), 'local');
var height = cm.getScrollInfo().clientHeight;
var y = charCoords.top;
var lineHeight = charCoords.bottom - y;
switch (actionArgs.position) {
case 'center':
y = y - height / 2 + lineHeight;
break;
case 'bottom':
y = y - height + lineHeight;
break;
}
cm.scrollTo(null, y);
},
replayMacro: function (cm, actionArgs, vim) {
var registerName = actionArgs.selectedCharacter;
var repeat = actionArgs.repeat;
var macroModeState = vimGlobalState.macroModeState;
if (registerName == '@') {
registerName = macroModeState.latestRegister;
}
while (repeat--) {
executeMacroRegister(cm, vim, macroModeState, registerName);
}
},
enterMacroRecordMode: function (cm, actionArgs) {
var macroModeState = vimGlobalState.macroModeState;
var registerName = actionArgs.selectedCharacter;
if (vimGlobalState.registerController.isValidRegister(registerName)) {
macroModeState.enterMacroRecordMode(cm, registerName);
}
},
toggleOverwrite: function (cm) {
if (!cm.state.overwrite) {
cm.toggleOverwrite(true);
cm.setOption('keyMap', 'vim-replace');
CodeMirror.signal(cm, "vim-mode-change", { mode: "replace" });
} else {
cm.toggleOverwrite(false);
cm.setOption('keyMap', 'vim-insert');
CodeMirror.signal(cm, "vim-mode-change", { mode: "insert" });
}
},
enterInsertMode: function (cm, actionArgs, vim) {
if (cm.getOption('readOnly')) {
return;
}
vim.insertMode = true;
vim.insertModeRepeat = actionArgs && actionArgs.repeat || 1;
var insertAt = actionArgs ? actionArgs.insertAt : null;
var sel = vim.sel;
var head = actionArgs.head || cm.getCursor('head');
var height = cm.listSelections().length;
if (insertAt == 'eol') {
head = Pos(head.line, lineLength(cm, head.line));
} else if (insertAt == 'charAfter') {
head = offsetCursor(head, 0, 1);
} else if (insertAt == 'firstNonBlank') {
head = motions.moveToFirstNonWhiteSpaceCharacter(cm, head);
} else if (insertAt == 'startOfSelectedArea') {
if (!vim.visualBlock) {
if (sel.head.line < sel.anchor.line) {
head = sel.head;
} else {
head = Pos(sel.anchor.line, 0);
}
} else {
head = Pos(Math.min(sel.head.line, sel.anchor.line), Math.min(sel.head.ch, sel.anchor.ch));
height = Math.abs(sel.head.line - sel.anchor.line) + 1;
}
} else if (insertAt == 'endOfSelectedArea') {
if (!vim.visualBlock) {
if (sel.head.line >= sel.anchor.line) {
head = offsetCursor(sel.head, 0, 1);
} else {
head = Pos(sel.anchor.line, 0);
}
} else {
head = Pos(Math.min(sel.head.line, sel.anchor.line), Math.max(sel.head.ch + 1, sel.anchor.ch));
height = Math.abs(sel.head.line - sel.anchor.line) + 1;
}
} else if (insertAt == 'inplace') {
if (vim.visualMode) {
return;
}
}
cm.setOption('disableInput', false);
if (actionArgs && actionArgs.replace) {
// Handle Replace-mode as a special case of insert mode.
cm.toggleOverwrite(true);
cm.setOption('keyMap', 'vim-replace');
CodeMirror.signal(cm, "vim-mode-change", { mode: "replace" });
} else {
cm.toggleOverwrite(false);
cm.setOption('keyMap', 'vim-insert');
CodeMirror.signal(cm, "vim-mode-change", { mode: "insert" });
}
if (!vimGlobalState.macroModeState.isPlaying) {
// Only record if not replaying.
cm.on('change', onChange);
CodeMirror.on(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
}
if (vim.visualMode) {
exitVisualMode(cm);
}
selectForInsert(cm, head, height);
},
toggleVisualMode: function (cm, actionArgs, vim) {
var repeat = actionArgs.repeat;
var anchor = cm.getCursor();
var head;
// TODO: The repeat should actually select number of characters/lines
// equal to the repeat times the size of the previous visual
// operation.
if (!vim.visualMode) {
// Entering visual mode
vim.visualMode = true;
vim.visualLine = !!actionArgs.linewise;
vim.visualBlock = !!actionArgs.blockwise;
head = clipCursorToContent(cm, Pos(anchor.line, anchor.ch + repeat - 1), true /** includeLineBreak */);
vim.sel = {
anchor: anchor,
head: head
};
CodeMirror.signal(cm, "vim-mode-change", { mode: "visual", subMode: vim.visualLine ? "linewise" : vim.visualBlock ? "blockwise" : "" });
updateCmSelection(cm);
updateMark(cm, vim, '<', cursorMin(anchor, head));
updateMark(cm, vim, '>', cursorMax(anchor, head));
} else if (vim.visualLine ^ actionArgs.linewise || vim.visualBlock ^ actionArgs.blockwise) {
// Toggling between modes
vim.visualLine = !!actionArgs.linewise;
vim.visualBlock = !!actionArgs.blockwise;
CodeMirror.signal(cm, "vim-mode-change", { mode: "visual", subMode: vim.visualLine ? "linewise" : vim.visualBlock ? "blockwise" : "" });
updateCmSelection(cm);
} else {
exitVisualMode(cm);
}
},
reselectLastSelection: function (cm, _actionArgs, vim) {
var lastSelection = vim.lastSelection;
if (vim.visualMode) {
updateLastSelection(cm, vim);
}
if (lastSelection) {
var anchor = lastSelection.anchorMark.find();
var head = lastSelection.headMark.find();
if (!anchor || !head) {
// If the marks have been destroyed due to edits, do nothing.
return;
}
vim.sel = {
anchor: anchor,
head: head
};
vim.visualMode = true;
vim.visualLine = lastSelection.visualLine;
vim.visualBlock = lastSelection.visualBlock;
updateCmSelection(cm);
updateMark(cm, vim, '<', cursorMin(anchor, head));
updateMark(cm, vim, '>', cursorMax(anchor, head));
CodeMirror.signal(cm, 'vim-mode-change', {
mode: 'visual',
subMode: vim.visualLine ? 'linewise' : vim.visualBlock ? 'blockwise' : '' });
}
},
joinLines: function (cm, actionArgs, vim) {
var curStart, curEnd;
if (vim.visualMode) {
curStart = cm.getCursor('anchor');
curEnd = cm.getCursor('head');
if (cursorIsBefore(curEnd, curStart)) {
var tmp = curEnd;
curEnd = curStart;
curStart = tmp;
}
curEnd.ch = lineLength(cm, curEnd.line) - 1;
} else {
// Repeat is the number of lines to join. Minimum 2 lines.
var repeat = Math.max(actionArgs.repeat, 2);
curStart = cm.getCursor();
curEnd = clipCursorToContent(cm, Pos(curStart.line + repeat - 1, Infinity));
}
var finalCh = 0;
for (var i = curStart.line; i < curEnd.line; i++) {
finalCh = lineLength(cm, curStart.line);
var tmp = Pos(curStart.line + 1, lineLength(cm, curStart.line + 1));
var text = cm.getRange(curStart, tmp);
text = text.replace(/\n\s*/g, ' ');
cm.replaceRange(text, curStart, tmp);
}
var curFinalPos = Pos(curStart.line, finalCh);
if (vim.visualMode) {
exitVisualMode(cm, false);
}
cm.setCursor(curFinalPos);
},
newLineAndEnterInsertMode: function (cm, actionArgs, vim) {
vim.insertMode = true;
var insertAt = copyCursor(cm.getCursor());
if (insertAt.line === cm.firstLine() && !actionArgs.after) {
// Special case for inserting newline before start of document.
cm.replaceRange('\n', Pos(cm.firstLine(), 0));
cm.setCursor(cm.firstLine(), 0);
} else {
insertAt.line = actionArgs.after ? insertAt.line : insertAt.line - 1;
insertAt.ch = lineLength(cm, insertAt.line);
cm.setCursor(insertAt);
var newlineFn = CodeMirror.commands.newlineAndIndentContinueComment || CodeMirror.commands.newlineAndIndent;
newlineFn(cm);
}
this.enterInsertMode(cm, { repeat: actionArgs.repeat }, vim);
},
paste: function (cm, actionArgs, vim) {
var cur = copyCursor(cm.getCursor());
var register = vimGlobalState.registerController.getRegister(actionArgs.registerName);
var text = register.toString();
if (!text) {
return;
}
if (actionArgs.matchIndent) {
var tabSize = cm.getOption("tabSize");
// length that considers tabs and tabSize
var whitespaceLength = function (str) {
var tabs = str.split("\t").length - 1;
var spaces = str.split(" ").length - 1;
return tabs * tabSize + spaces * 1;
};
var currentLine = cm.getLine(cm.getCursor().line);
var indent = whitespaceLength(currentLine.match(/^\s*/)[0]);
// chomp last newline b/c don't want it to match /^\s*/gm
var chompedText = text.replace(/\n$/, '');
var wasChomped = text !== chompedText;
var firstIndent = whitespaceLength(text.match(/^\s*/)[0]);
var text = chompedText.replace(/^\s*/gm, function (wspace) {
var newIndent = indent + (whitespaceLength(wspace) - firstIndent);
if (newIndent < 0) {
return "";
} else if (cm.getOption("indentWithTabs")) {
var quotient = Math.floor(newIndent / tabSize);
return Array(quotient + 1).join('\t');
} else {
return Array(newIndent + 1).join(' ');
}
});
text += wasChomped ? "\n" : "";
}
if (actionArgs.repeat > 1) {
var text = Array(actionArgs.repeat + 1).join(text);
}
var linewise = register.linewise;
var blockwise = register.blockwise;
if (linewise) {
if (vim.visualMode) {
text = vim.visualLine ? text.slice(0, -1) : '\n' + text.slice(0, text.length - 1) + '\n';
} else if (actionArgs.after) {
// Move the newline at the end to the start instead, and paste just
// before the newline character of the line we are on right now.
text = '\n' + text.slice(0, text.length - 1);
cur.ch = lineLength(cm, cur.line);
} else {
cur.ch = 0;
}
} else {
if (blockwise) {
text = text.split('\n');
for (var i = 0; i < text.length; i++) {
text[i] = text[i] == '' ? ' ' : text[i];
}
}
cur.ch += actionArgs.after ? 1 : 0;
}
var curPosFinal;
var idx;
if (vim.visualMode) {
// save the pasted text for reselection if the need arises
vim.lastPastedText = text;
var lastSelectionCurEnd;
var selectedArea = getSelectedAreaRange(cm, vim);
var selectionStart = selectedArea[0];
var selectionEnd = selectedArea[1];
var selectedText = cm.getSelection();
var selections = cm.listSelections();
var emptyStrings = new Array(selections.length).join('1').split('1');
// save the curEnd marker before it get cleared due to cm.replaceRange.
if (vim.lastSelection) {
lastSelectionCurEnd = vim.lastSelection.headMark.find();
}
// push the previously selected text to unnamed register
vimGlobalState.registerController.unnamedRegister.setText(selectedText);
if (blockwise) {
// first delete the selected text
cm.replaceSelections(emptyStrings);
// Set new selections as per the block length of the yanked text
selectionEnd = Pos(selectionStart.line + text.length - 1, selectionStart.ch);
cm.setCursor(selectionStart);
selectBlock(cm, selectionEnd);
cm.replaceSelections(text);
curPosFinal = selectionStart;
} else if (vim.visualBlock) {
cm.replaceSelections(emptyStrings);
cm.setCursor(selectionStart);
cm.replaceRange(text, selectionStart, selectionStart);
curPosFinal = selectionStart;
} else {
cm.replaceRange(text, selectionStart, selectionEnd);
curPosFinal = cm.posFromIndex(cm.indexFromPos(selectionStart) + text.length - 1);
}
// restore the the curEnd marker
if (lastSelectionCurEnd) {
vim.lastSelection.headMark = cm.setBookmark(lastSelectionCurEnd);
}
if (linewise) {
curPosFinal.ch = 0;
}
} else {
if (blockwise) {
cm.setCursor(cur);
for (var i = 0; i < text.length; i++) {
var line = cur.line + i;
if (line > cm.lastLine()) {
cm.replaceRange('\n', Pos(line, 0));
}
var lastCh = lineLength(cm, line);
if (lastCh < cur.ch) {
extendLineToColumn(cm, line, cur.ch);
}
}
cm.setCursor(cur);
selectBlock(cm, Pos(cur.line + text.length - 1, cur.ch));
cm.replaceSelections(text);
curPosFinal = cur;
} else {
cm.replaceRange(text, cur);
// Now fine tune the cursor to where we want it.
if (linewise && actionArgs.after) {
curPosFinal = Pos(cur.line + 1, findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line + 1)));
} else if (linewise && !actionArgs.after) {
curPosFinal = Pos(cur.line, findFirstNonWhiteSpaceCharacter(cm.getLine(cur.line)));
} else if (!linewise && actionArgs.after) {
idx = cm.indexFromPos(cur);
curPosFinal = cm.posFromIndex(idx + text.length - 1);
} else {
idx = cm.indexFromPos(cur);
curPosFinal = cm.posFromIndex(idx + text.length);
}
}
}
if (vim.visualMode) {
exitVisualMode(cm, false);
}
cm.setCursor(curPosFinal);
},
undo: function (cm, actionArgs) {
cm.operation(function () {
repeatFn(cm, CodeMirror.commands.undo, actionArgs.repeat)();
cm.setCursor(cm.getCursor('anchor'));
});
},
redo: function (cm, actionArgs) {
repeatFn(cm, CodeMirror.commands.redo, actionArgs.repeat)();
},
setRegister: function (_cm, actionArgs, vim) {
vim.inputState.registerName = actionArgs.selectedCharacter;
},
setMark: function (cm, actionArgs, vim) {
var markName = actionArgs.selectedCharacter;
updateMark(cm, vim, markName, cm.getCursor());
},
replace: function (cm, actionArgs, vim) {
var replaceWith = actionArgs.selectedCharacter;
var curStart = cm.getCursor();
var replaceTo;
var curEnd;
var selections = cm.listSelections();
if (vim.visualMode) {
curStart = cm.getCursor('start');
curEnd = cm.getCursor('end');
} else {
var line = cm.getLine(curStart.line);
replaceTo = curStart.ch + actionArgs.repeat;
if (replaceTo > line.length) {
replaceTo = line.length;
}
curEnd = Pos(curStart.line, replaceTo);
}
if (replaceWith == '\n') {
if (!vim.visualMode) cm.replaceRange('', curStart, curEnd);
// special case, where vim help says to replace by just one line-break
(CodeMirror.commands.newlineAndIndentContinueComment || CodeMirror.commands.newlineAndIndent)(cm);
} else {
var replaceWithStr = cm.getRange(curStart, curEnd);
//replace all characters in range by selected, but keep linebreaks
replaceWithStr = replaceWithStr.replace(/[^\n]/g, replaceWith);
if (vim.visualBlock) {
// Tabs are split in visua block before replacing
var spaces = new Array(cm.getOption("tabSize") + 1).join(' ');
replaceWithStr = cm.getSelection();
replaceWithStr = replaceWithStr.replace(/\t/g, spaces).replace(/[^\n]/g, replaceWith).split('\n');
cm.replaceSelections(replaceWithStr);
} else {
cm.replaceRange(replaceWithStr, curStart, curEnd);
}
if (vim.visualMode) {
curStart = cursorIsBefore(selections[0].anchor, selections[0].head) ? selections[0].anchor : selections[0].head;
cm.setCursor(curStart);
exitVisualMode(cm, false);
} else {
cm.setCursor(offsetCursor(curEnd, 0, -1));
}
}
},
incrementNumberToken: function (cm, actionArgs) {
var cur = cm.getCursor();
var lineStr = cm.getLine(cur.line);
var re = /(-?)(?:(0x)([\da-f]+)|(0b|0|)(\d+))/gi;
var match;
var start;
var end;
var numberStr;
while ((match = re.exec(lineStr)) !== null) {
start = match.index;
end = start + match[0].length;
if (cur.ch < end) break;
}
if (!actionArgs.backtrack && end <= cur.ch) return;
if (match) {
var baseStr = match[2] || match[4];
var digits = match[3] || match[5];
var increment = actionArgs.increase ? 1 : -1;
var base = { '0b': 2, '0': 8, '': 10, '0x': 16 }[baseStr.toLowerCase()];
var number = parseInt(match[1] + digits, base) + increment * actionArgs.repeat;
numberStr = number.toString(base);
var zeroPadding = baseStr ? new Array(digits.length - numberStr.length + 1 + match[1].length).join('0') : '';
if (numberStr.charAt(0) === '-') {
numberStr = '-' + baseStr + zeroPadding + numberStr.substr(1);
} else {
numberStr = baseStr + zeroPadding + numberStr;
}
var from = Pos(cur.line, start);
var to = Pos(cur.line, end);
cm.replaceRange(numberStr, from, to);
} else {
return;
}
cm.setCursor(Pos(cur.line, start + numberStr.length - 1));
},
repeatLastEdit: function (cm, actionArgs, vim) {
var lastEditInputState = vim.lastEditInputState;
if (!lastEditInputState) {
return;
}
var repeat = actionArgs.repeat;
if (repeat && actionArgs.repeatIsExplicit) {
vim.lastEditInputState.repeatOverride = repeat;
} else {
repeat = vim.lastEditInputState.repeatOverride || repeat;
}
repeatLastEdit(cm, vim, repeat, false /** repeatForInsert */);
},
indent: function (cm, actionArgs) {
cm.indentLine(cm.getCursor().line, actionArgs.indentRight);
},
exitInsertMode: exitInsertMode
};
function defineAction(name, fn) {
actions[name] = fn;
}
/*
* Below are miscellaneous utility functions used by vim.js
*/
/**
* Clips cursor to ensure that line is within the buffer's range
* If includeLineBreak is true, then allow cur.ch == lineLength.
*/
function clipCursorToContent(cm, cur, includeLineBreak) {
var line = Math.min(Math.max(cm.firstLine(), cur.line), cm.lastLine());
var maxCh = lineLength(cm, line) - 1;
maxCh = includeLineBreak ? maxCh + 1 : maxCh;
var ch = Math.min(Math.max(0, cur.ch), maxCh);
return Pos(line, ch);
}
function copyArgs(args) {
var ret = {};
for (var prop in args) {
if (args.hasOwnProperty(prop)) {
ret[prop] = args[prop];
}
}
return ret;
}
function offsetCursor(cur, offsetLine, offsetCh) {
if (typeof offsetLine === 'object') {
offsetCh = offsetLine.ch;
offsetLine = offsetLine.line;
}
return Pos(cur.line + offsetLine, cur.ch + offsetCh);
}
function getOffset(anchor, head) {
return {
line: head.line - anchor.line,
ch: head.line - anchor.line
};
}
function commandMatches(keys, keyMap, context, inputState) {
// Partial matches are not applied. They inform the key handler
// that the current key sequence is a subsequence of a valid key
// sequence, so that the key buffer is not cleared.
var match,
partial = [],
full = [];
for (var i = 0; i < keyMap.length; i++) {
var command = keyMap[i];
if (context == 'insert' && command.context != 'insert' || command.context && command.context != context || inputState.operator && command.type == 'action' || !(match = commandMatch(keys, command.keys))) {
continue;
}
if (match == 'partial') {
partial.push(command);
}
if (match == 'full') {
full.push(command);
}
}
return {
partial: partial.length && partial,
full: full.length && full
};
}
function commandMatch(pressed, mapped) {
if (mapped.slice(-11) == '<character>') {
// Last character matches anything.
var prefixLen = mapped.length - 11;
var pressedPrefix = pressed.slice(0, prefixLen);
var mappedPrefix = mapped.slice(0, prefixLen);
return pressedPrefix == mappedPrefix && pressed.length > prefixLen ? 'full' : mappedPrefix.indexOf(pressedPrefix) == 0 ? 'partial' : false;
} else {
return pressed == mapped ? 'full' : mapped.indexOf(pressed) == 0 ? 'partial' : false;
}
}
function lastChar(keys) {
var match = /^.*(<[^>]+>)$/.exec(keys);
var selectedCharacter = match ? match[1] : keys.slice(-1);
if (selectedCharacter.length > 1) {
switch (selectedCharacter) {
case '<CR>':
selectedCharacter = '\n';
break;
case '<Space>':
selectedCharacter = ' ';
break;
default:
selectedCharacter = '';
break;
}
}
return selectedCharacter;
}
function repeatFn(cm, fn, repeat) {
return function () {
for (var i = 0; i < repeat; i++) {
fn(cm);
}
};
}
function copyCursor(cur) {
return Pos(cur.line, cur.ch);
}
function cursorEqual(cur1, cur2) {
return cur1.ch == cur2.ch && cur1.line == cur2.line;
}
function cursorIsBefore(cur1, cur2) {
if (cur1.line < cur2.line) {
return true;
}
if (cur1.line == cur2.line && cur1.ch < cur2.ch) {
return true;
}
return false;
}
function cursorMin(cur1, cur2) {
if (arguments.length > 2) {
cur2 = cursorMin.apply(undefined, Array.prototype.slice.call(arguments, 1));
}
return cursorIsBefore(cur1, cur2) ? cur1 : cur2;
}
function cursorMax(cur1, cur2) {
if (arguments.length > 2) {
cur2 = cursorMax.apply(undefined, Array.prototype.slice.call(arguments, 1));
}
return cursorIsBefore(cur1, cur2) ? cur2 : cur1;
}
function cursorIsBetween(cur1, cur2, cur3) {
// returns true if cur2 is between cur1 and cur3.
var cur1before2 = cursorIsBefore(cur1, cur2);
var cur2before3 = cursorIsBefore(cur2, cur3);
return cur1before2 && cur2before3;
}
function lineLength(cm, lineNum) {
return cm.getLine(lineNum).length;
}
function trim(s) {
if (s.trim) {
return s.trim();
}
return s.replace(/^\s+|\s+$/g, '');
}
function escapeRegex(s) {
return s.replace(/([.?*+$\[\]\/\\(){}|\-])/g, '\\$1');
}
function extendLineToColumn(cm, lineNum, column) {
var endCh = lineLength(cm, lineNum);
var spaces = new Array(column - endCh + 1).join(' ');
cm.setCursor(Pos(lineNum, endCh));
cm.replaceRange(spaces, cm.getCursor());
}
// This functions selects a rectangular block
// of text with selectionEnd as any of its corner
// Height of block:
// Difference in selectionEnd.line and first/last selection.line
// Width of the block:
// Distance between selectionEnd.ch and any(first considered here) selection.ch
function selectBlock(cm, selectionEnd) {
var selections = [],
ranges = cm.listSelections();
var head = copyCursor(cm.clipPos(selectionEnd));
var isClipped = !cursorEqual(selectionEnd, head);
var curHead = cm.getCursor('head');
var primIndex = getIndex(ranges, curHead);
var wasClipped = cursorEqual(ranges[primIndex].head, ranges[primIndex].anchor);
var max = ranges.length - 1;
var index = max - primIndex > primIndex ? max : 0;
var base = ranges[index].anchor;
var firstLine = Math.min(base.line, head.line);
var lastLine = Math.max(base.line, head.line);
var baseCh = base.ch,
headCh = head.ch;
var dir = ranges[index].head.ch - baseCh;
var newDir = headCh - baseCh;
if (dir > 0 && newDir <= 0) {
baseCh++;
if (!isClipped) {
headCh--;
}
} else if (dir < 0 && newDir >= 0) {
baseCh--;
if (!wasClipped) {
headCh++;
}
} else if (dir < 0 && newDir == -1) {
baseCh--;
headCh++;
}
for (var line = firstLine; line <= lastLine; line++) {
var range = { anchor: new Pos(line, baseCh), head: new Pos(line, headCh) };
selections.push(range);
}
cm.setSelections(selections);
selectionEnd.ch = headCh;
base.ch = baseCh;
return base;
}
function selectForInsert(cm, head, height) {
var sel = [];
for (var i = 0; i < height; i++) {
var lineHead = offsetCursor(head, i, 0);
sel.push({ anchor: lineHead, head: lineHead });
}
cm.setSelections(sel, 0);
}
// getIndex returns the index of the cursor in the selections.
function getIndex(ranges, cursor, end) {
for (var i = 0; i < ranges.length; i++) {
var atAnchor = end != 'head' && cursorEqual(ranges[i].anchor, cursor);
var atHead = end != 'anchor' && cursorEqual(ranges[i].head, cursor);
if (atAnchor || atHead) {
return i;
}
}
return -1;
}
function getSelectedAreaRange(cm, vim) {
var lastSelection = vim.lastSelection;
var getCurrentSelectedAreaRange = function () {
var selections = cm.listSelections();
var start = selections[0];
var end = selections[selections.length - 1];
var selectionStart = cursorIsBefore(start.anchor, start.head) ? start.anchor : start.head;
var selectionEnd = cursorIsBefore(end.anchor, end.head) ? end.head : end.anchor;
return [selectionStart, selectionEnd];
};
var getLastSelectedAreaRange = function () {
var selectionStart = cm.getCursor();
var selectionEnd = cm.getCursor();
var block = lastSelection.visualBlock;
if (block) {
var width = block.width;
var height = block.height;
selectionEnd = Pos(selectionStart.line + height, selectionStart.ch + width);
var selections = [];
// selectBlock creates a 'proper' rectangular block.
// We do not want that in all cases, so we manually set selections.
for (var i = selectionStart.line; i < selectionEnd.line; i++) {
var anchor = Pos(i, selectionStart.ch);
var head = Pos(i, selectionEnd.ch);
var range = { anchor: anchor, head: head };
selections.push(range);
}
cm.setSelections(selections);
} else {
var start = lastSelection.anchorMark.find();
var end = lastSelection.headMark.find();
var line = end.line - start.line;
var ch = end.ch - start.ch;
selectionEnd = { line: selectionEnd.line + line, ch: line ? selectionEnd.ch : ch + selectionEnd.ch };
if (lastSelection.visualLine) {
selectionStart = Pos(selectionStart.line, 0);
selectionEnd = Pos(selectionEnd.line, lineLength(cm, selectionEnd.line));
}
cm.setSelection(selectionStart, selectionEnd);
}
return [selectionStart, selectionEnd];
};
if (!vim.visualMode) {
// In case of replaying the action.
return getLastSelectedAreaRange();
} else {
return getCurrentSelectedAreaRange();
}
}
// Updates the previous selection with the current selection's values. This
// should only be called in visual mode.
function updateLastSelection(cm, vim) {
var anchor = vim.sel.anchor;
var head = vim.sel.head;
// To accommodate the effect of lastPastedText in the last selection
if (vim.lastPastedText) {
head = cm.posFromIndex(cm.indexFromPos(anchor) + vim.lastPastedText.length);
vim.lastPastedText = null;
}
vim.lastSelection = { 'anchorMark': cm.setBookmark(anchor),
'headMark': cm.setBookmark(head),
'anchor': copyCursor(anchor),
'head': copyCursor(head),
'visualMode': vim.visualMode,
'visualLine': vim.visualLine,
'visualBlock': vim.visualBlock };
}
function expandSelection(cm, start, end) {
var sel = cm.state.vim.sel;
var head = sel.head;
var anchor = sel.anchor;
var tmp;
if (cursorIsBefore(end, start)) {
tmp = end;
end = start;
start = tmp;
}
if (cursorIsBefore(head, anchor)) {
head = cursorMin(start, head);
anchor = cursorMax(anchor, end);
} else {
anchor = cursorMin(start, anchor);
head = cursorMax(head, end);
head = offsetCursor(head, 0, -1);
if (head.ch == -1 && head.line != cm.firstLine()) {
head = Pos(head.line - 1, lineLength(cm, head.line - 1));
}
}
return [anchor, head];
}
/**
* Updates the CodeMirror selection to match the provided vim selection.
* If no arguments are given, it uses the current vim selection state.
*/
function updateCmSelection(cm, sel, mode) {
var vim = cm.state.vim;
sel = sel || vim.sel;
var mode = mode || vim.visualLine ? 'line' : vim.visualBlock ? 'block' : 'char';
var cmSel = makeCmSelection(cm, sel, mode);
cm.setSelections(cmSel.ranges, cmSel.primary);
updateFakeCursor(cm);
}
function makeCmSelection(cm, sel, mode, exclusive) {
var head = copyCursor(sel.head);
var anchor = copyCursor(sel.anchor);
if (mode == 'char') {
var headOffset = !exclusive && !cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
var anchorOffset = cursorIsBefore(sel.head, sel.anchor) ? 1 : 0;
head = offsetCursor(sel.head, 0, headOffset);
anchor = offsetCursor(sel.anchor, 0, anchorOffset);
return {
ranges: [{ anchor: anchor, head: head }],
primary: 0
};
} else if (mode == 'line') {
if (!cursorIsBefore(sel.head, sel.anchor)) {
anchor.ch = 0;
var lastLine = cm.lastLine();
if (head.line > lastLine) {
head.line = lastLine;
}
head.ch = lineLength(cm, head.line);
} else {
head.ch = 0;
anchor.ch = lineLength(cm, anchor.line);
}
return {
ranges: [{ anchor: anchor, head: head }],
primary: 0
};
} else if (mode == 'block') {
var top = Math.min(anchor.line, head.line),
left = Math.min(anchor.ch, head.ch),
bottom = Math.max(anchor.line, head.line),
right = Math.max(anchor.ch, head.ch) + 1;
var height = bottom - top + 1;
var primary = head.line == top ? 0 : height - 1;
var ranges = [];
for (var i = 0; i < height; i++) {
ranges.push({
anchor: Pos(top + i, left),
head: Pos(top + i, right)
});
}
return {
ranges: ranges,
primary: primary
};
}
}
function getHead(cm) {
var cur = cm.getCursor('head');
if (cm.getSelection().length == 1) {
// Small corner case when only 1 character is selected. The "real"
// head is the left of head and anchor.
cur = cursorMin(cur, cm.getCursor('anchor'));
}
return cur;
}
/**
* If moveHead is set to false, the CodeMirror selection will not be
* touched. The caller assumes the responsibility of putting the cursor
* in the right place.
*/
function exitVisualMode(cm, moveHead) {
var vim = cm.state.vim;
if (moveHead !== false) {
cm.setCursor(clipCursorToContent(cm, vim.sel.head));
}
updateLastSelection(cm, vim);
vim.visualMode = false;
vim.visualLine = false;
vim.visualBlock = false;
CodeMirror.signal(cm, "vim-mode-change", { mode: "normal" });
if (vim.fakeCursor) {
vim.fakeCursor.clear();
}
}
// Remove any trailing newlines from the selection. For
// example, with the caret at the start of the last word on the line,
// 'dw' should word, but not the newline, while 'w' should advance the
// caret to the first character of the next line.
function clipToLine(cm, curStart, curEnd) {
var selection = cm.getRange(curStart, curEnd);
// Only clip if the selection ends with trailing newline + whitespace
if (/\n\s*$/.test(selection)) {
var lines = selection.split('\n');
// We know this is all whitespace.
lines.pop();
// Cases:
// 1. Last word is an empty line - do not clip the trailing '\n'
// 2. Last word is not an empty line - clip the trailing '\n'
var line;
// Find the line containing the last word, and clip all whitespace up
// to it.
for (var line = lines.pop(); lines.length > 0 && line && isWhiteSpaceString(line); line = lines.pop()) {
curEnd.line--;
curEnd.ch = 0;
}
// If the last word is not an empty line, clip an additional newline
if (line) {
curEnd.line--;
curEnd.ch = lineLength(cm, curEnd.line);
} else {
curEnd.ch = 0;
}
}
}
// Expand the selection to line ends.
function expandSelectionToLine(_cm, curStart, curEnd) {
curStart.ch = 0;
curEnd.ch = 0;
curEnd.line++;
}
function findFirstNonWhiteSpaceCharacter(text) {
if (!text) {
return 0;
}
var firstNonWS = text.search(/\S/);
return firstNonWS == -1 ? text.length : firstNonWS;
}
function expandWordUnderCursor(cm, inclusive, _forward, bigWord, noSymbol) {
var cur = getHead(cm);
var line = cm.getLine(cur.line);
var idx = cur.ch;
// Seek to first word or non-whitespace character, depending on if
// noSymbol is true.
var test = noSymbol ? wordCharTest[0] : bigWordCharTest[0];
while (!test(line.charAt(idx))) {
idx++;
if (idx >= line.length) {
return null;
}
}
if (bigWord) {
test = bigWordCharTest[0];
} else {
test = wordCharTest[0];
if (!test(line.charAt(idx))) {
test = wordCharTest[1];
}
}
var end = idx,
start = idx;
while (test(line.charAt(end)) && end < line.length) {
end++;
}
while (test(line.charAt(start)) && start >= 0) {
start--;
}
start++;
if (inclusive) {
// If present, include all whitespace after word.
// Otherwise, include all whitespace before word, except indentation.
var wordEnd = end;
while (/\s/.test(line.charAt(end)) && end < line.length) {
end++;
}
if (wordEnd == end) {
var wordStart = start;
while (/\s/.test(line.charAt(start - 1)) && start > 0) {
start--;
}
if (!start) {
start = wordStart;
}
}
}
return { start: Pos(cur.line, start), end: Pos(cur.line, end) };
}
function recordJumpPosition(cm, oldCur, newCur) {
if (!cursorEqual(oldCur, newCur)) {
vimGlobalState.jumpList.add(cm, oldCur, newCur);
}
}
function recordLastCharacterSearch(increment, args) {
vimGlobalState.lastCharacterSearch.increment = increment;
vimGlobalState.lastCharacterSearch.forward = args.forward;
vimGlobalState.lastCharacterSearch.selectedCharacter = args.selectedCharacter;
}
var symbolToMode = {
'(': 'bracket', ')': 'bracket', '{': 'bracket', '}': 'bracket',
'[': 'section', ']': 'section',
'*': 'comment', '/': 'comment',
'm': 'method', 'M': 'method',
'#': 'preprocess'
};
var findSymbolModes = {
bracket: {
isComplete: function (state) {
if (state.nextCh === state.symb) {
state.depth++;
if (state.depth >= 1) return true;
} else if (state.nextCh === state.reverseSymb) {
state.depth--;
}
return false;
}
},
section: {
init: function (state) {
state.curMoveThrough = true;
state.symb = (state.forward ? ']' : '[') === state.symb ? '{' : '}';
},
isComplete: function (state) {
return state.index === 0 && state.nextCh === state.symb;
}
},
comment: {
isComplete: function (state) {
var found = state.lastCh === '*' && state.nextCh === '/';
state.lastCh = state.nextCh;
return found;
}
},
// TODO: The original Vim implementation only operates on level 1 and 2.
// The current implementation doesn't check for code block level and
// therefore it operates on any levels.
method: {
init: function (state) {
state.symb = state.symb === 'm' ? '{' : '}';
state.reverseSymb = state.symb === '{' ? '}' : '{';
},
isComplete: function (state) {
if (state.nextCh === state.symb) return true;
return false;
}
},
preprocess: {
init: function (state) {
state.index = 0;
},
isComplete: function (state) {
if (state.nextCh === '#') {
var token = state.lineText.match(/#(\w+)/)[1];
if (token === 'endif') {
if (state.forward && state.depth === 0) {
return true;
}
state.depth++;
} else if (token === 'if') {
if (!state.forward && state.depth === 0) {
return true;
}
state.depth--;
}
if (token === 'else' && state.depth === 0) return true;
}
return false;
}
}
};
function findSymbol(cm, repeat, forward, symb) {
var cur = copyCursor(cm.getCursor());
var increment = forward ? 1 : -1;
var endLine = forward ? cm.lineCount() : -1;
var curCh = cur.ch;
var line = cur.line;
var lineText = cm.getLine(line);
var state = {
lineText: lineText,
nextCh: lineText.charAt(curCh),
lastCh: null,
index: curCh,
symb: symb,
reverseSymb: (forward ? { ')': '(', '}': '{' } : { '(': ')', '{': '}' })[symb],
forward: forward,
depth: 0,
curMoveThrough: false
};
var mode = symbolToMode[symb];
if (!mode) return cur;
var init = findSymbolModes[mode].init;
var isComplete = findSymbolModes[mode].isComplete;
if (init) {
init(state);
}
while (line !== endLine && repeat) {
state.index += increment;
state.nextCh = state.lineText.charAt(state.index);
if (!state.nextCh) {
line += increment;
state.lineText = cm.getLine(line) || '';
if (increment > 0) {
state.index = 0;
} else {
var lineLen = state.lineText.length;
state.index = lineLen > 0 ? lineLen - 1 : 0;
}
state.nextCh = state.lineText.charAt(state.index);
}
if (isComplete(state)) {
cur.line = line;
cur.ch = state.index;
repeat--;
}
}
if (state.nextCh || state.curMoveThrough) {
return Pos(line, state.index);
}
return cur;
}
/*
* Returns the boundaries of the next word. If the cursor in the middle of
* the word, then returns the boundaries of the current word, starting at
* the cursor. If the cursor is at the start/end of a word, and we are going
* forward/backward, respectively, find the boundaries of the next word.
*
* @param {CodeMirror} cm CodeMirror object.
* @param {Cursor} cur The cursor position.
* @param {boolean} forward True to search forward. False to search
* backward.
* @param {boolean} bigWord True if punctuation count as part of the word.
* False if only [a-zA-Z0-9] characters count as part of the word.
* @param {boolean} emptyLineIsWord True if empty lines should be treated
* as words.
* @return {Object{from:number, to:number, line: number}} The boundaries of
* the word, or null if there are no more words.
*/
function findWord(cm, cur, forward, bigWord, emptyLineIsWord) {
var lineNum = cur.line;
var pos = cur.ch;
var line = cm.getLine(lineNum);
var dir = forward ? 1 : -1;
var charTests = bigWord ? bigWordCharTest : wordCharTest;
if (emptyLineIsWord && line == '') {
lineNum += dir;
line = cm.getLine(lineNum);
if (!isLine(cm, lineNum)) {
return null;
}
pos = forward ? 0 : line.length;
}
while (true) {
if (emptyLineIsWord && line == '') {
return { from: 0, to: 0, line: lineNum };
}
var stop = dir > 0 ? line.length : -1;
var wordStart = stop,
wordEnd = stop;
// Find bounds of next word.
while (pos != stop) {
var foundWord = false;
for (var i = 0; i < charTests.length && !foundWord; ++i) {
if (charTests[i](line.charAt(pos))) {
wordStart = pos;
// Advance to end of word.
while (pos != stop && charTests[i](line.charAt(pos))) {
pos += dir;
}
wordEnd = pos;
foundWord = wordStart != wordEnd;
if (wordStart == cur.ch && lineNum == cur.line && wordEnd == wordStart + dir) {
// We started at the end of a word. Find the next one.
continue;
} else {
return {
from: Math.min(wordStart, wordEnd + 1),
to: Math.max(wordStart, wordEnd),
line: lineNum };
}
}
}
if (!foundWord) {
pos += dir;
}
}
// Advance to next/prev line.
lineNum += dir;
if (!isLine(cm, lineNum)) {
return null;
}
line = cm.getLine(lineNum);
pos = dir > 0 ? 0 : line.length;
}
}
/**
* @param {CodeMirror} cm CodeMirror object.
* @param {Pos} cur The position to start from.
* @param {int} repeat Number of words to move past.
* @param {boolean} forward True to search forward. False to search
* backward.
* @param {boolean} wordEnd True to move to end of word. False to move to
* beginning of word.
* @param {boolean} bigWord True if punctuation count as part of the word.
* False if only alphabet characters count as part of the word.
* @return {Cursor} The position the cursor should move to.
*/
function moveToWord(cm, cur, repeat, forward, wordEnd, bigWord) {
var curStart = copyCursor(cur);
var words = [];
if (forward && !wordEnd || !forward && wordEnd) {
repeat++;
}
// For 'e', empty lines are not considered words, go figure.
var emptyLineIsWord = !(forward && wordEnd);
for (var i = 0; i < repeat; i++) {
var word = findWord(cm, cur, forward, bigWord, emptyLineIsWord);
if (!word) {
var eodCh = lineLength(cm, cm.lastLine());
words.push(forward ? { line: cm.lastLine(), from: eodCh, to: eodCh } : { line: 0, from: 0, to: 0 });
break;
}
words.push(word);
cur = Pos(word.line, forward ? word.to - 1 : word.from);
}
var shortCircuit = words.length != repeat;
var firstWord = words[0];
var lastWord = words.pop();
if (forward && !wordEnd) {
// w
if (!shortCircuit && (firstWord.from != curStart.ch || firstWord.line != curStart.line)) {
// We did not start in the middle of a word. Discard the extra word at the end.
lastWord = words.pop();
}
return Pos(lastWord.line, lastWord.from);
} else if (forward && wordEnd) {
return Pos(lastWord.line, lastWord.to - 1);
} else if (!forward && wordEnd) {
// ge
if (!shortCircuit && (firstWord.to != curStart.ch || firstWord.line != curStart.line)) {
// We did not start in the middle of a word. Discard the extra word at the end.
lastWord = words.pop();
}
return Pos(lastWord.line, lastWord.to);
} else {
// b
return Pos(lastWord.line, lastWord.from);
}
}
function moveToCharacter(cm, repeat, forward, character) {
var cur = cm.getCursor();
var start = cur.ch;
var idx;
for (var i = 0; i < repeat; i++) {
var line = cm.getLine(cur.line);
idx = charIdxInLine(start, line, character, forward, true);
if (idx == -1) {
return null;
}
start = idx;
}
return Pos(cm.getCursor().line, idx);
}
function moveToColumn(cm, repeat) {
// repeat is always >= 1, so repeat - 1 always corresponds
// to the column we want to go to.
var line = cm.getCursor().line;
return clipCursorToContent(cm, Pos(line, repeat - 1));
}
function updateMark(cm, vim, markName, pos) {
if (!inArray(markName, validMarks)) {
return;
}
if (vim.marks[markName]) {
vim.marks[markName].clear();
}
vim.marks[markName] = cm.setBookmark(pos);
}
function charIdxInLine(start, line, character, forward, includeChar) {
// Search for char in line.
// motion_options: {forward, includeChar}
// If includeChar = true, include it too.
// If forward = true, search forward, else search backwards.
// If char is not found on this line, do nothing
var idx;
if (forward) {
idx = line.indexOf(character, start + 1);
if (idx != -1 && !includeChar) {
idx -= 1;
}
} else {
idx = line.lastIndexOf(character, start - 1);
if (idx != -1 && !includeChar) {
idx += 1;
}
}
return idx;
}
function findParagraph(cm, head, repeat, dir, inclusive) {
var line = head.line;
var min = cm.firstLine();
var max = cm.lastLine();
var start,
end,
i = line;
function isEmpty(i) {
return !cm.getLine(i);
}
function isBoundary(i, dir, any) {
if (any) {
return isEmpty(i) != isEmpty(i + dir);
}
return !isEmpty(i) && isEmpty(i + dir);
}
if (dir) {
while (min <= i && i <= max && repeat > 0) {
if (isBoundary(i, dir)) {
repeat--;
}
i += dir;
}
return new Pos(i, 0);
}
var vim = cm.state.vim;
if (vim.visualLine && isBoundary(line, 1, true)) {
var anchor = vim.sel.anchor;
if (isBoundary(anchor.line, -1, true)) {
if (!inclusive || anchor.line != line) {
line += 1;
}
}
}
var startState = isEmpty(line);
for (i = line; i <= max && repeat; i++) {
if (isBoundary(i, 1, true)) {
if (!inclusive || isEmpty(i) != startState) {
repeat--;
}
}
}
end = new Pos(i, 0);
// select boundary before paragraph for the last one
if (i > max && !startState) {
startState = true;
} else {
inclusive = false;
}
for (i = line; i > min; i--) {
if (!inclusive || isEmpty(i) == startState || i == line) {
if (isBoundary(i, -1, true)) {
break;
}
}
}
start = new Pos(i, 0);
return { start: start, end: end };
}
function findSentence(cm, cur, repeat, dir) {
/*
Takes an index object
{
line: the line string,
ln: line number,
pos: index in line,
dir: direction of traversal (-1 or 1)
}
and modifies the line, ln, and pos members to represent the
next valid position or sets them to null if there are
no more valid positions.
*/
function nextChar(cm, idx) {
if (idx.pos + idx.dir < 0 || idx.pos + idx.dir >= idx.line.length) {
idx.ln += idx.dir;
if (!isLine(cm, idx.ln)) {
idx.line = null;
idx.ln = null;
idx.pos = null;
return;
}
idx.line = cm.getLine(idx.ln);
idx.pos = idx.dir > 0 ? 0 : idx.line.length - 1;
} else {
idx.pos += idx.dir;
}
}
/*
Performs one iteration of traversal in forward direction
Returns an index object of the new location
*/
function forward(cm, ln, pos, dir) {
var line = cm.getLine(ln);
var stop = line === "";
var curr = {
line: line,
ln: ln,
pos: pos,
dir: dir
};
var last_valid = {
ln: curr.ln,
pos: curr.pos
};
var skip_empty_lines = curr.line === "";
// Move one step to skip character we start on
nextChar(cm, curr);
while (curr.line !== null) {
last_valid.ln = curr.ln;
last_valid.pos = curr.pos;
if (curr.line === "" && !skip_empty_lines) {
return { ln: curr.ln, pos: curr.pos };
} else if (stop && curr.line !== "" && !isWhiteSpaceString(curr.line[curr.pos])) {
return { ln: curr.ln, pos: curr.pos };
} else if (isEndOfSentenceSymbol(curr.line[curr.pos]) && !stop && (curr.pos === curr.line.length - 1 || isWhiteSpaceString(curr.line[curr.pos + 1]))) {
stop = true;
}
nextChar(cm, curr);
}
/*
Set the position to the last non whitespace character on the last
valid line in the case that we reach the end of the document.
*/
var line = cm.getLine(last_valid.ln);
last_valid.pos = 0;
for (var i = line.length - 1; i >= 0; --i) {
if (!isWhiteSpaceString(line[i])) {
last_valid.pos = i;
break;
}
}
return last_valid;
}
/*
Performs one iteration of traversal in reverse direction
Returns an index object of the new location
*/
function reverse(cm, ln, pos, dir) {
var line = cm.getLine(ln);
var curr = {
line: line,
ln: ln,
pos: pos,
dir: dir
};
var last_valid = {
ln: curr.ln,
pos: null
};
var skip_empty_lines = curr.line === "";
// Move one step to skip character we start on
nextChar(cm, curr);
while (curr.line !== null) {
if (curr.line === "" && !skip_empty_lines) {
if (last_valid.pos !== null) {
return last_valid;
} else {
return { ln: curr.ln, pos: curr.pos };
}
} else if (isEndOfSentenceSymbol(curr.line[curr.pos]) && last_valid.pos !== null && !(curr.ln === last_valid.ln && curr.pos + 1 === last_valid.pos)) {
return last_valid;
} else if (curr.line !== "" && !isWhiteSpaceString(curr.line[curr.pos])) {
skip_empty_lines = false;
last_valid = { ln: curr.ln, pos: curr.pos };
}
nextChar(cm, curr);
}
/*
Set the position to the first non whitespace character on the last
valid line in the case that we reach the beginning of the document.
*/
var line = cm.getLine(last_valid.ln);
last_valid.pos = 0;
for (var i = 0; i < line.length; ++i) {
if (!isWhiteSpaceString(line[i])) {
last_valid.pos = i;
break;
}
}
return last_valid;
}
var curr_index = {
ln: cur.line,
pos: cur.ch
};
while (repeat > 0) {
if (dir < 0) {
curr_index = reverse(cm, curr_index.ln, curr_index.pos, dir);
} else {
curr_index = forward(cm, curr_index.ln, curr_index.pos, dir);
}
repeat--;
}
return Pos(curr_index.ln, curr_index.pos);
}
// TODO: perhaps this finagling of start and end positions belonds
// in codemirror/replaceRange?
function selectCompanionObject(cm, head, symb, inclusive) {
var cur = head,
start,
end;
var bracketRegexp = {
'(': /[()]/, ')': /[()]/,
'[': /[[\]]/, ']': /[[\]]/,
'{': /[{}]/, '}': /[{}]/ }[symb];
var openSym = {
'(': '(', ')': '(',
'[': '[', ']': '[',
'{': '{', '}': '{' }[symb];
var curChar = cm.getLine(cur.line).charAt(cur.ch);
// Due to the behavior of scanForBracket, we need to add an offset if the
// cursor is on a matching open bracket.
var offset = curChar === openSym ? 1 : 0;
start = cm.scanForBracket(Pos(cur.line, cur.ch + offset), -1, undefined, { 'bracketRegex': bracketRegexp });
end = cm.scanForBracket(Pos(cur.line, cur.ch + offset), 1, undefined, { 'bracketRegex': bracketRegexp });
if (!start || !end) {
return { start: cur, end: cur };
}
start = start.pos;
end = end.pos;
if (start.line == end.line && start.ch > end.ch || start.line > end.line) {
var tmp = start;
start = end;
end = tmp;
}
if (inclusive) {
end.ch += 1;
} else {
start.ch += 1;
}
return { start: start, end: end };
}
// Takes in a symbol and a cursor and tries to simulate text objects that
// have identical opening and closing symbols
// TODO support across multiple lines
function findBeginningAndEnd(cm, head, symb, inclusive) {
var cur = copyCursor(head);
var line = cm.getLine(cur.line);
var chars = line.split('');
var start, end, i, len;
var firstIndex = chars.indexOf(symb);
// the decision tree is to always look backwards for the beginning first,
// but if the cursor is in front of the first instance of the symb,
// then move the cursor forward
if (cur.ch < firstIndex) {
cur.ch = firstIndex;
// Why is this line even here???
// cm.setCursor(cur.line, firstIndex+1);
}
// otherwise if the cursor is currently on the closing symbol
else if (firstIndex < cur.ch && chars[cur.ch] == symb) {
end = cur.ch; // assign end to the current cursor
--cur.ch; // make sure to look backwards
}
// if we're currently on the symbol, we've got a start
if (chars[cur.ch] == symb && !end) {
start = cur.ch + 1; // assign start to ahead of the cursor
} else {
// go backwards to find the start
for (i = cur.ch; i > -1 && !start; i--) {
if (chars[i] == symb) {
start = i + 1;
}
}
}
// look forwards for the end symbol
if (start && !end) {
for (i = start, len = chars.length; i < len && !end; i++) {
if (chars[i] == symb) {
end = i;
}
}
}
// nothing found
if (!start || !end) {
return { start: cur, end: cur };
}
// include the symbols
if (inclusive) {
--start;++end;
}
return {
start: Pos(cur.line, start),
end: Pos(cur.line, end)
};
}
// Search functions
defineOption('pcre', true, 'boolean');
function SearchState() {}
SearchState.prototype = {
getQuery: function () {
return vimGlobalState.query;
},
setQuery: function (query) {
vimGlobalState.query = query;
},
getOverlay: function () {
return this.searchOverlay;
},
setOverlay: function (overlay) {
this.searchOverlay = overlay;
},
isReversed: function () {
return vimGlobalState.isReversed;
},
setReversed: function (reversed) {
vimGlobalState.isReversed = reversed;
},
getScrollbarAnnotate: function () {
return this.annotate;
},
setScrollbarAnnotate: function (annotate) {
this.annotate = annotate;
}
};
function getSearchState(cm) {
var vim = cm.state.vim;
return vim.searchState_ || (vim.searchState_ = new SearchState());
}
function dialog(cm, template, shortText, onClose, options) {
if (cm.openDialog) {
cm.openDialog(template, onClose, { bottom: true, value: options.value,
onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp,
selectValueOnOpen: false });
} else {
onClose(prompt(shortText, ''));
}
}
function splitBySlash(argString) {
return splitBySeparator(argString, '/');
}
function findUnescapedSlashes(argString) {
return findUnescapedSeparators(argString, '/');
}
function splitBySeparator(argString, separator) {
var slashes = findUnescapedSeparators(argString, separator) || [];
if (!slashes.length) return [];
var tokens = [];
// in case of strings like foo/bar
if (slashes[0] !== 0) return;
for (var i = 0; i < slashes.length; i++) {
if (typeof slashes[i] == 'number') tokens.push(argString.substring(slashes[i] + 1, slashes[i + 1]));
}
return tokens;
}
function findUnescapedSeparators(str, separator) {
if (!separator) separator = '/';
var escapeNextChar = false;
var slashes = [];
for (var i = 0; i < str.length; i++) {
var c = str.charAt(i);
if (!escapeNextChar && c == separator) {
slashes.push(i);
}
escapeNextChar = !escapeNextChar && c == '\\';
}
return slashes;
}
// Translates a search string from ex (vim) syntax into javascript form.
function translateRegex(str) {
// When these match, add a '\' if unescaped or remove one if escaped.
var specials = '|(){';
// Remove, but never add, a '\' for these.
var unescape = '}';
var escapeNextChar = false;
var out = [];
for (var i = -1; i < str.length; i++) {
var c = str.charAt(i) || '';
var n = str.charAt(i + 1) || '';
var specialComesNext = n && specials.indexOf(n) != -1;
if (escapeNextChar) {
if (c !== '\\' || !specialComesNext) {
out.push(c);
}
escapeNextChar = false;
} else {
if (c === '\\') {
escapeNextChar = true;
// Treat the unescape list as special for removing, but not adding '\'.
if (n && unescape.indexOf(n) != -1) {
specialComesNext = true;
}
// Not passing this test means removing a '\'.
if (!specialComesNext || n === '\\') {
out.push(c);
}
} else {
out.push(c);
if (specialComesNext && n !== '\\') {
out.push('\\');
}
}
}
}
return out.join('');
}
// Translates the replace part of a search and replace from ex (vim) syntax into
// javascript form. Similar to translateRegex, but additionally fixes back references
// (translates '\[0..9]' to '$[0..9]') and follows different rules for escaping '$'.
var charUnescapes = { '\\n': '\n', '\\r': '\r', '\\t': '\t' };
function translateRegexReplace(str) {
var escapeNextChar = false;
var out = [];
for (var i = -1; i < str.length; i++) {
var c = str.charAt(i) || '';
var n = str.charAt(i + 1) || '';
if (charUnescapes[c + n]) {
out.push(charUnescapes[c + n]);
i++;
} else if (escapeNextChar) {
// At any point in the loop, escapeNextChar is true if the previous
// character was a '\' and was not escaped.
out.push(c);
escapeNextChar = false;
} else {
if (c === '\\') {
escapeNextChar = true;
if (isNumber(n) || n === '$') {
out.push('$');
} else if (n !== '/' && n !== '\\') {
out.push('\\');
}
} else {
if (c === '$') {
out.push('$');
}
out.push(c);
if (n === '/') {
out.push('\\');
}
}
}
}
return out.join('');
}
// Unescape \ and / in the replace part, for PCRE mode.
var unescapes = { '\\/': '/', '\\\\': '\\', '\\n': '\n', '\\r': '\r', '\\t': '\t' };
function unescapeRegexReplace(str) {
var stream = new CodeMirror.StringStream(str);
var output = [];
while (!stream.eol()) {
// Search for \.
while (stream.peek() && stream.peek() != '\\') {
output.push(stream.next());
}
var matched = false;
for (var matcher in unescapes) {
if (stream.match(matcher, true)) {
matched = true;
output.push(unescapes[matcher]);
break;
}
}
if (!matched) {
// Don't change anything
output.push(stream.next());
}
}
return output.join('');
}
/**
* Extract the regular expression from the query and return a Regexp object.
* Returns null if the query is blank.
* If ignoreCase is passed in, the Regexp object will have the 'i' flag set.
* If smartCase is passed in, and the query contains upper case letters,
* then ignoreCase is overridden, and the 'i' flag will not be set.
* If the query contains the /i in the flag part of the regular expression,
* then both ignoreCase and smartCase are ignored, and 'i' will be passed
* through to the Regex object.
*/
function parseQuery(query, ignoreCase, smartCase) {
// First update the last search register
var lastSearchRegister = vimGlobalState.registerController.getRegister('/');
lastSearchRegister.setText(query);
// Check if the query is already a regex.
if (query instanceof RegExp) {
return query;
}
// First try to extract regex + flags from the input. If no flags found,
// extract just the regex. IE does not accept flags directly defined in
// the regex string in the form /regex/flags
var slashes = findUnescapedSlashes(query);
var regexPart;
var forceIgnoreCase;
if (!slashes.length) {
// Query looks like 'regexp'
regexPart = query;
} else {
// Query looks like 'regexp/...'
regexPart = query.substring(0, slashes[0]);
var flagsPart = query.substring(slashes[0]);
forceIgnoreCase = flagsPart.indexOf('i') != -1;
}
if (!regexPart) {
return null;
}
if (!getOption('pcre')) {
regexPart = translateRegex(regexPart);
}
if (smartCase) {
ignoreCase = /^[^A-Z]*$/.test(regexPart);
}
var regexp = new RegExp(regexPart, ignoreCase || forceIgnoreCase ? 'i' : undefined);
return regexp;
}
function showConfirm(cm, text) {
if (cm.openNotification) {
cm.openNotification('<span style="color: red">' + text + '</span>', { bottom: true, duration: 5000 });
} else {
alert(text);
}
}
function makePrompt(prefix, desc) {
var raw = '<span style="font-family: monospace; white-space: pre">' + (prefix || "") + '<input type="text"></span>';
if (desc) raw += ' <span style="color: #888">' + desc + '</span>';
return raw;
}
var searchPromptDesc = '(Javascript regexp)';
function showPrompt(cm, options) {
var shortText = (options.prefix || '') + ' ' + (options.desc || '');
var prompt = makePrompt(options.prefix, options.desc);
dialog(cm, prompt, shortText, options.onClose, options);
}
function regexEqual(r1, r2) {
if (r1 instanceof RegExp && r2 instanceof RegExp) {
var props = ['global', 'multiline', 'ignoreCase', 'source'];
for (var i = 0; i < props.length; i++) {
var prop = props[i];
if (r1[prop] !== r2[prop]) {
return false;
}
}
return true;
}
return false;
}
// Returns true if the query is valid.
function updateSearchQuery(cm, rawQuery, ignoreCase, smartCase) {
if (!rawQuery) {
return;
}
var state = getSearchState(cm);
var query = parseQuery(rawQuery, !!ignoreCase, !!smartCase);
if (!query) {
return;
}
highlightSearchMatches(cm, query);
if (regexEqual(query, state.getQuery())) {
return query;
}
state.setQuery(query);
return query;
}
function searchOverlay(query) {
if (query.source.charAt(0) == '^') {
var matchSol = true;
}
return {
token: function (stream) {
if (matchSol && !stream.sol()) {
stream.skipToEnd();
return;
}
var match = stream.match(query, false);
if (match) {
if (match[0].length == 0) {
// Matched empty string, skip to next.
stream.next();
return 'searching';
}
if (!stream.sol()) {
// Backtrack 1 to match \b
stream.backUp(1);
if (!query.exec(stream.next() + match[0])) {
stream.next();
return null;
}
}
stream.match(query);
return 'searching';
}
while (!stream.eol()) {
stream.next();
if (stream.match(query, false)) break;
}
},
query: query
};
}
function highlightSearchMatches(cm, query) {
var searchState = getSearchState(cm);
var overlay = searchState.getOverlay();
if (!overlay || query != overlay.query) {
if (overlay) {
cm.removeOverlay(overlay);
}
overlay = searchOverlay(query);
cm.addOverlay(overlay);
if (cm.showMatchesOnScrollbar) {
if (searchState.getScrollbarAnnotate()) {
searchState.getScrollbarAnnotate().clear();
}
searchState.setScrollbarAnnotate(cm.showMatchesOnScrollbar(query));
}
searchState.setOverlay(overlay);
}
}
function findNext(cm, prev, query, repeat) {
if (repeat === undefined) {
repeat = 1;
}
return cm.operation(function () {
var pos = cm.getCursor();
var cursor = cm.getSearchCursor(query, pos);
for (var i = 0; i < repeat; i++) {
var found = cursor.find(prev);
if (i == 0 && found && cursorEqual(cursor.from(), pos)) {
found = cursor.find(prev);
}
if (!found) {
// SearchCursor may have returned null because it hit EOF, wrap
// around and try again.
cursor = cm.getSearchCursor(query, prev ? Pos(cm.lastLine()) : Pos(cm.firstLine(), 0));
if (!cursor.find(prev)) {
return;
}
}
}
return cursor.from();
});
}
function clearSearchHighlight(cm) {
var state = getSearchState(cm);
cm.removeOverlay(getSearchState(cm).getOverlay());
state.setOverlay(null);
if (state.getScrollbarAnnotate()) {
state.getScrollbarAnnotate().clear();
state.setScrollbarAnnotate(null);
}
}
/**
* Check if pos is in the specified range, INCLUSIVE.
* Range can be specified with 1 or 2 arguments.
* If the first range argument is an array, treat it as an array of line
* numbers. Match pos against any of the lines.
* If the first range argument is a number,
* if there is only 1 range argument, check if pos has the same line
* number
* if there are 2 range arguments, then check if pos is in between the two
* range arguments.
*/
function isInRange(pos, start, end) {
if (typeof pos != 'number') {
// Assume it is a cursor position. Get the line number.
pos = pos.line;
}
if (start instanceof Array) {
return inArray(pos, start);
} else {
if (end) {
return pos >= start && pos <= end;
} else {
return pos == start;
}
}
}
function getUserVisibleLines(cm) {
var scrollInfo = cm.getScrollInfo();
var occludeToleranceTop = 6;
var occludeToleranceBottom = 10;
var from = cm.coordsChar({ left: 0, top: occludeToleranceTop + scrollInfo.top }, 'local');
var bottomY = scrollInfo.clientHeight - occludeToleranceBottom + scrollInfo.top;
var to = cm.coordsChar({ left: 0, top: bottomY }, 'local');
return { top: from.line, bottom: to.line };
}
function getMarkPos(cm, vim, markName) {
if (markName == '\'') {
var history = cm.doc.history.done;
var event = history[history.length - 2];
return event && event.ranges && event.ranges[0].head;
} else if (markName == '.') {
if (cm.doc.history.lastModTime == 0) {
return; // If no changes, bail out; don't bother to copy or reverse history array.
} else {
var changeHistory = cm.doc.history.done.filter(function (el) {
if (el.changes !== undefined) {
return el;
}
});
changeHistory.reverse();
var lastEditPos = changeHistory[0].changes[0].to;
}
return lastEditPos;
}
var mark = vim.marks[markName];
return mark && mark.find();
}
var ExCommandDispatcher = function () {
this.buildCommandMap_();
};
ExCommandDispatcher.prototype = {
processCommand: function (cm, input, opt_params) {
var that = this;
cm.operation(function () {
cm.curOp.isVimOp = true;
that._processCommand(cm, input, opt_params);
});
},
_processCommand: function (cm, input, opt_params) {
var vim = cm.state.vim;
var commandHistoryRegister = vimGlobalState.registerController.getRegister(':');
var previousCommand = commandHistoryRegister.toString();
if (vim.visualMode) {
exitVisualMode(cm);
}
var inputStream = new CodeMirror.StringStream(input);
// update ": with the latest command whether valid or invalid
commandHistoryRegister.setText(input);
var params = opt_params || {};
params.input = input;
try {
this.parseInput_(cm, inputStream, params);
} catch (e) {
showConfirm(cm, e);
throw e;
}
var command;
var commandName;
if (!params.commandName) {
// If only a line range is defined, move to the line.
if (params.line !== undefined) {
commandName = 'move';
}
} else {
command = this.matchCommand_(params.commandName);
if (command) {
commandName = command.name;
if (command.excludeFromCommandHistory) {
commandHistoryRegister.setText(previousCommand);
}
this.parseCommandArgs_(inputStream, params, command);
if (command.type == 'exToKey') {
// Handle Ex to Key mapping.
for (var i = 0; i < command.toKeys.length; i++) {
CodeMirror.Vim.handleKey(cm, command.toKeys[i], 'mapping');
}
return;
} else if (command.type == 'exToEx') {
// Handle Ex to Ex mapping.
this.processCommand(cm, command.toInput);
return;
}
}
}
if (!commandName) {
showConfirm(cm, 'Not an editor command ":' + input + '"');
return;
}
try {
exCommands[commandName](cm, params);
// Possibly asynchronous commands (e.g. substitute, which might have a
// user confirmation), are responsible for calling the callback when
// done. All others have it taken care of for them here.
if ((!command || !command.possiblyAsync) && params.callback) {
params.callback();
}
} catch (e) {
showConfirm(cm, e);
throw e;
}
},
parseInput_: function (cm, inputStream, result) {
inputStream.eatWhile(':');
// Parse range.
if (inputStream.eat('%')) {
result.line = cm.firstLine();
result.lineEnd = cm.lastLine();
} else {
result.line = this.parseLineSpec_(cm, inputStream);
if (result.line !== undefined && inputStream.eat(',')) {
result.lineEnd = this.parseLineSpec_(cm, inputStream);
}
}
// Parse command name.
var commandMatch = inputStream.match(/^(\w+)/);
if (commandMatch) {
result.commandName = commandMatch[1];
} else {
result.commandName = inputStream.match(/.*/)[0];
}
return result;
},
parseLineSpec_: function (cm, inputStream) {
var numberMatch = inputStream.match(/^(\d+)/);
if (numberMatch) {
// Absolute line number plus offset (N+M or N-M) is probably a typo,
// not something the user actually wanted. (NB: vim does allow this.)
return parseInt(numberMatch[1], 10) - 1;
}
switch (inputStream.next()) {
case '.':
return this.parseLineSpecOffset_(inputStream, cm.getCursor().line);
case '$':
return this.parseLineSpecOffset_(inputStream, cm.lastLine());
case '\'':
var markName = inputStream.next();
var markPos = getMarkPos(cm, cm.state.vim, markName);
if (!markPos) throw new Error('Mark not set');
return this.parseLineSpecOffset_(inputStream, markPos.line);
case '-':
case '+':
inputStream.backUp(1);
// Offset is relative to current line if not otherwise specified.
return this.parseLineSpecOffset_(inputStream, cm.getCursor().line);
default:
inputStream.backUp(1);
return undefined;
}
},
parseLineSpecOffset_: function (inputStream, line) {
var offsetMatch = inputStream.match(/^([+-])?(\d+)/);
if (offsetMatch) {
var offset = parseInt(offsetMatch[2], 10);
if (offsetMatch[1] == "-") {
line -= offset;
} else {
line += offset;
}
}
return line;
},
parseCommandArgs_: function (inputStream, params, command) {
if (inputStream.eol()) {
return;
}
params.argString = inputStream.match(/.*/)[0];
// Parse command-line arguments
var delim = command.argDelimiter || /\s+/;
var args = trim(params.argString).split(delim);
if (args.length && args[0]) {
params.args = args;
}
},
matchCommand_: function (commandName) {
// Return the command in the command map that matches the shortest
// prefix of the passed in command name. The match is guaranteed to be
// unambiguous if the defaultExCommandMap's shortNames are set up
// correctly. (see @code{defaultExCommandMap}).
for (var i = commandName.length; i > 0; i--) {
var prefix = commandName.substring(0, i);
if (this.commandMap_[prefix]) {
var command = this.commandMap_[prefix];
if (command.name.indexOf(commandName) === 0) {
return command;
}
}
}
return null;
},
buildCommandMap_: function () {
this.commandMap_ = {};
for (var i = 0; i < defaultExCommandMap.length; i++) {
var command = defaultExCommandMap[i];
var key = command.shortName || command.name;
this.commandMap_[key] = command;
}
},
map: function (lhs, rhs, ctx) {
if (lhs != ':' && lhs.charAt(0) == ':') {
if (ctx) {
throw Error('Mode not supported for ex mappings');
}
var commandName = lhs.substring(1);
if (rhs != ':' && rhs.charAt(0) == ':') {
// Ex to Ex mapping
this.commandMap_[commandName] = {
name: commandName,
type: 'exToEx',
toInput: rhs.substring(1),
user: true
};
} else {
// Ex to key mapping
this.commandMap_[commandName] = {
name: commandName,
type: 'exToKey',
toKeys: rhs,
user: true
};
}
} else {
if (rhs != ':' && rhs.charAt(0) == ':') {
// Key to Ex mapping.
var mapping = {
keys: lhs,
type: 'keyToEx',
exArgs: { input: rhs.substring(1) }
};
if (ctx) {
mapping.context = ctx;
}
defaultKeymap.unshift(mapping);
} else {
// Key to key mapping
var mapping = {
keys: lhs,
type: 'keyToKey',
toKeys: rhs
};
if (ctx) {
mapping.context = ctx;
}
defaultKeymap.unshift(mapping);
}
}
},
unmap: function (lhs, ctx) {
if (lhs != ':' && lhs.charAt(0) == ':') {
// Ex to Ex or Ex to key mapping
if (ctx) {
throw Error('Mode not supported for ex mappings');
}
var commandName = lhs.substring(1);
if (this.commandMap_[commandName] && this.commandMap_[commandName].user) {
delete this.commandMap_[commandName];
return;
}
} else {
// Key to Ex or key to key mapping
var keys = lhs;
for (var i = 0; i < defaultKeymap.length; i++) {
if (keys == defaultKeymap[i].keys && defaultKeymap[i].context === ctx) {
defaultKeymap.splice(i, 1);
return;
}
}
}
throw Error('No such mapping.');
}
};
var exCommands = {
colorscheme: function (cm, params) {
if (!params.args || params.args.length < 1) {
showConfirm(cm, cm.getOption('theme'));
return;
}
cm.setOption('theme', params.args[0]);
},
map: function (cm, params, ctx) {
var mapArgs = params.args;
if (!mapArgs || mapArgs.length < 2) {
if (cm) {
showConfirm(cm, 'Invalid mapping: ' + params.input);
}
return;
}
exCommandDispatcher.map(mapArgs[0], mapArgs[1], ctx);
},
imap: function (cm, params) {
this.map(cm, params, 'insert');
},
nmap: function (cm, params) {
this.map(cm, params, 'normal');
},
vmap: function (cm, params) {
this.map(cm, params, 'visual');
},
unmap: function (cm, params, ctx) {
var mapArgs = params.args;
if (!mapArgs || mapArgs.length < 1) {
if (cm) {
showConfirm(cm, 'No such mapping: ' + params.input);
}
return;
}
exCommandDispatcher.unmap(mapArgs[0], ctx);
},
move: function (cm, params) {
commandDispatcher.processCommand(cm, cm.state.vim, {
type: 'motion',
motion: 'moveToLineOrEdgeOfDocument',
motionArgs: { forward: false, explicitRepeat: true,
linewise: true },
repeatOverride: params.line + 1 });
},
set: function (cm, params) {
var setArgs = params.args;
// Options passed through to the setOption/getOption calls. May be passed in by the
// local/global versions of the set command
var setCfg = params.setCfg || {};
if (!setArgs || setArgs.length < 1) {
if (cm) {
showConfirm(cm, 'Invalid mapping: ' + params.input);
}
return;
}
var expr = setArgs[0].split('=');
var optionName = expr[0];
var value = expr[1];
var forceGet = false;
if (optionName.charAt(optionName.length - 1) == '?') {
// If post-fixed with ?, then the set is actually a get.
if (value) {
throw Error('Trailing characters: ' + params.argString);
}
optionName = optionName.substring(0, optionName.length - 1);
forceGet = true;
}
if (value === undefined && optionName.substring(0, 2) == 'no') {
// To set boolean options to false, the option name is prefixed with
// 'no'.
optionName = optionName.substring(2);
value = false;
}
var optionIsBoolean = options[optionName] && options[optionName].type == 'boolean';
if (optionIsBoolean && value == undefined) {
// Calling set with a boolean option sets it to true.
value = true;
}
// If no value is provided, then we assume this is a get.
if (!optionIsBoolean && value === undefined || forceGet) {
var oldValue = getOption(optionName, cm, setCfg);
if (oldValue instanceof Error) {
showConfirm(cm, oldValue.message);
} else if (oldValue === true || oldValue === false) {
showConfirm(cm, ' ' + (oldValue ? '' : 'no') + optionName);
} else {
showConfirm(cm, ' ' + optionName + '=' + oldValue);
}
} else {
var setOptionReturn = setOption(optionName, value, cm, setCfg);
if (setOptionReturn instanceof Error) {
showConfirm(cm, setOptionReturn.message);
}
}
},
setlocal: function (cm, params) {
// setCfg is passed through to setOption
params.setCfg = { scope: 'local' };
this.set(cm, params);
},
setglobal: function (cm, params) {
// setCfg is passed through to setOption
params.setCfg = { scope: 'global' };
this.set(cm, params);
},
registers: function (cm, params) {
var regArgs = params.args;
var registers = vimGlobalState.registerController.registers;
var regInfo = '----------Registers----------<br><br>';
if (!regArgs) {
for (var registerName in registers) {
var text = registers[registerName].toString();
if (text.length) {
regInfo += '"' + registerName + ' ' + text + '<br>';
}
}
} else {
var registerName;
regArgs = regArgs.join('');
for (var i = 0; i < regArgs.length; i++) {
registerName = regArgs.charAt(i);
if (!vimGlobalState.registerController.isValidRegister(registerName)) {
continue;
}
var register = registers[registerName] || new Register();
regInfo += '"' + registerName + ' ' + register.toString() + '<br>';
}
}
showConfirm(cm, regInfo);
},
sort: function (cm, params) {
var reverse, ignoreCase, unique, number, pattern;
function parseArgs() {
if (params.argString) {
var args = new CodeMirror.StringStream(params.argString);
if (args.eat('!')) {
reverse = true;
}
if (args.eol()) {
return;
}
if (!args.eatSpace()) {
return 'Invalid arguments';
}
var opts = args.match(/([dinuox]+)?\s*(\/.+\/)?\s*/);
if (!opts && !args.eol()) {
return 'Invalid arguments';
}
if (opts[1]) {
ignoreCase = opts[1].indexOf('i') != -1;
unique = opts[1].indexOf('u') != -1;
var decimal = opts[1].indexOf('d') != -1 || opts[1].indexOf('n') != -1 && 1;
var hex = opts[1].indexOf('x') != -1 && 1;
var octal = opts[1].indexOf('o') != -1 && 1;
if (decimal + hex + octal > 1) {
return 'Invalid arguments';
}
number = decimal && 'decimal' || hex && 'hex' || octal && 'octal';
}
if (opts[2]) {
pattern = new RegExp(opts[2].substr(1, opts[2].length - 2), ignoreCase ? 'i' : '');
}
}
}
var err = parseArgs();
if (err) {
showConfirm(cm, err + ': ' + params.argString);
return;
}
var lineStart = params.line || cm.firstLine();
var lineEnd = params.lineEnd || params.line || cm.lastLine();
if (lineStart == lineEnd) {
return;
}
var curStart = Pos(lineStart, 0);
var curEnd = Pos(lineEnd, lineLength(cm, lineEnd));
var text = cm.getRange(curStart, curEnd).split('\n');
var numberRegex = pattern ? pattern : number == 'decimal' ? /(-?)([\d]+)/ : number == 'hex' ? /(-?)(?:0x)?([0-9a-f]+)/i : number == 'octal' ? /([0-7]+)/ : null;
var radix = number == 'decimal' ? 10 : number == 'hex' ? 16 : number == 'octal' ? 8 : null;
var numPart = [],
textPart = [];
if (number || pattern) {
for (var i = 0; i < text.length; i++) {
var matchPart = pattern ? text[i].match(pattern) : null;
if (matchPart && matchPart[0] != '') {
numPart.push(matchPart);
} else if (!pattern && numberRegex.exec(text[i])) {
numPart.push(text[i]);
} else {
textPart.push(text[i]);
}
}
} else {
textPart = text;
}
function compareFn(a, b) {
if (reverse) {
var tmp;tmp = a;a = b;b = tmp;
}
if (ignoreCase) {
a = a.toLowerCase();b = b.toLowerCase();
}
var anum = number && numberRegex.exec(a);
var bnum = number && numberRegex.exec(b);
if (!anum) {
return a < b ? -1 : 1;
}
anum = parseInt((anum[1] + anum[2]).toLowerCase(), radix);
bnum = parseInt((bnum[1] + bnum[2]).toLowerCase(), radix);
return anum - bnum;
}
function comparePatternFn(a, b) {
if (reverse) {
var tmp;tmp = a;a = b;b = tmp;
}
if (ignoreCase) {
a[0] = a[0].toLowerCase();b[0] = b[0].toLowerCase();
}
return a[0] < b[0] ? -1 : 1;
}
numPart.sort(pattern ? comparePatternFn : compareFn);
if (pattern) {
for (var i = 0; i < numPart.length; i++) {
numPart[i] = numPart[i].input;
}
} else if (!number) {
textPart.sort(compareFn);
}
text = !reverse ? textPart.concat(numPart) : numPart.concat(textPart);
if (unique) {
// Remove duplicate lines
var textOld = text;
var lastLine;
text = [];
for (var i = 0; i < textOld.length; i++) {
if (textOld[i] != lastLine) {
text.push(textOld[i]);
}
lastLine = textOld[i];
}
}
cm.replaceRange(text.join('\n'), curStart, curEnd);
},
global: function (cm, params) {
// a global command is of the form
// :[range]g/pattern/[cmd]
// argString holds the string /pattern/[cmd]
var argString = params.argString;
if (!argString) {
showConfirm(cm, 'Regular Expression missing from global');
return;
}
// range is specified here
var lineStart = params.line !== undefined ? params.line : cm.firstLine();
var lineEnd = params.lineEnd || params.line || cm.lastLine();
// get the tokens from argString
var tokens = splitBySlash(argString);
var regexPart = argString,
cmd;
if (tokens.length) {
regexPart = tokens[0];
cmd = tokens.slice(1, tokens.length).join('/');
}
if (regexPart) {
// If regex part is empty, then use the previous query. Otherwise
// use the regex part as the new query.
try {
updateSearchQuery(cm, regexPart, true /** ignoreCase */
, true /** smartCase */);
} catch (e) {
showConfirm(cm, 'Invalid regex: ' + regexPart);
return;
}
}
// now that we have the regexPart, search for regex matches in the
// specified range of lines
var query = getSearchState(cm).getQuery();
var matchedLines = [],
content = '';
for (var i = lineStart; i <= lineEnd; i++) {
var matched = query.test(cm.getLine(i));
if (matched) {
matchedLines.push(i + 1);
content += cm.getLine(i) + '<br>';
}
}
// if there is no [cmd], just display the list of matched lines
if (!cmd) {
showConfirm(cm, content);
return;
}
var index = 0;
var nextCommand = function () {
if (index < matchedLines.length) {
var command = matchedLines[index] + cmd;
exCommandDispatcher.processCommand(cm, command, {
callback: nextCommand
});
}
index++;
};
nextCommand();
},
substitute: function (cm, params) {
if (!cm.getSearchCursor) {
throw new Error('Search feature not available. Requires searchcursor.js or ' + 'any other getSearchCursor implementation.');
}
var argString = params.argString;
var tokens = argString ? splitBySeparator(argString, argString[0]) : [];
var regexPart,
replacePart = '',
trailing,
flagsPart,
count;
var confirm = false; // Whether to confirm each replace.
var global = false; // True to replace all instances on a line, false to replace only 1.
if (tokens.length) {
regexPart = tokens[0];
replacePart = tokens[1];
if (regexPart && regexPart[regexPart.length - 1] === '$') {
regexPart = regexPart.slice(0, regexPart.length - 1) + '\\n';
replacePart = replacePart ? replacePart + '\n' : '\n';
}
if (replacePart !== undefined) {
if (getOption('pcre')) {
replacePart = unescapeRegexReplace(replacePart);
} else {
replacePart = translateRegexReplace(replacePart);
}
vimGlobalState.lastSubstituteReplacePart = replacePart;
}
trailing = tokens[2] ? tokens[2].split(' ') : [];
} else {
// either the argString is empty or its of the form ' hello/world'
// actually splitBySlash returns a list of tokens
// only if the string starts with a '/'
if (argString && argString.length) {
showConfirm(cm, 'Substitutions should be of the form ' + ':s/pattern/replace/');
return;
}
}
// After the 3rd slash, we can have flags followed by a space followed
// by count.
if (trailing) {
flagsPart = trailing[0];
count = parseInt(trailing[1]);
if (flagsPart) {
if (flagsPart.indexOf('c') != -1) {
confirm = true;
flagsPart.replace('c', '');
}
if (flagsPart.indexOf('g') != -1) {
global = true;
flagsPart.replace('g', '');
}
regexPart = regexPart.replace(/\//g, "\\/") + '/' + flagsPart;
}
}
if (regexPart) {
// If regex part is empty, then use the previous query. Otherwise use
// the regex part as the new query.
try {
updateSearchQuery(cm, regexPart, true /** ignoreCase */
, true /** smartCase */);
} catch (e) {
showConfirm(cm, 'Invalid regex: ' + regexPart);
return;
}
}
replacePart = replacePart || vimGlobalState.lastSubstituteReplacePart;
if (replacePart === undefined) {
showConfirm(cm, 'No previous substitute regular expression');
return;
}
var state = getSearchState(cm);
var query = state.getQuery();
var lineStart = params.line !== undefined ? params.line : cm.getCursor().line;
var lineEnd = params.lineEnd || lineStart;
if (lineStart == cm.firstLine() && lineEnd == cm.lastLine()) {
lineEnd = Infinity;
}
if (count) {
lineStart = lineEnd;
lineEnd = lineStart + count - 1;
}
var startPos = clipCursorToContent(cm, Pos(lineStart, 0));
var cursor = cm.getSearchCursor(query, startPos);
doReplace(cm, confirm, global, lineStart, lineEnd, cursor, query, replacePart, params.callback);
},
redo: CodeMirror.commands.redo,
undo: CodeMirror.commands.undo,
write: function (cm) {
if (CodeMirror.commands.save) {
// If a save command is defined, call it.
CodeMirror.commands.save(cm);
} else if (cm.save) {
// Saves to text area if no save command is defined and cm.save() is available.
cm.save();
}
},
nohlsearch: function (cm) {
clearSearchHighlight(cm);
},
yank: function (cm) {
var cur = copyCursor(cm.getCursor());
var line = cur.line;
var lineText = cm.getLine(line);
vimGlobalState.registerController.pushText('0', 'yank', lineText, true, true);
},
delmarks: function (cm, params) {
if (!params.argString || !trim(params.argString)) {
showConfirm(cm, 'Argument required');
return;
}
var state = cm.state.vim;
var stream = new CodeMirror.StringStream(trim(params.argString));
while (!stream.eol()) {
stream.eatSpace();
// Record the streams position at the beginning of the loop for use
// in error messages.
var count = stream.pos;
if (!stream.match(/[a-zA-Z]/, false)) {
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
return;
}
var sym = stream.next();
// Check if this symbol is part of a range
if (stream.match('-', true)) {
// This symbol is part of a range.
// The range must terminate at an alphabetic character.
if (!stream.match(/[a-zA-Z]/, false)) {
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
return;
}
var startMark = sym;
var finishMark = stream.next();
// The range must terminate at an alphabetic character which
// shares the same case as the start of the range.
if (isLowerCase(startMark) && isLowerCase(finishMark) || isUpperCase(startMark) && isUpperCase(finishMark)) {
var start = startMark.charCodeAt(0);
var finish = finishMark.charCodeAt(0);
if (start >= finish) {
showConfirm(cm, 'Invalid argument: ' + params.argString.substring(count));
return;
}
// Because marks are always ASCII values, and we have
// determined that they are the same case, we can use
// their char codes to iterate through the defined range.
for (var j = 0; j <= finish - start; j++) {
var mark = String.fromCharCode(start + j);
delete state.marks[mark];
}
} else {
showConfirm(cm, 'Invalid argument: ' + startMark + '-');
return;
}
} else {
// This symbol is a valid mark, and is not part of a range.
delete state.marks[sym];
}
}
}
};
var exCommandDispatcher = new ExCommandDispatcher();
/**
* @param {CodeMirror} cm CodeMirror instance we are in.
* @param {boolean} confirm Whether to confirm each replace.
* @param {Cursor} lineStart Line to start replacing from.
* @param {Cursor} lineEnd Line to stop replacing at.
* @param {RegExp} query Query for performing matches with.
* @param {string} replaceWith Text to replace matches with. May contain $1,
* $2, etc for replacing captured groups using Javascript replace.
* @param {function()} callback A callback for when the replace is done.
*/
function doReplace(cm, confirm, global, lineStart, lineEnd, searchCursor, query, replaceWith, callback) {
// Set up all the functions.
cm.state.vim.exMode = true;
var done = false;
var lastPos = searchCursor.from();
function replaceAll() {
cm.operation(function () {
while (!done) {
replace();
next();
}
stop();
});
}
function replace() {
var text = cm.getRange(searchCursor.from(), searchCursor.to());
var newText = text.replace(query, replaceWith);
searchCursor.replace(newText);
}
function next() {
// The below only loops to skip over multiple occurrences on the same
// line when 'global' is not true.
while (searchCursor.findNext() && isInRange(searchCursor.from(), lineStart, lineEnd)) {
if (!global && lastPos && searchCursor.from().line == lastPos.line) {
continue;
}
cm.scrollIntoView(searchCursor.from(), 30);
cm.setSelection(searchCursor.from(), searchCursor.to());
lastPos = searchCursor.from();
done = false;
return;
}
done = true;
}
function stop(close) {
if (close) {
close();
}
cm.focus();
if (lastPos) {
cm.setCursor(lastPos);
var vim = cm.state.vim;
vim.exMode = false;
vim.lastHPos = vim.lastHSPos = lastPos.ch;
}
if (callback) {
callback();
}
}
function onPromptKeyDown(e, _value, close) {
// Swallow all keys.
CodeMirror.e_stop(e);
var keyName = CodeMirror.keyName(e);
switch (keyName) {
case 'Y':
replace();next();break;
case 'N':
next();break;
case 'A':
// replaceAll contains a call to close of its own. We don't want it
// to fire too early or multiple times.
var savedCallback = callback;
callback = undefined;
cm.operation(replaceAll);
callback = savedCallback;
break;
case 'L':
replace();
// fall through and exit.
case 'Q':
case 'Esc':
case 'Ctrl-C':
case 'Ctrl-[':
stop(close);
break;
}
if (done) {
stop(close);
}
return true;
}
// Actually do replace.
next();
if (done) {
showConfirm(cm, 'No matches for ' + query.source);
return;
}
if (!confirm) {
replaceAll();
if (callback) {
callback();
}
return;
}
showPrompt(cm, {
prefix: 'replace with <strong>' + replaceWith + '</strong> (y/n/a/q/l)',
onKeyDown: onPromptKeyDown
});
}
CodeMirror.keyMap.vim = {
attach: attachVimMap,
detach: detachVimMap,
call: cmKey
};
function exitInsertMode(cm) {
var vim = cm.state.vim;
var macroModeState = vimGlobalState.macroModeState;
var insertModeChangeRegister = vimGlobalState.registerController.getRegister('.');
var isPlaying = macroModeState.isPlaying;
var lastChange = macroModeState.lastInsertModeChanges;
// In case of visual block, the insertModeChanges are not saved as a
// single word, so we convert them to a single word
// so as to update the ". register as expected in real vim.
var text = [];
if (!isPlaying) {
var selLength = lastChange.inVisualBlock && vim.lastSelection ? vim.lastSelection.visualBlock.height : 1;
var changes = lastChange.changes;
var text = [];
var i = 0;
// In case of multiple selections in blockwise visual,
// the inserted text, for example: 'f<Backspace>oo', is stored as
// 'f', 'f', InsertModeKey 'o', 'o', 'o', 'o'. (if you have a block with 2 lines).
// We push the contents of the changes array as per the following:
// 1. In case of InsertModeKey, just increment by 1.
// 2. In case of a character, jump by selLength (2 in the example).
while (i < changes.length) {
// This loop will convert 'ff<bs>oooo' to 'f<bs>oo'.
text.push(changes[i]);
if (changes[i] instanceof InsertModeKey) {
i++;
} else {
i += selLength;
}
}
lastChange.changes = text;
cm.off('change', onChange);
CodeMirror.off(cm.getInputField(), 'keydown', onKeyEventTargetKeyDown);
}
if (!isPlaying && vim.insertModeRepeat > 1) {
// Perform insert mode repeat for commands like 3,a and 3,o.
repeatLastEdit(cm, vim, vim.insertModeRepeat - 1, true /** repeatForInsert */);
vim.lastEditInputState.repeatOverride = vim.insertModeRepeat;
}
delete vim.insertModeRepeat;
vim.insertMode = false;
cm.setCursor(cm.getCursor().line, cm.getCursor().ch - 1);
cm.setOption('keyMap', 'vim');
cm.setOption('disableInput', true);
cm.toggleOverwrite(false); // exit replace mode if we were in it.
// update the ". register before exiting insert mode
insertModeChangeRegister.setText(lastChange.changes.join(''));
CodeMirror.signal(cm, "vim-mode-change", { mode: "normal" });
if (macroModeState.isRecording) {
logInsertModeChange(macroModeState);
}
}
function _mapCommand(command) {
defaultKeymap.unshift(command);
}
function mapCommand(keys, type, name, args, extra) {
var command = { keys: keys, type: type };
command[type] = name;
command[type + "Args"] = args;
for (var key in extra) command[key] = extra[key];
_mapCommand(command);
}
// The timeout in milliseconds for the two-character ESC keymap should be
// adjusted according to your typing speed to prevent false positives.
defineOption('insertModeEscKeysTimeout', 200, 'number');
CodeMirror.keyMap['vim-insert'] = {
// TODO: override navigation keys so that Esc will cancel automatic
// indentation from o, O, i_<CR>
fallthrough: ['default'],
attach: attachVimMap,
detach: detachVimMap,
call: cmKey
};
CodeMirror.keyMap['vim-replace'] = {
'Backspace': 'goCharLeft',
fallthrough: ['vim-insert'],
attach: attachVimMap,
detach: detachVimMap,
call: cmKey
};
function executeMacroRegister(cm, vim, macroModeState, registerName) {
var register = vimGlobalState.registerController.getRegister(registerName);
if (registerName == ':') {
// Read-only register containing last Ex command.
if (register.keyBuffer[0]) {
exCommandDispatcher.processCommand(cm, register.keyBuffer[0]);
}
macroModeState.isPlaying = false;
return;
}
var keyBuffer = register.keyBuffer;
var imc = 0;
macroModeState.isPlaying = true;
macroModeState.replaySearchQueries = register.searchQueries.slice(0);
for (var i = 0; i < keyBuffer.length; i++) {
var text = keyBuffer[i];
var match, key;
while (text) {
// Pull off one command key, which is either a single character
// or a special sequence wrapped in '<' and '>', e.g. '<Space>'.
match = /<\w+-.+?>|<\w+>|./.exec(text);
key = match[0];
text = text.substring(match.index + key.length);
CodeMirror.Vim.handleKey(cm, key, 'macro');
if (vim.insertMode) {
var changes = register.insertModeChanges[imc++].changes;
vimGlobalState.macroModeState.lastInsertModeChanges.changes = changes;
repeatInsertModeChanges(cm, changes, 1);
exitInsertMode(cm);
}
}
}
macroModeState.isPlaying = false;
}
function logKey(macroModeState, key) {
if (macroModeState.isPlaying) {
return;
}
var registerName = macroModeState.latestRegister;
var register = vimGlobalState.registerController.getRegister(registerName);
if (register) {
register.pushText(key);
}
}
function logInsertModeChange(macroModeState) {
if (macroModeState.isPlaying) {
return;
}
var registerName = macroModeState.latestRegister;
var register = vimGlobalState.registerController.getRegister(registerName);
if (register && register.pushInsertModeChanges) {
register.pushInsertModeChanges(macroModeState.lastInsertModeChanges);
}
}
function logSearchQuery(macroModeState, query) {
if (macroModeState.isPlaying) {
return;
}
var registerName = macroModeState.latestRegister;
var register = vimGlobalState.registerController.getRegister(registerName);
if (register && register.pushSearchQuery) {
register.pushSearchQuery(query);
}
}
/**
* Listens for changes made in insert mode.
* Should only be active in insert mode.
*/
function onChange(cm, changeObj) {
var macroModeState = vimGlobalState.macroModeState;
var lastChange = macroModeState.lastInsertModeChanges;
if (!macroModeState.isPlaying) {
while (changeObj) {
lastChange.expectCursorActivityForChange = true;
if (changeObj.origin == '+input' || changeObj.origin == 'paste' || changeObj.origin === undefined /* only in testing */) {
var text = changeObj.text.join('\n');
if (lastChange.maybeReset) {
lastChange.changes = [];
lastChange.maybeReset = false;
}
if (cm.state.overwrite && !/\n/.test(text)) {
lastChange.changes.push([text]);
} else {
lastChange.changes.push(text);
}
}
// Change objects may be chained with next.
changeObj = changeObj.next;
}
}
}
/**
* Listens for any kind of cursor activity on CodeMirror.
*/
function onCursorActivity(cm) {
var vim = cm.state.vim;
if (vim.insertMode) {
// Tracking cursor activity in insert mode (for macro support).
var macroModeState = vimGlobalState.macroModeState;
if (macroModeState.isPlaying) {
return;
}
var lastChange = macroModeState.lastInsertModeChanges;
if (lastChange.expectCursorActivityForChange) {
lastChange.expectCursorActivityForChange = false;
} else {
// Cursor moved outside the context of an edit. Reset the change.
lastChange.maybeReset = true;
}
} else if (!cm.curOp.isVimOp) {
handleExternalSelection(cm, vim);
}
if (vim.visualMode) {
updateFakeCursor(cm);
}
}
function updateFakeCursor(cm) {
var vim = cm.state.vim;
var from = clipCursorToContent(cm, copyCursor(vim.sel.head));
var to = offsetCursor(from, 0, 1);
if (vim.fakeCursor) {
vim.fakeCursor.clear();
}
vim.fakeCursor = cm.markText(from, to, { className: 'cm-animate-fat-cursor' });
}
function handleExternalSelection(cm, vim) {
var anchor = cm.getCursor('anchor');
var head = cm.getCursor('head');
// Enter or exit visual mode to match mouse selection.
if (vim.visualMode && !cm.somethingSelected()) {
exitVisualMode(cm, false);
} else if (!vim.visualMode && !vim.insertMode && cm.somethingSelected()) {
vim.visualMode = true;
vim.visualLine = false;
CodeMirror.signal(cm, "vim-mode-change", { mode: "visual" });
}
if (vim.visualMode) {
// Bind CodeMirror selection model to vim selection model.
// Mouse selections are considered visual characterwise.
var headOffset = !cursorIsBefore(head, anchor) ? -1 : 0;
var anchorOffset = cursorIsBefore(head, anchor) ? -1 : 0;
head = offsetCursor(head, 0, headOffset);
anchor = offsetCursor(anchor, 0, anchorOffset);
vim.sel = {
anchor: anchor,
head: head
};
updateMark(cm, vim, '<', cursorMin(head, anchor));
updateMark(cm, vim, '>', cursorMax(head, anchor));
} else if (!vim.insertMode) {
// Reset lastHPos if selection was modified by something outside of vim mode e.g. by mouse.
vim.lastHPos = cm.getCursor().ch;
}
}
/** Wrapper for special keys pressed in insert mode */
function InsertModeKey(keyName) {
this.keyName = keyName;
}
/**
* Handles raw key down events from the text area.
* - Should only be active in insert mode.
* - For recording deletes in insert mode.
*/
function onKeyEventTargetKeyDown(e) {
var macroModeState = vimGlobalState.macroModeState;
var lastChange = macroModeState.lastInsertModeChanges;
var keyName = CodeMirror.keyName(e);
if (!keyName) {
return;
}
function onKeyFound() {
if (lastChange.maybeReset) {
lastChange.changes = [];
lastChange.maybeReset = false;
}
lastChange.changes.push(new InsertModeKey(keyName));
return true;
}
if (keyName.indexOf('Delete') != -1 || keyName.indexOf('Backspace') != -1) {
CodeMirror.lookupKey(keyName, 'vim-insert', onKeyFound);
}
}
/**
* Repeats the last edit, which includes exactly 1 command and at most 1
* insert. Operator and motion commands are read from lastEditInputState,
* while action commands are read from lastEditActionCommand.
*
* If repeatForInsert is true, then the function was called by
* exitInsertMode to repeat the insert mode changes the user just made. The
* corresponding enterInsertMode call was made with a count.
*/
function repeatLastEdit(cm, vim, repeat, repeatForInsert) {
var macroModeState = vimGlobalState.macroModeState;
macroModeState.isPlaying = true;
var isAction = !!vim.lastEditActionCommand;
var cachedInputState = vim.inputState;
function repeatCommand() {
if (isAction) {
commandDispatcher.processAction(cm, vim, vim.lastEditActionCommand);
} else {
commandDispatcher.evalInput(cm, vim);
}
}
function repeatInsert(repeat) {
if (macroModeState.lastInsertModeChanges.changes.length > 0) {
// For some reason, repeat cw in desktop VIM does not repeat
// insert mode changes. Will conform to that behavior.
repeat = !vim.lastEditActionCommand ? 1 : repeat;
var changeObject = macroModeState.lastInsertModeChanges;
repeatInsertModeChanges(cm, changeObject.changes, repeat);
}
}
vim.inputState = vim.lastEditInputState;
if (isAction && vim.lastEditActionCommand.interlaceInsertRepeat) {
// o and O repeat have to be interlaced with insert repeats so that the
// insertions appear on separate lines instead of the last line.
for (var i = 0; i < repeat; i++) {
repeatCommand();
repeatInsert(1);
}
} else {
if (!repeatForInsert) {
// Hack to get the cursor to end up at the right place. If I is
// repeated in insert mode repeat, cursor will be 1 insert
// change set left of where it should be.
repeatCommand();
}
repeatInsert(repeat);
}
vim.inputState = cachedInputState;
if (vim.insertMode && !repeatForInsert) {
// Don't exit insert mode twice. If repeatForInsert is set, then we
// were called by an exitInsertMode call lower on the stack.
exitInsertMode(cm);
}
macroModeState.isPlaying = false;
}
function repeatInsertModeChanges(cm, changes, repeat) {
function keyHandler(binding) {
if (typeof binding == 'string') {
CodeMirror.commands[binding](cm);
} else {
binding(cm);
}
return true;
}
var head = cm.getCursor('head');
var inVisualBlock = vimGlobalState.macroModeState.lastInsertModeChanges.inVisualBlock;
if (inVisualBlock) {
// Set up block selection again for repeating the changes.
var vim = cm.state.vim;
var lastSel = vim.lastSelection;
var offset = getOffset(lastSel.anchor, lastSel.head);
selectForInsert(cm, head, offset.line + 1);
repeat = cm.listSelections().length;
cm.setCursor(head);
}
for (var i = 0; i < repeat; i++) {
if (inVisualBlock) {
cm.setCursor(offsetCursor(head, i, 0));
}
for (var j = 0; j < changes.length; j++) {
var change = changes[j];
if (change instanceof InsertModeKey) {
CodeMirror.lookupKey(change.keyName, 'vim-insert', keyHandler);
} else if (typeof change == "string") {
var cur = cm.getCursor();
cm.replaceRange(change, cur, cur);
} else {
var start = cm.getCursor();
var end = offsetCursor(start, 0, change[0].length);
cm.replaceRange(change[0], start, end);
}
}
}
if (inVisualBlock) {
cm.setCursor(offsetCursor(head, 0, 1));
}
}
resetVimGlobalState();
return vimApi;
};
// Initialize Vim and make it available as an API.
CodeMirror.Vim = Vim();
});
/***/ }),
/***/ "zKjx":
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__firebase_auth__ = __webpack_require__("RJVP");
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__firebase_auth___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__firebase_auth__);
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/***/ }),
/***/ "zs1I":
/***/ (function(module, exports, __webpack_require__) {
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function (mod) {
if (true) // CommonJS
mod(__webpack_require__("tQq4"));else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);else // Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
"use strict";
CodeMirror.registerHelper("fold", "brace", function (cm, start) {
var line = start.line,
lineText = cm.getLine(line);
var tokenType;
function findOpening(openCh) {
for (var at = start.ch, pass = 0;;) {
var found = at <= 0 ? -1 : lineText.lastIndexOf(openCh, at - 1);
if (found == -1) {
if (pass == 1) break;
pass = 1;
at = lineText.length;
continue;
}
if (pass == 1 && found < start.ch) break;
tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
if (!/^(comment|string)/.test(tokenType)) return found + 1;
at = found - 1;
}
}
var startToken = "{",
endToken = "}",
startCh = findOpening("{");
if (startCh == null) {
startToken = "[", endToken = "]";
startCh = findOpening("[");
}
if (startCh == null) return;
var count = 1,
lastLine = cm.lastLine(),
end,
endCh;
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i),
pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(startToken, pos),
nextClose = text.indexOf(endToken, pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == tokenType) {
if (pos == nextOpen) ++count;else if (! --count) {
end = i;endCh = pos;break outer;
}
}
++pos;
}
}
if (end == null || line == end && endCh == startCh) return;
return { from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh) };
});
CodeMirror.registerHelper("fold", "import", function (cm, start) {
function hasImport(line) {
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type != "keyword" || start.string != "import") return null;
// Now find closing semicolon, return its position
for (var i = line, e = Math.min(cm.lastLine(), line + 10); i <= e; ++i) {
var text = cm.getLine(i),
semi = text.indexOf(";");
if (semi != -1) return { startCh: start.end, end: CodeMirror.Pos(i, semi) };
}
}
var startLine = start.line,
has = hasImport(startLine),
prev;
if (!has || hasImport(startLine - 1) || (prev = hasImport(startLine - 2)) && prev.end.line == startLine - 1) return null;
for (var end = has.end;;) {
var next = hasImport(end.line + 1);
if (next == null) break;
end = next.end;
}
return { from: cm.clipPos(CodeMirror.Pos(startLine, has.startCh + 1)), to: end };
});
CodeMirror.registerHelper("fold", "include", function (cm, start) {
function hasInclude(line) {
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8;
}
var startLine = start.line,
has = hasInclude(startLine);
if (has == null || hasInclude(startLine - 1) != null) return null;
for (var end = startLine;;) {
var next = hasInclude(end + 1);
if (next == null) break;
++end;
}
return { from: CodeMirror.Pos(startLine, has + 1),
to: cm.clipPos(CodeMirror.Pos(end)) };
});
});
/***/ })
/******/ });