@remote-dom/polyfill 1.5.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +51 -3
  3. package/build/cjs/Attr.cjs +33 -4
  4. package/build/cjs/CharacterData.cjs +10 -0
  5. package/build/cjs/ChildNode.cjs +79 -13
  6. package/build/cjs/Comment.cjs +1 -1
  7. package/build/cjs/CustomElementRegistry.cjs +27 -2
  8. package/build/cjs/CustomEvent.cjs +2 -2
  9. package/build/cjs/Document.cjs +56 -32
  10. package/build/cjs/DocumentFragment.cjs +6 -2
  11. package/build/cjs/Element.cjs +68 -8
  12. package/build/cjs/Event.cjs +29 -27
  13. package/build/cjs/EventTarget.cjs +128 -58
  14. package/build/cjs/HTMLTemplateElement.cjs +1 -0
  15. package/build/cjs/MutationObserver.cjs +167 -1
  16. package/build/cjs/NamedNodeMap.cjs +82 -45
  17. package/build/cjs/Node.cjs +47 -11
  18. package/build/cjs/NodeList.cjs +9 -1
  19. package/build/cjs/ParentNode.cjs +319 -77
  20. package/build/cjs/SVGElement.cjs +1 -1
  21. package/build/cjs/Text.cjs +1 -1
  22. package/build/cjs/Window.cjs +131 -38
  23. package/build/cjs/attribute-reactions.cjs +20 -0
  24. package/build/cjs/constants.cjs +48 -24
  25. package/build/cjs/custom-element-reactions.cjs +52 -0
  26. package/build/cjs/dom-exception.cjs +15 -0
  27. package/build/cjs/hook-effects.cjs +51 -0
  28. package/build/cjs/names.cjs +61 -0
  29. package/build/cjs/selectors.cjs +213 -122
  30. package/build/cjs/serialization.cjs +168 -65
  31. package/build/cjs/shared.cjs +177 -28
  32. package/build/esm/Attr.mjs +34 -5
  33. package/build/esm/CharacterData.mjs +10 -0
  34. package/build/esm/ChildNode.mjs +76 -15
  35. package/build/esm/Comment.mjs +2 -2
  36. package/build/esm/CustomElementRegistry.mjs +27 -2
  37. package/build/esm/CustomEvent.mjs +2 -2
  38. package/build/esm/Document.mjs +60 -35
  39. package/build/esm/DocumentFragment.mjs +7 -3
  40. package/build/esm/Element.mjs +69 -9
  41. package/build/esm/Event.mjs +27 -27
  42. package/build/esm/EventTarget.mjs +130 -60
  43. package/build/esm/HTMLTemplateElement.mjs +2 -1
  44. package/build/esm/MutationObserver.mjs +166 -2
  45. package/build/esm/NamedNodeMap.mjs +83 -46
  46. package/build/esm/Node.mjs +48 -12
  47. package/build/esm/NodeList.mjs +9 -1
  48. package/build/esm/ParentNode.mjs +322 -81
  49. package/build/esm/SVGElement.mjs +2 -2
  50. package/build/esm/Text.mjs +2 -2
  51. package/build/esm/Window.mjs +132 -39
  52. package/build/esm/attribute-reactions.mjs +16 -0
  53. package/build/esm/constants.mjs +28 -23
  54. package/build/esm/custom-element-reactions.mjs +47 -0
  55. package/build/esm/dom-exception.mjs +11 -0
  56. package/build/esm/hook-effects.mjs +46 -0
  57. package/build/esm/names.mjs +54 -0
  58. package/build/esm/selectors.mjs +202 -124
  59. package/build/esm/serialization.mjs +169 -66
  60. package/build/esm/shared.mjs +173 -30
  61. package/build/esnext/Attr.esnext +45 -5
  62. package/build/esnext/CharacterData.esnext +10 -0
  63. package/build/esnext/ChildNode.esnext +84 -15
  64. package/build/esnext/Comment.esnext +2 -2
  65. package/build/esnext/CustomElementRegistry.esnext +42 -0
  66. package/build/esnext/CustomEvent.esnext +2 -2
  67. package/build/esnext/Document.esnext +69 -32
  68. package/build/esnext/DocumentFragment.esnext +6 -2
  69. package/build/esnext/Element.esnext +78 -9
  70. package/build/esnext/Event.esnext +36 -37
  71. package/build/esnext/EventTarget.esnext +133 -61
  72. package/build/esnext/HTMLTemplateElement.esnext +3 -1
  73. package/build/esnext/MutationObserver.esnext +163 -2
  74. package/build/esnext/NamedNodeMap.esnext +110 -42
  75. package/build/esnext/Node.esnext +50 -12
  76. package/build/esnext/NodeList.esnext +1 -1
  77. package/build/esnext/ParentNode.esnext +352 -79
  78. package/build/esnext/SVGElement.esnext +2 -2
  79. package/build/esnext/Text.esnext +2 -2
  80. package/build/esnext/Window.esnext +120 -16
  81. package/build/esnext/attribute-reactions.esnext +21 -0
  82. package/build/esnext/constants.esnext +34 -21
  83. package/build/esnext/custom-element-reactions.esnext +49 -0
  84. package/build/esnext/dom-exception.esnext +11 -0
  85. package/build/esnext/hook-effects.esnext +46 -0
  86. package/build/esnext/names.esnext +61 -0
  87. package/build/esnext/selectors.esnext +202 -100
  88. package/build/esnext/serialization.esnext +171 -48
  89. package/build/esnext/shared.esnext +181 -34
  90. package/build/tsconfig.tsbuildinfo +1 -1
  91. package/build/typescript/Attr.d.ts +6 -4
  92. package/build/typescript/Attr.d.ts.map +1 -1
  93. package/build/typescript/CharacterData.d.ts.map +1 -1
  94. package/build/typescript/ChildNode.d.ts +5 -0
  95. package/build/typescript/ChildNode.d.ts.map +1 -1
  96. package/build/typescript/ClipboardEvent.d.ts.map +1 -1
  97. package/build/typescript/Comment.d.ts +2 -2
  98. package/build/typescript/Comment.d.ts.map +1 -1
  99. package/build/typescript/CustomElementRegistry.d.ts +1 -0
  100. package/build/typescript/CustomElementRegistry.d.ts.map +1 -1
  101. package/build/typescript/CustomEvent.d.ts.map +1 -1
  102. package/build/typescript/Document.d.ts +10 -5
  103. package/build/typescript/Document.d.ts.map +1 -1
  104. package/build/typescript/DocumentFragment.d.ts +2 -1
  105. package/build/typescript/DocumentFragment.d.ts.map +1 -1
  106. package/build/typescript/Element.d.ts +16 -7
  107. package/build/typescript/Element.d.ts.map +1 -1
  108. package/build/typescript/ErrorEvent.d.ts.map +1 -1
  109. package/build/typescript/Event.d.ts +9 -10
  110. package/build/typescript/Event.d.ts.map +1 -1
  111. package/build/typescript/EventTarget.d.ts +20 -3
  112. package/build/typescript/EventTarget.d.ts.map +1 -1
  113. package/build/typescript/FocusEvent.d.ts.map +1 -1
  114. package/build/typescript/HTMLTemplateElement.d.ts.map +1 -1
  115. package/build/typescript/MutationObserver.d.ts +42 -0
  116. package/build/typescript/MutationObserver.d.ts.map +1 -1
  117. package/build/typescript/NamedNodeMap.d.ts +5 -3
  118. package/build/typescript/NamedNodeMap.d.ts.map +1 -1
  119. package/build/typescript/Node.d.ts +4 -3
  120. package/build/typescript/Node.d.ts.map +1 -1
  121. package/build/typescript/NodeList.d.ts +3 -2
  122. package/build/typescript/NodeList.d.ts.map +1 -1
  123. package/build/typescript/ParentNode.d.ts +29 -10
  124. package/build/typescript/ParentNode.d.ts.map +1 -1
  125. package/build/typescript/PromiseRejectionEvent.d.ts.map +1 -1
  126. package/build/typescript/SVGElement.d.ts +1 -1
  127. package/build/typescript/SVGElement.d.ts.map +1 -1
  128. package/build/typescript/Text.d.ts +1 -1
  129. package/build/typescript/Text.d.ts.map +1 -1
  130. package/build/typescript/ToggleEvent.d.ts.map +1 -1
  131. package/build/typescript/Window.d.ts +5 -1
  132. package/build/typescript/Window.d.ts.map +1 -1
  133. package/build/typescript/attribute-reactions.d.ts +4 -0
  134. package/build/typescript/attribute-reactions.d.ts.map +1 -0
  135. package/build/typescript/constants.d.ts +27 -18
  136. package/build/typescript/constants.d.ts.map +1 -1
  137. package/build/typescript/custom-element-reactions.d.ts +6 -0
  138. package/build/typescript/custom-element-reactions.d.ts.map +1 -0
  139. package/build/typescript/dom-exception.d.ts +2 -0
  140. package/build/typescript/dom-exception.d.ts.map +1 -0
  141. package/build/typescript/extensions.d.ts +4 -0
  142. package/build/typescript/extensions.d.ts.map +1 -0
  143. package/build/typescript/hook-effects.d.ts +6 -0
  144. package/build/typescript/hook-effects.d.ts.map +1 -0
  145. package/build/typescript/hooks.d.ts +3 -3
  146. package/build/typescript/hooks.d.ts.map +1 -1
  147. package/build/typescript/index.d.ts +1 -0
  148. package/build/typescript/index.d.ts.map +1 -1
  149. package/build/typescript/names.d.ts +11 -0
  150. package/build/typescript/names.d.ts.map +1 -0
  151. package/build/typescript/selectors.d.ts +21 -22
  152. package/build/typescript/selectors.d.ts.map +1 -1
  153. package/build/typescript/serialization.d.ts.map +1 -1
  154. package/build/typescript/shared.d.ts +10 -0
  155. package/build/typescript/shared.d.ts.map +1 -1
  156. package/build/typescript/tests/ChildNode.test.d.ts +2 -0
  157. package/build/typescript/tests/ChildNode.test.d.ts.map +1 -0
  158. package/build/typescript/tests/MutationObserver.test.d.ts +2 -0
  159. package/build/typescript/tests/MutationObserver.test.d.ts.map +1 -0
  160. package/build/typescript/tests/adopt-inserted-subtrees.test.d.ts +2 -0
  161. package/build/typescript/tests/adopt-inserted-subtrees.test.d.ts.map +1 -0
  162. package/build/typescript/tests/attr-mutation.test.d.ts +2 -0
  163. package/build/typescript/tests/attr-mutation.test.d.ts.map +1 -0
  164. package/build/typescript/tests/child-node-before-after.test.d.ts +2 -0
  165. package/build/typescript/tests/child-node-before-after.test.d.ts.map +1 -0
  166. package/build/typescript/tests/child-node-replace-with.test.d.ts +2 -0
  167. package/build/typescript/tests/child-node-replace-with.test.d.ts.map +1 -0
  168. package/build/typescript/tests/clone-import-namespaces.test.d.ts +2 -0
  169. package/build/typescript/tests/clone-import-namespaces.test.d.ts.map +1 -0
  170. package/build/typescript/tests/constants.test.d.ts +2 -0
  171. package/build/typescript/tests/constants.test.d.ts.map +1 -0
  172. package/build/typescript/tests/create-element-namespaces.test.d.ts +2 -0
  173. package/build/typescript/tests/create-element-namespaces.test.d.ts.map +1 -0
  174. package/build/typescript/tests/create-text-node.test.d.ts +2 -0
  175. package/build/typescript/tests/create-text-node.test.d.ts.map +1 -0
  176. package/build/typescript/tests/custom-element-reactions.test.d.ts +2 -0
  177. package/build/typescript/tests/custom-element-reactions.test.d.ts.map +1 -0
  178. package/build/typescript/tests/custom-element-registry.test.d.ts +2 -0
  179. package/build/typescript/tests/custom-element-registry.test.d.ts.map +1 -0
  180. package/build/typescript/tests/custom-event.test.d.ts +2 -0
  181. package/build/typescript/tests/custom-event.test.d.ts.map +1 -0
  182. package/build/typescript/tests/document-clone-import-contract.test.d.ts +2 -0
  183. package/build/typescript/tests/document-clone-import-contract.test.d.ts.map +1 -0
  184. package/build/typescript/tests/document.test.d.ts +2 -0
  185. package/build/typescript/tests/document.test.d.ts.map +1 -0
  186. package/build/typescript/tests/dom-mutation-selector-errors.test.d.ts +2 -0
  187. package/build/typescript/tests/dom-mutation-selector-errors.test.d.ts.map +1 -0
  188. package/build/typescript/tests/event-dispatch.test.d.ts +2 -0
  189. package/build/typescript/tests/event-dispatch.test.d.ts.map +1 -0
  190. package/build/typescript/tests/event-target.test.d.ts +2 -0
  191. package/build/typescript/tests/event-target.test.d.ts.map +1 -0
  192. package/build/typescript/tests/event.test.d.ts +2 -0
  193. package/build/typescript/tests/event.test.d.ts.map +1 -0
  194. package/build/typescript/tests/extensions.test.d.ts +2 -0
  195. package/build/typescript/tests/extensions.test.d.ts.map +1 -0
  196. package/build/typescript/tests/get-elements-by-tag-name.test.d.ts +2 -0
  197. package/build/typescript/tests/get-elements-by-tag-name.test.d.ts.map +1 -0
  198. package/build/typescript/tests/getElementsByClassName.test.d.ts +2 -0
  199. package/build/typescript/tests/getElementsByClassName.test.d.ts.map +1 -0
  200. package/build/typescript/tests/hooks.test.d.ts +2 -0
  201. package/build/typescript/tests/hooks.test.d.ts.map +1 -0
  202. package/build/typescript/tests/inner-html-parsing.test.d.ts +2 -0
  203. package/build/typescript/tests/inner-html-parsing.test.d.ts.map +1 -0
  204. package/build/typescript/tests/is-default-namespace.test.d.ts +2 -0
  205. package/build/typescript/tests/is-default-namespace.test.d.ts.map +1 -0
  206. package/build/typescript/tests/name-and-namespace-normalization.test.d.ts +2 -0
  207. package/build/typescript/tests/name-and-namespace-normalization.test.d.ts.map +1 -0
  208. package/build/typescript/tests/named-node-map.test.d.ts +2 -0
  209. package/build/typescript/tests/named-node-map.test.d.ts.map +1 -0
  210. package/build/typescript/tests/namespaced-attribute-reactions.test.d.ts +2 -0
  211. package/build/typescript/tests/namespaced-attribute-reactions.test.d.ts.map +1 -0
  212. package/build/typescript/tests/node.test.d.ts +2 -0
  213. package/build/typescript/tests/node.test.d.ts.map +1 -0
  214. package/build/typescript/tests/parent-node-mutation-return-values.test.d.ts +2 -0
  215. package/build/typescript/tests/parent-node-mutation-return-values.test.d.ts.map +1 -0
  216. package/build/typescript/tests/parent-node-mutation-validation.test.d.ts +2 -0
  217. package/build/typescript/tests/parent-node-mutation-validation.test.d.ts.map +1 -0
  218. package/build/typescript/tests/parent-node.test.d.ts +2 -0
  219. package/build/typescript/tests/parent-node.test.d.ts.map +1 -0
  220. package/build/typescript/tests/serialization-template.test.d.ts +2 -0
  221. package/build/typescript/tests/serialization-template.test.d.ts.map +1 -0
  222. package/build/typescript/tests/slot-attribute.test.d.ts +2 -0
  223. package/build/typescript/tests/slot-attribute.test.d.ts.map +1 -0
  224. package/build/typescript/tests/text-content.test.d.ts +2 -0
  225. package/build/typescript/tests/text-content.test.d.ts.map +1 -0
  226. package/build/typescript/tests/toggle-attribute.test.d.ts +2 -0
  227. package/build/typescript/tests/toggle-attribute.test.d.ts.map +1 -0
  228. package/build/typescript/tests/wide-tree-traversal.test.d.ts +2 -0
  229. package/build/typescript/tests/wide-tree-traversal.test.d.ts.map +1 -0
  230. package/build/typescript/tests/window-set-global.test.d.ts +2 -0
  231. package/build/typescript/tests/window-set-global.test.d.ts.map +1 -0
  232. package/package.json +1 -1
  233. package/source/Attr.ts +60 -8
  234. package/source/CharacterData.ts +13 -0
  235. package/source/ChildNode.ts +107 -14
  236. package/source/Comment.ts +2 -2
  237. package/source/CustomElementRegistry.ts +56 -0
  238. package/source/CustomEvent.ts +2 -2
  239. package/source/Document.ts +104 -38
  240. package/source/DocumentFragment.ts +12 -2
  241. package/source/Element.ts +129 -14
  242. package/source/Event.ts +34 -32
  243. package/source/EventTarget.ts +203 -79
  244. package/source/HTMLTemplateElement.ts +2 -1
  245. package/source/MutationObserver.ts +279 -1
  246. package/source/NamedNodeMap.ts +141 -60
  247. package/source/Node.ts +70 -14
  248. package/source/NodeList.ts +13 -3
  249. package/source/ParentNode.ts +500 -88
  250. package/source/SVGElement.ts +2 -2
  251. package/source/Text.ts +2 -2
  252. package/source/Window.ts +156 -17
  253. package/source/attribute-reactions.ts +32 -0
  254. package/source/constants.ts +40 -17
  255. package/source/custom-element-reactions.ts +64 -0
  256. package/source/dom-exception.ts +14 -0
  257. package/source/extensions.ts +4 -0
  258. package/source/hook-effects.ts +56 -0
  259. package/source/hooks.ts +11 -3
  260. package/source/index.ts +1 -0
  261. package/source/names.ts +94 -0
  262. package/source/selectors.ts +301 -138
  263. package/source/serialization.ts +224 -66
  264. package/source/shared.ts +269 -40
  265. package/source/tests/ChildNode.test.ts +178 -0
  266. package/source/tests/MutationObserver.test.ts +303 -0
  267. package/source/tests/adopt-inserted-subtrees.test.ts +584 -0
  268. package/source/tests/attr-mutation.test.ts +112 -0
  269. package/source/tests/child-node-before-after.test.ts +421 -0
  270. package/source/tests/child-node-replace-with.test.ts +251 -0
  271. package/source/tests/clone-import-namespaces.test.ts +365 -0
  272. package/source/tests/constants.test.ts +46 -0
  273. package/source/tests/create-element-namespaces.test.ts +142 -0
  274. package/source/tests/create-text-node.test.ts +38 -0
  275. package/source/tests/custom-element-reactions.test.ts +600 -0
  276. package/source/tests/custom-element-registry.test.ts +137 -0
  277. package/source/tests/custom-event.test.ts +26 -0
  278. package/source/tests/document-clone-import-contract.test.ts +77 -0
  279. package/source/tests/document.test.ts +122 -0
  280. package/source/tests/dom-mutation-selector-errors.test.ts +484 -0
  281. package/source/tests/event-dispatch.test.ts +270 -0
  282. package/source/tests/event-target.test.ts +208 -0
  283. package/source/tests/event.test.ts +98 -0
  284. package/source/tests/extensions.test.ts +159 -0
  285. package/source/tests/get-elements-by-tag-name.test.ts +79 -0
  286. package/source/tests/getElementsByClassName.test.ts +109 -0
  287. package/source/tests/hooks.test.ts +43 -0
  288. package/source/tests/inner-html-parsing.test.ts +461 -0
  289. package/source/tests/is-default-namespace.test.ts +111 -0
  290. package/source/tests/name-and-namespace-normalization.test.ts +319 -0
  291. package/source/tests/named-node-map.test.ts +122 -0
  292. package/source/tests/namespaced-attribute-reactions.test.ts +141 -0
  293. package/source/tests/node.test.ts +56 -0
  294. package/source/tests/parent-node-mutation-return-values.test.ts +63 -0
  295. package/source/tests/parent-node-mutation-validation.test.ts +362 -0
  296. package/source/tests/parent-node.test.ts +169 -0
  297. package/source/tests/selectors.test.ts +533 -22
  298. package/source/tests/serialization-template.test.ts +232 -0
  299. package/source/tests/slot-attribute.test.ts +133 -0
  300. package/source/tests/text-content.test.ts +440 -0
  301. package/source/tests/toggle-attribute.test.ts +113 -0
  302. package/source/tests/wide-tree-traversal.test.ts +699 -0
  303. package/source/tests/window-set-global.test.ts +321 -0
  304. package/tsconfig.json +1 -1
@@ -20,10 +20,80 @@ import { DocumentFragment } from './DocumentFragment.esnext';
20
20
  import { HTMLTemplateElement } from './HTMLTemplateElement.esnext';
21
21
  import { CustomElementRegistryImplementation } from './CustomElementRegistry.esnext';
22
22
  import { MutationObserver } from './MutationObserver.esnext';
23
- import { HOOKS } from './constants.esnext';
23
+ import { HOOKS, EXTENSIONS, HOOKS_DISPATCH } from './constants.esnext';
24
24
 
25
+ const EVENT_HANDLER_PROPERTIES = ["onerror", "onunhandledrejection"];
26
+ const POLYFILL_GLOBAL_PROPERTY = Symbol.for(
27
+ "@remote-dom/polyfill/global-property"
28
+ );
29
+ function windowPropertyDescriptors(window) {
30
+ return Object.getOwnPropertyDescriptors(window);
31
+ }
32
+ function eventTargetPropertyDescriptors(window) {
33
+ const properties = {};
34
+ for (const [property, descriptor] of Object.entries(
35
+ Object.getOwnPropertyDescriptors(EventTarget.prototype)
36
+ )) {
37
+ if (property !== "constructor" && typeof descriptor.value === "function") {
38
+ descriptor.value = markPolyfillGlobalProperty(
39
+ descriptor.value.bind(window)
40
+ );
41
+ properties[property] = descriptor;
42
+ }
43
+ }
44
+ return properties;
45
+ }
46
+ function eventHandlerPropertyDescriptors(window) {
47
+ const properties = {};
48
+ for (const property of EVENT_HANDLER_PROPERTIES) {
49
+ properties[property] = {
50
+ configurable: true,
51
+ enumerable: true,
52
+ get: markPolyfillGlobalProperty(() => window[property]),
53
+ set: markPolyfillGlobalProperty((handler) => {
54
+ window[property] = handler;
55
+ })
56
+ };
57
+ }
58
+ return properties;
59
+ }
60
+ function globalPropertyDescriptors(window) {
61
+ return Object.assign(
62
+ windowPropertyDescriptors(window),
63
+ eventTargetPropertyDescriptors(window),
64
+ eventHandlerPropertyDescriptors(window)
65
+ );
66
+ }
67
+ function markPolyfillGlobalProperty(value) {
68
+ Object.defineProperty(value, POLYFILL_GLOBAL_PROPERTY, { value: true });
69
+ return value;
70
+ }
71
+ function installMissingGlobalProperties(target, properties) {
72
+ for (const property of Reflect.ownKeys(properties)) {
73
+ const currentDescriptor = findPropertyDescriptor(target, property);
74
+ if (currentDescriptor == null || isPolyfillGlobalProperty(currentDescriptor)) {
75
+ Object.defineProperty(target, property, properties[property]);
76
+ }
77
+ }
78
+ }
79
+ function findPropertyDescriptor(target, property) {
80
+ let currentTarget = target;
81
+ while (currentTarget) {
82
+ const descriptor = Object.getOwnPropertyDescriptor(currentTarget, property);
83
+ if (descriptor) return descriptor;
84
+ currentTarget = Object.getPrototypeOf(currentTarget);
85
+ }
86
+ return void 0;
87
+ }
88
+ function isPolyfillGlobalProperty(descriptor) {
89
+ return [descriptor.value, descriptor.get, descriptor.set].some(
90
+ (value) => typeof value === "function" && value[POLYFILL_GLOBAL_PROPERTY] === true
91
+ );
92
+ }
25
93
  class Window extends EventTarget {
26
94
  [HOOKS] = {};
95
+ [EXTENSIONS] = [];
96
+ [HOOKS_DISPATCH] = createHooksDispatcher(this);
27
97
  name = "";
28
98
  window = this;
29
99
  parent = this;
@@ -57,6 +127,17 @@ class Window extends EventTarget {
57
127
  #currentOnErrorHandler = null;
58
128
  #currentOriginalOnErrorHandler = null;
59
129
  #currentOnUnhandledRejectionHandler = null;
130
+ static with(...extensions) {
131
+ const BaseWindow = this;
132
+ return class ExtendedWindow extends BaseWindow {
133
+ constructor() {
134
+ super();
135
+ for (const extension of extensions) {
136
+ installExtension(this, extension);
137
+ }
138
+ }
139
+ };
140
+ }
60
141
  get onerror() {
61
142
  return this.#currentOriginalOnErrorHandler;
62
143
  }
@@ -102,18 +183,26 @@ class Window extends EventTarget {
102
183
  }
103
184
  }
104
185
  static setGlobal(window) {
105
- const properties = Object.getOwnPropertyDescriptors(window);
186
+ const currentSelf = globalThis.self;
187
+ const currentWindow = globalThis.window;
188
+ const properties = windowPropertyDescriptors(window);
189
+ const missingProperties = Object.assign(
190
+ eventTargetPropertyDescriptors(window),
191
+ eventHandlerPropertyDescriptors(window)
192
+ );
106
193
  delete properties.self;
107
194
  Object.defineProperties(globalThis, properties);
108
- if (typeof globalThis.self === "undefined") {
195
+ installMissingGlobalProperties(globalThis, missingProperties);
196
+ if (typeof currentSelf === "undefined" || currentSelf === currentWindow && currentSelf !== globalThis) {
109
197
  Object.defineProperty(globalThis, "self", {
110
198
  value: window,
111
199
  configurable: true,
112
200
  writable: true,
113
201
  enumerable: true
114
202
  });
115
- } else {
116
- Object.defineProperties(self, properties);
203
+ } else if (currentSelf !== globalThis) {
204
+ Object.defineProperties(currentSelf, properties);
205
+ installMissingGlobalProperties(currentSelf, missingProperties);
117
206
  }
118
207
  }
119
208
  static setGlobalThis(window) {
@@ -122,18 +211,33 @@ class Window extends EventTarget {
122
211
  window[property] = globalThis;
123
212
  }
124
213
  }
125
- const properties = Object.getOwnPropertyDescriptors(window);
126
- const eventTargetPrototypeProperties = Object.getOwnPropertyDescriptors(
127
- EventTarget.prototype
128
- );
129
- for (const descriptor of Object.values(eventTargetPrototypeProperties)) {
130
- if (typeof descriptor.value === "function") {
131
- descriptor.value = descriptor.value.bind(window);
132
- }
133
- }
134
- Object.defineProperties(globalThis, properties);
135
- Object.defineProperties(globalThis, eventTargetPrototypeProperties);
214
+ Object.defineProperties(globalThis, globalPropertyDescriptors(window));
215
+ }
216
+ }
217
+ function installExtension(window, extension) {
218
+ window[EXTENSIONS].push(extension(window) ?? {});
219
+ }
220
+ function createHooksDispatcher(window) {
221
+ return {
222
+ createElement: dispatchHook.bind(null, window, "createElement"),
223
+ setAttribute: dispatchHook.bind(null, window, "setAttribute"),
224
+ removeAttribute: dispatchHook.bind(null, window, "removeAttribute"),
225
+ createText: dispatchHook.bind(null, window, "createText"),
226
+ setText: dispatchHook.bind(null, window, "setText"),
227
+ insertChild: dispatchHook.bind(null, window, "insertChild"),
228
+ removeChild: dispatchHook.bind(null, window, "removeChild"),
229
+ addEventListener: dispatchHook.bind(null, window, "addEventListener"),
230
+ removeEventListener: dispatchHook.bind(null, window, "removeEventListener")
231
+ };
232
+ }
233
+ function dispatchHook(window, name, ...args) {
234
+ for (const hooks2 of window[EXTENSIONS]) {
235
+ const hook = hooks2[name];
236
+ hook?.apply(hooks2, args);
136
237
  }
238
+ const hooks = window[HOOKS];
239
+ const legacyHook = hooks[name];
240
+ legacyHook?.apply(hooks, args);
137
241
  }
138
242
 
139
243
  export { Window };
@@ -0,0 +1,21 @@
1
+ import { enqueueCustomElementReaction } from './custom-element-reactions.esnext';
2
+
3
+ function enqueueAttributeReaction(element, localName, oldValue, newValue, namespace) {
4
+ const { observedAttributes } = element.constructor;
5
+ const { attributeChangedCallback } = element;
6
+ if (attributeChangedCallback == null || observedAttributes == null || !observedAttributes.includes(localName)) {
7
+ return;
8
+ }
9
+ enqueueCustomElementReaction(
10
+ element,
11
+ () => attributeChangedCallback.call(
12
+ element,
13
+ localName,
14
+ oldValue,
15
+ newValue,
16
+ namespace
17
+ )
18
+ );
19
+ }
20
+
21
+ export { enqueueAttributeReaction };
@@ -1,4 +1,5 @@
1
1
  const NAME = Symbol("name");
2
+ const PREFIX = Symbol("prefix");
2
3
  const VALUE = Symbol("value");
3
4
  const NS = Symbol("ns");
4
5
  const OWNER_ELEMENT = Symbol("owner");
@@ -8,33 +9,45 @@ const PREV = Symbol("prev");
8
9
  const NEXT = Symbol("next");
9
10
  const CHILD = Symbol("child");
10
11
  const PARENT = Symbol("parent");
12
+ const HOST = Symbol("host");
11
13
  const DATA = Symbol("data");
12
14
  const LISTENERS = Symbol("listeners");
13
15
  const IS_TRUSTED = Symbol("isTrusted");
14
16
  const PATH = Symbol("path");
15
17
  const STOP_IMMEDIATE_PROPAGATION = Symbol("stop_immediate_propagation");
18
+ const DISPATCHING = Symbol("dispatching");
16
19
  const CONTENT = Symbol("content");
17
20
  const HOOKS = Symbol("hooks");
21
+ const EXTENSIONS = Symbol("extensions");
22
+ const HOOKS_DISPATCH = Symbol("hooks_dispatch");
18
23
  const IS_CONNECTED = Symbol("is_connected");
19
- var NodeType = /* @__PURE__ */ ((NodeType2) => {
20
- NodeType2[NodeType2["NODE"] = 0] = "NODE";
21
- NodeType2[NodeType2["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
22
- NodeType2[NodeType2["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
23
- NodeType2[NodeType2["TEXT_NODE"] = 3] = "TEXT_NODE";
24
- NodeType2[NodeType2["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
25
- NodeType2[NodeType2["ENTITY_REFERENCE_NODE"] = 5] = "ENTITY_REFERENCE_NODE";
26
- NodeType2[NodeType2["ENTITY_NODE"] = 6] = "ENTITY_NODE";
27
- NodeType2[NodeType2["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
28
- NodeType2[NodeType2["COMMENT_NODE"] = 8] = "COMMENT_NODE";
29
- NodeType2[NodeType2["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
30
- NodeType2[NodeType2["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
31
- NodeType2[NodeType2["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
32
- return NodeType2;
33
- })(NodeType || {});
34
- var NamespaceURI = /* @__PURE__ */ ((NamespaceURI2) => {
35
- NamespaceURI2["XHTML"] = "http://www.w3.org/1999/xhtml";
36
- NamespaceURI2["SVG"] = "http://www.w3.org/2000/svg";
37
- return NamespaceURI2;
38
- })(NamespaceURI || {});
24
+ const CREATE_ELEMENT = Symbol("create_element");
25
+ const NODE_TYPE_NODE = 0;
26
+ const NODE_TYPE_ELEMENT = 1;
27
+ const NODE_TYPE_ATTRIBUTE = 2;
28
+ const NODE_TYPE_TEXT = 3;
29
+ const NODE_TYPE_COMMENT = 8;
30
+ const NODE_TYPE_DOCUMENT = 9;
31
+ const NODE_TYPE_DOCUMENT_TYPE = 10;
32
+ const NODE_TYPE_DOCUMENT_FRAGMENT = 11;
33
+ const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
34
+ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
35
+ const XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
36
+ const XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
37
+ function splitOnASCIIWhitespace(value) {
38
+ return value.split(/[\t\n\f\r ]+/).filter(Boolean);
39
+ }
40
+ function asciiLowercase(value) {
41
+ return value.replace(
42
+ /[A-Z]/g,
43
+ (character) => String.fromCharCode(character.charCodeAt(0) + 32)
44
+ );
45
+ }
46
+ function asciiUppercase(value) {
47
+ return value.replace(
48
+ /[a-z]/g,
49
+ (character) => String.fromCharCode(character.charCodeAt(0) - 32)
50
+ );
51
+ }
39
52
 
40
- export { ATTRIBUTES, CHILD, CONTENT, DATA, HOOKS, IS_CONNECTED, IS_TRUSTED, LISTENERS, NAME, NEXT, NS, NamespaceURI, NodeType, OWNER_DOCUMENT, OWNER_ELEMENT, PARENT, PATH, PREV, STOP_IMMEDIATE_PROPAGATION, VALUE };
53
+ export { ATTRIBUTES, CHILD, CONTENT, CREATE_ELEMENT, DATA, DISPATCHING, EXTENSIONS, HOOKS, HOOKS_DISPATCH, HOST, HTML_NAMESPACE, IS_CONNECTED, IS_TRUSTED, LISTENERS, NAME, NEXT, NODE_TYPE_ATTRIBUTE, NODE_TYPE_COMMENT, NODE_TYPE_DOCUMENT, NODE_TYPE_DOCUMENT_FRAGMENT, NODE_TYPE_DOCUMENT_TYPE, NODE_TYPE_ELEMENT, NODE_TYPE_NODE, NODE_TYPE_TEXT, NS, OWNER_DOCUMENT, OWNER_ELEMENT, PARENT, PATH, PREFIX, PREV, STOP_IMMEDIATE_PROPAGATION, SVG_NAMESPACE, VALUE, XMLNS_NAMESPACE, XML_NAMESPACE, asciiLowercase, asciiUppercase, splitOnASCIIWhitespace };
@@ -0,0 +1,49 @@
1
+ const scopes = [];
2
+ const reactionsByTarget = /* @__PURE__ */ new WeakMap();
3
+ function enqueueCustomElementReaction(target, reaction) {
4
+ const reactions = reactionsByTarget.get(target);
5
+ if (reactions) reactions.push(reaction);
6
+ else reactionsByTarget.set(target, [reaction]);
7
+ scopes[scopes.length - 1].push(target);
8
+ }
9
+ function performWithCustomElementReactions(mutation) {
10
+ const scope = [];
11
+ scopes.push(scope);
12
+ let result;
13
+ try {
14
+ result = mutation();
15
+ } catch (error) {
16
+ scopes.pop();
17
+ try {
18
+ flushCustomElementReactions(scope);
19
+ } catch {
20
+ }
21
+ throw error;
22
+ }
23
+ scopes.pop();
24
+ flushCustomElementReactions(scope);
25
+ return result;
26
+ }
27
+ function flushCustomElementReactions(scope) {
28
+ let firstError;
29
+ let didThrow = false;
30
+ for (const target of scope) {
31
+ const reactions = reactionsByTarget.get(target);
32
+ if (!reactions) continue;
33
+ while (reactions.length > 0) {
34
+ const reaction = reactions.shift();
35
+ try {
36
+ reaction();
37
+ } catch (error) {
38
+ if (!didThrow) {
39
+ firstError = error;
40
+ didThrow = true;
41
+ }
42
+ }
43
+ }
44
+ reactionsByTarget.delete(target);
45
+ }
46
+ if (didThrow) throw firstError;
47
+ }
48
+
49
+ export { enqueueCustomElementReaction, performWithCustomElementReactions };
@@ -0,0 +1,11 @@
1
+ function createDOMException(message, name) {
2
+ const DOMExceptionConstructor = globalThis.DOMException;
3
+ if (typeof DOMExceptionConstructor === "function") {
4
+ return new DOMExceptionConstructor(message, name);
5
+ }
6
+ const error = new Error(message);
7
+ error.name = name;
8
+ return error;
9
+ }
10
+
11
+ export { createDOMException };
@@ -0,0 +1,46 @@
1
+ import { PARENT, HOST } from './constants.esnext';
2
+
3
+ const hookEffects = [];
4
+ const pendingPublications = [];
5
+ let isDispatchingHookEffects = false;
6
+ function performHookEffects(effects) {
7
+ for (const effect of effects) {
8
+ hookEffects.push(effect);
9
+ if (effect[1]) pendingPublications.push(effect[1]);
10
+ }
11
+ if (isDispatchingHookEffects) return;
12
+ isDispatchingHookEffects = true;
13
+ try {
14
+ let firstError;
15
+ let didThrow = false;
16
+ for (let index = 0; index < hookEffects.length; index++) {
17
+ const [run, publication] = hookEffects[index];
18
+ if (publication) {
19
+ pendingPublications.splice(pendingPublications.indexOf(publication), 1);
20
+ }
21
+ try {
22
+ run();
23
+ } catch (error) {
24
+ if (!didThrow) {
25
+ firstError = error;
26
+ didThrow = true;
27
+ }
28
+ }
29
+ }
30
+ if (didThrow) throw firstError;
31
+ } finally {
32
+ hookEffects.length = 0;
33
+ pendingPublications.length = 0;
34
+ isDispatchingHookEffects = false;
35
+ }
36
+ }
37
+ function isCoveredByPendingPublication(node) {
38
+ let current = node;
39
+ while (current) {
40
+ if (pendingPublications.includes(current)) return true;
41
+ current = current[PARENT] ?? current[HOST];
42
+ }
43
+ return false;
44
+ }
45
+
46
+ export { isCoveredByPendingPublication, performHookEffects };
@@ -0,0 +1,61 @@
1
+ import { XML_NAMESPACE, XMLNS_NAMESPACE } from './constants.esnext';
2
+ import { createDOMException } from './dom-exception.esnext';
3
+
4
+ const VALID_ELEMENT_LOCAL_NAME = /^(?:[A-Za-z][^\0\t\n\f\r\u0020/>]*|[:_\u0080-\u{10FFFF}][A-Za-z0-9-.:_\u0080-\u{10FFFF}]*)$/u;
5
+ const INVALID_ATTRIBUTE_LOCAL_NAME = /[\0\t\n\f\r />=]/u;
6
+ const INVALID_NAMESPACE_PREFIX = /[\0\t\n\f\r />]/u;
7
+ function normalizeNamespace(namespace) {
8
+ if (namespace == null) return null;
9
+ const normalized = String(namespace);
10
+ return normalized === "" ? null : normalized;
11
+ }
12
+ function validateElementLocalName(name) {
13
+ if (!VALID_ELEMENT_LOCAL_NAME.test(name)) {
14
+ throwInvalidCharacterError(name);
15
+ }
16
+ }
17
+ function validateAttributeLocalName(name) {
18
+ if (name === "" || INVALID_ATTRIBUTE_LOCAL_NAME.test(name)) {
19
+ throwInvalidCharacterError(name);
20
+ }
21
+ }
22
+ function validateAndExtractQualifiedName(namespaceValue, qualifiedNameValue, kind) {
23
+ const namespace = normalizeNamespace(namespaceValue);
24
+ const qualifiedName = String(qualifiedNameValue);
25
+ const separator = qualifiedName.indexOf(":");
26
+ const prefix = separator < 0 ? null : qualifiedName.slice(0, separator);
27
+ const localName = separator < 0 ? qualifiedName : qualifiedName.slice(separator + 1);
28
+ if (prefix != null && (prefix === "" || INVALID_NAMESPACE_PREFIX.test(prefix)) || (kind === "element" ? !VALID_ELEMENT_LOCAL_NAME.test(localName) : localName === "" || INVALID_ATTRIBUTE_LOCAL_NAME.test(localName))) {
29
+ throwInvalidCharacterError(qualifiedName);
30
+ }
31
+ if (prefix != null && namespace == null) {
32
+ throw createDOMException(
33
+ `A namespace is required for the prefix in "${qualifiedName}"`,
34
+ "NamespaceError"
35
+ );
36
+ }
37
+ if (prefix === "xml" && namespace !== XML_NAMESPACE) {
38
+ throw createDOMException(
39
+ `The xml prefix requires the XML namespace`,
40
+ "NamespaceError"
41
+ );
42
+ }
43
+ if ((qualifiedName === "xmlns" || prefix === "xmlns") && namespace !== XMLNS_NAMESPACE) {
44
+ throw createDOMException(
45
+ `The xmlns name requires the XMLNS namespace`,
46
+ "NamespaceError"
47
+ );
48
+ }
49
+ if (namespace === XMLNS_NAMESPACE && qualifiedName !== "xmlns" && prefix !== "xmlns") {
50
+ throw createDOMException(
51
+ `The XMLNS namespace requires the xmlns name or prefix`,
52
+ "NamespaceError"
53
+ );
54
+ }
55
+ return { namespace, qualifiedName, prefix, localName };
56
+ }
57
+ function throwInvalidCharacterError(name) {
58
+ throw createDOMException(`Invalid name: "${name}"`, "InvalidCharacterError");
59
+ }
60
+
61
+ export { normalizeNamespace, validateAndExtractQualifiedName, validateAttributeLocalName, validateElementLocalName };