@sawabona/forms 1.0.2 → 1.0.4

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.
@@ -1,296 +1,335 @@
1
- var H = Object.defineProperty, K = Object.defineProperties;
2
- var U = Object.getOwnPropertyDescriptors;
3
- var R = Object.getOwnPropertySymbols;
4
- var P = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable;
5
- var z = (e, i, r) => i in e ? H(e, i, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[i] = r, h = (e, i) => {
6
- for (var r in i || (i = {}))
7
- P.call(i, r) && z(e, r, i[r]);
8
- if (R)
9
- for (var r of R(i))
10
- _.call(i, r) && z(e, r, i[r]);
1
+ var M = Object.defineProperty, U = Object.defineProperties;
2
+ var V = Object.getOwnPropertyDescriptors;
3
+ var B = Object.getOwnPropertySymbols;
4
+ var W = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable;
5
+ var P = (e, n, r) => n in e ? M(e, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[n] = r, a = (e, n) => {
6
+ for (var r in n || (n = {}))
7
+ W.call(n, r) && P(e, r, n[r]);
8
+ if (B)
9
+ for (var r of B(n))
10
+ _.call(n, r) && P(e, r, n[r]);
11
11
  return e;
12
- }, g = (e, i) => K(e, U(i));
13
- var $ = (e) => typeof e == "symbol" ? e : e + "", D = (e, i) => {
12
+ }, S = (e, n) => U(e, V(n));
13
+ var D = (e) => typeof e == "symbol" ? e : e + "", K = (e, n) => {
14
14
  var r = {};
15
15
  for (var t in e)
16
- P.call(e, t) && i.indexOf(t) < 0 && (r[t] = e[t]);
17
- if (e != null && R)
18
- for (var t of R(e))
19
- i.indexOf(t) < 0 && _.call(e, t) && (r[t] = e[t]);
16
+ W.call(e, t) && n.indexOf(t) < 0 && (r[t] = e[t]);
17
+ if (e != null && B)
18
+ for (var t of B(e))
19
+ n.indexOf(t) < 0 && _.call(e, t) && (r[t] = e[t]);
20
20
  return r;
21
21
  };
22
- import { jsxs as u, jsx as n } from "react/jsx-runtime";
23
- import { useState as V, useMemo as W, useCallback as k, createContext as M, useContext as G, useRef as X, useEffect as B } from "react";
24
- import { motion as w, AnimatePresence as J } from "framer-motion";
25
- import { Check as O, Star as Y, ChevronLeft as Z, ChevronRight as q } from "lucide-react";
26
- function ee({ schema: e, onSubmit: i }) {
27
- var N;
28
- const [r, t] = V({
22
+ import { jsxs as f, jsx as i } from "react/jsx-runtime";
23
+ import { useState as G, useMemo as X, useCallback as $, createContext as Z, useContext as J, useRef as Y, useEffect as T } from "react";
24
+ import { motion as b, AnimatePresence as q } from "framer-motion";
25
+ import { Check as O, Star as ee, ChevronLeft as te, ChevronRight as re } from "lucide-react";
26
+ function ne({ schema: e, onSubmit: n }) {
27
+ var d;
28
+ const [r, t] = G({
29
29
  answers: {},
30
- currentStepId: ((N = e.questions[0]) == null ? void 0 : N.id) || "",
30
+ currentStepId: ((d = e.questions[0]) == null ? void 0 : d.id) || "",
31
31
  history: [],
32
32
  isSubmitting: !1,
33
33
  errors: {},
34
34
  isCompleted: !1
35
- }), d = W(
36
- () => e.questions.findIndex((a) => a.id === r.currentStepId),
35
+ }), l = X(
36
+ () => e.questions.findIndex((o) => o.id === r.currentStepId),
37
37
  [e.questions, r.currentStepId]
38
- ), o = e.questions[d], p = k((a, s) => {
39
- t((l) => g(h({}, l), {
40
- answers: g(h({}, l.answers), {
41
- [a]: s
38
+ ), p = e.questions[l], u = $((o, c) => {
39
+ t((m) => S(a({}, m), {
40
+ answers: S(a({}, m.answers), {
41
+ [o]: c
42
42
  }),
43
43
  // Clear error on modification
44
- errors: g(h({}, l.errors), {
45
- [a]: ""
44
+ errors: S(a({}, m.errors), {
45
+ [o]: ""
46
46
  })
47
47
  }));
48
- }, []), c = k((a, s) => {
49
- t((l) => {
50
- if (s === null) {
51
- const F = l.errors, { [a]: j } = F, b = D(F, [$(a)]);
52
- return g(h({}, l), { errors: b });
48
+ }, []), x = $((o, c) => {
49
+ t((m) => {
50
+ if (c === null) {
51
+ const k = m.errors, { [o]: z } = k, L = K(k, [D(o)]);
52
+ return S(a({}, m), { errors: L });
53
53
  }
54
- return g(h({}, l), {
55
- errors: g(h({}, l.errors), { [a]: s })
54
+ return S(a({}, m), {
55
+ errors: S(a({}, m.errors), { [o]: c })
56
56
  });
57
57
  });
58
- }, []), m = k(() => {
59
- var l;
60
- if (!o) return !0;
61
- const a = r.answers[o.id], s = o.validation;
62
- return s && s.required && (a === void 0 || a === "" || Array.isArray(a) && a.length === 0) ? (c(o.id, ((l = e.i18n) == null ? void 0 : l.required) || "This field is required"), !1) : !0;
63
- }, [o, r.answers, c, e.i18n]), f = k((a) => {
64
- const s = e.questions.findIndex((l) => l.id === a.id);
65
- return s < e.questions.length - 1 ? e.questions[s + 1].id : "submit";
66
- }, [e.questions]), x = k(() => {
67
- if (!m()) return;
68
- const a = f(o);
69
- a === "submit" ? (t((s) => g(h({}, s), { isCompleted: !0 })), i == null || i(r.answers)) : t((s) => g(h({}, s), {
70
- history: [...s.history, s.currentStepId],
71
- currentStepId: a
58
+ }, []), g = $(() => {
59
+ var m;
60
+ if (!p) return !0;
61
+ const o = r.answers[p.id], c = p.validation;
62
+ return c && c.required && (o === void 0 || o === "" || Array.isArray(o) && o.length === 0) ? (x(p.id, ((m = e.i18n) == null ? void 0 : m.required) || "This field is required"), !1) : !0;
63
+ }, [p, r.answers, x, e.i18n]), h = $((o) => {
64
+ const c = e.questions.findIndex((m) => m.id === o.id);
65
+ return c < e.questions.length - 1 ? e.questions[c + 1].id : "submit";
66
+ }, [e.questions]), N = $(() => {
67
+ if (!g()) return;
68
+ const o = h(p);
69
+ o === "submit" ? (t((c) => S(a({}, c), { isCompleted: !0 })), n == null || n(r.answers)) : t((c) => S(a({}, c), {
70
+ history: [...c.history, c.currentStepId],
71
+ currentStepId: o
72
72
  }));
73
- }, [o, r.answers, m, f, i]), v = k(() => {
73
+ }, [p, r.answers, g, h, n]), s = $(() => {
74
74
  if (r.history.length === 0) return;
75
- const a = r.history[r.history.length - 1];
76
- t((s) => g(h({}, s), {
77
- history: s.history.slice(0, -1),
78
- currentStepId: a
75
+ const o = r.history[r.history.length - 1];
76
+ t((c) => S(a({}, c), {
77
+ history: c.history.slice(0, -1),
78
+ currentStepId: o
79
79
  }));
80
- }, [r.history]), C = k((a) => {
81
- if (!e.questions.some((l) => l.id === a)) {
82
- console.warn(`Step ${a} does not exist`);
80
+ }, [r.history]), v = $((o) => {
81
+ if (!e.questions.some((m) => m.id === o)) {
82
+ console.warn(`Step ${o} does not exist`);
83
83
  return;
84
84
  }
85
- t((l) => g(h({}, l), {
86
- history: [...l.history, l.currentStepId],
87
- currentStepId: a
85
+ t((m) => S(a({}, m), {
86
+ history: [...m.history, m.currentStepId],
87
+ currentStepId: o
88
88
  }));
89
- }, [e.questions]), I = k(() => {
90
- var a;
89
+ }, [e.questions]), y = $(() => {
90
+ var o;
91
91
  t({
92
92
  answers: {},
93
- currentStepId: ((a = e.questions[0]) == null ? void 0 : a.id) || "",
93
+ currentStepId: ((o = e.questions[0]) == null ? void 0 : o.id) || "",
94
94
  history: [],
95
95
  isSubmitting: !1,
96
96
  errors: {},
97
97
  isCompleted: !1
98
98
  });
99
99
  }, [e.questions]);
100
- return g(h({}, r), {
101
- setAnswer: p,
102
- nextStep: x,
103
- prevStep: v,
104
- jumpToStep: C,
105
- submitForm: () => i == null ? void 0 : i(r.answers),
106
- resetForm: I,
107
- registerError: c,
100
+ return S(a({}, r), {
101
+ setAnswer: u,
102
+ nextStep: N,
103
+ prevStep: s,
104
+ jumpToStep: v,
105
+ submitForm: () => n == null ? void 0 : n(r.answers),
106
+ resetForm: y,
107
+ registerError: x,
108
108
  // Helper to calculate progress
109
- progress: d / e.questions.length * 100
109
+ progress: l / e.questions.length * 100
110
110
  });
111
111
  }
112
- const Q = M(void 0), L = () => {
113
- const e = G(Q);
112
+ const Q = Z(void 0), E = () => {
113
+ const e = J(Q);
114
114
  if (!e)
115
115
  throw new Error("useFormContext must be used within a FormProvider");
116
116
  return e;
117
117
  };
118
- function te({ question: e }) {
119
- var N, a, s, l, F, j;
120
- const { answers: i, setAnswer: r, nextStep: t, schema: d } = L(), o = i[e.id], p = o != null ? String(o) : "", c = X(null), m = d.questions[0].id === e.id, f = !d.disableAutoFocus || !m;
121
- B(() => {
122
- if (f) {
123
- const b = setTimeout(() => {
124
- var y;
125
- (y = c.current) == null || y.focus();
118
+ function ie(e, n, r) {
119
+ if (!e) return "";
120
+ const t = e.replace(/\D/g, "");
121
+ if (n === "phone")
122
+ return t.replace(/(\d{2})(\d)/, "($1) $2").replace(/(\d{4})(\d)/, "$1-$2").slice(0, 14);
123
+ if (n === "cellphone")
124
+ return t.replace(/(\d{2})(\d)/, "($1) $2").replace(/(\d{5})(\d)/, "$1-$2").slice(0, 15);
125
+ if (n === "cpf")
126
+ return t.replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d{1,2})/, "$1-$2").replace(/(-\d{2})\d+?$/, "$1");
127
+ if (n === "cnpj")
128
+ return t.replace(/(\d{2})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1/$2").replace(/(\d{4})(\d)/, "$1-$2").replace(/(-\d{2})\d+?$/, "$1");
129
+ if (n === "cep")
130
+ return t.replace(/(\d{5})(\d)/, "$1-$2").slice(0, 9);
131
+ if (n === "custom" && r) {
132
+ let l = 0;
133
+ return r.replace(/[#X0]/g, () => t[l++] || "").replace(/[^0-9a-zA-Z]+$/, "");
134
+ }
135
+ return e;
136
+ }
137
+ function oe({ question: e }) {
138
+ var d, o, c, m, k, z, L, j;
139
+ const { answers: n, setAnswer: r, nextStep: t, schema: l } = E(), p = n[e.id], u = p != null ? String(p) : "", x = Y(null), g = l.questions[0].id === e.id, h = !l.disableAutoFocus || !g;
140
+ T(() => {
141
+ if (h) {
142
+ const C = setTimeout(() => {
143
+ var w;
144
+ (w = x.current) == null || w.focus();
126
145
  }, 500);
127
- return () => clearTimeout(b);
146
+ return () => clearTimeout(C);
128
147
  }
129
- }, [e.id, f]);
130
- const x = (b) => {
131
- var E;
132
- let y = b.target.value;
133
- const A = ((E = e.validation) == null ? void 0 : E.maxLength) || 2048;
134
- if (y.length > A && (y = y.slice(0, A)), e.type === "number") {
135
- const T = y === "" ? "" : parseFloat(y);
136
- r(e.id, T);
148
+ }, [e.id, h]);
149
+ const N = (C) => {
150
+ var A, R, F;
151
+ let w = C.target.value;
152
+ ((A = e.validation) != null && A.maskType || (R = e.validation) != null && R.mask) && (w = ie(w, e.validation.maskType, e.validation.mask));
153
+ const I = ((F = e.validation) == null ? void 0 : F.maxLength) || 2048;
154
+ if (w.length > I && (w = w.slice(0, I)), e.type === "number") {
155
+ const H = w === "" ? "" : parseFloat(w);
156
+ r(e.id, H);
137
157
  } else
138
- r(e.id, y);
139
- }, v = () => {
140
- var b, y, A, E, T;
141
- if ((b = e.validation) != null && b.required && !p) return !1;
142
- if (p) {
143
- if ((y = e.validation) != null && y.minLength && p.length < e.validation.minLength || e.type === "email" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p)) return !1;
144
- if ((A = e.validation) != null && A.pattern)
158
+ r(e.id, w);
159
+ }, s = () => {
160
+ var C, w, I, A, R;
161
+ if ((C = e.validation) != null && C.required && !u) return !1;
162
+ if (u) {
163
+ if ((w = e.validation) != null && w.minLength && u.length < e.validation.minLength || e.type === "email" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u)) return !1;
164
+ if ((I = e.validation) != null && I.pattern)
145
165
  try {
146
- if (!new RegExp(e.validation.pattern).test(p)) return !1;
147
- } catch (S) {
148
- console.error("Invalid regex pattern in schema", S);
166
+ if (!new RegExp(e.validation.pattern).test(u)) return !1;
167
+ } catch (F) {
168
+ console.error("Invalid regex pattern in schema", F);
149
169
  }
150
170
  if (e.type === "number") {
151
- const S = parseFloat(p);
152
- if (!isNaN(S) && (((E = e.validation) == null ? void 0 : E.min) !== void 0 && S < e.validation.min || ((T = e.validation) == null ? void 0 : T.max) !== void 0 && S > e.validation.max))
171
+ const F = parseFloat(u);
172
+ if (!isNaN(F) && (((A = e.validation) == null ? void 0 : A.min) !== void 0 && F < e.validation.min || ((R = e.validation) == null ? void 0 : R.max) !== void 0 && F > e.validation.max))
153
173
  return !1;
154
174
  }
155
175
  }
156
176
  return !0;
157
- }, C = (b) => {
158
- if (b.key === "Enter" && !b.shiftKey) {
159
- if (b.preventDefault(), !v()) {
160
- const y = document.querySelector(".sawabona-form-container") || document.body;
161
- y.classList.add("shake-animation"), setTimeout(() => y.classList.remove("shake-animation"), 500);
177
+ }, v = (C) => {
178
+ if (C.key === "Enter" && !C.shiftKey) {
179
+ if (C.preventDefault(), !s()) {
180
+ const w = document.querySelector(".sawabona-form-container") || document.body;
181
+ w.classList.add("shake-animation"), setTimeout(() => w.classList.remove("shake-animation"), 500);
162
182
  return;
163
183
  }
164
184
  t();
165
185
  }
166
186
  };
167
- return /* @__PURE__ */ u("div", { className: "w-full relative group", children: [
168
- /* @__PURE__ */ n(
187
+ return /* @__PURE__ */ f("div", { className: "w-full relative group", children: [
188
+ /* @__PURE__ */ i(
169
189
  "input",
170
190
  {
171
- ref: c,
191
+ ref: x,
172
192
  type: e.type,
173
- value: typeof p == "string" || typeof p == "number" ? p : "",
174
- onChange: x,
175
- onKeyDown: C,
193
+ value: typeof u == "string" || typeof u == "number" ? u : "",
194
+ onChange: N,
195
+ onKeyDown: v,
176
196
  placeholder: e.placeholder,
177
- minLength: (N = e.validation) == null ? void 0 : N.minLength,
178
- maxLength: ((a = e.validation) == null ? void 0 : a.maxLength) || 2048,
179
- min: (s = e.validation) == null ? void 0 : s.min,
180
- max: (l = e.validation) == null ? void 0 : l.max,
181
- pattern: (F = e.validation) == null ? void 0 : F.pattern,
197
+ minLength: (d = e.validation) == null ? void 0 : d.minLength,
198
+ maxLength: ((o = e.validation) == null ? void 0 : o.maxLength) || 2048,
199
+ min: (c = e.validation) == null ? void 0 : c.min,
200
+ max: (m = e.validation) == null ? void 0 : m.max,
201
+ pattern: (k = e.validation) == null ? void 0 : k.pattern,
182
202
  className: `
183
203
  w-full bg-transparent border-b-2 border-sw-text-secondary/20
184
204
  py-4 text-2xl md:text-3xl font-medium outline-none transition-colors
185
205
  placeholder:text-sw-text-secondary/30
186
206
  focus:border-sw-primary
187
207
  font-sw-heading
188
- `
208
+ `,
209
+ style: a(a({}, ((z = l.theme) == null ? void 0 : z.labelFont) && { fontFamily: "var(--font-sw-label)" }), ((L = l.theme) == null ? void 0 : L.labelFontSize) && { fontSize: "var(--size-sw-label)" })
189
210
  }
190
211
  ),
191
212
  void 0,
192
- /* @__PURE__ */ n("p", { className: "text-sm opacity-50 mt-4", children: (e.type === "email" || e.type === "text" || e.type === "number" || e.type === "url") && (((j = d.i18n) == null ? void 0 : j.pressEnter) || "Press Enter to continue") })
213
+ /* @__PURE__ */ i("p", { className: "text-sm opacity-50 mt-4", children: (e.type === "email" || e.type === "text" || e.type === "number" || e.type === "url") && (((j = l.i18n) == null ? void 0 : j.pressEnter) || "Press Enter to continue") })
193
214
  ] });
194
215
  }
195
- function re({ question: e }) {
196
- var c;
197
- const { answers: i, setAnswer: r, nextStep: t } = L(), d = i[e.id] || "", o = (m) => {
198
- r(e.id, m), setTimeout(() => t(), 400);
199
- }, p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
200
- return B(() => {
201
- const m = (f) => {
202
- var C;
203
- const x = f.key.toUpperCase(), v = p.indexOf(x);
204
- v >= 0 && v < (((C = e.options) == null ? void 0 : C.length) || 0) && o(e.options[v].value);
216
+ function ae({ question: e }) {
217
+ var N;
218
+ const { answers: n, setAnswer: r, nextStep: t, schema: l } = E(), p = e.type === "multi-select" || e.multiple, u = n[e.id], x = p ? Array.isArray(u) ? u : u !== void 0 ? [u] : [] : u || "", g = (s) => {
219
+ if (p) {
220
+ const v = x, y = v.includes(s);
221
+ let d;
222
+ y ? d = v.filter((o) => o !== s) : d = [...v, s], r(e.id, d);
223
+ } else
224
+ r(e.id, s), setTimeout(() => t(), 400);
225
+ }, h = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
226
+ return T(() => {
227
+ const s = (v) => {
228
+ var o;
229
+ const y = v.key.toUpperCase(), d = h.indexOf(y);
230
+ d >= 0 && d < (((o = e.options) == null ? void 0 : o.length) || 0) && g(e.options[d].value);
205
231
  };
206
- return window.addEventListener("keydown", m), () => window.removeEventListener("keydown", m);
207
- }, [e.options, e.id]), /* @__PURE__ */ n("div", { className: "flex flex-col gap-3 w-full max-w-xl", children: (c = e.options) == null ? void 0 : c.map((m, f) => {
208
- const x = Array.isArray(d) ? d.includes(m.value) : d === m.value;
209
- return /* @__PURE__ */ u(
210
- w.button,
232
+ return window.addEventListener("keydown", s), () => window.removeEventListener("keydown", s);
233
+ }, [e.options, e.id]), /* @__PURE__ */ i("div", { className: "flex flex-col gap-3 w-full max-w-xl", style: { gap: "var(--sw-option-gap, 0.75rem)" }, children: (N = e.options) == null ? void 0 : N.map((s, v) => {
234
+ var d, o, c, m, k, z;
235
+ const y = p ? x.includes(s.value) : x === s.value;
236
+ return /* @__PURE__ */ f(
237
+ b.button,
211
238
  {
212
239
  initial: { opacity: 0, y: 10 },
213
240
  animate: { opacity: 1, y: 0 },
214
- transition: { delay: f * 0.05 },
215
- onClick: () => o(m.value),
241
+ transition: { delay: v * 0.05 },
242
+ onClick: () => g(s.value),
216
243
  className: `
217
244
  w-full text-left p-4 rounded-lg border-2 transition-all duration-200
218
245
  flex items-center justify-between group
219
- ${x ? "border-sw-primary bg-sw-primary/5 text-sw-primary" : "border-sw-text-secondary/10 hover:border-sw-primary/50 hover:bg-sw-primary/5"}
246
+ ${y ? "border-sw-primary bg-sw-primary/5 text-sw-primary" : "border-sw-text-secondary/10 hover:border-sw-primary/50 hover:bg-sw-primary/5"}
220
247
  `,
248
+ style: a({
249
+ padding: "var(--sw-option-padding, 1rem)",
250
+ borderRadius: "var(--sw-option-radius, 0.5rem)",
251
+ borderWidth: "var(--sw-option-border, 2px)"
252
+ }, y && ((d = l.theme) != null && d.optionActiveColor) ? {
253
+ borderColor: "var(--sw-option-active)"
254
+ } : {}),
221
255
  children: [
222
- /* @__PURE__ */ u("span", { className: "text-lg font-medium flex items-center gap-3", children: [
223
- /* @__PURE__ */ n("span", { className: `
224
- w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
225
- ${x ? "border-sw-primary bg-sw-primary" : "border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
226
- `, children: x && /* @__PURE__ */ n(O, { size: 14, className: "text-sw-background" }) }),
227
- m.label
256
+ /* @__PURE__ */ f("span", { className: "text-lg font-medium flex items-center gap-3", style: a(a({}, ((o = l.theme) == null ? void 0 : o.labelFont) && { fontFamily: "var(--font-sw-label)" }), ((c = l.theme) == null ? void 0 : c.labelFontSize) && { fontSize: "var(--size-sw-label)" }), children: [
257
+ /* @__PURE__ */ i("span", { className: `
258
+ flex-shrink-0 w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
259
+ ${y ? "border-sw-primary bg-sw-primary" : "border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
260
+ `, style: a({}, y && ((m = l.theme) != null && m.optionActiveColor) ? {
261
+ borderColor: "var(--sw-option-active)",
262
+ backgroundColor: "var(--sw-option-active)"
263
+ } : {}), children: y && /* @__PURE__ */ i(O, { size: 14, className: "text-sw-background" }) }),
264
+ s.label
228
265
  ] }),
229
- /* @__PURE__ */ u("span", { className: "opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50", children: [
230
- "Select ",
231
- /* @__PURE__ */ u("span", { className: "hidden md:inline", children: [
266
+ !((k = l.i18n) != null && k.hideSelectText) && /* @__PURE__ */ f("span", { className: "opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50", children: [
267
+ ((z = l.i18n) == null ? void 0 : z.selectKey) || "Select",
268
+ " ",
269
+ /* @__PURE__ */ f("span", { className: "hidden md:inline", children: [
232
270
  "Key ",
233
- f + 1
271
+ v + 1
234
272
  ] })
235
273
  ] })
236
274
  ]
237
275
  },
238
- String(m.value)
276
+ String(s.value)
239
277
  );
240
278
  }) });
241
279
  }
242
- function ne({ question: e }) {
243
- var o;
244
- const { answers: i, setAnswer: r } = L(), t = i[e.id] || 0, d = Math.min(((o = e.validation) == null ? void 0 : o.max) || 5, 20);
245
- return /* @__PURE__ */ u("div", { className: "flex flex-col gap-6", children: [
246
- /* @__PURE__ */ n("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length: d }).map((p, c) => {
247
- const m = c + 1, f = m <= t;
248
- return /* @__PURE__ */ n(
249
- w.button,
280
+ function le({ question: e }) {
281
+ var p;
282
+ const { answers: n, setAnswer: r } = E(), t = n[e.id] || 0, l = Math.min(((p = e.validation) == null ? void 0 : p.max) || 5, 20);
283
+ return /* @__PURE__ */ f("div", { className: "flex flex-col gap-6", children: [
284
+ /* @__PURE__ */ i("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length: l }).map((u, x) => {
285
+ const g = x + 1, h = g <= t;
286
+ return /* @__PURE__ */ i(
287
+ b.button,
250
288
  {
251
289
  initial: { opacity: 0, scale: 0 },
252
290
  animate: { opacity: 1, scale: 1 },
253
- transition: { delay: c * 0.05 },
254
- onClick: () => r(e.id, m),
291
+ transition: { delay: x * 0.05 },
292
+ onClick: () => r(e.id, g),
255
293
  whileHover: { scale: 1.2, rotate: 5 },
256
294
  whileTap: { scale: 0.9 },
257
295
  className: "focus:outline-none",
258
- children: /* @__PURE__ */ n(
259
- Y,
296
+ children: /* @__PURE__ */ i(
297
+ ee,
260
298
  {
261
- className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${f ? "fill-yellow-400 text-yellow-400 drop-shadow-[0_0_15px_rgba(250,204,21,0.4)]" : "text-zinc-600 hover:text-yellow-400/50"}`,
299
+ className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${h ? "fill-yellow-400 text-yellow-400 drop-shadow-[0_0_15px_rgba(250,204,21,0.4)]" : "text-zinc-600 hover:text-yellow-400/50"}`,
262
300
  strokeWidth: 1.5
263
301
  }
264
302
  )
265
303
  },
266
- c
304
+ x
267
305
  );
268
306
  }) }),
269
- /* @__PURE__ */ u("div", { className: "flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center", children: [
270
- /* @__PURE__ */ n("span", { className: "text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide", children: e.minLabel || "Poor" }),
271
- /* @__PURE__ */ n(
272
- w.div,
307
+ /* @__PURE__ */ f("div", { className: "flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center", children: [
308
+ /* @__PURE__ */ i("span", { className: "text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide", children: e.minLabel || "Poor" }),
309
+ /* @__PURE__ */ i(
310
+ b.div,
273
311
  {
274
312
  initial: { opacity: 0, scale: 0.8 },
275
313
  animate: { opacity: t ? 1 : 0, scale: t ? 1 : 0.8 },
276
314
  className: "font-bold text-primary text-xl",
277
- children: t ? `${t} / ${d}` : ""
315
+ children: t ? `${t} / ${l}` : ""
278
316
  }
279
317
  ),
280
- /* @__PURE__ */ n("span", { className: "text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide", children: e.maxLabel || "Excellent" })
318
+ /* @__PURE__ */ i("span", { className: "text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide", children: e.maxLabel || "Excellent" })
281
319
  ] })
282
320
  ] });
283
321
  }
284
- function ie({ question: e }) {
285
- const { schema: i } = L(), r = i.questions.findIndex((c) => c.id === e.id) + 1, t = i.questions.length, d = {
322
+ function se({ question: e }) {
323
+ var x, g, h, N;
324
+ const { schema: n } = E(), r = n.questions.findIndex((s) => s.id === e.id) + 1, t = n.questions.length, l = {
286
325
  hidden: { opacity: 0, y: 20 },
287
326
  visible: { opacity: 1, y: 0, transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] } }
288
- }, o = (c) => c && c.replace(/\{\{(\w+)\}\}/g, (m, f) => {
289
- const x = p.answers[f];
290
- return x != null ? String(x) : "";
291
- }), p = L();
292
- return /* @__PURE__ */ u(
293
- w.div,
327
+ }, p = (s) => s && s.replace(/\{\{(\w+)\}\}/g, (v, y) => {
328
+ const d = u.answers[y];
329
+ return d != null ? String(d) : "";
330
+ }), u = E();
331
+ return /* @__PURE__ */ f(
332
+ b.div,
294
333
  {
295
334
  className: "flex flex-col gap-8 w-full max-w-4xl mx-auto",
296
335
  initial: "hidden",
@@ -299,34 +338,36 @@ function ie({ question: e }) {
299
338
  visible: { transition: { staggerChildren: 0.1 } }
300
339
  },
301
340
  children: [
302
- /* @__PURE__ */ u("div", { className: "flex flex-col gap-2", children: [
303
- /* @__PURE__ */ n(w.div, { variants: d, className: "flex gap-4 items-baseline", children: /* @__PURE__ */ u("span", { className: "flex items-center gap-2 text-sm md:text-base font-medium text-sw-primary/90 bg-sw-primary/10 px-3 py-1 rounded-full border border-sw-primary/20 backdrop-blur-sm", children: [
304
- /* @__PURE__ */ n("span", { children: r }),
305
- /* @__PURE__ */ n("span", { className: "opacity-40 text-xs", children: "/" }),
306
- /* @__PURE__ */ n("span", { className: "opacity-60", children: t })
341
+ /* @__PURE__ */ f("div", { className: "flex flex-col gap-2", children: [
342
+ /* @__PURE__ */ i(b.div, { variants: l, className: "flex gap-4 items-baseline", children: /* @__PURE__ */ f("span", { className: "flex items-center gap-2 text-sm md:text-base font-medium text-sw-primary/90 bg-sw-primary/10 px-3 py-1 rounded-full border border-sw-primary/20 backdrop-blur-sm", children: [
343
+ /* @__PURE__ */ i("span", { children: r }),
344
+ /* @__PURE__ */ i("span", { className: "opacity-40 text-xs", children: "/" }),
345
+ /* @__PURE__ */ i("span", { className: "opacity-60", children: t })
307
346
  ] }) }),
308
- /* @__PURE__ */ u(
309
- w.h2,
347
+ /* @__PURE__ */ f(
348
+ b.h2,
310
349
  {
311
- variants: d,
350
+ variants: l,
312
351
  className: "text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",
352
+ style: a(a({}, ((x = n.theme) == null ? void 0 : x.titleFont) && { fontFamily: "var(--font-sw-title)" }), ((g = n.theme) == null ? void 0 : g.titleFontSize) && { fontSize: "var(--size-sw-title)" }),
313
353
  children: [
314
- o(e.title),
354
+ p(e.title),
315
355
  " ",
316
- /* @__PURE__ */ n("span", { className: "text-sw-primary", children: "*" })
356
+ /* @__PURE__ */ i("span", { className: "text-sw-primary", children: "*" })
317
357
  ]
318
358
  }
319
359
  ),
320
- e.description && /* @__PURE__ */ n(
321
- w.p,
360
+ e.description && /* @__PURE__ */ i(
361
+ b.p,
322
362
  {
323
- variants: d,
363
+ variants: l,
324
364
  className: "text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",
325
- children: o(e.description)
365
+ style: a(a({}, ((h = n.theme) == null ? void 0 : h.descriptionFont) && { fontFamily: "var(--font-sw-description)" }), ((N = n.theme) == null ? void 0 : N.descriptionFontSize) && { fontSize: "var(--size-sw-description)" }),
366
+ children: p(e.description)
326
367
  }
327
368
  )
328
369
  ] }),
329
- /* @__PURE__ */ n(w.div, { variants: d, className: "w-full mt-6", children: e.type === "text" || e.type === "email" || e.type === "number" || e.type === "url" ? /* @__PURE__ */ n(te, { question: e }) : e.type === "select" ? /* @__PURE__ */ n(re, { question: e }) : e.type === "rating" ? /* @__PURE__ */ n(ne, { question: e }) : /* @__PURE__ */ u("div", { className: "p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded", children: [
370
+ /* @__PURE__ */ i(b.div, { variants: l, className: "w-full mt-6", children: e.type === "text" || e.type === "email" || e.type === "number" || e.type === "url" ? /* @__PURE__ */ i(oe, { question: e }) : e.type === "select" || e.type === "multi-select" ? /* @__PURE__ */ i(ae, { question: e }) : e.type === "rating" ? /* @__PURE__ */ i(le, { question: e }) : /* @__PURE__ */ f("div", { className: "p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded", children: [
330
371
  "Unsupported question type: ",
331
372
  e.type,
332
373
  " (ID: ",
@@ -337,7 +378,7 @@ function ie({ question: e }) {
337
378
  }
338
379
  );
339
380
  }
340
- const ae = {
381
+ const de = {
341
382
  next: "Next",
342
383
  back: "Back",
343
384
  submit: "Submit",
@@ -345,16 +386,16 @@ const ae = {
345
386
  optional: "Optional",
346
387
  stepInfo: "Question {{current}} of {{total}}"
347
388
  };
348
- function me({ schema: e, onSubmit: i }) {
349
- var I;
350
- const r = ee({ schema: e, onSubmit: i }), t = e.theme || {
389
+ function xe({ schema: e, onSubmit: n }) {
390
+ var y;
391
+ const r = ne({ schema: e, onSubmit: n }), t = e.theme || {
351
392
  backgroundColor: "#ffffff",
352
393
  textColor: "#000000",
353
394
  // Start with generic defaults, override in usage
354
395
  primaryColor: "#000000",
355
396
  borderRadius: "8px"
356
397
  // fontFamily removed to allow inheritance
357
- }, d = h(h({}, ae), e.i18n), o = {
398
+ }, l = a(a({}, de), e.i18n), p = a(a(a(a(a(a(a(a(a(a(a({
358
399
  backgroundColor: t.backgroundColor,
359
400
  color: t.textColor,
360
401
  fontFamily: t.fontFamily,
@@ -365,91 +406,91 @@ function me({ schema: e, onSubmit: i }) {
365
406
  "--color-sw-text-secondary": t.textColor,
366
407
  "--font-sw-heading": t.fontFamily || "inherit",
367
408
  "--font-sw-body": t.fontFamily || "inherit"
368
- }, p = t.buttonVariant === "outline", c = {
369
- backgroundColor: p ? "transparent" : t.primaryColor,
370
- color: p ? t.primaryColor : t.textColor,
371
- border: p ? `2px solid ${t.primaryColor}` : "none",
409
+ }, t.titleFont && { "--font-sw-title": t.titleFont }), t.descriptionFont && { "--font-sw-description": t.descriptionFont }), t.labelFont && { "--font-sw-label": t.labelFont }), t.titleFontSize && { "--size-sw-title": t.titleFontSize }), t.descriptionFontSize && { "--size-sw-description": t.descriptionFontSize }), t.labelFontSize && { "--size-sw-label": t.labelFontSize }), t.optionPadding && { "--sw-option-padding": t.optionPadding }), t.optionBorderRadius && { "--sw-option-radius": t.optionBorderRadius }), t.optionBorderWidth && { "--sw-option-border": t.optionBorderWidth }), t.optionGap && { "--sw-option-gap": t.optionGap }), t.optionActiveColor && { "--sw-option-active": t.optionActiveColor }), u = t.buttonVariant === "outline", x = {
410
+ backgroundColor: u ? "transparent" : t.primaryColor,
411
+ color: u ? t.primaryColor : t.textColor,
412
+ border: u ? `2px solid ${t.primaryColor}` : "none",
372
413
  borderRadius: t.borderRadius || "8px",
373
414
  fontWeight: 600
374
- }, m = {
415
+ }, g = {
375
416
  color: t.primaryColor,
376
417
  borderRadius: t.borderRadius || "8px",
377
418
  fontWeight: 600
378
- }, { autoReload: f, reloadDelay: x = 3e3 } = e;
379
- if (B(() => {
380
- if (r.isCompleted && f) {
381
- const N = setTimeout(() => {
419
+ }, { autoReload: h, reloadDelay: N = 3e3 } = e;
420
+ if (T(() => {
421
+ if (r.isCompleted && h) {
422
+ const d = setTimeout(() => {
382
423
  r.resetForm();
383
- }, x);
384
- return () => clearTimeout(N);
424
+ }, N);
425
+ return () => clearTimeout(d);
385
426
  }
386
- }, [r.isCompleted, f, x, r.resetForm]), r.isCompleted)
387
- return /* @__PURE__ */ u(
427
+ }, [r.isCompleted, h, N, r.resetForm]), r.isCompleted)
428
+ return /* @__PURE__ */ f(
388
429
  "div",
389
430
  {
390
431
  className: "flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",
391
- style: o,
432
+ style: p,
392
433
  children: [
393
- f && /* @__PURE__ */ n(
394
- w.div,
434
+ h && /* @__PURE__ */ i(
435
+ b.div,
395
436
  {
396
437
  initial: { width: "0%" },
397
438
  animate: { width: "100%" },
398
- transition: { duration: x / 1e3, ease: "linear" },
439
+ transition: { duration: N / 1e3, ease: "linear" },
399
440
  className: "absolute top-0 left-0 h-1 bg-green-500 z-50"
400
441
  }
401
442
  ),
402
- /* @__PURE__ */ u(
403
- w.div,
443
+ /* @__PURE__ */ f(
444
+ b.div,
404
445
  {
405
446
  initial: { scale: 0.9, opacity: 0, y: 20 },
406
447
  animate: { scale: 1, opacity: 1, y: 0 },
407
448
  transition: { duration: 0.6, ease: [0.22, 1, 0.36, 1] },
408
449
  className: "flex flex-col items-center",
409
450
  children: [
410
- /* @__PURE__ */ n("div", { className: "mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center", children: /* @__PURE__ */ n(O, { size: 48 }) }),
411
- /* @__PURE__ */ n("h1", { className: "text-4xl md:text-5xl font-bold mb-4 tracking-tight", children: "Obrigado!" }),
412
- /* @__PURE__ */ n("p", { className: "text-xl opacity-70 max-w-md leading-relaxed", children: "Suas respostas foram enviadas com sucesso." })
451
+ /* @__PURE__ */ i("div", { className: "mb-6 p-4 rounded-full bg-green-500/20 text-green-500 w-24 h-24 flex items-center justify-center", children: /* @__PURE__ */ i(O, { size: 48 }) }),
452
+ /* @__PURE__ */ i("h1", { className: "text-4xl md:text-5xl font-bold mb-4 tracking-tight", children: "Obrigado!" }),
453
+ /* @__PURE__ */ i("p", { className: "text-xl opacity-70 max-w-md leading-relaxed", children: "Suas respostas foram enviadas com sucesso." })
413
454
  ]
414
455
  }
415
456
  )
416
457
  ]
417
458
  }
418
459
  );
419
- const v = e.questions.find((N) => N.id === r.currentStepId), C = (e.questions.findIndex((N) => N.id === r.currentStepId) + 1) / e.questions.length * 100;
420
- return /* @__PURE__ */ n(Q.Provider, { value: g(h({}, r), { schema: e }), children: /* @__PURE__ */ u(
460
+ const s = e.questions.find((d) => d.id === r.currentStepId), v = (e.questions.findIndex((d) => d.id === r.currentStepId) + 1) / e.questions.length * 100;
461
+ return /* @__PURE__ */ i(Q.Provider, { value: S(a({}, r), { schema: e }), children: /* @__PURE__ */ f(
421
462
  "div",
422
463
  {
423
464
  className: "w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",
424
- style: o,
465
+ style: p,
425
466
  children: [
426
- /* @__PURE__ */ u("div", { className: "absolute top-0 left-0 w-full h-1 z-50", children: [
427
- /* @__PURE__ */ n("div", { className: "absolute top-0 left-0 w-full h-full bg-current opacity-10" }),
428
- /* @__PURE__ */ n(
429
- w.div,
467
+ /* @__PURE__ */ f("div", { className: "absolute top-0 left-0 w-full h-1 z-50", children: [
468
+ /* @__PURE__ */ i("div", { className: "absolute top-0 left-0 w-full h-full bg-current opacity-10" }),
469
+ /* @__PURE__ */ i(
470
+ b.div,
430
471
  {
431
472
  className: "h-full relative z-10",
432
473
  initial: { width: 0 },
433
- animate: { width: `${C}%` },
474
+ animate: { width: `${v}%` },
434
475
  transition: { duration: 0.5, ease: "easeInOut" },
435
476
  style: { backgroundColor: t.primaryColor }
436
477
  }
437
478
  )
438
479
  ] }),
439
- /* @__PURE__ */ n("div", { className: "flex-1 flex flex-col items-center justify-center p-6 md:p-12 w-full max-w-5xl mx-auto z-10", children: /* @__PURE__ */ n(J, { mode: "wait", children: v && /* @__PURE__ */ n(
440
- w.div,
480
+ /* @__PURE__ */ i("div", { className: "flex-1 flex flex-col items-center justify-center relative w-full pt-10 pb-6 px-6 md:px-12 z-10 overflow-y-auto", children: /* @__PURE__ */ i("div", { className: "w-full max-w-5xl mx-auto my-auto flex flex-col justify-center", children: /* @__PURE__ */ i(q, { mode: "wait", children: s && /* @__PURE__ */ i(
481
+ b.div,
441
482
  {
442
483
  initial: { opacity: 0, y: 40 },
443
484
  animate: { opacity: 1, y: 0 },
444
485
  exit: { opacity: 0, y: -40 },
445
486
  transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },
446
- className: "w-full",
447
- children: /* @__PURE__ */ n(ie, { question: v })
487
+ className: "w-full py-8",
488
+ children: /* @__PURE__ */ i(se, { question: s })
448
489
  },
449
- v.id
450
- ) }) }),
451
- /* @__PURE__ */ u("div", { className: "w-full px-6 pt-6 pb-8 md:p-10 flex flex-col md:flex-row justify-between items-center z-20 gap-4", children: [
452
- t.showPoweredBy !== !1 && /* @__PURE__ */ u(
490
+ s.id
491
+ ) }) }) }),
492
+ /* @__PURE__ */ f("div", { className: "w-full px-6 pt-6 pb-8 md:p-10 flex flex-col md:flex-row justify-between items-center z-20 gap-4", children: [
493
+ t.showPoweredBy !== !1 && /* @__PURE__ */ f(
453
494
  "a",
454
495
  {
455
496
  href: t.poweredByUrl || "#",
@@ -457,42 +498,42 @@ function me({ schema: e, onSubmit: i }) {
457
498
  rel: t.poweredByUrl ? "noopener noreferrer" : void 0,
458
499
  className: "order-3 md:order-1 group flex items-center gap-2 px-3 py-1.5 rounded-md border border-white/10 bg-black/20 hover:border-sw-primary/50 hover:bg-black/40 transition-all duration-300 cursor-pointer no-underline backdrop-blur-sm",
459
500
  children: [
460
- /* @__PURE__ */ n("span", { className: "text-[10px] md:text-xs font-mono font-medium tracking-[0.2em] uppercase text-muted-foreground group-hover:text-muted-foreground/80 transition-colors", children: "Powered By" }),
461
- /* @__PURE__ */ n(
501
+ /* @__PURE__ */ i("span", { className: "text-[10px] md:text-xs font-mono font-medium tracking-[0.2em] uppercase text-muted-foreground group-hover:text-muted-foreground/80 transition-colors", children: "Powered By" }),
502
+ /* @__PURE__ */ i(
462
503
  "span",
463
504
  {
464
505
  className: "text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",
465
506
  style: { color: t.brandColor || t.primaryColor },
466
- children: ((I = t.poweredBy) == null ? void 0 : I.replace("Powered by ", "")) || "SAWABONA TECH"
507
+ children: ((y = t.poweredBy) == null ? void 0 : y.replace("Powered by ", "")) || "SAWABONA TECH"
467
508
  }
468
509
  )
469
510
  ]
470
511
  }
471
512
  ),
472
- /* @__PURE__ */ u("div", { className: "flex items-center gap-4 order-2 md:order-3 ml-auto", children: [
473
- /* @__PURE__ */ n(
474
- w.button,
513
+ /* @__PURE__ */ f("div", { className: "flex items-center gap-4 order-2 md:order-3 ml-auto", children: [
514
+ /* @__PURE__ */ i(
515
+ b.button,
475
516
  {
476
517
  onClick: r.prevStep,
477
518
  disabled: r.history.length === 0,
478
519
  whileHover: { scale: 1.05 },
479
520
  whileTap: { scale: 0.95 },
480
521
  className: "w-12 h-12 md:w-14 md:h-14 flex items-center justify-center disabled:opacity-0 disabled:pointer-events-none transition-all hover:bg-white/5 rounded-full",
481
- style: m,
482
- children: /* @__PURE__ */ n(Z, { size: 24 })
522
+ style: g,
523
+ children: /* @__PURE__ */ i(te, { size: 24 })
483
524
  }
484
525
  ),
485
- /* @__PURE__ */ u(
486
- w.button,
526
+ /* @__PURE__ */ f(
527
+ b.button,
487
528
  {
488
529
  onClick: r.nextStep,
489
530
  whileHover: { scale: 1.02 },
490
531
  whileTap: { scale: 0.98 },
491
532
  className: "px-8 py-3 md:px-10 md:py-4 text-lg font-bold shadow-2xl flex items-center gap-3 transition-all rounded-lg",
492
- style: c,
533
+ style: x,
493
534
  children: [
494
- /* @__PURE__ */ n("span", { children: r.currentStepId === e.questions[e.questions.length - 1].id ? t.submitText || d.submit : d.next }),
495
- r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */ n(q, { size: 20, strokeWidth: 3 })
535
+ /* @__PURE__ */ i("span", { children: r.currentStepId === e.questions[e.questions.length - 1].id ? t.submitText || l.submit : l.next }),
536
+ r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */ i(re, { size: 20, strokeWidth: 3 })
496
537
  ]
497
538
  }
498
539
  )
@@ -503,5 +544,5 @@ function me({ schema: e, onSubmit: i }) {
503
544
  ) });
504
545
  }
505
546
  export {
506
- me as FormRenderer
547
+ xe as FormRenderer
507
548
  };