@remote-dom/polyfill 1.0.6 → 1.2.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 (82) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/cjs/Attr.cjs +55 -0
  3. package/build/cjs/CharacterData.cjs +30 -0
  4. package/build/cjs/ChildNode.cjs +47 -0
  5. package/build/cjs/Comment.cjs +13 -0
  6. package/build/cjs/CustomElementRegistry.cjs +43 -0
  7. package/build/cjs/CustomEvent.cjs +30 -0
  8. package/build/cjs/Document.cjs +107 -0
  9. package/build/cjs/DocumentFragment.cjs +14 -0
  10. package/build/cjs/Element.cjs +99 -0
  11. package/build/cjs/Event.cjs +115 -0
  12. package/build/cjs/EventTarget.cjs +108 -0
  13. package/build/cjs/HTMLBodyElement.cjs +9 -0
  14. package/build/cjs/HTMLElement.cjs +9 -0
  15. package/build/cjs/HTMLHeadElement.cjs +9 -0
  16. package/build/cjs/HTMLHtmlElement.cjs +9 -0
  17. package/build/cjs/HTMLTemplateElement.cjs +28 -0
  18. package/build/cjs/MutationObserver.cjs +9 -0
  19. package/build/cjs/NamedNodeMap.cjs +123 -0
  20. package/build/cjs/Node.cjs +116 -0
  21. package/build/cjs/NodeList.cjs +11 -0
  22. package/build/cjs/ParentNode.cjs +131 -0
  23. package/build/cjs/SVGElement.cjs +21 -0
  24. package/build/cjs/Text.cjs +13 -0
  25. package/build/cjs/Window.cjs +78 -0
  26. package/build/cjs/constants.cjs +61 -0
  27. package/build/cjs/index.cjs +13 -0
  28. package/build/cjs/selectors.cjs +203 -0
  29. package/build/cjs/serialization.cjs +99 -0
  30. package/build/cjs/shared.cjs +65 -0
  31. package/build/esm/Attr.mjs +2 -3
  32. package/build/esm/CharacterData.mjs +3 -4
  33. package/build/esm/Document.mjs +2 -3
  34. package/build/esm/EventTarget.mjs +8 -4
  35. package/build/esm/NamedNodeMap.mjs +3 -4
  36. package/build/esm/Node.mjs +4 -1
  37. package/build/esm/ParentNode.mjs +3 -4
  38. package/build/esm/Window.mjs +2 -0
  39. package/build/esm/constants.mjs +2 -1
  40. package/build/esm/index.mjs +2 -1
  41. package/build/esnext/Attr.esnext +2 -3
  42. package/build/esnext/CharacterData.esnext +3 -4
  43. package/build/esnext/Document.esnext +2 -3
  44. package/build/esnext/EventTarget.esnext +18 -4
  45. package/build/esnext/NamedNodeMap.esnext +7 -4
  46. package/build/esnext/Node.esnext +4 -1
  47. package/build/esnext/ParentNode.esnext +3 -4
  48. package/build/esnext/Window.esnext +2 -0
  49. package/build/esnext/constants.esnext +2 -1
  50. package/build/esnext/index.esnext +2 -1
  51. package/build/tsconfig.tsbuildinfo +1 -1
  52. package/build/typescript/Attr.d.ts.map +1 -1
  53. package/build/typescript/CharacterData.d.ts.map +1 -1
  54. package/build/typescript/Document.d.ts.map +1 -1
  55. package/build/typescript/EventTarget.d.ts +7 -1
  56. package/build/typescript/EventTarget.d.ts.map +1 -1
  57. package/build/typescript/NamedNodeMap.d.ts.map +1 -1
  58. package/build/typescript/Node.d.ts +2 -1
  59. package/build/typescript/Node.d.ts.map +1 -1
  60. package/build/typescript/Window.d.ts +3 -0
  61. package/build/typescript/Window.d.ts.map +1 -1
  62. package/build/typescript/constants.d.ts +1 -0
  63. package/build/typescript/constants.d.ts.map +1 -1
  64. package/build/typescript/hooks.d.ts +0 -1
  65. package/build/typescript/hooks.d.ts.map +1 -1
  66. package/build/typescript/index.d.ts +3 -1
  67. package/build/typescript/index.d.ts.map +1 -1
  68. package/package.json +3 -2
  69. package/rollup.config.js +1 -1
  70. package/source/Attr.ts +2 -2
  71. package/source/CharacterData.ts +3 -4
  72. package/source/Document.ts +9 -3
  73. package/source/EventTarget.ts +19 -4
  74. package/source/NamedNodeMap.ts +14 -4
  75. package/source/Node.ts +5 -0
  76. package/source/ParentNode.ts +3 -3
  77. package/source/Window.ts +3 -0
  78. package/source/constants.ts +1 -0
  79. package/source/hooks.ts +0 -2
  80. package/source/index.ts +3 -1
  81. package/build/esm/hooks.mjs +0 -3
  82. package/build/esnext/hooks.esnext +0 -3
@@ -1,14 +1,19 @@
1
- import {hooks} from './hooks.ts';
2
- import {LISTENERS} from './constants.ts';
1
+ import {HOOKS, LISTENERS, OWNER_DOCUMENT} from './constants.ts';
3
2
  import {fireEvent, EventPhase} from './Event.ts';
4
3
  import {CAPTURE_MARKER, type Event} from './Event.ts';
5
4
  import type {ChildNode} from './ChildNode.ts';
5
+ import type {Document} from './Document.ts';
6
6
 
7
7
  const ONCE_LISTENERS = Symbol('onceListeners');
8
8
 
9
9
  export class EventTarget {
10
10
  [LISTENERS]?: Map<string, Set<EventListenerOrEventListenerObject>>;
11
11
  [ONCE_LISTENERS]?: WeakMap<EventListenerOrEventListenerObject, EventListener>;
12
+ /**
13
+ * Property set by entities that extend this class that are part of the DOM tree.
14
+ * @internal
15
+ */
16
+ [OWNER_DOCUMENT]?: Document;
12
17
 
13
18
  addEventListener(
14
19
  type: string,
@@ -67,7 +72,12 @@ export class EventTarget {
67
72
  );
68
73
 
69
74
  list.add(normalizedListener);
70
- hooks.addEventListener?.(this as any, type, listener, options);
75
+ this[OWNER_DOCUMENT]?.defaultView[HOOKS].addEventListener?.(
76
+ this as any,
77
+ type,
78
+ listener,
79
+ options,
80
+ );
71
81
  }
72
82
 
73
83
  removeEventListener(
@@ -134,7 +144,12 @@ function removeEventListener(
134
144
  if (list) {
135
145
  const deleted = list.delete(normalizedListener);
136
146
  if (deleted) {
137
- hooks.removeEventListener?.(this as any, type, listener, options);
147
+ this[OWNER_DOCUMENT]?.defaultView[HOOKS].removeEventListener?.(
148
+ this as any,
149
+ type,
150
+ listener,
151
+ options,
152
+ );
138
153
  }
139
154
  }
140
155
  }
@@ -1,5 +1,11 @@
1
- import {hooks} from './hooks.ts';
2
- import {CHILD, OWNER_ELEMENT, NS, NEXT, NamespaceURI} from './constants.ts';
1
+ import {
2
+ CHILD,
3
+ OWNER_ELEMENT,
4
+ NS,
5
+ NEXT,
6
+ NamespaceURI,
7
+ HOOKS,
8
+ } from './constants.ts';
3
9
  import type {Attr} from './Attr.ts';
4
10
  import type {Element} from './Element.ts';
5
11
 
@@ -60,7 +66,11 @@ export class NamedNodeMap {
60
66
  if (prev) prev[NEXT] = attr[NEXT];
61
67
  if (this[CHILD] === attr) this[CHILD] = attr[NEXT];
62
68
  updateElementAttribute(ownerElement, attr.name, attr.value, null);
63
- hooks.removeAttribute?.(ownerElement as any, name, namespaceURI);
69
+ ownerElement[HOOKS].removeAttribute?.(
70
+ ownerElement as any,
71
+ name,
72
+ namespaceURI,
73
+ );
64
74
  return attr;
65
75
  }
66
76
 
@@ -108,7 +118,7 @@ export class NamedNodeMap {
108
118
  attr.value,
109
119
  );
110
120
 
111
- hooks.setAttribute?.(
121
+ ownerElement[HOOKS].setAttribute?.(
112
122
  ownerElement as any,
113
123
  attr.name,
114
124
  attr.value,
package/source/Node.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  NEXT,
8
8
  NamespaceURI,
9
9
  NodeType,
10
+ HOOKS,
10
11
  } from './constants.ts';
11
12
  import type {Document} from './Document.ts';
12
13
  import type {ParentNode} from './ParentNode.ts';
@@ -28,6 +29,10 @@ export class Node extends EventTarget {
28
29
  [PREV]: Node | null = null;
29
30
  [NEXT]: Node | null = null;
30
31
 
32
+ protected get [HOOKS]() {
33
+ return this[OWNER_DOCUMENT].defaultView[HOOKS];
34
+ }
35
+
31
36
  get localName() {
32
37
  return this[NAME];
33
38
  }
@@ -1,4 +1,3 @@
1
- import {hooks} from './hooks.ts';
2
1
  import {
3
2
  CHILD,
4
3
  NEXT,
@@ -6,6 +5,7 @@ import {
6
5
  PARENT,
7
6
  OWNER_DOCUMENT,
8
7
  NodeType,
8
+ HOOKS,
9
9
  } from './constants.ts';
10
10
  import type {Node} from './Node.ts';
11
11
  import {ChildNode, toNode} from './ChildNode.ts';
@@ -66,7 +66,7 @@ export class ParentNode extends ChildNode {
66
66
  children.splice(children.indexOf(child), 1);
67
67
  }
68
68
 
69
- hooks.removeChild?.(this as any, child as any, childNodesIndex);
69
+ this[HOOKS].removeChild?.(this as any, child as any, childNodesIndex);
70
70
  }
71
71
 
72
72
  replaceChild(newChild: Node, oldChild: Node) {
@@ -153,6 +153,6 @@ export class ParentNode extends ChildNode {
153
153
  if (isElement) this.children.push(child);
154
154
  }
155
155
 
156
- hooks.insertChild?.(this as any, child as any, insertIndex);
156
+ this[HOOKS].insertChild?.(this as any, child as any, insertIndex);
157
157
  }
158
158
  }
package/source/Window.ts CHANGED
@@ -15,8 +15,11 @@ import {DocumentFragment} from './DocumentFragment.ts';
15
15
  import {HTMLTemplateElement} from './HTMLTemplateElement.ts';
16
16
  import {CustomElementRegistryImplementation} from './CustomElementRegistry.ts';
17
17
  import {MutationObserver} from './MutationObserver.ts';
18
+ import {HOOKS} from './constants.ts';
19
+ import type {Hooks} from './hooks.ts';
18
20
 
19
21
  export class Window extends EventTarget {
22
+ [HOOKS]: Partial<Hooks> = {};
20
23
  name = '';
21
24
  parent = this;
22
25
  self = this;
@@ -14,6 +14,7 @@ export const LISTENERS = Symbol('listeners');
14
14
  export const IS_TRUSTED = Symbol('isTrusted');
15
15
  export const CONTENT = Symbol('content');
16
16
  export const SLOT = Symbol('slot');
17
+ export const HOOKS = Symbol('hooks');
17
18
 
18
19
  // @TODO remove explicit values
19
20
  export const enum NodeType {
package/source/hooks.ts CHANGED
@@ -24,5 +24,3 @@ export interface Hooks {
24
24
  options?: boolean | EventListenerOptions,
25
25
  ): void;
26
26
  }
27
-
28
- export const hooks: Partial<Hooks> = {};
package/source/index.ts CHANGED
@@ -1,2 +1,4 @@
1
- export {hooks, type Hooks} from './hooks.ts';
1
+ export {type Hooks} from './hooks.ts';
2
+ export {HOOKS} from './constants.ts';
2
3
  export {Window} from './Window.ts';
4
+ export {HTMLElement} from './HTMLElement.ts';
@@ -1,3 +0,0 @@
1
- const hooks = {};
2
-
3
- export { hooks };
@@ -1,3 +0,0 @@
1
- const hooks = {};
2
-
3
- export { hooks };