zidan-select 2.2.3 → 2.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/README.md +99 -50
- package/dist/file/plugin-file-core.css +31 -5
- package/dist/file/plugin-file-core.min.css +9 -0
- package/dist/file/plugin-file-theme.css +23 -6
- package/dist/file/plugin-file-theme.min.css +9 -0
- package/dist/file/zidan-file.d.ts +32 -0
- package/dist/file/zidan-file.js +196 -23
- package/dist/file/zidan-file.min.js +11 -0
- package/dist/plugin-core.css +106 -15
- package/dist/plugin-core.min.css +10 -0
- package/dist/plugin-theme.css +36 -6
- package/dist/plugin-theme.min.css +13 -0
- package/dist/select/plugin-select-core.css +22 -3
- package/dist/select/plugin-select-core.min.css +9 -0
- package/dist/select/plugin-select-theme.css +28 -4
- package/dist/select/plugin-select-theme.min.css +9 -0
- package/dist/select/zidan-select.d.ts +33 -0
- package/dist/select/zidan-select.js +277 -26
- package/dist/select/zidan-select.min.js +11 -0
- package/dist/zidan-form.js +448 -58
- package/dist/zidan-form.min.js +14 -0
- package/docs/build.md +11 -10
- package/docs/comparison.md +12 -7
- package/docs/html-and-wordpress.md +893 -0
- package/docs/index.html +13 -3
- package/docs/options.md +57 -9
- package/docs/validation.html +8 -0
- package/docs/validation.md +36 -1
- package/package.json +21 -1
- package/plugin-core.css +106 -15
- package/plugin-theme.css +36 -6
- package/zidan-form.d.ts +422 -0
- package/zidan-form.js +448 -58
package/dist/file/zidan-file.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ZidanForm File-only v2.
|
|
2
|
+
* ZidanForm File-only v2.3.0
|
|
3
3
|
* Zero-dependency drag & drop file upload with variants, previews, limits and progress.
|
|
4
4
|
* Pairs with plugin-file-core.css and plugin-file-theme.css.
|
|
5
5
|
*
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
})(typeof window !== 'undefined' ? window : this, function (global) {
|
|
30
30
|
'use strict';
|
|
31
31
|
|
|
32
|
-
var VERSION = '2.
|
|
32
|
+
var VERSION = '2.3.0';
|
|
33
33
|
|
|
34
34
|
// Loading the file twice (classic script + module wrapper, or two bundles)
|
|
35
35
|
// must not replace the classes and orphan the live instances.
|
|
@@ -93,6 +93,24 @@
|
|
|
93
93
|
return Array.isArray(value) ? value.slice() : [value];
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
function isThenable(value) {
|
|
97
|
+
return !!(value && (typeof value === 'object' || typeof value === 'function') && typeof value.then === 'function');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* true when the element renders right-to-left, following the nearest dir attribute */
|
|
101
|
+
function isRtl(element) {
|
|
102
|
+
if (!element) return false;
|
|
103
|
+
var host = element.closest ? element.closest('[dir]') : null;
|
|
104
|
+
var dir = host ? host.getAttribute('dir') : '';
|
|
105
|
+
if (!dir && doc && doc.documentElement) dir = doc.documentElement.getAttribute('dir') || '';
|
|
106
|
+
if (dir) return String(dir).toLowerCase() === 'rtl';
|
|
107
|
+
try {
|
|
108
|
+
return !!(global.getComputedStyle && global.getComputedStyle(element).direction === 'rtl');
|
|
109
|
+
} catch (err) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
96
114
|
function isElement(value) {
|
|
97
115
|
return !!(value && typeof value === 'object' && value.nodeType === 1);
|
|
98
116
|
}
|
|
@@ -288,9 +306,9 @@
|
|
|
288
306
|
}
|
|
289
307
|
|
|
290
308
|
function registerIcon(name, markup) {
|
|
291
|
-
if (!name || typeof markup !== 'string') return ZidanSelect;
|
|
292
|
-
ICON_REGISTRY[String(name)] = markup;
|
|
293
|
-
return ZidanSelect;
|
|
309
|
+
if (typeof ZidanSelect !== 'undefined' && (!name || typeof markup !== 'string')) return ZidanSelect;
|
|
310
|
+
if (name && typeof markup === 'string') ICON_REGISTRY[String(name)] = markup;
|
|
311
|
+
return typeof ZidanSelect !== 'undefined' ? ZidanSelect : ZidanForm;
|
|
294
312
|
}
|
|
295
313
|
|
|
296
314
|
/* ---------------- field options (JS options + data-* attributes) ---------------- */
|
|
@@ -348,6 +366,7 @@
|
|
|
348
366
|
fileType: 'This file type is not allowed.',
|
|
349
367
|
fileSize: 'This file is too large.',
|
|
350
368
|
fileCount: 'Too many files.',
|
|
369
|
+
pending: 'Checking…',
|
|
351
370
|
generic: 'Please check this field.'
|
|
352
371
|
};
|
|
353
372
|
|
|
@@ -375,6 +394,20 @@
|
|
|
375
394
|
return fillTemplate(map[key] || FIELD_MESSAGES[key] || map.generic, vars);
|
|
376
395
|
}
|
|
377
396
|
|
|
397
|
+
var NATIVE_VALIDITY_FLAGS = ['valueMissing', 'typeMismatch', 'patternMismatch', 'rangeUnderflow',
|
|
398
|
+
'rangeOverflow', 'stepMismatch', 'tooShort', 'tooLong', 'badInput', 'fileMissing'];
|
|
399
|
+
|
|
400
|
+
/* customError is the library mirroring its own message onto the input, so re-reading it
|
|
401
|
+
would turn a pending/custom check into a phantom native constraint failure */
|
|
402
|
+
function hasNativeValidityError(input) {
|
|
403
|
+
var v = input && input.validity;
|
|
404
|
+
if (!v) return false;
|
|
405
|
+
for (var i = 0; i < NATIVE_VALIDITY_FLAGS.length; i += 1) {
|
|
406
|
+
if (v[NATIVE_VALIDITY_FLAGS[i]]) return true;
|
|
407
|
+
}
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
|
|
378
411
|
/* first non-empty value of any of `names`, walking up the tree */
|
|
379
412
|
function inheritedAttr(node, names) {
|
|
380
413
|
var current = node;
|
|
@@ -471,6 +504,9 @@
|
|
|
471
504
|
this.validation = null;
|
|
472
505
|
this.errorMessage = null;
|
|
473
506
|
this.errorEl = null;
|
|
507
|
+
this.pending = false;
|
|
508
|
+
this._asyncToken = 0;
|
|
509
|
+
this._asyncController = null;
|
|
474
510
|
this.destroyed = false;
|
|
475
511
|
this._listeners = [];
|
|
476
512
|
this._cleanups = [];
|
|
@@ -511,6 +547,7 @@
|
|
|
511
547
|
root.id = this.id + '-field';
|
|
512
548
|
root.setAttribute('data-zs-kind', kind);
|
|
513
549
|
root.classList.add('zs-field--' + kind);
|
|
550
|
+
if (isRtl(this.el)) root.setAttribute('dir', 'rtl');
|
|
514
551
|
this._applyScope(root);
|
|
515
552
|
this.root = root;
|
|
516
553
|
return root;
|
|
@@ -561,15 +598,116 @@
|
|
|
561
598
|
var targets = this.validationTargets();
|
|
562
599
|
for (var i = 0; i < targets.length; i += 1) {
|
|
563
600
|
var input = targets[i];
|
|
564
|
-
if (input
|
|
601
|
+
if (hasNativeValidityError(input)) return this._messageFor(input);
|
|
565
602
|
}
|
|
566
603
|
return '';
|
|
567
604
|
};
|
|
568
605
|
|
|
569
|
-
|
|
606
|
+
/* subclasses forward this context to async validators so they can abort */
|
|
607
|
+
ZidanFieldBase.prototype._asyncSignal = function () {
|
|
608
|
+
return this._asyncController ? this._asyncController.signal : undefined;
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
ZidanFieldBase.prototype._asyncContext = function () {
|
|
612
|
+
return { signal: this._asyncSignal(), field: this, instance: this };
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
/* text inputs override this to block form submission while pending/invalid */
|
|
616
|
+
ZidanFieldBase.prototype._setCustomValidity = function () {};
|
|
617
|
+
|
|
618
|
+
ZidanFieldBase.prototype._abortAsync = function () {
|
|
619
|
+
this._asyncToken += 1;
|
|
620
|
+
if (this._asyncController) {
|
|
621
|
+
try { this._asyncController.abort(); } catch (err) { /* already settled */ }
|
|
622
|
+
this._asyncController = null;
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
/* returns { pending: promise } for async checks, otherwise { error, custom } */
|
|
627
|
+
ZidanFieldBase.prototype._evaluate = function () {
|
|
628
|
+
this._abortAsync();
|
|
629
|
+
if (typeof AbortController !== 'undefined') this._asyncController = new AbortController();
|
|
570
630
|
var custom = this._customError ? this._customError() : '';
|
|
571
|
-
if (custom) return
|
|
572
|
-
|
|
631
|
+
if (isThenable(custom)) return { pending: custom };
|
|
632
|
+
this._asyncController = null;
|
|
633
|
+
if (custom) {
|
|
634
|
+
return { error: typeof custom === 'string' ? custom : this.opts.messages.generic, custom: true };
|
|
635
|
+
}
|
|
636
|
+
var native = this._nativeError();
|
|
637
|
+
return native ? { error: native, custom: false } : {};
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
ZidanFieldBase.prototype._applyValidity = function (message, show, custom) {
|
|
641
|
+
this._setCustomValidity(message && custom ? message : '');
|
|
642
|
+
if (message) {
|
|
643
|
+
if (show) this.setError(message);
|
|
644
|
+
else this.setValidation('invalid');
|
|
645
|
+
return this;
|
|
646
|
+
}
|
|
647
|
+
if (this.errorMessage) this.setError(null);
|
|
648
|
+
if (this.validation === 'invalid') this.setValidation(null);
|
|
649
|
+
return this;
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
ZidanFieldBase.prototype._setPending = function (on) {
|
|
653
|
+
on = !!on;
|
|
654
|
+
this.pending = on;
|
|
655
|
+
if (this.root) {
|
|
656
|
+
this.root.classList.toggle('zs-field--pending', on);
|
|
657
|
+
if (on) {
|
|
658
|
+
this.root.setAttribute('data-zs-validation', 'pending');
|
|
659
|
+
} else if (this.root.getAttribute('data-zs-validation') === 'pending') {
|
|
660
|
+
this.root.removeAttribute('data-zs-validation');
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
this.validationTargets().forEach(function (input) {
|
|
664
|
+
if (!input || !input.setAttribute) return;
|
|
665
|
+
if (on) input.setAttribute('aria-busy', 'true');
|
|
666
|
+
else input.removeAttribute('aria-busy');
|
|
667
|
+
}, this);
|
|
668
|
+
if (on) {
|
|
669
|
+
if (this.errorMessage) this.setError(null);
|
|
670
|
+
this._setCustomValidity(this.opts.messages.pending || FIELD_MESSAGES.pending);
|
|
671
|
+
} else {
|
|
672
|
+
this._setCustomValidity('');
|
|
673
|
+
}
|
|
674
|
+
return this;
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
ZidanFieldBase.prototype._runAsync = function (promise) {
|
|
678
|
+
var self = this;
|
|
679
|
+
if (self.destroyed) return Promise.resolve(false);
|
|
680
|
+
var token = self._asyncToken;
|
|
681
|
+
self._setPending(true);
|
|
682
|
+
return Promise.resolve(promise).then(function (value) {
|
|
683
|
+
if (self.destroyed || token !== self._asyncToken) return false;
|
|
684
|
+
self._asyncController = null;
|
|
685
|
+
self._setPending(false);
|
|
686
|
+
var message = '';
|
|
687
|
+
if (value === false) message = self.opts.messages.generic;
|
|
688
|
+
else if (typeof value === 'string') message = value;
|
|
689
|
+
else if (value instanceof Error) message = value.message || self.opts.messages.generic;
|
|
690
|
+
self._applyValidity(message, self.touched || self.opts.alwaysValidate || !!message, true);
|
|
691
|
+
if (!message && self.opts.showValidState) self.setValidation('valid');
|
|
692
|
+
self.emit('async-validation', { valid: !message, message: message });
|
|
693
|
+
return !message;
|
|
694
|
+
}, function (err) {
|
|
695
|
+
if (self.destroyed || token !== self._asyncToken || (err && err.name === 'AbortError')) return false;
|
|
696
|
+
self._asyncController = null;
|
|
697
|
+
self._setPending(false);
|
|
698
|
+
var message = (err && (err.message || err.error)) || self.opts.messages.generic;
|
|
699
|
+
if (typeof message !== 'string') message = self.opts.messages.generic;
|
|
700
|
+
self._applyValidity(message, true, true);
|
|
701
|
+
self.emit('async-validation', { valid: false, message: message, error: err });
|
|
702
|
+
return false;
|
|
703
|
+
});
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
/* convenience: resolves with the async result, false when sync-invalid, true when sync-valid */
|
|
707
|
+
ZidanFieldBase.prototype.checkAsync = function () {
|
|
708
|
+
var result = this._evaluate();
|
|
709
|
+
if (result.pending) return this._runAsync(result.pending);
|
|
710
|
+
return Promise.resolve(!result.error);
|
|
573
711
|
};
|
|
574
712
|
|
|
575
713
|
ZidanFieldBase.prototype._syncDescribedBy = function () {
|
|
@@ -637,8 +775,12 @@
|
|
|
637
775
|
this.validationTargets().forEach(function (input) {
|
|
638
776
|
self.on(input, 'invalid', function () {
|
|
639
777
|
self.touched = true;
|
|
640
|
-
var
|
|
641
|
-
if (
|
|
778
|
+
var result = self._evaluate();
|
|
779
|
+
if (result.pending) {
|
|
780
|
+
self._runAsync(result.pending);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
if (result.error) self.setError(result.error);
|
|
642
784
|
else self.setValidation('invalid');
|
|
643
785
|
});
|
|
644
786
|
self.on(input, 'blur', function () {
|
|
@@ -651,8 +793,10 @@
|
|
|
651
793
|
this.on(this.formEl, 'reset', function () {
|
|
652
794
|
global.setTimeout(function () {
|
|
653
795
|
if (self.destroyed) return;
|
|
796
|
+
self._abortAsync();
|
|
654
797
|
self.touched = false;
|
|
655
798
|
self.errorMessage = null;
|
|
799
|
+
self._setPending(false);
|
|
656
800
|
if (self.errorEl) {
|
|
657
801
|
self.errorEl.textContent = '';
|
|
658
802
|
self.errorEl.hidden = true;
|
|
@@ -668,25 +812,27 @@
|
|
|
668
812
|
};
|
|
669
813
|
|
|
670
814
|
ZidanFieldBase.prototype._mirrorValidity = function () {
|
|
671
|
-
var
|
|
672
|
-
if (
|
|
673
|
-
|
|
674
|
-
else this.setValidation('invalid');
|
|
815
|
+
var result = this._evaluate();
|
|
816
|
+
if (result.pending) {
|
|
817
|
+
this._runAsync(result.pending);
|
|
675
818
|
return this;
|
|
676
819
|
}
|
|
677
|
-
if (this.
|
|
678
|
-
|
|
820
|
+
if (this.pending) this._setPending(false);
|
|
821
|
+
this._applyValidity(result.error || '', this.touched || this.opts.alwaysValidate, result.custom);
|
|
679
822
|
return this;
|
|
680
823
|
};
|
|
681
824
|
|
|
825
|
+
/* returns a boolean for sync rules and a Promise<boolean> when an async rule runs */
|
|
682
826
|
ZidanFieldBase.prototype.validate = function () {
|
|
683
827
|
this.touched = true;
|
|
684
|
-
var
|
|
685
|
-
if (
|
|
686
|
-
|
|
828
|
+
var result = this._evaluate();
|
|
829
|
+
if (result.pending) return this._runAsync(result.pending);
|
|
830
|
+
if (this.pending) this._setPending(false);
|
|
831
|
+
if (result.error) {
|
|
832
|
+
this._applyValidity(result.error, true, result.custom);
|
|
687
833
|
return false;
|
|
688
834
|
}
|
|
689
|
-
this.
|
|
835
|
+
this._applyValidity('', true, false);
|
|
690
836
|
if (this.opts.showValidState) this.setValidation('valid');
|
|
691
837
|
return true;
|
|
692
838
|
};
|
|
@@ -716,6 +862,10 @@
|
|
|
716
862
|
return this.validation;
|
|
717
863
|
};
|
|
718
864
|
|
|
865
|
+
ZidanFieldBase.prototype.isPending = function () {
|
|
866
|
+
return this.pending;
|
|
867
|
+
};
|
|
868
|
+
|
|
719
869
|
ZidanFieldBase.prototype.getValue = function () {
|
|
720
870
|
var el = this.el;
|
|
721
871
|
if (!el) return null;
|
|
@@ -770,6 +920,7 @@
|
|
|
770
920
|
ZidanFieldBase.prototype.destroy = function () {
|
|
771
921
|
if (this.destroyed) return this;
|
|
772
922
|
this.destroyed = true;
|
|
923
|
+
this._abortAsync();
|
|
773
924
|
this._listeners.forEach(function (entry) {
|
|
774
925
|
entry[0].removeEventListener(entry[1], entry[2], entry[3]);
|
|
775
926
|
});
|
|
@@ -1110,8 +1261,19 @@
|
|
|
1110
1261
|
};
|
|
1111
1262
|
};
|
|
1112
1263
|
|
|
1264
|
+
ZidanFileUpload.prototype._setCustomValidity = function (message) {
|
|
1265
|
+
if (this.el && this.el.setCustomValidity) this.el.setCustomValidity(message || '');
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1113
1268
|
ZidanFileUpload.prototype._customError = function () {
|
|
1114
|
-
|
|
1269
|
+
if (this.fileError) return this.fileError;
|
|
1270
|
+
if (typeof this.opts.validate === 'function') {
|
|
1271
|
+
var result = this.opts.validate(this.getFiles(), this, this._asyncContext());
|
|
1272
|
+
if (result === false) return this.opts.messages.generic;
|
|
1273
|
+
if (typeof result === 'string' && result) return result;
|
|
1274
|
+
if (isThenable(result)) return result;
|
|
1275
|
+
}
|
|
1276
|
+
return '';
|
|
1115
1277
|
};
|
|
1116
1278
|
|
|
1117
1279
|
ZidanFileUpload.prototype._validate = function () {
|
|
@@ -1148,7 +1310,9 @@
|
|
|
1148
1310
|
}
|
|
1149
1311
|
|
|
1150
1312
|
this.fileError = error;
|
|
1151
|
-
if (input.setCustomValidity)
|
|
1313
|
+
if (input.setCustomValidity) {
|
|
1314
|
+
input.setCustomValidity(this.pending ? (messages.pending || FIELD_MESSAGES.pending) : (error || ''));
|
|
1315
|
+
}
|
|
1152
1316
|
var shown = error || this._nativeError();
|
|
1153
1317
|
if (shown) this.setError(shown);
|
|
1154
1318
|
else if (this.errorMessage) this.setError(null);
|
|
@@ -1375,6 +1539,14 @@
|
|
|
1375
1539
|
var self = this;
|
|
1376
1540
|
if (!this.hasUploader) return this;
|
|
1377
1541
|
if (!this._validate()) return this;
|
|
1542
|
+
var check = this.validate();
|
|
1543
|
+
if (isThenable(check)) {
|
|
1544
|
+
return check.then(function (valid) {
|
|
1545
|
+
if (valid && !self.destroyed) self.getFiles().forEach(function (file) { self.uploadFile(file); });
|
|
1546
|
+
return valid;
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
if (!check) return this;
|
|
1378
1550
|
this.getFiles().forEach(function (file) { self.uploadFile(file); });
|
|
1379
1551
|
return this;
|
|
1380
1552
|
};
|
|
@@ -1758,6 +1930,7 @@
|
|
|
1758
1930
|
ZidanSelect.frameworks = FRAMEWORKS.slice();
|
|
1759
1931
|
ZidanSelect.scrollbars = SCROLLBARS.slice();
|
|
1760
1932
|
ZidanSelect.defaults = DEFAULTS;
|
|
1933
|
+
ZidanSelect.cacheLimit = 50;
|
|
1761
1934
|
ZidanSelect.get = function (target) {
|
|
1762
1935
|
var element = typeof target === 'string' ? doc.querySelector(target) : target;
|
|
1763
1936
|
if (!isElement(element)) return null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* ZidanForm File-only v2.3.0
|
|
3
|
+
* Zero-dependency drag & drop file upload with variants, previews, limits and progress.
|
|
4
|
+
* Pairs with plugin-file-core.css and plugin-file-theme.css.
|
|
5
|
+
*
|
|
6
|
+
* Generated by scripts/build.mjs — edit zidan-form.js instead.
|
|
7
|
+
* https://github.com/akhtar1985/zidan-select
|
|
8
|
+
* MIT License © akhtar1985
|
|
9
|
+
*
|
|
10
|
+
* Classic <script> adds window.ZidanForm plus window.zidanField / initZidanForms.
|
|
11
|
+
*/(function(p,T){"use strict";var l=T(p);typeof window!="undefined"&&(window.ZidanForm=l.ZidanForm,l.ZidanSelect&&(window.ZidanSelect=l.ZidanSelect,window.zidanSelect=l.zidanSelect,window.initZidanSelects=l.initZidanSelects),l.zidanField&&(window.zidanField=l.zidanField),l.initZidanForms&&(window.initZidanForms=l.initZidanForms),l.registerIcon&&(window.registerZidanIcon=l.registerIcon)),typeof module!="undefined"&&module.exports&&(module.exports=l)})(typeof window!="undefined"?window:this,function(p){"use strict";var T="2.3.0";if(p&&p.ZidanForm&&p.ZidanForm.__zidanFormGuard===T)return p.ZidanForm.api;var l=typeof document!="undefined"?document:null,bt=["classic-clean","floating-label","soft-pill","bordered-brutalist","glass-elevated"],j=["auto","none","vanilla","bootstrap","tailwind","bulma","foundation"],K=["default","modern","minimal","dark","glass"],W=["stacked","inline","card","compact","floating","outlined"],Et=["checkbox","radio","radio-group","file","input","textarea"],rt="[data-zidan], [data-zidan-checkbox], [data-zidan-switch], [data-zidan-radio], [data-zidan-radio-group], [data-zidan-file], [data-zidan-input], [data-zidan-textarea], .zidan-field",Q="[data-zidan-select], .zidan-select",St="[data-zidan-form], .zidan-form",zt=["default","thin","fancy","hover","hidden"],Ct="zidan:",at=0;function wt(t){return at+=1,(t||"zs")+"-"+at.toString(36)+Math.random().toString(36).slice(2,6)}function xt(t,e){return!!(t&&t.classList&&t.classList.contains(e))}function nt(t,e){return!t||!e||e.split(/\s+/).forEach(function(i){i&&t.classList.add(i)}),t}function v(t,e,i,r){var a=l.createElement(t);return e&&(a.className=e),i&&Object.keys(i).forEach(function(n){var s=i[n];s==null||s===!1||(n==="text"?a.textContent=String(s):a.setAttribute(n,s===!0?"":String(s)))}),r!=null&&(a.textContent=String(r)),a}function J(t){return t==null||t===""?[]:Array.isArray(t)?t.slice():[t]}function $(t){return!!(t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function")}function Ft(t){if(!t)return!1;var e=t.closest?t.closest("[dir]"):null,i=e?e.getAttribute("dir"):"";if(!i&&l&&l.documentElement&&(i=l.documentElement.getAttribute("dir")||""),i)return String(i).toLowerCase()==="rtl";try{return!!(p.getComputedStyle&&p.getComputedStyle(t).direction==="rtl")}catch{return!1}}function m(t){return!!(t&&typeof t=="object"&&t.nodeType===1)}function Tt(t,e){if(t==null||t==="")return e;var i=String(t).toLowerCase();return!(i==="false"||i==="0"||i==="no"||i==="off")}function I(){for(var t={},e=0;e<arguments.length;e++)(function(i){!i||typeof i!="object"||Object.keys(i).forEach(function(r){i[r]!==void 0&&(t[r]=i[r])})})(arguments[e]);return t}function Mt(t){if(!t||!t.getAttribute)return null;var e=t.getAttribute("data-zidan-options");if(!e)return null;try{var i=JSON.parse(e);return i&&typeof i=="object"&&!Array.isArray(i)?i:null}catch(r){return typeof console!="undefined"&&console.warn&&console.warn("[ZidanForm] ignoring invalid data-zidan-options JSON on",t,r),null}}function Lt(t,e,i){return Math.min(i,Math.max(e,t))}function P(t,e){return String(t).replace(/\{(\w+)\}/g,function(i,r){return e&&e[r]!==void 0&&e[r]!==null?String(e[r]):i})}var st={text:'<path d="M4 7h16M4 12h10M4 17h13"/>',mail:'<rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/>',phone:'<path d="M22 16.9v3a2 2 0 0 1-2.2 2 19.8 19.8 0 0 1-8.6-3.1 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.1 4.2 2 2 0 0 1 4.1 2h3a2 2 0 0 1 2 1.7c.1 1 .4 1.9.7 2.8a2 2 0 0 1-.5 2.1L8.1 9.9a16 16 0 0 0 6 6l1.3-1.2a2 2 0 0 1 2.1-.5c.9.3 1.8.6 2.8.7a2 2 0 0 1 1.7 2Z"/>',user:'<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>',lock:'<rect x="4" y="10" width="16" height="11" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/>',search:'<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/>',calendar:'<rect x="3" y="5" width="18" height="16" rx="2"/><path d="M16 3v4M8 3v4M3 11h18"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',link:'<path d="M10 13a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-1.5 1.5"/><path d="M14 11a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l1.5-1.5"/>',hash:'<path d="M4 9h16M4 15h16M10 3 8 21M16 3l-2 18"/>',palette:'<path d="M12 3a9 9 0 0 0 0 18h1.5a2.5 2.5 0 0 0 0-5H12a2 2 0 0 1 0-4h4a5 5 0 0 0 0-10Z"/><circle cx="8.5" cy="8.5" r="1"/><circle cx="8" cy="14" r="1"/>',sliders:'<path d="M4 7h16M4 17h16"/><circle cx="9" cy="7" r="2.5"/><circle cx="15" cy="17" r="2.5"/>',file:'<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/>',upload:'<path d="M12 16V4"/><path d="m7 9 5-5 5 5"/><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"/>',eye:'<path d="M2 12s3.5-6 10-6 10 6 10 6-3.5 6-10 6-10-6-10-6Z"/><circle cx="12" cy="12" r="3"/>',"eye-off":'<path d="m3 3 18 18"/><path d="M10.6 6.2A9.9 9.9 0 0 1 12 6c6.5 0 10 6 10 6a17 17 0 0 1-3.1 3.6"/><path d="M6.4 6.7C3.5 8.4 2 12 2 12s3.5 6 10 6c1.7 0 3.2-.4 4.5-1"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2"/>',check:'<path d="m4 12.5 5 5L20 6.5"/>',x:'<path d="M6 6l12 12M18 6 6 18"/>',plus:'<path d="M12 5v14M5 12h14"/>',minus:'<path d="M5 12h14"/>',"chevron-down":'<path d="m6 9 6 6 6-6"/>',"chevron-up":'<path d="m6 15 6-6 6 6"/>',"chevron-left":'<path d="m15 6-6 6 6 6"/>',"chevron-right":'<path d="m9 6 6 6-6 6"/>',alert:'<path d="M12 9v4"/><path d="M12 17h.01"/><path d="M10.3 3.9 2.6 17.4A2 2 0 0 0 4.3 20h15.4a2 2 0 0 0 1.7-2.6L13.7 3.9a2 2 0 0 0-3.4 0Z"/>',info:'<circle cx="12" cy="12" r="9"/><path d="M12 11v5"/><path d="M12 8h.01"/>',globe:'<circle cx="12" cy="12" r="9"/><path d="M3 12h18"/><path d="M12 3a15 15 0 0 1 0 18 15 15 0 0 1 0-18Z"/>',"map-pin":'<path d="M20 10c0 6-8 12-8 12S4 16 4 10a8 8 0 1 1 16 0Z"/><circle cx="12" cy="10" r="3"/>',image:'<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="m21 15-5-5L5 21"/>',refresh:'<path d="M20 11a8 8 0 0 0-14.9-3.9L3 10"/><path d="M3 5v5h5"/><path d="M4 13a8 8 0 0 0 14.9 3.9L21 14"/><path d="M21 19v-5h-5"/>',trash:'<path d="M4 7h16"/><path d="M9 7V4h6v3"/><path d="M6 7l1 13h10l1-13"/><path d="M10 11v5M14 11v5"/>'},Z={};Object.keys(st).forEach(function(t){Z[t]=st[t]});var Zt="http://www.w3.org/2000/svg",kt={svg:1,g:1,path:1,circle:1,rect:1,line:1,polyline:1,polygon:1,ellipse:1,title:1,defs:1,clipPath:1,clippath:1,mask:1};function Ut(t){if(typeof t!="string"||!t.trim())return"";var e;try{if(typeof p.DOMParser=="undefined")return"";e=new p.DOMParser().parseFromString(t,"image/svg+xml")}catch{return""}if(!e||!e.documentElement)return"";var i=e.documentElement;if(String(i.nodeName).toLowerCase()!=="svg"||e.getElementsByTagName("parsererror").length)return"";var r=function(a){Array.prototype.slice.call(a.children||[]).forEach(function(n){var s=String(n.nodeName);if(s!==s.toLowerCase()&&(s=s.toLowerCase()),!kt[s]){n.parentNode.removeChild(n);return}Array.prototype.slice.call(n.attributes||[]).forEach(function(o){var u=String(o.name).toLowerCase();u.indexOf("on")===0&&n.removeAttribute(o.name),(u==="href"||u==="xlink:href")&&!/^#/.test(o.value)&&n.removeAttribute(o.name),/url\s*\(\s*['"]?\s*(?:https?:|\/\/)/i.test(o.value)&&n.removeAttribute(o.name)}),r(n)})};return r(i),i.outerHTML}function B(t){var e=t;return/^\s*</.test(e)&&!/^\s*<svg/i.test(e)?e='<svg xmlns="'+Zt+'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">'+e+"</svg>":/^\s*<svg/i.test(e)||(e=""),Ut(e)}function Ot(t,e){var i="",r="";if(typeof t=="string"&&t?(r=t,/^\s*</.test(t)?i=B(t)||B('<path d="M4 12h16"/>'):Z[t]&&(i=B(Z[t])||"")):t&&typeof t=="object"&&t.name&&(r=t.name,i=B(Z[t.name]||"")),!i)return null;var a=l.createElement("span");e&&(a.className=e),a.setAttribute("data-zs-icon",r||"custom");try{a.innerHTML=i}catch{return null}var n=a.firstChild;return n&&(n.setAttribute("focusable","false"),n.setAttribute("aria-hidden","true"),n.setAttribute("width","18"),n.setAttribute("height","18")),a}var Vt={text:"text",email:"mail",password:"lock",number:"hash",tel:"phone",url:"link",search:"search",date:"calendar",time:"clock","datetime-local":"calendar",month:"calendar",week:"calendar",range:"sliders",color:"palette"};function Xt(t){return Vt[t]||""}function ot(t,e){return typeof ZidanSelect!="undefined"&&(!t||typeof e!="string")?ZidanSelect:(t&&typeof e=="string"&&(Z[String(t)]=e),typeof ZidanSelect!="undefined"?ZidanSelect:h)}function w(t,e,i,r,a){if(e&&e[i]!==void 0&&e[i]!==null)return e[i];if(t&&r&&t.getAttribute){var n=t.getAttribute("data-zidan-"+r);if(n!==null&&n!=="")return n}return a}function R(t,e,i,r,a){if(e&&e[i]!==void 0&&e[i]!==null)return!!e[i];if(t&&r&&t.getAttribute){var n=t.getAttribute("data-zidan-"+r);if(n!==null)return Tt(n,a)}return a}function It(t,e,i,r,a){var n=w(t,e,i,r,a);if(n==null||n==="")return a;var s=parseFloat(n);return isFinite(s)?s:a}function Kt(t,e,i,r,a){var n=w(t,e,i,r,null);return n==null||n===""?a:Array.isArray(n)?n.slice():String(n).split(",").map(function(s){return s.trim()}).filter(Boolean)}var M={required:"This field is required.",email:"Enter a valid email address.",url:"Enter a valid URL.",pattern:"The value does not match the expected format.",min:"Value must be at least {min}.",max:"Value must be at most {max}.",step:"Value must be a multiple of {step}.",minlength:"Use at least {minlength} characters.",maxlength:"Use at most {maxlength} characters.",badInput:"Enter a valid value.",phone:"Enter a valid phone number for {country}.",integer:"Enter a whole number.",date:"Enter a valid date.",weekend:"Weekends are not available \u2014 pick a weekday.",dateDisabled:"This date is not available.",fileType:"This file type is not allowed.",fileSize:"This file is too large.",fileCount:"Too many files.",pending:"Checking\u2026",generic:"Please check this field."};function Pt(t,e){if(!t||!t.validity||t.validity.valid)return"";var i=t.validity,r=e||M,a=String(t.type||"").toLowerCase(),n="",s={min:t.getAttribute("min"),max:t.getAttribute("max"),step:t.getAttribute("step")};return i.valueMissing?n="required":i.typeMismatch?n=a==="email"?"email":a==="url"?"url":"generic":i.patternMismatch?n="pattern":i.rangeUnderflow?n="min":i.rangeOverflow?n="max":i.stepMismatch?n="step":i.tooShort?(n="minlength",s.minlength=t.getAttribute("minlength")):i.tooLong?(n="maxlength",s.maxlength=t.getAttribute("maxlength")):(i.badInput||i.customError)&&(n="badInput"),n?P(r[n]||M[n]||r.generic,s):t.validationMessage||r.generic}var lt=["valueMissing","typeMismatch","patternMismatch","rangeUnderflow","rangeOverflow","stepMismatch","tooShort","tooLong","badInput","fileMissing"];function Rt(t){var e=t&&t.validity;if(!e)return!1;for(var i=0;i<lt.length;i+=1)if(e[lt[i]])return!0;return!1}function tt(t,e){for(var i=t;i&&i.nodeType===1;){for(var r=0;r<e.length;r+=1){var a=i.getAttribute(e[r]);if(a)return a}i=i.parentElement}return""}function L(t,e,i){var r=String(t||"").toLowerCase();return e.indexOf(r)===-1?i:r}function Nt(t,e){var i=e||{},r=i.theme||tt(t,["data-zidan-theme","data-zs-theme"]);!r&&l&&(r=l.documentElement.getAttribute("data-zs-theme")||"");var a=i.framework||tt(t,["data-zidan-framework","data-zs-framework"]);!a&&l&&(a=l.documentElement.getAttribute("data-zs-framework")||"");var n=i.layout||tt(t,["data-zidan-layout","data-zs-layout"]);return{theme:L(r,K,"default"),framework:L(a,j,"none"),layout:n?String(n).toLowerCase():""}}function Wt(t,e){var i=null;function r(){var a=arguments;clearTimeout(i),i=setTimeout(function(){i=null,t.apply(null,a)},e)}return r.cancel=function(){clearTimeout(i),i=null},r}var Dt=["valid","invalid"],dt=["default","switch","card","button","minimal"],ut=["ios","material","square","labeled","icon"],ft=["stacked","inline","card","button","tile"],N=["dropzone","button","avatar","gallery","compact"],ct=["default","gradient","stepped","minimal"];function Qt(t,e){var i="";return Array.prototype.slice.call(t.childNodes).forEach(function(r){r===e||r.nodeType!==3||(i+=r.nodeValue)}),i.replace(/\s+/g," ").trim()}function Jt(t,e){return Array.prototype.slice.call(t.childNodes).forEach(function(i){i.nodeType===3&&i.nodeValue.trim()&&e.appendChild(i)}),e}function f(t,e,i){if(!l)throw new Error("ZidanForm requires a DOM environment.");if(!m(t))throw new Error("ZidanForm: target element not found.");this.el=t,this.kind=i,this.opts=e||{},this.opts.messages=Object.assign({},M,this.opts.messages||{}),this.id=t.id||(t.id=wt("zf")),this.root=null,this.touched=!1,this.validation=null,this.errorMessage=null,this.errorEl=null,this.pending=!1,this._asyncToken=0,this._asyncController=null,this.destroyed=!1,this._listeners=[],this._cleanups=[],this.formEl=t.form||(t.closest?t.closest("form"):null);var r=Nt(t,this.opts);this.theme=r.theme,this.framework=r.framework,this.layout=this.opts.layout||r.layout}f.prototype.on=function(t,e,i,r){return!t||!t.addEventListener?this:(t.addEventListener(e,i,r),this._listeners.push([t,e,i,r]),this)},f.prototype.emit=function(t,e){if(!this.root)return this;var i=e||{};i.instance=this,i.kind=this.kind;try{this.root.dispatchEvent(new CustomEvent(Ct+t,{detail:i,bubbles:!0}))}catch{}return this},f.prototype.call=function(t,e){var i=this.opts[t];if(typeof i=="function")try{return i(e)}catch(r){this.emit("error",{error:r,callback:t})}},f.prototype._scope=function(t){var e=v("div","zs-field");return e.id=this.id+"-field",e.setAttribute("data-zs-kind",t),e.classList.add("zs-field--"+t),Ft(this.el)&&e.setAttribute("dir","rtl"),this._applyScope(e),this.root=e,e},f.prototype._applyScope=function(t){return t.setAttribute("data-zs-theme",this.theme),t.setAttribute("data-zs-framework",this.framework),this.layout&&t.setAttribute("data-zs-layout",this.layout),t},f.prototype.setTheme=function(t){return this.theme=L(t,K,this.theme),this.root&&this.root.setAttribute("data-zs-theme",this.theme),this},f.prototype.setFramework=function(t){return this.framework=L(t,j,this.framework),this.root&&this.root.setAttribute("data-zs-framework",this.framework),this},f.prototype.setLayout=function(t){return this.layout=L(t,W,this.layout||"stacked"),this.root&&this.root.setAttribute("data-zs-layout",this.layout),this},f.prototype.validationTargets=function(){return[this.el]},f.prototype._customError=function(){return""},f.prototype._messageFor=function(t){var e=Pt(t,this.opts.messages);return e||(t&&t.validationMessage?t.validationMessage:this.opts.messages.generic||M.generic)},f.prototype._nativeError=function(){for(var t=this.validationTargets(),e=0;e<t.length;e+=1){var i=t[e];if(Rt(i))return this._messageFor(i)}return""},f.prototype._asyncSignal=function(){return this._asyncController?this._asyncController.signal:void 0},f.prototype._asyncContext=function(){return{signal:this._asyncSignal(),field:this,instance:this}},f.prototype._setCustomValidity=function(){},f.prototype._abortAsync=function(){if(this._asyncToken+=1,this._asyncController){try{this._asyncController.abort()}catch{}this._asyncController=null}},f.prototype._evaluate=function(){this._abortAsync(),typeof AbortController!="undefined"&&(this._asyncController=new AbortController);var t=this._customError?this._customError():"";if($(t))return{pending:t};if(this._asyncController=null,t)return{error:typeof t=="string"?t:this.opts.messages.generic,custom:!0};var e=this._nativeError();return e?{error:e,custom:!1}:{}},f.prototype._applyValidity=function(t,e,i){return this._setCustomValidity(t&&i?t:""),t?(e?this.setError(t):this.setValidation("invalid"),this):(this.errorMessage&&this.setError(null),this.validation==="invalid"&&this.setValidation(null),this)},f.prototype._setPending=function(t){return t=!!t,this.pending=t,this.root&&(this.root.classList.toggle("zs-field--pending",t),t?this.root.setAttribute("data-zs-validation","pending"):this.root.getAttribute("data-zs-validation")==="pending"&&this.root.removeAttribute("data-zs-validation")),this.validationTargets().forEach(function(e){!e||!e.setAttribute||(t?e.setAttribute("aria-busy","true"):e.removeAttribute("aria-busy"))},this),t?(this.errorMessage&&this.setError(null),this._setCustomValidity(this.opts.messages.pending||M.pending)):this._setCustomValidity(""),this},f.prototype._runAsync=function(t){var e=this;if(e.destroyed)return Promise.resolve(!1);var i=e._asyncToken;return e._setPending(!0),Promise.resolve(t).then(function(r){if(e.destroyed||i!==e._asyncToken)return!1;e._asyncController=null,e._setPending(!1);var a="";return r===!1?a=e.opts.messages.generic:typeof r=="string"?a=r:r instanceof Error&&(a=r.message||e.opts.messages.generic),e._applyValidity(a,e.touched||e.opts.alwaysValidate||!!a,!0),!a&&e.opts.showValidState&&e.setValidation("valid"),e.emit("async-validation",{valid:!a,message:a}),!a},function(r){if(e.destroyed||i!==e._asyncToken||r&&r.name==="AbortError")return!1;e._asyncController=null,e._setPending(!1);var a=r&&(r.message||r.error)||e.opts.messages.generic;return typeof a!="string"&&(a=e.opts.messages.generic),e._applyValidity(a,!0,!0),e.emit("async-validation",{valid:!1,message:a,error:r}),!1})},f.prototype.checkAsync=function(){var t=this._evaluate();return t.pending?this._runAsync(t.pending):Promise.resolve(!t.error)},f.prototype._syncDescribedBy=function(){if(!(!this.el||!this.el.getAttribute)){var t=this.id+"-error",e=this.root&&this.root.querySelector?this.root.querySelector(".zs-field__hint[id]"):null,i=e?e.id:"",r=this.validationTargets();r.forEach(function(a){if(!(!a||!a.getAttribute)){var n=(a.getAttribute("aria-describedby")||"").split(/\s+/).filter(Boolean),s=n.filter(function(o){return o!==t&&o!==i});i&&s.push(i),this.errorMessage&&s.push(t),s.length?a.setAttribute("aria-describedby",s.join(" ")):a.removeAttribute("aria-describedby")}},this)}},f.prototype._renderError=function(){this.root&&(this.errorEl||(this.errorEl=v("p","zs-field__error",{id:this.id+"-error",role:"status","aria-live":"polite"}),this.root.appendChild(this.errorEl)),this.errorEl.textContent=this.errorMessage||"",this.errorEl.hidden=!this.errorMessage,this._syncDescribedBy())},f.prototype.setError=function(t){this.errorMessage=t||null,this.errorMessage?this.validation="invalid":this.validation==="invalid"&&(this.validation=null);var e=!!this.errorMessage||this.validation==="invalid";return this.root&&(this.root.classList.toggle("zs-field--invalid",e),this.root.classList.toggle("zs-field--valid",this.validation==="valid"&&!this.errorMessage),e||this.validation?this.root.setAttribute("data-zs-validation",e?"invalid":this.validation):this.root.removeAttribute("data-zs-validation")),this._renderError(),this.validationTargets().forEach(function(i){!i||!i.setAttribute||(e?i.setAttribute("aria-invalid","true"):this.validation==="valid"?i.setAttribute("aria-invalid","false"):i.removeAttribute("aria-invalid"))},this),this.emit("validation",{state:e?"invalid":this.validation,message:this.errorMessage}),this.call("onValidation",{state:e?"invalid":this.validation,message:this.errorMessage,instance:this}),this},f.prototype.clearError=function(){return this.setError(null)},f.prototype._bindValidity=function(){var t=this;this.validationTargets().forEach(function(i){t.on(i,"invalid",function(){t.touched=!0;var r=t._evaluate();if(r.pending){t._runAsync(r.pending);return}r.error?t.setError(r.error):t.setValidation("invalid")}),t.on(i,"blur",function(){t.touched=!0,t._mirrorValidity()}),t.on(i,"input",function(){t._mirrorValidity()}),t.on(i,"change",function(){t._mirrorValidity()})}),this.on(this.formEl,"reset",function(){p.setTimeout(function(){t.destroyed||(t._abortAsync(),t.touched=!1,t.errorMessage=null,t._setPending(!1),t.errorEl&&(t.errorEl.textContent="",t.errorEl.hidden=!0),t.setValidation(null),t.update())},0)});var e=this.opts.validation||this.el.getAttribute("data-zidan-validation")||this.el.getAttribute("data-zs-validation");(e==="valid"||e==="invalid")&&this.setValidation(e),this._syncDescribedBy()},f.prototype._mirrorValidity=function(){var t=this._evaluate();return t.pending?(this._runAsync(t.pending),this):(this.pending&&this._setPending(!1),this._applyValidity(t.error||"",this.touched||this.opts.alwaysValidate,t.custom),this)},f.prototype.validate=function(){this.touched=!0;var t=this._evaluate();return t.pending?this._runAsync(t.pending):(this.pending&&this._setPending(!1),t.error?(this._applyValidity(t.error,!0,t.custom),!1):(this._applyValidity("",!0,!1),this.opts.showValidState&&this.setValidation("valid"),!0))},f.prototype.setValidation=function(t){this.validation=Dt.indexOf(t)===-1?null:t;var e=this.validation==="invalid"||!!this.errorMessage;return this.root&&(this.root.classList.toggle("zs-field--invalid",e),this.root.classList.toggle("zs-field--valid",this.validation==="valid"&&!this.errorMessage),e?this.root.setAttribute("data-zs-validation","invalid"):this.validation?this.root.setAttribute("data-zs-validation",this.validation):this.root.removeAttribute("data-zs-validation")),this.validationTargets().forEach(function(i){!i||!i.setAttribute||(e?i.setAttribute("aria-invalid","true"):this.validation==="valid"?i.setAttribute("aria-invalid","false"):i.removeAttribute("aria-invalid"))},this),this.emit("validation",{state:e?"invalid":this.validation,message:this.errorMessage}),this.call("onValidation",{state:e?"invalid":this.validation,message:this.errorMessage,instance:this}),this},f.prototype.getValidation=function(){return this.validation},f.prototype.isPending=function(){return this.pending},f.prototype.getValue=function(){var t=this.el;return t?this.kind==="file"?this.getFiles?this.getFiles():Array.prototype.slice.call(t.files||[]):t.type==="checkbox"?!!t.checked:t.multiple&&t.options?Array.prototype.filter.call(t.options,function(e){return e.selected}).map(function(e){return e.value}):t.value:null},f.prototype.setValue=function(t){var e=this.el;if(!e)return this;if(this.kind==="file"){var i=t==null?[]:Array.isArray(t)?t:[t];return i.length?(this.addFiles&&this.addFiles(i),this):this.clear?this.clear():this}if(e.type==="checkbox")return this.setChecked?this.setChecked(!!t):(e.checked=!!t,e.dispatchEvent(new Event("change",{bubbles:!0})),this.update());if(e.multiple&&e.options){var r=(Array.isArray(t)?t:[t]).map(String);Array.prototype.forEach.call(e.options,function(a){a.selected=r.indexOf(a.value)!==-1})}else e.value=t==null?"":String(t);return e.dispatchEvent(new Event("change",{bubbles:!0})),this.update()},f.prototype.update=function(){return this._sync&&this._sync(),this._mirrorValidity(),this},f.prototype.refresh=function(){return this.update()},f.prototype.destroy=function(){return this.destroyed?this:(this.destroyed=!0,this._abortAsync(),this._listeners.forEach(function(t){t[0].removeEventListener(t[1],t[2],t[3])}),this._listeners.length=0,this._teardown&&this._teardown(),this._cleanups.forEach(function(t){t()}),this._cleanups.length=0,this.emit("destroy",{}),this.root&&this.root.parentNode&&this.root.parentNode.removeChild(this.root),this.el.__zidanField===this&&delete this.el.__zidanField,h._unregister(this),this)};function G(t){return!t&&t!==0?"":t<1024?t+" B":t<1024*1024?(t/1024).toFixed(t<10240?1:0)+" KB":(t/(1024*1024)).toFixed(1)+" MB"}function ht(t){var e=/\.([a-z0-9]+)$/i.exec(String(t||""));return e?"."+e[1].toLowerCase():""}function qt(t,e){return e?String(e).split(",").some(function(i){var r=i.trim().toLowerCase();return r?r.indexOf(".")===0?ht(t.name)===r:r.indexOf("/*")!==-1?String(t.type).toLowerCase().indexOf(r.split("/")[0]+"/")===0:String(t.type).toLowerCase()===r:!1}):!0}function x(t){return[t.name,t.size,t.lastModified||0,t.type||""].join("|")}function Ht(t,e){return t&&typeof t=="string"?t:t&&t.message?t.message:t&&t.status?"Upload failed (HTTP "+t.status+").":e||"Upload failed."}function d(t,e){if(!(this instanceof d))return new d(t,e);if(!/^file$/i.test(t.type))throw new Error('ZidanFileUpload: expected an <input type="file">.');f.call(this,t,e,"file");var i=this,r=t,a=this.opts,n=L(w(r,a,"fileVariant","file-variant",w(r,a,"variant","variant","dropzone")),N,"dropzone"),s=r.parentNode,o=this._scope("file");o.setAttribute("data-zs-file-variant",n),s.insertBefore(o,r);var u=v("label","zs-file-drop zs-file-drop--"+n);u.setAttribute("for",this.id);var _=v("span","zs-file-avatar",{hidden:!0}),E=l.createElement("img");E.alt="",_.appendChild(E);var z=v("span","zs-file-icon",{"aria-hidden":"true"}),c=w(r,a,"uploadIcon","upload-icon",w(r,a,"icon","icon","upload")),D=Ot(c,"zs-file-icon-svg");D&&z.appendChild(D);var X=a.title||r.getAttribute("data-zidan-title")||(n==="avatar"?"Upload an image":n==="gallery"?"Add images":"Choose a file"),S=v("span","zs-file-drop-title",null,X),A=v("span","zs-file-drop-hint",null,a.dropHint||r.getAttribute("data-zidan-drop-hint")||(r.multiple?"or drop files here \u2014 multiple allowed":"or drop it here"));u.appendChild(_),u.appendChild(z),u.appendChild(S),u.appendChild(A),u.appendChild(r),o.appendChild(u);var q=v("ul","zs-file-list");o.appendChild(q);var F=v("div","zs-file-meta-row"),O=v("span","zs-file-status",{role:"status","aria-live":"polite"}),C=v("button","zs-file-clear",{type:"button"});C.textContent=a.clearLabel||"Clear all",C.hidden=!0,F.appendChild(O),F.appendChild(C),o.appendChild(F);var V=a.accept||r.accept;V&&(A.textContent=A.textContent+" \xB7 "+V),this.variant=n,this.drop=u,this.list=q,this.status=O,this.clearBtn=C,this.titleEl=S,this.hintEl=A,this._fallbackTitle=X,this.avatarEl=_,this.avatarImg=E,this.uploadHandler=typeof a.upload=="function"?a.upload:typeof a.uploadHandler=="function"?a.uploadHandler:null,this.uploadUrl=w(r,a,"uploadUrl","upload-url",""),this.uploadField=w(r,a,"uploadField","upload-field","file"),this.withCredentials=R(r,a,"withCredentials","with-credentials",!1),this.uploadHeaders=a.uploadHeaders||a.headers||null,this.simulateUpload=R(r,a,"simulateUpload","simulate-upload",!1),this.simulateDuration=Math.max(120,It(r,a,"simulateDuration","simulate-duration",900)),this.autoUpload=R(r,a,"autoUpload","auto-upload",!0),this.showFileMeta=R(r,a,"showFileMeta","show-file-meta",!0),this.showPreview=R(r,a,"showPreview","preview",!0),this.hasUploader=!!(this.uploadHandler||this.uploadUrl||this.simulateUpload),o.setAttribute("data-zs-upload",this.hasUploader?"true":"false"),this._uploads=Object.create(null),this._active=Object.create(null),this._urls=[],this._renderQueued=!1,this.fileError="",this._restoreInput=function(){var b=o.parentNode||s;b.insertBefore(r,o.parentNode?o:null),r.classList.remove("zs-native-input","zs-file-input")},nt(r,"zs-native-input"),nt(r,"zs-file-input"),this.on(r,"change",function(){var b=i._validate();i._render(),i.emit("change",{files:i.getFiles()}),i.call("onChange",{files:i.getFiles(),instance:i}),b&&i.autoUpload&&i.hasUploader&&i.uploadAll()});var y=0;["dragenter","dragover"].forEach(function(b){i.on(u,b,function(H){H.preventDefault(),b==="dragenter"&&(y+=1),u.classList.add("zs-file-drop--over")})}),i.on(u,"dragleave",function(){y=Math.max(0,y-1),y||u.classList.remove("zs-file-drop--over")}),i.on(u,"drop",function(b){if(b.preventDefault(),y=0,u.classList.remove("zs-file-drop--over"),!(!b.dataTransfer||!b.dataTransfer.files||!b.dataTransfer.files.length)){var H=Array.prototype.slice.call(b.dataTransfer.files);r.multiple||(H=H.slice(0,1)),i.addFiles(H)}}),i.on(C,"click",function(){i.clear()}),this._bindValidity(),this.on(this.formEl,"reset",function(){p.setTimeout(function(){i.destroyed||(i.cancelAll(),i._uploads=Object.create(null),i.fileError="",r.setCustomValidity&&r.setCustomValidity(""),i._render())},0)}),r.__zidanField=this,this._render(),this.emit("init",{}),h._register(this)}d.prototype=Object.create(f.prototype),d.prototype.constructor=d,d.prototype.getFiles=function(){return this.el.files?Array.prototype.slice.call(this.el.files):[]},d.prototype.getUploadState=function(){var t=this;return this.getFiles().map(function(e){var i=t._stateFor(e,!1)||{status:"idle",progress:0,error:"",result:null};return{file:e,name:e.name,size:e.size,status:i.status,progress:i.progress,error:i.error,result:i.result}})},d.prototype._stateFor=function(t,e){var i=x(t),r=this._uploads[i];return!r&&e&&(r=this._uploads[i]={status:"idle",progress:0,error:"",result:null}),r},d.prototype._setFiles=function(t){try{var e=typeof DataTransfer!="undefined"?DataTransfer:p.DataTransfer;if(!e)return!1;var i=new e;return t.forEach(function(r){i.items.add(r)}),this.el.files=i.files,!0}catch{return!1}},d.prototype._applyFiles=function(t,e){if(!this._setFiles(t))return this.emit("error",{error:new Error("This browser cannot assign files programmatically."),action:"setFiles"}),this;if(e)try{this.el.dispatchEvent(new Event("change",{bubbles:!0}))}catch{}else this._validate(),this._render();return this},d.prototype.addFiles=function(t){var e=t&&t.length!==void 0?Array.prototype.slice.call(t):J(t);if(!e.length)return this;var i=this.el.multiple?this.getFiles():[],r=Object.create(null),a=i.concat(e).filter(function(n){var s=x(n);return r[s]?!1:(r[s]=!0,!0)});if(this.el.multiple||(a=a.slice(0,1)),!this._setFiles(a))return this.emit("error",{error:new Error("This browser cannot assign files programmatically."),action:"addFiles"}),this;try{this.el.dispatchEvent(new Event("change",{bubbles:!0}))}catch{}return this},d.prototype.replaceFiles=function(t){return this._applyFiles(t&&t.length!==void 0?Array.prototype.slice.call(t):J(t),!0)},d.prototype.removeFile=function(t){var e=this.getFiles(),i=typeof t=="number"?t:e.indexOf(t);if(i===-1||!e[i])return this;var r=e[i];this.cancelUpload(r),delete this._uploads[x(r)];var a=e.slice();return a.splice(i,1),this._setFiles(a),this._validate(),this._render(),this.emit("change",{files:a}),this.emit("remove",{file:r,index:i}),this.call("onChange",{files:a,instance:this}),this.call("onRemove",{file:r,index:i,instance:this}),this},d.prototype.clear=function(){return this.cancelAll(),this._uploads=Object.create(null),this.fileError="",this.el.value="",this.el.setCustomValidity&&this.el.setCustomValidity(""),this._validate(),this._render(),this.emit("change",{files:[]}),this.emit("clear",{}),this.call("onChange",{files:[],instance:this}),this},d.prototype._limits=function(){var t=this.el,e=this.opts,i=parseInt(e.maxFiles||t.getAttribute("data-zidan-max-files"),10),r=parseInt(e.maxSize||t.getAttribute("data-zidan-max-size"),10);if(!(r>0)){var a=e.maxSizeMB;if((a==null||a==="")&&(a=t.getAttribute("data-zidan-max-size-mb")),a!=null&&a!==""){var n=parseFloat(a);n>0&&(r=Math.round(n*1024*1024))}}return{maxFiles:i>0?i:0,maxSize:r>0?r:0,accept:e.accept||t.accept||""}},d.prototype._setCustomValidity=function(t){this.el&&this.el.setCustomValidity&&this.el.setCustomValidity(t||"")},d.prototype._customError=function(){if(this.fileError)return this.fileError;if(typeof this.opts.validate=="function"){var t=this.opts.validate(this.getFiles(),this,this._asyncContext());if(t===!1)return this.opts.messages.generic;if(typeof t=="string"&&t||$(t))return t}return""},d.prototype._validate=function(){var t=this.el,e=this.opts.messages,i=this._limits(),r=this.getFiles(),a="";if(i.maxFiles&&r.length>i.maxFiles&&(a=P(e.fileCount,{max:i.maxFiles}),r=r.slice(0,i.maxFiles),this._setFiles(r)),!a&&i.maxSize){for(var n=0;n<r.length;n+=1)if(r[n].size>i.maxSize){a=P(e.fileSize,{name:r[n].name,size:G(r[n].size),limit:G(i.maxSize)});break}}if(!a&&i.accept){for(var s=0;s<r.length;s+=1)if(!qt(r[s],i.accept)){a=P(e.fileType,{name:r[s].name,accept:i.accept});break}}this.fileError=a,t.setCustomValidity&&t.setCustomValidity(this.pending?e.pending||M.pending:a||"");var o=a||this._nativeError();return o?this.setError(o):this.errorMessage&&this.setError(null),this.root.classList.toggle("zs-field--filled",r.length>0),this.drop.classList.toggle("zs-file-drop--invalid",!!o),this._renderStatus(),!o},d.prototype._sync=function(){this._render()},d.prototype._queueRender=function(){var t=this;if(!(this._renderQueued||this.destroyed)){this._renderQueued=!0;var e=function(){t._renderQueued=!1,t.destroyed||t._render()};p.requestAnimationFrame?p.requestAnimationFrame(e):p.setTimeout(e,32)}},d.prototype._renderStatus=function(){var t=this.getFiles(),e=this.getUploadState(),i=t.reduce(function(u,_){return u+_.size},0),r=e.filter(function(u){return u.status==="uploading"}),a=e.filter(function(u){return u.status==="error"}),n=e.filter(function(u){return u.status==="done"}),s="";if(this.fileError)s=this.fileError;else if(t.length)if(s=t.length+(t.length===1?" file selected":" files selected")+" \xB7 "+G(i),r.length){var o=Math.round(r.reduce(function(u,_){return u+_.progress},0)/r.length);s+=" \xB7 Uploading "+o+"%"}else a.length?s+=" \xB7 "+a.length+" failed":n.length===t.length&&this.hasUploader&&(s+=" \xB7 Uploaded");this.status.textContent=s,this.status.classList.toggle("zs-file-status--error",!!this.fileError),this.status.classList.toggle("zs-file-status--success",!this.fileError&&t.length>0&&n.length===t.length&&this.hasUploader)},d.prototype._render=function(){var t=this,e=this.getFiles(),i=this.opts;this.list.textContent="",this._revokeLater(this._urls),this._urls=[],this.list.hidden=e.length===0,this.clearBtn.hidden=e.length===0,this.root.classList.toggle("zs-field--filled",e.length>0),this.drop.classList.toggle("zs-file-drop--has-files",e.length>0);var r=this.showPreview?e.filter(function(n){return/^image\//.test(n.type)})[0]:null;if(r){var a=URL.createObjectURL(r);this._urls.push(a),this.avatarImg.src=a,this.avatarEl.hidden=!1,this.drop.classList.add("zs-file-drop--has-preview"),this.titleEl.textContent=i.replaceTitle||"Change image"}else this.avatarImg.removeAttribute("src"),this.avatarEl.hidden=!0,this.drop.classList.remove("zs-file-drop--has-preview"),this.titleEl.textContent=this._fallbackTitle;e.forEach(function(n,s){var o=t._stateFor(n,!1)||{status:"idle",progress:0,error:"",result:null},u=v("li","zs-file-item");u.setAttribute("data-zs-upload-state",o.status);var _=v("span","zs-file-thumb");if(/^image\//.test(n.type)){var E=URL.createObjectURL(n);t._urls.push(E);var z=l.createElement("img");z.src=E,z.alt="",_.appendChild(z)}else _.textContent=(ht(n.name)||"file").replace(".","").slice(0,4).toUpperCase();var c=v("span","zs-file-info"),D=v("span","zs-file-name",null,n.name);if(c.appendChild(D),t.showFileMeta){var X=G(n.size)+(n.type?" \xB7 "+n.type:"");c.appendChild(v("span","zs-file-size",null,X))}if(t.hasUploader){var S=v("span","zs-file-upload-state");if(o.status==="uploading"){S.textContent=P(i.progressTemplate||"Uploading {percent}%",{percent:o.progress});var A=v("span","zs-file-progress");A.setAttribute("role","progressbar"),A.setAttribute("aria-valuemin","0"),A.setAttribute("aria-valuemax","100"),A.setAttribute("aria-valuenow",String(o.progress)),A.setAttribute("aria-label","Upload progress for "+n.name);var q=v("span","zs-file-progress-bar");q.style.width=o.progress+"%",A.appendChild(q),S.appendChild(A)}else o.status==="done"?S.textContent=i.uploadedLabel||"Uploaded":o.status==="error"?S.textContent=(i.failedLabel||"Upload failed")+(o.error?" \u2014 "+o.error:""):o.status==="canceled"&&(S.textContent=i.canceledLabel||"Upload canceled");S.textContent&&c.appendChild(S)}var F=v("span","zs-file-actions");if(o.status==="uploading"){var O=v("button","zs-file-cancel",{type:"button","aria-label":"Cancel upload of "+n.name});O.textContent=i.cancelLabel||"Cancel",t.on(O,"click",function(y){y.preventDefault(),y.stopPropagation(),t.cancelUpload(n)}),F.appendChild(O)}else if(o.status==="error"||o.status==="canceled"){var C=v("button","zs-file-retry",{type:"button","aria-label":"Retry upload of "+n.name});C.textContent=i.retryLabel||"Retry",t.on(C,"click",function(y){y.preventDefault(),y.stopPropagation(),t.retryUpload(n)}),F.appendChild(C)}var V=v("button","zs-file-remove",{type:"button","aria-label":"Remove "+n.name});if(V.textContent="\xD7",t.on(V,"click",function(y){y.preventDefault(),y.stopPropagation(),t.removeFile(n)}),F.appendChild(V),u.appendChild(_),u.appendChild(c),u.appendChild(F),t.list.appendChild(u),typeof i.renderFile=="function")try{i.renderFile(u,{file:n,index:s,state:o,field:t})}catch(y){t.emit("error",{error:y,callback:"renderFile"})}}),this._renderStatus()},d.prototype.setVariant=function(t){var e=L(t,N,this.variant);return e===this.variant?this:(this.variant=e,N.forEach(function(i){this.drop.classList.remove("zs-file-drop--"+i)},this),this.drop.classList.add("zs-file-drop--"+e),this.root.setAttribute("data-zs-file-variant",e),this._render(),this)},d.prototype.setUploader=function(t){return typeof t=="function"?(this.uploadHandler=t,this.uploadUrl=""):(this.uploadHandler=null,this.uploadUrl=t?String(t):""),this.hasUploader=!!(this.uploadHandler||this.uploadUrl||this.simulateUpload),this.root.setAttribute("data-zs-upload",this.hasUploader?"true":"false"),this._render(),this},d.prototype._formData=function(t){var e=new FormData;e.append(this.uploadField,t,t.name);var i=typeof this.opts.uploadData=="function"?this.opts.uploadData(t,this):this.opts.uploadData;return i&&typeof i=="object"&&Object.keys(i).forEach(function(r){var a=i[r];a!=null&&e.append(r,a)}),e},d.prototype.uploadAll=function(){var t=this;if(!this.hasUploader)return this;if(!this._validate())return this;var e=this.validate();return $(e)?e.then(function(i){return i&&!t.destroyed&&t.getFiles().forEach(function(r){t.uploadFile(r)}),i}):e?(this.getFiles().forEach(function(i){t.uploadFile(i)}),this):this},d.prototype.uploadFile=function(t){var e=this,i=x(t),r=this._stateFor(t,!0);if(r.status==="uploading"||r.status==="done")return this;if(r.status="uploading",r.progress=0,r.error="",r.result=null,this._queueRender(),this.emit("upload-start",{file:t,name:t.name,size:t.size}),this.call("onUploadStart",{file:t,name:t.name,size:t.size,instance:this}),this.uploadHandler){var a=typeof AbortController!="undefined"?new AbortController:null;this._active[i]={type:"handler",abort:function(){a&&a.abort()}};var n={file:t,field:this,formData:this._formData(t),signal:a?a.signal:null,onProgress:function(c){e._setProgress(t,c)},complete:function(c){e._finish(t,c)},fail:function(c){e._fail(t,c)}},s;try{s=this.uploadHandler(t,n)}catch(c){return this._fail(t,c),this}return s&&typeof s.then=="function"?s.then(function(c){e._finish(t,c)},function(c){c&&(c.name==="AbortError"||c.aborted)?e._canceledUpload(t):e._fail(t,c)}):s!==void 0&&this._finish(t,s),this}if(this.uploadUrl){var o=new p.XMLHttpRequest;this._active[i]={type:"xhr",abort:function(){try{o.abort()}catch{}}},o.open("POST",this.uploadUrl,!0),this.withCredentials&&(o.withCredentials=!0);var u=typeof this.uploadHeaders=="function"?this.uploadHeaders(t,this):this.uploadHeaders;return u&&typeof u=="object"&&Object.keys(u).forEach(function(c){o.setRequestHeader(c,u[c])}),o.upload.onprogress=function(c){c.lengthComputable&&e._setProgress(t,Math.min(99,Math.round(c.loaded/c.total*100)))},o.onload=function(){if(o.status>=200&&o.status<300){var c=o.responseText;try{c=JSON.parse(c)}catch{}e._finish(t,c)}else e._fail(t,{status:o.status,message:"Upload failed (HTTP "+o.status+")."})},o.onerror=function(){e._fail(t,{message:"Network error while uploading."})},o.onabort=function(){e._canceledUpload(t)},o.send(this._formData(t)),this}if(this.simulateUpload){var _=Date.now(),E=null,z=function(){if(!(!e._uploads[i]||r.status!=="uploading")){var c=Math.min(99,Math.round((Date.now()-_)/e.simulateDuration*100));e._setProgress(t,c),c>=99?(delete e._active[i],e._finish(t,{simulated:!0})):E=p.setTimeout(z,40)}};return this._active[i]={type:"simulation",abort:function(){E&&p.clearTimeout(E)}},E=p.setTimeout(z,40),this}return r.status="idle",this._queueRender(),this},d.prototype._setProgress=function(t,e){var i=this._stateFor(t,!1);if(!(!i||i.status!=="uploading")){var r=Lt(Math.round(Number(e)||0),0,99);r!==i.progress&&(i.progress=r,this._queueRender(),this.emit("upload-progress",{file:t,progress:r,name:t.name}),this.call("onUploadProgress",{file:t,progress:r,name:t.name,instance:this}))}},d.prototype._finish=function(t,e){var i=this._stateFor(t,!1);!i||i.status!=="uploading"||(delete this._active[x(t)],i.status="done",i.progress=100,i.result=e===void 0?null:e,this._queueRender(),this.emit("upload-success",{file:t,name:t.name,result:i.result}),this.call("onUploadSuccess",{file:t,name:t.name,result:i.result,instance:this}),this.call("onUpload",{file:t,name:t.name,result:i.result,instance:this}))},d.prototype._fail=function(t,e){var i=this._stateFor(t,!1);!i||i.status!=="uploading"||(delete this._active[x(t)],i.status="error",i.error=Ht(e,this.opts.messages.upload||"Upload failed."),this._queueRender(),this.emit("upload-error",{file:t,name:t.name,error:e,message:i.error}),this.call("onUploadError",{file:t,name:t.name,error:e,message:i.error,instance:this}))},d.prototype._canceledUpload=function(t){var e=this._stateFor(t,!1);!e||e.status!=="uploading"||(delete this._active[x(t)],e.status="canceled",e.progress=0,e.error="",this._queueRender(),this.emit("upload-cancel",{file:t,name:t.name}),this.call("onUploadCancel",{file:t,name:t.name,instance:this}))},d.prototype.cancelUpload=function(t){var e=x(t),i=this._active[e];if(i){try{i.abort()}catch{}delete this._active[e]}return this._canceledUpload(t),this},d.prototype.cancelAll=function(){var t=this;return Object.keys(this._active).forEach(function(e){try{t._active[e].abort()}catch{}delete t._active[e]}),this},d.prototype.retryUpload=function(t){var e=this._stateFor(t,!1);return e?(e.status="idle",e.progress=0,e.error="",this.uploadFile(t)):this},d.prototype._revokeLater=function(t){!t||!t.length||p.setTimeout(function(){t.forEach(function(e){try{URL.revokeObjectURL(e)}catch{}})},800)},d.prototype._teardown=function(){this.cancelAll(),this._uploads=Object.create(null),this._revokeLater(this._urls),this._urls=[],this._restoreInput&&this._restoreInput()};function k(t){if(!m(t))return null;var e=String(t.getAttribute("data-zidan")||"").toLowerCase();if(Et.indexOf(e)!==-1)return e;if(t.hasAttribute("data-zidan-radio-group"))return"radio-group";if(t.hasAttribute("data-zidan-radio"))return"radio";if(t.hasAttribute("data-zidan-checkbox")||t.hasAttribute("data-zidan-switch"))return"checkbox";if(t.hasAttribute("data-zidan-file"))return"file";if(t.hasAttribute("data-zidan-textarea"))return"textarea";if(t.hasAttribute("data-zidan-input"))return"input";var i=String(t.type||"").toLowerCase();if(i==="checkbox")return"checkbox";if(i==="radio")return"radio";if(i==="file")return"file";if(xt(t,"zidan-field")){if(t.tagName==="FIELDSET")return t.querySelector('input[type="radio"]')?"radio-group":null;if(t.tagName==="TEXTAREA")return"textarea";if(t.tagName!=="INPUT"||i==="radio")return null;if(typeof TEXT_TYPES!="undefined"&&TEXT_TYPES.indexOf(i)!==-1)return"input"}return null}function Y(t,e,i){var r=I(Mt(t),i);if(t.__zidanField&&!r.force)return t.__zidanField;switch(e){case"checkbox":return typeof ZidanCheckbox!="undefined"?new ZidanCheckbox(t,r):null;case"radio":case"radio-group":return typeof ZidanRadioGroup!="undefined"?new ZidanRadioGroup(t,r):null;case"file":return typeof d!="undefined"?new d(t,r):null;case"input":case"textarea":return typeof ZidanTextField!="undefined"?new ZidanTextField(t,r):null;default:return null}}function pt(t,e){var i=[];typeof t=="string"?i=Array.prototype.slice.call(l.querySelectorAll(t)):m(t)?i=[t]:t&&typeof t.length=="number"&&(i=Array.prototype.slice.call(t));var r=[];return i.forEach(function(a){if(!a.__zidanField){var n=k(a)||gt(a);if(n){n==="radio"&&!a.hasAttribute("data-zidan-radio")&&(n="radio-group");var s=Y(a,n,e||{});s&&r.push(s)}}}),r.length===1?r[0]:r}function vt(t,e){var i=[];return t.forEach(function(r){if(!(!m(r)||r.__zidanField)){var a=k(r);if(a){a==="radio"&&(a="radio-group");var n=Y(r,a,e||{});n&&i.push(n)}}}),i}function U(t,e){var i=t||l;if(!i||!i.querySelectorAll)return[];var r=Array.prototype.slice.call(i.querySelectorAll(rt));return m(i)&&i.matches&&i.matches(rt)&&r.unshift(i),vt(r,e)}var h={version:T,__zidanFormGuard:T,themes:K,frameworks:j.slice(),fieldLayouts:W,fields:[],_register:function(t){h.fields.indexOf(t)===-1&&h.fields.push(t)},_unregister:function(t){var e=h.fields.indexOf(t);e!==-1&&h.fields.splice(e,1)},get:function(t){var e=typeof t=="string"?l.querySelector(t):t;return m(e)&&e.__zidanField||null},init:function(t,e){return U(t||l,e||{})},field:pt,refresh:function(t){return U(t||l,{}),h.fields.slice().forEach(function(e){e.update()}),h.fields.slice()},destroyAll:function(){return h.fields.slice().forEach(function(t){t.destroy()}),h.fields=[],typeof ZidanSelect!="undefined"&&ZidanSelect.destroyAll&&ZidanSelect.destroyAll(),h},observe:function(t,e){var i=t||l.body;if(!i||!p.MutationObserver)return null;var r=new p.MutationObserver(function(a){a.forEach(function(n){Array.prototype.slice.call(n.addedNodes).forEach(function(s){m(s)&&(k(s)&&Y(s,k(s)==="radio"?"radio-group":k(s),e||{}),s.querySelectorAll&&U(s,e||{}))})}),h.fields.slice().forEach(function(n){n.el.isConnected||n.destroy()}),typeof ZidanSelect!="undefined"&&ZidanSelect.instances.slice().forEach(function(n){n.el.isConnected||n.destroy()})});return r.observe(i,{childList:!0,subtree:!0}),r}};h.api=null,h.registerIcon=ot,h.icons=Z,typeof PHONE_COUNTRIES!="undefined"&&(h.phoneCountries=PHONE_COUNTRIES,h.phoneFormats=PHONE_FORMATS.slice(),h.formatPhone=formatPhone,h.detectPhoneCountry=detectPhoneCountry),h.messages=M,h.variants={},typeof dt!="undefined"&&(h.variants.checkbox=dt.slice()),typeof ut!="undefined"&&(h.variants.switch=ut.slice()),typeof ft!="undefined"&&(h.variants.radio=ft.slice()),typeof N!="undefined"&&(h.variants.file=N.slice()),typeof ct!="undefined"&&(h.variants.range=ct.slice()),typeof STEPPER_MODES!="undefined"&&(h.stepperModes=STEPPER_MODES.slice()),h.fieldLayouts=W.slice(),typeof ZidanSelect!="undefined"&&(ZidanSelect.version=T,ZidanSelect.__zidanSelectGuard=T,ZidanSelect.layouts=bt.slice(),ZidanSelect.frameworks=j.slice(),ZidanSelect.scrollbars=zt.slice(),ZidanSelect.defaults=DEFAULTS,ZidanSelect.cacheLimit=50,ZidanSelect.get=function(t){var e=typeof t=="string"?l.querySelector(t):t;return m(e)&&e.__zidanSelect||null},ZidanSelect.instances=[],ZidanSelect.destroyAll=function(){ZidanSelect.instances.slice().forEach(function(t){t.destroy()}),ZidanSelect.instances=[]});function jt(t,e){var i=[];typeof t=="string"?i=Array.prototype.slice.call(l.querySelectorAll(t)):t&&typeof t.length=="number"&&!m(t)&&t!==p?i=Array.prototype.slice.call(t):m(t)&&(i=[t]);var r=i.map(function(a){var n=new ZidanSelect(a,e||{});return ZidanSelect.instances.push(n),n});return r.length===1?r[0]:r}function et(t,e){return t.filter(function(i){return m(i)&&!i.__zidanSelect}).map(function(i){return ZidanSelect.instances.push(new ZidanSelect(i,e||{})),i.__zidanSelect})}function mt(t,e){var i=t||l;if(!i||!i.querySelectorAll)return[];var r=Array.prototype.slice.call(i.querySelectorAll(Q));return m(i)&&i.matches&&i.matches(Q)&&r.unshift(i),et(r,e)}function it(t,e){J(t).forEach(function(i){i&&(typeof i=="string"?e(i,null):i.selector&&e(String(i.selector),i.options||null))})}function yt(t,e){it(t,function(i,r){et(Array.prototype.slice.call(l.querySelectorAll(i)),I(e,r))})}function Bt(t,e){it(t,function(i,r){var a=I(e,r);Array.prototype.slice.call(l.querySelectorAll(i)).forEach(function(n){if(!(!m(n)||n.__zidanField)){var s=k(n)||gt(n);s&&(s==="radio"&&(s="radio-group"),Y(n,s,a))}})})}function gt(t){return typeof TEXT_TYPES=="undefined"||!m(t)?null:t.tagName==="TEXTAREA"?"textarea":t.tagName!=="INPUT"?null:TEXT_TYPES.indexOf(String(t.type).toLowerCase())!==-1?"input":null}function Gt(t,e){if(typeof ZidanSelect=="undefined")return[];var i=Q+", select",r=Array.prototype.slice.call(t.querySelectorAll(i));return m(t)&&t.matches&&t.matches(i)&&r.unshift(t),et(r,e)}function _t(t,e,i){m(t)&&(Gt(t,e),typeof d!="undefined"&&vt(Array.prototype.slice.call(t.querySelectorAll('input[type="file"]')),i),(typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof d!="undefined"||typeof ZidanTextField!="undefined")&&U(t,i))}function Yt(t,e,i){Array.prototype.slice.call(l.querySelectorAll(St)).forEach(function(r){_t(r,e,i)}),it(t,function(r,a){Array.prototype.slice.call(l.querySelectorAll(r)).forEach(function(n){_t(n,I(e,a),I(i,a))})})}function At(){if(l){var t=p.ZIDAN_FORM_CONFIG||p.ZIDAN_SELECT_CONFIG||{};if(t.autoInit!==!1&&!(p.ZidanSelect&&p.ZidanSelect.autoInit===!1)&&l.documentElement.getAttribute("data-zidan-auto-init")!=="false"){var e=typeof ZidanSelect!="undefined",i=typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof d!="undefined"||typeof ZidanTextField!="undefined",r=t.options||{},a=t.fieldOptions||t.fields||{};e&&(t.selector?yt(t.selector,r):yt(t.targets||t.selectors,r)),i&&Bt(t.fieldTargets,a),Yt(t.formTargets,r,a),e&&!t.selector&&mt(l,r),i&&U(l,a)}}}l&&(l.readyState==="loading"?l.addEventListener("DOMContentLoaded",At):setTimeout(At,0));var g={ZidanForm:h,registerIcon:ot};return typeof ZidanSelect!="undefined"&&(g.ZidanSelect=ZidanSelect,g.zidanSelect=jt,g.initZidanSelects=mt),(typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof d!="undefined"||typeof ZidanTextField!="undefined")&&(g.zidanField=pt,g.initZidanForms=U),typeof ZidanCheckbox!="undefined"&&(g.ZidanCheckbox=ZidanCheckbox),typeof ZidanRadioGroup!="undefined"&&(g.ZidanRadioGroup=ZidanRadioGroup),typeof d!="undefined"&&(g.ZidanFileUpload=d),typeof ZidanTextField!="undefined"&&(g.ZidanTextField=ZidanTextField),typeof formatPhone=="function"&&(g.formatPhone=formatPhone,g.detectPhoneCountry=detectPhoneCountry),h.api=g,g});
|