@pixldocs/canvas-renderer 0.5.54 → 0.5.56
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 +58 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +44 -8
- package/dist/index.js +58 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -482,16 +482,29 @@ export declare function resolveFromForm(options: ResolveFromFormOptions): Promis
|
|
|
482
482
|
export declare interface ResolveFromFormOptions {
|
|
483
483
|
/** Template UUID */
|
|
484
484
|
templateId: string;
|
|
485
|
-
/**
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
485
|
+
/**
|
|
486
|
+
* Form schema UUID. Optional — omit for templates with manual `dynamicFields`
|
|
487
|
+
* that are not bound to a saved form schema.
|
|
488
|
+
*/
|
|
489
|
+
formSchemaId?: string;
|
|
490
|
+
/**
|
|
491
|
+
* V2 section state (same shape sent to /render-from-form). Optional when
|
|
492
|
+
* `flatFormData` is provided (manual-fields path).
|
|
493
|
+
*/
|
|
494
|
+
sectionState?: SectionFormState;
|
|
495
|
+
/**
|
|
496
|
+
* Flat key/value map of dynamic-field values, keyed by `dynamicField.id`.
|
|
497
|
+
* Use this for manual-fields templates with no `formSchemaId` — values
|
|
498
|
+
* are applied directly through `applyFormDataToConfig` without going
|
|
499
|
+
* through the section-state flatten step.
|
|
500
|
+
*/
|
|
501
|
+
flatFormData?: Record<string, unknown>;
|
|
489
502
|
/** Optional theme variant ID (default: 'default') */
|
|
490
503
|
themeId?: string;
|
|
491
504
|
/** Supabase project URL */
|
|
492
|
-
supabaseUrl
|
|
505
|
+
supabaseUrl?: string;
|
|
493
506
|
/** Supabase anon key */
|
|
494
|
-
supabaseAnonKey
|
|
507
|
+
supabaseAnonKey?: string;
|
|
495
508
|
/** Optional prefetched rows from a trusted server so browser-side package resolution can skip REST fetches entirely. */
|
|
496
509
|
prefetched?: {
|
|
497
510
|
templateRow?: {
|
|
@@ -530,9 +543,24 @@ export declare interface ResolveOptions {
|
|
|
530
543
|
/** Optional flat formData (legacy, simple fields only) */
|
|
531
544
|
formData?: Record<string, any>;
|
|
532
545
|
/** Supabase project URL */
|
|
533
|
-
supabaseUrl
|
|
546
|
+
supabaseUrl?: string;
|
|
534
547
|
/** Supabase anon key */
|
|
535
|
-
supabaseAnonKey
|
|
548
|
+
supabaseAnonKey?: string;
|
|
549
|
+
/**
|
|
550
|
+
* Optional prefetched template row from a trusted server. When provided
|
|
551
|
+
* the resolver skips the REST fetch — useful for the EC2 v2 pipeline where
|
|
552
|
+
* the server already has the row in memory.
|
|
553
|
+
*/
|
|
554
|
+
prefetched?: {
|
|
555
|
+
templateRow?: {
|
|
556
|
+
id?: string;
|
|
557
|
+
name?: string;
|
|
558
|
+
price?: number;
|
|
559
|
+
config: TemplateConfig;
|
|
560
|
+
form_schema?: unknown;
|
|
561
|
+
default_data?: unknown;
|
|
562
|
+
};
|
|
563
|
+
};
|
|
536
564
|
}
|
|
537
565
|
|
|
538
566
|
export declare function resolveTemplateData(options: ResolveOptions): Promise<ResolvedTemplate>;
|
|
@@ -550,6 +578,14 @@ export declare function rewriteSvgFontsForJsPDF(svgStr: string): string;
|
|
|
550
578
|
|
|
551
579
|
export { SectionFormState }
|
|
552
580
|
|
|
581
|
+
/**
|
|
582
|
+
* Enable verbose console logs for the auto-shrink loop in the live preview.
|
|
583
|
+
* Logs target width, measured line widths, font availability, and the chosen
|
|
584
|
+
* fontSize for each text element with `overflowPolicy: 'auto-shrink'`.
|
|
585
|
+
* Disabled by default — call once from the host app when debugging.
|
|
586
|
+
*/
|
|
587
|
+
export declare function setAutoShrinkDebug(enabled: boolean): void;
|
|
588
|
+
|
|
553
589
|
export { setBundledAssetPrefixes }
|
|
554
590
|
|
|
555
591
|
export { SmartElementProps }
|
package/dist/index.js
CHANGED
|
@@ -5270,6 +5270,10 @@ function createText(element) {
|
|
|
5270
5270
|
const splitByGrapheme = overflowPolicy === "auto-shrink" ? false : element.splitByGrapheme ?? element.wordWrap === "break-word";
|
|
5271
5271
|
if (overflowPolicy === "auto-shrink") {
|
|
5272
5272
|
const explicitLineCount = Math.max(1, text.split("\n").length);
|
|
5273
|
+
const debugAutoShrink = typeof window !== "undefined" && window.__pixldocsDebugAutoShrink === true;
|
|
5274
|
+
const startFontSize = fontSize;
|
|
5275
|
+
let breakReason = "min-font-size-reached";
|
|
5276
|
+
let lastIter = null;
|
|
5273
5277
|
while (fontSize > 1) {
|
|
5274
5278
|
const testTextbox = new fabric.Textbox(text, {
|
|
5275
5279
|
width: fixedWidth,
|
|
@@ -5291,11 +5295,47 @@ function createText(element) {
|
|
|
5291
5295
|
const lineWidths = testTextbox.__lineWidths;
|
|
5292
5296
|
const maxLineWidth = lineWidths && lineWidths.length > 0 ? Math.max(...lineWidths) : 0;
|
|
5293
5297
|
const fitsWidth = !widthDidGrow && maxLineWidth <= fixedWidth + 1;
|
|
5298
|
+
if (debugAutoShrink) {
|
|
5299
|
+
lastIter = {
|
|
5300
|
+
fontSize,
|
|
5301
|
+
renderedLineCount,
|
|
5302
|
+
explicitLineCount,
|
|
5303
|
+
textHeight,
|
|
5304
|
+
maxLineWidth,
|
|
5305
|
+
fixedWidth,
|
|
5306
|
+
widthDidGrow,
|
|
5307
|
+
hasNoImplicitWrap,
|
|
5308
|
+
fitsHeight,
|
|
5309
|
+
fitsWidth
|
|
5310
|
+
};
|
|
5311
|
+
}
|
|
5294
5312
|
if (hasNoImplicitWrap && fitsHeight && fitsWidth) {
|
|
5313
|
+
breakReason = "fits";
|
|
5295
5314
|
break;
|
|
5296
5315
|
}
|
|
5297
5316
|
fontSize--;
|
|
5298
5317
|
}
|
|
5318
|
+
if (debugAutoShrink) {
|
|
5319
|
+
console.log("[auto-shrink][diag]", {
|
|
5320
|
+
id: element.id,
|
|
5321
|
+
name: element.name,
|
|
5322
|
+
text,
|
|
5323
|
+
fontFamily: element.fontFamily,
|
|
5324
|
+
fontWeight: element.fontWeight,
|
|
5325
|
+
elementWidth: element.width,
|
|
5326
|
+
elementHeight: element.height,
|
|
5327
|
+
scaleX: element.scaleX ?? 1,
|
|
5328
|
+
scaleY: element.scaleY ?? 1,
|
|
5329
|
+
fixedWidth,
|
|
5330
|
+
baseHeight,
|
|
5331
|
+
startFontSize,
|
|
5332
|
+
finalFontSize: fontSize,
|
|
5333
|
+
breakReason,
|
|
5334
|
+
lastIter,
|
|
5335
|
+
fontCheckRegular: typeof document !== "undefined" && document.fonts ? document.fonts.check(`16px "${element.fontFamily || "Open Sans"}"`) : null,
|
|
5336
|
+
fontCheckBold: typeof document !== "undefined" && document.fonts ? document.fonts.check(`bold 16px "${element.fontFamily || "Open Sans"}"`) : null
|
|
5337
|
+
});
|
|
5338
|
+
}
|
|
5299
5339
|
}
|
|
5300
5340
|
if (overflowPolicy === "max-lines-ellipsis") {
|
|
5301
5341
|
const originalText = element.text || "Text";
|
|
@@ -11674,8 +11714,8 @@ function deriveRepeatablePagesFromTemplate(config, inlineFormSchema, formData) {
|
|
|
11674
11714
|
return out;
|
|
11675
11715
|
}
|
|
11676
11716
|
async function resolveTemplateData(options) {
|
|
11677
|
-
const { templateId, formData, supabaseUrl, supabaseAnonKey } = options;
|
|
11678
|
-
const template = await fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId);
|
|
11717
|
+
const { templateId, formData, supabaseUrl, supabaseAnonKey, prefetched } = options;
|
|
11718
|
+
const template = (prefetched == null ? void 0 : prefetched.templateRow) ? prefetched.templateRow : await fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId);
|
|
11679
11719
|
let config = template.config;
|
|
11680
11720
|
const inlineFormSchema = template.form_schema;
|
|
11681
11721
|
const defaultData = template.default_data;
|
|
@@ -11742,7 +11782,16 @@ async function resolveTemplateData(options) {
|
|
|
11742
11782
|
}
|
|
11743
11783
|
async function resolveFromForm(options) {
|
|
11744
11784
|
var _a, _b, _c;
|
|
11745
|
-
const { templateId, formSchemaId, sectionState, themeId, supabaseUrl, supabaseAnonKey, prefetched } = options;
|
|
11785
|
+
const { templateId, formSchemaId, sectionState, flatFormData: directFlatFormData, themeId, supabaseUrl, supabaseAnonKey, prefetched } = options;
|
|
11786
|
+
if (!formSchemaId) {
|
|
11787
|
+
return resolveTemplateData({
|
|
11788
|
+
templateId,
|
|
11789
|
+
formData: directFlatFormData ?? sectionState ?? {},
|
|
11790
|
+
supabaseUrl,
|
|
11791
|
+
supabaseAnonKey,
|
|
11792
|
+
prefetched: (prefetched == null ? void 0 : prefetched.templateRow) ? { templateRow: prefetched.templateRow } : void 0
|
|
11793
|
+
});
|
|
11794
|
+
}
|
|
11746
11795
|
const [templateRow, formSchemaRow, defaultForm] = await Promise.all([
|
|
11747
11796
|
(prefetched == null ? void 0 : prefetched.templateRow) ? Promise.resolve(prefetched.templateRow) : fetchRow(supabaseUrl, supabaseAnonKey, "templates", templateId),
|
|
11748
11797
|
(prefetched == null ? void 0 : prefetched.formSchemaRow) !== void 0 ? Promise.resolve(prefetched.formSchemaRow) : fetchRow(supabaseUrl, supabaseAnonKey, "form_schemas", formSchemaId),
|
|
@@ -15452,6 +15501,11 @@ async function warmTemplateFromForm(options) {
|
|
|
15452
15501
|
if (signal == null ? void 0 : signal.aborted) return;
|
|
15453
15502
|
await warmResolvedTemplateForPreview(resolved.config, { signal, imageProxyUrl });
|
|
15454
15503
|
}
|
|
15504
|
+
function setAutoShrinkDebug(enabled) {
|
|
15505
|
+
if (typeof window !== "undefined") {
|
|
15506
|
+
window.__pixldocsDebugAutoShrink = !!enabled;
|
|
15507
|
+
}
|
|
15508
|
+
}
|
|
15455
15509
|
export {
|
|
15456
15510
|
FONT_FALLBACK_DEVANAGARI,
|
|
15457
15511
|
FONT_FALLBACK_SYMBOLS,
|
|
@@ -15480,6 +15534,7 @@ export {
|
|
|
15480
15534
|
resolveFromForm,
|
|
15481
15535
|
resolveTemplateData,
|
|
15482
15536
|
rewriteSvgFontsForJsPDF,
|
|
15537
|
+
setAutoShrinkDebug,
|
|
15483
15538
|
setBundledAssetPrefixes,
|
|
15484
15539
|
warmResolvedTemplateForPreview,
|
|
15485
15540
|
warmTemplateFromForm
|