bruh 1.13.0 → 2.0.0-beta.1
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/browser/jsx-runtime.mjs +2 -0
- package/dist/browser/jsx-runtime.mjs.map +1 -0
- package/dist/browser.mjs +174 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/cli/node.mjs +16 -0
- package/dist/cli/node.mjs.map +1 -0
- package/dist/components/aside-toc.mjs +162 -0
- package/dist/components/aside-toc.mjs.map +1 -0
- package/dist/components/custom-elements.mjs +52 -0
- package/dist/components/custom-elements.mjs.map +1 -0
- package/dist/components/intl/date-time.mjs +219 -0
- package/dist/components/intl/date-time.mjs.map +1 -0
- package/dist/components/intl/display-name.mjs +71 -0
- package/dist/components/intl/display-name.mjs.map +1 -0
- package/dist/components/intl/language-picker.mjs +102 -0
- package/dist/components/intl/language-picker.mjs.map +1 -0
- package/dist/components/intl/list.mjs +80 -0
- package/dist/components/intl/list.mjs.map +1 -0
- package/dist/components/intl/number.mjs +118 -0
- package/dist/components/intl/number.mjs.map +1 -0
- package/dist/components/intl/plural.mjs +82 -0
- package/dist/components/intl/plural.mjs.map +1 -0
- package/dist/components/intl/utils.mjs +197 -0
- package/dist/components/intl/utils.mjs.map +1 -0
- package/dist/components/optimized-picture/hydrate.mjs +10 -0
- package/dist/components/optimized-picture/hydrate.mjs.map +1 -0
- package/dist/components/optimized-picture/server.mjs +28 -0
- package/dist/components/optimized-picture/server.mjs.map +1 -0
- package/dist/components/utils.mjs +4 -0
- package/dist/components/utils.mjs.map +1 -0
- package/dist/media/images/node.mjs +41 -0
- package/dist/media/images/node.mjs.map +1 -0
- package/dist/polyfills/weakref.mjs +16 -0
- package/dist/polyfills/weakref.mjs.map +1 -0
- package/dist/reactive/sync/transport/websocket/browser.mjs +52 -0
- package/dist/reactive/sync/transport/websocket/browser.mjs.map +1 -0
- package/dist/reactive.mjs +160 -0
- package/dist/reactive.mjs.map +1 -0
- package/dist/server/jsx-runtime.mjs +2 -0
- package/dist/server/jsx-runtime.mjs.map +1 -0
- package/dist/server.mjs +346 -0
- package/dist/server.mjs.map +1 -0
- package/dist/types/cli/index.d.mts +2 -0
- package/dist/types/components/aside-toc/index.d.ts +45 -0
- package/dist/types/components/custom-elements.d.mts +83 -0
- package/dist/types/components/intl/date-time.d.ts +138 -0
- package/dist/types/components/intl/display-name.d.ts +45 -0
- package/dist/types/components/intl/language-picker.d.ts +35 -0
- package/dist/types/components/intl/list.d.ts +41 -0
- package/dist/types/components/intl/number.d.ts +81 -0
- package/dist/types/components/intl/plural.d.ts +60 -0
- package/dist/types/components/intl/utils.d.mts +30 -0
- package/dist/types/components/optimized-picture/hydrate.d.mts +2 -0
- package/dist/types/components/optimized-picture/server.d.ts +8 -0
- package/dist/types/components/utils.d.mts +5 -0
- package/dist/types/dom/browser/jsx-runtime.d.mts +3 -0
- package/dist/types/dom/index.browser.d.mts +127 -0
- package/dist/types/dom/index.server.d.mts +174 -0
- package/dist/types/dom/server/jsx-runtime.d.mts +3 -0
- package/dist/types/dom/types.d.mts +9 -0
- package/dist/types/media/images.node.d.mts +1 -0
- package/dist/types/polyfills/weakref.d.mts +4 -0
- package/dist/types/reactive/index.d.mts +91 -0
- package/dist/types/reactive/sync/transport/websocket/browser.d.mts +11 -0
- package/dist/types/utils/browser.d.mts +2 -0
- package/dist/types/utils/index.d.mts +122 -0
- package/dist/utils/browser.mjs +27 -0
- package/dist/utils/browser.mjs.map +1 -0
- package/dist/utils.mjs +287 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +125 -18
- package/mod.mjs +0 -3
- package/src/cli/index.mjs +0 -19
- package/src/components/optimized-picture/hydrate.mjs +0 -10
- package/src/components/optimized-picture/render.mjs +0 -26
- package/src/dom/index.browser.mjs +0 -270
- package/src/dom/index.server.mjs +0 -280
- package/src/index.browser.mjs +0 -3
- package/src/media/images.node.mjs +0 -70
- package/src/reactive/index.mjs +0 -160
- package/src/util/index.mjs +0 -42
- package/vite.config.mjs +0 -12
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Reactive, MaybeReactive } from '../reactive/index.mts';
|
|
2
|
+
import { PropertyWiseOr, LikelyAsString, LikelyAsAbsent, LikelyAsBoolean } from './types.mts';
|
|
3
|
+
import { PropertiesHyphen as Styles } from 'csstype';
|
|
4
|
+
import { ElementType, HTMLTag, SVGTag, MathMLTag, Namespace, HTMLNamespace, SVGNamespace, MathMLNamespace, ElementToEventMap, ElementToAttributes } from 'html-info';
|
|
5
|
+
export type TerminalBruhChild = Node | LikelyAsString | LikelyAsAbsent;
|
|
6
|
+
export type TerminalBruhChildOutputNode<Child extends TerminalBruhChild> = Child extends Node ? Child : Child extends LikelyAsString ? Text : Child extends LikelyAsAbsent ? Comment : Node;
|
|
7
|
+
export type FlatBruhChild = MaybeReactive<TerminalBruhChild> | Reactive<TerminalBruhChild | Iterable<BruhChild>>;
|
|
8
|
+
export type BruhChild = FlatBruhChild | Iterable<BruhChild>;
|
|
9
|
+
export type StylesToApply = {
|
|
10
|
+
[Property in keyof Styles]: MaybeReactive<Styles[Property] | LikelyAsAbsent>;
|
|
11
|
+
};
|
|
12
|
+
export interface ClassesToApply {
|
|
13
|
+
[className: string]: MaybeReactive<LikelyAsBoolean>;
|
|
14
|
+
}
|
|
15
|
+
export type AttributesToApply<Name extends string, NS extends Namespace = HTMLNamespace> = {
|
|
16
|
+
[Attribute in keyof ElementToAttributes<Name, NS>]?: MaybeReactive<ElementToAttributes<Name, NS>[Attribute] | LikelyAsBoolean>;
|
|
17
|
+
};
|
|
18
|
+
type EventMapToListenerProps<EventMap> = {
|
|
19
|
+
[E in ((keyof EventMap) & string) as `on${E}`]: (event: EventMap[E]) => void;
|
|
20
|
+
};
|
|
21
|
+
type AttributeMapToProps<AttributeMap> = {
|
|
22
|
+
[Attribute in keyof AttributeMap]: MaybeReactive<AttributeMap[Attribute] | LikelyAsBoolean> | (Attribute extends "style" ? StylesToApply : Attribute extends "class" ? ClassesToApply : never);
|
|
23
|
+
};
|
|
24
|
+
export interface BruhOptions {
|
|
25
|
+
namespace?: Namespace;
|
|
26
|
+
}
|
|
27
|
+
interface BaseBruhProps {
|
|
28
|
+
bruh?: BruhOptions;
|
|
29
|
+
children?: BruhChild;
|
|
30
|
+
}
|
|
31
|
+
export type BruhProps<Name extends string, NS extends string = HTMLNamespace> = BaseBruhProps & (NS extends HTMLNamespace ? {
|
|
32
|
+
bruh?: {
|
|
33
|
+
namespace?: HTMLNamespace;
|
|
34
|
+
};
|
|
35
|
+
} : {
|
|
36
|
+
bruh: {
|
|
37
|
+
namespace: NS;
|
|
38
|
+
};
|
|
39
|
+
}) & Partial<EventMapToListenerProps<ElementToEventMap<Name, NS>> & AttributeMapToProps<ElementToAttributes<Name, NS>>>;
|
|
40
|
+
export type HTMLTagToBruhProps = {
|
|
41
|
+
[Name in HTMLTag]: BruhProps<Name, HTMLNamespace>;
|
|
42
|
+
};
|
|
43
|
+
export type SVGTagToBruhProps = {
|
|
44
|
+
[Name in SVGTag]: BruhProps<Name, SVGNamespace>;
|
|
45
|
+
};
|
|
46
|
+
export type MathMLTagToBruhProps = {
|
|
47
|
+
[Name in MathMLTag]: BruhProps<Name, MathMLNamespace>;
|
|
48
|
+
};
|
|
49
|
+
export type TagToBruhProps = PropertyWiseOr<HTMLTagToBruhProps, PropertyWiseOr<SVGTagToBruhProps, MathMLTagToBruhProps>>;
|
|
50
|
+
export declare namespace JSX {
|
|
51
|
+
/** @see https://www.typescriptlang.org/docs/handbook/jsx.html#children-type-checking */
|
|
52
|
+
interface ElementChildrenAttribute {
|
|
53
|
+
children: {};
|
|
54
|
+
}
|
|
55
|
+
/** @see https://www.typescriptlang.org/docs/handbook/jsx.html#attribute-type-checking */
|
|
56
|
+
interface IntrinsicElements extends TagToBruhProps {
|
|
57
|
+
}
|
|
58
|
+
type Element = any;
|
|
59
|
+
type ElementType = HTMLTag | SVGTag | MathMLTag | ((props: any) => Element);
|
|
60
|
+
}
|
|
61
|
+
export declare function bruhChildrenToNodes(children: Iterable<BruhChild>): IterableIterator<Node>;
|
|
62
|
+
type ElementWithStyle = HTMLElement | SVGElement | MathMLElement;
|
|
63
|
+
/**
|
|
64
|
+
* Style attribute rules from an object with
|
|
65
|
+
* potentially reactive and/or set as absent values
|
|
66
|
+
*/
|
|
67
|
+
export declare const applyStyles: <E extends ElementWithStyle>(element: E, styles: StylesToApply) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Class list from an object mapping from
|
|
70
|
+
* class names to potentially reactive booleans
|
|
71
|
+
*/
|
|
72
|
+
export declare const applyClasses: (element: Element, classes: ClassesToApply) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Attributes from an object with
|
|
75
|
+
* potentially reactive and/or set as absent values
|
|
76
|
+
*/
|
|
77
|
+
export declare const applyAttributes: <Name extends string, NS extends Namespace = HTMLNamespace>(element: ElementType<Name, NS>, attributes: AttributesToApply<Name, NS>) => void;
|
|
78
|
+
export declare const t: (textContent: MaybeReactive<LikelyAsString>) => Text;
|
|
79
|
+
declare global {
|
|
80
|
+
interface String {
|
|
81
|
+
startsWith<Prefix extends string>(prefix: Prefix, position?: 0): this is `${Prefix}${string}`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export declare const jsx: {
|
|
85
|
+
/**
|
|
86
|
+
* Create an HTML element
|
|
87
|
+
*/
|
|
88
|
+
<Name extends HTMLTag>(name: Name, props: HTMLTagToBruhProps[Name], key?: string): HTMLElementTagNameMap[Name];
|
|
89
|
+
/**
|
|
90
|
+
* Create an SVG element
|
|
91
|
+
*/
|
|
92
|
+
<Name extends SVGTag>(name: Name, props: SVGTagToBruhProps[Name], key?: string): SVGElementTagNameMap[Name];
|
|
93
|
+
/**
|
|
94
|
+
* Create a MathML element
|
|
95
|
+
*/
|
|
96
|
+
<Name extends MathMLTag>(name: Name, props: MathMLTagToBruhProps[Name], key?: string): MathMLElementTagNameMap[Name];
|
|
97
|
+
/**
|
|
98
|
+
* Create an element
|
|
99
|
+
*/
|
|
100
|
+
<Name extends string, NS extends Namespace = HTMLNamespace>(name: Name, props: BruhProps<Name, NS>, key?: string): ElementType<Name, NS>;
|
|
101
|
+
/**
|
|
102
|
+
* Call a function as a JSX component
|
|
103
|
+
*/
|
|
104
|
+
<Props extends Record<any, unknown>, Result>(component: (props: Props) => Result, props: Props, key?: string): Result;
|
|
105
|
+
};
|
|
106
|
+
export declare const Fragment: <Children extends BruhChild>(props: {
|
|
107
|
+
children: Children;
|
|
108
|
+
}) => Children;
|
|
109
|
+
export declare class BruhText extends HTMLElement {
|
|
110
|
+
static hydrated: {
|
|
111
|
+
readonly [tag: string]: ReadonlySet<Text>;
|
|
112
|
+
};
|
|
113
|
+
constructor();
|
|
114
|
+
}
|
|
115
|
+
declare global {
|
|
116
|
+
interface HTMLElementTagNameMap {
|
|
117
|
+
"bruh-text": BruhText;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
declare module "html-info" {
|
|
121
|
+
interface HTMLTagToAttributes {
|
|
122
|
+
"bruh-text": {
|
|
123
|
+
"tag"?: string;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { PropertyWiseOr, MaybePromise, LikelyAsString, LikelyAsAbsent, LikelyAsBoolean } from './types.mts';
|
|
2
|
+
import { PropertiesHyphen as Styles } from 'csstype';
|
|
3
|
+
import { HTMLTag, SVGTag, MathMLTag, Namespace, HTMLNamespace, SVGNamespace, MathMLNamespace, ElementToEventMap, ElementToAttributes } from 'html-info';
|
|
4
|
+
export type TerminalBruhChild = LikelyAsString | LikelyAsAbsent | MetaNode | MetaRawString;
|
|
5
|
+
export type BruhChild = MaybePromise<TerminalBruhChild> | Promise<BruhChild> | Iterable<BruhChild> | AsyncIterable<BruhChild>;
|
|
6
|
+
export type StylesToApply = {
|
|
7
|
+
[Property in keyof Styles]: MaybePromise<Styles[Property] | LikelyAsAbsent>;
|
|
8
|
+
};
|
|
9
|
+
export interface ClassesToApply {
|
|
10
|
+
[className: string]: MaybePromise<LikelyAsBoolean>;
|
|
11
|
+
}
|
|
12
|
+
export type AttributesToApply<Name extends string, NS extends Namespace = HTMLNamespace> = {
|
|
13
|
+
[Attribute in keyof ElementToAttributes<Name, NS>]?: MaybePromise<ElementToAttributes<Name, NS>[Attribute] | LikelyAsBoolean>;
|
|
14
|
+
};
|
|
15
|
+
type EventMapToListenerProps<EventMap> = {
|
|
16
|
+
[E in ((keyof EventMap) & string) as `on${E}`]: string;
|
|
17
|
+
};
|
|
18
|
+
type AttributeMapToProps<AttributeMap> = {
|
|
19
|
+
[Attribute in keyof AttributeMap]: MaybePromise<AttributeMap[Attribute] | LikelyAsBoolean> | (Attribute extends "style" ? StylesToApply : Attribute extends "class" ? ClassesToApply : never);
|
|
20
|
+
};
|
|
21
|
+
export interface BruhOptions {
|
|
22
|
+
namespace?: Namespace;
|
|
23
|
+
}
|
|
24
|
+
interface BaseBruhProps {
|
|
25
|
+
bruh?: BruhOptions;
|
|
26
|
+
children?: BruhChild;
|
|
27
|
+
}
|
|
28
|
+
export type BruhProps<Name extends string, NS extends string = HTMLNamespace> = BaseBruhProps & (NS extends HTMLNamespace ? {
|
|
29
|
+
bruh?: {
|
|
30
|
+
namespace?: HTMLNamespace;
|
|
31
|
+
};
|
|
32
|
+
} : {
|
|
33
|
+
bruh: {
|
|
34
|
+
namespace: NS;
|
|
35
|
+
};
|
|
36
|
+
}) & Partial<EventMapToListenerProps<ElementToEventMap<Name, NS>> & AttributeMapToProps<ElementToAttributes<Name, NS>>>;
|
|
37
|
+
export type HTMLTagToBruhProps = {
|
|
38
|
+
[Name in HTMLTag]: BruhProps<Name, HTMLNamespace>;
|
|
39
|
+
};
|
|
40
|
+
export type SVGTagToBruhProps = {
|
|
41
|
+
[Name in SVGTag]: BruhProps<Name, SVGNamespace>;
|
|
42
|
+
};
|
|
43
|
+
export type MathMLTagToBruhProps = {
|
|
44
|
+
[Name in MathMLTag]: BruhProps<Name, MathMLNamespace>;
|
|
45
|
+
};
|
|
46
|
+
export type TagToBruhProps = PropertyWiseOr<HTMLTagToBruhProps, PropertyWiseOr<SVGTagToBruhProps, MathMLTagToBruhProps>>;
|
|
47
|
+
export declare namespace JSX {
|
|
48
|
+
/** @see https://www.typescriptlang.org/docs/handbook/jsx.html#children-type-checking */
|
|
49
|
+
interface ElementChildrenAttribute {
|
|
50
|
+
children: {};
|
|
51
|
+
}
|
|
52
|
+
/** @see https://www.typescriptlang.org/docs/handbook/jsx.html#attribute-type-checking */
|
|
53
|
+
interface IntrinsicElements extends TagToBruhProps {
|
|
54
|
+
}
|
|
55
|
+
type Element = any;
|
|
56
|
+
type ElementType = HTMLTag | SVGTag | MathMLTag | ((props: any) => Element);
|
|
57
|
+
}
|
|
58
|
+
declare const isMetaNode: unique symbol;
|
|
59
|
+
declare const isMetaTextNode: unique symbol;
|
|
60
|
+
declare const isMetaElement: unique symbol;
|
|
61
|
+
declare const isMetaRawString: unique symbol;
|
|
62
|
+
type MetaNode = MetaTextNode | MetaElement<string, Namespace>;
|
|
63
|
+
export declare class MetaTextNode {
|
|
64
|
+
[isMetaNode]: boolean;
|
|
65
|
+
[isMetaTextNode]: boolean;
|
|
66
|
+
textContent: MaybePromise<LikelyAsString>;
|
|
67
|
+
tag?: string;
|
|
68
|
+
constructor(textContent: MaybePromise<LikelyAsString>);
|
|
69
|
+
[Symbol.iterator](): IterableIterator<string>;
|
|
70
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<string>;
|
|
71
|
+
toString(): string;
|
|
72
|
+
toStringPromise(): Promise<string>;
|
|
73
|
+
setTag(tag: string): this;
|
|
74
|
+
}
|
|
75
|
+
export declare class MetaElement<Name extends string, NS extends Namespace = HTMLNamespace> {
|
|
76
|
+
#private;
|
|
77
|
+
[isMetaNode]: boolean;
|
|
78
|
+
[isMetaElement]: boolean;
|
|
79
|
+
name: Name;
|
|
80
|
+
attributes: AttributesToApply<Name, NS>;
|
|
81
|
+
children: Array<BruhChild>;
|
|
82
|
+
constructor(name: Name);
|
|
83
|
+
[Symbol.iterator](): IterableIterator<string>;
|
|
84
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<string>;
|
|
85
|
+
toString(): string;
|
|
86
|
+
toStringPromise(): Promise<string>;
|
|
87
|
+
}
|
|
88
|
+
export declare class MetaRawString extends String {
|
|
89
|
+
[isMetaRawString]: boolean;
|
|
90
|
+
constructor(string: LikelyAsString);
|
|
91
|
+
}
|
|
92
|
+
type ElementWithStyle = MetaElement<string, HTMLNamespace | SVGNamespace | MathMLNamespace>;
|
|
93
|
+
export declare const applyStyles: (element: ElementWithStyle, styles: StylesToApply) => void;
|
|
94
|
+
export declare const applyClasses: (element: MetaElement<string, Namespace>, classes: ClassesToApply) => void;
|
|
95
|
+
export declare const applyAttributes: <Name extends string, NS extends Namespace = HTMLNamespace>(element: MetaElement<Name, NS>, attributes: AttributesToApply<Name, NS>) => void;
|
|
96
|
+
export declare const rawString: (string: LikelyAsString) => MetaRawString;
|
|
97
|
+
export declare const t: (textContent: MaybePromise<LikelyAsString>) => MetaTextNode;
|
|
98
|
+
export declare const jsx: {
|
|
99
|
+
/**
|
|
100
|
+
* Create an HTML element
|
|
101
|
+
*/
|
|
102
|
+
<Name extends HTMLTag>(name: Name, props: HTMLTagToBruhProps[Name], key?: string): MetaElement<Name, HTMLNamespace>;
|
|
103
|
+
/**
|
|
104
|
+
* Create an SVG element
|
|
105
|
+
*/
|
|
106
|
+
<Name extends SVGTag>(name: Name, props: SVGTagToBruhProps[Name], key?: string): MetaElement<Name, SVGNamespace>;
|
|
107
|
+
/**
|
|
108
|
+
* Create a MathML element
|
|
109
|
+
*/
|
|
110
|
+
<Name extends MathMLTag>(name: Name, props: MathMLTagToBruhProps[Name], key?: string): MetaElement<Name, MathMLNamespace>;
|
|
111
|
+
/**
|
|
112
|
+
* Create an element
|
|
113
|
+
*/
|
|
114
|
+
<Name extends string, NS extends Namespace = HTMLNamespace>(name: Name, props: BruhProps<Name, NS>, key?: string): MetaElement<Name, NS>;
|
|
115
|
+
/**
|
|
116
|
+
* Call a function as a JSX component
|
|
117
|
+
*/
|
|
118
|
+
<Props extends Record<any, unknown>, Result>(component: (props: Props) => Result, props: Props, key?: string): Result;
|
|
119
|
+
};
|
|
120
|
+
export declare const Fragment: <Children extends BruhChild>(props: {
|
|
121
|
+
children: Children;
|
|
122
|
+
}) => Children;
|
|
123
|
+
declare global {
|
|
124
|
+
interface HTMLElementTagNameMap {
|
|
125
|
+
"bruh-deferred": HTMLElement;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
declare module "html-info" {
|
|
129
|
+
interface HTMLTagToAttributes {
|
|
130
|
+
"bruh-deferred": {
|
|
131
|
+
"data-replace": `bruh-deferred-${number}`;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export declare const replaceDeferredScriptContent: string;
|
|
136
|
+
/**
|
|
137
|
+
* "Content-Security-Policy": `script-src '${replaceDeferredHash}'`
|
|
138
|
+
*/
|
|
139
|
+
export declare const replaceDeferredHash = "sha512-+xpsela6B2jMNhk2cPpAgB4Z89EeB6yltQ208+kvcbUKlkg11dBjAlj2FbNFxeE0kqOuZhdVVldl3hz1yZD38Q==";
|
|
140
|
+
type MetaDocumentDeferFunction = <P extends BruhChild>(context: {
|
|
141
|
+
placeholder: (id: `bruh-deferred-${number}`) => P;
|
|
142
|
+
content: Promise<BruhChild>;
|
|
143
|
+
}) => P;
|
|
144
|
+
type MetaDocumentDisabledDeferFunction = (context: {
|
|
145
|
+
content: Promise<BruhChild>;
|
|
146
|
+
}) => Promise<BruhChild>;
|
|
147
|
+
type MetaDocumentFunction = (context: {
|
|
148
|
+
defer: MetaDocumentDeferFunction;
|
|
149
|
+
deferred: AsyncIterableIterator<MetaElement<"template" | "bruh-deferred">>;
|
|
150
|
+
replaceDeferredScript: MetaElement<"script">;
|
|
151
|
+
} | {
|
|
152
|
+
defer: MetaDocumentDisabledDeferFunction;
|
|
153
|
+
deferred?: undefined;
|
|
154
|
+
replaceDeferredScript?: undefined;
|
|
155
|
+
}) => MetaElement<string>;
|
|
156
|
+
export declare class MetaDocument {
|
|
157
|
+
#private;
|
|
158
|
+
constructor(metaElementOrFunction: MetaElement<string> | MetaDocumentFunction);
|
|
159
|
+
[Symbol.iterator](): IterableIterator<string>;
|
|
160
|
+
[Symbol.asyncIterator]({ deferred: allowDefer }?: {
|
|
161
|
+
deferred?: boolean | undefined;
|
|
162
|
+
}): AsyncIterableIterator<string>;
|
|
163
|
+
toStream({ deferred }?: {
|
|
164
|
+
deferred?: boolean | undefined;
|
|
165
|
+
}): ReadableStream<Uint8Array>;
|
|
166
|
+
toResponse({ deferred }?: {
|
|
167
|
+
deferred?: boolean | undefined;
|
|
168
|
+
}): Response;
|
|
169
|
+
toString(): string;
|
|
170
|
+
toStringPromise({ deferred }?: {
|
|
171
|
+
deferred?: boolean | undefined;
|
|
172
|
+
}): Promise<string>;
|
|
173
|
+
}
|
|
174
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type PropertyWiseOr<A extends {}, B extends {}> = {
|
|
2
|
+
[K in keyof (A & B)]: K extends keyof (A | B) ? (A | B)[K] : K extends keyof A ? A[K] : K extends keyof B ? B[K] : never;
|
|
3
|
+
};
|
|
4
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
5
|
+
export type LikelyAsString = string | number | bigint;
|
|
6
|
+
/** Like `LikelyAsBoolean`, but `true` is treated as a missing value */
|
|
7
|
+
export type LikelyAsAbsent = null | undefined | boolean;
|
|
8
|
+
/** Like `LikelyAsAbsent`, but `true` is not treated as a missing value */
|
|
9
|
+
export type LikelyAsBoolean = boolean | null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const processImages: (directory: string) => Promise<void>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export declare const isReactiveSymbol: unique symbol;
|
|
2
|
+
export declare const isReactive: (x: unknown) => x is Reactive<unknown>;
|
|
3
|
+
type Reaction = () => void;
|
|
4
|
+
type StopReacting = () => void;
|
|
5
|
+
export interface Reactive<T> {
|
|
6
|
+
[isReactiveSymbol]: true;
|
|
7
|
+
value: T;
|
|
8
|
+
addReaction(reaction: Reaction): StopReacting;
|
|
9
|
+
}
|
|
10
|
+
export type Unreactive<T> = Exclude<T, {
|
|
11
|
+
[isReactiveSymbol]: true;
|
|
12
|
+
}>;
|
|
13
|
+
export type MaybeReactive<T> = Reactive<T> | Unreactive<T>;
|
|
14
|
+
/**
|
|
15
|
+
* A super simple and performant reactive value implementation
|
|
16
|
+
*/
|
|
17
|
+
export declare class SimpleReactive<T> implements Reactive<T> {
|
|
18
|
+
#private;
|
|
19
|
+
[isReactiveSymbol]: true;
|
|
20
|
+
constructor(value: T);
|
|
21
|
+
get value(): T;
|
|
22
|
+
set value(newValue: T);
|
|
23
|
+
/**
|
|
24
|
+
* @param reaction called every time that the value changes
|
|
25
|
+
* @returns a function that stops the reactions
|
|
26
|
+
*/
|
|
27
|
+
addReaction(reaction: Reaction): () => boolean;
|
|
28
|
+
}
|
|
29
|
+
export type SourceNode<T> = FunctionalReactive<T, "source">;
|
|
30
|
+
export type DerivativeNode<T> = FunctionalReactive<T, "derivative">;
|
|
31
|
+
/**
|
|
32
|
+
* A reactive implementation for building functional reactive graphs.
|
|
33
|
+
* Ensures state consistency, minimal node updates, and transparent update batching.
|
|
34
|
+
*/
|
|
35
|
+
export declare class FunctionalReactive<T, U extends "source" | "derivative" = any> implements Reactive<T> {
|
|
36
|
+
#private;
|
|
37
|
+
[isReactiveSymbol]: true;
|
|
38
|
+
constructor(value: T);
|
|
39
|
+
constructor(dependencies: ReadonlyArray<FunctionalReactive<unknown>>, f: () => T);
|
|
40
|
+
get value(): T;
|
|
41
|
+
set value(newValue: T);
|
|
42
|
+
/**
|
|
43
|
+
* @param reaction called every time that the value changes
|
|
44
|
+
* @returns a function that stops the reactions
|
|
45
|
+
*/
|
|
46
|
+
addReaction(reaction: Reaction): () => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Apply pending updates from actually changed source nodes
|
|
49
|
+
*/
|
|
50
|
+
static applyUpdates(): void;
|
|
51
|
+
}
|
|
52
|
+
type R = {
|
|
53
|
+
/**
|
|
54
|
+
* An initially undefined source node
|
|
55
|
+
*/
|
|
56
|
+
<T>(): SourceNode<T | undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* A source node
|
|
59
|
+
*/
|
|
60
|
+
<T>(value: T): SourceNode<T>;
|
|
61
|
+
/**
|
|
62
|
+
* A derived node
|
|
63
|
+
*/
|
|
64
|
+
<T>(dependencies: ReadonlyArray<FunctionalReactive<unknown>>, f: () => T): DerivativeNode<T>;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* A convenient wrapper for FunctionalReactive
|
|
68
|
+
*/
|
|
69
|
+
export declare const r: R;
|
|
70
|
+
type ReactiveDo = {
|
|
71
|
+
/**
|
|
72
|
+
* Calls the given function with the reactive's value whenever it changes
|
|
73
|
+
* @returns a function that stops the reactions
|
|
74
|
+
*/
|
|
75
|
+
<T>(reactive: Reactive<T>, f: (value: T) => unknown): StopReacting;
|
|
76
|
+
/**
|
|
77
|
+
* Calls the given function with the value once
|
|
78
|
+
*/
|
|
79
|
+
<T>(value: Unreactive<T>, f: (value: Unreactive<T>) => unknown): undefined;
|
|
80
|
+
/**
|
|
81
|
+
* If the value is not reactive, it calls the given function with that value once.
|
|
82
|
+
* If it is a reactive value, it calls the given function with the reactive's value whenever it changes.
|
|
83
|
+
* @returns a function that stops the reactions, if the value is reactive
|
|
84
|
+
*/
|
|
85
|
+
<T>(x: MaybeReactive<T>, f: (value: T) => unknown): StopReacting | undefined;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Do something with a value, updating if it is reactive
|
|
89
|
+
*/
|
|
90
|
+
export declare const reactiveDo: ReactiveDo;
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MaybeReactive } from '../../../../reactive/index.mts';
|
|
2
|
+
export declare const resolveWebSocketURL: (url?: URL | string) => URL;
|
|
3
|
+
export declare const connectToWebSocket: (url: URL | string, initialReconnectDelay?: number, // 1/4 second
|
|
4
|
+
reconnectDelayCeiling?: number) => import('../../../../reactive/index.mts').SourceNode<WebSocket | undefined>;
|
|
5
|
+
export type WebSocketHandlers = {
|
|
6
|
+
raw?: (data: Blob | ArrayBuffer) => void;
|
|
7
|
+
byType?: {
|
|
8
|
+
[type: string]: (data: any) => void;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const handleWebSocket: (maybeReactiveWebSocket: MaybeReactive<WebSocket | undefined>, handlers: WebSocketHandlers) => (data: unknown) => void;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { LikelyAsString } from '../dom/types.mts';
|
|
2
|
+
/**
|
|
3
|
+
* Dispatch a custom event to (capturing) and from (bubbling) a target (usually a DOM node).
|
|
4
|
+
* Returns false if the event was cancelled (preventDefault()) and true otherwise.
|
|
5
|
+
*
|
|
6
|
+
* Note that this is synchronous
|
|
7
|
+
*/
|
|
8
|
+
export declare const dispatch: (target: EventTarget, type: string, detail: unknown, options: CustomEventInit) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Inspired by https://antfu.me/posts/destructuring-with-object-or-array#take-away
|
|
11
|
+
*
|
|
12
|
+
* Creates an object that is both destructable with {...} and [...]
|
|
13
|
+
*
|
|
14
|
+
* Useful for writing library functions à la react-use & vueuse
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const useExample = () => {
|
|
19
|
+
* const a = "a"
|
|
20
|
+
* const b = "b"
|
|
21
|
+
* return createDestructable(
|
|
22
|
+
* { a, b },
|
|
23
|
+
* [ a, b ]
|
|
24
|
+
* )
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* const { a, b } = useExample()
|
|
28
|
+
* // or
|
|
29
|
+
* const [ a, b ] = useExample()
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const createDestructable: <const T extends {}, const U extends Iterable<unknown>>(object: T, iterable: U) => T & U;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an object (as a Proxy) that acts as a function
|
|
35
|
+
*
|
|
36
|
+
* So functionAsObject(f).property is equivalent to f("property")
|
|
37
|
+
*
|
|
38
|
+
* This is can be useful when combined with destructuring syntax
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const { html, head, title, body, main, h1, p } = functionAsObject(e)
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const functionAsObject: <T extends {
|
|
46
|
+
[input: PropertyKey]: any;
|
|
47
|
+
}>(f: <K extends keyof T>(property: K) => T[K]) => T;
|
|
48
|
+
export declare const pick: <T, K extends keyof T>(t: T, ...keys: ReadonlyArray<K>) => Pick<T, K>;
|
|
49
|
+
export declare const omit: <T, K extends keyof T>(t: T, ...keys: ReadonlyArray<K>) => Omit<T, K>;
|
|
50
|
+
export declare const mapObject: <const O extends {}, const K extends keyof O, const V extends O[K], const RK extends PropertyKey, const RV>(o: O, f: ([k, v]: [K, V]) => [RK, RV]) => { [Entry in { [Key in keyof O]: [RK, RV]; }[keyof O] as Entry[0]]: Entry[1]; };
|
|
51
|
+
export type InvertObject<O extends Record<PropertyKey, PropertyKey>> = {
|
|
52
|
+
[Entry in {
|
|
53
|
+
[Key in keyof O]: [O[Key], Key];
|
|
54
|
+
}[keyof O] as Entry[0]]: Entry[1];
|
|
55
|
+
};
|
|
56
|
+
export declare const invertObject: <const O extends Record<PropertyKey, PropertyKey>>(o: O) => InvertObject<O>;
|
|
57
|
+
export declare const camelToDashCase: (s: string) => string;
|
|
58
|
+
export declare const dashToCamelCase: (s: string) => string;
|
|
59
|
+
export declare const unique: <T, K>(values: Iterable<T>, getKey?: (value: T) => K) => T[];
|
|
60
|
+
export declare const attempt: {
|
|
61
|
+
<T, R = undefined>(f: () => T, recover?: (e: unknown) => R): T | R;
|
|
62
|
+
<T, R = undefined>(f: () => Promise<T>, recover?: (e: unknown) => R): Promise<T | R>;
|
|
63
|
+
};
|
|
64
|
+
export declare const makePromiseQueue: <T extends unknown, E extends unknown>() => {
|
|
65
|
+
enqueue: (promise: Promise<T>) => void;
|
|
66
|
+
[Symbol.asyncIterator](): AsyncGenerator<{
|
|
67
|
+
status: "fulfilled";
|
|
68
|
+
value: T;
|
|
69
|
+
} | {
|
|
70
|
+
status: "rejected";
|
|
71
|
+
reason: E;
|
|
72
|
+
}, void, unknown>;
|
|
73
|
+
};
|
|
74
|
+
export declare const concatenateStreams: <T extends any>(streams: ReadonlyArray<ReadableStream<T>>) => Promise<ReadableStream<T>>;
|
|
75
|
+
export declare const originLock: (name: string, options?: LockOptions) => Promise<() => void>;
|
|
76
|
+
export declare const range: (from: number, to: number, stepSize?: number) => number[];
|
|
77
|
+
export declare const randomId: () => string;
|
|
78
|
+
export declare const basicLatin: string;
|
|
79
|
+
export declare const makeRandomPassword: ({ length, characters }?: {
|
|
80
|
+
/** Max 256 */
|
|
81
|
+
length?: number;
|
|
82
|
+
characters?: string | ReadonlyArray<string>;
|
|
83
|
+
}) => string;
|
|
84
|
+
export declare const hash: (data: string | BufferSource, algorithm?: AlgorithmIdentifier) => Promise<string>;
|
|
85
|
+
/**
|
|
86
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping
|
|
87
|
+
*/
|
|
88
|
+
export declare const regexEscape: (s: string) => string;
|
|
89
|
+
export declare const regexTag: (strings: TemplateStringsArray, ...substitutions: ReadonlyArray<unknown>) => (flags?: string) => RegExp;
|
|
90
|
+
export declare const urlTag: (strings: TemplateStringsArray, ...substitutions: ReadonlyArray<unknown>) => string;
|
|
91
|
+
type UrlParts = {
|
|
92
|
+
pathname: string;
|
|
93
|
+
search: string;
|
|
94
|
+
hash: string;
|
|
95
|
+
};
|
|
96
|
+
export declare const modifyUrl: (url: URL | string, f: (parts: UrlParts) => Partial<UrlParts>) => string;
|
|
97
|
+
export declare const urlWithParams: (url: URL | string, searchParameters?: Record<string, LikelyAsString | ReadonlyArray<LikelyAsString> | undefined>) => string;
|
|
98
|
+
export declare class NodeTreeIterator implements IterableIterator<Node> {
|
|
99
|
+
#private;
|
|
100
|
+
constructor(root: ParentNode, filter?: (node: Node) => boolean);
|
|
101
|
+
/** Skip descendents of the current node */
|
|
102
|
+
skip(): void;
|
|
103
|
+
next(): {
|
|
104
|
+
done: false;
|
|
105
|
+
value: Node;
|
|
106
|
+
} | {
|
|
107
|
+
done: true;
|
|
108
|
+
value: undefined;
|
|
109
|
+
};
|
|
110
|
+
[Symbol.iterator](): this;
|
|
111
|
+
}
|
|
112
|
+
export declare const makeFlatRange: (firstNode: ChildNode, isLastNode: (node: ChildNode) => boolean) => Range;
|
|
113
|
+
type SearchPath = ReadonlyArray<{
|
|
114
|
+
parent: {};
|
|
115
|
+
key: PropertyKey;
|
|
116
|
+
value: unknown;
|
|
117
|
+
}>;
|
|
118
|
+
export declare const recursivelySearchFor: <T extends unknown>(x: unknown, f: (value: unknown) => value is T, path?: SearchPath) => ReadonlyArray<{
|
|
119
|
+
path: SearchPath;
|
|
120
|
+
value: T;
|
|
121
|
+
}>;
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { r } from '../reactive.mjs';
|
|
2
|
+
|
|
3
|
+
const currentUrl = r();
|
|
4
|
+
const reflectUrl = () => {
|
|
5
|
+
currentUrl.value = new URL(location.href);
|
|
6
|
+
};
|
|
7
|
+
reflectUrl();
|
|
8
|
+
addEventListener("hashchange", reflectUrl);
|
|
9
|
+
if ("navigation" in window)
|
|
10
|
+
navigation.addEventListener("navigate", reflectUrl);
|
|
11
|
+
else {
|
|
12
|
+
const replacedPushState = history.pushState;
|
|
13
|
+
history.pushState = function() {
|
|
14
|
+
const result = replacedPushState.apply(this, arguments);
|
|
15
|
+
reflectUrl();
|
|
16
|
+
return result;
|
|
17
|
+
};
|
|
18
|
+
const replacedReplaceState = history.replaceState;
|
|
19
|
+
history.replaceState = function() {
|
|
20
|
+
const result = replacedReplaceState.apply(this, arguments);
|
|
21
|
+
reflectUrl();
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { currentUrl };
|
|
27
|
+
//# sourceMappingURL=browser.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.mjs","sources":["../../src/utils/browser.mts"],"sourcesContent":["import { r, type SourceNode } from \"../reactive/index.mts\"\n\nexport const currentUrl = r() as SourceNode<URL>\n\nconst reflectUrl = () => {\n currentUrl.value = new URL(location.href)\n}\nreflectUrl()\n\naddEventListener(\"hashchange\", reflectUrl)\n\ndeclare var navigation: EventTarget\nif (\"navigation\" in window)\n navigation.addEventListener(\"navigate\", reflectUrl)\nelse {\n const replacedPushState = history.pushState\n history.pushState = function() {\n const result = replacedPushState.apply(this, arguments as any)\n reflectUrl()\n return result\n }\n\n const replacedReplaceState = history.replaceState\n history.replaceState = function() {\n const result = replacedReplaceState.apply(this, arguments as any)\n reflectUrl()\n return result\n }\n}\n"],"names":[],"mappings":";;AAEO,MAAM,aAAa,CAAE;AAE5B,MAAM,aAAa,MAAM;AACvB,EAAA,UAAA,CAAW,KAAQ,GAAA,IAAI,GAAI,CAAA,QAAA,CAAS,IAAI,CAAA;AAC1C,CAAA;AACA,UAAW,EAAA;AAEX,gBAAA,CAAiB,cAAc,UAAU,CAAA;AAGzC,IAAI,YAAgB,IAAA,MAAA;AAClB,EAAW,UAAA,CAAA,gBAAA,CAAiB,YAAY,UAAU,CAAA;AAAA,KAC/C;AACH,EAAA,MAAM,oBAAoB,OAAQ,CAAA,SAAA;AAClC,EAAA,OAAA,CAAQ,YAAY,WAAW;AAC7B,IAAA,MAAM,MAAS,GAAA,iBAAA,CAAkB,KAAM,CAAA,IAAA,EAAM,SAAgB,CAAA;AAC7D,IAAW,UAAA,EAAA;AACX,IAAO,OAAA,MAAA;AAAA,GACT;AAEA,EAAA,MAAM,uBAAuB,OAAQ,CAAA,YAAA;AACrC,EAAA,OAAA,CAAQ,eAAe,WAAW;AAChC,IAAA,MAAM,MAAS,GAAA,oBAAA,CAAqB,KAAM,CAAA,IAAA,EAAM,SAAgB,CAAA;AAChE,IAAW,UAAA,EAAA;AACX,IAAO,OAAA,MAAA;AAAA,GACT;AACF;;;;"}
|