@pixldocs/canvas-renderer 0.4.0 → 0.4.2
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/index.cjs +835 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +74 -0
- package/dist/index.js +835 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -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';
|
|
@@ -69,6 +70,25 @@ export declare interface DynamicField {
|
|
|
69
70
|
[key: string]: any;
|
|
70
71
|
}
|
|
71
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
|
+
|
|
72
92
|
/**
|
|
73
93
|
* Ensure all fonts required by a fully-resolved TemplateConfig are loaded
|
|
74
94
|
* and available to Fabric/Canvas before rendering.
|
|
@@ -87,6 +107,22 @@ export declare interface DynamicField {
|
|
|
87
107
|
*/
|
|
88
108
|
export declare function ensureFontsForResolvedConfig(config: TemplateConfig): Promise<void>;
|
|
89
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
|
+
|
|
90
126
|
/**
|
|
91
127
|
* Walk a fully-resolved TemplateConfig and collect every unique
|
|
92
128
|
* { fontFamily, fontWeight, fontStyle } tuple from all text nodes
|
|
@@ -98,8 +134,31 @@ export declare interface FontDescriptor {
|
|
|
98
134
|
style: string;
|
|
99
135
|
}
|
|
100
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
|
+
|
|
101
157
|
export { InferredSection }
|
|
102
158
|
|
|
159
|
+
/** Check if a font is in our local mapping */
|
|
160
|
+
export declare function isFontAvailable(fontName: string): boolean;
|
|
161
|
+
|
|
103
162
|
/**
|
|
104
163
|
* Load a Google Font by injecting a <link> stylesheet.
|
|
105
164
|
* Resolves when the font is ready for use.
|
|
@@ -126,6 +185,8 @@ export declare interface PdfAssemblyOptions {
|
|
|
126
185
|
filename?: string;
|
|
127
186
|
/** Whether to strip page background from SVG (drawn separately for gradient support) */
|
|
128
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;
|
|
129
190
|
}
|
|
130
191
|
|
|
131
192
|
/** Options for PDF rendering */
|
|
@@ -138,6 +199,8 @@ export declare interface PdfFromFormOptions {
|
|
|
138
199
|
watermark?: boolean;
|
|
139
200
|
/** PDF document title */
|
|
140
201
|
title?: string;
|
|
202
|
+
/** Base URL for TTF font files for PDF font embedding */
|
|
203
|
+
fontBaseUrl?: string;
|
|
141
204
|
}
|
|
142
205
|
|
|
143
206
|
export declare interface PdfRenderResult {
|
|
@@ -244,6 +307,7 @@ export declare class PixldocsRenderer {
|
|
|
244
307
|
*/
|
|
245
308
|
renderPdf(templateConfig: TemplateConfig, options?: {
|
|
246
309
|
title?: string;
|
|
310
|
+
fontBaseUrl?: string;
|
|
247
311
|
}): Promise<PdfRenderResult>;
|
|
248
312
|
/**
|
|
249
313
|
* Resolve from V2 sectionState and render a vector PDF.
|
|
@@ -331,6 +395,8 @@ export declare interface ResolvedTemplate {
|
|
|
331
395
|
price: number;
|
|
332
396
|
}
|
|
333
397
|
|
|
398
|
+
export declare function resolveFontWeight(weight: number): number;
|
|
399
|
+
|
|
334
400
|
/**
|
|
335
401
|
* Resolve a template using the V2 sectionState format.
|
|
336
402
|
* This is the primary API for external consumers and matches the server's /render-from-form pipeline.
|
|
@@ -366,6 +432,14 @@ export declare interface ResolveOptions {
|
|
|
366
432
|
|
|
367
433
|
export declare function resolveTemplateData(options: ResolveOptions): Promise<ResolvedTemplate>;
|
|
368
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
|
+
|
|
369
443
|
export { SectionFormState }
|
|
370
444
|
|
|
371
445
|
export { SmartElementProps }
|