UNPKG

@orfeas126/box-ui-elements

Version:
1,115 lines (1,079 loc) 4.36 MB
/*! * Box UI Element * * Copyright 2019 Box, Inc. All rights reserved. * * This product includes software developed by Box, Inc. ("Box") * (http://www.box.com) * * ALL BOX SOFTWARE IS PROVIDED "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 BOX 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. * * See the Box license for the specific language governing permissions * and limitations under the license. */ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./node_modules/@formatjs/ecma402-abstract/lib/utils.js": /*!**************************************************************!*\ !*** ./node_modules/@formatjs/ecma402-abstract/lib/utils.js ***! \**************************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ UNICODE_EXTENSION_SEQUENCE_REGEX: () => (/* binding */ UNICODE_EXTENSION_SEQUENCE_REGEX), /* harmony export */ createDataProperty: () => (/* binding */ createDataProperty), /* harmony export */ defineProperty: () => (/* binding */ defineProperty), /* harmony export */ getInternalSlot: () => (/* binding */ getInternalSlot), /* harmony export */ getMagnitude: () => (/* binding */ getMagnitude), /* harmony export */ getMultiInternalSlots: () => (/* binding */ getMultiInternalSlots), /* harmony export */ invariant: () => (/* binding */ invariant), /* harmony export */ isLiteralPart: () => (/* binding */ isLiteralPart), /* harmony export */ repeat: () => (/* binding */ repeat), /* harmony export */ setInternalSlot: () => (/* binding */ setInternalSlot), /* harmony export */ setMultiInternalSlots: () => (/* binding */ setMultiInternalSlots) /* harmony export */ }); /** * Cannot do Math.log(x) / Math.log(10) bc if IEEE floating point issue * @param x number */ function getMagnitude(x) { // Cannot count string length via Number.toString because it may use scientific notation // for very small or very large numbers. return Math.floor(Math.log(x) * Math.LOG10E); } function repeat(s, times) { if (typeof s.repeat === 'function') { return s.repeat(times); } var arr = new Array(times); for (var i = 0; i < arr.length; i++) { arr[i] = s; } return arr.join(''); } function setInternalSlot(map, pl, field, value) { if (!map.get(pl)) { map.set(pl, Object.create(null)); } var slots = map.get(pl); slots[field] = value; } function setMultiInternalSlots(map, pl, props) { for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) { var k = _a[_i]; setInternalSlot(map, pl, k, props[k]); } } function getInternalSlot(map, pl, field) { return getMultiInternalSlots(map, pl, field)[field]; } function getMultiInternalSlots(map, pl) { var fields = []; for (var _i = 2; _i < arguments.length; _i++) { fields[_i - 2] = arguments[_i]; } var slots = map.get(pl); if (!slots) { throw new TypeError("".concat(pl, " InternalSlot has not been initialized")); } return fields.reduce(function (all, f) { all[f] = slots[f]; return all; }, Object.create(null)); } function isLiteralPart(patternPart) { return patternPart.type === 'literal'; } /* 17 ECMAScript Standard Built-in Objects: Every built-in Function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, the name property of a built-in Function object, if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. */ function defineProperty(target, name, _a) { var value = _a.value; Object.defineProperty(target, name, { configurable: true, enumerable: false, writable: true, value: value, }); } /** * 7.3.5 CreateDataProperty * @param target * @param name * @param value */ function createDataProperty(target, name, value) { Object.defineProperty(target, name, { configurable: true, enumerable: true, writable: true, value: value, }); } var UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi; function invariant(condition, message, Err) { if (Err === void 0) { Err = Error; } if (!condition) { throw new Err(message); } } /***/ }), /***/ "./node_modules/@formatjs/fast-memoize/lib/index.js": /*!**********************************************************!*\ !*** ./node_modules/@formatjs/fast-memoize/lib/index.js ***! \**********************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ memoize: () => (/* binding */ memoize), /* harmony export */ strategies: () => (/* binding */ strategies) /* harmony export */ }); // // Main // function memoize(fn, options) { var cache = options && options.cache ? options.cache : cacheDefault; var serializer = options && options.serializer ? options.serializer : serializerDefault; var strategy = options && options.strategy ? options.strategy : strategyDefault; return strategy(fn, { cache: cache, serializer: serializer, }); } // // Strategy // function isPrimitive(value) { return (value == null || typeof value === 'number' || typeof value === 'boolean'); // || typeof value === "string" 'unsafe' primitive for our needs } function monadic(fn, cache, serializer, arg) { var cacheKey = isPrimitive(arg) ? arg : serializer(arg); var computedValue = cache.get(cacheKey); if (typeof computedValue === 'undefined') { computedValue = fn.call(this, arg); cache.set(cacheKey, computedValue); } return computedValue; } function variadic(fn, cache, serializer) { var args = Array.prototype.slice.call(arguments, 3); var cacheKey = serializer(args); var computedValue = cache.get(cacheKey); if (typeof computedValue === 'undefined') { computedValue = fn.apply(this, args); cache.set(cacheKey, computedValue); } return computedValue; } function assemble(fn, context, strategy, cache, serialize) { return strategy.bind(context, fn, cache, serialize); } function strategyDefault(fn, options) { var strategy = fn.length === 1 ? monadic : variadic; return assemble(fn, this, strategy, options.cache.create(), options.serializer); } function strategyVariadic(fn, options) { return assemble(fn, this, variadic, options.cache.create(), options.serializer); } function strategyMonadic(fn, options) { return assemble(fn, this, monadic, options.cache.create(), options.serializer); } // // Serializer // var serializerDefault = function () { return JSON.stringify(arguments); }; // // Cache // function ObjectWithoutPrototypeCache() { this.cache = Object.create(null); } ObjectWithoutPrototypeCache.prototype.get = function (key) { return this.cache[key]; }; ObjectWithoutPrototypeCache.prototype.set = function (key, value) { this.cache[key] = value; }; var cacheDefault = { create: function create() { // @ts-ignore return new ObjectWithoutPrototypeCache(); }, }; var strategies = { variadic: strategyVariadic, monadic: strategyMonadic, }; /***/ }), /***/ "./node_modules/@formatjs/icu-messageformat-parser/lib/date-time-pattern-generator.js": /*!********************************************************************************************!*\ !*** ./node_modules/@formatjs/icu-messageformat-parser/lib/date-time-pattern-generator.js ***! \********************************************************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ getBestPattern: () => (/* binding */ getBestPattern) /* harmony export */ }); /* harmony import */ var _time_data_generated__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./time-data.generated */ "./node_modules/@formatjs/icu-messageformat-parser/lib/time-data.generated.js"); /** * Returns the best matching date time pattern if a date time skeleton * pattern is provided with a locale. Follows the Unicode specification: * https://www.unicode.org/reports/tr35/tr35-dates.html#table-mapping-requested-time-skeletons-to-patterns * @param skeleton date time skeleton pattern that possibly includes j, J or C * @param locale */ function getBestPattern(skeleton, locale) { var skeletonCopy = ''; for (var patternPos = 0; patternPos < skeleton.length; patternPos++) { var patternChar = skeleton.charAt(patternPos); if (patternChar === 'j') { var extraLength = 0; while (patternPos + 1 < skeleton.length && skeleton.charAt(patternPos + 1) === patternChar) { extraLength++; patternPos++; } var hourLen = 1 + (extraLength & 1); var dayPeriodLen = extraLength < 2 ? 1 : 3 + (extraLength >> 1); var dayPeriodChar = 'a'; var hourChar = getDefaultHourSymbolFromLocale(locale); if (hourChar == 'H' || hourChar == 'k') { dayPeriodLen = 0; } while (dayPeriodLen-- > 0) { skeletonCopy += dayPeriodChar; } while (hourLen-- > 0) { skeletonCopy = hourChar + skeletonCopy; } } else if (patternChar === 'J') { skeletonCopy += 'H'; } else { skeletonCopy += patternChar; } } return skeletonCopy; } /** * Maps the [hour cycle type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle) * of the given `locale` to the corresponding time pattern. * @param locale */ function getDefaultHourSymbolFromLocale(locale) { var hourCycle = locale.hourCycle; if (hourCycle === undefined && // @ts-ignore hourCycle(s) is not identified yet locale.hourCycles && // @ts-ignore locale.hourCycles.length) { // @ts-ignore hourCycle = locale.hourCycles[0]; } if (hourCycle) { switch (hourCycle) { case 'h24': return 'k'; case 'h23': return 'H'; case 'h12': return 'h'; case 'h11': return 'K'; default: throw new Error('Invalid hourCycle'); } } // TODO: Once hourCycle is fully supported remove the following with data generation var languageTag = locale.language; var regionTag; if (languageTag !== 'root') { regionTag = locale.maximize().region; } var hourCycles = _time_data_generated__WEBPACK_IMPORTED_MODULE_0__.timeData[regionTag || ''] || _time_data_generated__WEBPACK_IMPORTED_MODULE_0__.timeData[languageTag || ''] || _time_data_generated__WEBPACK_IMPORTED_MODULE_0__.timeData["".concat(languageTag, "-001")] || _time_data_generated__WEBPACK_IMPORTED_MODULE_0__.timeData['001']; return hourCycles[0]; } /***/ }), /***/ "./node_modules/@formatjs/icu-messageformat-parser/lib/error.js": /*!**********************************************************************!*\ !*** ./node_modules/@formatjs/icu-messageformat-parser/lib/error.js ***! \**********************************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ ErrorKind: () => (/* binding */ ErrorKind) /* harmony export */ }); var ErrorKind; (function (ErrorKind) { /** Argument is unclosed (e.g. `{0`) */ ErrorKind[ErrorKind["EXPECT_ARGUMENT_CLOSING_BRACE"] = 1] = "EXPECT_ARGUMENT_CLOSING_BRACE"; /** Argument is empty (e.g. `{}`). */ ErrorKind[ErrorKind["EMPTY_ARGUMENT"] = 2] = "EMPTY_ARGUMENT"; /** Argument is malformed (e.g. `{foo!}``) */ ErrorKind[ErrorKind["MALFORMED_ARGUMENT"] = 3] = "MALFORMED_ARGUMENT"; /** Expect an argument type (e.g. `{foo,}`) */ ErrorKind[ErrorKind["EXPECT_ARGUMENT_TYPE"] = 4] = "EXPECT_ARGUMENT_TYPE"; /** Unsupported argument type (e.g. `{foo,foo}`) */ ErrorKind[ErrorKind["INVALID_ARGUMENT_TYPE"] = 5] = "INVALID_ARGUMENT_TYPE"; /** Expect an argument style (e.g. `{foo, number, }`) */ ErrorKind[ErrorKind["EXPECT_ARGUMENT_STYLE"] = 6] = "EXPECT_ARGUMENT_STYLE"; /** The number skeleton is invalid. */ ErrorKind[ErrorKind["INVALID_NUMBER_SKELETON"] = 7] = "INVALID_NUMBER_SKELETON"; /** The date time skeleton is invalid. */ ErrorKind[ErrorKind["INVALID_DATE_TIME_SKELETON"] = 8] = "INVALID_DATE_TIME_SKELETON"; /** Exepct a number skeleton following the `::` (e.g. `{foo, number, ::}`) */ ErrorKind[ErrorKind["EXPECT_NUMBER_SKELETON"] = 9] = "EXPECT_NUMBER_SKELETON"; /** Exepct a date time skeleton following the `::` (e.g. `{foo, date, ::}`) */ ErrorKind[ErrorKind["EXPECT_DATE_TIME_SKELETON"] = 10] = "EXPECT_DATE_TIME_SKELETON"; /** Unmatched apostrophes in the argument style (e.g. `{foo, number, 'test`) */ ErrorKind[ErrorKind["UNCLOSED_QUOTE_IN_ARGUMENT_STYLE"] = 11] = "UNCLOSED_QUOTE_IN_ARGUMENT_STYLE"; /** Missing select argument options (e.g. `{foo, select}`) */ ErrorKind[ErrorKind["EXPECT_SELECT_ARGUMENT_OPTIONS"] = 12] = "EXPECT_SELECT_ARGUMENT_OPTIONS"; /** Expecting an offset value in `plural` or `selectordinal` argument (e.g `{foo, plural, offset}`) */ ErrorKind[ErrorKind["EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE"] = 13] = "EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE"; /** Offset value in `plural` or `selectordinal` is invalid (e.g. `{foo, plural, offset: x}`) */ ErrorKind[ErrorKind["INVALID_PLURAL_ARGUMENT_OFFSET_VALUE"] = 14] = "INVALID_PLURAL_ARGUMENT_OFFSET_VALUE"; /** Expecting a selector in `select` argument (e.g `{foo, select}`) */ ErrorKind[ErrorKind["EXPECT_SELECT_ARGUMENT_SELECTOR"] = 15] = "EXPECT_SELECT_ARGUMENT_SELECTOR"; /** Expecting a selector in `plural` or `selectordinal` argument (e.g `{foo, plural}`) */ ErrorKind[ErrorKind["EXPECT_PLURAL_ARGUMENT_SELECTOR"] = 16] = "EXPECT_PLURAL_ARGUMENT_SELECTOR"; /** Expecting a message fragment after the `select` selector (e.g. `{foo, select, apple}`) */ ErrorKind[ErrorKind["EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT"] = 17] = "EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT"; /** * Expecting a message fragment after the `plural` or `selectordinal` selector * (e.g. `{foo, plural, one}`) */ ErrorKind[ErrorKind["EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT"] = 18] = "EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT"; /** Selector in `plural` or `selectordinal` is malformed (e.g. `{foo, plural, =x {#}}`) */ ErrorKind[ErrorKind["INVALID_PLURAL_ARGUMENT_SELECTOR"] = 19] = "INVALID_PLURAL_ARGUMENT_SELECTOR"; /** * Duplicate selectors in `plural` or `selectordinal` argument. * (e.g. {foo, plural, one {#} one {#}}) */ ErrorKind[ErrorKind["DUPLICATE_PLURAL_ARGUMENT_SELECTOR"] = 20] = "DUPLICATE_PLURAL_ARGUMENT_SELECTOR"; /** Duplicate selectors in `select` argument. * (e.g. {foo, select, apple {apple} apple {apple}}) */ ErrorKind[ErrorKind["DUPLICATE_SELECT_ARGUMENT_SELECTOR"] = 21] = "DUPLICATE_SELECT_ARGUMENT_SELECTOR"; /** Plural or select argument option must have `other` clause. */ ErrorKind[ErrorKind["MISSING_OTHER_CLAUSE"] = 22] = "MISSING_OTHER_CLAUSE"; /** The tag is malformed. (e.g. `<bold!>foo</bold!>) */ ErrorKind[ErrorKind["INVALID_TAG"] = 23] = "INVALID_TAG"; /** The tag name is invalid. (e.g. `<123>foo</123>`) */ ErrorKind[ErrorKind["INVALID_TAG_NAME"] = 25] = "INVALID_TAG_NAME"; /** The closing tag does not match the opening tag. (e.g. `<bold>foo</italic>`) */ ErrorKind[ErrorKind["UNMATCHED_CLOSING_TAG"] = 26] = "UNMATCHED_CLOSING_TAG"; /** The opening tag has unmatched closing tag. (e.g. `<bold>foo`) */ ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG"; })(ErrorKind || (ErrorKind = {})); /***/ }), /***/ "./node_modules/@formatjs/icu-messageformat-parser/lib/index.js": /*!**********************************************************************!*\ !*** ./node_modules/@formatjs/icu-messageformat-parser/lib/index.js ***! \**********************************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ SKELETON_TYPE: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SKELETON_TYPE), /* harmony export */ TYPE: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.TYPE), /* harmony export */ _Parser: () => (/* binding */ _Parser), /* harmony export */ createLiteralElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.createLiteralElement), /* harmony export */ createNumberElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.createNumberElement), /* harmony export */ isArgumentElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isArgumentElement), /* harmony export */ isDateElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isDateElement), /* harmony export */ isDateTimeSkeleton: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isDateTimeSkeleton), /* harmony export */ isLiteralElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isLiteralElement), /* harmony export */ isNumberElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isNumberElement), /* harmony export */ isNumberSkeleton: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isNumberSkeleton), /* harmony export */ isPluralElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isPluralElement), /* harmony export */ isPoundElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isPoundElement), /* harmony export */ isSelectElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isSelectElement), /* harmony export */ isTagElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isTagElement), /* harmony export */ isTimeElement: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.isTimeElement), /* harmony export */ parse: () => (/* binding */ parse) /* harmony export */ }); /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs"); /* harmony import */ var _error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./error */ "./node_modules/@formatjs/icu-messageformat-parser/lib/error.js"); /* harmony import */ var _parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./parser */ "./node_modules/@formatjs/icu-messageformat-parser/lib/parser.js"); /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./types */ "./node_modules/@formatjs/icu-messageformat-parser/lib/types.js"); function pruneLocation(els) { els.forEach(function (el) { delete el.location; if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.isSelectElement)(el) || (0,_types__WEBPACK_IMPORTED_MODULE_2__.isPluralElement)(el)) { for (var k in el.options) { delete el.options[k].location; pruneLocation(el.options[k].value); } } else if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.isNumberElement)(el) && (0,_types__WEBPACK_IMPORTED_MODULE_2__.isNumberSkeleton)(el.style)) { delete el.style.location; } else if (((0,_types__WEBPACK_IMPORTED_MODULE_2__.isDateElement)(el) || (0,_types__WEBPACK_IMPORTED_MODULE_2__.isTimeElement)(el)) && (0,_types__WEBPACK_IMPORTED_MODULE_2__.isDateTimeSkeleton)(el.style)) { delete el.style.location; } else if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.isTagElement)(el)) { pruneLocation(el.children); } }); } function parse(message, opts) { if (opts === void 0) { opts = {}; } opts = (0,tslib__WEBPACK_IMPORTED_MODULE_3__.__assign)({ shouldParseSkeletons: true, requiresOtherClause: true }, opts); var result = new _parser__WEBPACK_IMPORTED_MODULE_1__.Parser(message, opts).parse(); if (result.err) { var error = SyntaxError(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind[result.err.kind]); // @ts-expect-error Assign to error object error.location = result.err.location; // @ts-expect-error Assign to error object error.originalMessage = result.err.message; throw error; } if (!(opts === null || opts === void 0 ? void 0 : opts.captureLocation)) { pruneLocation(result.val); } return result.val; } // only for testing var _Parser = _parser__WEBPACK_IMPORTED_MODULE_1__.Parser; /***/ }), /***/ "./node_modules/@formatjs/icu-messageformat-parser/lib/parser.js": /*!***********************************************************************!*\ !*** ./node_modules/@formatjs/icu-messageformat-parser/lib/parser.js ***! \***********************************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Parser: () => (/* binding */ Parser) /* harmony export */ }); /* harmony import */ var tslib__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs"); /* harmony import */ var _error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./error */ "./node_modules/@formatjs/icu-messageformat-parser/lib/error.js"); /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./types */ "./node_modules/@formatjs/icu-messageformat-parser/lib/types.js"); /* harmony import */ var _regex_generated__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./regex.generated */ "./node_modules/@formatjs/icu-messageformat-parser/lib/regex.generated.js"); /* harmony import */ var _formatjs_icu_skeleton_parser__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @formatjs/icu-skeleton-parser */ "./node_modules/@formatjs/icu-skeleton-parser/lib/index.js"); /* harmony import */ var _date_time_pattern_generator__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./date-time-pattern-generator */ "./node_modules/@formatjs/icu-messageformat-parser/lib/date-time-pattern-generator.js"); var _a; var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(_regex_generated__WEBPACK_IMPORTED_MODULE_2__.SPACE_SEPARATOR_REGEX.source, "*")); var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(_regex_generated__WEBPACK_IMPORTED_MODULE_2__.SPACE_SEPARATOR_REGEX.source, "*$")); function createLocation(start, end) { return { start: start, end: end }; } // #region Ponyfills // Consolidate these variables up top for easier toggling during debugging var hasNativeStartsWith = !!String.prototype.startsWith && '_a'.startsWith('a', 1); var hasNativeFromCodePoint = !!String.fromCodePoint; var hasNativeFromEntries = !!Object.fromEntries; var hasNativeCodePointAt = !!String.prototype.codePointAt; var hasTrimStart = !!String.prototype.trimStart; var hasTrimEnd = !!String.prototype.trimEnd; var hasNativeIsSafeInteger = !!Number.isSafeInteger; var isSafeInteger = hasNativeIsSafeInteger ? Number.isSafeInteger : function (n) { return (typeof n === 'number' && isFinite(n) && Math.floor(n) === n && Math.abs(n) <= 0x1fffffffffffff); }; // IE11 does not support y and u. var REGEX_SUPPORTS_U_AND_Y = true; try { var re = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu'); /** * legacy Edge or Xbox One browser * Unicode flag support: supported * Pattern_Syntax support: not supported * See https://github.com/formatjs/formatjs/issues/2822 */ REGEX_SUPPORTS_U_AND_Y = ((_a = re.exec('a')) === null || _a === void 0 ? void 0 : _a[0]) === 'a'; } catch (_) { REGEX_SUPPORTS_U_AND_Y = false; } var startsWith = hasNativeStartsWith ? // Native function startsWith(s, search, position) { return s.startsWith(search, position); } : // For IE11 function startsWith(s, search, position) { return s.slice(position, position + search.length) === search; }; var fromCodePoint = hasNativeFromCodePoint ? String.fromCodePoint : // IE11 function fromCodePoint() { var codePoints = []; for (var _i = 0; _i < arguments.length; _i++) { codePoints[_i] = arguments[_i]; } var elements = ''; var length = codePoints.length; var i = 0; var code; while (length > i) { code = codePoints[i++]; if (code > 0x10ffff) throw RangeError(code + ' is not a valid code point'); elements += code < 0x10000 ? String.fromCharCode(code) : String.fromCharCode(((code -= 0x10000) >> 10) + 0xd800, (code % 0x400) + 0xdc00); } return elements; }; var fromEntries = // native hasNativeFromEntries ? Object.fromEntries : // Ponyfill function fromEntries(entries) { var obj = {}; for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) { var _a = entries_1[_i], k = _a[0], v = _a[1]; obj[k] = v; } return obj; }; var codePointAt = hasNativeCodePointAt ? // Native function codePointAt(s, index) { return s.codePointAt(index); } : // IE 11 function codePointAt(s, index) { var size = s.length; if (index < 0 || index >= size) { return undefined; } var first = s.charCodeAt(index); var second; return first < 0xd800 || first > 0xdbff || index + 1 === size || (second = s.charCodeAt(index + 1)) < 0xdc00 || second > 0xdfff ? first : ((first - 0xd800) << 10) + (second - 0xdc00) + 0x10000; }; var trimStart = hasTrimStart ? // Native function trimStart(s) { return s.trimStart(); } : // Ponyfill function trimStart(s) { return s.replace(SPACE_SEPARATOR_START_REGEX, ''); }; var trimEnd = hasTrimEnd ? // Native function trimEnd(s) { return s.trimEnd(); } : // Ponyfill function trimEnd(s) { return s.replace(SPACE_SEPARATOR_END_REGEX, ''); }; // Prevent minifier to translate new RegExp to literal form that might cause syntax error on IE11. function RE(s, flag) { return new RegExp(s, flag); } // #endregion var matchIdentifierAtIndex; if (REGEX_SUPPORTS_U_AND_Y) { // Native var IDENTIFIER_PREFIX_RE_1 = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu'); matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) { var _a; IDENTIFIER_PREFIX_RE_1.lastIndex = index; var match = IDENTIFIER_PREFIX_RE_1.exec(s); return (_a = match[1]) !== null && _a !== void 0 ? _a : ''; }; } else { // IE11 matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) { var match = []; while (true) { var c = codePointAt(s, index); if (c === undefined || _isWhiteSpace(c) || _isPatternSyntax(c)) { break; } match.push(c); index += c >= 0x10000 ? 2 : 1; } return fromCodePoint.apply(void 0, match); }; } var Parser = /** @class */ (function () { function Parser(message, options) { if (options === void 0) { options = {}; } this.message = message; this.position = { offset: 0, line: 1, column: 1 }; this.ignoreTag = !!options.ignoreTag; this.locale = options.locale; this.requiresOtherClause = !!options.requiresOtherClause; this.shouldParseSkeletons = !!options.shouldParseSkeletons; } Parser.prototype.parse = function () { if (this.offset() !== 0) { throw Error('parser can only be used once'); } return this.parseMessage(0, '', false); }; Parser.prototype.parseMessage = function (nestingLevel, parentArgType, expectingCloseTag) { var elements = []; while (!this.isEOF()) { var char = this.char(); if (char === 123 /* `{` */) { var result = this.parseArgument(nestingLevel, expectingCloseTag); if (result.err) { return result; } elements.push(result.val); } else if (char === 125 /* `}` */ && nestingLevel > 0) { break; } else if (char === 35 /* `#` */ && (parentArgType === 'plural' || parentArgType === 'selectordinal')) { var position = this.clonePosition(); this.bump(); elements.push({ type: _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.pound, location: createLocation(position, this.clonePosition()), }); } else if (char === 60 /* `<` */ && !this.ignoreTag && this.peek() === 47 // char code for '/' ) { if (expectingCloseTag) { break; } else { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition())); } } else if (char === 60 /* `<` */ && !this.ignoreTag && _isAlpha(this.peek() || 0)) { var result = this.parseTag(nestingLevel, parentArgType); if (result.err) { return result; } elements.push(result.val); } else { var result = this.parseLiteral(nestingLevel, parentArgType); if (result.err) { return result; } elements.push(result.val); } } return { val: elements, err: null }; }; /** * A tag name must start with an ASCII lower/upper case letter. The grammar is based on the * [custom element name][] except that a dash is NOT always mandatory and uppercase letters * are accepted: * * ``` * tag ::= "<" tagName (whitespace)* "/>" | "<" tagName (whitespace)* ">" message "</" tagName (whitespace)* ">" * tagName ::= [a-z] (PENChar)* * PENChar ::= * "-" | "." | [0-9] | "_" | [a-z] | [A-Z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | * [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | * [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] * ``` * * [custom element name]: https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name * NOTE: We're a bit more lax here since HTML technically does not allow uppercase HTML element but we do * since other tag-based engines like React allow it */ Parser.prototype.parseTag = function (nestingLevel, parentArgType) { var startPosition = this.clonePosition(); this.bump(); // `<` var tagName = this.parseTagName(); this.bumpSpace(); if (this.bumpIf('/>')) { // Self closing tag return { val: { type: _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.literal, value: "<".concat(tagName, "/>"), location: createLocation(startPosition, this.clonePosition()), }, err: null, }; } else if (this.bumpIf('>')) { var childrenResult = this.parseMessage(nestingLevel + 1, parentArgType, true); if (childrenResult.err) { return childrenResult; } var children = childrenResult.val; // Expecting a close tag var endTagStartPosition = this.clonePosition(); if (this.bumpIf('</')) { if (this.isEOF() || !_isAlpha(this.char())) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); } var closingTagNameStartPosition = this.clonePosition(); var closingTagName = this.parseTagName(); if (tagName !== closingTagName) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition())); } this.bumpSpace(); if (!this.bumpIf('>')) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); } return { val: { type: _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.tag, value: tagName, children: children, location: createLocation(startPosition, this.clonePosition()), }, err: null, }; } else { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition())); } } else { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition())); } }; /** * This method assumes that the caller has peeked ahead for the first tag character. */ Parser.prototype.parseTagName = function () { var startOffset = this.offset(); this.bump(); // the first tag name character while (!this.isEOF() && _isPotentialElementNameChar(this.char())) { this.bump(); } return this.message.slice(startOffset, this.offset()); }; Parser.prototype.parseLiteral = function (nestingLevel, parentArgType) { var start = this.clonePosition(); var value = ''; while (true) { var parseQuoteResult = this.tryParseQuote(parentArgType); if (parseQuoteResult) { value += parseQuoteResult; continue; } var parseUnquotedResult = this.tryParseUnquoted(nestingLevel, parentArgType); if (parseUnquotedResult) { value += parseUnquotedResult; continue; } var parseLeftAngleResult = this.tryParseLeftAngleBracket(); if (parseLeftAngleResult) { value += parseLeftAngleResult; continue; } break; } var location = createLocation(start, this.clonePosition()); return { val: { type: _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.literal, value: value, location: location }, err: null, }; }; Parser.prototype.tryParseLeftAngleBracket = function () { if (!this.isEOF() && this.char() === 60 /* `<` */ && (this.ignoreTag || // If at the opening tag or closing tag position, bail. !_isAlphaOrSlash(this.peek() || 0))) { this.bump(); // `<` return '<'; } return null; }; /** * Starting with ICU 4.8, an ASCII apostrophe only starts quoted text if it immediately precedes * a character that requires quoting (that is, "only where needed"), and works the same in * nested messages as on the top level of the pattern. The new behavior is otherwise compatible. */ Parser.prototype.tryParseQuote = function (parentArgType) { if (this.isEOF() || this.char() !== 39 /* `'` */) { return null; } // Parse escaped char following the apostrophe, or early return if there is no escaped char. // Check if is valid escaped character switch (this.peek()) { case 39 /* `'` */: // double quote, should return as a single quote. this.bump(); this.bump(); return "'"; // '{', '<', '>', '}' case 123: case 60: case 62: case 125: break; case 35: // '#' if (parentArgType === 'plural' || parentArgType === 'selectordinal') { break; } return null; default: return null; } this.bump(); // apostrophe var codePoints = [this.char()]; // escaped char this.bump(); // read chars until the optional closing apostrophe is found while (!this.isEOF()) { var ch = this.char(); if (ch === 39 /* `'` */) { if (this.peek() === 39 /* `'` */) { codePoints.push(39); // Bump one more time because we need to skip 2 characters. this.bump(); } else { // Optional closing apostrophe. this.bump(); break; } } else { codePoints.push(ch); } this.bump(); } return fromCodePoint.apply(void 0, codePoints); }; Parser.prototype.tryParseUnquoted = function (nestingLevel, parentArgType) { if (this.isEOF()) { return null; } var ch = this.char(); if (ch === 60 /* `<` */ || ch === 123 /* `{` */ || (ch === 35 /* `#` */ && (parentArgType === 'plural' || parentArgType === 'selectordinal')) || (ch === 125 /* `}` */ && nestingLevel > 0)) { return null; } else { this.bump(); return fromCodePoint(ch); } }; Parser.prototype.parseArgument = function (nestingLevel, expectingCloseTag) { var openingBracePosition = this.clonePosition(); this.bump(); // `{` this.bumpSpace(); if (this.isEOF()) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); } if (this.char() === 125 /* `}` */) { this.bump(); return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); } // argument name var value = this.parseIdentifierIfPossible().value; if (!value) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); } this.bumpSpace(); if (this.isEOF()) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); } switch (this.char()) { // Simple argument: `{name}` case 125 /* `}` */: { this.bump(); // `}` return { val: { type: _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.argument, // value does not include the opening and closing braces. value: value, location: createLocation(openingBracePosition, this.clonePosition()), }, err: null, }; } // Argument with options: `{name, format, ...}` case 44 /* `,` */: { this.bump(); // `,` this.bumpSpace(); if (this.isEOF()) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); } return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition); } default: return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); } }; /** * Advance the parser until the end of the identifier, if it is currently on * an identifier character. Return an empty string otherwise. */ Parser.prototype.parseIdentifierIfPossible = function () { var startingPosition = this.clonePosition(); var startOffset = this.offset(); var value = matchIdentifierAtIndex(this.message, startOffset); var endOffset = startOffset + value.length; this.bumpTo(endOffset); var endPosition = this.clonePosition(); var location = createLocation(startingPosition, endPosition); return { value: value, location: location }; }; Parser.prototype.parseArgumentOptions = function (nestingLevel, expectingCloseTag, value, openingBracePosition) { var _a; // Parse this range: // {name, type, style} // ^---^ var typeStartPosition = this.clonePosition(); var argType = this.parseIdentifierIfPossible().value; var typeEndPosition = this.clonePosition(); switch (argType) { case '': // Expecting a style string number, date, time, plural, selectordinal, or select. return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); case 'number': case 'date': case 'time': { // Parse this range: // {name, number, style} // ^-------^ this.bumpSpace(); var styleAndLocation = null; if (this.bumpIf(',')) { this.bumpSpace(); var styleStartPosition = this.clonePosition(); var result = this.parseSimpleArgStyleIfPossible(); if (result.err) { return result; } var style = trimEnd(result.val); if (style.length === 0) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition())); } var styleLocation = createLocation(styleStartPosition, this.clonePosition()); styleAndLocation = { style: style, styleLocation: styleLocation }; } var argCloseResult = this.tryParseArgumentClose(openingBracePosition); if (argCloseResult.err) { return argCloseResult; } var location_1 = createLocation(openingBracePosition, this.clonePosition()); // Extract style or skeleton if (styleAndLocation && startsWith(styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style, '::', 0)) { // Skeleton starts with `::`. var skeleton = trimStart(styleAndLocation.style.slice(2)); if (argType === 'number') { var result = this.parseNumberSkeletonFromString(skeleton, styleAndLocation.styleLocation); if (result.err) { return result; } return { val: { type: _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.number, value: value, location: location_1, style: result.val }, err: null, }; } else { if (skeleton.length === 0) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1); } var dateTimePattern = skeleton; // Get "best match" pattern only if locale is passed, if not, let it // pass as-is where `parseDateTimeSkeleton()` will throw an error // for unsupported patterns. if (this.locale) { dateTimePattern = (0,_date_time_pattern_generator__WEBPACK_IMPORTED_MODULE_4__.getBestPattern)(skeleton, this.locale); } var style = { type: _types__WEBPACK_IMPORTED_MODULE_1__.SKELETON_TYPE.dateTime, pattern: dateTimePattern, location: styleAndLocation.styleLocation, parsedOptions: this.shouldParseSkeletons ? (0,_formatjs_icu_skeleton_parser__WEBPACK_IMPORTED_MODULE_3__.parseDateTimeSkeleton)(dateTimePattern) : {}, }; var type = argType === 'date' ? _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.date : _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.time; return { val: { type: type, value: value, location: location_1, style: style }, err: null, }; } } // Regular style or no style. return { val: { type: argType === 'number' ? _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.number : argType === 'date' ? _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.date : _types__WEBPACK_IMPORTED_MODULE_1__.TYPE.time, value: value, location: location_1, style: (_a = styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style) !== null && _a !== void 0 ? _a : null, }, err: null, }; } case 'plural': case 'selectordinal': case 'select': { // Parse this range: // {name, plural, options} // ^---------^ var typeEndPosition_1 = this.clonePosition(); this.bumpSpace(); if (!this.bumpIf(',')) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, (0,tslib__WEBPACK_IMPORTED_MODULE_5__.__assign)({}, typeEndPosition_1))); } this.bumpSpace(); // Parse offset: // {name, plural, offset:1, options} // ^-----^ // // or the first option: // // {name, plural, one {...} other {...}} // ^--^ var identifierAndLocation = this.parseIdentifierIfPossible(); var pluralOffset = 0; if (argType !== 'select' && identifierAndLocation.value === 'offset') { if (!this.bumpIf(':')) { return this.error(_error__WEBPACK_IMPORTED_MODULE_0__.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition())); }