html-react-parser 0.8.0 → 0.9.2
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/CHANGELOG.md +59 -0
- package/README.md +56 -13
- package/dist/html-react-parser.js +1634 -269
- package/dist/html-react-parser.min.js +2 -2
- package/dist/html-react-parser.min.js.map +1 -1
- package/index.d.ts +10 -11
- package/index.js +7 -10
- package/lib/attributes-to-props.js +47 -42
- package/lib/dom-to-react.js +4 -4
- package/package.json +17 -11
- package/lib/property-config.js +0 -50
|
@@ -1,296 +1,1661 @@
|
|
|
1
|
-
(function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
else if(typeof exports === 'object')
|
|
7
|
-
exports["HTMLReactParser"] = factory(require("react"));
|
|
8
|
-
else
|
|
9
|
-
root["HTMLReactParser"] = factory(root["React"]);
|
|
10
|
-
})(window, function(__WEBPACK_EXTERNAL_MODULE_react__) {
|
|
11
|
-
return /******/ (function(modules) { // webpackBootstrap
|
|
12
|
-
/******/ // The module cache
|
|
13
|
-
/******/ var installedModules = {};
|
|
14
|
-
/******/
|
|
15
|
-
/******/ // The require function
|
|
16
|
-
/******/ function __webpack_require__(moduleId) {
|
|
17
|
-
/******/
|
|
18
|
-
/******/ // Check if module is in cache
|
|
19
|
-
/******/ if(installedModules[moduleId]) {
|
|
20
|
-
/******/ return installedModules[moduleId].exports;
|
|
21
|
-
/******/ }
|
|
22
|
-
/******/ // Create a new module (and put it into the cache)
|
|
23
|
-
/******/ var module = installedModules[moduleId] = {
|
|
24
|
-
/******/ i: moduleId,
|
|
25
|
-
/******/ l: false,
|
|
26
|
-
/******/ exports: {}
|
|
27
|
-
/******/ };
|
|
28
|
-
/******/
|
|
29
|
-
/******/ // Execute the module function
|
|
30
|
-
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
31
|
-
/******/
|
|
32
|
-
/******/ // Flag the module as loaded
|
|
33
|
-
/******/ module.l = true;
|
|
34
|
-
/******/
|
|
35
|
-
/******/ // Return the exports of the module
|
|
36
|
-
/******/ return module.exports;
|
|
37
|
-
/******/ }
|
|
38
|
-
/******/
|
|
39
|
-
/******/
|
|
40
|
-
/******/ // expose the modules object (__webpack_modules__)
|
|
41
|
-
/******/ __webpack_require__.m = modules;
|
|
42
|
-
/******/
|
|
43
|
-
/******/ // expose the module cache
|
|
44
|
-
/******/ __webpack_require__.c = installedModules;
|
|
45
|
-
/******/
|
|
46
|
-
/******/ // define getter function for harmony exports
|
|
47
|
-
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
48
|
-
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
49
|
-
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
50
|
-
/******/ }
|
|
51
|
-
/******/ };
|
|
52
|
-
/******/
|
|
53
|
-
/******/ // define __esModule on exports
|
|
54
|
-
/******/ __webpack_require__.r = function(exports) {
|
|
55
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
56
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
57
|
-
/******/ }
|
|
58
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
59
|
-
/******/ };
|
|
60
|
-
/******/
|
|
61
|
-
/******/ // create a fake namespace object
|
|
62
|
-
/******/ // mode & 1: value is a module id, require it
|
|
63
|
-
/******/ // mode & 2: merge all properties of value into the ns
|
|
64
|
-
/******/ // mode & 4: return value when already ns object
|
|
65
|
-
/******/ // mode & 8|1: behave like require
|
|
66
|
-
/******/ __webpack_require__.t = function(value, mode) {
|
|
67
|
-
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
68
|
-
/******/ if(mode & 8) return value;
|
|
69
|
-
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
70
|
-
/******/ var ns = Object.create(null);
|
|
71
|
-
/******/ __webpack_require__.r(ns);
|
|
72
|
-
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
73
|
-
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
74
|
-
/******/ return ns;
|
|
75
|
-
/******/ };
|
|
76
|
-
/******/
|
|
77
|
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
78
|
-
/******/ __webpack_require__.n = function(module) {
|
|
79
|
-
/******/ var getter = module && module.__esModule ?
|
|
80
|
-
/******/ function getDefault() { return module['default']; } :
|
|
81
|
-
/******/ function getModuleExports() { return module; };
|
|
82
|
-
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
83
|
-
/******/ return getter;
|
|
84
|
-
/******/ };
|
|
85
|
-
/******/
|
|
86
|
-
/******/ // Object.prototype.hasOwnProperty.call
|
|
87
|
-
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
88
|
-
/******/
|
|
89
|
-
/******/ // __webpack_public_path__
|
|
90
|
-
/******/ __webpack_require__.p = "";
|
|
91
|
-
/******/
|
|
92
|
-
/******/
|
|
93
|
-
/******/ // Load entry module and return exports
|
|
94
|
-
/******/ return __webpack_require__(__webpack_require__.s = "./index.js");
|
|
95
|
-
/******/ })
|
|
96
|
-
/************************************************************************/
|
|
97
|
-
/******/ ({
|
|
98
|
-
|
|
99
|
-
/***/ "./index.js":
|
|
100
|
-
/*!******************!*\
|
|
101
|
-
!*** ./index.js ***!
|
|
102
|
-
\******************/
|
|
103
|
-
/*! no static exports found */
|
|
104
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
105
|
-
|
|
106
|
-
eval("var domToReact = __webpack_require__(/*! ./lib/dom-to-react */ \"./lib/dom-to-react.js\");\nvar htmlToDOM = __webpack_require__(/*! html-dom-parser */ \"./node_modules/html-dom-parser/lib/html-to-dom-client.js\");\n\n// decode HTML entities by default for `htmlparser2`\nvar domParserOptions = { decodeEntities: true, lowerCaseAttributeNames: false };\n\n/**\n * Convert HTML string to React elements.\n *\n * @param {String} html - The HTML string.\n * @param {Object} [options] - The additional options.\n * @param {Function} [options.replace] - The replace method.\n * @return {ReactElement|Array}\n */\nfunction HTMLReactParser(html, options) {\n if (typeof html !== 'string') {\n throw new TypeError('First argument must be a string');\n }\n return domToReact(htmlToDOM(html, domParserOptions), options);\n}\n\n/**\n * Export HTML to React parser.\n */\nmodule.exports = HTMLReactParser;\n\nmodule.exports.domToReact = domToReact;\nmodule.exports.htmlToDOM = htmlToDOM;\n\n\n//# sourceURL=webpack://HTMLReactParser/./index.js?");
|
|
107
|
-
|
|
108
|
-
/***/ }),
|
|
109
|
-
|
|
110
|
-
/***/ "./lib/attributes-to-props.js":
|
|
111
|
-
/*!************************************!*\
|
|
112
|
-
!*** ./lib/attributes-to-props.js ***!
|
|
113
|
-
\************************************/
|
|
114
|
-
/*! no static exports found */
|
|
115
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
116
|
-
|
|
117
|
-
eval("var DOMProperty = __webpack_require__(/*! react-dom-core/lib/DOMProperty */ \"./node_modules/react-dom-core/lib/DOMProperty.js\");\nvar propertyConfig = __webpack_require__(/*! ./property-config */ \"./lib/property-config.js\");\nvar styleToObject = __webpack_require__(/*! style-to-object */ \"./node_modules/style-to-object/index.js\");\nvar utilities = __webpack_require__(/*! ./utilities */ \"./lib/utilities.js\");\n\nvar config = propertyConfig.config;\nvar isCustomAttribute = propertyConfig.HTMLDOMPropertyConfig.isCustomAttribute;\nDOMProperty.injection.injectDOMPropertyConfig(\n propertyConfig.HTMLDOMPropertyConfig\n);\n\n/**\n * Makes attributes compatible with React props.\n *\n * @param {Object} [attributes={}] - The attributes.\n * @return {Object} - The props.\n */\nfunction attributesToProps(attributes) {\n attributes = attributes || {};\n var props = {};\n var propertyName;\n var propertyValue;\n var reactProperty;\n\n for (propertyName in attributes) {\n propertyValue = attributes[propertyName];\n\n // custom attributes (`data-` and `aria-`)\n if (isCustomAttribute(propertyName)) {\n props[propertyName] = propertyValue;\n continue;\n }\n\n // make HTML DOM attribute/property consistent with React attribute/property\n reactProperty = config.html[propertyName.toLowerCase()];\n if (reactProperty) {\n if (\n Object.prototype.hasOwnProperty.call(\n DOMProperty.properties,\n reactProperty\n ) &&\n DOMProperty.properties[reactProperty].hasBooleanValue\n ) {\n props[reactProperty] = true;\n } else {\n props[reactProperty] = propertyValue;\n }\n continue;\n }\n\n // make SVG DOM attribute/property consistent with React attribute/property\n reactProperty = config.svg[propertyName];\n if (reactProperty) {\n props[reactProperty] = propertyValue;\n } else if (utilities.PRESERVE_CUSTOM_ATTRIBUTES) {\n props[propertyName] = propertyValue;\n }\n }\n\n // convert inline style to object\n if (attributes.style != null) {\n props.style = cssToJs(attributes.style);\n }\n return props;\n}\n\n/**\n * Converts CSS style string to JS style object.\n *\n * @param {String} style - The CSS style.\n * @return {Object} - The JS style object.\n */\nfunction cssToJs(style) {\n if (typeof style !== 'string') {\n throw new TypeError('First argument must be a string.');\n }\n var styleObj = {};\n\n styleToObject(style, function(propName, propValue) {\n // Check if it's not a comment node\n if (propName && propValue) {\n styleObj[utilities.camelCase(propName)] = propValue;\n }\n });\n return styleObj;\n}\n\nmodule.exports = attributesToProps;\n\n\n//# sourceURL=webpack://HTMLReactParser/./lib/attributes-to-props.js?");
|
|
118
|
-
|
|
119
|
-
/***/ }),
|
|
120
|
-
|
|
121
|
-
/***/ "./lib/dom-to-react.js":
|
|
122
|
-
/*!*****************************!*\
|
|
123
|
-
!*** ./lib/dom-to-react.js ***!
|
|
124
|
-
\*****************************/
|
|
125
|
-
/*! no static exports found */
|
|
126
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
127
|
-
|
|
128
|
-
eval("var React = __webpack_require__(/*! react */ \"react\");\nvar attributesToProps = __webpack_require__(/*! ./attributes-to-props */ \"./lib/attributes-to-props.js\");\nvar utilities = __webpack_require__(/*! ./utilities */ \"./lib/utilities.js\");\n\nvar cloneElement = React.cloneElement;\nvar createElement = React.createElement;\nvar isValidElement = React.isValidElement;\n\n/**\n * Converts DOM nodes to React elements.\n *\n * @param {Array} nodes - The DOM nodes.\n * @param {Object} [options] - The additional options.\n * @param {Function} [options.replace] - The replace method.\n * @return {ReactElement|Array}\n */\nfunction domToReact(nodes, options) {\n options = options || {};\n var result = [];\n var node;\n var hasReplace = typeof options.replace === 'function';\n var replaceElement;\n var props;\n var children;\n\n for (var i = 0, len = nodes.length; i < len; i++) {\n node = nodes[i];\n\n // replace with custom React element (if present)\n if (hasReplace) {\n replaceElement = options.replace(node);\n\n if (isValidElement(replaceElement)) {\n // specify a \"key\" prop if element has siblings\n // https://fb.me/react-warning-keys\n if (len > 1) {\n replaceElement = cloneElement(replaceElement, {\n key: replaceElement.key || i\n });\n }\n result.push(replaceElement);\n continue;\n }\n }\n\n if (node.type === 'text') {\n result.push(node.data);\n continue;\n }\n\n props = node.attribs;\n if (!shouldPassAttributesUnaltered(node)) {\n // update values\n props = attributesToProps(node.attribs);\n }\n\n children = null;\n\n // node type for <style> is \"style\"\n // skip node type \"script\" as react-dom does not render the contents\n if (node.type === 'style') {\n // prevent text in <style> from being escaped\n // https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml\n if (node.children[0]) {\n props.dangerouslySetInnerHTML = {\n __html: node.children[0].data\n };\n }\n } else if (node.type === 'tag') {\n // setting textarea value in children is an antipattern in React\n // https://reactjs.org/docs/forms.html#the-textarea-tag\n if (node.name === 'textarea' && node.children[0]) {\n props.defaultValue = node.children[0].data;\n\n // continue recursion of creating React elements (if applicable)\n } else if (node.children && node.children.length) {\n children = domToReact(node.children, options);\n }\n\n // skip all other cases (e.g., comment)\n } else {\n continue;\n }\n\n // specify a \"key\" prop if element has siblings\n // https://fb.me/react-warning-keys\n if (len > 1) {\n props.key = i;\n }\n\n result.push(createElement(node.name, props, children));\n }\n\n return result.length === 1 ? result[0] : result;\n}\n\nfunction shouldPassAttributesUnaltered(node) {\n return (\n utilities.PRESERVE_CUSTOM_ATTRIBUTES &&\n node.type === 'tag' &&\n utilities.isCustomComponent(node.name, node.attribs)\n );\n}\n\nmodule.exports = domToReact;\n\n\n//# sourceURL=webpack://HTMLReactParser/./lib/dom-to-react.js?");
|
|
129
|
-
|
|
130
|
-
/***/ }),
|
|
131
|
-
|
|
132
|
-
/***/ "./lib/property-config.js":
|
|
133
|
-
/*!********************************!*\
|
|
134
|
-
!*** ./lib/property-config.js ***!
|
|
135
|
-
\********************************/
|
|
136
|
-
/*! no static exports found */
|
|
137
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
138
|
-
|
|
139
|
-
eval("var HTMLDOMPropertyConfig = __webpack_require__(/*! react-dom-core/lib/HTMLDOMPropertyConfig */ \"./node_modules/react-dom-core/lib/HTMLDOMPropertyConfig.js\");\nvar SVGDOMPropertyConfig = __webpack_require__(/*! react-dom-core/lib/SVGDOMPropertyConfig */ \"./node_modules/react-dom-core/lib/SVGDOMPropertyConfig.js\");\nvar utilities = __webpack_require__(/*! ./utilities */ \"./lib/utilities.js\");\n\nvar config = {\n html: {},\n svg: {}\n};\n\nvar propertyName;\n\n/**\n * HTML DOM property config.\n *\n * https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/HTMLDOMPropertyConfig.js\n */\n\n// first map out the HTML attribute names\n// e.g., { className: 'class' } => { 'class': 'className' }\nconfig.html = utilities.invertObject(HTMLDOMPropertyConfig.DOMAttributeNames);\n\n// then map out the rest of the HTML properties\n// e.g., { readOnly: 0 } => { readonly: 'readOnly' }\nfor (propertyName in HTMLDOMPropertyConfig.Properties) {\n // lowercase to make matching property names easier\n config.html[propertyName.toLowerCase()] = propertyName;\n}\n\n/**\n * SVG DOM property config.\n *\n * https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/SVGDOMPropertyConfig.js\n */\n\n// first map out the SVG attribute names\n// e.g., { fontSize: 'font-size' } => { 'font-size': 'fontSize' }\nconfig.svg = utilities.invertObject(SVGDOMPropertyConfig.DOMAttributeNames);\n\n// then map out the rest of the SVG properties\n// e.g., { fillRule: 0 } => { fillRule: 'fillRule' }\nfor (propertyName in SVGDOMPropertyConfig.Properties) {\n // do not lowercase as some svg properties are camel cased\n config.html[propertyName] = propertyName;\n}\n\nmodule.exports = {\n config: config,\n HTMLDOMPropertyConfig: HTMLDOMPropertyConfig,\n SVGDOMPropertyConfig: SVGDOMPropertyConfig\n};\n\n\n//# sourceURL=webpack://HTMLReactParser/./lib/property-config.js?");
|
|
140
|
-
|
|
141
|
-
/***/ }),
|
|
142
|
-
|
|
143
|
-
/***/ "./lib/utilities.js":
|
|
144
|
-
/*!**************************!*\
|
|
145
|
-
!*** ./lib/utilities.js ***!
|
|
146
|
-
\**************************/
|
|
147
|
-
/*! no static exports found */
|
|
148
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
149
|
-
|
|
150
|
-
eval("var React = __webpack_require__(/*! react */ \"react\");\nvar hyphenPatternRegex = /-([a-z])/g;\nvar CUSTOM_PROPERTY_OR_NO_HYPHEN_REGEX = /^--[a-zA-Z0-9-]+$|^[^-]+$/;\n\n/**\n * Converts a string to camelCase.\n *\n * @param {String} string - The string.\n * @return {String}\n */\nfunction camelCase(string) {\n if (typeof string !== 'string') {\n throw new TypeError('First argument must be a string');\n }\n\n // custom property or no hyphen found\n if (CUSTOM_PROPERTY_OR_NO_HYPHEN_REGEX.test(string)) {\n return string;\n }\n\n // convert to camelCase\n return string\n .toLowerCase()\n .replace(hyphenPatternRegex, function(_, character) {\n return character.toUpperCase();\n });\n}\n\n/**\n * Swap key with value in an object.\n *\n * @param {Object} obj - The object.\n * @param {Function} [override] - The override method.\n * @return {Object} - The inverted object.\n */\nfunction invertObject(obj, override) {\n if (!obj || typeof obj !== 'object') {\n throw new TypeError('First argument must be an object');\n }\n\n var key;\n var value;\n var isOverridePresent = typeof override === 'function';\n var overrides = {};\n var result = {};\n\n for (key in obj) {\n value = obj[key];\n\n if (isOverridePresent) {\n overrides = override(key, value);\n if (overrides && overrides.length === 2) {\n result[overrides[0]] = overrides[1];\n continue;\n }\n }\n\n if (typeof value === 'string') {\n result[value] = key;\n }\n }\n\n return result;\n}\n\n/**\n * Check if a given tag is a custom component.\n *\n * @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}\n *\n * @param {string} tagName - The name of the html tag.\n * @param {Object} props - The props being passed to the element.\n * @return {boolean}\n */\nfunction isCustomComponent(tagName, props) {\n if (tagName.indexOf('-') === -1) {\n return props && typeof props.is === 'string';\n }\n\n switch (tagName) {\n // These are reserved SVG and MathML elements.\n // We don't mind this whitelist too much because we expect it to never grow.\n // The alternative is to track the namespace in a few places which is convoluted.\n // https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts\n case 'annotation-xml':\n case 'color-profile':\n case 'font-face':\n case 'font-face-src':\n case 'font-face-uri':\n case 'font-face-format':\n case 'font-face-name':\n case 'missing-glyph':\n return false;\n default:\n return true;\n }\n}\n\n/**\n * @constant {Boolean}\n * @see {@link https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html}\n */\nvar PRESERVE_CUSTOM_ATTRIBUTES = React.version.split('.')[0] >= 16;\n\nmodule.exports = {\n PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,\n camelCase: camelCase,\n invertObject: invertObject,\n isCustomComponent: isCustomComponent\n};\n\n\n//# sourceURL=webpack://HTMLReactParser/./lib/utilities.js?");
|
|
151
|
-
|
|
152
|
-
/***/ }),
|
|
153
|
-
|
|
154
|
-
/***/ "./node_modules/fbjs/lib/invariant.js":
|
|
155
|
-
/*!********************************************!*\
|
|
156
|
-
!*** ./node_modules/fbjs/lib/invariant.js ***!
|
|
157
|
-
\********************************************/
|
|
158
|
-
/*! no static exports found */
|
|
159
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
160
|
-
|
|
161
|
-
"use strict";
|
|
162
|
-
eval("/**\n * Copyright (c) 2013-present, Facebook, Inc.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * \n */\n\n\nvar validateFormat = true ? function (format) {} : undefined;\n/**\n * Use invariant() to assert state which your program assumes to be true.\n *\n * Provide sprintf-style format (only %s is supported) and arguments to provide\n * information about what broke and what you were expecting.\n *\n * The invariant message will be stripped in production, but the invariant will\n * remain to ensure logic does not differ in production.\n */\n\nfunction invariant(condition, format) {\n for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {\n args[_key - 2] = arguments[_key];\n }\n\n validateFormat(format);\n\n if (!condition) {\n var error;\n\n if (format === undefined) {\n error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');\n } else {\n var argIndex = 0;\n error = new Error(format.replace(/%s/g, function () {\n return String(args[argIndex++]);\n }));\n error.name = 'Invariant Violation';\n }\n\n error.framesToPop = 1; // Skip invariant's own stack frame.\n\n throw error;\n }\n}\n\nmodule.exports = invariant;\n\n//# sourceURL=webpack://HTMLReactParser/./node_modules/fbjs/lib/invariant.js?");
|
|
163
|
-
|
|
164
|
-
/***/ }),
|
|
165
|
-
|
|
166
|
-
/***/ "./node_modules/html-dom-parser/lib/constants.js":
|
|
167
|
-
/*!*******************************************************!*\
|
|
168
|
-
!*** ./node_modules/html-dom-parser/lib/constants.js ***!
|
|
169
|
-
\*******************************************************/
|
|
170
|
-
/*! no static exports found */
|
|
171
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
172
|
-
|
|
173
|
-
"use strict";
|
|
174
|
-
eval("\n\n/**\n * SVG elements, unlike HTML elements, are case-sensitive.\n *\n * @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}\n */\nvar CASE_SENSITIVE_TAG_NAMES = [\n 'animateMotion',\n 'animateTransform',\n 'clipPath',\n 'feBlend',\n 'feColorMatrix',\n 'feComponentTransfer',\n 'feComposite',\n 'feConvolveMatrix',\n 'feDiffuseLighting',\n 'feDisplacementMap',\n 'feDropShadow',\n 'feFlood',\n 'feFuncA',\n 'feFuncB',\n 'feFuncG',\n 'feFuncR',\n 'feGaussainBlur',\n 'feImage',\n 'feMerge',\n 'feMergeNode',\n 'feMorphology',\n 'feOffset',\n 'fePointLight',\n 'feSpecularLighting',\n 'feSpotLight',\n 'feTile',\n 'feTurbulence',\n 'foreignObject',\n 'linearGradient',\n 'radialGradient',\n 'textPath'\n];\n\nmodule.exports = {\n CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES\n};\n\n\n//# sourceURL=webpack://HTMLReactParser/./node_modules/html-dom-parser/lib/constants.js?");
|
|
175
|
-
|
|
176
|
-
/***/ }),
|
|
177
|
-
|
|
178
|
-
/***/ "./node_modules/html-dom-parser/lib/domparser.js":
|
|
179
|
-
/*!*******************************************************!*\
|
|
180
|
-
!*** ./node_modules/html-dom-parser/lib/domparser.js ***!
|
|
181
|
-
\*******************************************************/
|
|
182
|
-
/*! no static exports found */
|
|
183
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
184
|
-
|
|
185
|
-
"use strict";
|
|
186
|
-
eval("\n\n/**\n * Module dependencies.\n */\nvar utilities = __webpack_require__(/*! ./utilities */ \"./node_modules/html-dom-parser/lib/utilities.js\");\nvar detectIE = utilities.isIE;\n\n/**\n * Constants.\n */\nvar HTML_TAG_NAME = 'html';\nvar BODY_TAG_NAME = 'body';\nvar HEAD_TAG_NAME = 'head';\nvar FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>\nvar HEAD_REGEX = /<\\/head>/i;\nvar BODY_REGEX = /<\\/body>/i;\n// http://www.w3.org/TR/html/syntax.html#void-elements\nvar VOID_ELEMENTS_REGEX = /<(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)(.*?)\\/?>/gi;\n\n// browser support\nvar isIE = detectIE();\nvar isIE9 = detectIE(9);\n\n/**\n * DOMParser (performance: slow).\n *\n * https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document\n */\nvar parseFromString;\nif (typeof window.DOMParser === 'function') {\n var domParser = new window.DOMParser();\n // IE9 does not support 'text/html' MIME type\n // https://msdn.microsoft.com/en-us/library/ff975278(v=vs.85).aspx\n var MIME_TYPE = isIE9 ? 'text/xml' : 'text/html';\n\n /**\n * Creates an HTML document using `DOMParser.parseFromString`.\n *\n * @param {String} html - The HTML string.\n * @param {String} [tagName] - The element to render the HTML (with 'body' as fallback).\n * @return {HTMLDocument}\n */\n parseFromString = function domStringParser(html, tagName) {\n if (tagName) {\n html = ['<', tagName, '>', html, '</', tagName, '>'].join('');\n }\n // because IE9 only supports MIME type 'text/xml', void elements need to be self-closed\n if (isIE9) {\n html = html.replace(VOID_ELEMENTS_REGEX, '<$1$2$3/>');\n }\n return domParser.parseFromString(html, MIME_TYPE);\n };\n}\n\n/**\n * DOMImplementation (performance: fair).\n *\n * https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument\n */\nvar parseFromDocument;\nif (typeof document.implementation === 'object') {\n // title parameter is required in IE\n // https://msdn.microsoft.com/en-us/library/ff975457(v=vs.85).aspx\n var doc = document.implementation.createHTMLDocument(isIE ? 'HTML_DOM_PARSER_TITLE' : undefined);\n\n /**\n * Use HTML document created by `document.implementation.createHTMLDocument`.\n *\n * @param {String} html - The HTML string.\n * @param {String} [tagName] - The element to render the HTML (with 'body' as fallback).\n * @return {HTMLDocument}\n */\n parseFromDocument = function createHTMLDocument(html, tagName) {\n if (tagName) {\n doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;\n return doc;\n }\n\n try {\n doc.documentElement.innerHTML = html;\n return doc;\n // fallback when certain elements in `documentElement` are read-only (IE9)\n } catch (err) {\n if (parseFromString) return parseFromString(html);\n }\n };\n}\n\n/**\n * Template (performance: fast).\n *\n * https://developer.mozilla.org/docs/Web/HTML/Element/template\n */\nvar parseFromTemplate;\nvar template = document.createElement('template');\nif (template.content) {\n\n /**\n * Uses a template element (content fragment) to parse HTML.\n *\n * @param {String} html - The HTML string.\n * @return {NodeList}\n */\n parseFromTemplate = function templateParser(html) {\n template.innerHTML = html;\n return template.content.childNodes;\n };\n}\n\n/** Fallback document parser. */\nvar parseWithFallback = parseFromDocument || parseFromString;\n\n/**\n * Parses HTML string to DOM nodes.\n *\n * @param {String} html - The HTML string.\n * @param {String} [tagName] - The tag name.\n * @return {NodeList|Array}\n */\nmodule.exports = function domparser(html) {\n // try to match first tag\n var tagName;\n var match = html.match(FIRST_TAG_REGEX);\n if (match && match[1]) {\n tagName = match[1].toLowerCase();\n }\n\n var doc;\n var element;\n var elements;\n\n switch (tagName) {\n case HTML_TAG_NAME:\n if (parseFromString) {\n doc = parseFromString(html);\n\n // the created document may come with filler head/body elements,\n // so ake sure to remove them if they don't actually exist\n if (!HEAD_REGEX.test(html)) {\n element = doc.getElementsByTagName(HEAD_TAG_NAME)[0];\n if (element) element.parentNode.removeChild(element);\n }\n if (!BODY_REGEX.test(html)) {\n element = doc.getElementsByTagName(BODY_TAG_NAME)[0];\n if (element) element.parentNode.removeChild(element);\n }\n\n return doc.getElementsByTagName(HTML_TAG_NAME);\n }\n break;\n\n case HEAD_TAG_NAME:\n if (parseWithFallback) {\n elements = parseWithFallback(html).getElementsByTagName(HEAD_TAG_NAME);\n\n // account for possibility of sibling\n if (BODY_REGEX.test(html)) {\n return elements[0].parentNode.childNodes;\n }\n return elements;\n }\n break;\n\n case BODY_TAG_NAME:\n if (parseWithFallback) {\n elements = parseWithFallback(html).getElementsByTagName(BODY_TAG_NAME);\n\n // account for possibility of sibling (return both body and head)\n if (HEAD_REGEX.test(html)) {\n return elements[0].parentNode.childNodes;\n }\n return elements;\n }\n break;\n\n // low-level tag or text\n default:\n if (parseFromTemplate) return parseFromTemplate(html);\n if (parseWithFallback) {\n return parseWithFallback(html, BODY_TAG_NAME).getElementsByTagName(BODY_TAG_NAME)[0].childNodes;\n }\n break;\n }\n\n return [];\n};\n\n\n//# sourceURL=webpack://HTMLReactParser/./node_modules/html-dom-parser/lib/domparser.js?");
|
|
187
|
-
|
|
188
|
-
/***/ }),
|
|
189
|
-
|
|
190
|
-
/***/ "./node_modules/html-dom-parser/lib/html-to-dom-client.js":
|
|
191
|
-
/*!****************************************************************!*\
|
|
192
|
-
!*** ./node_modules/html-dom-parser/lib/html-to-dom-client.js ***!
|
|
193
|
-
\****************************************************************/
|
|
194
|
-
/*! no static exports found */
|
|
195
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['react'], factory) :
|
|
4
|
+
(global = global || self, global.HTMLReactParser = factory(global.React));
|
|
5
|
+
}(this, function (react) { 'use strict';
|
|
196
6
|
|
|
197
|
-
|
|
198
|
-
eval("\n\n/**\n * Module dependencies.\n */\nvar domparser = __webpack_require__(/*! ./domparser */ \"./node_modules/html-dom-parser/lib/domparser.js\");\nvar utilities = __webpack_require__(/*! ./utilities */ \"./node_modules/html-dom-parser/lib/utilities.js\");\nvar formatDOM = utilities.formatDOM;\nvar isIE9 = utilities.isIE(9);\n\n/**\n * Constants.\n */\nvar DIRECTIVE_REGEX = /<(![a-zA-Z\\s]+)>/; // e.g., <!doctype html>\n\n/**\n * Parses HTML and reformats DOM nodes output.\n *\n * @param {String} html - The HTML string.\n * @return {Array} - The formatted DOM nodes.\n */\nmodule.exports = function parseDOM(html) {\n if (typeof html !== 'string') {\n throw new TypeError('First argument must be a string.');\n }\n if (!html) return [];\n\n // match directive\n var match = html.match(DIRECTIVE_REGEX);\n var directive;\n if (match && match[1]) {\n directive = match[1];\n\n // remove directive in IE9 because DOMParser uses\n // MIME type 'text/xml' instead of 'text/html'\n if (isIE9) {\n html = html.replace(match[0], '');\n }\n }\n\n return formatDOM(domparser(html), null, directive);\n};\n\n\n//# sourceURL=webpack://HTMLReactParser/./node_modules/html-dom-parser/lib/html-to-dom-client.js?");
|
|
7
|
+
react = react && react.hasOwnProperty('default') ? react['default'] : react;
|
|
199
8
|
|
|
200
|
-
|
|
9
|
+
var HTMLDOMPropertyConfig = {
|
|
10
|
+
Properties: {
|
|
11
|
+
autoFocus: 4,
|
|
12
|
+
accept: 0,
|
|
13
|
+
acceptCharset: 0,
|
|
14
|
+
accessKey: 0,
|
|
15
|
+
action: 0,
|
|
16
|
+
allowFullScreen: 4,
|
|
17
|
+
allowTransparency: 0,
|
|
18
|
+
alt: 0,
|
|
19
|
+
as: 0,
|
|
20
|
+
async: 4,
|
|
21
|
+
autoComplete: 0,
|
|
22
|
+
autoPlay: 4,
|
|
23
|
+
capture: 4,
|
|
24
|
+
cellPadding: 0,
|
|
25
|
+
cellSpacing: 0,
|
|
26
|
+
charSet: 0,
|
|
27
|
+
challenge: 0,
|
|
28
|
+
checked: 5,
|
|
29
|
+
cite: 0,
|
|
30
|
+
classID: 0,
|
|
31
|
+
className: 0,
|
|
32
|
+
cols: 24,
|
|
33
|
+
colSpan: 0,
|
|
34
|
+
content: 0,
|
|
35
|
+
contentEditable: 0,
|
|
36
|
+
contextMenu: 0,
|
|
37
|
+
controls: 4,
|
|
38
|
+
controlsList: 0,
|
|
39
|
+
coords: 0,
|
|
40
|
+
crossOrigin: 0,
|
|
41
|
+
data: 0,
|
|
42
|
+
dateTime: 0,
|
|
43
|
+
default: 4,
|
|
44
|
+
defer: 4,
|
|
45
|
+
dir: 0,
|
|
46
|
+
disabled: 4,
|
|
47
|
+
download: 32,
|
|
48
|
+
draggable: 0,
|
|
49
|
+
encType: 0,
|
|
50
|
+
form: 0,
|
|
51
|
+
formAction: 0,
|
|
52
|
+
formEncType: 0,
|
|
53
|
+
formMethod: 0,
|
|
54
|
+
formNoValidate: 4,
|
|
55
|
+
formTarget: 0,
|
|
56
|
+
frameBorder: 0,
|
|
57
|
+
headers: 0,
|
|
58
|
+
height: 0,
|
|
59
|
+
hidden: 4,
|
|
60
|
+
high: 0,
|
|
61
|
+
href: 0,
|
|
62
|
+
hrefLang: 0,
|
|
63
|
+
htmlFor: 0,
|
|
64
|
+
httpEquiv: 0,
|
|
65
|
+
icon: 0,
|
|
66
|
+
id: 0,
|
|
67
|
+
inputMode: 0,
|
|
68
|
+
integrity: 0,
|
|
69
|
+
is: 0,
|
|
70
|
+
keyParams: 0,
|
|
71
|
+
keyType: 0,
|
|
72
|
+
kind: 0,
|
|
73
|
+
label: 0,
|
|
74
|
+
lang: 0,
|
|
75
|
+
list: 0,
|
|
76
|
+
loop: 4,
|
|
77
|
+
low: 0,
|
|
78
|
+
manifest: 0,
|
|
79
|
+
marginHeight: 0,
|
|
80
|
+
marginWidth: 0,
|
|
81
|
+
max: 0,
|
|
82
|
+
maxLength: 0,
|
|
83
|
+
media: 0,
|
|
84
|
+
mediaGroup: 0,
|
|
85
|
+
method: 0,
|
|
86
|
+
min: 0,
|
|
87
|
+
minLength: 0,
|
|
88
|
+
multiple: 5,
|
|
89
|
+
muted: 5,
|
|
90
|
+
name: 0,
|
|
91
|
+
nonce: 0,
|
|
92
|
+
noValidate: 4,
|
|
93
|
+
open: 4,
|
|
94
|
+
optimum: 0,
|
|
95
|
+
pattern: 0,
|
|
96
|
+
placeholder: 0,
|
|
97
|
+
playsInline: 4,
|
|
98
|
+
poster: 0,
|
|
99
|
+
preload: 0,
|
|
100
|
+
profile: 0,
|
|
101
|
+
radioGroup: 0,
|
|
102
|
+
readOnly: 4,
|
|
103
|
+
referrerPolicy: 0,
|
|
104
|
+
rel: 0,
|
|
105
|
+
required: 4,
|
|
106
|
+
reversed: 4,
|
|
107
|
+
role: 0,
|
|
108
|
+
rows: 24,
|
|
109
|
+
rowSpan: 8,
|
|
110
|
+
sandbox: 0,
|
|
111
|
+
scope: 0,
|
|
112
|
+
scoped: 4,
|
|
113
|
+
scrolling: 0,
|
|
114
|
+
seamless: 4,
|
|
115
|
+
selected: 5,
|
|
116
|
+
shape: 0,
|
|
117
|
+
size: 24,
|
|
118
|
+
sizes: 0,
|
|
119
|
+
span: 24,
|
|
120
|
+
spellCheck: 0,
|
|
121
|
+
src: 0,
|
|
122
|
+
srcDoc: 0,
|
|
123
|
+
srcLang: 0,
|
|
124
|
+
srcSet: 0,
|
|
125
|
+
start: 8,
|
|
126
|
+
step: 0,
|
|
127
|
+
style: 0,
|
|
128
|
+
summary: 0,
|
|
129
|
+
tabIndex: 0,
|
|
130
|
+
target: 0,
|
|
131
|
+
title: 0,
|
|
132
|
+
type: 0,
|
|
133
|
+
useMap: 0,
|
|
134
|
+
value: 0,
|
|
135
|
+
width: 0,
|
|
136
|
+
wmode: 0,
|
|
137
|
+
wrap: 0,
|
|
138
|
+
about: 0,
|
|
139
|
+
datatype: 0,
|
|
140
|
+
inlist: 0,
|
|
141
|
+
prefix: 0,
|
|
142
|
+
property: 0,
|
|
143
|
+
resource: 0,
|
|
144
|
+
typeof: 0,
|
|
145
|
+
vocab: 0,
|
|
146
|
+
autoCapitalize: 0,
|
|
147
|
+
autoCorrect: 0,
|
|
148
|
+
autoSave: 0,
|
|
149
|
+
color: 0,
|
|
150
|
+
itemProp: 0,
|
|
151
|
+
itemScope: 4,
|
|
152
|
+
itemType: 0,
|
|
153
|
+
itemID: 0,
|
|
154
|
+
itemRef: 0,
|
|
155
|
+
results: 0,
|
|
156
|
+
security: 0,
|
|
157
|
+
unselectable: 0
|
|
158
|
+
},
|
|
159
|
+
DOMAttributeNames: {
|
|
160
|
+
acceptCharset: 'accept-charset',
|
|
161
|
+
className: 'class',
|
|
162
|
+
htmlFor: 'for',
|
|
163
|
+
httpEquiv: 'http-equiv'
|
|
164
|
+
}
|
|
165
|
+
};
|
|
201
166
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
167
|
+
var SVGDOMPropertyConfig = {
|
|
168
|
+
Properties: {
|
|
169
|
+
accentHeight: 0,
|
|
170
|
+
accumulate: 0,
|
|
171
|
+
additive: 0,
|
|
172
|
+
alignmentBaseline: 0,
|
|
173
|
+
allowReorder: 0,
|
|
174
|
+
alphabetic: 0,
|
|
175
|
+
amplitude: 0,
|
|
176
|
+
arabicForm: 0,
|
|
177
|
+
ascent: 0,
|
|
178
|
+
attributeName: 0,
|
|
179
|
+
attributeType: 0,
|
|
180
|
+
autoReverse: 0,
|
|
181
|
+
azimuth: 0,
|
|
182
|
+
baseFrequency: 0,
|
|
183
|
+
baseProfile: 0,
|
|
184
|
+
baselineShift: 0,
|
|
185
|
+
bbox: 0,
|
|
186
|
+
begin: 0,
|
|
187
|
+
bias: 0,
|
|
188
|
+
by: 0,
|
|
189
|
+
calcMode: 0,
|
|
190
|
+
capHeight: 0,
|
|
191
|
+
clip: 0,
|
|
192
|
+
clipPath: 0,
|
|
193
|
+
clipRule: 0,
|
|
194
|
+
clipPathUnits: 0,
|
|
195
|
+
colorInterpolation: 0,
|
|
196
|
+
colorInterpolationFilters: 0,
|
|
197
|
+
colorProfile: 0,
|
|
198
|
+
colorRendering: 0,
|
|
199
|
+
contentScriptType: 0,
|
|
200
|
+
contentStyleType: 0,
|
|
201
|
+
cursor: 0,
|
|
202
|
+
cx: 0,
|
|
203
|
+
cy: 0,
|
|
204
|
+
d: 0,
|
|
205
|
+
decelerate: 0,
|
|
206
|
+
descent: 0,
|
|
207
|
+
diffuseConstant: 0,
|
|
208
|
+
direction: 0,
|
|
209
|
+
display: 0,
|
|
210
|
+
divisor: 0,
|
|
211
|
+
dominantBaseline: 0,
|
|
212
|
+
dur: 0,
|
|
213
|
+
dx: 0,
|
|
214
|
+
dy: 0,
|
|
215
|
+
edgeMode: 0,
|
|
216
|
+
elevation: 0,
|
|
217
|
+
enableBackground: 0,
|
|
218
|
+
end: 0,
|
|
219
|
+
exponent: 0,
|
|
220
|
+
externalResourcesRequired: 0,
|
|
221
|
+
fill: 0,
|
|
222
|
+
fillOpacity: 0,
|
|
223
|
+
fillRule: 0,
|
|
224
|
+
filter: 0,
|
|
225
|
+
filterRes: 0,
|
|
226
|
+
filterUnits: 0,
|
|
227
|
+
floodColor: 0,
|
|
228
|
+
floodOpacity: 0,
|
|
229
|
+
focusable: 0,
|
|
230
|
+
fontFamily: 0,
|
|
231
|
+
fontSize: 0,
|
|
232
|
+
fontSizeAdjust: 0,
|
|
233
|
+
fontStretch: 0,
|
|
234
|
+
fontStyle: 0,
|
|
235
|
+
fontVariant: 0,
|
|
236
|
+
fontWeight: 0,
|
|
237
|
+
format: 0,
|
|
238
|
+
from: 0,
|
|
239
|
+
fx: 0,
|
|
240
|
+
fy: 0,
|
|
241
|
+
g1: 0,
|
|
242
|
+
g2: 0,
|
|
243
|
+
glyphName: 0,
|
|
244
|
+
glyphOrientationHorizontal: 0,
|
|
245
|
+
glyphOrientationVertical: 0,
|
|
246
|
+
glyphRef: 0,
|
|
247
|
+
gradientTransform: 0,
|
|
248
|
+
gradientUnits: 0,
|
|
249
|
+
hanging: 0,
|
|
250
|
+
horizAdvX: 0,
|
|
251
|
+
horizOriginX: 0,
|
|
252
|
+
ideographic: 0,
|
|
253
|
+
imageRendering: 0,
|
|
254
|
+
in: 0,
|
|
255
|
+
in2: 0,
|
|
256
|
+
intercept: 0,
|
|
257
|
+
k: 0,
|
|
258
|
+
k1: 0,
|
|
259
|
+
k2: 0,
|
|
260
|
+
k3: 0,
|
|
261
|
+
k4: 0,
|
|
262
|
+
kernelMatrix: 0,
|
|
263
|
+
kernelUnitLength: 0,
|
|
264
|
+
kerning: 0,
|
|
265
|
+
keyPoints: 0,
|
|
266
|
+
keySplines: 0,
|
|
267
|
+
keyTimes: 0,
|
|
268
|
+
lengthAdjust: 0,
|
|
269
|
+
letterSpacing: 0,
|
|
270
|
+
lightingColor: 0,
|
|
271
|
+
limitingConeAngle: 0,
|
|
272
|
+
local: 0,
|
|
273
|
+
markerEnd: 0,
|
|
274
|
+
markerMid: 0,
|
|
275
|
+
markerStart: 0,
|
|
276
|
+
markerHeight: 0,
|
|
277
|
+
markerUnits: 0,
|
|
278
|
+
markerWidth: 0,
|
|
279
|
+
mask: 0,
|
|
280
|
+
maskContentUnits: 0,
|
|
281
|
+
maskUnits: 0,
|
|
282
|
+
mathematical: 0,
|
|
283
|
+
mode: 0,
|
|
284
|
+
numOctaves: 0,
|
|
285
|
+
offset: 0,
|
|
286
|
+
opacity: 0,
|
|
287
|
+
operator: 0,
|
|
288
|
+
order: 0,
|
|
289
|
+
orient: 0,
|
|
290
|
+
orientation: 0,
|
|
291
|
+
origin: 0,
|
|
292
|
+
overflow: 0,
|
|
293
|
+
overlinePosition: 0,
|
|
294
|
+
overlineThickness: 0,
|
|
295
|
+
paintOrder: 0,
|
|
296
|
+
panose1: 0,
|
|
297
|
+
pathLength: 0,
|
|
298
|
+
patternContentUnits: 0,
|
|
299
|
+
patternTransform: 0,
|
|
300
|
+
patternUnits: 0,
|
|
301
|
+
pointerEvents: 0,
|
|
302
|
+
points: 0,
|
|
303
|
+
pointsAtX: 0,
|
|
304
|
+
pointsAtY: 0,
|
|
305
|
+
pointsAtZ: 0,
|
|
306
|
+
preserveAlpha: 0,
|
|
307
|
+
preserveAspectRatio: 0,
|
|
308
|
+
primitiveUnits: 0,
|
|
309
|
+
r: 0,
|
|
310
|
+
radius: 0,
|
|
311
|
+
refX: 0,
|
|
312
|
+
refY: 0,
|
|
313
|
+
renderingIntent: 0,
|
|
314
|
+
repeatCount: 0,
|
|
315
|
+
repeatDur: 0,
|
|
316
|
+
requiredExtensions: 0,
|
|
317
|
+
requiredFeatures: 0,
|
|
318
|
+
restart: 0,
|
|
319
|
+
result: 0,
|
|
320
|
+
rotate: 0,
|
|
321
|
+
rx: 0,
|
|
322
|
+
ry: 0,
|
|
323
|
+
scale: 0,
|
|
324
|
+
seed: 0,
|
|
325
|
+
shapeRendering: 0,
|
|
326
|
+
slope: 0,
|
|
327
|
+
spacing: 0,
|
|
328
|
+
specularConstant: 0,
|
|
329
|
+
specularExponent: 0,
|
|
330
|
+
speed: 0,
|
|
331
|
+
spreadMethod: 0,
|
|
332
|
+
startOffset: 0,
|
|
333
|
+
stdDeviation: 0,
|
|
334
|
+
stemh: 0,
|
|
335
|
+
stemv: 0,
|
|
336
|
+
stitchTiles: 0,
|
|
337
|
+
stopColor: 0,
|
|
338
|
+
stopOpacity: 0,
|
|
339
|
+
strikethroughPosition: 0,
|
|
340
|
+
strikethroughThickness: 0,
|
|
341
|
+
string: 0,
|
|
342
|
+
stroke: 0,
|
|
343
|
+
strokeDasharray: 0,
|
|
344
|
+
strokeDashoffset: 0,
|
|
345
|
+
strokeLinecap: 0,
|
|
346
|
+
strokeLinejoin: 0,
|
|
347
|
+
strokeMiterlimit: 0,
|
|
348
|
+
strokeOpacity: 0,
|
|
349
|
+
strokeWidth: 0,
|
|
350
|
+
surfaceScale: 0,
|
|
351
|
+
systemLanguage: 0,
|
|
352
|
+
tableValues: 0,
|
|
353
|
+
targetX: 0,
|
|
354
|
+
targetY: 0,
|
|
355
|
+
textAnchor: 0,
|
|
356
|
+
textDecoration: 0,
|
|
357
|
+
textRendering: 0,
|
|
358
|
+
textLength: 0,
|
|
359
|
+
to: 0,
|
|
360
|
+
transform: 0,
|
|
361
|
+
u1: 0,
|
|
362
|
+
u2: 0,
|
|
363
|
+
underlinePosition: 0,
|
|
364
|
+
underlineThickness: 0,
|
|
365
|
+
unicode: 0,
|
|
366
|
+
unicodeBidi: 0,
|
|
367
|
+
unicodeRange: 0,
|
|
368
|
+
unitsPerEm: 0,
|
|
369
|
+
vAlphabetic: 0,
|
|
370
|
+
vHanging: 0,
|
|
371
|
+
vIdeographic: 0,
|
|
372
|
+
vMathematical: 0,
|
|
373
|
+
values: 0,
|
|
374
|
+
vectorEffect: 0,
|
|
375
|
+
version: 0,
|
|
376
|
+
vertAdvY: 0,
|
|
377
|
+
vertOriginX: 0,
|
|
378
|
+
vertOriginY: 0,
|
|
379
|
+
viewBox: 0,
|
|
380
|
+
viewTarget: 0,
|
|
381
|
+
visibility: 0,
|
|
382
|
+
widths: 0,
|
|
383
|
+
wordSpacing: 0,
|
|
384
|
+
writingMode: 0,
|
|
385
|
+
x: 0,
|
|
386
|
+
xHeight: 0,
|
|
387
|
+
x1: 0,
|
|
388
|
+
x2: 0,
|
|
389
|
+
xChannelSelector: 0,
|
|
390
|
+
xlinkActuate: 0,
|
|
391
|
+
xlinkArcrole: 0,
|
|
392
|
+
xlinkHref: 0,
|
|
393
|
+
xlinkRole: 0,
|
|
394
|
+
xlinkShow: 0,
|
|
395
|
+
xlinkTitle: 0,
|
|
396
|
+
xlinkType: 0,
|
|
397
|
+
xmlBase: 0,
|
|
398
|
+
xmlns: 0,
|
|
399
|
+
xmlnsXlink: 0,
|
|
400
|
+
xmlLang: 0,
|
|
401
|
+
xmlSpace: 0,
|
|
402
|
+
y: 0,
|
|
403
|
+
y1: 0,
|
|
404
|
+
y2: 0,
|
|
405
|
+
yChannelSelector: 0,
|
|
406
|
+
z: 0,
|
|
407
|
+
zoomAndPan: 0
|
|
408
|
+
},
|
|
409
|
+
DOMAttributeNames: {
|
|
410
|
+
accentHeight: 'accent-height',
|
|
411
|
+
alignmentBaseline: 'alignment-baseline',
|
|
412
|
+
arabicForm: 'arabic-form',
|
|
413
|
+
baselineShift: 'baseline-shift',
|
|
414
|
+
capHeight: 'cap-height',
|
|
415
|
+
clipPath: 'clip-path',
|
|
416
|
+
clipRule: 'clip-rule',
|
|
417
|
+
colorInterpolation: 'color-interpolation',
|
|
418
|
+
colorInterpolationFilters: 'color-interpolation-filters',
|
|
419
|
+
colorProfile: 'color-profile',
|
|
420
|
+
colorRendering: 'color-rendering',
|
|
421
|
+
dominantBaseline: 'dominant-baseline',
|
|
422
|
+
enableBackground: 'enable-background',
|
|
423
|
+
fillOpacity: 'fill-opacity',
|
|
424
|
+
fillRule: 'fill-rule',
|
|
425
|
+
floodColor: 'flood-color',
|
|
426
|
+
floodOpacity: 'flood-opacity',
|
|
427
|
+
fontFamily: 'font-family',
|
|
428
|
+
fontSize: 'font-size',
|
|
429
|
+
fontSizeAdjust: 'font-size-adjust',
|
|
430
|
+
fontStretch: 'font-stretch',
|
|
431
|
+
fontStyle: 'font-style',
|
|
432
|
+
fontVariant: 'font-variant',
|
|
433
|
+
fontWeight: 'font-weight',
|
|
434
|
+
glyphName: 'glyph-name',
|
|
435
|
+
glyphOrientationHorizontal: 'glyph-orientation-horizontal',
|
|
436
|
+
glyphOrientationVertical: 'glyph-orientation-vertical',
|
|
437
|
+
horizAdvX: 'horiz-adv-x',
|
|
438
|
+
horizOriginX: 'horiz-origin-x',
|
|
439
|
+
imageRendering: 'image-rendering',
|
|
440
|
+
letterSpacing: 'letter-spacing',
|
|
441
|
+
lightingColor: 'lighting-color',
|
|
442
|
+
markerEnd: 'marker-end',
|
|
443
|
+
markerMid: 'marker-mid',
|
|
444
|
+
markerStart: 'marker-start',
|
|
445
|
+
overlinePosition: 'overline-position',
|
|
446
|
+
overlineThickness: 'overline-thickness',
|
|
447
|
+
paintOrder: 'paint-order',
|
|
448
|
+
panose1: 'panose-1',
|
|
449
|
+
pointerEvents: 'pointer-events',
|
|
450
|
+
renderingIntent: 'rendering-intent',
|
|
451
|
+
shapeRendering: 'shape-rendering',
|
|
452
|
+
stopColor: 'stop-color',
|
|
453
|
+
stopOpacity: 'stop-opacity',
|
|
454
|
+
strikethroughPosition: 'strikethrough-position',
|
|
455
|
+
strikethroughThickness: 'strikethrough-thickness',
|
|
456
|
+
strokeDasharray: 'stroke-dasharray',
|
|
457
|
+
strokeDashoffset: 'stroke-dashoffset',
|
|
458
|
+
strokeLinecap: 'stroke-linecap',
|
|
459
|
+
strokeLinejoin: 'stroke-linejoin',
|
|
460
|
+
strokeMiterlimit: 'stroke-miterlimit',
|
|
461
|
+
strokeOpacity: 'stroke-opacity',
|
|
462
|
+
strokeWidth: 'stroke-width',
|
|
463
|
+
textAnchor: 'text-anchor',
|
|
464
|
+
textDecoration: 'text-decoration',
|
|
465
|
+
textRendering: 'text-rendering',
|
|
466
|
+
underlinePosition: 'underline-position',
|
|
467
|
+
underlineThickness: 'underline-thickness',
|
|
468
|
+
unicodeBidi: 'unicode-bidi',
|
|
469
|
+
unicodeRange: 'unicode-range',
|
|
470
|
+
unitsPerEm: 'units-per-em',
|
|
471
|
+
vAlphabetic: 'v-alphabetic',
|
|
472
|
+
vHanging: 'v-hanging',
|
|
473
|
+
vIdeographic: 'v-ideographic',
|
|
474
|
+
vMathematical: 'v-mathematical',
|
|
475
|
+
vectorEffect: 'vector-effect',
|
|
476
|
+
vertAdvY: 'vert-adv-y',
|
|
477
|
+
vertOriginX: 'vert-origin-x',
|
|
478
|
+
vertOriginY: 'vert-origin-y',
|
|
479
|
+
wordSpacing: 'word-spacing',
|
|
480
|
+
writingMode: 'writing-mode',
|
|
481
|
+
xHeight: 'x-height',
|
|
482
|
+
xlinkActuate: 'xlink:actuate',
|
|
483
|
+
xlinkArcrole: 'xlink:arcrole',
|
|
484
|
+
xlinkHref: 'xlink:href',
|
|
485
|
+
xlinkRole: 'xlink:role',
|
|
486
|
+
xlinkShow: 'xlink:show',
|
|
487
|
+
xlinkTitle: 'xlink:title',
|
|
488
|
+
xlinkType: 'xlink:type',
|
|
489
|
+
xmlBase: 'xml:base',
|
|
490
|
+
xmlnsXlink: 'xmlns:xlink',
|
|
491
|
+
xmlLang: 'xml:lang',
|
|
492
|
+
xmlSpace: 'xml:space'
|
|
493
|
+
}
|
|
494
|
+
};
|
|
208
495
|
|
|
209
|
-
|
|
210
|
-
|
|
496
|
+
var injection = {
|
|
497
|
+
MUST_USE_PROPERTY: 1,
|
|
498
|
+
HAS_BOOLEAN_VALUE: 4,
|
|
499
|
+
HAS_NUMERIC_VALUE: 8,
|
|
500
|
+
HAS_POSITIVE_NUMERIC_VALUE: 24,
|
|
501
|
+
HAS_OVERLOADED_BOOLEAN_VALUE: 32
|
|
502
|
+
};
|
|
211
503
|
|
|
212
|
-
|
|
504
|
+
var MUST_USE_PROPERTY = injection.MUST_USE_PROPERTY;
|
|
505
|
+
var HAS_BOOLEAN_VALUE = injection.HAS_BOOLEAN_VALUE;
|
|
506
|
+
var HAS_NUMERIC_VALUE = injection.HAS_NUMERIC_VALUE;
|
|
507
|
+
var HAS_POSITIVE_NUMERIC_VALUE = injection.HAS_POSITIVE_NUMERIC_VALUE;
|
|
508
|
+
var HAS_OVERLOADED_BOOLEAN_VALUE = injection.HAS_OVERLOADED_BOOLEAN_VALUE;
|
|
213
509
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
510
|
+
/**
|
|
511
|
+
* @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/DOMProperty.js#L14-L16
|
|
512
|
+
*
|
|
513
|
+
* @param {Number} value
|
|
514
|
+
* @param {Number} bitmask
|
|
515
|
+
* @return {Boolean}
|
|
516
|
+
*/
|
|
517
|
+
function checkMask(value, bitmask) {
|
|
518
|
+
return (value & bitmask) === bitmask;
|
|
519
|
+
}
|
|
220
520
|
|
|
221
|
-
|
|
521
|
+
/**
|
|
522
|
+
* @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/DOMProperty.js#L57
|
|
523
|
+
*
|
|
524
|
+
* @param {Object} domPropertyConfig - HTMLDOMPropertyConfig or SVGDOMPropertyConfig
|
|
525
|
+
* @param {Object} config - The object to be mutated
|
|
526
|
+
* @param {Boolean} isSVG - Whether the injected config is HTML or SVG (it assumes the default is HTML)
|
|
527
|
+
*/
|
|
528
|
+
function injectDOMPropertyConfig(domPropertyConfig, config, isSVG) {
|
|
529
|
+
var Properties = domPropertyConfig.Properties;
|
|
530
|
+
var DOMAttributeNames = domPropertyConfig.DOMAttributeNames;
|
|
531
|
+
var attributeName;
|
|
532
|
+
var propertyName;
|
|
533
|
+
var propConfig;
|
|
222
534
|
|
|
223
|
-
|
|
535
|
+
for (propertyName in Properties) {
|
|
536
|
+
attributeName =
|
|
537
|
+
DOMAttributeNames[propertyName] ||
|
|
538
|
+
(isSVG ? propertyName : propertyName.toLowerCase());
|
|
539
|
+
propConfig = Properties[propertyName];
|
|
224
540
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
541
|
+
config[attributeName] = {
|
|
542
|
+
attributeName: attributeName,
|
|
543
|
+
propertyName: propertyName,
|
|
544
|
+
mustUseProperty: checkMask(propConfig, MUST_USE_PROPERTY),
|
|
545
|
+
hasBooleanValue: checkMask(propConfig, HAS_BOOLEAN_VALUE),
|
|
546
|
+
hasNumericValue: checkMask(propConfig, HAS_NUMERIC_VALUE),
|
|
547
|
+
hasPositiveNumericValue: checkMask(
|
|
548
|
+
propConfig,
|
|
549
|
+
HAS_POSITIVE_NUMERIC_VALUE
|
|
550
|
+
),
|
|
551
|
+
hasOverloadedBooleanValue: checkMask(
|
|
552
|
+
propConfig,
|
|
553
|
+
HAS_OVERLOADED_BOOLEAN_VALUE
|
|
554
|
+
)
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
}
|
|
231
558
|
|
|
232
|
-
|
|
233
|
-
|
|
559
|
+
/**
|
|
560
|
+
* HTML properties config.
|
|
561
|
+
*
|
|
562
|
+
* @type {Object}
|
|
563
|
+
*/
|
|
564
|
+
var html = {};
|
|
565
|
+
injectDOMPropertyConfig(HTMLDOMPropertyConfig, html);
|
|
234
566
|
|
|
235
|
-
|
|
567
|
+
/**
|
|
568
|
+
* SVG properties config.
|
|
569
|
+
*
|
|
570
|
+
* @type {Object}
|
|
571
|
+
*/
|
|
572
|
+
var svg = {};
|
|
573
|
+
injectDOMPropertyConfig(SVGDOMPropertyConfig, svg, true);
|
|
236
574
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
575
|
+
/**
|
|
576
|
+
* HTML and SVG properties config.
|
|
577
|
+
*
|
|
578
|
+
* @type {Object}
|
|
579
|
+
*/
|
|
580
|
+
var properties = {};
|
|
581
|
+
injectDOMPropertyConfig(HTMLDOMPropertyConfig, properties);
|
|
582
|
+
injectDOMPropertyConfig(SVGDOMPropertyConfig, properties, true);
|
|
243
583
|
|
|
244
|
-
|
|
245
|
-
|
|
584
|
+
var ATTRIBUTE_NAME_START_CHAR =
|
|
585
|
+
':A-Z_a-z\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD';
|
|
586
|
+
var ATTRIBUTE_NAME_CHAR =
|
|
587
|
+
ATTRIBUTE_NAME_START_CHAR + '\\-.0-9\\u00B7\\u0300-\\u036F\\u203F-\\u2040';
|
|
246
588
|
|
|
247
|
-
|
|
589
|
+
var reactProperty = {
|
|
590
|
+
html: html,
|
|
591
|
+
svg: svg,
|
|
592
|
+
properties: properties,
|
|
248
593
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
594
|
+
/**
|
|
595
|
+
* Checks whether a property name is a custom attribute.
|
|
596
|
+
*
|
|
597
|
+
* @see https://github.com/facebook/react/blob/15-stable/src/renderers/dom/shared/HTMLDOMPropertyConfig.js#L23-L25
|
|
598
|
+
*
|
|
599
|
+
* @param {String}
|
|
600
|
+
* @return {Boolean}
|
|
601
|
+
*/
|
|
602
|
+
isCustomAttribute: RegExp.prototype.test.bind(
|
|
603
|
+
new RegExp('^(data|aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$')
|
|
604
|
+
)
|
|
605
|
+
};
|
|
255
606
|
|
|
256
|
-
|
|
257
|
-
|
|
607
|
+
// http://www.w3.org/TR/CSS21/grammar.html
|
|
608
|
+
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
|
|
609
|
+
var COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
|
258
610
|
|
|
259
|
-
|
|
611
|
+
var NEWLINE_REGEX = /\n/g;
|
|
612
|
+
var WHITESPACE_REGEX = /^\s*/;
|
|
260
613
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
614
|
+
// declaration
|
|
615
|
+
var PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/;
|
|
616
|
+
var COLON_REGEX = /^:\s*/;
|
|
617
|
+
var VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/;
|
|
618
|
+
var SEMICOLON_REGEX = /^[;\s]*/;
|
|
267
619
|
|
|
268
|
-
|
|
269
|
-
|
|
620
|
+
// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
|
|
621
|
+
var TRIM_REGEX = /^\s+|\s+$/g;
|
|
270
622
|
|
|
271
|
-
|
|
623
|
+
// strings
|
|
624
|
+
var NEWLINE = '\n';
|
|
625
|
+
var FORWARD_SLASH = '/';
|
|
626
|
+
var ASTERISK = '*';
|
|
627
|
+
var EMPTY_STRING = '';
|
|
272
628
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
\***********************************************/
|
|
277
|
-
/*! no static exports found */
|
|
278
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
629
|
+
// types
|
|
630
|
+
var TYPE_COMMENT = 'comment';
|
|
631
|
+
var TYPE_DECLARATION = 'declaration';
|
|
279
632
|
|
|
280
|
-
|
|
633
|
+
/**
|
|
634
|
+
* @param {String} style
|
|
635
|
+
* @param {Object} [options]
|
|
636
|
+
* @return {Object[]}
|
|
637
|
+
* @throws {TypeError}
|
|
638
|
+
* @throws {Error}
|
|
639
|
+
*/
|
|
640
|
+
var inlineStyleParser = function(style, options) {
|
|
641
|
+
if (typeof style !== 'string') {
|
|
642
|
+
throw new TypeError('First argument must be a string');
|
|
643
|
+
}
|
|
281
644
|
|
|
282
|
-
|
|
645
|
+
if (!style) return [];
|
|
283
646
|
|
|
284
|
-
|
|
285
|
-
/*!**************************************************************************************!*\
|
|
286
|
-
!*** external {"amd":"react","commonjs":"react","commonjs2":"react","root":"React"} ***!
|
|
287
|
-
\**************************************************************************************/
|
|
288
|
-
/*! no static exports found */
|
|
289
|
-
/***/ (function(module, exports) {
|
|
647
|
+
options = options || {};
|
|
290
648
|
|
|
291
|
-
|
|
649
|
+
/**
|
|
650
|
+
* Positional.
|
|
651
|
+
*/
|
|
652
|
+
var lineno = 1;
|
|
653
|
+
var column = 1;
|
|
292
654
|
|
|
293
|
-
|
|
655
|
+
/**
|
|
656
|
+
* Update lineno and column based on `str`.
|
|
657
|
+
*
|
|
658
|
+
* @param {String} str
|
|
659
|
+
*/
|
|
660
|
+
function updatePosition(str) {
|
|
661
|
+
var lines = str.match(NEWLINE_REGEX);
|
|
662
|
+
if (lines) lineno += lines.length;
|
|
663
|
+
var i = str.lastIndexOf(NEWLINE);
|
|
664
|
+
column = ~i ? str.length - i : column + str.length;
|
|
665
|
+
}
|
|
294
666
|
|
|
295
|
-
|
|
296
|
-
|
|
667
|
+
/**
|
|
668
|
+
* Mark position and patch `node.position`.
|
|
669
|
+
*
|
|
670
|
+
* @return {Function}
|
|
671
|
+
*/
|
|
672
|
+
function position() {
|
|
673
|
+
var start = { line: lineno, column: column };
|
|
674
|
+
return function(node) {
|
|
675
|
+
node.position = new Position(start);
|
|
676
|
+
whitespace();
|
|
677
|
+
return node;
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* Store position information for a node.
|
|
683
|
+
*
|
|
684
|
+
* @constructor
|
|
685
|
+
* @property {Object} start
|
|
686
|
+
* @property {Object} end
|
|
687
|
+
* @property {undefined|String} source
|
|
688
|
+
*/
|
|
689
|
+
function Position(start) {
|
|
690
|
+
this.start = start;
|
|
691
|
+
this.end = { line: lineno, column: column };
|
|
692
|
+
this.source = options.source;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Non-enumerable source string.
|
|
697
|
+
*/
|
|
698
|
+
Position.prototype.content = style;
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Error `msg`.
|
|
702
|
+
*
|
|
703
|
+
* @param {String} msg
|
|
704
|
+
* @throws {Error}
|
|
705
|
+
*/
|
|
706
|
+
function error(msg) {
|
|
707
|
+
var err = new Error(
|
|
708
|
+
options.source + ':' + lineno + ':' + column + ': ' + msg
|
|
709
|
+
);
|
|
710
|
+
err.reason = msg;
|
|
711
|
+
err.filename = options.source;
|
|
712
|
+
err.line = lineno;
|
|
713
|
+
err.column = column;
|
|
714
|
+
err.source = style;
|
|
715
|
+
|
|
716
|
+
if (options.silent) ; else {
|
|
717
|
+
throw err;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Match `re` and return captures.
|
|
723
|
+
*
|
|
724
|
+
* @param {RegExp} re
|
|
725
|
+
* @return {undefined|Array}
|
|
726
|
+
*/
|
|
727
|
+
function match(re) {
|
|
728
|
+
var m = re.exec(style);
|
|
729
|
+
if (!m) return;
|
|
730
|
+
var str = m[0];
|
|
731
|
+
updatePosition(str);
|
|
732
|
+
style = style.slice(str.length);
|
|
733
|
+
return m;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Parse whitespace.
|
|
738
|
+
*/
|
|
739
|
+
function whitespace() {
|
|
740
|
+
match(WHITESPACE_REGEX);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* Parse comments.
|
|
745
|
+
*
|
|
746
|
+
* @param {Object[]} [rules]
|
|
747
|
+
* @return {Object[]}
|
|
748
|
+
*/
|
|
749
|
+
function comments(rules) {
|
|
750
|
+
var c;
|
|
751
|
+
rules = rules || [];
|
|
752
|
+
while ((c = comment())) {
|
|
753
|
+
if (c !== false) {
|
|
754
|
+
rules.push(c);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return rules;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Parse comment.
|
|
762
|
+
*
|
|
763
|
+
* @return {Object}
|
|
764
|
+
* @throws {Error}
|
|
765
|
+
*/
|
|
766
|
+
function comment() {
|
|
767
|
+
var pos = position();
|
|
768
|
+
if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;
|
|
769
|
+
|
|
770
|
+
var i = 2;
|
|
771
|
+
while (
|
|
772
|
+
EMPTY_STRING != style.charAt(i) &&
|
|
773
|
+
(ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))
|
|
774
|
+
) {
|
|
775
|
+
++i;
|
|
776
|
+
}
|
|
777
|
+
i += 2;
|
|
778
|
+
|
|
779
|
+
if (EMPTY_STRING === style.charAt(i - 1)) {
|
|
780
|
+
return error('End of comment missing');
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
var str = style.slice(2, i - 2);
|
|
784
|
+
column += 2;
|
|
785
|
+
updatePosition(str);
|
|
786
|
+
style = style.slice(i);
|
|
787
|
+
column += 2;
|
|
788
|
+
|
|
789
|
+
return pos({
|
|
790
|
+
type: TYPE_COMMENT,
|
|
791
|
+
comment: str
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Parse declaration.
|
|
797
|
+
*
|
|
798
|
+
* @return {Object}
|
|
799
|
+
* @throws {Error}
|
|
800
|
+
*/
|
|
801
|
+
function declaration() {
|
|
802
|
+
var pos = position();
|
|
803
|
+
|
|
804
|
+
// prop
|
|
805
|
+
var prop = match(PROPERTY_REGEX);
|
|
806
|
+
if (!prop) return;
|
|
807
|
+
comment();
|
|
808
|
+
|
|
809
|
+
// :
|
|
810
|
+
if (!match(COLON_REGEX)) return error("property missing ':'");
|
|
811
|
+
|
|
812
|
+
// val
|
|
813
|
+
var val = match(VALUE_REGEX);
|
|
814
|
+
|
|
815
|
+
var ret = pos({
|
|
816
|
+
type: TYPE_DECLARATION,
|
|
817
|
+
property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),
|
|
818
|
+
value: val
|
|
819
|
+
? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))
|
|
820
|
+
: EMPTY_STRING
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
// ;
|
|
824
|
+
match(SEMICOLON_REGEX);
|
|
825
|
+
|
|
826
|
+
return ret;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* Parse declarations.
|
|
831
|
+
*
|
|
832
|
+
* @return {Object[]}
|
|
833
|
+
*/
|
|
834
|
+
function declarations() {
|
|
835
|
+
var decls = [];
|
|
836
|
+
|
|
837
|
+
comments(decls);
|
|
838
|
+
|
|
839
|
+
// declarations
|
|
840
|
+
var decl;
|
|
841
|
+
while ((decl = declaration())) {
|
|
842
|
+
if (decl !== false) {
|
|
843
|
+
decls.push(decl);
|
|
844
|
+
comments(decls);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
return decls;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
whitespace();
|
|
852
|
+
return declarations();
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* Trim `str`.
|
|
857
|
+
*
|
|
858
|
+
* @param {String} str
|
|
859
|
+
* @return {String}
|
|
860
|
+
*/
|
|
861
|
+
function trim(str) {
|
|
862
|
+
return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Parses inline style to object.
|
|
867
|
+
*
|
|
868
|
+
* @example
|
|
869
|
+
* // returns { 'line-height': '42' }
|
|
870
|
+
* StyleToObject('line-height: 42;');
|
|
871
|
+
*
|
|
872
|
+
* @param {String} style - The inline style.
|
|
873
|
+
* @param {Function} [iterator] - The iterator function.
|
|
874
|
+
* @return {null|Object}
|
|
875
|
+
*/
|
|
876
|
+
function StyleToObject(style, iterator) {
|
|
877
|
+
var output = null;
|
|
878
|
+
if (!style || typeof style !== 'string') {
|
|
879
|
+
return output;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
var declaration;
|
|
883
|
+
var declarations = inlineStyleParser(style);
|
|
884
|
+
var hasIterator = typeof iterator === 'function';
|
|
885
|
+
var property;
|
|
886
|
+
var value;
|
|
887
|
+
|
|
888
|
+
for (var i = 0, len = declarations.length; i < len; i++) {
|
|
889
|
+
declaration = declarations[i];
|
|
890
|
+
property = declaration.property;
|
|
891
|
+
value = declaration.value;
|
|
892
|
+
|
|
893
|
+
if (hasIterator) {
|
|
894
|
+
iterator(property, value, declaration);
|
|
895
|
+
} else if (value) {
|
|
896
|
+
output || (output = {});
|
|
897
|
+
output[property] = value;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
return output;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
var styleToObject = StyleToObject;
|
|
905
|
+
|
|
906
|
+
var hyphenPatternRegex = /-([a-z])/g;
|
|
907
|
+
var CUSTOM_PROPERTY_OR_NO_HYPHEN_REGEX = /^--[a-zA-Z0-9-]+$|^[^-]+$/;
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Converts a string to camelCase.
|
|
911
|
+
*
|
|
912
|
+
* @param {String} string - The string.
|
|
913
|
+
* @return {String}
|
|
914
|
+
*/
|
|
915
|
+
function camelCase(string) {
|
|
916
|
+
if (typeof string !== 'string') {
|
|
917
|
+
throw new TypeError('First argument must be a string');
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// custom property or no hyphen found
|
|
921
|
+
if (CUSTOM_PROPERTY_OR_NO_HYPHEN_REGEX.test(string)) {
|
|
922
|
+
return string;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// convert to camelCase
|
|
926
|
+
return string
|
|
927
|
+
.toLowerCase()
|
|
928
|
+
.replace(hyphenPatternRegex, function(_, character) {
|
|
929
|
+
return character.toUpperCase();
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Swap key with value in an object.
|
|
935
|
+
*
|
|
936
|
+
* @param {Object} obj - The object.
|
|
937
|
+
* @param {Function} [override] - The override method.
|
|
938
|
+
* @return {Object} - The inverted object.
|
|
939
|
+
*/
|
|
940
|
+
function invertObject(obj, override) {
|
|
941
|
+
if (!obj || typeof obj !== 'object') {
|
|
942
|
+
throw new TypeError('First argument must be an object');
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
var key;
|
|
946
|
+
var value;
|
|
947
|
+
var isOverridePresent = typeof override === 'function';
|
|
948
|
+
var overrides = {};
|
|
949
|
+
var result = {};
|
|
950
|
+
|
|
951
|
+
for (key in obj) {
|
|
952
|
+
value = obj[key];
|
|
953
|
+
|
|
954
|
+
if (isOverridePresent) {
|
|
955
|
+
overrides = override(key, value);
|
|
956
|
+
if (overrides && overrides.length === 2) {
|
|
957
|
+
result[overrides[0]] = overrides[1];
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
if (typeof value === 'string') {
|
|
963
|
+
result[value] = key;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
return result;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
/**
|
|
971
|
+
* Check if a given tag is a custom component.
|
|
972
|
+
*
|
|
973
|
+
* @see {@link https://github.com/facebook/react/blob/v16.6.3/packages/react-dom/src/shared/isCustomComponent.js}
|
|
974
|
+
*
|
|
975
|
+
* @param {string} tagName - The name of the html tag.
|
|
976
|
+
* @param {Object} props - The props being passed to the element.
|
|
977
|
+
* @return {boolean}
|
|
978
|
+
*/
|
|
979
|
+
function isCustomComponent(tagName, props) {
|
|
980
|
+
if (tagName.indexOf('-') === -1) {
|
|
981
|
+
return props && typeof props.is === 'string';
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
switch (tagName) {
|
|
985
|
+
// These are reserved SVG and MathML elements.
|
|
986
|
+
// We don't mind this whitelist too much because we expect it to never grow.
|
|
987
|
+
// The alternative is to track the namespace in a few places which is convoluted.
|
|
988
|
+
// https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
|
|
989
|
+
case 'annotation-xml':
|
|
990
|
+
case 'color-profile':
|
|
991
|
+
case 'font-face':
|
|
992
|
+
case 'font-face-src':
|
|
993
|
+
case 'font-face-uri':
|
|
994
|
+
case 'font-face-format':
|
|
995
|
+
case 'font-face-name':
|
|
996
|
+
case 'missing-glyph':
|
|
997
|
+
return false;
|
|
998
|
+
default:
|
|
999
|
+
return true;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* @constant {Boolean}
|
|
1005
|
+
* @see {@link https://reactjs.org/blog/2017/09/08/dom-attributes-in-react-16.html}
|
|
1006
|
+
*/
|
|
1007
|
+
var PRESERVE_CUSTOM_ATTRIBUTES = react.version.split('.')[0] >= 16;
|
|
1008
|
+
|
|
1009
|
+
var utilities = {
|
|
1010
|
+
PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
|
|
1011
|
+
camelCase: camelCase,
|
|
1012
|
+
invertObject: invertObject,
|
|
1013
|
+
isCustomComponent: isCustomComponent
|
|
1014
|
+
};
|
|
1015
|
+
|
|
1016
|
+
var camelCase$1 = utilities.camelCase;
|
|
1017
|
+
|
|
1018
|
+
var htmlProperties = reactProperty.html;
|
|
1019
|
+
var svgProperties = reactProperty.svg;
|
|
1020
|
+
var isCustomAttribute = reactProperty.isCustomAttribute;
|
|
1021
|
+
|
|
1022
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Converts HTML/SVG DOM attributes to React props.
|
|
1026
|
+
*
|
|
1027
|
+
* @param {Object} [attributes={}] - The HTML/SVG DOM attributes.
|
|
1028
|
+
* @return {Object} - The React props.
|
|
1029
|
+
*/
|
|
1030
|
+
function attributesToProps(attributes) {
|
|
1031
|
+
attributes = attributes || {};
|
|
1032
|
+
|
|
1033
|
+
var attributeName;
|
|
1034
|
+
var attributeNameLowerCased;
|
|
1035
|
+
var attributeValue;
|
|
1036
|
+
var property;
|
|
1037
|
+
var props = {};
|
|
1038
|
+
|
|
1039
|
+
for (attributeName in attributes) {
|
|
1040
|
+
attributeValue = attributes[attributeName];
|
|
1041
|
+
|
|
1042
|
+
// ARIA (aria-*) or custom data (data-*) attribute
|
|
1043
|
+
if (isCustomAttribute(attributeName)) {
|
|
1044
|
+
props[attributeName] = attributeValue;
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// convert HTML attribute to React prop
|
|
1049
|
+
attributeNameLowerCased = attributeName.toLowerCase();
|
|
1050
|
+
if (hasOwnProperty.call(htmlProperties, attributeNameLowerCased)) {
|
|
1051
|
+
property = htmlProperties[attributeNameLowerCased];
|
|
1052
|
+
props[property.propertyName] =
|
|
1053
|
+
property.hasBooleanValue ||
|
|
1054
|
+
(property.hasOverloadedBooleanValue && !attributeValue)
|
|
1055
|
+
? true
|
|
1056
|
+
: attributeValue;
|
|
1057
|
+
continue;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
// convert SVG attribute to React prop
|
|
1061
|
+
if (hasOwnProperty.call(svgProperties, attributeName)) {
|
|
1062
|
+
property = svgProperties[attributeName];
|
|
1063
|
+
props[property.propertyName] = attributeValue;
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// preserve custom attribute if React >=16
|
|
1068
|
+
if (utilities.PRESERVE_CUSTOM_ATTRIBUTES) {
|
|
1069
|
+
props[attributeName] = attributeValue;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// convert inline style to object
|
|
1074
|
+
if (attributes.style != null) {
|
|
1075
|
+
props.style = cssToJs(attributes.style);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
return props;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Converts CSS style string to JS style object.
|
|
1083
|
+
*
|
|
1084
|
+
* @param {String} style - The CSS style.
|
|
1085
|
+
* @return {Object} - The JS style object.
|
|
1086
|
+
*/
|
|
1087
|
+
function cssToJs(style) {
|
|
1088
|
+
if (typeof style !== 'string') {
|
|
1089
|
+
throw new TypeError('First argument must be a string.');
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
var styleObj = {};
|
|
1093
|
+
|
|
1094
|
+
styleToObject(style, function(property, value) {
|
|
1095
|
+
// skip if it's a comment node
|
|
1096
|
+
if (property && value) {
|
|
1097
|
+
styleObj[camelCase$1(property)] = value;
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1101
|
+
return styleObj;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
var attributesToProps_1 = attributesToProps;
|
|
1105
|
+
|
|
1106
|
+
var cloneElement = react.cloneElement;
|
|
1107
|
+
var createElement = react.createElement;
|
|
1108
|
+
var isValidElement = react.isValidElement;
|
|
1109
|
+
|
|
1110
|
+
/**
|
|
1111
|
+
* Converts DOM nodes to React elements.
|
|
1112
|
+
*
|
|
1113
|
+
* @param {Array} nodes - The DOM nodes.
|
|
1114
|
+
* @param {Object} [options] - The additional options.
|
|
1115
|
+
* @param {Function} [options.replace] - The replace method.
|
|
1116
|
+
* @return {ReactElement|Array}
|
|
1117
|
+
*/
|
|
1118
|
+
function domToReact(nodes, options) {
|
|
1119
|
+
options = options || {};
|
|
1120
|
+
var result = [];
|
|
1121
|
+
var node;
|
|
1122
|
+
var hasReplace = typeof options.replace === 'function';
|
|
1123
|
+
var replaceElement;
|
|
1124
|
+
var props;
|
|
1125
|
+
var children;
|
|
1126
|
+
|
|
1127
|
+
for (var i = 0, len = nodes.length; i < len; i++) {
|
|
1128
|
+
node = nodes[i];
|
|
1129
|
+
|
|
1130
|
+
// replace with custom React element (if present)
|
|
1131
|
+
if (hasReplace) {
|
|
1132
|
+
replaceElement = options.replace(node);
|
|
1133
|
+
|
|
1134
|
+
if (isValidElement(replaceElement)) {
|
|
1135
|
+
// specify a "key" prop if element has siblings
|
|
1136
|
+
// https://fb.me/react-warning-keys
|
|
1137
|
+
if (len > 1) {
|
|
1138
|
+
replaceElement = cloneElement(replaceElement, {
|
|
1139
|
+
key: replaceElement.key || i
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
result.push(replaceElement);
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
if (node.type === 'text') {
|
|
1148
|
+
result.push(node.data);
|
|
1149
|
+
continue;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
props = node.attribs;
|
|
1153
|
+
if (!shouldPassAttributesUnaltered(node)) {
|
|
1154
|
+
// update values
|
|
1155
|
+
props = attributesToProps_1(node.attribs);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
children = null;
|
|
1159
|
+
|
|
1160
|
+
// node type for <script> is "script"
|
|
1161
|
+
// node type for <style> is "style"
|
|
1162
|
+
if (node.type === 'script' || node.type === 'style') {
|
|
1163
|
+
// prevent text in <script> or <style> from being escaped
|
|
1164
|
+
// https://facebook.github.io/react/tips/dangerously-set-inner-html.html
|
|
1165
|
+
if (node.children[0]) {
|
|
1166
|
+
props.dangerouslySetInnerHTML = {
|
|
1167
|
+
__html: node.children[0].data
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
} else if (node.type === 'tag') {
|
|
1171
|
+
// setting textarea value in children is an antipattern in React
|
|
1172
|
+
// https://reactjs.org/docs/forms.html#the-textarea-tag
|
|
1173
|
+
if (node.name === 'textarea' && node.children[0]) {
|
|
1174
|
+
props.defaultValue = node.children[0].data;
|
|
1175
|
+
|
|
1176
|
+
// continue recursion of creating React elements (if applicable)
|
|
1177
|
+
} else if (node.children && node.children.length) {
|
|
1178
|
+
children = domToReact(node.children, options);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
// skip all other cases (e.g., comment)
|
|
1182
|
+
} else {
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// specify a "key" prop if element has siblings
|
|
1187
|
+
// https://fb.me/react-warning-keys
|
|
1188
|
+
if (len > 1) {
|
|
1189
|
+
props.key = i;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
result.push(createElement(node.name, props, children));
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
return result.length === 1 ? result[0] : result;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
function shouldPassAttributesUnaltered(node) {
|
|
1199
|
+
return (
|
|
1200
|
+
utilities.PRESERVE_CUSTOM_ATTRIBUTES &&
|
|
1201
|
+
node.type === 'tag' &&
|
|
1202
|
+
utilities.isCustomComponent(node.name, node.attribs)
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
var domToReact_1 = domToReact;
|
|
1207
|
+
|
|
1208
|
+
/**
|
|
1209
|
+
* SVG elements are case-sensitive.
|
|
1210
|
+
*
|
|
1211
|
+
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#SVG_elements_A_to_Z}
|
|
1212
|
+
*/
|
|
1213
|
+
var CASE_SENSITIVE_TAG_NAMES = [
|
|
1214
|
+
'animateMotion',
|
|
1215
|
+
'animateTransform',
|
|
1216
|
+
'clipPath',
|
|
1217
|
+
'feBlend',
|
|
1218
|
+
'feColorMatrix',
|
|
1219
|
+
'feComponentTransfer',
|
|
1220
|
+
'feComposite',
|
|
1221
|
+
'feConvolveMatrix',
|
|
1222
|
+
'feDiffuseLighting',
|
|
1223
|
+
'feDisplacementMap',
|
|
1224
|
+
'feDropShadow',
|
|
1225
|
+
'feFlood',
|
|
1226
|
+
'feFuncA',
|
|
1227
|
+
'feFuncB',
|
|
1228
|
+
'feFuncG',
|
|
1229
|
+
'feFuncR',
|
|
1230
|
+
'feGaussainBlur',
|
|
1231
|
+
'feImage',
|
|
1232
|
+
'feMerge',
|
|
1233
|
+
'feMergeNode',
|
|
1234
|
+
'feMorphology',
|
|
1235
|
+
'feOffset',
|
|
1236
|
+
'fePointLight',
|
|
1237
|
+
'feSpecularLighting',
|
|
1238
|
+
'feSpotLight',
|
|
1239
|
+
'feTile',
|
|
1240
|
+
'feTurbulence',
|
|
1241
|
+
'foreignObject',
|
|
1242
|
+
'linearGradient',
|
|
1243
|
+
'radialGradient',
|
|
1244
|
+
'textPath'
|
|
1245
|
+
];
|
|
1246
|
+
|
|
1247
|
+
var constants = {
|
|
1248
|
+
CASE_SENSITIVE_TAG_NAMES: CASE_SENSITIVE_TAG_NAMES
|
|
1249
|
+
};
|
|
1250
|
+
|
|
1251
|
+
var CASE_SENSITIVE_TAG_NAMES$1 = constants.CASE_SENSITIVE_TAG_NAMES;
|
|
1252
|
+
|
|
1253
|
+
var caseSensitiveTagNamesMap = {};
|
|
1254
|
+
var tagName;
|
|
1255
|
+
for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES$1.length; i < len; i++) {
|
|
1256
|
+
tagName = CASE_SENSITIVE_TAG_NAMES$1[i];
|
|
1257
|
+
caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* Gets case-sensitive tag name.
|
|
1262
|
+
*
|
|
1263
|
+
* @param {String} tagName - The lowercase tag name.
|
|
1264
|
+
* @return {String|undefined}
|
|
1265
|
+
*/
|
|
1266
|
+
function getCaseSensitiveTagName(tagName) {
|
|
1267
|
+
return caseSensitiveTagNamesMap[tagName];
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Formats DOM attributes to a hash map.
|
|
1272
|
+
*
|
|
1273
|
+
* @param {NamedNodeMap} attributes - The list of attributes.
|
|
1274
|
+
* @return {Object} - A map of attribute name to value.
|
|
1275
|
+
*/
|
|
1276
|
+
function formatAttributes(attributes) {
|
|
1277
|
+
var result = {};
|
|
1278
|
+
var attribute;
|
|
1279
|
+
// `NamedNodeMap` is array-like
|
|
1280
|
+
for (var i = 0, len = attributes.length; i < len; i++) {
|
|
1281
|
+
attribute = attributes[i];
|
|
1282
|
+
result[attribute.name] = attribute.value;
|
|
1283
|
+
}
|
|
1284
|
+
return result;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* Corrects the tag name if it is case-sensitive (SVG).
|
|
1289
|
+
* Otherwise, returns the lowercase tag name (HTML).
|
|
1290
|
+
*
|
|
1291
|
+
* @param {String} tagName - The lowercase tag name.
|
|
1292
|
+
* @return {String} - The formatted tag name.
|
|
1293
|
+
*/
|
|
1294
|
+
function formatTagName(tagName) {
|
|
1295
|
+
tagName = tagName.toLowerCase();
|
|
1296
|
+
var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
|
|
1297
|
+
if (caseSensitiveTagName) {
|
|
1298
|
+
return caseSensitiveTagName;
|
|
1299
|
+
}
|
|
1300
|
+
return tagName;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Formats the browser DOM nodes to mimic the output of `htmlparser2.parseDOM()`.
|
|
1305
|
+
*
|
|
1306
|
+
* @param {NodeList} nodes - The DOM nodes.
|
|
1307
|
+
* @param {Object} [parentObj] - The formatted parent node.
|
|
1308
|
+
* @param {String} [directive] - The directive.
|
|
1309
|
+
* @return {Object[]} - The formatted DOM object.
|
|
1310
|
+
*/
|
|
1311
|
+
function formatDOM(nodes, parentObj, directive) {
|
|
1312
|
+
parentObj = parentObj || null;
|
|
1313
|
+
|
|
1314
|
+
var result = [];
|
|
1315
|
+
var node;
|
|
1316
|
+
var prevNode;
|
|
1317
|
+
var nodeObj;
|
|
1318
|
+
|
|
1319
|
+
// `NodeList` is array-like
|
|
1320
|
+
for (var i = 0, len = nodes.length; i < len; i++) {
|
|
1321
|
+
node = nodes[i];
|
|
1322
|
+
// reset
|
|
1323
|
+
nodeObj = {
|
|
1324
|
+
next: null,
|
|
1325
|
+
prev: result[i - 1] || null,
|
|
1326
|
+
parent: parentObj
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
// set the next node for the previous node (if applicable)
|
|
1330
|
+
prevNode = result[i - 1];
|
|
1331
|
+
if (prevNode) {
|
|
1332
|
+
prevNode.next = nodeObj;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
// set the node name if it's not "#text" or "#comment"
|
|
1336
|
+
// e.g., "div"
|
|
1337
|
+
if (node.nodeName[0] !== '#') {
|
|
1338
|
+
nodeObj.name = formatTagName(node.nodeName);
|
|
1339
|
+
// also, nodes of type "tag" have "attribs"
|
|
1340
|
+
nodeObj.attribs = {}; // default
|
|
1341
|
+
if (node.attributes && node.attributes.length) {
|
|
1342
|
+
nodeObj.attribs = formatAttributes(node.attributes);
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
// set the node type
|
|
1347
|
+
// e.g., "tag"
|
|
1348
|
+
switch (node.nodeType) {
|
|
1349
|
+
// 1 = element
|
|
1350
|
+
case 1:
|
|
1351
|
+
if (nodeObj.name === 'script' || nodeObj.name === 'style') {
|
|
1352
|
+
nodeObj.type = nodeObj.name;
|
|
1353
|
+
} else {
|
|
1354
|
+
nodeObj.type = 'tag';
|
|
1355
|
+
}
|
|
1356
|
+
// recursively format the children
|
|
1357
|
+
nodeObj.children = formatDOM(node.childNodes, nodeObj);
|
|
1358
|
+
break;
|
|
1359
|
+
// 2 = attribute
|
|
1360
|
+
// 3 = text
|
|
1361
|
+
case 3:
|
|
1362
|
+
nodeObj.type = 'text';
|
|
1363
|
+
nodeObj.data = node.nodeValue;
|
|
1364
|
+
break;
|
|
1365
|
+
// 8 = comment
|
|
1366
|
+
case 8:
|
|
1367
|
+
nodeObj.type = 'comment';
|
|
1368
|
+
nodeObj.data = node.nodeValue;
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
result.push(nodeObj);
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
if (directive) {
|
|
1376
|
+
result.unshift({
|
|
1377
|
+
name: directive.substring(0, directive.indexOf(' ')).toLowerCase(),
|
|
1378
|
+
data: directive,
|
|
1379
|
+
type: 'directive',
|
|
1380
|
+
next: result[0] ? result[0] : null,
|
|
1381
|
+
prev: null,
|
|
1382
|
+
parent: parentObj
|
|
1383
|
+
});
|
|
1384
|
+
|
|
1385
|
+
if (result[1]) {
|
|
1386
|
+
result[1].prev = result[0];
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
return result;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* Detects IE with or without version.
|
|
1395
|
+
*
|
|
1396
|
+
* @param {Number} [version] - The IE version to detect.
|
|
1397
|
+
* @return {Boolean} - Whether IE or the version has been detected.
|
|
1398
|
+
*/
|
|
1399
|
+
function isIE(version) {
|
|
1400
|
+
if (version) {
|
|
1401
|
+
return document.documentMode === version;
|
|
1402
|
+
}
|
|
1403
|
+
return /(MSIE |Trident\/|Edge\/)/.test(navigator.userAgent);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
var utilities$1 = {
|
|
1407
|
+
formatAttributes: formatAttributes,
|
|
1408
|
+
formatDOM: formatDOM,
|
|
1409
|
+
isIE: isIE
|
|
1410
|
+
};
|
|
1411
|
+
|
|
1412
|
+
// constants
|
|
1413
|
+
var HTML = 'html';
|
|
1414
|
+
var HEAD = 'head';
|
|
1415
|
+
var BODY = 'body';
|
|
1416
|
+
var FIRST_TAG_REGEX = /<([a-zA-Z]+[0-9]?)/; // e.g., <h1>
|
|
1417
|
+
var HEAD_TAG_REGEX = /<head.*>/i;
|
|
1418
|
+
var BODY_TAG_REGEX = /<body.*>/i;
|
|
1419
|
+
// http://www.w3.org/TR/html/syntax.html#void-elements
|
|
1420
|
+
var VOID_ELEMENTS_REGEX = /<(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)(.*?)\/?>/gi;
|
|
1421
|
+
|
|
1422
|
+
// detect IE browser
|
|
1423
|
+
var isIE9 = utilities$1.isIE(9);
|
|
1424
|
+
var isIE$1 = isIE9 || utilities$1.isIE();
|
|
1425
|
+
|
|
1426
|
+
/**
|
|
1427
|
+
* DOMParser (performance: slow).
|
|
1428
|
+
*
|
|
1429
|
+
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
|
|
1430
|
+
*/
|
|
1431
|
+
var parseFromString;
|
|
1432
|
+
|
|
1433
|
+
if (typeof window.DOMParser === 'function') {
|
|
1434
|
+
var domParser = new window.DOMParser();
|
|
1435
|
+
|
|
1436
|
+
// IE9 does not support 'text/html' MIME type
|
|
1437
|
+
// https://msdn.microsoft.com/en-us/library/ff975278(v=vs.85).aspx
|
|
1438
|
+
var mimeType = isIE9 ? 'text/xml' : 'text/html';
|
|
1439
|
+
|
|
1440
|
+
/**
|
|
1441
|
+
* Creates an HTML document using `DOMParser.parseFromString`.
|
|
1442
|
+
*
|
|
1443
|
+
* @param {string} html - The HTML string.
|
|
1444
|
+
* @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
|
|
1445
|
+
* @return {HTMLDocument}
|
|
1446
|
+
*/
|
|
1447
|
+
parseFromString = function domStringParser(html, tagName) {
|
|
1448
|
+
if (tagName) {
|
|
1449
|
+
html = '<' + tagName + '>' + html + '</' + tagName + '>';
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
// because IE9 only supports MIME type 'text/xml', void elements need to be self-closed
|
|
1453
|
+
if (isIE9) {
|
|
1454
|
+
html = html.replace(VOID_ELEMENTS_REGEX, '<$1$2$3/>');
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
return domParser.parseFromString(html, mimeType);
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/**
|
|
1462
|
+
* DOMImplementation (performance: fair).
|
|
1463
|
+
*
|
|
1464
|
+
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
|
|
1465
|
+
*/
|
|
1466
|
+
var parseFromDocument;
|
|
1467
|
+
|
|
1468
|
+
if (typeof document.implementation === 'object') {
|
|
1469
|
+
// title parameter is required in IE
|
|
1470
|
+
// https://msdn.microsoft.com/en-us/library/ff975457(v=vs.85).aspx
|
|
1471
|
+
var doc = document.implementation.createHTMLDocument(
|
|
1472
|
+
isIE$1 ? 'HTML_DOM_PARSER_TITLE' : undefined
|
|
1473
|
+
);
|
|
1474
|
+
|
|
1475
|
+
/**
|
|
1476
|
+
* Use HTML document created by `document.implementation.createHTMLDocument`.
|
|
1477
|
+
*
|
|
1478
|
+
* @param {string} html - The HTML string.
|
|
1479
|
+
* @param {string} [tagName] - The element to render the HTML (with 'body' as fallback).
|
|
1480
|
+
* @return {HTMLDocument}
|
|
1481
|
+
*/
|
|
1482
|
+
parseFromDocument = function createHTMLDocument(html, tagName) {
|
|
1483
|
+
if (tagName) {
|
|
1484
|
+
doc.documentElement.getElementsByTagName(tagName)[0].innerHTML = html;
|
|
1485
|
+
return doc;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
try {
|
|
1489
|
+
doc.documentElement.innerHTML = html;
|
|
1490
|
+
return doc;
|
|
1491
|
+
// fallback when certain elements in `documentElement` are read-only (IE9)
|
|
1492
|
+
} catch (err) {
|
|
1493
|
+
if (parseFromString) {
|
|
1494
|
+
return parseFromString(html);
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
/**
|
|
1501
|
+
* Template (performance: fast).
|
|
1502
|
+
*
|
|
1503
|
+
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
|
|
1504
|
+
*/
|
|
1505
|
+
var parseFromTemplate;
|
|
1506
|
+
var template = document.createElement('template');
|
|
1507
|
+
|
|
1508
|
+
if (template.content) {
|
|
1509
|
+
/**
|
|
1510
|
+
* Uses a template element (content fragment) to parse HTML.
|
|
1511
|
+
*
|
|
1512
|
+
* @param {string} html - The HTML string.
|
|
1513
|
+
* @return {NodeList}
|
|
1514
|
+
*/
|
|
1515
|
+
parseFromTemplate = function templateParser(html) {
|
|
1516
|
+
template.innerHTML = html;
|
|
1517
|
+
return template.content.childNodes;
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
// fallback document parser
|
|
1522
|
+
var parseWithFallback = parseFromDocument || parseFromString;
|
|
1523
|
+
|
|
1524
|
+
/**
|
|
1525
|
+
* Parses HTML string to DOM nodes.
|
|
1526
|
+
*
|
|
1527
|
+
* @param {string} html - The HTML string.
|
|
1528
|
+
* @return {NodeList|Array}
|
|
1529
|
+
*/
|
|
1530
|
+
function domparser(html) {
|
|
1531
|
+
var firstTagName;
|
|
1532
|
+
var match = html.match(FIRST_TAG_REGEX);
|
|
1533
|
+
|
|
1534
|
+
if (match && match[1]) {
|
|
1535
|
+
firstTagName = match[1].toLowerCase();
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
var doc;
|
|
1539
|
+
var element;
|
|
1540
|
+
var elements;
|
|
1541
|
+
|
|
1542
|
+
switch (firstTagName) {
|
|
1543
|
+
case HTML:
|
|
1544
|
+
if (parseFromString) {
|
|
1545
|
+
doc = parseFromString(html);
|
|
1546
|
+
|
|
1547
|
+
// the created document may come with filler head/body elements,
|
|
1548
|
+
// so make sure to remove them if they don't actually exist
|
|
1549
|
+
if (!HEAD_TAG_REGEX.test(html)) {
|
|
1550
|
+
element = doc.getElementsByTagName(HEAD)[0];
|
|
1551
|
+
if (element) {
|
|
1552
|
+
element.parentNode.removeChild(element);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
if (!BODY_TAG_REGEX.test(html)) {
|
|
1557
|
+
element = doc.getElementsByTagName(BODY)[0];
|
|
1558
|
+
if (element) {
|
|
1559
|
+
element.parentNode.removeChild(element);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
return doc.getElementsByTagName(HTML);
|
|
1564
|
+
}
|
|
1565
|
+
break;
|
|
1566
|
+
|
|
1567
|
+
case HEAD:
|
|
1568
|
+
case BODY:
|
|
1569
|
+
if (parseWithFallback) {
|
|
1570
|
+
elements = parseWithFallback(html).getElementsByTagName(firstTagName);
|
|
1571
|
+
|
|
1572
|
+
// account for possibility of sibling
|
|
1573
|
+
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
|
1574
|
+
return elements[0].parentNode.childNodes;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
return elements;
|
|
1578
|
+
}
|
|
1579
|
+
break;
|
|
1580
|
+
|
|
1581
|
+
// low-level tag or text
|
|
1582
|
+
default:
|
|
1583
|
+
if (parseFromTemplate) {
|
|
1584
|
+
return parseFromTemplate(html);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
if (parseWithFallback) {
|
|
1588
|
+
return parseWithFallback(html, BODY).getElementsByTagName(BODY)[0]
|
|
1589
|
+
.childNodes;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
break;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
return [];
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
var domparser_1 = domparser;
|
|
1599
|
+
|
|
1600
|
+
var formatDOM$1 = utilities$1.formatDOM;
|
|
1601
|
+
var isIE9$1 = utilities$1.isIE(9);
|
|
1602
|
+
|
|
1603
|
+
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
|
|
1604
|
+
|
|
1605
|
+
/**
|
|
1606
|
+
* Parses HTML and reformats DOM nodes output.
|
|
1607
|
+
*
|
|
1608
|
+
* @param {String} html - The HTML string.
|
|
1609
|
+
* @return {Array} - The formatted DOM nodes.
|
|
1610
|
+
*/
|
|
1611
|
+
function parseDOM(html) {
|
|
1612
|
+
if (typeof html !== 'string') {
|
|
1613
|
+
throw new TypeError('First argument must be a string');
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
if (!html) {
|
|
1617
|
+
return [];
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
// match directive
|
|
1621
|
+
var match = html.match(DIRECTIVE_REGEX);
|
|
1622
|
+
var directive;
|
|
1623
|
+
|
|
1624
|
+
if (match && match[1]) {
|
|
1625
|
+
directive = match[1];
|
|
1626
|
+
|
|
1627
|
+
// remove directive in IE9 because DOMParser uses
|
|
1628
|
+
// MIME type 'text/xml' instead of 'text/html'
|
|
1629
|
+
if (isIE9$1) {
|
|
1630
|
+
html = html.replace(match[0], '');
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
return formatDOM$1(domparser_1(html), null, directive);
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
var htmlToDomClient = parseDOM;
|
|
1638
|
+
|
|
1639
|
+
/**
|
|
1640
|
+
* Converts HTML string to React elements.
|
|
1641
|
+
*
|
|
1642
|
+
* @param {String} html - The HTML string to parse to React.
|
|
1643
|
+
* @param {Object} [options] - The parser options.
|
|
1644
|
+
* @param {Function} [options.replace] - The replace method.
|
|
1645
|
+
* @return {ReactElement|Array|String} - When parsed with HTML string, returns React elements; otherwise, returns string or empty array.
|
|
1646
|
+
*/
|
|
1647
|
+
function HTMLReactParser(html, options) {
|
|
1648
|
+
if (typeof html !== 'string') {
|
|
1649
|
+
throw new TypeError('First argument must be a string');
|
|
1650
|
+
}
|
|
1651
|
+
return domToReact_1(htmlToDomClient(html), options);
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
HTMLReactParser.domToReact = domToReact_1;
|
|
1655
|
+
HTMLReactParser.htmlToDOM = htmlToDomClient;
|
|
1656
|
+
|
|
1657
|
+
var htmlReactParser = HTMLReactParser;
|
|
1658
|
+
|
|
1659
|
+
return htmlReactParser;
|
|
1660
|
+
|
|
1661
|
+
}));
|