@moku-labs/web 0.1.0-alpha.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.
@@ -0,0 +1,90 @@
1
+ //#region src/plugins/spa/types.d.ts
2
+ /** @file spa plugin shared types — config envelope, composed state, composed API, ComponentDef. */
3
+ type ComponentHooks = {
4
+ onCreate?(element: Element): void;
5
+ onMount?(ctx: {
6
+ container: Element;
7
+ pageData?: unknown;
8
+ url: string;
9
+ }): void;
10
+ onNavStart?(ctx: {
11
+ url: string;
12
+ fromUrl: string;
13
+ }): void;
14
+ onNavEnd?(ctx: {
15
+ url: string;
16
+ pageData?: unknown;
17
+ doc?: Document;
18
+ }): void;
19
+ onUnMount?(ctx: {
20
+ reason: 'navigation' | 'destroy';
21
+ element: Element;
22
+ }): void | Promise<void>;
23
+ onDestroy?(element: Element): void;
24
+ };
25
+ type ComponentDef = {
26
+ name: string;
27
+ hooks: ComponentHooks;
28
+ };
29
+ type ComponentInstance = {
30
+ def: ComponentDef;
31
+ element: Element;
32
+ };
33
+ type SpaRuntime = {
34
+ viewTransitions?: boolean;
35
+ progressBar?: boolean;
36
+ };
37
+ /** Synthetic envelope: `spa` blog key → config; `components` blog key → components. Documented per acknowledged risk. */
38
+ type SpaConfig = {
39
+ config: SpaRuntime;
40
+ components: ComponentDef[];
41
+ };
42
+ type EventBusListener = (payload: unknown) => void;
43
+ type EventBus = {
44
+ on(event: string, listener: EventBusListener): () => void;
45
+ emit(event: string, payload: unknown): void;
46
+ };
47
+ type SpaState = {
48
+ router: {
49
+ currentUrl: string;
50
+ history: string[];
51
+ };
52
+ head: {
53
+ currentDoc: Document | null;
54
+ };
55
+ progress: {
56
+ active: boolean;
57
+ visible: boolean;
58
+ };
59
+ components: {
60
+ instances: Map<Element, ComponentInstance>;
61
+ registered: ComponentDef[];
62
+ };
63
+ eventBus: EventBus;
64
+ };
65
+ type RouterSubApi = {
66
+ navigate(url: string): Promise<void>;
67
+ current(): string;
68
+ destroy(): void;
69
+ };
70
+ type HeadSubApi = {
71
+ update(doc: Document): void;
72
+ };
73
+ type ProgressSubApi = {
74
+ start(): void;
75
+ done(): void;
76
+ };
77
+ type ComponentsSubApi = {
78
+ register(def: ComponentDef): void;
79
+ };
80
+ type SpaApi = {
81
+ router: RouterSubApi;
82
+ head: HeadSubApi;
83
+ progress: ProgressSubApi;
84
+ components: ComponentsSubApi;
85
+ };
86
+ //#endregion
87
+ //#region src/plugins/spa/components/factory.d.ts
88
+ declare const createComponent: (name: string, hooks: ComponentHooks) => ComponentDef;
89
+ //#endregion
90
+ export { SpaConfig as a, SpaApi as i, ComponentDef as n, SpaState as o, ComponentHooks as r, createComponent as t };