html-react-parser 1.4.13 → 3.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.
- package/README.md +11 -1
- package/dist/html-react-parser.js +490 -485
- package/dist/html-react-parser.js.map +1 -1
- package/dist/html-react-parser.min.js +1 -1
- package/dist/html-react-parser.min.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +6 -6
- package/lib/attributes-to-props.d.ts +2 -2
- package/lib/attributes-to-props.js +3 -3
- package/lib/dom-to-react.d.ts +3 -3
- package/lib/dom-to-react.js +7 -7
- package/lib/utilities.js +7 -7
- package/package.json +20 -20
|
@@ -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 (
|
|
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);
|
|
@@ -1171,9 +1175,9 @@
|
|
|
1171
1175
|
if (!style || typeof style !== 'string') {
|
|
1172
1176
|
return output;
|
|
1173
1177
|
}
|
|
1174
|
-
style_to_object_1["default"](style, function (property, value) {
|
|
1178
|
+
(0, style_to_object_1["default"])(style, function (property, value) {
|
|
1175
1179
|
if (property && value) {
|
|
1176
|
-
output[utilities_1.camelCase(property, options)] = value;
|
|
1180
|
+
output[(0, utilities_1.camelCase)(property, options)] = value;
|
|
1177
1181
|
}
|
|
1178
1182
|
});
|
|
1179
1183
|
return output;
|
|
@@ -1187,9 +1191,9 @@
|
|
|
1187
1191
|
/**
|
|
1188
1192
|
* Swap key with value in an object.
|
|
1189
1193
|
*
|
|
1190
|
-
* @param
|
|
1191
|
-
* @param
|
|
1192
|
-
* @
|
|
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 {
|
|
1231
|
-
* @
|
|
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
|
|
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);
|
|
@@ -1318,8 +1322,8 @@
|
|
|
1318
1322
|
/**
|
|
1319
1323
|
* Converts HTML/SVG DOM attributes to React props.
|
|
1320
1324
|
*
|
|
1321
|
-
* @param
|
|
1322
|
-
* @
|
|
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
|
-
* @
|
|
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
|
|
1413
|
-
* @param
|
|
1414
|
-
* @param
|
|
1415
|
-
* @param
|
|
1416
|
-
* @
|
|
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
|
|
1530
|
-
* @
|
|
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,58 +1543,174 @@
|
|
|
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
|
+
|
|
1542
1567
|
/**
|
|
1543
|
-
*
|
|
1568
|
+
* DOMParser (performance: slow).
|
|
1544
1569
|
*
|
|
1545
|
-
* @see
|
|
1570
|
+
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
|
|
1546
1571
|
*/
|
|
1572
|
+
if (typeof window.DOMParser === 'function') {
|
|
1573
|
+
var domParser = new window.DOMParser();
|
|
1574
|
+
var mimeType = 'text/html';
|
|
1547
1575
|
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
'feDropShadow',
|
|
1560
|
-
'feFlood',
|
|
1561
|
-
'feFuncA',
|
|
1562
|
-
'feFuncB',
|
|
1563
|
-
'feFuncG',
|
|
1564
|
-
'feFuncR',
|
|
1565
|
-
'feGaussainBlur',
|
|
1566
|
-
'feImage',
|
|
1567
|
-
'feMerge',
|
|
1568
|
-
'feMergeNode',
|
|
1569
|
-
'feMorphology',
|
|
1570
|
-
'feOffset',
|
|
1571
|
-
'fePointLight',
|
|
1572
|
-
'feSpecularLighting',
|
|
1573
|
-
'feSpotLight',
|
|
1574
|
-
'feTile',
|
|
1575
|
-
'feTurbulence',
|
|
1576
|
-
'foreignObject',
|
|
1577
|
-
'linearGradient',
|
|
1578
|
-
'radialGradient',
|
|
1579
|
-
'textPath'
|
|
1580
|
-
];
|
|
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
|
+
}
|
|
1581
1587
|
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
};
|
|
1588
|
+
return domParser.parseFromString(html, mimeType);
|
|
1589
|
+
};
|
|
1585
1590
|
|
|
1586
|
-
|
|
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
|
+
|
|
1704
|
+
var utilities = {};
|
|
1587
1705
|
|
|
1588
1706
|
var lib$1 = {};
|
|
1589
1707
|
|
|
1708
|
+
var lib = {};
|
|
1709
|
+
|
|
1590
1710
|
var hasRequiredLib$1;
|
|
1591
1711
|
|
|
1592
1712
|
function requireLib$1 () {
|
|
1593
|
-
if (hasRequiredLib$1) return lib
|
|
1713
|
+
if (hasRequiredLib$1) return lib;
|
|
1594
1714
|
hasRequiredLib$1 = 1;
|
|
1595
1715
|
(function (exports) {
|
|
1596
1716
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1647,10 +1767,12 @@
|
|
|
1647
1767
|
exports.CDATA = ElementType.CDATA;
|
|
1648
1768
|
/** Type for <!doctype ...> */
|
|
1649
1769
|
exports.Doctype = ElementType.Doctype;
|
|
1650
|
-
} (lib
|
|
1651
|
-
return lib
|
|
1770
|
+
} (lib));
|
|
1771
|
+
return lib;
|
|
1652
1772
|
}
|
|
1653
1773
|
|
|
1774
|
+
var node = {};
|
|
1775
|
+
|
|
1654
1776
|
var hasRequiredNode;
|
|
1655
1777
|
|
|
1656
1778
|
function requireNode () {
|
|
@@ -1683,29 +1805,14 @@
|
|
|
1683
1805
|
return __assign.apply(this, arguments);
|
|
1684
1806
|
};
|
|
1685
1807
|
Object.defineProperty(node, "__esModule", { value: true });
|
|
1686
|
-
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;
|
|
1808
|
+
node.cloneNode = node.hasChildren = node.isDocument = node.isDirective = node.isComment = node.isText = node.isCDATA = node.isTag = node.Element = node.Document = node.CDATA = node.NodeWithChildren = node.ProcessingInstruction = node.Comment = node.Text = node.DataNode = node.Node = void 0;
|
|
1687
1809
|
var domelementtype_1 = requireLib$1();
|
|
1688
|
-
var nodeTypes = new Map([
|
|
1689
|
-
[domelementtype_1.ElementType.Tag, 1],
|
|
1690
|
-
[domelementtype_1.ElementType.Script, 1],
|
|
1691
|
-
[domelementtype_1.ElementType.Style, 1],
|
|
1692
|
-
[domelementtype_1.ElementType.Directive, 1],
|
|
1693
|
-
[domelementtype_1.ElementType.Text, 3],
|
|
1694
|
-
[domelementtype_1.ElementType.CDATA, 4],
|
|
1695
|
-
[domelementtype_1.ElementType.Comment, 8],
|
|
1696
|
-
[domelementtype_1.ElementType.Root, 9],
|
|
1697
|
-
]);
|
|
1698
1810
|
/**
|
|
1699
1811
|
* This object will be used as the prototype for Nodes when creating a
|
|
1700
1812
|
* DOM-Level-1-compliant structure.
|
|
1701
1813
|
*/
|
|
1702
1814
|
var Node = /** @class */ (function () {
|
|
1703
|
-
|
|
1704
|
-
*
|
|
1705
|
-
* @param type The type of the node.
|
|
1706
|
-
*/
|
|
1707
|
-
function Node(type) {
|
|
1708
|
-
this.type = type;
|
|
1815
|
+
function Node() {
|
|
1709
1816
|
/** Parent of the node */
|
|
1710
1817
|
this.parent = null;
|
|
1711
1818
|
/** Previous sibling */
|
|
@@ -1717,19 +1824,6 @@
|
|
|
1717
1824
|
/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
|
|
1718
1825
|
this.endIndex = null;
|
|
1719
1826
|
}
|
|
1720
|
-
Object.defineProperty(Node.prototype, "nodeType", {
|
|
1721
|
-
// Read-only aliases
|
|
1722
|
-
/**
|
|
1723
|
-
* [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible
|
|
1724
|
-
* node {@link type}.
|
|
1725
|
-
*/
|
|
1726
|
-
get: function () {
|
|
1727
|
-
var _a;
|
|
1728
|
-
return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
|
|
1729
|
-
},
|
|
1730
|
-
enumerable: false,
|
|
1731
|
-
configurable: true
|
|
1732
|
-
});
|
|
1733
1827
|
Object.defineProperty(Node.prototype, "parentNode", {
|
|
1734
1828
|
// Read-write aliases for properties
|
|
1735
1829
|
/**
|
|
@@ -1792,11 +1886,10 @@
|
|
|
1792
1886
|
var DataNode = /** @class */ (function (_super) {
|
|
1793
1887
|
__extends(DataNode, _super);
|
|
1794
1888
|
/**
|
|
1795
|
-
* @param type The type of the node
|
|
1796
1889
|
* @param data The content of the data node
|
|
1797
1890
|
*/
|
|
1798
|
-
function DataNode(
|
|
1799
|
-
var _this = _super.call(this
|
|
1891
|
+
function DataNode(data) {
|
|
1892
|
+
var _this = _super.call(this) || this;
|
|
1800
1893
|
_this.data = data;
|
|
1801
1894
|
return _this;
|
|
1802
1895
|
}
|
|
@@ -1822,9 +1915,18 @@
|
|
|
1822
1915
|
*/
|
|
1823
1916
|
var Text = /** @class */ (function (_super) {
|
|
1824
1917
|
__extends(Text, _super);
|
|
1825
|
-
function Text(
|
|
1826
|
-
|
|
1918
|
+
function Text() {
|
|
1919
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1920
|
+
_this.type = domelementtype_1.ElementType.Text;
|
|
1921
|
+
return _this;
|
|
1827
1922
|
}
|
|
1923
|
+
Object.defineProperty(Text.prototype, "nodeType", {
|
|
1924
|
+
get: function () {
|
|
1925
|
+
return 3;
|
|
1926
|
+
},
|
|
1927
|
+
enumerable: false,
|
|
1928
|
+
configurable: true
|
|
1929
|
+
});
|
|
1828
1930
|
return Text;
|
|
1829
1931
|
}(DataNode));
|
|
1830
1932
|
node.Text = Text;
|
|
@@ -1833,9 +1935,18 @@
|
|
|
1833
1935
|
*/
|
|
1834
1936
|
var Comment = /** @class */ (function (_super) {
|
|
1835
1937
|
__extends(Comment, _super);
|
|
1836
|
-
function Comment(
|
|
1837
|
-
|
|
1938
|
+
function Comment() {
|
|
1939
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1940
|
+
_this.type = domelementtype_1.ElementType.Comment;
|
|
1941
|
+
return _this;
|
|
1838
1942
|
}
|
|
1943
|
+
Object.defineProperty(Comment.prototype, "nodeType", {
|
|
1944
|
+
get: function () {
|
|
1945
|
+
return 8;
|
|
1946
|
+
},
|
|
1947
|
+
enumerable: false,
|
|
1948
|
+
configurable: true
|
|
1949
|
+
});
|
|
1839
1950
|
return Comment;
|
|
1840
1951
|
}(DataNode));
|
|
1841
1952
|
node.Comment = Comment;
|
|
@@ -1845,10 +1956,18 @@
|
|
|
1845
1956
|
var ProcessingInstruction = /** @class */ (function (_super) {
|
|
1846
1957
|
__extends(ProcessingInstruction, _super);
|
|
1847
1958
|
function ProcessingInstruction(name, data) {
|
|
1848
|
-
var _this = _super.call(this,
|
|
1959
|
+
var _this = _super.call(this, data) || this;
|
|
1849
1960
|
_this.name = name;
|
|
1961
|
+
_this.type = domelementtype_1.ElementType.Directive;
|
|
1850
1962
|
return _this;
|
|
1851
1963
|
}
|
|
1964
|
+
Object.defineProperty(ProcessingInstruction.prototype, "nodeType", {
|
|
1965
|
+
get: function () {
|
|
1966
|
+
return 1;
|
|
1967
|
+
},
|
|
1968
|
+
enumerable: false,
|
|
1969
|
+
configurable: true
|
|
1970
|
+
});
|
|
1852
1971
|
return ProcessingInstruction;
|
|
1853
1972
|
}(DataNode));
|
|
1854
1973
|
node.ProcessingInstruction = ProcessingInstruction;
|
|
@@ -1858,11 +1977,10 @@
|
|
|
1858
1977
|
var NodeWithChildren = /** @class */ (function (_super) {
|
|
1859
1978
|
__extends(NodeWithChildren, _super);
|
|
1860
1979
|
/**
|
|
1861
|
-
* @param type Type of the node.
|
|
1862
1980
|
* @param children Children of the node. Only certain node types can have children.
|
|
1863
1981
|
*/
|
|
1864
|
-
function NodeWithChildren(
|
|
1865
|
-
var _this = _super.call(this
|
|
1982
|
+
function NodeWithChildren(children) {
|
|
1983
|
+
var _this = _super.call(this) || this;
|
|
1866
1984
|
_this.children = children;
|
|
1867
1985
|
return _this;
|
|
1868
1986
|
}
|
|
@@ -1903,14 +2021,40 @@
|
|
|
1903
2021
|
return NodeWithChildren;
|
|
1904
2022
|
}(Node));
|
|
1905
2023
|
node.NodeWithChildren = NodeWithChildren;
|
|
2024
|
+
var CDATA = /** @class */ (function (_super) {
|
|
2025
|
+
__extends(CDATA, _super);
|
|
2026
|
+
function CDATA() {
|
|
2027
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2028
|
+
_this.type = domelementtype_1.ElementType.CDATA;
|
|
2029
|
+
return _this;
|
|
2030
|
+
}
|
|
2031
|
+
Object.defineProperty(CDATA.prototype, "nodeType", {
|
|
2032
|
+
get: function () {
|
|
2033
|
+
return 4;
|
|
2034
|
+
},
|
|
2035
|
+
enumerable: false,
|
|
2036
|
+
configurable: true
|
|
2037
|
+
});
|
|
2038
|
+
return CDATA;
|
|
2039
|
+
}(NodeWithChildren));
|
|
2040
|
+
node.CDATA = CDATA;
|
|
1906
2041
|
/**
|
|
1907
2042
|
* The root node of the document.
|
|
1908
2043
|
*/
|
|
1909
2044
|
var Document = /** @class */ (function (_super) {
|
|
1910
2045
|
__extends(Document, _super);
|
|
1911
|
-
function Document(
|
|
1912
|
-
|
|
2046
|
+
function Document() {
|
|
2047
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2048
|
+
_this.type = domelementtype_1.ElementType.Root;
|
|
2049
|
+
return _this;
|
|
1913
2050
|
}
|
|
2051
|
+
Object.defineProperty(Document.prototype, "nodeType", {
|
|
2052
|
+
get: function () {
|
|
2053
|
+
return 9;
|
|
2054
|
+
},
|
|
2055
|
+
enumerable: false,
|
|
2056
|
+
configurable: true
|
|
2057
|
+
});
|
|
1914
2058
|
return Document;
|
|
1915
2059
|
}(NodeWithChildren));
|
|
1916
2060
|
node.Document = Document;
|
|
@@ -1931,11 +2075,19 @@
|
|
|
1931
2075
|
: name === "style"
|
|
1932
2076
|
? domelementtype_1.ElementType.Style
|
|
1933
2077
|
: domelementtype_1.ElementType.Tag; }
|
|
1934
|
-
var _this = _super.call(this,
|
|
2078
|
+
var _this = _super.call(this, children) || this;
|
|
1935
2079
|
_this.name = name;
|
|
1936
2080
|
_this.attribs = attribs;
|
|
2081
|
+
_this.type = type;
|
|
1937
2082
|
return _this;
|
|
1938
2083
|
}
|
|
2084
|
+
Object.defineProperty(Element.prototype, "nodeType", {
|
|
2085
|
+
get: function () {
|
|
2086
|
+
return 1;
|
|
2087
|
+
},
|
|
2088
|
+
enumerable: false,
|
|
2089
|
+
configurable: true
|
|
2090
|
+
});
|
|
1939
2091
|
Object.defineProperty(Element.prototype, "tagName", {
|
|
1940
2092
|
// DOM Level 1 aliases
|
|
1941
2093
|
/**
|
|
@@ -2020,7 +2172,7 @@
|
|
|
2020
2172
|
node.isDocument = isDocument;
|
|
2021
2173
|
/**
|
|
2022
2174
|
* @param node Node to check.
|
|
2023
|
-
* @returns `true` if the node
|
|
2175
|
+
* @returns `true` if the node has children, `false` otherwise.
|
|
2024
2176
|
*/
|
|
2025
2177
|
function hasChildren(node) {
|
|
2026
2178
|
return Object.prototype.hasOwnProperty.call(node, "children");
|
|
@@ -2058,7 +2210,7 @@
|
|
|
2058
2210
|
}
|
|
2059
2211
|
else if (isCDATA(node)) {
|
|
2060
2212
|
var children = recursive ? cloneChildren(node.children) : [];
|
|
2061
|
-
var clone_2 = new
|
|
2213
|
+
var clone_2 = new CDATA(children);
|
|
2062
2214
|
children.forEach(function (child) { return (child.parent = clone_2); });
|
|
2063
2215
|
result = clone_2;
|
|
2064
2216
|
}
|
|
@@ -2102,355 +2254,10 @@
|
|
|
2102
2254
|
return node;
|
|
2103
2255
|
}
|
|
2104
2256
|
|
|
2105
|
-
var
|
|
2106
|
-
var domhandler = requireNode();
|
|
2107
|
-
|
|
2108
|
-
var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
|
|
2109
|
-
|
|
2110
|
-
var Comment = domhandler.Comment;
|
|
2111
|
-
var Element = domhandler.Element;
|
|
2112
|
-
var ProcessingInstruction = domhandler.ProcessingInstruction;
|
|
2113
|
-
var Text = domhandler.Text;
|
|
2114
|
-
|
|
2115
|
-
var caseSensitiveTagNamesMap = {};
|
|
2116
|
-
var tagName;
|
|
2117
|
-
|
|
2118
|
-
for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
|
|
2119
|
-
tagName = CASE_SENSITIVE_TAG_NAMES[i];
|
|
2120
|
-
caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2123
|
-
/**
|
|
2124
|
-
* Gets case-sensitive tag name.
|
|
2125
|
-
*
|
|
2126
|
-
* @param {string} tagName - Tag name in lowercase.
|
|
2127
|
-
* @return {string|undefined} - Case-sensitive tag name.
|
|
2128
|
-
*/
|
|
2129
|
-
function getCaseSensitiveTagName(tagName) {
|
|
2130
|
-
return caseSensitiveTagNamesMap[tagName];
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
/**
|
|
2134
|
-
* Formats DOM attributes to a hash map.
|
|
2135
|
-
*
|
|
2136
|
-
* @param {NamedNodeMap} attributes - List of attributes.
|
|
2137
|
-
* @return {object} - Map of attribute name to value.
|
|
2138
|
-
*/
|
|
2139
|
-
function formatAttributes(attributes) {
|
|
2140
|
-
var result = {};
|
|
2141
|
-
var attribute;
|
|
2142
|
-
// `NamedNodeMap` is array-like
|
|
2143
|
-
for (var i = 0, len = attributes.length; i < len; i++) {
|
|
2144
|
-
attribute = attributes[i];
|
|
2145
|
-
result[attribute.name] = attribute.value;
|
|
2146
|
-
}
|
|
2147
|
-
return result;
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
/**
|
|
2151
|
-
* Corrects the tag name if it is case-sensitive (SVG).
|
|
2152
|
-
* Otherwise, returns the lowercase tag name (HTML).
|
|
2153
|
-
*
|
|
2154
|
-
* @param {string} tagName - Lowercase tag name.
|
|
2155
|
-
* @return {string} - Formatted tag name.
|
|
2156
|
-
*/
|
|
2157
|
-
function formatTagName(tagName) {
|
|
2158
|
-
tagName = tagName.toLowerCase();
|
|
2159
|
-
var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
|
|
2160
|
-
if (caseSensitiveTagName) {
|
|
2161
|
-
return caseSensitiveTagName;
|
|
2162
|
-
}
|
|
2163
|
-
return tagName;
|
|
2164
|
-
}
|
|
2165
|
-
|
|
2166
|
-
/**
|
|
2167
|
-
* Transforms DOM nodes to `domhandler` nodes.
|
|
2168
|
-
*
|
|
2169
|
-
* @param {NodeList} nodes - DOM nodes.
|
|
2170
|
-
* @param {Element|null} [parent=null] - Parent node.
|
|
2171
|
-
* @param {string} [directive] - Directive.
|
|
2172
|
-
* @return {Array<Comment|Element|ProcessingInstruction|Text>}
|
|
2173
|
-
*/
|
|
2174
|
-
function formatDOM$1(nodes, parent, directive) {
|
|
2175
|
-
parent = parent || null;
|
|
2176
|
-
var result = [];
|
|
2177
|
-
|
|
2178
|
-
for (var index = 0, len = nodes.length; index < len; index++) {
|
|
2179
|
-
var node = nodes[index];
|
|
2180
|
-
var current;
|
|
2181
|
-
|
|
2182
|
-
// set the node data given the type
|
|
2183
|
-
switch (node.nodeType) {
|
|
2184
|
-
case 1:
|
|
2185
|
-
// script, style, or tag
|
|
2186
|
-
current = new Element(
|
|
2187
|
-
formatTagName(node.nodeName),
|
|
2188
|
-
formatAttributes(node.attributes)
|
|
2189
|
-
);
|
|
2190
|
-
current.children = formatDOM$1(node.childNodes, current);
|
|
2191
|
-
break;
|
|
2192
|
-
|
|
2193
|
-
case 3:
|
|
2194
|
-
current = new Text(node.nodeValue);
|
|
2195
|
-
break;
|
|
2196
|
-
|
|
2197
|
-
case 8:
|
|
2198
|
-
current = new Comment(node.nodeValue);
|
|
2199
|
-
break;
|
|
2200
|
-
|
|
2201
|
-
default:
|
|
2202
|
-
continue;
|
|
2203
|
-
}
|
|
2204
|
-
|
|
2205
|
-
// set previous node next
|
|
2206
|
-
var prev = result[index - 1] || null;
|
|
2207
|
-
if (prev) {
|
|
2208
|
-
prev.next = current;
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
// set properties for current node
|
|
2212
|
-
current.parent = parent;
|
|
2213
|
-
current.prev = prev;
|
|
2214
|
-
current.next = null;
|
|
2215
|
-
|
|
2216
|
-
result.push(current);
|
|
2217
|
-
}
|
|
2218
|
-
|
|
2219
|
-
if (directive) {
|
|
2220
|
-
current = new ProcessingInstruction(
|
|
2221
|
-
directive.substring(0, directive.indexOf(' ')).toLowerCase(),
|
|
2222
|
-
directive
|
|
2223
|
-
);
|
|
2224
|
-
current.next = result[0] || null;
|
|
2225
|
-
current.parent = parent;
|
|
2226
|
-
result.unshift(current);
|
|
2227
|
-
|
|
2228
|
-
if (result[1]) {
|
|
2229
|
-
result[1].prev = result[0];
|
|
2230
|
-
}
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
return result;
|
|
2234
|
-
}
|
|
2235
|
-
|
|
2236
|
-
/**
|
|
2237
|
-
* Detects if browser is Internet Explorer.
|
|
2238
|
-
*
|
|
2239
|
-
* @return {boolean} - Whether IE is detected.
|
|
2240
|
-
*/
|
|
2241
|
-
function isIE$1() {
|
|
2242
|
-
return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
|
|
2243
|
-
}
|
|
2244
|
-
|
|
2245
|
-
var utilities = {
|
|
2246
|
-
formatAttributes: formatAttributes,
|
|
2247
|
-
formatDOM: formatDOM$1,
|
|
2248
|
-
isIE: isIE$1
|
|
2249
|
-
};
|
|
2250
|
-
|
|
2251
|
-
// constants
|
|
2252
|
-
var HTML = 'html';
|
|
2253
|
-
var HEAD = 'head';
|
|
2254
|
-
var BODY = 'body';
|
|
2255
|
-
var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
|
|
2256
|
-
var HEAD_TAG_REGEX = /<head.*>/i;
|
|
2257
|
-
var BODY_TAG_REGEX = /<body.*>/i;
|
|
2258
|
-
|
|
2259
|
-
// falls back to `parseFromString` if `createHTMLDocument` cannot be used
|
|
2260
|
-
var parseFromDocument = function () {
|
|
2261
|
-
throw new Error(
|
|
2262
|
-
'This browser does not support `document.implementation.createHTMLDocument`'
|
|
2263
|
-
);
|
|
2264
|
-
};
|
|
2265
|
-
|
|
2266
|
-
var parseFromString = function () {
|
|
2267
|
-
throw new Error(
|
|
2268
|
-
'This browser does not support `DOMParser.prototype.parseFromString`'
|
|
2269
|
-
);
|
|
2270
|
-
};
|
|
2271
|
-
|
|
2272
|
-
/**
|
|
2273
|
-
* DOMParser (performance: slow).
|
|
2274
|
-
*
|
|
2275
|
-
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
|
|
2276
|
-
*/
|
|
2277
|
-
if (typeof window.DOMParser === 'function') {
|
|
2278
|
-
var domParser = new window.DOMParser();
|
|
2279
|
-
var mimeType = 'text/html';
|
|
2280
|
-
|
|
2281
|
-
/**
|
|
2282
|
-
* Creates an HTML document using `DOMParser.parseFromString`.
|
|
2283
|
-
*
|
|
2284
|
-
* @param {string} html - The HTML string.
|
|
2285
|
-
* @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
|
|
2286
|
-
* @return {HTMLDocument}
|
|
2287
|
-
*/
|
|
2288
|
-
parseFromString = function (html, tagName) {
|
|
2289
|
-
if (tagName) {
|
|
2290
|
-
html = '<' + tagName + '>' + html + '</' + tagName + '>';
|
|
2291
|
-
}
|
|
2292
|
-
|
|
2293
|
-
return domParser.parseFromString(html, mimeType);
|
|
2294
|
-
};
|
|
2295
|
-
|
|
2296
|
-
parseFromDocument = parseFromString;
|
|
2297
|
-
}
|
|
2298
|
-
|
|
2299
|
-
/**
|
|
2300
|
-
* DOMImplementation (performance: fair).
|
|
2301
|
-
*
|
|
2302
|
-
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
|
|
2303
|
-
*/
|
|
2304
|
-
if (document.implementation) {
|
|
2305
|
-
var isIE = utilities.isIE;
|
|
2306
|
-
|
|
2307
|
-
// title parameter is required in IE
|
|
2308
|
-
// https://msdn.microsoft.com/en-us/library/ff975457(v=vs.85).aspx
|
|
2309
|
-
var doc = document.implementation.createHTMLDocument(
|
|
2310
|
-
isIE() ? 'html-dom-parser' : undefined
|
|
2311
|
-
);
|
|
2312
|
-
|
|
2313
|
-
/**
|
|
2314
|
-
* Use HTML document created by `document.implementation.createHTMLDocument`.
|
|
2315
|
-
*
|
|
2316
|
-
* @param {string} html - The HTML string.
|
|
2317
|
-
* @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
|
|
2318
|
-
* @return {HTMLDocument}
|
|
2319
|
-
*/
|
|
2320
|
-
parseFromDocument = function (html, tagName) {
|
|
2321
|
-
if (tagName) {
|
|
2322
|
-
doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
|
|
2323
|
-
return doc;
|
|
2324
|
-
}
|
|
2325
|
-
|
|
2326
|
-
doc.documentElement.innerHTML = html;
|
|
2327
|
-
return doc;
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2330
|
-
|
|
2331
|
-
/**
|
|
2332
|
-
* Template (performance: fast).
|
|
2333
|
-
*
|
|
2334
|
-
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
|
|
2335
|
-
*/
|
|
2336
|
-
var template = document.createElement('template');
|
|
2337
|
-
var parseFromTemplate;
|
|
2338
|
-
|
|
2339
|
-
if (template.content) {
|
|
2340
|
-
/**
|
|
2341
|
-
* Uses a template element (content fragment) to parse HTML.
|
|
2342
|
-
*
|
|
2343
|
-
* @param {string} html - The HTML string.
|
|
2344
|
-
* @return {NodeList}
|
|
2345
|
-
*/
|
|
2346
|
-
parseFromTemplate = function (html) {
|
|
2347
|
-
template.innerHTML = html;
|
|
2348
|
-
return template.content.childNodes;
|
|
2349
|
-
};
|
|
2350
|
-
}
|
|
2351
|
-
|
|
2352
|
-
/**
|
|
2353
|
-
* Parses HTML string to DOM nodes.
|
|
2354
|
-
*
|
|
2355
|
-
* @param {string} html - HTML markup.
|
|
2356
|
-
* @return {NodeList}
|
|
2357
|
-
*/
|
|
2358
|
-
function domparser$1(html) {
|
|
2359
|
-
var firstTagName;
|
|
2360
|
-
var match = html.match(FIRST_TAG_REGEX);
|
|
2361
|
-
|
|
2362
|
-
if (match && match[1]) {
|
|
2363
|
-
firstTagName = match[1].toLowerCase();
|
|
2364
|
-
}
|
|
2365
|
-
|
|
2366
|
-
var doc;
|
|
2367
|
-
var element;
|
|
2368
|
-
var elements;
|
|
2369
|
-
|
|
2370
|
-
switch (firstTagName) {
|
|
2371
|
-
case HTML:
|
|
2372
|
-
doc = parseFromString(html);
|
|
2373
|
-
|
|
2374
|
-
// the created document may come with filler head/body elements,
|
|
2375
|
-
// so make sure to remove them if they don't actually exist
|
|
2376
|
-
if (!HEAD_TAG_REGEX.test(html)) {
|
|
2377
|
-
element = doc.getElementsByTagName(HEAD)[0];
|
|
2378
|
-
if (element) {
|
|
2379
|
-
element.parentNode.removeChild(element);
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
|
|
2383
|
-
if (!BODY_TAG_REGEX.test(html)) {
|
|
2384
|
-
element = doc.getElementsByTagName(BODY)[0];
|
|
2385
|
-
if (element) {
|
|
2386
|
-
element.parentNode.removeChild(element);
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
|
|
2390
|
-
return doc.getElementsByTagName(HTML);
|
|
2391
|
-
|
|
2392
|
-
case HEAD:
|
|
2393
|
-
case BODY:
|
|
2394
|
-
elements = parseFromDocument(html).getElementsByTagName(firstTagName);
|
|
2395
|
-
|
|
2396
|
-
// if there's a sibling element, then return both elements
|
|
2397
|
-
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
|
2398
|
-
return elements[0].parentNode.childNodes;
|
|
2399
|
-
}
|
|
2400
|
-
return elements;
|
|
2401
|
-
|
|
2402
|
-
// low-level tag or text
|
|
2403
|
-
default:
|
|
2404
|
-
if (parseFromTemplate) {
|
|
2405
|
-
return parseFromTemplate(html);
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
|
-
return parseFromDocument(html, BODY).getElementsByTagName(BODY)[0]
|
|
2409
|
-
.childNodes;
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
|
-
|
|
2413
|
-
var domparser_1 = domparser$1;
|
|
2414
|
-
|
|
2415
|
-
var domparser = domparser_1;
|
|
2416
|
-
var formatDOM = utilities.formatDOM;
|
|
2417
|
-
|
|
2418
|
-
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
|
|
2419
|
-
|
|
2420
|
-
/**
|
|
2421
|
-
* Parses HTML string to DOM nodes in browser.
|
|
2422
|
-
*
|
|
2423
|
-
* @param {string} html - HTML markup.
|
|
2424
|
-
* @return {DomElement[]} - DOM elements.
|
|
2425
|
-
*/
|
|
2426
|
-
function HTMLDOMParser(html) {
|
|
2427
|
-
if (typeof html !== 'string') {
|
|
2428
|
-
throw new TypeError('First argument must be a string');
|
|
2429
|
-
}
|
|
2430
|
-
|
|
2431
|
-
if (html === '') {
|
|
2432
|
-
return [];
|
|
2433
|
-
}
|
|
2434
|
-
|
|
2435
|
-
// match directive
|
|
2436
|
-
var match = html.match(DIRECTIVE_REGEX);
|
|
2437
|
-
var directive;
|
|
2438
|
-
|
|
2439
|
-
if (match && match[1]) {
|
|
2440
|
-
directive = match[1];
|
|
2441
|
-
}
|
|
2442
|
-
|
|
2443
|
-
return formatDOM(domparser(html), null, directive);
|
|
2444
|
-
}
|
|
2445
|
-
|
|
2446
|
-
var htmlToDom = HTMLDOMParser;
|
|
2447
|
-
|
|
2448
|
-
var lib = {};
|
|
2449
|
-
|
|
2450
|
-
var hasRequiredLib;
|
|
2257
|
+
var hasRequiredLib;
|
|
2451
2258
|
|
|
2452
2259
|
function requireLib () {
|
|
2453
|
-
if (hasRequiredLib) return lib;
|
|
2260
|
+
if (hasRequiredLib) return lib$1;
|
|
2454
2261
|
hasRequiredLib = 1;
|
|
2455
2262
|
(function (exports) {
|
|
2456
2263
|
var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
@@ -2470,12 +2277,10 @@
|
|
|
2470
2277
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2471
2278
|
exports.DomHandler = void 0;
|
|
2472
2279
|
var domelementtype_1 = requireLib$1();
|
|
2473
|
-
var
|
|
2280
|
+
var node_js_1 = requireNode();
|
|
2474
2281
|
__exportStar(requireNode(), exports);
|
|
2475
|
-
var reWhitespace = /\s+/g;
|
|
2476
2282
|
// Default options
|
|
2477
2283
|
var defaultOpts = {
|
|
2478
|
-
normalizeWhitespace: false,
|
|
2479
2284
|
withStartIndices: false,
|
|
2480
2285
|
withEndIndices: false,
|
|
2481
2286
|
xmlMode: false,
|
|
@@ -2490,7 +2295,7 @@
|
|
|
2490
2295
|
/** The elements of the DOM */
|
|
2491
2296
|
this.dom = [];
|
|
2492
2297
|
/** The root element for the DOM */
|
|
2493
|
-
this.root = new
|
|
2298
|
+
this.root = new node_js_1.Document(this.dom);
|
|
2494
2299
|
/** Indicated whether parsing has been completed. */
|
|
2495
2300
|
this.done = false;
|
|
2496
2301
|
/** Stack of open tags. */
|
|
@@ -2518,7 +2323,7 @@
|
|
|
2518
2323
|
// Resets the handler back to starting state
|
|
2519
2324
|
DomHandler.prototype.onreset = function () {
|
|
2520
2325
|
this.dom = [];
|
|
2521
|
-
this.root = new
|
|
2326
|
+
this.root = new node_js_1.Document(this.dom);
|
|
2522
2327
|
this.done = false;
|
|
2523
2328
|
this.tagStack = [this.root];
|
|
2524
2329
|
this.lastNode = null;
|
|
@@ -2546,29 +2351,20 @@
|
|
|
2546
2351
|
};
|
|
2547
2352
|
DomHandler.prototype.onopentag = function (name, attribs) {
|
|
2548
2353
|
var type = this.options.xmlMode ? domelementtype_1.ElementType.Tag : undefined;
|
|
2549
|
-
var element = new
|
|
2354
|
+
var element = new node_js_1.Element(name, attribs, undefined, type);
|
|
2550
2355
|
this.addNode(element);
|
|
2551
2356
|
this.tagStack.push(element);
|
|
2552
2357
|
};
|
|
2553
2358
|
DomHandler.prototype.ontext = function (data) {
|
|
2554
|
-
var normalizeWhitespace = this.options.normalizeWhitespace;
|
|
2555
2359
|
var lastNode = this.lastNode;
|
|
2556
2360
|
if (lastNode && lastNode.type === domelementtype_1.ElementType.Text) {
|
|
2557
|
-
|
|
2558
|
-
lastNode.data = (lastNode.data + data).replace(reWhitespace, " ");
|
|
2559
|
-
}
|
|
2560
|
-
else {
|
|
2561
|
-
lastNode.data += data;
|
|
2562
|
-
}
|
|
2361
|
+
lastNode.data += data;
|
|
2563
2362
|
if (this.options.withEndIndices) {
|
|
2564
2363
|
lastNode.endIndex = this.parser.endIndex;
|
|
2565
2364
|
}
|
|
2566
2365
|
}
|
|
2567
2366
|
else {
|
|
2568
|
-
|
|
2569
|
-
data = data.replace(reWhitespace, " ");
|
|
2570
|
-
}
|
|
2571
|
-
var node = new node_1.Text(data);
|
|
2367
|
+
var node = new node_js_1.Text(data);
|
|
2572
2368
|
this.addNode(node);
|
|
2573
2369
|
this.lastNode = node;
|
|
2574
2370
|
}
|
|
@@ -2578,7 +2374,7 @@
|
|
|
2578
2374
|
this.lastNode.data += data;
|
|
2579
2375
|
return;
|
|
2580
2376
|
}
|
|
2581
|
-
var node = new
|
|
2377
|
+
var node = new node_js_1.Comment(data);
|
|
2582
2378
|
this.addNode(node);
|
|
2583
2379
|
this.lastNode = node;
|
|
2584
2380
|
};
|
|
@@ -2586,8 +2382,8 @@
|
|
|
2586
2382
|
this.lastNode = null;
|
|
2587
2383
|
};
|
|
2588
2384
|
DomHandler.prototype.oncdatastart = function () {
|
|
2589
|
-
var text = new
|
|
2590
|
-
var node = new
|
|
2385
|
+
var text = new node_js_1.Text("");
|
|
2386
|
+
var node = new node_js_1.CDATA([text]);
|
|
2591
2387
|
this.addNode(node);
|
|
2592
2388
|
text.parent = node;
|
|
2593
2389
|
this.lastNode = text;
|
|
@@ -2596,7 +2392,7 @@
|
|
|
2596
2392
|
this.lastNode = null;
|
|
2597
2393
|
};
|
|
2598
2394
|
DomHandler.prototype.onprocessinginstruction = function (name, data) {
|
|
2599
|
-
var node = new
|
|
2395
|
+
var node = new node_js_1.ProcessingInstruction(name, data);
|
|
2600
2396
|
this.addNode(node);
|
|
2601
2397
|
};
|
|
2602
2398
|
DomHandler.prototype.handleCallback = function (error) {
|
|
@@ -2628,10 +2424,219 @@
|
|
|
2628
2424
|
}());
|
|
2629
2425
|
exports.DomHandler = DomHandler;
|
|
2630
2426
|
exports.default = DomHandler;
|
|
2631
|
-
} (lib));
|
|
2632
|
-
return lib;
|
|
2427
|
+
} (lib$1));
|
|
2428
|
+
return lib$1;
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
var constants$1 = {};
|
|
2432
|
+
|
|
2433
|
+
/**
|
|
2434
|
+
* SVG elements are case-sensitive.
|
|
2435
|
+
*
|
|
2436
|
+
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z}
|
|
2437
|
+
*/
|
|
2438
|
+
|
|
2439
|
+
constants$1.CASE_SENSITIVE_TAG_NAMES = [
|
|
2440
|
+
'animateMotion',
|
|
2441
|
+
'animateTransform',
|
|
2442
|
+
'clipPath',
|
|
2443
|
+
'feBlend',
|
|
2444
|
+
'feColorMatrix',
|
|
2445
|
+
'feComponentTransfer',
|
|
2446
|
+
'feComposite',
|
|
2447
|
+
'feConvolveMatrix',
|
|
2448
|
+
'feDiffuseLighting',
|
|
2449
|
+
'feDisplacementMap',
|
|
2450
|
+
'feDropShadow',
|
|
2451
|
+
'feFlood',
|
|
2452
|
+
'feFuncA',
|
|
2453
|
+
'feFuncB',
|
|
2454
|
+
'feFuncG',
|
|
2455
|
+
'feFuncR',
|
|
2456
|
+
'feGaussainBlur',
|
|
2457
|
+
'feImage',
|
|
2458
|
+
'feMerge',
|
|
2459
|
+
'feMergeNode',
|
|
2460
|
+
'feMorphology',
|
|
2461
|
+
'feOffset',
|
|
2462
|
+
'fePointLight',
|
|
2463
|
+
'feSpecularLighting',
|
|
2464
|
+
'feSpotLight',
|
|
2465
|
+
'feTile',
|
|
2466
|
+
'feTurbulence',
|
|
2467
|
+
'foreignObject',
|
|
2468
|
+
'linearGradient',
|
|
2469
|
+
'radialGradient',
|
|
2470
|
+
'textPath'
|
|
2471
|
+
];
|
|
2472
|
+
|
|
2473
|
+
var domhandler = requireLib();
|
|
2474
|
+
var constants = constants$1;
|
|
2475
|
+
|
|
2476
|
+
var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
|
|
2477
|
+
|
|
2478
|
+
var Comment = domhandler.Comment;
|
|
2479
|
+
var Element = domhandler.Element;
|
|
2480
|
+
var ProcessingInstruction = domhandler.ProcessingInstruction;
|
|
2481
|
+
var Text = domhandler.Text;
|
|
2482
|
+
|
|
2483
|
+
var caseSensitiveTagNamesMap = {};
|
|
2484
|
+
var tagName;
|
|
2485
|
+
|
|
2486
|
+
for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
|
|
2487
|
+
tagName = CASE_SENSITIVE_TAG_NAMES[i];
|
|
2488
|
+
caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
/**
|
|
2492
|
+
* Gets case-sensitive tag name.
|
|
2493
|
+
*
|
|
2494
|
+
* @param {string} tagName - Tag name in lowercase.
|
|
2495
|
+
* @returns {string|undefined} - Case-sensitive tag name.
|
|
2496
|
+
*/
|
|
2497
|
+
function getCaseSensitiveTagName(tagName) {
|
|
2498
|
+
return caseSensitiveTagNamesMap[tagName];
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
/**
|
|
2502
|
+
* Formats DOM attributes to a hash map.
|
|
2503
|
+
*
|
|
2504
|
+
* @param {NamedNodeMap} attributes - List of attributes.
|
|
2505
|
+
* @returns {object} - Map of attribute name to value.
|
|
2506
|
+
*/
|
|
2507
|
+
function formatAttributes(attributes) {
|
|
2508
|
+
var result = {};
|
|
2509
|
+
var attribute;
|
|
2510
|
+
// `NamedNodeMap` is array-like
|
|
2511
|
+
for (var i = 0, len = attributes.length; i < len; i++) {
|
|
2512
|
+
attribute = attributes[i];
|
|
2513
|
+
result[attribute.name] = attribute.value;
|
|
2514
|
+
}
|
|
2515
|
+
return result;
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
/**
|
|
2519
|
+
* Corrects the tag name if it is case-sensitive (SVG).
|
|
2520
|
+
* Otherwise, returns the lowercase tag name (HTML).
|
|
2521
|
+
*
|
|
2522
|
+
* @param {string} tagName - Lowercase tag name.
|
|
2523
|
+
* @returns {string} - Formatted tag name.
|
|
2524
|
+
*/
|
|
2525
|
+
function formatTagName(tagName) {
|
|
2526
|
+
tagName = tagName.toLowerCase();
|
|
2527
|
+
var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
|
|
2528
|
+
if (caseSensitiveTagName) {
|
|
2529
|
+
return caseSensitiveTagName;
|
|
2530
|
+
}
|
|
2531
|
+
return tagName;
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
/**
|
|
2535
|
+
* Transforms DOM nodes to `domhandler` nodes.
|
|
2536
|
+
*
|
|
2537
|
+
* @param {NodeList} nodes - DOM nodes.
|
|
2538
|
+
* @param {Element|null} [parent=null] - Parent node.
|
|
2539
|
+
* @param {string} [directive] - Directive.
|
|
2540
|
+
* @returns {Array<Comment|Element|ProcessingInstruction|Text>}
|
|
2541
|
+
*/
|
|
2542
|
+
function formatDOM$1(nodes, parent, directive) {
|
|
2543
|
+
parent = parent || null;
|
|
2544
|
+
var result = [];
|
|
2545
|
+
|
|
2546
|
+
for (var index = 0, len = nodes.length; index < len; index++) {
|
|
2547
|
+
var node = nodes[index];
|
|
2548
|
+
var current;
|
|
2549
|
+
|
|
2550
|
+
// set the node data given the type
|
|
2551
|
+
switch (node.nodeType) {
|
|
2552
|
+
case 1:
|
|
2553
|
+
// script, style, or tag
|
|
2554
|
+
current = new Element(
|
|
2555
|
+
formatTagName(node.nodeName),
|
|
2556
|
+
formatAttributes(node.attributes)
|
|
2557
|
+
);
|
|
2558
|
+
current.children = formatDOM$1(node.childNodes, current);
|
|
2559
|
+
break;
|
|
2560
|
+
|
|
2561
|
+
case 3:
|
|
2562
|
+
current = new Text(node.nodeValue);
|
|
2563
|
+
break;
|
|
2564
|
+
|
|
2565
|
+
case 8:
|
|
2566
|
+
current = new Comment(node.nodeValue);
|
|
2567
|
+
break;
|
|
2568
|
+
|
|
2569
|
+
default:
|
|
2570
|
+
continue;
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
// set previous node next
|
|
2574
|
+
var prev = result[index - 1] || null;
|
|
2575
|
+
if (prev) {
|
|
2576
|
+
prev.next = current;
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
// set properties for current node
|
|
2580
|
+
current.parent = parent;
|
|
2581
|
+
current.prev = prev;
|
|
2582
|
+
current.next = null;
|
|
2583
|
+
|
|
2584
|
+
result.push(current);
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
if (directive) {
|
|
2588
|
+
current = new ProcessingInstruction(
|
|
2589
|
+
directive.substring(0, directive.indexOf(' ')).toLowerCase(),
|
|
2590
|
+
directive
|
|
2591
|
+
);
|
|
2592
|
+
current.next = result[0] || null;
|
|
2593
|
+
current.parent = parent;
|
|
2594
|
+
result.unshift(current);
|
|
2595
|
+
|
|
2596
|
+
if (result[1]) {
|
|
2597
|
+
result[1].prev = result[0];
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
return result;
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
utilities.formatAttributes = formatAttributes;
|
|
2605
|
+
utilities.formatDOM = formatDOM$1;
|
|
2606
|
+
|
|
2607
|
+
var domparser = domparser_1;
|
|
2608
|
+
var formatDOM = utilities.formatDOM;
|
|
2609
|
+
|
|
2610
|
+
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
|
|
2611
|
+
|
|
2612
|
+
/**
|
|
2613
|
+
* Parses HTML string to DOM nodes in browser.
|
|
2614
|
+
*
|
|
2615
|
+
* @param {string} html - HTML markup.
|
|
2616
|
+
* @return {DomElement[]} - DOM elements.
|
|
2617
|
+
*/
|
|
2618
|
+
function HTMLDOMParser(html) {
|
|
2619
|
+
if (typeof html !== 'string') {
|
|
2620
|
+
throw new TypeError('First argument must be a string');
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
if (html === '') {
|
|
2624
|
+
return [];
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
// match directive
|
|
2628
|
+
var match = html.match(DIRECTIVE_REGEX);
|
|
2629
|
+
var directive;
|
|
2630
|
+
|
|
2631
|
+
if (match && match[1]) {
|
|
2632
|
+
directive = match[1];
|
|
2633
|
+
}
|
|
2634
|
+
|
|
2635
|
+
return formatDOM(domparser(html), null, directive);
|
|
2633
2636
|
}
|
|
2634
2637
|
|
|
2638
|
+
var htmlToDom = HTMLDOMParser;
|
|
2639
|
+
|
|
2635
2640
|
var domToReact = domToReact_1;
|
|
2636
2641
|
var attributesToProps = attributesToProps$2;
|
|
2637
2642
|
var htmlToDOM = htmlToDom;
|
|
@@ -2646,12 +2651,12 @@
|
|
|
2646
2651
|
/**
|
|
2647
2652
|
* Converts HTML string to React elements.
|
|
2648
2653
|
*
|
|
2649
|
-
* @param
|
|
2650
|
-
* @param
|
|
2651
|
-
* @param
|
|
2652
|
-
* @param
|
|
2653
|
-
* @param
|
|
2654
|
-
* @
|
|
2654
|
+
* @param {string} html - HTML string.
|
|
2655
|
+
* @param {object} [options] - Parser options.
|
|
2656
|
+
* @param {object} [options.htmlparser2] - htmlparser2 options.
|
|
2657
|
+
* @param {object} [options.library] - Library for React, Preact, etc.
|
|
2658
|
+
* @param {Function} [options.replace] - Replace method.
|
|
2659
|
+
* @returns {JSX.Element|JSX.Element[]|string} - React element(s), empty array, or string.
|
|
2655
2660
|
*/
|
|
2656
2661
|
function HTMLReactParser(html, options) {
|
|
2657
2662
|
if (typeof html !== 'string') {
|