@pdfme/ui 6.2.1 → 6.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -45448,7 +45448,7 @@ function parseExpressionAt(input, pos, options) {
45448
45448
  }
45449
45449
  //#endregion
45450
45450
  //#region ../common/dist/index.js
45451
- var PDFME_VERSION = "6.2.1";
45451
+ var PDFME_VERSION = "6.2.2";
45452
45452
  var PAGE_SIZE_PRESETS = {
45453
45453
  A3: {
45454
45454
  width: 297,
@@ -56820,7 +56820,7 @@ var dictionaries = {
56820
56820
  bulkUpdateFieldName: "Bulk update field names",
56821
56821
  addPageAfter: "Add Page After",
56822
56822
  removePage: "Remove Current Page",
56823
- removePageConfirm: "Are you sure you want to delete this page? This action cannot be undone.",
56823
+ removePageConfirm: "Are you sure you want to delete this page?",
56824
56824
  zoomIn: "Zoom in",
56825
56825
  zoomOut: "Zoom out",
56826
56826
  fitWidth: "Fit width",
@@ -56940,7 +56940,7 @@ var dictionaries = {
56940
56940
  bulkUpdateFieldName: "批量更新字段名称",
56941
56941
  addPageAfter: "在之后添加页面",
56942
56942
  removePage: "删除当前页面",
56943
- removePageConfirm: "您确定要删除此页面吗?此操作无法撤销。",
56943
+ removePageConfirm: "您确定要删除此页面吗?",
56944
56944
  zoomIn: "放大",
56945
56945
  zoomOut: "缩小",
56946
56946
  fitWidth: "适合宽度",
@@ -57060,7 +57060,7 @@ var dictionaries = {
57060
57060
  bulkUpdateFieldName: "批量更新字段名稱",
57061
57061
  addPageAfter: "在之後添加頁面",
57062
57062
  removePage: "刪除當前頁面",
57063
- removePageConfirm: "您確定要刪除此頁面嗎?此操作無法撤銷。",
57063
+ removePageConfirm: "您確定要刪除此頁面嗎?",
57064
57064
  zoomIn: "放大",
57065
57065
  zoomOut: "縮小",
57066
57066
  fitWidth: "適合寬度",
@@ -57180,7 +57180,7 @@ var dictionaries = {
57180
57180
  bulkUpdateFieldName: "項目名を一括変更",
57181
57181
  addPageAfter: "次にページを追加",
57182
57182
  removePage: "現在のページを削除",
57183
- removePageConfirm: "ページを削除してもよろしいですか?この操作は元に戻せません。",
57183
+ removePageConfirm: "ページを削除してもよろしいですか?",
57184
57184
  zoomIn: "拡大",
57185
57185
  zoomOut: "縮小",
57186
57186
  fitWidth: "横幅に合わせる",
@@ -57300,7 +57300,7 @@ var dictionaries = {
57300
57300
  bulkUpdateFieldName: "필드 이름 일괄 업데이트",
57301
57301
  addPageAfter: "다음에 페이지 추가",
57302
57302
  removePage: "현재 페이지 제거",
57303
- removePageConfirm: "이 페이지를 삭제하시겠습니까? 이 작업은 취소할 수 없습니다.",
57303
+ removePageConfirm: "이 페이지를 삭제하시겠습니까?",
57304
57304
  zoomIn: "확대",
57305
57305
  zoomOut: "축소",
57306
57306
  fitWidth: "너비에 맞춤",
@@ -57420,7 +57420,7 @@ var dictionaries = {
57420
57420
  bulkUpdateFieldName: "تغيير الأسماء",
57421
57421
  addPageAfter: "إضافة صفحة بعد",
57422
57422
  removePage: "احذف الصفحة الحالية",
57423
- removePageConfirm: "هل أنت متأكد من رغبتك في حذف هذه الصفحة؟ لا يمكن التراجع عن هذا الإجراء.",
57423
+ removePageConfirm: "هل أنت متأكد من رغبتك في حذف هذه الصفحة؟",
57424
57424
  zoomIn: "تكبير",
57425
57425
  zoomOut: "تصغير",
57426
57426
  fitWidth: "ملاءمة العرض",
@@ -57540,7 +57540,7 @@ var dictionaries = {
57540
57540
  bulkUpdateFieldName: "แก้ไขชื่อฟิลด์เป็นชุด",
57541
57541
  addPageAfter: "เพิ่มหน้าถัดไป",
57542
57542
  removePage: "ลบหน้าปัจจุบัน",
57543
- removePageConfirm: "คุณแน่ใจหรือไม่ว่าต้องการลบหน้านี้? การกระทำนี้ไม่สามารถย้อนกลับได้",
57543
+ removePageConfirm: "คุณแน่ใจหรือไม่ว่าต้องการลบหน้านี้?",
57544
57544
  zoomIn: "ซูมเข้า",
57545
57545
  zoomOut: "ซูมออก",
57546
57546
  fitWidth: "พอดีกับความกว้าง",
@@ -57660,7 +57660,7 @@ var dictionaries = {
57660
57660
  bulkUpdateFieldName: "Alan adlarını toplu güncelle",
57661
57661
  addPageAfter: "Sonrasına Sayfa Ekle",
57662
57662
  removePage: "Mevcut Sayfayı Kaldır",
57663
- removePageConfirm: "Bu sayfayı silmek istediğinizden emin misiniz? Bu işlem geri alınamaz.",
57663
+ removePageConfirm: "Bu sayfayı silmek istediğinizden emin misiniz?",
57664
57664
  zoomIn: "Yakınlaştır",
57665
57665
  zoomOut: "Uzaklaştır",
57666
57666
  fitWidth: "Genişliğe sığdır",
@@ -57780,7 +57780,7 @@ var dictionaries = {
57780
57780
  bulkUpdateFieldName: "Modifica nomi campi in blocco",
57781
57781
  addPageAfter: "Aggiungi pagina dopo",
57782
57782
  removePage: "Rimuovi la Pagina Corrente",
57783
- removePageConfirm: "Sei sicuro di voler eliminare questa pagina? Questa azione non può essere annullata.",
57783
+ removePageConfirm: "Sei sicuro di voler eliminare questa pagina?",
57784
57784
  zoomIn: "Ingrandisci",
57785
57785
  zoomOut: "Riduci",
57786
57786
  fitWidth: "Adatta larghezza",
@@ -57900,7 +57900,7 @@ var dictionaries = {
57900
57900
  bulkUpdateFieldName: "Masowo aktualizuj klucze pól",
57901
57901
  addPageAfter: "Dodaj stronę po",
57902
57902
  removePage: "Usuń Bieżącą Stronę",
57903
- removePageConfirm: "Czy na pewno chcesz usunąć tę stronę? Tej operacji nie można cofnąć.",
57903
+ removePageConfirm: "Czy na pewno chcesz usunąć tę stronę?",
57904
57904
  zoomIn: "Powiększ",
57905
57905
  zoomOut: "Pomniejsz",
57906
57906
  fitWidth: "Dopasuj szerokość",
@@ -58020,7 +58020,7 @@ var dictionaries = {
58020
58020
  bulkUpdateFieldName: "Mehrfachaktualisierung der Feldnamen",
58021
58021
  addPageAfter: "Seite danach hinzufügen",
58022
58022
  removePage: "Aktuelle Seite entfernen",
58023
- removePageConfirm: "Sind Sie sicher, dass Sie diese Seite löschen möchten? Diese Aktion kann nicht rückgängig gemacht werden.",
58023
+ removePageConfirm: "Sind Sie sicher, dass Sie diese Seite löschen möchten?",
58024
58024
  zoomIn: "Vergrößern",
58025
58025
  zoomOut: "Verkleinern",
58026
58026
  fitWidth: "Breite anpassen",
@@ -58140,7 +58140,7 @@ var dictionaries = {
58140
58140
  bulkUpdateFieldName: "Actualizar en bloque el nombre de los campos",
58141
58141
  addPageAfter: "Insertar página",
58142
58142
  removePage: "Eliminar página actual",
58143
- removePageConfirm: "¿Estás seguro de que quieres eliminar esta página? Esta acción no se puede deshacer.",
58143
+ removePageConfirm: "¿Estás seguro de que quieres eliminar esta página?",
58144
58144
  zoomIn: "Acercar",
58145
58145
  zoomOut: "Alejar",
58146
58146
  fitWidth: "Ajustar ancho",
@@ -58260,7 +58260,7 @@ var dictionaries = {
58260
58260
  bulkUpdateFieldName: "Modifier les noms de champs en masse",
58261
58261
  addPageAfter: "Ajouter une page après",
58262
58262
  removePage: "Supprimer la page actuelle",
58263
- removePageConfirm: "Êtes-vous sûr de vouloir supprimer cette page ? Cette action est irréversible.",
58263
+ removePageConfirm: "Êtes-vous sûr de vouloir supprimer cette page ?",
58264
58264
  zoomIn: "Zoom avant",
58265
58265
  zoomOut: "Zoom arrière",
58266
58266
  fitWidth: "Ajuster la largeur",
@@ -85536,7 +85536,7 @@ var measureRichTextLineHeights = (lines, fontSize, lineHeight, fallbackFont) =>
85536
85536
  return lines.map((line, index) => pt2mm(getLineBoxHeightPt(fontSize, index === 0, line.runs.map((run) => run.fontKitFont), fallbackFont) * lineHeight));
85537
85537
  };
85538
85538
  //#endregion
85539
- //#region ../schemas/dist/dynamicTemplate-DkTVIMNr.js
85539
+ //#region ../schemas/dist/dynamicTemplate-BecnZ8Uf.js
85540
85540
  function _typeof$17(o) {
85541
85541
  "@babel/helpers - typeof";
85542
85542
  return _typeof$17 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -86035,7 +86035,7 @@ function createSingleTable(body, args) {
86035
86035
  _cache
86036
86036
  });
86037
86037
  }
86038
- var HEX_COLOR_PATTERN = "^#(?:[A-Fa-f0-9]{6})$";
86038
+ var HEX_COLOR_PATTERN = "^#(?:[A-Fa-f0-9]{3,4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$";
86039
86039
  var getBody$1 = (value) => {
86040
86040
  if (typeof value === "string") return JSON.parse(value || "[]");
86041
86041
  return value || [];
@@ -86113,7 +86113,7 @@ var getDynamicLayoutForTable = async (value, args) => {
86113
86113
  };
86114
86114
  };
86115
86115
  //#endregion
86116
- //#region ../schemas/dist/utils-CPYF2FY_.js
86116
+ //#region ../schemas/dist/utils-DUdv_Vvk.js
86117
86117
  var convertForPdfLayoutProps = ({ schema, pageHeight, applyRotateTranslate = true }) => {
86118
86118
  const { width: mmWidth, height: mmHeight, position, rotate, opacity } = schema;
86119
86119
  const { x: mmX, y: mmY } = position;
@@ -86153,7 +86153,26 @@ var rotatePoint = (point, pivot, angleDegrees) => {
86153
86153
  };
86154
86154
  };
86155
86155
  var isEditable = (mode, schema) => mode === "designer" || mode === "form" && schema.readOnly !== true;
86156
+ var splitHexAlpha = (hexColor) => {
86157
+ if (!hexColor.startsWith("#")) return {
86158
+ color: hexColor,
86159
+ alpha: 1
86160
+ };
86161
+ const hex = hexColor.slice(1);
86162
+ if (!/^(?:[0-9a-f]{4}|[0-9a-f]{8})$/i.test(hex)) return {
86163
+ color: hexColor,
86164
+ alpha: 1
86165
+ };
86166
+ const rgbLength = hex.length === 4 ? 3 : 6;
86167
+ const alphaHex = hex.slice(rgbLength);
86168
+ return {
86169
+ color: `#${hex.slice(0, rgbLength)}`,
86170
+ alpha: parseInt(alphaHex.length === 1 ? alphaHex.repeat(2) : alphaHex, 16) / 255
86171
+ };
86172
+ };
86173
+ var applyAlphaToOpacity = (opacity, alpha) => alpha === 1 ? opacity : (opacity ?? 1) * alpha;
86156
86174
  var hex2rgb = (hex) => {
86175
+ hex = splitHexAlpha(hex).color;
86157
86176
  if (hex.slice(0, 1) === "#") hex = hex.slice(1);
86158
86177
  if (hex.length === 3) hex = hex.slice(0, 1) + hex.slice(0, 1) + hex.slice(1, 2) + hex.slice(1, 2) + hex.slice(2, 3) + hex.slice(2, 3);
86159
86178
  return [
@@ -86162,11 +86181,6 @@ var hex2rgb = (hex) => {
86162
86181
  hex.slice(4, 6)
86163
86182
  ].map((str) => parseInt(str, 16));
86164
86183
  };
86165
- var getHexOpacity = (hex) => {
86166
- const normalized = hex.startsWith("#") ? hex.slice(1) : hex;
86167
- const opacityHex = normalized.length === 4 ? normalized.slice(3, 4).repeat(2) : normalized.length === 8 ? normalized.slice(6, 8) : "";
86168
- return opacityHex ? parseInt(opacityHex, 16) / 255 : 1;
86169
- };
86170
86184
  var rgbColorToCmykColor = ({ red, green, blue }) => {
86171
86185
  const key = 1 - Math.max(red, green, blue);
86172
86186
  return cmyk(key === 1 ? 0 : (1 - red - key) / (1 - key), key === 1 ? 0 : (1 - green - key) / (1 - key), key === 1 ? 0 : (1 - blue - key) / (1 - key), key);
@@ -86181,11 +86195,7 @@ var hex2RgbColor = (hexString) => {
86181
86195
  var hex2CmykColor = (hexString) => {
86182
86196
  if (hexString) {
86183
86197
  if (!isHexValid(hexString)) throw new Error(`Invalid hex color value ${hexString}`);
86184
- let [r, g, b] = hex2rgb(hexString).map((value) => value / 255);
86185
- const opacity = getHexOpacity(hexString);
86186
- r = r * opacity + (1 - opacity);
86187
- g = g * opacity + (1 - opacity);
86188
- b = b * opacity + (1 - opacity);
86198
+ const [r, g, b] = hex2rgb(hexString).map((value) => value / 255);
86189
86199
  return rgbColorToCmykColor(rgb(r, g, b));
86190
86200
  }
86191
86201
  };
@@ -86406,7 +86416,7 @@ var Underline = [["path", { d: "M6 4v6a6 6 0 0 0 12 0V4" }], ["line", {
86406
86416
  y2: "20"
86407
86417
  }]];
86408
86418
  //#endregion
86409
- //#region ../schemas/dist/builtins-C-2wyB_3.js
86419
+ //#region ../schemas/dist/builtins-BID2DSHc.js
86410
86420
  var addUriLinkAnnotation = (arg) => {
86411
86421
  const { pdfDoc, page, uri, rect, borderWidth = 0 } = arg;
86412
86422
  const safeUri = normalizeSafeLinkUri(uri);
@@ -86514,7 +86524,7 @@ var getLinkAnnotationRect = (arg) => {
86514
86524
  });
86515
86525
  };
86516
86526
  var drawRun = (arg) => {
86517
- const { page, pdfLib, run, pdfFont, x, y, rotate, pivotPoint, fontSize, lineHeight, color, opacity, colorType, characterSpacing, strikethrough, underline } = arg;
86527
+ const { page, pdfLib, run, pdfFont, x, y, rotate, pivotPoint, fontSize, lineHeight, color, opacity, textOpacity, colorType, characterSpacing, strikethrough, underline } = arg;
86518
86528
  const runWidth = getRunWidth(run, fontSize, characterSpacing);
86519
86529
  const codePadding = run.code ? CODE_HORIZONTAL_PADDING : 0;
86520
86530
  const textX = x + codePadding;
@@ -86549,7 +86559,7 @@ var drawRun = (arg) => {
86549
86559
  pivotPoint,
86550
86560
  fontSize,
86551
86561
  color,
86552
- opacity
86562
+ opacity: textOpacity
86553
86563
  });
86554
86564
  if (underline && runWidth > 0) drawDecorationLine({
86555
86565
  page,
@@ -86560,7 +86570,7 @@ var drawRun = (arg) => {
86560
86570
  pivotPoint,
86561
86571
  fontSize,
86562
86572
  color,
86563
- opacity
86573
+ opacity: textOpacity
86564
86574
  });
86565
86575
  const drawAt = (drawX) => {
86566
86576
  const point = rotate.angle === 0 ? {
@@ -86578,7 +86588,7 @@ var drawRun = (arg) => {
86578
86588
  color,
86579
86589
  lineHeight: lineHeight * fontSize,
86580
86590
  font: pdfFont,
86581
- opacity,
86591
+ opacity: textOpacity,
86582
86592
  ...run.syntheticItalic ? { ySkew: pdfLib.degrees(12) } : {}
86583
86593
  });
86584
86594
  };
@@ -86589,7 +86599,8 @@ var drawRun = (arg) => {
86589
86599
  }
86590
86600
  };
86591
86601
  var renderInlineMarkdownText = async (arg) => {
86592
- const { value, schema, font, embedPdfFont, fontKitFont, pdfDoc, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, y, width, height, pivotPoint, rotate, opacity } = arg;
86602
+ const { value, schema, font, embedPdfFont, fontKitFont, pdfDoc, page, pdfLib, _cache, colorType, fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing, x, y, width, height, pivotPoint, rotate, opacity, colorAlpha } = arg;
86603
+ const textOpacity = applyAlphaToOpacity(opacity, colorAlpha);
86593
86604
  const lines = applyTextLineRange(layoutRichTextLines({
86594
86605
  runs: await resolveRichTextRuns({
86595
86606
  runs: parseInlineMarkdown(value),
@@ -86635,7 +86646,7 @@ var renderInlineMarkdownText = async (arg) => {
86635
86646
  pivotPoint,
86636
86647
  fontSize,
86637
86648
  color,
86638
- opacity
86649
+ opacity: textOpacity
86639
86650
  });
86640
86651
  if (schema.underline) drawDecorationLine({
86641
86652
  page,
@@ -86646,7 +86657,7 @@ var renderInlineMarkdownText = async (arg) => {
86646
86657
  pivotPoint,
86647
86658
  fontSize,
86648
86659
  color,
86649
- opacity
86660
+ opacity: textOpacity
86650
86661
  });
86651
86662
  }
86652
86663
  line.runs.reduce((currentX, run, runIndex) => {
@@ -86665,6 +86676,7 @@ var renderInlineMarkdownText = async (arg) => {
86665
86676
  lineHeight,
86666
86677
  color,
86667
86678
  opacity,
86679
+ textOpacity,
86668
86680
  colorType,
86669
86681
  characterSpacing: spacing,
86670
86682
  strikethrough: Boolean(run.strikethrough),
@@ -86717,13 +86729,14 @@ var embedAndGetFont = (arg) => {
86717
86729
  const pdfFontCache = getPdfFontCache(_cache);
86718
86730
  const cachedFont = pdfFontCache[fontName];
86719
86731
  if (cachedFont) return cachedFont;
86720
- const fontValue = font[fontName];
86721
- if (!fontValue) return Promise.reject(/* @__PURE__ */ new Error(`[@pdfme/schemas] Font "${fontName}" is not found.`));
86722
86732
  const pdfFontPromise = (async () => {
86733
+ const fontValue = font[fontName];
86734
+ if (!fontValue) throw new Error(`[@pdfme/schemas] Font "${fontName}" is not found.`);
86723
86735
  let fontData = fontValue.data;
86724
86736
  if (typeof fontData === "string" && fontData.startsWith("http")) fontData = await fetchRemoteFontData(fontData);
86725
86737
  return pdfDoc.embedFont(fontData, { subset: typeof fontValue.subset === "undefined" ? true : fontValue.subset });
86726
86738
  })();
86739
+ pdfFontPromise.catch(() => {});
86727
86740
  pdfFontCache[fontName] = pdfFontPromise;
86728
86741
  return pdfFontPromise;
86729
86742
  };
@@ -86733,14 +86746,16 @@ var getFontProp = ({ value, fontKitFont, schema, basePdf, colorType, fontSize: r
86733
86746
  fontKitFont,
86734
86747
  value
86735
86748
  }) : schema.fontSize ?? 13);
86736
- const color = hex2PrintingColor(schema.fontColor || "#000000", colorType);
86749
+ const { color: fontColorHex, alpha: colorAlpha } = splitHexAlpha(schema.fontColor || "#000000");
86750
+ const color = hex2PrintingColor(fontColorHex, colorType);
86737
86751
  return {
86738
86752
  alignment: schema.alignment ?? "left",
86739
86753
  verticalAlignment: schema.verticalAlignment ?? "top",
86740
86754
  lineHeight: schema.lineHeight ?? 1,
86741
86755
  characterSpacing: schema.characterSpacing ?? 0,
86742
86756
  fontSize,
86743
- color
86757
+ color,
86758
+ colorAlpha
86744
86759
  };
86745
86760
  };
86746
86761
  var pdfRender = async (arg) => {
@@ -86782,7 +86797,7 @@ var pdfRender = async (arg) => {
86782
86797
  _cache
86783
86798
  });
86784
86799
  const fontKitFont = await getFontKitFont(schema.fontName, font, _cache);
86785
- const { fontSize, color, alignment, verticalAlignment, lineHeight, characterSpacing } = getFontProp({
86800
+ const { fontSize, color, colorAlpha, alignment, verticalAlignment, lineHeight, characterSpacing } = getFontProp({
86786
86801
  value: enableInlineMarkdown ? stripInlineMarkdown(value) : value,
86787
86802
  fontKitFont,
86788
86803
  schema,
@@ -86795,6 +86810,7 @@ var pdfRender = async (arg) => {
86795
86810
  _cache
86796
86811
  }) : void 0
86797
86812
  });
86813
+ const textOpacity = applyAlphaToOpacity(opacity, colorAlpha);
86798
86814
  if (enableInlineMarkdown) {
86799
86815
  await renderInlineMarkdownText({
86800
86816
  value,
@@ -86824,7 +86840,8 @@ var pdfRender = async (arg) => {
86824
86840
  height: contentHeight,
86825
86841
  pivotPoint,
86826
86842
  rotate,
86827
- opacity
86843
+ opacity,
86844
+ colorAlpha
86828
86845
  });
86829
86846
  return;
86830
86847
  }
@@ -86876,7 +86893,7 @@ var pdfRender = async (arg) => {
86876
86893
  }, pivotPoint, rotate.angle),
86877
86894
  thickness: 1 / 12 * fontSize,
86878
86895
  color,
86879
- opacity
86896
+ opacity: textOpacity
86880
86897
  });
86881
86898
  }
86882
86899
  if (schema.underline && textWidth > 0) {
@@ -86893,7 +86910,7 @@ var pdfRender = async (arg) => {
86893
86910
  }, pivotPoint, rotate.angle),
86894
86911
  thickness: 1 / 12 * fontSize,
86895
86912
  color,
86896
- opacity
86913
+ opacity: textOpacity
86897
86914
  });
86898
86915
  }
86899
86916
  if (rotate.angle !== 0) {
@@ -86913,7 +86930,7 @@ var pdfRender = async (arg) => {
86913
86930
  color,
86914
86931
  lineHeight: lineHeight * fontSize,
86915
86932
  font: pdfFontValue,
86916
- opacity
86933
+ opacity: textOpacity
86917
86934
  });
86918
86935
  });
86919
86936
  };
@@ -86937,21 +86954,24 @@ var drawTextBoxDecoration = (arg) => {
86937
86954
  height: rect.height,
86938
86955
  rotate,
86939
86956
  color: rect.color,
86940
- opacity
86957
+ opacity: opacity * rect.alpha
86941
86958
  });
86942
86959
  };
86943
86960
  if (schema.backgroundColor) {
86944
- const color = hex2PrintingColor(schema.backgroundColor, colorType);
86961
+ const { color: bgHex, alpha } = splitHexAlpha(schema.backgroundColor);
86962
+ const color = hex2PrintingColor(bgHex, colorType);
86945
86963
  if (color) drawRectangle({
86946
86964
  x,
86947
86965
  y,
86948
86966
  width,
86949
86967
  height,
86950
- color
86968
+ color,
86969
+ alpha
86951
86970
  });
86952
86971
  }
86953
86972
  if (!schema.borderColor || !hasBoxDimension(schema.borderWidth)) return;
86954
- const color = hex2PrintingColor(schema.borderColor, colorType);
86973
+ const { color: borderHex, alpha } = splitHexAlpha(schema.borderColor);
86974
+ const color = hex2PrintingColor(borderHex, colorType);
86955
86975
  if (!color) return;
86956
86976
  const top = mm2pt(borderWidth.top);
86957
86977
  const right = mm2pt(borderWidth.right);
@@ -86962,28 +86982,32 @@ var drawTextBoxDecoration = (arg) => {
86962
86982
  y: y + height - top,
86963
86983
  width,
86964
86984
  height: top,
86965
- color
86985
+ color,
86986
+ alpha
86966
86987
  });
86967
86988
  drawRectangle({
86968
86989
  x: x + width - right,
86969
86990
  y,
86970
86991
  width: right,
86971
86992
  height,
86972
- color
86993
+ color,
86994
+ alpha
86973
86995
  });
86974
86996
  drawRectangle({
86975
86997
  x,
86976
86998
  y,
86977
86999
  width,
86978
87000
  height: bottom,
86979
- color
87001
+ color,
87002
+ alpha
86980
87003
  });
86981
87004
  drawRectangle({
86982
87005
  x,
86983
87006
  y,
86984
87007
  width: left,
86985
87008
  height,
86986
- color
87009
+ color,
87010
+ alpha
86987
87011
  });
86988
87012
  };
86989
87013
  var TextStrikethroughIcon = createSvgStr(Strikethrough);
@@ -87227,7 +87251,6 @@ var propPanel = {
87227
87251
  title: i18n("schemas.textColor"),
87228
87252
  type: "string",
87229
87253
  widget: "color",
87230
- props: { disabledAlpha: true },
87231
87254
  rules: [{
87232
87255
  pattern: HEX_COLOR_PATTERN,
87233
87256
  message: i18n("validation.hexColor")
@@ -87237,7 +87260,6 @@ var propPanel = {
87237
87260
  title: i18n("schemas.bgColor"),
87238
87261
  type: "string",
87239
87262
  widget: "color",
87240
- props: { disabledAlpha: true },
87241
87263
  rules: [{
87242
87264
  pattern: HEX_COLOR_PATTERN,
87243
87265
  message: i18n("validation.hexColor")
@@ -87247,7 +87269,6 @@ var propPanel = {
87247
87269
  title: i18n("schemas.borderColor"),
87248
87270
  type: "string",
87249
87271
  widget: "color",
87250
- props: { disabledAlpha: true },
87251
87272
  rules: [{
87252
87273
  pattern: HEX_COLOR_PATTERN,
87253
87274
  message: i18n("validation.hexColor")
@@ -87821,6 +87842,13 @@ var round$2 = (number, precision) => {
87821
87842
  return shift(Math.round(shift(number, precision, false)), precision, true);
87822
87843
  };
87823
87844
  var flatten = (arr) => [].concat(...arr);
87845
+ /**
87846
+ * Single source of truth for whether a schema type supports rotation in the
87847
+ * Designer (rotate handle on the canvas and rotate input in the detail view).
87848
+ * A plugin opts out by omitting `rotate` from its propPanel.defaultSchema or
87849
+ * setting it to `undefined` (e.g. `{ ...text.propPanel.defaultSchema, rotate: undefined }`).
87850
+ */
87851
+ var isRotatableSchema = (defaultSchema) => typeof defaultSchema?.rotate !== "undefined";
87824
87852
  var up = "up";
87825
87853
  var shiftUp = "shift+up";
87826
87854
  var down = "down";
@@ -87972,9 +88000,7 @@ var template2SchemasList = async (_template) => {
87972
88000
  const pdfArrayBuffer = b64toUint8Array(await getB64BasePdf(basePdf));
87973
88001
  pageSizes = await pdf2size(pdfArrayBuffer);
87974
88002
  }
87975
- const ssl = schemasForUI.length;
87976
- const psl = pageSizes.length;
87977
- return (ssl < psl ? schemasForUI.concat(Array.from({ length: psl - ssl }, () => cloneDeep$1([]))) : schemasForUI.slice(0, pageSizes.length)).map((schema, i) => {
88003
+ return alignSchemasListToPageCount(schemasForUI, pageSizes.length).map((schema, i) => {
87978
88004
  Object.values(schema).forEach((value) => {
87979
88005
  const { width, height } = pageSizes[i];
87980
88006
  const xEdge = value.position.x + value.width;
@@ -87985,6 +88011,26 @@ var template2SchemasList = async (_template) => {
87985
88011
  return schema;
87986
88012
  });
87987
88013
  };
88014
+ /**
88015
+ * Pad or truncate schema pages so the list length matches `pageCount`.
88016
+ * Empty pages are distinct arrays. This is the same alignment `template2SchemasList`
88017
+ * uses when a base PDF's page count and the schema pages differ.
88018
+ */
88019
+ var alignSchemasListToPageCount = (schemasList, pageCount) => {
88020
+ if (schemasList.length === pageCount) return schemasList;
88021
+ if (schemasList.length < pageCount) return schemasList.concat(Array.from({ length: pageCount - schemasList.length }, () => []));
88022
+ return schemasList.slice(0, Math.max(pageCount, 0));
88023
+ };
88024
+ /**
88025
+ * Fit a history snapshot to the pages of the current base PDF.
88026
+ * Blank PDFs follow the snapshot length. A non-blank PDF keeps `pageSizes.length`,
88027
+ * using the same pad/truncate as `template2SchemasList`. A zero page count means
88028
+ * sizes are not loaded yet, so the snapshot is left unchanged.
88029
+ */
88030
+ var normalizeSchemasListForBasePdf = (schemasList, basePdf, pageCount) => {
88031
+ if (isBlankPdf(basePdf) || pageCount <= 0) return schemasList;
88032
+ return alignSchemasListToPageCount(schemasList, pageCount);
88033
+ };
87988
88034
  var schemasList2template = (schemasList, basePdf) => ({
87989
88035
  schemas: cloneDeep$1(schemasList).map((page) => page.map((schema) => {
87990
88036
  delete schema.id;
@@ -133172,7 +133218,7 @@ var useMountStatus = () => {
133172
133218
  }, []);
133173
133219
  return isMounted;
133174
133220
  };
133175
- var useInitEvents = ({ pageCursor, pageSizes, activeElements, template, schemasList, changeSchemas, commitSchemas, removeSchemas, onSaveTemplate, past, future, setSchemasList, onEdit, onEditEnd }) => {
133221
+ var useInitEvents = ({ pageCursor, pageSizes, activeElements, template, schemasList, changeSchemas, commitSchemas, removeSchemas, onSaveTemplate, undo, redo, onEdit, onEditEnd }) => {
133176
133222
  const copiedSchemas = (0, import_react$9.useRef)(null);
133177
133223
  const initEvents = (0, import_react$9.useCallback)(() => {
133178
133224
  const getElementsByIds = (ids) => ids.map((id) => document.getElementById(id)).filter((element) => element instanceof HTMLElement);
@@ -133180,15 +133226,6 @@ var useInitEvents = ({ pageCursor, pageSizes, activeElements, template, schemasL
133180
133226
  const ids = activeElements.map((ae) => ae.id);
133181
133227
  return schemasList[pageCursor].filter((s) => ids.includes(s.id));
133182
133228
  };
133183
- const timeTravel = (mode) => {
133184
- const isUndo = mode === "undo";
133185
- const stack = isUndo ? past : future;
133186
- if (stack.current.length <= 0) return;
133187
- (isUndo ? future : past).current.push(cloneDeep$1(schemasList[pageCursor]));
133188
- const s = cloneDeep$1(schemasList);
133189
- s[pageCursor] = stack.current.pop();
133190
- setSchemasList(s);
133191
- };
133192
133229
  initShortCuts({
133193
133230
  move: (command, isShift) => {
133194
133231
  const pageSize = pageSizes[pageCursor];
@@ -133233,8 +133270,8 @@ var useInitEvents = ({ pageCursor, pageSizes, activeElements, template, schemasL
133233
133270
  });
133234
133271
  copiedSchemas.current = pasteSchemas;
133235
133272
  },
133236
- redo: () => timeTravel("redo"),
133237
- undo: () => timeTravel("undo"),
133273
+ redo: () => redo(),
133274
+ undo: () => undo(),
133238
133275
  save: () => onSaveTemplate && onSaveTemplate(schemasList2template(schemasList, template.basePdf)),
133239
133276
  remove: () => removeSchemas(getActiveSchemas().map((s) => s.id)),
133240
133277
  esc: onEditEnd,
@@ -133250,9 +133287,8 @@ var useInitEvents = ({ pageCursor, pageSizes, activeElements, template, schemasL
133250
133287
  schemasList,
133251
133288
  onSaveTemplate,
133252
133289
  removeSchemas,
133253
- past,
133254
- future,
133255
- setSchemasList,
133290
+ undo,
133291
+ redo,
133256
133292
  copiedSchemas,
133257
133293
  onEdit,
133258
133294
  onEditEnd
@@ -215721,10 +215757,10 @@ var ButtonGroupWidget = (props) => {
215721
215757
  //#endregion
215722
215758
  //#region src/components/Designer/RightSidebar/DetailView/ColorWidget.tsx
215723
215759
  var DEFAULT_COLOR = "#000000";
215724
- var HEX_COLOR_REGEXP = /^#(?:[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
215725
- var isCommittableColor = (value) => value === "" || HEX_COLOR_REGEXP.test(value);
215760
+ var HEX_COLOR_REGEXP = /^#(?:[0-9A-Fa-f]{3,4}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
215761
+ var FULL_HEX_COLOR_REGEXP = /^#(?:[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
215726
215762
  var ColorWidget = (props) => {
215727
- const { value, onChange, disabled, disabledAlpha = true, readOnly, className, style } = props;
215763
+ const { value, onChange, disabled, disabledAlpha = false, readOnly, className, style } = props;
215728
215764
  const [inputValue, setInputValue] = (0, import_react$9.useState)(value ?? "");
215729
215765
  (0, import_react$9.useEffect)(() => {
215730
215766
  setInputValue(value ?? "");
@@ -215734,8 +215770,15 @@ var ColorWidget = (props) => {
215734
215770
  children: value || ""
215735
215771
  });
215736
215772
  const commit = (next) => {
215773
+ onChange?.(next === "" ? void 0 : next);
215774
+ };
215775
+ const handleInputChange = (next) => {
215737
215776
  setInputValue(next);
215738
- if (isCommittableColor(next)) onChange?.(next === "" ? void 0 : next);
215777
+ if (next === "" || FULL_HEX_COLOR_REGEXP.test(next)) commit(next);
215778
+ };
215779
+ const handleInputCommit = () => {
215780
+ if (HEX_COLOR_REGEXP.test(inputValue)) commit(inputValue);
215781
+ else if (inputValue !== "") setInputValue(value ?? "");
215739
215782
  };
215740
215783
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Space$1.Compact, {
215741
215784
  style,
@@ -215745,13 +215788,19 @@ var ColorWidget = (props) => {
215745
215788
  disabled,
215746
215789
  disabledAlpha,
215747
215790
  format: "hex",
215748
- onChange: (color) => commit(color.toHexString())
215791
+ onChange: (color) => {
215792
+ const next = color.toHexString();
215793
+ setInputValue(next);
215794
+ commit(next);
215795
+ }
215749
215796
  }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input$4, {
215750
215797
  className,
215751
215798
  placeholder: DEFAULT_COLOR,
215752
215799
  disabled,
215753
215800
  value: inputValue,
215754
- onChange: (ev) => commit(ev.target.value)
215801
+ onChange: (ev) => handleInputChange(ev.target.value),
215802
+ onBlur: handleInputCommit,
215803
+ onPressEnter: handleInputCommit
215755
215804
  })]
215756
215805
  });
215757
215806
  };
@@ -215762,7 +215811,7 @@ var TEXT_OVERFLOW_EXPAND_SCHEMA_TYPES = /* @__PURE__ */ new Set(["text", "multiV
215762
215811
  var getElementIds = (elements) => elements.map(({ id }) => id);
215763
215812
  var DetailView = (props) => {
215764
215813
  const { token } = theme.useToken();
215765
- const { schemasList, changeSchemas, deselectSchema, activeSchema, pageSize, basePdf } = props;
215814
+ const { schemasList, changeSchemas, syncSchemas, deselectSchema, activeSchema, pageSize, basePdf } = props;
215766
215815
  const formInstance = useForm();
215767
215816
  const form = (0, import_react$9.useRef)(formInstance).current;
215768
215817
  const i18n = (0, import_react$9.useContext)(I18nContext);
@@ -215836,7 +215885,7 @@ var DetailView = (props) => {
215836
215885
  (0, import_react$9.useEffect)(() => {
215837
215886
  if (isBlankPdf(basePdf) || !TEXT_OVERFLOW_EXPAND_SCHEMA_TYPES.has(activeSchema.type)) return;
215838
215887
  if (activeSchema.overflow !== "expand") return;
215839
- changeSchemas([{
215888
+ syncSchemas([{
215840
215889
  key: "overflow",
215841
215890
  value: TEXT_OVERFLOW_VISIBLE,
215842
215891
  schemaId: activeSchema.id
@@ -215844,7 +215893,7 @@ var DetailView = (props) => {
215844
215893
  }, [
215845
215894
  activeSchema,
215846
215895
  basePdf,
215847
- changeSchemas
215896
+ syncSchemas
215848
215897
  ]);
215849
215898
  (0, import_react$9.useEffect)(() => {
215850
215899
  uniqueSchemaName.current = (value) => {
@@ -216056,7 +216105,7 @@ var DetailView = (props) => {
216056
216105
  title: typedI18n("rotate"),
216057
216106
  type: "number",
216058
216107
  widget: "inputNumber",
216059
- disabled: typeof defaultSchema.rotate === "undefined",
216108
+ disabled: !isRotatableSchema(defaultSchema),
216060
216109
  max: 360,
216061
216110
  props: { min: 0 },
216062
216111
  span: 6
@@ -236525,7 +236574,7 @@ var DeleteButton = ({ activeElements: aes, controlScale }) => {
236525
236574
  });
236526
236575
  };
236527
236576
  var Canvas = (props, ref) => {
236528
- const { basePdf, pageCursor, scale, renderScale, backgrounds, pageSizes, size, activeElements, schemasList, hoveringSchemaId, onEdit, changeSchemas, removeSchemas, onChangeHoveringSchemaId, paperRefs, sidebarOpen } = props;
236577
+ const { basePdf, pageCursor, scale, renderScale, backgrounds, pageSizes, size, activeElements, schemasList, hoveringSchemaId, onEdit, changeSchemas, syncSchemas, removeSchemas, onChangeHoveringSchemaId, paperRefs, sidebarOpen } = props;
236529
236578
  const { token } = theme.useToken();
236530
236579
  const pluginsRegistry = (0, import_react$9.useContext)(PluginsRegistry);
236531
236580
  const verticalGuides = (0, import_react$9.useRef)([]);
@@ -236738,8 +236787,7 @@ var Canvas = (props, ref) => {
236738
236787
  if (plugin.propPanel.defaultSchema) defaultSchemas.push(plugin.propPanel.defaultSchema);
236739
236788
  });
236740
236789
  return uniqueSchemaTypes.every((type) => {
236741
- const matchingSchema = defaultSchemas.find((ds) => ds && "type" in ds && ds.type === type);
236742
- return matchingSchema && "rotate" in matchingSchema;
236790
+ return isRotatableSchema(defaultSchemas.find((ds) => ds && "type" in ds && ds.type === type));
236743
236791
  });
236744
236792
  }, [
236745
236793
  activeElements,
@@ -236866,11 +236914,19 @@ var Canvas = (props, ref) => {
236866
236914
  onChangeHoveringSchemaId,
236867
236915
  mode,
236868
236916
  onChange: (schemasList[pageCursor] || []).some((s) => s.id === schema.id) ? (arg) => {
236869
- changeSchemas((Array.isArray(arg) ? arg : [arg]).map(({ key, value }) => ({
236917
+ const changes = (Array.isArray(arg) ? arg : [arg]).map(({ key, value }) => ({
236870
236918
  key,
236871
236919
  value,
236872
236920
  schemaId: schema.id
236873
- })));
236921
+ }));
236922
+ if (changes.length > 0 && changes.every((change) => change.key === "height")) {
236923
+ syncSchemas(changes.map((change) => ({
236924
+ ...change,
236925
+ value: typeof change.value === "number" && Number.isFinite(change.value) ? round$2(change.value, 2) : change.value
236926
+ })));
236927
+ return;
236928
+ }
236929
+ changeSchemas(changes);
236874
236930
  } : void 0,
236875
236931
  stopEditing: () => setEditing(false),
236876
236932
  outline: `1px ${hoveringSchemaId === schema.id ? "solid" : "dashed"} ${schema.readOnly && hoveringSchemaId !== schema.id ? "transparent" : token.colorPrimary}`,
@@ -237294,6 +237350,22 @@ var CtlBar = (props) => {
237294
237350
  };
237295
237351
  //#endregion
237296
237352
  //#region src/components/Designer/index.tsx
237353
+ var MAX_HISTORY_LENGTH = 100;
237354
+ /** Release scroll suppression if a pending page scroll never finishes. */
237355
+ var SCROLL_SUPPRESS_FALLBACK_MS = 1e3;
237356
+ var pushHistory = (stack, entry) => {
237357
+ stack.push({
237358
+ schemasList: cloneDeep$1(entry.schemasList),
237359
+ pageCursor: entry.pageCursor,
237360
+ appliedCursor: entry.appliedCursor
237361
+ });
237362
+ if (stack.length > MAX_HISTORY_LENGTH) stack.splice(0, stack.length - MAX_HISTORY_LENGTH);
237363
+ };
237364
+ var clampPageCursor = (pageCursor, pageCount) => {
237365
+ if (pageCount <= 0) return 0;
237366
+ return Math.min(Math.max(Number.isFinite(pageCursor) ? Math.trunc(pageCursor) : 0, 0), pageCount - 1);
237367
+ };
237368
+ var schemasEqual = (left, right) => JSON.stringify(left) === JSON.stringify(right);
237297
237369
  /**
237298
237370
  * When the canvas scales there is a displacement of the starting position of the dragged schema.
237299
237371
  * It moves left or right from the top-left corner of the drag icon depending on the scale.
@@ -237308,6 +237380,12 @@ var MIN_CANVAS_WIDTH = 100;
237308
237380
  var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPageCursorChange, onChangeSelection, onRegisterSchemaSelectionHandler, onUpdateTemplatePageApplied, updateTemplatePage }) => {
237309
237381
  const past = (0, import_react$9.useRef)([]);
237310
237382
  const future = (0, import_react$9.useRef)([]);
237383
+ const schemasListRef = (0, import_react$9.useRef)([[]]);
237384
+ const pageCursorRef = (0, import_react$9.useRef)(0);
237385
+ const pendingSelectionIdsRef = (0, import_react$9.useRef)(null);
237386
+ const suppressScrollPageCursorRef = (0, import_react$9.useRef)(false);
237387
+ const scrollSuppressTokenRef = (0, import_react$9.useRef)(0);
237388
+ const scrollSuppressTimerRef = (0, import_react$9.useRef)(null);
237311
237389
  const canvasRef = (0, import_react$9.useRef)(null);
237312
237390
  const paperRefs = (0, import_react$9.useRef)([]);
237313
237391
  const i18n = (0, import_react$9.useContext)(I18nContext);
@@ -237317,8 +237395,12 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237317
237395
  const canvasWidth = size.width - 45;
237318
237396
  const [hoveringSchemaId, setHoveringSchemaId] = (0, import_react$9.useState)(null);
237319
237397
  const [activeElements, setActiveElements] = (0, import_react$9.useState)([]);
237398
+ const activeElementsRef = (0, import_react$9.useRef)(activeElements);
237399
+ activeElementsRef.current = activeElements;
237320
237400
  const [schemasList, setSchemasList] = (0, import_react$9.useState)([[]]);
237321
237401
  const [pageCursor, setPageCursor] = (0, import_react$9.useState)(0);
237402
+ schemasListRef.current = schemasList;
237403
+ pageCursorRef.current = pageCursor;
237322
237404
  const [pendingScrollPage, setPendingScrollPage] = (0, import_react$9.useState)(null);
237323
237405
  const [sidebarOpen, setSidebarOpen] = (0, import_react$9.useState)(options.sidebarOpen ?? canvasWidth - 400 >= MIN_CANVAS_WIDTH);
237324
237406
  const [canvasHeight, setCanvasHeight] = (0, import_react$9.useState)(0);
@@ -237406,6 +237488,22 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237406
237488
  setActiveElements([]);
237407
237489
  setHoveringSchemaId(null);
237408
237490
  };
237491
+ const onEditRef = (0, import_react$9.useRef)(onEdit);
237492
+ const onEditEndRef = (0, import_react$9.useRef)(onEditEnd);
237493
+ onEditRef.current = onEdit;
237494
+ onEditEndRef.current = onEditEnd;
237495
+ (0, import_react$9.useLayoutEffect)(() => {
237496
+ const ids = pendingSelectionIdsRef.current;
237497
+ if (!ids) return;
237498
+ if (pageSizes.length !== schemasList.length || backgrounds.length !== schemasList.length) return;
237499
+ pendingSelectionIdsRef.current = null;
237500
+ const elements = ids.map((id) => document.getElementById(id)).filter((element) => element instanceof HTMLElement);
237501
+ onEditRef.current(elements);
237502
+ }, [
237503
+ backgrounds,
237504
+ pageSizes,
237505
+ schemasList
237506
+ ]);
237409
237507
  (0, import_react$9.useEffect)(() => {
237410
237508
  if (previousOptionsZoomLevelRef.current === options.zoomLevel) return;
237411
237509
  previousOptionsZoomLevelRef.current = options.zoomLevel;
@@ -237414,6 +237512,31 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237414
237512
  (0, import_react$9.useEffect)(() => {
237415
237513
  if (typeof options.sidebarOpen === "boolean") setSidebarOpen(options.sidebarOpen);
237416
237514
  }, [options.sidebarOpen]);
237515
+ const armScrollSuppression = (fallbackMs) => {
237516
+ const token = ++scrollSuppressTokenRef.current;
237517
+ suppressScrollPageCursorRef.current = true;
237518
+ if (scrollSuppressTimerRef.current !== null) {
237519
+ window.clearTimeout(scrollSuppressTimerRef.current);
237520
+ scrollSuppressTimerRef.current = null;
237521
+ }
237522
+ if (fallbackMs !== void 0) {
237523
+ scrollSuppressTimerRef.current = window.setTimeout(() => {
237524
+ scrollSuppressTimerRef.current = null;
237525
+ if (scrollSuppressTokenRef.current !== token) return;
237526
+ suppressScrollPageCursorRef.current = false;
237527
+ }, fallbackMs);
237528
+ return;
237529
+ }
237530
+ requestAnimationFrame(() => {
237531
+ if (scrollSuppressTokenRef.current !== token) return;
237532
+ suppressScrollPageCursorRef.current = false;
237533
+ });
237534
+ };
237535
+ (0, import_react$9.useEffect)(() => {
237536
+ return () => {
237537
+ if (scrollSuppressTimerRef.current !== null) window.clearTimeout(scrollSuppressTimerRef.current);
237538
+ };
237539
+ }, []);
237417
237540
  useScrollPageCursor({
237418
237541
  ref: canvasRef,
237419
237542
  paperRefs,
@@ -237421,6 +237544,7 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237421
237544
  scale: displayScale,
237422
237545
  pageCursor,
237423
237546
  onChangePageCursor: (p) => {
237547
+ if (suppressScrollPageCursorRef.current) return;
237424
237548
  setPageCursor(p);
237425
237549
  onPageCursorChange(p, schemasList.length);
237426
237550
  onEditEnd();
@@ -237435,6 +237559,7 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237435
237559
  if (!pageSizes.every((pageSize) => pageSize.width === width && pageSize.height === height)) return;
237436
237560
  } else if (pageSizes === queuedPageSizes) return;
237437
237561
  setPendingScrollPage(null);
237562
+ armScrollSuppression();
237438
237563
  canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, pendingPage, displayScale);
237439
237564
  if (requestedPage !== void 0) onUpdateTemplatePageApplied?.(requestedPage);
237440
237565
  }, [
@@ -237457,44 +237582,122 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237457
237582
  return () => observer.disconnect();
237458
237583
  }
237459
237584
  }, [displayScale]);
237585
+ const applyDocument = (0, import_react$9.useCallback)((nextSchemasList, nextPageCursor, options) => {
237586
+ const basePdf = template.basePdf;
237587
+ const next = normalizeSchemasListForBasePdf(nextSchemasList, basePdf, pageSizes.length);
237588
+ const clampedCursor = clampPageCursor(nextPageCursor, next.length);
237589
+ const pageCountChanged = next.length !== schemasListRef.current.length;
237590
+ const cursorChanged = clampedCursor !== pageCursorRef.current;
237591
+ if (options.preserveSelection) {
237592
+ const landingPage = next[clampedCursor] ?? [];
237593
+ const previousIds = activeElementsRef.current.map((element) => element.id);
237594
+ const survivingIds = previousIds.filter((id) => landingPage.some((schema) => schema.id === id));
237595
+ if (survivingIds.length !== previousIds.length) onEditEndRef.current();
237596
+ pendingSelectionIdsRef.current = survivingIds.length > 0 ? survivingIds : null;
237597
+ }
237598
+ schemasListRef.current = next;
237599
+ pageCursorRef.current = clampedCursor;
237600
+ setSchemasList(next);
237601
+ setPageCursor(clampedCursor);
237602
+ const newTemplate = schemasList2template(next, basePdf);
237603
+ onChangeTemplate(newTemplate);
237604
+ if (options.notifyPageCursor === "always") onPageCursorChange(clampedCursor, next.length);
237605
+ if (pageCountChanged) refresh(newTemplate);
237606
+ if (cursorChanged) {
237607
+ if (pageCountChanged) {
237608
+ armScrollSuppression(SCROLL_SUPPRESS_FALLBACK_MS);
237609
+ setPendingScrollPage({
237610
+ page: clampedCursor,
237611
+ queuedPageSizes: pageSizes
237612
+ });
237613
+ } else if (canvasRef.current) {
237614
+ armScrollSuppression();
237615
+ canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, clampedCursor, displayScale);
237616
+ }
237617
+ }
237618
+ }, [
237619
+ displayScale,
237620
+ onChangeTemplate,
237621
+ onPageCursorChange,
237622
+ pageSizes,
237623
+ refresh,
237624
+ template.basePdf
237625
+ ]);
237460
237626
  const commitSchemas = (0, import_react$9.useCallback)((newSchemas) => {
237627
+ const currentSchemas = schemasListRef.current;
237628
+ const currentPage = pageCursorRef.current;
237629
+ if (schemasEqual(currentSchemas[currentPage], newSchemas)) return;
237461
237630
  future.current = [];
237462
- past.current.push(cloneDeep$1(schemasList[pageCursor]));
237463
- const _schemasList = cloneDeep$1(schemasList);
237464
- _schemasList[pageCursor] = newSchemas;
237465
- setSchemasList(_schemasList);
237466
- onChangeTemplate(schemasList2template(_schemasList, template.basePdf));
237631
+ pushHistory(past.current, {
237632
+ schemasList: currentSchemas,
237633
+ pageCursor: currentPage,
237634
+ appliedCursor: currentPage
237635
+ });
237636
+ const next = cloneDeep$1(currentSchemas);
237637
+ next[currentPage] = newSchemas;
237638
+ applyDocument(next, currentPage, { notifyPageCursor: "never" });
237639
+ }, [applyDocument]);
237640
+ const syncSchemas = (0, import_react$9.useCallback)((objs) => {
237641
+ const currentPage = pageCursorRef.current;
237642
+ const pageSize = pageSizes[currentPage];
237643
+ if (!pageSize || objs.length === 0) return;
237644
+ changeSchemas({
237645
+ objs,
237646
+ schemas: schemasListRef.current[currentPage] ?? [],
237647
+ basePdf: template.basePdf,
237648
+ pluginsRegistry,
237649
+ pageSize,
237650
+ commitSchemas: (newSchemas) => {
237651
+ const currentSchemas = schemasListRef.current;
237652
+ if (schemasEqual(currentSchemas[currentPage], newSchemas)) return;
237653
+ const next = cloneDeep$1(currentSchemas);
237654
+ next[currentPage] = newSchemas;
237655
+ applyDocument(next, currentPage, { notifyPageCursor: "never" });
237656
+ }
237657
+ });
237467
237658
  }, [
237468
- template,
237469
- schemasList,
237470
- pageCursor,
237471
- onChangeTemplate
237659
+ applyDocument,
237660
+ pageSizes,
237661
+ pluginsRegistry,
237662
+ template.basePdf
237472
237663
  ]);
237473
237664
  const removeSchemas = (0, import_react$9.useCallback)((ids) => {
237474
- commitSchemas(schemasList[pageCursor].filter((schema) => !ids.includes(schema.id)));
237475
- onEditEnd();
237476
- }, [
237477
- schemasList,
237478
- pageCursor,
237479
- commitSchemas
237480
- ]);
237665
+ const currentPage = pageCursorRef.current;
237666
+ const pageSchemas = schemasListRef.current[currentPage] ?? [];
237667
+ commitSchemas(pageSchemas.filter((schema) => !ids.includes(schema.id)));
237668
+ onEditEndRef.current();
237669
+ }, [commitSchemas]);
237481
237670
  const changeSchemas$1 = (0, import_react$9.useCallback)((objs) => {
237671
+ const currentPage = pageCursorRef.current;
237482
237672
  changeSchemas({
237483
237673
  objs,
237484
- schemas: schemasList[pageCursor],
237674
+ schemas: schemasListRef.current[currentPage] ?? [],
237485
237675
  basePdf: template.basePdf,
237486
237676
  pluginsRegistry,
237487
- pageSize: pageSizes[pageCursor],
237677
+ pageSize: pageSizes[currentPage],
237488
237678
  commitSchemas
237489
237679
  });
237490
237680
  }, [
237491
237681
  commitSchemas,
237492
- pageCursor,
237493
- schemasList,
237494
- pluginsRegistry,
237495
237682
  pageSizes,
237683
+ pluginsRegistry,
237496
237684
  template.basePdf
237497
237685
  ]);
237686
+ const timeTravel = (0, import_react$9.useCallback)((mode) => {
237687
+ const source = mode === "undo" ? past : future;
237688
+ const destination = mode === "undo" ? future : past;
237689
+ const target = source.current.pop();
237690
+ if (!target) return;
237691
+ pushHistory(destination.current, {
237692
+ schemasList: schemasListRef.current,
237693
+ pageCursor: target.appliedCursor,
237694
+ appliedCursor: target.pageCursor
237695
+ });
237696
+ applyDocument(target.schemasList, target.pageCursor, {
237697
+ notifyPageCursor: "always",
237698
+ preserveSelection: true
237699
+ });
237700
+ }, [applyDocument]);
237498
237701
  useInitEvents({
237499
237702
  pageCursor,
237500
237703
  pageSizes,
@@ -237505,18 +237708,20 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237505
237708
  commitSchemas,
237506
237709
  removeSchemas,
237507
237710
  onSaveTemplate,
237508
- past,
237509
- future,
237510
- setSchemasList,
237711
+ undo: (0, import_react$9.useCallback)(() => timeTravel("undo"), [timeTravel]),
237712
+ redo: (0, import_react$9.useCallback)(() => timeTravel("redo"), [timeTravel]),
237511
237713
  onEdit,
237512
237714
  onEditEnd
237513
237715
  });
237514
237716
  const updateTemplate = (0, import_react$9.useCallback)(async (newTemplate, targetPage) => {
237515
237717
  const sl = await template2SchemasList(newTemplate);
237718
+ schemasListRef.current = sl;
237516
237719
  setSchemasList(sl);
237517
- onEditEnd();
237720
+ pendingSelectionIdsRef.current = null;
237721
+ onEditEndRef.current();
237518
237722
  if (targetPage !== void 0) {
237519
237723
  const clampedPage = Math.min(Math.max(Number.isFinite(targetPage) ? Math.trunc(targetPage) : 0, 0), sl.length - 1);
237724
+ pageCursorRef.current = clampedPage;
237520
237725
  setPageCursor(clampedPage);
237521
237726
  onPageCursorChange(clampedPage, sl.length);
237522
237727
  setPendingScrollPage({
@@ -237525,9 +237730,11 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237525
237730
  requestedPage: targetPage
237526
237731
  });
237527
237732
  } else {
237528
- const clampedPage = Math.min(pageCursor, sl.length - 1);
237733
+ const clampedPage = Math.min(pageCursorRef.current, sl.length - 1);
237734
+ const cursorChanged = clampedPage !== pageCursorRef.current;
237735
+ pageCursorRef.current = clampedPage;
237529
237736
  setPageCursor(clampedPage);
237530
- if (clampedPage !== pageCursor) {
237737
+ if (cursorChanged) {
237531
237738
  onPageCursorChange(clampedPage, sl.length);
237532
237739
  setPendingScrollPage({
237533
237740
  page: clampedPage,
@@ -237535,11 +237742,7 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237535
237742
  });
237536
237743
  }
237537
237744
  }
237538
- }, [
237539
- pageCursor,
237540
- pageSizes,
237541
- onPageCursorChange
237542
- ]);
237745
+ }, [pageSizes, onPageCursorChange]);
237543
237746
  const addSchema = (defaultSchema) => {
237544
237747
  const [paddingTop, paddingRight, paddingBottom, paddingLeft] = isBlankPdf(template.basePdf) ? template.basePdf.padding : [
237545
237748
  0,
@@ -237582,27 +237785,37 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237582
237785
  const onChangeHoveringSchemaId = (id) => {
237583
237786
  setHoveringSchemaId(id);
237584
237787
  };
237585
- const updatePage = async (sl, newPageCursor) => {
237586
- setPageCursor(newPageCursor);
237587
- const newTemplate = schemasList2template(sl, template.basePdf);
237588
- onChangeTemplate(newTemplate);
237589
- await updateTemplate(newTemplate, newPageCursor);
237590
- refresh(newTemplate);
237591
- setTimeout(() => {
237592
- if (canvasRef.current) canvasRef.current.scrollTop = getPagesScrollTopByIndex(pageSizes, newPageCursor, displayScale);
237593
- }, 0);
237594
- };
237595
237788
  const handleRemovePage = () => {
237596
- if (pageCursor === 0) return;
237789
+ const currentPage = pageCursorRef.current;
237790
+ if (currentPage === 0) return;
237597
237791
  if (!window.confirm(i18n("removePageConfirm"))) return;
237598
- const _schemasList = cloneDeep$1(schemasList);
237599
- _schemasList.splice(pageCursor, 1);
237600
- updatePage(_schemasList, pageCursor - 1);
237792
+ future.current = [];
237793
+ const currentSchemas = schemasListRef.current;
237794
+ pushHistory(past.current, {
237795
+ schemasList: currentSchemas,
237796
+ pageCursor: currentPage,
237797
+ appliedCursor: currentPage - 1
237798
+ });
237799
+ const next = cloneDeep$1(currentSchemas);
237800
+ next.splice(currentPage, 1);
237801
+ onEditEndRef.current();
237802
+ pendingSelectionIdsRef.current = null;
237803
+ applyDocument(next, currentPage - 1, { notifyPageCursor: "always" });
237601
237804
  };
237602
237805
  const handleAddPageAfter = () => {
237603
- const _schemasList = cloneDeep$1(schemasList);
237604
- _schemasList.splice(pageCursor + 1, 0, []);
237605
- updatePage(_schemasList, pageCursor + 1);
237806
+ future.current = [];
237807
+ const currentSchemas = schemasListRef.current;
237808
+ const currentPage = pageCursorRef.current;
237809
+ pushHistory(past.current, {
237810
+ schemasList: currentSchemas,
237811
+ pageCursor: currentPage,
237812
+ appliedCursor: currentPage + 1
237813
+ });
237814
+ const next = cloneDeep$1(currentSchemas);
237815
+ next.splice(currentPage + 1, 0, []);
237816
+ onEditEndRef.current();
237817
+ pendingSelectionIdsRef.current = null;
237818
+ applyDocument(next, currentPage + 1, { notifyPageCursor: "always" });
237606
237819
  };
237607
237820
  if (prevTemplate !== template) {
237608
237821
  setPrevTemplate(template);
@@ -237680,6 +237893,7 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237680
237893
  schemasList,
237681
237894
  schemas: schemasList[pageCursor] ?? [],
237682
237895
  changeSchemas: changeSchemas$1,
237896
+ syncSchemas,
237683
237897
  onSortEnd,
237684
237898
  onEdit: (id) => {
237685
237899
  const editingElem = document.getElementById(id);
@@ -237706,6 +237920,7 @@ var TemplateEditor = ({ template, size, onSaveTemplate, onChangeTemplate, onPage
237706
237920
  activeElements,
237707
237921
  schemasList,
237708
237922
  changeSchemas: changeSchemas$1,
237923
+ syncSchemas,
237709
237924
  removeSchemas,
237710
237925
  sidebarOpen,
237711
237926
  onEdit