UNPKG

docxtemplater

Version:

docx and pptx generator working with templates and data (like Mustache, for Word and Powerpoint documents)

61 lines (47 loc) 162 kB
/* * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). * This devtool is neither made for production nor for readable output files. * It uses "eval()" calls to create a separate source file in the browser devtools. * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) * or disable the default devtool with "devtool: false". * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). */ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./es6/browser-versions/xmldom.js": /*!****************************************!*\ !*** ./es6/browser-versions/xmldom.js ***! \****************************************/ /***/ ((module) => { eval("module.exports = {\n XMLSerializer: window.XMLSerializer,\n DOMParser: window.DOMParser,\n XMLDocument: window.XMLDocument\n};\n\n//# sourceURL=webpack://docxtemplater/./es6/browser-versions/xmldom.js?"); /***/ }), /***/ "./es6/collect-content-types.js": /*!**************************************!*\ !*** ./es6/collect-content-types.js ***! \**************************************/ /***/ ((module) => { eval("var ctXML = \"[Content_Types].xml\";\n\nfunction collectContentTypes(overrides, defaults, zip) {\n var partNames = {};\n\n for (var i = 0, len = overrides.length; i < len; i++) {\n var override = overrides[i];\n var contentType = override.getAttribute(\"ContentType\");\n var partName = override.getAttribute(\"PartName\").substr(1);\n partNames[partName] = contentType;\n }\n\n var _loop = function _loop(_i, _len) {\n var def = defaults[_i];\n var contentType = def.getAttribute(\"ContentType\");\n var extension = def.getAttribute(\"Extension\"); // eslint-disable-next-line no-loop-func\n\n zip.file(/./).map(function (_ref) {\n var name = _ref.name;\n\n if (name.slice(name.length - extension.length - 1) === \".xml\" && !partNames[name] && name !== ctXML) {\n partNames[name] = contentType;\n }\n });\n };\n\n for (var _i = 0, _len = defaults.length; _i < _len; _i++) {\n _loop(_i, _len);\n }\n\n return partNames;\n}\n\nmodule.exports = collectContentTypes;\n\n//# sourceURL=webpack://docxtemplater/./es6/collect-content-types.js?"); /***/ }), /***/ "./es6/doc-utils.js": /*!**************************!*\ !*** ./es6/doc-utils.js ***! \**************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; eval("\n\nfunction _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }\n\nfunction _nonIterableRest() { throw new TypeError(\"Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\n\nfunction _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); }\n\nfunction _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; }\n\nfunction _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== \"undefined\" && arr[Symbol.iterator] || arr[\"@@iterator\"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"] != null) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; }\n\nfunction _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }\n\nvar _require = __webpack_require__(/*! xmldom */ \"./es6/browser-versions/xmldom.js\"),\n DOMParser = _require.DOMParser,\n XMLSerializer = _require.XMLSerializer;\n\nvar _require2 = __webpack_require__(/*! ./errors.js */ \"./es6/errors.js\"),\n throwXmlTagNotFound = _require2.throwXmlTagNotFound;\n\nvar _require3 = __webpack_require__(/*! ./utils.js */ \"./es6/utils.js\"),\n last = _require3.last,\n first = _require3.first;\n\nfunction parser(tag) {\n return {\n get: function get(scope) {\n if (tag === \".\") {\n return scope;\n }\n\n return scope[tag];\n }\n };\n}\n\nfunction getNearestLeftIndex(parsed, elements, index) {\n for (var i = index; i >= 0; i--) {\n var part = parsed[i];\n\n for (var j = 0, len = elements.length; j < len; j++) {\n var element = elements[j];\n\n if (isStarting(part.value, element)) {\n return j;\n }\n }\n }\n\n return null;\n}\n\nfunction getNearestRightIndex(parsed, elements, index) {\n for (var i = index, l = parsed.length; i < l; i++) {\n var part = parsed[i];\n\n for (var j = 0, len = elements.length; j < len; j++) {\n var element = elements[j];\n\n if (isEnding(part.value, element)) {\n return j;\n }\n }\n }\n\n return -1;\n}\n\nfunction getNearestLeft(parsed, elements, index) {\n var found = getNearestLeftIndex(parsed, elements, index);\n\n if (found !== -1) {\n return elements[found];\n }\n\n return null;\n}\n\nfunction getNearestRight(parsed, elements, index) {\n var found = getNearestRightIndex(parsed, elements, index);\n\n if (found !== -1) {\n return elements[found];\n }\n\n return null;\n}\n\nfunction buildNearestCache(postparsed, tags) {\n return postparsed.reduce(function (cached, part, i) {\n if (part.type === \"tag\" && tags.indexOf(part.tag) !== -1) {\n cached.push({\n i: i,\n part: part\n });\n }\n\n return cached;\n }, []);\n}\n\nfunction getNearestLeftIndexWithCache(index, cache) {\n if (cache.length === 0) {\n return -1;\n }\n\n for (var i = 0, len = cache.length; i < len; i++) {\n var current = cache[i];\n var next = cache[i + 1];\n\n if (current.i < index && (!next || index < next.i) && current.part.position === \"start\") {\n return i;\n }\n }\n\n return -1;\n}\n\nfunction getNearestLeftWithCache(index, cache) {\n var found = getNearestLeftIndexWithCache(index, cache);\n\n if (found !== -1) {\n return cache[found].part.tag;\n }\n\n return null;\n}\n\nfunction getNearestRightIndexWithCache(index, cache) {\n if (cache.length === 0) {\n return -1;\n }\n\n for (var i = 0, len = cache.length; i < len; i++) {\n var current = cache[i];\n var _last = cache[i - 1];\n\n if (index < current.i && (!_last || _last.i < index) && current.part.position === \"end\") {\n return i;\n }\n }\n\n return -1;\n}\n\nfunction getNearestRightWithCache(index, cache) {\n var found = getNearestRightIndexWithCache(index, cache);\n\n if (found !== -1) {\n return cache[found].part.tag;\n }\n\n return null;\n}\n\nfunction endsWith(str, suffix) {\n return str.indexOf(suffix, str.length - suffix.length) !== -1;\n}\n\nfunction startsWith(str, prefix) {\n return str.substring(0, prefix.length) === prefix;\n}\n\nfunction unique(arr) {\n var hash = {},\n result = [];\n\n for (var i = 0, l = arr.length; i < l; ++i) {\n if (!hash.hasOwnProperty(arr[i])) {\n hash[arr[i]] = true;\n result.push(arr[i]);\n }\n }\n\n return result;\n}\n\nfunction chunkBy(parsed, f) {\n return parsed.reduce(function (chunks, p) {\n var currentChunk = last(chunks);\n var res = f(p);\n\n if (currentChunk.length === 0) {\n currentChunk.push(p);\n return chunks;\n }\n\n if (res === \"start\") {\n chunks.push([p]);\n } else if (res === \"end\") {\n currentChunk.push(p);\n chunks.push([]);\n } else {\n currentChunk.push(p);\n }\n\n return chunks;\n }, [[]]).filter(function (p) {\n return p.length > 0;\n });\n}\n\nvar defaults = {\n paragraphLoop: false,\n nullGetter: function nullGetter(part) {\n if (!part.module) {\n return \"undefined\";\n }\n\n if (part.module === \"rawxml\") {\n return \"\";\n }\n\n return \"\";\n },\n xmlFileNames: [],\n parser: parser,\n linebreaks: false,\n fileTypeConfig: null,\n delimiters: {\n start: \"{\",\n end: \"}\"\n }\n};\n\nfunction mergeObjects() {\n var resObj = {};\n var obj, keys;\n\n for (var i = 0; i < arguments.length; i += 1) {\n obj = arguments[i];\n keys = Object.keys(obj);\n\n for (var j = 0; j < keys.length; j += 1) {\n resObj[keys[j]] = obj[keys[j]];\n }\n }\n\n return resObj;\n}\n\nfunction xml2str(xmlNode) {\n var a = new XMLSerializer();\n return a.serializeToString(xmlNode).replace(/xmlns(:[a-z0-9]+)?=\"\" ?/g, \"\");\n}\n\nfunction str2xml(str) {\n if (str.charCodeAt(0) === 65279) {\n // BOM sequence\n str = str.substr(1);\n }\n\n var parser = new DOMParser();\n return parser.parseFromString(str, \"text/xml\");\n}\n\nvar charMap = [[\"&\", \"&amp;\"], [\"<\", \"&lt;\"], [\">\", \"&gt;\"], ['\"', \"&quot;\"], [\"'\", \"&apos;\"]];\n\nfunction escapeRegExp(str) {\n // to be able to use a string as a regex\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nvar charMapRegexes = charMap.map(function (_ref) {\n var _ref2 = _slicedToArray(_ref, 2),\n endChar = _ref2[0],\n startChar = _ref2[1];\n\n return {\n rstart: new RegExp(escapeRegExp(startChar), \"g\"),\n rend: new RegExp(escapeRegExp(endChar), \"g\"),\n start: startChar,\n end: endChar\n };\n});\n\nfunction wordToUtf8(string) {\n var r;\n\n for (var i = charMapRegexes.length - 1; i >= 0; i--) {\n r = charMapRegexes[i];\n string = string.replace(r.rstart, r.end);\n }\n\n return string;\n}\n\nfunction utf8ToWord(string) {\n if (typeof string !== \"string\") {\n string = string.toString();\n }\n\n var r;\n\n for (var i = 0, l = charMapRegexes.length; i < l; i++) {\n r = charMapRegexes[i];\n string = string.replace(r.rend, r.start);\n }\n\n return string;\n} // This function is written with for loops for performance\n\n\nfunction concatArrays(arrays) {\n var result = [];\n\n for (var i = 0; i < arrays.length; i++) {\n var array = arrays[i];\n\n for (var j = 0, len = array.length; j < len; j++) {\n result.push(array[j]);\n }\n }\n\n return result;\n}\n\nvar spaceRegexp = new RegExp(String.fromCharCode(160), \"g\");\n\nfunction convertSpaces(s) {\n return s.replace(spaceRegexp, \" \");\n}\n\nfunction pregMatchAll(regex, content) {\n /* regex is a string, content is the content. It returns an array of all matches with their offset, for example:\n \t regex=la\n \t content=lolalolilala\n returns: [{array: {0: 'la'},offset: 2},{array: {0: 'la'},offset: 8},{array: {0: 'la'} ,offset: 10}]\n */\n var matchArray = [];\n var match;\n\n while ((match = regex.exec(content)) != null) {\n matchArray.push({\n array: match,\n offset: match.index\n });\n }\n\n return matchArray;\n}\n\nfunction isEnding(value, element) {\n return value === \"</\" + element + \">\";\n}\n\nfunction isStarting(value, element) {\n return value.indexOf(\"<\" + element) === 0 && [\">\", \" \"].indexOf(value[element.length + 1]) !== -1;\n}\n\nfunction getRight(parsed, element, index) {\n var val = getRightOrNull(parsed, element, index);\n\n if (val !== null) {\n return val;\n }\n\n throwXmlTagNotFound({\n position: \"right\",\n element: element,\n parsed: parsed,\n index: index\n });\n}\n\nfunction getRightOrNull(parsed, elements, index) {\n if (typeof elements === \"string\") {\n elements = [elements];\n }\n\n var level = 1;\n\n for (var i = index, l = parsed.length; i < l; i++) {\n var part = parsed[i];\n\n for (var j = 0, len = elements.length; j < len; j++) {\n var element = elements[j];\n\n if (isEnding(part.value, element)) {\n level--;\n }\n\n if (isStarting(part.value, element)) {\n level++;\n }\n\n if (level === 0) {\n return i;\n }\n }\n }\n\n return null;\n}\n\nfunction getLeft(parsed, element, index) {\n var val = getLeftOrNull(parsed, element, index);\n\n if (val !== null) {\n return val;\n }\n\n throwXmlTagNotFound({\n position: \"left\",\n element: element,\n parsed: parsed,\n index: index\n });\n}\n\nfunction getLeftOrNull(parsed, elements, index) {\n if (typeof elements === \"string\") {\n elements = [elements];\n }\n\n var level = 1;\n\n for (var i = index; i >= 0; i--) {\n var part = parsed[i];\n\n for (var j = 0, len = elements.length; j < len; j++) {\n var element = elements[j];\n\n if (isStarting(part.value, element)) {\n level--;\n }\n\n if (isEnding(part.value, element)) {\n level++;\n }\n\n if (level === 0) {\n return i;\n }\n }\n }\n\n return null;\n}\n\nfunction isTagStart(tagType, _ref3) {\n var type = _ref3.type,\n tag = _ref3.tag,\n position = _ref3.position;\n return type === \"tag\" && tag === tagType && position === \"start\";\n}\n\nfunction isTagEnd(tagType, _ref4) {\n var type = _ref4.type,\n tag = _ref4.tag,\n position = _ref4.position;\n return type === \"tag\" && tag === tagType && position === \"end\";\n}\n\nfunction isParagraphStart(options) {\n return isTagStart(\"w:p\", options) || isTagStart(\"a:p\", options);\n}\n\nfunction isParagraphEnd(options) {\n return isTagEnd(\"w:p\", options) || isTagEnd(\"a:p\", options);\n}\n\nfunction isTextStart(part) {\n return part.type === \"tag\" && part.position === \"start\" && part.text;\n}\n\nfunction isTextEnd(part) {\n return part.type === \"tag\" && part.position === \"end\" && part.text;\n}\n\nfunction isContent(p) {\n return p.type === \"placeholder\" || p.type === \"content\" && p.position === \"insidetag\";\n}\n\nvar corruptCharacters = /[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F]/; // 00 NUL '\\0' (null character)\n// 01 SOH (start of heading)\n// 02 STX (start of text)\n// 03 ETX (end of text)\n// 04 EOT (end of transmission)\n// 05 ENQ (enquiry)\n// 06 ACK (acknowledge)\n// 07 BEL '\\a' (bell)\n// 08 BS '\\b' (backspace)\n// 0B VT '\\v' (vertical tab)\n// 0C FF '\\f' (form feed)\n// 0E SO (shift out)\n// 0F SI (shift in)\n// 10 DLE (data link escape)\n// 11 DC1 (device control 1)\n// 12 DC2 (device control 2)\n// 13 DC3 (device control 3)\n// 14 DC4 (device control 4)\n// 15 NAK (negative ack.)\n// 16 SYN (synchronous idle)\n// 17 ETB (end of trans. blk)\n// 18 CAN (cancel)\n// 19 EM (end of medium)\n// 1A SUB (substitute)\n// 1B ESC (escape)\n// 1C FS (file separator)\n// 1D GS (group separator)\n// 1E RS (record separator)\n// 1F US (unit separator)\n\nfunction hasCorruptCharacters(string) {\n return corruptCharacters.test(string);\n}\n\nfunction invertMap(map) {\n return Object.keys(map).reduce(function (invertedMap, key) {\n var value = map[key];\n invertedMap[value] = invertedMap[value] || [];\n invertedMap[value].push(key);\n return invertedMap;\n }, {});\n}\n\nmodule.exports = {\n endsWith: endsWith,\n startsWith: startsWith,\n getNearestLeft: getNearestLeft,\n getNearestRight: getNearestRight,\n getNearestLeftWithCache: getNearestLeftWithCache,\n getNearestRightWithCache: getNearestRightWithCache,\n getNearestLeftIndex: getNearestLeftIndex,\n getNearestRightIndex: getNearestRightIndex,\n getNearestLeftIndexWithCache: getNearestLeftIndexWithCache,\n getNearestRightIndexWithCache: getNearestRightIndexWithCache,\n buildNearestCache: buildNearestCache,\n isContent: isContent,\n isParagraphStart: isParagraphStart,\n isParagraphEnd: isParagraphEnd,\n isTagStart: isTagStart,\n isTagEnd: isTagEnd,\n isTextStart: isTextStart,\n isTextEnd: isTextEnd,\n unique: unique,\n chunkBy: chunkBy,\n last: last,\n first: first,\n mergeObjects: mergeObjects,\n xml2str: xml2str,\n str2xml: str2xml,\n getRightOrNull: getRightOrNull,\n getRight: getRight,\n getLeftOrNull: getLeftOrNull,\n getLeft: getLeft,\n pregMatchAll: pregMatchAll,\n convertSpaces: convertSpaces,\n escapeRegExp: escapeRegExp,\n charMapRegexes: charMapRegexes,\n hasCorruptCharacters: hasCorruptCharacters,\n defaults: defaults,\n wordToUtf8: wordToUtf8,\n utf8ToWord: utf8ToWord,\n concatArrays: concatArrays,\n invertMap: invertMap,\n charMap: charMap\n};\n\n//# sourceURL=webpack://docxtemplater/./es6/doc-utils.js?"); /***/ }), /***/ "./es6/docxtemplater.js": /*!******************************!*\ !*** ./es6/docxtemplater.js ***! \******************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; eval("\n\nvar _excluded = [\"modules\"];\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar DocUtils = __webpack_require__(/*! ./doc-utils.js */ \"./es6/doc-utils.js\");\n\nDocUtils.traits = __webpack_require__(/*! ./traits.js */ \"./es6/traits.js\");\nDocUtils.moduleWrapper = __webpack_require__(/*! ./module-wrapper.js */ \"./es6/module-wrapper.js\");\n\nvar createScope = __webpack_require__(/*! ./scope-manager.js */ \"./es6/scope-manager.js\");\n\nvar _require = __webpack_require__(/*! ./errors.js */ \"./es6/errors.js\"),\n throwMultiError = _require.throwMultiError,\n throwResolveBeforeCompile = _require.throwResolveBeforeCompile,\n throwRenderInvalidTemplate = _require.throwRenderInvalidTemplate;\n\nvar collectContentTypes = __webpack_require__(/*! ./collect-content-types.js */ \"./es6/collect-content-types.js\");\n\nvar ctXML = \"[Content_Types].xml\";\n\nvar commonModule = __webpack_require__(/*! ./modules/common.js */ \"./es6/modules/common.js\");\n\nvar Lexer = __webpack_require__(/*! ./lexer.js */ \"./es6/lexer.js\");\n\nvar defaults = DocUtils.defaults,\n str2xml = DocUtils.str2xml,\n xml2str = DocUtils.xml2str,\n moduleWrapper = DocUtils.moduleWrapper,\n concatArrays = DocUtils.concatArrays,\n unique = DocUtils.unique;\n\nvar _require2 = __webpack_require__(/*! ./errors.js */ \"./es6/errors.js\"),\n XTInternalError = _require2.XTInternalError,\n throwFileTypeNotIdentified = _require2.throwFileTypeNotIdentified,\n throwFileTypeNotHandled = _require2.throwFileTypeNotHandled,\n throwApiVersionError = _require2.throwApiVersionError;\n\nvar currentModuleApiVersion = [3, 26, 0];\n\nvar Docxtemplater = /*#__PURE__*/function () {\n function Docxtemplater(zip) {\n var _this = this;\n\n var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},\n _ref$modules = _ref.modules,\n modules = _ref$modules === void 0 ? [] : _ref$modules,\n options = _objectWithoutProperties(_ref, _excluded);\n\n _classCallCheck(this, Docxtemplater);\n\n if (!Array.isArray(modules)) {\n throw new Error(\"The modules argument of docxtemplater's constructor must be an array\");\n }\n\n this.scopeManagers = {};\n this.compiled = {};\n this.modules = [commonModule()];\n this.setOptions(options);\n modules.forEach(function (module) {\n _this.attachModule(module);\n });\n\n if (arguments.length > 0) {\n if (!zip || !zip.files || typeof zip.file !== \"function\") {\n throw new Error(\"The first argument of docxtemplater's constructor must be a valid zip file (jszip v2 or pizzip v3)\");\n }\n\n this.loadZip(zip); // remove the unsupported modules\n\n this.modules = this.modules.filter(function (module) {\n if (module.supportedFileTypes) {\n if (!Array.isArray(module.supportedFileTypes)) {\n throw new Error(\"The supportedFileTypes field of the module must be an array\");\n }\n\n var isSupportedModule = module.supportedFileTypes.indexOf(_this.fileType) !== -1;\n\n if (!isSupportedModule) {\n module.on(\"detached\");\n }\n\n return isSupportedModule;\n }\n\n return true;\n });\n this.compile();\n this.v4Constructor = true;\n }\n }\n\n _createClass(Docxtemplater, [{\n key: \"getModuleApiVersion\",\n value: function getModuleApiVersion() {\n return currentModuleApiVersion.join(\".\");\n }\n }, {\n key: \"verifyApiVersion\",\n value: function verifyApiVersion(neededVersion) {\n neededVersion = neededVersion.split(\".\").map(function (i) {\n return parseInt(i, 10);\n });\n\n if (neededVersion.length !== 3) {\n throwApiVersionError(\"neededVersion is not a valid version\", {\n neededVersion: neededVersion,\n explanation: \"the neededVersion must be an array of length 3\"\n });\n }\n\n if (neededVersion[0] !== currentModuleApiVersion[0]) {\n throwApiVersionError(\"The major api version do not match, you probably have to update docxtemplater with npm install --save docxtemplater\", {\n neededVersion: neededVersion,\n currentModuleApiVersion: currentModuleApiVersion,\n explanation: \"moduleAPIVersionMismatch : needed=\".concat(neededVersion.join(\".\"), \", current=\").concat(currentModuleApiVersion.join(\".\"))\n });\n }\n\n if (neededVersion[1] > currentModuleApiVersion[1]) {\n throwApiVersionError(\"The minor api version is not uptodate, you probably have to update docxtemplater with npm install --save docxtemplater\", {\n neededVersion: neededVersion,\n currentModuleApiVersion: currentModuleApiVersion,\n explanation: \"moduleAPIVersionMismatch : needed=\".concat(neededVersion.join(\".\"), \", current=\").concat(currentModuleApiVersion.join(\".\"))\n });\n }\n\n if (neededVersion[1] === currentModuleApiVersion[1] && neededVersion[2] > currentModuleApiVersion[2]) {\n throwApiVersionError(\"The patch api version is not uptodate, you probably have to update docxtemplater with npm install --save docxtemplater\", {\n neededVersion: neededVersion,\n currentModuleApiVersion: currentModuleApiVersion,\n explanation: \"moduleAPIVersionMismatch : needed=\".concat(neededVersion.join(\".\"), \", current=\").concat(currentModuleApiVersion.join(\".\"))\n });\n }\n\n return true;\n }\n }, {\n key: \"setModules\",\n value: function setModules(obj) {\n this.modules.forEach(function (module) {\n module.set(obj);\n });\n }\n }, {\n key: \"sendEvent\",\n value: function sendEvent(eventName) {\n this.modules.forEach(function (module) {\n module.on(eventName);\n });\n }\n }, {\n key: \"attachModule\",\n value: function attachModule(module) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n\n if (this.v4Constructor) {\n throw new Error(\"attachModule() should not be called manually when using the v4 constructor\");\n }\n\n if (module.requiredAPIVersion) {\n this.verifyApiVersion(module.requiredAPIVersion);\n }\n\n if (module.attached === true) {\n throw new Error(\"Cannot attach a module that was already attached : \\\"\".concat(module.name, \"\\\". Maybe you are instantiating the module at the root level, and using it for multiple instances of Docxtemplater\"));\n }\n\n module.attached = true;\n var prefix = options.prefix;\n\n if (prefix) {\n module.prefix = prefix;\n }\n\n var wrappedModule = moduleWrapper(module);\n this.modules.push(wrappedModule);\n wrappedModule.on(\"attached\");\n return this;\n }\n }, {\n key: \"setOptions\",\n value: function setOptions(options) {\n var _this2 = this;\n\n if (this.v4Constructor) {\n throw new Error(\"setOptions() should not be called manually when using the v4 constructor\");\n }\n\n if (!options) {\n throw new Error(\"setOptions should be called with an object as first parameter\");\n }\n\n this.options = {};\n Object.keys(defaults).forEach(function (key) {\n var defaultValue = defaults[key];\n _this2.options[key] = options[key] != null ? options[key] : defaultValue;\n _this2[key] = _this2.options[key];\n });\n\n if (this.zip) {\n this.updateFileTypeConfig();\n }\n\n return this;\n }\n }, {\n key: \"loadZip\",\n value: function loadZip(zip) {\n if (zip.loadAsync) {\n throw new XTInternalError(\"Docxtemplater doesn't handle JSZip version >=3, please use pizzip\");\n }\n\n this.zip = zip;\n this.updateFileTypeConfig();\n this.modules = concatArrays([this.fileTypeConfig.baseModules.map(function (moduleFunction) {\n return moduleFunction();\n }), this.modules]);\n return this;\n }\n }, {\n key: \"compileFile\",\n value: function compileFile(fileName) {\n this.compiled[fileName].parse();\n }\n }, {\n key: \"precompileFile\",\n value: function precompileFile(fileName) {\n var currentFile = this.createTemplateClass(fileName);\n currentFile.preparse();\n this.compiled[fileName] = currentFile;\n }\n }, {\n key: \"getScopeManager\",\n value: function getScopeManager(to, currentFile, tags) {\n if (!this.scopeManagers[to]) {\n this.scopeManagers[to] = createScope({\n tags: tags || {},\n parser: this.parser,\n cachedParsers: currentFile.cachedParsers\n });\n }\n\n return this.scopeManagers[to];\n }\n }, {\n key: \"resolveData\",\n value: function resolveData(data) {\n var _this3 = this;\n\n var errors = [];\n\n if (!Object.keys(this.compiled).length) {\n throwResolveBeforeCompile();\n }\n\n return Promise.resolve(data).then(function (data) {\n _this3.setData(data);\n\n _this3.setModules({\n data: _this3.data,\n Lexer: Lexer\n });\n\n _this3.mapper = _this3.modules.reduce(function (value, module) {\n return module.getRenderedMap(value);\n }, {});\n return Promise.all(Object.keys(_this3.mapper).map(function (to) {\n var _this3$mapper$to = _this3.mapper[to],\n from = _this3$mapper$to.from,\n data = _this3$mapper$to.data;\n return Promise.resolve(data).then(function (data) {\n var currentFile = _this3.compiled[from];\n currentFile.filePath = to;\n currentFile.scopeManager = _this3.getScopeManager(to, currentFile, data);\n currentFile.scopeManager.resolved = [];\n return currentFile.resolveTags(data).then(function (result) {\n currentFile.scopeManager.finishedResolving = true;\n return result;\n }, function (errs) {\n errors = errors.concat(errs);\n });\n });\n })).then(function (resolved) {\n if (errors.length !== 0) {\n throwMultiError(errors);\n }\n\n return concatArrays(resolved);\n });\n });\n }\n }, {\n key: \"compile\",\n value: function compile() {\n var _this4 = this;\n\n if (Object.keys(this.compiled).length) {\n return this;\n }\n\n this.options = this.modules.reduce(function (options, module) {\n return module.optionsTransformer(options, _this4);\n }, this.options);\n this.options.xmlFileNames = unique(this.options.xmlFileNames);\n this.xmlDocuments = this.options.xmlFileNames.reduce(function (xmlDocuments, fileName) {\n var content = _this4.zip.files[fileName].asText();\n\n xmlDocuments[fileName] = str2xml(content);\n return xmlDocuments;\n }, {});\n this.setModules({\n zip: this.zip,\n xmlDocuments: this.xmlDocuments\n });\n this.getTemplatedFiles();\n this.setModules({\n compiled: this.compiled\n }); // Loop inside all templatedFiles (ie xml files with content).\n // Sometimes they don't exist (footer.xml for example)\n\n this.templatedFiles.forEach(function (fileName) {\n if (_this4.zip.files[fileName] != null) {\n _this4.precompileFile(fileName);\n }\n });\n this.templatedFiles.forEach(function (fileName) {\n if (_this4.zip.files[fileName] != null) {\n _this4.compileFile(fileName);\n }\n });\n verifyErrors(this);\n return this;\n }\n }, {\n key: \"updateFileTypeConfig\",\n value: function updateFileTypeConfig() {\n var _this5 = this;\n\n var fileType;\n\n if (this.zip.files.mimetype) {\n fileType = \"odt\";\n }\n\n var contentTypes = this.zip.files[ctXML];\n this.targets = [];\n var contentTypeXml = contentTypes ? str2xml(contentTypes.asText()) : null;\n var overrides = contentTypeXml ? contentTypeXml.getElementsByTagName(\"Override\") : null;\n var defaults = contentTypeXml ? contentTypeXml.getElementsByTagName(\"Default\") : null;\n\n if (contentTypeXml) {\n this.filesContentTypes = collectContentTypes(overrides, defaults, this.zip);\n this.invertedContentTypes = DocUtils.invertMap(this.filesContentTypes);\n this.setModules({\n contentTypes: this.contentTypes,\n invertedContentTypes: this.invertedContentTypes\n });\n }\n\n this.modules.forEach(function (module) {\n fileType = module.getFileType({\n zip: _this5.zip,\n contentTypes: contentTypes,\n contentTypeXml: contentTypeXml,\n overrides: overrides,\n defaults: defaults,\n doc: _this5\n }) || fileType;\n });\n\n if (fileType === \"odt\") {\n throwFileTypeNotHandled(fileType);\n }\n\n if (!fileType) {\n throwFileTypeNotIdentified();\n }\n\n this.fileType = fileType;\n this.fileTypeConfig = this.options.fileTypeConfig || this.fileTypeConfig || Docxtemplater.FileTypeConfig[this.fileType]();\n return this;\n }\n }, {\n key: \"render\",\n value: function render() {\n var _this6 = this;\n\n this.compile();\n\n if (this.errors.length > 0) {\n throwRenderInvalidTemplate();\n }\n\n this.setModules({\n data: this.data,\n Lexer: Lexer\n });\n\n if (!this.mapper) {\n this.mapper = this.modules.reduce(function (value, module) {\n return module.getRenderedMap(value);\n }, {});\n }\n\n this.fileTypeConfig.tagsXmlLexedArray = unique(this.fileTypeConfig.tagsXmlLexedArray);\n this.fileTypeConfig.tagsXmlTextArray = unique(this.fileTypeConfig.tagsXmlTextArray);\n Object.keys(this.mapper).forEach(function (to) {\n var _this6$mapper$to = _this6.mapper[to],\n from = _this6$mapper$to.from,\n data = _this6$mapper$to.data;\n var currentFile = _this6.compiled[from];\n currentFile.setTags(data);\n currentFile.scopeManager = _this6.getScopeManager(to, currentFile, data);\n currentFile.render(to);\n\n _this6.zip.file(to, currentFile.content, {\n createFolders: true\n });\n });\n verifyErrors(this);\n this.sendEvent(\"syncing-zip\");\n this.syncZip();\n return this;\n }\n }, {\n key: \"syncZip\",\n value: function syncZip() {\n var _this7 = this;\n\n Object.keys(this.xmlDocuments).forEach(function (fileName) {\n _this7.zip.remove(fileName);\n\n var content = xml2str(_this7.xmlDocuments[fileName]);\n return _this7.zip.file(fileName, content, {\n createFolders: true\n });\n });\n }\n }, {\n key: \"setData\",\n value: function setData(data) {\n this.data = data;\n return this;\n }\n }, {\n key: \"getZip\",\n value: function getZip() {\n return this.zip;\n }\n }, {\n key: \"createTemplateClass\",\n value: function createTemplateClass(path) {\n var content = this.zip.files[path].asText();\n return this.createTemplateClassFromContent(content, path);\n }\n }, {\n key: \"createTemplateClassFromContent\",\n value: function createTemplateClassFromContent(content, filePath) {\n var _this8 = this;\n\n var xmltOptions = {\n filePath: filePath,\n contentType: this.filesContentTypes[filePath]\n };\n Object.keys(defaults).concat([\"filesContentTypes\", \"fileTypeConfig\", \"modules\"]).forEach(function (key) {\n xmltOptions[key] = _this8[key];\n });\n return new Docxtemplater.XmlTemplater(content, xmltOptions);\n }\n }, {\n key: \"getFullText\",\n value: function getFullText(path) {\n return this.createTemplateClass(path || this.fileTypeConfig.textPath(this)).getFullText();\n }\n }, {\n key: \"getTemplatedFiles\",\n value: function getTemplatedFiles() {\n var _this9 = this;\n\n this.templatedFiles = this.fileTypeConfig.getTemplatedFiles(this.zip);\n this.targets.forEach(function (target) {\n _this9.templatedFiles.push(target);\n });\n return this.templatedFiles;\n }\n }]);\n\n return Docxtemplater;\n}();\n\nfunction verifyErrors(doc) {\n var compiled = doc.compiled;\n var allErrors = [];\n Object.keys(compiled).forEach(function (name) {\n var templatePart = compiled[name];\n allErrors = concatArrays([allErrors, templatePart.allErrors]);\n });\n doc.errors = allErrors;\n\n if (allErrors.length !== 0) {\n throwMultiError(allErrors);\n }\n}\n\nDocxtemplater.DocUtils = DocUtils;\nDocxtemplater.Errors = __webpack_require__(/*! ./errors.js */ \"./es6/errors.js\");\nDocxtemplater.XmlTemplater = __webpack_require__(/*! ./xml-templater.js */ \"./es6/xml-templater.js\");\nDocxtemplater.FileTypeConfig = __webpack_require__(/*! ./file-type-config.js */ \"./es6/file-type-config.js\");\nDocxtemplater.XmlMatcher = __webpack_require__(/*! ./xml-matcher.js */ \"./es6/xml-matcher.js\");\nmodule.exports = Docxtemplater;\n\n//# sourceURL=webpack://docxtemplater/./es6/docxtemplater.js?"); /***/ }), /***/ "./es6/errors.js": /*!***********************!*\ !*** ./es6/errors.js ***! \***********************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { "use strict"; eval("\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nvar _require = __webpack_require__(/*! ./utils.js */ \"./es6/utils.js\"),\n last = _require.last,\n first = _require.first;\n\nfunction XTError(message) {\n this.name = \"GenericError\";\n this.message = message;\n this.stack = new Error(message).stack;\n}\n\nXTError.prototype = Error.prototype;\n\nfunction XTTemplateError(message) {\n this.name = \"TemplateError\";\n this.message = message;\n this.stack = new Error(message).stack;\n}\n\nXTTemplateError.prototype = new XTError();\n\nfunction XTRenderingError(message) {\n this.name = \"RenderingError\";\n this.message = message;\n this.stack = new Error(message).stack;\n}\n\nXTRenderingError.prototype = new XTError();\n\nfunction XTScopeParserError(message) {\n this.name = \"ScopeParserError\";\n this.message = message;\n this.stack = new Error(message).stack;\n}\n\nXTScopeParserError.prototype = new XTError();\n\nfunction XTInternalError(message) {\n this.name = \"InternalError\";\n this.properties = {\n explanation: \"InternalError\"\n };\n this.message = message;\n this.stack = new Error(message).stack;\n}\n\nXTInternalError.prototype = new XTError();\n\nfunction XTAPIVersionError(message) {\n this.name = \"APIVersionError\";\n this.properties = {\n explanation: \"APIVersionError\"\n };\n this.message = message;\n this.stack = new Error(message).stack;\n}\n\nXTAPIVersionError.prototype = new XTError();\n\nfunction throwApiVersionError(msg, properties) {\n var err = new XTAPIVersionError(msg);\n err.properties = _objectSpread({\n id: \"api_version_error\"\n }, properties);\n throw err;\n}\n\nfunction throwMultiError(errors) {\n var err = new XTTemplateError(\"Multi error\");\n err.properties = {\n errors: errors,\n id: \"multi_error\",\n explanation: \"The template has multiple errors\"\n };\n throw err;\n}\n\nfunction getUnopenedTagException(options) {\n var err = new XTTemplateError(\"Unopened tag\");\n err.properties = {\n xtag: last(options.xtag.split(\" \")),\n id: \"unopened_tag\",\n context: options.xtag,\n offset: options.offset,\n lIndex: options.lIndex,\n explanation: \"The tag beginning with \\\"\".concat(options.xtag.substr(0, 10), \"\\\" is unopened\")\n };\n return err;\n}\n\nfunction getDuplicateOpenTagException(options) {\n var err = new XTTemplateError(\"Duplicate open tag, expected one open tag\");\n err.properties = {\n xtag: first(options.xtag.split(\" \")),\n id: \"duplicate_open_tag\",\n context: options.xtag,\n offset: options.offset,\n lIndex: options.lIndex,\n explanation: \"The tag beginning with \\\"\".concat(options.xtag.substr(0, 10), \"\\\" has duplicate open tags\")\n };\n return err;\n}\n\nfunction getDuplicateCloseTagException(options) {\n var err = new XTTemplateError(\"Duplicate close tag, expected one close tag\");\n err.properties = {\n xtag: first(options.xtag.split(\" \")),\n id: \"duplicate_close_tag\",\n context: options.xtag,\n offset: options.offset,\n lIndex: options.lIndex,\n explanation: \"The tag ending with \\\"\".concat(options.xtag.substr(0, 10), \"\\\" has duplicate close tags\")\n };\n return err;\n}\n\nfunction getUnclosedTagException(options) {\n var err = new XTTemplateError(\"Unclosed tag\");\n err.properties = {\n xtag: first(options.xtag.split(\" \")).substr(1),\n id: \"unclosed_tag\",\n context: options.xtag,\n offset: options.offset,\n lIndex: options.lIndex,\n explanation: \"The tag beginning with \\\"\".concat(options.xtag.substr(0, 10), \"\\\" is unclosed\")\n };\n return err;\n}\n\nfunction throwXmlTagNotFound(options) {\n var err = new XTTemplateError(\"No tag \\\"\".concat(options.element, \"\\\" was found at the \").concat(options.position));\n var part = options.parsed[options.index];\n err.properties = {\n id: \"no_xml_tag_found_at_\".concat(options.position),\n explanation: \"No tag \\\"\".concat(options.element, \"\\\" was found at the \").concat(options.position),\n offset: part.offset,\n part: part,\n parsed: options.parsed,\n index: options.index,\n element: options.element\n };\n throw err;\n}\n\nfunction getCorruptCharactersException(_ref) {\n var tag = _ref.tag,\n value = _ref.value,\n offset = _ref.offset;\n var err = new XTRenderingError(\"There are some XML corrupt characters\");\n err.properties = {\n id: \"invalid_xml_characters\",\n xtag: tag,\n value: value,\n offset: offset,\n explanation: \"There are some corrupt characters for the field ${tag}\"\n };\n return err;\n}\n\nfunction throwContentMustBeString(type) {\n var err = new XTInternalError(\"Content must be a string\");\n err.properties.id = \"xmltemplater_content_must_be_string\";\n err.properties.type = type;\n throw err;\n}\n\nfunction throwExpandNotFound(options) {\n var _options$part = options.part,\n value = _options$part.value,\n offset = _options$part.offset,\n _options$id = options.id,\n id = _options$id === void 0 ? \"raw_tag_outerxml_invalid\" : _options$id,\n _options$message = options.message,\n message = _options$message === void 0 ? \"Raw tag not in paragraph\" : _options$message;\n var part = options.part;\n var _options$explanation = options.explanation,\n explanation = _options$explanation === void 0 ? \"The tag \\\"\".concat(value, \"\\\" is not inside a paragraph\") : _options$explanation;\n\n if (typeof explanation === \"function\") {\n explanation = explanation(part);\n }\n\n var err = new XTTemplateError(message);\n err.properties = {\n id: id,\n explanation: explanation,\n rootError: options.rootError,\n xtag: value,\n offset: offset,\n postparsed: options.postparsed,\n expandTo: options.expandTo,\n index: options.index\n };\n throw err;\n}\n\nfunction throwRawTagShouldBeOnlyTextInParagraph(options) {\n var err = new XTTemplateError(\"Raw tag should be the only text in paragraph\");\n var tag = options.part.value;\n err.properties = {\n id: \"raw_xml_tag_should_be_only_text_in_paragraph\",\n explanation: \"The raw tag \\\"\".concat(tag, \"\\\" should be the only text in this paragraph. This means that this tag should not be surrounded by any text or spaces.\"),\n xtag: tag,\n offset: options.part.offset,\n paragraphParts: options.paragraphParts\n };\n throw err;\n}\n\nfunction getUnmatchedLoopException(part) {\n var location = part.location,\n offset = part.offset;\n var t = location === \"start\" ? \"unclosed\" : \"unopened\";\n var T = location === \"start\" ? \"Unclosed\" : \"Unopened\";\n var err = new XTTemplateError(\"\".concat(T, \" loop\"));\n var tag = part.value;\n err.properties = {\n id: \"\".concat(t, \"_loop\"),\n explanation: \"The loop with tag \\\"\".concat(tag, \"\\\" is \").concat(t),\n xtag: tag,\n offset: offset\n };\n return err;\n}\n\nfunction getUnbalancedLoopException(pair, lastPair) {\n var err = new XTTemplateError(\"Unbalanced loop tag\");\n var lastL = lastPair[0].part.value;\n var lastR = lastPair[1].part.value;\n var l = pair[0].part.value;\n var r = pair[1].part.value;\n err.properties = {\n id: \"unbalanced_loop_tags\",\n explanation: \"Unbalanced loop tags {#\".concat(lastL, \"}{/\").concat(lastR, \"}{#\").concat(l, \"}{/\").concat(r, \"}\"),\n offset: [lastPair[0].part.offset, pair[1].part.offset],\n lastPair: {\n left: lastPair[0].part.value,\n right: lastPair[1].part.value\n },\n pair: {\n left: pair[0].part.value,\n right: pair[1].part.value\n }\n };\n return err;\n}\n\nfunction getClosingTagNotMatchOpeningTag(_ref2) {\n var tags = _ref2.tags;\n var err = new XTTemplateError(\"Closing tag does not match opening tag\");\n err.properties = {\n id: \"closing_tag_does_not_match_opening_tag\",\n explanation: \"The tag \\\"\".concat(tags[0].value, \"\\\" is closed by the tag \\\"\").concat(tags[1].value, \"\\\"\"),\n openingtag: first(tags).value,\n offset: [first(tags).offset, last(tags).offset],\n closingtag: last(tags).value\n };\n return err;\n}\n\nfunction getScopeCompilationError(_ref3) {\n var tag = _ref3.tag,\n rootError = _ref3.rootError,\n offset = _ref3.offset;\n var err = new XTScopeParserError(\"Scope parser compilation failed\");\n err.properties = {\n id: \"scopeparser_compilation_failed\",\n offset: offset,\n tag: tag,\n explanation: \"The scope parser for the tag \\\"\".concat(tag, \"\\\" failed to compile\"),\n rootError: rootError\n };\n return err;\n}\n\nfunction getScopeParserExecutionError(_ref4) {\n var tag = _ref4.tag,\n scope = _ref4.scope,\n error = _ref4.error,\n offset = _ref4.offset;\n var err = new XTScopeParserError(\"Scope parser execution failed\");\n err.properties = {\n id: \"scopeparser_execution_failed\",\n explanation: \"The scope parser for the tag \".concat(tag, \" failed to execute\"),\n scope: scope,\n offset: offset,\n tag: tag,\n rootError: error\n };\n return err;\n}\n\nfunction getLoopPositionProducesInvalidXMLError(_ref5) {\n var tag = _ref5.tag,\n offset = _ref5.offset;\n var err = new XTTemplateError(\"The position of the loop tags \\\"\".concat(tag, \"\\\" would produce invalid XML\"));\n err.properties = {\n tag: tag,\n id: \"loop_position_invalid\",\n explanation: \"The tags \\\"\".concat(tag, \"\\\" are misplaced in the document, for example one of them is in a table and the other one outside the table\"),\n offset: offset\n };\n return err;\n}\n\nfunction throwUnimplementedTagType(part, index) {\n var errorMsg = \"Unimplemented tag type \\\"\".concat(part.type, \"\\\"\");\n\n if (part.module) {\n errorMsg += \" \\\"\".concat(part.module, \"\\\"\");\n }\n\n var err = new XTTemplateError(errorMsg);\n err.properties = {\n part: part,\n index: index,\n id: \"unimplemented_tag_type\"\n };\n throw err;\n}\n\nfunction throwMalformedXml(part) {\n var err = new XTInternalError(\"Malformed xml\");\n err.properties = {\n part: part,\n id: \"malformed_xml\"\n };\n throw err;\n}\n\nfunction throwLocationInvalid(part) {\n throw new XTInternalError(\"Location should be one of \\\"start\\\" or \\\"end\\\" (given : \".concat(part.location, \")\"));\n}\n\nfunction throwResolveBeforeCompile() {\n var err = new XTInternalError(\"You must run `.compile()` before running `.resolveData()`\");\n err.properties = {\n id: \"resolve_before_compile\"\n };\n throw err;\n}\n\nfunction throwRenderInvalidTemplate() {\n var err = new XTInternalError(\"You should not call .render on a document that had compilation errors\");\n err.properties = {\n id: \"render_on_invalid_template\"\n };\n throw err;\n}\n\nfunction throwFileTypeNotIdentified() {\n var err = new XTInternalError(\"The filetype for this file could not be identified, is this file corrupted ?\");\n err.properties = {\n id: \"filetype_not_identified\"\n };\n throw err;\n}\n\nfunction throwXmlInvalid(content, offset) {\n var err = new XTTemplateError(\"An XML file has invalid xml\");\n err.properties = {\n id: \"file_has_invalid_xml\",\n content: content,\n offset: offset,\n explanation: \"The docx contains invalid XML, it is most likely corrupt\"\n };\n throw err;\n}\n\nfunction throwFileTypeNotHandled(fileType) {\n var err = new XTInternalError(\"The filetype \\\"\".concat(fileType, \"\\\" is not handled by docxtemplater\"));\n err.properties = {\n id: \"filetype_not_handled\",\n explanation: \"The file you are trying to generate is of type \\\"\".concat(fileType, \"\\\", but only docx and pptx formats are handled\"),\n fileType: fileType\n };\n throw err;\n}\n\nmodule.exports = {\n XTError: XTError,\n XTTemplateError: XTTemplateError,\n XTInternalError: XTInternalError,\n XTScopeParserError: XTScopeParserError,\n XTAPIVersionError: XTAPIVersionError,\n // Remove this alias in v4\n RenderingError: XTRenderingError,\n XTRenderingError: XTRenderingError,\n getClosingTagNotMatchOpeningTag: getClosingTagNotMatchOpeningTag,\n getLoopPositionProducesInvalidXMLError: getLoopPositionProducesInvalidXMLError,\n getScopeCompilationError: getScopeCompilationError,\n getScopeParserExecutionError: getScopeParserExecutionError,\n getUnclosedTagException: getUnclosedTagException,\n getUnopenedTagException: getUnopenedTagException,\n getUnmatchedLoopException: getUnmatchedLoopException,\n getDuplicateCloseTagException: getDuplicateCloseTagException,\n getDuplicateOpenTagException: getDuplicateOpenTagException,\n getCorruptCharactersException: getCorruptCharactersException,\n getUnbalancedLoopException: getUnbalanced