1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Biurad opensource projects. |
7
|
|
|
* |
8
|
|
|
* PHP version 7.2 and above required |
9
|
|
|
* |
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
11
|
|
|
* @copyright 2019 Biurad Group (https://biurad.com/) |
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
15
|
|
|
* file that was distributed with this source code. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Biurad\UI\Html { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The `<canvas>` HTML element with either the canvas scripting API or |
22
|
|
|
* the WebGL API to draw graphics and animations. |
23
|
|
|
* |
24
|
|
|
* @param array<int,string> $children The Element children |
25
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
26
|
|
|
* |
27
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas |
28
|
|
|
*/ |
29
|
|
|
function canvas($children, array $attributes = []): string |
30
|
|
|
{ |
31
|
|
|
return createElement('canvas', $attributes + ['children' => $children]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The `<script>` HTML element is used to embed executable code or data. |
36
|
|
|
* |
37
|
|
|
* @param string|array<int,string> $src The internal/external scripts to apply |
38
|
|
|
* @param array<string,mixed> $attributes The attributes for script tag |
39
|
|
|
* |
40
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script |
41
|
|
|
*/ |
42
|
|
|
function script($src, string $type = null, array $attributes = []): string |
43
|
|
|
{ |
44
|
|
|
$attributes += (\is_string($src) && 'j' === $src[-2] ? ['src' => $src, 'type' => $type] : ['children' => $src]); |
45
|
|
|
|
46
|
|
|
return createElement('script', $attributes); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The `<noscript>` HTML element defines a section of HTML to be inserted if a script type |
51
|
|
|
* on the page is unsupported or if scripting is currently turned off in the browser. |
52
|
|
|
* |
53
|
|
|
* @param array<int,string> $children The Element children |
54
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
55
|
|
|
* |
56
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript |
57
|
|
|
*/ |
58
|
|
|
function noscript($children, array $attributes = []): string |
59
|
|
|
{ |
60
|
|
|
return createElement('noscript', $attributes + ['children' => $children]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* The `<html>` HTML element represents the root (top-level element) of an HTML document. |
65
|
|
|
* |
66
|
|
|
* @param array<int,string> $children The Element children |
67
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
68
|
|
|
* |
69
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html |
70
|
|
|
*/ |
71
|
|
|
function html(array $children, array $attributes = []): string |
72
|
|
|
{ |
73
|
1 |
|
$attributes['children'] = $children; |
74
|
|
|
|
75
|
1 |
|
return createElement('!Doctype html', [], false) . createElement('html', $attributes); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* The `<head>` HTML element contains machine-readable information (metadata) about the document. |
80
|
|
|
* |
81
|
|
|
* @param array<int,string> $children The Element children |
82
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
83
|
|
|
* |
84
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head |
85
|
|
|
*/ |
86
|
|
|
function head(array $children, array $attributes = []): string |
87
|
|
|
{ |
88
|
1 |
|
$attributes['children'] = $children; |
89
|
|
|
|
90
|
1 |
|
return createElement('head', $attributes); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* The `<base>` HTML element specifies the base URL to use for all relative URLs in a document. |
95
|
|
|
* |
96
|
|
|
* This element must come before other elements with attribute values of URLs, |
97
|
|
|
* such as `<link>`’s href attribute. |
98
|
|
|
* |
99
|
|
|
* @param string $href The base URL to be used throughout the document for relative URLs |
100
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
101
|
|
|
* |
102
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base |
103
|
|
|
*/ |
104
|
|
|
function base(string $href, array $attributes = []): string |
105
|
|
|
{ |
106
|
|
|
$attributes += ['target' => '__self', 'href' => $href]; |
107
|
|
|
|
108
|
|
|
return createElement('base', $attributes, false); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* The `<title>` HTML element defines the document's title that is shown in a Browser's title bar. |
113
|
|
|
* |
114
|
|
|
* @param string $content The Document Title |
115
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
116
|
|
|
* |
117
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title |
118
|
|
|
*/ |
119
|
|
|
function title(string $content, array $attributes = []): string |
120
|
|
|
{ |
121
|
1 |
|
$attributes['children'] = $content; |
122
|
|
|
|
123
|
1 |
|
return createElement('title', $attributes); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* The `<link>` HTML element specifies relationships between the current document and an external resource. |
128
|
|
|
* |
129
|
|
|
* @param string $href This attribute specifies the URL of the linked resource |
130
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
131
|
|
|
* |
132
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link |
133
|
|
|
*/ |
134
|
|
|
function link(string $href, array $attributes = []): string |
135
|
|
|
{ |
136
|
|
|
$attributes += ['href' => $href, 'rel' => 'stylesheet']; |
137
|
|
|
|
138
|
|
|
return createElement('link', $attributes, false); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* The `<meta>` HTML element represents metadata that cannot be represented |
143
|
|
|
* by other HTML meta-related elements. |
144
|
|
|
* |
145
|
|
|
* @param string $content the charset value if empty $attributes |
146
|
|
|
* else passed as the content attribute of the (meta) tag |
147
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
148
|
|
|
* |
149
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta |
150
|
|
|
*/ |
151
|
|
|
function meta(string $content, array $attributes = []): string |
152
|
|
|
{ |
153
|
1 |
|
$attributes[empty($attributes) ? 'charset' : 'content'] = $content; |
154
|
|
|
|
155
|
1 |
|
return createElement('meta', $attributes, false); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Import stylesheet or Use a css styling for the `<style>` HTML Element. |
160
|
|
|
* |
161
|
|
|
* @param string|array<string,string> $children The styles/stylesheet to apply |
162
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
163
|
|
|
* |
164
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style |
165
|
|
|
*/ |
166
|
|
|
function style($children, array $attributes = []): string |
167
|
|
|
{ |
168
|
1 |
|
if (\is_array($children)) { |
169
|
1 |
|
$children = HtmlElement::cssFromArray($children); |
170
|
|
|
} elseif (\file_exists($children)) { |
171
|
|
|
$children = \file_get_contents($children); |
172
|
|
|
} |
173
|
|
|
|
174
|
1 |
|
$attributes['children'] = $children; |
175
|
1 |
|
$attributes += ['type' => 'text/javascript']; |
176
|
|
|
|
177
|
1 |
|
return createElement('style', $attributes); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* The `<body>` HTML element represents the content of an HTML document. |
182
|
|
|
* |
183
|
|
|
* @param array<int,string> $children The Element children |
184
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
185
|
|
|
* |
186
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body |
187
|
|
|
*/ |
188
|
|
|
function body(array $children, array $attributes = []): string |
189
|
|
|
{ |
190
|
1 |
|
$attributes['children'] = $children; |
191
|
|
|
|
192
|
1 |
|
return createElement('body', $attributes); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* The `<address>` HTML element indicates that the enclosed HTML provides contact |
197
|
|
|
* information for a person or people, or for an organization. |
198
|
|
|
* |
199
|
|
|
* @param string|array<int,string> $children The Element children |
200
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
201
|
|
|
* |
202
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/address |
203
|
|
|
*/ |
204
|
|
|
function address($children, array $attributes = []): string |
205
|
|
|
{ |
206
|
|
|
$attributes['children'] = $children; |
207
|
|
|
|
208
|
|
|
return createElement('address', $attributes); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* The `<article>` HTML element represents a self-contained composition in a |
213
|
|
|
* document, page, application, or site, which is intended to be independently |
214
|
|
|
* distributable or reusable (e.g., in syndication). |
215
|
|
|
* |
216
|
|
|
* @param string|array<int,string> $children The Element children |
217
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
218
|
|
|
* |
219
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article |
220
|
|
|
*/ |
221
|
|
|
function article($children, array $attributes = []): string |
222
|
|
|
{ |
223
|
|
|
$attributes['children'] = $children; |
224
|
|
|
|
225
|
|
|
return createElement('article', $attributes); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* The `<aside>` HTML element represents a portion of a document whose content |
230
|
|
|
* is only indirectly related to the document's main content. |
231
|
|
|
* |
232
|
|
|
* @param string|array<int,string> $children The Element children |
233
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
234
|
|
|
* |
235
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside |
236
|
|
|
*/ |
237
|
|
|
function aside($children, array $attributes = []): string |
238
|
|
|
{ |
239
|
|
|
$attributes['children'] = $children; |
240
|
|
|
|
241
|
|
|
return createElement('aside', $attributes); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* The `<header>` HTML element represents introductory content, |
246
|
|
|
* typically a group of introductory or navigational aids. |
247
|
|
|
* |
248
|
|
|
* @param string|array<int,string> $children The Element children |
249
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
250
|
|
|
* |
251
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header |
252
|
|
|
*/ |
253
|
|
|
function header($children, array $attributes = []): string |
254
|
|
|
{ |
255
|
|
|
$attributes['children'] = $children; |
256
|
|
|
|
257
|
|
|
return createElement('header', $attributes); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* The `<footer>` HTML element represents a footer for its nearest |
262
|
|
|
* sectioning content or sectioning root element. |
263
|
|
|
* |
264
|
|
|
* @param string|array<int,string> $children The Element children |
265
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
266
|
|
|
* |
267
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer |
268
|
|
|
*/ |
269
|
|
|
function footer($children, array $attributes = []): string |
270
|
|
|
{ |
271
|
|
|
$attributes['children'] = $children; |
272
|
|
|
|
273
|
|
|
return createElement('footer', $attributes); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* The `<h6>` HTML Section Heading element. |
278
|
|
|
* |
279
|
|
|
* @param string|array<int,string> $children The Element children |
280
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
281
|
|
|
* |
282
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements |
283
|
|
|
*/ |
284
|
|
|
function h6($children, array $attributes = []): string |
285
|
|
|
{ |
286
|
|
|
$attributes['children'] = $children; |
287
|
|
|
|
288
|
|
|
return createElement('h6', $attributes); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* The `<h5>` HTML Section Heading element. |
293
|
|
|
* |
294
|
|
|
* @param string|array<int,string> $children The Element children |
295
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
296
|
|
|
* |
297
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements |
298
|
|
|
*/ |
299
|
|
|
function h5($children, array $attributes = []): string |
300
|
|
|
{ |
301
|
|
|
$attributes['children'] = $children; |
302
|
|
|
|
303
|
|
|
return createElement('h5', $attributes); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* The `<h4>` HTML Section Heading element. |
308
|
|
|
* |
309
|
|
|
* @param string|array<int,string> $children The Element children |
310
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
311
|
|
|
* |
312
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements |
313
|
|
|
*/ |
314
|
|
|
function h4($children, array $attributes = []): string |
315
|
|
|
{ |
316
|
|
|
$attributes['children'] = $children; |
317
|
|
|
|
318
|
|
|
return createElement('h4', $attributes); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* The `<h3>` HTML Section Heading element. |
323
|
|
|
* |
324
|
|
|
* @param string|array<int,string> $children The Element children |
325
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
326
|
|
|
* |
327
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements |
328
|
|
|
*/ |
329
|
|
|
function h3($children, array $attributes = []): string |
330
|
|
|
{ |
331
|
|
|
$attributes['children'] = $children; |
332
|
|
|
|
333
|
|
|
return createElement('h3', $attributes); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* The `<h2>` HTML Section Heading element. |
338
|
|
|
* |
339
|
|
|
* @param string|array<int,string> $children The Element children |
340
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
341
|
|
|
* |
342
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements |
343
|
|
|
*/ |
344
|
|
|
function h2($children, array $attributes = []): string |
345
|
|
|
{ |
346
|
|
|
$attributes['children'] = $children; |
347
|
|
|
|
348
|
|
|
return createElement('h2', $attributes); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* The `<h1>` HTML Section Heading element. |
353
|
|
|
* |
354
|
|
|
* @param string|array<int,string> $children The Element children |
355
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
356
|
|
|
* |
357
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements |
358
|
|
|
*/ |
359
|
|
|
function h1($children, array $attributes = []): string |
360
|
|
|
{ |
361
|
1 |
|
$attributes['children'] = $children; |
362
|
|
|
|
363
|
1 |
|
return createElement('h1', $attributes); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* The `<nav>` HTML element represents a section of a page whose purpose is to provide |
368
|
|
|
* navigation links, either within the current document or to other documents. |
369
|
|
|
* |
370
|
|
|
* @param string|array<int,string> $children The Element children |
371
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
372
|
|
|
* |
373
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nav |
374
|
|
|
*/ |
375
|
|
|
function nav($children, array $attributes = []): string |
376
|
|
|
{ |
377
|
|
|
$attributes['children'] = $children; |
378
|
|
|
|
379
|
|
|
return createElement('nav', $attributes); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* The `<main>` HTML element represents the dominant content of the body of a document. |
384
|
|
|
* |
385
|
|
|
* @param string|array<int,string> $children The Element children |
386
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
387
|
|
|
* |
388
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/main |
389
|
|
|
*/ |
390
|
|
|
function main($children, array $attributes = []): string |
391
|
|
|
{ |
392
|
|
|
$attributes['children'] = $children; |
393
|
|
|
|
394
|
|
|
return createElement('main', $attributes); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* The `<section>` HTML element represents a generic standalone section of a document, |
399
|
|
|
* which doesn't have a more specific semantic element to represent it. |
400
|
|
|
* |
401
|
|
|
* @param string|array<int,string> $children The Element children |
402
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
403
|
|
|
* |
404
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section |
405
|
|
|
*/ |
406
|
|
|
function section($children, array $attributes = []): string |
407
|
|
|
{ |
408
|
|
|
$attributes['children'] = $children; |
409
|
|
|
|
410
|
|
|
return createElement('section', $attributes); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* The `<blockquote>` HTML element indicates that the enclosed text is an extended quotation. |
415
|
|
|
* |
416
|
|
|
* @param string|array<int,string> $children The Element children |
417
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
418
|
|
|
* |
419
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/blockquote |
420
|
|
|
*/ |
421
|
|
|
function blockquote($children, array $attributes = []): string |
422
|
|
|
{ |
423
|
|
|
$attributes['children'] = $children; |
424
|
|
|
|
425
|
|
|
return createElement('blockquote', $attributes); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* The `<dd>` HTML element provides the description, definition, |
430
|
|
|
* or value for the preceding term (dt) in a description list (dl). |
431
|
|
|
* |
432
|
|
|
* @param string|array<int,string> $children The Element children |
433
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
434
|
|
|
* |
435
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dd |
436
|
|
|
*/ |
437
|
|
|
function dd($children, array $attributes = []): string |
438
|
|
|
{ |
439
|
|
|
$attributes['children'] = $children; |
440
|
|
|
|
441
|
|
|
return createElement('dd', $attributes); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* The `<div>` HTML element is the generic container for flow content. |
446
|
|
|
* |
447
|
|
|
* @param string|array<int,string> $children The Element children |
448
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
449
|
|
|
* |
450
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div |
451
|
|
|
*/ |
452
|
|
|
function div($children, array $attributes = []): string |
453
|
|
|
{ |
454
|
1 |
|
$attributes['children'] = $children; |
455
|
|
|
|
456
|
1 |
|
return createElement('div', $attributes); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* The `<dl>` HTML element represents a description list. |
461
|
|
|
* |
462
|
|
|
* @param string|array<int,string> $children The Element children |
463
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
464
|
|
|
* |
465
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl |
466
|
|
|
*/ |
467
|
|
|
function dl($children, array $attributes = []): string |
468
|
|
|
{ |
469
|
|
|
$attributes['children'] = $children; |
470
|
|
|
|
471
|
|
|
return createElement('dl', $attributes); |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/** |
475
|
|
|
* The `<dt>` HTML element specifies a term in a description or definition list, |
476
|
|
|
* and as such must be used inside a dl element. |
477
|
|
|
* |
478
|
|
|
* @param string|array<int,string> $children The Element children |
479
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
480
|
|
|
* |
481
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dt |
482
|
|
|
*/ |
483
|
|
|
function dt($children, array $attributes = []): string |
484
|
|
|
{ |
485
|
|
|
$attributes['children'] = $children; |
486
|
|
|
|
487
|
|
|
return createElement('dt', $attributes); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* The `<figcaption>` HTML element represents a caption or legend describing |
492
|
|
|
* the rest of the contents of its parent figure element. |
493
|
|
|
* |
494
|
|
|
* @param string|array<int,string> $children The Element children |
495
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
496
|
|
|
* |
497
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption |
498
|
|
|
*/ |
499
|
|
|
function figcaption($children, array $attributes = []): string |
500
|
|
|
{ |
501
|
|
|
$attributes['children'] = $children; |
502
|
|
|
|
503
|
|
|
return createElement('figcaption', $attributes); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* The `<figure>` HTML element represents self-contained content, potentially |
508
|
|
|
* with an optional caption, which is specified using the figcaption element. |
509
|
|
|
* |
510
|
|
|
* @param string|array<int,string> $children The Element children |
511
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
512
|
|
|
* |
513
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption |
514
|
|
|
*/ |
515
|
|
|
function figure($children, array $attributes = []): string |
516
|
|
|
{ |
517
|
|
|
$attributes['children'] = $children; |
518
|
|
|
|
519
|
|
|
return createElement('figure', $attributes); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* The `<hr>` HTML element represents a thematic break between paragraph-level elements. |
524
|
|
|
* |
525
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
526
|
|
|
* |
527
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hr |
528
|
|
|
*/ |
529
|
|
|
function hr(array $attributes = []): string |
530
|
|
|
{ |
531
|
1 |
|
return createElement('hr', $attributes, false); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* The `<li>` HTML element is used to represent an item in a list. |
536
|
|
|
* |
537
|
|
|
* @param string|array<int,string> $children The Element children |
538
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
539
|
|
|
* |
540
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li |
541
|
|
|
*/ |
542
|
|
|
function li($children, array $attributes = []): string |
543
|
|
|
{ |
544
|
1 |
|
$attributes['children'] = $children; |
545
|
|
|
|
546
|
1 |
|
return createElement('li', $attributes); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* The `<ol>` HTML element represents an ordered list of items — typically rendered as a numbered list. |
551
|
|
|
* |
552
|
|
|
* @param string|array<int,string> $children The Element children |
553
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
554
|
|
|
* |
555
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol |
556
|
|
|
*/ |
557
|
|
|
function ol($children, array $attributes = []): string |
558
|
|
|
{ |
559
|
|
|
$attributes['children'] = $children; |
560
|
|
|
|
561
|
|
|
return createElement('ol', $attributes); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* The `<p>` HTML element represents a paragraph. |
566
|
|
|
* |
567
|
|
|
* @param string|array<int,string> $children The Element children |
568
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
569
|
|
|
* |
570
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p |
571
|
|
|
*/ |
572
|
|
|
function p($children, array $attributes = []): string |
573
|
|
|
{ |
574
|
1 |
|
$attributes['children'] = $children; |
575
|
|
|
|
576
|
1 |
|
return createElement('p', $attributes); |
577
|
|
|
} |
578
|
|
|
/** |
579
|
|
|
* The <pre> HTML element represents preformatted text which is to be presented exactly as written in the HTML file. |
580
|
|
|
* |
581
|
|
|
* @param string|array<int,string> $children The Element children |
582
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
583
|
|
|
* |
584
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre |
585
|
|
|
*/ |
586
|
|
|
function pre($children, array $attributes = []): string |
587
|
|
|
{ |
588
|
|
|
$attributes['children'] = $children; |
589
|
|
|
|
590
|
|
|
return createElement('pre', $attributes); |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* The `<ul>` HTML element represents an unordered list of items, typically rendered as a bulleted list. |
595
|
|
|
* |
596
|
|
|
* @param string|array<int,string> $children The Element children |
597
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
598
|
|
|
* |
599
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul |
600
|
|
|
*/ |
601
|
|
|
function ul($children, array $attributes = []): string |
602
|
|
|
{ |
603
|
1 |
|
$attributes['children'] = $children; |
604
|
|
|
|
605
|
1 |
|
return createElement('ul', $attributes); |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
/** |
609
|
|
|
* The `<a>` HTML element (or anchor element), with its href attribute, creates a hyperlink. |
610
|
|
|
* |
611
|
|
|
* @param string $href The URL that the hyperlink points to |
612
|
|
|
* @param string|array<int,string> $children The Element children |
613
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
614
|
|
|
* |
615
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a |
616
|
|
|
*/ |
617
|
|
|
function a(string $href, $children = [], array $attributes = []): string |
618
|
|
|
{ |
619
|
1 |
|
$attributes += ['href' => $href, 'children' => $children]; |
620
|
|
|
|
621
|
1 |
|
return createElement('a', $attributes); |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
/** |
625
|
|
|
* The `<abbr>` HTML element represents an abbreviation or acronym; |
626
|
|
|
* the optional title attribute can provide an expansion or description for the abbreviation. |
627
|
|
|
* |
628
|
|
|
* @param string|array<int,string> $children The Element children |
629
|
|
|
* @param string|null $title if present, must contain this full description |
630
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
631
|
|
|
* |
632
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/abbr |
633
|
|
|
*/ |
634
|
|
|
function abbr($children = [], string $title = null, array $attributes = []): string |
635
|
|
|
{ |
636
|
|
|
if (null !== $title) { |
637
|
|
|
$attributes['title'] = $title; |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
$attributes['children'] = $children; |
641
|
|
|
|
642
|
|
|
return createElement('abbr', $attributes); |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
/** |
646
|
|
|
* The `<b>` HTML element is used to draw the reader's attention to the element's contents, |
647
|
|
|
* which are not otherwise granted special importance. |
648
|
|
|
* |
649
|
|
|
* @param string|array<int,string> $children The Element children |
650
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
651
|
|
|
* |
652
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/b |
653
|
|
|
*/ |
654
|
|
|
function b($children = [], array $attributes = []): string |
655
|
|
|
{ |
656
|
|
|
$attributes['children'] = $children; |
657
|
|
|
|
658
|
|
|
return createElement('b', $attributes); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
/** |
662
|
|
|
* The `<bdi>` HTML element tells the browser's bidirectional algorithm to treat |
663
|
|
|
* the text it contains in isolation from its surrounding text. |
664
|
|
|
* |
665
|
|
|
* @param string|array<int,string> $children The Element children |
666
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
667
|
|
|
* |
668
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdi |
669
|
|
|
*/ |
670
|
|
|
function bdi($children, array $attributes = []): string |
671
|
|
|
{ |
672
|
|
|
$attributes['children'] = $children; |
673
|
|
|
|
674
|
|
|
return createElement('bdi', $attributes); |
675
|
|
|
} |
676
|
|
|
|
677
|
|
|
/** |
678
|
|
|
* The `<bdi>` HTML element tells the browser's bidirectional algorithm to treat |
679
|
|
|
* the text it contains in isolation from its surrounding text. |
680
|
|
|
* |
681
|
|
|
* @param string|array<int,string> $children The Element children |
682
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
683
|
|
|
* |
684
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdo |
685
|
|
|
*/ |
686
|
|
|
function bdo($children, array $attributes = []): string |
687
|
|
|
{ |
688
|
|
|
$attributes['children'] = $children; |
689
|
|
|
|
690
|
|
|
return createElement('bdo', $attributes); |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
/** |
694
|
|
|
* The `<br>` HTML element produces a line break in text (carriage-return). |
695
|
|
|
* |
696
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
697
|
|
|
* |
698
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br |
699
|
|
|
*/ |
700
|
|
|
function br(array $attributes = []): string |
701
|
|
|
{ |
702
|
1 |
|
return createElement('br', $attributes, true); |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
/** |
706
|
|
|
* The `<cite>` HTML element is used to describe a reference to a cited creative work, |
707
|
|
|
* and must include the title of that work. |
708
|
|
|
* |
709
|
|
|
* @param string|array<int,string> $children The Element children |
710
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
711
|
|
|
* |
712
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/cite |
713
|
|
|
*/ |
714
|
|
|
function cite($children, array $attributes = []): string |
715
|
|
|
{ |
716
|
|
|
$attributes['children'] = $children; |
717
|
|
|
|
718
|
|
|
return createElement('cite', $attributes); |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
/** |
722
|
|
|
* The `<code>` HTML element displays its contents styled in a fashion intended to |
723
|
|
|
* indicate that the text is a short fragment of computer code. |
724
|
|
|
* |
725
|
|
|
* @param string|array<int,string> $children The Element children |
726
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
727
|
|
|
* |
728
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code |
729
|
|
|
*/ |
730
|
|
|
function code($children, array $attributes = []): string |
731
|
|
|
{ |
732
|
|
|
$attributes['children'] = $children; |
733
|
|
|
|
734
|
|
|
return createElement('code', $attributes); |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
/** |
738
|
|
|
* The `<code>` HTML element displays its contents styled in a fashion intended to |
739
|
|
|
* indicate that the text is a short fragment of computer code. |
740
|
|
|
* |
741
|
|
|
* @param string $value specifies the machine-readable translation |
742
|
|
|
* of the content of the element |
743
|
|
|
* @param string|array<int,string> $children The Element children |
744
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
745
|
|
|
* |
746
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data |
747
|
|
|
*/ |
748
|
|
|
function data(string $value, $children, array $attributes = []): string |
749
|
|
|
{ |
750
|
|
|
$attributes['value'] = $value; |
751
|
|
|
$attributes['children'] = $children; |
752
|
|
|
|
753
|
|
|
return createElement('data', $attributes); |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* The `<dfn>` HTML element is used to indicate the term being defined |
758
|
|
|
* within the context of a definition phrase or sentence. |
759
|
|
|
* |
760
|
|
|
* @param string|array<int,string> $children The Element children |
761
|
|
|
* @param string|null $title id preset, it must contain the term being |
762
|
|
|
* defined and no other text |
763
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
764
|
|
|
* |
765
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dfn |
766
|
|
|
*/ |
767
|
|
|
function dfn($children, string $title = null, array $attributes = []): string |
768
|
|
|
{ |
769
|
|
|
if (null !== $title) { |
770
|
|
|
$attributes['title'] = $title; |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
$attributes['children'] = $children; |
774
|
|
|
|
775
|
|
|
return createElement('dfn', $attributes); |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
/** |
779
|
|
|
* The `<em>` HTML element marks text that has stress emphasis. |
780
|
|
|
* |
781
|
|
|
* @param string|array<int,string> $children The Element children |
782
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
783
|
|
|
* |
784
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em |
785
|
|
|
*/ |
786
|
|
|
function em($children, array $attributes = []): string |
787
|
|
|
{ |
788
|
|
|
$attributes['children'] = $children; |
789
|
|
|
|
790
|
|
|
return createElement('em', $attributes); |
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
/** |
794
|
|
|
* The `<i>` HTML element represents a range of text that is set off from the normal |
795
|
|
|
* text for some reason, such as idiomatic text, technical terms, taxonomical designations, among others. |
796
|
|
|
* |
797
|
|
|
* @param string|array<int,string> $children The Element children |
798
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
799
|
|
|
* |
800
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i |
801
|
|
|
*/ |
802
|
|
|
function i($children, array $attributes = []): string |
803
|
|
|
{ |
804
|
|
|
$attributes['children'] = $children; |
805
|
|
|
|
806
|
|
|
return createElement('i', $attributes); |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
/** |
810
|
|
|
* The `<kbd>` HTML element represents a span of inline text denoting textual user |
811
|
|
|
* input from a keyboard, voice input, or any other text entry device. |
812
|
|
|
* |
813
|
|
|
* @param string|array<int,string> $children The Element children |
814
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
815
|
|
|
* |
816
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd |
817
|
|
|
*/ |
818
|
|
|
function kbd($children, array $attributes = []): string |
819
|
|
|
{ |
820
|
|
|
$attributes['children'] = $children; |
821
|
|
|
|
822
|
|
|
return createElement('kbd', $attributes); |
823
|
|
|
} |
824
|
|
|
|
825
|
|
|
/** |
826
|
|
|
* The `<mark>` HTML element represents text which is marked or highlighted for reference or |
827
|
|
|
* notation purposes, due to the marked passage's relevance or importance in the enclosing context. |
828
|
|
|
* |
829
|
|
|
* @param string|array<int,string> $children The Element children |
830
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
831
|
|
|
* |
832
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark |
833
|
|
|
*/ |
834
|
|
|
function mark($children, array $attributes = []): string |
835
|
|
|
{ |
836
|
|
|
$attributes['children'] = $children; |
837
|
|
|
|
838
|
|
|
return createElement('mark', $attributes); |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
/** |
842
|
|
|
* The `<q>` HTML element indicates that the enclosed text is a short inline quotation. |
843
|
|
|
* |
844
|
|
|
* @param string|array<int,string> $children The Element children |
845
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
846
|
|
|
* |
847
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q |
848
|
|
|
*/ |
849
|
|
|
function q($children, array $attributes = []): string |
850
|
|
|
{ |
851
|
|
|
$attributes['children'] = $children; |
852
|
|
|
|
853
|
|
|
return createElement('q', $attributes); |
854
|
|
|
} |
855
|
|
|
/** |
856
|
|
|
* The `<rp>` HTML element is used to provide fall-back parentheses for browsers |
857
|
|
|
* that do not support display of ruby annotations using the ruby element. |
858
|
|
|
* |
859
|
|
|
* @param string|array<int,string> $children The Element children |
860
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
861
|
|
|
* |
862
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rp |
863
|
|
|
*/ |
864
|
|
|
function rp($children, array $attributes = []): string |
865
|
|
|
{ |
866
|
|
|
$attributes['children'] = $children; |
867
|
|
|
|
868
|
|
|
return createElement('rp', $attributes); |
869
|
|
|
} |
870
|
|
|
/** |
871
|
|
|
* The `<rt>` HTML element specifies the ruby text component of a ruby annotation, |
872
|
|
|
* which is used to provide pronunciation, translation, or transliteration |
873
|
|
|
* information for East Asian typography. |
874
|
|
|
* |
875
|
|
|
* @param string|array<int,string> $children The Element children |
876
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
877
|
|
|
* |
878
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rt |
879
|
|
|
*/ |
880
|
|
|
function rt($children, array $attributes = []): string |
881
|
|
|
{ |
882
|
|
|
$attributes['children'] = $children; |
883
|
|
|
|
884
|
|
|
return createElement('rt', $attributes); |
885
|
|
|
} |
886
|
|
|
/** |
887
|
|
|
* The `<ruby>` HTML element represents small annotations that are rendered above, below, |
888
|
|
|
* or next to base text, usually used for showing the pronunciation of East Asian characters. |
889
|
|
|
* |
890
|
|
|
* @param string|array<int,string> $children The Element children |
891
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
892
|
|
|
* |
893
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby |
894
|
|
|
*/ |
895
|
|
|
function ruby($children, array $attributes = []): string |
896
|
|
|
{ |
897
|
|
|
$attributes['children'] = $children; |
898
|
|
|
|
899
|
|
|
return createElement('ruby', $attributes); |
900
|
|
|
} |
901
|
|
|
/** |
902
|
|
|
* The `<s>` HTML element renders text with a strikethrough, or a line through it. |
903
|
|
|
* |
904
|
|
|
* @param string|array<int,string> $children The Element children |
905
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
906
|
|
|
* |
907
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/s |
908
|
|
|
*/ |
909
|
|
|
function s($children, array $attributes = []): string |
910
|
|
|
{ |
911
|
|
|
$attributes['children'] = $children; |
912
|
|
|
|
913
|
|
|
return createElement('s', $attributes); |
914
|
|
|
} |
915
|
|
|
/** |
916
|
|
|
* The `<samp>` HTML element is used to enclose inline text which represents |
917
|
|
|
* sample (or quoted) output from a computer program. |
918
|
|
|
* |
919
|
|
|
* @param string|array<int,string> $children The Element children |
920
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
921
|
|
|
* |
922
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/samp |
923
|
|
|
*/ |
924
|
|
|
function samp($children, array $attributes = []): string |
925
|
|
|
{ |
926
|
|
|
$attributes['children'] = $children; |
927
|
|
|
|
928
|
|
|
return createElement('samp', $attributes); |
929
|
|
|
} |
930
|
|
|
/** |
931
|
|
|
* The `<small>` HTML element represents side-comments and small print, |
932
|
|
|
* like copyright and legal text, independent of its styled presentation. |
933
|
|
|
* |
934
|
|
|
* @param string|array<int,string> $children The Element children |
935
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
936
|
|
|
* |
937
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/small |
938
|
|
|
*/ |
939
|
|
|
function small($children, array $attributes = []): string |
940
|
|
|
{ |
941
|
|
|
$attributes['children'] = $children; |
942
|
|
|
|
943
|
|
|
return createElement('small', $attributes); |
944
|
|
|
} |
945
|
|
|
|
946
|
|
|
/** |
947
|
|
|
* The `<span>` HTML element is a generic inline container for phrasing content, |
948
|
|
|
* which does not inherently represent anything. |
949
|
|
|
* |
950
|
|
|
* @param string|array<int,string> $children The Element children |
951
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
952
|
|
|
* |
953
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span |
954
|
|
|
*/ |
955
|
|
|
function span($children, array $attributes = []): string |
956
|
|
|
{ |
957
|
1 |
|
$attributes['children'] = $children; |
958
|
|
|
|
959
|
1 |
|
return createElement('span', $attributes); |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* The `<strong>` HTML element indicates that its contents have strong importance, seriousness, or urgency. |
964
|
|
|
* |
965
|
|
|
* @param string|array<int,string> $children The Element children |
966
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
967
|
|
|
* |
968
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strong |
969
|
|
|
*/ |
970
|
|
|
function strong($children, array $attributes = []): string |
971
|
|
|
{ |
972
|
|
|
$attributes['children'] = $children; |
973
|
|
|
|
974
|
|
|
return createElement('strong', $attributes); |
975
|
|
|
} |
976
|
|
|
|
977
|
|
|
/** |
978
|
|
|
* The `<sub>` HTML element specifies inline text which should be displayed as |
979
|
|
|
* subscript for solely typographical reasons. |
980
|
|
|
* |
981
|
|
|
* @param string|array<int,string> $children The Element children |
982
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
983
|
|
|
* |
984
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub |
985
|
|
|
*/ |
986
|
|
|
function sub($children, array $attributes = []): string |
987
|
|
|
{ |
988
|
|
|
$attributes['children'] = $children; |
989
|
|
|
|
990
|
|
|
return createElement('sub', $attributes); |
991
|
|
|
} |
992
|
|
|
|
993
|
|
|
/** |
994
|
|
|
* The `<sup>` HTML element specifies inline text which is to be displayed as |
995
|
|
|
* superscript for solely typographical reasons. |
996
|
|
|
* |
997
|
|
|
* @param string|array<int,string> $children The Element children |
998
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
999
|
|
|
* |
1000
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup |
1001
|
|
|
*/ |
1002
|
|
|
function sup($children, array $attributes = []): string |
1003
|
|
|
{ |
1004
|
|
|
$attributes['children'] = $children; |
1005
|
|
|
|
1006
|
|
|
return createElement('sub', $attributes); |
1007
|
|
|
} |
1008
|
|
|
|
1009
|
|
|
/** |
1010
|
|
|
* The `<time>` HTML element represents a specific period in time. |
1011
|
|
|
* |
1012
|
|
|
* @param string|array<int,string> $children The Element children |
1013
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1014
|
|
|
* |
1015
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time |
1016
|
|
|
*/ |
1017
|
|
|
function time(string $datetime, $children, array $attributes = []): string |
1018
|
|
|
{ |
1019
|
|
|
$attributes['datetime'] = $datetime; |
1020
|
|
|
$attributes['children'] = $children; |
1021
|
|
|
|
1022
|
|
|
return createElement('time', $attributes); |
1023
|
|
|
} |
1024
|
|
|
|
1025
|
|
|
/** |
1026
|
|
|
* The `<u>` HTML element represents an unarticulated annotation (Underline). |
1027
|
|
|
* |
1028
|
|
|
* @param string|array<int,string> $children The Element children |
1029
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1030
|
|
|
* |
1031
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/u |
1032
|
|
|
*/ |
1033
|
|
|
function u($children, array $attributes = []): string |
1034
|
|
|
{ |
1035
|
|
|
$attributes['children'] = $children; |
1036
|
|
|
|
1037
|
|
|
return createElement('u', $attributes); |
1038
|
|
|
} |
1039
|
|
|
|
1040
|
|
|
/** |
1041
|
|
|
* The `<var>` HTML element represents the name of a variable in a mathematical expression or a programming context. |
1042
|
|
|
* |
1043
|
|
|
* @param string|array<int,string> $children The Element children |
1044
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1045
|
|
|
* |
1046
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/var |
1047
|
|
|
*/ |
1048
|
|
|
function _var($children, array $attributes = []): string |
1049
|
|
|
{ |
1050
|
|
|
$attributes['children'] = $children; |
1051
|
|
|
|
1052
|
|
|
return createElement('var', $attributes); |
1053
|
|
|
} |
1054
|
|
|
|
1055
|
|
|
/** |
1056
|
|
|
* The `<wbr>` HTML element represents a word break opportunity. |
1057
|
|
|
* |
1058
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1059
|
|
|
* |
1060
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/wbr |
1061
|
|
|
*/ |
1062
|
|
|
function wbr(array $attributes = []): string |
1063
|
|
|
{ |
1064
|
|
|
return createElement('wbr', $attributes, true); |
1065
|
|
|
} |
1066
|
|
|
|
1067
|
|
|
/** |
1068
|
|
|
* The `<area>` HTML element represents an image map area element. |
1069
|
|
|
* |
1070
|
|
|
* @param string $shape defines the values rect, which defines a rectangular region |
1071
|
|
|
* @param string|null $coord the coords attribute details the coordinates of the shape attribute in |
1072
|
|
|
* size, shape, and placement of an area |
1073
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1074
|
|
|
* |
1075
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area |
1076
|
|
|
*/ |
1077
|
|
|
function area(string $shape, string $coord = null, array $attributes = []): string |
1078
|
|
|
{ |
1079
|
|
|
$attributes += ['shape' => $shape, 'coord' => $coord]; |
1080
|
|
|
|
1081
|
|
|
return createElement('area', $attributes, true); |
1082
|
|
|
} |
1083
|
|
|
|
1084
|
|
|
/** |
1085
|
|
|
* The `<audio>` HTML element represents an embed audio element. |
1086
|
|
|
* |
1087
|
|
|
* @param string|array<int,string> $children The Element children |
1088
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1089
|
|
|
* |
1090
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio |
1091
|
|
|
*/ |
1092
|
|
|
function audio($children, array $attributes = []): string |
1093
|
|
|
{ |
1094
|
|
|
$attributes['children'] = $children; |
1095
|
|
|
|
1096
|
|
|
return createElement('audio', $attributes); |
1097
|
|
|
} |
1098
|
|
|
|
1099
|
|
|
/** |
1100
|
|
|
* The `<img>` HTML element represents an image embed element. |
1101
|
|
|
* |
1102
|
|
|
* @param string $src is required, and contains the path to the image |
1103
|
|
|
* @param string $alt holds a text description of the image |
1104
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1105
|
|
|
* |
1106
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img |
1107
|
|
|
*/ |
1108
|
|
|
function img(string $src, string $alt = '', array $attributes = []): string |
1109
|
|
|
{ |
1110
|
|
|
$attributes += ['src' => $src, 'alt' => $alt]; |
1111
|
|
|
|
1112
|
|
|
return createElement('img', $attributes, true); |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
/** |
1116
|
|
|
* The `<map>` HTML element represents an image map element. |
1117
|
|
|
* |
1118
|
|
|
* @param string $name gives the map a name so that it can be referenced |
1119
|
|
|
* @param string|array<int,string> $children The Element children |
1120
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1121
|
|
|
* |
1122
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map |
1123
|
|
|
*/ |
1124
|
|
|
function map(string $name, $children, array $attributes = []): string |
1125
|
|
|
{ |
1126
|
|
|
$attributes += ['name' => $name, 'children' => $children]; |
1127
|
|
|
|
1128
|
|
|
return createElement('map', $attributes); |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
/** |
1132
|
|
|
* The `<track>` HTML element represents an embed text track element. |
1133
|
|
|
* |
1134
|
|
|
* @param string $src Address of the track (.vtt file). Must be a valid URL |
1135
|
|
|
* @param string $kind How the text track is meant to be used |
1136
|
|
|
* @param bool $default indicates that the track should be enabled |
1137
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1138
|
|
|
* |
1139
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track |
1140
|
|
|
*/ |
1141
|
|
|
function track(string $src, string $kind, bool $default = true, array $attributes = []): string |
1142
|
|
|
{ |
1143
|
|
|
$attributes += ['default' => $default, 'kind' => $kind, 'src' => $src]; |
1144
|
|
|
|
1145
|
|
|
return createElement('track', $attributes, true); |
1146
|
|
|
} |
1147
|
|
|
|
1148
|
|
|
/** |
1149
|
|
|
* The `<video>` HTML element represents an image map element. |
1150
|
|
|
* |
1151
|
|
|
* @param string $src The URL of the video to embed |
1152
|
|
|
* @param string|array<int,string> $children The Element children |
1153
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1154
|
|
|
* |
1155
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video |
1156
|
|
|
*/ |
1157
|
|
|
function video(string $src, $children, bool $autoplay = true, array $attributes = []): string |
1158
|
|
|
{ |
1159
|
|
|
$attributes += ['src' => $src, 'children' => $children, 'autoplay' => $autoplay ? 'true' : 'false']; |
1160
|
|
|
|
1161
|
|
|
return createElement('video', $attributes); |
1162
|
|
|
} |
1163
|
|
|
|
1164
|
|
|
/** |
1165
|
|
|
* The `<embed>` HTML element represents external content at the specified point in the document. |
1166
|
|
|
* |
1167
|
|
|
* @param string $src The URL of the resource being embedded |
1168
|
|
|
* @param bool $type The MIME type to use to select the plug-in to instantiate |
1169
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1170
|
|
|
* |
1171
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed |
1172
|
|
|
*/ |
1173
|
|
|
function embed(string $src, string $type, array $attributes = []): string |
1174
|
|
|
{ |
1175
|
|
|
$attributes += ['type' => $type, 'src' => $src]; |
1176
|
|
|
|
1177
|
|
|
return createElement('embed', $attributes, true); |
1178
|
|
|
} |
1179
|
|
|
|
1180
|
|
|
/** |
1181
|
|
|
* The `<iframe>` HTML element represents a nested browsing context, |
1182
|
|
|
* embedding another HTML page into the current one. |
1183
|
|
|
* |
1184
|
|
|
* @param string $src The URL of the page to embed |
1185
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1186
|
|
|
* |
1187
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe |
1188
|
|
|
*/ |
1189
|
|
|
function iframe(string $src = 'about:blank', array $attributes = []): string |
1190
|
|
|
{ |
1191
|
|
|
$attributes += ['src' => $src]; |
1192
|
|
|
|
1193
|
|
|
return createElement('iframe', $attributes); |
1194
|
|
|
} |
1195
|
|
|
|
1196
|
|
|
/** |
1197
|
|
|
* The `<object>` HTML element represents an external resource treated as image. |
1198
|
|
|
* |
1199
|
|
|
* @param string $data The address of the resource as a valid URL |
1200
|
|
|
* @param bool $type The content type of the resource specified by data |
1201
|
|
|
* @param string|array<int,string> $children The Element children (only param, del and ins tags) |
1202
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1203
|
|
|
* |
1204
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object |
1205
|
|
|
*/ |
1206
|
|
|
function object(string $data, string $type, $children, array $attributes = []): string |
1207
|
|
|
{ |
1208
|
|
|
$attributes += ['data' => $data, 'children' => $children, 'type' => $type]; |
1209
|
|
|
|
1210
|
|
|
return createElement('object', $attributes); |
1211
|
|
|
} |
1212
|
|
|
|
1213
|
|
|
/** |
1214
|
|
|
* The `<param>` HTML element defines parameters for an object element. |
1215
|
|
|
* |
1216
|
|
|
* @param string $name Name of the parameter |
1217
|
|
|
* @param bool $value Name of the parameter |
1218
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1219
|
|
|
* |
1220
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/param |
1221
|
|
|
*/ |
1222
|
|
|
function param(string $name, string $value, array $attributes = []): string |
1223
|
|
|
{ |
1224
|
|
|
$attributes += ['name' => $name, 'value' => $value]; |
1225
|
|
|
|
1226
|
|
|
return createElement('param', $attributes, true); |
1227
|
|
|
} |
1228
|
|
|
|
1229
|
|
|
/** |
1230
|
|
|
* The `<picture>` HTML element contains zero or more `<source>` elements and one `<img>` element, |
1231
|
|
|
* to offer alternative versions of an image for different display/device scenarios. |
1232
|
|
|
* |
1233
|
|
|
* @param string|array<int,string> $children The Element children |
1234
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1235
|
|
|
* |
1236
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture |
1237
|
|
|
*/ |
1238
|
|
|
function picture($children, array $attributes = []): string |
1239
|
|
|
{ |
1240
|
|
|
$attributes += ['children' => $children]; |
1241
|
|
|
|
1242
|
|
|
return createElement('picture', $attributes); |
1243
|
|
|
} |
1244
|
|
|
|
1245
|
|
|
/** |
1246
|
|
|
* The `<source>` HTML element specifies multiple media resources for the `<picture>`, |
1247
|
|
|
* the `<audio>` element, or the `<video>` element. |
1248
|
|
|
* |
1249
|
|
|
* If the $type parameter is a picture media supported attribute content, |
1250
|
|
|
* The src attribute changes to srcset while type to media. |
1251
|
|
|
* |
1252
|
|
|
* @param string $src The URL of the resource |
1253
|
|
|
* @param bool $type The MIME media type of the resource, optionally with a codecs parameter |
1254
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1255
|
|
|
* |
1256
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source |
1257
|
|
|
*/ |
1258
|
|
|
function source(string $src, string $type, array $attributes = []): string |
1259
|
|
|
{ |
1260
|
|
|
$attributes += ('(' === @$type[0] ? ['srcset' => $src, 'media' => $type] : ['type' => $type, 'src' => $src]); |
1261
|
|
|
|
1262
|
|
|
return createElement('source', $attributes, true); |
1263
|
|
|
} |
1264
|
|
|
|
1265
|
|
|
/** |
1266
|
|
|
* The `<del>` HTML element represents a range of text that has been deleted from a document. |
1267
|
|
|
* |
1268
|
|
|
* @param string|array<int,string> $children The Element children |
1269
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1270
|
|
|
* |
1271
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del |
1272
|
|
|
*/ |
1273
|
|
|
function del($children, array $attributes = []): string |
1274
|
|
|
{ |
1275
|
|
|
$attributes += ['children' => $children]; |
1276
|
|
|
|
1277
|
|
|
return createElement('del', $attributes); |
1278
|
|
|
} |
1279
|
|
|
|
1280
|
|
|
/** |
1281
|
|
|
* The `<ins>` HTML element represents a range of text that has been added to a document. |
1282
|
|
|
* |
1283
|
|
|
* @param string|array<int,string> $children The Element children |
1284
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1285
|
|
|
* |
1286
|
|
|
* @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins |
1287
|
|
|
*/ |
1288
|
|
|
function ins($children, array $attributes = []): string |
1289
|
|
|
{ |
1290
|
|
|
$attributes += ['children' => $children]; |
1291
|
|
|
|
1292
|
|
|
return createElement('ins', $attributes); |
1293
|
|
|
} |
1294
|
|
|
|
1295
|
|
|
/** |
1296
|
|
|
* Create a grouped. |
1297
|
|
|
*/ |
1298
|
|
|
function elements(array $children): string |
1299
|
|
|
{ |
1300
|
|
|
return \implode('', $children); |
1301
|
|
|
} |
1302
|
|
|
|
1303
|
|
|
/** |
1304
|
|
|
* Renders content as html comment. (eg: `<!-- Hello World -->`). |
1305
|
|
|
* |
1306
|
|
|
* @param string|array<int,string> $content The content for rendering |
1307
|
|
|
*/ |
1308
|
|
|
function comment($content): string |
1309
|
|
|
{ |
1310
|
1 |
|
if (\is_array($content)) { |
1311
|
|
|
return \implode('', \array_map(__FUNCTION__, $content)); |
1312
|
|
|
} |
1313
|
|
|
|
1314
|
1 |
|
return '<!-- ' . $content . ' -->'; |
1315
|
|
|
} |
1316
|
|
|
|
1317
|
|
|
/** |
1318
|
|
|
* Loop over an array of items. |
1319
|
|
|
* |
1320
|
|
|
* @param array<int|string,mixed> $array The array to loop through |
1321
|
|
|
* @param callable $handler Call back function to run per iteration |
1322
|
|
|
*/ |
1323
|
|
|
function loop(array $array, callable $handler): string |
1324
|
|
|
{ |
1325
|
1 |
|
$element = ''; |
1326
|
|
|
|
1327
|
1 |
|
foreach ($array as $key => $value) { |
1328
|
1 |
|
$element .= $handler($value, $key); |
1329
|
|
|
} |
1330
|
|
|
|
1331
|
1 |
|
return $element; |
1332
|
|
|
} |
1333
|
|
|
|
1334
|
|
|
/** |
1335
|
|
|
* Create an HTML element. |
1336
|
|
|
* |
1337
|
|
|
* @param array<string,mixed> $attributes Attributes for the element |
1338
|
|
|
*/ |
1339
|
|
|
function createElement(string $tag, $attributes = [], bool $selfClosing = null): string |
1340
|
|
|
{ |
1341
|
1 |
|
$html = '<' . $tag; |
1342
|
|
|
|
1343
|
1 |
|
if (!empty($attributes)) { |
1344
|
1 |
|
if (\is_string($attributes)) { |
|
|
|
|
1345
|
|
|
$attributes = ['children' => $attributes]; |
1346
|
|
|
} |
1347
|
|
|
|
1348
|
1 |
|
$children = $attributes['children'] ?? ''; |
1349
|
1 |
|
unset($attributes['children']); |
1350
|
|
|
|
1351
|
1 |
|
$html .= HtmlElement::renderAttributes($attributes); |
1352
|
|
|
} |
1353
|
|
|
|
1354
|
1 |
|
if (null !== $selfClosing) { |
1355
|
1 |
|
return $html . ($selfClosing ? '/' : '') . '>'; |
1356
|
|
|
} |
1357
|
|
|
|
1358
|
1 |
|
if (isset($children)) { |
1359
|
1 |
|
$children = (\is_array($children) ? \implode('', $children) : $children); |
1360
|
|
|
} |
1361
|
|
|
|
1362
|
1 |
|
return $html . '>' . ($children ?? null) . '</' . $tag . '>'; |
1363
|
|
|
} |
1364
|
|
|
} |
1365
|
|
|
|