-
Notifications
You must be signed in to change notification settings - Fork 0
/
elements.go
561 lines (424 loc) Β· 13.5 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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
package react
import (
"fmt"
"html/template"
"strings"
)
func Comment(comment string, args ...any) *Element {
return HTMLString("<!-- " + template.HTMLEscapeString(fmt.Sprintf(comment, args...)) + " -->")
}
func Doctype(doctype ...any) *Element {
d := "html"
if len(doctype) > 0 {
if doctype[0] != nil {
dStr, ok := doctype[0].(string)
if ok && dStr != "" {
d = dStr
}
if strings.HasPrefix(d, "<!doctype") || strings.HasPrefix(d, "<!Doctype") || strings.HasPrefix(d, "<!DOCTYPE") {
return HTMLString(d)
}
}
}
return CreateFragment(HTMLString("<!doctype " + d + ">"))
}
func A(props Props, children ...*Element) *Element {
return CreateElement("a", props, children...)
}
func Abbr(props Props, children ...*Element) *Element {
return CreateElement("abbr", props, children...)
}
func Address(props Props, children ...*Element) *Element {
return CreateElement("address", props, children...)
}
func Area(props Props, children ...*Element) *Element {
return CreateElement("area", props, children...)
}
func Article(props Props, children ...*Element) *Element {
return CreateElement("article", props, children...)
}
func Aside(props Props, children ...*Element) *Element {
return CreateElement("aside", props, children...)
}
func Audio(props Props, children ...*Element) *Element {
return CreateElement("audio", props, children...)
}
func B(props Props, children ...*Element) *Element {
return CreateElement("b", props, children...)
}
func Base(props Props, children ...*Element) *Element {
return CreateElement("base", props, children...)
}
func Bdi(props Props, children ...*Element) *Element {
return CreateElement("bdi", props, children...)
}
func Bdo(props Props, children ...*Element) *Element {
return CreateElement("bdo", props, children...)
}
func Blockquote(props Props, children ...*Element) *Element {
return CreateElement("blockquote", props, children...)
}
func Body(props Props, children ...*Element) *Element {
return CreateElement("body", props, children...)
}
func Br() *Element {
return CreateElement("br", nil)
}
func Button(props Props, children ...*Element) *Element {
return CreateElement("button", props, children...)
}
func Canvas(props Props, children ...*Element) *Element {
return CreateElement("canvas", props, children...)
}
func Caption(props Props, children ...*Element) *Element {
return CreateElement("caption", props, children...)
}
func Cite(props Props, children ...*Element) *Element {
return CreateElement("cite", props, children...)
}
func Code(props Props, children ...*Element) *Element {
return CreateElement("code", props, children...)
}
func Col(props Props, children ...*Element) *Element {
return CreateElement("col", props, children...)
}
func Colgroup(props Props, children ...*Element) *Element {
return CreateElement("colgroup", props, children...)
}
func Data(props Props, children ...*Element) *Element {
return CreateElement("data", props, children...)
}
func Datalist(props Props, children ...*Element) *Element {
return CreateElement("datalist", props, children...)
}
func Dd(props Props, children ...*Element) *Element {
return CreateElement("dd", props, children...)
}
func Del(props Props, children ...*Element) *Element {
return CreateElement("del", props, children...)
}
func Details(props Props, children ...*Element) *Element {
return CreateElement("details", props, children...)
}
func Dfn(props Props, children ...*Element) *Element {
return CreateElement("dfn", props, children...)
}
func Dialog(props Props, children ...*Element) *Element {
return CreateElement("dialog", props, children...)
}
func Div(props Props, children ...*Element) *Element {
return CreateElement("div", props, children...)
}
func Dl(props Props, children ...*Element) *Element {
return CreateElement("dl", props, children...)
}
func Dt(props Props, children ...*Element) *Element {
return CreateElement("dt", props, children...)
}
func Em(props Props, children ...*Element) *Element {
return CreateElement("em", props, children...)
}
func Embed(props Props, children ...*Element) *Element {
return CreateElement("embed", props, children...)
}
func Fieldset(props Props, children ...*Element) *Element {
return CreateElement("fieldset", props, children...)
}
func Figure(props Props, children ...*Element) *Element {
return CreateElement("figure", props, children...)
}
func Footer(props Props, children ...*Element) *Element {
return CreateElement("footer", props, children...)
}
func Form(props Props, children ...*Element) *Element {
return CreateElement("form", props, children...)
}
func H1(props Props, children ...*Element) *Element {
return CreateElement("h1", props, children...)
}
func H2(props Props, children ...*Element) *Element {
return CreateElement("h2", props, children...)
}
func H3(props Props, children ...*Element) *Element {
return CreateElement("h3", props, children...)
}
func H4(props Props, children ...*Element) *Element {
return CreateElement("h4", props, children...)
}
func H5(props Props, children ...*Element) *Element {
return CreateElement("h5", props, children...)
}
func H6(props Props, children ...*Element) *Element {
return CreateElement("h6", props, children...)
}
func Head(props Props, children ...*Element) *Element {
return CreateElement("head", props, children...)
}
func Header(props Props, children ...*Element) *Element {
return CreateElement("header", props, children...)
}
func Hgroup(props Props, children ...*Element) *Element {
return CreateElement("hgroup", props, children...)
}
func Hr(props ...Props) *Element {
var p Props
if len(props) > 0 {
p = props[0]
}
return CreateElement("hr", p)
}
func Html(props Props, children ...*Element) *Element {
return CreateElement("html", props, children...)
}
func I(props Props, children ...*Element) *Element {
return CreateElement("i", props, children...)
}
func Iframe(props Props, children ...*Element) *Element {
return CreateElement("iframe", props, children...)
}
func Img(source any, alt string, props ...Props) *Element {
p := NewProps()
if len(props) > 0 && props[0] != nil {
p = props[0]
}
p["alt"] = alt
if source != nil && source != "" {
switch src := source.(type) {
case string:
p["src"] = src
break
case template.URL:
p["src"] = string(src)
break
}
}
return CreateElement("img", p)
}
func Input(props Props) *Element {
return CreateElement("input", props)
}
func Ins(props Props, children ...*Element) *Element {
return CreateElement("ins", props, children...)
}
func Kbd(props Props, children ...*Element) *Element {
return CreateElement("kbd", props, children...)
}
func Keygen(props Props, children ...*Element) *Element {
return CreateElement("keygen", props, children...)
}
func Label(props Props, children ...*Element) *Element {
return CreateElement("label", props, children...)
}
func Legend(props Props, children ...*Element) *Element {
return CreateElement("legend", props, children...)
}
func Li(props Props, children ...*Element) *Element {
return CreateElement("li", props, children...)
}
func Link(rel string, href any, props Props) *Element {
p := NewProps()
if props != nil {
p = props
}
if rel != "" {
p["rel"] = rel
}
if href != nil && href != "" {
switch src := href.(type) {
case string:
p["href"] = src
break
case template.URL:
p["href"] = string(src)
break
}
}
return CreateElement("link", p)
}
func Main(props Props, children ...*Element) *Element {
return CreateElement("main", props, children...)
}
func Map(props Props, children ...*Element) *Element {
return CreateElement("map", props, children...)
}
func Mark(props Props, children ...*Element) *Element {
return CreateElement("mark", props, children...)
}
func Menu(props Props, children ...*Element) *Element {
return CreateElement("menu", props, children...)
}
func Menuitem(props Props, children ...*Element) *Element {
return CreateElement("menuitem", props, children...)
}
func Meter(props Props, children ...*Element) *Element {
return CreateElement("meter", props, children...)
}
func Nav(props Props, children ...*Element) *Element {
return CreateElement("nav", props, children...)
}
func Noscript(children ...*Element) *Element {
return CreateElement("noscript", nil, children...)
}
func Object(props Props, children ...*Element) *Element {
return CreateElement("object", props, children...)
}
func Ol(props Props, children ...*Element) *Element {
return CreateElement("ol", props, children...)
}
func Optgroup(props Props, children ...*Element) *Element {
return CreateElement("optgroup", props, children...)
}
func Option(props Props, children ...*Element) *Element {
return CreateElement("option", props, children...)
}
func Output(props Props, children ...*Element) *Element {
return CreateElement("output", props, children...)
}
func P(props Props, children ...*Element) *Element {
return CreateElement("p", props, children...)
}
func Param(props Props, children ...*Element) *Element {
return CreateElement("param", props, children...)
}
func Pre(props Props, children ...*Element) *Element {
return CreateElement("pre", props, children...)
}
func Progress(props Props, children ...*Element) *Element {
return CreateElement("progress", props, children...)
}
func Q(props Props, children ...*Element) *Element {
return CreateElement("q", props, children...)
}
func Rb(props Props, children ...*Element) *Element {
return CreateElement("rb", props, children...)
}
func Rp(props Props, children ...*Element) *Element {
return CreateElement("rp", props, children...)
}
func Rt(props Props, children ...*Element) *Element {
return CreateElement("rt", props, children...)
}
func Rtc(props Props, children ...*Element) *Element {
return CreateElement("rtc", props, children...)
}
func Ruby(props Props, children ...*Element) *Element {
return CreateElement("ruby", props, children...)
}
func S(props Props, children ...*Element) *Element {
return CreateElement("s", props, children...)
}
func Samp(props Props, children ...*Element) *Element {
return CreateElement("samp", props, children...)
}
func Script(source any, props Props) *Element {
var children template.JS
p := NewProps()
if props != nil {
p = props
}
if source != nil && source != "" {
switch src := source.(type) {
case string:
p["src"] = src
break
case template.URL:
p["src"] = string(src)
break
case template.JS:
children = src
break
}
}
if !p.Has("type") {
p["type"] = "application/javascript"
}
return CreateElement("script", p, JS(children))
}
func Section(props Props, children ...*Element) *Element {
return CreateElement("section", props, children...)
}
func Select(props Props, children ...*Element) *Element {
return CreateElement("select", props, children...)
}
func Small(props Props, children ...*Element) *Element {
return CreateElement("small", props, children...)
}
func Source(props Props, children ...*Element) *Element {
return CreateElement("source", props, children...)
}
func Span(props Props, children ...*Element) *Element {
return CreateElement("span", props, children...)
}
func Strong(props Props, children ...*Element) *Element {
return CreateElement("strong", props, children...)
}
func StyleTag(style template.CSS, props ...Props) *Element {
p := NewProps()
if len(props) > 0 && props[0] != nil {
p = props[0]
}
if !p.Has("type") {
p["type"] = "text/css"
}
return CreateElement("style", p, CSS(style))
}
func Sub(props Props, children ...*Element) *Element {
return CreateElement("sub", props, children...)
}
func Summary(props Props, children ...*Element) *Element {
return CreateElement("summary", props, children...)
}
func Sup(props Props, children ...*Element) *Element {
return CreateElement("sup", props, children...)
}
func Table(props Props, children ...*Element) *Element {
return CreateElement("table", props, children...)
}
func Tbody(props Props, children ...*Element) *Element {
return CreateElement("tbody", props, children...)
}
func Td(props Props, children ...*Element) *Element {
return CreateElement("td", props, children...)
}
func Template(props Props, children ...*Element) *Element {
return CreateElement("template", props, children...)
}
func Textarea(props Props, children ...*Element) *Element {
return CreateElement("textarea", props, children...)
}
func Tfoot(props Props, children ...*Element) *Element {
return CreateElement("tfoot", props, children...)
}
func Th(props Props, children ...*Element) *Element {
return CreateElement("th", props, children...)
}
func Thead(props Props, children ...*Element) *Element {
return CreateElement("thead", props, children...)
}
func Time(props Props, children ...*Element) *Element {
return CreateElement("time", props, children...)
}
func Title(title string, args ...any) *Element {
return CreateElement("title", nil, Textf(title, args...))
}
func Tr(props Props, children ...*Element) *Element {
return CreateElement("tr", props, children...)
}
func Track(props Props, children ...*Element) *Element {
return CreateElement("track", props, children...)
}
func U(props Props, children ...*Element) *Element {
return CreateElement("u", props, children...)
}
func Ul(props Props, children ...*Element) *Element {
return CreateElement("ul", props, children...)
}
func Var(props Props, children ...*Element) *Element {
return CreateElement("var", props, children...)
}
func Video(props Props, children ...*Element) *Element {
return CreateElement("video", props, children...)
}
func Wbr(props Props, children ...*Element) *Element {
return CreateElement("wbr", props, children...)
}