-
-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
becb659
commit 9bb326f
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1", | ||
"id": "web-dom", | ||
"type": "lib", | ||
"description": "Implementation of the HTML standard (https://html.spec.whatwg.org/multipage/)", | ||
"requires": [ | ||
"karm-logger", | ||
"web-base" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#pragma once | ||
|
||
#include <karm-base/list.h> | ||
|
||
namespace Web::Dom { | ||
|
||
struct Node : public Meta::Static { | ||
Node *_parent; | ||
LlItem<Node> _siblings; | ||
Ll<Node, &Node::_siblings> _children; | ||
|
||
virtual ~Node() {} | ||
|
||
/* --- Parent --- */ | ||
|
||
Node &parentNode() { | ||
if (not _parent) | ||
panic("node has no parent"); | ||
return *_parent; | ||
} | ||
|
||
Node const &parentNode() const { | ||
if (not _parent) | ||
panic("node has no parent"); | ||
return *_parent; | ||
} | ||
|
||
/* --- Children --- */ | ||
|
||
bool hasChildren() const { | ||
return _children.len() > 0; | ||
} | ||
|
||
Node &firstChild() { | ||
auto *res = _children._head; | ||
if (not res) | ||
panic("node has no children"); | ||
return *res; | ||
} | ||
|
||
Node const &firstChild() const { | ||
auto *res = _children._head; | ||
if (not res) | ||
panic("node has no children"); | ||
return *res; | ||
} | ||
|
||
Node &lastChild() { | ||
auto *res = _children._tail; | ||
if (not res) | ||
panic("node has no children"); | ||
return *res; | ||
} | ||
|
||
Node const &lastChild() const { | ||
auto *res = _children._tail; | ||
if (not res) | ||
panic("node has no children"); | ||
return *res; | ||
} | ||
|
||
/* --- Siblings --- */ | ||
|
||
Node &previousSibling() { | ||
auto *res = _siblings.prev; | ||
if (not res) | ||
panic("node has no previous sibling"); | ||
return *res; | ||
} | ||
|
||
Node const &previousSibling() const { | ||
auto *res = _siblings.prev; | ||
if (not res) | ||
panic("node has no previous sibling"); | ||
return *res; | ||
} | ||
|
||
Node &nextSibling() { | ||
auto *res = _siblings.next; | ||
if (not res) | ||
panic("node has no next sibling"); | ||
return *res; | ||
} | ||
|
||
Node const &nextSibling() const { | ||
auto *res = _siblings.next; | ||
if (not res) | ||
panic("node has no next sibling"); | ||
return *res; | ||
} | ||
}; | ||
|
||
} // namespace Web::Dom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "https://schemas.cute.engineering/stable/cutekit.manifest.component.v1", | ||
"id": "web-dom-tests", | ||
"type": "lib", | ||
"props": { | ||
"cpp-excluded": true | ||
}, | ||
"requires": [ | ||
"web-dom", | ||
"karm-test" | ||
], | ||
"injects": [ | ||
"__tests__" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <karm-test/macros.h> | ||
#include <web-dom/node.h> | ||
|
||
namespace Web::Dom::Tests { | ||
|
||
test$(domTree) { | ||
auto &root = *new Node(); | ||
|
||
delete &root; | ||
return Ok(); | ||
} | ||
|
||
} // namespace Web::Dom::Tests |