prev-cli 0.24.15 → 0.24.16
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/dist/cli.d.ts +1 -1
- package/dist/cli.js +4465 -1681
- package/dist/jsx/adapters/html.d.ts +15 -0
- package/dist/jsx/adapters/react.d.ts +26 -0
- package/dist/jsx/define-component.d.ts +68 -0
- package/dist/jsx/index.d.ts +7 -0
- package/dist/jsx/jsx-runtime.d.ts +34 -0
- package/dist/jsx/migrate.d.ts +24 -0
- package/dist/jsx/schemas/index.d.ts +2 -0
- package/dist/jsx/schemas/primitives.d.ts +355 -0
- package/dist/jsx/schemas/tokens.d.ts +79 -0
- package/dist/jsx/validation.d.ts +28 -0
- package/dist/jsx/vnode.d.ts +58 -0
- package/dist/migrate.d.ts +18 -0
- package/dist/primitives/index.d.ts +5 -0
- package/dist/primitives/migrate.d.ts +25 -0
- package/dist/primitives/parser.d.ts +32 -0
- package/dist/primitives/template-parser.d.ts +33 -0
- package/dist/primitives/template-renderer.d.ts +19 -0
- package/dist/primitives/types.d.ts +164 -0
- package/dist/renderers/html/index.d.ts +6 -0
- package/dist/renderers/index.d.ts +5 -0
- package/dist/renderers/react/index.d.ts +6 -0
- package/dist/renderers/registry.d.ts +41 -0
- package/dist/renderers/render.d.ts +35 -0
- package/dist/renderers/types.d.ts +188 -0
- package/dist/tokens/defaults.d.ts +2 -0
- package/dist/tokens/resolver.d.ts +67 -0
- package/dist/tokens/utils.d.ts +15 -0
- package/dist/tokens/validation.d.ts +36 -0
- package/dist/typecheck/index.d.ts +24 -0
- package/dist/ui/button.d.ts +1 -1
- package/dist/validators/index.d.ts +59 -0
- package/dist/validators/schema-validator.d.ts +27 -0
- package/dist/validators/semantic-validator.d.ts +47 -0
- package/dist/vite/plugins/tokens-plugin.d.ts +2 -0
- package/package.json +8 -4
- package/src/preview-runtime/fast-template.html +115 -0
- package/src/preview-runtime/template.html +50 -8
- package/src/preview-runtime/vendors.ts +9 -0
- package/src/theme/entry.tsx +153 -12
- package/src/theme/previews/TokensPage.tsx +328 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PrimitiveType } from './schemas/primitives';
|
|
3
|
+
export interface VNodeType {
|
|
4
|
+
id: string;
|
|
5
|
+
type: z.infer<typeof PrimitiveType>;
|
|
6
|
+
props: Record<string, unknown>;
|
|
7
|
+
children?: VNodeType[];
|
|
8
|
+
componentName?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const VNode: z.ZodType<VNodeType>;
|
|
11
|
+
/**
|
|
12
|
+
* Render context for isolated ID generation.
|
|
13
|
+
* Each render should use its own context to avoid ID conflicts
|
|
14
|
+
* when multiple renders execute concurrently.
|
|
15
|
+
*/
|
|
16
|
+
export interface RenderContext {
|
|
17
|
+
/** Generate unique ID for a node type */
|
|
18
|
+
nextId: (type: string) => string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a new render context with isolated ID counter.
|
|
22
|
+
* Use this for each render to ensure concurrent safety.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createRenderContext(): RenderContext;
|
|
25
|
+
/**
|
|
26
|
+
* Reset ID counter - call at start of each render.
|
|
27
|
+
* @deprecated Use createRenderContext() for concurrent safety
|
|
28
|
+
*/
|
|
29
|
+
export declare function resetIdCounter(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get the current global render context.
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export declare function getGlobalContext(): RenderContext;
|
|
35
|
+
/**
|
|
36
|
+
* Create an immutable VNode
|
|
37
|
+
* @param type - Node type (col, row, text, etc.)
|
|
38
|
+
* @param props - Node properties
|
|
39
|
+
* @param children - Child nodes
|
|
40
|
+
* @param context - Optional render context for ID generation (uses global if not provided)
|
|
41
|
+
*/
|
|
42
|
+
export declare function createVNode(type: VNodeType['type'], props: Record<string, unknown>, children?: VNodeType[], context?: RenderContext): VNodeType;
|
|
43
|
+
/**
|
|
44
|
+
* Create a component VNode (wraps rendered content)
|
|
45
|
+
* @param componentName - Name of the component
|
|
46
|
+
* @param props - Component properties
|
|
47
|
+
* @param children - Child nodes
|
|
48
|
+
* @param context - Optional render context for ID generation (uses global if not provided)
|
|
49
|
+
*/
|
|
50
|
+
export declare function createComponentVNode(componentName: string, props: Record<string, unknown>, children?: VNodeType[], context?: RenderContext): VNodeType;
|
|
51
|
+
/**
|
|
52
|
+
* Normalize children to array, converting strings/numbers to Text nodes
|
|
53
|
+
*/
|
|
54
|
+
export declare function normalizeChildren(children: unknown): VNodeType[];
|
|
55
|
+
/**
|
|
56
|
+
* Check structural equality of two VNodes (ignores IDs)
|
|
57
|
+
*/
|
|
58
|
+
export declare function vnodeEquals(a: VNodeType, b: VNodeType): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface MigrationResult {
|
|
2
|
+
success: boolean;
|
|
3
|
+
migrated: number;
|
|
4
|
+
skipped: number;
|
|
5
|
+
errors: MigrationError[];
|
|
6
|
+
}
|
|
7
|
+
export interface MigrationError {
|
|
8
|
+
file: string;
|
|
9
|
+
message: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Migrate all preview configs from v1 to v2 format
|
|
13
|
+
*/
|
|
14
|
+
export declare function migrateConfigs(rootDir?: string): Promise<MigrationResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Format migration result for CLI output
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatMigrationResult(result: MigrationResult): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Template, Slots } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Migration result
|
|
4
|
+
*/
|
|
5
|
+
export interface MigrationResult {
|
|
6
|
+
success: boolean;
|
|
7
|
+
template?: Template;
|
|
8
|
+
slots?: Slots;
|
|
9
|
+
errors: string[];
|
|
10
|
+
warnings: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Migrate a layoutByRenderer tree to template format
|
|
14
|
+
*
|
|
15
|
+
* Converts:
|
|
16
|
+
* - Stack/HStack/VStack to $col/$row
|
|
17
|
+
* - Box/Container to $box
|
|
18
|
+
* - ComponentRef to component refs
|
|
19
|
+
* - Slot to $slot
|
|
20
|
+
*/
|
|
21
|
+
export declare function migrateLayout(layout: unknown, _rendererName?: string): MigrationResult;
|
|
22
|
+
/**
|
|
23
|
+
* Migrate all layouts from a screen config
|
|
24
|
+
*/
|
|
25
|
+
export declare function migrateScreenConfig(layoutByRenderer: Record<string, unknown>): MigrationResult;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Primitive, PrimitiveType } from './types';
|
|
2
|
+
export interface ParseError {
|
|
3
|
+
message: string;
|
|
4
|
+
position?: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ParseResultSuccess<T extends Primitive = Primitive> {
|
|
7
|
+
success: true;
|
|
8
|
+
primitive: T;
|
|
9
|
+
raw: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ParseResultFailure {
|
|
12
|
+
success: false;
|
|
13
|
+
error: ParseError;
|
|
14
|
+
raw: string;
|
|
15
|
+
}
|
|
16
|
+
export type ParseResult<T extends Primitive = Primitive> = ParseResultSuccess<T> | ParseResultFailure;
|
|
17
|
+
/**
|
|
18
|
+
* Parse a primitive string like "$col(gap:lg align:center)"
|
|
19
|
+
*/
|
|
20
|
+
export declare function parsePrimitive(input: string): ParseResult;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a value is quoted (literal) vs bare (prop reference)
|
|
23
|
+
*/
|
|
24
|
+
export declare function isQuoted(value: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Extract primitive type from a primitive string
|
|
27
|
+
*/
|
|
28
|
+
export declare function getPrimitiveType(input: string): PrimitiveType | null;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a string is a valid primitive syntax
|
|
31
|
+
*/
|
|
32
|
+
export declare function isValidPrimitiveSyntax(input: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type TemplateNode, type Template } from './types';
|
|
2
|
+
export interface TemplateParseError {
|
|
3
|
+
path: string;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
export interface TemplateParseResult {
|
|
7
|
+
valid: boolean;
|
|
8
|
+
errors: TemplateParseError[];
|
|
9
|
+
warnings: TemplateParseError[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Validate a template structure
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateTemplate(template: unknown): TemplateParseResult;
|
|
15
|
+
/**
|
|
16
|
+
* Validate slots structure
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateSlots(slots: unknown, definedStates?: string[]): TemplateParseResult;
|
|
19
|
+
/**
|
|
20
|
+
* Extract all component refs from a template
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractRefs(template: unknown): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Extract all slot names from a template
|
|
25
|
+
*/
|
|
26
|
+
export declare function extractSlotNames(template: unknown): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Flatten a template into a list of nodes with paths
|
|
29
|
+
*/
|
|
30
|
+
export declare function flattenTemplate(template: Template): Array<{
|
|
31
|
+
path: string;
|
|
32
|
+
node: TemplateNode;
|
|
33
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Template, type Slots } from './types';
|
|
2
|
+
export interface RenderContext {
|
|
3
|
+
/** Current state for slot resolution */
|
|
4
|
+
state?: string;
|
|
5
|
+
/** Slots mapping for state-dependent content */
|
|
6
|
+
slots?: Slots;
|
|
7
|
+
/** Props for component rendering */
|
|
8
|
+
props?: Record<string, unknown>;
|
|
9
|
+
/** Callback to render component refs */
|
|
10
|
+
renderRef?: (ref: string) => string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Render a template to HTML
|
|
14
|
+
*/
|
|
15
|
+
export declare function renderTemplate(template: Template, context?: RenderContext): string;
|
|
16
|
+
/**
|
|
17
|
+
* Generate CSS custom properties for design tokens (shadcn-compatible)
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateTokenCSS(): string;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Design token types for consistent spacing, sizing, and styling
|
|
3
|
+
* Using shadcn/ui-compatible naming conventions
|
|
4
|
+
*/
|
|
5
|
+
export type SpacingToken = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
6
|
+
export type AlignToken = 'start' | 'center' | 'end' | 'stretch' | 'between';
|
|
7
|
+
export type BackgroundToken = 'transparent' | 'background' | 'card' | 'primary' | 'secondary' | 'muted' | 'accent' | 'destructive' | 'input';
|
|
8
|
+
export type RadiusToken = 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
9
|
+
export type ColorToken = 'foreground' | 'card-foreground' | 'primary' | 'primary-foreground' | 'secondary' | 'secondary-foreground' | 'muted' | 'muted-foreground' | 'accent' | 'accent-foreground' | 'destructive' | 'destructive-foreground' | 'border' | 'ring';
|
|
10
|
+
export type SizeToken = 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl';
|
|
11
|
+
export type WeightToken = 'normal' | 'medium' | 'semibold' | 'bold';
|
|
12
|
+
export type FitToken = 'cover' | 'contain' | 'fill';
|
|
13
|
+
/**
|
|
14
|
+
* All primitive type names
|
|
15
|
+
*/
|
|
16
|
+
export type PrimitiveType = '$col' | '$row' | '$box' | '$spacer' | '$slot' | '$text' | '$icon' | '$image';
|
|
17
|
+
/**
|
|
18
|
+
* Layout primitive: $col - Vertical stack
|
|
19
|
+
*/
|
|
20
|
+
export interface ColPrimitive {
|
|
21
|
+
type: '$col';
|
|
22
|
+
gap?: SpacingToken;
|
|
23
|
+
align?: AlignToken;
|
|
24
|
+
padding?: SpacingToken;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Layout primitive: $row - Horizontal stack
|
|
28
|
+
*/
|
|
29
|
+
export interface RowPrimitive {
|
|
30
|
+
type: '$row';
|
|
31
|
+
gap?: SpacingToken;
|
|
32
|
+
align?: AlignToken;
|
|
33
|
+
padding?: SpacingToken;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Layout primitive: $box - Container with styling
|
|
37
|
+
*/
|
|
38
|
+
export interface BoxPrimitive {
|
|
39
|
+
type: '$box';
|
|
40
|
+
padding?: SpacingToken;
|
|
41
|
+
bg?: BackgroundToken;
|
|
42
|
+
radius?: RadiusToken;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Layout primitive: $spacer - Whitespace
|
|
46
|
+
*/
|
|
47
|
+
export interface SpacerPrimitive {
|
|
48
|
+
type: '$spacer';
|
|
49
|
+
size?: SpacingToken;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Layout primitive: $slot - State-dependent placeholder
|
|
53
|
+
*/
|
|
54
|
+
export interface SlotPrimitive {
|
|
55
|
+
type: '$slot';
|
|
56
|
+
name: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Content primitive: $text - Text content
|
|
60
|
+
*/
|
|
61
|
+
export interface TextPrimitive {
|
|
62
|
+
type: '$text';
|
|
63
|
+
content: string;
|
|
64
|
+
size?: SizeToken;
|
|
65
|
+
weight?: WeightToken;
|
|
66
|
+
color?: ColorToken;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Content primitive: $icon - Icon
|
|
70
|
+
*/
|
|
71
|
+
export interface IconPrimitive {
|
|
72
|
+
type: '$icon';
|
|
73
|
+
name: string;
|
|
74
|
+
size?: SizeToken;
|
|
75
|
+
color?: ColorToken;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Content primitive: $image - Image
|
|
79
|
+
*/
|
|
80
|
+
export interface ImagePrimitive {
|
|
81
|
+
type: '$image';
|
|
82
|
+
src: string;
|
|
83
|
+
alt?: string;
|
|
84
|
+
fit?: FitToken;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Union of all primitives
|
|
88
|
+
*/
|
|
89
|
+
export type Primitive = ColPrimitive | RowPrimitive | BoxPrimitive | SpacerPrimitive | SlotPrimitive | TextPrimitive | IconPrimitive | ImagePrimitive;
|
|
90
|
+
/**
|
|
91
|
+
* Parsed primitive with original string
|
|
92
|
+
*/
|
|
93
|
+
export interface ParsedPrimitive<T extends Primitive = Primitive> {
|
|
94
|
+
primitive: T;
|
|
95
|
+
raw: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Template node - container or leaf
|
|
99
|
+
*/
|
|
100
|
+
export interface TemplateContainerNode {
|
|
101
|
+
type: string;
|
|
102
|
+
children?: Record<string, TemplateNode>;
|
|
103
|
+
}
|
|
104
|
+
export interface TemplateLeafNode {
|
|
105
|
+
value: string;
|
|
106
|
+
}
|
|
107
|
+
export type TemplateNode = TemplateContainerNode | string;
|
|
108
|
+
/**
|
|
109
|
+
* Template root structure
|
|
110
|
+
*/
|
|
111
|
+
export interface Template {
|
|
112
|
+
root: TemplateNode;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Slots mapping: state name -> content ref
|
|
116
|
+
*/
|
|
117
|
+
export type Slots = Record<string, Record<string, string>>;
|
|
118
|
+
/**
|
|
119
|
+
* Screen v2 config with template and slots
|
|
120
|
+
*/
|
|
121
|
+
export interface ScreenV2Config {
|
|
122
|
+
kind: 'screen';
|
|
123
|
+
id: string;
|
|
124
|
+
title: string;
|
|
125
|
+
schemaVersion: '2.0';
|
|
126
|
+
states?: Record<string, {
|
|
127
|
+
description?: string;
|
|
128
|
+
}>;
|
|
129
|
+
template: Template;
|
|
130
|
+
slots?: Slots;
|
|
131
|
+
layoutByRenderer?: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Component v2 config with props and template
|
|
135
|
+
*/
|
|
136
|
+
export interface ComponentV2Config {
|
|
137
|
+
kind: 'component';
|
|
138
|
+
id: string;
|
|
139
|
+
title: string;
|
|
140
|
+
schemaVersion: '2.0';
|
|
141
|
+
props?: Record<string, {
|
|
142
|
+
type?: string;
|
|
143
|
+
required?: boolean;
|
|
144
|
+
default?: unknown;
|
|
145
|
+
values?: unknown[];
|
|
146
|
+
}>;
|
|
147
|
+
template?: Template;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Check if a string is a primitive (starts with $)
|
|
151
|
+
*/
|
|
152
|
+
export declare function isPrimitive(value: string): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Check if a string is a component/screen/flow ref (contains /)
|
|
155
|
+
*/
|
|
156
|
+
export declare function isRef(value: string): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Check if a template node is a container (has type and children)
|
|
159
|
+
*/
|
|
160
|
+
export declare function isContainerNode(node: unknown): node is TemplateContainerNode;
|
|
161
|
+
/**
|
|
162
|
+
* Check if a template node is a leaf (string value)
|
|
163
|
+
*/
|
|
164
|
+
export declare function isLeafNode(node: unknown): node is string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { registerAdapter, getAdapter, listAdapters, getAllAdapters, isValidRendererKey, getLayoutSchema, clearAdapters, initializeAdapters, validateRendererKeys, } from './registry';
|
|
2
|
+
export { renderPreview, renderPreviews, selectAdapter, ensureAdaptersInitialized, supportsHMR, type RenderOptions, type RenderResult, } from './render';
|
|
3
|
+
export type { RendererAdapter, RenderOutput, DevServer, PreviewKind, PreviewRef, BaseConfig, ComponentConfig, ScreenConfig, FlowConfig, AtlasConfig, PreviewConfig, FlowStep, FlowTransition, AtlasNode, AtlasRelationship, } from './types';
|
|
4
|
+
export { ReactAdapter } from './react';
|
|
5
|
+
export { HTMLAdapter } from './html';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
import type { RendererAdapter } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Register a renderer adapter
|
|
5
|
+
* @throws Error if adapter with same name already registered
|
|
6
|
+
*/
|
|
7
|
+
export declare function registerAdapter(adapter: RendererAdapter): void;
|
|
8
|
+
/**
|
|
9
|
+
* Get a renderer adapter by name
|
|
10
|
+
*/
|
|
11
|
+
export declare function getAdapter(name: string): RendererAdapter | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* List all registered adapter names
|
|
14
|
+
*/
|
|
15
|
+
export declare function listAdapters(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* List all registered adapters
|
|
18
|
+
*/
|
|
19
|
+
export declare function getAllAdapters(): RendererAdapter[];
|
|
20
|
+
/**
|
|
21
|
+
* Check if a renderer key matches a registered adapter
|
|
22
|
+
*/
|
|
23
|
+
export declare function isValidRendererKey(key: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get the layout schema for a specific renderer
|
|
26
|
+
*/
|
|
27
|
+
export declare function getLayoutSchema(name: string): JSONSchema7 | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Clear all registered adapters (for testing)
|
|
30
|
+
*/
|
|
31
|
+
export declare function clearAdapters(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Initialize default adapters
|
|
34
|
+
* Called at startup to register built-in adapters
|
|
35
|
+
*/
|
|
36
|
+
export declare function initializeAdapters(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Validate that all layoutByRenderer keys have registered adapters
|
|
39
|
+
* @returns Array of unknown renderer keys
|
|
40
|
+
*/
|
|
41
|
+
export declare function validateRendererKeys(keys: string[]): string[];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PreviewConfig, RenderOutput, RendererAdapter } from './types';
|
|
2
|
+
export interface RenderOptions {
|
|
3
|
+
/** Specific renderer to use (defaults to first available in layoutByRenderer) */
|
|
4
|
+
renderer?: string;
|
|
5
|
+
/** State for screen rendering */
|
|
6
|
+
state?: string;
|
|
7
|
+
/** Step for flow rendering */
|
|
8
|
+
step?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface RenderResult {
|
|
11
|
+
success: boolean;
|
|
12
|
+
output?: RenderOutput;
|
|
13
|
+
error?: string;
|
|
14
|
+
renderer?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Ensure adapters are initialized
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureAdaptersInitialized(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Select the appropriate renderer adapter for a config
|
|
22
|
+
*/
|
|
23
|
+
export declare function selectAdapter(config: PreviewConfig, preferredRenderer?: string): RendererAdapter | null;
|
|
24
|
+
/**
|
|
25
|
+
* Render a preview config using the appropriate adapter
|
|
26
|
+
*/
|
|
27
|
+
export declare function renderPreview(config: PreviewConfig, options?: RenderOptions): Promise<RenderResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Render multiple previews with the same adapter
|
|
30
|
+
*/
|
|
31
|
+
export declare function renderPreviews(configs: PreviewConfig[], options?: RenderOptions): Promise<Map<string, RenderResult>>;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a specific renderer supports HMR
|
|
34
|
+
*/
|
|
35
|
+
export declare function supportsHMR(rendererName?: string): Promise<boolean>;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { JSONSchema7 } from 'json-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Preview type discriminator
|
|
4
|
+
*/
|
|
5
|
+
export type PreviewKind = 'component' | 'screen' | 'flow' | 'atlas';
|
|
6
|
+
/**
|
|
7
|
+
* Reference to another preview unit
|
|
8
|
+
*/
|
|
9
|
+
export type PreviewRef = string | {
|
|
10
|
+
ref: string;
|
|
11
|
+
state?: string;
|
|
12
|
+
options?: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Base config shared by all preview types
|
|
16
|
+
*/
|
|
17
|
+
export interface BaseConfig {
|
|
18
|
+
kind: PreviewKind;
|
|
19
|
+
id: string;
|
|
20
|
+
title: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
tags?: string[];
|
|
23
|
+
status?: 'draft' | 'stable' | 'deprecated';
|
|
24
|
+
schemaVersion: '1.0' | '2.0';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Template node - container or leaf
|
|
28
|
+
*/
|
|
29
|
+
export interface TemplateContainerNode {
|
|
30
|
+
type: string;
|
|
31
|
+
children?: Record<string, TemplateNode>;
|
|
32
|
+
}
|
|
33
|
+
export type TemplateNode = TemplateContainerNode | string;
|
|
34
|
+
/**
|
|
35
|
+
* Template root structure
|
|
36
|
+
*/
|
|
37
|
+
export interface Template {
|
|
38
|
+
root: TemplateNode;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Slots mapping: slot name -> state name -> content ref
|
|
42
|
+
*/
|
|
43
|
+
export type Slots = Record<string, Record<string, string>>;
|
|
44
|
+
/**
|
|
45
|
+
* Component config - defines reusable UI components
|
|
46
|
+
*/
|
|
47
|
+
export interface ComponentConfig extends BaseConfig {
|
|
48
|
+
kind: 'component';
|
|
49
|
+
props?: Record<string, {
|
|
50
|
+
type?: string;
|
|
51
|
+
required?: boolean;
|
|
52
|
+
default?: unknown;
|
|
53
|
+
values?: unknown[];
|
|
54
|
+
enum?: unknown[];
|
|
55
|
+
}>;
|
|
56
|
+
template?: Template;
|
|
57
|
+
slots?: Record<string, {
|
|
58
|
+
description?: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Screen config - defines full-page views with states
|
|
63
|
+
*/
|
|
64
|
+
export interface ScreenConfig extends BaseConfig {
|
|
65
|
+
kind: 'screen';
|
|
66
|
+
states?: Record<string, {
|
|
67
|
+
description?: string;
|
|
68
|
+
}>;
|
|
69
|
+
/** New: Renderer-agnostic template using primitives */
|
|
70
|
+
template?: Template;
|
|
71
|
+
/** New: State-dependent slot content mapping */
|
|
72
|
+
slots?: Slots;
|
|
73
|
+
/** Legacy: Layout definitions per renderer. Values can be arrays or objects per adapter schema. */
|
|
74
|
+
layoutByRenderer?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Flow step definition
|
|
78
|
+
*/
|
|
79
|
+
export interface FlowStep {
|
|
80
|
+
id: string;
|
|
81
|
+
title: string;
|
|
82
|
+
screen: PreviewRef;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Flow transition definition
|
|
86
|
+
*/
|
|
87
|
+
export interface FlowTransition {
|
|
88
|
+
from: string;
|
|
89
|
+
to: string;
|
|
90
|
+
trigger: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Flow config - defines multi-step user journeys
|
|
94
|
+
*/
|
|
95
|
+
export interface FlowConfig extends BaseConfig {
|
|
96
|
+
kind: 'flow';
|
|
97
|
+
steps: FlowStep[];
|
|
98
|
+
transitions?: FlowTransition[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Atlas node definition
|
|
102
|
+
*/
|
|
103
|
+
export interface AtlasNode {
|
|
104
|
+
id: string;
|
|
105
|
+
title: string;
|
|
106
|
+
ref?: PreviewRef;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Atlas relationship definition
|
|
110
|
+
*/
|
|
111
|
+
export interface AtlasRelationship {
|
|
112
|
+
from: string;
|
|
113
|
+
to: string;
|
|
114
|
+
type: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Atlas config - defines information architecture
|
|
118
|
+
*/
|
|
119
|
+
export interface AtlasConfig extends BaseConfig {
|
|
120
|
+
kind: 'atlas';
|
|
121
|
+
nodes: AtlasNode[];
|
|
122
|
+
relationships?: AtlasRelationship[];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Union of all config types
|
|
126
|
+
*/
|
|
127
|
+
export type PreviewConfig = ComponentConfig | ScreenConfig | FlowConfig | AtlasConfig;
|
|
128
|
+
/**
|
|
129
|
+
* Output from rendering a preview
|
|
130
|
+
*/
|
|
131
|
+
export interface RenderOutput {
|
|
132
|
+
/** Generated HTML content */
|
|
133
|
+
html: string;
|
|
134
|
+
/** Optional CSS styles */
|
|
135
|
+
css?: string;
|
|
136
|
+
/** Optional JS asset path (e.g., "login.js"), build system handles bundling */
|
|
137
|
+
js?: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Dev server interface for HMR support
|
|
141
|
+
*/
|
|
142
|
+
export interface DevServer {
|
|
143
|
+
start(): Promise<void>;
|
|
144
|
+
stop(): Promise<void>;
|
|
145
|
+
readonly port: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Renderer adapter interface - implementations for React, HTML, Solid, etc.
|
|
149
|
+
*
|
|
150
|
+
* The adapter interface is intentionally thin. Bundling, asset management,
|
|
151
|
+
* and hydration are handled by the build system (Vite/esbuild), not the adapter.
|
|
152
|
+
*/
|
|
153
|
+
export interface RendererAdapter {
|
|
154
|
+
/**
|
|
155
|
+
* Adapter name - must match layoutByRenderer keys in configs
|
|
156
|
+
* @example "react", "html", "solid"
|
|
157
|
+
*/
|
|
158
|
+
readonly name: string;
|
|
159
|
+
/**
|
|
160
|
+
* JSON Schema for validating this renderer's layout nodes
|
|
161
|
+
* Used by the validator to check layoutByRenderer subtrees
|
|
162
|
+
*/
|
|
163
|
+
readonly layoutSchema: JSONSchema7;
|
|
164
|
+
/**
|
|
165
|
+
* Render an isolated component with props applied
|
|
166
|
+
*/
|
|
167
|
+
renderComponent(config: ComponentConfig): RenderOutput;
|
|
168
|
+
/**
|
|
169
|
+
* Render a full screen layout in the specified state
|
|
170
|
+
*/
|
|
171
|
+
renderScreen(config: ScreenConfig, state?: string): RenderOutput;
|
|
172
|
+
/**
|
|
173
|
+
* Render the current step's screen with navigation UI (prev/next)
|
|
174
|
+
*/
|
|
175
|
+
renderFlow(config: FlowConfig, step?: string): RenderOutput;
|
|
176
|
+
/**
|
|
177
|
+
* Render a graph visualization with node thumbnails
|
|
178
|
+
*/
|
|
179
|
+
renderAtlas(config: AtlasConfig): RenderOutput;
|
|
180
|
+
/**
|
|
181
|
+
* Whether this adapter supports Hot Module Replacement
|
|
182
|
+
*/
|
|
183
|
+
supportsHMR(): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Create a dev server for HMR support (optional)
|
|
186
|
+
*/
|
|
187
|
+
createDevServer?(port: number): DevServer;
|
|
188
|
+
}
|