@useavalon/core 0.1.6 → 0.1.7

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.
Files changed (2) hide show
  1. package/dist/types.d.ts +139 -0
  2. package/package.json +3 -2
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Core types for the Avalon framework integration system.
3
+ * These types define the contract that all framework integrations must implement.
4
+ */
5
+ import type { Plugin, ViteDevServer } from 'vite';
6
+ /**
7
+ * Hydration condition types that determine when an island should become interactive
8
+ */
9
+ export type HydrationCondition = 'on:client' | 'on:visible' | 'on:interaction' | 'on:idle' | `media:${string}` | `on:${string}`;
10
+ /**
11
+ * Parameters passed to the integration's render function
12
+ */
13
+ export interface RenderParams {
14
+ /** The component to render (may be null if integration loads it) */
15
+ component: unknown;
16
+ /** Props to pass to the component */
17
+ props: Record<string, unknown>;
18
+ /** Source path to the component file */
19
+ src: string;
20
+ /** Hydration condition for the island */
21
+ condition?: HydrationCondition;
22
+ /** If true, component will not hydrate on client */
23
+ ssrOnly?: boolean;
24
+ /** Vite dev server instance (available in development) */
25
+ viteServer?: ViteDevServer;
26
+ /** Whether running in development mode */
27
+ isDev?: boolean;
28
+ }
29
+ /**
30
+ * Result returned from the integration's render function
31
+ */
32
+ export interface RenderResult {
33
+ /** Rendered HTML string */
34
+ html: string;
35
+ /** CSS to inject (for frameworks with scoped styles) */
36
+ css?: string;
37
+ /** Additional head content (scripts, meta tags, etc.) */
38
+ head?: string;
39
+ /** Scope ID for CSS scoping (e.g., Vue scoped styles) */
40
+ scopeId?: string;
41
+ /** Data to serialize for client-side hydration */
42
+ hydrationData?: Record<string, unknown>;
43
+ }
44
+ /**
45
+ * Configuration for a framework integration
46
+ */
47
+ export interface IntegrationConfig {
48
+ /** Unique name of the integration (e.g., "preact", "vue") */
49
+ name: string;
50
+ /** File extensions this integration handles */
51
+ fileExtensions: string[];
52
+ /** JSX import sources for this framework */
53
+ jsxImportSources?: string[];
54
+ /** Patterns to detect if a file uses this framework */
55
+ detectionPatterns: {
56
+ /** Regex patterns to match import statements */
57
+ imports: RegExp[];
58
+ /** Regex patterns to match code content */
59
+ content: RegExp[];
60
+ };
61
+ }
62
+ /**
63
+ * Main integration interface that all framework integrations must implement
64
+ */
65
+ export interface Integration {
66
+ /** Unique name of the integration */
67
+ name: string;
68
+ /** Version of the integration package */
69
+ version: string;
70
+ /**
71
+ * Render a component to HTML on the server
72
+ * @param params - Rendering parameters
73
+ * @returns Promise resolving to render result
74
+ */
75
+ render(params: RenderParams): Promise<RenderResult>;
76
+ /**
77
+ * Get the hydration script for client-side initialization
78
+ * @returns JavaScript code as a string
79
+ */
80
+ getHydrationScript(): string;
81
+ /**
82
+ * Get the integration configuration
83
+ * @returns Integration configuration object
84
+ */
85
+ config(): IntegrationConfig;
86
+ /**
87
+ * Optional: Provide Vite plugins required for this framework's build-time processing.
88
+ *
89
+ * Each integration encapsulates its own Vite plugin configuration, eliminating
90
+ * the need for manual framework plugin setup in the user's vite.config.ts.
91
+ *
92
+ * **Plugin Ordering Requirements:**
93
+ * - Lit integration plugins MUST be placed first (DOM shim requirement)
94
+ * - MDX plugins should come after Lit but before other framework plugins
95
+ * - Framework-specific plugins (React, Vue, Svelte, etc.) come last
96
+ *
97
+ * The Avalon plugin handles ordering automatically when collecting plugins
98
+ * from all activated integrations.
99
+ *
100
+ * @returns Promise resolving to a single Vite plugin or array of plugins
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * async vitePlugin(): Promise<Plugin | Plugin[]> {
105
+ * const { default: vue } = await import('@vitejs/plugin-vue');
106
+ * return vue({
107
+ * template: {
108
+ * compilerOptions: {
109
+ * isCustomElement: tag => tag === 'avalon-island',
110
+ * },
111
+ * },
112
+ * });
113
+ * }
114
+ * ```
115
+ */
116
+ vitePlugin?(): Promise<Plugin | Plugin[]>;
117
+ }
118
+ /**
119
+ * Context available during component loading
120
+ */
121
+ export interface LoadContext {
122
+ /** Whether running in development mode */
123
+ isDev: boolean;
124
+ /** Vite dev server instance (available in development) */
125
+ viteServer?: ViteDevServer;
126
+ /** Path to build output directory (production) */
127
+ buildOutput?: string;
128
+ }
129
+ /**
130
+ * Options for component loading
131
+ */
132
+ export interface ComponentLoadOptions {
133
+ /** Source path to the component */
134
+ src: string;
135
+ /** Load context */
136
+ context: LoadContext;
137
+ /** Whether to load for SSR or client */
138
+ target?: 'ssr' | 'client';
139
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useavalon/core",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Core types and utilities for Avalon framework integrations",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,7 +25,8 @@
25
25
  },
26
26
  "scripts": {
27
27
  "build": "bun run ../../../scripts/build-package.ts",
28
- "prepublishOnly": "bun run build"
28
+ "prepublishOnly": "bun run build",
29
+ "postpublish": "bun run ../../../scripts/postpublish.ts"
29
30
  },
30
31
  "files": [
31
32
  "dist/**/*.js",