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.
Files changed (489) hide show
  1. package/cjs/PropertySymbol.cjs +12 -9
  2. package/cjs/PropertySymbol.cjs.map +1 -1
  3. package/cjs/PropertySymbol.d.ts +4 -1
  4. package/cjs/PropertySymbol.d.ts.map +1 -1
  5. package/cjs/browser/utilities/BrowserFrameURL.cjs +1 -1
  6. package/cjs/browser/utilities/BrowserFrameURL.cjs.map +1 -1
  7. package/cjs/browser/utilities/BrowserFrameURL.d.ts +1 -1
  8. package/cjs/browser/utilities/BrowserFrameURL.d.ts.map +1 -1
  9. package/cjs/config/HTMLElementConfig.cjs +42 -16
  10. package/cjs/config/HTMLElementConfig.cjs.map +1 -1
  11. package/cjs/config/HTMLElementConfig.d.ts +7 -0
  12. package/cjs/config/HTMLElementConfig.d.ts.map +1 -1
  13. package/cjs/config/HTMLElementConfigContentModelEnum.cjs +3 -0
  14. package/cjs/config/HTMLElementConfigContentModelEnum.cjs.map +1 -1
  15. package/cjs/config/HTMLElementConfigContentModelEnum.d.ts +3 -0
  16. package/cjs/config/HTMLElementConfigContentModelEnum.d.ts.map +1 -1
  17. package/cjs/config/NamespaceURI.cjs +2 -0
  18. package/cjs/config/NamespaceURI.cjs.map +1 -1
  19. package/cjs/config/NamespaceURI.d.ts +2 -0
  20. package/cjs/config/NamespaceURI.d.ts.map +1 -1
  21. package/cjs/css/declaration/CSSStyleDeclaration.cjs +1 -1
  22. package/cjs/css/declaration/CSSStyleDeclaration.cjs.map +1 -1
  23. package/cjs/css/declaration/CSSStyleDeclaration.d.ts.map +1 -1
  24. package/cjs/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.cjs +2 -2
  25. package/cjs/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.cjs.map +1 -1
  26. package/cjs/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.d.ts.map +1 -1
  27. package/cjs/custom-element/CustomElementReactionStack.cjs +100 -0
  28. package/cjs/custom-element/CustomElementReactionStack.cjs.map +1 -0
  29. package/cjs/custom-element/CustomElementReactionStack.d.ts +27 -0
  30. package/cjs/custom-element/CustomElementReactionStack.d.ts.map +1 -0
  31. package/cjs/custom-element/CustomElementRegistry.cjs +32 -45
  32. package/cjs/custom-element/CustomElementRegistry.cjs.map +1 -1
  33. package/cjs/custom-element/CustomElementRegistry.d.ts +2 -6
  34. package/cjs/custom-element/CustomElementRegistry.d.ts.map +1 -1
  35. package/cjs/custom-element/CustomElementUtility.cjs +35 -0
  36. package/cjs/custom-element/CustomElementUtility.cjs.map +1 -0
  37. package/cjs/custom-element/CustomElementUtility.d.ts +14 -0
  38. package/cjs/custom-element/CustomElementUtility.d.ts.map +1 -0
  39. package/cjs/custom-element/ICustomElementDefinition.cjs +3 -0
  40. package/cjs/custom-element/ICustomElementDefinition.cjs.map +1 -0
  41. package/cjs/custom-element/ICustomElementDefinition.d.ts +12 -0
  42. package/cjs/custom-element/ICustomElementDefinition.d.ts.map +1 -0
  43. package/cjs/dom/DOMStringMap.cjs +8 -8
  44. package/cjs/dom/DOMStringMap.cjs.map +1 -1
  45. package/cjs/dom/DOMStringMap.d.ts.map +1 -1
  46. package/cjs/dom/DOMTokenList.cjs +1 -1
  47. package/cjs/dom/DOMTokenList.cjs.map +1 -1
  48. package/cjs/dom-parser/DOMParser.cjs +5 -67
  49. package/cjs/dom-parser/DOMParser.cjs.map +1 -1
  50. package/cjs/dom-parser/DOMParser.d.ts +0 -1
  51. package/cjs/dom-parser/DOMParser.d.ts.map +1 -1
  52. package/cjs/exception/DOMExceptionNameEnum.cjs +1 -0
  53. package/cjs/exception/DOMExceptionNameEnum.cjs.map +1 -1
  54. package/cjs/exception/DOMExceptionNameEnum.d.ts +2 -1
  55. package/cjs/exception/DOMExceptionNameEnum.d.ts.map +1 -1
  56. package/cjs/history/History.cjs +8 -8
  57. package/cjs/history/History.cjs.map +1 -1
  58. package/cjs/history/History.d.ts +2 -2
  59. package/cjs/history/History.d.ts.map +1 -1
  60. package/cjs/html-parser/HTMLParser.cjs +726 -0
  61. package/cjs/html-parser/HTMLParser.cjs.map +1 -0
  62. package/cjs/html-parser/HTMLParser.d.ts +91 -0
  63. package/cjs/html-parser/HTMLParser.d.ts.map +1 -0
  64. package/cjs/html-serializer/HTMLSerializer.cjs +152 -0
  65. package/cjs/html-serializer/HTMLSerializer.cjs.map +1 -0
  66. package/cjs/html-serializer/HTMLSerializer.d.ts +36 -0
  67. package/cjs/html-serializer/HTMLSerializer.d.ts.map +1 -0
  68. package/cjs/nodes/document/Document.cjs +105 -121
  69. package/cjs/nodes/document/Document.cjs.map +1 -1
  70. package/cjs/nodes/document/Document.d.ts +8 -0
  71. package/cjs/nodes/document/Document.d.ts.map +1 -1
  72. package/cjs/nodes/element/Element.cjs +35 -53
  73. package/cjs/nodes/element/Element.cjs.map +1 -1
  74. package/cjs/nodes/element/Element.d.ts +2 -12
  75. package/cjs/nodes/element/Element.d.ts.map +1 -1
  76. package/cjs/nodes/element/HTMLCollection.cjs +5 -9
  77. package/cjs/nodes/element/HTMLCollection.cjs.map +1 -1
  78. package/cjs/nodes/element/HTMLCollection.d.ts.map +1 -1
  79. package/cjs/nodes/element/NamedNodeMap.cjs +39 -52
  80. package/cjs/nodes/element/NamedNodeMap.cjs.map +1 -1
  81. package/cjs/nodes/element/NamedNodeMap.d.ts +1 -16
  82. package/cjs/nodes/element/NamedNodeMap.d.ts.map +1 -1
  83. package/cjs/nodes/element/NamedNodeMapProxyFactory.cjs +12 -14
  84. package/cjs/nodes/element/NamedNodeMapProxyFactory.cjs.map +1 -1
  85. package/cjs/nodes/element/NamedNodeMapProxyFactory.d.ts.map +1 -1
  86. package/cjs/nodes/html-button-element/HTMLButtonElement.cjs +1 -1
  87. package/cjs/nodes/html-button-element/HTMLButtonElement.cjs.map +1 -1
  88. package/cjs/nodes/html-button-element/HTMLButtonElement.d.ts.map +1 -1
  89. package/cjs/nodes/html-document/HTMLDocument.cjs +33 -2
  90. package/cjs/nodes/html-document/HTMLDocument.cjs.map +1 -1
  91. package/cjs/nodes/html-document/HTMLDocument.d.ts +10 -0
  92. package/cjs/nodes/html-document/HTMLDocument.d.ts.map +1 -1
  93. package/cjs/nodes/html-element/HTMLElement.cjs +52 -22
  94. package/cjs/nodes/html-element/HTMLElement.cjs.map +1 -1
  95. package/cjs/nodes/html-element/HTMLElement.d.ts +34 -0
  96. package/cjs/nodes/html-element/HTMLElement.d.ts.map +1 -1
  97. package/cjs/nodes/html-field-set-element/HTMLFieldSetElement.cjs +1 -1
  98. package/cjs/nodes/html-field-set-element/HTMLFieldSetElement.cjs.map +1 -1
  99. package/cjs/nodes/html-field-set-element/HTMLFieldSetElement.d.ts.map +1 -1
  100. package/cjs/nodes/html-form-element/HTMLFormElement.cjs +5 -8
  101. package/cjs/nodes/html-form-element/HTMLFormElement.cjs.map +1 -1
  102. package/cjs/nodes/html-form-element/HTMLFormElement.d.ts.map +1 -1
  103. package/cjs/nodes/html-iframe-element/HTMLIFrameElement.cjs +1 -1
  104. package/cjs/nodes/html-iframe-element/HTMLIFrameElement.cjs.map +1 -1
  105. package/cjs/nodes/html-input-element/HTMLInputElement.cjs +1 -1
  106. package/cjs/nodes/html-input-element/HTMLInputElement.cjs.map +1 -1
  107. package/cjs/nodes/html-input-element/HTMLInputElement.d.ts.map +1 -1
  108. package/cjs/nodes/html-media-element/TextTrackList.cjs +1 -1
  109. package/cjs/nodes/html-media-element/TextTrackList.cjs.map +1 -1
  110. package/cjs/nodes/html-object-element/HTMLObjectElement.cjs +1 -1
  111. package/cjs/nodes/html-object-element/HTMLObjectElement.cjs.map +1 -1
  112. package/cjs/nodes/html-object-element/HTMLObjectElement.d.ts.map +1 -1
  113. package/cjs/nodes/html-output-element/HTMLOutputElement.cjs +1 -1
  114. package/cjs/nodes/html-output-element/HTMLOutputElement.cjs.map +1 -1
  115. package/cjs/nodes/html-output-element/HTMLOutputElement.d.ts.map +1 -1
  116. package/cjs/nodes/html-script-element/HTMLScriptElement.cjs +3 -1
  117. package/cjs/nodes/html-script-element/HTMLScriptElement.cjs.map +1 -1
  118. package/cjs/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
  119. package/cjs/nodes/html-select-element/HTMLSelectElement.cjs +2 -2
  120. package/cjs/nodes/html-select-element/HTMLSelectElement.cjs.map +1 -1
  121. package/cjs/nodes/html-select-element/HTMLSelectElement.d.ts.map +1 -1
  122. package/cjs/nodes/html-table-element/HTMLTableElement.cjs +9 -1
  123. package/cjs/nodes/html-table-element/HTMLTableElement.cjs.map +1 -1
  124. package/cjs/nodes/html-table-element/HTMLTableElement.d.ts.map +1 -1
  125. package/cjs/nodes/html-table-row-element/HTMLTableRowElement.cjs +1 -1
  126. package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs +15 -17
  127. package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs.map +1 -1
  128. package/cjs/nodes/html-template-element/HTMLTemplateElement.d.ts +2 -2
  129. package/cjs/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
  130. package/cjs/nodes/html-text-area-element/HTMLTextAreaElement.cjs +1 -1
  131. package/cjs/nodes/html-text-area-element/HTMLTextAreaElement.cjs.map +1 -1
  132. package/cjs/nodes/html-text-area-element/HTMLTextAreaElement.d.ts.map +1 -1
  133. package/cjs/nodes/node/Node.cjs +44 -48
  134. package/cjs/nodes/node/Node.cjs.map +1 -1
  135. package/cjs/nodes/node/Node.d.ts +2 -10
  136. package/cjs/nodes/node/Node.d.ts.map +1 -1
  137. package/cjs/nodes/node/NodeList.cjs +1 -1
  138. package/cjs/nodes/node/NodeList.cjs.map +1 -1
  139. package/cjs/nodes/node/NodeUtility.cjs +4 -3
  140. package/cjs/nodes/node/NodeUtility.cjs.map +1 -1
  141. package/cjs/nodes/node/NodeUtility.d.ts.map +1 -1
  142. package/cjs/nodes/parent-node/ParentNodeUtility.cjs +5 -2
  143. package/cjs/nodes/parent-node/ParentNodeUtility.cjs.map +1 -1
  144. package/cjs/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
  145. package/cjs/nodes/shadow-root/ShadowRoot.cjs +8 -8
  146. package/cjs/nodes/shadow-root/ShadowRoot.cjs.map +1 -1
  147. package/cjs/nodes/shadow-root/ShadowRoot.d.ts.map +1 -1
  148. package/cjs/nodes/xml-document/XMLDocument.cjs +26 -0
  149. package/cjs/nodes/xml-document/XMLDocument.cjs.map +1 -1
  150. package/cjs/nodes/xml-document/XMLDocument.d.ts +2 -0
  151. package/cjs/nodes/xml-document/XMLDocument.d.ts.map +1 -1
  152. package/cjs/query-selector/SelectorItem.cjs +1 -2
  153. package/cjs/query-selector/SelectorItem.cjs.map +1 -1
  154. package/cjs/query-selector/SelectorItem.d.ts.map +1 -1
  155. package/cjs/range/Range.cjs +3 -3
  156. package/cjs/range/Range.cjs.map +1 -1
  157. package/cjs/range/Range.d.ts.map +1 -1
  158. package/cjs/storage/Storage.cjs +1 -1
  159. package/cjs/storage/Storage.cjs.map +1 -1
  160. package/cjs/svg/SVGLengthList.cjs +1 -1
  161. package/cjs/svg/SVGLengthList.cjs.map +1 -1
  162. package/cjs/svg/SVGNumberList.cjs +1 -1
  163. package/cjs/svg/SVGNumberList.cjs.map +1 -1
  164. package/cjs/svg/SVGPointList.cjs +1 -1
  165. package/cjs/svg/SVGPointList.cjs.map +1 -1
  166. package/cjs/svg/SVGStringList.cjs +1 -1
  167. package/cjs/svg/SVGStringList.cjs.map +1 -1
  168. package/cjs/svg/SVGTransformList.cjs +1 -1
  169. package/cjs/svg/SVGTransformList.cjs.map +1 -1
  170. package/cjs/tree-walker/NodeIterator.cjs +63 -6
  171. package/cjs/tree-walker/NodeIterator.cjs.map +1 -1
  172. package/cjs/tree-walker/NodeIterator.d.ts +18 -3
  173. package/cjs/tree-walker/NodeIterator.d.ts.map +1 -1
  174. package/cjs/tree-walker/TreeWalker.cjs +6 -6
  175. package/cjs/tree-walker/TreeWalker.cjs.map +1 -1
  176. package/cjs/tree-walker/TreeWalker.d.ts +2 -1
  177. package/cjs/tree-walker/TreeWalker.d.ts.map +1 -1
  178. package/cjs/utilities/ClassMethodBinder.cjs.map +1 -0
  179. package/cjs/utilities/ClassMethodBinder.d.ts.map +1 -0
  180. package/cjs/utilities/StringUtility.cjs.map +1 -0
  181. package/cjs/utilities/StringUtility.d.ts.map +1 -0
  182. package/cjs/utilities/XMLEncodeUtility.cjs +119 -0
  183. package/cjs/utilities/XMLEncodeUtility.cjs.map +1 -0
  184. package/cjs/utilities/XMLEncodeUtility.d.ts +48 -0
  185. package/cjs/utilities/XMLEncodeUtility.d.ts.map +1 -0
  186. package/cjs/window/BrowserWindow.cjs +9 -3
  187. package/cjs/window/BrowserWindow.cjs.map +1 -1
  188. package/cjs/window/BrowserWindow.d.ts +2 -0
  189. package/cjs/window/BrowserWindow.d.ts.map +1 -1
  190. package/cjs/window/WindowErrorUtility.cjs +1 -1
  191. package/cjs/window/WindowErrorUtility.cjs.map +1 -1
  192. package/cjs/xml-http-request/XMLHttpRequest.cjs +2 -1
  193. package/cjs/xml-http-request/XMLHttpRequest.cjs.map +1 -1
  194. package/cjs/xml-http-request/XMLHttpRequest.d.ts.map +1 -1
  195. package/cjs/xml-http-request/XMLHttpRequestResponseDataParser.cjs +1 -1
  196. package/cjs/xml-http-request/XMLHttpRequestResponseDataParser.cjs.map +1 -1
  197. package/cjs/xml-parser/XMLParser.cjs +531 -242
  198. package/cjs/xml-parser/XMLParser.cjs.map +1 -1
  199. package/cjs/xml-parser/XMLParser.d.ts +89 -19
  200. package/cjs/xml-parser/XMLParser.d.ts.map +1 -1
  201. package/cjs/xml-serializer/XMLSerializer.cjs +136 -40
  202. package/cjs/xml-serializer/XMLSerializer.cjs.map +1 -1
  203. package/cjs/xml-serializer/XMLSerializer.d.ts +6 -17
  204. package/cjs/xml-serializer/XMLSerializer.d.ts.map +1 -1
  205. package/lib/PropertySymbol.d.ts +4 -1
  206. package/lib/PropertySymbol.d.ts.map +1 -1
  207. package/lib/PropertySymbol.js +4 -1
  208. package/lib/PropertySymbol.js.map +1 -1
  209. package/lib/browser/utilities/BrowserFrameURL.d.ts +1 -1
  210. package/lib/browser/utilities/BrowserFrameURL.d.ts.map +1 -1
  211. package/lib/browser/utilities/BrowserFrameURL.js +1 -1
  212. package/lib/browser/utilities/BrowserFrameURL.js.map +1 -1
  213. package/lib/config/HTMLElementConfig.d.ts +7 -0
  214. package/lib/config/HTMLElementConfig.d.ts.map +1 -1
  215. package/lib/config/HTMLElementConfig.js +42 -16
  216. package/lib/config/HTMLElementConfig.js.map +1 -1
  217. package/lib/config/HTMLElementConfigContentModelEnum.d.ts +3 -0
  218. package/lib/config/HTMLElementConfigContentModelEnum.d.ts.map +1 -1
  219. package/lib/config/HTMLElementConfigContentModelEnum.js +3 -0
  220. package/lib/config/HTMLElementConfigContentModelEnum.js.map +1 -1
  221. package/lib/config/NamespaceURI.d.ts +2 -0
  222. package/lib/config/NamespaceURI.d.ts.map +1 -1
  223. package/lib/config/NamespaceURI.js +2 -0
  224. package/lib/config/NamespaceURI.js.map +1 -1
  225. package/lib/css/declaration/CSSStyleDeclaration.d.ts.map +1 -1
  226. package/lib/css/declaration/CSSStyleDeclaration.js +1 -1
  227. package/lib/css/declaration/CSSStyleDeclaration.js.map +1 -1
  228. package/lib/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.d.ts.map +1 -1
  229. package/lib/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.js +2 -2
  230. package/lib/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.js.map +1 -1
  231. package/lib/custom-element/CustomElementReactionStack.d.ts +27 -0
  232. package/lib/custom-element/CustomElementReactionStack.d.ts.map +1 -0
  233. package/lib/custom-element/CustomElementReactionStack.js +71 -0
  234. package/lib/custom-element/CustomElementReactionStack.js.map +1 -0
  235. package/lib/custom-element/CustomElementRegistry.d.ts +2 -6
  236. package/lib/custom-element/CustomElementRegistry.d.ts.map +1 -1
  237. package/lib/custom-element/CustomElementRegistry.js +32 -45
  238. package/lib/custom-element/CustomElementRegistry.js.map +1 -1
  239. package/lib/custom-element/CustomElementUtility.d.ts +14 -0
  240. package/lib/custom-element/CustomElementUtility.d.ts.map +1 -0
  241. package/lib/custom-element/CustomElementUtility.js +32 -0
  242. package/lib/custom-element/CustomElementUtility.js.map +1 -0
  243. package/lib/custom-element/ICustomElementDefinition.d.ts +12 -0
  244. package/lib/custom-element/ICustomElementDefinition.d.ts.map +1 -0
  245. package/lib/custom-element/ICustomElementDefinition.js +2 -0
  246. package/lib/custom-element/ICustomElementDefinition.js.map +1 -0
  247. package/lib/dom/DOMStringMap.d.ts.map +1 -1
  248. package/lib/dom/DOMStringMap.js +8 -8
  249. package/lib/dom/DOMStringMap.js.map +1 -1
  250. package/lib/dom/DOMTokenList.js +1 -1
  251. package/lib/dom/DOMTokenList.js.map +1 -1
  252. package/lib/dom-parser/DOMParser.d.ts +0 -1
  253. package/lib/dom-parser/DOMParser.d.ts.map +1 -1
  254. package/lib/dom-parser/DOMParser.js +5 -67
  255. package/lib/dom-parser/DOMParser.js.map +1 -1
  256. package/lib/exception/DOMExceptionNameEnum.d.ts +2 -1
  257. package/lib/exception/DOMExceptionNameEnum.d.ts.map +1 -1
  258. package/lib/exception/DOMExceptionNameEnum.js +1 -0
  259. package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
  260. package/lib/history/History.d.ts +2 -2
  261. package/lib/history/History.d.ts.map +1 -1
  262. package/lib/history/History.js +8 -8
  263. package/lib/history/History.js.map +1 -1
  264. package/lib/html-parser/HTMLParser.d.ts +91 -0
  265. package/lib/html-parser/HTMLParser.d.ts.map +1 -0
  266. package/lib/html-parser/HTMLParser.js +697 -0
  267. package/lib/html-parser/HTMLParser.js.map +1 -0
  268. package/lib/html-serializer/HTMLSerializer.d.ts +36 -0
  269. package/lib/html-serializer/HTMLSerializer.d.ts.map +1 -0
  270. package/lib/html-serializer/HTMLSerializer.js +123 -0
  271. package/lib/html-serializer/HTMLSerializer.js.map +1 -0
  272. package/lib/nodes/document/Document.d.ts +8 -0
  273. package/lib/nodes/document/Document.d.ts.map +1 -1
  274. package/lib/nodes/document/Document.js +106 -122
  275. package/lib/nodes/document/Document.js.map +1 -1
  276. package/lib/nodes/element/Element.d.ts +2 -12
  277. package/lib/nodes/element/Element.d.ts.map +1 -1
  278. package/lib/nodes/element/Element.js +35 -53
  279. package/lib/nodes/element/Element.js.map +1 -1
  280. package/lib/nodes/element/HTMLCollection.d.ts.map +1 -1
  281. package/lib/nodes/element/HTMLCollection.js +5 -9
  282. package/lib/nodes/element/HTMLCollection.js.map +1 -1
  283. package/lib/nodes/element/NamedNodeMap.d.ts +1 -16
  284. package/lib/nodes/element/NamedNodeMap.d.ts.map +1 -1
  285. package/lib/nodes/element/NamedNodeMap.js +39 -52
  286. package/lib/nodes/element/NamedNodeMap.js.map +1 -1
  287. package/lib/nodes/element/NamedNodeMapProxyFactory.d.ts.map +1 -1
  288. package/lib/nodes/element/NamedNodeMapProxyFactory.js +12 -14
  289. package/lib/nodes/element/NamedNodeMapProxyFactory.js.map +1 -1
  290. package/lib/nodes/html-button-element/HTMLButtonElement.d.ts.map +1 -1
  291. package/lib/nodes/html-button-element/HTMLButtonElement.js +1 -1
  292. package/lib/nodes/html-button-element/HTMLButtonElement.js.map +1 -1
  293. package/lib/nodes/html-document/HTMLDocument.d.ts +10 -0
  294. package/lib/nodes/html-document/HTMLDocument.d.ts.map +1 -1
  295. package/lib/nodes/html-document/HTMLDocument.js +33 -2
  296. package/lib/nodes/html-document/HTMLDocument.js.map +1 -1
  297. package/lib/nodes/html-element/HTMLElement.d.ts +34 -0
  298. package/lib/nodes/html-element/HTMLElement.d.ts.map +1 -1
  299. package/lib/nodes/html-element/HTMLElement.js +52 -22
  300. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  301. package/lib/nodes/html-field-set-element/HTMLFieldSetElement.d.ts.map +1 -1
  302. package/lib/nodes/html-field-set-element/HTMLFieldSetElement.js +1 -1
  303. package/lib/nodes/html-field-set-element/HTMLFieldSetElement.js.map +1 -1
  304. package/lib/nodes/html-form-element/HTMLFormElement.d.ts.map +1 -1
  305. package/lib/nodes/html-form-element/HTMLFormElement.js +5 -8
  306. package/lib/nodes/html-form-element/HTMLFormElement.js.map +1 -1
  307. package/lib/nodes/html-iframe-element/HTMLIFrameElement.js +1 -1
  308. package/lib/nodes/html-iframe-element/HTMLIFrameElement.js.map +1 -1
  309. package/lib/nodes/html-input-element/HTMLInputElement.d.ts.map +1 -1
  310. package/lib/nodes/html-input-element/HTMLInputElement.js +1 -1
  311. package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
  312. package/lib/nodes/html-media-element/TextTrackList.js +1 -1
  313. package/lib/nodes/html-media-element/TextTrackList.js.map +1 -1
  314. package/lib/nodes/html-object-element/HTMLObjectElement.d.ts.map +1 -1
  315. package/lib/nodes/html-object-element/HTMLObjectElement.js +1 -1
  316. package/lib/nodes/html-object-element/HTMLObjectElement.js.map +1 -1
  317. package/lib/nodes/html-output-element/HTMLOutputElement.d.ts.map +1 -1
  318. package/lib/nodes/html-output-element/HTMLOutputElement.js +1 -1
  319. package/lib/nodes/html-output-element/HTMLOutputElement.js.map +1 -1
  320. package/lib/nodes/html-script-element/HTMLScriptElement.d.ts.map +1 -1
  321. package/lib/nodes/html-script-element/HTMLScriptElement.js +3 -1
  322. package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
  323. package/lib/nodes/html-select-element/HTMLSelectElement.d.ts.map +1 -1
  324. package/lib/nodes/html-select-element/HTMLSelectElement.js +2 -2
  325. package/lib/nodes/html-select-element/HTMLSelectElement.js.map +1 -1
  326. package/lib/nodes/html-table-element/HTMLTableElement.d.ts.map +1 -1
  327. package/lib/nodes/html-table-element/HTMLTableElement.js +9 -1
  328. package/lib/nodes/html-table-element/HTMLTableElement.js.map +1 -1
  329. package/lib/nodes/html-table-row-element/HTMLTableRowElement.js +1 -1
  330. package/lib/nodes/html-template-element/HTMLTemplateElement.d.ts +2 -2
  331. package/lib/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
  332. package/lib/nodes/html-template-element/HTMLTemplateElement.js +15 -17
  333. package/lib/nodes/html-template-element/HTMLTemplateElement.js.map +1 -1
  334. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.d.ts.map +1 -1
  335. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js +1 -1
  336. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js.map +1 -1
  337. package/lib/nodes/node/Node.d.ts +2 -10
  338. package/lib/nodes/node/Node.d.ts.map +1 -1
  339. package/lib/nodes/node/Node.js +44 -48
  340. package/lib/nodes/node/Node.js.map +1 -1
  341. package/lib/nodes/node/NodeList.js +1 -1
  342. package/lib/nodes/node/NodeList.js.map +1 -1
  343. package/lib/nodes/node/NodeUtility.d.ts.map +1 -1
  344. package/lib/nodes/node/NodeUtility.js +4 -3
  345. package/lib/nodes/node/NodeUtility.js.map +1 -1
  346. package/lib/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
  347. package/lib/nodes/parent-node/ParentNodeUtility.js +5 -2
  348. package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
  349. package/lib/nodes/shadow-root/ShadowRoot.d.ts.map +1 -1
  350. package/lib/nodes/shadow-root/ShadowRoot.js +8 -8
  351. package/lib/nodes/shadow-root/ShadowRoot.js.map +1 -1
  352. package/lib/nodes/xml-document/XMLDocument.d.ts +2 -0
  353. package/lib/nodes/xml-document/XMLDocument.d.ts.map +1 -1
  354. package/lib/nodes/xml-document/XMLDocument.js +3 -0
  355. package/lib/nodes/xml-document/XMLDocument.js.map +1 -1
  356. package/lib/query-selector/SelectorItem.d.ts.map +1 -1
  357. package/lib/query-selector/SelectorItem.js +1 -2
  358. package/lib/query-selector/SelectorItem.js.map +1 -1
  359. package/lib/range/Range.d.ts.map +1 -1
  360. package/lib/range/Range.js +3 -3
  361. package/lib/range/Range.js.map +1 -1
  362. package/lib/storage/Storage.js +1 -1
  363. package/lib/storage/Storage.js.map +1 -1
  364. package/lib/svg/SVGLengthList.js +1 -1
  365. package/lib/svg/SVGLengthList.js.map +1 -1
  366. package/lib/svg/SVGNumberList.js +1 -1
  367. package/lib/svg/SVGNumberList.js.map +1 -1
  368. package/lib/svg/SVGPointList.js +1 -1
  369. package/lib/svg/SVGPointList.js.map +1 -1
  370. package/lib/svg/SVGStringList.js +1 -1
  371. package/lib/svg/SVGStringList.js.map +1 -1
  372. package/lib/svg/SVGTransformList.js +1 -1
  373. package/lib/svg/SVGTransformList.js.map +1 -1
  374. package/lib/tree-walker/NodeIterator.d.ts +18 -3
  375. package/lib/tree-walker/NodeIterator.d.ts.map +1 -1
  376. package/lib/tree-walker/NodeIterator.js +40 -6
  377. package/lib/tree-walker/NodeIterator.js.map +1 -1
  378. package/lib/tree-walker/TreeWalker.d.ts +2 -1
  379. package/lib/tree-walker/TreeWalker.d.ts.map +1 -1
  380. package/lib/tree-walker/TreeWalker.js +6 -6
  381. package/lib/tree-walker/TreeWalker.js.map +1 -1
  382. package/lib/utilities/ClassMethodBinder.d.ts.map +1 -0
  383. package/lib/utilities/ClassMethodBinder.js.map +1 -0
  384. package/lib/utilities/StringUtility.d.ts.map +1 -0
  385. package/lib/utilities/StringUtility.js.map +1 -0
  386. package/lib/utilities/XMLEncodeUtility.d.ts +48 -0
  387. package/lib/utilities/XMLEncodeUtility.d.ts.map +1 -0
  388. package/lib/utilities/XMLEncodeUtility.js +116 -0
  389. package/lib/utilities/XMLEncodeUtility.js.map +1 -0
  390. package/lib/window/BrowserWindow.d.ts +2 -0
  391. package/lib/window/BrowserWindow.d.ts.map +1 -1
  392. package/lib/window/BrowserWindow.js +9 -3
  393. package/lib/window/BrowserWindow.js.map +1 -1
  394. package/lib/window/WindowErrorUtility.js +1 -1
  395. package/lib/window/WindowErrorUtility.js.map +1 -1
  396. package/lib/xml-http-request/XMLHttpRequest.d.ts.map +1 -1
  397. package/lib/xml-http-request/XMLHttpRequest.js +2 -1
  398. package/lib/xml-http-request/XMLHttpRequest.js.map +1 -1
  399. package/lib/xml-http-request/XMLHttpRequestResponseDataParser.js +1 -1
  400. package/lib/xml-http-request/XMLHttpRequestResponseDataParser.js.map +1 -1
  401. package/lib/xml-parser/XMLParser.d.ts +89 -19
  402. package/lib/xml-parser/XMLParser.d.ts.map +1 -1
  403. package/lib/xml-parser/XMLParser.js +531 -242
  404. package/lib/xml-parser/XMLParser.js.map +1 -1
  405. package/lib/xml-serializer/XMLSerializer.d.ts +6 -17
  406. package/lib/xml-serializer/XMLSerializer.d.ts.map +1 -1
  407. package/lib/xml-serializer/XMLSerializer.js +136 -40
  408. package/lib/xml-serializer/XMLSerializer.js.map +1 -1
  409. package/package.json +1 -2
  410. package/src/PropertySymbol.ts +4 -1
  411. package/src/browser/utilities/BrowserFrameURL.ts +2 -2
  412. package/src/config/HTMLElementConfig.ts +53 -17
  413. package/src/config/HTMLElementConfigContentModelEnum.ts +3 -0
  414. package/src/config/NamespaceURI.ts +2 -0
  415. package/src/css/declaration/CSSStyleDeclaration.ts +1 -4
  416. package/src/css/declaration/computed-style/CSSStyleDeclarationComputedStyle.ts +2 -4
  417. package/src/custom-element/CustomElementReactionStack.ts +81 -0
  418. package/src/custom-element/CustomElementRegistry.ts +35 -54
  419. package/src/custom-element/CustomElementUtility.ts +34 -0
  420. package/src/custom-element/ICustomElementDefinition.ts +16 -0
  421. package/src/dom/DOMStringMap.ts +12 -10
  422. package/src/dom/DOMTokenList.ts +1 -1
  423. package/src/dom-parser/DOMParser.ts +5 -75
  424. package/src/exception/DOMExceptionNameEnum.ts +2 -1
  425. package/src/history/History.ts +10 -10
  426. package/src/html-parser/HTMLParser.ts +864 -0
  427. package/src/html-serializer/HTMLSerializer.ts +162 -0
  428. package/src/nodes/document/Document.ts +118 -137
  429. package/src/nodes/element/Element.ts +48 -95
  430. package/src/nodes/element/HTMLCollection.ts +5 -30
  431. package/src/nodes/element/NamedNodeMap.ts +58 -72
  432. package/src/nodes/element/NamedNodeMapProxyFactory.ts +12 -15
  433. package/src/nodes/html-button-element/HTMLButtonElement.ts +1 -4
  434. package/src/nodes/html-document/HTMLDocument.ts +58 -2
  435. package/src/nodes/html-element/HTMLElement.ts +107 -25
  436. package/src/nodes/html-field-set-element/HTMLFieldSetElement.ts +1 -4
  437. package/src/nodes/html-form-element/HTMLFormElement.ts +5 -27
  438. package/src/nodes/html-iframe-element/HTMLIFrameElement.ts +1 -1
  439. package/src/nodes/html-input-element/HTMLInputElement.ts +1 -4
  440. package/src/nodes/html-media-element/TextTrackList.ts +1 -1
  441. package/src/nodes/html-object-element/HTMLObjectElement.ts +1 -4
  442. package/src/nodes/html-output-element/HTMLOutputElement.ts +1 -4
  443. package/src/nodes/html-script-element/HTMLScriptElement.ts +4 -1
  444. package/src/nodes/html-select-element/HTMLSelectElement.ts +2 -5
  445. package/src/nodes/html-table-element/HTMLTableElement.ts +8 -1
  446. package/src/nodes/html-table-row-element/HTMLTableRowElement.ts +1 -1
  447. package/src/nodes/html-template-element/HTMLTemplateElement.ts +23 -17
  448. package/src/nodes/html-text-area-element/HTMLTextAreaElement.ts +1 -4
  449. package/src/nodes/node/Node.ts +57 -70
  450. package/src/nodes/node/NodeList.ts +1 -1
  451. package/src/nodes/node/NodeUtility.ts +4 -3
  452. package/src/nodes/parent-node/ParentNodeUtility.ts +6 -6
  453. package/src/nodes/shadow-root/ShadowRoot.ts +8 -8
  454. package/src/nodes/xml-document/XMLDocument.ts +5 -1
  455. package/src/query-selector/SelectorItem.ts +1 -2
  456. package/src/range/Range.ts +3 -3
  457. package/src/storage/Storage.ts +1 -1
  458. package/src/svg/SVGLengthList.ts +1 -1
  459. package/src/svg/SVGNumberList.ts +1 -1
  460. package/src/svg/SVGPointList.ts +1 -1
  461. package/src/svg/SVGStringList.ts +1 -1
  462. package/src/svg/SVGTransformList.ts +1 -1
  463. package/src/tree-walker/NodeIterator.ts +44 -8
  464. package/src/tree-walker/TreeWalker.ts +6 -6
  465. package/src/utilities/XMLEncodeUtility.ts +127 -0
  466. package/src/window/BrowserWindow.ts +18 -5
  467. package/src/window/WindowErrorUtility.ts +1 -1
  468. package/src/xml-http-request/XMLHttpRequest.ts +3 -1
  469. package/src/xml-http-request/XMLHttpRequestResponseDataParser.ts +1 -1
  470. package/src/xml-parser/XMLParser.ts +627 -313
  471. package/src/xml-serializer/XMLSerializer.ts +204 -58
  472. package/cjs/ClassMethodBinder.cjs.map +0 -1
  473. package/cjs/ClassMethodBinder.d.ts.map +0 -1
  474. package/cjs/StringUtility.cjs.map +0 -1
  475. package/cjs/StringUtility.d.ts.map +0 -1
  476. package/lib/ClassMethodBinder.d.ts.map +0 -1
  477. package/lib/ClassMethodBinder.js.map +0 -1
  478. package/lib/StringUtility.d.ts.map +0 -1
  479. package/lib/StringUtility.js.map +0 -1
  480. /package/cjs/{ClassMethodBinder.cjs → utilities/ClassMethodBinder.cjs} +0 -0
  481. /package/cjs/{ClassMethodBinder.d.ts → utilities/ClassMethodBinder.d.ts} +0 -0
  482. /package/cjs/{StringUtility.cjs → utilities/StringUtility.cjs} +0 -0
  483. /package/cjs/{StringUtility.d.ts → utilities/StringUtility.d.ts} +0 -0
  484. /package/lib/{ClassMethodBinder.d.ts → utilities/ClassMethodBinder.d.ts} +0 -0
  485. /package/lib/{ClassMethodBinder.js → utilities/ClassMethodBinder.js} +0 -0
  486. /package/lib/{StringUtility.d.ts → utilities/StringUtility.d.ts} +0 -0
  487. /package/lib/{StringUtility.js → utilities/StringUtility.js} +0 -0
  488. /package/src/{ClassMethodBinder.ts → utilities/ClassMethodBinder.ts} +0 -0
  489. /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 HTMLElementConfig_js_1 = __importDefault(require("../config/HTMLElementConfig.cjs"));
32
- const Entities = __importStar(require("entities"));
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*>|<!--([^-]+)-->|<!--([^>]+)>|<!([^>]*)>|<\?([^>]+)>|(\/>)|(>)/gm;
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 name when the attribute has a value using double apostrophe (e.g. "name" in "<div name="value">").
55
- * Group 4: Attribute value when the attribute has a value using double apostrophe (e.g. "value" in "<div name="value">").
56
- * Group 5: Attribute end apostrophe when the attribute has a value using double apostrophe (e.g. '"' in "<div name="value">").
57
- * Group 6: Attribute name when the attribute has a value using single apostrophe (e.g. "name" in "<div name='value'>").
58
- * Group 7: Attribute value when the attribute has a value using single apostrophe (e.g. "value" in "<div name='value'>").
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-_:.$@?\\]+) *= *([a-zA-Z0-9-_:.$@?{}/]+)|\s*([a-zA-Z0-9-_:.$@?\\]+) *= *"([^"]*)("{0,1})|\s*([a-zA-Z0-9-_:.$@?\\]+) *= *'([^']*)('{0,1})|\s*([a-zA-Z0-9-_:.$@?\\]+)/gm;
63
- var MarkupReadStateEnum;
64
- (function (MarkupReadStateEnum) {
65
- MarkupReadStateEnum["startOrEndTag"] = "startOrEndTag";
66
- MarkupReadStateEnum["insideStartTag"] = "insideStartTag";
67
- MarkupReadStateEnum["plainTextContent"] = "plainTextContent";
68
- })(MarkupReadStateEnum || (MarkupReadStateEnum = {}));
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
- * Parses XML/HTML and returns a root element.
113
+ * Constructor.
83
114
  *
84
- * @param document Document.
85
- * @param xml XML/HTML string.
115
+ * @param window Window.
86
116
  * @param [options] Options.
87
- * @param [options.rootNode] Node to append elements to. Otherwise a new DocumentFragment is created.
88
- * @param [options.evaluateScripts = false] Set to "true" to enable script execution.
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
- static parse(document, xml, options) {
92
- const root = options && options.rootNode ? options.rootNode : document.createDocumentFragment();
93
- const nodeStack = [root];
94
- const localNameStack = [null];
95
- const markupRegexp = new RegExp(MARKUP_REGEXP, 'gm');
96
- const { evaluateScripts = false } = options || {};
97
- let newNode = null;
98
- let currentNode = root;
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
- let readState = MarkupReadStateEnum.startOrEndTag;
101
- let startTagIndex = 0;
102
- let lastIndex = 0;
103
- if (xml !== null && xml !== undefined) {
104
- xml = String(xml);
105
- while ((match = markupRegexp.exec(xml))) {
106
- switch (readState) {
107
- case MarkupReadStateEnum.startOrEndTag:
108
- if (match.index !== lastIndex &&
109
- (match[1] || match[2] || match[3] || match[4] || match[5] !== undefined || match[6])) {
110
- // Plain text between tags.
111
- currentNode[PropertySymbol.appendChild](document.createTextNode(Entities.decodeHTML(xml.substring(lastIndex, match.index))), true);
112
- }
113
- if (match[1]) {
114
- // Start tag.
115
- const name = StringUtility_js_1.default.asciiLowerCase(match[1]);
116
- // NamespaceURI is inherited from the parent element.
117
- // NamespaceURI should be SVG for SVGSVGElement.
118
- const namespaceURI = name === 'svg'
119
- ? NamespaceURI_js_1.default.svg
120
- : currentNode[PropertySymbol.namespaceURI] || NamespaceURI_js_1.default.html;
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
- else if (match[2]) {
132
- // End tag.
133
- // We close all tags up until the first tag that matches the end tag.
134
- const localName = StringUtility_js_1.default.asciiLowerCase(match[2]);
135
- const index = localNameStack.lastIndexOf(localName);
136
- if (index !== -1) {
137
- nodeStack.splice(index, nodeStack.length - index);
138
- localNameStack.splice(index, localNameStack.length - index);
139
- currentNode = nodeStack[nodeStack.length - 1] || root;
140
- }
141
- }
142
- else if (match[3] ||
143
- match[4] ||
144
- (match[6] &&
145
- currentNode[PropertySymbol.namespaceURI] === NamespaceURI_js_1.default.html)) {
146
- // Comment.
147
- let comment;
148
- if (match[3]) {
149
- comment = match[3];
150
- }
151
- else if (match[4]) {
152
- comment = match[4].endsWith('--') ? match[4].slice(0, -2) : match[4];
153
- }
154
- else {
155
- comment = '?' + match[6];
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 '&lt;' 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, '&lt;' 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('&nbsp;')) {
271
+ this.errorMessage = `Entity 'nbsp' not defined\n`;
272
+ this.errorIndex = this.lastIndex + text.indexOf('&nbsp;') + 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
- break;
175
- case MarkupReadStateEnum.insideStartTag:
176
- // End of start tag
177
- if (match[7] || match[8]) {
178
- // Attribute name and value.
179
- const attributeString = xml.substring(startTagIndex, match.index);
180
- let hasAttributeStringEnded = true;
181
- if (!!attributeString) {
182
- const attributeRegexp = new RegExp(ATTRIBUTE_REGEXP, 'gm');
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
- // We need to check if the attribute string is read completely.
220
- // The attribute string can potentially contain "/>" or ">".
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
- break;
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
- lastIndex = markupRegexp.lastIndex;
507
+ this.readState = MarkupReadStateEnum.error;
508
+ this.removeOverflowingTextNodes();
509
+ return;
300
510
  }
301
- // We expected the "newNode" to be null if the start tag was closed correctly.
302
- // We should append the last node to the current node to correct it.
303
- if (newNode && currentNode) {
304
- currentNode[PropertySymbol.appendChild](newNode, true);
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
- if (lastIndex !== xml.length) {
307
- // Plain text after tags.
308
- currentNode[PropertySymbol.appendChild](document.createTextNode(Entities.decodeHTML(xml.substring(lastIndex))), true);
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 node.
600
+ * Returns document type.
315
601
  *
316
- * @param document Document.
317
602
  * @param value Value.
318
- * @returns Document type node.
603
+ * @returns Document type.
319
604
  */
320
- static getDocumentTypeNode(document, value) {
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 document.implementation.createDocumentType(docTypeSplit[1].toLowerCase(), publicId, systemId);
623
+ return {
624
+ name: docTypeSplit[1].toLowerCase(),
625
+ publicId,
626
+ systemId
627
+ };
339
628
  }
340
629
  }
341
630
  exports.default = XMLParser;