@jasonshimmy/custom-elements-runtime 0.0.10 → 0.0.12
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/README.md +85 -107
- package/dist/custom-elements-runtime.cjs.js +16 -69
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +1506 -1461
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.umd.js +16 -69
- package/dist/custom-elements-runtime.umd.js.map +1 -1
- package/dist/directives.d.ts +11 -0
- package/dist/router.d.ts +17 -6
- package/dist/runtime.d.ts +54 -137
- package/dist/store.d.ts +5 -1
- package/dist/style-utils.d.ts +9 -0
- package/dist/template-compiler.d.ts +4 -115
- package/dist/vdom.d.ts +32 -0
- package/package.json +5 -5
- package/dist/build-tools.d.ts +0 -66
- package/dist/computed-state.d.ts +0 -10
- package/dist/data-binding.d.ts +0 -8
- package/dist/dev-tools.d.ts +0 -21
- package/dist/ssr.d.ts +0 -49
- package/dist/template-helpers.d.ts +0 -43
- package/dist/v-dom.d.ts +0 -54
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { VNode } from "./vdom";
|
|
2
|
+
export declare function when(cond: boolean, children: VNode | VNode[]): VNode;
|
|
3
|
+
export declare function each<T extends string | number | boolean | {
|
|
4
|
+
id?: string | number;
|
|
5
|
+
key?: string;
|
|
6
|
+
}>(list: T[], render: (item: T, index: number) => VNode | VNode[]): VNode[];
|
|
7
|
+
export declare function match(): {
|
|
8
|
+
when(cond: any, content: VNode | VNode[]): /*elided*/ any;
|
|
9
|
+
otherwise(content: VNode | VNode[]): /*elided*/ any;
|
|
10
|
+
done(): VNode[];
|
|
11
|
+
};
|
package/dist/router.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* - Functional API, zero dependencies, SSR/static site compatible
|
|
4
4
|
* - Integrates with Store and runtime.ts
|
|
5
5
|
*/
|
|
6
|
+
import { type Store } from './store';
|
|
6
7
|
export interface Route {
|
|
7
8
|
path: string;
|
|
8
9
|
component?: string;
|
|
@@ -26,22 +27,32 @@ export interface RouteState {
|
|
|
26
27
|
*/
|
|
27
28
|
export declare function resolveRouteComponent(route: Route): Promise<any>;
|
|
28
29
|
export declare function useRouter(config: RouterConfig): {
|
|
29
|
-
store:
|
|
30
|
-
subscribe: (listener: (state: object) => void) => void;
|
|
31
|
-
getState: () => object;
|
|
32
|
-
};
|
|
30
|
+
store: Store<RouteState>;
|
|
33
31
|
push: (path: string) => void;
|
|
34
32
|
replace: (path: string) => void;
|
|
35
33
|
back: () => void;
|
|
36
|
-
subscribe: (listener: (state:
|
|
34
|
+
subscribe: (listener: (state: RouteState) => void) => void;
|
|
37
35
|
matchRoute: (path: string) => {
|
|
38
36
|
route: Route | null;
|
|
39
37
|
params: Record<string, string>;
|
|
40
38
|
};
|
|
41
|
-
getCurrent: () =>
|
|
39
|
+
getCurrent: () => RouteState;
|
|
42
40
|
resolveRouteComponent: typeof resolveRouteComponent;
|
|
43
41
|
};
|
|
44
42
|
export declare function matchRouteSSR(routes: Route[], path: string): {
|
|
45
43
|
route: Route | null;
|
|
46
44
|
params: Record<string, string>;
|
|
47
45
|
};
|
|
46
|
+
export declare function initRouter(config: RouterConfig): {
|
|
47
|
+
store: Store<RouteState>;
|
|
48
|
+
push: (path: string) => void;
|
|
49
|
+
replace: (path: string) => void;
|
|
50
|
+
back: () => void;
|
|
51
|
+
subscribe: (listener: (state: RouteState) => void) => void;
|
|
52
|
+
matchRoute: (path: string) => {
|
|
53
|
+
route: Route | null;
|
|
54
|
+
params: Record<string, string>;
|
|
55
|
+
};
|
|
56
|
+
getCurrent: () => RouteState;
|
|
57
|
+
resolveRouteComponent: typeof resolveRouteComponent;
|
|
58
|
+
};
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,144 +1,61 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
emit(eventName: string, detail?: unknown): void;
|
|
17
|
-
onGlobal<U = any>(eventName: string, handler: (data: U) => void): () => void;
|
|
18
|
-
offGlobal<U = any>(eventName: string, handler: (data: U) => void): void;
|
|
19
|
-
emitGlobal<U = any>(eventName: string, data?: U): void;
|
|
20
|
-
render(): void;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Configuration object for a custom element component.
|
|
24
|
-
* Defines template, state, computed properties, styles, refs, and lifecycle hooks.
|
|
25
|
-
* @template S - State type
|
|
26
|
-
* @template C - Computed type
|
|
27
|
-
*/
|
|
28
|
-
export interface ComponentConfig<S extends ComponentState, C extends Record<string, any> = {}> {
|
|
29
|
-
readonly template: (state: S & C, api: ComponentAPI<S & C>) => string | Promise<string> | CompiledTemplate<S & C>;
|
|
30
|
-
readonly state?: S;
|
|
31
|
-
readonly computed?: {
|
|
32
|
-
[K in keyof C]: (state: S) => C[K];
|
|
33
|
-
};
|
|
34
|
-
readonly style?: string | ((state: S & C) => string);
|
|
35
|
-
readonly refs?: Record<string, RefHandler<S & C>>;
|
|
36
|
-
readonly onMounted?: LifecycleHandler<S & C>;
|
|
37
|
-
readonly onUnmounted?: LifecycleHandler<S & C>;
|
|
38
|
-
readonly debug?: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Whitelist of state keys to reflect as attributes. If omitted, no keys are reflected.
|
|
41
|
-
*/
|
|
42
|
-
readonly reflect?: string[];
|
|
43
|
-
hydrate?: (el: Element | ShadowRoot, state: S & C, api: ComponentAPI<S & C>) => void;
|
|
44
|
-
[handler: string]: ((...args: unknown[]) => unknown) | unknown;
|
|
2
|
+
* runtime.ts
|
|
3
|
+
* Lightweight, strongly typed, functional custom element runtime for two-way binding, event, and prop support.
|
|
4
|
+
* Supports: state, computed, props, style, render, lifecycle hooks, #model-* and data-on-* attributes.
|
|
5
|
+
* No external dependencies. Mobile-first, secure, and developer friendly.
|
|
6
|
+
*/
|
|
7
|
+
export { createStore } from "./store";
|
|
8
|
+
export { eventBus } from "./event-bus";
|
|
9
|
+
export { html } from "./template-compiler";
|
|
10
|
+
export { when, each, match } from "./directives";
|
|
11
|
+
import { type VNode } from "./vdom";
|
|
12
|
+
type LifecycleKeys = "onConnected" | "onDisconnected" | "onAttributeChanged" | "onError" | "errorFallback";
|
|
13
|
+
interface WatchOptions {
|
|
14
|
+
immediate?: boolean;
|
|
15
|
+
deep?: boolean;
|
|
45
16
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export type RefHandler<T extends ComponentState> = (element: Element, state: T, api: ComponentAPI<T>) => void;
|
|
53
|
-
export type ComputedHandler<T extends ComponentState> = (state: T) => unknown;
|
|
54
|
-
/**
|
|
55
|
-
* Lifecycle handler for mounted/unmounted events.
|
|
56
|
-
* @param state - Current component state
|
|
57
|
-
* @param api - Component API
|
|
58
|
-
*/
|
|
59
|
-
export type LifecycleHandler<T extends ComponentState> = (state: T, api: ComponentAPI<T>) => void;
|
|
60
|
-
/**
|
|
61
|
-
* Plugin interface for runtime hooks (init, render, error).
|
|
62
|
-
*/
|
|
63
|
-
export type RuntimePlugin<S extends ComponentState, C extends Record<string, any>> = {
|
|
64
|
-
onInit?: (config: ComponentConfig<S, C>) => void;
|
|
65
|
-
onRender?: (state: S & C, api: ComponentAPI<S & C>) => void;
|
|
66
|
-
onError?: (error: Error, state: S & C, api: ComponentAPI<S & C>) => void;
|
|
17
|
+
type WatchCallback<T = any, S = any> = (newValue: T, oldValue: T, context?: S) => void;
|
|
18
|
+
type WatchConfig<S> = {
|
|
19
|
+
[K in keyof S]?: WatchCallback<S[K]> | [WatchCallback<S[K]>, WatchOptions?];
|
|
20
|
+
} | Record<string, WatchCallback | [WatchCallback, WatchOptions?]>;
|
|
21
|
+
type InferMethods<T> = {
|
|
22
|
+
[K in keyof T as K extends LifecycleKeys ? never : K]: T[K] extends Function ? T[K] : never;
|
|
67
23
|
};
|
|
68
|
-
export
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* @param obj - Object to sanitize
|
|
91
|
-
* @param seen - WeakSet to track visited objects
|
|
92
|
-
*/
|
|
93
|
-
export declare function deepSanitizeObject<T>(obj: T, seen?: WeakSet<object>): T;
|
|
94
|
-
/**
|
|
95
|
-
* Type guard to check if a value is Promise-like.
|
|
96
|
-
*/
|
|
97
|
-
export declare function isPromise(val: unknown): val is Promise<unknown>;
|
|
98
|
-
/**
|
|
99
|
-
* Registers a new custom element component.
|
|
100
|
-
* Validates config, sets up reactive state, and defines the custom element.
|
|
101
|
-
* Supports HMR and SSR hydration.
|
|
102
|
-
* @template S - State type
|
|
103
|
-
* @template C - Computed type
|
|
104
|
-
* @param tag - Custom element tag name
|
|
105
|
-
* @param config - Component configuration
|
|
106
|
-
*/
|
|
107
|
-
export declare function component<S extends ComponentState, C extends Record<string, any> = {}>(tag: string, config: ComponentConfig<S, C>): void;
|
|
108
|
-
/**
|
|
109
|
-
* RouterLink component state
|
|
110
|
-
*/
|
|
111
|
-
export interface RouterLinkState extends ComponentState {
|
|
112
|
-
to: string;
|
|
113
|
-
tag: string;
|
|
114
|
-
replace: boolean;
|
|
115
|
-
exact: boolean;
|
|
116
|
-
activeClass: string;
|
|
117
|
-
exactActiveClass: string;
|
|
118
|
-
ariaCurrentValue: string;
|
|
119
|
-
disabled: boolean;
|
|
120
|
-
external: boolean;
|
|
121
|
-
style: string;
|
|
24
|
+
export type ComponentContext<S extends object, C extends object, P extends object, T extends object = any> = S & C & P & InferMethods<T>;
|
|
25
|
+
export interface ComponentConfig<S extends object, C extends object = {}, P extends object = {}, T extends object = any> {
|
|
26
|
+
state?: S;
|
|
27
|
+
computed?: {
|
|
28
|
+
[K in keyof C]: (context: ComponentContext<S, C, P, T>) => C[K];
|
|
29
|
+
};
|
|
30
|
+
props?: Record<string, {
|
|
31
|
+
type: StringConstructor | NumberConstructor | BooleanConstructor;
|
|
32
|
+
default?: string | number | boolean;
|
|
33
|
+
}>;
|
|
34
|
+
watch?: WatchConfig<ComponentContext<S, C, P, T>>;
|
|
35
|
+
style?: string | ((context: ComponentContext<S, C, P, T>) => string);
|
|
36
|
+
minifyCSS?: boolean;
|
|
37
|
+
render: (context: ComponentContext<S, C, P, T>) => VNode | VNode[] | Promise<VNode | VNode[]>;
|
|
38
|
+
loadingTemplate?: (context: ComponentContext<S, C, P, T>) => VNode | VNode[];
|
|
39
|
+
errorTemplate?: (error: Error, context: ComponentContext<S, C, P, T>) => VNode | VNode[];
|
|
40
|
+
onConnected?: (context: ComponentContext<S, C, P, T>) => void;
|
|
41
|
+
onDisconnected?: (context: ComponentContext<S, C, P, T>) => void;
|
|
42
|
+
onAttributeChanged?: (name: string, oldValue: string | null, newValue: string | null, context: ComponentContext<S, C, P, T>) => void;
|
|
43
|
+
onError?: (error: Error | null, context: ComponentContext<S, C, P, T>) => void;
|
|
44
|
+
errorFallback?: (error: Error | null, context: ComponentContext<S, C, P, T>) => string;
|
|
45
|
+
[key: string]: any;
|
|
122
46
|
}
|
|
123
47
|
/**
|
|
124
|
-
*
|
|
48
|
+
* CSS template literal
|
|
125
49
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
subscribe: (listener: (state: object) => void) => void;
|
|
138
|
-
matchRoute: (path: string) => {
|
|
139
|
-
route: import("./router").Route | null;
|
|
140
|
-
params: Record<string, string>;
|
|
141
|
-
};
|
|
142
|
-
getCurrent: () => object;
|
|
143
|
-
resolveRouteComponent: typeof import("./router").resolveRouteComponent;
|
|
50
|
+
* This doesn't sanitize CSS values.
|
|
51
|
+
* Runtime does that for us.
|
|
52
|
+
*
|
|
53
|
+
* @param strings
|
|
54
|
+
* @param values
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
export declare function css(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
58
|
+
export declare function component<S extends object = {}, C extends object = {}, P extends object = {}, T extends object = any>(tag: string, renderOrConfig: ((context: ComponentContext<S, C, P, T>) => any) | ComponentConfig<S, C, P, T>, config?: Partial<ComponentConfig<S, C, P, T>>): void;
|
|
59
|
+
export declare function createElementClass<S extends object, C extends object, P extends object, T extends object = any>(config: ComponentConfig<S, C, P, T>): CustomElementConstructor | {
|
|
60
|
+
new (): object;
|
|
144
61
|
};
|
package/dist/store.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
type Listener<T> = (state: T) => void;
|
|
2
|
-
export
|
|
2
|
+
export interface Store<T extends object> {
|
|
3
|
+
subscribe(listener: Listener<T>): void;
|
|
4
|
+
getState(): T;
|
|
5
|
+
}
|
|
6
|
+
export declare function createStore<T extends object>(initial: T): {
|
|
3
7
|
subscribe: (listener: Listener<T>) => void;
|
|
4
8
|
getState: () => T;
|
|
5
9
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS minification utility (basic)
|
|
3
|
+
*/
|
|
4
|
+
export declare function minifyCSS(css: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Minimal Shadow DOM reset
|
|
7
|
+
*/
|
|
8
|
+
export declare const baseReset = "\n :host {\n box-sizing:border-box;\n line-height:1.5;\n font-family:ui-sans-serif,system-ui,sans-serif;\n -webkit-text-size-adjust:100%;\n text-size-adjust:100%;\n }\n *,::before,::after {\n box-sizing:inherit;\n margin:0;\n padding:0;\n border:0 solid currentColor;\n }\n";
|
|
9
|
+
export declare function jitCSS(html: string): string;
|
|
@@ -1,117 +1,6 @@
|
|
|
1
|
+
import type { VNode } from "./vdom";
|
|
2
|
+
export declare function h(tag: string, props?: Record<string, any>, children?: VNode[] | string, key?: string | number): VNode;
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Provides compile-time template optimization for better runtime performance.
|
|
5
|
-
* Features:
|
|
6
|
-
* - Static/dynamic separation
|
|
7
|
-
* - Efficient DOM updates
|
|
8
|
-
* - Treeshakable
|
|
9
|
-
* - TypeScript-friendly
|
|
10
|
-
* - Development-friendly fallbacks
|
|
4
|
+
* Default export: plain html.
|
|
11
5
|
*/
|
|
12
|
-
export
|
|
13
|
-
/** Static HTML parts that never change */
|
|
14
|
-
readonly statics: readonly string[];
|
|
15
|
-
/** Dynamic update functions for each interpolation */
|
|
16
|
-
readonly dynamics: readonly UpdateFunction<T>[];
|
|
17
|
-
/** Pre-compiled DOM fragment for initial render */
|
|
18
|
-
readonly fragment: DocumentFragment | null;
|
|
19
|
-
/** Unique template ID for caching */
|
|
20
|
-
readonly id: string;
|
|
21
|
-
/** Whether this template has dynamic content */
|
|
22
|
-
readonly hasDynamics: boolean;
|
|
23
|
-
/** Render method supporting async output */
|
|
24
|
-
render: (state: T, api: any) => string | Promise<string>;
|
|
25
|
-
}
|
|
26
|
-
export interface UpdateFunction<T = any> {
|
|
27
|
-
/** Target node path from root (e.g., [0, 1] means first child's second child) */
|
|
28
|
-
readonly path: readonly number[];
|
|
29
|
-
/** Type of update (text, attribute, property, etc.) */
|
|
30
|
-
readonly type: UpdateType;
|
|
31
|
-
/** Target property/attribute name (for non-text updates) */
|
|
32
|
-
readonly target?: string;
|
|
33
|
-
/** Function to extract value from state */
|
|
34
|
-
readonly getValue: (state: T, api: any) => unknown;
|
|
35
|
-
}
|
|
36
|
-
export type UpdateType = 'text' | 'attribute' | 'property' | 'event' | 'class' | 'style';
|
|
37
|
-
export interface TemplateCompilerOptions {
|
|
38
|
-
/** Enable development mode with better error messages */
|
|
39
|
-
development?: boolean;
|
|
40
|
-
/** Cache compiled templates */
|
|
41
|
-
cache?: boolean;
|
|
42
|
-
/** Enable static analysis optimizations */
|
|
43
|
-
optimize?: boolean;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Compile a template string into an optimized template object
|
|
47
|
-
* This is meant to be used at build time for best performance
|
|
48
|
-
*/
|
|
49
|
-
export declare function compileTemplate<T = any>(templateString: string, options?: TemplateCompilerOptions): CompiledTemplate<T>;
|
|
50
|
-
/**
|
|
51
|
-
* Tagged template literal for compile-time optimization
|
|
52
|
-
* Usage: compile`<div>${state.name}</div>`
|
|
53
|
-
*/
|
|
54
|
-
/**
|
|
55
|
-
* Find the DOM path to a placeholder in the template HTML
|
|
56
|
-
*/
|
|
57
|
-
export declare function findDOMPath(templateHTML: string, placeholder: string): number[];
|
|
58
|
-
export declare function compile<T = any>(strings: TemplateStringsArray, ...expressions: Array<(state: T, api: any) => unknown>): CompiledTemplate<T>;
|
|
59
|
-
export declare function parseAndCompileTemplate<T>(template: string, options: {
|
|
60
|
-
development: boolean;
|
|
61
|
-
optimize: boolean;
|
|
62
|
-
}): CompiledTemplate<T>;
|
|
63
|
-
export declare class TemplateAnalyzer {
|
|
64
|
-
private readonly template;
|
|
65
|
-
private readonly options;
|
|
66
|
-
private readonly dynamics;
|
|
67
|
-
private statics;
|
|
68
|
-
constructor(template: string, options: {
|
|
69
|
-
development: boolean;
|
|
70
|
-
optimize: boolean;
|
|
71
|
-
});
|
|
72
|
-
compile<T>(): CompiledTemplate<T>;
|
|
73
|
-
private parseTemplate;
|
|
74
|
-
private analyzeDynamicExpression;
|
|
75
|
-
private createValueGetter;
|
|
76
|
-
private createStaticFragment;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Render a compiled template efficiently
|
|
80
|
-
*/
|
|
81
|
-
export declare function renderCompiledTemplate<T>(compiled: CompiledTemplate<T>, state: T, api: any): DocumentFragment;
|
|
82
|
-
/**
|
|
83
|
-
* Update a rendered template with new state efficiently
|
|
84
|
-
*/
|
|
85
|
-
export declare function updateCompiledTemplate<T>(compiled: CompiledTemplate<T>, element: Element, newState: T, api: any, oldState?: T): void;
|
|
86
|
-
interface PerformanceMetrics {
|
|
87
|
-
compilationTime: number;
|
|
88
|
-
renderTime: number;
|
|
89
|
-
updateTime: number;
|
|
90
|
-
cacheHits: number;
|
|
91
|
-
cacheMisses: number;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Development helper to analyze template performance
|
|
95
|
-
*/
|
|
96
|
-
export declare function analyzeTemplate(template: string): {
|
|
97
|
-
staticParts: number;
|
|
98
|
-
dynamicParts: number;
|
|
99
|
-
complexity: 'low' | 'medium' | 'high';
|
|
100
|
-
recommendations: string[];
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Clear template cache for development/testing
|
|
104
|
-
*/
|
|
105
|
-
export declare function clearTemplateCache(): void;
|
|
106
|
-
/**
|
|
107
|
-
* Get performance metrics for development monitoring
|
|
108
|
-
*/
|
|
109
|
-
export declare function getPerformanceMetrics(): Map<string, PerformanceMetrics>;
|
|
110
|
-
/**
|
|
111
|
-
* Get cache statistics
|
|
112
|
-
*/
|
|
113
|
-
export declare function getCacheStats(): {
|
|
114
|
-
size: number;
|
|
115
|
-
entries: string[];
|
|
116
|
-
};
|
|
117
|
-
export {};
|
|
6
|
+
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): VNode | VNode[];
|
package/dist/vdom.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vdom.ts
|
|
3
|
+
* Lightweight, strongly typed, functional virtual DOM renderer for custom elements.
|
|
4
|
+
* Features: keyed diffing, incremental patching, focus/caret preservation, event delegation, SSR-friendly, no dependencies.
|
|
5
|
+
*/
|
|
6
|
+
export interface VNode {
|
|
7
|
+
tag: string;
|
|
8
|
+
key?: string;
|
|
9
|
+
props?: {
|
|
10
|
+
key?: string;
|
|
11
|
+
props?: any;
|
|
12
|
+
attrs?: Record<string, any>;
|
|
13
|
+
directives?: Record<string, {
|
|
14
|
+
value: string;
|
|
15
|
+
modifiers: string[];
|
|
16
|
+
}>;
|
|
17
|
+
};
|
|
18
|
+
children?: VNode[] | string;
|
|
19
|
+
}
|
|
20
|
+
export interface AnchorBlockVNode extends VNode {
|
|
21
|
+
tag: "#anchor";
|
|
22
|
+
key: string;
|
|
23
|
+
children: VNode[];
|
|
24
|
+
_startNode?: Comment;
|
|
25
|
+
_endNode?: Comment;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Main renderer: uses patching and keys for node reuse.
|
|
29
|
+
* Never uses innerHTML. Only updates what has changed.
|
|
30
|
+
*/
|
|
31
|
+
export declare function vdomRenderer(root: ShadowRoot, vnodeOrArray: VNode | VNode[], context?: any): void;
|
|
32
|
+
export declare function renderToString(vnode: VNode): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jasonshimmy/custom-elements-runtime",
|
|
3
3
|
"description": "A powerful, modern, and lightweight runtime for creating reactive web components with TypeScript",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"web-components",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"cy:open": "cypress open"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@testing-library/jest-dom": "^6.
|
|
32
|
+
"@testing-library/jest-dom": "^6.8.0",
|
|
33
33
|
"@vitest/coverage-v8": "^3.2.4",
|
|
34
|
-
"cypress": "^
|
|
34
|
+
"cypress": "^15.0.0",
|
|
35
35
|
"jsdom": "^26.1.0",
|
|
36
|
-
"typescript": "
|
|
37
|
-
"vite": "^7.
|
|
36
|
+
"typescript": "^5.9.2",
|
|
37
|
+
"vite": "^7.1.3",
|
|
38
38
|
"vitest": "^3.2.4"
|
|
39
39
|
},
|
|
40
40
|
"main": "dist/custom-elements-runtime.cjs.js",
|
package/dist/build-tools.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build Tool Integration for Template Compilation
|
|
3
|
-
*
|
|
4
|
-
* This file demonstrates how template compilation would integrate with build tools
|
|
5
|
-
* like Vite, Webpack, or Rollup for optimal production performance.
|
|
6
|
-
*/
|
|
7
|
-
import { type CompiledTemplate, type TemplateCompilerOptions } from '../lib/template-compiler.js';
|
|
8
|
-
/**
|
|
9
|
-
* Vite Plugin for Template Compilation
|
|
10
|
-
* This would be a real Vite plugin in production
|
|
11
|
-
*/
|
|
12
|
-
export declare function createTemplateCompilerPlugin(options?: TemplateCompilerOptions): {
|
|
13
|
-
name: string;
|
|
14
|
-
transform(code: string, id: string): {
|
|
15
|
-
code: string;
|
|
16
|
-
map: null;
|
|
17
|
-
} | null;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Development-time template analyzer
|
|
21
|
-
*/
|
|
22
|
-
export declare class TemplateDevTools {
|
|
23
|
-
private static readonly templates;
|
|
24
|
-
static analyzeTemplate(templateString: string): void;
|
|
25
|
-
static getStats(): {
|
|
26
|
-
totalTemplates: number;
|
|
27
|
-
totalUsage: number;
|
|
28
|
-
complexityDistribution: {
|
|
29
|
-
low: number;
|
|
30
|
-
medium: number;
|
|
31
|
-
high: number;
|
|
32
|
-
};
|
|
33
|
-
recommendations: string[];
|
|
34
|
-
};
|
|
35
|
-
static clear(): void;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Performance monitor for template rendering
|
|
39
|
-
*/
|
|
40
|
-
export declare class TemplatePerformanceMonitor {
|
|
41
|
-
private static readonly metrics;
|
|
42
|
-
static startRender(templateId: string): () => void;
|
|
43
|
-
private static recordRender;
|
|
44
|
-
static getMetrics(): {
|
|
45
|
-
templates: number;
|
|
46
|
-
totalRenders: number;
|
|
47
|
-
averageRenderTime: number;
|
|
48
|
-
slowestTemplate: {
|
|
49
|
-
id: string;
|
|
50
|
-
time: number;
|
|
51
|
-
} | null;
|
|
52
|
-
fastestTemplate: {
|
|
53
|
-
id: string;
|
|
54
|
-
time: number;
|
|
55
|
-
} | null;
|
|
56
|
-
};
|
|
57
|
-
static clear(): void;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Helper to migrate from string templates to compiled templates
|
|
61
|
-
*/
|
|
62
|
-
export declare function migrateToCompiledTemplate(stringTemplate: string, options?: TemplateCompilerOptions): {
|
|
63
|
-
compiled: CompiledTemplate;
|
|
64
|
-
migrationNotes: string[];
|
|
65
|
-
estimatedPerformanceGain: string;
|
|
66
|
-
};
|
package/dist/computed-state.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lightweight reactive state with computed properties and change notification.
|
|
3
|
-
* @template T - State shape
|
|
4
|
-
* @template C - Computed property map
|
|
5
|
-
*/
|
|
6
|
-
export declare function reactive<T extends object, C extends Record<string, (state: T) => any>>(initialState: T, computedMap?: C): T & {
|
|
7
|
-
subscribe: (fn: (state: T) => void) => () => void;
|
|
8
|
-
} & {
|
|
9
|
-
[K in keyof C]: ReturnType<C[K]>;
|
|
10
|
-
};
|
package/dist/data-binding.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal controlled input binding helper for data-model attributes.
|
|
3
|
-
* Handles checkboxes, radios, text, and modifiers (trim, number).
|
|
4
|
-
* @param el - Input/select/textarea element
|
|
5
|
-
* @param stateObj - State object to bind
|
|
6
|
-
* @param keyWithModifiers - Key and optional modifiers (e.g. 'name|trim|number')
|
|
7
|
-
*/
|
|
8
|
-
export declare function useDataModel<T extends Record<string, unknown>>(el: Element, stateObj: T, keyWithModifiers: string): void;
|
package/dist/dev-tools.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export declare const DevPerformance: {
|
|
2
|
-
measureRender<T>(name: string, fn: () => T): T;
|
|
3
|
-
getMemoryInfo(): any;
|
|
4
|
-
log(...args: unknown[]): void;
|
|
5
|
-
warn(...args: unknown[]): void;
|
|
6
|
-
error(...args: unknown[]): void;
|
|
7
|
-
debug(...args: unknown[]): void;
|
|
8
|
-
group(...args: unknown[]): void;
|
|
9
|
-
groupEnd(): void;
|
|
10
|
-
};
|
|
11
|
-
export declare const DevTools: {
|
|
12
|
-
startTiming(_componentName: string): () => number;
|
|
13
|
-
inspectComponent(element: HTMLElement): any;
|
|
14
|
-
trackStateChanges(element: HTMLElement, callback: (changes: any) => void): () => void;
|
|
15
|
-
log(...args: unknown[]): void;
|
|
16
|
-
warn(...args: unknown[]): void;
|
|
17
|
-
error(...args: unknown[]): void;
|
|
18
|
-
debug(...args: unknown[]): void;
|
|
19
|
-
group(...args: unknown[]): void;
|
|
20
|
-
groupEnd(): void;
|
|
21
|
-
};
|
package/dist/ssr.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ComponentAPI, ComponentState } from './runtime';
|
|
2
|
-
export interface SSRComponentConfig<T extends ComponentState = ComponentState> {
|
|
3
|
-
readonly tag: string;
|
|
4
|
-
readonly template: (state: T, api: ComponentAPI<T>) => string;
|
|
5
|
-
/**
|
|
6
|
-
* State object can include computed properties as getter functions that accept state as a parameter.
|
|
7
|
-
*/
|
|
8
|
-
readonly state: T;
|
|
9
|
-
readonly style?: string | ((state: T) => string);
|
|
10
|
-
readonly attrs?: Record<string, string>;
|
|
11
|
-
}
|
|
12
|
-
export interface SSRRenderOptions {
|
|
13
|
-
/** Include component styles in the output */
|
|
14
|
-
includeStyles?: boolean;
|
|
15
|
-
/** Pretty print the HTML output */
|
|
16
|
-
prettyPrint?: boolean;
|
|
17
|
-
/** Custom attribute sanitization function */
|
|
18
|
-
sanitizeAttributes?: (attrs: Record<string, string>) => Record<string, string>;
|
|
19
|
-
}
|
|
20
|
-
export interface SSRContext {
|
|
21
|
-
/** Track rendered components for hydration */
|
|
22
|
-
components: Map<string, SSRComponentConfig>;
|
|
23
|
-
/** Global styles collected during SSR */
|
|
24
|
-
styles: Set<string>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Create a minimal API for SSR that doesn't rely on DOM
|
|
28
|
-
*/
|
|
29
|
-
export declare function createSSRAPI<T extends ComponentState>(state: T): ComponentAPI<T>;
|
|
30
|
-
/**
|
|
31
|
-
* Render a component to HTML string on the server
|
|
32
|
-
* This function is treeshakable - only included when imported
|
|
33
|
-
*/
|
|
34
|
-
export declare function renderToString<T extends ComponentState>(config: SSRComponentConfig<T>, options?: SSRRenderOptions): string;
|
|
35
|
-
/**
|
|
36
|
-
* Render multiple components to HTML with shared context
|
|
37
|
-
*/
|
|
38
|
-
export declare function renderComponentsToString(components: SSRComponentConfig<any>[], options?: SSRRenderOptions): {
|
|
39
|
-
html: string;
|
|
40
|
-
styles: string;
|
|
41
|
-
context: SSRContext;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Generate hydration script for client-side takeover
|
|
45
|
-
*/
|
|
46
|
-
export declare function generateHydrationScript(context: SSRContext): string;
|
|
47
|
-
export declare const escapeHTML: (str: string) => string;
|
|
48
|
-
export declare const escapeAttribute: (str: string) => string;
|
|
49
|
-
export declare const formatHTML: (html: string) => string;
|