easy-forms-core 1.2.14 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/easy-form.d.ts +46 -2
- package/dist/easy-form.js +88 -62
- package/dist/easy-form.js.map +1 -1
- package/dist/index.d.ts +103 -6
- package/dist/index.js +75 -49
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/easy-form.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
var
|
|
1
|
+
var V=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&!t.steps)throw new Error("Schema debe tener fields o steps");if(t.steps){for(let r of t.steps)if(!r.fields||r.fields.length===0)throw new Error("Cada step debe tener al menos un field")}let e=t.fields?this.normalizeFields(t.fields):[],a=t.steps?t.steps.map(r=>({...r,fields:this.normalizeFields(r.fields)})):void 0;return{fields:e,steps:a,isWizard:!!(t.steps&&t.steps.length>0)}}normalizeFields(t){return t.map((e,a)=>{if(!e.type)throw new Error(`Field en \xEDndice ${a} debe tener un type`);if(!e.name)throw new Error(`Field en \xEDndice ${a} debe tener un name`);return this.validateFieldType(e,a),this.applyDefaults(e)})}validateFieldType(t,e){if(!["text","email","number","password","textarea","select","checkbox","radio","switch","date","file","file-drop","map","rating","slider","colorpicker","array","group","row","custom","quantity","accordion-select","image-grid-select","otp"].includes(t.type))throw new Error(`Field en \xEDndice ${e} tiene un type inv\xE1lido: ${t.type}`);switch(t.type){case"select":case"radio":case"accordion-select":case"image-grid-select":if(!("options"in t)||!t.options||t.options.length===0)throw new Error(`Field "${t.name}" de tipo ${t.type} debe tener options`);break;case"array":if(!("itemSchema"in t)||!t.itemSchema)throw new Error(`Field "${t.name}" de tipo array debe tener itemSchema`);if("minItems"in t){let r=t.minItems;if(r<0)throw new Error(`Field "${t.name}" de tipo array: minItems debe ser >= 0`);if("maxItems"in t){let s=t.maxItems;if(r>s)throw new Error(`Field "${t.name}" de tipo array: minItems (${r}) no puede ser mayor que maxItems (${s})`)}}break;case"group":if(!("fields"in t)||!t.fields||t.fields.length===0)throw new Error(`Field "${t.name}" de tipo group debe tener fields`);break;case"row":if(!("fields"in t)||!t.fields||t.fields.length===0)throw new Error(`Field "${t.name}" de tipo row debe tener fields`);break;case"colorpicker":if("defaultValue"in t&&t.defaultValue!=null&&!/^#[0-9A-Fa-f]{6}$/.test(String(t.defaultValue)))throw new Error(`Field "${t.name}" de tipo colorpicker debe tener defaultValue en formato hex (#RRGGBB)`);break}"leadingIcon"in t&&t.leadingIcon&&this.validateSlotContent(t.leadingIcon,t.name,"leadingIcon"),"trailingIcon"in t&&t.trailingIcon&&this.validateSlotContent(t.trailingIcon,t.name,"trailingIcon")}validateSlotContent(t,e,a){if(!t.type||!["image","html"].includes(t.type))throw new Error(`Field "${e}" ${a} debe tener type 'image' o 'html'`);if(t.type==="image"&&(!t.src||typeof t.src!="string"))throw new Error(`Field "${e}" ${a} con type 'image' debe tener src`);if(t.type==="html"&&(!t.html||typeof t.html!="string"))throw new Error(`Field "${e}" ${a} con type 'html' debe tener html`)}applyDefaults(t){let e={disabled:!1,hidden:!1};switch(t.type){case"checkbox":case"switch":"checked"in t||(e.checked=!1);break;case"select":case"accordion-select":case"image-grid-select":"multiple"in t||(e.multiple=!1),t.type==="image-grid-select"&&("columns"in t||(e.columns=3),"imageSize"in t||(e.imageSize="medium"));break;case"file":"multiple"in t||(e.multiple=!1);break;case"quantity":"min"in t||(e.min=0),"step"in t||(e.step=1);break;case"otp":"length"in t||(e.length=6),"numeric"in t||(e.numeric=!0);break;case"slider":"min"in t||(e.min=0),"max"in t||(e.max=100),"step"in t||(e.step=1);break;case"rating":"max"in t||(e.max=5);break;case"colorpicker":(!("defaultValue"in t)||t.defaultValue==null)&&(e.defaultValue="#000000");break}return{...e,...t}}getAllFields(t){let e=this.parse(t),a=[],r=s=>{for(let o of s)a.push(o),o.type==="group"&&"fields"in o&&r(o.fields),o.type==="row"&&"fields"in o&&r(o.fields),o.type==="array"&&"itemSchema"in o&&o.itemSchema.fields&&r(o.itemSchema.fields)};if(e.fields&&r(e.fields),e.steps)for(let s of e.steps)r(s.fields);return a}};function He(c){let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(c);if(!t){let e=/^#?([a-f\d])([a-f\d])([a-f\d])$/i.exec(c);return e?[parseInt(e[1]+e[1],16),parseInt(e[2]+e[2],16),parseInt(e[3]+e[3],16)].join(", "):"0, 123, 255"}return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)].join(", ")}var Be={primary:"#007bff",secondary:"#6c757d",error:"#dc3545",success:"#28a745",text:"#212529",labelColor:"#212529",border:"#ddd",background:"#ffffff",groupBackground:"var(--easy-form-group-background)",groupTitle:"#212529",groupBorder:"#ddd"};function I(c){return{...Be,...c}}function ye(c){return`
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
|
-
--easy-form-primary: ${
|
|
5
|
-
--easy-form-primary-rgb: ${
|
|
6
|
-
--easy-form-secondary: ${
|
|
7
|
-
--easy-form-error: ${
|
|
8
|
-
--easy-form-success: ${
|
|
9
|
-
--easy-form-text: ${
|
|
10
|
-
--easy-form-label-color: ${
|
|
11
|
-
--easy-form-border: ${
|
|
12
|
-
--easy-form-background: ${
|
|
13
|
-
--easy-form-group-background: ${
|
|
14
|
-
--easy-form-group-title: ${
|
|
15
|
-
--easy-form-group-border: ${
|
|
4
|
+
--easy-form-primary: ${c.primary};
|
|
5
|
+
--easy-form-primary-rgb: ${He(c.primary)};
|
|
6
|
+
--easy-form-secondary: ${c.secondary};
|
|
7
|
+
--easy-form-error: ${c.error};
|
|
8
|
+
--easy-form-success: ${c.success};
|
|
9
|
+
--easy-form-text: ${c.text};
|
|
10
|
+
--easy-form-label-color: ${c.labelColor};
|
|
11
|
+
--easy-form-border: ${c.border};
|
|
12
|
+
--easy-form-background: ${c.background};
|
|
13
|
+
--easy-form-group-background: ${c.groupBackground};
|
|
14
|
+
--easy-form-group-title: ${c.groupTitle};
|
|
15
|
+
--easy-form-group-border: ${c.groupBorder};
|
|
16
16
|
--easy-form-on-primary: #ffffff;
|
|
17
17
|
--easy-form-hover-overlay: rgba(0, 0, 0, 0.03);
|
|
18
18
|
}
|
|
@@ -551,35 +551,40 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
551
551
|
|
|
552
552
|
/* Timeline Style - Horizontal */
|
|
553
553
|
.easy-form-wizard-steps.ef-stepper-timeline {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
554
|
+
display: flex;
|
|
555
|
+
position: relative;
|
|
556
|
+
padding: 16px 0;
|
|
557
|
+
}
|
|
558
|
+
.easy-form-wizard-steps.ef-stepper-timeline::before {
|
|
559
|
+
content: "";
|
|
560
|
+
position: absolute;
|
|
561
|
+
top: 37px;
|
|
562
|
+
left: 15%;
|
|
563
|
+
right: 15%;
|
|
564
|
+
height: 2px;
|
|
565
|
+
background: var(--easy-form-text);
|
|
566
|
+
opacity: 0.2;
|
|
559
567
|
}
|
|
560
568
|
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step {
|
|
561
|
-
|
|
569
|
+
flex: 1;
|
|
562
570
|
display: flex;
|
|
563
571
|
flex-direction: column;
|
|
564
572
|
align-items: center;
|
|
565
|
-
|
|
573
|
+
text-align: center;
|
|
566
574
|
background: transparent !important;
|
|
567
575
|
color: var(--easy-form-text) !important;
|
|
568
576
|
border: none !important;
|
|
569
|
-
|
|
577
|
+
position: relative;
|
|
578
|
+
z-index: 1;
|
|
570
579
|
}
|
|
571
580
|
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step::before {
|
|
572
581
|
content: "";
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
height: 16px;
|
|
582
|
+
width: 24px;
|
|
583
|
+
height: 24px;
|
|
576
584
|
border-radius: 50%;
|
|
577
|
-
background: var(--easy-form-
|
|
578
|
-
border: 2px solid var(--easy-form-
|
|
579
|
-
|
|
580
|
-
margin-bottom: 0.25rem;
|
|
581
|
-
flex-shrink: 0;
|
|
582
|
-
transition: all 0.2s ease;
|
|
585
|
+
background: var(--easy-form-background);
|
|
586
|
+
border: 2px solid var(--easy-form-text);
|
|
587
|
+
margin-bottom: 8px;
|
|
583
588
|
}
|
|
584
589
|
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step.completed::before {
|
|
585
590
|
background: var(--easy-form-success);
|
|
@@ -588,8 +593,8 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
588
593
|
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step.active::before {
|
|
589
594
|
background: var(--easy-form-primary);
|
|
590
595
|
border-color: var(--easy-form-primary);
|
|
591
|
-
width:
|
|
592
|
-
height:
|
|
596
|
+
width: 28px;
|
|
597
|
+
height: 28px;
|
|
593
598
|
}
|
|
594
599
|
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step.active {
|
|
595
600
|
color: var(--easy-form-primary) !important;
|
|
@@ -598,22 +603,6 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
598
603
|
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step.completed {
|
|
599
604
|
color: var(--easy-form-success) !important;
|
|
600
605
|
}
|
|
601
|
-
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step::after {
|
|
602
|
-
content: "";
|
|
603
|
-
position: absolute;
|
|
604
|
-
top: 8px;
|
|
605
|
-
left: calc(50% + 14px);
|
|
606
|
-
width: calc(100% - 28px);
|
|
607
|
-
height: 2px;
|
|
608
|
-
background: var(--easy-form-border);
|
|
609
|
-
z-index: 0;
|
|
610
|
-
}
|
|
611
|
-
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step:last-child::after {
|
|
612
|
-
display: none;
|
|
613
|
-
}
|
|
614
|
-
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step.completed::after {
|
|
615
|
-
background: var(--easy-form-success);
|
|
616
|
-
}
|
|
617
606
|
.easy-form-wizard-steps.ef-stepper-timeline .easy-form-wizard-step .step-number {
|
|
618
607
|
display: none;
|
|
619
608
|
}
|
|
@@ -1055,10 +1044,47 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1055
1044
|
opacity: 0.6;
|
|
1056
1045
|
cursor: not-allowed !important;
|
|
1057
1046
|
}
|
|
1047
|
+
.easy-form-timer {
|
|
1048
|
+
display: flex;
|
|
1049
|
+
align-items: center;
|
|
1050
|
+
justify-content: center;
|
|
1051
|
+
padding: 0.75rem 1rem;
|
|
1052
|
+
margin-bottom: 1rem;
|
|
1053
|
+
background: var(--easy-form-primary);
|
|
1054
|
+
color: var(--easy-form-on-primary);
|
|
1055
|
+
border-radius: 4px;
|
|
1056
|
+
font-size: 1.25rem;
|
|
1057
|
+
font-weight: 600;
|
|
1058
|
+
font-family: ui-monospace, 'Cascadia Code', 'Fira Code', 'Courier New', monospace;
|
|
1059
|
+
}
|
|
1060
|
+
.easy-form-timer-warning {
|
|
1061
|
+
background: #f59e0b;
|
|
1062
|
+
color: #fff;
|
|
1063
|
+
}
|
|
1064
|
+
.easy-form-timer-danger {
|
|
1065
|
+
background: var(--easy-form-error);
|
|
1066
|
+
color: #fff;
|
|
1067
|
+
animation: easy-form-timer-pulse 1s ease-in-out infinite;
|
|
1068
|
+
}
|
|
1069
|
+
.easy-form-timer-expired {
|
|
1070
|
+
background: var(--easy-form-error) !important;
|
|
1071
|
+
color: #fff !important;
|
|
1072
|
+
}
|
|
1073
|
+
.easy-form-timer-expired ~ .easy-form-submit-wrapper {
|
|
1074
|
+
display: none;
|
|
1075
|
+
}
|
|
1076
|
+
@keyframes easy-form-timer-pulse {
|
|
1077
|
+
0%, 100% {
|
|
1078
|
+
opacity: 1;
|
|
1079
|
+
}
|
|
1080
|
+
50% {
|
|
1081
|
+
opacity: 0.7;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1058
1084
|
form {
|
|
1059
1085
|
position: relative;
|
|
1060
1086
|
}
|
|
1061
|
-
`}function de(
|
|
1087
|
+
`}function de(c){return`
|
|
1062
1088
|
.easy-form-label {
|
|
1063
1089
|
color: var(--easy-form-label-color);
|
|
1064
1090
|
}
|
|
@@ -1091,7 +1117,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1091
1117
|
border-bottom: 1px solid var(--easy-form-group-border);
|
|
1092
1118
|
border-radius: 0;
|
|
1093
1119
|
}
|
|
1094
|
-
`}function
|
|
1120
|
+
`}function ge(c){return`
|
|
1095
1121
|
.easy-form-label {
|
|
1096
1122
|
color: var(--easy-form-label-color);
|
|
1097
1123
|
}
|
|
@@ -1126,7 +1152,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1126
1152
|
border-radius: 4px;
|
|
1127
1153
|
background: var(--easy-form-group-background);
|
|
1128
1154
|
}
|
|
1129
|
-
`}function
|
|
1155
|
+
`}function be(c){return`
|
|
1130
1156
|
.easy-form-label {
|
|
1131
1157
|
font-size: 0.875rem;
|
|
1132
1158
|
font-weight: 500;
|
|
@@ -1211,7 +1237,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1211
1237
|
background: transparent;
|
|
1212
1238
|
border: none;
|
|
1213
1239
|
}
|
|
1214
|
-
`}function ve(
|
|
1240
|
+
`}function ve(c){return`
|
|
1215
1241
|
.easy-form-label {
|
|
1216
1242
|
color: var(--easy-form-label-color);
|
|
1217
1243
|
}
|
|
@@ -1263,7 +1289,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1263
1289
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
1264
1290
|
background: var(--easy-form-group-background);
|
|
1265
1291
|
}
|
|
1266
|
-
`}function xe(
|
|
1292
|
+
`}function xe(c){return`
|
|
1267
1293
|
.easy-form-field {
|
|
1268
1294
|
border-bottom: 1px solid var(--easy-form-border);
|
|
1269
1295
|
padding-bottom: 1rem;
|
|
@@ -1375,7 +1401,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1375
1401
|
border: none;
|
|
1376
1402
|
padding: 0;
|
|
1377
1403
|
}
|
|
1378
|
-
`}function we(
|
|
1404
|
+
`}function we(c){return`
|
|
1379
1405
|
.easy-form-label {
|
|
1380
1406
|
color: var(--easy-form-label-color);
|
|
1381
1407
|
font-size: 0.875rem;
|
|
@@ -1508,7 +1534,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1508
1534
|
transform: translateY(-2px);
|
|
1509
1535
|
background: linear-gradient(135deg, color-mix(in srgb, var(--easy-form-primary) 75%, black) 0%, var(--easy-form-primary) 100%);
|
|
1510
1536
|
}
|
|
1511
|
-
`}function ke(
|
|
1537
|
+
`}function ke(c){return`
|
|
1512
1538
|
.easy-form-label {
|
|
1513
1539
|
color: var(--easy-form-label-color);
|
|
1514
1540
|
font-size: 0.875rem;
|
|
@@ -1604,7 +1630,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1604
1630
|
border-color: var(--easy-form-group-border);
|
|
1605
1631
|
box-shadow: 0 2px 8px rgba(var(--easy-form-primary-rgb), 0.15);
|
|
1606
1632
|
}
|
|
1607
|
-
`}function Ee(
|
|
1633
|
+
`}function Ee(c){return`
|
|
1608
1634
|
.easy-form-label {
|
|
1609
1635
|
color: var(--easy-form-label-color);
|
|
1610
1636
|
font-size: 0.875rem;
|
|
@@ -1681,7 +1707,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1681
1707
|
background: var(--easy-form-group-background);
|
|
1682
1708
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.8);
|
|
1683
1709
|
}
|
|
1684
|
-
`}function
|
|
1710
|
+
`}function Se(c){return`
|
|
1685
1711
|
.easy-form-label {
|
|
1686
1712
|
color: var(--easy-form-label-color);
|
|
1687
1713
|
font-size: 0.875rem;
|
|
@@ -1837,7 +1863,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1837
1863
|
.easy-form-wizard-next:hover {
|
|
1838
1864
|
background: rgba(var(--easy-form-primary-rgb), 0.35);
|
|
1839
1865
|
}
|
|
1840
|
-
`}function
|
|
1866
|
+
`}function Ce(c){return`
|
|
1841
1867
|
.easy-form-label {
|
|
1842
1868
|
color: var(--easy-form-label-color);
|
|
1843
1869
|
font-size: 0.875rem;
|
|
@@ -1922,7 +1948,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
1922
1948
|
background: var(--easy-form-group-background);
|
|
1923
1949
|
box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
|
|
1924
1950
|
}
|
|
1925
|
-
`}function Fe(
|
|
1951
|
+
`}function Fe(c){return`
|
|
1926
1952
|
.easy-form-label {
|
|
1927
1953
|
color: var(--easy-form-label-color);
|
|
1928
1954
|
font-size: 0.75rem;
|
|
@@ -2123,7 +2149,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
2123
2149
|
border: none;
|
|
2124
2150
|
padding: 0;
|
|
2125
2151
|
}
|
|
2126
|
-
`}function Le(
|
|
2152
|
+
`}function Le(c){return`
|
|
2127
2153
|
.easy-form-label {
|
|
2128
2154
|
color: var(--easy-form-label-color);
|
|
2129
2155
|
font-size: 0.875rem;
|
|
@@ -2320,7 +2346,7 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
2320
2346
|
background-position: right 1rem center;
|
|
2321
2347
|
padding-right: 2.5rem;
|
|
2322
2348
|
}
|
|
2323
|
-
`}function P(m,t){let e=ye(t),a=Oe(m,t);return e+a}function Oe(m,t){switch(m){case"plano":return de(t);case"tradicional":return be(t);case"material":return ge(t);case"rounded-shadow":return ve(t);case"lines":return xe(t);case"shadcn":return we(t);case"chakra":return ke(t);case"mantine":return Ee(t);case"glass":return Ce(t);case"bordered":return Se(t);case"minimal":return Fe(t);case"efc":return Le(t);default:return de(t)}}var Me={phone:{pattern:"(999) 999-9999",placeholder:"_"},"phone-us":{pattern:"(999) 999-9999",placeholder:"_"},"phone-international":{pattern:"+99 999 999 9999",placeholder:"_"},date:{pattern:"99/99/9999",placeholder:"_"},"date-us":{pattern:"99/99/9999",placeholder:"_"},"date-eu":{pattern:"99-99-9999",placeholder:"_"},"credit-card":{pattern:"9999 9999 9999 9999",placeholder:"_"},ssn:{pattern:"999-99-9999",placeholder:"_"},"zip-code":{pattern:"99999",placeholder:"_"},currency:{pattern:"$999,999.99",placeholder:"_",transform:m=>{let t=m.replace(/[^\d.]/g,"");return(parseFloat(t)||0).toFixed(2)}},percentage:{pattern:"999%",placeholder:"_",transform:m=>m.replace(/[^\d]/g,"")},time:{pattern:"99:99",placeholder:"_"},datetime:{pattern:"99/99/9999 99:99",placeholder:"_"}};function me(m){return Me[m]}var D="El valor contiene caracteres o patrones no permitidos",je=[/\b(union|select|insert|update|delete|drop|exec|execute|declare)\s+(all\s+)?(select|from|into|table)/i,/\b(or|and)\s+['"]?\d+['"]?\s*=\s*['"]?\d+/i,/;\s*(drop|delete|truncate|alter)\s+/i,/--\s*$/,/\/\*[\s\S]*\*\//,/'\s*or\s+'1'\s*=\s*'1/i,/"\s*or\s+"1"\s*=\s*"1/i,/\bexec\s*\(/i,/\bxp_\w+/i,/<script\b[\s\S]*?>[\s\S]*?<\/script>/i,/<script\b/i,/javascript\s*:/i,/vbscript\s*:/i,/on\w+\s*=\s*["'][^"']*["']/i,/on\w+\s*=\s*[^\s>]+/i,/<iframe\b/i,/<object\b/i,/<embed\b/i,/\beval\s*\(/i,/document\.(cookie|write|location)/i,/window\.(location|open|eval)/i,/[;&|]\s*(ls|cat|rm|wget|curl|nc|bash|sh|python|perl)\s/i,/\$\s*\([^)]+\)/,/`[^`]+`/,/\|\s*\w+/,/\$\s*where\b/i,/\$\s*gt\b|\$\s*ne\b|\$\s*regex\b/i,/\{\{[^}]*\}\}/,/\$\{[^}]*\}/];function ze(m){if(typeof m!="string"||m.length===0||m.trim().length===0)return!1;for(let e of je)if(e.test(m))return!0;return!1}function N(m){return m==null?!0:typeof m=="string"?!ze(m):Array.isArray(m)?m.every(t=>N(t)):typeof m=="object"?Object.values(m).every(t=>N(t)):!0}var q=class{constructor(t){this.attempts=0;this.lockedUntil=null;this.unlockCheckInterval=null;this.maxAttempts=Math.max(1,t.maxAttempts),this.blockDurationMs=(t.blockDurationMinutes??5)*60*1e3,this.storageKey=t.storageKey,this.onLocked=t.onLocked,this.onUnlocked=t.onUnlocked,this.storageKey&&typeof sessionStorage<"u"&&this.loadFromStorage()}loadFromStorage(){if(!(!this.storageKey||typeof sessionStorage>"u"))try{let t=sessionStorage.getItem(this.storageKey);if(t){let e=JSON.parse(t);this.attempts=e.attempts??0,this.lockedUntil=e.lockedUntil??null,this.checkExpiration()}}catch{}}saveToStorage(){if(!(!this.storageKey||typeof sessionStorage>"u"))try{let t={attempts:this.attempts,lockedUntil:this.lockedUntil??void 0};sessionStorage.setItem(this.storageKey,JSON.stringify(t))}catch{}}checkExpiration(){return this.lockedUntil===null?!1:Date.now()>=this.lockedUntil?(this.reset(),this.onUnlocked?.(),!0):!1}startUnlockCheck(){this.unlockCheckInterval||(this.unlockCheckInterval=setInterval(()=>{this.checkExpiration()&&this.stopUnlockCheck()},1e3))}stopUnlockCheck(){this.unlockCheckInterval&&(clearInterval(this.unlockCheckInterval),this.unlockCheckInterval=null)}incrementAttempts(){this.attempts++,this.attempts>=this.maxAttempts?(this.lockedUntil=Date.now()+this.blockDurationMs,this.saveToStorage(),this.onLocked?.(this.blockDurationMs),this.startUnlockCheck()):this.saveToStorage()}isLocked(){return this.checkExpiration()?!1:this.lockedUntil!==null&&Date.now()<this.lockedUntil}getRemainingBlockTimeMs(){return this.checkExpiration()||this.lockedUntil===null?0:Math.max(0,this.lockedUntil-Date.now())}reset(){this.attempts=0,this.lockedUntil=null,this.stopUnlockCheck(),this.saveToStorage()}getAttempts(){return this.attempts}};function L(m){return m==null?"":typeof m=="boolean"?m?"true":"false":typeof m=="object"?JSON.stringify(m):String(m)}function F(m){if(!m)return null;try{return JSON.parse(m)}catch{return m}}function M(m,t){return t.split(".").reduce((e,a)=>e?.[a],m)}function z(m,t,e){let a=t.split("."),r=a.pop(),s=a.reduce((o,i)=>((!o[i]||typeof o[i]!="object")&&(o[i]={}),o[i]),m);s[r]=e}function Ae(m){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(m)}var A=class{evaluateCondition(t,e){let a=this.getFieldValue(t.field,e);return this.compareValues(a,t.operator,t.value)}evaluateConditions(t,e,a="and"){let r=Array.isArray(t)?t:[t];return r.length===0?!0:a==="and"?r.every(s=>this.evaluateCondition(s,e)):r.some(s=>this.evaluateCondition(s,e))}evaluateDependencies(t,e){let a=!0,r=!0,s=!1;if(t.show&&(a=this.evaluateConditions(t.show,e)),t.hide){let o=this.evaluateConditions(t.hide,e);a=a&&!o}if(t.enable&&(r=this.evaluateConditions(t.enable,e)),t.disable){let o=this.evaluateConditions(t.disable,e);r=r&&!o}if(t.required&&(s=this.evaluateConditions(t.required,e)),t.optional){let o=this.evaluateConditions(t.optional,e);s=s&&!o}return{visible:a,enabled:r,required:s}}getFieldValue(t,e){let a=t.split("."),r=e;for(let s of a){if(r==null)return null;r=r[s]}return r}compareValues(t,e,a){switch(e){case"equals":return this.deepEqual(t,a);case"notEquals":return!this.deepEqual(t,a);case"contains":return Array.isArray(t)?t.includes(a):typeof t=="string"?t.includes(String(a)):!1;case"notContains":return!this.compareValues(t,"contains",a);case"greaterThan":return this.toNumber(t)>this.toNumber(a);case"lessThan":return this.toNumber(t)<this.toNumber(a);case"greaterThanOrEqual":return this.toNumber(t)>=this.toNumber(a);case"lessThanOrEqual":return this.toNumber(t)<=this.toNumber(a);case"in":return Array.isArray(a)?a.includes(t):!1;case"notIn":return!this.compareValues(t,"in",a);case"isEmpty":return t==null||t===""||Array.isArray(t)&&t.length===0;case"isNotEmpty":return!this.compareValues(t,"isEmpty",a);case"regex":try{return(typeof a=="string"?new RegExp(a):a).test(String(t||""))}catch{return!1}default:return!1}}deepEqual(t,e){if(t===e)return!0;if(t===null||e===null||t===void 0||e===void 0)return t===e;if(typeof t!=typeof e)return!1;if(Array.isArray(t)&&Array.isArray(e))return t.length!==e.length?!1:t.every((a,r)=>this.deepEqual(a,e[r]));if(typeof t=="object"){let a=Object.keys(t),r=Object.keys(e);return a.length!==r.length?!1:a.every(s=>this.deepEqual(t[s],e[s]))}return!1}toNumber(t){if(typeof t=="number")return t;if(typeof t=="string"){let e=parseFloat(t);return isNaN(e)?0:e}return 0}};var H=class{constructor(){this.conditionEngine=new A}async validateField(t,e){return this.validateFieldWithValidations(t,e,t.validations||[])}async validateFieldWithValidations(t,e,a){let r=[];if(!a||a.length===0)return r;for(let s of a){let o=await this.validateValue(s,e);o.isValid||r.push(o.message||this.getDefaultMessage(s))}return r}async validateValue(t,e){switch(t.type){case"required":return this.validateRequired(e);case"email":return this.validateEmail(e);case"minLength":return this.validateMinLength(e,t.value);case"maxLength":return this.validateMaxLength(e,t.value);case"min":return this.validateMin(e,t.value);case"max":return this.validateMax(e,t.value);case"pattern":return this.validatePattern(e,t.value);case"custom":return await this.validateCustom(e,t);case"noInjection":return this.validateNoInjection(e,t);default:return{isValid:!0}}}validateRequired(t){let e=t!=null&&t!==""&&!(Array.isArray(t)&&t.length===0);return{isValid:e,message:e?void 0:"Este campo es requerido"}}validateEmail(t){if(!t)return{isValid:!0};let e=typeof t=="string"&&Ae(t);return{isValid:e,message:e?void 0:"Debe ser un email v\xE1lido"}}validateMinLength(t,e){if(!t)return{isValid:!0};let r=String(t).length>=e;return{isValid:r,message:r?void 0:`Debe tener al menos ${e} caracteres`}}validateMaxLength(t,e){if(!t)return{isValid:!0};let r=String(t).length<=e;return{isValid:r,message:r?void 0:`Debe tener m\xE1ximo ${e} caracteres`}}validateMin(t,e){if(t==null||t==="")return{isValid:!0};let a=Number(t),r=!isNaN(a)&&a>=e;return{isValid:r,message:r?void 0:`Debe ser mayor o igual a ${e}`}}validateMax(t,e){if(t==null||t==="")return{isValid:!0};let a=Number(t),r=!isNaN(a)&&a<=e;return{isValid:r,message:r?void 0:`Debe ser menor o igual a ${e}`}}validatePattern(t,e){if(!t)return{isValid:!0};let a;if(e instanceof RegExp)a=e;else if(typeof e=="string")try{a=new RegExp(e)}catch{return console.warn("Invalid regex pattern:",e),{isValid:!0}}else return console.warn("Pattern validation expects string or RegExp, got:",typeof e,e),{isValid:!0};let r=a.test(String(t));return{isValid:r,message:r?void 0:"El formato no es v\xE1lido"}}validateNoInjection(t,e){if(t==null||t==="")return{isValid:!0};let a=N(t);return{isValid:a,message:a?void 0:e.message||D}}async validateCustom(t,e){try{let a=await e.validator(t);return{isValid:!!a,message:a?void 0:e.message||"Validaci\xF3n fallida"}}catch{return{isValid:!1,message:e.message||"Error en la validaci\xF3n"}}}getDefaultMessage(t){switch(t.type){case"required":return"Este campo es requerido";case"email":return"Debe ser un email v\xE1lido";case"minLength":return`Debe tener al menos ${t.value} caracteres`;case"maxLength":return`Debe tener m\xE1ximo ${t.value} caracteres`;case"min":return`Debe ser mayor o igual a ${t.value}`;case"max":return`Debe ser menor o igual a ${t.value}`;case"pattern":return"El formato no es v\xE1lido";case"custom":return"Validaci\xF3n fallida";case"noInjection":return D;default:return"Campo inv\xE1lido"}}shouldValidateField(t,e){if(t.hidden||t.disabled)return!1;if(t.dependencies){let a=this.conditionEngine.evaluateDependencies(t.dependencies,e);if(!a.visible||!a.enabled)return!1}return!0}async validateForm(t,e){let a={};for(let r of t)if(this.shouldValidateField(r,e))if(r.type==="array"&&"itemSchema"in r){let i=r.itemSchema?.fields||[],n=e[r.name];if(Array.isArray(n))for(let d=0;d<n.length;d++){let c=n[d];for(let p of i){let u=`${r.name}.${d}.${p.name}`,h=c?.[p.name];if(!this.shouldValidateField(p,e))continue;let y=await this.validateField(p,h);y.length>0&&(a[u]=y)}}let l=await this.validateArrayField(r,n);l.length>0&&(a[r.name]=l)}else{let s=e[r.name],o=await this.validateField(r,s);o.length>0&&(a[r.name]=o)}return a}async validateArrayField(t,e){let a=[],r=t;return r.minItems!==void 0&&(Array.isArray(e)&&e.length>=r.minItems||a.push(`Debe tener al menos ${r.minItems} elementos`)),r.maxItems!==void 0&&(Array.isArray(e)&&e.length<=r.maxItems||a.push(`Debe tener m\xE1ximo ${r.maxItems} elementos`)),a}};var $=class{constructor(){this.wizardState=null;this.schema=null;this.dependencyCache=new Map;this.fieldDependencies=new Map;this.parser=new R,this.validator=new H,this.conditionEngine=new A,this.state=this.createInitialState()}createInitialState(){return{values:{},errors:{},touched:{},isValid:!0,isSubmitting:!1}}initializeSchema(t,e){this.schema=this.parser.parse(t),this.initializeValues(e),this.initializeWizard(),this.buildDependencyMap()}extractAllFields(t){let e=[];for(let a of t)e.push(a),a.type==="group"&&"fields"in a&&e.push(...this.extractAllFields(a.fields)),a.type==="row"&&"fields"in a&&e.push(...this.extractAllFields(a.fields));return e}getArrayItemOnlyFieldNames(t){let e=new Set(t.map(r=>r.name)),a=new Set;for(let r of t)if(r.type==="array"&&"itemSchema"in r&&r.itemSchema?.fields)for(let s of r.itemSchema.fields)e.has(s.name)||a.add(s.name);return a}findFieldPath(t,e,a=""){for(let r of e){let s=a?`${a}.${r.name}`:r.name;if(r.name===t)return s;if(r.type==="group"&&"fields"in r){let o=this.findFieldPath(t,r.fields,s);if(o)return o}if(r.type==="row"&&"fields"in r){let o=this.findFieldPath(t,r.fields,s);if(o)return o}}return null}buildDependencyMap(){if(this.fieldDependencies.clear(),this.dependencyCache.clear(),!this.schema)return;let t=this.schema.isWizard?this.schema.steps.flatMap(a=>a.fields):this.schema.fields||[],e=this.extractAllFields(t);for(let a of e){if(!a.dependencies)continue;let r=this.extractObservedFields(a.dependencies);for(let s of r)this.fieldDependencies.has(s)||this.fieldDependencies.set(s,new Set),this.fieldDependencies.get(s).add(a.name)}}extractObservedFields(t){let e=new Set,a=s=>{s&&s.field&&e.add(s.field)},r=s=>{Array.isArray(s)?s.forEach(a):s&&a(s)};return t.show&&r(t.show),t.hide&&r(t.hide),t.enable&&r(t.enable),t.disable&&r(t.disable),t.required&&r(t.required),t.optional&&r(t.optional),e}initializeValues(t){if(!this.schema)return;let e=this.schema.isWizard?this.schema.steps.flatMap(i=>i.fields):this.schema.fields||[],a=this.extractAllFields(e),r={...this.state.values},s={};if(t)for(let i in t){let n=t[i];n!=null&&z(s,i,n)}for(let i of a){let n=M(s,i.name);if(n!=null)continue;let l=M(r,i.name);l!=null?z(s,i.name,l):this.initializeFieldValue(i,s)}let o=this.getArrayItemOnlyFieldNames(e);for(let i in r)o.has(i)||i in s||(s[i]=r[i]);for(let i of e)if(i.type==="array"&&"minItems"in i&&"itemSchema"in i){let n=i,l=n.minItems??0;if(l>=1&&n.itemSchema?.fields?.length){let d=M(s,i.name);if(Array.isArray(d)&&d.length<l){let c=[...d];for(let p=d.length;p<l;p++){let u={};for(let h of n.itemSchema.fields)this.initializeFieldValue(h,u);c.push(u)}z(s,i.name,c)}}}for(let i of o)i in s&&delete s[i];this.state.values=s}initializeFieldValue(t,e){if(t.defaultValue!==void 0)e[t.name]=t.defaultValue;else switch(t.type){case"checkbox":case"switch":e[t.name]=t.checked||!1;break;case"select":"multiple"in t&&t.multiple?e[t.name]=[]:e[t.name]=null;break;case"array":{let a=t,r=a.minItems??0,s=a.itemSchema?.fields;if(r>=1&&s?.length){let o=[];for(let i=0;i<r;i++){let n={};for(let l of s)this.initializeFieldValue(l,n);o.push(n)}e[t.name]=o}else e[t.name]=[];break}case"group":if(e[t.name]={},"fields"in t)for(let a of t.fields)this.initializeFieldValue(a,e[t.name]);break;case"colorpicker":e[t.name]=t.defaultValue??"#000000";break;default:e[t.name]=null}}initializeWizard(){if(!this.schema||!this.schema.isWizard){this.wizardState=null;return}this.wizardState={currentStep:0,totalSteps:this.schema.steps.length,completedSteps:[]}}getState(){return{...this.state}}getWizardState(){return this.wizardState?{...this.wizardState}:null}getValue(t){return M(this.state.values,t)}createDefaultArrayItem(t){let a=t.itemSchema?.fields;if(!a?.length)return{};let r={};for(let s of a)this.initializeFieldValue(s,r);return r}async setValue(t,e){z(this.state.values,t,e),this.state.touched[t]=!0,this.invalidateDependencyCache(t),this.state.touched[t]&&this.schema&&await this.validateField(t);let a=this.fieldDependencies.get(t);if(a)for(let r of a)await this.validateField(r);this.updateValidity()}invalidateDependencyCache(t){let e=this.fieldDependencies.get(t);if(e)for(let a of e)this.dependencyCache.delete(a)}setValueWithoutValidation(t,e){z(this.state.values,t,e),this.invalidateDependencyCache(t)}async validateField(t){if(!this.schema)return;let e=this.schema.isWizard?this.schema.steps.flatMap(n=>n.fields):this.schema.fields||[],r=this.extractAllFields(e).find(n=>n.name===t);if(!r)return;if(!this.getFieldVisibility(t)){delete this.state.errors[t];return}let s=this.getValue(t),o=this.getActiveValidations(r),i=await this.validator.validateFieldWithValidations(r,s,o);i.length>0?this.state.errors[t]=i:delete this.state.errors[t]}getActiveValidations(t){let e=[...t.validations||[]],a=["text","email","password","textarea"],r=t.skipInjectionValidation??t.props?.skipInjectionValidation;a.includes(t.type)&&!r&&!e.some(i=>i.type==="noInjection")&&(e=[{type:"noInjection"},...e]);let s=this.getFieldRequired(t.name),o=e.some(i=>i.type==="required");if(s&&!o?e=[{type:"required"},...e]:!s&&o&&(e=e.filter(i=>i.type!=="required")),t.conditionalValidations)for(let i of t.conditionalValidations)this.conditionEngine.evaluateConditions(i.condition,this.state.values)&&(e=[...e,...i.validations]);return e}async validateForm(){if(!this.schema)return{};let t=this.schema.isWizard?this.schema.steps.flatMap(r=>r.fields):this.schema.fields||[],e=this.extractAllFields(t),a=await this.validator.validateForm(e,this.state.values);return this.state.errors=a,this.updateValidity(),a}updateValidity(){this.state.isValid=Object.keys(this.state.errors).length===0}setTouched(t){this.state.touched[t]=!0}getErrors(t){return this.state.errors[t]||[]}getAllErrors(){return{...this.state.errors}}reset(){this.state=this.createInitialState(),this.schema&&(this.initializeValues(),this.initializeWizard())}nextStep(){return this.wizardState&&this.wizardState.currentStep<this.wizardState.totalSteps-1?(this.wizardState.currentStep++,!0):!1}previousStep(){return this.wizardState&&this.wizardState.currentStep>0?(this.wizardState.currentStep--,!0):!1}goToStep(t){return this.wizardState&&t>=0&&t<this.wizardState.totalSteps?(this.wizardState.currentStep=t,!0):!1}completeStep(t){this.wizardState&&(this.wizardState.completedSteps.includes(t)||this.wizardState.completedSteps.push(t))}setSubmitting(t){this.state.isSubmitting=t}getCurrentStepFields(){return!this.schema||!this.schema.isWizard||!this.wizardState?this.schema?.fields||[]:this.schema.steps[this.wizardState.currentStep].fields}getFieldVisibility(t){let e=this.dependencyCache.get(t);if(e!==void 0)return e.visible;if(!this.schema)return!0;let a=this.schema.isWizard?this.schema.steps.flatMap(d=>d.fields):this.schema.fields||[],r=this.extractAllFields(a),s=r.find(d=>this.findFieldPath(d.name,a)===t||d.name===t);if(s||(s=r.find(d=>d.name===t)),!s||!s.dependencies)return!s?.hidden;let o=this.findFieldPath(s.name,a)||s.name,i=o.includes(".")?o.split(".").slice(0,-1).join("."):"",n={...this.state.values};if(i&&s.dependencies){let d=M(this.state.values,i);if(d&&typeof d=="object"){let c=(u,h="")=>{let y={};for(let[f,g]of Object.entries(u)){let x=h?`${h}.${f}`:f;g&&typeof g=="object"&&!Array.isArray(g)&&g!==null?Object.assign(y,c(g,x)):y[x]=g}return y},p=c(d);n={...this.state.values,...p}}}let l=this.conditionEngine.evaluateDependencies(s.dependencies,n);return this.dependencyCache.set(t,l),l.visible&&!s.hidden}getFieldEnabled(t){let e=this.dependencyCache.get(t);if(e!==void 0)return e.enabled;if(!this.schema)return!0;let a=this.schema.isWizard?this.schema.steps.flatMap(i=>i.fields):this.schema.fields||[],s=this.extractAllFields(a).find(i=>i.name===t);if(!s)return!0;if(s.disabled)return!1;if(!s.dependencies)return!0;let o=this.conditionEngine.evaluateDependencies(s.dependencies,this.state.values);return this.dependencyCache.set(t,o),o.enabled}getFieldRequired(t){let e=this.dependencyCache.get(t);if(e!==void 0)return e.required;if(!this.schema)return!1;let a=this.schema.isWizard?this.schema.steps.flatMap(n=>n.fields):this.schema.fields||[],s=this.extractAllFields(a).find(n=>n.name===t);if(!s)return!1;let o=s.validations?.some(n=>n.type==="required")||!1;if(!s.dependencies)return o;let i=this.conditionEngine.evaluateDependencies(s.dependencies,this.state.values);return this.dependencyCache.set(t,i),i.required||o}getDependentFields(t){return Array.from(this.fieldDependencies.get(t)||[])}};var b=class{constructor(t,e,a,r,s){this.field=t,this.value=e,this.error=a,this.onChange=r,this.onBlur=s}createInputWithSlots(t){let e=this.field.leadingIcon,a=this.field.trailingIcon;if(!e&&!a)return t;let r=document.createElement("div");if(r.className="easy-form-input-wrapper",e&&this.isSlotContentValid(e)){let o=this.renderSlotContent(e);o.className="easy-form-input-slot easy-form-input-slot-leading",r.appendChild(o)}let s=document.createElement("div");if(s.className="easy-form-input-core",s.appendChild(t),r.appendChild(s),a&&this.isSlotContentValid(a)){let o=this.renderSlotContent(a);o.className="easy-form-input-slot easy-form-input-slot-trailing",r.appendChild(o)}return r}isSlotContentValid(t){return t.type?t.type==="image"?!!t.src:t.type==="html"?!!t.html:!1:!1}renderSlotContent(t){let e=document.createElement("span");if(e.className="easy-form-input-slot-content",t.type==="image"&&t.src){let a=document.createElement("img");a.src=t.src,a.alt=t.alt??"",a.setAttribute("aria-hidden","true"),e.appendChild(a)}else t.type==="html"&&t.html&&(e.innerHTML=t.html);return e}createFieldContainer(t){let e=document.createElement("div"),r=Array.from(t.classList).filter(l=>l.startsWith("easy-form-")&&l!=="easy-form-field"&&(l.includes("-container")||l.includes("-wrapper"))),s=this.field.labelPosition??"up",o=this.createInputWithSlots(t);if(r.length>0?e.className=`easy-form-field easy-form-label-${s} ${r.join(" ")}`:e.className=`easy-form-field easy-form-label-${s}`,s==="none"&&this.field.label){let l=o.querySelector("input, textarea, select")||o;l instanceof HTMLElement&&l.setAttribute("aria-label",this.field.label)}let n=(()=>{if(!this.field.label||s==="none")return null;let l=document.createElement("label");if(l.className="easy-form-label",l.setAttribute("for",this.getFieldId()),l.textContent=this.field.label,this.field.validations?.some(d=>d.type==="required")){let d=document.createElement("span");d.className="easy-form-required",d.textContent=" *",l.appendChild(d)}return l})();if(s==="up")n&&e.appendChild(n),e.appendChild(o);else if(s==="down")e.appendChild(o),n&&e.appendChild(n);else if(s==="left"){let l=document.createElement("div");l.className="easy-form-field-inner easy-form-field-inner-horizontal",n&&l.appendChild(n),l.appendChild(o),e.appendChild(l)}else if(s==="right"){let l=document.createElement("div");l.className="easy-form-field-inner easy-form-field-inner-horizontal",l.appendChild(o),n&&l.appendChild(n),e.appendChild(l)}else e.appendChild(o);if(this.field.description){let l=document.createElement("p");l.className="easy-form-description",l.textContent=this.field.description,e.appendChild(l)}if(this.error){let l=document.createElement("p");l.className="easy-form-error",l.textContent=this.error,e.appendChild(l)}return e}getFieldId(){return`easy-form-${this.field.name}`}applyCommonProps(t){if(t.id=this.getFieldId(),t.setAttribute("name",this.field.name),this.field.disabled&&(t.setAttribute("disabled","true"),t.classList.add("easy-form-input-disabled")),this.field.hidden&&(t.style.display="none",t.classList.add("easy-form-field-hidden")),this.error&&t.classList.add("easy-form-input-error"),this.field.props)for(let[e,a]of Object.entries(this.field.props))(e.startsWith("data-")||e.startsWith("aria-"))&&t.setAttribute(e,String(a))}};function Te(m){let t=[];for(let e=0;e<m.length;e++){let a=m[e];switch(a){case"9":t.push({type:"digit",char:"9",editable:!0});break;case"a":case"A":t.push({type:"letter",char:a,editable:!0});break;case"*":t.push({type:"any",char:"*",editable:!0});break;default:t.push({type:"literal",char:a,editable:!1});break}}return t}function V(m,t){let e="",a=0;for(let r of t){if(!r.editable){e+=r.char;continue}if(a>=m.length)break;let s=m[a];if(!(r.type==="digit"&&!/\d/.test(s))){{if(r.type==="letter"&&!/[a-zA-Z]/.test(s))continue;if(r.type!=="any"){if(r.type!=="any"&&r.type!=="digit"&&r.type!=="letter")continue}}e+=s,a++}}return e}function ce(m,t){if(!m)return"";let e="",a=0;for(let r=0;r<m.length&&a<t.length;r++){let s=m[r],o=t[a];if(o.editable)o.type==="digit"&&/\d/.test(s)||o.type==="letter"&&/[a-zA-Z]/.test(s)||o.type==="any"?(e+=s,a++):(a++,r--);else if(s===o.char)a++;else if(a<t.length-1){let i=t[a+1];i&&i.editable&&(i.type==="digit"&&/\d/.test(s)||i.type==="letter"&&/[a-zA-Z]/.test(s)||i.type==="any")?(e+=s,a+=2):a++}else break}return e}function B(m,t,e="forward"){if(e==="forward"){for(let a=m+1;a<t.length;a++)if(t[a].editable)return a;return t.length}else{for(let a=m-1;a>=0;a--)if(t[a].editable)return a;return 0}}function Ie(m,t="_"){return m.map(e=>e.editable?t:e.char).join("")}function Ne(m,t,e,a){let r=0;for(let o=0;o<Math.min(e,m.length);o++){let i=o;i<a.length&&a[i].editable&&r++}let s=0;for(let o=0;o<t.length&&o<a.length;o++)if(a[o].editable&&(s++,s>r))return o+1;return B(Math.min(e,t.length-1),a,"forward")}var T=class{constructor(){this.tokenCache=new Map}getCustomMask(t){return t.custom?t.custom:t.type?me(t.type):null}getTokens(t){let e=this.getCustomMask(t);if(!e)return null;let a=e.pattern;if(this.tokenCache.has(a))return this.tokenCache.get(a);let r=Te(e.pattern);return this.tokenCache.set(a,r),r}applyMask(t,e){let a=this.getTokens(e);if(!a)return t;let r=this.getCustomMask(e),s=a.filter(l=>l.editable),o=new Set(s.map(l=>l.type)),i="";for(let l of t)(o.has("any")||o.has("digit")&&/\d/.test(l)||o.has("letter")&&/[a-zA-Z]/.test(l))&&(i+=l);let n=V(i,a);return r.transform&&(n=r.transform(n),n=V(n,a)),n}removeMask(t,e){let a=this.getTokens(e);return a?ce(t,a):t}getMaskPlaceholder(t){let e=this.getTokens(t);if(!e)return"";let a=this.getCustomMask(t);return Ie(e,a.placeholder||"_")}canInsertChar(t,e,a){let r=this.getTokens(a);if(!r||e>=r.length)return!1;let s=r[e];if(!s.editable)return!1;switch(s.type){case"digit":return/\d/.test(t);case"letter":return/[a-zA-Z]/.test(t);case"any":return!0;default:return!1}}processInput(t,e,a,r){let s=this.getTokens(a);if(!s)return{value:t,cursorPosition:t.length};let o=ce(t,s),i=V(o,s),n=this.getCustomMask(a);n.transform&&(i=n.transform(i),i=V(i,s));let l=Ne(e,i,r,s);return{value:i,cursorPosition:Math.min(l,i.length)}}processKeyInput(t,e,a,r,s=!1){let o=this.getTokens(r);if(!o)return{value:e,cursorPosition:a};if(s){if(a===0)return{value:e,cursorPosition:0};let i=B(a-1,o,"backward"),n=e.substring(0,i),l=e.substring(a),d=n+l,c=this.removeMask(d,r),p=this.applyMask(c,r),u=Math.max(0,i-1),h=B(u,o,"forward");return{value:p,cursorPosition:h}}if(t.length===1&&this.canInsertChar(t,a,r)){let i=e.substring(0,a),n=e.substring(a),l=i+t+n;return this.processInput(l,e,r,a)}return{value:e,cursorPosition:a}}};var O=class extends b{constructor(e,a,r,s,o){super(e,a,r,s,o);this.maskEngine=null;this.previousValue="";e.mask&&(this.maskEngine=new T)}render(){let e=document.createElement("input");e.type=this.field.type==="email"?"email":this.field.type==="password"?"password":"text";let a=this.value??"";if(this.maskEngine&&this.field.mask&&(a&&(a=this.maskEngine.applyMask(String(a),this.field.mask)),this.previousValue=a),e.value=a,this.applyCommonProps(e),this.field.placeholder)e.placeholder=this.field.placeholder;else if(this.maskEngine&&this.field.mask){let r=this.maskEngine.getMaskPlaceholder(this.field.mask);r&&(e.placeholder=r)}return this.maskEngine&&this.field.mask?(e.addEventListener("input",r=>{let s=r.target,o=s.selectionStart||0,i=s.value,n=this.maskEngine.processInput(i,this.previousValue,this.field.mask,o);s.value=n.value,this.previousValue=n.value,setTimeout(()=>{s.setSelectionRange(n.cursorPosition,n.cursorPosition)},0);let l=this.field.mask.keepFormat?n.value:this.maskEngine.removeMask(n.value,this.field.mask);this.onChange(l)}),e.addEventListener("keydown",r=>{let s=r.target,o=s.selectionStart||0;if(r.key==="Backspace"||r.key==="Delete"){r.preventDefault();let i=r.key==="Backspace",n=this.maskEngine.processKeyInput("",s.value,o,this.field.mask,i);s.value=n.value,this.previousValue=n.value,setTimeout(()=>{s.setSelectionRange(n.cursorPosition,n.cursorPosition)},0);let l=this.field.mask.keepFormat?n.value:this.maskEngine.removeMask(n.value,this.field.mask);this.onChange(l)}}),e.addEventListener("paste",r=>{r.preventDefault();let s=(r.clipboardData||window.clipboardData).getData("text");if(s){let o=r.target,i=o.selectionStart||0,n=o.value.substring(0,i),l=o.value.substring(i),d=n+s+l,c=this.maskEngine.processInput(d,this.previousValue,this.field.mask,i);o.value=c.value,this.previousValue=c.value,setTimeout(()=>{o.setSelectionRange(c.cursorPosition,c.cursorPosition)},0);let p=this.field.mask.keepFormat?c.value:this.maskEngine.removeMask(c.value,this.field.mask);this.onChange(p)}})):e.addEventListener("input",r=>{let s=r.target;this.onChange(s.value)}),e.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(e)}};var j=class extends b{constructor(e,a,r,s,o){super(e,a,r,s,o);this.maskEngine=null;this.previousValue="";e.mask&&(this.maskEngine=new T)}render(){let e=document.createElement("input");if(this.maskEngine&&this.field.mask){e.type="text";let r=this.value??"";r!==null&&r!==""&&(this.field.mask.type==="currency"?r=this.maskEngine.applyMask(String(r),this.field.mask):this.field.mask.type==="percentage"&&(r=this.maskEngine.applyMask(String(r),this.field.mask))),this.previousValue=r,e.value=r}else e.type="number",e.value=this.value??"";let a=this.field;if(!this.maskEngine&&e.type==="number"&&(a.min!==void 0&&(e.min=String(a.min)),a.max!==void 0&&(e.max=String(a.max)),a.step!==void 0&&(e.step=String(a.step))),this.applyCommonProps(e),this.field.placeholder)e.placeholder=this.field.placeholder;else if(this.maskEngine&&this.field.mask){let r=this.maskEngine.getMaskPlaceholder(this.field.mask);r&&(e.placeholder=r)}return this.maskEngine&&this.field.mask?(e.addEventListener("input",r=>{let s=r.target,o=s.selectionStart||0,i=s.value,n=this.maskEngine.processInput(i,this.previousValue,this.field.mask,o);s.value=n.value,this.previousValue=n.value,setTimeout(()=>{s.setSelectionRange(n.cursorPosition,n.cursorPosition)},0);let l=null;if(this.field.mask.type==="currency"){let d=this.maskEngine.removeMask(n.value,this.field.mask);l=d?parseFloat(d.replace(/[^\d.]/g,"")):null}else if(this.field.mask.type==="percentage"){let d=this.maskEngine.removeMask(n.value,this.field.mask);l=d?parseFloat(d):null}this.onChange(l)}),e.addEventListener("keydown",r=>{let s=r.target,o=s.selectionStart||0;if(r.key==="Backspace"||r.key==="Delete"){r.preventDefault();let i=r.key==="Backspace",n=this.maskEngine.processKeyInput("",s.value,o,this.field.mask,i);s.value=n.value,this.previousValue=n.value,setTimeout(()=>{s.setSelectionRange(n.cursorPosition,n.cursorPosition)},0);let l=null;if(this.field.mask.type==="currency"){let d=this.maskEngine.removeMask(n.value,this.field.mask);l=d?parseFloat(d.replace(/[^\d.]/g,"")):null}else if(this.field.mask.type==="percentage"){let d=this.maskEngine.removeMask(n.value,this.field.mask);l=d?parseFloat(d):null}this.onChange(l)}}),e.addEventListener("paste",r=>{r.preventDefault();let s=(r.clipboardData||window.clipboardData).getData("text");if(s){let o=r.target,i=o.selectionStart||0,n=o.value.substring(0,i),l=o.value.substring(i),d=n+s+l,c=this.maskEngine.processInput(d,this.previousValue,this.field.mask,i);o.value=c.value,this.previousValue=c.value,setTimeout(()=>{o.setSelectionRange(c.cursorPosition,c.cursorPosition)},0);let p=null;if(this.field.mask.type==="currency"){let u=this.maskEngine.removeMask(c.value,this.field.mask);p=u?parseFloat(u.replace(/[^\d.]/g,"")):null}else if(this.field.mask.type==="percentage"){let u=this.maskEngine.removeMask(c.value,this.field.mask);p=u?parseFloat(u):null}this.onChange(p)}})):e.addEventListener("input",r=>{let s=r.target,o=s.value===""?null:Number(s.value);this.onChange(o)}),e.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(e)}};var W=class extends b{render(){let t=document.createElement("textarea");t.value=this.value??"",t.placeholder=this.field.placeholder||"";let e=this.field;return e.rows&&(t.rows=e.rows),e.cols&&(t.cols=e.cols),this.applyCommonProps(t),t.addEventListener("input",a=>{let r=a.target;this.onChange(r.value)}),t.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(t)}};var _=class extends b{render(){let t=document.createElement("select"),e=this.field;if(e.multiple&&(t.multiple=!0),!e.multiple){let r=document.createElement("option");r.value="",r.textContent=e.placeholder||"Selecciona una opci\xF3n",r.setAttribute("data-placeholder",""),r.disabled=!0,t.appendChild(r)}for(let r of e.options){let s=document.createElement("option");typeof r=="string"?(s.value=r,s.textContent=r):(s.value=String(r.value),s.textContent=r.label),t.appendChild(s)}if(e.multiple&&Array.isArray(this.value))for(let r of t.options)r.selected=this.value.includes(r.value);else t.value=this.value??"";this.applyCommonProps(t);let a=()=>{!t.value?t.classList.add("easy-form-select-placeholder"):t.classList.remove("easy-form-select-placeholder")};return a(),t.addEventListener("change",r=>{let s=r.target;if(a(),e.multiple){let o=Array.from(s.selectedOptions).map(i=>i.value);this.onChange(o)}else this.onChange(s.value||null)}),t.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(t)}};var Y=class extends b{render(){let t=document.createElement("input");t.type="checkbox",t.checked=!!this.value,this.applyCommonProps(t),t.addEventListener("change",r=>{let s=r.target;this.onChange(s.checked)}),t.addEventListener("blur",()=>{this.onBlur()});let e=document.createElement("div");e.className="easy-form-field";let a=document.createElement("label");if(a.className="easy-form-label-checkbox",a.setAttribute("for",this.getFieldId()),a.appendChild(t),this.field.label){let r=document.createTextNode(this.field.label);a.appendChild(r)}if(e.appendChild(a),this.field.description){let r=document.createElement("p");r.className="easy-form-description",r.textContent=this.field.description,e.appendChild(r)}if(this.error){let r=document.createElement("p");r.className="easy-form-error",r.textContent=this.error,e.appendChild(r)}return e}};var U=class extends b{render(){let t=document.createElement("div");if(t.className="easy-form-field",this.field.label){let r=document.createElement("label");if(r.className="easy-form-label",r.textContent=this.field.label,this.field.validations?.some(s=>s.type==="required")){let s=document.createElement("span");s.className="easy-form-required",s.textContent=" *",r.appendChild(s)}t.appendChild(r)}let e=document.createElement("div");e.className="easy-form-radio-group";let a=this.field;for(let r of a.options){let s=typeof r=="string"?r:r.value,o=typeof r=="string"?r:r.label,i=document.createElement("div");i.className="easy-form-radio-option";let n=document.createElement("input");n.type="radio",n.name=this.field.name,n.id=`${this.getFieldId()}-${s}`,n.value=String(s),n.checked=String(this.value)===String(s),this.field.disabled&&(n.disabled=!0);let l=document.createElement("label");l.setAttribute("for",n.id),l.textContent=o,l.className="easy-form-radio-label",n.addEventListener("change",()=>{this.onChange(s)}),n.addEventListener("blur",()=>{this.onBlur()}),i.appendChild(n),i.appendChild(l),e.appendChild(i)}if(t.appendChild(e),this.field.description){let r=document.createElement("p");r.className="easy-form-description",r.textContent=this.field.description,t.appendChild(r)}if(this.error){let r=document.createElement("p");r.className="easy-form-error",r.textContent=this.error,t.appendChild(r)}return t}};var G=class extends b{render(){let t=document.createElement("input");t.type="checkbox",t.className="easy-form-switch",t.checked=!!this.value,this.applyCommonProps(t),t.addEventListener("change",r=>{let s=r.target;this.onChange(s.checked)}),t.addEventListener("blur",()=>{this.onBlur()});let e=document.createElement("div");e.className="easy-form-field";let a=document.createElement("label");if(a.className="easy-form-label-switch",a.setAttribute("for",this.getFieldId()),this.field.label){let r=document.createTextNode(this.field.label);a.appendChild(r)}if(a.appendChild(t),e.appendChild(a),this.field.description){let r=document.createElement("p");r.className="easy-form-description",r.textContent=this.field.description,e.appendChild(r)}if(this.error){let r=document.createElement("p");r.className="easy-form-error",r.textContent=this.error,e.appendChild(r)}return e}};var K=class extends b{render(){let t=document.createElement("input");t.type="date";let e=this.field;if(e.min&&(t.min=e.min),e.max&&(t.max=e.max),this.value){let a=this.value instanceof Date?this.value.toISOString().split("T")[0]:String(this.value);t.value=a}return this.applyCommonProps(t),t.addEventListener("change",a=>{let r=a.target;this.onChange(r.value||null)}),t.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(t)}};var Z=class extends b{render(){let t=document.createElement("input");t.type="file";let e=this.field;return e.accept&&(t.accept=e.accept),e.multiple&&(t.multiple=!0),this.applyCommonProps(t),t.addEventListener("change",a=>{let r=a.target;r.files&&(e.multiple?this.onChange(Array.from(r.files)):this.onChange(r.files[0]||null))}),t.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(t)}};var J=class extends b{render(){let t=document.createElement("div");t.className="easy-form-quantity-container";let e=this.field,a=e.min??0,r=e.max??void 0,s=e.step??1,o=this.value??a,i=document.createElement("div");i.className="easy-form-quantity-wrapper";let n=document.createElement("button");n.type="button",n.className="easy-form-quantity-btn easy-form-quantity-decrement",n.textContent="\u2212",n.setAttribute("aria-label","Decrementar"),o<=a&&(n.disabled=!0,n.classList.add("disabled"));let l=document.createElement("input");l.type="number",l.value=String(o),l.min=String(a),r!==void 0&&(l.max=String(r)),l.step=String(s),l.className="easy-form-quantity-input",this.applyCommonProps(l);let d=document.createElement("button");d.type="button",d.className="easy-form-quantity-btn easy-form-quantity-increment",d.textContent="+",d.setAttribute("aria-label","Incrementar"),r!==void 0&&o>=r&&(d.disabled=!0,d.classList.add("disabled")),n.addEventListener("click",()=>{let p=Math.max(a,Number(l.value)-s);l.value=String(p),this.onChange(p),c()}),d.addEventListener("click",()=>{let p=r!==void 0?Math.min(r,Number(l.value)+s):Number(l.value)+s;l.value=String(p),this.onChange(p),c()}),l.addEventListener("input",p=>{let u=p.target,h=Number(u.value);isNaN(h)&&(h=a),h<a&&(h=a),r!==void 0&&h>r&&(h=r),u.value=String(h),this.onChange(h),c()}),l.addEventListener("blur",()=>{this.onBlur()});let c=()=>{let p=Number(l.value);n.disabled=p<=a,n.classList.toggle("disabled",p<=a),r!==void 0?(d.disabled=p>=r,d.classList.toggle("disabled",p>=r)):(d.disabled=!1,d.classList.remove("disabled"))};return i.appendChild(n),i.appendChild(l),i.appendChild(d),t.appendChild(i),this.createFieldContainer(t)}};var X=class extends b{constructor(){super(...arguments);this.openAccordion=null}render(){let e=document.createElement("div");e.className="easy-form-accordion-select-container";let a=this.field,r=this.value??null;return a.options.forEach((s,o)=>{let i=typeof s=="string"?s:s.value,n=typeof s=="string"?s:s.label,l=typeof s=="object"&&"description"in s&&s.description?s.description:void 0,d=document.createElement("div");d.className="easy-form-accordion-item",d.setAttribute("data-value",String(i)),(r===i||Array.isArray(r)&&r.includes(i))&&(d.classList.add("selected"),a.multiple||(this.openAccordion=String(i)));let c=document.createElement("div");c.className="easy-form-accordion-header",c.setAttribute("role","button"),c.setAttribute("tabindex","0"),c.setAttribute("aria-expanded","false");let p=document.createElement("div");p.className="easy-form-accordion-header-content";let u=document.createElement("div");u.className="easy-form-accordion-indicator",a.multiple?(u.classList.add("checkbox"),Array.isArray(r)&&r.includes(i)&&u.classList.add("checked")):(u.classList.add("radio"),r===i&&u.classList.add("checked"));let h=document.createElement("span");h.className="easy-form-accordion-label",h.textContent=n;let y=document.createElement("span");y.className="easy-form-accordion-arrow",y.textContent="\u25BC",p.appendChild(u),p.appendChild(h),c.appendChild(p),c.appendChild(y);let f=document.createElement("div");if(f.className="easy-form-accordion-content",l){let v=document.createElement("p");v.className="easy-form-accordion-description",v.textContent=l,f.appendChild(v)}if(typeof s=="object"&&"content"in s&&s.content){let v=document.createElement("div");v.className="easy-form-accordion-custom-content",typeof s.content=="string"?v.innerHTML=s.content:s.content instanceof HTMLElement&&v.appendChild(s.content),f.appendChild(v)}d.appendChild(c),d.appendChild(f);let g=()=>{let v=d.classList.contains("open");a.multiple||e.querySelectorAll(".easy-form-accordion-item").forEach(C=>{if(C!==d){C.classList.remove("open");let E=C.querySelector(".easy-form-accordion-header"),w=C.querySelector(".easy-form-accordion-content"),k=C.querySelector(".easy-form-accordion-arrow");E&&E.setAttribute("aria-expanded","false"),w&&(w.style.maxHeight=null),k&&(k.style.transform="rotate(0deg)")}}),v?(d.classList.remove("open"),c.setAttribute("aria-expanded","false"),f.style.maxHeight=null,y.style.transform="rotate(0deg)",this.openAccordion=null):(d.classList.add("open"),c.setAttribute("aria-expanded","true"),f.style.maxHeight=f.scrollHeight+"px",y.style.transform="rotate(180deg)",this.openAccordion=String(i))},x=()=>{if(a.multiple){let v=Array.isArray(r)?[...r]:[],C=v.indexOf(i);C>-1?(v.splice(C,1),d.classList.remove("selected"),u.classList.remove("checked")):(v.push(i),d.classList.add("selected"),u.classList.add("checked")),this.onChange(v.length>0?v:null)}else e.querySelectorAll(".easy-form-accordion-item").forEach(v=>{v.classList.remove("selected");let C=v.querySelector(".easy-form-accordion-indicator");C&&C.classList.remove("checked")}),d.classList.add("selected"),u.classList.add("checked"),this.onChange(i)};c.addEventListener("click",v=>{v.stopPropagation(),x(),g()}),c.addEventListener("keydown",v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),x(),g())}),(r===i||Array.isArray(r)&&r.includes(i))&&(!a.multiple||a.autoExpand)&&setTimeout(()=>{d.classList.add("open"),c.setAttribute("aria-expanded","true"),f.style.maxHeight=f.scrollHeight+"px",y.style.transform="rotate(180deg)"},0),e.appendChild(d)}),this.createFieldContainer(e)}};var Q=class extends b{render(){let t=document.createElement("div");t.className="easy-form-image-grid-container";let e=this.field,a=this.value??null,r=e.columns??3,s=e.imageSize??"medium";return t.style.gridTemplateColumns=`repeat(${r}, 1fr)`,t.style.gap=e.gap??"1rem",e.options.forEach(o=>{let i=typeof o=="string"?o:o.value,n=typeof o=="string"?o:o.label,l=typeof o=="object"&&"image"in o&&o.image?o.image:void 0,d=typeof o=="object"&&"description"in o&&o.description?o.description:void 0,c=document.createElement("div");c.className=`easy-form-image-grid-item easy-form-image-grid-${s}`,c.setAttribute("data-value",String(i)),c.setAttribute("role","button"),c.setAttribute("tabindex","0"),c.setAttribute("aria-label",n),(a===i||Array.isArray(a)&&a.includes(i))&&c.classList.add("selected");let p=document.createElement("div");if(p.className="easy-form-image-grid-image-container",l){let f=document.createElement("img");f.src=l,f.alt=n,f.className="easy-form-image-grid-image",p.appendChild(f)}else{let f=document.createElement("div");f.className="easy-form-image-grid-placeholder",f.textContent=n.charAt(0).toUpperCase(),p.appendChild(f)}let u=document.createElement("div");u.className="easy-form-image-grid-indicator",e.multiple?(u.classList.add("checkbox"),Array.isArray(a)&&a.includes(i)&&(u.classList.add("checked"),u.innerHTML="\u2713")):(u.classList.add("radio"),a===i&&(u.classList.add("checked"),u.innerHTML="\u25CF")),p.appendChild(u);let h=document.createElement("div");if(h.className="easy-form-image-grid-label",h.textContent=n,d){let f=document.createElement("div");f.className="easy-form-image-grid-description",f.textContent=d,c.appendChild(f)}c.appendChild(p),c.appendChild(h);let y=()=>{if(e.multiple){let f=Array.isArray(a)?[...a]:[],g=f.indexOf(i);g>-1?(f.splice(g,1),c.classList.remove("selected"),u.classList.remove("checked"),u.innerHTML=""):(f.push(i),c.classList.add("selected"),u.classList.add("checked"),u.innerHTML="\u2713"),this.onChange(f.length>0?f:null)}else t.querySelectorAll(".easy-form-image-grid-item").forEach(f=>{f.classList.remove("selected");let g=f.querySelector(".easy-form-image-grid-indicator");g&&(g.classList.remove("checked"),g.innerHTML="")}),c.classList.add("selected"),u.classList.add("checked"),u.innerHTML="\u25CF",this.onChange(i)};c.addEventListener("click",y),c.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),y())}),c.addEventListener("blur",()=>{this.onBlur()}),t.appendChild(c)}),this.createFieldContainer(t)}};var ee=class extends b{constructor(){super(...arguments);this.inputs=[]}render(){let e=document.createElement("div");e.className="easy-form-otp-container";let r=this.field.length??6,s=this.value??"",o=String(s).padStart(r,"").slice(0,r);for(let i=0;i<r;i++){let n=document.createElement("input");n.type="text",n.inputMode="numeric",n.maxLength=1,n.className="easy-form-otp-input",n.setAttribute("aria-label",`C\xF3digo d\xEDgito ${i+1}`),o[i]&&(n.value=o[i]),this.applyCommonProps(n),n.id=`${this.getFieldId()}-${i}`;let l=i;n.addEventListener("input",d=>{let c=d.target,p=c.value.replace(/[^0-9]/g,"");c.value=p,p&&l<r-1&&this.inputs[l+1].focus(),this.updateOTPValue()}),n.addEventListener("keydown",d=>{let c=d.target;d.key==="Backspace"&&!c.value&&l>0&&(this.inputs[l-1].focus(),this.inputs[l-1].value="",this.updateOTPValue()),d.key==="ArrowLeft"&&l>0&&(d.preventDefault(),this.inputs[l-1].focus()),d.key==="ArrowRight"&&l<r-1&&(d.preventDefault(),this.inputs[l+1].focus())}),n.addEventListener("paste",d=>{d.preventDefault();let p=(d.clipboardData||window.clipboardData).getData("text").replace(/[^0-9]/g,"").slice(0,r);for(let h=0;h<p.length&&l+h<r;h++)this.inputs[l+h].value=p[h];let u=Math.min(l+p.length,r-1);this.inputs[u].focus(),this.updateOTPValue()}),n.addEventListener("focus",d=>{d.target.select()}),n.addEventListener("blur",()=>{this.onBlur()}),this.inputs.push(n),e.appendChild(n)}return this.createFieldContainer(e)}updateOTPValue(){let e=this.inputs.map(s=>s.value).join(""),a=this.field,r=e.length===this.inputs.length?e:null;a.numeric&&r?this.onChange(Number(r)):this.onChange(r)}};var We=6;function te(m){return m?'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>':'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>'}var re=class extends b{constructor(){super(...arguments);this.inputs=[];this.visible=!1}get passwordField(){return this.field}render(){let e=this.passwordField,a=!!e.characterSeparated,r=a?typeof e.characterSeparated=="number"?e.characterSeparated:We:0;return a?this.createFieldContainer(this.renderSeparated(r)):this.createFieldContainer(this.renderSingle())}renderSingle(){let a=!!this.passwordField.showToggle,r=document.createElement("input");if(r.type="password",r.value=this.value??"",r.id=this.getFieldId(),this.applyCommonProps(r),this.field.placeholder&&(r.placeholder=this.field.placeholder),r.addEventListener("input",i=>{this.onChange(i.target.value)}),r.addEventListener("blur",()=>this.onBlur()),!a)return r;let s=document.createElement("div");s.className="easy-form-password-inner",r.classList.add("easy-form-password-input"),s.appendChild(r);let o=document.createElement("button");return o.type="button",o.className="easy-form-password-toggle",o.setAttribute("aria-label","Mostrar contrase\xF1a"),o.innerHTML=te(!1),o.addEventListener("click",()=>{this.visible=!this.visible,r.type=this.visible?"text":"password",o.setAttribute("aria-label",this.visible?"Ocultar contrase\xF1a":"Mostrar contrase\xF1a"),o.innerHTML=te(this.visible)}),s.appendChild(o),s}renderSeparated(e){let r=!!this.passwordField.showToggle,s=this.value??"",o=String(s).slice(0,e),i=document.createElement("div");i.className="easy-form-password-separated";for(let n=0;n<e;n++){let l=document.createElement("input");l.type="password",l.maxLength=1,l.className="easy-form-password-separated-input",l.setAttribute("aria-label",`Car\xE1cter ${n+1} de ${e}`),o[n]&&(l.value=o[n]),this.applyCommonProps(l),l.id=n===0?this.getFieldId():`${this.getFieldId()}-${n}`,n>0&&l.removeAttribute("name");let d=n;l.addEventListener("input",c=>{c.target.value&&d<e-1&&this.inputs[d+1].focus(),this.updateSeparatedValue()}),l.addEventListener("keydown",c=>{c.key==="Backspace"&&!c.target.value&&d>0&&(this.inputs[d-1].focus(),this.inputs[d-1].value="",this.updateSeparatedValue()),c.key==="ArrowLeft"&&d>0&&(c.preventDefault(),this.inputs[d-1].focus()),c.key==="ArrowRight"&&d<e-1&&(c.preventDefault(),this.inputs[d+1].focus())}),l.addEventListener("paste",c=>{c.preventDefault();let u=((c.clipboardData||window.clipboardData)?.getData("text")||"").slice(0,e-d).split("");for(let y=0;y<u.length&&d+y<e;y++)this.inputs[d+y].value=u[y];let h=Math.min(d+u.length,e-1);this.inputs[h].focus(),this.updateSeparatedValue()}),l.addEventListener("focus",c=>c.target.select()),l.addEventListener("blur",()=>this.onBlur()),this.inputs.push(l),i.appendChild(l)}if(r){let n=document.createElement("div");n.className="easy-form-password-separated-toggle";let l=document.createElement("button");l.type="button",l.className="easy-form-password-toggle",l.setAttribute("aria-label","Mostrar contrase\xF1a"),l.innerHTML=te(!1),l.addEventListener("click",()=>{this.visible=!this.visible;let d=this.visible?"text":"password";this.inputs.forEach(c=>{c.type=d}),l.setAttribute("aria-label",this.visible?"Ocultar contrase\xF1a":"Mostrar contrase\xF1a"),l.innerHTML=te(this.visible)}),n.appendChild(l),i.appendChild(n)}return i}updateSeparatedValue(){let e=this.inputs.map(a=>a.value).join("");this.onChange(e||null)}};var ae=class extends b{render(){let t=this.field,e=t.accept??"",a=t.multiple??!1,r=document.createElement("div");r.className="easy-form-file-drop",r.setAttribute("tabindex","0");let s=document.createElement("input");s.type="file",s.className="easy-form-file-drop-input",s.style.display="none",e&&(s.accept=e),a&&(s.multiple=!0);let o=document.createElement("span");o.className="easy-form-file-drop-label",o.textContent="Arrastra archivos aqu\xED o haz clic para seleccionar",r.appendChild(o),r.appendChild(s);let i=document.createElement("div");i.className="easy-form-file-drop-list";let n=d=>{let c=d?Array.isArray(d)?d.map(p=>p.name):[d.name]:[];if(i.innerHTML="",c.length===0){i.style.display="none";return}i.style.display="block",c.forEach(p=>{let u=document.createElement("div");u.className="easy-form-file-drop-item",u.textContent=p,i.appendChild(u)})};n(this.value);let l=d=>{if(!d||d.length===0)return;let c=a?Array.from(d):d[0];this.onChange(c),this.onBlur(),n(c)};return r.addEventListener("click",()=>{s.click()}),s.addEventListener("change",d=>{let c=d.target;l(c.files),c.value=""}),r.addEventListener("dragover",d=>{d.preventDefault(),d.stopPropagation(),r.classList.add("easy-form-file-drop-over")}),r.addEventListener("dragleave",d=>{d.preventDefault(),d.stopPropagation(),r.classList.remove("easy-form-file-drop-over")}),r.addEventListener("drop",d=>{d.preventDefault(),d.stopPropagation(),r.classList.remove("easy-form-file-drop-over"),l(d.dataTransfer?.files??null)}),r.appendChild(i),this.createFieldContainer(r)}};var _e="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css",se=class extends b{constructor(){super(...arguments);this.mapInstance=null;this.markerInstance=null}render(){let e=this.field,a=e.center??{lat:0,lng:0},r=e.zoom??13,s=this.value,o=typeof s=="object"&&s?.lat!=null?s.lat:a.lat,i=typeof s=="object"&&s?.lng!=null?s.lng:a.lng,n=document.createElement("div");n.className="easy-form-map";let l=document.createElement("div");l.className="easy-form-map-inputs";let d=document.createElement("input");d.type="number",d.step="any",d.placeholder="Latitud",d.value=String(o),d.className="easy-form-map-lat";let c=document.createElement("input");c.type="number",c.step="any",c.placeholder="Longitud",c.value=String(i),c.className="easy-form-map-lng";let p=()=>{let x=parseFloat(d.value),v=parseFloat(c.value);!isNaN(x)&&!isNaN(v)&&(this.onChange({lat:x,lng:v}),this.syncMarkerPosition(x,v)),this.onBlur()};d.addEventListener("change",p),c.addEventListener("change",p),l.appendChild(d),l.appendChild(c),n.appendChild(l);let u=document.createElement("div");u.className="easy-form-map-container",n.appendChild(u);let h="easy-form-leaflet-css",y=!1,f=document.createElement("link");return f.id=h,f.rel="stylesheet",f.href=_e,f.onload=()=>{y=!0},n.insertBefore(f,n.firstChild),(async()=>{if(typeof window>"u")return;u.style.height="300px",u.style.width="100%",u.style.position="relative",u.style.overflow="hidden",u.style.display="block",await new Promise(w=>{let k=()=>{y&&u.offsetWidth>0&&u.offsetHeight>0?w(void 0):requestAnimationFrame(k)};k()}),await new Promise(w=>setTimeout(w,50));let x;try{x=await import("leaflet")}catch{u.innerHTML=`
|
|
2349
|
+
`}function D(c,t){let e=ye(t),a=Oe(c,t);return e+a}function Oe(c,t){switch(c){case"plano":return de(t);case"tradicional":return ge(t);case"material":return be(t);case"rounded-shadow":return ve(t);case"lines":return xe(t);case"shadcn":return we(t);case"chakra":return ke(t);case"mantine":return Ee(t);case"glass":return Se(t);case"bordered":return Ce(t);case"minimal":return Fe(t);case"efc":return Le(t);default:return de(t)}}var Te={phone:{pattern:"(999) 999-9999",placeholder:"_"},"phone-us":{pattern:"(999) 999-9999",placeholder:"_"},"phone-international":{pattern:"+99 999 999 9999",placeholder:"_"},date:{pattern:"99/99/9999",placeholder:"_"},"date-us":{pattern:"99/99/9999",placeholder:"_"},"date-eu":{pattern:"99-99-9999",placeholder:"_"},"credit-card":{pattern:"9999 9999 9999 9999",placeholder:"_"},ssn:{pattern:"999-99-9999",placeholder:"_"},"zip-code":{pattern:"99999",placeholder:"_"},currency:{pattern:"$999,999.99",placeholder:"_",transform:c=>{let t=c.replace(/[^\d.]/g,"");return(parseFloat(t)||0).toFixed(2)}},percentage:{pattern:"999%",placeholder:"_",transform:c=>c.replace(/[^\d]/g,"")},time:{pattern:"99:99",placeholder:"_"},datetime:{pattern:"99/99/9999 99:99",placeholder:"_"}};function me(c){return Te[c]}var P="El valor contiene caracteres o patrones no permitidos",je=[/\b(union|select|insert|update|delete|drop|exec|execute|declare)\s+(all\s+)?(select|from|into|table)/i,/\b(or|and)\s+['"]?\d+['"]?\s*=\s*['"]?\d+/i,/;\s*(drop|delete|truncate|alter)\s+/i,/--\s*$/,/\/\*[\s\S]*\*\//,/'\s*or\s+'1'\s*=\s*'1/i,/"\s*or\s+"1"\s*=\s*"1/i,/\bexec\s*\(/i,/\bxp_\w+/i,/<script\b[\s\S]*?>[\s\S]*?<\/script>/i,/<script\b/i,/javascript\s*:/i,/vbscript\s*:/i,/on\w+\s*=\s*["'][^"']*["']/i,/on\w+\s*=\s*[^\s>]+/i,/<iframe\b/i,/<object\b/i,/<embed\b/i,/\beval\s*\(/i,/document\.(cookie|write|location)/i,/window\.(location|open|eval)/i,/[;&|]\s*(ls|cat|rm|wget|curl|nc|bash|sh|python|perl)\s/i,/\$\s*\([^)]+\)/,/`[^`]+`/,/\|\s*\w+/,/\$\s*where\b/i,/\$\s*gt\b|\$\s*ne\b|\$\s*regex\b/i,/\{\{[^}]*\}\}/,/\$\{[^}]*\}/];function Me(c){if(typeof c!="string"||c.length===0||c.trim().length===0)return!1;for(let e of je)if(e.test(c))return!0;return!1}function q(c){return c==null?!0:typeof c=="string"?!Me(c):Array.isArray(c)?c.every(t=>q(t)):typeof c=="object"?Object.values(c).every(t=>q(t)):!0}var N=class{constructor(t){this.attempts=0;this.lockedUntil=null;this.unlockCheckInterval=null;this.maxAttempts=Math.max(1,t.maxAttempts),this.blockDurationMs=(t.blockDurationMinutes??5)*60*1e3,this.storageKey=t.storageKey,this.onLocked=t.onLocked,this.onUnlocked=t.onUnlocked,this.storageKey&&typeof sessionStorage<"u"&&this.loadFromStorage()}loadFromStorage(){if(!(!this.storageKey||typeof sessionStorage>"u"))try{let t=sessionStorage.getItem(this.storageKey);if(t){let e=JSON.parse(t);this.attempts=e.attempts??0,this.lockedUntil=e.lockedUntil??null,this.checkExpiration()}}catch{}}saveToStorage(){if(!(!this.storageKey||typeof sessionStorage>"u"))try{let t={attempts:this.attempts,lockedUntil:this.lockedUntil??void 0};sessionStorage.setItem(this.storageKey,JSON.stringify(t))}catch{}}checkExpiration(){return this.lockedUntil===null?!1:Date.now()>=this.lockedUntil?(this.reset(),this.onUnlocked?.(),!0):!1}startUnlockCheck(){this.unlockCheckInterval||(this.unlockCheckInterval=setInterval(()=>{this.checkExpiration()&&this.stopUnlockCheck()},1e3))}stopUnlockCheck(){this.unlockCheckInterval&&(clearInterval(this.unlockCheckInterval),this.unlockCheckInterval=null)}incrementAttempts(){this.attempts++,this.attempts>=this.maxAttempts?(this.lockedUntil=Date.now()+this.blockDurationMs,this.saveToStorage(),this.onLocked?.(this.blockDurationMs),this.startUnlockCheck()):this.saveToStorage()}isLocked(){return this.checkExpiration()?!1:this.lockedUntil!==null&&Date.now()<this.lockedUntil}getRemainingBlockTimeMs(){return this.checkExpiration()||this.lockedUntil===null?0:Math.max(0,this.lockedUntil-Date.now())}reset(){this.attempts=0,this.lockedUntil=null,this.stopUnlockCheck(),this.saveToStorage()}getAttempts(){return this.attempts}};function T(c){return c==null?"":typeof c=="boolean"?c?"true":"false":typeof c=="object"?JSON.stringify(c):String(c)}function L(c){if(!c)return null;try{return JSON.parse(c)}catch{return c}}function C(c,t){return t.split(".").reduce((e,a)=>e?.[a],c)}function M(c,t,e){let a=t.split("."),r=a.pop(),s=a.reduce((o,i)=>((!o[i]||typeof o[i]!="object")&&(o[i]={}),o[i]),c);s[r]=e}function Ae(c){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c)}var A=class{evaluateCondition(t,e){let a=this.getFieldValue(t.field,e);return this.compareValues(a,t.operator,t.value)}evaluateConditions(t,e,a="and"){let r=Array.isArray(t)?t:[t];return r.length===0?!0:a==="and"?r.every(s=>this.evaluateCondition(s,e)):r.some(s=>this.evaluateCondition(s,e))}evaluateDependencies(t,e){let a=!0,r=!0,s=!1;if(t.show&&(a=this.evaluateConditions(t.show,e)),t.hide){let o=this.evaluateConditions(t.hide,e);a=a&&!o}if(t.enable&&(r=this.evaluateConditions(t.enable,e)),t.disable){let o=this.evaluateConditions(t.disable,e);r=r&&!o}if(t.required&&(s=this.evaluateConditions(t.required,e)),t.optional){let o=this.evaluateConditions(t.optional,e);s=s&&!o}return{visible:a,enabled:r,required:s}}getFieldValue(t,e){if(t in e)return e[t];let a=t.split("."),r=e;for(let s of a){if(r==null)return null;r=r[s]}return r}compareValues(t,e,a){switch(e){case"equals":return this.deepEqual(t,a);case"notEquals":return!this.deepEqual(t,a);case"contains":return Array.isArray(t)?t.includes(a):typeof t=="string"?t.includes(String(a)):!1;case"notContains":return!this.compareValues(t,"contains",a);case"greaterThan":return this.toNumber(t)>this.toNumber(a);case"lessThan":return this.toNumber(t)<this.toNumber(a);case"greaterThanOrEqual":return this.toNumber(t)>=this.toNumber(a);case"lessThanOrEqual":return this.toNumber(t)<=this.toNumber(a);case"in":return Array.isArray(a)?a.includes(t):!1;case"notIn":return!this.compareValues(t,"in",a);case"isEmpty":return t==null||t===""||Array.isArray(t)&&t.length===0;case"isNotEmpty":return!this.compareValues(t,"isEmpty",a);case"regex":try{return(typeof a=="string"?new RegExp(a):a).test(String(t||""))}catch{return!1}default:return!1}}deepEqual(t,e){if(t===e)return!0;if(t===null||e===null||t===void 0||e===void 0)return t===e;if(typeof t!=typeof e)return!1;if(Array.isArray(t)&&Array.isArray(e))return t.length!==e.length?!1:t.every((a,r)=>this.deepEqual(a,e[r]));if(typeof t=="object"){let a=Object.keys(t),r=Object.keys(e);return a.length!==r.length?!1:a.every(s=>this.deepEqual(t[s],e[s]))}return!1}toNumber(t){if(typeof t=="number")return t;if(typeof t=="string"){let e=parseFloat(t);return isNaN(e)?0:e}return 0}};var $=class{constructor(){this.conditionEngine=new A}async validateField(t,e){return this.validateFieldWithValidations(t,e,t.validations||[])}async validateFieldWithValidations(t,e,a){let r=[];if(!a||a.length===0)return r;for(let s of a){let o=await this.validateValue(s,e);o.isValid||r.push(o.message||this.getDefaultMessage(s))}return r}async validateValue(t,e){switch(t.type){case"required":return this.validateRequired(e);case"email":return this.validateEmail(e);case"minLength":return this.validateMinLength(e,t.value);case"maxLength":return this.validateMaxLength(e,t.value);case"min":return this.validateMin(e,t.value);case"max":return this.validateMax(e,t.value);case"pattern":return this.validatePattern(e,t.value);case"custom":return await this.validateCustom(e,t);case"noInjection":return this.validateNoInjection(e,t);default:return{isValid:!0}}}validateRequired(t){let e=t!=null&&t!==""&&!(Array.isArray(t)&&t.length===0);return{isValid:e,message:e?void 0:"Este campo es requerido"}}validateEmail(t){if(!t)return{isValid:!0};let e=typeof t=="string"&&Ae(t);return{isValid:e,message:e?void 0:"Debe ser un email v\xE1lido"}}validateMinLength(t,e){if(!t)return{isValid:!0};let r=String(t).length>=e;return{isValid:r,message:r?void 0:`Debe tener al menos ${e} caracteres`}}validateMaxLength(t,e){if(!t)return{isValid:!0};let r=String(t).length<=e;return{isValid:r,message:r?void 0:`Debe tener m\xE1ximo ${e} caracteres`}}validateMin(t,e){if(t==null||t==="")return{isValid:!0};let a=Number(t),r=!isNaN(a)&&a>=e;return{isValid:r,message:r?void 0:`Debe ser mayor o igual a ${e}`}}validateMax(t,e){if(t==null||t==="")return{isValid:!0};let a=Number(t),r=!isNaN(a)&&a<=e;return{isValid:r,message:r?void 0:`Debe ser menor o igual a ${e}`}}validatePattern(t,e){if(!t)return{isValid:!0};let a;if(e instanceof RegExp)a=e;else if(typeof e=="string")try{a=new RegExp(e)}catch{return console.warn("Invalid regex pattern:",e),{isValid:!0}}else return console.warn("Pattern validation expects string or RegExp, got:",typeof e,e),{isValid:!0};let r=a.test(String(t));return{isValid:r,message:r?void 0:"El formato no es v\xE1lido"}}validateNoInjection(t,e){if(t==null||t==="")return{isValid:!0};let a=q(t);return{isValid:a,message:a?void 0:e.message||P}}async validateCustom(t,e){try{let a=await e.validator(t);return{isValid:!!a,message:a?void 0:e.message||"Validaci\xF3n fallida"}}catch{return{isValid:!1,message:e.message||"Error en la validaci\xF3n"}}}getDefaultMessage(t){switch(t.type){case"required":return"Este campo es requerido";case"email":return"Debe ser un email v\xE1lido";case"minLength":return`Debe tener al menos ${t.value} caracteres`;case"maxLength":return`Debe tener m\xE1ximo ${t.value} caracteres`;case"min":return`Debe ser mayor o igual a ${t.value}`;case"max":return`Debe ser menor o igual a ${t.value}`;case"pattern":return"El formato no es v\xE1lido";case"custom":return"Validaci\xF3n fallida";case"noInjection":return P;default:return"Campo inv\xE1lido"}}shouldValidateField(t,e){if(t.hidden||t.disabled)return!1;if(t.dependencies){let a=this.conditionEngine.evaluateDependencies(t.dependencies,e);if(!a.visible||!a.enabled)return!1}return!0}async validateForm(t,e){let a={};for(let r of t)if(this.shouldValidateField(r,e))if(r.type==="array"&&"itemSchema"in r){let i=r.itemSchema?.fields||[],n=e[r.name];if(Array.isArray(n))for(let d=0;d<n.length;d++){let p=n[d];for(let m of i){let u=`${r.name}.${d}.${m.name}`,h=p?.[m.name];if(!this.shouldValidateField(m,e))continue;let y=await this.validateField(m,h);y.length>0&&(a[u]=y)}}let l=await this.validateArrayField(r,n);l.length>0&&(a[r.name]=l)}else{let s=e[r.name],o=await this.validateField(r,s);o.length>0&&(a[r.name]=o)}return a}async validateArrayField(t,e){let a=[],r=t;return r.minItems!==void 0&&(Array.isArray(e)&&e.length>=r.minItems||a.push(`Debe tener al menos ${r.minItems} elementos`)),r.maxItems!==void 0&&(Array.isArray(e)&&e.length<=r.maxItems||a.push(`Debe tener m\xE1ximo ${r.maxItems} elementos`)),a}};var H=class{constructor(){this.wizardState=null;this.schema=null;this.dependencyCache=new Map;this.fieldDependencies=new Map;this.parser=new V,this.validator=new $,this.conditionEngine=new A,this.state=this.createInitialState()}createInitialState(){return{values:{},errors:{},touched:{},isValid:!0,isSubmitting:!1}}initializeSchema(t,e){this.schema=this.parser.parse(t),this.initializeValues(e),this.initializeWizard(),this.buildDependencyMap()}extractAllFields(t){let e=[];for(let a of t)e.push(a),a.type==="group"&&"fields"in a&&e.push(...this.extractAllFields(a.fields)),a.type==="row"&&"fields"in a&&e.push(...this.extractAllFields(a.fields));return e}getArrayItemOnlyFieldNames(t){let e=new Set(t.map(r=>r.name)),a=new Set;for(let r of t)if(r.type==="array"&&"itemSchema"in r&&r.itemSchema?.fields)for(let s of r.itemSchema.fields)e.has(s.name)||a.add(s.name);return a}extractAllFieldsWithArrays(t,e="",a="root"){let r=[];for(let s of t){let o=e?`${e}.${s.name}`:s.name,i=e||"";r.push({field:s,fullPath:o,containerType:a,containerPath:i}),s.type==="group"&&"fields"in s&&r.push(...this.extractAllFieldsWithArrays(s.fields,o,"group")),s.type==="row"&&"fields"in s&&r.push(...this.extractAllFieldsWithArrays(s.fields,o,"row")),s.type==="array"&&"itemSchema"in s&&s.itemSchema?.fields&&r.push(...this.extractAllFieldsWithArrays(s.itemSchema.fields,s.name,"array"))}return r}buildDependencyMap(){if(this.fieldDependencies.clear(),this.dependencyCache.clear(),!this.schema)return;let t=this.schema.isWizard?this.schema.steps.flatMap(a=>a.fields):this.schema.fields||[],e=this.extractAllFieldsWithArrays(t);for(let{field:a,fullPath:r,containerType:s,containerPath:o}of e){if(!a.dependencies)continue;let i=this.extractObservedFields(a.dependencies);for(let n of i)this.fieldDependencies.has(n)||this.fieldDependencies.set(n,new Set),this.fieldDependencies.get(n).add(a.name),r!==a.name&&this.fieldDependencies.get(n).add(r),s==="array"&&o&&(this.fieldDependencies.has(o)||this.fieldDependencies.set(o,new Set),this.fieldDependencies.get(o).add(r))}}extractObservedFields(t){let e=new Set,a=s=>{s&&s.field&&e.add(s.field)},r=s=>{Array.isArray(s)?s.forEach(a):s&&a(s)};return t.show&&r(t.show),t.hide&&r(t.hide),t.enable&&r(t.enable),t.disable&&r(t.disable),t.required&&r(t.required),t.optional&&r(t.optional),e}initializeValues(t){if(!this.schema)return;let e=this.schema.isWizard?this.schema.steps.flatMap(i=>i.fields):this.schema.fields||[],a=this.extractAllFields(e),r={...this.state.values},s={};if(t)for(let i in t){let n=t[i];n!=null&&M(s,i,n)}for(let i of a){let n=C(s,i.name);if(n!=null)continue;let l=C(r,i.name);l!=null?M(s,i.name,l):this.initializeFieldValue(i,s)}let o=this.getArrayItemOnlyFieldNames(e);for(let i in r)o.has(i)||i in s||(s[i]=r[i]);for(let i of e)if(i.type==="array"&&"minItems"in i&&"itemSchema"in i){let n=i,l=n.minItems??0;if(l>=1&&n.itemSchema?.fields?.length){let d=C(s,i.name);if(Array.isArray(d)&&d.length<l){let p=[...d];for(let m=d.length;m<l;m++){let u={};for(let h of n.itemSchema.fields)this.initializeFieldValue(h,u);p.push(u)}M(s,i.name,p)}}}for(let i of o)i in s&&delete s[i];this.state.values=s}initializeFieldValue(t,e){if(t.defaultValue!==void 0)e[t.name]=t.defaultValue;else switch(t.type){case"checkbox":case"switch":e[t.name]=t.checked||!1;break;case"select":"multiple"in t&&t.multiple?e[t.name]=[]:e[t.name]=null;break;case"array":{let a=t,r=a.minItems??0,s=a.itemSchema?.fields;if(r>=1&&s?.length){let o=[];for(let i=0;i<r;i++){let n={};for(let l of s)this.initializeFieldValue(l,n);o.push(n)}e[t.name]=o}else e[t.name]=[];break}case"group":if(e[t.name]={},"fields"in t)for(let a of t.fields)this.initializeFieldValue(a,e[t.name]);break;case"colorpicker":e[t.name]=t.defaultValue??"#000000";break;default:e[t.name]=null}}initializeWizard(){if(!this.schema||!this.schema.isWizard){this.wizardState=null;return}this.wizardState={currentStep:0,totalSteps:this.schema.steps.length,completedSteps:[]}}getState(){return{...this.state}}getWizardState(){return this.wizardState?{...this.wizardState}:null}getValue(t){return C(this.state.values,t)}createDefaultArrayItem(t){let a=t.itemSchema?.fields;if(!a?.length)return{};let r={};for(let s of a)this.initializeFieldValue(s,r);return r}async setValue(t,e){M(this.state.values,t,e),this.state.touched[t]=!0,this.invalidateDependencyCache(t),this.state.touched[t]&&this.schema&&await this.validateField(t);let a=this.fieldDependencies.get(t);if(a)for(let r of a)await this.validateField(r);this.updateValidity()}invalidateDependencyCache(t){let e=this.fieldDependencies.get(t);if(e)for(let s of e){this.dependencyCache.delete(s);let o=this.addArrayIndexToPath(t,s);o&&this.dependencyCache.delete(o)}let a=t.replace(/\[\d+\]/g,"");if(a!==t){if(e=this.fieldDependencies.get(a),e)for(let o of e){this.dependencyCache.delete(o);let i=t.match(/\[(\d+)\]/);if(i){let n=o.includes("[")?o:`${o.split(".").slice(0,-1).join(".")}[${i[1]}].${o.split(".").pop()}`;this.dependencyCache.delete(n)}}let s=a.split(".").pop();if(s&&s!==a&&(e=this.fieldDependencies.get(s),e))for(let o of e){this.dependencyCache.delete(o);let i=t.match(/\[(\d+)\]/);if(i){let l=`${t.split(".")[0].replace(/\[\d+\]/,"")}[${i[1]}].${o}`;this.dependencyCache.delete(l)}}}let r=t.split(".");for(let s=1;s<r.length;s++){if(r[s].includes("["))continue;let o=r.slice(s).join(".");if(e=this.fieldDependencies.get(o),e)for(let i of e)this.dependencyCache.delete(i),this.dependencyCache.delete(`${r[0]}.${o}`)}this.dependencyCache.delete(t)}addArrayIndexToPath(t,e){let a=t.match(/\[(\d+)\]/);if(!a)return null;let r=a[1],s=t.split(".")[0];if(e.startsWith(s)){let o=e.split(".");if(o.length>1)return`${o[0]}[${r}].${o.slice(1).join(".")}`}return null}setValueWithoutValidation(t,e){M(this.state.values,t,e),this.invalidateDependencyCache(t)}async validateField(t){if(!this.schema)return;let e=this.schema.isWizard?this.schema.steps.flatMap(n=>n.fields):this.schema.fields||[],r=this.extractAllFields(e).find(n=>n.name===t);if(!r)return;if(!this.getFieldVisibility(t)){delete this.state.errors[t];return}let s=this.getValue(t),o=this.getActiveValidations(r),i=await this.validator.validateFieldWithValidations(r,s,o);i.length>0?this.state.errors[t]=i:delete this.state.errors[t]}getActiveValidations(t){let e=[...t.validations||[]],a=["text","email","password","textarea"],r=t.skipInjectionValidation??t.props?.skipInjectionValidation;a.includes(t.type)&&!r&&!e.some(i=>i.type==="noInjection")&&(e=[{type:"noInjection"},...e]);let s=this.getFieldRequired(t.name),o=e.some(i=>i.type==="required");if(s&&!o?e=[{type:"required"},...e]:!s&&o&&(e=e.filter(i=>i.type!=="required")),t.conditionalValidations)for(let i of t.conditionalValidations)this.conditionEngine.evaluateConditions(i.condition,this.state.values)&&(e=[...e,...i.validations]);return e}async validateForm(){if(!this.schema)return{};let t=this.schema.isWizard?this.schema.steps.flatMap(r=>r.fields):this.schema.fields||[],e=this.extractAllFields(t),a=await this.validator.validateForm(e,this.state.values);return this.state.errors=a,this.updateValidity(),a}updateValidity(){this.state.isValid=Object.keys(this.state.errors).length===0}setTouched(t){this.state.touched[t]=!0}getErrors(t){return this.state.errors[t]||[]}getAllErrors(){return{...this.state.errors}}reset(){this.state=this.createInitialState(),this.schema&&(this.initializeValues(),this.initializeWizard())}nextStep(){return this.wizardState&&this.wizardState.currentStep<this.wizardState.totalSteps-1?(this.wizardState.currentStep++,!0):!1}previousStep(){return this.wizardState&&this.wizardState.currentStep>0?(this.wizardState.currentStep--,!0):!1}goToStep(t){return this.wizardState&&t>=0&&t<this.wizardState.totalSteps?(this.wizardState.currentStep=t,!0):!1}completeStep(t){this.wizardState&&(this.wizardState.completedSteps.includes(t)||this.wizardState.completedSteps.push(t))}setSubmitting(t){this.state.isSubmitting=t}getCurrentStepFields(){return!this.schema||!this.schema.isWizard||!this.wizardState?this.schema?.fields||[]:this.schema.steps[this.wizardState.currentStep].fields}getFieldVisibility(t){let e=this.dependencyCache.get(t);if(e!==void 0)return e.visible;if(!this.schema)return!0;let a=this.schema.isWizard?this.schema.steps.flatMap(m=>m.fields):this.schema.fields||[],r=this.extractAllFieldsWithArrays(a),s=r.find(m=>m.fullPath===t||m.field.name===t);if(!s){let m=t.replace(/\[\d+\]/g,"");s=r.find(u=>u.field.name===m||u.fullPath===m)}if(!s){let m=t.split(".").pop();s=r.find(u=>u.field.name===m)}if(!s||!s.field.dependencies)return!s?.field.hidden;let{field:o,containerType:i,containerPath:n}=s,l=s.field.dependencies,d={...this.state.values};if(i==="array"&&n){let m,u=y=>{if(y)return Array.isArray(y)?y[0]?.field:y.field};if(m=u(l.show)||u(l.hide)||u(l.enable)||u(l.disable)||u(l.required)||u(l.optional),m&&m){let y=t.match(/\[(\d+)\]/),f=y?parseInt(y[1],10):null,b=null;if(f!==null){let v=C(this.state.values,n);if(Array.isArray(v)&&v[f]&&(b=v[f][m]),b==null){let g=`${n}[${f}]`,w=this.state.values[g];w&&typeof w=="object"&&(b=w[m])}}else{let v=C(this.state.values,n);if(Array.isArray(v)){for(let g of v)if(g&&g[m]!==void 0){b=g[m];break}}}if(b!=null){let v={...this.state.values};v[m]=b;let g=this.conditionEngine.evaluateDependencies(l,v);return this.dependencyCache.set(t,g),g.visible&&!o.hidden}}let h={visible:!0,enabled:!0,required:!1};return this.dependencyCache.set(t,h),h.visible&&!o.hidden}else if(n){let m=C(this.state.values,n);if(m&&typeof m=="object"){let u=(y,f="")=>{let b={},v=Object.entries(y);for(let[g,w]of v){let k=f?`${f}.${g}`:g;w&&typeof w=="object"&&!Array.isArray(w)&&w!==null&&Object.assign(b,u(w,k))}for(let[g,w]of v){let k=f?`${f}.${g}`:g;w&&typeof w=="object"&&!Array.isArray(w)&&w!==null||k in b||(b[k]=w)}return b},h=u(m);d={...this.state.values,...h}}}let p=this.conditionEngine.evaluateDependencies(l,d);return this.dependencyCache.set(t,p),p.visible&&!o.hidden}getFieldEnabled(t){let e=this.dependencyCache.get(t);if(e!==void 0)return e.enabled;if(!this.schema)return!0;let a=this.schema.isWizard?this.schema.steps.flatMap(i=>i.fields):this.schema.fields||[],s=this.extractAllFields(a).find(i=>i.name===t);if(!s)return!0;if(s.disabled)return!1;if(!s.dependencies)return!0;let o=this.conditionEngine.evaluateDependencies(s.dependencies,this.state.values);return this.dependencyCache.set(t,o),o.enabled}getFieldRequired(t){let e=this.dependencyCache.get(t);if(e!==void 0)return e.required;if(!this.schema)return!1;let a=this.schema.isWizard?this.schema.steps.flatMap(n=>n.fields):this.schema.fields||[],s=this.extractAllFields(a).find(n=>n.name===t);if(!s)return!1;let o=s.validations?.some(n=>n.type==="required")||!1;if(!s.dependencies)return o;let i=this.conditionEngine.evaluateDependencies(s.dependencies,this.state.values);return this.dependencyCache.set(t,i),i.required||o}getDependentFields(t){return Array.from(this.fieldDependencies.get(t)||[])}};var x=class{constructor(t,e,a,r,s){this.field=t,this.value=e,this.error=a,this.onChange=r,this.onBlur=s}createInputWithSlots(t){let e=this.field.leadingIcon,a=this.field.trailingIcon;if(!e&&!a)return t;let r=document.createElement("div");if(r.className="easy-form-input-wrapper",e&&this.isSlotContentValid(e)){let o=this.renderSlotContent(e);o.className="easy-form-input-slot easy-form-input-slot-leading",r.appendChild(o)}let s=document.createElement("div");if(s.className="easy-form-input-core",s.appendChild(t),r.appendChild(s),a&&this.isSlotContentValid(a)){let o=this.renderSlotContent(a);o.className="easy-form-input-slot easy-form-input-slot-trailing",r.appendChild(o)}return r}isSlotContentValid(t){return t.type?t.type==="image"?!!t.src:t.type==="html"?!!t.html:!1:!1}renderSlotContent(t){let e=document.createElement("span");if(e.className="easy-form-input-slot-content",t.type==="image"&&t.src){let a=document.createElement("img");a.src=t.src,a.alt=t.alt??"",a.setAttribute("aria-hidden","true"),e.appendChild(a)}else t.type==="html"&&t.html&&(e.innerHTML=t.html);return e}createFieldContainer(t){let e=document.createElement("div"),r=Array.from(t.classList).filter(l=>l.startsWith("easy-form-")&&l!=="easy-form-field"&&(l.includes("-container")||l.includes("-wrapper"))),s=this.field.labelPosition??"up",o=this.createInputWithSlots(t);if(r.length>0?e.className=`easy-form-field easy-form-label-${s} ${r.join(" ")}`:e.className=`easy-form-field easy-form-label-${s}`,s==="none"&&this.field.label){let l=o.querySelector("input, textarea, select")||o;l instanceof HTMLElement&&l.setAttribute("aria-label",this.field.label)}let n=(()=>{if(!this.field.label||s==="none")return null;let l=document.createElement("label");if(l.className="easy-form-label",l.setAttribute("for",this.getFieldId()),l.textContent=this.field.label,this.field.validations?.some(d=>d.type==="required")){let d=document.createElement("span");d.className="easy-form-required",d.textContent=" *",l.appendChild(d)}return l})();if(s==="up")n&&e.appendChild(n),e.appendChild(o);else if(s==="down")e.appendChild(o),n&&e.appendChild(n);else if(s==="left"){let l=document.createElement("div");l.className="easy-form-field-inner easy-form-field-inner-horizontal",n&&l.appendChild(n),l.appendChild(o),e.appendChild(l)}else if(s==="right"){let l=document.createElement("div");l.className="easy-form-field-inner easy-form-field-inner-horizontal",l.appendChild(o),n&&l.appendChild(n),e.appendChild(l)}else e.appendChild(o);if(this.field.description){let l=document.createElement("p");l.className="easy-form-description",l.textContent=this.field.description,e.appendChild(l)}if(this.error){let l=document.createElement("p");l.className="easy-form-error",l.textContent=this.error,e.appendChild(l)}return e}getFieldId(){return`easy-form-${this.field.name}`}applyCommonProps(t){if(t.id=this.getFieldId(),t.setAttribute("name",this.field.name),this.field.disabled&&(t.setAttribute("disabled","true"),t.classList.add("easy-form-input-disabled")),this.field.hidden&&(t.style.display="none",t.classList.add("easy-form-field-hidden")),this.error&&t.classList.add("easy-form-input-error"),this.field.props)for(let[e,a]of Object.entries(this.field.props))(e.startsWith("data-")||e.startsWith("aria-"))&&t.setAttribute(e,String(a))}};function ze(c){let t=[];for(let e=0;e<c.length;e++){let a=c[e];switch(a){case"9":t.push({type:"digit",char:"9",editable:!0});break;case"a":case"A":t.push({type:"letter",char:a,editable:!0});break;case"*":t.push({type:"any",char:"*",editable:!0});break;default:t.push({type:"literal",char:a,editable:!1});break}}return t}function R(c,t){let e="",a=0;for(let r of t){if(!r.editable){e+=r.char;continue}if(a>=c.length)break;let s=c[a];if(!(r.type==="digit"&&!/\d/.test(s))){{if(r.type==="letter"&&!/[a-zA-Z]/.test(s))continue;if(r.type!=="any"){if(r.type!=="any"&&r.type!=="digit"&&r.type!=="letter")continue}}e+=s,a++}}return e}function ce(c,t){if(!c)return"";let e="",a=0;for(let r=0;r<c.length&&a<t.length;r++){let s=c[r],o=t[a];if(o.editable)o.type==="digit"&&/\d/.test(s)||o.type==="letter"&&/[a-zA-Z]/.test(s)||o.type==="any"?(e+=s,a++):(a++,r--);else if(s===o.char)a++;else if(a<t.length-1){let i=t[a+1];i&&i.editable&&(i.type==="digit"&&/\d/.test(s)||i.type==="letter"&&/[a-zA-Z]/.test(s)||i.type==="any")?(e+=s,a+=2):a++}else break}return e}function B(c,t,e="forward"){if(e==="forward"){for(let a=c+1;a<t.length;a++)if(t[a].editable)return a;return t.length}else{for(let a=c-1;a>=0;a--)if(t[a].editable)return a;return 0}}function Ie(c,t="_"){return c.map(e=>e.editable?t:e.char).join("")}function qe(c,t,e,a){let r=0;for(let o=0;o<Math.min(e,c.length);o++){let i=o;i<a.length&&a[i].editable&&r++}let s=0;for(let o=0;o<t.length&&o<a.length;o++)if(a[o].editable&&(s++,s>r))return o+1;return B(Math.min(e,t.length-1),a,"forward")}var z=class{constructor(){this.tokenCache=new Map}getCustomMask(t){return t.custom?t.custom:t.type?me(t.type):null}getTokens(t){let e=this.getCustomMask(t);if(!e)return null;let a=e.pattern;if(this.tokenCache.has(a))return this.tokenCache.get(a);let r=ze(e.pattern);return this.tokenCache.set(a,r),r}applyMask(t,e){let a=this.getTokens(e);if(!a)return t;let r=this.getCustomMask(e),s=a.filter(l=>l.editable),o=new Set(s.map(l=>l.type)),i="";for(let l of t)(o.has("any")||o.has("digit")&&/\d/.test(l)||o.has("letter")&&/[a-zA-Z]/.test(l))&&(i+=l);let n=R(i,a);return r.transform&&(n=r.transform(n),n=R(n,a)),n}removeMask(t,e){let a=this.getTokens(e);return a?ce(t,a):t}getMaskPlaceholder(t){let e=this.getTokens(t);if(!e)return"";let a=this.getCustomMask(t);return Ie(e,a.placeholder||"_")}canInsertChar(t,e,a){let r=this.getTokens(a);if(!r||e>=r.length)return!1;let s=r[e];if(!s.editable)return!1;switch(s.type){case"digit":return/\d/.test(t);case"letter":return/[a-zA-Z]/.test(t);case"any":return!0;default:return!1}}processInput(t,e,a,r){let s=this.getTokens(a);if(!s)return{value:t,cursorPosition:t.length};let o=ce(t,s),i=R(o,s),n=this.getCustomMask(a);n.transform&&(i=n.transform(i),i=R(i,s));let l=qe(e,i,r,s);return{value:i,cursorPosition:Math.min(l,i.length)}}processKeyInput(t,e,a,r,s=!1){let o=this.getTokens(r);if(!o)return{value:e,cursorPosition:a};if(s){if(a===0)return{value:e,cursorPosition:0};let i=B(a-1,o,"backward"),n=e.substring(0,i),l=e.substring(a),d=n+l,p=this.removeMask(d,r),m=this.applyMask(p,r),u=Math.max(0,i-1),h=B(u,o,"forward");return{value:m,cursorPosition:h}}if(t.length===1&&this.canInsertChar(t,a,r)){let i=e.substring(0,a),n=e.substring(a),l=i+t+n;return this.processInput(l,e,r,a)}return{value:e,cursorPosition:a}}};var O=class extends x{constructor(e,a,r,s,o){super(e,a,r,s,o);this.maskEngine=null;this.previousValue="";e.mask&&(this.maskEngine=new z)}render(){let e=document.createElement("input");e.type=this.field.type==="email"?"email":this.field.type==="password"?"password":"text";let a=this.value??"";if(this.maskEngine&&this.field.mask&&(a&&(a=this.maskEngine.applyMask(String(a),this.field.mask)),this.previousValue=a),e.value=a,this.applyCommonProps(e),this.field.placeholder)e.placeholder=this.field.placeholder;else if(this.maskEngine&&this.field.mask){let r=this.maskEngine.getMaskPlaceholder(this.field.mask);r&&(e.placeholder=r)}return this.maskEngine&&this.field.mask?(e.addEventListener("input",r=>{let s=r.target,o=s.selectionStart||0,i=s.value,n=this.maskEngine.processInput(i,this.previousValue,this.field.mask,o);s.value=n.value,this.previousValue=n.value,setTimeout(()=>{s.setSelectionRange(n.cursorPosition,n.cursorPosition)},0);let l=this.field.mask.keepFormat?n.value:this.maskEngine.removeMask(n.value,this.field.mask);this.onChange(l)}),e.addEventListener("keydown",r=>{let s=r.target,o=s.selectionStart||0;if(r.key==="Backspace"||r.key==="Delete"){r.preventDefault();let i=r.key==="Backspace",n=this.maskEngine.processKeyInput("",s.value,o,this.field.mask,i);s.value=n.value,this.previousValue=n.value,setTimeout(()=>{s.setSelectionRange(n.cursorPosition,n.cursorPosition)},0);let l=this.field.mask.keepFormat?n.value:this.maskEngine.removeMask(n.value,this.field.mask);this.onChange(l)}}),e.addEventListener("paste",r=>{r.preventDefault();let s=(r.clipboardData||window.clipboardData).getData("text");if(s){let o=r.target,i=o.selectionStart||0,n=o.value.substring(0,i),l=o.value.substring(i),d=n+s+l,p=this.maskEngine.processInput(d,this.previousValue,this.field.mask,i);o.value=p.value,this.previousValue=p.value,setTimeout(()=>{o.setSelectionRange(p.cursorPosition,p.cursorPosition)},0);let m=this.field.mask.keepFormat?p.value:this.maskEngine.removeMask(p.value,this.field.mask);this.onChange(m)}})):e.addEventListener("input",r=>{let s=r.target;this.onChange(s.value)}),e.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(e)}};var j=class extends x{constructor(e,a,r,s,o){super(e,a,r,s,o);this.maskEngine=null;this.previousValue="";e.mask&&(this.maskEngine=new z)}render(){let e=document.createElement("input");if(this.maskEngine&&this.field.mask){e.type="text";let r=this.value??"";r!==null&&r!==""&&(this.field.mask.type==="currency"?r=this.maskEngine.applyMask(String(r),this.field.mask):this.field.mask.type==="percentage"&&(r=this.maskEngine.applyMask(String(r),this.field.mask))),this.previousValue=r,e.value=r}else e.type="number",e.value=this.value??"";let a=this.field;if(!this.maskEngine&&e.type==="number"&&(a.min!==void 0&&(e.min=String(a.min)),a.max!==void 0&&(e.max=String(a.max)),a.step!==void 0&&(e.step=String(a.step))),this.applyCommonProps(e),this.field.placeholder)e.placeholder=this.field.placeholder;else if(this.maskEngine&&this.field.mask){let r=this.maskEngine.getMaskPlaceholder(this.field.mask);r&&(e.placeholder=r)}return this.maskEngine&&this.field.mask?(e.addEventListener("input",r=>{let s=r.target,o=s.selectionStart||0,i=s.value,n=this.maskEngine.processInput(i,this.previousValue,this.field.mask,o);s.value=n.value,this.previousValue=n.value,setTimeout(()=>{s.setSelectionRange(n.cursorPosition,n.cursorPosition)},0);let l=null;if(this.field.mask.type==="currency"){let d=this.maskEngine.removeMask(n.value,this.field.mask);l=d?parseFloat(d.replace(/[^\d.]/g,"")):null}else if(this.field.mask.type==="percentage"){let d=this.maskEngine.removeMask(n.value,this.field.mask);l=d?parseFloat(d):null}this.onChange(l)}),e.addEventListener("keydown",r=>{let s=r.target,o=s.selectionStart||0;if(r.key==="Backspace"||r.key==="Delete"){r.preventDefault();let i=r.key==="Backspace",n=this.maskEngine.processKeyInput("",s.value,o,this.field.mask,i);s.value=n.value,this.previousValue=n.value,setTimeout(()=>{s.setSelectionRange(n.cursorPosition,n.cursorPosition)},0);let l=null;if(this.field.mask.type==="currency"){let d=this.maskEngine.removeMask(n.value,this.field.mask);l=d?parseFloat(d.replace(/[^\d.]/g,"")):null}else if(this.field.mask.type==="percentage"){let d=this.maskEngine.removeMask(n.value,this.field.mask);l=d?parseFloat(d):null}this.onChange(l)}}),e.addEventListener("paste",r=>{r.preventDefault();let s=(r.clipboardData||window.clipboardData).getData("text");if(s){let o=r.target,i=o.selectionStart||0,n=o.value.substring(0,i),l=o.value.substring(i),d=n+s+l,p=this.maskEngine.processInput(d,this.previousValue,this.field.mask,i);o.value=p.value,this.previousValue=p.value,setTimeout(()=>{o.setSelectionRange(p.cursorPosition,p.cursorPosition)},0);let m=null;if(this.field.mask.type==="currency"){let u=this.maskEngine.removeMask(p.value,this.field.mask);m=u?parseFloat(u.replace(/[^\d.]/g,"")):null}else if(this.field.mask.type==="percentage"){let u=this.maskEngine.removeMask(p.value,this.field.mask);m=u?parseFloat(u):null}this.onChange(m)}})):e.addEventListener("input",r=>{let s=r.target,o=s.value===""?null:Number(s.value);this.onChange(o)}),e.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(e)}};var W=class extends x{render(){let t=document.createElement("textarea");t.value=this.value??"",t.placeholder=this.field.placeholder||"";let e=this.field;return e.rows&&(t.rows=e.rows),e.cols&&(t.cols=e.cols),this.applyCommonProps(t),t.addEventListener("input",a=>{let r=a.target;this.onChange(r.value)}),t.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(t)}};var _=class extends x{render(){let t=document.createElement("select"),e=this.field;if(e.multiple&&(t.multiple=!0),!e.multiple){let r=document.createElement("option");r.value="",r.textContent=e.placeholder||"Selecciona una opci\xF3n",r.setAttribute("data-placeholder",""),r.disabled=!0,t.appendChild(r)}for(let r of e.options){let s=document.createElement("option");typeof r=="string"?(s.value=r,s.textContent=r):(s.value=String(r.value),s.textContent=r.label),t.appendChild(s)}if(e.multiple&&Array.isArray(this.value))for(let r of t.options)r.selected=this.value.includes(r.value);else t.value=this.value??"";this.applyCommonProps(t);let a=()=>{!t.value?t.classList.add("easy-form-select-placeholder"):t.classList.remove("easy-form-select-placeholder")};return a(),t.addEventListener("change",r=>{let s=r.target;if(a(),e.multiple){let o=Array.from(s.selectedOptions).map(i=>i.value);this.onChange(o)}else this.onChange(s.value||null)}),t.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(t)}};var Y=class extends x{render(){let t=document.createElement("input");t.type="checkbox",t.checked=!!this.value,this.applyCommonProps(t),t.addEventListener("change",r=>{let s=r.target;this.onChange(s.checked)}),t.addEventListener("blur",()=>{this.onBlur()});let e=document.createElement("div");e.className="easy-form-field";let a=document.createElement("label");if(a.className="easy-form-label-checkbox",a.setAttribute("for",this.getFieldId()),a.appendChild(t),this.field.label){let r=document.createTextNode(this.field.label);a.appendChild(r)}if(e.appendChild(a),this.field.description){let r=document.createElement("p");r.className="easy-form-description",r.textContent=this.field.description,e.appendChild(r)}if(this.error){let r=document.createElement("p");r.className="easy-form-error",r.textContent=this.error,e.appendChild(r)}return e}};var U=class extends x{render(){let t=document.createElement("div");if(t.className="easy-form-field",this.field.label){let r=document.createElement("label");if(r.className="easy-form-label",r.textContent=this.field.label,this.field.validations?.some(s=>s.type==="required")){let s=document.createElement("span");s.className="easy-form-required",s.textContent=" *",r.appendChild(s)}t.appendChild(r)}let e=document.createElement("div");e.className="easy-form-radio-group";let a=this.field;for(let r of a.options){let s=typeof r=="string"?r:r.value,o=typeof r=="string"?r:r.label,i=document.createElement("div");i.className="easy-form-radio-option";let n=document.createElement("input");n.type="radio",n.name=this.field.name,n.id=`${this.getFieldId()}-${s}`,n.value=String(s),n.checked=String(this.value)===String(s),this.field.disabled&&(n.disabled=!0);let l=document.createElement("label");l.setAttribute("for",n.id),l.textContent=o,l.className="easy-form-radio-label",n.addEventListener("change",()=>{this.onChange(s)}),n.addEventListener("blur",()=>{this.onBlur()}),i.appendChild(n),i.appendChild(l),e.appendChild(i)}if(t.appendChild(e),this.field.description){let r=document.createElement("p");r.className="easy-form-description",r.textContent=this.field.description,t.appendChild(r)}if(this.error){let r=document.createElement("p");r.className="easy-form-error",r.textContent=this.error,t.appendChild(r)}return t}};var K=class extends x{render(){let t=document.createElement("input");t.type="checkbox",t.className="easy-form-switch",t.checked=!!this.value,this.applyCommonProps(t),t.addEventListener("change",r=>{let s=r.target;this.onChange(s.checked)}),t.addEventListener("blur",()=>{this.onBlur()});let e=document.createElement("div");e.className="easy-form-field";let a=document.createElement("label");if(a.className="easy-form-label-switch",a.setAttribute("for",this.getFieldId()),this.field.label){let r=document.createTextNode(this.field.label);a.appendChild(r)}if(a.appendChild(t),e.appendChild(a),this.field.description){let r=document.createElement("p");r.className="easy-form-description",r.textContent=this.field.description,e.appendChild(r)}if(this.error){let r=document.createElement("p");r.className="easy-form-error",r.textContent=this.error,e.appendChild(r)}return e}};var G=class extends x{render(){let t=document.createElement("input");t.type="date";let e=this.field;if(e.min&&(t.min=e.min),e.max&&(t.max=e.max),this.value){let a=this.value instanceof Date?this.value.toISOString().split("T")[0]:String(this.value);t.value=a}return this.applyCommonProps(t),t.addEventListener("change",a=>{let r=a.target;this.onChange(r.value||null)}),t.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(t)}};var J=class extends x{render(){let t=document.createElement("input");t.type="file";let e=this.field;return e.accept&&(t.accept=e.accept),e.multiple&&(t.multiple=!0),this.applyCommonProps(t),t.addEventListener("change",a=>{let r=a.target;r.files&&(e.multiple?this.onChange(Array.from(r.files)):this.onChange(r.files[0]||null))}),t.addEventListener("blur",()=>{this.onBlur()}),this.createFieldContainer(t)}};var Z=class extends x{render(){let t=document.createElement("div");t.className="easy-form-quantity-container";let e=this.field,a=e.min??0,r=e.max??void 0,s=e.step??1,o=this.value??a,i=document.createElement("div");i.className="easy-form-quantity-wrapper";let n=document.createElement("button");n.type="button",n.className="easy-form-quantity-btn easy-form-quantity-decrement",n.textContent="\u2212",n.setAttribute("aria-label","Decrementar"),o<=a&&(n.disabled=!0,n.classList.add("disabled"));let l=document.createElement("input");l.type="number",l.value=String(o),l.min=String(a),r!==void 0&&(l.max=String(r)),l.step=String(s),l.className="easy-form-quantity-input",this.applyCommonProps(l);let d=document.createElement("button");d.type="button",d.className="easy-form-quantity-btn easy-form-quantity-increment",d.textContent="+",d.setAttribute("aria-label","Incrementar"),r!==void 0&&o>=r&&(d.disabled=!0,d.classList.add("disabled")),n.addEventListener("click",()=>{let m=Math.max(a,Number(l.value)-s);l.value=String(m),this.onChange(m),p()}),d.addEventListener("click",()=>{let m=r!==void 0?Math.min(r,Number(l.value)+s):Number(l.value)+s;l.value=String(m),this.onChange(m),p()}),l.addEventListener("input",m=>{let u=m.target,h=Number(u.value);isNaN(h)&&(h=a),h<a&&(h=a),r!==void 0&&h>r&&(h=r),u.value=String(h),this.onChange(h),p()}),l.addEventListener("blur",()=>{this.onBlur()});let p=()=>{let m=Number(l.value);n.disabled=m<=a,n.classList.toggle("disabled",m<=a),r!==void 0?(d.disabled=m>=r,d.classList.toggle("disabled",m>=r)):(d.disabled=!1,d.classList.remove("disabled"))};return i.appendChild(n),i.appendChild(l),i.appendChild(d),t.appendChild(i),this.createFieldContainer(t)}};var X=class extends x{constructor(){super(...arguments);this.openAccordion=null}render(){let e=document.createElement("div");e.className="easy-form-accordion-select-container";let a=this.field,r=this.value??null;return a.options.forEach((s,o)=>{let i=typeof s=="string"?s:s.value,n=typeof s=="string"?s:s.label,l=typeof s=="object"&&"description"in s&&s.description?s.description:void 0,d=document.createElement("div");d.className="easy-form-accordion-item",d.setAttribute("data-value",String(i)),(r===i||Array.isArray(r)&&r.includes(i))&&(d.classList.add("selected"),a.multiple||(this.openAccordion=String(i)));let p=document.createElement("div");p.className="easy-form-accordion-header",p.setAttribute("role","button"),p.setAttribute("tabindex","0"),p.setAttribute("aria-expanded","false");let m=document.createElement("div");m.className="easy-form-accordion-header-content";let u=document.createElement("div");u.className="easy-form-accordion-indicator",a.multiple?(u.classList.add("checkbox"),Array.isArray(r)&&r.includes(i)&&u.classList.add("checked")):(u.classList.add("radio"),r===i&&u.classList.add("checked"));let h=document.createElement("span");h.className="easy-form-accordion-label",h.textContent=n;let y=document.createElement("span");y.className="easy-form-accordion-arrow",y.textContent="\u25BC",m.appendChild(u),m.appendChild(h),p.appendChild(m),p.appendChild(y);let f=document.createElement("div");if(f.className="easy-form-accordion-content",l){let g=document.createElement("p");g.className="easy-form-accordion-description",g.textContent=l,f.appendChild(g)}if(typeof s=="object"&&"content"in s&&s.content){let g=document.createElement("div");g.className="easy-form-accordion-custom-content",typeof s.content=="string"?g.innerHTML=s.content:s.content instanceof HTMLElement&&g.appendChild(s.content),f.appendChild(g)}d.appendChild(p),d.appendChild(f);let b=()=>{let g=d.classList.contains("open");a.multiple||e.querySelectorAll(".easy-form-accordion-item").forEach(w=>{if(w!==d){w.classList.remove("open");let k=w.querySelector(".easy-form-accordion-header"),E=w.querySelector(".easy-form-accordion-content"),S=w.querySelector(".easy-form-accordion-arrow");k&&k.setAttribute("aria-expanded","false"),E&&(E.style.maxHeight=null),S&&(S.style.transform="rotate(0deg)")}}),g?(d.classList.remove("open"),p.setAttribute("aria-expanded","false"),f.style.maxHeight=null,y.style.transform="rotate(0deg)",this.openAccordion=null):(d.classList.add("open"),p.setAttribute("aria-expanded","true"),f.style.maxHeight=f.scrollHeight+"px",y.style.transform="rotate(180deg)",this.openAccordion=String(i))},v=()=>{if(a.multiple){let g=Array.isArray(r)?[...r]:[],w=g.indexOf(i);w>-1?(g.splice(w,1),d.classList.remove("selected"),u.classList.remove("checked")):(g.push(i),d.classList.add("selected"),u.classList.add("checked")),this.onChange(g.length>0?g:null)}else e.querySelectorAll(".easy-form-accordion-item").forEach(g=>{g.classList.remove("selected");let w=g.querySelector(".easy-form-accordion-indicator");w&&w.classList.remove("checked")}),d.classList.add("selected"),u.classList.add("checked"),this.onChange(i)};p.addEventListener("click",g=>{g.stopPropagation(),v(),b()}),p.addEventListener("keydown",g=>{(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),v(),b())}),(r===i||Array.isArray(r)&&r.includes(i))&&(!a.multiple||a.autoExpand)&&setTimeout(()=>{d.classList.add("open"),p.setAttribute("aria-expanded","true"),f.style.maxHeight=f.scrollHeight+"px",y.style.transform="rotate(180deg)"},0),e.appendChild(d)}),this.createFieldContainer(e)}};var Q=class extends x{render(){let t=document.createElement("div");t.className="easy-form-image-grid-container";let e=this.field,a=this.value??null,r=e.columns??3,s=e.imageSize??"medium";return t.style.gridTemplateColumns=`repeat(${r}, 1fr)`,t.style.gap=e.gap??"1rem",e.options.forEach(o=>{let i=typeof o=="string"?o:o.value,n=typeof o=="string"?o:o.label,l=typeof o=="object"&&"image"in o&&o.image?o.image:void 0,d=typeof o=="object"&&"description"in o&&o.description?o.description:void 0,p=document.createElement("div");p.className=`easy-form-image-grid-item easy-form-image-grid-${s}`,p.setAttribute("data-value",String(i)),p.setAttribute("role","button"),p.setAttribute("tabindex","0"),p.setAttribute("aria-label",n),(a===i||Array.isArray(a)&&a.includes(i))&&p.classList.add("selected");let m=document.createElement("div");if(m.className="easy-form-image-grid-image-container",l){let f=document.createElement("img");f.src=l,f.alt=n,f.className="easy-form-image-grid-image",m.appendChild(f)}else{let f=document.createElement("div");f.className="easy-form-image-grid-placeholder",f.textContent=n.charAt(0).toUpperCase(),m.appendChild(f)}let u=document.createElement("div");u.className="easy-form-image-grid-indicator",e.multiple?(u.classList.add("checkbox"),Array.isArray(a)&&a.includes(i)&&(u.classList.add("checked"),u.innerHTML="\u2713")):(u.classList.add("radio"),a===i&&(u.classList.add("checked"),u.innerHTML="\u25CF")),m.appendChild(u);let h=document.createElement("div");if(h.className="easy-form-image-grid-label",h.textContent=n,d){let f=document.createElement("div");f.className="easy-form-image-grid-description",f.textContent=d,p.appendChild(f)}p.appendChild(m),p.appendChild(h);let y=()=>{if(e.multiple){let f=Array.isArray(a)?[...a]:[],b=f.indexOf(i);b>-1?(f.splice(b,1),p.classList.remove("selected"),u.classList.remove("checked"),u.innerHTML=""):(f.push(i),p.classList.add("selected"),u.classList.add("checked"),u.innerHTML="\u2713"),this.onChange(f.length>0?f:null)}else t.querySelectorAll(".easy-form-image-grid-item").forEach(f=>{f.classList.remove("selected");let b=f.querySelector(".easy-form-image-grid-indicator");b&&(b.classList.remove("checked"),b.innerHTML="")}),p.classList.add("selected"),u.classList.add("checked"),u.innerHTML="\u25CF",this.onChange(i)};p.addEventListener("click",y),p.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),y())}),p.addEventListener("blur",()=>{this.onBlur()}),t.appendChild(p)}),this.createFieldContainer(t)}};var ee=class extends x{constructor(){super(...arguments);this.inputs=[]}render(){let e=document.createElement("div");e.className="easy-form-otp-container";let r=this.field.length??6,s=this.value??"",o=String(s).padStart(r,"").slice(0,r);for(let i=0;i<r;i++){let n=document.createElement("input");n.type="text",n.inputMode="numeric",n.maxLength=1,n.className="easy-form-otp-input",n.setAttribute("aria-label",`C\xF3digo d\xEDgito ${i+1}`),o[i]&&(n.value=o[i]),this.applyCommonProps(n),n.id=`${this.getFieldId()}-${i}`;let l=i;n.addEventListener("input",d=>{let p=d.target,m=p.value.replace(/[^0-9]/g,"");p.value=m,m&&l<r-1&&this.inputs[l+1].focus(),this.updateOTPValue()}),n.addEventListener("keydown",d=>{let p=d.target;d.key==="Backspace"&&!p.value&&l>0&&(this.inputs[l-1].focus(),this.inputs[l-1].value="",this.updateOTPValue()),d.key==="ArrowLeft"&&l>0&&(d.preventDefault(),this.inputs[l-1].focus()),d.key==="ArrowRight"&&l<r-1&&(d.preventDefault(),this.inputs[l+1].focus())}),n.addEventListener("paste",d=>{d.preventDefault();let m=(d.clipboardData||window.clipboardData).getData("text").replace(/[^0-9]/g,"").slice(0,r);for(let h=0;h<m.length&&l+h<r;h++)this.inputs[l+h].value=m[h];let u=Math.min(l+m.length,r-1);this.inputs[u].focus(),this.updateOTPValue()}),n.addEventListener("focus",d=>{d.target.select()}),n.addEventListener("blur",()=>{this.onBlur()}),this.inputs.push(n),e.appendChild(n)}return this.createFieldContainer(e)}updateOTPValue(){let e=this.inputs.map(s=>s.value).join(""),a=this.field,r=e.length===this.inputs.length?e:null;a.numeric&&r?this.onChange(Number(r)):this.onChange(r)}};var We=6;function te(c){return c?'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>':'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>'}var re=class extends x{constructor(){super(...arguments);this.inputs=[];this.visible=!1}get passwordField(){return this.field}render(){let e=this.passwordField,a=!!e.characterSeparated,r=a?typeof e.characterSeparated=="number"?e.characterSeparated:We:0;return a?this.createFieldContainer(this.renderSeparated(r)):this.createFieldContainer(this.renderSingle())}renderSingle(){let a=!!this.passwordField.showToggle,r=document.createElement("input");if(r.type="password",r.value=this.value??"",r.id=this.getFieldId(),this.applyCommonProps(r),this.field.placeholder&&(r.placeholder=this.field.placeholder),r.addEventListener("input",i=>{this.onChange(i.target.value)}),r.addEventListener("blur",()=>this.onBlur()),!a)return r;let s=document.createElement("div");s.className="easy-form-password-inner",r.classList.add("easy-form-password-input"),s.appendChild(r);let o=document.createElement("button");return o.type="button",o.className="easy-form-password-toggle",o.setAttribute("aria-label","Mostrar contrase\xF1a"),o.innerHTML=te(!1),o.addEventListener("click",()=>{this.visible=!this.visible,r.type=this.visible?"text":"password",o.setAttribute("aria-label",this.visible?"Ocultar contrase\xF1a":"Mostrar contrase\xF1a"),o.innerHTML=te(this.visible)}),s.appendChild(o),s}renderSeparated(e){let r=!!this.passwordField.showToggle,s=this.value??"",o=String(s).slice(0,e),i=document.createElement("div");i.className="easy-form-password-separated";for(let n=0;n<e;n++){let l=document.createElement("input");l.type="password",l.maxLength=1,l.className="easy-form-password-separated-input",l.setAttribute("aria-label",`Car\xE1cter ${n+1} de ${e}`),o[n]&&(l.value=o[n]),this.applyCommonProps(l),l.id=n===0?this.getFieldId():`${this.getFieldId()}-${n}`,n>0&&l.removeAttribute("name");let d=n;l.addEventListener("input",p=>{p.target.value&&d<e-1&&this.inputs[d+1].focus(),this.updateSeparatedValue()}),l.addEventListener("keydown",p=>{p.key==="Backspace"&&!p.target.value&&d>0&&(this.inputs[d-1].focus(),this.inputs[d-1].value="",this.updateSeparatedValue()),p.key==="ArrowLeft"&&d>0&&(p.preventDefault(),this.inputs[d-1].focus()),p.key==="ArrowRight"&&d<e-1&&(p.preventDefault(),this.inputs[d+1].focus())}),l.addEventListener("paste",p=>{p.preventDefault();let u=((p.clipboardData||window.clipboardData)?.getData("text")||"").slice(0,e-d).split("");for(let y=0;y<u.length&&d+y<e;y++)this.inputs[d+y].value=u[y];let h=Math.min(d+u.length,e-1);this.inputs[h].focus(),this.updateSeparatedValue()}),l.addEventListener("focus",p=>p.target.select()),l.addEventListener("blur",()=>this.onBlur()),this.inputs.push(l),i.appendChild(l)}if(r){let n=document.createElement("div");n.className="easy-form-password-separated-toggle";let l=document.createElement("button");l.type="button",l.className="easy-form-password-toggle",l.setAttribute("aria-label","Mostrar contrase\xF1a"),l.innerHTML=te(!1),l.addEventListener("click",()=>{this.visible=!this.visible;let d=this.visible?"text":"password";this.inputs.forEach(p=>{p.type=d}),l.setAttribute("aria-label",this.visible?"Ocultar contrase\xF1a":"Mostrar contrase\xF1a"),l.innerHTML=te(this.visible)}),n.appendChild(l),i.appendChild(n)}return i}updateSeparatedValue(){let e=this.inputs.map(a=>a.value).join("");this.onChange(e||null)}};var ae=class extends x{render(){let t=this.field,e=t.accept??"",a=t.multiple??!1,r=document.createElement("div");r.className="easy-form-file-drop",r.setAttribute("tabindex","0");let s=document.createElement("input");s.type="file",s.className="easy-form-file-drop-input",s.style.display="none",e&&(s.accept=e),a&&(s.multiple=!0);let o=document.createElement("span");o.className="easy-form-file-drop-label",o.textContent="Arrastra archivos aqu\xED o haz clic para seleccionar",r.appendChild(o),r.appendChild(s);let i=document.createElement("div");i.className="easy-form-file-drop-list";let n=d=>{let p=d?Array.isArray(d)?d.map(m=>m.name):[d.name]:[];if(i.innerHTML="",p.length===0){i.style.display="none";return}i.style.display="block",p.forEach(m=>{let u=document.createElement("div");u.className="easy-form-file-drop-item",u.textContent=m,i.appendChild(u)})};n(this.value);let l=d=>{if(!d||d.length===0)return;let p=a?Array.from(d):d[0];this.onChange(p),this.onBlur(),n(p)};return r.addEventListener("click",()=>{s.click()}),s.addEventListener("change",d=>{let p=d.target;l(p.files),p.value=""}),r.addEventListener("dragover",d=>{d.preventDefault(),d.stopPropagation(),r.classList.add("easy-form-file-drop-over")}),r.addEventListener("dragleave",d=>{d.preventDefault(),d.stopPropagation(),r.classList.remove("easy-form-file-drop-over")}),r.addEventListener("drop",d=>{d.preventDefault(),d.stopPropagation(),r.classList.remove("easy-form-file-drop-over"),l(d.dataTransfer?.files??null)}),r.appendChild(i),this.createFieldContainer(r)}};var _e="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css",se=class extends x{constructor(){super(...arguments);this.mapInstance=null;this.markerInstance=null}render(){let e=this.field,a=e.center??{lat:0,lng:0},r=e.zoom??13,s=this.value,o=typeof s=="object"&&s?.lat!=null?s.lat:a.lat,i=typeof s=="object"&&s?.lng!=null?s.lng:a.lng,n=document.createElement("div");n.className="easy-form-map";let l=document.createElement("div");l.className="easy-form-map-inputs";let d=document.createElement("input");d.type="number",d.step="any",d.placeholder="Latitud",d.value=String(o),d.className="easy-form-map-lat";let p=document.createElement("input");p.type="number",p.step="any",p.placeholder="Longitud",p.value=String(i),p.className="easy-form-map-lng";let m=()=>{let v=parseFloat(d.value),g=parseFloat(p.value);!isNaN(v)&&!isNaN(g)&&(this.onChange({lat:v,lng:g}),this.syncMarkerPosition(v,g)),this.onBlur()};d.addEventListener("change",m),p.addEventListener("change",m),l.appendChild(d),l.appendChild(p),n.appendChild(l);let u=document.createElement("div");u.className="easy-form-map-container",n.appendChild(u);let h="easy-form-leaflet-css",y=!1,f=document.createElement("link");return f.id=h,f.rel="stylesheet",f.href=_e,f.onload=()=>{y=!0},n.insertBefore(f,n.firstChild),(async()=>{if(typeof window>"u")return;u.style.height="300px",u.style.width="100%",u.style.position="relative",u.style.overflow="hidden",u.style.display="block",await new Promise(E=>{let S=()=>{y&&u.offsetWidth>0&&u.offsetHeight>0?E(void 0):requestAnimationFrame(S)};S()}),await new Promise(E=>setTimeout(E,50));let v;try{v=await import("leaflet")}catch{u.innerHTML=`
|
|
2324
2350
|
<div style="padding:2rem;text-align:center;color:#666;font-size:0.875rem;background:#f9f9f9;border-radius:4px;">
|
|
2325
2351
|
<strong>Campo map requiere Leaflet</strong><br><br>
|
|
2326
2352
|
Instala e importa Leaflet para usar el mapa interactivo:<br>
|
|
@@ -2328,5 +2354,5 @@ var R=class{parse(t){if(!t)throw new Error("Schema es requerido");if(!t.fields&&
|
|
|
2328
2354
|
En tu app: <code>import 'leaflet'</code> y <code>import 'leaflet/dist/leaflet.css'</code><br>
|
|
2329
2355
|
<a href="https://easyforms.dev/docs/tipos-campos#map" target="_blank" rel="noopener" style="color:var(--easy-form-primary,#007bff);">Ver documentaci\xF3n</a>
|
|
2330
2356
|
</div>
|
|
2331
|
-
`;return}delete x.Icon.Default.prototype._getIconUrl,x.Icon.Default.mergeOptions({iconRetinaUrl:"https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png",iconUrl:"https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png",shadowUrl:"https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png"}),this.mapInstance=x.map(u,{preferCanvas:!1,zoomControl:!0}).setView([o,i],r);let v=x.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',maxZoom:19}).addTo(this.mapInstance);this.mapInstance.invalidateSize(),v.on("load",()=>{this.mapInstance&&this.mapInstance.invalidateSize()});let C=()=>{this.mapInstance&&this.mapInstance.invalidateSize()};setTimeout(C,100),setTimeout(C,300),setTimeout(C,500),new IntersectionObserver(w=>{w.forEach(k=>{k.isIntersecting&&this.mapInstance&&setTimeout(()=>{this.mapInstance?.invalidateSize()},100)})}).observe(u),this.markerInstance=x.marker([o,i],{draggable:!0}).addTo(this.mapInstance).on("dragend",()=>{let w=this.markerInstance.getLatLng();d.value=String(Number(w.lat.toFixed(6))),c.value=String(Number(w.lng.toFixed(6))),this.onChange({lat:w.lat,lng:w.lng}),this.onBlur()}),this.mapInstance.on("click",w=>{let{lat:k,lng:S}=w.latlng;this.markerInstance.setLatLng([k,S]),d.value=String(Number(k.toFixed(6))),c.value=String(Number(S.toFixed(6))),this.onChange({lat:k,lng:S}),this.onBlur()})})(),this.createFieldContainer(n)}syncMarkerPosition(e,a){this.mapInstance&&this.markerInstance&&(this.markerInstance.setLatLng([e,a]),this.mapInstance.setView([e,a]),setTimeout(()=>{this.mapInstance?.invalidateSize()},50))}};var qe=m=>`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="${m?"currentColor":"none"}" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" role="img" aria-hidden="true"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>`,oe=class extends b{render(){let t=this.field,e=t.max??5,a=t.half??!1,r=this.value!=null?Number(this.value):0,s=document.createElement("div");s.className="easy-form-rating",s.setAttribute("role","slider"),s.setAttribute("aria-valuemin","0"),s.setAttribute("aria-valuemax",String(e)),s.setAttribute("aria-valuenow",String(r)),s.setAttribute("aria-label",this.field.label||"Rating"),s.setAttribute("tabindex","0");let o=document.createElement("div");o.className="easy-form-rating-stars";for(let i=1;i<=e;i++){let n=document.createElement("button");n.type="button";let l=r>=i||a&&r>=i-.5;n.className=l?"easy-form-rating-star easy-form-rating-star-filled":"easy-form-rating-star",n.innerHTML=qe(l),n.setAttribute("aria-label",`${i} de ${e}`),n.addEventListener("click",d=>{d.preventDefault();let c=d.target.closest("button")?.getBoundingClientRect(),p=i;if(a&&c){let u=c.left+c.width/2;p=d.clientX<u?i-.5:i}this.onChange(p),this.onBlur(),this.rerenderStars(s,e,p,a),s.setAttribute("aria-valuenow",String(p))}),o.appendChild(n)}return s.appendChild(o),s.addEventListener("keydown",i=>{let n=Number(s.getAttribute("aria-valuenow"))||0,l=n;i.key==="ArrowRight"||i.key==="ArrowUp"?(i.preventDefault(),l=Math.min(e,a?n+.5:n+1),this.onChange(l)):(i.key==="ArrowLeft"||i.key==="ArrowDown")&&(i.preventDefault(),l=Math.max(0,a?n-.5:n-1),this.onChange(l)),l!==n&&(this.rerenderStars(s,e,l,a),s.setAttribute("aria-valuenow",String(l)))}),this.createFieldContainer(s)}rerenderStars(t,e,a,r){t.querySelectorAll(".easy-form-rating-star").forEach((o,i)=>{let n=i+1,l=a>=n||r&&a>=n-.5;o.className=l?"easy-form-rating-star easy-form-rating-star-filled":"easy-form-rating-star",o.innerHTML=qe(l)})}};var ie=class extends b{render(){let t=this.field,e=t.min??0,a=t.max??100,r=t.step??1,s=t.showValue??!1,o=document.createElement("input");o.type="range",o.min=String(e),o.max=String(a),o.step=String(r),o.value=this.value!=null?String(this.value):String(e),o.setAttribute("aria-valuemin",String(e)),o.setAttribute("aria-valuemax",String(a)),o.setAttribute("aria-valuenow",o.value),this.applyCommonProps(o),o.addEventListener("input",n=>{let l=n.target,d=r>=1?parseInt(l.value,10):parseFloat(l.value);this.onChange(isNaN(d)?e:d),i&&(i.textContent=l.value),o.setAttribute("aria-valuenow",l.value)}),o.addEventListener("change",()=>{this.onBlur()});let i=null;if(s){i=document.createElement("span"),i.className="easy-form-slider-value",i.textContent=o.value;let n=document.createElement("div");return n.className="easy-form-slider-wrapper",n.appendChild(o),n.appendChild(i),this.createFieldContainer(n)}return this.createFieldContainer(o)}};var Ye=/^#?([0-9A-Fa-f]{6})$/;function pe(m){let t=m.match(Ye);return t?`#${t[1].toLowerCase()}`:/^[0-9A-Fa-f]{6}$/.test(m)?`#${m.toLowerCase()}`:"#000000"}var ne=class extends b{render(){let e=this.field.defaultValue??"#000000",a=this.value!=null&&typeof this.value=="string"?pe(this.value):e,r=document.createElement("div");r.className="easy-form-color-wrapper";let s=document.createElement("input");s.type="color",s.value=a,s.setAttribute("value",a),s.setAttribute("aria-label",this.field.label||"Color"),s.id=`${this.getFieldId()}-picker`,this.field.disabled&&s.setAttribute("disabled","true");let o=document.createElement("input");o.type="text",o.value=a,o.setAttribute("aria-label",`${this.field.label||"Color"} (hex)`),o.placeholder="#000000",o.className="easy-form-color-text",this.applyCommonProps(o);let i=()=>{let l=s.value||"#000000",d=pe(l);o.value=d,this.onChange(d)},n=()=>{let l=o.value.trim(),d=l.startsWith("#")?l:`#${l}`;if(/^#[0-9A-Fa-f]{6}$/.test(d)){let c=pe(d);s.value=c,this.onChange(c)}};return s.addEventListener("input",i),s.addEventListener("change",()=>{i(),this.onBlur()}),o.addEventListener("input",n),o.addEventListener("blur",()=>{n(),this.onBlur()}),r.appendChild(s),r.appendChild(o),this.createFieldContainer(r)}};function Ve(m,t,e,a,r){switch(m.type){case"text":case"email":return new O(m,t,e,a,r).render();case"password":return new re(m,t,e,a,r).render();case"number":return new j(m,t,e,a,r).render();case"textarea":return new W(m,t,e,a,r).render();case"select":return new _(m,t,e,a,r).render();case"checkbox":return new Y(m,t,e,a,r).render();case"radio":return new U(m,t,e,a,r).render();case"switch":return new G(m,t,e,a,r).render();case"date":return new K(m,t,e,a,r).render();case"file":return new Z(m,t,e,a,r).render();case"file-drop":return new ae(m,t,e,a,r).render();case"map":return new se(m,t,e,a,r).render();case"rating":return new oe(m,t,e,a,r).render();case"slider":return new ie(m,t,e,a,r).render();case"colorpicker":return new ne(m,t,e,a,r).render();case"quantity":return new J(m,t,e,a,r).render();case"accordion-select":return new X(m,t,e,a,r).render();case"image-grid-select":return new Q(m,t,e,a,r).render();case"otp":return new ee(m,t,e,a,r).render();default:let s=document.createElement("div");return s.textContent=`Tipo de campo no soportado: ${m.type}`,s}}var Re=new Map;function Ue(m,t){Re.set(m,t)}function Pe(m){for(let[t,e]of Object.entries(m))Ue(t,e)}function ue(m){return Re.get(m)}var Ge={fields:[{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"password",name:"password",label:"Password",placeholder:"Enter your password",validations:[{type:"required",message:"Password is required"},{type:"minLength",value:6,message:"Password must be at least 6 characters"}]},{type:"checkbox",name:"rememberMe",label:"Remember me",defaultValue:!1}]},Ke={fields:[{type:"text",name:"name",label:"Full Name",placeholder:"Enter your full name",validations:[{type:"required",message:"Name is required"},{type:"minLength",value:2,message:"Name must be at least 2 characters"}]},{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"password",name:"password",label:"Password",placeholder:"Create a password",validations:[{type:"required",message:"Password is required"},{type:"minLength",value:8,message:"Password must be at least 8 characters"}]},{type:"password",name:"confirmPassword",label:"Confirm Password",placeholder:"Confirm your password",validations:[{type:"required",message:"Please confirm your password"},{type:"custom",validator:m=>typeof m=="string"&&m.length>=8,message:"Password must be at least 8 characters"}]}]},Ze={fields:[{type:"otp",name:"code",label:"Verification Code",validations:[{type:"required",message:"Verification code is required"}]}]},Je={fields:[{type:"text",name:"name",label:"Name",placeholder:"Enter your name",validations:[{type:"required",message:"Name is required"}]},{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"text",name:"subject",label:"Subject",placeholder:"Enter the subject",validations:[{type:"required",message:"Subject is required"}]},{type:"textarea",name:"message",label:"Message",placeholder:"Enter your message",rows:5,validations:[{type:"required",message:"Message is required"},{type:"minLength",value:10,message:"Message must be at least 10 characters"}]}]},Xe={fields:[{type:"email",name:"email",label:"Email",placeholder:"Enter your email address",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]}]},Qe={fields:[{type:"password",name:"currentPassword",label:"Current Password",placeholder:"Enter your current password",validations:[{type:"required",message:"Current password is required"}]},{type:"password",name:"newPassword",label:"New Password",placeholder:"Enter your new password",validations:[{type:"required",message:"New password is required"},{type:"minLength",value:8,message:"Password must be at least 8 characters"}]},{type:"password",name:"confirmPassword",label:"Confirm New Password",placeholder:"Confirm your new password",validations:[{type:"required",message:"Please confirm your new password"},{type:"custom",validator:m=>typeof m=="string"&&m.length>=8,message:"Password must be at least 8 characters"}]}]},et={fields:[{type:"text",name:"name",label:"Full Name",placeholder:"Enter your full name",validations:[{type:"required",message:"Name is required"}]},{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"text",name:"phone",label:"Phone",placeholder:"Enter your phone number",mask:{type:"phone"}},{type:"textarea",name:"bio",label:"Bio",placeholder:"Tell us about yourself",rows:4},{type:"file",name:"avatar",label:"Profile Picture",accept:"image/*"}]},tt={fields:[{type:"group",name:"billingAddress",label:"Billing Address",fields:[{type:"text",name:"street",label:"Street Address",placeholder:"Enter street address",validations:[{type:"required",message:"Street address is required"}]},{type:"row",name:"cityState",fields:[{type:"text",name:"city",label:"City",placeholder:"City",validations:[{type:"required",message:"City is required"}]},{type:"text",name:"state",label:"State",placeholder:"State",validations:[{type:"required",message:"State is required"}]}]},{type:"text",name:"zipCode",label:"ZIP Code",placeholder:"ZIP Code",validations:[{type:"required",message:"ZIP code is required"}]}]},{type:"select",name:"paymentMethod",label:"Payment Method",options:[{label:"Credit Card",value:"credit-card"},{label:"Debit Card",value:"debit-card"},{label:"PayPal",value:"paypal"},{label:"Bank Transfer",value:"bank-transfer"}],validations:[{type:"required",message:"Payment method is required"}]},{type:"select",name:"shipping",label:"Shipping Method",options:[{label:"Standard (5-7 days)",value:"standard"},{label:"Express (2-3 days)",value:"express"},{label:"Overnight",value:"overnight"}],validations:[{type:"required",message:"Shipping method is required"}]}]},rt={fields:[{type:"select",name:"rating",label:"Rating",options:[{label:"1 - Poor",value:1},{label:"2 - Fair",value:2},{label:"3 - Good",value:3},{label:"4 - Very Good",value:4},{label:"5 - Excellent",value:5}],validations:[{type:"required",message:"Rating is required"}]},{type:"textarea",name:"comment",label:"Comment",placeholder:"Share your feedback",rows:5,validations:[{type:"required",message:"Comment is required"}]},{type:"email",name:"email",label:"Email (optional)",placeholder:"Enter your email if you want a response"}]},at={fields:[{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"checkbox",name:"weeklyNewsletter",label:"Weekly Newsletter",defaultValue:!0},{type:"checkbox",name:"productUpdates",label:"Product Updates",defaultValue:!1},{type:"checkbox",name:"promotions",label:"Promotions and Special Offers",defaultValue:!1}]},st={fields:[{type:"date",name:"date",label:"Date",validations:[{type:"required",message:"Date is required"}]},{type:"text",name:"time",label:"Time",placeholder:"HH:MM",mask:{type:"time"},validations:[{type:"required",message:"Time is required"}]},{type:"number",name:"guests",label:"Number of Guests",placeholder:"Enter number of guests",min:1,max:20,validations:[{type:"required",message:"Number of guests is required"},{type:"min",value:1,message:"At least 1 guest is required"}]},{type:"textarea",name:"specialRequests",label:"Special Requests",placeholder:"Any special requests or dietary restrictions?",rows:4}]},ot={fields:[{type:"select",name:"rating",label:"Rating",options:[{label:"1 Star",value:1},{label:"2 Stars",value:2},{label:"3 Stars",value:3},{label:"4 Stars",value:4},{label:"5 Stars",value:5}],validations:[{type:"required",message:"Rating is required"}]},{type:"text",name:"title",label:"Review Title",placeholder:"Give your review a title",validations:[{type:"required",message:"Review title is required"},{type:"minLength",value:5,message:"Title must be at least 5 characters"}]},{type:"textarea",name:"comment",label:"Your Review",placeholder:"Share your experience",rows:6,validations:[{type:"required",message:"Review comment is required"},{type:"minLength",value:20,message:"Review must be at least 20 characters"}]}]},De={login:Ge,register:Ke,otp:Ze,contact:Je,"password-reset":Xe,"password-change":Qe,profile:et,checkout:tt,feedback:rt,subscription:at,booking:st,review:ot};function fe(m){return m in De?De[m]:null}function He(m,t){let e=fe(m);if(!e)throw new Error(`Template "${m}" not found`);let a=e.fields||[],r=e.steps;if(r&&r.length>0){let s=r[r.length-1];return{...e,steps:[...r.slice(0,-1),{...s,fields:[...s.fields,...t]}]}}return{...e,fields:[...a,...t]}}var it=typeof HTMLElement<"u"?HTMLElement:class{},he=class extends it{constructor(){if(typeof HTMLElement>"u")throw new Error("EasyForm can only be used in a browser environment");super();this.customComponents={};this.isRendering=!1;this.attemptsLock=null;this.lockCountdownInterval=null;this.slotTemplates=null;this.skipPreserveValuesOnNextRender=!1;this.persistenceConfig=null;this.persistenceDebounceTimer=null;this.pendingRestoreValues=null;this.isRestoringValues=!1;this.dependencyRenderTimeout=null;this.stateManager=new $,this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["schema","template","template-extend","theme","colors","initialData","loading","disabled","max-attempts","block-duration-minutes","attempts-storage-key","submit-button","label-position","show-completed-indicator","form-direction"]}get schema(){let e=this.getAttribute("schema");return e?this.getAttribute("template")?(console.warn('EasyForm: Cannot use both "schema" and "template" attributes. "template" will be ignored.'),F(e)):F(e):null}set schema(e){e&&this.getAttribute("template")&&(console.warn('EasyForm: Setting "schema" will remove "template" attribute.'),this.removeAttribute("template"),this.removeAttribute("template-extend")),e?this.setAttribute("schema",L(e)):this.removeAttribute("schema")}get template(){let e=this.getAttribute("template");return e?(this.getAttribute("schema")&&console.warn('EasyForm: Cannot use both "template" and "schema" attributes. "schema" will be ignored.'),e):null}set template(e){e&&this.getAttribute("schema")&&(console.warn('EasyForm: Setting "template" will remove "schema" attribute.'),this.removeAttribute("schema")),e?this.setAttribute("template",e):(this.removeAttribute("template"),this.removeAttribute("template-extend"))}get templateExtend(){let e=this.getAttribute("template-extend");return e?F(e):null}set templateExtend(e){e?this.setAttribute("template-extend",L(e)):this.removeAttribute("template-extend")}get maxAttempts(){let e=this.getAttribute("max-attempts");if(!e)return null;let a=parseInt(e,10);return isNaN(a)?null:a}set maxAttempts(e){e!=null&&e>=1?this.setAttribute("max-attempts",String(e)):this.removeAttribute("max-attempts")}get blockDurationMinutes(){let e=this.getAttribute("block-duration-minutes");if(!e)return null;let a=parseInt(e,10);return isNaN(a)?null:a}set blockDurationMinutes(e){e!=null&&e>=1?this.setAttribute("block-duration-minutes",String(e)):this.removeAttribute("block-duration-minutes")}get attemptsStorageKey(){return this.getAttribute("attempts-storage-key")}set attemptsStorageKey(e){e?this.setAttribute("attempts-storage-key",e):this.removeAttribute("attempts-storage-key")}get submitButton(){let e=this.getAttribute("submit-button");if(e)try{return F(e)}catch{return null}return null}set submitButton(e){e&&typeof e=="object"?this.setAttribute("submit-button",L(e)):this.removeAttribute("submit-button")}getSubmitButtonConfig(e){let a=this.submitButton,s={...e?.submitButton,...a};return{visible:s.visible??!0,text:s.text??"Enviar",width:s.width??"auto",align:s.align??"left"}}connectedCallback(){this.setupAttemptsLock(),this.setupStyles(),this.render()}attributeChangedCallback(e,a,r){if(e==="schema"&&r!==a&&(this.getAttribute("template")&&(console.warn('EasyForm: "schema" and "template" cannot be used together. Removing "template".'),this.removeAttribute("template"),this.removeAttribute("template-extend")),this.handleSchemaChange()),e==="template"&&r!==a&&(this.getAttribute("schema")&&(console.warn('EasyForm: "template" and "schema" cannot be used together. Removing "schema".'),this.removeAttribute("schema")),this.handleSchemaChange()),e==="template-extend"&&r!==a&&this.handleSchemaChange(),e==="initialData"&&r!==a&&this.handleSchemaChange(),(e==="theme"||e==="colors")&&r!==a&&this.setupStyles(),e==="loading"&&r!==a){let s=this.shadow.querySelector("form");this.updateLoadingOverlay(s||void 0),s&&s.querySelectorAll("input, textarea, select, button").forEach(i=>{i instanceof HTMLElement&&"disabled"in i&&(i.disabled=this.loading)})}e==="disabled"&&r!==a&&this.render(),(e==="label-position"||e==="form-direction"||e==="show-completed-indicator")&&r!==a&&this.render(),(e==="max-attempts"||e==="block-duration-minutes"||e==="attempts-storage-key")&&r!==a&&(this.setupAttemptsLock(),this.updateLockOverlay()),e==="submit-button"&&r!==a&&this.render()}setupAttemptsLock(){let e=this.maxAttempts;if(e==null||e<1){this.attemptsLock=null;return}this.attemptsLock=new q({maxAttempts:e,blockDurationMinutes:this.blockDurationMinutes??5,storageKey:this.attemptsStorageKey??void 0,onLocked:()=>{this.updateLockOverlay()},onUnlocked:()=>{this.stopLockCountdown(),this.updateLockOverlay(),this.render()}})}handleSchemaChange(){let e=null,a=this.template;if(a?e=this.getSchemaFromTemplate(a):e=this.schema,e){let r=this.initialData;this.stateManager.initializeSchema(e,r||void 0),this.initPersistence(e),this.render()}}getSchemaFromTemplate(e){let a=fe(e);if(!a)return console.error(`EasyForm: Template "${e}" not found`),null;let r=this.templateExtend;return r&&r.length>0?He(e,r):a}async render(){if(!this.isRendering){this.isRendering=!0;try{let e=null,a=this.template;if(a?e=this.getSchemaFromTemplate(a):e=this.schema,!e){let E=this.shadow.querySelector("form");E&&E.parentNode===this.shadow&&E.remove();return}let r=this.skipPreserveValuesOnNextRender,s=r?{}:this.preserveCurrentValues();this.skipPreserveValuesOnNextRender=!1;let o=this.stateManager.getWizardState();if(s&&Object.keys(s).length>0)for(let[E,w]of Object.entries(s))this.stateManager.setValueWithoutValidation(E,w);let i=this.initialData,n=o!==null,l=e.steps&&e.steps.length>0;if(!r&&(!o||!n||!l||o&&e.steps&&o.totalSteps!==e.steps.length)&&(this.stateManager.initializeSchema(e,i||void 0),n&&l&&o)){let E=this.stateManager.getWizardState();if(E&&o.totalSteps===E.totalSteps){o.currentStep>=0&&o.currentStep<E.totalSteps&&this.stateManager.goToStep(o.currentStep);for(let w of o.completedSteps)w>=0&&w<E.totalSteps&&this.stateManager.completeStep(w)}}let c=this.stateManager.getWizardState(),p=document.createElement("form");p.addEventListener("submit",E=>this.handleSubmit(E)),(this.disabled||this.loading)&&p.classList.add("easy-form-disabled");let u=this.getAttribute("form-direction"),h=e.direction??(u==="vertical"||u==="horizontal"?u:"vertical");p.classList.add(`easy-form-direction-${h}`);let y=this.getAttribute("show-completed-indicator"),f=e.completedIndicator??(y!==null&&y!=="false"),g=typeof f=="object"&&f?.position?f.position:"top";if(c)this.renderWizard(p,e);else{this.renderFields(p,e.fields||[]);let E=this.getSubmitButtonConfig(e);if(E.visible){let w=document.createElement("div");w.className="easy-form-submit-wrapper",w.style.textAlign=E.align;let k=document.createElement("button");k.type="submit",k.textContent=E.text,k.className="easy-form-submit",k.style.width=E.width,(this.disabled||this.loading)&&(k.disabled=!0),w.appendChild(k),p.appendChild(w)}}let x=null;if(f){let{completed:E,total:w}=this.getCompletedRequiredProgress(e),k=document.createElement("div");k.className="easy-form-completed-indicator",k.setAttribute("role","progressbar"),k.setAttribute("aria-valuenow",String(E)),k.setAttribute("aria-valuemin","0"),k.setAttribute("aria-valuemax",String(w)),k.setAttribute("aria-label",`Campos obligatorios completados: ${E} de ${w}`);let S=document.createElement("div");S.className="easy-form-completed-track";let le=document.createElement("div");le.className="easy-form-completed-fill",le.style.width=w>0?`${E/w*100}%`:"0%",S.appendChild(le),k.appendChild(S),x=document.createElement("div"),x.className="easy-form-wrapper",g==="top"?(x.appendChild(k),x.appendChild(p)):(x.appendChild(p),x.appendChild(k))}let v=this.shadow.querySelector("form");if(v&&v.parentNode===this.shadow&&v!==p)try{v.remove()}catch(E){console.warn("Error al eliminar formulario anterior:",E)}let C=this.shadow.querySelector(".easy-form-wrapper");C&&C.remove(),this.shadow.appendChild(x||p),this.loading&&this.updateLoadingOverlay(p),this.updateLockOverlay(p)}finally{this.isRendering=!1,this.pendingRestoreValues&&this.applyPendingRestoreValues()}}}updateLockOverlay(e){let a=this.shadow.querySelector(".easy-form-lock-overlay");if(a&&a.remove(),this.stopLockCountdown(),!this.attemptsLock?.isLocked())return;let r=e||this.shadow.querySelector("form");if(!r)return;let s=document.createElement("div");s.className="easy-form-lock-overlay";let o=document.createElement("div");o.className="easy-form-lock-message",o.setAttribute("role","alert");let i=()=>{let n=this.attemptsLock.getRemainingBlockTimeMs();if(n<=0){this.stopLockCountdown();return}let l=Math.floor(n/6e4),d=Math.floor(n%6e4/1e3),c=l>0?`${l} min ${d} s`:`${d} segundos`;o.textContent=`Demasiados intentos. Intenta de nuevo en ${c}.`};i(),s.appendChild(o),r.appendChild(s),this.lockCountdownInterval=setInterval(i,1e3)}stopLockCountdown(){this.lockCountdownInterval&&(clearInterval(this.lockCountdownInterval),this.lockCountdownInterval=null)}updateLoadingOverlay(e){let a=this.shadow.querySelector(".easy-form-loading-overlay");if(a&&a.remove(),this.loading){let r=e||this.shadow.querySelector("form");if(r){let s=document.createElement("div");s.className="easy-form-loading-overlay";let o=document.createElement("div");o.className="easy-form-loading-spinner",s.appendChild(o),r.appendChild(s)}}}preserveCurrentValues(){let e=null,a=this.template;if(a?e=this.getSchemaFromTemplate(a):e=this.schema,!e)return{};let r=this.shadow.querySelector("form"),s={};if(!r)return s;let o=r.querySelectorAll("input, textarea, select");for(let i of o){let n=i.getAttribute("name");if(!n||!(this.findFieldInSchema(e,n)!==null))continue;let d;if(i instanceof HTMLInputElement)if(i.type==="checkbox")d=i.checked;else if(i.type==="radio")if(i.checked)d=i.value;else continue;else i.type==="number"?d=i.value===""?null:Number(i.value):d=i.value;else i instanceof HTMLTextAreaElement?d=i.value:i instanceof HTMLSelectElement&&(i.multiple?d=Array.from(i.selectedOptions).map(c=>c.value):d=i.value||null);d!==void 0&&(s[n]=d===""?null:d)}return s}initializeSlotTemplates(){if(this.slotTemplates!==null)return;let e=[];for(let a of Array.from(this.children))a instanceof HTMLElement&&e.push(a);if(e.length===0){this.slotTemplates=[];return}this.slotTemplates=e.map(a=>{let r=a.hasAttribute("row")?a.getAttribute("row"):null,s=r!=null&&r!==""?Number(r):NaN,o=Number.isFinite(s)?s:null;return{template:a.cloneNode(!0),row:o}})}getSlotClonesByRow(e){this.initializeSlotTemplates();let a=new Map;if(!this.slotTemplates||this.slotTemplates.length===0)return a;for(let{template:r,row:s}of this.slotTemplates){let o=typeof s=="number"?s:-1;Number.isFinite(o)||(o=-1),(o<0||o>=e)&&(o=-1);let i=r.cloneNode(!0),n=a.get(o)??[];n.push(i),a.set(o,n)}return a}applySlotDisabledState(e){if(!this.disabled&&!this.loading)return;e.classList.add("easy-form-slot-disabled"),e.querySelectorAll("input, textarea, select, button").forEach(r=>{"disabled"in r&&(r.disabled=!0)})}renderFields(e,a){if(a.length===0){let n=this.getSlotClonesByRow(0).get(-1);if(n&&n.length>0)for(let l of n)this.applySlotDisabledState(l),e.appendChild(l);return}let r=a.length,s=this.getSlotClonesByRow(r);for(let i=0;i<a.length;i++){let n=s.get(i);if(n&&n.length>0){for(let c of n)this.applySlotDisabledState(c),e.appendChild(c);s.delete(i)}let l=a[i],d=this.renderField(l);d&&e.appendChild(d)}let o=s.get(-1);if(o&&o.length>0)for(let i of o)this.applySlotDisabledState(i),e.appendChild(i)}renderField(e){let a=this.stateManager.getFieldVisibility(e.name),r=this.stateManager.getFieldEnabled(e.name);if(e.type==="group"){let f=this.renderGroup(e);return a||(f.style.display="none",f.classList.add("easy-form-field-hidden")),r||f.classList.add("easy-form-field-disabled"),f}if(e.type==="row"){let f=this.renderRow(e);return a||(f.style.display="none",f.classList.add("easy-form-field-hidden")),r||f.classList.add("easy-form-field-disabled"),f}if(e.type==="array"){let f=this.renderArray(e);return a||(f.style.display="none",f.classList.add("easy-form-field-hidden")),r||f.classList.add("easy-form-field-disabled"),f}if(e.type==="custom"){let f=this.renderCustom(e);return f&&(a||(f.style.display="none",f.classList.add("easy-form-field-hidden")),r||f.classList.add("easy-form-field-disabled")),f}let s=this.stateManager.getValue(e.name),o=this.stateManager.getErrors(e.name),i=o.length>0?o[0]:void 0,n=this.disabled||this.loading,l=this.getAttribute("label-position"),d=["up","down","left","right","none"],c=e.labelPosition??(l&&d.includes(l)?l:"up"),p={...e,disabled:n||!r||e.disabled,labelPosition:c},u=ue(e.type);if(u){let f=u({field:p,value:s,error:i,onChange:g=>this.handleFieldChange(e.name,g),onBlur:()=>this.handleFieldBlur(e.name)});return f&&!a&&(f.style.display="none",f.classList.add("easy-form-field-hidden")),f}let h=Ve(p,s,i,f=>this.handleFieldChange(e.name,f),()=>this.handleFieldBlur(e.name)),y=h.querySelector(".easy-form-field")||h;return y instanceof HTMLElement&&y.setAttribute("data-field-name",e.name),a||(h.style.display="none",h.classList.add("easy-form-field-hidden")),h}renderGroup(e){let a=e,r=a.direction??"vertical",s=a.collapsible===!0,o=a.defaultOpen!==!1,i=document.createElement("div");if(i.className=`easy-form-group easy-form-direction-${r}`,e.name&&i.setAttribute("data-field-name",e.name),s){i.classList.add("easy-form-group-collapsible"),o||i.classList.add("easy-form-group-collapsed");let n=document.createElement("button");n.type="button",n.className="easy-form-group-header",n.setAttribute("aria-expanded",String(o));let l=`easy-form-group-${(e.name||"group").replace(/[^a-z0-9]/gi,"-")}-content`;n.setAttribute("aria-controls",l);let d=document.createElement("span");d.textContent=e.label||"Grupo";let c=document.createElement("span");c.className="easy-form-group-chevron",c.setAttribute("aria-hidden","true"),c.textContent="\u25BC",n.appendChild(d),n.appendChild(c),i.appendChild(n);let p=document.createElement("div");if(p.id=l,p.className="easy-form-group-content","fields"in e&&e.fields)for(let h of e.fields){let y=h.name.startsWith(e.name+".")?h.name:`${e.name}.${h.name}`,f={...h,name:y},g=this.renderField(f);g&&p.appendChild(g)}i.appendChild(p);let u=h=>{h?p.style.maxHeight=p.scrollHeight+"px":p.style.maxHeight="0"};o?requestAnimationFrame(()=>u(!0)):p.style.maxHeight="0",n.addEventListener("click",()=>{i.classList.contains("easy-form-group-collapsed")?(i.classList.remove("easy-form-group-collapsed"),n.setAttribute("aria-expanded","true"),u(!0)):(p.style.maxHeight=p.scrollHeight+"px",requestAnimationFrame(()=>{i.classList.add("easy-form-group-collapsed"),n.setAttribute("aria-expanded","false"),u(!1)}))})}else{if(e.label){let n=document.createElement("h3");n.className="easy-form-group-label",n.textContent=e.label,i.appendChild(n)}if("fields"in e&&e.fields)for(let n of e.fields){let l=n.name.startsWith(e.name+".")?n.name:`${e.name}.${n.name}`,d={...n,name:l},c=this.renderField(d);c&&i.appendChild(c)}}return i}renderRow(e){let a=document.createElement("div");a.className="easy-form-row";let r=e;if(a.style.display="flex",a.style.flexWrap="wrap",a.style.alignItems=r.align||"stretch",r.gap!==void 0){let s=typeof r.gap=="number"?`${r.gap}px`:r.gap;a.style.gap=s}else a.style.gap="1rem";if("fields"in e&&e.fields)for(let s of e.fields){let o=this.renderField(s);if(o){let i=document.createElement("div");i.style.flex="1",i.style.minWidth="0",i.appendChild(o),a.appendChild(i)}}return a}renderArray(e){let a=document.createElement("div");if(a.className="easy-form-array",a.setAttribute("data-field-name",e.name),e.label){let c=document.createElement("label");c.className="easy-form-label",c.textContent=e.label,a.appendChild(c)}let r=this.stateManager.getValue(e.name)||[],s=e,o=s.minItems??0,i=s.maxItems??1/0,n=document.createElement("div");n.className="easy-form-array-items";for(let c=0;c<r.length;c++){let p=document.createElement("div");if(p.className="easy-form-array-item",s.itemSchema?.fields)for(let y of s.itemSchema.fields){let f={...y,name:`${e.name}.${c}.${y.name}`},g=this.renderField(f);g&&p.appendChild(g)}let u=document.createElement("button");u.type="button",u.textContent="Eliminar",u.className="easy-form-array-remove";let h=r.length<=o;this.disabled||this.loading||h?u.disabled=!0:u.addEventListener("click",()=>{let y=[...r];y.splice(c,1),this.handleFieldChange(e.name,y)}),p.appendChild(u),n.appendChild(p)}a.appendChild(n);let l=document.createElement("button");l.type="button",l.textContent="Agregar",l.className="easy-form-array-add";let d=r.length>=i;return this.disabled||this.loading||d?l.disabled=!0:l.addEventListener("click",()=>{let c=this.stateManager.createDefaultArrayItem(e),p=[...r,c];this.handleFieldChange(e.name,p)}),a.appendChild(l),a}renderCustom(e){let a=ue("custom");if(!a){let i=document.createElement("div");return i.textContent=`Componente custom no registrado para: ${e.name}`,i}let r=this.stateManager.getValue(e.name),s=this.stateManager.getErrors(e.name),o=s.length>0?s[0]:void 0;return a({field:e,value:r,error:o,onChange:i=>this.handleFieldChange(e.name,i),onBlur:()=>this.handleFieldBlur(e.name)})}getCompletedRequiredProgress(e){let a=d=>{let c=[];for(let p of d)if(p.type==="array"&&"itemSchema"in p&&p.itemSchema?.fields){let u=this.stateManager.getValue(p.name),h=Array.isArray(u)?u.length:0;for(let y=0;y<h;y++)for(let f of p.itemSchema.fields)c.push({...f,name:`${p.name}.${y}.${f.name}`})}else(p.type==="group"||p.type==="row")&&"fields"in p&&p.fields?c.push(...a(p.fields)):c.push(p);return c},r=e.steps?this.stateManager.getCurrentStepFields()||[]:e.fields||[],i=a(r).filter(d=>d.validations?.some(c=>c.type==="required")).filter(d=>this.stateManager.getFieldVisibility(d.name)),n=i.length;return{completed:i.filter(d=>{if(this.stateManager.getErrors(d.name).length>0)return!1;let p=this.stateManager.getValue(d.name);return!(p==null||typeof p=="string"&&p.trim()===""||Array.isArray(p)&&p.length===0&&d.type==="array")}).length,total:n}}renderWizard(e,a){let r=this.stateManager.getWizardState();if(!r)return;let s=document.createElement("div");s.className="easy-form-wizard";let o=document.createElement("div");o.className="easy-form-wizard-steps";let i=a?.stepStyle;if(i&&i!=="default"&&o.classList.add(`ef-stepper-${i}`),a?.steps)for(let p=0;p<a.steps.length;p++){let u=document.createElement("div");u.className="easy-form-wizard-step",p===r.currentStep&&u.classList.add("active"),r.completedSteps.includes(p)&&u.classList.add("completed"),u.textContent=a.steps[p].title,o.appendChild(u)}s.appendChild(o);let n=document.createElement("div");n.className="easy-form-wizard-fields";let l=this.stateManager.getCurrentStepFields();this.renderFields(n,l),s.appendChild(n);let d=document.createElement("div");if(d.className="easy-form-wizard-nav",r.currentStep>0){let p=document.createElement("button");p.type="button",p.textContent="Anterior",p.className="easy-form-wizard-prev",this.disabled||this.loading?p.disabled=!0:p.addEventListener("click",()=>{this.stateManager.getWizardState()&&this.stateManager.previousStep()&&(this.render(),this.emitStepChange())}),d.appendChild(p)}if(r.currentStep<r.totalSteps-1){let p=document.createElement("button");p.type="button",p.textContent="Siguiente",p.className="easy-form-wizard-next",this.disabled||this.loading?p.disabled=!0:p.addEventListener("click",async()=>{let u=this.stateManager.getWizardState();if(!u)return;let h=this.stateManager.getCurrentStepFields();for(let x of h)this.stateManager.getFieldVisibility(x.name)&&await this.stateManager.validateField(x.name);let y=this.stateManager.getAllErrors(),f={};for(let x of h)y[x.name]&&y[x.name].length>0&&(f[x.name]=y[x.name]);Object.keys(f).length>0?this.emitError(f):(this.stateManager.completeStep(u.currentStep),this.stateManager.nextStep()&&(this.render(),this.emitStepChange()))}),d.appendChild(p)}let c=this.getSubmitButtonConfig(a);if(r.currentStep===r.totalSteps-1&&c.visible){let p=document.createElement("button");p.type="button",p.textContent=c.text,p.className="easy-form-wizard-next",p.style.width=c.width,this.disabled||this.loading?p.disabled=!0:p.addEventListener("click",async()=>{let u=this.stateManager.getCurrentStepFields();for(let g of u)this.stateManager.getFieldVisibility(g.name)&&await this.stateManager.validateField(g.name);let h=this.stateManager.getAllErrors(),y={};for(let g of u)h[g.name]&&h[g.name].length>0&&(y[g.name]=h[g.name]);Object.keys(y).length>0?this.emitError(y):await this.handleSubmit(new Event("submit"))}),d.appendChild(p)}s.appendChild(d),e.appendChild(s)}async handleFieldChange(e,a){await this.stateManager.setValue(e,a),this.scheduleSave();let r=this.schema;if(r){let i=this.findFieldInSchema(r,e);i?.type==="array"&&(this.rerenderArrayField(i)||(this.skipPreserveValuesOnNextRender=!0,requestAnimationFrame(()=>this.render())))}let s=this.stateManager.getDependentFields(e);s.length>0&&(this.dependencyRenderTimeout&&clearTimeout(this.dependencyRenderTimeout),this.dependencyRenderTimeout=setTimeout(()=>{this.renderDependentFields(s),this.emitDependencyChange(e,s)},10));let o=new CustomEvent("change",{detail:{field:e,value:a,values:this.stateManager.getState().values},bubbles:!0,composed:!0});this.dispatchEvent(o)}rerenderArrayField(e){let a=this.shadow.querySelector(`[data-field-name="${e.name}"].easy-form-array`);if(!a?.parentNode)return!1;let r=this.renderArray(e);return a.parentNode.replaceChild(r,a),!0}renderDependentFields(e){let a=this.shadow.querySelector("form");if(!a)return;let r=this.schema;if(r)for(let s of e){let o=a.querySelector(`.easy-form-field[name="${s}"], [data-field-name="${s}"]`)?.closest(".easy-form-field")??a.querySelector(`[data-field-name="${s}"]`);if(o){let i=this.findFieldInSchema(r,s);if(!i)continue;let n=this.renderField(i);n&&o.parentNode&&o.parentNode.replaceChild(n,o)}}}emitDependencyChange(e,a){let r=new CustomEvent("dependencyChange",{detail:{changedField:e,affectedFields:a},bubbles:!0,composed:!0});this.dispatchEvent(r)}async handleFieldBlur(e){this.stateManager.setTouched(e),await this.stateManager.validateField(e),this.updateSingleField(e)}updateSingleField(e){let a=this.schema;if(!a||!this.findFieldInSchema(a,e))return;let s=this.stateManager.getErrors(e),o=s.length>0?s[0]:void 0,i=this.shadow.querySelector(`[name="${e}"]`)?.closest(".easy-form-field");if(!i)return;let n=i.querySelector(".easy-form-error");if(o){if(n)n.textContent=o;else{let d=document.createElement("p");d.className="easy-form-error",d.textContent=o,i.appendChild(d)}i.querySelector("input, textarea, select")?.classList.add("easy-form-input-error")}else n?.remove(),i.querySelector("input, textarea, select")?.classList.remove("easy-form-input-error")}findFieldInSchema(e,a){let r=e.fields||[],s=a.indexOf(".");if(s>0){let o=a.slice(0,s),i=a.slice(s+1),n=r.find(l=>l.name===o);if(!n)return null;if((n.type==="group"||n.type==="row")&&"fields"in n&&n.fields){let l=this.findFieldInSchema({fields:n.fields},i);return l?{...l,name:a}:null}return null}for(let o of r){if(o.name===a)return o;if(o.type==="group"&&"fields"in o){let i=this.findFieldInSchema({fields:o.fields},a);if(i)return i}if(o.type==="row"&&"fields"in o){let i=this.findFieldInSchema({fields:o.fields},a);if(i)return i}}return null}async handleSubmit(e){if(e.preventDefault(),this.attemptsLock?.isLocked())return;let a=await this.stateManager.validateForm(),r=this.stateManager.getState();if(Object.keys(a).length>0){for(let o of Object.keys(a))this.updateSingleField(o);this.emitError(a);return}let s=new CustomEvent("submit",{detail:{values:r.values,isValid:!0,errors:{}},bubbles:!0,composed:!0});this.dispatchEvent(s),this.clearPersistence()}emitError(e){let a=new CustomEvent("error",{detail:{errors:e},bubbles:!0,composed:!0});this.dispatchEvent(a)}emitStepChange(){let e=this.stateManager.getWizardState();if(!e)return;let a=new CustomEvent("stepChange",{detail:{currentStep:e.currentStep,previousStep:e.currentStep>0?e.currentStep-1:e.currentStep,totalSteps:e.totalSteps},bubbles:!0,composed:!0});this.dispatchEvent(a)}registerComponents(e){this.customComponents={...this.customComponents,...e},Pe(e)}reset(){this.stateManager.reset(),this.render()}incrementAttempts(){this.attemptsLock?.incrementAttempts(),this.attemptsLock?.isLocked()&&this.updateLockOverlay()}resetAttempts(){this.attemptsLock?.reset(),this.stopLockCountdown(),this.updateLockOverlay(),this.render()}isLocked(){return this.attemptsLock?.isLocked()??!1}getRemainingBlockTimeMs(){return this.attemptsLock?.getRemainingBlockTimeMs()??0}requestSubmit(){let e=this.shadow.querySelector("form");e&&typeof e.requestSubmit=="function"&&e.requestSubmit()}clear(){let e=this.schema,a=this.template,r=null;a?r=this.getSchemaFromTemplate(a):r=e,r&&(this.stateManager.initializeSchema(r,{}),this.render())}getValues(){return this.stateManager.getState().values}getValue(e){return this.stateManager.getValue(e)}async setValue(e,a){await this.stateManager.setValue(e,a),this.render()}async setValues(e){for(let[a,r]of Object.entries(e))await this.stateManager.setValue(a,r);this.render()}async validate(){let e=await this.stateManager.validateForm();if(Object.keys(e).length>0){for(let a of Object.keys(e))this.updateSingleField(a);this.emitError(e)}else this.shadow.querySelectorAll(".easy-form-error").forEach(s=>s.remove()),this.shadow.querySelectorAll(".easy-form-input-error").forEach(s=>s.classList.remove("easy-form-input-error"));return e}async validateField(e){return await this.stateManager.validateField(e),this.updateSingleField(e),this.stateManager.getErrors(e)}getErrors(){return this.stateManager.getAllErrors()}getFieldErrors(e){return this.stateManager.getErrors(e)}isValid(){return this.stateManager.getState().isValid}get theme(){let e=this.getAttribute("theme");return e&&["plano","tradicional","material","rounded-shadow","lines","shadcn","chakra","mantine","glass","bordered","minimal","efc"].includes(e)?e:"plano"}set theme(e){e?this.setAttribute("theme",e):this.removeAttribute("theme")}get colors(){let e=this.getAttribute("colors");return e?F(e):null}set colors(e){e?this.setAttribute("colors",L(e)):this.removeAttribute("colors")}get initialData(){let e=this.getAttribute("initialData");return e?F(e):null}set initialData(e){e?this.setAttribute("initialData",L(e)):this.removeAttribute("initialData")}get loading(){return this.hasAttribute("loading")}set loading(e){e?this.setAttribute("loading",""):this.removeAttribute("loading")}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}setupStyles(){let e=this.shadow.querySelector("style");e&&e.remove();let a=this.theme,r=I(this.colors||void 0),s=P(a,r),o=document.createElement("style");o.textContent=s,this.shadow.firstChild?this.shadow.insertBefore(o,this.shadow.firstChild):this.shadow.appendChild(o)}initPersistence(e){if(!e.persistence||!e.persistence.enabled){this.persistenceConfig=null;return}this.persistenceConfig={enabled:!0,key:e.persistence.key,autoSave:e.persistence.autoSave??!0,debounce:e.persistence.debounce??500,onRestore:e.persistence.onRestore},this.restoreFromStorage()}restoreFromStorage(){if(!(!this.persistenceConfig||!this.persistenceConfig.enabled)&&this.persistenceConfig.key)try{let e=localStorage.getItem(this.persistenceConfig.key);if(e){let a=JSON.parse(e);a&&typeof a=="object"&&(this.pendingRestoreValues=a,this.persistenceConfig.onRestore&&this.persistenceConfig.onRestore(a))}}catch(e){console.warn("EasyForm: Error restoring from localStorage:",e)}}applyPendingRestoreValues(){if(!this.pendingRestoreValues||this.isRestoringValues)return;this.isRestoringValues=!0;let e={...this.pendingRestoreValues};this.pendingRestoreValues=null;for(let[a,r]of Object.entries(e))this.stateManager.setValueWithoutValidation(a,r);this.updateInputsWithValues(e),this.isRestoringValues=!1}updateInputsWithValues(e){for(let a of Object.keys(e)){let r=this.shadow.querySelector(`[name="${a}"]`);r&&(r.value=e[a]??"")}}saveToStorage(){if(!(!this.persistenceConfig||!this.persistenceConfig.enabled)&&this.persistenceConfig.key)try{let e=this.stateManager.getState().values;localStorage.setItem(this.persistenceConfig.key,JSON.stringify(e))}catch(e){console.warn("EasyForm: Error saving to localStorage:",e)}}scheduleSave(){!this.persistenceConfig||!this.persistenceConfig.enabled||this.persistenceConfig.autoSave&&(this.persistenceDebounceTimer&&clearTimeout(this.persistenceDebounceTimer),this.persistenceDebounceTimer=setTimeout(()=>{this.saveToStorage()},this.persistenceConfig.debounce))}clearPersistence(){if(!(!this.persistenceConfig||!this.persistenceConfig.key))try{localStorage.removeItem(this.persistenceConfig.key)}catch(e){console.warn("EasyForm: Error clearing localStorage:",e)}}};typeof window<"u"&&typeof customElements<"u"&&!customElements.get("easy-form")&&customElements.define("easy-form",he);export{he as EasyForm};
|
|
2357
|
+
`;return}delete v.Icon.Default.prototype._getIconUrl,v.Icon.Default.mergeOptions({iconRetinaUrl:"https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png",iconUrl:"https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png",shadowUrl:"https://unpkg.com/leaflet@1.9.4/dist/images/marker-shadow.png"}),this.mapInstance=v.map(u,{preferCanvas:!1,zoomControl:!0}).setView([o,i],r);let g=v.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',maxZoom:19}).addTo(this.mapInstance);this.mapInstance.invalidateSize(),g.on("load",()=>{this.mapInstance&&this.mapInstance.invalidateSize()});let w=()=>{this.mapInstance&&this.mapInstance.invalidateSize()};setTimeout(w,100),setTimeout(w,300),setTimeout(w,500),new IntersectionObserver(E=>{E.forEach(S=>{S.isIntersecting&&this.mapInstance&&setTimeout(()=>{this.mapInstance?.invalidateSize()},100)})}).observe(u),this.markerInstance=v.marker([o,i],{draggable:!0}).addTo(this.mapInstance).on("dragend",()=>{let E=this.markerInstance.getLatLng();d.value=String(Number(E.lat.toFixed(6))),p.value=String(Number(E.lng.toFixed(6))),this.onChange({lat:E.lat,lng:E.lng}),this.onBlur()}),this.mapInstance.on("click",E=>{let{lat:S,lng:F}=E.latlng;this.markerInstance.setLatLng([S,F]),d.value=String(Number(S.toFixed(6))),p.value=String(Number(F.toFixed(6))),this.onChange({lat:S,lng:F}),this.onBlur()})})(),this.createFieldContainer(n)}syncMarkerPosition(e,a){this.mapInstance&&this.markerInstance&&(this.markerInstance.setLatLng([e,a]),this.mapInstance.setView([e,a]),setTimeout(()=>{this.mapInstance?.invalidateSize()},50))}};var Ne=c=>`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="${c?"currentColor":"none"}" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" role="img" aria-hidden="true"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>`,oe=class extends x{render(){let t=this.field,e=t.max??5,a=t.half??!1,r=this.value!=null?Number(this.value):0,s=document.createElement("div");s.className="easy-form-rating",s.setAttribute("role","slider"),s.setAttribute("aria-valuemin","0"),s.setAttribute("aria-valuemax",String(e)),s.setAttribute("aria-valuenow",String(r)),s.setAttribute("aria-label",this.field.label||"Rating"),s.setAttribute("tabindex","0");let o=document.createElement("div");o.className="easy-form-rating-stars";for(let i=1;i<=e;i++){let n=document.createElement("button");n.type="button";let l=r>=i||a&&r>=i-.5;n.className=l?"easy-form-rating-star easy-form-rating-star-filled":"easy-form-rating-star",n.innerHTML=Ne(l),n.setAttribute("aria-label",`${i} de ${e}`),n.addEventListener("click",d=>{d.preventDefault();let p=d.target.closest("button")?.getBoundingClientRect(),m=i;if(a&&p){let u=p.left+p.width/2;m=d.clientX<u?i-.5:i}this.onChange(m),this.onBlur(),this.rerenderStars(s,e,m,a),s.setAttribute("aria-valuenow",String(m))}),o.appendChild(n)}return s.appendChild(o),s.addEventListener("keydown",i=>{let n=Number(s.getAttribute("aria-valuenow"))||0,l=n;i.key==="ArrowRight"||i.key==="ArrowUp"?(i.preventDefault(),l=Math.min(e,a?n+.5:n+1),this.onChange(l)):(i.key==="ArrowLeft"||i.key==="ArrowDown")&&(i.preventDefault(),l=Math.max(0,a?n-.5:n-1),this.onChange(l)),l!==n&&(this.rerenderStars(s,e,l,a),s.setAttribute("aria-valuenow",String(l)))}),this.createFieldContainer(s)}rerenderStars(t,e,a,r){t.querySelectorAll(".easy-form-rating-star").forEach((o,i)=>{let n=i+1,l=a>=n||r&&a>=n-.5;o.className=l?"easy-form-rating-star easy-form-rating-star-filled":"easy-form-rating-star",o.innerHTML=Ne(l)})}};var ie=class extends x{render(){let t=this.field,e=t.min??0,a=t.max??100,r=t.step??1,s=t.showValue??!1,o=document.createElement("input");o.type="range",o.min=String(e),o.max=String(a),o.step=String(r),o.value=this.value!=null?String(this.value):String(e),o.setAttribute("aria-valuemin",String(e)),o.setAttribute("aria-valuemax",String(a)),o.setAttribute("aria-valuenow",o.value),this.applyCommonProps(o),o.addEventListener("input",n=>{let l=n.target,d=r>=1?parseInt(l.value,10):parseFloat(l.value);this.onChange(isNaN(d)?e:d),i&&(i.textContent=l.value),o.setAttribute("aria-valuenow",l.value)}),o.addEventListener("change",()=>{this.onBlur()});let i=null;if(s){i=document.createElement("span"),i.className="easy-form-slider-value",i.textContent=o.value;let n=document.createElement("div");return n.className="easy-form-slider-wrapper",n.appendChild(o),n.appendChild(i),this.createFieldContainer(n)}return this.createFieldContainer(o)}};var Ye=/^#?([0-9A-Fa-f]{6})$/;function pe(c){let t=c.match(Ye);return t?`#${t[1].toLowerCase()}`:/^[0-9A-Fa-f]{6}$/.test(c)?`#${c.toLowerCase()}`:"#000000"}var ne=class extends x{render(){let e=this.field.defaultValue??"#000000",a=this.value!=null&&typeof this.value=="string"?pe(this.value):e,r=document.createElement("div");r.className="easy-form-color-wrapper";let s=document.createElement("input");s.type="color",s.value=a,s.setAttribute("value",a),s.setAttribute("aria-label",this.field.label||"Color"),s.id=`${this.getFieldId()}-picker`,this.field.disabled&&s.setAttribute("disabled","true");let o=document.createElement("input");o.type="text",o.value=a,o.setAttribute("aria-label",`${this.field.label||"Color"} (hex)`),o.placeholder="#000000",o.className="easy-form-color-text",this.applyCommonProps(o);let i=()=>{let l=s.value||"#000000",d=pe(l);o.value=d,this.onChange(d)},n=()=>{let l=o.value.trim(),d=l.startsWith("#")?l:`#${l}`;if(/^#[0-9A-Fa-f]{6}$/.test(d)){let p=pe(d);s.value=p,this.onChange(p)}};return s.addEventListener("input",i),s.addEventListener("change",()=>{i(),this.onBlur()}),o.addEventListener("input",n),o.addEventListener("blur",()=>{n(),this.onBlur()}),r.appendChild(s),r.appendChild(o),this.createFieldContainer(r)}};function Re(c,t,e,a,r){switch(c.type){case"text":case"email":return new O(c,t,e,a,r).render();case"password":return new re(c,t,e,a,r).render();case"number":return new j(c,t,e,a,r).render();case"textarea":return new W(c,t,e,a,r).render();case"select":return new _(c,t,e,a,r).render();case"checkbox":return new Y(c,t,e,a,r).render();case"radio":return new U(c,t,e,a,r).render();case"switch":return new K(c,t,e,a,r).render();case"date":return new G(c,t,e,a,r).render();case"file":return new J(c,t,e,a,r).render();case"file-drop":return new ae(c,t,e,a,r).render();case"map":return new se(c,t,e,a,r).render();case"rating":return new oe(c,t,e,a,r).render();case"slider":return new ie(c,t,e,a,r).render();case"colorpicker":return new ne(c,t,e,a,r).render();case"quantity":return new Z(c,t,e,a,r).render();case"accordion-select":return new X(c,t,e,a,r).render();case"image-grid-select":return new Q(c,t,e,a,r).render();case"otp":return new ee(c,t,e,a,r).render();default:let s=document.createElement("div");return s.textContent=`Tipo de campo no soportado: ${c.type}`,s}}var Ve=new Map;function Ue(c,t){Ve.set(c,t)}function De(c){for(let[t,e]of Object.entries(c))Ue(t,e)}function ue(c){return Ve.get(c)}var Ke={fields:[{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"password",name:"password",label:"Password",placeholder:"Enter your password",validations:[{type:"required",message:"Password is required"},{type:"minLength",value:6,message:"Password must be at least 6 characters"}]},{type:"checkbox",name:"rememberMe",label:"Remember me",defaultValue:!1}]},Ge={fields:[{type:"text",name:"name",label:"Full Name",placeholder:"Enter your full name",validations:[{type:"required",message:"Name is required"},{type:"minLength",value:2,message:"Name must be at least 2 characters"}]},{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"password",name:"password",label:"Password",placeholder:"Create a password",validations:[{type:"required",message:"Password is required"},{type:"minLength",value:8,message:"Password must be at least 8 characters"}]},{type:"password",name:"confirmPassword",label:"Confirm Password",placeholder:"Confirm your password",validations:[{type:"required",message:"Please confirm your password"},{type:"custom",validator:c=>typeof c=="string"&&c.length>=8,message:"Password must be at least 8 characters"}]}]},Je={fields:[{type:"otp",name:"code",label:"Verification Code",validations:[{type:"required",message:"Verification code is required"}]}]},Ze={fields:[{type:"text",name:"name",label:"Name",placeholder:"Enter your name",validations:[{type:"required",message:"Name is required"}]},{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"text",name:"subject",label:"Subject",placeholder:"Enter the subject",validations:[{type:"required",message:"Subject is required"}]},{type:"textarea",name:"message",label:"Message",placeholder:"Enter your message",rows:5,validations:[{type:"required",message:"Message is required"},{type:"minLength",value:10,message:"Message must be at least 10 characters"}]}]},Xe={fields:[{type:"email",name:"email",label:"Email",placeholder:"Enter your email address",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]}]},Qe={fields:[{type:"password",name:"currentPassword",label:"Current Password",placeholder:"Enter your current password",validations:[{type:"required",message:"Current password is required"}]},{type:"password",name:"newPassword",label:"New Password",placeholder:"Enter your new password",validations:[{type:"required",message:"New password is required"},{type:"minLength",value:8,message:"Password must be at least 8 characters"}]},{type:"password",name:"confirmPassword",label:"Confirm New Password",placeholder:"Confirm your new password",validations:[{type:"required",message:"Please confirm your new password"},{type:"custom",validator:c=>typeof c=="string"&&c.length>=8,message:"Password must be at least 8 characters"}]}]},et={fields:[{type:"text",name:"name",label:"Full Name",placeholder:"Enter your full name",validations:[{type:"required",message:"Name is required"}]},{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"text",name:"phone",label:"Phone",placeholder:"Enter your phone number",mask:{type:"phone"}},{type:"textarea",name:"bio",label:"Bio",placeholder:"Tell us about yourself",rows:4},{type:"file",name:"avatar",label:"Profile Picture",accept:"image/*"}]},tt={fields:[{type:"group",name:"billingAddress",label:"Billing Address",fields:[{type:"text",name:"street",label:"Street Address",placeholder:"Enter street address",validations:[{type:"required",message:"Street address is required"}]},{type:"row",name:"cityState",fields:[{type:"text",name:"city",label:"City",placeholder:"City",validations:[{type:"required",message:"City is required"}]},{type:"text",name:"state",label:"State",placeholder:"State",validations:[{type:"required",message:"State is required"}]}]},{type:"text",name:"zipCode",label:"ZIP Code",placeholder:"ZIP Code",validations:[{type:"required",message:"ZIP code is required"}]}]},{type:"select",name:"paymentMethod",label:"Payment Method",options:[{label:"Credit Card",value:"credit-card"},{label:"Debit Card",value:"debit-card"},{label:"PayPal",value:"paypal"},{label:"Bank Transfer",value:"bank-transfer"}],validations:[{type:"required",message:"Payment method is required"}]},{type:"select",name:"shipping",label:"Shipping Method",options:[{label:"Standard (5-7 days)",value:"standard"},{label:"Express (2-3 days)",value:"express"},{label:"Overnight",value:"overnight"}],validations:[{type:"required",message:"Shipping method is required"}]}]},rt={fields:[{type:"select",name:"rating",label:"Rating",options:[{label:"1 - Poor",value:1},{label:"2 - Fair",value:2},{label:"3 - Good",value:3},{label:"4 - Very Good",value:4},{label:"5 - Excellent",value:5}],validations:[{type:"required",message:"Rating is required"}]},{type:"textarea",name:"comment",label:"Comment",placeholder:"Share your feedback",rows:5,validations:[{type:"required",message:"Comment is required"}]},{type:"email",name:"email",label:"Email (optional)",placeholder:"Enter your email if you want a response"}]},at={fields:[{type:"email",name:"email",label:"Email",placeholder:"Enter your email",validations:[{type:"required",message:"Email is required"},{type:"email",message:"Please enter a valid email"}]},{type:"checkbox",name:"weeklyNewsletter",label:"Weekly Newsletter",defaultValue:!0},{type:"checkbox",name:"productUpdates",label:"Product Updates",defaultValue:!1},{type:"checkbox",name:"promotions",label:"Promotions and Special Offers",defaultValue:!1}]},st={fields:[{type:"date",name:"date",label:"Date",validations:[{type:"required",message:"Date is required"}]},{type:"text",name:"time",label:"Time",placeholder:"HH:MM",mask:{type:"time"},validations:[{type:"required",message:"Time is required"}]},{type:"number",name:"guests",label:"Number of Guests",placeholder:"Enter number of guests",min:1,max:20,validations:[{type:"required",message:"Number of guests is required"},{type:"min",value:1,message:"At least 1 guest is required"}]},{type:"textarea",name:"specialRequests",label:"Special Requests",placeholder:"Any special requests or dietary restrictions?",rows:4}]},ot={fields:[{type:"select",name:"rating",label:"Rating",options:[{label:"1 Star",value:1},{label:"2 Stars",value:2},{label:"3 Stars",value:3},{label:"4 Stars",value:4},{label:"5 Stars",value:5}],validations:[{type:"required",message:"Rating is required"}]},{type:"text",name:"title",label:"Review Title",placeholder:"Give your review a title",validations:[{type:"required",message:"Review title is required"},{type:"minLength",value:5,message:"Title must be at least 5 characters"}]},{type:"textarea",name:"comment",label:"Your Review",placeholder:"Share your experience",rows:6,validations:[{type:"required",message:"Review comment is required"},{type:"minLength",value:20,message:"Review must be at least 20 characters"}]}]},Pe={login:Ke,register:Ge,otp:Je,contact:Ze,"password-reset":Xe,"password-change":Qe,profile:et,checkout:tt,feedback:rt,subscription:at,booking:st,review:ot};function fe(c){return c in Pe?Pe[c]:null}function $e(c,t){let e=fe(c);if(!e)throw new Error(`Template "${c}" not found`);let a=e.fields||[],r=e.steps;if(r&&r.length>0){let s=r[r.length-1];return{...e,steps:[...r.slice(0,-1),{...s,fields:[...s.fields,...t]}]}}return{...e,fields:[...a,...t]}}var it=typeof HTMLElement<"u"?HTMLElement:class{},he=class extends it{constructor(){if(typeof HTMLElement>"u")throw new Error("EasyForm can only be used in a browser environment");super();this.customComponents={};this.isRendering=!1;this.attemptsLock=null;this.lockCountdownInterval=null;this.slotTemplates=null;this.skipPreserveValuesOnNextRender=!1;this.persistenceConfig=null;this.persistenceDebounceTimer=null;this.pendingRestoreValues=null;this.isRestoringValues=!1;this.completeTimeInterval=null;this.timeRemaining=0;this.timerStarted=!1;this.timerExpired=!1;this.dependencyRenderTimeout=null;this.stateManager=new H,this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["schema","template","template-extend","theme","colors","initialData","loading","disabled","max-attempts","block-duration-minutes","attempts-storage-key","submit-button","label-position","show-completed-indicator","form-direction","complete-time"]}get schema(){let e=this.getAttribute("schema");return e?this.getAttribute("template")?(console.warn('EasyForm: Cannot use both "schema" and "template" attributes. "template" will be ignored.'),L(e)):L(e):null}set schema(e){e&&this.getAttribute("template")&&(console.warn('EasyForm: Setting "schema" will remove "template" attribute.'),this.removeAttribute("template"),this.removeAttribute("template-extend")),console.log("EasyForm: Setting schema via JS",e?.fields?.map(a=>({name:a.name,type:a.type,deps:!!a.dependencies}))),e?(this.setAttribute("schema",T(e)),this.handleSchemaChange()):this.removeAttribute("schema")}get template(){let e=this.getAttribute("template");return e?(this.getAttribute("schema")&&console.warn('EasyForm: Cannot use both "template" and "schema" attributes. "schema" will be ignored.'),e):null}set template(e){e&&this.getAttribute("schema")&&(console.warn('EasyForm: Setting "template" will remove "schema" attribute.'),this.removeAttribute("schema")),e?this.setAttribute("template",e):(this.removeAttribute("template"),this.removeAttribute("template-extend"))}get templateExtend(){let e=this.getAttribute("template-extend");return e?L(e):null}set templateExtend(e){e?this.setAttribute("template-extend",T(e)):this.removeAttribute("template-extend")}get maxAttempts(){let e=this.getAttribute("max-attempts");if(!e)return null;let a=parseInt(e,10);return isNaN(a)?null:a}set maxAttempts(e){e!=null&&e>=1?this.setAttribute("max-attempts",String(e)):this.removeAttribute("max-attempts")}get blockDurationMinutes(){let e=this.getAttribute("block-duration-minutes");if(!e)return null;let a=parseInt(e,10);return isNaN(a)?null:a}set blockDurationMinutes(e){e!=null&&e>=1?this.setAttribute("block-duration-minutes",String(e)):this.removeAttribute("block-duration-minutes")}get attemptsStorageKey(){return this.getAttribute("attempts-storage-key")}set attemptsStorageKey(e){e?this.setAttribute("attempts-storage-key",e):this.removeAttribute("attempts-storage-key")}get submitButton(){let e=this.getAttribute("submit-button");if(e)try{return L(e)}catch{return null}return null}set submitButton(e){e&&typeof e=="object"?this.setAttribute("submit-button",T(e)):this.removeAttribute("submit-button")}getSubmitButtonConfig(e){let a=this.submitButton,s={...e?.submitButton,...a};return{visible:s.visible??!0,text:s.text??"Enviar",width:s.width??"auto",align:s.align??"left"}}connectedCallback(){this.setupAttemptsLock(),this.setupStyles(),(this.hasAttribute("schema")||this.schema)&&this.render()}attributeChangedCallback(e,a,r){if(e==="schema"&&r!==a&&(this.getAttribute("template")&&(console.warn('EasyForm: "schema" and "template" cannot be used together. Removing "template".'),this.removeAttribute("template"),this.removeAttribute("template-extend")),this.handleSchemaChange()),e==="template"&&r!==a&&(this.getAttribute("schema")&&(console.warn('EasyForm: "template" and "schema" cannot be used together. Removing "schema".'),this.removeAttribute("schema")),this.handleSchemaChange()),e==="template-extend"&&r!==a&&this.handleSchemaChange(),e==="initialData"&&r!==a&&this.handleSchemaChange(),(e==="theme"||e==="colors")&&r!==a&&this.setupStyles(),e==="loading"&&r!==a){let s=this.shadow.querySelector("form");this.updateLoadingOverlay(s||void 0),s&&s.querySelectorAll("input, textarea, select, button").forEach(i=>{i instanceof HTMLElement&&"disabled"in i&&(i.disabled=this.loading)})}e==="disabled"&&r!==a&&this.render(),(e==="label-position"||e==="form-direction"||e==="show-completed-indicator")&&r!==a&&this.render(),(e==="max-attempts"||e==="block-duration-minutes"||e==="attempts-storage-key")&&r!==a&&(this.setupAttemptsLock(),this.updateLockOverlay()),e==="submit-button"&&r!==a&&this.render(),e==="complete-time"&&r!==a&&(this.resetTimer(),this.completeTime&&(this.timeRemaining=this.completeTime,this.render()))}setupAttemptsLock(){let e=this.maxAttempts;if(e==null||e<1){this.attemptsLock=null;return}this.attemptsLock=new N({maxAttempts:e,blockDurationMinutes:this.blockDurationMinutes??5,storageKey:this.attemptsStorageKey??void 0,onLocked:()=>{this.updateLockOverlay()},onUnlocked:()=>{this.stopLockCountdown(),this.updateLockOverlay(),this.render()}})}handleSchemaChange(){let e=null,a=this.template;if(a?e=this.getSchemaFromTemplate(a):e=this.schema,e){let r=this.initialData;this.stateManager.initializeSchema(e,r||void 0),this.initPersistence(e),this.render()}}getSchemaFromTemplate(e){let a=fe(e);if(!a)return console.error(`EasyForm: Template "${e}" not found`),null;let r=this.templateExtend;return r&&r.length>0?$e(e,r):a}async render(){if(!this.isRendering){this.isRendering=!0;try{let e=null,a=this.template;if(a?e=this.getSchemaFromTemplate(a):e=this.schema,!e){let k=this.shadow.querySelector("form");k&&k.parentNode===this.shadow&&k.remove();return}let r=this.skipPreserveValuesOnNextRender,s=r?{}:this.preserveCurrentValues();this.skipPreserveValuesOnNextRender=!1;let o=this.stateManager.getWizardState();if(s&&Object.keys(s).length>0)for(let[k,E]of Object.entries(s))this.stateManager.setValueWithoutValidation(k,E);let i=this.initialData,n=o!==null,l=e.steps&&e.steps.length>0;if(!r&&(!o||!n||!l||o&&e.steps&&o.totalSteps!==e.steps.length)&&(this.stateManager.initializeSchema(e,i||void 0),n&&l&&o)){let k=this.stateManager.getWizardState();if(k&&o.totalSteps===k.totalSteps){o.currentStep>=0&&o.currentStep<k.totalSteps&&this.stateManager.goToStep(o.currentStep);for(let E of o.completedSteps)E>=0&&E<k.totalSteps&&this.stateManager.completeStep(E)}}let p=this.stateManager.getWizardState(),m=document.createElement("form");m.addEventListener("submit",k=>this.handleSubmit(k)),(this.disabled||this.loading)&&m.classList.add("easy-form-disabled");let u=this.getAttribute("form-direction"),h=e.direction??(u==="vertical"||u==="horizontal"?u:"vertical");m.classList.add(`easy-form-direction-${h}`);let y=this.getAttribute("show-completed-indicator"),f=e.completedIndicator??(y!==null&&y!=="false"),b=typeof f=="object"&&f?.position?f.position:"top";if(p)this.renderWizard(m,e);else{this.renderFields(m,e.fields||[]);let k=this.getSubmitButtonConfig(e);if(k.visible){let E=document.createElement("div");E.className="easy-form-submit-wrapper",E.style.textAlign=k.align;let S=document.createElement("button");S.type="submit",S.textContent=k.text,S.className="easy-form-submit",S.style.width=k.width,(this.disabled||this.loading)&&(S.disabled=!0),E.appendChild(S),m.appendChild(E)}}let v=null;if(f){let{completed:k,total:E}=this.getCompletedRequiredProgress(e),S=document.createElement("div");S.className="easy-form-completed-indicator",S.setAttribute("role","progressbar"),S.setAttribute("aria-valuenow",String(k)),S.setAttribute("aria-valuemin","0"),S.setAttribute("aria-valuemax",String(E)),S.setAttribute("aria-label",`Campos obligatorios completados: ${k} de ${E}`);let F=document.createElement("div");F.className="easy-form-completed-track";let le=document.createElement("div");le.className="easy-form-completed-fill",le.style.width=E>0?`${k/E*100}%`:"0%",F.appendChild(le),S.appendChild(F),v=document.createElement("div"),v.className="easy-form-wrapper",b==="top"?(v.appendChild(S),v.appendChild(m)):(v.appendChild(m),v.appendChild(S))}let g=this.shadow.querySelector("form");if(g&&g.parentNode===this.shadow&&g!==m)try{g.remove()}catch(k){console.warn("Error al eliminar formulario anterior:",k)}let w=this.shadow.querySelector(".easy-form-wrapper");w&&w.remove(),this.shadow.appendChild(v||m),this.completeTime&&!this.timerExpired&&(this.renderTimerDisplay(),this.setupTimerInputListener()),this.loading&&this.updateLoadingOverlay(m),this.updateLockOverlay(m)}finally{this.isRendering=!1,this.pendingRestoreValues&&this.applyPendingRestoreValues()}}}updateLockOverlay(e){let a=this.shadow.querySelector(".easy-form-lock-overlay");if(a&&a.remove(),this.stopLockCountdown(),!this.attemptsLock?.isLocked())return;let r=e||this.shadow.querySelector("form");if(!r)return;let s=document.createElement("div");s.className="easy-form-lock-overlay";let o=document.createElement("div");o.className="easy-form-lock-message",o.setAttribute("role","alert");let i=()=>{let n=this.attemptsLock.getRemainingBlockTimeMs();if(n<=0){this.stopLockCountdown();return}let l=Math.floor(n/6e4),d=Math.floor(n%6e4/1e3),p=l>0?`${l} min ${d} s`:`${d} segundos`;o.textContent=`Demasiados intentos. Intenta de nuevo en ${p}.`};i(),s.appendChild(o),r.appendChild(s),this.lockCountdownInterval=setInterval(i,1e3)}stopLockCountdown(){this.lockCountdownInterval&&(clearInterval(this.lockCountdownInterval),this.lockCountdownInterval=null)}updateLoadingOverlay(e){let a=this.shadow.querySelector(".easy-form-loading-overlay");if(a&&a.remove(),this.loading){let r=e||this.shadow.querySelector("form");if(r){let s=document.createElement("div");s.className="easy-form-loading-overlay";let o=document.createElement("div");o.className="easy-form-loading-spinner",s.appendChild(o),r.appendChild(s)}}}preserveCurrentValues(){let e=null,a=this.template;if(a?e=this.getSchemaFromTemplate(a):e=this.schema,!e)return{};let r=this.shadow.querySelector("form"),s={};if(!r)return s;let o=r.querySelectorAll("input, textarea, select");for(let i of o){let n=i.getAttribute("name");if(!n||!(this.findFieldInSchema(e,n)!==null))continue;let d;if(i instanceof HTMLInputElement)if(i.type==="checkbox")d=i.checked;else if(i.type==="radio")if(i.checked)d=i.value;else continue;else i.type==="number"?d=i.value===""?null:Number(i.value):d=i.value;else i instanceof HTMLTextAreaElement?d=i.value:i instanceof HTMLSelectElement&&(i.multiple?d=Array.from(i.selectedOptions).map(p=>p.value):d=i.value||null);d!==void 0&&(s[n]=d===""?null:d)}return s}initializeSlotTemplates(){if(this.slotTemplates!==null)return;let e=[];for(let a of Array.from(this.children))a instanceof HTMLElement&&e.push(a);if(e.length===0){this.slotTemplates=[];return}this.slotTemplates=e.map(a=>{let r=a.hasAttribute("row")?a.getAttribute("row"):null,s=r!=null&&r!==""?Number(r):NaN,o=Number.isFinite(s)?s:null;return{template:a.cloneNode(!0),row:o}})}getSlotClonesByRow(e){this.initializeSlotTemplates();let a=new Map;if(!this.slotTemplates||this.slotTemplates.length===0)return a;for(let{template:r,row:s}of this.slotTemplates){let o=typeof s=="number"?s:-1;Number.isFinite(o)||(o=-1),(o<0||o>=e)&&(o=-1);let i=r.cloneNode(!0),n=a.get(o)??[];n.push(i),a.set(o,n)}return a}applySlotDisabledState(e){if(!this.disabled&&!this.loading)return;e.classList.add("easy-form-slot-disabled"),e.querySelectorAll("input, textarea, select, button").forEach(r=>{"disabled"in r&&(r.disabled=!0)})}renderFields(e,a){if(a.length===0){let n=this.getSlotClonesByRow(0).get(-1);if(n&&n.length>0)for(let l of n)this.applySlotDisabledState(l),e.appendChild(l);return}let r=a.length,s=this.getSlotClonesByRow(r);for(let i=0;i<a.length;i++){let n=s.get(i);if(n&&n.length>0){for(let p of n)this.applySlotDisabledState(p),e.appendChild(p);s.delete(i)}let l=a[i],d=this.renderField(l);d&&e.appendChild(d)}let o=s.get(-1);if(o&&o.length>0)for(let i of o)this.applySlotDisabledState(i),e.appendChild(i)}renderField(e){let a=this.stateManager.getFieldVisibility(e.name),r=this.stateManager.getFieldEnabled(e.name);if(console.log(`Rendering field: ${e.name} (${e.type}), visible: ${a}, enabled: ${r}, hasDeps: ${!!e.dependencies}`),e.type==="group"){let f=this.renderGroup(e);return a||(f.style.display="none",f.classList.add("easy-form-field-hidden")),r||f.classList.add("easy-form-field-disabled"),f}if(e.type==="row"){let f=this.renderRow(e);return a||(f.style.display="none",f.classList.add("easy-form-field-hidden")),r||f.classList.add("easy-form-field-disabled"),f}if(e.type==="array"){let f=this.renderArray(e);return a||(f.style.display="none",f.classList.add("easy-form-field-hidden")),r||f.classList.add("easy-form-field-disabled"),f}if(e.type==="custom"){let f=this.renderCustom(e);return f&&(a||(f.style.display="none",f.classList.add("easy-form-field-hidden")),r||f.classList.add("easy-form-field-disabled")),f}let s=this.stateManager.getValue(e.name),o=this.stateManager.getErrors(e.name),i=o.length>0?o[0]:void 0,n=this.disabled||this.loading,l=this.getAttribute("label-position"),d=["up","down","left","right","none"],p=e.labelPosition??(l&&d.includes(l)?l:"up"),m={...e,disabled:n||!r||e.disabled,labelPosition:p},u=ue(e.type);if(u){let f=u({field:m,value:s,error:i,onChange:b=>this.handleFieldChange(e.name,b),onBlur:()=>this.handleFieldBlur(e.name)});return f&&!a&&(f.style.display="none",f.classList.add("easy-form-field-hidden")),f}let h=Re(m,s,i,f=>this.handleFieldChange(e.name,f),()=>this.handleFieldBlur(e.name)),y=h.querySelector(".easy-form-field")||h;return y instanceof HTMLElement&&y.setAttribute("data-field-name",e.name),a||(h.style.display="none",h.classList.add("easy-form-field-hidden")),h}renderGroup(e){let a=e,r=a.direction??"vertical",s=a.collapsible===!0,o=a.defaultOpen!==!1,i=document.createElement("div");if(i.className=`easy-form-group easy-form-direction-${r}`,e.name&&i.setAttribute("data-field-name",e.name),s){i.classList.add("easy-form-group-collapsible"),o||i.classList.add("easy-form-group-collapsed");let n=document.createElement("button");n.type="button",n.className="easy-form-group-header",n.setAttribute("aria-expanded",String(o));let l=`easy-form-group-${(e.name||"group").replace(/[^a-z0-9]/gi,"-")}-content`;n.setAttribute("aria-controls",l);let d=document.createElement("span");d.textContent=e.label||"Grupo";let p=document.createElement("span");p.className="easy-form-group-chevron",p.setAttribute("aria-hidden","true"),p.textContent="\u25BC",n.appendChild(d),n.appendChild(p),i.appendChild(n);let m=document.createElement("div");if(m.id=l,m.className="easy-form-group-content","fields"in e&&e.fields)for(let h of e.fields){let y=h.name.startsWith(e.name+".")?h.name:`${e.name}.${h.name}`,f={...h,name:y},b=this.renderField(f);b&&m.appendChild(b)}i.appendChild(m);let u=h=>{h?m.style.maxHeight=m.scrollHeight+"px":m.style.maxHeight="0"};o?requestAnimationFrame(()=>u(!0)):m.style.maxHeight="0",n.addEventListener("click",()=>{i.classList.contains("easy-form-group-collapsed")?(i.classList.remove("easy-form-group-collapsed"),n.setAttribute("aria-expanded","true"),u(!0)):(m.style.maxHeight=m.scrollHeight+"px",requestAnimationFrame(()=>{i.classList.add("easy-form-group-collapsed"),n.setAttribute("aria-expanded","false"),u(!1)}))})}else{if(e.label){let n=document.createElement("h3");n.className="easy-form-group-label",n.textContent=e.label,i.appendChild(n)}if("fields"in e&&e.fields)for(let n of e.fields){let l=n.name.startsWith(e.name+".")?n.name:`${e.name}.${n.name}`,d={...n,name:l},p=this.renderField(d);p&&i.appendChild(p)}}return i}renderRow(e){let a=document.createElement("div");a.className="easy-form-row";let r=e;if(a.style.display="flex",a.style.flexWrap="wrap",a.style.alignItems=r.align||"stretch",r.gap!==void 0){let s=typeof r.gap=="number"?`${r.gap}px`:r.gap;a.style.gap=s}else a.style.gap="1rem";if("fields"in e&&e.fields)for(let s of e.fields){let o=this.renderField(s);if(o){let i=document.createElement("div");i.style.flex="1",i.style.minWidth="0",i.appendChild(o),a.appendChild(i)}}return a}renderArray(e){let a=document.createElement("div");if(a.className="easy-form-array",a.setAttribute("data-field-name",e.name),e.label){let p=document.createElement("label");p.className="easy-form-label",p.textContent=e.label,a.appendChild(p)}let r=this.stateManager.getValue(e.name)||[],s=e,o=s.minItems??0,i=s.maxItems??1/0,n=document.createElement("div");n.className="easy-form-array-items";for(let p=0;p<r.length;p++){let m=document.createElement("div");if(m.className="easy-form-array-item",s.itemSchema?.fields)for(let y of s.itemSchema.fields){let f={...y,name:`${e.name}.${p}.${y.name}`},b=this.renderField(f);b&&m.appendChild(b)}let u=document.createElement("button");u.type="button",u.textContent="Eliminar",u.className="easy-form-array-remove";let h=r.length<=o;this.disabled||this.loading||h?u.disabled=!0:u.addEventListener("click",()=>{let y=[...r];y.splice(p,1),this.handleFieldChange(e.name,y)}),m.appendChild(u),n.appendChild(m)}a.appendChild(n);let l=document.createElement("button");l.type="button",l.textContent="Agregar",l.className="easy-form-array-add";let d=r.length>=i;return this.disabled||this.loading||d?l.disabled=!0:l.addEventListener("click",()=>{let p=this.stateManager.createDefaultArrayItem(e),m=[...r,p];this.handleFieldChange(e.name,m)}),a.appendChild(l),a}renderCustom(e){let a=ue("custom");if(!a){let i=document.createElement("div");return i.textContent=`Componente custom no registrado para: ${e.name}`,i}let r=this.stateManager.getValue(e.name),s=this.stateManager.getErrors(e.name),o=s.length>0?s[0]:void 0;return a({field:e,value:r,error:o,onChange:i=>this.handleFieldChange(e.name,i),onBlur:()=>this.handleFieldBlur(e.name)})}getCompletedRequiredProgress(e){let a=d=>{let p=[];for(let m of d)if(m.type==="array"&&"itemSchema"in m&&m.itemSchema?.fields){let u=this.stateManager.getValue(m.name),h=Array.isArray(u)?u.length:0;for(let y=0;y<h;y++)for(let f of m.itemSchema.fields)p.push({...f,name:`${m.name}.${y}.${f.name}`})}else(m.type==="group"||m.type==="row")&&"fields"in m&&m.fields?p.push(...a(m.fields)):p.push(m);return p},r=e.steps?this.stateManager.getCurrentStepFields()||[]:e.fields||[],i=a(r).filter(d=>d.validations?.some(p=>p.type==="required")).filter(d=>this.stateManager.getFieldVisibility(d.name)),n=i.length;return{completed:i.filter(d=>{if(this.stateManager.getErrors(d.name).length>0)return!1;let m=this.stateManager.getValue(d.name);return!(m==null||typeof m=="string"&&m.trim()===""||Array.isArray(m)&&m.length===0&&d.type==="array")}).length,total:n}}renderWizard(e,a){let r=this.stateManager.getWizardState();if(!r)return;let s=document.createElement("div");s.className="easy-form-wizard";let o=document.createElement("div");o.className="easy-form-wizard-steps";let i=a?.stepStyle;if(i&&i!=="default"&&o.classList.add(`ef-stepper-${i}`),a?.steps)for(let m=0;m<a.steps.length;m++){let u=document.createElement("div");u.className="easy-form-wizard-step",m===r.currentStep&&u.classList.add("active"),r.completedSteps.includes(m)&&u.classList.add("completed"),u.textContent=a.steps[m].title,o.appendChild(u)}s.appendChild(o);let n=document.createElement("div");n.className="easy-form-wizard-fields";let l=this.stateManager.getCurrentStepFields();this.renderFields(n,l),s.appendChild(n);let d=document.createElement("div");if(d.className="easy-form-wizard-nav",r.currentStep>0){let m=document.createElement("button");m.type="button",m.textContent="Anterior",m.className="easy-form-wizard-prev",this.disabled||this.loading?m.disabled=!0:m.addEventListener("click",()=>{this.stateManager.getWizardState()&&this.stateManager.previousStep()&&(this.render(),this.emitStepChange())}),d.appendChild(m)}if(r.currentStep<r.totalSteps-1){let m=document.createElement("button");m.type="button",m.textContent="Siguiente",m.className="easy-form-wizard-next",this.disabled||this.loading?m.disabled=!0:m.addEventListener("click",async()=>{let u=this.stateManager.getWizardState();if(!u)return;let h=this.stateManager.getCurrentStepFields();for(let v of h)this.stateManager.getFieldVisibility(v.name)&&await this.stateManager.validateField(v.name);let y=this.stateManager.getAllErrors(),f={};for(let v of h)y[v.name]&&y[v.name].length>0&&(f[v.name]=y[v.name]);Object.keys(f).length>0?this.emitError(f):(this.stateManager.completeStep(u.currentStep),this.stateManager.nextStep()&&(this.render(),this.emitStepChange()))}),d.appendChild(m)}let p=this.getSubmitButtonConfig(a);if(r.currentStep===r.totalSteps-1&&p.visible){let m=document.createElement("button");m.type="button",m.textContent=p.text,m.className="easy-form-wizard-next",m.style.width=p.width,this.disabled||this.loading?m.disabled=!0:m.addEventListener("click",async()=>{let u=this.stateManager.getCurrentStepFields();for(let b of u)this.stateManager.getFieldVisibility(b.name)&&await this.stateManager.validateField(b.name);let h=this.stateManager.getAllErrors(),y={};for(let b of u)h[b.name]&&h[b.name].length>0&&(y[b.name]=h[b.name]);Object.keys(y).length>0?this.emitError(y):await this.handleSubmit(new Event("submit"))}),d.appendChild(m)}s.appendChild(d),e.appendChild(s)}async handleFieldChange(e,a){await this.stateManager.setValue(e,a),this.scheduleSave();let r=this.schema;if(r){let i=this.findFieldInSchema(r,e);i?.type==="array"&&(this.rerenderArrayField(i)||(this.skipPreserveValuesOnNextRender=!0,requestAnimationFrame(()=>this.render())))}let s=this.stateManager.getDependentFields(e);s.length>0&&(this.dependencyRenderTimeout&&clearTimeout(this.dependencyRenderTimeout),this.dependencyRenderTimeout=setTimeout(()=>{this.renderDependentFields(s),this.emitDependencyChange(e,s)},10));let o=new CustomEvent("change",{detail:{field:e,value:a,values:this.stateManager.getState().values},bubbles:!0,composed:!0});this.dispatchEvent(o)}rerenderArrayField(e){let a=this.shadow.querySelector(`[data-field-name="${e.name}"].easy-form-array`);if(!a?.parentNode)return!1;let r=this.renderArray(e);return a.parentNode.replaceChild(r,a),!0}renderDependentFields(e){let a=this.schema;if(!a)return;let r=this.getAllFieldsWithDependencies(a),s=r.length>0;console.log("renderDependentFields:",{fieldNames:e,hasAnyFieldsWithDeps:s,allFieldsWithDeps:r.map(n=>n.name)});let o=this.shadow.querySelector("form");if(!o)return;let i=new Set;for(let n of e)i.add(n);for(let n of e)this.stateManager.getDependentFields(n).forEach(d=>i.add(d));for(let n of i){let l=o.querySelector(`[data-field-name="${n}"]`);if(l||(l=o.querySelector(`.easy-form-field[name="${n}"]`)),l||(l=o.querySelector(`[data-field-name="${n}"], [data-group-name="${n}"]`)),l){let d=this.findFieldInSchema(a,n);if(!d)continue;let p=l.parentElement;if(p){let m=this.renderField(d);m&&p.replaceChild(m,l)}}}}getAllFieldsWithDependencies(e){let a=[],r=o=>{for(let i of o)i.dependencies&&a.push(i),i.type==="group"&&"fields"in i&&r(i.fields),i.type==="row"&&"fields"in i&&r(i.fields),i.type==="array"&&"itemSchema"in i&&i.itemSchema?.fields&&r(i.itemSchema.fields)},s=e.isWizard?e.steps.flatMap(o=>o.fields):e.fields||[];return r(s),a}emitDependencyChange(e,a){let r=new CustomEvent("dependencyChange",{detail:{changedField:e,affectedFields:a},bubbles:!0,composed:!0});this.dispatchEvent(r)}async handleFieldBlur(e){this.stateManager.setTouched(e),await this.stateManager.validateField(e),this.updateSingleField(e)}updateSingleField(e){let a=this.schema;if(!a||!this.findFieldInSchema(a,e))return;let s=this.stateManager.getErrors(e),o=s.length>0?s[0]:void 0,i=this.shadow.querySelector(`[name="${e}"]`)?.closest(".easy-form-field");if(!i)return;let n=i.querySelector(".easy-form-error");if(o){if(n)n.textContent=o;else{let d=document.createElement("p");d.className="easy-form-error",d.textContent=o,i.appendChild(d)}i.querySelector("input, textarea, select")?.classList.add("easy-form-input-error")}else n?.remove(),i.querySelector("input, textarea, select")?.classList.remove("easy-form-input-error")}findFieldInSchema(e,a){let r=e.fields||[],s=a.indexOf(".");if(s>0){let o=a.slice(0,s),i=a.slice(s+1),n=r.find(l=>l.name===o);if(!n)return null;if((n.type==="group"||n.type==="row")&&"fields"in n&&n.fields){let l=this.findFieldInSchema({fields:n.fields},i);return l?{...l,name:a}:null}return null}for(let o of r){if(o.name===a)return o;if(o.type==="group"&&"fields"in o){let i=this.findFieldInSchema({fields:o.fields},a);if(i)return i}if(o.type==="row"&&"fields"in o){let i=this.findFieldInSchema({fields:o.fields},a);if(i)return i}}return null}async handleSubmit(e){if(e.preventDefault(),this.attemptsLock?.isLocked())return;if(this.timerExpired){this.emitError({form:["El tiempo ha expirado. No puedes enviar el formulario."]});return}let a=await this.stateManager.validateForm(),r=this.stateManager.getState();if(Object.keys(a).length>0){for(let i of Object.keys(a))this.updateSingleField(i);this.emitError(a);return}let s={values:r.values,isValid:!0,errors:{}};this.completeTime&&this.timerStarted&&(s.timeRemaining=this.timeRemaining);let o=new CustomEvent("submit",{detail:s,bubbles:!0,composed:!0});this.dispatchEvent(o),this.clearPersistence()}emitError(e){let a=new CustomEvent("error",{detail:{errors:e},bubbles:!0,composed:!0});this.dispatchEvent(a)}emitStepChange(){let e=this.stateManager.getWizardState();if(!e)return;let a=new CustomEvent("stepChange",{detail:{currentStep:e.currentStep,previousStep:e.currentStep>0?e.currentStep-1:e.currentStep,totalSteps:e.totalSteps},bubbles:!0,composed:!0});this.dispatchEvent(a)}registerComponents(e){this.customComponents={...this.customComponents,...e},De(e)}reset(){this.stateManager.reset(),this.render()}incrementAttempts(){this.attemptsLock?.incrementAttempts(),this.attemptsLock?.isLocked()&&this.updateLockOverlay()}resetAttempts(){this.attemptsLock?.reset(),this.stopLockCountdown(),this.updateLockOverlay(),this.render()}isLocked(){return this.attemptsLock?.isLocked()??!1}getRemainingBlockTimeMs(){return this.attemptsLock?.getRemainingBlockTimeMs()??0}requestSubmit(){let e=this.shadow.querySelector("form");e&&typeof e.requestSubmit=="function"&&e.requestSubmit()}clear(){let e=this.schema,a=this.template,r=null;a?r=this.getSchemaFromTemplate(a):r=e,r&&(this.stateManager.initializeSchema(r,{}),this.render())}getValues(){return this.stateManager.getState().values}getValue(e){return this.stateManager.getValue(e)}async setValue(e,a){await this.stateManager.setValue(e,a),this.render()}async setValues(e){for(let[a,r]of Object.entries(e))await this.stateManager.setValue(a,r);this.render()}async validate(){let e=await this.stateManager.validateForm();if(Object.keys(e).length>0){for(let a of Object.keys(e))this.updateSingleField(a);this.emitError(e)}else this.shadow.querySelectorAll(".easy-form-error").forEach(s=>s.remove()),this.shadow.querySelectorAll(".easy-form-input-error").forEach(s=>s.classList.remove("easy-form-input-error"));return e}async validateField(e){return await this.stateManager.validateField(e),this.updateSingleField(e),this.stateManager.getErrors(e)}getErrors(){return this.stateManager.getAllErrors()}getFieldErrors(e){return this.stateManager.getErrors(e)}isValid(){return this.stateManager.getState().isValid}get theme(){let e=this.getAttribute("theme");return e&&["plano","tradicional","material","rounded-shadow","lines","shadcn","chakra","mantine","glass","bordered","minimal","efc"].includes(e)?e:"plano"}set theme(e){e?this.setAttribute("theme",e):this.removeAttribute("theme")}get colors(){let e=this.getAttribute("colors");return e?L(e):null}set colors(e){e?this.setAttribute("colors",T(e)):this.removeAttribute("colors")}get initialData(){let e=this.getAttribute("initialData");return e?L(e):null}set initialData(e){e?this.setAttribute("initialData",T(e)):this.removeAttribute("initialData")}get loading(){return this.hasAttribute("loading")}set loading(e){e?this.setAttribute("loading",""):this.removeAttribute("loading")}get disabled(){return this.hasAttribute("disabled")}set disabled(e){e?this.setAttribute("disabled",""):this.removeAttribute("disabled")}get completeTime(){let e=this.getAttribute("complete-time");if(!e)return null;let a=parseInt(e,10);return isNaN(a)||a<=0?null:a}set completeTime(e){e!=null&&e>0?this.setAttribute("complete-time",String(e)):this.removeAttribute("complete-time")}setupStyles(){let e=this.shadow.querySelector("style");e&&e.remove();let a=this.theme,r=I(this.colors||void 0),s=D(a,r),o=document.createElement("style");o.textContent=s,this.shadow.firstChild?this.shadow.insertBefore(o,this.shadow.firstChild):this.shadow.appendChild(o)}initPersistence(e){if(!e.persistence||!e.persistence.enabled){this.persistenceConfig=null;return}this.persistenceConfig={enabled:!0,key:e.persistence.key,autoSave:e.persistence.autoSave??!0,debounce:e.persistence.debounce??500,onRestore:e.persistence.onRestore},this.restoreFromStorage()}restoreFromStorage(){if(!(!this.persistenceConfig||!this.persistenceConfig.enabled)&&this.persistenceConfig.key)try{let e=localStorage.getItem(this.persistenceConfig.key);if(e){let a=JSON.parse(e);a&&typeof a=="object"&&(this.pendingRestoreValues=a,this.persistenceConfig.onRestore&&this.persistenceConfig.onRestore(a))}}catch(e){console.warn("EasyForm: Error restoring from localStorage:",e)}}applyPendingRestoreValues(){if(!this.pendingRestoreValues||this.isRestoringValues)return;this.isRestoringValues=!0;let e={...this.pendingRestoreValues};this.pendingRestoreValues=null;for(let[a,r]of Object.entries(e))this.stateManager.setValueWithoutValidation(a,r);this.updateInputsWithValues(e),this.isRestoringValues=!1}updateInputsWithValues(e){for(let a of Object.keys(e)){let r=this.shadow.querySelector(`[name="${a}"]`);r&&(r.value=e[a]??"")}}saveToStorage(){if(!(!this.persistenceConfig||!this.persistenceConfig.enabled)&&this.persistenceConfig.key)try{let e=this.stateManager.getState().values;localStorage.setItem(this.persistenceConfig.key,JSON.stringify(e))}catch(e){console.warn("EasyForm: Error saving to localStorage:",e)}}scheduleSave(){!this.persistenceConfig||!this.persistenceConfig.enabled||this.persistenceConfig.autoSave&&(this.persistenceDebounceTimer&&clearTimeout(this.persistenceDebounceTimer),this.persistenceDebounceTimer=setTimeout(()=>{this.saveToStorage()},this.persistenceConfig.debounce))}clearPersistence(){if(!(!this.persistenceConfig||!this.persistenceConfig.key))try{localStorage.removeItem(this.persistenceConfig.key)}catch(e){console.warn("EasyForm: Error clearing localStorage:",e)}}resetTimer(){this.completeTimeInterval&&(clearInterval(this.completeTimeInterval),this.completeTimeInterval=null),this.timerStarted=!1,this.timerExpired=!1,this.completeTime&&(this.timeRemaining=this.completeTime)}startTimer(){this.timerStarted||this.timerExpired||!this.completeTime||(this.timerStarted=!0,this.timeRemaining=this.completeTime,this.updateTimerDisplay(),this.completeTimeInterval=setInterval(()=>{this.timeRemaining--,this.updateTimerDisplay(),this.timeRemaining<=0&&this.handleTimerExpired()},1e3))}updateTimerDisplay(){let e=this.shadow.querySelector(".easy-form-timer");if(!e)return;let a=Math.floor(this.timeRemaining/60),r=this.timeRemaining%60,s=`${a}:${r.toString().padStart(2,"0")}`;e.textContent=s,this.timeRemaining<=30&&e.classList.add("easy-form-timer-warning"),this.timeRemaining<=10&&e.classList.add("easy-form-timer-danger")}handleTimerExpired(){this.completeTimeInterval&&(clearInterval(this.completeTimeInterval),this.completeTimeInterval=null),this.timerExpired=!0;let e=new CustomEvent("timeout",{detail:{originalTime:this.completeTime||0,expiredAt:new Date},bubbles:!0,composed:!0});this.dispatchEvent(e),this.disableAllFields()}disableAllFields(){let e=this.shadow.querySelector("form");if(!e)return;e.querySelectorAll("input, textarea, select, button").forEach(s=>{(s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement||s instanceof HTMLButtonElement&&s.type!=="submit")&&(s.disabled=!0)}),e.classList.add("easy-form-timer-expired");let r=this.shadow.querySelector(".easy-form-timer");r&&(r.classList.add("easy-form-timer-expired"),r.textContent="Tiempo agotado")}setupTimerInputListener(){if(!this.completeTime||this.timerStarted)return;let e=this.shadow.querySelector("form");if(!e)return;let a=()=>{!this.timerStarted&&!this.timerExpired&&this.startTimer()};e.addEventListener("input",a,{once:!0})}renderTimerDisplay(){let e=this.shadow.querySelector(".easy-form-timer");e&&e.remove();let a=this.shadow.querySelector("form");if(!a)return;let r=document.createElement("div");r.className="easy-form-timer";let s=this.completeTime||0,o=Math.floor(s/60),i=s%60;r.textContent=`${o}:${i.toString().padStart(2,"0")}`,a.insertBefore(r,a.firstChild)}};typeof window<"u"&&typeof customElements<"u"&&!customElements.get("easy-form")&&customElements.define("easy-form",he);export{he as EasyForm};
|
|
2332
2358
|
//# sourceMappingURL=easy-form.js.map
|