@sawabona/forms 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"FormRenderer.d.ts","sourceRoot":"","sources":["../../src/lib/components/FormRenderer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AAO3D,UAAU,iBAAiB;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;CACpC;AAWD,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CAsLnE"}
1
+ {"version":3,"file":"FormRenderer.d.ts","sourceRoot":"","sources":["../../src/lib/components/FormRenderer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AAO3D,UAAU,iBAAiB;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;CACpC;AAWD,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CAwLnE"}
@@ -48,6 +48,7 @@ export interface FormTheme {
48
48
  borderRadius: string;
49
49
  poweredBy?: string;
50
50
  showPoweredBy?: boolean;
51
+ poweredByUrl?: string;
51
52
  brandColor?: string;
52
53
  submitText?: string;
53
54
  buttonVariant?: 'solid' | 'outline';
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/core/types.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,GAClB,MAAM,GACN,OAAO,GACP,QAAQ,GACR,KAAK,GACL,QAAQ,GACR,cAAc,GACd,MAAM,GACN,SAAS,GACT,QAAQ,GACR,eAAe,GACf,WAAW,CAAC;AAElB,MAAM,WA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AW,KAAK,IAAI,CAAC;IAC5D,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACrE"}
@@ -1,83 +1,83 @@
1
1
  var H = Object.defineProperty, K = Object.defineProperties;
2
- var V = Object.getOwnPropertyDescriptors;
2
+ var U = Object.getOwnPropertyDescriptors;
3
3
  var R = Object.getOwnPropertySymbols;
4
- var $ = Object.prototype.hasOwnProperty, B = Object.prototype.propertyIsEnumerable;
5
- var P = (e, i, r) => i in e ? H(e, i, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[i] = r, h = (e, i) => {
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
6
  for (var r in i || (i = {}))
7
- $.call(i, r) && P(e, r, i[r]);
7
+ P.call(i, r) && z(e, r, i[r]);
8
8
  if (R)
9
9
  for (var r of R(i))
10
- B.call(i, r) && P(e, r, i[r]);
10
+ _.call(i, r) && z(e, r, i[r]);
11
11
  return e;
12
- }, g = (e, i) => K(e, V(i));
13
- var _ = (e) => typeof e == "symbol" ? e : e + "", D = (e, i) => {
12
+ }, g = (e, i) => K(e, U(i));
13
+ var $ = (e) => typeof e == "symbol" ? e : e + "", D = (e, i) => {
14
14
  var r = {};
15
15
  for (var t in e)
16
- $.call(e, t) && i.indexOf(t) < 0 && (r[t] = e[t]);
16
+ P.call(e, t) && i.indexOf(t) < 0 && (r[t] = e[t]);
17
17
  if (e != null && R)
18
18
  for (var t of R(e))
19
- i.indexOf(t) < 0 && B.call(e, t) && (r[t] = e[t]);
19
+ i.indexOf(t) < 0 && _.call(e, t) && (r[t] = e[t]);
20
20
  return r;
21
21
  };
22
22
  import { jsxs as u, jsx as n } from "react/jsx-runtime";
23
- import { useState as W, useMemo as M, useCallback as S, createContext as U, useContext as G, useRef as X, useEffect as z } from "react";
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
24
  import { motion as w, AnimatePresence as J } from "framer-motion";
25
25
  import { Check as O, Star as Y, ChevronLeft as Z, ChevronRight as q } from "lucide-react";
26
26
  function ee({ schema: e, onSubmit: i }) {
27
27
  var N;
28
- const [r, t] = W({
28
+ const [r, t] = V({
29
29
  answers: {},
30
30
  currentStepId: ((N = e.questions[0]) == null ? void 0 : N.id) || "",
31
31
  history: [],
32
32
  isSubmitting: !1,
33
33
  errors: {},
34
34
  isCompleted: !1
35
- }), d = M(
35
+ }), d = W(
36
36
  () => e.questions.findIndex((a) => a.id === r.currentStepId),
37
37
  [e.questions, r.currentStepId]
38
- ), s = e.questions[d], p = S((a, o) => {
38
+ ), o = e.questions[d], p = k((a, s) => {
39
39
  t((l) => g(h({}, l), {
40
40
  answers: g(h({}, l.answers), {
41
- [a]: o
41
+ [a]: s
42
42
  }),
43
43
  // Clear error on modification
44
44
  errors: g(h({}, l.errors), {
45
45
  [a]: ""
46
46
  })
47
47
  }));
48
- }, []), c = S((a, o) => {
48
+ }, []), c = k((a, s) => {
49
49
  t((l) => {
50
- if (o === null) {
51
- const F = l.errors, { [a]: j } = F, b = D(F, [_(a)]);
50
+ if (s === null) {
51
+ const F = l.errors, { [a]: j } = F, b = D(F, [$(a)]);
52
52
  return g(h({}, l), { errors: b });
53
53
  }
54
54
  return g(h({}, l), {
55
- errors: g(h({}, l.errors), { [a]: o })
55
+ errors: g(h({}, l.errors), { [a]: s })
56
56
  });
57
57
  });
58
- }, []), m = S(() => {
58
+ }, []), m = k(() => {
59
59
  var l;
60
- if (!s) return !0;
61
- const a = r.answers[s.id], o = s.validation;
62
- return o && o.required && (a === void 0 || a === "" || Array.isArray(a) && a.length === 0) ? (c(s.id, ((l = e.i18n) == null ? void 0 : l.required) || "This field is required"), !1) : !0;
63
- }, [s, r.answers, c, e.i18n]), f = S((a) => {
64
- const o = e.questions.findIndex((l) => l.id === a.id);
65
- return o < e.questions.length - 1 ? e.questions[o + 1].id : "submit";
66
- }, [e.questions]), x = S(() => {
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
67
  if (!m()) return;
68
- const a = f(s);
69
- a === "submit" ? (t((o) => g(h({}, o), { isCompleted: !0 })), i == null || i(r.answers)) : t((o) => g(h({}, o), {
70
- history: [...o.history, o.currentStepId],
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
71
  currentStepId: a
72
72
  }));
73
- }, [s, r.answers, m, f, i]), v = S(() => {
73
+ }, [o, r.answers, m, f, i]), v = k(() => {
74
74
  if (r.history.length === 0) return;
75
75
  const a = r.history[r.history.length - 1];
76
- t((o) => g(h({}, o), {
77
- history: o.history.slice(0, -1),
76
+ t((s) => g(h({}, s), {
77
+ history: s.history.slice(0, -1),
78
78
  currentStepId: a
79
79
  }));
80
- }, [r.history]), C = S((a) => {
80
+ }, [r.history]), C = k((a) => {
81
81
  if (!e.questions.some((l) => l.id === a)) {
82
82
  console.warn(`Step ${a} does not exist`);
83
83
  return;
@@ -86,7 +86,7 @@ function ee({ schema: e, onSubmit: i }) {
86
86
  history: [...l.history, l.currentStepId],
87
87
  currentStepId: a
88
88
  }));
89
- }, [e.questions]), I = S(() => {
89
+ }, [e.questions]), I = k(() => {
90
90
  var a;
91
91
  t({
92
92
  answers: {},
@@ -109,16 +109,16 @@ function ee({ schema: e, onSubmit: i }) {
109
109
  progress: d / e.questions.length * 100
110
110
  });
111
111
  }
112
- const Q = U(void 0), L = () => {
112
+ const Q = M(void 0), L = () => {
113
113
  const e = G(Q);
114
114
  if (!e)
115
115
  throw new Error("useFormContext must be used within a FormProvider");
116
116
  return e;
117
117
  };
118
118
  function te({ question: e }) {
119
- var N, a, o, l, F, j;
120
- const { answers: i, setAnswer: r, nextStep: t, schema: d } = L(), s = i[e.id], p = s != null ? String(s) : "", c = X(null), m = d.questions[0].id === e.id, f = !d.disableAutoFocus || !m;
121
- z(() => {
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
122
  if (f) {
123
123
  const b = setTimeout(() => {
124
124
  var y;
@@ -144,12 +144,12 @@ function te({ question: e }) {
144
144
  if ((A = e.validation) != null && A.pattern)
145
145
  try {
146
146
  if (!new RegExp(e.validation.pattern).test(p)) return !1;
147
- } catch (k) {
148
- console.error("Invalid regex pattern in schema", k);
147
+ } catch (S) {
148
+ console.error("Invalid regex pattern in schema", S);
149
149
  }
150
150
  if (e.type === "number") {
151
- const k = parseFloat(p);
152
- if (!isNaN(k) && (((E = e.validation) == null ? void 0 : E.min) !== void 0 && k < e.validation.min || ((T = e.validation) == null ? void 0 : T.max) !== void 0 && k > e.validation.max))
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))
153
153
  return !1;
154
154
  }
155
155
  }
@@ -176,7 +176,7 @@ function te({ question: e }) {
176
176
  placeholder: e.placeholder,
177
177
  minLength: (N = e.validation) == null ? void 0 : N.minLength,
178
178
  maxLength: ((a = e.validation) == null ? void 0 : a.maxLength) || 2048,
179
- min: (o = e.validation) == null ? void 0 : o.min,
179
+ min: (s = e.validation) == null ? void 0 : s.min,
180
180
  max: (l = e.validation) == null ? void 0 : l.max,
181
181
  pattern: (F = e.validation) == null ? void 0 : F.pattern,
182
182
  className: `
@@ -194,14 +194,14 @@ function te({ question: e }) {
194
194
  }
195
195
  function re({ question: e }) {
196
196
  var c;
197
- const { answers: i, setAnswer: r, nextStep: t } = L(), d = i[e.id] || "", s = (m) => {
197
+ const { answers: i, setAnswer: r, nextStep: t } = L(), d = i[e.id] || "", o = (m) => {
198
198
  r(e.id, m), setTimeout(() => t(), 400);
199
199
  }, p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
200
- return z(() => {
200
+ return B(() => {
201
201
  const m = (f) => {
202
202
  var C;
203
203
  const x = f.key.toUpperCase(), v = p.indexOf(x);
204
- v >= 0 && v < (((C = e.options) == null ? void 0 : C.length) || 0) && s(e.options[v].value);
204
+ v >= 0 && v < (((C = e.options) == null ? void 0 : C.length) || 0) && o(e.options[v].value);
205
205
  };
206
206
  return window.addEventListener("keydown", m), () => window.removeEventListener("keydown", m);
207
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) => {
@@ -212,7 +212,7 @@ function re({ question: e }) {
212
212
  initial: { opacity: 0, y: 10 },
213
213
  animate: { opacity: 1, y: 0 },
214
214
  transition: { delay: f * 0.05 },
215
- onClick: () => s(m.value),
215
+ onClick: () => o(m.value),
216
216
  className: `
217
217
  w-full text-left p-4 rounded-lg border-2 transition-all duration-200
218
218
  flex items-center justify-between group
@@ -240,8 +240,8 @@ function re({ question: e }) {
240
240
  }) });
241
241
  }
242
242
  function ne({ question: e }) {
243
- var s;
244
- const { answers: i, setAnswer: r } = L(), t = i[e.id] || 0, d = Math.min(((s = e.validation) == null ? void 0 : s.max) || 5, 20);
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
245
  return /* @__PURE__ */ u("div", { className: "flex flex-col gap-6", children: [
246
246
  /* @__PURE__ */ n("div", { className: "flex gap-4 flex-wrap", children: Array.from({ length: d }).map((p, c) => {
247
247
  const m = c + 1, f = m <= t;
@@ -285,7 +285,7 @@ function ie({ question: e }) {
285
285
  const { schema: i } = L(), r = i.questions.findIndex((c) => c.id === e.id) + 1, t = i.questions.length, d = {
286
286
  hidden: { opacity: 0, y: 20 },
287
287
  visible: { opacity: 1, y: 0, transition: { duration: 0.5, ease: [0.22, 1, 0.36, 1] } }
288
- }, s = (c) => c && c.replace(/\{\{(\w+)\}\}/g, (m, f) => {
288
+ }, o = (c) => c && c.replace(/\{\{(\w+)\}\}/g, (m, f) => {
289
289
  const x = p.answers[f];
290
290
  return x != null ? String(x) : "";
291
291
  }), p = L();
@@ -311,7 +311,7 @@ function ie({ question: e }) {
311
311
  variants: d,
312
312
  className: "text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",
313
313
  children: [
314
- s(e.title),
314
+ o(e.title),
315
315
  " ",
316
316
  /* @__PURE__ */ n("span", { className: "text-sw-primary", children: "*" })
317
317
  ]
@@ -322,7 +322,7 @@ function ie({ question: e }) {
322
322
  {
323
323
  variants: d,
324
324
  className: "text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",
325
- children: s(e.description)
325
+ children: o(e.description)
326
326
  }
327
327
  )
328
328
  ] }),
@@ -354,7 +354,7 @@ function me({ schema: e, onSubmit: i }) {
354
354
  primaryColor: "#000000",
355
355
  borderRadius: "8px"
356
356
  // fontFamily removed to allow inheritance
357
- }, d = h(h({}, ae), e.i18n), s = {
357
+ }, d = h(h({}, ae), e.i18n), o = {
358
358
  backgroundColor: t.backgroundColor,
359
359
  color: t.textColor,
360
360
  fontFamily: t.fontFamily,
@@ -376,7 +376,7 @@ function me({ schema: e, onSubmit: i }) {
376
376
  borderRadius: t.borderRadius || "8px",
377
377
  fontWeight: 600
378
378
  }, { autoReload: f, reloadDelay: x = 3e3 } = e;
379
- if (z(() => {
379
+ if (B(() => {
380
380
  if (r.isCompleted && f) {
381
381
  const N = setTimeout(() => {
382
382
  r.resetForm();
@@ -388,7 +388,7 @@ function me({ schema: e, onSubmit: i }) {
388
388
  "div",
389
389
  {
390
390
  className: "flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",
391
- style: s,
391
+ style: o,
392
392
  children: [
393
393
  f && /* @__PURE__ */ n(
394
394
  w.div,
@@ -421,7 +421,7 @@ function me({ schema: e, onSubmit: i }) {
421
421
  "div",
422
422
  {
423
423
  className: "w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",
424
- style: s,
424
+ style: o,
425
425
  children: [
426
426
  /* @__PURE__ */ u("div", { className: "absolute top-0 left-0 w-full h-1 z-50", children: [
427
427
  /* @__PURE__ */ n("div", { className: "absolute top-0 left-0 w-full h-full bg-current opacity-10" }),
@@ -452,7 +452,9 @@ function me({ schema: e, onSubmit: i }) {
452
452
  t.showPoweredBy !== !1 && /* @__PURE__ */ u(
453
453
  "a",
454
454
  {
455
- href: "#",
455
+ href: t.poweredByUrl || "#",
456
+ target: t.poweredByUrl ? "_blank" : void 0,
457
+ rel: t.poweredByUrl ? "noopener noreferrer" : void 0,
456
458
  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",
457
459
  children: [
458
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" }),
@@ -1,14 +1,14 @@
1
- (function(n,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("react/jsx-runtime"),require("react"),require("framer-motion"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","framer-motion","lucide-react"],t):(n=typeof globalThis!="undefined"?globalThis:n||self,t(n.SawabonaForms={},n.jsxRuntime,n.React,n.Motion,n.Lucide))})(this,(function(n,t,o,l,I){"use strict";var J=Object.defineProperty,Y=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var B=(n,t,o)=>t in n?J(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,g=(n,t)=>{for(var o in t||(t={}))O.call(t,o)&&B(n,o,t[o]);if(z)for(var o of z(t))_.call(t,o)&&B(n,o,t[o]);return n},b=(n,t)=>Y(n,Z(t));var D=n=>typeof n=="symbol"?n:n+"",Q=(n,t)=>{var o={};for(var l in n)O.call(n,l)&&t.indexOf(l)<0&&(o[l]=n[l]);if(n!=null&&z)for(var l of z(n))t.indexOf(l)<0&&_.call(n,l)&&(o[l]=n[l]);return o};function H({schema:e,onSubmit:m}){var N;const[s,r]=o.useState({answers:{},currentStepId:((N=e.questions[0])==null?void 0:N.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1}),p=o.useMemo(()=>e.questions.findIndex(a=>a.id===s.currentStepId),[e.questions,s.currentStepId]),i=e.questions[p],f=o.useCallback((a,d)=>{r(c=>b(g({},c),{answers:b(g({},c.answers),{[a]:d}),errors:b(g({},c.errors),{[a]:""})}))},[]),u=o.useCallback((a,d)=>{r(c=>{if(d===null){const E=c.errors,{[a]:P}=E,v=Q(E,[D(a)]);return b(g({},c),{errors:v})}return b(g({},c),{errors:b(g({},c.errors),{[a]:d})})})},[]),x=o.useCallback(()=>{var c;if(!i)return!0;const a=s.answers[i.id],d=i.validation;return d&&d.required&&(a===void 0||a===""||Array.isArray(a)&&a.length===0)?(u(i.id,((c=e.i18n)==null?void 0:c.required)||"This field is required"),!1):!0},[i,s.answers,u,e.i18n]),y=o.useCallback(a=>{const d=e.questions.findIndex(c=>c.id===a.id);return d<e.questions.length-1?e.questions[d+1].id:"submit"},[e.questions]),h=o.useCallback(()=>{if(!x())return;const a=y(i);a==="submit"?(r(d=>b(g({},d),{isCompleted:!0})),m==null||m(s.answers)):r(d=>b(g({},d),{history:[...d.history,d.currentStepId],currentStepId:a}))},[i,s.answers,x,y,m]),C=o.useCallback(()=>{if(s.history.length===0)return;const a=s.history[s.history.length-1];r(d=>b(g({},d),{history:d.history.slice(0,-1),currentStepId:a}))},[s.history]),k=o.useCallback(a=>{if(!e.questions.some(c=>c.id===a)){console.warn(`Step ${a} does not exist`);return}r(c=>b(g({},c),{history:[...c.history,c.currentStepId],currentStepId:a}))},[e.questions]),A=o.useCallback(()=>{var a;r({answers:{},currentStepId:((a=e.questions[0])==null?void 0:a.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1})},[e.questions]);return b(g({},s),{setAnswer:f,nextStep:h,prevStep:C,jumpToStep:k,submitForm:()=>m==null?void 0:m(s.answers),resetForm:A,registerError:u,progress:p/e.questions.length*100})}const $=o.createContext(void 0),F=()=>{const e=o.useContext($);if(!e)throw new Error("useFormContext must be used within a FormProvider");return e};function K({question:e}){var N,a,d,c,E,P;const{answers:m,setAnswer:s,nextStep:r,schema:p}=F(),i=m[e.id],f=i!=null?String(i):"",u=o.useRef(null),x=p.questions[0].id===e.id,y=!p.disableAutoFocus||!x;o.useEffect(()=>{if(y){const v=setTimeout(()=>{var w;(w=u.current)==null||w.focus()},500);return()=>clearTimeout(v)}},[e.id,y]);const h=v=>{var L;let w=v.target.value;const T=((L=e.validation)==null?void 0:L.maxLength)||2048;if(w.length>T&&(w=w.slice(0,T)),e.type==="number"){const j=w===""?"":parseFloat(w);s(e.id,j)}else s(e.id,w)},C=()=>{var v,w,T,L,j;if((v=e.validation)!=null&&v.required&&!f)return!1;if(f){if((w=e.validation)!=null&&w.minLength&&f.length<e.validation.minLength||e.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f))return!1;if((T=e.validation)!=null&&T.pattern)try{if(!new RegExp(e.validation.pattern).test(f))return!1}catch(S){console.error("Invalid regex pattern in schema",S)}if(e.type==="number"){const S=parseFloat(f);if(!isNaN(S)&&(((L=e.validation)==null?void 0:L.min)!==void 0&&S<e.validation.min||((j=e.validation)==null?void 0:j.max)!==void 0&&S>e.validation.max))return!1}}return!0},k=v=>{if(v.key==="Enter"&&!v.shiftKey){if(v.preventDefault(),!C()){const w=document.querySelector(".sawabona-form-container")||document.body;w.classList.add("shake-animation"),setTimeout(()=>w.classList.remove("shake-animation"),500);return}r()}};return t.jsxs("div",{className:"w-full relative group",children:[t.jsx("input",{ref:u,type:e.type,value:typeof f=="string"||typeof f=="number"?f:"",onChange:h,onKeyDown:k,placeholder:e.placeholder,minLength:(N=e.validation)==null?void 0:N.minLength,maxLength:((a=e.validation)==null?void 0:a.maxLength)||2048,min:(d=e.validation)==null?void 0:d.min,max:(c=e.validation)==null?void 0:c.max,pattern:(E=e.validation)==null?void 0:E.pattern,className:`
1
+ (function(n,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("react/jsx-runtime"),require("react"),require("framer-motion"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","framer-motion","lucide-react"],t):(n=typeof globalThis!="undefined"?globalThis:n||self,t(n.SawabonaForms={},n.jsxRuntime,n.React,n.Motion,n.Lucide))})(this,(function(n,t,o,l,I){"use strict";var J=Object.defineProperty,Y=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var _=(n,t,o)=>t in n?J(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,g=(n,t)=>{for(var o in t||(t={}))$.call(t,o)&&_(n,o,t[o]);if(B)for(var o of B(t))O.call(t,o)&&_(n,o,t[o]);return n},b=(n,t)=>Y(n,Z(t));var D=n=>typeof n=="symbol"?n:n+"",Q=(n,t)=>{var o={};for(var l in n)$.call(n,l)&&t.indexOf(l)<0&&(o[l]=n[l]);if(n!=null&&B)for(var l of B(n))t.indexOf(l)<0&&O.call(n,l)&&(o[l]=n[l]);return o};function H({schema:e,onSubmit:m}){var N;const[s,r]=o.useState({answers:{},currentStepId:((N=e.questions[0])==null?void 0:N.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1}),p=o.useMemo(()=>e.questions.findIndex(a=>a.id===s.currentStepId),[e.questions,s.currentStepId]),i=e.questions[p],f=o.useCallback((a,d)=>{r(c=>b(g({},c),{answers:b(g({},c.answers),{[a]:d}),errors:b(g({},c.errors),{[a]:""})}))},[]),u=o.useCallback((a,d)=>{r(c=>{if(d===null){const E=c.errors,{[a]:z}=E,v=Q(E,[D(a)]);return b(g({},c),{errors:v})}return b(g({},c),{errors:b(g({},c.errors),{[a]:d})})})},[]),x=o.useCallback(()=>{var c;if(!i)return!0;const a=s.answers[i.id],d=i.validation;return d&&d.required&&(a===void 0||a===""||Array.isArray(a)&&a.length===0)?(u(i.id,((c=e.i18n)==null?void 0:c.required)||"This field is required"),!1):!0},[i,s.answers,u,e.i18n]),y=o.useCallback(a=>{const d=e.questions.findIndex(c=>c.id===a.id);return d<e.questions.length-1?e.questions[d+1].id:"submit"},[e.questions]),h=o.useCallback(()=>{if(!x())return;const a=y(i);a==="submit"?(r(d=>b(g({},d),{isCompleted:!0})),m==null||m(s.answers)):r(d=>b(g({},d),{history:[...d.history,d.currentStepId],currentStepId:a}))},[i,s.answers,x,y,m]),C=o.useCallback(()=>{if(s.history.length===0)return;const a=s.history[s.history.length-1];r(d=>b(g({},d),{history:d.history.slice(0,-1),currentStepId:a}))},[s.history]),k=o.useCallback(a=>{if(!e.questions.some(c=>c.id===a)){console.warn(`Step ${a} does not exist`);return}r(c=>b(g({},c),{history:[...c.history,c.currentStepId],currentStepId:a}))},[e.questions]),A=o.useCallback(()=>{var a;r({answers:{},currentStepId:((a=e.questions[0])==null?void 0:a.id)||"",history:[],isSubmitting:!1,errors:{},isCompleted:!1})},[e.questions]);return b(g({},s),{setAnswer:f,nextStep:h,prevStep:C,jumpToStep:k,submitForm:()=>m==null?void 0:m(s.answers),resetForm:A,registerError:u,progress:p/e.questions.length*100})}const P=o.createContext(void 0),F=()=>{const e=o.useContext(P);if(!e)throw new Error("useFormContext must be used within a FormProvider");return e};function K({question:e}){var N,a,d,c,E,z;const{answers:m,setAnswer:s,nextStep:r,schema:p}=F(),i=m[e.id],f=i!=null?String(i):"",u=o.useRef(null),x=p.questions[0].id===e.id,y=!p.disableAutoFocus||!x;o.useEffect(()=>{if(y){const v=setTimeout(()=>{var w;(w=u.current)==null||w.focus()},500);return()=>clearTimeout(v)}},[e.id,y]);const h=v=>{var L;let w=v.target.value;const T=((L=e.validation)==null?void 0:L.maxLength)||2048;if(w.length>T&&(w=w.slice(0,T)),e.type==="number"){const j=w===""?"":parseFloat(w);s(e.id,j)}else s(e.id,w)},C=()=>{var v,w,T,L,j;if((v=e.validation)!=null&&v.required&&!f)return!1;if(f){if((w=e.validation)!=null&&w.minLength&&f.length<e.validation.minLength||e.type==="email"&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f))return!1;if((T=e.validation)!=null&&T.pattern)try{if(!new RegExp(e.validation.pattern).test(f))return!1}catch(S){console.error("Invalid regex pattern in schema",S)}if(e.type==="number"){const S=parseFloat(f);if(!isNaN(S)&&(((L=e.validation)==null?void 0:L.min)!==void 0&&S<e.validation.min||((j=e.validation)==null?void 0:j.max)!==void 0&&S>e.validation.max))return!1}}return!0},k=v=>{if(v.key==="Enter"&&!v.shiftKey){if(v.preventDefault(),!C()){const w=document.querySelector(".sawabona-form-container")||document.body;w.classList.add("shake-animation"),setTimeout(()=>w.classList.remove("shake-animation"),500);return}r()}};return t.jsxs("div",{className:"w-full relative group",children:[t.jsx("input",{ref:u,type:e.type,value:typeof f=="string"||typeof f=="number"?f:"",onChange:h,onKeyDown:k,placeholder:e.placeholder,minLength:(N=e.validation)==null?void 0:N.minLength,maxLength:((a=e.validation)==null?void 0:a.maxLength)||2048,min:(d=e.validation)==null?void 0:d.min,max:(c=e.validation)==null?void 0:c.max,pattern:(E=e.validation)==null?void 0:E.pattern,className:`
2
2
  w-full bg-transparent border-b-2 border-sw-text-secondary/20
3
3
  py-4 text-2xl md:text-3xl font-medium outline-none transition-colors
4
4
  placeholder:text-sw-text-secondary/30
5
5
  focus:border-sw-primary
6
6
  font-sw-heading
7
- `}),void 0,t.jsx("p",{className:"text-sm opacity-50 mt-4",children:(e.type==="email"||e.type==="text"||e.type==="number"||e.type==="url")&&(((P=p.i18n)==null?void 0:P.pressEnter)||"Press Enter to continue")})]})}function V({question:e}){var u;const{answers:m,setAnswer:s,nextStep:r}=F(),p=m[e.id]||"",i=x=>{s(e.id,x),setTimeout(()=>r(),400)},f="ABCDEFGHIJKLMNOPQRSTUVWXYZ";return o.useEffect(()=>{const x=y=>{var k;const h=y.key.toUpperCase(),C=f.indexOf(h);C>=0&&C<(((k=e.options)==null?void 0:k.length)||0)&&i(e.options[C].value)};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[e.options,e.id]),t.jsx("div",{className:"flex flex-col gap-3 w-full max-w-xl",children:(u=e.options)==null?void 0:u.map((x,y)=>{const h=Array.isArray(p)?p.includes(x.value):p===x.value;return t.jsxs(l.motion.button,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:y*.05},onClick:()=>i(x.value),className:`
7
+ `}),void 0,t.jsx("p",{className:"text-sm opacity-50 mt-4",children:(e.type==="email"||e.type==="text"||e.type==="number"||e.type==="url")&&(((z=p.i18n)==null?void 0:z.pressEnter)||"Press Enter to continue")})]})}function U({question:e}){var u;const{answers:m,setAnswer:s,nextStep:r}=F(),p=m[e.id]||"",i=x=>{s(e.id,x),setTimeout(()=>r(),400)},f="ABCDEFGHIJKLMNOPQRSTUVWXYZ";return o.useEffect(()=>{const x=y=>{var k;const h=y.key.toUpperCase(),C=f.indexOf(h);C>=0&&C<(((k=e.options)==null?void 0:k.length)||0)&&i(e.options[C].value)};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[e.options,e.id]),t.jsx("div",{className:"flex flex-col gap-3 w-full max-w-xl",children:(u=e.options)==null?void 0:u.map((x,y)=>{const h=Array.isArray(p)?p.includes(x.value):p===x.value;return t.jsxs(l.motion.button,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:y*.05},onClick:()=>i(x.value),className:`
8
8
  w-full text-left p-4 rounded-lg border-2 transition-all duration-200
9
9
  flex items-center justify-between group
10
10
  ${h?"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"}
11
11
  `,children:[t.jsxs("span",{className:"text-lg font-medium flex items-center gap-3",children:[t.jsx("span",{className:`
12
12
  w-6 h-6 rounded-full border-2 flex items-center justify-center transition-colors
13
13
  ${h?"border-sw-primary bg-sw-primary":"border-sw-text-secondary/30 group-hover:border-sw-primary/50"}
14
- `,children:h&&t.jsx(I.Check,{size:14,className:"text-sw-background"})}),x.label]}),t.jsxs("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50",children:["Select ",t.jsxs("span",{className:"hidden md:inline",children:["Key ",y+1]})]})]},String(x.value))})})}function W({question:e}){var i;const{answers:m,setAnswer:s}=F(),r=m[e.id]||0,p=Math.min(((i=e.validation)==null?void 0:i.max)||5,20);return t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx("div",{className:"flex gap-4 flex-wrap",children:Array.from({length:p}).map((f,u)=>{const x=u+1,y=x<=r;return t.jsx(l.motion.button,{initial:{opacity:0,scale:0},animate:{opacity:1,scale:1},transition:{delay:u*.05},onClick:()=>s(e.id,x),whileHover:{scale:1.2,rotate:5},whileTap:{scale:.9},className:"focus:outline-none",children:t.jsx(I.Star,{className:`w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${y?"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"}`,strokeWidth:1.5})},u)})}),t.jsxs("div",{className:"flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center",children:[t.jsx("span",{className:"text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide",children:e.minLabel||"Poor"}),t.jsx(l.motion.div,{initial:{opacity:0,scale:.8},animate:{opacity:r?1:0,scale:r?1:.8},className:"font-bold text-primary text-xl",children:r?`${r} / ${p}`:""}),t.jsx("span",{className:"text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide",children:e.maxLabel||"Excellent"})]})]})}function U({question:e}){const{schema:m}=F(),s=m.questions.findIndex(u=>u.id===e.id)+1,r=m.questions.length,p={hidden:{opacity:0,y:20},visible:{opacity:1,y:0,transition:{duration:.5,ease:[.22,1,.36,1]}}},i=u=>u&&u.replace(/\{\{(\w+)\}\}/g,(x,y)=>{const h=f.answers[y];return h!=null?String(h):""}),f=F();return t.jsxs(l.motion.div,{className:"flex flex-col gap-8 w-full max-w-4xl mx-auto",initial:"hidden",animate:"visible",variants:{visible:{transition:{staggerChildren:.1}}},children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(l.motion.div,{variants:p,className:"flex gap-4 items-baseline",children:t.jsxs("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:[t.jsx("span",{children:s}),t.jsx("span",{className:"opacity-40 text-xs",children:"/"}),t.jsx("span",{className:"opacity-60",children:r})]})}),t.jsxs(l.motion.h2,{variants:p,className:"text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",children:[i(e.title)," ",t.jsx("span",{className:"text-sw-primary",children:"*"})]}),e.description&&t.jsx(l.motion.p,{variants:p,className:"text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",children:i(e.description)})]}),t.jsx(l.motion.div,{variants:p,className:"w-full mt-6",children:e.type==="text"||e.type==="email"||e.type==="number"||e.type==="url"?t.jsx(K,{question:e}):e.type==="select"?t.jsx(V,{question:e}):e.type==="rating"?t.jsx(W,{question:e}):t.jsxs("div",{className:"p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded",children:["Unsupported question type: ",e.type," (ID: ",e.id,")"]})})]})}const G={next:"Next",back:"Back",submit:"Submit",required:"Required",optional:"Optional",stepInfo:"Question {{current}} of {{total}}"};function X({schema:e,onSubmit:m}){var A;const s=H({schema:e,onSubmit:m}),r=e.theme||{backgroundColor:"#ffffff",textColor:"#000000",primaryColor:"#000000",borderRadius:"8px"},p=g(g({},G),e.i18n),i={backgroundColor:r.backgroundColor,color:r.textColor,fontFamily:r.fontFamily,"--color-sw-primary":r.primaryColor,"--color-sw-background":r.backgroundColor,"--color-sw-text-primary":r.primaryColor,"--color-sw-text-secondary":r.textColor,"--font-sw-heading":r.fontFamily||"inherit","--font-sw-body":r.fontFamily||"inherit"},f=r.buttonVariant==="outline",u={backgroundColor:f?"transparent":r.primaryColor,color:f?r.primaryColor:r.textColor,border:f?`2px solid ${r.primaryColor}`:"none",borderRadius:r.borderRadius||"8px",fontWeight:600},x={color:r.primaryColor,borderRadius:r.borderRadius||"8px",fontWeight:600},{autoReload:y,reloadDelay:h=3e3}=e;if(o.useEffect(()=>{if(s.isCompleted&&y){const N=setTimeout(()=>{s.resetForm()},h);return()=>clearTimeout(N)}},[s.isCompleted,y,h,s.resetForm]),s.isCompleted)return t.jsxs("div",{className:"flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",style:i,children:[y&&t.jsx(l.motion.div,{initial:{width:"0%"},animate:{width:"100%"},transition:{duration:h/1e3,ease:"linear"},className:"absolute top-0 left-0 h-1 bg-green-500 z-50"}),t.jsxs(l.motion.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},transition:{duration:.6,ease:[.22,1,.36,1]},className:"flex flex-col items-center",children:[t.jsx("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:t.jsx(I.Check,{size:48})}),t.jsx("h1",{className:"text-4xl md:text-5xl font-bold mb-4 tracking-tight",children:"Obrigado!"}),t.jsx("p",{className:"text-xl opacity-70 max-w-md leading-relaxed",children:"Suas respostas foram enviadas com sucesso."})]})]});const C=e.questions.find(N=>N.id===s.currentStepId),k=(e.questions.findIndex(N=>N.id===s.currentStepId)+1)/e.questions.length*100;return t.jsx($.Provider,{value:b(g({},s),{schema:e}),children:t.jsxs("div",{className:"w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",style:i,children:[t.jsxs("div",{className:"absolute top-0 left-0 w-full h-1 z-50",children:[t.jsx("div",{className:"absolute top-0 left-0 w-full h-full bg-current opacity-10"}),t.jsx(l.motion.div,{className:"h-full relative z-10",initial:{width:0},animate:{width:`${k}%`},transition:{duration:.5,ease:"easeInOut"},style:{backgroundColor:r.primaryColor}})]}),t.jsx("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:t.jsx(l.AnimatePresence,{mode:"wait",children:C&&t.jsx(l.motion.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},exit:{opacity:0,y:-40},transition:{duration:.5,ease:[.22,1,.36,1]},className:"w-full",children:t.jsx(U,{question:C})},C.id)})}),t.jsxs("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:[r.showPoweredBy!==!1&&t.jsxs("a",{href:"#",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",children:[t.jsx("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"}),t.jsx("span",{className:"text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",style:{color:r.brandColor||r.primaryColor},children:((A=r.poweredBy)==null?void 0:A.replace("Powered by ",""))||"SAWABONA TECH"})]}),t.jsxs("div",{className:"flex items-center gap-4 order-2 md:order-3 ml-auto",children:[t.jsx(l.motion.button,{onClick:s.prevStep,disabled:s.history.length===0,whileHover:{scale:1.05},whileTap:{scale:.95},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",style:x,children:t.jsx(I.ChevronLeft,{size:24})}),t.jsxs(l.motion.button,{onClick:s.nextStep,whileHover:{scale:1.02},whileTap:{scale:.98},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",style:u,children:[t.jsx("span",{children:s.currentStepId===e.questions[e.questions.length-1].id?r.submitText||p.submit:p.next}),s.currentStepId!==e.questions[e.questions.length-1].id&&t.jsx(I.ChevronRight,{size:20,strokeWidth:3})]})]})]})]})})}n.FormRenderer=X,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
14
+ `,children:h&&t.jsx(I.Check,{size:14,className:"text-sw-background"})}),x.label]}),t.jsxs("span",{className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono uppercase tracking-widest text-sw-text-secondary/50",children:["Select ",t.jsxs("span",{className:"hidden md:inline",children:["Key ",y+1]})]})]},String(x.value))})})}function V({question:e}){var i;const{answers:m,setAnswer:s}=F(),r=m[e.id]||0,p=Math.min(((i=e.validation)==null?void 0:i.max)||5,20);return t.jsxs("div",{className:"flex flex-col gap-6",children:[t.jsx("div",{className:"flex gap-4 flex-wrap",children:Array.from({length:p}).map((f,u)=>{const x=u+1,y=x<=r;return t.jsx(l.motion.button,{initial:{opacity:0,scale:0},animate:{opacity:1,scale:1},transition:{delay:u*.05},onClick:()=>s(e.id,x),whileHover:{scale:1.2,rotate:5},whileTap:{scale:.9},className:"focus:outline-none",children:t.jsx(I.Star,{className:`w-12 h-12 md:w-16 md:h-16 transition-all duration-300 ${y?"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"}`,strokeWidth:1.5})},u)})}),t.jsxs("div",{className:"flex justify-between w-full max-w-[300px] md:max-w-[400px] px-2 items-center",children:[t.jsx("span",{className:"text-sm md:text-base font-medium text-sw-text-secondary/50 uppercase tracking-wide",children:e.minLabel||"Poor"}),t.jsx(l.motion.div,{initial:{opacity:0,scale:.8},animate:{opacity:r?1:0,scale:r?1:.8},className:"font-bold text-primary text-xl",children:r?`${r} / ${p}`:""}),t.jsx("span",{className:"text-sm md:text-base font-medium text-muted-foreground uppercase tracking-wide",children:e.maxLabel||"Excellent"})]})]})}function W({question:e}){const{schema:m}=F(),s=m.questions.findIndex(u=>u.id===e.id)+1,r=m.questions.length,p={hidden:{opacity:0,y:20},visible:{opacity:1,y:0,transition:{duration:.5,ease:[.22,1,.36,1]}}},i=u=>u&&u.replace(/\{\{(\w+)\}\}/g,(x,y)=>{const h=f.answers[y];return h!=null?String(h):""}),f=F();return t.jsxs(l.motion.div,{className:"flex flex-col gap-8 w-full max-w-4xl mx-auto",initial:"hidden",animate:"visible",variants:{visible:{transition:{staggerChildren:.1}}},children:[t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(l.motion.div,{variants:p,className:"flex gap-4 items-baseline",children:t.jsxs("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:[t.jsx("span",{children:s}),t.jsx("span",{className:"opacity-40 text-xs",children:"/"}),t.jsx("span",{className:"opacity-60",children:r})]})}),t.jsxs(l.motion.h2,{variants:p,className:"text-3xl md:text-4xl lg:text-5xl font-bold leading-tight tracking-tight text-pretty mt-2 font-sw-heading",children:[i(e.title)," ",t.jsx("span",{className:"text-sw-primary",children:"*"})]}),e.description&&t.jsx(l.motion.p,{variants:p,className:"text-lg md:text-xl text-muted-foreground font-normal leading-relaxed max-w-2xl mt-2",children:i(e.description)})]}),t.jsx(l.motion.div,{variants:p,className:"w-full mt-6",children:e.type==="text"||e.type==="email"||e.type==="number"||e.type==="url"?t.jsx(K,{question:e}):e.type==="select"?t.jsx(U,{question:e}):e.type==="rating"?t.jsx(V,{question:e}):t.jsxs("div",{className:"p-4 bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 rounded",children:["Unsupported question type: ",e.type," (ID: ",e.id,")"]})})]})}const G={next:"Next",back:"Back",submit:"Submit",required:"Required",optional:"Optional",stepInfo:"Question {{current}} of {{total}}"};function X({schema:e,onSubmit:m}){var A;const s=H({schema:e,onSubmit:m}),r=e.theme||{backgroundColor:"#ffffff",textColor:"#000000",primaryColor:"#000000",borderRadius:"8px"},p=g(g({},G),e.i18n),i={backgroundColor:r.backgroundColor,color:r.textColor,fontFamily:r.fontFamily,"--color-sw-primary":r.primaryColor,"--color-sw-background":r.backgroundColor,"--color-sw-text-primary":r.primaryColor,"--color-sw-text-secondary":r.textColor,"--font-sw-heading":r.fontFamily||"inherit","--font-sw-body":r.fontFamily||"inherit"},f=r.buttonVariant==="outline",u={backgroundColor:f?"transparent":r.primaryColor,color:f?r.primaryColor:r.textColor,border:f?`2px solid ${r.primaryColor}`:"none",borderRadius:r.borderRadius||"8px",fontWeight:600},x={color:r.primaryColor,borderRadius:r.borderRadius||"8px",fontWeight:600},{autoReload:y,reloadDelay:h=3e3}=e;if(o.useEffect(()=>{if(s.isCompleted&&y){const N=setTimeout(()=>{s.resetForm()},h);return()=>clearTimeout(N)}},[s.isCompleted,y,h,s.resetForm]),s.isCompleted)return t.jsxs("div",{className:"flex flex-col items-center justify-center h-full w-full p-8 text-center relative overflow-hidden",style:i,children:[y&&t.jsx(l.motion.div,{initial:{width:"0%"},animate:{width:"100%"},transition:{duration:h/1e3,ease:"linear"},className:"absolute top-0 left-0 h-1 bg-green-500 z-50"}),t.jsxs(l.motion.div,{initial:{scale:.9,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},transition:{duration:.6,ease:[.22,1,.36,1]},className:"flex flex-col items-center",children:[t.jsx("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:t.jsx(I.Check,{size:48})}),t.jsx("h1",{className:"text-4xl md:text-5xl font-bold mb-4 tracking-tight",children:"Obrigado!"}),t.jsx("p",{className:"text-xl opacity-70 max-w-md leading-relaxed",children:"Suas respostas foram enviadas com sucesso."})]})]});const C=e.questions.find(N=>N.id===s.currentStepId),k=(e.questions.findIndex(N=>N.id===s.currentStepId)+1)/e.questions.length*100;return t.jsx(P.Provider,{value:b(g({},s),{schema:e}),children:t.jsxs("div",{className:"w-full h-full flex flex-col relative overflow-hidden transition-colors duration-700",style:i,children:[t.jsxs("div",{className:"absolute top-0 left-0 w-full h-1 z-50",children:[t.jsx("div",{className:"absolute top-0 left-0 w-full h-full bg-current opacity-10"}),t.jsx(l.motion.div,{className:"h-full relative z-10",initial:{width:0},animate:{width:`${k}%`},transition:{duration:.5,ease:"easeInOut"},style:{backgroundColor:r.primaryColor}})]}),t.jsx("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:t.jsx(l.AnimatePresence,{mode:"wait",children:C&&t.jsx(l.motion.div,{initial:{opacity:0,y:40},animate:{opacity:1,y:0},exit:{opacity:0,y:-40},transition:{duration:.5,ease:[.22,1,.36,1]},className:"w-full",children:t.jsx(W,{question:C})},C.id)})}),t.jsxs("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:[r.showPoweredBy!==!1&&t.jsxs("a",{href:r.poweredByUrl||"#",target:r.poweredByUrl?"_blank":void 0,rel:r.poweredByUrl?"noopener noreferrer":void 0,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",children:[t.jsx("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"}),t.jsx("span",{className:"text-[10px] md:text-xs font-mono font-bold tracking-[0.2em] uppercase transition-colors shadow-sw-primary",style:{color:r.brandColor||r.primaryColor},children:((A=r.poweredBy)==null?void 0:A.replace("Powered by ",""))||"SAWABONA TECH"})]}),t.jsxs("div",{className:"flex items-center gap-4 order-2 md:order-3 ml-auto",children:[t.jsx(l.motion.button,{onClick:s.prevStep,disabled:s.history.length===0,whileHover:{scale:1.05},whileTap:{scale:.95},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",style:x,children:t.jsx(I.ChevronLeft,{size:24})}),t.jsxs(l.motion.button,{onClick:s.nextStep,whileHover:{scale:1.02},whileTap:{scale:.98},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",style:u,children:[t.jsx("span",{children:s.currentStepId===e.questions[e.questions.length-1].id?r.submitText||p.submit:p.next}),s.currentStepId!==e.questions[e.questions.length-1].id&&t.jsx(I.ChevronRight,{size:20,strokeWidth:3})]})]})]})]})})}n.FormRenderer=X,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sawabona/forms",
3
3
  "private": false,
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "main": "./dist/sawabona-forms.umd.js",
7
7
  "module": "./dist/sawabona-forms.es.js",