@pdfme/schemas 6.1.0 → 6.1.1-dev.11

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 (62) hide show
  1. package/dist/{builtins-C0BvXHWr.js → builtins-Clh58o_b.js} +313 -483
  2. package/dist/builtins-Clh58o_b.js.map +1 -0
  3. package/dist/builtins.d.ts +1 -1
  4. package/dist/builtins.js +1 -1
  5. package/dist/checkbox/index.d.ts +2 -2
  6. package/dist/dynamicLayout.d.ts +4 -0
  7. package/dist/dynamicLayout.js +20 -0
  8. package/dist/dynamicLayout.js.map +1 -0
  9. package/dist/dynamicTemplate-CB2Hj9cN.js +65 -0
  10. package/dist/dynamicTemplate-CB2Hj9cN.js.map +1 -0
  11. package/dist/{dynamicTemplate-Dsrw11aL.js → dynamicTemplate-CjbGepw4.js} +24 -358
  12. package/dist/dynamicTemplate-CjbGepw4.js.map +1 -0
  13. package/dist/dynamicTemplate-Fn7mpUsu.js +114 -0
  14. package/dist/dynamicTemplate-Fn7mpUsu.js.map +1 -0
  15. package/dist/graphics/image.d.ts +1 -1
  16. package/dist/graphics/signature.d.ts +1 -1
  17. package/dist/helper-BJzBqIT4.js +40 -0
  18. package/dist/helper-BJzBqIT4.js.map +1 -0
  19. package/dist/index.d.ts +5 -2
  20. package/dist/index.js +847 -205
  21. package/dist/index.js.map +1 -1
  22. package/dist/list/constants.d.ts +10 -0
  23. package/dist/list/dynamicTemplate.d.ts +2 -0
  24. package/dist/list/helper.d.ts +15 -0
  25. package/dist/list/index.d.ts +4 -0
  26. package/dist/list/pdfRender.d.ts +3 -0
  27. package/dist/list/propPanel.d.ts +3 -0
  28. package/dist/list/types.d.ts +31 -0
  29. package/dist/list/uiRender.d.ts +3 -0
  30. package/dist/lists.d.ts +4 -0
  31. package/dist/lists.js +3 -0
  32. package/dist/measure-Bjmh9Ro3.js +585 -0
  33. package/dist/measure-Bjmh9Ro3.js.map +1 -0
  34. package/dist/multiVariableText/dynamicTemplate.d.ts +2 -0
  35. package/dist/radioGroup/index.d.ts +2 -2
  36. package/dist/select/index.d.ts +2 -2
  37. package/dist/shapes/line.d.ts +1 -1
  38. package/dist/shapes/rectAndEllipse.d.ts +1 -2
  39. package/dist/splitRange-CpXivbmJ.js +398 -0
  40. package/dist/splitRange-CpXivbmJ.js.map +1 -0
  41. package/dist/splitRange.d.ts +16 -0
  42. package/dist/tables/dynamicTemplate.d.ts +2 -1
  43. package/dist/tables/helper.d.ts +8 -8
  44. package/dist/tables.d.ts +2 -1
  45. package/dist/tables.js +3 -2
  46. package/dist/text/constants.d.ts +3 -0
  47. package/dist/text/dynamicTemplate.d.ts +2 -0
  48. package/dist/text/linkAnnotation.d.ts +14 -0
  49. package/dist/text/measure.d.ts +26 -0
  50. package/dist/text/overflow.d.ts +7 -0
  51. package/dist/text/richTextPdfRender.d.ts +2 -1
  52. package/dist/text/types.d.ts +3 -0
  53. package/dist/texts.d.ts +5 -0
  54. package/dist/texts.js +4 -0
  55. package/dist/types.d.ts +15 -0
  56. package/dist/types.js +0 -0
  57. package/dist/utils.d.ts +1 -0
  58. package/dist/utils.js +3 -2
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +21 -1
  61. package/dist/builtins-C0BvXHWr.js.map +0 -1
  62. package/dist/dynamicTemplate-Dsrw11aL.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,11 +1,16 @@
1
- import { B as VERTICAL_ALIGN_MIDDLE, C as DEFAULT_ALIGNMENT, F as SYNTHETIC_BOLD_CSS_TEXT_SHADOW, T as DEFAULT_FONT_COLOR, a as getColumnStylesPropPanelSchema, c as createSingleTable, i as getCellPropPanelSchema, n as getBody, o as getDefaultCellStyles, p as getFontKitFont, r as getBodyWithRange, s as HEX_COLOR_PATTERN, t as getDynamicHeightsForTable, x as CODE_BACKGROUND_COLOR } from "./dynamicTemplate-Dsrw11aL.js";
2
- import { a as mapVerticalAlignToFlex, c as Formatter, d as isInlineMarkdownTextSchema, f as resolveFontVariant, i as makeElementPlainTextContentEditable, l as getExtraFormatterSchema, m as parseInlineMarkdown, n as textSchema, o as uiRender$3, p as escapeInlineMarkdown, r as buildStyledTextContainer, s as propPanel$2, t as builtInPlugins, u as pdfRender$3 } from "./builtins-C0BvXHWr.js";
1
+ import { E as DEFAULT_ALIGNMENT, K as VERTICAL_ALIGN_MIDDLE, O as DEFAULT_FONT_COLOR, R as PLACEHOLDER_FONT_COLOR, a as createListItemSplitRange, c as getListItemRange, h as getFontKitFont, i as TEXT_LINE_SPLIT_UNIT, l as getTableBodyRange, n as LIST_ITEM_SPLIT_UNIT, o as createTableBodySplitRange, r as TABLE_BODY_SPLIT_UNIT, s as createTextLineSplitRange, t as BUILT_IN_DYNAMIC_LAYOUT_SPLIT_UNITS, u as getTextLineRange, w as CODE_BACKGROUND_COLOR, z as SYNTHETIC_BOLD_CSS_TEXT_SHADOW } from "./splitRange-CpXivbmJ.js";
2
+ import { d as resolveFontVariant, l as isInlineMarkdownTextSchema, m as parseInlineMarkdown } from "./measure-Bjmh9Ro3.js";
3
+ import { a as mapVerticalAlignToFlex, c as Formatter, i as makeElementPlainTextContentEditable, l as getExtraFormatterSchema, n as textSchema, o as uiRender$4, r as buildStyledTextContainer, s as propPanel$3, t as builtInPlugins, u as pdfRender$4 } from "./builtins-Clh58o_b.js";
4
+ import { a as getCellPropPanelSchema, c as HEX_COLOR_PATTERN, i as getBodyWithSchemaRange, l as createSingleTable, n as getDynamicLayoutForTable, o as getColumnStylesPropPanelSchema, r as getBody, s as getDefaultCellStyles, t as getDynamicHeightsForTable } from "./dynamicTemplate-CjbGepw4.js";
3
5
  import { addAlphaToHex, convertForPdfLayoutProps, createErrorElm, createSvgStr, hex2PrintingColor, isEditable, readFile, rotatePoint } from "./utils.js";
6
+ import { a as normalizeListItems, c as LIST_STYLE_BULLET, i as normalizeListItemEntries, l as LIST_STYLE_ORDERED, n as calculateListLayout, o as serializeListItems, s as DEFAULT_LIST_STYLE, t as getDynamicLayoutForList } from "./dynamicTemplate-Fn7mpUsu.js";
7
+ import { n as substituteVariablesAsInlineMarkdownLiterals, r as validateVariables, t as substituteVariables } from "./helper-BJzBqIT4.js";
4
8
  import "./tables.js";
9
+ import "./lists.js";
5
10
  import { DEFAULT_FONT_NAME, ZOOM, b64toUint8Array, getDefaultFont, getFallbackFontName, mm2pt, px2mm } from "@pdfme/common";
6
11
  import { Buffer as Buffer$1 } from "buffer";
7
12
  import { toRadians } from "@pdfme/pdf-lib";
8
- import { Barcode, Calendar, CalendarClock, ChevronDown, Circle, CircleDot, Clock, Image, Minus, QrCode, Route, Square, SquareCheck, Table, Type } from "lucide";
13
+ import { Barcode, Calendar, CalendarClock, ChevronDown, Circle, CircleDot, Clock, Image, List, Minus, QrCode, Route, Square, SquareCheck, Table, Type } from "lucide";
9
14
  import DOMPurify from "dompurify";
10
15
  import bwipjs from "bwip-js";
11
16
  import AirDatepicker from "air-datepicker";
@@ -34,47 +39,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
39
  enumerable: true
35
40
  }) : target, mod));
36
41
  //#endregion
37
- //#region src/multiVariableText/helper.ts
38
- var substituteVariables = (text, variablesIn, valueMapper = (value) => value) => {
39
- if (!text) return "";
40
- let substitutedText = text;
41
- if (variablesIn) {
42
- let variables;
43
- try {
44
- variables = typeof variablesIn === "string" ? JSON.parse(variablesIn || "{}") : variablesIn;
45
- } catch {
46
- throw new SyntaxError(`[@pdfme/schemas] MVT: invalid JSON string '${variablesIn}'`);
47
- }
48
- Object.keys(variables).forEach((variableName) => {
49
- const variableForRegex = variableName.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
50
- const regex = new RegExp("\\{" + variableForRegex + "\\}", "g");
51
- substitutedText = substitutedText.replace(regex, valueMapper(variables[variableName], variableName));
52
- });
53
- }
54
- substitutedText = substitutedText.replace(/{[^{}]+}/g, "");
55
- return substitutedText;
56
- };
57
- var substituteVariablesAsInlineMarkdownLiterals = (text, variablesIn) => substituteVariables(text, variablesIn, escapeInlineMarkdown);
58
- var validateVariables = (value, schema) => {
59
- if (schema.variables.length === 0) return true;
60
- let values;
61
- try {
62
- values = value ? JSON.parse(value) : {};
63
- } catch {
64
- throw new SyntaxError(`[@pdfme/generator] invalid JSON string '${value}' for variables in field ${schema.name}`);
65
- }
66
- for (const variable of schema.variables) if (!values[variable]) {
67
- if (schema.required) throw new Error(`[@pdfme/generator] variable ${variable} is missing for field ${schema.name}`);
68
- return false;
69
- }
70
- return true;
71
- };
72
- //#endregion
73
42
  //#region src/multiVariableText/pdfRender.ts
74
- var pdfRender$2 = async (arg) => {
43
+ var pdfRender$3 = async (arg) => {
75
44
  const { value, schema, ...rest } = arg;
45
+ if (schema.readOnly) {
46
+ await pdfRender$4({
47
+ value,
48
+ schema,
49
+ ...rest
50
+ });
51
+ return;
52
+ }
76
53
  if (!validateVariables(value, schema)) return;
77
- await pdfRender$3({
54
+ await pdfRender$4({
78
55
  value: isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(schema.text || "", value) : substituteVariables(schema.text || "", value),
79
56
  schema,
80
57
  ...rest
@@ -184,10 +161,10 @@ var mapDynamicVariables = (props) => {
184
161
  rootElement.appendChild(para);
185
162
  }
186
163
  };
187
- var propPanel$1 = {
164
+ var propPanel$2 = {
188
165
  schema: (propPanelProps) => {
189
- if (typeof propPanel$2.schema !== "function") throw new Error("Oops, is text schema no longer a function?");
190
- const parentSchema = typeof propPanel$2.schema === "function" ? propPanel$2.schema(propPanelProps) : {};
166
+ if (typeof propPanel$3.schema !== "function") throw new Error("Oops, is text schema no longer a function?");
167
+ const parentSchema = typeof propPanel$3.schema === "function" ? propPanel$3.schema(propPanelProps) : {};
191
168
  const i18n = propPanelProps.i18n;
192
169
  return {
193
170
  ...parentSchema,
@@ -225,11 +202,11 @@ var propPanel$1 = {
225
202
  };
226
203
  },
227
204
  widgets: {
228
- ...propPanel$2.widgets,
205
+ ...propPanel$3.widgets,
229
206
  mapDynamicVariables
230
207
  },
231
208
  defaultSchema: {
232
- ...propPanel$2.defaultSchema,
209
+ ...propPanel$3.defaultSchema,
233
210
  readOnly: false,
234
211
  type: "multiVariableText",
235
212
  text: "Add text here using {} for variables ",
@@ -262,16 +239,27 @@ var updateVariablesFromText = (text, variables) => {
262
239
  };
263
240
  //#endregion
264
241
  //#region src/multiVariableText/uiRender.ts
265
- var uiRender$2 = async (arg) => {
242
+ var uiRender$3 = async (arg) => {
266
243
  const { value, schema, rootElement, mode, onChange, ...rest } = arg;
267
244
  let text = schema.text;
268
245
  let numVariables = schema.variables.length;
269
- if (mode === "form" && numVariables > 0) {
246
+ const renderResolvedValue = schema.readOnly === true && mode !== "designer";
247
+ const renderValue = renderResolvedValue ? value : isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(text, value) : substituteVariables(text, value);
248
+ if (mode === "form" && numVariables > 0 && !renderResolvedValue) {
249
+ if (getTextLineRange(schema)) {
250
+ await uiRender$4({
251
+ value: renderValue,
252
+ schema,
253
+ mode: "viewer",
254
+ rootElement,
255
+ ...rest
256
+ });
257
+ return;
258
+ }
270
259
  await formUiRender(arg);
271
260
  return;
272
261
  }
273
- const renderValue = isInlineMarkdownTextSchema(schema) ? substituteVariablesAsInlineMarkdownLiterals(text, value) : substituteVariables(text, value);
274
- await uiRender$3({
262
+ await uiRender$4({
275
263
  value: isEditable(mode, schema) ? text : renderValue,
276
264
  schema,
277
265
  mode: mode === "form" ? "viewer" : mode,
@@ -373,7 +361,9 @@ var applyInlineMarkdownStyle = (arg) => {
373
361
  element.style.textShadow = SYNTHETIC_BOLD_CSS_TEXT_SHADOW;
374
362
  }
375
363
  if (resolvedFont.syntheticItalic) element.style.fontStyle = "italic";
376
- if (run.strikethrough) element.style.textDecoration = "line-through";
364
+ const textDecorations = [];
365
+ if (run.strikethrough) textDecorations.push("line-through");
366
+ if (textDecorations.length > 0) element.style.textDecoration = textDecorations.join(" ");
377
367
  if (run.code) {
378
368
  element.style.backgroundColor = CODE_BACKGROUND_COLOR;
379
369
  element.style.borderRadius = "2px";
@@ -470,11 +460,775 @@ var keyPressShouldBeChecked = (event) => {
470
460
  //#endregion
471
461
  //#region src/multiVariableText/index.ts
472
462
  var schema$1 = {
463
+ pdf: pdfRender$3,
464
+ ui: uiRender$3,
465
+ propPanel: propPanel$2,
466
+ icon: createSvgStr(Type),
467
+ uninterruptedEditMode: true
468
+ };
469
+ //#endregion
470
+ //#region src/shapes/rectAndEllipse.ts
471
+ var shape = {
472
+ ui: (arg) => {
473
+ const { schema, rootElement } = arg;
474
+ const div = document.createElement("div");
475
+ div.style.width = "100%";
476
+ div.style.height = "100%";
477
+ div.style.boxSizing = "border-box";
478
+ if (schema.type === "ellipse") div.style.borderRadius = "50%";
479
+ else if (schema.radius && schema.radius > 0) div.style.borderRadius = `${schema.radius}mm`;
480
+ div.style.borderWidth = `${schema.borderWidth ?? 0}mm`;
481
+ div.style.borderStyle = schema.borderWidth && schema.borderColor ? "solid" : "none";
482
+ div.style.borderColor = schema.borderColor ?? "transparent";
483
+ div.style.backgroundColor = schema.color ?? "transparent";
484
+ rootElement.appendChild(div);
485
+ },
486
+ pdf: (arg) => {
487
+ const { schema, page, options } = arg;
488
+ if (!schema.color && !schema.borderColor) return;
489
+ const { colorType } = options;
490
+ const cArg = {
491
+ schema,
492
+ pageHeight: page.getHeight()
493
+ };
494
+ const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
495
+ const { position: { x: x4Ellipse, y: y4Ellipse } } = convertForPdfLayoutProps({
496
+ ...cArg,
497
+ applyRotateTranslate: false
498
+ });
499
+ const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
500
+ const drawOptions = {
501
+ rotate,
502
+ borderWidth,
503
+ borderColor: hex2PrintingColor(schema.borderColor, colorType),
504
+ color: hex2PrintingColor(schema.color, colorType),
505
+ opacity,
506
+ borderOpacity: opacity
507
+ };
508
+ if (schema.type === "ellipse") page.drawEllipse({
509
+ x: x4Ellipse + width / 2,
510
+ y: y4Ellipse + height / 2,
511
+ xScale: width / 2 - borderWidth / 2,
512
+ yScale: height / 2 - borderWidth / 2,
513
+ ...drawOptions
514
+ });
515
+ else if (schema.type === "rectangle") {
516
+ const radius = schema.radius ?? 0;
517
+ page.drawRectangle({
518
+ x: position.x + borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
519
+ y: position.y + borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
520
+ width: width - borderWidth,
521
+ height: height - borderWidth,
522
+ ...radius ? { radius: mm2pt(radius) } : {},
523
+ ...drawOptions
524
+ });
525
+ }
526
+ },
527
+ propPanel: {
528
+ schema: ({ i18n }) => ({
529
+ borderWidth: {
530
+ title: i18n("schemas.borderWidth"),
531
+ type: "number",
532
+ widget: "inputNumber",
533
+ props: {
534
+ min: 0,
535
+ step: 1
536
+ },
537
+ span: 12
538
+ },
539
+ borderColor: {
540
+ title: i18n("schemas.borderColor"),
541
+ type: "string",
542
+ widget: "color",
543
+ props: { disabledAlpha: true },
544
+ rules: [{
545
+ pattern: HEX_COLOR_PATTERN,
546
+ message: i18n("validation.hexColor")
547
+ }],
548
+ span: 12
549
+ },
550
+ color: {
551
+ title: i18n("schemas.color"),
552
+ type: "string",
553
+ widget: "color",
554
+ props: { disabledAlpha: true },
555
+ rules: [{
556
+ pattern: HEX_COLOR_PATTERN,
557
+ message: i18n("validation.hexColor")
558
+ }]
559
+ },
560
+ radius: {
561
+ title: i18n("schemas.radius"),
562
+ type: "number",
563
+ widget: "inputNumber",
564
+ props: {
565
+ min: 0,
566
+ step: 1
567
+ },
568
+ span: 12
569
+ }
570
+ }),
571
+ defaultSchema: {
572
+ name: "",
573
+ type: "rectangle",
574
+ position: {
575
+ x: 0,
576
+ y: 0
577
+ },
578
+ width: 62.5,
579
+ height: 37.5,
580
+ rotate: 0,
581
+ opacity: 1,
582
+ borderWidth: 1,
583
+ borderColor: "#000000",
584
+ color: "",
585
+ readOnly: true,
586
+ radius: 0
587
+ }
588
+ }
589
+ };
590
+ var getPropPanelSchema = (type) => ({
591
+ ...shape.propPanel,
592
+ defaultSchema: {
593
+ ...shape.propPanel.defaultSchema,
594
+ type
595
+ }
596
+ });
597
+ var rectangle = {
598
+ ...shape,
599
+ propPanel: getPropPanelSchema("rectangle"),
600
+ icon: createSvgStr(Square)
601
+ };
602
+ var ellipse = {
603
+ ...shape,
604
+ propPanel: getPropPanelSchema("ellipse"),
605
+ icon: createSvgStr(Circle)
606
+ };
607
+ //#endregion
608
+ //#region src/list/pdfRender.ts
609
+ var rectanglePdfRender$2 = rectangle.pdf;
610
+ var pdfRender$2 = async (arg) => {
611
+ const { schema, value } = arg;
612
+ const items = normalizeListItems(value);
613
+ const range = getListItemRange(schema) ?? {
614
+ start: 0,
615
+ end: items.length
616
+ };
617
+ const visibleItems = items.slice(range.start, range.end);
618
+ if (visibleItems.length === 0) return;
619
+ const layout = await calculateListLayout({
620
+ schema,
621
+ items: visibleItems,
622
+ markerItems: items,
623
+ startIndex: range.start,
624
+ options: arg.options,
625
+ _cache: arg._cache
626
+ });
627
+ if (schema.backgroundColor) await rectanglePdfRender$2({
628
+ ...arg,
629
+ schema: {
630
+ ...schema,
631
+ type: "rectangle",
632
+ borderWidth: 0,
633
+ borderColor: "",
634
+ color: schema.backgroundColor
635
+ }
636
+ });
637
+ let y = schema.position.y;
638
+ for (const item of layout.items) {
639
+ await pdfRender$4({
640
+ ...arg,
641
+ value: item.marker,
642
+ schema: {
643
+ ...schema,
644
+ type: "text",
645
+ position: {
646
+ x: schema.position.x + item.markerX,
647
+ y
648
+ },
649
+ width: layout.markerWidth,
650
+ height: item.height,
651
+ backgroundColor: "",
652
+ alignment: "right",
653
+ verticalAlignment: "top",
654
+ dynamicFontSize: void 0
655
+ }
656
+ });
657
+ await pdfRender$4({
658
+ ...arg,
659
+ value: item.item,
660
+ schema: {
661
+ ...schema,
662
+ type: "text",
663
+ position: {
664
+ x: schema.position.x + item.bodyX,
665
+ y
666
+ },
667
+ width: item.bodyWidth,
668
+ height: item.height,
669
+ backgroundColor: "",
670
+ verticalAlignment: "top",
671
+ dynamicFontSize: void 0
672
+ }
673
+ });
674
+ y += item.height;
675
+ }
676
+ };
677
+ //#endregion
678
+ //#region src/list/propPanel.ts
679
+ var propPanel$1 = {
680
+ schema: (propPanelProps) => {
681
+ if (typeof propPanel$3.schema !== "function") throw new Error("Oops, is text schema no longer a function?");
682
+ const parentSchema = propPanel$3.schema(propPanelProps);
683
+ const i18n = propPanelProps.i18n;
684
+ const listSchema = { ...parentSchema };
685
+ delete listSchema.useDynamicFontSize;
686
+ delete listSchema.dynamicFontSize;
687
+ return {
688
+ ...listSchema,
689
+ "-------": {
690
+ type: "void",
691
+ widget: "Divider"
692
+ },
693
+ listStyle: {
694
+ title: i18n("schemas.list.listStyle"),
695
+ type: "string",
696
+ widget: "select",
697
+ props: { options: [{
698
+ label: i18n("schemas.list.bullet"),
699
+ value: LIST_STYLE_BULLET
700
+ }, {
701
+ label: i18n("schemas.list.ordered"),
702
+ value: LIST_STYLE_ORDERED
703
+ }] },
704
+ span: 24
705
+ },
706
+ markerWidth: {
707
+ title: i18n("schemas.list.markerWidth"),
708
+ type: "number",
709
+ widget: "inputNumber",
710
+ props: { min: 0 },
711
+ span: 6
712
+ },
713
+ markerGap: {
714
+ title: i18n("schemas.list.markerGap"),
715
+ type: "number",
716
+ widget: "inputNumber",
717
+ props: { min: 0 },
718
+ span: 6
719
+ },
720
+ indentSize: {
721
+ title: i18n("schemas.list.indentSize"),
722
+ type: "number",
723
+ widget: "inputNumber",
724
+ props: { min: 0 },
725
+ span: 6
726
+ },
727
+ itemSpacing: {
728
+ title: i18n("schemas.list.itemSpacing"),
729
+ type: "number",
730
+ widget: "inputNumber",
731
+ props: { min: 0 },
732
+ span: 6
733
+ }
734
+ };
735
+ },
736
+ widgets: propPanel$3.widgets,
737
+ defaultSchema: {
738
+ ...propPanel$3.defaultSchema,
739
+ type: "list",
740
+ content: JSON.stringify(["First item", "Second item"]),
741
+ width: 80,
742
+ height: 20,
743
+ listStyle: DEFAULT_LIST_STYLE,
744
+ markerWidth: 6,
745
+ markerGap: 2,
746
+ indentSize: 6,
747
+ itemSpacing: 1,
748
+ dynamicFontSize: void 0,
749
+ verticalAlignment: "top"
750
+ }
751
+ };
752
+ //#endregion
753
+ //#region src/list/uiRender.ts
754
+ var focusDataKey = "pdfmeListFocusIndex";
755
+ var actionDataKey = "pdfmeListAction";
756
+ var internalFocusDataKey = "pdfmeListInternalFocus";
757
+ var caretMarker = "​";
758
+ var pendingFocusIndexes = /* @__PURE__ */ new Map();
759
+ var getListFocusKey = (schema) => schema.id || schema.name;
760
+ var isComposingKeyboardEvent = (event) => event.isComposing || event.keyCode === 229;
761
+ var getText = (element) => {
762
+ const rawText = element.innerText;
763
+ const hasCaretMarker = rawText.includes(caretMarker);
764
+ let text = rawText.replace(/\u200B/g, "");
765
+ if (!hasCaretMarker && text.endsWith("\n")) text = text.slice(0, -1);
766
+ return text;
767
+ };
768
+ var setStyles = (element, styles) => {
769
+ Object.assign(element.style, styles);
770
+ };
771
+ var focusBody = (body) => {
772
+ body.focus();
773
+ const selection = window.getSelection();
774
+ const range = document.createRange();
775
+ if (selection && range) {
776
+ range.selectNodeContents(body);
777
+ range.collapse(false);
778
+ selection.removeAllRanges();
779
+ selection.addRange(range);
780
+ }
781
+ };
782
+ var getCaretRangeFromPoint = (x, y) => {
783
+ const documentWithCaret = document;
784
+ if (documentWithCaret.caretRangeFromPoint) return documentWithCaret.caretRangeFromPoint(x, y);
785
+ const caretPosition = documentWithCaret.caretPositionFromPoint?.(x, y);
786
+ if (!caretPosition) return null;
787
+ const range = document.createRange();
788
+ range.setStart(caretPosition.offsetNode, caretPosition.offset);
789
+ range.collapse(true);
790
+ return range;
791
+ };
792
+ var focusBodyFromMouseEvent = (body, event) => {
793
+ body.focus();
794
+ const range = getCaretRangeFromPoint(event.clientX, event.clientY);
795
+ if (!range || !body.contains(range.startContainer)) return;
796
+ const selection = window.getSelection();
797
+ if (!selection) return;
798
+ selection.removeAllRanges();
799
+ selection.addRange(range);
800
+ };
801
+ var getBodyEditor = (body) => body.querySelector("[contenteditable], [tabindex]");
802
+ var insertLineBreakAtSelection = (element) => {
803
+ const fallbackText = getText(element);
804
+ const selection = window.getSelection();
805
+ if (!selection?.rangeCount) {
806
+ element.innerText = `${fallbackText}\n${caretMarker}`;
807
+ focusBody(element);
808
+ return true;
809
+ }
810
+ const range = selection.getRangeAt(0);
811
+ if (!element.contains(range.commonAncestorContainer)) {
812
+ element.innerText = `${fallbackText}\n${caretMarker}`;
813
+ focusBody(element);
814
+ return true;
815
+ }
816
+ selection.deleteFromDocument();
817
+ const fragment = document.createDocumentFragment();
818
+ const lineBreak = document.createElement("br");
819
+ const marker = document.createTextNode(caretMarker);
820
+ fragment.append(lineBreak, marker);
821
+ range.insertNode(fragment);
822
+ range.setStart(marker, marker.length);
823
+ range.collapse(true);
824
+ selection.removeAllRanges();
825
+ selection.addRange(range);
826
+ if (!element.innerText.includes(caretMarker)) {
827
+ element.innerText = `${fallbackText}\n${caretMarker}`;
828
+ focusBody(element);
829
+ }
830
+ return true;
831
+ };
832
+ var createActionButton = (arg) => {
833
+ const button = document.createElement("button");
834
+ button.type = "button";
835
+ button.innerText = arg.label;
836
+ button.setAttribute("aria-label", arg.ariaLabel);
837
+ button.disabled = Boolean(arg.disabled);
838
+ setStyles(button, {
839
+ width: "18px",
840
+ height: "18px",
841
+ display: "inline-flex",
842
+ alignItems: "center",
843
+ justifyContent: "center",
844
+ padding: "0",
845
+ border: "1px solid #d9d9d9",
846
+ borderRadius: "3px",
847
+ background: "#ffffff",
848
+ color: "#333333",
849
+ fontSize: "11px",
850
+ lineHeight: "1",
851
+ cursor: arg.disabled ? "not-allowed" : "pointer",
852
+ opacity: arg.disabled ? .45 : 1
853
+ });
854
+ button.addEventListener("pointerdown", (event) => {
855
+ arg.onPressStart?.();
856
+ event.stopPropagation();
857
+ });
858
+ button.addEventListener("mousedown", (event) => {
859
+ arg.onPressStart?.();
860
+ event.preventDefault();
861
+ event.stopPropagation();
862
+ });
863
+ button.addEventListener("click", (event) => {
864
+ event.preventDefault();
865
+ event.stopPropagation();
866
+ if (!arg.disabled) arg.onClick();
867
+ });
868
+ return button;
869
+ };
870
+ var uiRender$2 = async (arg) => {
871
+ const { rootElement, schema, value, mode, onChange, stopEditing, tabIndex, placeholder } = arg;
872
+ const focusKey = getListFocusKey(schema);
873
+ const editable = isEditable(mode, schema);
874
+ const showControls = editable && (mode === "form" || mode === "designer");
875
+ const usePlaceholder = editable && !value && Boolean(placeholder);
876
+ const items = normalizeListItems(usePlaceholder ? placeholder || "" : value);
877
+ const originalItems = normalizeListItemEntries(value);
878
+ const range = getListItemRange(schema) ?? {
879
+ start: 0,
880
+ end: items.length
881
+ };
882
+ const visibleItems = items.slice(range.start, range.end);
883
+ const renderItems = visibleItems;
884
+ rootElement.innerHTML = "";
885
+ setStyles(rootElement, {
886
+ position: "relative",
887
+ width: "100%",
888
+ height: "100%",
889
+ backgroundColor: schema.backgroundColor || "transparent",
890
+ overflow: "visible"
891
+ });
892
+ const layout = await calculateListLayout({
893
+ schema,
894
+ items: renderItems,
895
+ markerItems: items,
896
+ startIndex: range.start,
897
+ options: arg.options,
898
+ _cache: arg._cache
899
+ });
900
+ const bodyElements = [];
901
+ const getEditedItems = () => layout.items.map((item, index) => ({
902
+ level: item.level,
903
+ text: getText(bodyElements[index])
904
+ }));
905
+ const getNextItems = () => {
906
+ const editedItems = getEditedItems();
907
+ if (usePlaceholder) return editedItems;
908
+ const nextItems = [...originalItems];
909
+ nextItems.splice(range.start, visibleItems.length, ...editedItems);
910
+ return nextItems;
911
+ };
912
+ const commitItems = (nextItems, focusIndex) => {
913
+ if (!onChange) return;
914
+ if (focusIndex !== void 0) {
915
+ rootElement.dataset[focusDataKey] = String(focusIndex);
916
+ pendingFocusIndexes.set(focusKey, focusIndex);
917
+ }
918
+ onChange({
919
+ key: "content",
920
+ value: serializeListItems(nextItems)
921
+ });
922
+ };
923
+ const commitHeight = async (focusIndex) => {
924
+ if (!onChange) return;
925
+ if (focusIndex !== void 0) {
926
+ rootElement.dataset[focusDataKey] = String(focusIndex);
927
+ pendingFocusIndexes.set(focusKey, focusIndex);
928
+ }
929
+ const rawItems = normalizeListItems(serializeListItems(getNextItems()));
930
+ const nextLayout = await calculateListLayout({
931
+ schema,
932
+ items: rawItems.slice(range.start, range.end),
933
+ markerItems: rawItems,
934
+ startIndex: range.start,
935
+ options: arg.options,
936
+ _cache: arg._cache
937
+ });
938
+ if (schema.height !== nextLayout.totalHeight) onChange({
939
+ key: "height",
940
+ value: nextLayout.totalHeight
941
+ });
942
+ };
943
+ const preserveEditingForAction = () => {
944
+ rootElement.dataset[actionDataKey] = "true";
945
+ };
946
+ const updateItems = (rowIndex, mutate) => {
947
+ const nextItems = getNextItems();
948
+ if (nextItems.length === 0) nextItems.push({
949
+ level: 0,
950
+ text: ""
951
+ });
952
+ const focusIndex = mutate(nextItems, Math.min(Math.max(range.start + rowIndex, 0), nextItems.length - 1));
953
+ preserveEditingForAction();
954
+ commitItems(nextItems, focusIndex);
955
+ };
956
+ const preserveEditingForInternalFocus = () => {
957
+ rootElement.dataset[internalFocusDataKey] = "true";
958
+ };
959
+ const preserveEditingForKeyboardCommit = () => {
960
+ preserveEditingForInternalFocus();
961
+ setTimeout(() => {
962
+ if (rootElement.dataset[internalFocusDataKey] === "true") delete rootElement.dataset[internalFocusDataKey];
963
+ });
964
+ };
965
+ const handleInternalFocusPointer = (event) => {
966
+ preserveEditingForInternalFocus();
967
+ event.stopPropagation();
968
+ };
969
+ const handleBodyMouseDown = (body, event) => {
970
+ handleInternalFocusPointer(event);
971
+ focusBodyFromMouseEvent(body, event);
972
+ };
973
+ const appendEmptyListControls = () => {
974
+ const controls = document.createElement("div");
975
+ controls.addEventListener("pointerdown", preserveEditingForAction);
976
+ controls.addEventListener("mousedown", preserveEditingForAction);
977
+ setStyles(controls, {
978
+ position: "absolute",
979
+ top: "0mm",
980
+ right: "-20px",
981
+ display: "flex",
982
+ gap: "2px"
983
+ });
984
+ controls.appendChild(createActionButton({
985
+ label: "+",
986
+ ariaLabel: arg.i18n("schemas.list.addItem"),
987
+ onPressStart: preserveEditingForAction,
988
+ onClick: () => {
989
+ const nextItems = [...originalItems];
990
+ nextItems.splice(range.start, 0, {
991
+ level: 0,
992
+ text: ""
993
+ });
994
+ commitItems(nextItems, range.start);
995
+ }
996
+ }));
997
+ rootElement.appendChild(controls);
998
+ };
999
+ let offsetY = 0;
1000
+ for (let index = 0; index < layout.items.length; index += 1) {
1001
+ const item = layout.items[index];
1002
+ const row = document.createElement("div");
1003
+ setStyles(row, {
1004
+ position: "absolute",
1005
+ top: `${offsetY}mm`,
1006
+ left: "0mm",
1007
+ width: `${schema.width}mm`,
1008
+ height: `${item.height}mm`
1009
+ });
1010
+ const marker = document.createElement("div");
1011
+ setStyles(marker, {
1012
+ position: "absolute",
1013
+ top: "0mm",
1014
+ left: `${item.markerX}mm`,
1015
+ width: `${layout.markerWidth}mm`,
1016
+ height: "100%",
1017
+ backgroundColor: "transparent",
1018
+ cursor: "default"
1019
+ });
1020
+ const body = document.createElement("div");
1021
+ setStyles(body, {
1022
+ position: "absolute",
1023
+ top: "0mm",
1024
+ left: `${item.bodyX}mm`,
1025
+ width: `${item.bodyWidth}mm`,
1026
+ height: `${item.height}mm`,
1027
+ backgroundColor: "transparent",
1028
+ cursor: editable ? "text" : "default"
1029
+ });
1030
+ const schemaForUI = schema;
1031
+ const textSchema = {
1032
+ ...schema,
1033
+ id: `${schemaForUI.id || schema.name}-list-item-${item.itemIndex}`,
1034
+ name: `${schema.name}-list-item-${item.itemIndex}`,
1035
+ type: "text",
1036
+ content: item.item,
1037
+ position: {
1038
+ x: 0,
1039
+ y: 0
1040
+ },
1041
+ width: item.bodyWidth,
1042
+ height: item.height,
1043
+ alignment: schema.alignment ?? "left",
1044
+ fontSize: schema.fontSize ?? 13,
1045
+ lineHeight: schema.lineHeight ?? 1,
1046
+ characterSpacing: schema.characterSpacing ?? 0,
1047
+ fontColor: usePlaceholder ? PLACEHOLDER_FONT_COLOR : schema.fontColor || "#000000",
1048
+ backgroundColor: ""
1049
+ };
1050
+ const markerTextSchema = {
1051
+ ...textSchema,
1052
+ id: `${schemaForUI.id || schema.name}-list-marker-${item.itemIndex}`,
1053
+ name: `${schema.name}-list-marker-${item.itemIndex}`,
1054
+ content: item.marker,
1055
+ width: layout.markerWidth,
1056
+ height: item.height,
1057
+ alignment: "right",
1058
+ fontColor: schema.fontColor || "#000000"
1059
+ };
1060
+ await uiRender$4({
1061
+ ...arg,
1062
+ rootElement: marker,
1063
+ schema: markerTextSchema,
1064
+ value: item.marker,
1065
+ mode: "viewer",
1066
+ placeholder: "",
1067
+ onChange: void 0,
1068
+ stopEditing: void 0
1069
+ });
1070
+ await uiRender$4({
1071
+ ...arg,
1072
+ rootElement: body,
1073
+ schema: textSchema,
1074
+ value: item.item,
1075
+ placeholder: "",
1076
+ onChange: void 0,
1077
+ stopEditing: void 0
1078
+ });
1079
+ if (editable) {
1080
+ const editor = getBodyEditor(body);
1081
+ if (!editor) throw new Error("Unable to find list item text editor");
1082
+ editor.tabIndex = tabIndex || 0;
1083
+ body.addEventListener("pointerdown", handleInternalFocusPointer);
1084
+ body.addEventListener("mousedown", (event) => {
1085
+ handleBodyMouseDown(editor, event);
1086
+ });
1087
+ body.addEventListener("click", (event) => {
1088
+ event.stopPropagation();
1089
+ focusBodyFromMouseEvent(editor, event);
1090
+ });
1091
+ editor.addEventListener("focus", () => {
1092
+ if (usePlaceholder) {
1093
+ editor.innerText = "";
1094
+ editor.style.color = schema.fontColor || "#000000";
1095
+ }
1096
+ });
1097
+ body.addEventListener("blur", (event) => {
1098
+ const isListAction = rootElement.dataset[actionDataKey] === "true";
1099
+ const relatedTarget = event.relatedTarget;
1100
+ const isInternalFocus = rootElement.dataset[internalFocusDataKey] === "true" || relatedTarget instanceof Node && rootElement.contains(relatedTarget);
1101
+ delete rootElement.dataset[internalFocusDataKey];
1102
+ if (isListAction || isInternalFocus) return;
1103
+ if (!onChange) return;
1104
+ commitItems(getNextItems());
1105
+ if (stopEditing) stopEditing();
1106
+ }, true);
1107
+ editor.addEventListener("keydown", (event) => {
1108
+ if (event.key === "Enter") {
1109
+ if (isComposingKeyboardEvent(event)) return;
1110
+ event.preventDefault();
1111
+ if (insertLineBreakAtSelection(editor)) {
1112
+ preserveEditingForKeyboardCommit();
1113
+ if (mode === "form") commitHeight(range.start + index);
1114
+ else commitItems(getNextItems(), range.start + index);
1115
+ }
1116
+ } else if (event.key === "Tab") {
1117
+ event.preventDefault();
1118
+ updateItems(index, (nextItems, itemIndex) => {
1119
+ const itemToUpdate = nextItems[itemIndex];
1120
+ itemToUpdate.level = event.shiftKey ? Math.max(itemToUpdate.level - 1, 0) : Math.min(itemToUpdate.level + 1, 8);
1121
+ return itemIndex;
1122
+ });
1123
+ } else if (event.key === "Backspace" && getText(editor) === "") {
1124
+ event.preventDefault();
1125
+ updateItems(index, (nextItems, itemIndex) => {
1126
+ if (nextItems.length <= 1) {
1127
+ nextItems.splice(0);
1128
+ return;
1129
+ }
1130
+ nextItems.splice(itemIndex, 1);
1131
+ return Math.min(itemIndex, nextItems.length - 1);
1132
+ });
1133
+ }
1134
+ });
1135
+ bodyElements.push(editor);
1136
+ }
1137
+ row.appendChild(marker);
1138
+ row.appendChild(body);
1139
+ if (showControls) {
1140
+ const controls = document.createElement("div");
1141
+ controls.addEventListener("pointerdown", preserveEditingForAction);
1142
+ controls.addEventListener("mousedown", preserveEditingForAction);
1143
+ setStyles(controls, {
1144
+ position: "absolute",
1145
+ top: "0mm",
1146
+ right: "-82px",
1147
+ display: "flex",
1148
+ gap: "2px"
1149
+ });
1150
+ controls.appendChild(createActionButton({
1151
+ label: "+",
1152
+ ariaLabel: arg.i18n("schemas.list.addItem"),
1153
+ onPressStart: preserveEditingForAction,
1154
+ onClick: () => {
1155
+ updateItems(index, (nextItems, itemIndex) => {
1156
+ nextItems.splice(itemIndex + 1, 0, {
1157
+ level: nextItems[itemIndex]?.level ?? 0,
1158
+ text: ""
1159
+ });
1160
+ return itemIndex + 1;
1161
+ });
1162
+ }
1163
+ }));
1164
+ controls.appendChild(createActionButton({
1165
+ label: "-",
1166
+ ariaLabel: arg.i18n("schemas.list.removeItem"),
1167
+ onPressStart: preserveEditingForAction,
1168
+ onClick: () => {
1169
+ updateItems(index, (nextItems, itemIndex) => {
1170
+ if (nextItems.length <= 1) {
1171
+ nextItems.splice(0);
1172
+ return;
1173
+ }
1174
+ nextItems.splice(itemIndex, 1);
1175
+ return Math.min(itemIndex, nextItems.length - 1);
1176
+ });
1177
+ }
1178
+ }));
1179
+ controls.appendChild(createActionButton({
1180
+ label: "<",
1181
+ ariaLabel: arg.i18n("schemas.list.outdentItem"),
1182
+ disabled: item.level === 0,
1183
+ onPressStart: preserveEditingForAction,
1184
+ onClick: () => {
1185
+ updateItems(index, (nextItems, itemIndex) => {
1186
+ nextItems[itemIndex].level = Math.max(nextItems[itemIndex].level - 1, 0);
1187
+ return itemIndex;
1188
+ });
1189
+ }
1190
+ }));
1191
+ controls.appendChild(createActionButton({
1192
+ label: ">",
1193
+ ariaLabel: arg.i18n("schemas.list.indentItem"),
1194
+ disabled: item.level >= 8,
1195
+ onPressStart: preserveEditingForAction,
1196
+ onClick: () => {
1197
+ updateItems(index, (nextItems, itemIndex) => {
1198
+ nextItems[itemIndex].level = Math.min(nextItems[itemIndex].level + 1, 8);
1199
+ return itemIndex;
1200
+ });
1201
+ }
1202
+ }));
1203
+ row.appendChild(controls);
1204
+ }
1205
+ rootElement.appendChild(row);
1206
+ offsetY += item.height;
1207
+ }
1208
+ if (showControls && visibleItems.length === 0) appendEmptyListControls();
1209
+ const pendingFocusIndex = pendingFocusIndexes.get(focusKey);
1210
+ if (pendingFocusIndex !== void 0) pendingFocusIndexes.delete(focusKey);
1211
+ const requestedFocusIndex = Number(rootElement.dataset[focusDataKey] ?? pendingFocusIndex);
1212
+ delete rootElement.dataset[focusDataKey];
1213
+ delete rootElement.dataset[actionDataKey];
1214
+ delete rootElement.dataset[internalFocusDataKey];
1215
+ const relativeFocusIndex = requestedFocusIndex - range.start;
1216
+ if (editable && Number.isFinite(requestedFocusIndex) && bodyElements[relativeFocusIndex]) setTimeout(() => focusBody(bodyElements[relativeFocusIndex]));
1217
+ else if (editable && mode === "designer" && bodyElements[0]) setTimeout(() => {
1218
+ if (!rootElement.contains(document.activeElement)) focusBody(bodyElements[0]);
1219
+ });
1220
+ if (schema.height !== layout.totalHeight && onChange) onChange({
1221
+ key: "height",
1222
+ value: layout.totalHeight
1223
+ });
1224
+ };
1225
+ //#endregion
1226
+ //#region src/list/index.ts
1227
+ var listSchema = {
473
1228
  pdf: pdfRender$2,
474
1229
  ui: uiRender$2,
475
1230
  propPanel: propPanel$1,
476
- icon: createSvgStr(Type),
477
- uninterruptedEditMode: true
1231
+ icon: createSvgStr(List)
478
1232
  };
479
1233
  //#endregion
480
1234
  //#region src/graphics/imagehelper.ts
@@ -1534,144 +2288,6 @@ var lineSchema = {
1534
2288
  icon: createSvgStr(Minus)
1535
2289
  };
1536
2290
  //#endregion
1537
- //#region src/shapes/rectAndEllipse.ts
1538
- var shape = {
1539
- ui: (arg) => {
1540
- const { schema, rootElement } = arg;
1541
- const div = document.createElement("div");
1542
- div.style.width = "100%";
1543
- div.style.height = "100%";
1544
- div.style.boxSizing = "border-box";
1545
- if (schema.type === "ellipse") div.style.borderRadius = "50%";
1546
- else if (schema.radius && schema.radius > 0) div.style.borderRadius = `${schema.radius}mm`;
1547
- div.style.borderWidth = `${schema.borderWidth ?? 0}mm`;
1548
- div.style.borderStyle = schema.borderWidth && schema.borderColor ? "solid" : "none";
1549
- div.style.borderColor = schema.borderColor ?? "transparent";
1550
- div.style.backgroundColor = schema.color ?? "transparent";
1551
- rootElement.appendChild(div);
1552
- },
1553
- pdf: (arg) => {
1554
- const { schema, page, options } = arg;
1555
- if (!schema.color && !schema.borderColor) return;
1556
- const { colorType } = options;
1557
- const cArg = {
1558
- schema,
1559
- pageHeight: page.getHeight()
1560
- };
1561
- const { position, width, height, rotate, opacity } = convertForPdfLayoutProps(cArg);
1562
- const { position: { x: x4Ellipse, y: y4Ellipse } } = convertForPdfLayoutProps({
1563
- ...cArg,
1564
- applyRotateTranslate: false
1565
- });
1566
- const borderWidth = schema.borderWidth ? mm2pt(schema.borderWidth) : 0;
1567
- const drawOptions = {
1568
- rotate,
1569
- borderWidth,
1570
- borderColor: hex2PrintingColor(schema.borderColor, colorType),
1571
- color: hex2PrintingColor(schema.color, colorType),
1572
- opacity,
1573
- borderOpacity: opacity
1574
- };
1575
- if (schema.type === "ellipse") page.drawEllipse({
1576
- x: x4Ellipse + width / 2,
1577
- y: y4Ellipse + height / 2,
1578
- xScale: width / 2 - borderWidth / 2,
1579
- yScale: height / 2 - borderWidth / 2,
1580
- ...drawOptions
1581
- });
1582
- else if (schema.type === "rectangle") {
1583
- const radius = schema.radius ?? 0;
1584
- page.drawRectangle({
1585
- x: position.x + borderWidth * ((1 - Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
1586
- y: position.y + borderWidth * ((1 + Math.sin(toRadians(rotate))) / 2) + Math.tan(toRadians(rotate)) * Math.PI ** 2,
1587
- width: width - borderWidth,
1588
- height: height - borderWidth,
1589
- ...radius ? { radius: mm2pt(radius) } : {},
1590
- ...drawOptions
1591
- });
1592
- }
1593
- },
1594
- propPanel: {
1595
- schema: ({ i18n }) => ({
1596
- borderWidth: {
1597
- title: i18n("schemas.borderWidth"),
1598
- type: "number",
1599
- widget: "inputNumber",
1600
- props: {
1601
- min: 0,
1602
- step: 1
1603
- },
1604
- span: 12
1605
- },
1606
- borderColor: {
1607
- title: i18n("schemas.borderColor"),
1608
- type: "string",
1609
- widget: "color",
1610
- props: { disabledAlpha: true },
1611
- rules: [{
1612
- pattern: HEX_COLOR_PATTERN,
1613
- message: i18n("validation.hexColor")
1614
- }],
1615
- span: 12
1616
- },
1617
- color: {
1618
- title: i18n("schemas.color"),
1619
- type: "string",
1620
- widget: "color",
1621
- props: { disabledAlpha: true },
1622
- rules: [{
1623
- pattern: HEX_COLOR_PATTERN,
1624
- message: i18n("validation.hexColor")
1625
- }]
1626
- },
1627
- radius: {
1628
- title: i18n("schemas.radius"),
1629
- type: "number",
1630
- widget: "inputNumber",
1631
- props: {
1632
- min: 0,
1633
- step: 1
1634
- },
1635
- span: 12
1636
- }
1637
- }),
1638
- defaultSchema: {
1639
- name: "",
1640
- type: "rectangle",
1641
- position: {
1642
- x: 0,
1643
- y: 0
1644
- },
1645
- width: 62.5,
1646
- height: 37.5,
1647
- rotate: 0,
1648
- opacity: 1,
1649
- borderWidth: 1,
1650
- borderColor: "#000000",
1651
- color: "",
1652
- readOnly: true,
1653
- radius: 0
1654
- }
1655
- }
1656
- };
1657
- var getPropPanelSchema = (type) => ({
1658
- ...shape.propPanel,
1659
- defaultSchema: {
1660
- ...shape.propPanel.defaultSchema,
1661
- type
1662
- }
1663
- });
1664
- var rectangle = {
1665
- ...shape,
1666
- propPanel: getPropPanelSchema("rectangle"),
1667
- icon: createSvgStr(Square)
1668
- };
1669
- var ellipse = {
1670
- ...shape,
1671
- propPanel: getPropPanelSchema("ellipse"),
1672
- icon: createSvgStr(Circle)
1673
- };
1674
- //#endregion
1675
2291
  //#region src/tables/cell.ts
1676
2292
  var linePdfRender = lineSchema.pdf;
1677
2293
  var rectanglePdfRender$1 = rectangle.pdf;
@@ -1743,7 +2359,7 @@ var cellSchema = {
1743
2359
  y: position.y
1744
2360
  }, borderWidth.left, height)
1745
2361
  ]);
1746
- await pdfRender$3({
2362
+ await pdfRender$4({
1747
2363
  ...arg,
1748
2364
  schema: {
1749
2365
  ...schema,
@@ -1763,7 +2379,7 @@ var cellSchema = {
1763
2379
  const { borderWidth, width, height, borderColor, backgroundColor } = schema;
1764
2380
  rootElement.style.backgroundColor = backgroundColor;
1765
2381
  const textDiv = createTextDiv(schema);
1766
- await uiRender$3({
2382
+ await uiRender$4({
1767
2383
  ...arg,
1768
2384
  schema: {
1769
2385
  ...schema,
@@ -1887,7 +2503,7 @@ async function drawTable(arg, table) {
1887
2503
  }
1888
2504
  var pdfRender = async (arg) => {
1889
2505
  const { value, schema, basePdf, options, _cache } = arg;
1890
- const body = getBodyWithRange(typeof value !== "string" ? JSON.stringify(value || "[]") : value, schema.__bodyRange);
2506
+ const body = getBodyWithSchemaRange(typeof value !== "string" ? JSON.stringify(value || "[]") : value, schema);
1891
2507
  const createTableArgs = {
1892
2508
  schema,
1893
2509
  basePdf,
@@ -1898,17 +2514,38 @@ var pdfRender = async (arg) => {
1898
2514
  };
1899
2515
  //#endregion
1900
2516
  //#region src/tables/uiRender.ts
1901
- var buttonSize = 30;
2517
+ var buttonSize = 18;
1902
2518
  function createButton(options) {
1903
2519
  const button = document.createElement("button");
2520
+ button.type = "button";
2521
+ button.innerText = options.text;
2522
+ if (options.ariaLabel) button.setAttribute("aria-label", options.ariaLabel);
1904
2523
  button.style.width = `${options.width}px`;
1905
2524
  button.style.height = `${options.height}px`;
1906
2525
  button.style.position = "absolute";
1907
2526
  button.style.top = options.top;
2527
+ button.style.display = "inline-flex";
2528
+ button.style.alignItems = "center";
2529
+ button.style.justifyContent = "center";
2530
+ button.style.padding = "0";
2531
+ button.style.border = "1px solid #d9d9d9";
2532
+ button.style.borderRadius = "3px";
2533
+ button.style.background = "#ffffff";
2534
+ button.style.color = "#333333";
2535
+ button.style.fontSize = "11px";
2536
+ button.style.lineHeight = "1";
2537
+ button.style.cursor = "pointer";
2538
+ button.style.zIndex = "20";
1908
2539
  if (options.left !== void 0) button.style.left = options.left;
1909
2540
  if (options.right !== void 0) button.style.right = options.right;
1910
- button.innerText = options.text;
1911
- button.onclick = options.onClick;
2541
+ button.addEventListener("mousedown", (event) => {
2542
+ event.preventDefault();
2543
+ });
2544
+ button.addEventListener("click", (event) => {
2545
+ event.preventDefault();
2546
+ event.stopPropagation();
2547
+ options.onClick(event);
2548
+ });
1912
2549
  return button;
1913
2550
  }
1914
2551
  var cellUiRender = cellSchema.ui;
@@ -1993,7 +2630,7 @@ var renderRowUi = (args) => {
1993
2630
  if (!arg.onChange) return;
1994
2631
  const newValue = Array.isArray(v) ? v[0].value : v.value;
1995
2632
  if (section === "body") {
1996
- const startRange = arg.schema.__bodyRange?.start ?? 0;
2633
+ const startRange = getTableBodyRange(arg.schema)?.start ?? 0;
1997
2634
  value[rowIndex + startRange][colIndex] = newValue;
1998
2635
  arg.onChange({
1999
2636
  key: "content",
@@ -2046,7 +2683,8 @@ var resetEditingPosition = () => {
2046
2683
  var uiRender = async (arg) => {
2047
2684
  const { rootElement, onChange, schema, value, mode, scale } = arg;
2048
2685
  const body = getBody(value);
2049
- const bodyWidthRange = getBodyWithRange(value, schema.__bodyRange);
2686
+ const bodyRange = getTableBodyRange(schema);
2687
+ const bodyWidthRange = getBodyWithSchemaRange(value, schema, bodyRange);
2050
2688
  const table = await createSingleTable(bodyWidthRange, arg);
2051
2689
  const showHead = table.settings.showHead;
2052
2690
  rootElement.innerHTML = "";
@@ -2078,6 +2716,7 @@ var uiRender = async (arg) => {
2078
2716
  top: `${table.getHeight()}mm`,
2079
2717
  left: `calc(50% - ${buttonSize / 2}px)`,
2080
2718
  text: "+",
2719
+ ariaLabel: "Add row",
2081
2720
  onClick: () => {
2082
2721
  const newRow = Array(schema.head.length).fill("");
2083
2722
  if (onChange) onChange({
@@ -2096,8 +2735,9 @@ var uiRender = async (arg) => {
2096
2735
  top: `${offsetY - px2mm(buttonSize)}mm`,
2097
2736
  right: `-${buttonSize}px`,
2098
2737
  text: "-",
2738
+ ariaLabel: "Remove row",
2099
2739
  onClick: () => {
2100
- const newTableBody = body.filter((_, j) => j !== i + (schema.__bodyRange?.start ?? 0));
2740
+ const newTableBody = body.filter((_, j) => j !== i + (bodyRange?.start ?? 0));
2101
2741
  if (onChange) onChange({
2102
2742
  key: "content",
2103
2743
  value: JSON.stringify(newTableBody)
@@ -2107,7 +2747,7 @@ var uiRender = async (arg) => {
2107
2747
  });
2108
2748
  };
2109
2749
  if (mode === "form" && onChange && !schema.readOnly) {
2110
- if (schema.__bodyRange?.end === void 0 || schema.__bodyRange.end >= JSON.parse(value || "[]").length) rootElement.appendChild(createAddRowButton());
2750
+ if (bodyRange?.end === void 0 || bodyRange.end >= JSON.parse(value || "[]").length) rootElement.appendChild(createAddRowButton());
2111
2751
  createRemoveRowButtons().forEach((button) => rootElement.appendChild(button));
2112
2752
  }
2113
2753
  if (mode === "designer" && onChange) {
@@ -2117,6 +2757,7 @@ var uiRender = async (arg) => {
2117
2757
  top: `${(showHead ? table.getHeadHeight() : 0) - px2mm(buttonSize)}mm`,
2118
2758
  right: `-${buttonSize}px`,
2119
2759
  text: "+",
2760
+ ariaLabel: "Add column",
2120
2761
  onClick: (e) => {
2121
2762
  e.preventDefault();
2122
2763
  const newColumnWidthPercentage = 25;
@@ -2152,6 +2793,7 @@ var uiRender = async (arg) => {
2152
2793
  top: `${-buttonSize}px`,
2153
2794
  left: `${offsetX - px2mm(buttonSize)}mm`,
2154
2795
  text: "-",
2796
+ ariaLabel: "Remove column",
2155
2797
  onClick: () => {
2156
2798
  const totalWidthMinusRemoved = schema.headWidthPercentages.reduce((sum, width, j) => j !== i ? sum + width : sum, 0);
2157
2799
  onChange([
@@ -5318,13 +5960,13 @@ var schema$3 = {
5318
5960
  propPanel: {
5319
5961
  ...textSchema.propPanel,
5320
5962
  widgets: {
5321
- ...propPanel$2.widgets,
5963
+ ...propPanel$3.widgets,
5322
5964
  addOptions
5323
5965
  },
5324
5966
  schema: (propPanelProps) => {
5325
- if (typeof propPanel$2.schema !== "function") throw Error("Oops, is text schema no longer a function?");
5967
+ if (typeof propPanel$3.schema !== "function") throw Error("Oops, is text schema no longer a function?");
5326
5968
  return {
5327
- ...propPanel$2.schema(propPanelProps),
5969
+ ...propPanel$3.schema(propPanelProps),
5328
5970
  "-------": {
5329
5971
  type: "void",
5330
5972
  widget: "Divider"
@@ -5506,6 +6148,6 @@ var schema = {
5506
6148
  icon: getCheckedIcon()
5507
6149
  };
5508
6150
  //#endregion
5509
- export { barcodes, builtInPlugins, schema as checkbox, date_default as date, dateTime_default as dateTime, ellipse, getDynamicHeightsForTable, imageSchema as image, lineSchema as line, schema$1 as multiVariableText, schema$2 as radioGroup, rectangle, schema$3 as select, signature, svgSchema as svg, tableSchema as table, textSchema as text, time_default as time };
6151
+ export { BUILT_IN_DYNAMIC_LAYOUT_SPLIT_UNITS, LIST_ITEM_SPLIT_UNIT, TABLE_BODY_SPLIT_UNIT, TEXT_LINE_SPLIT_UNIT, barcodes, builtInPlugins, schema as checkbox, createListItemSplitRange, createTableBodySplitRange, createTextLineSplitRange, date_default as date, dateTime_default as dateTime, ellipse, getDynamicHeightsForTable, getDynamicLayoutForList, getDynamicLayoutForTable, getListItemRange, getTableBodyRange, getTextLineRange, imageSchema as image, lineSchema as line, listSchema as list, schema$1 as multiVariableText, schema$2 as radioGroup, rectangle, schema$3 as select, signature, svgSchema as svg, tableSchema as table, textSchema as text, time_default as time };
5510
6152
 
5511
6153
  //# sourceMappingURL=index.js.map