yvee 0.1.3 → 0.1.5

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.
package/dist/index.d.ts CHANGED
@@ -477,64 +477,100 @@ type CSSStyle = {
477
477
  };
478
478
 
479
479
  interface c_events<T extends Elements = HTMLElement> {
480
- state?: (this: T, e: T) => maybePromise<[
480
+ state?: ((this: T, e: T) => maybePromise<[
481
481
  (...args: any[]) => void,
482
482
  IStateful<any>[],
483
483
  boolean?,
484
484
  boolean?
485
- ]>;
486
- states?: (this: T, e: T) => maybePromise<[
485
+ ]>) | undefined;
486
+ states?: ((this: T, e: T) => maybePromise<[
487
487
  (...args: any[]) => void,
488
488
  IStateful<any>[],
489
489
  boolean?,
490
490
  boolean?
491
- ]>[];
492
- ready?: (this: T, e: T) => maybePromise<void | (() => void)>;
493
- resize?: (this: T, e: UIEvent) => void;
494
- beforeunload?: (this: T, e: BeforeUnloadEvent) => void;
495
- popstate?: (this: T, e: PopStateEvent) => void;
496
- DOMContentLoaded?: (this: T, e: Event) => void;
497
- winscroll?: (this: T, e: Event) => void;
498
- winload?: (this: T, e: Event) => void;
499
- winfocus?: (this: T, e: Event) => void;
500
- winblur?: (this: T, e: Event) => void;
501
- winkeydown?: (this: T, e: KeyboardEvent) => void;
502
- winkeypress?: (this: T, e: KeyboardEvent) => void;
503
- winkeyup?: (this: T, e: KeyboardEvent) => void;
491
+ ]>[]) | undefined;
492
+ ready?: ((this: T, e: T) => maybePromise<void | (() => void)>) | undefined;
493
+ resize?: ((this: T, e: UIEvent) => void) | undefined;
494
+ beforeunload?: ((this: T, e: BeforeUnloadEvent) => void) | undefined;
495
+ popstate?: ((this: T, e: PopStateEvent) => void) | undefined;
496
+ DOMContentLoaded?: ((this: T, e: Event) => void) | undefined;
497
+ winscroll?: ((this: T, e: Event) => void) | undefined;
498
+ winload?: ((this: T, e: Event) => void) | undefined;
499
+ winfocus?: ((this: T, e: Event) => void) | undefined;
500
+ winblur?: ((this: T, e: Event) => void) | undefined;
501
+ winkeydown?: ((this: T, e: KeyboardEvent) => void) | undefined;
502
+ winkeypress?: ((this: T, e: KeyboardEvent) => void) | undefined;
503
+ winkeyup?: ((this: T, e: KeyboardEvent) => void) | undefined;
504
504
  }
505
+ /**
506
+ * Event handler map accepted by `on`. Every handler is optional and may be
507
+ * explicitly `undefined`; the renderer skips absent handlers.
508
+ */
505
509
  type DOMEvents<T extends Elements = HTMLElement> = {
506
- [P in keyof GlobalEventHandlersEventMap]?: (this: T, event: GlobalEventHandlersEventMap[P]) => void;
510
+ [P in keyof GlobalEventHandlersEventMap]?: ((this: T, event: GlobalEventHandlersEventMap[P]) => void) | undefined;
507
511
  } & c_events<T>;
508
512
 
513
+ /**
514
+ * Attributes accepted by every Yvee element. Optional attributes are declared
515
+ * as `?: T | undefined` so a conditionally-present value
516
+ * (`disabled={props.disabled}`) type-checks under `exactOptionalPropertyTypes`;
517
+ * an explicitly `undefined` attribute is dropped during render.
518
+ */
509
519
  interface EAttr<T = DVal> {
510
520
  [key: string]: any;
511
521
  [key: `data-${string}`]: T | any;
512
- accesskey?: T;
513
- autocapitalize?: T;
514
- class?: T | T[];
515
- on?: DOMEvents<any>;
516
- ref?: Ref<any>;
517
- contenteditable?: T;
518
- dir?: T;
519
- draggable?: T;
520
- hidden?: T;
521
- id?: T;
522
- itemprop?: T;
523
- lang?: T;
524
- role?: T;
525
- slot?: T;
526
- spellcheck?: T;
527
- style?: CSSStyle | string;
528
- tabindex?: T;
529
- title?: T;
530
- translate?: T;
522
+ accesskey?: T | undefined;
523
+ autocapitalize?: T | undefined;
524
+ class?: T | T[] | undefined;
525
+ on?: DOMEvents<any> | undefined;
526
+ ref?: Ref<any> | undefined;
527
+ contenteditable?: T | undefined;
528
+ dir?: T | undefined;
529
+ draggable?: T | undefined;
530
+ hidden?: T | undefined;
531
+ id?: T | undefined;
532
+ itemprop?: T | undefined;
533
+ lang?: T | undefined;
534
+ role?: T | undefined;
535
+ slot?: T | undefined;
536
+ spellcheck?: T | undefined;
537
+ style?: CSSStyle | string | undefined;
538
+ tabindex?: T | undefined;
539
+ title?: T | undefined;
540
+ translate?: T | undefined;
531
541
  }
532
542
 
543
+ /**
544
+ * Attribute/event shape accepted by renderer nodes and JSX intrinsics.
545
+ *
546
+ * Optional attributes accept an explicitly `undefined` value
547
+ * (`disabled?: T | undefined`) and are omitted from the rendered markup.
548
+ */
533
549
  type DOMAttr = EAttr;
534
550
  type DOMValue<T = V | V[]> = DVal<T>;
535
551
  type DOMRenderable = string | number | boolean | null | undefined | DOM | DOMRenderable[] | IStateful<unknown> | object | (() => maybePromise<DOMRenderable>);
536
552
  type DOMContext = maybePromise<DOMRenderable>;
553
+ /**
554
+ * Attributes passed to a Yvee function component: {@link DOMAttr} plus the
555
+ * component's own props.
556
+ *
557
+ * JSX children are **not** part of this object. `dom` forwards them as rest
558
+ * arguments, so `props.children` is always `undefined`; declare components as
559
+ * `(props: P, ...children: DOMContext[])` and render `{children}`.
560
+ */
537
561
  type DOMComponentProps<T extends object = {}> = DOMAttr & T;
562
+ /**
563
+ * Type of a Yvee function component.
564
+ *
565
+ * The first parameter carries attributes/props; JSX children arrive as the
566
+ * remaining rest parameters (they are never placed on the props object).
567
+ *
568
+ * ```tsx
569
+ * function Card(props: { title: string }, ...children: DOMContext[]) {
570
+ * return <section><h2>{props.title}</h2>{children}</section>;
571
+ * }
572
+ * ```
573
+ */
538
574
  type DOMComponent<T extends object = {}> = (attributes: DOMComponentProps<T>, ...children: DOMContext[]) => maybePromise<DOM>;
539
575
  type DOMNode = DOM;
540
576
 
@@ -548,329 +584,329 @@ declare function dom(tag: string | DOMComponent, attr?: DOMAttr | null, ...ctx:
548
584
  declare const frag: (_attr: DOMAttr, ...ctx: DOMContext[]) => Promise<DOM>;
549
585
 
550
586
  interface aAttr<T = DVal> extends EAttr {
551
- download?: T;
552
- href?: T;
553
- hreflang?: T;
554
- media?: T;
555
- ping?: T;
556
- referrerpolicy?: T;
557
- rel?: T;
558
- shape?: T;
559
- target?: T;
587
+ download?: T | undefined;
588
+ href?: T | undefined;
589
+ hreflang?: T | undefined;
590
+ media?: T | undefined;
591
+ ping?: T | undefined;
592
+ referrerpolicy?: T | undefined;
593
+ rel?: T | undefined;
594
+ shape?: T | undefined;
595
+ target?: T | undefined;
560
596
  }
561
597
  interface areaAttr<T = DVal> extends EAttr {
562
- alt?: T;
563
- coords?: T;
564
- download?: T;
565
- href?: T;
566
- media?: T;
567
- ping?: T;
568
- referrerpolicy?: T;
569
- rel?: T;
570
- shape?: T;
571
- target?: T;
598
+ alt?: T | undefined;
599
+ coords?: T | undefined;
600
+ download?: T | undefined;
601
+ href?: T | undefined;
602
+ media?: T | undefined;
603
+ ping?: T | undefined;
604
+ referrerpolicy?: T | undefined;
605
+ rel?: T | undefined;
606
+ shape?: T | undefined;
607
+ target?: T | undefined;
572
608
  }
573
609
  interface audioAttr<T = DVal> extends EAttr {
574
- autoplay?: T;
575
- controls?: T;
576
- crossorigin?: T;
577
- loop?: T;
578
- muted?: T;
579
- preload?: T;
580
- src?: T;
610
+ autoplay?: T | undefined;
611
+ controls?: T | undefined;
612
+ crossorigin?: T | undefined;
613
+ loop?: T | undefined;
614
+ muted?: T | undefined;
615
+ preload?: T | undefined;
616
+ src?: T | undefined;
581
617
  }
582
618
  interface baseAttr<T = DVal> extends EAttr {
583
- href?: T;
584
- target?: T;
619
+ href?: T | undefined;
620
+ target?: T | undefined;
585
621
  }
586
622
  interface blockquoteAttr<T = DVal> extends EAttr {
587
- cite?: T;
623
+ cite?: T | undefined;
588
624
  }
589
625
  interface buttonAttr<T = DVal> extends EAttr {
590
- disabled?: T;
591
- form?: T;
592
- formaction?: T;
593
- formenctype?: T;
594
- formmethod?: T;
595
- formnovalidate?: T;
596
- formtarget?: T;
597
- name?: T;
598
- type?: T;
599
- value?: T;
626
+ disabled?: T | undefined;
627
+ form?: T | undefined;
628
+ formaction?: T | undefined;
629
+ formenctype?: T | undefined;
630
+ formmethod?: T | undefined;
631
+ formnovalidate?: T | undefined;
632
+ formtarget?: T | undefined;
633
+ name?: T | undefined;
634
+ type?: T | undefined;
635
+ value?: T | undefined;
600
636
  }
601
637
  interface canvasAttr<T = DVal> extends EAttr {
602
- height?: T;
603
- width?: T;
638
+ height?: T | undefined;
639
+ width?: T | undefined;
604
640
  }
605
641
  interface colAttr<T = DVal> extends EAttr {
606
- span?: T;
642
+ span?: T | undefined;
607
643
  }
608
644
  interface colgroupAttr<T = DVal> extends EAttr {
609
- span?: T;
645
+ span?: T | undefined;
610
646
  }
611
647
  interface dataAttr<T = DVal> extends EAttr {
612
- value?: T;
648
+ value?: T | undefined;
613
649
  }
614
650
  interface delAttr<T = DVal> extends EAttr {
615
- cite?: T;
616
- datetime?: T;
651
+ cite?: T | undefined;
652
+ datetime?: T | undefined;
617
653
  }
618
654
  interface detailsAttr<T = DVal> extends EAttr {
619
- open?: T;
655
+ open?: T | undefined;
620
656
  }
621
657
  interface dialogAttr<T = DVal> extends EAttr {
622
- open?: T;
658
+ open?: T | undefined;
623
659
  }
624
660
  interface embedAttr<T = DVal> extends EAttr {
625
- height?: T;
626
- src?: T;
627
- type?: T;
628
- width?: T;
661
+ height?: T | undefined;
662
+ src?: T | undefined;
663
+ type?: T | undefined;
664
+ width?: T | undefined;
629
665
  }
630
666
  interface fieldsetAttr<T = DVal> extends EAttr {
631
- disabled?: T;
632
- form?: T;
633
- name?: T;
667
+ disabled?: T | undefined;
668
+ form?: T | undefined;
669
+ name?: T | undefined;
634
670
  }
635
671
  interface formAttr<T = DVal> extends EAttr {
636
- accept?: T;
637
- "accept-charset"?: T;
638
- action?: T;
639
- autocomplete?: T;
640
- enctype?: T;
641
- method?: T;
642
- name?: T;
643
- novalidate?: T;
644
- target?: T;
672
+ accept?: T | undefined;
673
+ "accept-charset"?: T | undefined;
674
+ action?: T | undefined;
675
+ autocomplete?: T | undefined;
676
+ enctype?: T | undefined;
677
+ method?: T | undefined;
678
+ name?: T | undefined;
679
+ novalidate?: T | undefined;
680
+ target?: T | undefined;
645
681
  }
646
682
  interface iframeAttr<T = DVal> extends EAttr {
647
- allow?: T;
648
- csp?: T;
649
- loading?: T;
650
- name?: T;
651
- height?: T;
652
- referrerpolicy?: T;
653
- sandbox?: T;
654
- src?: T;
655
- srcdoc?: T;
656
- width?: T;
683
+ allow?: T | undefined;
684
+ csp?: T | undefined;
685
+ loading?: T | undefined;
686
+ name?: T | undefined;
687
+ height?: T | undefined;
688
+ referrerpolicy?: T | undefined;
689
+ sandbox?: T | undefined;
690
+ src?: T | undefined;
691
+ srcdoc?: T | undefined;
692
+ width?: T | undefined;
657
693
  }
658
694
  interface imgAttr<T = DVal> extends EAttr {
659
- alt?: T;
660
- crossorigin?: T;
661
- decoding?: T;
662
- ismap?: T;
663
- loading?: T;
664
- height?: T;
665
- referrerpolicy?: T;
666
- sizes?: T;
667
- src?: T;
668
- srcset?: T;
669
- usemap?: T;
670
- width?: T;
695
+ alt?: T | undefined;
696
+ crossorigin?: T | undefined;
697
+ decoding?: T | undefined;
698
+ ismap?: T | undefined;
699
+ loading?: T | undefined;
700
+ height?: T | undefined;
701
+ referrerpolicy?: T | undefined;
702
+ sizes?: T | undefined;
703
+ src?: T | undefined;
704
+ srcset?: T | undefined;
705
+ usemap?: T | undefined;
706
+ width?: T | undefined;
671
707
  }
672
708
  interface inputAttr<T = DVal> extends EAttr {
673
- accept?: T;
674
- alt?: T;
675
- autocomplete?: T;
676
- capture?: T;
677
- checked?: T;
678
- dirname?: T;
679
- disabled?: T;
680
- form?: T;
681
- formaction?: T;
682
- formenctype?: T;
683
- formmethod?: T;
684
- formnovalidate?: T;
685
- formtarget?: T;
686
- list?: T;
687
- max?: T;
688
- maxlength?: T;
689
- minlength?: T;
690
- min?: T;
691
- multiple?: T;
692
- name?: T;
693
- pattern?: T;
694
- placeholder?: T;
695
- height?: T;
696
- readonly?: T;
697
- required?: T;
698
- size?: T;
699
- src?: T;
700
- step?: T;
701
- type?: T;
702
- usemap?: T;
703
- value?: T;
704
- width?: T;
709
+ accept?: T | undefined;
710
+ alt?: T | undefined;
711
+ autocomplete?: T | undefined;
712
+ capture?: T | undefined;
713
+ checked?: T | undefined;
714
+ dirname?: T | undefined;
715
+ disabled?: T | undefined;
716
+ form?: T | undefined;
717
+ formaction?: T | undefined;
718
+ formenctype?: T | undefined;
719
+ formmethod?: T | undefined;
720
+ formnovalidate?: T | undefined;
721
+ formtarget?: T | undefined;
722
+ list?: T | undefined;
723
+ max?: T | undefined;
724
+ maxlength?: T | undefined;
725
+ minlength?: T | undefined;
726
+ min?: T | undefined;
727
+ multiple?: T | undefined;
728
+ name?: T | undefined;
729
+ pattern?: T | undefined;
730
+ placeholder?: T | undefined;
731
+ height?: T | undefined;
732
+ readonly?: T | undefined;
733
+ required?: T | undefined;
734
+ size?: T | undefined;
735
+ src?: T | undefined;
736
+ step?: T | undefined;
737
+ type?: T | undefined;
738
+ usemap?: T | undefined;
739
+ value?: T | undefined;
740
+ width?: T | undefined;
705
741
  }
706
742
  interface insAttr<T = DVal> extends EAttr {
707
- cite?: T;
708
- datetime?: T;
743
+ cite?: T | undefined;
744
+ datetime?: T | undefined;
709
745
  }
710
746
  interface labelAttr<T = DVal> extends EAttr {
711
- for?: T;
712
- form?: T;
747
+ for?: T | undefined;
748
+ form?: T | undefined;
713
749
  }
714
750
  interface liAttr<T = DVal> extends EAttr {
715
- value?: T;
751
+ value?: T | undefined;
716
752
  }
717
753
  interface linkAttr<T = DVal> extends EAttr {
718
- as?: T;
719
- crossorigin?: T;
720
- href?: T;
721
- hreflang?: T;
722
- integrity?: T;
723
- media?: T;
724
- referrerpolicy?: T;
725
- rel?: T;
726
- sizes?: T;
727
- type?: T;
754
+ as?: T | undefined;
755
+ crossorigin?: T | undefined;
756
+ href?: T | undefined;
757
+ hreflang?: T | undefined;
758
+ integrity?: T | undefined;
759
+ media?: T | undefined;
760
+ referrerpolicy?: T | undefined;
761
+ rel?: T | undefined;
762
+ sizes?: T | undefined;
763
+ type?: T | undefined;
728
764
  }
729
765
  interface mapAttr<T = DVal> extends EAttr {
730
- name?: T;
766
+ name?: T | undefined;
731
767
  }
732
768
  interface menuAttr<T = DVal> extends EAttr {
733
- type?: T;
769
+ type?: T | undefined;
734
770
  }
735
771
  interface metaAttr<T = DVal> extends EAttr {
736
- charset?: T;
737
- content?: T;
738
- "http-equiv"?: T;
739
- name?: T;
772
+ charset?: T | undefined;
773
+ content?: T | undefined;
774
+ "http-equiv"?: T | undefined;
775
+ name?: T | undefined;
740
776
  }
741
777
  interface meterAttr<T = DVal> extends EAttr {
742
- form?: T;
743
- high?: T;
744
- low?: T;
745
- max?: T;
746
- min?: T;
747
- optimum?: T;
748
- value?: T;
778
+ form?: T | undefined;
779
+ high?: T | undefined;
780
+ low?: T | undefined;
781
+ max?: T | undefined;
782
+ min?: T | undefined;
783
+ optimum?: T | undefined;
784
+ value?: T | undefined;
749
785
  }
750
786
  interface objectAttr<T = DVal> extends EAttr {
751
- data?: T;
752
- form?: T;
753
- name?: T;
754
- height?: T;
755
- type?: T;
756
- usemap?: T;
757
- width?: T;
787
+ data?: T | undefined;
788
+ form?: T | undefined;
789
+ name?: T | undefined;
790
+ height?: T | undefined;
791
+ type?: T | undefined;
792
+ usemap?: T | undefined;
793
+ width?: T | undefined;
758
794
  }
759
795
  interface olAttr<T = DVal> extends EAttr {
760
- reversed?: T;
761
- start?: T;
762
- type?: T;
796
+ reversed?: T | undefined;
797
+ start?: T | undefined;
798
+ type?: T | undefined;
763
799
  }
764
800
  interface optgroupAttr<T = DVal> extends EAttr {
765
- disabled?: T;
766
- label?: T;
801
+ disabled?: T | undefined;
802
+ label?: T | undefined;
767
803
  }
768
804
  interface optionAttr<T = DVal> extends EAttr {
769
- disabled?: T;
770
- label?: T;
771
- selected?: T;
772
- value?: T;
805
+ disabled?: T | undefined;
806
+ label?: T | undefined;
807
+ selected?: T | undefined;
808
+ value?: T | undefined;
773
809
  }
774
810
  interface outputAttr<T = DVal> extends EAttr {
775
- for?: T;
776
- form?: T;
777
- name?: T;
811
+ for?: T | undefined;
812
+ form?: T | undefined;
813
+ name?: T | undefined;
778
814
  }
779
815
  interface paramAttr<T = DVal> extends EAttr {
780
- name?: T;
781
- value?: T;
816
+ name?: T | undefined;
817
+ value?: T | undefined;
782
818
  }
783
819
  interface progressAttr<T = DVal> extends EAttr {
784
- form?: T;
785
- max?: T;
786
- value?: T;
820
+ form?: T | undefined;
821
+ max?: T | undefined;
822
+ value?: T | undefined;
787
823
  }
788
824
  interface qAttr<T = DVal> extends EAttr {
789
- cite?: T;
825
+ cite?: T | undefined;
790
826
  }
791
827
  interface scriptAttr<T = DVal> extends EAttr {
792
- async?: T;
793
- crossorigin?: T;
794
- defer?: T;
795
- integrity?: T;
796
- referrerpolicy?: T;
797
- src?: T;
798
- type?: T;
828
+ async?: T | undefined;
829
+ crossorigin?: T | undefined;
830
+ defer?: T | undefined;
831
+ integrity?: T | undefined;
832
+ referrerpolicy?: T | undefined;
833
+ src?: T | undefined;
834
+ type?: T | undefined;
799
835
  }
800
836
  interface selectAttr<T = DVal> extends EAttr {
801
- autocomplete?: T;
802
- disabled?: T;
803
- form?: T;
804
- multiple?: T;
805
- name?: T;
806
- required?: T;
807
- size?: T;
837
+ autocomplete?: T | undefined;
838
+ disabled?: T | undefined;
839
+ form?: T | undefined;
840
+ multiple?: T | undefined;
841
+ name?: T | undefined;
842
+ required?: T | undefined;
843
+ size?: T | undefined;
808
844
  }
809
845
  interface sourceAttr<T = DVal> extends EAttr {
810
- media?: T;
811
- sizes?: T;
812
- src?: T;
813
- srcset?: T;
814
- type?: T;
846
+ media?: T | undefined;
847
+ sizes?: T | undefined;
848
+ src?: T | undefined;
849
+ srcset?: T | undefined;
850
+ type?: T | undefined;
815
851
  }
816
852
  interface styleAttr<T = DVal> extends EAttr {
817
- media?: T;
818
- type?: T;
853
+ media?: T | undefined;
854
+ type?: T | undefined;
819
855
  }
820
856
  interface tdAttr<T = DVal> extends EAttr {
821
- colspan?: T;
822
- headers?: T;
823
- rowspan?: T;
857
+ colspan?: T | undefined;
858
+ headers?: T | undefined;
859
+ rowspan?: T | undefined;
824
860
  }
825
861
  interface textareaAttr<T = DVal> extends EAttr {
826
- autocomplete?: T;
827
- cols?: T;
828
- dirname?: T;
829
- disabled?: T;
830
- enterkeyhint?: T;
831
- form?: T;
832
- inputmode?: T;
833
- maxlength?: T;
834
- minlength?: T;
835
- name?: T;
836
- placeholder?: T;
837
- readonly?: T;
838
- required?: T;
839
- rows?: T;
840
- wrap?: T;
862
+ autocomplete?: T | undefined;
863
+ cols?: T | undefined;
864
+ dirname?: T | undefined;
865
+ disabled?: T | undefined;
866
+ enterkeyhint?: T | undefined;
867
+ form?: T | undefined;
868
+ inputmode?: T | undefined;
869
+ maxlength?: T | undefined;
870
+ minlength?: T | undefined;
871
+ name?: T | undefined;
872
+ placeholder?: T | undefined;
873
+ readonly?: T | undefined;
874
+ required?: T | undefined;
875
+ rows?: T | undefined;
876
+ wrap?: T | undefined;
841
877
  }
842
878
  interface thAttr<T = DVal> extends EAttr<T> {
843
- colspan?: T;
844
- headers?: T;
845
- rowspan?: T;
846
- scope?: T;
879
+ colspan?: T | undefined;
880
+ headers?: T | undefined;
881
+ rowspan?: T | undefined;
882
+ scope?: T | undefined;
847
883
  }
848
884
  interface timeAttr<T = DVal> extends EAttr {
849
- datetime?: T;
885
+ datetime?: T | undefined;
850
886
  }
851
887
  interface trackAttr<T = DVal> extends EAttr {
852
- default?: T;
853
- kind?: T;
854
- label?: T;
855
- src?: T;
856
- srclang?: T;
888
+ default?: T | undefined;
889
+ kind?: T | undefined;
890
+ label?: T | undefined;
891
+ src?: T | undefined;
892
+ srclang?: T | undefined;
857
893
  }
858
894
  interface videoAttr<T = DVal> extends EAttr {
859
- autoplay?: T;
860
- controls?: T;
861
- crossorigin?: T;
862
- loop?: T;
863
- muted?: T;
864
- playsinline?: T;
865
- height?: T;
866
- poster?: T;
867
- preload?: T;
868
- src?: T;
869
- width?: T;
895
+ autoplay?: T | undefined;
896
+ controls?: T | undefined;
897
+ crossorigin?: T | undefined;
898
+ loop?: T | undefined;
899
+ muted?: T | undefined;
900
+ playsinline?: T | undefined;
901
+ height?: T | undefined;
902
+ poster?: T | undefined;
903
+ preload?: T | undefined;
904
+ src?: T | undefined;
905
+ width?: T | undefined;
870
906
  }
871
907
  interface contenteditableAttr<T = DVal> extends EAttr {
872
- enterkeyhint?: T;
873
- inputmode?: T;
908
+ enterkeyhint?: T | undefined;
909
+ inputmode?: T | undefined;
874
910
  }
875
911
 
876
912
  interface ElementAttributes {
@@ -984,7 +1020,7 @@ interface ElementAttributes {
984
1020
 
985
1021
  interface SVGAttributes {
986
1022
  svg: svgAttr & {
987
- viewBox?: DVal;
1023
+ viewBox?: DVal | undefined;
988
1024
  };
989
1025
  path: svgEAttr;
990
1026
  circle: svgEAttr;
@@ -1046,57 +1082,66 @@ interface SVGAttributes {
1046
1082
  view: svgEAttr;
1047
1083
  }
1048
1084
  interface svgAttr<T = DVal> extends EAttr<T> {
1049
- height?: T;
1050
- width?: T;
1051
- preserveAspectRatio?: T;
1052
- fill?: T;
1053
- stroke?: T;
1054
- strokeWidth?: T;
1055
- opacity?: T;
1056
- display?: T;
1057
- overflow?: T;
1085
+ height?: T | undefined;
1086
+ width?: T | undefined;
1087
+ preserveAspectRatio?: T | undefined;
1088
+ fill?: T | undefined;
1089
+ stroke?: T | undefined;
1090
+ strokeWidth?: T | undefined;
1091
+ opacity?: T | undefined;
1092
+ display?: T | undefined;
1093
+ overflow?: T | undefined;
1058
1094
  }
1059
1095
  interface svgEAttr<T = DVal> extends svgAttr<T> {
1060
- transform?: T;
1061
- role?: T;
1062
- tabindex?: T;
1063
- visibility?: T;
1064
- fillOpacity?: T;
1065
- fillRule?: T;
1066
- stroke?: T;
1067
- strokeWidth?: T;
1068
- strokeOpacity?: T;
1069
- strokeLinecap?: T;
1070
- strokeLinejoin?: T;
1071
- strokeMiterlimit?: T;
1072
- strokeDasharray?: T;
1073
- strokeDashoffset?: T;
1074
- x?: T;
1075
- y?: T;
1076
- x1?: T;
1077
- y1?: T;
1078
- x2?: T;
1079
- y2?: T;
1080
- cx?: T;
1081
- cy?: T;
1082
- r?: T;
1083
- rx?: T;
1084
- ry?: T;
1085
- d?: T;
1086
- points?: T;
1096
+ transform?: T | undefined;
1097
+ role?: T | undefined;
1098
+ tabindex?: T | undefined;
1099
+ visibility?: T | undefined;
1100
+ fillOpacity?: T | undefined;
1101
+ fillRule?: T | undefined;
1102
+ stroke?: T | undefined;
1103
+ strokeWidth?: T | undefined;
1104
+ strokeOpacity?: T | undefined;
1105
+ strokeLinecap?: T | undefined;
1106
+ strokeLinejoin?: T | undefined;
1107
+ strokeMiterlimit?: T | undefined;
1108
+ strokeDasharray?: T | undefined;
1109
+ strokeDashoffset?: T | undefined;
1110
+ x?: T | undefined;
1111
+ y?: T | undefined;
1112
+ x1?: T | undefined;
1113
+ y1?: T | undefined;
1114
+ x2?: T | undefined;
1115
+ y2?: T | undefined;
1116
+ cx?: T | undefined;
1117
+ cy?: T | undefined;
1118
+ r?: T | undefined;
1119
+ rx?: T | undefined;
1120
+ ry?: T | undefined;
1121
+ d?: T | undefined;
1122
+ points?: T | undefined;
1087
1123
  }
1088
1124
  interface svgETextAttr<T = DVal> extends svgEAttr<T> {
1089
- fontSize?: T;
1090
- fontFamily?: T;
1091
- fontWeight?: T;
1092
- textAnchor?: T;
1093
- dominantBaseline?: T;
1125
+ fontSize?: T | undefined;
1126
+ fontFamily?: T | undefined;
1127
+ fontWeight?: T | undefined;
1128
+ textAnchor?: T | undefined;
1129
+ dominantBaseline?: T | undefined;
1094
1130
  }
1095
1131
 
1096
1132
  declare global {
1097
1133
  type events<T extends Elements = HTMLElement> = {
1098
- [P in keyof GlobalEventHandlersEventMap]?: (this: T, e: GlobalEventHandlersEventMap[P]) => void;
1134
+ [P in keyof GlobalEventHandlersEventMap]?: ((this: T, e: GlobalEventHandlersEventMap[P]) => void) | undefined;
1099
1135
  } & c_events<T>;
1136
+ /**
1137
+ * Yvee JSX namespace.
1138
+ *
1139
+ * Function components receive their attributes as the first argument and JSX
1140
+ * children as **rest arguments**: declare them as
1141
+ * `(props: P, ...children: DOMContext[])` and render `{children}`.
1142
+ * Children are never placed on `props`, and `props.children` is always
1143
+ * `undefined`.
1144
+ */
1100
1145
  namespace JSX {
1101
1146
  type Element = maybePromise<DOM>;
1102
1147
  interface IntrinsicElements extends ElementAttributes, SVGAttributes {
@@ -1213,7 +1258,63 @@ declare function applyHead(config: HeadConfig, owner: string, options?: {
1213
1258
  nonce?: string;
1214
1259
  }): HeadCleanup;
1215
1260
 
1261
+ /**
1262
+ * State retained for a region between renders. `get` returns the value stored
1263
+ * by the previous render of the same region (or `undefined`), and `set` keeps
1264
+ * `value` for its next render. The runtime owns storage: values are plain data
1265
+ * that dies with the page, and they are only retained on pages that set
1266
+ * `Page.keepAlive`.
1267
+ */
1268
+ interface RegionCache {
1269
+ /** Value retained by the previous render of this region, or `undefined`. */
1270
+ get(): unknown;
1271
+ /** Store `value` for this region's next render. */
1272
+ set(value: unknown): void;
1273
+ }
1274
+ /** A lazily imported in-page region view, using the same `default` contract as `body()`. */
1275
+ interface RegionModule {
1276
+ /**
1277
+ * Render the region view. `cache` is always provided: it is a working
1278
+ * read/write store on `keepAlive` pages and a no-op store everywhere else,
1279
+ * so modules stay portable.
1280
+ */
1281
+ default: (context: {
1282
+ page: Page;
1283
+ cache: RegionCache;
1284
+ }) => unknown | Promise<unknown>;
1285
+ /**
1286
+ * Head contributed while this region is displayed. Accepts the same values
1287
+ * as a body module `head`; the runtime recombines it with the page head on
1288
+ * region changes without a route transition.
1289
+ */
1290
+ head?: HeadResult | ((context: {
1291
+ page: Page;
1292
+ }) => HeadResult | Promise<HeadResult>);
1293
+ }
1294
+ /** Context passed to `Page.regionWillLeave` before a region changes. */
1295
+ interface RegionLeaveContext<TData extends Record<string, unknown> = Record<string, unknown>> {
1296
+ /** Region currently displayed. */
1297
+ from: string;
1298
+ /** Region the navigation wants to display. */
1299
+ to: string;
1300
+ /** Target URL; the navigation is not committed when the hook runs. */
1301
+ url: YveeURL;
1302
+ /** Route parameters of the current page. */
1303
+ params: Record<string, string>;
1304
+ /** Mutable page data, including any data merged by earlier region refreshes. */
1305
+ data: TData;
1306
+ /** Page-lifetime abort signal; aborts when the page is left. */
1307
+ signal: AbortSignal;
1308
+ }
1309
+ /** Context passed to `Page.regionDidEnter` after a region view has settled. */
1310
+ interface RegionEnterContext {
1311
+ /** Region that is now displayed. */
1312
+ region: string;
1313
+ }
1314
+ /** Imports one region view module; the runtime caches the promise per page and region. */
1315
+ type RegionLoader = () => Promise<RegionModule>;
1216
1316
  declare class Page<TData extends Record<string, unknown> = Record<string, unknown>> {
1317
+ #private;
1217
1318
  readonly resources: DisposalScope;
1218
1319
  url: YveeURL;
1219
1320
  path: string;
@@ -1224,6 +1325,110 @@ declare class Page<TData extends Record<string, unknown> = Record<string, unknow
1224
1325
  fetch?(context: PageFetchContext<TData>): Partial<TData> | Promise<Partial<TData>>;
1225
1326
  head?(): HeadResult | Promise<HeadResult>;
1226
1327
  body?(): unknown | Promise<unknown>;
1328
+ /**
1329
+ * Query parameter that selects the active region, for example `"tab"`.
1330
+ * Set it together with `regions`; without either value regions stay inactive.
1331
+ */
1332
+ regionParam?: string;
1333
+ /** Region shown when the URL omits the region parameter or names an unknown region. */
1334
+ defaultRegion?: string;
1335
+ /**
1336
+ * Remember the region the user last opened on this page's path and reopen it
1337
+ * when a later in-app navigation omits the region parameter. Explicit region
1338
+ * parameters always win, and fresh document loads keep rendering the URL's
1339
+ * region. Requires `regions` and `regionParam`.
1340
+ */
1341
+ rememberRegion?: boolean;
1342
+ /**
1343
+ * Lazily imported region views keyed by region id. Switching regions updates
1344
+ * the URL query parameter without a page transition, so the page shell stays
1345
+ * mounted while only `regionContent` changes.
1346
+ */
1347
+ regions?: Record<string, RegionLoader>;
1348
+ /**
1349
+ * Retain plain state per region between renders on this page (off by
1350
+ * default). `true` keeps the five most recently rendered regions, and a
1351
+ * number sets that bound. Retained values are handed back through the
1352
+ * `cache` context member on the next render of the same region, which lets
1353
+ * form data, selections or fetched lists survive tab round-trips; the DOM is
1354
+ * rebuilt every time, so effects and subscriptions still belong to
1355
+ * `regionResources`. Requires `regions` and `regionParam`.
1356
+ */
1357
+ keepAlive?: number | true;
1358
+ /**
1359
+ * Guards that run when a region becomes active, keyed by region id. They run
1360
+ * before the region is imported and rendered, before `regionWillLeave`, and
1361
+ * before any history write, scroll capture or view change.
1362
+ *
1363
+ * On the initial load the resolved region's guards run after region
1364
+ * resolution (an unknown id resolves to `defaultRegion` first, and
1365
+ * `strictRegions` still 404s before them): `redirect` returns to the normal
1366
+ * server/client redirect loop, while `stop` leaves the request without a
1367
+ * page. Because a first-load `stop` has no client render path, login-style
1368
+ * gates should return `redirect` with `returnTo` instead.
1369
+ *
1370
+ * During an in-page swap a `stop` changes nothing at all, and a `redirect`
1371
+ * re-enters navigation at the redirect target. A history move that is denied
1372
+ * restores the previous URL. Guards are not run when the target region is
1373
+ * already displayed.
1374
+ */
1375
+ regionGuards?: Record<string, RegionGuard<any, any, any>[]>;
1376
+ /**
1377
+ * Re-run `fetch` in the incoming region's scope on every in-page region
1378
+ * change, so a region can load its own data without a full page load. The
1379
+ * result merges into `page.data` before the region view renders. Ignored
1380
+ * without `regions` or `fetch`, and the initial document load keeps using the
1381
+ * normal `fetch` pass.
1382
+ */
1383
+ refreshOnRegionChange?: boolean;
1384
+ /**
1385
+ * Reject region ids the page does not declare. On the initial load an unknown
1386
+ * id renders the 404 error page; an in-app navigation or history move to an
1387
+ * unknown id is denied and the previous URL is restored instead of falling
1388
+ * back to `defaultRegion`. Off by default, which keeps the canonicalizing
1389
+ * default-region fallback.
1390
+ */
1391
+ strictRegions?: boolean;
1392
+ /**
1393
+ * Runs before an in-page region change writes history or swaps the view.
1394
+ * Throwing (or rejecting) cancels the navigation: the URL, history entry and
1395
+ * displayed region stay untouched and the error is reported through
1396
+ * `onError`. Not called when the target region is already displayed.
1397
+ */
1398
+ regionWillLeave?(context: RegionLeaveContext<TData>): void | Promise<void>;
1399
+ /**
1400
+ * Runs after an in-page region swap or region history move has settled.
1401
+ * Errors are reported through `onError` after the swap has committed. The
1402
+ * initial document load does not call this hook.
1403
+ */
1404
+ regionDidEnter?(context: RegionEnterContext): void | Promise<void>;
1405
+ /**
1406
+ * Id of the displayed region. The runtime owns this value: it writes the id
1407
+ * after resolving the URL, so views should only read it (for example to mark
1408
+ * the active tab). Do not assign to it from a view.
1409
+ */
1410
+ readonly region: IStateful<string>;
1411
+ /**
1412
+ * Outlet content for the active region. Render this state inside the page
1413
+ * view; the runtime replaces its value during region switches. Treat it as
1414
+ * read-only from application code.
1415
+ */
1416
+ readonly regionContent: IStateful<unknown>;
1417
+ /**
1418
+ * Resources owned by the active region. Each activation starts a fresh scope
1419
+ * and the previous scope is disposed before the next region renders. Page
1420
+ * `resources` are independent and only close when the page is left.
1421
+ */
1422
+ regionResources: DisposalScope;
1423
+ /**
1424
+ * Read the server-seeded data for this document at most once.
1425
+ *
1426
+ * During SSR (no `document`) it returns `this.data` on every call, so server
1427
+ * renders are deterministic. In the browser it returns the hydrated payload
1428
+ * for the first call of the initial mount and `undefined` for later calls,
1429
+ * re-renders and client-side navigations. `page.data` is never modified.
1430
+ */
1431
+ ssrData<T extends Record<string, unknown> = TData>(): T | undefined;
1227
1432
  }
1228
1433
  interface PageFetchContext<TData extends Record<string, unknown>> {
1229
1434
  url: YveeURL;
@@ -1277,15 +1482,25 @@ interface GuardApp<TData extends Record<string, unknown>> {
1277
1482
  data: TData;
1278
1483
  url: IStateful<YveeURL>;
1279
1484
  }
1280
- type GuardResult = void | {
1281
- kind: "allow";
1282
- } | {
1283
- kind: "stop";
1284
- } | {
1485
+ /** A guard redirect decision. */
1486
+ type GuardRedirect = {
1285
1487
  kind: "redirect";
1488
+ /** Destination path, optionally carrying its own query and hash. */
1286
1489
  to: string;
1490
+ /** Keep the current history entry instead of pushing a new one. */
1287
1491
  replace?: boolean;
1492
+ /**
1493
+ * Preserves the URL that was rejected as a `returnTo` query parameter on
1494
+ * `to`. `true` appends the current request URL (`path + search + hash`);
1495
+ * a string appends that explicit value instead. Omit it for a bare redirect.
1496
+ */
1497
+ returnTo?: boolean | string;
1288
1498
  };
1499
+ type GuardResult = void | {
1500
+ kind: "allow";
1501
+ } | {
1502
+ kind: "stop";
1503
+ } | GuardRedirect;
1289
1504
  interface GuardContext<TApp = unknown, TPage = unknown, TData extends Record<string, unknown> = Record<string, unknown>> {
1290
1505
  app: TApp;
1291
1506
  page: TPage;
@@ -1293,11 +1508,54 @@ interface GuardContext<TApp = unknown, TPage = unknown, TData extends Record<str
1293
1508
  params: Readonly<Record<string, string>>;
1294
1509
  data: TData;
1295
1510
  signal: AbortSignal;
1511
+ /**
1512
+ * `true` while guards run without a browser `window` (server rendering or
1513
+ * Bun), `false` for client-side navigation. Always populated by the guard
1514
+ * runner, so guard code can branch without touching globals.
1515
+ */
1516
+ readonly server: boolean;
1296
1517
  }
1518
+ /**
1519
+ * Guard context accepted by the runner before the environment flag is filled
1520
+ * in. Existing call sites may omit `server`; `checkGuards` normalizes it to a
1521
+ * full `GuardContext` for every guard.
1522
+ */
1523
+ type GuardContextInput<TApp = unknown, TPage = unknown, TData extends Record<string, unknown> = Record<string, unknown>> = Omit<GuardContext<TApp, TPage, TData>, "server"> & {
1524
+ readonly server?: boolean;
1525
+ };
1297
1526
  type Guard<TApp = unknown, TPage = unknown, TData extends Record<string, unknown> = Record<string, unknown>> = (context: GuardContext<TApp, TPage, TData>) => GuardResult | Promise<GuardResult>;
1527
+ /**
1528
+ * Guard context for a region becoming active. It is a `GuardContext` with the
1529
+ * region transition itself added, so the same guards, decisions and helpers
1530
+ * work for pages and regions.
1531
+ */
1532
+ interface RegionGuardContext<TApp = unknown, TPage = unknown, TData extends Record<string, unknown> = Record<string, unknown>> extends GuardContext<TApp, TPage, TData> {
1533
+ /** Region id the navigation wants to display. */
1534
+ region: string;
1535
+ /** Region that was displayed before the change; `undefined` on the initial load. */
1536
+ from: string | undefined;
1537
+ }
1538
+ /**
1539
+ * A guard that runs when its region becomes active. Declare guards per region
1540
+ * through `Page.regionGuards`; `stop` keeps the previous region (and URL) and a
1541
+ * `redirect` re-enters navigation with the redirect target.
1542
+ */
1543
+ type RegionGuard<TApp = unknown, TPage = unknown, TData extends Record<string, unknown> = Record<string, unknown>> = (context: RegionGuardContext<TApp, TPage, TData>) => GuardResult | Promise<GuardResult>;
1298
1544
  type GuardFactory<Args extends unknown[] = [], TContext = GuardContext> = (...args: Args) => (context: TContext) => GuardResult | Promise<GuardResult>;
1299
1545
  declare const createGuard: <Args extends unknown[], TContext = GuardContext>(factory: GuardFactory<Args, TContext>) => GuardFactory<Args, TContext>;
1300
1546
  declare const use: (...guards: Guard<any, any, any>[]) => <T extends Constructor>(controller: T) => T;
1547
+ /**
1548
+ * Returns `to` with the request URL (`path + search + hash`) appended as an
1549
+ * encoded `returnTo` query parameter. Guards can set `returnTo: true` instead;
1550
+ * this helper is for building a redirect target by hand.
1551
+ */
1552
+ declare function buildReturnTo(url: YveeURL, to: string): string;
1553
+ /**
1554
+ * Reads and decodes a `returnTo` query parameter from a redirect target, a
1555
+ * `URL`, or a parsed `YveeURL`. Returns `undefined` when the parameter is
1556
+ * absent, so a login view can fall back to its default destination.
1557
+ */
1558
+ declare function readReturnTo(url: string | URL | YveeURL): string | undefined;
1301
1559
 
1302
1560
  type ContextGuard<C = GuardContext> = (context: C) => GuardResult | Promise<GuardResult>;
1303
1561
  type GuardPredicate<C = GuardContext> = (context: C) => boolean | Promise<boolean>;
@@ -1357,6 +1615,8 @@ interface SocketRouteSource {
1357
1615
  routes: RouteBook;
1358
1616
  }
1359
1617
  type MessageFailure = 'parse' | 'validation' | 'handler';
1618
+ /** Lifecycle of a socket connection: waiting to connect or retry, open, or closed/disposed. */
1619
+ type SocketConnectionState = 'connecting' | 'open' | 'closed';
1360
1620
  interface JsonMessageOptions<T> {
1361
1621
  validate?: (value: unknown) => value is T;
1362
1622
  onError?: (error: unknown, phase: MessageFailure, event: MessageEvent) => void;
@@ -1374,12 +1634,44 @@ declare class SocketController {
1374
1634
  connection?: WebSocket;
1375
1635
  path: string;
1376
1636
  params: Record<string, string>;
1637
+ /**
1638
+ * Reactive connection state, bindable from a view like `app.loading`.
1639
+ * Starts as `"connecting"`, becomes `"open"` once the native socket opens and
1640
+ * queued frames flush, and `"closed"` when the socket closes or the hub
1641
+ * disposes the controller. Retries cycle `"closed"` back to `"connecting"`.
1642
+ */
1643
+ readonly state: IStateful<SocketConnectionState>;
1644
+ private queue;
1645
+ private disposed;
1377
1646
  open(_event: Event): void;
1378
1647
  message(_event: MessageEvent): void | Promise<void>;
1379
1648
  close(_event: CloseEvent): void;
1380
1649
  error(_event: Event): void;
1381
1650
  messageError(error: unknown, phase: MessageFailure, _event: MessageEvent): void;
1651
+ /**
1652
+ * Sends a JSON frame, queueing it in FIFO order while the socket is missing
1653
+ * or not open. Queued frames flush once when the connection opens, including
1654
+ * after a retry reconnect. Frames sent to a disposed controller are dropped.
1655
+ * The queue is unbounded while waiting, so senders should avoid producing
1656
+ * frames faster than the connection can open. Never throws: serialization
1657
+ * and native send failures are logged and the frame is skipped.
1658
+ *
1659
+ * Unlike `sendJson`, this does not drop frames sent before the socket opens.
1660
+ */
1661
+ send(value: unknown): void;
1662
+ /** Fire-and-forget: silently drops the frame unless the socket is open now. */
1382
1663
  sendJson(value: unknown): void;
1664
+ /** @internal Binds the native socket and enters `"connecting"`. */
1665
+ attach(socket: WebSocket): void;
1666
+ /** @internal Enters `"open"`; the hub flushes queued frames after the `open` hook. */
1667
+ opened(): void;
1668
+ /** @internal Sends queued frames in FIFO order if the socket is open. */
1669
+ flush(): void;
1670
+ /** @internal Enters `"closed"`; queued frames survive for a retry reconnect. */
1671
+ closed(): void;
1672
+ /** @internal Disposes the controller: clears queued frames and enters `"closed"`. */
1673
+ dispose(): void;
1674
+ private transmit;
1383
1675
  onMessage<T = unknown>(handler: (value: T, event: MessageEvent) => void | Promise<void>, options?: JsonMessageOptions<T>): this;
1384
1676
  }
1385
1677
  declare class SocketHub {
@@ -1457,6 +1749,15 @@ declare class Yvee<T extends Record<string, unknown> = Record<string, unknown>>
1457
1749
  private load;
1458
1750
  }
1459
1751
 
1752
+ /**
1753
+ * `true` when the module is evaluated in a browser (a global `window` exists).
1754
+ *
1755
+ * Evaluated once at module scope with `typeof window`, so importing this module
1756
+ * during server rendering or in Bun never throws. Use it in guards, pages and
1757
+ * auth helpers instead of repeating `typeof window === "undefined"` checks.
1758
+ */
1759
+ declare const isClient: boolean;
1760
+
1460
1761
  type StoreName = "localStorage" | "sessionStorage";
1461
1762
 
1462
1763
  interface StorageSchema<T> {
@@ -1512,6 +1813,13 @@ declare class BrowserStore {
1512
1813
  versioned<T>(key: string, schema: StorageSchema<T>): VersionedValue<T>;
1513
1814
  /** Native storage events from other documents; same-document writes do not notify. */
1514
1815
  watch(key: string, callback: (change: StorageChange) => void, { signal, scope }?: StorageWatchOptions): Cleanup;
1816
+ /**
1817
+ * Validated read: parses the stored JSON and returns its value only when it
1818
+ * passes `validate`; otherwise `.value` is `undefined`. Invalid entries are
1819
+ * left in storage, so call `.remove()` to discard them. A function argument
1820
+ * is always treated as a validator.
1821
+ */
1822
+ get<T>(key: string, validate: (value: unknown) => value is T): StoredValue<T | undefined>;
1515
1823
  get<T = unknown>(key: string, fallback?: T): StoredValue<T | undefined>;
1516
1824
  /** Writes immediately; storage/serialization failures propagate to the caller. */
1517
1825
  set<T>(key: string, value: T): StoredValue<T>;
@@ -1522,22 +1830,83 @@ declare class BrowserStore {
1522
1830
  declare const local: BrowserStore;
1523
1831
  declare const session: BrowserStore;
1524
1832
 
1833
+ /**
1834
+ * Non-success HTTP response. `body` holds the parsed JSON error body when one
1835
+ * was readable. The message is the explicit `message` argument, then a string
1836
+ * `error` or `message` field on `body`, then `HTTP <status> <statusText>`.
1837
+ */
1525
1838
  declare class HTTPError extends Error {
1526
1839
  readonly response: Response;
1527
- constructor(response: Response);
1840
+ /** Parsed JSON body of the response, or `undefined` when it was not JSON. */
1841
+ readonly body?: unknown;
1842
+ constructor(response: Response, message?: string, body?: unknown);
1843
+ /**
1844
+ * Builds an `HTTPError` after cloning the response and parsing its JSON body.
1845
+ * The clone is taken first, so `response` stays readable for other callers.
1846
+ * Parse failures leave `body` undefined.
1847
+ */
1848
+ static fromResponse(response: Response, message?: string): Promise<HTTPError>;
1528
1849
  }
1529
1850
  interface RequestRetry {
1530
1851
  /** Additional attempts, from 0 to 5. Only GET, HEAD and OPTIONS may retry. */
1531
1852
  attempts: number;
1532
1853
  delayMs?: number;
1533
1854
  }
1855
+ interface CsrfOptions {
1856
+ /** Header carrying the token. Defaults to `x-csrf-token`. */
1857
+ header?: string;
1858
+ /** JSON body field carrying the token. Defaults to `csrfToken`. */
1859
+ field?: string;
1860
+ /** Token minting endpoint. Defaults to `/csrf`; `false` disables minting. */
1861
+ endpoint?: string | false;
1862
+ }
1534
1863
  interface JSONRequestOptions<T> extends RequestInit {
1535
1864
  validate: (value: unknown) => value is T;
1536
1865
  retry?: RequestRetry;
1537
1866
  fetch?: typeof globalThis.fetch;
1867
+ /**
1868
+ * Attaches a CSRF token to the request header and, for a JSON body, a body
1869
+ * field. `true` uses the `x-csrf-token` header, the `csrfToken` field, the
1870
+ * `csrf_token` cookie, a `meta[name="csrf-token"]` tag, then a cached or
1871
+ * freshly minted token from `GET /csrf`. Existing body fields are never
1872
+ * overwritten.
1873
+ */
1874
+ csrf?: boolean | CsrfOptions;
1538
1875
  }
1539
1876
  /** HTTP/status failures are distinct from JSON parsing and caller validation failures. */
1540
1877
  declare function requestJSON<T>(input: RequestInfo | URL, options: JSONRequestOptions<T>): Promise<T>;
1878
+ interface FormRequestOptions<T> extends Omit<RequestInit, "body"> {
1879
+ /** JSON payload, serialized as the request body. Ignored when `body` is set. */
1880
+ data?: unknown;
1881
+ /** Raw body such as `FormData`; takes precedence over `data`. */
1882
+ body?: BodyInit | null;
1883
+ /** Optional validator for the parsed JSON success payload. */
1884
+ validate?: (value: unknown) => value is T;
1885
+ /** CSRF options forwarded to `requestJSON`. */
1886
+ csrf?: boolean | CsrfOptions;
1887
+ fetch?: typeof globalThis.fetch;
1888
+ }
1889
+ interface FormResult<T> {
1890
+ ok: boolean;
1891
+ /** HTTP status, or `0` when no response was received. */
1892
+ status: number;
1893
+ data?: T | undefined;
1894
+ /** Server error text when available, otherwise the failure message. */
1895
+ error?: string | undefined;
1896
+ }
1897
+ /**
1898
+ * Submits a JSON or `FormData` body without throwing.
1899
+ * HTTP and network failures resolve to `{ ok: false, status, error }`; a
1900
+ * missing response reports status `0`. A 204/205 success has no `data`.
1901
+ */
1902
+ declare function requestForm<T = unknown>(url: string | URL, options?: FormRequestOptions<T>): Promise<FormResult<T>>;
1903
+
1904
+ /**
1905
+ * Reads a cookie from `document.cookie` in the browser.
1906
+ * Returns `undefined` without a `document` or when the cookie is absent.
1907
+ * Values are decoded once; a malformed percent-encoding returns the raw value.
1908
+ */
1909
+ declare function readCookie(name: string): string | undefined;
1541
1910
 
1542
1911
  interface StreamHandlers {
1543
1912
  open?: (event: Event) => void;
@@ -1558,5 +1927,5 @@ declare function renderJSONScript(value: unknown, options: {
1558
1927
  nonce?: string;
1559
1928
  }): string;
1560
1929
 
1561
- export { $, ATTR, BrowserStore, Column, DOM, DbRepository, Derived, DisposalScope, Elem, EventStream, FailurePage, Field, HTTPError, HeadDefaults, IDNotConnected, IndexedDatabase, MissingPage, Page, QState, RecState, RecStateful, Ref, RefState, RouteBook, Schema, Scope, SetState, SetStateful, SocketController, SocketHub, State, StateEffect, StateHook, StateLoaded, Stateful, Stored, StoredValue, Toggled, VersionedValue, Yvee, allGuards, applyHead, attr_value, batch, createGuard, dom, error, eventStream, eventStreams, frag, getElementById, hook, interpolate, loaded, local, normalizePath, page, paramsGuard, renderContent, renderDom, renderJSONScript, requestJSON, requireGuard, route, serializePayload, session, setContentRenderer, shallowEqual, socketRoute, t, toURL, use, useRef, whenGuard };
1562
- export type { $_, CSSStyle, Cleanup, ColumnType, Constructor, ContentRenderer, ContextGuard, DOMAttr, DOMComponent, DOMComponentProps, DOMContext, DOMEvents, DOMNode, DOMRenderable, DOMValue, DVal, DerivedOptions, DerivedValue, Disposable, EAttr, ElementAttributes, Elements, Equality, EventMap, FieldScopeSet, Guard, GuardApp, GuardContext, GuardFactory, GuardFallback, GuardPredicate, GuardRejection, GuardResult, HeadConfig, HeadResult, IRecStateful, ISetStateful, IStateful, JSONRequestOptions, JsonMessageOptions, Layout, MessageFailure, MountOptions, OpenOptions, PageFetchContext, RenderResult, RenderedContent, RenderedDOM, RequestRetry, RouteEntry, SVGAttributes, ScopeDecorator, ScopeProxy, ScopeSet, ServerDataContext, ServerOptions, ServerRenderer, ServerRequest, ServerStatusResult, SocketLoadOptions, StateHookOptions, StateOptions, StateUpdate, StorageChange, StorageSchema, StorageWatchOptions, StreamHandlers, StreamOptions, TagNames, Transport, YveeOptions, YveeURL, _$, aAttr, areaAttr, audioAttr, baseAttr, blockquoteAttr, buttonAttr, c_events, canvasAttr, colAttr, colgroupAttr, contenteditableAttr, dataAttr, delAttr, detailsAttr, dialogAttr, embedAttr, errorStatus, fieldsetAttr, formAttr, iframeAttr, imgAttr, inputAttr, insAttr, labelAttr, liAttr, linkAttr, mapAttr, menuAttr, metaAttr, meterAttr, objectAttr, olAttr, optgroupAttr, optionAttr, outputAttr, paramAttr, progressAttr, qAttr, renderedDom, scriptAttr, selectAttr, sourceAttr, statefulValue, styleAttr, successStatus, svgAttr, svgEAttr, svgETextAttr, tdAttr, textareaAttr, thAttr, timeAttr, trackAttr, videoAttr };
1930
+ export { $, ATTR, BrowserStore, Column, DOM, DbRepository, Derived, DisposalScope, Elem, EventStream, FailurePage, Field, HTTPError, HeadDefaults, IDNotConnected, IndexedDatabase, MissingPage, Page, QState, RecState, RecStateful, Ref, RefState, RouteBook, Schema, Scope, SetState, SetStateful, SocketController, SocketHub, State, StateEffect, StateHook, StateLoaded, Stateful, Stored, StoredValue, Toggled, VersionedValue, Yvee, allGuards, applyHead, attr_value, batch, buildReturnTo, createGuard, dom, error, eventStream, eventStreams, frag, getElementById, hook, interpolate, isClient, loaded, local, normalizePath, page, paramsGuard, readCookie, readReturnTo, renderContent, renderDom, renderJSONScript, requestForm, requestJSON, requireGuard, route, serializePayload, session, setContentRenderer, shallowEqual, socketRoute, t, toURL, use, useRef, whenGuard };
1931
+ export type { $_, CSSStyle, Cleanup, ColumnType, Constructor, ContentRenderer, ContextGuard, CsrfOptions, DOMAttr, DOMComponent, DOMComponentProps, DOMContext, DOMEvents, DOMNode, DOMRenderable, DOMValue, DVal, DerivedOptions, DerivedValue, Disposable, EAttr, ElementAttributes, Elements, Equality, EventMap, FieldScopeSet, FormRequestOptions, FormResult, Guard, GuardApp, GuardContext, GuardContextInput, GuardFactory, GuardFallback, GuardPredicate, GuardRedirect, GuardRejection, GuardResult, HeadConfig, HeadResult, IRecStateful, ISetStateful, IStateful, JSONRequestOptions, JsonMessageOptions, Layout, MessageFailure, MountOptions, OpenOptions, PageFetchContext, RegionCache, RegionEnterContext, RegionGuard, RegionGuardContext, RegionLeaveContext, RegionLoader, RegionModule, RenderResult, RenderedContent, RenderedDOM, RequestRetry, RouteEntry, SVGAttributes, ScopeDecorator, ScopeProxy, ScopeSet, ServerDataContext, ServerOptions, ServerRenderer, ServerRequest, ServerStatusResult, SocketConnectionState, SocketLoadOptions, StateHookOptions, StateOptions, StateUpdate, StorageChange, StorageSchema, StorageWatchOptions, StreamHandlers, StreamOptions, TagNames, Transport, YveeOptions, YveeURL, _$, aAttr, areaAttr, audioAttr, baseAttr, blockquoteAttr, buttonAttr, c_events, canvasAttr, colAttr, colgroupAttr, contenteditableAttr, dataAttr, delAttr, detailsAttr, dialogAttr, embedAttr, errorStatus, fieldsetAttr, formAttr, iframeAttr, imgAttr, inputAttr, insAttr, labelAttr, liAttr, linkAttr, mapAttr, menuAttr, metaAttr, meterAttr, objectAttr, olAttr, optgroupAttr, optionAttr, outputAttr, paramAttr, progressAttr, qAttr, renderedDom, scriptAttr, selectAttr, sourceAttr, statefulValue, styleAttr, successStatus, svgAttr, svgEAttr, svgETextAttr, tdAttr, textareaAttr, thAttr, timeAttr, trackAttr, videoAttr };