@lucidkiln/core 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { n as contentStart } from "./parser-BZpRlGWi.js";
1
+ import { n as contentStart } from "./parser-CRWl5Lka.js";
2
2
  //#region src/errors.ts
3
3
  /** Creates a diagnostic for a span of a source. */
4
4
  const createDiagnostic = (source, code, message, span, severity = "error") => ({
@@ -145,6 +145,1116 @@ const resolveTemplateName = (name, from) => {
145
145
  return segments.join("/");
146
146
  };
147
147
  //#endregion
148
+ //#region src/html/data.ts
149
+ /** Obsolete elements in the HTML standard, by what to use instead. */
150
+ const OBSOLETE = new Map(Object.entries({
151
+ "Use <abbr> instead": ["acronym"],
152
+ "Use <object> or <embed> instead": ["applet"],
153
+ "Use CSS instead": [
154
+ "basefont",
155
+ "big",
156
+ "blink",
157
+ "center",
158
+ "font",
159
+ "marquee",
160
+ "multicol",
161
+ "nobr",
162
+ "spacer"
163
+ ],
164
+ "Use <audio> instead": ["bgsound"],
165
+ "Use <ul> instead": ["dir"],
166
+ "Use <iframe>, or a layout with CSS, instead": [
167
+ "frame",
168
+ "frameset",
169
+ "noframes"
170
+ ],
171
+ "Use a form with a text field instead": ["isindex"],
172
+ "Use the Web Crypto API instead": ["keygen"],
173
+ "Use <pre> and <code> instead": [
174
+ "listing",
175
+ "plaintext",
176
+ "xmp"
177
+ ],
178
+ "Use a <button> inside <menu> instead": ["menuitem"],
179
+ "Remove it": ["nextid"],
180
+ "Use fallback content inside <object> instead": ["noembed"],
181
+ "Use attributes on <object> instead": ["param"],
182
+ "Use <ruby> with <rt> instead": ["rb", "rtc"],
183
+ "Use <s>, or <del> for removed text, instead": ["strike"],
184
+ "Use <code>, <kbd> or <samp> instead": ["tt"]
185
+ }).flatMap(([advice, names]) => names.map((name) => [name, advice])));
186
+ /** States and properties from WAI-ARIA 1.2, plus those the 1.3 draft adds. */
187
+ const ARIA_ATTRIBUTES = new Set([
188
+ "activedescendant",
189
+ "atomic",
190
+ "autocomplete",
191
+ "braillelabel",
192
+ "brailleroledescription",
193
+ "busy",
194
+ "checked",
195
+ "colcount",
196
+ "colindex",
197
+ "colindextext",
198
+ "colspan",
199
+ "controls",
200
+ "current",
201
+ "describedby",
202
+ "description",
203
+ "details",
204
+ "disabled",
205
+ "dropeffect",
206
+ "errormessage",
207
+ "expanded",
208
+ "flowto",
209
+ "grabbed",
210
+ "haspopup",
211
+ "hidden",
212
+ "invalid",
213
+ "keyshortcuts",
214
+ "label",
215
+ "labelledby",
216
+ "level",
217
+ "live",
218
+ "modal",
219
+ "multiline",
220
+ "multiselectable",
221
+ "orientation",
222
+ "owns",
223
+ "placeholder",
224
+ "posinset",
225
+ "pressed",
226
+ "readonly",
227
+ "relevant",
228
+ "required",
229
+ "roledescription",
230
+ "rowcount",
231
+ "rowindex",
232
+ "rowindextext",
233
+ "rowspan",
234
+ "selected",
235
+ "setsize",
236
+ "sort",
237
+ "valuemax",
238
+ "valuemin",
239
+ "valuenow",
240
+ "valuetext"
241
+ ].map((name) => `aria-${name}`));
242
+ /** Roles from WAI-ARIA 1.2, plus those the 1.3 draft adds. */
243
+ const ROLES = /* @__PURE__ */ new Set([
244
+ "alert",
245
+ "alertdialog",
246
+ "application",
247
+ "article",
248
+ "banner",
249
+ "blockquote",
250
+ "button",
251
+ "caption",
252
+ "cell",
253
+ "checkbox",
254
+ "code",
255
+ "columnheader",
256
+ "combobox",
257
+ "comment",
258
+ "complementary",
259
+ "contentinfo",
260
+ "definition",
261
+ "deletion",
262
+ "dialog",
263
+ "directory",
264
+ "document",
265
+ "emphasis",
266
+ "feed",
267
+ "figure",
268
+ "form",
269
+ "generic",
270
+ "grid",
271
+ "gridcell",
272
+ "group",
273
+ "heading",
274
+ "image",
275
+ "img",
276
+ "insertion",
277
+ "link",
278
+ "list",
279
+ "listbox",
280
+ "listitem",
281
+ "log",
282
+ "main",
283
+ "mark",
284
+ "marquee",
285
+ "math",
286
+ "menu",
287
+ "menubar",
288
+ "menuitem",
289
+ "menuitemcheckbox",
290
+ "menuitemradio",
291
+ "meter",
292
+ "navigation",
293
+ "none",
294
+ "note",
295
+ "option",
296
+ "paragraph",
297
+ "presentation",
298
+ "progressbar",
299
+ "radio",
300
+ "radiogroup",
301
+ "region",
302
+ "row",
303
+ "rowgroup",
304
+ "rowheader",
305
+ "scrollbar",
306
+ "search",
307
+ "searchbox",
308
+ "sectionfooter",
309
+ "sectionheader",
310
+ "separator",
311
+ "slider",
312
+ "spinbutton",
313
+ "status",
314
+ "strong",
315
+ "subscript",
316
+ "suggestion",
317
+ "superscript",
318
+ "switch",
319
+ "tab",
320
+ "table",
321
+ "tablist",
322
+ "tabpanel",
323
+ "term",
324
+ "textbox",
325
+ "time",
326
+ "timer",
327
+ "toolbar",
328
+ "tooltip",
329
+ "tree",
330
+ "treegrid",
331
+ "treeitem"
332
+ ]);
333
+ /** Roles that only organise the ARIA spec. Pages must not use them. */
334
+ const ABSTRACT_ROLES = /* @__PURE__ */ new Set([
335
+ "command",
336
+ "composite",
337
+ "input",
338
+ "landmark",
339
+ "range",
340
+ "roletype",
341
+ "section",
342
+ "sectionhead",
343
+ "select",
344
+ "structure",
345
+ "widget",
346
+ "window"
347
+ ]);
348
+ /** Elements whose content is text, so tags inside them aren't elements. */
349
+ const RAW_TEXT = /* @__PURE__ */ new Set([
350
+ "script",
351
+ "style",
352
+ "textarea",
353
+ "title",
354
+ "xmp",
355
+ "iframe",
356
+ "noembed",
357
+ "noframes",
358
+ "plaintext"
359
+ ]);
360
+ /** Elements whose content follows SVG or MathML rules instead of HTML's. */
361
+ const FOREIGN = /* @__PURE__ */ new Set(["svg", "math"]);
362
+ /** Elements with no content or end tag. */
363
+ const VOID = /* @__PURE__ */ new Set([
364
+ "area",
365
+ "base",
366
+ "basefont",
367
+ "bgsound",
368
+ "br",
369
+ "col",
370
+ "embed",
371
+ "frame",
372
+ "hr",
373
+ "img",
374
+ "input",
375
+ "keygen",
376
+ "link",
377
+ "meta",
378
+ "param",
379
+ "source",
380
+ "track",
381
+ "wbr"
382
+ ]);
383
+ /** What each obsolete attribute is replaced by, by element. Attributes missing from an element's list use CSS. */
384
+ const CSS = "Use CSS instead";
385
+ const REMOVE = "Remove it";
386
+ const USE_ID = "Use id instead";
387
+ const presentational = (...names) => Object.fromEntries(names.map((name) => [name, CSS]));
388
+ const cellAttributes = presentational("align", "bgcolor", "char", "charoff", "height", "nowrap", "valign", "width");
389
+ const rowGroupAttributes = presentational("align", "char", "charoff", "valign");
390
+ const OBSOLETE_ATTRIBUTES = {
391
+ a: {
392
+ charset: REMOVE,
393
+ coords: "Use <area> instead",
394
+ methods: REMOVE,
395
+ name: USE_ID,
396
+ rev: "Use rel instead",
397
+ shape: "Use <area> instead",
398
+ urn: REMOVE
399
+ },
400
+ area: {
401
+ nohref: "Leave out href instead",
402
+ type: REMOVE
403
+ },
404
+ body: presentational("alink", "background", "bgcolor", "bottommargin", "leftmargin", "link", "marginbottom", "marginheight", "marginleft", "marginright", "margintop", "marginwidth", "rightmargin", "text", "topmargin", "vlink"),
405
+ br: presentational("clear"),
406
+ caption: presentational("align"),
407
+ col: presentational("align", "char", "charoff", "valign", "width"),
408
+ div: presentational("align"),
409
+ dl: presentational("compact"),
410
+ embed: {
411
+ ...presentational("align", "hspace", "vspace"),
412
+ name: USE_ID
413
+ },
414
+ head: { profile: REMOVE },
415
+ hr: presentational("align", "color", "noshade", "size", "width"),
416
+ html: {
417
+ manifest: "Use a service worker instead",
418
+ version: REMOVE
419
+ },
420
+ ...Object.fromEntries([
421
+ "h1",
422
+ "h2",
423
+ "h3",
424
+ "h4",
425
+ "h5",
426
+ "h6",
427
+ "legend",
428
+ "p"
429
+ ].map((name) => [name, presentational("align")])),
430
+ iframe: {
431
+ ...presentational("align", "allowtransparency", "frameborder", "framespacing", "hspace", "marginheight", "marginwidth", "scrolling", "vspace"),
432
+ longdesc: "Link to the description instead"
433
+ },
434
+ img: {
435
+ ...presentational("align", "border", "hspace", "vspace"),
436
+ longdesc: "Link to the description instead",
437
+ lowsrc: "Use srcset instead",
438
+ name: USE_ID
439
+ },
440
+ input: {
441
+ ...presentational("align", "hspace", "vspace"),
442
+ ismap: "Use <img> for image maps instead",
443
+ usemap: "Use <img> for image maps instead"
444
+ },
445
+ li: presentational("type"),
446
+ link: {
447
+ charset: REMOVE,
448
+ rev: "Use rel instead",
449
+ target: REMOVE
450
+ },
451
+ menu: presentational("compact"),
452
+ meta: { scheme: REMOVE },
453
+ object: {
454
+ ...presentational("align", "border", "hspace", "vspace"),
455
+ archive: "Use data and type instead",
456
+ classid: "Use data and type instead",
457
+ code: "Use data and type instead",
458
+ codebase: "Use data and type instead",
459
+ codetype: "Use data and type instead",
460
+ declare: REMOVE,
461
+ standby: REMOVE
462
+ },
463
+ ol: presentational("compact"),
464
+ option: { name: USE_ID },
465
+ pre: presentational("width"),
466
+ script: {
467
+ charset: REMOVE,
468
+ event: REMOVE,
469
+ for: REMOVE,
470
+ language: REMOVE
471
+ },
472
+ table: {
473
+ ...presentational("align", "bgcolor", "border", "cellpadding", "cellspacing", "frame", "rules", "width"),
474
+ summary: "Use <caption> instead"
475
+ },
476
+ tbody: rowGroupAttributes,
477
+ thead: rowGroupAttributes,
478
+ tfoot: rowGroupAttributes,
479
+ tr: {
480
+ ...rowGroupAttributes,
481
+ bgcolor: CSS
482
+ },
483
+ td: {
484
+ ...cellAttributes,
485
+ abbr: "Use <th> with abbr instead",
486
+ axis: "Use scope on <th> instead",
487
+ scope: "Use <th> instead"
488
+ },
489
+ th: {
490
+ ...cellAttributes,
491
+ axis: "Use scope instead"
492
+ },
493
+ ul: presentational("compact", "type")
494
+ };
495
+ const FORM_METHODS = [
496
+ "get",
497
+ "post",
498
+ "dialog"
499
+ ];
500
+ const ENCTYPES = [
501
+ "application/x-www-form-urlencoded",
502
+ "multipart/form-data",
503
+ "text/plain"
504
+ ];
505
+ const TARGETS = [
506
+ "_blank",
507
+ "_parent",
508
+ "_self",
509
+ "_top",
510
+ "_unfencedTop"
511
+ ];
512
+ /** A target that isn't a keyword is a name, and names can't start with `_`. */
513
+ const targetName = (value) => !value.startsWith("_");
514
+ const ATTRIBUTE_VALUES = {
515
+ type: [
516
+ {
517
+ on: ["input"],
518
+ values: [
519
+ "button",
520
+ "checkbox",
521
+ "color",
522
+ "date",
523
+ "datetime-local",
524
+ "email",
525
+ "file",
526
+ "hidden",
527
+ "image",
528
+ "month",
529
+ "number",
530
+ "password",
531
+ "radio",
532
+ "range",
533
+ "reset",
534
+ "search",
535
+ "submit",
536
+ "tel",
537
+ "text",
538
+ "time",
539
+ "url",
540
+ "week"
541
+ ]
542
+ },
543
+ {
544
+ on: ["button"],
545
+ values: [
546
+ "button",
547
+ "reset",
548
+ "submit"
549
+ ]
550
+ },
551
+ {
552
+ on: ["ol"],
553
+ values: [
554
+ "1",
555
+ "a",
556
+ "A",
557
+ "i",
558
+ "I"
559
+ ],
560
+ caseSensitive: true
561
+ }
562
+ ],
563
+ method: [{
564
+ on: ["form"],
565
+ values: FORM_METHODS
566
+ }],
567
+ formmethod: [{
568
+ on: ["button", "input"],
569
+ values: FORM_METHODS
570
+ }],
571
+ enctype: [{
572
+ on: ["form"],
573
+ values: ENCTYPES
574
+ }],
575
+ formenctype: [{
576
+ on: ["button", "input"],
577
+ values: ENCTYPES
578
+ }],
579
+ autocomplete: [{
580
+ on: ["form"],
581
+ values: ["on", "off"]
582
+ }],
583
+ loading: [{
584
+ on: ["img", "iframe"],
585
+ values: ["eager", "lazy"]
586
+ }],
587
+ decoding: [{
588
+ on: ["img"],
589
+ values: [
590
+ "async",
591
+ "auto",
592
+ "sync"
593
+ ]
594
+ }],
595
+ fetchpriority: [{
596
+ on: [
597
+ "img",
598
+ "iframe",
599
+ "link",
600
+ "script"
601
+ ],
602
+ values: [
603
+ "auto",
604
+ "high",
605
+ "low"
606
+ ]
607
+ }],
608
+ crossorigin: [{
609
+ on: [
610
+ "audio",
611
+ "img",
612
+ "link",
613
+ "script",
614
+ "video"
615
+ ],
616
+ values: [
617
+ "",
618
+ "anonymous",
619
+ "use-credentials"
620
+ ]
621
+ }],
622
+ referrerpolicy: [{
623
+ on: [
624
+ "a",
625
+ "area",
626
+ "iframe",
627
+ "img",
628
+ "link",
629
+ "script"
630
+ ],
631
+ values: [
632
+ "",
633
+ "no-referrer",
634
+ "no-referrer-when-downgrade",
635
+ "origin",
636
+ "origin-when-cross-origin",
637
+ "same-origin",
638
+ "strict-origin",
639
+ "strict-origin-when-cross-origin",
640
+ "unsafe-url"
641
+ ]
642
+ }],
643
+ target: [{
644
+ on: [
645
+ "a",
646
+ "area",
647
+ "base",
648
+ "form"
649
+ ],
650
+ values: TARGETS,
651
+ other: targetName
652
+ }],
653
+ formtarget: [{
654
+ on: ["button", "input"],
655
+ values: TARGETS,
656
+ other: targetName
657
+ }],
658
+ preload: [{
659
+ on: ["audio", "video"],
660
+ values: [
661
+ "",
662
+ "auto",
663
+ "metadata",
664
+ "none"
665
+ ]
666
+ }],
667
+ scope: [{
668
+ on: ["th"],
669
+ values: [
670
+ "col",
671
+ "colgroup",
672
+ "row",
673
+ "rowgroup"
674
+ ]
675
+ }],
676
+ kind: [{
677
+ on: ["track"],
678
+ values: [
679
+ "captions",
680
+ "chapters",
681
+ "descriptions",
682
+ "metadata",
683
+ "subtitles"
684
+ ]
685
+ }],
686
+ wrap: [{
687
+ on: ["textarea"],
688
+ values: ["hard", "soft"]
689
+ }],
690
+ shape: [{
691
+ on: ["area"],
692
+ values: [
693
+ "circle",
694
+ "default",
695
+ "poly",
696
+ "rect"
697
+ ]
698
+ }],
699
+ capture: [{
700
+ on: ["input"],
701
+ values: ["environment", "user"]
702
+ }],
703
+ sandbox: [{
704
+ on: ["iframe"],
705
+ tokens: true,
706
+ values: [
707
+ "allow-downloads",
708
+ "allow-forms",
709
+ "allow-modals",
710
+ "allow-orientation-lock",
711
+ "allow-pointer-lock",
712
+ "allow-popups",
713
+ "allow-popups-to-escape-sandbox",
714
+ "allow-presentation",
715
+ "allow-same-origin",
716
+ "allow-scripts",
717
+ "allow-storage-access-by-user-activation",
718
+ "allow-top-navigation",
719
+ "allow-top-navigation-by-user-activation",
720
+ "allow-top-navigation-to-custom-protocols"
721
+ ]
722
+ }],
723
+ blocking: [{
724
+ on: [
725
+ "link",
726
+ "script",
727
+ "style"
728
+ ],
729
+ tokens: true,
730
+ values: ["render"]
731
+ }],
732
+ popovertargetaction: [{
733
+ on: ["button", "input"],
734
+ values: [
735
+ "hide",
736
+ "show",
737
+ "toggle"
738
+ ]
739
+ }],
740
+ command: [{
741
+ on: ["button"],
742
+ values: [
743
+ "close",
744
+ "hide-popover",
745
+ "request-close",
746
+ "show-modal",
747
+ "show-popover",
748
+ "toggle-popover"
749
+ ],
750
+ other: (value) => value.startsWith("--")
751
+ }],
752
+ shadowrootmode: [{
753
+ on: ["template"],
754
+ values: ["closed", "open"]
755
+ }],
756
+ dir: [{
757
+ on: "*",
758
+ values: [
759
+ "auto",
760
+ "ltr",
761
+ "rtl"
762
+ ]
763
+ }],
764
+ hidden: [{
765
+ on: "*",
766
+ values: [
767
+ "",
768
+ "hidden",
769
+ "until-found"
770
+ ]
771
+ }],
772
+ contenteditable: [{
773
+ on: "*",
774
+ values: [
775
+ "",
776
+ "false",
777
+ "plaintext-only",
778
+ "true"
779
+ ]
780
+ }],
781
+ draggable: [{
782
+ on: "*",
783
+ values: ["false", "true"]
784
+ }],
785
+ spellcheck: [{
786
+ on: "*",
787
+ values: [
788
+ "",
789
+ "false",
790
+ "true"
791
+ ]
792
+ }],
793
+ translate: [{
794
+ on: "*",
795
+ values: [
796
+ "",
797
+ "no",
798
+ "yes"
799
+ ]
800
+ }],
801
+ autocapitalize: [{
802
+ on: "*",
803
+ values: [
804
+ "characters",
805
+ "none",
806
+ "off",
807
+ "on",
808
+ "sentences",
809
+ "words"
810
+ ]
811
+ }],
812
+ inputmode: [{
813
+ on: "*",
814
+ values: [
815
+ "decimal",
816
+ "email",
817
+ "none",
818
+ "numeric",
819
+ "search",
820
+ "tel",
821
+ "text",
822
+ "url"
823
+ ]
824
+ }],
825
+ enterkeyhint: [{
826
+ on: "*",
827
+ values: [
828
+ "done",
829
+ "enter",
830
+ "go",
831
+ "next",
832
+ "previous",
833
+ "search",
834
+ "send"
835
+ ]
836
+ }],
837
+ popover: [{
838
+ on: "*",
839
+ values: [
840
+ "",
841
+ "auto",
842
+ "hint",
843
+ "manual"
844
+ ]
845
+ }]
846
+ };
847
+ /** Boolean attributes, which are on whenever they are present, by the elements that have them. `*` is any element. */
848
+ const BOOLEAN_ATTRIBUTES = {
849
+ allowfullscreen: ["iframe"],
850
+ async: ["script"],
851
+ autofocus: "*",
852
+ autoplay: ["audio", "video"],
853
+ checked: ["input"],
854
+ controls: ["audio", "video"],
855
+ default: ["track"],
856
+ defer: ["script"],
857
+ disabled: [
858
+ "button",
859
+ "fieldset",
860
+ "input",
861
+ "link",
862
+ "optgroup",
863
+ "option",
864
+ "select",
865
+ "textarea"
866
+ ],
867
+ formnovalidate: ["button", "input"],
868
+ inert: "*",
869
+ ismap: ["img"],
870
+ itemscope: "*",
871
+ loop: ["audio", "video"],
872
+ multiple: ["input", "select"],
873
+ muted: ["audio", "video"],
874
+ nomodule: ["script"],
875
+ novalidate: ["form"],
876
+ open: ["details", "dialog"],
877
+ playsinline: ["video"],
878
+ readonly: ["input", "textarea"],
879
+ required: [
880
+ "input",
881
+ "select",
882
+ "textarea"
883
+ ],
884
+ reversed: ["ol"],
885
+ selected: ["option"],
886
+ shadowrootclonable: ["template"],
887
+ shadowrootdelegatesfocus: ["template"],
888
+ shadowrootserializable: ["template"]
889
+ };
890
+ /** Roles elements always have, whatever their attributes. Lists are left out; see the docs on `html-redundant-role`. */
891
+ const IMPLICIT_ROLES = {
892
+ article: "article",
893
+ aside: "complementary",
894
+ blockquote: "blockquote",
895
+ button: "button",
896
+ caption: "caption",
897
+ code: "code",
898
+ datalist: "listbox",
899
+ del: "deletion",
900
+ details: "group",
901
+ dfn: "term",
902
+ dialog: "dialog",
903
+ em: "emphasis",
904
+ fieldset: "group",
905
+ figure: "figure",
906
+ h1: "heading",
907
+ h2: "heading",
908
+ h3: "heading",
909
+ h4: "heading",
910
+ h5: "heading",
911
+ h6: "heading",
912
+ hr: "separator",
913
+ html: "document",
914
+ ins: "insertion",
915
+ main: "main",
916
+ meter: "meter",
917
+ nav: "navigation",
918
+ optgroup: "group",
919
+ option: "option",
920
+ output: "status",
921
+ p: "paragraph",
922
+ progress: "progressbar",
923
+ search: "search",
924
+ strong: "strong",
925
+ sub: "subscript",
926
+ sup: "superscript",
927
+ table: "table",
928
+ tbody: "rowgroup",
929
+ textarea: "textbox",
930
+ tfoot: "rowgroup",
931
+ thead: "rowgroup",
932
+ time: "time",
933
+ tr: "row"
934
+ };
935
+ /** The roles `<input>` has for each `type`, when the role doesn't depend on other attributes. */
936
+ const INPUT_ROLES = {
937
+ button: "button",
938
+ checkbox: "checkbox",
939
+ image: "button",
940
+ number: "spinbutton",
941
+ radio: "radio",
942
+ range: "slider",
943
+ reset: "button",
944
+ submit: "button"
945
+ };
946
+ const HEADINGS = /* @__PURE__ */ new Set([
947
+ "h1",
948
+ "h2",
949
+ "h3",
950
+ "h4",
951
+ "h5",
952
+ "h6"
953
+ ]);
954
+ /** Elements that aren't phrasing content. Starting one ends an open `<p>`. */
955
+ const FLOW = /* @__PURE__ */ new Set([
956
+ "address",
957
+ "article",
958
+ "aside",
959
+ "blockquote",
960
+ "center",
961
+ "dd",
962
+ "details",
963
+ "dialog",
964
+ "dir",
965
+ "div",
966
+ "dl",
967
+ "dt",
968
+ "fieldset",
969
+ "figcaption",
970
+ "figure",
971
+ "footer",
972
+ "form",
973
+ ...HEADINGS,
974
+ "header",
975
+ "hgroup",
976
+ "hr",
977
+ "li",
978
+ "listing",
979
+ "main",
980
+ "menu",
981
+ "nav",
982
+ "ol",
983
+ "p",
984
+ "plaintext",
985
+ "pre",
986
+ "search",
987
+ "section",
988
+ "summary",
989
+ "table",
990
+ "ul",
991
+ "xmp"
992
+ ]);
993
+ /** Elements that only hold phrasing content: text and inline elements. `<p>` is left out, since the browser ends it. */
994
+ const PHRASING_ONLY = /* @__PURE__ */ new Set([
995
+ "abbr",
996
+ "b",
997
+ "bdi",
998
+ "bdo",
999
+ "button",
1000
+ "cite",
1001
+ "code",
1002
+ "data",
1003
+ "dfn",
1004
+ "em",
1005
+ ...HEADINGS,
1006
+ "i",
1007
+ "kbd",
1008
+ "label",
1009
+ "legend",
1010
+ "mark",
1011
+ "meter",
1012
+ "output",
1013
+ "pre",
1014
+ "progress",
1015
+ "q",
1016
+ "rp",
1017
+ "rt",
1018
+ "ruby",
1019
+ "s",
1020
+ "samp",
1021
+ "small",
1022
+ "span",
1023
+ "strong",
1024
+ "sub",
1025
+ "summary",
1026
+ "sup",
1027
+ "time",
1028
+ "u",
1029
+ "var"
1030
+ ]);
1031
+ /** Elements that take the content model of their parent, so their parent decides what they may hold. */
1032
+ const TRANSPARENT = /* @__PURE__ */ new Set([
1033
+ "a",
1034
+ "audio",
1035
+ "canvas",
1036
+ "del",
1037
+ "ins",
1038
+ "map",
1039
+ "noscript",
1040
+ "object",
1041
+ "slot",
1042
+ "video"
1043
+ ]);
1044
+ const SCRIPT_SUPPORTING = ["script", "template"];
1045
+ const TABLE_PARTS = [
1046
+ "caption",
1047
+ "colgroup",
1048
+ "col",
1049
+ "thead",
1050
+ "tbody",
1051
+ "tfoot",
1052
+ "tr"
1053
+ ];
1054
+ /**
1055
+ * Elements that browsers show on a line or in a box of their own, so text either side of their tags doesn't join into
1056
+ * one word: `FLOW`, and the parts of tables, selects, fieldsets and the document. Other elements, including custom ones,
1057
+ * show inline.
1058
+ */
1059
+ const BLOCK = /* @__PURE__ */ new Set([
1060
+ ...FLOW,
1061
+ ...TABLE_PARTS,
1062
+ "td",
1063
+ "th",
1064
+ "optgroup",
1065
+ "option",
1066
+ "legend",
1067
+ "html",
1068
+ "head",
1069
+ "title",
1070
+ "body"
1071
+ ]);
1072
+ /** Elements that only hold certain children. */
1073
+ const ONLY_CHILDREN = {
1074
+ ul: ["li", ...SCRIPT_SUPPORTING],
1075
+ ol: ["li", ...SCRIPT_SUPPORTING],
1076
+ menu: ["li", ...SCRIPT_SUPPORTING],
1077
+ dl: [
1078
+ "dt",
1079
+ "dd",
1080
+ "div",
1081
+ ...SCRIPT_SUPPORTING
1082
+ ],
1083
+ table: [...TABLE_PARTS, ...SCRIPT_SUPPORTING],
1084
+ thead: ["tr", ...SCRIPT_SUPPORTING],
1085
+ tbody: ["tr", ...SCRIPT_SUPPORTING],
1086
+ tfoot: ["tr", ...SCRIPT_SUPPORTING],
1087
+ tr: [
1088
+ "td",
1089
+ "th",
1090
+ ...SCRIPT_SUPPORTING
1091
+ ],
1092
+ colgroup: ["col", "template"],
1093
+ picture: [
1094
+ "source",
1095
+ "img",
1096
+ ...SCRIPT_SUPPORTING
1097
+ ],
1098
+ hgroup: [
1099
+ "p",
1100
+ ...HEADINGS,
1101
+ ...SCRIPT_SUPPORTING
1102
+ ]
1103
+ };
1104
+ /** What `<head>` holds. Anything else ends it, since `</head>` can be left out. */
1105
+ const METADATA = /* @__PURE__ */ new Set([
1106
+ "base",
1107
+ "link",
1108
+ "meta",
1109
+ "noscript",
1110
+ "script",
1111
+ "style",
1112
+ "template",
1113
+ "title"
1114
+ ]);
1115
+ /** Elements that must sit directly inside certain parents. */
1116
+ const REQUIRED_PARENTS = {
1117
+ li: [
1118
+ "ul",
1119
+ "ol",
1120
+ "menu"
1121
+ ],
1122
+ dt: ["dl", "div"],
1123
+ dd: ["dl", "div"],
1124
+ tr: [
1125
+ "table",
1126
+ "thead",
1127
+ "tbody",
1128
+ "tfoot"
1129
+ ],
1130
+ td: ["tr"],
1131
+ th: ["tr"],
1132
+ thead: ["table"],
1133
+ tbody: ["table"],
1134
+ tfoot: ["table"],
1135
+ caption: ["table"],
1136
+ colgroup: ["table"],
1137
+ col: ["colgroup", "table"],
1138
+ summary: ["details"],
1139
+ legend: ["fieldset", "optgroup"],
1140
+ figcaption: ["figure"],
1141
+ source: [
1142
+ "picture",
1143
+ "audio",
1144
+ "video"
1145
+ ],
1146
+ track: ["audio", "video"],
1147
+ rt: ["ruby"],
1148
+ rp: ["ruby"]
1149
+ };
1150
+ /** Elements that must be the first child of their parent. */
1151
+ const FIRST_CHILD = {
1152
+ summary: "details",
1153
+ legend: "fieldset"
1154
+ };
1155
+ /** Where `<main>` may go, besides custom elements. */
1156
+ const MAIN_PARENTS = /* @__PURE__ */ new Set([
1157
+ "html",
1158
+ "body",
1159
+ "div",
1160
+ "form",
1161
+ "template"
1162
+ ]);
1163
+ /**
1164
+ * The "special" elements of the HTML parser, which stop it looking further for an `<li>`, `<dd>` or `<dt>` to end.
1165
+ * `address`, `div` and `p` are left out, as the parser looks past them.
1166
+ */
1167
+ const SPECIAL = /* @__PURE__ */ new Set([
1168
+ "applet",
1169
+ "area",
1170
+ "article",
1171
+ "aside",
1172
+ "base",
1173
+ "basefont",
1174
+ "bgsound",
1175
+ "blockquote",
1176
+ "body",
1177
+ "br",
1178
+ "button",
1179
+ "caption",
1180
+ "center",
1181
+ "col",
1182
+ "colgroup",
1183
+ "dd",
1184
+ "details",
1185
+ "dir",
1186
+ "dl",
1187
+ "dt",
1188
+ "embed",
1189
+ "fieldset",
1190
+ "figcaption",
1191
+ "figure",
1192
+ "footer",
1193
+ "form",
1194
+ "frame",
1195
+ "frameset",
1196
+ ...HEADINGS,
1197
+ "head",
1198
+ "header",
1199
+ "hgroup",
1200
+ "hr",
1201
+ "html",
1202
+ "iframe",
1203
+ "img",
1204
+ "input",
1205
+ "keygen",
1206
+ "li",
1207
+ "link",
1208
+ "listing",
1209
+ "main",
1210
+ "marquee",
1211
+ "menu",
1212
+ "meta",
1213
+ "nav",
1214
+ "noembed",
1215
+ "noframes",
1216
+ "noscript",
1217
+ "object",
1218
+ "ol",
1219
+ "param",
1220
+ "plaintext",
1221
+ "pre",
1222
+ "script",
1223
+ "search",
1224
+ "section",
1225
+ "select",
1226
+ "source",
1227
+ "style",
1228
+ "summary",
1229
+ "table",
1230
+ "tbody",
1231
+ "td",
1232
+ "template",
1233
+ "textarea",
1234
+ "tfoot",
1235
+ "th",
1236
+ "thead",
1237
+ "title",
1238
+ "tr",
1239
+ "track",
1240
+ "ul",
1241
+ "wbr",
1242
+ "xmp"
1243
+ ]);
1244
+ /** Elements that end the search for an open `<p>` or `<button>`: the parser's "button scope". */
1245
+ const BUTTON_SCOPE = /* @__PURE__ */ new Set([
1246
+ "applet",
1247
+ "button",
1248
+ "caption",
1249
+ "html",
1250
+ "marquee",
1251
+ "object",
1252
+ "table",
1253
+ "td",
1254
+ "template",
1255
+ "th"
1256
+ ]);
1257
+ //#endregion
148
1258
  //#region src/runtime/escape.ts
149
1259
  /** Throws a `KilnIssue`, which the call site locates. */
150
1260
  const tooLong = (limit) => issue("limit-output", `Escaping made a string longer than the output limit of ${limit}`);
@@ -295,13 +1405,19 @@ const distance = (a, b) => {
295
1405
  }
296
1406
  return at(a.length, b.length);
297
1407
  };
1408
+ /** Names longer than this get no hint, since each candidate costs the product of the two lengths to compare. */
1409
+ const MAX_NAME_LENGTH = 64;
298
1410
  /** Returns a `Did you mean "x"?` hint for the closest candidate, or undefined if none is close. */
299
1411
  const suggest = (name, candidates) => {
1412
+ if (name.length > MAX_NAME_LENGTH) return void 0;
1413
+ const lower = name.toLowerCase();
300
1414
  let best;
301
1415
  let bestDistance = Math.max(1, Math.floor(name.length / 3)) + 1;
302
1416
  for (const candidate of candidates) {
303
1417
  if (candidate === name) continue;
304
- const score = distance(name.toLowerCase(), candidate.toLowerCase());
1418
+ const other = candidate.toLowerCase();
1419
+ if (Math.abs(other.length - lower.length) >= bestDistance) continue;
1420
+ const score = distance(lower, other);
305
1421
  if (score < bestDistance) {
306
1422
  best = candidate;
307
1423
  bestDistance = score;
@@ -398,6 +1514,7 @@ var RenderState = class {
398
1514
  timeZone;
399
1515
  userState;
400
1516
  signal;
1517
+ /** Steps counted so far. A streamed island's state counts up to `maxSteps` through the lease it holds. */
401
1518
  steps = 0;
402
1519
  /** Parts of the render running ahead of a part that waits, and not joined yet. See `ahead.ts`. */
403
1520
  ahead = 0;
@@ -424,6 +1541,13 @@ var RenderState = class {
424
1541
  streamed = null;
425
1542
  /** Whether the `<kiln-island>` script is in the render's output yet. */
426
1543
  islandScript = false;
1544
+ /**
1545
+ * For a streamed island's state, the page's state, which lends it steps a lease at a time. Null otherwise. See
1546
+ * `moreSteps`.
1547
+ */
1548
+ page = null;
1549
+ /** The streamed islands still rendering, which may hold steps this state lent them. Made at the first island. */
1550
+ islandStates = null;
427
1551
  constructor(env, globals, maxSteps, maxSize, maxDepth, locale, timeZone, userState, signal) {
428
1552
  this.env = env;
429
1553
  this.globals = globals;
@@ -444,12 +1568,16 @@ var RenderState = class {
444
1568
  */
445
1569
  var Capture = class {
446
1570
  outer;
1571
+ parent;
447
1572
  section;
448
1573
  behind;
449
1574
  /** The additions made in it, and the captures started in it, in order. Made when the first is. */
450
1575
  additions = null;
451
- constructor(outer, section, behind) {
1576
+ /** Whether it is in `outer` yet. One running ahead goes in once the part before it is done. */
1577
+ linked = true;
1578
+ constructor(outer, parent, section, behind) {
452
1579
  this.outer = outer;
1580
+ this.parent = parent;
453
1581
  this.section = section;
454
1582
  this.behind = behind;
455
1583
  }
@@ -462,7 +1590,7 @@ const additionLog = (run) => {
462
1590
  /** Starts a capture inside `run`'s. With `section`, it is a cached section. */
463
1591
  const startCapture = (run, section) => {
464
1592
  const outer = additionLog(run);
465
- const capture = new Capture(outer, section ?? run.capture?.section ?? null, run.capture?.behind ?? null);
1593
+ const capture = new Capture(outer, run.capture, section ?? run.capture?.section ?? null, run.capture?.behind ?? null);
466
1594
  outer.push(capture);
467
1595
  return capture;
468
1596
  };
@@ -591,20 +1719,25 @@ const recordAddition = (run, span, addition, front = false) => {
591
1719
  /**
592
1720
  * After a `flush` closes outlets, fails for content a part running ahead added to one of them before then. Every part
593
1721
  * before the flush is done and in the log by now, so content outside the log comes after the flush in the template,
594
- * where adding to a closed outlet is an error.
1722
+ * where adding to a closed outlet is an error. Content in the log is checked, so it is dropped from `late`.
595
1723
  */
596
1724
  const checkLate = (state) => {
597
1725
  const late = state.late;
598
1726
  if (late === null) return;
599
- const logged = new Set(additionsIn(state.additions ?? []));
600
- for (const { addition, run, span } of late) {
601
- if (logged.has(addition)) continue;
1727
+ let kept = null;
1728
+ for (const entry of late) {
1729
+ if (inLog(entry.run.capture)) continue;
1730
+ const { addition, run, span } = entry;
602
1731
  const mark = state.outlets?.get(addition.outlet);
603
- if (mark === void 0 || mark.content === null) continue;
604
- if (addition.once !== null && state.once?.has(addition.once)) continue;
605
- throw closedError(run, span, addition.outlet);
1732
+ if (mark !== void 0 && mark.content !== null && (addition.once === null || !state.once?.has(addition.once))) throw closedError(run, span, addition.outlet);
1733
+ (kept ??= []).push(entry);
606
1734
  }
607
- state.late = late.filter(({ addition }) => !logged.has(addition));
1735
+ state.late = kept;
1736
+ };
1737
+ /** Whether additions made in `capture` are in the render's log: it and every capture around it are linked. */
1738
+ const inLog = (capture) => {
1739
+ for (let at = capture; at !== null; at = at.parent) if (!at.linked) return false;
1740
+ return true;
608
1741
  };
609
1742
  const closedError = (run, span, outlet) => fail(run, span, "outlet-closed", `Outlet "${outlet}" was closed by "flush", so content can't be added to it any more`);
610
1743
  /** Closes every outlet reached so far, fixing its content. */
@@ -663,6 +1796,11 @@ const takeOutput = (state, output) => {
663
1796
  const NOTHING = () => {};
664
1797
  /** Whether parts may start early ahead of a part that waits: the render runs fewer parts ahead than it may. */
665
1798
  const mayRunAhead = (state) => state.ahead < 64;
1799
+ /** Puts a capture that ran ahead in its place in the log, once the part before it is done. */
1800
+ const link = (log, capture) => {
1801
+ log.push(capture);
1802
+ capture.linked = true;
1803
+ };
666
1804
  /**
667
1805
  * Starts `rest` while `pending`, the promise of the part before it, waits, and returns a promise for both. Rejects with
668
1806
  * the part's error when it fails, or else with the rest's, after both settle, so a failed render has nothing still
@@ -673,10 +1811,11 @@ const runAhead = (run, out, pending, rest, span) => {
673
1811
  state.ahead++;
674
1812
  const log = additionLog(run);
675
1813
  const outer = run.capture;
676
- const capture = new Capture(log, outer?.section ?? null, {
1814
+ const capture = new Capture(log, outer, outer?.section ?? null, {
677
1815
  part: pending,
678
1816
  previous: outer?.behind ?? null
679
1817
  });
1818
+ capture.linked = false;
680
1819
  const ahead = {
681
1820
  s: "",
682
1821
  ahead: out.ahead ?? {
@@ -702,10 +1841,10 @@ const runAhead = (run, out, pending, rest, span) => {
702
1841
  }
703
1842
  };
704
1843
  pending.then(() => {
705
- log.push(capture);
1844
+ link(log, capture);
706
1845
  settle();
707
1846
  }, (error) => {
708
- log.push(capture);
1847
+ link(log, capture);
709
1848
  failure = { error };
710
1849
  settle();
711
1850
  });
@@ -836,7 +1975,7 @@ const passesFrom = (run, out, pending, from, to, pass, span, ahead) => {
836
1975
  };
837
1976
  const done = () => {
838
1977
  settled[at] = true;
839
- while (linked < captures.length && settled[linked] === true) log.push(captures[linked++]);
1978
+ while (linked < captures.length && settled[linked] === true) link(log, captures[linked++]);
840
1979
  if (--left === 0) finish();
841
1980
  };
842
1981
  part.then(done, (error) => {
@@ -849,7 +1988,8 @@ const passesFrom = (run, out, pending, from, to, pass, span, ahead) => {
849
1988
  while (index < to) {
850
1989
  const at = segments.length + 1;
851
1990
  state.ahead++;
852
- const capture = new Capture(log, section, behind);
1991
+ const capture = new Capture(log, outer, section, behind);
1992
+ capture.linked = false;
853
1993
  const segment = {
854
1994
  s: "",
855
1995
  ahead: group
@@ -968,6 +2108,11 @@ const exposedMembers = (proto) => {
968
2108
  };
969
2109
  //#endregion
970
2110
  //#region src/runtime/values.ts
2111
+ /**
2112
+ * Lists and hashes nested deeper than this are refused by `json`, `dump`, `urlEncode` and island props, so they can't
2113
+ * overflow the stack.
2114
+ */
2115
+ const MAX_DATA_DEPTH = 1e3;
971
2116
  /** Returned by guarded lookups for a variable or property that does not exist. Never escapes into template values. */
972
2117
  const MISSING = Symbol("kiln.missing");
973
2118
  /** Checks for an object literal or a null-prototype object, which Kiln treats as a hash. */
@@ -1116,8 +2261,7 @@ const valueLabel = (value) => {
1116
2261
  };
1117
2262
  /**
1118
2263
  * Arrow functions written in templates, each mapped to the version built-ins call. Built-ins that take callbacks accept
1119
- * only these, never functions found in data. A promise from the built-ins' version may resolve to a held value; see
1120
- * `hold`.
2264
+ * only these, never functions found in data.
1121
2265
  */
1122
2266
  const templateFunctions = /* @__PURE__ */ new WeakMap();
1123
2267
  /** A class instance prints only when its class exposes `toString`. */
@@ -1252,10 +2396,59 @@ const locating = (run, span, produce, host) => {
1252
2396
  throw locate(run, span, error, host);
1253
2397
  }
1254
2398
  };
2399
+ /** Starts a streamed island's counting, with no lease yet: its first step takes one. */
2400
+ const lendSteps = (page, island) => {
2401
+ island.page = page;
2402
+ island.steps = island.maxSteps;
2403
+ (page.islandStates ??= []).push(island);
2404
+ };
2405
+ /** Takes back the steps an island holds and hasn't counted, so it takes a new lease at its next step. */
2406
+ const reclaimLease = (page, island) => {
2407
+ const unused = island.maxSteps - island.steps;
2408
+ if (unused > 0) {
2409
+ page.steps -= unused;
2410
+ island.steps = island.maxSteps;
2411
+ }
2412
+ };
2413
+ /** Takes back every lease `page`'s islands hold and haven't counted. */
2414
+ const reclaimLeases = (page) => {
2415
+ for (const island of page.islandStates ?? []) reclaimLease(page, island);
2416
+ };
2417
+ /** Gives back the steps a finished island hasn't counted. */
2418
+ const returnSteps = (island) => {
2419
+ const page = island.page;
2420
+ const islands = page?.islandStates;
2421
+ if (!page || !islands) return;
2422
+ reclaimLease(page, island);
2423
+ const index = islands.indexOf(island);
2424
+ if (index !== -1) islands.splice(index, 1);
2425
+ };
2426
+ /**
2427
+ * Called once `state.steps` passes `maxSteps`. Takes back leases or takes a new one, and returns whether the render
2428
+ * can carry on, with `state.steps` within `maxSteps` again.
2429
+ */
2430
+ const moreSteps = (state) => {
2431
+ const page = state.page;
2432
+ if (page === null) {
2433
+ if (state.islandStates === null) return false;
2434
+ reclaimLeases(state);
2435
+ return state.steps <= state.maxSteps;
2436
+ }
2437
+ const needed = state.steps - state.maxSteps;
2438
+ if (page.maxSteps - page.steps < needed) reclaimLeases(page);
2439
+ const left = page.maxSteps - page.steps;
2440
+ if (left < needed) return false;
2441
+ const grant = needed + Math.floor((left - needed) / 2);
2442
+ page.steps += grant;
2443
+ state.steps -= grant;
2444
+ return true;
2445
+ };
2446
+ /** The `limit-steps` error, located at `span`. */
2447
+ const stepError = (run, span) => fail(run, span, "limit-steps", `Render stopped after ${run.state.maxSteps} steps`);
1255
2448
  /** Counts one step against `maxSteps`, and checks the abort signal. */
1256
2449
  const step = (run, span) => {
1257
2450
  const state = run.state;
1258
- if (++state.steps > state.maxSteps) throw fail(run, span, "limit-steps", `Render stopped after ${state.maxSteps} steps`);
2451
+ if (++state.steps > state.maxSteps && !moreSteps(state)) throw stepError(run, span);
1259
2452
  if (state.signal?.aborted) throw fail(run, span, "aborted", "Render was aborted");
1260
2453
  };
1261
2454
  /**
@@ -1266,13 +2459,13 @@ const step = (run, span) => {
1266
2459
  const consume = (run, amount) => {
1267
2460
  const state = run.state;
1268
2461
  state.steps += amount;
1269
- if (state.steps > state.maxSteps) issue("limit-steps", `Render stopped after ${state.maxSteps} steps`);
2462
+ if (state.steps > state.maxSteps && !moreSteps(state)) issue("limit-steps", `Render stopped after ${state.maxSteps} steps`);
1270
2463
  };
1271
2464
  /** `consume`, failing at `span`. For work in proportion to a value's size, such as the variables an include passes. */
1272
2465
  const consumeAt = (run, span, amount) => {
1273
2466
  const state = run.state;
1274
2467
  state.steps += amount;
1275
- if (state.steps > state.maxSteps) throw fail(run, span, "limit-steps", `Render stopped after ${state.maxSteps} steps`);
2468
+ if (state.steps > state.maxSteps && !moreSteps(state)) throw stepError(run, span);
1276
2469
  };
1277
2470
  /** Refuses strings longer than `maxOutputLength`, which could never be printed. */
1278
2471
  const checkLength = (run, text) => {
@@ -1655,8 +2848,6 @@ const readableNames = (target) => {
1655
2848
  //#region src/builtins/helpers.ts
1656
2849
  /** Iterables from the host are read up to this many items, so an endless generator cannot hang a filter. */
1657
2850
  const MAX_ITERABLE_ITEMS = 1e6;
1658
- /** Lists and hashes nested deeper than this are refused by `json`, `dump` and `urlEncode`, so they can't overflow the stack. */
1659
- const MAX_DATA_DEPTH = 1e3;
1660
2851
  /** Refuses data nested deeper than `MAX_DATA_DEPTH`. */
1661
2852
  const checkDepth = (depth, what) => {
1662
2853
  if (depth > 1e3) issue("too-deep", `"${what}" cannot convert data nested more than ${MAX_DATA_DEPTH} levels deep`);
@@ -1679,6 +2870,12 @@ const mapContents = (map) => {
1679
2870
  };
1680
2871
  };
1681
2872
  /**
2873
+ * A hash key as the name a filter builds a hash, query string or attribute with. A `Map`'s number, boolean and other
2874
+ * primitive keys convert as `String` does. An object or symbol key gives null, and is skipped, as loops with keys
2875
+ * skip it, since converting an object would call its methods.
2876
+ */
2877
+ const keyName = (key) => typeof key === "string" ? key : typeof key === "object" && key !== null || typeof key === "function" || typeof key === "symbol" ? null : String(key);
2878
+ /**
1682
2879
  * Values and keys of anything a filter can treat as a list. Hashes keep their keys.
1683
2880
  *
1684
2881
  * Every item is charged against `maxSteps`: arrays and hashes before they are read, and iterables such as generators
@@ -1896,7 +3093,8 @@ const toPlainData = (value, onCycle, { what, charge = () => {}, maxLength = Infi
1896
3093
  };
1897
3094
  charge(keys.length);
1898
3095
  for (let i = 0; i < keys.length; i++) {
1899
- const name = String(keys[i]);
3096
+ const name = keyName(keys[i]);
3097
+ if (name === null) continue;
1900
3098
  const item = convert(values ? values[i] : getAttr(object, name), depth + 1);
1901
3099
  if (item !== void 0 && item !== MISSING) {
1902
3100
  grow(name.length + (indent === 0 ? 4 : 6 + (depth + 1) * indent));
@@ -1937,11 +3135,18 @@ const tagEnd = (html, from, lastDouble, lastSingle) => {
1937
3135
  }
1938
3136
  return -1;
1939
3137
  };
3138
+ /** The start tag of a `<script>` or `<style>`, whose content browsers never read as HTML. */
3139
+ const RAW_TEXT_START = /<(script|style)[\s/>]/iy;
3140
+ const SCRIPT_END = /<\/script[\s/>]/gi;
3141
+ const STYLE_END = /<\/style[\s/>]/gi;
1940
3142
  /**
1941
3143
  * Splits HTML into tags and comments, given to `onTag`, and the text between them, given to `onText`, in one linear
1942
3144
  * pass. A `<` that doesn't start a tag that closes is text.
3145
+ *
3146
+ * With `rawText`, a `<script>` or `<style>` start tag and its content, up to the end tag or the end of the HTML, go
3147
+ * to `onTag` as one piece, since browsers don't decode entities or find tags in them.
1943
3148
  */
1944
- const scanHtml = (html, onText, onTag) => {
3149
+ const scanHtml = (html, onText, onTag, rawText = false) => {
1945
3150
  const lastDouble = html.lastIndexOf("\"");
1946
3151
  const lastSingle = html.lastIndexOf("'");
1947
3152
  let index = 0;
@@ -1950,6 +3155,15 @@ const scanHtml = (html, onText, onTag) => {
1950
3155
  let tagsCanClose = true;
1951
3156
  const tag = (open, end) => {
1952
3157
  if (textStart < open) onText(html.slice(textStart, open));
3158
+ if (rawText && (html.charCodeAt(open + 1) | 32) === 115) {
3159
+ RAW_TEXT_START.lastIndex = open;
3160
+ const name = RAW_TEXT_START.exec(html)?.[1];
3161
+ if (name !== void 0) {
3162
+ const closer = name.toLowerCase() === "script" ? SCRIPT_END : STYLE_END;
3163
+ closer.lastIndex = end;
3164
+ end = closer.exec(html)?.index ?? html.length;
3165
+ }
3166
+ }
1953
3167
  onTag(html.slice(open, end));
1954
3168
  index = textStart = end;
1955
3169
  };
@@ -2045,12 +3259,12 @@ const decodeSequences = (text, strategy) => {
2045
3259
  };
2046
3260
  /**
2047
3261
  * Splits markup into its decoded text and the pieces string filters keep as they are. HTML markup keeps its tags,
2048
- * comments and the entities the escapers don't write. Other markup is all text.
3262
+ * comments, `<script>` and `<style>` elements, and the entities the escapers don't write. Other markup is all text.
2049
3263
  */
2050
3264
  const toPieces = (markup) => {
2051
3265
  if (!isHtmlStrategy(markup.strategy)) return [decodeSequences(markup.value, markup.strategy)];
2052
3266
  const pieces = [];
2053
- scanHtml(markup.value, (text) => decodeEntities(text, pieces), (tag) => pieces.push(new Kept(tag)));
3267
+ scanHtml(markup.value, (text) => decodeEntities(text, pieces), (tag) => pieces.push(new Kept(tag)), true);
2054
3268
  return pieces;
2055
3269
  };
2056
3270
  /** Joins pieces back into markup, escaping the text with the markup's strategy. */
@@ -2228,7 +3442,8 @@ const builtinFunctions = {
2228
3442
  const { values, keys } = entriesOf(run, target, "attrs");
2229
3443
  let html = "";
2230
3444
  keys.forEach((key, index) => {
2231
- const name = String(key);
3445
+ const name = keyName(key);
3446
+ if (name === null) return;
2232
3447
  if (!ATTRIBUTE_NAME.test(name)) issue("invalid-argument", `"${name}" is not a valid attribute name`);
2233
3448
  const value = values[index];
2234
3449
  if (value === true) {
@@ -2272,6 +3487,9 @@ const builtinTests = {
2272
3487
  };
2273
3488
  //#endregion
2274
3489
  //#region src/source.ts
3490
+ /** Lines longer than this show only `FRAME_WIDTH` characters around the span in a frame. */
3491
+ const MAX_FRAME_LINE = 200;
3492
+ const FRAME_WIDTH = 120;
2275
3493
  /**
2276
3494
  * A template's text and resolved name.
2277
3495
  *
@@ -2319,15 +3537,21 @@ var Source = class {
2319
3537
  const lastLine = Math.min(starts.length, start.line + context);
2320
3538
  const gutter = String(lastLine).length;
2321
3539
  const lines = [];
3540
+ const from = Math.max(0, start.column - 1 - FRAME_WIDTH / 2);
2322
3541
  for (let line = firstLine; line <= lastLine; line++) {
2323
- const text = this.#lineText(line);
3542
+ const full = this.#lineText(line);
3543
+ const long = full.length > MAX_FRAME_LINE;
3544
+ const shownFrom = long ? Math.min(from, full.length - FRAME_WIDTH) : 0;
3545
+ const shownTo = long ? shownFrom + FRAME_WIDTH : full.length;
3546
+ const before = shownFrom > 0 ? "…" : "";
3547
+ const text = `${before}${full.slice(shownFrom, shownTo)}${shownTo < full.length ? "…" : ""}`;
2324
3548
  const number = String(line).padStart(gutter);
2325
3549
  const marker = line === start.line ? ">" : " ";
2326
3550
  lines.push(`${marker} ${number} | ${text}`);
2327
3551
  if (line === start.line) {
2328
- const lineEnd = this.#lineStart(line) + text.length;
3552
+ const lineEnd = this.#lineStart(line) + shownTo;
2329
3553
  const width = Math.max(1, Math.min(span.end, lineEnd) - span.start);
2330
- const indent = text.slice(0, start.column - 1).replace(/[^\t]/g, " ");
3554
+ const indent = (before + full.slice(shownFrom, start.column - 1)).replace(/[^\t]/g, " ");
2331
3555
  lines.push(` ${" ".repeat(gutter)} | ${indent}${"^".repeat(width)}`);
2332
3556
  }
2333
3557
  }
@@ -2353,6 +3577,6 @@ var Source = class {
2353
3577
  }
2354
3578
  };
2355
3579
  //#endregion
2356
- export { compare as $, escapeUrl as $t, consume as A, additionsIn as At, loadTemplate as B, fillScope as Bt, getAttr as C, contentSets as Ct, after as D, passesFrom as Dt, addSlotFlags as E, passesAhead as Et, fail as F, RenderState as Ft, renderTemplate as G, sectionCopy as Gt, locating as H, childScope as Ht, hold as I, Run as It, unhold as J, suggest as Jt, silence as K, sectionScope as Kt, holdData as L, blockScope as Lt, embed as M, closeOutlets as Mt, embedKeyed as N, recordAddition as Nt, all as O, runAhead as Ot, embedScope as P, takeOutput as Pt, MISSING as Q, escapeHtml as Qt, importsFor as R, emptyOut as Rt, toTime as S, atFront as St, readableNames as T, mayRunAhead as Tt, markCaller as U, lookup$1 as Ut, locate as V, startCapture as Vt, passData as W, ownerOf as Wt, write as X, isSafe as Xt, withCaller as Y, Markup as Yt, FORMATTERS as Z, safe as Zt, markupText as _, unwrap as _t, operatorFunction as a, KilnSyntaxError as an, isHashLike as at, toPieces as b, expose as bt, checkDepth as c, mapKeys as ct, functionArgument as d, templateFunctions as dt, escapeWith as en, describeType as et, insertedPiece as f, toNumber as ft, mapContents as g, typeName as gt, listOf as h, truthy as ht, contains as i, KilnRenderError as in, isEmpty as it, consumeAt as j, checkLate as jt, checkLength as k, runSequence as kt, entriesOf as l, matchesType as lt, isHtmlStrategy as m, toStringArgument as mt, builtinFunctions as n, resolveTemplateName as nn, equals as nt, rangeOperator as o, createDiagnostic as on, isPlainObject as ot, integerArgument as p, toStr as pt, step as q, variableNames as qt, builtinTests as r, KilnIssue as rn, hashKeys as rt, Kept as s, issue as sn, literalOptions as st, Source as t, TEMPLATE_EXTENSION as tn, describeValue as tt, fromPieces as u, setOwn as ut, readProperty as v, valueLabel as vt, getMethod as w, isRoot as wt, toPlainData as x, lookup as xt, scanHtml as y, BLOCKED_NAMES as yt, isPromise as z, endCapture as zt };
3580
+ export { unhold as $, variableNames as $t, checkLength as A, VOID as An, isRoot as At, isPromise as B, takeOutput as Bt, toTime as C, ONLY_CHILDREN as Cn, unwrap as Ct, addSlotFlags as D, ROLES as Dn, lookup as Dt, readableNames as E, REQUIRED_PARENTS as En, expose as Et, embedScope as F, KilnSyntaxError as Fn, runSequence as Ft, markCaller as G, endCapture as Gt, loadTemplate as H, Run as Ht, fail as I, createDiagnostic as In, additionsIn as It, renderTemplate as J, childScope as Jt, moreSteps as K, fillScope as Kt, hold as L, issue as Ln, checkLate as Lt, consumeAt as M, resolveTemplateName as Mn, passesAhead as Mt, embed as N, KilnIssue as Nn, passesFrom as Nt, after as O, SPECIAL as On, atFront as Ot, embedKeyed as P, KilnRenderError as Pn, runAhead as Pt, stepError as Q, sectionScope as Qt, holdData as R, closeOutlets as Rt, toPlainData as S, OBSOLETE_ATTRIBUTES as Sn, typeName as St, getMethod as T, RAW_TEXT as Tn, BLOCKED_NAMES as Tt, locate as U, blockScope as Ut, lendSteps as V, RenderState as Vt, locating as W, emptyOut as Wt, silence as X, ownerOf as Xt, returnSteps as Y, lookup$1 as Yt, step as Z, sectionCopy as Zt, mapContents as _, IMPLICIT_ROLES as _n, templateFunctions as _t, operatorFunction as a, escapeUrl as an, compare as at, scanHtml as b, METADATA as bn, toStringArgument as bt, checkDepth as c, ARIA_ATTRIBUTES as cn, equals as ct, functionArgument as d, BOOLEAN_ATTRIBUTES as dn, isHashLike as dt, suggest as en, withCaller as et, insertedPiece as f, BUTTON_SCOPE as fn, isPlainObject as ft, listOf as g, HEADINGS as gn, setOwn as gt, keyName as h, FOREIGN as hn, matchesType as ht, contains as i, escapeHtml as in, MISSING as it, consume as j, TEMPLATE_EXTENSION as jn, mayRunAhead as jt, all as k, TRANSPARENT as kn, contentSets as kt, entriesOf as l, ATTRIBUTE_VALUES as ln, hashKeys as lt, isHtmlStrategy as m, FLOW as mn, mapKeys as mt, builtinFunctions as n, isSafe as nn, FORMATTERS as nt, rangeOperator as o, escapeWith as on, describeType as ot, integerArgument as p, FIRST_CHILD as pn, literalOptions as pt, passData as q, startCapture as qt, builtinTests as r, safe as rn, MAX_DATA_DEPTH as rt, Kept as s, ABSTRACT_ROLES as sn, describeValue as st, Source as t, Markup as tn, write as tt, fromPieces as u, BLOCK as un, isEmpty as ut, markupText as v, INPUT_ROLES as vn, toNumber as vt, getAttr as w, PHRASING_ONLY as wn, valueLabel as wt, toPieces as x, OBSOLETE as xn, truthy as xt, readProperty as y, MAIN_PARENTS as yn, toStr as yt, importsFor as z, recordAddition as zt };
2357
3581
 
2358
- //# sourceMappingURL=source-DxHQeBEo.js.map
3582
+ //# sourceMappingURL=source-tVX6J33O.js.map