Passed
Push — master ( 635760...191350 )
by Divine Niiquaye
11:17
created

style()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 9
ccs 3
cts 5
cp 0.6
crap 3.576
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|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(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);
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space after "+"; 0 found
Loading history...
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
        return createElement('data', $attributes + ['children' => $children]);
663
    }
664
665
    /**
666
     * The `<dfn>` HTML element is used to indicate the term being defined
667
     * within the context of a definition phrase or sentence.
668
     *
669
     * @param string|array<int,string> $children   The Element children
670
     * @param string|null              $title      id preset, it must contain the term being
671
     *                                             defined and no other text
672
     * @param array<string,mixed>      $attributes Attributes for the element
673
     *
674
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dfn
675
     */
676
    function dfn($children, string $title = null, array $attributes = []): string
677
    {
678
        return createElement('dfn', $attributes + ['title' => $title, 'children' => $children]);
679
    }
680
681
    /**
682
     * The `<em>` HTML element marks text that has stress emphasis.
683
     *
684
     * @param string|array<int,string> $children   The Element children
685
     * @param array<string,mixed>      $attributes Attributes for the element
686
     *
687
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em
688
     */
689
    function em($children, array $attributes = []): string
690
    {
691
        return createElement('em', $attributes + ['children' => $children]);
692
    }
693
694
    /**
695
     * The `<i>` HTML element represents a range of text that is set off from the normal
696
     * text for some reason, such as idiomatic text, technical terms, taxonomical designations, among others.
697
     *
698
     * @param string|array<int,string> $children   The Element children
699
     * @param array<string,mixed>      $attributes Attributes for the element
700
     *
701
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i
702
     */
703
    function i($children, array $attributes = []): string
704
    {
705
        return createElement('i', $attributes + ['children' => $children]);
706
    }
707
708
    /**
709
     * The `<kbd>` HTML element represents a span of inline text denoting textual user
710
     * input from a keyboard, voice input, or any other text entry device.
711
     *
712
     * @param string|array<int,string> $children   The Element children
713
     * @param array<string,mixed>      $attributes Attributes for the element
714
     *
715
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd
716
     */
717
    function kbd($children, array $attributes = []): string
718
    {
719
        return createElement('kbd', $attributes + ['children' => $children]);
720
    }
721
722
    /**
723
     * The `<mark>` HTML element represents text which is marked or highlighted for reference or
724
     * notation purposes, due to the marked passage's relevance or importance in the enclosing context.
725
     *
726
     * @param string|array<int,string> $children   The Element children
727
     * @param array<string,mixed>      $attributes Attributes for the element
728
     *
729
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark
730
     */
731
    function mark($children, array $attributes = []): string
732
    {
733
        return createElement('mark', $attributes + ['children' => $children]);
734
    }
735
736
    /**
737
     * The `<q>` HTML element indicates that the enclosed text is a short inline quotation.
738
     *
739
     * @param string|array<int,string> $children   The Element children
740
     * @param array<string,mixed>      $attributes Attributes for the element
741
     *
742
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q
743
     */
744
    function q($children, array $attributes = []): string
745
    {
746
        return createElement('q', $attributes + ['children' => $children]);
747
    }
748
    /**
749
     * The  `<rp>` HTML element is used to provide fall-back parentheses for browsers
750
     * that do not support display of ruby annotations using the ruby element.
751
     *
752
     * @param string|array<int,string> $children   The Element children
753
     * @param array<string,mixed>      $attributes Attributes for the element
754
     *
755
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rp
756
     */
757
    function rp($children, array $attributes = []): string
758
    {
759
        return createElement('rp', $attributes + ['children' => $children]);
760
    }
761
    /**
762
     * The `<rt>` HTML element specifies the ruby text component of a ruby annotation,
763
     * which is used to provide pronunciation, translation, or transliteration
764
     * information for East Asian typography.
765
     *
766
     * @param string|array<int,string> $children   The Element children
767
     * @param array<string,mixed>      $attributes Attributes for the element
768
     *
769
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rt
770
     */
771
    function rt($children, array $attributes = []): string
772
    {
773
        return createElement('rt', $attributes + ['children' => $children]);
774
    }
775
    /**
776
     * The `<ruby>` HTML element represents small annotations that are rendered above, below,
777
     * or next to base text, usually used for showing the pronunciation of East Asian characters.
778
     *
779
     * @param string|array<int,string> $children   The Element children
780
     * @param array<string,mixed>      $attributes Attributes for the element
781
     *
782
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby
783
     */
784
    function ruby($children, array $attributes = []): string
785
    {
786
        return createElement('ruby', $attributes + ['children' => $children]);
787
    }
788
    /**
789
     * The `<s>` HTML element renders text with a strikethrough, or a line through it.
790
     *
791
     * @param string|array<int,string> $children   The Element children
792
     * @param array<string,mixed>      $attributes Attributes for the element
793
     *
794
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/s
795
     */
796
    function s($children, array $attributes = []): string
797
    {
798
        return createElement('s', $attributes + ['children' => $children]);
799
    }
800
    /**
801
     * The `<samp>` HTML element is used to enclose inline text which represents
802
     * sample (or quoted) output from a computer program.
803
     *
804
     * @param string|array<int,string> $children   The Element children
805
     * @param array<string,mixed>      $attributes Attributes for the element
806
     *
807
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/samp
808
     */
809
    function samp($children, array $attributes = []): string
810
    {
811
        return createElement('samp', $attributes + ['children' => $children]);
812
    }
813
    /**
814
     * The `<small>` HTML element represents side-comments and small print,
815
     * like copyright and legal text, independent of its styled presentation.
816
     *
817
     * @param string|array<int,string> $children   The Element children
818
     * @param array<string,mixed>      $attributes Attributes for the element
819
     *
820
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/small
821
     */
822
    function small($children, array $attributes = []): string
823
    {
824
        return createElement('small', $attributes + ['children' => $children]);
825
    }
826
827
    /**
828
     * The `<span>` HTML element is a generic inline container for phrasing content,
829
     * which does not inherently represent anything.
830
     *
831
     * @param string|array<int,string> $children   The Element children
832
     * @param array<string,mixed>      $attributes Attributes for the element
833
     *
834
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
835
     */
836
    function span($children, array $attributes = []): string
837
    {
838 1
        return createElement('span', $attributes + ['children' => $children]);
839
    }
840
841
    /**
842
     * The `<strong>` HTML element indicates that its contents have strong importance, seriousness, or urgency.
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/strong
848
     */
849
    function strong($children, array $attributes = []): string
850
    {
851
        return createElement('strong', $attributes + ['children' => $children]);
852
    }
853
854
    /**
855
     * The `<sub>` HTML element specifies inline text which should be displayed as
856
     * subscript for solely typographical reasons.
857
     *
858
     * @param string|array<int,string> $children   The Element children
859
     * @param array<string,mixed>      $attributes Attributes for the element
860
     *
861
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub
862
     */
863
    function sub($children, array $attributes = []): string
864
    {
865
        return createElement('sub', $attributes + ['children' => $children]);
866
    }
867
868
    /**
869
     * The `<sup>` HTML element specifies inline text which is to be displayed as
870
     * superscript for solely typographical reasons.
871
     *
872
     * @param string|array<int,string> $children   The Element children
873
     * @param array<string,mixed>      $attributes Attributes for the element
874
     *
875
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup
876
     */
877
    function sup($children, array $attributes = []): string
878
    {
879
        return createElement('sub', $attributes + ['children' => $children]);
880
    }
881
882
    /**
883
     * The `<time>` HTML element represents a specific period in time.
884
     *
885
     * @param string|array<int,string> $children   The Element children
886
     * @param array<string,mixed>      $attributes Attributes for the element
887
     *
888
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
889
     */
890
    function time(string $datetime, $children, array $attributes = []): string
891
    {
892
        return createElement('time', $attributes + ['datetime' => $datetime, 'children' => $children]);
893
    }
894
895
    /**
896
     * The `<u>` HTML element represents an unarticulated annotation (Underline).
897
     *
898
     * @param string|array<int,string> $children   The Element children
899
     * @param array<string,mixed>      $attributes Attributes for the element
900
     *
901
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/u
902
     */
903
    function u($children, array $attributes = []): string
904
    {
905
        return createElement('u', $attributes + ['children' => $children]);
906
    }
907
908
    /**
909
     * The `<var>` HTML element represents the name of a variable in a mathematical expression or a programming context.
910
     *
911
     * @param string|array<int,string> $children   The Element children
912
     * @param array<string,mixed>      $attributes Attributes for the element
913
     *
914
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/var
915
     */
916
    function _var($children, array $attributes = []): string
917
    {
918
        return createElement('var', $attributes + ['children' => $children]);
919
    }
920
921
    /**
922
     * The `<wbr>` HTML element represents a word break opportunity.
923
     *
924
     * @param array<string,mixed> $attributes Attributes for the element
925
     *
926
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/wbr
927
     */
928
    function wbr(array $attributes = []): string
929
    {
930
        return createElement('wbr', $attributes, true);
931
    }
932
933
    /**
934
     * The `<area>` HTML element represents an image map area element.
935
     *
936
     * @param string              $shape      defines the values rect, which defines a rectangular region
937
     * @param string|null         $coord      the coords attribute details the coordinates of the shape attribute in
938
     *                                        size, shape, and placement of an area
939
     * @param array<string,mixed> $attributes Attributes for the element
940
     *
941
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area
942
     */
943
    function area(string $shape, string $coord = null, array $attributes = []): string
944
    {
945
        return createElement('area', $attributes + ['shape' => $shape, 'coord' => $coord], true);
946
    }
947
948
    /**
949
     * The `<audio>` HTML element represents an embed audio element.
950
     *
951
     * @param string|array<int,string> $children   The Element children
952
     * @param array<string,mixed>      $attributes Attributes for the element
953
     *
954
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
955
     */
956
    function audio($children, array $attributes = []): string
957
    {
958
        return createElement('audio', $attributes + ['children' => $children]);
959
    }
960
961
    /**
962
     * The `<img>` HTML element represents an image embed element.
963
     *
964
     * @param string              $src        is required, and contains the path to the image
965
     * @param string              $alt        holds a text description of the image
966
     * @param array<string,mixed> $attributes Attributes for the element
967
     *
968
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
969
     */
970
    function img(string $src, string $alt = '', array $attributes = []): string
971
    {
972
        return createElement('img', $attributes + ['src' => $src, 'alt' => $alt], true);
973
    }
974
975
    /**
976
     * The `<map>` HTML element represents an image map element.
977
     *
978
     * @param string                   $name       gives the map a name so that it can be referenced
979
     * @param string|array<int,string> $children   The Element children
980
     * @param array<string,mixed>      $attributes Attributes for the element
981
     *
982
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map
983
     */
984
    function map(string $name, $children, array $attributes = []): string
985
    {
986
        return createElement('map', $attributes + ['name' => $name, 'children' => $children]);
987
    }
988
989
    /**
990
     * The `<track>` HTML element represents an embed text track element.
991
     *
992
     * @param string              $src        Address of the track (.vtt file). Must be a valid URL
993
     * @param string              $kind       How the text track is meant to be used
994
     * @param array<string,mixed> $attributes Attributes for the element
995
     *
996
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track
997
     */
998
    function track(string $src, string $kind, array $attributes = []): string
999
    {
1000
        return createElement('track', $attributes + ['default' => true, 'kind' => $kind, 'src' => $src], true);
1001
    }
1002
1003
    /**
1004
     * The `<video>` HTML element represents an image map element.
1005
     *
1006
     * @param string                   $src        The URL of the video to embed
1007
     * @param string|array<int,string> $children   The Element children
1008
     * @param array<string,mixed>      $attributes Attributes for the element
1009
     *
1010
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video
1011
     */
1012
    function video(string $src, $children, array $attributes = []): string
1013
    {
1014
        return createElement('video', $attributes + ['src' => $src, 'children' => $children, 'autoplay' => 'true']);
1015
    }
1016
1017
    /**
1018
     * The `<embed>` HTML element represents external content at the specified point in the document.
1019
     *
1020
     * @param string              $src        The URL of the resource being embedded
1021
     * @param bool                $type       The MIME type to use to select the plug-in to instantiate
1022
     * @param array<string,mixed> $attributes Attributes for the element
1023
     *
1024
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed
1025
     */
1026
    function embed(string $src, string $type, array $attributes = []): string
1027
    {
1028
        return createElement('embed', $attributes + ['type' => $type, 'src' => $src], true);
1029
    }
1030
1031
    /**
1032
     * The `<iframe>` HTML element represents a nested browsing context,
1033
     * embedding another HTML page into the current one.
1034
     *
1035
     * @param string              $src        The URL of the page to embed
1036
     * @param array<string,mixed> $attributes Attributes for the element
1037
     *
1038
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
1039
     */
1040
    function iframe(string $src = 'about:blank', array $attributes = []): string
1041
    {
1042
        return createElement('iframe', $attributes + ['src' => $src]);
1043
    }
1044
1045
    /**
1046
     * The `<object>` HTML element represents an external resource treated as image.
1047
     *
1048
     * @param string                   $data       The address of the resource as a valid URL
1049
     * @param bool                     $type       The content type of the resource specified by data
1050
     * @param string|array<int,string> $children   The Element children (only param, del and ins tags)
1051
     * @param array<string,mixed>      $attributes Attributes for the element
1052
     *
1053
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object
1054
     */
1055
    function object(string $data, string $type, $children, array $attributes = []): string
1056
    {
1057
        return createElement('object', $attributes + ['data' => $data, 'children' => $children, 'type' => $type]);
1058
    }
1059
1060
    /**
1061
     * The `<param>` HTML element defines parameters for an object element.
1062
     *
1063
     * @param string              $name       Name of the parameter
1064
     * @param bool                $value      Name of the parameter
1065
     * @param array<string,mixed> $attributes Attributes for the element
1066
     *
1067
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/param
1068
     */
1069
    function param(string $name, string $value, array $attributes = []): string
1070
    {
1071
        return createElement('param', $attributes + ['name' => $name, 'value' => $value], true);
1072
    }
1073
1074
    /**
1075
     * The `<picture>` HTML element contains zero or more `<source>` elements and one `<img>` element,
1076
     * to offer alternative versions of an image for different display/device scenarios.
1077
     *
1078
     * @param string|array<int,string> $children   The Element children
1079
     * @param array<string,mixed>      $attributes Attributes for the element
1080
     *
1081
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture
1082
     */
1083
    function picture($children, array $attributes = []): string
1084
    {
1085
        return createElement('picture', $attributes + ['children' => $children]);
1086
    }
1087
1088
    /**
1089
     * The `<source>` HTML element specifies multiple media resources for the `<picture>`,
1090
     * the `<audio>` element, or the `<video>` element.
1091
     *
1092
     * If the $type parameter is a picture media supported attribute content,
1093
     * The src attribute changes to srcset while type to media.
1094
     *
1095
     * @param string              $src        The URL of the resource
1096
     * @param bool                $type       The MIME media type of the resource, optionally with a codecs parameter
1097
     * @param array<string,mixed> $attributes Attributes for the element
1098
     *
1099
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source
1100
     */
1101
    function source(string $src, string $type, array $attributes = []): string
1102
    {
1103
        $attributes += ('(' === @$type[0] ? ['srcset' => $src, 'media' => $type] : ['type' => $type, 'src' => $src]);
1104
1105
        return createElement('source', $attributes, true);
1106
    }
1107
1108
    /**
1109
     * The `<del>` HTML element represents a range of text that has been deleted from a document.
1110
     *
1111
     * @param string|array<int,string> $children   The Element children
1112
     * @param array<string,mixed>      $attributes Attributes for the element
1113
     *
1114
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del
1115
     */
1116
    function del($children, array $attributes = []): string
1117
    {
1118
        return createElement('del', $attributes + ['children' => $children]);
1119
    }
1120
1121
    /**
1122
     * The `<ins>` HTML element represents a range of text that has been added to a document.
1123
     *
1124
     * @param string|array<int,string> $children   The Element children
1125
     * @param array<string,mixed>      $attributes Attributes for the element
1126
     *
1127
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins
1128
     */
1129
    function ins($children, array $attributes = []): string
1130
    {
1131
        $attributes += ['children' => $children];
1132
1133
        return createElement('ins', $attributes + ['children' => $children]);
1134
    }
1135
1136
    /**
1137
     * The `<caption>` HTML element specifies the caption (or title) of a table.
1138
     *
1139
     * @param string|array<int,string> $children   The Element children
1140
     * @param array<string,mixed>      $attributes Attributes for the element
1141
     *
1142
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption
1143
     */
1144
    function caption($children, array $attributes = []): string
1145
    {
1146
        return createElement('caption', $attributes + ['children' => $children]);
1147
    }
1148
1149
    /**
1150
     * The `<col>` HTML element defines a column within a table and is used for
1151
     * defining common semantics on all common cells.
1152
     *
1153
     * @param int                 $span       contains a positive integer indicating for columns
1154
     * @param array<string,mixed> $attributes Attributes for the element
1155
     *
1156
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col
1157
     */
1158
    function col(int $span = 1, array $attributes = []): string
1159
    {
1160
        return createElement('col', $attributes + ['span' => (string) $span], true);
1161
    }
1162
1163
    /**
1164
     * The `<colgroup>` HTML element defines a group of columns within a table.
1165
     *
1166
     * @param int                      $span       contains a positive integer indicating for columns
1167
     * @param string|array<int,string> $children   The Element children
1168
     * @param array<string,mixed>      $attributes Attributes for the element
1169
     *
1170
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup
1171
     */
1172
    function colgroup($children, int $span = 1, array $attributes = []): string
1173
    {
1174
        return createElement('colgroup', $attributes + ['span' => (string) $span, 'children' => $children]);
1175
    }
1176
1177
    /**
1178
     * The `<table>` HTML element represents tabular data — that is, information presented in a
1179
     * two-dimensional table comprised of rows and columns of cells containing data.
1180
     *
1181
     * @param string|array<int,string> $children   The Element children
1182
     * @param array<string,mixed>      $attributes Attributes for the element
1183
     *
1184
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table
1185
     */
1186
    function table($children, array $attributes = []): string
1187
    {
1188
        return createElement('table', $attributes + ['children' => $children]);
1189
    }
1190
1191
    /**
1192
     * The `<tbody>` HTML element encapsulates a set of table rows (`<tr>` elements),
1193
     * indicating that they comprise the body of the table (`<table>`).
1194
     *
1195
     * @param string|array<int,string> $children   The Element children
1196
     * @param array<string,mixed>      $attributes Attributes for the element
1197
     *
1198
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody
1199
     */
1200
    function tbody($children, array $attributes = []): string
1201
    {
1202
        return createElement('tbody', $attributes + ['children' => $children]);
1203
    }
1204
1205
    /**
1206
     * The `<td>` HTML element defines a cell of a table that contains data.
1207
     *
1208
     * @param string|array<int,string> $children   The Element children
1209
     * @param array<string,mixed>      $attributes Attributes for the element
1210
     *
1211
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td
1212
     */
1213
    function td($children, array $attributes = []): string
1214
    {
1215
        return createElement('td', $attributes + ['children' => $children]);
1216
    }
1217
1218
    /**
1219
     * The `<tfoot>` HTML element defines a set of rows summarizing the columns of the table.
1220
     *
1221
     * @param string|array<int,string> $children   The Element children
1222
     * @param array<string,mixed>      $attributes Attributes for the element
1223
     *
1224
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tfoot
1225
     */
1226
    function tfoot($children, array $attributes = []): string
1227
    {
1228
        return createElement('tfoot', $attributes + ['children' => $children]);
1229
    }
1230
1231
    /**
1232
     * The `<th>` HTML element defines a cell as header of a group of table cells.
1233
     *
1234
     * @param string                   $scope      Defines a cell as header of a group of table cells
1235
     * @param string|array<int,string> $children   The Element children
1236
     * @param array<string,mixed>      $attributes Attributes for the element
1237
     *
1238
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
1239
     */
1240
    function th(string $scope, $children, array $attributes = []): string
1241
    {
1242
        return createElement('th', $attributes + ['scope' => $scope, 'children' => $children]);
1243
    }
1244
1245
    /**
1246
     * The `<thead>` HTML element defines a set of rows defining the head of the columns of the table.
1247
     *
1248
     * @param string|array<int,string> $children   The Element children
1249
     * @param array<string,mixed>      $attributes Attributes for the element
1250
     *
1251
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/thead
1252
     */
1253
    function thead($children, array $attributes = []): string
1254
    {
1255
        return createElement('thead', $attributes + ['children' => $children]);
1256
    }
1257
1258
    /**
1259
     * The `<tr>` HTML element defines a row of cells in a table.
1260
     *
1261
     * @param string|array<int,string> $children   The Element children
1262
     * @param array<string,mixed>      $attributes Attributes for the element
1263
     *
1264
     * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr
1265
     */
1266
    function tr($children, array $attributes = []): string
1267
    {
1268
        return createElement('tr', $attributes + ['children' => $children]);
1269
    }
1270
1271
    /**
1272
     * Create a grouped.
1273
     */
1274
    function elements(array $children): string
1275
    {
1276
        return \implode('', $children);
1277
    }
1278
1279
    /**
1280
     * Renders content as html comment. (eg: `<!-- Hello World -->`).
1281
     *
1282
     * @param string|array<int,string> $content The content for rendering
1283
     */
1284
    function comment($content): string
1285
    {
1286 1
        if (\is_array($content)) {
1287
            return \implode('', \array_map(__FUNCTION__, $content));
1288
        }
1289
1290 1
        return '<!-- ' . $content . ' -->';
1291
    }
1292
1293
    /**
1294
     * Loop over an array of items.
1295
     *
1296
     * @param array<int|string,mixed> $array   The array to loop through
1297
     * @param callable                $handler Call back function to run per iteration
1298
     */
1299
    function loop(array $array, callable $handler): string
1300
    {
1301 1
        $element = '';
1302
1303 1
        foreach ($array as $key => $value) {
1304 1
            $element .= $handler($value, $key);
1305
        }
1306
1307 1
        return $element;
1308
    }
1309
1310
    /**
1311
     * Create an HTML element.
1312
     *
1313
     * @param \Stringable|string|array<string,mixed> $attributes Attributes for the element
1314
     */
1315
    function createElement(string $tag, $attributes = [], bool $selfClosing = null): string
1316
    {
1317 1
        $html = '<' . $tag;
1318
1319 1
        if (\is_array($attributes)) {
1320 1
            if (\is_array($children = $attributes['children'] ?? '')) {
1321 1
                $children = \implode('', $children);
1322
            }
1323
1324 1
            unset($attributes['children']);
1325 1
            $html .= HtmlElement::renderAttributes($attributes);
1326
        } elseif (\is_string($attributes) || $attributes instanceof \Stringable) {
0 ignored issues
show
introduced by
$attributes is always a sub-type of Stringable.
Loading history...
1327
            $children = (string) $attributes;
1328
        }
1329
1330 1
        if (null !== $selfClosing) {
1331 1
            return $html . ($selfClosing ? '/' : '') . '>';
1332
        }
1333
1334 1
        return $html . '>' . ($children ?? null) . '</' . $tag . '>';
1335
    }
1336
}
1337