zidan-select 2.3.0 → 2.4.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm File-only v2.3.0
2
+ * ZidanForm File-only v2.4.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.3.0';
32
+ var VERSION = '2.4.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.
@@ -426,6 +426,24 @@
426
426
  return list.indexOf(candidate) === -1 ? fallback : candidate;
427
427
  }
428
428
 
429
+ /* rangeTicks: JS array, JSON array, comma list or a tick count */
430
+ function parseRangeTicks(value) {
431
+ if (Array.isArray(value)) return value.slice();
432
+ if (typeof value === 'string') {
433
+ var raw = value.trim();
434
+ if (raw.charAt(0) === '[') {
435
+ try {
436
+ var parsed = JSON.parse(raw);
437
+ if (Array.isArray(parsed)) return parsed;
438
+ } catch (err) { /* fall back to the tick count */ }
439
+ } else if (raw.indexOf(',') !== -1) {
440
+ return raw.split(',').map(function (part) { return Number(part.trim()); })
441
+ .filter(function (number) { return isFinite(number); });
442
+ }
443
+ }
444
+ return value;
445
+ }
446
+
429
447
  /* theme/framework/layout resolution shared by every field and the select */
430
448
  function resolveScope(node, options) {
431
449
  var opts = options || {};
@@ -472,6 +490,8 @@
472
490
  var RADIO_VARIANTS = ['stacked', 'inline', 'card', 'button', 'tile'];
473
491
  var FILE_VARIANTS = ['dropzone', 'button', 'avatar', 'gallery', 'compact'];
474
492
  var RANGE_VARIANTS = ['default', 'gradient', 'stepped', 'minimal'];
493
+ var RANGE_BUBBLE_MODES = ['always', 'active', 'never'];
494
+ var RANGE_BUBBLE_POSITIONS = ['top', 'bottom'];
475
495
 
476
496
  function textWithout(rootNode, skip) {
477
497
  var out = '';
@@ -510,6 +530,7 @@
510
530
  this.destroyed = false;
511
531
  this._listeners = [];
512
532
  this._cleanups = [];
533
+ this._describedByBefore = [];
513
534
  this.formEl = target.form || (target.closest ? target.closest('form') : null);
514
535
  var scope = resolveScope(target, this.opts);
515
536
  this.theme = scope.theme;
@@ -641,11 +662,12 @@
641
662
  this._setCustomValidity(message && custom ? message : '');
642
663
  if (message) {
643
664
  if (show) this.setError(message);
644
- else this.setValidation('invalid');
665
+ else this.setValidation('invalid', true);
645
666
  return this;
646
667
  }
647
668
  if (this.errorMessage) this.setError(null);
648
- if (this.validation === 'invalid') this.setValidation(null);
669
+ /* keep an initial or manually set invalid state until the user interacts */
670
+ if (this.validation === 'invalid' && !this._presetValidation) this.setValidation(null, true);
649
671
  return this;
650
672
  };
651
673
 
@@ -710,6 +732,22 @@
710
732
  return Promise.resolve(!result.error);
711
733
  };
712
734
 
735
+ ZidanFieldBase.prototype._trackDescribedBy = function (input) {
736
+ if (!input || !input.getAttribute) return;
737
+ for (var i = 0; i < this._describedByBefore.length; i += 1) {
738
+ if (this._describedByBefore[i][0] === input) return;
739
+ }
740
+ this._describedByBefore.push([input, input.getAttribute('aria-describedby')]);
741
+ };
742
+
743
+ ZidanFieldBase.prototype._addDescribedBy = function (input, id) {
744
+ if (!input || !input.getAttribute || !id) return;
745
+ this._trackDescribedBy(input);
746
+ var current = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
747
+ if (current.indexOf(id) === -1) current.push(id);
748
+ input.setAttribute('aria-describedby', current.join(' '));
749
+ };
750
+
713
751
  ZidanFieldBase.prototype._syncDescribedBy = function () {
714
752
  if (!this.el || !this.el.getAttribute) return;
715
753
  var errorId = this.id + '-error';
@@ -718,6 +756,7 @@
718
756
  var targets = this.validationTargets();
719
757
  targets.forEach(function (input) {
720
758
  if (!input || !input.getAttribute) return;
759
+ this._trackDescribedBy(input);
721
760
  var current = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
722
761
  var next = current.filter(function (id) { return id !== errorId && id !== hintId; });
723
762
  if (hintId) next.push(hintId);
@@ -785,10 +824,17 @@
785
824
  });
786
825
  self.on(input, 'blur', function () {
787
826
  self.touched = true;
827
+ self._presetValidation = false;
828
+ self._mirrorValidity();
829
+ });
830
+ self.on(input, 'input', function () {
831
+ self._presetValidation = false;
832
+ self._mirrorValidity();
833
+ });
834
+ self.on(input, 'change', function () {
835
+ self._presetValidation = false;
788
836
  self._mirrorValidity();
789
837
  });
790
- self.on(input, 'input', function () { self._mirrorValidity(); });
791
- self.on(input, 'change', function () { self._mirrorValidity(); });
792
838
  });
793
839
  this.on(this.formEl, 'reset', function () {
794
840
  global.setTimeout(function () {
@@ -837,8 +883,10 @@
837
883
  return true;
838
884
  };
839
885
 
840
- ZidanFieldBase.prototype.setValidation = function (state) {
886
+ ZidanFieldBase.prototype.setValidation = function (state, internal) {
841
887
  this.validation = VALIDATION_STATES.indexOf(state) === -1 ? null : state;
888
+ /* public calls pin the state; internal mirrors may clear it again */
889
+ if (!internal) this._presetValidation = this.validation === 'invalid';
842
890
  var invalid = this.validation === 'invalid' || !!this.errorMessage;
843
891
  if (this.root) {
844
892
  this.root.classList.toggle('zs-field--invalid', invalid);
@@ -929,7 +977,16 @@
929
977
  this._cleanups.forEach(function (fn) { fn(); });
930
978
  this._cleanups.length = 0;
931
979
  this.emit('destroy', {});
932
- if (this.root && this.root.parentNode) this.root.parentNode.removeChild(this.root);
980
+ /* radio groups use the author's <fieldset> as their root: removing it would
981
+ delete the original radios too, so only remove roots the field created. */
982
+ if (this.root && this.root !== this.el && this.root.parentNode) this.root.parentNode.removeChild(this.root);
983
+ this._describedByBefore.forEach(function (entry) {
984
+ var input = entry[0];
985
+ if (!input || !input.getAttribute) return;
986
+ if (entry[1] === null || entry[1] === undefined) input.removeAttribute('aria-describedby');
987
+ else input.setAttribute('aria-describedby', entry[1]);
988
+ });
989
+ this._describedByBefore = [];
933
990
  if (this.el.__zidanField === this) delete this.el.__zidanField;
934
991
  ZidanForm._unregister(this);
935
992
  return this;
@@ -1104,6 +1161,22 @@
1104
1161
 
1105
1162
  self.on(clearBtn, 'click', function () { self.clear(); });
1106
1163
 
1164
+ /* Delegated once: the list is rebuilt on every upload progress tick, so
1165
+ per-item listeners would grow without bound. */
1166
+ self.on(list, 'click', function (event) {
1167
+ var button = event.target && event.target.closest ? event.target.closest('button') : null;
1168
+ if (!button || !list.contains(button)) return;
1169
+ var item = button.closest('.zs-file-item');
1170
+ var index = item ? parseInt(item.getAttribute('data-zs-file-index'), 10) : -1;
1171
+ var file = index >= 0 ? self.getFiles()[index] : null;
1172
+ if (!file) return;
1173
+ event.preventDefault();
1174
+ event.stopPropagation();
1175
+ if (button.classList.contains('zs-file-cancel')) self.cancelUpload(file);
1176
+ else if (button.classList.contains('zs-file-retry')) self.retryUpload(file);
1177
+ else if (button.classList.contains('zs-file-remove')) self.removeFile(file);
1178
+ });
1179
+
1107
1180
  this._bindValidity();
1108
1181
  this.on(this.formEl, 'reset', function () {
1109
1182
  global.setTimeout(function () {
@@ -1400,6 +1473,7 @@
1400
1473
  var state = self._stateFor(file, false) || { status: 'idle', progress: 0, error: '', result: null };
1401
1474
  var item = el('li', 'zs-file-item');
1402
1475
  item.setAttribute('data-zs-upload-state', state.status);
1476
+ item.setAttribute('data-zs-file-index', String(index));
1403
1477
 
1404
1478
  var thumb = el('span', 'zs-file-thumb');
1405
1479
  if (/^image\//.test(file.type)) {
@@ -1449,30 +1523,15 @@
1449
1523
  if (state.status === 'uploading') {
1450
1524
  var cancel = el('button', 'zs-file-cancel', { type: 'button', 'aria-label': 'Cancel upload of ' + file.name });
1451
1525
  cancel.textContent = opts.cancelLabel || 'Cancel';
1452
- self.on(cancel, 'click', function (event) {
1453
- event.preventDefault();
1454
- event.stopPropagation();
1455
- self.cancelUpload(file);
1456
- });
1457
1526
  actions.appendChild(cancel);
1458
1527
  } else if (state.status === 'error' || state.status === 'canceled') {
1459
1528
  var retry = el('button', 'zs-file-retry', { type: 'button', 'aria-label': 'Retry upload of ' + file.name });
1460
1529
  retry.textContent = opts.retryLabel || 'Retry';
1461
- self.on(retry, 'click', function (event) {
1462
- event.preventDefault();
1463
- event.stopPropagation();
1464
- self.retryUpload(file);
1465
- });
1466
1530
  actions.appendChild(retry);
1467
1531
  }
1468
1532
 
1469
1533
  var remove = el('button', 'zs-file-remove', { type: 'button', 'aria-label': 'Remove ' + file.name });
1470
1534
  remove.textContent = '\u00d7';
1471
- self.on(remove, 'click', function (event) {
1472
- event.preventDefault();
1473
- event.stopPropagation();
1474
- self.removeFile(file);
1475
- });
1476
1535
  actions.appendChild(remove);
1477
1536
 
1478
1537
  item.appendChild(thumb);
@@ -1810,7 +1869,11 @@
1810
1869
  // (output, counter, clearable, …) work without a data attribute
1811
1870
  var kind = fieldKindFor(node) || inferredTextKind(node);
1812
1871
  if (!kind) return;
1813
- if (kind === 'radio' && !node.hasAttribute('data-zidan-radio')) {
1872
+ if (kind === 'radio' || kind === 'radio-group') {
1873
+ if (/^INPUT$/i.test(node.tagName)) {
1874
+ node = node.closest ? node.closest('fieldset, [data-zidan-radio-group]') : null;
1875
+ if (!node) return;
1876
+ }
1814
1877
  kind = 'radio-group';
1815
1878
  }
1816
1879
  var instance = createField(node, kind, options || {});
@@ -1825,7 +1888,13 @@
1825
1888
  if (!isElement(node) || node.__zidanField) return;
1826
1889
  var kind = fieldKindFor(node);
1827
1890
  if (!kind) return;
1828
- if (kind === 'radio') kind = 'radio-group';
1891
+ if (kind === 'radio' || kind === 'radio-group') {
1892
+ if (/^INPUT$/i.test(node.tagName)) {
1893
+ node = node.closest ? node.closest('fieldset, [data-zidan-radio-group]') : null;
1894
+ if (!node) return;
1895
+ }
1896
+ kind = 'radio-group';
1897
+ }
1829
1898
  var instance = createField(node, kind, options || {});
1830
1899
  if (instance) instances.push(instance);
1831
1900
  });
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ZidanForm File-only v2.3.0
2
+ * ZidanForm File-only v2.4.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
  *
@@ -8,4 +8,4 @@
8
8
  * MIT License © akhtar1985
9
9
  *
10
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});
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.4.0";if(p&&p.ZidanForm&&p.ZidanForm.__zidanFormGuard===T)return p.ZidanForm.api;var l=typeof document!="undefined"?document:null,zt=["classic-clean","floating-label","soft-pill","bordered-brutalist","glass-elevated"],H=["auto","none","vanilla","bootstrap","tailwind","bulma","foundation"],W=["default","modern","minimal","dark","glass"],J=["stacked","inline","card","compact","floating","outlined"],Ct=["checkbox","radio","radio-group","file","input","textarea"],at="[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",wt="[data-zidan-form], .zidan-form",xt=["default","thin","fancy","hover","hidden"],Ft="zidan:",nt=0;function Tt(t){return nt+=1,(t||"zs")+"-"+nt.toString(36)+Math.random().toString(36).slice(2,6)}function Mt(t,e){return!!(t&&t.classList&&t.classList.contains(e))}function st(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 $(t){return t==null||t===""?[]:Array.isArray(t)?t.slice():[t]}function tt(t){return!!(t&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function")}function Lt(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 y(t){return!!(t&&typeof t=="object"&&t.nodeType===1)}function kt(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 Zt(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 Ot(t,e,i){return Math.min(i,Math.max(e,t))}function N(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 ot={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"/>'},O={};Object.keys(ot).forEach(function(t){O[t]=ot[t]});var Ut="http://www.w3.org/2000/svg",Vt={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 It(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()),!Vt[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 j(t){var e=t;return/^\s*</.test(e)&&!/^\s*<svg/i.test(e)?e='<svg xmlns="'+Ut+'" 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=""),It(e)}function Nt(t,e){var i="",r="";if(typeof t=="string"&&t?(r=t,/^\s*</.test(t)?i=j(t)||j('<path d="M4 12h16"/>'):O[t]&&(i=j(O[t])||"")):t&&typeof t=="object"&&t.name&&(r=t.name,i=j(O[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 Pt={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 Jt(t){return Pt[t]||""}function lt(t,e){return typeof ZidanSelect!="undefined"&&(!t||typeof e!="string")?ZidanSelect:(t&&typeof e=="string"&&(O[String(t)]=e),typeof ZidanSelect!="undefined"?ZidanSelect:h)}function C(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 P(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 kt(n,a)}return a}function Rt(t,e,i,r,a){var n=C(t,e,i,r,a);if(n==null||n==="")return a;var s=parseFloat(n);return isFinite(s)?s:a}function Qt(t,e,i,r,a){var n=C(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 Dt(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?N(r[n]||M[n]||r.generic,s):t.validationMessage||r.generic}var dt=["valueMissing","typeMismatch","patternMismatch","rangeUnderflow","rangeOverflow","stepMismatch","tooShort","tooLong","badInput","fileMissing"];function Bt(t){var e=t&&t.validity;if(!e)return!1;for(var i=0;i<dt.length;i+=1)if(e[dt[i]])return!0;return!1}function et(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 $t(t){if(Array.isArray(t))return t.slice();if(typeof t=="string"){var e=t.trim();if(e.charAt(0)==="[")try{var i=JSON.parse(e);if(Array.isArray(i))return i}catch{}else if(e.indexOf(",")!==-1)return e.split(",").map(function(r){return Number(r.trim())}).filter(function(r){return isFinite(r)})}return t}function qt(t,e){var i=e||{},r=i.theme||et(t,["data-zidan-theme","data-zs-theme"]);!r&&l&&(r=l.documentElement.getAttribute("data-zs-theme")||"");var a=i.framework||et(t,["data-zidan-framework","data-zs-framework"]);!a&&l&&(a=l.documentElement.getAttribute("data-zs-framework")||"");var n=i.layout||et(t,["data-zidan-layout","data-zs-layout"]);return{theme:L(r,W,"default"),framework:L(a,H,"none"),layout:n?String(n).toLowerCase():""}}function te(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 Ht=["valid","invalid"],ut=["default","switch","card","button","minimal"],ft=["ios","material","square","labeled","icon"],ct=["stacked","inline","card","button","tile"],R=["dropzone","button","avatar","gallery","compact"],ht=["default","gradient","stepped","minimal"],ee=["always","active","never"],ie=["top","bottom"];function re(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 ae(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(!y(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=Tt("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._describedByBefore=[],this.formEl=t.form||(t.closest?t.closest("form"):null);var r=qt(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(Ft+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),Lt(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,W,this.theme),this.root&&this.root.setAttribute("data-zs-theme",this.theme),this},f.prototype.setFramework=function(t){return this.framework=L(t,H,this.framework),this.root&&this.root.setAttribute("data-zs-framework",this.framework),this},f.prototype.setLayout=function(t){return this.layout=L(t,J,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=Dt(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(Bt(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(tt(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",!0),this):(this.errorMessage&&this.setError(null),this.validation==="invalid"&&!this._presetValidation&&this.setValidation(null,!0),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._trackDescribedBy=function(t){if(!(!t||!t.getAttribute)){for(var e=0;e<this._describedByBefore.length;e+=1)if(this._describedByBefore[e][0]===t)return;this._describedByBefore.push([t,t.getAttribute("aria-describedby")])}},f.prototype._addDescribedBy=function(t,e){if(!(!t||!t.getAttribute||!e)){this._trackDescribedBy(t);var i=(t.getAttribute("aria-describedby")||"").split(/\s+/).filter(Boolean);i.indexOf(e)===-1&&i.push(e),t.setAttribute("aria-describedby",i.join(" "))}},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)){this._trackDescribedBy(a);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._presetValidation=!1,t._mirrorValidity()}),t.on(i,"input",function(){t._presetValidation=!1,t._mirrorValidity()}),t.on(i,"change",function(){t._presetValidation=!1,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,e){this.validation=Ht.indexOf(t)===-1?null:t,e||(this._presetValidation=this.validation==="invalid");var i=this.validation==="invalid"||!!this.errorMessage;return this.root&&(this.root.classList.toggle("zs-field--invalid",i),this.root.classList.toggle("zs-field--valid",this.validation==="valid"&&!this.errorMessage),i?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(r){!r||!r.setAttribute||(i?r.setAttribute("aria-invalid","true"):this.validation==="valid"?r.setAttribute("aria-invalid","false"):r.removeAttribute("aria-invalid"))},this),this.emit("validation",{state:i?"invalid":this.validation,message:this.errorMessage}),this.call("onValidation",{state:i?"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!==this.el&&this.root.parentNode&&this.root.parentNode.removeChild(this.root),this._describedByBefore.forEach(function(t){var e=t[0];!e||!e.getAttribute||(t[1]===null||t[1]===void 0?e.removeAttribute("aria-describedby"):e.setAttribute("aria-describedby",t[1]))}),this._describedByBefore=[],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 pt(t){var e=/\.([a-z0-9]+)$/i.exec(String(t||""));return e?"."+e[1].toLowerCase():""}function jt(t,e){return e?String(e).split(",").some(function(i){var r=i.trim().toLowerCase();return r?r.indexOf(".")===0?pt(t.name)===r:r.indexOf("/*")!==-1?String(t.type).toLowerCase().indexOf(r.split("/")[0]+"/")===0:String(t.type).toLowerCase()===r:!1}):!0}function w(t){return[t.name,t.size,t.lastModified||0,t.type||""].join("|")}function Gt(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(C(r,a,"fileVariant","file-variant",C(r,a,"variant","variant","dropzone")),R,"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=C(r,a,"uploadIcon","upload-icon",C(r,a,"icon","icon","upload")),D=Nt(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),b=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(b),u.appendChild(r),o.appendChild(u);var k=v("ul","zs-file-list");o.appendChild(k);var x=v("div","zs-file-meta-row"),B=v("span","zs-file-status",{role:"status","aria-live":"polite"}),F=v("button","zs-file-clear",{type:"button"});F.textContent=a.clearLabel||"Clear all",F.hidden=!0,x.appendChild(B),x.appendChild(F),o.appendChild(x);var q=a.accept||r.accept;q&&(b.textContent=b.textContent+" \xB7 "+q),this.variant=n,this.drop=u,this.list=k,this.status=B,this.clearBtn=F,this.titleEl=S,this.hintEl=b,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=C(r,a,"uploadUrl","upload-url",""),this.uploadField=C(r,a,"uploadField","upload-field","file"),this.withCredentials=P(r,a,"withCredentials","with-credentials",!1),this.uploadHeaders=a.uploadHeaders||a.headers||null,this.simulateUpload=P(r,a,"simulateUpload","simulate-upload",!1),this.simulateDuration=Math.max(120,Rt(r,a,"simulateDuration","simulate-duration",900)),this.autoUpload=P(r,a,"autoUpload","auto-upload",!0),this.showFileMeta=P(r,a,"showFileMeta","show-file-meta",!0),this.showPreview=P(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 m=o.parentNode||s;m.insertBefore(r,o.parentNode?o:null),r.classList.remove("zs-native-input","zs-file-input")},st(r,"zs-native-input"),st(r,"zs-file-input"),this.on(r,"change",function(){var m=i._validate();i._render(),i.emit("change",{files:i.getFiles()}),i.call("onChange",{files:i.getFiles(),instance:i}),m&&i.autoUpload&&i.hasUploader&&i.uploadAll()});var Z=0;["dragenter","dragover"].forEach(function(m){i.on(u,m,function(A){A.preventDefault(),m==="dragenter"&&(Z+=1),u.classList.add("zs-file-drop--over")})}),i.on(u,"dragleave",function(){Z=Math.max(0,Z-1),Z||u.classList.remove("zs-file-drop--over")}),i.on(u,"drop",function(m){if(m.preventDefault(),Z=0,u.classList.remove("zs-file-drop--over"),!(!m.dataTransfer||!m.dataTransfer.files||!m.dataTransfer.files.length)){var A=Array.prototype.slice.call(m.dataTransfer.files);r.multiple||(A=A.slice(0,1)),i.addFiles(A)}}),i.on(F,"click",function(){i.clear()}),i.on(k,"click",function(m){var A=m.target&&m.target.closest?m.target.closest("button"):null;if(!(!A||!k.contains(A))){var Et=A.closest(".zs-file-item"),St=Et?parseInt(Et.getAttribute("data-zs-file-index"),10):-1,K=St>=0?i.getFiles()[St]:null;K&&(m.preventDefault(),m.stopPropagation(),A.classList.contains("zs-file-cancel")?i.cancelUpload(K):A.classList.contains("zs-file-retry")?i.retryUpload(K):A.classList.contains("zs-file-remove")&&i.removeFile(K))}}),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=w(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):$(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=w(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):$(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[w(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||tt(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=N(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=N(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(!jt(r[s],i.accept)){a=N(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),u.setAttribute("data-zs-file-index",String(s));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=(pt(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=N(i.progressTemplate||"Uploading {percent}%",{percent:o.progress});var b=v("span","zs-file-progress");b.setAttribute("role","progressbar"),b.setAttribute("aria-valuemin","0"),b.setAttribute("aria-valuemax","100"),b.setAttribute("aria-valuenow",String(o.progress)),b.setAttribute("aria-label","Upload progress for "+n.name);var k=v("span","zs-file-progress-bar");k.style.width=o.progress+"%",b.appendChild(k),S.appendChild(b)}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 x=v("span","zs-file-actions");if(o.status==="uploading"){var B=v("button","zs-file-cancel",{type:"button","aria-label":"Cancel upload of "+n.name});B.textContent=i.cancelLabel||"Cancel",x.appendChild(B)}else if(o.status==="error"||o.status==="canceled"){var F=v("button","zs-file-retry",{type:"button","aria-label":"Retry upload of "+n.name});F.textContent=i.retryLabel||"Retry",x.appendChild(F)}var q=v("button","zs-file-remove",{type:"button","aria-label":"Remove "+n.name});if(q.textContent="\xD7",x.appendChild(q),u.appendChild(_),u.appendChild(c),u.appendChild(x),t.list.appendChild(u),typeof i.renderFile=="function")try{i.renderFile(u,{file:n,index:s,state:o,field:t})}catch(Z){t.emit("error",{error:Z,callback:"renderFile"})}}),this._renderStatus()},d.prototype.setVariant=function(t){var e=L(t,R,this.variant);return e===this.variant?this:(this.variant=e,R.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 tt(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=w(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=Ot(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[w(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[w(t)],i.status="error",i.error=Gt(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[w(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=w(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 U(t){if(!y(t))return null;var e=String(t.getAttribute("data-zidan")||"").toLowerCase();if(Ct.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(Mt(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(Zt(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 vt(t,e){var i=[];typeof t=="string"?i=Array.prototype.slice.call(l.querySelectorAll(t)):y(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=U(a)||_t(a);if(n){if(n==="radio"||n==="radio-group"){if(/^INPUT$/i.test(a.tagName)&&(a=a.closest?a.closest("fieldset, [data-zidan-radio-group]"):null,!a))return;n="radio-group"}var s=Y(a,n,e||{});s&&r.push(s)}}}),r.length===1?r[0]:r}function mt(t,e){var i=[];return t.forEach(function(r){if(!(!y(r)||r.__zidanField)){var a=U(r);if(a){if(a==="radio"||a==="radio-group"){if(/^INPUT$/i.test(r.tagName)&&(r=r.closest?r.closest("fieldset, [data-zidan-radio-group]"):null,!r))return;a="radio-group"}var n=Y(r,a,e||{});n&&i.push(n)}}}),i}function V(t,e){var i=t||l;if(!i||!i.querySelectorAll)return[];var r=Array.prototype.slice.call(i.querySelectorAll(at));return y(i)&&i.matches&&i.matches(at)&&r.unshift(i),mt(r,e)}var h={version:T,__zidanFormGuard:T,themes:W,frameworks:H.slice(),fieldLayouts:J,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 y(e)&&e.__zidanField||null},init:function(t,e){return V(t||l,e||{})},field:vt,refresh:function(t){return V(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){y(s)&&(U(s)&&Y(s,U(s)==="radio"?"radio-group":U(s),e||{}),s.querySelectorAll&&V(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=lt,h.icons=O,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 ut!="undefined"&&(h.variants.checkbox=ut.slice()),typeof ft!="undefined"&&(h.variants.switch=ft.slice()),typeof ct!="undefined"&&(h.variants.radio=ct.slice()),typeof R!="undefined"&&(h.variants.file=R.slice()),typeof ht!="undefined"&&(h.variants.range=ht.slice()),typeof STEPPER_MODES!="undefined"&&(h.stepperModes=STEPPER_MODES.slice()),h.fieldLayouts=J.slice(),typeof ZidanSelect!="undefined"&&(ZidanSelect.version=T,ZidanSelect.__zidanSelectGuard=T,ZidanSelect.layouts=zt.slice(),ZidanSelect.frameworks=H.slice(),ZidanSelect.scrollbars=xt.slice(),ZidanSelect.defaults=DEFAULTS,ZidanSelect.cacheLimit=50,ZidanSelect.get=function(t){var e=typeof t=="string"?l.querySelector(t):t;return y(e)&&e.__zidanSelect||null},ZidanSelect.instances=[],ZidanSelect.destroyAll=function(){ZidanSelect.instances.slice().forEach(function(t){t.destroy()}),ZidanSelect.instances=[]});function Yt(t,e){var i=[];typeof t=="string"?i=Array.prototype.slice.call(l.querySelectorAll(t)):t&&typeof t.length=="number"&&!y(t)&&t!==p?i=Array.prototype.slice.call(t):y(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 it(t,e){return t.filter(function(i){return y(i)&&!i.__zidanSelect}).map(function(i){return ZidanSelect.instances.push(new ZidanSelect(i,e||{})),i.__zidanSelect})}function yt(t,e){var i=t||l;if(!i||!i.querySelectorAll)return[];var r=Array.prototype.slice.call(i.querySelectorAll(Q));return y(i)&&i.matches&&i.matches(Q)&&r.unshift(i),it(r,e)}function rt(t,e){$(t).forEach(function(i){i&&(typeof i=="string"?e(i,null):i.selector&&e(String(i.selector),i.options||null))})}function gt(t,e){rt(t,function(i,r){it(Array.prototype.slice.call(l.querySelectorAll(i)),I(e,r))})}function Xt(t,e){rt(t,function(i,r){var a=I(e,r);Array.prototype.slice.call(l.querySelectorAll(i)).forEach(function(n){if(!(!y(n)||n.__zidanField)){var s=U(n)||_t(n);s&&(s==="radio"&&(s="radio-group"),Y(n,s,a))}})})}function _t(t){return typeof TEXT_TYPES=="undefined"||!y(t)?null:t.tagName==="TEXTAREA"?"textarea":t.tagName!=="INPUT"?null:TEXT_TYPES.indexOf(String(t.type).toLowerCase())!==-1?"input":null}function Kt(t,e){if(typeof ZidanSelect=="undefined")return[];var i=Q+", select",r=Array.prototype.slice.call(t.querySelectorAll(i));return y(t)&&t.matches&&t.matches(i)&&r.unshift(t),it(r,e)}function bt(t,e,i){y(t)&&(Kt(t,e),typeof d!="undefined"&&mt(Array.prototype.slice.call(t.querySelectorAll('input[type="file"]')),i),(typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof d!="undefined"||typeof ZidanTextField!="undefined")&&V(t,i))}function Wt(t,e,i){Array.prototype.slice.call(l.querySelectorAll(wt)).forEach(function(r){bt(r,e,i)}),rt(t,function(r,a){Array.prototype.slice.call(l.querySelectorAll(r)).forEach(function(n){bt(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?gt(t.selector,r):gt(t.targets||t.selectors,r)),i&&Xt(t.fieldTargets,a),Wt(t.formTargets,r,a),e&&!t.selector&&yt(l,r),i&&V(l,a)}}}l&&(l.readyState==="loading"?l.addEventListener("DOMContentLoaded",At):setTimeout(At,0));var g={ZidanForm:h,registerIcon:lt};return typeof ZidanSelect!="undefined"&&(g.ZidanSelect=ZidanSelect,g.zidanSelect=Yt,g.initZidanSelects=yt),(typeof ZidanCheckbox!="undefined"||typeof ZidanRadioGroup!="undefined"||typeof d!="undefined"||typeof ZidanTextField!="undefined")&&(g.zidanField=vt,g.initZidanForms=V),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});