@jasonshimmy/custom-elements-runtime 0.3.0 → 0.3.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,138 @@
1
+ import type { VNode } from "./runtime/types";
2
+ /**
3
+ * Conditional rendering with negated condition (opposite of when)
4
+ * @param cond - Boolean condition to negate
5
+ * @param children - Content to render when condition is false
6
+ */
7
+ export declare function unless(cond: boolean, children: VNode | VNode[]): VNode;
8
+ /**
9
+ * Render content only if array/collection is empty
10
+ * @param collection - Array or collection to check
11
+ * @param children - Content to render when empty
12
+ */
13
+ export declare function whenEmpty(collection: any[] | null | undefined, children: VNode | VNode[]): VNode;
14
+ /**
15
+ * Render content only if array/collection has items
16
+ * @param collection - Array or collection to check
17
+ * @param children - Content to render when not empty
18
+ */
19
+ export declare function whenNotEmpty(collection: any[] | null | undefined, children: VNode | VNode[]): VNode;
20
+ /**
21
+ * Enhanced each with filtering capability
22
+ * @param list - Array to iterate over
23
+ * @param predicate - Filter function (optional)
24
+ * @param render - Render function for each item
25
+ */
26
+ export declare function eachWhere<T>(list: T[], predicate: (item: T, index: number) => boolean, render: (item: T, index: number, filteredIndex: number) => VNode | VNode[]): VNode[];
27
+ /**
28
+ * Render different content based on array length
29
+ * @param list - Array to check
30
+ * @param cases - Object with length-based cases
31
+ */
32
+ export declare function switchOnLength<T>(list: T[], cases: {
33
+ empty?: VNode | VNode[];
34
+ one?: (item: T) => VNode | VNode[];
35
+ many?: (items: T[]) => VNode | VNode[];
36
+ exactly?: {
37
+ [count: number]: (items: T[]) => VNode | VNode[];
38
+ };
39
+ }): VNode;
40
+ /**
41
+ * Group array items and render each group
42
+ * @param list - Array to group
43
+ * @param groupBy - Function to determine group key
44
+ * @param renderGroup - Function to render each group
45
+ */
46
+ export declare function eachGroup<T, K extends string | number>(list: T[], groupBy: (item: T) => K, renderGroup: (groupKey: K, items: T[], groupIndex: number) => VNode | VNode[]): VNode[];
47
+ /**
48
+ * Render with pagination/chunking
49
+ * @param list - Array to chunk
50
+ * @param pageSize - Items per page/chunk
51
+ * @param currentPage - Current page (0-based)
52
+ * @param render - Render function for visible items
53
+ */
54
+ export declare function eachPage<T>(list: T[], pageSize: number, currentPage: number, render: (item: T, index: number, pageIndex: number) => VNode | VNode[]): VNode[];
55
+ /**
56
+ * Render content based on Promise state
57
+ * @param promiseState - Object with loading, data, error states
58
+ * @param cases - Render functions for each state
59
+ */
60
+ export declare function switchOnPromise<T, E = Error>(promiseState: {
61
+ loading?: boolean;
62
+ data?: T;
63
+ error?: E;
64
+ }, cases: {
65
+ loading?: VNode | VNode[];
66
+ success?: (data: T) => VNode | VNode[];
67
+ error?: (error: E) => VNode | VNode[];
68
+ idle?: VNode | VNode[];
69
+ }): VNode;
70
+ /**
71
+ * Render content based on screen size/media query
72
+ * @param mediaQuery - CSS media query string
73
+ * @param children - Content to render when media query matches
74
+ */
75
+ export declare function whenMedia(mediaQuery: string, children: VNode | VNode[]): VNode;
76
+ /**
77
+ * Media variants matching those in style.ts
78
+ */
79
+ export declare const mediaVariants: {
80
+ readonly sm: "(min-width:640px)";
81
+ readonly md: "(min-width:768px)";
82
+ readonly lg: "(min-width:1024px)";
83
+ readonly xl: "(min-width:1280px)";
84
+ readonly "2xl": "(min-width:1536px)";
85
+ readonly dark: "(prefers-color-scheme: dark)";
86
+ };
87
+ /**
88
+ * Responsive order matching style.ts
89
+ */
90
+ export declare const responsiveOrder: readonly ["sm", "md", "lg", "xl", "2xl"];
91
+ /**
92
+ * Individual responsive directives matching the style.ts breakpoint system
93
+ */
94
+ export declare const responsive: {
95
+ readonly sm: (children: VNode | VNode[]) => VNode;
96
+ readonly md: (children: VNode | VNode[]) => VNode;
97
+ readonly lg: (children: VNode | VNode[]) => VNode;
98
+ readonly xl: (children: VNode | VNode[]) => VNode;
99
+ readonly "2xl": (children: VNode | VNode[]) => VNode;
100
+ readonly dark: (children: VNode | VNode[]) => VNode;
101
+ readonly light: (children: VNode | VNode[]) => VNode;
102
+ readonly touch: (children: VNode | VNode[]) => VNode;
103
+ readonly mouse: (children: VNode | VNode[]) => VNode;
104
+ readonly reducedMotion: (children: VNode | VNode[]) => VNode;
105
+ readonly highContrast: (children: VNode | VNode[]) => VNode;
106
+ readonly portrait: (children: VNode | VNode[]) => VNode;
107
+ readonly landscape: (children: VNode | VNode[]) => VNode;
108
+ };
109
+ /**
110
+ * Advanced responsive directive that matches the style.ts multi-variant processing
111
+ * Allows chaining responsive and dark mode conditions like in CSS classes
112
+ * @param variants - Array of variant keys (e.g., ['dark', 'lg'])
113
+ * @param children - Content to render when all variants match
114
+ */
115
+ export declare function whenVariants(variants: Array<keyof typeof mediaVariants | 'light'>, children: VNode | VNode[]): VNode;
116
+ /**
117
+ * Responsive switch directive - render different content for different breakpoints
118
+ * Mirrors the responsive behavior from the style system
119
+ * @param content - Object with breakpoint keys and corresponding content
120
+ */
121
+ export declare function responsiveSwitch(content: {
122
+ base?: VNode | VNode[];
123
+ sm?: VNode | VNode[];
124
+ md?: VNode | VNode[];
125
+ lg?: VNode | VNode[];
126
+ xl?: VNode | VNode[];
127
+ "2xl"?: VNode | VNode[];
128
+ }): VNode[];
129
+ /**
130
+ * Enhanced match directive with more fluent API
131
+ * @param value - Value to match against
132
+ */
133
+ export declare function switchOn<T>(value: T): {
134
+ case(matcher: T | ((val: T) => boolean), content: VNode | VNode[]): /*elided*/ any;
135
+ when(predicate: (val: T) => boolean, content: VNode | VNode[]): /*elided*/ any;
136
+ otherwise(content: VNode | VNode[]): /*elided*/ any;
137
+ done(): VNode;
138
+ };
@@ -9,3 +9,8 @@ export declare function match(): {
9
9
  otherwise(content: VNode | VNode[]): /*elided*/ any;
10
10
  done(): VNode[];
11
11
  };
12
+ /**
13
+ * Create a stable anchor block with consistent boundaries.
14
+ * Always has start/end boundaries.
15
+ */
16
+ export declare function anchorBlock(children: VNode | VNode[] | null | undefined, anchorKey: string): VNode;
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
  export * from "./runtime/types";
8
8
  export * from "./directives";
9
+ export * from "./directive-enhancements";
9
10
  export * from "./event-bus";
10
11
  export * from "./store";
11
12
  export * from "./router";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Development-only logging utilities
3
+ * These are stripped out in production builds via bundler configuration
4
+ */
5
+ /**
6
+ * Log error only in development mode
7
+ */
8
+ export declare function devError(message: string, ...args: any[]): void;
9
+ /**
10
+ * Log warning only in development mode
11
+ */
12
+ export declare function devWarn(message: string, ...args: any[]): void;
13
+ /**
14
+ * Log info only in development mode
15
+ */
16
+ export declare function devLog(message: string, ...args: any[]): void;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Update Scheduler for batching DOM updates
3
+ * Prevents excessive re-renders and improves performance
4
+ */
5
+ declare class UpdateScheduler {
6
+ private pendingUpdates;
7
+ private isFlushScheduled;
8
+ /**
9
+ * Schedule an update to be executed in the next microtask
10
+ * Uses component identity to deduplicate multiple render requests for the same component
11
+ */
12
+ schedule(update: () => void, componentId?: string): void;
13
+ /**
14
+ * Execute all pending updates
15
+ */
16
+ private flush;
17
+ /**
18
+ * Get the number of pending updates
19
+ */
20
+ get pendingCount(): number;
21
+ }
22
+ export declare const updateScheduler: UpdateScheduler;
23
+ /**
24
+ * Schedule a DOM update to be batched with optional component identity
25
+ */
26
+ export declare function scheduleDOMUpdate(update: () => void, componentId?: string): void;
27
+ export {};
@@ -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,15 +39,8 @@ 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;
43
- /**
44
- * Process :class directive for conditional CSS classes
45
- * @param value
46
- * @param attrs
47
- * @param context
48
- * @returns
49
- */
50
- export declare function processClassDirective(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;
51
44
  /**
52
45
  * Process :style directive for dynamic inline styles
53
46
  * @param value
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": "0.3.1",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "web-components",