Skip to content

Commit 4420452

Browse files
committed
docs: document dom query helpers
1 parent 0d184b8 commit 4420452

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

docs/api/dom.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,111 @@ Gets a handle to the `<body>` element of the document.
1818
webcc::DOMElement get_body();
1919
```
2020

21+
### `get_active_element`
22+
23+
Gets a handle to the currently focused element (`document.activeElement`).
24+
Returns an invalid handle (`-1`) if no active element exists.
25+
26+
```cpp
27+
webcc::DOMElement get_active_element();
28+
```
29+
2130
### `get_element_by_id`
2231

2332
Gets a handle to an element by its ID.
33+
Returns an invalid handle (`-1`) if the element does not exist.
2434

2535
```cpp
2636
webcc::DOMElement get_element_by_id(webcc::string_view id);
2737
```
2838
39+
### `get_parent_node`
40+
41+
Gets the parent element of a node.
42+
Returns an invalid handle (`-1`) if the node has no parent element.
43+
44+
```cpp
45+
webcc::DOMElement get_parent_node(webcc::DOMElement node_handle);
46+
```
47+
48+
### `is_connected`
49+
50+
Returns true if the node is currently connected to the document.
51+
52+
```cpp
53+
bool is_connected(webcc::DOMElement node_handle);
54+
```
55+
56+
### `is_valid`
57+
58+
Returns true if the handle currently refers to a valid DOM element.
59+
This is useful for checking results of selector-based APIs which can return `-1`.
60+
61+
```cpp
62+
bool is_valid(webcc::DOMElement handle);
63+
```
64+
65+
### `contains`
66+
67+
Returns true if `container` contains `other` in the DOM tree.
68+
69+
```cpp
70+
bool contains(webcc::DOMElement container_handle, webcc::DOMElement other_handle);
71+
```
72+
73+
### `query_selector`
74+
75+
Queries a descendant element using a CSS selector.
76+
Returns an invalid handle (`-1`) if nothing matches.
77+
78+
```cpp
79+
webcc::DOMElement query_selector(webcc::DOMElement root_handle, webcc::string_view selector);
80+
```
81+
82+
### `closest`
83+
84+
Returns the closest ancestor (including the node itself) that matches a selector.
85+
Returns an invalid handle (`-1`) if nothing matches.
86+
87+
```cpp
88+
webcc::DOMElement closest(webcc::DOMElement node_handle, webcc::string_view selector);
89+
```
90+
91+
### `query_selector_all_count`
92+
93+
Returns the number of matches for a CSS selector under `root`.
94+
95+
```cpp
96+
int32_t query_selector_all_count(webcc::DOMElement root_handle, webcc::string_view selector);
97+
```
98+
99+
### `query_selector_all_fill`
100+
101+
Fills a contiguous range of handles with the results of `querySelectorAll`.
102+
Use `webcc::reserve_deferred_handles(count)` to reserve `[start, start+count)` and then convert
103+
entries back to `webcc::DOMElement` via `webcc::DOMElement(start + i)`.
104+
105+
```cpp
106+
void query_selector_all_fill(webcc::DOMElement root_handle, webcc::string_view selector, int32_t start, int32_t count);
107+
```
108+
109+
### `child_element_count`
110+
111+
Returns the number of element children of `root`.
112+
113+
```cpp
114+
int32_t child_element_count(webcc::DOMElement root_handle);
115+
```
116+
117+
### `child_element_fill`
118+
119+
Fills a contiguous range of handles with the element children of `root`.
120+
Use `webcc::reserve_deferred_handles(count)` to reserve `[start, start+count)`.
121+
122+
```cpp
123+
void child_element_fill(webcc::DOMElement root_handle, int32_t start, int32_t count);
124+
```
125+
29126
### `create_element`
30127
31128
Creates a new HTML element with the specified tag name.
@@ -180,3 +277,9 @@ inline int32_t next_deferred_handle() {
180277
return counter++;
181278
}
182279
```
280+
281+
To reserve a contiguous range (useful for fill-style APIs):
282+
283+
```cpp
284+
inline int32_t reserve_deferred_handles(int32_t count);
285+
```

docs/api/websocket.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ webcc::WebSocket connect(webcc::string_view url);
2020
2121
All events (message, open, close, error) are automatically subscribed.
2222
23+
### `is_connected`
24+
25+
Returns true if the WebSocket exists and is currently open.
26+
27+
```cpp
28+
bool is_connected(webcc::WebSocket handle);
29+
```
30+
2331
### `send`
2432

2533
Sends a text message over the WebSocket connection.

docs/architecture.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ webcc::flush();
5555
5656
Deferred handles start at `0x100000` and increment upward, while JS-assigned handles use lower values, ensuring no collisions. This pattern is essential for high-performance DOM manipulation.
5757
58+
For APIs that need a contiguous range (e.g. `*_fill` APIs), use:
59+
60+
```cpp
61+
int32_t start = webcc::reserve_deferred_handles(count);
62+
// range is [start, start+count)
63+
```
64+
5865
## C++ Standard Library Compatibility
5966
WebCC provides a lightweight compatibility layer for common C++ Standard Library headers (located in `include/webcc/compat/`).
6067

0 commit comments

Comments
 (0)