@jasonshimmy/custom-elements-runtime 0.1.2 → 0.1.4
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 +1 -0
- package/dist/custom-elements-runtime.cjs.js +30 -4
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +1247 -937
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.umd.js +30 -4
- package/dist/custom-elements-runtime.umd.js.map +1 -1
- package/dist/directives.d.ts +1 -1
- package/dist/index.d.ts +14 -0
- package/dist/index.spec.d.ts +1 -0
- package/dist/router.d.ts +46 -5
- package/dist/router.spec.d.ts +1 -0
- package/dist/runtime/component.d.ts +5 -0
- package/dist/runtime/helpers.d.ts +2 -0
- package/dist/runtime/lifecycle.d.ts +13 -0
- package/dist/runtime/props.d.ts +8 -0
- package/dist/runtime/render.d.ts +17 -0
- package/dist/runtime/render.spec.d.ts +1 -0
- package/dist/runtime/style.d.ts +61 -0
- package/dist/runtime/template-compiler.d.ts +26 -0
- package/dist/{runtime.d.ts → runtime/types.d.ts} +44 -31
- package/dist/runtime/vdom.d.ts +67 -0
- package/dist/runtime/vdom.edge.spec.d.ts +1 -0
- package/dist/runtime/vdom.spec.d.ts +1 -0
- package/dist/runtime/watchers.d.ts +13 -0
- package/dist/store.d.ts +2 -4
- package/package.json +5 -6
- package/dist/style-utils.d.ts +0 -11
- package/dist/template-compiler.d.ts +0 -6
- package/dist/vdom.d.ts +0 -34
package/dist/directives.d.ts
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom Elements Runtime
|
|
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 * from "./runtime/types";
|
|
8
|
+
export * from "./directives";
|
|
9
|
+
export * from "./event-bus";
|
|
10
|
+
export * from "./store";
|
|
11
|
+
export * from "./router";
|
|
12
|
+
export { component } from "./runtime/component";
|
|
13
|
+
export { css } from "./runtime/style";
|
|
14
|
+
export { html } from "./runtime/template-compiler";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/router.d.ts
CHANGED
|
@@ -1,25 +1,60 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Lightweight, scalable router for Custom Elements Runtime
|
|
3
3
|
* - Functional API, zero dependencies, SSR/static site compatible
|
|
4
|
-
* - Integrates with
|
|
4
|
+
* - Integrates with createStore and lib/index.ts
|
|
5
5
|
*/
|
|
6
6
|
import { type Store } from './store';
|
|
7
|
+
export interface RouteComponent {
|
|
8
|
+
new (...args: any[]): any;
|
|
9
|
+
(...args: any[]): any;
|
|
10
|
+
}
|
|
11
|
+
export interface RouteState {
|
|
12
|
+
path: string;
|
|
13
|
+
params: Record<string, string>;
|
|
14
|
+
query: Record<string, string>;
|
|
15
|
+
}
|
|
16
|
+
export type GuardResult = boolean | string | Promise<boolean | string>;
|
|
7
17
|
export interface Route {
|
|
8
18
|
path: string;
|
|
19
|
+
/**
|
|
20
|
+
* Statically available component (already imported)
|
|
21
|
+
*/
|
|
9
22
|
component?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Lazy loader that resolves to something renderable
|
|
25
|
+
*/
|
|
10
26
|
load?: () => Promise<{
|
|
11
27
|
default: string | HTMLElement | Function;
|
|
12
28
|
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Runs before matching — return false to cancel,
|
|
31
|
+
* or a string to redirect
|
|
32
|
+
*/
|
|
33
|
+
beforeEnter?: (to: RouteState, from: RouteState) => GuardResult;
|
|
34
|
+
/**
|
|
35
|
+
* Runs right before navigation commits — can cancel or redirect
|
|
36
|
+
*/
|
|
37
|
+
onEnter?: (to: RouteState, from: RouteState) => GuardResult;
|
|
38
|
+
/**
|
|
39
|
+
* Runs after navigation completes — cannot cancel
|
|
40
|
+
*/
|
|
41
|
+
afterEnter?: (to: RouteState, from: RouteState) => void;
|
|
13
42
|
}
|
|
14
43
|
export interface RouterConfig {
|
|
15
44
|
routes: Route[];
|
|
16
45
|
base?: string;
|
|
46
|
+
initialUrl?: string;
|
|
17
47
|
}
|
|
18
48
|
export interface RouteState {
|
|
19
49
|
path: string;
|
|
20
50
|
params: Record<string, string>;
|
|
21
51
|
query: Record<string, string>;
|
|
22
52
|
}
|
|
53
|
+
export declare const parseQuery: (search: string) => Record<string, string>;
|
|
54
|
+
export declare const matchRoute: (routes: Route[], path: string) => {
|
|
55
|
+
route: Route | null;
|
|
56
|
+
params: Record<string, string>;
|
|
57
|
+
};
|
|
23
58
|
/**
|
|
24
59
|
* Loads a route's component, supporting both static and async.
|
|
25
60
|
* @param route Route object
|
|
@@ -28,8 +63,8 @@ export interface RouteState {
|
|
|
28
63
|
export declare function resolveRouteComponent(route: Route): Promise<any>;
|
|
29
64
|
export declare function useRouter(config: RouterConfig): {
|
|
30
65
|
store: Store<RouteState>;
|
|
31
|
-
push: (path: string) => void
|
|
32
|
-
replace: (path: string) => void
|
|
66
|
+
push: (path: string) => Promise<void>;
|
|
67
|
+
replace: (path: string) => Promise<void>;
|
|
33
68
|
back: () => void;
|
|
34
69
|
subscribe: (listener: (state: RouteState) => void) => void;
|
|
35
70
|
matchRoute: (path: string) => {
|
|
@@ -43,10 +78,16 @@ export declare function matchRouteSSR(routes: Route[], path: string): {
|
|
|
43
78
|
route: Route | null;
|
|
44
79
|
params: Record<string, string>;
|
|
45
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Singleton router instance for global access.
|
|
83
|
+
*
|
|
84
|
+
* Define here to prevent circular dependency
|
|
85
|
+
* issue with component.
|
|
86
|
+
*/
|
|
46
87
|
export declare function initRouter(config: RouterConfig): {
|
|
47
88
|
store: Store<RouteState>;
|
|
48
|
-
push: (path: string) => void
|
|
49
|
-
replace: (path: string) => void
|
|
89
|
+
push: (path: string) => Promise<void>;
|
|
90
|
+
replace: (path: string) => Promise<void>;
|
|
50
91
|
back: () => void;
|
|
51
92
|
subscribe: (listener: (state: RouteState) => void) => void;
|
|
52
93
|
matchRoute: (path: string) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ComponentConfig, ComponentContext } from "./types";
|
|
2
|
+
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;
|
|
3
|
+
export declare function createElementClass<S extends object, C extends object, P extends object, T extends object = any>(config: ComponentConfig<S, C, P, T>): CustomElementConstructor | {
|
|
4
|
+
new (): object;
|
|
5
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComponentConfig, ComponentContext } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Handles the connected lifecycle hook.
|
|
4
|
+
*/
|
|
5
|
+
export declare function handleConnected<S extends object, C extends object, P extends object, T extends object>(cfg: ComponentConfig<S, C, P, T>, context: ComponentContext<S, C, P, T>, isMounted: boolean, setMounted: (val: boolean) => void): void;
|
|
6
|
+
/**
|
|
7
|
+
* Handles the disconnected lifecycle hook.
|
|
8
|
+
*/
|
|
9
|
+
export declare function handleDisconnected<S extends object, C extends object, P extends object, T extends object>(cfg: ComponentConfig<S, C, P, T>, context: ComponentContext<S, C, P, T>, listeners: Array<() => void>, clearListeners: () => void, clearWatchers: () => void, setTemplateLoading: (val: boolean) => void, setTemplateError: (err: Error | null) => void, setMounted: (val: boolean) => void): void;
|
|
10
|
+
/**
|
|
11
|
+
* Handles the attribute changed lifecycle hook.
|
|
12
|
+
*/
|
|
13
|
+
export declare function handleAttributeChanged<S extends object, C extends object, P extends object, T extends object>(cfg: ComponentConfig<S, C, P, T>, name: string, oldValue: string | null, newValue: string | null, context: ComponentContext<S, C, P, T>): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComponentConfig, ComponentContext } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Applies props to the component context.
|
|
4
|
+
* @param element - The custom element instance.
|
|
5
|
+
* @param cfg - The component config.
|
|
6
|
+
* @param context - The component context.
|
|
7
|
+
*/
|
|
8
|
+
export declare function applyProps<S extends object, C extends object, P extends object, T extends object>(element: HTMLElement, cfg: ComponentConfig<S, C, P, T>, context: ComponentContext<S, C, P, T>): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ComponentConfig, ComponentContext, VNode, Refs } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Renders the component output.
|
|
4
|
+
*/
|
|
5
|
+
export declare function renderComponent<S extends object, C extends object, P extends object, T extends object>(shadowRoot: ShadowRoot | null, cfg: ComponentConfig<S, C, P, T>, context: ComponentContext<S, C, P, T>, refs: Refs["refs"], setHtmlString: (html: string) => void, setLoading: (val: boolean) => void, setError: (err: Error | null) => void, applyStyle: (html: string) => void): void;
|
|
6
|
+
/**
|
|
7
|
+
* Renders VNode(s) to the shadowRoot.
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderOutput<S extends object, C extends object, P extends object, T extends object>(shadowRoot: ShadowRoot | null, output: VNode | VNode[], context: ComponentContext<S, C, P, T>, refs: Refs["refs"], setHtmlString: (html: string) => void): void;
|
|
10
|
+
/**
|
|
11
|
+
* Debounced render request.
|
|
12
|
+
*/
|
|
13
|
+
export declare function requestRender(renderFn: () => void, lastRenderTime: number, renderCount: number, setLastRenderTime: (t: number) => void, setRenderCount: (c: number) => void, renderTimeoutId: ReturnType<typeof setTimeout> | null, setRenderTimeoutId: (id: ReturnType<typeof setTimeout> | null) => void): void;
|
|
14
|
+
/**
|
|
15
|
+
* Applies styles to the shadowRoot.
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyStyle<S extends object, C extends object, P extends object, T extends object>(shadowRoot: ShadowRoot | null, cfg: ComponentConfig<S, C, P, T>, context: ComponentContext<S, C, P, T>, htmlString: string, styleSheet: CSSStyleSheet | null, setStyleSheet: (sheet: CSSStyleSheet | null) => void): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS template literal
|
|
3
|
+
*
|
|
4
|
+
* This doesn't sanitize CSS values.
|
|
5
|
+
* Runtime does that for us.
|
|
6
|
+
*
|
|
7
|
+
* @param strings
|
|
8
|
+
* @param values
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function css(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
12
|
+
/**
|
|
13
|
+
* CSS minification utility (basic)
|
|
14
|
+
*/
|
|
15
|
+
export declare function minifyCSS(css: string): string;
|
|
16
|
+
export declare function getBaseResetSheet(): CSSStyleSheet;
|
|
17
|
+
export declare function sanitizeCSS(css: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Minimal Shadow DOM reset
|
|
20
|
+
*/
|
|
21
|
+
export declare const baseReset: string;
|
|
22
|
+
/**
|
|
23
|
+
* JIT CSS implementation
|
|
24
|
+
*/
|
|
25
|
+
type CSSMap = Record<string, string>;
|
|
26
|
+
type SelectorVariantMap = Record<string, (selector: string, body: string) => string>;
|
|
27
|
+
type MediaVariantMap = Record<string, string>;
|
|
28
|
+
export declare const colors: Record<string, Record<string, string>>;
|
|
29
|
+
export declare const utilityMap: CSSMap;
|
|
30
|
+
export declare const spacing = "var(--spacing, 0.25rem)";
|
|
31
|
+
export declare const spacingProps: Record<string, string[]>;
|
|
32
|
+
export declare const selectorVariants: SelectorVariantMap;
|
|
33
|
+
export declare const mediaVariants: MediaVariantMap;
|
|
34
|
+
export declare const responsiveOrder: string[];
|
|
35
|
+
export declare function parseSpacing(className: string): string | null;
|
|
36
|
+
export declare function hexToRgb(hex: string): string;
|
|
37
|
+
export declare function parseColorClass(className: string): string | null;
|
|
38
|
+
export declare function parseOpacityModifier(className: string): {
|
|
39
|
+
base: string;
|
|
40
|
+
opacity?: number;
|
|
41
|
+
};
|
|
42
|
+
export declare function parseColorWithOpacity(className: string): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Arbitrary value parser — supports:
|
|
45
|
+
* - prop-[value]
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseArbitrary(className: string): string | null;
|
|
48
|
+
export declare function escapeClassName(name: string): string;
|
|
49
|
+
export declare function extractClassesFromHTML(html: string): string[];
|
|
50
|
+
/**
|
|
51
|
+
* JIT CSS generation with throttling and memoization.
|
|
52
|
+
* Only regenerates CSS if HTML changes and enough time has passed.
|
|
53
|
+
* Caches results for repeated HTML inputs.
|
|
54
|
+
*/
|
|
55
|
+
export declare const jitCssCache: Map<string, {
|
|
56
|
+
css: string;
|
|
57
|
+
timestamp: number;
|
|
58
|
+
}>;
|
|
59
|
+
export declare const JIT_CSS_THROTTLE_MS = 16;
|
|
60
|
+
export declare function jitCSS(html: string): string;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { VNode } from "./types";
|
|
2
|
+
export declare function h(tag: string, props?: Record<string, any>, children?: VNode[] | string, key?: string | number): VNode;
|
|
3
|
+
export declare function isAnchorBlock(v: any): boolean;
|
|
4
|
+
export declare function isElementVNode(v: any): v is VNode;
|
|
5
|
+
export declare function ensureKey(v: VNode, k: string): VNode;
|
|
6
|
+
export declare function parseProps(str: string, values?: unknown[], context?: Record<string, any>): {
|
|
7
|
+
props: Record<string, any>;
|
|
8
|
+
attrs: Record<string, any>;
|
|
9
|
+
directives: Record<string, {
|
|
10
|
+
value: string;
|
|
11
|
+
modifiers: string[];
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Internal implementation allowing an optional compile context for #model.
|
|
16
|
+
* Fixes:
|
|
17
|
+
* - Recognize interpolation markers embedded in text ("World{{1}}") and replace them.
|
|
18
|
+
* - Skip empty arrays from directives so markers don't leak as text.
|
|
19
|
+
* - Pass AnchorBlocks through (and deep-normalize their children's keys) so the renderer can mount/patch them surgically.
|
|
20
|
+
* - Do not rewrap interpolated VNodes (preserve their keys); only fill in missing keys.
|
|
21
|
+
*/
|
|
22
|
+
export declare function htmlImpl(strings: TemplateStringsArray, values: unknown[], context?: Record<string, any>): VNode | VNode[];
|
|
23
|
+
/**
|
|
24
|
+
* Default export: plain html.
|
|
25
|
+
*/
|
|
26
|
+
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): VNode | VNode[];
|
|
@@ -1,30 +1,58 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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.
|
|
2
|
+
* VDOM types
|
|
6
3
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
export interface VNode {
|
|
5
|
+
tag: string;
|
|
6
|
+
key?: string;
|
|
7
|
+
props?: {
|
|
8
|
+
key?: string;
|
|
9
|
+
props?: any;
|
|
10
|
+
attrs?: Record<string, any>;
|
|
11
|
+
directives?: Record<string, {
|
|
12
|
+
value: string;
|
|
13
|
+
modifiers: string[];
|
|
14
|
+
}>;
|
|
15
|
+
ref?: string;
|
|
16
|
+
};
|
|
17
|
+
children?: VNode[] | string;
|
|
18
|
+
}
|
|
19
|
+
export type VDomRefs = Record<string, HTMLElement | undefined>;
|
|
20
|
+
export interface AnchorBlockVNode extends VNode {
|
|
21
|
+
tag: "#anchor";
|
|
22
|
+
key: string;
|
|
23
|
+
children: VNode[];
|
|
24
|
+
_startNode?: Comment;
|
|
25
|
+
_endNode?: Comment;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Runtime types
|
|
29
|
+
*/
|
|
30
|
+
export type LifecycleKeys = "onConnected" | "onDisconnected" | "onAttributeChanged" | "onError" | "errorFallback";
|
|
31
|
+
export interface WatchOptions {
|
|
14
32
|
immediate?: boolean;
|
|
15
33
|
deep?: boolean;
|
|
16
34
|
}
|
|
17
|
-
type WatchCallback<T = any, S = any> = (newValue: T, oldValue: T, context?: S) => void;
|
|
18
|
-
|
|
35
|
+
export type WatchCallback<T = any, S = any> = (newValue: T, oldValue: T, context?: S) => void;
|
|
36
|
+
export interface WatcherState {
|
|
37
|
+
callback: WatchCallback;
|
|
38
|
+
options: WatchOptions;
|
|
39
|
+
oldValue: any;
|
|
40
|
+
}
|
|
41
|
+
export type WatchConfig<S> = {
|
|
19
42
|
[K in keyof S]?: WatchCallback<S[K]> | [WatchCallback<S[K]>, WatchOptions?];
|
|
20
43
|
} | Record<string, WatchCallback | [WatchCallback, WatchOptions?]>;
|
|
21
|
-
type InferMethods<T> = {
|
|
44
|
+
export type InferMethods<T> = {
|
|
22
45
|
[K in keyof T as K extends LifecycleKeys ? never : K]: T[K] extends Function ? T[K] : never;
|
|
23
46
|
};
|
|
24
|
-
interface Refs {
|
|
47
|
+
export interface Refs {
|
|
25
48
|
refs: Record<string, HTMLElement | undefined>;
|
|
26
49
|
}
|
|
27
|
-
export type ComponentContext<S extends object, C extends object, P extends object, T extends object = any> = S & C & P & InferMethods<T> & Refs
|
|
50
|
+
export type ComponentContext<S extends object, C extends object, P extends object, T extends object = any> = S & C & P & InferMethods<T> & Refs & {
|
|
51
|
+
requestRender?: () => void;
|
|
52
|
+
error?: Error | null;
|
|
53
|
+
hasError?: boolean;
|
|
54
|
+
isLoading?: boolean;
|
|
55
|
+
};
|
|
28
56
|
export interface ComponentConfig<S extends object, C extends object = {}, P extends object = {}, T extends object = any> {
|
|
29
57
|
state?: S;
|
|
30
58
|
computed?: {
|
|
@@ -46,18 +74,3 @@ export interface ComponentConfig<S extends object, C extends object = {}, P exte
|
|
|
46
74
|
errorFallback?: (error: Error | null, context: ComponentContext<S, C, P, T>) => string;
|
|
47
75
|
[key: string]: any;
|
|
48
76
|
}
|
|
49
|
-
/**
|
|
50
|
-
* CSS template literal
|
|
51
|
-
*
|
|
52
|
-
* This doesn't sanitize CSS values.
|
|
53
|
-
* Runtime does that for us.
|
|
54
|
-
*
|
|
55
|
-
* @param strings
|
|
56
|
-
* @param values
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
export declare function css(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
60
|
-
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;
|
|
61
|
-
export declare function createElementClass<S extends object, C extends object, P extends object, T extends object = any>(config: ComponentConfig<S, C, P, T>): CustomElementConstructor | {
|
|
62
|
-
new (): object;
|
|
63
|
-
};
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
import type { VNode, VDomRefs } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Recursively clean up refs for all descendants of a node
|
|
9
|
+
*/
|
|
10
|
+
export declare function cleanupRefs(node: Node, refs?: VDomRefs): void;
|
|
11
|
+
/**
|
|
12
|
+
* Get nested property value from object using dot notation
|
|
13
|
+
*/
|
|
14
|
+
export declare function getNestedValue(obj: any, path: string): any;
|
|
15
|
+
/**
|
|
16
|
+
* Set nested property value in object using dot notation
|
|
17
|
+
*/
|
|
18
|
+
export declare function setNestedValue(obj: any, path: string, value: any): void;
|
|
19
|
+
/**
|
|
20
|
+
* Process #model directive for two-way data binding
|
|
21
|
+
*/
|
|
22
|
+
export declare function processModelDirective(value: string, modifiers: string[], props: Record<string, any>, attrs: Record<string, any>, listeners: Record<string, EventListener>, context?: any, el?: HTMLElement): void;
|
|
23
|
+
/**
|
|
24
|
+
* Process #bind directive for attribute/property binding
|
|
25
|
+
*/
|
|
26
|
+
export declare function processBindDirective(value: string, props: Record<string, any>, attrs: Record<string, any>, context?: any): void;
|
|
27
|
+
/**
|
|
28
|
+
* Process #show directive for conditional display
|
|
29
|
+
*/
|
|
30
|
+
export declare function processShowDirective(value: string, attrs: Record<string, any>, context?: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* Process #class directive for conditional CSS classes
|
|
33
|
+
*/
|
|
34
|
+
export declare function processClassDirective(value: string, attrs: Record<string, any>, context?: any): void;
|
|
35
|
+
export declare function processStyleDirective(value: any, attrs: Record<string, any>, context?: any): void;
|
|
36
|
+
/**
|
|
37
|
+
* Process directives and return merged props, attrs, and event listeners
|
|
38
|
+
*/
|
|
39
|
+
export declare function processDirectives(directives: Record<string, {
|
|
40
|
+
value: any;
|
|
41
|
+
modifiers: string[];
|
|
42
|
+
}>, context?: any, el?: HTMLElement, vnodeAttrs?: Record<string, any>): {
|
|
43
|
+
props: Record<string, any>;
|
|
44
|
+
attrs: Record<string, any>;
|
|
45
|
+
listeners: Record<string, EventListener>;
|
|
46
|
+
};
|
|
47
|
+
export declare function assignKeysDeep(nodeOrNodes: VNode | VNode[], baseKey: string): VNode | VNode[];
|
|
48
|
+
/**
|
|
49
|
+
* Patch props on an element.
|
|
50
|
+
* Only update changed props, remove old, add new.
|
|
51
|
+
*/
|
|
52
|
+
export declare function patchProps(el: HTMLElement, oldProps: Record<string, any>, newProps: Record<string, any>, context?: any): void;
|
|
53
|
+
export declare function createElement(vnode: VNode | string, context?: any, refs?: VDomRefs): Node;
|
|
54
|
+
/**
|
|
55
|
+
* Patch children using keys for node matching.
|
|
56
|
+
*/
|
|
57
|
+
export declare function patchChildren(parent: HTMLElement, oldChildren: VNode[] | string | undefined, newChildren: VNode[] | string | undefined, context?: any, refs?: VDomRefs): void;
|
|
58
|
+
/**
|
|
59
|
+
* Patch a node using keys for node matching.
|
|
60
|
+
*/
|
|
61
|
+
export declare function patch(dom: Node, oldVNode: VNode | string | null, newVNode: VNode | string | null, context?: any, refs?: VDomRefs): Node;
|
|
62
|
+
/**
|
|
63
|
+
* Main renderer: uses patching and keys for node reuse.
|
|
64
|
+
* Never uses innerHTML. Only updates what has changed.
|
|
65
|
+
*/
|
|
66
|
+
export declare function vdomRenderer(root: ShadowRoot, vnodeOrArray: VNode | VNode[], context?: any, refs?: VDomRefs): void;
|
|
67
|
+
export declare function renderToString(vnode: VNode): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ComponentContext, WatchCallback, WatchOptions, WatcherState } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Initializes watchers for a component.
|
|
4
|
+
*/
|
|
5
|
+
export declare function initWatchers(context: ComponentContext<any, any, any, any>, watchers: Map<string, WatcherState>, watchConfig: Record<string, WatchCallback | [WatchCallback, WatchOptions]>): void;
|
|
6
|
+
/**
|
|
7
|
+
* Gets a nested value from context by path.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getNestedValue(context: any, path: string): any;
|
|
10
|
+
/**
|
|
11
|
+
* Triggers watchers when state changes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function triggerWatchers(context: ComponentContext<any, any, any, any>, watchers: Map<string, WatcherState>, path: string, newValue: any): void;
|
package/dist/store.d.ts
CHANGED
|
@@ -2,9 +2,7 @@ type Listener<T> = (state: T) => void;
|
|
|
2
2
|
export interface Store<T extends object> {
|
|
3
3
|
subscribe(listener: Listener<T>): void;
|
|
4
4
|
getState(): T;
|
|
5
|
+
setState(partial: Partial<T> | ((prev: T) => Partial<T>)): void;
|
|
5
6
|
}
|
|
6
|
-
export declare function createStore<T extends object>(initial: T):
|
|
7
|
-
subscribe: (listener: Listener<T>) => void;
|
|
8
|
-
getState: () => T;
|
|
9
|
-
};
|
|
7
|
+
export declare function createStore<T extends object>(initial: T): Store<T>;
|
|
10
8
|
export {};
|
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.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"web-components",
|
|
@@ -39,19 +39,18 @@
|
|
|
39
39
|
},
|
|
40
40
|
"main": "dist/custom-elements-runtime.cjs.js",
|
|
41
41
|
"module": "dist/custom-elements-runtime.es.js",
|
|
42
|
-
"types": "dist/
|
|
42
|
+
"types": "dist/index.d.ts",
|
|
43
43
|
"files": [
|
|
44
44
|
"dist",
|
|
45
|
-
"dist/
|
|
45
|
+
"dist/index.d.ts"
|
|
46
46
|
],
|
|
47
47
|
"exports": {
|
|
48
48
|
".": {
|
|
49
|
-
"types": "./dist/
|
|
49
|
+
"types": "./dist/index.d.ts",
|
|
50
50
|
"import": "./dist/custom-elements-runtime.es.js",
|
|
51
51
|
"require": "./dist/custom-elements-runtime.cjs.js",
|
|
52
52
|
"default": "./dist/custom-elements-runtime.umd.js"
|
|
53
|
-
}
|
|
54
|
-
"./runtime.d.ts": "./dist/runtime.d.ts"
|
|
53
|
+
}
|
|
55
54
|
},
|
|
56
55
|
"publishConfig": {
|
|
57
56
|
"access": "public"
|
package/dist/style-utils.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CSS minification utility (basic)
|
|
3
|
-
*/
|
|
4
|
-
export declare function minifyCSS(css: string): string;
|
|
5
|
-
export declare function getBaseResetSheet(): CSSStyleSheet;
|
|
6
|
-
export declare function sanitizeCSS(css: string): string;
|
|
7
|
-
/**
|
|
8
|
-
* Minimal Shadow DOM reset
|
|
9
|
-
*/
|
|
10
|
-
export declare const baseReset = "\n :host, *, ::before, ::after {\n all: isolate;\n box-sizing: border-box;\n border: 0 solid currentColor;\n margin: 0;\n padding: 0;\n font: inherit;\n vertical-align: baseline;\n background: transparent;\n color: inherit;\n -webkit-tap-highlight-color: transparent;\n }\n :host {\n display: contents;\n font: 16px/1.5 ui-sans-serif, system-ui, sans-serif;\n -webkit-text-size-adjust: 100%;\n text-size-adjust: 100%;\n }\n button, input, select, textarea {\n background: transparent;\n outline: none;\n }\n textarea { resize: vertical }\n progress { vertical-align: baseline }\n button, textarea { overflow: visible }\n img, svg, video, canvas, audio, iframe, embed, object {\n display: block;\n max-width: 100%;\n height: auto;\n }\n svg { fill: currentColor; stroke: none }\n a { text-decoration: inherit; cursor: pointer }\n button, [type=button], [type=reset], [type=submit] {\n cursor: pointer;\n appearance: button;\n background: none;\n -webkit-user-select: none;\n user-select: none;\n }\n ::-webkit-input-placeholder, ::placeholder {\n color: inherit; opacity: .5;\n }\n *:focus {\n outline: 2px solid var(--color-blue-500, #3b82f6);\n outline-offset: 2px;\n }\n ol, ul { list-style: none }\n table { border-collapse: collapse }\n sub, sup {\n font-size: .75em;\n line-height: 0;\n position: relative;\n }\n sub { bottom: -.25em }\n sup { top: -.5em }\n [disabled], [aria-disabled=true] { cursor: not-allowed }\n [hidden] { display: none }\n";
|
|
11
|
-
export declare function jitCSS(html: string): string;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { VNode } from "./vdom";
|
|
2
|
-
export declare function h(tag: string, props?: Record<string, any>, children?: VNode[] | string, key?: string | number): VNode;
|
|
3
|
-
/**
|
|
4
|
-
* Default export: plain html.
|
|
5
|
-
*/
|
|
6
|
-
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): VNode | VNode[];
|
package/dist/vdom.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
ref?: string;
|
|
18
|
-
};
|
|
19
|
-
children?: VNode[] | string;
|
|
20
|
-
}
|
|
21
|
-
export type VDomRefs = Record<string, HTMLElement | undefined>;
|
|
22
|
-
export interface AnchorBlockVNode extends VNode {
|
|
23
|
-
tag: "#anchor";
|
|
24
|
-
key: string;
|
|
25
|
-
children: VNode[];
|
|
26
|
-
_startNode?: Comment;
|
|
27
|
-
_endNode?: Comment;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Main renderer: uses patching and keys for node reuse.
|
|
31
|
-
* Never uses innerHTML. Only updates what has changed.
|
|
32
|
-
*/
|
|
33
|
-
export declare function vdomRenderer(root: ShadowRoot, vnodeOrArray: VNode | VNode[], context?: any, refs?: VDomRefs): void;
|
|
34
|
-
export declare function renderToString(vnode: VNode): string;
|