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.
- package/README.md +6 -1
- package/dist/html-react-parser.js +927 -740
- 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 +7 -7
- 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 -19
|
@@ -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
|
|
13
|
+
var htmlReactParser = {exports: {}};
|
|
14
14
|
|
|
15
|
-
var lib$
|
|
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$
|
|
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$
|
|
819
|
-
lib$
|
|
820
|
-
lib$
|
|
821
|
-
lib$
|
|
822
|
-
lib$
|
|
823
|
-
lib$
|
|
824
|
-
lib$
|
|
825
|
-
lib$
|
|
826
|
-
lib$
|
|
827
|
-
lib$
|
|
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 (
|
|
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
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
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
|
|
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);
|
|
@@ -1312,14 +1316,14 @@
|
|
|
1312
1316
|
elementsWithNoTextChildren: elementsWithNoTextChildren
|
|
1313
1317
|
};
|
|
1314
1318
|
|
|
1315
|
-
var reactProperty = lib$
|
|
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
|
|
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,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
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
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
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
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 =
|
|
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
|
|
2449
|
-
* @param
|
|
2450
|
-
* @param
|
|
2451
|
-
* @param
|
|
2452
|
-
* @param
|
|
2453
|
-
* @
|
|
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 =
|
|
2661
|
+
HTMLReactParser.Element = requireLib().Element;
|
|
2473
2662
|
|
|
2474
2663
|
// support CommonJS and ES Modules
|
|
2475
|
-
htmlReactParser
|
|
2476
|
-
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
|