@unlev/exeq 0.5.2 → 0.5.3

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.mjs CHANGED
@@ -2087,7 +2087,7 @@ function DesignerView({
2087
2087
  }
2088
2088
 
2089
2089
  // src/components/pdf-builder/SignerView.tsx
2090
- import { useState as useState7, useCallback as useCallback5, useEffect as useEffect3, useRef as useRef5 } from "react";
2090
+ import { useState as useState7, useCallback as useCallback5, useEffect as useEffect3, useRef as useRef5, useLayoutEffect } from "react";
2091
2091
 
2092
2092
  // src/utils/pdfFiller.ts
2093
2093
  import {
@@ -2226,17 +2226,6 @@ function fitFontSize(o) {
2226
2226
  }
2227
2227
  return size;
2228
2228
  }
2229
- var measureCtx = null;
2230
- function measureTextWidth(text, size, opts) {
2231
- if (typeof document === "undefined") return text.length * size * 0.5;
2232
- if (!measureCtx) measureCtx = document.createElement("canvas").getContext("2d");
2233
- if (!measureCtx) return text.length * size * 0.5;
2234
- const family = getCssFontFamily(opts?.fontFamily) || "Helvetica, Arial, sans-serif";
2235
- measureCtx.font = `${opts?.italic ? "italic " : ""}${opts?.bold ? "bold " : ""}${size}px ${family}`;
2236
- const base = measureCtx.measureText(text).width;
2237
- const spacing = opts?.letterSpacing ? opts.letterSpacing * Math.max(0, text.length - 1) : 0;
2238
- return base + spacing;
2239
- }
2240
2229
 
2241
2230
  // src/utils/pdfFiller.ts
2242
2231
  var FONT_VARIANTS = {
@@ -2590,6 +2579,41 @@ function FieldNavigator({
2590
2579
 
2591
2580
  // src/components/pdf-builder/SignerView.tsx
2592
2581
  import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
2582
+ var useIsoLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect3;
2583
+ function shrinkToFit(el, maxPt, selfBox) {
2584
+ if (!el) return;
2585
+ const box = selfBox ? el : el.parentElement;
2586
+ if (!box) return;
2587
+ let pt = Math.max(1, maxPt);
2588
+ el.style.fontSize = `${pt}pt`;
2589
+ let guard = 0;
2590
+ while (pt > 2 && guard++ < 400 && (el.scrollWidth > box.clientWidth + 0.5 || el.scrollHeight > box.clientHeight + 0.5)) {
2591
+ pt -= 0.5;
2592
+ el.style.fontSize = `${pt}pt`;
2593
+ }
2594
+ }
2595
+ function FitInput({
2596
+ maxPt,
2597
+ ...rest
2598
+ }) {
2599
+ const ref = useRef5(null);
2600
+ useIsoLayoutEffect(() => {
2601
+ shrinkToFit(ref.current, maxPt, true);
2602
+ });
2603
+ return /* @__PURE__ */ jsx6("input", { ref, ...rest });
2604
+ }
2605
+ function FitText({
2606
+ maxPt,
2607
+ className,
2608
+ style,
2609
+ children
2610
+ }) {
2611
+ const ref = useRef5(null);
2612
+ useIsoLayoutEffect(() => {
2613
+ shrinkToFit(ref.current, maxPt, false);
2614
+ });
2615
+ return /* @__PURE__ */ jsx6("div", { ref, className, style, children });
2616
+ }
2593
2617
  function SignerView({
2594
2618
  apiKey,
2595
2619
  initialPdfUrl,
@@ -2841,12 +2865,12 @@ ${row.join(",")}`, "csv");
2841
2865
  setSubmitting(false);
2842
2866
  }
2843
2867
  }, [pdfSource, fields, callbackUrl, allRequiredFilled, onComplete, isLastSigner, signer, onSignerComplete, includeAuditTrail, exportFormat, onExport, getValues, transforms]);
2844
- const renderFieldContent = useCallback5((field, pageWidthPt, pageHeightPt) => {
2868
+ const renderFieldContent = useCallback5((field) => {
2845
2869
  if (isRedactField(field)) {
2846
2870
  return null;
2847
2871
  }
2848
2872
  if (field.formula) {
2849
- return /* @__PURE__ */ jsx6("div", { className: "field-overlay-value formula", children: field.value || "..." });
2873
+ return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, className: "field-overlay-value formula", style: getCssTextStyle(field), children: field.value || "..." });
2850
2874
  }
2851
2875
  const editable = field.assignee === signer;
2852
2876
  if (!editable) {
@@ -2856,7 +2880,7 @@ ${row.join(",")}`, "csv");
2856
2880
  if (field.type === "checkbox") {
2857
2881
  return /* @__PURE__ */ jsx6("div", { className: "field-checkbox-display readonly", children: field.value === "true" ? "\u2713" : "" });
2858
2882
  }
2859
- return /* @__PURE__ */ jsx6("div", { className: "field-overlay-placeholder readonly", children: field.value || field.placeholder });
2883
+ return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, className: "field-overlay-placeholder readonly", style: getCssTextStyle(field), children: field.value || field.placeholder });
2860
2884
  }
2861
2885
  if (isSignatureField(field)) {
2862
2886
  if (field.value) {
@@ -2878,25 +2902,9 @@ ${row.join(",")}`, "csv");
2878
2902
  );
2879
2903
  }
2880
2904
  if (field.type === "signed-date") {
2881
- return /* @__PURE__ */ jsx6("div", { className: "field-overlay-value", children: field.value || (/* @__PURE__ */ new Date()).toLocaleDateString() });
2905
+ return /* @__PURE__ */ jsx6(FitText, { maxPt: field.fontSize, className: "field-overlay-value", style: getCssTextStyle(field), children: field.value || (/* @__PURE__ */ new Date()).toLocaleDateString() });
2882
2906
  }
2883
- const fieldWidthPt = pageWidthPt ? field.width / 100 * pageWidthPt : Infinity;
2884
- const fieldHeightPt = pageHeightPt ? field.height / 100 * pageHeightPt : 0;
2885
- const effectiveFontSize = pageWidthPt ? fitFontSize({
2886
- value: field.value || "",
2887
- fontSize: field.fontSize,
2888
- autoShrink: field.autoShrink,
2889
- fieldWidthPt,
2890
- fieldHeightPt,
2891
- measure: (t, s) => measureTextWidth(t, s, {
2892
- fontFamily: field.fontFamily,
2893
- bold: field.bold,
2894
- italic: field.italic,
2895
- letterSpacing: field.letterSpacing
2896
- })
2897
- }) : field.fontSize;
2898
2907
  const fontStyle = {
2899
- fontSize: `${effectiveFontSize}pt`,
2900
2908
  letterSpacing: field.letterSpacing ? `${field.letterSpacing}pt` : void 0,
2901
2909
  lineHeight: field.lineHeight ? `${field.lineHeight}` : void 0,
2902
2910
  ...getCssTextStyle(field)
@@ -2910,7 +2918,7 @@ ${row.join(",")}`, "csv");
2910
2918
  onChange: (e) => handleFieldUpdate(field.id, e.target.value),
2911
2919
  onFocus: () => setSelectedFieldId(field.id),
2912
2920
  onClick: (e) => e.stopPropagation(),
2913
- style: fontStyle,
2921
+ style: { fontSize: `${field.fontSize}pt`, ...fontStyle },
2914
2922
  children: [
2915
2923
  /* @__PURE__ */ jsx6("option", { value: "", children: field.placeholder || "Select..." }),
2916
2924
  (field.options || []).map((opt) => /* @__PURE__ */ jsx6("option", { value: opt, children: opt }, opt))
@@ -2919,8 +2927,9 @@ ${row.join(",")}`, "csv");
2919
2927
  );
2920
2928
  }
2921
2929
  return /* @__PURE__ */ jsx6(
2922
- "input",
2930
+ FitInput,
2923
2931
  {
2932
+ maxPt: field.fontSize,
2924
2933
  type: field.textSubtype === "email" ? "email" : field.textSubtype === "number" ? "number" : field.textSubtype === "phone" ? "tel" : field.textSubtype === "date" ? "date" : "text",
2925
2934
  className: "field-inline-input",
2926
2935
  value: field.value,