@digipair/skill-docxtemplater 0.136.3 → 0.136.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -714,11 +714,6 @@ if (UNICODE_SUPPORT) {
714
714
  // eslint-disable-next-line es5/no-unicode-code-point-escape
715
715
  Char = reg('[', chars(Char), '\\u{10000}-\\u{10FFFF}', ']');
716
716
  }
717
- // Negation of Char: matches any character that is NOT a valid XML 1.0 Char.
718
- // Derived directly from the Char character class above (after the unicode-support extension).
719
- // XML 1.0 Char production [2]: #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
720
- // @see https://www.w3.org/TR/xml/#NT-Char
721
- var InvalidChar = new RegExp('[^' + chars(Char) + ']', UNICODE_SUPPORT ? 'u' : '');
722
717
  var _SChar = /[\x20\x09\x0D\x0A]/;
723
718
  var SChar_s = chars(_SChar);
724
719
  // https://www.w3.org/TR/xml11/#NT-S
@@ -926,12 +921,6 @@ var PUBLIC = 'PUBLIC';
926
921
  // `[75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral`
927
922
  var ExternalID = regg(regg(SYSTEM, S, SystemLiteral), '|', regg(PUBLIC, S, PubidLiteral, S, SystemLiteral));
928
923
  var ExternalID_match = reg('^', regg(regg(SYSTEM, S, '(?<SystemLiteralOnly>', SystemLiteral, ')'), '|', regg(PUBLIC, S, '(?<PubidLiteral>', PubidLiteral, ')', S, '(?<SystemLiteral>', SystemLiteral, ')')));
929
- // Full-string anchored matcher for requireWellFormed serializer checks
930
- // https://w3c.github.io/DOM-Parsing/#xml-serializing-a-document-node
931
- var PubidLiteral_match = reg('^', PubidLiteral, '$');
932
- // Full-string anchored matcher for requireWellFormed serializer checks
933
- // https://w3c.github.io/DOM-Parsing/#xml-serializing-a-document-node
934
- var SystemLiteral_match = reg('^', SystemLiteral, '$');
935
924
  // https://www.w3.org/TR/xml11/#NT-NDataDecl
936
925
  // `[76] NDataDecl ::= S 'NDATA' S Name` [VC: Notation Declared]
937
926
  var NDataDecl = regg(S, 'NDATA', S, Name);
@@ -1043,7 +1032,6 @@ grammar.PEReference = PEReference;
1043
1032
  grammar.PI = PI;
1044
1033
  grammar.PUBLIC = PUBLIC;
1045
1034
  grammar.PubidLiteral = PubidLiteral;
1046
- grammar.PubidLiteral_match = PubidLiteral_match;
1047
1035
  grammar.QName = QName;
1048
1036
  grammar.QName_exact = QName_exact;
1049
1037
  grammar.QName_group = QName_group;
@@ -1052,8 +1040,6 @@ grammar.SChar_s = SChar_s;
1052
1040
  grammar.S_OPT = S_OPT;
1053
1041
  grammar.SYSTEM = SYSTEM;
1054
1042
  grammar.SystemLiteral = SystemLiteral;
1055
- grammar.SystemLiteral_match = SystemLiteral_match;
1056
- grammar.InvalidChar = InvalidChar;
1057
1043
  grammar.UNICODE_REPLACEMENT_CHARACTER = UNICODE_REPLACEMENT_CHARACTER;
1058
1044
  grammar.UNICODE_SUPPORT = UNICODE_SUPPORT;
1059
1045
  grammar.XMLDecl = XMLDecl;
@@ -1363,38 +1349,13 @@ NodeList.prototype = {
1363
1349
  /**
1364
1350
  * Returns a string representation of the NodeList.
1365
1351
  *
1366
- * Accepts the same `options` object as `XMLSerializer.prototype.serializeToString`
1367
- * (`requireWellFormed`, `splitCDATASections`, `nodeFilter`). Passing a function is treated as
1368
- * a legacy `nodeFilter` for backward compatibility.
1369
- *
1370
- * @param {Object | function} [options]
1371
- * @param {boolean} [options.requireWellFormed=false]
1372
- * @param {boolean} [options.splitCDATASections=true]
1373
- * @param {function} [options.nodeFilter]
1352
+ * @param {unknown} nodeFilter
1353
+ * __A filter function? Not implemented according to the spec?__.
1374
1354
  * @returns {string}
1375
- */ toString: function toString(options) {
1376
- var opts;
1377
- if (typeof options === 'function') {
1378
- opts = {
1379
- requireWellFormed: false,
1380
- splitCDATASections: true,
1381
- nodeFilter: options
1382
- };
1383
- } else if (!!options) {
1384
- opts = {
1385
- requireWellFormed: !!options.requireWellFormed,
1386
- splitCDATASections: options.splitCDATASections !== false,
1387
- nodeFilter: options.nodeFilter || null
1388
- };
1389
- } else {
1390
- opts = {
1391
- requireWellFormed: false,
1392
- splitCDATASections: true,
1393
- nodeFilter: null
1394
- };
1395
- }
1355
+ * A string representation of the NodeList.
1356
+ */ toString: function toString(nodeFilter) {
1396
1357
  for(var buf = [], i = 0; i < this.length; i++){
1397
- serializeToString(this[i], buf, null, opts);
1358
+ serializeToString(this[i], buf, nodeFilter);
1398
1359
  }
1399
1360
  return buf.join('');
1400
1361
  },
@@ -1894,21 +1855,11 @@ DOMImplementation$1.prototype = {
1894
1855
  * The {@link https://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-qualifiedname qualified
1895
1856
  * name} of the document type to be created.
1896
1857
  * @param {string} [publicId]
1897
- * The external subset public identifier. Stored verbatim including surrounding quotes.
1898
- * When serialized with `requireWellFormed: true`, the serializer throws `InvalidStateError`
1899
- * if the value is non-empty and does not match the XML `PubidLiteral` production
1900
- * (W3C DOM Parsing §3.2.1.3; XML 1.0 production [12]). Creation-time validation is not
1901
- * enforced — deferred to a future breaking release.
1858
+ * The external subset public identifier.
1902
1859
  * @param {string} [systemId]
1903
- * The external subset system identifier. Stored verbatim including surrounding quotes.
1904
- * When serialized with `requireWellFormed: true`, the serializer throws `InvalidStateError`
1905
- * if the value is non-empty and does not match the XML `SystemLiteral` production
1906
- * (W3C DOM Parsing §3.2.1.3; XML 1.0 production [11]). Creation-time validation is not
1907
- * enforced — deferred to a future breaking release.
1860
+ * The external subset system identifier.
1908
1861
  * @param {string} [internalSubset]
1909
- * The internal subset or an empty string if it is not present. Stored verbatim.
1910
- * When serialized with `requireWellFormed: true`, the serializer throws `InvalidStateError`
1911
- * if the value contains `"]>"`. Creation-time validation is not enforced.
1862
+ * the internal subset or an empty string if it is not present
1912
1863
  * @returns {DocumentType}
1913
1864
  * A new {@link DocumentType} node with {@link Node#ownerDocument} set to null.
1914
1865
  * @throws {DOMException}
@@ -2101,7 +2052,7 @@ Node.prototype = {
2101
2052
  var parent = other;
2102
2053
  do {
2103
2054
  if (this === parent) return true;
2104
- parent = parent.parentNode;
2055
+ parent = other.parentNode;
2105
2056
  }while (parent);
2106
2057
  return false;
2107
2058
  },
@@ -2131,73 +2082,50 @@ Node.prototype = {
2131
2082
  /**
2132
2083
  * Checks whether the given node is equal to this node.
2133
2084
  *
2134
- * Two nodes are equal when they have the same type, defining characteristics (for the type),
2135
- * and the same childNodes. The comparison is iterative to avoid stack overflows on
2136
- * deeply-nested trees. Attribute nodes of each Element pair are also pushed onto the stack
2137
- * and compared the same way.
2138
- *
2139
2085
  * @param {Node} [otherNode]
2140
- * @returns {boolean}
2141
2086
  * @see https://dom.spec.whatwg.org/#concept-node-equals
2142
- * @see ../docs/walk-dom.md.
2143
2087
  */ isEqualNode: function isEqualNode(otherNode) {
2144
2088
  if (!otherNode) return false;
2145
- // Use an explicit {node, other} pair stack to avoid call-stack overflow on deep trees.
2146
- // walkDOM cannot be used here — parallel two-tree traversal requires pairing
2147
- // corresponding nodes at each step across both trees simultaneously.
2148
- var stack = [
2149
- {
2150
- node: this,
2151
- other: otherNode
2152
- }
2153
- ];
2154
- while(stack.length > 0){
2155
- var pair = stack.pop();
2156
- var node = pair.node;
2157
- var other = pair.other;
2158
- if (node.nodeType !== other.nodeType) return false;
2159
- switch(node.nodeType){
2160
- case node.DOCUMENT_TYPE_NODE:
2161
- if (node.name !== other.name) return false;
2162
- if (node.publicId !== other.publicId) return false;
2163
- if (node.systemId !== other.systemId) return false;
2164
- break;
2165
- case node.ELEMENT_NODE:
2166
- if (node.namespaceURI !== other.namespaceURI) return false;
2167
- if (node.prefix !== other.prefix) return false;
2168
- if (node.localName !== other.localName) return false;
2169
- if (node.attributes.length !== other.attributes.length) return false;
2170
- for(var i = 0; i < node.attributes.length; i++){
2171
- var attr = node.attributes.item(i);
2172
- var otherAttr = other.getAttributeNodeNS(attr.namespaceURI, attr.localName);
2173
- if (!otherAttr) return false;
2174
- stack.push({
2175
- node: attr,
2176
- other: otherAttr
2177
- });
2089
+ if (this.nodeType !== otherNode.nodeType) return false;
2090
+ switch(this.nodeType){
2091
+ case this.DOCUMENT_TYPE_NODE:
2092
+ if (this.name !== otherNode.name) return false;
2093
+ if (this.publicId !== otherNode.publicId) return false;
2094
+ if (this.systemId !== otherNode.systemId) return false;
2095
+ break;
2096
+ case this.ELEMENT_NODE:
2097
+ if (this.namespaceURI !== otherNode.namespaceURI) return false;
2098
+ if (this.prefix !== otherNode.prefix) return false;
2099
+ if (this.localName !== otherNode.localName) return false;
2100
+ if (this.attributes.length !== otherNode.attributes.length) return false;
2101
+ for(var i = 0; i < this.attributes.length; i++){
2102
+ var attr = this.attributes.item(i);
2103
+ if (!attr.isEqualNode(otherNode.getAttributeNodeNS(attr.namespaceURI, attr.localName))) {
2104
+ return false;
2178
2105
  }
2179
- break;
2180
- case node.ATTRIBUTE_NODE:
2181
- if (node.namespaceURI !== other.namespaceURI) return false;
2182
- if (node.localName !== other.localName) return false;
2183
- if (node.value !== other.value) return false;
2184
- break;
2185
- case node.PROCESSING_INSTRUCTION_NODE:
2186
- if (node.target !== other.target || node.data !== other.data) return false;
2187
- break;
2188
- case node.TEXT_NODE:
2189
- case node.CDATA_SECTION_NODE:
2190
- case node.COMMENT_NODE:
2191
- if (node.data !== other.data) return false;
2192
- break;
2193
- }
2194
- if (node.childNodes.length !== other.childNodes.length) return false;
2195
- // Push children in reverse order so index 0 is processed first (LIFO).
2196
- for(var i = node.childNodes.length - 1; i >= 0; i--){
2197
- stack.push({
2198
- node: node.childNodes[i],
2199
- other: other.childNodes[i]
2200
- });
2106
+ }
2107
+ break;
2108
+ case this.ATTRIBUTE_NODE:
2109
+ if (this.namespaceURI !== otherNode.namespaceURI) return false;
2110
+ if (this.localName !== otherNode.localName) return false;
2111
+ if (this.value !== otherNode.value) return false;
2112
+ break;
2113
+ case this.PROCESSING_INSTRUCTION_NODE:
2114
+ if (this.target !== otherNode.target || this.data !== otherNode.data) {
2115
+ return false;
2116
+ }
2117
+ break;
2118
+ case this.TEXT_NODE:
2119
+ case this.COMMENT_NODE:
2120
+ if (this.data !== otherNode.data) return false;
2121
+ break;
2122
+ }
2123
+ if (this.childNodes.length !== otherNode.childNodes.length) {
2124
+ return false;
2125
+ }
2126
+ for(var i = 0; i < this.childNodes.length; i++){
2127
+ if (!this.childNodes[i].isEqualNode(otherNode.childNodes[i])) {
2128
+ return false;
2201
2129
  }
2202
2130
  }
2203
2131
  return true;
@@ -2309,7 +2237,7 @@ Node.prototype = {
2309
2237
  * is `TEXT_NODE`) into a single node with the combined data. It also removes any empty text
2310
2238
  * nodes.
2311
2239
  *
2312
- * This method iterativly traverses all child nodes to normalize all descendent nodes within
2240
+ * This method operates recursively, so it also normalizes any and all descendent nodes within
2313
2241
  * the subtree.
2314
2242
  *
2315
2243
  * @throws {DOMException}
@@ -2318,27 +2246,18 @@ Node.prototype = {
2318
2246
  * @since Modified in DOM Level 2
2319
2247
  * @see {@link Node.removeChild}
2320
2248
  * @see {@link CharacterData.appendData}
2321
- * @see ../docs/walk-dom.md.
2322
2249
  */ normalize: function normalize() {
2323
- walkDOM(this, null, {
2324
- enter: function enter(node) {
2325
- // Merge adjacent text children of node before walkDOM schedules them.
2326
- // walkDOM reads lastChild/previousSibling after enter returns, so the
2327
- // surviving post-merge children are what it descends into.
2328
- var child = node.firstChild;
2329
- while(child){
2330
- var next = child.nextSibling;
2331
- if (next !== null && next.nodeType === TEXT_NODE && child.nodeType === TEXT_NODE) {
2332
- node.removeChild(next);
2333
- child.appendData(next.data);
2334
- // Do not advance child: re-check new nextSibling for another text run
2335
- } else {
2336
- child = next;
2337
- }
2338
- }
2339
- return true; // descend into surviving children
2250
+ var child = this.firstChild;
2251
+ while(child){
2252
+ var next = child.nextSibling;
2253
+ if (next && next.nodeType == TEXT_NODE && child.nodeType == TEXT_NODE) {
2254
+ this.removeChild(next);
2255
+ child.appendData(next.data);
2256
+ } else {
2257
+ child.normalize();
2258
+ child = next;
2340
2259
  }
2341
- });
2260
+ }
2342
2261
  },
2343
2262
  /**
2344
2263
  * Checks whether the DOM implementation implements a specific feature and its version.
@@ -2533,118 +2452,22 @@ copy(NodeType, Node.prototype);
2533
2452
  copy(DocumentPosition, Node);
2534
2453
  copy(DocumentPosition, Node.prototype);
2535
2454
  /**
2536
- * Visits every node in the subtree rooted at `node` in depth-first pre-order.
2537
- *
2538
- * Delegates to {@link walkDOM} for traversal. The `callback` is called on each node;
2539
- * if it returns a truthy value, traversal stops immediately.
2540
- *
2541
- * @param {Node} node
2542
- * Root of the subtree to visit.
2543
- * @param {function(Node): *} callback
2544
- * Called for each node. A truthy return value stops traversal early.
2455
+ * @param callback
2456
+ * Return true for continue,false for break.
2457
+ * @returns
2458
+ * boolean true: break visit;
2545
2459
  */ function _visitNode(node, callback) {
2546
- walkDOM(node, null, {
2547
- enter: function enter(n) {
2548
- return callback(n) ? walkDOM.STOP : true;
2549
- }
2550
- });
2551
- }
2552
- /**
2553
- * Depth-first pre/post-order DOM tree walker.
2554
- *
2555
- * Visits every node in the subtree rooted at `node`. For each node:
2556
- *
2557
- * 1. Calls `callbacks.enter(node, context)` before descending into the node's children. The
2558
- * return value becomes the `context` passed to each child's `enter` call and to the matching
2559
- * `exit` call.
2560
- * 2. If `enter` returns `null` or `undefined`, the node's children are skipped;
2561
- * sibling traversal continues normally.
2562
- * 3. If `enter` returns `walkDOM.STOP`, the entire traversal is aborted immediately — no
2563
- * further `enter` or `exit` calls are made.
2564
- * 4. `lastChild` and `previousSibling` are read **after** `enter` returns, so `enter` may
2565
- * safely modify the node's own child list before the walker descends. Modifying siblings of
2566
- * the current node or any other part of the tree produces unpredictable results: nodes already
2567
- * queued on the stack are visited regardless of DOM changes, and newly inserted nodes outside
2568
- * the current child list are never visited.
2569
- * 5. Calls `callbacks.exit(node, context)` (if provided) after all of a node's children have
2570
- * been visited, passing the same `context` that `enter`
2571
- * returned for that node.
2572
- *
2573
- * This implementation uses an explicit stack and does not recurse — it is safe on arbitrarily
2574
- * deep trees.
2575
- *
2576
- * @param {Node} node
2577
- * Root of the subtree to walk.
2578
- * @param {*} context
2579
- * Initial context value passed to the root node's `enter`.
2580
- * @param {{ enter: function(Node, *): *, exit?: function(Node, *): void }} callbacks
2581
- * @returns {void | walkDOM.STOP}
2582
- * @see ../docs/walk-dom.md.
2583
- */ function walkDOM(node, context, callbacks) {
2584
- // Each stack frame is {node, context, phase}:
2585
- // walkDOM.ENTER — call enter, then push children
2586
- // walkDOM.EXIT — call exit
2587
- var stack = [
2588
- {
2589
- node: node,
2590
- context: context,
2591
- phase: walkDOM.ENTER
2592
- }
2593
- ];
2594
- while(stack.length > 0){
2595
- var frame = stack.pop();
2596
- if (frame.phase === walkDOM.ENTER) {
2597
- var childContext = callbacks.enter(frame.node, frame.context);
2598
- if (childContext === walkDOM.STOP) {
2599
- return walkDOM.STOP;
2600
- }
2601
- // Push exit frame before children so it fires after all children are processed (Last In First Out)
2602
- stack.push({
2603
- node: frame.node,
2604
- context: childContext,
2605
- phase: walkDOM.EXIT
2606
- });
2607
- if (childContext === null || childContext === undefined) {
2608
- continue; // skip children
2609
- }
2610
- // lastChild is read after enter returns, so enter may modify the child list.
2611
- var child = frame.node.lastChild;
2612
- // Traverse from lastChild backwards so that pushing onto the stack
2613
- // naturally yields firstChild on top (processed first).
2614
- while(child){
2615
- stack.push({
2616
- node: child,
2617
- context: childContext,
2618
- phase: walkDOM.ENTER
2619
- });
2620
- child = child.previousSibling;
2621
- }
2622
- } else {
2623
- // frame.phase === walkDOM.EXIT
2624
- if (callbacks.exit) {
2625
- callbacks.exit(frame.node, frame.context);
2460
+ if (callback(node)) {
2461
+ return true;
2462
+ }
2463
+ if (node = node.firstChild) {
2464
+ do {
2465
+ if (_visitNode(node, callback)) {
2466
+ return true;
2626
2467
  }
2627
- }
2468
+ }while (node = node.nextSibling);
2628
2469
  }
2629
2470
  }
2630
- /**
2631
- * Sentinel value returned from a `walkDOM` `enter` callback to abort the entire traversal
2632
- * immediately.
2633
- *
2634
- * @type {symbol}
2635
- */ walkDOM.STOP = Symbol('walkDOM.STOP');
2636
- /**
2637
- * Phase constant for a stack frame that has not yet been visited.
2638
- * The `enter` callback is called and children are scheduled.
2639
- *
2640
- * @type {number}
2641
- */ walkDOM.ENTER = 0;
2642
- /**
2643
- * Phase constant for a stack frame whose subtree has been fully visited.
2644
- * The `exit` callback is called.
2645
- *
2646
- * @type {number}
2647
- */ walkDOM.EXIT = 1;
2648
2471
  /**
2649
2472
  * @typedef DocumentOptions
2650
2473
  * @property {string} [contentType=MIME_TYPE.XML_APPLICATION]
@@ -3164,20 +2987,8 @@ Document.prototype = {
3164
2987
  this.documentElement = newChild;
3165
2988
  }
3166
2989
  },
3167
- /**
3168
- * Imports a node from another document into this document, creating a new copy owned by this
3169
- * document. The source node and its subtree are not modified.
3170
- *
3171
- * @param {Node} importedNode
3172
- * The node to import.
3173
- * @param {boolean} deep
3174
- * If true, the contents of the node are recursively imported.
3175
- * If false, only the node itself (and its attributes, if it is an element) are imported.
3176
- * @returns {Node}
3177
- * Returns the newly created import of the node.
3178
- * @see {@link importNode}
3179
- * @see {@link https://dom.spec.whatwg.org/#dom-document-importnode}
3180
- */ importNode: function importNode1(importedNode, deep) {
2990
+ // Introduced in DOM Level 2:
2991
+ importNode: function importNode1(importedNode, deep) {
3181
2992
  return importNode(this, importedNode, deep);
3182
2993
  },
3183
2994
  // Introduced in DOM Level 2:
@@ -3248,15 +3059,6 @@ Document.prototype = {
3248
3059
  /**
3249
3060
  * @param {string} data
3250
3061
  * @returns {Comment}
3251
- * @see https://dom.spec.whatwg.org/#dom-document-createcomment
3252
- * @see https://www.w3.org/TR/xml/#NT-Comment XML 1.0 production [15]
3253
- * @see https://www.w3.org/TR/DOM-Parsing/#dfn-concept-serialize-xml §3.2.1.3
3254
- *
3255
- * Note: no validation is performed at creation time. When the resulting document is
3256
- * serialized with `requireWellFormed: true`, the serializer throws `InvalidStateError`
3257
- * if the comment data contains `--` anywhere, ends with `-`, or contains characters
3258
- * outside the XML Char production (W3C DOM Parsing §3.2.1.3). Without that option the
3259
- * data is emitted verbatim.
3260
3062
  */ createComment: function createComment(data) {
3261
3063
  var node = new Comment(PDC);
3262
3064
  node.ownerDocument = this;
@@ -3265,21 +3067,9 @@ Document.prototype = {
3265
3067
  return node;
3266
3068
  },
3267
3069
  /**
3268
- * Returns a new CDATASection node whose data is `data`.
3269
- *
3270
- * __This implementation differs from the specification:__ - calling this method on an HTML
3271
- * document does not throw `NotSupportedError`.
3272
- *
3273
3070
  * @param {string} data
3274
3071
  * @returns {CDATASection}
3275
- * @throws {DOMException}
3276
- * With code `INVALID_CHARACTER_ERR` if `data` contains `"]]>"`.
3277
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/createCDATASection
3278
- * @see https://dom.spec.whatwg.org/#dom-document-createcdatasection
3279
3072
  */ createCDATASection: function createCDATASection(data) {
3280
- if (data.indexOf(']]>') !== -1) {
3281
- throw new DOMException$1(DOMException$1.INVALID_CHARACTER_ERR, 'data contains "]]>"');
3282
- }
3283
3073
  var node = new CDATASection(PDC);
3284
3074
  node.ownerDocument = this;
3285
3075
  node.childNodes = new NodeList();
@@ -3287,24 +3077,9 @@ Document.prototype = {
3287
3077
  return node;
3288
3078
  },
3289
3079
  /**
3290
- * Returns a ProcessingInstruction node whose target is target and data is data.
3291
- *
3292
- * __This behavior is slightly different from the in the specs__:
3293
- * - it does not do any input validation on the arguments and doesn't throw
3294
- * "InvalidCharacterError".
3295
- *
3296
- * Note: When the resulting document is serialized with `requireWellFormed: true`, the
3297
- * serializer throws `InvalidStateError` if `.target` contains `:` or is an ASCII
3298
- * case-insensitive match for `"xml"`, or if `.data` contains `?>` or characters outside the
3299
- * XML Char production (W3C DOM Parsing §3.2.1.7). Without that option the data is emitted
3300
- * verbatim.
3301
- *
3302
3080
  * @param {string} target
3303
3081
  * @param {string} data
3304
3082
  * @returns {ProcessingInstruction}
3305
- * @see https://developer.mozilla.org/docs/Web/API/Document/createProcessingInstruction
3306
- * @see https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
3307
- * @see https://www.w3.org/TR/DOM-Parsing/#dfn-concept-serialize-xml §3.2.1.7
3308
3083
  */ createProcessingInstruction: function createProcessingInstruction(target, data) {
3309
3084
  var node = new ProcessingInstruction(PDC);
3310
3085
  node.ownerDocument = this;
@@ -3708,31 +3483,7 @@ CDATASection.prototype = {
3708
3483
  nodeType: CDATA_SECTION_NODE
3709
3484
  };
3710
3485
  _extends(CDATASection, Text);
3711
- /**
3712
- * @class DocumentType
3713
- * @augments Node
3714
- * @property {string} publicId
3715
- * The external subset public identifier, stored verbatim (including surrounding quotes).
3716
- * Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this constraint —
3717
- * direct property writes succeed and the written value is serialized verbatim.
3718
- * When serialized with `requireWellFormed: true`, the serializer validates the value against
3719
- * the XML `PubidLiteral` production and throws `InvalidStateError` if it does not match.
3720
- * @property {string} systemId
3721
- * The external subset system identifier, stored verbatim (including surrounding quotes).
3722
- * Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this constraint —
3723
- * direct property writes succeed and the written value is serialized verbatim.
3724
- * When serialized with `requireWellFormed: true`, the serializer validates the value against
3725
- * the XML `SystemLiteral` production and throws `InvalidStateError` if it does not match.
3726
- * @property {string} internalSubset
3727
- * The internal subset string (the raw content between `[` and `]`), or an empty string.
3728
- * Declared `readonly` by the WHATWG DOM spec; xmldom does not enforce this constraint —
3729
- * direct property writes succeed and the written value is serialized verbatim.
3730
- * When serialized with `requireWellFormed: true`, the serializer throws `InvalidStateError`
3731
- * if the value contains `"]>"`.
3732
- * @see https://developer.mozilla.org/en-US/docs/Web/API/DocumentType MDN
3733
- * @see https://dom.spec.whatwg.org/#interface-documenttype WHATWG DOM
3734
- * @prettierignore
3735
- */ function DocumentType(symbol) {
3486
+ function DocumentType(symbol) {
3736
3487
  checkSymbol(symbol);
3737
3488
  }
3738
3489
  DocumentType.prototype.nodeType = DOCUMENT_TYPE_NODE;
@@ -3764,89 +3515,11 @@ function ProcessingInstruction(symbol) {
3764
3515
  ProcessingInstruction.prototype.nodeType = PROCESSING_INSTRUCTION_NODE;
3765
3516
  _extends(ProcessingInstruction, CharacterData);
3766
3517
  function XMLSerializer$1() {}
3767
- /**
3768
- * Returns the result of serializing `node` to XML.
3769
- *
3770
- * When `options.requireWellFormed` is `true`, the serializer throws `InvalidStateError` for
3771
- * content that would produce ill-formed XML (e.g. CDATASection data containing `"]]>"`, Text
3772
- * data containing characters outside the XML Char production, or a Document with no
3773
- * `documentElement`).
3774
- *
3775
- * When `options.splitCDATASections` is `false`, CDATASection data is emitted verbatim even
3776
- * when it contains `"]]>"`. When `true` (the default), `"]]>"` sequences are split across
3777
- * concatenated CDATA sections — this behavior is **deprecated** and will be removed in the
3778
- * next breaking release. Callers should migrate to `{ requireWellFormed: true }`, which throws
3779
- * `InvalidStateError` instead of transforming.
3780
- *
3781
- * __This implementation differs from the specification:__ - CDATASection serialization is not
3782
- * specified by W3C DOM Parsing or WHATWG DOM Parsing (see
3783
- * {@link https://github.com/w3c/DOM-Parsing/issues/38 w3c/DOM-Parsing#38}).
3784
- * When `splitCDATASections` is `true` (the default), `"]]>"` sequences in CDATASection data
3785
- * are split across concatenated CDATA sections — this mechanism is derived from DOM Level 3
3786
- * Core and is **deprecated**. The split mechanics will be removed in the next breaking
3787
- * release. Callers that rely on this behavior should migrate to `{ requireWellFormed: true }`.
3788
- * - W3C DOM Parsing §3.2.1.1 requires well-formedness checks on Element `localName`s,
3789
- * prefixes,
3790
- * and attribute serialization (duplicate attributes, namespace declarations, attribute value
3791
- * characters) when `requireWellFormed` is `true`. These checks are **not implemented** in this
3792
- * release — see the tracking issue filed against the next breaking milestone.
3793
- *
3794
- * @param {Node} node
3795
- * @param {Object | function} [options]
3796
- * Options object, or a legacy nodeFilter function (backward compatible).
3797
- * @param {boolean} [options.requireWellFormed=false]
3798
- * When `true`, throws `InvalidStateError` for content that would produce ill-formed XML.
3799
- * @param {boolean} [options.splitCDATASections=true]
3800
- * When `true` (default), splits `"]]>"` sequences in CDATASection data across concatenated
3801
- * CDATA sections. **Deprecated** — will be removed in the next breaking release.
3802
- * @param {function} [options.nodeFilter]
3803
- * A filter function applied to each node before serialization.
3804
- * @returns {string}
3805
- * @throws {DOMException}
3806
- * With name `InvalidStateError` when `requireWellFormed` is `true` and any of the following
3807
- * conditions hold:
3808
- * - CDATASection data contains `"]]>"`
3809
- * - Text data contains characters outside the XML Char production
3810
- * - a Comment node's data contains `--` anywhere or ends with `-`
3811
- * - a ProcessingInstruction's target contains `:` or is an ASCII case-insensitive match for
3812
- * `"xml"`, or its data contains `?>` or characters outside the XML Char production
3813
- * - a DocumentType's `publicId` is non-empty and does not match the XML `PubidLiteral`
3814
- * production (W3C DOM Parsing §3.2.1.3; XML 1.0 production [12])
3815
- * - a DocumentType's `systemId` is non-empty and does not match the XML `SystemLiteral`
3816
- * production (W3C DOM Parsing §3.2.1.3; XML 1.0 production [11])
3817
- * - a DocumentType's `internalSubset` contains `"]>"`
3818
- * - the Document has no `documentElement`
3819
- * @see https://developer.mozilla.org/docs/Web/API/XMLSerializer/serializeToString
3820
- * @see https://html.spec.whatwg.org/#dom-xmlserializer-serializetostring
3821
- * @see https://github.com/w3c/DOM-Parsing/issues/84
3822
- * @prettierignore
3823
- */ XMLSerializer$1.prototype.serializeToString = function(node, options) {
3824
- return nodeSerializeToString.call(node, options);
3518
+ XMLSerializer$1.prototype.serializeToString = function(node, nodeFilter) {
3519
+ return nodeSerializeToString.call(node, nodeFilter);
3825
3520
  };
3826
3521
  Node.prototype.toString = nodeSerializeToString;
3827
- function nodeSerializeToString(options) {
3828
- // Normalize the user-supplied options into a single internal opts object so that the
3829
- // internal serializer always works with a consistent shape rather than positional flags.
3830
- var opts;
3831
- if (typeof options === 'function') {
3832
- opts = {
3833
- requireWellFormed: false,
3834
- splitCDATASections: true,
3835
- nodeFilter: options
3836
- };
3837
- } else if (options != null) {
3838
- opts = {
3839
- requireWellFormed: !!options.requireWellFormed,
3840
- splitCDATASections: options.splitCDATASections !== false,
3841
- nodeFilter: options.nodeFilter || null
3842
- };
3843
- } else {
3844
- opts = {
3845
- requireWellFormed: false,
3846
- splitCDATASections: true,
3847
- nodeFilter: null
3848
- };
3849
- }
3522
+ function nodeSerializeToString(nodeFilter) {
3850
3523
  var buf = [];
3851
3524
  var refNode = this.nodeType === DOCUMENT_NODE && this.documentElement || this;
3852
3525
  var prefix = refNode.prefix;
@@ -3862,7 +3535,7 @@ function nodeSerializeToString(options) {
3862
3535
  ];
3863
3536
  }
3864
3537
  }
3865
- serializeToString(this, buf, visibleNamespaces, opts);
3538
+ serializeToString(this, buf, nodeFilter, visibleNamespaces);
3866
3539
  return buf.join('');
3867
3540
  }
3868
3541
  function needNamespaceDefine(node, isHTML, visibleNamespaces) {
@@ -3908,302 +3581,222 @@ function needNamespaceDefine(node, isHTML, visibleNamespaces) {
3908
3581
  */ function addSerializedAttribute(buf, qualifiedName, value) {
3909
3582
  buf.push(' ', qualifiedName, '="', value.replace(/[<>&"\t\n\r]/g, _xmlEncoder), '"');
3910
3583
  }
3911
- function serializeToString(node, buf, visibleNamespaces, opts) {
3584
+ function serializeToString(node, buf, nodeFilter, visibleNamespaces) {
3912
3585
  if (!visibleNamespaces) {
3913
3586
  visibleNamespaces = [];
3914
3587
  }
3915
- var nodeFilter = opts.nodeFilter;
3916
- var requireWellFormed = opts.requireWellFormed;
3917
- var splitCDATASections = opts.splitCDATASections;
3918
3588
  var doc = node.nodeType === DOCUMENT_NODE ? node : node.ownerDocument;
3919
3589
  var isHTML = doc.type === 'html';
3920
- walkDOM(node, {
3921
- ns: visibleNamespaces
3922
- }, {
3923
- enter: function enter(n, ctx) {
3924
- var namespaces = ctx.ns;
3925
- if (nodeFilter) {
3926
- n = nodeFilter(n);
3927
- if (n) {
3928
- if (typeof n == 'string') {
3929
- buf.push(n);
3930
- return null;
3931
- }
3932
- } else {
3933
- return null;
3934
- }
3590
+ if (nodeFilter) {
3591
+ node = nodeFilter(node);
3592
+ if (node) {
3593
+ if (typeof node == 'string') {
3594
+ buf.push(node);
3595
+ return;
3935
3596
  }
3936
- switch(n.nodeType){
3937
- case ELEMENT_NODE:
3938
- var attrs = n.attributes;
3939
- var len = attrs.length;
3940
- var nodeName = n.tagName;
3941
- var prefixedNodeName = nodeName;
3942
- if (!isHTML && !n.prefix && n.namespaceURI) {
3943
- var defaultNS;
3944
- // lookup current default ns from `xmlns` attribute
3945
- for(var ai = 0; ai < attrs.length; ai++){
3946
- if (attrs.item(ai).name === 'xmlns') {
3947
- defaultNS = attrs.item(ai).value;
3948
- break;
3949
- }
3950
- }
3951
- if (!defaultNS) {
3952
- // lookup current default ns in visibleNamespaces
3953
- for(var nsi = namespaces.length - 1; nsi >= 0; nsi--){
3954
- var nsEntry = namespaces[nsi];
3955
- if (nsEntry.prefix === '' && nsEntry.namespace === n.namespaceURI) {
3956
- defaultNS = nsEntry.namespace;
3957
- break;
3958
- }
3959
- }
3960
- }
3961
- if (defaultNS !== n.namespaceURI) {
3962
- for(var nsi = namespaces.length - 1; nsi >= 0; nsi--){
3963
- var nsEntry = namespaces[nsi];
3964
- if (nsEntry.namespace === n.namespaceURI) {
3965
- if (nsEntry.prefix) {
3966
- prefixedNodeName = nsEntry.prefix + ':' + nodeName;
3967
- }
3968
- break;
3969
- }
3970
- }
3971
- }
3972
- }
3973
- buf.push('<', prefixedNodeName);
3974
- // Build a fresh namespace snapshot for this element's children.
3975
- // The slice prevents sibling elements from inheriting each other's declarations.
3976
- var childNamespaces = namespaces.slice();
3977
- for(var i = 0; i < len; i++){
3978
- // add namespaces for attributes
3979
- var attr = attrs.item(i);
3980
- if (attr.prefix == 'xmlns') {
3981
- childNamespaces.push({
3982
- prefix: attr.localName,
3983
- namespace: attr.value
3984
- });
3985
- } else if (attr.nodeName == 'xmlns') {
3986
- childNamespaces.push({
3987
- prefix: '',
3988
- namespace: attr.value
3989
- });
3990
- }
3597
+ } else {
3598
+ return;
3599
+ }
3600
+ //buf.sort.apply(attrs, attributeSorter);
3601
+ }
3602
+ switch(node.nodeType){
3603
+ case ELEMENT_NODE:
3604
+ var attrs = node.attributes;
3605
+ var len = attrs.length;
3606
+ var child = node.firstChild;
3607
+ var nodeName = node.tagName;
3608
+ var prefixedNodeName = nodeName;
3609
+ if (!isHTML && !node.prefix && node.namespaceURI) {
3610
+ var defaultNS;
3611
+ // lookup current default ns from `xmlns` attribute
3612
+ for(var ai = 0; ai < attrs.length; ai++){
3613
+ if (attrs.item(ai).name === 'xmlns') {
3614
+ defaultNS = attrs.item(ai).value;
3615
+ break;
3991
3616
  }
3992
- for(var i = 0; i < len; i++){
3993
- var attr = attrs.item(i);
3994
- if (needNamespaceDefine(attr, isHTML, childNamespaces)) {
3995
- var attrPrefix = attr.prefix || '';
3996
- var uri = attr.namespaceURI;
3997
- addSerializedAttribute(buf, attrPrefix ? 'xmlns:' + attrPrefix : 'xmlns', uri);
3998
- childNamespaces.push({
3999
- prefix: attrPrefix,
4000
- namespace: uri
4001
- });
4002
- }
4003
- // Apply nodeFilter and serialize the attribute.
4004
- var filteredAttr = nodeFilter ? nodeFilter(attr) : attr;
4005
- if (filteredAttr) {
4006
- if (typeof filteredAttr === 'string') {
4007
- buf.push(filteredAttr);
4008
- } else {
4009
- addSerializedAttribute(buf, filteredAttr.name, filteredAttr.value);
4010
- }
3617
+ }
3618
+ if (!defaultNS) {
3619
+ // lookup current default ns in visibleNamespaces
3620
+ for(var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--){
3621
+ var namespace = visibleNamespaces[nsi];
3622
+ if (namespace.prefix === '' && namespace.namespace === node.namespaceURI) {
3623
+ defaultNS = namespace.namespace;
3624
+ break;
4011
3625
  }
4012
3626
  }
4013
- // add namespace for current node
4014
- if (nodeName === prefixedNodeName && needNamespaceDefine(n, isHTML, childNamespaces)) {
4015
- var nodePrefix = n.prefix || '';
4016
- var uri = n.namespaceURI;
4017
- addSerializedAttribute(buf, nodePrefix ? 'xmlns:' + nodePrefix : 'xmlns', uri);
4018
- childNamespaces.push({
4019
- prefix: nodePrefix,
4020
- namespace: uri
4021
- });
4022
- }
4023
- // in XML elements can be closed when they have no children
4024
- var canCloseTag = !n.firstChild;
4025
- if (canCloseTag && (isHTML || n.namespaceURI === NAMESPACE$2.HTML)) {
4026
- // in HTML (doc or ns) only void elements can be closed right away
4027
- canCloseTag = isHTMLVoidElement(nodeName);
4028
- }
4029
- if (canCloseTag) {
4030
- buf.push('/>');
4031
- // Self-closing: no children and no closing tag needed from exit.
4032
- return null;
4033
- }
4034
- buf.push('>');
4035
- // HTML raw text elements: serialize children as raw data without further descent.
4036
- if (isHTML && isHTMLRawTextElement$1(nodeName)) {
4037
- var child = n.firstChild;
4038
- while(child){
4039
- if (child.data) {
4040
- buf.push(child.data);
4041
- } else {
4042
- serializeToString(child, buf, childNamespaces.slice(), opts);
3627
+ }
3628
+ if (defaultNS !== node.namespaceURI) {
3629
+ for(var nsi = visibleNamespaces.length - 1; nsi >= 0; nsi--){
3630
+ var namespace = visibleNamespaces[nsi];
3631
+ if (namespace.namespace === node.namespaceURI) {
3632
+ if (namespace.prefix) {
3633
+ prefixedNodeName = namespace.prefix + ':' + nodeName;
4043
3634
  }
4044
- child = child.nextSibling;
4045
- }
4046
- buf.push('</', prefixedNodeName, '>');
4047
- // Children handled manually above; prevent walkDOM from also traversing them.
4048
- return null;
4049
- }
4050
- // Return child context so walkDOM descends; exit will emit the closing tag.
4051
- return {
4052
- ns: childNamespaces,
4053
- tag: prefixedNodeName
4054
- };
4055
- case DOCUMENT_NODE:
4056
- case DOCUMENT_FRAGMENT_NODE:
4057
- if (requireWellFormed && n.nodeType === DOCUMENT_NODE && n.documentElement == null) {
4058
- throw new DOMException$1('The Document has no documentElement', DOMExceptionName.InvalidStateError);
4059
- }
4060
- // Pass namespaces through; each child element will slice independently.
4061
- return {
4062
- ns: namespaces
4063
- };
4064
- case ATTRIBUTE_NODE:
4065
- addSerializedAttribute(buf, n.name, n.value);
4066
- return null;
4067
- case TEXT_NODE:
4068
- /*
4069
- * The ampersand character (&) and the left angle bracket (<) must not appear in their literal form,
4070
- * except when used as markup delimiters, or within a comment, a processing instruction,
4071
- * or a CDATA section.
4072
- * If they are needed elsewhere, they must be escaped using either numeric character
4073
- * references or the strings `&amp;` and `&lt;` respectively.
4074
- * The right angle bracket (>) may be represented using the string " &gt; ",
4075
- * and must, for compatibility, be escaped using either `&gt;`,
4076
- * or a character reference when it appears in the string `]]>` in content,
4077
- * when that string is not marking the end of a CDATA section.
4078
- *
4079
- * In the content of elements, character data is any string of characters which does not
4080
- * contain the start-delimiter of any markup and does not include the CDATA-section-close
4081
- * delimiter, `]]>`.
4082
- *
4083
- * @see https://www.w3.org/TR/xml/#NT-CharData
4084
- * @see https://w3c.github.io/DOM-Parsing/#xml-serializing-a-text-node
4085
- */ if (requireWellFormed && g$1.InvalidChar.test(n.data)) {
4086
- throw new DOMException$1('The Text node data contains characters outside the XML Char production', DOMExceptionName.InvalidStateError);
4087
- }
4088
- buf.push(n.data.replace(/[<&>]/g, _xmlEncoder));
4089
- return null;
4090
- case CDATA_SECTION_NODE:
4091
- if (requireWellFormed && n.data.indexOf(']]>') !== -1) {
4092
- throw new DOMException$1('The CDATASection data contains "]]>"', DOMExceptionName.InvalidStateError);
4093
- }
4094
- if (splitCDATASections) {
4095
- buf.push(g$1.CDATA_START, n.data.replace(/]]>/g, ']]]]><![CDATA[>'), g$1.CDATA_END);
4096
- } else {
4097
- buf.push(g$1.CDATA_START, n.data, g$1.CDATA_END);
4098
- }
4099
- return null;
4100
- case COMMENT_NODE:
4101
- if (requireWellFormed) {
4102
- if (g$1.InvalidChar.test(n.data)) {
4103
- throw new DOMException$1('The comment node data contains characters outside the XML Char production', DOMExceptionName.InvalidStateError);
4104
- }
4105
- if (n.data.indexOf('--') !== -1 || n.data[n.data.length - 1] === '-') {
4106
- throw new DOMException$1('The comment node data contains "--" or ends with "-"', DOMExceptionName.InvalidStateError);
4107
- }
4108
- }
4109
- buf.push(g$1.COMMENT_START, n.data, g$1.COMMENT_END);
4110
- return null;
4111
- case DOCUMENT_TYPE_NODE:
4112
- var pubid = n.publicId;
4113
- var sysid = n.systemId;
4114
- if (requireWellFormed) {
4115
- if (pubid && !g$1.PubidLiteral_match.test(pubid)) {
4116
- throw new DOMException$1('DocumentType publicId is not a valid PubidLiteral', DOMExceptionName.InvalidStateError);
4117
- }
4118
- if (sysid && sysid !== '.' && !g$1.SystemLiteral_match.test(sysid)) {
4119
- throw new DOMException$1('DocumentType systemId is not a valid SystemLiteral', DOMExceptionName.InvalidStateError);
4120
- }
4121
- if (n.internalSubset && n.internalSubset.indexOf(']>') !== -1) {
4122
- throw new DOMException$1('DocumentType internalSubset contains "]>"', DOMExceptionName.InvalidStateError);
3635
+ break;
4123
3636
  }
4124
3637
  }
4125
- buf.push(g$1.DOCTYPE_DECL_START, ' ', n.name);
4126
- if (pubid) {
4127
- buf.push(' ', g$1.PUBLIC, ' ', pubid);
4128
- if (sysid && sysid !== '.') {
4129
- buf.push(' ', sysid);
3638
+ }
3639
+ }
3640
+ buf.push('<', prefixedNodeName);
3641
+ for(var i = 0; i < len; i++){
3642
+ // add namespaces for attributes
3643
+ var attr = attrs.item(i);
3644
+ if (attr.prefix == 'xmlns') {
3645
+ visibleNamespaces.push({
3646
+ prefix: attr.localName,
3647
+ namespace: attr.value
3648
+ });
3649
+ } else if (attr.nodeName == 'xmlns') {
3650
+ visibleNamespaces.push({
3651
+ prefix: '',
3652
+ namespace: attr.value
3653
+ });
3654
+ }
3655
+ }
3656
+ for(var i = 0; i < len; i++){
3657
+ var attr = attrs.item(i);
3658
+ if (needNamespaceDefine(attr, isHTML, visibleNamespaces)) {
3659
+ var prefix = attr.prefix || '';
3660
+ var uri = attr.namespaceURI;
3661
+ addSerializedAttribute(buf, prefix ? 'xmlns:' + prefix : 'xmlns', uri);
3662
+ visibleNamespaces.push({
3663
+ prefix: prefix,
3664
+ namespace: uri
3665
+ });
3666
+ }
3667
+ serializeToString(attr, buf, nodeFilter, visibleNamespaces);
3668
+ }
3669
+ // add namespace for current node
3670
+ if (nodeName === prefixedNodeName && needNamespaceDefine(node, isHTML, visibleNamespaces)) {
3671
+ var prefix = node.prefix || '';
3672
+ var uri = node.namespaceURI;
3673
+ addSerializedAttribute(buf, prefix ? 'xmlns:' + prefix : 'xmlns', uri);
3674
+ visibleNamespaces.push({
3675
+ prefix: prefix,
3676
+ namespace: uri
3677
+ });
3678
+ }
3679
+ // in XML elements can be closed when they have no children
3680
+ var canCloseTag = !child;
3681
+ if (canCloseTag && (isHTML || node.namespaceURI === NAMESPACE$2.HTML)) {
3682
+ // in HTML (doc or ns) only void elements can be closed right away
3683
+ canCloseTag = isHTMLVoidElement(nodeName);
3684
+ }
3685
+ if (canCloseTag) {
3686
+ buf.push('/>');
3687
+ } else {
3688
+ buf.push('>');
3689
+ //if is cdata child node
3690
+ if (isHTML && isHTMLRawTextElement$1(nodeName)) {
3691
+ while(child){
3692
+ if (child.data) {
3693
+ buf.push(child.data);
3694
+ } else {
3695
+ serializeToString(child, buf, nodeFilter, visibleNamespaces.slice());
4130
3696
  }
4131
- } else if (sysid && sysid !== '.') {
4132
- buf.push(' ', g$1.SYSTEM, ' ', sysid);
4133
- }
4134
- if (n.internalSubset) {
4135
- buf.push(' [', n.internalSubset, ']');
3697
+ child = child.nextSibling;
4136
3698
  }
4137
- buf.push('>');
4138
- return null;
4139
- case PROCESSING_INSTRUCTION_NODE:
4140
- if (requireWellFormed) {
4141
- if (n.target.indexOf(':') !== -1 || n.target.toLowerCase() === 'xml') {
4142
- throw new DOMException$1('The ProcessingInstruction target is not well-formed', DOMExceptionName.InvalidStateError);
4143
- }
4144
- if (g$1.InvalidChar.test(n.data)) {
4145
- throw new DOMException$1('The ProcessingInstruction data contains characters outside the XML Char production', DOMExceptionName.InvalidStateError);
4146
- }
4147
- if (n.data.indexOf('?>') !== -1) {
4148
- throw new DOMException$1('The ProcessingInstruction data contains "?>"', DOMExceptionName.InvalidStateError);
4149
- }
3699
+ } else {
3700
+ while(child){
3701
+ serializeToString(child, buf, nodeFilter, visibleNamespaces.slice());
3702
+ child = child.nextSibling;
4150
3703
  }
4151
- buf.push('<?', n.target, ' ', n.data, '?>');
4152
- return null;
4153
- case ENTITY_REFERENCE_NODE:
4154
- buf.push('&', n.nodeName, ';');
4155
- return null;
4156
- //case ENTITY_NODE:
4157
- //case NOTATION_NODE:
4158
- default:
4159
- buf.push('??', n.nodeName);
4160
- return null;
3704
+ }
3705
+ buf.push('</', prefixedNodeName, '>');
4161
3706
  }
4162
- },
4163
- exit: function exit(n, childCtx) {
4164
- // Emit the closing tag for elements that were opened (not self-closed, not raw text).
4165
- if (childCtx && childCtx.tag) {
4166
- buf.push('</', childCtx.tag, '>');
3707
+ // remove added visible namespaces
3708
+ //visibleNamespaces.length = startVisibleNamespaces;
3709
+ return;
3710
+ case DOCUMENT_NODE:
3711
+ case DOCUMENT_FRAGMENT_NODE:
3712
+ var child = node.firstChild;
3713
+ while(child){
3714
+ serializeToString(child, buf, nodeFilter, visibleNamespaces.slice());
3715
+ child = child.nextSibling;
4167
3716
  }
4168
- }
4169
- });
4170
- }
4171
- /**
4172
- * Imports a node from a different document into `doc`, creating a new copy.
4173
- * Delegates to {@link walkDOM} for traversal. Each node in the subtree is shallow-cloned,
4174
- * stamped with `doc` as its `ownerDocument`, and detached (`parentNode` set to `null`).
4175
- * Children are imported recursively when `deep` is `true`; for {@link Attr} nodes `deep` is
4176
- * always forced to `true`
4177
- * because an attribute's value lives in a child text node.
4178
- *
4179
- * @param {Document} doc
4180
- * The document that will own the imported node.
4181
- * @param {Node} node
4182
- * The node to import.
4183
- * @param {boolean} deep
4184
- * If `true`, descendants are imported recursively.
4185
- * @returns {Node}
4186
- * The newly imported node, now owned by `doc`.
4187
- */ function importNode(doc, node, deep) {
4188
- var destRoot;
4189
- walkDOM(node, null, {
4190
- enter: function enter(srcNode, destParent) {
4191
- // Shallow-clone the node and stamp it into the target document.
4192
- var destNode = srcNode.cloneNode(false);
4193
- destNode.ownerDocument = doc;
4194
- destNode.parentNode = null;
4195
- // capture as the root of the imported subtree or attach to parent.
4196
- if (destParent === null) {
4197
- destRoot = destNode;
4198
- } else {
4199
- destParent.appendChild(destNode);
3717
+ return;
3718
+ case ATTRIBUTE_NODE:
3719
+ return addSerializedAttribute(buf, node.name, node.value);
3720
+ case TEXT_NODE:
3721
+ /*
3722
+ * The ampersand character (&) and the left angle bracket (<) must not appear in their literal form,
3723
+ * except when used as markup delimiters, or within a comment, a processing instruction,
3724
+ * or a CDATA section.
3725
+ * If they are needed elsewhere, they must be escaped using either numeric character
3726
+ * references or the strings `&amp;` and `&lt;` respectively.
3727
+ * The right angle bracket (>) may be represented using the string " &gt; ",
3728
+ * and must, for compatibility, be escaped using either `&gt;`,
3729
+ * or a character reference when it appears in the string `]]>` in content,
3730
+ * when that string is not marking the end of a CDATA section.
3731
+ *
3732
+ * In the content of elements, character data is any string of characters which does not
3733
+ * contain the start-delimiter of any markup and does not include the CDATA-section-close
3734
+ * delimiter, `]]>`.
3735
+ *
3736
+ * @see https://www.w3.org/TR/xml/#NT-CharData
3737
+ * @see https://w3c.github.io/DOM-Parsing/#xml-serializing-a-text-node
3738
+ */ return buf.push(node.data.replace(/[<&>]/g, _xmlEncoder));
3739
+ case CDATA_SECTION_NODE:
3740
+ return buf.push(g$1.CDATA_START, node.data, g$1.CDATA_END);
3741
+ case COMMENT_NODE:
3742
+ return buf.push(g$1.COMMENT_START, node.data, g$1.COMMENT_END);
3743
+ case DOCUMENT_TYPE_NODE:
3744
+ var pubid = node.publicId;
3745
+ var sysid = node.systemId;
3746
+ buf.push(g$1.DOCTYPE_DECL_START, ' ', node.name);
3747
+ if (pubid) {
3748
+ buf.push(' ', g$1.PUBLIC, ' ', pubid);
3749
+ if (sysid && sysid !== '.') {
3750
+ buf.push(' ', sysid);
3751
+ }
3752
+ } else if (sysid && sysid !== '.') {
3753
+ buf.push(' ', g$1.SYSTEM, ' ', sysid);
3754
+ }
3755
+ if (node.internalSubset) {
3756
+ buf.push(' [', node.internalSubset, ']');
4200
3757
  }
4201
- // ATTRIBUTE_NODE must always be imported deeply: its value lives in a child text node.
4202
- var shouldDeep = srcNode.nodeType === ATTRIBUTE_NODE || deep;
4203
- return shouldDeep ? destNode : null;
3758
+ buf.push('>');
3759
+ return;
3760
+ case PROCESSING_INSTRUCTION_NODE:
3761
+ return buf.push('<?', node.target, ' ', node.data, '?>');
3762
+ case ENTITY_REFERENCE_NODE:
3763
+ return buf.push('&', node.nodeName, ';');
3764
+ //case ENTITY_NODE:
3765
+ //case NOTATION_NODE:
3766
+ default:
3767
+ buf.push('??', node.nodeName);
3768
+ }
3769
+ }
3770
+ function importNode(doc, node, deep) {
3771
+ var node2;
3772
+ switch(node.nodeType){
3773
+ case ELEMENT_NODE:
3774
+ node2 = node.cloneNode(false);
3775
+ node2.ownerDocument = doc;
3776
+ //var attrs = node2.attributes;
3777
+ //var len = attrs.length;
3778
+ //for(var i=0;i<len;i++){
3779
+ //node2.setAttributeNodeNS(importNode(doc,attrs.item(i),deep));
3780
+ //}
3781
+ case DOCUMENT_FRAGMENT_NODE:
3782
+ break;
3783
+ case ATTRIBUTE_NODE:
3784
+ deep = true;
3785
+ break;
3786
+ }
3787
+ if (!node2) {
3788
+ node2 = node.cloneNode(false); //false
3789
+ }
3790
+ node2.ownerDocument = doc;
3791
+ node2.parentNode = null;
3792
+ if (deep) {
3793
+ var child = node.firstChild;
3794
+ while(child){
3795
+ node2.appendChild(importNode(doc, child, deep));
3796
+ child = child.nextSibling;
4204
3797
  }
4205
- });
4206
- return destRoot;
3798
+ }
3799
+ return node2;
4207
3800
  }
4208
3801
  /**
4209
3802
  * Creates a copy of a node from an existing one.
@@ -4221,73 +3814,46 @@ function serializeToString(node, buf, visibleNamespaces, opts) {
4221
3814
  * May throw a DOMException if operations within setAttributeNode or appendChild (which are
4222
3815
  * potentially invoked in this function) do not meet their specific constraints.
4223
3816
  */ function cloneNode(doc, node, deep) {
4224
- var destRoot;
4225
- walkDOM(node, null, {
4226
- enter: function enter(srcNode, destParent) {
4227
- // 1. Create a blank node of the same type and copy all scalar own properties.
4228
- var destNode = new srcNode.constructor(PDC);
4229
- for(var n in srcNode){
4230
- if (hasOwn$1(srcNode, n)) {
4231
- var v = srcNode[n];
4232
- if ((typeof v === "undefined" ? "undefined" : _type_of(v)) != 'object') {
4233
- if (v != destNode[n]) {
4234
- destNode[n] = v;
4235
- }
4236
- }
3817
+ var node2 = new node.constructor(PDC);
3818
+ for(var n in node){
3819
+ if (hasOwn$1(node, n)) {
3820
+ var v = node[n];
3821
+ if ((typeof v === "undefined" ? "undefined" : _type_of(v)) != 'object') {
3822
+ if (v != node2[n]) {
3823
+ node2[n] = v;
4237
3824
  }
4238
3825
  }
4239
- if (srcNode.childNodes) {
4240
- destNode.childNodes = new NodeList();
4241
- }
4242
- destNode.ownerDocument = doc;
4243
- // 2. Handle node-type-specific setup.
4244
- // Attributes are not DOM children, so they are cloned inline here
4245
- // rather than by walkDOM descent.
4246
- // ATTRIBUTE_NODE forces deep=true so its own children are walked.
4247
- var shouldDeep = deep;
4248
- switch(destNode.nodeType){
4249
- case ELEMENT_NODE:
4250
- var attrs = srcNode.attributes;
4251
- var attrs2 = destNode.attributes = new NamedNodeMap();
4252
- var len = attrs.length;
4253
- attrs2._ownerElement = destNode;
4254
- for(var i = 0; i < len; i++){
4255
- destNode.setAttributeNode(cloneNode(doc, attrs.item(i), true));
4256
- }
4257
- break;
4258
- case ATTRIBUTE_NODE:
4259
- shouldDeep = true;
4260
- }
4261
- // 3. Attach to parent, or capture as the root of the cloned subtree.
4262
- if (destParent !== null) {
4263
- destParent.appendChild(destNode);
4264
- } else {
4265
- destRoot = destNode;
3826
+ }
3827
+ }
3828
+ if (node.childNodes) {
3829
+ node2.childNodes = new NodeList();
3830
+ }
3831
+ node2.ownerDocument = doc;
3832
+ switch(node2.nodeType){
3833
+ case ELEMENT_NODE:
3834
+ var attrs = node.attributes;
3835
+ var attrs2 = node2.attributes = new NamedNodeMap();
3836
+ var len = attrs.length;
3837
+ attrs2._ownerElement = node2;
3838
+ for(var i = 0; i < len; i++){
3839
+ node2.setAttributeNode(cloneNode(doc, attrs.item(i), true));
4266
3840
  }
4267
- // 4. Return destNode as the context for children (causes walkDOM to descend),
4268
- // or null to skip children (shallow clone).
4269
- return shouldDeep ? destNode : null;
3841
+ break;
3842
+ case ATTRIBUTE_NODE:
3843
+ deep = true;
3844
+ }
3845
+ if (deep) {
3846
+ var child = node.firstChild;
3847
+ while(child){
3848
+ node2.appendChild(cloneNode(doc, child, deep));
3849
+ child = child.nextSibling;
4270
3850
  }
4271
- });
4272
- return destRoot;
3851
+ }
3852
+ return node2;
4273
3853
  }
4274
3854
  function __set__(object, key, value) {
4275
3855
  object[key] = value;
4276
3856
  }
4277
- // Returns a new array of direct Element children.
4278
- // Passed to LiveNodeList to implement ParentNode.children.
4279
- // https://dom.spec.whatwg.org/#dom-parentnode-children
4280
- function childrenRefresh(node) {
4281
- var ls = [];
4282
- var child = node.firstChild;
4283
- while(child){
4284
- if (child.nodeType === ELEMENT_NODE) {
4285
- ls.push(child);
4286
- }
4287
- child = child.nextSibling;
4288
- }
4289
- return ls;
4290
- }
4291
3857
  //do dynamic
4292
3858
  try {
4293
3859
  if (Object.defineProperty) {
@@ -4297,36 +3863,9 @@ try {
4297
3863
  return this.$$length;
4298
3864
  }
4299
3865
  });
4300
- /**
4301
- * The text content of this node and its descendants.
4302
- *
4303
- * For {@link Element} and {@link DocumentFragment} nodes, returns the concatenation of the
4304
- * `nodeValue` of every descendant text node, excluding processing instruction and comment
4305
- * nodes. For all other node types, returns `nodeValue`.
4306
- *
4307
- * Setting `textContent` on an element or document fragment replaces all child nodes with a
4308
- * single text node; on other nodes it sets `data`, `value`, and `nodeValue` directly.
4309
- *
4310
- * @type {string | null}
4311
- * @see {@link https://dom.spec.whatwg.org/#dom-node-textcontent}
4312
- */ Object.defineProperty(Node.prototype, 'textContent', {
3866
+ Object.defineProperty(Node.prototype, 'textContent', {
4313
3867
  get: function get() {
4314
- if (this.nodeType === ELEMENT_NODE || this.nodeType === DOCUMENT_FRAGMENT_NODE) {
4315
- var buf = [];
4316
- walkDOM(this, null, {
4317
- enter: function enter(n) {
4318
- if (n.nodeType === ELEMENT_NODE || n.nodeType === DOCUMENT_FRAGMENT_NODE) {
4319
- return true; // enter children
4320
- }
4321
- if (n.nodeType === PROCESSING_INSTRUCTION_NODE || n.nodeType === COMMENT_NODE) {
4322
- return null; // excluded from text content
4323
- }
4324
- buf.push(n.nodeValue);
4325
- }
4326
- });
4327
- return buf.join('');
4328
- }
4329
- return this.nodeValue;
3868
+ return getTextContent(this);
4330
3869
  },
4331
3870
  set: function set(data) {
4332
3871
  switch(this.nodeType){
@@ -4346,21 +3885,23 @@ try {
4346
3885
  }
4347
3886
  }
4348
3887
  });
4349
- Object.defineProperty(Element.prototype, 'children', {
4350
- get: function get() {
4351
- return new LiveNodeList(this, childrenRefresh);
4352
- }
4353
- });
4354
- Object.defineProperty(Document.prototype, 'children', {
4355
- get: function get() {
4356
- return new LiveNodeList(this, childrenRefresh);
4357
- }
4358
- });
4359
- Object.defineProperty(DocumentFragment.prototype, 'children', {
4360
- get: function get() {
4361
- return new LiveNodeList(this, childrenRefresh);
3888
+ function getTextContent(node) {
3889
+ switch(node.nodeType){
3890
+ case ELEMENT_NODE:
3891
+ case DOCUMENT_FRAGMENT_NODE:
3892
+ var buf = [];
3893
+ node = node.firstChild;
3894
+ while(node){
3895
+ if (node.nodeType !== 7 && node.nodeType !== 8) {
3896
+ buf.push(getTextContent(node));
3897
+ }
3898
+ node = node.nextSibling;
3899
+ }
3900
+ return buf.join('');
3901
+ default:
3902
+ return node.nodeValue;
4362
3903
  }
4363
- });
3904
+ }
4364
3905
  __set__ = function __set__(object, key, value) {
4365
3906
  //console.log(value)
4366
3907
  object['$$' + key] = value;
@@ -4388,7 +3929,6 @@ dom$2.NodeList = NodeList;
4388
3929
  dom$2.Notation = Notation;
4389
3930
  dom$2.Text = Text;
4390
3931
  dom$2.ProcessingInstruction = ProcessingInstruction;
4391
- dom$2.walkDOM = walkDOM;
4392
3932
  dom$2.XMLSerializer = XMLSerializer$1;
4393
3933
 
4394
3934
  var domParser$1 = {};
@@ -8092,200 +7632,76 @@ function requireErrors () {
8092
7632
  this.stack = new Error(message).stack;
8093
7633
  }
8094
7634
  XTAPIVersionError.prototype = new XTError();
8095
- /*
8096
- * Version/Compatibility Errors
8097
- * ============================
8098
- */ function throwApiVersionError(msg, properties) {
7635
+ function throwApiVersionError(msg, properties) {
8099
7636
  var err = new XTAPIVersionError(msg);
8100
- /*
8101
- * This error arises when a recent module version necessitates a more
8102
- * current version of the docxtemplater core. Docxtemplater specifies an
8103
- * "APIVersion," and if a module requires API Version 3.55 or higher,
8104
- * but the docxtemplater instance provides API 3.52, this error will
8105
- * occur. To resolve this issue, please update to the latest version of
8106
- * docxtemplater.
8107
- */ err.properties = _objectSpread({
7637
+ err.properties = _objectSpread({
8108
7638
  id: "api_version_error"
8109
7639
  }, properties);
8110
7640
  throw err;
8111
7641
  }
8112
- function throwFileTypeNotIdentified(zip) {
8113
- var files = Object.keys(zip.files).slice(0, 10);
8114
- var msg = "";
8115
- if (files.length === 0) {
8116
- msg = "Empty zip file";
8117
- } else {
8118
- msg = "Zip file contains : ".concat(files.join(","));
8119
- }
8120
- var err = new XTInternalError("The filetype for this file could not be identified, is this file corrupted ? ".concat(msg));
8121
- /*
8122
- * This error happens if you're creating docxtemplater with a zip file, but that file is not recognized as a docx/pptx/xlsx or odt file.
8123
- *
8124
- * Note that xlsx files and odt files need a paid module to be templated.
8125
- *
8126
- * Other zip files (zip, odp, ods) will trigger the same error.
8127
- */ err.properties = {
8128
- id: "filetype_not_identified",
8129
- explanation: "The filetype for this file could not be identified, is this file corrupted ? ".concat(msg)
8130
- };
8131
- throw err;
8132
- }
8133
- function throwFileTypeNotHandled(fileType) {
8134
- var err = new XTInternalError("The filetype \"".concat(fileType, "\" is not handled by docxtemplater"));
8135
- /*
8136
- * This error happens if the filetype was recognized (xlsx, odt), but
8137
- * without the correct module, this file cannot be templated
8138
- */ err.properties = {
8139
- id: "filetype_not_handled",
8140
- explanation: "The file you are trying to generate is of type \"".concat(fileType, "\", but only docx and pptx formats are handled"),
8141
- fileType: fileType
8142
- };
8143
- throw err;
8144
- }
8145
- /*
8146
- * Template Errors
8147
- * ===============
8148
- */ function throwMultiError(errors) {
8149
- var err = new XTTemplateError("Multi error");
8150
- /*
8151
- * This error is an Error that contains all template errors.
8152
- * It is a multi error because it contains all errors of the template in :
8153
- * err.properties.errors.
8154
- *
8155
- * You can then map on each sub error like this :
8156
- *
8157
- * ```js
8158
- * for (const err of error.properties.errors) {
8159
- * console.log(err.properties.explanation);
8160
- * }
8161
- * ```
8162
- */ err.properties = {
8163
- errors: errors,
8164
- id: "multi_error",
8165
- explanation: "The template has multiple errors"
7642
+ function throwMultiError(errors) {
7643
+ var err = new XTTemplateError("Multi error");
7644
+ err.properties = {
7645
+ errors: errors,
7646
+ id: "multi_error",
7647
+ explanation: "The template has multiple errors"
8166
7648
  };
8167
7649
  throw err;
8168
7650
  }
8169
7651
  function getUnopenedTagException(options) {
8170
7652
  var err = new XTTemplateError("Unopened tag");
8171
- /*
8172
- * This error happens if a tag is closed but not opened. For example with
8173
- * the following template:
8174
- *
8175
- * ```docx
8176
- * Hello name} !
8177
- * ```
8178
- */ err.properties = {
7653
+ err.properties = {
8179
7654
  xtag: last(options.xtag.split(" ")),
8180
7655
  id: "unopened_tag",
8181
7656
  context: options.xtag,
8182
7657
  offset: options.offset,
8183
7658
  lIndex: options.lIndex,
8184
- explanation: "The tag beginning with \"".concat(options.xtag.substr(0, 30), "\" is unopened")
7659
+ explanation: "The tag beginning with \"".concat(options.xtag.substr(0, 10), "\" is unopened")
8185
7660
  };
8186
7661
  return err;
8187
7662
  }
8188
7663
  function getDuplicateOpenTagException(options) {
8189
7664
  var err = new XTTemplateError("Duplicate open tag, expected one open tag");
8190
- /*
8191
- * This error happens with following template :
8192
- *
8193
- * ```docx
8194
- * Hello {{name
8195
- * ```
8196
- */ err.properties = {
7665
+ err.properties = {
8197
7666
  xtag: first(options.xtag.split(" ")),
8198
7667
  id: "duplicate_open_tag",
8199
7668
  context: options.xtag,
8200
7669
  offset: options.offset,
8201
7670
  lIndex: options.lIndex,
8202
- explanation: "The tag beginning with \"".concat(options.xtag.substr(0, 30), "\" has duplicate open tags")
7671
+ explanation: "The tag beginning with \"".concat(options.xtag.substr(0, 10), "\" has duplicate open tags")
8203
7672
  };
8204
7673
  return err;
8205
7674
  }
8206
7675
  function getDuplicateCloseTagException(options) {
8207
7676
  var err = new XTTemplateError("Duplicate close tag, expected one close tag");
8208
- /*
8209
- * This error happens with following template :
8210
- *
8211
- * ```docx
8212
- * Hello {name}}
8213
- * ```
8214
- */ err.properties = {
7677
+ err.properties = {
8215
7678
  xtag: first(options.xtag.split(" ")),
8216
7679
  id: "duplicate_close_tag",
8217
7680
  context: options.xtag,
8218
7681
  offset: options.offset,
8219
7682
  lIndex: options.lIndex,
8220
- explanation: "The tag ending with \"".concat(options.xtag.substr(0, 30), "\" has duplicate close tags")
7683
+ explanation: "The tag ending with \"".concat(options.xtag.substr(0, 10), "\" has duplicate close tags")
8221
7684
  };
8222
7685
  return err;
8223
7686
  }
8224
7687
  function getUnclosedTagException(options) {
8225
7688
  var err = new XTTemplateError("Unclosed tag");
8226
- /*
8227
- * This error happens if a tag is opened but not closed.
8228
- * For example with the following template:
8229
- *
8230
- * ```docx
8231
- * Hello {name !
8232
- * ```
8233
- */ err.properties = {
7689
+ err.properties = {
8234
7690
  xtag: first(options.xtag.split(" ")).substr(1),
8235
- // name
8236
7691
  id: "unclosed_tag",
8237
7692
  context: options.xtag,
8238
7693
  offset: options.offset,
8239
7694
  lIndex: options.lIndex,
8240
- explanation: "The tag beginning with \"".concat(options.xtag.substr(0, 30), "\" is unclosed")
7695
+ explanation: "The tag beginning with \"".concat(options.xtag.substr(0, 10), "\" is unclosed")
8241
7696
  };
8242
7697
  return err;
8243
7698
  }
8244
7699
  function throwXmlTagNotFound(options) {
8245
- if (options.position === "left") {
8246
- throwXmlTagNotFoundLeft(options);
8247
- } else {
8248
- throwXmlTagNotFoundRight(options);
8249
- }
8250
- }
8251
- /*
8252
- * Raw XML / XML Expansion Errors
8253
- * ==============================
8254
- */ function throwXmlTagNotFoundLeft(options) {
8255
7700
  var err = new XTTemplateError("No tag \"".concat(options.element, "\" was found at the ").concat(options.position));
8256
7701
  var part = options.parsed[options.index];
8257
- /*
8258
- * This error is not directly linked to the template, it means that some
8259
- * tag tried to expand to adjacent XML tags, but those elements cannot be
8260
- * accessed from the current node.
8261
- *
8262
- * This error happens if a rawXMLTag doesn't find a `<w:p>` element
8263
- *
8264
- * ```docx
8265
- * <w:p><w:t>{@raw}</w:t>
8266
- * // Note that the `</w:p>` tag is missing.
8267
- * ```
8268
- */ err.properties = {
8269
- id: "no_xml_tag_found_at_left",
8270
- explanation: "No tag \"".concat(options.element, "\" was found at the left"),
8271
- offset: part.offset,
8272
- part: part,
8273
- parsed: options.parsed,
8274
- index: options.index,
8275
- element: options.element
8276
- };
8277
- throw err;
8278
- }
8279
- function throwXmlTagNotFoundRight(options) {
8280
- var err = new XTTemplateError("No tag \"".concat(options.element, "\" was found at the ").concat(options.position));
8281
- var part = options.parsed[options.index];
8282
- /*
8283
- * This error is not directly linked to the template, it means that some
8284
- * tag tried to expand to adjacent XML tags, but those elements cannot be
8285
- * accessed from the current node.
8286
- */ err.properties = {
8287
- id: "no_xml_tag_found_at_right",
8288
- explanation: "No tag \"".concat(options.element, "\" was found at the right"),
7702
+ err.properties = {
7703
+ id: "no_xml_tag_found_at_".concat(options.position),
7704
+ explanation: "No tag \"".concat(options.element, "\" was found at the ").concat(options.position),
8289
7705
  offset: part.offset,
8290
7706
  part: part,
8291
7707
  parsed: options.parsed,
@@ -8297,35 +7713,24 @@ function requireErrors () {
8297
7713
  function getCorruptCharactersException(_ref) {
8298
7714
  var tag = _ref.tag, value = _ref.value, offset = _ref.offset;
8299
7715
  var err = new XTRenderingError("There are some XML corrupt characters");
8300
- /*
8301
- * This error prevents the docx document to become corrupt.
8302
- * It happens if you're trying to render text that would produce invalid XML output.
8303
- *
8304
- * See #corrupt-character-error on how this can be fixed by changing your parser.
8305
- */ err.properties = {
7716
+ err.properties = {
8306
7717
  id: "invalid_xml_characters",
8307
7718
  xtag: tag,
8308
7719
  value: value,
8309
7720
  offset: offset,
8310
- explanation: "There are some corrupt characters for the field \"".concat(tag, "\"")
7721
+ explanation: "There are some corrupt characters for the field ".concat(tag)
8311
7722
  };
8312
7723
  return err;
8313
7724
  }
8314
7725
  function getInvalidRawXMLValueException(_ref2) {
8315
- var tag = _ref2.tag, value = _ref2.value, offset = _ref2.offset, partDelims = _ref2.partDelims;
7726
+ var tag = _ref2.tag, value = _ref2.value, offset = _ref2.offset;
8316
7727
  var err = new XTRenderingError("Non string values are not allowed for rawXML tags");
8317
- /*
8318
- * This error happens if you try to render a rawXml tag, such as : {@raw}
8319
- * And the value of the data for "raw" is truthy but not a string.
8320
- *
8321
- * (If the value of the data is falsy, than the tag is simply dropped and
8322
- * no error is thrown)
8323
- */ err.properties = {
7728
+ err.properties = {
8324
7729
  id: "invalid_raw_xml_value",
8325
7730
  xtag: tag,
8326
7731
  value: value,
8327
7732
  offset: offset,
8328
- explanation: "The value of the raw tag : \"".concat(partDelims, "\" is not a string")
7733
+ explanation: "The value of the raw tag : '".concat(tag, "' is not a string")
8329
7734
  };
8330
7735
  return err;
8331
7736
  }
@@ -8336,10 +7741,7 @@ function requireErrors () {
8336
7741
  if (typeof explanation === "function") {
8337
7742
  explanation = explanation(part);
8338
7743
  }
8339
- /*
8340
- * This error happens if you try to render a rawXml tag, such as : {@raw},
8341
- * but that tag is not placed inside a paragraph.
8342
- */ var err = new XTTemplateError(message);
7744
+ var err = new XTTemplateError(message);
8343
7745
  err.properties = {
8344
7746
  id: id,
8345
7747
  explanation: explanation,
@@ -8355,36 +7757,7 @@ function requireErrors () {
8355
7757
  function throwRawTagShouldBeOnlyTextInParagraph(options) {
8356
7758
  var err = new XTTemplateError("Raw tag should be the only text in paragraph");
8357
7759
  var tag = options.part.value;
8358
- /*
8359
- * This happens when a rawXMLTag {@raw} is not the only text in the
8360
- * paragraph. For example, writing ` {@raw}` (Note the spaces)
8361
- * is not acceptable because the {@raw} tag replaces the full paragraph. We
8362
- * prefer to throw an Error now rather than have "strange behavior"
8363
- * because the spaces "disappeared".
8364
- *
8365
- * To correct this error, you have to add manually the text that you want
8366
- * in your raw tag. (Or you can use the [docxtemplater word-run
8367
- * module](/modules/word-run/) which adds a tag
8368
- * that can replace rawXML inside a tag).
8369
- *
8370
- * Writing
8371
- *
8372
- * ```docx
8373
- * {@my_first_tag}{my_second_tag}
8374
- * ```
8375
- *
8376
- * Or even
8377
- *
8378
- * ```docx
8379
- * Hello {@my_first_tag}
8380
- * ```
8381
- *
8382
- * Is misusing docxtemplater.
8383
- *
8384
- * The `@` at the beginning means "replace the xml of **the
8385
- * current paragraph** with scope.my_first_tag" so that means that
8386
- * everything else in that Paragraph will be removed.
8387
- */ err.properties = {
7760
+ err.properties = {
8388
7761
  id: "raw_xml_tag_should_be_only_text_in_paragraph",
8389
7762
  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."),
8390
7763
  xtag: tag,
@@ -8393,23 +7766,13 @@ function requireErrors () {
8393
7766
  };
8394
7767
  throw err;
8395
7768
  }
8396
- /*
8397
- * Loop / Table Structure Errors
8398
- * =============================
8399
- */ function getUnmatchedLoopException(part) {
7769
+ function getUnmatchedLoopException(part) {
8400
7770
  var location = part.location, offset = part.offset, square = part.square;
8401
7771
  var t = location === "start" ? "unclosed" : "unopened";
8402
7772
  var T = location === "start" ? "Unclosed" : "Unopened";
8403
7773
  var err = new XTTemplateError("".concat(T, " loop"));
8404
7774
  var tag = part.value;
8405
- /*
8406
- * This error happens with following template :
8407
- *
8408
- * ```docx
8409
- * {#users}
8410
- * {/companies}
8411
- * ```
8412
- */ err.properties = {
7775
+ err.properties = {
8413
7776
  id: "".concat(t, "_loop"),
8414
7777
  explanation: "The loop with tag \"".concat(tag, "\" is ").concat(t),
8415
7778
  xtag: tag,
@@ -8426,25 +7789,7 @@ function requireErrors () {
8426
7789
  var lastR = lastPair[1].part.value;
8427
7790
  var l = pair[0].part.value;
8428
7791
  var r = pair[1].part.value;
8429
- /*
8430
- * This error happens if you create a table and misplace tags inside the table :
8431
- *
8432
- * ```docx-md
8433
- * | Head1 | Head2 |
8434
- * | -------- | ------------ |
8435
- * | {#a}X | {/a}{#b}Y{/b} |
8436
- * ```
8437
- *
8438
- * In the case above, the {#a} and {/a} will expand to the whole loop, but this is not possible because of the other loop in {#b}Y{/b}
8439
- *
8440
- * Instead, you should usually write :
8441
- *
8442
- * ```docx-md
8443
- * | Head1 | Head2 |
8444
- * | -------- | ------------ |
8445
- * | {#a}X | {#b}Y{/b}{/a} |
8446
- * ```
8447
- */ err.properties = {
7792
+ err.properties = {
8448
7793
  id: "unbalanced_loop_tags",
8449
7794
  explanation: "Unbalanced loop tags {#".concat(lastL, "}{/").concat(lastR, "}{#").concat(l, "}{/").concat(r, "}"),
8450
7795
  offset: [
@@ -8465,17 +7810,7 @@ function requireErrors () {
8465
7810
  function getClosingTagNotMatchOpeningTag(_ref3) {
8466
7811
  var tags = _ref3.tags;
8467
7812
  var err = new XTTemplateError("Closing tag does not match opening tag");
8468
- /*
8469
- * This error happens if your loop tags are incorrectly closed
8470
- *
8471
- * ```docx
8472
- * {#condition1}
8473
- * Some text
8474
- * {/otherCondition}
8475
- * ```
8476
- *
8477
- * Since the start tag does not match the open tag, the template is invalid.
8478
- */ err.properties = {
7813
+ err.properties = {
8479
7814
  id: "closing_tag_does_not_match_opening_tag",
8480
7815
  explanation: "The tag \"".concat(tags[0].value, "\" is closed by the tag \"").concat(tags[1].value, "\""),
8481
7816
  openingtag: first(tags).value,
@@ -8493,53 +7828,10 @@ function requireErrors () {
8493
7828
  }
8494
7829
  return err;
8495
7830
  }
8496
- function getLoopPositionProducesInvalidXMLError(_ref4) {
8497
- var tag = _ref4.tag, offset = _ref4.offset;
8498
- var err = new XTTemplateError("The position of the loop tags \"".concat(tag, "\" would produce invalid XML"));
8499
- /*
8500
- * This happens when a loop would produce invalid XML.
8501
- *
8502
- * For example, if you write:
8503
- *
8504
- * ```docx-md
8505
- * | Head1 | Head2 |
8506
- * | -------- | ------------ |
8507
- * | {#users} | content |
8508
- *
8509
- * {/users}
8510
- * ```
8511
- *
8512
- * this is not allowed since a loop that starts in a table must also end
8513
- * in that table.
8514
- */ err.properties = {
8515
- xtag: tag,
8516
- id: "loop_position_invalid",
8517
- 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"),
8518
- offset: offset
8519
- };
8520
- return err;
8521
- }
8522
- /*
8523
- * Scope Parser Errors
8524
- * ===================
8525
- */ function getScopeCompilationError(_ref5) {
8526
- var tag = _ref5.tag, rootError = _ref5.rootError, offset = _ref5.offset;
7831
+ function getScopeCompilationError(_ref4) {
7832
+ var tag = _ref4.tag, rootError = _ref4.rootError, offset = _ref4.offset;
8527
7833
  var err = new XTScopeParserError("Scope parser compilation failed");
8528
- /*
8529
- * This happens when your parser throws an error during compilation. The
8530
- * parser is the second argument of the constructor
8531
- * `new Docxtemplater(zip, {parser: function parser(tag) {}});`
8532
- *
8533
- * For example, if your template is:
8534
- *
8535
- * ```docx
8536
- * {name++}
8537
- * ```
8538
- *
8539
- * and you use the angular expression parser, you will have this error. The error
8540
- * happens when you call parser('name++'); The underlying error can be
8541
- * read in `e.properties.rootError`
8542
- */ err.properties = {
7834
+ err.properties = {
8543
7835
  id: "scopeparser_compilation_failed",
8544
7836
  offset: offset,
8545
7837
  xtag: tag,
@@ -8548,47 +7840,12 @@ function requireErrors () {
8548
7840
  };
8549
7841
  return err;
8550
7842
  }
8551
- function getScopeParserExecutionError(_ref6) {
8552
- var tag = _ref6.tag, scope = _ref6.scope, error = _ref6.error, offset = _ref6.offset;
7843
+ function getScopeParserExecutionError(_ref5) {
7844
+ var tag = _ref5.tag, scope = _ref5.scope, error = _ref5.error, offset = _ref5.offset;
8553
7845
  var err = new XTScopeParserError("Scope parser execution failed");
8554
- /*
8555
- * This happens when your parser throws an error during execution. The
8556
- * parser is the second argument of the constructor
8557
- * `new Docxtemplater(zip, {parser: function parser(tag) {}});`
8558
- *
8559
- * For example, if your template is:
8560
- *
8561
- * ```docx
8562
- * {test | toFixed}
8563
- * ```
8564
- *
8565
- * and your code is :
8566
- *
8567
- * ```js
8568
- * const expressionParser = require("docxtemplater/expressions.js");
8569
- * const doc = new Docxtemplater(zip, {
8570
- * paragraphLoop: true,
8571
- * linebreaks: true,
8572
- * parser: expressionParser.configure({
8573
- * filters: {
8574
- * toFixed(input) {
8575
- * return input.toFixed();
8576
- * }
8577
- * }
8578
- * }),
8579
- * });
8580
- * doc.render({
8581
- * test: false
8582
- * });
8583
- * ```
8584
- *
8585
- * Since false.toFixed() triggers an error in Javascript, this will then throw an error "Scope parser execution failed".
8586
- *
8587
- * You can either fix your data or make your toFixed function more robust
8588
- * by returning "input" if the input is not a number.
8589
- */ err.properties = {
7846
+ err.properties = {
8590
7847
  id: "scopeparser_execution_failed",
8591
- explanation: "The scope parser for the tag \"".concat(tag, "\" failed to execute"),
7848
+ explanation: "The scope parser for the tag ".concat(tag, " failed to execute"),
8592
7849
  scope: scope,
8593
7850
  offset: offset,
8594
7851
  xtag: tag,
@@ -8596,20 +7853,24 @@ function requireErrors () {
8596
7853
  };
8597
7854
  return err;
8598
7855
  }
8599
- /*
8600
- * Internal / API Misuse Errors
8601
- * ============================
8602
- */ function throwUnimplementedTagType(part, index) {
7856
+ function getLoopPositionProducesInvalidXMLError(_ref6) {
7857
+ var tag = _ref6.tag, offset = _ref6.offset;
7858
+ var err = new XTTemplateError("The position of the loop tags \"".concat(tag, "\" would produce invalid XML"));
7859
+ err.properties = {
7860
+ xtag: tag,
7861
+ id: "loop_position_invalid",
7862
+ 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"),
7863
+ offset: offset
7864
+ };
7865
+ return err;
7866
+ }
7867
+ function throwUnimplementedTagType(part, index) {
8603
7868
  var errorMsg = "Unimplemented tag type \"".concat(part.type, "\"");
8604
7869
  if (part.module) {
8605
7870
  errorMsg += " \"".concat(part.module, "\"");
8606
7871
  }
8607
7872
  var err = new XTTemplateError(errorMsg);
8608
- /*
8609
- * This happens when a tag type is not implemented. It should normally not happen,
8610
- * unless you changed docxtemplater code or created your own module and didn't
8611
- * implement the `render` function of your module correctly.
8612
- */ err.properties = {
7873
+ err.properties = {
8613
7874
  part: part,
8614
7875
  index: index,
8615
7876
  id: "unimplemented_tag_type"
@@ -8618,10 +7879,7 @@ function requireErrors () {
8618
7879
  }
8619
7880
  function throwMalformedXml() {
8620
7881
  var err = new XTInternalError("Malformed xml");
8621
- /*
8622
- * This happens when an xml file of the document cannot be parsed
8623
- * correctly.
8624
- */ err.properties = {
7882
+ err.properties = {
8625
7883
  explanation: "The template contains malformed xml",
8626
7884
  id: "malformed_xml"
8627
7885
  };
@@ -8629,13 +7887,7 @@ function requireErrors () {
8629
7887
  }
8630
7888
  function throwResolveBeforeCompile() {
8631
7889
  var err = new XTInternalError("You must run `.compile()` before running `.resolveData()`");
8632
- /*
8633
- * This happens if you're calling `resolveData()` before you run `.compile()`.
8634
- *
8635
- * You should always call `compile` first and then only `resolveData`
8636
- *
8637
- * Or you can migrate to [the constructor with two arguments](/docs/get-started-node/#usage)
8638
- */ err.properties = {
7890
+ err.properties = {
8639
7891
  id: "resolve_before_compile",
8640
7892
  explanation: "You must run `.compile()` before running `.resolveData()`"
8641
7893
  };
@@ -8643,9 +7895,7 @@ function requireErrors () {
8643
7895
  }
8644
7896
  function throwRenderInvalidTemplate() {
8645
7897
  var err = new XTInternalError("You should not call .render on a document that had compilation errors");
8646
- /*
8647
- * This happens if you're calling `render()` on a document that had template errors
8648
- */ err.properties = {
7898
+ err.properties = {
8649
7899
  id: "render_on_invalid_template",
8650
7900
  explanation: "You should not call .render on a document that had compilation errors"
8651
7901
  };
@@ -8653,25 +7903,30 @@ function requireErrors () {
8653
7903
  }
8654
7904
  function throwRenderTwice() {
8655
7905
  var err = new XTInternalError("You should not call .render twice on the same docxtemplater instance");
8656
- /*
8657
- * This happens if you're calling `render()` on a document twice.
8658
- *
8659
- * You should always create a new docxtemplater instance if you need to create two output documents.
8660
- */ err.properties = {
7906
+ err.properties = {
8661
7907
  id: "render_twice",
8662
7908
  explanation: "You should not call .render twice on the same docxtemplater instance"
8663
7909
  };
8664
7910
  throw err;
8665
7911
  }
7912
+ function throwFileTypeNotIdentified(zip) {
7913
+ var files = Object.keys(zip.files).slice(0, 10);
7914
+ var msg = "";
7915
+ if (files.length === 0) {
7916
+ msg = "Empty zip file";
7917
+ } else {
7918
+ msg = "Zip file contains : ".concat(files.join(","));
7919
+ }
7920
+ var err = new XTInternalError("The filetype for this file could not be identified, is this file corrupted ? ".concat(msg));
7921
+ err.properties = {
7922
+ id: "filetype_not_identified",
7923
+ explanation: "The filetype for this file could not be identified, is this file corrupted ? ".concat(msg)
7924
+ };
7925
+ throw err;
7926
+ }
8666
7927
  function throwXmlInvalid(content, offset) {
8667
7928
  var err = new XTTemplateError("An XML file has invalid xml");
8668
- /*
8669
- * This error happens if the XML is invalid in your template file.
8670
- *
8671
- * This should be very rare except if you were using a tool to preprocess
8672
- * the template (an XML error in a docx file means that the template file
8673
- * is already corrupt).
8674
- */ err.properties = {
7929
+ err.properties = {
8675
7930
  id: "file_has_invalid_xml",
8676
7931
  content: content,
8677
7932
  offset: offset,
@@ -8679,6 +7934,15 @@ function requireErrors () {
8679
7934
  };
8680
7935
  throw err;
8681
7936
  }
7937
+ function throwFileTypeNotHandled(fileType) {
7938
+ var err = new XTInternalError("The filetype \"".concat(fileType, "\" is not handled by docxtemplater"));
7939
+ err.properties = {
7940
+ id: "filetype_not_handled",
7941
+ explanation: "The file you are trying to generate is of type \"".concat(fileType, "\", but only docx and pptx formats are handled"),
7942
+ fileType: fileType
7943
+ };
7944
+ throw err;
7945
+ }
8682
7946
  errors = {
8683
7947
  XTError: XTError,
8684
7948
  XTTemplateError: XTTemplateError,
@@ -8782,14 +8046,6 @@ function parser(tag) {
8782
8046
  }
8783
8047
  };
8784
8048
  }
8785
- function defaultWarnFn(errors) {
8786
- for(var _i2 = 0; _i2 < errors.length; _i2++){
8787
- var error = errors[_i2];
8788
- if (error.message) {
8789
- /* eslint-disable-next-line no-console */ console.warn("Warning : " + error.message);
8790
- }
8791
- }
8792
- }
8793
8049
  var attrToRegex = {};
8794
8050
  function setSingleAttribute(partValue, attr, attrValue) {
8795
8051
  var regex;
@@ -8851,8 +8107,8 @@ function chunkBy(parsed, f) {
8851
8107
  var chunks = [
8852
8108
  []
8853
8109
  ];
8854
- for(var _i4 = 0; _i4 < parsed.length; _i4++){
8855
- var p = parsed[_i4];
8110
+ for(var _i2 = 0; _i2 < parsed.length; _i2++){
8111
+ var p = parsed[_i2];
8856
8112
  var currentChunk = chunks[chunks.length - 1];
8857
8113
  var res = f(p);
8858
8114
  if (res === "start") {
@@ -8867,8 +8123,8 @@ function chunkBy(parsed, f) {
8867
8123
  }
8868
8124
  } // Remove empty chunks
8869
8125
  var result = [];
8870
- for(var _i6 = 0; _i6 < chunks.length; _i6++){
8871
- var chunk = chunks[_i6];
8126
+ for(var _i4 = 0; _i4 < chunks.length; _i4++){
8127
+ var chunk = chunks[_i4];
8872
8128
  if (chunk.length > 0) {
8873
8129
  result.push(chunk);
8874
8130
  }
@@ -8887,7 +8143,6 @@ function getDefaults() {
8887
8143
  "[Content_Types].xml"
8888
8144
  ],
8889
8145
  parser: parser,
8890
- warnFn: defaultWarnFn,
8891
8146
  linebreaks: false,
8892
8147
  fileTypeConfig: null,
8893
8148
  delimiters: {
@@ -8895,11 +8150,7 @@ function getDefaults() {
8895
8150
  end: "}"
8896
8151
  },
8897
8152
  syntax: {
8898
- changeDelimiterPrefix: "=",
8899
- preserveNewlinesInTags: false,
8900
- allowUnopenedTag: false,
8901
- allowUnclosedTag: false,
8902
- allowUnbalancedLoops: false
8153
+ changeDelimiterPrefix: "="
8903
8154
  }
8904
8155
  };
8905
8156
  }
@@ -8969,10 +8220,10 @@ function utf8ToWord(string) {
8969
8220
  // This function is written with for loops for performance
8970
8221
  function concatArrays(arrays) {
8971
8222
  var result = [];
8972
- for(var _i8 = 0; _i8 < arrays.length; _i8++){
8973
- var array = arrays[_i8];
8974
- for(var _i0 = 0; _i0 < array.length; _i0++){
8975
- var el = array[_i0];
8223
+ for(var _i6 = 0; _i6 < arrays.length; _i6++){
8224
+ var array = arrays[_i6];
8225
+ for(var _i8 = 0; _i8 < array.length; _i8++){
8226
+ var el = array[_i8];
8976
8227
  result.push(el);
8977
8228
  }
8978
8229
  }
@@ -9047,8 +8298,8 @@ function getRightOrNull(parsed, elements, index) {
9047
8298
  var level = 1;
9048
8299
  for(var i = index, l = parsed.length; i < l; i++){
9049
8300
  var part = parsed[i];
9050
- for(var _i10 = 0, _elements2 = elements; _i10 < _elements2.length; _i10++){
9051
- var element = _elements2[_i10];
8301
+ for(var _i0 = 0, _elements2 = elements; _i0 < _elements2.length; _i0++){
8302
+ var element = _elements2[_i0];
9052
8303
  if (isEnding(part.value, element)) {
9053
8304
  level--;
9054
8305
  }
@@ -9083,8 +8334,8 @@ function getLeftOrNull(parsed, elements, index) {
9083
8334
  var level = 1;
9084
8335
  for(var i = index; i >= 0; i--){
9085
8336
  var part = parsed[i];
9086
- for(var _i12 = 0, _elements4 = elements; _i12 < _elements4.length; _i12++){
9087
- var element = _elements4[_i12];
8337
+ for(var _i10 = 0, _elements4 = elements; _i10 < _elements4.length; _i10++){
8338
+ var element = _elements4[_i10];
9088
8339
  if (isStarting(part.value, element)) {
9089
8340
  level--;
9090
8341
  }
@@ -9126,27 +8377,20 @@ function isParagraphEnd(_ref6) {
9126
8377
  "text:p"
9127
8378
  ].indexOf(tag) !== -1 && type === "tag" && position === "end";
9128
8379
  }
9129
- function isBreakTag(_ref7) {
9130
- var type = _ref7.type, tag = _ref7.tag, position = _ref7.position;
9131
- return [
9132
- "w:br",
9133
- "a:br"
9134
- ].indexOf(tag) !== -1 && type === "tag" && (position === "start" || position === "selfclosing");
9135
- }
9136
- function isTextStart(_ref8) {
9137
- var type = _ref8.type, position = _ref8.position, text = _ref8.text;
8380
+ function isTextStart(_ref7) {
8381
+ var type = _ref7.type, position = _ref7.position, text = _ref7.text;
9138
8382
  return text && type === "tag" && position === "start";
9139
8383
  }
9140
- function isTextEnd(_ref9) {
9141
- var type = _ref9.type, position = _ref9.position, text = _ref9.text;
8384
+ function isTextEnd(_ref8) {
8385
+ var type = _ref8.type, position = _ref8.position, text = _ref8.text;
9142
8386
  return text && type === "tag" && position === "end";
9143
8387
  }
9144
- function isContent(_ref0) {
9145
- var type = _ref0.type, position = _ref0.position;
8388
+ function isContent(_ref9) {
8389
+ var type = _ref9.type, position = _ref9.position;
9146
8390
  return type === "placeholder" || type === "content" && position === "insidetag";
9147
8391
  }
9148
- function isModule(_ref1, modules) {
9149
- var _$module = _ref1.module, type = _ref1.type;
8392
+ function isModule(_ref0, modules) {
8393
+ var _$module = _ref0.module, type = _ref0.type;
9150
8394
  if (!_instanceof$2(modules, Array)) {
9151
8395
  modules = [
9152
8396
  modules
@@ -9210,35 +8454,26 @@ function invertMap(map) {
9210
8454
  * is not stable in firefox, as the JS spec does not enforce the sort to be
9211
8455
  * stable.
9212
8456
  */ function stableSort(arr, compare) {
9213
- // Stryker disable all
9214
- var withIndex = [];
9215
- for(var i = 0; i < arr.length; i++){
9216
- withIndex.push({
9217
- item: arr[i],
9218
- index: i
9219
- });
9220
- }
9221
- withIndex.sort(function(a, b) {
8457
+ // Stryker disable all : in previous versions of Chrome, sort was not stable by itself, so we had to add this. This is to support older versions of JS runners.
8458
+ return arr.map(function(item, index) {
8459
+ return {
8460
+ item: item,
8461
+ index: index
8462
+ };
8463
+ }).sort(function(a, b) {
9222
8464
  return compare(a.item, b.item) || a.index - b.index;
8465
+ }).map(function(_ref1) {
8466
+ var item = _ref1.item;
8467
+ return item;
9223
8468
  });
9224
- var result = [];
9225
- for(var _i13 = 0; _i13 < withIndex.length; _i13++){
9226
- result.push(withIndex[_i13].item);
9227
- }
9228
- return result;
9229
8469
  // Stryker restore all
9230
8470
  }
9231
- function getPartWithDelimiters(part, options) {
9232
- return options.delimiters.start + part.raw + options.delimiters.end;
9233
- }
9234
8471
  var docUtils = {
9235
- getPartWithDelimiters: getPartWithDelimiters,
9236
8472
  endsWith: endsWith,
9237
8473
  startsWith: startsWith,
9238
8474
  isContent: isContent,
9239
8475
  isParagraphStart: isParagraphStart,
9240
8476
  isParagraphEnd: isParagraphEnd,
9241
- isBreakTag: isBreakTag,
9242
8477
  isTagStart: isTagStart,
9243
8478
  isTagEnd: isTagEnd,
9244
8479
  isTextStart: isTextStart,
@@ -9680,18 +8915,20 @@ function requireGetContentTypes () {
9680
8915
  var partName = override.getAttribute("PartName").substr(1);
9681
8916
  partNames[partName] = contentType;
9682
8917
  }
9683
- zip.file(/./).map(function(_ref) {
9684
- var name = _ref.name;
9685
- for(var _i4 = 0; _i4 < defaults.length; _i4++){
9686
- var def = defaults[_i4];
9687
- var _contentType = def.getAttribute("ContentType");
9688
- var extension = def.getAttribute("Extension");
8918
+ var _loop = function _loop() {
8919
+ var def = defaults[_i4];
8920
+ var contentType = def.getAttribute("ContentType");
8921
+ var extension = def.getAttribute("Extension");
8922
+ zip.file(/./).map(function(_ref) {
8923
+ var name = _ref.name;
9689
8924
  if (name.slice(name.length - extension.length) === extension && !partNames[name] && name !== ctXML) {
9690
- partNames[name] = _contentType;
8925
+ partNames[name] = contentType;
9691
8926
  }
9692
- }
9693
- partNames[name] || (partNames[name] = "");
9694
- });
8927
+ });
8928
+ };
8929
+ for(var _i4 = 0; _i4 < defaults.length; _i4++){
8930
+ _loop();
8931
+ }
9695
8932
  return partNames;
9696
8933
  }
9697
8934
  function getContentTypes(zip) {
@@ -9726,24 +8963,24 @@ function requireModuleWrapper () {
9726
8963
  }
9727
8964
  moduleWrapper = function(module1) {
9728
8965
  var defaults = {
9729
- on: emptyFun,
9730
8966
  set: emptyFun,
9731
- getFileType: emptyFun,
9732
- optionsTransformer: identity,
9733
- preparse: identity,
9734
8967
  matchers: function matchers() {
9735
8968
  return [];
9736
8969
  },
9737
8970
  parse: emptyFun,
8971
+ render: emptyFun,
9738
8972
  getTraits: emptyFun,
9739
- postparse: identity,
8973
+ getFileType: emptyFun,
8974
+ nullGetter: emptyFun,
8975
+ optionsTransformer: identity,
8976
+ postrender: identity,
9740
8977
  errorsTransformer: identity,
9741
- preResolve: emptyFun,
9742
- resolve: emptyFun,
9743
8978
  getRenderedMap: identity,
9744
- render: emptyFun,
9745
- nullGetter: emptyFun,
9746
- postrender: identity
8979
+ preparse: identity,
8980
+ postparse: identity,
8981
+ on: emptyFun,
8982
+ resolve: emptyFun,
8983
+ preResolve: emptyFun
9747
8984
  };
9748
8985
  if (Object.keys(defaults).every(function(key) {
9749
8986
  return !module1[key];
@@ -10007,7 +9244,25 @@ function requireTraits () {
10007
9244
  return false;
10008
9245
  }
10009
9246
  function getExpandToDefault(postparsed, pair, expandTags) {
10010
- var xmlElements = getListXmlElements(postparsed.slice(pair[0].offset, pair[1].offset));
9247
+ var parts = postparsed.slice(pair[0].offset, pair[1].offset);
9248
+ var xmlElements = getListXmlElements(parts);
9249
+ var closingTagCount = xmlElements.filter(function(tag) {
9250
+ return tag[1] === "/";
9251
+ }).length;
9252
+ var startingTagCount = xmlElements.filter(function(tag) {
9253
+ return tag[1] !== "/" && tag[tag.length - 2] !== "/";
9254
+ }).length;
9255
+ if (closingTagCount !== startingTagCount) {
9256
+ return {
9257
+ error: getLoopPositionProducesInvalidXMLError({
9258
+ tag: first(pair).part.value,
9259
+ offset: [
9260
+ first(pair).part.offset,
9261
+ last(pair).part.offset
9262
+ ]
9263
+ })
9264
+ };
9265
+ }
10011
9266
  var _loop = function _loop() {
10012
9267
  var _expandTags$_i = expandTags[_i6], contains = _expandTags$_i.contains, expand = _expandTags$_i.expand, onlyTextInTag = _expandTags$_i.onlyTextInTag;
10013
9268
  if (has(contains, xmlElements)) {
@@ -10017,8 +9272,7 @@ function requireTraits () {
10017
9272
  if (left === null || right === null) {
10018
9273
  return 0; // continue
10019
9274
  }
10020
- var subparsed = postparsed.slice(left, right);
10021
- var chunks = chunkBy(subparsed, function(p) {
9275
+ var chunks = chunkBy(postparsed.slice(left, right), function(p) {
10022
9276
  return isTagStart(contains, p) ? "start" : isTagEnd(contains, p) ? "end" : null;
10023
9277
  });
10024
9278
  var firstChunk = first(chunks);
@@ -10029,33 +9283,6 @@ function requireTraits () {
10029
9283
  return 0; // continue
10030
9284
  }
10031
9285
  }
10032
- var structured = getStructuredTagPositions(xmlElements);
10033
- var openCount = 0;
10034
- for(var _i8 = 0; _i8 < structured.length; _i8++){
10035
- var _structured$_i = structured[_i8], tag = _structured$_i.tag, position = _structured$_i.position;
10036
- if (tag === expand) {
10037
- if (position === "start") {
10038
- openCount++;
10039
- }
10040
- if (position === "end") {
10041
- openCount--;
10042
- }
10043
- }
10044
- }
10045
- if (openCount !== 0) {
10046
- // Tested by #regression-loop-with-field-and-nofield
10047
- return {
10048
- v: {
10049
- error: getLoopPositionProducesInvalidXMLError({
10050
- tag: first(pair).part.value,
10051
- offset: [
10052
- first(pair).part.offset,
10053
- last(pair).part.offset
10054
- ]
10055
- })
10056
- }
10057
- };
10058
- }
10059
9286
  return {
10060
9287
  v: {
10061
9288
  value: expand
@@ -10068,50 +9295,8 @@ function requireTraits () {
10068
9295
  if (_ret === 0) continue;
10069
9296
  if (_ret) return _ret.v;
10070
9297
  }
10071
- if (!checkStartEnd(xmlElements)) {
10072
- return {
10073
- error: getLoopPositionProducesInvalidXMLError({
10074
- tag: first(pair).part.value,
10075
- offset: [
10076
- first(pair).part.offset,
10077
- last(pair).part.offset
10078
- ]
10079
- })
10080
- };
10081
- }
10082
9298
  return {};
10083
9299
  }
10084
- function getStructuredTagPositions(xmlElements) {
10085
- var result = [];
10086
- for(var _i0 = 0; _i0 < xmlElements.length; _i0++){
10087
- var el = xmlElements[_i0];
10088
- var tag = getTagName(el);
10089
- var position = /^\s*<\//.test(el) ? "end" : "start";
10090
- result.push({
10091
- tag: tag,
10092
- position: position
10093
- });
10094
- }
10095
- return result;
10096
- }
10097
- function getTagName(tag) {
10098
- return tag.replace(/^\s*<\/?([a-zA-Z:]+).*/, "$1");
10099
- }
10100
- function checkStartEnd(xmlElements) {
10101
- if (xmlElements.length % 2 === 1) {
10102
- return false;
10103
- }
10104
- for(var i = 0, len = xmlElements.length / 2; i < len; i++){
10105
- var start = xmlElements[i];
10106
- var end = xmlElements[xmlElements.length - i - 1];
10107
- var tagNameStart = getTagName(start);
10108
- var tagNameEnd = getTagName(end);
10109
- if (tagNameStart !== tagNameEnd) {
10110
- return false;
10111
- }
10112
- }
10113
- return true;
10114
- }
10115
9300
  function getExpandLimit(part, index, postparsed, options) {
10116
9301
  var expandTo = part.expandTo || options.expandTo;
10117
9302
  // Stryker disable all : because this condition can be removed in v4 (the only usage was the image module before version 3.12.3 of the image module
@@ -10215,10 +9400,10 @@ function requireTraits () {
10215
9400
  });
10216
9401
  var maxRight = -1;
10217
9402
  var offset = 0;
10218
- for(var _i1 = 0, _len = limits.length; _i1 < _len; _i1++){
9403
+ for(var _i7 = 0, _len = limits.length; _i7 < _len; _i7++){
10219
9404
  var _postparsed;
10220
- var _limit2 = limits[_i1];
10221
- maxRight = Math.max(maxRight, _i1 > 0 ? limits[_i1 - 1].right : 0);
9405
+ var _limit2 = limits[_i7];
9406
+ maxRight = Math.max(maxRight, _i7 > 0 ? limits[_i7 - 1].right : 0);
10222
9407
  if (_limit2.left < maxRight) {
10223
9408
  continue;
10224
9409
  }
@@ -10458,7 +9643,7 @@ function requireCommon () {
10458
9643
  }
10459
9644
  }
10460
9645
  if (ftCandidate) {
10461
- continue;
9646
+ return ftCandidate;
10462
9647
  }
10463
9648
  }
10464
9649
  return ftCandidate;
@@ -10538,7 +9723,6 @@ function requireScopeManager () {
10538
9723
  function _getValue(tag, meta, num) {
10539
9724
  var _this = this;
10540
9725
  var scope = this.scopeList[num];
10541
- var lastScope = this.scopeList[this.scopeList.length - 1];
10542
9726
  if (this.root.finishedResolving) {
10543
9727
  var w = this.resolved;
10544
9728
  var _loop = function _loop() {
@@ -10584,24 +9768,11 @@ function requireScopeManager () {
10584
9768
  if (result == null && num > 0) {
10585
9769
  return _getValue.call(this, tag, meta, num - 1);
10586
9770
  }
10587
- if (typeof result === "function") {
10588
- try {
10589
- result = result(lastScope, this);
10590
- } catch (error) {
10591
- throw getScopeParserExecutionError({
10592
- tag: tag,
10593
- scope: scope,
10594
- error: error,
10595
- offset: meta.part.offset
10596
- });
10597
- }
10598
- }
10599
9771
  return result;
10600
9772
  }
10601
9773
  function _getValueAsync(tag, meta, num) {
10602
9774
  var _this2 = this;
10603
9775
  var scope = this.scopeList[num];
10604
- var lastScope = this.scopeList[this.scopeList.length - 1];
10605
9776
  // search in the scopes (in reverse order) and keep the first defined value
10606
9777
  var parser;
10607
9778
  if (!this.cachedParsers || !meta.part) {
@@ -10631,20 +9802,6 @@ function requireScopeManager () {
10631
9802
  return _getValueAsync.call(_this2, tag, meta, num - 1);
10632
9803
  }
10633
9804
  return result;
10634
- }).then(function(result) {
10635
- if (typeof result === "function") {
10636
- try {
10637
- result = result(lastScope, _this2);
10638
- } catch (error) {
10639
- throw getScopeParserExecutionError({
10640
- tag: tag,
10641
- scope: scope,
10642
- error: error,
10643
- offset: meta.part.offset
10644
- });
10645
- }
10646
- }
10647
- return result;
10648
9805
  });
10649
9806
  }
10650
9807
  var ScopeManager = /*#__PURE__*/ function() {
@@ -10714,13 +9871,22 @@ function requireScopeManager () {
10714
9871
  key: "getValue",
10715
9872
  value: function getValue(tag, meta) {
10716
9873
  var result = _getValue.call(this, tag, meta, this.scopeList.length - 1);
9874
+ if (typeof result === "function") {
9875
+ return result(this.scopeList[this.scopeList.length - 1], this);
9876
+ }
10717
9877
  return result;
10718
9878
  }
10719
9879
  },
10720
9880
  {
10721
9881
  key: "getValueAsync",
10722
9882
  value: function getValueAsync(tag, meta) {
10723
- return _getValueAsync.call(this, tag, meta, this.scopeList.length - 1);
9883
+ var _this3 = this;
9884
+ return _getValueAsync.call(this, tag, meta, this.scopeList.length - 1).then(function(result) {
9885
+ if (typeof result === "function") {
9886
+ return result(_this3.scopeList[_this3.scopeList.length - 1], _this3);
9887
+ }
9888
+ return result;
9889
+ });
10724
9890
  }
10725
9891
  },
10726
9892
  {
@@ -11019,6 +10185,11 @@ function requireLexer () {
11019
10185
  xtag: wordToUtf8(xtag),
11020
10186
  offset: lastDelimiterOffset
11021
10187
  }));
10188
+ lastDelimiterMatch = currDelimiterMatch;
10189
+ delimiterAcc.push(_objectSpread(_objectSpread({}, currDelimiterMatch), {}, {
10190
+ error: true
10191
+ }));
10192
+ return delimiterAcc;
11022
10193
  }
11023
10194
  delimiterAcc.pop();
11024
10195
  }
@@ -11061,8 +10232,9 @@ function requireLexer () {
11061
10232
  xtag: wordToUtf8(xtag),
11062
10233
  offset: lastDelimiterOffset
11063
10234
  }));
10235
+ } else {
10236
+ delimiterWithErrors.pop();
11064
10237
  }
11065
- delimiterWithErrors.pop();
11066
10238
  }
11067
10239
  return {
11068
10240
  delimiterWithErrors: delimiterWithErrors,
@@ -11181,35 +10353,28 @@ function requireLexer () {
11181
10353
  }
11182
10354
  }
11183
10355
  function parseDelimiters(innerContentParts, delimiters, syntaxOptions) {
11184
- var full = "";
11185
- for(var _i6 = 0; _i6 < innerContentParts.length; _i6++){
11186
- var p = innerContentParts[_i6];
11187
- full += p.value;
11188
- }
10356
+ var full = innerContentParts.map(function(p) {
10357
+ return p.value;
10358
+ }).join("");
11189
10359
  var delimiterMatches = getAllDelimiterIndexes(full, delimiters, syntaxOptions);
11190
10360
  var offset = 0;
11191
- var ranges = [];
11192
- for(var _i8 = 0; _i8 < innerContentParts.length; _i8++){
11193
- var part = innerContentParts[_i8];
10361
+ var ranges = innerContentParts.map(function(part) {
11194
10362
  offset += part.value.length;
11195
- ranges.push({
10363
+ return {
11196
10364
  offset: offset - part.value.length,
11197
10365
  lIndex: part.lIndex
11198
- });
11199
- }
10366
+ };
10367
+ });
11200
10368
  var _getDelimiterErrors = getDelimiterErrors(delimiterMatches, full, syntaxOptions), delimiterWithErrors = _getDelimiterErrors.delimiterWithErrors, errors = _getDelimiterErrors.errors;
11201
10369
  var cutNext = 0;
11202
10370
  var delimiterIndex = 0;
11203
- var parsed = [];
11204
- for(var i = 0; i < ranges.length; i++){
11205
- var _p = ranges[i];
11206
- var innerContentPart = innerContentParts[i];
11207
- var _offset = _p.offset;
10371
+ var parsed = ranges.map(function(p, i) {
10372
+ var offset = p.offset;
11208
10373
  var range = [
11209
- _offset,
11210
- _offset + innerContentPart.value.length
10374
+ offset,
10375
+ offset + innerContentParts[i].value.length
11211
10376
  ];
11212
- var partContent = innerContentPart.value;
10377
+ var partContent = innerContentParts[i].value;
11213
10378
  var delimitersInOffset = [];
11214
10379
  while(delimiterIndex < delimiterWithErrors.length && inRange(range, delimiterWithErrors[delimiterIndex])){
11215
10380
  delimitersInOffset.push(delimiterWithErrors[delimiterIndex]);
@@ -11221,9 +10386,9 @@ function requireLexer () {
11221
10386
  cursor = cutNext;
11222
10387
  cutNext = 0;
11223
10388
  }
11224
- for(var _i0 = 0; _i0 < delimitersInOffset.length; _i0++){
11225
- var delimiterInOffset = delimitersInOffset[_i0];
11226
- var _value = partContent.substr(cursor, delimiterInOffset.offset - _offset - cursor);
10389
+ for(var _i6 = 0; _i6 < delimitersInOffset.length; _i6++){
10390
+ var delimiterInOffset = delimitersInOffset[_i6];
10391
+ var _value = partContent.substr(cursor, delimiterInOffset.offset - offset - cursor);
11227
10392
  if (delimiterInOffset.changedelimiter) {
11228
10393
  if (delimiterInOffset.position === "start") {
11229
10394
  if (_value.length > 0) {
@@ -11233,7 +10398,7 @@ function requireLexer () {
11233
10398
  });
11234
10399
  }
11235
10400
  } else {
11236
- cursor = delimiterInOffset.offset - _offset + delimiterInOffset.length;
10401
+ cursor = delimiterInOffset.offset - offset + delimiterInOffset.length;
11237
10402
  }
11238
10403
  continue;
11239
10404
  }
@@ -11247,10 +10412,10 @@ function requireLexer () {
11247
10412
  var delimiterPart = {
11248
10413
  type: "delimiter",
11249
10414
  position: delimiterInOffset.position,
11250
- offset: cursor + _offset
10415
+ offset: cursor + offset
11251
10416
  };
11252
10417
  parts.push(delimiterPart);
11253
- cursor = delimiterInOffset.offset - _offset + delimiterInOffset.length;
10418
+ cursor = delimiterInOffset.offset - offset + delimiterInOffset.length;
11254
10419
  }
11255
10420
  cutNext = cursor - partContent.length;
11256
10421
  var value = partContent.substr(cursor);
@@ -11260,8 +10425,8 @@ function requireLexer () {
11260
10425
  value: value
11261
10426
  });
11262
10427
  }
11263
- parsed.push(parts);
11264
- }
10428
+ return parts;
10429
+ }, this);
11265
10430
  return {
11266
10431
  parsed: parsed,
11267
10432
  errors: errors
@@ -11277,8 +10442,8 @@ function requireLexer () {
11277
10442
  }
11278
10443
  function decodeContentParts(xmlparsed, fileType) {
11279
10444
  var inTextTag = false;
11280
- for(var _i10 = 0; _i10 < xmlparsed.length; _i10++){
11281
- var part = xmlparsed[_i10];
10445
+ for(var _i8 = 0; _i8 < xmlparsed.length; _i8++){
10446
+ var part = xmlparsed[_i8];
11282
10447
  inTextTag = updateInTextTag(part, inTextTag);
11283
10448
  if (part.type === "content") {
11284
10449
  part.position = inTextTag ? "insidetag" : "outsidetag";
@@ -11296,11 +10461,11 @@ function requireLexer () {
11296
10461
  var lexed = [];
11297
10462
  var index = 0;
11298
10463
  var lIndex = 0;
11299
- for(var _i12 = 0; _i12 < xmllexed.length; _i12++){
11300
- var part = xmllexed[_i12];
10464
+ for(var _i0 = 0; _i0 < xmllexed.length; _i0++){
10465
+ var part = xmllexed[_i0];
11301
10466
  if (isInsideContent(part)) {
11302
- for(var _i14 = 0, _delimiterParsed$inde2 = delimiterParsed[index]; _i14 < _delimiterParsed$inde2.length; _i14++){
11303
- var p = _delimiterParsed$inde2[_i14];
10467
+ for(var _i10 = 0, _delimiterParsed$inde2 = delimiterParsed[index]; _i10 < _delimiterParsed$inde2.length; _i10++){
10468
+ var p = _delimiterParsed$inde2[_i10];
11304
10469
  if (p.type === "content") {
11305
10470
  p.position = "insidetag";
11306
10471
  }
@@ -11322,8 +10487,8 @@ function requireLexer () {
11322
10487
  var matches = tagMatcher(content, xmltags.text, xmltags.other);
11323
10488
  var cursor = 0;
11324
10489
  var parsed = [];
11325
- for(var _i16 = 0; _i16 < matches.length; _i16++){
11326
- var match = matches[_i16];
10490
+ for(var _i12 = 0; _i12 < matches.length; _i12++){
10491
+ var match = matches[_i12];
11327
10492
  if (content.length > cursor && match.offset - cursor > 0) {
11328
10493
  parsed.push({
11329
10494
  type: "content",
@@ -11722,7 +10887,7 @@ function requireParser () {
11722
10887
  function _arrayWithHoles(r) {
11723
10888
  if (Array.isArray(r)) return r;
11724
10889
  }
11725
- var _require = docUtils, wordToUtf8 = _require.wordToUtf8, pushArray = _require.pushArray, isParagraphStart = _require.isParagraphStart, isBreakTag = _require.isBreakTag;
10890
+ var _require = docUtils, wordToUtf8 = _require.wordToUtf8, pushArray = _require.pushArray;
11726
10891
  var _require2 = requirePrefixMatcher(), match = _require2.match, getValue = _require2.getValue, getValues = _require2.getValues;
11727
10892
  function getMatchers(modules, options) {
11728
10893
  var allMatchers = [];
@@ -11857,9 +11022,6 @@ function requireParser () {
11857
11022
  return parsed;
11858
11023
  }
11859
11024
  if (token.type !== "content" || token.position !== "insidetag") {
11860
- if (options.syntax.preserveNewlinesInTags && (isBreakTag(token) || isParagraphStart(token))) {
11861
- placeHolderContent += "\n";
11862
- }
11863
11025
  if (droppedTags.indexOf(token.tag) !== -1) {
11864
11026
  return parsed;
11865
11027
  }
@@ -11871,20 +11033,17 @@ function requireParser () {
11871
11033
  }, []);
11872
11034
  },
11873
11035
  postparse: function postparse(postparsed, modules, options) {
11874
- function getTraits(traitName, postparsed, options) {
11875
- var result = [];
11876
- for(var _i10 = 0; _i10 < modules.length; _i10++){
11877
- var _module5 = modules[_i10];
11878
- result.push(_module5.getTraits(traitName, postparsed, options));
11879
- }
11880
- return result;
11036
+ function getTraits(traitName, postparsed) {
11037
+ return modules.map(function(module1) {
11038
+ return module1.getTraits(traitName, postparsed);
11039
+ });
11881
11040
  }
11882
11041
  var errors = [];
11883
11042
  function _postparse(postparsed, options) {
11884
11043
  var newPostparsed = postparsed;
11885
- for(var _i12 = 0; _i12 < modules.length; _i12++){
11886
- var _module6 = modules[_i12];
11887
- var postparseResult = _module6.postparse(newPostparsed, _objectSpread(_objectSpread({}, options), {}, {
11044
+ for(var _i10 = 0; _i10 < modules.length; _i10++){
11045
+ var _module5 = modules[_i10];
11046
+ var postparseResult = _module5.postparse(newPostparsed, _objectSpread(_objectSpread({}, options), {}, {
11888
11047
  postparse: function postparse(parsed, opts) {
11889
11048
  return _postparse(parsed, _objectSpread(_objectSpread({}, options), opts));
11890
11049
  },
@@ -12194,99 +11353,58 @@ function requireResolve () {
12194
11353
  }
12195
11354
  return false;
12196
11355
  }
12197
- function resolvePart(part, resolved, errors, options) {
12198
- var moduleResolved = moduleResolve(part, _objectSpread(_objectSpread({}, options), {}, {
12199
- resolvedId: getResolvedId(part, options)
12200
- }));
12201
- if (moduleResolved) {
12202
- return moduleResolved.then(function(value) {
12203
- resolved.push({
12204
- tag: part.value,
12205
- lIndex: part.lIndex,
12206
- value: value
12207
- });
12208
- })["catch"](function(e) {
12209
- if (_instanceof(e, Array)) {
12210
- pushArray(errors, e);
12211
- } else {
12212
- errors.push(e);
12213
- }
12214
- });
12215
- }
12216
- if (part.type === "placeholder") {
12217
- return options.scopeManager.getValueAsync(part.value, {
12218
- part: part
12219
- }).then(function(value) {
12220
- return value == null ? options.nullGetter(part) : value;
12221
- }).then(function(value) {
12222
- resolved.push({
12223
- tag: part.value,
12224
- lIndex: part.lIndex,
12225
- value: value
12226
- });
12227
- })["catch"](function(e) {
12228
- if (_instanceof(e, Array)) {
12229
- pushArray(errors, e);
12230
- } else {
12231
- errors.push(e);
12232
- }
12233
- });
12234
- }
12235
- }
12236
11356
  function resolve(options) {
12237
11357
  var resolved = [];
12238
- var errors = [];
12239
11358
  var baseNullGetter = options.baseNullGetter;
12240
- var scopeManager = options.scopeManager;
11359
+ var compiled = options.compiled, scopeManager = options.scopeManager;
12241
11360
  options.nullGetter = function(part, sm) {
12242
11361
  return baseNullGetter(part, sm || scopeManager);
12243
11362
  };
12244
11363
  options.resolved = resolved;
12245
- var p = resolveSerial(options, errors, resolved);
12246
- if (p) {
12247
- return p.then(function() {
12248
- return resolveParallel(options, errors, resolved);
12249
- });
12250
- }
12251
- return resolveParallel(options, errors, resolved);
12252
- }
12253
- function resolveSerial(options, errors, resolved) {
12254
- var p = null;
12255
- var _loop = function _loop() {
12256
- var part = _options$compiled2[_i4];
12257
- if ([
11364
+ var errors = [];
11365
+ return Promise.all(compiled.filter(function(part) {
11366
+ return [
12258
11367
  "content",
12259
11368
  "tag"
12260
- ].indexOf(part.type) !== -1) {
12261
- return 1; // continue
12262
- }
12263
- if (part.resolveFirst) {
12264
- p !== null && p !== void 0 ? p : p = Promise.resolve(null);
12265
- p = p.then(function() {
12266
- return resolvePart(part, resolved, errors, options);
11369
+ ].indexOf(part.type) === -1;
11370
+ }).reduce(function(promises, part) {
11371
+ var moduleResolved = moduleResolve(part, _objectSpread(_objectSpread({}, options), {}, {
11372
+ resolvedId: getResolvedId(part, options)
11373
+ }));
11374
+ var result;
11375
+ if (moduleResolved) {
11376
+ result = moduleResolved.then(function(value) {
11377
+ resolved.push({
11378
+ tag: part.value,
11379
+ lIndex: part.lIndex,
11380
+ value: value
11381
+ });
12267
11382
  });
11383
+ } else if (part.type === "placeholder") {
11384
+ result = scopeManager.getValueAsync(part.value, {
11385
+ part: part
11386
+ }).then(function(value) {
11387
+ return value == null ? options.nullGetter(part) : value;
11388
+ }).then(function(value) {
11389
+ resolved.push({
11390
+ tag: part.value,
11391
+ lIndex: part.lIndex,
11392
+ value: value
11393
+ });
11394
+ return value;
11395
+ });
11396
+ } else {
11397
+ return;
12268
11398
  }
12269
- };
12270
- for(var _i4 = 0, _options$compiled2 = options.compiled; _i4 < _options$compiled2.length; _i4++){
12271
- if (_loop()) continue;
12272
- }
12273
- return p;
12274
- }
12275
- function resolveParallel(options, errors, resolved) {
12276
- var promises = [];
12277
- for(var _i6 = 0, _options$compiled4 = options.compiled; _i6 < _options$compiled4.length; _i6++){
12278
- var part = _options$compiled4[_i6];
12279
- if ([
12280
- "content",
12281
- "tag"
12282
- ].indexOf(part.type) !== -1) {
12283
- continue;
12284
- }
12285
- if (!part.resolveFirst) {
12286
- promises.push(resolvePart(part, resolved, errors, options));
12287
- }
12288
- }
12289
- return Promise.all(promises).then(function() {
11399
+ promises.push(result["catch"](function(e) {
11400
+ if (_instanceof(e, Array)) {
11401
+ pushArray(errors, e);
11402
+ } else {
11403
+ errors.push(e);
11404
+ }
11405
+ }));
11406
+ return promises;
11407
+ }, [])).then(function() {
12290
11408
  return {
12291
11409
  errors: errors,
12292
11410
  resolved: resolved
@@ -12461,11 +11579,9 @@ function requireXmlTemplater () {
12461
11579
  var joinUncorrupt = requireJoinUncorrupt();
12462
11580
  function _getFullText(content, tagsXmlArray) {
12463
11581
  var matcher = xmlMatcher(content, tagsXmlArray);
12464
- var result = [];
12465
- for(var _i2 = 0, _matcher$matches2 = matcher.matches; _i2 < _matcher$matches2.length; _i2++){
12466
- var match = _matcher$matches2[_i2];
12467
- result.push(match.array[2]);
12468
- }
11582
+ var result = matcher.matches.map(function(match) {
11583
+ return match.array[2];
11584
+ });
12469
11585
  return wordToUtf8(convertSpaces(result.join("")));
12470
11586
  }
12471
11587
  xmlTemplater = /*#__PURE__*/ function() {
@@ -12493,22 +11609,18 @@ function requireXmlTemplater () {
12493
11609
  options.scopeManager = this.scopeManager;
12494
11610
  options.resolve = resolve;
12495
11611
  var errors = [];
12496
- var promises = [];
12497
- for(var _i4 = 0, _this$modules2 = this.modules; _i4 < _this$modules2.length; _i4++){
12498
- var _module = _this$modules2[_i4];
12499
- promises.push(Promise.resolve(_module.preResolve(options))["catch"](function(e) {
11612
+ return Promise.all(this.modules.map(function(module1) {
11613
+ return Promise.resolve(module1.preResolve(options))["catch"](function(e) {
12500
11614
  errors.push(e);
12501
- }));
12502
- }
12503
- return Promise.all(promises).then(function() {
11615
+ });
11616
+ })).then(function() {
12504
11617
  if (errors.length !== 0) {
12505
11618
  throw errors;
12506
11619
  }
12507
11620
  return resolve(options).then(function(_ref) {
12508
11621
  var resolved = _ref.resolved, errors = _ref.errors;
12509
- for(var i = 0; i < errors.length; i++){
11622
+ errors = errors.map(function(error) {
12510
11623
  var _error;
12511
- var error = errors[i];
12512
11624
  // If a string is thrown, convert it to a real Error
12513
11625
  if (!_instanceof(error, Error)) {
12514
11626
  error = new Error(error);
@@ -12519,8 +11631,8 @@ function requireXmlTemplater () {
12519
11631
  * thrown.
12520
11632
  */ (_error = error).properties || (_error.properties = {});
12521
11633
  error.properties.file = filePath;
12522
- errors[i] = error;
12523
- }
11634
+ return error;
11635
+ });
12524
11636
  if (errors.length !== 0) {
12525
11637
  throw errors;
12526
11638
  }
@@ -12551,9 +11663,9 @@ function requireXmlTemplater () {
12551
11663
  {
12552
11664
  key: "setModules",
12553
11665
  value: function setModules(obj) {
12554
- for(var _i6 = 0, _this$modules4 = this.modules; _i6 < _this$modules4.length; _i6++){
12555
- var _module2 = _this$modules4[_i6];
12556
- _module2.set(obj);
11666
+ for(var _i2 = 0, _this$modules2 = this.modules; _i2 < _this$modules2.length; _i2++){
11667
+ var _module = _this$modules2[_i2];
11668
+ _module.set(obj);
12557
11669
  }
12558
11670
  }
12559
11671
  },
@@ -12628,8 +11740,8 @@ function requireXmlTemplater () {
12628
11740
  {
12629
11741
  key: "errorChecker",
12630
11742
  value: function errorChecker(errors) {
12631
- for(var _i8 = 0, _errors2 = errors; _i8 < _errors2.length; _i8++){
12632
- var error = _errors2[_i8];
11743
+ for(var _i4 = 0, _errors2 = errors; _i4 < _errors2.length; _i4++){
11744
+ var error = _errors2[_i4];
12633
11745
  /*
12634
11746
  * error properties might not be defined if some foreign
12635
11747
  * (unhandled error not thrown by docxtemplater willingly) is
@@ -12637,9 +11749,9 @@ function requireXmlTemplater () {
12637
11749
  */ error.properties || (error.properties = {});
12638
11750
  error.properties.file = this.filePath;
12639
11751
  }
12640
- for(var _i0 = 0, _this$modules6 = this.modules; _i0 < _this$modules6.length; _i0++){
12641
- var _module3 = _this$modules6[_i0];
12642
- errors = _module3.errorsTransformer(errors);
11752
+ for(var _i6 = 0, _this$modules4 = this.modules; _i6 < _this$modules4.length; _i6++){
11753
+ var _module2 = _this$modules4[_i6];
11754
+ errors = _module2.errorsTransformer(errors);
12643
11755
  }
12644
11756
  }
12645
11757
  },
@@ -12647,12 +11759,12 @@ function requireXmlTemplater () {
12647
11759
  key: "baseNullGetter",
12648
11760
  value: function baseNullGetter(part, sm) {
12649
11761
  var value = null;
12650
- for(var _i10 = 0, _this$modules8 = this.modules; _i10 < _this$modules8.length; _i10++){
12651
- var _module4 = _this$modules8[_i10];
11762
+ for(var _i8 = 0, _this$modules6 = this.modules; _i8 < _this$modules6.length; _i8++){
11763
+ var _module3 = _this$modules6[_i8];
12652
11764
  if (value != null) {
12653
11765
  continue;
12654
11766
  }
12655
- value = _module4.nullGetter(part, sm, this);
11767
+ value = _module3.nullGetter(part, sm, this);
12656
11768
  }
12657
11769
  if (value != null) {
12658
11770
  return value;
@@ -12673,7 +11785,6 @@ function requireXmlTemplater () {
12673
11785
  relsType: this.relsType,
12674
11786
  baseNullGetter: this.baseNullGetter.bind(this),
12675
11787
  filePath: this.filePath,
12676
- syntax: this.syntax,
12677
11788
  fileTypeConfig: this.fileTypeConfig,
12678
11789
  fileType: this.fileType,
12679
11790
  linebreaks: this.linebreaks,
@@ -12831,20 +11942,15 @@ function requireLoop () {
12831
11942
  var _require = docUtils, chunkBy = _require.chunkBy, last = _require.last, isParagraphStart = _require.isParagraphStart, isModule = _require.isModule, pushArray = _require.pushArray, isParagraphEnd = _require.isParagraphEnd, isContent = _require.isContent, startsWith = _require.startsWith, isTagEnd = _require.isTagEnd, isTagStart = _require.isTagStart, getSingleAttribute = _require.getSingleAttribute, setSingleAttribute = _require.setSingleAttribute;
12832
11943
  var filetypes = requireFiletypes();
12833
11944
  var wrapper = requireModuleWrapper();
12834
- var _require2 = docUtils, isWhiteSpace = _require2.isWhiteSpace;
12835
11945
  var moduleName = "loop";
12836
11946
  function hasContent(parts) {
12837
- for(var _i2 = 0; _i2 < parts.length; _i2++){
12838
- var part = parts[_i2];
12839
- if (isContent(part)) {
12840
- return true;
12841
- }
12842
- }
12843
- return false;
11947
+ return parts.some(function(part) {
11948
+ return isContent(part);
11949
+ });
12844
11950
  }
12845
11951
  function getFirstMeaningFulPart(parsed) {
12846
- for(var _i4 = 0; _i4 < parsed.length; _i4++){
12847
- var part = parsed[_i4];
11952
+ for(var _i2 = 0; _i2 < parsed.length; _i2++){
11953
+ var part = parsed[_i2];
12848
11954
  if (part.type !== "content") {
12849
11955
  return part;
12850
11956
  }
@@ -12876,94 +11982,74 @@ function requireLoop () {
12876
11982
  subRendered.parts.unshift('<w:p><w:r><w:br w:type="page"/></w:r></w:p>');
12877
11983
  }
12878
11984
  function isContinuous(parts) {
12879
- for(var _i6 = 0; _i6 < parts.length; _i6++){
12880
- var part = parts[_i6];
12881
- if (isTagStart("w:type", part) && part.value.indexOf("continuous") !== -1) {
12882
- return true;
12883
- }
12884
- }
12885
- return false;
11985
+ return parts.some(function(part) {
11986
+ return isTagStart("w:type", part) && part.value.indexOf("continuous") !== -1;
11987
+ });
12886
11988
  }
12887
11989
  function isNextPage(parts) {
12888
- for(var _i8 = 0; _i8 < parts.length; _i8++){
12889
- var part = parts[_i8];
12890
- if (isTagStart("w:type", part) && part.value.indexOf('w:val="nextPage"') !== -1) {
12891
- return true;
12892
- }
12893
- }
12894
- return false;
11990
+ return parts.some(function(part) {
11991
+ return isTagStart("w:type", part) && part.value.indexOf('w:val="nextPage"') !== -1;
11992
+ });
12895
11993
  }
12896
11994
  function addSectionBefore(parts, sect) {
12897
- var result = "";
12898
- for(var _i0 = 0; _i0 < sect.length; _i0++){
12899
- var value = sect[_i0].value;
12900
- result += value;
12901
- }
12902
- parts.unshift("<w:p><w:pPr>".concat(result, "</w:pPr></w:p>"));
11995
+ return pushArray([
11996
+ "<w:p><w:pPr>".concat(sect.map(function(_ref) {
11997
+ var value = _ref.value;
11998
+ return value;
11999
+ }).join(""), "</w:pPr></w:p>")
12000
+ ], parts);
12903
12001
  }
12904
12002
  function addContinuousType(parts) {
12905
12003
  var stop = false;
12906
12004
  var inSectPr = false;
12907
- for(var i = 0; i < parts.length; i++){
12908
- var part = parts[i];
12909
- if (!stop && startsWith(part, "<w:sectPr")) {
12005
+ var result = [];
12006
+ for(var _i4 = 0; _i4 < parts.length; _i4++){
12007
+ var part = parts[_i4];
12008
+ if (stop === false && startsWith(part, "<w:sectPr")) {
12910
12009
  inSectPr = true;
12911
12010
  }
12912
12011
  if (inSectPr) {
12913
12012
  if (startsWith(part, "<w:type")) {
12914
12013
  stop = true;
12915
12014
  }
12916
- if (!stop && startsWith(part, "</w:sectPr")) {
12917
- parts.splice(i, 0, '<w:type w:val="continuous"/>');
12918
- i++; // Skip re-processing the now-shifted closing tag to avoid infinite insertion
12015
+ if (stop === false && startsWith(part, "</w:sectPr")) {
12016
+ result.push('<w:type w:val="continuous"/>');
12919
12017
  }
12920
12018
  }
12019
+ result.push(part);
12921
12020
  }
12922
- return parts;
12021
+ return result;
12923
12022
  }
12924
12023
  function dropHeaderFooterRefs(parts) {
12925
- var writeIndex = 0;
12926
- for(var readIndex = 0; readIndex < parts.length; readIndex++){
12927
- if (!startsWith(parts[readIndex], "<w:headerReference") && !startsWith(parts[readIndex], "<w:footerReference")) {
12928
- parts[writeIndex] = parts[readIndex];
12929
- writeIndex++;
12930
- }
12931
- }
12932
- parts.length = writeIndex;
12933
- return parts;
12024
+ return parts.filter(function(text) {
12025
+ return !startsWith(text, "<w:headerReference") && !startsWith(text, "<w:footerReference");
12026
+ });
12934
12027
  }
12935
12028
  function hasPageBreak(chunk) {
12936
- for(var _i10 = 0; _i10 < chunk.length; _i10++){
12937
- var part = chunk[_i10];
12938
- if (part.tag === "w:br" && part.value.indexOf('w:type="page"') !== -1) {
12939
- return true;
12940
- }
12941
- }
12942
- return false;
12029
+ return chunk.some(function(part) {
12030
+ return part.tag === "w:br" && part.value.indexOf('w:type="page"') !== -1;
12031
+ });
12943
12032
  }
12944
12033
  function hasImage(chunk) {
12945
- for(var _i12 = 0; _i12 < chunk.length; _i12++){
12946
- var el = chunk[_i12];
12947
- if (el.tag === "w:drawing") {
12948
- return true;
12949
- }
12950
- }
12951
- return false;
12034
+ return chunk.some(function(_ref2) {
12035
+ var tag = _ref2.tag;
12036
+ return tag === "w:drawing";
12037
+ });
12952
12038
  }
12953
12039
  function getSectPr(chunks) {
12040
+ var collectSectPr = false;
12954
12041
  var sectPrs = [];
12955
- var currentSectPr = null;
12956
- for(var _i14 = 0; _i14 < chunks.length; _i14++){
12957
- var part = chunks[_i14];
12042
+ for(var _i6 = 0; _i6 < chunks.length; _i6++){
12043
+ var part = chunks[_i6];
12958
12044
  if (isTagStart("w:sectPr", part)) {
12959
- currentSectPr = [];
12960
- sectPrs.push(currentSectPr);
12045
+ sectPrs.push([]);
12046
+ collectSectPr = true;
12961
12047
  }
12962
- if (currentSectPr !== null) {
12963
- currentSectPr.push(part);
12048
+ if (collectSectPr) {
12049
+ sectPrs[sectPrs.length - 1].push(part);
12964
12050
  }
12965
12051
  if (isTagEnd("w:sectPr", part)) {
12966
- currentSectPr = null;
12052
+ collectSectPr = false;
12967
12053
  }
12968
12054
  }
12969
12055
  return sectPrs;
@@ -12971,8 +12057,8 @@ function requireLoop () {
12971
12057
  function getSectPrHeaderFooterChangeCount(chunks) {
12972
12058
  var collectSectPr = false;
12973
12059
  var sectPrCount = 0;
12974
- for(var _i16 = 0; _i16 < chunks.length; _i16++){
12975
- var part = chunks[_i16];
12060
+ for(var _i8 = 0; _i8 < chunks.length; _i8++){
12061
+ var part = chunks[_i8];
12976
12062
  if (isTagStart("w:sectPr", part)) {
12977
12063
  collectSectPr = true;
12978
12064
  }
@@ -12993,11 +12079,7 @@ function requireLoop () {
12993
12079
  var inSectPr = false;
12994
12080
  for(var i = parsed.length - 1; i >= 0; i--){
12995
12081
  var part = parsed[i];
12996
- /*
12997
- * Since we try to get the last sectPr, we traverse the parsed array
12998
- * from the end to beginning, this is why inSectPr becomes true when we
12999
- * we see a </w:sectPr> closing tag
13000
- */ if (isTagEnd("w:sectPr", part)) {
12082
+ if (isTagEnd("w:sectPr", part)) {
13001
12083
  inSectPr = true;
13002
12084
  }
13003
12085
  if (isTagStart("w:sectPr", part)) {
@@ -13039,8 +12121,8 @@ function requireLoop () {
13039
12121
  },
13040
12122
  {
13041
12123
  key: "preparse",
13042
- value: function preparse(parsed, _ref) {
13043
- var contentType = _ref.contentType;
12124
+ value: function preparse(parsed, _ref3) {
12125
+ var contentType = _ref3.contentType;
13044
12126
  if (filetypes.main.indexOf(contentType) !== -1) {
13045
12127
  this.sects = getSectPr(parsed);
13046
12128
  }
@@ -13079,8 +12161,8 @@ function requireLoop () {
13079
12161
  [
13080
12162
  this.prefix.dash,
13081
12163
  _$module,
13082
- function(_ref2) {
13083
- var _ref3 = _slicedToArray(_ref2, 3), expandTo = _ref3[1], value = _ref3[2];
12164
+ function(_ref4) {
12165
+ var _ref5 = _slicedToArray(_ref4, 3), expandTo = _ref5[1], value = _ref5[2];
13084
12166
  return {
13085
12167
  location: "start",
13086
12168
  inverted: false,
@@ -13115,19 +12197,18 @@ function requireLoop () {
13115
12197
  },
13116
12198
  {
13117
12199
  key: "postparse",
13118
- value: function postparse(parsed, _ref4) {
13119
- var basePart = _ref4.basePart;
12200
+ value: function postparse(parsed, _ref6) {
12201
+ var basePart = _ref6.basePart;
13120
12202
  if (basePart && this.docxtemplater.fileType === "docx" && parsed.length > 0) {
13121
12203
  basePart.sectPrCount = getSectPrHeaderFooterChangeCount(parsed);
13122
12204
  this.totalSectPr += basePart.sectPrCount;
13123
12205
  var sects = this.sects;
13124
- for(var index = 0, len = sects.length; index < len; index++){
13125
- var sect = sects[index];
12206
+ sects.some(function(sect, index) {
13126
12207
  if (basePart.lIndex < sect[0].lIndex) {
13127
12208
  if (index + 1 < sects.length && isContinuous(sects[index + 1])) {
13128
12209
  basePart.addContinuousType = true;
13129
12210
  }
13130
- break;
12211
+ return true;
13131
12212
  }
13132
12213
  if (parsed[0].lIndex < sect[0].lIndex && sect[0].lIndex < basePart.lIndex) {
13133
12214
  if (isNextPage(sects[index])) {
@@ -13135,9 +12216,9 @@ function requireLoop () {
13135
12216
  index: index
13136
12217
  };
13137
12218
  }
13138
- break;
12219
+ return true;
13139
12220
  }
13140
- }
12221
+ });
13141
12222
  basePart.lastParagrapSectPr = getLastSectPr(parsed);
13142
12223
  }
13143
12224
  if (!basePart || basePart.expandTo !== "auto" || basePart.module !== moduleName || !isEnclosedByParagraphs(parsed)) {
@@ -13164,12 +12245,6 @@ function requireLoop () {
13164
12245
  var lastChunk = last(chunks);
13165
12246
  var firstOffset = getOffset(firstChunk);
13166
12247
  var lastOffset = getOffset(lastChunk);
13167
- if (firstOffset > 0 && chunks[1][0].type === "content" && isWhiteSpace(chunks[1][0].value)) {
13168
- firstOffset += 1;
13169
- }
13170
- if (lastOffset > 0 && last(chunks[chunks.length - 2]).type === "content" && isWhiteSpace(last(chunks[chunks.length - 2]).value)) {
13171
- lastOffset += 1;
13172
- }
13173
12248
  basePart.hasPageBreakBeginning = hasPageBreak(firstChunk);
13174
12249
  basePart.hasPageBreak = hasPageBreak(lastChunk);
13175
12250
  if (hasImage(firstChunk)) {
@@ -13184,7 +12259,6 @@ function requireLoop () {
13184
12259
  {
13185
12260
  key: "resolve",
13186
12261
  value: function resolve(part, options) {
13187
- var self = this;
13188
12262
  if (!isModule(part, moduleName)) {
13189
12263
  return null;
13190
12264
  }
@@ -13193,59 +12267,46 @@ function requireLoop () {
13193
12267
  part: part
13194
12268
  });
13195
12269
  var promises = [];
13196
- var lastPromise;
13197
- if (self.resolveSerially) {
13198
- lastPromise = Promise.resolve(null);
13199
- }
13200
12270
  function loopOver(scope, i, length) {
13201
12271
  var scopeManager = sm.createSubScopeManager(scope, part.value, i, part, length);
13202
- if (self.resolveSerially) {
13203
- lastPromise = lastPromise.then(function() {
13204
- return options.resolve(_objectSpread(_objectSpread({}, options), {}, {
13205
- compiled: part.subparsed,
13206
- tags: {},
13207
- scopeManager: scopeManager
13208
- }));
13209
- });
13210
- promises.push(lastPromise);
13211
- } else {
13212
- promises.push(options.resolve(_objectSpread(_objectSpread({}, options), {}, {
13213
- compiled: part.subparsed,
13214
- tags: {},
13215
- scopeManager: scopeManager
13216
- })));
13217
- }
12272
+ promises.push(options.resolve(_objectSpread(_objectSpread({}, options), {}, {
12273
+ compiled: part.subparsed,
12274
+ tags: {},
12275
+ scopeManager: scopeManager
12276
+ })));
13218
12277
  }
13219
12278
  var errorList = [];
13220
12279
  return promisedValue.then(function(values) {
13221
12280
  values !== null && values !== void 0 ? values : values = options.nullGetter(part);
13222
- if (_instanceof(values, Promise)) {
13223
- return values.then(function(values) {
13224
- if (_instanceof(values, Array)) {
13225
- return Promise.all(values);
13226
- }
13227
- return values;
13228
- });
13229
- }
13230
- if (_instanceof(values, Array)) {
13231
- return Promise.all(values);
13232
- }
13233
- return values;
13234
- }).then(function(values) {
13235
- sm.loopOverValue(values, loopOver, part.inverted);
13236
- return Promise.all(promises).then(function(r) {
13237
- var result = [];
13238
- for(var _i18 = 0; _i18 < r.length; _i18++){
13239
- var _r$_i = r[_i18], resolved = _r$_i.resolved, errors = _r$_i.errors;
13240
- pushArray(errorList, errors);
13241
- result.push(resolved);
12281
+ return new Promise(function(resolve) {
12282
+ if (_instanceof(values, Promise)) {
12283
+ return values.then(function(values) {
12284
+ if (_instanceof(values, Array)) {
12285
+ Promise.all(values).then(resolve);
12286
+ } else {
12287
+ resolve(values);
12288
+ }
12289
+ });
13242
12290
  }
13243
- return result;
13244
- }).then(function(value) {
13245
- if (errorList.length > 0) {
13246
- throw errorList;
12291
+ if (_instanceof(values, Array)) {
12292
+ Promise.all(values).then(resolve);
12293
+ } else {
12294
+ resolve(values);
13247
12295
  }
13248
- return value;
12296
+ }).then(function(values) {
12297
+ sm.loopOverValue(values, loopOver, part.inverted);
12298
+ return Promise.all(promises).then(function(r) {
12299
+ return r.map(function(_ref7) {
12300
+ var resolved = _ref7.resolved, errors = _ref7.errors;
12301
+ pushArray(errorList, errors);
12302
+ return resolved;
12303
+ });
12304
+ }).then(function(value) {
12305
+ if (errorList.length > 0) {
12306
+ throw errorList;
12307
+ }
12308
+ return value;
12309
+ });
13249
12310
  });
13250
12311
  });
13251
12312
  }
@@ -13253,12 +12314,11 @@ function requireLoop () {
13253
12314
  {
13254
12315
  key: "render",
13255
12316
  value: function render(part, options) {
13256
- var self = this;
13257
12317
  if (part.tag === "p:xfrm") {
13258
- self.inXfrm = part.position === "start";
12318
+ this.inXfrm = part.position === "start";
13259
12319
  }
13260
- if (part.tag === "a:ext" && self.inXfrm) {
13261
- self.lastExt = part;
12320
+ if (part.tag === "a:ext" && this.inXfrm) {
12321
+ this.lastExt = part;
13262
12322
  return part;
13263
12323
  }
13264
12324
  if (!isModule(part, moduleName)) {
@@ -13267,6 +12327,7 @@ function requireLoop () {
13267
12327
  var totalValue = [];
13268
12328
  var errors = [];
13269
12329
  var heightOffset = 0;
12330
+ var self = this;
13270
12331
  var firstTag = part.subparsed[0];
13271
12332
  var tagHeight = 0;
13272
12333
  if ((firstTag === null || firstTag === void 0 ? void 0 : firstTag.tag) === "a:tr") {
@@ -13278,8 +12339,8 @@ function requireLoop () {
13278
12339
  function loopOver(scope, i, length) {
13279
12340
  heightOffset += tagHeight;
13280
12341
  var scopeManager = options.scopeManager.createSubScopeManager(scope, part.value, i, part, length);
13281
- for(var _i20 = 0, _part$subparsed2 = part.subparsed; _i20 < _part$subparsed2.length; _i20++){
13282
- var pp = _part$subparsed2[_i20];
12342
+ for(var _i0 = 0, _part$subparsed2 = part.subparsed; _i0 < _part$subparsed2.length; _i0++){
12343
+ var pp = _part$subparsed2[_i0];
13283
12344
  if (isTagStart("a16:rowId", pp)) {
13284
12345
  var val = +getSingleAttribute(pp.value, "val") + a16RowIdOffset;
13285
12346
  a16RowIdOffset = 1;
@@ -13305,7 +12366,7 @@ function requireLoop () {
13305
12366
  subRendered.parts = addContinuousType(subRendered.parts);
13306
12367
  }
13307
12368
  } else if (part.addNextPage) {
13308
- addSectionBefore(subRendered.parts, self.sects[part.addNextPage.index]);
12369
+ subRendered.parts = addSectionBefore(subRendered.parts, self.sects[part.addNextPage.index]);
13309
12370
  }
13310
12371
  if (part.addNextPage) {
13311
12372
  addPageBreakAtEnd(subRendered);
@@ -13313,8 +12374,8 @@ function requireLoop () {
13313
12374
  if (part.hasPageBreakBeginning && insideParagraphLoop) {
13314
12375
  addPageBreakAtBeginning(subRendered);
13315
12376
  }
13316
- for(var _i22 = 0, _subRendered$parts2 = subRendered.parts; _i22 < _subRendered$parts2.length; _i22++){
13317
- var _val = _subRendered$parts2[_i22];
12377
+ for(var _i10 = 0, _subRendered$parts2 = subRendered.parts; _i10 < _subRendered$parts2.length; _i10++){
12378
+ var _val = _subRendered$parts2[_i10];
13318
12379
  totalValue.push(_val);
13319
12380
  }
13320
12381
  pushArray(errors, subRendered.errors);
@@ -13342,11 +12403,11 @@ function requireLoop () {
13342
12403
  };
13343
12404
  }
13344
12405
  if (heightOffset !== 0) {
13345
- var cy = +getSingleAttribute(self.lastExt.value, "cy");
12406
+ var cy = +getSingleAttribute(this.lastExt.value, "cy");
13346
12407
  /*
13347
12408
  * We do edit the value of a previous result here
13348
12409
  * #edit-value-backwards
13349
- */ self.lastExt.value = setSingleAttribute(self.lastExt.value, "cy", cy + heightOffset);
12410
+ */ this.lastExt.value = setSingleAttribute(this.lastExt.value, "cy", cy + heightOffset);
13350
12411
  }
13351
12412
  return {
13352
12413
  value: options.joinUncorrupt(totalValue, _objectSpread(_objectSpread({}, options), {}, {
@@ -13562,7 +12623,7 @@ function requireRawxml () {
13562
12623
  return (String )(t);
13563
12624
  }
13564
12625
  var traits = requireTraits();
13565
- var _require = docUtils, isContent = _require.isContent, getPartWithDelimiters = _require.getPartWithDelimiters;
12626
+ var _require = docUtils, isContent = _require.isContent;
13566
12627
  var _require2 = requireErrors(), throwRawTagShouldBeOnlyTextInParagraph = _require2.throwRawTagShouldBeOnlyTextInParagraph, getInvalidRawXMLValueException = _require2.getInvalidRawXMLValueException;
13567
12628
  var wrapper = requireModuleWrapper();
13568
12629
  var moduleName = "rawxml";
@@ -13611,7 +12672,6 @@ function requireRawxml () {
13611
12672
  {
13612
12673
  key: "postparse",
13613
12674
  value: function postparse(postparsed) {
13614
- var _this = this;
13615
12675
  return traits.expandToOne(postparsed, {
13616
12676
  moduleName: moduleName,
13617
12677
  getInner: getInner,
@@ -13620,7 +12680,7 @@ function requireRawxml () {
13620
12680
  message: "Raw tag not in paragraph",
13621
12681
  id: "raw_tag_outerxml_invalid",
13622
12682
  explanation: function explanation(part) {
13623
- return "The tag \"".concat(getPartWithDelimiters(part, _this.docxtemplater), "\" is not inside a paragraph, putting raw tags inside an inline loop is disallowed.");
12683
+ return "The tag \"".concat(part.value, "\" is not inside a paragraph, putting raw tags inside an inline loop is disallowed.");
13624
12684
  }
13625
12685
  }
13626
12686
  });
@@ -13656,8 +12716,6 @@ function requireRawxml () {
13656
12716
  getInvalidRawXMLValueException({
13657
12717
  tag: part.value,
13658
12718
  value: value,
13659
- partDelims: getPartWithDelimiters(part, this.docxtemplater),
13660
- part: part,
13661
12719
  offset: part.offset
13662
12720
  })
13663
12721
  ]
@@ -13910,10 +12968,10 @@ function requireExpandPairTrait () {
13910
12968
  },
13911
12969
  {
13912
12970
  key: "postparse",
13913
- value: function postparse(postparsed, options) {
12971
+ value: function postparse(postparsed, _ref) {
13914
12972
  var _this = this;
13915
- var getTraits = options.getTraits, postparse = options.postparse, fileType = options.fileType;
13916
- var traits = getTraits(traitName, postparsed, options);
12973
+ var getTraits = _ref.getTraits, _postparse = _ref.postparse, fileType = _ref.fileType;
12974
+ var traits = getTraits(traitName, postparsed);
13917
12975
  traits = traits.map(function(trait) {
13918
12976
  return trait || [];
13919
12977
  });
@@ -13994,7 +13052,7 @@ function requireExpandPairTrait () {
13994
13052
  if (expandedPair[1] === i) {
13995
13053
  // End pair
13996
13054
  var basePart = postparsed[pair[0].offset];
13997
- basePart.subparsed = postparse(innerParts, {
13055
+ basePart.subparsed = _postparse(innerParts, {
13998
13056
  basePart: basePart
13999
13057
  });
14000
13058
  basePart.endLindex = pair[1].part.lIndex;
@@ -14100,6 +13158,17 @@ function requireRender () {
14100
13158
  this.recordedRun = [];
14101
13159
  }
14102
13160
  return _createClass(Render, [
13161
+ {
13162
+ key: "optionsTransformer",
13163
+ value: function optionsTransformer(options, docxtemplater) {
13164
+ this.docxtemplater = docxtemplater;
13165
+ this.brTag = docxtemplater.fileType === "docx" ? "<w:r><w:br/></w:r>" : "<a:br/>";
13166
+ this.prefix = ftprefix[docxtemplater.fileType];
13167
+ this.runStartTag = "".concat(this.prefix, ":r");
13168
+ this.runPropsStartTag = "".concat(this.prefix, ":rPr");
13169
+ return options;
13170
+ }
13171
+ },
14103
13172
  {
14104
13173
  key: "set",
14105
13174
  value: function set(obj) {
@@ -14112,14 +13181,15 @@ function requireRender () {
14112
13181
  }
14113
13182
  },
14114
13183
  {
14115
- key: "optionsTransformer",
14116
- value: function optionsTransformer(options, docxtemplater) {
14117
- this.docxtemplater = docxtemplater;
14118
- this.brTag = docxtemplater.fileType === "docx" ? "<w:r><w:br/></w:r>" : "<a:br/>";
14119
- this.prefix = ftprefix[docxtemplater.fileType];
14120
- this.runStartTag = "".concat(this.prefix, ":r");
14121
- this.runPropsStartTag = "".concat(this.prefix, ":rPr");
14122
- return options;
13184
+ key: "getRenderedMap",
13185
+ value: function getRenderedMap(mapper) {
13186
+ for(var from in this.compiled){
13187
+ mapper[from] = {
13188
+ from: from,
13189
+ data: this.data
13190
+ };
13191
+ }
13192
+ return mapper;
14123
13193
  }
14124
13194
  },
14125
13195
  {
@@ -14149,18 +13219,6 @@ function requireRender () {
14149
13219
  };
14150
13220
  }
14151
13221
  },
14152
- {
14153
- key: "getRenderedMap",
14154
- value: function getRenderedMap(mapper) {
14155
- for(var from in this.compiled){
14156
- mapper[from] = {
14157
- from: from,
14158
- data: this.data
14159
- };
14160
- }
14161
- return mapper;
14162
- }
14163
- },
14164
13222
  {
14165
13223
  key: "render",
14166
13224
  value: function render(part, _ref) {
@@ -14274,9 +13332,6 @@ function requireFileTypeConfig () {
14274
13332
  getTemplatedFiles: function getTemplatedFiles() {
14275
13333
  return [];
14276
13334
  },
14277
- templatedNs: [
14278
- "http://schemas.microsoft.com/office/2006/coverPageProps"
14279
- ],
14280
13335
  textPath: function textPath(doc) {
14281
13336
  return doc.textTarget;
14282
13337
  },
@@ -14291,12 +13346,6 @@ function requireFileTypeConfig () {
14291
13346
  "dc:subject",
14292
13347
  "dc:title",
14293
13348
  "cp:contentStatus",
14294
- "PublishDate",
14295
- "Abstract",
14296
- "CompanyAddress",
14297
- "CompanyPhone",
14298
- "CompanyFax",
14299
- "CompanyEmail",
14300
13349
  "w:t",
14301
13350
  "a:t",
14302
13351
  "m:t",
@@ -14650,8 +13699,7 @@ function requireFileTypeConfig () {
14650
13699
  linebreaks: z["boolean"]().optional(),
14651
13700
  nullGetter: z["function"]().optional(),
14652
13701
  syntax: dxtSyntaxSchema.optional(),
14653
- stripInvalidXMLChars: z["boolean"]().optional(),
14654
- warnFn: z["function"]().optional()
13702
+ stripInvalidXMLChars: z["boolean"]().optional()
14655
13703
  }).strict();
14656
13704
  var _require = requireGetRelationTypes(), getRelsTypes = _require.getRelsTypes;
14657
13705
  var _require2 = requireGetContentTypes(), collectContentTypes = _require2.collectContentTypes, getContentTypes = _require2.getContentTypes;
@@ -14677,24 +13725,22 @@ function requireFileTypeConfig () {
14677
13725
  2
14678
13726
  ];
14679
13727
  function throwIfDuplicateModules(modules) {
14680
- var names = [];
14681
- for(var _i2 = 0; _i2 < modules.length; _i2++){
14682
- var mod = modules[_i2];
14683
- names.push(mod.name);
14684
- }
14685
- var duplicates = getDuplicates(names);
13728
+ var duplicates = getDuplicates(modules.map(function(_ref) {
13729
+ var name = _ref.name;
13730
+ return name;
13731
+ }));
14686
13732
  if (duplicates.length > 0) {
14687
13733
  throw new XTInternalError("Detected duplicate module \"".concat(duplicates[0], "\""));
14688
13734
  }
14689
13735
  }
14690
13736
  function addXmlFileNamesFromXmlContentType(doc) {
14691
- for(var _i4 = 0, _doc$modules2 = doc.modules; _i4 < _doc$modules2.length; _i4++){
14692
- var _module = _doc$modules2[_i4];
14693
- for(var _i6 = 0, _ref2 = _module.xmlContentTypes || []; _i6 < _ref2.length; _i6++){
14694
- var contentType = _ref2[_i6];
13737
+ for(var _i2 = 0, _doc$modules2 = doc.modules; _i2 < _doc$modules2.length; _i2++){
13738
+ var _module = _doc$modules2[_i2];
13739
+ for(var _i4 = 0, _ref3 = _module.xmlContentTypes || []; _i4 < _ref3.length; _i4++){
13740
+ var contentType = _ref3[_i4];
14695
13741
  var candidates = doc.invertedContentTypes[contentType] || [];
14696
- for(var _i8 = 0; _i8 < candidates.length; _i8++){
14697
- var candidate = candidates[_i8];
13742
+ for(var _i6 = 0; _i6 < candidates.length; _i6++){
13743
+ var candidate = candidates[_i6];
14698
13744
  if (doc.zip.files[candidate]) {
14699
13745
  doc.options.xmlFileNames.push(candidate);
14700
13746
  }
@@ -14747,10 +13793,10 @@ function requireFileTypeConfig () {
14747
13793
  "xl/",
14748
13794
  "ppt/"
14749
13795
  ];
14750
- for(var _i0 = 0; _i0 < allFiles.length; _i0++){
14751
- var _name = allFiles[_i0];
14752
- for(var _i10 = 0; _i10 < prefixes.length; _i10++){
14753
- var prefix = prefixes[_i10];
13796
+ for(var _i8 = 0; _i8 < allFiles.length; _i8++){
13797
+ var _name = allFiles[_i8];
13798
+ for(var _i0 = 0; _i0 < prefixes.length; _i0++){
13799
+ var prefix = prefixes[_i0];
14754
13800
  if (_name.indexOf("".concat(prefix)) === 0) {
14755
13801
  resultFiles.push(_name);
14756
13802
  }
@@ -14758,8 +13804,8 @@ function requireFileTypeConfig () {
14758
13804
  }
14759
13805
  /*
14760
13806
  * Push the rest of files, such as docProps/core.xml and docProps/app.xml
14761
- */ for(var _i12 = 0; _i12 < allFiles.length; _i12++){
14762
- var _name2 = allFiles[_i12];
13807
+ */ for(var _i10 = 0; _i10 < allFiles.length; _i10++){
13808
+ var _name2 = allFiles[_i10];
14763
13809
  if (resultFiles.indexOf(_name2) === -1) {
14764
13810
  resultFiles.push(_name2);
14765
13811
  }
@@ -14811,7 +13857,7 @@ function requireFileTypeConfig () {
14811
13857
  }
14812
13858
  var Docxtemplater = /*#__PURE__*/ function() {
14813
13859
  function Docxtemplater(zip) {
14814
- var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref3$modules = _ref3.modules, modules = _ref3$modules === void 0 ? [] : _ref3$modules, options = _objectWithoutProperties(_ref3, _excluded);
13860
+ var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref4$modules = _ref4.modules, modules = _ref4$modules === void 0 ? [] : _ref4$modules, options = _objectWithoutProperties(_ref4, _excluded);
14815
13861
  _classCallCheck(this, Docxtemplater);
14816
13862
  this.targets = [];
14817
13863
  this.rendered = false;
@@ -14837,8 +13883,8 @@ function requireFileTypeConfig () {
14837
13883
  if (!Array.isArray(modules)) {
14838
13884
  throw new Error("The modules argument of docxtemplater's constructor must be an array");
14839
13885
  }
14840
- for(var _i14 = 0; _i14 < modules.length; _i14++){
14841
- var _module2 = modules[_i14];
13886
+ for(var _i12 = 0; _i12 < modules.length; _i12++){
13887
+ var _module2 = modules[_i12];
14842
13888
  this.attachModule(_module2);
14843
13889
  }
14844
13890
  this.loadZip(zip);
@@ -14851,10 +13897,9 @@ function requireFileTypeConfig () {
14851
13897
  {
14852
13898
  key: "verifyApiVersion",
14853
13899
  value: function verifyApiVersion(neededVersion) {
14854
- neededVersion = neededVersion.split(".");
14855
- for(var i = 0; i < neededVersion.length; i++){
14856
- neededVersion[i] = parseInt(neededVersion[i], 10);
14857
- }
13900
+ neededVersion = neededVersion.split(".").map(function(i) {
13901
+ return parseInt(i, 10);
13902
+ });
14858
13903
  if (neededVersion.length !== 3) {
14859
13904
  throwApiVersionError("neededVersion is not a valid version", {
14860
13905
  neededVersion: neededVersion,
@@ -14888,8 +13933,8 @@ function requireFileTypeConfig () {
14888
13933
  {
14889
13934
  key: "setModules",
14890
13935
  value: function setModules(obj) {
14891
- for(var _i16 = 0, _this$modules2 = this.modules; _i16 < _this$modules2.length; _i16++){
14892
- var _module3 = _this$modules2[_i16];
13936
+ for(var _i14 = 0, _this$modules2 = this.modules; _i14 < _this$modules2.length; _i14++){
13937
+ var _module3 = _this$modules2[_i14];
14893
13938
  _module3.set(obj);
14894
13939
  }
14895
13940
  }
@@ -14897,8 +13942,8 @@ function requireFileTypeConfig () {
14897
13942
  {
14898
13943
  key: "sendEvent",
14899
13944
  value: function sendEvent(eventName) {
14900
- for(var _i18 = 0, _this$modules4 = this.modules; _i18 < _this$modules4.length; _i18++){
14901
- var _module4 = _this$modules4[_i18];
13945
+ for(var _i16 = 0, _this$modules4 = this.modules; _i16 < _this$modules4.length; _i16++){
13946
+ var _module4 = _this$modules4[_i16];
14902
13947
  _module4.on(eventName);
14903
13948
  }
14904
13949
  }
@@ -14940,8 +13985,8 @@ function requireFileTypeConfig () {
14940
13985
  {
14941
13986
  key: "findModule",
14942
13987
  value: function findModule(name) {
14943
- for(var _i20 = 0, _this$modules6 = this.modules; _i20 < _this$modules6.length; _i20++){
14944
- var _module5 = _this$modules6[_i20];
13988
+ for(var _i18 = 0, _this$modules6 = this.modules; _i18 < _this$modules6.length; _i18++){
13989
+ var _module5 = _this$modules6[_i18];
14945
13990
  if (_module5.name === name) {
14946
13991
  return _module5;
14947
13992
  }
@@ -14985,11 +14030,6 @@ function requireFileTypeConfig () {
14985
14030
  if (zip.loadAsync) {
14986
14031
  throw new XTInternalError("Docxtemplater doesn't handle JSZip version >=3, please use pizzip");
14987
14032
  }
14988
- if (zip.xtRendered) {
14989
- this.options.warnFn([
14990
- new Error("This zip file appears to be the outcome of a previous docxtemplater generation. This typically indicates that docxtemplater was integrated by reusing the same zip file. It is recommended to create a new Pizzip instance for each docxtemplater generation.")
14991
- ]);
14992
- }
14993
14033
  this.zip = zip;
14994
14034
  this.updateFileTypeConfig();
14995
14035
  this.modules = concatArrays([
@@ -14998,8 +14038,8 @@ function requireFileTypeConfig () {
14998
14038
  }),
14999
14039
  this.modules
15000
14040
  ]);
15001
- for(var _i22 = 0, _this$modules8 = this.modules; _i22 < _this$modules8.length; _i22++){
15002
- var _module6 = _this$modules8[_i22];
14041
+ for(var _i20 = 0, _this$modules8 = this.modules; _i20 < _this$modules8.length; _i20++){
14042
+ var _module6 = _this$modules8[_i20];
15003
14043
  _module6.zip = this.zip;
15004
14044
  _module6.docxtemplater = this;
15005
14045
  _module6.fileTypeConfig = this.fileTypeConfig;
@@ -15055,11 +14095,9 @@ function requireFileTypeConfig () {
15055
14095
  _this.mapper = _this.modules.reduce(function(value, module1) {
15056
14096
  return module1.getRenderedMap(value);
15057
14097
  }, {});
15058
- var promises = [];
15059
- var _loop = function _loop() {
15060
- var to = _Object$keys2[_i24];
14098
+ return Promise.all(Object.keys(_this.mapper).map(function(to) {
15061
14099
  var _this$mapper$to = _this.mapper[to], from = _this$mapper$to.from, _$data = _this$mapper$to.data;
15062
- promises.push(Promise.resolve(_$data).then(function(data) {
14100
+ return Promise.resolve(_$data).then(function(data) {
15063
14101
  var currentFile = _this.compiled[from];
15064
14102
  currentFile.filePath = to;
15065
14103
  currentFile.scopeManager = _this.getScopeManager(to, currentFile, data);
@@ -15069,12 +14107,8 @@ function requireFileTypeConfig () {
15069
14107
  }, function(errs) {
15070
14108
  pushArray(errors, errs);
15071
14109
  });
15072
- }));
15073
- };
15074
- for(var _i24 = 0, _Object$keys2 = Object.keys(_this.mapper); _i24 < _Object$keys2.length; _i24++){
15075
- _loop();
15076
- }
15077
- return Promise.all(promises).then(function(resolved) {
14110
+ });
14111
+ })).then(function(resolved) {
15078
14112
  if (errors.length !== 0) {
15079
14113
  if (_this.options.errorLogging) {
15080
14114
  logErrors(errors, _this.options.errorLogging);
@@ -15097,14 +14131,14 @@ function requireFileTypeConfig () {
15097
14131
  return this;
15098
14132
  }
15099
14133
  var options = this.options;
15100
- for(var _i26 = 0, _this$modules0 = this.modules; _i26 < _this$modules0.length; _i26++){
15101
- var _module7 = _this$modules0[_i26];
14134
+ for(var _i22 = 0, _this$modules0 = this.modules; _i22 < _this$modules0.length; _i22++){
14135
+ var _module7 = _this$modules0[_i22];
15102
14136
  options = _module7.optionsTransformer(options, this);
15103
14137
  }
15104
14138
  this.options = options;
15105
14139
  this.options.xmlFileNames = uniq(this.options.xmlFileNames);
15106
- for(var _i28 = 0, _this$options$xmlFile2 = this.options.xmlFileNames; _i28 < _this$options$xmlFile2.length; _i28++){
15107
- var fileName = _this$options$xmlFile2[_i28];
14140
+ for(var _i24 = 0, _this$options$xmlFile2 = this.options.xmlFileNames; _i24 < _this$options$xmlFile2.length; _i24++){
14141
+ var fileName = _this$options$xmlFile2[_i24];
15108
14142
  var content = this.zip.files[fileName].asText();
15109
14143
  this.xmlDocuments[fileName] = str2xml(content);
15110
14144
  }
@@ -15112,8 +14146,8 @@ function requireFileTypeConfig () {
15112
14146
  zip: this.zip,
15113
14147
  xmlDocuments: this.xmlDocuments
15114
14148
  });
15115
- for(var _i30 = 0, _this$modules10 = this.modules; _i30 < _this$modules10.length; _i30++){
15116
- var _module8 = _this$modules10[_i30];
14149
+ for(var _i26 = 0, _this$modules10 = this.modules; _i26 < _this$modules10.length; _i26++){
14150
+ var _module8 = _this$modules10[_i26];
15117
14151
  _module8.xmlDocuments = this.xmlDocuments;
15118
14152
  }
15119
14153
  this.getTemplatedFiles();
@@ -15121,15 +14155,15 @@ function requireFileTypeConfig () {
15121
14155
  * Loop inside all templatedFiles (ie xml files with content).
15122
14156
  * Sometimes they don't exist (footer.xml for example)
15123
14157
  */ this.sendEvent("before-preparse");
15124
- for(var _i32 = 0, _this$templatedFiles2 = this.templatedFiles; _i32 < _this$templatedFiles2.length; _i32++){
15125
- var _fileName = _this$templatedFiles2[_i32];
14158
+ for(var _i28 = 0, _this$templatedFiles2 = this.templatedFiles; _i28 < _this$templatedFiles2.length; _i28++){
14159
+ var _fileName = _this$templatedFiles2[_i28];
15126
14160
  if (this.zip.files[_fileName] != null) {
15127
14161
  this.precompileFile(_fileName);
15128
14162
  }
15129
14163
  }
15130
14164
  this.sendEvent("after-preparse");
15131
- for(var _i34 = 0, _this$templatedFiles4 = this.templatedFiles; _i34 < _this$templatedFiles4.length; _i34++){
15132
- var _fileName2 = _this$templatedFiles4[_i34];
14165
+ for(var _i30 = 0, _this$templatedFiles4 = this.templatedFiles; _i30 < _this$templatedFiles4.length; _i30++){
14166
+ var _fileName2 = _this$templatedFiles4[_i30];
15133
14167
  if (this.zip.files[_fileName2] != null) {
15134
14168
  this.compiled[_fileName2].parse({
15135
14169
  noPostParse: true
@@ -15137,8 +14171,8 @@ function requireFileTypeConfig () {
15137
14171
  }
15138
14172
  }
15139
14173
  this.sendEvent("after-parse");
15140
- for(var _i36 = 0, _this$templatedFiles6 = this.templatedFiles; _i36 < _this$templatedFiles6.length; _i36++){
15141
- var _fileName3 = _this$templatedFiles6[_i36];
14174
+ for(var _i32 = 0, _this$templatedFiles6 = this.templatedFiles; _i32 < _this$templatedFiles6.length; _i32++){
14175
+ var _fileName3 = _this$templatedFiles6[_i32];
15142
14176
  if (this.zip.files[_fileName3] != null) {
15143
14177
  this.compiled[_fileName3].postparse();
15144
14178
  }
@@ -15168,8 +14202,8 @@ function requireFileTypeConfig () {
15168
14202
  if (this.zip.files.mimetype) {
15169
14203
  fileType = "odt";
15170
14204
  }
15171
- for(var _i38 = 0, _this$modules12 = this.modules; _i38 < _this$modules12.length; _i38++){
15172
- var _module9 = _this$modules12[_i38];
14205
+ for(var _i34 = 0, _this$modules12 = this.modules; _i34 < _this$modules12.length; _i34++){
14206
+ var _module9 = _this$modules12[_i34];
15173
14207
  fileType = _module9.getFileType({
15174
14208
  zip: this.zip,
15175
14209
  contentTypes: contentTypes,
@@ -15220,7 +14254,6 @@ function requireFileTypeConfig () {
15220
14254
  this.hideDeprecations = true;
15221
14255
  var promise = this.resolveData(data);
15222
14256
  this.hideDeprecations = false;
15223
- this.zip.xtRendered = true;
15224
14257
  return promise.then(function() {
15225
14258
  return _this2.render();
15226
14259
  });
@@ -15229,7 +14262,6 @@ function requireFileTypeConfig () {
15229
14262
  {
15230
14263
  key: "render",
15231
14264
  value: function render(data) {
15232
- this.zip.xtRendered = true;
15233
14265
  if (this.rendered) {
15234
14266
  throwRenderTwice();
15235
14267
  }
@@ -15263,11 +14295,11 @@ function requireFileTypeConfig () {
15263
14295
  ]);
15264
14296
  delete currentFile.content;
15265
14297
  }
15266
- for(var _i40 = 0; _i40 < output.length; _i40++){
15267
- var outputPart = output[_i40];
14298
+ for(var _i36 = 0; _i36 < output.length; _i36++){
14299
+ var outputPart = output[_i36];
15268
14300
  var _outputPart = _slicedToArray(outputPart, 3), content = _outputPart[1], _currentFile = _outputPart[2];
15269
- for(var _i42 = 0, _this$modules14 = this.modules; _i42 < _this$modules14.length; _i42++){
15270
- var _module0 = _this$modules14[_i42];
14301
+ for(var _i38 = 0, _this$modules14 = this.modules; _i38 < _this$modules14.length; _i38++){
14302
+ var _module0 = _this$modules14[_i38];
15271
14303
  if (_module0.preZip) {
15272
14304
  var result = _module0.preZip(content, _currentFile);
15273
14305
  if (typeof result === "string") {
@@ -15276,8 +14308,8 @@ function requireFileTypeConfig () {
15276
14308
  }
15277
14309
  }
15278
14310
  }
15279
- for(var _i44 = 0; _i44 < output.length; _i44++){
15280
- var _output$_i = _slicedToArray(output[_i44], 2), _to = _output$_i[0], _content = _output$_i[1];
14311
+ for(var _i40 = 0; _i40 < output.length; _i40++){
14312
+ var _output$_i = _slicedToArray(output[_i40], 2), _to = _output$_i[0], _content = _output$_i[1];
15281
14313
  this.zip.file(_to, _content, {
15282
14314
  createFolders: true
15283
14315
  });
@@ -15338,8 +14370,8 @@ function requireFileTypeConfig () {
15338
14370
  "fileType",
15339
14371
  "modules"
15340
14372
  ]);
15341
- for(var _i46 = 0; _i46 < defaultKeys.length; _i46++){
15342
- var key = defaultKeys[_i46];
14373
+ for(var _i42 = 0; _i42 < defaultKeys.length; _i42++){
14374
+ var key = defaultKeys[_i42];
15343
14375
  xmltOptions[key] = this[key];
15344
14376
  }
15345
14377
  return new Docxtemplater.XmlTemplater(content, xmltOptions);
@@ -15356,20 +14388,6 @@ function requireFileTypeConfig () {
15356
14388
  value: function getTemplatedFiles() {
15357
14389
  this.templatedFiles = this.fileTypeConfig.getTemplatedFiles(this.zip);
15358
14390
  pushArray(this.templatedFiles, this.targets);
15359
- var templatedNs = this.fileTypeConfig.templatedNs || [];
15360
- if (templatedNs.length > 0) {
15361
- for(var key in this.filesContentTypes){
15362
- if (/^customXml\/item\d+\.xml$/.test(key)) {
15363
- for(var _i48 = 0; _i48 < templatedNs.length; _i48++){
15364
- var ns = templatedNs[_i48];
15365
- var text = this.zip.file(key).asText();
15366
- if (text.indexOf("xmlns=\"".concat(ns, "\"")) !== -1) {
15367
- this.templatedFiles.push(key);
15368
- }
15369
- }
15370
- }
15371
- }
15372
- }
15373
14391
  this.templatedFiles = uniq(this.templatedFiles);
15374
14392
  return this.templatedFiles;
15375
14393
  }