@mavogel/cdk-vscode-server 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/.jsii +4351 -0
  2. package/API.md +367 -0
  3. package/CONTRIBUTING.md +59 -0
  4. package/LICENSE +202 -0
  5. package/README.md +183 -0
  6. package/assets/installer/installer.lambda/index.js +112 -0
  7. package/assets/secret-retriever/secret-retriever.lambda/index.js +57 -0
  8. package/docs/img/vscode-server-ui-login-min.png +0 -0
  9. package/docs/img/vscode-server-ui-min.png +0 -0
  10. package/docs/img/vscode-server.drawio +108 -0
  11. package/docs/img/vscode-server.drawio-min.png +0 -0
  12. package/integ-tests/code-server login.html +48 -0
  13. package/integ-tests/functions/login-handler.ts +63 -0
  14. package/integ-tests/integ.al2023.ts +69 -0
  15. package/integ-tests/integ.al2023.ts.snapshot/IntegSetupVSCodeOnAl2023DefaultTestDeployAssert74D8F645.assets.json +32 -0
  16. package/integ-tests/integ.al2023.ts.snapshot/IntegSetupVSCodeOnAl2023DefaultTestDeployAssert74D8F645.template.json +337 -0
  17. package/integ-tests/integ.al2023.ts.snapshot/IntegTestStackAl2023.assets.json +110 -0
  18. package/integ-tests/integ.al2023.ts.snapshot/IntegTestStackAl2023.template.json +2459 -0
  19. package/integ-tests/integ.al2023.ts.snapshot/asset.23732f3d1982f7fb0da3bd6638a8107337bb767fea165b45eae12000a1dd67ce/index.js +6169 -0
  20. package/integ-tests/integ.al2023.ts.snapshot/asset.2819175352ad1ce0dae768e83fc328fb70fb5f10b4a8ff0ccbcb791f02b0716d/index.js +1 -0
  21. package/integ-tests/integ.al2023.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/cfn-response.js +1 -0
  22. package/integ-tests/integ.al2023.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/consts.js +1 -0
  23. package/integ-tests/integ.al2023.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/framework.js +3 -0
  24. package/integ-tests/integ.al2023.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/outbound.js +1 -0
  25. package/integ-tests/integ.al2023.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/util.js +1 -0
  26. package/integ-tests/integ.al2023.ts.snapshot/asset.512cf155ada4793b37a885c1aa6d9bb8f534e88bac6f63c69672d4d73df2decf.lambda/index.js +112 -0
  27. package/integ-tests/integ.al2023.ts.snapshot/asset.781ab0ab74634cdaf61539ab208ab777829ef07097ac21f95b9e15a3b1eedc1b.lambda/index.js +57 -0
  28. package/integ-tests/integ.al2023.ts.snapshot/asset.c504585dae89ce8e394d7744ccae054318e7d1aff14afb545438d173d51dc97d.bundle/index.js +30572 -0
  29. package/integ-tests/integ.al2023.ts.snapshot/asset.ce2f3595a340d6c519a65888ef97e3b9b64f053f83608e32cc28162e22d7d99a/index.js +1 -0
  30. package/integ-tests/integ.al2023.ts.snapshot/asset.ee7de53d64cc9d6248fa6aa550f92358f6c907b5efd6f3298aeab1b5e7ea358a/__entrypoint__.js +1 -0
  31. package/integ-tests/integ.al2023.ts.snapshot/asset.ee7de53d64cc9d6248fa6aa550f92358f6c907b5efd6f3298aeab1b5e7ea358a/index.js +1 -0
  32. package/integ-tests/integ.al2023.ts.snapshot/cdk.out +1 -0
  33. package/integ-tests/integ.al2023.ts.snapshot/integ.json +22 -0
  34. package/integ-tests/integ.al2023.ts.snapshot/manifest.json +510 -0
  35. package/integ-tests/integ.al2023.ts.snapshot/tree.json +2944 -0
  36. package/integ-tests/integ.ubuntu.ts +66 -0
  37. package/integ-tests/integ.ubuntu.ts.snapshot/IntegSetupVSCodeOnUbuntuDefaultTestDeployAssertFF8DF2C5.assets.json +32 -0
  38. package/integ-tests/integ.ubuntu.ts.snapshot/IntegSetupVSCodeOnUbuntuDefaultTestDeployAssertFF8DF2C5.template.json +337 -0
  39. package/integ-tests/integ.ubuntu.ts.snapshot/IntegTestStackUbuntu22.assets.json +110 -0
  40. package/integ-tests/integ.ubuntu.ts.snapshot/IntegTestStackUbuntu22.template.json +2477 -0
  41. package/integ-tests/integ.ubuntu.ts.snapshot/asset.23732f3d1982f7fb0da3bd6638a8107337bb767fea165b45eae12000a1dd67ce/index.js +6169 -0
  42. package/integ-tests/integ.ubuntu.ts.snapshot/asset.2819175352ad1ce0dae768e83fc328fb70fb5f10b4a8ff0ccbcb791f02b0716d/index.js +1 -0
  43. package/integ-tests/integ.ubuntu.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/cfn-response.js +1 -0
  44. package/integ-tests/integ.ubuntu.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/consts.js +1 -0
  45. package/integ-tests/integ.ubuntu.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/framework.js +3 -0
  46. package/integ-tests/integ.ubuntu.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/outbound.js +1 -0
  47. package/integ-tests/integ.ubuntu.ts.snapshot/asset.4dc48ffba382f93077a1e6824599bbd4ceb6f91eb3d9442eca3b85bdb1a20b1e/util.js +1 -0
  48. package/integ-tests/integ.ubuntu.ts.snapshot/asset.512cf155ada4793b37a885c1aa6d9bb8f534e88bac6f63c69672d4d73df2decf.lambda/index.js +112 -0
  49. package/integ-tests/integ.ubuntu.ts.snapshot/asset.781ab0ab74634cdaf61539ab208ab777829ef07097ac21f95b9e15a3b1eedc1b.lambda/index.js +57 -0
  50. package/integ-tests/integ.ubuntu.ts.snapshot/asset.c504585dae89ce8e394d7744ccae054318e7d1aff14afb545438d173d51dc97d.bundle/index.js +30572 -0
  51. package/integ-tests/integ.ubuntu.ts.snapshot/asset.ce2f3595a340d6c519a65888ef97e3b9b64f053f83608e32cc28162e22d7d99a/index.js +1 -0
  52. package/integ-tests/integ.ubuntu.ts.snapshot/asset.ee7de53d64cc9d6248fa6aa550f92358f6c907b5efd6f3298aeab1b5e7ea358a/__entrypoint__.js +1 -0
  53. package/integ-tests/integ.ubuntu.ts.snapshot/asset.ee7de53d64cc9d6248fa6aa550f92358f6c907b5efd6f3298aeab1b5e7ea358a/index.js +1 -0
  54. package/integ-tests/integ.ubuntu.ts.snapshot/cdk.out +1 -0
  55. package/integ-tests/integ.ubuntu.ts.snapshot/integ.json +22 -0
  56. package/integ-tests/integ.ubuntu.ts.snapshot/manifest.json +510 -0
  57. package/integ-tests/integ.ubuntu.ts.snapshot/tree.json +2962 -0
  58. package/lib/index.d.ts +1 -0
  59. package/lib/index.js +18 -0
  60. package/lib/installer/installer-function.d.ts +13 -0
  61. package/lib/installer/installer-function.js +23 -0
  62. package/lib/installer/installer.d.ts +64 -0
  63. package/lib/installer/installer.js +707 -0
  64. package/lib/installer/installer.lambda.d.ts +3 -0
  65. package/lib/installer/installer.lambda.js +94 -0
  66. package/lib/mappings.d.ts +2 -0
  67. package/lib/mappings.js +25 -0
  68. package/lib/prefixlist-retriever/prefixlist-retriever.d.ts +16 -0
  69. package/lib/prefixlist-retriever/prefixlist-retriever.js +56 -0
  70. package/lib/secret-retriever/secret-retriever-function.d.ts +13 -0
  71. package/lib/secret-retriever/secret-retriever-function.js +23 -0
  72. package/lib/secret-retriever/secret-retriever.d.ts +33 -0
  73. package/lib/secret-retriever/secret-retriever.js +72 -0
  74. package/lib/secret-retriever/secret-retriever.lambda.d.ts +2 -0
  75. package/lib/secret-retriever/secret-retriever.lambda.js +36 -0
  76. package/lib/vscode-server.d.ts +97 -0
  77. package/lib/vscode-server.js +417 -0
  78. package/node_modules/boolbase/README.md +10 -0
  79. package/node_modules/boolbase/index.js +8 -0
  80. package/node_modules/boolbase/package.json +23 -0
  81. package/node_modules/css-select/LICENSE +11 -0
  82. package/node_modules/css-select/README.md +264 -0
  83. package/node_modules/css-select/lib/attributes.d.ts +7 -0
  84. package/node_modules/css-select/lib/attributes.d.ts.map +1 -0
  85. package/node_modules/css-select/lib/attributes.js +236 -0
  86. package/node_modules/css-select/lib/attributes.js.map +1 -0
  87. package/node_modules/css-select/lib/compile.d.ts +13 -0
  88. package/node_modules/css-select/lib/compile.d.ts.map +1 -0
  89. package/node_modules/css-select/lib/compile.js +151 -0
  90. package/node_modules/css-select/lib/compile.js.map +1 -0
  91. package/node_modules/css-select/lib/esm/attributes.d.ts +7 -0
  92. package/node_modules/css-select/lib/esm/attributes.d.ts.map +1 -0
  93. package/node_modules/css-select/lib/esm/attributes.js +222 -0
  94. package/node_modules/css-select/lib/esm/attributes.js.map +1 -0
  95. package/node_modules/css-select/lib/esm/compile.d.ts +13 -0
  96. package/node_modules/css-select/lib/esm/compile.d.ts.map +1 -0
  97. package/node_modules/css-select/lib/esm/compile.js +115 -0
  98. package/node_modules/css-select/lib/esm/compile.js.map +1 -0
  99. package/node_modules/css-select/lib/esm/general.d.ts +3 -0
  100. package/node_modules/css-select/lib/esm/general.d.ts.map +1 -0
  101. package/node_modules/css-select/lib/esm/general.js +144 -0
  102. package/node_modules/css-select/lib/esm/general.js.map +1 -0
  103. package/node_modules/css-select/lib/esm/index.d.ts +50 -0
  104. package/node_modules/css-select/lib/esm/index.d.ts.map +1 -0
  105. package/node_modules/css-select/lib/esm/index.js +115 -0
  106. package/node_modules/css-select/lib/esm/index.js.map +1 -0
  107. package/node_modules/css-select/lib/esm/package.json +1 -0
  108. package/node_modules/css-select/lib/esm/pseudo-selectors/aliases.d.ts +5 -0
  109. package/node_modules/css-select/lib/esm/pseudo-selectors/aliases.d.ts.map +1 -0
  110. package/node_modules/css-select/lib/esm/pseudo-selectors/aliases.js +35 -0
  111. package/node_modules/css-select/lib/esm/pseudo-selectors/aliases.js.map +1 -0
  112. package/node_modules/css-select/lib/esm/pseudo-selectors/filters.d.ts +4 -0
  113. package/node_modules/css-select/lib/esm/pseudo-selectors/filters.d.ts.map +1 -0
  114. package/node_modules/css-select/lib/esm/pseudo-selectors/filters.js +143 -0
  115. package/node_modules/css-select/lib/esm/pseudo-selectors/filters.js.map +1 -0
  116. package/node_modules/css-select/lib/esm/pseudo-selectors/index.d.ts +8 -0
  117. package/node_modules/css-select/lib/esm/pseudo-selectors/index.d.ts.map +1 -0
  118. package/node_modules/css-select/lib/esm/pseudo-selectors/index.js +40 -0
  119. package/node_modules/css-select/lib/esm/pseudo-selectors/index.js.map +1 -0
  120. package/node_modules/css-select/lib/esm/pseudo-selectors/pseudos.d.ts +6 -0
  121. package/node_modules/css-select/lib/esm/pseudo-selectors/pseudos.d.ts.map +1 -0
  122. package/node_modules/css-select/lib/esm/pseudo-selectors/pseudos.js +79 -0
  123. package/node_modules/css-select/lib/esm/pseudo-selectors/pseudos.js.map +1 -0
  124. package/node_modules/css-select/lib/esm/pseudo-selectors/subselects.d.ts +9 -0
  125. package/node_modules/css-select/lib/esm/pseudo-selectors/subselects.d.ts.map +1 -0
  126. package/node_modules/css-select/lib/esm/pseudo-selectors/subselects.js +94 -0
  127. package/node_modules/css-select/lib/esm/pseudo-selectors/subselects.js.map +1 -0
  128. package/node_modules/css-select/lib/esm/sort.d.ts +12 -0
  129. package/node_modules/css-select/lib/esm/sort.d.ts.map +1 -0
  130. package/node_modules/css-select/lib/esm/sort.js +79 -0
  131. package/node_modules/css-select/lib/esm/sort.js.map +1 -0
  132. package/node_modules/css-select/lib/esm/types.d.ts +167 -0
  133. package/node_modules/css-select/lib/esm/types.d.ts.map +1 -0
  134. package/node_modules/css-select/lib/esm/types.js +2 -0
  135. package/node_modules/css-select/lib/esm/types.js.map +1 -0
  136. package/node_modules/css-select/lib/general.d.ts +3 -0
  137. package/node_modules/css-select/lib/general.d.ts.map +1 -0
  138. package/node_modules/css-select/lib/general.js +148 -0
  139. package/node_modules/css-select/lib/general.js.map +1 -0
  140. package/node_modules/css-select/lib/index.d.ts +50 -0
  141. package/node_modules/css-select/lib/index.d.ts.map +1 -0
  142. package/node_modules/css-select/lib/index.js +154 -0
  143. package/node_modules/css-select/lib/index.js.map +1 -0
  144. package/node_modules/css-select/lib/pseudo-selectors/aliases.d.ts +5 -0
  145. package/node_modules/css-select/lib/pseudo-selectors/aliases.d.ts.map +1 -0
  146. package/node_modules/css-select/lib/pseudo-selectors/aliases.js +34 -0
  147. package/node_modules/css-select/lib/pseudo-selectors/aliases.js.map +1 -0
  148. package/node_modules/css-select/lib/pseudo-selectors/filters.d.ts +4 -0
  149. package/node_modules/css-select/lib/pseudo-selectors/filters.d.ts.map +1 -0
  150. package/node_modules/css-select/lib/pseudo-selectors/filters.js +157 -0
  151. package/node_modules/css-select/lib/pseudo-selectors/filters.js.map +1 -0
  152. package/node_modules/css-select/lib/pseudo-selectors/index.d.ts +8 -0
  153. package/node_modules/css-select/lib/pseudo-selectors/index.d.ts.map +1 -0
  154. package/node_modules/css-select/lib/pseudo-selectors/index.js +46 -0
  155. package/node_modules/css-select/lib/pseudo-selectors/index.js.map +1 -0
  156. package/node_modules/css-select/lib/pseudo-selectors/pseudos.d.ts +6 -0
  157. package/node_modules/css-select/lib/pseudo-selectors/pseudos.d.ts.map +1 -0
  158. package/node_modules/css-select/lib/pseudo-selectors/pseudos.js +93 -0
  159. package/node_modules/css-select/lib/pseudo-selectors/pseudos.js.map +1 -0
  160. package/node_modules/css-select/lib/pseudo-selectors/subselects.d.ts +9 -0
  161. package/node_modules/css-select/lib/pseudo-selectors/subselects.d.ts.map +1 -0
  162. package/node_modules/css-select/lib/pseudo-selectors/subselects.js +112 -0
  163. package/node_modules/css-select/lib/pseudo-selectors/subselects.js.map +1 -0
  164. package/node_modules/css-select/lib/sort.d.ts +12 -0
  165. package/node_modules/css-select/lib/sort.d.ts.map +1 -0
  166. package/node_modules/css-select/lib/sort.js +84 -0
  167. package/node_modules/css-select/lib/sort.js.map +1 -0
  168. package/node_modules/css-select/lib/types.d.ts +167 -0
  169. package/node_modules/css-select/lib/types.d.ts.map +1 -0
  170. package/node_modules/css-select/lib/types.js +3 -0
  171. package/node_modules/css-select/lib/types.js.map +1 -0
  172. package/node_modules/css-select/package.json +81 -0
  173. package/node_modules/css-what/LICENSE +11 -0
  174. package/node_modules/css-what/lib/commonjs/index.d.ts +4 -0
  175. package/node_modules/css-what/lib/commonjs/index.d.ts.map +1 -0
  176. package/node_modules/css-what/lib/commonjs/index.js +23 -0
  177. package/node_modules/css-what/lib/commonjs/parse.d.ts +20 -0
  178. package/node_modules/css-what/lib/commonjs/parse.d.ts.map +1 -0
  179. package/node_modules/css-what/lib/commonjs/parse.js +425 -0
  180. package/node_modules/css-what/lib/commonjs/stringify.d.ts +8 -0
  181. package/node_modules/css-what/lib/commonjs/stringify.d.ts.map +1 -0
  182. package/node_modules/css-what/lib/commonjs/stringify.js +138 -0
  183. package/node_modules/css-what/lib/commonjs/types.d.ts +70 -0
  184. package/node_modules/css-what/lib/commonjs/types.d.ts.map +1 -0
  185. package/node_modules/css-what/lib/commonjs/types.js +42 -0
  186. package/node_modules/css-what/lib/es/index.d.ts +4 -0
  187. package/node_modules/css-what/lib/es/index.d.ts.map +1 -0
  188. package/node_modules/css-what/lib/es/index.js +3 -0
  189. package/node_modules/css-what/lib/es/parse.d.ts +20 -0
  190. package/node_modules/css-what/lib/es/parse.d.ts.map +1 -0
  191. package/node_modules/css-what/lib/es/parse.js +420 -0
  192. package/node_modules/css-what/lib/es/stringify.d.ts +8 -0
  193. package/node_modules/css-what/lib/es/stringify.d.ts.map +1 -0
  194. package/node_modules/css-what/lib/es/stringify.js +126 -0
  195. package/node_modules/css-what/lib/es/types.d.ts +70 -0
  196. package/node_modules/css-what/lib/es/types.d.ts.map +1 -0
  197. package/node_modules/css-what/lib/es/types.js +39 -0
  198. package/node_modules/css-what/package.json +59 -0
  199. package/node_modules/css-what/readme.md +69 -0
  200. package/node_modules/dom-serializer/LICENSE +11 -0
  201. package/node_modules/dom-serializer/README.md +109 -0
  202. package/node_modules/dom-serializer/lib/esm/foreignNames.d.ts +3 -0
  203. package/node_modules/dom-serializer/lib/esm/foreignNames.d.ts.map +1 -0
  204. package/node_modules/dom-serializer/lib/esm/foreignNames.js +100 -0
  205. package/node_modules/dom-serializer/lib/esm/index.d.ts +52 -0
  206. package/node_modules/dom-serializer/lib/esm/index.d.ts.map +1 -0
  207. package/node_modules/dom-serializer/lib/esm/index.js +190 -0
  208. package/node_modules/dom-serializer/lib/esm/package.json +1 -0
  209. package/node_modules/dom-serializer/lib/foreignNames.d.ts +3 -0
  210. package/node_modules/dom-serializer/lib/foreignNames.d.ts.map +1 -0
  211. package/node_modules/dom-serializer/lib/foreignNames.js +103 -0
  212. package/node_modules/dom-serializer/lib/index.d.ts +52 -0
  213. package/node_modules/dom-serializer/lib/index.d.ts.map +1 -0
  214. package/node_modules/dom-serializer/lib/index.js +229 -0
  215. package/node_modules/dom-serializer/package.json +69 -0
  216. package/node_modules/domelementtype/LICENSE +11 -0
  217. package/node_modules/domelementtype/lib/esm/index.d.ts +48 -0
  218. package/node_modules/domelementtype/lib/esm/index.d.ts.map +1 -0
  219. package/node_modules/domelementtype/lib/esm/index.js +51 -0
  220. package/node_modules/domelementtype/lib/esm/package.json +1 -0
  221. package/node_modules/domelementtype/lib/index.d.ts +48 -0
  222. package/node_modules/domelementtype/lib/index.d.ts.map +1 -0
  223. package/node_modules/domelementtype/lib/index.js +55 -0
  224. package/node_modules/domelementtype/package.json +54 -0
  225. package/node_modules/domelementtype/readme.md +1 -0
  226. package/node_modules/domhandler/LICENSE +11 -0
  227. package/node_modules/domhandler/lib/esm/index.d.ts +76 -0
  228. package/node_modules/domhandler/lib/esm/index.d.ts.map +1 -0
  229. package/node_modules/domhandler/lib/esm/index.js +146 -0
  230. package/node_modules/domhandler/lib/esm/node.d.ts +245 -0
  231. package/node_modules/domhandler/lib/esm/node.d.ts.map +1 -0
  232. package/node_modules/domhandler/lib/esm/node.js +338 -0
  233. package/node_modules/domhandler/lib/esm/package.json +1 -0
  234. package/node_modules/domhandler/lib/index.d.ts +76 -0
  235. package/node_modules/domhandler/lib/index.d.ts.map +1 -0
  236. package/node_modules/domhandler/lib/index.js +165 -0
  237. package/node_modules/domhandler/lib/node.d.ts +245 -0
  238. package/node_modules/domhandler/lib/node.d.ts.map +1 -0
  239. package/node_modules/domhandler/lib/node.js +474 -0
  240. package/node_modules/domhandler/package.json +73 -0
  241. package/node_modules/domhandler/readme.md +92 -0
  242. package/node_modules/domutils/LICENSE +11 -0
  243. package/node_modules/domutils/lib/esm/feeds.d.ts +71 -0
  244. package/node_modules/domutils/lib/esm/feeds.d.ts.map +1 -0
  245. package/node_modules/domutils/lib/esm/feeds.js +183 -0
  246. package/node_modules/domutils/lib/esm/feeds.js.map +1 -0
  247. package/node_modules/domutils/lib/esm/helpers.d.ts +59 -0
  248. package/node_modules/domutils/lib/esm/helpers.d.ts.map +1 -0
  249. package/node_modules/domutils/lib/esm/helpers.js +136 -0
  250. package/node_modules/domutils/lib/esm/helpers.js.map +1 -0
  251. package/node_modules/domutils/lib/esm/index.d.ts +10 -0
  252. package/node_modules/domutils/lib/esm/index.d.ts.map +1 -0
  253. package/node_modules/domutils/lib/esm/index.js +10 -0
  254. package/node_modules/domutils/lib/esm/index.js.map +1 -0
  255. package/node_modules/domutils/lib/esm/legacy.d.ts +79 -0
  256. package/node_modules/domutils/lib/esm/legacy.d.ts.map +1 -0
  257. package/node_modules/domutils/lib/esm/legacy.js +152 -0
  258. package/node_modules/domutils/lib/esm/legacy.js.map +1 -0
  259. package/node_modules/domutils/lib/esm/manipulation.d.ts +49 -0
  260. package/node_modules/domutils/lib/esm/manipulation.d.ts.map +1 -0
  261. package/node_modules/domutils/lib/esm/manipulation.js +134 -0
  262. package/node_modules/domutils/lib/esm/manipulation.js.map +1 -0
  263. package/node_modules/domutils/lib/esm/package.json +1 -0
  264. package/node_modules/domutils/lib/esm/querying.d.ts +64 -0
  265. package/node_modules/domutils/lib/esm/querying.d.ts.map +1 -0
  266. package/node_modules/domutils/lib/esm/querying.js +142 -0
  267. package/node_modules/domutils/lib/esm/querying.js.map +1 -0
  268. package/node_modules/domutils/lib/esm/stringify.d.ts +46 -0
  269. package/node_modules/domutils/lib/esm/stringify.d.ts.map +1 -0
  270. package/node_modules/domutils/lib/esm/stringify.js +81 -0
  271. package/node_modules/domutils/lib/esm/stringify.js.map +1 -0
  272. package/node_modules/domutils/lib/esm/traversal.d.ts +67 -0
  273. package/node_modules/domutils/lib/esm/traversal.d.ts.map +1 -0
  274. package/node_modules/domutils/lib/esm/traversal.js +112 -0
  275. package/node_modules/domutils/lib/esm/traversal.js.map +1 -0
  276. package/node_modules/domutils/lib/feeds.d.ts +71 -0
  277. package/node_modules/domutils/lib/feeds.d.ts.map +1 -0
  278. package/node_modules/domutils/lib/feeds.js +190 -0
  279. package/node_modules/domutils/lib/feeds.js.map +1 -0
  280. package/node_modules/domutils/lib/helpers.d.ts +59 -0
  281. package/node_modules/domutils/lib/helpers.d.ts.map +1 -0
  282. package/node_modules/domutils/lib/helpers.js +142 -0
  283. package/node_modules/domutils/lib/helpers.js.map +1 -0
  284. package/node_modules/domutils/lib/index.d.ts +10 -0
  285. package/node_modules/domutils/lib/index.d.ts.map +1 -0
  286. package/node_modules/domutils/lib/index.js +33 -0
  287. package/node_modules/domutils/lib/index.js.map +1 -0
  288. package/node_modules/domutils/lib/legacy.d.ts +79 -0
  289. package/node_modules/domutils/lib/legacy.d.ts.map +1 -0
  290. package/node_modules/domutils/lib/legacy.js +168 -0
  291. package/node_modules/domutils/lib/legacy.js.map +1 -0
  292. package/node_modules/domutils/lib/manipulation.d.ts +49 -0
  293. package/node_modules/domutils/lib/manipulation.d.ts.map +1 -0
  294. package/node_modules/domutils/lib/manipulation.js +142 -0
  295. package/node_modules/domutils/lib/manipulation.js.map +1 -0
  296. package/node_modules/domutils/lib/querying.d.ts +64 -0
  297. package/node_modules/domutils/lib/querying.d.ts.map +1 -0
  298. package/node_modules/domutils/lib/querying.js +155 -0
  299. package/node_modules/domutils/lib/querying.js.map +1 -0
  300. package/node_modules/domutils/lib/stringify.d.ts +46 -0
  301. package/node_modules/domutils/lib/stringify.d.ts.map +1 -0
  302. package/node_modules/domutils/lib/stringify.js +91 -0
  303. package/node_modules/domutils/lib/stringify.js.map +1 -0
  304. package/node_modules/domutils/lib/traversal.d.ts +67 -0
  305. package/node_modules/domutils/lib/traversal.d.ts.map +1 -0
  306. package/node_modules/domutils/lib/traversal.js +125 -0
  307. package/node_modules/domutils/lib/traversal.js.map +1 -0
  308. package/node_modules/domutils/package.json +79 -0
  309. package/node_modules/domutils/readme.md +31 -0
  310. package/node_modules/entities/LICENSE +11 -0
  311. package/node_modules/entities/lib/decode.d.ts +211 -0
  312. package/node_modules/entities/lib/decode.d.ts.map +1 -0
  313. package/node_modules/entities/lib/decode.js +536 -0
  314. package/node_modules/entities/lib/decode.js.map +1 -0
  315. package/node_modules/entities/lib/decode_codepoint.d.ts +19 -0
  316. package/node_modules/entities/lib/decode_codepoint.d.ts.map +1 -0
  317. package/node_modules/entities/lib/decode_codepoint.js +76 -0
  318. package/node_modules/entities/lib/decode_codepoint.js.map +1 -0
  319. package/node_modules/entities/lib/encode.d.ts +22 -0
  320. package/node_modules/entities/lib/encode.d.ts.map +1 -0
  321. package/node_modules/entities/lib/encode.js +77 -0
  322. package/node_modules/entities/lib/encode.js.map +1 -0
  323. package/node_modules/entities/lib/escape.d.ts +43 -0
  324. package/node_modules/entities/lib/escape.d.ts.map +1 -0
  325. package/node_modules/entities/lib/escape.js +122 -0
  326. package/node_modules/entities/lib/escape.js.map +1 -0
  327. package/node_modules/entities/lib/esm/decode.d.ts +211 -0
  328. package/node_modules/entities/lib/esm/decode.d.ts.map +1 -0
  329. package/node_modules/entities/lib/esm/decode.js +496 -0
  330. package/node_modules/entities/lib/esm/decode.js.map +1 -0
  331. package/node_modules/entities/lib/esm/decode_codepoint.d.ts +19 -0
  332. package/node_modules/entities/lib/esm/decode_codepoint.d.ts.map +1 -0
  333. package/node_modules/entities/lib/esm/decode_codepoint.js +71 -0
  334. package/node_modules/entities/lib/esm/decode_codepoint.js.map +1 -0
  335. package/node_modules/entities/lib/esm/encode.d.ts +22 -0
  336. package/node_modules/entities/lib/esm/encode.d.ts.map +1 -0
  337. package/node_modules/entities/lib/esm/encode.js +69 -0
  338. package/node_modules/entities/lib/esm/encode.js.map +1 -0
  339. package/node_modules/entities/lib/esm/escape.d.ts +43 -0
  340. package/node_modules/entities/lib/esm/escape.d.ts.map +1 -0
  341. package/node_modules/entities/lib/esm/escape.js +116 -0
  342. package/node_modules/entities/lib/esm/escape.js.map +1 -0
  343. package/node_modules/entities/lib/esm/generated/decode-data-html.d.ts +3 -0
  344. package/node_modules/entities/lib/esm/generated/decode-data-html.d.ts.map +1 -0
  345. package/node_modules/entities/lib/esm/generated/decode-data-html.js +7 -0
  346. package/node_modules/entities/lib/esm/generated/decode-data-html.js.map +1 -0
  347. package/node_modules/entities/lib/esm/generated/decode-data-xml.d.ts +3 -0
  348. package/node_modules/entities/lib/esm/generated/decode-data-xml.d.ts.map +1 -0
  349. package/node_modules/entities/lib/esm/generated/decode-data-xml.js +7 -0
  350. package/node_modules/entities/lib/esm/generated/decode-data-xml.js.map +1 -0
  351. package/node_modules/entities/lib/esm/generated/encode-html.d.ts +8 -0
  352. package/node_modules/entities/lib/esm/generated/encode-html.d.ts.map +1 -0
  353. package/node_modules/entities/lib/esm/generated/encode-html.js +10 -0
  354. package/node_modules/entities/lib/esm/generated/encode-html.js.map +1 -0
  355. package/node_modules/entities/lib/esm/index.d.ts +96 -0
  356. package/node_modules/entities/lib/esm/index.d.ts.map +1 -0
  357. package/node_modules/entities/lib/esm/index.js +99 -0
  358. package/node_modules/entities/lib/esm/index.js.map +1 -0
  359. package/node_modules/entities/lib/esm/package.json +1 -0
  360. package/node_modules/entities/lib/generated/decode-data-html.d.ts +3 -0
  361. package/node_modules/entities/lib/generated/decode-data-html.d.ts.map +1 -0
  362. package/node_modules/entities/lib/generated/decode-data-html.js +9 -0
  363. package/node_modules/entities/lib/generated/decode-data-html.js.map +1 -0
  364. package/node_modules/entities/lib/generated/decode-data-xml.d.ts +3 -0
  365. package/node_modules/entities/lib/generated/decode-data-xml.d.ts.map +1 -0
  366. package/node_modules/entities/lib/generated/decode-data-xml.js +9 -0
  367. package/node_modules/entities/lib/generated/decode-data-xml.js.map +1 -0
  368. package/node_modules/entities/lib/generated/encode-html.d.ts +8 -0
  369. package/node_modules/entities/lib/generated/encode-html.d.ts.map +1 -0
  370. package/node_modules/entities/lib/generated/encode-html.js +12 -0
  371. package/node_modules/entities/lib/generated/encode-html.js.map +1 -0
  372. package/node_modules/entities/lib/index.d.ts +96 -0
  373. package/node_modules/entities/lib/index.d.ts.map +1 -0
  374. package/node_modules/entities/lib/index.js +126 -0
  375. package/node_modules/entities/lib/index.js.map +1 -0
  376. package/node_modules/entities/package.json +90 -0
  377. package/node_modules/entities/readme.md +122 -0
  378. package/node_modules/he/LICENSE-MIT.txt +20 -0
  379. package/node_modules/he/README.md +379 -0
  380. package/node_modules/he/bin/he +148 -0
  381. package/node_modules/he/he.js +345 -0
  382. package/node_modules/he/man/he.1 +78 -0
  383. package/node_modules/he/package.json +58 -0
  384. package/node_modules/node-html-parser/CHANGELOG.md +137 -0
  385. package/node_modules/node-html-parser/LICENSE +7 -0
  386. package/node_modules/node-html-parser/README.md +365 -0
  387. package/node_modules/node-html-parser/dist/back.d.ts +1 -0
  388. package/node_modules/node-html-parser/dist/back.js +6 -0
  389. package/node_modules/node-html-parser/dist/index.d.ts +20 -0
  390. package/node_modules/node-html-parser/dist/index.js +32 -0
  391. package/node_modules/node-html-parser/dist/main.js +1646 -0
  392. package/node_modules/node-html-parser/dist/matcher.d.ts +6 -0
  393. package/node_modules/node-html-parser/dist/matcher.js +106 -0
  394. package/node_modules/node-html-parser/dist/nodes/comment.d.ts +20 -0
  395. package/node_modules/node-html-parser/dist/nodes/comment.js +57 -0
  396. package/node_modules/node-html-parser/dist/nodes/html.d.ts +240 -0
  397. package/node_modules/node-html-parser/dist/nodes/html.js +1218 -0
  398. package/node_modules/node-html-parser/dist/nodes/node.d.ts +24 -0
  399. package/node_modules/node-html-parser/dist/nodes/node.js +52 -0
  400. package/node_modules/node-html-parser/dist/nodes/text.d.ts +44 -0
  401. package/node_modules/node-html-parser/dist/nodes/text.js +144 -0
  402. package/node_modules/node-html-parser/dist/nodes/type.d.ts +6 -0
  403. package/node_modules/node-html-parser/dist/nodes/type.js +9 -0
  404. package/node_modules/node-html-parser/dist/parse.d.ts +1 -0
  405. package/node_modules/node-html-parser/dist/parse.js +5 -0
  406. package/node_modules/node-html-parser/dist/valid.d.ts +6 -0
  407. package/node_modules/node-html-parser/dist/valid.js +13 -0
  408. package/node_modules/node-html-parser/dist/void-tag.d.ts +7 -0
  409. package/node_modules/node-html-parser/dist/void-tag.js +29 -0
  410. package/node_modules/node-html-parser/package.json +114 -0
  411. package/node_modules/nth-check/LICENSE +11 -0
  412. package/node_modules/nth-check/README.md +136 -0
  413. package/node_modules/nth-check/lib/compile.d.ts +55 -0
  414. package/node_modules/nth-check/lib/compile.d.ts.map +1 -0
  415. package/node_modules/nth-check/lib/compile.js +121 -0
  416. package/node_modules/nth-check/lib/compile.js.map +1 -0
  417. package/node_modules/nth-check/lib/esm/compile.d.ts +55 -0
  418. package/node_modules/nth-check/lib/esm/compile.d.ts.map +1 -0
  419. package/node_modules/nth-check/lib/esm/compile.js +113 -0
  420. package/node_modules/nth-check/lib/esm/compile.js.map +1 -0
  421. package/node_modules/nth-check/lib/esm/index.d.ts +59 -0
  422. package/node_modules/nth-check/lib/esm/index.d.ts.map +1 -0
  423. package/node_modules/nth-check/lib/esm/index.js +63 -0
  424. package/node_modules/nth-check/lib/esm/index.js.map +1 -0
  425. package/node_modules/nth-check/lib/esm/package.json +1 -0
  426. package/node_modules/nth-check/lib/esm/parse.d.ts +9 -0
  427. package/node_modules/nth-check/lib/esm/parse.d.ts.map +1 -0
  428. package/node_modules/nth-check/lib/esm/parse.js +73 -0
  429. package/node_modules/nth-check/lib/esm/parse.js.map +1 -0
  430. package/node_modules/nth-check/lib/index.d.ts +59 -0
  431. package/node_modules/nth-check/lib/index.d.ts.map +1 -0
  432. package/node_modules/nth-check/lib/index.js +70 -0
  433. package/node_modules/nth-check/lib/index.js.map +1 -0
  434. package/node_modules/nth-check/lib/parse.d.ts +9 -0
  435. package/node_modules/nth-check/lib/parse.d.ts.map +1 -0
  436. package/node_modules/nth-check/lib/parse.js +77 -0
  437. package/node_modules/nth-check/lib/parse.js.map +1 -0
  438. package/node_modules/nth-check/package.json +78 -0
  439. package/package.json +154 -0
@@ -0,0 +1,1218 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
+ if (ar || !(i in from)) {
31
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
+ ar[i] = from[i];
33
+ }
34
+ }
35
+ return to.concat(ar || Array.prototype.slice.call(from));
36
+ };
37
+ var __importDefault = (this && this.__importDefault) || function (mod) {
38
+ return (mod && mod.__esModule) ? mod : { "default": mod };
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.parse = exports.base_parse = void 0;
42
+ var css_select_1 = require("css-select");
43
+ var he_1 = __importDefault(require("he"));
44
+ var back_1 = __importDefault(require("../back"));
45
+ var matcher_1 = __importDefault(require("../matcher"));
46
+ var void_tag_1 = __importDefault(require("../void-tag"));
47
+ var comment_1 = __importDefault(require("./comment"));
48
+ var node_1 = __importDefault(require("./node"));
49
+ var text_1 = __importDefault(require("./text"));
50
+ var type_1 = __importDefault(require("./type"));
51
+ function decode(val) {
52
+ // clone string
53
+ return JSON.parse(JSON.stringify(he_1.default.decode(val)));
54
+ }
55
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
56
+ var Htags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup'];
57
+ var Dtags = ['details', 'dialog', 'dd', 'div', 'dt'];
58
+ var Ftags = ['fieldset', 'figcaption', 'figure', 'footer', 'form'];
59
+ var tableTags = ['table', 'td', 'tr'];
60
+ var htmlTags = ['address', 'article', 'aside', 'blockquote', 'br', 'hr', 'li', 'main', 'nav', 'ol', 'p', 'pre', 'section', 'ul'];
61
+ var kBlockElements = new Set();
62
+ function addToKBlockElement() {
63
+ var args = [];
64
+ for (var _i = 0; _i < arguments.length; _i++) {
65
+ args[_i] = arguments[_i];
66
+ }
67
+ var addToSet = function (array) {
68
+ for (var index = 0; index < array.length; index++) {
69
+ var element = array[index];
70
+ kBlockElements.add(element);
71
+ kBlockElements.add(element.toUpperCase());
72
+ }
73
+ };
74
+ for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
75
+ var arg = args_1[_a];
76
+ addToSet(arg);
77
+ }
78
+ }
79
+ addToKBlockElement(Htags, Dtags, Ftags, tableTags, htmlTags);
80
+ var DOMTokenList = /** @class */ (function () {
81
+ function DOMTokenList(valuesInit, afterUpdate) {
82
+ if (valuesInit === void 0) { valuesInit = []; }
83
+ if (afterUpdate === void 0) { afterUpdate = function () { return null; }; }
84
+ this._set = new Set(valuesInit);
85
+ this._afterUpdate = afterUpdate;
86
+ }
87
+ DOMTokenList.prototype._validate = function (c) {
88
+ if (/\s/.test(c)) {
89
+ throw new Error("DOMException in DOMTokenList.add: The token '".concat(c, "' contains HTML space characters, which are not valid in tokens."));
90
+ }
91
+ };
92
+ DOMTokenList.prototype.add = function (c) {
93
+ this._validate(c);
94
+ this._set.add(c);
95
+ this._afterUpdate(this); // eslint-disable-line @typescript-eslint/no-unsafe-call
96
+ };
97
+ DOMTokenList.prototype.replace = function (c1, c2) {
98
+ this._validate(c2);
99
+ this._set.delete(c1);
100
+ this._set.add(c2);
101
+ this._afterUpdate(this); // eslint-disable-line @typescript-eslint/no-unsafe-call
102
+ };
103
+ DOMTokenList.prototype.remove = function (c) {
104
+ this._set.delete(c) && this._afterUpdate(this); // eslint-disable-line @typescript-eslint/no-unsafe-call
105
+ };
106
+ DOMTokenList.prototype.toggle = function (c) {
107
+ this._validate(c);
108
+ if (this._set.has(c))
109
+ this._set.delete(c);
110
+ else
111
+ this._set.add(c);
112
+ this._afterUpdate(this); // eslint-disable-line @typescript-eslint/no-unsafe-call
113
+ };
114
+ DOMTokenList.prototype.contains = function (c) {
115
+ return this._set.has(c);
116
+ };
117
+ Object.defineProperty(DOMTokenList.prototype, "length", {
118
+ get: function () {
119
+ return this._set.size;
120
+ },
121
+ enumerable: false,
122
+ configurable: true
123
+ });
124
+ DOMTokenList.prototype.values = function () {
125
+ return this._set.values();
126
+ };
127
+ Object.defineProperty(DOMTokenList.prototype, "value", {
128
+ get: function () {
129
+ return Array.from(this._set.values());
130
+ },
131
+ enumerable: false,
132
+ configurable: true
133
+ });
134
+ DOMTokenList.prototype.toString = function () {
135
+ return Array.from(this._set.values()).join(' ');
136
+ };
137
+ return DOMTokenList;
138
+ }());
139
+ /**
140
+ * HTMLElement, which contains a set of children.
141
+ *
142
+ * Note: this is a minimalist implementation, no complete tree
143
+ * structure provided (no parentNode, nextSibling,
144
+ * previousSibling etc).
145
+ * @class HTMLElement
146
+ * @extends {Node}
147
+ */
148
+ var HTMLElement = /** @class */ (function (_super) {
149
+ __extends(HTMLElement, _super);
150
+ /**
151
+ * Creates an instance of HTMLElement.
152
+ * @param keyAttrs id and class attribute
153
+ * @param [rawAttrs] attributes in string
154
+ *
155
+ * @memberof HTMLElement
156
+ */
157
+ function HTMLElement(tagName, keyAttrs, rawAttrs, parentNode, range, voidTag, _parseOptions) {
158
+ if (rawAttrs === void 0) { rawAttrs = ''; }
159
+ if (parentNode === void 0) { parentNode = null; }
160
+ if (voidTag === void 0) { voidTag = new void_tag_1.default(); }
161
+ if (_parseOptions === void 0) { _parseOptions = {}; }
162
+ var _this = _super.call(this, parentNode, range) || this;
163
+ _this.rawAttrs = rawAttrs;
164
+ _this.voidTag = voidTag;
165
+ /**
166
+ * Node Type declaration.
167
+ */
168
+ _this.nodeType = type_1.default.ELEMENT_NODE;
169
+ _this.rawTagName = tagName;
170
+ _this.rawAttrs = rawAttrs || '';
171
+ _this.id = keyAttrs.id || '';
172
+ _this.childNodes = [];
173
+ _this._parseOptions = _parseOptions;
174
+ _this.classList = new DOMTokenList(keyAttrs.class ? keyAttrs.class.split(/\s+/) : [], function (classList) { return _this.setAttribute('class', classList.toString()); } // eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
175
+ );
176
+ if (keyAttrs.id) {
177
+ if (!rawAttrs) {
178
+ _this.rawAttrs = "id=\"".concat(keyAttrs.id, "\"");
179
+ }
180
+ }
181
+ if (keyAttrs.class) {
182
+ if (!rawAttrs) {
183
+ var cls = "class=\"".concat(_this.classList.toString(), "\"");
184
+ if (_this.rawAttrs) {
185
+ _this.rawAttrs += " ".concat(cls);
186
+ }
187
+ else {
188
+ _this.rawAttrs = cls;
189
+ }
190
+ }
191
+ }
192
+ return _this;
193
+ }
194
+ /**
195
+ * Quote attribute values
196
+ * @param attr attribute value
197
+ * @returns {string} quoted value
198
+ */
199
+ HTMLElement.prototype.quoteAttribute = function (attr) {
200
+ if (attr == null) {
201
+ return 'null';
202
+ }
203
+ return JSON.stringify(attr.replace(/"/g, '&quot;')).replace(/\\t/g, '\t').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\/g, '');
204
+ };
205
+ /**
206
+ * Remove Child element from childNodes array
207
+ * @param {HTMLElement} node node to remove
208
+ */
209
+ HTMLElement.prototype.removeChild = function (node) {
210
+ this.childNodes = this.childNodes.filter(function (child) {
211
+ return child !== node;
212
+ });
213
+ return this;
214
+ };
215
+ /**
216
+ * Exchanges given child with new child
217
+ * @param {HTMLElement} oldNode node to exchange
218
+ * @param {HTMLElement} newNode new node
219
+ */
220
+ HTMLElement.prototype.exchangeChild = function (oldNode, newNode) {
221
+ var children = this.childNodes;
222
+ this.childNodes = children.map(function (child) {
223
+ if (child === oldNode) {
224
+ return newNode;
225
+ }
226
+ return child;
227
+ });
228
+ return this;
229
+ };
230
+ Object.defineProperty(HTMLElement.prototype, "tagName", {
231
+ get: function () {
232
+ return this.rawTagName ? this.rawTagName.toUpperCase() : this.rawTagName;
233
+ },
234
+ set: function (newname) {
235
+ this.rawTagName = newname.toLowerCase();
236
+ },
237
+ enumerable: false,
238
+ configurable: true
239
+ });
240
+ Object.defineProperty(HTMLElement.prototype, "localName", {
241
+ get: function () {
242
+ return this.rawTagName.toLowerCase();
243
+ },
244
+ enumerable: false,
245
+ configurable: true
246
+ });
247
+ Object.defineProperty(HTMLElement.prototype, "isVoidElement", {
248
+ get: function () {
249
+ return this.voidTag.isVoidElement(this.localName);
250
+ },
251
+ enumerable: false,
252
+ configurable: true
253
+ });
254
+ Object.defineProperty(HTMLElement.prototype, "rawText", {
255
+ /**
256
+ * Get escpaed (as-it) text value of current node and its children.
257
+ * @return {string} text content
258
+ */
259
+ get: function () {
260
+ // https://github.com/taoqf/node-html-parser/issues/249
261
+ if (/^br$/i.test(this.rawTagName)) {
262
+ return '\n';
263
+ }
264
+ return this.childNodes.reduce(function (pre, cur) {
265
+ return (pre += cur.rawText);
266
+ }, '');
267
+ },
268
+ enumerable: false,
269
+ configurable: true
270
+ });
271
+ Object.defineProperty(HTMLElement.prototype, "textContent", {
272
+ get: function () {
273
+ return decode(this.rawText);
274
+ },
275
+ set: function (val) {
276
+ var content = [new text_1.default(val, this)];
277
+ this.childNodes = content;
278
+ },
279
+ enumerable: false,
280
+ configurable: true
281
+ });
282
+ Object.defineProperty(HTMLElement.prototype, "text", {
283
+ /**
284
+ * Get unescaped text value of current node and its children.
285
+ * @return {string} text content
286
+ */
287
+ get: function () {
288
+ return decode(this.rawText);
289
+ },
290
+ enumerable: false,
291
+ configurable: true
292
+ });
293
+ Object.defineProperty(HTMLElement.prototype, "structuredText", {
294
+ /**
295
+ * Get structured Text (with '\n' etc.)
296
+ * @return {string} structured text
297
+ */
298
+ get: function () {
299
+ var currentBlock = [];
300
+ var blocks = [currentBlock];
301
+ function dfs(node) {
302
+ if (node.nodeType === type_1.default.ELEMENT_NODE) {
303
+ if (kBlockElements.has(node.rawTagName)) {
304
+ if (currentBlock.length > 0) {
305
+ blocks.push((currentBlock = []));
306
+ }
307
+ node.childNodes.forEach(dfs);
308
+ if (currentBlock.length > 0) {
309
+ blocks.push((currentBlock = []));
310
+ }
311
+ }
312
+ else {
313
+ node.childNodes.forEach(dfs);
314
+ }
315
+ }
316
+ else if (node.nodeType === type_1.default.TEXT_NODE) {
317
+ if (node.isWhitespace) {
318
+ // Whitespace node, postponed output
319
+ currentBlock.prependWhitespace = true;
320
+ }
321
+ else {
322
+ var text = node.trimmedText;
323
+ if (currentBlock.prependWhitespace) {
324
+ text = " ".concat(text);
325
+ currentBlock.prependWhitespace = false;
326
+ }
327
+ currentBlock.push(text);
328
+ }
329
+ }
330
+ }
331
+ dfs(this);
332
+ return blocks
333
+ .map(function (block) {
334
+ return block.join('').replace(/\s{2,}/g, ' '); // Normalize each line's whitespace
335
+ })
336
+ .join('\n')
337
+ .replace(/\s+$/, ''); // trimRight;
338
+ },
339
+ enumerable: false,
340
+ configurable: true
341
+ });
342
+ HTMLElement.prototype.toString = function () {
343
+ var tag = this.rawTagName;
344
+ if (tag) {
345
+ var attrs = this.rawAttrs ? " ".concat(this.rawAttrs) : '';
346
+ return this.voidTag.formatNode(tag, attrs, this.innerHTML);
347
+ }
348
+ return this.innerHTML;
349
+ };
350
+ Object.defineProperty(HTMLElement.prototype, "innerHTML", {
351
+ get: function () {
352
+ return this.childNodes
353
+ .map(function (child) {
354
+ return child.toString();
355
+ })
356
+ .join('');
357
+ },
358
+ set: function (content) {
359
+ var r = parse(content, this._parseOptions);
360
+ var nodes = r.childNodes.length ? r.childNodes : [new text_1.default(content, this)];
361
+ resetParent(nodes, this);
362
+ resetParent(this.childNodes, null);
363
+ this.childNodes = nodes;
364
+ },
365
+ enumerable: false,
366
+ configurable: true
367
+ });
368
+ HTMLElement.prototype.set_content = function (content, options) {
369
+ if (options === void 0) { options = {}; }
370
+ if (content instanceof node_1.default) {
371
+ content = [content];
372
+ }
373
+ else if (typeof content == 'string') {
374
+ options = __assign(__assign({}, this._parseOptions), options);
375
+ var r = parse(content, options);
376
+ content = r.childNodes.length ? r.childNodes : [new text_1.default(r.innerHTML, this)];
377
+ }
378
+ resetParent(this.childNodes, null);
379
+ resetParent(content, this);
380
+ this.childNodes = content;
381
+ return this;
382
+ };
383
+ HTMLElement.prototype.replaceWith = function () {
384
+ var _this = this;
385
+ var nodes = [];
386
+ for (var _i = 0; _i < arguments.length; _i++) {
387
+ nodes[_i] = arguments[_i];
388
+ }
389
+ var parent = this.parentNode;
390
+ var content = nodes
391
+ .map(function (node) {
392
+ if (node instanceof node_1.default) {
393
+ return [node];
394
+ }
395
+ else if (typeof node == 'string') {
396
+ var r = parse(node, _this._parseOptions);
397
+ return r.childNodes.length ? r.childNodes : [new text_1.default(node, _this)];
398
+ }
399
+ return [];
400
+ })
401
+ .flat();
402
+ var idx = parent.childNodes.findIndex(function (child) {
403
+ return child === _this;
404
+ });
405
+ resetParent([this], null);
406
+ parent.childNodes = __spreadArray(__spreadArray(__spreadArray([], parent.childNodes.slice(0, idx), true), resetParent(content, parent), true), parent.childNodes.slice(idx + 1), true);
407
+ return this;
408
+ };
409
+ Object.defineProperty(HTMLElement.prototype, "outerHTML", {
410
+ get: function () {
411
+ return this.toString();
412
+ },
413
+ enumerable: false,
414
+ configurable: true
415
+ });
416
+ /**
417
+ * Trim element from right (in block) after seeing pattern in a TextNode.
418
+ * @param {RegExp} pattern pattern to find
419
+ * @return {HTMLElement} reference to current node
420
+ */
421
+ HTMLElement.prototype.trimRight = function (pattern) {
422
+ for (var i = 0; i < this.childNodes.length; i++) {
423
+ var childNode = this.childNodes[i];
424
+ if (childNode.nodeType === type_1.default.ELEMENT_NODE) {
425
+ childNode.trimRight(pattern);
426
+ }
427
+ else {
428
+ var index = childNode.rawText.search(pattern);
429
+ if (index > -1) {
430
+ childNode.rawText = childNode.rawText.substr(0, index);
431
+ // trim all following nodes.
432
+ this.childNodes.length = i + 1;
433
+ }
434
+ }
435
+ }
436
+ return this;
437
+ };
438
+ Object.defineProperty(HTMLElement.prototype, "structure", {
439
+ /**
440
+ * Get DOM structure
441
+ * @return {string} structure
442
+ */
443
+ get: function () {
444
+ var res = [];
445
+ var indention = 0;
446
+ function write(str) {
447
+ res.push(' '.repeat(indention) + str);
448
+ }
449
+ function dfs(node) {
450
+ var idStr = node.id ? "#".concat(node.id) : '';
451
+ var classStr = node.classList.length ? ".".concat(node.classList.value.join('.')) : ''; // eslint-disable-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-call
452
+ write("".concat(node.rawTagName).concat(idStr).concat(classStr));
453
+ indention++;
454
+ node.childNodes.forEach(function (childNode) {
455
+ if (childNode.nodeType === type_1.default.ELEMENT_NODE) {
456
+ dfs(childNode);
457
+ }
458
+ else if (childNode.nodeType === type_1.default.TEXT_NODE) {
459
+ if (!childNode.isWhitespace) {
460
+ write('#text');
461
+ }
462
+ }
463
+ });
464
+ indention--;
465
+ }
466
+ dfs(this);
467
+ return res.join('\n');
468
+ },
469
+ enumerable: false,
470
+ configurable: true
471
+ });
472
+ /**
473
+ * Remove whitespaces in this sub tree.
474
+ * @return {HTMLElement} pointer to this
475
+ */
476
+ HTMLElement.prototype.removeWhitespace = function () {
477
+ var _this = this;
478
+ var o = 0;
479
+ this.childNodes.forEach(function (node) {
480
+ if (node.nodeType === type_1.default.TEXT_NODE) {
481
+ if (node.isWhitespace) {
482
+ return;
483
+ }
484
+ node.rawText = node.trimmedRawText;
485
+ }
486
+ else if (node.nodeType === type_1.default.ELEMENT_NODE) {
487
+ node.removeWhitespace();
488
+ }
489
+ _this.childNodes[o++] = node;
490
+ });
491
+ this.childNodes.length = o;
492
+ return this;
493
+ };
494
+ /**
495
+ * Query CSS selector to find matching nodes.
496
+ * @param {string} selector Simplified CSS selector
497
+ * @return {HTMLElement[]} matching elements
498
+ */
499
+ HTMLElement.prototype.querySelectorAll = function (selector) {
500
+ return (0, css_select_1.selectAll)(selector, this, {
501
+ xmlMode: true,
502
+ adapter: matcher_1.default,
503
+ });
504
+ };
505
+ /**
506
+ * Query CSS Selector to find matching node.
507
+ * @param {string} selector Simplified CSS selector
508
+ * @return {(HTMLElement|null)} matching node
509
+ */
510
+ HTMLElement.prototype.querySelector = function (selector) {
511
+ return (0, css_select_1.selectOne)(selector, this, {
512
+ xmlMode: true,
513
+ adapter: matcher_1.default,
514
+ });
515
+ };
516
+ /**
517
+ * find elements by their tagName
518
+ * @param {string} tagName the tagName of the elements to select
519
+ */
520
+ HTMLElement.prototype.getElementsByTagName = function (tagName) {
521
+ var upperCasedTagName = tagName.toUpperCase();
522
+ var re = [];
523
+ var stack = [];
524
+ var currentNodeReference = this;
525
+ var index = 0;
526
+ // index turns to undefined once the stack is empty and the first condition occurs
527
+ // which happens once all relevant children are searched through
528
+ while (index !== undefined) {
529
+ var child = void 0;
530
+ // make it work with sparse arrays
531
+ do {
532
+ child = currentNodeReference.childNodes[index++];
533
+ } while (index < currentNodeReference.childNodes.length && child === undefined);
534
+ // if the child does not exist we move on with the last provided index (which belongs to the parentNode)
535
+ if (child === undefined) {
536
+ currentNodeReference = currentNodeReference.parentNode;
537
+ index = stack.pop();
538
+ continue;
539
+ }
540
+ if (child.nodeType === type_1.default.ELEMENT_NODE) {
541
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName#syntax
542
+ if (tagName === '*' || child.tagName === upperCasedTagName)
543
+ re.push(child);
544
+ // if children are existing push the current status to the stack and keep searching for elements in the level below
545
+ if (child.childNodes.length > 0) {
546
+ stack.push(index);
547
+ currentNodeReference = child;
548
+ index = 0;
549
+ }
550
+ }
551
+ }
552
+ return re;
553
+ };
554
+ /**
555
+ * find element by it's id
556
+ * @param {string} id the id of the element to select
557
+ * @returns {HTMLElement | null} the element with the given id or null if not found
558
+ */
559
+ HTMLElement.prototype.getElementById = function (id) {
560
+ var stack = [];
561
+ var currentNodeReference = this;
562
+ var index = 0;
563
+ // index turns to undefined once the stack is empty and the first condition occurs
564
+ // which happens once all relevant children are searched through
565
+ while (index !== undefined) {
566
+ var child = void 0;
567
+ // make it work with sparse arrays
568
+ do {
569
+ child = currentNodeReference.childNodes[index++];
570
+ } while (index < currentNodeReference.childNodes.length && child === undefined);
571
+ // if the child does not exist we move on with the last provided index (which belongs to the parentNode)
572
+ if (child === undefined) {
573
+ currentNodeReference = currentNodeReference.parentNode;
574
+ index = stack.pop();
575
+ continue;
576
+ }
577
+ if (child.nodeType === type_1.default.ELEMENT_NODE) {
578
+ if (child.id === id) {
579
+ return child;
580
+ }
581
+ ;
582
+ // if children are existing push the current status to the stack and keep searching for elements in the level below
583
+ if (child.childNodes.length > 0) {
584
+ stack.push(index);
585
+ currentNodeReference = child;
586
+ index = 0;
587
+ }
588
+ }
589
+ }
590
+ return null;
591
+ };
592
+ /**
593
+ * traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
594
+ * @param selector a DOMString containing a selector list
595
+ * @returns {HTMLElement | null} the element with the given id or null if not found
596
+ */
597
+ HTMLElement.prototype.closest = function (selector) {
598
+ var mapChild = new Map();
599
+ var el = this;
600
+ var old = null;
601
+ function findOne(test, elems) {
602
+ var elem = null;
603
+ for (var i = 0, l = elems.length; i < l && !elem; i++) {
604
+ var el_1 = elems[i];
605
+ if (test(el_1)) {
606
+ elem = el_1;
607
+ }
608
+ else {
609
+ var child = mapChild.get(el_1);
610
+ if (child) {
611
+ elem = findOne(test, [child]);
612
+ }
613
+ }
614
+ }
615
+ return elem;
616
+ }
617
+ while (el) {
618
+ mapChild.set(el, old);
619
+ old = el;
620
+ el = el.parentNode;
621
+ }
622
+ el = this;
623
+ while (el) {
624
+ var e = (0, css_select_1.selectOne)(selector, el, {
625
+ xmlMode: true,
626
+ adapter: __assign(__assign({}, matcher_1.default), { getChildren: function (node) {
627
+ var child = mapChild.get(node);
628
+ return child && [child];
629
+ }, getSiblings: function (node) {
630
+ return [node];
631
+ }, findOne: findOne, findAll: function () {
632
+ return [];
633
+ } }),
634
+ });
635
+ if (e) {
636
+ return e;
637
+ }
638
+ el = el.parentNode;
639
+ }
640
+ return null;
641
+ };
642
+ /**
643
+ * Append a child node to childNodes
644
+ * @param {Node} node node to append
645
+ * @return {Node} node appended
646
+ */
647
+ HTMLElement.prototype.appendChild = function (node) {
648
+ // remove the node from it's parent
649
+ node.remove();
650
+ this.childNodes.push(node);
651
+ node.parentNode = this;
652
+ return node;
653
+ };
654
+ Object.defineProperty(HTMLElement.prototype, "firstChild", {
655
+ /**
656
+ * Get first child node
657
+ * @return {Node | undefined} first child node; or undefined if none
658
+ */
659
+ get: function () {
660
+ return this.childNodes[0];
661
+ },
662
+ enumerable: false,
663
+ configurable: true
664
+ });
665
+ Object.defineProperty(HTMLElement.prototype, "lastChild", {
666
+ /**
667
+ * Get last child node
668
+ * @return {Node | undefined} last child node; or undefined if none
669
+ */
670
+ get: function () {
671
+ return (0, back_1.default)(this.childNodes);
672
+ },
673
+ enumerable: false,
674
+ configurable: true
675
+ });
676
+ Object.defineProperty(HTMLElement.prototype, "attrs", {
677
+ /**
678
+ * Get attributes
679
+ * @access private
680
+ * @return {Object} parsed and unescaped attributes
681
+ */
682
+ get: function () {
683
+ if (this._attrs) {
684
+ return this._attrs;
685
+ }
686
+ this._attrs = {};
687
+ var attrs = this.rawAttributes;
688
+ for (var key in attrs) {
689
+ var val = attrs[key] || '';
690
+ this._attrs[key.toLowerCase()] = decode(val);
691
+ }
692
+ return this._attrs;
693
+ },
694
+ enumerable: false,
695
+ configurable: true
696
+ });
697
+ Object.defineProperty(HTMLElement.prototype, "attributes", {
698
+ get: function () {
699
+ var ret_attrs = {};
700
+ var attrs = this.rawAttributes;
701
+ for (var key in attrs) {
702
+ var val = attrs[key] || '';
703
+ ret_attrs[key] = decode(val);
704
+ }
705
+ return ret_attrs;
706
+ },
707
+ enumerable: false,
708
+ configurable: true
709
+ });
710
+ Object.defineProperty(HTMLElement.prototype, "rawAttributes", {
711
+ /**
712
+ * Get escaped (as-is) attributes
713
+ * @return {Object} parsed attributes
714
+ */
715
+ get: function () {
716
+ if (this._rawAttrs) {
717
+ return this._rawAttrs;
718
+ }
719
+ var attrs = {};
720
+ if (this.rawAttrs) {
721
+ var re = /([a-zA-Z()[\]#@$.?:][a-zA-Z0-9-_:()[\]#]*)(?:\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+))?/g;
722
+ var match = void 0;
723
+ while ((match = re.exec(this.rawAttrs))) {
724
+ var key = match[1];
725
+ var val = match[2] || null;
726
+ if (val && (val[0] === "'" || val[0] === "\""))
727
+ val = val.slice(1, val.length - 1);
728
+ attrs[key] = attrs[key] || val;
729
+ }
730
+ }
731
+ this._rawAttrs = attrs;
732
+ return attrs;
733
+ },
734
+ enumerable: false,
735
+ configurable: true
736
+ });
737
+ HTMLElement.prototype.removeAttribute = function (key) {
738
+ var _this = this;
739
+ var attrs = this.rawAttributes;
740
+ delete attrs[key];
741
+ // Update this.attribute
742
+ if (this._attrs) {
743
+ delete this._attrs[key];
744
+ }
745
+ // Update rawString
746
+ this.rawAttrs = Object.keys(attrs)
747
+ .map(function (name) {
748
+ var val = _this.quoteAttribute(attrs[name]);
749
+ if (val === 'null' || val === '""')
750
+ return name;
751
+ return "".concat(name, "=").concat(val);
752
+ })
753
+ .join(' ');
754
+ // Update this.id
755
+ if (key === 'id') {
756
+ this.id = '';
757
+ }
758
+ return this;
759
+ };
760
+ HTMLElement.prototype.hasAttribute = function (key) {
761
+ return key.toLowerCase() in this.attrs;
762
+ };
763
+ /**
764
+ * Get an attribute
765
+ * @return {string | undefined} value of the attribute; or undefined if not exist
766
+ */
767
+ HTMLElement.prototype.getAttribute = function (key) {
768
+ return this.attrs[key.toLowerCase()];
769
+ };
770
+ /**
771
+ * Set an attribute value to the HTMLElement
772
+ * @param {string} key The attribute name
773
+ * @param {string} value The value to set, or null / undefined to remove an attribute
774
+ */
775
+ HTMLElement.prototype.setAttribute = function (key, value) {
776
+ var _this = this;
777
+ if (arguments.length < 2) {
778
+ throw new Error("Failed to execute 'setAttribute' on 'Element'");
779
+ }
780
+ var k2 = key.toLowerCase();
781
+ var attrs = this.rawAttributes;
782
+ for (var k in attrs) {
783
+ if (k.toLowerCase() === k2) {
784
+ key = k;
785
+ break;
786
+ }
787
+ }
788
+ attrs[key] = String(value);
789
+ // update this.attrs
790
+ if (this._attrs) {
791
+ this._attrs[k2] = decode(attrs[key]);
792
+ }
793
+ // Update rawString
794
+ this.rawAttrs = Object.keys(attrs)
795
+ .map(function (name) {
796
+ var val = _this.quoteAttribute(attrs[name]);
797
+ if (val === 'null' || val === '""')
798
+ return name;
799
+ return "".concat(name, "=").concat(val);
800
+ })
801
+ .join(' ');
802
+ // Update this.id
803
+ if (key === 'id') {
804
+ this.id = value;
805
+ }
806
+ return this;
807
+ };
808
+ /**
809
+ * Replace all the attributes of the HTMLElement by the provided attributes
810
+ * @param {Attributes} attributes the new attribute set
811
+ */
812
+ HTMLElement.prototype.setAttributes = function (attributes) {
813
+ var _this = this;
814
+ // Invalidate current this.attributes
815
+ if (this._attrs) {
816
+ delete this._attrs;
817
+ }
818
+ // Invalidate current this.rawAttributes
819
+ if (this._rawAttrs) {
820
+ delete this._rawAttrs;
821
+ }
822
+ // Update rawString
823
+ this.rawAttrs = Object.keys(attributes)
824
+ .map(function (name) {
825
+ var val = attributes[name];
826
+ if (val === 'null' || val === '""')
827
+ return name;
828
+ return "".concat(name, "=").concat(_this.quoteAttribute(String(val)));
829
+ })
830
+ .join(' ');
831
+ return this;
832
+ };
833
+ HTMLElement.prototype.insertAdjacentHTML = function (where, html) {
834
+ var _a, _b, _c;
835
+ var _this = this;
836
+ if (arguments.length < 2) {
837
+ throw new Error('2 arguments required');
838
+ }
839
+ var p = parse(html, this._parseOptions);
840
+ if (where === 'afterend') {
841
+ var idx = this.parentNode.childNodes.findIndex(function (child) {
842
+ return child === _this;
843
+ });
844
+ resetParent(p.childNodes, this.parentNode);
845
+ (_a = this.parentNode.childNodes).splice.apply(_a, __spreadArray([idx + 1, 0], p.childNodes, false));
846
+ }
847
+ else if (where === 'afterbegin') {
848
+ resetParent(p.childNodes, this);
849
+ (_b = this.childNodes).unshift.apply(_b, p.childNodes);
850
+ }
851
+ else if (where === 'beforeend') {
852
+ p.childNodes.forEach(function (n) {
853
+ _this.appendChild(n);
854
+ });
855
+ }
856
+ else if (where === 'beforebegin') {
857
+ var idx = this.parentNode.childNodes.findIndex(function (child) {
858
+ return child === _this;
859
+ });
860
+ resetParent(p.childNodes, this.parentNode);
861
+ (_c = this.parentNode.childNodes).splice.apply(_c, __spreadArray([idx, 0], p.childNodes, false));
862
+ }
863
+ else {
864
+ throw new Error("The value provided ('".concat(where, "') is not one of 'beforebegin', 'afterbegin', 'beforeend', or 'afterend'"));
865
+ }
866
+ return this;
867
+ // if (!where || html === undefined || html === null) {
868
+ // return;
869
+ // }
870
+ };
871
+ Object.defineProperty(HTMLElement.prototype, "nextSibling", {
872
+ get: function () {
873
+ if (this.parentNode) {
874
+ var children = this.parentNode.childNodes;
875
+ var i = 0;
876
+ while (i < children.length) {
877
+ var child = children[i++];
878
+ if (this === child)
879
+ return children[i] || null;
880
+ }
881
+ return null;
882
+ }
883
+ },
884
+ enumerable: false,
885
+ configurable: true
886
+ });
887
+ Object.defineProperty(HTMLElement.prototype, "nextElementSibling", {
888
+ get: function () {
889
+ if (this.parentNode) {
890
+ var children = this.parentNode.childNodes;
891
+ var i = 0;
892
+ var find = false;
893
+ while (i < children.length) {
894
+ var child = children[i++];
895
+ if (find) {
896
+ if (child instanceof HTMLElement) {
897
+ return child || null;
898
+ }
899
+ }
900
+ else if (this === child) {
901
+ find = true;
902
+ }
903
+ }
904
+ return null;
905
+ }
906
+ },
907
+ enumerable: false,
908
+ configurable: true
909
+ });
910
+ Object.defineProperty(HTMLElement.prototype, "previousSibling", {
911
+ get: function () {
912
+ if (this.parentNode) {
913
+ var children = this.parentNode.childNodes;
914
+ var i = children.length;
915
+ while (i > 0) {
916
+ var child = children[--i];
917
+ if (this === child)
918
+ return children[i - 1] || null;
919
+ }
920
+ return null;
921
+ }
922
+ },
923
+ enumerable: false,
924
+ configurable: true
925
+ });
926
+ Object.defineProperty(HTMLElement.prototype, "previousElementSibling", {
927
+ get: function () {
928
+ if (this.parentNode) {
929
+ var children = this.parentNode.childNodes;
930
+ var i = children.length;
931
+ var find = false;
932
+ while (i > 0) {
933
+ var child = children[--i];
934
+ if (find) {
935
+ if (child instanceof HTMLElement) {
936
+ return child || null;
937
+ }
938
+ }
939
+ else if (this === child) {
940
+ find = true;
941
+ }
942
+ }
943
+ return null;
944
+ }
945
+ },
946
+ enumerable: false,
947
+ configurable: true
948
+ });
949
+ Object.defineProperty(HTMLElement.prototype, "classNames", {
950
+ get: function () {
951
+ return this.classList.toString();
952
+ },
953
+ enumerable: false,
954
+ configurable: true
955
+ });
956
+ /**
957
+ * Clone this Node
958
+ */
959
+ HTMLElement.prototype.clone = function () {
960
+ return parse(this.toString(), this._parseOptions).firstChild;
961
+ };
962
+ return HTMLElement;
963
+ }(node_1.default));
964
+ exports.default = HTMLElement;
965
+ // https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
966
+ var kMarkupPattern = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][-.:0-9_a-zA-Z]*)((?:\s+[^>]*?(?:(?:'[^']*')|(?:"[^"]*"))?)*)\s*(\/?)>/g;
967
+ var kAttributePattern = /(?:^|\s)(id|class)\s*=\s*((?:'[^']*')|(?:"[^"]*")|\S+)/gi;
968
+ var kElementsClosedByOpening = {
969
+ li: { li: true, LI: true },
970
+ LI: { li: true, LI: true },
971
+ p: { p: true, div: true, P: true, DIV: true },
972
+ P: { p: true, div: true, P: true, DIV: true },
973
+ b: { div: true, DIV: true },
974
+ B: { div: true, DIV: true },
975
+ td: { td: true, th: true, TD: true, TH: true },
976
+ TD: { td: true, th: true, TD: true, TH: true },
977
+ th: { td: true, th: true, TD: true, TH: true },
978
+ TH: { td: true, th: true, TD: true, TH: true },
979
+ h1: { h1: true, H1: true },
980
+ H1: { h1: true, H1: true },
981
+ h2: { h2: true, H2: true },
982
+ H2: { h2: true, H2: true },
983
+ h3: { h3: true, H3: true },
984
+ H3: { h3: true, H3: true },
985
+ h4: { h4: true, H4: true },
986
+ H4: { h4: true, H4: true },
987
+ h5: { h5: true, H5: true },
988
+ H5: { h5: true, H5: true },
989
+ h6: { h6: true, H6: true },
990
+ H6: { h6: true, H6: true },
991
+ };
992
+ var kElementsClosedByClosing = {
993
+ li: { ul: true, ol: true, UL: true, OL: true },
994
+ LI: { ul: true, ol: true, UL: true, OL: true },
995
+ a: { div: true, DIV: true },
996
+ A: { div: true, DIV: true },
997
+ b: { div: true, DIV: true },
998
+ B: { div: true, DIV: true },
999
+ i: { div: true, DIV: true },
1000
+ I: { div: true, DIV: true },
1001
+ p: { div: true, DIV: true },
1002
+ P: { div: true, DIV: true },
1003
+ td: { tr: true, table: true, TR: true, TABLE: true },
1004
+ TD: { tr: true, table: true, TR: true, TABLE: true },
1005
+ th: { tr: true, table: true, TR: true, TABLE: true },
1006
+ TH: { tr: true, table: true, TR: true, TABLE: true },
1007
+ };
1008
+ var frameflag = 'documentfragmentcontainer';
1009
+ /**
1010
+ * Parses HTML and returns a root element
1011
+ * Parse a chuck of HTML source.
1012
+ * @param {string} data html
1013
+ * @return {HTMLElement} root element
1014
+ */
1015
+ function base_parse(data, options) {
1016
+ var _a, _b;
1017
+ if (options === void 0) { options = {}; }
1018
+ var voidTag = new void_tag_1.default((_a = options === null || options === void 0 ? void 0 : options.voidTag) === null || _a === void 0 ? void 0 : _a.closingSlash, (_b = options === null || options === void 0 ? void 0 : options.voidTag) === null || _b === void 0 ? void 0 : _b.tags);
1019
+ var elements = options.blockTextElements || {
1020
+ script: true,
1021
+ noscript: true,
1022
+ style: true,
1023
+ pre: true,
1024
+ };
1025
+ var element_names = Object.keys(elements);
1026
+ var kBlockTextElements = element_names.map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
1027
+ var kIgnoreElements = element_names.filter(function (it) { return Boolean(elements[it]); }).map(function (it) { return new RegExp("^".concat(it, "$"), 'i'); });
1028
+ function element_should_be_ignore(tag) {
1029
+ return kIgnoreElements.some(function (it) { return it.test(tag); });
1030
+ }
1031
+ function is_block_text_element(tag) {
1032
+ return kBlockTextElements.some(function (it) { return it.test(tag); });
1033
+ }
1034
+ var createRange = function (startPos, endPos) { return [startPos - frameFlagOffset, endPos - frameFlagOffset]; };
1035
+ var root = new HTMLElement(null, {}, '', null, [0, data.length], voidTag, options);
1036
+ var currentParent = root;
1037
+ var stack = [root];
1038
+ var lastTextPos = -1;
1039
+ var noNestedTagIndex = undefined;
1040
+ var match;
1041
+ // https://github.com/taoqf/node-html-parser/issues/38
1042
+ data = "<".concat(frameflag, ">").concat(data, "</").concat(frameflag, ">");
1043
+ var lowerCaseTagName = options.lowerCaseTagName, fixNestedATags = options.fixNestedATags;
1044
+ var dataEndPos = data.length - (frameflag.length + 2);
1045
+ var frameFlagOffset = frameflag.length + 2;
1046
+ while ((match = kMarkupPattern.exec(data))) {
1047
+ // Note: Object destructuring here consistently tests as higher performance than array destructuring
1048
+ // eslint-disable-next-line prefer-const
1049
+ var matchText = match[0], leadingSlash = match[1], tagName = match[2], attributes = match[3], closingSlash = match[4];
1050
+ var matchLength = matchText.length;
1051
+ var tagStartPos = kMarkupPattern.lastIndex - matchLength;
1052
+ var tagEndPos = kMarkupPattern.lastIndex;
1053
+ // Add TextNode if content
1054
+ if (lastTextPos > -1) {
1055
+ if (lastTextPos + matchLength < tagEndPos) {
1056
+ var text = data.substring(lastTextPos, tagStartPos);
1057
+ currentParent.appendChild(new text_1.default(text, currentParent, createRange(lastTextPos, tagStartPos)));
1058
+ }
1059
+ }
1060
+ lastTextPos = kMarkupPattern.lastIndex;
1061
+ // https://github.com/taoqf/node-html-parser/issues/38
1062
+ // Skip frameflag node
1063
+ if (tagName === frameflag)
1064
+ continue;
1065
+ // Handle comments
1066
+ if (matchText[1] === '!') {
1067
+ if (options.comment) {
1068
+ // Only keep what is in between <!-- and -->
1069
+ var text = data.substring(tagStartPos + 4, tagEndPos - 3);
1070
+ currentParent.appendChild(new comment_1.default(text, currentParent, createRange(tagStartPos, tagEndPos)));
1071
+ }
1072
+ continue;
1073
+ }
1074
+ /* -- Handle tag matching -- */
1075
+ // Fix tag casing if necessary
1076
+ if (lowerCaseTagName)
1077
+ tagName = tagName.toLowerCase();
1078
+ // Handle opening tags (ie. <this> not </that>)
1079
+ if (!leadingSlash) {
1080
+ /* Populate attributes */
1081
+ var attrs = {};
1082
+ for (var attMatch = void 0; (attMatch = kAttributePattern.exec(attributes));) {
1083
+ var key = attMatch[1], val = attMatch[2];
1084
+ var isQuoted = val[0] === "'" || val[0] === "\"";
1085
+ attrs[key.toLowerCase()] = isQuoted ? val.slice(1, val.length - 1) : val;
1086
+ }
1087
+ var parentTagName = currentParent.rawTagName;
1088
+ if (!closingSlash && kElementsClosedByOpening[parentTagName]) {
1089
+ if (kElementsClosedByOpening[parentTagName][tagName]) {
1090
+ stack.pop();
1091
+ currentParent = (0, back_1.default)(stack);
1092
+ }
1093
+ }
1094
+ // Prevent nested A tags by terminating the last A and starting a new one : see issue #144
1095
+ if (fixNestedATags && (tagName === 'a' || tagName === 'A')) {
1096
+ if (noNestedTagIndex !== undefined) {
1097
+ stack.splice(noNestedTagIndex);
1098
+ currentParent = (0, back_1.default)(stack);
1099
+ }
1100
+ noNestedTagIndex = stack.length;
1101
+ }
1102
+ var tagEndPos_1 = kMarkupPattern.lastIndex;
1103
+ var tagStartPos_1 = tagEndPos_1 - matchLength;
1104
+ currentParent = currentParent.appendChild(
1105
+ // Initialize range (end position updated later for closed tags)
1106
+ new HTMLElement(tagName, attrs, attributes.slice(1), null, createRange(tagStartPos_1, tagEndPos_1), voidTag, options));
1107
+ stack.push(currentParent);
1108
+ if (is_block_text_element(tagName)) {
1109
+ // Find closing tag
1110
+ var closeMarkup = "</".concat(tagName, ">");
1111
+ var closeIndex = lowerCaseTagName
1112
+ ? data.toLocaleLowerCase().indexOf(closeMarkup, kMarkupPattern.lastIndex)
1113
+ : data.indexOf(closeMarkup, kMarkupPattern.lastIndex);
1114
+ var textEndPos = closeIndex === -1 ? dataEndPos : closeIndex;
1115
+ if (element_should_be_ignore(tagName)) {
1116
+ var text = data.substring(tagEndPos_1, textEndPos);
1117
+ if (text.length > 0 && /\S/.test(text)) {
1118
+ currentParent.appendChild(new text_1.default(text, currentParent, createRange(tagEndPos_1, textEndPos)));
1119
+ }
1120
+ }
1121
+ if (closeIndex === -1) {
1122
+ lastTextPos = kMarkupPattern.lastIndex = data.length + 1;
1123
+ }
1124
+ else {
1125
+ lastTextPos = kMarkupPattern.lastIndex = closeIndex + closeMarkup.length;
1126
+ // Cause to be treated as self-closing, because no close found
1127
+ leadingSlash = '/';
1128
+ }
1129
+ }
1130
+ }
1131
+ // Handle closing tags or self-closed elements (ie </tag> or <br>)
1132
+ if (leadingSlash || closingSlash || voidTag.isVoidElement(tagName)) {
1133
+ while (true) {
1134
+ if (noNestedTagIndex != null && (tagName === 'a' || tagName === 'A'))
1135
+ noNestedTagIndex = undefined;
1136
+ if (currentParent.rawTagName === tagName) {
1137
+ // Update range end for closed tag
1138
+ currentParent.range[1] = createRange(-1, Math.max(lastTextPos, tagEndPos))[1];
1139
+ stack.pop();
1140
+ currentParent = (0, back_1.default)(stack);
1141
+ break;
1142
+ }
1143
+ else {
1144
+ var parentTagName = currentParent.tagName;
1145
+ // Trying to close current tag, and move on
1146
+ if (kElementsClosedByClosing[parentTagName]) {
1147
+ if (kElementsClosedByClosing[parentTagName][tagName]) {
1148
+ stack.pop();
1149
+ currentParent = (0, back_1.default)(stack);
1150
+ continue;
1151
+ }
1152
+ }
1153
+ // Use aggressive strategy to handle unmatching markups.
1154
+ break;
1155
+ }
1156
+ }
1157
+ }
1158
+ }
1159
+ return stack;
1160
+ }
1161
+ exports.base_parse = base_parse;
1162
+ /**
1163
+ * Parses HTML and returns a root element
1164
+ * Parse a chuck of HTML source.
1165
+ */
1166
+ function parse(data, options) {
1167
+ if (options === void 0) { options = {}; }
1168
+ var stack = base_parse(data, options);
1169
+ var root = stack[0];
1170
+ var _loop_1 = function () {
1171
+ // Handle each error elements.
1172
+ var last = stack.pop();
1173
+ var oneBefore = (0, back_1.default)(stack);
1174
+ if (last.parentNode && last.parentNode.parentNode) {
1175
+ if (last.parentNode === oneBefore && last.tagName === oneBefore.tagName) {
1176
+ // Pair error case <h3> <h3> handle : Fixes to <h3> </h3>
1177
+ // this is wrong, becouse this will put the H3 outside the current right position which should be inside the current Html Element, see issue 152 for more info
1178
+ if (options.parseNoneClosedTags !== true) {
1179
+ oneBefore.removeChild(last);
1180
+ last.childNodes.forEach(function (child) {
1181
+ oneBefore.parentNode.appendChild(child);
1182
+ });
1183
+ stack.pop();
1184
+ }
1185
+ }
1186
+ else {
1187
+ // Single error <div> <h3> </div> handle: Just removes <h3>
1188
+ // Why remove? this is already a HtmlElement and the missing <H3> is already added in this case. see issue 152 for more info
1189
+ // eslint-disable-next-line no-lonely-if
1190
+ if (options.parseNoneClosedTags !== true) {
1191
+ oneBefore.removeChild(last);
1192
+ last.childNodes.forEach(function (child) {
1193
+ oneBefore.appendChild(child);
1194
+ });
1195
+ }
1196
+ }
1197
+ }
1198
+ else {
1199
+ // If it's final element just skip.
1200
+ }
1201
+ };
1202
+ while (stack.length > 1) {
1203
+ _loop_1();
1204
+ }
1205
+ // response.childNodes.forEach((node) => {
1206
+ // if (node instanceof HTMLElement) {
1207
+ // node.parentNode = null;
1208
+ // }
1209
+ // });
1210
+ return root;
1211
+ }
1212
+ exports.parse = parse;
1213
+ function resetParent(nodes, parent) {
1214
+ return nodes.map(function (node) {
1215
+ node.parentNode = parent;
1216
+ return node;
1217
+ });
1218
+ }