(self["webpackChunkbrowser_extension"] = self["webpackChunkbrowser_extension"] || []).push([["761"], {
20580(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.d(__webpack_exports__, {
Tl: () => (translate)
});
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) {
arr2[i] = arr[i];
}
return arr2;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
var NODE_TYPES;
(function (NODE_TYPES) {
NODE_TYPES["PLACEHOLDER"] = "placeholder";
NODE_TYPES["TEXT"] = "text";
NODE_TYPES["TAG"] = "tag";
NODE_TYPES["VOID_TAG"] = "void_tag";
})(NODE_TYPES || (NODE_TYPES = {}));
var isTextNode = function isTextNode(node) {
return node.type === NODE_TYPES.TEXT;
};
var isTagNode = function isTagNode(node) {
return node.type === NODE_TYPES.TAG;
};
var isPlaceholderNode = function isPlaceholderNode(node) {
return node.type === NODE_TYPES.PLACEHOLDER;
};
var isVoidTagNode = function isVoidTagNode(node) {
return node.type === NODE_TYPES.VOID_TAG;
};
var placeholderNode = function placeholderNode(value) {
return {
type: NODE_TYPES.PLACEHOLDER,
value: value
};
};
var textNode = function textNode(str) {
return {
type: NODE_TYPES.TEXT,
value: str
};
};
var tagNode = function tagNode(tagName, children) {
var value = tagName.trim();
return {
type: NODE_TYPES.TAG,
value: value,
children: children
};
};
var voidTagNode = function voidTagNode(tagName) {
var value = tagName.trim();
return {
type: NODE_TYPES.VOID_TAG,
value: value
};
};
/**
* Checks if target is node
* @param target
*/
var isNode = function isNode(target) {
if (typeof target === 'string') {
return false;
}
return !!target.type;
};
var STATE;
(function (STATE) {
/**
* Parser function switches to the text state when parses simple text,
* or content between open and close tags
*/
STATE["TEXT"] = "text";
/**
* Parser function switches to the tag state when meets open tag brace ("<"), and switches back,
* when meets closing tag brace (">")
*/
STATE["TAG"] = "tag";
/**
* Parser function switches to the placeholder state when meets in the text
* open placeholders brace ("{") and switches back to the text state,
* when meets close placeholder brace ("}")
*/
STATE["PLACEHOLDER"] = "placeholder";
})(STATE || (STATE = {}));
var CONTROL_CHARS = {
TAG_OPEN_BRACE: '<',
TAG_CLOSE_BRACE: '>',
CLOSING_TAG_MARK: '/',
PLACEHOLDER_MARK: '%'
};
/**
* Checks if text length is enough to create text node
* If text node created, then if stack is not empty it is pushed into stack,
* otherwise into result
* @param context
*/
var createTextNodeIfPossible = function createTextNodeIfPossible(context) {
var text = context.text;
if (text.length > 0) {
var node = textNode(text);
if (context.stack.length > 0) {
context.stack.push(node);
} else {
context.result.push(node);
}
}
context.text = '';
};
/**
* Checks if lastFromStack tag has any attributes
* @param lastFromStack
*/
var hasAttributes = function hasAttributes(lastFromStack) {
// e.g. "a class" or "a href='#'"
var tagStrParts = lastFromStack.split(' ');
return tagStrParts.length > 1;
};
/**
* Handles text state
*/
var textStateHandler = function textStateHandler(context) {
var currChar = context.currChar,
currIdx = context.currIdx; // switches to the tag state
if (currChar === CONTROL_CHARS.TAG_OPEN_BRACE) {
context.lastTextStateChangeIdx = currIdx;
return STATE.TAG;
} // switches to the placeholder state
if (currChar === CONTROL_CHARS.PLACEHOLDER_MARK) {
context.lastTextStateChangeIdx = currIdx;
return STATE.PLACEHOLDER;
} // remains in the text state
context.text += currChar;
return STATE.TEXT;
};
/**
* Handles placeholder state
* @param context
*/
var placeholderStateHandler = function placeholderStateHandler(context) {
var currChar = context.currChar,
currIdx = context.currIdx,
lastTextStateChangeIdx = context.lastTextStateChangeIdx,
placeholder = context.placeholder,
stack = context.stack,
result = context.result,
str = context.str;
if (currChar === CONTROL_CHARS.PLACEHOLDER_MARK) {
// if distance between current index and last state change equal to 1,
// it means that placeholder mark was escaped by itself e.g. "%%",
// so we return to the text state
if (currIdx - lastTextStateChangeIdx === 1) {
context.text += str.substring(lastTextStateChangeIdx, currIdx);
return STATE.TEXT;
}
createTextNodeIfPossible(context);
var node = placeholderNode(placeholder); // push node to the appropriate stack
if (stack.length > 0) {
stack.push(node);
} else {
result.push(node);
}
context.placeholder = '';
return STATE.TEXT;
}
context.placeholder += currChar;
return STATE.PLACEHOLDER;
};
/**
* Switches current state to the tag state and returns tag state handler
*/
var tagStateHandler = function tagStateHandler(context) {
var currChar = context.currChar,
text = context.text,
stack = context.stack,
result = context.result,
lastTextStateChangeIdx = context.lastTextStateChangeIdx,
currIdx = context.currIdx,
str = context.str;
var tag = context.tag; // if found tag end ">"
if (currChar === CONTROL_CHARS.TAG_CLOSE_BRACE) {
// if the tag is close tag e.g.
if (tag.indexOf(CONTROL_CHARS.CLOSING_TAG_MARK) === 0) {
// remove slash from tag
tag = tag.substring(1);
var children = [];
if (text.length > 0) {
children.push(textNode(text));
context.text = '';
}
var pairTagFound = false; // looking for the pair to the close tag
while (!pairTagFound && stack.length > 0) {
var lastFromStack = stack.pop(); // if tag from stack equal to close tag
if (lastFromStack === tag) {
// create tag node
var node = tagNode(tag, children); // and add it to the appropriate stack
if (stack.length > 0) {
stack.push(node);
} else {
result.push(node);
}
children = [];
pairTagFound = true;
} else if (isNode(lastFromStack)) {
// add nodes between close tag and open tag to the children
children.unshift(lastFromStack);
} else {
if (typeof lastFromStack === 'string' && hasAttributes(lastFromStack)) {
throw new Error("Tags in string should not have attributes: ".concat(str));
} else {
throw new Error("String has unbalanced tags: ".concat(str));
}
}
if (stack.length === 0 && children.length > 0) {
throw new Error("String has unbalanced tags: ".concat(str));
}
}
context.tag = '';
return STATE.TEXT;
} // if the tag is void tag e.g.
if (tag.lastIndexOf(CONTROL_CHARS.CLOSING_TAG_MARK) === tag.length - 1) {
tag = tag.substring(0, tag.length - 1);
createTextNodeIfPossible(context);
var _node = voidTagNode(tag); // add node to the appropriate stack
if (stack.length > 0) {
stack.push(_node);
} else {
result.push(_node);
}
context.tag = '';
return STATE.TEXT;
}
createTextNodeIfPossible(context);
stack.push(tag);
context.tag = '';
return STATE.TEXT;
} // If we meet open tag "<" it means that we wrongly moved into tag state
if (currChar === CONTROL_CHARS.TAG_OPEN_BRACE) {
context.text += str.substring(lastTextStateChangeIdx, currIdx);
context.lastTextStateChangeIdx = currIdx;
context.tag = '';
return STATE.TAG;
}
context.tag += currChar;
return STATE.TAG;
};
/**
* Parses string into AST (abstract syntax tree) and returns it
* e.g.
* parse("String to translate") ->
* ```
* [
* { type: 'text', value: 'String to ' },
* { type: 'tag', value: 'a', children: [{ type: 'text', value: 'translate' }] }
* ];
* ```
* Empty string is parsed into empty AST (abstract syntax tree): "[]"
*
* @param str Message in simplified ICU like syntax without plural support.
*
* @returns AST representation of the input string.
*
* @throws Error if tags have attributes or string has unbalanced tags or placeholder marker '%' is unclosed.
*/
var parser = function parser() {
var _STATE_HANDLERS;
var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var context = {
/**
* Stack is used to keep and search nested tag nodes
*/
stack: [],
/**
* Result is stack where function allocates nodes
*/
result: [],
/**
* Current char index
*/
currIdx: 0,
/**
* Saves index of the last state change from the text state,
* used to restore parsed text if we moved into other state wrongly
*/
lastTextStateChangeIdx: 0,
/**
* Accumulated tag value
*/
tag: '',
/**
* Accumulated text value
*/
text: '',
/**
* Accumulated placeholder value
*/
placeholder: '',
/**
* Parsed string
*/
str: str
};
var STATE_HANDLERS = (_STATE_HANDLERS = {}, _defineProperty(_STATE_HANDLERS, STATE.TEXT, textStateHandler), _defineProperty(_STATE_HANDLERS, STATE.PLACEHOLDER, placeholderStateHandler), _defineProperty(_STATE_HANDLERS, STATE.TAG, tagStateHandler), _STATE_HANDLERS); // Start from text state
var currentState = STATE.TEXT;
while (context.currIdx < str.length) {
context.currChar = str[context.currIdx];
var currentStateHandler = STATE_HANDLERS[currentState];
currentState = currentStateHandler(context);
context.currIdx += 1;
}
var result = context.result,
text = context.text,
stack = context.stack,
lastTextStateChangeIdx = context.lastTextStateChangeIdx; // Means that placeholder nodes were not closed
if (currentState === STATE.PLACEHOLDER) {
throw new Error("Unclosed placeholder marker '%' in string: ".concat(str));
} // Means that tag node were not closed, so we consider them as text
if (currentState !== STATE.TEXT) {
var restText = str.substring(lastTextStateChangeIdx);
if ((restText + text).length > 0) {
result.push(textNode(text + restText));
}
} else {
// eslint-disable-next-line no-lonely-if
if (text.length > 0) {
result.push(textNode(text));
}
}
if (stack.length > 0) {
throw new Error("String has unbalanced tags: ".concat(context.str));
}
return result;
};
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**
* Helper functions used by default to assemble strings from tag nodes
* @param tagName
* @param children
*/
var createStringElement = function createStringElement(tagName, children) {
if (children) {
return "<".concat(tagName, ">").concat(children, "").concat(tagName, ">");
}
return "<".concat(tagName, "/>");
};
/**
* Creates map with default values for tag converters
*/
var createDefaultValues = function createDefaultValues() {
return {
p: function p(children) {
return createStringElement('p', children);
},
b: function b(children) {
return createStringElement('b', children);
},
strong: function strong(children) {
return createStringElement('strong', children);
},
tt: function tt(children) {
return createStringElement('tt', children);
},
s: function s(children) {
return createStringElement('s', children);
},
i: function i(children) {
return createStringElement('i', children);
}
};
};
/**
* Returns prepared error message text.
*
* @param nodeType Node type.
* @param nodeValue Node value.
* @param key String key.
*
* @returns Error message.
*/
var getErrorMessage = function getErrorMessage(nodeType, nodeValue, key) {
var errorMessage = "Value '".concat(nodeValue, "' for '").concat(nodeType, "' was not provided");
if (key) {
errorMessage += " in string '".concat(key, "'");
}
return errorMessage;
};
/**
* This function accepts an AST (abstract syntax tree) which is a result
* of the parser function call, and converts tree nodes into array of strings replacing node
* values with provided values.
* Values is a map with functions or strings, where each key is related to placeholder value
* or tag value
* e.g.
* string "text tag text %placeholder%" is parsed into next AST
*
* [
* { type: 'text', value: 'text ' },
* {
* type: 'tag',
* value: 'tag',
* children: [{ type: 'text', value: 'tag text' }],
* },
* { type: 'text', value: ' ' },
* { type: 'placeholder', value: 'placeholder' }
* ];
*
* this AST after format and next values
*
* {
* // here used template strings, but it can be react components as well
* tag: (chunks) => `${chunks}`,
* placeholder: 'placeholder text'
* }
*
* will return next array
*
* [ 'text ', 'tag text', ' ', 'placeholder text' ]
*
* as you can see, was replaced by , and placeholder was replaced by placeholder text
*
* @param key
* @param ast - AST (abstract syntax tree)
* @param values
*/
var format = function format(key) {
var ast = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var values = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var result = [];
var tmplValues = _objectSpread(_objectSpread({}, createDefaultValues()), values);
var i = 0;
while (i < ast.length) {
var currentNode = ast[i]; // if current node is text node, there is nothing to change, append value to the result
if (isTextNode(currentNode)) {
result.push(currentNode.value);
} else if (isTagNode(currentNode)) {
var children = _toConsumableArray(format(key, currentNode.children, tmplValues));
var value = tmplValues[currentNode.value];
if (value) {
// TODO consider using strong typing
if (typeof value === 'function') {
result.push(value(children.join('')));
} else {
result.push(value);
}
} else {
throw new Error(getErrorMessage(currentNode.type, currentNode.value, key));
}
} else if (isVoidTagNode(currentNode)) {
var _value = tmplValues[currentNode.value]; // TODO consider using strong typing
if (_value && typeof _value === 'string') {
result.push(_value);
} else {
throw new Error(getErrorMessage(currentNode.type, currentNode.value, key));
}
} else if (isPlaceholderNode(currentNode)) {
var _value2 = tmplValues[currentNode.value]; // TODO consider using strong typing
if (_value2 && typeof _value2 === 'string') {
result.push(_value2);
} else {
throw new Error(getErrorMessage(currentNode.type, currentNode.value, key));
}
}
i += 1;
}
return result;
};
/**
* Function gets AST (abstract syntax tree) or string and formats messages,
* replacing values accordingly
* e.g.
* const message = formatter('some text', {
* a: (chunks) => `${chunks}`,
* });
* console.log(message); // ['some text']
*
* @param key
* @param message
* @param values
*/
var formatter = function formatter(key, message, values) {
var ast = parser(message);
var preparedValues = {}; // convert values to strings if not a function
if (values) {
Object.keys(values).forEach(function (key) {
var value = values[key]; // TODO consider using strong typing
if (typeof value === 'function') {
preparedValues[key] = value;
} else {
preparedValues[key] = String(value);
}
});
}
return format(key, ast, preparedValues);
};
var _pluralFormsCount;
var AvailableLocales;
(function (AvailableLocales) {
AvailableLocales["az"] = "az";
AvailableLocales["bo"] = "bo";
AvailableLocales["dz"] = "dz";
AvailableLocales["id"] = "id";
AvailableLocales["ja"] = "ja";
AvailableLocales["jv"] = "jv";
AvailableLocales["ka"] = "ka";
AvailableLocales["km"] = "km";
AvailableLocales["kn"] = "kn";
AvailableLocales["ko"] = "ko";
AvailableLocales["ms"] = "ms";
AvailableLocales["th"] = "th";
AvailableLocales["tr"] = "tr";
AvailableLocales["vi"] = "vi";
AvailableLocales["zh"] = "zh";
AvailableLocales["zh_cn"] = "zh_cn";
AvailableLocales["zh_tw"] = "zh_tw";
AvailableLocales["af"] = "af";
AvailableLocales["bn"] = "bn";
AvailableLocales["bg"] = "bg";
AvailableLocales["ca"] = "ca";
AvailableLocales["da"] = "da";
AvailableLocales["de"] = "de";
AvailableLocales["el"] = "el";
AvailableLocales["en"] = "en";
AvailableLocales["eo"] = "eo";
AvailableLocales["es"] = "es";
AvailableLocales["et"] = "et";
AvailableLocales["eu"] = "eu";
AvailableLocales["fa"] = "fa";
AvailableLocales["fi"] = "fi";
AvailableLocales["fo"] = "fo";
AvailableLocales["fur"] = "fur";
AvailableLocales["fy"] = "fy";
AvailableLocales["gl"] = "gl";
AvailableLocales["gu"] = "gu";
AvailableLocales["ha"] = "ha";
AvailableLocales["he"] = "he";
AvailableLocales["hu"] = "hu";
AvailableLocales["is"] = "is";
AvailableLocales["it"] = "it";
AvailableLocales["ku"] = "ku";
AvailableLocales["lb"] = "lb";
AvailableLocales["ml"] = "ml";
AvailableLocales["mn"] = "mn";
AvailableLocales["mr"] = "mr";
AvailableLocales["nah"] = "nah";
AvailableLocales["nb"] = "nb";
AvailableLocales["ne"] = "ne";
AvailableLocales["nl"] = "nl";
AvailableLocales["nn"] = "nn";
AvailableLocales["no"] = "no";
AvailableLocales["oc"] = "oc";
AvailableLocales["om"] = "om";
AvailableLocales["or"] = "or";
AvailableLocales["pa"] = "pa";
AvailableLocales["pap"] = "pap";
AvailableLocales["ps"] = "ps";
AvailableLocales["pt"] = "pt";
AvailableLocales["pt_pt"] = "pt_pt";
AvailableLocales["pt_br"] = "pt_br";
AvailableLocales["so"] = "so";
AvailableLocales["sq"] = "sq";
AvailableLocales["sv"] = "sv";
AvailableLocales["sw"] = "sw";
AvailableLocales["ta"] = "ta";
AvailableLocales["te"] = "te";
AvailableLocales["tk"] = "tk";
AvailableLocales["ur"] = "ur";
AvailableLocales["zu"] = "zu";
AvailableLocales["am"] = "am";
AvailableLocales["bh"] = "bh";
AvailableLocales["fil"] = "fil";
AvailableLocales["fr"] = "fr";
AvailableLocales["gun"] = "gun";
AvailableLocales["hi"] = "hi";
AvailableLocales["hy"] = "hy";
AvailableLocales["ln"] = "ln";
AvailableLocales["mg"] = "mg";
AvailableLocales["nso"] = "nso";
AvailableLocales["xbr"] = "xbr";
AvailableLocales["ti"] = "ti";
AvailableLocales["wa"] = "wa";
AvailableLocales["be"] = "be";
AvailableLocales["bs"] = "bs";
AvailableLocales["hr"] = "hr";
AvailableLocales["ru"] = "ru";
AvailableLocales["sr"] = "sr";
AvailableLocales["uk"] = "uk";
AvailableLocales["cs"] = "cs";
AvailableLocales["sk"] = "sk";
AvailableLocales["ga"] = "ga";
AvailableLocales["lt"] = "lt";
AvailableLocales["sl"] = "sl";
AvailableLocales["mk"] = "mk";
AvailableLocales["mt"] = "mt";
AvailableLocales["lv"] = "lv";
AvailableLocales["pl"] = "pl";
AvailableLocales["cy"] = "cy";
AvailableLocales["ro"] = "ro";
AvailableLocales["ar"] = "ar";
AvailableLocales["sr_latn"] = "sr_latn";
})(AvailableLocales || (AvailableLocales = {}));
var getPluralFormId = function getPluralFormId(locale, number) {
var _supportedForms;
if (number === 0) {
return 0;
}
var slavNum = number % 10 === 1 && number % 100 !== 11 ? 1 : number % 10 >= 2 && number % 10 <= 4 && (number % 100 < 10 || number % 100 >= 20) ? 2 : 3;
var supportedForms = (_supportedForms = {}, _defineProperty(_supportedForms, AvailableLocales.az, 1), _defineProperty(_supportedForms, AvailableLocales.bo, 1), _defineProperty(_supportedForms, AvailableLocales.dz, 1), _defineProperty(_supportedForms, AvailableLocales.id, 1), _defineProperty(_supportedForms, AvailableLocales.ja, 1), _defineProperty(_supportedForms, AvailableLocales.jv, 1), _defineProperty(_supportedForms, AvailableLocales.ka, 1), _defineProperty(_supportedForms, AvailableLocales.km, 1), _defineProperty(_supportedForms, AvailableLocales.kn, 1), _defineProperty(_supportedForms, AvailableLocales.ko, 1), _defineProperty(_supportedForms, AvailableLocales.ms, 1), _defineProperty(_supportedForms, AvailableLocales.th, 1), _defineProperty(_supportedForms, AvailableLocales.tr, 1), _defineProperty(_supportedForms, AvailableLocales.vi, 1), _defineProperty(_supportedForms, AvailableLocales.zh, 1), _defineProperty(_supportedForms, AvailableLocales.zh_tw, 1), _defineProperty(_supportedForms, AvailableLocales.zh_cn, 1), _defineProperty(_supportedForms, AvailableLocales.af, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.bn, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.bg, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.ca, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.da, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.de, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.el, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.en, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.eo, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.es, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.et, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.eu, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.fa, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.fi, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.fo, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.fur, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.fy, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.gl, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.gu, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.ha, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.he, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.hu, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.is, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.it, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.ku, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.lb, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.ml, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.mn, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.mr, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.nah, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.nb, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.ne, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.nl, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.nn, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.no, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.oc, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.om, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.or, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.pa, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.pap, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.ps, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.pt, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.pt_pt, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.pt_br, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.so, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.sq, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.sv, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.sw, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.ta, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.te, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.tk, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.ur, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.zu, number === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.am, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.bh, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.fil, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.fr, number === 0 || number >= 2 ? 2 : 1), _defineProperty(_supportedForms, AvailableLocales.gun, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.hi, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.hy, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.ln, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.mg, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.nso, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.xbr, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.ti, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.wa, number === 0 || number === 1 ? 0 : 1), _defineProperty(_supportedForms, AvailableLocales.be, slavNum), _defineProperty(_supportedForms, AvailableLocales.bs, slavNum), _defineProperty(_supportedForms, AvailableLocales.hr, slavNum), _defineProperty(_supportedForms, AvailableLocales.ru, slavNum), _defineProperty(_supportedForms, AvailableLocales.sr, slavNum), _defineProperty(_supportedForms, AvailableLocales.sr_latn, slavNum), _defineProperty(_supportedForms, AvailableLocales.uk, slavNum), _defineProperty(_supportedForms, AvailableLocales.cs, number === 1 ? 1 : number >= 2 && number <= 4 ? 2 : 3), _defineProperty(_supportedForms, AvailableLocales.sk, number === 1 ? 1 : number >= 2 && number <= 4 ? 2 : 3), _defineProperty(_supportedForms, AvailableLocales.ga, number === 1 ? 1 : number === 2 ? 2 : 3), _defineProperty(_supportedForms, AvailableLocales.lt, number % 10 === 1 && number % 100 !== 11 ? 1 : number % 10 >= 2 && (number % 100 < 10 || number % 100 >= 20) ? 2 : 3), _defineProperty(_supportedForms, AvailableLocales.sl, number % 100 === 1 ? 1 : number % 100 === 2 ? 2 : number % 100 === 3 || number % 100 === 4 ? 3 : 4), _defineProperty(_supportedForms, AvailableLocales.mk, number % 10 === 1 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.mt, number === 1 ? 1 : number === 0 || number % 100 > 1 && number % 100 < 11 ? 2 : number % 100 > 10 && number % 100 < 20 ? 3 : 4), _defineProperty(_supportedForms, AvailableLocales.lv, number === 0 ? 0 : number % 10 === 1 && number % 100 !== 11 ? 1 : 2), _defineProperty(_supportedForms, AvailableLocales.pl, number === 1 ? 1 : number % 10 >= 2 && number % 10 <= 4 && (number % 100 < 12 || number % 100 > 14) ? 2 : 3), _defineProperty(_supportedForms, AvailableLocales.cy, number === 1 ? 0 : number === 2 ? 1 : number === 8 || number === 11 ? 2 : 3), _defineProperty(_supportedForms, AvailableLocales.ro, number === 1 ? 1 : number === 1 || number % 100 > 0 && number % 100 < 20 ? 2 : 3), _defineProperty(_supportedForms, AvailableLocales.ar, number === 0 ? 0 : number === 1 ? 1 : number === 2 ? 2 : number % 100 >= 3 && number % 100 <= 10 ? 3 : number % 100 >= 11 && number % 100 <= 99 ? 4 : 5), _supportedForms);
return supportedForms[locale];
};
var pluralFormsCount = (_pluralFormsCount = {}, _defineProperty(_pluralFormsCount, AvailableLocales.az, 2), _defineProperty(_pluralFormsCount, AvailableLocales.bo, 2), _defineProperty(_pluralFormsCount, AvailableLocales.dz, 2), _defineProperty(_pluralFormsCount, AvailableLocales.id, 2), _defineProperty(_pluralFormsCount, AvailableLocales.ja, 2), _defineProperty(_pluralFormsCount, AvailableLocales.jv, 2), _defineProperty(_pluralFormsCount, AvailableLocales.ka, 2), _defineProperty(_pluralFormsCount, AvailableLocales.km, 2), _defineProperty(_pluralFormsCount, AvailableLocales.kn, 2), _defineProperty(_pluralFormsCount, AvailableLocales.ko, 2), _defineProperty(_pluralFormsCount, AvailableLocales.ms, 2), _defineProperty(_pluralFormsCount, AvailableLocales.th, 2), _defineProperty(_pluralFormsCount, AvailableLocales.tr, 2), _defineProperty(_pluralFormsCount, AvailableLocales.vi, 2), _defineProperty(_pluralFormsCount, AvailableLocales.zh, 2), _defineProperty(_pluralFormsCount, AvailableLocales.zh_cn, 2), _defineProperty(_pluralFormsCount, AvailableLocales.zh_tw, 2), _defineProperty(_pluralFormsCount, AvailableLocales.af, 3), _defineProperty(_pluralFormsCount, AvailableLocales.bn, 3), _defineProperty(_pluralFormsCount, AvailableLocales.bg, 3), _defineProperty(_pluralFormsCount, AvailableLocales.ca, 3), _defineProperty(_pluralFormsCount, AvailableLocales.da, 3), _defineProperty(_pluralFormsCount, AvailableLocales.de, 3), _defineProperty(_pluralFormsCount, AvailableLocales.el, 3), _defineProperty(_pluralFormsCount, AvailableLocales.en, 3), _defineProperty(_pluralFormsCount, AvailableLocales.eo, 3), _defineProperty(_pluralFormsCount, AvailableLocales.es, 3), _defineProperty(_pluralFormsCount, AvailableLocales.et, 3), _defineProperty(_pluralFormsCount, AvailableLocales.eu, 3), _defineProperty(_pluralFormsCount, AvailableLocales.fa, 3), _defineProperty(_pluralFormsCount, AvailableLocales.fi, 3), _defineProperty(_pluralFormsCount, AvailableLocales.fo, 3), _defineProperty(_pluralFormsCount, AvailableLocales.fur, 3), _defineProperty(_pluralFormsCount, AvailableLocales.fy, 3), _defineProperty(_pluralFormsCount, AvailableLocales.gl, 3), _defineProperty(_pluralFormsCount, AvailableLocales.gu, 3), _defineProperty(_pluralFormsCount, AvailableLocales.ha, 3), _defineProperty(_pluralFormsCount, AvailableLocales.he, 3), _defineProperty(_pluralFormsCount, AvailableLocales.hu, 3), _defineProperty(_pluralFormsCount, AvailableLocales.is, 3), _defineProperty(_pluralFormsCount, AvailableLocales.it, 3), _defineProperty(_pluralFormsCount, AvailableLocales.ku, 3), _defineProperty(_pluralFormsCount, AvailableLocales.lb, 3), _defineProperty(_pluralFormsCount, AvailableLocales.ml, 3), _defineProperty(_pluralFormsCount, AvailableLocales.mn, 3), _defineProperty(_pluralFormsCount, AvailableLocales.mr, 3), _defineProperty(_pluralFormsCount, AvailableLocales.nah, 3), _defineProperty(_pluralFormsCount, AvailableLocales.nb, 3), _defineProperty(_pluralFormsCount, AvailableLocales.ne, 3), _defineProperty(_pluralFormsCount, AvailableLocales.nl, 3), _defineProperty(_pluralFormsCount, AvailableLocales.nn, 3), _defineProperty(_pluralFormsCount, AvailableLocales.no, 3), _defineProperty(_pluralFormsCount, AvailableLocales.oc, 3), _defineProperty(_pluralFormsCount, AvailableLocales.om, 3), _defineProperty(_pluralFormsCount, AvailableLocales.or, 3), _defineProperty(_pluralFormsCount, AvailableLocales.pa, 3), _defineProperty(_pluralFormsCount, AvailableLocales.pap, 3), _defineProperty(_pluralFormsCount, AvailableLocales.ps, 3), _defineProperty(_pluralFormsCount, AvailableLocales.pt, 3), _defineProperty(_pluralFormsCount, AvailableLocales.pt_pt, 3), _defineProperty(_pluralFormsCount, AvailableLocales.pt_br, 3), _defineProperty(_pluralFormsCount, AvailableLocales.so, 3), _defineProperty(_pluralFormsCount, AvailableLocales.sq, 3), _defineProperty(_pluralFormsCount, AvailableLocales.sv, 3), _defineProperty(_pluralFormsCount, AvailableLocales.sw, 3), _defineProperty(_pluralFormsCount, AvailableLocales.ta, 3), _defineProperty(_pluralFormsCount, AvailableLocales.te, 3), _defineProperty(_pluralFormsCount, AvailableLocales.tk, 3), _defineProperty(_pluralFormsCount, AvailableLocales.ur, 3), _defineProperty(_pluralFormsCount, AvailableLocales.zu, 3), _defineProperty(_pluralFormsCount, AvailableLocales.am, 2), _defineProperty(_pluralFormsCount, AvailableLocales.bh, 2), _defineProperty(_pluralFormsCount, AvailableLocales.fil, 2), _defineProperty(_pluralFormsCount, AvailableLocales.fr, 3), _defineProperty(_pluralFormsCount, AvailableLocales.gun, 2), _defineProperty(_pluralFormsCount, AvailableLocales.hi, 2), _defineProperty(_pluralFormsCount, AvailableLocales.hy, 2), _defineProperty(_pluralFormsCount, AvailableLocales.ln, 2), _defineProperty(_pluralFormsCount, AvailableLocales.mg, 2), _defineProperty(_pluralFormsCount, AvailableLocales.nso, 2), _defineProperty(_pluralFormsCount, AvailableLocales.xbr, 2), _defineProperty(_pluralFormsCount, AvailableLocales.ti, 2), _defineProperty(_pluralFormsCount, AvailableLocales.wa, 2), _defineProperty(_pluralFormsCount, AvailableLocales.be, 4), _defineProperty(_pluralFormsCount, AvailableLocales.bs, 4), _defineProperty(_pluralFormsCount, AvailableLocales.hr, 4), _defineProperty(_pluralFormsCount, AvailableLocales.ru, 4), _defineProperty(_pluralFormsCount, AvailableLocales.sr, 4), _defineProperty(_pluralFormsCount, AvailableLocales.sr_latn, 4), _defineProperty(_pluralFormsCount, AvailableLocales.uk, 4), _defineProperty(_pluralFormsCount, AvailableLocales.cs, 4), _defineProperty(_pluralFormsCount, AvailableLocales.sk, 4), _defineProperty(_pluralFormsCount, AvailableLocales.ga, 4), _defineProperty(_pluralFormsCount, AvailableLocales.lt, 4), _defineProperty(_pluralFormsCount, AvailableLocales.sl, 5), _defineProperty(_pluralFormsCount, AvailableLocales.mk, 3), _defineProperty(_pluralFormsCount, AvailableLocales.mt, 5), _defineProperty(_pluralFormsCount, AvailableLocales.lv, 3), _defineProperty(_pluralFormsCount, AvailableLocales.pl, 4), _defineProperty(_pluralFormsCount, AvailableLocales.cy, 4), _defineProperty(_pluralFormsCount, AvailableLocales.ro, 4), _defineProperty(_pluralFormsCount, AvailableLocales.ar, 6), _pluralFormsCount);
var PLURAL_STRING_DELIMITER = '|';
/**
* Returns string plural forms which are separated by `|`.
*
* @param str Message.
*
* @returns Array of plural forms.
*/
var getForms = function getForms(str) {
return str.split(PLURAL_STRING_DELIMITER);
};
/**
* Checks whether the string has correct number of plural forms.
*
* @param str Translated string.
* @param locale Locale.
* @param key Optional, base key.
*
* @throws Error if the number of plural forms is incorrect.
*/
var checkForms = function checkForms(str, locale, key) {
var givenCount = getForms(str).length;
var requiredCount = pluralFormsCount[locale]; // e.g. 'sr-latn' may be passed and it is not supported, 'sr_latn' should be used
if (typeof requiredCount === 'undefined') {
throw new Error("Locale is not supported: '".concat(locale, "'"));
}
if (givenCount !== requiredCount) {
var prefix = typeof key !== 'undefined' ? "Invalid plural string \"".concat(key, "\" for locale '").concat(locale, "'") : "Invalid plural string for locale '".concat(locale, "'");
throw new Error("".concat(prefix, ": required ").concat(requiredCount, ", given ").concat(givenCount, " in string \"").concat(str, "\""));
}
};
/**
* Checks whether plural forms are present in base string
* by checking the presence of the vertical bar `|`.
*
* @param baseStr Base string.
*
* @returns True if `baseStr` contains `|`, false otherwise.
*/
var hasPluralForm = function hasPluralForm(baseStr) {
return baseStr.includes(PLURAL_STRING_DELIMITER);
};
/**
* Checks if plural forms are valid.
*
* @param targetStr Translated message with plural forms.
* @param locale Locale.
* @param key Optional, message key, used for clearer log message.
*
* @returns True if plural forms are valid, false otherwise.
*/
var isPluralFormValid = function isPluralFormValid(targetStr, locale, key) {
try {
checkForms(targetStr, locale, key);
return true;
} catch (error) {
return false;
}
};
/**
* Returns plural form corresponding to number
* @param str
* @param number
* @param locale - current locale
* @param key - message key
*/
var getForm = function getForm(str, number, locale, key) {
checkForms(str, locale, key);
var forms = getForms(str);
var currentForm = getPluralFormId(locale, number);
return forms[currentForm].trim();
};
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var defaultMessageConstructor = function defaultMessageConstructor(formatted) {
return formatted.join('');
};
var Translator = /*#__PURE__*/function () {
function Translator(i18n, // eslint-disable-next-line @typescript-eslint/no-explicit-any
messageConstructor, values) {
_classCallCheck(this, Translator);
this.i18n = i18n;
this.messageConstructor = messageConstructor || defaultMessageConstructor;
this.values = values || {};
}
/**
* Retrieves message and translates it, substituting parameters where necessary
* @param key - translation message key
* @param params - values used to substitute placeholders and tags
*/
_createClass(Translator, [{
key: "getMessage",
value: function getMessage(key) {
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var message = this.i18n.getMessage(key);
if (!message) {
message = this.i18n.getBaseMessage(key);
if (!message) {
throw new Error("Was unable to find message for key: \"".concat(key, "\""));
}
}
var formatted = formatter(key, message, _objectSpread$1(_objectSpread$1({}, this.values), params));
return this.messageConstructor(formatted);
}
/**
* Retrieves correct plural form and translates it
* @param key - translation message key
* @param number - plural form number
* @param params - values used to substitute placeholders or tags if necessary,
* if params has "count" property it will be overridden by number (plural form number)
*/
}, {
key: "getPlural",
value: function getPlural(key, number) {
var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var message = this.i18n.getMessage(key);
var language = this.i18n.getUILanguage();
if (!message) {
message = this.i18n.getBaseMessage(key);
if (!message) {
throw new Error("Was unable to find message for key: \"".concat(key, "\""));
}
language = this.i18n.getBaseUILanguage();
}
var form = getForm(message, number, language, key);
var formatted = formatter(key, form, _objectSpread$1(_objectSpread$1(_objectSpread$1({}, this.values), params), {}, {
count: number
}));
return this.messageConstructor(formatted);
}
}]);
return Translator;
}();
function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**
* Creates translation function for strings used in the React components
* We do not import React directly, because translator module can be used
* in the modules without React too
*
* e.g.
* const translateReact = createReactTranslator(getMessage, React);
* in locales folder you should have messages.json file
* ```
* message:
* "popup_auth_agreement_consent": {
* "message": "You agree to our EULA",
* },
* ```
*
* this message can be retrieved and translated into react components next way:
*
* const component = translateReact('popup_auth_agreement_consent', {
* eula: (chunks) => (
*
* ),
* });
*
* Note how functions in the values argument can be used with handlers
*
* @param i18n - object with methods which get translated message by key and return current locale
* @param React - instance of react library
*/
var createReactTranslator = function createReactTranslator(i18n, react, defaults) {
/**
* Helps to build nodes without values
*
* @param tagName
* @param children
*/
var createReactElement = function createReactElement(tagName, children) {
if (children) {
return react.createElement(tagName, null, react.Children.toArray(children));
}
return react.createElement(tagName, null);
};
/**
* Function creates default values to be used if user didn't provide function values for tags
*/
var createDefaultValues = function createDefaultValues() {
// eslint-disable-next-line @typescript-eslint/ban-types
var externalDefaults = {};
if (defaults) {
defaults.tags.forEach(function (t) {
externalDefaults[t.key] = function (children) {
return createReactElement(t.createdTag, children);
};
});
}
if (defaults !== null && defaults !== void 0 && defaults.override) {
return externalDefaults;
}
return _objectSpread$2({
p: function p(children) {
return createReactElement('p', children);
},
b: function b(children) {
return createReactElement('b', children);
},
strong: function strong(children) {
return createReactElement('strong', children);
},
tt: function tt(children) {
return createReactElement('tt', children);
},
s: function s(children) {
return createReactElement('s', children);
},
i: function i(children) {
return createReactElement('i', children);
}
}, externalDefaults);
};
var reactMessageConstructor = function reactMessageConstructor(formatted) {
var reactChildren = react.Children.toArray(formatted); // if there is only strings in the array we join them
if (reactChildren.every(function (child) {
return typeof child === 'string';
})) {
return reactChildren.join('');
}
return reactChildren;
};
var defaultValues = createDefaultValues();
return new Translator(i18n, reactMessageConstructor, defaultValues);
};
var r,
f;
function A(n, l) {
return l = l || [], null == n || "boolean" == typeof n || (Array.isArray(n) ? n.some(function (n) {
A(n, l);
}) : l.push(n)), l;
}
r = "function" == typeof Promise ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout, f = 0;
function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**
* Creates translation function for strings used in the Preact components
* We do not import Preact directly, because translator module can be used
* in the modules without Preact too
*
* e.g.
* const translatePreact = createPreactTranslator(getMessage, Preact);
* in locales folder you should have messages.json file
* ```
* message:
* "popup_auth_agreement_consent": {
* "message": "You agree to our EULA",
* },
* ```
*
* this message can be retrieved and translated into preact components next way:
*
* const component = translatePreact('popup_auth_agreement_consent', {
* eula: (chunks) => (
*
* ),
* });
*
* Note how functions in the values argument can be used with handlers
*
* @param i18n - object with methods which get translated message by key and return current locale
* @param Preact - instance of preact library
*/
var createPreactTranslator = function createPreactTranslator(i18n, preact, defaults) {
/**
* Helps to build nodes without values
*
* @param tagName
* @param children
*/
var createPreactElement = function createPreactElement(tagName, children) {
if (children) {
return preact.createElement(tagName, null, A(children));
}
return preact.createElement(tagName, null);
};
/**
* Function creates default values to be used if user didn't provide function values for tags
*/
var createDefaultValues = function createDefaultValues() {
// eslint-disable-next-line @typescript-eslint/ban-types
var externalDefaults = {};
if (defaults) {
defaults.tags.forEach(function (t) {
externalDefaults[t.key] = function (children) {
return createPreactElement(t.createdTag, children);
};
});
}
if (defaults !== null && defaults !== void 0 && defaults.override) {
return externalDefaults;
}
return _objectSpread$3({
p: function p(children) {
return createPreactElement('p', children);
},
b: function b(children) {
return createPreactElement('b', children);
},
strong: function strong(children) {
return createPreactElement('strong', children);
},
tt: function tt(children) {
return createPreactElement('tt', children);
},
s: function s(children) {
return createPreactElement('s', children);
},
i: function i(children) {
return createPreactElement('i', children);
}
}, externalDefaults);
};
var preactMessageConstructor = function preactMessageConstructor(formatted) {
var preactChildren = A(formatted); // if there is only strings in the array we join them
if (preactChildren.every(function (child) {
return typeof child === 'string';
})) {
return preactChildren.join('');
}
return preactChildren;
};
var defaultValues = createDefaultValues();
return new Translator(i18n, preactMessageConstructor, defaultValues);
};
/**
* Creates translator instance strings, by default for simple strings
* @param i18n - function which returns translated message by key
* @param messageConstructor - function that will collect messages
* @param values - map with default values for tag converters
*/
var createTranslator = function createTranslator(i18n, messageConstructor, values) {
return new Translator(i18n, messageConstructor, values);
};
var translate = {
createTranslator: createTranslator,
createReactTranslator: createReactTranslator,
createPreactTranslator: createPreactTranslator
};
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function _typeof(obj) {
return typeof obj;
};
} else {
_typeof = function _typeof(obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
/**
* Compares two AST (abstract syntax tree) structures,
* view tests for examples
* @param baseAst
* @param targetAst
*/
var areAstStructuresSame = function areAstStructuresSame(baseAst, targetAst) {
var textNodeFilter = function textNodeFilter(node) {
return !isTextNode(node);
};
var filteredBaseAst = baseAst.filter(textNodeFilter);
var filteredTargetAst = targetAst.filter(textNodeFilter); // if AST structures have different lengths, they are not equal
if (filteredBaseAst.length !== filteredTargetAst.length) {
return false;
}
var _loop = function _loop(i) {
var baseNode = filteredBaseAst[i];
var targetNode = filteredTargetAst.find(function (node) {
return node.type === baseNode.type && node.value === baseNode.value;
});
if (!targetNode) {
return {
v: false
};
}
if (targetNode.children && baseNode.children) {
var areChildrenSame = areAstStructuresSame(baseNode.children, targetNode.children);
if (!areChildrenSame) {
return {
v: false
};
}
}
};
for (var i = 0; i < filteredBaseAst.length; i += 1) {
var _ret = _loop(i);
if (_typeof(_ret) === "object") return _ret.v;
}
return true;
};
/**
* Validates translation against base string by AST (abstract syntax tree) structure.
*
* @param baseMessage Base message.
* @param translatedMessage Translated message.
* @param locale Locale of `translatedMessage`.
*
* @returns True if translated message is valid, false otherwise:
* - if base message has no plural forms, it will return true if AST structures are same;
* - if base message has plural forms, first of all
* the function checks if the number of plural forms is correct for the `locale`,
* and then it validates AST plural forms structures for base and translated messages.
*
* @throws Error for invalid tags in base or translated messages,
* if translated message has invalid plural forms,
* or if base or translated message has unclosed placeholder markers.
*/
var isTranslationValid = function isTranslationValid(baseMessage, translatedMessage, locale) {
if (hasPluralForm(baseMessage)) {
var isPluralFormsValid = isPluralFormValid(translatedMessage, locale);
if (!isPluralFormsValid) {
throw new Error('Invalid plural forms');
}
var baseForms = getForms(baseMessage);
var translatedForms = getForms(translatedMessage); // check a zero form structures of base and translated messages
if (!isTranslationValid(baseForms[0], translatedForms[0], locale)) {
return false;
} // and check other forms structures of translated messages against the first form of base message
for (var i = 1; i < translatedForms.length; i += 1) {
if (!isTranslationValid(baseForms[1], translatedForms[i], locale)) {
return false;
}
} // if no errors, return true after all checks
return true;
}
var baseMessageAst = parser(baseMessage);
var translatedMessageAst = parser(translatedMessage);
return areAstStructuresSame(baseMessageAst, translatedMessageAst);
};
var validator = (/* unused pure expression or super */ null && ({
isTranslationValid: isTranslationValid,
isPluralFormValid: isPluralFormValid
}));
},
28467(module, __unused_webpack_exports, __webpack_require__) {
/* module decorator */ module = __webpack_require__.nmd(module);
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define("webextension-polyfill", ["module"], factory);
} else if (true) {
factory(module);
} else { var mod }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (module) {
/* webextension-polyfill - v0.12.0 - Tue May 14 2024 18:01:29 */
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
if (!(globalThis.chrome && globalThis.chrome.runtime && globalThis.chrome.runtime.id)) {
throw new Error("This script should only be loaded in a browser extension.");
}
if (!(globalThis.browser && globalThis.browser.runtime && globalThis.browser.runtime.id)) {
const CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE = "The message port closed before a response was received.";
// Wrapping the bulk of this polyfill in a one-time-use function is a minor
// optimization for Firefox. Since Spidermonkey does not fully parse the
// contents of a function until the first time it's called, and since it will
// never actually need to be called, this allows the polyfill to be included
// in Firefox nearly for free.
const wrapAPIs = extensionAPIs => {
// NOTE: apiMetadata is associated to the content of the api-metadata.json file
// at build time by replacing the following "include" with the content of the
// JSON file.
const apiMetadata = {
"alarms": {
"clear": {
"minArgs": 0,
"maxArgs": 1
},
"clearAll": {
"minArgs": 0,
"maxArgs": 0
},
"get": {
"minArgs": 0,
"maxArgs": 1
},
"getAll": {
"minArgs": 0,
"maxArgs": 0
}
},
"bookmarks": {
"create": {
"minArgs": 1,
"maxArgs": 1
},
"get": {
"minArgs": 1,
"maxArgs": 1
},
"getChildren": {
"minArgs": 1,
"maxArgs": 1
},
"getRecent": {
"minArgs": 1,
"maxArgs": 1
},
"getSubTree": {
"minArgs": 1,
"maxArgs": 1
},
"getTree": {
"minArgs": 0,
"maxArgs": 0
},
"move": {
"minArgs": 2,
"maxArgs": 2
},
"remove": {
"minArgs": 1,
"maxArgs": 1
},
"removeTree": {
"minArgs": 1,
"maxArgs": 1
},
"search": {
"minArgs": 1,
"maxArgs": 1
},
"update": {
"minArgs": 2,
"maxArgs": 2
}
},
"browserAction": {
"disable": {
"minArgs": 0,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"enable": {
"minArgs": 0,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"getBadgeBackgroundColor": {
"minArgs": 1,
"maxArgs": 1
},
"getBadgeText": {
"minArgs": 1,
"maxArgs": 1
},
"getPopup": {
"minArgs": 1,
"maxArgs": 1
},
"getTitle": {
"minArgs": 1,
"maxArgs": 1
},
"openPopup": {
"minArgs": 0,
"maxArgs": 0
},
"setBadgeBackgroundColor": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"setBadgeText": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"setIcon": {
"minArgs": 1,
"maxArgs": 1
},
"setPopup": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"setTitle": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
}
},
"browsingData": {
"remove": {
"minArgs": 2,
"maxArgs": 2
},
"removeCache": {
"minArgs": 1,
"maxArgs": 1
},
"removeCookies": {
"minArgs": 1,
"maxArgs": 1
},
"removeDownloads": {
"minArgs": 1,
"maxArgs": 1
},
"removeFormData": {
"minArgs": 1,
"maxArgs": 1
},
"removeHistory": {
"minArgs": 1,
"maxArgs": 1
},
"removeLocalStorage": {
"minArgs": 1,
"maxArgs": 1
},
"removePasswords": {
"minArgs": 1,
"maxArgs": 1
},
"removePluginData": {
"minArgs": 1,
"maxArgs": 1
},
"settings": {
"minArgs": 0,
"maxArgs": 0
}
},
"commands": {
"getAll": {
"minArgs": 0,
"maxArgs": 0
}
},
"contextMenus": {
"remove": {
"minArgs": 1,
"maxArgs": 1
},
"removeAll": {
"minArgs": 0,
"maxArgs": 0
},
"update": {
"minArgs": 2,
"maxArgs": 2
}
},
"cookies": {
"get": {
"minArgs": 1,
"maxArgs": 1
},
"getAll": {
"minArgs": 1,
"maxArgs": 1
},
"getAllCookieStores": {
"minArgs": 0,
"maxArgs": 0
},
"remove": {
"minArgs": 1,
"maxArgs": 1
},
"set": {
"minArgs": 1,
"maxArgs": 1
}
},
"devtools": {
"inspectedWindow": {
"eval": {
"minArgs": 1,
"maxArgs": 2,
"singleCallbackArg": false
}
},
"panels": {
"create": {
"minArgs": 3,
"maxArgs": 3,
"singleCallbackArg": true
},
"elements": {
"createSidebarPane": {
"minArgs": 1,
"maxArgs": 1
}
}
}
},
"downloads": {
"cancel": {
"minArgs": 1,
"maxArgs": 1
},
"download": {
"minArgs": 1,
"maxArgs": 1
},
"erase": {
"minArgs": 1,
"maxArgs": 1
},
"getFileIcon": {
"minArgs": 1,
"maxArgs": 2
},
"open": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"pause": {
"minArgs": 1,
"maxArgs": 1
},
"removeFile": {
"minArgs": 1,
"maxArgs": 1
},
"resume": {
"minArgs": 1,
"maxArgs": 1
},
"search": {
"minArgs": 1,
"maxArgs": 1
},
"show": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
}
},
"extension": {
"isAllowedFileSchemeAccess": {
"minArgs": 0,
"maxArgs": 0
},
"isAllowedIncognitoAccess": {
"minArgs": 0,
"maxArgs": 0
}
},
"history": {
"addUrl": {
"minArgs": 1,
"maxArgs": 1
},
"deleteAll": {
"minArgs": 0,
"maxArgs": 0
},
"deleteRange": {
"minArgs": 1,
"maxArgs": 1
},
"deleteUrl": {
"minArgs": 1,
"maxArgs": 1
},
"getVisits": {
"minArgs": 1,
"maxArgs": 1
},
"search": {
"minArgs": 1,
"maxArgs": 1
}
},
"i18n": {
"detectLanguage": {
"minArgs": 1,
"maxArgs": 1
},
"getAcceptLanguages": {
"minArgs": 0,
"maxArgs": 0
}
},
"identity": {
"launchWebAuthFlow": {
"minArgs": 1,
"maxArgs": 1
}
},
"idle": {
"queryState": {
"minArgs": 1,
"maxArgs": 1
}
},
"management": {
"get": {
"minArgs": 1,
"maxArgs": 1
},
"getAll": {
"minArgs": 0,
"maxArgs": 0
},
"getSelf": {
"minArgs": 0,
"maxArgs": 0
},
"setEnabled": {
"minArgs": 2,
"maxArgs": 2
},
"uninstallSelf": {
"minArgs": 0,
"maxArgs": 1
}
},
"notifications": {
"clear": {
"minArgs": 1,
"maxArgs": 1
},
"create": {
"minArgs": 1,
"maxArgs": 2
},
"getAll": {
"minArgs": 0,
"maxArgs": 0
},
"getPermissionLevel": {
"minArgs": 0,
"maxArgs": 0
},
"update": {
"minArgs": 2,
"maxArgs": 2
}
},
"pageAction": {
"getPopup": {
"minArgs": 1,
"maxArgs": 1
},
"getTitle": {
"minArgs": 1,
"maxArgs": 1
},
"hide": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"setIcon": {
"minArgs": 1,
"maxArgs": 1
},
"setPopup": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"setTitle": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
},
"show": {
"minArgs": 1,
"maxArgs": 1,
"fallbackToNoCallback": true
}
},
"permissions": {
"contains": {
"minArgs": 1,
"maxArgs": 1
},
"getAll": {
"minArgs": 0,
"maxArgs": 0
},
"remove": {
"minArgs": 1,
"maxArgs": 1
},
"request": {
"minArgs": 1,
"maxArgs": 1
}
},
"runtime": {
"getBackgroundPage": {
"minArgs": 0,
"maxArgs": 0
},
"getPlatformInfo": {
"minArgs": 0,
"maxArgs": 0
},
"openOptionsPage": {
"minArgs": 0,
"maxArgs": 0
},
"requestUpdateCheck": {
"minArgs": 0,
"maxArgs": 0
},
"sendMessage": {
"minArgs": 1,
"maxArgs": 3
},
"sendNativeMessage": {
"minArgs": 2,
"maxArgs": 2
},
"setUninstallURL": {
"minArgs": 1,
"maxArgs": 1
}
},
"sessions": {
"getDevices": {
"minArgs": 0,
"maxArgs": 1
},
"getRecentlyClosed": {
"minArgs": 0,
"maxArgs": 1
},
"restore": {
"minArgs": 0,
"maxArgs": 1
}
},
"storage": {
"local": {
"clear": {
"minArgs": 0,
"maxArgs": 0
},
"get": {
"minArgs": 0,
"maxArgs": 1
},
"getBytesInUse": {
"minArgs": 0,
"maxArgs": 1
},
"remove": {
"minArgs": 1,
"maxArgs": 1
},
"set": {
"minArgs": 1,
"maxArgs": 1
}
},
"managed": {
"get": {
"minArgs": 0,
"maxArgs": 1
},
"getBytesInUse": {
"minArgs": 0,
"maxArgs": 1
}
},
"sync": {
"clear": {
"minArgs": 0,
"maxArgs": 0
},
"get": {
"minArgs": 0,
"maxArgs": 1
},
"getBytesInUse": {
"minArgs": 0,
"maxArgs": 1
},
"remove": {
"minArgs": 1,
"maxArgs": 1
},
"set": {
"minArgs": 1,
"maxArgs": 1
}
}
},
"tabs": {
"captureVisibleTab": {
"minArgs": 0,
"maxArgs": 2
},
"create": {
"minArgs": 1,
"maxArgs": 1
},
"detectLanguage": {
"minArgs": 0,
"maxArgs": 1
},
"discard": {
"minArgs": 0,
"maxArgs": 1
},
"duplicate": {
"minArgs": 1,
"maxArgs": 1
},
"executeScript": {
"minArgs": 1,
"maxArgs": 2
},
"get": {
"minArgs": 1,
"maxArgs": 1
},
"getCurrent": {
"minArgs": 0,
"maxArgs": 0
},
"getZoom": {
"minArgs": 0,
"maxArgs": 1
},
"getZoomSettings": {
"minArgs": 0,
"maxArgs": 1
},
"goBack": {
"minArgs": 0,
"maxArgs": 1
},
"goForward": {
"minArgs": 0,
"maxArgs": 1
},
"highlight": {
"minArgs": 1,
"maxArgs": 1
},
"insertCSS": {
"minArgs": 1,
"maxArgs": 2
},
"move": {
"minArgs": 2,
"maxArgs": 2
},
"query": {
"minArgs": 1,
"maxArgs": 1
},
"reload": {
"minArgs": 0,
"maxArgs": 2
},
"remove": {
"minArgs": 1,
"maxArgs": 1
},
"removeCSS": {
"minArgs": 1,
"maxArgs": 2
},
"sendMessage": {
"minArgs": 2,
"maxArgs": 3
},
"setZoom": {
"minArgs": 1,
"maxArgs": 2
},
"setZoomSettings": {
"minArgs": 1,
"maxArgs": 2
},
"update": {
"minArgs": 1,
"maxArgs": 2
}
},
"topSites": {
"get": {
"minArgs": 0,
"maxArgs": 0
}
},
"webNavigation": {
"getAllFrames": {
"minArgs": 1,
"maxArgs": 1
},
"getFrame": {
"minArgs": 1,
"maxArgs": 1
}
},
"webRequest": {
"handlerBehaviorChanged": {
"minArgs": 0,
"maxArgs": 0
}
},
"windows": {
"create": {
"minArgs": 0,
"maxArgs": 1
},
"get": {
"minArgs": 1,
"maxArgs": 2
},
"getAll": {
"minArgs": 0,
"maxArgs": 1
},
"getCurrent": {
"minArgs": 0,
"maxArgs": 1
},
"getLastFocused": {
"minArgs": 0,
"maxArgs": 1
},
"remove": {
"minArgs": 1,
"maxArgs": 1
},
"update": {
"minArgs": 2,
"maxArgs": 2
}
}
};
if (Object.keys(apiMetadata).length === 0) {
throw new Error("api-metadata.json has not been included in browser-polyfill");
}
/**
* A WeakMap subclass which creates and stores a value for any key which does
* not exist when accessed, but behaves exactly as an ordinary WeakMap
* otherwise.
*
* @param {function} createItem
* A function which will be called in order to create the value for any
* key which does not exist, the first time it is accessed. The
* function receives, as its only argument, the key being created.
*/
class DefaultWeakMap extends WeakMap {
constructor(createItem, items = undefined) {
super(items);
this.createItem = createItem;
}
get(key) {
if (!this.has(key)) {
this.set(key, this.createItem(key));
}
return super.get(key);
}
}
/**
* Returns true if the given object is an object with a `then` method, and can
* therefore be assumed to behave as a Promise.
*
* @param {*} value The value to test.
* @returns {boolean} True if the value is thenable.
*/
const isThenable = value => {
return value && typeof value === "object" && typeof value.then === "function";
};
/**
* Creates and returns a function which, when called, will resolve or reject
* the given promise based on how it is called:
*
* - If, when called, `chrome.runtime.lastError` contains a non-null object,
* the promise is rejected with that value.
* - If the function is called with exactly one argument, the promise is
* resolved to that value.
* - Otherwise, the promise is resolved to an array containing all of the
* function's arguments.
*
* @param {object} promise
* An object containing the resolution and rejection functions of a
* promise.
* @param {function} promise.resolve
* The promise's resolution function.
* @param {function} promise.reject
* The promise's rejection function.
* @param {object} metadata
* Metadata about the wrapped method which has created the callback.
* @param {boolean} metadata.singleCallbackArg
* Whether or not the promise is resolved with only the first
* argument of the callback, alternatively an array of all the
* callback arguments is resolved. By default, if the callback
* function is invoked with only a single argument, that will be
* resolved to the promise, while all arguments will be resolved as
* an array if multiple are given.
*
* @returns {function}
* The generated callback function.
*/
const makeCallback = (promise, metadata) => {
return (...callbackArgs) => {
if (extensionAPIs.runtime.lastError) {
promise.reject(new Error(extensionAPIs.runtime.lastError.message));
} else if (metadata.singleCallbackArg || callbackArgs.length <= 1 && metadata.singleCallbackArg !== false) {
promise.resolve(callbackArgs[0]);
} else {
promise.resolve(callbackArgs);
}
};
};
const pluralizeArguments = numArgs => numArgs == 1 ? "argument" : "arguments";
/**
* Creates a wrapper function for a method with the given name and metadata.
*
* @param {string} name
* The name of the method which is being wrapped.
* @param {object} metadata
* Metadata about the method being wrapped.
* @param {integer} metadata.minArgs
* The minimum number of arguments which must be passed to the
* function. If called with fewer than this number of arguments, the
* wrapper will raise an exception.
* @param {integer} metadata.maxArgs
* The maximum number of arguments which may be passed to the
* function. If called with more than this number of arguments, the
* wrapper will raise an exception.
* @param {boolean} metadata.singleCallbackArg
* Whether or not the promise is resolved with only the first
* argument of the callback, alternatively an array of all the
* callback arguments is resolved. By default, if the callback
* function is invoked with only a single argument, that will be
* resolved to the promise, while all arguments will be resolved as
* an array if multiple are given.
*
* @returns {function(object, ...*)}
* The generated wrapper function.
*/
const wrapAsyncFunction = (name, metadata) => {
return function asyncFunctionWrapper(target, ...args) {
if (args.length < metadata.minArgs) {
throw new Error(`Expected at least ${metadata.minArgs} ${pluralizeArguments(metadata.minArgs)} for ${name}(), got ${args.length}`);
}
if (args.length > metadata.maxArgs) {
throw new Error(`Expected at most ${metadata.maxArgs} ${pluralizeArguments(metadata.maxArgs)} for ${name}(), got ${args.length}`);
}
return new Promise((resolve, reject) => {
if (metadata.fallbackToNoCallback) {
// This API method has currently no callback on Chrome, but it return a promise on Firefox,
// and so the polyfill will try to call it with a callback first, and it will fallback
// to not passing the callback if the first call fails.
try {
target[name](...args, makeCallback({
resolve,
reject
}, metadata));
} catch (cbError) {
console.warn(`${name} API method doesn't seem to support the callback parameter, ` + "falling back to call it without a callback: ", cbError);
target[name](...args);
// Update the API method metadata, so that the next API calls will not try to
// use the unsupported callback anymore.
metadata.fallbackToNoCallback = false;
metadata.noCallback = true;
resolve();
}
} else if (metadata.noCallback) {
target[name](...args);
resolve();
} else {
target[name](...args, makeCallback({
resolve,
reject
}, metadata));
}
});
};
};
/**
* Wraps an existing method of the target object, so that calls to it are
* intercepted by the given wrapper function. The wrapper function receives,
* as its first argument, the original `target` object, followed by each of
* the arguments passed to the original method.
*
* @param {object} target
* The original target object that the wrapped method belongs to.
* @param {function} method
* The method being wrapped. This is used as the target of the Proxy
* object which is created to wrap the method.
* @param {function} wrapper
* The wrapper function which is called in place of a direct invocation
* of the wrapped method.
*
* @returns {Proxy}
* A Proxy object for the given method, which invokes the given wrapper
* method in its place.
*/
const wrapMethod = (target, method, wrapper) => {
return new Proxy(method, {
apply(targetMethod, thisObj, args) {
return wrapper.call(thisObj, target, ...args);
}
});
};
let hasOwnProperty = Function.call.bind(Object.prototype.hasOwnProperty);
/**
* Wraps an object in a Proxy which intercepts and wraps certain methods
* based on the given `wrappers` and `metadata` objects.
*
* @param {object} target
* The target object to wrap.
*
* @param {object} [wrappers = {}]
* An object tree containing wrapper functions for special cases. Any
* function present in this object tree is called in place of the
* method in the same location in the `target` object tree. These
* wrapper methods are invoked as described in {@see wrapMethod}.
*
* @param {object} [metadata = {}]
* An object tree containing metadata used to automatically generate
* Promise-based wrapper functions for asynchronous. Any function in
* the `target` object tree which has a corresponding metadata object
* in the same location in the `metadata` tree is replaced with an
* automatically-generated wrapper function, as described in
* {@see wrapAsyncFunction}
*
* @returns {Proxy