@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/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @pixldocs/canvas-renderer
|
|
2
|
+
|
|
3
|
+
React component + imperative API for rendering Pixldocs templates client-side. No server needed.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @pixldocs/canvas-renderer fabric react react-dom
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start — React Component
|
|
12
|
+
|
|
13
|
+
### Mode 1: Pre-resolved config
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { PixldocsPreview } from '@pixldocs/canvas-renderer';
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<PixldocsPreview
|
|
21
|
+
config={templateConfig}
|
|
22
|
+
pageIndex={0}
|
|
23
|
+
imageProxyUrl="https://your-project.supabase.co/functions/v1/image-proxy"
|
|
24
|
+
onReady={() => console.log('Rendered!')}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Mode 2: Auto-resolve from database (recommended)
|
|
31
|
+
|
|
32
|
+
Pass the same data you'd send to the server API — the component fetches
|
|
33
|
+
the template, resolves repeatable sections, applies themes, and renders.
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { PixldocsPreview } from '@pixldocs/canvas-renderer';
|
|
37
|
+
|
|
38
|
+
function App() {
|
|
39
|
+
const sectionState = {
|
|
40
|
+
section_abc123: { full_name: 'John Doe', photo: 'https://...' },
|
|
41
|
+
section_def456: [
|
|
42
|
+
{ label: 'Date of Birth', value: '1995-08-15' },
|
|
43
|
+
{ label: 'Religion', value: 'Hindu' },
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<PixldocsPreview
|
|
49
|
+
templateId="dc3fbb17-b671-47cb-a4cf-643a10251fb2"
|
|
50
|
+
formSchemaId="b04cd362-a0ef-438d-a7a3-0e8560a709ce"
|
|
51
|
+
sectionState={sectionState}
|
|
52
|
+
supabaseUrl="https://xxx.supabase.co"
|
|
53
|
+
supabaseAnonKey="eyJ..."
|
|
54
|
+
onReady={() => console.log('Rendered!')}
|
|
55
|
+
onError={(err) => console.error(err)}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Props
|
|
62
|
+
|
|
63
|
+
| Prop | Type | Default | Description |
|
|
64
|
+
|------|------|---------|-------------|
|
|
65
|
+
| `config` | `TemplateConfig` | — | Pre-resolved template config (Mode 1) |
|
|
66
|
+
| `templateId` | `string` | — | Template UUID (Mode 2) |
|
|
67
|
+
| `formSchemaId` | `string` | — | Form schema UUID (Mode 2) |
|
|
68
|
+
| `sectionState` | `SectionFormState` | — | V2 section state data (Mode 2) |
|
|
69
|
+
| `themeId` | `string` | `'default'` | Theme variant ID (Mode 2) |
|
|
70
|
+
| `supabaseUrl` | `string` | — | Supabase URL (Mode 2) |
|
|
71
|
+
| `supabaseAnonKey` | `string` | — | Supabase anon key (Mode 2) |
|
|
72
|
+
| `pageIndex` | `number` | `0` | Page index to render |
|
|
73
|
+
| `zoom` | `number` | auto-fit | Zoom/scale factor |
|
|
74
|
+
| `absoluteZoom` | `boolean` | `false` | Use zoom as-is without auto-fit |
|
|
75
|
+
| `imageProxyUrl` | `string` | — | CORS proxy URL for external images |
|
|
76
|
+
| `className` | `string` | — | CSS class for outer container |
|
|
77
|
+
| `onReady` | `() => void` | — | Called when rendering completes |
|
|
78
|
+
| `onError` | `(error: Error) => void` | — | Called on error |
|
|
79
|
+
|
|
80
|
+
## Imperative API
|
|
81
|
+
|
|
82
|
+
### Render from V2 sectionState (primary use case)
|
|
83
|
+
|
|
84
|
+
Same payload format as the Pixldocs server API (`/render-from-form`):
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { PixldocsRenderer } from '@pixldocs/canvas-renderer';
|
|
88
|
+
|
|
89
|
+
const renderer = new PixldocsRenderer({
|
|
90
|
+
supabaseUrl: 'https://xxx.supabase.co',
|
|
91
|
+
supabaseAnonKey: 'eyJ...',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const results = await renderer.renderFromForm({
|
|
95
|
+
templateId: 'dc3fbb17-b671-47cb-a4cf-643a10251fb2',
|
|
96
|
+
formSchemaId: 'b04cd362-a0ef-438d-a7a3-0e8560a709ce',
|
|
97
|
+
sectionState: {
|
|
98
|
+
section_abc: { full_name: 'John' },
|
|
99
|
+
section_def: [{ label: 'DOB', value: '1995-08-15' }],
|
|
100
|
+
},
|
|
101
|
+
themeId: 'default',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// results is an array of { dataUrl, width, height } for each page
|
|
105
|
+
for (const page of results) {
|
|
106
|
+
console.log(page.dataUrl); // data:image/png;base64,...
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Render a pre-resolved config
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const { dataUrl } = await renderer.render(templateConfig);
|
|
114
|
+
const allPages = await renderer.renderAllPages(templateConfig);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Render by template ID (simple flat data)
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
const result = await renderer.renderById('template-uuid', { name: 'John' });
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Data Resolution Utilities
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { resolveFromForm, resolveTemplateData } from '@pixldocs/canvas-renderer';
|
|
127
|
+
|
|
128
|
+
// V2: resolve from sectionState (same as server API)
|
|
129
|
+
const { config } = await resolveFromForm({
|
|
130
|
+
templateId: 'uuid',
|
|
131
|
+
formSchemaId: 'uuid',
|
|
132
|
+
sectionState: { ... },
|
|
133
|
+
supabaseUrl: '...', supabaseAnonKey: '...',
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Legacy: resolve with flat formData
|
|
137
|
+
const { config } = await resolveTemplateData({
|
|
138
|
+
templateId: 'uuid',
|
|
139
|
+
formData: { name: 'Jane' },
|
|
140
|
+
supabaseUrl: '...', supabaseAnonKey: '...',
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Peer Dependencies
|
|
145
|
+
|
|
146
|
+
- `fabric` ^6.0.0
|
|
147
|
+
- `react` ^18.0.0 || ^19.0.0
|
|
148
|
+
- `react-dom` ^18.0.0 || ^19.0.0
|