@dooboostore/dom-parser 1.0.1 → 1.0.3

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 (519) hide show
  1. package/dist/cjs/DomParser.js +43 -13
  2. package/dist/cjs/DomParser.js.map +2 -2
  3. package/dist/cjs/factory/ElementFactory.js +27 -6
  4. package/dist/cjs/factory/ElementFactory.js.map +2 -2
  5. package/dist/cjs/index.js +4 -0
  6. package/dist/cjs/index.js.map +2 -2
  7. package/dist/cjs/node/CharacterData.js.map +1 -1
  8. package/dist/cjs/node/ChildNode.js +0 -15
  9. package/dist/cjs/node/ChildNode.js.map +3 -3
  10. package/dist/cjs/node/ChildNodeBase.js +20 -0
  11. package/dist/cjs/node/ChildNodeBase.js.map +2 -2
  12. package/dist/cjs/node/Comment.js.map +2 -2
  13. package/dist/cjs/node/Document.js +0 -27
  14. package/dist/cjs/node/Document.js.map +4 -4
  15. package/dist/cjs/node/DocumentBase.js +169 -202
  16. package/dist/cjs/node/DocumentBase.js.map +2 -2
  17. package/dist/cjs/node/DocumentFragment.js +0 -15
  18. package/dist/cjs/node/DocumentFragment.js.map +3 -3
  19. package/dist/cjs/node/DocumentFragmentBase.js.map +2 -2
  20. package/dist/cjs/node/Node.js.map +1 -1
  21. package/dist/cjs/node/NodeBase.js +44 -2
  22. package/dist/cjs/node/NodeBase.js.map +2 -2
  23. package/dist/cjs/node/NodeFilter.js +43 -0
  24. package/dist/cjs/node/NodeFilter.js.map +7 -0
  25. package/dist/cjs/node/NodeIterator.js +1 -28
  26. package/dist/cjs/node/NodeIterator.js.map +2 -2
  27. package/dist/cjs/node/ParentNode.js +0 -15
  28. package/dist/cjs/node/ParentNode.js.map +3 -3
  29. package/dist/cjs/node/ParentNodeBase.js +10 -10
  30. package/dist/cjs/node/ParentNodeBase.js.map +3 -3
  31. package/dist/cjs/node/ShadowRootBase.js +79 -0
  32. package/dist/cjs/node/ShadowRootBase.js.map +7 -0
  33. package/dist/cjs/node/Text.js +0 -15
  34. package/dist/cjs/node/Text.js.map +3 -3
  35. package/dist/cjs/node/TextBase.js +0 -3
  36. package/dist/cjs/node/TextBase.js.map +2 -2
  37. package/dist/cjs/node/TreeWalker.js +272 -0
  38. package/dist/cjs/node/TreeWalker.js.map +7 -0
  39. package/dist/cjs/node/collection/{HTMLCollection.js → HTMLCollectionImp.js} +7 -6
  40. package/dist/cjs/node/collection/HTMLCollectionImp.js.map +7 -0
  41. package/dist/cjs/node/collection/HTMLCollectionOfImp.js +26 -0
  42. package/dist/cjs/node/collection/HTMLCollectionOfImp.js.map +7 -0
  43. package/dist/cjs/node/collection/NodeList.js.map +1 -1
  44. package/dist/cjs/node/collection/{NodeListOf.js → NodeListOfImp.js} +6 -6
  45. package/dist/cjs/node/collection/NodeListOfImp.js.map +7 -0
  46. package/dist/cjs/node/collection/StylePropertyMapImpl.js +65 -0
  47. package/dist/cjs/node/collection/StylePropertyMapImpl.js.map +7 -0
  48. package/dist/cjs/node/collection/index.js +6 -6
  49. package/dist/cjs/node/collection/index.js.map +2 -2
  50. package/dist/cjs/node/elements/Element.js +0 -15
  51. package/dist/cjs/node/elements/Element.js.map +3 -3
  52. package/dist/cjs/node/elements/ElementBase.js +164 -322
  53. package/dist/cjs/node/elements/ElementBase.js.map +3 -3
  54. package/dist/cjs/node/elements/HTMLAreaElement.js.map +2 -2
  55. package/dist/cjs/node/{collection/HTMLCollectionOf.js → elements/HTMLAudioElement.js} +9 -16
  56. package/dist/cjs/node/elements/HTMLAudioElement.js.map +7 -0
  57. package/dist/cjs/node/elements/HTMLButtonElement.js +1 -1
  58. package/dist/cjs/node/elements/HTMLButtonElement.js.map +2 -2
  59. package/dist/cjs/node/elements/HTMLDListElement.js +29 -0
  60. package/dist/cjs/node/elements/HTMLDListElement.js.map +7 -0
  61. package/dist/cjs/node/elements/HTMLDataElement.js +29 -0
  62. package/dist/cjs/node/elements/HTMLDataElement.js.map +7 -0
  63. package/dist/cjs/node/elements/HTMLDataListElement.js +29 -0
  64. package/dist/cjs/node/elements/HTMLDataListElement.js.map +7 -0
  65. package/dist/cjs/node/elements/HTMLDetailsElement.js +29 -0
  66. package/dist/cjs/node/elements/HTMLDetailsElement.js.map +7 -0
  67. package/dist/cjs/node/elements/HTMLDialogElement.js +29 -0
  68. package/dist/cjs/node/elements/HTMLDialogElement.js.map +7 -0
  69. package/dist/cjs/node/elements/HTMLElement.js +10 -0
  70. package/dist/cjs/node/elements/HTMLElement.js.map +2 -2
  71. package/dist/cjs/node/elements/HTMLElementBase.js +153 -3
  72. package/dist/cjs/node/elements/HTMLElementBase.js.map +2 -2
  73. package/dist/cjs/node/elements/HTMLEmbedElement.js.map +2 -2
  74. package/dist/cjs/node/elements/HTMLFieldSetElement.js +29 -0
  75. package/dist/cjs/node/elements/HTMLFieldSetElement.js.map +7 -0
  76. package/dist/cjs/node/elements/HTMLHRElement.js +29 -0
  77. package/dist/cjs/node/elements/HTMLHRElement.js.map +7 -0
  78. package/dist/cjs/node/elements/HTMLIFrameElement.js +29 -0
  79. package/dist/cjs/node/elements/HTMLIFrameElement.js.map +7 -0
  80. package/dist/cjs/node/elements/HTMLLabelElement.js +29 -0
  81. package/dist/cjs/node/elements/HTMLLabelElement.js.map +7 -0
  82. package/dist/cjs/node/elements/HTMLLegendElement.js +29 -0
  83. package/dist/cjs/node/elements/HTMLLegendElement.js.map +7 -0
  84. package/dist/cjs/node/elements/HTMLMapElement.js +29 -0
  85. package/dist/cjs/node/elements/HTMLMapElement.js.map +7 -0
  86. package/dist/cjs/node/elements/HTMLMeterElement.js +29 -0
  87. package/dist/cjs/node/elements/HTMLMeterElement.js.map +7 -0
  88. package/dist/cjs/node/elements/HTMLModElement.js +29 -0
  89. package/dist/cjs/node/elements/HTMLModElement.js.map +7 -0
  90. package/dist/cjs/node/elements/HTMLObjectElement.js +29 -0
  91. package/dist/cjs/node/elements/HTMLObjectElement.js.map +7 -0
  92. package/dist/cjs/node/elements/HTMLOptGroupElement.js +29 -0
  93. package/dist/cjs/node/elements/HTMLOptGroupElement.js.map +7 -0
  94. package/dist/cjs/node/elements/HTMLOptionElement.js +29 -0
  95. package/dist/cjs/node/elements/HTMLOptionElement.js.map +7 -0
  96. package/dist/cjs/node/elements/HTMLOutputElement.js +29 -0
  97. package/dist/cjs/node/elements/HTMLOutputElement.js.map +7 -0
  98. package/dist/cjs/node/elements/HTMLParamElement.js +29 -0
  99. package/dist/cjs/node/elements/HTMLParamElement.js.map +7 -0
  100. package/dist/cjs/node/elements/HTMLPictureElement.js +29 -0
  101. package/dist/cjs/node/elements/HTMLPictureElement.js.map +7 -0
  102. package/dist/cjs/node/elements/HTMLPreElement.js +29 -0
  103. package/dist/cjs/node/elements/HTMLPreElement.js.map +7 -0
  104. package/dist/cjs/node/elements/HTMLProgressElement.js +29 -0
  105. package/dist/cjs/node/elements/HTMLProgressElement.js.map +7 -0
  106. package/dist/cjs/node/elements/HTMLQuoteElement.js +29 -0
  107. package/dist/cjs/node/elements/HTMLQuoteElement.js.map +7 -0
  108. package/dist/cjs/node/elements/HTMLSelectElement.js +29 -0
  109. package/dist/cjs/node/elements/HTMLSelectElement.js.map +7 -0
  110. package/dist/cjs/node/elements/HTMLSlotElement.js +29 -0
  111. package/dist/cjs/node/elements/HTMLSlotElement.js.map +7 -0
  112. package/dist/cjs/node/elements/HTMLSourceElement.js +29 -0
  113. package/dist/cjs/node/elements/HTMLSourceElement.js.map +7 -0
  114. package/dist/cjs/node/elements/HTMLTableElement.js.map +2 -2
  115. package/dist/cjs/node/elements/HTMLTbodyElement.js.map +2 -2
  116. package/dist/cjs/node/elements/HTMLTdElement.js.map +2 -2
  117. package/dist/cjs/node/elements/HTMLTemplateElement.js.map +2 -2
  118. package/dist/cjs/node/elements/HTMLTextAreaElement.js +29 -0
  119. package/dist/cjs/node/elements/HTMLTextAreaElement.js.map +7 -0
  120. package/dist/cjs/node/elements/HTMLTfootElement.js.map +2 -2
  121. package/dist/cjs/node/elements/HTMLTheadElement.js.map +2 -2
  122. package/dist/cjs/node/elements/HTMLTimeElement.js +29 -0
  123. package/dist/cjs/node/elements/HTMLTimeElement.js.map +7 -0
  124. package/dist/cjs/node/elements/HTMLTrElement.js.map +2 -2
  125. package/dist/cjs/node/elements/HTMLTrackElement.js +29 -0
  126. package/dist/cjs/node/elements/HTMLTrackElement.js.map +7 -0
  127. package/dist/cjs/node/elements/HTMLVideoElement.js +29 -0
  128. package/dist/cjs/node/elements/HTMLVideoElement.js.map +7 -0
  129. package/dist/cjs/node/elements/index.js +181 -92
  130. package/dist/cjs/node/elements/index.js.map +2 -2
  131. package/dist/cjs/node/index.js +6 -16
  132. package/dist/cjs/node/index.js.map +2 -2
  133. package/dist/cjs/utils/CSSSelector.js.map +2 -2
  134. package/dist/cjs/window/CustomElementRegistryImp.js +105 -0
  135. package/dist/cjs/window/CustomElementRegistryImp.js.map +7 -0
  136. package/dist/cjs/window/Window.js +0 -15
  137. package/dist/cjs/window/Window.js.map +3 -3
  138. package/dist/cjs/window/WindowBase.js +233 -515
  139. package/dist/cjs/window/WindowBase.js.map +2 -2
  140. package/dist/cjs/window/index.js +0 -5
  141. package/dist/cjs/window/index.js.map +2 -2
  142. package/dist/esm/DomParser.js +43 -13
  143. package/dist/esm/DomParser.js.map +2 -2
  144. package/dist/esm/factory/ElementFactory.js +27 -6
  145. package/dist/esm/factory/ElementFactory.js.map +2 -2
  146. package/dist/esm/index.js +4 -0
  147. package/dist/esm/index.js.map +2 -2
  148. package/dist/esm/node/ChildNodeBase.js +20 -0
  149. package/dist/esm/node/ChildNodeBase.js.map +2 -2
  150. package/dist/esm/node/Comment.js.map +2 -2
  151. package/dist/esm/node/Document.js +0 -8
  152. package/dist/esm/node/Document.js.map +4 -4
  153. package/dist/esm/node/DocumentBase.js +166 -199
  154. package/dist/esm/node/DocumentBase.js.map +2 -2
  155. package/dist/esm/node/DocumentFragmentBase.js.map +2 -2
  156. package/dist/esm/node/Node.js.map +1 -1
  157. package/dist/esm/node/NodeBase.js +45 -22
  158. package/dist/esm/node/NodeBase.js.map +2 -2
  159. package/dist/esm/node/NodeFilter.js +24 -0
  160. package/dist/esm/node/NodeFilter.js.map +7 -0
  161. package/dist/esm/node/NodeIterator.js +1 -28
  162. package/dist/esm/node/NodeIterator.js.map +2 -2
  163. package/dist/esm/node/ParentNodeBase.js +4 -4
  164. package/dist/esm/node/ParentNodeBase.js.map +2 -2
  165. package/dist/esm/node/ShadowRootBase.js +60 -0
  166. package/dist/esm/node/ShadowRootBase.js.map +7 -0
  167. package/dist/esm/node/TextBase.js +0 -3
  168. package/dist/esm/node/TextBase.js.map +2 -2
  169. package/dist/esm/node/TreeWalker.js +253 -0
  170. package/dist/esm/node/TreeWalker.js.map +7 -0
  171. package/dist/esm/node/collection/{HTMLCollection.js → HTMLCollectionImp.js} +4 -3
  172. package/dist/esm/node/collection/HTMLCollectionImp.js.map +7 -0
  173. package/dist/esm/node/collection/HTMLCollectionOfImp.js +7 -0
  174. package/dist/esm/node/collection/HTMLCollectionOfImp.js.map +7 -0
  175. package/dist/esm/node/collection/NodeList.js.map +1 -1
  176. package/dist/esm/node/collection/{NodeListOf.js → NodeListOfImp.js} +3 -3
  177. package/dist/esm/node/collection/NodeListOfImp.js.map +7 -0
  178. package/dist/esm/node/collection/StylePropertyMapImpl.js +46 -0
  179. package/dist/esm/node/collection/StylePropertyMapImpl.js.map +7 -0
  180. package/dist/esm/node/collection/index.js +6 -6
  181. package/dist/esm/node/collection/index.js.map +2 -2
  182. package/dist/esm/node/elements/ElementBase.js +164 -322
  183. package/dist/esm/node/elements/ElementBase.js.map +3 -3
  184. package/dist/esm/node/elements/HTMLAreaElement.js.map +2 -2
  185. package/dist/esm/node/elements/HTMLAudioElement.js +10 -0
  186. package/dist/esm/node/elements/HTMLAudioElement.js.map +7 -0
  187. package/dist/esm/node/elements/HTMLButtonElement.js +1 -1
  188. package/dist/esm/node/elements/HTMLButtonElement.js.map +2 -2
  189. package/dist/esm/node/elements/HTMLDListElement.js +10 -0
  190. package/dist/esm/node/elements/HTMLDListElement.js.map +7 -0
  191. package/dist/esm/node/elements/HTMLDataElement.js +10 -0
  192. package/dist/esm/node/elements/HTMLDataElement.js.map +7 -0
  193. package/dist/esm/node/elements/HTMLDataListElement.js +10 -0
  194. package/dist/esm/node/elements/HTMLDataListElement.js.map +7 -0
  195. package/dist/esm/node/elements/HTMLDetailsElement.js +10 -0
  196. package/dist/esm/node/elements/HTMLDetailsElement.js.map +7 -0
  197. package/dist/esm/node/elements/HTMLDialogElement.js +10 -0
  198. package/dist/esm/node/elements/HTMLDialogElement.js.map +7 -0
  199. package/dist/esm/node/elements/HTMLElement.js +6 -0
  200. package/dist/esm/node/elements/HTMLElement.js.map +3 -3
  201. package/dist/esm/node/elements/HTMLElementBase.js +153 -3
  202. package/dist/esm/node/elements/HTMLElementBase.js.map +2 -2
  203. package/dist/esm/node/elements/HTMLEmbedElement.js.map +2 -2
  204. package/dist/esm/node/elements/HTMLFieldSetElement.js +10 -0
  205. package/dist/esm/node/elements/HTMLFieldSetElement.js.map +7 -0
  206. package/dist/esm/node/elements/HTMLHRElement.js +10 -0
  207. package/dist/esm/node/elements/HTMLHRElement.js.map +7 -0
  208. package/dist/esm/node/elements/HTMLIFrameElement.js +10 -0
  209. package/dist/esm/node/elements/HTMLIFrameElement.js.map +7 -0
  210. package/dist/esm/node/elements/HTMLLabelElement.js +10 -0
  211. package/dist/esm/node/elements/HTMLLabelElement.js.map +7 -0
  212. package/dist/esm/node/elements/HTMLLegendElement.js +10 -0
  213. package/dist/esm/node/elements/HTMLLegendElement.js.map +7 -0
  214. package/dist/esm/node/elements/HTMLMapElement.js +10 -0
  215. package/dist/esm/node/elements/HTMLMapElement.js.map +7 -0
  216. package/dist/esm/node/elements/HTMLMeterElement.js +10 -0
  217. package/dist/esm/node/elements/HTMLMeterElement.js.map +7 -0
  218. package/dist/esm/node/elements/HTMLModElement.js +10 -0
  219. package/dist/esm/node/elements/HTMLModElement.js.map +7 -0
  220. package/dist/esm/node/elements/HTMLObjectElement.js +10 -0
  221. package/dist/esm/node/elements/HTMLObjectElement.js.map +7 -0
  222. package/dist/esm/node/elements/HTMLOptGroupElement.js +10 -0
  223. package/dist/esm/node/elements/HTMLOptGroupElement.js.map +7 -0
  224. package/dist/esm/node/elements/HTMLOptionElement.js +10 -0
  225. package/dist/esm/node/elements/HTMLOptionElement.js.map +7 -0
  226. package/dist/esm/node/elements/HTMLOutputElement.js +10 -0
  227. package/dist/esm/node/elements/HTMLOutputElement.js.map +7 -0
  228. package/dist/esm/node/elements/HTMLParamElement.js +10 -0
  229. package/dist/esm/node/elements/HTMLParamElement.js.map +7 -0
  230. package/dist/esm/node/elements/HTMLPictureElement.js +10 -0
  231. package/dist/esm/node/elements/HTMLPictureElement.js.map +7 -0
  232. package/dist/esm/node/elements/HTMLPreElement.js +10 -0
  233. package/dist/esm/node/elements/HTMLPreElement.js.map +7 -0
  234. package/dist/esm/node/elements/HTMLProgressElement.js +10 -0
  235. package/dist/esm/node/elements/HTMLProgressElement.js.map +7 -0
  236. package/dist/esm/node/elements/HTMLQuoteElement.js +10 -0
  237. package/dist/esm/node/elements/HTMLQuoteElement.js.map +7 -0
  238. package/dist/esm/node/elements/HTMLSelectElement.js +10 -0
  239. package/dist/esm/node/elements/HTMLSelectElement.js.map +7 -0
  240. package/dist/esm/node/elements/HTMLSlotElement.js +10 -0
  241. package/dist/esm/node/elements/HTMLSlotElement.js.map +7 -0
  242. package/dist/esm/node/elements/HTMLSourceElement.js +10 -0
  243. package/dist/esm/node/elements/HTMLSourceElement.js.map +7 -0
  244. package/dist/esm/node/elements/HTMLTableElement.js.map +2 -2
  245. package/dist/esm/node/elements/HTMLTbodyElement.js.map +2 -2
  246. package/dist/esm/node/elements/HTMLTdElement.js.map +2 -2
  247. package/dist/esm/node/elements/HTMLTemplateElement.js.map +2 -2
  248. package/dist/esm/node/elements/HTMLTextAreaElement.js +10 -0
  249. package/dist/esm/node/elements/HTMLTextAreaElement.js.map +7 -0
  250. package/dist/esm/node/elements/HTMLTfootElement.js.map +2 -2
  251. package/dist/esm/node/elements/HTMLTheadElement.js.map +2 -2
  252. package/dist/esm/node/elements/HTMLTimeElement.js +10 -0
  253. package/dist/esm/node/elements/HTMLTimeElement.js.map +7 -0
  254. package/dist/esm/node/elements/HTMLTrElement.js.map +2 -2
  255. package/dist/esm/node/elements/HTMLTrackElement.js +10 -0
  256. package/dist/esm/node/elements/HTMLTrackElement.js.map +7 -0
  257. package/dist/esm/node/elements/HTMLVideoElement.js +10 -0
  258. package/dist/esm/node/elements/HTMLVideoElement.js.map +7 -0
  259. package/dist/esm/node/elements/index.js +182 -93
  260. package/dist/esm/node/elements/index.js.map +2 -2
  261. package/dist/esm/node/index.js +7 -17
  262. package/dist/esm/node/index.js.map +2 -2
  263. package/dist/esm/utils/CSSSelector.js.map +2 -2
  264. package/dist/esm/window/CustomElementRegistryImp.js +86 -0
  265. package/dist/esm/window/CustomElementRegistryImp.js.map +7 -0
  266. package/dist/esm/window/WindowBase.js +282 -499
  267. package/dist/esm/window/WindowBase.js.map +2 -2
  268. package/dist/esm/window/index.js +0 -5
  269. package/dist/esm/window/index.js.map +2 -2
  270. package/dist/esm-bundle/dooboostore-dom-parser.esm.js +3755 -3548
  271. package/dist/esm-bundle/dooboostore-dom-parser.esm.js.map +4 -4
  272. package/dist/types/DomParser.d.ts +4 -0
  273. package/dist/types/DomParser.d.ts.map +1 -1
  274. package/dist/types/factory/ElementFactory.d.ts +1 -1
  275. package/dist/types/factory/ElementFactory.d.ts.map +1 -1
  276. package/dist/types/index.d.ts +3 -1
  277. package/dist/types/index.d.ts.map +1 -1
  278. package/dist/types/node/CharacterData.d.ts +0 -2
  279. package/dist/types/node/CharacterData.d.ts.map +1 -1
  280. package/dist/types/node/ChildNode.d.ts +0 -38
  281. package/dist/types/node/ChildNode.d.ts.map +1 -1
  282. package/dist/types/node/ChildNodeBase.d.ts +6 -4
  283. package/dist/types/node/ChildNodeBase.d.ts.map +1 -1
  284. package/dist/types/node/Comment.d.ts +1 -1
  285. package/dist/types/node/Comment.d.ts.map +1 -1
  286. package/dist/types/node/Document.d.ts +0 -856
  287. package/dist/types/node/Document.d.ts.map +1 -1
  288. package/dist/types/node/DocumentBase.d.ts +68 -108
  289. package/dist/types/node/DocumentBase.d.ts.map +1 -1
  290. package/dist/types/node/DocumentFragment.d.ts +0 -38
  291. package/dist/types/node/DocumentFragment.d.ts.map +1 -1
  292. package/dist/types/node/DocumentFragmentBase.d.ts +1 -8
  293. package/dist/types/node/DocumentFragmentBase.d.ts.map +1 -1
  294. package/dist/types/node/Node.d.ts +0 -213
  295. package/dist/types/node/Node.d.ts.map +1 -1
  296. package/dist/types/node/NodeBase.d.ts +11 -8
  297. package/dist/types/node/NodeBase.d.ts.map +1 -1
  298. package/dist/types/node/NodeFilter.d.ts +25 -0
  299. package/dist/types/node/NodeFilter.d.ts.map +1 -0
  300. package/dist/types/node/NodeIterator.d.ts +0 -34
  301. package/dist/types/node/NodeIterator.d.ts.map +1 -1
  302. package/dist/types/node/ParentNode.d.ts +0 -84
  303. package/dist/types/node/ParentNode.d.ts.map +1 -1
  304. package/dist/types/node/ParentNodeBase.d.ts +0 -5
  305. package/dist/types/node/ParentNodeBase.d.ts.map +1 -1
  306. package/dist/types/node/ShadowRootBase.d.ts +36 -0
  307. package/dist/types/node/ShadowRootBase.d.ts.map +1 -0
  308. package/dist/types/node/Text.d.ts +0 -24
  309. package/dist/types/node/Text.d.ts.map +1 -1
  310. package/dist/types/node/TextBase.d.ts +2 -3
  311. package/dist/types/node/TextBase.d.ts.map +1 -1
  312. package/dist/types/node/TreeWalker.d.ts +48 -0
  313. package/dist/types/node/TreeWalker.d.ts.map +1 -0
  314. package/dist/types/node/collection/{HTMLCollection.d.ts → HTMLCollectionImp.d.ts} +2 -3
  315. package/dist/types/node/collection/HTMLCollectionImp.d.ts.map +1 -0
  316. package/dist/types/node/collection/HTMLCollectionOfImp.d.ts +9 -0
  317. package/dist/types/node/collection/HTMLCollectionOfImp.d.ts.map +1 -0
  318. package/dist/types/node/collection/NodeList.d.ts +0 -1
  319. package/dist/types/node/collection/NodeList.d.ts.map +1 -1
  320. package/dist/types/node/collection/{NodeListOf.d.ts → NodeListOfImp.d.ts} +3 -4
  321. package/dist/types/node/collection/NodeListOfImp.d.ts.map +1 -0
  322. package/dist/types/node/collection/StylePropertyMapImpl.d.ts +20 -0
  323. package/dist/types/node/collection/StylePropertyMapImpl.d.ts.map +1 -0
  324. package/dist/types/node/collection/index.d.ts +3 -3
  325. package/dist/types/node/collection/index.d.ts.map +1 -1
  326. package/dist/types/node/elements/Element.d.ts +0 -686
  327. package/dist/types/node/elements/Element.d.ts.map +1 -1
  328. package/dist/types/node/elements/ElementBase.d.ts +97 -73
  329. package/dist/types/node/elements/ElementBase.d.ts.map +1 -1
  330. package/dist/types/node/elements/HTMLAreaElement.d.ts +0 -1
  331. package/dist/types/node/elements/HTMLAreaElement.d.ts.map +1 -1
  332. package/dist/types/node/elements/HTMLAudioElement.d.ts +8 -0
  333. package/dist/types/node/elements/HTMLAudioElement.d.ts.map +1 -0
  334. package/dist/types/node/elements/HTMLButtonElement.d.ts +1 -1
  335. package/dist/types/node/elements/HTMLButtonElement.d.ts.map +1 -1
  336. package/dist/types/node/elements/HTMLDListElement.d.ts +5 -0
  337. package/dist/types/node/elements/HTMLDListElement.d.ts.map +1 -0
  338. package/dist/types/node/elements/HTMLDataElement.d.ts +5 -0
  339. package/dist/types/node/elements/HTMLDataElement.d.ts.map +1 -0
  340. package/dist/types/node/elements/HTMLDataListElement.d.ts +5 -0
  341. package/dist/types/node/elements/HTMLDataListElement.d.ts.map +1 -0
  342. package/dist/types/node/elements/HTMLDetailsElement.d.ts +5 -0
  343. package/dist/types/node/elements/HTMLDetailsElement.d.ts.map +1 -0
  344. package/dist/types/node/elements/HTMLDialogElement.d.ts +5 -0
  345. package/dist/types/node/elements/HTMLDialogElement.d.ts.map +1 -0
  346. package/dist/types/node/elements/HTMLElement.d.ts +2 -88
  347. package/dist/types/node/elements/HTMLElement.d.ts.map +1 -1
  348. package/dist/types/node/elements/HTMLElementBase.d.ts +133 -3
  349. package/dist/types/node/elements/HTMLElementBase.d.ts.map +1 -1
  350. package/dist/types/node/elements/HTMLEmbedElement.d.ts +0 -1
  351. package/dist/types/node/elements/HTMLEmbedElement.d.ts.map +1 -1
  352. package/dist/types/node/elements/HTMLFieldSetElement.d.ts +5 -0
  353. package/dist/types/node/elements/HTMLFieldSetElement.d.ts.map +1 -0
  354. package/dist/types/node/elements/HTMLHRElement.d.ts +5 -0
  355. package/dist/types/node/elements/HTMLHRElement.d.ts.map +1 -0
  356. package/dist/types/node/elements/HTMLIFrameElement.d.ts +5 -0
  357. package/dist/types/node/elements/HTMLIFrameElement.d.ts.map +1 -0
  358. package/dist/types/node/elements/HTMLLabelElement.d.ts +5 -0
  359. package/dist/types/node/elements/HTMLLabelElement.d.ts.map +1 -0
  360. package/dist/types/node/elements/HTMLLegendElement.d.ts +5 -0
  361. package/dist/types/node/elements/HTMLLegendElement.d.ts.map +1 -0
  362. package/dist/types/node/elements/HTMLMapElement.d.ts +5 -0
  363. package/dist/types/node/elements/HTMLMapElement.d.ts.map +1 -0
  364. package/dist/types/node/elements/HTMLMeterElement.d.ts +5 -0
  365. package/dist/types/node/elements/HTMLMeterElement.d.ts.map +1 -0
  366. package/dist/types/node/elements/HTMLModElement.d.ts +5 -0
  367. package/dist/types/node/elements/HTMLModElement.d.ts.map +1 -0
  368. package/dist/types/node/elements/HTMLObjectElement.d.ts +5 -0
  369. package/dist/types/node/elements/HTMLObjectElement.d.ts.map +1 -0
  370. package/dist/types/node/elements/HTMLOptGroupElement.d.ts +5 -0
  371. package/dist/types/node/elements/HTMLOptGroupElement.d.ts.map +1 -0
  372. package/dist/types/node/elements/HTMLOptionElement.d.ts +5 -0
  373. package/dist/types/node/elements/HTMLOptionElement.d.ts.map +1 -0
  374. package/dist/types/node/elements/HTMLOutputElement.d.ts +5 -0
  375. package/dist/types/node/elements/HTMLOutputElement.d.ts.map +1 -0
  376. package/dist/types/node/elements/HTMLParamElement.d.ts +5 -0
  377. package/dist/types/node/elements/HTMLParamElement.d.ts.map +1 -0
  378. package/dist/types/node/elements/HTMLPictureElement.d.ts +5 -0
  379. package/dist/types/node/elements/HTMLPictureElement.d.ts.map +1 -0
  380. package/dist/types/node/elements/HTMLPreElement.d.ts +5 -0
  381. package/dist/types/node/elements/HTMLPreElement.d.ts.map +1 -0
  382. package/dist/types/node/elements/HTMLProgressElement.d.ts +5 -0
  383. package/dist/types/node/elements/HTMLProgressElement.d.ts.map +1 -0
  384. package/dist/types/node/elements/HTMLQuoteElement.d.ts +5 -0
  385. package/dist/types/node/elements/HTMLQuoteElement.d.ts.map +1 -0
  386. package/dist/types/node/elements/HTMLSelectElement.d.ts +5 -0
  387. package/dist/types/node/elements/HTMLSelectElement.d.ts.map +1 -0
  388. package/dist/types/node/elements/HTMLSlotElement.d.ts +5 -0
  389. package/dist/types/node/elements/HTMLSlotElement.d.ts.map +1 -0
  390. package/dist/types/node/elements/HTMLSourceElement.d.ts +5 -0
  391. package/dist/types/node/elements/HTMLSourceElement.d.ts.map +1 -0
  392. package/dist/types/node/elements/HTMLTableElement.d.ts +3 -4
  393. package/dist/types/node/elements/HTMLTableElement.d.ts.map +1 -1
  394. package/dist/types/node/elements/HTMLTbodyElement.d.ts +2 -3
  395. package/dist/types/node/elements/HTMLTbodyElement.d.ts.map +1 -1
  396. package/dist/types/node/elements/HTMLTemplateElement.d.ts +0 -1
  397. package/dist/types/node/elements/HTMLTemplateElement.d.ts.map +1 -1
  398. package/dist/types/node/elements/HTMLTextAreaElement.d.ts +5 -0
  399. package/dist/types/node/elements/HTMLTextAreaElement.d.ts.map +1 -0
  400. package/dist/types/node/elements/HTMLTfootElement.d.ts +2 -3
  401. package/dist/types/node/elements/HTMLTfootElement.d.ts.map +1 -1
  402. package/dist/types/node/elements/HTMLTheadElement.d.ts +2 -3
  403. package/dist/types/node/elements/HTMLTheadElement.d.ts.map +1 -1
  404. package/dist/types/node/elements/HTMLTimeElement.d.ts +5 -0
  405. package/dist/types/node/elements/HTMLTimeElement.d.ts.map +1 -0
  406. package/dist/types/node/elements/HTMLTrElement.d.ts +2 -3
  407. package/dist/types/node/elements/HTMLTrElement.d.ts.map +1 -1
  408. package/dist/types/node/elements/HTMLTrackElement.d.ts +5 -0
  409. package/dist/types/node/elements/HTMLTrackElement.d.ts.map +1 -0
  410. package/dist/types/node/elements/HTMLVideoElement.d.ts +8 -0
  411. package/dist/types/node/elements/HTMLVideoElement.d.ts.map +1 -0
  412. package/dist/types/node/elements/index.d.ts +106 -52
  413. package/dist/types/node/elements/index.d.ts.map +1 -1
  414. package/dist/types/node/index.d.ts +4 -7
  415. package/dist/types/node/index.d.ts.map +1 -1
  416. package/dist/types/utils/CSSSelector.d.ts +0 -1
  417. package/dist/types/utils/CSSSelector.d.ts.map +1 -1
  418. package/dist/types/window/CustomElementRegistryImp.d.ts +18 -0
  419. package/dist/types/window/CustomElementRegistryImp.d.ts.map +1 -0
  420. package/dist/types/window/Window.d.ts +0 -619
  421. package/dist/types/window/Window.d.ts.map +1 -1
  422. package/dist/types/window/WindowBase.d.ts +261 -284
  423. package/dist/types/window/WindowBase.d.ts.map +1 -1
  424. package/dist/types/window/index.d.ts +0 -1
  425. package/dist/types/window/index.d.ts.map +1 -1
  426. package/dist/umd-bundle/dooboostore-dom-parser.umd.js +3765 -3558
  427. package/dist/umd-bundle/dooboostore-dom-parser.umd.js.map +4 -4
  428. package/package.json +1 -1
  429. package/src/DomParser.ts +458 -429
  430. package/src/factory/ElementFactory.ts +79 -53
  431. package/src/index.ts +11 -10
  432. package/src/node/CharacterData.ts +0 -2
  433. package/src/node/ChildNode.ts +42 -42
  434. package/src/node/ChildNodeBase.ts +60 -39
  435. package/src/node/Comment.ts +60 -60
  436. package/src/node/Document.ts +129 -882
  437. package/src/node/DocumentBase.ts +371 -462
  438. package/src/node/DocumentFragment.ts +38 -44
  439. package/src/node/DocumentFragmentBase.ts +4 -9
  440. package/src/node/Node.ts +231 -224
  441. package/src/node/NodeBase.ts +469 -443
  442. package/src/node/NodeFilter.ts +50 -0
  443. package/src/node/NodeIterator.ts +117 -172
  444. package/src/node/ParentNode.ts +93 -93
  445. package/src/node/ParentNodeBase.ts +7 -10
  446. package/src/node/ShadowRootBase.ts +87 -0
  447. package/src/node/Text.ts +30 -30
  448. package/src/node/TextBase.ts +92 -94
  449. package/src/node/TreeWalker.ts +280 -0
  450. package/src/node/collection/{HTMLCollection.ts → HTMLCollectionImp.ts} +3 -2
  451. package/src/node/collection/HTMLCollectionOfImp.ts +12 -0
  452. package/src/node/collection/NodeList.ts +1 -1
  453. package/src/node/collection/{NodeListOf.ts → NodeListOfImp.ts} +3 -3
  454. package/src/node/collection/StylePropertyMapImpl.ts +60 -0
  455. package/src/node/collection/index.ts +3 -3
  456. package/src/node/elements/Element.ts +212 -771
  457. package/src/node/elements/ElementBase.ts +840 -1195
  458. package/src/node/elements/HTMLAreaElement.ts +0 -1
  459. package/src/node/elements/HTMLAudioElement.ts +10 -0
  460. package/src/node/elements/HTMLButtonElement.ts +63 -63
  461. package/src/node/elements/HTMLDListElement.ts +2 -0
  462. package/src/node/elements/HTMLDataElement.ts +6 -0
  463. package/src/node/elements/HTMLDataListElement.ts +2 -0
  464. package/src/node/elements/HTMLDetailsElement.ts +2 -0
  465. package/src/node/elements/HTMLDialogElement.ts +2 -0
  466. package/src/node/elements/HTMLElement.ts +2 -102
  467. package/src/node/elements/HTMLElementBase.ts +453 -156
  468. package/src/node/elements/HTMLEmbedElement.ts +0 -1
  469. package/src/node/elements/HTMLFieldSetElement.ts +2 -0
  470. package/src/node/elements/HTMLHRElement.ts +2 -0
  471. package/src/node/elements/HTMLIFrameElement.ts +2 -0
  472. package/src/node/elements/HTMLLabelElement.ts +2 -0
  473. package/src/node/elements/HTMLLegendElement.ts +2 -0
  474. package/src/node/elements/HTMLMapElement.ts +2 -0
  475. package/src/node/elements/HTMLMeterElement.ts +2 -0
  476. package/src/node/elements/HTMLModElement.ts +2 -0
  477. package/src/node/elements/HTMLObjectElement.ts +2 -0
  478. package/src/node/elements/HTMLOptGroupElement.ts +2 -0
  479. package/src/node/elements/HTMLOptionElement.ts +2 -0
  480. package/src/node/elements/HTMLOutputElement.ts +2 -0
  481. package/src/node/elements/HTMLParamElement.ts +2 -0
  482. package/src/node/elements/HTMLPictureElement.ts +2 -0
  483. package/src/node/elements/HTMLPreElement.ts +2 -0
  484. package/src/node/elements/HTMLProgressElement.ts +2 -0
  485. package/src/node/elements/HTMLQuoteElement.ts +2 -0
  486. package/src/node/elements/HTMLSelectElement.ts +2 -0
  487. package/src/node/elements/HTMLSlotElement.ts +2 -0
  488. package/src/node/elements/HTMLSourceElement.ts +2 -0
  489. package/src/node/elements/HTMLTableElement.ts +3 -7
  490. package/src/node/elements/HTMLTbodyElement.ts +2 -3
  491. package/src/node/elements/HTMLTdElement.ts +1 -1
  492. package/src/node/elements/HTMLTemplateElement.ts +3 -6
  493. package/src/node/elements/HTMLTextAreaElement.ts +2 -0
  494. package/src/node/elements/HTMLTfootElement.ts +2 -3
  495. package/src/node/elements/HTMLTheadElement.ts +2 -3
  496. package/src/node/elements/HTMLTimeElement.ts +2 -0
  497. package/src/node/elements/HTMLTrElement.ts +3 -4
  498. package/src/node/elements/HTMLTrackElement.ts +2 -0
  499. package/src/node/elements/HTMLVideoElement.ts +10 -0
  500. package/src/node/elements/index.ts +226 -149
  501. package/src/node/index.ts +8 -8
  502. package/src/utils/CSSSelector.ts +0 -1
  503. package/src/window/CustomElementRegistryImp.ts +120 -0
  504. package/src/window/Window.ts +716 -715
  505. package/src/window/WindowBase.ts +842 -998
  506. package/src/window/index.ts +0 -1
  507. package/tsconfig.json +1 -0
  508. package/dist/cjs/node/collection/HTMLCollection.js.map +0 -7
  509. package/dist/cjs/node/collection/HTMLCollectionOf.js.map +0 -7
  510. package/dist/cjs/node/collection/NodeListOf.js.map +0 -7
  511. package/dist/esm/node/collection/HTMLCollection.js.map +0 -7
  512. package/dist/esm/node/collection/HTMLCollectionOf.js +0 -17
  513. package/dist/esm/node/collection/HTMLCollectionOf.js.map +0 -7
  514. package/dist/esm/node/collection/NodeListOf.js.map +0 -7
  515. package/dist/types/node/collection/HTMLCollection.d.ts.map +0 -1
  516. package/dist/types/node/collection/HTMLCollectionOf.d.ts +0 -14
  517. package/dist/types/node/collection/HTMLCollectionOf.d.ts.map +0 -1
  518. package/dist/types/node/collection/NodeListOf.d.ts.map +0 -1
  519. package/src/node/collection/HTMLCollectionOf.ts +0 -26
@@ -1,1239 +1,884 @@
1
1
  import { ParentNodeBase } from '../ParentNodeBase';
2
- import { ChildNodeBase } from '../ChildNodeBase';
3
- import { HTMLCollection } from "../collection";
4
- import { Text } from "../Text";
5
- import { ElementFactory } from "../../factory/ElementFactory";
6
- import { Element, DOMTokenList, Attr, NamedNodeMap } from './Element';
2
+ import { HTMLCollectionImp, HTMLCollectionOfImp } from '../collection';
7
3
  import { ELEMENT_NODE, TEXT_NODE, ATTRIBUTE_NODE } from '../Node';
8
4
  import { CSSSelector } from '../../utils/CSSSelector';
9
- import { HTMLElementTagNameMap } from "./index";
10
5
  import { NodeBase } from '../NodeBase';
11
-
12
- // InsertPosition type for insertAdjacent methods
13
- type InsertPosition = 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
6
+ import { ShadowRootBase } from '../ShadowRootBase';
14
7
 
15
8
  // Simple DOMException class for error handling
16
9
  class DOMException extends Error {
17
- constructor(message: string, public name: string = 'DOMException') {
18
- super(message);
19
- this.name = name;
20
- }
10
+ constructor(
11
+ message: string,
12
+ public name: string = 'DOMException'
13
+ ) {
14
+ super(message);
15
+ this.name = name;
16
+ }
21
17
  }
18
+
22
19
  /**
23
20
  * Base implementation of the Element interface
24
21
  */
22
+ // @ts-ignore
25
23
  export abstract class ElementBase extends ParentNodeBase implements Element {
26
- private _id: string = '';
27
- private _className: string = '';
28
- private _attributes: Map<string, string> = new Map();
29
-
30
- constructor(
31
- public _tagName: string,
32
- ownerDocument?: any
33
- ) {
34
- super(ELEMENT_NODE, _tagName.toUpperCase(), ownerDocument);
35
- }
36
-
37
- get tagName(): string {
38
- return this._tagName.toUpperCase();
39
- }
40
-
41
- get localName(): string {
42
- return this._tagName.toLowerCase();
43
- }
44
-
45
- // Element interface implementation
46
- get id(): string {
47
- return this._id;
48
- }
49
-
50
- set id(value: string) {
51
- this._id = value;
52
- this._attributes.set('id', value);
53
- }
54
-
55
- get className(): string {
56
- return this._className;
57
- }
58
-
59
- set className(value: string) {
60
- this._className = value;
61
- this._attributes.set('class', value);
62
- }
63
-
64
- get classList(): DOMTokenList {
65
- return new DOMTokenListImpl(this);
66
- }
67
-
68
- get innerHTML(): string {
69
- // Generate innerHTML from actual child nodes
70
- let html = '';
71
- for (const child of this._childNodesInternal) {
72
- if (child.nodeType === TEXT_NODE) {
73
- // For text nodes, use the escaped content stored in _nodeValue
74
- html += (child as any)._nodeValue || '';
75
- } else if (child.nodeType === ELEMENT_NODE) {
76
- // Generate outerHTML directly to avoid circular dependency
77
- html += this.generateChildElementHTML(child as any);
78
- } else if (child.nodeType === 8) { // COMMENT_NODE
79
- html += `<!--${(child as any).textContent || ''}-->`;
80
- }
24
+ /**
25
+ * Static dependencies to break circular references without using 'require' or 'global'.
26
+ * These are injected by the main DomParser entry point.
27
+ */
28
+ public static dependencies: {
29
+ ElementFactory?: any;
30
+ TextBase?: any;
31
+ Comment?: any;
32
+ } = {};
33
+
34
+ private _id: string = '';
35
+ private _className: string = '';
36
+ private _attributes: Map<string, string> = new Map();
37
+ private _shadowRoot: ShadowRoot | null = null;
38
+
39
+ constructor(
40
+ public _tagName: string = 'DIV',
41
+ ownerDocument?: any
42
+ ) {
43
+ super(ELEMENT_NODE, _tagName.toUpperCase(), ownerDocument);
44
+ }
45
+
46
+ ariaActiveDescendantElement: Element;
47
+ ariaAtomic: string;
48
+ ariaAutoComplete: string;
49
+ ariaBrailleLabel: string;
50
+ ariaBrailleRoleDescription: string;
51
+ ariaBusy: string;
52
+ ariaChecked: string;
53
+ ariaColCount: string;
54
+ ariaColIndex: string;
55
+ ariaColIndexText: string;
56
+ ariaColSpan: string;
57
+ ariaControlsElements: readonly Element[];
58
+ ariaCurrent: string;
59
+ ariaDescribedByElements: readonly Element[];
60
+ ariaDescription: string;
61
+ ariaDetailsElements: readonly Element[];
62
+ ariaDisabled: string;
63
+ ariaErrorMessageElements: readonly Element[];
64
+ ariaExpanded: string;
65
+ ariaFlowToElements: readonly Element[];
66
+ ariaHasPopup: string;
67
+ ariaHidden: string;
68
+ ariaInvalid: string;
69
+ ariaKeyShortcuts: string;
70
+ ariaLabel: string;
71
+ ariaLabelledByElements: readonly Element[];
72
+ ariaLevel: string;
73
+ ariaLive: string;
74
+ ariaModal: string;
75
+ ariaMultiLine: string;
76
+ ariaMultiSelectable: string;
77
+ ariaOrientation: string;
78
+ ariaOwnsElements: readonly Element[];
79
+ ariaPlaceholder: string;
80
+ ariaPosInSet: string;
81
+ ariaPressed: string;
82
+ ariaReadOnly: string;
83
+ ariaRelevant: string;
84
+ ariaRequired: string;
85
+ ariaRoleDescription: string;
86
+ ariaRowCount: string;
87
+ ariaRowIndex: string;
88
+ ariaRowIndexText: string;
89
+ ariaRowSpan: string;
90
+ ariaSelected: string;
91
+ ariaSetSize: string;
92
+ ariaSort: string;
93
+ ariaValueMax: string;
94
+ ariaValueMin: string;
95
+ ariaValueNow: string;
96
+ ariaValueText: string;
97
+ role: string;
98
+ animate(keyframes: Keyframe[] | PropertyIndexedKeyframes | null, options?: number | KeyframeAnimationOptions): Animation {
99
+ throw new Error('Method not implemented.');
100
+ }
101
+ getAnimations(options?: GetAnimationsOptions): Animation[] {
102
+ throw new Error('Method not implemented.');
103
+ }
104
+
105
+ get tagName(): string {
106
+ return this._tagName.toUpperCase();
107
+ }
108
+
109
+ get localName(): string {
110
+ return this._tagName.toLowerCase();
111
+ }
112
+
113
+ // Element interface implementation
114
+ get id(): string {
115
+ return this._id;
116
+ }
117
+
118
+ set id(value: string) {
119
+ this._id = value;
120
+ this._attributes.set('id', value);
121
+ }
122
+
123
+ get className(): string {
124
+ return this._className;
125
+ }
126
+
127
+ set className(value: string) {
128
+ this._className = value;
129
+ this._attributes.set('class', value);
130
+ }
131
+
132
+ get classList(): DOMTokenList {
133
+ return new (DOMTokenListImpl as any)(this);
134
+ }
135
+
136
+ get innerHTML(): string {
137
+ // Generate innerHTML from actual child nodes
138
+ let html = '';
139
+ for (const child of this._childNodesInternal) {
140
+ if (child.nodeType === TEXT_NODE) {
141
+ // For text nodes, use the escaped content stored in _nodeValue
142
+ html += (child as any)._nodeValue || '';
143
+ } else if (child.nodeType === ELEMENT_NODE) {
144
+ // Generate outerHTML directly to avoid circular dependency
145
+ html += this.generateChildElementHTML(child as any);
146
+ } else if (child.nodeType === 8) {
147
+ // COMMENT_NODE
148
+ html += `<!--${(child as any).textContent || ''}-->`;
149
+ }
150
+ }
151
+ return html;
152
+ }
153
+
154
+ get innerText(): string {
155
+ // innerText should return the decoded text content
156
+ return this.textContent || '';
157
+ }
158
+
159
+ set innerText(value: string | null) {
160
+ // Clear all children and add escaped text content
161
+ this._childNodesInternal = [];
162
+ if (value !== null && value !== undefined) {
163
+ const stringValue = String(value);
164
+ const escapedValue = this.escapeHTMLEntities(stringValue);
165
+
166
+ const { TextBase } = ElementBase.dependencies;
167
+ if (TextBase) {
168
+ const textNode = new TextBase(escapedValue, this._ownerDocument);
169
+ this._childNodesInternal.push(textNode);
170
+ (textNode as any)._parentNodeInternal = this;
171
+ }
172
+ }
173
+ }
174
+
175
+ set innerHTML(value: string) {
176
+ // Clear existing children
177
+ while (this._childNodesInternal.length > 0) {
178
+ const child = this._childNodesInternal[0];
179
+ if (child) {
180
+ this.removeChild(child);
181
+ }
182
+ }
183
+
184
+ // Parse HTML and create child nodes
185
+ if (value.trim()) {
186
+ this.parseAndAppendHTML(value);
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Generate HTML for a child element without using outerHTML to avoid circular dependency
192
+ */
193
+ private generateChildElementHTML(element: any): string {
194
+ const tagName = element.tagName.toLowerCase();
195
+ // Get attributes
196
+ const attrs = Array.from(element._attributes?.entries() || [])
197
+ .map(([name, value]: [string, string]) => (value === '' ? ` ${name}` : ` ${name}="${String(value).replace(/"/g, '&quot;')}"`))
198
+ .join('');
199
+
200
+ // Check if it's a self-closing tag
201
+ const selfClosingTags = ['img', 'input', 'br', 'hr', 'meta', 'link', 'area', 'base', 'col', 'embed', 'source', 'track', 'wbr'];
202
+ const isSelfClosing = selfClosingTags.includes(tagName);
203
+
204
+ if (isSelfClosing) {
205
+ return `<${tagName}${attrs} />`;
206
+ } else {
207
+ // Generate innerHTML directly without calling element.innerHTML to avoid recursion
208
+ let childHTML = '';
209
+
210
+ // Add Declarative Shadow DOM if present
211
+ if (element.shadowRoot) {
212
+ childHTML += `<template shadowrootmode="${element.shadowRoot.mode}">${element.shadowRoot.innerHTML}</template>`;
213
+ }
214
+
215
+ for (const child of element._childNodesInternal || []) {
216
+ if (child.nodeType === TEXT_NODE) {
217
+ childHTML += (child as any)._nodeValue || '';
218
+ } else if (child.nodeType === ELEMENT_NODE) {
219
+ childHTML += this.generateChildElementHTML(child as any);
220
+ } else if (child.nodeType === 8) {
221
+ // COMMENT_NODE
222
+ childHTML += `<!--${(child as any).textContent || ''}-->`;
81
223
  }
82
- return html;
224
+ }
225
+ return `<${tagName}${attrs}>${childHTML}</${tagName}>`;
83
226
  }
227
+ }
84
228
 
85
- get innerText(): string {
86
- // innerText should return the decoded text content
87
- return this.textContent || '';
88
- }
229
+ /**
230
+ * Improved HTML parser for innerHTML using a stack-based approach
231
+ */
232
+ private parseAndAppendHTML(html: string, targetNode: any = this): void {
233
+ const { ElementFactory, TextBase, Comment } = ElementBase.dependencies;
89
234
 
90
- set innerText(value: string | null) {
91
- // Clear all children and add escaped text content
92
- this._childNodesInternal = [];
93
- if (value !== null && value !== undefined) {
94
- const stringValue = String(value);
95
- const escapedValue = this.escapeHTMLEntities(stringValue);
96
- // Create text node with escaped content
97
- const { TextBase } = require('../TextBase');
98
- const textNode = new TextBase(escapedValue, this._ownerDocument);
99
- this._childNodesInternal.push(textNode);
100
- textNode._parentNodeInternal = this;
101
- }
235
+ if (!ElementFactory) {
236
+ // Fallback for direct library usage without entry point initialization
237
+ console.error('SWC DOM Parser: ElementFactory dependency not injected.');
238
+ return;
102
239
  }
103
240
 
104
- set innerHTML(value: string) {
105
- // Clear existing children
106
- while (this._childNodesInternal.length > 0) {
107
- const child = this._childNodesInternal[0];
108
- if (child) {
109
- this.removeChild(child);
110
- }
111
- }
112
-
113
- // Parse HTML and create child nodes
114
- if (value.trim()) {
115
- this.parseAndAppendHTML(value);
116
- }
117
- }
118
-
119
- /**
120
- * Generate HTML for a child element without using outerHTML to avoid circular dependency
121
- */
122
- private generateChildElementHTML(element: any): string {
123
- const tagName = element.tagName.toLowerCase();
124
-
125
- // Get attributes
126
- const attrs = Array.from(element._attributes?.entries() || [])
127
- .map(([name, value]: [string, string]) => value === '' ? ` ${name}` : ` ${name}="${value.replace(/"/g, '&quot;')}"`)
128
- .join('');
129
-
130
- // Check if it's a self-closing tag
131
- const selfClosingTags = ['img', 'input', 'br', 'hr', 'meta', 'link', 'area', 'base', 'col', 'embed', 'source', 'track', 'wbr'];
132
- const isSelfClosing = selfClosingTags.includes(tagName);
241
+ let i = 0;
242
+ const length = html.length;
133
243
 
134
- if (isSelfClosing) {
135
- return `<${tagName}${attrs} />`;
136
- } else {
137
- // Generate innerHTML directly without calling element.innerHTML to avoid recursion
138
- let childHTML = '';
139
- for (const child of element._childNodesInternal || []) {
140
- if (child.nodeType === TEXT_NODE) {
141
- childHTML += (child as any)._nodeValue || '';
142
- } else if (child.nodeType === ELEMENT_NODE) {
143
- childHTML += this.generateChildElementHTML(child as any);
144
- } else if (child.nodeType === 8) { // COMMENT_NODE
145
- childHTML += `<!--${(child as any).textContent || ''}-->`;
146
- }
147
- }
148
- return `<${tagName}${attrs}>${childHTML}</${tagName}>`;
149
- }
150
- }
244
+ while (i < length) {
245
+ const nextTagStart = html.indexOf('<', i);
151
246
 
152
- /**
153
- * Improved HTML parser for innerHTML using a stack-based approach
154
- */
155
- private parseAndAppendHTML(html: string): void {
156
- const ElementFactory = require('../../factory/ElementFactory').ElementFactory;
157
-
158
- let i = 0;
159
- const length = html.length;
160
-
161
- while (i < length) {
162
- const nextTagStart = html.indexOf('<', i);
163
-
164
- // Handle text content before next tag
165
- if (nextTagStart === -1) {
166
- // No more tags, rest is text
167
- let text = html.substring(i).trim();
168
- if (text) {
169
- // Fix broken closing tags (e.g., "/div>" -> "</div>")
170
- text = this.fixBrokenClosingTags(text);
171
- const { TextBase } = require('../TextBase');
172
- const textNode = new TextBase(text, this._ownerDocument);
173
- this.appendChild(textNode);
174
- }
175
- break;
176
- } else if (nextTagStart > i) {
177
- // Text content before the tag
178
- let text = html.substring(i, nextTagStart).trim();
179
- if (text) {
180
- // Fix broken closing tags (e.g., "/div>" -> "</div>")
181
- text = this.fixBrokenClosingTags(text);
182
- const { TextBase } = require('../TextBase');
183
- const textNode = new TextBase(text, this._ownerDocument);
184
- this.appendChild(textNode);
185
- }
186
- }
187
-
188
- i = nextTagStart;
189
-
190
- // Parse the tag - find the real tag end, considering quoted attributes
191
- const tagEnd = this.findTagEnd(html, i);
192
- if (tagEnd === -1) break;
193
-
194
- const tagContent = html.substring(i + 1, tagEnd);
195
-
196
- // Handle comments
197
- if (tagContent.startsWith('!--')) {
198
- const commentEnd = html.indexOf('-->', i);
199
- if (commentEnd !== -1) {
200
- const commentContent = html.substring(i + 4, commentEnd);
201
- const { Comment } = require('../Comment');
202
- const commentNode = new Comment(commentContent, this._ownerDocument);
203
- this.appendChild(commentNode);
204
- i = commentEnd + 3;
205
- continue;
206
- }
207
- }
208
-
209
- // Handle self-closing tags
210
- if (tagContent.endsWith('/')) {
211
- const parts = tagContent.slice(0, -1).trim().split(/\s+/);
212
- const tagName = parts[0];
213
- const attributeString = tagContent.slice(tagName.length, -1).trim();
214
-
215
- const element = ElementFactory.createElement(tagName, this._ownerDocument);
216
- this.parseAttributes(element, attributeString);
217
- this.appendChild(element);
218
- i = tagEnd + 1;
219
- continue;
220
- }
221
-
222
- // Handle closing tags - if they don't have matching opening tags, treat as text
223
- if (tagContent.startsWith('/')) {
224
- // For now, treat unmatched closing tags as text content
225
- const closingTagText = `<${tagContent}>`;
226
- const { TextBase } = require('../TextBase');
227
- const textNode = new TextBase(closingTagText, this._ownerDocument);
228
- this.appendChild(textNode);
229
- i = tagEnd + 1;
230
- continue;
231
- }
232
-
233
- // Handle opening tags
234
- const parts = tagContent.split(/\s+/);
235
- const tagName = parts[0];
236
- const attributeString = tagContent.slice(tagName.length).trim();
237
-
238
- // Special handling for style and script tags
239
- if (tagName === 'style' || tagName === 'script') {
240
- const closingTag = `</${tagName}>`;
241
- const closingTagIndex = html.indexOf(closingTag, tagEnd + 1);
242
-
243
- if (closingTagIndex !== -1) {
244
- const element = ElementFactory.createElement(tagName, this._ownerDocument);
245
- this.parseAttributes(element, attributeString);
246
-
247
- const content = html.substring(tagEnd + 1, closingTagIndex);
248
- if (content) {
249
- const { TextBase } = require('../TextBase');
250
- const textNode = new TextBase(content, this._ownerDocument);
251
- element.appendChild(textNode);
252
- }
253
-
254
- this.appendChild(element);
255
- i = closingTagIndex + closingTag.length;
256
- continue;
257
- }
258
- }
259
-
260
- // Handle regular opening tags with content
261
- const closingTag = `</${tagName}>`;
262
- const closingTagIndex = this.findMatchingClosingTag(html, tagName, tagEnd + 1);
263
-
264
- if (closingTagIndex !== -1) {
265
- const element = ElementFactory.createElement(tagName, this._ownerDocument);
266
- this.parseAttributes(element, attributeString);
267
-
268
- const content = html.substring(tagEnd + 1, closingTagIndex);
269
- if (content.trim()) {
270
- element.innerHTML = content;
271
- }
272
-
273
- this.appendChild(element);
274
- i = closingTagIndex + closingTag.length;
275
- } else {
276
- // No matching closing tag found, treat as self-closing
277
- const element = ElementFactory.createElement(tagName, this._ownerDocument);
278
- this.parseAttributes(element, attributeString);
279
- this.appendChild(element);
280
- i = tagEnd + 1;
281
- }
247
+ // Handle text content before next tag
248
+ if (nextTagStart === -1) {
249
+ let text = html.substring(i).trim();
250
+ if (text) {
251
+ text = this.fixBrokenClosingTags(text);
252
+ if (TextBase) targetNode.appendChild(new TextBase(text, this._ownerDocument));
282
253
  }
283
- }
284
-
285
- /**
286
- * Find the real end of a tag, considering quoted attributes
287
- */
288
- private findTagEnd(html: string, startIndex: number): number {
289
- let i = startIndex + 1; // Skip the '<'
290
- let inQuotes = false;
291
- let quoteChar = '';
292
-
293
- while (i < html.length) {
294
- const char = html[i];
295
-
296
- if (!inQuotes) {
297
- if (char === '"' || char === "'") {
298
- inQuotes = true;
299
- quoteChar = char;
300
- } else if (char === '>') {
301
- return i;
302
- }
303
- } else {
304
- if (char === quoteChar) {
305
- inQuotes = false;
306
- quoteChar = '';
307
- }
308
- }
309
-
310
- i++;
254
+ break;
255
+ } else if (nextTagStart > i) {
256
+ let text = html.substring(i, nextTagStart).trim();
257
+ if (text) {
258
+ text = this.fixBrokenClosingTags(text);
259
+ if (TextBase) targetNode.appendChild(new TextBase(text, this._ownerDocument));
311
260
  }
312
-
313
- return -1; // No closing '>' found
314
- }
315
-
316
- /**
317
- * Fix broken closing tags in text content
318
- * Converts patterns like "/div>" to "</div>"
319
- */
320
- private fixBrokenClosingTags(text: string): string {
321
- // Pattern to match broken closing tags: /tagname>
322
- return text.replace(/\/(\w+)>/g, '</$1>');
323
- }
324
-
325
- /**
326
- * Find the matching closing tag, accounting for nested tags of the same type
327
- */
328
- private findMatchingClosingTag(html: string, tagName: string, startIndex: number): number {
329
- const openTag = `<${tagName}`;
330
- const closeTag = `</${tagName}>`;
331
- let depth = 1;
332
- let i = startIndex;
333
-
334
- while (i < html.length && depth > 0) {
335
- const nextOpen = html.indexOf(openTag, i);
336
- const nextClose = html.indexOf(closeTag, i);
337
-
338
- if (nextClose === -1) {
339
- return -1; // No closing tag found
340
- }
341
-
342
- if (nextOpen !== -1 && nextOpen < nextClose) {
343
- // Found another opening tag before the closing tag
344
- // Make sure it's a complete tag (not just a substring)
345
- const afterTag = html.charAt(nextOpen + openTag.length);
346
- if (afterTag === ' ' || afterTag === '>' || afterTag === '/') {
347
- depth++;
348
- }
349
- i = nextOpen + openTag.length;
350
- } else {
351
- // Found a closing tag
352
- depth--;
353
- if (depth === 0) {
354
- return nextClose;
355
- }
356
- i = nextClose + closeTag.length;
357
- }
261
+ }
262
+
263
+ i = nextTagStart;
264
+ const tagEnd = this.findTagEnd(html, i);
265
+ if (tagEnd === -1) break;
266
+
267
+ const tagContent = html.substring(i + 1, tagEnd);
268
+
269
+ // Handle comments
270
+ if (tagContent.startsWith('!--')) {
271
+ const commentEnd = html.indexOf('-->', i);
272
+ if (commentEnd !== -1) {
273
+ const commentContent = html.substring(i + 4, commentEnd);
274
+ if (Comment) targetNode.appendChild(new Comment(commentContent, this._ownerDocument));
275
+ i = commentEnd + 3;
276
+ continue;
358
277
  }
359
-
360
- return -1;
361
- }
362
-
363
- /**
364
- * Parse attributes from attribute string
365
- */
366
- private parseAttributes(element: any, attributeString: string): void {
367
- // Improved attribute parsing that handles complex JavaScript expressions
368
- let position = 0;
369
- const length = attributeString.length;
370
-
371
- while (position < length) {
372
- // Skip whitespace
373
- while (position < length && /\s/.test(attributeString[position])) {
374
- position++;
375
- }
376
-
377
- if (position >= length) break;
378
-
379
- // Find attribute name
380
- const nameStart = position;
381
- while (position < length && /[\w:-]/.test(attributeString[position])) {
382
- position++;
383
- }
384
-
385
- if (position === nameStart) {
386
- // Invalid character, skip it
387
- position++;
388
- continue;
389
- }
390
-
391
- const name = attributeString.substring(nameStart, position);
392
-
393
- // Skip whitespace
394
- while (position < length && /\s/.test(attributeString[position])) {
395
- position++;
396
- }
397
-
398
- let value = '';
399
-
400
- // Check if there's an equals sign
401
- if (position < length && attributeString[position] === '=') {
402
- position++; // Skip '='
403
-
404
- // Skip whitespace
405
- while (position < length && /\s/.test(attributeString[position])) {
406
- position++;
407
- }
408
-
409
- if (position < length) {
410
- const quote = attributeString[position];
411
-
412
- if (quote === '"' || quote === "'") {
413
- // Quoted value - find matching closing quote
414
- position++; // Skip opening quote
415
- const valueStart = position;
416
-
417
- while (position < length && attributeString[position] !== quote) {
418
- position++;
419
- }
420
-
421
- value = attributeString.substring(valueStart, position);
422
-
423
- if (position < length && attributeString[position] === quote) {
424
- position++; // Skip closing quote
425
- }
426
- } else {
427
- // Unquoted value - read until whitespace or end
428
- const valueStart = position;
429
- while (position < length && !/\s/.test(attributeString[position])) {
430
- position++;
431
- }
432
- value = attributeString.substring(valueStart, position);
433
- }
434
- }
435
- }
436
-
437
- // Decode HTML entities in attribute values
438
- value = this.decodeHTMLEntities(value);
439
-
440
- element.setAttribute(name, value);
278
+ }
279
+
280
+ // Handle self-closing tags
281
+ if (tagContent.endsWith('/')) {
282
+ const parts = tagContent.slice(0, -1).trim().split(/\s+/);
283
+ const tagName = parts[0];
284
+ const attributeString = tagContent.slice(tagName.length, -1).trim();
285
+ const element = ElementFactory.createElement(tagName, this._ownerDocument);
286
+ this.parseAttributes(element, attributeString);
287
+ targetNode.appendChild(element);
288
+ i = tagEnd + 1;
289
+ continue;
290
+ }
291
+
292
+ // Handle closing tags
293
+ if (tagContent.startsWith('/')) {
294
+ const closingTagText = `<${tagContent}>`;
295
+ if (TextBase) targetNode.appendChild(new TextBase(closingTagText, this._ownerDocument));
296
+ i = tagEnd + 1;
297
+ continue;
298
+ }
299
+
300
+ // Handle opening tags
301
+ const parts = tagContent.split(/\s+/);
302
+ const tagName = parts[0];
303
+ const attributeString = tagContent.slice(tagName.length).trim();
304
+
305
+ // Special handling for style and script tags
306
+ if (tagName === 'style' || tagName === 'script') {
307
+ const closingTag = `</${tagName}>`;
308
+ const closingTagIndex = html.indexOf(closingTag, tagEnd + 1);
309
+
310
+ if (closingTagIndex !== -1) {
311
+ const element = ElementFactory.createElement(tagName, this._ownerDocument);
312
+ this.parseAttributes(element, attributeString);
313
+ const content = html.substring(tagEnd + 1, closingTagIndex);
314
+ if (content && TextBase) {
315
+ element.appendChild(new TextBase(content, this._ownerDocument));
316
+ }
317
+ targetNode.appendChild(element);
318
+ i = closingTagIndex + closingTag.length;
319
+ continue;
441
320
  }
442
- }
443
-
444
- /**
445
- * Escape HTML entities in a string to prevent XSS
446
- */
447
- protected escapeHTMLEntities(str: string): string {
448
- const entityMap: { [key: string]: string } = {
449
- '&': '&amp;',
450
- '<': '&lt;',
451
- '>': '&gt;',
452
- '"': '&quot;',
453
- "'": '&#39;'
454
- };
455
-
456
- return str.replace(/[&<>"']/g, (char) => {
457
- return entityMap[char] || char;
458
- });
459
- }
460
-
461
- /**
462
- * Decode HTML entities in a string
463
- */
464
- protected decodeHTMLEntities(str: string): string {
465
- const entityMap: { [key: string]: string } = {
466
- '&amp;': '&',
467
- '&lt;': '<',
468
- '&gt;': '>',
469
- '&quot;': '"',
470
- '&#39;': "'",
471
- '&#34;': '"',
472
- '&apos;': "'",
473
- '&copy;': '©',
474
- '&reg;': '®',
475
- '&trade;': '™',
476
- '&nbsp;': ' ',
477
- '&hellip;': '…',
478
- '&mdash;': '—',
479
- '&ndash;': '–',
480
- '&lsquo;': '\u2018',
481
- '&rsquo;': '\u2019',
482
- '&ldquo;': '"',
483
- '&rdquo;': '"'
484
- };
485
-
486
- return str.replace(/&[a-zA-Z0-9#]+;/g, (entity) => {
487
- // Handle named entities
488
- if (entityMap[entity]) {
489
- return entityMap[entity];
490
- }
491
-
492
- // Handle numeric entities like &#39; &#34;
493
- if (entity.startsWith('&#') && entity.endsWith(';')) {
494
- const numStr = entity.slice(2, -1);
495
- const num = parseInt(numStr, 10);
496
- if (!isNaN(num)) {
497
- return String.fromCharCode(num);
498
- }
499
- }
500
-
501
- // Handle hex entities like &#x27;
502
- if (entity.startsWith('&#x') && entity.endsWith(';')) {
503
- const hexStr = entity.slice(3, -1);
504
- const num = parseInt(hexStr, 16);
505
- if (!isNaN(num)) {
506
- return String.fromCharCode(num);
507
- }
508
- }
509
-
510
- // Return original if not recognized
511
- return entity;
512
- });
513
- }
514
-
515
- get outerHTML(): string {
516
- const attrs = Array.from(this._attributes.entries())
517
- .map(([name, value]) => value === '' ? ` ${name}` : ` ${name}="${value.replace(/"/g, '&quot;')}"`)
518
- .join('');
321
+ }
519
322
 
520
- // Check if it's a self-closing tag
521
- const selfClosingTags = ['img', 'input', 'br', 'hr', 'meta', 'link', 'area', 'base', 'col', 'embed', 'source', 'track', 'wbr'];
522
- const isSelfClosing = selfClosingTags.includes(this.tagName.toLowerCase());
323
+ // Handle regular opening tags with content
324
+ const closingTagIndex = this.findMatchingClosingTag(html, tagName, tagEnd + 1);
523
325
 
524
- if (isSelfClosing) {
525
- return `<${this.tagName.toLowerCase()}${attrs} />`;
526
- } else {
527
- return `<${this.tagName.toLowerCase()}${attrs}>${this.innerHTML}</${this.tagName.toLowerCase()}>`;
326
+ if (closingTagIndex !== -1) {
327
+ const element = ElementFactory.createElement(tagName, this._ownerDocument);
328
+ this.parseAttributes(element, attributeString);
329
+ const content = html.substring(tagEnd + 1, closingTagIndex);
330
+ if (content.trim()) {
331
+ element.innerHTML = content;
528
332
  }
529
- }
530
-
531
- get namespaceURI(): string | null {
532
- return 'http://www.w3.org/1999/xhtml';
533
- }
534
-
535
- get prefix(): string | null {
536
- return null;
537
- }
538
-
539
- // Attribute methods
540
- getAttribute(qualifiedName: string): string | null {
541
- const value = this._attributes.get(qualifiedName.toLowerCase());
542
- return value !== undefined ? value : null;
543
- }
544
-
545
- setAttribute(qualifiedName: string, value: string): void {
546
- const name = qualifiedName.toLowerCase();
547
- this._attributes.set(name, value);
548
-
549
- // Update special properties
550
- if (name === 'id') {
551
- this._id = value;
552
- } else if (name === 'class') {
553
- this._className = value;
333
+ targetNode.appendChild(element);
334
+ i = closingTagIndex + (tagName.length + 3); // </tagName>
335
+ } else {
336
+ const element = ElementFactory.createElement(tagName, this._ownerDocument);
337
+ this.parseAttributes(element, attributeString);
338
+ targetNode.appendChild(element);
339
+ i = tagEnd + 1;
340
+ }
341
+ }
342
+ }
343
+
344
+ private findTagEnd(html: string, startIndex: number): number {
345
+ let i = startIndex + 1;
346
+ let inQuotes = false;
347
+ let quoteChar = '';
348
+ while (i < html.length) {
349
+ const char = html[i];
350
+ if (!inQuotes) {
351
+ if (char === '"' || char === "'") {
352
+ inQuotes = true;
353
+ quoteChar = char;
354
+ } else if (char === '>') return i;
355
+ } else {
356
+ if (char === quoteChar) {
357
+ inQuotes = false;
358
+ quoteChar = '';
554
359
  }
555
- }
556
-
557
- removeAttribute(qualifiedName: string): void {
558
- const name = qualifiedName.toLowerCase();
559
- this._attributes.delete(name);
560
-
561
- // Update special properties
562
- if (name === 'id') {
563
- this._id = '';
564
- } else if (name === 'class') {
565
- this._className = '';
360
+ }
361
+ i++;
362
+ }
363
+ return -1;
364
+ }
365
+
366
+ private fixBrokenClosingTags(text: string): string {
367
+ return text.replace(/\/(\w+)>/g, '</$1>');
368
+ }
369
+
370
+ private findMatchingClosingTag(html: string, tagName: string, startIndex: number): number {
371
+ const openTag = `<${tagName}`;
372
+ const closeTag = `</${tagName}>`;
373
+ let depth = 1;
374
+ let i = startIndex;
375
+ while (i < html.length && depth > 0) {
376
+ const nextOpen = html.indexOf(openTag, i);
377
+ const nextClose = html.indexOf(closeTag, i);
378
+ if (nextClose === -1) return -1;
379
+ if (nextOpen !== -1 && nextOpen < nextClose) {
380
+ const afterTag = html.charAt(nextOpen + openTag.length);
381
+ if (afterTag === ' ' || afterTag === '>' || afterTag === '/') depth++;
382
+ i = nextOpen + openTag.length;
383
+ } else {
384
+ depth--;
385
+ if (depth === 0) return nextClose;
386
+ i = nextClose + closeTag.length;
387
+ }
388
+ }
389
+ return -1;
390
+ }
391
+
392
+ private parseAttributes(element: any, attributeString: string): void {
393
+ let position = 0;
394
+ const length = attributeString.length;
395
+ while (position < length) {
396
+ while (position < length && /\s/.test(attributeString[position])) position++;
397
+ if (position >= length) break;
398
+ const nameStart = position;
399
+ while (position < length && /[\w:-]/.test(attributeString[position])) position++;
400
+ if (position === nameStart) {
401
+ position++;
402
+ continue;
403
+ }
404
+ const name = attributeString.substring(nameStart, position);
405
+ while (position < length && /\s/.test(attributeString[position])) position++;
406
+ let value = '';
407
+ if (position < length && attributeString[position] === '=') {
408
+ position++;
409
+ while (position < length && /\s/.test(attributeString[position])) position++;
410
+ if (position < length) {
411
+ const quote = attributeString[position];
412
+ if (quote === '"' || quote === "'") {
413
+ position++;
414
+ const valueStart = position;
415
+ while (position < length && attributeString[position] !== quote) position++;
416
+ value = attributeString.substring(valueStart, position);
417
+ if (position < length && attributeString[position] === quote) position++;
418
+ } else {
419
+ const valueStart = position;
420
+ while (position < length && !/\s/.test(attributeString[position])) position++;
421
+ value = attributeString.substring(valueStart, position);
422
+ }
566
423
  }
567
- }
568
-
569
- hasAttribute(qualifiedName: string): boolean {
570
- return this._attributes.has(qualifiedName.toLowerCase());
571
- }
572
-
573
- /**
574
- * Returns the closest ancestor element (including the element itself) that matches the specified CSS selector.
575
- *
576
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/closest)
577
- */
578
- closest<K extends keyof HTMLElementTagNameMap>(selector: K): HTMLElementTagNameMap[K] | null;
579
- closest<K extends keyof SVGElementTagNameMap>(selector: K): SVGElementTagNameMap[K] | null;
580
- closest<K extends keyof MathMLElementTagNameMap>(selector: K): MathMLElementTagNameMap[K] | null;
581
- closest<E extends Element = Element>(selectors: string): E | null;
582
- closest(selectors: string): Element | null {
583
- let element: Element | null = this as any;
584
-
585
- while (element) {
586
- if (element.matches && element.matches(selectors)) {
587
- return element;
588
- }
589
- element = element.parentElement;
424
+ }
425
+ element.setAttribute(name, this.decodeHTMLEntities(value));
426
+ }
427
+ }
428
+
429
+ protected escapeHTMLEntities(str: string): string {
430
+ const entityMap: any = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
431
+ return str.replace(/[&<>"']/g, char => entityMap[char] || char);
432
+ }
433
+
434
+ protected decodeHTMLEntities(str: string): string {
435
+ const entityMap: any = { '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"', '&#39;': "'", '&#34;': '"', '&apos;': "'", '&copy;': '©', '&reg;': '®', '&trade;': '™', '&nbsp;': ' ', '&hellip;': '…', '&mdash;': '—', '&ndash;': '–', '&lsquo;': '\u2018', '&rsquo;': '\u2019', '&ldquo;': '"', '&rdquo;': '"' };
436
+ return str.replace(/&[a-zA-Z0-9#]+;/g, entity => {
437
+ if (entityMap[entity]) return entityMap[entity];
438
+ if (entity.startsWith('&#') && entity.endsWith(';')) {
439
+ const num = parseInt(entity.slice(2, -1), 10);
440
+ return isNaN(num) ? entity : String.fromCharCode(num);
441
+ }
442
+ if (entity.startsWith('&#x') && entity.endsWith(';')) {
443
+ const num = parseInt(entity.slice(3, -1), 16);
444
+ return isNaN(num) ? entity : String.fromCharCode(num);
445
+ }
446
+ return entity;
447
+ });
448
+ }
449
+
450
+ get outerHTML(): string {
451
+ const attrs = Array.from(this._attributes.entries())
452
+ .map(([name, value]) => (value === '' ? ` ${name}` : ` ${name}="${value.replace(/"/g, '&quot;')}"`))
453
+ .join('');
454
+ const selfClosingTags = ['img', 'input', 'br', 'hr', 'meta', 'link', 'area', 'base', 'col', 'embed', 'source', 'track', 'wbr'];
455
+ const isSelfClosing = selfClosingTags.includes(this.tagName.toLowerCase());
456
+ return isSelfClosing ? `<${this.tagName.toLowerCase()}${attrs} />` : `<${this.tagName.toLowerCase()}${attrs}>${this.innerHTML}</${this.tagName.toLowerCase()}>`;
457
+ }
458
+
459
+ get namespaceURI(): string | null {
460
+ return 'http://www.w3.org/1999/xhtml';
461
+ }
462
+ get prefix(): string | null {
463
+ return null;
464
+ }
465
+ getAttribute(qualifiedName: string): string | null {
466
+ return this._attributes.get(qualifiedName.toLowerCase()) ?? null;
467
+ }
468
+ setAttribute(qualifiedName: string, value: string): void {
469
+ const name = qualifiedName.toLowerCase();
470
+ this._attributes.set(name, value);
471
+ if (name === 'id') this._id = value;
472
+ else if (name === 'class') this._className = value;
473
+ }
474
+ removeAttribute(qualifiedName: string): void {
475
+ const name = qualifiedName.toLowerCase();
476
+ this._attributes.delete(name);
477
+ if (name === 'id') this._id = '';
478
+ else if (name === 'class') this._className = '';
479
+ }
480
+ hasAttribute(qualifiedName: string): boolean {
481
+ return this._attributes.has(qualifiedName.toLowerCase());
482
+ }
483
+ closest(selectors: string): any {
484
+ let element: Element | null = this as any;
485
+ while (element) {
486
+ if (element.matches && element.matches(selectors)) return element;
487
+ element = element.parentElement;
488
+ }
489
+ return null;
490
+ }
491
+ matches(selectors: string): boolean {
492
+ return CSSSelector.matches(this as any, selectors);
493
+ }
494
+ get attributes(): any {
495
+ return new (NamedNodeMapImpl as any)(this._attributes);
496
+ }
497
+ get clientHeight(): number {
498
+ return 0;
499
+ }
500
+ get clientLeft(): number {
501
+ return 0;
502
+ }
503
+ get clientTop(): number {
504
+ return 0;
505
+ }
506
+ get clientWidth(): number {
507
+ return 0;
508
+ }
509
+ get currentCSSZoom(): number {
510
+ return 1;
511
+ }
512
+ onfullscreenchange: any = null;
513
+ onfullscreenerror: any = null;
514
+ get part(): any {
515
+ return { length: 0, value: '', add: () => {}, remove: () => {}, contains: () => false, toggle: () => false, replace: () => false, item: () => null };
516
+ }
517
+ get scrollHeight(): number {
518
+ return 0;
519
+ }
520
+ get scrollLeft(): number {
521
+ return 0;
522
+ }
523
+ set scrollLeft(_: number) {}
524
+ get scrollTop(): number {
525
+ return 0;
526
+ }
527
+ set scrollTop(_: number) {}
528
+ get scrollWidth(): number {
529
+ return 0;
530
+ }
531
+ get shadowRoot(): ShadowRoot | null {
532
+ return this._shadowRoot;
533
+ }
534
+ get slot(): string {
535
+ return this.getAttribute('slot') || '';
536
+ }
537
+ set slot(value: string) {
538
+ this.setAttribute('slot', value);
539
+ }
540
+ attachShadow(init: ShadowRootInit): ShadowRoot {
541
+ if (this._shadowRoot) throw new DOMException('Shadow root already attached', 'NotSupportedError');
542
+ this._shadowRoot = new ShadowRootBase(this as any, init, this._ownerDocument) as unknown as ShadowRoot;
543
+ return this._shadowRoot;
544
+ }
545
+ checkVisibility(_options?: any): boolean {
546
+ return true;
547
+ }
548
+ computedStyleMap(): any {
549
+ return new Map();
550
+ }
551
+ getAttributeNS(_ns: string | null, localName: string): string | null {
552
+ return this.getAttribute(localName);
553
+ }
554
+ getAttributeNames(): string[] {
555
+ return Array.from(this._attributes.keys());
556
+ }
557
+ getAttributeNode(qualifiedName: string): any {
558
+ const value = this.getAttribute(qualifiedName);
559
+ return value !== null ? new AttrImpl(qualifiedName, value) : null;
560
+ }
561
+ getAttributeNodeNS(_ns: string | null, localName: string): any {
562
+ return this.getAttributeNode(localName);
563
+ }
564
+ getBoundingClientRect(): any {
565
+ return { bottom: 0, height: 0, left: 0, right: 0, top: 0, width: 0, x: 0, y: 0, toJSON: () => ({}) };
566
+ }
567
+ getClientRects(): any {
568
+ return { length: 0, item: () => null, [Symbol.iterator]: function* () {} };
569
+ }
570
+
571
+ getElementsByClassName(classNames: string): HTMLCollectionOf<Element> {
572
+ const result: Element[] = [];
573
+ const classNameList = classNames.trim().split(/\s+/);
574
+ const hasAllClasses = (element: Element, classes: string[]): boolean => {
575
+ const elementClasses = element.className.trim().split(/\s+/);
576
+ return classes.every(cls => elementClasses.includes(cls));
577
+ };
578
+ const traverse = (node: any) => {
579
+ if (node.nodeType === ELEMENT_NODE && hasAllClasses(node as Element, classNameList)) result.push(node as Element);
580
+ for (let i = 0; i < node.childNodes.length; i++) traverse(node.childNodes[i]);
581
+ };
582
+ for (let i = 0; i < this.childNodes.length; i++) traverse(this.childNodes[i]);
583
+ // @ts-ignore
584
+ return new HTMLCollectionOfImp(result);
585
+ }
586
+
587
+ getElementsByTagName(qualifiedName: string): HTMLCollection {
588
+ const result: Element[] = [];
589
+ const tagName = qualifiedName.toLowerCase();
590
+ const isWildcard = tagName === '*';
591
+ const traverse = (node: any) => {
592
+ if (node.nodeType === ELEMENT_NODE && (isWildcard || node.localName === tagName)) result.push(node as Element);
593
+ for (let i = 0; i < node.childNodes.length; i++) traverse(node.childNodes[i]);
594
+ };
595
+ for (let i = 0; i < this.childNodes.length; i++) traverse(this.childNodes[i]);
596
+ // @ts-ignore
597
+ return new HTMLCollectionImp(result);
598
+ }
599
+ getElementsByTagNameNS(_ns: string | null, localName: string): any {
600
+ return this.getElementsByTagName(localName);
601
+ }
602
+ getHTML(_options?: any): string {
603
+ return this.outerHTML;
604
+ }
605
+ hasAttributeNS(_ns: string | null, localName: string): boolean {
606
+ return this.hasAttribute(localName);
607
+ }
608
+ hasAttributes(): boolean {
609
+ return this._attributes.size > 0;
610
+ }
611
+ hasPointerCapture(_id: number): boolean {
612
+ return false;
613
+ }
614
+ insertAdjacentElement(where: InsertPosition, element: Element): Element | null {
615
+ const position = where.toLowerCase();
616
+ switch (position) {
617
+ case 'beforebegin':
618
+ if (this.parentNode) {
619
+ this.parentNode.insertBefore(element as any, this as any);
620
+ return element;
590
621
  }
591
-
592
622
  return null;
593
- }
594
-
595
- /**
596
- * Returns true if the element would be selected by the specified CSS selector; otherwise, returns false.
597
- *
598
- * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/matches)
599
- */
600
- matches(selectors: string): boolean {
601
- return CSSSelector.matches(this as any, selectors);
602
- }
603
-
604
- // ChildNode methods are inherited from ParentNodeBase -> ChildNodeBase
605
-
606
- // Additional Element properties and methods - Not implemented yet
607
-
608
- get attributes(): NamedNodeMap {
609
- return new NamedNodeMapImpl(this._attributes);
610
- }
611
-
612
- get clientHeight(): number {
613
- throw new Error('Element.clientHeight is not implemented yet');
614
- }
615
-
616
- get clientLeft(): number {
617
- throw new Error('Element.clientLeft is not implemented yet');
618
- }
619
-
620
- get clientTop(): number {
621
- throw new Error('Element.clientTop is not implemented yet');
622
- }
623
-
624
- get clientWidth(): number {
625
- throw new Error('Element.clientWidth is not implemented yet');
626
- }
627
-
628
- get currentCSSZoom(): number {
629
- throw new Error('Element.currentCSSZoom is not implemented yet');
630
- }
631
-
632
- onfullscreenchange: ((this: Element, ev: Event) => any) | null = null;
633
- onfullscreenerror: ((this: Element, ev: Event) => any) | null = null;
634
-
635
- get part(): any {
636
- throw new Error('Element.part is not implemented yet');
637
- }
638
-
639
- get scrollHeight(): number {
640
- throw new Error('Element.scrollHeight is not implemented yet');
641
- }
642
-
643
- get scrollLeft(): number {
644
- throw new Error('Element.scrollLeft is not implemented yet');
645
- }
646
-
647
- set scrollLeft(value: number) {
648
- throw new Error('Element.scrollLeft setter is not implemented yet');
649
- }
650
-
651
- get scrollTop(): number {
652
- throw new Error('Element.scrollTop is not implemented yet');
653
- }
654
-
655
- set scrollTop(value: number) {
656
- throw new Error('Element.scrollTop setter is not implemented yet');
657
- }
658
-
659
- get scrollWidth(): number {
660
- throw new Error('Element.scrollWidth is not implemented yet');
661
- }
662
-
663
- get shadowRoot(): any {
664
- throw new Error('Element.shadowRoot is not implemented yet');
665
- }
666
-
667
- get slot(): string {
668
- throw new Error('Element.slot is not implemented yet');
669
- }
670
-
671
- set slot(value: string) {
672
- throw new Error('Element.slot setter is not implemented yet');
673
- }
674
-
675
- // Methods - Not implemented yet
676
-
677
- attachShadow(init: any): any {
678
- throw new Error('Element.attachShadow() is not implemented yet');
679
- }
680
-
681
- checkVisibility(options?: any): boolean {
682
- throw new Error('Element.checkVisibility() is not implemented yet');
683
- }
684
-
685
- computedStyleMap(): any {
686
- throw new Error('Element.computedStyleMap() is not implemented yet');
687
- }
688
-
689
- getAttributeNS(namespace: string | null, localName: string): string | null {
690
- // For simplicity, we'll ignore namespace and use localName
691
- return this.getAttribute(localName);
692
- }
693
-
694
- getAttributeNames(): string[] {
695
- return Array.from(this._attributes.keys());
696
- }
697
-
698
- getAttributeNode(qualifiedName: string): Attr | null {
699
- const value = this.getAttribute(qualifiedName);
700
- if (value !== null) {
701
- return new AttrImpl(qualifiedName, value);
623
+ case 'afterbegin':
624
+ if (this.firstChild) this.insertBefore(element as any, this.firstChild);
625
+ else this.appendChild(element as any);
626
+ return element;
627
+ case 'beforeend':
628
+ this.appendChild(element as any);
629
+ return element;
630
+ case 'afterend':
631
+ if (this.parentNode) {
632
+ if (this.nextSibling) this.parentNode.insertBefore(element as any, this.nextSibling);
633
+ else this.parentNode.appendChild(element as any);
634
+ return element;
702
635
  }
703
636
  return null;
704
- }
705
-
706
- getAttributeNodeNS(namespace: string | null, localName: string): Attr | null {
707
- // For simplicity, we'll ignore namespace and use localName
708
- return this.getAttributeNode(localName);
709
- }
710
-
711
- getBoundingClientRect(): any {
712
- throw new Error('Element.getBoundingClientRect() is not implemented yet');
713
- }
714
-
715
- getClientRects(): any {
716
- throw new Error('Element.getClientRects() is not implemented yet');
717
- }
718
-
719
- getElementsByClassName(classNames: string): HTMLCollection {
720
- const result: Element[] = [];
721
- const classNameList = classNames.trim().split(/\s+/);
722
-
723
- // Helper function to check if element has all specified classes
724
- const hasAllClasses = (element: Element, classes: string[]): boolean => {
725
- const elementClasses = element.className.trim().split(/\s+/);
726
- return classes.every(cls => elementClasses.includes(cls));
727
- };
728
-
729
- // Recursive function to traverse all descendants
730
- const traverse = (node: any) => {
731
- if (node.nodeType === ELEMENT_NODE) {
732
- const element = node as Element;
733
- if (hasAllClasses(element, classNameList)) {
734
- result.push(element);
735
- }
736
- }
737
-
738
- // Traverse children
739
- for (let i = 0; i < node.childNodes.length; i++) {
740
- traverse(node.childNodes[i]);
741
- }
742
- };
743
-
744
- // Start traversal from this element's children
745
- for (let i = 0; i < this.childNodes.length; i++) {
746
- traverse(this.childNodes[i]);
747
- }
748
-
749
- return new HTMLCollection(result);
750
- }
751
-
752
- getElementsByTagName(qualifiedName: string): HTMLCollection {
753
- const result: Element[] = [];
754
- const tagName = qualifiedName.toLowerCase();
755
- const isWildcard = tagName === '*';
756
-
757
- // Recursive function to traverse all descendants
758
- const traverse = (node: any) => {
759
- if (node.nodeType === ELEMENT_NODE) {
760
- const element = node as Element;
761
- if (isWildcard || element.localName === tagName) {
762
- result.push(element);
763
- }
764
- }
765
-
766
- // Traverse children
767
- for (let i = 0; i < node.childNodes.length; i++) {
768
- traverse(node.childNodes[i]);
769
- }
770
- };
771
-
772
- // Start traversal from this element's children
773
- for (let i = 0; i < this.childNodes.length; i++) {
774
- traverse(this.childNodes[i]);
775
- }
776
-
777
- return new HTMLCollection(result);
778
- }
779
-
780
- getElementsByTagNameNS(namespace: string | null, localName: string): any {
781
- // For simplicity, we'll implement this similar to getElementsByTagName
782
- // In a full implementation, namespace handling would be more complex
783
- return this.getElementsByTagName(localName);
784
- }
785
-
786
- getHTML(options?: any): string {
787
- throw new Error('Element.getHTML() is not implemented yet');
788
- }
789
-
790
- hasAttributeNS(namespace: string | null, localName: string): boolean {
791
- // For simplicity, we'll ignore namespace and use localName
792
- return this.hasAttribute(localName);
793
- }
794
-
795
- hasAttributes(): boolean {
796
- return this._attributes.size > 0;
797
- }
798
-
799
- hasPointerCapture(pointerId: number): boolean {
800
- throw new Error('Element.hasPointerCapture() is not implemented yet');
801
- }
802
-
803
- insertAdjacentElement(where: InsertPosition, element: Element): Element | null {
804
- const position = where.toLowerCase();
805
-
806
- switch (position) {
807
- case 'beforebegin':
808
- // Insert before this element
809
- if (this.parentNode) {
810
- this.parentNode.insertBefore(element as any, this as any);
811
- return element;
812
- }
813
- return null;
814
-
815
- case 'afterbegin':
816
- // Insert as first child of this element
817
- if (this.firstChild) {
818
- this.insertBefore(element as any, this.firstChild);
819
- } else {
820
- this.appendChild(element as any);
821
- }
822
- return element;
823
-
824
- case 'beforeend':
825
- // Insert as last child of this element
826
- this.appendChild(element as any);
827
- return element;
828
-
829
- case 'afterend':
830
- // Insert after this element
831
- if (this.parentNode) {
832
- if (this.nextSibling) {
833
- this.parentNode.insertBefore(element as any, this.nextSibling);
834
- } else {
835
- this.parentNode.appendChild(element as any);
836
- }
837
- return element;
838
- }
839
- return null;
840
-
841
- default:
842
- throw new DOMException(`Invalid position: ${where}`, 'SyntaxError');
843
- }
844
- }
845
-
846
- insertAdjacentHTML(position: InsertPosition, html: string): void {
847
- const pos = position.toLowerCase();
848
-
849
- // Parse HTML string into elements
850
- const tempDiv = this._ownerDocument.createElement('div');
851
- tempDiv.innerHTML = html;
852
-
853
- // Move all parsed nodes to the target position
854
- const fragment = this._ownerDocument.createDocumentFragment();
855
- while (tempDiv.firstChild) {
856
- fragment.appendChild(tempDiv.firstChild);
857
- }
858
-
859
- switch (pos) {
860
- case 'beforebegin':
861
- if (this.parentNode) {
862
- this.parentNode.insertBefore(fragment, this as any);
863
- }
864
- break;
865
-
866
- case 'afterbegin':
867
- if (this.firstChild) {
868
- this.insertBefore(fragment, this.firstChild);
869
- } else {
870
- this.appendChild(fragment);
871
- }
872
- break;
873
-
874
- case 'beforeend':
875
- this.appendChild(fragment);
876
- break;
877
-
878
- case 'afterend':
879
- if (this.parentNode) {
880
- if (this.nextSibling) {
881
- this.parentNode.insertBefore(fragment, this.nextSibling);
882
- } else {
883
- this.parentNode.appendChild(fragment);
884
- }
885
- }
886
- break;
887
-
888
- default:
889
- throw new DOMException(`Invalid position: ${position}`, 'SyntaxError');
890
- }
891
- }
892
-
893
- insertAdjacentText(where: InsertPosition, data: string): void {
894
- const position = where.toLowerCase();
895
-
896
- // Create text node
897
- const textNode = this._ownerDocument.createTextNode(data);
898
-
899
- switch (position) {
900
- case 'beforebegin':
901
- if (this.parentNode) {
902
- this.parentNode.insertBefore(textNode, this as any);
903
- }
904
- break;
905
-
906
- case 'afterbegin':
907
- if (this.firstChild) {
908
- this.insertBefore(textNode, this.firstChild);
909
- } else {
910
- this.appendChild(textNode);
911
- }
912
- break;
913
-
914
- case 'beforeend':
915
- this.appendChild(textNode);
916
- break;
917
-
918
- case 'afterend':
919
- if (this.parentNode) {
920
- if (this.nextSibling) {
921
- this.parentNode.insertBefore(textNode, this.nextSibling);
922
- } else {
923
- this.parentNode.appendChild(textNode);
924
- }
925
- }
926
- break;
927
-
928
- default:
929
- throw new DOMException(`Invalid position: ${where}`, 'SyntaxError');
930
- }
931
- }
932
-
933
- releasePointerCapture(pointerId: number): void {
934
- // throw new Error('Element.releasePointerCapture() is not implemented yet');
935
- }
936
-
937
- removeAttributeNS(namespace: string | null, localName: string): void {
938
- // For simplicity, we'll ignore namespace and use localName
939
- this.removeAttribute(localName);
940
- }
941
-
942
- removeAttributeNode(attr: Attr): Attr {
943
- const oldValue = this.getAttribute(attr.name);
944
- if (oldValue !== null) {
945
- this.removeAttribute(attr.name);
946
- return new AttrImpl(attr.name, oldValue);
637
+ default:
638
+ throw new DOMException(`Invalid position: ${where}`, 'SyntaxError');
639
+ }
640
+ }
641
+ insertAdjacentHTML(position: InsertPosition, html: string): void {
642
+ const pos = position.toLowerCase();
643
+ const tempDiv = this._ownerDocument.createElement('div');
644
+ tempDiv.innerHTML = html;
645
+ const fragment = this._ownerDocument.createDocumentFragment();
646
+ while (tempDiv.firstChild) fragment.appendChild(tempDiv.firstChild);
647
+ switch (pos) {
648
+ case 'beforebegin':
649
+ if (this.parentNode) this.parentNode.insertBefore(fragment, this as any);
650
+ break;
651
+ case 'afterbegin':
652
+ if (this.firstChild) this.insertBefore(fragment, this.firstChild);
653
+ else this.appendChild(fragment);
654
+ break;
655
+ case 'beforeend':
656
+ this.appendChild(fragment);
657
+ break;
658
+ case 'afterend':
659
+ if (this.parentNode) {
660
+ if (this.nextSibling) this.parentNode.insertBefore(fragment, this.nextSibling);
661
+ else this.parentNode.appendChild(fragment);
947
662
  }
948
- throw new DOMException('The attribute node is not an attribute of this element', 'NotFoundError');
949
- }
950
-
951
- requestFullscreen(options?: any): Promise<void> {
952
- throw new Error('Element.requestFullscreen() is not implemented yet');
953
- }
954
-
955
- requestPointerLock(options?: any): Promise<void> {
956
- throw new Error('Element.requestPointerLock() is not implemented yet');
957
- }
958
-
959
- scroll(options?: any): void;
960
- scroll(x: number, y: number): void;
961
- scroll(optionsOrX?: any, y?: number): void {
962
- // throw new Error('Element.scroll() is not implemented yet');
963
- }
964
-
965
- scrollBy(options?: any): void;
966
- scrollBy(x: number, y: number): void;
967
- scrollBy(optionsOrX?: any, y?: number): void {
968
- // throw new Error('Element.scrollBy() is not implemented yet');
969
- }
970
-
971
- scrollIntoView(arg?: boolean | any): void {
972
- // throw new Error('Element.scrollIntoView() is not implemented yet');
973
- }
974
-
975
- scrollTo(options?: any): void;
976
- scrollTo(x: number, y: number): void;
977
- scrollTo(optionsOrX?: any, y?: number): void {
978
- // throw new Error('Element.scrollTo() is not implemented yet');
979
- }
980
-
981
- setAttributeNS(namespace: string | null, qualifiedName: string, value: string): void {
982
- // For simplicity, we'll ignore namespace and use qualifiedName
983
- this.setAttribute(qualifiedName, value);
984
- }
985
-
986
- setAttributeNode(attr: Attr): Attr | null {
987
- const oldAttr = this.getAttributeNode(attr.name);
988
- this.setAttribute(attr.name, attr.value);
989
- return oldAttr;
990
- }
991
-
992
- setAttributeNodeNS(attr: Attr): Attr | null {
993
- // For simplicity, we'll ignore namespace
994
- return this.setAttributeNode(attr);
995
- }
996
-
997
- setHTMLUnsafe(html: string): void {
998
- // throw new Error('Element.setHTMLUnsafe() is not implemented yet');
999
- }
1000
-
1001
- setPointerCapture(pointerId: number): void {
1002
- // throw new Error('Element.setPointerCapture() is not implemented yet');
1003
- }
1004
-
1005
- toggleAttribute(qualifiedName: string, force?: boolean): boolean {
1006
- const hasAttr = this.hasAttribute(qualifiedName);
1007
-
1008
- if (force === true || (force === undefined && !hasAttr)) {
1009
- this.setAttribute(qualifiedName, '');
1010
- return true;
1011
- } else if (force === false || (force === undefined && hasAttr)) {
1012
- this.removeAttribute(qualifiedName);
1013
- return false;
663
+ break;
664
+ default:
665
+ throw new DOMException(`Invalid position: ${position}`, 'SyntaxError');
666
+ }
667
+ }
668
+ insertAdjacentText(where: InsertPosition, data: string): void {
669
+ const position = where.toLowerCase();
670
+ const textNode = this._ownerDocument.createTextNode(data);
671
+ switch (position) {
672
+ case 'beforebegin':
673
+ if (this.parentNode) this.parentNode.insertBefore(textNode, this as any);
674
+ break;
675
+ case 'afterbegin':
676
+ if (this.firstChild) this.insertBefore(textNode, this.firstChild);
677
+ else this.appendChild(textNode);
678
+ break;
679
+ case 'beforeend':
680
+ this.appendChild(textNode);
681
+ break;
682
+ case 'afterend':
683
+ if (this.parentNode) {
684
+ if (this.nextSibling) this.parentNode.insertBefore(textNode, this.nextSibling);
685
+ else this.parentNode.appendChild(textNode);
1014
686
  }
1015
-
1016
- return hasAttr;
1017
- }
1018
-
1019
- webkitMatchesSelector(selectors: string): boolean {
1020
- // throw new Error('Element.webkitMatchesSelector() is not implemented yet');
1021
- return false;
1022
- }
1023
-
1024
- // EventTarget methods - Not implemented yet
1025
- addEventListener(type: string, listener: any, options?: any): void {
1026
- // throw new Error('Element.addEventListener() is not implemented yet');
1027
- }
1028
-
1029
- removeEventListener(type: string, listener: any, options?: any): void {
1030
- // throw new Error('Element.removeEventListener() is not implemented yet');
1031
- }
1032
-
1033
- dispatchEvent(event: any): boolean {
1034
- // throw new Error('Element.dispatchEvent() is not implemented yet');
1035
- return true;
1036
- }
1037
-
1038
- cloneNode(deep?: boolean): ElementBase {
1039
- // Use ElementFactory to create the correct element type
1040
- const clone = ElementFactory.createElement(this.tagName, this._ownerDocument);
1041
-
1042
- // Copy attributes
1043
- for (const [name, value] of this._attributes) {
1044
- clone.setAttribute(name, value);
1045
- }
1046
-
1047
- // Copy children if deep clone
1048
- if (deep) {
1049
- for (const child of this._childNodesInternal) {
1050
- if (child && 'cloneNode' in child) {
1051
- clone.appendChild((child as any).cloneNode(true));
1052
- }
1053
- }
1054
- }
1055
-
1056
- return clone;
1057
- }
687
+ break;
688
+ default:
689
+ throw new DOMException(`Invalid position: ${where}`, 'SyntaxError');
690
+ }
691
+ }
692
+ releasePointerCapture(_id: number): void {}
693
+ removeAttributeNS(_ns: string | null, localName: string): void {
694
+ this.removeAttribute(localName);
695
+ }
696
+ removeAttributeNode(attr: any): any {
697
+ const oldValue = this.getAttribute(attr.name);
698
+ if (oldValue !== null) {
699
+ this.removeAttribute(attr.name);
700
+ return new AttrImpl(attr.name, oldValue);
701
+ }
702
+ throw new DOMException('The attribute node is not an attribute of this element', 'NotFoundError');
703
+ }
704
+ requestFullscreen(_opt?: any): Promise<void> {
705
+ return Promise.resolve();
706
+ }
707
+ requestPointerLock(_opt?: any): Promise<void> {
708
+ return Promise.resolve();
709
+ }
710
+ scroll(_x?: any, _y?: any): void {}
711
+ scrollBy(_x?: any, _y?: any): void {}
712
+ scrollIntoView(_arg?: any): void {}
713
+ scrollTo(_x?: any, _y?: any): void {}
714
+ setAttributeNS(_ns: string | null, qualifiedName: string, value: string): void {
715
+ this.setAttribute(qualifiedName, value);
716
+ }
717
+ setAttributeNode(attr: any): any {
718
+ const oldAttr = this.getAttributeNode(attr.name);
719
+ this.setAttribute(attr.name, attr.value);
720
+ return oldAttr;
721
+ }
722
+ setAttributeNodeNS(attr: any): any {
723
+ return this.setAttributeNode(attr);
724
+ }
725
+ setHTMLUnsafe(html: string): void {
726
+ this.innerHTML = html;
727
+ }
728
+ setPointerCapture(_id: number): void {}
729
+ toggleAttribute(qualifiedName: string, force?: boolean): boolean {
730
+ const hasAttr = this.hasAttribute(qualifiedName);
731
+ if (force === true || (force === undefined && !hasAttr)) {
732
+ this.setAttribute(qualifiedName, '');
733
+ return true;
734
+ } else if (force === false || (force === undefined && hasAttr)) {
735
+ this.removeAttribute(qualifiedName);
736
+ return false;
737
+ }
738
+ return hasAttr;
739
+ }
740
+ webkitMatchesSelector(selectors: string): boolean {
741
+ return this.matches(selectors);
742
+ }
743
+ addEventListener(type: string, listener: any, options?: any): void {}
744
+ removeEventListener(type: string, listener: any, options?: any): void {}
745
+ dispatchEvent(_event: any): boolean {
746
+ return true;
747
+ }
748
+ cloneNode(deep?: boolean): any {
749
+ const { ElementFactory } = ElementBase.dependencies;
750
+ const clone = ElementFactory.createElement(this.tagName, this._ownerDocument);
751
+ for (const [name, value] of this._attributes) clone.setAttribute(name, value);
752
+ if (deep) for (const child of this._childNodesInternal) if (child && 'cloneNode' in child) clone.appendChild((child as any).cloneNode(true));
753
+ return clone;
754
+ }
1058
755
  }
1059
756
 
1060
- // DOMTokenList implementation
757
+ //@ts-ignore
1061
758
  class DOMTokenListImpl implements DOMTokenList {
1062
- constructor(private element: ElementBase) { }
1063
-
1064
- get length(): number {
1065
- return this.element.className.split(/\s+/).filter(c => c.length > 0).length;
1066
- }
1067
-
1068
- get value(): string {
1069
- return this.element.className;
1070
- }
1071
-
1072
- set value(value: string) {
1073
- this.element.className = value;
1074
- }
1075
-
1076
- add(...tokens: string[]): void {
1077
- const classes = new Set(this.element.className.split(/\s+/).filter(c => c.length > 0));
1078
- for (const token of tokens) {
1079
- classes.add(token);
1080
- }
1081
- this.element.className = Array.from(classes).join(' ');
1082
- }
1083
-
1084
- remove(...tokens: string[]): void {
1085
- const classes = new Set(this.element.className.split(/\s+/).filter(c => c.length > 0));
1086
- for (const token of tokens) {
1087
- classes.delete(token);
1088
- }
1089
- this.element.className = Array.from(classes).join(' ');
1090
- }
1091
-
1092
- contains(token: string): boolean {
1093
- return this.element.className.split(/\s+/).includes(token);
1094
- }
1095
-
1096
- toggle(token: string, force?: boolean): boolean {
1097
- const hasToken = this.contains(token);
1098
-
1099
- if (force === true || (force === undefined && !hasToken)) {
1100
- this.add(token);
1101
- return true;
1102
- } else {
1103
- this.remove(token);
1104
- return false;
1105
- }
1106
- }
1107
-
1108
- replace(oldToken: string, newToken: string): boolean {
1109
- if (this.contains(oldToken)) {
1110
- this.remove(oldToken);
1111
- this.add(newToken);
1112
- return true;
1113
- }
1114
- return false;
1115
- }
1116
-
1117
- item(index: number): string | null {
1118
- const classes = this.element.className.split(/\s+/).filter(c => c.length > 0);
1119
- return index >= 0 && index < classes.length ? classes[index] : null;
1120
- }
1121
-
1122
- [index: number]: string;
759
+ constructor(private element: ElementBase) {}
760
+
761
+ get length(): number {
762
+ return this.element.className.split(/\s+/).filter(c => c.length > 0).length;
763
+ }
764
+ get value(): string {
765
+ return this.element.className;
766
+ }
767
+ set value(value: string) {
768
+ this.element.className = value;
769
+ }
770
+ add(...tokens: string[]): void {
771
+ const classes = new Set(this.element.className.split(/\s+/).filter(c => c.length > 0));
772
+ tokens.forEach(t => classes.add(t));
773
+ this.element.className = Array.from(classes).join(' ');
774
+ }
775
+ remove(...tokens: string[]): void {
776
+ const classes = new Set(this.element.className.split(/\s+/).filter(c => c.length > 0));
777
+ tokens.forEach(t => classes.delete(t));
778
+ this.element.className = Array.from(classes).join(' ');
779
+ }
780
+ contains(token: string): boolean {
781
+ return this.element.className.split(/\s+/).includes(token);
782
+ }
783
+ toggle(token: string, force?: boolean): boolean {
784
+ const hasToken = this.contains(token);
785
+ if (force === true || (force === undefined && !hasToken)) {
786
+ this.add(token);
787
+ return true;
788
+ } else {
789
+ this.remove(token);
790
+ return false;
791
+ }
792
+ }
793
+ replace(oldToken: string, newToken: string): boolean {
794
+ if (this.contains(oldToken)) {
795
+ this.remove(oldToken);
796
+ this.add(newToken);
797
+ return true;
798
+ }
799
+ return false;
800
+ }
801
+ item(index: number): string | null {
802
+ const classes = this.element.className.split(/\s+/).filter(c => c.length > 0);
803
+ return index >= 0 && index < classes.length ? classes[index] : null;
804
+ }
805
+ [index: number]: string;
1123
806
  }
1124
807
 
1125
-
1126
-
1127
- // Attr implementation
808
+ //@ts-ignore
1128
809
  class AttrImpl extends NodeBase implements Attr {
1129
- public ownerElement: Element | null = null;
1130
- public namespaceURI: string | null = null;
1131
- public prefix: string | null = null;
1132
- public specified: boolean = true;
1133
-
1134
- constructor(public name: string, public value: string) {
1135
- super(ATTRIBUTE_NODE, name);
1136
- }
1137
-
1138
- get localName(): string {
1139
- return this.name;
1140
- }
810
+ public ownerElement: Element | null = null;
811
+ public namespaceURI: string | null = null;
812
+ public prefix: string | null = null;
813
+ public specified: boolean = true;
814
+ constructor(
815
+ public name: string,
816
+ public value: string
817
+ ) {
818
+ super(ATTRIBUTE_NODE, name);
819
+ }
820
+ get localName(): string {
821
+ return this.name;
822
+ }
1141
823
  }
1142
824
 
1143
- // NamedNodeMap implementation
1144
825
  class NamedNodeMapImpl implements NamedNodeMap {
1145
- constructor(private attributes: Map<string, string>) { }
1146
-
1147
- get length(): number {
1148
- return this.attributes.size;
1149
- }
1150
-
1151
- getNamedItem(qualifiedName: string): Attr | null {
1152
- const value = this.attributes.get(qualifiedName.toLowerCase());
1153
- return value !== undefined ? new AttrImpl(qualifiedName, value) : null;
1154
- }
1155
-
1156
- getNamedItemNS(namespace: string | null, localName: string): Attr | null {
1157
- // For simplicity, ignore namespace
1158
- return this.getNamedItem(localName);
1159
- }
1160
-
1161
- item(index: number): Attr | null {
1162
- const keys = Array.from(this.attributes.keys());
1163
- if (index >= 0 && index < keys.length) {
1164
- const key = keys[index];
1165
- const value = this.attributes.get(key)!;
1166
- return new AttrImpl(key, value);
1167
- }
1168
- return null;
1169
- }
1170
-
1171
- removeNamedItem(qualifiedName: string): Attr {
1172
- const value = this.attributes.get(qualifiedName.toLowerCase());
1173
- if (value !== undefined) {
1174
- this.attributes.delete(qualifiedName.toLowerCase());
1175
- return new AttrImpl(qualifiedName, value);
1176
- }
1177
- throw new DOMException('The attribute is not found', 'NotFoundError');
1178
- }
1179
-
1180
- removeNamedItemNS(namespace: string | null, localName: string): Attr {
1181
- // For simplicity, ignore namespace
1182
- return this.removeNamedItem(localName);
1183
- }
1184
-
1185
- setNamedItem(attr: Attr): Attr | null {
1186
- const oldValue = this.attributes.get(attr.name.toLowerCase());
1187
- this.attributes.set(attr.name.toLowerCase(), attr.value);
1188
- return oldValue !== undefined ? new AttrImpl(attr.name, oldValue) : null;
1189
- }
1190
-
1191
- setNamedItemNS(attr: Attr): Attr | null {
1192
- // For simplicity, ignore namespace
1193
- return this.setNamedItem(attr);
1194
- }
1195
-
1196
- // Iterator implementation
1197
- *[Symbol.iterator](): IterableIterator<Attr> {
1198
- const keys = Array.from(this.attributes.keys());
1199
- for (const key of keys) {
1200
- const value = this.attributes.get(key)!;
1201
- yield new AttrImpl(key, value);
1202
- }
1203
- }
1204
-
1205
- // Additional iterator methods for compatibility
1206
- keys(): IterableIterator<string> {
1207
- return this.attributes.keys();
1208
- }
1209
-
1210
- values(): IterableIterator<Attr> {
1211
- const self = this;
1212
- return (function* () {
1213
- for (const [key, value] of self.attributes) {
1214
- yield new AttrImpl(key, value);
1215
- }
1216
- })();
1217
- }
1218
-
1219
- entries(): IterableIterator<[string, Attr]> {
1220
- const self = this;
1221
- return (function* () {
1222
- for (const [key, value] of self.attributes) {
1223
- yield [key, new AttrImpl(key, value)] as [string, Attr];
1224
- }
1225
- })();
1226
- }
1227
-
1228
- // forEach method for compatibility
1229
- forEach(callback: (attr: Attr, index: number, map: NamedNodeMap) => void, thisArg?: any): void {
1230
- const keys = Array.from(this.attributes.keys());
1231
- keys.forEach((key, index) => {
1232
- const value = this.attributes.get(key)!;
1233
- const attr = new AttrImpl(key, value);
1234
- callback.call(thisArg, attr, index, this);
1235
- });
1236
- }
1237
-
1238
- [index: number]: Attr;
1239
- }
826
+ constructor(private attributes: Map<string, string>) {}
827
+ get length(): number {
828
+ return this.attributes.size;
829
+ }
830
+ getNamedItem(qualifiedName: string): any {
831
+ const value = this.attributes.get(qualifiedName.toLowerCase());
832
+ return value !== undefined ? new AttrImpl(qualifiedName, value) : null;
833
+ }
834
+ getNamedItemNS(_ns: string | null, localName: string): any {
835
+ return this.getNamedItem(localName);
836
+ }
837
+ item(index: number): any {
838
+ const keys = Array.from(this.attributes.keys());
839
+ if (index >= 0 && index < keys.length) return new AttrImpl(keys[index], this.attributes.get(keys[index])!);
840
+ return null;
841
+ }
842
+ removeNamedItem(qualifiedName: string): any {
843
+ const value = this.attributes.get(qualifiedName.toLowerCase());
844
+ if (value !== undefined) {
845
+ this.attributes.delete(qualifiedName.toLowerCase());
846
+ return new AttrImpl(qualifiedName, value);
847
+ }
848
+ throw new DOMException('The attribute is not found', 'NotFoundError');
849
+ }
850
+ removeNamedItemNS(_ns: string | null, localName: string): any {
851
+ return this.removeNamedItem(localName);
852
+ }
853
+ setNamedItem(attr: any): any {
854
+ const oldValue = this.attributes.get(attr.name.toLowerCase());
855
+ this.attributes.set(attr.name.toLowerCase(), attr.value);
856
+ return oldValue !== undefined ? new AttrImpl(attr.name, oldValue) : null;
857
+ }
858
+ setNamedItemNS(attr: any): any {
859
+ return this.setNamedItem(attr);
860
+ }
861
+ *[Symbol.iterator](): any {
862
+ for (const [key, value] of this.attributes) yield new AttrImpl(key, value);
863
+ }
864
+ keys(): any {
865
+ return this.attributes.keys();
866
+ }
867
+ values(): any {
868
+ const self = this;
869
+ return (function* () {
870
+ for (const [key, value] of self.attributes) yield new AttrImpl(key, value);
871
+ })();
872
+ }
873
+ entries(): any {
874
+ const self = this;
875
+ return (function* () {
876
+ for (const [key, value] of self.attributes) yield [key, new AttrImpl(key, value)];
877
+ })();
878
+ }
879
+ forEach(callback: any, thisArg?: any): void {
880
+ const keys = Array.from(this.attributes.keys());
881
+ keys.forEach((key, index) => callback.call(thisArg, new AttrImpl(key, this.attributes.get(key)!), index, this));
882
+ }
883
+ [index: number]: any;
884
+ }