summary refs log tree commit diff stats
path: root/lib/js
diff options
context:
space:
mode:
authorBung <crc32@qq.com>2020-07-22 01:11:12 +0800
committerGitHub <noreply@github.com>2020-07-21 19:11:12 +0200
commit64d629c617b5bbc700349afbc16607e2ed9f8eeb (patch)
tree50ced3076671b0e1e59691ef25d8b02f248d27b7 /lib/js
parentc8a72e07488de996fc7d03985747a22414d3d9df (diff)
downloadNim-64d629c617b5bbc700349afbc16607e2ed9f8eeb.tar.gz
Shadow Dom apis (#14979)
* shadow dom api

* fix typos

* host to Element type

* fix code style

* move elementsFromPoint to dom_extensions.nim
Diffstat (limited to 'lib/js')
-rw-r--r--lib/js/dom.nim32
-rw-r--r--lib/js/dom_extensions.nim5
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/js/dom.nim b/lib/js/dom.nim
index be676a813..84ceb73f3 100644
--- a/lib/js/dom.nim
+++ b/lib/js/dom.nim
@@ -1324,6 +1324,26 @@ since (1, 3):
     FileReaderObj {.importc.} = object of EventTargetObj
 
     FileReaderState* = distinct range[0'u16..2'u16]
+    RootNodeOptions* = object of RootObj
+      composed*: bool
+    DocumentOrShadowRoot* {.importc.} = object of RootObj
+      activeElement*: Element
+      # styleSheets*: StyleSheetList 
+    ShadowRoot* = ref ShadowRootObj
+    ShadowRootObj {.importc.} = object of DocumentOrShadowRoot
+      delegatesFocus*: bool
+      host*: Element
+      innerHTML*: cstring
+      mode*: cstring # "open" or "closed"
+    ShadowRootInit* = object of RootObj
+      mode*: cstring
+      delegatesFocus*: bool
+
+    HTMLSlotElement* = ref HTMLSlotElementObj
+    HTMLSlotElementObj {.importc.} = object of RootObj
+      name*: cstring
+    SlotOptions* = object of RootObj
+      flatten*: bool
 
   const
     fileReaderEmpty* = 0.FileReaderState
@@ -1503,6 +1523,18 @@ proc contains*(n: Node): bool
 proc isEqualNode*(n: Node): bool
 proc isSameNode*(n: Node): bool
 
+since (1, 3):
+  proc getRootNode*(n: Node,options: RootNodeOptions): Node
+
+  # DocumentOrShadowRoot
+  proc getSelection*(n: DocumentOrShadowRoot): Selection
+  proc elementFromPoint*(n: DocumentOrShadowRoot; x, y: float): Element
+
+  # shadow dom
+  proc attachShadow*(n: Element): ShadowRoot
+  proc assignedNodes*(n: HTMLSlotElement; options: SlotOptions): seq[Node]
+  proc assignedElements*(n: HTMLSlotElement; options: SlotOptions): seq[Element]
+
 # Document "methods"
 proc createAttribute*(d: Document, identifier: cstring): Node
 proc getElementsByName*(d: Document, name: cstring): seq[Element]
diff --git a/lib/js/dom_extensions.nim b/lib/js/dom_extensions.nim
new file mode 100644
index 000000000..851ec0c5f
--- /dev/null
+++ b/lib/js/dom_extensions.nim
@@ -0,0 +1,5 @@
+import dom
+
+{.push importcpp.}
+proc elementsFromPoint*(n: DocumentOrShadowRoot; x, y: float): seq[Element]
+{.pop.}
\ No newline at end of file