@sawabona/forms 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,92 +1,92 @@
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 H = Object.defineProperty, U = Object.defineProperties;
2
+ var M = Object.getOwnPropertyDescriptors;
3
+ var L = Object.getOwnPropertySymbols;
4
+ var W = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable;
5
+ var P = (e, n, r) => n in e ? H(e, n, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[n] = r, o = (e, n) => {
6
+ for (var r in n || (n = {}))
7
+ W.call(n, r) && P(e, r, n[r]);
8
+ if (L)
9
+ for (var r of L(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
+ }, N = (e, n) => U(e, M(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 && L)
18
+ for (var t of L(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 k, 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 x;
28
+ const [r, t] = G({
29
29
  answers: {},
30
- currentStepId: ((N = e.questions[0]) == null ? void 0 : N.id) || "",
30
+ currentStepId: ((x = e.questions[0]) == null ? void 0 : x.id) || "",
31
31
  history: [],
32
32
  isSubmitting: !1,
33
33
  errors: {},
34
34
  isCompleted: !1
35
- }), d = W(
35
+ }), l = X(
36
36
  () => e.questions.findIndex((a) => a.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), {
38
+ ), d = e.questions[l], m = k((a, s) => {
39
+ t((p) => N(o({}, p), {
40
+ answers: N(o({}, p.answers), {
41
41
  [a]: s
42
42
  }),
43
43
  // Clear error on modification
44
- errors: g(h({}, l.errors), {
44
+ errors: N(o({}, p.errors), {
45
45
  [a]: ""
46
46
  })
47
47
  }));
48
- }, []), c = k((a, s) => {
49
- t((l) => {
48
+ }, []), y = k((a, s) => {
49
+ t((p) => {
50
50
  if (s === null) {
51
- const F = l.errors, { [a]: j } = F, b = D(F, [$(a)]);
52
- return g(h({}, l), { errors: b });
51
+ const $ = p.errors, { [a]: B } = $, E = K($, [D(a)]);
52
+ return N(o({}, p), { errors: E });
53
53
  }
54
- return g(h({}, l), {
55
- errors: g(h({}, l.errors), { [a]: s })
54
+ return N(o({}, p), {
55
+ errors: N(o({}, p.errors), { [a]: s })
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);
58
+ }, []), h = k(() => {
59
+ var p;
60
+ if (!d) return !0;
61
+ const a = r.answers[d.id], s = d.validation;
62
+ return s && s.required && (a === void 0 || a === "" || Array.isArray(a) && a.length === 0) ? (y(d.id, ((p = e.i18n) == null ? void 0 : p.required) || "This field is required"), !1) : !0;
63
+ }, [d, r.answers, y, e.i18n]), c = k((a) => {
64
+ const s = e.questions.findIndex((p) => p.id === a.id);
65
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), {
66
+ }, [e.questions]), g = k(() => {
67
+ if (!h()) return;
68
+ const a = c(d);
69
+ a === "submit" ? (t((s) => N(o({}, s), { isCompleted: !0 })), n == null || n(r.answers)) : t((s) => N(o({}, s), {
70
70
  history: [...s.history, s.currentStepId],
71
71
  currentStepId: a
72
72
  }));
73
- }, [o, r.answers, m, f, i]), v = k(() => {
73
+ }, [d, r.answers, h, c, n]), u = k(() => {
74
74
  if (r.history.length === 0) return;
75
75
  const a = r.history[r.history.length - 1];
76
- t((s) => g(h({}, s), {
76
+ t((s) => N(o({}, s), {
77
77
  history: s.history.slice(0, -1),
78
78
  currentStepId: a
79
79
  }));
80
- }, [r.history]), C = k((a) => {
81
- if (!e.questions.some((l) => l.id === a)) {
80
+ }, [r.history]), v = k((a) => {
81
+ if (!e.questions.some((p) => p.id === a)) {
82
82
  console.warn(`Step ${a} does not exist`);
83
83
  return;
84
84
  }
85
- t((l) => g(h({}, l), {
86
- history: [...l.history, l.currentStepId],
85
+ t((p) => N(o({}, p), {
86
+ history: [...p.history, p.currentStepId],
87
87
  currentStepId: a
88
88
  }));
89
- }, [e.questions]), I = k(() => {
89
+ }, [e.questions]), C = k(() => {
90
90
  var a;
91
91
  t({
92
92
  answers: {},
@@ -97,200 +97,234 @@ function ee({ schema: e, onSubmit: i }) {
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 N(o({}, r), {
101
+ setAnswer: m,
102
+ nextStep: g,
103
+ prevStep: u,
104
+ jumpToStep: v,
105
+ submitForm: () => n == null ? void 0 : n(r.answers),
106
+ resetForm: C,
107
+ registerError: y,
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), R = () => {
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 x, a, s, p, $, B, E, j;
139
+ const { answers: n, setAnswer: r, nextStep: t, schema: l } = R(), d = n[e.id], m = d != null ? String(d) : "", y = Y(null), h = l.questions[0].id === e.id, c = !l.disableAutoFocus || !h;
140
+ T(() => {
141
+ if (c) {
142
+ const S = setTimeout(() => {
143
+ var w;
144
+ (w = y.current) == null || w.focus();
126
145
  }, 500);
127
- return () => clearTimeout(b);
146
+ return () => clearTimeout(S);
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, c]);
149
+ const g = (S) => {
150
+ var I, A, F;
151
+ let w = S.target.value;
152
+ ((I = e.validation) != null && I.maskType || (A = e.validation) != null && A.mask) && (w = ie(w, e.validation.maskType, e.validation.mask));
153
+ const z = ((F = e.validation) == null ? void 0 : F.maxLength) || 2048;
154
+ if (w.length > z && (w = w.slice(0, z)), e.type === "number") {
155
+ const V = w === "" ? "" : parseFloat(w);
156
+ r(e.id, V);
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
+ }, u = () => {
160
+ var S, w, z, I, A;
161
+ if ((S = e.validation) != null && S.required && !m) return !1;
162
+ if (m) {
163
+ if ((w = e.validation) != null && w.minLength && m.length < e.validation.minLength || e.type === "email" && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m)) return !1;
164
+ if ((z = e.validation) != null && z.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(m)) 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(m);
172
+ if (!isNaN(F) && (((I = e.validation) == null ? void 0 : I.min) !== void 0 && F < e.validation.min || ((A = e.validation) == null ? void 0 : A.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 = (S) => {
178
+ if (S.key === "Enter" && !S.shiftKey) {
179
+ if (S.preventDefault(), !u()) {
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: y,
172
192
  type: e.type,
173
- value: typeof p == "string" || typeof p == "number" ? p : "",
174
- onChange: x,
175
- onKeyDown: C,
193
+ value: typeof m == "string" || typeof m == "number" ? m : "",
194
+ onChange: g,
195
+ onKeyDown: v,
176
196
  placeholder: e.placeholder,
177
- minLength: (N = e.validation) == null ? void 0 : N.minLength,
197
+ minLength: (x = e.validation) == null ? void 0 : x.minLength,
178
198
  maxLength: ((a = e.validation) == null ? void 0 : a.maxLength) || 2048,
179
199
  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,
200
+ max: (p = e.validation) == null ? void 0 : p.max,
201
+ pattern: ($ = e.validation) == null ? void 0 : $.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: o(o({}, ((B = l.theme) == null ? void 0 : B.labelFont) && { fontFamily: "var(--font-sw-label)" }), ((E = l.theme) == null ? void 0 : E.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) => {
216
+ function ae({ question: e }) {
217
+ var h;
218
+ const { answers: n, setAnswer: r, nextStep: t, schema: l } = R(), d = n[e.id] || "", m = (c) => {
219
+ r(e.id, c), setTimeout(() => t(), 400);
220
+ }, y = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
221
+ return T(() => {
222
+ const c = (g) => {
202
223
  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);
224
+ const u = g.key.toUpperCase(), v = y.indexOf(u);
225
+ v >= 0 && v < (((C = e.options) == null ? void 0 : C.length) || 0) && m(e.options[v].value);
205
226
  };
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,
227
+ return window.addEventListener("keydown", c), () => window.removeEventListener("keydown", c);
228
+ }, [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: (h = e.options) == null ? void 0 : h.map((c, g) => {
229
+ var v, C, x, a, s, p;
230
+ const u = Array.isArray(d) ? d.includes(c.value) : d === c.value;
231
+ return /* @__PURE__ */ f(
232
+ b.button,
211
233
  {
212
234
  initial: { opacity: 0, y: 10 },
213
235
  animate: { opacity: 1, y: 0 },
214
- transition: { delay: f * 0.05 },
215
- onClick: () => o(m.value),
236
+ transition: { delay: g * 0.05 },
237
+ onClick: () => m(c.value),
216
238
  className: `
217
239
  w-full text-left p-4 rounded-lg border-2 transition-all duration-200
218
240
  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"}
241
+ ${u ? "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
242
  `,
243
+ style: o({
244
+ padding: "var(--sw-option-padding, 1rem)",
245
+ borderRadius: "var(--sw-option-radius, 0.5rem)",
246
+ borderWidth: "var(--sw-option-border, 2px)"
247
+ }, u && ((v = l.theme) != null && v.optionActiveColor) ? {
248
+ borderColor: "var(--sw-option-active)"
249
+ } : {}),
221
250
  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
251
+ /* @__PURE__ */ f("span", { className: "text-lg font-medium flex items-center gap-3", style: o(o({}, ((C = l.theme) == null ? void 0 : C.labelFont) && { fontFamily: "var(--font-sw-label)" }), ((x = l.theme) == null ? void 0 : x.labelFontSize) && { fontSize: "var(--size-sw-label)" }), children: [
252
+ /* @__PURE__ */ i("span", { className: `
253
+ flex-shrink-0 w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
254
+ ${u ? "border-sw-primary bg-sw-primary" : "border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
255
+ `, style: o({}, u && ((a = l.theme) != null && a.optionActiveColor) ? {
256
+ borderColor: "var(--sw-option-active)",
257
+ backgroundColor: "var(--sw-option-active)"
258
+ } : {}), children: u && /* @__PURE__ */ i(O, { size: 14, className: "text-sw-background" }) }),
259
+ c.label
228
260
  ] }),
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: [
261
+ !((s = l.i18n) != null && s.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: [
262
+ ((p = l.i18n) == null ? void 0 : p.selectKey) || "Select",
263
+ " ",
264
+ /* @__PURE__ */ f("span", { className: "hidden md:inline", children: [
232
265
  "Key ",
233
- f + 1
266
+ g + 1
234
267
  ] })
235
268
  ] })
236
269
  ]
237
270
  },
238
- String(m.value)
271
+ String(c.value)
239
272
  );
240
273
  }) });
241
274
  }
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,
275
+ function le({ question: e }) {
276
+ var d;
277
+ const { answers: n, setAnswer: r } = R(), t = n[e.id] || 0, l = Math.min(((d = e.validation) == null ? void 0 : d.max) || 5, 20);
278
+ return /* @__PURE__ */ f("div", { className: "flex flex-col gap-6", children: [
279
+ /* @__PURE__ */ i("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length: l }).map((m, y) => {
280
+ const h = y + 1, c = h <= t;
281
+ return /* @__PURE__ */ i(
282
+ b.button,
250
283
  {
251
284
  initial: { opacity: 0, scale: 0 },
252
285
  animate: { opacity: 1, scale: 1 },
253
- transition: { delay: c * 0.05 },
254
- onClick: () => r(e.id, m),
286
+ transition: { delay: y * 0.05 },
287
+ onClick: () => r(e.id, h),
255
288
  whileHover: { scale: 1.2, rotate: 5 },
256
289
  whileTap: { scale: 0.9 },
257
290
  className: "focus:outline-none",
258
- children: /* @__PURE__ */ n(
259
- Y,
291
+ children: /* @__PURE__ */ i(
292
+ ee,
260
293
  {
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"}`,
294
+ className: `w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${c ? "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
295
  strokeWidth: 1.5
263
296
  }
264
297
  )
265
298
  },
266
- c
299
+ y
267
300
  );
268
301
  }) }),
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,
302
+ /* @__PURE__ */ f("div", { className: "flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center", children: [
303
+ /* @__PURE__ */ i("span", { className: "text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide", children: e.minLabel || "Poor" }),
304
+ /* @__PURE__ */ i(
305
+ b.div,
273
306
  {
274
307
  initial: { opacity: 0, scale: 0.8 },
275
308
  animate: { opacity: t ? 1 : 0, scale: t ? 1 : 0.8 },
276
309
  className: "font-bold text-primary text-xl",
277
- children: t ? `${t} / ${d}` : ""
310
+ children: t ? `${t} / ${l}` : ""
278
311
  }
279
312
  ),
280
- /* @__PURE__ */ n("span", { className: "text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide", children: e.maxLabel || "Excellent" })
313
+ /* @__PURE__ */ i("span", { className: "text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide", children: e.maxLabel || "Excellent" })
281
314
  ] })
282
315
  ] });
283
316
  }
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 = {
317
+ function se({ question: e }) {
318
+ var y, h, c, g;
319
+ const { schema: n } = R(), r = n.questions.findIndex((u) => u.id === e.id) + 1, t = n.questions.length, l = {
286
320
  hidden: { opacity: 0, y: 20 },
287
321
  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];
322
+ }, d = (u) => u && u.replace(/\{\{(\w+)\}\}/g, (v, C) => {
323
+ const x = m.answers[C];
290
324
  return x != null ? String(x) : "";
291
- }), p = L();
292
- return /* @__PURE__ */ u(
293
- w.div,
325
+ }), m = R();
326
+ return /* @__PURE__ */ f(
327
+ b.div,
294
328
  {
295
329
  className: "flex flex-col gap-8 w-full max-w-4xl mx-auto",
296
330
  initial: "hidden",
@@ -299,34 +333,36 @@ function ie({ question: e }) {
299
333
  visible: { transition: { staggerChildren: 0.1 } }
300
334
  },
301
335
  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 })
336
+ /* @__PURE__ */ f("div", { className: "flex flex-col gap-2", children: [
337
+ /* @__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: [
338
+ /* @__PURE__ */ i("span", { children: r }),
339
+ /* @__PURE__ */ i("span", { className: "opacity-40 text-xs", children: "/" }),
340
+ /* @__PURE__ */ i("span", { className: "opacity-60", children: t })
307
341
  ] }) }),
308
- /* @__PURE__ */ u(
309
- w.h2,
342
+ /* @__PURE__ */ f(
343
+ b.h2,
310
344
  {
311
- variants: d,
345
+ variants: l,
312
346
  className: "text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",
347
+ style: o(o({}, ((y = n.theme) == null ? void 0 : y.titleFont) && { fontFamily: "var(--font-sw-title)" }), ((h = n.theme) == null ? void 0 : h.titleFontSize) && { fontSize: "var(--size-sw-title)" }),
313
348
  children: [
314
- o(e.title),
349
+ d(e.title),
315
350
  " ",
316
- /* @__PURE__ */ n("span", { className: "text-sw-primary", children: "*" })
351
+ /* @__PURE__ */ i("span", { className: "text-sw-primary", children: "*" })
317
352
  ]
318
353
  }
319
354
  ),
320
- e.description && /* @__PURE__ */ n(
321
- w.p,
355
+ e.description && /* @__PURE__ */ i(
356
+ b.p,
322
357
  {
323
- variants: d,
358
+ variants: l,
324
359
  className: "text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",
325
- children: o(e.description)
360
+ style: o(o({}, ((c = n.theme) == null ? void 0 : c.descriptionFont) && { fontFamily: "var(--font-sw-description)" }), ((g = n.theme) == null ? void 0 : g.descriptionFontSize) && { fontSize: "var(--size-sw-description)" }),
361
+ children: d(e.description)
326
362
  }
327
363
  )
328
364
  ] }),
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: [
365
+ /* @__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" ? /* @__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
366
  "Unsupported question type: ",
331
367
  e.type,
332
368
  " (ID: ",
@@ -337,7 +373,7 @@ function ie({ question: e }) {
337
373
  }
338
374
  );
339
375
  }
340
- const ae = {
376
+ const de = {
341
377
  next: "Next",
342
378
  back: "Back",
343
379
  submit: "Submit",
@@ -345,16 +381,16 @@ const ae = {
345
381
  optional: "Optional",
346
382
  stepInfo: "Question {{current}} of {{total}}"
347
383
  };
348
- function me({ schema: e, onSubmit: i }) {
349
- var I;
350
- const r = ee({ schema: e, onSubmit: i }), t = e.theme || {
384
+ function xe({ schema: e, onSubmit: n }) {
385
+ var C;
386
+ const r = ne({ schema: e, onSubmit: n }), t = e.theme || {
351
387
  backgroundColor: "#ffffff",
352
388
  textColor: "#000000",
353
389
  // Start with generic defaults, override in usage
354
390
  primaryColor: "#000000",
355
391
  borderRadius: "8px"
356
392
  // fontFamily removed to allow inheritance
357
- }, d = h(h({}, ae), e.i18n), o = {
393
+ }, l = o(o({}, de), e.i18n), d = o(o(o(o(o(o(o(o(o(o(o({
358
394
  backgroundColor: t.backgroundColor,
359
395
  color: t.textColor,
360
396
  fontFamily: t.fontFamily,
@@ -365,91 +401,91 @@ function me({ schema: e, onSubmit: i }) {
365
401
  "--color-sw-text-secondary": t.textColor,
366
402
  "--font-sw-heading": t.fontFamily || "inherit",
367
403
  "--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",
404
+ }, 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 }), m = t.buttonVariant === "outline", y = {
405
+ backgroundColor: m ? "transparent" : t.primaryColor,
406
+ color: m ? t.primaryColor : t.textColor,
407
+ border: m ? `2px solid ${t.primaryColor}` : "none",
372
408
  borderRadius: t.borderRadius || "8px",
373
409
  fontWeight: 600
374
- }, m = {
410
+ }, h = {
375
411
  color: t.primaryColor,
376
412
  borderRadius: t.borderRadius || "8px",
377
413
  fontWeight: 600
378
- }, { autoReload: f, reloadDelay: x = 3e3 } = e;
379
- if (B(() => {
380
- if (r.isCompleted && f) {
381
- const N = setTimeout(() => {
414
+ }, { autoReload: c, reloadDelay: g = 3e3 } = e;
415
+ if (T(() => {
416
+ if (r.isCompleted && c) {
417
+ const x = setTimeout(() => {
382
418
  r.resetForm();
383
- }, x);
384
- return () => clearTimeout(N);
419
+ }, g);
420
+ return () => clearTimeout(x);
385
421
  }
386
- }, [r.isCompleted, f, x, r.resetForm]), r.isCompleted)
387
- return /* @__PURE__ */ u(
422
+ }, [r.isCompleted, c, g, r.resetForm]), r.isCompleted)
423
+ return /* @__PURE__ */ f(
388
424
  "div",
389
425
  {
390
426
  className: "flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",
391
- style: o,
427
+ style: d,
392
428
  children: [
393
- f && /* @__PURE__ */ n(
394
- w.div,
429
+ c && /* @__PURE__ */ i(
430
+ b.div,
395
431
  {
396
432
  initial: { width: "0%" },
397
433
  animate: { width: "100%" },
398
- transition: { duration: x / 1e3, ease: "linear" },
434
+ transition: { duration: g / 1e3, ease: "linear" },
399
435
  className: "absolute top-0 left-0 h-1 bg-green-500 z-50"
400
436
  }
401
437
  ),
402
- /* @__PURE__ */ u(
403
- w.div,
438
+ /* @__PURE__ */ f(
439
+ b.div,
404
440
  {
405
441
  initial: { scale: 0.9, opacity: 0, y: 20 },
406
442
  animate: { scale: 1, opacity: 1, y: 0 },
407
443
  transition: { duration: 0.6, ease: [0.22, 1, 0.36, 1] },
408
444
  className: "flex flex-col items-center",
409
445
  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." })
446
+ /* @__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 }) }),
447
+ /* @__PURE__ */ i("h1", { className: "text-4xl md:text-5xl font-bold mb-4 tracking-tight", children: "Obrigado!" }),
448
+ /* @__PURE__ */ i("p", { className: "text-xl opacity-70 max-w-md leading-relaxed", children: "Suas respostas foram enviadas com sucesso." })
413
449
  ]
414
450
  }
415
451
  )
416
452
  ]
417
453
  }
418
454
  );
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(
455
+ const u = e.questions.find((x) => x.id === r.currentStepId), v = (e.questions.findIndex((x) => x.id === r.currentStepId) + 1) / e.questions.length * 100;
456
+ return /* @__PURE__ */ i(Q.Provider, { value: N(o({}, r), { schema: e }), children: /* @__PURE__ */ f(
421
457
  "div",
422
458
  {
423
459
  className: "w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",
424
- style: o,
460
+ style: d,
425
461
  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,
462
+ /* @__PURE__ */ f("div", { className: "absolute top-0 left-0 w-full h-1 z-50", children: [
463
+ /* @__PURE__ */ i("div", { className: "absolute top-0 left-0 w-full h-full bg-current opacity-10" }),
464
+ /* @__PURE__ */ i(
465
+ b.div,
430
466
  {
431
467
  className: "h-full relative z-10",
432
468
  initial: { width: 0 },
433
- animate: { width: `${C}%` },
469
+ animate: { width: `${v}%` },
434
470
  transition: { duration: 0.5, ease: "easeInOut" },
435
471
  style: { backgroundColor: t.primaryColor }
436
472
  }
437
473
  )
438
474
  ] }),
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,
475
+ /* @__PURE__ */ i("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__ */ i(q, { mode: "wait", children: u && /* @__PURE__ */ i(
476
+ b.div,
441
477
  {
442
478
  initial: { opacity: 0, y: 40 },
443
479
  animate: { opacity: 1, y: 0 },
444
480
  exit: { opacity: 0, y: -40 },
445
481
  transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },
446
482
  className: "w-full",
447
- children: /* @__PURE__ */ n(ie, { question: v })
483
+ children: /* @__PURE__ */ i(se, { question: u })
448
484
  },
449
- v.id
485
+ u.id
450
486
  ) }) }),
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(
487
+ /* @__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: [
488
+ t.showPoweredBy !== !1 && /* @__PURE__ */ f(
453
489
  "a",
454
490
  {
455
491
  href: t.poweredByUrl || "#",
@@ -457,42 +493,42 @@ function me({ schema: e, onSubmit: i }) {
457
493
  rel: t.poweredByUrl ? "noopener noreferrer" : void 0,
458
494
  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
495
  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(
496
+ /* @__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" }),
497
+ /* @__PURE__ */ i(
462
498
  "span",
463
499
  {
464
500
  className: "text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",
465
501
  style: { color: t.brandColor || t.primaryColor },
466
- children: ((I = t.poweredBy) == null ? void 0 : I.replace("Powered by ", "")) || "SAWABONA TECH"
502
+ children: ((C = t.poweredBy) == null ? void 0 : C.replace("Powered by ", "")) || "SAWABONA TECH"
467
503
  }
468
504
  )
469
505
  ]
470
506
  }
471
507
  ),
472
- /* @__PURE__ */ u("div", { className: "flex items-center gap-4 order-2 md:order-3 ml-auto", children: [
473
- /* @__PURE__ */ n(
474
- w.button,
508
+ /* @__PURE__ */ f("div", { className: "flex items-center gap-4 order-2 md:order-3 ml-auto", children: [
509
+ /* @__PURE__ */ i(
510
+ b.button,
475
511
  {
476
512
  onClick: r.prevStep,
477
513
  disabled: r.history.length === 0,
478
514
  whileHover: { scale: 1.05 },
479
515
  whileTap: { scale: 0.95 },
480
516
  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 })
517
+ style: h,
518
+ children: /* @__PURE__ */ i(te, { size: 24 })
483
519
  }
484
520
  ),
485
- /* @__PURE__ */ u(
486
- w.button,
521
+ /* @__PURE__ */ f(
522
+ b.button,
487
523
  {
488
524
  onClick: r.nextStep,
489
525
  whileHover: { scale: 1.02 },
490
526
  whileTap: { scale: 0.98 },
491
527
  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,
528
+ style: y,
493
529
  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 })
530
+ /* @__PURE__ */ i("span", { children: r.currentStepId === e.questions[e.questions.length - 1].id ? t.submitText || l.submit : l.next }),
531
+ r.currentStepId !== e.questions[e.questions.length - 1].id && /* @__PURE__ */ i(re, { size: 20, strokeWidth: 3 })
496
532
  ]
497
533
  }
498
534
  )
@@ -503,5 +539,5 @@ function me({ schema: e, onSubmit: i }) {
503
539
  ) });
504
540
  }
505
541
  export {
506
- me as FormRenderer
542
+ xe as FormRenderer
507
543
  };