-
Notifications
You must be signed in to change notification settings - Fork 27
/
elements.go
537 lines (420 loc) · 14.4 KB
/
elements.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
package elem
import (
"github.com/chasefleming/elem-go/attrs"
)
// ========== Document Structure ==========
// Body creates a <body> element.
func Body(attrs attrs.Props, children ...Node) *Element {
return newElement("body", attrs, children...)
}
// Head creates a <head> element.
func Head(attrs attrs.Props, children ...Node) *Element {
return newElement("head", attrs, children...)
}
// Html creates an <html> element.
func Html(attrs attrs.Props, children ...Node) *Element {
return newElement("html", attrs, children...)
}
// Title creates a <title> element.
func Title(attrs attrs.Props, children ...Node) *Element {
return newElement("title", attrs, children...)
}
// ========== Text Formatting and Structure ==========
// A creates an <a> element.
func A(attrs attrs.Props, children ...Node) *Element {
return newElement("a", attrs, children...)
}
// Br creates a <br> element.
func Br(attrs attrs.Props) *Element {
return newElement("br", attrs)
}
// Blockquote creates a <blockquote> element.
func Blockquote(attrs attrs.Props, children ...Node) *Element {
return newElement("blockquote", attrs, children...)
}
// Code creates a <code> element.
func Code(attrs attrs.Props, children ...Node) *Element {
return newElement("code", attrs, children...)
}
// Div creates a <div> element.
func Div(attrs attrs.Props, children ...Node) *Element {
return newElement("div", attrs, children...)
}
// Em creates an <em> element.
func Em(attrs attrs.Props, children ...Node) *Element {
return newElement("em", attrs, children...)
}
// H1 creates an <h1> element.
func H1(attrs attrs.Props, children ...Node) *Element {
return newElement("h1", attrs, children...)
}
// H2 creates an <h2> element.
func H2(attrs attrs.Props, children ...Node) *Element {
return newElement("h2", attrs, children...)
}
// H3 creates an <h3> element.
func H3(attrs attrs.Props, children ...Node) *Element {
return newElement("h3", attrs, children...)
}
// H4 creates an <h4> element.
func H4(attrs attrs.Props, children ...Node) *Element {
return newElement("h4", attrs, children...)
}
// H5 creates an <h5> element.
func H5(attrs attrs.Props, children ...Node) *Element {
return newElement("h5", attrs, children...)
}
// H6 creates an <h6> element.
func H6(attrs attrs.Props, children ...Node) *Element {
return newElement("h6", attrs, children...)
}
// Hgroup creates an <hgroup> element.
func Hgroup(attrs attrs.Props, children ...Node) *Element {
return newElement("hgroup", attrs, children...)
}
// Hr creates an <hr> element.
func Hr(attrs attrs.Props) *Element {
return newElement("hr", attrs)
}
// I creates an <i> element.
func I(attrs attrs.Props, children ...Node) *Element {
return newElement("i", attrs, children...)
}
// P creates a <p> element.
func P(attrs attrs.Props, children ...Node) *Element {
return newElement("p", attrs, children...)
}
// Pre creates a <pre> element.
func Pre(attrs attrs.Props, children ...Node) *Element {
return newElement("pre", attrs, children...)
}
// Span creates a <span> element.
func Span(attrs attrs.Props, children ...Node) *Element {
return newElement("span", attrs, children...)
}
// Strong creates a <strong> element.
func Strong(attrs attrs.Props, children ...Node) *Element {
return newElement("strong", attrs, children...)
}
// Sub creates a <sub> element.
func Sub(attrs attrs.Props, children ...Node) *Element {
return newElement("sub", attrs, children...)
}
// Sup creates a <sub> element.
func Sup(attrs attrs.Props, children ...Node) *Element {
return newElement("sup", attrs, children...)
}
// B creates a <b> element.
func B(attrs attrs.Props, children ...Node) *Element {
return newElement("b", attrs, children...)
}
// U creates a <u> element.
func U(attrs attrs.Props, children ...Node) *Element {
return newElement("u", attrs, children...)
}
// Text creates a TextNode.
func Text(content string) TextNode {
return TextNode(content)
}
// Comment creates a CommentNode.
func Comment(comment string) CommentNode {
return CommentNode(comment)
}
// ========== Lists ==========
// Li creates an <li> element.
func Li(attrs attrs.Props, children ...Node) *Element {
return newElement("li", attrs, children...)
}
// Ul creates a <ul> element.
func Ul(attrs attrs.Props, children ...Node) *Element {
return newElement("ul", attrs, children...)
}
// Ol creates an <ol> element.
func Ol(attrs attrs.Props, children ...Node) *Element {
return newElement("ol", attrs, children...)
}
// Dl creates a <dl> element.
func Dl(attrs attrs.Props, children ...Node) *Element {
return newElement("dl", attrs, children...)
}
// Dt creates a <dt> element.
func Dt(attrs attrs.Props, children ...Node) *Element {
return newElement("dt", attrs, children...)
}
// Dd creates a <dd> element.
func Dd(attrs attrs.Props, children ...Node) *Element {
return newElement("dd", attrs, children...)
}
// ========== Forms ==========
// Button creates a <button> element.
func Button(attrs attrs.Props, children ...Node) *Element {
return newElement("button", attrs, children...)
}
// Form creates a <form> element.
func Form(attrs attrs.Props, children ...Node) *Element {
return newElement("form", attrs, children...)
}
// Input creates an <input> element.
func Input(attrs attrs.Props) *Element {
return newElement("input", attrs)
}
// Label creates a <label> element.
func Label(attrs attrs.Props, children ...Node) *Element {
return newElement("label", attrs, children...)
}
// Optgroup creates an <optgroup> element to group <option>s within a <select> element.
func Optgroup(attrs attrs.Props, children ...Node) *Element {
return newElement("optgroup", attrs, children...)
}
// Option creates an <option> element.
func Option(attrs attrs.Props, content TextNode) *Element {
return newElement("option", attrs, content)
}
// Select creates a <select> element.
func Select(attrs attrs.Props, children ...Node) *Element {
return newElement("select", attrs, children...)
}
// Textarea creates a <textarea> element.
func Textarea(attrs attrs.Props, content TextNode) *Element {
return newElement("textarea", attrs, content)
}
// ========== Hyperlinks and Multimedia ==========
// Img creates an <img> element.
func Img(attrs attrs.Props) *Element {
return newElement("img", attrs)
}
// ========== Head Elements ==========
// Base creates a <base> element.
func Base(attrs attrs.Props) *Element {
return newElement("base", attrs)
}
// Link creates a <link> element.
func Link(attrs attrs.Props) *Element {
return newElement("link", attrs)
}
// Meta creates a <meta> element.
func Meta(attrs attrs.Props) *Element {
return newElement("meta", attrs)
}
// Script creates a <script> element.
func Script(attrs attrs.Props, children ...Node) *Element {
return newElement("script", attrs, children...)
}
// Style creates a <style> element.
func Style(attrs attrs.Props, children ...Node) *Element {
return newElement("style", attrs, children...)
}
// ========== Semantic Elements ==========
// --- Semantic Sectioning Elements ---
// Article creates an <article> element.
func Article(attrs attrs.Props, children ...Node) *Element {
return newElement("article", attrs, children...)
}
// Aside creates an <aside> element.
func Aside(attrs attrs.Props, children ...Node) *Element {
return newElement("aside", attrs, children...)
}
// Footer creates a <footer> element.
func Footer(attrs attrs.Props, children ...Node) *Element {
return newElement("footer", attrs, children...)
}
// Header creates a <header> element.
func Header(attrs attrs.Props, children ...Node) *Element {
return newElement("header", attrs, children...)
}
// Main creates a <main> element.
func Main(attrs attrs.Props, children ...Node) *Element {
return newElement("main", attrs, children...)
}
// Nav creates a <nav> element.
func Nav(attrs attrs.Props, children ...Node) *Element {
return newElement("nav", attrs, children...)
}
// Section creates a <section> element.
func Section(attrs attrs.Props, children ...Node) *Element {
return newElement("section", attrs, children...)
}
// Details creates a <details> element.
func Details(attrs attrs.Props, children ...Node) *Element {
return newElement("details", attrs, children...)
}
// Summary creates a <summary> element.
func Summary(attrs attrs.Props, children ...Node) *Element {
return newElement("summary", attrs, children...)
}
// ========== Semantic Form Elements ==========
// Fieldset creates a <fieldset> element.
func Fieldset(attrs attrs.Props, children ...Node) *Element {
return newElement("fieldset", attrs, children...)
}
// Legend creates a <legend> element.
func Legend(attrs attrs.Props, children ...Node) *Element {
return newElement("legend", attrs, children...)
}
// Datalist creates a <datalist> element.
func Datalist(attrs attrs.Props, children ...Node) *Element {
return newElement("datalist", attrs, children...)
}
// Meter creates a <meter> element.
func Meter(attrs attrs.Props, children ...Node) *Element {
return newElement("meter", attrs, children...)
}
// Output creates an <output> element.
func Output(attrs attrs.Props, children ...Node) *Element {
return newElement("output", attrs, children...)
}
// Progress creates a <progress> element.
func Progress(attrs attrs.Props, children ...Node) *Element {
return newElement("progress", attrs, children...)
}
// --- Semantic Interactive Elements ---
// Dialog creates a <dialog> element.
func Dialog(attrs attrs.Props, children ...Node) *Element {
return newElement("dialog", attrs, children...)
}
// Menu creates a <menu> element.
func Menu(attrs attrs.Props, children ...Node) *Element {
return newElement("menu", attrs, children...)
}
// --- Semantic Script Supporting Elements ---
// NoScript creates a <noscript> element.
func NoScript(attrs attrs.Props, children ...Node) *Element {
return newElement("noscript", attrs, children...)
}
// --- Semantic Text Content Elements ---
// Abbr creates an <abbr> element.
func Abbr(attrs attrs.Props, children ...Node) *Element {
return newElement("abbr", attrs, children...)
}
// Address creates an <address> element.
func Address(attrs attrs.Props, children ...Node) *Element {
return newElement("address", attrs, children...)
}
// Cite creates a <cite> element.
func Cite(attrs attrs.Props, children ...Node) *Element {
return newElement("cite", attrs, children...)
}
// Data creates a <data> element.
func Data(attrs attrs.Props, children ...Node) *Element {
return newElement("data", attrs, children...)
}
// FigCaption creates a <figcaption> element.
func FigCaption(attrs attrs.Props, children ...Node) *Element {
return newElement("figcaption", attrs, children...)
}
// Figure creates a <figure> element.
func Figure(attrs attrs.Props, children ...Node) *Element {
return newElement("figure", attrs, children...)
}
// Kbd creates a <kbd> element.
func Kbd(attrs attrs.Props, children ...Node) *Element {
return newElement("kbd", attrs, children...)
}
// Mark creates a <mark> element.
func Mark(attrs attrs.Props, children ...Node) *Element {
return newElement("mark", attrs, children...)
}
// Q creates a <q> element.
func Q(attrs attrs.Props, children ...Node) *Element {
return newElement("q", attrs, children...)
}
// Samp creates a <samp> element.
func Samp(attrs attrs.Props, children ...Node) *Element {
return newElement("samp", attrs, children...)
}
// Small creates a <small> element.
func Small(attrs attrs.Props, children ...Node) *Element {
return newElement("small", attrs, children...)
}
// Time creates a <time> element.
func Time(attrs attrs.Props, children ...Node) *Element {
return newElement("time", attrs, children...)
}
// Var creates a <var> element.
func Var(attrs attrs.Props, children ...Node) *Element {
return newElement("var", attrs, children...)
}
// Ruby creates a <ruby> element.
func Ruby(attrs attrs.Props, children ...Node) *Element {
return newElement("ruby", attrs, children...)
}
// Rt creates a <rt> element.
func Rt(attrs attrs.Props, children ...Node) *Element {
return newElement("rt", attrs, children...)
}
// Rp creates a <rp> element.
func Rp(attrs attrs.Props, children ...Node) *Element {
return newElement("rp", attrs, children...)
}
// ========== Tables ==========
// Table creates a <table> element.
func Table(attrs attrs.Props, children ...Node) *Element {
return newElement("table", attrs, children...)
}
// THead creates a <thead> element.
func THead(attrs attrs.Props, children ...Node) *Element {
return newElement("thead", attrs, children...)
}
// TBody creates a <tbody> element.
func TBody(attrs attrs.Props, children ...Node) *Element {
return newElement("tbody", attrs, children...)
}
// TFoot creates a <tfoot> element.
func TFoot(attrs attrs.Props, children ...Node) *Element {
return newElement("tfoot", attrs, children...)
}
// Tr creates a <tr> element.
func Tr(attrs attrs.Props, children ...Node) *Element {
return newElement("tr", attrs, children...)
}
// Th creates a <th> element.
func Th(attrs attrs.Props, children ...Node) *Element {
return newElement("th", attrs, children...)
}
// Td creates a <td> element.
func Td(attrs attrs.Props, children ...Node) *Element {
return newElement("td", attrs, children...)
}
// ========== Embedded Content ==========
// IFrames creates an <iframe> element.
func IFrame(attrs attrs.Props, children ...Node) *Element {
return newElement("iframe", attrs, children...)
}
// Audio creates an <audio> element.
func Audio(attrs attrs.Props, children ...Node) *Element {
return newElement("audio", attrs, children...)
}
// Video creates a <video> element.
func Video(attrs attrs.Props, children ...Node) *Element {
return newElement("video", attrs, children...)
}
// Source creates a <source> element.
func Source(attrs attrs.Props, children ...Node) *Element {
return newElement("source", attrs, children...)
}
// ========== Image Map Elements ==========
// Map creates a <map> element.
func Map(attrs attrs.Props, children ...Node) *Element {
return newElement("map", attrs, children...)
}
// Area creates an <area> element.
func Area(attrs attrs.Props) *Element {
return newElement("area", attrs)
}
// ========== Other ==========
// None creates a NoneNode, representing a no-operation in rendering.
func None() NoneNode {
return NoneNode{}
}
// Raw takes html content and returns a RawNode.
func Raw(html string) RawNode {
return RawNode(html)
}
// CSS takes css content and returns a TextNode.
func CSS(content string) TextNode {
return TextNode(content)
}
// Fragments are a way to group multiple elements together without adding an extra node to the DOM.
func Fragment(children ...Node) *Element {
return newElement("fragment", attrs.Props{}, children...)
}