area()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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