happy-dom 15.11.6 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/PropertySymbol.cjs +12 -9
- package/cjs/PropertySymbol.cjs.map +1 -1
- package/cjs/PropertySymbol.d.ts +4 -1
- package/cjs/PropertySymbol.d.ts.map +1 -1
- package/cjs/browser/utilities/BrowserFrameURL.cjs +1 -1
- package/cjs/browser/utilities/BrowserFrameURL.cjs.map +1 -1
- package/cjs/browser/utilities/BrowserFrameURL.d.ts +1 -1
- package/cjs/browser/utilities/BrowserFrameURL.d.ts.map +1 -1
- package/cjs/config/HTMLElementConfig.cjs +42 -16
- package/cjs/config/HTMLElementConfig.cjs.map +1 -1
- package/cjs/config/HTMLElementConfig.d.ts +7 -0
- package/cjs/config/HTMLElementConfig.d.ts.map +1 -1
- package/cjs/config/HTMLElementConfigContentModelEnum.cjs +3 -0
- package/cjs/config/HTMLElementConfigContentModelEnum.cjs.map +1 -1
- package/cjs/config/HTMLElementConfigContentModelEnum.d.ts +3 -0
- package/cjs/config/HTMLElementConfigContentModelEnum.d.ts.map +1 -1
- package/cjs/config/NamespaceURI.cjs +2 -0
- package/cjs/config/NamespaceURI.cjs.map +1 -1
- package/cjs/config/NamespaceURI.d.ts +2 -0
- package/cjs/config/NamespaceURI.d.ts.map +1 -1
- package/cjs/css/declaration/CSSStyleDeclaration.cjs +1 -1
- package/cjs/css/declaration/CSSStyleDeclaration.cjs.map +1 -1
- package/cjs/css/declaration/CSSStyleDeclaration.d.ts.map +1 -1
- package/cjs/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.cjs +2 -2
- package/cjs/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.cjs.map +1 -1
- package/cjs/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.d.ts.map +1 -1
- package/cjs/custom-element/CustomElementReactionStack.cjs +100 -0
- package/cjs/custom-element/CustomElementReactionStack.cjs.map +1 -0
- package/cjs/custom-element/CustomElementReactionStack.d.ts +27 -0
- package/cjs/custom-element/CustomElementReactionStack.d.ts.map +1 -0
- package/cjs/custom-element/CustomElementRegistry.cjs +32 -45
- package/cjs/custom-element/CustomElementRegistry.cjs.map +1 -1
- package/cjs/custom-element/CustomElementRegistry.d.ts +2 -6
- package/cjs/custom-element/CustomElementRegistry.d.ts.map +1 -1
- package/cjs/custom-element/CustomElementUtility.cjs +35 -0
- package/cjs/custom-element/CustomElementUtility.cjs.map +1 -0
- package/cjs/custom-element/CustomElementUtility.d.ts +14 -0
- package/cjs/custom-element/CustomElementUtility.d.ts.map +1 -0
- package/cjs/custom-element/ICustomElementDefinition.cjs +3 -0
- package/cjs/custom-element/ICustomElementDefinition.cjs.map +1 -0
- package/cjs/custom-element/ICustomElementDefinition.d.ts +12 -0
- package/cjs/custom-element/ICustomElementDefinition.d.ts.map +1 -0
- package/cjs/dom/DOMStringMap.cjs +8 -8
- package/cjs/dom/DOMStringMap.cjs.map +1 -1
- package/cjs/dom/DOMStringMap.d.ts.map +1 -1
- package/cjs/dom/DOMTokenList.cjs +1 -1
- package/cjs/dom/DOMTokenList.cjs.map +1 -1
- package/cjs/dom-parser/DOMParser.cjs +5 -67
- package/cjs/dom-parser/DOMParser.cjs.map +1 -1
- package/cjs/dom-parser/DOMParser.d.ts +0 -1
- package/cjs/dom-parser/DOMParser.d.ts.map +1 -1
- package/cjs/exception/DOMExceptionNameEnum.cjs +1 -0
- package/cjs/exception/DOMExceptionNameEnum.cjs.map +1 -1
- package/cjs/exception/DOMExceptionNameEnum.d.ts +2 -1
- package/cjs/exception/DOMExceptionNameEnum.d.ts.map +1 -1
- package/cjs/history/History.cjs +8 -8
- package/cjs/history/History.cjs.map +1 -1
- package/cjs/history/History.d.ts +2 -2
- package/cjs/history/History.d.ts.map +1 -1
- package/cjs/html-parser/HTMLParser.cjs +726 -0
- package/cjs/html-parser/HTMLParser.cjs.map +1 -0
- package/cjs/html-parser/HTMLParser.d.ts +91 -0
- package/cjs/html-parser/HTMLParser.d.ts.map +1 -0
- package/cjs/html-serializer/HTMLSerializer.cjs +152 -0
- package/cjs/html-serializer/HTMLSerializer.cjs.map +1 -0
- package/cjs/html-serializer/HTMLSerializer.d.ts +36 -0
- package/cjs/html-serializer/HTMLSerializer.d.ts.map +1 -0
- package/cjs/nodes/document/Document.cjs +105 -121
- package/cjs/nodes/document/Document.cjs.map +1 -1
- package/cjs/nodes/document/Document.d.ts +8 -0
- package/cjs/nodes/document/Document.d.ts.map +1 -1
- package/cjs/nodes/element/Element.cjs +35 -53
- package/cjs/nodes/element/Element.cjs.map +1 -1
- package/cjs/nodes/element/Element.d.ts +2 -12
- package/cjs/nodes/element/Element.d.ts.map +1 -1
- package/cjs/nodes/element/HTMLCollection.cjs +5 -9
- package/cjs/nodes/element/HTMLCollection.cjs.map +1 -1
- package/cjs/nodes/element/HTMLCollection.d.ts.map +1 -1
- package/cjs/nodes/element/NamedNodeMap.cjs +39 -52
- package/cjs/nodes/element/NamedNodeMap.cjs.map +1 -1
- package/cjs/nodes/element/NamedNodeMap.d.ts +1 -16
- package/cjs/nodes/element/NamedNodeMap.d.ts.map +1 -1
- package/cjs/nodes/element/NamedNodeMapProxyFactory.cjs +12 -14
- package/cjs/nodes/element/NamedNodeMapProxyFactory.cjs.map +1 -1
- package/cjs/nodes/element/NamedNodeMapProxyFactory.d.ts.map +1 -1
- package/cjs/nodes/html-button-element/HTMLButtonElement.cjs +1 -1
- package/cjs/nodes/html-button-element/HTMLButtonElement.cjs.map +1 -1
- package/cjs/nodes/html-button-element/HTMLButtonElement.d.ts.map +1 -1
- package/cjs/nodes/html-document/HTMLDocument.cjs +33 -2
- package/cjs/nodes/html-document/HTMLDocument.cjs.map +1 -1
- package/cjs/nodes/html-document/HTMLDocument.d.ts +10 -0
- package/cjs/nodes/html-document/HTMLDocument.d.ts.map +1 -1
- package/cjs/nodes/html-element/HTMLElement.cjs +52 -22
- package/cjs/nodes/html-element/HTMLElement.cjs.map +1 -1
- package/cjs/nodes/html-element/HTMLElement.d.ts +34 -0
- package/cjs/nodes/html-element/HTMLElement.d.ts.map +1 -1
- package/cjs/nodes/html-field-set-element/HTMLFieldSetElement.cjs +1 -1
- package/cjs/nodes/html-field-set-element/HTMLFieldSetElement.cjs.map +1 -1
- package/cjs/nodes/html-field-set-element/HTMLFieldSetElement.d.ts.map +1 -1
- package/cjs/nodes/html-form-element/HTMLFormElement.cjs +5 -8
- package/cjs/nodes/html-form-element/HTMLFormElement.cjs.map +1 -1
- package/cjs/nodes/html-form-element/HTMLFormElement.d.ts.map +1 -1
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.cjs +1 -1
- package/cjs/nodes/html-iframe-element/HTMLIFrameElement.cjs.map +1 -1
- package/cjs/nodes/html-input-element/HTMLInputElement.cjs +1 -1
- package/cjs/nodes/html-input-element/HTMLInputElement.cjs.map +1 -1
- package/cjs/nodes/html-input-element/HTMLInputElement.d.ts.map +1 -1
- package/cjs/nodes/html-media-element/TextTrackList.cjs +1 -1
- package/cjs/nodes/html-media-element/TextTrackList.cjs.map +1 -1
- package/cjs/nodes/html-object-element/HTMLObjectElement.cjs +1 -1
- package/cjs/nodes/html-object-element/HTMLObjectElement.cjs.map +1 -1
- package/cjs/nodes/html-object-element/HTMLObjectElement.d.ts.map +1 -1
- package/cjs/nodes/html-output-element/HTMLOutputElement.cjs +1 -1
- package/cjs/nodes/html-output-element/HTMLOutputElement.cjs.map +1 -1
- package/cjs/nodes/html-output-element/HTMLOutputElement.d.ts.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.cjs +3 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.cjs.map +1 -1
- package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
- package/cjs/nodes/html-select-element/HTMLSelectElement.cjs +2 -2
- package/cjs/nodes/html-select-element/HTMLSelectElement.cjs.map +1 -1
- package/cjs/nodes/html-select-element/HTMLSelectElement.d.ts.map +1 -1
- package/cjs/nodes/html-table-element/HTMLTableElement.cjs +9 -1
- package/cjs/nodes/html-table-element/HTMLTableElement.cjs.map +1 -1
- package/cjs/nodes/html-table-element/HTMLTableElement.d.ts.map +1 -1
- package/cjs/nodes/html-table-row-element/HTMLTableRowElement.cjs +1 -1
- package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs +15 -17
- package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs.map +1 -1
- package/cjs/nodes/html-template-element/HTMLTemplateElement.d.ts +2 -2
- package/cjs/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
- package/cjs/nodes/html-text-area-element/HTMLTextAreaElement.cjs +1 -1
- package/cjs/nodes/html-text-area-element/HTMLTextAreaElement.cjs.map +1 -1
- package/cjs/nodes/html-text-area-element/HTMLTextAreaElement.d.ts.map +1 -1
- package/cjs/nodes/node/Node.cjs +44 -48
- package/cjs/nodes/node/Node.cjs.map +1 -1
- package/cjs/nodes/node/Node.d.ts +2 -10
- package/cjs/nodes/node/Node.d.ts.map +1 -1
- package/cjs/nodes/node/NodeList.cjs +1 -1
- package/cjs/nodes/node/NodeList.cjs.map +1 -1
- package/cjs/nodes/node/NodeUtility.cjs +4 -3
- package/cjs/nodes/node/NodeUtility.cjs.map +1 -1
- package/cjs/nodes/node/NodeUtility.d.ts.map +1 -1
- package/cjs/nodes/parent-node/ParentNodeUtility.cjs +5 -2
- package/cjs/nodes/parent-node/ParentNodeUtility.cjs.map +1 -1
- package/cjs/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
- package/cjs/nodes/shadow-root/ShadowRoot.cjs +8 -8
- package/cjs/nodes/shadow-root/ShadowRoot.cjs.map +1 -1
- package/cjs/nodes/shadow-root/ShadowRoot.d.ts.map +1 -1
- package/cjs/nodes/xml-document/XMLDocument.cjs +26 -0
- package/cjs/nodes/xml-document/XMLDocument.cjs.map +1 -1
- package/cjs/nodes/xml-document/XMLDocument.d.ts +2 -0
- package/cjs/nodes/xml-document/XMLDocument.d.ts.map +1 -1
- package/cjs/query-selector/SelectorItem.cjs +1 -2
- package/cjs/query-selector/SelectorItem.cjs.map +1 -1
- package/cjs/query-selector/SelectorItem.d.ts.map +1 -1
- package/cjs/range/Range.cjs +3 -3
- package/cjs/range/Range.cjs.map +1 -1
- package/cjs/range/Range.d.ts.map +1 -1
- package/cjs/storage/Storage.cjs +1 -1
- package/cjs/storage/Storage.cjs.map +1 -1
- package/cjs/svg/SVGLengthList.cjs +1 -1
- package/cjs/svg/SVGLengthList.cjs.map +1 -1
- package/cjs/svg/SVGNumberList.cjs +1 -1
- package/cjs/svg/SVGNumberList.cjs.map +1 -1
- package/cjs/svg/SVGPointList.cjs +1 -1
- package/cjs/svg/SVGPointList.cjs.map +1 -1
- package/cjs/svg/SVGStringList.cjs +1 -1
- package/cjs/svg/SVGStringList.cjs.map +1 -1
- package/cjs/svg/SVGTransformList.cjs +1 -1
- package/cjs/svg/SVGTransformList.cjs.map +1 -1
- package/cjs/tree-walker/NodeIterator.cjs +63 -6
- package/cjs/tree-walker/NodeIterator.cjs.map +1 -1
- package/cjs/tree-walker/NodeIterator.d.ts +18 -3
- package/cjs/tree-walker/NodeIterator.d.ts.map +1 -1
- package/cjs/tree-walker/TreeWalker.cjs +6 -6
- package/cjs/tree-walker/TreeWalker.cjs.map +1 -1
- package/cjs/tree-walker/TreeWalker.d.ts +2 -1
- package/cjs/tree-walker/TreeWalker.d.ts.map +1 -1
- package/cjs/utilities/ClassMethodBinder.cjs.map +1 -0
- package/cjs/utilities/ClassMethodBinder.d.ts.map +1 -0
- package/cjs/utilities/StringUtility.cjs.map +1 -0
- package/cjs/utilities/StringUtility.d.ts.map +1 -0
- package/cjs/utilities/XMLEncodeUtility.cjs +119 -0
- package/cjs/utilities/XMLEncodeUtility.cjs.map +1 -0
- package/cjs/utilities/XMLEncodeUtility.d.ts +48 -0
- package/cjs/utilities/XMLEncodeUtility.d.ts.map +1 -0
- package/cjs/window/BrowserWindow.cjs +9 -3
- package/cjs/window/BrowserWindow.cjs.map +1 -1
- package/cjs/window/BrowserWindow.d.ts +2 -0
- package/cjs/window/BrowserWindow.d.ts.map +1 -1
- package/cjs/window/WindowErrorUtility.cjs +1 -1
- package/cjs/window/WindowErrorUtility.cjs.map +1 -1
- package/cjs/xml-http-request/XMLHttpRequest.cjs +2 -1
- package/cjs/xml-http-request/XMLHttpRequest.cjs.map +1 -1
- package/cjs/xml-http-request/XMLHttpRequest.d.ts.map +1 -1
- package/cjs/xml-http-request/XMLHttpRequestResponseDataParser.cjs +1 -1
- package/cjs/xml-http-request/XMLHttpRequestResponseDataParser.cjs.map +1 -1
- package/cjs/xml-parser/XMLParser.cjs +531 -242
- package/cjs/xml-parser/XMLParser.cjs.map +1 -1
- package/cjs/xml-parser/XMLParser.d.ts +89 -19
- package/cjs/xml-parser/XMLParser.d.ts.map +1 -1
- package/cjs/xml-serializer/XMLSerializer.cjs +136 -40
- package/cjs/xml-serializer/XMLSerializer.cjs.map +1 -1
- package/cjs/xml-serializer/XMLSerializer.d.ts +6 -17
- package/cjs/xml-serializer/XMLSerializer.d.ts.map +1 -1
- package/lib/PropertySymbol.d.ts +4 -1
- package/lib/PropertySymbol.d.ts.map +1 -1
- package/lib/PropertySymbol.js +4 -1
- package/lib/PropertySymbol.js.map +1 -1
- package/lib/browser/utilities/BrowserFrameURL.d.ts +1 -1
- package/lib/browser/utilities/BrowserFrameURL.d.ts.map +1 -1
- package/lib/browser/utilities/BrowserFrameURL.js +1 -1
- package/lib/browser/utilities/BrowserFrameURL.js.map +1 -1
- package/lib/config/HTMLElementConfig.d.ts +7 -0
- package/lib/config/HTMLElementConfig.d.ts.map +1 -1
- package/lib/config/HTMLElementConfig.js +42 -16
- package/lib/config/HTMLElementConfig.js.map +1 -1
- package/lib/config/HTMLElementConfigContentModelEnum.d.ts +3 -0
- package/lib/config/HTMLElementConfigContentModelEnum.d.ts.map +1 -1
- package/lib/config/HTMLElementConfigContentModelEnum.js +3 -0
- package/lib/config/HTMLElementConfigContentModelEnum.js.map +1 -1
- package/lib/config/NamespaceURI.d.ts +2 -0
- package/lib/config/NamespaceURI.d.ts.map +1 -1
- package/lib/config/NamespaceURI.js +2 -0
- package/lib/config/NamespaceURI.js.map +1 -1
- package/lib/css/declaration/CSSStyleDeclaration.d.ts.map +1 -1
- package/lib/css/declaration/CSSStyleDeclaration.js +1 -1
- package/lib/css/declaration/CSSStyleDeclaration.js.map +1 -1
- package/lib/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.d.ts.map +1 -1
- package/lib/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.js +2 -2
- package/lib/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.js.map +1 -1
- package/lib/custom-element/CustomElementReactionStack.d.ts +27 -0
- package/lib/custom-element/CustomElementReactionStack.d.ts.map +1 -0
- package/lib/custom-element/CustomElementReactionStack.js +71 -0
- package/lib/custom-element/CustomElementReactionStack.js.map +1 -0
- package/lib/custom-element/CustomElementRegistry.d.ts +2 -6
- package/lib/custom-element/CustomElementRegistry.d.ts.map +1 -1
- package/lib/custom-element/CustomElementRegistry.js +32 -45
- package/lib/custom-element/CustomElementRegistry.js.map +1 -1
- package/lib/custom-element/CustomElementUtility.d.ts +14 -0
- package/lib/custom-element/CustomElementUtility.d.ts.map +1 -0
- package/lib/custom-element/CustomElementUtility.js +32 -0
- package/lib/custom-element/CustomElementUtility.js.map +1 -0
- package/lib/custom-element/ICustomElementDefinition.d.ts +12 -0
- package/lib/custom-element/ICustomElementDefinition.d.ts.map +1 -0
- package/lib/custom-element/ICustomElementDefinition.js +2 -0
- package/lib/custom-element/ICustomElementDefinition.js.map +1 -0
- package/lib/dom/DOMStringMap.d.ts.map +1 -1
- package/lib/dom/DOMStringMap.js +8 -8
- package/lib/dom/DOMStringMap.js.map +1 -1
- package/lib/dom/DOMTokenList.js +1 -1
- package/lib/dom/DOMTokenList.js.map +1 -1
- package/lib/dom-parser/DOMParser.d.ts +0 -1
- package/lib/dom-parser/DOMParser.d.ts.map +1 -1
- package/lib/dom-parser/DOMParser.js +5 -67
- package/lib/dom-parser/DOMParser.js.map +1 -1
- package/lib/exception/DOMExceptionNameEnum.d.ts +2 -1
- package/lib/exception/DOMExceptionNameEnum.d.ts.map +1 -1
- package/lib/exception/DOMExceptionNameEnum.js +1 -0
- package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
- package/lib/history/History.d.ts +2 -2
- package/lib/history/History.d.ts.map +1 -1
- package/lib/history/History.js +8 -8
- package/lib/history/History.js.map +1 -1
- package/lib/html-parser/HTMLParser.d.ts +91 -0
- package/lib/html-parser/HTMLParser.d.ts.map +1 -0
- package/lib/html-parser/HTMLParser.js +697 -0
- package/lib/html-parser/HTMLParser.js.map +1 -0
- package/lib/html-serializer/HTMLSerializer.d.ts +36 -0
- package/lib/html-serializer/HTMLSerializer.d.ts.map +1 -0
- package/lib/html-serializer/HTMLSerializer.js +123 -0
- package/lib/html-serializer/HTMLSerializer.js.map +1 -0
- package/lib/nodes/document/Document.d.ts +8 -0
- package/lib/nodes/document/Document.d.ts.map +1 -1
- package/lib/nodes/document/Document.js +106 -122
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/element/Element.d.ts +2 -12
- package/lib/nodes/element/Element.d.ts.map +1 -1
- package/lib/nodes/element/Element.js +35 -53
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/element/HTMLCollection.d.ts.map +1 -1
- package/lib/nodes/element/HTMLCollection.js +5 -9
- package/lib/nodes/element/HTMLCollection.js.map +1 -1
- package/lib/nodes/element/NamedNodeMap.d.ts +1 -16
- package/lib/nodes/element/NamedNodeMap.d.ts.map +1 -1
- package/lib/nodes/element/NamedNodeMap.js +39 -52
- package/lib/nodes/element/NamedNodeMap.js.map +1 -1
- package/lib/nodes/element/NamedNodeMapProxyFactory.d.ts.map +1 -1
- package/lib/nodes/element/NamedNodeMapProxyFactory.js +12 -14
- package/lib/nodes/element/NamedNodeMapProxyFactory.js.map +1 -1
- package/lib/nodes/html-button-element/HTMLButtonElement.d.ts.map +1 -1
- package/lib/nodes/html-button-element/HTMLButtonElement.js +1 -1
- package/lib/nodes/html-button-element/HTMLButtonElement.js.map +1 -1
- package/lib/nodes/html-document/HTMLDocument.d.ts +10 -0
- package/lib/nodes/html-document/HTMLDocument.d.ts.map +1 -1
- package/lib/nodes/html-document/HTMLDocument.js +33 -2
- package/lib/nodes/html-document/HTMLDocument.js.map +1 -1
- package/lib/nodes/html-element/HTMLElement.d.ts +34 -0
- package/lib/nodes/html-element/HTMLElement.d.ts.map +1 -1
- package/lib/nodes/html-element/HTMLElement.js +52 -22
- package/lib/nodes/html-element/HTMLElement.js.map +1 -1
- package/lib/nodes/html-field-set-element/HTMLFieldSetElement.d.ts.map +1 -1
- package/lib/nodes/html-field-set-element/HTMLFieldSetElement.js +1 -1
- package/lib/nodes/html-field-set-element/HTMLFieldSetElement.js.map +1 -1
- package/lib/nodes/html-form-element/HTMLFormElement.d.ts.map +1 -1
- package/lib/nodes/html-form-element/HTMLFormElement.js +5 -8
- package/lib/nodes/html-form-element/HTMLFormElement.js.map +1 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.js +1 -1
- package/lib/nodes/html-iframe-element/HTMLIFrameElement.js.map +1 -1
- package/lib/nodes/html-input-element/HTMLInputElement.d.ts.map +1 -1
- package/lib/nodes/html-input-element/HTMLInputElement.js +1 -1
- package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
- package/lib/nodes/html-media-element/TextTrackList.js +1 -1
- package/lib/nodes/html-media-element/TextTrackList.js.map +1 -1
- package/lib/nodes/html-object-element/HTMLObjectElement.d.ts.map +1 -1
- package/lib/nodes/html-object-element/HTMLObjectElement.js +1 -1
- package/lib/nodes/html-object-element/HTMLObjectElement.js.map +1 -1
- package/lib/nodes/html-output-element/HTMLOutputElement.d.ts.map +1 -1
- package/lib/nodes/html-output-element/HTMLOutputElement.js +1 -1
- package/lib/nodes/html-output-element/HTMLOutputElement.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js +3 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/nodes/html-select-element/HTMLSelectElement.d.ts.map +1 -1
- package/lib/nodes/html-select-element/HTMLSelectElement.js +2 -2
- package/lib/nodes/html-select-element/HTMLSelectElement.js.map +1 -1
- package/lib/nodes/html-table-element/HTMLTableElement.d.ts.map +1 -1
- package/lib/nodes/html-table-element/HTMLTableElement.js +9 -1
- package/lib/nodes/html-table-element/HTMLTableElement.js.map +1 -1
- package/lib/nodes/html-table-row-element/HTMLTableRowElement.js +1 -1
- package/lib/nodes/html-template-element/HTMLTemplateElement.d.ts +2 -2
- package/lib/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
- package/lib/nodes/html-template-element/HTMLTemplateElement.js +15 -17
- package/lib/nodes/html-template-element/HTMLTemplateElement.js.map +1 -1
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.d.ts.map +1 -1
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js +1 -1
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js.map +1 -1
- package/lib/nodes/node/Node.d.ts +2 -10
- package/lib/nodes/node/Node.d.ts.map +1 -1
- package/lib/nodes/node/Node.js +44 -48
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/nodes/node/NodeList.js +1 -1
- package/lib/nodes/node/NodeList.js.map +1 -1
- package/lib/nodes/node/NodeUtility.d.ts.map +1 -1
- package/lib/nodes/node/NodeUtility.js +4 -3
- package/lib/nodes/node/NodeUtility.js.map +1 -1
- package/lib/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
- package/lib/nodes/parent-node/ParentNodeUtility.js +5 -2
- package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
- package/lib/nodes/shadow-root/ShadowRoot.d.ts.map +1 -1
- package/lib/nodes/shadow-root/ShadowRoot.js +8 -8
- package/lib/nodes/shadow-root/ShadowRoot.js.map +1 -1
- package/lib/nodes/xml-document/XMLDocument.d.ts +2 -0
- package/lib/nodes/xml-document/XMLDocument.d.ts.map +1 -1
- package/lib/nodes/xml-document/XMLDocument.js +3 -0
- package/lib/nodes/xml-document/XMLDocument.js.map +1 -1
- package/lib/query-selector/SelectorItem.d.ts.map +1 -1
- package/lib/query-selector/SelectorItem.js +1 -2
- package/lib/query-selector/SelectorItem.js.map +1 -1
- package/lib/range/Range.d.ts.map +1 -1
- package/lib/range/Range.js +3 -3
- package/lib/range/Range.js.map +1 -1
- package/lib/storage/Storage.js +1 -1
- package/lib/storage/Storage.js.map +1 -1
- package/lib/svg/SVGLengthList.js +1 -1
- package/lib/svg/SVGLengthList.js.map +1 -1
- package/lib/svg/SVGNumberList.js +1 -1
- package/lib/svg/SVGNumberList.js.map +1 -1
- package/lib/svg/SVGPointList.js +1 -1
- package/lib/svg/SVGPointList.js.map +1 -1
- package/lib/svg/SVGStringList.js +1 -1
- package/lib/svg/SVGStringList.js.map +1 -1
- package/lib/svg/SVGTransformList.js +1 -1
- package/lib/svg/SVGTransformList.js.map +1 -1
- package/lib/tree-walker/NodeIterator.d.ts +18 -3
- package/lib/tree-walker/NodeIterator.d.ts.map +1 -1
- package/lib/tree-walker/NodeIterator.js +40 -6
- package/lib/tree-walker/NodeIterator.js.map +1 -1
- package/lib/tree-walker/TreeWalker.d.ts +2 -1
- package/lib/tree-walker/TreeWalker.d.ts.map +1 -1
- package/lib/tree-walker/TreeWalker.js +6 -6
- package/lib/tree-walker/TreeWalker.js.map +1 -1
- package/lib/utilities/ClassMethodBinder.d.ts.map +1 -0
- package/lib/utilities/ClassMethodBinder.js.map +1 -0
- package/lib/utilities/StringUtility.d.ts.map +1 -0
- package/lib/utilities/StringUtility.js.map +1 -0
- package/lib/utilities/XMLEncodeUtility.d.ts +48 -0
- package/lib/utilities/XMLEncodeUtility.d.ts.map +1 -0
- package/lib/utilities/XMLEncodeUtility.js +116 -0
- package/lib/utilities/XMLEncodeUtility.js.map +1 -0
- package/lib/window/BrowserWindow.d.ts +2 -0
- package/lib/window/BrowserWindow.d.ts.map +1 -1
- package/lib/window/BrowserWindow.js +9 -3
- package/lib/window/BrowserWindow.js.map +1 -1
- package/lib/window/WindowErrorUtility.js +1 -1
- package/lib/window/WindowErrorUtility.js.map +1 -1
- package/lib/xml-http-request/XMLHttpRequest.d.ts.map +1 -1
- package/lib/xml-http-request/XMLHttpRequest.js +2 -1
- package/lib/xml-http-request/XMLHttpRequest.js.map +1 -1
- package/lib/xml-http-request/XMLHttpRequestResponseDataParser.js +1 -1
- package/lib/xml-http-request/XMLHttpRequestResponseDataParser.js.map +1 -1
- package/lib/xml-parser/XMLParser.d.ts +89 -19
- package/lib/xml-parser/XMLParser.d.ts.map +1 -1
- package/lib/xml-parser/XMLParser.js +531 -242
- package/lib/xml-parser/XMLParser.js.map +1 -1
- package/lib/xml-serializer/XMLSerializer.d.ts +6 -17
- package/lib/xml-serializer/XMLSerializer.d.ts.map +1 -1
- package/lib/xml-serializer/XMLSerializer.js +136 -40
- package/lib/xml-serializer/XMLSerializer.js.map +1 -1
- package/package.json +1 -2
- package/src/PropertySymbol.ts +4 -1
- package/src/browser/utilities/BrowserFrameURL.ts +2 -2
- package/src/config/HTMLElementConfig.ts +53 -17
- package/src/config/HTMLElementConfigContentModelEnum.ts +3 -0
- package/src/config/NamespaceURI.ts +2 -0
- package/src/css/declaration/CSSStyleDeclaration.ts +1 -4
- package/src/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.ts +2 -4
- package/src/custom-element/CustomElementReactionStack.ts +81 -0
- package/src/custom-element/CustomElementRegistry.ts +35 -54
- package/src/custom-element/CustomElementUtility.ts +34 -0
- package/src/custom-element/ICustomElementDefinition.ts +16 -0
- package/src/dom/DOMStringMap.ts +12 -10
- package/src/dom/DOMTokenList.ts +1 -1
- package/src/dom-parser/DOMParser.ts +5 -75
- package/src/exception/DOMExceptionNameEnum.ts +2 -1
- package/src/history/History.ts +10 -10
- package/src/html-parser/HTMLParser.ts +864 -0
- package/src/html-serializer/HTMLSerializer.ts +162 -0
- package/src/nodes/document/Document.ts +118 -137
- package/src/nodes/element/Element.ts +48 -95
- package/src/nodes/element/HTMLCollection.ts +5 -30
- package/src/nodes/element/NamedNodeMap.ts +58 -72
- package/src/nodes/element/NamedNodeMapProxyFactory.ts +12 -15
- package/src/nodes/html-button-element/HTMLButtonElement.ts +1 -4
- package/src/nodes/html-document/HTMLDocument.ts +58 -2
- package/src/nodes/html-element/HTMLElement.ts +107 -25
- package/src/nodes/html-field-set-element/HTMLFieldSetElement.ts +1 -4
- package/src/nodes/html-form-element/HTMLFormElement.ts +5 -27
- package/src/nodes/html-iframe-element/HTMLIFrameElement.ts +1 -1
- package/src/nodes/html-input-element/HTMLInputElement.ts +1 -4
- package/src/nodes/html-media-element/TextTrackList.ts +1 -1
- package/src/nodes/html-object-element/HTMLObjectElement.ts +1 -4
- package/src/nodes/html-output-element/HTMLOutputElement.ts +1 -4
- package/src/nodes/html-script-element/HTMLScriptElement.ts +4 -1
- package/src/nodes/html-select-element/HTMLSelectElement.ts +2 -5
- package/src/nodes/html-table-element/HTMLTableElement.ts +8 -1
- package/src/nodes/html-table-row-element/HTMLTableRowElement.ts +1 -1
- package/src/nodes/html-template-element/HTMLTemplateElement.ts +23 -17
- package/src/nodes/html-text-area-element/HTMLTextAreaElement.ts +1 -4
- package/src/nodes/node/Node.ts +57 -70
- package/src/nodes/node/NodeList.ts +1 -1
- package/src/nodes/node/NodeUtility.ts +4 -3
- package/src/nodes/parent-node/ParentNodeUtility.ts +6 -6
- package/src/nodes/shadow-root/ShadowRoot.ts +8 -8
- package/src/nodes/xml-document/XMLDocument.ts +5 -1
- package/src/query-selector/SelectorItem.ts +1 -2
- package/src/range/Range.ts +3 -3
- package/src/storage/Storage.ts +1 -1
- package/src/svg/SVGLengthList.ts +1 -1
- package/src/svg/SVGNumberList.ts +1 -1
- package/src/svg/SVGPointList.ts +1 -1
- package/src/svg/SVGStringList.ts +1 -1
- package/src/svg/SVGTransformList.ts +1 -1
- package/src/tree-walker/NodeIterator.ts +44 -8
- package/src/tree-walker/TreeWalker.ts +6 -6
- package/src/utilities/XMLEncodeUtility.ts +127 -0
- package/src/window/BrowserWindow.ts +18 -5
- package/src/window/WindowErrorUtility.ts +1 -1
- package/src/xml-http-request/XMLHttpRequest.ts +3 -1
- package/src/xml-http-request/XMLHttpRequestResponseDataParser.ts +1 -1
- package/src/xml-parser/XMLParser.ts +627 -313
- package/src/xml-serializer/XMLSerializer.ts +204 -58
- package/cjs/ClassMethodBinder.cjs.map +0 -1
- package/cjs/ClassMethodBinder.d.ts.map +0 -1
- package/cjs/StringUtility.cjs.map +0 -1
- package/cjs/StringUtility.d.ts.map +0 -1
- package/lib/ClassMethodBinder.d.ts.map +0 -1
- package/lib/ClassMethodBinder.js.map +0 -1
- package/lib/StringUtility.d.ts.map +0 -1
- package/lib/StringUtility.js.map +0 -1
- /package/cjs/{ClassMethodBinder.cjs → utilities/ClassMethodBinder.cjs} +0 -0
- /package/cjs/{ClassMethodBinder.d.ts → utilities/ClassMethodBinder.d.ts} +0 -0
- /package/cjs/{StringUtility.cjs → utilities/StringUtility.cjs} +0 -0
- /package/cjs/{StringUtility.d.ts → utilities/StringUtility.d.ts} +0 -0
- /package/lib/{ClassMethodBinder.d.ts → utilities/ClassMethodBinder.d.ts} +0 -0
- /package/lib/{ClassMethodBinder.js → utilities/ClassMethodBinder.js} +0 -0
- /package/lib/{StringUtility.d.ts → utilities/StringUtility.d.ts} +0 -0
- /package/lib/{StringUtility.js → utilities/StringUtility.js} +0 -0
- /package/src/{ClassMethodBinder.ts → utilities/ClassMethodBinder.ts} +0 -0
- /package/src/{StringUtility.ts → utilities/StringUtility.ts} +0 -0
@@ -28,11 +28,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
29
|
const PropertySymbol = __importStar(require("../PropertySymbol.cjs"));
|
30
30
|
const NamespaceURI_js_1 = __importDefault(require("../config/NamespaceURI.cjs"));
|
31
|
-
const
|
32
|
-
const
|
33
|
-
const HTMLElementConfigContentModelEnum_js_1 = __importDefault(require("../config/HTMLElementConfigContentModelEnum.cjs"));
|
34
|
-
const SVGElementConfig_js_1 = __importDefault(require("../config/SVGElementConfig.cjs"));
|
35
|
-
const StringUtility_js_1 = __importDefault(require("../StringUtility.cjs"));
|
31
|
+
const Node_js_1 = __importDefault(require("../nodes/node/Node.cjs"));
|
32
|
+
const XMLEncodeUtility_js_1 = __importDefault(require("../utilities/XMLEncodeUtility.cjs"));
|
36
33
|
/**
|
37
34
|
* Markup RegExp.
|
38
35
|
*
|
@@ -45,283 +42,571 @@ const StringUtility_js_1 = __importDefault(require("../StringUtility.cjs"));
|
|
45
42
|
* Group 7: End of self closing start tag (e.g. "/>" in "<img/>").
|
46
43
|
* Group 8: End of start tag (e.g. ">" in "<div>").
|
47
44
|
*/
|
48
|
-
const MARKUP_REGEXP = /<([^\s/!>?]+)|<\/([^\s/!>?]+)\s
|
45
|
+
const MARKUP_REGEXP = /<([^\s/!>?]+)|<\/([^\s/!>?]+)\s*>|(<!--)|(-->)|(<!)|(<\?)|(\/>)|(>)/gm;
|
49
46
|
/**
|
50
47
|
* Attribute RegExp.
|
51
48
|
*
|
52
49
|
* Group 1: Attribute name when the attribute has a value using double apostrophe (e.g. "name" in "<div name="value">").
|
53
50
|
* Group 2: Attribute value when the attribute has a value using double apostrophe (e.g. "value" in "<div name="value">").
|
54
|
-
* Group 3: Attribute
|
55
|
-
* Group 4: Attribute
|
56
|
-
* Group 5: Attribute
|
57
|
-
* Group 6: Attribute
|
58
|
-
* Group 7: Attribute
|
59
|
-
* Group 8: Attribute end apostrophe when the attribute has a value using single apostrophe (e.g. "'" in "<div name='value'>").
|
60
|
-
* Group 9: Attribute name when the attribute has no value (e.g. "disabled" in "<div disabled>").
|
51
|
+
* Group 3: Attribute end apostrophe when the attribute has a value using double apostrophe (e.g. '"' in "<div name="value">").
|
52
|
+
* Group 4: Attribute name when the attribute has a value using single apostrophe (e.g. "name" in "<div name='value'>").
|
53
|
+
* Group 5: Attribute value when the attribute has a value using single apostrophe (e.g. "value" in "<div name='value'>").
|
54
|
+
* Group 6: Attribute end apostrophe when the attribute has a value using single apostrophe (e.g. "'" in "<div name='value'>").
|
55
|
+
* Group 7: Attribute name when the attribute has no value (e.g. "disabled" in "<div disabled>").
|
61
56
|
*/
|
62
|
-
const ATTRIBUTE_REGEXP = /\s*([a-zA-Z0-9-_
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
57
|
+
const ATTRIBUTE_REGEXP = /\s*([a-zA-Z0-9-_:]+)\s*=\s*"([^"]*)("{0,1})|\s*([a-zA-Z0-9-_:]+)\s*=\s*'([^']*)('{0,1})/gm;
|
58
|
+
/**
|
59
|
+
* Attribute without value RegExp.
|
60
|
+
*/
|
61
|
+
const ATTRIBUTE_WITHOUT_VALUE_REGEXP = /^\s*([a-zA-Z0-9-_:]+)$/;
|
62
|
+
/**
|
63
|
+
* XML processing instruction version RegExp.
|
64
|
+
*/
|
65
|
+
const XML_PROCESSING_INSTRUCTION_VERSION_REGEXP = /version="[^"]+"/;
|
69
66
|
/**
|
70
67
|
* Document type attribute RegExp.
|
71
68
|
*
|
72
69
|
* Group 1: Attribute value.
|
73
70
|
*/
|
74
71
|
const DOCUMENT_TYPE_ATTRIBUTE_REGEXP = /"([^"]+)"/gm;
|
72
|
+
/**
|
73
|
+
* Space RegExp.
|
74
|
+
*/
|
75
|
+
const SPACE_REGEXP = /\s+/;
|
76
|
+
/**
|
77
|
+
* New line RegExp.
|
78
|
+
*/
|
79
|
+
const NEW_LINE_REGEXP = /\n/g;
|
80
|
+
/**
|
81
|
+
* Markup read state (which state the parser is in).
|
82
|
+
*/
|
83
|
+
var MarkupReadStateEnum;
|
84
|
+
(function (MarkupReadStateEnum) {
|
85
|
+
MarkupReadStateEnum["any"] = "any";
|
86
|
+
MarkupReadStateEnum["startTag"] = "startTag";
|
87
|
+
MarkupReadStateEnum["comment"] = "comment";
|
88
|
+
MarkupReadStateEnum["documentType"] = "documentType";
|
89
|
+
MarkupReadStateEnum["processingInstruction"] = "processingInstruction";
|
90
|
+
MarkupReadStateEnum["error"] = "error";
|
91
|
+
})(MarkupReadStateEnum || (MarkupReadStateEnum = {}));
|
92
|
+
const NAMESPACE_URIS = Object.values(NamespaceURI_js_1.default);
|
75
93
|
/**
|
76
94
|
* XML parser.
|
77
|
-
*
|
78
|
-
* @see https://html.spec.whatwg.org/multipage/indices.html
|
79
95
|
*/
|
80
96
|
class XMLParser {
|
97
|
+
window;
|
98
|
+
rootNode = null;
|
99
|
+
nodeStack = [];
|
100
|
+
tagNameStack = [];
|
101
|
+
defaultNamespaceStack = null;
|
102
|
+
namespacePrefixStack = null;
|
103
|
+
startTagIndex = 0;
|
104
|
+
markupRegExp = null;
|
105
|
+
lastIndex = 0;
|
106
|
+
errorIndex = 0;
|
107
|
+
nextElement = null;
|
108
|
+
nextTagName = null;
|
109
|
+
currentNode = null;
|
110
|
+
readState = MarkupReadStateEnum.any;
|
111
|
+
errorMessage = null;
|
81
112
|
/**
|
82
|
-
*
|
113
|
+
* Constructor.
|
83
114
|
*
|
84
|
-
* @param
|
85
|
-
* @param xml XML/HTML string.
|
115
|
+
* @param window Window.
|
86
116
|
* @param [options] Options.
|
87
|
-
* @param [options.
|
88
|
-
* @param [options.evaluateScripts
|
89
|
-
* @returns Root node.
|
117
|
+
* @param [options.mode] Mode. Defaults to "htmlFragment".
|
118
|
+
* @param [options.evaluateScripts] Set to "true" to enable script execution
|
90
119
|
*/
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
120
|
+
constructor(window) {
|
121
|
+
this.window = window;
|
122
|
+
}
|
123
|
+
/**
|
124
|
+
* Parses XML and returns an XML document containing nodes found.
|
125
|
+
*
|
126
|
+
* @param xml XML string.
|
127
|
+
* @returns XML document.
|
128
|
+
*/
|
129
|
+
parse(xml) {
|
130
|
+
this.rootNode = new this.window.XMLDocument();
|
131
|
+
this.nodeStack = [this.rootNode];
|
132
|
+
this.tagNameStack = [null];
|
133
|
+
this.currentNode = this.rootNode;
|
134
|
+
this.readState = MarkupReadStateEnum.any;
|
135
|
+
this.defaultNamespaceStack = [null];
|
136
|
+
this.namespacePrefixStack = [null];
|
137
|
+
this.startTagIndex = 0;
|
138
|
+
this.errorIndex = 0;
|
139
|
+
this.errorMessage = null;
|
140
|
+
this.markupRegExp = new RegExp(MARKUP_REGEXP, 'gm');
|
141
|
+
this.lastIndex = 0;
|
99
142
|
let match;
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
// SVG elements are resolved to their local name during parsing.
|
122
|
-
// This should probably be handled in an XML document.
|
123
|
-
const qualifiedName = namespaceURI === NamespaceURI_js_1.default.svg && SVGElementConfig_js_1.default[name]
|
124
|
-
? SVGElementConfig_js_1.default[name].localName
|
125
|
-
: name;
|
126
|
-
// Create a new element.
|
127
|
-
newNode = document.createElementNS(namespaceURI, qualifiedName);
|
128
|
-
readState = MarkupReadStateEnum.insideStartTag;
|
129
|
-
startTagIndex = markupRegexp.lastIndex;
|
143
|
+
this.rootNode[PropertySymbol.defaultView] = this.window;
|
144
|
+
xml = String(xml);
|
145
|
+
while ((match = this.markupRegExp.exec(xml))) {
|
146
|
+
switch (this.readState) {
|
147
|
+
case MarkupReadStateEnum.any:
|
148
|
+
if (match.index !== this.lastIndex &&
|
149
|
+
(match[1] || match[2] || match[3] || match[4] || match[5] !== undefined || match[6])) {
|
150
|
+
// Plain text between tags.
|
151
|
+
this.parsePlainText(xml.substring(this.lastIndex, match.index));
|
152
|
+
}
|
153
|
+
if (match[1]) {
|
154
|
+
// Start tag.
|
155
|
+
this.parseStartTag(match[1]);
|
156
|
+
}
|
157
|
+
else if (match[2]) {
|
158
|
+
// End tag.
|
159
|
+
if (!this.parseEndTag(match[2])) {
|
160
|
+
this.errorMessage = `Opening and ending tag mismatch: ${this.tagNameStack[this.tagNameStack.length - 1]} line ${xml.substring(0, this.startTagIndex).split('\n').length} and ${match[2]}\n`;
|
161
|
+
this.errorIndex = this.markupRegExp.lastIndex;
|
162
|
+
this.readState = MarkupReadStateEnum.error;
|
163
|
+
this.removeOverflowingTextNodes();
|
130
164
|
}
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
165
|
+
}
|
166
|
+
else if (match[3]) {
|
167
|
+
// Comment.
|
168
|
+
this.startTagIndex = this.markupRegExp.lastIndex;
|
169
|
+
this.readState = MarkupReadStateEnum.comment;
|
170
|
+
}
|
171
|
+
else if (match[5] !== undefined) {
|
172
|
+
// Document type
|
173
|
+
this.startTagIndex = this.markupRegExp.lastIndex;
|
174
|
+
this.readState = MarkupReadStateEnum.documentType;
|
175
|
+
}
|
176
|
+
else if (match[6]) {
|
177
|
+
// Processing instruction.
|
178
|
+
this.startTagIndex = this.markupRegExp.lastIndex;
|
179
|
+
this.readState = MarkupReadStateEnum.processingInstruction;
|
180
|
+
}
|
181
|
+
else {
|
182
|
+
// Plain text between tags, including the matched tag as it is not a valid start or end tag.
|
183
|
+
this.parsePlainText(xml.substring(this.lastIndex, this.markupRegExp.lastIndex));
|
184
|
+
}
|
185
|
+
break;
|
186
|
+
case MarkupReadStateEnum.startTag:
|
187
|
+
// End of start tag
|
188
|
+
// match[7] is matching "/>" (e.g. "<img/>").
|
189
|
+
// match[8] is matching ">" (e.g. "<div>").
|
190
|
+
if (match[7] || match[8]) {
|
191
|
+
const attributeString = xml.substring(this.startTagIndex, match[2] ? this.markupRegExp.lastIndex - 1 : match.index);
|
192
|
+
const isSelfClosed = !!match[7];
|
193
|
+
this.parseEndOfStartTag(attributeString, isSelfClosed);
|
194
|
+
}
|
195
|
+
else {
|
196
|
+
this.errorMessage =
|
197
|
+
match[2] && this.lastIndex !== this.startTagIndex
|
198
|
+
? `Unescaped '<' not allowed in attributes values\n`
|
199
|
+
: 'error parsing attribute name\n';
|
200
|
+
this.errorIndex = match.index;
|
201
|
+
this.readState = MarkupReadStateEnum.error;
|
202
|
+
this.removeOverflowingTextNodes();
|
203
|
+
}
|
204
|
+
break;
|
205
|
+
case MarkupReadStateEnum.comment:
|
206
|
+
// Comment end tag.
|
207
|
+
if (match[4]) {
|
208
|
+
this.parseComment(xml.substring(this.startTagIndex, match.index));
|
209
|
+
}
|
210
|
+
break;
|
211
|
+
case MarkupReadStateEnum.documentType:
|
212
|
+
// Document type end tag.
|
213
|
+
if (match[7] || match[8]) {
|
214
|
+
this.parseDocumentType(xml.substring(this.startTagIndex, match.index));
|
215
|
+
}
|
216
|
+
break;
|
217
|
+
case MarkupReadStateEnum.processingInstruction:
|
218
|
+
// Processing instruction end tag.
|
219
|
+
if (match[7] || match[8]) {
|
220
|
+
this.parseProcessingInstruction(xml.substring(this.startTagIndex, match.index));
|
221
|
+
}
|
222
|
+
break;
|
223
|
+
case MarkupReadStateEnum.error:
|
224
|
+
this.parseError(xml.slice(0, this.errorIndex), this.errorMessage);
|
225
|
+
return this.rootNode;
|
226
|
+
}
|
227
|
+
this.lastIndex = this.markupRegExp.lastIndex;
|
228
|
+
}
|
229
|
+
if (this.readState === MarkupReadStateEnum.error) {
|
230
|
+
this.parseError(xml.slice(0, this.errorIndex), this.errorMessage);
|
231
|
+
return this.rootNode;
|
232
|
+
}
|
233
|
+
if (this.readState === MarkupReadStateEnum.comment) {
|
234
|
+
this.parseError(xml, 'Comment not terminated\n');
|
235
|
+
this.removeOverflowingTextNodes();
|
236
|
+
return this.rootNode;
|
237
|
+
}
|
238
|
+
// Missing start tag (e.g. when parsing just a string like "Test").
|
239
|
+
if (this.rootNode[PropertySymbol.elementArray].length === 0) {
|
240
|
+
this.parseError('', `Start tag expected, '<' not found`);
|
241
|
+
return this.rootNode;
|
242
|
+
}
|
243
|
+
// Plain text after tags.
|
244
|
+
if (this.lastIndex !== xml.length && this.currentNode) {
|
245
|
+
this.parsePlainText(xml.substring(this.lastIndex));
|
246
|
+
}
|
247
|
+
// Missing end tag.
|
248
|
+
if (this.nodeStack.length !== 1) {
|
249
|
+
this.parseError(xml, this.nextElement
|
250
|
+
? 'attributes construct error\n'
|
251
|
+
: 'Premature end of data in tag article line 1\n');
|
252
|
+
return this.rootNode;
|
253
|
+
}
|
254
|
+
return this.rootNode;
|
255
|
+
}
|
256
|
+
/**
|
257
|
+
* Parses plain text.
|
258
|
+
*
|
259
|
+
* @param text Text.
|
260
|
+
*/
|
261
|
+
parsePlainText(text) {
|
262
|
+
if (this.currentNode === this.rootNode) {
|
263
|
+
const xmlText = text.replace(SPACE_REGEXP, '');
|
264
|
+
if (xmlText) {
|
265
|
+
this.errorMessage = 'Extra content at the end of the document\n';
|
266
|
+
this.errorIndex = this.lastIndex;
|
267
|
+
this.readState = MarkupReadStateEnum.error;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
else if (text.includes(' ')) {
|
271
|
+
this.errorMessage = `Entity 'nbsp' not defined\n`;
|
272
|
+
this.errorIndex = this.lastIndex + text.indexOf(' ') + 6;
|
273
|
+
this.readState = MarkupReadStateEnum.error;
|
274
|
+
}
|
275
|
+
else {
|
276
|
+
this.currentNode[PropertySymbol.appendChild](this.rootNode.createTextNode(XMLEncodeUtility_js_1.default.decodeXMLEntities(text)), true);
|
277
|
+
}
|
278
|
+
}
|
279
|
+
/**
|
280
|
+
* Parses processing instruction.
|
281
|
+
*
|
282
|
+
* @param text Text.
|
283
|
+
*/
|
284
|
+
parseProcessingInstruction(text) {
|
285
|
+
const parts = text.split(SPACE_REGEXP);
|
286
|
+
const endsWithQuestionMark = text[text.length - 1] === '?';
|
287
|
+
if (parts[0] === 'xml') {
|
288
|
+
if (this.currentNode !== this.rootNode ||
|
289
|
+
this.rootNode[PropertySymbol.nodeArray].length !== 0 ||
|
290
|
+
parts.length === 1) {
|
291
|
+
this.errorMessage = 'XML declaration allowed only at the start of the document\n';
|
292
|
+
this.errorIndex = this.markupRegExp.lastIndex - text.length + 2;
|
293
|
+
this.readState = MarkupReadStateEnum.error;
|
294
|
+
this.removeOverflowingTextNodes();
|
295
|
+
}
|
296
|
+
else if (!XML_PROCESSING_INSTRUCTION_VERSION_REGEXP.test(parts[1])) {
|
297
|
+
this.errorMessage = 'Malformed declaration expecting version\n';
|
298
|
+
this.errorIndex = this.markupRegExp.lastIndex - text.length + 3;
|
299
|
+
this.readState = MarkupReadStateEnum.error;
|
300
|
+
}
|
301
|
+
else if (!endsWithQuestionMark) {
|
302
|
+
this.errorMessage = 'Blank needed here\n';
|
303
|
+
this.errorIndex = this.markupRegExp.lastIndex - 1;
|
304
|
+
this.readState = MarkupReadStateEnum.error;
|
305
|
+
}
|
306
|
+
else {
|
307
|
+
// When the processing instruction has "xml" as target, we should not add it as a child node.
|
308
|
+
// Instead we will store the state on the root node, so that it is added when serializing the document with XMLSerializer.
|
309
|
+
// TODO: We need to handle validation of encoding.
|
310
|
+
const name = parts[0];
|
311
|
+
// We need to remove the ending "?".
|
312
|
+
const content = parts.slice(1).join(' ').slice(0, -1);
|
313
|
+
this.rootNode[PropertySymbol.xmlProcessingInstruction] =
|
314
|
+
this.rootNode.createProcessingInstruction(name, content);
|
315
|
+
this.readState = MarkupReadStateEnum.any;
|
316
|
+
}
|
317
|
+
}
|
318
|
+
else {
|
319
|
+
if (parts.length === 1 && !endsWithQuestionMark) {
|
320
|
+
this.errorMessage = 'ParsePI: PI processing-instruction space expected\n';
|
321
|
+
this.errorIndex = this.markupRegExp.lastIndex - 1;
|
322
|
+
this.readState = MarkupReadStateEnum.error;
|
323
|
+
}
|
324
|
+
else if (parts.length > 1 && !endsWithQuestionMark) {
|
325
|
+
this.errorMessage = 'ParsePI: PI processing-instruction never end ...\n';
|
326
|
+
this.errorIndex = this.markupRegExp.lastIndex - 1;
|
327
|
+
this.readState = MarkupReadStateEnum.error;
|
328
|
+
}
|
329
|
+
else {
|
330
|
+
const name = parts[0];
|
331
|
+
// We need to remove the ending "?".
|
332
|
+
const content = parts.slice(1).join(' ').slice(0, -1);
|
333
|
+
this.currentNode[PropertySymbol.appendChild](this.rootNode.createProcessingInstruction(name, content), true);
|
334
|
+
this.readState = MarkupReadStateEnum.any;
|
335
|
+
}
|
336
|
+
}
|
337
|
+
}
|
338
|
+
/**
|
339
|
+
* Parses comment.
|
340
|
+
*
|
341
|
+
* @param comment Comment.
|
342
|
+
*/
|
343
|
+
parseComment(comment) {
|
344
|
+
// Comments are not allowed in the root when parsing XML.
|
345
|
+
if (this.currentNode !== this.rootNode) {
|
346
|
+
this.currentNode[PropertySymbol.appendChild](this.rootNode.createComment(XMLEncodeUtility_js_1.default.decodeXMLEntities(comment)), true);
|
347
|
+
}
|
348
|
+
this.readState = MarkupReadStateEnum.any;
|
349
|
+
}
|
350
|
+
/**
|
351
|
+
* Parses document type.
|
352
|
+
*
|
353
|
+
* @param text Text.
|
354
|
+
*/
|
355
|
+
parseDocumentType(text) {
|
356
|
+
if (this.currentNode === this.rootNode &&
|
357
|
+
this.rootNode[PropertySymbol.nodeArray].length === 0) {
|
358
|
+
const documentType = this.getDocumentType(XMLEncodeUtility_js_1.default.decodeXMLEntities(text));
|
359
|
+
if (documentType?.name) {
|
360
|
+
this.rootNode[PropertySymbol.appendChild](this.window.document.implementation.createDocumentType(documentType.name, documentType.publicId, documentType.systemId), true);
|
361
|
+
this.readState = MarkupReadStateEnum.any;
|
362
|
+
}
|
363
|
+
else if (documentType) {
|
364
|
+
this.errorMessage = 'xmlParseDocTypeDecl : no DOCTYPE name\n';
|
365
|
+
this.errorIndex = this.markupRegExp.lastIndex - text.length - 2;
|
366
|
+
this.readState = MarkupReadStateEnum.error;
|
367
|
+
}
|
368
|
+
else {
|
369
|
+
this.errorMessage = 'StartTag: invalid element name\n';
|
370
|
+
this.errorIndex = this.markupRegExp.lastIndex - text.length - 2;
|
371
|
+
this.readState = MarkupReadStateEnum.error;
|
372
|
+
}
|
373
|
+
}
|
374
|
+
else if (this.currentNode === this.rootNode &&
|
375
|
+
this.rootNode[PropertySymbol.elementArray].length === 1) {
|
376
|
+
this.errorMessage = 'Extra content at the end of the document\n';
|
377
|
+
this.errorIndex = this.markupRegExp.lastIndex - text.length - 2;
|
378
|
+
this.readState = MarkupReadStateEnum.error;
|
379
|
+
}
|
380
|
+
else {
|
381
|
+
this.errorMessage = 'StartTag: invalid element name\n';
|
382
|
+
this.errorIndex = this.markupRegExp.lastIndex - text.length - 2;
|
383
|
+
this.readState = MarkupReadStateEnum.error;
|
384
|
+
}
|
385
|
+
}
|
386
|
+
/**
|
387
|
+
* Parses start tag.
|
388
|
+
*
|
389
|
+
* @param tagName Tag name.
|
390
|
+
*/
|
391
|
+
parseStartTag(tagName) {
|
392
|
+
const parts = tagName.split(':');
|
393
|
+
if (parts.length > 1) {
|
394
|
+
this.nextElement = this.rootNode.createElementNS(this.namespacePrefixStack[this.namespacePrefixStack.length - 1]?.get(parts[0]) || null, tagName);
|
395
|
+
}
|
396
|
+
else {
|
397
|
+
this.nextElement = this.rootNode.createElementNS(this.defaultNamespaceStack[this.defaultNamespaceStack.length - 1] || null, tagName);
|
398
|
+
}
|
399
|
+
this.namespacePrefixStack.push(new Map(this.namespacePrefixStack[this.namespacePrefixStack.length - 1]));
|
400
|
+
this.nextTagName = tagName;
|
401
|
+
this.startTagIndex = this.markupRegExp.lastIndex;
|
402
|
+
this.readState = MarkupReadStateEnum.startTag;
|
403
|
+
}
|
404
|
+
/**
|
405
|
+
* Parses end of start tag.
|
406
|
+
*
|
407
|
+
* @param attributeString Attribute string.
|
408
|
+
* @param isSelfClosed Is self closed.
|
409
|
+
*/
|
410
|
+
parseEndOfStartTag(attributeString, isSelfClosed) {
|
411
|
+
const namespacePrefix = this.namespacePrefixStack[this.namespacePrefixStack.length - 1];
|
412
|
+
if (attributeString) {
|
413
|
+
const attributeRegexp = new RegExp(ATTRIBUTE_REGEXP, 'gm');
|
414
|
+
let attributeMatch;
|
415
|
+
let lastIndex = 0;
|
416
|
+
while ((attributeMatch = attributeRegexp.exec(attributeString))) {
|
417
|
+
const textBetweenAttributes = attributeString
|
418
|
+
.substring(lastIndex, attributeMatch.index)
|
419
|
+
.replace(SPACE_REGEXP, '');
|
420
|
+
// If there is text between attributes, the text did not match a valid attribute.
|
421
|
+
if (textBetweenAttributes.length) {
|
422
|
+
const match = textBetweenAttributes.match(ATTRIBUTE_WITHOUT_VALUE_REGEXP);
|
423
|
+
this.errorMessage = match
|
424
|
+
? `Specification mandates value for attribute ${match[1]}\n`
|
425
|
+
: 'attributes construct error\n';
|
426
|
+
this.errorIndex = this.startTagIndex;
|
427
|
+
this.readState = MarkupReadStateEnum.error;
|
428
|
+
this.removeOverflowingTextNodes();
|
429
|
+
return;
|
430
|
+
}
|
431
|
+
if ((attributeMatch[1] && attributeMatch[3] === '"') ||
|
432
|
+
(attributeMatch[4] && attributeMatch[6] === "'")) {
|
433
|
+
// Valid attribute name and value.
|
434
|
+
const name = attributeMatch[1] ?? attributeMatch[4];
|
435
|
+
const rawValue = attributeMatch[2] ?? attributeMatch[5];
|
436
|
+
// In XML, new line characters should be replaced with a space.
|
437
|
+
const value = rawValue
|
438
|
+
? XMLEncodeUtility_js_1.default.decodeAttributeValue(rawValue.replace(NEW_LINE_REGEXP, ' '))
|
439
|
+
: '';
|
440
|
+
const attributes = this.nextElement[PropertySymbol.attributes];
|
441
|
+
const nameParts = name.split(':');
|
442
|
+
if (nameParts.length > 2 ||
|
443
|
+
(nameParts.length === 2 && (!nameParts[0] || !nameParts[1]))) {
|
444
|
+
this.errorMessage = `Failed to parse QName '${name}'\n`;
|
445
|
+
this.errorIndex =
|
446
|
+
this.startTagIndex + attributeMatch.index + attributeMatch[0].split('=')[0].length;
|
447
|
+
this.readState = MarkupReadStateEnum.error;
|
448
|
+
return;
|
449
|
+
}
|
450
|
+
// In XML, attributes prefixed with "xmlns:" or named "xmlns" should be set to the "http://www.w3.org/2000/xmlns/" namespace.
|
451
|
+
const namespaceURI = nameParts[0] === 'xmlns' ? NamespaceURI_js_1.default.xmlns : null;
|
452
|
+
if (!attributes.getNamedItemNS(namespaceURI, name)) {
|
453
|
+
const attributeItem = this.rootNode.createAttributeNS(namespaceURI, name);
|
454
|
+
attributeItem[PropertySymbol.value] = value;
|
455
|
+
attributes[PropertySymbol.setNamedItem](attributeItem);
|
456
|
+
// Attributes prefixed with "xmlns:" should be added to the namespace prefix map, so that the prefix can be added as namespaceURI to elements using the prefix.
|
457
|
+
if (attributeItem[PropertySymbol.prefix] === 'xmlns') {
|
458
|
+
namespacePrefix.set(attributeItem[PropertySymbol.localName], value);
|
459
|
+
// If the prefix matches the current element, we should set the namespace URI of the element to the value of the attribute.
|
460
|
+
// We don't need to upgrade the element, as there are no defined element types using a prefix.
|
461
|
+
if (this.nextElement[PropertySymbol.prefix] === attributeItem[PropertySymbol.localName]) {
|
462
|
+
this.nextElement[PropertySymbol.namespaceURI] = value;
|
156
463
|
}
|
157
|
-
currentNode[PropertySymbol.appendChild](document.createComment(Entities.decodeHTML(comment)), true);
|
158
|
-
}
|
159
|
-
else if (match[5] !== undefined) {
|
160
|
-
// Exclamation mark comment.
|
161
|
-
// Document type node or comment.
|
162
|
-
const exclamationComment = Entities.decodeHTML(match[5]);
|
163
|
-
currentNode[PropertySymbol.appendChild](this.getDocumentTypeNode(document, exclamationComment) ||
|
164
|
-
document.createComment(exclamationComment), true);
|
165
|
-
}
|
166
|
-
else if (match[6]) {
|
167
|
-
// Processing instruction (not supported by HTML).
|
168
|
-
// TODO: Add support for processing instructions.
|
169
|
-
}
|
170
|
-
else {
|
171
|
-
// Plain text between tags, including the match as it is not a valid start or end tag.
|
172
|
-
currentNode[PropertySymbol.appendChild](document.createTextNode(Entities.decodeHTML(xml.substring(lastIndex, markupRegexp.lastIndex))), true);
|
173
464
|
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
let attributeMatch;
|
184
|
-
while ((attributeMatch = attributeRegexp.exec(attributeString))) {
|
185
|
-
if ((attributeMatch[1] && attributeMatch[2]) ||
|
186
|
-
(attributeMatch[3] && attributeMatch[5] === '"') ||
|
187
|
-
(attributeMatch[6] && attributeMatch[8] === "'") ||
|
188
|
-
attributeMatch[9]) {
|
189
|
-
// Valid attribute name and value.
|
190
|
-
const name = attributeMatch[1] ||
|
191
|
-
attributeMatch[3] ||
|
192
|
-
attributeMatch[6] ||
|
193
|
-
attributeMatch[9] ||
|
194
|
-
'';
|
195
|
-
const rawValue = attributeMatch[2] || attributeMatch[4] || attributeMatch[7] || '';
|
196
|
-
const value = rawValue ? Entities.decodeHTMLAttribute(rawValue) : '';
|
197
|
-
if (newNode[PropertySymbol.namespaceURI] === NamespaceURI_js_1.default.svg) {
|
198
|
-
// In XML and SVG namespaces, the attribute "xmlns" should be set to the "http://www.w3.org/2000/xmlns/" namespace.
|
199
|
-
const attributeItem = document.createAttributeNS(name === 'xmlns' ? NamespaceURI_js_1.default.xmlns : null, name);
|
200
|
-
attributeItem[PropertySymbol.value] = value;
|
201
|
-
newNode[PropertySymbol.attributes][PropertySymbol.setNamedItem](attributeItem);
|
202
|
-
}
|
203
|
-
else {
|
204
|
-
const attributeItem = document.createAttribute(name);
|
205
|
-
attributeItem[PropertySymbol.value] = value;
|
206
|
-
newNode[PropertySymbol.attributes][PropertySymbol.setNamedItem](attributeItem);
|
207
|
-
}
|
208
|
-
startTagIndex += attributeMatch[0].length;
|
209
|
-
}
|
210
|
-
else if (!attributeMatch[1] &&
|
211
|
-
((attributeMatch[3] && !attributeMatch[5]) ||
|
212
|
-
(attributeMatch[6] && !attributeMatch[8]))) {
|
213
|
-
// End attribute apostrophe is missing (e.g. "attr='value" or 'attr="value').
|
214
|
-
hasAttributeStringEnded = false;
|
215
|
-
break;
|
216
|
-
}
|
465
|
+
// If the attribute is "xmlns", we should upgrade the element to an element created using the namespace URI.
|
466
|
+
else if (name === 'xmlns' && !this.nextElement[PropertySymbol.prefix]) {
|
467
|
+
// We only need to create a new instance if it is a known namespace URI.
|
468
|
+
if (NAMESPACE_URIS.includes(value)) {
|
469
|
+
this.nextElement = this.rootNode.createElementNS(value, this.nextElement[PropertySymbol.tagName]);
|
470
|
+
this.nextElement[PropertySymbol.attributes] = attributes;
|
471
|
+
attributes[PropertySymbol.ownerElement] = this.nextElement;
|
472
|
+
for (const attr of attributes[PropertySymbol.namespaceItems].values()) {
|
473
|
+
attr[PropertySymbol.ownerElement] = this.nextElement;
|
217
474
|
}
|
218
475
|
}
|
219
|
-
|
220
|
-
|
221
|
-
if (hasAttributeStringEnded) {
|
222
|
-
const config = HTMLElementConfig_js_1.default[newNode[PropertySymbol.localName]];
|
223
|
-
const localName = StringUtility_js_1.default.asciiLowerCase(newNode[PropertySymbol.localName]);
|
224
|
-
// Some elements are not allowed to be nested (e.g. "<a><a></a></a>" is not allowed.).
|
225
|
-
// Therefore we need to auto-close the tag, so that it become valid (e.g. "<a></a><a></a>").
|
226
|
-
if (config?.contentModel ===
|
227
|
-
HTMLElementConfigContentModelEnum_js_1.default.noFirstLevelSelfDescendants &&
|
228
|
-
localNameStack[localNameStack.length - 1] === localName) {
|
229
|
-
nodeStack.pop();
|
230
|
-
localNameStack.pop();
|
231
|
-
currentNode = nodeStack[nodeStack.length - 1] || root;
|
232
|
-
}
|
233
|
-
else if (config?.contentModel === HTMLElementConfigContentModelEnum_js_1.default.noSelfDescendants &&
|
234
|
-
localNameStack.includes(localName)) {
|
235
|
-
while (currentNode !== root) {
|
236
|
-
if (currentNode[PropertySymbol.localName] === localName) {
|
237
|
-
nodeStack.pop();
|
238
|
-
localNameStack.pop();
|
239
|
-
currentNode = nodeStack[nodeStack.length - 1] || root;
|
240
|
-
break;
|
241
|
-
}
|
242
|
-
nodeStack.pop();
|
243
|
-
localNameStack.pop();
|
244
|
-
currentNode = nodeStack[nodeStack.length - 1] || root;
|
245
|
-
}
|
246
|
-
}
|
247
|
-
// Appends the new node to its parent and sets is as current node.
|
248
|
-
currentNode[PropertySymbol.appendChild](newNode, true);
|
249
|
-
currentNode = newNode;
|
250
|
-
nodeStack.push(currentNode);
|
251
|
-
localNameStack.push(localName);
|
252
|
-
newNode = null;
|
253
|
-
// Checks if the tag is a self closing tag (ends with "/>") or void element.
|
254
|
-
// When it is a self closing tag or void element it should be closed immediately.
|
255
|
-
// Self closing tags are not allowed in the HTML namespace, but the parser should still allow it for void elements.
|
256
|
-
// Self closing tags is supported in the SVG namespace.
|
257
|
-
if (config?.contentModel === HTMLElementConfigContentModelEnum_js_1.default.noDescendants ||
|
258
|
-
// SVG tag is self closing (<svg/>).
|
259
|
-
(match[7] &&
|
260
|
-
currentNode[PropertySymbol.namespaceURI] === NamespaceURI_js_1.default.svg)) {
|
261
|
-
nodeStack.pop();
|
262
|
-
localNameStack.pop();
|
263
|
-
currentNode = nodeStack[nodeStack.length - 1] || root;
|
264
|
-
readState = MarkupReadStateEnum.startOrEndTag;
|
265
|
-
}
|
266
|
-
else {
|
267
|
-
readState =
|
268
|
-
config?.contentModel === HTMLElementConfigContentModelEnum_js_1.default.rawText
|
269
|
-
? MarkupReadStateEnum.plainTextContent
|
270
|
-
: MarkupReadStateEnum.startOrEndTag;
|
271
|
-
}
|
272
|
-
startTagIndex = markupRegexp.lastIndex;
|
273
|
-
}
|
274
|
-
}
|
275
|
-
break;
|
276
|
-
case MarkupReadStateEnum.plainTextContent:
|
277
|
-
const localName = currentNode[PropertySymbol.localName];
|
278
|
-
if (localName && match[2] && StringUtility_js_1.default.asciiLowerCase(match[2]) === localName) {
|
279
|
-
// End of plain text tag.
|
280
|
-
// Scripts are not allowed to be executed when they are parsed using innerHTML, outerHTML, replaceWith() etc.
|
281
|
-
// However, they are allowed to be executed when document.write() is used.
|
282
|
-
// See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement
|
283
|
-
if (localName === 'script') {
|
284
|
-
currentNode[PropertySymbol.evaluateScript] = evaluateScripts;
|
285
|
-
}
|
286
|
-
else if (localName === 'link') {
|
287
|
-
// An assumption that the same rule should be applied for the HTMLLinkElement is made here.
|
288
|
-
currentNode[PropertySymbol.evaluateCSS] = evaluateScripts;
|
476
|
+
else {
|
477
|
+
this.nextElement[PropertySymbol.namespaceURI] = value;
|
289
478
|
}
|
290
|
-
// Plain text elements such as <script> and <style> should only contain text.
|
291
|
-
currentNode[PropertySymbol.appendChild](document.createTextNode(Entities.decodeHTML(xml.substring(startTagIndex, match.index))), true);
|
292
|
-
nodeStack.pop();
|
293
|
-
localNameStack.pop();
|
294
|
-
currentNode = nodeStack[nodeStack.length - 1] || root;
|
295
|
-
readState = MarkupReadStateEnum.startOrEndTag;
|
296
479
|
}
|
297
|
-
|
480
|
+
}
|
481
|
+
else {
|
482
|
+
this.errorMessage = `Attribute ${name} redefined\n`;
|
483
|
+
this.errorIndex = this.startTagIndex;
|
484
|
+
this.readState = MarkupReadStateEnum.error;
|
485
|
+
}
|
486
|
+
this.startTagIndex += attributeMatch[0].length;
|
487
|
+
}
|
488
|
+
else if ((attributeMatch[1] && attributeMatch[3] !== '"') ||
|
489
|
+
(attributeMatch[4] && attributeMatch[6] !== "'")) {
|
490
|
+
// End attribute apostrophe is missing (e.g. "attr='value" or 'attr="value').
|
491
|
+
// We should continue to the next end of start tag match.
|
492
|
+
return;
|
493
|
+
}
|
494
|
+
lastIndex = attributeRegexp.lastIndex;
|
495
|
+
}
|
496
|
+
const attributeStringEnd = attributeString.substring(lastIndex).replace(SPACE_REGEXP, '');
|
497
|
+
if (attributeStringEnd.length) {
|
498
|
+
const match = attributeStringEnd.match(ATTRIBUTE_WITHOUT_VALUE_REGEXP);
|
499
|
+
if (match) {
|
500
|
+
this.errorMessage = `Specification mandates value for attribute ${match[1]}\n`;
|
501
|
+
this.errorIndex = this.markupRegExp.lastIndex - 2;
|
502
|
+
}
|
503
|
+
else {
|
504
|
+
this.errorMessage = 'attributes construct error\n';
|
505
|
+
this.errorIndex = this.startTagIndex;
|
298
506
|
}
|
299
|
-
|
507
|
+
this.readState = MarkupReadStateEnum.error;
|
508
|
+
this.removeOverflowingTextNodes();
|
509
|
+
return;
|
300
510
|
}
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
511
|
+
}
|
512
|
+
// Prefixed elements need to have a namespace URI defined by a prefixed "xmlns:" attribute either by a parent or in the current element.
|
513
|
+
if (this.nextElement[PropertySymbol.prefix] && !this.nextElement[PropertySymbol.namespaceURI]) {
|
514
|
+
this.errorMessage = `Namespace prefix ${this.nextElement[PropertySymbol.prefix]} on name is not defined\n`;
|
515
|
+
this.errorIndex = this.lastIndex;
|
516
|
+
this.readState = MarkupReadStateEnum.error;
|
517
|
+
return;
|
518
|
+
}
|
519
|
+
// Only one document element is allowed in the document.
|
520
|
+
if (this.currentNode === this.rootNode &&
|
521
|
+
this.rootNode[PropertySymbol.elementArray].length !== 0) {
|
522
|
+
this.errorMessage = 'Extra content at the end of the document\n';
|
523
|
+
this.errorIndex = this.lastIndex - this.nextElement[PropertySymbol.tagName].length - 1;
|
524
|
+
this.readState = MarkupReadStateEnum.error;
|
525
|
+
return;
|
526
|
+
}
|
527
|
+
this.currentNode[PropertySymbol.appendChild](this.nextElement, true);
|
528
|
+
// Sets the new element as the current node.
|
529
|
+
// XML nodes can be self closed using "/>"
|
530
|
+
if (!isSelfClosed) {
|
531
|
+
this.currentNode = this.nextElement;
|
532
|
+
this.nodeStack.push(this.currentNode);
|
533
|
+
this.tagNameStack.push(this.nextTagName);
|
534
|
+
if (this.currentNode[PropertySymbol.namespaceURI] &&
|
535
|
+
!this.currentNode[PropertySymbol.prefix]) {
|
536
|
+
this.defaultNamespaceStack.push(this.currentNode[PropertySymbol.namespaceURI]);
|
537
|
+
}
|
538
|
+
else {
|
539
|
+
this.defaultNamespaceStack.push(this.defaultNamespaceStack[this.defaultNamespaceStack.length - 1]);
|
305
540
|
}
|
306
|
-
|
307
|
-
|
308
|
-
|
541
|
+
}
|
542
|
+
this.nextElement = null;
|
543
|
+
this.nextTagName = null;
|
544
|
+
this.readState = MarkupReadStateEnum.any;
|
545
|
+
this.startTagIndex = this.markupRegExp.lastIndex;
|
546
|
+
}
|
547
|
+
/**
|
548
|
+
* Parses end tag.
|
549
|
+
*
|
550
|
+
* @param tagName Tag name.
|
551
|
+
* @returns True if the end tag was parsed, false otherwise.
|
552
|
+
*/
|
553
|
+
parseEndTag(tagName) {
|
554
|
+
if (this.tagNameStack[this.tagNameStack.length - 1] === tagName) {
|
555
|
+
this.nodeStack.pop();
|
556
|
+
this.tagNameStack.pop();
|
557
|
+
this.namespacePrefixStack.pop();
|
558
|
+
this.defaultNamespaceStack.pop();
|
559
|
+
this.currentNode = this.nodeStack[this.nodeStack.length - 1] || this.rootNode;
|
560
|
+
return true;
|
561
|
+
}
|
562
|
+
return false;
|
563
|
+
}
|
564
|
+
/**
|
565
|
+
* Parses XML document error.
|
566
|
+
*
|
567
|
+
* @param readXML XML that has been read.
|
568
|
+
* @param errorMessage Error message.
|
569
|
+
*/
|
570
|
+
parseError(readXML, errorMessage) {
|
571
|
+
let errorRoot = this.rootNode.documentElement;
|
572
|
+
if (!errorRoot) {
|
573
|
+
const documentElement = this.rootNode.createElementNS(NamespaceURI_js_1.default.html, 'html');
|
574
|
+
const body = this.rootNode.createElementNS(NamespaceURI_js_1.default.html, 'body');
|
575
|
+
documentElement.appendChild(body);
|
576
|
+
errorRoot = body;
|
577
|
+
this.rootNode[PropertySymbol.appendChild](documentElement, true);
|
578
|
+
}
|
579
|
+
const rows = readXML.split('\n');
|
580
|
+
const column = rows[rows.length - 1].length + 1;
|
581
|
+
const error = `error on line ${rows.length} at column ${column}: ${errorMessage}`;
|
582
|
+
const errorElement = this.rootNode.createElementNS(NamespaceURI_js_1.default.html, 'parsererror');
|
583
|
+
errorElement.setAttribute('style', 'display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black');
|
584
|
+
errorElement.innerHTML = `<h3>This page contains the following errors:</h3><div style="font-family:monospace;font-size:12px">${error}</div><h3>Below is a rendering of the page up to the first error.</h3>`;
|
585
|
+
errorRoot.insertBefore(errorElement, errorRoot.firstChild);
|
586
|
+
}
|
587
|
+
/**
|
588
|
+
* Removes overflowing text nodes in the current node.
|
589
|
+
*
|
590
|
+
* This needs to be done for some errors.
|
591
|
+
*/
|
592
|
+
removeOverflowingTextNodes() {
|
593
|
+
if (this.currentNode && this.currentNode !== this.rootNode) {
|
594
|
+
while (this.currentNode.lastChild?.[PropertySymbol.nodeType] === Node_js_1.default.TEXT_NODE) {
|
595
|
+
this.currentNode.removeChild(this.currentNode.lastChild);
|
309
596
|
}
|
310
597
|
}
|
311
|
-
return root;
|
312
598
|
}
|
313
599
|
/**
|
314
|
-
* Returns document type
|
600
|
+
* Returns document type.
|
315
601
|
*
|
316
|
-
* @param document Document.
|
317
602
|
* @param value Value.
|
318
|
-
* @returns Document type
|
603
|
+
* @returns Document type.
|
319
604
|
*/
|
320
|
-
|
605
|
+
getDocumentType(value) {
|
321
606
|
if (!value.toUpperCase().startsWith('DOCTYPE')) {
|
322
607
|
return null;
|
323
608
|
}
|
324
|
-
const docTypeSplit = value.split(
|
609
|
+
const docTypeSplit = value.split(SPACE_REGEXP);
|
325
610
|
if (docTypeSplit.length <= 1) {
|
326
611
|
return null;
|
327
612
|
}
|
@@ -335,7 +620,11 @@ class XMLParser {
|
|
335
620
|
}
|
336
621
|
const publicId = isPublic ? attributes[0] || '' : '';
|
337
622
|
const systemId = isPublic ? attributes[1] || '' : attributes[0] || '';
|
338
|
-
return
|
623
|
+
return {
|
624
|
+
name: docTypeSplit[1].toLowerCase(),
|
625
|
+
publicId,
|
626
|
+
systemId
|
627
|
+
};
|
339
628
|
}
|
340
629
|
}
|
341
630
|
exports.default = XMLParser;
|