1 module spasm.node;
2 
3 import spasm.types;
4 
5 template getChildren(Parent) {
6   import std.traits : hasUDA;
7   import std.meta : AliasSeq;
8   import std.traits : FieldNameTuple;
9   alias members = FieldNameTuple!Parent;
10   template isChild(string member) {
11     static if (__traits(compiles, __traits(getMember, Parent, member)))
12       enum isChild = hasUDA!(__traits(getMember, Parent, member), child);
13     else
14       enum isChild = false;
15   }
16   import std.meta : Filter;
17   alias getChildren = Filter!(isChild, members);
18 }
19 
20 struct BaseNode {
21   JsHandle node = invalidHandle;
22   bool mounted;
23   bool marked;
24   alias node this;
25 }
26 
27 struct TagHtmlElementMap {
28   import spasm.bindings.html;
29   alias a = HTMLAnchorElement;
30   alias area = HTMLAreaElement;
31   alias audio = HTMLAudioElement;
32   alias br = HTMLBRElement;
33   alias base = HTMLBaseElement;
34   alias body_ = HTMLBodyElement;
35   alias button = HTMLButtonElement;
36   alias canvas = HTMLCanvasElement;
37   alias dlist = HTMLDListElement;
38   alias data = HTMLDataElement;
39   alias datalist = HTMLDataListElement;
40   alias details = HTMLDetailsElement;
41   alias dialog = HTMLDialogElement;
42   alias directory = HTMLDirectoryElement;
43   alias div = HTMLDivElement;
44   alias embed = HTMLEmbedElement;
45   alias fieldset = HTMLFieldSetElement;
46   alias font = HTMLFontElement;
47   alias form = HTMLFormElement;
48   alias frame = HTMLFrameElement;
49   alias frameset = HTMLFrameSetElement;
50   alias hr = HTMLHRElement;
51   alias head = HTMLHeadElement;
52   alias h1 = HTMLHeadingElement;
53   alias h2 = HTMLHeadingElement;
54   alias h3 = HTMLHeadingElement;
55   alias h4 = HTMLHeadingElement;
56   alias h5 = HTMLHeadingElement;
57   alias h6 = HTMLHeadingElement;
58   alias html = HTMLHtmlElement;
59   alias iframe = HTMLIFrameElement;
60   alias image = HTMLImageElement;
61   alias input = HTMLInputElement;
62   alias li = HTMLLIElement;
63   alias label = HTMLLabelElement;
64   alias legend = HTMLLegendElement;
65   alias link = HTMLLinkElement;
66   alias map = HTMLMapElement;
67   alias marquee = HTMLMarqueeElement;
68   alias media = HTMLMediaElement;
69   alias menu = HTMLMenuElement;
70   alias meta = HTMLMetaElement;
71   alias meter = HTMLMeterElement;
72   alias mod = HTMLModElement;
73   alias olist = HTMLOListElement;
74   alias object = HTMLObjectElement;
75   alias optgroup = HTMLOptGroupElement;
76   alias option = HTMLOptionElement;
77   alias output = HTMLOutputElement;
78   alias paragraph = HTMLParagraphElement;
79   alias param = HTMLParamElement;
80   alias picture = HTMLPictureElement;
81   alias pre = HTMLPreElement;
82   alias progress = HTMLProgressElement;
83   alias quote = HTMLQuoteElement;
84   alias script = HTMLScriptElement;
85   alias select = HTMLSelectElement;
86   alias slot = HTMLSlotElement;
87   alias source = HTMLSourceElement;
88   alias span = HTMLSpanElement;
89   alias style = HTMLStyleElement;
90   alias tablecaption = HTMLTableCaptionElement;
91   alias tablecell = HTMLTableCellElement;
92   alias tablecol = HTMLTableColElement;
93   alias table = HTMLTableElement;
94   alias tablerow = HTMLTableRowElement;
95   alias tablesection = HTMLTableSectionElement;
96   alias template_ = HTMLTemplateElement;
97   alias textarea = HTMLTextAreaElement;
98   alias time = HTMLTimeElement;
99   alias title = HTMLTitleElement;
100   alias track = HTMLTrackElement;
101   alias ul = HTMLUListElement;
102   alias unknown = HTMLUnknownElement;
103   alias video = HTMLVideoElement;
104   // anything not known (custom elements, or footer/section/header/etc.)
105   template opDispatch(string name) {
106     alias opDispatch = HTMLElement;
107   }
108 }
109 
110 struct NamedNode(string tag) {
111   alias Element = __traits(getMember, TagHtmlElementMap, tag);
112   Element node = invalidHandle;
113   bool mounted;
114   bool marked;
115   alias node this;
116 }
117 
118 mixin template Node(string str) {
119   mixin("NamedNode!\""~str~"\" node;");
120 }