@vulcantech/forms 0.3.0 → 0.4.0

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
@@ -109,6 +109,18 @@ var DEFAULT_SPAM_PROTECTION = {
109
109
  honeypot: true,
110
110
  minSubmitTime: 3
111
111
  };
112
+ var FORM_STYLE_COLOR_KEYS = [
113
+ "formBackgroundColor",
114
+ "inputBgColor",
115
+ "inputBorderColor",
116
+ "inputFocusColor",
117
+ "inputTextColor",
118
+ "placeholderColor",
119
+ "labelColor",
120
+ "errorColor",
121
+ "buttonColor",
122
+ "buttonTextColor"
123
+ ];
112
124
  var DEFAULT_FORM_STYLE = {
113
125
  preset: "default",
114
126
  borderRadius: "md",
@@ -464,6 +476,105 @@ function getSafeRedirectUrl(raw) {
464
476
  return null;
465
477
  }
466
478
 
479
+ // src/utils/conversion.ts
480
+ var FORM_SUBMIT_SUCCESS_EVENT = "form_submit_success";
481
+ var FORM_CONVERSION_SEND_TO_GLOBAL = "__vtFormConversionSendTo";
482
+ var ENHANCED_CONVERSIONS_GLOBAL = "__vtEnhancedConversions";
483
+ function toE164(raw) {
484
+ if (typeof raw !== "string" && typeof raw !== "number") return void 0;
485
+ const digits = String(raw).replace(/\D/g, "");
486
+ if (digits.length === 10) return `+1${digits}`;
487
+ if (digits.length === 11 && digits[0] === "1") return `+${digits}`;
488
+ return void 0;
489
+ }
490
+ function buildUserData(input) {
491
+ if (!input) return void 0;
492
+ const email = typeof input.email === "string" ? input.email.trim().toLowerCase() : "";
493
+ const phone = toE164(input.phone);
494
+ if (!email && !phone) return void 0;
495
+ return __spreadValues(__spreadValues({}, email ? { email } : {}), phone ? { phone_number: phone } : {});
496
+ }
497
+ function newTransactionId() {
498
+ try {
499
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
500
+ return crypto.randomUUID();
501
+ }
502
+ } catch (e) {
503
+ }
504
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
505
+ }
506
+ function googleWindow() {
507
+ if (typeof window === "undefined") return void 0;
508
+ return window;
509
+ }
510
+ function pushFormSubmitSuccess(context) {
511
+ const win = googleWindow();
512
+ if (!win) return false;
513
+ try {
514
+ if (!Array.isArray(win.dataLayer)) {
515
+ if (win.dataLayer !== void 0) return false;
516
+ win.dataLayer = [];
517
+ }
518
+ win.dataLayer.push({
519
+ event: FORM_SUBMIT_SUCCESS_EVENT,
520
+ formId: context.formId,
521
+ formName: context.formName,
522
+ formType: context.formType
523
+ });
524
+ return true;
525
+ } catch (e) {
526
+ return false;
527
+ }
528
+ }
529
+ function fireAdsConversion(sendTo, extras = {}) {
530
+ if (typeof sendTo !== "string" || sendTo.trim() === "") return false;
531
+ const win = googleWindow();
532
+ if (!win || typeof win.gtag !== "function") return false;
533
+ try {
534
+ if (win[ENHANCED_CONVERSIONS_GLOBAL] === true) {
535
+ const userData = buildUserData(extras.userData);
536
+ if (userData) win.gtag("set", "user_data", userData);
537
+ }
538
+ win.gtag("event", "conversion", __spreadValues({
539
+ send_to: sendTo.trim()
540
+ }, extras.transactionId ? { transaction_id: extras.transactionId } : {}));
541
+ return true;
542
+ } catch (e) {
543
+ return false;
544
+ }
545
+ }
546
+ function fireGenerateLead(context) {
547
+ const win = googleWindow();
548
+ if (!win || typeof win.gtag !== "function") return false;
549
+ try {
550
+ win.gtag("event", "generate_lead", {
551
+ form_id: context.formId,
552
+ form_type: context.formType
553
+ });
554
+ return true;
555
+ } catch (e) {
556
+ return false;
557
+ }
558
+ }
559
+ function resolveConversionSendTo(formSendTo) {
560
+ var _a;
561
+ if (typeof formSendTo === "string" && formSendTo.trim() !== "") {
562
+ return formSendTo.trim();
563
+ }
564
+ const global = (_a = googleWindow()) == null ? void 0 : _a[FORM_CONVERSION_SEND_TO_GLOBAL];
565
+ if (typeof global === "string" && global.trim() !== "") return global.trim();
566
+ return void 0;
567
+ }
568
+ function trackFormConversion(context, formSendTo, extras = {}) {
569
+ const pushed = pushFormSubmitSuccess(context);
570
+ const conversionFired = fireAdsConversion(
571
+ resolveConversionSendTo(formSendTo),
572
+ extras
573
+ );
574
+ const leadFired = fireGenerateLead(context);
575
+ return { pushed, conversionFired, leadFired };
576
+ }
577
+
467
578
  // src/utils/textTransforms.ts
468
579
  function formatSsn(raw) {
469
580
  const digits = raw.replace(/\D/g, "").slice(0, 9);
@@ -722,14 +833,161 @@ function deriveLast4(plaintext) {
722
833
  const digits = plaintext.replace(/\D/g, "");
723
834
  return digits.slice(-4).padStart(4, "\u2022");
724
835
  }
725
- var FormStyleContext = react.createContext(DEFAULT_FORM_STYLE);
726
- var useFormStyle = () => react.useContext(FormStyleContext);
727
- var FormStyleProvider = FormStyleContext.Provider;
728
- var FormPreviewOverridesContext = react.createContext(
729
- null
730
- );
731
- var useFormPreviewOverrides = () => react.useContext(FormPreviewOverridesContext);
732
- var FormPreviewOverridesProvider = FormPreviewOverridesContext.Provider;
836
+
837
+ // src/tracking/adReferral.ts
838
+ var AD_REFERRAL_COOKIE = "vt_ad_ref";
839
+ var AD_REFERRAL_TTL_DAYS = 30;
840
+ var LANDING_PAGE_MAX = 200;
841
+ function cleanLandingPage(pathname) {
842
+ if (typeof pathname !== "string" || !pathname.startsWith("/")) return void 0;
843
+ return pathname.slice(0, LANDING_PAGE_MAX);
844
+ }
845
+ var CLICK_ID_PARAMS = ["gclid", "gbraid", "wbraid"];
846
+ function isClickIdType(value) {
847
+ return CLICK_ID_PARAMS.includes(value);
848
+ }
849
+ var GOOGLE_AD_PARAMS = ["gad_source", "gad_campaignid"];
850
+ var UTM_PARAMS = [
851
+ ["utm_source", "source"],
852
+ ["utm_medium", "medium"],
853
+ ["utm_campaign", "campaign"],
854
+ ["utm_term", "term"],
855
+ ["utm_content", "content"]
856
+ ];
857
+ function captureAdReferral(search, fallback, now = /* @__PURE__ */ new Date(), pathname) {
858
+ var _a, _b, _c, _d;
859
+ const landingPage = cleanLandingPage(pathname);
860
+ const params = new URLSearchParams(search);
861
+ const utm = {};
862
+ for (const [param, key] of UTM_PARAMS) {
863
+ const value = params.get(param);
864
+ if (value) utm[key] = value;
865
+ }
866
+ let clickId;
867
+ let clickIdType;
868
+ for (const param of CLICK_ID_PARAMS) {
869
+ const value = params.get(param);
870
+ if (value) {
871
+ clickId = value;
872
+ clickIdType = param;
873
+ break;
874
+ }
875
+ }
876
+ const adCampaignId = params.get("gad_campaignid") || void 0;
877
+ const googleAdClick = clickId !== void 0 || GOOGLE_AD_PARAMS.some((p) => params.get(p));
878
+ const hasSignal = Object.keys(utm).length > 0 || googleAdClick;
879
+ if (!hasSignal) {
880
+ if (!fallback) return null;
881
+ return __spreadProps(__spreadValues({
882
+ source: fallback.source,
883
+ medium: fallback.medium,
884
+ campaign: fallback.campaign
885
+ }, landingPage ? { landingPage } : {}), {
886
+ landedAt: now.toISOString()
887
+ });
888
+ }
889
+ return __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
890
+ // An auto-tagged click with no UTMs is a Google paid click. Inferring
891
+ // this is what makes `classifySource` bucket it as "paid" rather than
892
+ // leaving the lead unattributed.
893
+ //
894
+ // Tagging that sets only `utm_campaign` (or only term/content) leaves
895
+ // BOTH of these empty, and that is deliberate: the CMS's
896
+ // `deriveLeadSource` only classifies when one of them is non-empty and
897
+ // otherwise returns undefined, so such a lead reads as "unknown". Do not
898
+ // "fix" this by defaulting to "direct" — an honest unknown beats a
899
+ // fabricated bucket, and the campaign still rides along for inspection.
900
+ source: (_a = utm.source) != null ? _a : googleAdClick ? "google" : "",
901
+ medium: (_b = utm.medium) != null ? _b : googleAdClick ? "cpc" : "",
902
+ campaign: (_d = (_c = utm.campaign) != null ? _c : adCampaignId) != null ? _d : googleAdClick ? "(not set)" : ""
903
+ }, utm.term ? { term: utm.term } : {}), utm.content ? { content: utm.content } : {}), clickId ? { clickId, clickIdType } : {}), landingPage ? { landingPage } : {}), {
904
+ landedAt: now.toISOString()
905
+ });
906
+ }
907
+ function readAdReferral(cookieName = AD_REFERRAL_COOKIE) {
908
+ if (typeof document === "undefined") return null;
909
+ for (const cookie of document.cookie.split(";")) {
910
+ const separator = cookie.indexOf("=");
911
+ if (separator === -1) continue;
912
+ if (cookie.slice(0, separator).trim() !== cookieName) continue;
913
+ try {
914
+ const parsed = JSON.parse(
915
+ decodeURIComponent(cookie.slice(separator + 1))
916
+ );
917
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
918
+ return null;
919
+ }
920
+ const _a = parsed, { source, medium, campaign, landedAt, clickIdType } = _a, rest = __objRest(_a, ["source", "medium", "campaign", "landedAt", "clickIdType"]);
921
+ if (typeof source !== "string" || typeof medium !== "string") return null;
922
+ return __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, rest), {
923
+ source,
924
+ medium,
925
+ campaign: typeof campaign === "string" ? campaign : ""
926
+ }), isClickIdType(clickIdType) ? { clickIdType } : {}), {
927
+ landedAt: typeof landedAt === "string" ? landedAt : ""
928
+ });
929
+ } catch (e) {
930
+ return null;
931
+ }
932
+ }
933
+ return null;
934
+ }
935
+ function isSameAdReferralTouch(a, b) {
936
+ return [...Object.keys(a), ...Object.keys(b)].every(
937
+ (key) => key === "landedAt" || a[key] === b[key]
938
+ );
939
+ }
940
+ function writeAdReferral(referral, cookieName = AD_REFERRAL_COOKIE, ttlDays = AD_REFERRAL_TTL_DAYS) {
941
+ if (typeof document === "undefined") return;
942
+ const expires = /* @__PURE__ */ new Date();
943
+ expires.setDate(expires.getDate() + ttlDays);
944
+ const value = encodeURIComponent(JSON.stringify(referral));
945
+ document.cookie = `${cookieName}=${value}; expires=${expires.toUTCString()}; path=/; SameSite=Lax`;
946
+ }
947
+
948
+ // src/tracking/analyticsSession.ts
949
+ var ANALYTICS_SESSION_KEY = "__vt_sid";
950
+ function readAnalyticsSessionId() {
951
+ if (typeof window === "undefined") return void 0;
952
+ try {
953
+ const sid = window.sessionStorage.getItem(ANALYTICS_SESSION_KEY);
954
+ return sid && /^[a-z0-9]{6,64}$/i.test(sid) ? sid : void 0;
955
+ } catch (e) {
956
+ return void 0;
957
+ }
958
+ }
959
+
960
+ // src/utils/colorScheme.ts
961
+ function hasDarkColors(style) {
962
+ const dark = style == null ? void 0 : style.dark;
963
+ if (!dark) return false;
964
+ return FORM_STYLE_COLOR_KEYS.some((key) => Boolean(dark[key]));
965
+ }
966
+ function definitionHasDarkColors(definition) {
967
+ if (hasDarkColors(definition.style)) return true;
968
+ if (definition.defaultTextColorDark) return true;
969
+ return definition.sections.some((section) => Boolean(section.textColorDark));
970
+ }
971
+ function resolveSchemeColors(style, scheme) {
972
+ const dark = scheme === "dark" ? style.dark : void 0;
973
+ const out = {};
974
+ for (const key of FORM_STYLE_COLOR_KEYS) {
975
+ const value = (dark == null ? void 0 : dark[key]) || style[key];
976
+ if (value) out[key] = value;
977
+ }
978
+ return out;
979
+ }
980
+ function resolveSchemeStyle(style, scheme) {
981
+ const structural = __spreadValues({}, style);
982
+ delete structural.dark;
983
+ for (const key of FORM_STYLE_COLOR_KEYS) delete structural[key];
984
+ return __spreadValues(__spreadValues({}, structural), resolveSchemeColors(style, scheme));
985
+ }
986
+ function resolveSectionTextColor(section, formDefaults, scheme) {
987
+ const light = section.textColor || formDefaults.light || void 0;
988
+ if (scheme === "light") return light;
989
+ return section.textColorDark || formDefaults.dark || light;
990
+ }
733
991
 
734
992
  // src/renderer/cssVars.ts
735
993
  var FORM_CSS_VAR = {
@@ -744,6 +1002,31 @@ var FORM_CSS_VAR = {
744
1002
  buttonBg: "--form-button-bg",
745
1003
  buttonText: "--form-button-text"
746
1004
  };
1005
+ var FORM_STRUCT_VAR = {
1006
+ radius: "--form-radius",
1007
+ gap: "--form-gap",
1008
+ focusBorderWidth: "--form-focus-border-width"
1009
+ };
1010
+ var FORM_DEFAULT_RADIUS = "0.375rem";
1011
+ var FORM_RADIUS_VAR = `var(${FORM_STRUCT_VAR.radius}, ${FORM_DEFAULT_RADIUS})`;
1012
+ var FORM_GAP_VAR = `var(${FORM_STRUCT_VAR.gap}, 1rem)`;
1013
+ var FORM_DEFAULT_FOCUS_BORDER_WIDTH = "2px";
1014
+ var FORM_FOCUS_BORDER_WIDTH_VAR = `var(${FORM_STRUCT_VAR.focusBorderWidth}, ${FORM_DEFAULT_FOCUS_BORDER_WIDTH})`;
1015
+ function resolveCustomGap(style) {
1016
+ var _a;
1017
+ const raw = (_a = style.fieldGapValue) == null ? void 0 : _a.trim();
1018
+ return raw ? raw : null;
1019
+ }
1020
+ function resolveCustomRadius(style) {
1021
+ var _a;
1022
+ const raw = (_a = style.borderRadiusValue) == null ? void 0 : _a.trim();
1023
+ return raw ? raw : null;
1024
+ }
1025
+ function resolveCustomFocusBorderWidth(style) {
1026
+ var _a;
1027
+ const raw = (_a = style.inputFocusBorderWidth) == null ? void 0 : _a.trim();
1028
+ return raw ? raw : null;
1029
+ }
747
1030
  var FORM_DEFAULT_COLOR = {
748
1031
  formBg: "transparent",
749
1032
  inputBg: "inherit",
@@ -774,29 +1057,76 @@ var FORM_VAR = {
774
1057
  buttonBg: ref(FORM_CSS_VAR.buttonBg, FORM_DEFAULT_COLOR.buttonBg),
775
1058
  buttonText: ref(FORM_CSS_VAR.buttonText, FORM_DEFAULT_COLOR.buttonText)
776
1059
  };
1060
+ var COLOR_VAR_BY_KEY = {
1061
+ formBackgroundColor: FORM_CSS_VAR.formBg,
1062
+ inputBgColor: FORM_CSS_VAR.inputBg,
1063
+ inputBorderColor: FORM_CSS_VAR.inputBorder,
1064
+ inputFocusColor: FORM_CSS_VAR.inputFocusBorder,
1065
+ inputTextColor: FORM_CSS_VAR.inputText,
1066
+ placeholderColor: FORM_CSS_VAR.placeholder,
1067
+ labelColor: FORM_CSS_VAR.labelText,
1068
+ errorColor: FORM_CSS_VAR.error,
1069
+ buttonColor: FORM_CSS_VAR.buttonBg,
1070
+ buttonTextColor: FORM_CSS_VAR.buttonText
1071
+ };
1072
+ var FORM_DARK_SCOPE_ATTR = "data-vt-form-dark";
1073
+ var FORM_DARK_TEXT_ATTR = "data-vt-text-dark";
1074
+ var FORM_DARK_TEXT_VAR = "--form-text-dark";
1075
+ var FORM_DEFAULT_DARK_SELECTOR = ".dark";
1076
+ var FORM_ROOT_BG_VAR = `var(${FORM_CSS_VAR.formBg}, inherit)`;
1077
+ function darkVarName(name) {
1078
+ return `${name}-dark`;
1079
+ }
1080
+ function buildColorVars(style, scheme, keys = FORM_STYLE_COLOR_KEYS) {
1081
+ const colors = resolveSchemeColors(style, scheme);
1082
+ const out = {};
1083
+ for (const key of keys) {
1084
+ const value = colors[key];
1085
+ if (!value) continue;
1086
+ const name = COLOR_VAR_BY_KEY[key];
1087
+ out[scheme === "dark" ? darkVarName(name) : name] = value;
1088
+ }
1089
+ return out;
1090
+ }
777
1091
  function buildFormCssVars(style, previewBg) {
1092
+ var _a;
1093
+ const light = buildColorVars(style, "light");
778
1094
  const out = {};
779
- const effectiveFormBg = previewBg != null ? previewBg : style.formBackgroundColor;
780
- if (effectiveFormBg) out[FORM_CSS_VAR.formBg] = effectiveFormBg;
781
- const effectiveInputBg = previewBg != null ? previewBg : style.inputBgColor;
782
- if (effectiveInputBg) out[FORM_CSS_VAR.inputBg] = effectiveInputBg;
783
- if (style.inputBorderColor)
784
- out[FORM_CSS_VAR.inputBorder] = style.inputBorderColor;
785
- if (style.inputFocusColor)
786
- out[FORM_CSS_VAR.inputFocusBorder] = style.inputFocusColor;
787
- if (style.inputTextColor)
788
- out[FORM_CSS_VAR.inputText] = style.inputTextColor;
789
- if (style.placeholderColor)
790
- out[FORM_CSS_VAR.placeholder] = style.placeholderColor;
791
- if (style.labelColor) out[FORM_CSS_VAR.labelText] = style.labelColor;
792
- if (style.errorColor) out[FORM_CSS_VAR.error] = style.errorColor;
793
- if (style.buttonColor) out[FORM_CSS_VAR.buttonBg] = style.buttonColor;
794
- if (style.buttonTextColor)
795
- out[FORM_CSS_VAR.buttonText] = style.buttonTextColor;
1095
+ const formBg = (_a = light[FORM_CSS_VAR.formBg]) != null ? _a : previewBg;
1096
+ if (formBg) out[FORM_CSS_VAR.formBg] = formBg;
1097
+ for (const [name, value] of Object.entries(light)) {
1098
+ if (name !== FORM_CSS_VAR.formBg) out[name] = value;
1099
+ }
1100
+ const customRadius = resolveCustomRadius(style);
1101
+ if (customRadius) out[FORM_STRUCT_VAR.radius] = customRadius;
1102
+ const customGap = resolveCustomGap(style);
1103
+ if (customGap) out[FORM_STRUCT_VAR.gap] = customGap;
1104
+ const customFocusBorderWidth = resolveCustomFocusBorderWidth(style);
1105
+ if (customFocusBorderWidth)
1106
+ out[FORM_STRUCT_VAR.focusBorderWidth] = customFocusBorderWidth;
796
1107
  return out;
797
1108
  }
798
-
799
- // src/renderer/fields/useInputStyles.ts
1109
+ function buildFormDarkCssVars(style, keys) {
1110
+ return buildColorVars(style, "dark", keys);
1111
+ }
1112
+ function buildDarkSchemeCss(darkSelector = FORM_DEFAULT_DARK_SELECTOR) {
1113
+ const swaps = Object.values(FORM_CSS_VAR).map((name) => `${name}:var(${darkVarName(name)})!important`).join(";");
1114
+ const scope = `${darkSelector} [${FORM_DARK_SCOPE_ATTR}]`;
1115
+ return `${scope}{${swaps}}${scope} [${FORM_DARK_TEXT_ATTR}]{color:var(${FORM_DARK_TEXT_VAR})!important}`;
1116
+ }
1117
+ var FORM_MUTED_TEXT_CLASS = "text-current/65";
1118
+ var FORM_FAINT_TEXT_CLASS = "text-current/45";
1119
+ var FORM_SUBTLE_BORDER_CLASS = "border-current/20";
1120
+ var FORM_SUBTLE_FILL_CLASS = "bg-current/10";
1121
+ var FORM_SUBTLE_HOVER_FILL_CLASS = "hover:bg-current/10";
1122
+ var FormStyleContext = react.createContext(DEFAULT_FORM_STYLE);
1123
+ var useFormStyle = () => react.useContext(FormStyleContext);
1124
+ var FormStyleProvider = FormStyleContext.Provider;
1125
+ var FormColorSchemeContext = react.createContext({
1126
+ darkEnabled: false
1127
+ });
1128
+ var useFormColorScheme = () => react.useContext(FormColorSchemeContext);
1129
+ var FormColorSchemeProvider = FormColorSchemeContext.Provider;
800
1130
  var placeholderClass = "placeholder:[color:var(--form-placeholder,#9ca3af)]";
801
1131
  var textClass = "text-[color:var(--form-input-text,inherit)]";
802
1132
  function getVariantClasses(style) {
@@ -833,7 +1163,7 @@ function getVariantClasses(style) {
833
1163
  case "underlined":
834
1164
  return {
835
1165
  inputClass: tailwindMerge.twMerge(
836
- "rounded-none bg-transparent px-1 py-1.5 text-base transition ease-in-out placeholder:opacity-0 focus:outline-none focus:placeholder:opacity-100 disabled:cursor-not-allowed",
1166
+ "rounded-none bg-inherit px-1 py-1.5 text-base transition ease-in-out placeholder:opacity-0 focus:outline-none focus:placeholder:opacity-100 disabled:cursor-not-allowed",
837
1167
  textClass,
838
1168
  placeholderClass
839
1169
  ),
@@ -849,7 +1179,7 @@ function getVariantClasses(style) {
849
1179
  default:
850
1180
  return {
851
1181
  inputClass: tailwindMerge.twMerge(
852
- "rounded px-3 py-1.5 text-base transition ease-in-out placeholder:opacity-0 focus:outline-none focus:placeholder:opacity-100 disabled:cursor-not-allowed bg-transparent",
1182
+ "rounded px-3 py-1.5 text-base transition ease-in-out placeholder:opacity-0 focus:outline-none focus:placeholder:opacity-100 disabled:cursor-not-allowed bg-inherit",
853
1183
  textClass,
854
1184
  placeholderClass
855
1185
  ),
@@ -858,19 +1188,23 @@ function getVariantClasses(style) {
858
1188
  borderWidth: 1,
859
1189
  borderColor: FORM_VAR.inputBorder
860
1190
  },
861
- // Label must paint a solid bg on top of the input border. `bg-inherit`
862
- // doesn't work — wrapper divs between the form root and the label
863
- // have transparent bgs, so `inherit` resolves to transparent. Read
864
- // from `--form-input-bg`, which DynamicForm publishes on the form
865
- // root from the resolved input background (or the editor preview
866
- // override). The fallback matches FORM_DEFAULT_COLOR.inputBg.
1191
+ // Label must paint a solid bg on top of the input border. It reads
1192
+ // `--form-input-bg`, which DynamicForm publishes on the form root
1193
+ // from the resolved input background (or the editor preview
1194
+ // override). The fallback is `inherit`, and it now resolves to a
1195
+ // real color: every element from the form root down to this span
1196
+ // carries `bg-inherit`, so an unstyled form picks up whatever
1197
+ // background the consumer's container paints. See the chain note in
1198
+ // DynamicForm.
867
1199
  labelClass: "absolute left-2 top-2 z-10 flex min-h-[1ch] w-min -translate-y-[18px] cursor-text flex-col justify-around whitespace-nowrap rounded-md bg-[var(--form-input-bg,inherit)] px-1 text-sm transition-transform group-focus-within:-translate-y-[18px] peer-placeholder-shown:translate-y-0 peer-focus:-translate-y-[18px]"
868
1200
  };
869
1201
  }
870
1202
  }
871
1203
  function getFocusStyle(style) {
872
1204
  if (style.inputVariant === "filled" || style.inputVariant === "underlined") {
873
- return { borderBottomColor: FORM_VAR.inputFocusBorder };
1205
+ return __spreadValues({
1206
+ borderBottomColor: FORM_VAR.inputFocusBorder
1207
+ }, resolveCustomFocusBorderWidth(style) ? { borderBottomWidth: FORM_FOCUS_BORDER_WIDTH_VAR } : {});
874
1208
  }
875
1209
  if (style.inputVariant === "stacked") {
876
1210
  return {
@@ -884,13 +1218,19 @@ function useInputStyles() {
884
1218
  const style = useFormStyle();
885
1219
  const variant = getVariantClasses(style);
886
1220
  const isStacked = style.inputVariant === "stacked";
1221
+ const customRadius = resolveCustomRadius(style);
1222
+ const radiusStyle = customRadius ? { borderRadius: FORM_RADIUS_VAR } : {};
1223
+ const radiusClass = customRadius ? "rounded-none" : "";
887
1224
  return {
888
- wrapperClass: isStacked ? "flex w-full flex-col" : "group relative flex w-full flex-col pt-3",
889
- inputClass: isStacked ? tailwindMerge.twMerge("block w-full", variant.inputClass) : tailwindMerge.twMerge(
1225
+ // `bg-inherit` keeps the form root's background flowing down to the
1226
+ // inputs and floating labels, which resolve theirs with `inherit`.
1227
+ wrapperClass: isStacked ? "flex w-full flex-col bg-inherit" : "group relative flex w-full flex-col pt-3 bg-inherit",
1228
+ inputClass: isStacked ? tailwindMerge.twMerge("block w-full", variant.inputClass, radiusClass) : tailwindMerge.twMerge(
890
1229
  "peer m-0 mb-3 block min-h-8 w-full overflow-hidden",
891
- variant.inputClass
1230
+ variant.inputClass,
1231
+ radiusClass
892
1232
  ),
893
- inputStyle: variant.inputStyle,
1233
+ inputStyle: __spreadValues(__spreadValues({}, variant.inputStyle), radiusStyle),
894
1234
  inputFocusStyle: getFocusStyle(style),
895
1235
  labelClass: variant.labelClass,
896
1236
  labelStyle: { color: FORM_VAR.labelText },
@@ -899,8 +1239,9 @@ function useInputStyles() {
899
1239
  isStacked
900
1240
  };
901
1241
  }
902
- function getErrorOutlineStyle(hasError, variant) {
1242
+ function getErrorOutlineStyle(hasError, style) {
903
1243
  if (!hasError) return {};
1244
+ const variant = style.inputVariant;
904
1245
  if (variant === "stacked") {
905
1246
  return {
906
1247
  outline: `2px solid ${FORM_VAR.error}`,
@@ -914,9 +1255,9 @@ function getErrorOutlineStyle(hasError, variant) {
914
1255
  borderColor: FORM_VAR.error
915
1256
  };
916
1257
  }
917
- return {
1258
+ return __spreadValues({
918
1259
  borderBottomColor: FORM_VAR.error
919
- };
1260
+ }, resolveCustomFocusBorderWidth(style) ? { borderBottomWidth: FORM_FOCUS_BORDER_WIDTH_VAR } : {});
920
1261
  }
921
1262
  var StyledInput = ({
922
1263
  id,
@@ -934,7 +1275,7 @@ var StyledInput = ({
934
1275
  const style = useFormStyle();
935
1276
  const styles = useInputStyles();
936
1277
  const hasError = !!(error && touched);
937
- const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, style.inputVariant));
1278
+ const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, style));
938
1279
  if (styles.isStacked) {
939
1280
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
940
1281
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: styles.labelClass, style: styles.labelStyle, children: label }),
@@ -960,7 +1301,7 @@ var StyledInput = ({
960
1301
  hasError && /* @__PURE__ */ jsxRuntime.jsx(
961
1302
  "span",
962
1303
  {
963
- className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
1304
+ className: "mt-1 text-xs",
964
1305
  style: styles.errorStyle,
965
1306
  children: error
966
1307
  }
@@ -968,7 +1309,7 @@ var StyledInput = ({
968
1309
  ] });
969
1310
  }
970
1311
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
971
- /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: id, className: "relative inline-block", children: [
1312
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: id, className: "relative inline-block bg-inherit", children: [
972
1313
  /* @__PURE__ */ jsxRuntime.jsx(
973
1314
  "input",
974
1315
  {
@@ -990,7 +1331,7 @@ var StyledInput = ({
990
1331
  ),
991
1332
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: label })
992
1333
  ] }),
993
- hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: error })
1334
+ hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "relative mt-[-8px] text-xs", style: styles.errorStyle, children: error })
994
1335
  ] });
995
1336
  };
996
1337
  var TextField = ({ field: fieldDef, disabled }) => {
@@ -1039,7 +1380,7 @@ var PhoneField = ({ field: fieldDef, disabled }) => {
1039
1380
  const formStyle = useFormStyle();
1040
1381
  const styles = useInputStyles();
1041
1382
  const hasError = !!(meta.error && meta.touched);
1042
- const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
1383
+ const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
1043
1384
  const handleChange = (e) => {
1044
1385
  helpers.setValue(formatUsPhone(e.target.value));
1045
1386
  };
@@ -1076,7 +1417,7 @@ var PhoneField = ({ field: fieldDef, disabled }) => {
1076
1417
  hasError && /* @__PURE__ */ jsxRuntime.jsx(
1077
1418
  "span",
1078
1419
  {
1079
- className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
1420
+ className: "mt-1 text-xs",
1080
1421
  style: styles.errorStyle,
1081
1422
  children: meta.error
1082
1423
  }
@@ -1105,7 +1446,7 @@ var PhoneField = ({ field: fieldDef, disabled }) => {
1105
1446
  ),
1106
1447
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
1107
1448
  ] }),
1108
- hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
1449
+ hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "relative mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
1109
1450
  ] });
1110
1451
  };
1111
1452
  var UrlField = ({ field: fieldDef, disabled }) => {
@@ -1137,7 +1478,7 @@ var AddressField = ({ field: fieldDef, disabled }) => {
1137
1478
  const formStyle = useFormStyle();
1138
1479
  const styles = useInputStyles();
1139
1480
  const hasError = !!(meta.error && meta.touched);
1140
- const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
1481
+ const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
1141
1482
  const placeholder = fieldDef.placeholder || "123 Main St, City, State 12345";
1142
1483
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `${styles.wrapperClass} pb-5 lg:pb-0`, children: [
1143
1484
  /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block bg-inherit", children: [
@@ -1178,7 +1519,7 @@ var TextAreaField = ({ field: fieldDef, disabled }) => {
1178
1519
  const styles = useInputStyles();
1179
1520
  const hasError = !!(meta.error && meta.touched);
1180
1521
  const value = (_a = field.value) != null ? _a : "";
1181
- const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
1522
+ const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
1182
1523
  if (styles.isStacked) {
1183
1524
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: tailwindMerge.twMerge(styles.wrapperClass, "relative"), children: [
1184
1525
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1209,11 +1550,20 @@ var TextAreaField = ({ field: fieldDef, disabled }) => {
1209
1550
  }
1210
1551
  }
1211
1552
  ),
1212
- fieldDef.characterCounter && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-1 text-right text-xs text-gray-500 dark:text-zinc-400", children: value.length }),
1553
+ fieldDef.characterCounter && /* @__PURE__ */ jsxRuntime.jsx(
1554
+ "span",
1555
+ {
1556
+ className: tailwindMerge.twMerge(
1557
+ "mt-1 text-right text-xs",
1558
+ FORM_MUTED_TEXT_CLASS
1559
+ ),
1560
+ children: value.length
1561
+ }
1562
+ ),
1213
1563
  hasError && /* @__PURE__ */ jsxRuntime.jsx(
1214
1564
  "span",
1215
1565
  {
1216
- className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
1566
+ className: "mt-1 text-xs",
1217
1567
  style: styles.errorStyle,
1218
1568
  children: meta.error
1219
1569
  }
@@ -1221,7 +1571,7 @@ var TextAreaField = ({ field: fieldDef, disabled }) => {
1221
1571
  ] });
1222
1572
  }
1223
1573
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: tailwindMerge.twMerge(styles.wrapperClass, "pb-5 lg:pb-0"), children: [
1224
- /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block", children: [
1574
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { htmlFor: fieldDef.id, className: "relative inline-block bg-inherit", children: [
1225
1575
  /* @__PURE__ */ jsxRuntime.jsx(
1226
1576
  "textarea",
1227
1577
  {
@@ -1247,20 +1597,29 @@ var TextAreaField = ({ field: fieldDef, disabled }) => {
1247
1597
  hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs", style: styles.errorStyle, children: meta.error })
1248
1598
  ] });
1249
1599
  };
1600
+ var POPOVER_COLOR_KEYS = [
1601
+ "inputBgColor",
1602
+ "inputBorderColor",
1603
+ "inputTextColor",
1604
+ "inputFocusColor"
1605
+ ];
1250
1606
  var SelectField = ({ field: fieldDef, disabled }) => {
1251
1607
  var _a;
1252
1608
  const [field, meta, helpers] = formik.useField(fieldDef.id);
1253
1609
  const [focused, setFocused] = react.useState(false);
1254
1610
  const formStyle = useFormStyle();
1611
+ const { darkEnabled } = useFormColorScheme();
1255
1612
  const styles = useInputStyles();
1256
1613
  const hasError = !!(meta.error && meta.touched);
1614
+ const popoverVars = __spreadValues(__spreadValues({}, buildColorVars(formStyle, "light", POPOVER_COLOR_KEYS)), darkEnabled ? buildColorVars(formStyle, "dark", POPOVER_COLOR_KEYS) : {});
1615
+ const popoverScopeAttr = darkEnabled ? { [FORM_DARK_SCOPE_ATTR]: "" } : {};
1257
1616
  const [currentValue, setCurrentValue] = react.useState(field.value || "");
1258
1617
  react.useEffect(() => {
1259
1618
  setCurrentValue(field.value || "");
1260
1619
  }, [field.value]);
1261
1620
  const options = (fieldDef.options || []).filter((opt) => opt.value !== "");
1262
1621
  const displayName = ((_a = options.find((opt) => opt.value === currentValue)) == null ? void 0 : _a.label) || "";
1263
- const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
1622
+ const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
1264
1623
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
1265
1624
  /* @__PURE__ */ jsxRuntime.jsxs(
1266
1625
  radixUi.Select.Root,
@@ -1272,43 +1631,43 @@ var SelectField = ({ field: fieldDef, disabled }) => {
1272
1631
  },
1273
1632
  value: currentValue,
1274
1633
  children: [
1275
- /* @__PURE__ */ jsxRuntime.jsx(
1634
+ /* @__PURE__ */ jsxRuntime.jsxs(
1276
1635
  "label",
1277
1636
  {
1278
1637
  htmlFor: fieldDef.id,
1279
1638
  className: "relative block bg-inherit",
1280
- children: /* @__PURE__ */ jsxRuntime.jsxs(
1281
- radixUi.Select.Trigger,
1282
- {
1283
- className: `${styles.inputClass} cursor-pointer text-left`,
1284
- style: borderStyle,
1285
- "aria-label": fieldDef.label,
1286
- onFocus: () => setFocused(true),
1287
- onBlur: () => {
1288
- setFocused(false);
1289
- helpers.setTouched(true);
1290
- },
1291
- children: [
1292
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Value, { placeholder: "Choose an option", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block truncate", children: displayName }) }),
1293
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Icon, { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsChevronDown, { style: { color: FORM_VAR.placeholder } }) }),
1294
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
1295
- ]
1296
- }
1297
- )
1639
+ children: [
1640
+ /* @__PURE__ */ jsxRuntime.jsxs(
1641
+ radixUi.Select.Trigger,
1642
+ {
1643
+ className: `${styles.inputClass} relative cursor-pointer text-left`,
1644
+ style: borderStyle,
1645
+ "aria-label": fieldDef.label,
1646
+ onFocus: () => setFocused(true),
1647
+ onBlur: () => {
1648
+ setFocused(false);
1649
+ helpers.setTouched(true);
1650
+ },
1651
+ children: [
1652
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Value, { placeholder: "Choose an option", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "block truncate", children: displayName }) }),
1653
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Icon, { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsChevronDown, { style: { color: FORM_VAR.placeholder } }) })
1654
+ ]
1655
+ }
1656
+ ),
1657
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label })
1658
+ ]
1298
1659
  }
1299
1660
  ),
1300
1661
  /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Portal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
1301
1662
  radixUi.Select.Content,
1302
- {
1663
+ __spreadProps(__spreadValues({
1303
1664
  className: "z-20 rounded-md border p-3 shadow-lg",
1304
- style: {
1305
- // Portal renders outside the form DOM tree, so CSS variables
1306
- // from the form wrapper don't cascade. Use resolved style
1307
- // values from the form context instead.
1308
- backgroundColor: formStyle.inputBgColor || "#ffffff",
1309
- borderColor: formStyle.inputBorderColor || "#e5e7eb",
1310
- color: formStyle.inputTextColor || "#1f2937"
1311
- },
1665
+ style: __spreadProps(__spreadValues({}, popoverVars), {
1666
+ backgroundColor: `var(${FORM_CSS_VAR.inputBg}, #ffffff)`,
1667
+ borderColor: `var(${FORM_CSS_VAR.inputBorder}, #e5e7eb)`,
1668
+ color: `var(${FORM_CSS_VAR.inputText}, #1f2937)`
1669
+ })
1670
+ }, popoverScopeAttr), {
1312
1671
  children: [
1313
1672
  /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.ScrollUpButton, { children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsChevronDown, { className: "rotate-180" }) }),
1314
1673
  /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Viewport, { children: /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.Group, { children: options.map((opt) => /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1316,7 +1675,7 @@ var SelectField = ({ field: fieldDef, disabled }) => {
1316
1675
  {
1317
1676
  className: "relative m-1 flex cursor-pointer select-none justify-between rounded p-1 pr-8 hover:ring-1 focus:ring-1",
1318
1677
  style: {
1319
- "--tw-ring-color": formStyle.inputFocusColor || "#2563eb"
1678
+ "--tw-ring-color": `var(${FORM_CSS_VAR.inputFocusBorder}, #2563eb)`
1320
1679
  },
1321
1680
  value: opt.value,
1322
1681
  children: [
@@ -1328,7 +1687,7 @@ var SelectField = ({ field: fieldDef, disabled }) => {
1328
1687
  )) }) }),
1329
1688
  /* @__PURE__ */ jsxRuntime.jsx(radixUi.Select.ScrollDownButton, { children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsChevronDown, {}) })
1330
1689
  ]
1331
- }
1690
+ })
1332
1691
  ) })
1333
1692
  ]
1334
1693
  }
@@ -1341,11 +1700,19 @@ var CheckboxField = ({ field: fieldDef }) => {
1341
1700
  const formStyle = useFormStyle();
1342
1701
  const isChecked = field.value === true;
1343
1702
  const isStacked = formStyle.inputVariant === "stacked";
1344
- const checkboxStyle = isChecked ? { borderColor: FORM_VAR.inputFocusBorder, backgroundColor: FORM_VAR.inputFocusBorder } : { borderColor: FORM_VAR.inputBorder, backgroundColor: FORM_VAR.inputBg };
1703
+ const radiusStyle = resolveCustomRadius(formStyle) ? { borderRadius: FORM_RADIUS_VAR } : {};
1704
+ const checkboxStyle = isChecked ? __spreadProps(__spreadValues({}, radiusStyle), {
1705
+ borderColor: FORM_VAR.inputFocusBorder,
1706
+ backgroundColor: FORM_VAR.inputFocusBorder
1707
+ }) : __spreadProps(__spreadValues({}, radiusStyle), {
1708
+ borderColor: FORM_VAR.inputBorder,
1709
+ backgroundColor: FORM_VAR.inputBg
1710
+ });
1345
1711
  return /* @__PURE__ */ jsxRuntime.jsxs(
1346
1712
  "div",
1347
1713
  {
1348
1714
  className: tailwindMerge.twMerge(
1715
+ "bg-inherit",
1349
1716
  isStacked ? "flex items-start gap-3" : "flex items-center gap-3 pt-3"
1350
1717
  ),
1351
1718
  children: [
@@ -1359,8 +1726,8 @@ var CheckboxField = ({ field: fieldDef }) => {
1359
1726
  helpers.setTouched(true, false);
1360
1727
  },
1361
1728
  className: tailwindMerge.twMerge(
1362
- "flex h-5 w-5 items-center justify-center rounded border",
1363
- isStacked && "mt-0.5 shrink-0"
1729
+ "flex h-5 w-5 shrink-0 items-center justify-center rounded border",
1730
+ isStacked && "mt-0.5"
1364
1731
  ),
1365
1732
  style: checkboxStyle,
1366
1733
  children: /* @__PURE__ */ jsxRuntime.jsx(radixUi.Checkbox.Indicator, { children: /* @__PURE__ */ jsxRuntime.jsx(bs.BsCheck, { className: "text-white" }) })
@@ -1370,7 +1737,7 @@ var CheckboxField = ({ field: fieldDef }) => {
1370
1737
  "label",
1371
1738
  {
1372
1739
  htmlFor: fieldDef.id,
1373
- className: "cursor-pointer text-sm",
1740
+ className: "min-w-0 cursor-pointer text-sm",
1374
1741
  style: { color: FORM_VAR.labelText },
1375
1742
  children: fieldDef.label
1376
1743
  }
@@ -1382,7 +1749,7 @@ var CheckboxField = ({ field: fieldDef }) => {
1382
1749
  };
1383
1750
  var RadioField = ({ field: fieldDef, disabled }) => {
1384
1751
  const [field, meta, helpers] = formik.useField(fieldDef.id);
1385
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pt-3", children: [
1752
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-inherit pt-3", children: [
1386
1753
  /* @__PURE__ */ jsxRuntime.jsx(
1387
1754
  "span",
1388
1755
  {
@@ -1400,10 +1767,10 @@ var RadioField = ({ field: fieldDef, disabled }) => {
1400
1767
  helpers.setValue(value);
1401
1768
  helpers.setTouched(true, false);
1402
1769
  },
1403
- className: "flex flex-col gap-2",
1770
+ className: "flex flex-col gap-2 bg-inherit",
1404
1771
  children: (fieldDef.options || []).map((opt) => {
1405
1772
  const isSelected = field.value === opt.value;
1406
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
1773
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 bg-inherit", children: [
1407
1774
  /* @__PURE__ */ jsxRuntime.jsx(
1408
1775
  radixUi.RadioGroup.Item,
1409
1776
  {
@@ -1462,13 +1829,126 @@ function nextBusinessDay(from) {
1462
1829
  while (dateFns.isWeekend(d)) d = dateFns.addDays(d, 1);
1463
1830
  return d;
1464
1831
  }
1465
- function buildDateFilter(config) {
1832
+ function timeOnDay(value, onDay) {
1833
+ const parsed = dateFns.parse(value, "HH:mm", onDay);
1834
+ return Number.isNaN(parsed.getTime()) ? null : parsed;
1835
+ }
1836
+ function minutesOfDay(d) {
1837
+ return d.getHours() * 60 + d.getMinutes();
1838
+ }
1839
+ function minutesOfString(value) {
1840
+ const m = /^(\d{2}):(\d{2})$/.exec(value);
1841
+ if (!m) return null;
1842
+ const mins = Number(m[1]) * 60 + Number(m[2]);
1843
+ return Number.isFinite(mins) ? mins : null;
1844
+ }
1845
+ function windowOnDay(config, day) {
1846
+ const base = dateFns.set(day, { seconds: 0, milliseconds: 0 });
1847
+ const min = (config == null ? void 0 : config.minTime) ? timeOnDay(config.minTime, base) : dateFns.set(base, { hours: 0, minutes: 0 });
1848
+ const max = (config == null ? void 0 : config.maxTime) ? timeOnDay(config.maxTime, base) : dateFns.set(base, { hours: 23, minutes: 59 });
1849
+ if (!min || !max || max < min) return null;
1850
+ return { min, max };
1851
+ }
1852
+ function lastSlotOnDay(config, day) {
1853
+ var _a;
1854
+ const bounds = windowOnDay(config, day);
1855
+ if (!bounds) return null;
1856
+ const intervalMs = Math.max(1, (_a = config == null ? void 0 : config.timeIntervals) != null ? _a : 30) * 6e4;
1857
+ const steps = Math.floor(
1858
+ (bounds.max.getTime() - bounds.min.getTime()) / intervalMs
1859
+ );
1860
+ return new Date(bounds.min.getTime() + steps * intervalMs);
1861
+ }
1862
+ function rangesOnDay(config, day) {
1863
+ const ranges = config == null ? void 0 : config.excludeTimeRanges;
1864
+ if (!ranges || ranges.length === 0) return [];
1865
+ const key = dateFns.format(day, "yyyy-MM-dd");
1866
+ return ranges.filter((r) => r && r.date === key);
1867
+ }
1868
+ function isTimeExcluded(config, slot) {
1869
+ const ranges = rangesOnDay(config, slot);
1870
+ if (ranges.length === 0) return false;
1871
+ const at = minutesOfDay(slot);
1872
+ return ranges.some((r) => {
1873
+ const from = minutesOfString(r.from);
1874
+ const to = minutesOfString(r.to);
1875
+ if (from === null || to === null || to <= from) return false;
1876
+ return at >= from && at < to;
1877
+ });
1878
+ }
1879
+ function hasSelectableSlot(config, day, options = {}, now = /* @__PURE__ */ new Date()) {
1880
+ var _a, _b, _c;
1881
+ const bounds = windowOnDay(config, day);
1882
+ if (!bounds) return true;
1883
+ const filterPast = (_b = (_a = options.filterPastTimes) != null ? _a : config == null ? void 0 : config.filterPastTimes) != null ? _b : true;
1884
+ const intervalMs = Math.max(1, (_c = config == null ? void 0 : config.timeIntervals) != null ? _c : 30) * 6e4;
1885
+ const last = lastSlotOnDay(config, day);
1886
+ if (!last) return true;
1887
+ for (let t = bounds.min.getTime(); t <= last.getTime(); t += intervalMs) {
1888
+ const slot = new Date(t);
1889
+ if (filterPast && slot.getTime() < now.getTime()) continue;
1890
+ if (isTimeExcluded(config, slot)) continue;
1891
+ return true;
1892
+ }
1893
+ return false;
1894
+ }
1895
+ function isDayExcluded(config, date, now = /* @__PURE__ */ new Date()) {
1466
1896
  var _a, _b, _c, _d;
1897
+ if (((_a = config == null ? void 0 : config.excludeWeekends) != null ? _a : false) && dateFns.isWeekend(date)) return true;
1898
+ if (((_b = config == null ? void 0 : config.excludeToday) != null ? _b : false) && dateFns.isSameDay(date, now)) return true;
1899
+ if (((_c = config == null ? void 0 : config.excludeTomorrow) != null ? _c : false) && dateFns.isSameDay(date, dateFns.addDays(now, 1))) {
1900
+ return true;
1901
+ }
1902
+ if (((_d = config == null ? void 0 : config.excludeNextBusinessDay) != null ? _d : false) && dateFns.isSameDay(date, nextBusinessDay(now))) {
1903
+ return true;
1904
+ }
1905
+ const named = config == null ? void 0 : config.excludeDates;
1906
+ if (named && named.length > 0) {
1907
+ const key = dateFns.format(date, "yyyy-MM-dd");
1908
+ if (named.some((d) => d === key)) return true;
1909
+ }
1910
+ return false;
1911
+ }
1912
+ function buildTimeFilter(config, options = {}) {
1913
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1914
+ if (!((_b = (_a = options.showTimeSelect) != null ? _a : config == null ? void 0 : config.showTimeSelect) != null ? _b : true)) return void 0;
1915
+ const filterPast = (_d = (_c = options.filterPastTimes) != null ? _c : config == null ? void 0 : config.filterPastTimes) != null ? _d : true;
1916
+ const hasRanges = ((_f = (_e = config == null ? void 0 : config.excludeTimeRanges) == null ? void 0 : _e.length) != null ? _f : 0) > 0;
1917
+ const hasDayRules = ((_g = config == null ? void 0 : config.excludeWeekends) != null ? _g : false) || ((_h = config == null ? void 0 : config.excludeToday) != null ? _h : false) || ((_i = config == null ? void 0 : config.excludeTomorrow) != null ? _i : false) || ((_j = config == null ? void 0 : config.excludeNextBusinessDay) != null ? _j : false) || ((_l = (_k = config == null ? void 0 : config.excludeDates) == null ? void 0 : _k.length) != null ? _l : 0) > 0;
1918
+ if (!filterPast && !hasRanges && !hasDayRules) return void 0;
1919
+ return (time) => {
1920
+ const now = /* @__PURE__ */ new Date();
1921
+ if (filterPast && time.getTime() < now.getTime()) return false;
1922
+ if (hasDayRules && isDayExcluded(config, time, now)) return false;
1923
+ if (hasRanges && isTimeExcluded(config, time)) return false;
1924
+ return true;
1925
+ };
1926
+ }
1927
+ function firstSelectableDay(config, options = {}, from = /* @__PURE__ */ new Date(), limit = 370) {
1928
+ const filter = buildDateFilter(config, options);
1929
+ let day = new Date(from.getFullYear(), from.getMonth(), from.getDate());
1930
+ for (let i = 0; i < limit; i += 1) {
1931
+ if (!filter || filter(day)) return day;
1932
+ day = dateFns.addDays(day, 1);
1933
+ }
1934
+ return null;
1935
+ }
1936
+ function buildDateFilter(config, options = {}) {
1937
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1467
1938
  const excludeWeekends = (_a = config == null ? void 0 : config.excludeWeekends) != null ? _a : false;
1468
1939
  const excludeToday = (_b = config == null ? void 0 : config.excludeToday) != null ? _b : false;
1469
1940
  const excludeTomorrow = (_c = config == null ? void 0 : config.excludeTomorrow) != null ? _c : false;
1470
1941
  const excludeNext = (_d = config == null ? void 0 : config.excludeNextBusinessDay) != null ? _d : false;
1471
- if (!excludeWeekends && !excludeToday && !excludeTomorrow && !excludeNext) {
1942
+ const excludedDays = new Set(
1943
+ ((_e = config == null ? void 0 : config.excludeDates) != null ? _e : []).filter(
1944
+ (d) => typeof d === "string" && d.length === 10
1945
+ )
1946
+ );
1947
+ const timeSelect = (_g = (_f = options.showTimeSelect) != null ? _f : config == null ? void 0 : config.showTimeSelect) != null ? _g : true;
1948
+ const filterPast = (_i = (_h = options.filterPastTimes) != null ? _h : config == null ? void 0 : config.filterPastTimes) != null ? _i : true;
1949
+ const hasRanges = ((_k = (_j = config == null ? void 0 : config.excludeTimeRanges) == null ? void 0 : _j.length) != null ? _k : 0) > 0;
1950
+ const checkSlots = timeSelect && (filterPast || hasRanges);
1951
+ if (!excludeWeekends && !excludeToday && !excludeTomorrow && !excludeNext && !checkSlots && excludedDays.size === 0) {
1472
1952
  return void 0;
1473
1953
  }
1474
1954
  return (date) => {
@@ -1477,6 +1957,15 @@ function buildDateFilter(config) {
1477
1957
  if (excludeToday && dateFns.isSameDay(date, now)) return false;
1478
1958
  if (excludeTomorrow && dateFns.isSameDay(date, dateFns.addDays(now, 1))) return false;
1479
1959
  if (excludeNext && dateFns.isSameDay(date, nextBusinessDay(now))) return false;
1960
+ if (excludedDays.size > 0 && excludedDays.has(dateFns.format(date, "yyyy-MM-dd"))) {
1961
+ return false;
1962
+ }
1963
+ if (checkSlots) {
1964
+ const needsCheck = filterPast && dateFns.isSameDay(date, now) || hasRanges && rangesOnDay(config, date).length > 0;
1965
+ if (needsCheck && !hasSelectableSlot(config, date, options, now)) {
1966
+ return false;
1967
+ }
1968
+ }
1480
1969
  return true;
1481
1970
  };
1482
1971
  }
@@ -1500,7 +1989,7 @@ var DateTimeField = ({
1500
1989
  dateOnly = false,
1501
1990
  disabled
1502
1991
  }) => {
1503
- var _a, _b, _c, _d, _e, _f, _g, _h;
1992
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1504
1993
  const [field, meta, helpers] = formik.useField(fieldDef.id);
1505
1994
  const [focused, setFocused] = react.useState(false);
1506
1995
  const formStyle = useFormStyle();
@@ -1517,11 +2006,15 @@ var DateTimeField = ({
1517
2006
  const maxTime = showTimeSelect ? parseTimeString(config.maxTime, 23, 59) : void 0;
1518
2007
  const minDate = excludePastDates ? /* @__PURE__ */ new Date() : void 0;
1519
2008
  const selected = parseStoredValue(field.value);
1520
- const filterDate = buildDateFilter(config);
1521
- const filterTime = (time) => {
1522
- if (!filterPastTimes) return true;
1523
- return time.getTime() >= Date.now();
1524
- };
2009
+ const filterDate = buildDateFilter(config, {
2010
+ showTimeSelect,
2011
+ filterPastTimes
2012
+ });
2013
+ const filterTime = buildTimeFilter(config, {
2014
+ showTimeSelect,
2015
+ filterPastTimes
2016
+ });
2017
+ const openToDate = selected || !filterDate ? void 0 : (_i = firstSelectableDay(config, { showTimeSelect, filterPastTimes })) != null ? _i : void 0;
1525
2018
  const handleChange = (date) => {
1526
2019
  if (!date) {
1527
2020
  helpers.setValue("");
@@ -1529,11 +2022,15 @@ var DateTimeField = ({
1529
2022
  }
1530
2023
  helpers.setValue(dateOnly ? dateFns.format(date, "yyyy-MM-dd") : date.toISOString());
1531
2024
  };
1532
- const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant));
1533
- const pickerProps = {
2025
+ const borderStyle = __spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle));
2026
+ const pickerProps = __spreadProps(__spreadValues({
1534
2027
  id: fieldDef.id,
1535
2028
  name: fieldDef.id,
1536
2029
  wrapperClassName: "block w-full",
2030
+ // react-datepicker's stylesheet pins the popper at z-index 1, below the
2031
+ // z-10 floating labels in useInputStyles — neighboring fields' labels
2032
+ // would paint over the open calendar.
2033
+ popperClassName: "!z-50",
1537
2034
  disabled,
1538
2035
  selected,
1539
2036
  onChange: handleChange,
@@ -1544,15 +2041,16 @@ var DateTimeField = ({
1544
2041
  },
1545
2042
  showTimeSelect,
1546
2043
  timeIntervals,
1547
- minDate,
2044
+ minDate
2045
+ }, openToDate ? { openToDate } : {}), {
1548
2046
  minTime,
1549
2047
  maxTime,
1550
2048
  filterDate,
1551
- filterTime: showTimeSelect && filterPastTimes ? filterTime : void 0,
2049
+ filterTime,
1552
2050
  dateFormat,
1553
2051
  placeholderText,
1554
2052
  autoComplete: "off"
1555
- };
2053
+ });
1556
2054
  if (styles.isStacked) {
1557
2055
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.wrapperClass, children: [
1558
2056
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1579,7 +2077,7 @@ var DateTimeField = ({
1579
2077
  hasError && /* @__PURE__ */ jsxRuntime.jsx(
1580
2078
  "span",
1581
2079
  {
1582
- className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
2080
+ className: "mt-1 text-xs",
1583
2081
  style: styles.errorStyle,
1584
2082
  children: meta.error
1585
2083
  }
@@ -1617,7 +2115,7 @@ var DateTimeField = ({
1617
2115
  }
1618
2116
  )
1619
2117
  ] }),
1620
- hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
2118
+ hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "relative mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
1621
2119
  ] });
1622
2120
  };
1623
2121
  var DateField = ({ field, disabled }) => {
@@ -1643,13 +2141,12 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
1643
2141
  );
1644
2142
  helpers.setValue(next);
1645
2143
  };
1646
- const borderStyle = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle.inputVariant)), {
2144
+ const borderStyle = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, styles.inputStyle), focused ? styles.inputFocusStyle : {}), getErrorOutlineStyle(hasError, formStyle)), {
1647
2145
  paddingRight: "2.75rem"
1648
2146
  });
1649
2147
  const inputType = reveal ? "text" : "password";
1650
2148
  const inputProps = {
1651
2149
  id: fieldDef.id,
1652
- name: fieldDef.id,
1653
2150
  type: inputType,
1654
2151
  disabled,
1655
2152
  autoComplete: "off",
@@ -1658,9 +2155,9 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
1658
2155
  value: field.value,
1659
2156
  onChange: handleChange,
1660
2157
  onFocus: () => setFocused(true),
1661
- onBlur: (e) => {
2158
+ onBlur: () => {
1662
2159
  setFocused(false);
1663
- field.onBlur(e);
2160
+ helpers.setTouched(true);
1664
2161
  },
1665
2162
  "aria-describedby": `${fieldDef.id}-secure`,
1666
2163
  "data-sensitive": "true"
@@ -1677,7 +2174,11 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
1677
2174
  {
1678
2175
  type: "button",
1679
2176
  onClick: () => setReveal((r) => !r),
1680
- className: "flex h-7 w-7 items-center justify-center rounded text-gray-600 hover:bg-gray-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/60 dark:text-zinc-400 dark:hover:bg-zinc-700",
2177
+ className: tailwindMerge.twMerge(
2178
+ "flex h-7 w-7 items-center justify-center rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/60",
2179
+ FORM_MUTED_TEXT_CLASS,
2180
+ FORM_SUBTLE_HOVER_FILL_CLASS
2181
+ ),
1681
2182
  "aria-pressed": reveal,
1682
2183
  "aria-label": reveal ? "Hide value" : "Show value",
1683
2184
  children: reveal ? /* @__PURE__ */ jsxRuntime.jsx(fi.FiEyeOff, { size: 16, "aria-hidden": "true" }) : /* @__PURE__ */ jsxRuntime.jsx(fi.FiEye, { size: 16, "aria-hidden": "true" })
@@ -1690,7 +2191,8 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
1690
2191
  {
1691
2192
  id: `${fieldDef.id}-secure`,
1692
2193
  className: tailwindMerge.twMerge(
1693
- "flex items-center gap-1 text-xs text-gray-500 dark:text-zinc-400",
2194
+ "flex items-center gap-1 text-xs",
2195
+ FORM_MUTED_TEXT_CLASS,
1694
2196
  className
1695
2197
  ),
1696
2198
  children: [
@@ -1714,14 +2216,14 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
1714
2216
  /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: fieldDef.id, className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label }),
1715
2217
  renderSecureHint("mb-1")
1716
2218
  ] }),
1717
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
2219
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative bg-inherit", children: [
1718
2220
  /* @__PURE__ */ jsxRuntime.jsx("input", __spreadValues({ className: styles.inputClass, style: borderStyle }, inputProps)),
1719
2221
  renderToggle()
1720
2222
  ] }),
1721
2223
  hasError && /* @__PURE__ */ jsxRuntime.jsx(
1722
2224
  "span",
1723
2225
  {
1724
- className: tailwindMerge.twMerge("mt-1 text-xs", "text-red-600 dark:text-red-400"),
2226
+ className: "mt-1 text-xs",
1725
2227
  style: styles.errorStyle,
1726
2228
  children: meta.error
1727
2229
  }
@@ -1735,7 +2237,7 @@ var SensitiveField = ({ field: fieldDef, disabled }) => {
1735
2237
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: styles.labelClass, style: styles.labelStyle, children: fieldDef.label }),
1736
2238
  renderToggle("mb-3")
1737
2239
  ] }),
1738
- hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
2240
+ hasError && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "relative mt-[-8px] text-xs", style: styles.errorStyle, children: meta.error })
1739
2241
  ] });
1740
2242
  };
1741
2243
  var FormFileUploadContext = react.createContext({});
@@ -1873,14 +2375,14 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
1873
2375
  "p",
1874
2376
  {
1875
2377
  className: "mb-2 text-xs",
1876
- style: { color: "var(--form-placeholder-color, #9ca3af)" },
2378
+ style: { color: FORM_VAR.placeholder },
1877
2379
  children: fieldDef.helpText
1878
2380
  }
1879
2381
  ),
1880
2382
  /* @__PURE__ */ jsxRuntime.jsxs(
1881
2383
  "div",
1882
2384
  {
1883
- className: `relative rounded-lg border-2 border-dashed p-6 text-center transition-colors ${hasError ? "border-red-400" : pickerDisabled ? "border-gray-200 dark:border-gray-700" : "border-gray-300 hover:border-gray-400 dark:border-gray-600 dark:hover:border-gray-500"}`,
2385
+ className: `relative rounded-lg border-2 border-dashed p-6 text-center transition-colors ${hasError ? "border-red-400" : pickerDisabled ? "border-current/10" : "border-current/25 hover:border-current/40"}`,
1884
2386
  onDragOver: (e) => {
1885
2387
  if (pickerDisabled) return;
1886
2388
  e.preventDefault();
@@ -1910,9 +2412,15 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
1910
2412
  }
1911
2413
  ),
1912
2414
  uploading ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
1913
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-auto h-1.5 w-32 overflow-hidden rounded-full bg-gray-200 dark:bg-gray-700", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-full w-1/3 animate-pulse rounded-full bg-indigo-500" }) }),
1914
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-gray-500", children: "Uploading\u2026" })
1915
- ] }) : uploadsUnavailable ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-gray-500 dark:text-gray-400", children: NO_UPLOADER_MESSAGE }) : /* @__PURE__ */ jsxRuntime.jsxs(
2415
+ /* @__PURE__ */ jsxRuntime.jsx(
2416
+ "div",
2417
+ {
2418
+ className: `mx-auto h-1.5 w-32 overflow-hidden rounded-full ${FORM_SUBTLE_FILL_CLASS}`,
2419
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-full w-1/3 animate-pulse rounded-full bg-indigo-500" })
2420
+ }
2421
+ ),
2422
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: `text-sm ${FORM_MUTED_TEXT_CLASS}`, children: "Uploading\u2026" })
2423
+ ] }) : uploadsUnavailable ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: `text-sm ${FORM_MUTED_TEXT_CLASS}`, children: NO_UPLOADER_MESSAGE }) : /* @__PURE__ */ jsxRuntime.jsxs(
1916
2424
  "button",
1917
2425
  {
1918
2426
  type: "button",
@@ -1921,12 +2429,12 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
1921
2429
  return (_a2 = inputRef.current) == null ? void 0 : _a2.click();
1922
2430
  },
1923
2431
  disabled,
1924
- className: "cursor-pointer text-sm text-gray-500 hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-50 dark:text-gray-400 dark:hover:text-gray-200",
2432
+ className: `cursor-pointer text-sm ${FORM_MUTED_TEXT_CLASS} hover:text-current disabled:cursor-not-allowed disabled:opacity-50`,
1925
2433
  children: [
1926
2434
  /* @__PURE__ */ jsxRuntime.jsx(
1927
2435
  "svg",
1928
2436
  {
1929
- className: "mx-auto mb-2 h-8 w-8 text-gray-400",
2437
+ className: `mx-auto mb-2 h-8 w-8 ${FORM_FAINT_TEXT_CLASS}`,
1930
2438
  fill: "none",
1931
2439
  viewBox: "0 0 24 24",
1932
2440
  strokeWidth: 1.5,
@@ -1944,7 +2452,7 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
1944
2452
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-medium", children: "Click to upload" }),
1945
2453
  " or drag and drop",
1946
2454
  /* @__PURE__ */ jsxRuntime.jsx("br", {}),
1947
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs text-gray-400", children: [
2455
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: `text-xs ${FORM_FAINT_TEXT_CLASS}`, children: [
1948
2456
  "Max ",
1949
2457
  formatBytes(maxSizeBytes),
1950
2458
  multiple && ` \xB7 Up to ${maxFiles} files`
@@ -1958,7 +2466,7 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
1958
2466
  files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-3 space-y-2", children: files.map((f, i) => /* @__PURE__ */ jsxRuntime.jsxs(
1959
2467
  "div",
1960
2468
  {
1961
- className: "flex items-center gap-3 rounded-md border border-gray-200 bg-gray-50 px-3 py-2 dark:border-gray-700 dark:bg-gray-800",
2469
+ className: `flex items-center gap-3 rounded-md border ${FORM_SUBTLE_BORDER_CLASS} ${FORM_SUBTLE_FILL_CLASS} px-3 py-2`,
1962
2470
  children: [
1963
2471
  f.url && f.name.match(/\.(jpg|jpeg|png|webp|gif|svg)$/i) && // eslint-disable-next-line @next/next/no-img-element
1964
2472
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1970,15 +2478,15 @@ var FileField = ({ field: fieldDef, onUpload, disabled }) => {
1970
2478
  }
1971
2479
  ),
1972
2480
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "min-w-0 flex-1", children: [
1973
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-sm font-medium text-gray-900 dark:text-gray-100", children: f.name }),
1974
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-gray-500", children: formatBytes(f.size) })
2481
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "truncate text-sm font-medium", children: f.name }),
2482
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: `text-xs ${FORM_MUTED_TEXT_CLASS}`, children: formatBytes(f.size) })
1975
2483
  ] }),
1976
2484
  /* @__PURE__ */ jsxRuntime.jsx(
1977
2485
  "button",
1978
2486
  {
1979
2487
  type: "button",
1980
2488
  onClick: () => removeFile(i),
1981
- className: "cursor-pointer text-gray-400 hover:text-red-500",
2489
+ className: `cursor-pointer ${FORM_FAINT_TEXT_CLASS} hover:text-red-500`,
1982
2490
  "aria-label": `Remove ${f.name}`,
1983
2491
  children: /* @__PURE__ */ jsxRuntime.jsx(
1984
2492
  "svg",
@@ -2056,12 +2564,13 @@ var DynamicFormField = ({ field, mirrored, mirrorBehavior }) => {
2056
2564
  };
2057
2565
  const widthClass = widthClasses[((_a = field.layout) == null ? void 0 : _a.width) || "full"] || "md:col-span-6";
2058
2566
  const description = (_b = field.description) != null ? _b : field.helpText;
2059
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: widthClass, children: [
2567
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: tailwindMerge.twMerge(widthClass, "bg-inherit"), children: [
2060
2568
  /* @__PURE__ */ jsxRuntime.jsx(Component, { field, disabled: locked }),
2061
- description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: tailwindMerge.twMerge("mt-1 text-xs", "text-gray-500 dark:text-zinc-400"), children: description })
2569
+ description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: tailwindMerge.twMerge("mt-1 text-xs", FORM_MUTED_TEXT_CLASS), children: description })
2062
2570
  ] });
2063
2571
  };
2064
2572
  var spacingGap = {
2573
+ none: "gap-4",
2065
2574
  compact: "gap-2",
2066
2575
  normal: "gap-4",
2067
2576
  relaxed: "gap-6"
@@ -2070,12 +2579,12 @@ var DynamicFormSection = ({
2070
2579
  section,
2071
2580
  isLast,
2072
2581
  formDefaultTextColor,
2582
+ formDefaultTextColorDark,
2073
2583
  inlineSubmit
2074
2584
  }) => {
2075
- var _a, _b;
2585
+ var _a;
2076
2586
  const style = useFormStyle();
2077
- const previewOverrides = useFormPreviewOverrides();
2078
- const previewTextColor = previewOverrides == null ? void 0 : previewOverrides.textColor;
2587
+ const { forced, darkEnabled } = useFormColorScheme();
2079
2588
  const { values, setFieldValue } = formik.useFormikContext();
2080
2589
  const sameAs = section.sameAs;
2081
2590
  const toggleKey = sameAs ? sameAsToggleKey(section.id) : "";
@@ -2094,35 +2603,44 @@ var DynamicFormSection = ({
2094
2603
  setFieldValue(targetId, (_a2 = values[sourceId]) != null ? _a2 : "");
2095
2604
  }
2096
2605
  }, [toggleOn, sourceSignature]);
2097
- const effectiveTextColor = (_b = previewTextColor != null ? previewTextColor : section.textColor) != null ? _b : formDefaultTextColor;
2606
+ const formDefaults = {
2607
+ light: formDefaultTextColor,
2608
+ dark: formDefaultTextColorDark
2609
+ };
2610
+ const effectiveTextColor = resolveSectionTextColor(
2611
+ section,
2612
+ formDefaults,
2613
+ forced != null ? forced : "light"
2614
+ );
2615
+ const darkTextColor = darkEnabled && (section.textColorDark || formDefaultTextColorDark) ? resolveSectionTextColor(section, formDefaults, "dark") : void 0;
2098
2616
  const sortedFields = [...section.fields].sort(
2099
2617
  (a, b) => {
2100
- var _a2, _b2, _c, _d;
2101
- return ((_b2 = (_a2 = a.layout) == null ? void 0 : _a2.order) != null ? _b2 : 0) - ((_d = (_c = b.layout) == null ? void 0 : _c.order) != null ? _d : 0);
2618
+ var _a2, _b, _c, _d;
2619
+ return ((_b = (_a2 = a.layout) == null ? void 0 : _a2.order) != null ? _b : 0) - ((_d = (_c = b.layout) == null ? void 0 : _c.order) != null ? _d : 0);
2102
2620
  }
2103
2621
  );
2104
- const gap = spacingGap[style.spacing || "normal"];
2622
+ const customGap = resolveCustomGap(style);
2623
+ const gap = customGap ? "gap-0" : spacingGap[style.spacing || "normal"];
2624
+ const gapStyle = customGap ? { gap: FORM_GAP_VAR } : {};
2105
2625
  const divider = style.sectionDividers && !isLast;
2106
2626
  const isStacked = style.inputVariant === "stacked";
2107
2627
  const sectionWrapperClass = tailwindMerge.twMerge(
2628
+ "bg-inherit",
2108
2629
  isStacked ? "space-y-4" : "mb-6",
2109
- divider && "border-b border-gray-200 dark:border-zinc-700 pb-6"
2110
- );
2111
- const titleClass = tailwindMerge.twMerge(
2112
- "text-lg font-semibold",
2113
- effectiveTextColor ? "" : "text-gray-800 dark:text-zinc-100",
2114
- !isStacked && "mb-1"
2630
+ divider && `border-b ${FORM_SUBTLE_BORDER_CLASS} pb-6`
2115
2631
  );
2632
+ const titleClass = tailwindMerge.twMerge("text-lg font-semibold", !isStacked && "mb-1");
2116
2633
  const descriptionClass = tailwindMerge.twMerge(
2117
2634
  "text-sm",
2118
- effectiveTextColor ? "" : "text-gray-500 dark:text-zinc-400",
2635
+ effectiveTextColor ? "" : FORM_MUTED_TEXT_CLASS,
2119
2636
  !isStacked && "mb-4"
2120
2637
  );
2121
- const textStyle = effectiveTextColor ? { color: effectiveTextColor } : void 0;
2638
+ const textStyle = effectiveTextColor || darkTextColor ? __spreadValues(__spreadValues({}, effectiveTextColor ? { color: effectiveTextColor } : {}), darkTextColor ? { [FORM_DARK_TEXT_VAR]: darkTextColor } : {}) : void 0;
2639
+ const darkTextAttr = darkTextColor ? { [FORM_DARK_TEXT_ATTR]: "" } : {};
2122
2640
  return /* @__PURE__ */ jsxRuntime.jsxs("fieldset", { className: sectionWrapperClass, children: [
2123
- section.title && /* @__PURE__ */ jsxRuntime.jsx("legend", { className: titleClass, style: textStyle, children: section.title }),
2124
- section.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: descriptionClass, style: textStyle, children: section.description }),
2125
- sameAs && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 flex items-center gap-3", children: [
2641
+ section.title && /* @__PURE__ */ jsxRuntime.jsx("legend", __spreadProps(__spreadValues({ className: titleClass, style: textStyle }, darkTextAttr), { children: section.title })),
2642
+ section.description && /* @__PURE__ */ jsxRuntime.jsx("p", __spreadProps(__spreadValues({ className: descriptionClass, style: textStyle }, darkTextAttr), { children: section.description })),
2643
+ sameAs && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 flex items-center gap-3 bg-inherit", children: [
2126
2644
  /* @__PURE__ */ jsxRuntime.jsx(
2127
2645
  radixUi.Checkbox.Root,
2128
2646
  {
@@ -2149,10 +2667,11 @@ var DynamicFormSection = ({
2149
2667
  "div",
2150
2668
  {
2151
2669
  className: tailwindMerge.twMerge(
2152
- "grid grid-cols-1 md:grid-cols-6",
2670
+ "grid grid-cols-1 bg-inherit md:grid-cols-6",
2153
2671
  gap,
2154
2672
  inlineSubmit && "min-w-0 flex-auto"
2155
2673
  ),
2674
+ style: gapStyle,
2156
2675
  children: sortedFields.map((field, i) => /* @__PURE__ */ jsxRuntime.jsx(
2157
2676
  DynamicFormField,
2158
2677
  {
@@ -2164,13 +2683,52 @@ var DynamicFormSection = ({
2164
2683
  ))
2165
2684
  }
2166
2685
  );
2167
- return inlineSubmit ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-3", children: [
2686
+ return inlineSubmit ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start gap-3 bg-inherit", children: [
2168
2687
  fieldsGrid,
2169
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: tailwindMerge.twMerge("flex-none", !isStacked && "pt-3"), children: inlineSubmit })
2688
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: tailwindMerge.twMerge("flex-none bg-inherit", !isStacked && "pt-3"), children: inlineSubmit })
2170
2689
  ] }) : fieldsGrid;
2171
2690
  })()
2172
2691
  ] });
2173
2692
  };
2693
+ var COOLDOWN_MS = 2e3;
2694
+ function useSuccessFeedback(isSuccess) {
2695
+ const bannerRef = react.useRef(null);
2696
+ const [cooldown, setCooldown] = react.useState(false);
2697
+ const [submittedSnapshot, setSubmittedSnapshot] = react.useState(null);
2698
+ react.useEffect(() => {
2699
+ if (!isSuccess) return;
2700
+ setCooldown(true);
2701
+ const timer = setTimeout(() => setCooldown(false), COOLDOWN_MS);
2702
+ const node = bannerRef.current;
2703
+ if (node && typeof node.scrollIntoView === "function") {
2704
+ const reduceMotion = typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
2705
+ node.scrollIntoView({
2706
+ behavior: reduceMotion ? "auto" : "smooth",
2707
+ block: "center"
2708
+ });
2709
+ }
2710
+ return () => clearTimeout(timer);
2711
+ }, [isSuccess]);
2712
+ return {
2713
+ bannerRef,
2714
+ cooldown,
2715
+ submittedSnapshot,
2716
+ markSubmitted: (values) => setSubmittedSnapshot(JSON.stringify(values)),
2717
+ clearSubmitted: () => setSubmittedSnapshot(null)
2718
+ };
2719
+ }
2720
+ function ValuesObserver({ onChange }) {
2721
+ const { values } = formik.useFormikContext();
2722
+ const mounted = react.useRef(false);
2723
+ react.useEffect(() => {
2724
+ if (!mounted.current) {
2725
+ mounted.current = true;
2726
+ return;
2727
+ }
2728
+ onChange(values);
2729
+ }, [values, onChange]);
2730
+ return null;
2731
+ }
2174
2732
  function globalTracker() {
2175
2733
  if (typeof window === "undefined") return void 0;
2176
2734
  return window.__vtTrack;
@@ -2213,6 +2771,20 @@ function findUnresolvedUploads(payload) {
2213
2771
  }
2214
2772
  return ids;
2215
2773
  }
2774
+ function getConversionUserData(definition, values) {
2775
+ const out = {};
2776
+ for (const section of definition.sections) {
2777
+ for (const field of section.fields) {
2778
+ if (field.type === "email" && out.email === void 0 && values[field.id]) {
2779
+ out.email = values[field.id];
2780
+ }
2781
+ if (field.type === "phone" && out.phone === void 0 && values[field.id]) {
2782
+ out.phone = values[field.id];
2783
+ }
2784
+ }
2785
+ }
2786
+ return out;
2787
+ }
2216
2788
  function getSensitiveFieldIds(definition) {
2217
2789
  const ids = [];
2218
2790
  for (const section of definition.sections) {
@@ -2254,9 +2826,9 @@ function fetchTransportKey(endpoint) {
2254
2826
  var presetNonBgClasses = {
2255
2827
  default: "",
2256
2828
  minimal: "",
2257
- bordered: "border border-gray-200",
2829
+ bordered: "border border-current/15",
2258
2830
  shadow: "shadow-lg",
2259
- card: "shadow-lg border border-gray-200",
2831
+ card: "shadow-lg border border-current/15",
2260
2832
  dark: ""
2261
2833
  };
2262
2834
  var radiusClasses = {
@@ -2267,12 +2839,23 @@ var radiusClasses = {
2267
2839
  full: "rounded-2xl"
2268
2840
  };
2269
2841
  var spacingClasses = {
2842
+ // "none" exists for forms dropped into a page that owns its own layout —
2843
+ // without it a consumer had to neutralise the padding with a `p-0` class
2844
+ // override from the outside.
2845
+ none: "p-0",
2270
2846
  compact: "p-3",
2271
2847
  normal: "p-6",
2272
2848
  relaxed: "p-8"
2273
2849
  };
2850
+ function getRadiusClass(style, fallback = "rounded-md") {
2851
+ if (resolveCustomRadius(style)) return "rounded-none";
2852
+ return radiusClasses[style.borderRadius] || fallback;
2853
+ }
2854
+ function getRadiusStyle(style) {
2855
+ return resolveCustomRadius(style) ? { borderRadius: FORM_RADIUS_VAR } : {};
2856
+ }
2274
2857
  function getButtonClasses(style) {
2275
- const radius = radiusClasses[style.borderRadius] || "rounded-md";
2858
+ const radius = getRadiusClass(style);
2276
2859
  const weight = style.inputVariant === "stacked" ? "font-semibold" : "font-medium";
2277
2860
  switch (style.buttonVariant) {
2278
2861
  case "outline":
@@ -2285,17 +2868,18 @@ function getButtonClasses(style) {
2285
2868
  }
2286
2869
  }
2287
2870
  function getButtonStyle(style) {
2871
+ const radius = getRadiusStyle(style);
2288
2872
  switch (style.buttonVariant) {
2289
2873
  case "outline":
2290
- return { borderColor: FORM_VAR.buttonBg, color: FORM_VAR.buttonBg };
2874
+ return __spreadProps(__spreadValues({}, radius), { borderColor: FORM_VAR.buttonBg, color: FORM_VAR.buttonBg });
2291
2875
  case "ghost":
2292
- return { color: FORM_VAR.buttonBg };
2876
+ return __spreadProps(__spreadValues({}, radius), { color: FORM_VAR.buttonBg });
2293
2877
  case "filled":
2294
2878
  default:
2295
- return {
2879
+ return __spreadProps(__spreadValues({}, radius), {
2296
2880
  backgroundColor: FORM_VAR.buttonBg,
2297
2881
  color: FORM_VAR.buttonText
2298
- };
2882
+ });
2299
2883
  }
2300
2884
  }
2301
2885
  function interpolateSuccessMessage(template, response) {
@@ -2409,6 +2993,9 @@ var ErrorBanner = ({
2409
2993
  var DynamicForm = ({
2410
2994
  definition,
2411
2995
  apiRoute,
2996
+ submit,
2997
+ initialValues: initialValueOverrides,
2998
+ onValuesChange,
2412
2999
  onSuccess,
2413
3000
  onError,
2414
3001
  extraData,
@@ -2422,17 +3009,19 @@ var DynamicForm = ({
2422
3009
  previewTouchAllSignal,
2423
3010
  previewUntouchAllSignal,
2424
3011
  previewBg,
2425
- previewTextColor
3012
+ previewTextColor,
3013
+ previewColorScheme,
3014
+ darkModeSelector = FORM_DEFAULT_DARK_SELECTOR
2426
3015
  }) => {
2427
- var _a, _b, _c;
3016
+ var _a, _b, _c, _d;
2428
3017
  const [submitStatus, setSubmitStatus] = react.useState("idle");
2429
- const [postSuccessCooldown, setPostSuccessCooldown] = react.useState(false);
2430
- react.useEffect(() => {
2431
- if (submitStatus !== "success") return;
2432
- setPostSuccessCooldown(true);
2433
- const t = setTimeout(() => setPostSuccessCooldown(false), 2e3);
2434
- return () => clearTimeout(t);
2435
- }, [submitStatus]);
3018
+ const {
3019
+ bannerRef,
3020
+ cooldown: postSuccessCooldown,
3021
+ submittedSnapshot,
3022
+ markSubmitted,
3023
+ clearSubmitted
3024
+ } = useSuccessFeedback(submitStatus === "success");
2436
3025
  const [responseData, setResponseData] = react.useState(
2437
3026
  null
2438
3027
  );
@@ -2454,8 +3043,15 @@ var DynamicForm = ({
2454
3043
  mountTimeRef.current = Date.now();
2455
3044
  }, [definition.id]);
2456
3045
  const validationSchema = react.useMemo(() => buildYupSchema(definition), [definition]);
3046
+ react.useEffect(() => {
3047
+ var _a2;
3048
+ void ((_a2 = formikRef.current) == null ? void 0 : _a2.validateForm());
3049
+ }, [validationSchema]);
2457
3050
  const initialValues = react.useMemo(() => {
2458
3051
  const base = buildInitialValues(definition);
3052
+ for (const [key, value] of Object.entries(initialValueOverrides != null ? initialValueOverrides : {})) {
3053
+ if (key in base && value !== void 0) base[key] = value;
3054
+ }
2459
3055
  if (honeypotEnabled) {
2460
3056
  base[HONEYPOT_FIELD_NAME] = "";
2461
3057
  }
@@ -2486,19 +3082,34 @@ var DynamicForm = ({
2486
3082
  if (previewUntouchAllSignal === void 0 || !formikRef.current) return;
2487
3083
  formikRef.current.setTouched({}, false);
2488
3084
  }, [previewUntouchAllSignal]);
2489
- const style = __spreadValues(__spreadValues({}, DEFAULT_FORM_STYLE), definition.style);
3085
+ const rawStyle = __spreadValues(__spreadValues({}, DEFAULT_FORM_STYLE), definition.style);
3086
+ const style = previewColorScheme ? resolveSchemeStyle(rawStyle, previewColorScheme) : rawStyle;
3087
+ const darkEnabled = !previewColorScheme && definitionHasDarkColors(definition);
3088
+ const colorSchemeState = {
3089
+ forced: previewColorScheme,
3090
+ darkEnabled
3091
+ };
2490
3092
  const isStacked = style.inputVariant === "stacked";
2491
3093
  const isCard = style.preset === "card";
2492
3094
  const submittingText = (_b = definition.submitConfig.submittingText) != null ? _b : "Submitting...";
2493
- const successBehavior = (_c = definition.submitConfig.successBehavior) != null ? _c : "message";
2494
- const hasPreviewOverride = Boolean(previewBg || previewTextColor);
2495
- const previewOverrides = hasPreviewOverride ? { backgroundColor: previewBg, textColor: previewTextColor } : null;
2496
- const cssVarStyle = buildFormCssVars(style, previewBg);
2497
- const effectiveFormBg = previewBg != null ? previewBg : style.formBackgroundColor;
2498
- const formInlineStyle = __spreadValues(__spreadValues(__spreadValues({}, cssVarStyle), effectiveFormBg ? { backgroundColor: effectiveFormBg } : {}), previewTextColor ? { color: previewTextColor } : {});
3095
+ const submittedText = (_c = definition.submitConfig.submittedText) != null ? _c : "Sent";
3096
+ const successBehavior = (_d = definition.submitConfig.successBehavior) != null ? _d : "message";
3097
+ const cssVarStyle = __spreadValues(__spreadValues({}, buildFormCssVars(style, previewBg)), darkEnabled ? buildFormDarkCssVars(style) : {});
3098
+ const effectiveFormBg = style.formBackgroundColor || previewBg;
3099
+ const rootBgStyle = darkEnabled ? { backgroundColor: FORM_ROOT_BG_VAR } : effectiveFormBg ? { backgroundColor: effectiveFormBg } : {};
3100
+ const formInlineStyle = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, cssVarStyle), getRadiusStyle(style)), rootBgStyle), previewTextColor ? { color: previewTextColor } : {});
3101
+ const darkScopeAttr = darkEnabled ? { [FORM_DARK_SCOPE_ATTR]: "" } : {};
3102
+ const darkStyleSheet = darkEnabled ? /* @__PURE__ */ jsxRuntime.jsx(
3103
+ "style",
3104
+ {
3105
+ "data-vt-forms-dark": "",
3106
+ dangerouslySetInnerHTML: { __html: buildDarkSchemeCss(darkModeSelector) }
3107
+ }
3108
+ ) : null;
2499
3109
  const formClasses = tailwindMerge.twMerge(
3110
+ "bg-inherit",
2500
3111
  presetNonBgClasses[style.preset] || "",
2501
- radiusClasses[style.borderRadius] || "rounded-md",
3112
+ getRadiusClass(style),
2502
3113
  isCard ? "p-8" : spacingClasses[style.spacing] || "p-6",
2503
3114
  isStacked ? "space-y-8" : "",
2504
3115
  className
@@ -2511,24 +3122,29 @@ var DynamicForm = ({
2511
3122
  responseData
2512
3123
  );
2513
3124
  if (successBehavior === "replace" && effectiveSubmitStatus === "success") {
2514
- return /* @__PURE__ */ jsxRuntime.jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsxRuntime.jsx(FormPreviewOverridesProvider, { value: previewOverrides, children: /* @__PURE__ */ jsxRuntime.jsx(
3125
+ return /* @__PURE__ */ jsxRuntime.jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsxRuntime.jsx(FormColorSchemeProvider, { value: colorSchemeState, children: /* @__PURE__ */ jsxRuntime.jsxs(
2515
3126
  "div",
2516
- {
3127
+ __spreadProps(__spreadValues({
3128
+ ref: bannerRef,
2517
3129
  className: formClasses,
2518
3130
  style: formInlineStyle,
2519
- "data-form-version": definition.version,
2520
- children: /* @__PURE__ */ jsxRuntime.jsx(SuccessBanner, { message: successMessage })
2521
- }
3131
+ "data-form-version": definition.version
3132
+ }, darkScopeAttr), {
3133
+ children: [
3134
+ darkStyleSheet,
3135
+ /* @__PURE__ */ jsxRuntime.jsx(SuccessBanner, { message: successMessage })
3136
+ ]
3137
+ })
2522
3138
  ) }) });
2523
3139
  }
2524
- return /* @__PURE__ */ jsxRuntime.jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsxRuntime.jsx(FormPreviewOverridesProvider, { value: previewOverrides, children: /* @__PURE__ */ jsxRuntime.jsx(FormFileUploadProvider, { value: fileUploadValue, children: /* @__PURE__ */ jsxRuntime.jsx(
3140
+ return /* @__PURE__ */ jsxRuntime.jsx(FormStyleProvider, { value: style, children: /* @__PURE__ */ jsxRuntime.jsx(FormColorSchemeProvider, { value: colorSchemeState, children: /* @__PURE__ */ jsxRuntime.jsx(FormFileUploadProvider, { value: fileUploadValue, children: /* @__PURE__ */ jsxRuntime.jsx(
2525
3141
  formik.Formik,
2526
3142
  {
2527
3143
  innerRef: formikRef,
2528
3144
  initialValues,
2529
3145
  validationSchema,
2530
3146
  onSubmit: (_0, _1) => __async(null, [_0, _1], function* (values, { setSubmitting, resetForm }) {
2531
- var _a2, _b2, _d, _e, _f;
3147
+ var _a2, _b2, _d2, _e, _f, _g;
2532
3148
  if (previewState) {
2533
3149
  setSubmitting(false);
2534
3150
  return;
@@ -2543,6 +3159,7 @@ var DynamicForm = ({
2543
3159
  console.debug(`[forms] Spam detected: ${reason}`);
2544
3160
  }
2545
3161
  setResponseData(null);
3162
+ markSubmitted(values);
2546
3163
  setSubmitStatus("success");
2547
3164
  if (successBehavior === "reset" || successBehavior === "replace") {
2548
3165
  resetForm();
@@ -2554,7 +3171,9 @@ var DynamicForm = ({
2554
3171
  setSubmitStatus("idle");
2555
3172
  try {
2556
3173
  const _c2 = values, { [_b2 = HONEYPOT_FIELD_NAME]: _hp } = _c2, cleanValues = __objRest(_c2, [__restKey(_b2)]);
2557
- const payload = __spreadProps(__spreadValues(__spreadValues({}, cleanValues), extraData), {
3174
+ const adReferral = readAdReferral();
3175
+ const analyticsSessionId = readAnalyticsSessionId();
3176
+ const payload = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, cleanValues), adReferral ? { adReferral } : {}), analyticsSessionId ? { analyticsSessionId } : {}), extraData), {
2558
3177
  formId: definition.id
2559
3178
  });
2560
3179
  for (const hiddenId of getHiddenFieldIds(definition, cleanValues)) {
@@ -2584,29 +3203,49 @@ var DynamicForm = ({
2584
3203
  );
2585
3204
  }
2586
3205
  }
2587
- const res = yield fetch(apiRoute, {
2588
- method: "POST",
2589
- headers: { "Content-Type": "application/json" },
2590
- body: JSON.stringify(payload)
2591
- });
2592
- if (!res.ok) {
2593
- const errBody = yield res.json().catch(() => null);
2594
- throw new Error(
2595
- (errBody == null ? void 0 : errBody.error) || `Submission failed (${res.status})`
2596
- );
2597
- }
2598
3206
  let body = null;
2599
- try {
2600
- body = yield res.json();
2601
- } catch (e) {
2602
- body = null;
3207
+ if (submit) {
3208
+ const result = yield submit(payload);
3209
+ body = result && typeof result === "object" ? result : null;
3210
+ } else {
3211
+ const res = yield fetch(apiRoute, {
3212
+ method: "POST",
3213
+ headers: { "Content-Type": "application/json" },
3214
+ body: JSON.stringify(payload)
3215
+ });
3216
+ if (!res.ok) {
3217
+ const errBody = yield res.json().catch(() => null);
3218
+ throw new Error(
3219
+ (errBody == null ? void 0 : errBody.error) || `Submission failed (${res.status})`
3220
+ );
3221
+ }
3222
+ try {
3223
+ body = yield res.json();
3224
+ } catch (e) {
3225
+ body = null;
3226
+ }
2603
3227
  }
2604
3228
  setResponseData(body);
3229
+ const submissionType = (_d2 = extraData == null ? void 0 : extraData.submissionType) != null ? _d2 : "contact";
3230
+ const serverId = body == null ? void 0 : body.submissionId;
3231
+ trackFormConversion(
3232
+ {
3233
+ formId: definition.id,
3234
+ formName: definition.name,
3235
+ formType: submissionType
3236
+ },
3237
+ (_e = definition.submitConfig.conversion) == null ? void 0 : _e.sendTo,
3238
+ {
3239
+ transactionId: typeof serverId === "string" && serverId ? serverId : newTransactionId(),
3240
+ userData: getConversionUserData(definition, values)
3241
+ }
3242
+ );
3243
+ markSubmitted(values);
2605
3244
  setSubmitStatus("success");
2606
- (_f = onFormSubmitCallback != null ? onFormSubmitCallback : (_d = globalTracker()) == null ? void 0 : _d.trackFormSubmit) == null ? void 0 : _f(
3245
+ (_g = onFormSubmitCallback != null ? onFormSubmitCallback : (_f = globalTracker()) == null ? void 0 : _f.trackFormSubmit) == null ? void 0 : _g(
2607
3246
  definition.id,
2608
3247
  definition.name,
2609
- (_e = extraData == null ? void 0 : extraData.submissionType) != null ? _e : "contact"
3248
+ submissionType
2610
3249
  );
2611
3250
  if (successBehavior === "reset" || successBehavior === "replace") {
2612
3251
  resetForm();
@@ -2620,23 +3259,29 @@ var DynamicForm = ({
2620
3259
  }
2621
3260
  } catch (err) {
2622
3261
  setResponseData(null);
3262
+ clearSubmitted();
2623
3263
  setSubmitStatus("error");
2624
3264
  onError == null ? void 0 : onError(err instanceof Error ? err : new Error("Submission failed"));
2625
3265
  } finally {
2626
3266
  setSubmitting(false);
2627
3267
  }
2628
3268
  }),
2629
- children: ({ isSubmitting, getFieldProps }) => {
3269
+ children: ({ isSubmitting, getFieldProps, values }) => {
2630
3270
  const showSubmitting = isSubmitting || previewSubmitting;
2631
3271
  const isDisabled = successBehavior === "disable" && effectiveSubmitStatus === "success";
2632
- const submitLocked = showSubmitting || postSuccessCooldown || previewState === "success";
3272
+ const unchangedSinceSuccess = effectiveSubmitStatus === "success" && submittedSnapshot !== null && JSON.stringify(values) === submittedSnapshot;
3273
+ const submitLocked = showSubmitting || postSuccessCooldown || unchangedSinceSuccess || previewState === "success";
2633
3274
  return /* @__PURE__ */ jsxRuntime.jsxs(
2634
3275
  formik.Form,
2635
- {
3276
+ __spreadProps(__spreadValues({
3277
+ method: "post",
2636
3278
  className: formClasses,
2637
3279
  style: formInlineStyle,
2638
- "data-form-version": definition.version,
3280
+ "data-form-version": definition.version
3281
+ }, darkScopeAttr), {
2639
3282
  children: [
3283
+ darkStyleSheet,
3284
+ onValuesChange && /* @__PURE__ */ jsxRuntime.jsx(ValuesObserver, { onChange: onValuesChange }),
2640
3285
  honeypotEnabled && /* @__PURE__ */ jsxRuntime.jsxs(
2641
3286
  "div",
2642
3287
  {
@@ -2666,7 +3311,7 @@ var DynamicForm = ({
2666
3311
  ]
2667
3312
  }
2668
3313
  ),
2669
- effectiveSubmitStatus === "success" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: bannerWrapperClass, children: /* @__PURE__ */ jsxRuntime.jsx(SuccessBanner, { message: successMessage }) }),
3314
+ effectiveSubmitStatus === "success" && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: bannerRef, className: bannerWrapperClass, children: /* @__PURE__ */ jsxRuntime.jsx(SuccessBanner, { message: successMessage }) }),
2670
3315
  effectiveSubmitStatus === "error" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: bannerWrapperClass, children: /* @__PURE__ */ jsxRuntime.jsx(
2671
3316
  ErrorBanner,
2672
3317
  {
@@ -2680,7 +3325,7 @@ var DynamicForm = ({
2680
3325
  disabled: isDisabled,
2681
3326
  "aria-disabled": isDisabled,
2682
3327
  className: tailwindMerge.twMerge(
2683
- "min-w-0 border-0 p-0",
3328
+ "min-w-0 border-0 bg-inherit p-0",
2684
3329
  isStacked ? "space-y-8" : "",
2685
3330
  isDisabled ? "pointer-events-none opacity-60" : ""
2686
3331
  ),
@@ -2699,7 +3344,7 @@ var DynamicForm = ({
2699
3344
  "aria-busy": showSubmitting,
2700
3345
  children: [
2701
3346
  showSubmitting && /* @__PURE__ */ jsxRuntime.jsx(Spinner, {}),
2702
- showSubmitting ? submittingText : definition.submitConfig.buttonText
3347
+ showSubmitting ? submittingText : unchangedSinceSuccess ? submittedText : definition.submitConfig.buttonText
2703
3348
  ]
2704
3349
  }
2705
3350
  );
@@ -2712,6 +3357,7 @@ var DynamicForm = ({
2712
3357
  section,
2713
3358
  isLast,
2714
3359
  formDefaultTextColor: definition.defaultTextColor,
3360
+ formDefaultTextColorDark: definition.defaultTextColorDark,
2715
3361
  inlineSubmit: inlineButton && isLast ? submitButton : void 0
2716
3362
  },
2717
3363
  section.id
@@ -2723,12 +3369,31 @@ var DynamicForm = ({
2723
3369
  }
2724
3370
  )
2725
3371
  ]
2726
- }
3372
+ })
2727
3373
  );
2728
3374
  }
2729
3375
  }
2730
3376
  ) }) }) });
2731
3377
  };
3378
+ function AdReferralTracker({
3379
+ fallback,
3380
+ cookieName = AD_REFERRAL_COOKIE,
3381
+ ttlDays = AD_REFERRAL_TTL_DAYS
3382
+ } = {}) {
3383
+ react.useEffect(() => {
3384
+ const referral = captureAdReferral(
3385
+ window.location.search,
3386
+ fallback,
3387
+ /* @__PURE__ */ new Date(),
3388
+ window.location.pathname
3389
+ );
3390
+ if (!referral) return;
3391
+ const existing = readAdReferral(cookieName);
3392
+ if (existing && isSameAdReferralTouch(existing, referral)) return;
3393
+ writeAdReferral(referral, cookieName, ttlDays);
3394
+ }, []);
3395
+ return null;
3396
+ }
2732
3397
  function buildQueryString(opts) {
2733
3398
  const params = new URLSearchParams({
2734
3399
  projectId: opts.projectId,
@@ -2990,7 +3655,10 @@ function useDragReorder({
2990
3655
  });
2991
3656
  }
2992
3657
 
3658
+ exports.AD_REFERRAL_COOKIE = AD_REFERRAL_COOKIE;
3659
+ exports.AD_REFERRAL_TTL_DAYS = AD_REFERRAL_TTL_DAYS;
2993
3660
  exports.APPLICATION_STATUS_KEYS = APPLICATION_STATUS_KEYS;
3661
+ exports.AdReferralTracker = AdReferralTracker;
2994
3662
  exports.CORE_EMAIL_TEMPLATE_VARIABLES = CORE_EMAIL_TEMPLATE_VARIABLES;
2995
3663
  exports.DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES = DEFAULT_APPLICATION_STATUS_EMAIL_TEMPLATES;
2996
3664
  exports.DEFAULT_FILE_FIELD_CONFIG = DEFAULT_FILE_FIELD_CONFIG;
@@ -3003,8 +3671,21 @@ exports.DEFAULT_SPAM_PROTECTION = DEFAULT_SPAM_PROTECTION;
3003
3671
  exports.DynamicForm = DynamicForm;
3004
3672
  exports.DynamicFormField = DynamicFormField;
3005
3673
  exports.DynamicFormSection = DynamicFormSection;
3674
+ exports.ENHANCED_CONVERSIONS_GLOBAL = ENHANCED_CONVERSIONS_GLOBAL;
3675
+ exports.FORM_CONVERSION_SEND_TO_GLOBAL = FORM_CONVERSION_SEND_TO_GLOBAL;
3006
3676
  exports.FORM_CSS_VAR = FORM_CSS_VAR;
3677
+ exports.FORM_DARK_SCOPE_ATTR = FORM_DARK_SCOPE_ATTR;
3678
+ exports.FORM_DARK_TEXT_ATTR = FORM_DARK_TEXT_ATTR;
3679
+ exports.FORM_DARK_TEXT_VAR = FORM_DARK_TEXT_VAR;
3007
3680
  exports.FORM_DEFAULT_COLOR = FORM_DEFAULT_COLOR;
3681
+ exports.FORM_DEFAULT_DARK_SELECTOR = FORM_DEFAULT_DARK_SELECTOR;
3682
+ exports.FORM_DEFAULT_RADIUS = FORM_DEFAULT_RADIUS;
3683
+ exports.FORM_GAP_VAR = FORM_GAP_VAR;
3684
+ exports.FORM_RADIUS_VAR = FORM_RADIUS_VAR;
3685
+ exports.FORM_ROOT_BG_VAR = FORM_ROOT_BG_VAR;
3686
+ exports.FORM_STRUCT_VAR = FORM_STRUCT_VAR;
3687
+ exports.FORM_STYLE_COLOR_KEYS = FORM_STYLE_COLOR_KEYS;
3688
+ exports.FORM_SUBMIT_SUCCESS_EVENT = FORM_SUBMIT_SUCCESS_EVENT;
3008
3689
  exports.FORM_VAR = FORM_VAR;
3009
3690
  exports.FileField = FileField;
3010
3691
  exports.FormFileUploadProvider = FormFileUploadProvider;
@@ -3016,26 +3697,49 @@ exports.applyTextTransform = applyTextTransform;
3016
3697
  exports.applyTransform = applyTransform;
3017
3698
  exports.base64ToBuffer = base64ToBuffer;
3018
3699
  exports.bufferToBase64 = bufferToBase64;
3700
+ exports.buildColorVars = buildColorVars;
3701
+ exports.buildDarkSchemeCss = buildDarkSchemeCss;
3019
3702
  exports.buildEmailTemplateVariables = buildEmailTemplateVariables;
3020
3703
  exports.buildFormCssVars = buildFormCssVars;
3704
+ exports.buildFormDarkCssVars = buildFormDarkCssVars;
3021
3705
  exports.buildInitialValues = buildInitialValues;
3706
+ exports.buildUserData = buildUserData;
3022
3707
  exports.buildYupSchema = buildYupSchema;
3708
+ exports.captureAdReferral = captureAdReferral;
3709
+ exports.darkVarName = darkVarName;
3710
+ exports.definitionHasDarkColors = definitionHasDarkColors;
3023
3711
  exports.deriveLast4 = deriveLast4;
3024
3712
  exports.encryptSensitiveValue = encryptSensitiveValue;
3713
+ exports.fireAdsConversion = fireAdsConversion;
3714
+ exports.fireGenerateLead = fireGenerateLead;
3025
3715
  exports.formatSsn = formatSsn;
3026
3716
  exports.formatUsPhone = formatUsPhone;
3027
3717
  exports.getFormDefinition = getFormDefinition;
3028
3718
  exports.getSafeRedirectUrl = getSafeRedirectUrl;
3719
+ exports.hasDarkColors = hasDarkColors;
3720
+ exports.isSameAdReferralTouch = isSameAdReferralTouch;
3029
3721
  exports.isVisibilityConditionMet = isVisibilityConditionMet;
3722
+ exports.newTransactionId = newTransactionId;
3030
3723
  exports.parseFormDefinition = parseFormDefinition;
3724
+ exports.pushFormSubmitSuccess = pushFormSubmitSuccess;
3725
+ exports.readAdReferral = readAdReferral;
3031
3726
  exports.renderEmailTemplate = renderEmailTemplate;
3032
3727
  exports.renderNotificationEmail = renderNotificationEmail;
3033
3728
  exports.resizeImageFile = resizeImageFile;
3729
+ exports.resolveConversionSendTo = resolveConversionSendTo;
3730
+ exports.resolveCustomGap = resolveCustomGap;
3731
+ exports.resolveCustomRadius = resolveCustomRadius;
3732
+ exports.resolveSchemeColors = resolveSchemeColors;
3733
+ exports.resolveSchemeStyle = resolveSchemeStyle;
3734
+ exports.resolveSectionTextColor = resolveSectionTextColor;
3034
3735
  exports.sameAsToggleKey = sameAsToggleKey;
3736
+ exports.toE164 = toE164;
3737
+ exports.trackFormConversion = trackFormConversion;
3035
3738
  exports.useDragReorder = useDragReorder;
3036
3739
  exports.useFormDefinition = useFormDefinition;
3037
3740
  exports.useFormFileUpload = useFormFileUpload;
3038
3741
  exports.useUndoRedo = useUndoRedo;
3039
3742
  exports.useUndoRedoShortcuts = useUndoRedoShortcuts;
3743
+ exports.writeAdReferral = writeAdReferral;
3040
3744
  //# sourceMappingURL=index.js.map
3041
3745
  //# sourceMappingURL=index.js.map