html-react-parser 1.4.12 → 2.0.0

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.
@@ -10,9 +10,9 @@
10
10
 
11
11
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
12
12
 
13
- var htmlReactParser$1 = {exports: {}};
13
+ var htmlReactParser = {exports: {}};
14
14
 
15
- var lib$1 = {};
15
+ var lib$2 = {};
16
16
 
17
17
  var possibleStandardNamesOptimized$1 = {};
18
18
 
@@ -510,7 +510,7 @@
510
510
  zoomAndPan: 1
511
511
  };
512
512
 
513
- Object.defineProperty(lib$1, '__esModule', { value: true });
513
+ Object.defineProperty(lib$2, '__esModule', { value: true });
514
514
 
515
515
  function _slicedToArray(arr, i) {
516
516
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
@@ -815,16 +815,16 @@
815
815
  return accumulator;
816
816
  }, {});
817
817
 
818
- lib$1.BOOLEAN = BOOLEAN;
819
- lib$1.BOOLEANISH_STRING = BOOLEANISH_STRING;
820
- lib$1.NUMERIC = NUMERIC;
821
- lib$1.OVERLOADED_BOOLEAN = OVERLOADED_BOOLEAN;
822
- lib$1.POSITIVE_NUMERIC = POSITIVE_NUMERIC;
823
- lib$1.RESERVED = RESERVED;
824
- lib$1.STRING = STRING;
825
- lib$1.getPropertyInfo = getPropertyInfo;
826
- lib$1.isCustomAttribute = isCustomAttribute;
827
- lib$1.possibleStandardNames = possibleStandardNames;
818
+ lib$2.BOOLEAN = BOOLEAN;
819
+ lib$2.BOOLEANISH_STRING = BOOLEANISH_STRING;
820
+ lib$2.NUMERIC = NUMERIC;
821
+ lib$2.OVERLOADED_BOOLEAN = OVERLOADED_BOOLEAN;
822
+ lib$2.POSITIVE_NUMERIC = POSITIVE_NUMERIC;
823
+ lib$2.RESERVED = RESERVED;
824
+ lib$2.STRING = STRING;
825
+ lib$2.getPropertyInfo = getPropertyInfo;
826
+ lib$2.isCustomAttribute = isCustomAttribute;
827
+ lib$2.possibleStandardNames = possibleStandardNames;
828
828
 
829
829
  var cjs = {};
830
830
 
@@ -1137,6 +1137,7 @@
1137
1137
  var HYPHEN_REGEX = /-([a-z])/g;
1138
1138
  var NO_HYPHEN_REGEX = /^[^-]+$/;
1139
1139
  var VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
1140
+ var MS_VENDOR_PREFIX_REGEX = /^-(ms)-/;
1140
1141
  var skipCamelCase = function (property) {
1141
1142
  return !property ||
1142
1143
  NO_HYPHEN_REGEX.test(property) ||
@@ -1145,14 +1146,17 @@
1145
1146
  var capitalize = function (match, character) {
1146
1147
  return character.toUpperCase();
1147
1148
  };
1148
- var trimHyphen = function (match, prefix) { return prefix + "-"; };
1149
+ var trimHyphen = function (match, prefix) { return "".concat(prefix, "-"); };
1149
1150
  var camelCase = function (property, options) {
1150
1151
  if (options === void 0) { options = {}; }
1151
1152
  if (skipCamelCase(property)) {
1152
1153
  return property;
1153
1154
  }
1154
1155
  property = property.toLowerCase();
1155
- if (!options.reactCompat) {
1156
+ if (options.reactCompat) {
1157
+ property = property.replace(MS_VENDOR_PREFIX_REGEX, trimHyphen);
1158
+ }
1159
+ else {
1156
1160
  property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
1157
1161
  }
1158
1162
  return property.replace(HYPHEN_REGEX, capitalize);
@@ -1160,26 +1164,26 @@
1160
1164
  utilities$4.camelCase = camelCase;
1161
1165
 
1162
1166
  (function (exports) {
1163
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1164
- return (mod && mod.__esModule) ? mod : { "default": mod };
1165
- };
1166
- exports.__esModule = true;
1167
- var style_to_object_1 = __importDefault(styleToObject);
1168
- var utilities_1 = utilities$4;
1169
- function StyleToJS(style, options) {
1170
- var output = {};
1171
- if (!style || typeof style !== 'string') {
1172
- return output;
1173
- }
1174
- style_to_object_1["default"](style, function (property, value) {
1175
- if (property && value) {
1176
- output[utilities_1.camelCase(property, options)] = value;
1177
- }
1178
- });
1179
- return output;
1180
- }
1181
- exports["default"] = StyleToJS;
1182
- }(cjs));
1167
+ var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
1168
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1169
+ };
1170
+ exports.__esModule = true;
1171
+ var style_to_object_1 = __importDefault(styleToObject);
1172
+ var utilities_1 = utilities$4;
1173
+ function StyleToJS(style, options) {
1174
+ var output = {};
1175
+ if (!style || typeof style !== 'string') {
1176
+ return output;
1177
+ }
1178
+ (0, style_to_object_1["default"])(style, function (property, value) {
1179
+ if (property && value) {
1180
+ output[(0, utilities_1.camelCase)(property, options)] = value;
1181
+ }
1182
+ });
1183
+ return output;
1184
+ }
1185
+ exports["default"] = StyleToJS;
1186
+ } (cjs));
1183
1187
 
1184
1188
  var React$1 = require$$0__default["default"];
1185
1189
  var styleToJS = cjs.default;
@@ -1187,9 +1191,9 @@
1187
1191
  /**
1188
1192
  * Swap key with value in an object.
1189
1193
  *
1190
- * @param {Object} obj - The object.
1191
- * @param {Function} [override] - The override method.
1192
- * @return {Object} - The inverted object.
1194
+ * @param {object} obj - The object.
1195
+ * @param {Function} [override] - The override method.
1196
+ * @returns - The inverted object.
1193
1197
  */
1194
1198
  function invertObject(obj, override) {
1195
1199
  if (!obj || typeof obj !== 'object') {
@@ -1227,8 +1231,8 @@
1227
1231
  * @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
1228
1232
  *
1229
1233
  * @param {string} tagName - The name of the html tag.
1230
- * @param {Object} props - The props being passed to the element.
1231
- * @return {boolean}
1234
+ * @param {object} props - The props being passed to the element.
1235
+ * @returns - Whether tag is custom component.
1232
1236
  */
1233
1237
  function isCustomComponent(tagName, props) {
1234
1238
  if (tagName.indexOf('-') === -1) {
@@ -1296,8 +1300,8 @@
1296
1300
  /**
1297
1301
  * Checks if the given node can contain text nodes
1298
1302
  *
1299
- * @param {DomElement} node
1300
- * @returns {boolean}
1303
+ * @param {DomElement} node - Node.
1304
+ * @returns - Whether node can contain text nodes.
1301
1305
  */
1302
1306
  function canTextBeChildOfNode$1(node) {
1303
1307
  return !elementsWithNoTextChildren.has(node.name);
@@ -1312,14 +1316,14 @@
1312
1316
  elementsWithNoTextChildren: elementsWithNoTextChildren
1313
1317
  };
1314
1318
 
1315
- var reactProperty = lib$1;
1319
+ var reactProperty = lib$2;
1316
1320
  var utilities$2 = utilities$3;
1317
1321
 
1318
1322
  /**
1319
1323
  * Converts HTML/SVG DOM attributes to React props.
1320
1324
  *
1321
- * @param {object} [attributes={}] - HTML/SVG DOM attributes.
1322
- * @return {object} - React props.
1325
+ * @param {object} [attributes={}] - HTML/SVG DOM attributes.
1326
+ * @returns - React props.
1323
1327
  */
1324
1328
  var attributesToProps$2 = function attributesToProps(attributes) {
1325
1329
  attributes = attributes || {};
@@ -1393,7 +1397,7 @@
1393
1397
  * Gets prop name from lowercased attribute name.
1394
1398
  *
1395
1399
  * @param {string} attributeName - Lowercased attribute name.
1396
- * @return {string}
1400
+ * @returns - Prop name.
1397
1401
  */
1398
1402
  function getPropName(attributeName) {
1399
1403
  return reactProperty.possibleStandardNames[attributeName];
@@ -1409,11 +1413,11 @@
1409
1413
  /**
1410
1414
  * Converts DOM nodes to JSX element(s).
1411
1415
  *
1412
- * @param {DomElement[]} nodes - DOM nodes.
1413
- * @param {object} [options={}] - Options.
1414
- * @param {Function} [options.replace] - Replacer.
1415
- * @param {object} [options.library] - Library (React/Preact/etc.).
1416
- * @return {string|JSX.Element|JSX.Element[]}
1416
+ * @param {DomElement[]} nodes - DOM nodes.
1417
+ * @param {object} [options={}] - Options.
1418
+ * @param {Function} [options.replace] - Replacer.
1419
+ * @param {object} [options.library] - Library (React, Preact, etc.).
1420
+ * @returns - String or JSX element(s).
1417
1421
  */
1418
1422
  function domToReact$1(nodes, options) {
1419
1423
  options = options || {};
@@ -1526,8 +1530,8 @@
1526
1530
  * Determines whether DOM element attributes should be transformed to props.
1527
1531
  * Web Components should not have their attributes transformed except for `style`.
1528
1532
  *
1529
- * @param {DomElement} node
1530
- * @return {boolean}
1533
+ * @param {DomElement} node
1534
+ * @returns - Whether node attributes should be converted to props.
1531
1535
  */
1532
1536
  function skipAttributesToProps(node) {
1533
1537
  return (
@@ -1539,6 +1543,164 @@
1539
1543
 
1540
1544
  var domToReact_1 = domToReact$1;
1541
1545
 
1546
+ // constants
1547
+ var HTML = 'html';
1548
+ var HEAD = 'head';
1549
+ var BODY = 'body';
1550
+ var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
1551
+ var HEAD_TAG_REGEX = /<head.*>/i;
1552
+ var BODY_TAG_REGEX = /<body.*>/i;
1553
+
1554
+ // falls back to `parseFromString` if `createHTMLDocument` cannot be used
1555
+ var parseFromDocument = function () {
1556
+ throw new Error(
1557
+ 'This browser does not support `document.implementation.createHTMLDocument`'
1558
+ );
1559
+ };
1560
+
1561
+ var parseFromString = function () {
1562
+ throw new Error(
1563
+ 'This browser does not support `DOMParser.prototype.parseFromString`'
1564
+ );
1565
+ };
1566
+
1567
+ /**
1568
+ * DOMParser (performance: slow).
1569
+ *
1570
+ * @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
1571
+ */
1572
+ if (typeof window.DOMParser === 'function') {
1573
+ var domParser = new window.DOMParser();
1574
+ var mimeType = 'text/html';
1575
+
1576
+ /**
1577
+ * Creates an HTML document using `DOMParser.parseFromString`.
1578
+ *
1579
+ * @param {string} html - The HTML string.
1580
+ * @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
1581
+ * @return {HTMLDocument}
1582
+ */
1583
+ parseFromString = function (html, tagName) {
1584
+ if (tagName) {
1585
+ html = '<' + tagName + '>' + html + '</' + tagName + '>';
1586
+ }
1587
+
1588
+ return domParser.parseFromString(html, mimeType);
1589
+ };
1590
+
1591
+ parseFromDocument = parseFromString;
1592
+ }
1593
+
1594
+ /**
1595
+ * DOMImplementation (performance: fair).
1596
+ *
1597
+ * @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
1598
+ */
1599
+ if (document.implementation) {
1600
+ var doc = document.implementation.createHTMLDocument();
1601
+
1602
+ /**
1603
+ * Use HTML document created by `document.implementation.createHTMLDocument`.
1604
+ *
1605
+ * @param {string} html - The HTML string.
1606
+ * @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
1607
+ * @return {HTMLDocument}
1608
+ */
1609
+ parseFromDocument = function (html, tagName) {
1610
+ if (tagName) {
1611
+ doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
1612
+ return doc;
1613
+ }
1614
+
1615
+ doc.documentElement.innerHTML = html;
1616
+ return doc;
1617
+ };
1618
+ }
1619
+
1620
+ /**
1621
+ * Template (performance: fast).
1622
+ *
1623
+ * @see https://developer.mozilla.org/docs/Web/HTML/Element/template
1624
+ */
1625
+ var template = document.createElement('template');
1626
+ var parseFromTemplate;
1627
+
1628
+ if (template.content) {
1629
+ /**
1630
+ * Uses a template element (content fragment) to parse HTML.
1631
+ *
1632
+ * @param {string} html - The HTML string.
1633
+ * @return {NodeList}
1634
+ */
1635
+ parseFromTemplate = function (html) {
1636
+ template.innerHTML = html;
1637
+ return template.content.childNodes;
1638
+ };
1639
+ }
1640
+
1641
+ /**
1642
+ * Parses HTML string to DOM nodes.
1643
+ *
1644
+ * @param {string} html - HTML markup.
1645
+ * @return {NodeList}
1646
+ */
1647
+ function domparser$1(html) {
1648
+ var firstTagName;
1649
+ var match = html.match(FIRST_TAG_REGEX);
1650
+
1651
+ if (match && match[1]) {
1652
+ firstTagName = match[1].toLowerCase();
1653
+ }
1654
+
1655
+ var doc;
1656
+ var element;
1657
+ var elements;
1658
+
1659
+ switch (firstTagName) {
1660
+ case HTML:
1661
+ doc = parseFromString(html);
1662
+
1663
+ // the created document may come with filler head/body elements,
1664
+ // so make sure to remove them if they don't actually exist
1665
+ if (!HEAD_TAG_REGEX.test(html)) {
1666
+ element = doc.getElementsByTagName(HEAD)[0];
1667
+ if (element) {
1668
+ element.parentNode.removeChild(element);
1669
+ }
1670
+ }
1671
+
1672
+ if (!BODY_TAG_REGEX.test(html)) {
1673
+ element = doc.getElementsByTagName(BODY)[0];
1674
+ if (element) {
1675
+ element.parentNode.removeChild(element);
1676
+ }
1677
+ }
1678
+
1679
+ return doc.getElementsByTagName(HTML);
1680
+
1681
+ case HEAD:
1682
+ case BODY:
1683
+ elements = parseFromDocument(html).getElementsByTagName(firstTagName);
1684
+
1685
+ // if there's a sibling element, then return both elements
1686
+ if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
1687
+ return elements[0].parentNode.childNodes;
1688
+ }
1689
+ return elements;
1690
+
1691
+ // low-level tag or text
1692
+ default:
1693
+ if (parseFromTemplate) {
1694
+ return parseFromTemplate(html);
1695
+ }
1696
+
1697
+ return parseFromDocument(html, BODY).getElementsByTagName(BODY)[0]
1698
+ .childNodes;
1699
+ }
1700
+ }
1701
+
1702
+ var domparser_1 = domparser$1;
1703
+
1542
1704
  /**
1543
1705
  * SVG elements are case-sensitive.
1544
1706
  *
@@ -1585,511 +1747,525 @@
1585
1747
 
1586
1748
  var node = {};
1587
1749
 
1588
- var lib = {};
1750
+ var lib$1 = {};
1589
1751
 
1590
- (function (exports) {
1591
- Object.defineProperty(exports, "__esModule", { value: true });
1592
- exports.Doctype = exports.CDATA = exports.Tag = exports.Style = exports.Script = exports.Comment = exports.Directive = exports.Text = exports.Root = exports.isTag = exports.ElementType = void 0;
1593
- /** Types of elements found in htmlparser2's DOM */
1594
- var ElementType;
1595
- (function (ElementType) {
1596
- /** Type for the root element of a document */
1597
- ElementType["Root"] = "root";
1598
- /** Type for Text */
1599
- ElementType["Text"] = "text";
1600
- /** Type for <? ... ?> */
1601
- ElementType["Directive"] = "directive";
1602
- /** Type for <!-- ... --> */
1603
- ElementType["Comment"] = "comment";
1604
- /** Type for <script> tags */
1605
- ElementType["Script"] = "script";
1606
- /** Type for <style> tags */
1607
- ElementType["Style"] = "style";
1608
- /** Type for Any tag */
1609
- ElementType["Tag"] = "tag";
1610
- /** Type for <![CDATA[ ... ]]> */
1611
- ElementType["CDATA"] = "cdata";
1612
- /** Type for <!doctype ...> */
1613
- ElementType["Doctype"] = "doctype";
1614
- })(ElementType = exports.ElementType || (exports.ElementType = {}));
1615
- /**
1616
- * Tests whether an element is a tag or not.
1617
- *
1618
- * @param elem Element to test
1619
- */
1620
- function isTag(elem) {
1621
- return (elem.type === ElementType.Tag ||
1622
- elem.type === ElementType.Script ||
1623
- elem.type === ElementType.Style);
1752
+ var hasRequiredLib$1;
1753
+
1754
+ function requireLib$1 () {
1755
+ if (hasRequiredLib$1) return lib$1;
1756
+ hasRequiredLib$1 = 1;
1757
+ (function (exports) {
1758
+ Object.defineProperty(exports, "__esModule", { value: true });
1759
+ exports.Doctype = exports.CDATA = exports.Tag = exports.Style = exports.Script = exports.Comment = exports.Directive = exports.Text = exports.Root = exports.isTag = exports.ElementType = void 0;
1760
+ /** Types of elements found in htmlparser2's DOM */
1761
+ var ElementType;
1762
+ (function (ElementType) {
1763
+ /** Type for the root element of a document */
1764
+ ElementType["Root"] = "root";
1765
+ /** Type for Text */
1766
+ ElementType["Text"] = "text";
1767
+ /** Type for <? ... ?> */
1768
+ ElementType["Directive"] = "directive";
1769
+ /** Type for <!-- ... --> */
1770
+ ElementType["Comment"] = "comment";
1771
+ /** Type for <script> tags */
1772
+ ElementType["Script"] = "script";
1773
+ /** Type for <style> tags */
1774
+ ElementType["Style"] = "style";
1775
+ /** Type for Any tag */
1776
+ ElementType["Tag"] = "tag";
1777
+ /** Type for <![CDATA[ ... ]]> */
1778
+ ElementType["CDATA"] = "cdata";
1779
+ /** Type for <!doctype ...> */
1780
+ ElementType["Doctype"] = "doctype";
1781
+ })(ElementType = exports.ElementType || (exports.ElementType = {}));
1782
+ /**
1783
+ * Tests whether an element is a tag or not.
1784
+ *
1785
+ * @param elem Element to test
1786
+ */
1787
+ function isTag(elem) {
1788
+ return (elem.type === ElementType.Tag ||
1789
+ elem.type === ElementType.Script ||
1790
+ elem.type === ElementType.Style);
1791
+ }
1792
+ exports.isTag = isTag;
1793
+ // Exports for backwards compatibility
1794
+ /** Type for the root element of a document */
1795
+ exports.Root = ElementType.Root;
1796
+ /** Type for Text */
1797
+ exports.Text = ElementType.Text;
1798
+ /** Type for <? ... ?> */
1799
+ exports.Directive = ElementType.Directive;
1800
+ /** Type for <!-- ... --> */
1801
+ exports.Comment = ElementType.Comment;
1802
+ /** Type for <script> tags */
1803
+ exports.Script = ElementType.Script;
1804
+ /** Type for <style> tags */
1805
+ exports.Style = ElementType.Style;
1806
+ /** Type for Any tag */
1807
+ exports.Tag = ElementType.Tag;
1808
+ /** Type for <![CDATA[ ... ]]> */
1809
+ exports.CDATA = ElementType.CDATA;
1810
+ /** Type for <!doctype ...> */
1811
+ exports.Doctype = ElementType.Doctype;
1812
+ } (lib$1));
1813
+ return lib$1;
1624
1814
  }
1625
- exports.isTag = isTag;
1626
- // Exports for backwards compatibility
1627
- /** Type for the root element of a document */
1628
- exports.Root = ElementType.Root;
1629
- /** Type for Text */
1630
- exports.Text = ElementType.Text;
1631
- /** Type for <? ... ?> */
1632
- exports.Directive = ElementType.Directive;
1633
- /** Type for <!-- ... --> */
1634
- exports.Comment = ElementType.Comment;
1635
- /** Type for <script> tags */
1636
- exports.Script = ElementType.Script;
1637
- /** Type for <style> tags */
1638
- exports.Style = ElementType.Style;
1639
- /** Type for Any tag */
1640
- exports.Tag = ElementType.Tag;
1641
- /** Type for <![CDATA[ ... ]]> */
1642
- exports.CDATA = ElementType.CDATA;
1643
- /** Type for <!doctype ...> */
1644
- exports.Doctype = ElementType.Doctype;
1645
- }(lib));
1646
-
1647
- var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
1648
- var extendStatics = function (d, b) {
1649
- extendStatics = Object.setPrototypeOf ||
1650
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1651
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1652
- return extendStatics(d, b);
1653
- };
1654
- return function (d, b) {
1655
- if (typeof b !== "function" && b !== null)
1656
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1657
- extendStatics(d, b);
1658
- function __() { this.constructor = d; }
1659
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1660
- };
1661
- })();
1662
- var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1663
- __assign = Object.assign || function(t) {
1664
- for (var s, i = 1, n = arguments.length; i < n; i++) {
1665
- s = arguments[i];
1666
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1667
- t[p] = s[p];
1668
- }
1669
- return t;
1670
- };
1671
- return __assign.apply(this, arguments);
1672
- };
1673
- Object.defineProperty(node, "__esModule", { value: true });
1674
- node.cloneNode = node.hasChildren = node.isDocument = node.isDirective = node.isComment = node.isText = node.isCDATA = node.isTag = node.Element = node.Document = node.NodeWithChildren = node.ProcessingInstruction = node.Comment = node.Text = node.DataNode = node.Node = void 0;
1675
- var domelementtype_1 = lib;
1676
- var nodeTypes = new Map([
1677
- [domelementtype_1.ElementType.Tag, 1],
1678
- [domelementtype_1.ElementType.Script, 1],
1679
- [domelementtype_1.ElementType.Style, 1],
1680
- [domelementtype_1.ElementType.Directive, 1],
1681
- [domelementtype_1.ElementType.Text, 3],
1682
- [domelementtype_1.ElementType.CDATA, 4],
1683
- [domelementtype_1.ElementType.Comment, 8],
1684
- [domelementtype_1.ElementType.Root, 9],
1685
- ]);
1686
- /**
1687
- * This object will be used as the prototype for Nodes when creating a
1688
- * DOM-Level-1-compliant structure.
1689
- */
1690
- var Node = /** @class */ (function () {
1691
- /**
1692
- *
1693
- * @param type The type of the node.
1694
- */
1695
- function Node(type) {
1696
- this.type = type;
1697
- /** Parent of the node */
1698
- this.parent = null;
1699
- /** Previous sibling */
1700
- this.prev = null;
1701
- /** Next sibling */
1702
- this.next = null;
1703
- /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
1704
- this.startIndex = null;
1705
- /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
1706
- this.endIndex = null;
1707
- }
1708
- Object.defineProperty(Node.prototype, "nodeType", {
1709
- // Read-only aliases
1710
- /**
1711
- * [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible
1712
- * node {@link type}.
1713
- */
1714
- get: function () {
1715
- var _a;
1716
- return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
1717
- },
1718
- enumerable: false,
1719
- configurable: true
1720
- });
1721
- Object.defineProperty(Node.prototype, "parentNode", {
1722
- // Read-write aliases for properties
1723
- /**
1724
- * Same as {@link parent}.
1725
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1726
- */
1727
- get: function () {
1728
- return this.parent;
1729
- },
1730
- set: function (parent) {
1731
- this.parent = parent;
1732
- },
1733
- enumerable: false,
1734
- configurable: true
1735
- });
1736
- Object.defineProperty(Node.prototype, "previousSibling", {
1737
- /**
1738
- * Same as {@link prev}.
1739
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1740
- */
1741
- get: function () {
1742
- return this.prev;
1743
- },
1744
- set: function (prev) {
1745
- this.prev = prev;
1746
- },
1747
- enumerable: false,
1748
- configurable: true
1749
- });
1750
- Object.defineProperty(Node.prototype, "nextSibling", {
1751
- /**
1752
- * Same as {@link next}.
1753
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1754
- */
1755
- get: function () {
1756
- return this.next;
1757
- },
1758
- set: function (next) {
1759
- this.next = next;
1760
- },
1761
- enumerable: false,
1762
- configurable: true
1763
- });
1764
- /**
1765
- * Clone this node, and optionally its children.
1766
- *
1767
- * @param recursive Clone child nodes as well.
1768
- * @returns A clone of the node.
1769
- */
1770
- Node.prototype.cloneNode = function (recursive) {
1771
- if (recursive === void 0) { recursive = false; }
1772
- return cloneNode(this, recursive);
1773
- };
1774
- return Node;
1775
- }());
1776
- node.Node = Node;
1777
- /**
1778
- * A node that contains some data.
1779
- */
1780
- var DataNode = /** @class */ (function (_super) {
1781
- __extends(DataNode, _super);
1782
- /**
1783
- * @param type The type of the node
1784
- * @param data The content of the data node
1785
- */
1786
- function DataNode(type, data) {
1787
- var _this = _super.call(this, type) || this;
1788
- _this.data = data;
1789
- return _this;
1790
- }
1791
- Object.defineProperty(DataNode.prototype, "nodeValue", {
1792
- /**
1793
- * Same as {@link data}.
1794
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1795
- */
1796
- get: function () {
1797
- return this.data;
1798
- },
1799
- set: function (data) {
1800
- this.data = data;
1801
- },
1802
- enumerable: false,
1803
- configurable: true
1804
- });
1805
- return DataNode;
1806
- }(Node));
1807
- node.DataNode = DataNode;
1808
- /**
1809
- * Text within the document.
1810
- */
1811
- var Text$1 = /** @class */ (function (_super) {
1812
- __extends(Text, _super);
1813
- function Text(data) {
1814
- return _super.call(this, domelementtype_1.ElementType.Text, data) || this;
1815
- }
1816
- return Text;
1817
- }(DataNode));
1818
- node.Text = Text$1;
1819
- /**
1820
- * Comments within the document.
1821
- */
1822
- var Comment$1 = /** @class */ (function (_super) {
1823
- __extends(Comment, _super);
1824
- function Comment(data) {
1825
- return _super.call(this, domelementtype_1.ElementType.Comment, data) || this;
1826
- }
1827
- return Comment;
1828
- }(DataNode));
1829
- node.Comment = Comment$1;
1830
- /**
1831
- * Processing instructions, including doc types.
1832
- */
1833
- var ProcessingInstruction$1 = /** @class */ (function (_super) {
1834
- __extends(ProcessingInstruction, _super);
1835
- function ProcessingInstruction(name, data) {
1836
- var _this = _super.call(this, domelementtype_1.ElementType.Directive, data) || this;
1837
- _this.name = name;
1838
- return _this;
1839
- }
1840
- return ProcessingInstruction;
1841
- }(DataNode));
1842
- node.ProcessingInstruction = ProcessingInstruction$1;
1843
- /**
1844
- * A `Node` that can have children.
1845
- */
1846
- var NodeWithChildren = /** @class */ (function (_super) {
1847
- __extends(NodeWithChildren, _super);
1848
- /**
1849
- * @param type Type of the node.
1850
- * @param children Children of the node. Only certain node types can have children.
1851
- */
1852
- function NodeWithChildren(type, children) {
1853
- var _this = _super.call(this, type) || this;
1854
- _this.children = children;
1855
- return _this;
1856
- }
1857
- Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
1858
- // Aliases
1859
- /** First child of the node. */
1860
- get: function () {
1861
- var _a;
1862
- return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
1863
- },
1864
- enumerable: false,
1865
- configurable: true
1866
- });
1867
- Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
1868
- /** Last child of the node. */
1869
- get: function () {
1870
- return this.children.length > 0
1871
- ? this.children[this.children.length - 1]
1872
- : null;
1873
- },
1874
- enumerable: false,
1875
- configurable: true
1876
- });
1877
- Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
1878
- /**
1879
- * Same as {@link children}.
1880
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1881
- */
1882
- get: function () {
1883
- return this.children;
1884
- },
1885
- set: function (children) {
1886
- this.children = children;
1887
- },
1888
- enumerable: false,
1889
- configurable: true
1890
- });
1891
- return NodeWithChildren;
1892
- }(Node));
1893
- node.NodeWithChildren = NodeWithChildren;
1894
- /**
1895
- * The root node of the document.
1896
- */
1897
- var Document = /** @class */ (function (_super) {
1898
- __extends(Document, _super);
1899
- function Document(children) {
1900
- return _super.call(this, domelementtype_1.ElementType.Root, children) || this;
1901
- }
1902
- return Document;
1903
- }(NodeWithChildren));
1904
- node.Document = Document;
1905
- /**
1906
- * An element within the DOM.
1907
- */
1908
- var Element$1 = /** @class */ (function (_super) {
1909
- __extends(Element, _super);
1910
- /**
1911
- * @param name Name of the tag, eg. `div`, `span`.
1912
- * @param attribs Object mapping attribute names to attribute values.
1913
- * @param children Children of the node.
1914
- */
1915
- function Element(name, attribs, children, type) {
1916
- if (children === void 0) { children = []; }
1917
- if (type === void 0) { type = name === "script"
1918
- ? domelementtype_1.ElementType.Script
1919
- : name === "style"
1920
- ? domelementtype_1.ElementType.Style
1921
- : domelementtype_1.ElementType.Tag; }
1922
- var _this = _super.call(this, type, children) || this;
1923
- _this.name = name;
1924
- _this.attribs = attribs;
1925
- return _this;
1926
- }
1927
- Object.defineProperty(Element.prototype, "tagName", {
1928
- // DOM Level 1 aliases
1929
- /**
1930
- * Same as {@link name}.
1931
- * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1932
- */
1933
- get: function () {
1934
- return this.name;
1935
- },
1936
- set: function (name) {
1937
- this.name = name;
1938
- },
1939
- enumerable: false,
1940
- configurable: true
1941
- });
1942
- Object.defineProperty(Element.prototype, "attributes", {
1943
- get: function () {
1944
- var _this = this;
1945
- return Object.keys(this.attribs).map(function (name) {
1946
- var _a, _b;
1947
- return ({
1948
- name: name,
1949
- value: _this.attribs[name],
1950
- namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
1951
- prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
1952
- });
1953
- });
1954
- },
1955
- enumerable: false,
1956
- configurable: true
1957
- });
1958
- return Element;
1959
- }(NodeWithChildren));
1960
- node.Element = Element$1;
1961
- /**
1962
- * @param node Node to check.
1963
- * @returns `true` if the node is a `Element`, `false` otherwise.
1964
- */
1965
- function isTag(node) {
1966
- return (0, domelementtype_1.isTag)(node);
1967
- }
1968
- node.isTag = isTag;
1969
- /**
1970
- * @param node Node to check.
1971
- * @returns `true` if the node has the type `CDATA`, `false` otherwise.
1972
- */
1973
- function isCDATA(node) {
1974
- return node.type === domelementtype_1.ElementType.CDATA;
1975
- }
1976
- node.isCDATA = isCDATA;
1977
- /**
1978
- * @param node Node to check.
1979
- * @returns `true` if the node has the type `Text`, `false` otherwise.
1980
- */
1981
- function isText(node) {
1982
- return node.type === domelementtype_1.ElementType.Text;
1983
- }
1984
- node.isText = isText;
1985
- /**
1986
- * @param node Node to check.
1987
- * @returns `true` if the node has the type `Comment`, `false` otherwise.
1988
- */
1989
- function isComment(node) {
1990
- return node.type === domelementtype_1.ElementType.Comment;
1991
- }
1992
- node.isComment = isComment;
1993
- /**
1994
- * @param node Node to check.
1995
- * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
1996
- */
1997
- function isDirective(node) {
1998
- return node.type === domelementtype_1.ElementType.Directive;
1999
- }
2000
- node.isDirective = isDirective;
2001
- /**
2002
- * @param node Node to check.
2003
- * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
2004
- */
2005
- function isDocument(node) {
2006
- return node.type === domelementtype_1.ElementType.Root;
2007
- }
2008
- node.isDocument = isDocument;
2009
- /**
2010
- * @param node Node to check.
2011
- * @returns `true` if the node is a `NodeWithChildren` (has children), `false` otherwise.
2012
- */
2013
- function hasChildren(node) {
2014
- return Object.prototype.hasOwnProperty.call(node, "children");
2015
- }
2016
- node.hasChildren = hasChildren;
2017
- /**
2018
- * Clone a node, and optionally its children.
2019
- *
2020
- * @param recursive Clone child nodes as well.
2021
- * @returns A clone of the node.
2022
- */
2023
- function cloneNode(node, recursive) {
2024
- if (recursive === void 0) { recursive = false; }
2025
- var result;
2026
- if (isText(node)) {
2027
- result = new Text$1(node.data);
2028
- }
2029
- else if (isComment(node)) {
2030
- result = new Comment$1(node.data);
2031
- }
2032
- else if (isTag(node)) {
2033
- var children = recursive ? cloneChildren(node.children) : [];
2034
- var clone_1 = new Element$1(node.name, __assign({}, node.attribs), children);
2035
- children.forEach(function (child) { return (child.parent = clone_1); });
2036
- if (node.namespace != null) {
2037
- clone_1.namespace = node.namespace;
2038
- }
2039
- if (node["x-attribsNamespace"]) {
2040
- clone_1["x-attribsNamespace"] = __assign({}, node["x-attribsNamespace"]);
2041
- }
2042
- if (node["x-attribsPrefix"]) {
2043
- clone_1["x-attribsPrefix"] = __assign({}, node["x-attribsPrefix"]);
2044
- }
2045
- result = clone_1;
2046
- }
2047
- else if (isCDATA(node)) {
2048
- var children = recursive ? cloneChildren(node.children) : [];
2049
- var clone_2 = new NodeWithChildren(domelementtype_1.ElementType.CDATA, children);
2050
- children.forEach(function (child) { return (child.parent = clone_2); });
2051
- result = clone_2;
2052
- }
2053
- else if (isDocument(node)) {
2054
- var children = recursive ? cloneChildren(node.children) : [];
2055
- var clone_3 = new Document(children);
2056
- children.forEach(function (child) { return (child.parent = clone_3); });
2057
- if (node["x-mode"]) {
2058
- clone_3["x-mode"] = node["x-mode"];
2059
- }
2060
- result = clone_3;
2061
- }
2062
- else if (isDirective(node)) {
2063
- var instruction = new ProcessingInstruction$1(node.name, node.data);
2064
- if (node["x-name"] != null) {
2065
- instruction["x-name"] = node["x-name"];
2066
- instruction["x-publicId"] = node["x-publicId"];
2067
- instruction["x-systemId"] = node["x-systemId"];
2068
- }
2069
- result = instruction;
2070
- }
2071
- else {
2072
- throw new Error("Not implemented yet: ".concat(node.type));
2073
- }
2074
- result.startIndex = node.startIndex;
2075
- result.endIndex = node.endIndex;
2076
- if (node.sourceCodeLocation != null) {
2077
- result.sourceCodeLocation = node.sourceCodeLocation;
2078
- }
2079
- return result;
2080
- }
2081
- node.cloneNode = cloneNode;
2082
- function cloneChildren(childs) {
2083
- var children = childs.map(function (child) { return cloneNode(child, true); });
2084
- for (var i = 1; i < children.length; i++) {
2085
- children[i].prev = children[i - 1];
2086
- children[i - 1].next = children[i];
2087
- }
2088
- return children;
1815
+
1816
+ var hasRequiredNode;
1817
+
1818
+ function requireNode () {
1819
+ if (hasRequiredNode) return node;
1820
+ hasRequiredNode = 1;
1821
+ var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
1822
+ var extendStatics = function (d, b) {
1823
+ extendStatics = Object.setPrototypeOf ||
1824
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
1825
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
1826
+ return extendStatics(d, b);
1827
+ };
1828
+ return function (d, b) {
1829
+ if (typeof b !== "function" && b !== null)
1830
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1831
+ extendStatics(d, b);
1832
+ function __() { this.constructor = d; }
1833
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1834
+ };
1835
+ })();
1836
+ var __assign = (commonjsGlobal && commonjsGlobal.__assign) || function () {
1837
+ __assign = Object.assign || function(t) {
1838
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1839
+ s = arguments[i];
1840
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
1841
+ t[p] = s[p];
1842
+ }
1843
+ return t;
1844
+ };
1845
+ return __assign.apply(this, arguments);
1846
+ };
1847
+ Object.defineProperty(node, "__esModule", { value: true });
1848
+ node.cloneNode = node.hasChildren = node.isDocument = node.isDirective = node.isComment = node.isText = node.isCDATA = node.isTag = node.Element = node.Document = node.NodeWithChildren = node.ProcessingInstruction = node.Comment = node.Text = node.DataNode = node.Node = void 0;
1849
+ var domelementtype_1 = requireLib$1();
1850
+ var nodeTypes = new Map([
1851
+ [domelementtype_1.ElementType.Tag, 1],
1852
+ [domelementtype_1.ElementType.Script, 1],
1853
+ [domelementtype_1.ElementType.Style, 1],
1854
+ [domelementtype_1.ElementType.Directive, 1],
1855
+ [domelementtype_1.ElementType.Text, 3],
1856
+ [domelementtype_1.ElementType.CDATA, 4],
1857
+ [domelementtype_1.ElementType.Comment, 8],
1858
+ [domelementtype_1.ElementType.Root, 9],
1859
+ ]);
1860
+ /**
1861
+ * This object will be used as the prototype for Nodes when creating a
1862
+ * DOM-Level-1-compliant structure.
1863
+ */
1864
+ var Node = /** @class */ (function () {
1865
+ /**
1866
+ *
1867
+ * @param type The type of the node.
1868
+ */
1869
+ function Node(type) {
1870
+ this.type = type;
1871
+ /** Parent of the node */
1872
+ this.parent = null;
1873
+ /** Previous sibling */
1874
+ this.prev = null;
1875
+ /** Next sibling */
1876
+ this.next = null;
1877
+ /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
1878
+ this.startIndex = null;
1879
+ /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
1880
+ this.endIndex = null;
1881
+ }
1882
+ Object.defineProperty(Node.prototype, "nodeType", {
1883
+ // Read-only aliases
1884
+ /**
1885
+ * [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible
1886
+ * node {@link type}.
1887
+ */
1888
+ get: function () {
1889
+ var _a;
1890
+ return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
1891
+ },
1892
+ enumerable: false,
1893
+ configurable: true
1894
+ });
1895
+ Object.defineProperty(Node.prototype, "parentNode", {
1896
+ // Read-write aliases for properties
1897
+ /**
1898
+ * Same as {@link parent}.
1899
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1900
+ */
1901
+ get: function () {
1902
+ return this.parent;
1903
+ },
1904
+ set: function (parent) {
1905
+ this.parent = parent;
1906
+ },
1907
+ enumerable: false,
1908
+ configurable: true
1909
+ });
1910
+ Object.defineProperty(Node.prototype, "previousSibling", {
1911
+ /**
1912
+ * Same as {@link prev}.
1913
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1914
+ */
1915
+ get: function () {
1916
+ return this.prev;
1917
+ },
1918
+ set: function (prev) {
1919
+ this.prev = prev;
1920
+ },
1921
+ enumerable: false,
1922
+ configurable: true
1923
+ });
1924
+ Object.defineProperty(Node.prototype, "nextSibling", {
1925
+ /**
1926
+ * Same as {@link next}.
1927
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1928
+ */
1929
+ get: function () {
1930
+ return this.next;
1931
+ },
1932
+ set: function (next) {
1933
+ this.next = next;
1934
+ },
1935
+ enumerable: false,
1936
+ configurable: true
1937
+ });
1938
+ /**
1939
+ * Clone this node, and optionally its children.
1940
+ *
1941
+ * @param recursive Clone child nodes as well.
1942
+ * @returns A clone of the node.
1943
+ */
1944
+ Node.prototype.cloneNode = function (recursive) {
1945
+ if (recursive === void 0) { recursive = false; }
1946
+ return cloneNode(this, recursive);
1947
+ };
1948
+ return Node;
1949
+ }());
1950
+ node.Node = Node;
1951
+ /**
1952
+ * A node that contains some data.
1953
+ */
1954
+ var DataNode = /** @class */ (function (_super) {
1955
+ __extends(DataNode, _super);
1956
+ /**
1957
+ * @param type The type of the node
1958
+ * @param data The content of the data node
1959
+ */
1960
+ function DataNode(type, data) {
1961
+ var _this = _super.call(this, type) || this;
1962
+ _this.data = data;
1963
+ return _this;
1964
+ }
1965
+ Object.defineProperty(DataNode.prototype, "nodeValue", {
1966
+ /**
1967
+ * Same as {@link data}.
1968
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
1969
+ */
1970
+ get: function () {
1971
+ return this.data;
1972
+ },
1973
+ set: function (data) {
1974
+ this.data = data;
1975
+ },
1976
+ enumerable: false,
1977
+ configurable: true
1978
+ });
1979
+ return DataNode;
1980
+ }(Node));
1981
+ node.DataNode = DataNode;
1982
+ /**
1983
+ * Text within the document.
1984
+ */
1985
+ var Text = /** @class */ (function (_super) {
1986
+ __extends(Text, _super);
1987
+ function Text(data) {
1988
+ return _super.call(this, domelementtype_1.ElementType.Text, data) || this;
1989
+ }
1990
+ return Text;
1991
+ }(DataNode));
1992
+ node.Text = Text;
1993
+ /**
1994
+ * Comments within the document.
1995
+ */
1996
+ var Comment = /** @class */ (function (_super) {
1997
+ __extends(Comment, _super);
1998
+ function Comment(data) {
1999
+ return _super.call(this, domelementtype_1.ElementType.Comment, data) || this;
2000
+ }
2001
+ return Comment;
2002
+ }(DataNode));
2003
+ node.Comment = Comment;
2004
+ /**
2005
+ * Processing instructions, including doc types.
2006
+ */
2007
+ var ProcessingInstruction = /** @class */ (function (_super) {
2008
+ __extends(ProcessingInstruction, _super);
2009
+ function ProcessingInstruction(name, data) {
2010
+ var _this = _super.call(this, domelementtype_1.ElementType.Directive, data) || this;
2011
+ _this.name = name;
2012
+ return _this;
2013
+ }
2014
+ return ProcessingInstruction;
2015
+ }(DataNode));
2016
+ node.ProcessingInstruction = ProcessingInstruction;
2017
+ /**
2018
+ * A `Node` that can have children.
2019
+ */
2020
+ var NodeWithChildren = /** @class */ (function (_super) {
2021
+ __extends(NodeWithChildren, _super);
2022
+ /**
2023
+ * @param type Type of the node.
2024
+ * @param children Children of the node. Only certain node types can have children.
2025
+ */
2026
+ function NodeWithChildren(type, children) {
2027
+ var _this = _super.call(this, type) || this;
2028
+ _this.children = children;
2029
+ return _this;
2030
+ }
2031
+ Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
2032
+ // Aliases
2033
+ /** First child of the node. */
2034
+ get: function () {
2035
+ var _a;
2036
+ return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
2037
+ },
2038
+ enumerable: false,
2039
+ configurable: true
2040
+ });
2041
+ Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
2042
+ /** Last child of the node. */
2043
+ get: function () {
2044
+ return this.children.length > 0
2045
+ ? this.children[this.children.length - 1]
2046
+ : null;
2047
+ },
2048
+ enumerable: false,
2049
+ configurable: true
2050
+ });
2051
+ Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
2052
+ /**
2053
+ * Same as {@link children}.
2054
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2055
+ */
2056
+ get: function () {
2057
+ return this.children;
2058
+ },
2059
+ set: function (children) {
2060
+ this.children = children;
2061
+ },
2062
+ enumerable: false,
2063
+ configurable: true
2064
+ });
2065
+ return NodeWithChildren;
2066
+ }(Node));
2067
+ node.NodeWithChildren = NodeWithChildren;
2068
+ /**
2069
+ * The root node of the document.
2070
+ */
2071
+ var Document = /** @class */ (function (_super) {
2072
+ __extends(Document, _super);
2073
+ function Document(children) {
2074
+ return _super.call(this, domelementtype_1.ElementType.Root, children) || this;
2075
+ }
2076
+ return Document;
2077
+ }(NodeWithChildren));
2078
+ node.Document = Document;
2079
+ /**
2080
+ * An element within the DOM.
2081
+ */
2082
+ var Element = /** @class */ (function (_super) {
2083
+ __extends(Element, _super);
2084
+ /**
2085
+ * @param name Name of the tag, eg. `div`, `span`.
2086
+ * @param attribs Object mapping attribute names to attribute values.
2087
+ * @param children Children of the node.
2088
+ */
2089
+ function Element(name, attribs, children, type) {
2090
+ if (children === void 0) { children = []; }
2091
+ if (type === void 0) { type = name === "script"
2092
+ ? domelementtype_1.ElementType.Script
2093
+ : name === "style"
2094
+ ? domelementtype_1.ElementType.Style
2095
+ : domelementtype_1.ElementType.Tag; }
2096
+ var _this = _super.call(this, type, children) || this;
2097
+ _this.name = name;
2098
+ _this.attribs = attribs;
2099
+ return _this;
2100
+ }
2101
+ Object.defineProperty(Element.prototype, "tagName", {
2102
+ // DOM Level 1 aliases
2103
+ /**
2104
+ * Same as {@link name}.
2105
+ * [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
2106
+ */
2107
+ get: function () {
2108
+ return this.name;
2109
+ },
2110
+ set: function (name) {
2111
+ this.name = name;
2112
+ },
2113
+ enumerable: false,
2114
+ configurable: true
2115
+ });
2116
+ Object.defineProperty(Element.prototype, "attributes", {
2117
+ get: function () {
2118
+ var _this = this;
2119
+ return Object.keys(this.attribs).map(function (name) {
2120
+ var _a, _b;
2121
+ return ({
2122
+ name: name,
2123
+ value: _this.attribs[name],
2124
+ namespace: (_a = _this["x-attribsNamespace"]) === null || _a === void 0 ? void 0 : _a[name],
2125
+ prefix: (_b = _this["x-attribsPrefix"]) === null || _b === void 0 ? void 0 : _b[name],
2126
+ });
2127
+ });
2128
+ },
2129
+ enumerable: false,
2130
+ configurable: true
2131
+ });
2132
+ return Element;
2133
+ }(NodeWithChildren));
2134
+ node.Element = Element;
2135
+ /**
2136
+ * @param node Node to check.
2137
+ * @returns `true` if the node is a `Element`, `false` otherwise.
2138
+ */
2139
+ function isTag(node) {
2140
+ return (0, domelementtype_1.isTag)(node);
2141
+ }
2142
+ node.isTag = isTag;
2143
+ /**
2144
+ * @param node Node to check.
2145
+ * @returns `true` if the node has the type `CDATA`, `false` otherwise.
2146
+ */
2147
+ function isCDATA(node) {
2148
+ return node.type === domelementtype_1.ElementType.CDATA;
2149
+ }
2150
+ node.isCDATA = isCDATA;
2151
+ /**
2152
+ * @param node Node to check.
2153
+ * @returns `true` if the node has the type `Text`, `false` otherwise.
2154
+ */
2155
+ function isText(node) {
2156
+ return node.type === domelementtype_1.ElementType.Text;
2157
+ }
2158
+ node.isText = isText;
2159
+ /**
2160
+ * @param node Node to check.
2161
+ * @returns `true` if the node has the type `Comment`, `false` otherwise.
2162
+ */
2163
+ function isComment(node) {
2164
+ return node.type === domelementtype_1.ElementType.Comment;
2165
+ }
2166
+ node.isComment = isComment;
2167
+ /**
2168
+ * @param node Node to check.
2169
+ * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
2170
+ */
2171
+ function isDirective(node) {
2172
+ return node.type === domelementtype_1.ElementType.Directive;
2173
+ }
2174
+ node.isDirective = isDirective;
2175
+ /**
2176
+ * @param node Node to check.
2177
+ * @returns `true` if the node has the type `ProcessingInstruction`, `false` otherwise.
2178
+ */
2179
+ function isDocument(node) {
2180
+ return node.type === domelementtype_1.ElementType.Root;
2181
+ }
2182
+ node.isDocument = isDocument;
2183
+ /**
2184
+ * @param node Node to check.
2185
+ * @returns `true` if the node is a `NodeWithChildren` (has children), `false` otherwise.
2186
+ */
2187
+ function hasChildren(node) {
2188
+ return Object.prototype.hasOwnProperty.call(node, "children");
2189
+ }
2190
+ node.hasChildren = hasChildren;
2191
+ /**
2192
+ * Clone a node, and optionally its children.
2193
+ *
2194
+ * @param recursive Clone child nodes as well.
2195
+ * @returns A clone of the node.
2196
+ */
2197
+ function cloneNode(node, recursive) {
2198
+ if (recursive === void 0) { recursive = false; }
2199
+ var result;
2200
+ if (isText(node)) {
2201
+ result = new Text(node.data);
2202
+ }
2203
+ else if (isComment(node)) {
2204
+ result = new Comment(node.data);
2205
+ }
2206
+ else if (isTag(node)) {
2207
+ var children = recursive ? cloneChildren(node.children) : [];
2208
+ var clone_1 = new Element(node.name, __assign({}, node.attribs), children);
2209
+ children.forEach(function (child) { return (child.parent = clone_1); });
2210
+ if (node.namespace != null) {
2211
+ clone_1.namespace = node.namespace;
2212
+ }
2213
+ if (node["x-attribsNamespace"]) {
2214
+ clone_1["x-attribsNamespace"] = __assign({}, node["x-attribsNamespace"]);
2215
+ }
2216
+ if (node["x-attribsPrefix"]) {
2217
+ clone_1["x-attribsPrefix"] = __assign({}, node["x-attribsPrefix"]);
2218
+ }
2219
+ result = clone_1;
2220
+ }
2221
+ else if (isCDATA(node)) {
2222
+ var children = recursive ? cloneChildren(node.children) : [];
2223
+ var clone_2 = new NodeWithChildren(domelementtype_1.ElementType.CDATA, children);
2224
+ children.forEach(function (child) { return (child.parent = clone_2); });
2225
+ result = clone_2;
2226
+ }
2227
+ else if (isDocument(node)) {
2228
+ var children = recursive ? cloneChildren(node.children) : [];
2229
+ var clone_3 = new Document(children);
2230
+ children.forEach(function (child) { return (child.parent = clone_3); });
2231
+ if (node["x-mode"]) {
2232
+ clone_3["x-mode"] = node["x-mode"];
2233
+ }
2234
+ result = clone_3;
2235
+ }
2236
+ else if (isDirective(node)) {
2237
+ var instruction = new ProcessingInstruction(node.name, node.data);
2238
+ if (node["x-name"] != null) {
2239
+ instruction["x-name"] = node["x-name"];
2240
+ instruction["x-publicId"] = node["x-publicId"];
2241
+ instruction["x-systemId"] = node["x-systemId"];
2242
+ }
2243
+ result = instruction;
2244
+ }
2245
+ else {
2246
+ throw new Error("Not implemented yet: ".concat(node.type));
2247
+ }
2248
+ result.startIndex = node.startIndex;
2249
+ result.endIndex = node.endIndex;
2250
+ if (node.sourceCodeLocation != null) {
2251
+ result.sourceCodeLocation = node.sourceCodeLocation;
2252
+ }
2253
+ return result;
2254
+ }
2255
+ node.cloneNode = cloneNode;
2256
+ function cloneChildren(childs) {
2257
+ var children = childs.map(function (child) { return cloneNode(child, true); });
2258
+ for (var i = 1; i < children.length; i++) {
2259
+ children[i].prev = children[i - 1];
2260
+ children[i - 1].next = children[i];
2261
+ }
2262
+ return children;
2263
+ }
2264
+ return node;
2089
2265
  }
2090
2266
 
2091
2267
  var constants = constants$1;
2092
- var domhandler = node;
2268
+ var domhandler = requireNode();
2093
2269
 
2094
2270
  var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
2095
2271
 
@@ -2219,185 +2395,11 @@
2219
2395
  return result;
2220
2396
  }
2221
2397
 
2222
- /**
2223
- * Detects if browser is Internet Explorer.
2224
- *
2225
- * @return {boolean} - Whether IE is detected.
2226
- */
2227
- function isIE$1() {
2228
- return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
2229
- }
2230
-
2231
2398
  var utilities = {
2232
2399
  formatAttributes: formatAttributes,
2233
- formatDOM: formatDOM$1,
2234
- isIE: isIE$1
2400
+ formatDOM: formatDOM$1
2235
2401
  };
2236
2402
 
2237
- // constants
2238
- var HTML = 'html';
2239
- var HEAD = 'head';
2240
- var BODY = 'body';
2241
- var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
2242
- var HEAD_TAG_REGEX = /<head.*>/i;
2243
- var BODY_TAG_REGEX = /<body.*>/i;
2244
-
2245
- // falls back to `parseFromString` if `createHTMLDocument` cannot be used
2246
- var parseFromDocument = function () {
2247
- throw new Error(
2248
- 'This browser does not support `document.implementation.createHTMLDocument`'
2249
- );
2250
- };
2251
-
2252
- var parseFromString = function () {
2253
- throw new Error(
2254
- 'This browser does not support `DOMParser.prototype.parseFromString`'
2255
- );
2256
- };
2257
-
2258
- /**
2259
- * DOMParser (performance: slow).
2260
- *
2261
- * @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
2262
- */
2263
- if (typeof window.DOMParser === 'function') {
2264
- var domParser = new window.DOMParser();
2265
- var mimeType = 'text/html';
2266
-
2267
- /**
2268
- * Creates an HTML document using `DOMParser.parseFromString`.
2269
- *
2270
- * @param {string} html - The HTML string.
2271
- * @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
2272
- * @return {HTMLDocument}
2273
- */
2274
- parseFromString = function (html, tagName) {
2275
- if (tagName) {
2276
- html = '<' + tagName + '>' + html + '</' + tagName + '>';
2277
- }
2278
-
2279
- return domParser.parseFromString(html, mimeType);
2280
- };
2281
-
2282
- parseFromDocument = parseFromString;
2283
- }
2284
-
2285
- /**
2286
- * DOMImplementation (performance: fair).
2287
- *
2288
- * @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
2289
- */
2290
- if (document.implementation) {
2291
- var isIE = utilities.isIE;
2292
-
2293
- // title parameter is required in IE
2294
- // https://msdn.microsoft.com/en-us/library/ff975457(v=vs.85).aspx
2295
- var doc = document.implementation.createHTMLDocument(
2296
- isIE() ? 'html-dom-parser' : undefined
2297
- );
2298
-
2299
- /**
2300
- * Use HTML document created by `document.implementation.createHTMLDocument`.
2301
- *
2302
- * @param {string} html - The HTML string.
2303
- * @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
2304
- * @return {HTMLDocument}
2305
- */
2306
- parseFromDocument = function (html, tagName) {
2307
- if (tagName) {
2308
- doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
2309
- return doc;
2310
- }
2311
-
2312
- doc.documentElement.innerHTML = html;
2313
- return doc;
2314
- };
2315
- }
2316
-
2317
- /**
2318
- * Template (performance: fast).
2319
- *
2320
- * @see https://developer.mozilla.org/docs/Web/HTML/Element/template
2321
- */
2322
- var template = document.createElement('template');
2323
- var parseFromTemplate;
2324
-
2325
- if (template.content) {
2326
- /**
2327
- * Uses a template element (content fragment) to parse HTML.
2328
- *
2329
- * @param {string} html - The HTML string.
2330
- * @return {NodeList}
2331
- */
2332
- parseFromTemplate = function (html) {
2333
- template.innerHTML = html;
2334
- return template.content.childNodes;
2335
- };
2336
- }
2337
-
2338
- /**
2339
- * Parses HTML string to DOM nodes.
2340
- *
2341
- * @param {string} html - HTML markup.
2342
- * @return {NodeList}
2343
- */
2344
- function domparser$1(html) {
2345
- var firstTagName;
2346
- var match = html.match(FIRST_TAG_REGEX);
2347
-
2348
- if (match && match[1]) {
2349
- firstTagName = match[1].toLowerCase();
2350
- }
2351
-
2352
- var doc;
2353
- var element;
2354
- var elements;
2355
-
2356
- switch (firstTagName) {
2357
- case HTML:
2358
- doc = parseFromString(html);
2359
-
2360
- // the created document may come with filler head/body elements,
2361
- // so make sure to remove them if they don't actually exist
2362
- if (!HEAD_TAG_REGEX.test(html)) {
2363
- element = doc.getElementsByTagName(HEAD)[0];
2364
- if (element) {
2365
- element.parentNode.removeChild(element);
2366
- }
2367
- }
2368
-
2369
- if (!BODY_TAG_REGEX.test(html)) {
2370
- element = doc.getElementsByTagName(BODY)[0];
2371
- if (element) {
2372
- element.parentNode.removeChild(element);
2373
- }
2374
- }
2375
-
2376
- return doc.getElementsByTagName(HTML);
2377
-
2378
- case HEAD:
2379
- case BODY:
2380
- elements = parseFromDocument(html).getElementsByTagName(firstTagName);
2381
-
2382
- // if there's a sibling element, then return both elements
2383
- if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
2384
- return elements[0].parentNode.childNodes;
2385
- }
2386
- return elements;
2387
-
2388
- // low-level tag or text
2389
- default:
2390
- if (parseFromTemplate) {
2391
- return parseFromTemplate(html);
2392
- }
2393
-
2394
- return parseFromDocument(html, BODY).getElementsByTagName(BODY)[0]
2395
- .childNodes;
2396
- }
2397
- }
2398
-
2399
- var domparser_1 = domparser$1;
2400
-
2401
2403
  var domparser = domparser_1;
2402
2404
  var formatDOM = utilities.formatDOM;
2403
2405
 
@@ -2431,6 +2433,193 @@
2431
2433
 
2432
2434
  var htmlToDom = HTMLDOMParser;
2433
2435
 
2436
+ var lib = {};
2437
+
2438
+ var hasRequiredLib;
2439
+
2440
+ function requireLib () {
2441
+ if (hasRequiredLib) return lib;
2442
+ hasRequiredLib = 1;
2443
+ (function (exports) {
2444
+ var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2445
+ if (k2 === undefined) k2 = k;
2446
+ var desc = Object.getOwnPropertyDescriptor(m, k);
2447
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
2448
+ desc = { enumerable: true, get: function() { return m[k]; } };
2449
+ }
2450
+ Object.defineProperty(o, k2, desc);
2451
+ }) : (function(o, m, k, k2) {
2452
+ if (k2 === undefined) k2 = k;
2453
+ o[k2] = m[k];
2454
+ }));
2455
+ var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
2456
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
2457
+ };
2458
+ Object.defineProperty(exports, "__esModule", { value: true });
2459
+ exports.DomHandler = void 0;
2460
+ var domelementtype_1 = requireLib$1();
2461
+ var node_1 = requireNode();
2462
+ __exportStar(requireNode(), exports);
2463
+ var reWhitespace = /\s+/g;
2464
+ // Default options
2465
+ var defaultOpts = {
2466
+ normalizeWhitespace: false,
2467
+ withStartIndices: false,
2468
+ withEndIndices: false,
2469
+ xmlMode: false,
2470
+ };
2471
+ var DomHandler = /** @class */ (function () {
2472
+ /**
2473
+ * @param callback Called once parsing has completed.
2474
+ * @param options Settings for the handler.
2475
+ * @param elementCB Callback whenever a tag is closed.
2476
+ */
2477
+ function DomHandler(callback, options, elementCB) {
2478
+ /** The elements of the DOM */
2479
+ this.dom = [];
2480
+ /** The root element for the DOM */
2481
+ this.root = new node_1.Document(this.dom);
2482
+ /** Indicated whether parsing has been completed. */
2483
+ this.done = false;
2484
+ /** Stack of open tags. */
2485
+ this.tagStack = [this.root];
2486
+ /** A data node that is still being written to. */
2487
+ this.lastNode = null;
2488
+ /** Reference to the parser instance. Used for location information. */
2489
+ this.parser = null;
2490
+ // Make it possible to skip arguments, for backwards-compatibility
2491
+ if (typeof options === "function") {
2492
+ elementCB = options;
2493
+ options = defaultOpts;
2494
+ }
2495
+ if (typeof callback === "object") {
2496
+ options = callback;
2497
+ callback = undefined;
2498
+ }
2499
+ this.callback = callback !== null && callback !== void 0 ? callback : null;
2500
+ this.options = options !== null && options !== void 0 ? options : defaultOpts;
2501
+ this.elementCB = elementCB !== null && elementCB !== void 0 ? elementCB : null;
2502
+ }
2503
+ DomHandler.prototype.onparserinit = function (parser) {
2504
+ this.parser = parser;
2505
+ };
2506
+ // Resets the handler back to starting state
2507
+ DomHandler.prototype.onreset = function () {
2508
+ this.dom = [];
2509
+ this.root = new node_1.Document(this.dom);
2510
+ this.done = false;
2511
+ this.tagStack = [this.root];
2512
+ this.lastNode = null;
2513
+ this.parser = null;
2514
+ };
2515
+ // Signals the handler that parsing is done
2516
+ DomHandler.prototype.onend = function () {
2517
+ if (this.done)
2518
+ return;
2519
+ this.done = true;
2520
+ this.parser = null;
2521
+ this.handleCallback(null);
2522
+ };
2523
+ DomHandler.prototype.onerror = function (error) {
2524
+ this.handleCallback(error);
2525
+ };
2526
+ DomHandler.prototype.onclosetag = function () {
2527
+ this.lastNode = null;
2528
+ var elem = this.tagStack.pop();
2529
+ if (this.options.withEndIndices) {
2530
+ elem.endIndex = this.parser.endIndex;
2531
+ }
2532
+ if (this.elementCB)
2533
+ this.elementCB(elem);
2534
+ };
2535
+ DomHandler.prototype.onopentag = function (name, attribs) {
2536
+ var type = this.options.xmlMode ? domelementtype_1.ElementType.Tag : undefined;
2537
+ var element = new node_1.Element(name, attribs, undefined, type);
2538
+ this.addNode(element);
2539
+ this.tagStack.push(element);
2540
+ };
2541
+ DomHandler.prototype.ontext = function (data) {
2542
+ var normalizeWhitespace = this.options.normalizeWhitespace;
2543
+ var lastNode = this.lastNode;
2544
+ if (lastNode && lastNode.type === domelementtype_1.ElementType.Text) {
2545
+ if (normalizeWhitespace) {
2546
+ lastNode.data = (lastNode.data + data).replace(reWhitespace, " ");
2547
+ }
2548
+ else {
2549
+ lastNode.data += data;
2550
+ }
2551
+ if (this.options.withEndIndices) {
2552
+ lastNode.endIndex = this.parser.endIndex;
2553
+ }
2554
+ }
2555
+ else {
2556
+ if (normalizeWhitespace) {
2557
+ data = data.replace(reWhitespace, " ");
2558
+ }
2559
+ var node = new node_1.Text(data);
2560
+ this.addNode(node);
2561
+ this.lastNode = node;
2562
+ }
2563
+ };
2564
+ DomHandler.prototype.oncomment = function (data) {
2565
+ if (this.lastNode && this.lastNode.type === domelementtype_1.ElementType.Comment) {
2566
+ this.lastNode.data += data;
2567
+ return;
2568
+ }
2569
+ var node = new node_1.Comment(data);
2570
+ this.addNode(node);
2571
+ this.lastNode = node;
2572
+ };
2573
+ DomHandler.prototype.oncommentend = function () {
2574
+ this.lastNode = null;
2575
+ };
2576
+ DomHandler.prototype.oncdatastart = function () {
2577
+ var text = new node_1.Text("");
2578
+ var node = new node_1.NodeWithChildren(domelementtype_1.ElementType.CDATA, [text]);
2579
+ this.addNode(node);
2580
+ text.parent = node;
2581
+ this.lastNode = text;
2582
+ };
2583
+ DomHandler.prototype.oncdataend = function () {
2584
+ this.lastNode = null;
2585
+ };
2586
+ DomHandler.prototype.onprocessinginstruction = function (name, data) {
2587
+ var node = new node_1.ProcessingInstruction(name, data);
2588
+ this.addNode(node);
2589
+ };
2590
+ DomHandler.prototype.handleCallback = function (error) {
2591
+ if (typeof this.callback === "function") {
2592
+ this.callback(error, this.dom);
2593
+ }
2594
+ else if (error) {
2595
+ throw error;
2596
+ }
2597
+ };
2598
+ DomHandler.prototype.addNode = function (node) {
2599
+ var parent = this.tagStack[this.tagStack.length - 1];
2600
+ var previousSibling = parent.children[parent.children.length - 1];
2601
+ if (this.options.withStartIndices) {
2602
+ node.startIndex = this.parser.startIndex;
2603
+ }
2604
+ if (this.options.withEndIndices) {
2605
+ node.endIndex = this.parser.endIndex;
2606
+ }
2607
+ parent.children.push(node);
2608
+ if (previousSibling) {
2609
+ node.prev = previousSibling;
2610
+ previousSibling.next = node;
2611
+ }
2612
+ node.parent = parent;
2613
+ this.lastNode = null;
2614
+ };
2615
+ return DomHandler;
2616
+ }());
2617
+ exports.DomHandler = DomHandler;
2618
+ exports.default = DomHandler;
2619
+ } (lib));
2620
+ return lib;
2621
+ }
2622
+
2434
2623
  var domToReact = domToReact_1;
2435
2624
  var attributesToProps = attributesToProps$2;
2436
2625
  var htmlToDOM = htmlToDom;
@@ -2445,12 +2634,12 @@
2445
2634
  /**
2446
2635
  * Converts HTML string to React elements.
2447
2636
  *
2448
- * @param {String} html - HTML string.
2449
- * @param {Object} [options] - Parser options.
2450
- * @param {Object} [options.htmlparser2] - htmlparser2 options.
2451
- * @param {Object} [options.library] - Library for React, Preact, etc.
2452
- * @param {Function} [options.replace] - Replace method.
2453
- * @return {JSX.Element|JSX.Element[]|String} - React element(s), empty array, or string.
2637
+ * @param {string} html - HTML string.
2638
+ * @param {object} [options] - Parser options.
2639
+ * @param {object} [options.htmlparser2] - htmlparser2 options.
2640
+ * @param {object} [options.library] - Library for React, Preact, etc.
2641
+ * @param {Function} [options.replace] - Replace method.
2642
+ * @returns {JSX.Element|JSX.Element[]|string} - React element(s), empty array, or string.
2454
2643
  */
2455
2644
  function HTMLReactParser(html, options) {
2456
2645
  if (typeof html !== 'string') {
@@ -2469,15 +2658,13 @@
2469
2658
  HTMLReactParser.domToReact = domToReact;
2470
2659
  HTMLReactParser.htmlToDOM = htmlToDOM;
2471
2660
  HTMLReactParser.attributesToProps = attributesToProps;
2472
- HTMLReactParser.Element = node.Element;
2661
+ HTMLReactParser.Element = requireLib().Element;
2473
2662
 
2474
2663
  // support CommonJS and ES Modules
2475
- htmlReactParser$1.exports = HTMLReactParser;
2476
- htmlReactParser$1.exports.default = HTMLReactParser;
2477
-
2478
- var htmlReactParser = htmlReactParser$1.exports;
2664
+ htmlReactParser.exports = HTMLReactParser;
2665
+ htmlReactParser.exports.default = HTMLReactParser;
2479
2666
 
2480
- return htmlReactParser;
2667
+ return htmlReactParser.exports;
2481
2668
 
2482
2669
  }));
2483
2670
  //# sourceMappingURL=html-react-parser.js.map