@coherent.js/core 1.0.0-rc.5 → 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.
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@coherent.js/core",
3
- "version": "1.0.0-rc.5",
3
+ "version": "1.0.0",
4
4
  "description": "Core runtime for Coherent.js (SSR framework).",
5
5
  "type": "module",
6
- "main": "dist/index.cjs",
6
+ "main": "dist/index.js",
7
7
  "module": "dist/index.js",
8
8
  "types": "./types/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./types/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
12
+ "default": "./dist/index.js"
14
13
  }
15
14
  },
16
15
  "files": [
@@ -20,7 +19,7 @@
20
19
  "LICENSE"
21
20
  ],
22
21
  "engines": {
23
- "node": ">=22.0.0"
22
+ "node": ">=22.12.0"
24
23
  },
25
24
  "license": "MIT",
26
25
  "repository": {
package/types/index.d.ts CHANGED
@@ -595,8 +595,44 @@ export function evaluateLazy<T>(obj: T, ...args: any[]): T;
595
595
  // Component System Classes and Functions
596
596
  // ============================================================================
597
597
 
598
- /** Create a component instance */
599
- export function createComponent(definition: ComponentDefinition | CoherentComponent): Component;
598
+ /** Stateful component class backing createComponent() */
599
+ export class Component implements ComponentInstance {
600
+ constructor(definition?: ComponentDefinition);
601
+
602
+ name: string;
603
+ props: ComponentProps;
604
+ state: ComponentStateManager;
605
+ children: ComponentInstance[];
606
+ parent: ComponentInstance | null;
607
+ rendered: CoherentNode | null;
608
+ isMounted: boolean;
609
+ isDestroyed: boolean;
610
+ definition: ComponentDefinition;
611
+ hooks: Required<ComponentLifecycleHooks>;
612
+ methods: ComponentMethods;
613
+ computed: ComputedProperties;
614
+ computedCache: Map<string, any>;
615
+ watchers: ComponentWatchers;
616
+
617
+ render(props?: ComponentProps): CoherentNode;
618
+ mount(): ComponentInstance;
619
+ update(): ComponentInstance;
620
+ destroy(): ComponentInstance;
621
+ clone(overrides?: Partial<ComponentDefinition>): ComponentInstance;
622
+ getMetadata(): ComponentMetadata;
623
+ callHook(hookName: keyof ComponentLifecycleHooks, ...args: any[]): any;
624
+ handleError(error: Error, context?: string): void;
625
+ }
626
+
627
+ /**
628
+ * Create a component.
629
+ *
630
+ * The result is callable -- `render(Counter({ count: 2 }))` -- and also carries
631
+ * the full Component instance API (`render`, `mount`, `state`, ...).
632
+ */
633
+ export function createComponent<P extends ComponentProps = ComponentProps>(
634
+ definition: ComponentDefinition | CoherentComponent
635
+ ): CoherentComponent<P> & ComponentInstance;
600
636
 
601
637
  /** Define a component factory */
602
638
  export function defineComponent<P extends ComponentProps>(
@@ -615,6 +651,29 @@ export function getComponent<P extends ComponentProps>(name: string): CoherentCo
615
651
  /** Get all registered components */
616
652
  export function getRegisteredComponents(): Map<string, CoherentComponent>;
617
653
 
654
+ /** Create a higher-order component */
655
+ export function createHOC<P extends ComponentProps = ComponentProps>(
656
+ enhancer: (component: CoherentComponent<P>, props: P) => CoherentNode
657
+ ): (component: CoherentComponent<P>) => CoherentComponent<P>;
658
+
659
+ /**
660
+ * Options for memoComponent().
661
+ *
662
+ * Distinct from MemoOptions: memoComponent compares props and state rather
663
+ * than raw memo arguments.
664
+ */
665
+ export interface MemoComponentOptions<P extends ComponentProps = ComponentProps> {
666
+ propsEqual?: (a: P, b: P) => boolean;
667
+ stateEqual?: (a: ComponentState, b: ComponentState) => boolean;
668
+ name?: string;
669
+ }
670
+
671
+ /** Memoize a component */
672
+ export function memoComponent<P extends ComponentProps = ComponentProps>(
673
+ component: CoherentComponent<P>,
674
+ options?: MemoComponentOptions<P>
675
+ ): MemoizedFunction<CoherentComponent<P>>;
676
+
618
677
  // ============================================================================
619
678
  // State Management Functions
620
679
  // ============================================================================
@@ -649,6 +708,22 @@ export interface VDOMPatch {
649
708
  // ============================================================================
650
709
 
651
710
  /** Global performance monitor instance */
711
+ /** Performance monitor surface, as implemented by performance/monitor.js */
712
+ export interface PerformanceMonitor {
713
+ startRender(componentName?: string): string;
714
+ endRender(renderId: string): number;
715
+ recordMetric(name: string, value: number, tags?: Record<string, any>): void;
716
+ addMetric(name: string, value: number, tags?: Record<string, any>): void;
717
+ measure<T>(name: string, fn: () => T): T;
718
+ measureAsync<T>(name: string, fn: () => Promise<T>): Promise<T>;
719
+ addAlertRule(rule: Record<string, any>): void;
720
+ generateReport(): Record<string, any>;
721
+ getStats(): Record<string, any>;
722
+ reset(): void;
723
+ start(): void;
724
+ stop(): void;
725
+ }
726
+
652
727
  export const performanceMonitor: PerformanceMonitor;
653
728
 
654
729
  // ============================================================================
@@ -673,6 +748,12 @@ export interface CacheManager {
673
748
  prune(): void;
674
749
  }
675
750
 
751
+ /** Shared cache manager instance */
752
+ export const cacheManager: CacheManager;
753
+
754
+ /** Create a cache manager */
755
+ export function createCacheManager(options?: CacheManagerOptions): CacheManager;
756
+
676
757
  // ============================================================================
677
758
  // Bundle Optimization (Additional)
678
759
  // ============================================================================
@@ -692,6 +773,31 @@ export class ComponentCache {
692
773
  /** Create component cache */
693
774
  export function createComponentCache(options?: CacheManagerOptions): ComponentCache;
694
775
 
776
+ // ============================================================================
777
+ // HTML Utilities
778
+ // ============================================================================
779
+
780
+ /** Escape HTML special characters in text */
781
+ export function escapeHtml(text: string): string;
782
+
783
+ /** Check whether a tag is a void element */
784
+ export function isVoidElement(tagName: string): boolean;
785
+
786
+ /** Serialize props into an HTML attribute string */
787
+ export function formatAttributes(props: Record<string, any>): string;
788
+
789
+ /** Mark content as trusted so it is emitted without escaping */
790
+ export function dangerouslySetInnerContent(content: string): TrustedContent;
791
+
792
+ /** Content marked trusted by dangerouslySetInnerContent() */
793
+ export interface TrustedContent {
794
+ __html: string;
795
+ __trusted: true;
796
+ }
797
+
798
+ /** Detect content marked by dangerouslySetInnerContent() */
799
+ export function isTrustedContent(value: unknown): value is TrustedContent;
800
+
695
801
  // ============================================================================
696
802
  // Utility Types and Constants
697
803
  // ============================================================================