@jasonshimmy/custom-elements-runtime 0.3.0 → 1.0.0

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,30 @@
1
+ /**
2
+ * Secure expression evaluator to replace unsafe Function() constructor
3
+ * Provides AST-based validation and caching for performance
4
+ */
5
+ /**
6
+ * Secure expression evaluator with caching and AST validation
7
+ */
8
+ declare class SecureExpressionEvaluator {
9
+ private static cache;
10
+ private static maxCacheSize;
11
+ private static dangerousPatterns;
12
+ static evaluate(expression: string, context: any): any;
13
+ private static createEvaluator;
14
+ private static hasDangerousPatterns;
15
+ private static createSafeEvaluator;
16
+ private static createObjectEvaluator;
17
+ private static parseObjectProperties;
18
+ private static createSimpleEvaluator;
19
+ /**
20
+ * Evaluate a very small, safe expression grammar without using eval/Function.
21
+ * Supports: numbers, string literals, true/false, null, arrays, unary !,
22
+ * arithmetic (+ - * / %), comparisons, logical && and ||, parentheses, and ternary `a ? b : c`.
23
+ */
24
+ private static evaluateBasicExpression;
25
+ private static tokenize;
26
+ private static evaluateSimpleValue;
27
+ static clearCache(): void;
28
+ static getCacheSize(): number;
29
+ }
30
+ export { SecureExpressionEvaluator };
@@ -23,6 +23,10 @@ export declare function parseProps(str: string, values?: unknown[], context?: Re
23
23
  * - Do not rewrap interpolated VNodes (preserve their keys); only fill in missing keys.
24
24
  */
25
25
  export declare function htmlImpl(strings: TemplateStringsArray, values: unknown[], context?: Record<string, any>): VNode | VNode[];
26
+ /**
27
+ * Clear the template compile cache (useful for tests)
28
+ */
29
+ export declare function clearTemplateCompileCache(): void;
26
30
  /**
27
31
  * Default export: plain html.
28
32
  */
@@ -14,6 +14,7 @@ export interface VNode {
14
14
  arg?: string;
15
15
  }>;
16
16
  ref?: string;
17
+ reactiveRef?: any;
17
18
  /** Compiler-provided hint: whether this VNode represents a custom element (contains a dash) */
18
19
  isCustomElement?: boolean;
19
20
  };
@@ -30,7 +31,7 @@ export interface AnchorBlockVNode extends VNode {
30
31
  /**
31
32
  * Runtime types
32
33
  */
33
- export type LifecycleKeys = "onConnected" | "onDisconnected" | "onAttributeChanged" | "onError" | "errorFallback";
34
+ export type LifecycleKeys = "onConnected" | "onDisconnected" | "onAttributeChanged" | "onError";
34
35
  export interface WatchOptions {
35
36
  immediate?: boolean;
36
37
  deep?: boolean;
@@ -64,24 +65,15 @@ export type ComponentContext<S extends object, C extends object, P extends objec
64
65
  emit: <D = any>(eventName: string, detail?: D, options?: CustomEventInit) => boolean;
65
66
  };
66
67
  export type ComponentConfig<S extends object, C extends object = {}, P extends object = {}, T extends object = {}> = {
67
- state?: S;
68
- computed?: {
69
- [K in keyof C]: (context: ComponentContext<S, C, P, T>) => C[K];
70
- };
71
68
  props?: Record<string, {
72
69
  type: StringConstructor | NumberConstructor | BooleanConstructor | FunctionConstructor;
73
70
  default?: string | number | boolean;
74
71
  }>;
75
- watch?: WatchConfig<ComponentContext<S, C, P, T>>;
76
- style?: string | ((context: ComponentContext<S, C, P, T>) => string);
77
72
  render: (context: ComponentContext<S, C, P, T>) => VNode | VNode[] | Promise<VNode | VNode[]>;
78
- loadingTemplate?: (context: ComponentContext<S, C, P, T>) => VNode | VNode[];
79
- errorTemplate?: (error: Error, context: ComponentContext<S, C, P, T>) => VNode | VNode[];
80
73
  onConnected?: (context: ComponentContext<S, C, P, T>) => void;
81
74
  onDisconnected?: (context: ComponentContext<S, C, P, T>) => void;
82
75
  onAttributeChanged?: (name: string, oldValue: string | null, newValue: string | null, context: ComponentContext<S, C, P, T>) => void;
83
76
  onError?: (error: Error | null, context: ComponentContext<S, C, P, T>) => void;
84
- errorFallback?: (error: Error | null, context: ComponentContext<S, C, P, T>) => string;
85
77
  } & {
86
78
  [K in keyof T as K extends LifecycleKeys ? never : K]: T[K] extends Function ? T[K] : never;
87
79
  };
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { VNode, VDomRefs } from "./types";
7
7
  /**
8
- * Recursively clean up refs for all descendants of a node
8
+ * Recursively clean up refs and event listeners for all descendants of a node
9
9
  * @param node The node to clean up.
10
10
  * @param refs The refs to clean up.
11
11
  * @returns
@@ -22,7 +22,7 @@ export declare function cleanupRefs(node: Node, refs?: VDomRefs): void;
22
22
  * @param el
23
23
  * @returns
24
24
  */
25
- export declare function processModelDirective(value: string, modifiers: string[], props: Record<string, any>, attrs: Record<string, any>, listeners: Record<string, EventListener>, context?: any, el?: HTMLElement, arg?: string): void;
25
+ export declare function processModelDirective(value: string | any, modifiers: string[], props: Record<string, any>, attrs: Record<string, any>, listeners: Record<string, EventListener>, context?: any, el?: HTMLElement, arg?: string): void;
26
26
  /**
27
27
  * Process :bind directive for attribute/property binding
28
28
  * @param value
@@ -31,7 +31,7 @@ export declare function processModelDirective(value: string, modifiers: string[]
31
31
  * @param context
32
32
  * @returns
33
33
  */
34
- export declare function processBindDirective(value: string, props: Record<string, any>, attrs: Record<string, any>, context?: any): void;
34
+ export declare function processBindDirective(value: any, props: Record<string, any>, attrs: Record<string, any>, context?: any): void;
35
35
  /**
36
36
  * Process :show directive for conditional display
37
37
  * @param value
@@ -39,23 +39,24 @@ export declare function processBindDirective(value: string, props: Record<string
39
39
  * @param context
40
40
  * @returns
41
41
  */
42
- export declare function processShowDirective(value: string, attrs: Record<string, any>, context?: any): void;
42
+ export declare function processShowDirective(value: any, attrs: Record<string, any>, context?: any): void;
43
+ export declare function processClassDirective(value: any, attrs: Record<string, any>, context?: any): void;
43
44
  /**
44
- * Process :class directive for conditional CSS classes
45
+ * Process :style directive for dynamic inline styles
45
46
  * @param value
46
47
  * @param attrs
47
48
  * @param context
48
49
  * @returns
49
50
  */
50
- export declare function processClassDirective(value: string, attrs: Record<string, any>, context?: any): void;
51
+ export declare function processStyleDirective(value: any, attrs: Record<string, any>, context?: any): void;
51
52
  /**
52
- * Process :style directive for dynamic inline styles
53
+ * Process :ref directive for element references
53
54
  * @param value
54
- * @param attrs
55
+ * @param props
55
56
  * @param context
56
57
  * @returns
57
58
  */
58
- export declare function processStyleDirective(value: any, attrs: Record<string, any>, context?: any): void;
59
+ export declare function processRefDirective(value: any, props: Record<string, any>, context?: any): void;
59
60
  /**
60
61
  * Process directives and return merged props, attrs, and event listeners
61
62
  * @param directives
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.3.0",
4
+ "version": "1.0.0",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "web-components",