html-react-parser 4.2.3 → 4.2.5
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.
|
@@ -208,7 +208,7 @@
|
|
|
208
208
|
/**
|
|
209
209
|
* Text within the document.
|
|
210
210
|
*/
|
|
211
|
-
var Text
|
|
211
|
+
var Text = /** @class */ (function (_super) {
|
|
212
212
|
__extends(Text, _super);
|
|
213
213
|
function Text() {
|
|
214
214
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
@@ -224,11 +224,11 @@
|
|
|
224
224
|
});
|
|
225
225
|
return Text;
|
|
226
226
|
}(DataNode));
|
|
227
|
-
node.Text = Text
|
|
227
|
+
node.Text = Text;
|
|
228
228
|
/**
|
|
229
229
|
* Comments within the document.
|
|
230
230
|
*/
|
|
231
|
-
var Comment
|
|
231
|
+
var Comment = /** @class */ (function (_super) {
|
|
232
232
|
__extends(Comment, _super);
|
|
233
233
|
function Comment() {
|
|
234
234
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
@@ -244,11 +244,11 @@
|
|
|
244
244
|
});
|
|
245
245
|
return Comment;
|
|
246
246
|
}(DataNode));
|
|
247
|
-
node.Comment = Comment
|
|
247
|
+
node.Comment = Comment;
|
|
248
248
|
/**
|
|
249
249
|
* Processing instructions, including doc types.
|
|
250
250
|
*/
|
|
251
|
-
var ProcessingInstruction
|
|
251
|
+
var ProcessingInstruction = /** @class */ (function (_super) {
|
|
252
252
|
__extends(ProcessingInstruction, _super);
|
|
253
253
|
function ProcessingInstruction(name, data) {
|
|
254
254
|
var _this = _super.call(this, data) || this;
|
|
@@ -265,7 +265,7 @@
|
|
|
265
265
|
});
|
|
266
266
|
return ProcessingInstruction;
|
|
267
267
|
}(DataNode));
|
|
268
|
-
node.ProcessingInstruction = ProcessingInstruction
|
|
268
|
+
node.ProcessingInstruction = ProcessingInstruction;
|
|
269
269
|
/**
|
|
270
270
|
* A `Node` that can have children.
|
|
271
271
|
*/
|
|
@@ -356,7 +356,7 @@
|
|
|
356
356
|
/**
|
|
357
357
|
* An element within the DOM.
|
|
358
358
|
*/
|
|
359
|
-
var Element
|
|
359
|
+
var Element = /** @class */ (function (_super) {
|
|
360
360
|
__extends(Element, _super);
|
|
361
361
|
/**
|
|
362
362
|
* @param name Name of the tag, eg. `div`, `span`.
|
|
@@ -416,7 +416,7 @@
|
|
|
416
416
|
});
|
|
417
417
|
return Element;
|
|
418
418
|
}(NodeWithChildren));
|
|
419
|
-
node.Element = Element
|
|
419
|
+
node.Element = Element;
|
|
420
420
|
/**
|
|
421
421
|
* @param node Node to check.
|
|
422
422
|
* @returns `true` if the node is a `Element`, `false` otherwise.
|
|
@@ -483,14 +483,14 @@
|
|
|
483
483
|
if (recursive === void 0) { recursive = false; }
|
|
484
484
|
var result;
|
|
485
485
|
if (isText(node)) {
|
|
486
|
-
result = new Text
|
|
486
|
+
result = new Text(node.data);
|
|
487
487
|
}
|
|
488
488
|
else if (isComment(node)) {
|
|
489
|
-
result = new Comment
|
|
489
|
+
result = new Comment(node.data);
|
|
490
490
|
}
|
|
491
491
|
else if (isTag(node)) {
|
|
492
492
|
var children = recursive ? cloneChildren(node.children) : [];
|
|
493
|
-
var clone_1 = new Element
|
|
493
|
+
var clone_1 = new Element(node.name, __assign({}, node.attribs), children);
|
|
494
494
|
children.forEach(function (child) { return (child.parent = clone_1); });
|
|
495
495
|
if (node.namespace != null) {
|
|
496
496
|
clone_1.namespace = node.namespace;
|
|
@@ -519,7 +519,7 @@
|
|
|
519
519
|
result = clone_3;
|
|
520
520
|
}
|
|
521
521
|
else if (isDirective(node)) {
|
|
522
|
-
var instruction = new ProcessingInstruction
|
|
522
|
+
var instruction = new ProcessingInstruction(node.name, node.data);
|
|
523
523
|
if (node["x-name"] != null) {
|
|
524
524
|
instruction["x-name"] = node["x-name"];
|
|
525
525
|
instruction["x-publicId"] = node["x-publicId"];
|
|
@@ -714,6 +714,11 @@
|
|
|
714
714
|
exports.default = DomHandler;
|
|
715
715
|
} (lib$2));
|
|
716
716
|
|
|
717
|
+
var htmlToDom = {};
|
|
718
|
+
|
|
719
|
+
var domparser$1 = {};
|
|
720
|
+
|
|
721
|
+
Object.defineProperty(domparser$1, "__esModule", { value: true });
|
|
717
722
|
// constants
|
|
718
723
|
var HTML = 'html';
|
|
719
724
|
var HEAD = 'head';
|
|
@@ -722,377 +727,319 @@
|
|
|
722
727
|
// match-all-characters in case of newlines (DOTALL)
|
|
723
728
|
var HEAD_TAG_REGEX = /<head[^]*>/i;
|
|
724
729
|
var BODY_TAG_REGEX = /<body[^]*>/i;
|
|
725
|
-
|
|
726
730
|
// falls back to `parseFromString` if `createHTMLDocument` cannot be used
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
732
|
+
var parseFromDocument = function (html, tagName) {
|
|
733
|
+
/* istanbul ignore next */
|
|
734
|
+
throw new Error('This browser does not support `document.implementation.createHTMLDocument`');
|
|
731
735
|
};
|
|
732
|
-
|
|
733
|
-
var parseFromString = function () {
|
|
734
|
-
|
|
735
|
-
'This browser does not support `DOMParser.prototype.parseFromString`'
|
|
736
|
-
);
|
|
736
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
737
|
+
var parseFromString = function (html, tagName) {
|
|
738
|
+
/* istanbul ignore next */
|
|
739
|
+
throw new Error('This browser does not support `DOMParser.prototype.parseFromString`');
|
|
737
740
|
};
|
|
738
|
-
|
|
739
741
|
var DOMParser = typeof window === 'object' && window.DOMParser;
|
|
740
|
-
|
|
741
742
|
/**
|
|
742
743
|
* DOMParser (performance: slow).
|
|
743
744
|
*
|
|
744
745
|
* @see https://developer.mozilla.org/docs/Web/API/DOMParser#Parsing_an_SVG_or_HTML_document
|
|
745
746
|
*/
|
|
746
747
|
if (typeof DOMParser === 'function') {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
};
|
|
764
|
-
|
|
765
|
-
parseFromDocument = parseFromString;
|
|
748
|
+
var domParser_1 = new DOMParser();
|
|
749
|
+
var mimeType_1 = 'text/html';
|
|
750
|
+
/**
|
|
751
|
+
* Creates an HTML document using `DOMParser.parseFromString`.
|
|
752
|
+
*
|
|
753
|
+
* @param html - The HTML string.
|
|
754
|
+
* @param tagName - The element to render the HTML (with 'body' as fallback).
|
|
755
|
+
* @returns - Document.
|
|
756
|
+
*/
|
|
757
|
+
parseFromString = function (html, tagName) {
|
|
758
|
+
if (tagName) {
|
|
759
|
+
html = "<".concat(tagName, ">").concat(html, "</").concat(tagName, ">");
|
|
760
|
+
}
|
|
761
|
+
return domParser_1.parseFromString(html, mimeType_1);
|
|
762
|
+
};
|
|
763
|
+
parseFromDocument = parseFromString;
|
|
766
764
|
}
|
|
767
|
-
|
|
768
765
|
/**
|
|
769
766
|
* DOMImplementation (performance: fair).
|
|
770
767
|
*
|
|
771
768
|
* @see https://developer.mozilla.org/docs/Web/API/DOMImplementation/createHTMLDocument
|
|
772
769
|
*/
|
|
773
770
|
if (typeof document === 'object' && document.implementation) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
771
|
+
var htmlDocument_1 = document.implementation.createHTMLDocument();
|
|
772
|
+
/**
|
|
773
|
+
* Use HTML document created by `document.implementation.createHTMLDocument`.
|
|
774
|
+
*
|
|
775
|
+
* @param html - The HTML string.
|
|
776
|
+
* @param tagName - The element to render the HTML (with 'body' as fallback).
|
|
777
|
+
* @returns - Document
|
|
778
|
+
*/
|
|
779
|
+
parseFromDocument = function (html, tagName) {
|
|
780
|
+
if (tagName) {
|
|
781
|
+
var element = htmlDocument_1.documentElement.querySelector(tagName);
|
|
782
|
+
if (element) {
|
|
783
|
+
element.innerHTML = html;
|
|
784
|
+
}
|
|
785
|
+
return htmlDocument_1;
|
|
786
|
+
}
|
|
787
|
+
htmlDocument_1.documentElement.innerHTML = html;
|
|
788
|
+
return htmlDocument_1;
|
|
789
|
+
};
|
|
793
790
|
}
|
|
794
|
-
|
|
795
791
|
/**
|
|
796
792
|
* Template (performance: fast).
|
|
797
793
|
*
|
|
798
794
|
* @see https://developer.mozilla.org/docs/Web/HTML/Element/template
|
|
799
795
|
*/
|
|
800
|
-
var template =
|
|
801
|
-
|
|
802
|
-
|
|
796
|
+
var template = typeof document === 'object' && document.createElement('template');
|
|
797
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
803
798
|
var parseFromTemplate;
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
};
|
|
799
|
+
if (template && template.content) {
|
|
800
|
+
/**
|
|
801
|
+
* Uses a template element (content fragment) to parse HTML.
|
|
802
|
+
*
|
|
803
|
+
* @param html - HTML string.
|
|
804
|
+
* @returns - Nodes.
|
|
805
|
+
*/
|
|
806
|
+
parseFromTemplate = function (html) {
|
|
807
|
+
template.innerHTML = html;
|
|
808
|
+
return template.content.childNodes;
|
|
809
|
+
};
|
|
816
810
|
}
|
|
817
|
-
|
|
818
811
|
/**
|
|
819
812
|
* Parses HTML string to DOM nodes.
|
|
820
813
|
*
|
|
821
|
-
* @param
|
|
822
|
-
* @
|
|
814
|
+
* @param html - HTML markup.
|
|
815
|
+
* @returns - DOM nodes.
|
|
823
816
|
*/
|
|
824
|
-
function domparser
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
if (!HEAD_TAG_REGEX.test(html)) {
|
|
843
|
-
element = doc.querySelector(HEAD);
|
|
844
|
-
if (element) {
|
|
845
|
-
element.parentNode.removeChild(element);
|
|
817
|
+
function domparser(html) {
|
|
818
|
+
var _a, _b;
|
|
819
|
+
var match = html.match(FIRST_TAG_REGEX);
|
|
820
|
+
var firstTagName = match && match[1] ? match[1].toLowerCase() : '';
|
|
821
|
+
switch (firstTagName) {
|
|
822
|
+
case HTML: {
|
|
823
|
+
var doc = parseFromString(html);
|
|
824
|
+
// the created document may come with filler head/body elements,
|
|
825
|
+
// so make sure to remove them if they don't actually exist
|
|
826
|
+
if (!HEAD_TAG_REGEX.test(html)) {
|
|
827
|
+
var element = doc.querySelector(HEAD);
|
|
828
|
+
(_a = element === null || element === void 0 ? void 0 : element.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(element);
|
|
829
|
+
}
|
|
830
|
+
if (!BODY_TAG_REGEX.test(html)) {
|
|
831
|
+
var element = doc.querySelector(BODY);
|
|
832
|
+
(_b = element === null || element === void 0 ? void 0 : element.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(element);
|
|
833
|
+
}
|
|
834
|
+
return doc.querySelectorAll(HTML);
|
|
846
835
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
836
|
+
case HEAD:
|
|
837
|
+
case BODY: {
|
|
838
|
+
var elements = parseFromDocument(html).querySelectorAll(firstTagName);
|
|
839
|
+
// if there's a sibling element, then return both elements
|
|
840
|
+
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
|
841
|
+
return elements[0].parentNode.childNodes;
|
|
842
|
+
}
|
|
843
|
+
return elements;
|
|
853
844
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
// if there's a sibling element, then return both elements
|
|
864
|
-
if (BODY_TAG_REGEX.test(html) && HEAD_TAG_REGEX.test(html)) {
|
|
865
|
-
return elements[0].parentNode.childNodes;
|
|
866
|
-
}
|
|
867
|
-
return elements;
|
|
868
|
-
|
|
869
|
-
// low-level tag or text
|
|
870
|
-
default:
|
|
871
|
-
if (parseFromTemplate) {
|
|
872
|
-
return parseFromTemplate(html);
|
|
873
|
-
}
|
|
874
|
-
element = parseFromDocument(html, BODY).querySelector(BODY);
|
|
875
|
-
return element.childNodes;
|
|
876
|
-
}
|
|
845
|
+
// low-level tag or text
|
|
846
|
+
default: {
|
|
847
|
+
if (parseFromTemplate) {
|
|
848
|
+
return parseFromTemplate(html);
|
|
849
|
+
}
|
|
850
|
+
var element = parseFromDocument(html, BODY).querySelector(BODY);
|
|
851
|
+
return element.childNodes;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
877
854
|
}
|
|
855
|
+
domparser$1.default = domparser;
|
|
878
856
|
|
|
879
|
-
var
|
|
880
|
-
|
|
881
|
-
var utilities$5 = {};
|
|
882
|
-
|
|
883
|
-
var constants$1 = {};
|
|
884
|
-
|
|
885
|
-
/**
|
|
886
|
-
* SVG elements are case-sensitive.
|
|
887
|
-
*
|
|
888
|
-
* @see {@link https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z}
|
|
889
|
-
*/
|
|
857
|
+
var utilities$4 = {};
|
|
890
858
|
|
|
891
|
-
constants
|
|
892
|
-
'animateMotion',
|
|
893
|
-
'animateTransform',
|
|
894
|
-
'clipPath',
|
|
895
|
-
'feBlend',
|
|
896
|
-
'feColorMatrix',
|
|
897
|
-
'feComponentTransfer',
|
|
898
|
-
'feComposite',
|
|
899
|
-
'feConvolveMatrix',
|
|
900
|
-
'feDiffuseLighting',
|
|
901
|
-
'feDisplacementMap',
|
|
902
|
-
'feDropShadow',
|
|
903
|
-
'feFlood',
|
|
904
|
-
'feFuncA',
|
|
905
|
-
'feFuncB',
|
|
906
|
-
'feFuncG',
|
|
907
|
-
'feFuncR',
|
|
908
|
-
'feGaussianBlur',
|
|
909
|
-
'feImage',
|
|
910
|
-
'feMerge',
|
|
911
|
-
'feMergeNode',
|
|
912
|
-
'feMorphology',
|
|
913
|
-
'feOffset',
|
|
914
|
-
'fePointLight',
|
|
915
|
-
'feSpecularLighting',
|
|
916
|
-
'feSpotLight',
|
|
917
|
-
'feTile',
|
|
918
|
-
'feTurbulence',
|
|
919
|
-
'foreignObject',
|
|
920
|
-
'linearGradient',
|
|
921
|
-
'radialGradient',
|
|
922
|
-
'textPath'
|
|
923
|
-
];
|
|
924
|
-
|
|
925
|
-
var domhandler$1 = lib$2;
|
|
926
|
-
var constants = constants$1;
|
|
927
|
-
|
|
928
|
-
var CASE_SENSITIVE_TAG_NAMES = constants.CASE_SENSITIVE_TAG_NAMES;
|
|
929
|
-
|
|
930
|
-
var Comment = domhandler$1.Comment;
|
|
931
|
-
var Element = domhandler$1.Element;
|
|
932
|
-
var ProcessingInstruction = domhandler$1.ProcessingInstruction;
|
|
933
|
-
var Text = domhandler$1.Text;
|
|
934
|
-
|
|
935
|
-
var caseSensitiveTagNamesMap = {};
|
|
936
|
-
var tagName;
|
|
937
|
-
|
|
938
|
-
for (var i = 0, len = CASE_SENSITIVE_TAG_NAMES.length; i < len; i++) {
|
|
939
|
-
tagName = CASE_SENSITIVE_TAG_NAMES[i];
|
|
940
|
-
caseSensitiveTagNamesMap[tagName.toLowerCase()] = tagName;
|
|
941
|
-
}
|
|
859
|
+
var constants = {};
|
|
942
860
|
|
|
861
|
+
(function (exports) {
|
|
862
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
863
|
+
exports.CASE_SENSITIVE_TAG_NAMES_MAP = exports.CASE_SENSITIVE_TAG_NAMES = void 0;
|
|
864
|
+
/**
|
|
865
|
+
* SVG elements are case-sensitive.
|
|
866
|
+
*
|
|
867
|
+
* @see https://developer.mozilla.org/docs/Web/SVG/Element#svg_elements_a_to_z
|
|
868
|
+
*/
|
|
869
|
+
exports.CASE_SENSITIVE_TAG_NAMES = [
|
|
870
|
+
'animateMotion',
|
|
871
|
+
'animateTransform',
|
|
872
|
+
'clipPath',
|
|
873
|
+
'feBlend',
|
|
874
|
+
'feColorMatrix',
|
|
875
|
+
'feComponentTransfer',
|
|
876
|
+
'feComposite',
|
|
877
|
+
'feConvolveMatrix',
|
|
878
|
+
'feDiffuseLighting',
|
|
879
|
+
'feDisplacementMap',
|
|
880
|
+
'feDropShadow',
|
|
881
|
+
'feFlood',
|
|
882
|
+
'feFuncA',
|
|
883
|
+
'feFuncB',
|
|
884
|
+
'feFuncG',
|
|
885
|
+
'feFuncR',
|
|
886
|
+
'feGaussianBlur',
|
|
887
|
+
'feImage',
|
|
888
|
+
'feMerge',
|
|
889
|
+
'feMergeNode',
|
|
890
|
+
'feMorphology',
|
|
891
|
+
'feOffset',
|
|
892
|
+
'fePointLight',
|
|
893
|
+
'feSpecularLighting',
|
|
894
|
+
'feSpotLight',
|
|
895
|
+
'feTile',
|
|
896
|
+
'feTurbulence',
|
|
897
|
+
'foreignObject',
|
|
898
|
+
'linearGradient',
|
|
899
|
+
'radialGradient',
|
|
900
|
+
'textPath',
|
|
901
|
+
];
|
|
902
|
+
exports.CASE_SENSITIVE_TAG_NAMES_MAP = exports.CASE_SENSITIVE_TAG_NAMES.reduce(function (accumulator, tagName) {
|
|
903
|
+
accumulator[tagName.toLowerCase()] = tagName;
|
|
904
|
+
return accumulator;
|
|
905
|
+
}, {});
|
|
906
|
+
|
|
907
|
+
} (constants));
|
|
908
|
+
|
|
909
|
+
Object.defineProperty(utilities$4, "__esModule", { value: true });
|
|
910
|
+
utilities$4.formatDOM = utilities$4.formatAttributes = void 0;
|
|
911
|
+
var domhandler_1 = lib$2;
|
|
912
|
+
var constants_1 = constants;
|
|
943
913
|
/**
|
|
944
914
|
* Gets case-sensitive tag name.
|
|
945
915
|
*
|
|
946
|
-
* @param
|
|
947
|
-
* @returns
|
|
916
|
+
* @param tagName - Tag name in lowercase.
|
|
917
|
+
* @returns - Case-sensitive tag name.
|
|
948
918
|
*/
|
|
949
919
|
function getCaseSensitiveTagName(tagName) {
|
|
950
|
-
|
|
920
|
+
return constants_1.CASE_SENSITIVE_TAG_NAMES_MAP[tagName];
|
|
951
921
|
}
|
|
952
|
-
|
|
953
922
|
/**
|
|
954
923
|
* Formats DOM attributes to a hash map.
|
|
955
924
|
*
|
|
956
|
-
* @param
|
|
957
|
-
* @returns
|
|
925
|
+
* @param attributes - List of attributes.
|
|
926
|
+
* @returns - Map of attribute name to value.
|
|
958
927
|
*/
|
|
959
928
|
function formatAttributes(attributes) {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
929
|
+
var map = {};
|
|
930
|
+
var index = 0;
|
|
931
|
+
var attributesLength = attributes.length;
|
|
932
|
+
// `NamedNodeMap` is array-like
|
|
933
|
+
for (; index < attributesLength; index++) {
|
|
934
|
+
var attribute = attributes[index];
|
|
935
|
+
map[attribute.name] = attribute.value;
|
|
936
|
+
}
|
|
937
|
+
return map;
|
|
968
938
|
}
|
|
969
|
-
|
|
939
|
+
utilities$4.formatAttributes = formatAttributes;
|
|
970
940
|
/**
|
|
971
941
|
* Corrects the tag name if it is case-sensitive (SVG).
|
|
972
942
|
* Otherwise, returns the lowercase tag name (HTML).
|
|
973
943
|
*
|
|
974
|
-
* @param
|
|
975
|
-
* @returns
|
|
944
|
+
* @param tagName - Lowercase tag name.
|
|
945
|
+
* @returns - Formatted tag name.
|
|
976
946
|
*/
|
|
977
947
|
function formatTagName(tagName) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
948
|
+
tagName = tagName.toLowerCase();
|
|
949
|
+
var caseSensitiveTagName = getCaseSensitiveTagName(tagName);
|
|
950
|
+
if (caseSensitiveTagName) {
|
|
951
|
+
return caseSensitiveTagName;
|
|
952
|
+
}
|
|
953
|
+
return tagName;
|
|
984
954
|
}
|
|
985
|
-
|
|
986
955
|
/**
|
|
987
956
|
* Transforms DOM nodes to `domhandler` nodes.
|
|
988
957
|
*
|
|
989
|
-
* @param
|
|
990
|
-
* @param
|
|
991
|
-
* @param
|
|
992
|
-
* @returns
|
|
958
|
+
* @param nodes - DOM nodes.
|
|
959
|
+
* @param parent - Parent node.
|
|
960
|
+
* @param directive - Directive.
|
|
961
|
+
* @returns - Nodes.
|
|
993
962
|
*/
|
|
994
|
-
function formatDOM
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
var tagName;
|
|
998
|
-
|
|
999
|
-
for (var index = 0, len = nodes.length; index < len; index++) {
|
|
1000
|
-
var node = nodes[index];
|
|
963
|
+
function formatDOM(nodes, parent, directive) {
|
|
964
|
+
if (parent === void 0) { parent = null; }
|
|
965
|
+
var result = [];
|
|
1001
966
|
var current;
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
967
|
+
var index = 0;
|
|
968
|
+
var nodesLength = nodes.length;
|
|
969
|
+
for (; index < nodesLength; index++) {
|
|
970
|
+
var node = nodes[index];
|
|
971
|
+
// set the node data given the type
|
|
972
|
+
switch (node.nodeType) {
|
|
973
|
+
case 1: {
|
|
974
|
+
var tagName = formatTagName(node.nodeName);
|
|
975
|
+
// script, style, or tag
|
|
976
|
+
current = new domhandler_1.Element(tagName, formatAttributes(node.attributes));
|
|
977
|
+
current.children = formatDOM(
|
|
978
|
+
// template children are on content
|
|
979
|
+
tagName === 'template'
|
|
980
|
+
? node.content.childNodes
|
|
981
|
+
: node.childNodes, current);
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
case 3:
|
|
985
|
+
current = new domhandler_1.Text(node.nodeValue);
|
|
986
|
+
break;
|
|
987
|
+
case 8:
|
|
988
|
+
current = new domhandler_1.Comment(node.nodeValue);
|
|
989
|
+
break;
|
|
990
|
+
default:
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
// set previous node next
|
|
994
|
+
var prev = result[index - 1] || null;
|
|
995
|
+
if (prev) {
|
|
996
|
+
prev.next = current;
|
|
997
|
+
}
|
|
998
|
+
// set properties for current node
|
|
999
|
+
current.parent = parent;
|
|
1000
|
+
current.prev = prev;
|
|
1001
|
+
current.next = null;
|
|
1002
|
+
result.push(current);
|
|
1032
1003
|
}
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
if (directive) {
|
|
1043
|
-
current = new ProcessingInstruction(
|
|
1044
|
-
directive.substring(0, directive.indexOf(' ')).toLowerCase(),
|
|
1045
|
-
directive
|
|
1046
|
-
);
|
|
1047
|
-
current.next = result[0] || null;
|
|
1048
|
-
current.parent = parent;
|
|
1049
|
-
result.unshift(current);
|
|
1050
|
-
|
|
1051
|
-
if (result[1]) {
|
|
1052
|
-
result[1].prev = result[0];
|
|
1004
|
+
if (directive) {
|
|
1005
|
+
current = new domhandler_1.ProcessingInstruction(directive.substring(0, directive.indexOf(' ')).toLowerCase(), directive);
|
|
1006
|
+
current.next = result[0] || null;
|
|
1007
|
+
current.parent = parent;
|
|
1008
|
+
result.unshift(current);
|
|
1009
|
+
if (result[1]) {
|
|
1010
|
+
result[1].prev = result[0];
|
|
1011
|
+
}
|
|
1053
1012
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
return result;
|
|
1013
|
+
return result;
|
|
1057
1014
|
}
|
|
1015
|
+
utilities$4.formatDOM = formatDOM;
|
|
1058
1016
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
var
|
|
1064
|
-
|
|
1065
|
-
var formatDOM = utilities$4.formatDOM;
|
|
1066
|
-
|
|
1017
|
+
var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
1018
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
1019
|
+
};
|
|
1020
|
+
Object.defineProperty(htmlToDom, "__esModule", { value: true });
|
|
1021
|
+
var domparser_1 = __importDefault$2(domparser$1);
|
|
1022
|
+
var utilities_1$1 = utilities$4;
|
|
1067
1023
|
var DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; // e.g., <!doctype html>
|
|
1068
|
-
|
|
1069
1024
|
/**
|
|
1070
1025
|
* Parses HTML string to DOM nodes in browser.
|
|
1071
1026
|
*
|
|
1072
|
-
* @param
|
|
1073
|
-
* @
|
|
1027
|
+
* @param html - HTML markup.
|
|
1028
|
+
* @returns - DOM elements.
|
|
1074
1029
|
*/
|
|
1075
1030
|
function HTMLDOMParser(html) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
var directive;
|
|
1087
|
-
|
|
1088
|
-
if (match && match[1]) {
|
|
1089
|
-
directive = match[1];
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
return formatDOM(domparser(html), null, directive);
|
|
1031
|
+
if (typeof html !== 'string') {
|
|
1032
|
+
throw new TypeError('First argument must be a string');
|
|
1033
|
+
}
|
|
1034
|
+
if (html === '') {
|
|
1035
|
+
return [];
|
|
1036
|
+
}
|
|
1037
|
+
// match directive
|
|
1038
|
+
var match = html.match(DIRECTIVE_REGEX);
|
|
1039
|
+
var directive = match ? match[1] : undefined;
|
|
1040
|
+
return (0, utilities_1$1.formatDOM)((0, domparser_1.default)(html), null, directive);
|
|
1093
1041
|
}
|
|
1094
|
-
|
|
1095
|
-
var htmlToDom = HTMLDOMParser;
|
|
1042
|
+
htmlToDom.default = HTMLDOMParser;
|
|
1096
1043
|
|
|
1097
1044
|
var lib = {};
|
|
1098
1045
|
|
|
@@ -1908,9 +1855,9 @@
|
|
|
1908
1855
|
lib.isCustomAttribute = isCustomAttribute;
|
|
1909
1856
|
lib.possibleStandardNames = possibleStandardNames;
|
|
1910
1857
|
|
|
1911
|
-
var cjs = {};
|
|
1858
|
+
var cjs$1 = {};
|
|
1912
1859
|
|
|
1913
|
-
var
|
|
1860
|
+
var cjs = {};
|
|
1914
1861
|
|
|
1915
1862
|
// http://www.w3.org/TR/CSS21/grammar.html
|
|
1916
1863
|
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
|
|
@@ -1945,7 +1892,7 @@
|
|
|
1945
1892
|
* @throws {TypeError}
|
|
1946
1893
|
* @throws {Error}
|
|
1947
1894
|
*/
|
|
1948
|
-
var inlineStyleParser = function(style, options) {
|
|
1895
|
+
var inlineStyleParser = function (style, options) {
|
|
1949
1896
|
if (typeof style !== 'string') {
|
|
1950
1897
|
throw new TypeError('First argument must be a string');
|
|
1951
1898
|
}
|
|
@@ -1979,7 +1926,7 @@
|
|
|
1979
1926
|
*/
|
|
1980
1927
|
function position() {
|
|
1981
1928
|
var start = { line: lineno, column: column };
|
|
1982
|
-
return function(node) {
|
|
1929
|
+
return function (node) {
|
|
1983
1930
|
node.position = new Position(start);
|
|
1984
1931
|
whitespace();
|
|
1985
1932
|
return node;
|
|
@@ -2170,51 +2117,48 @@
|
|
|
2170
2117
|
return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
|
|
2171
2118
|
}
|
|
2172
2119
|
|
|
2173
|
-
var
|
|
2174
|
-
|
|
2120
|
+
var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2121
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2122
|
+
};
|
|
2123
|
+
Object.defineProperty(cjs, "__esModule", { value: true });
|
|
2124
|
+
var inline_style_parser_1 = __importDefault$1(inlineStyleParser);
|
|
2175
2125
|
/**
|
|
2176
2126
|
* Parses inline style to object.
|
|
2177
2127
|
*
|
|
2178
|
-
* @
|
|
2179
|
-
*
|
|
2180
|
-
*
|
|
2128
|
+
* @param style - Inline style.
|
|
2129
|
+
* @param iterator - Iterator.
|
|
2130
|
+
* @returns - Style object or null.
|
|
2131
|
+
*
|
|
2132
|
+
* @example Parsing inline style to object:
|
|
2181
2133
|
*
|
|
2182
|
-
*
|
|
2183
|
-
*
|
|
2184
|
-
*
|
|
2134
|
+
* ```js
|
|
2135
|
+
* import parse from 'style-to-object';
|
|
2136
|
+
* parse('line-height: 42;'); // { 'line-height': '42' }
|
|
2137
|
+
* ```
|
|
2185
2138
|
*/
|
|
2186
2139
|
function StyleToObject(style, iterator) {
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
}
|
|
2191
|
-
|
|
2192
|
-
var declaration;
|
|
2193
|
-
var declarations = parse(style);
|
|
2194
|
-
var hasIterator = typeof iterator === 'function';
|
|
2195
|
-
var property;
|
|
2196
|
-
var value;
|
|
2197
|
-
|
|
2198
|
-
for (var i = 0, len = declarations.length; i < len; i++) {
|
|
2199
|
-
declaration = declarations[i];
|
|
2200
|
-
property = declaration.property;
|
|
2201
|
-
value = declaration.value;
|
|
2202
|
-
|
|
2203
|
-
if (hasIterator) {
|
|
2204
|
-
iterator(property, value, declaration);
|
|
2205
|
-
} else if (value) {
|
|
2206
|
-
output || (output = {});
|
|
2207
|
-
output[property] = value;
|
|
2140
|
+
var styleObject = null;
|
|
2141
|
+
if (!style || typeof style !== 'string') {
|
|
2142
|
+
return styleObject;
|
|
2208
2143
|
}
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2144
|
+
var declarations = (0, inline_style_parser_1.default)(style);
|
|
2145
|
+
var hasIterator = typeof iterator === 'function';
|
|
2146
|
+
declarations.forEach(function (declaration) {
|
|
2147
|
+
if (declaration.type !== 'declaration') {
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2150
|
+
var property = declaration.property, value = declaration.value;
|
|
2151
|
+
if (hasIterator) {
|
|
2152
|
+
iterator(property, value, declaration);
|
|
2153
|
+
}
|
|
2154
|
+
else if (value) {
|
|
2155
|
+
styleObject = styleObject || {};
|
|
2156
|
+
styleObject[property] = value;
|
|
2157
|
+
}
|
|
2158
|
+
});
|
|
2159
|
+
return styleObject;
|
|
2212
2160
|
}
|
|
2213
|
-
|
|
2214
|
-
styleToObject.exports = StyleToObject;
|
|
2215
|
-
styleToObject.exports.default = StyleToObject; // ESM support
|
|
2216
|
-
|
|
2217
|
-
var styleToObjectExports = styleToObject.exports;
|
|
2161
|
+
cjs.default = StyleToObject;
|
|
2218
2162
|
|
|
2219
2163
|
var utilities$3 = {};
|
|
2220
2164
|
|
|
@@ -2253,8 +2197,8 @@
|
|
|
2253
2197
|
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
2254
2198
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2255
2199
|
};
|
|
2256
|
-
Object.defineProperty(cjs, "__esModule", { value: true });
|
|
2257
|
-
var style_to_object_1 = __importDefault(
|
|
2200
|
+
Object.defineProperty(cjs$1, "__esModule", { value: true });
|
|
2201
|
+
var style_to_object_1 = __importDefault(cjs);
|
|
2258
2202
|
var utilities_1 = utilities$3;
|
|
2259
2203
|
function StyleToJS(style, options) {
|
|
2260
2204
|
var output = {};
|
|
@@ -2268,10 +2212,10 @@
|
|
|
2268
2212
|
});
|
|
2269
2213
|
return output;
|
|
2270
2214
|
}
|
|
2271
|
-
cjs.default = StyleToJS;
|
|
2215
|
+
cjs$1.default = StyleToJS;
|
|
2272
2216
|
|
|
2273
2217
|
var React$1 = require$$0;
|
|
2274
|
-
var styleToJS = cjs.default;
|
|
2218
|
+
var styleToJS = cjs$1.default;
|
|
2275
2219
|
|
|
2276
2220
|
/**
|
|
2277
2221
|
* Swap key with value in an object.
|
|
@@ -2648,7 +2592,7 @@
|
|
|
2648
2592
|
var domToReact_1 = domToReact$1;
|
|
2649
2593
|
|
|
2650
2594
|
var domhandler = lib$2;
|
|
2651
|
-
var htmlToDOM = htmlToDom;
|
|
2595
|
+
var htmlToDOM = htmlToDom.default;
|
|
2652
2596
|
|
|
2653
2597
|
var attributesToProps = attributesToProps$2;
|
|
2654
2598
|
var domToReact = domToReact_1;
|