@remote-dom/polyfill 0.0.1

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 (168) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +45 -0
  3. package/build/cjs/Attr.cjs +54 -0
  4. package/build/cjs/CharacterData.cjs +29 -0
  5. package/build/cjs/ChildNode.cjs +45 -0
  6. package/build/cjs/Comment.cjs +11 -0
  7. package/build/cjs/CustomElementRegistry.cjs +35 -0
  8. package/build/cjs/CustomEvent.cjs +28 -0
  9. package/build/cjs/Document.cjs +94 -0
  10. package/build/cjs/DocumentFragment.cjs +12 -0
  11. package/build/cjs/Element.cjs +81 -0
  12. package/build/cjs/Event.cjs +113 -0
  13. package/build/cjs/EventTarget.cjs +101 -0
  14. package/build/cjs/HTMLElement.cjs +7 -0
  15. package/build/cjs/HTMLTemplateElement.cjs +26 -0
  16. package/build/cjs/MutationObserver.cjs +7 -0
  17. package/build/cjs/NamedNodeMap.cjs +115 -0
  18. package/build/cjs/Node.cjs +102 -0
  19. package/build/cjs/NodeList.cjs +9 -0
  20. package/build/cjs/ParentNode.cjs +130 -0
  21. package/build/cjs/SVGElement.cjs +19 -0
  22. package/build/cjs/Text.cjs +11 -0
  23. package/build/cjs/Window.cjs +69 -0
  24. package/build/cjs/constants.cjs +57 -0
  25. package/build/cjs/hooks.cjs +5 -0
  26. package/build/cjs/index.cjs +10 -0
  27. package/build/cjs/selectors.cjs +203 -0
  28. package/build/cjs/serialization.cjs +96 -0
  29. package/build/cjs/shared.cjs +63 -0
  30. package/build/esm/Attr.mjs +52 -0
  31. package/build/esm/CharacterData.mjs +27 -0
  32. package/build/esm/ChildNode.mjs +42 -0
  33. package/build/esm/Comment.mjs +9 -0
  34. package/build/esm/CustomElementRegistry.mjs +33 -0
  35. package/build/esm/CustomEvent.mjs +26 -0
  36. package/build/esm/Document.mjs +89 -0
  37. package/build/esm/DocumentFragment.mjs +10 -0
  38. package/build/esm/Element.mjs +95 -0
  39. package/build/esm/Event.mjs +108 -0
  40. package/build/esm/EventTarget.mjs +99 -0
  41. package/build/esm/HTMLElement.mjs +5 -0
  42. package/build/esm/HTMLTemplateElement.mjs +24 -0
  43. package/build/esm/MutationObserver.mjs +5 -0
  44. package/build/esm/NamedNodeMap.mjs +121 -0
  45. package/build/esm/Node.mjs +100 -0
  46. package/build/esm/NodeList.mjs +7 -0
  47. package/build/esm/ParentNode.mjs +128 -0
  48. package/build/esm/SVGElement.mjs +17 -0
  49. package/build/esm/Text.mjs +9 -0
  50. package/build/esm/Window.mjs +66 -0
  51. package/build/esm/constants.mjs +39 -0
  52. package/build/esm/hooks.mjs +3 -0
  53. package/build/esm/index.mjs +2 -0
  54. package/build/esm/selectors.mjs +197 -0
  55. package/build/esm/serialization.mjs +92 -0
  56. package/build/esm/shared.mjs +55 -0
  57. package/build/esnext/Attr.esnext +57 -0
  58. package/build/esnext/CharacterData.esnext +27 -0
  59. package/build/esnext/ChildNode.esnext +47 -0
  60. package/build/esnext/Comment.esnext +9 -0
  61. package/build/esnext/CustomElementRegistry.esnext +34 -0
  62. package/build/esnext/CustomEvent.esnext +25 -0
  63. package/build/esnext/Document.esnext +86 -0
  64. package/build/esnext/DocumentFragment.esnext +10 -0
  65. package/build/esnext/Element.esnext +99 -0
  66. package/build/esnext/Event.esnext +109 -0
  67. package/build/esnext/EventTarget.esnext +99 -0
  68. package/build/esnext/HTMLElement.esnext +6 -0
  69. package/build/esnext/HTMLTemplateElement.esnext +26 -0
  70. package/build/esnext/MutationObserver.esnext +5 -0
  71. package/build/esnext/NamedNodeMap.esnext +131 -0
  72. package/build/esnext/Node.esnext +116 -0
  73. package/build/esnext/NodeList.esnext +7 -0
  74. package/build/esnext/ParentNode.esnext +138 -0
  75. package/build/esnext/SVGElement.esnext +17 -0
  76. package/build/esnext/Text.esnext +9 -0
  77. package/build/esnext/Window.esnext +59 -0
  78. package/build/esnext/constants.esnext +37 -0
  79. package/build/esnext/hooks.esnext +3 -0
  80. package/build/esnext/index.esnext +2 -0
  81. package/build/esnext/selectors.esnext +169 -0
  82. package/build/esnext/serialization.esnext +76 -0
  83. package/build/esnext/shared.esnext +59 -0
  84. package/build/tsconfig.tsbuildinfo +1 -0
  85. package/build/typescript/Attr.d.ts +24 -0
  86. package/build/typescript/Attr.d.ts.map +1 -0
  87. package/build/typescript/CharacterData.d.ts +10 -0
  88. package/build/typescript/CharacterData.d.ts.map +1 -0
  89. package/build/typescript/ChildNode.d.ts +10 -0
  90. package/build/typescript/ChildNode.d.ts.map +1 -0
  91. package/build/typescript/Comment.d.ts +7 -0
  92. package/build/typescript/Comment.d.ts.map +1 -0
  93. package/build/typescript/CustomElementRegistry.d.ts +9 -0
  94. package/build/typescript/CustomElementRegistry.d.ts.map +1 -0
  95. package/build/typescript/CustomEvent.d.ts +17 -0
  96. package/build/typescript/CustomEvent.d.ts.map +1 -0
  97. package/build/typescript/Document.d.ts +27 -0
  98. package/build/typescript/Document.d.ts.map +1 -0
  99. package/build/typescript/DocumentFragment.d.ts +8 -0
  100. package/build/typescript/DocumentFragment.d.ts.map +1 -0
  101. package/build/typescript/Element.d.ts +32 -0
  102. package/build/typescript/Element.d.ts.map +1 -0
  103. package/build/typescript/Event.d.ts +47 -0
  104. package/build/typescript/Event.d.ts.map +1 -0
  105. package/build/typescript/EventTarget.d.ts +12 -0
  106. package/build/typescript/EventTarget.d.ts.map +1 -0
  107. package/build/typescript/HTMLElement.d.ts +4 -0
  108. package/build/typescript/HTMLElement.d.ts.map +1 -0
  109. package/build/typescript/HTMLTemplateElement.d.ts +11 -0
  110. package/build/typescript/HTMLTemplateElement.d.ts.map +1 -0
  111. package/build/typescript/MutationObserver.d.ts +3 -0
  112. package/build/typescript/MutationObserver.d.ts.map +1 -0
  113. package/build/typescript/NamedNodeMap.d.ts +18 -0
  114. package/build/typescript/NamedNodeMap.d.ts.map +1 -0
  115. package/build/typescript/Node.d.ts +37 -0
  116. package/build/typescript/Node.d.ts.map +1 -0
  117. package/build/typescript/NodeList.d.ts +4 -0
  118. package/build/typescript/NodeList.d.ts.map +1 -0
  119. package/build/typescript/ParentNode.d.ts +18 -0
  120. package/build/typescript/ParentNode.d.ts.map +1 -0
  121. package/build/typescript/SVGElement.d.ts +7 -0
  122. package/build/typescript/SVGElement.d.ts.map +1 -0
  123. package/build/typescript/Text.d.ts +7 -0
  124. package/build/typescript/Text.d.ts.map +1 -0
  125. package/build/typescript/Window.d.ts +45 -0
  126. package/build/typescript/Window.d.ts.map +1 -0
  127. package/build/typescript/constants.d.ts +35 -0
  128. package/build/typescript/constants.d.ts.map +1 -0
  129. package/build/typescript/hooks.d.ts +13 -0
  130. package/build/typescript/hooks.d.ts.map +1 -0
  131. package/build/typescript/index.d.ts +3 -0
  132. package/build/typescript/index.d.ts.map +1 -0
  133. package/build/typescript/selectors.d.ts +32 -0
  134. package/build/typescript/selectors.d.ts.map +1 -0
  135. package/build/typescript/serialization.d.ts +6 -0
  136. package/build/typescript/serialization.d.ts.map +1 -0
  137. package/build/typescript/shared.d.ts +16 -0
  138. package/build/typescript/shared.d.ts.map +1 -0
  139. package/package.json +35 -0
  140. package/rollup.config.js +3 -0
  141. package/source/Attr.ts +70 -0
  142. package/source/CharacterData.ts +29 -0
  143. package/source/ChildNode.ts +45 -0
  144. package/source/Comment.ts +7 -0
  145. package/source/CustomElementRegistry.ts +52 -0
  146. package/source/CustomEvent.ts +30 -0
  147. package/source/Document.ts +112 -0
  148. package/source/DocumentFragment.ts +8 -0
  149. package/source/Element.ts +119 -0
  150. package/source/Event.ts +142 -0
  151. package/source/EventTarget.ts +139 -0
  152. package/source/HTMLElement.ts +3 -0
  153. package/source/HTMLTemplateElement.ts +28 -0
  154. package/source/MutationObserver.ts +3 -0
  155. package/source/NamedNodeMap.ts +156 -0
  156. package/source/Node.ts +139 -0
  157. package/source/NodeList.ts +5 -0
  158. package/source/ParentNode.ts +158 -0
  159. package/source/SVGElement.ts +16 -0
  160. package/source/Text.ts +7 -0
  161. package/source/Window.ts +64 -0
  162. package/source/constants.ts +37 -0
  163. package/source/hooks.ts +28 -0
  164. package/source/index.ts +2 -0
  165. package/source/selectors.ts +230 -0
  166. package/source/serialization.ts +110 -0
  167. package/source/shared.ts +80 -0
  168. package/tsconfig.json +10 -0
@@ -0,0 +1,35 @@
1
+ export declare const NAME: unique symbol;
2
+ export declare const VALUE: unique symbol;
3
+ export declare const NS: unique symbol;
4
+ export declare const OWNER_ELEMENT: unique symbol;
5
+ export declare const OWNER_DOCUMENT: unique symbol;
6
+ export declare const ATTRIBUTES: unique symbol;
7
+ export declare const PREV: unique symbol;
8
+ export declare const NEXT: unique symbol;
9
+ export declare const CHILD: unique symbol;
10
+ export declare const PARENT: unique symbol;
11
+ export declare const DATA: unique symbol;
12
+ export declare const USER_PROPERTIES: unique symbol;
13
+ export declare const LISTENERS: unique symbol;
14
+ export declare const IS_TRUSTED: unique symbol;
15
+ export declare const CONTENT: unique symbol;
16
+ export declare const SLOT: unique symbol;
17
+ export declare const enum NodeType {
18
+ NODE = 0,
19
+ ELEMENT_NODE = 1,
20
+ ATTRIBUTE_NODE = 2,
21
+ TEXT_NODE = 3,
22
+ CDATA_SECTION_NODE = 4,
23
+ ENTITY_REFERENCE_NODE = 5,
24
+ ENTITY_NODE = 6,
25
+ PROCESSING_INSTRUCTION_NODE = 7,
26
+ COMMENT_NODE = 8,
27
+ DOCUMENT_NODE = 9,
28
+ DOCUMENT_TYPE_NODE = 10,
29
+ DOCUMENT_FRAGMENT_NODE = 11
30
+ }
31
+ export declare const enum NamespaceURI {
32
+ XHTML = "http://www.w3.org/1999/xhtml",
33
+ SVG = "http://www.w3.org/2000/svg"
34
+ }
35
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../source/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,eAAiB,CAAC;AACnC,eAAO,MAAM,KAAK,eAAkB,CAAC;AACrC,eAAO,MAAM,EAAE,eAAe,CAAC;AAC/B,eAAO,MAAM,aAAa,eAAkB,CAAC;AAC7C,eAAO,MAAM,cAAc,eAA2B,CAAC;AACvD,eAAO,MAAM,UAAU,eAAuB,CAAC;AAC/C,eAAO,MAAM,IAAI,eAAiB,CAAC;AACnC,eAAO,MAAM,IAAI,eAAiB,CAAC;AACnC,eAAO,MAAM,KAAK,eAAkB,CAAC;AACrC,eAAO,MAAM,MAAM,eAAmB,CAAC;AACvC,eAAO,MAAM,IAAI,eAAiB,CAAC;AACnC,eAAO,MAAM,eAAe,eAA4B,CAAC;AACzD,eAAO,MAAM,SAAS,eAAsB,CAAC;AAC7C,eAAO,MAAM,UAAU,eAAsB,CAAC;AAC9C,eAAO,MAAM,OAAO,eAAoB,CAAC;AACzC,eAAO,MAAM,IAAI,eAAiB,CAAC;AAGnC,0BAAkB,QAAQ;IACxB,IAAI,IAAI;IACR,YAAY,IAAI;IAChB,cAAc,IAAI;IAClB,SAAS,IAAI;IACb,kBAAkB,IAAI;IACtB,qBAAqB,IAAI;IACzB,WAAW,IAAI;IACf,2BAA2B,IAAI;IAC/B,YAAY,IAAI;IAChB,aAAa,IAAI;IACjB,kBAAkB,KAAK;IACvB,sBAAsB,KAAK;CAC5B;AAED,0BAAkB,YAAY;IAC5B,KAAK,iCAAiC;IACtC,GAAG,+BAA+B;CACnC"}
@@ -0,0 +1,13 @@
1
+ export interface Hooks {
2
+ createElement(element: Element, ns?: string | null): void;
3
+ setAttribute(element: Element, name: string, value: string, ns?: string | null): void;
4
+ removeAttribute(element: Element, name: string, ns?: string | null): void;
5
+ createText(text: Text, data: string): void;
6
+ setText(text: Text, data: string): void;
7
+ insertChild(parent: Element, node: Element | Text, index: number): void;
8
+ removeChild(parent: Element, node: Element | Text, index: number): void;
9
+ addEventListener(element: EventTarget, type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
10
+ removeEventListener(element: EventTarget, type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
11
+ }
12
+ export declare const hooks: Partial<Hooks>;
13
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../source/hooks.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1D,YAAY,CACV,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,GACjB,IAAI,CAAC;IACR,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1E,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,gBAAgB,CACd,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,GAAG,IAAI,EACnD,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC1C,IAAI,CAAC;IACR,mBAAmB,CACjB,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,GAAG,IAAI,EACnD,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,IAAI,CAAC;CACT;AAED,eAAO,MAAM,KAAK,EAAE,OAAO,CAAC,KAAK,CAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { hooks, type Hooks } from './hooks.ts';
2
+ export { Window } from './Window.ts';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,KAAK,KAAK,EAAC,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { Element } from './Element.ts';
2
+ import type { ParentNode } from './ParentNode.ts';
3
+ declare const enum Combinator {
4
+ Descendant = 0,
5
+ Child = 1,
6
+ Sibling = 2,
7
+ Adjacent = 3,
8
+ Inner = 4
9
+ }
10
+ declare const enum MatcherType {
11
+ Unknown = 0,
12
+ Element = 1,
13
+ Id = 2,
14
+ Class = 3,
15
+ Attribute = 4,
16
+ Pseudo = 5,
17
+ Function = 6
18
+ }
19
+ interface Part {
20
+ combinator: Combinator;
21
+ matchers: Matcher[];
22
+ }
23
+ interface Matcher {
24
+ type: MatcherType;
25
+ name: string;
26
+ value?: string;
27
+ }
28
+ export declare function querySelector(within: ParentNode, selector: string): null;
29
+ export declare function querySelectorAll(within: ParentNode, selector: string): Element[];
30
+ export declare function parseSelector(selector: string): Part[];
31
+ export {};
32
+ //# sourceMappingURL=selectors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../source/selectors.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAEhD,mBAAW,UAAU;IACnB,UAAU,IAAA;IACV,KAAK,IAAA;IACL,OAAO,IAAA;IACP,QAAQ,IAAA;IACR,KAAK,IAAA;CACN;AAED,mBAAW,WAAW;IACpB,OAAO,IAAA;IACP,OAAO,IAAA;IACP,EAAE,IAAA;IACF,KAAK,IAAA;IACL,SAAS,IAAA;IACT,MAAM,IAAA;IACN,QAAQ,IAAA;CACT;AAED,UAAU,IAAI;IACZ,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,UAAU,OAAO;IACf,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,QAYjE;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAWpE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,UA0C7C"}
@@ -0,0 +1,6 @@
1
+ import type { Node } from './Node.ts';
2
+ import type { ParentNode } from './ParentNode.ts';
3
+ export declare function parseHtml(html: string, contextNode: Node): import("./DocumentFragment.ts").DocumentFragment;
4
+ export declare function serializeChildren(parentNode: ParentNode): string;
5
+ export declare function serializeNode(node: Node): string;
6
+ //# sourceMappingURL=serialization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../source/serialization.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAGpC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAiBhD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,oDA8BxD;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,UAQvD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,UAsCvC"}
@@ -0,0 +1,16 @@
1
+ import type { Document } from './Document.ts';
2
+ import type { DocumentFragment } from './DocumentFragment.ts';
3
+ import type { Node } from './Node.ts';
4
+ import type { Comment } from './Comment.ts';
5
+ import type { ParentNode } from './ParentNode.ts';
6
+ import type { Element } from './Element.ts';
7
+ import type { CharacterData } from './CharacterData.ts';
8
+ import type { Text } from './Text.ts';
9
+ export declare function isCharacterData(node: Node): node is CharacterData;
10
+ export declare function isTextNode(node: Node): node is Text;
11
+ export declare function isCommentNode(node: Node): node is Comment;
12
+ export declare function isElementNode(node: Node): node is Element;
13
+ export declare function isDocumentFragmentNode(node: Node): node is DocumentFragment;
14
+ export declare function isParentNode(node: Node): node is ParentNode;
15
+ export declare function cloneNode(node: Node, deep?: boolean, document?: Document): Node;
16
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../source/shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAEpC,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,aAAa,CAEjE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,IAAI,CAEnD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,OAAO,CAEzD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,OAAO,CAEzD;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,gBAAgB,CAE3E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,UAAU,CAE3D;AAED,wBAAgB,SAAS,CACvB,IAAI,EAAE,IAAI,EACV,IAAI,CAAC,EAAE,OAAO,EACd,QAAQ,GAAE,QAA6B,GACtC,IAAI,CAyCN"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@remote-dom/polyfill",
3
+ "type": "module",
4
+ "license": "MIT",
5
+ "description": "A polyfill for the browser APIs used by Remote DOM",
6
+ "publishConfig": {
7
+ "access": "public",
8
+ "@remote-dom/registry": "https://registry.npmjs.org"
9
+ },
10
+ "version": "0.0.1",
11
+ "engines": {
12
+ "node": ">=14.0.0"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/Shopify/remote-dom",
17
+ "directory": "packages/polyfill"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "types": "./build/typescript/index.d.ts",
22
+ "quilt:source": "./source/index.ts",
23
+ "quilt:esnext": "./build/esnext/index.esnext",
24
+ "import": "./build/esm/index.mjs"
25
+ }
26
+ },
27
+ "types": "./build/typescript/index.d.ts",
28
+ "sideEffects": false,
29
+ "browserslist": [
30
+ "defaults and not dead"
31
+ ],
32
+ "scripts": {
33
+ "build": "rollup --config ./rollup.config.js"
34
+ }
35
+ }
@@ -0,0 +1,3 @@
1
+ import {quiltPackage} from '@quilted/rollup/package';
2
+
3
+ export default quiltPackage();
package/source/Attr.ts ADDED
@@ -0,0 +1,70 @@
1
+ import {hooks} from './hooks.ts';
2
+ import {
3
+ NS,
4
+ NEXT,
5
+ VALUE,
6
+ OWNER_ELEMENT,
7
+ NAME,
8
+ NamespaceURI,
9
+ NodeType,
10
+ } from './constants.ts';
11
+ import {Node} from './Node.ts';
12
+ import type {Element} from './Element.ts';
13
+
14
+ export class Attr extends Node {
15
+ nodeType = NodeType.ATTRIBUTE_NODE;
16
+ [NS]: NamespaceURI | null = null;
17
+ [NEXT]: Attr | null = null;
18
+ [VALUE]: string;
19
+ [OWNER_ELEMENT]: Element | null = null;
20
+ isConnected = false;
21
+
22
+ constructor(name: string, value: string, namespace?: NamespaceURI | null) {
23
+ super();
24
+ this[NAME] = name;
25
+ this[VALUE] = value;
26
+ if (namespace) this[NS] = namespace;
27
+ }
28
+
29
+ get nodeName() {
30
+ return this[NAME];
31
+ }
32
+
33
+ set nodeName(_readonly: string) {}
34
+ get name() {
35
+ return this[NAME];
36
+ }
37
+
38
+ set name(_readonly: string) {}
39
+ get value() {
40
+ return this[VALUE];
41
+ }
42
+
43
+ set value(value: string) {
44
+ const str = String(value);
45
+ this[VALUE] = str;
46
+ const ownerElement = this[OWNER_ELEMENT];
47
+ if (!ownerElement) return;
48
+ hooks.setAttribute?.(ownerElement as any, this[NAME], str, this[NS]);
49
+ }
50
+
51
+ get nodeValue() {
52
+ return this.value;
53
+ }
54
+
55
+ set nodeValue(value: string) {
56
+ this.value = value;
57
+ }
58
+
59
+ get ownerElement() {
60
+ return this[OWNER_ELEMENT];
61
+ }
62
+
63
+ get namespaceURI() {
64
+ return this[NS];
65
+ }
66
+
67
+ get specified() {
68
+ return true;
69
+ }
70
+ }
@@ -0,0 +1,29 @@
1
+ import {hooks} from './hooks.ts';
2
+ import {DATA} from './constants.ts';
3
+ import {ChildNode} from './ChildNode.ts';
4
+
5
+ export class CharacterData extends ChildNode {
6
+ [DATA] = '';
7
+
8
+ constructor(data: any) {
9
+ super();
10
+ this.setData(data);
11
+ }
12
+
13
+ protected setData(data: any) {
14
+ let str = '';
15
+ if (data != null) {
16
+ str = typeof data === 'string' ? data : String(data);
17
+ }
18
+ this[DATA] = str;
19
+ hooks.setText?.(this as any, str);
20
+ }
21
+
22
+ get data() {
23
+ return this[DATA];
24
+ }
25
+
26
+ set data(data: any) {
27
+ this.setData(data);
28
+ }
29
+ }
@@ -0,0 +1,45 @@
1
+ import {NEXT} from './constants.ts';
2
+ import type {ParentNode} from './ParentNode.ts';
3
+ import {Node} from './Node.ts';
4
+
5
+ export class ChildNode extends Node {
6
+ remove() {
7
+ const parent = this.parentNode;
8
+ if (!parent) return;
9
+ parent.removeChild(this);
10
+ }
11
+
12
+ replaceWith(...nodes: (Node | string)[]) {
13
+ const parent = this.parentNode;
14
+ if (!parent) return;
15
+ const node = toNode(parent, nodes[0]);
16
+ const next = node[NEXT];
17
+ parent.replaceChild(this, node);
18
+ for (let i = 1; i < nodes.length; i++) {
19
+ parent.insertBefore(toNode(parent, nodes[i]), next);
20
+ }
21
+ }
22
+
23
+ before(...nodes: (Node | string)[]) {
24
+ const parent = this.parentNode;
25
+ if (!parent) return;
26
+ for (const node of nodes) {
27
+ parent.insertBefore(toNode(parent, node), this);
28
+ }
29
+ }
30
+
31
+ after(...nodes: (Node | string)[]) {
32
+ const parent = this.parentNode;
33
+ if (!parent) return;
34
+ const next = this[NEXT];
35
+ for (const node of nodes) {
36
+ parent.insertBefore(toNode(parent, node), next);
37
+ }
38
+ }
39
+ }
40
+
41
+ export function toNode(parent: ParentNode, node: Node | any) {
42
+ if (node instanceof Node) return node;
43
+ const ownerDocument = parent.ownerDocument;
44
+ return ownerDocument.createTextNode(String(node));
45
+ }
@@ -0,0 +1,7 @@
1
+ import {NAME} from './constants.ts';
2
+ import {CharacterData} from './CharacterData.ts';
3
+
4
+ export class Comment extends CharacterData {
5
+ nodeType = 8;
6
+ [NAME] = '#comment';
7
+ }
@@ -0,0 +1,52 @@
1
+ export class CustomElementRegistryImplementation
2
+ implements CustomElementRegistry
3
+ {
4
+ private registry = new Map<string, CustomElementConstructor>();
5
+ private listenersByName = new Map<
6
+ string,
7
+ ((Constructor: CustomElementConstructor) => void)[]
8
+ >();
9
+
10
+ define(
11
+ name: string,
12
+ Constructor: CustomElementConstructor,
13
+ _options?: ElementDefinitionOptions,
14
+ ) {
15
+ this.registry.set(name, Constructor);
16
+
17
+ const listeners = this.listenersByName.get(name);
18
+
19
+ if (listeners == null) return;
20
+
21
+ this.listenersByName.delete(name);
22
+
23
+ for (const listener of listeners) {
24
+ listener(Constructor);
25
+ }
26
+ }
27
+
28
+ get(name: string) {
29
+ return this.registry.get(name);
30
+ }
31
+
32
+ whenDefined(name: string) {
33
+ const Constructor = this.registry.get(name);
34
+
35
+ if (Constructor != null) return Promise.resolve(Constructor);
36
+
37
+ let listeners = this.listenersByName.get(name);
38
+
39
+ if (listeners == null) {
40
+ listeners = [];
41
+ this.listenersByName.set(name, listeners);
42
+ }
43
+
44
+ return new Promise<CustomElementConstructor>((resolve) => {
45
+ listeners!.push(resolve);
46
+ });
47
+ }
48
+
49
+ upgrade(_root: Node) {
50
+ // TODO
51
+ }
52
+ }
@@ -0,0 +1,30 @@
1
+ import {Event} from './Event.ts';
2
+
3
+ export class CustomEvent<T = any> extends Event {
4
+ /**
5
+ * Returns any custom data event was created with. Typically used for synthetic events.
6
+ *
7
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail)
8
+ */
9
+ readonly detail: T;
10
+
11
+ constructor(type: string, eventInitDict?: CustomEventInit<T>) {
12
+ super(type, eventInitDict);
13
+ this.detail = eventInitDict?.detail as any;
14
+ }
15
+
16
+ /**
17
+ * Returns any custom data event was created with. Typically used for synthetic events.
18
+ *
19
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CustomEvent/detail)
20
+ */
21
+ initCustomEvent(
22
+ type: string,
23
+ bubbles?: boolean,
24
+ cancelable?: boolean,
25
+ detail?: T,
26
+ ) {
27
+ super.initEvent(type, bubbles, cancelable);
28
+ (this as any).detail = detail;
29
+ }
30
+ }
@@ -0,0 +1,112 @@
1
+ import {NS, NAME, NamespaceURI, NodeType, OWNER_DOCUMENT} from './constants.ts';
2
+ import type {Window} from './Window.ts';
3
+ import type {Node} from './Node.ts';
4
+ import {Event} from './Event.ts';
5
+ import {ParentNode} from './ParentNode.ts';
6
+ import {Element} from './Element.ts';
7
+ import {SVGElement} from './SVGElement.ts';
8
+ import {Text} from './Text.ts';
9
+ import {Comment} from './Comment.ts';
10
+ import {DocumentFragment} from './DocumentFragment.ts';
11
+ import {HTMLTemplateElement} from './HTMLTemplateElement.ts';
12
+ import {isParentNode, cloneNode} from './shared.ts';
13
+
14
+ export class Document extends ParentNode {
15
+ nodeType = NodeType.DOCUMENT_NODE;
16
+ [NAME] = '#document';
17
+
18
+ constructor(public defaultView: Window) {
19
+ super();
20
+ this[OWNER_DOCUMENT] = this;
21
+ }
22
+
23
+ createElement(localName: string) {
24
+ const lowerName = String(localName).toLowerCase();
25
+
26
+ if (lowerName === 'template') {
27
+ return createElement(new HTMLTemplateElement(), this, 'template');
28
+ }
29
+
30
+ const CustomElement = this.defaultView.customElements.get(localName);
31
+
32
+ if (CustomElement) {
33
+ return createElement(new CustomElement() as any, this, localName);
34
+ } else {
35
+ return createElement(new Element(), this, localName);
36
+ }
37
+ }
38
+
39
+ createElementNS(localName: string, namespaceURI?: NamespaceURI) {
40
+ if (namespaceURI === NamespaceURI.SVG) {
41
+ return createElement(new SVGElement(), this, localName);
42
+ }
43
+
44
+ return createElement(new Element(), this, localName, namespaceURI);
45
+ }
46
+
47
+ createTextNode(data: any) {
48
+ return createNode(new Text(data), this);
49
+ }
50
+
51
+ createComment(data: any) {
52
+ return createNode(new Comment(data), this);
53
+ }
54
+
55
+ createDocumentFragment() {
56
+ return createNode(new DocumentFragment(), this);
57
+ }
58
+
59
+ createEvent() {
60
+ return new Event('');
61
+ }
62
+
63
+ importNode(node: Node, deep?: boolean) {
64
+ return cloneNode(node, deep, this);
65
+ }
66
+
67
+ adoptNode(node: Node) {
68
+ if (node[OWNER_DOCUMENT] === this) return node;
69
+
70
+ node.parentNode?.removeChild(node);
71
+ adoptNode(node, this);
72
+
73
+ return node;
74
+ }
75
+ }
76
+
77
+ export function createNode<T extends Node>(node: T, ownerDocument: Document) {
78
+ Object.defineProperty(node, OWNER_DOCUMENT, {
79
+ value: ownerDocument,
80
+ writable: true,
81
+ enumerable: false,
82
+ });
83
+
84
+ return node;
85
+ }
86
+
87
+ export function createElement<T extends Element>(
88
+ element: T,
89
+ ownerDocument: Document,
90
+ name: string,
91
+ namespace?: NamespaceURI,
92
+ ) {
93
+ createNode(element, ownerDocument);
94
+
95
+ Object.defineProperty(element, NAME, {value: name});
96
+
97
+ if (namespace) {
98
+ Object.defineProperty(element, NS, {value: namespace});
99
+ }
100
+
101
+ return element;
102
+ }
103
+
104
+ export function adoptNode(node: Node, document: Document) {
105
+ node[OWNER_DOCUMENT] = document;
106
+
107
+ if (isParentNode(node)) {
108
+ for (const child of node.childNodes) {
109
+ adoptNode(child, document);
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,8 @@
1
+ import {NAME, OWNER_DOCUMENT, NodeType} from './constants.ts';
2
+ import {ParentNode} from './ParentNode.ts';
3
+
4
+ export class DocumentFragment extends ParentNode {
5
+ nodeType = NodeType.DOCUMENT_FRAGMENT_NODE;
6
+ [NAME] = '#document-fragment';
7
+ [OWNER_DOCUMENT] = window.document as any;
8
+ }
@@ -0,0 +1,119 @@
1
+ import {NS, SLOT, ATTRIBUTES, NamespaceURI, NodeType} from './constants.ts';
2
+ import {ParentNode} from './ParentNode.ts';
3
+ import {NamedNodeMap} from './NamedNodeMap.ts';
4
+ import {Attr} from './Attr.ts';
5
+ import {serializeNode, serializeChildren, parseHtml} from './serialization.ts';
6
+
7
+ export class Element extends ParentNode {
8
+ static readonly observedAttributes?: string[];
9
+
10
+ nodeType = NodeType.ELEMENT_NODE;
11
+
12
+ [NS] = NamespaceURI.XHTML;
13
+ [SLOT] = '';
14
+ get namespaceURI() {
15
+ return this[NS];
16
+ }
17
+
18
+ get tagName() {
19
+ return this.nodeName;
20
+ }
21
+
22
+ [ATTRIBUTES]!: NamedNodeMap;
23
+
24
+ [anyProperty: string]: any;
25
+
26
+ get slot() {
27
+ return this[SLOT];
28
+ }
29
+
30
+ set slot(slot: string) {
31
+ const finalSlot = String(slot);
32
+ this[SLOT] = finalSlot;
33
+ if (this.getAttribute('slot') !== finalSlot) {
34
+ this.attributes.setNamedItem(new Attr('slot', finalSlot));
35
+ }
36
+ }
37
+
38
+ get attributes() {
39
+ let attributes = this[ATTRIBUTES];
40
+ if (!attributes) {
41
+ attributes = new NamedNodeMap(this);
42
+ this[ATTRIBUTES] = attributes;
43
+ }
44
+ return attributes;
45
+ }
46
+
47
+ get firstElementChild() {
48
+ return this.children[0] ?? null;
49
+ }
50
+
51
+ get lastElementChild() {
52
+ return this.children[this.children.length - 1] ?? null;
53
+ }
54
+
55
+ get nextElementSibling() {
56
+ let sib = this.nextSibling;
57
+ while (sib && sib.nodeType !== 1) sib = sib.nextSibling;
58
+ return sib;
59
+ }
60
+
61
+ get previewElementSibling() {
62
+ let sib = this.previousSibling;
63
+ while (sib && sib.nodeType !== 1) sib = sib.previousSibling;
64
+ return sib;
65
+ }
66
+
67
+ setAttribute(name: string, value: string) {
68
+ this.attributes.setNamedItem(new Attr(name, String(value)));
69
+ }
70
+
71
+ setAttributeNS(namespace: NamespaceURI | null, name: string, value: string) {
72
+ this.attributes.setNamedItemNS(new Attr(name, String(value), namespace));
73
+ }
74
+
75
+ getAttribute(name: string) {
76
+ const attr = this.attributes.getNamedItem(name);
77
+ return attr && attr.value;
78
+ }
79
+
80
+ getAttributeNS(namespace: NamespaceURI | null, name: string) {
81
+ const attr = this.attributes.getNamedItemNS(namespace, name);
82
+ return attr && attr.value;
83
+ }
84
+
85
+ hasAttribute(name: string) {
86
+ const attr = this.attributes.getNamedItem(name);
87
+ return attr != null;
88
+ }
89
+
90
+ hasAttributeNS(namespace: NamespaceURI | null, name: string) {
91
+ const attr = this.attributes.getNamedItemNS(namespace, name);
92
+ return attr != null;
93
+ }
94
+
95
+ removeAttribute(name: string) {
96
+ this.attributes.removeNamedItem(name);
97
+ }
98
+
99
+ removeAttributeNS(namespace: NamespaceURI | null, name: string) {
100
+ this.attributes.removeNamedItemNS(namespace, name);
101
+ }
102
+
103
+ get outerHTML() {
104
+ return serializeNode(this);
105
+ }
106
+
107
+ get innerHTML() {
108
+ return serializeChildren(this);
109
+ }
110
+
111
+ set innerHTML(html: any) {
112
+ if (html == null || html === '') {
113
+ this.replaceChildren();
114
+ } else {
115
+ const fragment = parseHtml(String(html), this);
116
+ this.replaceChildren(fragment);
117
+ }
118
+ }
119
+ }