@pixldocs/canvas-renderer 0.3.3
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/README.md +148 -0
- package/dist/index.cjs +10628 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +281 -0
- package/dist/index.js +10611 -0
- package/dist/index.js.map +1 -0
- package/dist/svgColorUtils-BkKZ8cyd.js +379 -0
- package/dist/svgColorUtils-BkKZ8cyd.js.map +1 -0
- package/dist/svgColorUtils-DQN6fbIM.cjs +379 -0
- package/dist/svgColorUtils-DQN6fbIM.cjs.map +1 -0
- package/package.json +41 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { InferredSection } from '../../../src/lib/inferFormSchemaFromTemplate';
|
|
2
|
+
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
3
|
+
import { SectionFormState } from '../../../src/lib/inferFormSchemaFromTemplate';
|
|
4
|
+
import { SmartElementProps } from '../../../shared/smart-elements/types';
|
|
5
|
+
import { SmartElementType } from '../../../shared/smart-elements/types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Apply theme variable overrides to a template config.
|
|
9
|
+
* Walks the tree and replaces any property value that matches a theme variable reference.
|
|
10
|
+
*
|
|
11
|
+
* Theme variables in config look like: {{theme.variableName}}
|
|
12
|
+
* Or are stored in themeConfig.variables as { [name]: { value, label } }
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyThemeToConfig(config: TemplateConfig, themeOverrides: ThemeVariables): TemplateConfig;
|
|
15
|
+
|
|
16
|
+
export declare interface CanvasNode {
|
|
17
|
+
id: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
type?: string;
|
|
20
|
+
left?: number;
|
|
21
|
+
top?: number;
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
visible?: boolean;
|
|
25
|
+
children?: CanvasNode[];
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Minimal type definitions for template configs.
|
|
31
|
+
* These are the subset of types needed by the renderer,
|
|
32
|
+
* extracted from the main app's types/editor.ts to avoid coupling.
|
|
33
|
+
*/
|
|
34
|
+
export declare interface CanvasSize {
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Collect all font families used in a template config.
|
|
41
|
+
*/
|
|
42
|
+
export declare function collectFontsFromConfig(config: TemplateConfig): Set<string>;
|
|
43
|
+
|
|
44
|
+
export declare interface DynamicField {
|
|
45
|
+
id: string;
|
|
46
|
+
label: string;
|
|
47
|
+
type: string;
|
|
48
|
+
mappings: Array<{
|
|
49
|
+
elementId: string;
|
|
50
|
+
targetProperty: string;
|
|
51
|
+
}>;
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { InferredSection }
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Load a Google Font by injecting a <link> stylesheet.
|
|
59
|
+
* Resolves when the font is ready for use.
|
|
60
|
+
*/
|
|
61
|
+
export declare function loadGoogleFontCSS(fontFamily: string): Promise<void>;
|
|
62
|
+
|
|
63
|
+
export declare interface PageSettings {
|
|
64
|
+
backgroundColor?: string;
|
|
65
|
+
backgroundGradient?: any;
|
|
66
|
+
contentTop?: number;
|
|
67
|
+
contentBottom?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export declare function PixldocsPreview(props: PixldocsPreviewProps): JSX_2.Element;
|
|
71
|
+
|
|
72
|
+
declare interface PixldocsPreviewBaseProps {
|
|
73
|
+
/** Page index to render (default: 0) */
|
|
74
|
+
pageIndex?: number;
|
|
75
|
+
/** Zoom / scale factor (default: 1) */
|
|
76
|
+
zoom?: number;
|
|
77
|
+
/** When true, zoom is used as-is without auto-fit calculation */
|
|
78
|
+
absoluteZoom?: boolean;
|
|
79
|
+
/** Image proxy URL for CORS-safe external image loading */
|
|
80
|
+
imageProxyUrl?: string;
|
|
81
|
+
/** CSS class name for the outer container */
|
|
82
|
+
className?: string;
|
|
83
|
+
/** Inline styles for the outer container */
|
|
84
|
+
style?: Record<string, string | number>;
|
|
85
|
+
/** Optional dynamic field click callback */
|
|
86
|
+
onDynamicFieldClick?: (elementId: string, fieldId: string) => void;
|
|
87
|
+
/** Called when the canvas has fully loaded fonts and is ready to display */
|
|
88
|
+
onReady?: () => void;
|
|
89
|
+
/** Called when resolution or rendering fails */
|
|
90
|
+
onError?: (error: Error) => void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Mode 1: Pre-resolved config */
|
|
94
|
+
export declare interface PixldocsPreviewConfigProps extends PixldocsPreviewBaseProps {
|
|
95
|
+
/** Template configuration object (pre-resolved) */
|
|
96
|
+
config: TemplateConfig;
|
|
97
|
+
templateId?: never;
|
|
98
|
+
formSchemaId?: never;
|
|
99
|
+
sectionState?: never;
|
|
100
|
+
themeId?: never;
|
|
101
|
+
supabaseUrl?: never;
|
|
102
|
+
supabaseAnonKey?: never;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export declare type PixldocsPreviewProps = PixldocsPreviewConfigProps | PixldocsPreviewResolveProps;
|
|
106
|
+
|
|
107
|
+
/** Mode 2: Auto-resolve from database */
|
|
108
|
+
export declare interface PixldocsPreviewResolveProps extends PixldocsPreviewBaseProps {
|
|
109
|
+
config?: never;
|
|
110
|
+
/** Template UUID to fetch and resolve */
|
|
111
|
+
templateId: string;
|
|
112
|
+
/** Form schema UUID */
|
|
113
|
+
formSchemaId: string;
|
|
114
|
+
/** V2 section state data */
|
|
115
|
+
sectionState: SectionFormState;
|
|
116
|
+
/** Optional theme variant ID */
|
|
117
|
+
themeId?: string;
|
|
118
|
+
/** Supabase project URL */
|
|
119
|
+
supabaseUrl: string;
|
|
120
|
+
/** Supabase anon key */
|
|
121
|
+
supabaseAnonKey: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export declare class PixldocsRenderer {
|
|
125
|
+
private config;
|
|
126
|
+
constructor(config: RendererConfig);
|
|
127
|
+
/**
|
|
128
|
+
* Render a pre-resolved template config to an image using the full PageCanvas engine.
|
|
129
|
+
* Mounts a hidden PreviewCanvas component and captures the Fabric canvas output.
|
|
130
|
+
*/
|
|
131
|
+
render(templateConfig: TemplateConfig, options?: RenderOptions): Promise<RenderResult>;
|
|
132
|
+
/**
|
|
133
|
+
* Render all pages and return array of results.
|
|
134
|
+
*/
|
|
135
|
+
renderAllPages(templateConfig: TemplateConfig, options?: Omit<RenderOptions, 'pageIndex'>): Promise<RenderResult[]>;
|
|
136
|
+
/**
|
|
137
|
+
* Resolve from V2 sectionState (like the server API) and render all pages.
|
|
138
|
+
* This is the primary external API for the package.
|
|
139
|
+
*/
|
|
140
|
+
renderFromForm(options: RenderFromFormOptions): Promise<RenderResult[]>;
|
|
141
|
+
/**
|
|
142
|
+
* Convenience: fetch by ID with simple flat data and render.
|
|
143
|
+
*/
|
|
144
|
+
renderById(templateId: string, formData?: Record<string, any>, options?: RenderOptions): Promise<RenderResult>;
|
|
145
|
+
/**
|
|
146
|
+
* Wait until every image on the Fabric canvas inside the container has loaded.
|
|
147
|
+
* Polls img elements since we can't hook into Fabric's internal load events.
|
|
148
|
+
*/
|
|
149
|
+
private waitForCanvasImages;
|
|
150
|
+
private getNormalizedGradientStops;
|
|
151
|
+
private paintPageBackground;
|
|
152
|
+
private renderPageViaPreviewCanvas;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export declare interface RendererConfig {
|
|
156
|
+
/** Supabase project URL for fetching templates */
|
|
157
|
+
supabaseUrl: string;
|
|
158
|
+
/** Supabase anon key */
|
|
159
|
+
supabaseAnonKey: string;
|
|
160
|
+
/** Optional: image proxy URL for CORS-safe image loading */
|
|
161
|
+
imageProxyUrl?: string;
|
|
162
|
+
/** Optional: pixel ratio for high-DPI rendering (default: 2) */
|
|
163
|
+
pixelRatio?: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Options for renderFromForm — matches the server API payload */
|
|
167
|
+
export declare interface RenderFromFormOptions extends Omit<RenderOptions, 'pageIndex'> {
|
|
168
|
+
templateId: string;
|
|
169
|
+
formSchemaId: string;
|
|
170
|
+
sectionState: SectionFormState;
|
|
171
|
+
themeId?: string;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export declare interface RenderOptions {
|
|
175
|
+
/** Page index to render (default: 0) */
|
|
176
|
+
pageIndex?: number;
|
|
177
|
+
/** Output format (default: 'png') */
|
|
178
|
+
format?: 'png' | 'jpeg' | 'webp';
|
|
179
|
+
/** Quality for jpeg/webp (0-1, default: 0.92) */
|
|
180
|
+
quality?: number;
|
|
181
|
+
/** Scale multiplier (default: 1) */
|
|
182
|
+
scale?: number;
|
|
183
|
+
/** Custom pixel ratio override */
|
|
184
|
+
pixelRatio?: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export declare interface RenderResult {
|
|
188
|
+
/** Data URL of the rendered image */
|
|
189
|
+
dataUrl: string;
|
|
190
|
+
/** Width of the rendered image in CSS pixels */
|
|
191
|
+
width: number;
|
|
192
|
+
/** Height of the rendered image in CSS pixels */
|
|
193
|
+
height: number;
|
|
194
|
+
/** Actual pixel width (width * pixelRatio) */
|
|
195
|
+
pixelWidth: number;
|
|
196
|
+
/** Actual pixel height (height * pixelRatio) */
|
|
197
|
+
pixelHeight: number;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export declare interface ResolvedTemplate {
|
|
201
|
+
config: TemplateConfig;
|
|
202
|
+
templateName: string;
|
|
203
|
+
templateId: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Resolve a template using the V2 sectionState format.
|
|
208
|
+
* This is the primary API for external consumers and matches the server's /render-from-form pipeline.
|
|
209
|
+
*/
|
|
210
|
+
export declare function resolveFromForm(options: ResolveFromFormOptions): Promise<ResolvedTemplate>;
|
|
211
|
+
|
|
212
|
+
/** V2 resolution options — matches the server API payload */
|
|
213
|
+
export declare interface ResolveFromFormOptions {
|
|
214
|
+
/** Template UUID */
|
|
215
|
+
templateId: string;
|
|
216
|
+
/** Form schema UUID */
|
|
217
|
+
formSchemaId: string;
|
|
218
|
+
/** V2 section state (same shape sent to /render-from-form) */
|
|
219
|
+
sectionState: SectionFormState;
|
|
220
|
+
/** Optional theme variant ID (default: 'default') */
|
|
221
|
+
themeId?: string;
|
|
222
|
+
/** Supabase project URL */
|
|
223
|
+
supabaseUrl: string;
|
|
224
|
+
/** Supabase anon key */
|
|
225
|
+
supabaseAnonKey: string;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export declare interface ResolveOptions {
|
|
229
|
+
/** Template UUID */
|
|
230
|
+
templateId: string;
|
|
231
|
+
/** Optional flat formData (legacy, simple fields only) */
|
|
232
|
+
formData?: Record<string, any>;
|
|
233
|
+
/** Supabase project URL */
|
|
234
|
+
supabaseUrl: string;
|
|
235
|
+
/** Supabase anon key */
|
|
236
|
+
supabaseAnonKey: string;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export declare function resolveTemplateData(options: ResolveOptions): Promise<ResolvedTemplate>;
|
|
240
|
+
|
|
241
|
+
export { SectionFormState }
|
|
242
|
+
|
|
243
|
+
export { SmartElementProps }
|
|
244
|
+
|
|
245
|
+
export { SmartElementType }
|
|
246
|
+
|
|
247
|
+
export declare interface TemplateConfig {
|
|
248
|
+
version?: string;
|
|
249
|
+
name?: string;
|
|
250
|
+
description?: string;
|
|
251
|
+
canvas: CanvasSize;
|
|
252
|
+
pages: TemplateConfigPage[];
|
|
253
|
+
dynamicFields?: DynamicField[];
|
|
254
|
+
fieldGroups?: any[];
|
|
255
|
+
themeConfig?: ThemeConfig;
|
|
256
|
+
formBindingMode?: string;
|
|
257
|
+
boundFormDefId?: string;
|
|
258
|
+
boundFormDefName?: string;
|
|
259
|
+
[key: string]: any;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export declare interface TemplateConfigPage {
|
|
263
|
+
id: string;
|
|
264
|
+
name: string;
|
|
265
|
+
children: CanvasNode[];
|
|
266
|
+
settings?: PageSettings;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export declare interface ThemeConfig {
|
|
270
|
+
variables?: Record<string, {
|
|
271
|
+
value: string;
|
|
272
|
+
label?: string;
|
|
273
|
+
}>;
|
|
274
|
+
[key: string]: any;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export declare interface ThemeVariables {
|
|
278
|
+
[variableName: string]: string;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export { }
|