import { z } from 'zod'; import type { PDFPage, PDFDocument } from '@pdfme/pdf-lib'; import type { ThemeConfig, GlobalToken } from 'antd'; import type { WidgetProps as _PropPanelWidgetProps, Schema as _PropPanelSchema } from 'form-render'; import { Lang, Dict, Mode, Size, Schema, Font, SchemaForUI, BasePdf, BlankPdf, CustomPdf, CommonOptions, Template, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ColorType, LegacySchemaPageArray, SchemaPageArray, } from './schema.js'; export type PropPanelSchema = _PropPanelSchema; export type ChangeSchemaItem = { key: string; value: unknown; schemaId: string; }; export type ChangeSchemas = (objs: ChangeSchemaItem[]) => void; /** * Properties used for PDF rendering. * @template T Type of the extended Schema object. * @property {string} value The string used for PDF rendering. * @property {T} schema Extended Schema object for rendering. * @property {BasePdf} basePdf Base PDF object for rendering. * @property {typeof import('@pdfme/pdf-lib')} pdfLib The pdf-lib library used for rendering. * @property {PDFDocument} pdfDoc PDFDocument object from pdf-lib. * @property {PDFPage} page PDFPage object from pdf-lib. * @property {GeneratorOptions} options Options object passed from the generator. * @property {Map} _cache Cache shared only during the execution of the generate function (useful for caching images, etc. if needed). */ export interface PDFRenderProps { value: string; schema: T; basePdf: BasePdf; pdfLib: typeof import('@pdfme/pdf-lib'); pdfDoc: PDFDocument; page: PDFPage; options: GeneratorOptions; _cache: Map; } /** * Type for properties used in UI rendering. * * @template T - Type of the extended Schema object. * @property {T} schema - Extended Schema object for rendering. * @property {BasePdf} basePdf Base PDF object for rendering. * @property {Mode} mode - String indicating the rendering state. 'designer' is only used when the field is in edit mode in the Designer. * @property {number} [tabIndex] - Tab index for Form. * @property {string} [placeholder] - Placeholder text for Form. * @property {() => void} [stopEditing] - Stops editing mode, can be used when the mode is 'designer'. * @property {string} value - The string used for UI rendering. * @property {(arg: { key: string; value: unknown } | { key: string; value: unknown }[]) => void} [onChange] - Used to change the value and schema properties. Only applicable when the mode is 'form' or 'designer'. * @property {HTMLDivElement} rootElement - The root HTMLDivElement for the UI. * @property {UIOptions} options - Options object passed from the Viewer, Form, or Designer. * @property {ThemeConfig} theme - An object that merges the 'theme' passed as an options with the default theme. * @property {(key: keyof Dict | string) => string} i18n - An object merged based on the options 'lang' and 'labels'. * @property {Map} _cache - Cache shared only during the execution of the render function (useful for caching images, etc. if needed). */ export type UIRenderProps = { schema: T; basePdf: BasePdf; mode: Mode; tabIndex?: number; placeholder?: string; stopEditing?: () => void; value: string; onChange?: (arg: { key: string; value: unknown } | { key: string; value: unknown }[]) => void; rootElement: HTMLDivElement; options: UIOptions; theme: GlobalToken; i18n: (key: string) => string; _cache: Map; }; /** * Type for properties used in configuring the property panel. * * @property {HTMLDivElement} rootElement - The root HTML element of the property panel. * @property {SchemaForUI} activeSchema - The currently active schema for UI rendering. * @property {HTMLElement[]} activeElements - Array of currently active HTML elements in the UI. * @property {ChangeSchemas} changeSchemas - Function to change multiple schemas simultaneously. * @property {SchemaForUI[]} schemas - Array of schemas for UI rendering. * @property {Size} pageSize - The size of the page being edited. * @property {UIOptions} options - UI options for the property panel. * @property {GlobalToken} theme - The theme configuration used in the UI. * @property {(key: keyof Dict | string) => string} i18n - Internationalization dictionary for UI labels and texts. */ type PropPanelProps = { rootElement: HTMLDivElement; activeSchema: SchemaForUI; activeElements: HTMLElement[]; changeSchemas: ChangeSchemas; schemas: SchemaForUI[]; options: UIOptions; theme: GlobalToken; i18n: (key: string) => string; }; export type PropPanelWidgetProps = _PropPanelWidgetProps & PropPanelProps; /** * Used for customizing the property panel. * @template T - Type of the extended Schema object. * @property {Record | ((propPanelProps: Omit) => Record)} schema - A function returning a form-render schema object or the schema object itself. When a function, it takes properties passed from the designer as arguments. * @property {Record void>} [widgets] - An object of functions returning form-render widgets. The functions take, as arguments, both form-render's WidgetProps and properties passed from the designer. * @property {T} defaultSchema - The default schema set when adding the schema. */ export interface PropPanel { schema: | ((propPanelProps: Omit) => Record) | Record; widgets?: Record void>; defaultSchema: T; } /** * The Plugin interface is used for PDF and UI rendering, as well as defining the property panel. * The 'pdf' is used in the generator package, 'ui' is used in the viewer, form, and designer packages, and 'propPanel' is used in the designer package. * Objects defined as Plugins using this interface can be used with a consistent interface across all packages. * @template T Type of the extended Schema object. * @property {function} pdf Function for rendering PDFs. * @property {function} ui Function for rendering UI. * @property {PropPanel} propPanel Object for defining the property panel. * @property {string} [icon] Icon SVG for the plugin. * @property {boolean} [uninterruptedEditMode] When editing in the UI, should the field avoid re-rendering while in edit mode? */ export type Plugin = { pdf: (arg: PDFRenderProps) => Promise | void; ui: (arg: UIRenderProps) => Promise | void; propPanel: PropPanel; icon?: string; uninterruptedEditMode?: boolean; }; // eslint-disable-next-line @typescript-eslint/no-explicit-any export type Plugins = { [key: string]: Plugin }; export interface PluginRegistry { plugins: { [key: string]: Plugin }; exists(): boolean; values(): Plugin[]; entries(): [string, Plugin][]; findByType(type: string): Plugin | undefined; findWithLabelByType(type: string): [string, Plugin|undefined]; } export type Lang = z.infer; export type Dict = z.infer; export type Mode = z.infer; export type Size = z.infer; export type Schema = z.infer; export type SchemaForUI = z.infer; /** * Represents the Font type definition. * @property {Object} [x: string] - Object key is the font name. * @property {(string | ArrayBuffer | Uint8Array)} data - The font data. * @property {boolean} [fallback] - Please set to true for the fallback font when no font is specified. Only one value within the given Font object needs to be set to true. * @property {boolean} [subset] - The default is true (use subset font). So if you don't want to use a subset font, please set it to false. */ export type Font = z.infer; export type ColorType = z.infer; export type BasePdf = z.infer; export type BlankPdf = z.infer; export type CustomPdf = z.infer; export type Template = z.infer; export type CommonOptions = z.infer; export type GeneratorOptions = z.infer; export type GenerateProps = z.infer & { plugins?: Plugins }; export type UIOptions = z.infer & { theme?: ThemeConfig }; export type UIProps = z.infer & { plugins?: Plugins }; export type PreviewProps = z.infer & { plugins?: Plugins }; export type DesignerProps = z.infer & { plugins?: Plugins }; export type SchemaPageArray = z.infer; export type LegacySchemaPageArray = z.infer;