(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i 1) { throw 'Error: Missing operators between parts of the term.'; } // The only remaining element of the $nodes array contains the overall result result = nodes.pop(); // If the $nodes array did not contain any operator (but only one node) than // the result of this node has to be calculated now if (isNaN(result)) { return this.calculateNode(result); } return result; } /** * Returns the numeric value of a function node. * @param {FrontCalculatorParserNodeFunction} functionNode * * @returns {number} */ }, { key: "calculateFunctionNode", value: function calculateFunctionNode(functionNode) { var nodes = functionNode.childNodes; var functionArguments = []; // ex : func(1+2,3,4) : 1+2 need to be calculated first var argumentChildNodes = []; var containerNode = null; for (var i = 0; i < nodes.length; i++) { var node = nodes[i]; if (node instanceof _frontCalculatorParserNode.default) { if (node.symbol instanceof _frontCalculatorSymbol3.default) { containerNode = new _frontCalculatorParserNode3.default(argumentChildNodes); functionArguments.push(this.calculateNode(containerNode)); argumentChildNodes = []; } else { argumentChildNodes.push(node); } } else { argumentChildNodes.push(node); } } if (argumentChildNodes.length > 0) { containerNode = new _frontCalculatorParserNode3.default(argumentChildNodes); functionArguments.push(this.calculateNode(containerNode)); } /** * * @type {FrontCalculatorSymbolFunctionAbstract} */ var symbol = functionNode.symbolNode.symbol; return symbol.execute(functionArguments); } /** * Returns the numeric value of a symbol node. * Attention: node.symbol must not be of type AbstractOperator! * * @param {FrontCalculatorParserNodeSymbol} symbolNode * * @returns {Number} */ }, { key: "calculateSymbolNode", value: function calculateSymbolNode(symbolNode) { var symbol = symbolNode.symbol; var number = 0; if (symbol instanceof _frontCalculatorSymbol2.default) { number = symbolNode.token.value; // Convert string to int or float (depending on the type of the number) // If the number has a longer fractional part, it will be cut. number = Number(number); } else if (symbol instanceof _frontCalculatorSymbolConstant.default) { number = symbol.value; } else { throw 'Error: Found symbol of unexpected type "' + symbol.constructor.name + '", expected number or constant'; } return number; } /** * Detect the calculation order of a given array of nodes. * Does only care for the precedence of operators. * Does not care for child nodes of container nodes. * Returns a new array with ordered symbol nodes * * @param {FrontCalculatorParserNodeAbstract[]} nodes * * @return {Array} */ }, { key: "detectCalculationOrder", value: function detectCalculationOrder(nodes) { var operatorNodes = []; // Store all symbol nodes that have a symbol of type abstract operator in an array for (var i = 0; i < nodes.length; i++) { var node = nodes[i]; if (node instanceof _frontCalculatorParserNode.default) { if (node.symbol instanceof _frontCalculatorSymbolOperator.default) { var operatorNode = { index: i, node: node }; operatorNodes.push(operatorNode); } } } operatorNodes.sort( /** * Returning 1 means $nodeTwo before $nodeOne, returning -1 means $nodeOne before $nodeTwo. * @param {Object} operatorNodeOne * @param {Object} operatorNodeTwo */ function (operatorNodeOne, operatorNodeTwo) { var nodeOne = operatorNodeOne.node; var nodeTwo = operatorNodeTwo.node; // First-level precedence of node one /** * * @type {FrontCalculatorSymbolOperatorAbstract} */ var symbolOne = nodeOne.symbol; var precedenceOne = 2; if (nodeOne.isUnaryOperator) { precedenceOne = 3; } // First-level precedence of node two /** * * @type {FrontCalculatorSymbolOperatorAbstract} */ var symbolTwo = nodeTwo.symbol; var precedenceTwo = 2; if (nodeTwo.isUnaryOperator) { precedenceTwo = 3; } // If the first-level precedence is the same, compare the second-level precedence if (precedenceOne === precedenceTwo) { precedenceOne = symbolOne.precedence; precedenceTwo = symbolTwo.precedence; } // If the second-level precedence is the same, we have to ensure that the sorting algorithm does // insert the node / token that is left in the term before the node / token that is right. // Therefore we cannot return 0 but compare the positions and return 1 / -1. if (precedenceOne === precedenceTwo) { return nodeOne.token.position < nodeTwo.token.position ? -1 : 1; } return precedenceOne < precedenceTwo ? 1 : -1; }); return operatorNodes; } }]); return FrontCalculator; }(); if (window['forminatorCalculator'] === undefined) { window.forminatorCalculator = function (term) { return new FrontCalculator(term); }; } },{"./parser/front.calculator.parser":2,"./parser/front.calculator.parser.tokenizer":4,"./parser/node/front.calculator.parser.node.container":6,"./parser/node/front.calculator.parser.node.function":7,"./parser/node/front.calculator.parser.node.symbol":8,"./symbol/abstract/front.calculator.symbol.constant.abstract":10,"./symbol/abstract/front.calculator.symbol.operator.abstract":12,"./symbol/front.calculator.symbol.loader":16,"./symbol/front.calculator.symbol.number":17,"./symbol/front.calculator.symbol.separator":18}],2:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorParser = _interopRequireDefault(require("./front.calculator.parser.token")); var _frontCalculatorSymbol = _interopRequireDefault(require("../symbol/front.calculator.symbol.number")); var _frontCalculatorSymbolOpening = _interopRequireDefault(require("../symbol/brackets/front.calculator.symbol.opening.bracket")); var _frontCalculatorSymbolClosing = _interopRequireDefault(require("../symbol/brackets/front.calculator.symbol.closing.bracket")); var _frontCalculatorSymbolFunction = _interopRequireDefault(require("../symbol/abstract/front.calculator.symbol.function.abstract")); var _frontCalculatorSymbolOperator = _interopRequireDefault(require("../symbol/abstract/front.calculator.symbol.operator.abstract")); var _frontCalculatorSymbol2 = _interopRequireDefault(require("../symbol/front.calculator.symbol.separator")); var _frontCalculatorParserNode = _interopRequireDefault(require("./node/front.calculator.parser.node.symbol")); var _frontCalculatorParserNode2 = _interopRequireDefault(require("./node/front.calculator.parser.node.container")); var _frontCalculatorParserNode3 = _interopRequireDefault(require("./node/front.calculator.parser.node.function")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /** * The parsers has one important method: parse() * It takes an array of tokens as input and * returns an array of nodes as output. * These nodes are the syntax tree of the term. * */ var FrontCalculatorParser = exports.default = /*#__PURE__*/function () { /** * * @param {FrontCalculatorSymbolLoader} symbolLoader */ function FrontCalculatorParser(symbolLoader) { _classCallCheck(this, FrontCalculatorParser); /** * * @type {FrontCalculatorSymbolLoader} */ this.symbolLoader = symbolLoader; } /** * Parses an array with tokens. Returns an array of nodes. * These nodes define a syntax tree. * * @param {FrontCalculatorParserToken[]} tokens * * @returns FrontCalculatorParserNodeContainer */ _createClass(FrontCalculatorParser, [{ key: "parse", value: function parse(tokens) { var symbolNodes = this.detectSymbols(tokens); var nodes = this.createTreeByBrackets(symbolNodes); nodes = this.transformTreeByFunctions(nodes); this.checkGrammar(nodes); // Wrap the nodes in an array node. return new _frontCalculatorParserNode2.default(nodes); } /** * Creates a flat array of symbol nodes from tokens. * * @param {FrontCalculatorParserToken[]} tokens * @returns {FrontCalculatorParserNodeSymbol[]} */ }, { key: "detectSymbols", value: function detectSymbols(tokens) { var symbolNodes = []; var symbol = null; var identifier = null; var expectingOpeningBracket = false; // True if we expect an opening bracket (after a function name) var openBracketCounter = 0; for (var i = 0; i < tokens.length; i++) { var token = tokens[i]; var type = token.type; if (_frontCalculatorParser.default.TYPE_WORD === type) { identifier = token.value; symbol = this.symbolLoader.find(identifier); if (null === symbol) { throw 'Error: Detected unknown or invalid string identifier: ' + identifier + '.'; } } else if (type === _frontCalculatorParser.default.TYPE_NUMBER) { // Notice: Numbers do not have an identifier var symbolNumbers = this.symbolLoader.findSubTypes(_frontCalculatorSymbol.default); if (symbolNumbers.length < 1 || !(symbolNumbers instanceof Array)) { throw 'Error: Unavailable number symbol processor.'; } symbol = symbolNumbers[0]; } else { // Type Token::TYPE_CHARACTER: identifier = token.value; symbol = this.symbolLoader.find(identifier); if (null === symbol) { throw 'Error: Detected unknown or invalid string identifier: ' + identifier + '.'; } if (symbol instanceof _frontCalculatorSymbolOpening.default) { openBracketCounter++; } if (symbol instanceof _frontCalculatorSymbolClosing.default) { openBracketCounter--; // Make sure there are not too many closing brackets if (openBracketCounter < 0) { throw 'Error: Found closing bracket that does not have an opening bracket.'; } } } if (expectingOpeningBracket) { if (!(symbol instanceof _frontCalculatorSymbolOpening.default)) { throw 'Error: Expected opening bracket (after a function) but got something else.'; } expectingOpeningBracket = false; } else { if (symbol instanceof _frontCalculatorSymbolFunction.default) { expectingOpeningBracket = true; } } var symbolNode = new _frontCalculatorParserNode.default(token, symbol); symbolNodes.push(symbolNode); } // Make sure the term does not end with the name of a function but without an opening bracket if (expectingOpeningBracket) { throw 'Error: Expected opening bracket (after a function) but reached the end of the term'; } // Make sure there are not too many opening brackets if (openBracketCounter > 0) { throw 'Error: There is at least one opening bracket that does not have a closing bracket'; } return symbolNodes; } /** * Expects a flat array of symbol nodes and (if possible) transforms * it to a tree of nodes. Cares for brackets. * Attention: Expects valid brackets! * Check the brackets before you call this method. * * @param {FrontCalculatorParserNodeSymbol[]} symbolNodes * @returns {FrontCalculatorParserNodeAbstract[]} */ }, { key: "createTreeByBrackets", value: function createTreeByBrackets(symbolNodes) { var tree = []; var nodesInBracket = []; // AbstractSymbol nodes inside level-0-brackets var openBracketCounter = 0; for (var i = 0; i < symbolNodes.length; i++) { var symbolNode = symbolNodes[i]; if (!(symbolNode instanceof _frontCalculatorParserNode.default)) { throw 'Error: Expected symbol node, but got "' + symbolNode.constructor.name + '"'; } if (symbolNode.symbol instanceof _frontCalculatorSymbolOpening.default) { openBracketCounter++; if (openBracketCounter > 1) { nodesInBracket.push(symbolNode); } } else if (symbolNode.symbol instanceof _frontCalculatorSymbolClosing.default) { openBracketCounter--; // Found a closing bracket on level 0 if (0 === openBracketCounter) { var subTree = this.createTreeByBrackets(nodesInBracket); // Subtree can be empty for example if the term looks like this: "()" or "functioname()" // But this is okay, we need to allow this so we can call functions without a parameter tree.push(new _frontCalculatorParserNode2.default(subTree)); nodesInBracket = []; } else { nodesInBracket.push(symbolNode); } } else { if (0 === openBracketCounter) { tree.push(symbolNode); } else { nodesInBracket.push(symbolNode); } } } return tree; } /** * Replaces [a SymbolNode that has a symbol of type AbstractFunction, * followed by a node of type ContainerNode] by a FunctionNode. * Expects the $nodes not including any function nodes (yet). * * @param {FrontCalculatorParserNodeAbstract[]} nodes * * @returns {FrontCalculatorParserNodeAbstract[]} */ }, { key: "transformTreeByFunctions", value: function transformTreeByFunctions(nodes) { var transformedNodes = []; var functionSymbolNode = null; for (var i = 0; i < nodes.length; i++) { var node = nodes[i]; if (node instanceof _frontCalculatorParserNode2.default) { var transformedChildNodes = this.transformTreeByFunctions(node.childNodes); if (null !== functionSymbolNode) { var functionNode = new _frontCalculatorParserNode3.default(transformedChildNodes, functionSymbolNode); transformedNodes.push(functionNode); functionSymbolNode = null; } else { // not a function node.childNodes = transformedChildNodes; transformedNodes.push(node); } } else if (node instanceof _frontCalculatorParserNode.default) { var symbol = node.symbol; if (symbol instanceof _frontCalculatorSymbolFunction.default) { functionSymbolNode = node; } else { transformedNodes.push(node); } } else { throw 'Error: Expected array node or symbol node, got "' + node.constructor.name + '"'; } } return transformedNodes; } /** * Ensures the tree follows the grammar rules for terms * * @param {FrontCalculatorParserNodeAbstract[]} nodes */ }, { key: "checkGrammar", value: function checkGrammar(nodes) { // TODO Make sure that separators are only in the child nodes of the array node of a function node // (If this happens the calculator will throw an exception) for (var i = 0; i < nodes.length; i++) { var node = nodes[i]; if (node instanceof _frontCalculatorParserNode.default) { var symbol = node.symbol; if (symbol instanceof _frontCalculatorSymbolOperator.default) { var posOfRightOperand = i + 1; // Make sure the operator is positioned left of a (potential) operand (=prefix notation). // Example term: "-1" if (posOfRightOperand >= nodes.length) { throw 'Error: Found operator that does not stand before an operand.'; } var posOfLeftOperand = i - 1; var leftOperand = null; // Operator is unary if positioned at the beginning of a term if (posOfLeftOperand >= 0) { leftOperand = nodes[posOfLeftOperand]; if (leftOperand instanceof _frontCalculatorParserNode.default) { if (leftOperand.symbol instanceof _frontCalculatorSymbolOperator.default // example 1`+-`5 : + = operator, - = unary || leftOperand.symbol instanceof _frontCalculatorSymbol2.default // example func(1`,-`5) ,= separator, - = unary ) { // Operator is unary if positioned right to another operator leftOperand = null; } } } // If null, the operator is unary if (null === leftOperand) { if (!symbol.operatesUnary) { throw 'Error: Found operator in unary notation that is not unary.'; } // Remember that this node represents a unary operator node.setIsUnaryOperator(true); } else { if (!symbol.operatesBinary) { console.log(symbol); throw 'Error: Found operator in binary notation that is not binary.'; } } } } else { this.checkGrammar(node.childNodes); } } } }]); return FrontCalculatorParser; }(); },{"../symbol/abstract/front.calculator.symbol.function.abstract":11,"../symbol/abstract/front.calculator.symbol.operator.abstract":12,"../symbol/brackets/front.calculator.symbol.closing.bracket":13,"../symbol/brackets/front.calculator.symbol.opening.bracket":14,"../symbol/front.calculator.symbol.number":17,"../symbol/front.calculator.symbol.separator":18,"./front.calculator.parser.token":3,"./node/front.calculator.parser.node.container":6,"./node/front.calculator.parser.node.function":7,"./node/front.calculator.parser.node.symbol":8}],3:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } var FrontCalculatorParserToken = exports.default = /*#__PURE__*/function () { function FrontCalculatorParserToken(type, value, position) { _classCallCheck(this, FrontCalculatorParserToken); /** * * @type {Number} */ this.type = type; /** * * @type {String|Number} */ this.value = value; /** * * @type {Number} */ this.position = position; } _createClass(FrontCalculatorParserToken, null, [{ key: "TYPE_WORD", get: function get() { return 1; } }, { key: "TYPE_CHAR", get: function get() { return 2; } }, { key: "TYPE_NUMBER", get: function get() { return 3; } }]); return FrontCalculatorParserToken; }(); },{}],4:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorParser = _interopRequireDefault(require("./front.calculator.parser.token")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } var FrontCalculatorParserTokenizer = exports.default = /*#__PURE__*/function () { function FrontCalculatorParserTokenizer(input) { _classCallCheck(this, FrontCalculatorParserTokenizer); /** * * @type {String} */ this.input = input; /** * @type {number} */ this.currentPosition = 0; } /** * * @returns {FrontCalculatorParserToken[]} */ _createClass(FrontCalculatorParserTokenizer, [{ key: "tokenize", value: function tokenize() { this.reset(); var tokens = []; var token = this.readToken(); while (token) { tokens.push(token); token = this.readToken(); } return tokens; } /** * * @returns {FrontCalculatorParserToken} */ }, { key: "readToken", value: function readToken() { this.stepOverWhitespace(); var char = this.readCurrent(); if (null === char) { return null; } var value = null; var type = null; if (this.isLetter(char)) { value = this.readWord(); type = _frontCalculatorParser.default.TYPE_WORD; } else if (this.isDigit(char) || this.isPeriod(char)) { value = this.readNumber(); type = _frontCalculatorParser.default.TYPE_NUMBER; } else { value = this.readChar(); type = _frontCalculatorParser.default.TYPE_CHAR; } return new _frontCalculatorParser.default(type, value, this.currentPosition); } /** * Returns true, if a given character is a letter (a-z and A-Z). * * @param char * @returns {boolean} */ }, { key: "isLetter", value: function isLetter(char) { if (null === char) { return false; } var ascii = char.charCodeAt(0); /** * ASCII codes: 65 = 'A', 90 = 'Z', 97 = 'a', 122 = 'z'-- **/ return ascii >= 65 && ascii <= 90 || ascii >= 97 && ascii <= 122; } /** * Returns true, if a given character is a digit (0-9). * * @param char * @returns {boolean} */ }, { key: "isDigit", value: function isDigit(char) { if (null === char) { return false; } var ascii = char.charCodeAt(0); /** * ASCII codes: 48 = '0', 57 = '9' */ return ascii >= 48 && ascii <= 57; } /** * Returns true, if a given character is a period ('.'). * * @param char * @returns {boolean} */ }, { key: "isPeriod", value: function isPeriod(char) { return '.' === char; } /** * Returns true, if a given character is whitespace. * Notice: A null char is not seen as whitespace. * * @param char * @returns {boolean} */ }, { key: "isWhitespace", value: function isWhitespace(char) { return [" ", "\t", "\n"].indexOf(char) >= 0; } }, { key: "stepOverWhitespace", value: function stepOverWhitespace() { while (this.isWhitespace(this.readCurrent())) { this.readNext(); } } /** * Reads a word. Assumes that the cursor of the input stream * currently is positioned at the beginning of a word. * * @returns {string} */ }, { key: "readWord", value: function readWord() { var word = ''; var char = this.readCurrent(); // Try to read the word while (null !== char) { if (this.isLetter(char)) { word += char; } else { break; } // Just move the cursor to the next position char = this.readNext(); } return word; } /** * Reads a number (as a string). Assumes that the cursor * of the input stream currently is positioned at the * beginning of a number. * * @returns {string} */ }, { key: "readNumber", value: function readNumber() { var number = ''; var foundPeriod = false; // Try to read the number. // Notice: It does not matter if the number only consists of a single period // or if it ends with a period. var char = this.readCurrent(); while (null !== char) { if (this.isPeriod(char) || this.isDigit(char)) { if (this.isPeriod(char)) { if (foundPeriod) { throw 'Error: A number cannot have more than one period'; } foundPeriod = true; } number += char; } else { break; } // read next char = this.readNext(); } return number; } /** * Reads a single char. Assumes that the cursor of the input stream * currently is positioned at a char (not on null). * * @returns {String} */ }, { key: "readChar", value: function readChar() { var char = this.readCurrent(); // Just move the cursor to the next position this.readNext(); return char; } /** * * @returns {String|null} */ }, { key: "readCurrent", value: function readCurrent() { var char = null; if (this.hasCurrent()) { char = this.input[this.currentPosition]; } return char; } /** * Move the the cursor to the next position. * Will always move the cursor, even if the end of the string has been passed. * * @returns {String} */ }, { key: "readNext", value: function readNext() { this.currentPosition++; return this.readCurrent(); } /** * Returns true if there is a character at the current position * * @returns {boolean} */ }, { key: "hasCurrent", value: function hasCurrent() { return this.currentPosition < this.input.length; } }, { key: "reset", value: function reset() { this.currentPosition = 0; } }]); return FrontCalculatorParserTokenizer; }(); },{"./front.calculator.parser.token":3}],5:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var FrontCalculatorParserNodeAbstract = exports.default = /*#__PURE__*/_createClass(function FrontCalculatorParserNodeAbstract() { _classCallCheck(this, FrontCalculatorParserNodeAbstract); }); },{}],6:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorParserNode = _interopRequireDefault(require("./front.calculator.parser.node.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * A parent node is a container for a (sorted) array of nodes. * */ var FrontCalculatorParserNodeContainer = exports.default = /*#__PURE__*/function (_FrontCalculatorParse) { _inherits(FrontCalculatorParserNodeContainer, _FrontCalculatorParse); var _super = _createSuper(FrontCalculatorParserNodeContainer); function FrontCalculatorParserNodeContainer(childNodes) { var _this; _classCallCheck(this, FrontCalculatorParserNodeContainer); _this = _super.call(this); /** * * @type {FrontCalculatorParserNodeAbstract[]} */ _this.childNodes = null; _this.setChildNodes(childNodes); return _this; } /** * Setter for the child nodes. * Notice: The number of child nodes can be 0. * @param childNodes */ _createClass(FrontCalculatorParserNodeContainer, [{ key: "setChildNodes", value: function setChildNodes(childNodes) { childNodes.forEach(function (childNode) { if (!(childNode instanceof _frontCalculatorParserNode.default)) { throw 'Expected AbstractNode, but got ' + childNode.constructor.name; } }); this.childNodes = childNodes; } /** * Returns the number of child nodes in this array node. * Does not count the child nodes of the child nodes. * * @returns {number} */ }, { key: "size", value: function size() { try { return this.childNodes.length; } catch (e) { return 0; } } /** * Returns true if the array node does not have any * child nodes. This might sound strange but is possible. * * @returns {boolean} */ }, { key: "isEmpty", value: function isEmpty() { return !this.size(); } }]); return FrontCalculatorParserNodeContainer; }(_frontCalculatorParserNode.default); },{"./front.calculator.parser.node.abstract":5}],7:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorParserNode = _interopRequireDefault(require("./front.calculator.parser.node.container")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * A function in a term consists of the name of the function * (the symbol of the function) and the brackets that follow * the name and everything that is in this brackets (the * arguments). A function node combines these two things. * It stores its symbol in the $symbolNode property and its * arguments in the $childNodes property which is inherited * from the ContainerNode class. * */ var FrontCalculatorParserNodeFunction = exports.default = /*#__PURE__*/function (_FrontCalculatorParse) { _inherits(FrontCalculatorParserNodeFunction, _FrontCalculatorParse); var _super = _createSuper(FrontCalculatorParserNodeFunction); /** * ContainerNode constructor. * Attention: The constructor is differs from the constructor * of the parent class! * * @param childNodes * @param symbolNode */ function FrontCalculatorParserNodeFunction(childNodes, symbolNode) { var _this; _classCallCheck(this, FrontCalculatorParserNodeFunction); _this = _super.call(this, childNodes); /** * * @type {FrontCalculatorParserNodeSymbol} */ _this.symbolNode = symbolNode; return _this; } return _createClass(FrontCalculatorParserNodeFunction); }(_frontCalculatorParserNode.default); },{"./front.calculator.parser.node.container":6}],8:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolOperator = _interopRequireDefault(require("../../symbol/abstract/front.calculator.symbol.operator.abstract")); var _frontCalculatorParserNode = _interopRequireDefault(require("./front.calculator.parser.node.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * A symbol node is a node in the syntax tree. * Leaf nodes do not have any child nodes * (parent nodes can have child nodes). A * symbol node represents a mathematical symbol. * Nodes are created by the parser. * */ var FrontCalculatorParserNodeSymbol = exports.default = /*#__PURE__*/function (_FrontCalculatorParse) { _inherits(FrontCalculatorParserNodeSymbol, _FrontCalculatorParse); var _super = _createSuper(FrontCalculatorParserNodeSymbol); function FrontCalculatorParserNodeSymbol(token, symbol) { var _this; _classCallCheck(this, FrontCalculatorParserNodeSymbol); _this = _super.call(this); /** * The token of the node. It contains the value. * * @type {FrontCalculatorParserToken} */ _this.token = token; /** * The symbol of the node. It defines the type of the node. * * @type {FrontCalculatorSymbolAbstract} */ _this.symbol = symbol; /** * Unary operators need to be treated specially. * Therefore a node has to know if it (or to be * more precise the symbol of the node) * represents a unary operator. * Example : -1, -4 * * @type {boolean} */ _this.isUnaryOperator = false; return _this; } _createClass(FrontCalculatorParserNodeSymbol, [{ key: "setIsUnaryOperator", value: function setIsUnaryOperator(isUnaryOperator) { if (!(this.symbol instanceof _frontCalculatorSymbolOperator.default)) { throw 'Error: Cannot mark node as unary operator, because symbol is not an operator but of type ' + this.symbol.constructor.name; } this.isUnaryOperator = isUnaryOperator; } }]); return FrontCalculatorParserNodeSymbol; }(_frontCalculatorParserNode.default); },{"../../symbol/abstract/front.calculator.symbol.operator.abstract":12,"./front.calculator.parser.node.abstract":5}],9:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } var FrontCalculatorSymbolAbstract = exports.default = /*#__PURE__*/function () { function FrontCalculatorSymbolAbstract() { _classCallCheck(this, FrontCalculatorSymbolAbstract); /** * Array with the 1-n (exception: the Numbers class may have 0) * unique identifiers (the textual representation of a symbol) * of the symbol. Example: ['/', ':'] * Attention: The identifiers are case-sensitive, however, * valid identifiers in a term are always written in lower-case. * Therefore identifiers always have to be written in lower-case! * * @type {String[]} */ this.identifiers = []; } /** * Getter for the identifiers of the symbol. * Attention: The identifiers will be lower-cased! * @returns {String[]} */ _createClass(FrontCalculatorSymbolAbstract, [{ key: "getIdentifiers", value: function getIdentifiers() { var lowerIdentifiers = []; this.identifiers.forEach(function (identifier) { lowerIdentifiers.push(identifier.toLowerCase()); }); return lowerIdentifiers; } }]); return FrontCalculatorSymbolAbstract; }(); },{}],10:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbol = _interopRequireDefault(require("./front.calculator.symbol.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * This class is the base class for all symbols that are of the type "constant". * We recommend to use names as textual representations for this type of symbol. * Please take note of the fact that the precision of PHP float constants * (for example M_PI) is based on the "precision" directive in php.ini, * which defaults to 14. */ var FrontCalculatorSymbolConstantAbstract = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolConstantAbstract, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolConstantAbstract); function FrontCalculatorSymbolConstantAbstract() { var _this; _classCallCheck(this, FrontCalculatorSymbolConstantAbstract); _this = _super.call(this); /** * This is the value of the constant. We use 0 as an example here, * but you are supposed to overwrite this in the concrete constant class. * Usually mathematical constants are not integers, however, * you are allowed to use an integer in this context. * * @type {number} */ _this.value = 0; return _this; } return _createClass(FrontCalculatorSymbolConstantAbstract); }(_frontCalculatorSymbol.default); },{"./front.calculator.symbol.abstract":9}],11:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbol = _interopRequireDefault(require("./front.calculator.symbol.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * This class is the base class for all symbols that are of the type "function". * Typically the textual representation of a function consists of two or more letters. */ var FrontCalculatorSymbolFunctionAbstract = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolFunctionAbstract, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolFunctionAbstract); function FrontCalculatorSymbolFunctionAbstract() { _classCallCheck(this, FrontCalculatorSymbolFunctionAbstract); return _super.call(this); } /** * This method is called when the function is executed. A function can have 0-n parameters. * The implementation of this method is responsible to validate the number of arguments. * The $arguments array contains these arguments. If the number of arguments is improper, * the method has to throw a Exceptions\NumberOfArgumentsException exception. * The items of the $arguments array will always be of type int or float. They will never be null. * They keys will be integers starting at 0 and representing the positions of the arguments * in ascending order. * Overwrite this method in the concrete operator class. * If this class does NOT return a value of type int or float, * an exception will be thrown. * * @param {int[]|float[]} params * @returns {number} */ _createClass(FrontCalculatorSymbolFunctionAbstract, [{ key: "execute", value: function execute(params) { return 0.0; } }]); return FrontCalculatorSymbolFunctionAbstract; }(_frontCalculatorSymbol.default); },{"./front.calculator.symbol.abstract":9}],12:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbol = _interopRequireDefault(require("./front.calculator.symbol.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * This class is the base class for all symbols that are of the type "(binary) operator". * The textual representation of an operator consists of a single char that is not a letter. * It is worth noting that a operator has the same power as a function with two parameters. * Operators are always binary. To mimic a unary operator you might want to create a function * that accepts one parameter. */ var FrontCalculatorSymbolOperatorAbstract = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolOperatorAbstract, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolOperatorAbstract); function FrontCalculatorSymbolOperatorAbstract() { var _this; _classCallCheck(this, FrontCalculatorSymbolOperatorAbstract); _this = _super.call(this); /** * The operator precedence determines which operators to perform first * in order to evaluate a given term. * You are supposed to overwrite this constant in the concrete constant class. * Take a look at other operator classes to see the precedences of the predefined operators. * 0: default, > 0: higher, < 0: lower * * @type {number} */ _this.precedence = 0; /** * Usually operators are binary, they operate on two operands (numbers). * But some can operate on one operand (number). The operand of a unary * operator is always positioned after the operator (=prefix notation). * Good example: "-1" Bad Example: "1-" * If you want to create a unary operator that operates on the left * operand, you should use a function instead. Functions with one * parameter execute unary operations in functional notation. * Notice: Operators can be unary AND binary (but this is a rare case) * * @type {boolean} */ _this.operatesUnary = false; /** * Usually operators are binary, they operate on two operands (numbers). * Notice: Operators can be unary AND binary (but this is a rare case) * * @type {boolean} */ _this.operatesBinary = true; return _this; } _createClass(FrontCalculatorSymbolOperatorAbstract, [{ key: "operate", value: function operate(leftNumber, rightNumber) { return 0.0; } }]); return FrontCalculatorSymbolOperatorAbstract; }(_frontCalculatorSymbol.default); },{"./front.calculator.symbol.abstract":9}],13:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbol = _interopRequireDefault(require("../abstract/front.calculator.symbol.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var FrontCalculatorSymbolClosingBracket = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolClosingBracket, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolClosingBracket); function FrontCalculatorSymbolClosingBracket() { var _this; _classCallCheck(this, FrontCalculatorSymbolClosingBracket); _this = _super.call(this); _this.identifiers = [')']; return _this; } return _createClass(FrontCalculatorSymbolClosingBracket); }(_frontCalculatorSymbol.default); },{"../abstract/front.calculator.symbol.abstract":9}],14:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbol = _interopRequireDefault(require("../abstract/front.calculator.symbol.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var FrontCalculatorSymbolOpeningBracket = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolOpeningBracket, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolOpeningBracket); function FrontCalculatorSymbolOpeningBracket() { var _this; _classCallCheck(this, FrontCalculatorSymbolOpeningBracket); _this = _super.call(this); _this.identifiers = ['(']; return _this; } return _createClass(FrontCalculatorSymbolOpeningBracket); }(_frontCalculatorSymbol.default); },{"../abstract/front.calculator.symbol.abstract":9}],15:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolConstant = _interopRequireDefault(require("../abstract/front.calculator.symbol.constant.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Math.PI * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI */ var FrontCalculatorSymbolConstantPi = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolConstantPi, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolConstantPi); function FrontCalculatorSymbolConstantPi() { var _this; _classCallCheck(this, FrontCalculatorSymbolConstantPi); _this = _super.call(this); _this.identifiers = ['pi']; _this.value = Math.PI; return _this; } return _createClass(FrontCalculatorSymbolConstantPi); }(_frontCalculatorSymbolConstant.default); },{"../abstract/front.calculator.symbol.constant.abstract":10}],16:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbol = _interopRequireDefault(require("./front.calculator.symbol.number")); var _frontCalculatorSymbol2 = _interopRequireDefault(require("./front.calculator.symbol.separator")); var _frontCalculatorSymbolOpening = _interopRequireDefault(require("./brackets/front.calculator.symbol.opening.bracket")); var _frontCalculatorSymbolClosing = _interopRequireDefault(require("./brackets/front.calculator.symbol.closing.bracket")); var _frontCalculatorSymbolConstant = _interopRequireDefault(require("./constants/front.calculator.symbol.constant.pi")); var _frontCalculatorSymbolOperator = _interopRequireDefault(require("./operators/front.calculator.symbol.operator.addition")); var _frontCalculatorSymbolOperator2 = _interopRequireDefault(require("./operators/front.calculator.symbol.operator.division")); var _frontCalculatorSymbolOperator3 = _interopRequireDefault(require("./operators/front.calculator.symbol.operator.exponentiation")); var _frontCalculatorSymbolOperator4 = _interopRequireDefault(require("./operators/front.calculator.symbol.operator.modulo")); var _frontCalculatorSymbolOperator5 = _interopRequireDefault(require("./operators/front.calculator.symbol.operator.multiplication")); var _frontCalculatorSymbolOperator6 = _interopRequireDefault(require("./operators/front.calculator.symbol.operator.subtraction")); var _frontCalculatorSymbolFunction = _interopRequireDefault(require("./functions/front.calculator.symbol.function.abs")); var _frontCalculatorSymbolFunction2 = _interopRequireDefault(require("./functions/front.calculator.symbol.function.avg")); var _frontCalculatorSymbolFunction3 = _interopRequireDefault(require("./functions/front.calculator.symbol.function.ceil")); var _frontCalculatorSymbolFunction4 = _interopRequireDefault(require("./functions/front.calculator.symbol.function.floor")); var _frontCalculatorSymbolFunction5 = _interopRequireDefault(require("./functions/front.calculator.symbol.function.max")); var _frontCalculatorSymbolFunction6 = _interopRequireDefault(require("./functions/front.calculator.symbol.function.min")); var _frontCalculatorSymbolFunction7 = _interopRequireDefault(require("./functions/front.calculator.symbol.function.round")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } var FrontCalculatorSymbolLoader = exports.default = /*#__PURE__*/function () { function FrontCalculatorSymbolLoader() { _classCallCheck(this, FrontCalculatorSymbolLoader); /** * * @type {{FrontCalculatorSymbolOperatorModulo: FrontCalculatorSymbolOperatorModulo, FrontCalculatorSymbolOperatorSubtraction: FrontCalculatorSymbolOperatorSubtraction, FrontCalculatorSymbolOperatorExponentiation: FrontCalculatorSymbolOperatorExponentiation, FrontCalculatorSymbolOperatorAddition: FrontCalculatorSymbolOperatorAddition, FrontCalculatorSymbolClosingBracket: FrontCalculatorSymbolClosingBracket, FrontCalculatorSymbolFunctionMax: FrontCalculatorSymbolFunctionMax, FrontCalculatorSymbolFunctionCeil: FrontCalculatorSymbolFunctionCeil, FrontCalculatorSymbolSeparator: FrontCalculatorSymbolSeparator, FrontCalculatorSymbolOperatorMultiplication: FrontCalculatorSymbolOperatorMultiplication, FrontCalculatorSymbolFunctionAbs: FrontCalculatorSymbolFunctionAbs, FrontCalculatorSymbolFunctionAvg: FrontCalculatorSymbolFunctionAvg, FrontCalculatorSymbolFunctionFloor: FrontCalculatorSymbolFunctionFloor, FrontCalculatorSymbolFunctionMin: FrontCalculatorSymbolFunctionMin, FrontCalculatorSymbolOperatorDivision: FrontCalculatorSymbolOperatorDivision, FrontCalculatorSymbolNumber: FrontCalculatorSymbolNumber, FrontCalculatorSymbolOpeningBracket: FrontCalculatorSymbolOpeningBracket, FrontCalculatorSymbolConstantPi: FrontCalculatorSymbolConstantPi, FrontCalculatorSymbolFunctionRound: FrontCalculatorSymbolFunctionRound}} */ this.symbols = { FrontCalculatorSymbolNumber: new _frontCalculatorSymbol.default(), FrontCalculatorSymbolSeparator: new _frontCalculatorSymbol2.default(), FrontCalculatorSymbolOpeningBracket: new _frontCalculatorSymbolOpening.default(), FrontCalculatorSymbolClosingBracket: new _frontCalculatorSymbolClosing.default(), FrontCalculatorSymbolConstantPi: new _frontCalculatorSymbolConstant.default(), FrontCalculatorSymbolOperatorAddition: new _frontCalculatorSymbolOperator.default(), FrontCalculatorSymbolOperatorDivision: new _frontCalculatorSymbolOperator2.default(), FrontCalculatorSymbolOperatorExponentiation: new _frontCalculatorSymbolOperator3.default(), FrontCalculatorSymbolOperatorModulo: new _frontCalculatorSymbolOperator4.default(), FrontCalculatorSymbolOperatorMultiplication: new _frontCalculatorSymbolOperator5.default(), FrontCalculatorSymbolOperatorSubtraction: new _frontCalculatorSymbolOperator6.default(), FrontCalculatorSymbolFunctionAbs: new _frontCalculatorSymbolFunction.default(), FrontCalculatorSymbolFunctionAvg: new _frontCalculatorSymbolFunction2.default(), FrontCalculatorSymbolFunctionCeil: new _frontCalculatorSymbolFunction3.default(), FrontCalculatorSymbolFunctionFloor: new _frontCalculatorSymbolFunction4.default(), FrontCalculatorSymbolFunctionMax: new _frontCalculatorSymbolFunction5.default(), FrontCalculatorSymbolFunctionMin: new _frontCalculatorSymbolFunction6.default(), FrontCalculatorSymbolFunctionRound: new _frontCalculatorSymbolFunction7.default() }; } /** * Returns the symbol that has the given identifier. * Returns null if none is found. * * @param identifier * @returns {FrontCalculatorSymbolAbstract|null} */ _createClass(FrontCalculatorSymbolLoader, [{ key: "find", value: function find(identifier) { identifier = identifier.toLowerCase(); for (var key in this.symbols) { if (this.symbols.hasOwnProperty(key)) { var symbol = this.symbols[key]; if (symbol.getIdentifiers().indexOf(identifier) >= 0) { return symbol; } } } return null; } /** * Returns all symbols that inherit from a given abstract * parent type (class): The parent type has to be an * AbstractSymbol. * Notice: The parent type name will not be validated! * * @param parentTypeName * @returns {FrontCalculatorSymbolAbstract[]} */ }, { key: "findSubTypes", value: function findSubTypes(parentTypeName) { var symbols = []; for (var key in this.symbols) { if (this.symbols.hasOwnProperty(key)) { var symbol = this.symbols[key]; if (symbol instanceof parentTypeName) { symbols.push(symbol); } } } return symbols; } }]); return FrontCalculatorSymbolLoader; }(); },{"./brackets/front.calculator.symbol.closing.bracket":13,"./brackets/front.calculator.symbol.opening.bracket":14,"./constants/front.calculator.symbol.constant.pi":15,"./front.calculator.symbol.number":17,"./front.calculator.symbol.separator":18,"./functions/front.calculator.symbol.function.abs":19,"./functions/front.calculator.symbol.function.avg":20,"./functions/front.calculator.symbol.function.ceil":21,"./functions/front.calculator.symbol.function.floor":22,"./functions/front.calculator.symbol.function.max":23,"./functions/front.calculator.symbol.function.min":24,"./functions/front.calculator.symbol.function.round":25,"./operators/front.calculator.symbol.operator.addition":26,"./operators/front.calculator.symbol.operator.division":27,"./operators/front.calculator.symbol.operator.exponentiation":28,"./operators/front.calculator.symbol.operator.modulo":29,"./operators/front.calculator.symbol.operator.multiplication":30,"./operators/front.calculator.symbol.operator.subtraction":31}],17:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbol = _interopRequireDefault(require("./abstract/front.calculator.symbol.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * This class is the class that represents symbols of type "number". * Numbers are completely handled by the tokenizer/parser so there is no need to * create more than this concrete, empty number class that does not specify * a textual representation of numbers (numbers always consist of digits * and may include a single dot). */ var FrontCalculatorSymbolNumber = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolNumber, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolNumber); function FrontCalculatorSymbolNumber() { _classCallCheck(this, FrontCalculatorSymbolNumber); return _super.call(this); } return _createClass(FrontCalculatorSymbolNumber); }(_frontCalculatorSymbol.default); },{"./abstract/front.calculator.symbol.abstract":9}],18:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbol = _interopRequireDefault(require("./abstract/front.calculator.symbol.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * This class is a class that represents symbols of type "separator". * A separator separates the arguments of a (mathematical) function. * Most likely we will only need one concrete "separator" class. */ var FrontCalculatorSymbolSeparator = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolSeparator, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolSeparator); function FrontCalculatorSymbolSeparator() { var _this; _classCallCheck(this, FrontCalculatorSymbolSeparator); _this = _super.call(this); _this.identifiers = [',']; return _this; } return _createClass(FrontCalculatorSymbolSeparator); }(_frontCalculatorSymbol.default); },{"./abstract/front.calculator.symbol.abstract":9}],19:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolFunction = _interopRequireDefault(require("../abstract/front.calculator.symbol.function.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Math.abs() function. Expects one parameter. * Example: "abs(2)" => 2, "abs(-2)" => 2, "abs(0)" => 0 * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs */ var FrontCalculatorSymbolFunctionAbs = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolFunctionAbs, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolFunctionAbs); function FrontCalculatorSymbolFunctionAbs() { var _this; _classCallCheck(this, FrontCalculatorSymbolFunctionAbs); _this = _super.call(this); _this.identifiers = ['abs']; return _this; } _createClass(FrontCalculatorSymbolFunctionAbs, [{ key: "execute", value: function execute(params) { if (params.length !== 1) { throw 'Error: Expected one argument, got ' + params.length; } var number = params[0]; return Math.abs(number); } }]); return FrontCalculatorSymbolFunctionAbs; }(_frontCalculatorSymbolFunction.default); },{"../abstract/front.calculator.symbol.function.abstract":11}],20:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolFunction = _interopRequireDefault(require("../abstract/front.calculator.symbol.function.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Math.abs() function. Expects one parameter. * Example: "abs(2)" => 2, "abs(-2)" => 2, "abs(0)" => 0 * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs */ var FrontCalculatorSymbolFunctionAvg = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolFunctionAvg, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolFunctionAvg); function FrontCalculatorSymbolFunctionAvg() { var _this; _classCallCheck(this, FrontCalculatorSymbolFunctionAvg); _this = _super.call(this); _this.identifiers = ['avg']; return _this; } _createClass(FrontCalculatorSymbolFunctionAvg, [{ key: "execute", value: function execute(params) { if (params.length < 1) { throw 'Error: Expected at least one argument, got ' + params.length; } var sum = 0.0; for (var i = 0; i < params.length; i++) { sum += params[i]; } return sum / params.length; } }]); return FrontCalculatorSymbolFunctionAvg; }(_frontCalculatorSymbolFunction.default); },{"../abstract/front.calculator.symbol.function.abstract":11}],21:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolFunction = _interopRequireDefault(require("../abstract/front.calculator.symbol.function.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Math.ceil() function aka round fractions up. * Expects one parameter. * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil */ var FrontCalculatorSymbolFunctionCeil = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolFunctionCeil, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolFunctionCeil); function FrontCalculatorSymbolFunctionCeil() { var _this; _classCallCheck(this, FrontCalculatorSymbolFunctionCeil); _this = _super.call(this); _this.identifiers = ['ceil']; return _this; } _createClass(FrontCalculatorSymbolFunctionCeil, [{ key: "execute", value: function execute(params) { if (params.length !== 1) { throw 'Error: Expected one argument, got ' + params.length; } return Math.ceil(params[0]); } }]); return FrontCalculatorSymbolFunctionCeil; }(_frontCalculatorSymbolFunction.default); },{"../abstract/front.calculator.symbol.function.abstract":11}],22:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolFunction = _interopRequireDefault(require("../abstract/front.calculator.symbol.function.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Math.floor() function aka round fractions down. * Expects one parameter. * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor */ var FrontCalculatorSymbolFunctionFloor = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolFunctionFloor, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolFunctionFloor); function FrontCalculatorSymbolFunctionFloor() { var _this; _classCallCheck(this, FrontCalculatorSymbolFunctionFloor); _this = _super.call(this); _this.identifiers = ['floor']; return _this; } _createClass(FrontCalculatorSymbolFunctionFloor, [{ key: "execute", value: function execute(params) { if (params.length !== 1) { throw 'Error: Expected one argument, got ' + params.length; } return Math.floor(params[0]); } }]); return FrontCalculatorSymbolFunctionFloor; }(_frontCalculatorSymbolFunction.default); },{"../abstract/front.calculator.symbol.function.abstract":11}],23:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolFunction = _interopRequireDefault(require("../abstract/front.calculator.symbol.function.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } 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 _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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } 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 _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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Math.max() function. Expects at least one parameter. * Example: "max(1,2,3)" => 3, "max(1,-1)" => 1, "max(0,0)" => 0, "max(2)" => 2 * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max */ var FrontCalculatorSymbolFunctionMax = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolFunctionMax, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolFunctionMax); function FrontCalculatorSymbolFunctionMax() { var _this; _classCallCheck(this, FrontCalculatorSymbolFunctionMax); _this = _super.call(this); _this.identifiers = ['max']; return _this; } _createClass(FrontCalculatorSymbolFunctionMax, [{ key: "execute", value: function execute(params) { if (params.length < 1) { throw 'Error: Expected at least one argument, got ' + params.length; } return Math.max.apply(Math, _toConsumableArray(params)); } }]); return FrontCalculatorSymbolFunctionMax; }(_frontCalculatorSymbolFunction.default); },{"../abstract/front.calculator.symbol.function.abstract":11}],24:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolFunction = _interopRequireDefault(require("../abstract/front.calculator.symbol.function.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } 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 _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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } 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 _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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Math.min() function. Expects at least one parameter. * Example: "min(1,2,3)" => 1, "min(1,-1)" => -1, "min(0,0)" => 0, "min(2)" => 2 * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min */ var FrontCalculatorSymbolFunctionMin = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolFunctionMin, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolFunctionMin); function FrontCalculatorSymbolFunctionMin() { var _this; _classCallCheck(this, FrontCalculatorSymbolFunctionMin); _this = _super.call(this); _this.identifiers = ['min']; return _this; } _createClass(FrontCalculatorSymbolFunctionMin, [{ key: "execute", value: function execute(params) { if (params.length < 1) { throw 'Error: Expected at least one argument, got ' + params.length; } return Math.min.apply(Math, _toConsumableArray(params)); } }]); return FrontCalculatorSymbolFunctionMin; }(_frontCalculatorSymbolFunction.default); },{"../abstract/front.calculator.symbol.function.abstract":11}],25:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolFunction = _interopRequireDefault(require("../abstract/front.calculator.symbol.function.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Math.round() function aka rounds a float. * Expects one parameter. * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round */ var FrontCalculatorSymbolFunctionRound = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolFunctionRound, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolFunctionRound); function FrontCalculatorSymbolFunctionRound() { var _this; _classCallCheck(this, FrontCalculatorSymbolFunctionRound); _this = _super.call(this); _this.identifiers = ['round']; return _this; } _createClass(FrontCalculatorSymbolFunctionRound, [{ key: "execute", value: function execute(params) { if (params.length !== 1) { throw 'Error: Expected one argument, got ' + params.length; } return Math.round(params[0]); } }]); return FrontCalculatorSymbolFunctionRound; }(_frontCalculatorSymbolFunction.default); },{"../abstract/front.calculator.symbol.function.abstract":11}],26:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolOperator = _interopRequireDefault(require("../abstract/front.calculator.symbol.operator.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Operator for mathematical addition. * Example: "1+2" => 3 * * @see https://en.wikipedia.org/wiki/Addition * */ var FrontCalculatorSymbolOperatorAddition = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolOperatorAddition, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolOperatorAddition); function FrontCalculatorSymbolOperatorAddition() { var _this; _classCallCheck(this, FrontCalculatorSymbolOperatorAddition); _this = _super.call(this); _this.identifiers = ['+']; _this.precedence = 100; return _this; } _createClass(FrontCalculatorSymbolOperatorAddition, [{ key: "operate", value: function operate(leftNumber, rightNumber) { return leftNumber + rightNumber; } }]); return FrontCalculatorSymbolOperatorAddition; }(_frontCalculatorSymbolOperator.default); },{"../abstract/front.calculator.symbol.operator.abstract":12}],27:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolOperator = _interopRequireDefault(require("../abstract/front.calculator.symbol.operator.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Operator for mathematical division. * Example: "6/2" => 3, "6/0" => PHP warning * * @see https://en.wikipedia.org/wiki/Division_(mathematics) * */ var FrontCalculatorSymbolOperatorDivision = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolOperatorDivision, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolOperatorDivision); function FrontCalculatorSymbolOperatorDivision() { var _this; _classCallCheck(this, FrontCalculatorSymbolOperatorDivision); _this = _super.call(this); _this.identifiers = ['/']; _this.precedence = 200; return _this; } _createClass(FrontCalculatorSymbolOperatorDivision, [{ key: "operate", value: function operate(leftNumber, rightNumber) { var result = leftNumber / rightNumber; // // force to 0 // if (!isFinite(result)) { // return 0; // } return result; } }]); return FrontCalculatorSymbolOperatorDivision; }(_frontCalculatorSymbolOperator.default); },{"../abstract/front.calculator.symbol.operator.abstract":12}],28:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolOperator = _interopRequireDefault(require("../abstract/front.calculator.symbol.operator.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Operator for mathematical exponentiation. * Example: "3^2" => 9, "-3^2" => -9, "3^-2" equals "3^(-2)" * * @see https://en.wikipedia.org/wiki/Exponentiation * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow * */ var FrontCalculatorSymbolOperatorExponentiation = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolOperatorExponentiation, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolOperatorExponentiation); function FrontCalculatorSymbolOperatorExponentiation() { var _this; _classCallCheck(this, FrontCalculatorSymbolOperatorExponentiation); _this = _super.call(this); _this.identifiers = ['^']; _this.precedence = 300; return _this; } _createClass(FrontCalculatorSymbolOperatorExponentiation, [{ key: "operate", value: function operate(leftNumber, rightNumber) { return Math.pow(leftNumber, rightNumber); } }]); return FrontCalculatorSymbolOperatorExponentiation; }(_frontCalculatorSymbolOperator.default); },{"../abstract/front.calculator.symbol.operator.abstract":12}],29:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolOperator = _interopRequireDefault(require("../abstract/front.calculator.symbol.operator.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Operator for mathematical modulo operation. * Example: "5%3" => 2 * * @see https://en.wikipedia.org/wiki/Modulo_operation * */ var FrontCalculatorSymbolOperatorModulo = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolOperatorModulo, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolOperatorModulo); function FrontCalculatorSymbolOperatorModulo() { var _this; _classCallCheck(this, FrontCalculatorSymbolOperatorModulo); _this = _super.call(this); _this.identifiers = ['%']; _this.precedence = 200; return _this; } _createClass(FrontCalculatorSymbolOperatorModulo, [{ key: "operate", value: function operate(leftNumber, rightNumber) { return leftNumber % rightNumber; } }]); return FrontCalculatorSymbolOperatorModulo; }(_frontCalculatorSymbolOperator.default); },{"../abstract/front.calculator.symbol.operator.abstract":12}],30:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolOperator = _interopRequireDefault(require("../abstract/front.calculator.symbol.operator.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Operator for mathematical multiplication. * Example: "2*3" => 6 * * @see https://en.wikipedia.org/wiki/Multiplication * */ var FrontCalculatorSymbolOperatorMultiplication = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolOperatorMultiplication, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolOperatorMultiplication); function FrontCalculatorSymbolOperatorMultiplication() { var _this; _classCallCheck(this, FrontCalculatorSymbolOperatorMultiplication); _this = _super.call(this); _this.identifiers = ['*']; _this.precedence = 200; return _this; } _createClass(FrontCalculatorSymbolOperatorMultiplication, [{ key: "operate", value: function operate(leftNumber, rightNumber) { return leftNumber * rightNumber; } }]); return FrontCalculatorSymbolOperatorMultiplication; }(_frontCalculatorSymbolOperator.default); },{"../abstract/front.calculator.symbol.operator.abstract":12}],31:[function(require,module,exports){ "use strict"; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _frontCalculatorSymbolOperator = _interopRequireDefault(require("../abstract/front.calculator.symbol.operator.abstract")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** * Operator for mathematical subtraction. * Example: "2-1" => 1 * * @see https://en.wikipedia.org/wiki/Subtraction * */ var FrontCalculatorSymbolOperatorSubtraction = exports.default = /*#__PURE__*/function (_FrontCalculatorSymbo) { _inherits(FrontCalculatorSymbolOperatorSubtraction, _FrontCalculatorSymbo); var _super = _createSuper(FrontCalculatorSymbolOperatorSubtraction); function FrontCalculatorSymbolOperatorSubtraction() { var _this; _classCallCheck(this, FrontCalculatorSymbolOperatorSubtraction); _this = _super.call(this); _this.identifiers = ['-']; _this.precedence = 100; /** * Notice: The subtraction operator is unary AND binary! * * @type {boolean} */ _this.operatesUnary = true; return _this; } _createClass(FrontCalculatorSymbolOperatorSubtraction, [{ key: "operate", value: function operate(leftNumber, rightNumber) { return leftNumber - rightNumber; } }]); return FrontCalculatorSymbolOperatorSubtraction; }(_frontCalculatorSymbolOperator.default); },{"../abstract/front.calculator.symbol.operator.abstract":12}]},{},[1]); /*! * https://github.com/alfaslash/array-includes/blob/master/array-includes.js * * Array includes 1.0.4 * https://github.com/alfaslash/array-includes * * Released under the Apache License 2.0 * https://github.com/alfaslash/array-includes/blob/master/LICENSE */ if (![].includes) { Array.prototype.includes = function (searchElement, fromIndex) { 'use strict'; var O = Object(this); var len = parseInt(O.length) || 0; if (len === 0) { return false; } var n = parseInt(fromIndex) || 0; var k; if (n >= 0) { k = n; } else { k = len + n; if (k < 0) { k = 0; } } while (k < len) { var currentElement = O[k]; if (searchElement === currentElement || (searchElement !== searchElement && currentElement !== currentElement) ) { return true; } k++; } return false; }; } /********** * Common functions * ***********/ class forminatorFrontUtils { constructor() {} field_is_checkbox($element) { var is_checkbox = false; $element.each(function () { if (jQuery(this).attr('type') === 'checkbox') { is_checkbox = true; //break return false; } }); return is_checkbox; } field_is_radio($element) { var is_radio = false; $element.each(function () { if (jQuery(this).attr('type') === 'radio') { is_radio = true; //break return false; } }); return is_radio; } field_is_select($element) { return $element.is('select'); } field_has_inputMask( $element ) { var hasMask = false; $element.each(function () { if ( undefined !== jQuery( this ).attr( 'data-inputmask' ) ) { hasMask = true; //break return false; } }); return hasMask; } get_field_value( $element ) { var value = 0; var calculation = 0; var checked = null; if (this.field_is_radio($element)) { checked = $element.filter(":checked"); if (checked.length) { calculation = checked.data('calculation'); if (calculation !== undefined) { value = Number(calculation); } } } else if (this.field_is_checkbox($element)) { $element.each(function () { if (jQuery(this).is(':checked')) { calculation = jQuery(this).data('calculation'); if (calculation !== undefined) { value += Number(calculation); } } }); } else if (this.field_is_select($element)) { checked = $element.find("option").filter(':selected'); if (checked.length) { calculation = checked.data('calculation'); if (calculation !== undefined) { value = Number(calculation); } } } else if ( this.field_has_inputMask( $element ) ) { value = parseFloat( $element.inputmask('unmaskedvalue').replace(',','.') ); } else if ( $element.length ) { var number = $element.val(); value = parseFloat( number.replace(',','.') ); } return isNaN(value) ? 0 : value; } } if (window['forminatorUtils'] === undefined) { window.forminatorUtils = function () { return new forminatorFrontUtils(); } } // the semi-colon before function invocation is a safety net against concatenated // scripts and/or other plugins which may not be closed properly. ;// noinspection JSUnusedLocalSymbols (function ($, window, document, undefined) { "use strict"; // undefined is used here as the undefined global variable in ECMAScript 3 is // mutable (ie. it can be changed by someone else). undefined isn't really being // passed in so we can ensure the value of it is truly undefined. In ES5, undefined // can no longer be modified. // window and document are passed through as local variables rather than global // as this (slightly) quickens the resolution process and can be more efficiently // minified (especially when both are regularly referenced in your plugin). // Create the defaults once var pluginName = "forminatorLoader", defaults = { action: '', type: '', id: '', render_id: '', is_preview: '', preview_data: [], nonce: false, last_submit_data: {}, extra: {}, }; // The actual plugin constructor function ForminatorLoader(element, options) { this.element = element; this.$el = $(this.element); // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object // is generally empty as we don't want to alter the default options for // future instances of the plugin this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.frontInitCalled = false; this.scriptsQue = []; this.frontOptions = null; this.leadFrontOptions = null; this.init(); } // Avoid Plugin.prototype conflicts $.extend(ForminatorLoader.prototype, { init: function () { var param = (decodeURI(document.location.search)).replace(/(^\?)/, '').split("&").map(function (n) { return n = n.split("="), this[n[0]] = n[1], this }.bind({}))[0]; param.action = this.settings.action; param.type = this.settings.type; param.id = this.settings.id; param.render_id = this.settings.render_id; param.is_preview = this.settings.is_preview; param.preview_data = JSON.stringify(this.settings.preview_data); param.last_submit_data = this.settings.last_submit_data; param.extra = this.settings.extra; param.nonce = this.settings.nonce; if ( 'undefined' !== typeof this.settings.has_lead ) { param.has_lead = this.settings.has_lead; param.leads_id = this.settings.leads_id; } this.load_ajax(param); this.handleDiviPopup(); }, load_ajax: function (param) { var self = this; $.ajax({ type: 'POST', url: window.ForminatorFront.ajaxUrl, data: param, cache: false, beforeSend: function () { $(document).trigger('before.load.forminator', param.id); }, success: function (data) { if (data.success) { var response = data.data; $(document).trigger('response.success.load.forminator', param.id, data); if (!response.is_ajax_load) { //not load ajax return false; } var pagination_config = []; if(typeof response.pagination_config === "undefined" && typeof response.options.pagination_config !== "undefined") { pagination_config = response.options.pagination_config; } // response.pagination_config if (pagination_config) { window.Forminator_Cform_Paginations = window.Forminator_Cform_Paginations || []; window.Forminator_Cform_Paginations[param.id] = pagination_config; } self.frontOptions = response.options || null; // Solution for form Preview if (typeof window.Forminator_Cform_Paginations === "undefined" && self.frontOptions.pagination_config) { window.Forminator_Cform_Paginations = window.Forminator_Cform_Paginations || []; window.Forminator_Cform_Paginations[param.id] = self.frontOptions.pagination_config; } if( 'undefined' !== typeof response.lead_options ) { self.leadFrontOptions = response.lead_options || null; if (typeof window.Forminator_Cform_Paginations === "undefined" && self.leadFrontOptions.pagination_config) { window.Forminator_Cform_Paginations = window.Forminator_Cform_Paginations || []; window.Forminator_Cform_Paginations[param.leads_id] = self.leadFrontOptions.pagination_config; } } //response.html if (response.html) { var style = response.style || null; var script = response.script || null; self.render_html(response.html, style, script); } //response.styles if (response.styles) { self.maybe_append_styles(response.styles); } if (response.scripts) { self.maybe_append_scripts(response.scripts); } if (!response.scripts && self.frontOptions) { // when no additional scripts, direct execute self.init_front(); } } else { $(document).trigger('response.error.load.forminator', param.id, data); } }, error: function () { $(document).trigger('request.error.load.forminator', param.id); }, } ).always(function () { $(document).trigger('after.load.forminator', param.id); }); }, render_html: function (html, style, script) { var id = this.settings.id, render_id = this.settings.render_id, // save message message = '', wrapper_message = null; wrapper_message = this.$el.find('.forminator-response-message'); if (wrapper_message.length) { message = wrapper_message.get(0).outerHTML; } wrapper_message = this.$el.find('.forminator-poll-response-message'); if (wrapper_message.length) { message = wrapper_message.get(0).outerHTML; } if ( this.$el.parent().hasClass( 'forminator-guttenberg' ) ) { this.$el.parent() .html(html); } else { this.$el .replaceWith(html); } if (message) { $('#forminator-module-' + id + '[data-forminator-render=' + render_id + '] .forminator-response-message') .replaceWith(message); $('#forminator-module-' + id + '[data-forminator-render=' + render_id + '] .forminator-poll-response-message') .replaceWith(message); } //response.style if (style) { if ($('style#forminator-module-' + id).length) { $('style#forminator-module-' + id).remove(); } $('body').append(style); } if (script) { $('body').append(script); } }, maybe_append_styles: function (styles) { for (var style_id in styles) { if (styles.hasOwnProperty(style_id)) { // already loaded? if (!$('link#' + style_id).length) { var link = $(''); link.attr('rel', 'stylesheet'); link.attr('id', style_id); link.attr('type', 'text/css'); link.attr('media', 'all'); link.attr('href', styles[style_id].src); $('head').append(link); } } } }, maybe_append_scripts: function (scripts) { var self = this, scripts_to_load = [], hasHustle = $( 'body' ).find( '.hustle-ui' ).length, paypal_src = $( 'body' ).find( "script[src^='https://www.paypal.com/sdk/js']" ).attr('src') ; for (var script_id in scripts) { if (scripts.hasOwnProperty(script_id)) { var load_on = scripts[script_id].on; var load_of = scripts[script_id].load; // already loaded? if ('window' === load_on) { if ( window[load_of] && 'forminator-google-recaptcha' !== script_id && 0 === hasHustle ) { continue; } } else if ('$' === load_on) { if ($.fn[load_of]) { continue; } } var script = {}; script.src = scripts[script_id].src; // Check if a paypal script is already loaded. if ( script.src !== paypal_src ) { scripts_to_load.push(script); this.scriptsQue.push(script_id); } } } if (!this.scriptsQue.length) { this.init_front(); return; } for (var script_id_to_load in scripts_to_load) { if (scripts_to_load.hasOwnProperty(script_id_to_load)) { this.load_script(scripts_to_load[script_id_to_load]); } } }, load_script: function (script_props) { var self = this; var script = document.createElement('script'); var body = document.getElementsByTagName('body')[0]; script.type = 'text/javascript'; script.src = script_props.src; script.async = true; script.defer = true; script.onload = function () { self.script_on_load(); }; // Check if script is already loaded or not. if ( 0 === $( 'script[src="' + script.src + '"]' ).length ) { body.appendChild(script); } else { self.script_on_load(); } }, script_on_load: function () { this.scriptsQue.pop(); if (!this.scriptsQue.length) { this.init_front(); } }, init_front: function () { if (this.frontInitCalled) { return; } this.frontInitCalled = true; var id = this.settings.id; var render_id = this.settings.render_id; var options = this.frontOptions || null; var lead_options = this.leadFrontOptions || null; if (options) { $('#forminator-module-' + id + '[data-forminator-render="' + render_id + '"]') .forminatorFront(options); } if ( 'undefined' !== typeof this.settings.has_lead && lead_options) { var leads_id = this.settings.leads_id; $('#forminator-module-' + leads_id + '[data-forminator-render="' + render_id + '"]') .forminatorFront(lead_options); } this.init_window_vars(); }, init_window_vars: function () { // RELOAD type if (typeof ForminatorValidationErrors !== 'undefined') { var forminatorFrontSubmit = jQuery(ForminatorValidationErrors.selector).data('forminatorFrontSubmit'); if (typeof forminatorFrontSubmit !== 'undefined') { forminatorFrontSubmit.show_messages(ForminatorValidationErrors.errors); } } if (typeof ForminatorFormHider !== 'undefined') { var forminatorFront = jQuery(ForminatorFormHider.selector).data('forminatorFront'); if (typeof forminatorFront !== 'undefined') { forminatorFront.hide(); } } }, handleDiviPopup: function () { var self = this; if ( 'undefined' !== typeof DiviArea ) { DiviArea.addAction( 'show_area', function( area ) { var $form = area.find( '#' + self.element.id ); if ( 0 !== $form.length ) { self.frontInitCalled = false; self.init_front(); forminator_render_hcaptcha(); } }); } }, }); // A really lightweight plugin wrapper around the constructor, // preventing against multiple instantiations $.fn[pluginName] = function (options) { return this.each(function () { if (!$.data(this, pluginName)) { $.data(this, pluginName, new ForminatorLoader(this, options)); } }); }; })(jQuery, window, document); // the semi-colon before function invocation is a safety net against concatenated // scripts and/or other plugins which may not be closed properly. ;// noinspection JSUnusedLocalSymbols (function ($, window, document, undefined) { "use strict"; // undefined is used here as the undefined global variable in ECMAScript 3 is // mutable (ie. it can be changed by someone else). undefined isn't really being // passed in so we can ensure the value of it is truly undefined. In ES5, undefined // can no longer be modified. // window and document are passed through as local variables rather than global // as this (slightly) quickens the resolution process and can be more efficiently // minified (especially when both are regularly referenced in your plugin). // Create the defaults once var pluginName = "forminatorFront", defaults = { form_type: 'custom-form', rules: {}, messages: {}, conditions: {}, inline_validation: false, print_value: false, chart_design: 'bar', chart_options: {}, forminator_fields: [], general_messages: { calculation_error: 'Failed to calculate field.', payment_require_ssl_error: 'SSL required to submit this form, please check your URL.', payment_require_amount_error: 'PayPal amount must be greater than 0.', form_has_error: 'Please correct the errors before submission.' }, payment_require_ssl : false, }; // The actual plugin constructor function ForminatorFront(element, options) { this.element = element; this.$el = $(this.element); this.forminator_selector = '#' + $(this.element).attr('id') + '[data-forminator-render="' + $(this.element).data('forminator-render') + '"]'; this.forminator_loader_selector = 'div[data-forminator-render="' + $(this.element).data('forminator-render') + '"]' + '[data-form="' + $(this.element).attr('id') + '"]'; // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object // is generally empty as we don't want to alter the default options for // future instances of the plugin this.settings = $.extend({}, defaults, options); // special treatment for rules, messages, and conditions if (typeof this.settings.messages !== 'undefined') { this.settings.messages = this.maybeParseStringToJson(this.settings.messages, 'object'); } if (typeof this.settings.rules !== 'undefined') { this.settings.rules = this.maybeParseStringToJson(this.settings.rules, 'object'); } if (typeof this.settings.calendar !== 'undefined') { this.settings.calendar = this.maybeParseStringToJson(this.settings.calendar, 'array'); } this._defaults = defaults; this._name = pluginName; this.form_id = 0; this.template_type = ''; this.init(); this.handleDiviPopup(); } // Avoid Plugin.prototype conflicts $.extend(ForminatorFront.prototype, { init: function () { var self = this; if (this.$el.find('input[name="form_id"]').length > 0) { this.form_id = this.$el.find('input[name="form_id"]').val(); } if (this.$el.find('input[name="form_type"]').length > 0) { this.template_type = this.$el.find('input[name="form_type"]').val(); } $(this.forminator_loader_selector).remove(); // If form from hustle popup, do not show if (this.$el.closest('.wph-modal').length === 0) { this.$el.show(); } // Show form when popup trigger with click $(document).on("hustle:module:displayed", function (e, data) { var $modal = $('.wph-modal-active'); $modal.find('form').css('display', ''); }); self.reint_intlTelInput(); // Show form when popup trigger setTimeout(function () { var $modal = $('.wph-modal-active'); $modal.find('form').css('display', ''); }, 10); //selective activation based on type of form switch (this.settings.form_type) { case 'custom-form': $( this.element ).each( function() { self.init_custom_form( this ); }); this.$el.on( 'forminator-clone-group', function ( event ) { self.init_custom_form( event.target ); } ); break; case 'poll': this.init_poll_form(); break; case 'quiz': this.init_quiz_form(); break; } //init submit var submitOptions = { form_type: self.settings.form_type, forminator_selector: self.forminator_selector, chart_design: self.settings.chart_design, chart_options: self.settings.chart_options, has_quiz_loader: self.settings.has_quiz_loader, has_loader: self.settings.has_loader, loader_label: self.settings.loader_label, resetEnabled: self.settings.is_reset_enabled, inline_validation: self.settings.inline_validation, }; if( 'leads' === this.template_type || 'quiz' === this.settings.form_type ) { submitOptions.form_placement = self.settings.form_placement; submitOptions.hasLeads = self.settings.hasLeads; submitOptions.leads_id = self.settings.leads_id; submitOptions.quiz_id = self.settings.quiz_id; submitOptions.skip_form = self.settings.skip_form; } $(this.element).forminatorFrontSubmit( submitOptions ); // TODO: confirm usage on form type // Handle field activation classes this.activate_field(); // Handle special classes for material design // this.material_field(); // Init small form for all type of form this.small_form(); }, init_custom_form: function ( form_selector ) { var self = this, $saveDraft = this.$el.find( '.forminator-save-draft-link' ), saveDraftExists = 0 !== $saveDraft.length ? true : false, draftTimer ; //initiate validator this.init_intlTelInput_validation( form_selector ); if (this.settings.inline_validation) { $( form_selector ).forminatorFrontValidate({ rules: self.settings.rules, messages: self.settings.messages }); } // initiate calculator $( form_selector ).forminatorFrontCalculate({ forminatorFields: self.settings.forminator_fields, generalMessages: self.settings.general_messages, memoizeTime: self.settings.calcs_memoize_time || 300, }); // initiate merge tags $( form_selector ).forminatorFrontMergeTags({ forminatorFields: self.settings.forminator_fields, print_value: self.settings.print_value, }); //initiate pagination this.init_pagination( form_selector ); // initiate payment if exist var first_payment = $( form_selector ).find('div[data-is-payment="true"], input[data-is-payment="true"]').first(); if( self.settings.has_stripe ) { var stripe_payment = $(this.element).find('.forminator-stripe-element').first(); if ( $( self.element ).is( ':visible' ) ) { this.renderStripe( self, stripe_payment ); } // Show Stripe on modal display. $( document ).on( "hustle:module:displayed", function () { self.renderStripe( self, stripe_payment ); }); } if( self.settings.has_paypal // Fix for Divi popup. && ( ! $( self.element ).closest( '.et_pb_section' ).length || $( self.element ).is( ':visible' ) ) ) { $(this.element).forminatorFrontPayPal({ type: 'paypal', paymentEl: this.settings.paypal_config, paymentRequireSsl: self.settings.payment_require_ssl, generalMessages: self.settings.general_messages, has_loader: self.settings.has_loader, loader_label: self.settings.loader_label, }); } //initiate condition $( form_selector ).forminatorFrontCondition(this.settings.conditions, this.settings.calendar); //initiate forminator ui scripts this.init_fui( form_selector ); //initiate datepicker $( form_selector ).find('.forminator-datepicker').forminatorFrontDatePicker(this.settings.calendar); // Handle responsive captcha this.responsive_captcha( form_selector ); // Handle field counter this.field_counter( form_selector ); // Handle number input this.field_number( form_selector ); // Handle time fields this.field_time(); // Handle upload field change $( form_selector ).find('.forminator-multi-upload').forminatorFrontMultiFile( this.$el ); this.upload_field( form_selector ); this.init_login_2FA(); self.maybeRemoveDuplicateFields( form_selector ); self.checkComplianzBlocker(); // Handle function on resize $(window).on('resize', function () { self.responsive_captcha( form_selector ); }); // Handle function on load $( window ).on( 'load', function () { // Repeat the function here, just in case our scripts gets loaded late self.maybeRemoveDuplicateFields( form_selector ); }); // We have to declare initialData here, after everything has been set initially, to prevent triggering change event. var initialData = saveDraftExists ? this.$el.serializeArray() : ''; this.$el.find( ".forminator-field input, .forminator-row input[type=hidden], .forminator-field select, .forminator-field textarea, .forminator-field-signature").on( 'change input', function (e) { if ( saveDraftExists && $saveDraft.hasClass( 'disabled' ) ) { clearTimeout( draftTimer ); draftTimer = setTimeout( function() { self.maybe_enable_save_draft( $saveDraft, initialData ); }, 500 ); } }); if( 'undefined' !== typeof self.settings.hasLeads ) { if( 'beginning' === self.settings.form_placement ) { $('#forminator-module-' + this.settings.quiz_id ).css({ 'height': 0, 'opacity': 0, 'overflow': 'hidden', 'visibility': 'hidden', 'pointer-events': 'none', 'margin': 0, 'padding': 0, 'border': 0 }); } if( 'end' === self.settings.form_placement ) { $( form_selector ).css({ 'height': 0, 'opacity': 0, 'overflow': 'hidden', 'visibility': 'hidden', 'pointer-events': 'none', 'margin': 0, 'padding': 0, 'border': 0 }); } } }, init_poll_form: function() { var self = this, $fieldset = this.$el.find( 'fieldset' ), $selection = this.$el.find( '.forminator-radio input' ), $input = this.$el.find( '.forminator-input' ), $field = $input.closest( '.forminator-field' ) ; // Load input states FUI.inputStates( $input ); // Show input when option has been selected $selection.on( 'click', function() { // Reset $field.addClass( 'forminator-hidden' ); $field.attr( 'aria-hidden', 'true' ); $input.removeAttr( 'tabindex' ); $input.attr( 'name', '' ); var checked = this.checked, $id = $( this ).attr( 'id' ), $name = $( this ).attr( 'name' ) ; // Once an option has been chosen, remove error class. $fieldset.removeClass( 'forminator-has_error' ); if ( self.$el.find( '.forminator-input#' + $id + '-extra' ).length ) { var $extra = self.$el.find( '.forminator-input#' + $id + '-extra' ), $extraField = $extra.closest( '.forminator-field' ) ; if ( checked ) { $extra.attr( 'name', $name + '-extra' ); $extraField.removeClass( 'forminator-hidden' ); $extraField.removeAttr( 'aria-hidden' ); $extra.attr( 'tabindex', '-1' ); $extra.focus(); } else { $extraField.addClass( 'forminator-hidden' ); $extraField.attr( 'aria-hidden', 'true' ); $extra.removeAttr( 'tabindex' ); } } return true; }); // Disable options if ( this.$el.hasClass( 'forminator-poll-disabled' ) ) { this.$el.find( '.forminator-radio' ).each( function() { $( this ).addClass( 'forminator-disabled' ); $( this ).find( 'input' ).attr( 'disabled', true ); }); } }, init_quiz_form: function () { var self = this, lead_placement = 'undefined' !== typeof self.settings.form_placement ? self.settings.form_placement : '', quiz_id = 'undefined' !== typeof self.settings.quiz_id ? self.settings.quiz_id : 0; this.$el.find('.forminator-button:not(.forminator-quiz-start)').each(function () { $(this).prop("disabled", true); }); this.$el.find('.forminator-answer input').each(function () { $(this).attr('checked', false); }); this.$el.find('.forminator-result--info button').on('click', function () { location.reload(); }); $('#forminator-quiz-leads-' + quiz_id + ' .forminator-quiz-intro .forminator-quiz-start').on('click', function(e){ e.preventDefault(); $(this).closest( '.forminator-quiz-intro').hide(); self.$el.prepend('') .find('.forminator-quiz-start').trigger('click').remove(); }); this.$el.on('click', '.forminator-quiz-start', function (e) { e.preventDefault(); self.$el.find('.forminator-quiz-intro').hide(); self.$el.find('.forminator-pagination').removeClass('forminator-hidden'); //initiate pagination var args = { totalSteps: self.$el.find('.forminator-pagination').length - 1, //subtract the last step with result step: 0, quiz: true }; if ( self.settings.text_next ) { args.next_button = self.settings.text_next; } if ( self.settings.text_prev ) { args.prev_button = self.settings.text_prev; } if ( self.settings.submit_class ) { args.submitButtonClass = self.settings.submit_class; } $(self.element).forminatorFrontPagination(args); }); if( 'end' !== lead_placement ) { this.$el.find('.forminator-submit-rightaway').on("click", function () { self.$el.submit(); $(this).closest('.forminator-question').find('.forminator-submit-rightaway').addClass('forminator-has-been-disabled').attr('disabled', 'disabled'); }); } if( self.settings.hasLeads ) { if( 'beginning' === lead_placement ) { self.$el.css({ 'height': 0, 'opacity': 0, 'overflow': 'hidden', 'visibility': 'hidden', 'pointer-events': 'none', 'margin': 0, 'padding': 0, 'border': 0 }); } if( 'end' === lead_placement ) { self.$el.closest('div').find('#forminator-module-' + self.settings.leads_id ).css({ 'height': 0, 'opacity': 0, 'overflow': 'hidden', 'visibility': 'hidden', 'pointer-events': 'none', 'margin': 0, 'padding': 0, 'border': 0 }); $('#forminator-quiz-leads-' + quiz_id + ' .forminator-lead-form-skip' ).hide(); } } this.$el.on('click', '.forminator-social--icon a', function (e) { e.preventDefault(); var social = $(this).data('social'), url = $(this).closest('.forminator-social--icons').data('url'), message = $(this).closest('.forminator-social--icons').data('message'), message = encodeURIComponent(message), social_shares = { 'facebook': 'https://www.facebook.com/sharer/sharer.php?u=' + url + '"e=' + message, 'twitter': 'https://twitter.com/intent/tweet?&url=' + url + '&text=' + message, 'google': 'https://plus.google.com/share?url=' + url, 'linkedin': 'https://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + message }; if (social_shares[social] !== undefined) { var newwindow = window.open(social_shares[social], social, 'height=' + $(window).height() + ',width=' + $(window).width()); if (window.focus) { newwindow.focus(); } return false; } }); this.$el.on('change', '.forminator-answer input', function (e) { var paginated = !!$( this ).closest('.forminator-pagination').length, parent = paginated ? $( this ).closest('.forminator-pagination') : self.$el, count = parent.find('.forminator-answer input:checked').length, amount_answers = parent.find('.forminator-question').length, parentQuestion = $( this ).closest( '.forminator-question' ), isMultiChoice = parentQuestion.data( 'multichoice' ) ; self.$el.find('.forminator-button:not(.forminator-button-back)').each(function () { var disabled = count < amount_answers; $( this ).prop('disabled', disabled); if ( paginated ) { if ( disabled ) { $( this ).addClass('forminator-disabled'); } else { $( this ).removeClass('forminator-disabled'); } } }); // If multichoice is false, uncheck other options if( this.checked && false === isMultiChoice ) { parentQuestion .find( '.forminator-answer' ) .not( $( this ).parent( '.forminator-answer' ) ) .each( function( i, el ){ $( el ).find( '> input' ).prop( 'checked', false ); }); } }); }, small_form: function () { var form = $( this.element ), formWidth = form.width() ; if ( 783 < Math.max( document.documentElement.clientWidth, window.innerWidth || 0 ) ) { if ( form.hasClass( 'forminator-size--small' ) ) { if ( 480 < formWidth ) { form.removeClass( 'forminator-size--small' ); } } else { var hasHustle = form.closest('.hustle-content'); if ( form.is(":visible") && 480 >= formWidth && ! hasHustle.length ) { form.addClass( 'forminator-size--small' ); } } } }, init_intlTelInput_validation: function ( form_selector ) { var form = $( form_selector ), is_material = form.is('.forminator-design--material'), fields = form.find('.forminator-field--phone'); fields.each(function () { // Initialize intlTelInput plugin on each field with "format check" enabled and // set to check either "international" or "standard" phones. var self = this, is_national_phone = $(this).data('national_mode'), country = $(this).data('country'), validation = $(this).data('validation'); if ('undefined' !== typeof (is_national_phone)) { if (is_material) { //$(this).unwrap('.forminator-input--wrap'); } var args = { nationalMode: ('enabled' === is_national_phone) ? true : false, initialCountry: 'undefined' !== typeof ( country ) ? country : 'us', utilsScript: window.ForminatorFront.cform.intlTelInput_utils_script, }; if ( 'undefined' !== typeof ( validation ) && 'standard' === validation ) { args.allowDropdown = false; } // stop from removing country code. if ( 'undefined' !== typeof ( validation ) && 'international' === validation ) { args.autoHideDialCode = false; } var iti = $(this).intlTelInput(args); if ( 'undefined' !== typeof ( validation ) && 'international' === validation ) { var dial_code = $(this).intlTelInput( 'getSelectedCountryData' ).dialCode, country_code = '+' + dial_code; if ( country_code !== $(this).val() ) { var phone_value = $(this).val().trim().replace( dial_code, '' ).replace( '+', '' ); $(this).val( country_code + phone_value ); } } if ( 'undefined' !== typeof ( validation ) && 'standard' === validation ) { // Reset country to default if changed and invalid previously. $( this ).on( 'blur', function() { if ( '' === $( self ).val() ) { iti.intlTelInput( 'setCountry', country ); form.validate().element( $( self ) ); } }); } // Use libphonenumber to format the telephone number. $(this).on('input', function() { var countryData = $( self ).intlTelInput( 'getSelectedCountryData' ); var regionCode = (countryData && countryData.iso2) ? countryData.iso2.toUpperCase() : ''; // return if no region code is present if('' === regionCode) { return } var phoneNumber = $(this).val(); var isValidLength = libphonenumber.validatePhoneNumberLength(phoneNumber, regionCode) !== 'TOO_LONG'; if(!isValidLength) { // Prevent further typing when the number exceeds the maximum length $(this).val(phoneNumber.slice(0, phoneNumber.length - 1)); } else { var formatter = new libphonenumber.AsYouType(regionCode); var formattedNumber = formatter.input(phoneNumber); $(this).val(formattedNumber); } }); if ( ! is_material ) { $(this).closest( '.forminator-field' ).find( 'div.iti' ).addClass( 'forminator-phone' ); } else { $(this).closest( '.forminator-field' ).find( 'div.iti' ).addClass( 'forminator-input-with-phone' ); if ( $(this).closest( '.forminator-field' ).find( 'div.iti' ).hasClass( 'iti--allow-dropdown' ) ) { $(this).closest( '.forminator-field' ).find( '.forminator-label' ).addClass( 'iti--allow-dropdown' ); } } // intlTelInput plugin adds a markup that's not compatible with 'material' theme when 'allowDropdown' is true (default). // If we're going to allow users to disable the dropdown, this should be adjusted accordingly. if (is_material) { //$(this).closest('.intl-tel-input.allow-dropdown').addClass('forminator-phone-intl').removeClass('intl-tel-input'); //$(this).wrap('
'); } } }); }, reint_intlTelInput: function () { var self = this; self.$el.on( 'after:forminator:form:submit', function (e, data) { self.init_intlTelInput_validation( self.forminator_selector ); } ); }, init_fui: function ( form_selector ) { var form = $( form_selector ), input = form.find( '.forminator-input' ), textarea = form.find( '.forminator-textarea' ), select2 = form.find( '.forminator-select2' ), multiselect = form.find( '.forminator-multiselect' ), stripe = form.find( '.forminator-stripe-element' ), slider = form.find( '.forminator-slider' ) ; var isDefault = ( form.attr( 'data-design' ) === 'default' ), isBold = ( form.attr( 'data-design' ) === 'bold' ), isFlat = ( form.attr( 'data-design' ) === 'flat' ), isMaterial = ( form.attr( 'data-design' ) === 'material' ) ; if ( input.length ) { input.each( function() { FUI.inputStates( this ); }); } if ( textarea.length ) { textarea.each( function() { FUI.textareaStates( this ); }); } if ( 'function' === typeof FUI.select2 ) { FUI.select2( select2.length ); } if ( 'function' === typeof FUI.slider ) { FUI.slider(); } if ( multiselect.length ) { FUI.multiSelectStates( multiselect ); } if ( form.hasClass( 'forminator-design--material' ) ) { if ( input.length ) { input.each( function() { FUI.inputMaterial( this ); }); } if ( textarea.length ) { textarea.each( function() { FUI.textareaMaterial( this ); }); } if ( stripe.length ) { stripe.each( function() { var field = $(this).closest('.forminator-field'); var label = field.find('.forminator-label'); if (label.length) { field.addClass('forminator-stripe-floating'); // Add floating class label.addClass('forminator-floating--input'); } }); } } }, responsive_captcha: function ( form_selector ) { $( form_selector ).find('.forminator-g-recaptcha').each(function () { var badge = $(this).data('badge'); // eslint-disable-line if ($(this).is(':visible') && 'inline' === badge ) { var width = $(this).parent().width(), scale = 1; if (width < 302) { scale = width / 302; } $(this).css('transform', 'scale(' + scale + ')'); $(this).css('-webkit-transform', 'scale(' + scale + ')'); $(this).css('transform-origin', '0 0'); $(this).css('-webkit-transform-origin', '0 0'); } }); }, init_pagination: function ( form_selector ) { var self = this, num_pages = $( form_selector ).find(".forminator-pagination").length, hash = window.location.hash, hashStep = false, step = 0; if (num_pages > 0) { //find from hash if (typeof hash !== "undefined" && hash.indexOf('step-') >= 0) { hashStep = true; step = hash.substr(6, 8); } $(this.element).forminatorFrontPagination({ totalSteps: num_pages, hashStep: hashStep, step: step, inline_validation: self.settings.inline_validation, submitButtonClass: self.settings.submit_button_class }); } }, activate_field: function () { var form = $( this.element ); var input = form.find( '.forminator-input' ); var textarea = form.find( '.forminator-textarea' ); function classFilled( el ) { var element = $( el ); var elementValue = element.val().trim(); var elementField = element.closest( '.forminator-field' ); var elementAnswer = element.closest( '.forminator-poll--answer' ); var filledClass = 'forminator-is_filled'; if ( '' !== elementValue ) { elementField.addClass( filledClass ); elementAnswer.addClass( filledClass ); } else { elementField.removeClass( filledClass ); elementAnswer.removeClass( filledClass ); } element.change( function( e ) { if ( '' !== elementValue ) { elementField.addClass( filledClass ); elementAnswer.addClass( filledClass ); } else { elementField.removeClass( filledClass ); elementAnswer.removeClass( filledClass ); } e.stopPropagation(); }); } function classHover( el ) { var element = $( el ); var elementField = element.closest( '.forminator-field' ); var elementAnswer = element.closest( '.forminator-poll--answer' ); var hoverClass = 'forminator-is_hover'; element.on( 'mouseover', function( e ) { elementField.addClass( hoverClass ); elementAnswer.addClass( hoverClass ); e.stopPropagation(); }).on( 'mouseout', function( e ) { elementField.removeClass( hoverClass ); elementAnswer.removeClass( hoverClass ); e.stopPropagation(); }); } function classActive( el ) { var element = $( el ); var elementField = element.closest( '.forminator-field' ); var elementAnswer = element.closest( '.forminator-poll--answer' ); var activeClass = 'forminator-is_active'; element.focus( function( e ) { elementField.addClass( activeClass ); elementAnswer.addClass( activeClass ); e.stopPropagation(); }).blur( function( e ) { elementField.removeClass( activeClass ); elementAnswer.removeClass( activeClass ); e.stopPropagation(); }); } function classError( el ) { var element = $( el ); var elementValue = element.val().trim(); var elementField = element.closest( '.forminator-field' ); var elementTime = element.attr( 'data-field' ); var timePicker = element.closest( '.forminator-timepicker' ); var timeColumn = timePicker.parent(); var errorField = elementField.find( '.forminator-error-message' ); var errorClass = 'forminator-has_error'; element.on( 'load change keyup keydown', function( e ) { if ( 'undefined' !== typeof elementTime && false !== elementTime ) { if ( 'hours' === element.data( 'field' ) ) { var hoursError = timeColumn.find( '.forminator-error-message[data-error-field="hours"]' ); if ( '' !== elementValue && 0 !== hoursError.length ) { hoursError.remove(); } } if ( 'minutes' === element.data( 'field' ) ) { var minutesError = timeColumn.find( '.forminator-error-message[data-error-field="minutes"]' ); if ( '' !== elementValue && 0 !== minutesError.length ) { minutesError.remove(); } } } else { if ( '' !== elementValue && errorField.text() ) { errorField.remove(); elementField.removeClass( errorClass ); } } e.stopPropagation(); }); } if ( input.length ) { input.each( function() { //classFilled( this ); //classHover( this ); //classActive( this ); classError( this ); }); } if ( textarea.length ) { textarea.each( function() { //classFilled( this ); //classHover( this ); //classActive( this ); classError( this ); }); } form.find('select.forminator-select2 + .forminator-select').each(function () { var $select = $(this); // Set field active class on hover $select.on('mouseover', function (e) { e.stopPropagation(); $(this).closest('.forminator-field').addClass('forminator-is_hover'); }).on('mouseout', function (e) { e.stopPropagation(); $(this).closest('.forminator-field').removeClass('forminator-is_hover'); }); // Set field active class on focus $select.on('click', function (e) { e.stopPropagation(); checkSelectActive(); if ($select.hasClass('select2-container--open')) { $(this).closest('.forminator-field').addClass('forminator-is_active'); } else { $(this).closest('.forminator-field').removeClass('forminator-is_active'); } }); }); function checkSelectActive() { if (form.find('.select2-container').hasClass('select2-container--open')) { setTimeout(checkSelectActive, 300); } else { form.find('.select2-container').closest('.forminator-field').removeClass('forminator-is_active'); } } }, field_counter: function ( form_selector ) { var form = $( form_selector ), submit_button = form.find('.forminator-button-submit'); form.find('.forminator-input, .forminator-textarea').each(function () { var $input = $(this), numwords = 0, count = 0; $input.on('keydown', function (e) { if ( ! $(this).hasClass('forminator-textarea') && e.keyCode === 13 ) { e.preventDefault(); if ( submit_button.is(":visible") ) { submit_button.trigger('click'); } return false; } }); $input.on('change keyup keydown', function (e) { e.stopPropagation(); var $field = $(this).closest('.forminator-col'), $limit = $field.find('.forminator-description span'), fieldVal = sanitize_text_field( $(this).val() ) ; if ($limit.length) { if ($limit.data('limit')) { var field_value = fieldVal.replace( /<[^>]*>/g, '' ); if ($limit.data('type') !== "words") { count = $( '
' + field_value + '
' ).text().length; } else { count = field_value.trim().split(/\s+/).length; // Prevent additional words from being added when limit is reached. numwords = field_value.trim().split(/\s+/).length; if ( numwords >= $limit.data( 'limit' ) ) { // Allow to delete and backspace when limit is reached. if( e.which === 32 ) { e.preventDefault(); } } } $limit.html(count + ' / ' + $limit.data('limit')); } } }); }); }, field_number: function ( form_selector ) { // var form = $(this.element); // form.find('input[type=number]').on('change keyup', function () { // if( ! $(this).val().match(/^\d+$/) ){ // var sanitized = $(this).val().replace(/[^0-9]/g, ''); // $(this).val(sanitized); // } // }); var form = $( form_selector ); form.find('input[type=number]').each(function () { $(this).keypress(function (e) { var i; var allowed = [44, 45, 46]; var key = e.which; for (i = 48; i < 58; i++) { allowed.push(i); } if (!(allowed.indexOf(key) >= 0)) { e.preventDefault(); } }); }); form.find('.forminator-number--field, .forminator-currency, .forminator-calculation').each(function () { var inputType = $( this ).attr( 'type' ); if ( 'number' === inputType ) { var decimals = $( this ).data( 'decimals' ); $( this ).change( function ( e ) { this.value = parseFloat( this.value ).toFixed( decimals ); }); $( this ).trigger( 'change' ); } /* * If you need to retrieve the formatted (masked) value, you can use something like this: * $element.inputmask({'autoUnmask' : false}); * var value = $element.val(); * $element.inputmask({'autoUnmask' : true}); */ $( this ).inputmask({ 'alias': 'decimal', 'rightAlign': false, 'digitsOptional': false, 'showMaskOnHover': false, 'autoUnmask' : true, // Automatically unmask the value when retrieved - this prevents the "Maximum call stack size exceeded" console error that happens in some forms that contain number/calculation fields with localized masks. 'removeMaskOnSubmit': true, }); }); // Fixes the 2nd number input bug: https://incsub.atlassian.net/browse/FOR-3033 form.find( 'input[type=number]' ).on( 'mouseout', function() { $( this ).trigger( 'blur' ); }); }, field_time: function () { var self = this; $('.forminator-input-time').on('input', function (e) { var $this = $(this), value = $this.val() ; // Allow only 2 digits for time fields if (value && value.length >= 2) { $this.val(value.substr(0, 2)); } }); // Apply time limits. this.$el.find( '.forminator-timepicker' ).each( function( i, el ) { var $tp = $( el ), start = $tp.data( 'start-limit' ), end = $tp.data( 'end-limit' ) ; if ( 'undefined' !== typeof start && 'undefined' !== typeof end ) { var hourSelect = $tp.find( '.time-hours' ), initHours = hourSelect.html() ; // Reset right away. self.resetTimePicker( $tp, start, end ); // Reset onchange. $tp.find( '.time-ampm' ).on( 'change', function() { hourSelect.val(''); hourSelect.html( initHours ); self.resetTimePicker( $tp, start, end ); setTimeout( function() { $tp.find( '.forminator-field' ).removeClass( 'forminator-has_error' ); }, 10 ); }); } }); }, // Remove hour options that are outside the limits. resetTimePicker: function ( timePicker, start, end ) { var meridiem = timePicker.find( '.time-ampm' ), [ startTime, startModifier ] = start.split(' '), [ startHour, startMinute ] = startTime.split(':'), startHour = parseInt( startHour ), [ endTime, endModifier ] = end.split(' '), [ endHour, endMinute ] = endTime.split(':'), endHour = parseInt( endHour ) ; if ( startModifier === endModifier ) { meridiem.find( 'option[value!="' + endModifier + '"]' ).remove(); } timePicker.find( '.time-hours' ).children().each( function( optionIndex, optionEl ) { var optionValue = parseInt( optionEl.value ); if ( '' !== optionValue && ( optionValue < startHour || ( 0 !== startHour && 12 === optionValue ) ) && meridiem.val() === startModifier ) { optionEl.remove(); } if ( '' !== optionValue && optionValue > endHour && 12 !== optionValue && meridiem.val() === endModifier ) { optionEl.remove(); } }); }, init_login_2FA: function () { var self = this; this.two_factor_providers( 'totp' ); $('body').on('click', '.forminator-2fa-link', function () { self.$el.find('#login_error').remove(); self.$el.find('.notification').empty(); var slug = $(this).data('slug'); self.two_factor_providers( slug ); if ('fallback-email' === slug) { self.resend_code(); } }); this.$el.find('.wpdef-2fa-email-resend input').on('click', function () { self.resend_code(); }); }, two_factor_providers: function ( slug ) { var self = this; self.$el.find('.forminator-authentication-box').hide(); self.$el.find('.forminator-authentication-box input').attr( 'disabled', true ); self.$el.find( '#forminator-2fa-' + slug ).show(); self.$el.find( '#forminator-2fa-' + slug + ' input' ).attr( 'disabled', false ); if ( self.$el.find('.forminator-2fa-link').length > 0 ) { self.$el.find('.forminator-2fa-link').hide(); self.$el.find('.forminator-2fa-link:not(#forminator-2fa-link-'+ slug +')').each(function() { self.$el.find('.forminator-auth-method').val( slug ); $( this ).find('input').attr( 'disabled', false ); $( this ).show(); }); } }, // Logic for FallbackEmail method. resend_code: function () { // Work with the button 'Resen Code'. var self = this; var that = $('input[name="button_resend_code"]'); var token = $('.forminator-auth-token'); let data = { action: 'forminator_2fa_fallback_email', data: JSON.stringify({ 'token': token }) }; $.ajax({ type: 'POST', url: window.ForminatorFront.ajaxUrl, data: data, beforeSend: function () { that.attr('disabled', 'disabled'); $('.def-ajaxloader').show(); }, success: function (data) { that.removeAttr('disabled'); $('.def-ajaxloader').hide(); $('.notification').text(data.data.message); } }) }, material_field: function () { /* var form = $(this.element); if (form.is('.forminator-design--material')) { var $input = form.find('.forminator-input--wrap'), $textarea = form.find('.forminator-textarea--wrap'), $date = form.find('.forminator-date'), $product = form.find('.forminator-product'); var $navigation = form.find('.forminator-pagination--nav'), $navitem = $navigation.find('li'); $('').insertAfter($navitem); $input.prev('.forminator-field--label').addClass('forminator-floating--input'); $input.closest('.forminator-phone-intl').prev('.forminator-field--label').addClass('forminator-floating--input'); $textarea.prev('.forminator-field--label').addClass('forminator-floating--textarea'); if ($date.hasClass('forminator-has_icon')) { $date.prev('.forminator-field--label').addClass('forminator-floating--date'); } else { $date.prev('.forminator-field--label').addClass('forminator-floating--input'); } } */ }, toggle_file_input: function() { var $form = $( this.element ); $form.find( '.forminator-file-upload' ).each( function() { var $field = $( this ); var $input = $field.find( 'input' ); var $remove = $field.find( '.forminator-button-delete' ); // Toggle remove button depend on input value if ( '' !== $input.val() ) { $remove.show(); // Show remove button } else { $remove.hide(); // Hide remove button } }); }, upload_field: function ( form_selector ) { var self = this, form = $( form_selector ) ; // Toggle file remove button this.toggle_file_input(); // Handle remove file button click form.find( '.forminator-button-delete' ).on('click', function (e) { e.preventDefault(); var $self = $( this ), $input = $self.siblings('input'), $label = $self.closest( '.forminator-file-upload' ).find('> span') ; // Cleanup $input.val(''); $label.html( $label.data( 'empty-text' ) ); $self.hide(); }); form.find( '.forminator-input-file, .forminator-input-file-required' ).on('change', function () { var $nameLabel = $(this).closest( '.forminator-file-upload' ).find( '> span' ), vals = $(this).val(), val = vals.length ? vals.split('\\').pop() : '' ; $nameLabel.text(val); self.toggle_file_input(); }); form.find( '.forminator-button-upload' ).off(); form.find( '.forminator-button-upload' ).on( 'click', function (e) { e.preventDefault(); var $id = $(this).attr('data-id'), $target = form.find('input#' + $id) ; $target.trigger('click'); }); form.find( '.forminator-input-file, .forminator-input-file-required' ).on('change', function (e) { e.preventDefault(); var $file = $(this)[0].files.length, $remove = $(this).find('.forminator-button-delete'); if ($file === 0) { $remove.hide(); } else { $remove.show(); } }); }, // Remove duplicate fields created by other plugins/themes maybeRemoveDuplicateFields: function ( form_selector ) { var form = $( form_selector ); // Check for Neira Lite theme if ( $( document ).find( "link[id='neira-lite-style-css']" ).length ) { var duplicateSelect = form.find( '.forminator-select-container' ).next( '.chosen-container' ), duplicateSelect2 = form.find( 'select.forminator-select2 + .forminator-select' ).next( '.chosen-container' ), duplicateAddress = form.find( '.forminator-select' ).next( '.chosen-container' ) ; if ( 0 !== duplicateSelect.length ) { duplicateSelect.remove(); } if ( 0 !== duplicateSelect2.length ) { duplicateSelect2.remove(); } if ( 0 !== duplicateAddress.length ) { duplicateAddress.remove(); } } }, renderCaptcha: function (captcha_field) { var self = this; //render captcha only if not rendered if (typeof $(captcha_field).data('forminator-recapchta-widget') === 'undefined') { var size = $(captcha_field).data('size'), data = { sitekey: $(captcha_field).data('sitekey'), theme: $(captcha_field).data('theme'), size: size }; if (size === 'invisible') { data.badge = $(captcha_field).data('badge'); data.callback = function (token) { $(self.element).trigger('submit.frontSubmit'); }; } else { data.callback = function () { $(captcha_field).parent( '.forminator-col' ) .removeClass( 'forminator-has_error' ) .remove( '.forminator-error-message' ); }; } if (data.sitekey !== "") { // noinspection Annotator var widget = window.grecaptcha.render(captcha_field, data); // mark as rendered $(captcha_field).data('forminator-recapchta-widget', widget); this.addCaptchaAria( captcha_field ); this.responsive_captcha(); } } }, renderHcaptcha: function ( captcha_field ) { var self = this; //render hcaptcha only if not rendered if (typeof $( captcha_field ).data( 'forminator-hcaptcha-widget' ) === 'undefined') { var size = $( captcha_field ).data( 'size' ), data = { sitekey: $( captcha_field ).data( 'sitekey' ), theme: $( captcha_field ).data( 'theme' ), size: size }; if ( size === 'invisible' ) { data.callback = function ( token ) { $( self.element ).trigger( 'submit.frontSubmit' ); }; } else { data.callback = function () { $( captcha_field ).parent( '.forminator-col' ) .removeClass( 'forminator-has_error' ) .remove( '.forminator-error-message' ); }; } if ( data.sitekey !== "" ) { // noinspection Annotator var widgetId = hcaptcha.render( captcha_field, data ); // mark as rendered $( captcha_field ).data( 'forminator-hcaptcha-widget', widgetId ); // this.addCaptchaAria( captcha_field ); // this.responsive_captcha(); } } }, addCaptchaAria: function ( captcha_field ) { var gRecaptchaResponse = $( captcha_field ).find( '.g-recaptcha-response' ), gRecaptcha = $( captcha_field ).find( '>div' ); if ( 0 !== gRecaptchaResponse.length ) { gRecaptchaResponse.attr( "aria-hidden", "true" ); gRecaptchaResponse.attr( "aria-label", "do not use" ); gRecaptchaResponse.attr( "aria-readonly", "true" ); } if ( 0 !== gRecaptcha.length ) { gRecaptcha.css( 'z-index', 99 ); } }, hide: function () { this.$el.hide(); }, /** * Return JSON object if possible * * We tried our best here * if there is an error/exception, it will return empty object/array * * @param string * @param type ('array'/'object') */ maybeParseStringToJson: function (string, type) { var object = {}; // already object if (typeof string === 'object') { return string; } if (type === 'object') { string = '{' + string.trim() + '}'; } else if (type === 'array') { string = '[' + string.trim() + ']'; } else { return {}; } try { // remove trailing comma, duh /** * find `,`, after which there is no any new attribute, object or array. * New attribute could start either with quotes (" or ') or with any word-character (\w). * New object could start only with character {. * New array could start only with character [. * New attribute, object or array could be placed after a bunch of space-like symbols (\s). * * Feel free to hack this regex if you got better idea * @type {RegExp} */ var trailingCommaRegex = /\,(?!\s*?[\{\[\"\'\w])/g; string = string.replace(trailingCommaRegex, ''); object = JSON.parse(string); } catch (e) { console.error(e.message); if (type === 'object') { object = {}; } else if (type === 'array') { object = []; } } return object; }, /** * Render Stripe once it's available * * @param string * @param type ('array'/'object') */ renderStripe: function( form, stripe_payment, stripeLoadCounter = 0 ) { var self = this; setTimeout( function() { stripeLoadCounter++; if ( 'undefined' !== typeof Stripe ) { $( form.element ).forminatorFrontPayment({ type: 'stripe', paymentEl: stripe_payment, paymentRequireSsl: form.settings.payment_require_ssl, generalMessages: form.settings.general_messages, has_loader: form.settings.has_loader, loader_label: form.settings.loader_label, }); // Retry checking for 30 seconds } else if ( stripeLoadCounter < 300 ) { self.renderStripe( form, stripe_payment, stripeLoadCounter ); } else { console.error( 'Failed to load Stripe.' ); } }, 100 ); }, // Enable save draft button once a change is made maybe_enable_save_draft: function ( $saveDraft, initialData ) { var changedData = this.$el.serializeArray(), hasChanged = false, hasSig = this.$el.find( '.forminator-field-signature' ).length ? true : false ; // Remove signature field from changedData, will process later changedData = changedData.filter( function( val ) { return val.name.indexOf( 'ctlSignature' ) === -1 ; }); initialData = JSON.stringify( initialData ); changedData = JSON.stringify( changedData ); // Check for field changes if ( initialData !== changedData ) { hasChanged = true; } // Check for signature change if ( hasSig && false === hasChanged ) { this.$el.find( '.forminator-field-signature' ).each( function(e) { var sigPrefix = $( this ).find( '.signature-prefix' ).val(); if ( 0 !== $( this ).find( '#ctlSignature' + sigPrefix + '_data' ).length && '' !== $( this ).find( '#ctlSignature' + sigPrefix + '_data' ).val() ) { hasChanged = true; return false; } }); } if ( hasChanged ) { $saveDraft.removeClass( 'disabled' ); } else { $saveDraft.addClass( 'disabled' ); } }, handleDiviPopup: function () { var self = this; if ( 'undefined' !== typeof DiviArea ) { DiviArea.addAction( 'show_area', function( area ) { setTimeout( function() { self.init(); forminatorSignInit(); forminatorSignatureResize(); }, 100 ); }); } }, disableFields: function () { this.$el.addClass( 'forminator-fields-disabled' ); }, // Check if Complianz has added a blocker for reCaptcha. checkComplianzBlocker: function () { var complianzBlocker = this.$el.find( '.cmplz-blocked-content-container' ); if ( complianzBlocker.length > 0 ) { var row = complianzBlocker.closest( '.forminator-row' ); this.disableFields(); row.insertBefore( this.$el.find( '.forminator-row' ).first() ); row.css({ 'pointer-events': 'all', 'opacity': '1' }); row.find( '*' ).css( 'pointer-events', 'all' ); // For paginated. if ( row.closest( '.forminator-pagination--content' ).length > 0 ) { row.closest( '.forminator-pagination--content' ).css({ 'pointer-events': 'all', 'opacity': '1' }); row.nextAll( '.forminator-row' ).css({ 'opacity': '0.5' }); } // Reload window if accepted. $( 'body' ).on( 'click', '.cmplz-blocked-content-notice, .cmplz-accept', function() { setTimeout( function() { window.location.reload(); }, 50 ); }); } }, }); // A really lightweight plugin wrapper around the constructor, // preventing against multiple instantiations $.fn[pluginName] = function (options) { return this.each(function () { if (!$.data(this, pluginName)) { $.data(this, pluginName, new ForminatorFront(this, options)); } }); }; // hook from wp_editor tinymce $(document).on('tinymce-editor-init', function (event, editor) { var editor_id = editor.id, $field = $('#' + editor_id ).closest('.forminator-col') ; // trigger editor change to save value to textarea, // default wp tinymce textarea update only triggered when submit var count = 0; editor.on('change', function () { // only forminator if ( -1 !== editor_id.indexOf( 'forminator-field-textarea-' ) ) { editor.save(); $field.find( '#' + editor_id ).trigger( 'change' ); } if ( -1 !== editor_id.indexOf( 'forminator-field-post-content-' ) ) { editor.save(); $field.find( '#' + editor_id ).trigger( 'change' ); } }); // Trigger onblur. editor.on( 'blur', function () { // only forminator if ( -1 !== editor_id.indexOf( 'forminator-field-textarea-' ) || -1 !== editor_id.indexOf( 'forminator-field-post-content-' ) ) { $field.find( '#' + editor_id ).valid(); } }); // Make the visual editor and html editor the same height if ( $( '#' + editor.id + '_ifr' ).is( ':visible' ) ) { $( '#' + editor.id + '_ifr' ).height( $( '#' + editor.id ).height() ); } // Add aria-describedby. if ( -1 !== editor_id.indexOf( 'forminator' ) ) { $( '#' + editor_id ).closest( '.wp-editor-wrap' ).attr( 'aria-describedby', editor_id + '-description' ); } }); $( document ).on( 'click', '.forminator-copy-btn', function( e ) { forminatorCopyTextToClipboard( $( this ).prev( '.forminator-draft-link' ).val() ); if ( ! $( this ).hasClass( 'copied' ) ) { $( this ).addClass( 'copied' ) $( this ).prepend( '✓ ' ); } } ); // Copy: Async + Fallback // https://stackoverflow.com/a/30810322 function forminatorFallbackCopyTextToClipboard( text ) { var textArea = document.createElement("textarea"); textArea.value = text; // Avoid scrolling to bottom textArea.style.top = "0"; textArea.style.left = "0"; textArea.style.position = "fixed"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; // console.log('Fallback: Copying text command was ' + msg); } catch (err) { // console.error('Fallback: Oops, unable to copy', err); } document.body.removeChild(textArea); } function forminatorCopyTextToClipboard (text ) { if (!navigator.clipboard) { forminatorFallbackCopyTextToClipboard(text); return; } navigator.clipboard.writeText(text).then(function() { // console.log('Async: Copying to clipboard was successful!'); }, function(err) { // console.error('Async: Could not copy text: ', err); }); } // Focus to nearest input when label is clicked function focus_to_nearest_input() { $( '.forminator-custom-form' ).find( '.forminator-label' ).on( 'click', function ( e ) { e.preventDefault(); var fieldLabel = $( this ); fieldLabel.next( '#' + fieldLabel.attr( 'for' ) ).focus(); }); } focus_to_nearest_input(); $( document ).on( 'after.load.forminator', focus_to_nearest_input ); // Elementor Popup show event jQuery( document ).on( 'elementor/popup/show', () => { forminator_render_captcha(); forminator_render_hcaptcha(); } ); /** * Sanitize the user input string. * * @param {string} string */ function sanitize_text_field( string ) { if ( typeof string === 'string') { var str = String(string).replace(/[&\/\\#^+()$~%.'":*?<>{}!@]/g, ''); return str.trim(); } return string; } })(jQuery, window, document); // noinspection JSUnusedGlobalSymbols var forminator_render_captcha = function () { // TODO: avoid conflict with another plugins that provide recaptcha // notify forminator front that grecaptcha has loaded and can be used jQuery('.forminator-g-recaptcha').each(function () { // find closest form var thisCaptcha = jQuery(this), form = thisCaptcha.closest('form'); if ( form.length > 0 && '' === thisCaptcha.html() ) { window.setTimeout( function() { var forminatorFront = form.data( 'forminatorFront' ); if ( typeof forminatorFront !== 'undefined' ) { forminatorFront.renderCaptcha( thisCaptcha[0] ); } }, 100 ); } }); }; // noinspection JSUnusedGlobalSymbols var forminator_render_hcaptcha = function () { // TODO: avoid conflict with another plugins that provide hcaptcha // notify forminator front that hcaptcha has loaded and can be used jQuery('.forminator-hcaptcha').each(function () { // find closest form var thisCaptcha = jQuery(this), form = thisCaptcha.closest('form'); if ( form.length > 0 && '' === thisCaptcha.html() ) { window.setTimeout( function() { var forminatorFront = form.data( 'forminatorFront' ); if ( typeof forminatorFront !== 'undefined' ) { forminatorFront.renderHcaptcha( thisCaptcha[0] ); } }, 100 ); } }); }; // Source: http://stackoverflow.com/questions/497790 var forminatorDateUtil = { month_number: function( v ) { var months_short = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']; var months_full = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december']; if( v.constructor === Number ) { return v; } var n = NaN; if( v.constructor === String ) { v = v.toLowerCase(); var index = months_short.indexOf( v ); if( index === -1 ) { index = months_full.indexOf( v ); } n = ( index === -1 ) ? NaN : index; } return n; }, convert: function( d ) { // Converts the date in d to a date-object. The input can be: // a date object: returned without modification // an array : Interpreted as [year,month,day]. NOTE: month is 0-11. // a number : Interpreted as number of milliseconds // since 1 Jan 1970 (a timestamp) // a string : Any format supported by the javascript engine, like // "YYYY/MM/DD", "MM/DD/YYYY", "Jan 31 2009" etc. // an object : Interpreted as an object with year, month and date // attributes. **NOTE** month is 0-11. return ( d.constructor === Date ? d : d.constructor === Array ? new Date( d[0], this.month_number( d[1] ), d[2] ) : jQuery.isNumeric( d ) ? new Date( 1 * d ) : d.constructor === Number ? new Date( d ) : d.constructor === String ? new Date( d ) : typeof d === "object" ? new Date( d.year, this.month_number( d.month ), d.date ) : NaN ); }, compare: function( a, b ) { // Compare two dates (could be of any type supported by the convert // function above) and returns: // -1 : if a < b // 0 : if a = b // 1 : if a > b // NaN : if a or b is an illegal date // NOTE: The code inside isFinite does an assignment (=). return ( isFinite( a = this.convert( a ).valueOf() ) && isFinite( b = this.convert( b ).valueOf() ) ? ( a > b ) - ( a < b ) : NaN ); }, inRange: function( d, start, end ) { // Checks if date in d is between dates in start and end. // Returns a boolean or NaN: // true : if d is between start and end (inclusive) // false : if d is before start or after end // NaN : if one or more of the dates is illegal. // NOTE: The code inside isFinite does an assignment (=). return ( isFinite( d = this.convert( d ).valueOf() ) && isFinite( start = this.convert( start ).valueOf() ) && isFinite( end = this.convert( end ).valueOf() ) ? start <= d && d <= end : NaN ); }, diffInDays: function( d1, d2 ) { d1 = this.convert( d1 ); d2 = this.convert( d2 ); if( typeof d1.getMonth !== 'function' || typeof d2.getMonth !== 'function' ) { return NaN; } var t2 = d2.getTime(); var t1 = d1.getTime(); return parseFloat((t2-t1)/(24*3600*1000)); }, diffInWeeks: function( d1, d2 ) { d1 = this.convert( d1 ); d2 = this.convert( d2 ); if( typeof d1.getMonth !== 'function' || typeof d2.getMonth !== 'function' ) { return NaN; } var t2 = d2.getTime(); var t1 = d1.getTime(); return parseInt((t2-t1)/(24*3600*1000*7)); }, diffInMonths: function( d1, d2 ) { d1 = this.convert( d1 ); d2 = this.convert( d2 ); if( typeof d1.getMonth !== 'function' || typeof d2.getMonth !== 'function' ) { return NaN; } var d1Y = d1.getFullYear(); var d2Y = d2.getFullYear(); var d1M = d1.getMonth(); var d2M = d2.getMonth(); return (d2M+12*d2Y)-(d1M+12*d1Y); }, diffInYears: function( d1, d2 ) { d1 = this.convert( d1 ); d2 = this.convert( d2 ); if( typeof d1.getMonth !== 'function' || typeof d2.getMonth !== 'function' ) { return NaN; } return d2.getFullYear()-d1.getFullYear(); }, }; // the semi-colon before function invocation is a safety net against concatenated // scripts and/or other plugins which may not be closed properly. ;// noinspection JSUnusedLocalSymbols (function ($, window, document, undefined) { "use strict"; // undefined is used here as the undefined global variable in ECMAScript 3 is // mutable (ie. it can be changed by someone else). undefined isn't really being // passed in so we can ensure the value of it is truly undefined. In ES5, undefined // can no longer be modified. // window and document are passed through as local variables rather than global // as this (slightly) quickens the resolution process and can be more efficiently // minified (especially when both are regularly referenced in your plugin). // Create the defaults once var pluginName = "forminatorFrontCalculate", defaults = { forminatorFields: [], generalMessages: {}, }; // The actual plugin constructor function ForminatorFrontCalculate(element, options) { this.element = element; this.$el = $(this.element); // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object // is generally empty as we don't want to alter the default options for // future instances of the plugin this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.calculationFields = []; this.triggerInputs = []; this.isError = false; this.init(); } // Avoid Plugin.prototype conflicts $.extend(ForminatorFrontCalculate.prototype, { init: function () { var self = this; // find calculation fields var calculationInputs = this.$el.find('input.forminator-calculation'); if (calculationInputs.length > 0) { calculationInputs.each(function () { self.calculationFields.push({ $input: $(this), formula: $(this).data('formula'), name: $(this).attr('name'), isHidden: $(this).data('isHidden'), precision: $(this).data('precision'), //separators: $(this).data('separators'), }); // isHidden if ($(this).data('isHidden')) { $(this).closest('.forminator-col').addClass('forminator-hidden forminator-hidden-option'); var rowField = $(this).closest('.forminator-row'); rowField.addClass('forminator-hidden-option'); if (rowField.find('> .forminator-col:not(.forminator-hidden)').length === 0) { rowField.addClass('forminator-hidden'); } } }); var memoizeTime = this.settings.memoizeTime || 300; this.debouncedReCalculateAll = this.debounce(this.recalculateAll, 1000); this.memoizeDebounceRender = this.memoize(this.recalculate, memoizeTime); this.$el.on('forminator:field:condition:toggled', function (e) { self.debouncedReCalculateAll(); }); this.parseCalcFieldsFormula(); this.attachEventToTriggeringFields(); this.debouncedReCalculateAll(); } this.$el.off( 'forminator:recalculate' ).on( 'forminator:recalculate', function() { self.recalculateAll(); } ); }, // Memoize an expensive function by storing its results. memoize: function(func, wait) { var memo = {}; var timeout; var slice = Array.prototype.slice; return function() { var args = slice.call(arguments); var later = function() { timeout = null; memo = {}; }; clearTimeout(timeout); timeout = setTimeout(later, wait); if (args[0].name in memo) { return memo[args[0].name]; } else { return (memo[args[0].name] = func.apply(this, args)); } } }, debounce: function (func, wait, immediate) { var timeout; return function() { var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }, parseCalcFieldsFormula: function () { for (var i = 0; i < this.calculationFields.length; i++) { var calcField = this.calculationFields[i]; var formula = calcField.formula; calcField.formula = formula; this.calculationFields[i] = calcField; } }, findTriggerInputs: function (calcField) { var formula = calcField.formula; var joinedFieldTypes = this.settings.forminatorFields.join('|'); var incrementFieldPattern = "(" + joinedFieldTypes + ")-\\d+"; var pattern = new RegExp('\\{(' + incrementFieldPattern + '(?:-min|-max)?)(\\-[A-Za-z-_]+)?(\\-[A-Za-z0-9-_]+)?\\}', 'g'); formula = this.maybeReplaceCalculationGroups(formula); var matches; while (matches = pattern.exec(formula)) { var fullMatch = matches[0]; var groupSuffix = matches[4] || ''; var inputName = matches[1] + groupSuffix; var fieldType = matches[2]; if (fullMatch === undefined || inputName === undefined || fieldType === undefined) { continue; } var formField = this.get_form_field(inputName); if (!formField.length) { continue; } var calcFields = formField.data('calcFields'); if (calcFields === undefined) { calcFields = []; } var calcFieldAlreadyExist = false; for (var j = 0; j < calcFields.length; j++) { var currentCalcField = calcFields[j]; if (currentCalcField.name === calcField.name) { calcFieldAlreadyExist = true; break; } } if (!calcFieldAlreadyExist) { calcFields.push(calcField); } formField.data('calcFields', calcFields); this.triggerInputs.push(formField); } }, // taken from forminatorFrontCondition get_form_field: function (element_id) { //find element by suffix -field on id input (default behavior) let $form = this.$el; if ( $form.hasClass( 'forminator-grouped-fields' ) ) { $form = $form.closest( 'form.forminator-ui' ); } var $form_id = $form.data( 'form-id' ), $uid = $form.data( 'uid' ), $element = $form.find('#forminator-form-' + $form_id + '__field--' + element_id + '_' + $uid ); if ( $element.length === 0 ) { var $element = $form.find('#' + element_id + '-field' ); if ($element.length === 0) { //find element by its on name (for radio on singlevalue) $element = $form.find('input[name=' + element_id + ']'); if ($element.length === 0) { // for text area that have uniqid, so we check its name instead $element = $form.find('textarea[name=' + element_id + ']'); if ($element.length === 0) { //find element by its on name[] (for checkbox on multivalue) $element = $form.find('input[name="' + element_id + '[]"]'); if ($element.length === 0) { //find element by select name $element = this.$el.find('select[name="' + element_id + '"]'); if ($element.length === 0) { //find element by direct id (for name field mostly) //will work for all field with element_id-[somestring] $element = $form.find('#' + element_id); } } } } } } return $element; }, attachEventToTriggeringFields: function () { var self = this; for (var i = 0; i < this.calculationFields.length; i++) { var calcField = this.calculationFields[i]; this.findTriggerInputs(calcField); } if (this.triggerInputs.length > 0) { var cFields = []; for (var j = 0; j < this.triggerInputs.length; j++) { var $input = this.triggerInputs[j]; var inputId = $input.attr('id'); if (cFields.indexOf(inputId) < 0) { $input.on('change.forminatorFrontCalculate, blur', function () { var calcFields = $(this).data('calcFields'); if (calcFields !== undefined && calcFields.length > 0) { for (var k = 0; k < calcFields.length; k++) { var calcField = calcFields[k]; if(self.field_is_checkbox($(this)) || self.field_is_radio($(this))) { self.recalculate(calcField); } else { self.memoizeDebounceRender(calcField); } } } }); cFields.push(inputId); } } } }, recalculateAll: function () { for (var i = 0; i < this.calculationFields.length; i++) { this.recalculate(this.calculationFields[i]); } }, recalculate: function (calcField) { var $input = calcField.$input; this.hideErrorMessage($input); var formula = this.maybeReplaceFieldOnFormula(calcField.formula); var res = 0; var calc = new window.forminatorCalculator(formula); try { res = calc.calculate(); if (!isFinite(res)) { throw ('Infinity calculation result.'); } } catch (e) { this.isError = true; console.log(e); // override error message this.displayErrorMessage( $input, this.settings.generalMessages.calculation_error ); res = '0'; } // Support cases like 1.005. Correct result is 1.01. res = ( +( Math.round( res + `e+${calcField.precision}` ) + `e-${calcField.precision}` ) ).toFixed(calcField.precision); const inputVal = $input.val(); var decimal_point = $input.data('decimal-point'); res = String(res).replace(".", decimal_point ); if (inputVal !== res) { $input.val(res).trigger("change"); } }, maybeReplaceCalculationGroups: function (formula) { var pattern = new RegExp('\\{((?:calculation|number|slider|currency|radio|select|checkbox)-\\d+(?:-min|-max)?)-\\*\\}', 'g'); var matches; while( matches = pattern.exec( formula ) ) { var fullMatch = matches[0]; var selector = matches[1]; var repeatedFields = this.$el.find( "[name='" + selector + "'], [name='" + selector + "\[\]'], [name^='" + selector + "-']" ).map(function() { const name = this.name.replace( '[]', '' ); return '{' + name + '}'; }).get(); repeatedFields = $.unique(repeatedFields.sort()); repeatedFields = '(' + repeatedFields.join('+') + ')'; formula = formula.replace( fullMatch, repeatedFields ); } return formula; }, maybeReplaceFieldOnFormula: function (formula) { formula = this.maybeReplaceCalculationGroups(formula); var joinedFieldTypes = this.settings.forminatorFields.join('|'); var incrementFieldPattern = "(" + joinedFieldTypes + ")-\\d+"; var pattern = new RegExp('\\{(' + incrementFieldPattern + '(?:-min|-max)?)(\\-[A-Za-z-_]+)?(\\-[A-Za-z0-9-_]+)?\\}', 'g'); var parsedFormula = formula; var matches; while (matches = pattern.exec(formula)) { var fullMatch = matches[0]; var groupSuffix = matches[4] || ''; var inputName = matches[1] + groupSuffix; var fieldType = matches[2]; var replace = fullMatch; if (fullMatch === undefined || inputName === undefined || fieldType === undefined) { continue; } if(this.is_hidden(inputName)) { replace = 0; const $element = this.get_form_field(inputName); if ( 'zero' !== $element.data('hidden-behavior') ) { var quotedOperand = fullMatch.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1"); var regexp = new RegExp('([\\+\\-\\*\\/]?)[^\\+\\-\\*\\/\\(]*' + quotedOperand + '[^\\)\\+\\-\\*\\/]*([\\+\\-\\*\\/]?)'); var mt = regexp.exec(parsedFormula); if (mt) { // if operand in multiplication or division set value = 1 if (mt[1] === '*' || mt[1] === '/' || mt[2] === '*' || mt[2] === '/') { replace = 1; } } } } else { if (fieldType === 'calculation') { var calcField = this.get_calculation_field(inputName); if (calcField) { this.memoizeDebounceRender( calcField ); } } replace = this.get_field_value(inputName); } // bracketify replace = '(' + replace + ')'; parsedFormula = parsedFormula.replace(fullMatch, replace); } return parsedFormula; }, get_calculation_field: function (element_id) { for (var i = 0; i < this.calculationFields.length; i++) { if(this.calculationFields[i].name === element_id) { return this.calculationFields[i]; } } return false; }, is_hidden: function (element_id) { var $element_id = this.get_form_field(element_id), $column_field = $element_id.closest('.forminator-col'), $row_field = $column_field.closest('.forminator-row') ; if( $row_field.hasClass("forminator-hidden-option") || $column_field.hasClass("forminator-hidden-option") ) { return false; } if( $row_field.hasClass("forminator-hidden") || $column_field.hasClass("forminator-hidden") ) { return true; } return false; }, get_field_value: function (element_id) { var $element = this.get_form_field(element_id); var value = 0; var calculation = 0; var checked = null; if (this.field_is_radio($element)) { checked = $element.filter(":checked"); if (checked.length) { calculation = checked.data('calculation'); if (calculation !== undefined) { value = Number(calculation); } } } else if (this.field_is_checkbox($element)) { $element.each(function () { if ($(this).is(':checked')) { calculation = $(this).data('calculation'); if (calculation !== undefined) { value += Number(calculation); } } }); } else if (this.field_is_select($element)) { checked = $element.find("option").filter(':selected'); if (checked.length) { calculation = checked.data('calculation'); if (calculation !== undefined) { value = Number(calculation); } } } else if ( this.field_has_inputMask( $element ) ) { value = parseFloat( $element.inputmask('unmaskedvalue').replace(',','.') ); } else if ( $element.length ) { var number = $element.val(); value = parseFloat( number.replace(',','.') ); } return isNaN(value) ? 0 : value; }, field_has_inputMask: function ( $element ) { var hasMask = false; $element.each(function () { if ( undefined !== $( this ).attr( 'data-inputmask' ) ) { hasMask = true; //break return false; } }); return hasMask; }, field_is_radio: function ($element) { var is_radio = false; $element.each(function () { if ($(this).attr('type') === 'radio') { is_radio = true; //break return false; } }); return is_radio; }, field_is_checkbox: function ($element) { var is_checkbox = false; $element.each(function () { if ($(this).attr('type') === 'checkbox') { is_checkbox = true; //break return false; } }); return is_checkbox; }, field_is_select: function ($element) { return $element.is('select'); }, displayErrorMessage: function ($element, errorMessage) { var $field_holder = $element.closest('.forminator-field--inner'); if ($field_holder.length === 0) { $field_holder = $element.closest('.forminator-field'); } var $error_holder = $field_holder.find('.forminator-error-message'); var $error_id = $element.attr('id') + '-error'; var $element_aria_describedby = $element.attr('aria-describedby'); if ($element_aria_describedby) { var ids = $element_aria_describedby.split(' '); var errorIdExists = ids.includes($error_id); if (!errorIdExists) { ids.push($error_id); } var updatedAriaDescribedby = ids.join(' '); $element.attr('aria-describedby', updatedAriaDescribedby); } else { $element.attr('aria-describedby', $error_id); } if ($error_holder.length === 0) { $field_holder.append(''); $error_holder = $field_holder.find('.forminator-error-message'); } $element.attr('aria-invalid', 'true'); $error_holder.html(errorMessage); $field_holder.addClass('forminator-has_error'); }, hideErrorMessage: function ($element) { var $field_holder = $element.closest('.forminator-field--inner'); if ($field_holder.length === 0) { $field_holder = $element.closest('.forminator-field'); } var $error_holder = $field_holder.find('.forminator-error-message'); var $error_id = $element.attr('id') + '-error'; var $element_aria_describedby = $element.attr('aria-describedby'); if ($element_aria_describedby) { var ids = $element_aria_describedby.split(' '); ids = ids.filter(function (id) { return id !== $error_id; }); var updatedAriaDescribedby = ids.join(' '); $element.attr('aria-describedby', updatedAriaDescribedby); } else { $element.removeAttr('aria-describedby'); } $element.removeAttr('aria-invalid'); $error_holder.remove(); $field_holder.removeClass('forminator-has_error'); }, }); // A really lightweight plugin wrapper around the constructor, // preventing against multiple instantiations $.fn[pluginName] = function (options) { return this.each(function () { if (!$.data(this, pluginName)) { $.data(this, pluginName, new ForminatorFrontCalculate(this, options)); } }); }; })(jQuery, window, document); // the semi-colon before function invocation is a safety net against concatenated // scripts and/or other plugins which may not be closed properly. ;// noinspection JSUnusedLocalSymbols (function ($, window, document, undefined) { "use strict"; // undefined is used here as the undefined global variable in ECMAScript 3 is // mutable (ie. it can be changed by someone else). undefined isn't really being // passed in so we can ensure the value of it is truly undefined. In ES5, undefined // can no longer be modified. // window and document are passed through as local variables rather than global // as this (slightly) quickens the resolution process and can be more efficiently // minified (especially when both are regularly referenced in your plugin). // Create the defaults once var pluginName = "forminatorFrontMergeTags", defaults = { print_value: false, forminatorFields: [], }; // The actual plugin constructor function forminatorFrontMergeTags(element, options) { this.element = element; this.$el = $(this.element); // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object // is generally empty as we don't want to alter the default options for // future instances of the plugin this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; ForminatorFront.MergeTags = ForminatorFront.MergeTags || []; this.init(); } // Avoid Plugin.prototype conflicts $.extend(forminatorFrontMergeTags.prototype, { init: function () { var self = this; var fields = this.$el.find('.forminator-merge-tags'); const formId = this.getFormId(); ForminatorFront.MergeTags[ formId ] = ForminatorFront.MergeTags[ formId ] || []; if (fields.length > 0) { fields.each(function () { let html = $(this).html(), fieldId = $(this).data('field'); if ( self.$el.hasClass( 'forminator-grouped-fields' ) ) { // Get origin HTML during cloningGroup fields. const suffix = self.$el.data( 'suffix' ); if ( ForminatorFront.MergeTags[ formId ][ fieldId ] ) { html = ForminatorFront.MergeTags[ formId ][ fieldId ]['value']; // get Fields in the current Group. const groupFields = self.$el.find( '[name]' ).map(function() { return this.name; }).get(); $.each( groupFields, function( index, item ) { var fieldWithoutSuffix = item.replace( '-' + suffix, '' ); if ( fieldWithoutSuffix === item ) { return; // continue. } const regexp = new RegExp( `{${fieldWithoutSuffix}}`, 'g' ); html = html.replace( regexp, '{' + item + '}' ); }); } fieldId += '-' + suffix; } ForminatorFront.MergeTags[ formId ][ fieldId ] = { $input: $(this), value: html, }; }); } this.replaceAll(); this.attachEvents(); }, getFormId: function () { let formId = ''; if ( this.$el.hasClass( 'forminator-grouped-fields' ) ) { formId = this.$el.closest( 'form.forminator-ui' ).data( 'form-id' ); } else { formId = this.$el.data( 'form-id' ); } return formId; }, attachEvents: function () { var self = this; this.$el.find( '.forminator-textarea, input.forminator-input, .forminator-checkbox, .forminator-radio, .forminator-input-file, select.forminator-select2, .forminator-multiselect input' + ', input.forminator-slider-hidden, input.forminator-slider-hidden-min, input.forminator-slider-hidden-max' ).each(function () { $(this).on('change', function () { // Give jquery sometime to apply changes setTimeout( function() { self.replaceAll(); }, 300 ); }); }); }, replaceAll: function () { const self = this, formId = this.getFormId(), formFields = ForminatorFront.MergeTags[ formId ]; for ( const key in formFields ) { const formField = formFields[key]; self.replace( formField ); } }, replace: function ( field ) { var $input = field.$input; var res = this.maybeReplaceValue(field.value); $input.html(res); }, maybeReplaceValue: function (value) { var joinedFieldTypes = this.settings.forminatorFields.join('|'); var incrementFieldPattern = "(" + joinedFieldTypes + ")-\\d+"; var pattern = new RegExp('\\{(' + incrementFieldPattern + ')(\\-[0-9A-Za-z-_]+)?\\}', 'g'); var parsedValue = value; var matches; while (matches = pattern.exec(value)) { var fullMatch = matches[0]; var inputName = fullMatch.replace('{', '').replace('}', ''); var fieldType = matches[2]; var replace = fullMatch; if (fullMatch === undefined || inputName === undefined || fieldType === undefined) { continue; } replace = this.get_field_value(inputName); parsedValue = parsedValue.replace(fullMatch, replace); } return parsedValue; }, // taken from forminatorFrontCondition get_form_field: function (element_id) { let $form = this.$el; if ( $form.hasClass( 'forminator-grouped-fields' ) ) { $form = $form.closest( 'form.forminator-ui' ); } //find element by suffix -field on id input (default behavior) var $element = $form.find('#' + element_id + '-field'); if ($element.length === 0) { //find element by its on name $element = $form.find('[name=' + element_id + ']'); if ($element.length === 0) { //find element by its on name[] (for checkbox on multivalue) $element = $form.find('input[name="' + element_id + '[]"]'); if ($element.length === 0) { //find element by direct id (for name field mostly) //will work for all field with element_id-[somestring] $element = $form.find('#' + element_id); } } } return $element; }, is_calculation: function (element_id) { var $element = this.get_form_field(element_id); if ( $element.hasClass("forminator-calculation") ) { return true; } return false; }, get_field_value: function (element_id) { var $element = this.get_form_field(element_id), self = this, value = '', checked = null; if ( this.is_hidden( element_id ) && ! this.is_calculation( element_id ) ) { return ''; } if ( this.is_calculation( element_id ) ) { var $element_id = this.get_form_field(element_id), $column_field = $element_id.closest('.forminator-col'), $row_field = $column_field.closest('.forminator-row') ; if ( ! $row_field.hasClass("forminator-hidden-option") && this.is_hidden( element_id ) ) { return ''; } } if (this.field_is_radio($element)) { checked = $element.filter(":checked"); if (checked.length) { if ( this.settings.print_value ) { value = checked.val(); } else { value = 0 === checked.siblings( '.forminator-radio-label' ).length ? checked.siblings( '.forminator-screen-reader-only' ).text() : checked.siblings( '.forminator-radio-label' ).text(); } } } else if (this.field_is_checkbox($element)) { $element.each(function () { if ($(this).is(':checked')) { if(value !== "") { value += ', '; } var multiselect = !! $(this).closest('.forminator-multiselect').length; if ( self.settings.print_value ) { value += $(this).val(); } else if ( multiselect ) { value += $(this).closest('label').text(); } else { value += 0 === $(this).siblings( '.forminator-checkbox-label' ).length ? $(this).siblings( '.forminator-screen-reader-only' ).text() : $(this).siblings( '.forminator-checkbox-label' ).text(); } } }); } else if (this.field_is_select($element)) { checked = $element.find("option").filter(':selected'); if (checked.length) { if ( this.settings.print_value ) { value = checked.val(); } else { value = checked.text(); } } } else if (this.field_is_upload($element)) { value = $element.val().split('\\').pop(); } else if (this.field_has_inputMask($element)) { $element.inputmask({'autoUnmask' : false}); value = $element.val(); $element.inputmask({'autoUnmask' : true}); } else { value = $element.val(); } return value; }, field_has_inputMask: function ( $element ) { var hasMask = false; $element.each(function () { if ( undefined !== $( this ).attr( 'data-inputmask' ) ) { hasMask = true; //break return false; } }); return hasMask; }, field_is_radio: function ($element) { var is_radio = false; $element.each(function () { if ($(this).attr('type') === 'radio') { is_radio = true; //break return false; } }); return is_radio; }, field_is_checkbox: function ($element) { var is_checkbox = false; $element.each(function () { if ($(this).attr('type') === 'checkbox') { is_checkbox = true; //break return false; } }); return is_checkbox; }, field_is_upload: function ($element) { if ($element.attr('type') === 'file') { return true; } return false; }, field_is_select: function ($element) { return $element.is('select'); }, // modified from front.condition is_hidden: function (element_id) { var $element_id = this.get_form_field(element_id), $column_field = $element_id.closest('.forminator-col'), $row_field = $column_field.closest('.forminator-row') ; if ( $row_field.hasClass("forminator-hidden-option") || $row_field.hasClass("forminator-hidden") ) { return true; } if( $column_field.hasClass("forminator-hidden") ) { return true; } return false; }, }); // A really lightweight plugin wrapper around the constructor, // preventing against multiple instantiations $.fn[pluginName] = function (options) { return this.each(function () { if (!$.data(this, pluginName)) { $.data(this, pluginName, new forminatorFrontMergeTags(this, options)); } }); }; })(jQuery, window, document); // the semi-colon before function invocation is a safety net against concatenated // scripts and/or other plugins which may not be closed properly. ;// noinspection JSUnusedLocalSymbols (function ($, window, document, undefined) { "use strict"; // Polyfill if (!Object.assign) { Object.defineProperty(Object, 'assign', { enumerable: false, configurable: true, writable: true, value: function(target, firstSource) { 'use strict'; if (target === undefined || target === null) { throw new TypeError('Cannot convert first argument to object'); } var to = Object(target); for (var i = 1; i < arguments.length; i++) { var nextSource = arguments[i]; if (nextSource === undefined || nextSource === null) { continue; } var keysArray = Object.keys(Object(nextSource)); for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) { var nextKey = keysArray[nextIndex]; var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey); if (desc !== undefined && desc.enumerable) { to[nextKey] = nextSource[nextKey]; } } } return to; } }); } // undefined is used here as the undefined global variable in ECMAScript 3 is // mutable (ie. it can be changed by someone else). undefined isn't really being // passed in so we can ensure the value of it is truly undefined. In ES5, undefined // can no longer be modified. // window and document are passed through as local variables rather than global // as this (slightly) quickens the resolution process and can be more efficiently // minified (especially when both are regularly referenced in your plugin). // Create the defaults once var pluginName = "forminatorFrontPayment", defaults = { type: 'stripe', paymentEl: null, paymentRequireSsl: false, generalMessages: {}, }; // The actual plugin constructor function ForminatorFrontPayment(element, options) { this.element = element; this.$el = $(this.element); // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object // is generally empty as we don't want to alter the default options for // future instances of the plugin this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this._stripeData = null; this._stripe = null; this._cardElement = null; this._stripeToken = null; this._beforeSubmitCallback = null; this._form = null; this._paymentIntent = null; this.init(); } // Avoid Plugin.prototype conflicts $.extend(ForminatorFrontPayment.prototype, { init: function () { if (!this.settings.paymentEl || typeof this.settings.paymentEl.data() === 'undefined') { return; } var self = this; this._stripeData = this.settings.paymentEl.data(); if ( false === this.mountCardField() ) { return; } $(this.element).on('payment.before.submit.forminator', function (e, formData, callback) { self._form = self.getForm(e); self._beforeSubmitCallback = callback; self.validateStripe(e, formData); }); this.$el.on("forminator:form:submit:stripe:3dsecurity", function(e, secret, subscription) { self.validate3d(e, secret, subscription); }); // Listen for fields change to update ZIP mapping this.$el.find( 'input.forminator-input, .forminator-checkbox, .forminator-radio, select.forminator-select2' ).each(function () { $(this).on('change', function (e) { self.mapZip(e); }); }); }, validate3d: function( e, secret, subscription ) { var self = this; if ( subscription ) { this._stripe.confirmCardPayment(secret, { payment_method: { card: self._cardElement, ...self.getBillingData(), }, }) .then(function(result) { self.$el.find('#forminator-stripe-subscriptionid').val( subscription ); if (self._beforeSubmitCallback) { self._beforeSubmitCallback.call(); } }); } else { this._stripe.retrievePaymentIntent( secret ).then(function(result) { if ( result.paymentIntent.status === 'requires_action' || result.paymentIntent.status === 'requires_source_action' ) { self._stripe.handleCardAction( secret ).then(function(result) { if (self._beforeSubmitCallback) { self._beforeSubmitCallback.call(); } }); } }); } }, validateStripe: function(e, formData) { var self = this; this._stripe.createToken(this._cardElement).then(function (result) { if (result.error) { self.showCardError(result.error.message, true); self.$el.find( 'button' ).removeAttr( 'disabled' ); } else { self.hideCardError(); self._stripe.createPaymentMethod('card', self._cardElement, self.getBillingData()).then(function (result) { var paymentMethod = self.getObjectValue(result, 'paymentMethod'); self._stripeData['paymentMethod'] = self.getObjectValue(paymentMethod, 'id'); self.updateAmount(e, formData, result); }); } }); }, isValid: function(focus) { var self = this; this._stripe.createToken(this._cardElement).then(function (result) { if (result.error) { self.showCardError(result.error.message, focus); } else { self.hideCardError(); } }); }, getForm: function(e) { var $form = $( e.target ); if(!$form.hasClass('forminator-custom-form')) { $form = $form.closest('form.forminator-custom-form'); } return $form; }, updateAmount: function(e, formData, result) { e.preventDefault(); var self = this; var updateFormData = formData; var paymentMethod = this.getObjectValue(result, 'paymentMethod'); //Method set() doesn't work in IE11 updateFormData.append( 'action', 'forminator_update_payment_amount' ); updateFormData.append( 'paymentid', this.getStripeData('paymentid') ); updateFormData.append( 'payment_method', this.getObjectValue(paymentMethod, 'id') ); var receipt = this.getStripeData('receipt'); var receiptEmail = this.getStripeData('receiptEmail'); var receiptObject = {}; if( receipt && receiptEmail ) { var emailValue = this.get_field_value(receiptEmail) || ''; updateFormData.append( 'receipt_email', emailValue ); } $.ajax({ type: 'POST', url: window.ForminatorFront.ajaxUrl, data: updateFormData, cache: false, contentType: false, processData: false, beforeSend: function () { if( typeof self.settings.has_loader !== "undefined" && self.settings.has_loader ) { // Disable form fields self._form.addClass('forminator-fields-disabled'); var $target_message = self._form.find('.forminator-response-message'); $target_message.html('

' + self.settings.loader_label + '

'); self.focus_to_element($target_message); $target_message.removeAttr("aria-hidden") .prop("tabindex", "-1") .removeClass('forminator-success forminator-error') .addClass('forminator-loading forminator-show'); } self._form.find('button').attr('disabled', true); }, success: function (data) { if (data.success === true) { // Store payment id if (typeof data.data !== 'undefined' && typeof data.data.paymentid !== 'undefined') { self.$el.find('#forminator-stripe-paymentid').val(data.data.paymentid); self.$el.find('#forminator-stripe-paymentmethod').val(self._stripeData['paymentMethod']); self._stripeData['paymentid'] = data.data.paymentid; self._stripeData['secret'] = data.data.paymentsecret; self.handleCardPayment(data, e, formData); } else { self.show_error('Invalid Payment Intent ID'); } } else { self.show_error(data.data.message); if(data.data.errors.length) { self.show_messages(data.data.errors); } var $captcha_field = self._form.find('.forminator-g-recaptcha'); if ($captcha_field.length) { $captcha_field = $($captcha_field.get(0)); var recaptcha_widget = $captcha_field.data('forminator-recapchta-widget'), recaptcha_size = $captcha_field.data('size'); if (recaptcha_size === 'invisible') { window.grecaptcha.reset(recaptcha_widget); } } } }, error: function (err) { var $message = err.status === 400 ? window.ForminatorFront.cform.upload_error : window.ForminatorFront.cform.error; self.show_error($message); } }) }, show_error: function(message) { var $target_message = this._form.find('.forminator-response-message'); this._form.find('button').removeAttr('disabled'); $target_message.removeAttr("aria-hidden") .prop("tabindex", "-1") .removeClass('forminator-loading') .addClass('forminator-error forminator-show'); $target_message.html('

' + message + '

'); this.focus_to_element($target_message); this.enable_form(); }, enable_form: function() { if( typeof this.settings.has_loader !== "undefined" && this.settings.has_loader ) { var $target_message = this._form.find('.forminator-response-message'); // Enable form fields this._form.removeClass('forminator-fields-disabled'); $target_message.removeClass('forminator-loading'); } }, mapZip: function (e) { var verifyZip = this.getStripeData('veifyZip'); var zipField = this.getStripeData('zipField'); var changedField = $(e.currentTarget).attr('name'); // Verify ZIP is enabled, mapped field is not empty and changed field is the mapped field, proceed if (verifyZip && zipField !== "" && changedField === zipField) { if (e.originalEvent !== undefined) { // Get field var value = this.get_field_value(zipField); // Update card element this._cardElement.update({ value: { postalCode: value } }); } } }, focus_to_element: function ($element) { // force show in case its hidden of fadeOut $element.show(); $('html,body').animate({scrollTop: ($element.offset().top - ($(window).height() - $element.outerHeight(true)) / 2)}, 500, function () { if (!$element.attr("tabindex")) { $element.attr("tabindex", -1); } $element.focus(); }); }, show_messages: function (errors) { var self = this, forminatorFrontCondition = self.$el.data('forminatorFrontCondition'); if (typeof forminatorFrontCondition !== 'undefined') { // clear all validation message before show new one this.$el.find('.forminator-error-message').remove(); var i = 0; errors.forEach(function (value) { var element_id = Object.keys(value), message = Object.values(value), element = forminatorFrontCondition.get_form_field(element_id); if (element.length) { if (i === 0) { // focus on first error self.$el.trigger('forminator.front.pagination.focus.input',[element]); self.focus_to_element(element); } if ($(element).hasClass('forminator-input-time')) { var $time_field_holder = $(element).closest('.forminator-field:not(.forminator-field--inner)'), $time_error_holder = $time_field_holder.children('.forminator-error-message'); if ($time_error_holder.length === 0) { $time_field_holder.append(''); $time_error_holder = $time_field_holder.children('.forminator-error-message'); } $time_error_holder.html(message); } var $field_holder = $(element).closest('.forminator-field--inner'); if ($field_holder.length === 0) { $field_holder = $(element).closest('.forminator-field'); if ($field_holder.length === 0) { // handling postdata field $field_holder = $(element).find('.forminator-field'); if ($field_holder.length > 1) { $field_holder = $field_holder.first(); } } } var $error_holder = $field_holder.find('.forminator-error-message'); if ($error_holder.length === 0) { $field_holder.append(''); $error_holder = $field_holder.find('.forminator-error-message'); } $(element).attr('aria-invalid', 'true'); $error_holder.html(message); $field_holder.addClass('forminator-has_error'); i++; } }); } return this; }, getBillingData: function (formData) { var billing = this.getStripeData('billing'); // If billing is disabled, return if (!billing) { return {} }; // Get billing fields var billingName = this.getStripeData('billingName'); var billingEmail = this.getStripeData('billingEmail'); var billingAddress = this.getStripeData('billingAddress'); // Create billing object var billingObject = { address: {} } if( billingName ) { var nameField = this.get_field_value(billingName); // Check if Name field is multiple if (!nameField) { var fName = this.get_field_value(billingName + '-first-name') || ''; var lName = this.get_field_value(billingName + '-last-name') || ''; nameField = fName + ' ' + lName; } // Check if Name field is empty in the end, if not assign to the object if (nameField) { billingObject.name = nameField; } } // Map email field if(billingEmail) { var billingEmailValue = this.get_field_value(billingEmail) || ''; if (billingEmailValue) { billingObject.email = billingEmailValue; } } // Map address line 1 field var addressLine1 = this.get_field_value(billingAddress + '-street_address') || ''; if (addressLine1) { billingObject.address.line1 = addressLine1; } // Map address line 2 field var addressLine2 = this.get_field_value(billingAddress + '-address_line') || ''; if (addressLine2) { billingObject.address.line2 = addressLine2; } // Map address city field var addressCity = this.get_field_value(billingAddress + '-city') || ''; if (addressCity) { billingObject.address.city = addressCity; } // Map address state field var addressState = this.get_field_value(billingAddress + '-state') || ''; if (addressState) { billingObject.address.state = addressState; } // Map address country field var countryField = this.get_form_field(billingAddress + '-country'); var addressCountry = countryField.find(':selected').data('country-code'); if (addressCountry) { billingObject.address.country = addressCountry; } // Map address country field var addressZip = this.get_field_value(billingAddress + '-zip') || ''; if (addressZip) { billingObject.address.postal_code = addressZip; } return { billing_details: billingObject } }, handleCardPayment: function (data, e, formData) { var self = this, secret = data.data.paymentsecret || false, input = $( '.forminator-number--field, .forminator-currency, .forminator-calculation' ); if ( input.inputmask ) { input.inputmask('remove'); } if (self._beforeSubmitCallback) { self._beforeSubmitCallback.call(); } }, mountCardField: function () { var key = this.getStripeData('key'); var cardIcon = this.getStripeData('cardIcon'); var verifyZip = this.getStripeData('veifyZip'); var zipField = this.getStripeData('zipField'); var fieldId = this.getStripeData('fieldId'); if ( null === key ) { return false; } // Init Stripe this._stripe = Stripe( key, { locale: this.getStripeData('language') } ); // Create empty ZIP object var zipObject = {} if (!verifyZip) { // If verify ZIP is disabled, disable ZIP zipObject.hidePostalCode = true; } else { // Set empty post code, later will be updated when field is changed zipObject.value = { postalCode: '', }; } var stripeObject = {}; var fontFamily = this.getStripeData('fontFamily'); var customFonts = this.getStripeData('customFonts'); if (fontFamily && customFonts) { stripeObject.fonts = [ { cssSrc: 'https://fonts.bunny.net/css?family=' + fontFamily, } ]; } var elements = this._stripe.elements(stripeObject); this._cardElement = elements.create('card', Object.assign( { classes: { base: this.getStripeData('baseClass'), complete: this.getStripeData('completeClass'), empty: this.getStripeData('emptyClass'), focus: this.getStripeData('focusedClass'), invalid: this.getStripeData('invalidClass'), webkitAutofill: this.getStripeData('autofilledClass'), }, style: { base: { iconColor: this.getStripeData( 'iconColor' ), color: this.getStripeData( 'fontColor' ), lineHeight: this.getStripeData( 'lineHeight' ), fontWeight: this.getStripeData( 'fontWeight' ), fontFamily: this.getStripeData( 'fontFamily' ), fontSmoothing: 'antialiased', fontSize: this.getStripeData( 'fontSize' ), '::placeholder': { color: this.getStripeData( 'placeholder' ), }, ':hover': { iconColor: this.getStripeData( 'iconColorHover' ), }, ':focus': { iconColor: this.getStripeData( 'iconColorFocus' ), } }, invalid: { iconColor: this.getStripeData( 'iconColorError' ), color: this.getStripeData( 'fontColorError' ), }, }, iconStyle: 'solid', hideIcon: !cardIcon, }, zipObject )); this._cardElement.mount('#card-element-' + fieldId); this.validateCard(); }, validateCard: function () { var self = this; this._cardElement.on( 'change', function( event ) { if ( self.$el.find( '.forminator-stripe-element' ).hasClass( 'StripeElement--empty' ) ) { self.$el.find( '.forminator-stripe-element' ).closest( '.forminator-field' ).removeClass( 'forminator-is_filled' ); } else { self.$el.find( '.forminator-stripe-element' ).closest( '.forminator-field' ).addClass( 'forminator-is_filled' ); } if ( self.$el.find( '.forminator-stripe-element' ).hasClass( 'StripeElement--invalid' ) ) { self.$el.find( '.forminator-stripe-element' ).closest( '.forminator-field' ).addClass( 'forminator-has_error' ); } }); this._cardElement.on('focus', function(event) { self.$el.find('.forminator-stripe-element').closest('.forminator-field').addClass('forminator-is_active'); }); this._cardElement.on('blur', function(event) { self.$el.find('.forminator-stripe-element').closest('.forminator-field').removeClass('forminator-is_active'); self.isValid(false); }); }, hideCardError: function () { var $field_holder = this.$el.find('.forminator-card-message'); var $error_holder = $field_holder.find('.forminator-error-message'); if ($error_holder.length === 0) { $field_holder.append(''); $error_holder = $field_holder.find('.forminator-error-message'); } $field_holder.closest('.forminator-field').removeClass('forminator-has_error'); $error_holder.html(''); }, showCardError: function (message, focus) { var $field_holder = this.$el.find('.forminator-card-message'); var $error_holder = $field_holder.find('.forminator-error-message'); if ($error_holder.length === 0) { $field_holder.append(''); $error_holder = $field_holder.find('.forminator-error-message'); } $field_holder.closest('.forminator-field').addClass('forminator-has_error'); $field_holder.closest('.forminator-field').addClass( 'forminator-is_filled' ); $error_holder.html(message); if(focus) { this.focus_to_element($field_holder.closest('.forminator-field')); } }, getStripeData: function (key) { if ( (typeof this._stripeData !== 'undefined') && (typeof this._stripeData[key] !== 'undefined') ) { return this._stripeData[key]; } return null; }, getObjectValue: function(object, key) { if (typeof object[key] !== 'undefined') { return object[key]; } return null; }, // taken from forminatorFrontCondition get_form_field: function (element_id) { //find element by suffix -field on id input (default behavior) var $element = this.$el.find('#' + element_id + '-field'); if ($element.length === 0) { //find element by its on name (for radio on singlevalue) $element = this.$el.find('input[name=' + element_id + ']'); if ($element.length === 0) { // for text area that have uniqid, so we check its name instead $element = this.$el.find('textarea[name=' + element_id + ']'); if ($element.length === 0) { //find element by its on name[] (for checkbox on multivalue) $element = this.$el.find('input[name="' + element_id + '[]"]'); if ($element.length === 0) { //find element by select name $element = this.$el.find('select[name="' + element_id + '"]'); if ($element.length === 0) { //find element by direct id (for name field mostly) //will work for all field with element_id-[somestring] $element = this.$el.find('#' + element_id); } } } } } return $element; }, get_field_value: function (element_id) { var $element = this.get_form_field(element_id); var value = ''; var checked = null; if (this.field_is_radio($element)) { checked = $element.filter(":checked"); if (checked.length) { value = checked.val(); } } else if (this.field_is_checkbox($element)) { $element.each(function () { if ($(this).is(':checked')) { value = $(this).val(); } }); } else if (this.field_is_select($element)) { value = $element.val(); } else if ( this.field_has_inputMask( $element ) ) { value = parseFloat( $element.inputmask( 'unmaskedvalue' ) ); } else { value = $element.val() } return value; }, get_field_calculation: function (element_id) { var $element = this.get_form_field(element_id); var value = 0; var calculation = 0; var checked = null; if (this.field_is_radio($element)) { checked = $element.filter(":checked"); if (checked.length) { calculation = checked.data('calculation'); if (calculation !== undefined) { value = Number(calculation); } } } else if (this.field_is_checkbox($element)) { $element.each(function () { if ($(this).is(':checked')) { calculation = $(this).data('calculation'); if (calculation !== undefined) { value += Number(calculation); } } }); } else if (this.field_is_select($element)) { checked = $element.find("option").filter(':selected'); if (checked.length) { calculation = checked.data('calculation'); if (calculation !== undefined) { value = Number(calculation); } } } else { value = Number($element.val()); } return isNaN(value) ? 0 : value; }, field_has_inputMask: function ( $element ) { var hasMask = false; $element.each(function () { if ( undefined !== $( this ).attr( 'data-inputmask' ) ) { hasMask = true; //break return false; } }); return hasMask; }, field_is_radio: function ($element) { var is_radio = false; $element.each(function () { if ($(this).attr('type') === 'radio') { is_radio = true; //break return false; } }); return is_radio; }, field_is_checkbox: function ($element) { var is_checkbox = false; $element.each(function () { if ($(this).attr('type') === 'checkbox') { is_checkbox = true; //break return false; } }); return is_checkbox; }, field_is_select: function ($element) { return $element.is('select'); }, }); // A really lightweight plugin wrapper around the constructor, // preventing against multiple instantiations $.fn[pluginName] = function (options) { return this.each(function () { if (!$.data(this, pluginName)) { $.data(this, pluginName, new ForminatorFrontPayment(this, options)); } }); }; })(jQuery, window, document); // the semi-colon before function invocation is a safety net against concatenated // scripts and/or other plugins which may not be closed properly. ;// noinspection JSUnusedLocalSymbols (function ($, window, document, undefined) { "use strict"; // undefined is used here as the undefined global variable in ECMAScript 3 is // mutable (ie. it can be changed by someone else). undefined isn't really being // passed in so we can ensure the value of it is truly undefined. In ES5, undefined // can no longer be modified. // window and document are passed through as local variables rather than global // as this (slightly) quickens the resolution process and can be more efficiently // minified (especially when both are regularly referenced in your plugin). // Create the defaults once var pluginName = "forminatorFrontPagination", defaults = { totalSteps: 0, step: 0, hashStep: 0, inline_validation: false }; // The actual plugin constructor function ForminatorFrontPagination(element, options) { this.element = $(element); this.$el = this.element; this.totalSteps = 0; this.step = 0; this.finished = false; this.hashStep = false; this.next_button_txt = ''; this.prev_button_txt = ''; this.custom_label = []; this.form_id = 0; this.element = ''; // jQuery has an extend method which merges the contents of two or // more objects, storing the result in the first object. The first object // is generally empty as we don't want to alter the default options for // future instances of the plugin this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.init(); } // Avoid Plugin.prototype conflicts $.extend(ForminatorFrontPagination.prototype, { init: function () { var self = this; var draftPage = !! this.$el.data( 'draft-page' ) ? this.$el.data( 'draft-page' ) : 0; this.next_button = this.settings.next_button ? this.settings.next_button : window.ForminatorFront.cform.pagination_next; this.prev_button = this.settings.prev_button ? this.settings.prev_button : window.ForminatorFront.cform.pagination_prev; if (this.$el.find('input[name=form_id]').length > 0) { this.form_id = this.$el.find('input[name=form_id]').val(); } this.totalSteps = this.settings.totalSteps; this.step = this.settings.step; this.quiz = this.settings.quiz; this.element = this.$el.find('[data-step=' + this.step + ']').data('name'); if (this.form_id && typeof window.Forminator_Cform_Paginations === 'object' && typeof window.Forminator_Cform_Paginations[this.form_id] === 'object') { this.custom_label = window.Forminator_Cform_Paginations[this.form_id]; } if ( draftPage > 0 ) { this.go_to( draftPage, true ); } else if (this.settings.hashStep && this.step > 0) { this.go_to(this.step, true); } else if ( this.quiz ) { this.go_to(0, true); } else { this.go_to(0, false); } this.render_navigation(); this.render_bar_navigation(); this.render_footer_navigation( this.form_id ); this.init_events(); this.update_buttons(); this.update_navigation(); this.$el.find('.forminator-button.forminator-button-back, .forminator-button.forminator-button-next, .forminator-button.forminator-button-submit').on("click", function (e) { e.preventDefault(); $(this).trigger('forminator.front.pagination.move'); self.resetRichTextEditorHeight(); }); this.$el.on('click', '.forminator-result--view-answers', function(e){ e.preventDefault(); $(this).trigger('forminator.front.pagination.move'); }); }, init_events: function () { var self = this; this.$el.find('.forminator-button-back').on('forminator.front.pagination.move',function (e) { self.handle_click('prev'); }); this.$el.on('forminator.front.pagination.move', '.forminator-result--view-answers', function (e) { self.handle_click('prev'); }); this.$el.find('.forminator-button-next').on('forminator.front.pagination.move', function (e) { self.handle_click('next'); }); this.$el.find('.forminator-step').on("click", function (e) { e.preventDefault(); var step = $(this).data('nav'); self.handle_step(step); }); this.$el.on('reset', function (e) { self.on_form_reset(e); }); this.$el.on('forminator:quiz:submit:success', function (e, ajaxData, formData, resultText) { if ( resultText ) { self.move_to_results(e); } }); this.$el.on('forminator.front.pagination.focus.input', function (e, input) { self.on_focus_input(e, input); }); }, /** * Move quiz to rezult page */ move_to_results: function (e) { this.finished = true; if ( this.$el.find('.forminator-submit-rightaway').length ) { this.$el.find('#forminator-submit').removeClass('forminator-hidden'); } else { this.handle_click('next'); } }, /** * On reset event of Form * * @since 1.0.3 * * @param e */ on_form_reset: function (e) { // Trigger pagination to first page this.go_to(0, true); this.update_buttons(); }, /** * On Input focused * * @param e * @param input */ on_focus_input: function (e, input) { //Go to page where element exist var step = this.get_page_of_input(input); this.go_to(step, true); this.update_buttons(); }, render_footer_navigation: function( form_id ) { var footer_html = '', paypal_field = '', footer_align = ( this.custom_label['has-paypal'] === true ) ? ' style="align-items: flex-start;"' : '', save_draft_btn = this.$el.find( '.forminator-save-draft-link' ).length ? this.$el.find( '.forminator-save-draft-link' ) : '' ; if ( this.custom_label[ this.element ] && this.custom_label[ 'pagination-labels' ] === 'custom' ){ this.prev_button_txt = this.custom_label[ this.element ][ 'prev-text' ] !== '' ? this.custom_label[ this.element ][ 'prev-text' ] : this.prev_button; this.next_button_txt = this.custom_label[ this.element ][ 'next-text' ] !== '' ? this.custom_label[ this.element ][ 'next-text' ] : this.next_button; } else { this.prev_button_txt = this.prev_button; this.next_button_txt = this.next_button; } if ( this.$el.hasClass('forminator-design--material') ) { footer_html = '