drill-widgets 2.7.5 → 2.7.7

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.
@@ -6,13 +6,13 @@
6
6
  * @license
7
7
  * Copyright 2017 Google LLC
8
8
  * SPDX-License-Identifier: BSD-3-Clause
9
- */const{is:He,defineProperty:Ve,getOwnPropertyDescriptor:je,getOwnPropertyNames:Qe,getOwnPropertySymbols:Be,getPrototypeOf:Ge}=Object,M=globalThis,ye=M.trustedTypes,Ye=ye?ye.emptyScript:"",oe=M.reactiveElementPolyfillSupport,W=(i,e)=>i,q={toAttribute(i,e){switch(e){case Boolean:i=i?Ye:null;break;case Object:case Array:i=i==null?i:JSON.stringify(i)}return i},fromAttribute(i,e){let t=i;switch(e){case Boolean:t=i!==null;break;case Number:t=i===null?null:Number(i);break;case Object:case Array:try{t=JSON.parse(i)}catch{t=null}}return t}},ae=(i,e)=>!He(i,e),we={attribute:!0,type:String,converter:q,reflect:!1,useDefault:!1,hasChanged:ae};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),M.litPropertyMetadata??(M.litPropertyMetadata=new WeakMap);let N=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??(this.l=[])).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=we){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){const n=Symbol(),s=this.getPropertyDescriptor(e,n,t);s!==void 0&&Ve(this.prototype,e,s)}}static getPropertyDescriptor(e,t,n){const{get:s,set:r}=je(this.prototype,e)??{get(){return this[t]},set(o){this[t]=o}};return{get:s,set(o){const a=s==null?void 0:s.call(this);r==null||r.call(this,o),this.requestUpdate(e,a,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??we}static _$Ei(){if(this.hasOwnProperty(W("elementProperties")))return;const e=Ge(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(W("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(W("properties"))){const t=this.properties,n=[...Qe(t),...Be(t)];for(const s of n)this.createProperty(s,t[s])}const e=this[Symbol.metadata];if(e!==null){const t=litPropertyMetadata.get(e);if(t!==void 0)for(const[n,s]of t)this.elementProperties.set(n,s)}this._$Eh=new Map;for(const[t,n]of this.elementProperties){const s=this._$Eu(t,n);s!==void 0&&this._$Eh.set(s,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const n=new Set(e.flat(1/0).reverse());for(const s of n)t.unshift(Se(s))}else e!==void 0&&t.push(Se(e));return t}static _$Eu(e,t){const n=t.attribute;return n===!1?void 0:typeof n=="string"?n:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var e;this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),(e=this.constructor.l)==null||e.forEach(t=>t(this))}addController(e){var t;(this._$EO??(this._$EO=new Set)).add(e),this.renderRoot!==void 0&&this.isConnected&&((t=e.hostConnected)==null||t.call(e))}removeController(e){var t;(t=this._$EO)==null||t.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const n of t.keys())this.hasOwnProperty(n)&&(e.set(n,this[n]),delete this[n]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return We(e,this.constructor.elementStyles),e}connectedCallback(){var e;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(e=this._$EO)==null||e.forEach(t=>{var n;return(n=t.hostConnected)==null?void 0:n.call(t)})}enableUpdating(e){}disconnectedCallback(){var e;(e=this._$EO)==null||e.forEach(t=>{var n;return(n=t.hostDisconnected)==null?void 0:n.call(t)})}attributeChangedCallback(e,t,n){this._$AK(e,n)}_$ET(e,t){var r;const n=this.constructor.elementProperties.get(e),s=this.constructor._$Eu(e,n);if(s!==void 0&&n.reflect===!0){const o=(((r=n.converter)==null?void 0:r.toAttribute)!==void 0?n.converter:q).toAttribute(t,n.type);this._$Em=e,o==null?this.removeAttribute(s):this.setAttribute(s,o),this._$Em=null}}_$AK(e,t){var r,o;const n=this.constructor,s=n._$Eh.get(e);if(s!==void 0&&this._$Em!==s){const a=n.getPropertyOptions(s),d=typeof a.converter=="function"?{fromAttribute:a.converter}:((r=a.converter)==null?void 0:r.fromAttribute)!==void 0?a.converter:q;this._$Em=s,this[s]=d.fromAttribute(t,a.type)??((o=this._$Ej)==null?void 0:o.get(s))??null,this._$Em=null}}requestUpdate(e,t,n){var s;if(e!==void 0){const r=this.constructor,o=this[e];if(n??(n=r.getPropertyOptions(e)),!((n.hasChanged??ae)(o,t)||n.useDefault&&n.reflect&&o===((s=this._$Ej)==null?void 0:s.get(e))&&!this.hasAttribute(r._$Eu(e,n))))return;this.C(e,t,n)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,t,{useDefault:n,reflect:s,wrapped:r},o){n&&!(this._$Ej??(this._$Ej=new Map)).has(e)&&(this._$Ej.set(e,o??t??this[e]),r!==!0||o!==void 0)||(this._$AL.has(e)||(this.hasUpdated||n||(t=void 0),this._$AL.set(e,t)),s===!0&&this._$Em!==e&&(this._$Eq??(this._$Eq=new Set)).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var n;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[r,o]of this._$Ep)this[r]=o;this._$Ep=void 0}const s=this.constructor.elementProperties;if(s.size>0)for(const[r,o]of s){const{wrapped:a}=o,d=this[r];a!==!0||this._$AL.has(r)||d===void 0||this.C(r,void 0,o,d)}}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),(n=this._$EO)==null||n.forEach(s=>{var r;return(r=s.hostUpdate)==null?void 0:r.call(s)}),this.update(t)):this._$EM()}catch(s){throw e=!1,this._$EM(),s}e&&this._$AE(t)}willUpdate(e){}_$AE(e){var t;(t=this._$EO)==null||t.forEach(n=>{var s;return(s=n.hostUpdated)==null?void 0:s.call(n)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&(this._$Eq=this._$Eq.forEach(t=>this._$ET(t,this[t]))),this._$EM()}updated(e){}firstUpdated(e){}};N.elementStyles=[],N.shadowRootOptions={mode:"open"},N[W("elementProperties")]=new Map,N[W("finalized")]=new Map,oe==null||oe({ReactiveElement:N}),(M.reactiveElementVersions??(M.reactiveElementVersions=[])).push("2.1.0");/**
9
+ */const{is:He,defineProperty:Ve,getOwnPropertyDescriptor:je,getOwnPropertyNames:Qe,getOwnPropertySymbols:Be,getPrototypeOf:Ge}=Object,M=globalThis,ye=M.trustedTypes,Ye=ye?ye.emptyScript:"",oe=M.reactiveElementPolyfillSupport,W=(i,e)=>i,q={toAttribute(i,e){switch(e){case Boolean:i=i?Ye:null;break;case Object:case Array:i=i==null?i:JSON.stringify(i)}return i},fromAttribute(i,e){let t=i;switch(e){case Boolean:t=i!==null;break;case Number:t=i===null?null:Number(i);break;case Object:case Array:try{t=JSON.parse(i)}catch{t=null}}return t}},ae=(i,e)=>!He(i,e),we={attribute:!0,type:String,converter:q,reflect:!1,useDefault:!1,hasChanged:ae};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),M.litPropertyMetadata??(M.litPropertyMetadata=new WeakMap);let N=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??(this.l=[])).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=we){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){const n=Symbol(),s=this.getPropertyDescriptor(e,n,t);s!==void 0&&Ve(this.prototype,e,s)}}static getPropertyDescriptor(e,t,n){const{get:s,set:r}=je(this.prototype,e)??{get(){return this[t]},set(o){this[t]=o}};return{get:s,set(o){const a=s==null?void 0:s.call(this);r==null||r.call(this,o),this.requestUpdate(e,a,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??we}static _$Ei(){if(this.hasOwnProperty(W("elementProperties")))return;const e=Ge(this);e.finalize(),e.l!==void 0&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(W("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(W("properties"))){const t=this.properties,n=[...Qe(t),...Be(t)];for(const s of n)this.createProperty(s,t[s])}const e=this[Symbol.metadata];if(e!==null){const t=litPropertyMetadata.get(e);if(t!==void 0)for(const[n,s]of t)this.elementProperties.set(n,s)}this._$Eh=new Map;for(const[t,n]of this.elementProperties){const s=this._$Eu(t,n);s!==void 0&&this._$Eh.set(s,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const n=new Set(e.flat(1/0).reverse());for(const s of n)t.unshift(Se(s))}else e!==void 0&&t.push(Se(e));return t}static _$Eu(e,t){const n=t.attribute;return n===!1?void 0:typeof n=="string"?n:typeof e=="string"?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){var e;this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),(e=this.constructor.l)==null||e.forEach(t=>t(this))}addController(e){var t;(this._$EO??(this._$EO=new Set)).add(e),this.renderRoot!==void 0&&this.isConnected&&((t=e.hostConnected)==null||t.call(e))}removeController(e){var t;(t=this._$EO)==null||t.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const n of t.keys())this.hasOwnProperty(n)&&(e.set(n,this[n]),delete this[n]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return We(e,this.constructor.elementStyles),e}connectedCallback(){var e;this.renderRoot??(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),(e=this._$EO)==null||e.forEach(t=>{var n;return(n=t.hostConnected)==null?void 0:n.call(t)})}enableUpdating(e){}disconnectedCallback(){var e;(e=this._$EO)==null||e.forEach(t=>{var n;return(n=t.hostDisconnected)==null?void 0:n.call(t)})}attributeChangedCallback(e,t,n){this._$AK(e,n)}_$ET(e,t){var r;const n=this.constructor.elementProperties.get(e),s=this.constructor._$Eu(e,n);if(s!==void 0&&n.reflect===!0){const o=(((r=n.converter)==null?void 0:r.toAttribute)!==void 0?n.converter:q).toAttribute(t,n.type);this._$Em=e,o==null?this.removeAttribute(s):this.setAttribute(s,o),this._$Em=null}}_$AK(e,t){var r,o;const n=this.constructor,s=n._$Eh.get(e);if(s!==void 0&&this._$Em!==s){const a=n.getPropertyOptions(s),l=typeof a.converter=="function"?{fromAttribute:a.converter}:((r=a.converter)==null?void 0:r.fromAttribute)!==void 0?a.converter:q;this._$Em=s,this[s]=l.fromAttribute(t,a.type)??((o=this._$Ej)==null?void 0:o.get(s))??null,this._$Em=null}}requestUpdate(e,t,n){var s;if(e!==void 0){const r=this.constructor,o=this[e];if(n??(n=r.getPropertyOptions(e)),!((n.hasChanged??ae)(o,t)||n.useDefault&&n.reflect&&o===((s=this._$Ej)==null?void 0:s.get(e))&&!this.hasAttribute(r._$Eu(e,n))))return;this.C(e,t,n)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(e,t,{useDefault:n,reflect:s,wrapped:r},o){n&&!(this._$Ej??(this._$Ej=new Map)).has(e)&&(this._$Ej.set(e,o??t??this[e]),r!==!0||o!==void 0)||(this._$AL.has(e)||(this.hasUpdated||n||(t=void 0),this._$AL.set(e,t)),s===!0&&this._$Em!==e&&(this._$Eq??(this._$Eq=new Set)).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const e=this.scheduleUpdate();return e!=null&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var n;if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??(this.renderRoot=this.createRenderRoot()),this._$Ep){for(const[r,o]of this._$Ep)this[r]=o;this._$Ep=void 0}const s=this.constructor.elementProperties;if(s.size>0)for(const[r,o]of s){const{wrapped:a}=o,l=this[r];a!==!0||this._$AL.has(r)||l===void 0||this.C(r,void 0,o,l)}}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),(n=this._$EO)==null||n.forEach(s=>{var r;return(r=s.hostUpdate)==null?void 0:r.call(s)}),this.update(t)):this._$EM()}catch(s){throw e=!1,this._$EM(),s}e&&this._$AE(t)}willUpdate(e){}_$AE(e){var t;(t=this._$EO)==null||t.forEach(n=>{var s;return(s=n.hostUpdated)==null?void 0:s.call(n)}),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&(this._$Eq=this._$Eq.forEach(t=>this._$ET(t,this[t]))),this._$EM()}updated(e){}firstUpdated(e){}};N.elementStyles=[],N.shadowRootOptions={mode:"open"},N[W("elementProperties")]=new Map,N[W("finalized")]=new Map,oe==null||oe({ReactiveElement:N}),(M.reactiveElementVersions??(M.reactiveElementVersions=[])).push("2.1.0");/**
10
10
  * @license
11
11
  * Copyright 2017 Google LLC
12
12
  * SPDX-License-Identifier: BSD-3-Clause
13
- */const H=globalThis,K=H.trustedTypes,ke=K?K.createPolicy("lit-html",{createHTML:i=>i}):void 0,$e="$lit$",F=`lit$${Math.random().toFixed(9).slice(2)}$`,De="?"+F,qe=`<${De}>`,T=document,V=()=>T.createComment(""),j=i=>i===null||typeof i!="object"&&typeof i!="function",de=Array.isArray,Ke=i=>de(i)||typeof(i==null?void 0:i[Symbol.iterator])=="function",le=`[
14
- \f\r]`,Q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Ce=/-->/g,Ee=/>/g,z=RegExp(`>|${le}(?:([^\\s"'>=/]+)(${le}*=${le}*(?:[^
15
- \f\r"'\`<>=]|("|')|))|$)`,"g"),Ae=/'/g,Me=/"/g,Fe=/^(?:script|style|textarea|title)$/i,Je=i=>(e,...t)=>({_$litType$:i,strings:e,values:t}),l=Je(1),I=Symbol.for("lit-noChange"),v=Symbol.for("lit-nothing"),Te=new WeakMap,U=T.createTreeWalker(T,129);function ze(i,e){if(!de(i)||!i.hasOwnProperty("raw"))throw Error("invalid template strings array");return ke!==void 0?ke.createHTML(e):e}const Xe=(i,e)=>{const t=i.length-1,n=[];let s,r=e===2?"<svg>":e===3?"<math>":"",o=Q;for(let a=0;a<t;a++){const d=i[a];let p,c,u=-1,h=0;for(;h<d.length&&(o.lastIndex=h,c=o.exec(d),c!==null);)h=o.lastIndex,o===Q?c[1]==="!--"?o=Ce:c[1]!==void 0?o=Ee:c[2]!==void 0?(Fe.test(c[2])&&(s=RegExp("</"+c[2],"g")),o=z):c[3]!==void 0&&(o=z):o===z?c[0]===">"?(o=s??Q,u=-1):c[1]===void 0?u=-2:(u=o.lastIndex-c[2].length,p=c[1],o=c[3]===void 0?z:c[3]==='"'?Me:Ae):o===Me||o===Ae?o=z:o===Ce||o===Ee?o=Q:(o=z,s=void 0);const f=o===z&&i[a+1].startsWith("/>")?" ":"";r+=o===Q?d+qe:u>=0?(n.push(p),d.slice(0,u)+$e+d.slice(u)+F+f):d+F+(u===-2?a:f)}return[ze(i,r+(i[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),n]};class B{constructor({strings:e,_$litType$:t},n){let s;this.parts=[];let r=0,o=0;const a=e.length-1,d=this.parts,[p,c]=Xe(e,t);if(this.el=B.createElement(p,n),U.currentNode=this.el.content,t===2||t===3){const u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(s=U.nextNode())!==null&&d.length<a;){if(s.nodeType===1){if(s.hasAttributes())for(const u of s.getAttributeNames())if(u.endsWith($e)){const h=c[o++],f=s.getAttribute(u).split(F),b=/([.?@])?(.*)/.exec(h);d.push({type:1,index:r,name:b[2],strings:f,ctor:b[1]==="."?et:b[1]==="?"?tt:b[1]==="@"?it:J}),s.removeAttribute(u)}else u.startsWith(F)&&(d.push({type:6,index:r}),s.removeAttribute(u));if(Fe.test(s.tagName)){const u=s.textContent.split(F),h=u.length-1;if(h>0){s.textContent=K?K.emptyScript:"";for(let f=0;f<h;f++)s.append(u[f],V()),U.nextNode(),d.push({type:2,index:++r});s.append(u[h],V())}}}else if(s.nodeType===8)if(s.data===De)d.push({type:2,index:r});else{let u=-1;for(;(u=s.data.indexOf(F,u+1))!==-1;)d.push({type:7,index:r}),u+=F.length-1}r++}}static createElement(e,t){const n=T.createElement("template");return n.innerHTML=e,n}}function O(i,e,t=i,n){var o,a;if(e===I)return e;let s=n!==void 0?(o=t._$Co)==null?void 0:o[n]:t._$Cl;const r=j(e)?void 0:e._$litDirective$;return(s==null?void 0:s.constructor)!==r&&((a=s==null?void 0:s._$AO)==null||a.call(s,!1),r===void 0?s=void 0:(s=new r(i),s._$AT(i,t,n)),n!==void 0?(t._$Co??(t._$Co=[]))[n]=s:t._$Cl=s),s!==void 0&&(e=O(i,s._$AS(i,e.values),s,n)),e}class Ze{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:n}=this._$AD,s=((e==null?void 0:e.creationScope)??T).importNode(t,!0);U.currentNode=s;let r=U.nextNode(),o=0,a=0,d=n[0];for(;d!==void 0;){if(o===d.index){let p;d.type===2?p=new G(r,r.nextSibling,this,e):d.type===1?p=new d.ctor(r,d.name,d.strings,this,e):d.type===6&&(p=new nt(r,this,e)),this._$AV.push(p),d=n[++a]}o!==(d==null?void 0:d.index)&&(r=U.nextNode(),o++)}return U.currentNode=T,s}p(e){let t=0;for(const n of this._$AV)n!==void 0&&(n.strings!==void 0?(n._$AI(e,n,t),t+=n.strings.length-2):n._$AI(e[t])),t++}}class G{get _$AU(){var e;return((e=this._$AM)==null?void 0:e._$AU)??this._$Cv}constructor(e,t,n,s){this.type=2,this._$AH=v,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=n,this.options=s,this._$Cv=(s==null?void 0:s.isConnected)??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(e==null?void 0:e.nodeType)===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=O(this,e,t),j(e)?e===v||e==null||e===""?(this._$AH!==v&&this._$AR(),this._$AH=v):e!==this._$AH&&e!==I&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Ke(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==v&&j(this._$AH)?this._$AA.nextSibling.data=e:this.T(T.createTextNode(e)),this._$AH=e}$(e){var r;const{values:t,_$litType$:n}=e,s=typeof n=="number"?this._$AC(e):(n.el===void 0&&(n.el=B.createElement(ze(n.h,n.h[0]),this.options)),n);if(((r=this._$AH)==null?void 0:r._$AD)===s)this._$AH.p(t);else{const o=new Ze(s,this),a=o.u(this.options);o.p(t),this.T(a),this._$AH=o}}_$AC(e){let t=Te.get(e.strings);return t===void 0&&Te.set(e.strings,t=new B(e)),t}k(e){de(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let n,s=0;for(const r of e)s===t.length?t.push(n=new G(this.O(V()),this.O(V()),this,this.options)):n=t[s],n._$AI(r),s++;s<t.length&&(this._$AR(n&&n._$AB.nextSibling,s),t.length=s)}_$AR(e=this._$AA.nextSibling,t){var n;for((n=this._$AP)==null?void 0:n.call(this,!1,!0,t);e&&e!==this._$AB;){const s=e.nextSibling;e.remove(),e=s}}setConnected(e){var t;this._$AM===void 0&&(this._$Cv=e,(t=this._$AP)==null||t.call(this,e))}}class J{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,n,s,r){this.type=1,this._$AH=v,this._$AN=void 0,this.element=e,this.name=t,this._$AM=s,this.options=r,n.length>2||n[0]!==""||n[1]!==""?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=v}_$AI(e,t=this,n,s){const r=this.strings;let o=!1;if(r===void 0)e=O(this,e,t,0),o=!j(e)||e!==this._$AH&&e!==I,o&&(this._$AH=e);else{const a=e;let d,p;for(e=r[0],d=0;d<r.length-1;d++)p=O(this,a[n+d],t,d),p===I&&(p=this._$AH[d]),o||(o=!j(p)||p!==this._$AH[d]),p===v?e=v:e!==v&&(e+=(p??"")+r[d+1]),this._$AH[d]=p}o&&!s&&this.j(e)}j(e){e===v?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class et extends J{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===v?void 0:e}}class tt extends J{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==v)}}class it extends J{constructor(e,t,n,s,r){super(e,t,n,s,r),this.type=5}_$AI(e,t=this){if((e=O(this,e,t,0)??v)===I)return;const n=this._$AH,s=e===v&&n!==v||e.capture!==n.capture||e.once!==n.once||e.passive!==n.passive,r=e!==v&&(n===v||s);s&&this.element.removeEventListener(this.name,this,n),r&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,e):this._$AH.handleEvent(e)}}class nt{constructor(e,t,n){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=n}get _$AU(){return this._$AM._$AU}_$AI(e){O(this,e)}}const pe=H.litHtmlPolyfillSupport;pe==null||pe(B,G),(H.litHtmlVersions??(H.litHtmlVersions=[])).push("3.3.0");const st=(i,e,t)=>{const n=(t==null?void 0:t.renderBefore)??e;let s=n._$litPart$;if(s===void 0){const r=(t==null?void 0:t.renderBefore)??null;n._$litPart$=s=new G(e.insertBefore(V(),r),r,void 0,t??{})}return s._$AI(i),s};/**
13
+ */const H=globalThis,K=H.trustedTypes,ke=K?K.createPolicy("lit-html",{createHTML:i=>i}):void 0,$e="$lit$",T=`lit$${Math.random().toFixed(9).slice(2)}$`,De="?"+T,qe=`<${De}>`,F=document,V=()=>F.createComment(""),j=i=>i===null||typeof i!="object"&&typeof i!="function",le=Array.isArray,Ke=i=>le(i)||typeof(i==null?void 0:i[Symbol.iterator])=="function",de=`[
14
+ \f\r]`,Q=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Ce=/-->/g,Ee=/>/g,z=RegExp(`>|${de}(?:([^\\s"'>=/]+)(${de}*=${de}*(?:[^
15
+ \f\r"'\`<>=]|("|')|))|$)`,"g"),Ae=/'/g,Me=/"/g,Te=/^(?:script|style|textarea|title)$/i,Je=i=>(e,...t)=>({_$litType$:i,strings:e,values:t}),d=Je(1),I=Symbol.for("lit-noChange"),v=Symbol.for("lit-nothing"),Fe=new WeakMap,U=F.createTreeWalker(F,129);function ze(i,e){if(!le(i)||!i.hasOwnProperty("raw"))throw Error("invalid template strings array");return ke!==void 0?ke.createHTML(e):e}const Xe=(i,e)=>{const t=i.length-1,n=[];let s,r=e===2?"<svg>":e===3?"<math>":"",o=Q;for(let a=0;a<t;a++){const l=i[a];let p,c,u=-1,h=0;for(;h<l.length&&(o.lastIndex=h,c=o.exec(l),c!==null);)h=o.lastIndex,o===Q?c[1]==="!--"?o=Ce:c[1]!==void 0?o=Ee:c[2]!==void 0?(Te.test(c[2])&&(s=RegExp("</"+c[2],"g")),o=z):c[3]!==void 0&&(o=z):o===z?c[0]===">"?(o=s??Q,u=-1):c[1]===void 0?u=-2:(u=o.lastIndex-c[2].length,p=c[1],o=c[3]===void 0?z:c[3]==='"'?Me:Ae):o===Me||o===Ae?o=z:o===Ce||o===Ee?o=Q:(o=z,s=void 0);const f=o===z&&i[a+1].startsWith("/>")?" ":"";r+=o===Q?l+qe:u>=0?(n.push(p),l.slice(0,u)+$e+l.slice(u)+T+f):l+T+(u===-2?a:f)}return[ze(i,r+(i[t]||"<?>")+(e===2?"</svg>":e===3?"</math>":"")),n]};class B{constructor({strings:e,_$litType$:t},n){let s;this.parts=[];let r=0,o=0;const a=e.length-1,l=this.parts,[p,c]=Xe(e,t);if(this.el=B.createElement(p,n),U.currentNode=this.el.content,t===2||t===3){const u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(s=U.nextNode())!==null&&l.length<a;){if(s.nodeType===1){if(s.hasAttributes())for(const u of s.getAttributeNames())if(u.endsWith($e)){const h=c[o++],f=s.getAttribute(u).split(T),b=/([.?@])?(.*)/.exec(h);l.push({type:1,index:r,name:b[2],strings:f,ctor:b[1]==="."?et:b[1]==="?"?tt:b[1]==="@"?it:J}),s.removeAttribute(u)}else u.startsWith(T)&&(l.push({type:6,index:r}),s.removeAttribute(u));if(Te.test(s.tagName)){const u=s.textContent.split(T),h=u.length-1;if(h>0){s.textContent=K?K.emptyScript:"";for(let f=0;f<h;f++)s.append(u[f],V()),U.nextNode(),l.push({type:2,index:++r});s.append(u[h],V())}}}else if(s.nodeType===8)if(s.data===De)l.push({type:2,index:r});else{let u=-1;for(;(u=s.data.indexOf(T,u+1))!==-1;)l.push({type:7,index:r}),u+=T.length-1}r++}}static createElement(e,t){const n=F.createElement("template");return n.innerHTML=e,n}}function O(i,e,t=i,n){var o,a;if(e===I)return e;let s=n!==void 0?(o=t._$Co)==null?void 0:o[n]:t._$Cl;const r=j(e)?void 0:e._$litDirective$;return(s==null?void 0:s.constructor)!==r&&((a=s==null?void 0:s._$AO)==null||a.call(s,!1),r===void 0?s=void 0:(s=new r(i),s._$AT(i,t,n)),n!==void 0?(t._$Co??(t._$Co=[]))[n]=s:t._$Cl=s),s!==void 0&&(e=O(i,s._$AS(i,e.values),s,n)),e}class Ze{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:n}=this._$AD,s=((e==null?void 0:e.creationScope)??F).importNode(t,!0);U.currentNode=s;let r=U.nextNode(),o=0,a=0,l=n[0];for(;l!==void 0;){if(o===l.index){let p;l.type===2?p=new G(r,r.nextSibling,this,e):l.type===1?p=new l.ctor(r,l.name,l.strings,this,e):l.type===6&&(p=new nt(r,this,e)),this._$AV.push(p),l=n[++a]}o!==(l==null?void 0:l.index)&&(r=U.nextNode(),o++)}return U.currentNode=F,s}p(e){let t=0;for(const n of this._$AV)n!==void 0&&(n.strings!==void 0?(n._$AI(e,n,t),t+=n.strings.length-2):n._$AI(e[t])),t++}}class G{get _$AU(){var e;return((e=this._$AM)==null?void 0:e._$AU)??this._$Cv}constructor(e,t,n,s){this.type=2,this._$AH=v,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=n,this.options=s,this._$Cv=(s==null?void 0:s.isConnected)??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(e==null?void 0:e.nodeType)===11&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=O(this,e,t),j(e)?e===v||e==null||e===""?(this._$AH!==v&&this._$AR(),this._$AH=v):e!==this._$AH&&e!==I&&this._(e):e._$litType$!==void 0?this.$(e):e.nodeType!==void 0?this.T(e):Ke(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==v&&j(this._$AH)?this._$AA.nextSibling.data=e:this.T(F.createTextNode(e)),this._$AH=e}$(e){var r;const{values:t,_$litType$:n}=e,s=typeof n=="number"?this._$AC(e):(n.el===void 0&&(n.el=B.createElement(ze(n.h,n.h[0]),this.options)),n);if(((r=this._$AH)==null?void 0:r._$AD)===s)this._$AH.p(t);else{const o=new Ze(s,this),a=o.u(this.options);o.p(t),this.T(a),this._$AH=o}}_$AC(e){let t=Fe.get(e.strings);return t===void 0&&Fe.set(e.strings,t=new B(e)),t}k(e){le(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let n,s=0;for(const r of e)s===t.length?t.push(n=new G(this.O(V()),this.O(V()),this,this.options)):n=t[s],n._$AI(r),s++;s<t.length&&(this._$AR(n&&n._$AB.nextSibling,s),t.length=s)}_$AR(e=this._$AA.nextSibling,t){var n;for((n=this._$AP)==null?void 0:n.call(this,!1,!0,t);e&&e!==this._$AB;){const s=e.nextSibling;e.remove(),e=s}}setConnected(e){var t;this._$AM===void 0&&(this._$Cv=e,(t=this._$AP)==null||t.call(this,e))}}class J{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,n,s,r){this.type=1,this._$AH=v,this._$AN=void 0,this.element=e,this.name=t,this._$AM=s,this.options=r,n.length>2||n[0]!==""||n[1]!==""?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=v}_$AI(e,t=this,n,s){const r=this.strings;let o=!1;if(r===void 0)e=O(this,e,t,0),o=!j(e)||e!==this._$AH&&e!==I,o&&(this._$AH=e);else{const a=e;let l,p;for(e=r[0],l=0;l<r.length-1;l++)p=O(this,a[n+l],t,l),p===I&&(p=this._$AH[l]),o||(o=!j(p)||p!==this._$AH[l]),p===v?e=v:e!==v&&(e+=(p??"")+r[l+1]),this._$AH[l]=p}o&&!s&&this.j(e)}j(e){e===v?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class et extends J{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===v?void 0:e}}class tt extends J{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==v)}}class it extends J{constructor(e,t,n,s,r){super(e,t,n,s,r),this.type=5}_$AI(e,t=this){if((e=O(this,e,t,0)??v)===I)return;const n=this._$AH,s=e===v&&n!==v||e.capture!==n.capture||e.once!==n.once||e.passive!==n.passive,r=e!==v&&(n===v||s);s&&this.element.removeEventListener(this.name,this,n),r&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,e):this._$AH.handleEvent(e)}}class nt{constructor(e,t,n){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=n}get _$AU(){return this._$AM._$AU}_$AI(e){O(this,e)}}const pe=H.litHtmlPolyfillSupport;pe==null||pe(B,G),(H.litHtmlVersions??(H.litHtmlVersions=[])).push("3.3.0");const st=(i,e,t)=>{const n=(t==null?void 0:t.renderBefore)??e;let s=n._$litPart$;if(s===void 0){const r=(t==null?void 0:t.renderBefore)??null;n._$litPart$=s=new G(e.insertBefore(V(),r),r,void 0,t??{})}return s._$AI(i),s};/**
16
16
  * @license
17
17
  * Copyright 2017 Google LLC
18
18
  * SPDX-License-Identifier: BSD-3-Clause
@@ -24,11 +24,11 @@
24
24
  * @license
25
25
  * Copyright 2017 Google LLC
26
26
  * SPDX-License-Identifier: BSD-3-Clause
27
- */const rt={attribute:!0,type:String,converter:q,reflect:!1,hasChanged:ae},ot=(i=rt,e,t)=>{const{kind:n,metadata:s}=t;let r=globalThis.litPropertyMetadata.get(s);if(r===void 0&&globalThis.litPropertyMetadata.set(s,r=new Map),n==="setter"&&((i=Object.create(i)).wrapped=!0),r.set(t.name,i),n==="accessor"){const{name:o}=t;return{set(a){const d=e.get.call(this);e.set.call(this,a),this.requestUpdate(o,d,i)},init(a){return a!==void 0&&this.C(o,void 0,i,a),a}}}if(n==="setter"){const{name:o}=t;return function(a){const d=this[o];e.call(this,a),this.requestUpdate(o,d,i)}}throw Error("Unsupported decorator location: "+n)};function C(i){return(e,t)=>typeof t=="object"?ot(i,e,t):((n,s,r)=>{const o=s.hasOwnProperty(r);return s.constructor.createProperty(r,n),o?Object.getOwnPropertyDescriptor(s,r):void 0})(i,e,t)}/**
27
+ */const rt={attribute:!0,type:String,converter:q,reflect:!1,hasChanged:ae},ot=(i=rt,e,t)=>{const{kind:n,metadata:s}=t;let r=globalThis.litPropertyMetadata.get(s);if(r===void 0&&globalThis.litPropertyMetadata.set(s,r=new Map),n==="setter"&&((i=Object.create(i)).wrapped=!0),r.set(t.name,i),n==="accessor"){const{name:o}=t;return{set(a){const l=e.get.call(this);e.set.call(this,a),this.requestUpdate(o,l,i)},init(a){return a!==void 0&&this.C(o,void 0,i,a),a}}}if(n==="setter"){const{name:o}=t;return function(a){const l=this[o];e.call(this,a),this.requestUpdate(o,l,i)}}throw Error("Unsupported decorator location: "+n)};function C(i){return(e,t)=>typeof t=="object"?ot(i,e,t):((n,s,r)=>{const o=s.hasOwnProperty(r);return s.constructor.createProperty(r,n),o?Object.getOwnPropertyDescriptor(s,r):void 0})(i,e,t)}/**
28
28
  * @license
29
29
  * Copyright 2017 Google LLC
30
30
  * SPDX-License-Identifier: BSD-3-Clause
31
- */function _(i){return C({...i,state:!0,attribute:!1})}const S=[];for(let i=0;i<256;++i)S.push((i+256).toString(16).slice(1));function at(i,e=0){return(S[i[e+0]]+S[i[e+1]]+S[i[e+2]]+S[i[e+3]]+"-"+S[i[e+4]]+S[i[e+5]]+"-"+S[i[e+6]]+S[i[e+7]]+"-"+S[i[e+8]]+S[i[e+9]]+"-"+S[i[e+10]]+S[i[e+11]]+S[i[e+12]]+S[i[e+13]]+S[i[e+14]]+S[i[e+15]]).toLowerCase()}let ue;const dt=new Uint8Array(16);function lt(){if(!ue){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ue=crypto.getRandomValues.bind(crypto)}return ue(dt)}const Ue={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function he(i,e,t){var s;if(Ue.randomUUID&&!i)return Ue.randomUUID();i=i||{};const n=i.random??((s=i.rng)==null?void 0:s.call(i))??lt();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,at(n)}const pt=L`
31
+ */function _(i){return C({...i,state:!0,attribute:!1})}const S=[];for(let i=0;i<256;++i)S.push((i+256).toString(16).slice(1));function at(i,e=0){return(S[i[e+0]]+S[i[e+1]]+S[i[e+2]]+S[i[e+3]]+"-"+S[i[e+4]]+S[i[e+5]]+"-"+S[i[e+6]]+S[i[e+7]]+"-"+S[i[e+8]]+S[i[e+9]]+"-"+S[i[e+10]]+S[i[e+11]]+S[i[e+12]]+S[i[e+13]]+S[i[e+14]]+S[i[e+15]]).toLowerCase()}let ue;const lt=new Uint8Array(16);function dt(){if(!ue){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ue=crypto.getRandomValues.bind(crypto)}return ue(lt)}const Ue={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function he(i,e,t){var s;if(Ue.randomUUID&&!i)return Ue.randomUUID();i=i||{};const n=i.random??((s=i.rng)==null?void 0:s.call(i))??dt();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,at(n)}const pt=L`
32
32
  :host {
33
33
  display: block;
34
34
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
@@ -2491,15 +2491,15 @@
2491
2491
  .modal-create-button:hover {
2492
2492
  background-color: #2563eb;
2493
2493
  }
2494
- `;var gt=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,E=(i,e,t,n)=>{for(var s=n>1?void 0:n?ft(e,t):e,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=(n?o(e,t,s):o(s))||s);return n&&s&&gt(e,t,s),s};let w=class extends R{constructor(){super(...arguments),this._templateData={name:"",description:"",steps:[]},this._showStepModal=!1,this._stepFormData={title:"",description:""},this._draggedStepId=null,this._dragOverStepId=null,this._selectedStepId=null,this._questions=[]}connectedCallback(){super.connectedCallback(),this._templateData=this._getDefaultWorkflowData()}_getDefaultWorkflowData(){const i={id:"step-1",title:"Step 1",description:"",order:1,assignment:{category:"individual",type:"subject"},elements:[],status:"pending"};return{id:he(),name:"",description:"",steps:[i]}}_handleTitleChange(i){const e=i.target;this._templateData={...this._templateData,name:e.value}}_handleDescriptionChange(i){const e=i.target;this._templateData={...this._templateData,description:e.value}}_handleCancel(){var i;console.log("🚫 Builder Widget: Cancel button clicked"),(i=this.onCancel)==null||i.call(this)}_handleSave(){var i,e;if((i=this._templateData.name)!=null&&i.trim()){const t={id:this._templateData.id||he(),name:this._templateData.name,description:this._templateData.description||"",steps:this._templateData.steps||[]};console.log("💾 Builder Widget: Save button clicked"),console.log("📄 Workflow Template:",JSON.stringify(t,null,2)),console.log("🔄 Calling onSave callback with workflow template"),(e=this.onSave)==null||e.call(this,t)}else console.log("⚠️ Builder Widget: Save attempted but no title provided")}_addStep(){console.log("🔹 Opening step creation modal"),this._stepFormData={title:"",description:""},this._showStepModal=!0}_closeStepModal(){console.log("🔹 Closing step creation modal"),this._showStepModal=!1,this._stepFormData={title:"",description:""}}_handleStepFormInput(i){const e=i.target,{name:t,value:n}=e;this._stepFormData={...this._stepFormData,[t]:n}}_createStep(){var t,n;if(!((t=this._stepFormData.title)!=null&&t.trim())){console.log("⚠️ Step title is required");return}const i=this._templateData.steps||[],e={id:he(),title:this._stepFormData.title.trim(),description:((n=this._stepFormData.description)==null?void 0:n.trim())||"",order:i.length+1,assignment:{category:"individual",type:"subject"},elements:[],status:"pending"};this._templateData={...this._templateData,steps:[...i,e]},this._selectedStepId=e.id,console.log("✅ Step created and selected:",e),this._closeStepModal()}_selectStep(i){this._selectedStepId=i,console.log("🎯 Step selected:",i)}_getSelectedStep(){return!this._selectedStepId||!this._templateData.steps?null:this._templateData.steps.find(i=>i.id===this._selectedStepId)||null}_handleDragStart(i,e){this._draggedStepId=e,i.dataTransfer&&(i.dataTransfer.effectAllowed="move",i.dataTransfer.setData("text/plain",e)),console.log("🔄 Drag started for step:",e)}_handleDragEnd(i){this._draggedStepId=null,this._dragOverStepId=null,console.log("🔄 Drag ended")}_handleDragOver(i,e){i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect="move"),this._dragOverStepId!==e&&(this._dragOverStepId=e)}_handleDragLeave(i){const e=i.relatedTarget;i.currentTarget.contains(e)||(this._dragOverStepId=null)}_handleDrop(i,e){if(i.preventDefault(),!this._draggedStepId||this._draggedStepId===e){this._draggedStepId=null,this._dragOverStepId=null;return}const t=this._templateData.steps||[],n=t.findIndex(a=>a.id===this._draggedStepId),s=t.findIndex(a=>a.id===e);if(n===-1||s===-1){console.error("Could not find step indices for reordering");return}console.log("🔄 Before reorder:",t.map((a,d)=>`${d+1}: ${a.title}`));const r=[...t],[o]=r.splice(n,1);r.splice(s,0,o),r.forEach((a,d)=>{a.order=d+1}),console.log("🔄 After reorder:",r.map((a,d)=>`${d+1}: ${a.title}`)),this._templateData={...this._templateData,steps:r},console.log("📝 Template updated with new step order"),this._draggedStepId=null,this._dragOverStepId=null}_addQuestion(i="text_input"){var n,s;if(!this._templateData.steps||this._templateData.steps.length===0||!this._selectedStepId){console.log("⚠️ Cannot add questions without steps or selected step");return}const e=this._getSelectedStep();if(!e){console.log("⚠️ No step selected");return}if(["text","html","divider","markdown"].includes(i)){let r={id:`c-${Date.now()}`,type:i,order:(((n=e.elements)==null?void 0:n.length)||0)+1};switch(i){case"text":r.content="Enter your text content here...";break;case"html":r.content="<p>Enter your HTML content here...</p>";break;case"divider":r.content="",r.caption="Section Divider";break;case"markdown":r.content=`## Enter your markdown content here...
2494
+ `;var gt=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,E=(i,e,t,n)=>{for(var s=n>1?void 0:n?ft(e,t):e,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=(n?o(e,t,s):o(s))||s);return n&&s&&gt(e,t,s),s};let w=class extends R{constructor(){super(...arguments),this._templateData={name:"",description:"",steps:[]},this._showStepModal=!1,this._stepFormData={title:"",description:""},this._draggedStepId=null,this._dragOverStepId=null,this._selectedStepId=null,this._questions=[]}connectedCallback(){super.connectedCallback(),this.workflow?(this._templateData={...this.workflow},this.workflow.steps&&this.workflow.steps.length>0&&(this._selectedStepId=this.workflow.steps[0].id),console.log("Builder loaded with existing workflow:",this.workflow.name)):this._templateData=this._getDefaultWorkflowData()}updated(i){i.has("workflow")&&this.workflow&&(this._templateData={...this.workflow},this.workflow.steps&&this.workflow.steps.length>0&&(this._selectedStepId=this.workflow.steps[0].id),console.log("Workflow property changed, reloading template data"))}_getDefaultWorkflowData(){const i={id:"step-1",title:"Step 1",description:"",order:1,assignment:{category:"individual",type:"subject"},elements:[],status:"pending"};return{id:he(),name:"",description:"",steps:[i]}}_handleTitleChange(i){const e=i.target;this._templateData={...this._templateData,name:e.value}}_handleDescriptionChange(i){const e=i.target;this._templateData={...this._templateData,description:e.value}}_handleCancel(){var i;console.log("🚫 Builder Widget: Cancel button clicked"),(i=this.onCancel)==null||i.call(this)}_handleSave(){var i,e,t;if((i=this._templateData.name)!=null&&i.trim()){const n={id:this._templateData.id||he(),name:this._templateData.name,description:this._templateData.description||"",steps:this._templateData.steps||[]};console.log("💾 Builder Widget: Save button clicked"),console.log("📄 Workflow Template:",JSON.stringify(n,null,2)),this.workflow?(console.log("Calling onWorkflowUpdated callback"),(e=this.onWorkflowUpdated)==null||e.call(this,n)):(console.log("Calling onWorkflowCreated callback"),(t=this.onWorkflowCreated)==null||t.call(this,n))}else console.log("⚠️ Builder Widget: Save attempted but no title provided")}_addStep(){console.log("🔹 Opening step creation modal"),this._stepFormData={title:"",description:""},this._showStepModal=!0}_closeStepModal(){console.log("🔹 Closing step creation modal"),this._showStepModal=!1,this._stepFormData={title:"",description:""}}_handleStepFormInput(i){const e=i.target,{name:t,value:n}=e;this._stepFormData={...this._stepFormData,[t]:n}}_createStep(){var t,n;if(!((t=this._stepFormData.title)!=null&&t.trim())){console.log("⚠️ Step title is required");return}const i=this._templateData.steps||[],e={id:he(),title:this._stepFormData.title.trim(),description:((n=this._stepFormData.description)==null?void 0:n.trim())||"",order:i.length+1,assignment:{category:"individual",type:"subject"},elements:[],status:"pending"};this._templateData={...this._templateData,steps:[...i,e]},this._selectedStepId=e.id,console.log("✅ Step created and selected:",e),this._closeStepModal()}_selectStep(i){this._selectedStepId=i,console.log("🎯 Step selected:",i)}_getSelectedStep(){return!this._selectedStepId||!this._templateData.steps?null:this._templateData.steps.find(i=>i.id===this._selectedStepId)||null}_handleDragStart(i,e){this._draggedStepId=e,i.dataTransfer&&(i.dataTransfer.effectAllowed="move",i.dataTransfer.setData("text/plain",e)),console.log("🔄 Drag started for step:",e)}_handleDragEnd(i){this._draggedStepId=null,this._dragOverStepId=null,console.log("🔄 Drag ended")}_handleDragOver(i,e){i.preventDefault(),i.dataTransfer&&(i.dataTransfer.dropEffect="move"),this._dragOverStepId!==e&&(this._dragOverStepId=e)}_handleDragLeave(i){const e=i.relatedTarget;i.currentTarget.contains(e)||(this._dragOverStepId=null)}_handleDrop(i,e){if(i.preventDefault(),!this._draggedStepId||this._draggedStepId===e){this._draggedStepId=null,this._dragOverStepId=null;return}const t=this._templateData.steps||[],n=t.findIndex(a=>a.id===this._draggedStepId),s=t.findIndex(a=>a.id===e);if(n===-1||s===-1){console.error("Could not find step indices for reordering");return}console.log("🔄 Before reorder:",t.map((a,l)=>`${l+1}: ${a.title}`));const r=[...t],[o]=r.splice(n,1);r.splice(s,0,o),r.forEach((a,l)=>{a.order=l+1}),console.log("🔄 After reorder:",r.map((a,l)=>`${l+1}: ${a.title}`)),this._templateData={...this._templateData,steps:r},console.log("📝 Template updated with new step order"),this._draggedStepId=null,this._dragOverStepId=null}_addQuestion(i="text_input"){var n,s;if(!this._templateData.steps||this._templateData.steps.length===0||!this._selectedStepId){console.log("⚠️ Cannot add questions without steps or selected step");return}const e=this._getSelectedStep();if(!e){console.log("⚠️ No step selected");return}if(["text","html","divider","markdown"].includes(i)){let r={id:`c-${Date.now()}`,type:i,order:(((n=e.elements)==null?void 0:n.length)||0)+1};switch(i){case"text":r.content="Enter your text content here...";break;case"html":r.content="<p>Enter your HTML content here...</p>";break;case"divider":r.content="",r.caption="Section Divider";break;case"markdown":r.content=`## Enter your markdown content here...
2495
2495
 
2496
2496
  Use **bold** and *italic* text.`;break}const o=this._templateData.steps.map(a=>a.id===this._selectedStepId?{...a,elements:[...a.elements||[],r]}:a);this._templateData={...this._templateData,steps:o},console.log("✅ Content element added to step:",this._selectedStepId)}else{const r={id:`q-${Date.now()}`,type:i,label:this._getQuestionTypeDisplayName(i),order:(((s=e.elements)==null?void 0:s.length)||0)+1,required:!1};["select","radio","checkbox"].includes(i)&&(r.options=["Option 1","Option 2"]);const o=this._templateData.steps.map(a=>a.id===this._selectedStepId?{...a,elements:[...a.elements||[],r]}:a);this._templateData={...this._templateData,steps:o},console.log("✅ Question added to step:",this._selectedStepId)}}_addContentElement(i){var s;if(!this._templateData.steps||this._templateData.steps.length===0||!this._selectedStepId){console.log("⚠️ Cannot add content without steps or selected step");return}const e=this._getSelectedStep();if(!e){console.log("⚠️ No step selected");return}let t={id:`c-${Date.now()}`,type:i,order:(((s=e.elements)==null?void 0:s.length)||0)+1};switch(i){case"text":t.content="Enter your text content here...";break;case"html":t.content="<p>Enter your HTML content here...</p>";break;case"image":t.content="",t.url="",t.alt="",t.caption="";break;case"video":t.content="",t.url="",t.caption="";break;case"file":t.content="",t.url="",t.caption="";break;case"divider":t.content="",t.caption="Section Divider";break;case"markdown":t.content=`## Enter your markdown content here...
2497
2497
 
2498
- Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r.id===this._selectedStepId?{...r,elements:[...r.elements||[],t]}:r);this._templateData={...this._templateData,steps:n},console.log("✅ Content element added to step:",this._selectedStepId)}_updateQuestion(i,e){var n;if(!this._selectedStepId)return;const t=(n=this._templateData.steps)==null?void 0:n.map(s=>{var r;return s.id===this._selectedStepId?{...s,elements:((r=s.elements)==null?void 0:r.map(o=>o.id===i?{...o,...e}:o))||[]}:s});this._templateData={...this._templateData,steps:t}}_updateContentElement(i,e){var n;if(!this._selectedStepId)return;const t=(n=this._templateData.steps)==null?void 0:n.map(s=>{var r;return s.id===this._selectedStepId?{...s,elements:((r=s.elements)==null?void 0:r.map(o=>o.id===i?{...o,...e}:o))||[]}:s});this._templateData={...this._templateData,steps:t}}_deleteQuestion(i){var t;if(!this._selectedStepId)return;const e=(t=this._templateData.steps)==null?void 0:t.map(n=>{var s;return n.id===this._selectedStepId?{...n,elements:((s=n.elements)==null?void 0:s.filter(r=>r.id!==i))||[]}:n});this._templateData={...this._templateData,steps:e},console.log("🗑️ Question deleted:",i)}_renderQuestionTypeSpecificFields(i){switch(i.type){case"select":case"radio":return l`
2498
+ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r.id===this._selectedStepId?{...r,elements:[...r.elements||[],t]}:r);this._templateData={...this._templateData,steps:n},console.log("✅ Content element added to step:",this._selectedStepId)}_updateQuestion(i,e){var n;if(!this._selectedStepId)return;const t=(n=this._templateData.steps)==null?void 0:n.map(s=>{var r;return s.id===this._selectedStepId?{...s,elements:((r=s.elements)==null?void 0:r.map(o=>o.id===i?{...o,...e}:o))||[]}:s});this._templateData={...this._templateData,steps:t}}_updateContentElement(i,e){var n;if(!this._selectedStepId)return;const t=(n=this._templateData.steps)==null?void 0:n.map(s=>{var r;return s.id===this._selectedStepId?{...s,elements:((r=s.elements)==null?void 0:r.map(o=>o.id===i?{...o,...e}:o))||[]}:s});this._templateData={...this._templateData,steps:t}}_deleteQuestion(i){var t;if(!this._selectedStepId)return;const e=(t=this._templateData.steps)==null?void 0:t.map(n=>{var s;return n.id===this._selectedStepId?{...n,elements:((s=n.elements)==null?void 0:s.filter(r=>r.id!==i))||[]}:n});this._templateData={...this._templateData,steps:e},console.log("🗑️ Question deleted:",i)}_renderQuestionTypeSpecificFields(i){switch(i.type){case"select":case"radio":return d`
2499
2499
  <div class="question-options-section">
2500
2500
  <label class="options-label">Options:</label>
2501
2501
  <div class="options-list">
2502
- ${(i.options||[]).map((e,t)=>l`
2502
+ ${(i.options||[]).map((e,t)=>d`
2503
2503
  <div class="option-item">
2504
2504
  <input
2505
2505
  type="text"
@@ -2525,7 +2525,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2525
2525
  </button>
2526
2526
  </div>
2527
2527
  </div>
2528
- `;case"checkbox":return l`
2528
+ `;case"checkbox":return d`
2529
2529
  <div class="question-checkbox-config">
2530
2530
  <div class="checkbox-type-selection">
2531
2531
  <label class="checkbox-type-label">
@@ -2550,11 +2550,11 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2550
2550
  </label>
2551
2551
  </div>
2552
2552
 
2553
- ${i.options&&i.options.length>0?l`
2553
+ ${i.options&&i.options.length>0?d`
2554
2554
  <div class="question-options-section">
2555
2555
  <label class="options-label">Checkbox Options:</label>
2556
2556
  <div class="options-list">
2557
- ${(i.options||[]).map((e,t)=>l`
2557
+ ${(i.options||[]).map((e,t)=>d`
2558
2558
  <div class="option-item">
2559
2559
  <input
2560
2560
  type="text"
@@ -2580,7 +2580,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2580
2580
  </button>
2581
2581
  </div>
2582
2582
  </div>
2583
- `:l`
2583
+ `:d`
2584
2584
  <div class="single-checkbox-info">
2585
2585
  <p class="config-note">
2586
2586
  Single checkbox - users can check/uncheck for Yes/No response
@@ -2588,7 +2588,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2588
2588
  </div>
2589
2589
  `}
2590
2590
  </div>
2591
- `;case"textarea":return l`
2591
+ `;case"textarea":return d`
2592
2592
  <div class="question-config-section">
2593
2593
  <label class="config-label">
2594
2594
  Placeholder:
@@ -2601,7 +2601,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2601
2601
  />
2602
2602
  </label>
2603
2603
  </div>
2604
- `;case"text_input":return l`
2604
+ `;case"text_input":return d`
2605
2605
  <div class="question-config-section">
2606
2606
  <label class="config-label">
2607
2607
  Placeholder:
@@ -2614,7 +2614,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2614
2614
  />
2615
2615
  </label>
2616
2616
  </div>
2617
- `;case"number":return l`
2617
+ `;case"number":return d`
2618
2618
  <div class="question-config-section">
2619
2619
  <label class="config-label">
2620
2620
  Placeholder:
@@ -2627,19 +2627,19 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2627
2627
  />
2628
2628
  </label>
2629
2629
  </div>
2630
- `;case"file_upload":return l`
2630
+ `;case"file_upload":return d`
2631
2631
  <div class="question-config-section">
2632
2632
  <p class="config-note">File upload field - users can upload files</p>
2633
2633
  </div>
2634
- `;case"signature":return l`
2634
+ `;case"signature":return d`
2635
2635
  <div class="question-config-section">
2636
2636
  <p class="config-note">Digital signature pad - users can sign with mouse/touch</p>
2637
2637
  </div>
2638
- `;case"date":return l`
2638
+ `;case"date":return d`
2639
2639
  <div class="question-config-section">
2640
2640
  <p class="config-note">Date picker field</p>
2641
2641
  </div>
2642
- `;default:return l``}}_renderContentTypeSpecificFields(i){switch(i.type){case"text":return l`
2642
+ `;default:return d``}}_renderContentTypeSpecificFields(i){switch(i.type){case"text":return d`
2643
2643
  <div class="content-config-section">
2644
2644
  <label class="config-label">
2645
2645
  Text Content:
@@ -2651,7 +2651,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2651
2651
  ></textarea>
2652
2652
  </label>
2653
2653
  </div>
2654
- `;case"html":return l`
2654
+ `;case"html":return d`
2655
2655
  <div class="content-config-section">
2656
2656
  <label class="config-label">
2657
2657
  HTML Content:
@@ -2663,7 +2663,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2663
2663
  ></textarea>
2664
2664
  </label>
2665
2665
  </div>
2666
- `;case"image":return l`
2666
+ `;case"image":return d`
2667
2667
  <div class="content-config-section">
2668
2668
  <label class="config-label">
2669
2669
  Image URL:
@@ -2696,7 +2696,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2696
2696
  />
2697
2697
  </label>
2698
2698
  </div>
2699
- `;case"video":return l`
2699
+ `;case"video":return d`
2700
2700
  <div class="content-config-section">
2701
2701
  <label class="config-label">
2702
2702
  Video URL:
@@ -2719,7 +2719,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2719
2719
  />
2720
2720
  </label>
2721
2721
  </div>
2722
- `;case"file":return l`
2722
+ `;case"file":return d`
2723
2723
  <div class="content-config-section">
2724
2724
  <label class="config-label">
2725
2725
  File URL:
@@ -2742,7 +2742,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2742
2742
  />
2743
2743
  </label>
2744
2744
  </div>
2745
- `;case"divider":return l`
2745
+ `;case"divider":return d`
2746
2746
  <div class="content-config-section">
2747
2747
  <label class="config-label">
2748
2748
  Caption:
@@ -2755,7 +2755,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2755
2755
  />
2756
2756
  </label>
2757
2757
  </div>
2758
- `;case"markdown":return l`
2758
+ `;case"markdown":return d`
2759
2759
  <div class="content-config-section">
2760
2760
  <label class="config-label">
2761
2761
  Markdown Content:
@@ -2767,7 +2767,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2767
2767
  ></textarea>
2768
2768
  </label>
2769
2769
  </div>
2770
- `;default:return l``}}_getQuestionTypeDisplayName(i){switch(i){case"text_input":return"Text Input";case"textarea":return"Long Text";case"select":return"Select";case"radio":return"Radio";case"checkbox":return"Checkbox";case"number":return"Number";case"date":return"Date";case"file_upload":return"File Upload";case"signature":return"Signature";default:return"Question"}}_getContentTypeDisplayName(i){switch(i){case"text":return"Text";case"html":return"HTML";case"image":return"Image";case"video":return"Video";case"file":return"File";case"divider":return"Divider";case"markdown":return"Markdown";default:return"Content"}}_getCheckboxTypeDisplayName(i){return i.options&&i.options.length>0?"Checkbox Group":"Single Checkbox"}_hasSteps(){const i=!!(this._templateData.steps&&this._templateData.steps.length>0);return i&&!this._selectedStepId&&this._templateData.steps&&(this._selectedStepId=this._templateData.steps[0].id,console.log("🎯 Auto-selected first step:",this._templateData.steps[0].title)),!i&&this._selectedStepId&&(this._selectedStepId=null),i}_getAssignmentDisplayText(i){switch(i.category){case"individual":switch(i.type){case"subject":return"Assigned to: Subject";case"creator":return"Assigned to: Creator";case"instance_assignee_select":return"Assigned to: To be selected";case"specific_user":return i.email?`Assigned to: ${i.email}`:"Assigned to: Specific user";default:return"Assigned to: Individual"}case"role":switch(i.type){case"instance_role_assignee_select":return i.targetId?`Assigned to: ${i.targetId} role`:"Assigned to: Role";default:return"Assigned to: Role"}default:return"Assignment not configured"}}render(){const i=this._getSelectedStep();return l`
2770
+ `;default:return d``}}_getQuestionTypeDisplayName(i){switch(i){case"text_input":return"Text Input";case"textarea":return"Long Text";case"select":return"Select";case"radio":return"Radio";case"checkbox":return"Checkbox";case"number":return"Number";case"date":return"Date";case"file_upload":return"File Upload";case"signature":return"Signature";default:return"Question"}}_getContentTypeDisplayName(i){switch(i){case"text":return"Text";case"html":return"HTML";case"image":return"Image";case"video":return"Video";case"file":return"File";case"divider":return"Divider";case"markdown":return"Markdown";default:return"Content"}}_getCheckboxTypeDisplayName(i){return i.options&&i.options.length>0?"Checkbox Group":"Single Checkbox"}_hasSteps(){const i=!!(this._templateData.steps&&this._templateData.steps.length>0);return i&&!this._selectedStepId&&this._templateData.steps&&(this._selectedStepId=this._templateData.steps[0].id,console.log("🎯 Auto-selected first step:",this._templateData.steps[0].title)),!i&&this._selectedStepId&&(this._selectedStepId=null),i}_showStepMenu(i,e){i.stopPropagation(),console.log("Step menu for:",e),confirm("Delete this step?")&&this._deleteStep(e)}_deleteStep(i){if(!confirm("Are you sure you want to delete this step?"))return;const e=(this._templateData.steps||[]).filter(t=>t.id!==i);e.forEach((t,n)=>{t.order=n+1}),this._templateData={...this._templateData,steps:e},this._selectedStepId===i&&(this._selectedStepId=e.length>0?e[0].id:null),console.log("Step deleted:",i)}_getAssignmentDisplayText(i){switch(i.category){case"individual":switch(i.type){case"subject":return"Assigned to: Subject";case"creator":return"Assigned to: Creator";case"instance_assignee_select":return"Assigned to: To be selected";case"specific_user":return i.email?`Assigned to: ${i.email}`:"Assigned to: Specific user";default:return"Assigned to: Individual"}case"role":switch(i.type){case"instance_role_assignee_select":return i.targetId?`Assigned to: ${i.targetId} role`:"Assigned to: Role";default:return"Assigned to: Role"}default:return"Assignment not configured"}}render(){var e;const i=this._getSelectedStep();return d`
2771
2771
  <div class="header">
2772
2772
  <div class="header-inputs">
2773
2773
  <div class="form-group">
@@ -2807,15 +2807,45 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2807
2807
  </div>
2808
2808
 
2809
2809
  <div class="steps-list">
2810
- <div class="step-item selected" @click=${()=>this._selectStep("step-1")}>
2811
- <div class="step-handle">⋮⋮</div>
2812
- <div class="step-content">
2813
- <strong>Step 1</strong>
2814
- </div>
2815
- <div class="step-actions">
2816
- <button class="step-menu">⋯</button>
2817
- </div>
2818
- </div>
2810
+ ${((e=this._templateData.steps)==null?void 0:e.map(t=>d`
2811
+ <div
2812
+ class="step-item ${this._selectedStepId===t.id?"selected":""} ${this._dragOverStepId===t.id?"drag-over":""}"
2813
+ @click=${()=>this._selectStep(t.id)}
2814
+ draggable="true"
2815
+ @dragstart=${n=>this._handleDragStart(n,t.id)}
2816
+ @dragend=${this._handleDragEnd}
2817
+ @dragover=${n=>this._handleDragOver(n,t.id)}
2818
+ @dragleave=${this._handleDragLeave}
2819
+ @drop=${n=>this._handleDrop(n,t.id)}
2820
+ >
2821
+ <div class="step-handle">
2822
+ <svg
2823
+ width="16"
2824
+ height="16"
2825
+ viewBox="0 0 16 16"
2826
+ fill="none"
2827
+ stroke="currentColor"
2828
+ stroke-width="2"
2829
+ >
2830
+ <line x1="4" y1="4" x2="12" y2="4" />
2831
+ <line x1="4" y1="8" x2="12" y2="8" />
2832
+ <line x1="4" y1="12" x2="12" y2="12" />
2833
+ </svg>
2834
+ </div>
2835
+ <div class="step-content">
2836
+ <strong>${t.title}</strong>
2837
+ <small>${this._getAssignmentDisplayText(t.assignment)}</small>
2838
+ </div>
2839
+ <div class="step-actions">
2840
+ <button
2841
+ class="step-menu"
2842
+ @click=${n=>{n.stopPropagation(),this._showStepMenu(n,t.id)}}
2843
+ >
2844
+
2845
+ </button>
2846
+ </div>
2847
+ </div>
2848
+ `))||[]}
2819
2849
  </div>
2820
2850
  </div>
2821
2851
 
@@ -2826,20 +2856,20 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2826
2856
  <button class="add-button" @click=${()=>this._addQuestion()}>Add</button>
2827
2857
  </div>
2828
2858
 
2829
- ${i&&i.elements&&i.elements.length>0?l`
2859
+ ${i&&i.elements&&i.elements.length>0?d`
2830
2860
  <div class="elements-list">
2831
- ${i.elements.map(e=>{const t="label"in e&&"required"in e,n="content"in e;if(t){const s=e;return l`
2861
+ ${i.elements.map(t=>{const n="label"in t&&"required"in t,s="content"in t;if(n){const r=t;return d`
2832
2862
  <div class="question-item">
2833
2863
  <div class="question-header">
2834
2864
  <h3 class="question-title">
2835
- ${s.label||(s.type==="checkbox"?this._getCheckboxTypeDisplayName(s):this._getQuestionTypeDisplayName(s.type))}
2865
+ ${r.label||(r.type==="checkbox"?this._getCheckboxTypeDisplayName(r):this._getQuestionTypeDisplayName(r.type))}
2836
2866
  </h3>
2837
2867
  <div class="question-header-controls">
2838
2868
  <select
2839
2869
  class="question-type-select"
2840
- .value=${s.type||"text_input"}
2870
+ .value=${r.type||"text_input"}
2841
2871
  style="color: #000 !important;"
2842
- @change=${r=>{const a=r.target.value;if(["text","html","divider","markdown"].includes(a)){this._addQuestion(a),this._deleteQuestion(s.id);return}const p={type:a};["select","radio","checkbox"].includes(a)&&!s.options&&(p.options=["Option 1","Option 2"]);const c=this._getQuestionTypeDisplayName(s.type);(!s.label||s.label===c)&&(p.label=this._getQuestionTypeDisplayName(a)),this._updateQuestion(s.id,p)}}
2872
+ @change=${o=>{const l=o.target.value;if(["text","html","divider","markdown"].includes(l)){this._addQuestion(l),this._deleteQuestion(r.id);return}const c={type:l};["select","radio","checkbox"].includes(l)&&!r.options&&(c.options=["Option 1","Option 2"]);const u=this._getQuestionTypeDisplayName(r.type);(!r.label||r.label===u)&&(c.label=this._getQuestionTypeDisplayName(l)),this._updateQuestion(r.id,c)}}
2843
2873
  >
2844
2874
  <optgroup label="Questions">
2845
2875
  <option value="text_input">Text Input (short)</option>
@@ -2861,7 +2891,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2861
2891
  </select>
2862
2892
  <button
2863
2893
  class="delete-question-button"
2864
- @click=${()=>this._deleteQuestion(s.id)}
2894
+ @click=${()=>this._deleteQuestion(r.id)}
2865
2895
  title="Delete question"
2866
2896
  >
2867
2897
  🗑️
@@ -2873,33 +2903,33 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2873
2903
  type="text"
2874
2904
  class="question-label-input"
2875
2905
  placeholder="Question label"
2876
- .value=${s.label||""}
2877
- @input=${r=>{const o=r.target;this._updateQuestion(s.id,{label:o.value}),this.requestUpdate()}}
2906
+ .value=${r.label||""}
2907
+ @input=${o=>{const a=o.target;this._updateQuestion(r.id,{label:a.value}),this.requestUpdate()}}
2878
2908
  />
2879
2909
 
2880
- ${this._renderQuestionTypeSpecificFields(s)}
2910
+ ${this._renderQuestionTypeSpecificFields(r)}
2881
2911
 
2882
2912
  <label class="question-required-label">
2883
2913
  <input
2884
2914
  type="checkbox"
2885
- .checked=${s.required||!1}
2886
- @change=${r=>{const o=r.target;this._updateQuestion(s.id,{required:o.checked})}}
2915
+ .checked=${r.required||!1}
2916
+ @change=${o=>{const a=o.target;this._updateQuestion(r.id,{required:a.checked})}}
2887
2917
  />
2888
2918
  Required
2889
2919
  </label>
2890
2920
  </div>
2891
- `}else if(n){const s=e;return l`
2921
+ `}else if(s){const r=t;return d`
2892
2922
  <div class="question-item">
2893
2923
  <div class="question-header">
2894
2924
  <h3 class="question-title">
2895
- ${this._getContentTypeDisplayName(s.type)}
2925
+ ${this._getContentTypeDisplayName(r.type)}
2896
2926
  </h3>
2897
2927
  <div class="question-header-controls">
2898
2928
  <select
2899
2929
  class="question-type-select"
2900
- .value=${e.type||"text"}
2930
+ .value=${t.type||"text"}
2901
2931
  style="color: #000 !important;"
2902
- @change=${r=>{const a=r.target.value;if(!["text","html","divider","markdown"].includes(a)){this._addQuestion(a),this._deleteQuestion(e.id);return}this._addQuestion(a),this._deleteQuestion(e.id)}}
2932
+ @change=${o=>{const l=o.target.value;if(!["text","html","divider","markdown"].includes(l)){this._addQuestion(l),this._deleteQuestion(t.id);return}this._addQuestion(l),this._deleteQuestion(t.id)}}
2903
2933
  >
2904
2934
  <optgroup label="Questions">
2905
2935
  <option value="text_input">Text Input (short)</option>
@@ -2921,7 +2951,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2921
2951
  </select>
2922
2952
  <button
2923
2953
  class="delete-question-button"
2924
- @click=${()=>this._deleteQuestion(e.id)}
2954
+ @click=${()=>this._deleteQuestion(t.id)}
2925
2955
  title="Delete content"
2926
2956
  >
2927
2957
 
@@ -2929,17 +2959,17 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2929
2959
  </div>
2930
2960
  </div>
2931
2961
  <div class="question-content">
2932
- ${this._renderContentTypeSpecificFields(s)}
2962
+ ${this._renderContentTypeSpecificFields(r)}
2933
2963
  </div>
2934
2964
  </div>
2935
- `}else{const s=e;return l`
2965
+ `}else{const r=t;return d`
2936
2966
  <div class="question-item">
2937
2967
  <div class="question-header">
2938
2968
  <h3 class="question-title">Unknown Element</h3>
2939
2969
  <div class="question-header-controls">
2940
2970
  <button
2941
2971
  class="delete-question-button"
2942
- @click=${()=>this._deleteQuestion(s.id)}
2972
+ @click=${()=>this._deleteQuestion(r.id)}
2943
2973
  title="Delete element"
2944
2974
  >
2945
2975
 
@@ -2949,7 +2979,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2949
2979
  </div>
2950
2980
  `}})}
2951
2981
  </div>
2952
- `:l`
2982
+ `:d`
2953
2983
  <div class="empty-state">
2954
2984
  <h3>Add questions</h3>
2955
2985
  <p>Use the add button to start building your workflow</p>
@@ -2965,21 +2995,21 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2965
2995
  ${ut}
2966
2996
  ${Pe}
2967
2997
  ${ht}
2968
- `,E([_()],w.prototype,"_templateData",2),E([_()],w.prototype,"_showStepModal",2),E([_()],w.prototype,"_stepFormData",2),E([_()],w.prototype,"_draggedStepId",2),E([_()],w.prototype,"_dragOverStepId",2),E([_()],w.prototype,"_selectedStepId",2),E([_()],w.prototype,"_questions",2),E([C({attribute:!1})],w.prototype,"onCancel",2),E([C({attribute:!1})],w.prototype,"onSave",2),w=E([Ie("builder-widget")],w);class mt{constructor(e,t){this.signaturePads=e,this.savedSignatures=t}validateStep(e,t,n){if(n==="preview")return{isValid:!0,errors:{}};if(!e)return{isValid:!1,errors:{}};let s=!0;const r={};for(const o of e.elements)if(this.isQuestionElement(o)){const a=o;if(a.required){const d=this.validateQuestion(a,t[a.id]);d&&(s=!1,r[a.id]=d.message)}}return{isValid:s,errors:r}}validateQuestion(e,t){switch(e.type){case"checkbox":return this.validateCheckbox(e,t);case"signature":return this.validateSignature(e,t);case"file_upload":return this.validateFileUpload(e,t);default:return this.validateBasicField(e,t)}}validateCheckbox(e,t){if(e.options&&e.options.length>0){if(!Array.isArray(t)||t.length===0)return{questionId:e.id,message:`${e.label} is required.`}}else if(t!==!0)return{questionId:e.id,message:`${e.label} is required.`};return null}validateSignature(e,t){const n=this.signaturePads.get(e.id);return!n||n.isEmpty()?{questionId:e.id,message:`${e.label} is required.`}:this.savedSignatures.has(e.id)?null:{questionId:e.id,message:`Please save your ${e.label} before continuing.`}}validateFileUpload(e,t){return!t||t===null||t===void 0?{questionId:e.id,message:`${e.label} is required.`}:null}validateBasicField(e,t){return t==null||t===""?{questionId:e.id,message:`${e.label} is required.`}:null}isQuestionElement(e){return["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"].includes(e.type)}}class bt{getStorageKey(e){return`runner-form-data-${e||"default"}`}saveFormData(e,t,n,s,r,o){var c,u,h;const a=this.getStorageKey(e),d=o?{...o,currentStepId:(u=(c=o.steps)==null?void 0:c[n])==null?void 0:u.id,completedSteps:Array.from(r),updatedAt:new Date,steps:(h=o.steps)==null?void 0:h.map(f=>({...f,responses:f.responses||[]}))}:null,p={formData:t,timestamp:new Date().toISOString(),stepIndex:n,savedSignatures:Array.from(s),completedSteps:Array.from(r),instance:d};try{localStorage.setItem(a,JSON.stringify(p))}catch(f){console.warn("Failed to save form data to localStorage:",f)}}restoreFormData(e){const t=this.getStorageKey(e);try{const n=localStorage.getItem(t);if(!n)return null;const s=JSON.parse(n);return{formData:s.formData||{},stepIndex:s.stepIndex||0,savedSignatures:new Set(s.savedSignatures||[]),completedSteps:new Set(s.completedSteps||[]),savedInstance:s.instance||null}}catch(n){return console.warn("Failed to restore form data from localStorage:",n),null}}clearFormData(e,t="completed workflow"){const n=this.getStorageKey(e);try{localStorage.removeItem(n),console.log(`Cleared saved form data for ${t}`)}catch(s){console.warn("Failed to clear saved form data:",s)}}shouldRestoreData(e){return e==="default"}}/*!
2998
+ `,E([_()],w.prototype,"_templateData",2),E([_()],w.prototype,"_showStepModal",2),E([_()],w.prototype,"_stepFormData",2),E([_()],w.prototype,"_draggedStepId",2),E([_()],w.prototype,"_dragOverStepId",2),E([_()],w.prototype,"_selectedStepId",2),E([_()],w.prototype,"_questions",2),E([C({attribute:!1})],w.prototype,"onCancel",2),E([C({attribute:!1})],w.prototype,"workflow",2),w=E([Ie("builder-widget")],w);class mt{constructor(e,t){this.signaturePads=e,this.savedSignatures=t}validateStep(e,t,n){if(n==="preview")return{isValid:!0,errors:{}};if(!e)return{isValid:!1,errors:{}};let s=!0;const r={};for(const o of e.elements)if(this.isQuestionElement(o)){const a=o;if(a.required){const l=this.validateQuestion(a,t[a.id]);l&&(s=!1,r[a.id]=l.message)}}return{isValid:s,errors:r}}validateQuestion(e,t){switch(e.type){case"checkbox":return this.validateCheckbox(e,t);case"signature":return this.validateSignature(e,t);case"file_upload":return this.validateFileUpload(e,t);default:return this.validateBasicField(e,t)}}validateCheckbox(e,t){if(e.options&&e.options.length>0){if(!Array.isArray(t)||t.length===0)return{questionId:e.id,message:`${e.label} is required.`}}else if(t!==!0)return{questionId:e.id,message:`${e.label} is required.`};return null}validateSignature(e,t){const n=this.signaturePads.get(e.id);return!n||n.isEmpty()?{questionId:e.id,message:`${e.label} is required.`}:this.savedSignatures.has(e.id)?null:{questionId:e.id,message:`Please save your ${e.label} before continuing.`}}validateFileUpload(e,t){return!t||t===null||t===void 0?{questionId:e.id,message:`${e.label} is required.`}:null}validateBasicField(e,t){return t==null||t===""?{questionId:e.id,message:`${e.label} is required.`}:null}isQuestionElement(e){return["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"].includes(e.type)}}class bt{getStorageKey(e){return`runner-form-data-${e||"default"}`}saveFormData(e,t,n,s,r,o){var c,u,h;const a=this.getStorageKey(e),l=o?{...o,currentStepId:(u=(c=o.steps)==null?void 0:c[n])==null?void 0:u.id,completedSteps:Array.from(r),updatedAt:new Date,steps:(h=o.steps)==null?void 0:h.map(f=>({...f,responses:f.responses||[]}))}:null,p={formData:t,timestamp:new Date().toISOString(),stepIndex:n,savedSignatures:Array.from(s),completedSteps:Array.from(r),instance:l};try{localStorage.setItem(a,JSON.stringify(p))}catch(f){console.warn("Failed to save form data to localStorage:",f)}}restoreFormData(e){const t=this.getStorageKey(e);try{const n=localStorage.getItem(t);if(!n)return null;const s=JSON.parse(n);return{formData:s.formData||{},stepIndex:s.stepIndex||0,savedSignatures:new Set(s.savedSignatures||[]),completedSteps:new Set(s.completedSteps||[]),savedInstance:s.instance||null}}catch(n){return console.warn("Failed to restore form data from localStorage:",n),null}}clearFormData(e,t="completed workflow"){const n=this.getStorageKey(e);try{localStorage.removeItem(n),console.log(`Cleared saved form data for ${t}`)}catch(s){console.warn("Failed to clear saved form data:",s)}}shouldRestoreData(e){return e==="default"}}/*!
2969
2999
  * Signature Pad v5.0.10 | https://github.com/szimek/signature_pad
2970
3000
  * (c) 2025 Szymon Nowak | Released under the MIT license
2971
- */class X{constructor(e,t,n,s){if(isNaN(e)||isNaN(t))throw new Error(`Point is invalid: (${e}, ${t})`);this.x=+e,this.y=+t,this.pressure=n||0,this.time=s||Date.now()}distanceTo(e){return Math.sqrt(Math.pow(this.x-e.x,2)+Math.pow(this.y-e.y,2))}equals(e){return this.x===e.x&&this.y===e.y&&this.pressure===e.pressure&&this.time===e.time}velocityFrom(e){return this.time!==e.time?this.distanceTo(e)/(this.time-e.time):0}}class ge{static fromPoints(e,t){const n=this.calculateControlPoints(e[0],e[1],e[2]).c2,s=this.calculateControlPoints(e[1],e[2],e[3]).c1;return new ge(e[1],n,s,e[2],t.start,t.end)}static calculateControlPoints(e,t,n){const s=e.x-t.x,r=e.y-t.y,o=t.x-n.x,a=t.y-n.y,d={x:(e.x+t.x)/2,y:(e.y+t.y)/2},p={x:(t.x+n.x)/2,y:(t.y+n.y)/2},c=Math.sqrt(s*s+r*r),u=Math.sqrt(o*o+a*a),h=d.x-p.x,f=d.y-p.y,b=c+u==0?0:u/(c+u),$={x:p.x+h*b,y:p.y+f*b},ie=t.x-$.x,ne=t.y-$.y;return{c1:new X(d.x+ie,d.y+ne),c2:new X(p.x+ie,p.y+ne)}}constructor(e,t,n,s,r,o){this.startPoint=e,this.control2=t,this.control1=n,this.endPoint=s,this.startWidth=r,this.endWidth=o}length(){let t=0,n,s;for(let r=0;r<=10;r+=1){const o=r/10,a=this.point(o,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),d=this.point(o,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(r>0){const p=a-n,c=d-s;t+=Math.sqrt(p*p+c*c)}n=a,s=d}return t}point(e,t,n,s,r){return t*(1-e)*(1-e)*(1-e)+3*n*(1-e)*(1-e)*e+3*s*(1-e)*e*e+r*e*e*e}}class vt{constructor(){try{this._et=new EventTarget}catch{this._et=document}}addEventListener(e,t,n){this._et.addEventListener(e,t,n)}dispatchEvent(e){return this._et.dispatchEvent(e)}removeEventListener(e,t,n){this._et.removeEventListener(e,t,n)}}function xt(i,e=250){let t=0,n=null,s,r,o;const a=()=>{t=Date.now(),n=null,s=i.apply(r,o),n||(r=null,o=[])};return function(...p){const c=Date.now(),u=e-(c-t);return r=this,o=p,u<=0||u>e?(n&&(clearTimeout(n),n=null),t=c,s=i.apply(r,o),n||(r=null,o=[])):n||(n=window.setTimeout(a,u)),s}}class Z extends vt{constructor(e,t={}){var n,s,r;super(),this.canvas=e,this._drawingStroke=!1,this._isEmpty=!0,this._lastPoints=[],this._data=[],this._lastVelocity=0,this._lastWidth=0,this.velocityFilterWeight=t.velocityFilterWeight||.7,this.minWidth=t.minWidth||.5,this.maxWidth=t.maxWidth||2.5,this.throttle=(n=t.throttle)!==null&&n!==void 0?n:16,this.minDistance=(s=t.minDistance)!==null&&s!==void 0?s:5,this.dotSize=t.dotSize||0,this.penColor=t.penColor||"black",this.backgroundColor=t.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=t.compositeOperation||"source-over",this.canvasContextOptions=(r=t.canvasContextOptions)!==null&&r!==void 0?r:{},this._strokeMoveUpdate=this.throttle?xt(Z.prototype._strokeUpdate,this.throttle):Z.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._ctx=e.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){const{_ctx:e,canvas:t}=this;e.fillStyle=this.backgroundColor,e.clearRect(0,0,t.width,t.height),e.fillRect(0,0,t.width,t.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._strokePointerId=void 0}fromDataURL(e,t={}){return new Promise((n,s)=>{const r=new Image,o=t.ratio||window.devicePixelRatio||1,a=t.width||this.canvas.width/o,d=t.height||this.canvas.height/o,p=t.xOffset||0,c=t.yOffset||0;this._reset(this._getPointGroupOptions()),r.onload=()=>{this._ctx.drawImage(r,p,c,a,d),n()},r.onerror=u=>{s(u)},r.crossOrigin="anonymous",r.src=e,this._isEmpty=!1})}toDataURL(e="image/png",t){switch(e){case"image/svg+xml":return typeof t!="object"&&(t=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;default:return typeof t!="number"&&(t=void 0),this.canvas.toDataURL(e,t)}}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none";const e=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!e?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){var e;const t=window.document===this.canvas.ownerDocument?window:(e=this.canvas.ownerDocument.defaultView)!==null&&e!==void 0?e:this.canvas.ownerDocument;return{addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}_removeMoveUpEventListeners(){const{removeEventListener:e}=this._getListenerFunctions();e("pointermove",this._handlePointerMove),e("pointerup",this._handlePointerUp),e("mousemove",this._handleMouseMove),e("mouseup",this._handleMouseUp),e("touchmove",this._handleTouchMove),e("touchend",this._handleTouchEnd)}isEmpty(){return this._isEmpty}fromData(e,{clear:t=!0}={}){t&&this.clear(),this._fromData(e,this._drawCurve.bind(this),this._drawDot.bind(this)),this._data=this._data.concat(e)}toData(){return this._data}_isLeftButtonPressed(e,t){return t?e.buttons===1:(e.buttons&1)===1}_pointerEventToSignatureEvent(e){return{event:e,type:e.type,x:e.clientX,y:e.clientY,pressure:"pressure"in e?e.pressure:0}}_touchEventToSignatureEvent(e){const t=e.changedTouches[0];return{event:e,type:e.type,x:t.clientX,y:t.clientY,pressure:t.force}}_handleMouseDown(e){!this._isLeftButtonPressed(e,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(e))}_handleMouseMove(e){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}_handleMouseUp(e){this._isLeftButtonPressed(e)||this._strokeEnd(this._pointerEventToSignatureEvent(e))}_handleTouchStart(e){e.targetTouches.length!==1||this._drawingStroke||(e.cancelable&&e.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(e)))}_handleTouchMove(e){if(e.targetTouches.length===1){if(e.cancelable&&e.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(e))}}_handleTouchEnd(e){e.targetTouches.length===0&&(e.cancelable&&e.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(e)))}_getPointerId(e){return e.persistentDeviceId||e.pointerId}_allowPointerId(e,t=!1){return typeof this._strokePointerId>"u"?t:this._getPointerId(e)===this._strokePointerId}_handlePointerDown(e){this._drawingStroke||!this._isLeftButtonPressed(e)||!this._allowPointerId(e,!0)||(this._strokePointerId=this._getPointerId(e),e.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(e)))}_handlePointerMove(e){if(this._allowPointerId(e)){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}e.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}}_handlePointerUp(e){this._isLeftButtonPressed(e)||!this._allowPointerId(e)||(e.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(e)))}_getPointGroupOptions(e){return{penColor:e&&"penColor"in e?e.penColor:this.penColor,dotSize:e&&"dotSize"in e?e.dotSize:this.dotSize,minWidth:e&&"minWidth"in e?e.minWidth:this.minWidth,maxWidth:e&&"maxWidth"in e?e.maxWidth:this.maxWidth,velocityFilterWeight:e&&"velocityFilterWeight"in e?e.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:e&&"compositeOperation"in e?e.compositeOperation:this.compositeOperation}}_strokeBegin(e){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:e,cancelable:!0})))return;const{addEventListener:n}=this._getListenerFunctions();switch(e.event.type){case"mousedown":n("mousemove",this._handleMouseMove,{passive:!1}),n("mouseup",this._handleMouseUp,{passive:!1});break;case"touchstart":n("touchmove",this._handleTouchMove,{passive:!1}),n("touchend",this._handleTouchEnd,{passive:!1});break;case"pointerdown":n("pointermove",this._handlePointerMove,{passive:!1}),n("pointerup",this._handlePointerUp,{passive:!1});break}this._drawingStroke=!0;const s=this._getPointGroupOptions(),r=Object.assign(Object.assign({},s),{points:[]});this._data.push(r),this._reset(s),this._strokeUpdate(e)}_strokeUpdate(e){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(e);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:e}));const t=this._createPoint(e.x,e.y,e.pressure),n=this._data[this._data.length-1],s=n.points,r=s.length>0&&s[s.length-1],o=r?t.distanceTo(r)<=this.minDistance:!1,a=this._getPointGroupOptions(n);if(!r||!(r&&o)){const d=this._addPoint(t,a);r?d&&this._drawCurve(d,a):this._drawDot(t,a),s.push({time:t.time,x:t.x,y:t.y,pressure:t.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:e}))}_strokeEnd(e,t=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(t&&this._strokeUpdate(e),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent("endStroke",{detail:e})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart,{passive:!1})}_reset(e){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(e.minWidth+e.maxWidth)/2,this._ctx.fillStyle=e.penColor,this._ctx.globalCompositeOperation=e.compositeOperation}_createPoint(e,t,n){const s=this.canvas.getBoundingClientRect();return new X(e-s.left,t-s.top,n,new Date().getTime())}_addPoint(e,t){const{_lastPoints:n}=this;if(n.push(e),n.length>2){n.length===3&&n.unshift(n[0]);const s=this._calculateCurveWidths(n[1],n[2],t),r=ge.fromPoints(n,s);return n.shift(),r}return null}_calculateCurveWidths(e,t,n){const s=n.velocityFilterWeight*t.velocityFrom(e)+(1-n.velocityFilterWeight)*this._lastVelocity,r=this._strokeWidth(s,n),o={end:r,start:this._lastWidth};return this._lastVelocity=s,this._lastWidth=r,o}_strokeWidth(e,t){return Math.max(t.maxWidth/(e+1),t.minWidth)}_drawCurveSegment(e,t,n){const s=this._ctx;s.moveTo(e,t),s.arc(e,t,n,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(e,t){const n=this._ctx,s=e.endWidth-e.startWidth,r=Math.ceil(e.length())*2;n.beginPath(),n.fillStyle=t.penColor;for(let o=0;o<r;o+=1){const a=o/r,d=a*a,p=d*a,c=1-a,u=c*c,h=u*c;let f=h*e.startPoint.x;f+=3*u*a*e.control1.x,f+=3*c*d*e.control2.x,f+=p*e.endPoint.x;let b=h*e.startPoint.y;b+=3*u*a*e.control1.y,b+=3*c*d*e.control2.y,b+=p*e.endPoint.y;const $=Math.min(e.startWidth+p*s,t.maxWidth);this._drawCurveSegment(f,b,$)}n.closePath(),n.fill()}_drawDot(e,t){const n=this._ctx,s=t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2;n.beginPath(),this._drawCurveSegment(e.x,e.y,s),n.closePath(),n.fillStyle=t.penColor,n.fill()}_fromData(e,t,n){for(const s of e){const{points:r}=s,o=this._getPointGroupOptions(s);if(r.length>1)for(let a=0;a<r.length;a+=1){const d=r[a],p=new X(d.x,d.y,d.pressure,d.time);a===0&&this._reset(o);const c=this._addPoint(p,o);c&&t(c,o)}else this._reset(o),n(r[0],o)}}toSVG({includeBackgroundColor:e=!1}={}){const t=this._data,n=Math.max(window.devicePixelRatio||1,1),s=0,r=0,o=this.canvas.width/n,a=this.canvas.height/n,d=document.createElementNS("http://www.w3.org/2000/svg","svg");if(d.setAttribute("xmlns","http://www.w3.org/2000/svg"),d.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),d.setAttribute("viewBox",`${s} ${r} ${o} ${a}`),d.setAttribute("width",o.toString()),d.setAttribute("height",a.toString()),e&&this.backgroundColor){const p=document.createElement("rect");p.setAttribute("width","100%"),p.setAttribute("height","100%"),p.setAttribute("fill",this.backgroundColor),d.appendChild(p)}return this._fromData(t,(p,{penColor:c})=>{const u=document.createElement("path");if(!isNaN(p.control1.x)&&!isNaN(p.control1.y)&&!isNaN(p.control2.x)&&!isNaN(p.control2.y)){const h=`M ${p.startPoint.x.toFixed(3)},${p.startPoint.y.toFixed(3)} C ${p.control1.x.toFixed(3)},${p.control1.y.toFixed(3)} ${p.control2.x.toFixed(3)},${p.control2.y.toFixed(3)} ${p.endPoint.x.toFixed(3)},${p.endPoint.y.toFixed(3)}`;u.setAttribute("d",h),u.setAttribute("stroke-width",(p.endWidth*2.25).toFixed(3)),u.setAttribute("stroke",c),u.setAttribute("fill","none"),u.setAttribute("stroke-linecap","round"),d.appendChild(u)}},(p,{penColor:c,dotSize:u,minWidth:h,maxWidth:f})=>{const b=document.createElement("circle"),$=u>0?u:(h+f)/2;b.setAttribute("r",$.toString()),b.setAttribute("cx",p.x.toString()),b.setAttribute("cy",p.y.toString()),b.setAttribute("fill",c),d.appendChild(b)}),d.outerHTML}}class _t{constructor(e){this.signaturePads=new Map,this.canvasElements=new Map,this.onSignatureChange=e}initializeSignaturePad(e,t){const n=t==null?void 0:t.getElementById(`signature-${e}`);if(!n)return null;this.clearSignaturePad(e),this.resizeCanvas(n);const s=new Z(n,{backgroundColor:"rgb(255, 255, 255)",penColor:"rgb(0, 0, 0)",minWidth:.5,maxWidth:2.5});return this.signaturePads.set(e,s),this.canvasElements.set(e,n),s.addEventListener("endStroke",()=>{this.handleSignatureChange(e)}),s}handleSignatureChange(e){var r;const t=this.signaturePads.get(e);if(!t)return;const n=!t.isEmpty(),s=n?t.toData():null;(r=this.onSignatureChange)==null||r.call(this,{questionId:e,hasSignature:n,signatureData:s})}clearSignature(e){const t=this.signaturePads.get(e);t&&(t.clear(),this.handleSignatureChange(e))}saveSignature(e){const t=this.signaturePads.get(e);if(!t||t.isEmpty())return null;const n=t.toSVG(),s=t.toDataURL();return{questionId:e,svgData:n,dataURL:s}}restoreSignature(e,t){const n=this.signaturePads.get(e);if(!n||!t)return!1;try{return n.clear(),n.fromData(t),!0}catch(s){return console.warn(`Failed to restore signature for ${e}:`,s),!1}}handleResize(){this.signaturePads.forEach((e,t)=>{const n=this.canvasElements.get(t);if(n){this.resizeCanvas(n);const s=e.toData();e.clear(),e.fromData(s)}})}resizeCanvas(e){const t=Math.max(window.devicePixelRatio||1,1),n=window.getComputedStyle(e),s=parseFloat(n.width),r=parseFloat(n.height);e.width=s*t,e.height=r*t;const o=e.getContext("2d");o&&o.scale(t,t)}clearSignaturePad(e){var t;this.signaturePads.has(e)&&((t=this.signaturePads.get(e))==null||t.off(),this.signaturePads.delete(e),this.canvasElements.delete(e))}getSignaturePad(e){return this.signaturePads.get(e)}hasSignaturePads(){return this.signaturePads.size>0}getAllSignaturePads(){return new Map(this.signaturePads)}destroy(){this.signaturePads.forEach(e=>{e.off()}),this.signaturePads.clear(),this.canvasElements.clear()}}class St{trackQuestionResponse(e,t,n){if(!e)return;e.responses||(e.responses=[]);const s=e.responses.findIndex(o=>o.elementId===t),r={elementId:t,value:n,answeredAt:new Date};s>=0?e.responses[s]=r:e.responses.push(r)}updateInstanceWithFormData(e,t){e!=null&&e.steps&&e.steps.forEach(n=>{n.responses||(n.responses=[]),n.elements.forEach(s=>{if(this.isQuestionElement(s.type)){const r=t[s.id];if(r!==void 0&&n.responses){let o=n.responses.find(a=>a.elementId===s.id);o?(o.value=r,o.answeredAt=new Date):(o={elementId:s.id,value:r,answeredAt:new Date},n.responses.push(o))}}})})}extractFormDataFromSteps(e){const t={};return e.forEach(n=>{n.responses&&n.responses.forEach(s=>{t[s.elementId]=s.value})}),t}hasChangedFromPrevious(e,t,n){if(!(n!=null&&n.steps))return!0;for(const s of n.steps)if(s.responses){const r=s.responses.find(o=>o.elementId===e);if(r)return r.value!==t}return!0}isQuestionElement(e){return["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"].includes(e)}}class yt{constructor(e,t){this.mode=e,this.currentUser=t}updateMode(e){this.mode=e}updateCurrentUser(e){this.currentUser=e}isStepAssignedToUser(e){if(!this.currentUser)return!1;const t=e.assignment;return!!(this.currentUser.targetId&&t.targetId&&this.currentUser.targetId===t.targetId||this.currentUser.email&&t.email&&this.currentUser.email===t.email)}getAssignedSteps(e){return e!=null&&e.steps?e.steps.filter(t=>this.isStepAssignedToUser(t)):[]}findNextAssignedStep(e,t){if(!(t!=null&&t.steps))return-1;if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print")return e+1<t.steps.length?e+1:-1;for(let n=e+1;n<t.steps.length;n++){const s=t.steps[n];if(this.isStepAssignedToUser(s))return n}return-1}isLastAssignedStep(e,t){if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print"){const n=t==null?void 0:t.steps;return e===((n==null?void 0:n.length)||0)-1}return this.findNextAssignedStep(e,t)===-1}canNavigateToStep(e,t,n,s,r,o){if((r||o)&&this.mode!=="admin"&&this.mode!=="view-only"&&this.mode!=="print")return{canNavigate:!1,newStepIndex:t,reason:"Navigation blocked: workflow submitted"};if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print"){const p=n.steps;return!p||e<0||e>=p.length?{canNavigate:!1,newStepIndex:t,reason:"Invalid step index"}:{canNavigate:!0,newStepIndex:e}}const a=n.steps;if(!a||e<0||e>=a.length)return{canNavigate:!1,newStepIndex:t,reason:"Invalid step index"};const d=a[e];if(this.isStepAssignedToUser(d)){const p=s.has(d.id),c=this.isStepWithinAllowedRange(e,n,s);return p||c?{canNavigate:!0,newStepIndex:e}:{canNavigate:!1,newStepIndex:t,reason:"Step not accessible yet"}}else return{canNavigate:!0,newStepIndex:e}}isStepWithinAllowedRange(e,t,n){if(!(t!=null&&t.steps))return!1;const r=this.getAssignedSteps(t).map(d=>t.steps.findIndex(p=>p.id===d.id)).sort((d,p)=>d-p);let o=-1;for(const d of r){const p=t.steps[d];n.has(p.id)&&(o=d)}let a=-1;for(const d of r)if(d>o){a=d;break}return a!==-1?e<=a&&this.isStepAssignedToUser(t.steps[e]):this.isStepAssignedToUser(t.steps[e])}}const ee=class ee{constructor(){this.formData={},this.validationErrors={}}updateFormData(e){this.formData={...e}}mergeFormData(e){this.formData={...this.formData,...e}}setFormField(e,t){this.formData={...this.formData,[e]:t}}removeFormField(e){const t={...this.formData};delete t[e],this.formData=t}getFormData(){return{...this.formData}}getFormField(e){return this.formData[e]}hasFormField(e){return e in this.formData}setValidationErrors(e){this.validationErrors={...e}}getValidationErrors(){return{...this.validationErrors}}clearValidationError(e){if(this.validationErrors[e]){const t={...this.validationErrors};delete t[e],this.validationErrors=t}}hasValidationError(e){return!!this.validationErrors[e]}setValidationError(e,t){this.validationErrors={...this.validationErrors,[e]:t}}clearAllValidationErrors(){this.validationErrors={}}initializeFromResponses(e){const t={};e.forEach(n=>{n.responses&&n.responses.forEach(s=>{t[s.elementId]=s.value})}),this.formData=t}reset(){this.formData={},this.validationErrors={}}isQuestionElement(e){return ee.QUESTION_ELEMENT_TYPES.includes(e.type)}getStepFormData(e){var n;const t={};return(n=e.elements)==null||n.forEach(s=>{if(this.isQuestionElement(s)){const r=s,o=this.formData[r.id];o!==void 0&&(t[r.id]=o)}}),t}hasFormData(){return Object.keys(this.formData).length>0}getFormFieldIds(){return Object.keys(this.formData)}getValidationErrorCount(){return Object.keys(this.validationErrors).length}};ee.QUESTION_ELEMENT_TYPES=["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"];let fe=ee;const te=class te{constructor(e,t){this.formStateManager=e,this.responseTracker=t}handleFileUpload(e,t,n){var p,c,u,h,f;const s=t.target,r=(p=s.files)==null?void 0:p[0];if(!r){this.clearFile(e),(c=n.onRequestUpdate)==null||c.call(n);return}const o=this.validateFileSize(r);if(o){this.handleFileValidationError(e,o,s),(u=n.onRequestUpdate)==null||u.call(n);return}this.formStateManager.clearValidationError(e);const a=this.createFileInfo(r);this.formStateManager.setFormField(e,a);const d=this.hasFileChanged(e,a,n.savedInstance);d&&n.mode!=="preview"?this.executeFileUploadCallback(e,r,a,n):this.logSkippedCallback(e,n.mode,d),(h=n.onRequestUpdate)==null||h.call(n),n.mode!=="admin"&&((f=n.onFormDataSave)==null||f.call(n))}clearFile(e){this.formStateManager.setFormField(e,null),this.formStateManager.clearValidationError(e)}validateFileSize(e){return e.size>te.MAX_FILE_SIZE?`File size must be less than 5MB. Current size: ${(e.size/1024/1024).toFixed(2)}MB`:null}handleFileValidationError(e,t,n){this.formStateManager.setValidationError(e,t),this.formStateManager.setFormField(e,null),n.value=""}createFileInfo(e){return{name:e.name,size:e.size,type:e.type,lastModified:e.lastModified}}hasFileChanged(e,t,n){if(!(n!=null&&n.steps))return!0;for(const s of n.steps)if(s.responses){const r=s.responses.find(o=>o.elementId===e);if(r&&r.value&&typeof r.value=="object"){const o=r.value;return o.name!==t.name||o.size!==t.size||o.type!==t.type||o.lastModified!==t.lastModified}}return!0}executeFileUploadCallback(e,t,n,s){var r,o;console.log("File changed, calling callback for:",e),console.log("Callback function exists:",!!s.onFileUploaded),s.onFileUploaded&&s.onFileUploaded({instanceId:(r=s.instance)==null?void 0:r.id,stepId:(o=s.currentStep)==null?void 0:o.id,questionId:e,file:t,fileName:n.name,fileSize:n.size,fileType:n.type})}logSkippedCallback(e,t,n){t==="preview"?console.log("Preview mode: skipping file upload callback for:",e):n||console.log("File unchanged, skipping callback for:",e)}};te.MAX_FILE_SIZE=5*1024*1024;let me=te;class y{static _isInputDisabled(e){return(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="admin"||e.mode==="view-only"||e.mode==="print"||e.mode==="default"&&!e.handlers.isCurrentStepAssigned()}static _formatFileSize(e){if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB"],s=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,s)).toFixed(2))+" "+n[s]}static _extractFilenameFromUrl(e){try{return new URL(e).pathname.split("/").pop()||""||"Uploaded File"}catch{const t=e.split("/"),n=t[t.length-1];return n&&n.includes(".")?n:"Uploaded File"}}static _guessFileTypeFromUrl(e){var r;const n=(r=y._extractFilenameFromUrl(e).split(".").pop())==null?void 0:r.toLowerCase();return n?{pdf:"PDF Document",doc:"Word Document",docx:"Word Document",xls:"Excel Spreadsheet",xlsx:"Excel Spreadsheet",png:"PNG Image",jpg:"JPEG Image",jpeg:"JPEG Image",gif:"GIF Image",svg:"SVG Image",txt:"Text File",csv:"CSV File",zip:"ZIP Archive",mp4:"MP4 Video",mp3:"MP3 Audio"}[n]||`${n.toUpperCase()} File`:"Unknown"}static renderTextArea(e,t,n){return n.mode==="print"?l`<div class="print-response-value textarea-response">
2972
- ${t||l`<span class="print-no-response">No response</span>`}
2973
- </div>`:l`<textarea
3001
+ */class X{constructor(e,t,n,s){if(isNaN(e)||isNaN(t))throw new Error(`Point is invalid: (${e}, ${t})`);this.x=+e,this.y=+t,this.pressure=n||0,this.time=s||Date.now()}distanceTo(e){return Math.sqrt(Math.pow(this.x-e.x,2)+Math.pow(this.y-e.y,2))}equals(e){return this.x===e.x&&this.y===e.y&&this.pressure===e.pressure&&this.time===e.time}velocityFrom(e){return this.time!==e.time?this.distanceTo(e)/(this.time-e.time):0}}class ge{static fromPoints(e,t){const n=this.calculateControlPoints(e[0],e[1],e[2]).c2,s=this.calculateControlPoints(e[1],e[2],e[3]).c1;return new ge(e[1],n,s,e[2],t.start,t.end)}static calculateControlPoints(e,t,n){const s=e.x-t.x,r=e.y-t.y,o=t.x-n.x,a=t.y-n.y,l={x:(e.x+t.x)/2,y:(e.y+t.y)/2},p={x:(t.x+n.x)/2,y:(t.y+n.y)/2},c=Math.sqrt(s*s+r*r),u=Math.sqrt(o*o+a*a),h=l.x-p.x,f=l.y-p.y,b=c+u==0?0:u/(c+u),$={x:p.x+h*b,y:p.y+f*b},ie=t.x-$.x,ne=t.y-$.y;return{c1:new X(l.x+ie,l.y+ne),c2:new X(p.x+ie,p.y+ne)}}constructor(e,t,n,s,r,o){this.startPoint=e,this.control2=t,this.control1=n,this.endPoint=s,this.startWidth=r,this.endWidth=o}length(){let t=0,n,s;for(let r=0;r<=10;r+=1){const o=r/10,a=this.point(o,this.startPoint.x,this.control1.x,this.control2.x,this.endPoint.x),l=this.point(o,this.startPoint.y,this.control1.y,this.control2.y,this.endPoint.y);if(r>0){const p=a-n,c=l-s;t+=Math.sqrt(p*p+c*c)}n=a,s=l}return t}point(e,t,n,s,r){return t*(1-e)*(1-e)*(1-e)+3*n*(1-e)*(1-e)*e+3*s*(1-e)*e*e+r*e*e*e}}class vt{constructor(){try{this._et=new EventTarget}catch{this._et=document}}addEventListener(e,t,n){this._et.addEventListener(e,t,n)}dispatchEvent(e){return this._et.dispatchEvent(e)}removeEventListener(e,t,n){this._et.removeEventListener(e,t,n)}}function xt(i,e=250){let t=0,n=null,s,r,o;const a=()=>{t=Date.now(),n=null,s=i.apply(r,o),n||(r=null,o=[])};return function(...p){const c=Date.now(),u=e-(c-t);return r=this,o=p,u<=0||u>e?(n&&(clearTimeout(n),n=null),t=c,s=i.apply(r,o),n||(r=null,o=[])):n||(n=window.setTimeout(a,u)),s}}class Z extends vt{constructor(e,t={}){var n,s,r;super(),this.canvas=e,this._drawingStroke=!1,this._isEmpty=!0,this._lastPoints=[],this._data=[],this._lastVelocity=0,this._lastWidth=0,this.velocityFilterWeight=t.velocityFilterWeight||.7,this.minWidth=t.minWidth||.5,this.maxWidth=t.maxWidth||2.5,this.throttle=(n=t.throttle)!==null&&n!==void 0?n:16,this.minDistance=(s=t.minDistance)!==null&&s!==void 0?s:5,this.dotSize=t.dotSize||0,this.penColor=t.penColor||"black",this.backgroundColor=t.backgroundColor||"rgba(0,0,0,0)",this.compositeOperation=t.compositeOperation||"source-over",this.canvasContextOptions=(r=t.canvasContextOptions)!==null&&r!==void 0?r:{},this._strokeMoveUpdate=this.throttle?xt(Z.prototype._strokeUpdate,this.throttle):Z.prototype._strokeUpdate,this._handleMouseDown=this._handleMouseDown.bind(this),this._handleMouseMove=this._handleMouseMove.bind(this),this._handleMouseUp=this._handleMouseUp.bind(this),this._handleTouchStart=this._handleTouchStart.bind(this),this._handleTouchMove=this._handleTouchMove.bind(this),this._handleTouchEnd=this._handleTouchEnd.bind(this),this._handlePointerDown=this._handlePointerDown.bind(this),this._handlePointerMove=this._handlePointerMove.bind(this),this._handlePointerUp=this._handlePointerUp.bind(this),this._ctx=e.getContext("2d",this.canvasContextOptions),this.clear(),this.on()}clear(){const{_ctx:e,canvas:t}=this;e.fillStyle=this.backgroundColor,e.clearRect(0,0,t.width,t.height),e.fillRect(0,0,t.width,t.height),this._data=[],this._reset(this._getPointGroupOptions()),this._isEmpty=!0,this._strokePointerId=void 0}fromDataURL(e,t={}){return new Promise((n,s)=>{const r=new Image,o=t.ratio||window.devicePixelRatio||1,a=t.width||this.canvas.width/o,l=t.height||this.canvas.height/o,p=t.xOffset||0,c=t.yOffset||0;this._reset(this._getPointGroupOptions()),r.onload=()=>{this._ctx.drawImage(r,p,c,a,l),n()},r.onerror=u=>{s(u)},r.crossOrigin="anonymous",r.src=e,this._isEmpty=!1})}toDataURL(e="image/png",t){switch(e){case"image/svg+xml":return typeof t!="object"&&(t=void 0),`data:image/svg+xml;base64,${btoa(this.toSVG(t))}`;default:return typeof t!="number"&&(t=void 0),this.canvas.toDataURL(e,t)}}on(){this.canvas.style.touchAction="none",this.canvas.style.msTouchAction="none",this.canvas.style.userSelect="none";const e=/Macintosh/.test(navigator.userAgent)&&"ontouchstart"in document;window.PointerEvent&&!e?this._handlePointerEvents():(this._handleMouseEvents(),"ontouchstart"in window&&this._handleTouchEvents())}off(){this.canvas.style.touchAction="auto",this.canvas.style.msTouchAction="auto",this.canvas.style.userSelect="auto",this.canvas.removeEventListener("pointerdown",this._handlePointerDown),this.canvas.removeEventListener("mousedown",this._handleMouseDown),this.canvas.removeEventListener("touchstart",this._handleTouchStart),this._removeMoveUpEventListeners()}_getListenerFunctions(){var e;const t=window.document===this.canvas.ownerDocument?window:(e=this.canvas.ownerDocument.defaultView)!==null&&e!==void 0?e:this.canvas.ownerDocument;return{addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}_removeMoveUpEventListeners(){const{removeEventListener:e}=this._getListenerFunctions();e("pointermove",this._handlePointerMove),e("pointerup",this._handlePointerUp),e("mousemove",this._handleMouseMove),e("mouseup",this._handleMouseUp),e("touchmove",this._handleTouchMove),e("touchend",this._handleTouchEnd)}isEmpty(){return this._isEmpty}fromData(e,{clear:t=!0}={}){t&&this.clear(),this._fromData(e,this._drawCurve.bind(this),this._drawDot.bind(this)),this._data=this._data.concat(e)}toData(){return this._data}_isLeftButtonPressed(e,t){return t?e.buttons===1:(e.buttons&1)===1}_pointerEventToSignatureEvent(e){return{event:e,type:e.type,x:e.clientX,y:e.clientY,pressure:"pressure"in e?e.pressure:0}}_touchEventToSignatureEvent(e){const t=e.changedTouches[0];return{event:e,type:e.type,x:t.clientX,y:t.clientY,pressure:t.force}}_handleMouseDown(e){!this._isLeftButtonPressed(e,!0)||this._drawingStroke||this._strokeBegin(this._pointerEventToSignatureEvent(e))}_handleMouseMove(e){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}_handleMouseUp(e){this._isLeftButtonPressed(e)||this._strokeEnd(this._pointerEventToSignatureEvent(e))}_handleTouchStart(e){e.targetTouches.length!==1||this._drawingStroke||(e.cancelable&&e.preventDefault(),this._strokeBegin(this._touchEventToSignatureEvent(e)))}_handleTouchMove(e){if(e.targetTouches.length===1){if(e.cancelable&&e.preventDefault(),!this._drawingStroke){this._strokeEnd(this._touchEventToSignatureEvent(e),!1);return}this._strokeMoveUpdate(this._touchEventToSignatureEvent(e))}}_handleTouchEnd(e){e.targetTouches.length===0&&(e.cancelable&&e.preventDefault(),this._strokeEnd(this._touchEventToSignatureEvent(e)))}_getPointerId(e){return e.persistentDeviceId||e.pointerId}_allowPointerId(e,t=!1){return typeof this._strokePointerId>"u"?t:this._getPointerId(e)===this._strokePointerId}_handlePointerDown(e){this._drawingStroke||!this._isLeftButtonPressed(e)||!this._allowPointerId(e,!0)||(this._strokePointerId=this._getPointerId(e),e.preventDefault(),this._strokeBegin(this._pointerEventToSignatureEvent(e)))}_handlePointerMove(e){if(this._allowPointerId(e)){if(!this._isLeftButtonPressed(e,!0)||!this._drawingStroke){this._strokeEnd(this._pointerEventToSignatureEvent(e),!1);return}e.preventDefault(),this._strokeMoveUpdate(this._pointerEventToSignatureEvent(e))}}_handlePointerUp(e){this._isLeftButtonPressed(e)||!this._allowPointerId(e)||(e.preventDefault(),this._strokeEnd(this._pointerEventToSignatureEvent(e)))}_getPointGroupOptions(e){return{penColor:e&&"penColor"in e?e.penColor:this.penColor,dotSize:e&&"dotSize"in e?e.dotSize:this.dotSize,minWidth:e&&"minWidth"in e?e.minWidth:this.minWidth,maxWidth:e&&"maxWidth"in e?e.maxWidth:this.maxWidth,velocityFilterWeight:e&&"velocityFilterWeight"in e?e.velocityFilterWeight:this.velocityFilterWeight,compositeOperation:e&&"compositeOperation"in e?e.compositeOperation:this.compositeOperation}}_strokeBegin(e){if(!this.dispatchEvent(new CustomEvent("beginStroke",{detail:e,cancelable:!0})))return;const{addEventListener:n}=this._getListenerFunctions();switch(e.event.type){case"mousedown":n("mousemove",this._handleMouseMove,{passive:!1}),n("mouseup",this._handleMouseUp,{passive:!1});break;case"touchstart":n("touchmove",this._handleTouchMove,{passive:!1}),n("touchend",this._handleTouchEnd,{passive:!1});break;case"pointerdown":n("pointermove",this._handlePointerMove,{passive:!1}),n("pointerup",this._handlePointerUp,{passive:!1});break}this._drawingStroke=!0;const s=this._getPointGroupOptions(),r=Object.assign(Object.assign({},s),{points:[]});this._data.push(r),this._reset(s),this._strokeUpdate(e)}_strokeUpdate(e){if(!this._drawingStroke)return;if(this._data.length===0){this._strokeBegin(e);return}this.dispatchEvent(new CustomEvent("beforeUpdateStroke",{detail:e}));const t=this._createPoint(e.x,e.y,e.pressure),n=this._data[this._data.length-1],s=n.points,r=s.length>0&&s[s.length-1],o=r?t.distanceTo(r)<=this.minDistance:!1,a=this._getPointGroupOptions(n);if(!r||!(r&&o)){const l=this._addPoint(t,a);r?l&&this._drawCurve(l,a):this._drawDot(t,a),s.push({time:t.time,x:t.x,y:t.y,pressure:t.pressure})}this.dispatchEvent(new CustomEvent("afterUpdateStroke",{detail:e}))}_strokeEnd(e,t=!0){this._removeMoveUpEventListeners(),this._drawingStroke&&(t&&this._strokeUpdate(e),this._drawingStroke=!1,this._strokePointerId=void 0,this.dispatchEvent(new CustomEvent("endStroke",{detail:e})))}_handlePointerEvents(){this._drawingStroke=!1,this.canvas.addEventListener("pointerdown",this._handlePointerDown,{passive:!1})}_handleMouseEvents(){this._drawingStroke=!1,this.canvas.addEventListener("mousedown",this._handleMouseDown,{passive:!1})}_handleTouchEvents(){this.canvas.addEventListener("touchstart",this._handleTouchStart,{passive:!1})}_reset(e){this._lastPoints=[],this._lastVelocity=0,this._lastWidth=(e.minWidth+e.maxWidth)/2,this._ctx.fillStyle=e.penColor,this._ctx.globalCompositeOperation=e.compositeOperation}_createPoint(e,t,n){const s=this.canvas.getBoundingClientRect();return new X(e-s.left,t-s.top,n,new Date().getTime())}_addPoint(e,t){const{_lastPoints:n}=this;if(n.push(e),n.length>2){n.length===3&&n.unshift(n[0]);const s=this._calculateCurveWidths(n[1],n[2],t),r=ge.fromPoints(n,s);return n.shift(),r}return null}_calculateCurveWidths(e,t,n){const s=n.velocityFilterWeight*t.velocityFrom(e)+(1-n.velocityFilterWeight)*this._lastVelocity,r=this._strokeWidth(s,n),o={end:r,start:this._lastWidth};return this._lastVelocity=s,this._lastWidth=r,o}_strokeWidth(e,t){return Math.max(t.maxWidth/(e+1),t.minWidth)}_drawCurveSegment(e,t,n){const s=this._ctx;s.moveTo(e,t),s.arc(e,t,n,0,2*Math.PI,!1),this._isEmpty=!1}_drawCurve(e,t){const n=this._ctx,s=e.endWidth-e.startWidth,r=Math.ceil(e.length())*2;n.beginPath(),n.fillStyle=t.penColor;for(let o=0;o<r;o+=1){const a=o/r,l=a*a,p=l*a,c=1-a,u=c*c,h=u*c;let f=h*e.startPoint.x;f+=3*u*a*e.control1.x,f+=3*c*l*e.control2.x,f+=p*e.endPoint.x;let b=h*e.startPoint.y;b+=3*u*a*e.control1.y,b+=3*c*l*e.control2.y,b+=p*e.endPoint.y;const $=Math.min(e.startWidth+p*s,t.maxWidth);this._drawCurveSegment(f,b,$)}n.closePath(),n.fill()}_drawDot(e,t){const n=this._ctx,s=t.dotSize>0?t.dotSize:(t.minWidth+t.maxWidth)/2;n.beginPath(),this._drawCurveSegment(e.x,e.y,s),n.closePath(),n.fillStyle=t.penColor,n.fill()}_fromData(e,t,n){for(const s of e){const{points:r}=s,o=this._getPointGroupOptions(s);if(r.length>1)for(let a=0;a<r.length;a+=1){const l=r[a],p=new X(l.x,l.y,l.pressure,l.time);a===0&&this._reset(o);const c=this._addPoint(p,o);c&&t(c,o)}else this._reset(o),n(r[0],o)}}toSVG({includeBackgroundColor:e=!1}={}){const t=this._data,n=Math.max(window.devicePixelRatio||1,1),s=0,r=0,o=this.canvas.width/n,a=this.canvas.height/n,l=document.createElementNS("http://www.w3.org/2000/svg","svg");if(l.setAttribute("xmlns","http://www.w3.org/2000/svg"),l.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),l.setAttribute("viewBox",`${s} ${r} ${o} ${a}`),l.setAttribute("width",o.toString()),l.setAttribute("height",a.toString()),e&&this.backgroundColor){const p=document.createElement("rect");p.setAttribute("width","100%"),p.setAttribute("height","100%"),p.setAttribute("fill",this.backgroundColor),l.appendChild(p)}return this._fromData(t,(p,{penColor:c})=>{const u=document.createElement("path");if(!isNaN(p.control1.x)&&!isNaN(p.control1.y)&&!isNaN(p.control2.x)&&!isNaN(p.control2.y)){const h=`M ${p.startPoint.x.toFixed(3)},${p.startPoint.y.toFixed(3)} C ${p.control1.x.toFixed(3)},${p.control1.y.toFixed(3)} ${p.control2.x.toFixed(3)},${p.control2.y.toFixed(3)} ${p.endPoint.x.toFixed(3)},${p.endPoint.y.toFixed(3)}`;u.setAttribute("d",h),u.setAttribute("stroke-width",(p.endWidth*2.25).toFixed(3)),u.setAttribute("stroke",c),u.setAttribute("fill","none"),u.setAttribute("stroke-linecap","round"),l.appendChild(u)}},(p,{penColor:c,dotSize:u,minWidth:h,maxWidth:f})=>{const b=document.createElement("circle"),$=u>0?u:(h+f)/2;b.setAttribute("r",$.toString()),b.setAttribute("cx",p.x.toString()),b.setAttribute("cy",p.y.toString()),b.setAttribute("fill",c),l.appendChild(b)}),l.outerHTML}}class _t{constructor(e){this.signaturePads=new Map,this.canvasElements=new Map,this.onSignatureChange=e}initializeSignaturePad(e,t){const n=t==null?void 0:t.getElementById(`signature-${e}`);if(!n)return null;this.clearSignaturePad(e),this.resizeCanvas(n);const s=new Z(n,{backgroundColor:"rgb(255, 255, 255)",penColor:"rgb(0, 0, 0)",minWidth:.5,maxWidth:2.5});return this.signaturePads.set(e,s),this.canvasElements.set(e,n),s.addEventListener("endStroke",()=>{this.handleSignatureChange(e)}),s}handleSignatureChange(e){var r;const t=this.signaturePads.get(e);if(!t)return;const n=!t.isEmpty(),s=n?t.toData():null;(r=this.onSignatureChange)==null||r.call(this,{questionId:e,hasSignature:n,signatureData:s})}clearSignature(e){const t=this.signaturePads.get(e);t&&(t.clear(),this.handleSignatureChange(e))}saveSignature(e){const t=this.signaturePads.get(e);if(!t||t.isEmpty())return null;const n=t.toSVG(),s=t.toDataURL();return{questionId:e,svgData:n,dataURL:s}}restoreSignature(e,t){const n=this.signaturePads.get(e);if(!n||!t)return!1;try{return n.clear(),n.fromData(t),!0}catch(s){return console.warn(`Failed to restore signature for ${e}:`,s),!1}}handleResize(){this.signaturePads.forEach((e,t)=>{const n=this.canvasElements.get(t);if(n){this.resizeCanvas(n);const s=e.toData();e.clear(),e.fromData(s)}})}resizeCanvas(e){const t=Math.max(window.devicePixelRatio||1,1),n=window.getComputedStyle(e),s=parseFloat(n.width),r=parseFloat(n.height);e.width=s*t,e.height=r*t;const o=e.getContext("2d");o&&o.scale(t,t)}clearSignaturePad(e){var t;this.signaturePads.has(e)&&((t=this.signaturePads.get(e))==null||t.off(),this.signaturePads.delete(e),this.canvasElements.delete(e))}getSignaturePad(e){return this.signaturePads.get(e)}hasSignaturePads(){return this.signaturePads.size>0}getAllSignaturePads(){return new Map(this.signaturePads)}destroy(){this.signaturePads.forEach(e=>{e.off()}),this.signaturePads.clear(),this.canvasElements.clear()}}class St{trackQuestionResponse(e,t,n){if(!e)return;e.responses||(e.responses=[]);const s=e.responses.findIndex(o=>o.elementId===t),r={elementId:t,value:n,answeredAt:new Date};s>=0?e.responses[s]=r:e.responses.push(r)}updateInstanceWithFormData(e,t){e!=null&&e.steps&&e.steps.forEach(n=>{n.responses||(n.responses=[]),n.elements.forEach(s=>{if(this.isQuestionElement(s.type)){const r=t[s.id];if(r!==void 0&&n.responses){let o=n.responses.find(a=>a.elementId===s.id);o?(o.value=r,o.answeredAt=new Date):(o={elementId:s.id,value:r,answeredAt:new Date},n.responses.push(o))}}})})}extractFormDataFromSteps(e){const t={};return e.forEach(n=>{n.responses&&n.responses.forEach(s=>{t[s.elementId]=s.value})}),t}hasChangedFromPrevious(e,t,n){if(!(n!=null&&n.steps))return!0;for(const s of n.steps)if(s.responses){const r=s.responses.find(o=>o.elementId===e);if(r)return r.value!==t}return!0}isQuestionElement(e){return["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"].includes(e)}}class yt{constructor(e,t){this.mode=e,this.currentUser=t}updateMode(e){this.mode=e}updateCurrentUser(e){this.currentUser=e}isStepAssignedToUser(e){if(!this.currentUser)return!1;const t=e.assignment;return!!(this.currentUser.targetId&&t.targetId&&this.currentUser.targetId===t.targetId||this.currentUser.email&&t.email&&this.currentUser.email===t.email)}getAssignedSteps(e){return e!=null&&e.steps?e.steps.filter(t=>this.isStepAssignedToUser(t)):[]}findNextAssignedStep(e,t){if(!(t!=null&&t.steps))return-1;if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print")return e+1<t.steps.length?e+1:-1;for(let n=e+1;n<t.steps.length;n++){const s=t.steps[n];if(this.isStepAssignedToUser(s))return n}return-1}isLastAssignedStep(e,t){if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print"){const n=t==null?void 0:t.steps;return e===((n==null?void 0:n.length)||0)-1}return this.findNextAssignedStep(e,t)===-1}canNavigateToStep(e,t,n,s,r,o){if((r||o)&&this.mode!=="admin"&&this.mode!=="view-only"&&this.mode!=="print")return{canNavigate:!1,newStepIndex:t,reason:"Navigation blocked: workflow submitted"};if(this.mode==="preview"||this.mode==="admin"||this.mode==="view-only"||this.mode==="print"){const p=n.steps;return!p||e<0||e>=p.length?{canNavigate:!1,newStepIndex:t,reason:"Invalid step index"}:{canNavigate:!0,newStepIndex:e}}const a=n.steps;if(!a||e<0||e>=a.length)return{canNavigate:!1,newStepIndex:t,reason:"Invalid step index"};const l=a[e];if(this.isStepAssignedToUser(l)){const p=s.has(l.id),c=this.isStepWithinAllowedRange(e,n,s);return p||c?{canNavigate:!0,newStepIndex:e}:{canNavigate:!1,newStepIndex:t,reason:"Step not accessible yet"}}else return{canNavigate:!0,newStepIndex:e}}isStepWithinAllowedRange(e,t,n){if(!(t!=null&&t.steps))return!1;const r=this.getAssignedSteps(t).map(l=>t.steps.findIndex(p=>p.id===l.id)).sort((l,p)=>l-p);let o=-1;for(const l of r){const p=t.steps[l];n.has(p.id)&&(o=l)}let a=-1;for(const l of r)if(l>o){a=l;break}return a!==-1?e<=a&&this.isStepAssignedToUser(t.steps[e]):this.isStepAssignedToUser(t.steps[e])}}const ee=class ee{constructor(){this.formData={},this.validationErrors={}}updateFormData(e){this.formData={...e}}mergeFormData(e){this.formData={...this.formData,...e}}setFormField(e,t){this.formData={...this.formData,[e]:t}}removeFormField(e){const t={...this.formData};delete t[e],this.formData=t}getFormData(){return{...this.formData}}getFormField(e){return this.formData[e]}hasFormField(e){return e in this.formData}setValidationErrors(e){this.validationErrors={...e}}getValidationErrors(){return{...this.validationErrors}}clearValidationError(e){if(this.validationErrors[e]){const t={...this.validationErrors};delete t[e],this.validationErrors=t}}hasValidationError(e){return!!this.validationErrors[e]}setValidationError(e,t){this.validationErrors={...this.validationErrors,[e]:t}}clearAllValidationErrors(){this.validationErrors={}}initializeFromResponses(e){const t={};e.forEach(n=>{n.responses&&n.responses.forEach(s=>{t[s.elementId]=s.value})}),this.formData=t}reset(){this.formData={},this.validationErrors={}}isQuestionElement(e){return ee.QUESTION_ELEMENT_TYPES.includes(e.type)}getStepFormData(e){var n;const t={};return(n=e.elements)==null||n.forEach(s=>{if(this.isQuestionElement(s)){const r=s,o=this.formData[r.id];o!==void 0&&(t[r.id]=o)}}),t}hasFormData(){return Object.keys(this.formData).length>0}getFormFieldIds(){return Object.keys(this.formData)}getValidationErrorCount(){return Object.keys(this.validationErrors).length}};ee.QUESTION_ELEMENT_TYPES=["text_input","textarea","select","number","radio","checkbox","date","file_upload","signature"];let fe=ee;const te=class te{constructor(e,t){this.formStateManager=e,this.responseTracker=t}handleFileUpload(e,t,n){var p,c,u,h,f;const s=t.target,r=(p=s.files)==null?void 0:p[0];if(!r){this.clearFile(e),(c=n.onRequestUpdate)==null||c.call(n);return}const o=this.validateFileSize(r);if(o){this.handleFileValidationError(e,o,s),(u=n.onRequestUpdate)==null||u.call(n);return}this.formStateManager.clearValidationError(e);const a=this.createFileInfo(r);this.formStateManager.setFormField(e,a);const l=this.hasFileChanged(e,a,n.savedInstance);l&&n.mode!=="preview"?this.executeFileUploadCallback(e,r,a,n):this.logSkippedCallback(e,n.mode,l),(h=n.onRequestUpdate)==null||h.call(n),n.mode!=="admin"&&((f=n.onFormDataSave)==null||f.call(n))}clearFile(e){this.formStateManager.setFormField(e,null),this.formStateManager.clearValidationError(e)}validateFileSize(e){return e.size>te.MAX_FILE_SIZE?`File size must be less than 5MB. Current size: ${(e.size/1024/1024).toFixed(2)}MB`:null}handleFileValidationError(e,t,n){this.formStateManager.setValidationError(e,t),this.formStateManager.setFormField(e,null),n.value=""}createFileInfo(e){return{name:e.name,size:e.size,type:e.type,lastModified:e.lastModified}}hasFileChanged(e,t,n){if(!(n!=null&&n.steps))return!0;for(const s of n.steps)if(s.responses){const r=s.responses.find(o=>o.elementId===e);if(r&&r.value&&typeof r.value=="object"){const o=r.value;return o.name!==t.name||o.size!==t.size||o.type!==t.type||o.lastModified!==t.lastModified}}return!0}executeFileUploadCallback(e,t,n,s){var r,o;console.log("File changed, calling callback for:",e),console.log("Callback function exists:",!!s.onFileUploaded),s.onFileUploaded&&s.onFileUploaded({instanceId:(r=s.instance)==null?void 0:r.id,stepId:(o=s.currentStep)==null?void 0:o.id,questionId:e,file:t,fileName:n.name,fileSize:n.size,fileType:n.type})}logSkippedCallback(e,t,n){t==="preview"?console.log("Preview mode: skipping file upload callback for:",e):n||console.log("File unchanged, skipping callback for:",e)}};te.MAX_FILE_SIZE=5*1024*1024;let me=te;class y{static _isInputDisabled(e){return(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="admin"||e.mode==="view-only"||e.mode==="print"||e.mode==="default"&&!e.handlers.isCurrentStepAssigned()}static _formatFileSize(e){if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB"],s=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,s)).toFixed(2))+" "+n[s]}static _extractFilenameFromUrl(e){try{return new URL(e).pathname.split("/").pop()||""||"Uploaded File"}catch{const t=e.split("/"),n=t[t.length-1];return n&&n.includes(".")?n:"Uploaded File"}}static _guessFileTypeFromUrl(e){var r;const n=(r=y._extractFilenameFromUrl(e).split(".").pop())==null?void 0:r.toLowerCase();return n?{pdf:"PDF Document",doc:"Word Document",docx:"Word Document",xls:"Excel Spreadsheet",xlsx:"Excel Spreadsheet",png:"PNG Image",jpg:"JPEG Image",jpeg:"JPEG Image",gif:"GIF Image",svg:"SVG Image",txt:"Text File",csv:"CSV File",zip:"ZIP Archive",mp4:"MP4 Video",mp3:"MP3 Audio"}[n]||`${n.toUpperCase()} File`:"Unknown"}static renderTextArea(e,t,n){return n.mode==="print"?d`<div class="print-response-value textarea-response">
3002
+ ${t||d`<span class="print-no-response">No response</span>`}
3003
+ </div>`:d`<textarea
2974
3004
  id=${e.id}
2975
3005
  .value=${t}
2976
3006
  ?required=${e.required}
2977
3007
  ?disabled=${this._isInputDisabled(n)}
2978
3008
  placeholder="Your Response"
2979
3009
  @input=${s=>n.handlers.handleInputChange(e.id,s)}
2980
- ></textarea>`}static renderSelect(e,t,n){var s;return n.mode==="print"?l`<div class="print-response-value select-response">
2981
- ${t||l`<span class="print-no-response">No selection made</span>`}
2982
- </div>`:l`<select
3010
+ ></textarea>`}static renderSelect(e,t,n){var s;return n.mode==="print"?d`<div class="print-response-value select-response">
3011
+ ${t||d`<span class="print-no-response">No selection made</span>`}
3012
+ </div>`:d`<select
2983
3013
  id=${e.id}
2984
3014
  .value=${t}
2985
3015
  ?required=${e.required}
@@ -2988,11 +3018,11 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
2988
3018
  @change=${r=>n.handlers.handleInputChange(e.id,r)}
2989
3019
  >
2990
3020
  <option value="">Choose</option>
2991
- ${(s=e.options)==null?void 0:s.map(r=>l`<option value=${r}>${r}</option>`)}
2992
- </select>`}static renderRadio(e,t,n){var o;const s=this._isInputDisabled(n),r=n.mode==="print";return r?l`<div class="print-response-value radio-response">
2993
- ${t||l`<span class="print-no-response">No selection made</span>`}
2994
- </div>`:l`<div class="radio-group ${r?"print-mode":""}">
2995
- ${(o=e.options)==null?void 0:o.map(a=>l`
3021
+ ${(s=e.options)==null?void 0:s.map(r=>d`<option value=${r}>${r}</option>`)}
3022
+ </select>`}static renderRadio(e,t,n){var o;const s=this._isInputDisabled(n),r=n.mode==="print";return r?d`<div class="print-response-value radio-response">
3023
+ ${t||d`<span class="print-no-response">No selection made</span>`}
3024
+ </div>`:d`<div class="radio-group ${r?"print-mode":""}">
3025
+ ${(o=e.options)==null?void 0:o.map(a=>d`
2996
3026
  <label class="radio-option">
2997
3027
  <input
2998
3028
  type="radio"
@@ -3000,15 +3030,15 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3000
3030
  value=${a}
3001
3031
  .checked=${t===a}
3002
3032
  ?disabled=${s}
3003
- @change=${r?null:d=>n.handlers.handleInputChange(e.id,d)}
3033
+ @change=${r?null:l=>n.handlers.handleInputChange(e.id,l)}
3004
3034
  />
3005
3035
  <span class="radio-label">${a}</span>
3006
3036
  </label>
3007
3037
  `)}
3008
- </div>`}static renderCheckbox(e,t,n){var o;const s=this._isInputDisabled(n),r=n.mode==="print";if(e.options&&e.options.length>0){if(r){const a=Array.isArray(t)?t:[];return l`<div class="print-response-value checkbox-response">
3009
- ${a.length>0?a.map(d=>l`<div>• ${d}</div>`):l`<span class="print-no-response">No selections made</span>`}
3010
- </div>`}return l`<div class="checkbox-group ${r?"print-mode":""}">
3011
- ${(o=e.options)==null?void 0:o.map(a=>l`
3038
+ </div>`}static renderCheckbox(e,t,n){var o;const s=this._isInputDisabled(n),r=n.mode==="print";if(e.options&&e.options.length>0){if(r){const a=Array.isArray(t)?t:[];return d`<div class="print-response-value checkbox-response">
3039
+ ${a.length>0?a.map(l=>d`<div>• ${l}</div>`):d`<span class="print-no-response">No selections made</span>`}
3040
+ </div>`}return d`<div class="checkbox-group ${r?"print-mode":""}">
3041
+ ${(o=e.options)==null?void 0:o.map(a=>d`
3012
3042
  <label class="checkbox-option">
3013
3043
  <input
3014
3044
  type="checkbox"
@@ -3016,14 +3046,14 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3016
3046
  value=${a}
3017
3047
  .checked=${Array.isArray(t)?t.includes(a):!1}
3018
3048
  ?disabled=${s}
3019
- @change=${r?null:d=>n.handlers.handleCheckboxGroupChange(e.id,a,d)}
3049
+ @change=${r?null:l=>n.handlers.handleCheckboxGroupChange(e.id,a,l)}
3020
3050
  />
3021
3051
  <span class="checkbox-label">${a}</span>
3022
3052
  </label>
3023
3053
  `)}
3024
- </div>`}else return r?l`<div class="print-response-value checkbox-response">
3054
+ </div>`}else return r?d`<div class="print-response-value checkbox-response">
3025
3055
  ${t?"Yes":"No"}
3026
- </div>`:l`<label class="checkbox-single ${r?"print-mode":""}">
3056
+ </div>`:d`<label class="checkbox-single ${r?"print-mode":""}">
3027
3057
  <input
3028
3058
  type="checkbox"
3029
3059
  id=${e.id}
@@ -3032,40 +3062,40 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3032
3062
  @change=${r?null:a=>n.handlers.handleCheckboxChange(e.id,a)}
3033
3063
  />
3034
3064
  <span class="checkbox-label">${e.label}</span>
3035
- </label>`}static renderSignature(e,t,n){const s=n.formData[e.id],r=!!n.formData[e.id],o=n.savedSignatures.has(e.id),a=n.replacingSignatures.has(e.id);if(n.mode==="print")return s&&typeof s=="string"?l`
3065
+ </label>`}static renderSignature(e,t,n){const s=n.formData[e.id],r=!!n.formData[e.id],o=n.savedSignatures.has(e.id),a=n.replacingSignatures.has(e.id);if(n.mode==="print")return s&&typeof s=="string"?d`
3036
3066
  <div class="print-response-value signature-response">
3037
3067
  <img
3038
3068
  src="${s}"
3039
3069
  alt="Digital Signature"
3040
3070
  class="signature-image"
3041
- @error=${d=>{var u;const p=d.target;p.style.display="none";const c=(u=p.parentElement)==null?void 0:u.querySelector(".signature-fallback");c&&c.classList.remove("hidden")}}
3071
+ @error=${l=>{var u;const p=l.target;p.style.display="none";const c=(u=p.parentElement)==null?void 0:u.querySelector(".signature-fallback");c&&c.classList.remove("hidden")}}
3042
3072
  />
3043
3073
  <div class="signature-fallback hidden">
3044
3074
  <span class="signature-error">Unable to display signature</span>
3045
3075
  </div>
3046
3076
  </div>
3047
- `:l`<div class="print-response-value signature-response">
3077
+ `:d`<div class="print-response-value signature-response">
3048
3078
  <span class="print-no-response">No signature provided</span>
3049
- </div>`;if(n.mode==="view-only")return s&&typeof s=="string"?l`
3079
+ </div>`;if(n.mode==="view-only")return s&&typeof s=="string"?d`
3050
3080
  <div class="signature-view-only">
3051
3081
  <img
3052
3082
  src="${s}"
3053
3083
  alt="Digital Signature"
3054
3084
  class="signature-image"
3055
- @error=${d=>{var u;const p=d.target;p.style.display="none";const c=(u=p.parentElement)==null?void 0:u.querySelector(".signature-fallback");c&&c.classList.remove("hidden")}}
3085
+ @error=${l=>{var u;const p=l.target;p.style.display="none";const c=(u=p.parentElement)==null?void 0:u.querySelector(".signature-fallback");c&&c.classList.remove("hidden")}}
3056
3086
  />
3057
3087
  <div class="signature-fallback hidden">
3058
3088
  <span class="signature-error">Unable to display signature</span>
3059
3089
  </div>
3060
3090
  </div>
3061
- `:l`
3091
+ `:d`
3062
3092
  <div class="signature-view-only">
3063
3093
  <span class="no-signature">No signature captured</span>
3064
3094
  </div>
3065
- `;if(n.mode==="admin"&&s&&typeof s=="string"&&!a){const d=s.trim().startsWith("<svg");return l`
3095
+ `;if(n.mode==="admin"&&s&&typeof s=="string"&&!a){const l=s.trim().startsWith("<svg");return d`
3066
3096
  <div class="signature-admin-display">
3067
3097
  <div class="signature-existing">
3068
- ${d?l` <div class="signature-svg-container" .innerHTML=${s}></div> `:l`
3098
+ ${l?d` <div class="signature-svg-container" .innerHTML=${s}></div> `:d`
3069
3099
  <img
3070
3100
  src="${s}"
3071
3101
  alt="Digital Signature"
@@ -3087,7 +3117,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3087
3117
  </button>
3088
3118
  </div>
3089
3119
  </div>
3090
- `}return l`
3120
+ `}return d`
3091
3121
  <div class="signature-container ${this._isInputDisabled(n)?"disabled":""}">
3092
3122
  <canvas id="signature-${e.id}" class="signature-canvas"></canvas>
3093
3123
  <div class="signature-controls">
@@ -3099,7 +3129,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3099
3129
  >
3100
3130
  Clear
3101
3131
  </button>
3102
- ${r&&!o?l`
3132
+ ${r&&!o?d`
3103
3133
  <button
3104
3134
  type="button"
3105
3135
  class="signature-save-btn"
@@ -3109,8 +3139,8 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3109
3139
  Save
3110
3140
  </button>
3111
3141
  `:""}
3112
- ${o?l` <span class="signature-saved">✓ Saved</span> `:""}
3113
- ${n.mode==="admin"&&a?l`
3142
+ ${o?d` <span class="signature-saved">✓ Saved</span> `:""}
3143
+ ${n.mode==="admin"&&a?d`
3114
3144
  <button
3115
3145
  type="button"
3116
3146
  class="signature-cancel-btn"
@@ -3121,31 +3151,31 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3121
3151
  `:""}
3122
3152
  </div>
3123
3153
  </div>
3124
- `}static renderFileUpload(e,t,n){const s=n.formData[e.id];if(n.mode==="view-only"||n.mode==="print")if(s){const r=typeof s=="string",o=typeof s=="object"&&s.name;if(n.mode==="print"){if(o)return l`
3154
+ `}static renderFileUpload(e,t,n){const s=n.formData[e.id];if(n.mode==="view-only"||n.mode==="print")if(s){const r=typeof s=="string",o=typeof s=="object"&&s.name;if(n.mode==="print"){if(o)return d`
3125
3155
  <div class="print-response-value file-response">
3126
3156
  📎 ${s.name}
3127
- ${s.size?l` <span class="file-size"
3157
+ ${s.size?d` <span class="file-size"
3128
3158
  >(${y._formatFileSize(s.size)})</span
3129
3159
  >`:""}
3130
3160
  </div>
3131
- `;if(r){const a=y._extractFilenameFromUrl(s);return l` <div class="print-response-value file-response">📎 ${a}</div> `}else return l` <div class="print-response-value file-response">📎 ${s}</div> `}else{const a=r?s:"#",d=o?s.name:r?y._extractFilenameFromUrl(s):"View File";return l`
3161
+ `;if(r){const a=y._extractFilenameFromUrl(s);return d` <div class="print-response-value file-response">📎 ${a}</div> `}else return d` <div class="print-response-value file-response">📎 ${s}</div> `}else{const a=r?s:"#",l=o?s.name:r?y._extractFilenameFromUrl(s):"View File";return d`
3132
3162
  <div class="file-upload-view-only">
3133
- <a href="${a}" target="_blank" class="file-link"> 📎 ${d} </a>
3134
- ${o&&s.size?l`
3163
+ <a href="${a}" target="_blank" class="file-link"> 📎 ${l} </a>
3164
+ ${o&&s.size?d`
3135
3165
  <span class="file-size-info"
3136
3166
  >(${y._formatFileSize(s.size)})</span
3137
3167
  >
3138
3168
  `:""}
3139
3169
  </div>
3140
- `}}else return n.mode==="print"?l`
3170
+ `}}else return n.mode==="print"?d`
3141
3171
  <div class="print-response-value file-response">
3142
3172
  <span class="print-no-response">No file uploaded</span>
3143
3173
  </div>
3144
- `:l`
3174
+ `:d`
3145
3175
  <div class="file-upload-view-only">
3146
3176
  <span class="no-file">No file uploaded</span>
3147
3177
  </div>
3148
- `;return l`
3178
+ `;return d`
3149
3179
  <div class="file-upload-container">
3150
3180
  <input
3151
3181
  type="file"
@@ -3154,7 +3184,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3154
3184
  ?disabled=${this._isInputDisabled(n)}
3155
3185
  @change=${r=>n.handlers.handleFileUpload(e.id,r)}
3156
3186
  />
3157
- ${s?l`
3187
+ ${s?d`
3158
3188
  <div class="file-preview">
3159
3189
  <span class="file-name">${s.name||"File selected"}</span>
3160
3190
  <button
@@ -3168,9 +3198,9 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3168
3198
  </div>
3169
3199
  `:""}
3170
3200
  </div>
3171
- `}static renderDefaultInput(e,t,n){if(n.mode==="print"){const r=e.type==="date"&&t?new Date(t).toLocaleDateString():t;return l`<div class="print-response-value input-response">
3172
- ${r||l`<span class="print-no-response">No response</span>`}
3173
- </div>`}const s=e.type==="number"?"number":e.type==="date"?"date":"text";return l`<input
3201
+ `}static renderDefaultInput(e,t,n){if(n.mode==="print"){const r=e.type==="date"&&t?new Date(t).toLocaleDateString():t;return d`<div class="print-response-value input-response">
3202
+ ${r||d`<span class="print-no-response">No response</span>`}
3203
+ </div>`}const s=e.type==="number"?"number":e.type==="date"?"date":"text";return d`<input
3174
3204
  type=${s}
3175
3205
  id=${e.id}
3176
3206
  .value=${t}
@@ -3178,22 +3208,22 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3178
3208
  ?disabled=${this._isInputDisabled(n)}
3179
3209
  placeholder="Your Response"
3180
3210
  @input=${r=>n.handlers.handleInputChange(e.id,r)}
3181
- />`}static render(e,t){const n=t.formData[e.id]??"",s=t.validationErrors[e.id],r=()=>{switch(e.type){case"textarea":return y.renderTextArea(e,n,t);case"select":return y.renderSelect(e,n,t);case"radio":return y.renderRadio(e,n,t);case"checkbox":return y.renderCheckbox(e,n,t);case"signature":return y.renderSignature(e,n,t);case"file_upload":return y.renderFileUpload(e,n,t);default:return y.renderDefaultInput(e,n,t)}},o=e.type==="checkbox"&&(!e.options||e.options.length===0);return t.mode==="print"?l`
3211
+ />`}static render(e,t){const n=t.formData[e.id]??"",s=t.validationErrors[e.id],r=()=>{switch(e.type){case"textarea":return y.renderTextArea(e,n,t);case"select":return y.renderSelect(e,n,t);case"radio":return y.renderRadio(e,n,t);case"checkbox":return y.renderCheckbox(e,n,t);case"signature":return y.renderSignature(e,n,t);case"file_upload":return y.renderFileUpload(e,n,t);default:return y.renderDefaultInput(e,n,t)}},o=e.type==="checkbox"&&(!e.options||e.options.length===0);return t.mode==="print"?d`
3182
3212
  <div class="question-print">
3183
- ${o?"":l` <div class="print-question-title">${e.label}:</div> `}
3213
+ ${o?"":d` <div class="print-question-title">${e.label}:</div> `}
3184
3214
  ${r()}
3185
3215
  <hr class="print-question-separator" />
3186
3216
  </div>
3187
- `:l`
3217
+ `:d`
3188
3218
  <div class="question ${s?"error":""}">
3189
- ${o?"":l`
3219
+ ${o?"":d`
3190
3220
  <div class="runner-question-title">
3191
- ${e.label}${e.required?l`<span class="runner-question-required">*</span>`:""}
3221
+ ${e.label}${e.required?d`<span class="runner-question-required">*</span>`:""}
3192
3222
  </div>
3193
3223
  <hr class="runner-question-divider" />
3194
3224
  `}
3195
3225
  ${r()}
3196
- ${s?l`<div class="error-message">${s}</div>`:""}
3226
+ ${s?d`<div class="error-message">${s}</div>`:""}
3197
3227
  </div>
3198
3228
  `}}/**
3199
3229
  * @license
@@ -3203,60 +3233,60 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3203
3233
  * @license
3204
3234
  * Copyright 2017 Google LLC
3205
3235
  * SPDX-License-Identifier: BSD-3-Clause
3206
- */class be extends $t{constructor(e){if(super(e),this.it=v,e.type!==wt.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===v||e==null)return this._t=void 0,this.it=e;if(e===I)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;const t=[e];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}}be.directiveName="unsafeHTML",be.resultType=1;const Le=kt(be);class k{static renderMarkdown(e){return e.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*?)\*\*/gim,"<strong>$1</strong>").replace(/\*(.*?)\*/gim,"<em>$1</em>").replace(/`(.*?)`/gim,"<code>$1</code>").replace(/^> (.*$)/gim,"<blockquote>$1</blockquote>").replace(/\n/gim,"<br>")}static renderText(e){return l`
3236
+ */class be extends $t{constructor(e){if(super(e),this.it=v,e.type!==wt.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(e){if(e===v||e==null)return this._t=void 0,this.it=e;if(e===I)return e;if(typeof e!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(e===this.it)return this._t;this.it=e;const t=[e];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}}be.directiveName="unsafeHTML",be.resultType=1;const Le=kt(be);class k{static renderMarkdown(e){return e.replace(/^### (.*$)/gim,"<h3>$1</h3>").replace(/^## (.*$)/gim,"<h2>$1</h2>").replace(/^# (.*$)/gim,"<h1>$1</h1>").replace(/\*\*(.*?)\*\*/gim,"<strong>$1</strong>").replace(/\*(.*?)\*/gim,"<em>$1</em>").replace(/`(.*?)`/gim,"<code>$1</code>").replace(/^> (.*$)/gim,"<blockquote>$1</blockquote>").replace(/\n/gim,"<br>")}static renderText(e){return d`
3207
3237
  <div class="content-element text-content">
3208
3238
  <p>${e.content}</p>
3209
3239
  </div>
3210
- `}static renderMarkdownElement(e){return l`
3240
+ `}static renderMarkdownElement(e){return d`
3211
3241
  <div class="content-element markdown-content">
3212
3242
  <div class="markdown-text">
3213
3243
  ${Le(k.renderMarkdown(e.content))}
3214
3244
  </div>
3215
3245
  </div>
3216
- `}static renderDivider(e){return l`
3246
+ `}static renderDivider(e){return d`
3217
3247
  <div class="content-element divider-content">
3218
3248
  <hr class="content-divider" />
3219
- ${e.caption?l`<div class="divider-caption">${e.caption}</div>`:""}
3249
+ ${e.caption?d`<div class="divider-caption">${e.caption}</div>`:""}
3220
3250
  </div>
3221
- `}static renderHtml(e){return l`
3251
+ `}static renderHtml(e){return d`
3222
3252
  <div class="content-element html-content">
3223
3253
  <div class="html-content-wrapper">${Le(e.content)}</div>
3224
3254
  </div>
3225
- `}static renderImage(e){return l`
3255
+ `}static renderImage(e){return d`
3226
3256
  <div class="content-element image-content">
3227
3257
  <div class="image-placeholder">
3228
3258
  <p>📷 Image: ${e.caption||e.alt||"Image content"}</p>
3229
3259
  <small>URL: ${e.url||"No URL provided"}</small>
3230
3260
  </div>
3231
3261
  </div>
3232
- `}static renderVideo(e){return l`
3262
+ `}static renderVideo(e){return d`
3233
3263
  <div class="content-element video-content">
3234
3264
  <div class="video-placeholder">
3235
3265
  <p>🎥 Video: ${e.caption||"Video content"}</p>
3236
3266
  <small>URL: ${e.url||"No URL provided"}</small>
3237
3267
  </div>
3238
3268
  </div>
3239
- `}static renderFile(e){return l`
3269
+ `}static renderFile(e){return d`
3240
3270
  <div class="content-element file-content">
3241
3271
  <div class="file-placeholder">
3242
3272
  <p>📄 File: ${e.caption||"File content"}</p>
3243
3273
  <small>URL: ${e.url||"No URL provided"}</small>
3244
3274
  </div>
3245
3275
  </div>
3246
- `}static renderUnknown(e){return l`
3276
+ `}static renderUnknown(e){return d`
3247
3277
  <div class="content-element unknown-content">
3248
3278
  <p>⚠️ Unknown content type: ${e.type}</p>
3249
3279
  </div>
3250
- `}static render(e,t){const n=()=>{switch(e.type){case"text":return k.renderText(e);case"markdown":return k.renderMarkdownElement(e);case"divider":return k.renderDivider(e);case"html":return k.renderHtml(e);case"image":return k.renderImage(e);case"video":return k.renderVideo(e);case"file":return k.renderFile(e);default:return k.renderUnknown(e)}};return(t==null?void 0:t.mode)==="print"?l`
3280
+ `}static render(e,t){const n=()=>{switch(e.type){case"text":return k.renderText(e);case"markdown":return k.renderMarkdownElement(e);case"divider":return k.renderDivider(e);case"html":return k.renderHtml(e);case"image":return k.renderImage(e);case"video":return k.renderVideo(e);case"file":return k.renderFile(e);default:return k.renderUnknown(e)}};return(t==null?void 0:t.mode)==="print"?d`
3251
3281
  <div class="content-print">
3252
3282
  ${n()}
3253
- ${e.type!=="divider"?l`<hr class="print-question-separator" />`:""}
3283
+ ${e.type!=="divider"?d`<hr class="print-question-separator" />`:""}
3254
3284
  </div>
3255
- `:n()}}class Ne{static renderMobileStepsForStatus(e){const{steps:t,disabled:n=!1}=e;return l`
3285
+ `:n()}}class Ne{static renderMobileStepsForStatus(e){const{steps:t,disabled:n=!1}=e;return d`
3256
3286
  <div class="runner-mobile-steps">
3257
3287
  <nav aria-label="Workflow steps">
3258
3288
  <div class="runner-mobile-steps-container">
3259
- ${t==null?void 0:t.map(s=>{const r=e.isStepAssignedToUser(s),o=e.completedSteps.has(s.id);return l`
3289
+ ${t==null?void 0:t.map(s=>{const r=e.isStepAssignedToUser(s),o=e.completedSteps.has(s.id);return d`
3260
3290
  <div
3261
3291
  class="runner-mobile-step-tab ${o?"completed":""} ${r?"":"unassigned"} ${n?"disabled":""}"
3262
3292
  style="cursor: not-allowed; opacity: ${n?"0.6":r?"1":"0.6"};"
@@ -3270,7 +3300,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3270
3300
  </div>
3271
3301
  </nav>
3272
3302
  </div>
3273
- `}static renderNotAssignedView(){return l`
3303
+ `}static renderNotAssignedView(){return d`
3274
3304
  <div class="runner-content not-assigned-view">
3275
3305
  <div class="not-assigned-container">
3276
3306
  <div class="not-assigned-icon">
@@ -3293,7 +3323,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3293
3323
  </p>
3294
3324
  </div>
3295
3325
  </div>
3296
- `}static renderUnifiedSubmissionView(e){var t,n,s;return l`
3326
+ `}static renderUnifiedSubmissionView(e){var t,n,s;return d`
3297
3327
  <div class="runner-layout">
3298
3328
  <!-- Mobile Steps Navigation (visible only on mobile) -->
3299
3329
  ${this.renderMobileStepsForStatus({steps:(t=e.instance)==null?void 0:t.steps,isStepAssignedToUser:e.isStepAssignedToUser,completedSteps:e.completedSteps,disabled:!0})}
@@ -3303,7 +3333,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3303
3333
  <div class="runner-sidebar-header">Steps</div>
3304
3334
  <nav aria-label="Workflow steps">
3305
3335
  <ul class="runner-steps-list">
3306
- ${(s=(n=e.instance)==null?void 0:n.steps)==null?void 0:s.map(r=>{const o=e.isStepAssignedToUser(r),a=e.completedSteps.has(r.id);return l`
3336
+ ${(s=(n=e.instance)==null?void 0:n.steps)==null?void 0:s.map(r=>{const o=e.isStepAssignedToUser(r),a=e.completedSteps.has(r.id);return d`
3307
3337
  <li
3308
3338
  class="runner-step-item ${a?"completed":""} ${o?"":"unassigned"}"
3309
3339
  style="opacity: ${o?"1":"0.6"}; cursor: not-allowed;"
@@ -3342,59 +3372,59 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3342
3372
  </div>
3343
3373
  </main>
3344
3374
  </div>
3345
- `}}class Y{static isStepCompleted(e,t,n){return!!(t.completedSteps.has(e.id)||(t.isSubmitted||t.userStepsSubmitted)&&n)}static renderSidebar(e){const{steps:t}=e;return l`
3375
+ `}}class Y{static isStepCompleted(e,t,n){return!!(t.completedSteps.has(e.id)||(t.isSubmitted||t.userStepsSubmitted)&&n)}static renderSidebar(e){const{steps:t}=e;return d`
3346
3376
  <aside class="runner-sidebar">
3347
3377
  <div class="runner-sidebar-header">Steps</div>
3348
3378
  <nav aria-label="Workflow steps">
3349
3379
  <ul class="runner-steps-list">
3350
- ${t==null?void 0:t.map((n,s)=>{const r=e.mode==="preview"||e.mode==="admin"||e.mode==="view-only"||e.mode==="print"||e.isStepAssignedToUser(n),o=s===e.currentStepIndex,a=this.isStepCompleted(n,e,r),d=(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="preview"&&e.mode!=="admin"&&e.mode!=="view-only"&&e.mode!=="print",p=e.isLoading;return l`
3380
+ ${t==null?void 0:t.map((n,s)=>{const r=e.mode==="preview"||e.mode==="admin"||e.mode==="view-only"||e.mode==="print"||e.isStepAssignedToUser(n),o=s===e.currentStepIndex,a=this.isStepCompleted(n,e,r),l=(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="preview"&&e.mode!=="admin"&&e.mode!=="view-only"&&e.mode!=="print",p=e.isLoading;return d`
3351
3381
  <li
3352
- class="runner-step-item ${o?"active":""} ${a?"completed":""} ${r?"":"unassigned"} ${d?"disabled":""} ${p?"loading-disabled":""}"
3382
+ class="runner-step-item ${o?"active":""} ${a?"completed":""} ${r?"":"unassigned"} ${l?"disabled":""} ${p?"loading-disabled":""}"
3353
3383
  @click=${()=>!p&&e.goToStep(s)}
3354
- style="${d?"opacity: 0.5; cursor: not-allowed;":""}"
3384
+ style="${l?"opacity: 0.5; cursor: not-allowed;":""}"
3355
3385
  >
3356
3386
  <span class="runner-step-title">${n.title}</span>
3357
3387
  <span class="runner-step-badge">
3358
- ${e.mode==="preview"?"Preview":e.mode==="admin"?"Admin":e.mode==="view-only"?"View Only":e.mode==="print"?"Print":d?"Submitted":a?"Completed":r?"Assigned":"Not Assigned"}
3388
+ ${e.mode==="preview"?"Preview":e.mode==="admin"?"Admin":e.mode==="view-only"?"View Only":e.mode==="print"?"Print":l?"Submitted":a?"Completed":r?"Assigned":"Not Assigned"}
3359
3389
  </span>
3360
3390
  </li>
3361
3391
  `})}
3362
3392
  </ul>
3363
3393
  </nav>
3364
3394
  </aside>
3365
- `}static renderMobileSteps(e){const{steps:t}=e;return l`
3395
+ `}static renderMobileSteps(e){const{steps:t}=e;return d`
3366
3396
  <div class="runner-mobile-steps">
3367
3397
  <nav aria-label="Workflow steps">
3368
3398
  <div class="runner-mobile-steps-container">
3369
- ${t==null?void 0:t.map((n,s)=>{const r=e.mode==="preview"||e.mode==="admin"||e.mode==="view-only"||e.mode==="print"||e.isStepAssignedToUser(n),o=s===e.currentStepIndex,a=this.isStepCompleted(n,e,r),d=(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="preview"&&e.mode!=="admin"&&e.mode!=="view-only"&&e.mode!=="print",p=e.isLoading;return l`
3399
+ ${t==null?void 0:t.map((n,s)=>{const r=e.mode==="preview"||e.mode==="admin"||e.mode==="view-only"||e.mode==="print"||e.isStepAssignedToUser(n),o=s===e.currentStepIndex,a=this.isStepCompleted(n,e,r),l=(e.isSubmitted||e.userStepsSubmitted)&&e.mode!=="preview"&&e.mode!=="admin"&&e.mode!=="view-only"&&e.mode!=="print",p=e.isLoading;return d`
3370
3400
  <button
3371
- class="runner-mobile-step-tab ${o?"active":""} ${a?"completed":""} ${r?"":"unassigned"} ${d?"disabled":""} ${p?"loading-disabled":""}"
3401
+ class="runner-mobile-step-tab ${o?"active":""} ${a?"completed":""} ${r?"":"unassigned"} ${l?"disabled":""} ${p?"loading-disabled":""}"
3372
3402
  @click=${()=>!p&&e.goToStep(s)}
3373
- ?disabled=${d||p}
3403
+ ?disabled=${l||p}
3374
3404
  aria-current=${o?"step":"false"}
3375
3405
  >
3376
3406
  <span class="runner-mobile-step-title">${n.title}</span>
3377
3407
  <span class="runner-mobile-step-badge">
3378
- ${e.mode==="preview"?"Preview":e.mode==="admin"?"Admin":e.mode==="view-only"?"View Only":e.mode==="print"?"Print":d?"Submitted":a?"Completed":r?"Assigned":"Not Assigned"}
3408
+ ${e.mode==="preview"?"Preview":e.mode==="admin"?"Admin":e.mode==="view-only"?"View Only":e.mode==="print"?"Print":l?"Submitted":a?"Completed":r?"Assigned":"Not Assigned"}
3379
3409
  </span>
3380
3410
  </button>
3381
3411
  `})}
3382
3412
  </div>
3383
3413
  </nav>
3384
3414
  </div>
3385
- `}static renderStepHeader(e){const{step:t,mode:n}=e;return n==="print"?l`
3415
+ `}static renderStepHeader(e){const{step:t,mode:n}=e;return n==="print"?d`
3386
3416
  <div class="step-print-header">
3387
3417
  <div class="print-step-title">${t.title}</div>
3388
- ${t.description?l`<div class="print-step-description">${t.description}</div>`:""}
3418
+ ${t.description?d`<div class="print-step-description">${t.description}</div>`:""}
3389
3419
  <hr class="print-question-separator" />
3390
3420
  </div>
3391
- `:l`
3421
+ `:d`
3392
3422
  <section class="runner-step-header">
3393
3423
  <h2 class="runner-step-title">${t.title}</h2>
3394
3424
  <hr class="runner-step-divider" />
3395
- ${t.description?l`<p class="runner-step-desc">${t.description}</p>`:""}
3425
+ ${t.description?d`<p class="runner-step-desc">${t.description}</p>`:""}
3396
3426
  </section>
3397
- `}}class Dt{static renderFormActions(e){return e.mode==="preview"||e.mode==="view-only"||e.mode==="print"||!e.isCurrentStepAssigned?l``:l`
3427
+ `}}class Dt{static renderFormActions(e){return e.mode==="preview"||e.mode==="view-only"||e.mode==="print"||!e.isCurrentStepAssigned?d``:d`
3398
3428
  <div class="runner-form-actions">
3399
3429
  <button
3400
3430
  class="next-button ${e.mode==="admin"&&e.justSaved?"saved-state":""}"
@@ -3404,13 +3434,13 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3404
3434
  ${e.mode==="admin"?e.justSaved?"✓ Saved!":"Save":e.isLastStep?"Submit":"Next"}
3405
3435
  </button>
3406
3436
  </div>
3407
- `}}class ve{static handleInputChange(e,t,n,s,r,o){const a=t.target;let d;a.type==="radio"?d=a.value:a.type==="checkbox"?d=a.checked:d=a.value;const p={...n,[e]:d};s(p),o!=="preview"&&r(e,d)}static handleCheckboxChange(e,t,n,s,r,o){const d=t.target.checked,p={...n,[e]:d};s(p),o!=="preview"&&r(e,d)}static handleCheckboxGroupChange(e,t,n,s,r,o,a){const d=n.target,p=s[e];let c=Array.isArray(p)?[...p]:[];d.checked?c.includes(t)||c.push(t):c=c.filter(h=>h!==t);const u={...s,[e]:c};r(u),a!=="preview"&&o(e,c)}}var Ct=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,x=(i,e,t,n)=>{for(var s=n>1?void 0:n?Et(e,t):e,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=(n?o(e,t,s):o(s))||s);return n&&s&&Ct(e,t,s),s};let m=class extends R{constructor(){super(...arguments),this.mode="default",this.isLoading=!1,this._currentStepIndex=0,this._formData={},this._validationErrors={},this._internalCompletedSteps=new Set,this._formRestorationComplete=!1,this._savedSignatures=new Set,this._replacingSignatures=new Set,this._isSubmitted=!1,this._userStepsSubmitted=!1,this._justSaved=!1}willUpdate(i){(i.has("mode")||i.has("currentUser"))&&this._updateNavigationService(),(i.has("instance")||i.has("workflow")||i.has("mode"))&&(this._initializeState(),this._updateValidationService())}connectedCallback(){super.connectedCallback(),this._initializeServices(),this._initializeState(),window.addEventListener("resize",this._handleResize.bind(this)),this._restoreFormData()}disconnectedCallback(){var i;super.disconnectedCallback(),window.removeEventListener("resize",this._handleResize.bind(this)),(i=this.signatureManager)==null||i.destroy()}_initializeServices(){this.persistenceManager=new bt,this.responseTracker=new St,this.formStateManager=new fe,this.signatureManager=new _t(i=>this._handleSignatureChange(i)),this.fileUploadManager=new me(this.formStateManager,this.responseTracker),this._updateNavigationService(),this._updateValidationService()}_updateNavigationService(){this.navigationService=new yt(this.mode||"default",this.currentUser)}_updateValidationService(){var i;this.validationService=new mt(((i=this.signatureManager)==null?void 0:i.getAllSignaturePads())||new Map,this._savedSignatures)}_getRenderContext(){return{formData:this._formData,validationErrors:this._validationErrors,currentStepIndex:this._currentStepIndex,internalCompletedSteps:this._internalCompletedSteps,savedSignatures:this._savedSignatures,replacingSignatures:this._replacingSignatures,isSubmitted:this._isSubmitted,userStepsSubmitted:this._userStepsSubmitted,justSaved:this._justSaved,validationService:this.validationService,persistenceManager:this.persistenceManager,signatureManager:this.signatureManager,responseTracker:this.responseTracker,navigationService:this.navigationService,formStateManager:this.formStateManager,fileUploadManager:this.fileUploadManager,mode:this.mode||"default",instance:this.instance,workflow:this.workflow,currentUser:this.currentUser,isLoading:this.isLoading,handlers:{handleInputChange:this._handleInputChange.bind(this),handleCheckboxChange:this._handleCheckboxChange.bind(this),handleCheckboxGroupChange:this._handleCheckboxGroupChange.bind(this),startReplaceSignature:this._startReplaceSignature.bind(this),cancelReplaceSignature:this._cancelReplaceSignature.bind(this),clearSignature:this._clearSignature.bind(this),saveSignature:this._saveSignature.bind(this),handleFileUpload:this._handleFileUpload.bind(this),trackQuestionResponse:this._trackQuestionResponse.bind(this),isCurrentStepAssigned:this._isCurrentStepAssigned.bind(this)}}}_handleSignatureChange(i){this.formStateManager.setFormField(i.questionId,i.hasSignature),this.formStateManager.setFormField(`${i.questionId}_signatureData`,i.signatureData),this._formData=this.formStateManager.getFormData(),this._savedSignatures.has(i.questionId)&&(this._savedSignatures=new Set([...this._savedSignatures].filter(e=>e!==i.questionId))),this._clearValidationError(i.questionId),this.mode!=="admin"&&this._saveFormDataToHistory()}_clearValidationError(i){this.formStateManager.clearValidationError(i),this._validationErrors=this.formStateManager.getValidationErrors()}_updateFormData(i){this.formStateManager.updateFormData(i),this._formData=this.formStateManager.getFormData(),this.mode!=="admin"&&this._saveFormDataToHistory()}_handleFormDataUpdate(i){this._clearValidationError(i)}_initializeState(){var i,e,t;if((i=this.formStateManager)==null||i.reset(),this._validationErrors={},this._formData={},this._formRestorationComplete=!1,this._savedSignatures=new Set,this._replacingSignatures=new Set,this._savedInstance=void 0,this._justSaved=!1,this._isSubmitted=((e=this.instance)==null?void 0:e.status)==="completed"||!1,this.instance&&this.instance.status!=="completed"){const n=this._getAssignedSteps(),s=n.filter(r=>{var o;return(o=this.instance.completedSteps)==null?void 0:o.includes(r.id)});this._userStepsSubmitted=n.length>0&&s.length===n.length}else this._userStepsSubmitted=((t=this.instance)==null?void 0:t.status)==="completed"||!1;this.mode==="preview"&&this.workflow?this._initializePreviewMode():this.mode==="view-only"&&this.instance?this._initializeViewOnlyMode():this.mode==="print"&&this.instance?this._initializePrintMode():this.instance&&this._initializeDefaultMode()}_initializePreviewMode(){var i;if(console.log("Initializing preview mode..."),!((i=this.workflow)!=null&&i.steps)||this.workflow.steps.length===0){console.warn("Workflow has no steps in preview mode.");return}this.formStateManager.reset(),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this._internalCompletedSteps=new Set,console.log("Preview mode initialized with empty form data.")}_initializeDefaultMode(){var i;!((i=this.instance)!=null&&i.steps)||this.instance.steps.length===0||(this.instance.completedSteps?this._internalCompletedSteps=new Set(this.instance.completedSteps):this._internalCompletedSteps=new Set(this.instance.steps.filter(e=>e.status==="completed").map(e=>e.id)),this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=this.instance.steps.findIndex(e=>{var t;return e.id===((t=this.instance)==null?void 0:t.currentStepId)}),this._currentStepIndex<0&&(this._currentStepIndex=0),this.instance.steps.forEach((e,t)=>{this._internalCompletedSteps.has(e.id)?e.status="completed":t===this._currentStepIndex?e.status="active":e.status="pending"}))}_initializeViewOnlyMode(){var i;!((i=this.instance)!=null&&i.steps)||this.instance.steps.length===0||(this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this.instance.steps.forEach(e=>{e.responses&&e.responses.length>0?(e.status="completed",this._internalCompletedSteps.add(e.id)):e.status="pending"}),console.log("View-only mode initialized with existing responses:",this._formData))}_initializePrintMode(){var i;!((i=this.instance)!=null&&i.steps)||this.instance.steps.length===0||(this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this.instance.steps.forEach(e=>{e.responses&&e.responses.length>0?(e.status="completed",this._internalCompletedSteps.add(e.id)):e.status="pending"}),console.log("Print mode initialized with existing responses:",this._formData))}_isStepAssignedToUser(i){return this.navigationService.isStepAssignedToUser(i)}_getAssignedSteps(){return this.instance?this.navigationService.getAssignedSteps(this.instance):[]}_isCurrentStepAssigned(){const i=this._currentStep;return!i||this.mode!=="default"?!0:this._isStepAssignedToUser(i)}_renderNotAssignedView(){return Ne.renderNotAssignedView()}get _currentStep(){var i,e,t;return this.mode==="preview"&&this.workflow?(i=this.workflow.steps)==null?void 0:i[this._currentStepIndex]:(t=(e=this.instance)==null?void 0:e.steps)==null?void 0:t[this._currentStepIndex]}_validateStep(){const i=this._currentStep;if(!i)return!1;const e=this.validationService.validateStep(i,this._formData,this.mode||"default");return this.formStateManager.setValidationErrors(e.errors),this._validationErrors=this.formStateManager.getValidationErrors(),e.isValid}_handleInputChange(i,e){ve.handleInputChange(i,e,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(i)}_handleCheckboxChange(i,e){ve.handleCheckboxChange(i,e,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(i)}_handleCheckboxGroupChange(i,e,t){ve.handleCheckboxGroupChange(i,e,t,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(i)}_initializeSignaturePad(i){this.signatureManager.initializeSignaturePad(i,this.shadowRoot)&&this._updateValidationService()}_handleResize(){this.signatureManager.handleResize()}_clearSignature(i){this.signatureManager.clearSignature(i)}_startReplaceSignature(i){this._replacingSignatures=new Set([...this._replacingSignatures,i]),this.formStateManager.setFormField(i,!1),this.formStateManager.setFormField(`${i}_signatureData`,null),this._formData=this.formStateManager.getFormData(),this._savedSignatures=new Set([...this._savedSignatures].filter(e=>e!==i)),this.requestUpdate()}_cancelReplaceSignature(i){this._replacingSignatures=new Set([...this._replacingSignatures].filter(e=>e!==i))}_saveSignature(i){var n,s,r;const e=this.signatureManager.saveSignature(i);if(!e)return;const t=this._hasSignatureChanged(i,e.svgData);this._savedSignatures=new Set([...this._savedSignatures,i]),this._replacingSignatures.has(i)&&(this._replacingSignatures=new Set([...this._replacingSignatures].filter(o=>o!==i))),this._trackQuestionResponse(i,e.svgData),t&&this.mode!=="preview"?(console.log("Signature changed, calling callback for:",i),console.log("Callback function exists:",!!this.onSignatureCaptured),(r=this.onSignatureCaptured)==null||r.call(this,{instanceId:(n=this.instance)==null?void 0:n.id,stepId:(s=this._currentStep)==null?void 0:s.id,questionId:i,svgData:e.svgData,dataURL:e.dataURL})):this.mode==="preview"?console.log("Preview mode: skipping signature callback for:",i):console.log("Signature unchanged, skipping callback for:",i),this._clearValidationError(i),this.mode!=="admin"&&this._saveFormDataToHistory()}_hasSignatureChanged(i,e){return this.responseTracker.hasChangedFromPrevious(i,e,this._savedInstance)}_restoreInstanceResponses(){var i,e;!((i=this._savedInstance)!=null&&i.steps)||!((e=this.instance)!=null&&e.steps)||this._savedInstance.steps.forEach((t,n)=>{var s;(s=this.instance)!=null&&s.steps&&this.instance.steps[n]&&(this.instance.steps[n].responses=t.responses||[])})}_handleFileUpload(i,e){this.fileUploadManager.handleFileUpload(i,e,{instance:this.instance,currentStep:this._currentStep,mode:this.mode||"default",savedInstance:this._savedInstance,onFileUploaded:this.onFileUploaded,onFormDataSave:()=>this._saveFormDataToHistory(),onRequestUpdate:()=>{this._formData=this.formStateManager.getFormData(),this._validationErrors=this.formStateManager.getValidationErrors();const t=this._formData[i];t&&this._trackQuestionResponse(i,t),this.requestUpdate()}})}_captureSignaturesFromStep(i){console.log("Capturing signatures from step:",i.id)}_trackQuestionResponse(i,e){this.responseTracker.trackQuestionResponse(this._currentStep,i,e)}_renderQuestion(i){return y.render(i,this._getRenderContext())}_renderContentElement(i){return k.render(i,this._getRenderContext())}_isQuestionElement(i){return m.QUESTION_ELEMENT_TYPES.includes(i.type)}_isContentElement(i){return m.CONTENT_ELEMENT_TYPES.includes(i.type)}_renderStepElement(i){return this.mode==="print"?this._isQuestionElement(i)?this._renderQuestion(i):this._isContentElement(i)?this._renderContentElement(i):l`<div class="unknown-element">
3437
+ `}}class ve{static handleInputChange(e,t,n,s,r,o){const a=t.target;let l;a.type==="radio"?l=a.value:a.type==="checkbox"?l=a.checked:l=a.value;const p={...n,[e]:l};s(p),o!=="preview"&&r(e,l)}static handleCheckboxChange(e,t,n,s,r,o){const l=t.target.checked,p={...n,[e]:l};s(p),o!=="preview"&&r(e,l)}static handleCheckboxGroupChange(e,t,n,s,r,o,a){const l=n.target,p=s[e];let c=Array.isArray(p)?[...p]:[];l.checked?c.includes(t)||c.push(t):c=c.filter(h=>h!==t);const u={...s,[e]:c};r(u),a!=="preview"&&o(e,c)}}var Ct=Object.defineProperty,Et=Object.getOwnPropertyDescriptor,x=(i,e,t,n)=>{for(var s=n>1?void 0:n?Et(e,t):e,r=i.length-1,o;r>=0;r--)(o=i[r])&&(s=(n?o(e,t,s):o(s))||s);return n&&s&&Ct(e,t,s),s};let m=class extends R{constructor(){super(...arguments),this.mode="default",this.isLoading=!1,this._currentStepIndex=0,this._formData={},this._validationErrors={},this._internalCompletedSteps=new Set,this._formRestorationComplete=!1,this._savedSignatures=new Set,this._replacingSignatures=new Set,this._isSubmitted=!1,this._userStepsSubmitted=!1,this._justSaved=!1}willUpdate(i){(i.has("mode")||i.has("currentUser"))&&this._updateNavigationService(),(i.has("instance")||i.has("workflow")||i.has("mode"))&&(this._initializeState(),this._updateValidationService())}connectedCallback(){super.connectedCallback(),this._initializeServices(),this._initializeState(),window.addEventListener("resize",this._handleResize.bind(this)),this._restoreFormData()}disconnectedCallback(){var i;super.disconnectedCallback(),window.removeEventListener("resize",this._handleResize.bind(this)),(i=this.signatureManager)==null||i.destroy()}_initializeServices(){this.persistenceManager=new bt,this.responseTracker=new St,this.formStateManager=new fe,this.signatureManager=new _t(i=>this._handleSignatureChange(i)),this.fileUploadManager=new me(this.formStateManager,this.responseTracker),this._updateNavigationService(),this._updateValidationService()}_updateNavigationService(){this.navigationService=new yt(this.mode||"default",this.currentUser)}_updateValidationService(){var i;this.validationService=new mt(((i=this.signatureManager)==null?void 0:i.getAllSignaturePads())||new Map,this._savedSignatures)}_getRenderContext(){return{formData:this._formData,validationErrors:this._validationErrors,currentStepIndex:this._currentStepIndex,internalCompletedSteps:this._internalCompletedSteps,savedSignatures:this._savedSignatures,replacingSignatures:this._replacingSignatures,isSubmitted:this._isSubmitted,userStepsSubmitted:this._userStepsSubmitted,justSaved:this._justSaved,validationService:this.validationService,persistenceManager:this.persistenceManager,signatureManager:this.signatureManager,responseTracker:this.responseTracker,navigationService:this.navigationService,formStateManager:this.formStateManager,fileUploadManager:this.fileUploadManager,mode:this.mode||"default",instance:this.instance,workflow:this.workflow,currentUser:this.currentUser,isLoading:this.isLoading,handlers:{handleInputChange:this._handleInputChange.bind(this),handleCheckboxChange:this._handleCheckboxChange.bind(this),handleCheckboxGroupChange:this._handleCheckboxGroupChange.bind(this),startReplaceSignature:this._startReplaceSignature.bind(this),cancelReplaceSignature:this._cancelReplaceSignature.bind(this),clearSignature:this._clearSignature.bind(this),saveSignature:this._saveSignature.bind(this),handleFileUpload:this._handleFileUpload.bind(this),trackQuestionResponse:this._trackQuestionResponse.bind(this),isCurrentStepAssigned:this._isCurrentStepAssigned.bind(this)}}}_handleSignatureChange(i){this.formStateManager.setFormField(i.questionId,i.hasSignature),this.formStateManager.setFormField(`${i.questionId}_signatureData`,i.signatureData),this._formData=this.formStateManager.getFormData(),this._savedSignatures.has(i.questionId)&&(this._savedSignatures=new Set([...this._savedSignatures].filter(e=>e!==i.questionId))),this._clearValidationError(i.questionId),this.mode!=="admin"&&this._saveFormDataToHistory()}_clearValidationError(i){this.formStateManager.clearValidationError(i),this._validationErrors=this.formStateManager.getValidationErrors()}_updateFormData(i){this.formStateManager.updateFormData(i),this._formData=this.formStateManager.getFormData(),this.mode!=="admin"&&this._saveFormDataToHistory()}_handleFormDataUpdate(i){this._clearValidationError(i)}_initializeState(){var i,e,t;if((i=this.formStateManager)==null||i.reset(),this._validationErrors={},this._formData={},this._formRestorationComplete=!1,this._savedSignatures=new Set,this._replacingSignatures=new Set,this._savedInstance=void 0,this._justSaved=!1,this._isSubmitted=((e=this.instance)==null?void 0:e.status)==="completed"||!1,this.instance&&this.instance.status!=="completed"){const n=this._getAssignedSteps(),s=n.filter(r=>{var o;return(o=this.instance.completedSteps)==null?void 0:o.includes(r.id)});this._userStepsSubmitted=n.length>0&&s.length===n.length}else this._userStepsSubmitted=((t=this.instance)==null?void 0:t.status)==="completed"||!1;this.mode==="preview"&&this.workflow?this._initializePreviewMode():this.mode==="view-only"&&this.instance?this._initializeViewOnlyMode():this.mode==="print"&&this.instance?this._initializePrintMode():this.instance&&this._initializeDefaultMode()}_initializePreviewMode(){var i;if(console.log("Initializing preview mode..."),!((i=this.workflow)!=null&&i.steps)||this.workflow.steps.length===0){console.warn("Workflow has no steps in preview mode.");return}this.formStateManager.reset(),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this._internalCompletedSteps=new Set,console.log("Preview mode initialized with empty form data.")}_initializeDefaultMode(){var i;!((i=this.instance)!=null&&i.steps)||this.instance.steps.length===0||(this.instance.completedSteps?this._internalCompletedSteps=new Set(this.instance.completedSteps):this._internalCompletedSteps=new Set(this.instance.steps.filter(e=>e.status==="completed").map(e=>e.id)),this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=this.instance.steps.findIndex(e=>{var t;return e.id===((t=this.instance)==null?void 0:t.currentStepId)}),this._currentStepIndex<0&&(this._currentStepIndex=0),this.instance.steps.forEach((e,t)=>{this._internalCompletedSteps.has(e.id)?e.status="completed":t===this._currentStepIndex?e.status="active":e.status="pending"}))}_initializeViewOnlyMode(){var i;!((i=this.instance)!=null&&i.steps)||this.instance.steps.length===0||(this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this.instance.steps.forEach(e=>{e.responses&&e.responses.length>0?(e.status="completed",this._internalCompletedSteps.add(e.id)):e.status="pending"}),console.log("View-only mode initialized with existing responses:",this._formData))}_initializePrintMode(){var i;!((i=this.instance)!=null&&i.steps)||this.instance.steps.length===0||(this.formStateManager.initializeFromResponses(this.instance.steps),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=0,this.instance.steps.forEach(e=>{e.responses&&e.responses.length>0?(e.status="completed",this._internalCompletedSteps.add(e.id)):e.status="pending"}),console.log("Print mode initialized with existing responses:",this._formData))}_isStepAssignedToUser(i){return this.navigationService.isStepAssignedToUser(i)}_getAssignedSteps(){return this.instance?this.navigationService.getAssignedSteps(this.instance):[]}_isCurrentStepAssigned(){const i=this._currentStep;return!i||this.mode!=="default"?!0:this._isStepAssignedToUser(i)}_renderNotAssignedView(){return Ne.renderNotAssignedView()}get _currentStep(){var i,e,t;return this.mode==="preview"&&this.workflow?(i=this.workflow.steps)==null?void 0:i[this._currentStepIndex]:(t=(e=this.instance)==null?void 0:e.steps)==null?void 0:t[this._currentStepIndex]}_validateStep(){const i=this._currentStep;if(!i)return!1;const e=this.validationService.validateStep(i,this._formData,this.mode||"default");return this.formStateManager.setValidationErrors(e.errors),this._validationErrors=this.formStateManager.getValidationErrors(),e.isValid}_handleInputChange(i,e){ve.handleInputChange(i,e,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(i)}_handleCheckboxChange(i,e){ve.handleCheckboxChange(i,e,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(i)}_handleCheckboxGroupChange(i,e,t){ve.handleCheckboxGroupChange(i,e,t,this._formData,this._updateFormData.bind(this),this._trackQuestionResponse.bind(this),this.mode),this._handleFormDataUpdate(i)}_initializeSignaturePad(i){this.signatureManager.initializeSignaturePad(i,this.shadowRoot)&&this._updateValidationService()}_handleResize(){this.signatureManager.handleResize()}_clearSignature(i){this.signatureManager.clearSignature(i)}_startReplaceSignature(i){this._replacingSignatures=new Set([...this._replacingSignatures,i]),this.formStateManager.setFormField(i,!1),this.formStateManager.setFormField(`${i}_signatureData`,null),this._formData=this.formStateManager.getFormData(),this._savedSignatures=new Set([...this._savedSignatures].filter(e=>e!==i)),this.requestUpdate()}_cancelReplaceSignature(i){this._replacingSignatures=new Set([...this._replacingSignatures].filter(e=>e!==i))}_saveSignature(i){var n,s,r;const e=this.signatureManager.saveSignature(i);if(!e)return;const t=this._hasSignatureChanged(i,e.svgData);this._savedSignatures=new Set([...this._savedSignatures,i]),this._replacingSignatures.has(i)&&(this._replacingSignatures=new Set([...this._replacingSignatures].filter(o=>o!==i))),this._trackQuestionResponse(i,e.svgData),t&&this.mode!=="preview"?(console.log("Signature changed, calling callback for:",i),console.log("Callback function exists:",!!this.onSignatureCaptured),(r=this.onSignatureCaptured)==null||r.call(this,{instanceId:(n=this.instance)==null?void 0:n.id,stepId:(s=this._currentStep)==null?void 0:s.id,questionId:i,svgData:e.svgData,dataURL:e.dataURL})):this.mode==="preview"?console.log("Preview mode: skipping signature callback for:",i):console.log("Signature unchanged, skipping callback for:",i),this._clearValidationError(i),this.mode!=="admin"&&this._saveFormDataToHistory()}_hasSignatureChanged(i,e){return this.responseTracker.hasChangedFromPrevious(i,e,this._savedInstance)}_restoreInstanceResponses(){var i,e;!((i=this._savedInstance)!=null&&i.steps)||!((e=this.instance)!=null&&e.steps)||this._savedInstance.steps.forEach((t,n)=>{var s;(s=this.instance)!=null&&s.steps&&this.instance.steps[n]&&(this.instance.steps[n].responses=t.responses||[])})}_handleFileUpload(i,e){this.fileUploadManager.handleFileUpload(i,e,{instance:this.instance,currentStep:this._currentStep,mode:this.mode||"default",savedInstance:this._savedInstance,onFileUploaded:this.onFileUploaded,onFormDataSave:()=>this._saveFormDataToHistory(),onRequestUpdate:()=>{this._formData=this.formStateManager.getFormData(),this._validationErrors=this.formStateManager.getValidationErrors();const t=this._formData[i];t&&this._trackQuestionResponse(i,t),this.requestUpdate()}})}_captureSignaturesFromStep(i){console.log("Capturing signatures from step:",i.id)}_trackQuestionResponse(i,e){this.responseTracker.trackQuestionResponse(this._currentStep,i,e)}_renderQuestion(i){return y.render(i,this._getRenderContext())}_renderContentElement(i){return k.render(i,this._getRenderContext())}_isQuestionElement(i){return m.QUESTION_ELEMENT_TYPES.includes(i.type)}_isContentElement(i){return m.CONTENT_ELEMENT_TYPES.includes(i.type)}_renderStepElement(i){return this.mode==="print"?this._isQuestionElement(i)?this._renderQuestion(i):this._isContentElement(i)?this._renderContentElement(i):d`<div class="unknown-element">
3408
3438
  <p>⚠️ Unknown element type: ${i.type}</p>
3409
- </div>`:this._isQuestionElement(i)?l`<div class="runner-card">${this._renderQuestion(i)}</div>`:this._isContentElement(i)?l`<div class="runner-card">${this._renderContentElement(i)}</div>`:l`<div class="runner-card">
3439
+ </div>`:this._isQuestionElement(i)?d`<div class="runner-card">${this._renderQuestion(i)}</div>`:this._isContentElement(i)?d`<div class="runner-card">${this._renderContentElement(i)}</div>`:d`<div class="runner-card">
3410
3440
  <div class="unknown-element">
3411
3441
  <p>⚠️ Unknown element type: ${i.type}</p>
3412
3442
  </div>
3413
- </div>`}_renderStepWithElements(i){return l`
3443
+ </div>`}_renderStepWithElements(i){return d`
3414
3444
  <div class="print-step">
3415
3445
  <!-- Step Header -->
3416
3446
  ${Y.renderStepHeader({step:i,mode:"print"})}
@@ -3418,9 +3448,9 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3418
3448
  <!-- Step Elements -->
3419
3449
  ${i.elements.map(e=>this._renderStepElement(e))}
3420
3450
  </div>
3421
- `}_renderAllStepsForPrint(){var i;return!((i=this.instance)!=null&&i.steps)||this.instance.steps.length===0?l`<div class="runner-content">
3451
+ `}_renderAllStepsForPrint(){var i;return!((i=this.instance)!=null&&i.steps)||this.instance.steps.length===0?d`<div class="runner-content">
3422
3452
  No workflow instance loaded or instance has no steps.
3423
- </div>`:l`
3453
+ </div>`:d`
3424
3454
  <div class="print-layout">
3425
3455
  <!-- Instance Title at top -->
3426
3456
  <div class="print-instance-title">${this.instance.name||"Untitled Form"}</div>
@@ -3428,9 +3458,9 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3428
3458
 
3429
3459
  ${this.instance.steps.map(e=>this._renderStepWithElements(e))}
3430
3460
  </div>
3431
- `}_nextStep(){var t,n,s,r;if(!this._validateStep())return;const i=this._currentStep;i&&this._captureSignaturesFromStep(i);const e=this._findNextAssignedStep(this._currentStepIndex);if(e!==-1){const o=(t=this._currentStep)==null?void 0:t.id;if(this._currentStepIndex=e,o&&((n=this.instance)!=null&&n.steps)){const d=this.instance.steps.find(p=>p.id===o);d&&(d.status="completed")}const a=(r=(s=this.instance)==null?void 0:s.steps)==null?void 0:r[this._currentStepIndex];a&&(a.status="active"),this._updateInstanceData(o,"step_navigation",{direction:"next",fromStepIndex:this._currentStepIndex-1,toStepIndex:this._currentStepIndex,completedStepId:o}),this.mode!=="admin"&&this._saveFormDataToHistory(),this._scrollToTop()}}_findNextAssignedStep(i){return this.instance?this.navigationService.findNextAssignedStep(i,this.instance):-1}_isLastAssignedStep(){return this.navigationService.isLastAssignedStep(this._currentStepIndex,this.instance)}_isLastStepInWorkflow(){var e;const i=(e=this.instance)==null?void 0:e.steps;return i?this._currentStepIndex===i.length-1:!1}_goToStep(i){var n;console.log(`🎯 _goToStep called: stepIndex=${i}, mode=${this.mode}, currentStep=${this._currentStepIndex}`);const e=this.mode==="preview"?this.workflow:this.instance;if(console.log("📊 Data source:",e?`${((n=e.steps)==null?void 0:n.length)||0} steps`:"null"),!e){console.log("❌ No data source available");return}const t=this.navigationService.canNavigateToStep(i,this._currentStepIndex,e,this._internalCompletedSteps,this._isSubmitted,this._userStepsSubmitted);console.log("🚦 Navigation result:",t),t.canNavigate?(this._currentStepIndex=t.newStepIndex,console.log(`✅ Navigated to step ${t.newStepIndex}`),this._scrollToTop()):console.log("❌ Navigation blocked:",t.reason)}_submitUserSteps(){var t;if(!this._validateStep())return;const i=this._currentStep;if(i&&this._captureSignaturesFromStep(i),!this.instance){console.error("Cannot submit, instance data is missing.");return}const e=(t=this._currentStep)==null?void 0:t.id;e&&this._internalCompletedSteps.add(e),console.log("User completing their assigned steps:",this.instance.id),console.log("Form data:",this._formData),this._userStepsSubmitted=!0,this._clearSavedFormData("user steps submission"),this._updateInstanceData(e,"user_steps_submission"),this._scrollToTop()}_submit(){var t;if(!this._validateStep())return;const i=this._currentStep;if(i&&this._captureSignaturesFromStep(i),!this.instance){console.error("Cannot submit, instance data is missing.");return}const e=(t=this._currentStep)==null?void 0:t.id;e&&this._internalCompletedSteps.add(e),console.log("Submitting entire workflow:",this.instance.id),console.log("Final form data:",this._formData),this.instance&&(this.instance.status="completed",this.instance.updatedAt=new Date,this.instance.currentStepId=void 0,this.instance.completedSteps=Array.from(this._internalCompletedSteps)),this._isSubmitted=!0,this._clearSavedFormData("full workflow submission"),this._scrollToTop(),this._updateInstanceData(e,"submission")}_saveStep(){var t;if(!this._validateStep())return;const i=this._currentStep;if(i&&this._captureSignaturesFromStep(i),!this.instance){console.error("Cannot save, instance data is missing.");return}const e=(t=this._currentStep)==null?void 0:t.id;if(e&&(this._internalCompletedSteps.add(e),this.instance.steps)){const n=this.instance.steps.find(s=>s.id===e);n&&(n.status="completed")}this._updateInstanceData(e,"admin_save",{stepId:e,adminMode:!0}),this._justSaved=!0,this.requestUpdate(),setTimeout(()=>{this._justSaved=!1,this.requestUpdate()},2e3)}_clearSavedFormData(i){var e;this.persistenceManager.clearFormData((e=this.instance)==null?void 0:e.id,i)}_scrollToTop(){requestAnimationFrame(()=>{var t,n;this.scrollIntoView({behavior:"smooth",block:"start"});const i=(t=this.shadowRoot)==null?void 0:t.querySelector(".runner-layout");i&&i.scrollTo({top:0,behavior:"smooth"});const e=(n=this.shadowRoot)==null?void 0:n.querySelector(".runner-main-content");e&&e.scrollTo({top:0,behavior:"smooth"})})}_updateInstanceData(i,e,t){var d,p,c,u,h,f,b;i&&this._internalCompletedSteps.add(i);let n=(p=(d=this.instance)==null?void 0:d.steps)==null?void 0:p.find($=>$.id===i);if(!n&&this._internalCompletedSteps.size>0){const $=Array.from(this._internalCompletedSteps),ie=$[$.length-1];n=(u=(c=this.instance)==null?void 0:c.steps)==null?void 0:u.find(ne=>ne.id===ie)}const s=e==="submission",r=((h=this.instance)==null?void 0:h.steps)&&this._internalCompletedSteps.size>=this.instance.steps.length,o=s||r?null:this._currentStep?{id:this._currentStep.id,title:this._currentStep.title}:null,a={instanceId:(f=this.instance)==null?void 0:f.id,workflowId:(b=this.instance)==null?void 0:b.workflowId,completedStepId:i||(n?n.id:null),completedStepData:n?{id:n.id,title:n.title,responses:n.responses||[]}:null,completedSteps:Array.from(this._internalCompletedSteps),currentStep:o,mode:this.mode};this.dispatchEvent(new CustomEvent("instance-updated",{detail:a,bubbles:!0,composed:!0}))}_restoreFormData(){var e;if(!this.persistenceManager.shouldRestoreData(this.mode||"default")){console.log("Skipping form data restoration - showing official instance data");return}const i=this.persistenceManager.restoreFormData((e=this.instance)==null?void 0:e.id);i?(this.formStateManager.updateFormData(i.formData),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=i.stepIndex,this._savedSignatures=i.savedSignatures,this._internalCompletedSteps=i.completedSteps,this._savedInstance=i.savedInstance||void 0):this._updateCompletedStepsFromCurrentIndex()}_updateCompletedStepsFromCurrentIndex(){var i;if((i=this.instance)!=null&&i.steps){this._internalCompletedSteps=new Set(this.instance.completedSteps||[]);for(let e=0;e<this._currentStepIndex;e++)this.instance.steps[e]&&this._internalCompletedSteps.add(this.instance.steps[e].id)}}_restoreFormDataFromDOM(){this._restoreFormData(),this._restoreFormValuesToDOM()}_restoreFormValuesToDOM(){this.updateComplete.then(()=>{var e,t;(e=this.shadowRoot)!=null&&e.querySelector(".runner-step-form")&&(Object.entries(this._formData).forEach(([n,s])=>{var o;if(n.endsWith("_signatureData"))return;const r=(o=this.shadowRoot)==null?void 0:o.getElementById(n);if(r){if(r.type==="checkbox"){const a=r;typeof s=="boolean"?a.checked=s:Array.isArray(s)&&(a.checked=s.includes(a.value))}else if(r.type==="radio"){const a=r;a.checked=a.value===s}else if(r.type==="file"){const a=r;a.value=""}else r.value=String(s||"");console.log(`Restored value for ${n}:`,s)}}),this._restoreSignatures(),console.log("Form values restored to DOM elements"),this._updateInstanceWithFormData(!0),(t=this._savedInstance)!=null&&t.steps&&this._restoreInstanceResponses())})}_updateInstanceWithFormData(i=!1){this.instance&&this.instance.steps&&this.instance.steps.forEach(e=>{e.responses||(e.responses=[]),e.elements.forEach(t=>{if(t.type==="text_input"||t.type==="textarea"||t.type==="select"||t.type==="number"||t.type==="radio"||t.type==="checkbox"||t.type==="date"||t.type==="file_upload"||t.type==="signature"){const n=t,s=this._formData[n.id];if(s!==void 0&&e.responses){let r=e.responses.find(o=>o.elementId===n.id);r?(r.value=s,r.answeredAt=new Date):(r={elementId:n.id,value:s,answeredAt:new Date},e.responses.push(r))}}})})}_restoreSignatures(){Object.entries(this._formData).forEach(([i,e])=>{if(i.endsWith("_signatureData")&&e){const t=i.replace("_signatureData",""),n=this.signatureManager.getSignaturePad(t);if(n&&e)try{n.clear(),n.fromData(e)}catch{}}})}_saveFormDataToHistory(){var i;this.persistenceManager.saveFormData((i=this.instance)==null?void 0:i.id,this._formData,this._currentStepIndex,this._savedSignatures,this._internalCompletedSteps,this.instance||null)}_extractFormDataFromDOM(){var n;const i={},e=(n=this.shadowRoot)==null?void 0:n.querySelector(".runner-step-form");if(!e)return i;const t=e.elements;for(let s=0;s<t.length;s++){const r=t[s];if(r.name||r.id){const o=r.id||r.name;if(r.type==="checkbox"){const a=r;a.name&&a.name===o?(i[o]||(i[o]=[]),a.checked&&i[o].push(a.value)):i[o]=a.checked}else if(r.type==="radio"){const a=r;a.checked&&(i[o]=a.value)}else i[o]=r.value}}return i}_updateInstanceFromFormData(i=!1){const e=this._extractFormDataFromDOM();Object.keys(e).length>0?(this.formStateManager.mergeFormData(e),this._formData=this.formStateManager.getFormData(),this.instance&&this.instance.steps&&this.instance.steps.forEach(n=>{n.responses||(n.responses=[]),n.elements.forEach(s=>{if(s.type==="text_input"||s.type==="textarea"||s.type==="select"||s.type==="number"||s.type==="radio"||s.type==="checkbox"||s.type==="date"||s.type==="file_upload"||s.type==="signature"){const r=s,o=this._formData[r.id];if(o!==void 0&&n.responses){let a=n.responses.find(d=>d.elementId===r.id);a?(a.value=o,a.answeredAt=new Date):(a={elementId:r.id,value:o,answeredAt:new Date},n.responses.push(a))}}})}),console.log("Instance updated from form data:",this.instance),i&&this._updateInstanceData(void 0,"form_data_update",{updatedFormDataKeys:Object.keys(this._formData),updatedCompletedSteps:Array.from(this._internalCompletedSteps)})):console.log("No new form data to update instance with")}updateInstanceFromFormData(i=!1){this._updateInstanceFromFormData(i)}getFormData(){return this.formStateManager.getFormData()}restoreFormData(){this._restoreFormDataFromDOM()}clearSavedFormData(i){this._clearSavedFormData(i)}_renderUnifiedSubmissionView(){const i={instance:this.instance,assignedSteps:this._getAssignedSteps(),completedSteps:this._internalCompletedSteps,isStepAssignedToUser:this._isStepAssignedToUser.bind(this)};return Ne.renderUnifiedSubmissionView(i)}_isInstanceCompleted(){var i;return((i=this.instance)==null?void 0:i.status)==="completed"}_areUserStepsCompleted(){var e;if(!((e=this.instance)!=null&&e.steps))return!1;const i=this._getAssignedSteps();return i.length===0?!1:i.every(t=>t.status==="completed")}_shouldShowCompletionView(){var i;return this.mode!=="default"?!1:!!(this._isInstanceCompleted()||((i=this.instance)==null?void 0:i.status)==="active"&&this._areUserStepsCompleted())}_renderModeBasedContent(){var e,t;if(this._shouldShowCompletionView())return this._renderUnifiedSubmissionView();if(this.mode==="print")return this._renderAllStepsForPrint();const i=this.mode==="preview"?(e=this.workflow)==null?void 0:e.steps:(t=this.instance)==null?void 0:t.steps;return!i||i.length===0?l`<div class="runner-content">
3461
+ `}_nextStep(){var t,n,s,r;if(!this._validateStep())return;const i=this._currentStep;i&&this._captureSignaturesFromStep(i);const e=this._findNextAssignedStep(this._currentStepIndex);if(e!==-1){const o=(t=this._currentStep)==null?void 0:t.id;if(this._currentStepIndex=e,o&&((n=this.instance)!=null&&n.steps)){const l=this.instance.steps.find(p=>p.id===o);l&&(l.status="completed")}const a=(r=(s=this.instance)==null?void 0:s.steps)==null?void 0:r[this._currentStepIndex];a&&(a.status="active"),this._updateInstanceData(o,"step_navigation",{direction:"next",fromStepIndex:this._currentStepIndex-1,toStepIndex:this._currentStepIndex,completedStepId:o}),this.mode!=="admin"&&this._saveFormDataToHistory(),this._scrollToTop()}}_findNextAssignedStep(i){return this.instance?this.navigationService.findNextAssignedStep(i,this.instance):-1}_isLastAssignedStep(){return this.navigationService.isLastAssignedStep(this._currentStepIndex,this.instance)}_isLastStepInWorkflow(){var e;const i=(e=this.instance)==null?void 0:e.steps;return i?this._currentStepIndex===i.length-1:!1}_goToStep(i){var n;console.log(`🎯 _goToStep called: stepIndex=${i}, mode=${this.mode}, currentStep=${this._currentStepIndex}`);const e=this.mode==="preview"?this.workflow:this.instance;if(console.log("📊 Data source:",e?`${((n=e.steps)==null?void 0:n.length)||0} steps`:"null"),!e){console.log("❌ No data source available");return}const t=this.navigationService.canNavigateToStep(i,this._currentStepIndex,e,this._internalCompletedSteps,this._isSubmitted,this._userStepsSubmitted);console.log("🚦 Navigation result:",t),t.canNavigate?(this._currentStepIndex=t.newStepIndex,console.log(`✅ Navigated to step ${t.newStepIndex}`),this._scrollToTop()):console.log("❌ Navigation blocked:",t.reason)}_submitUserSteps(){var t;if(!this._validateStep())return;const i=this._currentStep;if(i&&this._captureSignaturesFromStep(i),!this.instance){console.error("Cannot submit, instance data is missing.");return}const e=(t=this._currentStep)==null?void 0:t.id;e&&this._internalCompletedSteps.add(e),console.log("User completing their assigned steps:",this.instance.id),console.log("Form data:",this._formData),this._userStepsSubmitted=!0,this._clearSavedFormData("user steps submission"),this._updateInstanceData(e,"user_steps_submission"),this._scrollToTop()}_submit(){var t;if(!this._validateStep())return;const i=this._currentStep;if(i&&this._captureSignaturesFromStep(i),!this.instance){console.error("Cannot submit, instance data is missing.");return}const e=(t=this._currentStep)==null?void 0:t.id;e&&this._internalCompletedSteps.add(e),console.log("Submitting entire workflow:",this.instance.id),console.log("Final form data:",this._formData),this.instance&&(this.instance.status="completed",this.instance.updatedAt=new Date,this.instance.currentStepId=void 0,this.instance.completedSteps=Array.from(this._internalCompletedSteps)),this._isSubmitted=!0,this._clearSavedFormData("full workflow submission"),this._scrollToTop(),this._updateInstanceData(e,"submission")}_saveStep(){var t;if(!this._validateStep())return;const i=this._currentStep;if(i&&this._captureSignaturesFromStep(i),!this.instance){console.error("Cannot save, instance data is missing.");return}const e=(t=this._currentStep)==null?void 0:t.id;if(e&&(this._internalCompletedSteps.add(e),this.instance.steps)){const n=this.instance.steps.find(s=>s.id===e);n&&(n.status="completed")}this._updateInstanceData(e,"admin_save",{stepId:e,adminMode:!0}),this._justSaved=!0,this.requestUpdate(),setTimeout(()=>{this._justSaved=!1,this.requestUpdate()},2e3)}_clearSavedFormData(i){var e;this.persistenceManager.clearFormData((e=this.instance)==null?void 0:e.id,i)}_scrollToTop(){requestAnimationFrame(()=>{var t,n;this.scrollIntoView({behavior:"smooth",block:"start"});const i=(t=this.shadowRoot)==null?void 0:t.querySelector(".runner-layout");i&&i.scrollTo({top:0,behavior:"smooth"});const e=(n=this.shadowRoot)==null?void 0:n.querySelector(".runner-main-content");e&&e.scrollTo({top:0,behavior:"smooth"})})}_updateInstanceData(i,e,t){var l,p,c,u,h,f,b;i&&this._internalCompletedSteps.add(i);let n=(p=(l=this.instance)==null?void 0:l.steps)==null?void 0:p.find($=>$.id===i);if(!n&&this._internalCompletedSteps.size>0){const $=Array.from(this._internalCompletedSteps),ie=$[$.length-1];n=(u=(c=this.instance)==null?void 0:c.steps)==null?void 0:u.find(ne=>ne.id===ie)}const s=e==="submission",r=((h=this.instance)==null?void 0:h.steps)&&this._internalCompletedSteps.size>=this.instance.steps.length,o=s||r?null:this._currentStep?{id:this._currentStep.id,title:this._currentStep.title}:null,a={instanceId:(f=this.instance)==null?void 0:f.id,workflowId:(b=this.instance)==null?void 0:b.workflowId,completedStepId:i||(n?n.id:null),completedStepData:n?{id:n.id,title:n.title,responses:n.responses||[]}:null,completedSteps:Array.from(this._internalCompletedSteps),currentStep:o,mode:this.mode};this.dispatchEvent(new CustomEvent("instance-updated",{detail:a,bubbles:!0,composed:!0}))}_restoreFormData(){var e;if(!this.persistenceManager.shouldRestoreData(this.mode||"default")){console.log("Skipping form data restoration - showing official instance data");return}const i=this.persistenceManager.restoreFormData((e=this.instance)==null?void 0:e.id);i?(this.formStateManager.updateFormData(i.formData),this._formData=this.formStateManager.getFormData(),this._currentStepIndex=i.stepIndex,this._savedSignatures=i.savedSignatures,this._internalCompletedSteps=i.completedSteps,this._savedInstance=i.savedInstance||void 0):this._updateCompletedStepsFromCurrentIndex()}_updateCompletedStepsFromCurrentIndex(){var i;if((i=this.instance)!=null&&i.steps){this._internalCompletedSteps=new Set(this.instance.completedSteps||[]);for(let e=0;e<this._currentStepIndex;e++)this.instance.steps[e]&&this._internalCompletedSteps.add(this.instance.steps[e].id)}}_restoreFormDataFromDOM(){this._restoreFormData(),this._restoreFormValuesToDOM()}_restoreFormValuesToDOM(){this.updateComplete.then(()=>{var e,t;(e=this.shadowRoot)!=null&&e.querySelector(".runner-step-form")&&(Object.entries(this._formData).forEach(([n,s])=>{var o;if(n.endsWith("_signatureData"))return;const r=(o=this.shadowRoot)==null?void 0:o.getElementById(n);if(r){if(r.type==="checkbox"){const a=r;typeof s=="boolean"?a.checked=s:Array.isArray(s)&&(a.checked=s.includes(a.value))}else if(r.type==="radio"){const a=r;a.checked=a.value===s}else if(r.type==="file"){const a=r;a.value=""}else r.value=String(s||"");console.log(`Restored value for ${n}:`,s)}}),this._restoreSignatures(),console.log("Form values restored to DOM elements"),this._updateInstanceWithFormData(!0),(t=this._savedInstance)!=null&&t.steps&&this._restoreInstanceResponses())})}_updateInstanceWithFormData(i=!1){this.instance&&this.instance.steps&&this.instance.steps.forEach(e=>{e.responses||(e.responses=[]),e.elements.forEach(t=>{if(t.type==="text_input"||t.type==="textarea"||t.type==="select"||t.type==="number"||t.type==="radio"||t.type==="checkbox"||t.type==="date"||t.type==="file_upload"||t.type==="signature"){const n=t,s=this._formData[n.id];if(s!==void 0&&e.responses){let r=e.responses.find(o=>o.elementId===n.id);r?(r.value=s,r.answeredAt=new Date):(r={elementId:n.id,value:s,answeredAt:new Date},e.responses.push(r))}}})})}_restoreSignatures(){Object.entries(this._formData).forEach(([i,e])=>{if(i.endsWith("_signatureData")&&e){const t=i.replace("_signatureData",""),n=this.signatureManager.getSignaturePad(t);if(n&&e)try{n.clear(),n.fromData(e)}catch{}}})}_saveFormDataToHistory(){var i;this.persistenceManager.saveFormData((i=this.instance)==null?void 0:i.id,this._formData,this._currentStepIndex,this._savedSignatures,this._internalCompletedSteps,this.instance||null)}_extractFormDataFromDOM(){var n;const i={},e=(n=this.shadowRoot)==null?void 0:n.querySelector(".runner-step-form");if(!e)return i;const t=e.elements;for(let s=0;s<t.length;s++){const r=t[s];if(r.name||r.id){const o=r.id||r.name;if(r.type==="checkbox"){const a=r;a.name&&a.name===o?(i[o]||(i[o]=[]),a.checked&&i[o].push(a.value)):i[o]=a.checked}else if(r.type==="radio"){const a=r;a.checked&&(i[o]=a.value)}else i[o]=r.value}}return i}_updateInstanceFromFormData(i=!1){const e=this._extractFormDataFromDOM();Object.keys(e).length>0?(this.formStateManager.mergeFormData(e),this._formData=this.formStateManager.getFormData(),this.instance&&this.instance.steps&&this.instance.steps.forEach(n=>{n.responses||(n.responses=[]),n.elements.forEach(s=>{if(s.type==="text_input"||s.type==="textarea"||s.type==="select"||s.type==="number"||s.type==="radio"||s.type==="checkbox"||s.type==="date"||s.type==="file_upload"||s.type==="signature"){const r=s,o=this._formData[r.id];if(o!==void 0&&n.responses){let a=n.responses.find(l=>l.elementId===r.id);a?(a.value=o,a.answeredAt=new Date):(a={elementId:r.id,value:o,answeredAt:new Date},n.responses.push(a))}}})}),console.log("Instance updated from form data:",this.instance),i&&this._updateInstanceData(void 0,"form_data_update",{updatedFormDataKeys:Object.keys(this._formData),updatedCompletedSteps:Array.from(this._internalCompletedSteps)})):console.log("No new form data to update instance with")}updateInstanceFromFormData(i=!1){this._updateInstanceFromFormData(i)}getFormData(){return this.formStateManager.getFormData()}restoreFormData(){this._restoreFormDataFromDOM()}clearSavedFormData(i){this._clearSavedFormData(i)}_renderUnifiedSubmissionView(){const i={instance:this.instance,assignedSteps:this._getAssignedSteps(),completedSteps:this._internalCompletedSteps,isStepAssignedToUser:this._isStepAssignedToUser.bind(this)};return Ne.renderUnifiedSubmissionView(i)}_isInstanceCompleted(){var i;return((i=this.instance)==null?void 0:i.status)==="completed"}_areUserStepsCompleted(){var e;if(!((e=this.instance)!=null&&e.steps))return!1;const i=this._getAssignedSteps();return i.length===0?!1:i.every(t=>t.status==="completed")}_shouldShowCompletionView(){var i;return this.mode!=="default"?!1:!!(this._isInstanceCompleted()||((i=this.instance)==null?void 0:i.status)==="active"&&this._areUserStepsCompleted())}_renderModeBasedContent(){var e,t;if(this._shouldShowCompletionView())return this._renderUnifiedSubmissionView();if(this.mode==="print")return this._renderAllStepsForPrint();const i=this.mode==="preview"?(e=this.workflow)==null?void 0:e.steps:(t=this.instance)==null?void 0:t.steps;return!i||i.length===0?d`<div class="runner-content">
3432
3462
  ${this.mode==="preview"?"No workflow loaded or workflow has no steps.":"No workflow instance loaded or instance has no steps."}
3433
- </div>`:this.mode==="default"&&this._getAssignedSteps().length===0?this._renderNotAssignedView():null}_validateCurrentStep(){return this._currentStep}_initializeStepAssets(i){this.updateComplete.then(()=>{i.elements.forEach(e=>{var t;e.type==="signature"&&((t=this.shadowRoot)!=null&&t.getElementById(`signature-${e.id}`))&&this._initializeSignaturePad(e.id)}),this._restoreSignatures(),setTimeout(()=>{this._formRestorationComplete||(this._restoreFormDataFromDOM(),this._formRestorationComplete=!0)},100)})}_renderCurrentStepLayout(i){var s,r;const e=this._isLastAssignedStep(),t=this._isLastStepInWorkflow(),n=this.mode==="preview"?(s=this.workflow)==null?void 0:s.steps:(r=this.instance)==null?void 0:r.steps;return l`
3463
+ </div>`:this.mode==="default"&&this._getAssignedSteps().length===0?this._renderNotAssignedView():null}_validateCurrentStep(){return this._currentStep}_initializeStepAssets(i){this.updateComplete.then(()=>{i.elements.forEach(e=>{var t;e.type==="signature"&&((t=this.shadowRoot)!=null&&t.getElementById(`signature-${e.id}`))&&this._initializeSignaturePad(e.id)}),this._restoreSignatures(),setTimeout(()=>{this._formRestorationComplete||(this._restoreFormDataFromDOM(),this._formRestorationComplete=!0)},100)})}_renderCurrentStepLayout(i){var s,r;const e=this._isLastAssignedStep(),t=this._isLastStepInWorkflow(),n=this.mode==="preview"?(s=this.workflow)==null?void 0:s.steps:(r=this.instance)==null?void 0:r.steps;return d`
3434
3464
  <!-- Mobile Steps Navigation (visible only on mobile) -->
3435
3465
  ${Y.renderMobileSteps({steps:n,currentStepIndex:this._currentStepIndex,mode:this.mode||"default",isSubmitted:this._isSubmitted,userStepsSubmitted:this._userStepsSubmitted,completedSteps:this._internalCompletedSteps,isLoading:this.isLoading,isStepAssignedToUser:this._isStepAssignedToUser.bind(this),goToStep:this._goToStep.bind(this)})}
3436
3466
 
@@ -3439,7 +3469,7 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3439
3469
 
3440
3470
  <!-- Main Content: Step Details and Questions -->
3441
3471
  <main class="runner-main-content">
3442
- ${this.mode==="print"?Y.renderStepHeader({step:i,mode:this.mode}):l`<div class="runner-card">
3472
+ ${this.mode==="print"?Y.renderStepHeader({step:i,mode:this.mode}):d`<div class="runner-card">
3443
3473
  ${Y.renderStepHeader({step:i,mode:this.mode})}
3444
3474
  </div>`}
3445
3475
  <form class="runner-step-form" @submit=${o=>o.preventDefault()}>
@@ -3447,12 +3477,12 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3447
3477
  ${Dt.renderFormActions({mode:this.mode||"default",isLastStep:e,isLastStepInWorkflow:t,justSaved:this._justSaved,isCurrentStepAssigned:this._isCurrentStepAssigned(),handlers:{saveStep:this._saveStep.bind(this),nextStep:this._nextStep.bind(this),submitUserSteps:this._submitUserSteps.bind(this),submit:this._submit.bind(this)}})}
3448
3478
  </form>
3449
3479
  </main>
3450
- `}_renderMainContent(){const i=this._renderModeBasedContent();if(i)return i;const e=this._validateCurrentStep();return e?(this._initializeStepAssets(e),this._renderCurrentStepLayout(e)):l`<div class="runner-content">Invalid current step.</div>`}render(){return l`
3480
+ `}_renderMainContent(){const i=this._renderModeBasedContent();if(i)return i;const e=this._validateCurrentStep();return e?(this._initializeStepAssets(e),this._renderCurrentStepLayout(e)):d`<div class="runner-content">Invalid current step.</div>`}render(){return d`
3451
3481
  <div class="runner-layout">
3452
3482
  ${this._renderMainContent()}
3453
3483
 
3454
3484
  <!-- Loading overlay with white box (conditionally rendered) -->
3455
- ${this.isLoading?l`
3485
+ ${this.isLoading?d`
3456
3486
  <div class="runner-loading-overlay">
3457
3487
  <div class="runner-loading-box">
3458
3488
  <div class="runner-loading-spinner"></div>
@@ -3479,26 +3509,26 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
3479
3509
  <hr class="print-question-separator" />
3480
3510
 
3481
3511
  ${r?jt(i,o):""}
3482
- ${i.steps.map(d=>Mt(d)).join(`
3512
+ ${i.steps.map(l=>Mt(l)).join(`
3483
3513
  `)}
3484
3514
  </div>
3485
3515
  </body>
3486
3516
  </html>`,title:t,generatedAt:o}}function Mt(i){return`
3487
3517
  <div class="print-step">
3488
3518
  <!-- Step Header -->
3489
- ${Ft(i)}
3519
+ ${Tt(i)}
3490
3520
 
3491
3521
  <!-- Step Elements -->
3492
- ${i.elements.map(e=>Tt(e,i)).join(`
3522
+ ${i.elements.map(e=>Ft(e,i)).join(`
3493
3523
  `)}
3494
3524
  </div>
3495
- `}function Ft(i){return`
3525
+ `}function Tt(i){return`
3496
3526
  <div class="step-print-header">
3497
3527
  <div class="print-step-title">${g(i.title)}</div>
3498
3528
  ${i.description?`<div class="print-step-description">${g(i.description)}</div>`:""}
3499
3529
  <hr class="print-question-separator" />
3500
3530
  </div>
3501
- `}function Tt(i,e){return Ht(i)?zt(i,e):It(i)}function zt(i,e){const t=Vt(i.id,e.responses),n=t==null?void 0:t.value,r=i.type==="checkbox"&&(!i.options||i.options.length===0)?"":`
3531
+ `}function Ft(i,e){return Ht(i)?zt(i,e):It(i)}function zt(i,e){const t=Vt(i.id,e.responses),n=t==null?void 0:t.value,r=i.type==="checkbox"&&(!i.options||i.options.length===0)?"":`
3502
3532
  <div class="print-question-title">
3503
3533
  ${g(i.label)}:
3504
3534
  </div>
@@ -4153,4 +4183,4 @@ Use **bold** and *italic* text.`;break}const n=this._templateData.steps.map(r=>r
4153
4183
  margin: 2px 0;
4154
4184
  line-height: 1.4;
4155
4185
  }
4156
- `}function qt(i,e={}){if(!customElements.get("builder-widget"))return console.error("Error: <builder-widget> is not defined. Make sure it was imported."),null;const t=document.getElementById(i);if(!t)return console.error(`Error: Target element with ID '${i}' not found.`),null;t.innerHTML="";const n=document.createElement("builder-widget");return e.onWorkflowCreated&&(n.onWorkflowCreated=e.onWorkflowCreated),e.onWorkflowDeleted&&(n.onWorkflowDeleted=e.onWorkflowDeleted),e.onWorkflowUpdated&&(n.onWorkflowUpdated=e.onWorkflowUpdated),t.appendChild(n),console.log(`Drill Builder mounted on #${i}`),n}function Kt(i,e){if(!customElements.get("runner-widget"))return console.error("Error: <runner-widget> is not defined. Make sure it was imported."),null;const t=document.getElementById(i);if(!t)return console.error(`Error: Target element with ID '${i}' not found.`),null;if(e.mode==="preview"){if(!e||!e.workflow)return console.error("Error: Workflow data must be provided for preview mode."),t.innerHTML='<p style="color: red;">Error: Workflow data required for preview mode.</p>',null;if(!e.workflow.steps||e.workflow.steps.length===0)return console.error("Error: Workflow provided to runner has no steps defined."),t.innerHTML='<p style="color: red;">Error: Workflow has no steps.</p>',null}else{if(!e||!e.instance)return console.error("Error: Instance data must be provided in runner config."),t.innerHTML='<p style="color: red;">Error: Instance data required.</p>',null;if(!e.instance.steps||e.instance.steps.length===0)return console.error("Error: Instance provided to runner has no steps defined."),t.innerHTML='<p style="color: red;">Error: Instance has no steps.</p>',null}t.innerHTML="";const n=document.createElement("runner-widget");return e.mode==="preview"?(n.workflow=e.workflow,n.mode="preview"):(n.instance=e.instance,n.mode=e.mode||"default"),e.mode&&(n.mode=e.mode),e.isLoading!==void 0&&(n.isLoading=e.isLoading),e.onSignatureCaptured&&(n.onSignatureCaptured=e.onSignatureCaptured),e.onFileUploaded&&(n.onFileUploaded=e.onFileUploaded),e.currentUser&&(n.currentUser=e.currentUser),e.onInstanceUpdated&&n.addEventListener("instance-updated",s=>{const r=s;try{e.onInstanceUpdated(r.detail)}catch(o){console.error("Error executing onInstanceUpdated callback:",o)}}),t.appendChild(n),console.log(`Drill Runner mounted on #${i}`),n}function Jt(i,e){const t=i.getFormData(),n=JSON.parse(JSON.stringify(e));return n.steps&&n.steps.forEach(s=>{s.responses||(s.responses=[]),s.elements.forEach(r=>{if(r.type==="text_input"||r.type==="textarea"||r.type==="select"||r.type==="number"||r.type==="radio"||r.type==="checkbox"||r.type==="date"||r.type==="file_upload"||r.type==="signature"){const o=t[r.id];if(o!==void 0){let a=s.responses.find(d=>d.elementId===r.id);a?(a.value=o,a.answeredAt=new Date):(a={elementId:r.id,value:o,answeredAt:new Date},s.responses.push(a))}}})}),n}function Xt(i,e){const t={};e.steps&&e.steps.forEach(n=>{n.responses&&n.responses.forEach(s=>{t[s.elementId]=s.value})}),i.restoreFormData(),console.log("Form data restored to runner widget:",t)}D.createBuilder=qt,D.createRunner=Kt,D.generateInstanceHTML=At,D.restoreFormDataToRunner=Xt,D.updateInstanceFromRunnerForm=Jt,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
4186
+ `}function qt(i,e={}){if(!customElements.get("builder-widget"))return console.error("Error: <builder-widget> is not defined. Make sure it was imported."),null;const t=document.getElementById(i);if(!t)return console.error(`Error: Target element with ID '${i}' not found.`),null;t.innerHTML="";const n=document.createElement("builder-widget");return e.workflow&&(n.workflow=e.workflow),e.onWorkflowCreated&&(n.onWorkflowCreated=e.onWorkflowCreated),e.onWorkflowDeleted&&(n.onWorkflowDeleted=e.onWorkflowDeleted),e.onWorkflowUpdated&&(n.onWorkflowUpdated=e.onWorkflowUpdated),t.appendChild(n),console.log(`Drill Builder mounted on #${i}`),n}function Kt(i,e){if(!customElements.get("runner-widget"))return console.error("Error: <runner-widget> is not defined. Make sure it was imported."),null;const t=document.getElementById(i);if(!t)return console.error(`Error: Target element with ID '${i}' not found.`),null;if(e.mode==="preview"){if(!e||!e.workflow)return console.error("Error: Workflow data must be provided for preview mode."),t.innerHTML='<p style="color: red;">Error: Workflow data required for preview mode.</p>',null;if(!e.workflow.steps||e.workflow.steps.length===0)return console.error("Error: Workflow provided to runner has no steps defined."),t.innerHTML='<p style="color: red;">Error: Workflow has no steps.</p>',null}else{if(!e||!e.instance)return console.error("Error: Instance data must be provided in runner config."),t.innerHTML='<p style="color: red;">Error: Instance data required.</p>',null;if(!e.instance.steps||e.instance.steps.length===0)return console.error("Error: Instance provided to runner has no steps defined."),t.innerHTML='<p style="color: red;">Error: Instance has no steps.</p>',null}t.innerHTML="";const n=document.createElement("runner-widget");return e.mode==="preview"?(n.workflow=e.workflow,n.mode="preview"):(n.instance=e.instance,n.mode=e.mode||"default"),e.mode&&(n.mode=e.mode),e.isLoading!==void 0&&(n.isLoading=e.isLoading),e.onSignatureCaptured&&(n.onSignatureCaptured=e.onSignatureCaptured),e.onFileUploaded&&(n.onFileUploaded=e.onFileUploaded),e.currentUser&&(n.currentUser=e.currentUser),e.onInstanceUpdated&&n.addEventListener("instance-updated",s=>{const r=s;try{e.onInstanceUpdated(r.detail)}catch(o){console.error("Error executing onInstanceUpdated callback:",o)}}),t.appendChild(n),console.log(`Drill Runner mounted on #${i}`),n}function Jt(i,e){const t=i.getFormData(),n=JSON.parse(JSON.stringify(e));return n.steps&&n.steps.forEach(s=>{s.responses||(s.responses=[]),s.elements.forEach(r=>{if(r.type==="text_input"||r.type==="textarea"||r.type==="select"||r.type==="number"||r.type==="radio"||r.type==="checkbox"||r.type==="date"||r.type==="file_upload"||r.type==="signature"){const o=t[r.id];if(o!==void 0){let a=s.responses.find(l=>l.elementId===r.id);a?(a.value=o,a.answeredAt=new Date):(a={elementId:r.id,value:o,answeredAt:new Date},s.responses.push(a))}}})}),n}function Xt(i,e){const t={};e.steps&&e.steps.forEach(n=>{n.responses&&n.responses.forEach(s=>{t[s.elementId]=s.value})}),i.restoreFormData(),console.log("Form data restored to runner widget:",t)}D.createBuilder=qt,D.createRunner=Kt,D.generateInstanceHTML=At,D.restoreFormDataToRunner=Xt,D.updateInstanceFromRunnerForm=Jt,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});