@pixldocs/canvas-renderer 0.3.28 → 0.4.1
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 +35 -0
- package/dist/index.cjs +1880 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +125 -1
- package/dist/index.js +1880 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InferredSection } from '../../../src/lib/inferFormSchemaFromTemplate';
|
|
2
|
+
import { jsPDF } from 'jspdf';
|
|
2
3
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
3
4
|
import { SectionFormState } from '../../../src/lib/inferFormSchemaFromTemplate';
|
|
4
5
|
import { SmartElementProps } from '../../../shared/smart-elements/types';
|
|
@@ -13,6 +14,12 @@ import { SmartElementType } from '../../../shared/smart-elements/types';
|
|
|
13
14
|
*/
|
|
14
15
|
export declare function applyThemeToConfig(config: TemplateConfig, themeOverrides: ThemeVariables): TemplateConfig;
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Assemble a vector PDF from SVG render results.
|
|
19
|
+
* This is the core function that converts canvas SVGs into a multi-page PDF document.
|
|
20
|
+
*/
|
|
21
|
+
export declare function assemblePdfFromSvgs(svgResults: SvgRenderResult[], options?: PdfAssemblyOptions): Promise<PdfRenderResult>;
|
|
22
|
+
|
|
16
23
|
export declare interface CanvasNode {
|
|
17
24
|
id: string;
|
|
18
25
|
name?: string;
|
|
@@ -63,6 +70,25 @@ export declare interface DynamicField {
|
|
|
63
70
|
[key: string]: any;
|
|
64
71
|
}
|
|
65
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Load and embed a single font weight into jsPDF.
|
|
75
|
+
* Each weight is registered as a SEPARATE jsPDF font name like "JosefinSans-SemiBold"
|
|
76
|
+
* with style "normal". This is the key difference from the old approach.
|
|
77
|
+
*/
|
|
78
|
+
export declare function embedFont(pdf: jsPDF, fontName: string, weight: number, fontBaseUrl: string, isItalic?: boolean): Promise<boolean>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Walk a template config to discover all font families/weights,
|
|
82
|
+
* then embed each one into jsPDF. Also embeds symbol + devanagari fallbacks.
|
|
83
|
+
*/
|
|
84
|
+
export declare function embedFontsForConfig(pdf: jsPDF, config: any, fontBaseUrl: string): Promise<Set<string>>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated Use embedFontsForConfig + rewriteSvgFontsForJsPDF instead.
|
|
88
|
+
* Embed all required fonts into a jsPDF instance using the old approach.
|
|
89
|
+
*/
|
|
90
|
+
export declare function embedFontsInPdf(pdf: jsPDF, fontFamilies: Set<string>, fontBaseUrl: string): Promise<Set<string>>;
|
|
91
|
+
|
|
66
92
|
/**
|
|
67
93
|
* Ensure all fonts required by a fully-resolved TemplateConfig are loaded
|
|
68
94
|
* and available to Fabric/Canvas before rendering.
|
|
@@ -81,6 +107,22 @@ export declare interface DynamicField {
|
|
|
81
107
|
*/
|
|
82
108
|
export declare function ensureFontsForResolvedConfig(config: TemplateConfig): Promise<void>;
|
|
83
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Extract all unique font-family values from SVG strings.
|
|
112
|
+
*/
|
|
113
|
+
export declare function extractFontFamiliesFromSvgs(svgs: string[]): Set<string>;
|
|
114
|
+
|
|
115
|
+
/** Font used for Devanagari / Hindi script */
|
|
116
|
+
export declare const FONT_FALLBACK_DEVANAGARI = "Hind";
|
|
117
|
+
|
|
118
|
+
/** Font used for symbols (● ◆ ★ etc.) */
|
|
119
|
+
export declare const FONT_FALLBACK_SYMBOLS = "Noto Sans";
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Maps font family names to their TTF file names (relative to fontBaseUrl).
|
|
123
|
+
*/
|
|
124
|
+
export declare const FONT_FILES: Record<string, FontWeightFiles>;
|
|
125
|
+
|
|
84
126
|
/**
|
|
85
127
|
* Walk a fully-resolved TemplateConfig and collect every unique
|
|
86
128
|
* { fontFamily, fontWeight, fontStyle } tuple from all text nodes
|
|
@@ -92,8 +134,31 @@ export declare interface FontDescriptor {
|
|
|
92
134
|
style: string;
|
|
93
135
|
}
|
|
94
136
|
|
|
137
|
+
declare type FontWeightFiles = {
|
|
138
|
+
regular: string;
|
|
139
|
+
bold?: string;
|
|
140
|
+
light?: string;
|
|
141
|
+
medium?: string;
|
|
142
|
+
semibold?: string;
|
|
143
|
+
italic?: string;
|
|
144
|
+
boldItalic?: string;
|
|
145
|
+
lightItalic?: string;
|
|
146
|
+
mediumItalic?: string;
|
|
147
|
+
semiboldItalic?: string;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Get the embedded jsPDF font name for a given font family + weight + italic.
|
|
152
|
+
* This is the name used for pdf.setFont() and must match the font-family
|
|
153
|
+
* attribute rewritten in SVG text elements.
|
|
154
|
+
*/
|
|
155
|
+
export declare function getEmbeddedJsPDFFontName(fontName: string, weight: number, isItalic?: boolean): string;
|
|
156
|
+
|
|
95
157
|
export { InferredSection }
|
|
96
158
|
|
|
159
|
+
/** Check if a font is in our local mapping */
|
|
160
|
+
export declare function isFontAvailable(fontName: string): boolean;
|
|
161
|
+
|
|
97
162
|
/**
|
|
98
163
|
* Load a Google Font by injecting a <link> stylesheet.
|
|
99
164
|
* Resolves when the font is ready for use.
|
|
@@ -113,6 +178,45 @@ export declare interface PageSettings {
|
|
|
113
178
|
contentBottom?: number;
|
|
114
179
|
}
|
|
115
180
|
|
|
181
|
+
export declare interface PdfAssemblyOptions {
|
|
182
|
+
/** PDF document title */
|
|
183
|
+
title?: string;
|
|
184
|
+
/** Output filename hint */
|
|
185
|
+
filename?: string;
|
|
186
|
+
/** Whether to strip page background from SVG (drawn separately for gradient support) */
|
|
187
|
+
stripPageBackground?: boolean;
|
|
188
|
+
/** Base URL for TTF font files (e.g. 'https://pixldocs.com/fonts/' or '/fonts/'). Required for correct font rendering. */
|
|
189
|
+
fontBaseUrl?: string;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Options for PDF rendering */
|
|
193
|
+
export declare interface PdfFromFormOptions {
|
|
194
|
+
templateId: string;
|
|
195
|
+
formSchemaId: string;
|
|
196
|
+
sectionState: SectionFormState;
|
|
197
|
+
themeId?: string;
|
|
198
|
+
/** Whether to inject watermark. Default: auto (true for paid templates, false for free). */
|
|
199
|
+
watermark?: boolean;
|
|
200
|
+
/** PDF document title */
|
|
201
|
+
title?: string;
|
|
202
|
+
/** Base URL for TTF font files for PDF font embedding */
|
|
203
|
+
fontBaseUrl?: string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export declare interface PdfRenderResult {
|
|
207
|
+
/** PDF as a Blob */
|
|
208
|
+
blob: Blob;
|
|
209
|
+
/** PDF as ArrayBuffer */
|
|
210
|
+
arrayBuffer: ArrayBuffer;
|
|
211
|
+
/** Total number of pages */
|
|
212
|
+
totalPages: number;
|
|
213
|
+
/** Page dimensions (CSS pixels) */
|
|
214
|
+
pages: Array<{
|
|
215
|
+
width: number;
|
|
216
|
+
height: number;
|
|
217
|
+
}>;
|
|
218
|
+
}
|
|
219
|
+
|
|
116
220
|
export declare function PixldocsPreview(props: PixldocsPreviewProps): JSX_2.Element;
|
|
117
221
|
|
|
118
222
|
declare interface PixldocsPreviewBaseProps {
|
|
@@ -198,8 +302,18 @@ export declare class PixldocsRenderer {
|
|
|
198
302
|
*/
|
|
199
303
|
renderSvgsFromForm(options: Omit<RenderFromFormOptions, 'format' | 'quality' | 'scale' | 'pixelRatio'>): Promise<SvgRenderResult[]>;
|
|
200
304
|
/**
|
|
201
|
-
*
|
|
305
|
+
* Render a pre-resolved template config to a vector PDF.
|
|
306
|
+
* Returns a Blob and ArrayBuffer.
|
|
307
|
+
*/
|
|
308
|
+
renderPdf(templateConfig: TemplateConfig, options?: {
|
|
309
|
+
title?: string;
|
|
310
|
+
fontBaseUrl?: string;
|
|
311
|
+
}): Promise<PdfRenderResult>;
|
|
312
|
+
/**
|
|
313
|
+
* Resolve from V2 sectionState and render a vector PDF.
|
|
314
|
+
* This is the primary PDF export API — mirrors renderFromForm() but returns a PDF.
|
|
202
315
|
*/
|
|
316
|
+
renderPdfFromForm(options: PdfFromFormOptions): Promise<PdfRenderResult>;
|
|
203
317
|
renderById(templateId: string, formData?: Record<string, any>, options?: RenderOptions): Promise<RenderResult>;
|
|
204
318
|
/**
|
|
205
319
|
* Convenience: fetch by ID with flat data and render ALL pages.
|
|
@@ -281,6 +395,8 @@ export declare interface ResolvedTemplate {
|
|
|
281
395
|
price: number;
|
|
282
396
|
}
|
|
283
397
|
|
|
398
|
+
export declare function resolveFontWeight(weight: number): number;
|
|
399
|
+
|
|
284
400
|
/**
|
|
285
401
|
* Resolve a template using the V2 sectionState format.
|
|
286
402
|
* This is the primary API for external consumers and matches the server's /render-from-form pipeline.
|
|
@@ -316,6 +432,14 @@ export declare interface ResolveOptions {
|
|
|
316
432
|
|
|
317
433
|
export declare function resolveTemplateData(options: ResolveOptions): Promise<ResolvedTemplate>;
|
|
318
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Rewrite font-family attributes in SVG <text>/<tspan> to match jsPDF embedded font names.
|
|
437
|
+
* CRITICAL: Also sets font-weight to "normal" because the weight is already baked into
|
|
438
|
+
* the jsPDF font name (e.g. JosefinSans-SemiBold). Without this, svg2pdf combines
|
|
439
|
+
* font-weight + font-style into "600normal" which won't match fonts registered with style "normal".
|
|
440
|
+
*/
|
|
441
|
+
export declare function rewriteSvgFontsForJsPDF(svgStr: string): string;
|
|
442
|
+
|
|
319
443
|
export { SectionFormState }
|
|
320
444
|
|
|
321
445
|
export { SmartElementProps }
|