@remote-dom/polyfill 0.0.0-preview-20240219211553

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 (142) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE.md +7 -0
  3. package/README.md +45 -0
  4. package/build/esm/Attr.mjs +52 -0
  5. package/build/esm/CharacterData.mjs +27 -0
  6. package/build/esm/ChildNode.mjs +42 -0
  7. package/build/esm/Comment.mjs +9 -0
  8. package/build/esm/CustomElementRegistry.mjs +33 -0
  9. package/build/esm/CustomEvent.mjs +26 -0
  10. package/build/esm/Document.mjs +89 -0
  11. package/build/esm/DocumentFragment.mjs +10 -0
  12. package/build/esm/Element.mjs +95 -0
  13. package/build/esm/Event.mjs +108 -0
  14. package/build/esm/EventTarget.mjs +99 -0
  15. package/build/esm/HTMLElement.mjs +5 -0
  16. package/build/esm/HTMLTemplateElement.mjs +24 -0
  17. package/build/esm/MutationObserver.mjs +5 -0
  18. package/build/esm/NamedNodeMap.mjs +121 -0
  19. package/build/esm/Node.mjs +100 -0
  20. package/build/esm/NodeList.mjs +7 -0
  21. package/build/esm/ParentNode.mjs +128 -0
  22. package/build/esm/SVGElement.mjs +17 -0
  23. package/build/esm/Text.mjs +9 -0
  24. package/build/esm/Window.mjs +66 -0
  25. package/build/esm/constants.mjs +39 -0
  26. package/build/esm/hooks.mjs +3 -0
  27. package/build/esm/index.mjs +2 -0
  28. package/build/esm/selectors.mjs +197 -0
  29. package/build/esm/serialization.mjs +92 -0
  30. package/build/esm/shared.mjs +55 -0
  31. package/build/esnext/Attr.esnext +57 -0
  32. package/build/esnext/CharacterData.esnext +27 -0
  33. package/build/esnext/ChildNode.esnext +47 -0
  34. package/build/esnext/Comment.esnext +9 -0
  35. package/build/esnext/CustomElementRegistry.esnext +34 -0
  36. package/build/esnext/CustomEvent.esnext +25 -0
  37. package/build/esnext/Document.esnext +86 -0
  38. package/build/esnext/DocumentFragment.esnext +10 -0
  39. package/build/esnext/Element.esnext +99 -0
  40. package/build/esnext/Event.esnext +109 -0
  41. package/build/esnext/EventTarget.esnext +99 -0
  42. package/build/esnext/HTMLElement.esnext +6 -0
  43. package/build/esnext/HTMLTemplateElement.esnext +26 -0
  44. package/build/esnext/MutationObserver.esnext +5 -0
  45. package/build/esnext/NamedNodeMap.esnext +131 -0
  46. package/build/esnext/Node.esnext +116 -0
  47. package/build/esnext/NodeList.esnext +7 -0
  48. package/build/esnext/ParentNode.esnext +138 -0
  49. package/build/esnext/SVGElement.esnext +17 -0
  50. package/build/esnext/Text.esnext +9 -0
  51. package/build/esnext/Window.esnext +59 -0
  52. package/build/esnext/constants.esnext +37 -0
  53. package/build/esnext/hooks.esnext +3 -0
  54. package/build/esnext/index.esnext +2 -0
  55. package/build/esnext/selectors.esnext +169 -0
  56. package/build/esnext/serialization.esnext +76 -0
  57. package/build/esnext/shared.esnext +59 -0
  58. package/build/tsconfig.tsbuildinfo +1 -0
  59. package/build/typescript/Attr.d.ts +24 -0
  60. package/build/typescript/Attr.d.ts.map +1 -0
  61. package/build/typescript/CharacterData.d.ts +10 -0
  62. package/build/typescript/CharacterData.d.ts.map +1 -0
  63. package/build/typescript/ChildNode.d.ts +10 -0
  64. package/build/typescript/ChildNode.d.ts.map +1 -0
  65. package/build/typescript/Comment.d.ts +7 -0
  66. package/build/typescript/Comment.d.ts.map +1 -0
  67. package/build/typescript/CustomElementRegistry.d.ts +9 -0
  68. package/build/typescript/CustomElementRegistry.d.ts.map +1 -0
  69. package/build/typescript/CustomEvent.d.ts +17 -0
  70. package/build/typescript/CustomEvent.d.ts.map +1 -0
  71. package/build/typescript/Document.d.ts +27 -0
  72. package/build/typescript/Document.d.ts.map +1 -0
  73. package/build/typescript/DocumentFragment.d.ts +8 -0
  74. package/build/typescript/DocumentFragment.d.ts.map +1 -0
  75. package/build/typescript/Element.d.ts +32 -0
  76. package/build/typescript/Element.d.ts.map +1 -0
  77. package/build/typescript/Event.d.ts +47 -0
  78. package/build/typescript/Event.d.ts.map +1 -0
  79. package/build/typescript/EventTarget.d.ts +12 -0
  80. package/build/typescript/EventTarget.d.ts.map +1 -0
  81. package/build/typescript/HTMLElement.d.ts +4 -0
  82. package/build/typescript/HTMLElement.d.ts.map +1 -0
  83. package/build/typescript/HTMLTemplateElement.d.ts +11 -0
  84. package/build/typescript/HTMLTemplateElement.d.ts.map +1 -0
  85. package/build/typescript/MutationObserver.d.ts +3 -0
  86. package/build/typescript/MutationObserver.d.ts.map +1 -0
  87. package/build/typescript/NamedNodeMap.d.ts +18 -0
  88. package/build/typescript/NamedNodeMap.d.ts.map +1 -0
  89. package/build/typescript/Node.d.ts +37 -0
  90. package/build/typescript/Node.d.ts.map +1 -0
  91. package/build/typescript/NodeList.d.ts +4 -0
  92. package/build/typescript/NodeList.d.ts.map +1 -0
  93. package/build/typescript/ParentNode.d.ts +18 -0
  94. package/build/typescript/ParentNode.d.ts.map +1 -0
  95. package/build/typescript/SVGElement.d.ts +7 -0
  96. package/build/typescript/SVGElement.d.ts.map +1 -0
  97. package/build/typescript/Text.d.ts +7 -0
  98. package/build/typescript/Text.d.ts.map +1 -0
  99. package/build/typescript/Window.d.ts +45 -0
  100. package/build/typescript/Window.d.ts.map +1 -0
  101. package/build/typescript/constants.d.ts +35 -0
  102. package/build/typescript/constants.d.ts.map +1 -0
  103. package/build/typescript/hooks.d.ts +13 -0
  104. package/build/typescript/hooks.d.ts.map +1 -0
  105. package/build/typescript/index.d.ts +3 -0
  106. package/build/typescript/index.d.ts.map +1 -0
  107. package/build/typescript/selectors.d.ts +32 -0
  108. package/build/typescript/selectors.d.ts.map +1 -0
  109. package/build/typescript/serialization.d.ts +6 -0
  110. package/build/typescript/serialization.d.ts.map +1 -0
  111. package/build/typescript/shared.d.ts +16 -0
  112. package/build/typescript/shared.d.ts.map +1 -0
  113. package/package.json +35 -0
  114. package/rollup.config.js +3 -0
  115. package/source/Attr.ts +70 -0
  116. package/source/CharacterData.ts +29 -0
  117. package/source/ChildNode.ts +45 -0
  118. package/source/Comment.ts +7 -0
  119. package/source/CustomElementRegistry.ts +52 -0
  120. package/source/CustomEvent.ts +30 -0
  121. package/source/Document.ts +112 -0
  122. package/source/DocumentFragment.ts +8 -0
  123. package/source/Element.ts +119 -0
  124. package/source/Event.ts +142 -0
  125. package/source/EventTarget.ts +139 -0
  126. package/source/HTMLElement.ts +3 -0
  127. package/source/HTMLTemplateElement.ts +28 -0
  128. package/source/MutationObserver.ts +3 -0
  129. package/source/NamedNodeMap.ts +156 -0
  130. package/source/Node.ts +139 -0
  131. package/source/NodeList.ts +5 -0
  132. package/source/ParentNode.ts +158 -0
  133. package/source/SVGElement.ts +16 -0
  134. package/source/Text.ts +7 -0
  135. package/source/Window.ts +64 -0
  136. package/source/constants.ts +37 -0
  137. package/source/hooks.ts +28 -0
  138. package/source/index.ts +2 -0
  139. package/source/selectors.ts +230 -0
  140. package/source/serialization.ts +110 -0
  141. package/source/shared.ts +80 -0
  142. package/tsconfig.json +10 -0
@@ -0,0 +1,80 @@
1
+ import {DATA, OWNER_DOCUMENT, ATTRIBUTES, NodeType} from './constants.ts';
2
+ import type {Document} from './Document.ts';
3
+ import type {DocumentFragment} from './DocumentFragment.ts';
4
+ import type {Node} from './Node.ts';
5
+ import type {Comment} from './Comment.ts';
6
+ import type {ParentNode} from './ParentNode.ts';
7
+ import type {Element} from './Element.ts';
8
+ import type {CharacterData} from './CharacterData.ts';
9
+ import type {Text} from './Text.ts';
10
+
11
+ export function isCharacterData(node: Node): node is CharacterData {
12
+ return DATA in node;
13
+ }
14
+
15
+ export function isTextNode(node: Node): node is Text {
16
+ return node.nodeType === NodeType.TEXT_NODE;
17
+ }
18
+
19
+ export function isCommentNode(node: Node): node is Comment {
20
+ return node.nodeType === NodeType.COMMENT_NODE;
21
+ }
22
+
23
+ export function isElementNode(node: Node): node is Element {
24
+ return node.nodeType === NodeType.ELEMENT_NODE;
25
+ }
26
+
27
+ export function isDocumentFragmentNode(node: Node): node is DocumentFragment {
28
+ return node.nodeType === NodeType.DOCUMENT_FRAGMENT_NODE;
29
+ }
30
+
31
+ export function isParentNode(node: Node): node is ParentNode {
32
+ return 'appendChild' in node;
33
+ }
34
+
35
+ export function cloneNode(
36
+ node: Node,
37
+ deep?: boolean,
38
+ document: Document = node.ownerDocument,
39
+ ): Node {
40
+ if (isTextNode(node)) {
41
+ return document.createTextNode(node.data);
42
+ } else if (isCommentNode(node)) {
43
+ return document.createComment(node.data);
44
+ } else if (isElementNode(node)) {
45
+ const cloned = document.createElement(node.localName);
46
+
47
+ if (node[ATTRIBUTES]) {
48
+ for (let i = 0; i < node[ATTRIBUTES].length; i++) {
49
+ const attribute = node[ATTRIBUTES].item(i)!;
50
+ cloned.setAttributeNS(
51
+ attribute.namespaceURI,
52
+ attribute.name,
53
+ attribute.value,
54
+ );
55
+ }
56
+ }
57
+
58
+ if (deep) {
59
+ for (const child of node.childNodes) {
60
+ cloned.appendChild(cloneNode(child, true, document));
61
+ }
62
+ }
63
+
64
+ return cloned;
65
+ } else if (isDocumentFragmentNode(node)) {
66
+ const fragment = document.createDocumentFragment();
67
+
68
+ if (deep) {
69
+ for (const child of (node as DocumentFragment).childNodes) {
70
+ fragment.appendChild(cloneNode(child, true, document));
71
+ }
72
+ }
73
+
74
+ return fragment;
75
+ } else {
76
+ const cloned = new (node.constructor as any)();
77
+ cloned[OWNER_DOCUMENT] = document;
78
+ return cloned;
79
+ }
80
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@quilted/typescript/project.json",
3
+ "compilerOptions": {
4
+ "rootDir": "source",
5
+ "outDir": "build/typescript"
6
+ },
7
+ "include": ["source"],
8
+ "exclude": [],
9
+ "references": []
10
+ }