voc-lib-js 1.0.64 → 1.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.d.mts CHANGED
@@ -24,6 +24,7 @@ type BaseField = {
24
24
  multiple?: boolean;
25
25
  description?: string;
26
26
  icon?: string;
27
+ option_label?: string;
27
28
  };
28
29
  type RowField = {
29
30
  label?: string;
package/dist/main.d.ts CHANGED
@@ -24,6 +24,7 @@ type BaseField = {
24
24
  multiple?: boolean;
25
25
  description?: string;
26
26
  icon?: string;
27
+ option_label?: string;
27
28
  };
28
29
  type RowField = {
29
30
  label?: string;
@@ -1,2 +1,2 @@
1
- "use strict";var VocLibJs=(()=>{var G=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(r,x)=>{for(var f in x)G(r,f,{get:x[f],enumerable:!0})},se=(r,x,f,k)=>{if(x&&typeof x=="object"||typeof x=="function")for(let h of ae(x))!ne.call(r,h)&&h!==f&&G(r,h,{get:()=>x[h],enumerable:!(k=te(x,h))||k.enumerable});return r};var oe=r=>se(G({},"__esModule",{value:!0}),r);var ue={};re(ue,{FormsLib:()=>de,default:()=>me});function U(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-avatar-wrapper",k&&h.classList.add("d-flex","align-items-center","gap-3");let v=document.createElement("img");v.className="voc-form-avatar-preview",v.alt=r.label||"avatar",k&&(v.classList.add("img-thumbnail","rounded-circle"),v.style.width=v.style.height="64px",v.style.objectFit="cover");let u=f!=null?String(f):r.default!==void 0&&r.default!==null?String(r.default):"";u?v.src=u:(v.src="",v.style.display="none");let i=document.createElement("input");i.type="file",i.accept=r.accept||"image/*",i.className="voc-form-avatar-input",k&&i.classList.add("form-control"),(r.key||r.name)&&(i.name=r.name||r.key,r.key&&(i.id=`voc-form-${r.key}`));let d=document.createElement("input");if(d.type="hidden",(r.key||r.name)&&(d.name=(r.name||r.key)+"_url"),d.value=u||"",i.addEventListener("change",p=>{let g=p.target;if(g.files&&g.files.length>0){let T=g.files[0],L=new FileReader;L.onload=()=>{v.src=String(L.result),v.style.display="",d.value=""},L.readAsDataURL(T)}}),k){let p=document.createElement("div");p.style.flex="1",p.appendChild(i),p.appendChild(d),h.appendChild(v),h.appendChild(p)}else h.appendChild(v),h.appendChild(i),h.appendChild(d);return h}function J(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");if(h.className="voc-form-audio-select",!r.options||r.options.length===0)return h;let v=r.name||r.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,u;return Array.isArray(f)?u=f[0]:f!==void 0?u=f:r.default!==void 0&&(u=r.default),r.options.forEach((i,d)=>{let p=document.createElement("div");p.className="voc-form-audio-item",k&&p.classList.add("form-check");let g=document.createElement("input");g.type="radio",g.name=v,g.value=i.value,g.className="voc-form-audio-radio",r.key&&(g.id=`voc-form-${r.key}-${d}`),r.required&&d===0&&(g.required=!0),g.style.position="absolute",g.style.width="1px",g.style.height="1px",g.style.margin="0",g.style.padding="0",g.style.clip="rect(0 0 0 0)",g.style.clipPath="inset(50%)",g.style.overflow="hidden",g.style.border="0",u!==void 0&&(Array.isArray(u)?g.checked=u.includes(i.value):g.checked=String(u)===String(i.value));let T=()=>{g.checked?p.classList.add("selected"):p.classList.remove("selected")};g.addEventListener("change",()=>{h.querySelectorAll(".voc-form-audio-item").forEach(n=>n.classList.remove("selected")),T()}),g.checked&&p.classList.add("selected");let L=document.createElement("label");L.className="voc-form-audio-label",k&&L.classList.add("form-check-label"),L.htmlFor=g.id||"",L.textContent=i.label||i.value,L.tabIndex=0;let e=document.createElement("div");e.className="voc-form-audio-control";let l=null;if(i.audio_link){let t=document.createElement("button");t.type="button",t.className="voc-form-audio-play",k&&t.classList.add("btn","btn-sm","btn-outline-secondary"),t.setAttribute("aria-label",`Play ${i.label||i.value}`);let n="http://www.w3.org/2000/svg",o=document.createElementNS(n,"svg");o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("width","16"),o.setAttribute("height","16"),o.setAttribute("aria-hidden","true");let s=document.createElementNS(n,"path");s.setAttribute("d","M8 5v14l11-7z"),s.setAttribute("fill","currentColor"),o.appendChild(s),t.appendChild(o),l=document.createElement("audio"),l.src=i.audio_link,l.preload="none",l.style.display="none";let c=y=>{for(;y.firstChild;)y.removeChild(y.firstChild)},N=()=>{let y="http://www.w3.org/2000/svg",$=document.createElementNS(y,"svg");$.setAttribute("viewBox","0 0 24 24"),$.setAttribute("width","16"),$.setAttribute("height","16"),$.setAttribute("aria-hidden","true");let q=document.createElementNS(y,"path");return q.setAttribute("d","M8 5v14l11-7z"),q.setAttribute("fill","currentColor"),$.appendChild(q),$},S=()=>{let y="http://www.w3.org/2000/svg",$=document.createElementNS(y,"svg");$.setAttribute("viewBox","0 0 24 24"),$.setAttribute("width","16"),$.setAttribute("height","16"),$.setAttribute("aria-hidden","true");let q=document.createElementNS(y,"rect");return q.setAttribute("x","6"),q.setAttribute("y","6"),q.setAttribute("width","12"),q.setAttribute("height","12"),q.setAttribute("fill","currentColor"),$.appendChild(q),$};c(t),t.appendChild(N());let M=y=>{c(t),y?(t.appendChild(S()),t.setAttribute("aria-label",`Stop ${i.label||i.value}`)):(t.appendChild(N()),t.setAttribute("aria-label",`Play ${i.label||i.value}`))};t.addEventListener("click",()=>{try{if(!l)return;let y=h.querySelectorAll("audio");if(!l.paused&&!l.ended){l.pause(),l.currentTime=0;return}y.forEach(q=>{try{q.pause(),q.currentTime=0}catch{}}),h.querySelectorAll(".voc-form-audio-item").forEach(q=>q.classList.remove("is-playing")),l.play()}catch(y){console.warn("audio play failed",y)}}),l.addEventListener("playing",()=>{p.classList.add("is-playing"),M(!0)});let _=()=>{p.classList.remove("is-playing"),M(!1)};l.addEventListener("pause",_),l.addEventListener("ended",_),e.appendChild(t),e.appendChild(l)}let m=document.createElement("div");m.className="voc-form-item-detail",m.style.display="flex",m.style.flexDirection="column",m.style.gap="4px";let a=document.createElement("div");a.className="voc-form-item-top",a.style.display="flex",a.style.alignItems="center",a.style.gap="8px",a.appendChild(g),a.appendChild(L);let E=document.createElement("div");E.className="voc-form-item-description";let w=i.description||i.hint_text||"";w&&(E.textContent=w),m.appendChild(a),m.appendChild(E),e.appendChild(m),p.appendChild(e),a.addEventListener("click",t=>{let n=t.target;n&&n.closest(".voc-form-audio-play")||(g.checked=!0,g.dispatchEvent(new Event("change",{bubbles:!0})))}),p.addEventListener("click",t=>{let n=t.target;n&&n.closest(".voc-form-audio-play")||(g.checked=!0,g.dispatchEvent(new Event("change",{bubbles:!0})))}),h.appendChild(p)}),h}function Y(r,x,f){let k=document.createElement("div");k.className="voc-form-table-wrapper";let h=x?.style==="bootstrap",v=document.createElement("input");v.type="hidden",v.name=r.name||r.key,r.key&&(v.id=`voc-form-${r.key}`),k.appendChild(v);let u=document.createElement("table");u.className="voc-form-table",h&&u.classList.add("table","table-bordered");let i=document.createElement("thead"),d=document.createElement("tr"),p=document.createElement("th");p.className="voc-form-table-drag-col",p.textContent="",d.appendChild(p),(r.fields||[]).forEach(n=>{let o=document.createElement("th");o.textContent=n.label||n.key,d.appendChild(o)});let g=document.createElement("th");g.textContent="Actions",d.appendChild(g),i.appendChild(d),u.appendChild(i);let T=document.createElement("tbody");u.appendChild(T),k.appendChild(u);let L=document.createElement("button");L.type="button",L.className="voc-form-table-add",h&&L.classList.add("btn","btn-secondary"),L.textContent="+Add";let e=document.createElement("tfoot"),l=document.createElement("tr"),m=document.createElement("td");m.colSpan=(r.fields?r.fields.length:0)+1,m.appendChild(L),l.appendChild(m),e.appendChild(l),u.appendChild(e),k.appendChild(u);let a=[];function E(){v.value=JSON.stringify(a)}function w(n){let o=[];return r.fields.forEach(s=>{let c=n[s.key];if(s.type==="checkbox"){let N=Array.isArray(c)?c:c?[c]:[];s.required&&N.length===0&&o.push(`${s.label||s.key} is required`);return}s.required&&(c==null||String(c).trim()==="")&&o.push(`${s.label||s.key} is required`),s.type==="email"&&c&&(/^\S+@\S+\.\S+$/.test(String(c))||o.push(`${s.label||s.key} must be a valid email`)),s.type==="number"&&c&&isNaN(Number(c))&&o.push(`${s.label||s.key} must be a number`),s.validation&&s.validation.regex&&c&&(new RegExp(s.validation.regex).test(String(c))||o.push(`${s.label||s.key} invalid format`))}),o}function t(){T.innerHTML="";let n=(o,s)=>{s.draggable=!0,s.addEventListener("mousedown",()=>{s.style.cursor="grabbing"}),s.addEventListener("mouseup",()=>{s.style.cursor="grab"}),s.addEventListener("dragstart",c=>{let N=Number(o.dataset.rowIndex);c.dataTransfer.setData("text/plain",String(N)),o.classList.add("dragging");try{c.dataTransfer?.setDragImage(s,10,10)}catch{}}),s.addEventListener("dragend",()=>{o.classList.remove("dragging"),s.style.cursor="grab"}),o.addEventListener("dragover",c=>{c.preventDefault();let N=c.currentTarget,S=N.getBoundingClientRect(),M=S.top+S.height/2,_=(c.clientY||c.y)>M;N.classList.remove("drag-over-top","drag-over-bottom"),_?(N.classList.add("drag-over-bottom"),N.dataset.dropPosition="after"):(N.classList.add("drag-over-top"),N.dataset.dropPosition="before")}),o.addEventListener("dragleave",c=>{let N=c.currentTarget;N.classList.remove("drag-over-top","drag-over-bottom"),delete N.dataset.dropPosition}),o.addEventListener("drop",c=>{c.preventDefault();let N=c.dataTransfer.getData("text/plain"),S=Number(c.currentTarget.dataset.rowIndex),M=Number(N),_=c.currentTarget.dataset.dropPosition||"before";if(isNaN(M)||isNaN(S))return;let[y]=a.splice(M,1),$=S;M<S&&($=S-1);let q=_==="after"?$+1:$;a.splice(q,0,y),c.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete c.currentTarget.dataset.dropPosition,t(),E()})};a.forEach((o,s)=>{let c=document.createElement("tr");c.dataset.rowIndex=String(s),c.classList.add("voc-form-table-row");let N=document.createElement("td");N.className="voc-form-table-drag-handle";let S=document.createElement("span");S.className="voc-form-drag-handle-icon",S.textContent="\u2630",S.style.cursor="grab",N.appendChild(S),c.appendChild(N),n(c,S),r.fields.forEach(y=>{let $=document.createElement("td"),q,A=(y.type||"text").toLowerCase();if(A==="select"){let b=document.createElement("select");if(b.className="voc-form-table-cell",h&&b.classList.add("form-control"),y.placeholder){let C=document.createElement("option");C.value="",C.textContent=y.placeholder,C.disabled=!0,(o[y.key]===void 0||o[y.key]===null||o[y.key]==="")&&(C.selected=!0),b.appendChild(C)}(y.options||[]).forEach(C=>{let O=document.createElement("option");O.value=C.value,O.textContent=C.label,b.appendChild(O)}),b.value=o[y.key]!==void 0&&o[y.key]!==null?String(o[y.key]):"",y.required&&(b.required=!0),b.addEventListener("change",C=>{a[s][y.key]=C.target.value,E()}),q=b}else if(A==="checkbox"){let b=document.createElement("div");b.className="voc-form-table-checkboxes",h&&b.classList.add("form-check");let F=y.options||[];Array.isArray(a[s][y.key])||(a[s][y.key]=a[s][y.key]?[a[s][y.key]]:[]),F.forEach(C=>{let O=`voc-form-${r.key}-${y.key}-${s}-${C.value}`,B=document.createElement("div");B.className="voc-form-table-checkbox-item",h&&B.classList.add("form-check");let H=document.createElement("input");H.type="checkbox",H.className="voc-form-table-cell",h&&H.classList.add("form-check-input"),H.id=O,H.value=C.value,H.checked=Array.isArray(a[s][y.key])&&a[s][y.key].includes(C.value),H.addEventListener("change",z=>{let I=z.target.checked;Array.isArray(a[s][y.key])||(a[s][y.key]=[]),I?a[s][y.key].includes(C.value)||a[s][y.key].push(C.value):a[s][y.key]=a[s][y.key].filter(R=>R!==C.value),E()});let D=document.createElement("label");D.htmlFor=O,D.className="voc-form-table-checkbox-label",h&&D.classList.add("form-check-label"),D.textContent=C.label,B.appendChild(H),B.appendChild(D),b.appendChild(B)}),q=b}else if(A==="radio"){let b=document.createElement("div");b.className="voc-form-table-radios",h&&b.classList.add("form-check");let F=y.options||[];a[s][y.key]===void 0&&(a[s][y.key]=""),F.forEach(C=>{let O=`voc-form-${r.key}-${y.key}-${s}-${C.value}`,B=document.createElement("div");B.className="voc-form-table-radio-item",h&&B.classList.add("form-check");let H=document.createElement("input");H.type="radio",H.className="voc-form-table-cell",h&&H.classList.add("form-check-input"),H.id=O,H.name=`voc-form-${r.key}-${y.key}-${s}`,H.value=C.value,H.checked=a[s][y.key]===C.value,H.addEventListener("change",z=>{z.target.checked&&(a[s][y.key]=z.target.value,E())});let D=document.createElement("label");D.htmlFor=O,D.className="voc-form-table-radio-label",h&&D.classList.add("form-check-label"),D.textContent=C.label,B.appendChild(H),B.appendChild(D),b.appendChild(B)}),q=b}else{let b=document.createElement("input");A==="number"?b.type="number":A==="email"?b.type="email":A==="tel"?b.type="tel":A==="url"?b.type="url":A==="date"?b.type="date":b.type="text",b.value=o[y.key]!==void 0&&o[y.key]!==null?String(o[y.key]):"",y.placeholder&&(b.placeholder=y.placeholder),y.required&&(b.required=!0),b.className="voc-form-table-cell",h&&b.classList.add("form-control"),b.addEventListener("input",F=>{a[s][y.key]=F.target.value,E()}),q=b}$.appendChild(q),c.appendChild($)});let M=document.createElement("td"),_=document.createElement("button");_.type="button",_.className="voc-form-table-remove",h&&_.classList.add("btn","btn-danger"),_.textContent="Remove",_.addEventListener("click",()=>{a.splice(s,1),t(),E()}),M.appendChild(_),c.appendChild(M),T.appendChild(c)})}return L.addEventListener("click",()=>{if(r.validation?.max_rows!==void 0&&a.length>=r.validation.max_rows)return;let n={};r.fields.forEach(o=>n[o.key]=""),a.push(n),t(),E()}),Array.isArray(f)&&f.length?a=f.map(n=>({...n})):r.default&&Array.isArray(r.default)&&(a=r.default.map(n=>({...n}))),t(),E(),k.validate=function(){let n=[];return a.forEach((o,s)=>{let c=w(o);c.length&&n.push(`Row ${s+1}: ${c.join("; ")}`)}),r.validation?.min_rows!==void 0&&a.length<r.validation.min_rows&&n.push(`At least ${r.validation.min_rows} rows required`),r.validation?.max_rows!==void 0&&a.length>r.validation.max_rows&&n.push(`No more than ${r.validation.max_rows} rows allowed`),r.validation?.unique_fields&&r.validation.unique_fields.length&&r.validation.unique_fields.forEach(o=>{let s=new Set;a.forEach((c,N)=>{let S=c[o];S!=null&&(s.has(S)&&n.push(`Field ${o} must be unique (duplicate at row ${N+1})`),s.add(S))})}),n},k}async function ie(r){let f=new TextEncoder().encode(r),k=await crypto.subtle.digest("SHA-256",f);return Array.from(new Uint8Array(k)).map(v=>v.toString(16).padStart(2,"0")).join("")}async function ce(r){let x=String(r||"").trim().toLowerCase();return x?`https://gravatar.com/avatar/${await ie(x)}?d=mp`:""}function K(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-users";let v=document.createElement("div");if(v.className="voc-form-users-header",k&&v.classList.add("mb-2"),r.label){let e=document.createElement("div");if(e.className="voc-form-users-label",k&&e.classList.add("form-label"),e.textContent=r.label,r.required){let l=document.createElement("span");l.className="voc-form-required",l.textContent="*",e.appendChild(l)}v.appendChild(e)}if(r.description){let e=document.createElement("div");e.className="voc-form-users-description",k&&e.classList.add("form-text"),e.textContent=r.description,v.appendChild(e)}h.appendChild(v);let u=document.createElement("div");u.className="voc-form-users-search-wrapper";let i=document.createElement("input");if(i.type="search",i.placeholder="Search users...",i.className="voc-form-users-search",k&&i.classList.add("form-control","mb-2"),u.appendChild(i),h.appendChild(u),!r.options||r.options.length===0)return h;let d=document.createElement("div");d.className="voc-form-users-list",k&&d.classList.add("list-group");let p=r.name||r.key||`users_${Math.random().toString(36).substr(2,6)}`,g=[];if(Array.isArray(f)?g=f:f!=null?g=[f]:Array.isArray(r.default)&&(g=r.default),r.options.forEach((e,l)=>{let m=document.createElement("div");m.className="voc-form-user-item",m.dataset.label=String(e.label||"").toLowerCase(),m.dataset.email=String(e.email||"").toLowerCase(),m.dataset.value=String(e.value||"").toLowerCase(),k&&m.classList.add("d-flex","align-items-center","gap-2");let a=document.createElement("input");if(a.type="checkbox",a.name=`${p}[]`,a.value=e.value,a.className="voc-form-user-checkbox",r.key&&(a.id=`voc-form-${r.key}-${l}`),a.style.position="absolute",a.style.width="1px",a.style.height="1px",a.style.margin="0",a.style.padding="0",a.style.clip="rect(0 0 0 0)",a.style.clipPath="inset(50%)",a.style.overflow="hidden",a.style.border="0",g&&Array.isArray(g)){let o=g.map(s=>String(s));a.checked=o.includes(String(e.value))}let E=document.createElement("img");E.className="voc-form-user-avatar",E.alt=e.label||String(e.value||"user"),E.style.width=E.style.height="40px",E.style.objectFit="cover",E.style.borderRadius="50%",E.src="",e.email&&ce(e.email).then(o=>{o&&(E.src=o)}).catch(()=>{});let w=document.createElement("div");w.className="voc-form-user-info",w.style.display="flex",w.style.flexDirection="column",w.style.gap="2px";let t=document.createElement("div");t.className="voc-form-user-label",t.textContent=e.label||String(e.value);let n=document.createElement("small");n.className="voc-form-user-email",n.textContent=e.email||"",w.appendChild(t),w.appendChild(n),m.addEventListener("click",o=>{let s=o.target;s&&(s.closest("input")||s.closest("a")||s.closest("button"))||(a.checked=!a.checked,a.dispatchEvent(new Event("change",{bubbles:!0})))}),a.addEventListener("change",()=>{a.checked?m.classList.add("selected"):m.classList.remove("selected")}),a.checked&&m.classList.add("selected"),m.appendChild(a),m.appendChild(E),m.appendChild(w),d.appendChild(m)}),h.appendChild(d),r.required){let e=d.querySelectorAll('input[type="checkbox"]'),l=()=>{let m=Array.from(e).some(a=>a.checked);return e.forEach(a=>{m?a.setCustomValidity(""):a.setCustomValidity("At least one option must be selected.")}),m};e.forEach(m=>{m.addEventListener("change",l)}),h._validateCheckboxGroup=l,l()}let T=Array.from(d.querySelectorAll(".voc-form-user-item")),L=()=>{let e=String(i.value||"").trim().toLowerCase();if(!e){T.forEach(l=>l.style.setProperty("display","flex","important"));return}T.forEach(l=>{let m=l.dataset.label||"",a=l.dataset.email||"",E=l.dataset.value||"",w=m.includes(e)||a.includes(e)||E.includes(e);l.style.setProperty("display",w?"flex":"none","important")})};return i.addEventListener("input",L),h}function Q(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-timezone";let v=r.name||r.key||`timezone_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("input");u.type="text",u.name=v,r.key&&(u.id=`voc-form-${r.key}`),u.className="voc-form-timezone-input",k&&u.classList.add("form-control"),r.placeholder&&(u.placeholder=r.placeholder||""),r.required&&(u.required=!0),r.width&&(u.style.width=r.width);try{u.autocomplete="off"}catch{}try{u.autocorrect="off"}catch{}try{u.autocapitalize="off"}catch{}try{u.spellcheck=!1}catch{}u.setAttribute("data-lpignore","true"),f!=null?u.value=String(f):r.default!==void 0&&r.default!==null&&(u.value=String(r.default));let i=document.createElement("div");i.className="voc-form-timezone-control",i.style.position="relative",i.style.display="inline-block",i.style.width=r.width||"100%";let d=document.createElement("button");d.type="button",d.className="voc-form-timezone-toggle",d.setAttribute("aria-haspopup","listbox"),d.setAttribute("aria-expanded","false"),d.style.position="absolute",d.style.right="4px",d.style.top="50%",d.style.transform="translateY(-50%)",d.style.height="28px",d.style.width="28px",d.style.padding="0",d.style.border="none",d.style.background="transparent",d.style.cursor="pointer",d.innerHTML="\u25BC";let p=document.createElement("ul");p.className="voc-form-timezone-list",p.setAttribute("role","listbox"),p.style.position="absolute",p.style.left="0",p.style.right="0",p.style.zIndex="1000",p.style.maxHeight="200px",p.style.overflow="auto",p.style.margin="4px 0 0 0",p.style.padding="0",p.style.listStyle="none",p.style.background="white",p.style.border="1px solid rgba(0,0,0,0.15)",p.style.display="none",p.tabIndex=-1,u.style.paddingRight="36px";let T=["UTC","ETC","AEST","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Vancouver","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Amsterdam","Asia/Tokyo","Asia/Shanghai","Asia/Singapore","Asia/Kolkata","Asia/Dubai","Australia/Lindeman","Australia/Brisbane","Australia/Sydney","Australia/Melbourne","Australia/Hobart","Australia/Currie","Australia/Broken_Hill","Australia/Lord_Howe","Australia/Adelaide","Australia/Darwin","Australia/Perth","Australia/Eucla","Australia/ACT","ACT","Pacific/Auckland","America/Sao_Paulo","America/Mexico_City","Africa/Cairo","Africa/Johannesburg"];function L(t){p.innerHTML="",t.forEach((n,o)=>{let s=document.createElement("li");s.className="voc-form-timezone-item",s.setAttribute("role","option"),s.dataset.value=n,s.style.padding="6px 8px",s.style.cursor="pointer",s.textContent=n,s.addEventListener("mousedown",c=>{c.preventDefault(),u.value=n,a(),u.dispatchEvent(new Event("change",{bubbles:!0}))}),p.appendChild(s)})}L(T);let e=-1;function l(){Array.from(p.children).forEach((n,o)=>{o===e?(n.style.background="rgba(0,123,255,0.1)",n.setAttribute("aria-selected","true")):(n.style.background="",n.removeAttribute("aria-selected"))})}function m(){p.style.display="block",d.setAttribute("aria-expanded","true")}function a(){p.style.display="none",d.setAttribute("aria-expanded","false"),e=-1,l()}function E(){p.style.display==="none"?m():a()}u.addEventListener("input",()=>{let t=(u.value||"").trim().toLowerCase(),n=t?T.filter(o=>o.toLowerCase().includes(t)):T;L(n),m()}),d.addEventListener("click",t=>{t.preventDefault(),p.style.display==="none"?(L(T),m(),u.focus()):a()}),u.addEventListener("keydown",t=>{let n=Array.from(p.children);if(t.key==="ArrowDown"){if(t.preventDefault(),n.length===0)return;e=Math.min(e+1,n.length-1),l(),n[e].scrollIntoView({block:"nearest"})}else if(t.key==="ArrowUp"){if(t.preventDefault(),n.length===0)return;e=Math.max(e-1,0),l(),n[e].scrollIntoView({block:"nearest"})}else if(t.key==="Enter"){if(p.style.display!=="none"&&e>=0){t.preventDefault();let o=n[e];u.value=o.dataset.value||o.textContent||"",a(),u.dispatchEvent(new Event("change",{bubbles:!0}))}}else t.key==="Escape"&&a()}),document.addEventListener("click",t=>{i.contains(t.target)||a()});let w={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(u.addEventListener("blur",()=>{let t=(u.value||"").trim();if(!t)return;let n=Object.keys(w).find(o=>o.toLowerCase()===t.toLowerCase());n&&(u.value=w[n])}),r.description){let t=document.createElement("div");t.className="voc-form-timezone-description",k&&t.classList.add("form-text"),t.textContent=r.description,h.appendChild(t)}return i.appendChild(u),i.appendChild(d),i.appendChild(p),h.appendChild(i),h}function X(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-tags";let v=r.name||r.key||`tags_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("div");u.className="voc-form-tags-container",u.style.display="flex",u.style.flexWrap="wrap",u.style.gap="6px",u.style.alignItems="center",u.style.padding="6px",u.style.border="1px solid rgba(0,0,0,0.12)",u.style.borderRadius="4px";let i=document.createElement("input");i.type="text",i.className="voc-form-tags-input",i.style.border="none",i.style.flex="1 0 120px",i.style.minWidth="80px",i.style.outline="none",i.placeholder=r.placeholder||"",k&&i.classList.add("form-control"),u.appendChild(i);let d=[],p=document.createElement("input");p.type="text",p.style.position="absolute",p.style.left="-9999px",p.style.width="1px",p.style.height="1px",p.tabIndex=-1,r.required&&(p.required=!0),h.appendChild(p);function g(){Array.from(h.querySelectorAll("input.voc-form-tag-hidden")).forEach(m=>m.parentElement?.removeChild(m)),d.forEach(m=>{let a=document.createElement("input");a.type="hidden",a.name=`${v}[]`,a.className="voc-form-tag-hidden",a.value=m,r.key&&(a.id=`voc-form-${r.key}`),h.appendChild(a)}),r.required&&(d.length===0?(p.value="",p.setCustomValidity("Please enter at least one tag")):(p.value="1",p.setCustomValidity("")))}function T(l){let m=document.createElement("span");m.className="voc-form-tag",m.style.display="inline-flex",m.style.alignItems="center",m.style.padding="4px 8px",m.style.background="rgba(0,0,0,0.05)",m.style.borderRadius="16px";let a=document.createElement("span");a.textContent=l,a.style.marginRight="8px",m.appendChild(a);let E=document.createElement("button");return E.type="button",E.textContent="\xD7",E.style.border="none",E.style.background="transparent",E.style.cursor="pointer",E.addEventListener("click",()=>{let w=d.indexOf(l);w>=0&&(d.splice(w,1),u.removeChild(m),g())}),m.appendChild(E),m}function L(l){let m=l.trim();if(!m||d.includes(m))return;d.push(m);let a=T(m);u.insertBefore(a,i),g()}let e=f!=null?String(f):r.default||"";return e&&e.split(",").map(l=>l.trim()).filter(Boolean).forEach(L),i.addEventListener("keydown",l=>{if(l.key==="Enter"||l.key===",")l.preventDefault(),L(i.value),i.value="";else if(l.key==="Backspace"&&i.value===""&&d.pop()){let a=Array.from(u.querySelectorAll(".voc-form-tag")),E=a[a.length-1];E&&u.removeChild(E),g()}}),i.addEventListener("paste",l=>{let m=l.clipboardData?.getData("text");m&&(l.preventDefault(),m.split(/[,\n\r]+/).map(a=>a.trim()).filter(Boolean).forEach(L),i.value="")}),h.getTags=()=>d.slice(),h.addTag=L,h.appendChild(u),g(),h}function j(r,x=!0){let f=new FormData(r);if(x)return le(f);let k={};return f.forEach((h,v)=>{let u=(h instanceof File,h);Object.prototype.hasOwnProperty.call(k,v)?Array.isArray(k[v])?k[v].push(u):k[v]=[k[v],u]:k[v]=u}),k}function le(r){let x=new FormData;for(let[f,k]of r.entries()){if(k instanceof File){x.append(f,k);continue}let h;try{h=JSON.parse(k)}catch{h=null}Array.isArray(h)?h.length===0?x.append(f,"[]"):h.every(v=>typeof v=="object"&&v!==null)?h.forEach((v,u)=>{for(let[i,d]of Object.entries(v))x.append(`${f}[${u}][${i}]`,d)}):x.append(f,k):x.append(f,k)}return x}async function Z(r,x,f){let k=x.url,h={"Content-Type":"application/json"};x?.api_token&&(h.Authorization=`Bearer ${x.api_token}`);let v=j(r);if(x?.additional_data)for(let[d,p]of Object.entries(x.additional_data))v.append(d,p);let u,i=v instanceof FormData;u={method:"POST",headers:{Authorization:`Bearer ${x.api_token}`,...i?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:i?v:JSON.stringify(Object.fromEntries(v.entries()))};try{fetch(k,u).then(async d=>{let p=d.headers.get("content-type");if(!d.ok)try{let T=(await d.json())?.message;throw new Error(T??"Their was an error submitting the form. Check your form and try again.")}catch(g){throw new Error(g.message)}return p&&p.includes("application/json")?d.json():d.text()}).then(d=>{f&&f(d,null)}).catch(d=>{f&&f(null,d)})}catch(d){f&&f(null,d)}}function ee(r,x,f){let k=[];if(typeof r=="string"?k=Array.from(document.querySelectorAll(r)):k=[r],k.length===0)return null;function h(){let i=f?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),i&&d.classList.add("needs-validation"),d.id=x.id;let p=document.createElement("h2");p.className="voc-form-title",i&&p.classList.add("mb-3"),p.textContent=x.form_name,d.appendChild(p);function g(e,l){l&&(l.min_length!==void 0&&(e.minLength=l.min_length),l.max_length!==void 0&&(e.maxLength=l.max_length),l.regex&&(e instanceof HTMLInputElement?e.pattern=l.regex:e.dataset.pattern=l.regex))}function T(e){if(!e.key&&!e.label)return null;let l=x.default_values||{},m=e.name||e.key,a=m?l[m]:void 0,E=document.createElement("div");if(E.className="voc-form-group",i&&E.classList.add("mb-3"),e.label&&e.type!=="users"){let t=document.createElement("label");if(t.classList.add("voc-form-label"),i&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label,e.required){let n=document.createElement("span");n.className="voc-form-required",n.textContent="*",t.appendChild(n)}E.appendChild(t)}let w=null;switch(e.type){case"tags":{w=X(e,f||{},a);break}case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options){if(e.options.forEach((n,o)=>{let s=document.createElement("label");s.classList.add("voc-form-checkbox-label"),i&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),i&&c.classList.add("form-check-input"),c.name=`${e.name||e.key||""}[]`,c.value=n.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),Array.isArray(a)?a.includes(n.value)&&(c.checked=!0):a!==void 0?a===n.value&&(c.checked=!0):e.default===n.value&&(c.checked=!0),s.appendChild(c),s.appendChild(document.createTextNode(n.label)),t.appendChild(s)}),e.required){let n=t.querySelectorAll('input[type="checkbox"]'),o=()=>{let s=Array.from(n).some(c=>c.checked);return n.forEach(c=>{s?c.setCustomValidity(""):c.setCustomValidity("At least one option must be selected.")}),s};n.forEach(s=>{s.addEventListener("change",o)}),t._validateCheckboxGroup=o,o()}}else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),i&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),(e.key||e.name)&&(o.name=e.name||e.key,e.key&&(o.id=`voc-form-${e.key}`)),i&&o.classList.add("form-check-input"),e.required&&(o.required=!0),a!==void 0?o.checked=!!a:e.default&&(o.checked=!!e.default),n.appendChild(o),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}w=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),a!=null?t.value=String(a):e.default!==void 0&&e.default!==null&&(t.value=String(e.default));let n=e.default||a||"";if(n){let o=(n.match(/\n/g)||[]).length,s=80,c=n.split(`
2
- `).reduce((M,_)=>Math.max(M,_.length),0),N=Math.ceil(c/s)||1,S=Math.max(2,o+N);t.rows=S,t.style.resize="vertical"}e.width&&(t.style.width=e.width),e.required&&(t.required=!0),g(t,e.validation),w=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),i&&t.classList.add("form-select"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let o=document.createElement("option");o.value=n.value,o.textContent=n.label,Array.isArray(a)?a.includes(n.value)&&(o.selected=!0):a!==void 0?a===n.value&&(o.selected=!0):e.default===n.value&&(o.selected=!0),t.appendChild(o)}),e.width&&(t.style.width=e.width),w=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,o)=>{let s=document.createElement("label");s.classList.add("voc-form-radio-label"),i&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let c=document.createElement("input");c.type="radio",c.classList.add("voc-form-radio"),i&&c.classList.add("form-check-input"),c.name=e.name||e.key||"",c.value=n.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),Array.isArray(a)?a.includes(n.value)&&(c.checked=!0):a!==void 0?a===n.value&&(c.checked=!0):e.default===n.value&&(c.checked=!0),s.appendChild(c),s.appendChild(document.createTextNode(n.label)),t.appendChild(s)}),w=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),i&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),w=t;break}case"avatar":{w=U(e,f||{},a);break}case"table":{w=Y(e,f||{},a);break}case"users":{w=K(e,f||{},a);break}case"timezone":{w=Q(e,f||{},a);break}case"audio_select":{w=J(e,f||{},a);break}case"field-select":{let t=f?.style==="bootstrap",n=document.createElement("div");n.className="voc-form-field-selects";let o=document.createElement("div");if(o.className="voc-form-field-selects-header",t&&o.classList.add("mb-2"),e.label){let A=document.createElement("div");if(A.className="voc-form-field-selects-label",t&&A.classList.add("form-label"),A.textContent=e.label,e.required){let b=document.createElement("span");b.className="voc-form-required",b.textContent="*",A.appendChild(b)}o.appendChild(A)}if(e.description){let A=document.createElement("div");A.className="voc-form-field-selects-description",t&&A.classList.add("form-text"),A.textContent=e.description,o.appendChild(A)}n.appendChild(o);let s=document.createElement("div");s.className="voc-form-field-selects-search-wrapper";let c=document.createElement("input");if(c.type="search",c.placeholder="Search...",c.className="voc-form-field-selects-search",t&&c.classList.add("form-control","mb-2"),s.appendChild(c),n.appendChild(s),!e.options||e.options.length===0)return n;let N=document.createElement("div");N.className="voc-form-field-selects-list",t&&N.classList.add("list-group");let S=document.createElement("div");S.className="voc-form-field-selects-selected",S.style.marginTop="12px";let M={},_=e.name||e.key||`users_${Math.random().toString(36).substr(2,6)}`,y=[];if(Array.isArray(a)?y=a:a!=null?y=[a]:Array.isArray(e.default)&&(y=e.default),e.options.forEach((A,b)=>{let F=document.createElement("div");F.className="voc-form-field-selects-item",F.dataset.label=String(A.label||"").toLowerCase(),F.dataset.email=String(A.email||"").toLowerCase(),F.dataset.value=String(A.value||"").toLowerCase(),t&&F.classList.add("d-flex","align-items-center","gap-2");let C=document.createElement("input");if(C.type="checkbox",C.name=`${_}[]`,C.value=A.value??A.key,C.className="voc-form--checkbox",e.key&&(C.id=`voc-form-${e.key}-${b}`),C.style.position="absolute",C.style.width="1px",C.style.height="1px",C.style.margin="0",C.style.padding="0",C.style.clip="rect(0 0 0 0)",C.style.clipPath="inset(50%)",C.style.overflow="hidden",C.style.border="0",y&&Array.isArray(y)){let I=y.map(P=>String(P)),R=String(A.value??A.key);C.checked=I.includes(R)}let O=A.icon||'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><!-- Icon from Google Material Icons by Material Design Authors - https://github.com/material-icons/material-icons/blob/master/LICENSE --><path fill="currentColor" d="M14 11c0 .55-.45 1-1 1H4c-.55 0-1-.45-1-1s.45-1 1-1h9c.55 0 1 .45 1 1M3 7c0 .55.45 1 1 1h9c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1m7 8c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1m8.01-2.13l.71-.71a.996.996 0 0 1 1.41 0l.71.71c.39.39.39 1.02 0 1.41l-.71.71zm-.71.71l-5.16 5.16c-.09.09-.14.21-.14.35v1.41c0 .28.22.5.5.5h1.41c.13 0 .26-.05.35-.15l5.16-5.16z"/></svg>',B=document.createElement("div");B.className="voc-form-fields-select-avatar",B.innerHTML=O;let H=document.createElement("div");H.className="voc-form-field-select-info",H.style.display="flex",H.style.flexDirection="column",H.style.gap="2px";let D=document.createElement("div");D.className="voc-form-field-select-label",D.textContent=A.label||String(A.value);let z=document.createElement("small");z.className="voc-form-field-select-email",z.textContent=A.email||"",H.appendChild(D),H.appendChild(z),F.addEventListener("click",I=>{let R=I.target;R&&(R.closest("input")||R.closest("a")||R.closest("button"))||(C.checked=!C.checked,C.dispatchEvent(new Event("change",{bubbles:!0})))}),C.addEventListener("change",()=>{if(C.checked){F.classList.add("selected"),(M[b]||[]).forEach(P=>P.parentElement?.removeChild(P)),M[b]=[];let R=A;if(R&&Array.isArray(R.items))R.items.forEach(P=>{let W=T(P);W&&(S.appendChild(W),M[b].push(W))});else if(R&&(R.type||R.key)){let P=T(R);P&&(S.appendChild(P),M[b].push(P))}}else F.classList.remove("selected"),(M[b]||[]).forEach(R=>R.parentElement?.removeChild(R)),M[b]=[]}),C.checked&&(F.classList.add("selected"),setTimeout(()=>{let I=A;if(I&&Array.isArray(I.items))I.items.forEach(R=>{let P=T(R);P&&(S.appendChild(P),M[b]=M[b]||[],M[b].push(P))});else if(I&&(I.type||I.key)){let R=T(I);R&&(S.appendChild(R),M[b]=M[b]||[],M[b].push(R))}},0)),F.appendChild(C),F.appendChild(B),F.appendChild(H),N.appendChild(F)}),n.appendChild(N),n.appendChild(S),e.required){let A=N.querySelectorAll('input[type="checkbox"]'),b=()=>{let F=Array.from(A).some(C=>C.checked);return A.forEach(C=>{F?C.setCustomValidity(""):C.setCustomValidity("At least one option must be selected.")}),F};A.forEach(F=>{F.addEventListener("change",b)}),n._validateCheckboxGroup=b,b()}let $=Array.from(N.querySelectorAll(".voc-form-field-select-item")),q=()=>{let A=String(c.value||"").trim().toLowerCase();if(!A){$.forEach(b=>b.style.setProperty("display","flex","important"));return}$.forEach(b=>{let F=b.dataset.label||"",C=b.dataset.email||"",O=b.dataset.value||"",B=F.includes(A)||C.includes(A)||O.includes(A);b.style.setProperty("display",B?"flex":"none","important")})};return c.addEventListener("input",q),n}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),a!=null?t.value=String(a):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),g(t,e.validation),w=t;break}}if(w&&E.appendChild(w),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,E.appendChild(t)}return E}x.fields.forEach(e=>{if(e.type==="group"&&"items"in e){let l=e;if(i){let m=document.createElement("div");m.className="card voc-form-group-card mb-3";let a=l.label||l.header?.title,E=l.description||l.header?.description;if(a||E){let t=document.createElement("div");if(t.className="card-header voc-form-group-head",a){let n=document.createElement("h5");n.className="mb-0 voc-form-group-label",n.textContent=a,t.appendChild(n)}if(E){let n=document.createElement("p");n.className="mb-0 voc-form-group-description",n.textContent=E,t.appendChild(n)}m.appendChild(t)}let w=document.createElement("div");w.className="card-body voc-form-group-body",l.items.forEach(t=>{if(t.type==="row"&&"items"in t){let n=t,o=document.createElement("div");if(o.className="voc-form-group voc-form-row mb-3",n.label){let c=document.createElement("h6");c.className="voc-form-row-label",c.textContent=n.label,o.appendChild(c)}let s=document.createElement("div");s.className="voc-form-row-items "+(n.direction||"horizontal"),n.items.forEach(c=>{let N=T(c);N&&s.appendChild(N)}),o.appendChild(s),w.appendChild(o)}else{let n=T(t);n&&w.appendChild(n)}}),m.appendChild(w),d.appendChild(m)}else{let m=document.createElement("div");m.className="voc-form-group voc-form-group-wrapper",i&&m.classList.add("mb-3");let a=l.label||l.header?.title,E=l.description||l.header?.description;if(a||E){let w=document.createElement("div");if(w.className="voc-form-group-head",a){let t=document.createElement("h3");t.className="voc-form-group-label",t.textContent=a,w.appendChild(t)}if(E){let t=document.createElement("p");t.className="voc-form-group-description",t.textContent=E,w.appendChild(t)}m.appendChild(w)}l.items.forEach(w=>{if(w.type==="row"&&"items"in w){let t=w,n=document.createElement("div");if(n.className="voc-form-group voc-form-row",i&&n.classList.add("mb-3"),t.label){let s=document.createElement("h4");s.className="voc-form-row-label",s.textContent=t.label,n.appendChild(s)}let o=document.createElement("div");o.className="voc-form-row-items "+(t.direction||"horizontal"),t.items.forEach(s=>{let c=T(s);c&&o.appendChild(c)}),n.appendChild(o),m.appendChild(n)}else{let t=T(w);t&&m.appendChild(t)}}),d.appendChild(m)}return}if(e.type==="row"&&"items"in e){let l=document.createElement("div");if(l.className="voc-form-group voc-form-row",i&&l.classList.add("mb-3"),e.label){let a=document.createElement("h3");a.className="voc-form-row-label",a.textContent=e.label,l.appendChild(a)}if(e.description){let a=document.createElement("p");a.className="voc-form-row-description",a.textContent=e.description,l.appendChild(a)}let m=document.createElement("div");m.className="voc-form-row-items "+(e.direction||"horizontal"),l.appendChild(m),e.items.forEach(a=>{let E=T(a);E&&m.appendChild(E)}),d.appendChild(l)}else{let l=T(e);l&&d.appendChild(l)}});let L=document.createElement("button");return L.type="submit",L.className="voc-form-submit",L.textContent="Submit",i&&L.classList.add("btn","btn-primary"),d.appendChild(L),d}let v=h();k[0].appendChild(v);let u=x?.submit_config??f?.submit_config??null;return u&&v.addEventListener("submit",i=>{i.preventDefault();let d=Array.from(v.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),p=[];if(d.forEach(L=>{L&&typeof L._validateCheckboxGroup=="function"&&(L._validateCheckboxGroup()||L.querySelector('input[type="checkbox"]')&&p.push("Please select at least one option"))}),!v.checkValidity()){v.reportValidity(),f?.onSubmitResult&&f.onSubmitResult(null,new Error("Form validation failed"));return}let g=Array.from(v.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),T=[];if(g.forEach(L=>{if(L&&typeof L.validate=="function"){let e=L.validate();e&&e.length&&T.push(...e)}}),T.length){f?.onSubmitResult&&f.onSubmitResult(null,new Error(T.join("; ")));let L=g[0];L&&L.scrollIntoView({behavior:"smooth",block:"center"});return}if(f?.onSubmit){let L=j(v);f.onSubmit(L)}Z(v,u,(L,e)=>{f?.onSubmitResult&&f.onSubmitResult(L,e)})}),{element:v,validate:()=>{let i=[];return v.querySelectorAll(":invalid").forEach(p=>{let g=p.validationMessage;i.push({element:p,message:g})}),i},getValues:()=>j(v),onSubmit:i=>{v.addEventListener("submit",d=>{d.preventDefault();let p=j(v);i(p,d)})}}}var V={renderForm:ee};var de=V,me={FormsLib:V};return oe(ue);})();
1
+ "use strict";var VocLibJs=(()=>{var P=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ae=Object.prototype.hasOwnProperty;var ne=(r,L)=>{for(var v in L)P(r,v,{get:L[v],enumerable:!0})},re=(r,L,v,C)=>{if(L&&typeof L=="object"||typeof L=="function")for(let f of te(L))!ae.call(r,f)&&f!==v&&P(r,f,{get:()=>L[f],enumerable:!(C=ee(L,f))||C.enumerable});return r};var se=r=>re(P({},"__esModule",{value:!0}),r);var me={};ne(me,{FormsLib:()=>ce,default:()=>de});function j(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-avatar-wrapper",C&&f.classList.add("d-flex","align-items-center","gap-3");let b=document.createElement("img");b.className="voc-form-avatar-preview",b.alt=r.label||"avatar",C&&(b.classList.add("img-thumbnail","rounded-circle"),b.style.width=b.style.height="64px",b.style.objectFit="cover");let u=v!=null?String(v):r.default!==void 0&&r.default!==null?String(r.default):"";u?b.src=u:(b.src="",b.style.display="none");let o=document.createElement("input");o.type="file",o.accept=r.accept||"image/*",o.className="voc-form-avatar-input",C&&o.classList.add("form-control"),(r.key||r.name)&&(o.name=r.name||r.key,r.key&&(o.id=`voc-form-${r.key}`));let d=document.createElement("input");if(d.type="hidden",(r.key||r.name)&&(d.name=(r.name||r.key)+"_url"),d.value=u||"",o.addEventListener("change",p=>{let E=p.target;if(E.files&&E.files.length>0){let w=E.files[0],k=new FileReader;k.onload=()=>{b.src=String(k.result),b.style.display="",d.value=""},k.readAsDataURL(w)}}),C){let p=document.createElement("div");p.style.flex="1",p.appendChild(o),p.appendChild(d),f.appendChild(b),f.appendChild(p)}else f.appendChild(b),f.appendChild(o),f.appendChild(d);return f}function W(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");if(f.className="voc-form-audio-select",!r.options||r.options.length===0)return f;let b=r.name||r.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,u;return Array.isArray(v)?u=v[0]:v!==void 0?u=v:r.default!==void 0&&(u=r.default),r.options.forEach((o,d)=>{let p=document.createElement("div");p.className="voc-form-audio-item",C&&p.classList.add("form-check");let E=document.createElement("input");E.type="radio",E.name=b,E.value=o.value,E.className="voc-form-audio-radio",r.key&&(E.id=`voc-form-${r.key}-${d}`),r.required&&d===0&&(E.required=!0),E.style.position="absolute",E.style.width="1px",E.style.height="1px",E.style.margin="0",E.style.padding="0",E.style.clip="rect(0 0 0 0)",E.style.clipPath="inset(50%)",E.style.overflow="hidden",E.style.border="0",u!==void 0&&(Array.isArray(u)?E.checked=u.includes(o.value):E.checked=String(u)===String(o.value));let w=()=>{E.checked?p.classList.add("selected"):p.classList.remove("selected")};E.addEventListener("change",()=>{f.querySelectorAll(".voc-form-audio-item").forEach(a=>a.classList.remove("selected")),w()}),E.checked&&p.classList.add("selected");let k=document.createElement("label");k.className="voc-form-audio-label",C&&k.classList.add("form-check-label"),k.htmlFor=E.id||"",k.textContent=o.label||o.value,k.tabIndex=0;let e=document.createElement("div");e.className="voc-form-audio-control";let c=null;if(o.audio_link){let t=document.createElement("button");t.type="button",t.className="voc-form-audio-play",C&&t.classList.add("btn","btn-sm","btn-outline-secondary"),t.setAttribute("aria-label",`Play ${o.label||o.value}`);let a="http://www.w3.org/2000/svg",i=document.createElementNS(a,"svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width","16"),i.setAttribute("height","16"),i.setAttribute("aria-hidden","true");let s=document.createElementNS(a,"path");s.setAttribute("d","M8 5v14l11-7z"),s.setAttribute("fill","currentColor"),i.appendChild(s),t.appendChild(i),c=document.createElement("audio"),c.src=o.audio_link,c.preload="none",c.style.display="none";let l=g=>{for(;g.firstChild;)g.removeChild(g.firstChild)},A=()=>{let g="http://www.w3.org/2000/svg",F=document.createElementNS(g,"svg");F.setAttribute("viewBox","0 0 24 24"),F.setAttribute("width","16"),F.setAttribute("height","16"),F.setAttribute("aria-hidden","true");let M=document.createElementNS(g,"path");return M.setAttribute("d","M8 5v14l11-7z"),M.setAttribute("fill","currentColor"),F.appendChild(M),F},S=()=>{let g="http://www.w3.org/2000/svg",F=document.createElementNS(g,"svg");F.setAttribute("viewBox","0 0 24 24"),F.setAttribute("width","16"),F.setAttribute("height","16"),F.setAttribute("aria-hidden","true");let M=document.createElementNS(g,"rect");return M.setAttribute("x","6"),M.setAttribute("y","6"),M.setAttribute("width","12"),M.setAttribute("height","12"),M.setAttribute("fill","currentColor"),F.appendChild(M),F};l(t),t.appendChild(A());let N=g=>{l(t),g?(t.appendChild(S()),t.setAttribute("aria-label",`Stop ${o.label||o.value}`)):(t.appendChild(A()),t.setAttribute("aria-label",`Play ${o.label||o.value}`))};t.addEventListener("click",()=>{try{if(!c)return;let g=f.querySelectorAll("audio");if(!c.paused&&!c.ended){c.pause(),c.currentTime=0;return}g.forEach(M=>{try{M.pause(),M.currentTime=0}catch{}}),f.querySelectorAll(".voc-form-audio-item").forEach(M=>M.classList.remove("is-playing")),c.play()}catch(g){console.warn("audio play failed",g)}}),c.addEventListener("playing",()=>{p.classList.add("is-playing"),N(!0)});let x=()=>{p.classList.remove("is-playing"),N(!1)};c.addEventListener("pause",x),c.addEventListener("ended",x),e.appendChild(t),e.appendChild(c)}let h=document.createElement("div");h.className="voc-form-item-detail",h.style.display="flex",h.style.flexDirection="column",h.style.gap="4px";let n=document.createElement("div");n.className="voc-form-item-top",n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.appendChild(E),n.appendChild(k);let m=document.createElement("div");m.className="voc-form-item-description";let y=o.description||o.hint_text||"";y&&(m.textContent=y),h.appendChild(n),h.appendChild(m),e.appendChild(h),p.appendChild(e),n.addEventListener("click",t=>{let a=t.target;a&&a.closest(".voc-form-audio-play")||(E.checked=!0,E.dispatchEvent(new Event("change",{bubbles:!0})))}),p.addEventListener("click",t=>{let a=t.target;a&&a.closest(".voc-form-audio-play")||(E.checked=!0,E.dispatchEvent(new Event("change",{bubbles:!0})))}),f.appendChild(p)}),f}function G(r,L,v){let C=document.createElement("div");C.className="voc-form-table-wrapper";let f=L?.style==="bootstrap",b=document.createElement("input");b.type="hidden",b.name=r.name||r.key,r.key&&(b.id=`voc-form-${r.key}`),C.appendChild(b);let u=document.createElement("table");u.className="voc-form-table",f&&u.classList.add("table","table-bordered");let o=document.createElement("thead"),d=document.createElement("tr"),p=document.createElement("th");p.className="voc-form-table-drag-col",p.textContent="",d.appendChild(p),(r.fields||[]).forEach(a=>{let i=document.createElement("th");i.textContent=a.label||a.key,d.appendChild(i)});let E=document.createElement("th");E.textContent="Actions",d.appendChild(E),o.appendChild(d),u.appendChild(o);let w=document.createElement("tbody");u.appendChild(w),C.appendChild(u);let k=document.createElement("button");k.type="button",k.className="voc-form-table-add",f&&k.classList.add("btn","btn-secondary"),k.textContent="+Add";let e=document.createElement("tfoot"),c=document.createElement("tr"),h=document.createElement("td");h.colSpan=(r.fields?r.fields.length:0)+1,h.appendChild(k),c.appendChild(h),e.appendChild(c),u.appendChild(e),C.appendChild(u);let n=[];function m(){b.value=JSON.stringify(n)}function y(a){let i=[];return r.fields.forEach(s=>{let l=a[s.key];if(s.type==="checkbox"){let A=Array.isArray(l)?l:l?[l]:[];s.required&&A.length===0&&i.push(`${s.label||s.key} is required`);return}s.required&&(l==null||String(l).trim()==="")&&i.push(`${s.label||s.key} is required`),s.type==="email"&&l&&(/^\S+@\S+\.\S+$/.test(String(l))||i.push(`${s.label||s.key} must be a valid email`)),s.type==="number"&&l&&isNaN(Number(l))&&i.push(`${s.label||s.key} must be a number`),s.validation&&s.validation.regex&&l&&(new RegExp(s.validation.regex).test(String(l))||i.push(`${s.label||s.key} invalid format`))}),i}function t(){w.innerHTML="";let a=(i,s)=>{s.draggable=!0,s.addEventListener("mousedown",()=>{s.style.cursor="grabbing"}),s.addEventListener("mouseup",()=>{s.style.cursor="grab"}),s.addEventListener("dragstart",l=>{let A=Number(i.dataset.rowIndex);l.dataTransfer.setData("text/plain",String(A)),i.classList.add("dragging");try{l.dataTransfer?.setDragImage(s,10,10)}catch{}}),s.addEventListener("dragend",()=>{i.classList.remove("dragging"),s.style.cursor="grab"}),i.addEventListener("dragover",l=>{l.preventDefault();let A=l.currentTarget,S=A.getBoundingClientRect(),N=S.top+S.height/2,x=(l.clientY||l.y)>N;A.classList.remove("drag-over-top","drag-over-bottom"),x?(A.classList.add("drag-over-bottom"),A.dataset.dropPosition="after"):(A.classList.add("drag-over-top"),A.dataset.dropPosition="before")}),i.addEventListener("dragleave",l=>{let A=l.currentTarget;A.classList.remove("drag-over-top","drag-over-bottom"),delete A.dataset.dropPosition}),i.addEventListener("drop",l=>{l.preventDefault();let A=l.dataTransfer.getData("text/plain"),S=Number(l.currentTarget.dataset.rowIndex),N=Number(A),x=l.currentTarget.dataset.dropPosition||"before";if(isNaN(N)||isNaN(S))return;let[g]=n.splice(N,1),F=S;N<S&&(F=S-1);let M=x==="after"?F+1:F;n.splice(M,0,g),l.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete l.currentTarget.dataset.dropPosition,t(),m()})};n.forEach((i,s)=>{let l=document.createElement("tr");l.dataset.rowIndex=String(s),l.classList.add("voc-form-table-row");let A=document.createElement("td");A.className="voc-form-table-drag-handle";let S=document.createElement("span");S.className="voc-form-drag-handle-icon",S.textContent="\u2630",S.style.cursor="grab",A.appendChild(S),l.appendChild(A),a(l,S),r.fields.forEach(g=>{let F=document.createElement("td"),M,B=(g.type||"text").toLowerCase();if(B==="select"){let T=document.createElement("select");if(T.className="voc-form-table-cell",f&&T.classList.add("form-control"),g.placeholder){let H=document.createElement("option");H.value="",H.textContent=g.placeholder,H.disabled=!0,(i[g.key]===void 0||i[g.key]===null||i[g.key]==="")&&(H.selected=!0),T.appendChild(H)}(g.options||[]).forEach(H=>{let $=document.createElement("option");$.value=H.value,$.textContent=H.label,T.appendChild($)}),T.value=i[g.key]!==void 0&&i[g.key]!==null?String(i[g.key]):"",g.required&&(T.required=!0),T.addEventListener("change",H=>{n[s][g.key]=H.target.value,m()}),M=T}else if(B==="checkbox"){let T=document.createElement("div");T.className="voc-form-table-checkboxes",f&&T.classList.add("form-check");let D=g.options||[];Array.isArray(n[s][g.key])||(n[s][g.key]=n[s][g.key]?[n[s][g.key]]:[]),D.forEach(H=>{let $=`voc-form-${r.key}-${g.key}-${s}-${H.value}`,q=document.createElement("div");q.className="voc-form-table-checkbox-item",f&&q.classList.add("form-check");let R=document.createElement("input");R.type="checkbox",R.className="voc-form-table-cell",f&&R.classList.add("form-check-input"),R.id=$,R.value=H.value,R.checked=Array.isArray(n[s][g.key])&&n[s][g.key].includes(H.value),R.addEventListener("change",O=>{let X=O.target.checked;Array.isArray(n[s][g.key])||(n[s][g.key]=[]),X?n[s][g.key].includes(H.value)||n[s][g.key].push(H.value):n[s][g.key]=n[s][g.key].filter(Z=>Z!==H.value),m()});let _=document.createElement("label");_.htmlFor=$,_.className="voc-form-table-checkbox-label",f&&_.classList.add("form-check-label"),_.textContent=H.label,q.appendChild(R),q.appendChild(_),T.appendChild(q)}),M=T}else if(B==="radio"){let T=document.createElement("div");T.className="voc-form-table-radios",f&&T.classList.add("form-check");let D=g.options||[];n[s][g.key]===void 0&&(n[s][g.key]=""),D.forEach(H=>{let $=`voc-form-${r.key}-${g.key}-${s}-${H.value}`,q=document.createElement("div");q.className="voc-form-table-radio-item",f&&q.classList.add("form-check");let R=document.createElement("input");R.type="radio",R.className="voc-form-table-cell",f&&R.classList.add("form-check-input"),R.id=$,R.name=`voc-form-${r.key}-${g.key}-${s}`,R.value=H.value,R.checked=n[s][g.key]===H.value,R.addEventListener("change",O=>{O.target.checked&&(n[s][g.key]=O.target.value,m())});let _=document.createElement("label");_.htmlFor=$,_.className="voc-form-table-radio-label",f&&_.classList.add("form-check-label"),_.textContent=H.label,q.appendChild(R),q.appendChild(_),T.appendChild(q)}),M=T}else{let T=document.createElement("input");B==="number"?T.type="number":B==="email"?T.type="email":B==="tel"?T.type="tel":B==="url"?T.type="url":B==="date"?T.type="date":T.type="text",T.value=i[g.key]!==void 0&&i[g.key]!==null?String(i[g.key]):"",g.placeholder&&(T.placeholder=g.placeholder),g.required&&(T.required=!0),T.className="voc-form-table-cell",f&&T.classList.add("form-control"),T.addEventListener("input",D=>{n[s][g.key]=D.target.value,m()}),M=T}F.appendChild(M),l.appendChild(F)});let N=document.createElement("td"),x=document.createElement("button");x.type="button",x.className="voc-form-table-remove",f&&x.classList.add("btn","btn-danger"),x.textContent="Remove",x.addEventListener("click",()=>{n.splice(s,1),t(),m()}),N.appendChild(x),l.appendChild(N),w.appendChild(l)})}return k.addEventListener("click",()=>{if(r.validation?.max_rows!==void 0&&n.length>=r.validation.max_rows)return;let a={};r.fields.forEach(i=>a[i.key]=""),n.push(a),t(),m()}),Array.isArray(v)&&v.length?n=v.map(a=>({...a})):r.default&&Array.isArray(r.default)&&(n=r.default.map(a=>({...a}))),t(),m(),C.validate=function(){let a=[];return n.forEach((i,s)=>{let l=y(i);l.length&&a.push(`Row ${s+1}: ${l.join("; ")}`)}),r.validation?.min_rows!==void 0&&n.length<r.validation.min_rows&&a.push(`At least ${r.validation.min_rows} rows required`),r.validation?.max_rows!==void 0&&n.length>r.validation.max_rows&&a.push(`No more than ${r.validation.max_rows} rows allowed`),r.validation?.unique_fields&&r.validation.unique_fields.length&&r.validation.unique_fields.forEach(i=>{let s=new Set;n.forEach((l,A)=>{let S=l[i];S!=null&&(s.has(S)&&a.push(`Field ${i} must be unique (duplicate at row ${A+1})`),s.add(S))})}),a},C}async function oe(r){let v=new TextEncoder().encode(r),C=await crypto.subtle.digest("SHA-256",v);return Array.from(new Uint8Array(C)).map(b=>b.toString(16).padStart(2,"0")).join("")}async function ie(r){let L=String(r||"").trim().toLowerCase();return L?`https://gravatar.com/avatar/${await oe(L)}?d=mp`:""}function U(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-users";let b=document.createElement("div");if(b.className="voc-form-users-header",C&&b.classList.add("mb-2"),r.label){let e=document.createElement("div");if(e.className="voc-form-users-label",C&&e.classList.add("form-label"),e.textContent=r.label,r.required){let c=document.createElement("span");c.className="voc-form-required",c.textContent="*",e.appendChild(c)}b.appendChild(e)}if(r.description){let e=document.createElement("div");e.className="voc-form-users-description",C&&e.classList.add("form-text"),e.textContent=r.description,b.appendChild(e)}f.appendChild(b);let u=document.createElement("div");u.className="voc-form-users-search-wrapper";let o=document.createElement("input");if(o.type="search",o.placeholder="Search users...",o.className="voc-form-users-search",C&&o.classList.add("form-control","mb-2"),u.appendChild(o),f.appendChild(u),!r.options||r.options.length===0)return f;let d=document.createElement("div");d.className="voc-form-users-list",C&&d.classList.add("list-group");let p=r.name||r.key||`users_${Math.random().toString(36).substr(2,6)}`,E=[];if(Array.isArray(v)?E=v:v!=null?E=[v]:Array.isArray(r.default)&&(E=r.default),r.options.forEach((e,c)=>{let h=document.createElement("div");h.className="voc-form-user-item",h.dataset.label=String(e.label||"").toLowerCase(),h.dataset.email=String(e.email||"").toLowerCase(),h.dataset.value=String(e.value||"").toLowerCase(),C&&h.classList.add("d-flex","align-items-center","gap-2");let n=document.createElement("input");if(n.type="checkbox",n.name=`${p}[]`,n.value=e.value,n.className="voc-form-user-checkbox",r.key&&(n.id=`voc-form-${r.key}-${c}`),n.style.position="absolute",n.style.width="1px",n.style.height="1px",n.style.margin="0",n.style.padding="0",n.style.clip="rect(0 0 0 0)",n.style.clipPath="inset(50%)",n.style.overflow="hidden",n.style.border="0",E&&Array.isArray(E)){let i=E.map(s=>String(s));n.checked=i.includes(String(e.value))}let m=document.createElement("img");m.className="voc-form-user-avatar",m.alt=e.label||String(e.value||"user"),m.style.width=m.style.height="40px",m.style.objectFit="cover",m.style.borderRadius="50%",m.src="",e.email&&ie(e.email).then(i=>{i&&(m.src=i)}).catch(()=>{});let y=document.createElement("div");y.className="voc-form-user-info",y.style.display="flex",y.style.flexDirection="column",y.style.gap="2px";let t=document.createElement("div");t.className="voc-form-user-label",t.textContent=e.label||String(e.value);let a=document.createElement("small");a.className="voc-form-user-email",a.textContent=e.email||"",y.appendChild(t),y.appendChild(a),h.addEventListener("click",i=>{let s=i.target;s&&(s.closest("input")||s.closest("a")||s.closest("button"))||(n.checked=!n.checked,n.dispatchEvent(new Event("change",{bubbles:!0})))}),n.addEventListener("change",()=>{n.checked?h.classList.add("selected"):h.classList.remove("selected")}),n.checked&&h.classList.add("selected"),h.appendChild(n),h.appendChild(m),h.appendChild(y),d.appendChild(h)}),f.appendChild(d),r.required){let e=d.querySelectorAll('input[type="checkbox"]'),c=()=>{let h=Array.from(e).some(n=>n.checked);return e.forEach(n=>{h?n.setCustomValidity(""):n.setCustomValidity("At least one option must be selected.")}),h};e.forEach(h=>{h.addEventListener("change",c)}),f._validateCheckboxGroup=c,c()}let w=Array.from(d.querySelectorAll(".voc-form-user-item")),k=()=>{let e=String(o.value||"").trim().toLowerCase();if(!e){w.forEach(c=>c.style.setProperty("display","flex","important"));return}w.forEach(c=>{let h=c.dataset.label||"",n=c.dataset.email||"",m=c.dataset.value||"",y=h.includes(e)||n.includes(e)||m.includes(e);c.style.setProperty("display",y?"flex":"none","important")})};return o.addEventListener("input",k),f}function V(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-timezone";let b=r.name||r.key||`timezone_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("input");u.type="text",u.name=b,r.key&&(u.id=`voc-form-${r.key}`),u.className="voc-form-timezone-input",C&&u.classList.add("form-control"),r.placeholder&&(u.placeholder=r.placeholder||""),r.required&&(u.required=!0),r.width&&(u.style.width=r.width);try{u.autocomplete="off"}catch{}try{u.autocorrect="off"}catch{}try{u.autocapitalize="off"}catch{}try{u.spellcheck=!1}catch{}u.setAttribute("data-lpignore","true"),v!=null?u.value=String(v):r.default!==void 0&&r.default!==null&&(u.value=String(r.default));let o=document.createElement("div");o.className="voc-form-timezone-control",o.style.position="relative",o.style.display="inline-block",o.style.width=r.width||"100%";let d=document.createElement("button");d.type="button",d.className="voc-form-timezone-toggle",d.setAttribute("aria-haspopup","listbox"),d.setAttribute("aria-expanded","false"),d.style.position="absolute",d.style.right="4px",d.style.top="50%",d.style.transform="translateY(-50%)",d.style.height="28px",d.style.width="28px",d.style.padding="0",d.style.border="none",d.style.background="transparent",d.style.cursor="pointer",d.innerHTML="\u25BC";let p=document.createElement("ul");p.className="voc-form-timezone-list",p.setAttribute("role","listbox"),p.style.position="absolute",p.style.left="0",p.style.right="0",p.style.zIndex="1000",p.style.maxHeight="200px",p.style.overflow="auto",p.style.margin="4px 0 0 0",p.style.padding="0",p.style.listStyle="none",p.style.background="white",p.style.border="1px solid rgba(0,0,0,0.15)",p.style.display="none",p.tabIndex=-1,u.style.paddingRight="36px";let w=["UTC","ETC","AEST","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Vancouver","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Amsterdam","Asia/Tokyo","Asia/Shanghai","Asia/Singapore","Asia/Kolkata","Asia/Dubai","Australia/Lindeman","Australia/Brisbane","Australia/Sydney","Australia/Melbourne","Australia/Hobart","Australia/Currie","Australia/Broken_Hill","Australia/Lord_Howe","Australia/Adelaide","Australia/Darwin","Australia/Perth","Australia/Eucla","Australia/ACT","ACT","Pacific/Auckland","America/Sao_Paulo","America/Mexico_City","Africa/Cairo","Africa/Johannesburg"];function k(t){p.innerHTML="",t.forEach((a,i)=>{let s=document.createElement("li");s.className="voc-form-timezone-item",s.setAttribute("role","option"),s.dataset.value=a,s.style.padding="6px 8px",s.style.cursor="pointer",s.textContent=a,s.addEventListener("mousedown",l=>{l.preventDefault(),u.value=a,n(),u.dispatchEvent(new Event("change",{bubbles:!0}))}),p.appendChild(s)})}k(w);let e=-1;function c(){Array.from(p.children).forEach((a,i)=>{i===e?(a.style.background="rgba(0,123,255,0.1)",a.setAttribute("aria-selected","true")):(a.style.background="",a.removeAttribute("aria-selected"))})}function h(){p.style.display="block",d.setAttribute("aria-expanded","true")}function n(){p.style.display="none",d.setAttribute("aria-expanded","false"),e=-1,c()}function m(){p.style.display==="none"?h():n()}u.addEventListener("input",()=>{let t=(u.value||"").trim().toLowerCase(),a=t?w.filter(i=>i.toLowerCase().includes(t)):w;k(a),h()}),d.addEventListener("click",t=>{t.preventDefault(),p.style.display==="none"?(k(w),h(),u.focus()):n()}),u.addEventListener("keydown",t=>{let a=Array.from(p.children);if(t.key==="ArrowDown"){if(t.preventDefault(),a.length===0)return;e=Math.min(e+1,a.length-1),c(),a[e].scrollIntoView({block:"nearest"})}else if(t.key==="ArrowUp"){if(t.preventDefault(),a.length===0)return;e=Math.max(e-1,0),c(),a[e].scrollIntoView({block:"nearest"})}else if(t.key==="Enter"){if(p.style.display!=="none"&&e>=0){t.preventDefault();let i=a[e];u.value=i.dataset.value||i.textContent||"",n(),u.dispatchEvent(new Event("change",{bubbles:!0}))}}else t.key==="Escape"&&n()}),document.addEventListener("click",t=>{o.contains(t.target)||n()});let y={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(u.addEventListener("blur",()=>{let t=(u.value||"").trim();if(!t)return;let a=Object.keys(y).find(i=>i.toLowerCase()===t.toLowerCase());a&&(u.value=y[a])}),r.description){let t=document.createElement("div");t.className="voc-form-timezone-description",C&&t.classList.add("form-text"),t.textContent=r.description,f.appendChild(t)}return o.appendChild(u),o.appendChild(d),o.appendChild(p),f.appendChild(o),f}function J(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-tags";let b=r.name||r.key||`tags_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("div");u.className="voc-form-tags-container",u.style.display="flex",u.style.flexWrap="wrap",u.style.gap="6px",u.style.alignItems="center",u.style.padding="6px",u.style.border="1px solid rgba(0,0,0,0.12)",u.style.borderRadius="4px";let o=document.createElement("input");o.type="text",o.className="voc-form-tags-input",o.style.border="none",o.style.flex="1 0 120px",o.style.minWidth="80px",o.style.outline="none",o.placeholder=r.placeholder||"",C&&o.classList.add("form-control"),u.appendChild(o);let d=[],p=document.createElement("input");p.type="text",p.style.position="absolute",p.style.left="-9999px",p.style.width="1px",p.style.height="1px",p.tabIndex=-1,r.required&&(p.required=!0),f.appendChild(p);function E(){Array.from(f.querySelectorAll("input.voc-form-tag-hidden")).forEach(h=>h.parentElement?.removeChild(h)),d.forEach(h=>{let n=document.createElement("input");n.type="hidden",n.name=`${b}[]`,n.className="voc-form-tag-hidden",n.value=h,r.key&&(n.id=`voc-form-${r.key}`),f.appendChild(n)}),r.required&&(d.length===0?(p.value="",p.setCustomValidity("Please enter at least one tag")):(p.value="1",p.setCustomValidity("")))}function w(c){let h=document.createElement("span");h.className="voc-form-tag",h.style.display="inline-flex",h.style.alignItems="center",h.style.padding="4px 8px",h.style.background="rgba(0,0,0,0.05)",h.style.borderRadius="16px";let n=document.createElement("span");n.textContent=c,n.style.marginRight="8px",h.appendChild(n);let m=document.createElement("button");return m.type="button",m.textContent="\xD7",m.style.border="none",m.style.background="transparent",m.style.cursor="pointer",m.addEventListener("click",()=>{let y=d.indexOf(c);y>=0&&(d.splice(y,1),u.removeChild(h),E())}),h.appendChild(m),h}function k(c){let h=c.trim();if(!h||d.includes(h))return;d.push(h);let n=w(h);u.insertBefore(n,o),E()}let e=v!=null?String(v):r.default||"";return e&&e.split(",").map(c=>c.trim()).filter(Boolean).forEach(k),o.addEventListener("keydown",c=>{if(c.key==="Enter"||c.key===",")c.preventDefault(),k(o.value),o.value="";else if(c.key==="Backspace"&&o.value===""&&d.pop()){let n=Array.from(u.querySelectorAll(".voc-form-tag")),m=n[n.length-1];m&&u.removeChild(m),E()}}),o.addEventListener("paste",c=>{let h=c.clipboardData?.getData("text");h&&(c.preventDefault(),h.split(/[,\n\r]+/).map(n=>n.trim()).filter(Boolean).forEach(k),o.value="")}),f.getTags=()=>d.slice(),f.addTag=k,f.appendChild(u),E(),f}function Y(r,L,v,C){let f=L?.style==="bootstrap",b=document.createElement("div");b.className="voc-form-field-selects";let u=document.createElement("div");if(u.className="voc-form-field-selects-header",f&&u.classList.add("mb-2"),r.label){let m=document.createElement("div");if(m.className="voc-form-field-selects-label",f&&m.classList.add("form-label"),m.textContent=r.label,r.required){let y=document.createElement("span");y.className="voc-form-required",y.textContent="*",m.appendChild(y)}u.appendChild(m)}if(r.description){let m=document.createElement("div");m.className="voc-form-field-selects-description",f&&m.classList.add("form-text"),m.textContent=r.description,u.appendChild(m)}b.appendChild(u);let o=document.createElement("div");o.className="voc-form-field-selects-search-wrapper";let d=document.createElement("input");d.type="search",d.placeholder="Search...",d.className="voc-form-field-selects-search",f&&d.classList.add("form-control","mb-2"),o.appendChild(d),b.appendChild(o);let p=r.options;if(!p||p.length===0)return b;let E=document.createElement("div");E.className="voc-form-field-selects-list",f&&E.classList.add("list-group");let w=document.createElement("div");w.className="voc-form-field-selects-selected",w.style.marginTop="12px";let k={},e=r.name||r.key||`users_${Math.random().toString(36).substr(2,6)}`,c=[];if(Array.isArray(v)?c=v:v!=null?c=[v]:Array.isArray(r.default)&&(c=r.default),p.forEach((m,y)=>{let t=document.createElement("div");t.className="voc-form-field-selects-item",t.dataset.label=String(m.option_label??m.label??"").toLowerCase(),t.dataset.email=String(m.email||"").toLowerCase(),t.dataset.value=String(m.value||"").toLowerCase(),f&&t.classList.add("d-flex","align-items-center","gap-2");let a=document.createElement("input");if(a.type="checkbox",a.name=`${e}[]`,a.value=m.value??m.key,a.className="voc-form--checkbox",r.key&&(a.id=`voc-form-${r.key}-${y}`),a.style.position="absolute",a.style.width="1px",a.style.height="1px",a.style.margin="0",a.style.padding="0",a.style.clip="rect(0 0 0 0)",a.style.clipPath="inset(50%)",a.style.overflow="hidden",a.style.border="0",c&&Array.isArray(c)){let N=c.map(g=>String(g)),x=String(m.value??m.key);a.checked=N.includes(x)}let i=m.icon||'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M14 11c0 .55-.45 1-1 1H4c-.55 0-1-.45-1-1s.45-1 1-1h9c.55 0 1 .45 1 1M3 7c0 .55.45 1 1 1h9c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1m7 8c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1m8.01-2.13l.71-.71a.996.996 0 0 1 1.41 0l.71.71c.39.39.39 1.02 0 1.41l-.71.71zm-.71.71l-5.16 5.16c-.09.09-.14.21-.14.35v1.41c0 .28.22.5.5.5h1.41c.13 0 .26-.05.35-.15l5.16-5.16z"/></svg>',s=document.createElement("div");s.className="voc-form-fields-select-avatar",s.innerHTML=i;let l=document.createElement("div");l.className="voc-form-field-select-info",l.style.display="flex",l.style.flexDirection="column",l.style.gap="2px";let A=document.createElement("div");A.className="voc-form-field-select-label",A.textContent=(m.option_label??m.label)||String(m.value);let S=document.createElement("small");S.className="voc-form-field-select-email",S.textContent=m.email||"",l.appendChild(A),l.appendChild(S),t.addEventListener("click",N=>{let x=N.target;x&&(x.closest("input")||x.closest("a")||x.closest("button"))||(a.checked=!a.checked,a.dispatchEvent(new Event("change",{bubbles:!0})))}),a.addEventListener("change",()=>{if(a.checked){t.classList.add("selected"),(k[y]||[]).forEach(g=>g.parentElement?.removeChild(g)),k[y]=[];let x=m;if(x&&Array.isArray(x.items))x.items.forEach(g=>{let F=C(g);F&&(w.appendChild(F),k[y].push(F))});else if(x&&(x.type||x.key)){let g=C(x);g&&(w.appendChild(g),k[y].push(g))}}else t.classList.remove("selected"),(k[y]||[]).forEach(x=>x.parentElement?.removeChild(x)),k[y]=[]}),a.checked&&(t.classList.add("selected"),setTimeout(()=>{let N=m;if(N&&Array.isArray(N.items))N.items.forEach(x=>{let g=C(x);g&&(w.appendChild(g),k[y]=k[y]||[],k[y].push(g))});else if(N&&(N.type||N.key)){let x=C(N);x&&(w.appendChild(x),k[y]=k[y]||[],k[y].push(x))}},0)),t.appendChild(a),t.appendChild(s),t.appendChild(l),E.appendChild(t)}),b.appendChild(E),b.appendChild(w),r.required){let m=E.querySelectorAll('input[type="checkbox"]'),y=()=>{let t=Array.from(m).some(a=>a.checked);return m.forEach(a=>{t?a.setCustomValidity(""):a.setCustomValidity("At least one option must be selected.")}),t};m.forEach(t=>{t.addEventListener("change",y)}),b._validateCheckboxGroup=y,y()}let h=Array.from(E.querySelectorAll(".voc-form-field-select-item")),n=()=>{let m=String(d.value||"").trim().toLowerCase();if(!m){h.forEach(y=>y.style.setProperty("display","flex","important"));return}h.forEach(y=>{let t=y.dataset.label||"",a=y.dataset.email||"",i=y.dataset.value||"",s=t.includes(m)||a.includes(m)||i.includes(m);y.style.setProperty("display",s?"flex":"none","important")})};return d.addEventListener("input",n),b}function I(r,L=!0){let v=new FormData(r);if(L)return le(v);let C={};return v.forEach((f,b)=>{let u=(f instanceof File,f);Object.prototype.hasOwnProperty.call(C,b)?Array.isArray(C[b])?C[b].push(u):C[b]=[C[b],u]:C[b]=u}),C}function le(r){let L=new FormData;for(let[v,C]of r.entries()){if(C instanceof File){L.append(v,C);continue}let f;try{f=JSON.parse(C)}catch{f=null}Array.isArray(f)?f.length===0?L.append(v,"[]"):f.every(b=>typeof b=="object"&&b!==null)?f.forEach((b,u)=>{for(let[o,d]of Object.entries(b))L.append(`${v}[${u}][${o}]`,d)}):L.append(v,C):L.append(v,C)}return L}async function K(r,L,v){let C=L.url,f={"Content-Type":"application/json"};L?.api_token&&(f.Authorization=`Bearer ${L.api_token}`);let b=I(r);if(L?.additional_data)for(let[d,p]of Object.entries(L.additional_data))b.append(d,p);let u,o=b instanceof FormData;u={method:"POST",headers:{Authorization:`Bearer ${L.api_token}`,...o?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:o?b:JSON.stringify(Object.fromEntries(b.entries()))};try{fetch(C,u).then(async d=>{let p=d.headers.get("content-type");if(!d.ok)try{let w=(await d.json())?.message;throw new Error(w??"Their was an error submitting the form. Check your form and try again.")}catch(E){throw new Error(E.message)}return p&&p.includes("application/json")?d.json():d.text()}).then(d=>{v&&v(d,null)}).catch(d=>{v&&v(null,d)})}catch(d){v&&v(null,d)}}function Q(r,L,v){let C=[];if(typeof r=="string"?C=Array.from(document.querySelectorAll(r)):C=[r],C.length===0)return null;function f(){let o=v?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),o&&d.classList.add("needs-validation"),d.id=L.id;let p=document.createElement("h2");p.className="voc-form-title",o&&p.classList.add("mb-3"),p.textContent=L.form_name,d.appendChild(p);function E(e,c){c&&(c.min_length!==void 0&&(e.minLength=c.min_length),c.max_length!==void 0&&(e.maxLength=c.max_length),c.regex&&(e instanceof HTMLInputElement?e.pattern=c.regex:e.dataset.pattern=c.regex))}function w(e){if(!e.key&&!e.label)return null;let c=L.default_values||{},h=e.name||e.key,n=h?c[h]:void 0,m=document.createElement("div");if(m.className="voc-form-group",o&&m.classList.add("mb-3"),e.label&&e.type!=="users"){let t=document.createElement("label");if(t.classList.add("voc-form-label"),o&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label,e.required){let a=document.createElement("span");a.className="voc-form-required",a.textContent="*",t.appendChild(a)}m.appendChild(t)}let y=null;switch(e.type){case"tags":{y=J(e,v||{},n);break}case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options){if(e.options.forEach((a,i)=>{let s=document.createElement("label");s.classList.add("voc-form-checkbox-label"),o&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let l=document.createElement("input");l.type="checkbox",l.classList.add("voc-form-checkbox"),o&&l.classList.add("form-check-input"),l.name=`${e.name||e.key||""}[]`,l.value=a.value,e.key&&(l.id=`voc-form-${e.key}-${i}`),Array.isArray(n)?n.includes(a.value)&&(l.checked=!0):n!==void 0?n===a.value&&(l.checked=!0):e.default===a.value&&(l.checked=!0),s.appendChild(l),s.appendChild(document.createTextNode(a.label)),t.appendChild(s)}),e.required){let a=t.querySelectorAll('input[type="checkbox"]'),i=()=>{let s=Array.from(a).some(l=>l.checked);return a.forEach(l=>{s?l.setCustomValidity(""):l.setCustomValidity("At least one option must be selected.")}),s};a.forEach(s=>{s.addEventListener("change",i)}),t._validateCheckboxGroup=i,i()}}else{let a=document.createElement("label");a.classList.add("voc-form-checkbox-label"),o&&a.classList.add("form-check"),e.width&&(a.style.width=e.width);let i=document.createElement("input");i.type="checkbox",i.classList.add("voc-form-checkbox"),(e.key||e.name)&&(i.name=e.name||e.key,e.key&&(i.id=`voc-form-${e.key}`)),o&&i.classList.add("form-check-input"),e.required&&(i.required=!0),n!==void 0?i.checked=!!n:e.default&&(i.checked=!!e.default),a.appendChild(i),a.appendChild(document.createTextNode(e.label||"")),t.appendChild(a)}y=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),n!=null?t.value=String(n):e.default!==void 0&&e.default!==null&&(t.value=String(e.default));let a=e.default||n||"";if(a){let i=(a.match(/\n/g)||[]).length,s=80,l=a.split(`
2
+ `).reduce((N,x)=>Math.max(N,x.length),0),A=Math.ceil(l/s)||1,S=Math.max(2,i+A);t.rows=S,t.style.resize="vertical"}e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),y=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),o&&t.classList.add("form-select"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let a=document.createElement("option");a.value="",a.textContent=e.placeholder,a.disabled=!0,a.selected=!0,t.appendChild(a)}e.required&&(t.required=!0),e.options&&e.options.forEach(a=>{let i=document.createElement("option");i.value=a.value,i.textContent=a.label,Array.isArray(n)?n.includes(a.value)&&(i.selected=!0):n!==void 0?n===a.value&&(i.selected=!0):e.default===a.value&&(i.selected=!0),t.appendChild(i)}),e.width&&(t.style.width=e.width),y=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((a,i)=>{let s=document.createElement("label");s.classList.add("voc-form-radio-label"),o&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let l=document.createElement("input");l.type="radio",l.classList.add("voc-form-radio"),o&&l.classList.add("form-check-input"),l.name=e.name||e.key||"",l.value=a.value,e.key&&(l.id=`voc-form-${e.key}-${i}`),Array.isArray(n)?n.includes(a.value)&&(l.checked=!0):n!==void 0?n===a.value&&(l.checked=!0):e.default===a.value&&(l.checked=!0),s.appendChild(l),s.appendChild(document.createTextNode(a.label)),t.appendChild(s)}),y=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let a=document.createElement("input");a.type="file",a.classList.add("voc-form-file"),o&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.width&&(a.style.width=e.width),e.required&&(a.required=!0),e.accept&&(a.accept=e.accept),e.multiple&&(a.multiple=!0),t.appendChild(a),y=t;break}case"avatar":{y=j(e,v||{},n);break}case"table":{y=G(e,v||{},n);break}case"users":{y=U(e,v||{},n);break}case"timezone":{y=V(e,v||{},n);break}case"audio_select":{y=W(e,v||{},n);break}case"field-select":{y=Y(e,v||{},n,w);break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),n!=null?t.value=String(n):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),y=t;break}}if(y&&m.appendChild(y),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,m.appendChild(t)}return m}L.fields.forEach(e=>{if(e.type==="group"&&"items"in e){let c=e;if(o){let h=document.createElement("div");h.className="card voc-form-group-card mb-3";let n=c.label||c.header?.title,m=c.description||c.header?.description;if(n||m){let t=document.createElement("div");if(t.className="card-header voc-form-group-head",n){let a=document.createElement("h5");a.className="mb-0 voc-form-group-label",a.textContent=n,t.appendChild(a)}if(m){let a=document.createElement("p");a.className="mb-0 voc-form-group-description",a.textContent=m,t.appendChild(a)}h.appendChild(t)}let y=document.createElement("div");y.className="card-body voc-form-group-body",c.items.forEach(t=>{if(t.type==="row"&&"items"in t){let a=t,i=document.createElement("div");if(i.className="voc-form-group voc-form-row mb-3",a.label){let l=document.createElement("h6");l.className="voc-form-row-label",l.textContent=a.label,i.appendChild(l)}let s=document.createElement("div");s.className="voc-form-row-items "+(a.direction||"horizontal"),a.items.forEach(l=>{let A=w(l);A&&s.appendChild(A)}),i.appendChild(s),y.appendChild(i)}else{let a=w(t);a&&y.appendChild(a)}}),h.appendChild(y),d.appendChild(h)}else{let h=document.createElement("div");h.className="voc-form-group voc-form-group-wrapper",o&&h.classList.add("mb-3");let n=c.label||c.header?.title,m=c.description||c.header?.description;if(n||m){let y=document.createElement("div");if(y.className="voc-form-group-head",n){let t=document.createElement("h3");t.className="voc-form-group-label",t.textContent=n,y.appendChild(t)}if(m){let t=document.createElement("p");t.className="voc-form-group-description",t.textContent=m,y.appendChild(t)}h.appendChild(y)}c.items.forEach(y=>{if(y.type==="row"&&"items"in y){let t=y,a=document.createElement("div");if(a.className="voc-form-group voc-form-row",o&&a.classList.add("mb-3"),t.label){let s=document.createElement("h4");s.className="voc-form-row-label",s.textContent=t.label,a.appendChild(s)}let i=document.createElement("div");i.className="voc-form-row-items "+(t.direction||"horizontal"),t.items.forEach(s=>{let l=w(s);l&&i.appendChild(l)}),a.appendChild(i),h.appendChild(a)}else{let t=w(y);t&&h.appendChild(t)}}),d.appendChild(h)}return}if(e.type==="row"&&"items"in e){let c=document.createElement("div");if(c.className="voc-form-group voc-form-row",o&&c.classList.add("mb-3"),e.label){let n=document.createElement("h3");n.className="voc-form-row-label",n.textContent=e.label,c.appendChild(n)}if(e.description){let n=document.createElement("p");n.className="voc-form-row-description",n.textContent=e.description,c.appendChild(n)}let h=document.createElement("div");h.className="voc-form-row-items "+(e.direction||"horizontal"),c.appendChild(h),e.items.forEach(n=>{let m=w(n);m&&h.appendChild(m)}),d.appendChild(c)}else{let c=w(e);c&&d.appendChild(c)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",o&&k.classList.add("btn","btn-primary"),d.appendChild(k),d}let b=f();C[0].appendChild(b);let u=L?.submit_config??v?.submit_config??null;return u&&b.addEventListener("submit",o=>{o.preventDefault();let d=Array.from(b.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),p=[];if(d.forEach(k=>{k&&typeof k._validateCheckboxGroup=="function"&&(k._validateCheckboxGroup()||k.querySelector('input[type="checkbox"]')&&p.push("Please select at least one option"))}),!b.checkValidity()){b.reportValidity(),v?.onSubmitResult&&v.onSubmitResult(null,new Error("Form validation failed"));return}let E=Array.from(b.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),w=[];if(E.forEach(k=>{if(k&&typeof k.validate=="function"){let e=k.validate();e&&e.length&&w.push(...e)}}),w.length){v?.onSubmitResult&&v.onSubmitResult(null,new Error(w.join("; ")));let k=E[0];k&&k.scrollIntoView({behavior:"smooth",block:"center"});return}if(v?.onSubmit){let k=I(b);v.onSubmit(k)}K(b,u,(k,e)=>{v?.onSubmitResult&&v.onSubmitResult(k,e)})}),{element:b,validate:()=>{let o=[];return b.querySelectorAll(":invalid").forEach(p=>{let E=p.validationMessage;o.push({element:p,message:E})}),o},getValues:()=>I(b),onSubmit:o=>{b.addEventListener("submit",d=>{d.preventDefault();let p=I(b);o(p,d)})}}}var z={renderForm:Q};var ce=z,de={FormsLib:z};return se(me);})();
package/dist/main.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var G=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(r,x)=>{for(var f in x)G(r,f,{get:x[f],enumerable:!0})},se=(r,x,f,k)=>{if(x&&typeof x=="object"||typeof x=="function")for(let h of ae(x))!ne.call(r,h)&&h!==f&&G(r,h,{get:()=>x[h],enumerable:!(k=te(x,h))||k.enumerable});return r};var oe=r=>se(G({},"__esModule",{value:!0}),r);var ue={};re(ue,{FormsLib:()=>de,default:()=>me});module.exports=oe(ue);function U(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-avatar-wrapper",k&&h.classList.add("d-flex","align-items-center","gap-3");let v=document.createElement("img");v.className="voc-form-avatar-preview",v.alt=r.label||"avatar",k&&(v.classList.add("img-thumbnail","rounded-circle"),v.style.width=v.style.height="64px",v.style.objectFit="cover");let u=f!=null?String(f):r.default!==void 0&&r.default!==null?String(r.default):"";u?v.src=u:(v.src="",v.style.display="none");let i=document.createElement("input");i.type="file",i.accept=r.accept||"image/*",i.className="voc-form-avatar-input",k&&i.classList.add("form-control"),(r.key||r.name)&&(i.name=r.name||r.key,r.key&&(i.id=`voc-form-${r.key}`));let d=document.createElement("input");if(d.type="hidden",(r.key||r.name)&&(d.name=(r.name||r.key)+"_url"),d.value=u||"",i.addEventListener("change",p=>{let g=p.target;if(g.files&&g.files.length>0){let T=g.files[0],L=new FileReader;L.onload=()=>{v.src=String(L.result),v.style.display="",d.value=""},L.readAsDataURL(T)}}),k){let p=document.createElement("div");p.style.flex="1",p.appendChild(i),p.appendChild(d),h.appendChild(v),h.appendChild(p)}else h.appendChild(v),h.appendChild(i),h.appendChild(d);return h}function J(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");if(h.className="voc-form-audio-select",!r.options||r.options.length===0)return h;let v=r.name||r.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,u;return Array.isArray(f)?u=f[0]:f!==void 0?u=f:r.default!==void 0&&(u=r.default),r.options.forEach((i,d)=>{let p=document.createElement("div");p.className="voc-form-audio-item",k&&p.classList.add("form-check");let g=document.createElement("input");g.type="radio",g.name=v,g.value=i.value,g.className="voc-form-audio-radio",r.key&&(g.id=`voc-form-${r.key}-${d}`),r.required&&d===0&&(g.required=!0),g.style.position="absolute",g.style.width="1px",g.style.height="1px",g.style.margin="0",g.style.padding="0",g.style.clip="rect(0 0 0 0)",g.style.clipPath="inset(50%)",g.style.overflow="hidden",g.style.border="0",u!==void 0&&(Array.isArray(u)?g.checked=u.includes(i.value):g.checked=String(u)===String(i.value));let T=()=>{g.checked?p.classList.add("selected"):p.classList.remove("selected")};g.addEventListener("change",()=>{h.querySelectorAll(".voc-form-audio-item").forEach(n=>n.classList.remove("selected")),T()}),g.checked&&p.classList.add("selected");let L=document.createElement("label");L.className="voc-form-audio-label",k&&L.classList.add("form-check-label"),L.htmlFor=g.id||"",L.textContent=i.label||i.value,L.tabIndex=0;let e=document.createElement("div");e.className="voc-form-audio-control";let l=null;if(i.audio_link){let t=document.createElement("button");t.type="button",t.className="voc-form-audio-play",k&&t.classList.add("btn","btn-sm","btn-outline-secondary"),t.setAttribute("aria-label",`Play ${i.label||i.value}`);let n="http://www.w3.org/2000/svg",o=document.createElementNS(n,"svg");o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("width","16"),o.setAttribute("height","16"),o.setAttribute("aria-hidden","true");let s=document.createElementNS(n,"path");s.setAttribute("d","M8 5v14l11-7z"),s.setAttribute("fill","currentColor"),o.appendChild(s),t.appendChild(o),l=document.createElement("audio"),l.src=i.audio_link,l.preload="none",l.style.display="none";let c=y=>{for(;y.firstChild;)y.removeChild(y.firstChild)},N=()=>{let y="http://www.w3.org/2000/svg",$=document.createElementNS(y,"svg");$.setAttribute("viewBox","0 0 24 24"),$.setAttribute("width","16"),$.setAttribute("height","16"),$.setAttribute("aria-hidden","true");let q=document.createElementNS(y,"path");return q.setAttribute("d","M8 5v14l11-7z"),q.setAttribute("fill","currentColor"),$.appendChild(q),$},S=()=>{let y="http://www.w3.org/2000/svg",$=document.createElementNS(y,"svg");$.setAttribute("viewBox","0 0 24 24"),$.setAttribute("width","16"),$.setAttribute("height","16"),$.setAttribute("aria-hidden","true");let q=document.createElementNS(y,"rect");return q.setAttribute("x","6"),q.setAttribute("y","6"),q.setAttribute("width","12"),q.setAttribute("height","12"),q.setAttribute("fill","currentColor"),$.appendChild(q),$};c(t),t.appendChild(N());let M=y=>{c(t),y?(t.appendChild(S()),t.setAttribute("aria-label",`Stop ${i.label||i.value}`)):(t.appendChild(N()),t.setAttribute("aria-label",`Play ${i.label||i.value}`))};t.addEventListener("click",()=>{try{if(!l)return;let y=h.querySelectorAll("audio");if(!l.paused&&!l.ended){l.pause(),l.currentTime=0;return}y.forEach(q=>{try{q.pause(),q.currentTime=0}catch{}}),h.querySelectorAll(".voc-form-audio-item").forEach(q=>q.classList.remove("is-playing")),l.play()}catch(y){console.warn("audio play failed",y)}}),l.addEventListener("playing",()=>{p.classList.add("is-playing"),M(!0)});let _=()=>{p.classList.remove("is-playing"),M(!1)};l.addEventListener("pause",_),l.addEventListener("ended",_),e.appendChild(t),e.appendChild(l)}let m=document.createElement("div");m.className="voc-form-item-detail",m.style.display="flex",m.style.flexDirection="column",m.style.gap="4px";let a=document.createElement("div");a.className="voc-form-item-top",a.style.display="flex",a.style.alignItems="center",a.style.gap="8px",a.appendChild(g),a.appendChild(L);let E=document.createElement("div");E.className="voc-form-item-description";let w=i.description||i.hint_text||"";w&&(E.textContent=w),m.appendChild(a),m.appendChild(E),e.appendChild(m),p.appendChild(e),a.addEventListener("click",t=>{let n=t.target;n&&n.closest(".voc-form-audio-play")||(g.checked=!0,g.dispatchEvent(new Event("change",{bubbles:!0})))}),p.addEventListener("click",t=>{let n=t.target;n&&n.closest(".voc-form-audio-play")||(g.checked=!0,g.dispatchEvent(new Event("change",{bubbles:!0})))}),h.appendChild(p)}),h}function Y(r,x,f){let k=document.createElement("div");k.className="voc-form-table-wrapper";let h=x?.style==="bootstrap",v=document.createElement("input");v.type="hidden",v.name=r.name||r.key,r.key&&(v.id=`voc-form-${r.key}`),k.appendChild(v);let u=document.createElement("table");u.className="voc-form-table",h&&u.classList.add("table","table-bordered");let i=document.createElement("thead"),d=document.createElement("tr"),p=document.createElement("th");p.className="voc-form-table-drag-col",p.textContent="",d.appendChild(p),(r.fields||[]).forEach(n=>{let o=document.createElement("th");o.textContent=n.label||n.key,d.appendChild(o)});let g=document.createElement("th");g.textContent="Actions",d.appendChild(g),i.appendChild(d),u.appendChild(i);let T=document.createElement("tbody");u.appendChild(T),k.appendChild(u);let L=document.createElement("button");L.type="button",L.className="voc-form-table-add",h&&L.classList.add("btn","btn-secondary"),L.textContent="+Add";let e=document.createElement("tfoot"),l=document.createElement("tr"),m=document.createElement("td");m.colSpan=(r.fields?r.fields.length:0)+1,m.appendChild(L),l.appendChild(m),e.appendChild(l),u.appendChild(e),k.appendChild(u);let a=[];function E(){v.value=JSON.stringify(a)}function w(n){let o=[];return r.fields.forEach(s=>{let c=n[s.key];if(s.type==="checkbox"){let N=Array.isArray(c)?c:c?[c]:[];s.required&&N.length===0&&o.push(`${s.label||s.key} is required`);return}s.required&&(c==null||String(c).trim()==="")&&o.push(`${s.label||s.key} is required`),s.type==="email"&&c&&(/^\S+@\S+\.\S+$/.test(String(c))||o.push(`${s.label||s.key} must be a valid email`)),s.type==="number"&&c&&isNaN(Number(c))&&o.push(`${s.label||s.key} must be a number`),s.validation&&s.validation.regex&&c&&(new RegExp(s.validation.regex).test(String(c))||o.push(`${s.label||s.key} invalid format`))}),o}function t(){T.innerHTML="";let n=(o,s)=>{s.draggable=!0,s.addEventListener("mousedown",()=>{s.style.cursor="grabbing"}),s.addEventListener("mouseup",()=>{s.style.cursor="grab"}),s.addEventListener("dragstart",c=>{let N=Number(o.dataset.rowIndex);c.dataTransfer.setData("text/plain",String(N)),o.classList.add("dragging");try{c.dataTransfer?.setDragImage(s,10,10)}catch{}}),s.addEventListener("dragend",()=>{o.classList.remove("dragging"),s.style.cursor="grab"}),o.addEventListener("dragover",c=>{c.preventDefault();let N=c.currentTarget,S=N.getBoundingClientRect(),M=S.top+S.height/2,_=(c.clientY||c.y)>M;N.classList.remove("drag-over-top","drag-over-bottom"),_?(N.classList.add("drag-over-bottom"),N.dataset.dropPosition="after"):(N.classList.add("drag-over-top"),N.dataset.dropPosition="before")}),o.addEventListener("dragleave",c=>{let N=c.currentTarget;N.classList.remove("drag-over-top","drag-over-bottom"),delete N.dataset.dropPosition}),o.addEventListener("drop",c=>{c.preventDefault();let N=c.dataTransfer.getData("text/plain"),S=Number(c.currentTarget.dataset.rowIndex),M=Number(N),_=c.currentTarget.dataset.dropPosition||"before";if(isNaN(M)||isNaN(S))return;let[y]=a.splice(M,1),$=S;M<S&&($=S-1);let q=_==="after"?$+1:$;a.splice(q,0,y),c.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete c.currentTarget.dataset.dropPosition,t(),E()})};a.forEach((o,s)=>{let c=document.createElement("tr");c.dataset.rowIndex=String(s),c.classList.add("voc-form-table-row");let N=document.createElement("td");N.className="voc-form-table-drag-handle";let S=document.createElement("span");S.className="voc-form-drag-handle-icon",S.textContent="\u2630",S.style.cursor="grab",N.appendChild(S),c.appendChild(N),n(c,S),r.fields.forEach(y=>{let $=document.createElement("td"),q,A=(y.type||"text").toLowerCase();if(A==="select"){let b=document.createElement("select");if(b.className="voc-form-table-cell",h&&b.classList.add("form-control"),y.placeholder){let C=document.createElement("option");C.value="",C.textContent=y.placeholder,C.disabled=!0,(o[y.key]===void 0||o[y.key]===null||o[y.key]==="")&&(C.selected=!0),b.appendChild(C)}(y.options||[]).forEach(C=>{let O=document.createElement("option");O.value=C.value,O.textContent=C.label,b.appendChild(O)}),b.value=o[y.key]!==void 0&&o[y.key]!==null?String(o[y.key]):"",y.required&&(b.required=!0),b.addEventListener("change",C=>{a[s][y.key]=C.target.value,E()}),q=b}else if(A==="checkbox"){let b=document.createElement("div");b.className="voc-form-table-checkboxes",h&&b.classList.add("form-check");let F=y.options||[];Array.isArray(a[s][y.key])||(a[s][y.key]=a[s][y.key]?[a[s][y.key]]:[]),F.forEach(C=>{let O=`voc-form-${r.key}-${y.key}-${s}-${C.value}`,B=document.createElement("div");B.className="voc-form-table-checkbox-item",h&&B.classList.add("form-check");let H=document.createElement("input");H.type="checkbox",H.className="voc-form-table-cell",h&&H.classList.add("form-check-input"),H.id=O,H.value=C.value,H.checked=Array.isArray(a[s][y.key])&&a[s][y.key].includes(C.value),H.addEventListener("change",z=>{let I=z.target.checked;Array.isArray(a[s][y.key])||(a[s][y.key]=[]),I?a[s][y.key].includes(C.value)||a[s][y.key].push(C.value):a[s][y.key]=a[s][y.key].filter(R=>R!==C.value),E()});let D=document.createElement("label");D.htmlFor=O,D.className="voc-form-table-checkbox-label",h&&D.classList.add("form-check-label"),D.textContent=C.label,B.appendChild(H),B.appendChild(D),b.appendChild(B)}),q=b}else if(A==="radio"){let b=document.createElement("div");b.className="voc-form-table-radios",h&&b.classList.add("form-check");let F=y.options||[];a[s][y.key]===void 0&&(a[s][y.key]=""),F.forEach(C=>{let O=`voc-form-${r.key}-${y.key}-${s}-${C.value}`,B=document.createElement("div");B.className="voc-form-table-radio-item",h&&B.classList.add("form-check");let H=document.createElement("input");H.type="radio",H.className="voc-form-table-cell",h&&H.classList.add("form-check-input"),H.id=O,H.name=`voc-form-${r.key}-${y.key}-${s}`,H.value=C.value,H.checked=a[s][y.key]===C.value,H.addEventListener("change",z=>{z.target.checked&&(a[s][y.key]=z.target.value,E())});let D=document.createElement("label");D.htmlFor=O,D.className="voc-form-table-radio-label",h&&D.classList.add("form-check-label"),D.textContent=C.label,B.appendChild(H),B.appendChild(D),b.appendChild(B)}),q=b}else{let b=document.createElement("input");A==="number"?b.type="number":A==="email"?b.type="email":A==="tel"?b.type="tel":A==="url"?b.type="url":A==="date"?b.type="date":b.type="text",b.value=o[y.key]!==void 0&&o[y.key]!==null?String(o[y.key]):"",y.placeholder&&(b.placeholder=y.placeholder),y.required&&(b.required=!0),b.className="voc-form-table-cell",h&&b.classList.add("form-control"),b.addEventListener("input",F=>{a[s][y.key]=F.target.value,E()}),q=b}$.appendChild(q),c.appendChild($)});let M=document.createElement("td"),_=document.createElement("button");_.type="button",_.className="voc-form-table-remove",h&&_.classList.add("btn","btn-danger"),_.textContent="Remove",_.addEventListener("click",()=>{a.splice(s,1),t(),E()}),M.appendChild(_),c.appendChild(M),T.appendChild(c)})}return L.addEventListener("click",()=>{if(r.validation?.max_rows!==void 0&&a.length>=r.validation.max_rows)return;let n={};r.fields.forEach(o=>n[o.key]=""),a.push(n),t(),E()}),Array.isArray(f)&&f.length?a=f.map(n=>({...n})):r.default&&Array.isArray(r.default)&&(a=r.default.map(n=>({...n}))),t(),E(),k.validate=function(){let n=[];return a.forEach((o,s)=>{let c=w(o);c.length&&n.push(`Row ${s+1}: ${c.join("; ")}`)}),r.validation?.min_rows!==void 0&&a.length<r.validation.min_rows&&n.push(`At least ${r.validation.min_rows} rows required`),r.validation?.max_rows!==void 0&&a.length>r.validation.max_rows&&n.push(`No more than ${r.validation.max_rows} rows allowed`),r.validation?.unique_fields&&r.validation.unique_fields.length&&r.validation.unique_fields.forEach(o=>{let s=new Set;a.forEach((c,N)=>{let S=c[o];S!=null&&(s.has(S)&&n.push(`Field ${o} must be unique (duplicate at row ${N+1})`),s.add(S))})}),n},k}async function ie(r){let f=new TextEncoder().encode(r),k=await crypto.subtle.digest("SHA-256",f);return Array.from(new Uint8Array(k)).map(v=>v.toString(16).padStart(2,"0")).join("")}async function ce(r){let x=String(r||"").trim().toLowerCase();return x?`https://gravatar.com/avatar/${await ie(x)}?d=mp`:""}function K(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-users";let v=document.createElement("div");if(v.className="voc-form-users-header",k&&v.classList.add("mb-2"),r.label){let e=document.createElement("div");if(e.className="voc-form-users-label",k&&e.classList.add("form-label"),e.textContent=r.label,r.required){let l=document.createElement("span");l.className="voc-form-required",l.textContent="*",e.appendChild(l)}v.appendChild(e)}if(r.description){let e=document.createElement("div");e.className="voc-form-users-description",k&&e.classList.add("form-text"),e.textContent=r.description,v.appendChild(e)}h.appendChild(v);let u=document.createElement("div");u.className="voc-form-users-search-wrapper";let i=document.createElement("input");if(i.type="search",i.placeholder="Search users...",i.className="voc-form-users-search",k&&i.classList.add("form-control","mb-2"),u.appendChild(i),h.appendChild(u),!r.options||r.options.length===0)return h;let d=document.createElement("div");d.className="voc-form-users-list",k&&d.classList.add("list-group");let p=r.name||r.key||`users_${Math.random().toString(36).substr(2,6)}`,g=[];if(Array.isArray(f)?g=f:f!=null?g=[f]:Array.isArray(r.default)&&(g=r.default),r.options.forEach((e,l)=>{let m=document.createElement("div");m.className="voc-form-user-item",m.dataset.label=String(e.label||"").toLowerCase(),m.dataset.email=String(e.email||"").toLowerCase(),m.dataset.value=String(e.value||"").toLowerCase(),k&&m.classList.add("d-flex","align-items-center","gap-2");let a=document.createElement("input");if(a.type="checkbox",a.name=`${p}[]`,a.value=e.value,a.className="voc-form-user-checkbox",r.key&&(a.id=`voc-form-${r.key}-${l}`),a.style.position="absolute",a.style.width="1px",a.style.height="1px",a.style.margin="0",a.style.padding="0",a.style.clip="rect(0 0 0 0)",a.style.clipPath="inset(50%)",a.style.overflow="hidden",a.style.border="0",g&&Array.isArray(g)){let o=g.map(s=>String(s));a.checked=o.includes(String(e.value))}let E=document.createElement("img");E.className="voc-form-user-avatar",E.alt=e.label||String(e.value||"user"),E.style.width=E.style.height="40px",E.style.objectFit="cover",E.style.borderRadius="50%",E.src="",e.email&&ce(e.email).then(o=>{o&&(E.src=o)}).catch(()=>{});let w=document.createElement("div");w.className="voc-form-user-info",w.style.display="flex",w.style.flexDirection="column",w.style.gap="2px";let t=document.createElement("div");t.className="voc-form-user-label",t.textContent=e.label||String(e.value);let n=document.createElement("small");n.className="voc-form-user-email",n.textContent=e.email||"",w.appendChild(t),w.appendChild(n),m.addEventListener("click",o=>{let s=o.target;s&&(s.closest("input")||s.closest("a")||s.closest("button"))||(a.checked=!a.checked,a.dispatchEvent(new Event("change",{bubbles:!0})))}),a.addEventListener("change",()=>{a.checked?m.classList.add("selected"):m.classList.remove("selected")}),a.checked&&m.classList.add("selected"),m.appendChild(a),m.appendChild(E),m.appendChild(w),d.appendChild(m)}),h.appendChild(d),r.required){let e=d.querySelectorAll('input[type="checkbox"]'),l=()=>{let m=Array.from(e).some(a=>a.checked);return e.forEach(a=>{m?a.setCustomValidity(""):a.setCustomValidity("At least one option must be selected.")}),m};e.forEach(m=>{m.addEventListener("change",l)}),h._validateCheckboxGroup=l,l()}let T=Array.from(d.querySelectorAll(".voc-form-user-item")),L=()=>{let e=String(i.value||"").trim().toLowerCase();if(!e){T.forEach(l=>l.style.setProperty("display","flex","important"));return}T.forEach(l=>{let m=l.dataset.label||"",a=l.dataset.email||"",E=l.dataset.value||"",w=m.includes(e)||a.includes(e)||E.includes(e);l.style.setProperty("display",w?"flex":"none","important")})};return i.addEventListener("input",L),h}function Q(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-timezone";let v=r.name||r.key||`timezone_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("input");u.type="text",u.name=v,r.key&&(u.id=`voc-form-${r.key}`),u.className="voc-form-timezone-input",k&&u.classList.add("form-control"),r.placeholder&&(u.placeholder=r.placeholder||""),r.required&&(u.required=!0),r.width&&(u.style.width=r.width);try{u.autocomplete="off"}catch{}try{u.autocorrect="off"}catch{}try{u.autocapitalize="off"}catch{}try{u.spellcheck=!1}catch{}u.setAttribute("data-lpignore","true"),f!=null?u.value=String(f):r.default!==void 0&&r.default!==null&&(u.value=String(r.default));let i=document.createElement("div");i.className="voc-form-timezone-control",i.style.position="relative",i.style.display="inline-block",i.style.width=r.width||"100%";let d=document.createElement("button");d.type="button",d.className="voc-form-timezone-toggle",d.setAttribute("aria-haspopup","listbox"),d.setAttribute("aria-expanded","false"),d.style.position="absolute",d.style.right="4px",d.style.top="50%",d.style.transform="translateY(-50%)",d.style.height="28px",d.style.width="28px",d.style.padding="0",d.style.border="none",d.style.background="transparent",d.style.cursor="pointer",d.innerHTML="\u25BC";let p=document.createElement("ul");p.className="voc-form-timezone-list",p.setAttribute("role","listbox"),p.style.position="absolute",p.style.left="0",p.style.right="0",p.style.zIndex="1000",p.style.maxHeight="200px",p.style.overflow="auto",p.style.margin="4px 0 0 0",p.style.padding="0",p.style.listStyle="none",p.style.background="white",p.style.border="1px solid rgba(0,0,0,0.15)",p.style.display="none",p.tabIndex=-1,u.style.paddingRight="36px";let T=["UTC","ETC","AEST","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Vancouver","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Amsterdam","Asia/Tokyo","Asia/Shanghai","Asia/Singapore","Asia/Kolkata","Asia/Dubai","Australia/Lindeman","Australia/Brisbane","Australia/Sydney","Australia/Melbourne","Australia/Hobart","Australia/Currie","Australia/Broken_Hill","Australia/Lord_Howe","Australia/Adelaide","Australia/Darwin","Australia/Perth","Australia/Eucla","Australia/ACT","ACT","Pacific/Auckland","America/Sao_Paulo","America/Mexico_City","Africa/Cairo","Africa/Johannesburg"];function L(t){p.innerHTML="",t.forEach((n,o)=>{let s=document.createElement("li");s.className="voc-form-timezone-item",s.setAttribute("role","option"),s.dataset.value=n,s.style.padding="6px 8px",s.style.cursor="pointer",s.textContent=n,s.addEventListener("mousedown",c=>{c.preventDefault(),u.value=n,a(),u.dispatchEvent(new Event("change",{bubbles:!0}))}),p.appendChild(s)})}L(T);let e=-1;function l(){Array.from(p.children).forEach((n,o)=>{o===e?(n.style.background="rgba(0,123,255,0.1)",n.setAttribute("aria-selected","true")):(n.style.background="",n.removeAttribute("aria-selected"))})}function m(){p.style.display="block",d.setAttribute("aria-expanded","true")}function a(){p.style.display="none",d.setAttribute("aria-expanded","false"),e=-1,l()}function E(){p.style.display==="none"?m():a()}u.addEventListener("input",()=>{let t=(u.value||"").trim().toLowerCase(),n=t?T.filter(o=>o.toLowerCase().includes(t)):T;L(n),m()}),d.addEventListener("click",t=>{t.preventDefault(),p.style.display==="none"?(L(T),m(),u.focus()):a()}),u.addEventListener("keydown",t=>{let n=Array.from(p.children);if(t.key==="ArrowDown"){if(t.preventDefault(),n.length===0)return;e=Math.min(e+1,n.length-1),l(),n[e].scrollIntoView({block:"nearest"})}else if(t.key==="ArrowUp"){if(t.preventDefault(),n.length===0)return;e=Math.max(e-1,0),l(),n[e].scrollIntoView({block:"nearest"})}else if(t.key==="Enter"){if(p.style.display!=="none"&&e>=0){t.preventDefault();let o=n[e];u.value=o.dataset.value||o.textContent||"",a(),u.dispatchEvent(new Event("change",{bubbles:!0}))}}else t.key==="Escape"&&a()}),document.addEventListener("click",t=>{i.contains(t.target)||a()});let w={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(u.addEventListener("blur",()=>{let t=(u.value||"").trim();if(!t)return;let n=Object.keys(w).find(o=>o.toLowerCase()===t.toLowerCase());n&&(u.value=w[n])}),r.description){let t=document.createElement("div");t.className="voc-form-timezone-description",k&&t.classList.add("form-text"),t.textContent=r.description,h.appendChild(t)}return i.appendChild(u),i.appendChild(d),i.appendChild(p),h.appendChild(i),h}function X(r,x,f){let k=x?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-tags";let v=r.name||r.key||`tags_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("div");u.className="voc-form-tags-container",u.style.display="flex",u.style.flexWrap="wrap",u.style.gap="6px",u.style.alignItems="center",u.style.padding="6px",u.style.border="1px solid rgba(0,0,0,0.12)",u.style.borderRadius="4px";let i=document.createElement("input");i.type="text",i.className="voc-form-tags-input",i.style.border="none",i.style.flex="1 0 120px",i.style.minWidth="80px",i.style.outline="none",i.placeholder=r.placeholder||"",k&&i.classList.add("form-control"),u.appendChild(i);let d=[],p=document.createElement("input");p.type="text",p.style.position="absolute",p.style.left="-9999px",p.style.width="1px",p.style.height="1px",p.tabIndex=-1,r.required&&(p.required=!0),h.appendChild(p);function g(){Array.from(h.querySelectorAll("input.voc-form-tag-hidden")).forEach(m=>m.parentElement?.removeChild(m)),d.forEach(m=>{let a=document.createElement("input");a.type="hidden",a.name=`${v}[]`,a.className="voc-form-tag-hidden",a.value=m,r.key&&(a.id=`voc-form-${r.key}`),h.appendChild(a)}),r.required&&(d.length===0?(p.value="",p.setCustomValidity("Please enter at least one tag")):(p.value="1",p.setCustomValidity("")))}function T(l){let m=document.createElement("span");m.className="voc-form-tag",m.style.display="inline-flex",m.style.alignItems="center",m.style.padding="4px 8px",m.style.background="rgba(0,0,0,0.05)",m.style.borderRadius="16px";let a=document.createElement("span");a.textContent=l,a.style.marginRight="8px",m.appendChild(a);let E=document.createElement("button");return E.type="button",E.textContent="\xD7",E.style.border="none",E.style.background="transparent",E.style.cursor="pointer",E.addEventListener("click",()=>{let w=d.indexOf(l);w>=0&&(d.splice(w,1),u.removeChild(m),g())}),m.appendChild(E),m}function L(l){let m=l.trim();if(!m||d.includes(m))return;d.push(m);let a=T(m);u.insertBefore(a,i),g()}let e=f!=null?String(f):r.default||"";return e&&e.split(",").map(l=>l.trim()).filter(Boolean).forEach(L),i.addEventListener("keydown",l=>{if(l.key==="Enter"||l.key===",")l.preventDefault(),L(i.value),i.value="";else if(l.key==="Backspace"&&i.value===""&&d.pop()){let a=Array.from(u.querySelectorAll(".voc-form-tag")),E=a[a.length-1];E&&u.removeChild(E),g()}}),i.addEventListener("paste",l=>{let m=l.clipboardData?.getData("text");m&&(l.preventDefault(),m.split(/[,\n\r]+/).map(a=>a.trim()).filter(Boolean).forEach(L),i.value="")}),h.getTags=()=>d.slice(),h.addTag=L,h.appendChild(u),g(),h}function j(r,x=!0){let f=new FormData(r);if(x)return le(f);let k={};return f.forEach((h,v)=>{let u=(h instanceof File,h);Object.prototype.hasOwnProperty.call(k,v)?Array.isArray(k[v])?k[v].push(u):k[v]=[k[v],u]:k[v]=u}),k}function le(r){let x=new FormData;for(let[f,k]of r.entries()){if(k instanceof File){x.append(f,k);continue}let h;try{h=JSON.parse(k)}catch{h=null}Array.isArray(h)?h.length===0?x.append(f,"[]"):h.every(v=>typeof v=="object"&&v!==null)?h.forEach((v,u)=>{for(let[i,d]of Object.entries(v))x.append(`${f}[${u}][${i}]`,d)}):x.append(f,k):x.append(f,k)}return x}async function Z(r,x,f){let k=x.url,h={"Content-Type":"application/json"};x?.api_token&&(h.Authorization=`Bearer ${x.api_token}`);let v=j(r);if(x?.additional_data)for(let[d,p]of Object.entries(x.additional_data))v.append(d,p);let u,i=v instanceof FormData;u={method:"POST",headers:{Authorization:`Bearer ${x.api_token}`,...i?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:i?v:JSON.stringify(Object.fromEntries(v.entries()))};try{fetch(k,u).then(async d=>{let p=d.headers.get("content-type");if(!d.ok)try{let T=(await d.json())?.message;throw new Error(T??"Their was an error submitting the form. Check your form and try again.")}catch(g){throw new Error(g.message)}return p&&p.includes("application/json")?d.json():d.text()}).then(d=>{f&&f(d,null)}).catch(d=>{f&&f(null,d)})}catch(d){f&&f(null,d)}}function ee(r,x,f){let k=[];if(typeof r=="string"?k=Array.from(document.querySelectorAll(r)):k=[r],k.length===0)return null;function h(){let i=f?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),i&&d.classList.add("needs-validation"),d.id=x.id;let p=document.createElement("h2");p.className="voc-form-title",i&&p.classList.add("mb-3"),p.textContent=x.form_name,d.appendChild(p);function g(e,l){l&&(l.min_length!==void 0&&(e.minLength=l.min_length),l.max_length!==void 0&&(e.maxLength=l.max_length),l.regex&&(e instanceof HTMLInputElement?e.pattern=l.regex:e.dataset.pattern=l.regex))}function T(e){if(!e.key&&!e.label)return null;let l=x.default_values||{},m=e.name||e.key,a=m?l[m]:void 0,E=document.createElement("div");if(E.className="voc-form-group",i&&E.classList.add("mb-3"),e.label&&e.type!=="users"){let t=document.createElement("label");if(t.classList.add("voc-form-label"),i&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label,e.required){let n=document.createElement("span");n.className="voc-form-required",n.textContent="*",t.appendChild(n)}E.appendChild(t)}let w=null;switch(e.type){case"tags":{w=X(e,f||{},a);break}case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options){if(e.options.forEach((n,o)=>{let s=document.createElement("label");s.classList.add("voc-form-checkbox-label"),i&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),i&&c.classList.add("form-check-input"),c.name=`${e.name||e.key||""}[]`,c.value=n.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),Array.isArray(a)?a.includes(n.value)&&(c.checked=!0):a!==void 0?a===n.value&&(c.checked=!0):e.default===n.value&&(c.checked=!0),s.appendChild(c),s.appendChild(document.createTextNode(n.label)),t.appendChild(s)}),e.required){let n=t.querySelectorAll('input[type="checkbox"]'),o=()=>{let s=Array.from(n).some(c=>c.checked);return n.forEach(c=>{s?c.setCustomValidity(""):c.setCustomValidity("At least one option must be selected.")}),s};n.forEach(s=>{s.addEventListener("change",o)}),t._validateCheckboxGroup=o,o()}}else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),i&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),(e.key||e.name)&&(o.name=e.name||e.key,e.key&&(o.id=`voc-form-${e.key}`)),i&&o.classList.add("form-check-input"),e.required&&(o.required=!0),a!==void 0?o.checked=!!a:e.default&&(o.checked=!!e.default),n.appendChild(o),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}w=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),a!=null?t.value=String(a):e.default!==void 0&&e.default!==null&&(t.value=String(e.default));let n=e.default||a||"";if(n){let o=(n.match(/\n/g)||[]).length,s=80,c=n.split(`
2
- `).reduce((M,_)=>Math.max(M,_.length),0),N=Math.ceil(c/s)||1,S=Math.max(2,o+N);t.rows=S,t.style.resize="vertical"}e.width&&(t.style.width=e.width),e.required&&(t.required=!0),g(t,e.validation),w=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),i&&t.classList.add("form-select"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let o=document.createElement("option");o.value=n.value,o.textContent=n.label,Array.isArray(a)?a.includes(n.value)&&(o.selected=!0):a!==void 0?a===n.value&&(o.selected=!0):e.default===n.value&&(o.selected=!0),t.appendChild(o)}),e.width&&(t.style.width=e.width),w=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,o)=>{let s=document.createElement("label");s.classList.add("voc-form-radio-label"),i&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let c=document.createElement("input");c.type="radio",c.classList.add("voc-form-radio"),i&&c.classList.add("form-check-input"),c.name=e.name||e.key||"",c.value=n.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),Array.isArray(a)?a.includes(n.value)&&(c.checked=!0):a!==void 0?a===n.value&&(c.checked=!0):e.default===n.value&&(c.checked=!0),s.appendChild(c),s.appendChild(document.createTextNode(n.label)),t.appendChild(s)}),w=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),i&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),w=t;break}case"avatar":{w=U(e,f||{},a);break}case"table":{w=Y(e,f||{},a);break}case"users":{w=K(e,f||{},a);break}case"timezone":{w=Q(e,f||{},a);break}case"audio_select":{w=J(e,f||{},a);break}case"field-select":{let t=f?.style==="bootstrap",n=document.createElement("div");n.className="voc-form-field-selects";let o=document.createElement("div");if(o.className="voc-form-field-selects-header",t&&o.classList.add("mb-2"),e.label){let A=document.createElement("div");if(A.className="voc-form-field-selects-label",t&&A.classList.add("form-label"),A.textContent=e.label,e.required){let b=document.createElement("span");b.className="voc-form-required",b.textContent="*",A.appendChild(b)}o.appendChild(A)}if(e.description){let A=document.createElement("div");A.className="voc-form-field-selects-description",t&&A.classList.add("form-text"),A.textContent=e.description,o.appendChild(A)}n.appendChild(o);let s=document.createElement("div");s.className="voc-form-field-selects-search-wrapper";let c=document.createElement("input");if(c.type="search",c.placeholder="Search...",c.className="voc-form-field-selects-search",t&&c.classList.add("form-control","mb-2"),s.appendChild(c),n.appendChild(s),!e.options||e.options.length===0)return n;let N=document.createElement("div");N.className="voc-form-field-selects-list",t&&N.classList.add("list-group");let S=document.createElement("div");S.className="voc-form-field-selects-selected",S.style.marginTop="12px";let M={},_=e.name||e.key||`users_${Math.random().toString(36).substr(2,6)}`,y=[];if(Array.isArray(a)?y=a:a!=null?y=[a]:Array.isArray(e.default)&&(y=e.default),e.options.forEach((A,b)=>{let F=document.createElement("div");F.className="voc-form-field-selects-item",F.dataset.label=String(A.label||"").toLowerCase(),F.dataset.email=String(A.email||"").toLowerCase(),F.dataset.value=String(A.value||"").toLowerCase(),t&&F.classList.add("d-flex","align-items-center","gap-2");let C=document.createElement("input");if(C.type="checkbox",C.name=`${_}[]`,C.value=A.value??A.key,C.className="voc-form--checkbox",e.key&&(C.id=`voc-form-${e.key}-${b}`),C.style.position="absolute",C.style.width="1px",C.style.height="1px",C.style.margin="0",C.style.padding="0",C.style.clip="rect(0 0 0 0)",C.style.clipPath="inset(50%)",C.style.overflow="hidden",C.style.border="0",y&&Array.isArray(y)){let I=y.map(P=>String(P)),R=String(A.value??A.key);C.checked=I.includes(R)}let O=A.icon||'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><!-- Icon from Google Material Icons by Material Design Authors - https://github.com/material-icons/material-icons/blob/master/LICENSE --><path fill="currentColor" d="M14 11c0 .55-.45 1-1 1H4c-.55 0-1-.45-1-1s.45-1 1-1h9c.55 0 1 .45 1 1M3 7c0 .55.45 1 1 1h9c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1m7 8c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1m8.01-2.13l.71-.71a.996.996 0 0 1 1.41 0l.71.71c.39.39.39 1.02 0 1.41l-.71.71zm-.71.71l-5.16 5.16c-.09.09-.14.21-.14.35v1.41c0 .28.22.5.5.5h1.41c.13 0 .26-.05.35-.15l5.16-5.16z"/></svg>',B=document.createElement("div");B.className="voc-form-fields-select-avatar",B.innerHTML=O;let H=document.createElement("div");H.className="voc-form-field-select-info",H.style.display="flex",H.style.flexDirection="column",H.style.gap="2px";let D=document.createElement("div");D.className="voc-form-field-select-label",D.textContent=A.label||String(A.value);let z=document.createElement("small");z.className="voc-form-field-select-email",z.textContent=A.email||"",H.appendChild(D),H.appendChild(z),F.addEventListener("click",I=>{let R=I.target;R&&(R.closest("input")||R.closest("a")||R.closest("button"))||(C.checked=!C.checked,C.dispatchEvent(new Event("change",{bubbles:!0})))}),C.addEventListener("change",()=>{if(C.checked){F.classList.add("selected"),(M[b]||[]).forEach(P=>P.parentElement?.removeChild(P)),M[b]=[];let R=A;if(R&&Array.isArray(R.items))R.items.forEach(P=>{let W=T(P);W&&(S.appendChild(W),M[b].push(W))});else if(R&&(R.type||R.key)){let P=T(R);P&&(S.appendChild(P),M[b].push(P))}}else F.classList.remove("selected"),(M[b]||[]).forEach(R=>R.parentElement?.removeChild(R)),M[b]=[]}),C.checked&&(F.classList.add("selected"),setTimeout(()=>{let I=A;if(I&&Array.isArray(I.items))I.items.forEach(R=>{let P=T(R);P&&(S.appendChild(P),M[b]=M[b]||[],M[b].push(P))});else if(I&&(I.type||I.key)){let R=T(I);R&&(S.appendChild(R),M[b]=M[b]||[],M[b].push(R))}},0)),F.appendChild(C),F.appendChild(B),F.appendChild(H),N.appendChild(F)}),n.appendChild(N),n.appendChild(S),e.required){let A=N.querySelectorAll('input[type="checkbox"]'),b=()=>{let F=Array.from(A).some(C=>C.checked);return A.forEach(C=>{F?C.setCustomValidity(""):C.setCustomValidity("At least one option must be selected.")}),F};A.forEach(F=>{F.addEventListener("change",b)}),n._validateCheckboxGroup=b,b()}let $=Array.from(N.querySelectorAll(".voc-form-field-select-item")),q=()=>{let A=String(c.value||"").trim().toLowerCase();if(!A){$.forEach(b=>b.style.setProperty("display","flex","important"));return}$.forEach(b=>{let F=b.dataset.label||"",C=b.dataset.email||"",O=b.dataset.value||"",B=F.includes(A)||C.includes(A)||O.includes(A);b.style.setProperty("display",B?"flex":"none","important")})};return c.addEventListener("input",q),n}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),a!=null?t.value=String(a):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),g(t,e.validation),w=t;break}}if(w&&E.appendChild(w),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,E.appendChild(t)}return E}x.fields.forEach(e=>{if(e.type==="group"&&"items"in e){let l=e;if(i){let m=document.createElement("div");m.className="card voc-form-group-card mb-3";let a=l.label||l.header?.title,E=l.description||l.header?.description;if(a||E){let t=document.createElement("div");if(t.className="card-header voc-form-group-head",a){let n=document.createElement("h5");n.className="mb-0 voc-form-group-label",n.textContent=a,t.appendChild(n)}if(E){let n=document.createElement("p");n.className="mb-0 voc-form-group-description",n.textContent=E,t.appendChild(n)}m.appendChild(t)}let w=document.createElement("div");w.className="card-body voc-form-group-body",l.items.forEach(t=>{if(t.type==="row"&&"items"in t){let n=t,o=document.createElement("div");if(o.className="voc-form-group voc-form-row mb-3",n.label){let c=document.createElement("h6");c.className="voc-form-row-label",c.textContent=n.label,o.appendChild(c)}let s=document.createElement("div");s.className="voc-form-row-items "+(n.direction||"horizontal"),n.items.forEach(c=>{let N=T(c);N&&s.appendChild(N)}),o.appendChild(s),w.appendChild(o)}else{let n=T(t);n&&w.appendChild(n)}}),m.appendChild(w),d.appendChild(m)}else{let m=document.createElement("div");m.className="voc-form-group voc-form-group-wrapper",i&&m.classList.add("mb-3");let a=l.label||l.header?.title,E=l.description||l.header?.description;if(a||E){let w=document.createElement("div");if(w.className="voc-form-group-head",a){let t=document.createElement("h3");t.className="voc-form-group-label",t.textContent=a,w.appendChild(t)}if(E){let t=document.createElement("p");t.className="voc-form-group-description",t.textContent=E,w.appendChild(t)}m.appendChild(w)}l.items.forEach(w=>{if(w.type==="row"&&"items"in w){let t=w,n=document.createElement("div");if(n.className="voc-form-group voc-form-row",i&&n.classList.add("mb-3"),t.label){let s=document.createElement("h4");s.className="voc-form-row-label",s.textContent=t.label,n.appendChild(s)}let o=document.createElement("div");o.className="voc-form-row-items "+(t.direction||"horizontal"),t.items.forEach(s=>{let c=T(s);c&&o.appendChild(c)}),n.appendChild(o),m.appendChild(n)}else{let t=T(w);t&&m.appendChild(t)}}),d.appendChild(m)}return}if(e.type==="row"&&"items"in e){let l=document.createElement("div");if(l.className="voc-form-group voc-form-row",i&&l.classList.add("mb-3"),e.label){let a=document.createElement("h3");a.className="voc-form-row-label",a.textContent=e.label,l.appendChild(a)}if(e.description){let a=document.createElement("p");a.className="voc-form-row-description",a.textContent=e.description,l.appendChild(a)}let m=document.createElement("div");m.className="voc-form-row-items "+(e.direction||"horizontal"),l.appendChild(m),e.items.forEach(a=>{let E=T(a);E&&m.appendChild(E)}),d.appendChild(l)}else{let l=T(e);l&&d.appendChild(l)}});let L=document.createElement("button");return L.type="submit",L.className="voc-form-submit",L.textContent="Submit",i&&L.classList.add("btn","btn-primary"),d.appendChild(L),d}let v=h();k[0].appendChild(v);let u=x?.submit_config??f?.submit_config??null;return u&&v.addEventListener("submit",i=>{i.preventDefault();let d=Array.from(v.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),p=[];if(d.forEach(L=>{L&&typeof L._validateCheckboxGroup=="function"&&(L._validateCheckboxGroup()||L.querySelector('input[type="checkbox"]')&&p.push("Please select at least one option"))}),!v.checkValidity()){v.reportValidity(),f?.onSubmitResult&&f.onSubmitResult(null,new Error("Form validation failed"));return}let g=Array.from(v.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),T=[];if(g.forEach(L=>{if(L&&typeof L.validate=="function"){let e=L.validate();e&&e.length&&T.push(...e)}}),T.length){f?.onSubmitResult&&f.onSubmitResult(null,new Error(T.join("; ")));let L=g[0];L&&L.scrollIntoView({behavior:"smooth",block:"center"});return}if(f?.onSubmit){let L=j(v);f.onSubmit(L)}Z(v,u,(L,e)=>{f?.onSubmitResult&&f.onSubmitResult(L,e)})}),{element:v,validate:()=>{let i=[];return v.querySelectorAll(":invalid").forEach(p=>{let g=p.validationMessage;i.push({element:p,message:g})}),i},getValues:()=>j(v),onSubmit:i=>{v.addEventListener("submit",d=>{d.preventDefault();let p=j(v);i(p,d)})}}}var V={renderForm:ee};var de=V,me={FormsLib:V};0&&(module.exports={FormsLib});
1
+ "use strict";var P=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ae=Object.prototype.hasOwnProperty;var ne=(r,L)=>{for(var v in L)P(r,v,{get:L[v],enumerable:!0})},re=(r,L,v,C)=>{if(L&&typeof L=="object"||typeof L=="function")for(let f of te(L))!ae.call(r,f)&&f!==v&&P(r,f,{get:()=>L[f],enumerable:!(C=ee(L,f))||C.enumerable});return r};var se=r=>re(P({},"__esModule",{value:!0}),r);var me={};ne(me,{FormsLib:()=>ce,default:()=>de});module.exports=se(me);function j(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-avatar-wrapper",C&&f.classList.add("d-flex","align-items-center","gap-3");let b=document.createElement("img");b.className="voc-form-avatar-preview",b.alt=r.label||"avatar",C&&(b.classList.add("img-thumbnail","rounded-circle"),b.style.width=b.style.height="64px",b.style.objectFit="cover");let u=v!=null?String(v):r.default!==void 0&&r.default!==null?String(r.default):"";u?b.src=u:(b.src="",b.style.display="none");let o=document.createElement("input");o.type="file",o.accept=r.accept||"image/*",o.className="voc-form-avatar-input",C&&o.classList.add("form-control"),(r.key||r.name)&&(o.name=r.name||r.key,r.key&&(o.id=`voc-form-${r.key}`));let d=document.createElement("input");if(d.type="hidden",(r.key||r.name)&&(d.name=(r.name||r.key)+"_url"),d.value=u||"",o.addEventListener("change",p=>{let E=p.target;if(E.files&&E.files.length>0){let w=E.files[0],k=new FileReader;k.onload=()=>{b.src=String(k.result),b.style.display="",d.value=""},k.readAsDataURL(w)}}),C){let p=document.createElement("div");p.style.flex="1",p.appendChild(o),p.appendChild(d),f.appendChild(b),f.appendChild(p)}else f.appendChild(b),f.appendChild(o),f.appendChild(d);return f}function W(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");if(f.className="voc-form-audio-select",!r.options||r.options.length===0)return f;let b=r.name||r.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,u;return Array.isArray(v)?u=v[0]:v!==void 0?u=v:r.default!==void 0&&(u=r.default),r.options.forEach((o,d)=>{let p=document.createElement("div");p.className="voc-form-audio-item",C&&p.classList.add("form-check");let E=document.createElement("input");E.type="radio",E.name=b,E.value=o.value,E.className="voc-form-audio-radio",r.key&&(E.id=`voc-form-${r.key}-${d}`),r.required&&d===0&&(E.required=!0),E.style.position="absolute",E.style.width="1px",E.style.height="1px",E.style.margin="0",E.style.padding="0",E.style.clip="rect(0 0 0 0)",E.style.clipPath="inset(50%)",E.style.overflow="hidden",E.style.border="0",u!==void 0&&(Array.isArray(u)?E.checked=u.includes(o.value):E.checked=String(u)===String(o.value));let w=()=>{E.checked?p.classList.add("selected"):p.classList.remove("selected")};E.addEventListener("change",()=>{f.querySelectorAll(".voc-form-audio-item").forEach(a=>a.classList.remove("selected")),w()}),E.checked&&p.classList.add("selected");let k=document.createElement("label");k.className="voc-form-audio-label",C&&k.classList.add("form-check-label"),k.htmlFor=E.id||"",k.textContent=o.label||o.value,k.tabIndex=0;let e=document.createElement("div");e.className="voc-form-audio-control";let c=null;if(o.audio_link){let t=document.createElement("button");t.type="button",t.className="voc-form-audio-play",C&&t.classList.add("btn","btn-sm","btn-outline-secondary"),t.setAttribute("aria-label",`Play ${o.label||o.value}`);let a="http://www.w3.org/2000/svg",i=document.createElementNS(a,"svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width","16"),i.setAttribute("height","16"),i.setAttribute("aria-hidden","true");let s=document.createElementNS(a,"path");s.setAttribute("d","M8 5v14l11-7z"),s.setAttribute("fill","currentColor"),i.appendChild(s),t.appendChild(i),c=document.createElement("audio"),c.src=o.audio_link,c.preload="none",c.style.display="none";let l=g=>{for(;g.firstChild;)g.removeChild(g.firstChild)},A=()=>{let g="http://www.w3.org/2000/svg",F=document.createElementNS(g,"svg");F.setAttribute("viewBox","0 0 24 24"),F.setAttribute("width","16"),F.setAttribute("height","16"),F.setAttribute("aria-hidden","true");let M=document.createElementNS(g,"path");return M.setAttribute("d","M8 5v14l11-7z"),M.setAttribute("fill","currentColor"),F.appendChild(M),F},S=()=>{let g="http://www.w3.org/2000/svg",F=document.createElementNS(g,"svg");F.setAttribute("viewBox","0 0 24 24"),F.setAttribute("width","16"),F.setAttribute("height","16"),F.setAttribute("aria-hidden","true");let M=document.createElementNS(g,"rect");return M.setAttribute("x","6"),M.setAttribute("y","6"),M.setAttribute("width","12"),M.setAttribute("height","12"),M.setAttribute("fill","currentColor"),F.appendChild(M),F};l(t),t.appendChild(A());let N=g=>{l(t),g?(t.appendChild(S()),t.setAttribute("aria-label",`Stop ${o.label||o.value}`)):(t.appendChild(A()),t.setAttribute("aria-label",`Play ${o.label||o.value}`))};t.addEventListener("click",()=>{try{if(!c)return;let g=f.querySelectorAll("audio");if(!c.paused&&!c.ended){c.pause(),c.currentTime=0;return}g.forEach(M=>{try{M.pause(),M.currentTime=0}catch{}}),f.querySelectorAll(".voc-form-audio-item").forEach(M=>M.classList.remove("is-playing")),c.play()}catch(g){console.warn("audio play failed",g)}}),c.addEventListener("playing",()=>{p.classList.add("is-playing"),N(!0)});let x=()=>{p.classList.remove("is-playing"),N(!1)};c.addEventListener("pause",x),c.addEventListener("ended",x),e.appendChild(t),e.appendChild(c)}let h=document.createElement("div");h.className="voc-form-item-detail",h.style.display="flex",h.style.flexDirection="column",h.style.gap="4px";let n=document.createElement("div");n.className="voc-form-item-top",n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.appendChild(E),n.appendChild(k);let m=document.createElement("div");m.className="voc-form-item-description";let y=o.description||o.hint_text||"";y&&(m.textContent=y),h.appendChild(n),h.appendChild(m),e.appendChild(h),p.appendChild(e),n.addEventListener("click",t=>{let a=t.target;a&&a.closest(".voc-form-audio-play")||(E.checked=!0,E.dispatchEvent(new Event("change",{bubbles:!0})))}),p.addEventListener("click",t=>{let a=t.target;a&&a.closest(".voc-form-audio-play")||(E.checked=!0,E.dispatchEvent(new Event("change",{bubbles:!0})))}),f.appendChild(p)}),f}function G(r,L,v){let C=document.createElement("div");C.className="voc-form-table-wrapper";let f=L?.style==="bootstrap",b=document.createElement("input");b.type="hidden",b.name=r.name||r.key,r.key&&(b.id=`voc-form-${r.key}`),C.appendChild(b);let u=document.createElement("table");u.className="voc-form-table",f&&u.classList.add("table","table-bordered");let o=document.createElement("thead"),d=document.createElement("tr"),p=document.createElement("th");p.className="voc-form-table-drag-col",p.textContent="",d.appendChild(p),(r.fields||[]).forEach(a=>{let i=document.createElement("th");i.textContent=a.label||a.key,d.appendChild(i)});let E=document.createElement("th");E.textContent="Actions",d.appendChild(E),o.appendChild(d),u.appendChild(o);let w=document.createElement("tbody");u.appendChild(w),C.appendChild(u);let k=document.createElement("button");k.type="button",k.className="voc-form-table-add",f&&k.classList.add("btn","btn-secondary"),k.textContent="+Add";let e=document.createElement("tfoot"),c=document.createElement("tr"),h=document.createElement("td");h.colSpan=(r.fields?r.fields.length:0)+1,h.appendChild(k),c.appendChild(h),e.appendChild(c),u.appendChild(e),C.appendChild(u);let n=[];function m(){b.value=JSON.stringify(n)}function y(a){let i=[];return r.fields.forEach(s=>{let l=a[s.key];if(s.type==="checkbox"){let A=Array.isArray(l)?l:l?[l]:[];s.required&&A.length===0&&i.push(`${s.label||s.key} is required`);return}s.required&&(l==null||String(l).trim()==="")&&i.push(`${s.label||s.key} is required`),s.type==="email"&&l&&(/^\S+@\S+\.\S+$/.test(String(l))||i.push(`${s.label||s.key} must be a valid email`)),s.type==="number"&&l&&isNaN(Number(l))&&i.push(`${s.label||s.key} must be a number`),s.validation&&s.validation.regex&&l&&(new RegExp(s.validation.regex).test(String(l))||i.push(`${s.label||s.key} invalid format`))}),i}function t(){w.innerHTML="";let a=(i,s)=>{s.draggable=!0,s.addEventListener("mousedown",()=>{s.style.cursor="grabbing"}),s.addEventListener("mouseup",()=>{s.style.cursor="grab"}),s.addEventListener("dragstart",l=>{let A=Number(i.dataset.rowIndex);l.dataTransfer.setData("text/plain",String(A)),i.classList.add("dragging");try{l.dataTransfer?.setDragImage(s,10,10)}catch{}}),s.addEventListener("dragend",()=>{i.classList.remove("dragging"),s.style.cursor="grab"}),i.addEventListener("dragover",l=>{l.preventDefault();let A=l.currentTarget,S=A.getBoundingClientRect(),N=S.top+S.height/2,x=(l.clientY||l.y)>N;A.classList.remove("drag-over-top","drag-over-bottom"),x?(A.classList.add("drag-over-bottom"),A.dataset.dropPosition="after"):(A.classList.add("drag-over-top"),A.dataset.dropPosition="before")}),i.addEventListener("dragleave",l=>{let A=l.currentTarget;A.classList.remove("drag-over-top","drag-over-bottom"),delete A.dataset.dropPosition}),i.addEventListener("drop",l=>{l.preventDefault();let A=l.dataTransfer.getData("text/plain"),S=Number(l.currentTarget.dataset.rowIndex),N=Number(A),x=l.currentTarget.dataset.dropPosition||"before";if(isNaN(N)||isNaN(S))return;let[g]=n.splice(N,1),F=S;N<S&&(F=S-1);let M=x==="after"?F+1:F;n.splice(M,0,g),l.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete l.currentTarget.dataset.dropPosition,t(),m()})};n.forEach((i,s)=>{let l=document.createElement("tr");l.dataset.rowIndex=String(s),l.classList.add("voc-form-table-row");let A=document.createElement("td");A.className="voc-form-table-drag-handle";let S=document.createElement("span");S.className="voc-form-drag-handle-icon",S.textContent="\u2630",S.style.cursor="grab",A.appendChild(S),l.appendChild(A),a(l,S),r.fields.forEach(g=>{let F=document.createElement("td"),M,B=(g.type||"text").toLowerCase();if(B==="select"){let T=document.createElement("select");if(T.className="voc-form-table-cell",f&&T.classList.add("form-control"),g.placeholder){let H=document.createElement("option");H.value="",H.textContent=g.placeholder,H.disabled=!0,(i[g.key]===void 0||i[g.key]===null||i[g.key]==="")&&(H.selected=!0),T.appendChild(H)}(g.options||[]).forEach(H=>{let $=document.createElement("option");$.value=H.value,$.textContent=H.label,T.appendChild($)}),T.value=i[g.key]!==void 0&&i[g.key]!==null?String(i[g.key]):"",g.required&&(T.required=!0),T.addEventListener("change",H=>{n[s][g.key]=H.target.value,m()}),M=T}else if(B==="checkbox"){let T=document.createElement("div");T.className="voc-form-table-checkboxes",f&&T.classList.add("form-check");let D=g.options||[];Array.isArray(n[s][g.key])||(n[s][g.key]=n[s][g.key]?[n[s][g.key]]:[]),D.forEach(H=>{let $=`voc-form-${r.key}-${g.key}-${s}-${H.value}`,q=document.createElement("div");q.className="voc-form-table-checkbox-item",f&&q.classList.add("form-check");let R=document.createElement("input");R.type="checkbox",R.className="voc-form-table-cell",f&&R.classList.add("form-check-input"),R.id=$,R.value=H.value,R.checked=Array.isArray(n[s][g.key])&&n[s][g.key].includes(H.value),R.addEventListener("change",O=>{let X=O.target.checked;Array.isArray(n[s][g.key])||(n[s][g.key]=[]),X?n[s][g.key].includes(H.value)||n[s][g.key].push(H.value):n[s][g.key]=n[s][g.key].filter(Z=>Z!==H.value),m()});let _=document.createElement("label");_.htmlFor=$,_.className="voc-form-table-checkbox-label",f&&_.classList.add("form-check-label"),_.textContent=H.label,q.appendChild(R),q.appendChild(_),T.appendChild(q)}),M=T}else if(B==="radio"){let T=document.createElement("div");T.className="voc-form-table-radios",f&&T.classList.add("form-check");let D=g.options||[];n[s][g.key]===void 0&&(n[s][g.key]=""),D.forEach(H=>{let $=`voc-form-${r.key}-${g.key}-${s}-${H.value}`,q=document.createElement("div");q.className="voc-form-table-radio-item",f&&q.classList.add("form-check");let R=document.createElement("input");R.type="radio",R.className="voc-form-table-cell",f&&R.classList.add("form-check-input"),R.id=$,R.name=`voc-form-${r.key}-${g.key}-${s}`,R.value=H.value,R.checked=n[s][g.key]===H.value,R.addEventListener("change",O=>{O.target.checked&&(n[s][g.key]=O.target.value,m())});let _=document.createElement("label");_.htmlFor=$,_.className="voc-form-table-radio-label",f&&_.classList.add("form-check-label"),_.textContent=H.label,q.appendChild(R),q.appendChild(_),T.appendChild(q)}),M=T}else{let T=document.createElement("input");B==="number"?T.type="number":B==="email"?T.type="email":B==="tel"?T.type="tel":B==="url"?T.type="url":B==="date"?T.type="date":T.type="text",T.value=i[g.key]!==void 0&&i[g.key]!==null?String(i[g.key]):"",g.placeholder&&(T.placeholder=g.placeholder),g.required&&(T.required=!0),T.className="voc-form-table-cell",f&&T.classList.add("form-control"),T.addEventListener("input",D=>{n[s][g.key]=D.target.value,m()}),M=T}F.appendChild(M),l.appendChild(F)});let N=document.createElement("td"),x=document.createElement("button");x.type="button",x.className="voc-form-table-remove",f&&x.classList.add("btn","btn-danger"),x.textContent="Remove",x.addEventListener("click",()=>{n.splice(s,1),t(),m()}),N.appendChild(x),l.appendChild(N),w.appendChild(l)})}return k.addEventListener("click",()=>{if(r.validation?.max_rows!==void 0&&n.length>=r.validation.max_rows)return;let a={};r.fields.forEach(i=>a[i.key]=""),n.push(a),t(),m()}),Array.isArray(v)&&v.length?n=v.map(a=>({...a})):r.default&&Array.isArray(r.default)&&(n=r.default.map(a=>({...a}))),t(),m(),C.validate=function(){let a=[];return n.forEach((i,s)=>{let l=y(i);l.length&&a.push(`Row ${s+1}: ${l.join("; ")}`)}),r.validation?.min_rows!==void 0&&n.length<r.validation.min_rows&&a.push(`At least ${r.validation.min_rows} rows required`),r.validation?.max_rows!==void 0&&n.length>r.validation.max_rows&&a.push(`No more than ${r.validation.max_rows} rows allowed`),r.validation?.unique_fields&&r.validation.unique_fields.length&&r.validation.unique_fields.forEach(i=>{let s=new Set;n.forEach((l,A)=>{let S=l[i];S!=null&&(s.has(S)&&a.push(`Field ${i} must be unique (duplicate at row ${A+1})`),s.add(S))})}),a},C}async function oe(r){let v=new TextEncoder().encode(r),C=await crypto.subtle.digest("SHA-256",v);return Array.from(new Uint8Array(C)).map(b=>b.toString(16).padStart(2,"0")).join("")}async function ie(r){let L=String(r||"").trim().toLowerCase();return L?`https://gravatar.com/avatar/${await oe(L)}?d=mp`:""}function U(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-users";let b=document.createElement("div");if(b.className="voc-form-users-header",C&&b.classList.add("mb-2"),r.label){let e=document.createElement("div");if(e.className="voc-form-users-label",C&&e.classList.add("form-label"),e.textContent=r.label,r.required){let c=document.createElement("span");c.className="voc-form-required",c.textContent="*",e.appendChild(c)}b.appendChild(e)}if(r.description){let e=document.createElement("div");e.className="voc-form-users-description",C&&e.classList.add("form-text"),e.textContent=r.description,b.appendChild(e)}f.appendChild(b);let u=document.createElement("div");u.className="voc-form-users-search-wrapper";let o=document.createElement("input");if(o.type="search",o.placeholder="Search users...",o.className="voc-form-users-search",C&&o.classList.add("form-control","mb-2"),u.appendChild(o),f.appendChild(u),!r.options||r.options.length===0)return f;let d=document.createElement("div");d.className="voc-form-users-list",C&&d.classList.add("list-group");let p=r.name||r.key||`users_${Math.random().toString(36).substr(2,6)}`,E=[];if(Array.isArray(v)?E=v:v!=null?E=[v]:Array.isArray(r.default)&&(E=r.default),r.options.forEach((e,c)=>{let h=document.createElement("div");h.className="voc-form-user-item",h.dataset.label=String(e.label||"").toLowerCase(),h.dataset.email=String(e.email||"").toLowerCase(),h.dataset.value=String(e.value||"").toLowerCase(),C&&h.classList.add("d-flex","align-items-center","gap-2");let n=document.createElement("input");if(n.type="checkbox",n.name=`${p}[]`,n.value=e.value,n.className="voc-form-user-checkbox",r.key&&(n.id=`voc-form-${r.key}-${c}`),n.style.position="absolute",n.style.width="1px",n.style.height="1px",n.style.margin="0",n.style.padding="0",n.style.clip="rect(0 0 0 0)",n.style.clipPath="inset(50%)",n.style.overflow="hidden",n.style.border="0",E&&Array.isArray(E)){let i=E.map(s=>String(s));n.checked=i.includes(String(e.value))}let m=document.createElement("img");m.className="voc-form-user-avatar",m.alt=e.label||String(e.value||"user"),m.style.width=m.style.height="40px",m.style.objectFit="cover",m.style.borderRadius="50%",m.src="",e.email&&ie(e.email).then(i=>{i&&(m.src=i)}).catch(()=>{});let y=document.createElement("div");y.className="voc-form-user-info",y.style.display="flex",y.style.flexDirection="column",y.style.gap="2px";let t=document.createElement("div");t.className="voc-form-user-label",t.textContent=e.label||String(e.value);let a=document.createElement("small");a.className="voc-form-user-email",a.textContent=e.email||"",y.appendChild(t),y.appendChild(a),h.addEventListener("click",i=>{let s=i.target;s&&(s.closest("input")||s.closest("a")||s.closest("button"))||(n.checked=!n.checked,n.dispatchEvent(new Event("change",{bubbles:!0})))}),n.addEventListener("change",()=>{n.checked?h.classList.add("selected"):h.classList.remove("selected")}),n.checked&&h.classList.add("selected"),h.appendChild(n),h.appendChild(m),h.appendChild(y),d.appendChild(h)}),f.appendChild(d),r.required){let e=d.querySelectorAll('input[type="checkbox"]'),c=()=>{let h=Array.from(e).some(n=>n.checked);return e.forEach(n=>{h?n.setCustomValidity(""):n.setCustomValidity("At least one option must be selected.")}),h};e.forEach(h=>{h.addEventListener("change",c)}),f._validateCheckboxGroup=c,c()}let w=Array.from(d.querySelectorAll(".voc-form-user-item")),k=()=>{let e=String(o.value||"").trim().toLowerCase();if(!e){w.forEach(c=>c.style.setProperty("display","flex","important"));return}w.forEach(c=>{let h=c.dataset.label||"",n=c.dataset.email||"",m=c.dataset.value||"",y=h.includes(e)||n.includes(e)||m.includes(e);c.style.setProperty("display",y?"flex":"none","important")})};return o.addEventListener("input",k),f}function V(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-timezone";let b=r.name||r.key||`timezone_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("input");u.type="text",u.name=b,r.key&&(u.id=`voc-form-${r.key}`),u.className="voc-form-timezone-input",C&&u.classList.add("form-control"),r.placeholder&&(u.placeholder=r.placeholder||""),r.required&&(u.required=!0),r.width&&(u.style.width=r.width);try{u.autocomplete="off"}catch{}try{u.autocorrect="off"}catch{}try{u.autocapitalize="off"}catch{}try{u.spellcheck=!1}catch{}u.setAttribute("data-lpignore","true"),v!=null?u.value=String(v):r.default!==void 0&&r.default!==null&&(u.value=String(r.default));let o=document.createElement("div");o.className="voc-form-timezone-control",o.style.position="relative",o.style.display="inline-block",o.style.width=r.width||"100%";let d=document.createElement("button");d.type="button",d.className="voc-form-timezone-toggle",d.setAttribute("aria-haspopup","listbox"),d.setAttribute("aria-expanded","false"),d.style.position="absolute",d.style.right="4px",d.style.top="50%",d.style.transform="translateY(-50%)",d.style.height="28px",d.style.width="28px",d.style.padding="0",d.style.border="none",d.style.background="transparent",d.style.cursor="pointer",d.innerHTML="\u25BC";let p=document.createElement("ul");p.className="voc-form-timezone-list",p.setAttribute("role","listbox"),p.style.position="absolute",p.style.left="0",p.style.right="0",p.style.zIndex="1000",p.style.maxHeight="200px",p.style.overflow="auto",p.style.margin="4px 0 0 0",p.style.padding="0",p.style.listStyle="none",p.style.background="white",p.style.border="1px solid rgba(0,0,0,0.15)",p.style.display="none",p.tabIndex=-1,u.style.paddingRight="36px";let w=["UTC","ETC","AEST","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Vancouver","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Amsterdam","Asia/Tokyo","Asia/Shanghai","Asia/Singapore","Asia/Kolkata","Asia/Dubai","Australia/Lindeman","Australia/Brisbane","Australia/Sydney","Australia/Melbourne","Australia/Hobart","Australia/Currie","Australia/Broken_Hill","Australia/Lord_Howe","Australia/Adelaide","Australia/Darwin","Australia/Perth","Australia/Eucla","Australia/ACT","ACT","Pacific/Auckland","America/Sao_Paulo","America/Mexico_City","Africa/Cairo","Africa/Johannesburg"];function k(t){p.innerHTML="",t.forEach((a,i)=>{let s=document.createElement("li");s.className="voc-form-timezone-item",s.setAttribute("role","option"),s.dataset.value=a,s.style.padding="6px 8px",s.style.cursor="pointer",s.textContent=a,s.addEventListener("mousedown",l=>{l.preventDefault(),u.value=a,n(),u.dispatchEvent(new Event("change",{bubbles:!0}))}),p.appendChild(s)})}k(w);let e=-1;function c(){Array.from(p.children).forEach((a,i)=>{i===e?(a.style.background="rgba(0,123,255,0.1)",a.setAttribute("aria-selected","true")):(a.style.background="",a.removeAttribute("aria-selected"))})}function h(){p.style.display="block",d.setAttribute("aria-expanded","true")}function n(){p.style.display="none",d.setAttribute("aria-expanded","false"),e=-1,c()}function m(){p.style.display==="none"?h():n()}u.addEventListener("input",()=>{let t=(u.value||"").trim().toLowerCase(),a=t?w.filter(i=>i.toLowerCase().includes(t)):w;k(a),h()}),d.addEventListener("click",t=>{t.preventDefault(),p.style.display==="none"?(k(w),h(),u.focus()):n()}),u.addEventListener("keydown",t=>{let a=Array.from(p.children);if(t.key==="ArrowDown"){if(t.preventDefault(),a.length===0)return;e=Math.min(e+1,a.length-1),c(),a[e].scrollIntoView({block:"nearest"})}else if(t.key==="ArrowUp"){if(t.preventDefault(),a.length===0)return;e=Math.max(e-1,0),c(),a[e].scrollIntoView({block:"nearest"})}else if(t.key==="Enter"){if(p.style.display!=="none"&&e>=0){t.preventDefault();let i=a[e];u.value=i.dataset.value||i.textContent||"",n(),u.dispatchEvent(new Event("change",{bubbles:!0}))}}else t.key==="Escape"&&n()}),document.addEventListener("click",t=>{o.contains(t.target)||n()});let y={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(u.addEventListener("blur",()=>{let t=(u.value||"").trim();if(!t)return;let a=Object.keys(y).find(i=>i.toLowerCase()===t.toLowerCase());a&&(u.value=y[a])}),r.description){let t=document.createElement("div");t.className="voc-form-timezone-description",C&&t.classList.add("form-text"),t.textContent=r.description,f.appendChild(t)}return o.appendChild(u),o.appendChild(d),o.appendChild(p),f.appendChild(o),f}function J(r,L,v){let C=L?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-tags";let b=r.name||r.key||`tags_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("div");u.className="voc-form-tags-container",u.style.display="flex",u.style.flexWrap="wrap",u.style.gap="6px",u.style.alignItems="center",u.style.padding="6px",u.style.border="1px solid rgba(0,0,0,0.12)",u.style.borderRadius="4px";let o=document.createElement("input");o.type="text",o.className="voc-form-tags-input",o.style.border="none",o.style.flex="1 0 120px",o.style.minWidth="80px",o.style.outline="none",o.placeholder=r.placeholder||"",C&&o.classList.add("form-control"),u.appendChild(o);let d=[],p=document.createElement("input");p.type="text",p.style.position="absolute",p.style.left="-9999px",p.style.width="1px",p.style.height="1px",p.tabIndex=-1,r.required&&(p.required=!0),f.appendChild(p);function E(){Array.from(f.querySelectorAll("input.voc-form-tag-hidden")).forEach(h=>h.parentElement?.removeChild(h)),d.forEach(h=>{let n=document.createElement("input");n.type="hidden",n.name=`${b}[]`,n.className="voc-form-tag-hidden",n.value=h,r.key&&(n.id=`voc-form-${r.key}`),f.appendChild(n)}),r.required&&(d.length===0?(p.value="",p.setCustomValidity("Please enter at least one tag")):(p.value="1",p.setCustomValidity("")))}function w(c){let h=document.createElement("span");h.className="voc-form-tag",h.style.display="inline-flex",h.style.alignItems="center",h.style.padding="4px 8px",h.style.background="rgba(0,0,0,0.05)",h.style.borderRadius="16px";let n=document.createElement("span");n.textContent=c,n.style.marginRight="8px",h.appendChild(n);let m=document.createElement("button");return m.type="button",m.textContent="\xD7",m.style.border="none",m.style.background="transparent",m.style.cursor="pointer",m.addEventListener("click",()=>{let y=d.indexOf(c);y>=0&&(d.splice(y,1),u.removeChild(h),E())}),h.appendChild(m),h}function k(c){let h=c.trim();if(!h||d.includes(h))return;d.push(h);let n=w(h);u.insertBefore(n,o),E()}let e=v!=null?String(v):r.default||"";return e&&e.split(",").map(c=>c.trim()).filter(Boolean).forEach(k),o.addEventListener("keydown",c=>{if(c.key==="Enter"||c.key===",")c.preventDefault(),k(o.value),o.value="";else if(c.key==="Backspace"&&o.value===""&&d.pop()){let n=Array.from(u.querySelectorAll(".voc-form-tag")),m=n[n.length-1];m&&u.removeChild(m),E()}}),o.addEventListener("paste",c=>{let h=c.clipboardData?.getData("text");h&&(c.preventDefault(),h.split(/[,\n\r]+/).map(n=>n.trim()).filter(Boolean).forEach(k),o.value="")}),f.getTags=()=>d.slice(),f.addTag=k,f.appendChild(u),E(),f}function Y(r,L,v,C){let f=L?.style==="bootstrap",b=document.createElement("div");b.className="voc-form-field-selects";let u=document.createElement("div");if(u.className="voc-form-field-selects-header",f&&u.classList.add("mb-2"),r.label){let m=document.createElement("div");if(m.className="voc-form-field-selects-label",f&&m.classList.add("form-label"),m.textContent=r.label,r.required){let y=document.createElement("span");y.className="voc-form-required",y.textContent="*",m.appendChild(y)}u.appendChild(m)}if(r.description){let m=document.createElement("div");m.className="voc-form-field-selects-description",f&&m.classList.add("form-text"),m.textContent=r.description,u.appendChild(m)}b.appendChild(u);let o=document.createElement("div");o.className="voc-form-field-selects-search-wrapper";let d=document.createElement("input");d.type="search",d.placeholder="Search...",d.className="voc-form-field-selects-search",f&&d.classList.add("form-control","mb-2"),o.appendChild(d),b.appendChild(o);let p=r.options;if(!p||p.length===0)return b;let E=document.createElement("div");E.className="voc-form-field-selects-list",f&&E.classList.add("list-group");let w=document.createElement("div");w.className="voc-form-field-selects-selected",w.style.marginTop="12px";let k={},e=r.name||r.key||`users_${Math.random().toString(36).substr(2,6)}`,c=[];if(Array.isArray(v)?c=v:v!=null?c=[v]:Array.isArray(r.default)&&(c=r.default),p.forEach((m,y)=>{let t=document.createElement("div");t.className="voc-form-field-selects-item",t.dataset.label=String(m.option_label??m.label??"").toLowerCase(),t.dataset.email=String(m.email||"").toLowerCase(),t.dataset.value=String(m.value||"").toLowerCase(),f&&t.classList.add("d-flex","align-items-center","gap-2");let a=document.createElement("input");if(a.type="checkbox",a.name=`${e}[]`,a.value=m.value??m.key,a.className="voc-form--checkbox",r.key&&(a.id=`voc-form-${r.key}-${y}`),a.style.position="absolute",a.style.width="1px",a.style.height="1px",a.style.margin="0",a.style.padding="0",a.style.clip="rect(0 0 0 0)",a.style.clipPath="inset(50%)",a.style.overflow="hidden",a.style.border="0",c&&Array.isArray(c)){let N=c.map(g=>String(g)),x=String(m.value??m.key);a.checked=N.includes(x)}let i=m.icon||'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M14 11c0 .55-.45 1-1 1H4c-.55 0-1-.45-1-1s.45-1 1-1h9c.55 0 1 .45 1 1M3 7c0 .55.45 1 1 1h9c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1m7 8c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1m8.01-2.13l.71-.71a.996.996 0 0 1 1.41 0l.71.71c.39.39.39 1.02 0 1.41l-.71.71zm-.71.71l-5.16 5.16c-.09.09-.14.21-.14.35v1.41c0 .28.22.5.5.5h1.41c.13 0 .26-.05.35-.15l5.16-5.16z"/></svg>',s=document.createElement("div");s.className="voc-form-fields-select-avatar",s.innerHTML=i;let l=document.createElement("div");l.className="voc-form-field-select-info",l.style.display="flex",l.style.flexDirection="column",l.style.gap="2px";let A=document.createElement("div");A.className="voc-form-field-select-label",A.textContent=(m.option_label??m.label)||String(m.value);let S=document.createElement("small");S.className="voc-form-field-select-email",S.textContent=m.email||"",l.appendChild(A),l.appendChild(S),t.addEventListener("click",N=>{let x=N.target;x&&(x.closest("input")||x.closest("a")||x.closest("button"))||(a.checked=!a.checked,a.dispatchEvent(new Event("change",{bubbles:!0})))}),a.addEventListener("change",()=>{if(a.checked){t.classList.add("selected"),(k[y]||[]).forEach(g=>g.parentElement?.removeChild(g)),k[y]=[];let x=m;if(x&&Array.isArray(x.items))x.items.forEach(g=>{let F=C(g);F&&(w.appendChild(F),k[y].push(F))});else if(x&&(x.type||x.key)){let g=C(x);g&&(w.appendChild(g),k[y].push(g))}}else t.classList.remove("selected"),(k[y]||[]).forEach(x=>x.parentElement?.removeChild(x)),k[y]=[]}),a.checked&&(t.classList.add("selected"),setTimeout(()=>{let N=m;if(N&&Array.isArray(N.items))N.items.forEach(x=>{let g=C(x);g&&(w.appendChild(g),k[y]=k[y]||[],k[y].push(g))});else if(N&&(N.type||N.key)){let x=C(N);x&&(w.appendChild(x),k[y]=k[y]||[],k[y].push(x))}},0)),t.appendChild(a),t.appendChild(s),t.appendChild(l),E.appendChild(t)}),b.appendChild(E),b.appendChild(w),r.required){let m=E.querySelectorAll('input[type="checkbox"]'),y=()=>{let t=Array.from(m).some(a=>a.checked);return m.forEach(a=>{t?a.setCustomValidity(""):a.setCustomValidity("At least one option must be selected.")}),t};m.forEach(t=>{t.addEventListener("change",y)}),b._validateCheckboxGroup=y,y()}let h=Array.from(E.querySelectorAll(".voc-form-field-select-item")),n=()=>{let m=String(d.value||"").trim().toLowerCase();if(!m){h.forEach(y=>y.style.setProperty("display","flex","important"));return}h.forEach(y=>{let t=y.dataset.label||"",a=y.dataset.email||"",i=y.dataset.value||"",s=t.includes(m)||a.includes(m)||i.includes(m);y.style.setProperty("display",s?"flex":"none","important")})};return d.addEventListener("input",n),b}function I(r,L=!0){let v=new FormData(r);if(L)return le(v);let C={};return v.forEach((f,b)=>{let u=(f instanceof File,f);Object.prototype.hasOwnProperty.call(C,b)?Array.isArray(C[b])?C[b].push(u):C[b]=[C[b],u]:C[b]=u}),C}function le(r){let L=new FormData;for(let[v,C]of r.entries()){if(C instanceof File){L.append(v,C);continue}let f;try{f=JSON.parse(C)}catch{f=null}Array.isArray(f)?f.length===0?L.append(v,"[]"):f.every(b=>typeof b=="object"&&b!==null)?f.forEach((b,u)=>{for(let[o,d]of Object.entries(b))L.append(`${v}[${u}][${o}]`,d)}):L.append(v,C):L.append(v,C)}return L}async function K(r,L,v){let C=L.url,f={"Content-Type":"application/json"};L?.api_token&&(f.Authorization=`Bearer ${L.api_token}`);let b=I(r);if(L?.additional_data)for(let[d,p]of Object.entries(L.additional_data))b.append(d,p);let u,o=b instanceof FormData;u={method:"POST",headers:{Authorization:`Bearer ${L.api_token}`,...o?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:o?b:JSON.stringify(Object.fromEntries(b.entries()))};try{fetch(C,u).then(async d=>{let p=d.headers.get("content-type");if(!d.ok)try{let w=(await d.json())?.message;throw new Error(w??"Their was an error submitting the form. Check your form and try again.")}catch(E){throw new Error(E.message)}return p&&p.includes("application/json")?d.json():d.text()}).then(d=>{v&&v(d,null)}).catch(d=>{v&&v(null,d)})}catch(d){v&&v(null,d)}}function Q(r,L,v){let C=[];if(typeof r=="string"?C=Array.from(document.querySelectorAll(r)):C=[r],C.length===0)return null;function f(){let o=v?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),o&&d.classList.add("needs-validation"),d.id=L.id;let p=document.createElement("h2");p.className="voc-form-title",o&&p.classList.add("mb-3"),p.textContent=L.form_name,d.appendChild(p);function E(e,c){c&&(c.min_length!==void 0&&(e.minLength=c.min_length),c.max_length!==void 0&&(e.maxLength=c.max_length),c.regex&&(e instanceof HTMLInputElement?e.pattern=c.regex:e.dataset.pattern=c.regex))}function w(e){if(!e.key&&!e.label)return null;let c=L.default_values||{},h=e.name||e.key,n=h?c[h]:void 0,m=document.createElement("div");if(m.className="voc-form-group",o&&m.classList.add("mb-3"),e.label&&e.type!=="users"){let t=document.createElement("label");if(t.classList.add("voc-form-label"),o&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label,e.required){let a=document.createElement("span");a.className="voc-form-required",a.textContent="*",t.appendChild(a)}m.appendChild(t)}let y=null;switch(e.type){case"tags":{y=J(e,v||{},n);break}case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options){if(e.options.forEach((a,i)=>{let s=document.createElement("label");s.classList.add("voc-form-checkbox-label"),o&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let l=document.createElement("input");l.type="checkbox",l.classList.add("voc-form-checkbox"),o&&l.classList.add("form-check-input"),l.name=`${e.name||e.key||""}[]`,l.value=a.value,e.key&&(l.id=`voc-form-${e.key}-${i}`),Array.isArray(n)?n.includes(a.value)&&(l.checked=!0):n!==void 0?n===a.value&&(l.checked=!0):e.default===a.value&&(l.checked=!0),s.appendChild(l),s.appendChild(document.createTextNode(a.label)),t.appendChild(s)}),e.required){let a=t.querySelectorAll('input[type="checkbox"]'),i=()=>{let s=Array.from(a).some(l=>l.checked);return a.forEach(l=>{s?l.setCustomValidity(""):l.setCustomValidity("At least one option must be selected.")}),s};a.forEach(s=>{s.addEventListener("change",i)}),t._validateCheckboxGroup=i,i()}}else{let a=document.createElement("label");a.classList.add("voc-form-checkbox-label"),o&&a.classList.add("form-check"),e.width&&(a.style.width=e.width);let i=document.createElement("input");i.type="checkbox",i.classList.add("voc-form-checkbox"),(e.key||e.name)&&(i.name=e.name||e.key,e.key&&(i.id=`voc-form-${e.key}`)),o&&i.classList.add("form-check-input"),e.required&&(i.required=!0),n!==void 0?i.checked=!!n:e.default&&(i.checked=!!e.default),a.appendChild(i),a.appendChild(document.createTextNode(e.label||"")),t.appendChild(a)}y=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),n!=null?t.value=String(n):e.default!==void 0&&e.default!==null&&(t.value=String(e.default));let a=e.default||n||"";if(a){let i=(a.match(/\n/g)||[]).length,s=80,l=a.split(`
2
+ `).reduce((N,x)=>Math.max(N,x.length),0),A=Math.ceil(l/s)||1,S=Math.max(2,i+A);t.rows=S,t.style.resize="vertical"}e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),y=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),o&&t.classList.add("form-select"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let a=document.createElement("option");a.value="",a.textContent=e.placeholder,a.disabled=!0,a.selected=!0,t.appendChild(a)}e.required&&(t.required=!0),e.options&&e.options.forEach(a=>{let i=document.createElement("option");i.value=a.value,i.textContent=a.label,Array.isArray(n)?n.includes(a.value)&&(i.selected=!0):n!==void 0?n===a.value&&(i.selected=!0):e.default===a.value&&(i.selected=!0),t.appendChild(i)}),e.width&&(t.style.width=e.width),y=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((a,i)=>{let s=document.createElement("label");s.classList.add("voc-form-radio-label"),o&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let l=document.createElement("input");l.type="radio",l.classList.add("voc-form-radio"),o&&l.classList.add("form-check-input"),l.name=e.name||e.key||"",l.value=a.value,e.key&&(l.id=`voc-form-${e.key}-${i}`),Array.isArray(n)?n.includes(a.value)&&(l.checked=!0):n!==void 0?n===a.value&&(l.checked=!0):e.default===a.value&&(l.checked=!0),s.appendChild(l),s.appendChild(document.createTextNode(a.label)),t.appendChild(s)}),y=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let a=document.createElement("input");a.type="file",a.classList.add("voc-form-file"),o&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.width&&(a.style.width=e.width),e.required&&(a.required=!0),e.accept&&(a.accept=e.accept),e.multiple&&(a.multiple=!0),t.appendChild(a),y=t;break}case"avatar":{y=j(e,v||{},n);break}case"table":{y=G(e,v||{},n);break}case"users":{y=U(e,v||{},n);break}case"timezone":{y=V(e,v||{},n);break}case"audio_select":{y=W(e,v||{},n);break}case"field-select":{y=Y(e,v||{},n,w);break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),n!=null?t.value=String(n):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),y=t;break}}if(y&&m.appendChild(y),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,m.appendChild(t)}return m}L.fields.forEach(e=>{if(e.type==="group"&&"items"in e){let c=e;if(o){let h=document.createElement("div");h.className="card voc-form-group-card mb-3";let n=c.label||c.header?.title,m=c.description||c.header?.description;if(n||m){let t=document.createElement("div");if(t.className="card-header voc-form-group-head",n){let a=document.createElement("h5");a.className="mb-0 voc-form-group-label",a.textContent=n,t.appendChild(a)}if(m){let a=document.createElement("p");a.className="mb-0 voc-form-group-description",a.textContent=m,t.appendChild(a)}h.appendChild(t)}let y=document.createElement("div");y.className="card-body voc-form-group-body",c.items.forEach(t=>{if(t.type==="row"&&"items"in t){let a=t,i=document.createElement("div");if(i.className="voc-form-group voc-form-row mb-3",a.label){let l=document.createElement("h6");l.className="voc-form-row-label",l.textContent=a.label,i.appendChild(l)}let s=document.createElement("div");s.className="voc-form-row-items "+(a.direction||"horizontal"),a.items.forEach(l=>{let A=w(l);A&&s.appendChild(A)}),i.appendChild(s),y.appendChild(i)}else{let a=w(t);a&&y.appendChild(a)}}),h.appendChild(y),d.appendChild(h)}else{let h=document.createElement("div");h.className="voc-form-group voc-form-group-wrapper",o&&h.classList.add("mb-3");let n=c.label||c.header?.title,m=c.description||c.header?.description;if(n||m){let y=document.createElement("div");if(y.className="voc-form-group-head",n){let t=document.createElement("h3");t.className="voc-form-group-label",t.textContent=n,y.appendChild(t)}if(m){let t=document.createElement("p");t.className="voc-form-group-description",t.textContent=m,y.appendChild(t)}h.appendChild(y)}c.items.forEach(y=>{if(y.type==="row"&&"items"in y){let t=y,a=document.createElement("div");if(a.className="voc-form-group voc-form-row",o&&a.classList.add("mb-3"),t.label){let s=document.createElement("h4");s.className="voc-form-row-label",s.textContent=t.label,a.appendChild(s)}let i=document.createElement("div");i.className="voc-form-row-items "+(t.direction||"horizontal"),t.items.forEach(s=>{let l=w(s);l&&i.appendChild(l)}),a.appendChild(i),h.appendChild(a)}else{let t=w(y);t&&h.appendChild(t)}}),d.appendChild(h)}return}if(e.type==="row"&&"items"in e){let c=document.createElement("div");if(c.className="voc-form-group voc-form-row",o&&c.classList.add("mb-3"),e.label){let n=document.createElement("h3");n.className="voc-form-row-label",n.textContent=e.label,c.appendChild(n)}if(e.description){let n=document.createElement("p");n.className="voc-form-row-description",n.textContent=e.description,c.appendChild(n)}let h=document.createElement("div");h.className="voc-form-row-items "+(e.direction||"horizontal"),c.appendChild(h),e.items.forEach(n=>{let m=w(n);m&&h.appendChild(m)}),d.appendChild(c)}else{let c=w(e);c&&d.appendChild(c)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",o&&k.classList.add("btn","btn-primary"),d.appendChild(k),d}let b=f();C[0].appendChild(b);let u=L?.submit_config??v?.submit_config??null;return u&&b.addEventListener("submit",o=>{o.preventDefault();let d=Array.from(b.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),p=[];if(d.forEach(k=>{k&&typeof k._validateCheckboxGroup=="function"&&(k._validateCheckboxGroup()||k.querySelector('input[type="checkbox"]')&&p.push("Please select at least one option"))}),!b.checkValidity()){b.reportValidity(),v?.onSubmitResult&&v.onSubmitResult(null,new Error("Form validation failed"));return}let E=Array.from(b.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),w=[];if(E.forEach(k=>{if(k&&typeof k.validate=="function"){let e=k.validate();e&&e.length&&w.push(...e)}}),w.length){v?.onSubmitResult&&v.onSubmitResult(null,new Error(w.join("; ")));let k=E[0];k&&k.scrollIntoView({behavior:"smooth",block:"center"});return}if(v?.onSubmit){let k=I(b);v.onSubmit(k)}K(b,u,(k,e)=>{v?.onSubmitResult&&v.onSubmitResult(k,e)})}),{element:b,validate:()=>{let o=[];return b.querySelectorAll(":invalid").forEach(p=>{let E=p.validationMessage;o.push({element:p,message:E})}),o},getValues:()=>I(b),onSubmit:o=>{b.addEventListener("submit",d=>{d.preventDefault();let p=I(b);o(p,d)})}}}var z={renderForm:Q};var ce=z,de={FormsLib:z};0&&(module.exports={FormsLib});
package/dist/main.mjs CHANGED
@@ -1,2 +1,2 @@
1
- function V(s,N,v){let C=N?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-avatar-wrapper",C&&h.classList.add("d-flex","align-items-center","gap-3");let y=document.createElement("img");y.className="voc-form-avatar-preview",y.alt=s.label||"avatar",C&&(y.classList.add("img-thumbnail","rounded-circle"),y.style.width=y.style.height="64px",y.style.objectFit="cover");let u=v!=null?String(v):s.default!==void 0&&s.default!==null?String(s.default):"";u?y.src=u:(y.src="",y.style.display="none");let i=document.createElement("input");i.type="file",i.accept=s.accept||"image/*",i.className="voc-form-avatar-input",C&&i.classList.add("form-control"),(s.key||s.name)&&(i.name=s.name||s.key,s.key&&(i.id=`voc-form-${s.key}`));let d=document.createElement("input");if(d.type="hidden",(s.key||s.name)&&(d.name=(s.name||s.key)+"_url"),d.value=u||"",i.addEventListener("change",p=>{let g=p.target;if(g.files&&g.files.length>0){let T=g.files[0],L=new FileReader;L.onload=()=>{y.src=String(L.result),y.style.display="",d.value=""},L.readAsDataURL(T)}}),C){let p=document.createElement("div");p.style.flex="1",p.appendChild(i),p.appendChild(d),h.appendChild(y),h.appendChild(p)}else h.appendChild(y),h.appendChild(i),h.appendChild(d);return h}function U(s,N,v){let C=N?.style==="bootstrap",h=document.createElement("div");if(h.className="voc-form-audio-select",!s.options||s.options.length===0)return h;let y=s.name||s.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,u;return Array.isArray(v)?u=v[0]:v!==void 0?u=v:s.default!==void 0&&(u=s.default),s.options.forEach((i,d)=>{let p=document.createElement("div");p.className="voc-form-audio-item",C&&p.classList.add("form-check");let g=document.createElement("input");g.type="radio",g.name=y,g.value=i.value,g.className="voc-form-audio-radio",s.key&&(g.id=`voc-form-${s.key}-${d}`),s.required&&d===0&&(g.required=!0),g.style.position="absolute",g.style.width="1px",g.style.height="1px",g.style.margin="0",g.style.padding="0",g.style.clip="rect(0 0 0 0)",g.style.clipPath="inset(50%)",g.style.overflow="hidden",g.style.border="0",u!==void 0&&(Array.isArray(u)?g.checked=u.includes(i.value):g.checked=String(u)===String(i.value));let T=()=>{g.checked?p.classList.add("selected"):p.classList.remove("selected")};g.addEventListener("change",()=>{h.querySelectorAll(".voc-form-audio-item").forEach(n=>n.classList.remove("selected")),T()}),g.checked&&p.classList.add("selected");let L=document.createElement("label");L.className="voc-form-audio-label",C&&L.classList.add("form-check-label"),L.htmlFor=g.id||"",L.textContent=i.label||i.value,L.tabIndex=0;let e=document.createElement("div");e.className="voc-form-audio-control";let l=null;if(i.audio_link){let t=document.createElement("button");t.type="button",t.className="voc-form-audio-play",C&&t.classList.add("btn","btn-sm","btn-outline-secondary"),t.setAttribute("aria-label",`Play ${i.label||i.value}`);let n="http://www.w3.org/2000/svg",o=document.createElementNS(n,"svg");o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("width","16"),o.setAttribute("height","16"),o.setAttribute("aria-hidden","true");let r=document.createElementNS(n,"path");r.setAttribute("d","M8 5v14l11-7z"),r.setAttribute("fill","currentColor"),o.appendChild(r),t.appendChild(o),l=document.createElement("audio"),l.src=i.audio_link,l.preload="none",l.style.display="none";let c=f=>{for(;f.firstChild;)f.removeChild(f.firstChild)},A=()=>{let f="http://www.w3.org/2000/svg",$=document.createElementNS(f,"svg");$.setAttribute("viewBox","0 0 24 24"),$.setAttribute("width","16"),$.setAttribute("height","16"),$.setAttribute("aria-hidden","true");let q=document.createElementNS(f,"path");return q.setAttribute("d","M8 5v14l11-7z"),q.setAttribute("fill","currentColor"),$.appendChild(q),$},S=()=>{let f="http://www.w3.org/2000/svg",$=document.createElementNS(f,"svg");$.setAttribute("viewBox","0 0 24 24"),$.setAttribute("width","16"),$.setAttribute("height","16"),$.setAttribute("aria-hidden","true");let q=document.createElementNS(f,"rect");return q.setAttribute("x","6"),q.setAttribute("y","6"),q.setAttribute("width","12"),q.setAttribute("height","12"),q.setAttribute("fill","currentColor"),$.appendChild(q),$};c(t),t.appendChild(A());let M=f=>{c(t),f?(t.appendChild(S()),t.setAttribute("aria-label",`Stop ${i.label||i.value}`)):(t.appendChild(A()),t.setAttribute("aria-label",`Play ${i.label||i.value}`))};t.addEventListener("click",()=>{try{if(!l)return;let f=h.querySelectorAll("audio");if(!l.paused&&!l.ended){l.pause(),l.currentTime=0;return}f.forEach(q=>{try{q.pause(),q.currentTime=0}catch{}}),h.querySelectorAll(".voc-form-audio-item").forEach(q=>q.classList.remove("is-playing")),l.play()}catch(f){console.warn("audio play failed",f)}}),l.addEventListener("playing",()=>{p.classList.add("is-playing"),M(!0)});let _=()=>{p.classList.remove("is-playing"),M(!1)};l.addEventListener("pause",_),l.addEventListener("ended",_),e.appendChild(t),e.appendChild(l)}let m=document.createElement("div");m.className="voc-form-item-detail",m.style.display="flex",m.style.flexDirection="column",m.style.gap="4px";let a=document.createElement("div");a.className="voc-form-item-top",a.style.display="flex",a.style.alignItems="center",a.style.gap="8px",a.appendChild(g),a.appendChild(L);let E=document.createElement("div");E.className="voc-form-item-description";let w=i.description||i.hint_text||"";w&&(E.textContent=w),m.appendChild(a),m.appendChild(E),e.appendChild(m),p.appendChild(e),a.addEventListener("click",t=>{let n=t.target;n&&n.closest(".voc-form-audio-play")||(g.checked=!0,g.dispatchEvent(new Event("change",{bubbles:!0})))}),p.addEventListener("click",t=>{let n=t.target;n&&n.closest(".voc-form-audio-play")||(g.checked=!0,g.dispatchEvent(new Event("change",{bubbles:!0})))}),h.appendChild(p)}),h}function J(s,N,v){let C=document.createElement("div");C.className="voc-form-table-wrapper";let h=N?.style==="bootstrap",y=document.createElement("input");y.type="hidden",y.name=s.name||s.key,s.key&&(y.id=`voc-form-${s.key}`),C.appendChild(y);let u=document.createElement("table");u.className="voc-form-table",h&&u.classList.add("table","table-bordered");let i=document.createElement("thead"),d=document.createElement("tr"),p=document.createElement("th");p.className="voc-form-table-drag-col",p.textContent="",d.appendChild(p),(s.fields||[]).forEach(n=>{let o=document.createElement("th");o.textContent=n.label||n.key,d.appendChild(o)});let g=document.createElement("th");g.textContent="Actions",d.appendChild(g),i.appendChild(d),u.appendChild(i);let T=document.createElement("tbody");u.appendChild(T),C.appendChild(u);let L=document.createElement("button");L.type="button",L.className="voc-form-table-add",h&&L.classList.add("btn","btn-secondary"),L.textContent="+Add";let e=document.createElement("tfoot"),l=document.createElement("tr"),m=document.createElement("td");m.colSpan=(s.fields?s.fields.length:0)+1,m.appendChild(L),l.appendChild(m),e.appendChild(l),u.appendChild(e),C.appendChild(u);let a=[];function E(){y.value=JSON.stringify(a)}function w(n){let o=[];return s.fields.forEach(r=>{let c=n[r.key];if(r.type==="checkbox"){let A=Array.isArray(c)?c:c?[c]:[];r.required&&A.length===0&&o.push(`${r.label||r.key} is required`);return}r.required&&(c==null||String(c).trim()==="")&&o.push(`${r.label||r.key} is required`),r.type==="email"&&c&&(/^\S+@\S+\.\S+$/.test(String(c))||o.push(`${r.label||r.key} must be a valid email`)),r.type==="number"&&c&&isNaN(Number(c))&&o.push(`${r.label||r.key} must be a number`),r.validation&&r.validation.regex&&c&&(new RegExp(r.validation.regex).test(String(c))||o.push(`${r.label||r.key} invalid format`))}),o}function t(){T.innerHTML="";let n=(o,r)=>{r.draggable=!0,r.addEventListener("mousedown",()=>{r.style.cursor="grabbing"}),r.addEventListener("mouseup",()=>{r.style.cursor="grab"}),r.addEventListener("dragstart",c=>{let A=Number(o.dataset.rowIndex);c.dataTransfer.setData("text/plain",String(A)),o.classList.add("dragging");try{c.dataTransfer?.setDragImage(r,10,10)}catch{}}),r.addEventListener("dragend",()=>{o.classList.remove("dragging"),r.style.cursor="grab"}),o.addEventListener("dragover",c=>{c.preventDefault();let A=c.currentTarget,S=A.getBoundingClientRect(),M=S.top+S.height/2,_=(c.clientY||c.y)>M;A.classList.remove("drag-over-top","drag-over-bottom"),_?(A.classList.add("drag-over-bottom"),A.dataset.dropPosition="after"):(A.classList.add("drag-over-top"),A.dataset.dropPosition="before")}),o.addEventListener("dragleave",c=>{let A=c.currentTarget;A.classList.remove("drag-over-top","drag-over-bottom"),delete A.dataset.dropPosition}),o.addEventListener("drop",c=>{c.preventDefault();let A=c.dataTransfer.getData("text/plain"),S=Number(c.currentTarget.dataset.rowIndex),M=Number(A),_=c.currentTarget.dataset.dropPosition||"before";if(isNaN(M)||isNaN(S))return;let[f]=a.splice(M,1),$=S;M<S&&($=S-1);let q=_==="after"?$+1:$;a.splice(q,0,f),c.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete c.currentTarget.dataset.dropPosition,t(),E()})};a.forEach((o,r)=>{let c=document.createElement("tr");c.dataset.rowIndex=String(r),c.classList.add("voc-form-table-row");let A=document.createElement("td");A.className="voc-form-table-drag-handle";let S=document.createElement("span");S.className="voc-form-drag-handle-icon",S.textContent="\u2630",S.style.cursor="grab",A.appendChild(S),c.appendChild(A),n(c,S),s.fields.forEach(f=>{let $=document.createElement("td"),q,x=(f.type||"text").toLowerCase();if(x==="select"){let b=document.createElement("select");if(b.className="voc-form-table-cell",h&&b.classList.add("form-control"),f.placeholder){let k=document.createElement("option");k.value="",k.textContent=f.placeholder,k.disabled=!0,(o[f.key]===void 0||o[f.key]===null||o[f.key]==="")&&(k.selected=!0),b.appendChild(k)}(f.options||[]).forEach(k=>{let O=document.createElement("option");O.value=k.value,O.textContent=k.label,b.appendChild(O)}),b.value=o[f.key]!==void 0&&o[f.key]!==null?String(o[f.key]):"",f.required&&(b.required=!0),b.addEventListener("change",k=>{a[r][f.key]=k.target.value,E()}),q=b}else if(x==="checkbox"){let b=document.createElement("div");b.className="voc-form-table-checkboxes",h&&b.classList.add("form-check");let F=f.options||[];Array.isArray(a[r][f.key])||(a[r][f.key]=a[r][f.key]?[a[r][f.key]]:[]),F.forEach(k=>{let O=`voc-form-${s.key}-${f.key}-${r}-${k.value}`,B=document.createElement("div");B.className="voc-form-table-checkbox-item",h&&B.classList.add("form-check");let H=document.createElement("input");H.type="checkbox",H.className="voc-form-table-cell",h&&H.classList.add("form-check-input"),H.id=O,H.value=k.value,H.checked=Array.isArray(a[r][f.key])&&a[r][f.key].includes(k.value),H.addEventListener("change",z=>{let I=z.target.checked;Array.isArray(a[r][f.key])||(a[r][f.key]=[]),I?a[r][f.key].includes(k.value)||a[r][f.key].push(k.value):a[r][f.key]=a[r][f.key].filter(R=>R!==k.value),E()});let D=document.createElement("label");D.htmlFor=O,D.className="voc-form-table-checkbox-label",h&&D.classList.add("form-check-label"),D.textContent=k.label,B.appendChild(H),B.appendChild(D),b.appendChild(B)}),q=b}else if(x==="radio"){let b=document.createElement("div");b.className="voc-form-table-radios",h&&b.classList.add("form-check");let F=f.options||[];a[r][f.key]===void 0&&(a[r][f.key]=""),F.forEach(k=>{let O=`voc-form-${s.key}-${f.key}-${r}-${k.value}`,B=document.createElement("div");B.className="voc-form-table-radio-item",h&&B.classList.add("form-check");let H=document.createElement("input");H.type="radio",H.className="voc-form-table-cell",h&&H.classList.add("form-check-input"),H.id=O,H.name=`voc-form-${s.key}-${f.key}-${r}`,H.value=k.value,H.checked=a[r][f.key]===k.value,H.addEventListener("change",z=>{z.target.checked&&(a[r][f.key]=z.target.value,E())});let D=document.createElement("label");D.htmlFor=O,D.className="voc-form-table-radio-label",h&&D.classList.add("form-check-label"),D.textContent=k.label,B.appendChild(H),B.appendChild(D),b.appendChild(B)}),q=b}else{let b=document.createElement("input");x==="number"?b.type="number":x==="email"?b.type="email":x==="tel"?b.type="tel":x==="url"?b.type="url":x==="date"?b.type="date":b.type="text",b.value=o[f.key]!==void 0&&o[f.key]!==null?String(o[f.key]):"",f.placeholder&&(b.placeholder=f.placeholder),f.required&&(b.required=!0),b.className="voc-form-table-cell",h&&b.classList.add("form-control"),b.addEventListener("input",F=>{a[r][f.key]=F.target.value,E()}),q=b}$.appendChild(q),c.appendChild($)});let M=document.createElement("td"),_=document.createElement("button");_.type="button",_.className="voc-form-table-remove",h&&_.classList.add("btn","btn-danger"),_.textContent="Remove",_.addEventListener("click",()=>{a.splice(r,1),t(),E()}),M.appendChild(_),c.appendChild(M),T.appendChild(c)})}return L.addEventListener("click",()=>{if(s.validation?.max_rows!==void 0&&a.length>=s.validation.max_rows)return;let n={};s.fields.forEach(o=>n[o.key]=""),a.push(n),t(),E()}),Array.isArray(v)&&v.length?a=v.map(n=>({...n})):s.default&&Array.isArray(s.default)&&(a=s.default.map(n=>({...n}))),t(),E(),C.validate=function(){let n=[];return a.forEach((o,r)=>{let c=w(o);c.length&&n.push(`Row ${r+1}: ${c.join("; ")}`)}),s.validation?.min_rows!==void 0&&a.length<s.validation.min_rows&&n.push(`At least ${s.validation.min_rows} rows required`),s.validation?.max_rows!==void 0&&a.length>s.validation.max_rows&&n.push(`No more than ${s.validation.max_rows} rows allowed`),s.validation?.unique_fields&&s.validation.unique_fields.length&&s.validation.unique_fields.forEach(o=>{let r=new Set;a.forEach((c,A)=>{let S=c[o];S!=null&&(r.has(S)&&n.push(`Field ${o} must be unique (duplicate at row ${A+1})`),r.add(S))})}),n},C}async function ee(s){let v=new TextEncoder().encode(s),C=await crypto.subtle.digest("SHA-256",v);return Array.from(new Uint8Array(C)).map(y=>y.toString(16).padStart(2,"0")).join("")}async function te(s){let N=String(s||"").trim().toLowerCase();return N?`https://gravatar.com/avatar/${await ee(N)}?d=mp`:""}function Y(s,N,v){let C=N?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-users";let y=document.createElement("div");if(y.className="voc-form-users-header",C&&y.classList.add("mb-2"),s.label){let e=document.createElement("div");if(e.className="voc-form-users-label",C&&e.classList.add("form-label"),e.textContent=s.label,s.required){let l=document.createElement("span");l.className="voc-form-required",l.textContent="*",e.appendChild(l)}y.appendChild(e)}if(s.description){let e=document.createElement("div");e.className="voc-form-users-description",C&&e.classList.add("form-text"),e.textContent=s.description,y.appendChild(e)}h.appendChild(y);let u=document.createElement("div");u.className="voc-form-users-search-wrapper";let i=document.createElement("input");if(i.type="search",i.placeholder="Search users...",i.className="voc-form-users-search",C&&i.classList.add("form-control","mb-2"),u.appendChild(i),h.appendChild(u),!s.options||s.options.length===0)return h;let d=document.createElement("div");d.className="voc-form-users-list",C&&d.classList.add("list-group");let p=s.name||s.key||`users_${Math.random().toString(36).substr(2,6)}`,g=[];if(Array.isArray(v)?g=v:v!=null?g=[v]:Array.isArray(s.default)&&(g=s.default),s.options.forEach((e,l)=>{let m=document.createElement("div");m.className="voc-form-user-item",m.dataset.label=String(e.label||"").toLowerCase(),m.dataset.email=String(e.email||"").toLowerCase(),m.dataset.value=String(e.value||"").toLowerCase(),C&&m.classList.add("d-flex","align-items-center","gap-2");let a=document.createElement("input");if(a.type="checkbox",a.name=`${p}[]`,a.value=e.value,a.className="voc-form-user-checkbox",s.key&&(a.id=`voc-form-${s.key}-${l}`),a.style.position="absolute",a.style.width="1px",a.style.height="1px",a.style.margin="0",a.style.padding="0",a.style.clip="rect(0 0 0 0)",a.style.clipPath="inset(50%)",a.style.overflow="hidden",a.style.border="0",g&&Array.isArray(g)){let o=g.map(r=>String(r));a.checked=o.includes(String(e.value))}let E=document.createElement("img");E.className="voc-form-user-avatar",E.alt=e.label||String(e.value||"user"),E.style.width=E.style.height="40px",E.style.objectFit="cover",E.style.borderRadius="50%",E.src="",e.email&&te(e.email).then(o=>{o&&(E.src=o)}).catch(()=>{});let w=document.createElement("div");w.className="voc-form-user-info",w.style.display="flex",w.style.flexDirection="column",w.style.gap="2px";let t=document.createElement("div");t.className="voc-form-user-label",t.textContent=e.label||String(e.value);let n=document.createElement("small");n.className="voc-form-user-email",n.textContent=e.email||"",w.appendChild(t),w.appendChild(n),m.addEventListener("click",o=>{let r=o.target;r&&(r.closest("input")||r.closest("a")||r.closest("button"))||(a.checked=!a.checked,a.dispatchEvent(new Event("change",{bubbles:!0})))}),a.addEventListener("change",()=>{a.checked?m.classList.add("selected"):m.classList.remove("selected")}),a.checked&&m.classList.add("selected"),m.appendChild(a),m.appendChild(E),m.appendChild(w),d.appendChild(m)}),h.appendChild(d),s.required){let e=d.querySelectorAll('input[type="checkbox"]'),l=()=>{let m=Array.from(e).some(a=>a.checked);return e.forEach(a=>{m?a.setCustomValidity(""):a.setCustomValidity("At least one option must be selected.")}),m};e.forEach(m=>{m.addEventListener("change",l)}),h._validateCheckboxGroup=l,l()}let T=Array.from(d.querySelectorAll(".voc-form-user-item")),L=()=>{let e=String(i.value||"").trim().toLowerCase();if(!e){T.forEach(l=>l.style.setProperty("display","flex","important"));return}T.forEach(l=>{let m=l.dataset.label||"",a=l.dataset.email||"",E=l.dataset.value||"",w=m.includes(e)||a.includes(e)||E.includes(e);l.style.setProperty("display",w?"flex":"none","important")})};return i.addEventListener("input",L),h}function K(s,N,v){let C=N?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-timezone";let y=s.name||s.key||`timezone_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("input");u.type="text",u.name=y,s.key&&(u.id=`voc-form-${s.key}`),u.className="voc-form-timezone-input",C&&u.classList.add("form-control"),s.placeholder&&(u.placeholder=s.placeholder||""),s.required&&(u.required=!0),s.width&&(u.style.width=s.width);try{u.autocomplete="off"}catch{}try{u.autocorrect="off"}catch{}try{u.autocapitalize="off"}catch{}try{u.spellcheck=!1}catch{}u.setAttribute("data-lpignore","true"),v!=null?u.value=String(v):s.default!==void 0&&s.default!==null&&(u.value=String(s.default));let i=document.createElement("div");i.className="voc-form-timezone-control",i.style.position="relative",i.style.display="inline-block",i.style.width=s.width||"100%";let d=document.createElement("button");d.type="button",d.className="voc-form-timezone-toggle",d.setAttribute("aria-haspopup","listbox"),d.setAttribute("aria-expanded","false"),d.style.position="absolute",d.style.right="4px",d.style.top="50%",d.style.transform="translateY(-50%)",d.style.height="28px",d.style.width="28px",d.style.padding="0",d.style.border="none",d.style.background="transparent",d.style.cursor="pointer",d.innerHTML="\u25BC";let p=document.createElement("ul");p.className="voc-form-timezone-list",p.setAttribute("role","listbox"),p.style.position="absolute",p.style.left="0",p.style.right="0",p.style.zIndex="1000",p.style.maxHeight="200px",p.style.overflow="auto",p.style.margin="4px 0 0 0",p.style.padding="0",p.style.listStyle="none",p.style.background="white",p.style.border="1px solid rgba(0,0,0,0.15)",p.style.display="none",p.tabIndex=-1,u.style.paddingRight="36px";let T=["UTC","ETC","AEST","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Vancouver","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Amsterdam","Asia/Tokyo","Asia/Shanghai","Asia/Singapore","Asia/Kolkata","Asia/Dubai","Australia/Lindeman","Australia/Brisbane","Australia/Sydney","Australia/Melbourne","Australia/Hobart","Australia/Currie","Australia/Broken_Hill","Australia/Lord_Howe","Australia/Adelaide","Australia/Darwin","Australia/Perth","Australia/Eucla","Australia/ACT","ACT","Pacific/Auckland","America/Sao_Paulo","America/Mexico_City","Africa/Cairo","Africa/Johannesburg"];function L(t){p.innerHTML="",t.forEach((n,o)=>{let r=document.createElement("li");r.className="voc-form-timezone-item",r.setAttribute("role","option"),r.dataset.value=n,r.style.padding="6px 8px",r.style.cursor="pointer",r.textContent=n,r.addEventListener("mousedown",c=>{c.preventDefault(),u.value=n,a(),u.dispatchEvent(new Event("change",{bubbles:!0}))}),p.appendChild(r)})}L(T);let e=-1;function l(){Array.from(p.children).forEach((n,o)=>{o===e?(n.style.background="rgba(0,123,255,0.1)",n.setAttribute("aria-selected","true")):(n.style.background="",n.removeAttribute("aria-selected"))})}function m(){p.style.display="block",d.setAttribute("aria-expanded","true")}function a(){p.style.display="none",d.setAttribute("aria-expanded","false"),e=-1,l()}function E(){p.style.display==="none"?m():a()}u.addEventListener("input",()=>{let t=(u.value||"").trim().toLowerCase(),n=t?T.filter(o=>o.toLowerCase().includes(t)):T;L(n),m()}),d.addEventListener("click",t=>{t.preventDefault(),p.style.display==="none"?(L(T),m(),u.focus()):a()}),u.addEventListener("keydown",t=>{let n=Array.from(p.children);if(t.key==="ArrowDown"){if(t.preventDefault(),n.length===0)return;e=Math.min(e+1,n.length-1),l(),n[e].scrollIntoView({block:"nearest"})}else if(t.key==="ArrowUp"){if(t.preventDefault(),n.length===0)return;e=Math.max(e-1,0),l(),n[e].scrollIntoView({block:"nearest"})}else if(t.key==="Enter"){if(p.style.display!=="none"&&e>=0){t.preventDefault();let o=n[e];u.value=o.dataset.value||o.textContent||"",a(),u.dispatchEvent(new Event("change",{bubbles:!0}))}}else t.key==="Escape"&&a()}),document.addEventListener("click",t=>{i.contains(t.target)||a()});let w={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(u.addEventListener("blur",()=>{let t=(u.value||"").trim();if(!t)return;let n=Object.keys(w).find(o=>o.toLowerCase()===t.toLowerCase());n&&(u.value=w[n])}),s.description){let t=document.createElement("div");t.className="voc-form-timezone-description",C&&t.classList.add("form-text"),t.textContent=s.description,h.appendChild(t)}return i.appendChild(u),i.appendChild(d),i.appendChild(p),h.appendChild(i),h}function Q(s,N,v){let C=N?.style==="bootstrap",h=document.createElement("div");h.className="voc-form-tags";let y=s.name||s.key||`tags_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("div");u.className="voc-form-tags-container",u.style.display="flex",u.style.flexWrap="wrap",u.style.gap="6px",u.style.alignItems="center",u.style.padding="6px",u.style.border="1px solid rgba(0,0,0,0.12)",u.style.borderRadius="4px";let i=document.createElement("input");i.type="text",i.className="voc-form-tags-input",i.style.border="none",i.style.flex="1 0 120px",i.style.minWidth="80px",i.style.outline="none",i.placeholder=s.placeholder||"",C&&i.classList.add("form-control"),u.appendChild(i);let d=[],p=document.createElement("input");p.type="text",p.style.position="absolute",p.style.left="-9999px",p.style.width="1px",p.style.height="1px",p.tabIndex=-1,s.required&&(p.required=!0),h.appendChild(p);function g(){Array.from(h.querySelectorAll("input.voc-form-tag-hidden")).forEach(m=>m.parentElement?.removeChild(m)),d.forEach(m=>{let a=document.createElement("input");a.type="hidden",a.name=`${y}[]`,a.className="voc-form-tag-hidden",a.value=m,s.key&&(a.id=`voc-form-${s.key}`),h.appendChild(a)}),s.required&&(d.length===0?(p.value="",p.setCustomValidity("Please enter at least one tag")):(p.value="1",p.setCustomValidity("")))}function T(l){let m=document.createElement("span");m.className="voc-form-tag",m.style.display="inline-flex",m.style.alignItems="center",m.style.padding="4px 8px",m.style.background="rgba(0,0,0,0.05)",m.style.borderRadius="16px";let a=document.createElement("span");a.textContent=l,a.style.marginRight="8px",m.appendChild(a);let E=document.createElement("button");return E.type="button",E.textContent="\xD7",E.style.border="none",E.style.background="transparent",E.style.cursor="pointer",E.addEventListener("click",()=>{let w=d.indexOf(l);w>=0&&(d.splice(w,1),u.removeChild(m),g())}),m.appendChild(E),m}function L(l){let m=l.trim();if(!m||d.includes(m))return;d.push(m);let a=T(m);u.insertBefore(a,i),g()}let e=v!=null?String(v):s.default||"";return e&&e.split(",").map(l=>l.trim()).filter(Boolean).forEach(L),i.addEventListener("keydown",l=>{if(l.key==="Enter"||l.key===",")l.preventDefault(),L(i.value),i.value="";else if(l.key==="Backspace"&&i.value===""&&d.pop()){let a=Array.from(u.querySelectorAll(".voc-form-tag")),E=a[a.length-1];E&&u.removeChild(E),g()}}),i.addEventListener("paste",l=>{let m=l.clipboardData?.getData("text");m&&(l.preventDefault(),m.split(/[,\n\r]+/).map(a=>a.trim()).filter(Boolean).forEach(L),i.value="")}),h.getTags=()=>d.slice(),h.addTag=L,h.appendChild(u),g(),h}function j(s,N=!0){let v=new FormData(s);if(N)return ae(v);let C={};return v.forEach((h,y)=>{let u=(h instanceof File,h);Object.prototype.hasOwnProperty.call(C,y)?Array.isArray(C[y])?C[y].push(u):C[y]=[C[y],u]:C[y]=u}),C}function ae(s){let N=new FormData;for(let[v,C]of s.entries()){if(C instanceof File){N.append(v,C);continue}let h;try{h=JSON.parse(C)}catch{h=null}Array.isArray(h)?h.length===0?N.append(v,"[]"):h.every(y=>typeof y=="object"&&y!==null)?h.forEach((y,u)=>{for(let[i,d]of Object.entries(y))N.append(`${v}[${u}][${i}]`,d)}):N.append(v,C):N.append(v,C)}return N}async function X(s,N,v){let C=N.url,h={"Content-Type":"application/json"};N?.api_token&&(h.Authorization=`Bearer ${N.api_token}`);let y=j(s);if(N?.additional_data)for(let[d,p]of Object.entries(N.additional_data))y.append(d,p);let u,i=y instanceof FormData;u={method:"POST",headers:{Authorization:`Bearer ${N.api_token}`,...i?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:i?y:JSON.stringify(Object.fromEntries(y.entries()))};try{fetch(C,u).then(async d=>{let p=d.headers.get("content-type");if(!d.ok)try{let T=(await d.json())?.message;throw new Error(T??"Their was an error submitting the form. Check your form and try again.")}catch(g){throw new Error(g.message)}return p&&p.includes("application/json")?d.json():d.text()}).then(d=>{v&&v(d,null)}).catch(d=>{v&&v(null,d)})}catch(d){v&&v(null,d)}}function Z(s,N,v){let C=[];if(typeof s=="string"?C=Array.from(document.querySelectorAll(s)):C=[s],C.length===0)return null;function h(){let i=v?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),i&&d.classList.add("needs-validation"),d.id=N.id;let p=document.createElement("h2");p.className="voc-form-title",i&&p.classList.add("mb-3"),p.textContent=N.form_name,d.appendChild(p);function g(e,l){l&&(l.min_length!==void 0&&(e.minLength=l.min_length),l.max_length!==void 0&&(e.maxLength=l.max_length),l.regex&&(e instanceof HTMLInputElement?e.pattern=l.regex:e.dataset.pattern=l.regex))}function T(e){if(!e.key&&!e.label)return null;let l=N.default_values||{},m=e.name||e.key,a=m?l[m]:void 0,E=document.createElement("div");if(E.className="voc-form-group",i&&E.classList.add("mb-3"),e.label&&e.type!=="users"){let t=document.createElement("label");if(t.classList.add("voc-form-label"),i&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label,e.required){let n=document.createElement("span");n.className="voc-form-required",n.textContent="*",t.appendChild(n)}E.appendChild(t)}let w=null;switch(e.type){case"tags":{w=Q(e,v||{},a);break}case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options){if(e.options.forEach((n,o)=>{let r=document.createElement("label");r.classList.add("voc-form-checkbox-label"),i&&r.classList.add("form-check"),r.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(r.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),i&&c.classList.add("form-check-input"),c.name=`${e.name||e.key||""}[]`,c.value=n.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),Array.isArray(a)?a.includes(n.value)&&(c.checked=!0):a!==void 0?a===n.value&&(c.checked=!0):e.default===n.value&&(c.checked=!0),r.appendChild(c),r.appendChild(document.createTextNode(n.label)),t.appendChild(r)}),e.required){let n=t.querySelectorAll('input[type="checkbox"]'),o=()=>{let r=Array.from(n).some(c=>c.checked);return n.forEach(c=>{r?c.setCustomValidity(""):c.setCustomValidity("At least one option must be selected.")}),r};n.forEach(r=>{r.addEventListener("change",o)}),t._validateCheckboxGroup=o,o()}}else{let n=document.createElement("label");n.classList.add("voc-form-checkbox-label"),i&&n.classList.add("form-check"),e.width&&(n.style.width=e.width);let o=document.createElement("input");o.type="checkbox",o.classList.add("voc-form-checkbox"),(e.key||e.name)&&(o.name=e.name||e.key,e.key&&(o.id=`voc-form-${e.key}`)),i&&o.classList.add("form-check-input"),e.required&&(o.required=!0),a!==void 0?o.checked=!!a:e.default&&(o.checked=!!e.default),n.appendChild(o),n.appendChild(document.createTextNode(e.label||"")),t.appendChild(n)}w=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),a!=null?t.value=String(a):e.default!==void 0&&e.default!==null&&(t.value=String(e.default));let n=e.default||a||"";if(n){let o=(n.match(/\n/g)||[]).length,r=80,c=n.split(`
2
- `).reduce((M,_)=>Math.max(M,_.length),0),A=Math.ceil(c/r)||1,S=Math.max(2,o+A);t.rows=S,t.style.resize="vertical"}e.width&&(t.style.width=e.width),e.required&&(t.required=!0),g(t,e.validation),w=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),i&&t.classList.add("form-select"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let n=document.createElement("option");n.value="",n.textContent=e.placeholder,n.disabled=!0,n.selected=!0,t.appendChild(n)}e.required&&(t.required=!0),e.options&&e.options.forEach(n=>{let o=document.createElement("option");o.value=n.value,o.textContent=n.label,Array.isArray(a)?a.includes(n.value)&&(o.selected=!0):a!==void 0?a===n.value&&(o.selected=!0):e.default===n.value&&(o.selected=!0),t.appendChild(o)}),e.width&&(t.style.width=e.width),w=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((n,o)=>{let r=document.createElement("label");r.classList.add("voc-form-radio-label"),i&&r.classList.add("form-check"),r.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(r.style.width=e.width);let c=document.createElement("input");c.type="radio",c.classList.add("voc-form-radio"),i&&c.classList.add("form-check-input"),c.name=e.name||e.key||"",c.value=n.value,e.key&&(c.id=`voc-form-${e.key}-${o}`),Array.isArray(a)?a.includes(n.value)&&(c.checked=!0):a!==void 0?a===n.value&&(c.checked=!0):e.default===n.value&&(c.checked=!0),r.appendChild(c),r.appendChild(document.createTextNode(n.label)),t.appendChild(r)}),w=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let n=document.createElement("input");n.type="file",n.classList.add("voc-form-file"),i&&n.classList.add("form-control"),(e.key||e.name)&&(n.name=e.name||e.key,e.key&&(n.id=`voc-form-${e.key}`)),e.width&&(n.style.width=e.width),e.required&&(n.required=!0),e.accept&&(n.accept=e.accept),e.multiple&&(n.multiple=!0),t.appendChild(n),w=t;break}case"avatar":{w=V(e,v||{},a);break}case"table":{w=J(e,v||{},a);break}case"users":{w=Y(e,v||{},a);break}case"timezone":{w=K(e,v||{},a);break}case"audio_select":{w=U(e,v||{},a);break}case"field-select":{let t=v?.style==="bootstrap",n=document.createElement("div");n.className="voc-form-field-selects";let o=document.createElement("div");if(o.className="voc-form-field-selects-header",t&&o.classList.add("mb-2"),e.label){let x=document.createElement("div");if(x.className="voc-form-field-selects-label",t&&x.classList.add("form-label"),x.textContent=e.label,e.required){let b=document.createElement("span");b.className="voc-form-required",b.textContent="*",x.appendChild(b)}o.appendChild(x)}if(e.description){let x=document.createElement("div");x.className="voc-form-field-selects-description",t&&x.classList.add("form-text"),x.textContent=e.description,o.appendChild(x)}n.appendChild(o);let r=document.createElement("div");r.className="voc-form-field-selects-search-wrapper";let c=document.createElement("input");if(c.type="search",c.placeholder="Search...",c.className="voc-form-field-selects-search",t&&c.classList.add("form-control","mb-2"),r.appendChild(c),n.appendChild(r),!e.options||e.options.length===0)return n;let A=document.createElement("div");A.className="voc-form-field-selects-list",t&&A.classList.add("list-group");let S=document.createElement("div");S.className="voc-form-field-selects-selected",S.style.marginTop="12px";let M={},_=e.name||e.key||`users_${Math.random().toString(36).substr(2,6)}`,f=[];if(Array.isArray(a)?f=a:a!=null?f=[a]:Array.isArray(e.default)&&(f=e.default),e.options.forEach((x,b)=>{let F=document.createElement("div");F.className="voc-form-field-selects-item",F.dataset.label=String(x.label||"").toLowerCase(),F.dataset.email=String(x.email||"").toLowerCase(),F.dataset.value=String(x.value||"").toLowerCase(),t&&F.classList.add("d-flex","align-items-center","gap-2");let k=document.createElement("input");if(k.type="checkbox",k.name=`${_}[]`,k.value=x.value??x.key,k.className="voc-form--checkbox",e.key&&(k.id=`voc-form-${e.key}-${b}`),k.style.position="absolute",k.style.width="1px",k.style.height="1px",k.style.margin="0",k.style.padding="0",k.style.clip="rect(0 0 0 0)",k.style.clipPath="inset(50%)",k.style.overflow="hidden",k.style.border="0",f&&Array.isArray(f)){let I=f.map(P=>String(P)),R=String(x.value??x.key);k.checked=I.includes(R)}let O=x.icon||'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><!-- Icon from Google Material Icons by Material Design Authors - https://github.com/material-icons/material-icons/blob/master/LICENSE --><path fill="currentColor" d="M14 11c0 .55-.45 1-1 1H4c-.55 0-1-.45-1-1s.45-1 1-1h9c.55 0 1 .45 1 1M3 7c0 .55.45 1 1 1h9c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1m7 8c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1m8.01-2.13l.71-.71a.996.996 0 0 1 1.41 0l.71.71c.39.39.39 1.02 0 1.41l-.71.71zm-.71.71l-5.16 5.16c-.09.09-.14.21-.14.35v1.41c0 .28.22.5.5.5h1.41c.13 0 .26-.05.35-.15l5.16-5.16z"/></svg>',B=document.createElement("div");B.className="voc-form-fields-select-avatar",B.innerHTML=O;let H=document.createElement("div");H.className="voc-form-field-select-info",H.style.display="flex",H.style.flexDirection="column",H.style.gap="2px";let D=document.createElement("div");D.className="voc-form-field-select-label",D.textContent=x.label||String(x.value);let z=document.createElement("small");z.className="voc-form-field-select-email",z.textContent=x.email||"",H.appendChild(D),H.appendChild(z),F.addEventListener("click",I=>{let R=I.target;R&&(R.closest("input")||R.closest("a")||R.closest("button"))||(k.checked=!k.checked,k.dispatchEvent(new Event("change",{bubbles:!0})))}),k.addEventListener("change",()=>{if(k.checked){F.classList.add("selected"),(M[b]||[]).forEach(P=>P.parentElement?.removeChild(P)),M[b]=[];let R=x;if(R&&Array.isArray(R.items))R.items.forEach(P=>{let W=T(P);W&&(S.appendChild(W),M[b].push(W))});else if(R&&(R.type||R.key)){let P=T(R);P&&(S.appendChild(P),M[b].push(P))}}else F.classList.remove("selected"),(M[b]||[]).forEach(R=>R.parentElement?.removeChild(R)),M[b]=[]}),k.checked&&(F.classList.add("selected"),setTimeout(()=>{let I=x;if(I&&Array.isArray(I.items))I.items.forEach(R=>{let P=T(R);P&&(S.appendChild(P),M[b]=M[b]||[],M[b].push(P))});else if(I&&(I.type||I.key)){let R=T(I);R&&(S.appendChild(R),M[b]=M[b]||[],M[b].push(R))}},0)),F.appendChild(k),F.appendChild(B),F.appendChild(H),A.appendChild(F)}),n.appendChild(A),n.appendChild(S),e.required){let x=A.querySelectorAll('input[type="checkbox"]'),b=()=>{let F=Array.from(x).some(k=>k.checked);return x.forEach(k=>{F?k.setCustomValidity(""):k.setCustomValidity("At least one option must be selected.")}),F};x.forEach(F=>{F.addEventListener("change",b)}),n._validateCheckboxGroup=b,b()}let $=Array.from(A.querySelectorAll(".voc-form-field-select-item")),q=()=>{let x=String(c.value||"").trim().toLowerCase();if(!x){$.forEach(b=>b.style.setProperty("display","flex","important"));return}$.forEach(b=>{let F=b.dataset.label||"",k=b.dataset.email||"",O=b.dataset.value||"",B=F.includes(x)||k.includes(x)||O.includes(x);b.style.setProperty("display",B?"flex":"none","important")})};return c.addEventListener("input",q),n}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),i&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),a!=null?t.value=String(a):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),g(t,e.validation),w=t;break}}if(w&&E.appendChild(w),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,E.appendChild(t)}return E}N.fields.forEach(e=>{if(e.type==="group"&&"items"in e){let l=e;if(i){let m=document.createElement("div");m.className="card voc-form-group-card mb-3";let a=l.label||l.header?.title,E=l.description||l.header?.description;if(a||E){let t=document.createElement("div");if(t.className="card-header voc-form-group-head",a){let n=document.createElement("h5");n.className="mb-0 voc-form-group-label",n.textContent=a,t.appendChild(n)}if(E){let n=document.createElement("p");n.className="mb-0 voc-form-group-description",n.textContent=E,t.appendChild(n)}m.appendChild(t)}let w=document.createElement("div");w.className="card-body voc-form-group-body",l.items.forEach(t=>{if(t.type==="row"&&"items"in t){let n=t,o=document.createElement("div");if(o.className="voc-form-group voc-form-row mb-3",n.label){let c=document.createElement("h6");c.className="voc-form-row-label",c.textContent=n.label,o.appendChild(c)}let r=document.createElement("div");r.className="voc-form-row-items "+(n.direction||"horizontal"),n.items.forEach(c=>{let A=T(c);A&&r.appendChild(A)}),o.appendChild(r),w.appendChild(o)}else{let n=T(t);n&&w.appendChild(n)}}),m.appendChild(w),d.appendChild(m)}else{let m=document.createElement("div");m.className="voc-form-group voc-form-group-wrapper",i&&m.classList.add("mb-3");let a=l.label||l.header?.title,E=l.description||l.header?.description;if(a||E){let w=document.createElement("div");if(w.className="voc-form-group-head",a){let t=document.createElement("h3");t.className="voc-form-group-label",t.textContent=a,w.appendChild(t)}if(E){let t=document.createElement("p");t.className="voc-form-group-description",t.textContent=E,w.appendChild(t)}m.appendChild(w)}l.items.forEach(w=>{if(w.type==="row"&&"items"in w){let t=w,n=document.createElement("div");if(n.className="voc-form-group voc-form-row",i&&n.classList.add("mb-3"),t.label){let r=document.createElement("h4");r.className="voc-form-row-label",r.textContent=t.label,n.appendChild(r)}let o=document.createElement("div");o.className="voc-form-row-items "+(t.direction||"horizontal"),t.items.forEach(r=>{let c=T(r);c&&o.appendChild(c)}),n.appendChild(o),m.appendChild(n)}else{let t=T(w);t&&m.appendChild(t)}}),d.appendChild(m)}return}if(e.type==="row"&&"items"in e){let l=document.createElement("div");if(l.className="voc-form-group voc-form-row",i&&l.classList.add("mb-3"),e.label){let a=document.createElement("h3");a.className="voc-form-row-label",a.textContent=e.label,l.appendChild(a)}if(e.description){let a=document.createElement("p");a.className="voc-form-row-description",a.textContent=e.description,l.appendChild(a)}let m=document.createElement("div");m.className="voc-form-row-items "+(e.direction||"horizontal"),l.appendChild(m),e.items.forEach(a=>{let E=T(a);E&&m.appendChild(E)}),d.appendChild(l)}else{let l=T(e);l&&d.appendChild(l)}});let L=document.createElement("button");return L.type="submit",L.className="voc-form-submit",L.textContent="Submit",i&&L.classList.add("btn","btn-primary"),d.appendChild(L),d}let y=h();C[0].appendChild(y);let u=N?.submit_config??v?.submit_config??null;return u&&y.addEventListener("submit",i=>{i.preventDefault();let d=Array.from(y.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),p=[];if(d.forEach(L=>{L&&typeof L._validateCheckboxGroup=="function"&&(L._validateCheckboxGroup()||L.querySelector('input[type="checkbox"]')&&p.push("Please select at least one option"))}),!y.checkValidity()){y.reportValidity(),v?.onSubmitResult&&v.onSubmitResult(null,new Error("Form validation failed"));return}let g=Array.from(y.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),T=[];if(g.forEach(L=>{if(L&&typeof L.validate=="function"){let e=L.validate();e&&e.length&&T.push(...e)}}),T.length){v?.onSubmitResult&&v.onSubmitResult(null,new Error(T.join("; ")));let L=g[0];L&&L.scrollIntoView({behavior:"smooth",block:"center"});return}if(v?.onSubmit){let L=j(y);v.onSubmit(L)}X(y,u,(L,e)=>{v?.onSubmitResult&&v.onSubmitResult(L,e)})}),{element:y,validate:()=>{let i=[];return y.querySelectorAll(":invalid").forEach(p=>{let g=p.validationMessage;i.push({element:p,message:g})}),i},getValues:()=>j(y),onSubmit:i=>{y.addEventListener("submit",d=>{d.preventDefault();let p=j(y);i(p,d)})}}}var G={renderForm:Z};var we=G,xe={FormsLib:G};export{we as FormsLib,xe as default};
1
+ function z(r,L,g){let C=L?.style==="bootstrap",y=document.createElement("div");y.className="voc-form-avatar-wrapper",C&&y.classList.add("d-flex","align-items-center","gap-3");let v=document.createElement("img");v.className="voc-form-avatar-preview",v.alt=r.label||"avatar",C&&(v.classList.add("img-thumbnail","rounded-circle"),v.style.width=v.style.height="64px",v.style.objectFit="cover");let u=g!=null?String(g):r.default!==void 0&&r.default!==null?String(r.default):"";u?v.src=u:(v.src="",v.style.display="none");let o=document.createElement("input");o.type="file",o.accept=r.accept||"image/*",o.className="voc-form-avatar-input",C&&o.classList.add("form-control"),(r.key||r.name)&&(o.name=r.name||r.key,r.key&&(o.id=`voc-form-${r.key}`));let d=document.createElement("input");if(d.type="hidden",(r.key||r.name)&&(d.name=(r.name||r.key)+"_url"),d.value=u||"",o.addEventListener("change",p=>{let E=p.target;if(E.files&&E.files.length>0){let w=E.files[0],k=new FileReader;k.onload=()=>{v.src=String(k.result),v.style.display="",d.value=""},k.readAsDataURL(w)}}),C){let p=document.createElement("div");p.style.flex="1",p.appendChild(o),p.appendChild(d),y.appendChild(v),y.appendChild(p)}else y.appendChild(v),y.appendChild(o),y.appendChild(d);return y}function j(r,L,g){let C=L?.style==="bootstrap",y=document.createElement("div");if(y.className="voc-form-audio-select",!r.options||r.options.length===0)return y;let v=r.name||r.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,u;return Array.isArray(g)?u=g[0]:g!==void 0?u=g:r.default!==void 0&&(u=r.default),r.options.forEach((o,d)=>{let p=document.createElement("div");p.className="voc-form-audio-item",C&&p.classList.add("form-check");let E=document.createElement("input");E.type="radio",E.name=v,E.value=o.value,E.className="voc-form-audio-radio",r.key&&(E.id=`voc-form-${r.key}-${d}`),r.required&&d===0&&(E.required=!0),E.style.position="absolute",E.style.width="1px",E.style.height="1px",E.style.margin="0",E.style.padding="0",E.style.clip="rect(0 0 0 0)",E.style.clipPath="inset(50%)",E.style.overflow="hidden",E.style.border="0",u!==void 0&&(Array.isArray(u)?E.checked=u.includes(o.value):E.checked=String(u)===String(o.value));let w=()=>{E.checked?p.classList.add("selected"):p.classList.remove("selected")};E.addEventListener("change",()=>{y.querySelectorAll(".voc-form-audio-item").forEach(a=>a.classList.remove("selected")),w()}),E.checked&&p.classList.add("selected");let k=document.createElement("label");k.className="voc-form-audio-label",C&&k.classList.add("form-check-label"),k.htmlFor=E.id||"",k.textContent=o.label||o.value,k.tabIndex=0;let e=document.createElement("div");e.className="voc-form-audio-control";let c=null;if(o.audio_link){let t=document.createElement("button");t.type="button",t.className="voc-form-audio-play",C&&t.classList.add("btn","btn-sm","btn-outline-secondary"),t.setAttribute("aria-label",`Play ${o.label||o.value}`);let a="http://www.w3.org/2000/svg",i=document.createElementNS(a,"svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width","16"),i.setAttribute("height","16"),i.setAttribute("aria-hidden","true");let s=document.createElementNS(a,"path");s.setAttribute("d","M8 5v14l11-7z"),s.setAttribute("fill","currentColor"),i.appendChild(s),t.appendChild(i),c=document.createElement("audio"),c.src=o.audio_link,c.preload="none",c.style.display="none";let l=b=>{for(;b.firstChild;)b.removeChild(b.firstChild)},A=()=>{let b="http://www.w3.org/2000/svg",F=document.createElementNS(b,"svg");F.setAttribute("viewBox","0 0 24 24"),F.setAttribute("width","16"),F.setAttribute("height","16"),F.setAttribute("aria-hidden","true");let M=document.createElementNS(b,"path");return M.setAttribute("d","M8 5v14l11-7z"),M.setAttribute("fill","currentColor"),F.appendChild(M),F},S=()=>{let b="http://www.w3.org/2000/svg",F=document.createElementNS(b,"svg");F.setAttribute("viewBox","0 0 24 24"),F.setAttribute("width","16"),F.setAttribute("height","16"),F.setAttribute("aria-hidden","true");let M=document.createElementNS(b,"rect");return M.setAttribute("x","6"),M.setAttribute("y","6"),M.setAttribute("width","12"),M.setAttribute("height","12"),M.setAttribute("fill","currentColor"),F.appendChild(M),F};l(t),t.appendChild(A());let N=b=>{l(t),b?(t.appendChild(S()),t.setAttribute("aria-label",`Stop ${o.label||o.value}`)):(t.appendChild(A()),t.setAttribute("aria-label",`Play ${o.label||o.value}`))};t.addEventListener("click",()=>{try{if(!c)return;let b=y.querySelectorAll("audio");if(!c.paused&&!c.ended){c.pause(),c.currentTime=0;return}b.forEach(M=>{try{M.pause(),M.currentTime=0}catch{}}),y.querySelectorAll(".voc-form-audio-item").forEach(M=>M.classList.remove("is-playing")),c.play()}catch(b){console.warn("audio play failed",b)}}),c.addEventListener("playing",()=>{p.classList.add("is-playing"),N(!0)});let x=()=>{p.classList.remove("is-playing"),N(!1)};c.addEventListener("pause",x),c.addEventListener("ended",x),e.appendChild(t),e.appendChild(c)}let h=document.createElement("div");h.className="voc-form-item-detail",h.style.display="flex",h.style.flexDirection="column",h.style.gap="4px";let n=document.createElement("div");n.className="voc-form-item-top",n.style.display="flex",n.style.alignItems="center",n.style.gap="8px",n.appendChild(E),n.appendChild(k);let m=document.createElement("div");m.className="voc-form-item-description";let f=o.description||o.hint_text||"";f&&(m.textContent=f),h.appendChild(n),h.appendChild(m),e.appendChild(h),p.appendChild(e),n.addEventListener("click",t=>{let a=t.target;a&&a.closest(".voc-form-audio-play")||(E.checked=!0,E.dispatchEvent(new Event("change",{bubbles:!0})))}),p.addEventListener("click",t=>{let a=t.target;a&&a.closest(".voc-form-audio-play")||(E.checked=!0,E.dispatchEvent(new Event("change",{bubbles:!0})))}),y.appendChild(p)}),y}function W(r,L,g){let C=document.createElement("div");C.className="voc-form-table-wrapper";let y=L?.style==="bootstrap",v=document.createElement("input");v.type="hidden",v.name=r.name||r.key,r.key&&(v.id=`voc-form-${r.key}`),C.appendChild(v);let u=document.createElement("table");u.className="voc-form-table",y&&u.classList.add("table","table-bordered");let o=document.createElement("thead"),d=document.createElement("tr"),p=document.createElement("th");p.className="voc-form-table-drag-col",p.textContent="",d.appendChild(p),(r.fields||[]).forEach(a=>{let i=document.createElement("th");i.textContent=a.label||a.key,d.appendChild(i)});let E=document.createElement("th");E.textContent="Actions",d.appendChild(E),o.appendChild(d),u.appendChild(o);let w=document.createElement("tbody");u.appendChild(w),C.appendChild(u);let k=document.createElement("button");k.type="button",k.className="voc-form-table-add",y&&k.classList.add("btn","btn-secondary"),k.textContent="+Add";let e=document.createElement("tfoot"),c=document.createElement("tr"),h=document.createElement("td");h.colSpan=(r.fields?r.fields.length:0)+1,h.appendChild(k),c.appendChild(h),e.appendChild(c),u.appendChild(e),C.appendChild(u);let n=[];function m(){v.value=JSON.stringify(n)}function f(a){let i=[];return r.fields.forEach(s=>{let l=a[s.key];if(s.type==="checkbox"){let A=Array.isArray(l)?l:l?[l]:[];s.required&&A.length===0&&i.push(`${s.label||s.key} is required`);return}s.required&&(l==null||String(l).trim()==="")&&i.push(`${s.label||s.key} is required`),s.type==="email"&&l&&(/^\S+@\S+\.\S+$/.test(String(l))||i.push(`${s.label||s.key} must be a valid email`)),s.type==="number"&&l&&isNaN(Number(l))&&i.push(`${s.label||s.key} must be a number`),s.validation&&s.validation.regex&&l&&(new RegExp(s.validation.regex).test(String(l))||i.push(`${s.label||s.key} invalid format`))}),i}function t(){w.innerHTML="";let a=(i,s)=>{s.draggable=!0,s.addEventListener("mousedown",()=>{s.style.cursor="grabbing"}),s.addEventListener("mouseup",()=>{s.style.cursor="grab"}),s.addEventListener("dragstart",l=>{let A=Number(i.dataset.rowIndex);l.dataTransfer.setData("text/plain",String(A)),i.classList.add("dragging");try{l.dataTransfer?.setDragImage(s,10,10)}catch{}}),s.addEventListener("dragend",()=>{i.classList.remove("dragging"),s.style.cursor="grab"}),i.addEventListener("dragover",l=>{l.preventDefault();let A=l.currentTarget,S=A.getBoundingClientRect(),N=S.top+S.height/2,x=(l.clientY||l.y)>N;A.classList.remove("drag-over-top","drag-over-bottom"),x?(A.classList.add("drag-over-bottom"),A.dataset.dropPosition="after"):(A.classList.add("drag-over-top"),A.dataset.dropPosition="before")}),i.addEventListener("dragleave",l=>{let A=l.currentTarget;A.classList.remove("drag-over-top","drag-over-bottom"),delete A.dataset.dropPosition}),i.addEventListener("drop",l=>{l.preventDefault();let A=l.dataTransfer.getData("text/plain"),S=Number(l.currentTarget.dataset.rowIndex),N=Number(A),x=l.currentTarget.dataset.dropPosition||"before";if(isNaN(N)||isNaN(S))return;let[b]=n.splice(N,1),F=S;N<S&&(F=S-1);let M=x==="after"?F+1:F;n.splice(M,0,b),l.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete l.currentTarget.dataset.dropPosition,t(),m()})};n.forEach((i,s)=>{let l=document.createElement("tr");l.dataset.rowIndex=String(s),l.classList.add("voc-form-table-row");let A=document.createElement("td");A.className="voc-form-table-drag-handle";let S=document.createElement("span");S.className="voc-form-drag-handle-icon",S.textContent="\u2630",S.style.cursor="grab",A.appendChild(S),l.appendChild(A),a(l,S),r.fields.forEach(b=>{let F=document.createElement("td"),M,B=(b.type||"text").toLowerCase();if(B==="select"){let T=document.createElement("select");if(T.className="voc-form-table-cell",y&&T.classList.add("form-control"),b.placeholder){let H=document.createElement("option");H.value="",H.textContent=b.placeholder,H.disabled=!0,(i[b.key]===void 0||i[b.key]===null||i[b.key]==="")&&(H.selected=!0),T.appendChild(H)}(b.options||[]).forEach(H=>{let $=document.createElement("option");$.value=H.value,$.textContent=H.label,T.appendChild($)}),T.value=i[b.key]!==void 0&&i[b.key]!==null?String(i[b.key]):"",b.required&&(T.required=!0),T.addEventListener("change",H=>{n[s][b.key]=H.target.value,m()}),M=T}else if(B==="checkbox"){let T=document.createElement("div");T.className="voc-form-table-checkboxes",y&&T.classList.add("form-check");let D=b.options||[];Array.isArray(n[s][b.key])||(n[s][b.key]=n[s][b.key]?[n[s][b.key]]:[]),D.forEach(H=>{let $=`voc-form-${r.key}-${b.key}-${s}-${H.value}`,q=document.createElement("div");q.className="voc-form-table-checkbox-item",y&&q.classList.add("form-check");let R=document.createElement("input");R.type="checkbox",R.className="voc-form-table-cell",y&&R.classList.add("form-check-input"),R.id=$,R.value=H.value,R.checked=Array.isArray(n[s][b.key])&&n[s][b.key].includes(H.value),R.addEventListener("change",O=>{let Q=O.target.checked;Array.isArray(n[s][b.key])||(n[s][b.key]=[]),Q?n[s][b.key].includes(H.value)||n[s][b.key].push(H.value):n[s][b.key]=n[s][b.key].filter(X=>X!==H.value),m()});let _=document.createElement("label");_.htmlFor=$,_.className="voc-form-table-checkbox-label",y&&_.classList.add("form-check-label"),_.textContent=H.label,q.appendChild(R),q.appendChild(_),T.appendChild(q)}),M=T}else if(B==="radio"){let T=document.createElement("div");T.className="voc-form-table-radios",y&&T.classList.add("form-check");let D=b.options||[];n[s][b.key]===void 0&&(n[s][b.key]=""),D.forEach(H=>{let $=`voc-form-${r.key}-${b.key}-${s}-${H.value}`,q=document.createElement("div");q.className="voc-form-table-radio-item",y&&q.classList.add("form-check");let R=document.createElement("input");R.type="radio",R.className="voc-form-table-cell",y&&R.classList.add("form-check-input"),R.id=$,R.name=`voc-form-${r.key}-${b.key}-${s}`,R.value=H.value,R.checked=n[s][b.key]===H.value,R.addEventListener("change",O=>{O.target.checked&&(n[s][b.key]=O.target.value,m())});let _=document.createElement("label");_.htmlFor=$,_.className="voc-form-table-radio-label",y&&_.classList.add("form-check-label"),_.textContent=H.label,q.appendChild(R),q.appendChild(_),T.appendChild(q)}),M=T}else{let T=document.createElement("input");B==="number"?T.type="number":B==="email"?T.type="email":B==="tel"?T.type="tel":B==="url"?T.type="url":B==="date"?T.type="date":T.type="text",T.value=i[b.key]!==void 0&&i[b.key]!==null?String(i[b.key]):"",b.placeholder&&(T.placeholder=b.placeholder),b.required&&(T.required=!0),T.className="voc-form-table-cell",y&&T.classList.add("form-control"),T.addEventListener("input",D=>{n[s][b.key]=D.target.value,m()}),M=T}F.appendChild(M),l.appendChild(F)});let N=document.createElement("td"),x=document.createElement("button");x.type="button",x.className="voc-form-table-remove",y&&x.classList.add("btn","btn-danger"),x.textContent="Remove",x.addEventListener("click",()=>{n.splice(s,1),t(),m()}),N.appendChild(x),l.appendChild(N),w.appendChild(l)})}return k.addEventListener("click",()=>{if(r.validation?.max_rows!==void 0&&n.length>=r.validation.max_rows)return;let a={};r.fields.forEach(i=>a[i.key]=""),n.push(a),t(),m()}),Array.isArray(g)&&g.length?n=g.map(a=>({...a})):r.default&&Array.isArray(r.default)&&(n=r.default.map(a=>({...a}))),t(),m(),C.validate=function(){let a=[];return n.forEach((i,s)=>{let l=f(i);l.length&&a.push(`Row ${s+1}: ${l.join("; ")}`)}),r.validation?.min_rows!==void 0&&n.length<r.validation.min_rows&&a.push(`At least ${r.validation.min_rows} rows required`),r.validation?.max_rows!==void 0&&n.length>r.validation.max_rows&&a.push(`No more than ${r.validation.max_rows} rows allowed`),r.validation?.unique_fields&&r.validation.unique_fields.length&&r.validation.unique_fields.forEach(i=>{let s=new Set;n.forEach((l,A)=>{let S=l[i];S!=null&&(s.has(S)&&a.push(`Field ${i} must be unique (duplicate at row ${A+1})`),s.add(S))})}),a},C}async function Z(r){let g=new TextEncoder().encode(r),C=await crypto.subtle.digest("SHA-256",g);return Array.from(new Uint8Array(C)).map(v=>v.toString(16).padStart(2,"0")).join("")}async function ee(r){let L=String(r||"").trim().toLowerCase();return L?`https://gravatar.com/avatar/${await Z(L)}?d=mp`:""}function G(r,L,g){let C=L?.style==="bootstrap",y=document.createElement("div");y.className="voc-form-users";let v=document.createElement("div");if(v.className="voc-form-users-header",C&&v.classList.add("mb-2"),r.label){let e=document.createElement("div");if(e.className="voc-form-users-label",C&&e.classList.add("form-label"),e.textContent=r.label,r.required){let c=document.createElement("span");c.className="voc-form-required",c.textContent="*",e.appendChild(c)}v.appendChild(e)}if(r.description){let e=document.createElement("div");e.className="voc-form-users-description",C&&e.classList.add("form-text"),e.textContent=r.description,v.appendChild(e)}y.appendChild(v);let u=document.createElement("div");u.className="voc-form-users-search-wrapper";let o=document.createElement("input");if(o.type="search",o.placeholder="Search users...",o.className="voc-form-users-search",C&&o.classList.add("form-control","mb-2"),u.appendChild(o),y.appendChild(u),!r.options||r.options.length===0)return y;let d=document.createElement("div");d.className="voc-form-users-list",C&&d.classList.add("list-group");let p=r.name||r.key||`users_${Math.random().toString(36).substr(2,6)}`,E=[];if(Array.isArray(g)?E=g:g!=null?E=[g]:Array.isArray(r.default)&&(E=r.default),r.options.forEach((e,c)=>{let h=document.createElement("div");h.className="voc-form-user-item",h.dataset.label=String(e.label||"").toLowerCase(),h.dataset.email=String(e.email||"").toLowerCase(),h.dataset.value=String(e.value||"").toLowerCase(),C&&h.classList.add("d-flex","align-items-center","gap-2");let n=document.createElement("input");if(n.type="checkbox",n.name=`${p}[]`,n.value=e.value,n.className="voc-form-user-checkbox",r.key&&(n.id=`voc-form-${r.key}-${c}`),n.style.position="absolute",n.style.width="1px",n.style.height="1px",n.style.margin="0",n.style.padding="0",n.style.clip="rect(0 0 0 0)",n.style.clipPath="inset(50%)",n.style.overflow="hidden",n.style.border="0",E&&Array.isArray(E)){let i=E.map(s=>String(s));n.checked=i.includes(String(e.value))}let m=document.createElement("img");m.className="voc-form-user-avatar",m.alt=e.label||String(e.value||"user"),m.style.width=m.style.height="40px",m.style.objectFit="cover",m.style.borderRadius="50%",m.src="",e.email&&ee(e.email).then(i=>{i&&(m.src=i)}).catch(()=>{});let f=document.createElement("div");f.className="voc-form-user-info",f.style.display="flex",f.style.flexDirection="column",f.style.gap="2px";let t=document.createElement("div");t.className="voc-form-user-label",t.textContent=e.label||String(e.value);let a=document.createElement("small");a.className="voc-form-user-email",a.textContent=e.email||"",f.appendChild(t),f.appendChild(a),h.addEventListener("click",i=>{let s=i.target;s&&(s.closest("input")||s.closest("a")||s.closest("button"))||(n.checked=!n.checked,n.dispatchEvent(new Event("change",{bubbles:!0})))}),n.addEventListener("change",()=>{n.checked?h.classList.add("selected"):h.classList.remove("selected")}),n.checked&&h.classList.add("selected"),h.appendChild(n),h.appendChild(m),h.appendChild(f),d.appendChild(h)}),y.appendChild(d),r.required){let e=d.querySelectorAll('input[type="checkbox"]'),c=()=>{let h=Array.from(e).some(n=>n.checked);return e.forEach(n=>{h?n.setCustomValidity(""):n.setCustomValidity("At least one option must be selected.")}),h};e.forEach(h=>{h.addEventListener("change",c)}),y._validateCheckboxGroup=c,c()}let w=Array.from(d.querySelectorAll(".voc-form-user-item")),k=()=>{let e=String(o.value||"").trim().toLowerCase();if(!e){w.forEach(c=>c.style.setProperty("display","flex","important"));return}w.forEach(c=>{let h=c.dataset.label||"",n=c.dataset.email||"",m=c.dataset.value||"",f=h.includes(e)||n.includes(e)||m.includes(e);c.style.setProperty("display",f?"flex":"none","important")})};return o.addEventListener("input",k),y}function U(r,L,g){let C=L?.style==="bootstrap",y=document.createElement("div");y.className="voc-form-timezone";let v=r.name||r.key||`timezone_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("input");u.type="text",u.name=v,r.key&&(u.id=`voc-form-${r.key}`),u.className="voc-form-timezone-input",C&&u.classList.add("form-control"),r.placeholder&&(u.placeholder=r.placeholder||""),r.required&&(u.required=!0),r.width&&(u.style.width=r.width);try{u.autocomplete="off"}catch{}try{u.autocorrect="off"}catch{}try{u.autocapitalize="off"}catch{}try{u.spellcheck=!1}catch{}u.setAttribute("data-lpignore","true"),g!=null?u.value=String(g):r.default!==void 0&&r.default!==null&&(u.value=String(r.default));let o=document.createElement("div");o.className="voc-form-timezone-control",o.style.position="relative",o.style.display="inline-block",o.style.width=r.width||"100%";let d=document.createElement("button");d.type="button",d.className="voc-form-timezone-toggle",d.setAttribute("aria-haspopup","listbox"),d.setAttribute("aria-expanded","false"),d.style.position="absolute",d.style.right="4px",d.style.top="50%",d.style.transform="translateY(-50%)",d.style.height="28px",d.style.width="28px",d.style.padding="0",d.style.border="none",d.style.background="transparent",d.style.cursor="pointer",d.innerHTML="\u25BC";let p=document.createElement("ul");p.className="voc-form-timezone-list",p.setAttribute("role","listbox"),p.style.position="absolute",p.style.left="0",p.style.right="0",p.style.zIndex="1000",p.style.maxHeight="200px",p.style.overflow="auto",p.style.margin="4px 0 0 0",p.style.padding="0",p.style.listStyle="none",p.style.background="white",p.style.border="1px solid rgba(0,0,0,0.15)",p.style.display="none",p.tabIndex=-1,u.style.paddingRight="36px";let w=["UTC","ETC","AEST","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Vancouver","Europe/London","Europe/Paris","Europe/Berlin","Europe/Rome","Europe/Madrid","Europe/Amsterdam","Asia/Tokyo","Asia/Shanghai","Asia/Singapore","Asia/Kolkata","Asia/Dubai","Australia/Lindeman","Australia/Brisbane","Australia/Sydney","Australia/Melbourne","Australia/Hobart","Australia/Currie","Australia/Broken_Hill","Australia/Lord_Howe","Australia/Adelaide","Australia/Darwin","Australia/Perth","Australia/Eucla","Australia/ACT","ACT","Pacific/Auckland","America/Sao_Paulo","America/Mexico_City","Africa/Cairo","Africa/Johannesburg"];function k(t){p.innerHTML="",t.forEach((a,i)=>{let s=document.createElement("li");s.className="voc-form-timezone-item",s.setAttribute("role","option"),s.dataset.value=a,s.style.padding="6px 8px",s.style.cursor="pointer",s.textContent=a,s.addEventListener("mousedown",l=>{l.preventDefault(),u.value=a,n(),u.dispatchEvent(new Event("change",{bubbles:!0}))}),p.appendChild(s)})}k(w);let e=-1;function c(){Array.from(p.children).forEach((a,i)=>{i===e?(a.style.background="rgba(0,123,255,0.1)",a.setAttribute("aria-selected","true")):(a.style.background="",a.removeAttribute("aria-selected"))})}function h(){p.style.display="block",d.setAttribute("aria-expanded","true")}function n(){p.style.display="none",d.setAttribute("aria-expanded","false"),e=-1,c()}function m(){p.style.display==="none"?h():n()}u.addEventListener("input",()=>{let t=(u.value||"").trim().toLowerCase(),a=t?w.filter(i=>i.toLowerCase().includes(t)):w;k(a),h()}),d.addEventListener("click",t=>{t.preventDefault(),p.style.display==="none"?(k(w),h(),u.focus()):n()}),u.addEventListener("keydown",t=>{let a=Array.from(p.children);if(t.key==="ArrowDown"){if(t.preventDefault(),a.length===0)return;e=Math.min(e+1,a.length-1),c(),a[e].scrollIntoView({block:"nearest"})}else if(t.key==="ArrowUp"){if(t.preventDefault(),a.length===0)return;e=Math.max(e-1,0),c(),a[e].scrollIntoView({block:"nearest"})}else if(t.key==="Enter"){if(p.style.display!=="none"&&e>=0){t.preventDefault();let i=a[e];u.value=i.dataset.value||i.textContent||"",n(),u.dispatchEvent(new Event("change",{bubbles:!0}))}}else t.key==="Escape"&&n()}),document.addEventListener("click",t=>{o.contains(t.target)||n()});let f={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(u.addEventListener("blur",()=>{let t=(u.value||"").trim();if(!t)return;let a=Object.keys(f).find(i=>i.toLowerCase()===t.toLowerCase());a&&(u.value=f[a])}),r.description){let t=document.createElement("div");t.className="voc-form-timezone-description",C&&t.classList.add("form-text"),t.textContent=r.description,y.appendChild(t)}return o.appendChild(u),o.appendChild(d),o.appendChild(p),y.appendChild(o),y}function V(r,L,g){let C=L?.style==="bootstrap",y=document.createElement("div");y.className="voc-form-tags";let v=r.name||r.key||`tags_${Math.random().toString(36).substr(2,6)}`,u=document.createElement("div");u.className="voc-form-tags-container",u.style.display="flex",u.style.flexWrap="wrap",u.style.gap="6px",u.style.alignItems="center",u.style.padding="6px",u.style.border="1px solid rgba(0,0,0,0.12)",u.style.borderRadius="4px";let o=document.createElement("input");o.type="text",o.className="voc-form-tags-input",o.style.border="none",o.style.flex="1 0 120px",o.style.minWidth="80px",o.style.outline="none",o.placeholder=r.placeholder||"",C&&o.classList.add("form-control"),u.appendChild(o);let d=[],p=document.createElement("input");p.type="text",p.style.position="absolute",p.style.left="-9999px",p.style.width="1px",p.style.height="1px",p.tabIndex=-1,r.required&&(p.required=!0),y.appendChild(p);function E(){Array.from(y.querySelectorAll("input.voc-form-tag-hidden")).forEach(h=>h.parentElement?.removeChild(h)),d.forEach(h=>{let n=document.createElement("input");n.type="hidden",n.name=`${v}[]`,n.className="voc-form-tag-hidden",n.value=h,r.key&&(n.id=`voc-form-${r.key}`),y.appendChild(n)}),r.required&&(d.length===0?(p.value="",p.setCustomValidity("Please enter at least one tag")):(p.value="1",p.setCustomValidity("")))}function w(c){let h=document.createElement("span");h.className="voc-form-tag",h.style.display="inline-flex",h.style.alignItems="center",h.style.padding="4px 8px",h.style.background="rgba(0,0,0,0.05)",h.style.borderRadius="16px";let n=document.createElement("span");n.textContent=c,n.style.marginRight="8px",h.appendChild(n);let m=document.createElement("button");return m.type="button",m.textContent="\xD7",m.style.border="none",m.style.background="transparent",m.style.cursor="pointer",m.addEventListener("click",()=>{let f=d.indexOf(c);f>=0&&(d.splice(f,1),u.removeChild(h),E())}),h.appendChild(m),h}function k(c){let h=c.trim();if(!h||d.includes(h))return;d.push(h);let n=w(h);u.insertBefore(n,o),E()}let e=g!=null?String(g):r.default||"";return e&&e.split(",").map(c=>c.trim()).filter(Boolean).forEach(k),o.addEventListener("keydown",c=>{if(c.key==="Enter"||c.key===",")c.preventDefault(),k(o.value),o.value="";else if(c.key==="Backspace"&&o.value===""&&d.pop()){let n=Array.from(u.querySelectorAll(".voc-form-tag")),m=n[n.length-1];m&&u.removeChild(m),E()}}),o.addEventListener("paste",c=>{let h=c.clipboardData?.getData("text");h&&(c.preventDefault(),h.split(/[,\n\r]+/).map(n=>n.trim()).filter(Boolean).forEach(k),o.value="")}),y.getTags=()=>d.slice(),y.addTag=k,y.appendChild(u),E(),y}function J(r,L,g,C){let y=L?.style==="bootstrap",v=document.createElement("div");v.className="voc-form-field-selects";let u=document.createElement("div");if(u.className="voc-form-field-selects-header",y&&u.classList.add("mb-2"),r.label){let m=document.createElement("div");if(m.className="voc-form-field-selects-label",y&&m.classList.add("form-label"),m.textContent=r.label,r.required){let f=document.createElement("span");f.className="voc-form-required",f.textContent="*",m.appendChild(f)}u.appendChild(m)}if(r.description){let m=document.createElement("div");m.className="voc-form-field-selects-description",y&&m.classList.add("form-text"),m.textContent=r.description,u.appendChild(m)}v.appendChild(u);let o=document.createElement("div");o.className="voc-form-field-selects-search-wrapper";let d=document.createElement("input");d.type="search",d.placeholder="Search...",d.className="voc-form-field-selects-search",y&&d.classList.add("form-control","mb-2"),o.appendChild(d),v.appendChild(o);let p=r.options;if(!p||p.length===0)return v;let E=document.createElement("div");E.className="voc-form-field-selects-list",y&&E.classList.add("list-group");let w=document.createElement("div");w.className="voc-form-field-selects-selected",w.style.marginTop="12px";let k={},e=r.name||r.key||`users_${Math.random().toString(36).substr(2,6)}`,c=[];if(Array.isArray(g)?c=g:g!=null?c=[g]:Array.isArray(r.default)&&(c=r.default),p.forEach((m,f)=>{let t=document.createElement("div");t.className="voc-form-field-selects-item",t.dataset.label=String(m.option_label??m.label??"").toLowerCase(),t.dataset.email=String(m.email||"").toLowerCase(),t.dataset.value=String(m.value||"").toLowerCase(),y&&t.classList.add("d-flex","align-items-center","gap-2");let a=document.createElement("input");if(a.type="checkbox",a.name=`${e}[]`,a.value=m.value??m.key,a.className="voc-form--checkbox",r.key&&(a.id=`voc-form-${r.key}-${f}`),a.style.position="absolute",a.style.width="1px",a.style.height="1px",a.style.margin="0",a.style.padding="0",a.style.clip="rect(0 0 0 0)",a.style.clipPath="inset(50%)",a.style.overflow="hidden",a.style.border="0",c&&Array.isArray(c)){let N=c.map(b=>String(b)),x=String(m.value??m.key);a.checked=N.includes(x)}let i=m.icon||'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" d="M14 11c0 .55-.45 1-1 1H4c-.55 0-1-.45-1-1s.45-1 1-1h9c.55 0 1 .45 1 1M3 7c0 .55.45 1 1 1h9c.55 0 1-.45 1-1s-.45-1-1-1H4c-.55 0-1 .45-1 1m7 8c0-.55-.45-1-1-1H4c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1m8.01-2.13l.71-.71a.996.996 0 0 1 1.41 0l.71.71c.39.39.39 1.02 0 1.41l-.71.71zm-.71.71l-5.16 5.16c-.09.09-.14.21-.14.35v1.41c0 .28.22.5.5.5h1.41c.13 0 .26-.05.35-.15l5.16-5.16z"/></svg>',s=document.createElement("div");s.className="voc-form-fields-select-avatar",s.innerHTML=i;let l=document.createElement("div");l.className="voc-form-field-select-info",l.style.display="flex",l.style.flexDirection="column",l.style.gap="2px";let A=document.createElement("div");A.className="voc-form-field-select-label",A.textContent=(m.option_label??m.label)||String(m.value);let S=document.createElement("small");S.className="voc-form-field-select-email",S.textContent=m.email||"",l.appendChild(A),l.appendChild(S),t.addEventListener("click",N=>{let x=N.target;x&&(x.closest("input")||x.closest("a")||x.closest("button"))||(a.checked=!a.checked,a.dispatchEvent(new Event("change",{bubbles:!0})))}),a.addEventListener("change",()=>{if(a.checked){t.classList.add("selected"),(k[f]||[]).forEach(b=>b.parentElement?.removeChild(b)),k[f]=[];let x=m;if(x&&Array.isArray(x.items))x.items.forEach(b=>{let F=C(b);F&&(w.appendChild(F),k[f].push(F))});else if(x&&(x.type||x.key)){let b=C(x);b&&(w.appendChild(b),k[f].push(b))}}else t.classList.remove("selected"),(k[f]||[]).forEach(x=>x.parentElement?.removeChild(x)),k[f]=[]}),a.checked&&(t.classList.add("selected"),setTimeout(()=>{let N=m;if(N&&Array.isArray(N.items))N.items.forEach(x=>{let b=C(x);b&&(w.appendChild(b),k[f]=k[f]||[],k[f].push(b))});else if(N&&(N.type||N.key)){let x=C(N);x&&(w.appendChild(x),k[f]=k[f]||[],k[f].push(x))}},0)),t.appendChild(a),t.appendChild(s),t.appendChild(l),E.appendChild(t)}),v.appendChild(E),v.appendChild(w),r.required){let m=E.querySelectorAll('input[type="checkbox"]'),f=()=>{let t=Array.from(m).some(a=>a.checked);return m.forEach(a=>{t?a.setCustomValidity(""):a.setCustomValidity("At least one option must be selected.")}),t};m.forEach(t=>{t.addEventListener("change",f)}),v._validateCheckboxGroup=f,f()}let h=Array.from(E.querySelectorAll(".voc-form-field-select-item")),n=()=>{let m=String(d.value||"").trim().toLowerCase();if(!m){h.forEach(f=>f.style.setProperty("display","flex","important"));return}h.forEach(f=>{let t=f.dataset.label||"",a=f.dataset.email||"",i=f.dataset.value||"",s=t.includes(m)||a.includes(m)||i.includes(m);f.style.setProperty("display",s?"flex":"none","important")})};return d.addEventListener("input",n),v}function I(r,L=!0){let g=new FormData(r);if(L)return te(g);let C={};return g.forEach((y,v)=>{let u=(y instanceof File,y);Object.prototype.hasOwnProperty.call(C,v)?Array.isArray(C[v])?C[v].push(u):C[v]=[C[v],u]:C[v]=u}),C}function te(r){let L=new FormData;for(let[g,C]of r.entries()){if(C instanceof File){L.append(g,C);continue}let y;try{y=JSON.parse(C)}catch{y=null}Array.isArray(y)?y.length===0?L.append(g,"[]"):y.every(v=>typeof v=="object"&&v!==null)?y.forEach((v,u)=>{for(let[o,d]of Object.entries(v))L.append(`${g}[${u}][${o}]`,d)}):L.append(g,C):L.append(g,C)}return L}async function Y(r,L,g){let C=L.url,y={"Content-Type":"application/json"};L?.api_token&&(y.Authorization=`Bearer ${L.api_token}`);let v=I(r);if(L?.additional_data)for(let[d,p]of Object.entries(L.additional_data))v.append(d,p);let u,o=v instanceof FormData;u={method:"POST",headers:{Authorization:`Bearer ${L.api_token}`,...o?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:o?v:JSON.stringify(Object.fromEntries(v.entries()))};try{fetch(C,u).then(async d=>{let p=d.headers.get("content-type");if(!d.ok)try{let w=(await d.json())?.message;throw new Error(w??"Their was an error submitting the form. Check your form and try again.")}catch(E){throw new Error(E.message)}return p&&p.includes("application/json")?d.json():d.text()}).then(d=>{g&&g(d,null)}).catch(d=>{g&&g(null,d)})}catch(d){g&&g(null,d)}}function K(r,L,g){let C=[];if(typeof r=="string"?C=Array.from(document.querySelectorAll(r)):C=[r],C.length===0)return null;function y(){let o=g?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),o&&d.classList.add("needs-validation"),d.id=L.id;let p=document.createElement("h2");p.className="voc-form-title",o&&p.classList.add("mb-3"),p.textContent=L.form_name,d.appendChild(p);function E(e,c){c&&(c.min_length!==void 0&&(e.minLength=c.min_length),c.max_length!==void 0&&(e.maxLength=c.max_length),c.regex&&(e instanceof HTMLInputElement?e.pattern=c.regex:e.dataset.pattern=c.regex))}function w(e){if(!e.key&&!e.label)return null;let c=L.default_values||{},h=e.name||e.key,n=h?c[h]:void 0,m=document.createElement("div");if(m.className="voc-form-group",o&&m.classList.add("mb-3"),e.label&&e.type!=="users"){let t=document.createElement("label");if(t.classList.add("voc-form-label"),o&&t.classList.add("form-label"),e.key?e.type==="radio"?t.htmlFor="":t.htmlFor=`voc-form-${e.key}`:t.htmlFor="",t.textContent=e.label,e.required){let a=document.createElement("span");a.className="voc-form-required",a.textContent="*",t.appendChild(a)}m.appendChild(t)}let f=null;switch(e.type){case"tags":{f=V(e,g||{},n);break}case"checkbox":{let t=document.createElement("div");if(t.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options){if(e.options.forEach((a,i)=>{let s=document.createElement("label");s.classList.add("voc-form-checkbox-label"),o&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let l=document.createElement("input");l.type="checkbox",l.classList.add("voc-form-checkbox"),o&&l.classList.add("form-check-input"),l.name=`${e.name||e.key||""}[]`,l.value=a.value,e.key&&(l.id=`voc-form-${e.key}-${i}`),Array.isArray(n)?n.includes(a.value)&&(l.checked=!0):n!==void 0?n===a.value&&(l.checked=!0):e.default===a.value&&(l.checked=!0),s.appendChild(l),s.appendChild(document.createTextNode(a.label)),t.appendChild(s)}),e.required){let a=t.querySelectorAll('input[type="checkbox"]'),i=()=>{let s=Array.from(a).some(l=>l.checked);return a.forEach(l=>{s?l.setCustomValidity(""):l.setCustomValidity("At least one option must be selected.")}),s};a.forEach(s=>{s.addEventListener("change",i)}),t._validateCheckboxGroup=i,i()}}else{let a=document.createElement("label");a.classList.add("voc-form-checkbox-label"),o&&a.classList.add("form-check"),e.width&&(a.style.width=e.width);let i=document.createElement("input");i.type="checkbox",i.classList.add("voc-form-checkbox"),(e.key||e.name)&&(i.name=e.name||e.key,e.key&&(i.id=`voc-form-${e.key}`)),o&&i.classList.add("form-check-input"),e.required&&(i.required=!0),n!==void 0?i.checked=!!n:e.default&&(i.checked=!!e.default),a.appendChild(i),a.appendChild(document.createTextNode(e.label||"")),t.appendChild(a)}f=t;break}case"textarea":{let t=document.createElement("textarea");t.classList.add("voc-form-textarea"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),n!=null?t.value=String(n):e.default!==void 0&&e.default!==null&&(t.value=String(e.default));let a=e.default||n||"";if(a){let i=(a.match(/\n/g)||[]).length,s=80,l=a.split(`
2
+ `).reduce((N,x)=>Math.max(N,x.length),0),A=Math.ceil(l/s)||1,S=Math.max(2,i+A);t.rows=S,t.style.resize="vertical"}e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),f=t;break}case"select":{let t=document.createElement("select");if(t.classList.add("voc-form-select"),o&&t.classList.add("form-select"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder){let a=document.createElement("option");a.value="",a.textContent=e.placeholder,a.disabled=!0,a.selected=!0,t.appendChild(a)}e.required&&(t.required=!0),e.options&&e.options.forEach(a=>{let i=document.createElement("option");i.value=a.value,i.textContent=a.label,Array.isArray(n)?n.includes(a.value)&&(i.selected=!0):n!==void 0?n===a.value&&(i.selected=!0):e.default===a.value&&(i.selected=!0),t.appendChild(i)}),e.width&&(t.style.width=e.width),f=t;break}case"radio":{let t=document.createElement("div");t.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(t.style.width=e.width),e.options&&e.options.forEach((a,i)=>{let s=document.createElement("label");s.classList.add("voc-form-radio-label"),o&&s.classList.add("form-check"),s.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(s.style.width=e.width);let l=document.createElement("input");l.type="radio",l.classList.add("voc-form-radio"),o&&l.classList.add("form-check-input"),l.name=e.name||e.key||"",l.value=a.value,e.key&&(l.id=`voc-form-${e.key}-${i}`),Array.isArray(n)?n.includes(a.value)&&(l.checked=!0):n!==void 0?n===a.value&&(l.checked=!0):e.default===a.value&&(l.checked=!0),s.appendChild(l),s.appendChild(document.createTextNode(a.label)),t.appendChild(s)}),f=t;break}case"file":{let t=document.createElement("div");t.className="voc-form-file-wrapper",e.width&&(t.style.width=e.width);let a=document.createElement("input");a.type="file",a.classList.add("voc-form-file"),o&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.width&&(a.style.width=e.width),e.required&&(a.required=!0),e.accept&&(a.accept=e.accept),e.multiple&&(a.multiple=!0),t.appendChild(a),f=t;break}case"avatar":{f=z(e,g||{},n);break}case"table":{f=W(e,g||{},n);break}case"users":{f=G(e,g||{},n);break}case"timezone":{f=U(e,g||{},n);break}case"audio_select":{f=j(e,g||{},n);break}case"field-select":{f=J(e,g||{},n,w);break}default:{let t=document.createElement("input");t.type=e.type||"text",t.classList.add("voc-form-input"),o&&t.classList.add("form-control"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.placeholder&&(t.placeholder=e.placeholder),n!=null?t.value=String(n):e.default!==void 0&&e.default!==null&&(t.value=String(e.default)),e.width&&(t.style.width=e.width),e.required&&(t.required=!0),E(t,e.validation),f=t;break}}if(f&&m.appendChild(f),e.hint_text){let t=document.createElement("small");t.className="voc-form-hint",t.textContent=e.hint_text,m.appendChild(t)}return m}L.fields.forEach(e=>{if(e.type==="group"&&"items"in e){let c=e;if(o){let h=document.createElement("div");h.className="card voc-form-group-card mb-3";let n=c.label||c.header?.title,m=c.description||c.header?.description;if(n||m){let t=document.createElement("div");if(t.className="card-header voc-form-group-head",n){let a=document.createElement("h5");a.className="mb-0 voc-form-group-label",a.textContent=n,t.appendChild(a)}if(m){let a=document.createElement("p");a.className="mb-0 voc-form-group-description",a.textContent=m,t.appendChild(a)}h.appendChild(t)}let f=document.createElement("div");f.className="card-body voc-form-group-body",c.items.forEach(t=>{if(t.type==="row"&&"items"in t){let a=t,i=document.createElement("div");if(i.className="voc-form-group voc-form-row mb-3",a.label){let l=document.createElement("h6");l.className="voc-form-row-label",l.textContent=a.label,i.appendChild(l)}let s=document.createElement("div");s.className="voc-form-row-items "+(a.direction||"horizontal"),a.items.forEach(l=>{let A=w(l);A&&s.appendChild(A)}),i.appendChild(s),f.appendChild(i)}else{let a=w(t);a&&f.appendChild(a)}}),h.appendChild(f),d.appendChild(h)}else{let h=document.createElement("div");h.className="voc-form-group voc-form-group-wrapper",o&&h.classList.add("mb-3");let n=c.label||c.header?.title,m=c.description||c.header?.description;if(n||m){let f=document.createElement("div");if(f.className="voc-form-group-head",n){let t=document.createElement("h3");t.className="voc-form-group-label",t.textContent=n,f.appendChild(t)}if(m){let t=document.createElement("p");t.className="voc-form-group-description",t.textContent=m,f.appendChild(t)}h.appendChild(f)}c.items.forEach(f=>{if(f.type==="row"&&"items"in f){let t=f,a=document.createElement("div");if(a.className="voc-form-group voc-form-row",o&&a.classList.add("mb-3"),t.label){let s=document.createElement("h4");s.className="voc-form-row-label",s.textContent=t.label,a.appendChild(s)}let i=document.createElement("div");i.className="voc-form-row-items "+(t.direction||"horizontal"),t.items.forEach(s=>{let l=w(s);l&&i.appendChild(l)}),a.appendChild(i),h.appendChild(a)}else{let t=w(f);t&&h.appendChild(t)}}),d.appendChild(h)}return}if(e.type==="row"&&"items"in e){let c=document.createElement("div");if(c.className="voc-form-group voc-form-row",o&&c.classList.add("mb-3"),e.label){let n=document.createElement("h3");n.className="voc-form-row-label",n.textContent=e.label,c.appendChild(n)}if(e.description){let n=document.createElement("p");n.className="voc-form-row-description",n.textContent=e.description,c.appendChild(n)}let h=document.createElement("div");h.className="voc-form-row-items "+(e.direction||"horizontal"),c.appendChild(h),e.items.forEach(n=>{let m=w(n);m&&h.appendChild(m)}),d.appendChild(c)}else{let c=w(e);c&&d.appendChild(c)}});let k=document.createElement("button");return k.type="submit",k.className="voc-form-submit",k.textContent="Submit",o&&k.classList.add("btn","btn-primary"),d.appendChild(k),d}let v=y();C[0].appendChild(v);let u=L?.submit_config??g?.submit_config??null;return u&&v.addEventListener("submit",o=>{o.preventDefault();let d=Array.from(v.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),p=[];if(d.forEach(k=>{k&&typeof k._validateCheckboxGroup=="function"&&(k._validateCheckboxGroup()||k.querySelector('input[type="checkbox"]')&&p.push("Please select at least one option"))}),!v.checkValidity()){v.reportValidity(),g?.onSubmitResult&&g.onSubmitResult(null,new Error("Form validation failed"));return}let E=Array.from(v.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),w=[];if(E.forEach(k=>{if(k&&typeof k.validate=="function"){let e=k.validate();e&&e.length&&w.push(...e)}}),w.length){g?.onSubmitResult&&g.onSubmitResult(null,new Error(w.join("; ")));let k=E[0];k&&k.scrollIntoView({behavior:"smooth",block:"center"});return}if(g?.onSubmit){let k=I(v);g.onSubmit(k)}Y(v,u,(k,e)=>{g?.onSubmitResult&&g.onSubmitResult(k,e)})}),{element:v,validate:()=>{let o=[];return v.querySelectorAll(":invalid").forEach(p=>{let E=p.validationMessage;o.push({element:p,message:E})}),o},getValues:()=>I(v),onSubmit:o=>{v.addEventListener("submit",d=>{d.preventDefault();let p=I(v);o(p,d)})}}}var P={renderForm:K};var xe=P,Ae={FormsLib:P};export{xe as FormsLib,Ae as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voc-lib-js",
3
- "version": "1.0.64",
3
+ "version": "1.0.66",
4
4
  "description": "A JavaScript library for VocPhone",
5
5
  "main": "./dist/main.cjs",
6
6
  "module": "./dist/main.mjs",