@coherent.js/core 1.0.0-beta.3 → 1.0.0-beta.6

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/types/index.d.ts CHANGED
@@ -5,6 +5,9 @@
5
5
  * @version 1.0.0-beta.1
6
6
  */
7
7
 
8
+ // Re-export strict element types
9
+ export * from './elements';
10
+
8
11
  // ============================================================================
9
12
  // Basic Types
10
13
  // ============================================================================
@@ -12,9 +15,12 @@
12
15
  /** Primitive values that can be rendered as HTML */
13
16
  export type Primitive = string | number | boolean | null | undefined;
14
17
 
18
+ /** Allow objects and functions in attributes */
19
+ export type AttributeValue = Primitive | object;
20
+
15
21
  /** HTML attributes object */
16
22
  export interface HTMLAttributes {
17
- [key: string]: Primitive | (() => Primitive);
23
+ [key: string]: AttributeValue;
18
24
  className?: string;
19
25
  class?: string;
20
26
  id?: string;
@@ -47,15 +53,151 @@ export interface ElementProps extends HTMLAttributes {
47
53
  text?: Primitive;
48
54
  }
49
55
 
50
- /** A Coherent.js HTML element definition */
56
+ /**
57
+ * Permissive element type - allows any tag name and any attributes.
58
+ * For strict type checking with per-element attributes, use StrictCoherentElement.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * // Permissive - accepts any attributes on any element
63
+ * const element: CoherentElement = {
64
+ * div: { checked: true } // No error (but incorrect HTML)
65
+ * };
66
+ *
67
+ * // For strict checking, use StrictCoherentElement instead
68
+ * import { StrictCoherentElement } from '@coherent.js/core';
69
+ * const strictElement: StrictCoherentElement = {
70
+ * div: { checked: true } // Type error! checked not valid on div
71
+ * };
72
+ * ```
73
+ *
74
+ * @see StrictCoherentElement for strict per-element attribute validation
75
+ */
51
76
  export interface CoherentElement {
52
- [tagName: string]: ElementProps | string;
77
+ [tagName: string]: ElementProps | string | undefined;
78
+
79
+ // Common HTML Elements
80
+ a?: ElementProps | string;
81
+ abbr?: ElementProps | string;
82
+ address?: ElementProps | string;
83
+ area?: ElementProps | string;
84
+ article?: ElementProps | string;
85
+ aside?: ElementProps | string;
86
+ audio?: ElementProps | string;
87
+ b?: ElementProps | string;
88
+ base?: ElementProps | string;
89
+ bdi?: ElementProps | string;
90
+ bdo?: ElementProps | string;
91
+ blockquote?: ElementProps | string;
92
+ body?: ElementProps | string;
93
+ br?: ElementProps | string;
94
+ button?: ElementProps | string;
95
+ canvas?: ElementProps | string;
96
+ caption?: ElementProps | string;
97
+ cite?: ElementProps | string;
98
+ code?: ElementProps | string;
99
+ col?: ElementProps | string;
100
+ colgroup?: ElementProps | string;
101
+ data?: ElementProps | string;
102
+ datalist?: ElementProps | string;
103
+ dd?: ElementProps | string;
104
+ del?: ElementProps | string;
105
+ details?: ElementProps | string;
106
+ dfn?: ElementProps | string;
107
+ dialog?: ElementProps | string;
108
+ div?: ElementProps | string;
109
+ dl?: ElementProps | string;
110
+ dt?: ElementProps | string;
111
+ em?: ElementProps | string;
112
+ embed?: ElementProps | string;
113
+ fieldset?: ElementProps | string;
114
+ figcaption?: ElementProps | string;
115
+ figure?: ElementProps | string;
116
+ footer?: ElementProps | string;
117
+ form?: ElementProps | string;
118
+ h1?: ElementProps | string;
119
+ h2?: ElementProps | string;
120
+ h3?: ElementProps | string;
121
+ h4?: ElementProps | string;
122
+ h5?: ElementProps | string;
123
+ h6?: ElementProps | string;
124
+ head?: ElementProps | string;
125
+ header?: ElementProps | string;
126
+ hgroup?: ElementProps | string;
127
+ hr?: ElementProps | string;
128
+ html?: ElementProps | string;
129
+ i?: ElementProps | string;
130
+ iframe?: ElementProps | string;
131
+ img?: ElementProps | string;
132
+ input?: ElementProps | string;
133
+ ins?: ElementProps | string;
134
+ kbd?: ElementProps | string;
135
+ label?: ElementProps | string;
136
+ legend?: ElementProps | string;
137
+ li?: ElementProps | string;
138
+ link?: ElementProps | string;
139
+ main?: ElementProps | string;
140
+ map?: ElementProps | string;
141
+ mark?: ElementProps | string;
142
+ menu?: ElementProps | string;
143
+ meta?: ElementProps | string;
144
+ meter?: ElementProps | string;
145
+ nav?: ElementProps | string;
146
+ noscript?: ElementProps | string;
147
+ object?: ElementProps | string;
148
+ ol?: ElementProps | string;
149
+ optgroup?: ElementProps | string;
150
+ option?: ElementProps | string;
151
+ output?: ElementProps | string;
152
+ p?: ElementProps | string;
153
+ picture?: ElementProps | string;
154
+ pre?: ElementProps | string;
155
+ progress?: ElementProps | string;
156
+ q?: ElementProps | string;
157
+ rp?: ElementProps | string;
158
+ rt?: ElementProps | string;
159
+ ruby?: ElementProps | string;
160
+ s?: ElementProps | string;
161
+ samp?: ElementProps | string;
162
+ script?: ElementProps | string;
163
+ section?: ElementProps | string;
164
+ select?: ElementProps | string;
165
+ slot?: ElementProps | string;
166
+ small?: ElementProps | string;
167
+ source?: ElementProps | string;
168
+ span?: ElementProps | string;
169
+ strong?: ElementProps | string;
170
+ style?: ElementProps | string;
171
+ sub?: ElementProps | string;
172
+ summary?: ElementProps | string;
173
+ sup?: ElementProps | string;
174
+ table?: ElementProps | string;
175
+ tbody?: ElementProps | string;
176
+ td?: ElementProps | string;
177
+ template?: ElementProps | string;
178
+ textarea?: ElementProps | string;
179
+ tfoot?: ElementProps | string;
180
+ th?: ElementProps | string;
181
+ thead?: ElementProps | string;
182
+ time?: ElementProps | string;
183
+ title?: ElementProps | string;
184
+ tr?: ElementProps | string;
185
+ track?: ElementProps | string;
186
+ u?: ElementProps | string;
187
+ ul?: ElementProps | string;
188
+ var?: ElementProps | string;
189
+ video?: ElementProps | string;
190
+ wbr?: ElementProps | string;
53
191
  }
54
192
 
55
- /** Valid nodes that can be rendered */
193
+ /**
194
+ * Valid nodes that can be rendered.
195
+ * Accepts both permissive CoherentElement and strict StrictCoherentElement.
196
+ */
56
197
  export type CoherentNode =
57
198
  | Primitive
58
199
  | CoherentElement
200
+ | StrictCoherentElement
59
201
  | CoherentNode[]
60
202
  | CoherentComponent
61
203
  | ContextProvider
@@ -218,11 +360,11 @@ export interface StateUtilities<S extends ComponentState = ComponentState> {
218
360
  }
219
361
 
220
362
  /** Enhanced props with state for withState HOC */
221
- export interface WithStateProps<P extends ComponentProps, S extends ComponentState> extends P {
363
+ export type WithStateProps<P extends ComponentProps, S extends ComponentState> = P & {
222
364
  state: S;
223
365
  setState: (newState: Partial<S> | ((state: S) => Partial<S>)) => void;
224
366
  stateUtils: StateUtilities<S>;
225
- }
367
+ };
226
368
 
227
369
  // ============================================================================
228
370
  // Higher-Order Components (HOCs)
@@ -256,7 +398,7 @@ export interface MemoOptions {
256
398
  }
257
399
 
258
400
  /** Memoized function with utilities */
259
- export interface MemoizedFunction<T extends (...args: any[]) => any> extends T {
401
+ export type MemoizedFunction<T extends (...args: any[]) => any> = T & {
260
402
  cache: Map<string, any>;
261
403
  clear(): void;
262
404
  delete(key: string): boolean;
@@ -265,7 +407,7 @@ export interface MemoizedFunction<T extends (...args: any[]) => any> extends T {
265
407
  refresh(...args: Parameters<T>): ReturnType<T>;
266
408
  stats?(): { hits: number; misses: number; evictions: number };
267
409
  resetStats?(): void;
268
- }
410
+ };
269
411
 
270
412
  /** Props transformation function */
271
413
  export type PropsTransform<P, T> = (props: P, state?: ComponentState, context?: ComponentContext) => T | Promise<T>;
@@ -370,14 +512,57 @@ export interface PerformanceMetrics {
370
512
  // Core Functions
371
513
  // ============================================================================
372
514
 
373
- /** Render a Coherent node to HTML string */
374
- export function render(obj: CoherentNode): string;
515
+ /** Render options for `render(component, options)` */
516
+ export interface RenderOptions {
517
+ enableCache?: boolean;
518
+ enableMonitoring?: boolean;
519
+ minify?: boolean;
520
+ maxDepth?: number;
521
+ cacheSize?: number;
522
+ cacheTTL?: number;
523
+ scoped?: boolean;
524
+ encapsulate?: boolean;
525
+ }
526
+
527
+ /** Render a Coherent node to an HTML string */
528
+ export function render(component: CoherentNode, options?: RenderOptions): string;
375
529
 
376
- /** Alias for render */
377
- export function render(obj: CoherentNode): string;
530
+ export interface RenderUtilityOptions {
531
+ enablePerformanceMonitoring?: boolean;
532
+ template?: string;
533
+ }
534
+
535
+ export function renderWithMonitoring(component: CoherentNode, options?: RenderUtilityOptions): string;
536
+ export function renderWithTemplate(component: CoherentNode, options?: RenderUtilityOptions): string;
537
+ export function renderComponentFactory(
538
+ componentFactory: (...args: any[]) => CoherentNode | Promise<CoherentNode>,
539
+ factoryArgs: any[],
540
+ options?: RenderUtilityOptions
541
+ ): Promise<string>;
542
+ export function isCoherentComponent(obj: unknown): boolean;
543
+ export function createErrorResponse(
544
+ error: Error,
545
+ context?: string
546
+ ): {
547
+ error: string;
548
+ message: string;
549
+ context: string;
550
+ timestamp: string;
551
+ };
378
552
 
379
- /** Synchronous version of render */
380
- export function renderSync(obj: CoherentNode): string;
553
+ export function isPeerDependencyAvailable(packageName: string): boolean;
554
+ export function importPeerDependency(packageName: string, integrationName: string): Promise<any>;
555
+ export function createLazyIntegration(
556
+ packageName: string,
557
+ integrationName: string,
558
+ createIntegration: (module: any) => (...args: any[]) => any
559
+ ): (...args: any[]) => Promise<any>;
560
+ export function checkPeerDependencies(
561
+ dependencies: Array<{ package: string; integration: string }>
562
+ ): Record<string, boolean>;
563
+
564
+ export function hasChildren(component: unknown): boolean;
565
+ export function normalizeChildren(children: unknown): unknown[];
381
566
 
382
567
  /** Escape HTML characters in text */
383
568
  export function escapeHtml(text: string): string;
@@ -564,55 +749,6 @@ export class VDOMDiffer {
564
749
  patch(element: HTMLElement, patches: VDOMPatch[]): void;
565
750
  }
566
751
 
567
- // ============================================================================
568
- // Advanced Rendering Functions (Additional)
569
- // ============================================================================
570
-
571
- /** Render options */
572
- export interface RenderOptions {
573
- cache?: boolean;
574
- pretty?: boolean;
575
- minify?: boolean;
576
- streaming?: boolean;
577
- chunkSize?: number;
578
- }
579
-
580
- /** Render component to string */
581
- export function render(component: CoherentNode, options?: RenderOptions): string;
582
-
583
- /** Render multiple components in batch */
584
- export function renderBatch(components: CoherentNode[], options?: RenderOptions): string[];
585
-
586
- /** Render to chunks generator */
587
- export function renderToChunks(component: CoherentNode, options?: RenderOptions): Generator<string, void, unknown>;
588
-
589
- /** Render to stream async generator */
590
- export function renderToStream(component: CoherentNode, options?: RenderOptions): AsyncGenerator<string, void, unknown>;
591
-
592
- /** Get rendering cache */
593
- export function getCache(): Map<string, any>;
594
-
595
- /** Reset rendering cache */
596
- export function resetCache(): void;
597
-
598
- /** Get rendering statistics */
599
- export function getRenderingStats(): {
600
- totalRenders: number;
601
- cacheHits: number;
602
- cacheMisses: number;
603
- averageRenderTime: number;
604
- };
605
-
606
- /** Precompile component for faster rendering */
607
- export function precompileComponent(component: CoherentNode, options?: RenderOptions): any;
608
-
609
- /** Render with timing information */
610
- export function renderWithTiming(component: CoherentNode, options?: RenderOptions): {
611
- html: string;
612
- time: number;
613
- metrics: Record<string, any>;
614
- };
615
-
616
752
  // ============================================================================
617
753
  // CSS Management (Additional)
618
754
  // ============================================================================
@@ -720,8 +856,6 @@ export const componentUtils: ComponentUtils;
720
856
  /** Default export with all core functionality */
721
857
  declare const coherent: {
722
858
  render: typeof render;
723
- render: typeof render;
724
- renderSync: typeof renderSync;
725
859
  withState: typeof withState;
726
860
  memo: typeof memo;
727
861
  validateComponent: typeof validateComponent;