voc-lib-js 1.0.66 → 1.0.67

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
@@ -7,22 +7,33 @@ type Option = {
7
7
  label: string;
8
8
  value: string;
9
9
  };
10
+ /**
11
+ * Union type of all supported field types for better type identification and intellisense.
12
+ */
13
+ type FieldType = "text" | "email" | "number" | "password" | "tel" | "url" | "date" | "color" | "hidden" | "textarea" | "select" | "checkbox" | "boolean" | "radio" | "file" | "avatar" | "table" | "users" | "timezone" | "audio_select" | "tags" | "field-select" | "group" | "row";
10
14
  type BaseField = {
11
15
  label?: string;
12
16
  key: string;
13
17
  placeholder?: string;
14
18
  name?: string;
15
- type?: string;
19
+ type?: FieldType | string;
16
20
  required?: boolean;
17
21
  validation?: Validation;
22
+ /**
23
+ * Hint text displayed below the input field (after the input).
24
+ */
18
25
  hint_text?: string;
26
+ /**
27
+ * Description text displayed below the label (before the input).
28
+ * Use this to provide context about the field.
29
+ */
30
+ description?: string;
19
31
  direction?: "horizontal" | "vertical";
20
32
  options?: Option[];
21
- default?: string;
33
+ default?: string | boolean;
22
34
  width?: string;
23
35
  accept?: string;
24
36
  multiple?: boolean;
25
- description?: string;
26
37
  icon?: string;
27
38
  option_label?: string;
28
39
  };
@@ -84,4 +95,4 @@ declare const _default: {
84
95
  };
85
96
  };
86
97
 
87
- export { FormsLib, _default as default };
98
+ export { type BaseField, type FieldType, type FormData, FormsLib, type Option, type RenderOptions, type RenderedForm, type SubmitConfig, type Validation, _default as default };
package/dist/main.d.ts CHANGED
@@ -7,22 +7,33 @@ type Option = {
7
7
  label: string;
8
8
  value: string;
9
9
  };
10
+ /**
11
+ * Union type of all supported field types for better type identification and intellisense.
12
+ */
13
+ type FieldType = "text" | "email" | "number" | "password" | "tel" | "url" | "date" | "color" | "hidden" | "textarea" | "select" | "checkbox" | "boolean" | "radio" | "file" | "avatar" | "table" | "users" | "timezone" | "audio_select" | "tags" | "field-select" | "group" | "row";
10
14
  type BaseField = {
11
15
  label?: string;
12
16
  key: string;
13
17
  placeholder?: string;
14
18
  name?: string;
15
- type?: string;
19
+ type?: FieldType | string;
16
20
  required?: boolean;
17
21
  validation?: Validation;
22
+ /**
23
+ * Hint text displayed below the input field (after the input).
24
+ */
18
25
  hint_text?: string;
26
+ /**
27
+ * Description text displayed below the label (before the input).
28
+ * Use this to provide context about the field.
29
+ */
30
+ description?: string;
19
31
  direction?: "horizontal" | "vertical";
20
32
  options?: Option[];
21
- default?: string;
33
+ default?: string | boolean;
22
34
  width?: string;
23
35
  accept?: string;
24
36
  multiple?: boolean;
25
- description?: string;
26
37
  icon?: string;
27
38
  option_label?: string;
28
39
  };
@@ -84,4 +95,4 @@ declare const _default: {
84
95
  };
85
96
  };
86
97
 
87
- export { FormsLib, _default as default };
98
+ export { type BaseField, type FieldType, type FormData, FormsLib, type Option, type RenderOptions, type RenderedForm, type SubmitConfig, type Validation, _default as default };
@@ -1,2 +1,2 @@
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);})();
1
+ "use strict";var VocLibJs=(()=>{var P=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ae=Object.prototype.hasOwnProperty;var ne=(n,w)=>{for(var v in w)P(n,v,{get:w[v],enumerable:!0})},re=(n,w,v,L)=>{if(w&&typeof w=="object"||typeof w=="function")for(let p of te(w))!ae.call(n,p)&&p!==v&&P(n,p,{get:()=>w[p],enumerable:!(L=ee(w,p))||L.enumerable});return n};var se=n=>re(P({},"__esModule",{value:!0}),n);var me={};ne(me,{FormsLib:()=>le,default:()=>de});function j(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");p.className="voc-form-avatar-wrapper",L&&p.classList.add("d-flex","align-items-center","gap-3");let b=document.createElement("img");b.className="voc-form-avatar-preview",b.alt=n.label||"avatar",L&&(b.classList.add("img-thumbnail","rounded-circle"),b.style.width=b.style.height="64px",b.style.objectFit="cover");let m=v!=null?String(v):n.default!==void 0&&n.default!==null?String(n.default):"";m?b.src=m:(b.src="",b.style.display="none");let i=document.createElement("input");i.type="file",i.accept=n.accept||"image/*",i.className="voc-form-avatar-input",L&&i.classList.add("form-control"),(n.key||n.name)&&(i.name=n.name||n.key,n.key&&(i.id=`voc-form-${n.key}`));let d=document.createElement("input");if(d.type="hidden",(n.key||n.name)&&(d.name=(n.name||n.key)+"_url"),d.value=m||"",i.addEventListener("change",u=>{let k=u.target;if(k.files&&k.files.length>0){let T=k.files[0],C=new FileReader;C.onload=()=>{b.src=String(C.result),b.style.display="",d.value=""},C.readAsDataURL(T)}}),L){let u=document.createElement("div");u.style.flex="1",u.appendChild(i),u.appendChild(d),p.appendChild(b),p.appendChild(u)}else p.appendChild(b),p.appendChild(i),p.appendChild(d);return p}function W(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");if(p.className="voc-form-audio-select",!n.options||n.options.length===0)return p;let b=n.name||n.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,m;return Array.isArray(v)?m=v[0]:v!==void 0?m=v:n.default!==void 0&&(m=n.default),n.options.forEach((i,d)=>{let u=document.createElement("div");u.className="voc-form-audio-item",L&&u.classList.add("form-check");let k=document.createElement("input");k.type="radio",k.name=b,k.value=i.value,k.className="voc-form-audio-radio",n.key&&(k.id=`voc-form-${n.key}-${d}`),n.required&&d===0&&(k.required=!0),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",m!==void 0&&(Array.isArray(m)?k.checked=m.includes(i.value):k.checked=String(m)===String(i.value));let T=()=>{k.checked?u.classList.add("selected"):u.classList.remove("selected")};k.addEventListener("change",()=>{p.querySelectorAll(".voc-form-audio-item").forEach(r=>r.classList.remove("selected")),T()}),k.checked&&u.classList.add("selected");let C=document.createElement("label");C.className="voc-form-audio-label",L&&C.classList.add("form-check-label"),C.htmlFor=k.id||"",C.textContent=i.label||i.value,C.tabIndex=0;let g=document.createElement("div");g.className="voc-form-audio-control";let e=null;if(i.audio_link){let l=document.createElement("button");l.type="button",l.className="voc-form-audio-play",L&&l.classList.add("btn","btn-sm","btn-outline-secondary"),l.setAttribute("aria-label",`Play ${i.label||i.value}`);let r="http://www.w3.org/2000/svg",a=document.createElementNS(r,"svg");a.setAttribute("viewBox","0 0 24 24"),a.setAttribute("width","16"),a.setAttribute("height","16"),a.setAttribute("aria-hidden","true");let t=document.createElementNS(r,"path");t.setAttribute("d","M8 5v14l11-7z"),t.setAttribute("fill","currentColor"),a.appendChild(t),l.appendChild(a),e=document.createElement("audio"),e.src=i.audio_link,e.preload="none",e.style.display="none";let c=y=>{for(;y.firstChild;)y.removeChild(y.firstChild)},E=()=>{let y="http://www.w3.org/2000/svg",F=document.createElementNS(y,"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(y,"path");return M.setAttribute("d","M8 5v14l11-7z"),M.setAttribute("fill","currentColor"),F.appendChild(M),F},x=()=>{let y="http://www.w3.org/2000/svg",F=document.createElementNS(y,"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(y,"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};c(l),l.appendChild(E());let N=y=>{c(l),y?(l.appendChild(x()),l.setAttribute("aria-label",`Stop ${i.label||i.value}`)):(l.appendChild(E()),l.setAttribute("aria-label",`Play ${i.label||i.value}`))};l.addEventListener("click",()=>{try{if(!e)return;let y=p.querySelectorAll("audio");if(!e.paused&&!e.ended){e.pause(),e.currentTime=0;return}y.forEach(M=>{try{M.pause(),M.currentTime=0}catch{}}),p.querySelectorAll(".voc-form-audio-item").forEach(M=>M.classList.remove("is-playing")),e.play()}catch(y){console.warn("audio play failed",y)}}),e.addEventListener("playing",()=>{u.classList.add("is-playing"),N(!0)});let A=()=>{u.classList.remove("is-playing"),N(!1)};e.addEventListener("pause",A),e.addEventListener("ended",A),g.appendChild(l),g.appendChild(e)}let h=document.createElement("div");h.className="voc-form-item-detail",h.style.display="flex",h.style.flexDirection="column",h.style.gap="4px";let s=document.createElement("div");s.className="voc-form-item-top",s.style.display="flex",s.style.alignItems="center",s.style.gap="8px",s.appendChild(k),s.appendChild(C);let o=document.createElement("div");o.className="voc-form-item-description";let f=i.description||i.hint_text||"";f&&(o.textContent=f),h.appendChild(s),h.appendChild(o),g.appendChild(h),u.appendChild(g),s.addEventListener("click",l=>{let r=l.target;r&&r.closest(".voc-form-audio-play")||(k.checked=!0,k.dispatchEvent(new Event("change",{bubbles:!0})))}),u.addEventListener("click",l=>{let r=l.target;r&&r.closest(".voc-form-audio-play")||(k.checked=!0,k.dispatchEvent(new Event("change",{bubbles:!0})))}),p.appendChild(u)}),p}function G(n,w,v){let L=document.createElement("div");L.className="voc-form-table-wrapper";let p=w?.style==="bootstrap",b=document.createElement("input");b.type="hidden",b.name=n.name||n.key,n.key&&(b.id=`voc-form-${n.key}`),L.appendChild(b);let m=document.createElement("table");m.className="voc-form-table",p&&m.classList.add("table","table-bordered");let i=document.createElement("thead"),d=document.createElement("tr"),u=document.createElement("th");u.className="voc-form-table-drag-col",u.textContent="",d.appendChild(u),(n.fields||[]).forEach(r=>{let a=document.createElement("th");a.textContent=r.label||r.key,d.appendChild(a)});let k=document.createElement("th");k.textContent="Actions",d.appendChild(k),i.appendChild(d),m.appendChild(i);let T=document.createElement("tbody");m.appendChild(T),L.appendChild(m);let C=document.createElement("button");C.type="button",C.className="voc-form-table-add",p&&C.classList.add("btn","btn-secondary"),C.textContent="+Add";let g=document.createElement("tfoot"),e=document.createElement("tr"),h=document.createElement("td");h.colSpan=(n.fields?n.fields.length:0)+1,h.appendChild(C),e.appendChild(h),g.appendChild(e),m.appendChild(g),L.appendChild(m);let s=[];function o(){b.value=JSON.stringify(s)}function f(r){let a=[];return n.fields.forEach(t=>{let c=r[t.key];if(t.type==="checkbox"){let E=Array.isArray(c)?c:c?[c]:[];t.required&&E.length===0&&a.push(`${t.label||t.key} is required`);return}t.required&&(c==null||String(c).trim()==="")&&a.push(`${t.label||t.key} is required`),t.type==="email"&&c&&(/^\S+@\S+\.\S+$/.test(String(c))||a.push(`${t.label||t.key} must be a valid email`)),t.type==="number"&&c&&isNaN(Number(c))&&a.push(`${t.label||t.key} must be a number`),t.validation&&t.validation.regex&&c&&(new RegExp(t.validation.regex).test(String(c))||a.push(`${t.label||t.key} invalid format`))}),a}function l(){T.innerHTML="";let r=(a,t)=>{t.draggable=!0,t.addEventListener("mousedown",()=>{t.style.cursor="grabbing"}),t.addEventListener("mouseup",()=>{t.style.cursor="grab"}),t.addEventListener("dragstart",c=>{let E=Number(a.dataset.rowIndex);c.dataTransfer.setData("text/plain",String(E)),a.classList.add("dragging");try{c.dataTransfer?.setDragImage(t,10,10)}catch{}}),t.addEventListener("dragend",()=>{a.classList.remove("dragging"),t.style.cursor="grab"}),a.addEventListener("dragover",c=>{c.preventDefault();let E=c.currentTarget,x=E.getBoundingClientRect(),N=x.top+x.height/2,A=(c.clientY||c.y)>N;E.classList.remove("drag-over-top","drag-over-bottom"),A?(E.classList.add("drag-over-bottom"),E.dataset.dropPosition="after"):(E.classList.add("drag-over-top"),E.dataset.dropPosition="before")}),a.addEventListener("dragleave",c=>{let E=c.currentTarget;E.classList.remove("drag-over-top","drag-over-bottom"),delete E.dataset.dropPosition}),a.addEventListener("drop",c=>{c.preventDefault();let E=c.dataTransfer.getData("text/plain"),x=Number(c.currentTarget.dataset.rowIndex),N=Number(E),A=c.currentTarget.dataset.dropPosition||"before";if(isNaN(N)||isNaN(x))return;let[y]=s.splice(N,1),F=x;N<x&&(F=x-1);let M=A==="after"?F+1:F;s.splice(M,0,y),c.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete c.currentTarget.dataset.dropPosition,l(),o()})};s.forEach((a,t)=>{let c=document.createElement("tr");c.dataset.rowIndex=String(t),c.classList.add("voc-form-table-row");let E=document.createElement("td");E.className="voc-form-table-drag-handle";let x=document.createElement("span");x.className="voc-form-drag-handle-icon",x.textContent="\u2630",x.style.cursor="grab",E.appendChild(x),c.appendChild(E),r(c,x),n.fields.forEach(y=>{let F=document.createElement("td"),M,$=(y.type||"text").toLowerCase();if($==="select"){let S=document.createElement("select");if(S.className="voc-form-table-cell",p&&S.classList.add("form-control"),y.placeholder){let H=document.createElement("option");H.value="",H.textContent=y.placeholder,H.disabled=!0,(a[y.key]===void 0||a[y.key]===null||a[y.key]==="")&&(H.selected=!0),S.appendChild(H)}(y.options||[]).forEach(H=>{let B=document.createElement("option");B.value=H.value,B.textContent=H.label,S.appendChild(B)}),S.value=a[y.key]!==void 0&&a[y.key]!==null?String(a[y.key]):"",y.required&&(S.required=!0),S.addEventListener("change",H=>{s[t][y.key]=H.target.value,o()}),M=S}else if($==="checkbox"){let S=document.createElement("div");S.className="voc-form-table-checkboxes",p&&S.classList.add("form-check");let D=y.options||[];Array.isArray(s[t][y.key])||(s[t][y.key]=s[t][y.key]?[s[t][y.key]]:[]),D.forEach(H=>{let B=`voc-form-${n.key}-${y.key}-${t}-${H.value}`,R=document.createElement("div");R.className="voc-form-table-checkbox-item",p&&R.classList.add("form-check");let q=document.createElement("input");q.type="checkbox",q.className="voc-form-table-cell",p&&q.classList.add("form-check-input"),q.id=B,q.value=H.value,q.checked=Array.isArray(s[t][y.key])&&s[t][y.key].includes(H.value),q.addEventListener("change",O=>{let X=O.target.checked;Array.isArray(s[t][y.key])||(s[t][y.key]=[]),X?s[t][y.key].includes(H.value)||s[t][y.key].push(H.value):s[t][y.key]=s[t][y.key].filter(Z=>Z!==H.value),o()});let _=document.createElement("label");_.htmlFor=B,_.className="voc-form-table-checkbox-label",p&&_.classList.add("form-check-label"),_.textContent=H.label,R.appendChild(q),R.appendChild(_),S.appendChild(R)}),M=S}else if($==="radio"){let S=document.createElement("div");S.className="voc-form-table-radios",p&&S.classList.add("form-check");let D=y.options||[];s[t][y.key]===void 0&&(s[t][y.key]=""),D.forEach(H=>{let B=`voc-form-${n.key}-${y.key}-${t}-${H.value}`,R=document.createElement("div");R.className="voc-form-table-radio-item",p&&R.classList.add("form-check");let q=document.createElement("input");q.type="radio",q.className="voc-form-table-cell",p&&q.classList.add("form-check-input"),q.id=B,q.name=`voc-form-${n.key}-${y.key}-${t}`,q.value=H.value,q.checked=s[t][y.key]===H.value,q.addEventListener("change",O=>{O.target.checked&&(s[t][y.key]=O.target.value,o())});let _=document.createElement("label");_.htmlFor=B,_.className="voc-form-table-radio-label",p&&_.classList.add("form-check-label"),_.textContent=H.label,R.appendChild(q),R.appendChild(_),S.appendChild(R)}),M=S}else{let S=document.createElement("input");$==="number"?S.type="number":$==="email"?S.type="email":$==="tel"?S.type="tel":$==="url"?S.type="url":$==="date"?S.type="date":S.type="text",S.value=a[y.key]!==void 0&&a[y.key]!==null?String(a[y.key]):"",y.placeholder&&(S.placeholder=y.placeholder),y.required&&(S.required=!0),S.className="voc-form-table-cell",p&&S.classList.add("form-control"),S.addEventListener("input",D=>{s[t][y.key]=D.target.value,o()}),M=S}F.appendChild(M),c.appendChild(F)});let N=document.createElement("td"),A=document.createElement("button");A.type="button",A.className="voc-form-table-remove",p&&A.classList.add("btn","btn-danger"),A.textContent="Remove",A.addEventListener("click",()=>{s.splice(t,1),l(),o()}),N.appendChild(A),c.appendChild(N),T.appendChild(c)})}return C.addEventListener("click",()=>{if(n.validation?.max_rows!==void 0&&s.length>=n.validation.max_rows)return;let r={};n.fields.forEach(a=>r[a.key]=""),s.push(r),l(),o()}),Array.isArray(v)&&v.length?s=v.map(r=>({...r})):n.default&&Array.isArray(n.default)&&(s=n.default.map(r=>({...r}))),l(),o(),L.validate=function(){let r=[];return s.forEach((a,t)=>{let c=f(a);c.length&&r.push(`Row ${t+1}: ${c.join("; ")}`)}),n.validation?.min_rows!==void 0&&s.length<n.validation.min_rows&&r.push(`At least ${n.validation.min_rows} rows required`),n.validation?.max_rows!==void 0&&s.length>n.validation.max_rows&&r.push(`No more than ${n.validation.max_rows} rows allowed`),n.validation?.unique_fields&&n.validation.unique_fields.length&&n.validation.unique_fields.forEach(a=>{let t=new Set;s.forEach((c,E)=>{let x=c[a];x!=null&&(t.has(x)&&r.push(`Field ${a} must be unique (duplicate at row ${E+1})`),t.add(x))})}),r},L}async function oe(n){let v=new TextEncoder().encode(n),L=await crypto.subtle.digest("SHA-256",v);return Array.from(new Uint8Array(L)).map(b=>b.toString(16).padStart(2,"0")).join("")}async function ie(n){let w=String(n||"").trim().toLowerCase();return w?`https://gravatar.com/avatar/${await oe(w)}?d=mp`:""}function V(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");p.className="voc-form-users";let b=document.createElement("div");if(b.className="voc-form-users-header",L&&b.classList.add("mb-2"),n.label){let g=document.createElement("div");if(g.className="voc-form-users-label",L&&g.classList.add("form-label"),g.textContent=n.label,n.required){let e=document.createElement("span");e.className="voc-form-required",e.textContent="*",g.appendChild(e)}b.appendChild(g)}if(n.description){let g=document.createElement("div");g.className="voc-form-users-description",L&&g.classList.add("form-text"),g.textContent=n.description,b.appendChild(g)}p.appendChild(b);let m=document.createElement("div");m.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",L&&i.classList.add("form-control","mb-2"),m.appendChild(i),p.appendChild(m),!n.options||n.options.length===0)return p;let d=document.createElement("div");d.className="voc-form-users-list",L&&d.classList.add("list-group");let u=n.name||n.key||`users_${Math.random().toString(36).substr(2,6)}`,k=[];if(Array.isArray(v)?k=v:v!=null?k=[v]:Array.isArray(n.default)&&(k=n.default),n.options.forEach((g,e)=>{let h=document.createElement("div");h.className="voc-form-user-item",h.dataset.label=String(g.label||"").toLowerCase(),h.dataset.email=String(g.email||"").toLowerCase(),h.dataset.value=String(g.value||"").toLowerCase(),L&&h.classList.add("d-flex","align-items-center","gap-2");let s=document.createElement("input");if(s.type="checkbox",s.name=`${u}[]`,s.value=g.value,s.className="voc-form-user-checkbox",n.key&&(s.id=`voc-form-${n.key}-${e}`),s.style.position="absolute",s.style.width="1px",s.style.height="1px",s.style.margin="0",s.style.padding="0",s.style.clip="rect(0 0 0 0)",s.style.clipPath="inset(50%)",s.style.overflow="hidden",s.style.border="0",k&&Array.isArray(k)){let a=k.map(t=>String(t));s.checked=a.includes(String(g.value))}let o=document.createElement("img");o.className="voc-form-user-avatar",o.alt=g.label||String(g.value||"user"),o.style.width=o.style.height="40px",o.style.objectFit="cover",o.style.borderRadius="50%",o.src="",g.email&&ie(g.email).then(a=>{a&&(o.src=a)}).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 l=document.createElement("div");l.className="voc-form-user-label",l.textContent=g.label||String(g.value);let r=document.createElement("small");r.className="voc-form-user-email",r.textContent=g.email||"",f.appendChild(l),f.appendChild(r),h.addEventListener("click",a=>{let t=a.target;t&&(t.closest("input")||t.closest("a")||t.closest("button"))||(s.checked=!s.checked,s.dispatchEvent(new Event("change",{bubbles:!0})))}),s.addEventListener("change",()=>{s.checked?h.classList.add("selected"):h.classList.remove("selected")}),s.checked&&h.classList.add("selected"),h.appendChild(s),h.appendChild(o),h.appendChild(f),d.appendChild(h)}),p.appendChild(d),n.required){let g=d.querySelectorAll('input[type="checkbox"]'),e=()=>{let h=Array.from(g).some(s=>s.checked);return g.forEach(s=>{h?s.setCustomValidity(""):s.setCustomValidity("At least one option must be selected.")}),h};g.forEach(h=>{h.addEventListener("change",e)}),p._validateCheckboxGroup=e,e()}let T=Array.from(d.querySelectorAll(".voc-form-user-item")),C=()=>{let g=String(i.value||"").trim().toLowerCase();if(!g){T.forEach(e=>e.style.setProperty("display","flex","important"));return}T.forEach(e=>{let h=e.dataset.label||"",s=e.dataset.email||"",o=e.dataset.value||"",f=h.includes(g)||s.includes(g)||o.includes(g);e.style.setProperty("display",f?"flex":"none","important")})};return i.addEventListener("input",C),p}function U(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");p.className="voc-form-timezone";let b=n.name||n.key||`timezone_${Math.random().toString(36).substr(2,6)}`,m=document.createElement("input");m.type="text",m.name=b,n.key&&(m.id=`voc-form-${n.key}`),m.className="voc-form-timezone-input",L&&m.classList.add("form-control"),n.placeholder&&(m.placeholder=n.placeholder||""),n.required&&(m.required=!0),n.width&&(m.style.width=n.width);try{m.autocomplete="off"}catch{}try{m.autocorrect="off"}catch{}try{m.autocapitalize="off"}catch{}try{m.spellcheck=!1}catch{}m.setAttribute("data-lpignore","true"),v!=null?m.value=String(v):n.default!==void 0&&n.default!==null&&(m.value=String(n.default));let i=document.createElement("div");i.className="voc-form-timezone-control",i.style.position="relative",i.style.display="inline-block",i.style.width=n.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 u=document.createElement("ul");u.className="voc-form-timezone-list",u.setAttribute("role","listbox"),u.style.position="absolute",u.style.left="0",u.style.right="0",u.style.zIndex="1000",u.style.maxHeight="200px",u.style.overflow="auto",u.style.margin="4px 0 0 0",u.style.padding="0",u.style.listStyle="none",u.style.background="white",u.style.border="1px solid rgba(0,0,0,0.15)",u.style.display="none",u.tabIndex=-1,m.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 C(l){u.innerHTML="",l.forEach((r,a)=>{let t=document.createElement("li");t.className="voc-form-timezone-item",t.setAttribute("role","option"),t.dataset.value=r,t.style.padding="6px 8px",t.style.cursor="pointer",t.textContent=r,t.addEventListener("mousedown",c=>{c.preventDefault(),m.value=r,s(),m.dispatchEvent(new Event("change",{bubbles:!0}))}),u.appendChild(t)})}C(T);let g=-1;function e(){Array.from(u.children).forEach((r,a)=>{a===g?(r.style.background="rgba(0,123,255,0.1)",r.setAttribute("aria-selected","true")):(r.style.background="",r.removeAttribute("aria-selected"))})}function h(){u.style.display="block",d.setAttribute("aria-expanded","true")}function s(){u.style.display="none",d.setAttribute("aria-expanded","false"),g=-1,e()}function o(){u.style.display==="none"?h():s()}m.addEventListener("input",()=>{let l=(m.value||"").trim().toLowerCase(),r=l?T.filter(a=>a.toLowerCase().includes(l)):T;C(r),h()}),d.addEventListener("click",l=>{l.preventDefault(),u.style.display==="none"?(C(T),h(),m.focus()):s()}),m.addEventListener("keydown",l=>{let r=Array.from(u.children);if(l.key==="ArrowDown"){if(l.preventDefault(),r.length===0)return;g=Math.min(g+1,r.length-1),e(),r[g].scrollIntoView({block:"nearest"})}else if(l.key==="ArrowUp"){if(l.preventDefault(),r.length===0)return;g=Math.max(g-1,0),e(),r[g].scrollIntoView({block:"nearest"})}else if(l.key==="Enter"){if(u.style.display!=="none"&&g>=0){l.preventDefault();let a=r[g];m.value=a.dataset.value||a.textContent||"",s(),m.dispatchEvent(new Event("change",{bubbles:!0}))}}else l.key==="Escape"&&s()}),document.addEventListener("click",l=>{i.contains(l.target)||s()});let f={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(m.addEventListener("blur",()=>{let l=(m.value||"").trim();if(!l)return;let r=Object.keys(f).find(a=>a.toLowerCase()===l.toLowerCase());r&&(m.value=f[r])}),n.description){let l=document.createElement("div");l.className="voc-form-timezone-description",L&&l.classList.add("form-text"),l.textContent=n.description,p.appendChild(l)}return i.appendChild(m),i.appendChild(d),i.appendChild(u),p.appendChild(i),p}function J(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");p.className="voc-form-tags";let b=n.name||n.key||`tags_${Math.random().toString(36).substr(2,6)}`,m=document.createElement("div");m.className="voc-form-tags-container",m.style.display="flex",m.style.flexWrap="wrap",m.style.gap="6px",m.style.alignItems="center",m.style.padding="6px",m.style.border="1px solid rgba(0,0,0,0.12)",m.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=n.placeholder||"",L&&i.classList.add("form-control"),m.appendChild(i);let d=[],u=document.createElement("input");u.type="text",u.style.position="absolute",u.style.left="-9999px",u.style.width="1px",u.style.height="1px",u.tabIndex=-1,n.required&&(u.required=!0),p.appendChild(u);function k(){Array.from(p.querySelectorAll("input.voc-form-tag-hidden")).forEach(h=>h.parentElement?.removeChild(h)),d.forEach(h=>{let s=document.createElement("input");s.type="hidden",s.name=`${b}[]`,s.className="voc-form-tag-hidden",s.value=h,n.key&&(s.id=`voc-form-${n.key}`),p.appendChild(s)}),n.required&&(d.length===0?(u.value="",u.setCustomValidity("Please enter at least one tag")):(u.value="1",u.setCustomValidity("")))}function T(e){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 s=document.createElement("span");s.textContent=e,s.style.marginRight="8px",h.appendChild(s);let o=document.createElement("button");return o.type="button",o.textContent="\xD7",o.style.border="none",o.style.background="transparent",o.style.cursor="pointer",o.addEventListener("click",()=>{let f=d.indexOf(e);f>=0&&(d.splice(f,1),m.removeChild(h),k())}),h.appendChild(o),h}function C(e){let h=e.trim();if(!h||d.includes(h))return;d.push(h);let s=T(h);m.insertBefore(s,i),k()}let g=v!=null?String(v):n.default||"";return g&&g.split(",").map(e=>e.trim()).filter(Boolean).forEach(C),i.addEventListener("keydown",e=>{if(e.key==="Enter"||e.key===",")e.preventDefault(),C(i.value),i.value="";else if(e.key==="Backspace"&&i.value===""&&d.pop()){let s=Array.from(m.querySelectorAll(".voc-form-tag")),o=s[s.length-1];o&&m.removeChild(o),k()}}),i.addEventListener("paste",e=>{let h=e.clipboardData?.getData("text");h&&(e.preventDefault(),h.split(/[,\n\r]+/).map(s=>s.trim()).filter(Boolean).forEach(C),i.value="")}),p.getTags=()=>d.slice(),p.addTag=C,p.appendChild(m),k(),p}function Y(n,w,v,L){let p=w?.style==="bootstrap",b=document.createElement("div");b.className="voc-form-field-selects";let m=document.createElement("div");if(m.className="voc-form-field-selects-header",p&&m.classList.add("mb-2"),n.label){let o=document.createElement("div");if(o.className="voc-form-field-selects-label",p&&o.classList.add("form-label"),o.textContent=n.label,n.required){let f=document.createElement("span");f.className="voc-form-required",f.textContent="*",o.appendChild(f)}m.appendChild(o)}if(n.description){let o=document.createElement("div");o.className="voc-form-field-selects-description",p&&o.classList.add("form-text"),o.textContent=n.description,m.appendChild(o)}b.appendChild(m);let i=document.createElement("div");i.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",p&&d.classList.add("form-control","mb-2"),i.appendChild(d),b.appendChild(i);let u=n.options;if(!u||u.length===0)return b;let k=document.createElement("div");k.className="voc-form-field-selects-list",p&&k.classList.add("list-group");let T=document.createElement("div");T.className="voc-form-field-selects-selected",T.style.marginTop="12px";let C={},g=n.name||n.key||`users_${Math.random().toString(36).substr(2,6)}`,e=[];if(Array.isArray(v)?e=v:v!=null?e=[v]:Array.isArray(n.default)&&(e=n.default),u.forEach((o,f)=>{let l=document.createElement("div");l.className="voc-form-field-selects-item",l.dataset.label=String(o.option_label??o.label??"").toLowerCase(),l.dataset.email=String(o.email||"").toLowerCase(),l.dataset.value=String(o.value||"").toLowerCase(),p&&l.classList.add("d-flex","align-items-center","gap-2");let r=document.createElement("input");if(r.type="checkbox",r.name=`${g}[]`,r.value=o.value??o.key,r.className="voc-form--checkbox",n.key&&(r.id=`voc-form-${n.key}-${f}`),r.style.position="absolute",r.style.width="1px",r.style.height="1px",r.style.margin="0",r.style.padding="0",r.style.clip="rect(0 0 0 0)",r.style.clipPath="inset(50%)",r.style.overflow="hidden",r.style.border="0",e&&Array.isArray(e)){let N=e.map(y=>String(y)),A=String(o.value??o.key);r.checked=N.includes(A)}let a=o.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>',t=document.createElement("div");t.className="voc-form-fields-select-avatar",t.innerHTML=a;let c=document.createElement("div");c.className="voc-form-field-select-info",c.style.display="flex",c.style.flexDirection="column",c.style.gap="2px";let E=document.createElement("div");E.className="voc-form-field-select-label",E.textContent=(o.option_label??o.label)||String(o.value);let x=document.createElement("small");x.className="voc-form-field-select-email",x.textContent=o.email||"",c.appendChild(E),c.appendChild(x),l.addEventListener("click",N=>{let A=N.target;A&&(A.closest("input")||A.closest("a")||A.closest("button"))||(r.checked=!r.checked,r.dispatchEvent(new Event("change",{bubbles:!0})))}),r.addEventListener("change",()=>{if(r.checked){l.classList.add("selected"),(C[f]||[]).forEach(y=>y.parentElement?.removeChild(y)),C[f]=[];let A=o;if(A&&Array.isArray(A.items))A.items.forEach(y=>{let F=L(y);F&&(T.appendChild(F),C[f].push(F))});else if(A&&(A.type||A.key)){let y=L(A);y&&(T.appendChild(y),C[f].push(y))}}else l.classList.remove("selected"),(C[f]||[]).forEach(A=>A.parentElement?.removeChild(A)),C[f]=[]}),r.checked&&(l.classList.add("selected"),setTimeout(()=>{let N=o;if(N&&Array.isArray(N.items))N.items.forEach(A=>{let y=L(A);y&&(T.appendChild(y),C[f]=C[f]||[],C[f].push(y))});else if(N&&(N.type||N.key)){let A=L(N);A&&(T.appendChild(A),C[f]=C[f]||[],C[f].push(A))}},0)),l.appendChild(r),l.appendChild(t),l.appendChild(c),k.appendChild(l)}),b.appendChild(k),b.appendChild(T),n.required){let o=k.querySelectorAll('input[type="checkbox"]'),f=()=>{let l=Array.from(o).some(r=>r.checked);return o.forEach(r=>{l?r.setCustomValidity(""):r.setCustomValidity("At least one option must be selected.")}),l};o.forEach(l=>{l.addEventListener("change",f)}),b._validateCheckboxGroup=f,f()}let h=Array.from(k.querySelectorAll(".voc-form-field-select-item")),s=()=>{let o=String(d.value||"").trim().toLowerCase();if(!o){h.forEach(f=>f.style.setProperty("display","flex","important"));return}h.forEach(f=>{let l=f.dataset.label||"",r=f.dataset.email||"",a=f.dataset.value||"",t=l.includes(o)||r.includes(o)||a.includes(o);f.style.setProperty("display",t?"flex":"none","important")})};return d.addEventListener("input",s),b}function I(n,w=!0){let v=new FormData(n);if(w)return ce(v);let L={};return v.forEach((p,b)=>{let m=(p instanceof File,p);Object.prototype.hasOwnProperty.call(L,b)?Array.isArray(L[b])?L[b].push(m):L[b]=[L[b],m]:L[b]=m}),L}function ce(n){let w=new FormData;for(let[v,L]of n.entries()){if(L instanceof File){w.append(v,L);continue}let p;try{p=JSON.parse(L)}catch{p=null}Array.isArray(p)?p.length===0?w.append(v,"[]"):p.every(b=>typeof b=="object"&&b!==null)?p.forEach((b,m)=>{for(let[i,d]of Object.entries(b))w.append(`${v}[${m}][${i}]`,d)}):w.append(v,L):w.append(v,L)}return w}async function K(n,w,v){let L=w.url,p={"Content-Type":"application/json"};w?.api_token&&(p.Authorization=`Bearer ${w.api_token}`);let b=I(n);if(w?.additional_data)for(let[d,u]of Object.entries(w.additional_data))b.append(d,u);let m,i=b instanceof FormData;m={method:"POST",headers:{Authorization:`Bearer ${w.api_token}`,...i?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:i?b:JSON.stringify(Object.fromEntries(b.entries()))};try{fetch(L,m).then(async d=>{let u=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(k){throw new Error(k.message)}return u&&u.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(n,w,v){let L=[];if(typeof n=="string"?L=Array.from(document.querySelectorAll(n)):L=[n],L.length===0)return null;function p(){let i=v?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),i&&d.classList.add("needs-validation"),d.id=w.id;let u=document.createElement("h2");u.className="voc-form-title",i&&u.classList.add("mb-3"),u.textContent=w.form_name,d.appendChild(u);function k(e,h){h&&(h.min_length!==void 0&&(e.minLength=h.min_length),h.max_length!==void 0&&(e.maxLength=h.max_length),h.regex&&(e instanceof HTMLInputElement?e.pattern=h.regex:e.dataset.pattern=h.regex))}function T(e){if(!e.key&&!e.label)return null;let h=w.default_values||{},s=e.name||e.key,o=s?h[s]:void 0,f=document.createElement("div");if(f.className="voc-form-group",i&&f.classList.add("mb-3"),e.label&&e.type!=="users"){let a=document.createElement("label");if(a.classList.add("voc-form-label"),i&&a.classList.add("form-label"),e.key?e.type==="radio"?a.htmlFor="":a.htmlFor=`voc-form-${e.key}`:a.htmlFor="",a.textContent=e.label,e.required){let t=document.createElement("span");t.className="voc-form-required",t.textContent="*",a.appendChild(t)}f.appendChild(a)}let l=new Set(["users","timezone"]);if(e.description&&!l.has(String(e.type||""))){let a=document.createElement("div");a.className="voc-form-description",i&&a.classList.add("form-text","text-muted","mb-2"),a.textContent=e.description,f.appendChild(a)}let r=null;switch(e.type){case"tags":{r=J(e,v||{},o);break}case"checkbox":{let a=document.createElement("div");if(a.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(a.style.width=e.width),e.options){if(e.options.forEach((t,c)=>{let E=document.createElement("label");E.classList.add("voc-form-checkbox-label"),i&&E.classList.add("form-check"),E.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(E.style.width=e.width);let x=document.createElement("input");x.type="checkbox",x.classList.add("voc-form-checkbox"),i&&x.classList.add("form-check-input"),x.name=`${e.name||e.key||""}[]`,x.value=t.value,e.key&&(x.id=`voc-form-${e.key}-${c}`),Array.isArray(o)?o.includes(t.value)&&(x.checked=!0):o!==void 0?o===t.value&&(x.checked=!0):e.default===t.value&&(x.checked=!0),E.appendChild(x),E.appendChild(document.createTextNode(t.label)),a.appendChild(E)}),e.required){let t=a.querySelectorAll('input[type="checkbox"]'),c=()=>{let E=Array.from(t).some(x=>x.checked);return t.forEach(x=>{E?x.setCustomValidity(""):x.setCustomValidity("At least one option must be selected.")}),E};t.forEach(E=>{E.addEventListener("change",c)}),a._validateCheckboxGroup=c,c()}}else{let t=document.createElement("label");t.classList.add("voc-form-checkbox-label"),i&&t.classList.add("form-check"),e.width&&(t.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),(e.key||e.name)&&(c.name=e.name||e.key,e.key&&(c.id=`voc-form-${e.key}`)),i&&c.classList.add("form-check-input"),e.required&&(c.required=!0),o!==void 0?c.checked=!!o:e.default&&(c.checked=!!e.default),t.appendChild(c),t.appendChild(document.createTextNode(e.label||"")),a.appendChild(t)}r=a;break}case"boolean":{let a=document.createElement("div");a.className="voc-form-boolean-wrapper",i&&a.classList.add("form-check"),e.width&&(a.style.width=e.width);let t=document.createElement("input");if(t.type="checkbox",t.classList.add("voc-form-boolean"),i&&t.classList.add("form-check-input"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.required&&(t.required=!0),o!==void 0?t.checked=!!o:e.default!==void 0&&(t.checked=e.default===!0||e.default==="true"),a.appendChild(t),e.label){let E=document.createElement("label");if(E.classList.add("voc-form-boolean-label"),i&&E.classList.add("form-check-label"),e.key&&(E.htmlFor=`voc-form-${e.key}`),E.textContent=e.label,e.required){let x=document.createElement("span");x.className="voc-form-required",x.textContent="*",E.appendChild(x)}a.appendChild(E)}let c=f.querySelector(".voc-form-label");c&&c.remove(),r=a;break}case"textarea":{let a=document.createElement("textarea");a.classList.add("voc-form-textarea"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder&&(a.placeholder=e.placeholder),o!=null?a.value=String(o):e.default!==void 0&&e.default!==null&&(a.value=String(e.default));let t=e.default||o||"";if(t){let c=(t.match(/\n/g)||[]).length,E=80,x=t.split(`
2
+ `).reduce((y,F)=>Math.max(y,F.length),0),N=Math.ceil(x/E)||1,A=Math.max(2,c+N);a.rows=A,a.style.resize="vertical"}e.width&&(a.style.width=e.width),e.required&&(a.required=!0),k(a,e.validation),r=a;break}case"select":{let a=document.createElement("select");if(a.classList.add("voc-form-select"),i&&a.classList.add("form-select"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder){let t=document.createElement("option");t.value="",t.textContent=e.placeholder,t.disabled=!0,t.selected=!0,a.appendChild(t)}e.required&&(a.required=!0),e.options&&e.options.forEach(t=>{let c=document.createElement("option");c.value=t.value,c.textContent=t.label,Array.isArray(o)?o.includes(t.value)&&(c.selected=!0):o!==void 0?o===t.value&&(c.selected=!0):e.default===t.value&&(c.selected=!0),a.appendChild(c)}),e.width&&(a.style.width=e.width),r=a;break}case"radio":{let a=document.createElement("div");a.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(a.style.width=e.width),e.options&&e.options.forEach((t,c)=>{let E=document.createElement("label");E.classList.add("voc-form-radio-label"),i&&E.classList.add("form-check"),E.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(E.style.width=e.width);let x=document.createElement("input");x.type="radio",x.classList.add("voc-form-radio"),i&&x.classList.add("form-check-input"),x.name=e.name||e.key||"",x.value=t.value,e.key&&(x.id=`voc-form-${e.key}-${c}`),Array.isArray(o)?o.includes(t.value)&&(x.checked=!0):o!==void 0?o===t.value&&(x.checked=!0):e.default===t.value&&(x.checked=!0),E.appendChild(x),E.appendChild(document.createTextNode(t.label)),a.appendChild(E)}),r=a;break}case"file":{let a=document.createElement("div");a.className="voc-form-file-wrapper",e.width&&(a.style.width=e.width);let t=document.createElement("input");t.type="file",t.classList.add("voc-form-file"),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.width&&(t.style.width=e.width),e.required&&(t.required=!0),e.accept&&(t.accept=e.accept),e.multiple&&(t.multiple=!0),a.appendChild(t),r=a;break}case"avatar":{r=j(e,v||{},o);break}case"table":{r=G(e,v||{},o);break}case"users":{r=V(e,v||{},o);break}case"timezone":{r=U(e,v||{},o);break}case"audio_select":{r=W(e,v||{},o);break}case"field-select":{r=Y(e,v||{},o,T);break}default:{let a=document.createElement("input");a.type=e.type||"text",a.classList.add("voc-form-input"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder&&(a.placeholder=e.placeholder),o!=null?a.value=String(o):e.default!==void 0&&e.default!==null&&(a.value=String(e.default)),e.width&&(a.style.width=e.width),e.required&&(a.required=!0),k(a,e.validation),r=a;break}}if(r&&f.appendChild(r),e.hint_text){let a=document.createElement("small");a.className="voc-form-hint",a.textContent=e.hint_text,f.appendChild(a)}return f}function C(e,h,s=0){if(e.type==="group"&&"items"in e){let f=e;if(i){let l=document.createElement("div");l.className="card voc-form-group-card mb-3",s>0&&l.classList.add("voc-form-nested-group");let r=f.label||f.header?.title,a=f.description||f.header?.description;if(r||a){let c=document.createElement("div");if(c.className="card-header voc-form-group-head",r){let E=document.createElement("h5");E.className="mb-0 voc-form-group-label",E.textContent=r,c.appendChild(E)}if(a){let E=document.createElement("p");E.className="mb-0 voc-form-group-description",E.textContent=a,c.appendChild(E)}l.appendChild(c)}let t=document.createElement("div");t.className="card-body voc-form-group-body",f.items.forEach(c=>{C(c,t,s+1)}),l.appendChild(t),h.appendChild(l)}else{let l=document.createElement("div");l.className="voc-form-group voc-form-group-wrapper",s>0&&l.classList.add("voc-form-nested-group");let r=f.label||f.header?.title,a=f.description||f.header?.description;if(r||a){let t=document.createElement("div");if(t.className="voc-form-group-head",r){let c=document.createElement("h3");c.className="voc-form-group-label",c.textContent=r,t.appendChild(c)}if(a){let c=document.createElement("p");c.className="voc-form-group-description",c.textContent=a,t.appendChild(c)}l.appendChild(t)}f.items.forEach(t=>{C(t,l,s+1)}),h.appendChild(l)}return}if(e.type==="row"&&"items"in e){let f=e,l=document.createElement("div");if(l.className="voc-form-group voc-form-row",i&&l.classList.add("mb-3"),f.label){let a=document.createElement(s>0?"h6":"h3");a.className="voc-form-row-label",a.textContent=f.label,l.appendChild(a)}if(f.description){let a=document.createElement("p");a.className="voc-form-row-description",a.textContent=f.description,l.appendChild(a)}let r=document.createElement("div");r.className="voc-form-row-items "+(f.direction||"horizontal"),f.items.forEach(a=>{let t=T(a);t&&r.appendChild(t)}),l.appendChild(r),h.appendChild(l);return}let o=T(e);o&&h.appendChild(o)}w.fields.forEach(e=>{C(e,d,0)});let g=document.createElement("button");return g.type="submit",g.className="voc-form-submit",g.textContent="Submit",i&&g.classList.add("btn","btn-primary"),d.appendChild(g),d}let b=p();L[0].appendChild(b);let m=w?.submit_config??v?.submit_config??null;return m&&b.addEventListener("submit",i=>{i.preventDefault();let d=Array.from(b.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),u=[];if(d.forEach(C=>{C&&typeof C._validateCheckboxGroup=="function"&&(C._validateCheckboxGroup()||C.querySelector('input[type="checkbox"]')&&u.push("Please select at least one option"))}),!b.checkValidity()){b.reportValidity(),v?.onSubmitResult&&v.onSubmitResult(null,new Error("Form validation failed"));return}let k=Array.from(b.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),T=[];if(k.forEach(C=>{if(C&&typeof C.validate=="function"){let g=C.validate();g&&g.length&&T.push(...g)}}),T.length){v?.onSubmitResult&&v.onSubmitResult(null,new Error(T.join("; ")));let C=k[0];C&&C.scrollIntoView({behavior:"smooth",block:"center"});return}if(v?.onSubmit){let C=I(b);v.onSubmit(C)}K(b,m,(C,g)=>{v?.onSubmitResult&&v.onSubmitResult(C,g)})}),{element:b,validate:()=>{let i=[];return b.querySelectorAll(":invalid").forEach(u=>{let k=u.validationMessage;i.push({element:u,message:k})}),i},getValues:()=>I(b),onSubmit:i=>{b.addEventListener("submit",d=>{d.preventDefault();let u=I(b);i(u,d)})}}}var z={renderForm:Q};var le=z,de={FormsLib:z};return se(me);})();
package/dist/main.js CHANGED
@@ -1,2 +1,2 @@
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});
1
+ "use strict";var P=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ae=Object.prototype.hasOwnProperty;var ne=(n,w)=>{for(var v in w)P(n,v,{get:w[v],enumerable:!0})},re=(n,w,v,L)=>{if(w&&typeof w=="object"||typeof w=="function")for(let p of te(w))!ae.call(n,p)&&p!==v&&P(n,p,{get:()=>w[p],enumerable:!(L=ee(w,p))||L.enumerable});return n};var se=n=>re(P({},"__esModule",{value:!0}),n);var me={};ne(me,{FormsLib:()=>le,default:()=>de});module.exports=se(me);function j(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");p.className="voc-form-avatar-wrapper",L&&p.classList.add("d-flex","align-items-center","gap-3");let b=document.createElement("img");b.className="voc-form-avatar-preview",b.alt=n.label||"avatar",L&&(b.classList.add("img-thumbnail","rounded-circle"),b.style.width=b.style.height="64px",b.style.objectFit="cover");let m=v!=null?String(v):n.default!==void 0&&n.default!==null?String(n.default):"";m?b.src=m:(b.src="",b.style.display="none");let i=document.createElement("input");i.type="file",i.accept=n.accept||"image/*",i.className="voc-form-avatar-input",L&&i.classList.add("form-control"),(n.key||n.name)&&(i.name=n.name||n.key,n.key&&(i.id=`voc-form-${n.key}`));let d=document.createElement("input");if(d.type="hidden",(n.key||n.name)&&(d.name=(n.name||n.key)+"_url"),d.value=m||"",i.addEventListener("change",u=>{let k=u.target;if(k.files&&k.files.length>0){let T=k.files[0],C=new FileReader;C.onload=()=>{b.src=String(C.result),b.style.display="",d.value=""},C.readAsDataURL(T)}}),L){let u=document.createElement("div");u.style.flex="1",u.appendChild(i),u.appendChild(d),p.appendChild(b),p.appendChild(u)}else p.appendChild(b),p.appendChild(i),p.appendChild(d);return p}function W(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");if(p.className="voc-form-audio-select",!n.options||n.options.length===0)return p;let b=n.name||n.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,m;return Array.isArray(v)?m=v[0]:v!==void 0?m=v:n.default!==void 0&&(m=n.default),n.options.forEach((i,d)=>{let u=document.createElement("div");u.className="voc-form-audio-item",L&&u.classList.add("form-check");let k=document.createElement("input");k.type="radio",k.name=b,k.value=i.value,k.className="voc-form-audio-radio",n.key&&(k.id=`voc-form-${n.key}-${d}`),n.required&&d===0&&(k.required=!0),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",m!==void 0&&(Array.isArray(m)?k.checked=m.includes(i.value):k.checked=String(m)===String(i.value));let T=()=>{k.checked?u.classList.add("selected"):u.classList.remove("selected")};k.addEventListener("change",()=>{p.querySelectorAll(".voc-form-audio-item").forEach(r=>r.classList.remove("selected")),T()}),k.checked&&u.classList.add("selected");let C=document.createElement("label");C.className="voc-form-audio-label",L&&C.classList.add("form-check-label"),C.htmlFor=k.id||"",C.textContent=i.label||i.value,C.tabIndex=0;let g=document.createElement("div");g.className="voc-form-audio-control";let e=null;if(i.audio_link){let l=document.createElement("button");l.type="button",l.className="voc-form-audio-play",L&&l.classList.add("btn","btn-sm","btn-outline-secondary"),l.setAttribute("aria-label",`Play ${i.label||i.value}`);let r="http://www.w3.org/2000/svg",a=document.createElementNS(r,"svg");a.setAttribute("viewBox","0 0 24 24"),a.setAttribute("width","16"),a.setAttribute("height","16"),a.setAttribute("aria-hidden","true");let t=document.createElementNS(r,"path");t.setAttribute("d","M8 5v14l11-7z"),t.setAttribute("fill","currentColor"),a.appendChild(t),l.appendChild(a),e=document.createElement("audio"),e.src=i.audio_link,e.preload="none",e.style.display="none";let c=y=>{for(;y.firstChild;)y.removeChild(y.firstChild)},E=()=>{let y="http://www.w3.org/2000/svg",F=document.createElementNS(y,"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(y,"path");return M.setAttribute("d","M8 5v14l11-7z"),M.setAttribute("fill","currentColor"),F.appendChild(M),F},x=()=>{let y="http://www.w3.org/2000/svg",F=document.createElementNS(y,"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(y,"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};c(l),l.appendChild(E());let N=y=>{c(l),y?(l.appendChild(x()),l.setAttribute("aria-label",`Stop ${i.label||i.value}`)):(l.appendChild(E()),l.setAttribute("aria-label",`Play ${i.label||i.value}`))};l.addEventListener("click",()=>{try{if(!e)return;let y=p.querySelectorAll("audio");if(!e.paused&&!e.ended){e.pause(),e.currentTime=0;return}y.forEach(M=>{try{M.pause(),M.currentTime=0}catch{}}),p.querySelectorAll(".voc-form-audio-item").forEach(M=>M.classList.remove("is-playing")),e.play()}catch(y){console.warn("audio play failed",y)}}),e.addEventListener("playing",()=>{u.classList.add("is-playing"),N(!0)});let A=()=>{u.classList.remove("is-playing"),N(!1)};e.addEventListener("pause",A),e.addEventListener("ended",A),g.appendChild(l),g.appendChild(e)}let h=document.createElement("div");h.className="voc-form-item-detail",h.style.display="flex",h.style.flexDirection="column",h.style.gap="4px";let s=document.createElement("div");s.className="voc-form-item-top",s.style.display="flex",s.style.alignItems="center",s.style.gap="8px",s.appendChild(k),s.appendChild(C);let o=document.createElement("div");o.className="voc-form-item-description";let f=i.description||i.hint_text||"";f&&(o.textContent=f),h.appendChild(s),h.appendChild(o),g.appendChild(h),u.appendChild(g),s.addEventListener("click",l=>{let r=l.target;r&&r.closest(".voc-form-audio-play")||(k.checked=!0,k.dispatchEvent(new Event("change",{bubbles:!0})))}),u.addEventListener("click",l=>{let r=l.target;r&&r.closest(".voc-form-audio-play")||(k.checked=!0,k.dispatchEvent(new Event("change",{bubbles:!0})))}),p.appendChild(u)}),p}function G(n,w,v){let L=document.createElement("div");L.className="voc-form-table-wrapper";let p=w?.style==="bootstrap",b=document.createElement("input");b.type="hidden",b.name=n.name||n.key,n.key&&(b.id=`voc-form-${n.key}`),L.appendChild(b);let m=document.createElement("table");m.className="voc-form-table",p&&m.classList.add("table","table-bordered");let i=document.createElement("thead"),d=document.createElement("tr"),u=document.createElement("th");u.className="voc-form-table-drag-col",u.textContent="",d.appendChild(u),(n.fields||[]).forEach(r=>{let a=document.createElement("th");a.textContent=r.label||r.key,d.appendChild(a)});let k=document.createElement("th");k.textContent="Actions",d.appendChild(k),i.appendChild(d),m.appendChild(i);let T=document.createElement("tbody");m.appendChild(T),L.appendChild(m);let C=document.createElement("button");C.type="button",C.className="voc-form-table-add",p&&C.classList.add("btn","btn-secondary"),C.textContent="+Add";let g=document.createElement("tfoot"),e=document.createElement("tr"),h=document.createElement("td");h.colSpan=(n.fields?n.fields.length:0)+1,h.appendChild(C),e.appendChild(h),g.appendChild(e),m.appendChild(g),L.appendChild(m);let s=[];function o(){b.value=JSON.stringify(s)}function f(r){let a=[];return n.fields.forEach(t=>{let c=r[t.key];if(t.type==="checkbox"){let E=Array.isArray(c)?c:c?[c]:[];t.required&&E.length===0&&a.push(`${t.label||t.key} is required`);return}t.required&&(c==null||String(c).trim()==="")&&a.push(`${t.label||t.key} is required`),t.type==="email"&&c&&(/^\S+@\S+\.\S+$/.test(String(c))||a.push(`${t.label||t.key} must be a valid email`)),t.type==="number"&&c&&isNaN(Number(c))&&a.push(`${t.label||t.key} must be a number`),t.validation&&t.validation.regex&&c&&(new RegExp(t.validation.regex).test(String(c))||a.push(`${t.label||t.key} invalid format`))}),a}function l(){T.innerHTML="";let r=(a,t)=>{t.draggable=!0,t.addEventListener("mousedown",()=>{t.style.cursor="grabbing"}),t.addEventListener("mouseup",()=>{t.style.cursor="grab"}),t.addEventListener("dragstart",c=>{let E=Number(a.dataset.rowIndex);c.dataTransfer.setData("text/plain",String(E)),a.classList.add("dragging");try{c.dataTransfer?.setDragImage(t,10,10)}catch{}}),t.addEventListener("dragend",()=>{a.classList.remove("dragging"),t.style.cursor="grab"}),a.addEventListener("dragover",c=>{c.preventDefault();let E=c.currentTarget,x=E.getBoundingClientRect(),N=x.top+x.height/2,A=(c.clientY||c.y)>N;E.classList.remove("drag-over-top","drag-over-bottom"),A?(E.classList.add("drag-over-bottom"),E.dataset.dropPosition="after"):(E.classList.add("drag-over-top"),E.dataset.dropPosition="before")}),a.addEventListener("dragleave",c=>{let E=c.currentTarget;E.classList.remove("drag-over-top","drag-over-bottom"),delete E.dataset.dropPosition}),a.addEventListener("drop",c=>{c.preventDefault();let E=c.dataTransfer.getData("text/plain"),x=Number(c.currentTarget.dataset.rowIndex),N=Number(E),A=c.currentTarget.dataset.dropPosition||"before";if(isNaN(N)||isNaN(x))return;let[y]=s.splice(N,1),F=x;N<x&&(F=x-1);let M=A==="after"?F+1:F;s.splice(M,0,y),c.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete c.currentTarget.dataset.dropPosition,l(),o()})};s.forEach((a,t)=>{let c=document.createElement("tr");c.dataset.rowIndex=String(t),c.classList.add("voc-form-table-row");let E=document.createElement("td");E.className="voc-form-table-drag-handle";let x=document.createElement("span");x.className="voc-form-drag-handle-icon",x.textContent="\u2630",x.style.cursor="grab",E.appendChild(x),c.appendChild(E),r(c,x),n.fields.forEach(y=>{let F=document.createElement("td"),M,$=(y.type||"text").toLowerCase();if($==="select"){let S=document.createElement("select");if(S.className="voc-form-table-cell",p&&S.classList.add("form-control"),y.placeholder){let H=document.createElement("option");H.value="",H.textContent=y.placeholder,H.disabled=!0,(a[y.key]===void 0||a[y.key]===null||a[y.key]==="")&&(H.selected=!0),S.appendChild(H)}(y.options||[]).forEach(H=>{let B=document.createElement("option");B.value=H.value,B.textContent=H.label,S.appendChild(B)}),S.value=a[y.key]!==void 0&&a[y.key]!==null?String(a[y.key]):"",y.required&&(S.required=!0),S.addEventListener("change",H=>{s[t][y.key]=H.target.value,o()}),M=S}else if($==="checkbox"){let S=document.createElement("div");S.className="voc-form-table-checkboxes",p&&S.classList.add("form-check");let D=y.options||[];Array.isArray(s[t][y.key])||(s[t][y.key]=s[t][y.key]?[s[t][y.key]]:[]),D.forEach(H=>{let B=`voc-form-${n.key}-${y.key}-${t}-${H.value}`,R=document.createElement("div");R.className="voc-form-table-checkbox-item",p&&R.classList.add("form-check");let q=document.createElement("input");q.type="checkbox",q.className="voc-form-table-cell",p&&q.classList.add("form-check-input"),q.id=B,q.value=H.value,q.checked=Array.isArray(s[t][y.key])&&s[t][y.key].includes(H.value),q.addEventListener("change",O=>{let X=O.target.checked;Array.isArray(s[t][y.key])||(s[t][y.key]=[]),X?s[t][y.key].includes(H.value)||s[t][y.key].push(H.value):s[t][y.key]=s[t][y.key].filter(Z=>Z!==H.value),o()});let _=document.createElement("label");_.htmlFor=B,_.className="voc-form-table-checkbox-label",p&&_.classList.add("form-check-label"),_.textContent=H.label,R.appendChild(q),R.appendChild(_),S.appendChild(R)}),M=S}else if($==="radio"){let S=document.createElement("div");S.className="voc-form-table-radios",p&&S.classList.add("form-check");let D=y.options||[];s[t][y.key]===void 0&&(s[t][y.key]=""),D.forEach(H=>{let B=`voc-form-${n.key}-${y.key}-${t}-${H.value}`,R=document.createElement("div");R.className="voc-form-table-radio-item",p&&R.classList.add("form-check");let q=document.createElement("input");q.type="radio",q.className="voc-form-table-cell",p&&q.classList.add("form-check-input"),q.id=B,q.name=`voc-form-${n.key}-${y.key}-${t}`,q.value=H.value,q.checked=s[t][y.key]===H.value,q.addEventListener("change",O=>{O.target.checked&&(s[t][y.key]=O.target.value,o())});let _=document.createElement("label");_.htmlFor=B,_.className="voc-form-table-radio-label",p&&_.classList.add("form-check-label"),_.textContent=H.label,R.appendChild(q),R.appendChild(_),S.appendChild(R)}),M=S}else{let S=document.createElement("input");$==="number"?S.type="number":$==="email"?S.type="email":$==="tel"?S.type="tel":$==="url"?S.type="url":$==="date"?S.type="date":S.type="text",S.value=a[y.key]!==void 0&&a[y.key]!==null?String(a[y.key]):"",y.placeholder&&(S.placeholder=y.placeholder),y.required&&(S.required=!0),S.className="voc-form-table-cell",p&&S.classList.add("form-control"),S.addEventListener("input",D=>{s[t][y.key]=D.target.value,o()}),M=S}F.appendChild(M),c.appendChild(F)});let N=document.createElement("td"),A=document.createElement("button");A.type="button",A.className="voc-form-table-remove",p&&A.classList.add("btn","btn-danger"),A.textContent="Remove",A.addEventListener("click",()=>{s.splice(t,1),l(),o()}),N.appendChild(A),c.appendChild(N),T.appendChild(c)})}return C.addEventListener("click",()=>{if(n.validation?.max_rows!==void 0&&s.length>=n.validation.max_rows)return;let r={};n.fields.forEach(a=>r[a.key]=""),s.push(r),l(),o()}),Array.isArray(v)&&v.length?s=v.map(r=>({...r})):n.default&&Array.isArray(n.default)&&(s=n.default.map(r=>({...r}))),l(),o(),L.validate=function(){let r=[];return s.forEach((a,t)=>{let c=f(a);c.length&&r.push(`Row ${t+1}: ${c.join("; ")}`)}),n.validation?.min_rows!==void 0&&s.length<n.validation.min_rows&&r.push(`At least ${n.validation.min_rows} rows required`),n.validation?.max_rows!==void 0&&s.length>n.validation.max_rows&&r.push(`No more than ${n.validation.max_rows} rows allowed`),n.validation?.unique_fields&&n.validation.unique_fields.length&&n.validation.unique_fields.forEach(a=>{let t=new Set;s.forEach((c,E)=>{let x=c[a];x!=null&&(t.has(x)&&r.push(`Field ${a} must be unique (duplicate at row ${E+1})`),t.add(x))})}),r},L}async function oe(n){let v=new TextEncoder().encode(n),L=await crypto.subtle.digest("SHA-256",v);return Array.from(new Uint8Array(L)).map(b=>b.toString(16).padStart(2,"0")).join("")}async function ie(n){let w=String(n||"").trim().toLowerCase();return w?`https://gravatar.com/avatar/${await oe(w)}?d=mp`:""}function V(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");p.className="voc-form-users";let b=document.createElement("div");if(b.className="voc-form-users-header",L&&b.classList.add("mb-2"),n.label){let g=document.createElement("div");if(g.className="voc-form-users-label",L&&g.classList.add("form-label"),g.textContent=n.label,n.required){let e=document.createElement("span");e.className="voc-form-required",e.textContent="*",g.appendChild(e)}b.appendChild(g)}if(n.description){let g=document.createElement("div");g.className="voc-form-users-description",L&&g.classList.add("form-text"),g.textContent=n.description,b.appendChild(g)}p.appendChild(b);let m=document.createElement("div");m.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",L&&i.classList.add("form-control","mb-2"),m.appendChild(i),p.appendChild(m),!n.options||n.options.length===0)return p;let d=document.createElement("div");d.className="voc-form-users-list",L&&d.classList.add("list-group");let u=n.name||n.key||`users_${Math.random().toString(36).substr(2,6)}`,k=[];if(Array.isArray(v)?k=v:v!=null?k=[v]:Array.isArray(n.default)&&(k=n.default),n.options.forEach((g,e)=>{let h=document.createElement("div");h.className="voc-form-user-item",h.dataset.label=String(g.label||"").toLowerCase(),h.dataset.email=String(g.email||"").toLowerCase(),h.dataset.value=String(g.value||"").toLowerCase(),L&&h.classList.add("d-flex","align-items-center","gap-2");let s=document.createElement("input");if(s.type="checkbox",s.name=`${u}[]`,s.value=g.value,s.className="voc-form-user-checkbox",n.key&&(s.id=`voc-form-${n.key}-${e}`),s.style.position="absolute",s.style.width="1px",s.style.height="1px",s.style.margin="0",s.style.padding="0",s.style.clip="rect(0 0 0 0)",s.style.clipPath="inset(50%)",s.style.overflow="hidden",s.style.border="0",k&&Array.isArray(k)){let a=k.map(t=>String(t));s.checked=a.includes(String(g.value))}let o=document.createElement("img");o.className="voc-form-user-avatar",o.alt=g.label||String(g.value||"user"),o.style.width=o.style.height="40px",o.style.objectFit="cover",o.style.borderRadius="50%",o.src="",g.email&&ie(g.email).then(a=>{a&&(o.src=a)}).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 l=document.createElement("div");l.className="voc-form-user-label",l.textContent=g.label||String(g.value);let r=document.createElement("small");r.className="voc-form-user-email",r.textContent=g.email||"",f.appendChild(l),f.appendChild(r),h.addEventListener("click",a=>{let t=a.target;t&&(t.closest("input")||t.closest("a")||t.closest("button"))||(s.checked=!s.checked,s.dispatchEvent(new Event("change",{bubbles:!0})))}),s.addEventListener("change",()=>{s.checked?h.classList.add("selected"):h.classList.remove("selected")}),s.checked&&h.classList.add("selected"),h.appendChild(s),h.appendChild(o),h.appendChild(f),d.appendChild(h)}),p.appendChild(d),n.required){let g=d.querySelectorAll('input[type="checkbox"]'),e=()=>{let h=Array.from(g).some(s=>s.checked);return g.forEach(s=>{h?s.setCustomValidity(""):s.setCustomValidity("At least one option must be selected.")}),h};g.forEach(h=>{h.addEventListener("change",e)}),p._validateCheckboxGroup=e,e()}let T=Array.from(d.querySelectorAll(".voc-form-user-item")),C=()=>{let g=String(i.value||"").trim().toLowerCase();if(!g){T.forEach(e=>e.style.setProperty("display","flex","important"));return}T.forEach(e=>{let h=e.dataset.label||"",s=e.dataset.email||"",o=e.dataset.value||"",f=h.includes(g)||s.includes(g)||o.includes(g);e.style.setProperty("display",f?"flex":"none","important")})};return i.addEventListener("input",C),p}function U(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");p.className="voc-form-timezone";let b=n.name||n.key||`timezone_${Math.random().toString(36).substr(2,6)}`,m=document.createElement("input");m.type="text",m.name=b,n.key&&(m.id=`voc-form-${n.key}`),m.className="voc-form-timezone-input",L&&m.classList.add("form-control"),n.placeholder&&(m.placeholder=n.placeholder||""),n.required&&(m.required=!0),n.width&&(m.style.width=n.width);try{m.autocomplete="off"}catch{}try{m.autocorrect="off"}catch{}try{m.autocapitalize="off"}catch{}try{m.spellcheck=!1}catch{}m.setAttribute("data-lpignore","true"),v!=null?m.value=String(v):n.default!==void 0&&n.default!==null&&(m.value=String(n.default));let i=document.createElement("div");i.className="voc-form-timezone-control",i.style.position="relative",i.style.display="inline-block",i.style.width=n.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 u=document.createElement("ul");u.className="voc-form-timezone-list",u.setAttribute("role","listbox"),u.style.position="absolute",u.style.left="0",u.style.right="0",u.style.zIndex="1000",u.style.maxHeight="200px",u.style.overflow="auto",u.style.margin="4px 0 0 0",u.style.padding="0",u.style.listStyle="none",u.style.background="white",u.style.border="1px solid rgba(0,0,0,0.15)",u.style.display="none",u.tabIndex=-1,m.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 C(l){u.innerHTML="",l.forEach((r,a)=>{let t=document.createElement("li");t.className="voc-form-timezone-item",t.setAttribute("role","option"),t.dataset.value=r,t.style.padding="6px 8px",t.style.cursor="pointer",t.textContent=r,t.addEventListener("mousedown",c=>{c.preventDefault(),m.value=r,s(),m.dispatchEvent(new Event("change",{bubbles:!0}))}),u.appendChild(t)})}C(T);let g=-1;function e(){Array.from(u.children).forEach((r,a)=>{a===g?(r.style.background="rgba(0,123,255,0.1)",r.setAttribute("aria-selected","true")):(r.style.background="",r.removeAttribute("aria-selected"))})}function h(){u.style.display="block",d.setAttribute("aria-expanded","true")}function s(){u.style.display="none",d.setAttribute("aria-expanded","false"),g=-1,e()}function o(){u.style.display==="none"?h():s()}m.addEventListener("input",()=>{let l=(m.value||"").trim().toLowerCase(),r=l?T.filter(a=>a.toLowerCase().includes(l)):T;C(r),h()}),d.addEventListener("click",l=>{l.preventDefault(),u.style.display==="none"?(C(T),h(),m.focus()):s()}),m.addEventListener("keydown",l=>{let r=Array.from(u.children);if(l.key==="ArrowDown"){if(l.preventDefault(),r.length===0)return;g=Math.min(g+1,r.length-1),e(),r[g].scrollIntoView({block:"nearest"})}else if(l.key==="ArrowUp"){if(l.preventDefault(),r.length===0)return;g=Math.max(g-1,0),e(),r[g].scrollIntoView({block:"nearest"})}else if(l.key==="Enter"){if(u.style.display!=="none"&&g>=0){l.preventDefault();let a=r[g];m.value=a.dataset.value||a.textContent||"",s(),m.dispatchEvent(new Event("change",{bubbles:!0}))}}else l.key==="Escape"&&s()}),document.addEventListener("click",l=>{i.contains(l.target)||s()});let f={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(m.addEventListener("blur",()=>{let l=(m.value||"").trim();if(!l)return;let r=Object.keys(f).find(a=>a.toLowerCase()===l.toLowerCase());r&&(m.value=f[r])}),n.description){let l=document.createElement("div");l.className="voc-form-timezone-description",L&&l.classList.add("form-text"),l.textContent=n.description,p.appendChild(l)}return i.appendChild(m),i.appendChild(d),i.appendChild(u),p.appendChild(i),p}function J(n,w,v){let L=w?.style==="bootstrap",p=document.createElement("div");p.className="voc-form-tags";let b=n.name||n.key||`tags_${Math.random().toString(36).substr(2,6)}`,m=document.createElement("div");m.className="voc-form-tags-container",m.style.display="flex",m.style.flexWrap="wrap",m.style.gap="6px",m.style.alignItems="center",m.style.padding="6px",m.style.border="1px solid rgba(0,0,0,0.12)",m.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=n.placeholder||"",L&&i.classList.add("form-control"),m.appendChild(i);let d=[],u=document.createElement("input");u.type="text",u.style.position="absolute",u.style.left="-9999px",u.style.width="1px",u.style.height="1px",u.tabIndex=-1,n.required&&(u.required=!0),p.appendChild(u);function k(){Array.from(p.querySelectorAll("input.voc-form-tag-hidden")).forEach(h=>h.parentElement?.removeChild(h)),d.forEach(h=>{let s=document.createElement("input");s.type="hidden",s.name=`${b}[]`,s.className="voc-form-tag-hidden",s.value=h,n.key&&(s.id=`voc-form-${n.key}`),p.appendChild(s)}),n.required&&(d.length===0?(u.value="",u.setCustomValidity("Please enter at least one tag")):(u.value="1",u.setCustomValidity("")))}function T(e){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 s=document.createElement("span");s.textContent=e,s.style.marginRight="8px",h.appendChild(s);let o=document.createElement("button");return o.type="button",o.textContent="\xD7",o.style.border="none",o.style.background="transparent",o.style.cursor="pointer",o.addEventListener("click",()=>{let f=d.indexOf(e);f>=0&&(d.splice(f,1),m.removeChild(h),k())}),h.appendChild(o),h}function C(e){let h=e.trim();if(!h||d.includes(h))return;d.push(h);let s=T(h);m.insertBefore(s,i),k()}let g=v!=null?String(v):n.default||"";return g&&g.split(",").map(e=>e.trim()).filter(Boolean).forEach(C),i.addEventListener("keydown",e=>{if(e.key==="Enter"||e.key===",")e.preventDefault(),C(i.value),i.value="";else if(e.key==="Backspace"&&i.value===""&&d.pop()){let s=Array.from(m.querySelectorAll(".voc-form-tag")),o=s[s.length-1];o&&m.removeChild(o),k()}}),i.addEventListener("paste",e=>{let h=e.clipboardData?.getData("text");h&&(e.preventDefault(),h.split(/[,\n\r]+/).map(s=>s.trim()).filter(Boolean).forEach(C),i.value="")}),p.getTags=()=>d.slice(),p.addTag=C,p.appendChild(m),k(),p}function Y(n,w,v,L){let p=w?.style==="bootstrap",b=document.createElement("div");b.className="voc-form-field-selects";let m=document.createElement("div");if(m.className="voc-form-field-selects-header",p&&m.classList.add("mb-2"),n.label){let o=document.createElement("div");if(o.className="voc-form-field-selects-label",p&&o.classList.add("form-label"),o.textContent=n.label,n.required){let f=document.createElement("span");f.className="voc-form-required",f.textContent="*",o.appendChild(f)}m.appendChild(o)}if(n.description){let o=document.createElement("div");o.className="voc-form-field-selects-description",p&&o.classList.add("form-text"),o.textContent=n.description,m.appendChild(o)}b.appendChild(m);let i=document.createElement("div");i.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",p&&d.classList.add("form-control","mb-2"),i.appendChild(d),b.appendChild(i);let u=n.options;if(!u||u.length===0)return b;let k=document.createElement("div");k.className="voc-form-field-selects-list",p&&k.classList.add("list-group");let T=document.createElement("div");T.className="voc-form-field-selects-selected",T.style.marginTop="12px";let C={},g=n.name||n.key||`users_${Math.random().toString(36).substr(2,6)}`,e=[];if(Array.isArray(v)?e=v:v!=null?e=[v]:Array.isArray(n.default)&&(e=n.default),u.forEach((o,f)=>{let l=document.createElement("div");l.className="voc-form-field-selects-item",l.dataset.label=String(o.option_label??o.label??"").toLowerCase(),l.dataset.email=String(o.email||"").toLowerCase(),l.dataset.value=String(o.value||"").toLowerCase(),p&&l.classList.add("d-flex","align-items-center","gap-2");let r=document.createElement("input");if(r.type="checkbox",r.name=`${g}[]`,r.value=o.value??o.key,r.className="voc-form--checkbox",n.key&&(r.id=`voc-form-${n.key}-${f}`),r.style.position="absolute",r.style.width="1px",r.style.height="1px",r.style.margin="0",r.style.padding="0",r.style.clip="rect(0 0 0 0)",r.style.clipPath="inset(50%)",r.style.overflow="hidden",r.style.border="0",e&&Array.isArray(e)){let N=e.map(y=>String(y)),A=String(o.value??o.key);r.checked=N.includes(A)}let a=o.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>',t=document.createElement("div");t.className="voc-form-fields-select-avatar",t.innerHTML=a;let c=document.createElement("div");c.className="voc-form-field-select-info",c.style.display="flex",c.style.flexDirection="column",c.style.gap="2px";let E=document.createElement("div");E.className="voc-form-field-select-label",E.textContent=(o.option_label??o.label)||String(o.value);let x=document.createElement("small");x.className="voc-form-field-select-email",x.textContent=o.email||"",c.appendChild(E),c.appendChild(x),l.addEventListener("click",N=>{let A=N.target;A&&(A.closest("input")||A.closest("a")||A.closest("button"))||(r.checked=!r.checked,r.dispatchEvent(new Event("change",{bubbles:!0})))}),r.addEventListener("change",()=>{if(r.checked){l.classList.add("selected"),(C[f]||[]).forEach(y=>y.parentElement?.removeChild(y)),C[f]=[];let A=o;if(A&&Array.isArray(A.items))A.items.forEach(y=>{let F=L(y);F&&(T.appendChild(F),C[f].push(F))});else if(A&&(A.type||A.key)){let y=L(A);y&&(T.appendChild(y),C[f].push(y))}}else l.classList.remove("selected"),(C[f]||[]).forEach(A=>A.parentElement?.removeChild(A)),C[f]=[]}),r.checked&&(l.classList.add("selected"),setTimeout(()=>{let N=o;if(N&&Array.isArray(N.items))N.items.forEach(A=>{let y=L(A);y&&(T.appendChild(y),C[f]=C[f]||[],C[f].push(y))});else if(N&&(N.type||N.key)){let A=L(N);A&&(T.appendChild(A),C[f]=C[f]||[],C[f].push(A))}},0)),l.appendChild(r),l.appendChild(t),l.appendChild(c),k.appendChild(l)}),b.appendChild(k),b.appendChild(T),n.required){let o=k.querySelectorAll('input[type="checkbox"]'),f=()=>{let l=Array.from(o).some(r=>r.checked);return o.forEach(r=>{l?r.setCustomValidity(""):r.setCustomValidity("At least one option must be selected.")}),l};o.forEach(l=>{l.addEventListener("change",f)}),b._validateCheckboxGroup=f,f()}let h=Array.from(k.querySelectorAll(".voc-form-field-select-item")),s=()=>{let o=String(d.value||"").trim().toLowerCase();if(!o){h.forEach(f=>f.style.setProperty("display","flex","important"));return}h.forEach(f=>{let l=f.dataset.label||"",r=f.dataset.email||"",a=f.dataset.value||"",t=l.includes(o)||r.includes(o)||a.includes(o);f.style.setProperty("display",t?"flex":"none","important")})};return d.addEventListener("input",s),b}function I(n,w=!0){let v=new FormData(n);if(w)return ce(v);let L={};return v.forEach((p,b)=>{let m=(p instanceof File,p);Object.prototype.hasOwnProperty.call(L,b)?Array.isArray(L[b])?L[b].push(m):L[b]=[L[b],m]:L[b]=m}),L}function ce(n){let w=new FormData;for(let[v,L]of n.entries()){if(L instanceof File){w.append(v,L);continue}let p;try{p=JSON.parse(L)}catch{p=null}Array.isArray(p)?p.length===0?w.append(v,"[]"):p.every(b=>typeof b=="object"&&b!==null)?p.forEach((b,m)=>{for(let[i,d]of Object.entries(b))w.append(`${v}[${m}][${i}]`,d)}):w.append(v,L):w.append(v,L)}return w}async function K(n,w,v){let L=w.url,p={"Content-Type":"application/json"};w?.api_token&&(p.Authorization=`Bearer ${w.api_token}`);let b=I(n);if(w?.additional_data)for(let[d,u]of Object.entries(w.additional_data))b.append(d,u);let m,i=b instanceof FormData;m={method:"POST",headers:{Authorization:`Bearer ${w.api_token}`,...i?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:i?b:JSON.stringify(Object.fromEntries(b.entries()))};try{fetch(L,m).then(async d=>{let u=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(k){throw new Error(k.message)}return u&&u.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(n,w,v){let L=[];if(typeof n=="string"?L=Array.from(document.querySelectorAll(n)):L=[n],L.length===0)return null;function p(){let i=v?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),i&&d.classList.add("needs-validation"),d.id=w.id;let u=document.createElement("h2");u.className="voc-form-title",i&&u.classList.add("mb-3"),u.textContent=w.form_name,d.appendChild(u);function k(e,h){h&&(h.min_length!==void 0&&(e.minLength=h.min_length),h.max_length!==void 0&&(e.maxLength=h.max_length),h.regex&&(e instanceof HTMLInputElement?e.pattern=h.regex:e.dataset.pattern=h.regex))}function T(e){if(!e.key&&!e.label)return null;let h=w.default_values||{},s=e.name||e.key,o=s?h[s]:void 0,f=document.createElement("div");if(f.className="voc-form-group",i&&f.classList.add("mb-3"),e.label&&e.type!=="users"){let a=document.createElement("label");if(a.classList.add("voc-form-label"),i&&a.classList.add("form-label"),e.key?e.type==="radio"?a.htmlFor="":a.htmlFor=`voc-form-${e.key}`:a.htmlFor="",a.textContent=e.label,e.required){let t=document.createElement("span");t.className="voc-form-required",t.textContent="*",a.appendChild(t)}f.appendChild(a)}let l=new Set(["users","timezone"]);if(e.description&&!l.has(String(e.type||""))){let a=document.createElement("div");a.className="voc-form-description",i&&a.classList.add("form-text","text-muted","mb-2"),a.textContent=e.description,f.appendChild(a)}let r=null;switch(e.type){case"tags":{r=J(e,v||{},o);break}case"checkbox":{let a=document.createElement("div");if(a.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(a.style.width=e.width),e.options){if(e.options.forEach((t,c)=>{let E=document.createElement("label");E.classList.add("voc-form-checkbox-label"),i&&E.classList.add("form-check"),E.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(E.style.width=e.width);let x=document.createElement("input");x.type="checkbox",x.classList.add("voc-form-checkbox"),i&&x.classList.add("form-check-input"),x.name=`${e.name||e.key||""}[]`,x.value=t.value,e.key&&(x.id=`voc-form-${e.key}-${c}`),Array.isArray(o)?o.includes(t.value)&&(x.checked=!0):o!==void 0?o===t.value&&(x.checked=!0):e.default===t.value&&(x.checked=!0),E.appendChild(x),E.appendChild(document.createTextNode(t.label)),a.appendChild(E)}),e.required){let t=a.querySelectorAll('input[type="checkbox"]'),c=()=>{let E=Array.from(t).some(x=>x.checked);return t.forEach(x=>{E?x.setCustomValidity(""):x.setCustomValidity("At least one option must be selected.")}),E};t.forEach(E=>{E.addEventListener("change",c)}),a._validateCheckboxGroup=c,c()}}else{let t=document.createElement("label");t.classList.add("voc-form-checkbox-label"),i&&t.classList.add("form-check"),e.width&&(t.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),(e.key||e.name)&&(c.name=e.name||e.key,e.key&&(c.id=`voc-form-${e.key}`)),i&&c.classList.add("form-check-input"),e.required&&(c.required=!0),o!==void 0?c.checked=!!o:e.default&&(c.checked=!!e.default),t.appendChild(c),t.appendChild(document.createTextNode(e.label||"")),a.appendChild(t)}r=a;break}case"boolean":{let a=document.createElement("div");a.className="voc-form-boolean-wrapper",i&&a.classList.add("form-check"),e.width&&(a.style.width=e.width);let t=document.createElement("input");if(t.type="checkbox",t.classList.add("voc-form-boolean"),i&&t.classList.add("form-check-input"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.required&&(t.required=!0),o!==void 0?t.checked=!!o:e.default!==void 0&&(t.checked=e.default===!0||e.default==="true"),a.appendChild(t),e.label){let E=document.createElement("label");if(E.classList.add("voc-form-boolean-label"),i&&E.classList.add("form-check-label"),e.key&&(E.htmlFor=`voc-form-${e.key}`),E.textContent=e.label,e.required){let x=document.createElement("span");x.className="voc-form-required",x.textContent="*",E.appendChild(x)}a.appendChild(E)}let c=f.querySelector(".voc-form-label");c&&c.remove(),r=a;break}case"textarea":{let a=document.createElement("textarea");a.classList.add("voc-form-textarea"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder&&(a.placeholder=e.placeholder),o!=null?a.value=String(o):e.default!==void 0&&e.default!==null&&(a.value=String(e.default));let t=e.default||o||"";if(t){let c=(t.match(/\n/g)||[]).length,E=80,x=t.split(`
2
+ `).reduce((y,F)=>Math.max(y,F.length),0),N=Math.ceil(x/E)||1,A=Math.max(2,c+N);a.rows=A,a.style.resize="vertical"}e.width&&(a.style.width=e.width),e.required&&(a.required=!0),k(a,e.validation),r=a;break}case"select":{let a=document.createElement("select");if(a.classList.add("voc-form-select"),i&&a.classList.add("form-select"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder){let t=document.createElement("option");t.value="",t.textContent=e.placeholder,t.disabled=!0,t.selected=!0,a.appendChild(t)}e.required&&(a.required=!0),e.options&&e.options.forEach(t=>{let c=document.createElement("option");c.value=t.value,c.textContent=t.label,Array.isArray(o)?o.includes(t.value)&&(c.selected=!0):o!==void 0?o===t.value&&(c.selected=!0):e.default===t.value&&(c.selected=!0),a.appendChild(c)}),e.width&&(a.style.width=e.width),r=a;break}case"radio":{let a=document.createElement("div");a.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(a.style.width=e.width),e.options&&e.options.forEach((t,c)=>{let E=document.createElement("label");E.classList.add("voc-form-radio-label"),i&&E.classList.add("form-check"),E.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(E.style.width=e.width);let x=document.createElement("input");x.type="radio",x.classList.add("voc-form-radio"),i&&x.classList.add("form-check-input"),x.name=e.name||e.key||"",x.value=t.value,e.key&&(x.id=`voc-form-${e.key}-${c}`),Array.isArray(o)?o.includes(t.value)&&(x.checked=!0):o!==void 0?o===t.value&&(x.checked=!0):e.default===t.value&&(x.checked=!0),E.appendChild(x),E.appendChild(document.createTextNode(t.label)),a.appendChild(E)}),r=a;break}case"file":{let a=document.createElement("div");a.className="voc-form-file-wrapper",e.width&&(a.style.width=e.width);let t=document.createElement("input");t.type="file",t.classList.add("voc-form-file"),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.width&&(t.style.width=e.width),e.required&&(t.required=!0),e.accept&&(t.accept=e.accept),e.multiple&&(t.multiple=!0),a.appendChild(t),r=a;break}case"avatar":{r=j(e,v||{},o);break}case"table":{r=G(e,v||{},o);break}case"users":{r=V(e,v||{},o);break}case"timezone":{r=U(e,v||{},o);break}case"audio_select":{r=W(e,v||{},o);break}case"field-select":{r=Y(e,v||{},o,T);break}default:{let a=document.createElement("input");a.type=e.type||"text",a.classList.add("voc-form-input"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder&&(a.placeholder=e.placeholder),o!=null?a.value=String(o):e.default!==void 0&&e.default!==null&&(a.value=String(e.default)),e.width&&(a.style.width=e.width),e.required&&(a.required=!0),k(a,e.validation),r=a;break}}if(r&&f.appendChild(r),e.hint_text){let a=document.createElement("small");a.className="voc-form-hint",a.textContent=e.hint_text,f.appendChild(a)}return f}function C(e,h,s=0){if(e.type==="group"&&"items"in e){let f=e;if(i){let l=document.createElement("div");l.className="card voc-form-group-card mb-3",s>0&&l.classList.add("voc-form-nested-group");let r=f.label||f.header?.title,a=f.description||f.header?.description;if(r||a){let c=document.createElement("div");if(c.className="card-header voc-form-group-head",r){let E=document.createElement("h5");E.className="mb-0 voc-form-group-label",E.textContent=r,c.appendChild(E)}if(a){let E=document.createElement("p");E.className="mb-0 voc-form-group-description",E.textContent=a,c.appendChild(E)}l.appendChild(c)}let t=document.createElement("div");t.className="card-body voc-form-group-body",f.items.forEach(c=>{C(c,t,s+1)}),l.appendChild(t),h.appendChild(l)}else{let l=document.createElement("div");l.className="voc-form-group voc-form-group-wrapper",s>0&&l.classList.add("voc-form-nested-group");let r=f.label||f.header?.title,a=f.description||f.header?.description;if(r||a){let t=document.createElement("div");if(t.className="voc-form-group-head",r){let c=document.createElement("h3");c.className="voc-form-group-label",c.textContent=r,t.appendChild(c)}if(a){let c=document.createElement("p");c.className="voc-form-group-description",c.textContent=a,t.appendChild(c)}l.appendChild(t)}f.items.forEach(t=>{C(t,l,s+1)}),h.appendChild(l)}return}if(e.type==="row"&&"items"in e){let f=e,l=document.createElement("div");if(l.className="voc-form-group voc-form-row",i&&l.classList.add("mb-3"),f.label){let a=document.createElement(s>0?"h6":"h3");a.className="voc-form-row-label",a.textContent=f.label,l.appendChild(a)}if(f.description){let a=document.createElement("p");a.className="voc-form-row-description",a.textContent=f.description,l.appendChild(a)}let r=document.createElement("div");r.className="voc-form-row-items "+(f.direction||"horizontal"),f.items.forEach(a=>{let t=T(a);t&&r.appendChild(t)}),l.appendChild(r),h.appendChild(l);return}let o=T(e);o&&h.appendChild(o)}w.fields.forEach(e=>{C(e,d,0)});let g=document.createElement("button");return g.type="submit",g.className="voc-form-submit",g.textContent="Submit",i&&g.classList.add("btn","btn-primary"),d.appendChild(g),d}let b=p();L[0].appendChild(b);let m=w?.submit_config??v?.submit_config??null;return m&&b.addEventListener("submit",i=>{i.preventDefault();let d=Array.from(b.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),u=[];if(d.forEach(C=>{C&&typeof C._validateCheckboxGroup=="function"&&(C._validateCheckboxGroup()||C.querySelector('input[type="checkbox"]')&&u.push("Please select at least one option"))}),!b.checkValidity()){b.reportValidity(),v?.onSubmitResult&&v.onSubmitResult(null,new Error("Form validation failed"));return}let k=Array.from(b.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),T=[];if(k.forEach(C=>{if(C&&typeof C.validate=="function"){let g=C.validate();g&&g.length&&T.push(...g)}}),T.length){v?.onSubmitResult&&v.onSubmitResult(null,new Error(T.join("; ")));let C=k[0];C&&C.scrollIntoView({behavior:"smooth",block:"center"});return}if(v?.onSubmit){let C=I(b);v.onSubmit(C)}K(b,m,(C,g)=>{v?.onSubmitResult&&v.onSubmitResult(C,g)})}),{element:b,validate:()=>{let i=[];return b.querySelectorAll(":invalid").forEach(u=>{let k=u.validationMessage;i.push({element:u,message:k})}),i},getValues:()=>I(b),onSubmit:i=>{b.addEventListener("submit",d=>{d.preventDefault();let u=I(b);i(u,d)})}}}var z={renderForm:Q};var le=z,de={FormsLib:z};0&&(module.exports={FormsLib});
package/dist/main.mjs CHANGED
@@ -1,2 +1,2 @@
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};
1
+ function z(n,w,g){let x=w?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-avatar-wrapper",x&&f.classList.add("d-flex","align-items-center","gap-3");let v=document.createElement("img");v.className="voc-form-avatar-preview",v.alt=n.label||"avatar",x&&(v.classList.add("img-thumbnail","rounded-circle"),v.style.width=v.style.height="64px",v.style.objectFit="cover");let m=g!=null?String(g):n.default!==void 0&&n.default!==null?String(n.default):"";m?v.src=m:(v.src="",v.style.display="none");let i=document.createElement("input");i.type="file",i.accept=n.accept||"image/*",i.className="voc-form-avatar-input",x&&i.classList.add("form-control"),(n.key||n.name)&&(i.name=n.name||n.key,n.key&&(i.id=`voc-form-${n.key}`));let d=document.createElement("input");if(d.type="hidden",(n.key||n.name)&&(d.name=(n.name||n.key)+"_url"),d.value=m||"",i.addEventListener("change",u=>{let k=u.target;if(k.files&&k.files.length>0){let T=k.files[0],C=new FileReader;C.onload=()=>{v.src=String(C.result),v.style.display="",d.value=""},C.readAsDataURL(T)}}),x){let u=document.createElement("div");u.style.flex="1",u.appendChild(i),u.appendChild(d),f.appendChild(v),f.appendChild(u)}else f.appendChild(v),f.appendChild(i),f.appendChild(d);return f}function j(n,w,g){let x=w?.style==="bootstrap",f=document.createElement("div");if(f.className="voc-form-audio-select",!n.options||n.options.length===0)return f;let v=n.name||n.key||`audio_select_${Math.random().toString(36).substr(2,6)}`,m;return Array.isArray(g)?m=g[0]:g!==void 0?m=g:n.default!==void 0&&(m=n.default),n.options.forEach((i,d)=>{let u=document.createElement("div");u.className="voc-form-audio-item",x&&u.classList.add("form-check");let k=document.createElement("input");k.type="radio",k.name=v,k.value=i.value,k.className="voc-form-audio-radio",n.key&&(k.id=`voc-form-${n.key}-${d}`),n.required&&d===0&&(k.required=!0),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",m!==void 0&&(Array.isArray(m)?k.checked=m.includes(i.value):k.checked=String(m)===String(i.value));let T=()=>{k.checked?u.classList.add("selected"):u.classList.remove("selected")};k.addEventListener("change",()=>{f.querySelectorAll(".voc-form-audio-item").forEach(r=>r.classList.remove("selected")),T()}),k.checked&&u.classList.add("selected");let C=document.createElement("label");C.className="voc-form-audio-label",x&&C.classList.add("form-check-label"),C.htmlFor=k.id||"",C.textContent=i.label||i.value,C.tabIndex=0;let b=document.createElement("div");b.className="voc-form-audio-control";let e=null;if(i.audio_link){let l=document.createElement("button");l.type="button",l.className="voc-form-audio-play",x&&l.classList.add("btn","btn-sm","btn-outline-secondary"),l.setAttribute("aria-label",`Play ${i.label||i.value}`);let r="http://www.w3.org/2000/svg",a=document.createElementNS(r,"svg");a.setAttribute("viewBox","0 0 24 24"),a.setAttribute("width","16"),a.setAttribute("height","16"),a.setAttribute("aria-hidden","true");let t=document.createElementNS(r,"path");t.setAttribute("d","M8 5v14l11-7z"),t.setAttribute("fill","currentColor"),a.appendChild(t),l.appendChild(a),e=document.createElement("audio"),e.src=i.audio_link,e.preload="none",e.style.display="none";let c=y=>{for(;y.firstChild;)y.removeChild(y.firstChild)},E=()=>{let y="http://www.w3.org/2000/svg",F=document.createElementNS(y,"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(y,"path");return M.setAttribute("d","M8 5v14l11-7z"),M.setAttribute("fill","currentColor"),F.appendChild(M),F},L=()=>{let y="http://www.w3.org/2000/svg",F=document.createElementNS(y,"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(y,"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};c(l),l.appendChild(E());let N=y=>{c(l),y?(l.appendChild(L()),l.setAttribute("aria-label",`Stop ${i.label||i.value}`)):(l.appendChild(E()),l.setAttribute("aria-label",`Play ${i.label||i.value}`))};l.addEventListener("click",()=>{try{if(!e)return;let y=f.querySelectorAll("audio");if(!e.paused&&!e.ended){e.pause(),e.currentTime=0;return}y.forEach(M=>{try{M.pause(),M.currentTime=0}catch{}}),f.querySelectorAll(".voc-form-audio-item").forEach(M=>M.classList.remove("is-playing")),e.play()}catch(y){console.warn("audio play failed",y)}}),e.addEventListener("playing",()=>{u.classList.add("is-playing"),N(!0)});let A=()=>{u.classList.remove("is-playing"),N(!1)};e.addEventListener("pause",A),e.addEventListener("ended",A),b.appendChild(l),b.appendChild(e)}let p=document.createElement("div");p.className="voc-form-item-detail",p.style.display="flex",p.style.flexDirection="column",p.style.gap="4px";let s=document.createElement("div");s.className="voc-form-item-top",s.style.display="flex",s.style.alignItems="center",s.style.gap="8px",s.appendChild(k),s.appendChild(C);let o=document.createElement("div");o.className="voc-form-item-description";let h=i.description||i.hint_text||"";h&&(o.textContent=h),p.appendChild(s),p.appendChild(o),b.appendChild(p),u.appendChild(b),s.addEventListener("click",l=>{let r=l.target;r&&r.closest(".voc-form-audio-play")||(k.checked=!0,k.dispatchEvent(new Event("change",{bubbles:!0})))}),u.addEventListener("click",l=>{let r=l.target;r&&r.closest(".voc-form-audio-play")||(k.checked=!0,k.dispatchEvent(new Event("change",{bubbles:!0})))}),f.appendChild(u)}),f}function W(n,w,g){let x=document.createElement("div");x.className="voc-form-table-wrapper";let f=w?.style==="bootstrap",v=document.createElement("input");v.type="hidden",v.name=n.name||n.key,n.key&&(v.id=`voc-form-${n.key}`),x.appendChild(v);let m=document.createElement("table");m.className="voc-form-table",f&&m.classList.add("table","table-bordered");let i=document.createElement("thead"),d=document.createElement("tr"),u=document.createElement("th");u.className="voc-form-table-drag-col",u.textContent="",d.appendChild(u),(n.fields||[]).forEach(r=>{let a=document.createElement("th");a.textContent=r.label||r.key,d.appendChild(a)});let k=document.createElement("th");k.textContent="Actions",d.appendChild(k),i.appendChild(d),m.appendChild(i);let T=document.createElement("tbody");m.appendChild(T),x.appendChild(m);let C=document.createElement("button");C.type="button",C.className="voc-form-table-add",f&&C.classList.add("btn","btn-secondary"),C.textContent="+Add";let b=document.createElement("tfoot"),e=document.createElement("tr"),p=document.createElement("td");p.colSpan=(n.fields?n.fields.length:0)+1,p.appendChild(C),e.appendChild(p),b.appendChild(e),m.appendChild(b),x.appendChild(m);let s=[];function o(){v.value=JSON.stringify(s)}function h(r){let a=[];return n.fields.forEach(t=>{let c=r[t.key];if(t.type==="checkbox"){let E=Array.isArray(c)?c:c?[c]:[];t.required&&E.length===0&&a.push(`${t.label||t.key} is required`);return}t.required&&(c==null||String(c).trim()==="")&&a.push(`${t.label||t.key} is required`),t.type==="email"&&c&&(/^\S+@\S+\.\S+$/.test(String(c))||a.push(`${t.label||t.key} must be a valid email`)),t.type==="number"&&c&&isNaN(Number(c))&&a.push(`${t.label||t.key} must be a number`),t.validation&&t.validation.regex&&c&&(new RegExp(t.validation.regex).test(String(c))||a.push(`${t.label||t.key} invalid format`))}),a}function l(){T.innerHTML="";let r=(a,t)=>{t.draggable=!0,t.addEventListener("mousedown",()=>{t.style.cursor="grabbing"}),t.addEventListener("mouseup",()=>{t.style.cursor="grab"}),t.addEventListener("dragstart",c=>{let E=Number(a.dataset.rowIndex);c.dataTransfer.setData("text/plain",String(E)),a.classList.add("dragging");try{c.dataTransfer?.setDragImage(t,10,10)}catch{}}),t.addEventListener("dragend",()=>{a.classList.remove("dragging"),t.style.cursor="grab"}),a.addEventListener("dragover",c=>{c.preventDefault();let E=c.currentTarget,L=E.getBoundingClientRect(),N=L.top+L.height/2,A=(c.clientY||c.y)>N;E.classList.remove("drag-over-top","drag-over-bottom"),A?(E.classList.add("drag-over-bottom"),E.dataset.dropPosition="after"):(E.classList.add("drag-over-top"),E.dataset.dropPosition="before")}),a.addEventListener("dragleave",c=>{let E=c.currentTarget;E.classList.remove("drag-over-top","drag-over-bottom"),delete E.dataset.dropPosition}),a.addEventListener("drop",c=>{c.preventDefault();let E=c.dataTransfer.getData("text/plain"),L=Number(c.currentTarget.dataset.rowIndex),N=Number(E),A=c.currentTarget.dataset.dropPosition||"before";if(isNaN(N)||isNaN(L))return;let[y]=s.splice(N,1),F=L;N<L&&(F=L-1);let M=A==="after"?F+1:F;s.splice(M,0,y),c.currentTarget.classList.remove("drag-over-top","drag-over-bottom"),delete c.currentTarget.dataset.dropPosition,l(),o()})};s.forEach((a,t)=>{let c=document.createElement("tr");c.dataset.rowIndex=String(t),c.classList.add("voc-form-table-row");let E=document.createElement("td");E.className="voc-form-table-drag-handle";let L=document.createElement("span");L.className="voc-form-drag-handle-icon",L.textContent="\u2630",L.style.cursor="grab",E.appendChild(L),c.appendChild(E),r(c,L),n.fields.forEach(y=>{let F=document.createElement("td"),M,$=(y.type||"text").toLowerCase();if($==="select"){let S=document.createElement("select");if(S.className="voc-form-table-cell",f&&S.classList.add("form-control"),y.placeholder){let H=document.createElement("option");H.value="",H.textContent=y.placeholder,H.disabled=!0,(a[y.key]===void 0||a[y.key]===null||a[y.key]==="")&&(H.selected=!0),S.appendChild(H)}(y.options||[]).forEach(H=>{let B=document.createElement("option");B.value=H.value,B.textContent=H.label,S.appendChild(B)}),S.value=a[y.key]!==void 0&&a[y.key]!==null?String(a[y.key]):"",y.required&&(S.required=!0),S.addEventListener("change",H=>{s[t][y.key]=H.target.value,o()}),M=S}else if($==="checkbox"){let S=document.createElement("div");S.className="voc-form-table-checkboxes",f&&S.classList.add("form-check");let D=y.options||[];Array.isArray(s[t][y.key])||(s[t][y.key]=s[t][y.key]?[s[t][y.key]]:[]),D.forEach(H=>{let B=`voc-form-${n.key}-${y.key}-${t}-${H.value}`,R=document.createElement("div");R.className="voc-form-table-checkbox-item",f&&R.classList.add("form-check");let q=document.createElement("input");q.type="checkbox",q.className="voc-form-table-cell",f&&q.classList.add("form-check-input"),q.id=B,q.value=H.value,q.checked=Array.isArray(s[t][y.key])&&s[t][y.key].includes(H.value),q.addEventListener("change",O=>{let Q=O.target.checked;Array.isArray(s[t][y.key])||(s[t][y.key]=[]),Q?s[t][y.key].includes(H.value)||s[t][y.key].push(H.value):s[t][y.key]=s[t][y.key].filter(X=>X!==H.value),o()});let _=document.createElement("label");_.htmlFor=B,_.className="voc-form-table-checkbox-label",f&&_.classList.add("form-check-label"),_.textContent=H.label,R.appendChild(q),R.appendChild(_),S.appendChild(R)}),M=S}else if($==="radio"){let S=document.createElement("div");S.className="voc-form-table-radios",f&&S.classList.add("form-check");let D=y.options||[];s[t][y.key]===void 0&&(s[t][y.key]=""),D.forEach(H=>{let B=`voc-form-${n.key}-${y.key}-${t}-${H.value}`,R=document.createElement("div");R.className="voc-form-table-radio-item",f&&R.classList.add("form-check");let q=document.createElement("input");q.type="radio",q.className="voc-form-table-cell",f&&q.classList.add("form-check-input"),q.id=B,q.name=`voc-form-${n.key}-${y.key}-${t}`,q.value=H.value,q.checked=s[t][y.key]===H.value,q.addEventListener("change",O=>{O.target.checked&&(s[t][y.key]=O.target.value,o())});let _=document.createElement("label");_.htmlFor=B,_.className="voc-form-table-radio-label",f&&_.classList.add("form-check-label"),_.textContent=H.label,R.appendChild(q),R.appendChild(_),S.appendChild(R)}),M=S}else{let S=document.createElement("input");$==="number"?S.type="number":$==="email"?S.type="email":$==="tel"?S.type="tel":$==="url"?S.type="url":$==="date"?S.type="date":S.type="text",S.value=a[y.key]!==void 0&&a[y.key]!==null?String(a[y.key]):"",y.placeholder&&(S.placeholder=y.placeholder),y.required&&(S.required=!0),S.className="voc-form-table-cell",f&&S.classList.add("form-control"),S.addEventListener("input",D=>{s[t][y.key]=D.target.value,o()}),M=S}F.appendChild(M),c.appendChild(F)});let N=document.createElement("td"),A=document.createElement("button");A.type="button",A.className="voc-form-table-remove",f&&A.classList.add("btn","btn-danger"),A.textContent="Remove",A.addEventListener("click",()=>{s.splice(t,1),l(),o()}),N.appendChild(A),c.appendChild(N),T.appendChild(c)})}return C.addEventListener("click",()=>{if(n.validation?.max_rows!==void 0&&s.length>=n.validation.max_rows)return;let r={};n.fields.forEach(a=>r[a.key]=""),s.push(r),l(),o()}),Array.isArray(g)&&g.length?s=g.map(r=>({...r})):n.default&&Array.isArray(n.default)&&(s=n.default.map(r=>({...r}))),l(),o(),x.validate=function(){let r=[];return s.forEach((a,t)=>{let c=h(a);c.length&&r.push(`Row ${t+1}: ${c.join("; ")}`)}),n.validation?.min_rows!==void 0&&s.length<n.validation.min_rows&&r.push(`At least ${n.validation.min_rows} rows required`),n.validation?.max_rows!==void 0&&s.length>n.validation.max_rows&&r.push(`No more than ${n.validation.max_rows} rows allowed`),n.validation?.unique_fields&&n.validation.unique_fields.length&&n.validation.unique_fields.forEach(a=>{let t=new Set;s.forEach((c,E)=>{let L=c[a];L!=null&&(t.has(L)&&r.push(`Field ${a} must be unique (duplicate at row ${E+1})`),t.add(L))})}),r},x}async function Z(n){let g=new TextEncoder().encode(n),x=await crypto.subtle.digest("SHA-256",g);return Array.from(new Uint8Array(x)).map(v=>v.toString(16).padStart(2,"0")).join("")}async function ee(n){let w=String(n||"").trim().toLowerCase();return w?`https://gravatar.com/avatar/${await Z(w)}?d=mp`:""}function G(n,w,g){let x=w?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-users";let v=document.createElement("div");if(v.className="voc-form-users-header",x&&v.classList.add("mb-2"),n.label){let b=document.createElement("div");if(b.className="voc-form-users-label",x&&b.classList.add("form-label"),b.textContent=n.label,n.required){let e=document.createElement("span");e.className="voc-form-required",e.textContent="*",b.appendChild(e)}v.appendChild(b)}if(n.description){let b=document.createElement("div");b.className="voc-form-users-description",x&&b.classList.add("form-text"),b.textContent=n.description,v.appendChild(b)}f.appendChild(v);let m=document.createElement("div");m.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",x&&i.classList.add("form-control","mb-2"),m.appendChild(i),f.appendChild(m),!n.options||n.options.length===0)return f;let d=document.createElement("div");d.className="voc-form-users-list",x&&d.classList.add("list-group");let u=n.name||n.key||`users_${Math.random().toString(36).substr(2,6)}`,k=[];if(Array.isArray(g)?k=g:g!=null?k=[g]:Array.isArray(n.default)&&(k=n.default),n.options.forEach((b,e)=>{let p=document.createElement("div");p.className="voc-form-user-item",p.dataset.label=String(b.label||"").toLowerCase(),p.dataset.email=String(b.email||"").toLowerCase(),p.dataset.value=String(b.value||"").toLowerCase(),x&&p.classList.add("d-flex","align-items-center","gap-2");let s=document.createElement("input");if(s.type="checkbox",s.name=`${u}[]`,s.value=b.value,s.className="voc-form-user-checkbox",n.key&&(s.id=`voc-form-${n.key}-${e}`),s.style.position="absolute",s.style.width="1px",s.style.height="1px",s.style.margin="0",s.style.padding="0",s.style.clip="rect(0 0 0 0)",s.style.clipPath="inset(50%)",s.style.overflow="hidden",s.style.border="0",k&&Array.isArray(k)){let a=k.map(t=>String(t));s.checked=a.includes(String(b.value))}let o=document.createElement("img");o.className="voc-form-user-avatar",o.alt=b.label||String(b.value||"user"),o.style.width=o.style.height="40px",o.style.objectFit="cover",o.style.borderRadius="50%",o.src="",b.email&&ee(b.email).then(a=>{a&&(o.src=a)}).catch(()=>{});let h=document.createElement("div");h.className="voc-form-user-info",h.style.display="flex",h.style.flexDirection="column",h.style.gap="2px";let l=document.createElement("div");l.className="voc-form-user-label",l.textContent=b.label||String(b.value);let r=document.createElement("small");r.className="voc-form-user-email",r.textContent=b.email||"",h.appendChild(l),h.appendChild(r),p.addEventListener("click",a=>{let t=a.target;t&&(t.closest("input")||t.closest("a")||t.closest("button"))||(s.checked=!s.checked,s.dispatchEvent(new Event("change",{bubbles:!0})))}),s.addEventListener("change",()=>{s.checked?p.classList.add("selected"):p.classList.remove("selected")}),s.checked&&p.classList.add("selected"),p.appendChild(s),p.appendChild(o),p.appendChild(h),d.appendChild(p)}),f.appendChild(d),n.required){let b=d.querySelectorAll('input[type="checkbox"]'),e=()=>{let p=Array.from(b).some(s=>s.checked);return b.forEach(s=>{p?s.setCustomValidity(""):s.setCustomValidity("At least one option must be selected.")}),p};b.forEach(p=>{p.addEventListener("change",e)}),f._validateCheckboxGroup=e,e()}let T=Array.from(d.querySelectorAll(".voc-form-user-item")),C=()=>{let b=String(i.value||"").trim().toLowerCase();if(!b){T.forEach(e=>e.style.setProperty("display","flex","important"));return}T.forEach(e=>{let p=e.dataset.label||"",s=e.dataset.email||"",o=e.dataset.value||"",h=p.includes(b)||s.includes(b)||o.includes(b);e.style.setProperty("display",h?"flex":"none","important")})};return i.addEventListener("input",C),f}function V(n,w,g){let x=w?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-timezone";let v=n.name||n.key||`timezone_${Math.random().toString(36).substr(2,6)}`,m=document.createElement("input");m.type="text",m.name=v,n.key&&(m.id=`voc-form-${n.key}`),m.className="voc-form-timezone-input",x&&m.classList.add("form-control"),n.placeholder&&(m.placeholder=n.placeholder||""),n.required&&(m.required=!0),n.width&&(m.style.width=n.width);try{m.autocomplete="off"}catch{}try{m.autocorrect="off"}catch{}try{m.autocapitalize="off"}catch{}try{m.spellcheck=!1}catch{}m.setAttribute("data-lpignore","true"),g!=null?m.value=String(g):n.default!==void 0&&n.default!==null&&(m.value=String(n.default));let i=document.createElement("div");i.className="voc-form-timezone-control",i.style.position="relative",i.style.display="inline-block",i.style.width=n.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 u=document.createElement("ul");u.className="voc-form-timezone-list",u.setAttribute("role","listbox"),u.style.position="absolute",u.style.left="0",u.style.right="0",u.style.zIndex="1000",u.style.maxHeight="200px",u.style.overflow="auto",u.style.margin="4px 0 0 0",u.style.padding="0",u.style.listStyle="none",u.style.background="white",u.style.border="1px solid rgba(0,0,0,0.15)",u.style.display="none",u.tabIndex=-1,m.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 C(l){u.innerHTML="",l.forEach((r,a)=>{let t=document.createElement("li");t.className="voc-form-timezone-item",t.setAttribute("role","option"),t.dataset.value=r,t.style.padding="6px 8px",t.style.cursor="pointer",t.textContent=r,t.addEventListener("mousedown",c=>{c.preventDefault(),m.value=r,s(),m.dispatchEvent(new Event("change",{bubbles:!0}))}),u.appendChild(t)})}C(T);let b=-1;function e(){Array.from(u.children).forEach((r,a)=>{a===b?(r.style.background="rgba(0,123,255,0.1)",r.setAttribute("aria-selected","true")):(r.style.background="",r.removeAttribute("aria-selected"))})}function p(){u.style.display="block",d.setAttribute("aria-expanded","true")}function s(){u.style.display="none",d.setAttribute("aria-expanded","false"),b=-1,e()}function o(){u.style.display==="none"?p():s()}m.addEventListener("input",()=>{let l=(m.value||"").trim().toLowerCase(),r=l?T.filter(a=>a.toLowerCase().includes(l)):T;C(r),p()}),d.addEventListener("click",l=>{l.preventDefault(),u.style.display==="none"?(C(T),p(),m.focus()):s()}),m.addEventListener("keydown",l=>{let r=Array.from(u.children);if(l.key==="ArrowDown"){if(l.preventDefault(),r.length===0)return;b=Math.min(b+1,r.length-1),e(),r[b].scrollIntoView({block:"nearest"})}else if(l.key==="ArrowUp"){if(l.preventDefault(),r.length===0)return;b=Math.max(b-1,0),e(),r[b].scrollIntoView({block:"nearest"})}else if(l.key==="Enter"){if(u.style.display!=="none"&&b>=0){l.preventDefault();let a=r[b];m.value=a.dataset.value||a.textContent||"",s(),m.dispatchEvent(new Event("change",{bubbles:!0}))}}else l.key==="Escape"&&s()}),document.addEventListener("click",l=>{i.contains(l.target)||s()});let h={"Australia/ACT":"Australia/Sydney",ACT:"Australia/Sydney",Canberra:"Australia/Sydney"};if(m.addEventListener("blur",()=>{let l=(m.value||"").trim();if(!l)return;let r=Object.keys(h).find(a=>a.toLowerCase()===l.toLowerCase());r&&(m.value=h[r])}),n.description){let l=document.createElement("div");l.className="voc-form-timezone-description",x&&l.classList.add("form-text"),l.textContent=n.description,f.appendChild(l)}return i.appendChild(m),i.appendChild(d),i.appendChild(u),f.appendChild(i),f}function U(n,w,g){let x=w?.style==="bootstrap",f=document.createElement("div");f.className="voc-form-tags";let v=n.name||n.key||`tags_${Math.random().toString(36).substr(2,6)}`,m=document.createElement("div");m.className="voc-form-tags-container",m.style.display="flex",m.style.flexWrap="wrap",m.style.gap="6px",m.style.alignItems="center",m.style.padding="6px",m.style.border="1px solid rgba(0,0,0,0.12)",m.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=n.placeholder||"",x&&i.classList.add("form-control"),m.appendChild(i);let d=[],u=document.createElement("input");u.type="text",u.style.position="absolute",u.style.left="-9999px",u.style.width="1px",u.style.height="1px",u.tabIndex=-1,n.required&&(u.required=!0),f.appendChild(u);function k(){Array.from(f.querySelectorAll("input.voc-form-tag-hidden")).forEach(p=>p.parentElement?.removeChild(p)),d.forEach(p=>{let s=document.createElement("input");s.type="hidden",s.name=`${v}[]`,s.className="voc-form-tag-hidden",s.value=p,n.key&&(s.id=`voc-form-${n.key}`),f.appendChild(s)}),n.required&&(d.length===0?(u.value="",u.setCustomValidity("Please enter at least one tag")):(u.value="1",u.setCustomValidity("")))}function T(e){let p=document.createElement("span");p.className="voc-form-tag",p.style.display="inline-flex",p.style.alignItems="center",p.style.padding="4px 8px",p.style.background="rgba(0,0,0,0.05)",p.style.borderRadius="16px";let s=document.createElement("span");s.textContent=e,s.style.marginRight="8px",p.appendChild(s);let o=document.createElement("button");return o.type="button",o.textContent="\xD7",o.style.border="none",o.style.background="transparent",o.style.cursor="pointer",o.addEventListener("click",()=>{let h=d.indexOf(e);h>=0&&(d.splice(h,1),m.removeChild(p),k())}),p.appendChild(o),p}function C(e){let p=e.trim();if(!p||d.includes(p))return;d.push(p);let s=T(p);m.insertBefore(s,i),k()}let b=g!=null?String(g):n.default||"";return b&&b.split(",").map(e=>e.trim()).filter(Boolean).forEach(C),i.addEventListener("keydown",e=>{if(e.key==="Enter"||e.key===",")e.preventDefault(),C(i.value),i.value="";else if(e.key==="Backspace"&&i.value===""&&d.pop()){let s=Array.from(m.querySelectorAll(".voc-form-tag")),o=s[s.length-1];o&&m.removeChild(o),k()}}),i.addEventListener("paste",e=>{let p=e.clipboardData?.getData("text");p&&(e.preventDefault(),p.split(/[,\n\r]+/).map(s=>s.trim()).filter(Boolean).forEach(C),i.value="")}),f.getTags=()=>d.slice(),f.addTag=C,f.appendChild(m),k(),f}function J(n,w,g,x){let f=w?.style==="bootstrap",v=document.createElement("div");v.className="voc-form-field-selects";let m=document.createElement("div");if(m.className="voc-form-field-selects-header",f&&m.classList.add("mb-2"),n.label){let o=document.createElement("div");if(o.className="voc-form-field-selects-label",f&&o.classList.add("form-label"),o.textContent=n.label,n.required){let h=document.createElement("span");h.className="voc-form-required",h.textContent="*",o.appendChild(h)}m.appendChild(o)}if(n.description){let o=document.createElement("div");o.className="voc-form-field-selects-description",f&&o.classList.add("form-text"),o.textContent=n.description,m.appendChild(o)}v.appendChild(m);let i=document.createElement("div");i.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"),i.appendChild(d),v.appendChild(i);let u=n.options;if(!u||u.length===0)return v;let k=document.createElement("div");k.className="voc-form-field-selects-list",f&&k.classList.add("list-group");let T=document.createElement("div");T.className="voc-form-field-selects-selected",T.style.marginTop="12px";let C={},b=n.name||n.key||`users_${Math.random().toString(36).substr(2,6)}`,e=[];if(Array.isArray(g)?e=g:g!=null?e=[g]:Array.isArray(n.default)&&(e=n.default),u.forEach((o,h)=>{let l=document.createElement("div");l.className="voc-form-field-selects-item",l.dataset.label=String(o.option_label??o.label??"").toLowerCase(),l.dataset.email=String(o.email||"").toLowerCase(),l.dataset.value=String(o.value||"").toLowerCase(),f&&l.classList.add("d-flex","align-items-center","gap-2");let r=document.createElement("input");if(r.type="checkbox",r.name=`${b}[]`,r.value=o.value??o.key,r.className="voc-form--checkbox",n.key&&(r.id=`voc-form-${n.key}-${h}`),r.style.position="absolute",r.style.width="1px",r.style.height="1px",r.style.margin="0",r.style.padding="0",r.style.clip="rect(0 0 0 0)",r.style.clipPath="inset(50%)",r.style.overflow="hidden",r.style.border="0",e&&Array.isArray(e)){let N=e.map(y=>String(y)),A=String(o.value??o.key);r.checked=N.includes(A)}let a=o.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>',t=document.createElement("div");t.className="voc-form-fields-select-avatar",t.innerHTML=a;let c=document.createElement("div");c.className="voc-form-field-select-info",c.style.display="flex",c.style.flexDirection="column",c.style.gap="2px";let E=document.createElement("div");E.className="voc-form-field-select-label",E.textContent=(o.option_label??o.label)||String(o.value);let L=document.createElement("small");L.className="voc-form-field-select-email",L.textContent=o.email||"",c.appendChild(E),c.appendChild(L),l.addEventListener("click",N=>{let A=N.target;A&&(A.closest("input")||A.closest("a")||A.closest("button"))||(r.checked=!r.checked,r.dispatchEvent(new Event("change",{bubbles:!0})))}),r.addEventListener("change",()=>{if(r.checked){l.classList.add("selected"),(C[h]||[]).forEach(y=>y.parentElement?.removeChild(y)),C[h]=[];let A=o;if(A&&Array.isArray(A.items))A.items.forEach(y=>{let F=x(y);F&&(T.appendChild(F),C[h].push(F))});else if(A&&(A.type||A.key)){let y=x(A);y&&(T.appendChild(y),C[h].push(y))}}else l.classList.remove("selected"),(C[h]||[]).forEach(A=>A.parentElement?.removeChild(A)),C[h]=[]}),r.checked&&(l.classList.add("selected"),setTimeout(()=>{let N=o;if(N&&Array.isArray(N.items))N.items.forEach(A=>{let y=x(A);y&&(T.appendChild(y),C[h]=C[h]||[],C[h].push(y))});else if(N&&(N.type||N.key)){let A=x(N);A&&(T.appendChild(A),C[h]=C[h]||[],C[h].push(A))}},0)),l.appendChild(r),l.appendChild(t),l.appendChild(c),k.appendChild(l)}),v.appendChild(k),v.appendChild(T),n.required){let o=k.querySelectorAll('input[type="checkbox"]'),h=()=>{let l=Array.from(o).some(r=>r.checked);return o.forEach(r=>{l?r.setCustomValidity(""):r.setCustomValidity("At least one option must be selected.")}),l};o.forEach(l=>{l.addEventListener("change",h)}),v._validateCheckboxGroup=h,h()}let p=Array.from(k.querySelectorAll(".voc-form-field-select-item")),s=()=>{let o=String(d.value||"").trim().toLowerCase();if(!o){p.forEach(h=>h.style.setProperty("display","flex","important"));return}p.forEach(h=>{let l=h.dataset.label||"",r=h.dataset.email||"",a=h.dataset.value||"",t=l.includes(o)||r.includes(o)||a.includes(o);h.style.setProperty("display",t?"flex":"none","important")})};return d.addEventListener("input",s),v}function I(n,w=!0){let g=new FormData(n);if(w)return te(g);let x={};return g.forEach((f,v)=>{let m=(f instanceof File,f);Object.prototype.hasOwnProperty.call(x,v)?Array.isArray(x[v])?x[v].push(m):x[v]=[x[v],m]:x[v]=m}),x}function te(n){let w=new FormData;for(let[g,x]of n.entries()){if(x instanceof File){w.append(g,x);continue}let f;try{f=JSON.parse(x)}catch{f=null}Array.isArray(f)?f.length===0?w.append(g,"[]"):f.every(v=>typeof v=="object"&&v!==null)?f.forEach((v,m)=>{for(let[i,d]of Object.entries(v))w.append(`${g}[${m}][${i}]`,d)}):w.append(g,x):w.append(g,x)}return w}async function Y(n,w,g){let x=w.url,f={"Content-Type":"application/json"};w?.api_token&&(f.Authorization=`Bearer ${w.api_token}`);let v=I(n);if(w?.additional_data)for(let[d,u]of Object.entries(w.additional_data))v.append(d,u);let m,i=v instanceof FormData;m={method:"POST",headers:{Authorization:`Bearer ${w.api_token}`,...i?{}:{"Content-Type":"application/json"},Accept:"application/json"},body:i?v:JSON.stringify(Object.fromEntries(v.entries()))};try{fetch(x,m).then(async d=>{let u=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(k){throw new Error(k.message)}return u&&u.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(n,w,g){let x=[];if(typeof n=="string"?x=Array.from(document.querySelectorAll(n)):x=[n],x.length===0)return null;function f(){let i=g?.style==="bootstrap",d=document.createElement("form");d.classList.add("voc-form"),i&&d.classList.add("needs-validation"),d.id=w.id;let u=document.createElement("h2");u.className="voc-form-title",i&&u.classList.add("mb-3"),u.textContent=w.form_name,d.appendChild(u);function k(e,p){p&&(p.min_length!==void 0&&(e.minLength=p.min_length),p.max_length!==void 0&&(e.maxLength=p.max_length),p.regex&&(e instanceof HTMLInputElement?e.pattern=p.regex:e.dataset.pattern=p.regex))}function T(e){if(!e.key&&!e.label)return null;let p=w.default_values||{},s=e.name||e.key,o=s?p[s]:void 0,h=document.createElement("div");if(h.className="voc-form-group",i&&h.classList.add("mb-3"),e.label&&e.type!=="users"){let a=document.createElement("label");if(a.classList.add("voc-form-label"),i&&a.classList.add("form-label"),e.key?e.type==="radio"?a.htmlFor="":a.htmlFor=`voc-form-${e.key}`:a.htmlFor="",a.textContent=e.label,e.required){let t=document.createElement("span");t.className="voc-form-required",t.textContent="*",a.appendChild(t)}h.appendChild(a)}let l=new Set(["users","timezone"]);if(e.description&&!l.has(String(e.type||""))){let a=document.createElement("div");a.className="voc-form-description",i&&a.classList.add("form-text","text-muted","mb-2"),a.textContent=e.description,h.appendChild(a)}let r=null;switch(e.type){case"tags":{r=U(e,g||{},o);break}case"checkbox":{let a=document.createElement("div");if(a.className="voc-form-checkbox-group "+(e.direction||"vertical"),e.width&&(a.style.width=e.width),e.options){if(e.options.forEach((t,c)=>{let E=document.createElement("label");E.classList.add("voc-form-checkbox-label"),i&&E.classList.add("form-check"),E.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(E.style.width=e.width);let L=document.createElement("input");L.type="checkbox",L.classList.add("voc-form-checkbox"),i&&L.classList.add("form-check-input"),L.name=`${e.name||e.key||""}[]`,L.value=t.value,e.key&&(L.id=`voc-form-${e.key}-${c}`),Array.isArray(o)?o.includes(t.value)&&(L.checked=!0):o!==void 0?o===t.value&&(L.checked=!0):e.default===t.value&&(L.checked=!0),E.appendChild(L),E.appendChild(document.createTextNode(t.label)),a.appendChild(E)}),e.required){let t=a.querySelectorAll('input[type="checkbox"]'),c=()=>{let E=Array.from(t).some(L=>L.checked);return t.forEach(L=>{E?L.setCustomValidity(""):L.setCustomValidity("At least one option must be selected.")}),E};t.forEach(E=>{E.addEventListener("change",c)}),a._validateCheckboxGroup=c,c()}}else{let t=document.createElement("label");t.classList.add("voc-form-checkbox-label"),i&&t.classList.add("form-check"),e.width&&(t.style.width=e.width);let c=document.createElement("input");c.type="checkbox",c.classList.add("voc-form-checkbox"),(e.key||e.name)&&(c.name=e.name||e.key,e.key&&(c.id=`voc-form-${e.key}`)),i&&c.classList.add("form-check-input"),e.required&&(c.required=!0),o!==void 0?c.checked=!!o:e.default&&(c.checked=!!e.default),t.appendChild(c),t.appendChild(document.createTextNode(e.label||"")),a.appendChild(t)}r=a;break}case"boolean":{let a=document.createElement("div");a.className="voc-form-boolean-wrapper",i&&a.classList.add("form-check"),e.width&&(a.style.width=e.width);let t=document.createElement("input");if(t.type="checkbox",t.classList.add("voc-form-boolean"),i&&t.classList.add("form-check-input"),(e.key||e.name)&&(t.name=e.name||e.key,e.key&&(t.id=`voc-form-${e.key}`)),e.required&&(t.required=!0),o!==void 0?t.checked=!!o:e.default!==void 0&&(t.checked=e.default===!0||e.default==="true"),a.appendChild(t),e.label){let E=document.createElement("label");if(E.classList.add("voc-form-boolean-label"),i&&E.classList.add("form-check-label"),e.key&&(E.htmlFor=`voc-form-${e.key}`),E.textContent=e.label,e.required){let L=document.createElement("span");L.className="voc-form-required",L.textContent="*",E.appendChild(L)}a.appendChild(E)}let c=h.querySelector(".voc-form-label");c&&c.remove(),r=a;break}case"textarea":{let a=document.createElement("textarea");a.classList.add("voc-form-textarea"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder&&(a.placeholder=e.placeholder),o!=null?a.value=String(o):e.default!==void 0&&e.default!==null&&(a.value=String(e.default));let t=e.default||o||"";if(t){let c=(t.match(/\n/g)||[]).length,E=80,L=t.split(`
2
+ `).reduce((y,F)=>Math.max(y,F.length),0),N=Math.ceil(L/E)||1,A=Math.max(2,c+N);a.rows=A,a.style.resize="vertical"}e.width&&(a.style.width=e.width),e.required&&(a.required=!0),k(a,e.validation),r=a;break}case"select":{let a=document.createElement("select");if(a.classList.add("voc-form-select"),i&&a.classList.add("form-select"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder){let t=document.createElement("option");t.value="",t.textContent=e.placeholder,t.disabled=!0,t.selected=!0,a.appendChild(t)}e.required&&(a.required=!0),e.options&&e.options.forEach(t=>{let c=document.createElement("option");c.value=t.value,c.textContent=t.label,Array.isArray(o)?o.includes(t.value)&&(c.selected=!0):o!==void 0?o===t.value&&(c.selected=!0):e.default===t.value&&(c.selected=!0),a.appendChild(c)}),e.width&&(a.style.width=e.width),r=a;break}case"radio":{let a=document.createElement("div");a.className="voc-form-radio-group "+(e.direction||"vertical"),e.width&&(a.style.width=e.width),e.options&&e.options.forEach((t,c)=>{let E=document.createElement("label");E.classList.add("voc-form-radio-label"),i&&E.classList.add("form-check"),E.style.display=e.direction==="horizontal"?"inline-block":"block",e.width&&(E.style.width=e.width);let L=document.createElement("input");L.type="radio",L.classList.add("voc-form-radio"),i&&L.classList.add("form-check-input"),L.name=e.name||e.key||"",L.value=t.value,e.key&&(L.id=`voc-form-${e.key}-${c}`),Array.isArray(o)?o.includes(t.value)&&(L.checked=!0):o!==void 0?o===t.value&&(L.checked=!0):e.default===t.value&&(L.checked=!0),E.appendChild(L),E.appendChild(document.createTextNode(t.label)),a.appendChild(E)}),r=a;break}case"file":{let a=document.createElement("div");a.className="voc-form-file-wrapper",e.width&&(a.style.width=e.width);let t=document.createElement("input");t.type="file",t.classList.add("voc-form-file"),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.width&&(t.style.width=e.width),e.required&&(t.required=!0),e.accept&&(t.accept=e.accept),e.multiple&&(t.multiple=!0),a.appendChild(t),r=a;break}case"avatar":{r=z(e,g||{},o);break}case"table":{r=W(e,g||{},o);break}case"users":{r=G(e,g||{},o);break}case"timezone":{r=V(e,g||{},o);break}case"audio_select":{r=j(e,g||{},o);break}case"field-select":{r=J(e,g||{},o,T);break}default:{let a=document.createElement("input");a.type=e.type||"text",a.classList.add("voc-form-input"),i&&a.classList.add("form-control"),(e.key||e.name)&&(a.name=e.name||e.key,e.key&&(a.id=`voc-form-${e.key}`)),e.placeholder&&(a.placeholder=e.placeholder),o!=null?a.value=String(o):e.default!==void 0&&e.default!==null&&(a.value=String(e.default)),e.width&&(a.style.width=e.width),e.required&&(a.required=!0),k(a,e.validation),r=a;break}}if(r&&h.appendChild(r),e.hint_text){let a=document.createElement("small");a.className="voc-form-hint",a.textContent=e.hint_text,h.appendChild(a)}return h}function C(e,p,s=0){if(e.type==="group"&&"items"in e){let h=e;if(i){let l=document.createElement("div");l.className="card voc-form-group-card mb-3",s>0&&l.classList.add("voc-form-nested-group");let r=h.label||h.header?.title,a=h.description||h.header?.description;if(r||a){let c=document.createElement("div");if(c.className="card-header voc-form-group-head",r){let E=document.createElement("h5");E.className="mb-0 voc-form-group-label",E.textContent=r,c.appendChild(E)}if(a){let E=document.createElement("p");E.className="mb-0 voc-form-group-description",E.textContent=a,c.appendChild(E)}l.appendChild(c)}let t=document.createElement("div");t.className="card-body voc-form-group-body",h.items.forEach(c=>{C(c,t,s+1)}),l.appendChild(t),p.appendChild(l)}else{let l=document.createElement("div");l.className="voc-form-group voc-form-group-wrapper",s>0&&l.classList.add("voc-form-nested-group");let r=h.label||h.header?.title,a=h.description||h.header?.description;if(r||a){let t=document.createElement("div");if(t.className="voc-form-group-head",r){let c=document.createElement("h3");c.className="voc-form-group-label",c.textContent=r,t.appendChild(c)}if(a){let c=document.createElement("p");c.className="voc-form-group-description",c.textContent=a,t.appendChild(c)}l.appendChild(t)}h.items.forEach(t=>{C(t,l,s+1)}),p.appendChild(l)}return}if(e.type==="row"&&"items"in e){let h=e,l=document.createElement("div");if(l.className="voc-form-group voc-form-row",i&&l.classList.add("mb-3"),h.label){let a=document.createElement(s>0?"h6":"h3");a.className="voc-form-row-label",a.textContent=h.label,l.appendChild(a)}if(h.description){let a=document.createElement("p");a.className="voc-form-row-description",a.textContent=h.description,l.appendChild(a)}let r=document.createElement("div");r.className="voc-form-row-items "+(h.direction||"horizontal"),h.items.forEach(a=>{let t=T(a);t&&r.appendChild(t)}),l.appendChild(r),p.appendChild(l);return}let o=T(e);o&&p.appendChild(o)}w.fields.forEach(e=>{C(e,d,0)});let b=document.createElement("button");return b.type="submit",b.className="voc-form-submit",b.textContent="Submit",i&&b.classList.add("btn","btn-primary"),d.appendChild(b),d}let v=f();x[0].appendChild(v);let m=w?.submit_config??g?.submit_config??null;return m&&v.addEventListener("submit",i=>{i.preventDefault();let d=Array.from(v.querySelectorAll(".voc-form-checkbox-group, .voc-form-users")),u=[];if(d.forEach(C=>{C&&typeof C._validateCheckboxGroup=="function"&&(C._validateCheckboxGroup()||C.querySelector('input[type="checkbox"]')&&u.push("Please select at least one option"))}),!v.checkValidity()){v.reportValidity(),g?.onSubmitResult&&g.onSubmitResult(null,new Error("Form validation failed"));return}let k=Array.from(v.querySelectorAll(" .voc-form-table-wrapper, .voc-form-table-wrapper")),T=[];if(k.forEach(C=>{if(C&&typeof C.validate=="function"){let b=C.validate();b&&b.length&&T.push(...b)}}),T.length){g?.onSubmitResult&&g.onSubmitResult(null,new Error(T.join("; ")));let C=k[0];C&&C.scrollIntoView({behavior:"smooth",block:"center"});return}if(g?.onSubmit){let C=I(v);g.onSubmit(C)}Y(v,m,(C,b)=>{g?.onSubmitResult&&g.onSubmitResult(C,b)})}),{element:v,validate:()=>{let i=[];return v.querySelectorAll(":invalid").forEach(u=>{let k=u.validationMessage;i.push({element:u,message:k})}),i},getValues:()=>I(v),onSubmit:i=>{v.addEventListener("submit",d=>{d.preventDefault();let u=I(v);i(u,d)})}}}var P={renderForm:K};var we=P,Ae={FormsLib:P};export{we 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.66",
3
+ "version": "1.0.67",
4
4
  "description": "A JavaScript library for VocPhone",
5
5
  "main": "./dist/main.cjs",
6
6
  "module": "./dist/main.mjs",