@pdfme/schemas 6.0.3 → 6.0.5-dev.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.
Files changed (116) hide show
  1. package/dist/barcodes/constants.d.ts +4 -0
  2. package/dist/barcodes/helper.d.ts +21 -0
  3. package/dist/barcodes/index.d.ts +4 -0
  4. package/dist/barcodes/pdfRender.d.ts +3 -0
  5. package/dist/barcodes/propPanel.d.ts +3 -0
  6. package/{src/barcodes/types.ts → dist/barcodes/types.d.ts} +5 -7
  7. package/dist/barcodes/uiRender.d.ts +3 -0
  8. package/dist/builtins-CgaZ0UX3.js +613 -0
  9. package/dist/builtins-CgaZ0UX3.js.map +1 -0
  10. package/dist/builtins.d.ts +4 -0
  11. package/dist/builtins.js +2 -0
  12. package/dist/checkbox/index.d.ts +6 -0
  13. package/dist/constants.d.ts +2 -0
  14. package/dist/date/date.d.ts +2 -0
  15. package/dist/date/dateTime.d.ts +2 -0
  16. package/dist/date/helper.d.ts +20 -0
  17. package/dist/date/time.d.ts +2 -0
  18. package/dist/date/types.d.ts +17 -0
  19. package/dist/dynamicTemplate-D_DHR3-X.js +1128 -0
  20. package/dist/dynamicTemplate-D_DHR3-X.js.map +1 -0
  21. package/dist/graphics/image.d.ts +5 -0
  22. package/dist/graphics/imagehelper.d.ts +4 -0
  23. package/dist/graphics/signature.d.ts +4 -0
  24. package/dist/graphics/svg.d.ts +4 -0
  25. package/{src/index.ts → dist/index.d.ts} +1 -22
  26. package/dist/index.js +5383 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/multiVariableText/helper.d.ts +3 -0
  29. package/dist/multiVariableText/index.d.ts +4 -0
  30. package/dist/multiVariableText/pdfRender.d.ts +3 -0
  31. package/dist/multiVariableText/propPanel.d.ts +3 -0
  32. package/{src/multiVariableText/types.ts → dist/multiVariableText/types.d.ts} +2 -3
  33. package/dist/multiVariableText/uiRender.d.ts +3 -0
  34. package/dist/multiVariableText/variables.d.ts +10 -0
  35. package/dist/radioGroup/index.d.ts +7 -0
  36. package/dist/sanitize.d.ts +1 -0
  37. package/dist/select/index.d.ts +7 -0
  38. package/dist/shapes/line.d.ts +6 -0
  39. package/dist/shapes/rectAndEllipse.d.ts +11 -0
  40. package/dist/tables/cell.d.ts +4 -0
  41. package/dist/tables/classes.d.ts +69 -0
  42. package/dist/tables/dynamicTemplate.d.ts +7 -0
  43. package/dist/tables/helper.d.ts +265 -0
  44. package/dist/tables/index.d.ts +4 -0
  45. package/dist/tables/pdfRender.d.ts +3 -0
  46. package/dist/tables/propPanel.d.ts +3 -0
  47. package/dist/tables/tableHelper.d.ts +10 -0
  48. package/dist/tables/types.d.ts +88 -0
  49. package/dist/tables/uiRender.d.ts +3 -0
  50. package/dist/tables.js +2 -0
  51. package/dist/text/constants.d.ts +23 -0
  52. package/dist/text/extraFormatter.d.ts +25 -0
  53. package/dist/text/helper.d.ts +40 -0
  54. package/dist/text/icons/index.d.ts +9 -0
  55. package/dist/text/index.d.ts +4 -0
  56. package/dist/text/pdfRender.d.ts +3 -0
  57. package/dist/text/propPanel.d.ts +3 -0
  58. package/dist/text/types.d.ts +28 -0
  59. package/dist/text/uiRender.d.ts +11 -0
  60. package/dist/utils.d.ts +40 -0
  61. package/dist/utils.js +215 -0
  62. package/dist/utils.js.map +1 -0
  63. package/package.json +5 -1
  64. package/src/barcodes/constants.ts +0 -20
  65. package/src/barcodes/helper.ts +0 -187
  66. package/src/barcodes/index.ts +0 -23
  67. package/src/barcodes/pdfRender.ts +0 -37
  68. package/src/barcodes/propPanel.ts +0 -249
  69. package/src/barcodes/uiRender.ts +0 -94
  70. package/src/builtins.ts +0 -8
  71. package/src/checkbox/index.ts +0 -70
  72. package/src/constants.ts +0 -2
  73. package/src/date/date.ts +0 -9
  74. package/src/date/dateTime.ts +0 -9
  75. package/src/date/helper.ts +0 -544
  76. package/src/date/time.ts +0 -9
  77. package/src/date/types.ts +0 -19
  78. package/src/graphics/image.ts +0 -201
  79. package/src/graphics/imagehelper.ts +0 -156
  80. package/src/graphics/signature.ts +0 -136
  81. package/src/graphics/svg.ts +0 -121
  82. package/src/multiVariableText/helper.ts +0 -65
  83. package/src/multiVariableText/index.ts +0 -16
  84. package/src/multiVariableText/pdfRender.ts +0 -21
  85. package/src/multiVariableText/propPanel.ts +0 -169
  86. package/src/multiVariableText/uiRender.ts +0 -157
  87. package/src/multiVariableText/variables.ts +0 -63
  88. package/src/radioGroup/index.ts +0 -115
  89. package/src/sanitize.ts +0 -50
  90. package/src/select/index.ts +0 -205
  91. package/src/shapes/line.ts +0 -94
  92. package/src/shapes/rectAndEllipse.ts +0 -152
  93. package/src/tables/cell.ts +0 -152
  94. package/src/tables/classes.ts +0 -402
  95. package/src/tables/dynamicTemplate.ts +0 -88
  96. package/src/tables/helper.ts +0 -216
  97. package/src/tables/index.ts +0 -15
  98. package/src/tables/pdfRender.ts +0 -144
  99. package/src/tables/propPanel.ts +0 -111
  100. package/src/tables/tableHelper.ts +0 -289
  101. package/src/tables/types.ts +0 -87
  102. package/src/tables/uiRender.ts +0 -436
  103. package/src/text/constants.ts +0 -104
  104. package/src/text/extraFormatter.ts +0 -83
  105. package/src/text/helper.ts +0 -573
  106. package/src/text/icons/index.ts +0 -30
  107. package/src/text/index.ts +0 -16
  108. package/src/text/pdfRender.ts +0 -240
  109. package/src/text/propPanel.ts +0 -184
  110. package/src/text/types.ts +0 -30
  111. package/src/text/uiRender.ts +0 -292
  112. package/src/utils.ts +0 -354
  113. package/tsconfig.build.json +0 -14
  114. package/tsconfig.json +0 -16
  115. package/vite.config.mts +0 -51
  116. /package/{src/tables.ts → dist/tables.d.ts} +0 -0
@@ -0,0 +1,4 @@
1
+ export declare const BARCODE_TYPES: readonly ["qrcode", "japanpost", "ean13", "ean8", "code39", "code128", "nw7", "itf14", "upca", "upce", "gs1datamatrix", "pdf417"];
2
+ export declare const DEFAULT_BARCODE_BG_COLOR = "#ffffff";
3
+ export declare const DEFAULT_BARCODE_COLOR = "#000000";
4
+ export declare const DEFAULT_BARCODE_INCLUDETEXT = true;
@@ -0,0 +1,21 @@
1
+ import { Buffer } from 'buffer';
2
+ import { BarcodeTypes } from './types.js';
3
+ export declare const validateBarcodeInput: (type: BarcodeTypes, input: string) => boolean;
4
+ /**
5
+ * The bwip.js lib has a different name for nw7 type barcodes
6
+ */
7
+ export declare const barCodeType2Bcid: (type: BarcodeTypes) => "qrcode" | "japanpost" | "ean13" | "ean8" | "code39" | "code128" | "itf14" | "upca" | "upce" | "gs1datamatrix" | "pdf417" | "rationalizedCodabar";
8
+ /**
9
+ * Strip hash from the beginning of HTML hex color codes for the bwip.js lib
10
+ */
11
+ export declare const mapHexColorForBwipJsLib: (color: string | undefined, fallback?: string) => string;
12
+ export declare const createBarCode: (arg: {
13
+ type: BarcodeTypes;
14
+ input: string;
15
+ width: number;
16
+ height: number;
17
+ backgroundColor?: string;
18
+ barColor?: string;
19
+ textColor?: string;
20
+ includetext?: boolean;
21
+ }) => Promise<Buffer>;
@@ -0,0 +1,4 @@
1
+ import type { BarcodeSchema } from './types.js';
2
+ import { Plugin } from '@pdfme/common';
3
+ declare const barcodes: Record<"qrcode" | "japanpost" | "ean13" | "ean8" | "code39" | "code128" | "nw7" | "itf14" | "upca" | "upce" | "gs1datamatrix" | "pdf417", Plugin<BarcodeSchema>>;
4
+ export default barcodes;
@@ -0,0 +1,3 @@
1
+ import { PDFRenderProps } from '@pdfme/common';
2
+ import type { BarcodeSchema } from './types.js';
3
+ export declare const pdfRender: (arg: PDFRenderProps<BarcodeSchema>) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { PropPanel } from '@pdfme/common';
2
+ import type { BarcodeSchema } from './types.js';
3
+ export declare const getPropPanelByBarcodeType: (barcodeType: string) => PropPanel<BarcodeSchema>;
@@ -1,12 +1,10 @@
1
1
  import { Schema } from '@pdfme/common';
2
2
  import { BARCODE_TYPES } from './constants.js';
3
-
4
3
  export type BarcodeSchema = Schema & {
5
- type: (typeof BARCODE_TYPES)[number];
6
- backgroundColor: string;
7
- barColor: string;
8
- textColor?: string;
9
- includetext?: boolean;
4
+ type: (typeof BARCODE_TYPES)[number];
5
+ backgroundColor: string;
6
+ barColor: string;
7
+ textColor?: string;
8
+ includetext?: boolean;
10
9
  };
11
-
12
10
  export type BarcodeTypes = (typeof BARCODE_TYPES)[number];
@@ -0,0 +1,3 @@
1
+ import { UIRenderProps } from '@pdfme/common';
2
+ import type { BarcodeSchema } from './types.js';
3
+ export declare const uiRender: (arg: UIRenderProps<BarcodeSchema>) => Promise<void>;
@@ -0,0 +1,613 @@
1
+ import { C as DEFAULT_FONT_COLOR, D as VERTICAL_ALIGN_BOTTOM, E as PLACEHOLDER_FONT_COLOR, O as VERTICAL_ALIGN_MIDDLE, S as DEFAULT_DYNAMIC_FIT, T as DYNAMIC_FIT_VERTICAL, _ as widthOfTextAtSize, b as ALIGN_RIGHT, d as getBrowserVerticalFontAdjustments, f as getFontDescentInPt, g as splitTextToSize, h as isFirefox, l as calculateDynamicFontSize, m as heightOfFontAtSize, p as getFontKitFont, s as HEX_COLOR_PATTERN, u as fetchRemoteFontData, v as ALIGN_CENTER, w as DYNAMIC_FIT_HORIZONTAL, x as DEFAULT_ALIGNMENT, y as ALIGN_JUSTIFY } from "./dynamicTemplate-D_DHR3-X.js";
2
+ import { convertForPdfLayoutProps, createSvgStr, hex2PrintingColor, isEditable, rotatePoint } from "./utils.js";
3
+ import { DEFAULT_FONT_NAME, getDefaultFont, getFallbackFontName, mm2pt } from "@pdfme/common";
4
+ import { AlignCenter, AlignJustify, AlignLeft, AlignRight, ArrowDownToLine, ArrowUpToLine, Strikethrough, TextCursorInput, Underline } from "lucide";
5
+ //#region src/text/pdfRender.ts
6
+ var embedAndGetFontObj = async (arg) => {
7
+ const { pdfDoc, font, _cache } = arg;
8
+ if (_cache.has(pdfDoc)) return _cache.get(pdfDoc);
9
+ const fontValues = await Promise.all(Object.values(font).map(async (v) => {
10
+ let fontData = v.data;
11
+ if (typeof fontData === "string" && fontData.startsWith("http")) fontData = await fetchRemoteFontData(fontData);
12
+ return pdfDoc.embedFont(fontData, { subset: typeof v.subset === "undefined" ? true : v.subset });
13
+ }));
14
+ const fontObj = Object.keys(font).reduce((acc, cur, i) => Object.assign(acc, { [cur]: fontValues[i] }), {});
15
+ _cache.set(pdfDoc, fontObj);
16
+ return fontObj;
17
+ };
18
+ var getFontProp = ({ value, fontKitFont, schema, colorType }) => {
19
+ const fontSize = schema.dynamicFontSize ? calculateDynamicFontSize({
20
+ textSchema: schema,
21
+ fontKitFont,
22
+ value
23
+ }) : schema.fontSize ?? 13;
24
+ const color = hex2PrintingColor(schema.fontColor || "#000000", colorType);
25
+ return {
26
+ alignment: schema.alignment ?? "left",
27
+ verticalAlignment: schema.verticalAlignment ?? "top",
28
+ lineHeight: schema.lineHeight ?? 1,
29
+ characterSpacing: schema.characterSpacing ?? 0,
30
+ fontSize,
31
+ color
32
+ };
33
+ };
34
+ var pdfRender = async (arg) => {
35
+ const { value, pdfDoc, pdfLib, page, options, schema, _cache } = arg;
36
+ if (!value) return;
37
+ const { font = getDefaultFont(), colorType } = options;
38
+ const [pdfFontObj, fontKitFont] = await Promise.all([embedAndGetFontObj({
39
+ pdfDoc,
40
+ font,
41
+ _cache
42
+ }), getFontKitFont(schema.fontName, font, _cache)]);
43
+ const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = getFontProp({
44
+ value,
45
+ fontKitFont,
46
+ schema,
47
+ colorType
48
+ });
49
+ const fontName = schema.fontName ? schema.fontName : getFallbackFontName(font);
50
+ const pdfFontValue = pdfFontObj && pdfFontObj[fontName];
51
+ const pageHeight = page.getHeight();
52
+ const { width, height, rotate, position: { x, y }, opacity } = convertForPdfLayoutProps({
53
+ schema,
54
+ pageHeight,
55
+ applyRotateTranslate: false
56
+ });
57
+ const pivotPoint = {
58
+ x: x + width / 2,
59
+ y: pageHeight - mm2pt(schema.position.y) - height / 2
60
+ };
61
+ if (schema.backgroundColor) {
62
+ const color = hex2PrintingColor(schema.backgroundColor, colorType);
63
+ if (rotate.angle !== 0) {
64
+ const rotatedPoint = rotatePoint({
65
+ x,
66
+ y
67
+ }, pivotPoint, rotate.angle);
68
+ page.drawRectangle({
69
+ x: rotatedPoint.x,
70
+ y: rotatedPoint.y,
71
+ width,
72
+ height,
73
+ rotate,
74
+ color
75
+ });
76
+ } else page.drawRectangle({
77
+ x,
78
+ y,
79
+ width,
80
+ height,
81
+ rotate,
82
+ color
83
+ });
84
+ }
85
+ const firstLineTextHeight = heightOfFontAtSize(fontKitFont, fontSize);
86
+ const descent = getFontDescentInPt(fontKitFont, fontSize);
87
+ const halfLineHeightAdjustment = lineHeight === 0 ? 0 : (lineHeight - 1) * fontSize / 2;
88
+ const lines = splitTextToSize({
89
+ value,
90
+ characterSpacing,
91
+ fontSize,
92
+ fontKitFont,
93
+ boxWidthInPt: width
94
+ });
95
+ let yOffset = 0;
96
+ if (verticalAlignment === "top") yOffset = firstLineTextHeight + halfLineHeightAdjustment;
97
+ else {
98
+ const otherLinesHeight = lineHeight * fontSize * (lines.length - 1);
99
+ if (verticalAlignment === "bottom") yOffset = height - otherLinesHeight + descent - halfLineHeightAdjustment;
100
+ else if (verticalAlignment === "middle") yOffset = (height - otherLinesHeight - firstLineTextHeight + descent) / 2 + firstLineTextHeight;
101
+ }
102
+ const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
103
+ lines.forEach((line, rowIndex) => {
104
+ const trimmed = line.replace("\n", "");
105
+ const textWidth = widthOfTextAtSize(trimmed, fontKitFont, fontSize, characterSpacing);
106
+ const textHeight = heightOfFontAtSize(fontKitFont, fontSize);
107
+ const rowYOffset = lineHeight * fontSize * rowIndex;
108
+ if (line === "") line = "\r\n";
109
+ let xLine = x;
110
+ if (alignment === "center") xLine += (width - textWidth) / 2;
111
+ else if (alignment === "right") xLine += width - textWidth;
112
+ let yLine = pageHeight - mm2pt(schema.position.y) - yOffset - rowYOffset;
113
+ if (schema.strikethrough && textWidth > 0) {
114
+ const _x = xLine + textWidth + 1;
115
+ const _y = yLine + textHeight / 3;
116
+ page.drawLine({
117
+ start: rotatePoint({
118
+ x: xLine,
119
+ y: _y
120
+ }, pivotPoint, rotate.angle),
121
+ end: rotatePoint({
122
+ x: _x,
123
+ y: _y
124
+ }, pivotPoint, rotate.angle),
125
+ thickness: 1 / 12 * fontSize,
126
+ color,
127
+ opacity
128
+ });
129
+ }
130
+ if (schema.underline && textWidth > 0) {
131
+ const _x = xLine + textWidth + 1;
132
+ const _y = yLine - textHeight / 12;
133
+ page.drawLine({
134
+ start: rotatePoint({
135
+ x: xLine,
136
+ y: _y
137
+ }, pivotPoint, rotate.angle),
138
+ end: rotatePoint({
139
+ x: _x,
140
+ y: _y
141
+ }, pivotPoint, rotate.angle),
142
+ thickness: 1 / 12 * fontSize,
143
+ color,
144
+ opacity
145
+ });
146
+ }
147
+ if (rotate.angle !== 0) {
148
+ const rotatedPoint = rotatePoint({
149
+ x: xLine,
150
+ y: yLine
151
+ }, pivotPoint, rotate.angle);
152
+ xLine = rotatedPoint.x;
153
+ yLine = rotatedPoint.y;
154
+ }
155
+ let spacing = characterSpacing;
156
+ if (alignment === "justify" && line.slice(-1) !== "\n") {
157
+ const iterator = segmenter.segment(trimmed)[Symbol.iterator]();
158
+ const len = Array.from(iterator).length;
159
+ spacing += (width - textWidth) / len;
160
+ }
161
+ page.pushOperators(pdfLib.setCharacterSpacing(spacing));
162
+ page.drawText(trimmed, {
163
+ x: xLine,
164
+ y: yLine,
165
+ rotate,
166
+ size: fontSize,
167
+ color,
168
+ lineHeight: lineHeight * fontSize,
169
+ font: pdfFontValue,
170
+ opacity
171
+ });
172
+ });
173
+ };
174
+ //#endregion
175
+ //#region src/text/icons/index.ts
176
+ var TextStrikethroughIcon = createSvgStr(Strikethrough);
177
+ var TextUnderlineIcon = createSvgStr(Underline);
178
+ var TextAlignLeftIcon = createSvgStr(AlignLeft);
179
+ var TextAlignCenterIcon = createSvgStr(AlignCenter);
180
+ var TextAlignRightIcon = createSvgStr(AlignRight);
181
+ var TextAlignJustifyIcon = createSvgStr(AlignJustify);
182
+ var TextVerticalAlignTopIcon = createSvgStr(ArrowUpToLine);
183
+ var TextVerticalAlignMiddleIcon = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><path d="M8 19h3v4h2v-4h3l-4-4l-4 4zm8-14h-3V1h-2v4H8l4 4l4-4zM4 11v2h16v-2H4z" fill="currentColor"></path></svg>`;
184
+ var TextVerticalAlignBottomIcon = createSvgStr(ArrowDownToLine);
185
+ //#endregion
186
+ //#region src/text/extraFormatter.ts
187
+ var Formatter = /* @__PURE__ */ function(Formatter) {
188
+ Formatter["STRIKETHROUGH"] = "strikethrough";
189
+ Formatter["UNDERLINE"] = "underline";
190
+ Formatter["ALIGNMENT"] = "alignment";
191
+ Formatter["VERTICAL_ALIGNMENT"] = "verticalAlignment";
192
+ return Formatter;
193
+ }({});
194
+ function getExtraFormatterSchema(i18n) {
195
+ const buttons = [
196
+ {
197
+ key: Formatter.STRIKETHROUGH,
198
+ icon: TextStrikethroughIcon,
199
+ type: "boolean"
200
+ },
201
+ {
202
+ key: Formatter.UNDERLINE,
203
+ icon: TextUnderlineIcon,
204
+ type: "boolean"
205
+ },
206
+ {
207
+ key: Formatter.ALIGNMENT,
208
+ icon: TextAlignLeftIcon,
209
+ type: "select",
210
+ value: DEFAULT_ALIGNMENT
211
+ },
212
+ {
213
+ key: Formatter.ALIGNMENT,
214
+ icon: TextAlignCenterIcon,
215
+ type: "select",
216
+ value: ALIGN_CENTER
217
+ },
218
+ {
219
+ key: Formatter.ALIGNMENT,
220
+ icon: TextAlignRightIcon,
221
+ type: "select",
222
+ value: ALIGN_RIGHT
223
+ },
224
+ {
225
+ key: Formatter.ALIGNMENT,
226
+ icon: TextAlignJustifyIcon,
227
+ type: "select",
228
+ value: ALIGN_JUSTIFY
229
+ },
230
+ {
231
+ key: Formatter.VERTICAL_ALIGNMENT,
232
+ icon: TextVerticalAlignTopIcon,
233
+ type: "select",
234
+ value: "top"
235
+ },
236
+ {
237
+ key: Formatter.VERTICAL_ALIGNMENT,
238
+ icon: TextVerticalAlignMiddleIcon,
239
+ type: "select",
240
+ value: VERTICAL_ALIGN_MIDDLE
241
+ },
242
+ {
243
+ key: Formatter.VERTICAL_ALIGNMENT,
244
+ icon: TextVerticalAlignBottomIcon,
245
+ type: "select",
246
+ value: VERTICAL_ALIGN_BOTTOM
247
+ }
248
+ ];
249
+ return {
250
+ title: i18n("schemas.text.format"),
251
+ widget: "ButtonGroup",
252
+ buttons,
253
+ span: 24
254
+ };
255
+ }
256
+ //#endregion
257
+ //#region src/text/propPanel.ts
258
+ var UseDynamicFontSize = (props) => {
259
+ const { rootElement, changeSchemas, activeSchema, i18n } = props;
260
+ const checkbox = document.createElement("input");
261
+ checkbox.type = "checkbox";
262
+ checkbox.checked = Boolean(activeSchema?.dynamicFontSize);
263
+ checkbox.onchange = (e) => {
264
+ changeSchemas([{
265
+ key: "dynamicFontSize",
266
+ value: e.target.checked ? {
267
+ min: 4,
268
+ max: 72,
269
+ fit: DEFAULT_DYNAMIC_FIT
270
+ } : void 0,
271
+ schemaId: activeSchema.id
272
+ }]);
273
+ };
274
+ const label = document.createElement("label");
275
+ const span = document.createElement("span");
276
+ span.innerText = i18n("schemas.text.dynamicFontSize") || "";
277
+ span.style.cssText = "margin-left: 0.5rem";
278
+ label.style.cssText = "display: flex; width: 100%;";
279
+ label.appendChild(checkbox);
280
+ label.appendChild(span);
281
+ rootElement.appendChild(label);
282
+ };
283
+ var propPanel = {
284
+ schema: ({ options, activeSchema, i18n }) => {
285
+ const font = options.font || { [DEFAULT_FONT_NAME]: {
286
+ data: "",
287
+ fallback: true
288
+ } };
289
+ const fontNames = Object.keys(font);
290
+ const fallbackFontName = getFallbackFontName(font);
291
+ const enableDynamicFont = Boolean(activeSchema?.dynamicFontSize);
292
+ return {
293
+ fontName: {
294
+ title: i18n("schemas.text.fontName"),
295
+ type: "string",
296
+ widget: "select",
297
+ default: fallbackFontName,
298
+ placeholder: fallbackFontName,
299
+ props: { options: fontNames.map((name) => ({
300
+ label: name,
301
+ value: name
302
+ })) },
303
+ span: 12
304
+ },
305
+ fontSize: {
306
+ title: i18n("schemas.text.size"),
307
+ type: "number",
308
+ widget: "inputNumber",
309
+ span: 6,
310
+ disabled: enableDynamicFont,
311
+ props: { min: 0 }
312
+ },
313
+ characterSpacing: {
314
+ title: i18n("schemas.text.spacing"),
315
+ type: "number",
316
+ widget: "inputNumber",
317
+ span: 6,
318
+ props: { min: 0 }
319
+ },
320
+ formatter: getExtraFormatterSchema(i18n),
321
+ lineHeight: {
322
+ title: i18n("schemas.text.lineHeight"),
323
+ type: "number",
324
+ widget: "inputNumber",
325
+ props: {
326
+ step: .1,
327
+ min: 0
328
+ },
329
+ span: 8
330
+ },
331
+ useDynamicFontSize: {
332
+ type: "boolean",
333
+ widget: "UseDynamicFontSize",
334
+ bind: false,
335
+ span: 16
336
+ },
337
+ dynamicFontSize: {
338
+ type: "object",
339
+ widget: "card",
340
+ column: 3,
341
+ properties: {
342
+ min: {
343
+ title: i18n("schemas.text.min"),
344
+ type: "number",
345
+ widget: "inputNumber",
346
+ hidden: !enableDynamicFont,
347
+ props: { min: 0 }
348
+ },
349
+ max: {
350
+ title: i18n("schemas.text.max"),
351
+ type: "number",
352
+ widget: "inputNumber",
353
+ hidden: !enableDynamicFont,
354
+ props: { min: 0 }
355
+ },
356
+ fit: {
357
+ title: i18n("schemas.text.fit"),
358
+ type: "string",
359
+ widget: "select",
360
+ hidden: !enableDynamicFont,
361
+ props: { options: [{
362
+ label: i18n("schemas.horizontal"),
363
+ value: DYNAMIC_FIT_HORIZONTAL
364
+ }, {
365
+ label: i18n("schemas.vertical"),
366
+ value: DYNAMIC_FIT_VERTICAL
367
+ }] }
368
+ }
369
+ }
370
+ },
371
+ fontColor: {
372
+ title: i18n("schemas.textColor"),
373
+ type: "string",
374
+ widget: "color",
375
+ props: { disabledAlpha: true },
376
+ rules: [{
377
+ pattern: HEX_COLOR_PATTERN,
378
+ message: i18n("validation.hexColor")
379
+ }]
380
+ },
381
+ backgroundColor: {
382
+ title: i18n("schemas.bgColor"),
383
+ type: "string",
384
+ widget: "color",
385
+ props: { disabledAlpha: true },
386
+ rules: [{
387
+ pattern: HEX_COLOR_PATTERN,
388
+ message: i18n("validation.hexColor")
389
+ }]
390
+ }
391
+ };
392
+ },
393
+ widgets: { UseDynamicFontSize },
394
+ defaultSchema: {
395
+ name: "",
396
+ type: "text",
397
+ content: "Type Something...",
398
+ position: {
399
+ x: 0,
400
+ y: 0
401
+ },
402
+ width: 45,
403
+ height: 10,
404
+ rotate: 0,
405
+ alignment: DEFAULT_ALIGNMENT,
406
+ verticalAlignment: "top",
407
+ fontSize: 13,
408
+ lineHeight: 1,
409
+ characterSpacing: 0,
410
+ dynamicFontSize: void 0,
411
+ fontColor: DEFAULT_FONT_COLOR,
412
+ fontName: void 0,
413
+ backgroundColor: "",
414
+ opacity: 1,
415
+ strikethrough: false,
416
+ underline: false
417
+ }
418
+ };
419
+ //#endregion
420
+ //#region src/text/uiRender.ts
421
+ var replaceUnsupportedChars = (text, fontKitFont) => {
422
+ const charSupportCache = {};
423
+ const isCharSupported = (char) => {
424
+ if (char in charSupportCache) return charSupportCache[char];
425
+ const isSupported = fontKitFont.hasGlyphForCodePoint(char.codePointAt(0) || 0);
426
+ charSupportCache[char] = isSupported;
427
+ return isSupported;
428
+ };
429
+ return text.split(/(\r\n|\n|\r)/).map((segment) => {
430
+ if (/\r\n|\n|\r/.test(segment)) return segment;
431
+ return segment.split("").map((char) => {
432
+ if (/\s/.test(char) || char.charCodeAt(0) < 32) return char;
433
+ return isCharSupported(char) ? char : "〿";
434
+ }).join("");
435
+ }).join("");
436
+ };
437
+ var uiRender = async (arg) => {
438
+ const { value, schema, mode, onChange, stopEditing, tabIndex, placeholder, options, _cache } = arg;
439
+ const usePlaceholder = isEditable(mode, schema) && placeholder && !value;
440
+ const getText = (element) => {
441
+ let text = element.innerText;
442
+ if (text.endsWith("\n")) text = text.slice(0, -1);
443
+ return text;
444
+ };
445
+ const font = options?.font || getDefaultFont();
446
+ const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
447
+ const textBlock = buildStyledTextContainer(arg, fontKitFont, usePlaceholder ? placeholder : value);
448
+ const processedText = replaceUnsupportedChars(value, fontKitFont);
449
+ if (!isEditable(mode, schema)) {
450
+ textBlock.innerHTML = processedText.split("").map((l, i) => {
451
+ const escaped = l.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
452
+ return `<span style="letter-spacing:${String(value).length === i + 1 ? 0 : "inherit"};">${escaped}</span>`;
453
+ }).join("");
454
+ return;
455
+ }
456
+ makeElementPlainTextContentEditable(textBlock);
457
+ textBlock.tabIndex = tabIndex || 0;
458
+ textBlock.innerText = mode === "designer" ? value : processedText;
459
+ textBlock.addEventListener("blur", (e) => {
460
+ if (onChange) onChange({
461
+ key: "content",
462
+ value: getText(e.target)
463
+ });
464
+ if (stopEditing) stopEditing();
465
+ });
466
+ if (schema.dynamicFontSize) {
467
+ let dynamicFontSize = void 0;
468
+ textBlock.addEventListener("keyup", () => {
469
+ setTimeout(() => {
470
+ (() => {
471
+ if (!textBlock.textContent) return;
472
+ dynamicFontSize = calculateDynamicFontSize({
473
+ textSchema: schema,
474
+ fontKitFont,
475
+ value: getText(textBlock),
476
+ startingFontSize: dynamicFontSize
477
+ });
478
+ textBlock.style.fontSize = `${dynamicFontSize}pt`;
479
+ const { topAdj: newTopAdj, bottomAdj: newBottomAdj } = getBrowserVerticalFontAdjustments(fontKitFont, dynamicFontSize ?? schema.fontSize ?? 13, schema.lineHeight ?? 1, schema.verticalAlignment ?? "top");
480
+ textBlock.style.paddingTop = `${newTopAdj}px`;
481
+ textBlock.style.marginBottom = `${newBottomAdj}px`;
482
+ })();
483
+ }, 0);
484
+ });
485
+ }
486
+ if (usePlaceholder) {
487
+ textBlock.style.color = PLACEHOLDER_FONT_COLOR;
488
+ textBlock.addEventListener("focus", () => {
489
+ if (textBlock.innerText === placeholder) {
490
+ textBlock.innerText = "";
491
+ textBlock.style.color = schema.fontColor ?? "#000000";
492
+ }
493
+ });
494
+ }
495
+ if (mode === "designer") setTimeout(() => {
496
+ textBlock.focus();
497
+ const selection = window.getSelection();
498
+ const range = document.createRange();
499
+ if (selection && range) {
500
+ range.selectNodeContents(textBlock);
501
+ range.collapse(false);
502
+ selection?.removeAllRanges();
503
+ selection?.addRange(range);
504
+ }
505
+ });
506
+ };
507
+ var buildStyledTextContainer = (arg, fontKitFont, value) => {
508
+ const { schema, rootElement, mode } = arg;
509
+ let dynamicFontSize = void 0;
510
+ if (schema.dynamicFontSize && value) dynamicFontSize = calculateDynamicFontSize({
511
+ textSchema: schema,
512
+ fontKitFont,
513
+ value,
514
+ startingFontSize: dynamicFontSize
515
+ });
516
+ const { topAdj, bottomAdj } = getBrowserVerticalFontAdjustments(fontKitFont, dynamicFontSize ?? schema.fontSize ?? 13, schema.lineHeight ?? 1, schema.verticalAlignment ?? "top");
517
+ const topAdjustment = topAdj.toString();
518
+ const bottomAdjustment = bottomAdj.toString();
519
+ const container = document.createElement("div");
520
+ const containerStyle = {
521
+ padding: 0,
522
+ resize: "none",
523
+ backgroundColor: getBackgroundColor(value, schema),
524
+ border: "none",
525
+ display: "flex",
526
+ flexDirection: "column",
527
+ justifyContent: mapVerticalAlignToFlex(schema.verticalAlignment),
528
+ width: "100%",
529
+ height: "100%",
530
+ cursor: isEditable(mode, schema) ? "text" : "default"
531
+ };
532
+ Object.assign(container.style, containerStyle);
533
+ rootElement.innerHTML = "";
534
+ rootElement.appendChild(container);
535
+ const textDecorations = [];
536
+ if (schema.strikethrough) textDecorations.push("line-through");
537
+ if (schema.underline) textDecorations.push("underline");
538
+ const textBlockStyle = {
539
+ fontFamily: schema.fontName ? `'${schema.fontName}'` : "inherit",
540
+ color: schema.fontColor ? schema.fontColor : DEFAULT_FONT_COLOR,
541
+ fontSize: `${dynamicFontSize ?? schema.fontSize ?? 13}pt`,
542
+ letterSpacing: `${schema.characterSpacing ?? 0}pt`,
543
+ lineHeight: `${schema.lineHeight ?? 1}em`,
544
+ textAlign: schema.alignment ?? "left",
545
+ whiteSpace: "pre-wrap",
546
+ wordBreak: "break-word",
547
+ resize: "none",
548
+ border: "none",
549
+ outline: "none",
550
+ marginBottom: `${bottomAdjustment}px`,
551
+ paddingTop: `${topAdjustment}px`,
552
+ backgroundColor: "transparent",
553
+ textDecoration: textDecorations.join(" ")
554
+ };
555
+ const textBlock = document.createElement("div");
556
+ textBlock.id = "text-" + String(schema.id);
557
+ Object.assign(textBlock.style, textBlockStyle);
558
+ container.appendChild(textBlock);
559
+ return textBlock;
560
+ };
561
+ /**
562
+ * Firefox doesn't support 'plaintext-only' contentEditable mode, which we want to avoid mark-up.
563
+ * This function adds a workaround for Firefox to make the contentEditable element behave like 'plaintext-only'.
564
+ */
565
+ var makeElementPlainTextContentEditable = (element) => {
566
+ if (!isFirefox()) {
567
+ element.contentEditable = "plaintext-only";
568
+ return;
569
+ }
570
+ element.contentEditable = "true";
571
+ element.addEventListener("keydown", (e) => {
572
+ if (e.key === "Enter" && !e.shiftKey) {
573
+ e.preventDefault();
574
+ document.execCommand("insertLineBreak", false, void 0);
575
+ }
576
+ });
577
+ element.addEventListener("paste", (e) => {
578
+ e.preventDefault();
579
+ const paste = e.clipboardData?.getData("text");
580
+ const selection = window.getSelection();
581
+ if (!selection?.rangeCount) return;
582
+ selection.deleteFromDocument();
583
+ selection.getRangeAt(0).insertNode(document.createTextNode(paste || ""));
584
+ selection.collapseToEnd();
585
+ });
586
+ };
587
+ var mapVerticalAlignToFlex = (verticalAlignmentValue) => {
588
+ switch (verticalAlignmentValue) {
589
+ case "top": return "flex-start";
590
+ case VERTICAL_ALIGN_MIDDLE: return "center";
591
+ case VERTICAL_ALIGN_BOTTOM: return "flex-end";
592
+ }
593
+ return "flex-start";
594
+ };
595
+ var getBackgroundColor = (value, schema) => {
596
+ if (!value || !schema.backgroundColor) return "transparent";
597
+ return schema.backgroundColor;
598
+ };
599
+ //#endregion
600
+ //#region src/text/index.ts
601
+ var textSchema = {
602
+ pdf: pdfRender,
603
+ ui: uiRender,
604
+ propPanel,
605
+ icon: createSvgStr(TextCursorInput)
606
+ };
607
+ //#endregion
608
+ //#region src/builtins.ts
609
+ var builtInPlugins = { Text: textSchema };
610
+ //#endregion
611
+ export { mapVerticalAlignToFlex as a, Formatter as c, makeElementPlainTextContentEditable as i, getExtraFormatterSchema as l, textSchema as n, uiRender as o, buildStyledTextContainer as r, propPanel as s, builtInPlugins as t, pdfRender as u };
612
+
613
+ //# sourceMappingURL=builtins-CgaZ0UX3.js.map