@feedal/embed
Version:
Feedal embed script to load feedback forms via JS or NPM
49 lines (43 loc) • 61.9 kB
JavaScript
(function(y,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(y=typeof globalThis<"u"?globalThis:y||self,g(y.FeedalEmbed={}))})(this,function(y){"use strict";var te=Object.defineProperty;var se=(y,g,S)=>g in y?te(y,g,{enumerable:!0,configurable:!0,writable:!0,value:S}):y[g]=S;var l=(y,g,S)=>se(y,typeof g!="symbol"?g+"":g,S);const g={host:"https://fedl.io/f/",mode:"popup",theme:"light",trigger:"manual",triggerCooldown:5,autoClose:!0,showCloseButton:!0,closeOnOverlayClick:!1,responsive:!0,animation:"fade",zIndex:9999,overlay:!1,useCard:!1,ariaLabel:"Feedback form",focusTrap:!0,lazyLoad:!0,preloadResources:!0,performanceMonitoring:!1,disableFormAnimations:!0,showLoadingIndicator:!1,loadingSpinner:!0,rememberSubmission:!0,submissionExpiry:30,storageType:"local",buttonPosition:"bottom-right",buttonSize:"medium",buttonColor:"#007bff",buttonIcon:"👍",buttonText:"",draggable:!1,resizable:!1,collapsible:!1,persistent:!1,blurBackground:!1};function S(i){return/^[a-zA-Z0-9\-_]+$/.test(i)}function d(i){return typeof i=="number"?`${i}px`:i}function R(i,e){const t=new URLSearchParams({s:"e"});return i.theme&&t.set("theme",i.theme),i.customCssUrl&&t.set("css",i.customCssUrl),i.autoClose&&t.set("autoClose",String(i.autoClose)),i.mode&&t.set("mode",i.mode),i.token&&t.set("token",i.token),i.useCard&&t.set("useCard",String(i.useCard)),i.disableFormAnimations&&t.set("disableAnimations","1"),i.metadata&&t.set("metadata",JSON.stringify(i.metadata)),i.prefill&&t.set("prefill",JSON.stringify(i.prefill)),t}function A(){return window.innerWidth<=768}function $(i,e){const t={},s=(e==null?void 0:e.x)||0,o=(e==null?void 0:e.y)||0;switch(i){case"top-left":t.top=`${20+o}px`,t.left=`${20+s}px`;break;case"top-center":t.top=`${20+o}px`,t.left="50%",t.transform=`translateX(calc(-50% + ${s}px))`;break;case"top-right":t.top=`${20+o}px`,t.right=`${20-s}px`;break;case"bottom-left":t.bottom=`${20-o}px`,t.left=`${20+s}px`;break;case"bottom-center":t.bottom=`${20-o}px`,t.left="50%",t.transform=`translateX(calc(-50% + ${s}px))`;break;case"bottom-right":t.bottom=`${20-o}px`,t.right=`${20-s}px`;break;case"left":t.top="50%",t.left=`${20+s}px`,t.transform=`translateY(calc(-50% + ${o}px))`;break;case"right":t.top="50%",t.right=`${20-s}px`,t.transform=`translateY(calc(-50% + ${o}px))`;break;case"center":default:t.top="50%",t.left="50%",t.transform=`translate(calc(-50% + ${s}px), calc(-50% + ${o}px))`;break}return t}function M(i,e,t){return new Promise(s=>{if(e==="none"){s();return}const o=O(e),r=D(e),a=[],n=i.style.transform||"",c=n.includes("translate")||n.includes("calc");switch(e){case"fade":a.push({opacity:t==="enter"?0:1},{opacity:t==="enter"?1:0});break;case"slide":c?a.push({transform:`${n} translateY(${t==="enter"?"100%":"0"})`},{transform:`${n} translateY(${t==="enter"?"0":"100%"})`}):a.push({transform:`translateY(${t==="enter"?"100%":"0"})`},{transform:`translateY(${t==="enter"?"0":"100%"})`});break;case"scale":c?a.push({transform:`${n} scale(${t==="enter"?.8:1})`,opacity:t==="enter"?0:1},{transform:`${n} scale(${t==="enter"?1:.8})`,opacity:t==="enter"?1:0}):a.push({transform:`scale(${t==="enter"?.8:1})`,opacity:t==="enter"?0:1},{transform:`scale(${t==="enter"?1:.8})`,opacity:t==="enter"?1:0});break;case"bounce":t==="enter"?c?a.push({transform:`${n} scale(0.3)`,opacity:0},{transform:`${n} scale(1.05)`,opacity:.8,offset:.5},{transform:`${n} scale(0.9)`,opacity:.9,offset:.7},{transform:`${n} scale(1.03)`,opacity:.95,offset:.8},{transform:`${n} scale(0.97)`,opacity:.98,offset:.9},{transform:`${n} scale(1)`,opacity:1}):a.push({transform:"scale(0.3)",opacity:0},{transform:"scale(1.05)",opacity:.8,offset:.5},{transform:"scale(0.9)",opacity:.9,offset:.7},{transform:"scale(1.03)",opacity:.95,offset:.8},{transform:"scale(0.97)",opacity:.98,offset:.9},{transform:"scale(1)",opacity:1}):c?a.push({transform:`${n} scale(1)`,opacity:1},{transform:`${n} scale(1.02)`,opacity:.9,offset:.3},{transform:`${n} scale(0.95)`,opacity:.7,offset:.6},{transform:`${n} scale(0.3)`,opacity:0}):a.push({transform:"scale(1)",opacity:1},{transform:"scale(1.02)",opacity:.9,offset:.3},{transform:"scale(0.95)",opacity:.7,offset:.6},{transform:"scale(0.3)",opacity:0});break;case"flip":c?a.push({transform:`${n} rotateY(${t==="enter"?"90deg":"0deg"})`,opacity:t==="enter"?0:1},{transform:`${n} rotateY(${t==="enter"?"0deg":"90deg"})`,opacity:t==="enter"?1:0}):a.push({transform:`rotateY(${t==="enter"?"90deg":"0deg"})`,opacity:t==="enter"?0:1},{transform:`rotateY(${t==="enter"?"0deg":"90deg"})`,opacity:t==="enter"?1:0});break;case"elastic":t==="enter"?c?a.push({transform:`${n} scale(0)`,opacity:0},{transform:`${n} scale(1.2)`,opacity:.8,offset:.6},{transform:`${n} scale(0.9)`,opacity:.9,offset:.8},{transform:`${n} scale(1.05)`,opacity:.95,offset:.9},{transform:`${n} scale(1)`,opacity:1}):a.push({transform:"scale(0)",opacity:0},{transform:"scale(1.2)",opacity:.8,offset:.6},{transform:"scale(0.9)",opacity:.9,offset:.8},{transform:"scale(1.05)",opacity:.95,offset:.9},{transform:"scale(1)",opacity:1}):c?a.push({transform:`${n} scale(1)`,opacity:1},{transform:`${n} scale(1.1)`,opacity:.8,offset:.4},{transform:`${n} scale(0)`,opacity:0}):a.push({transform:"scale(1)",opacity:1},{transform:"scale(1.1)",opacity:.8,offset:.4},{transform:"scale(0)",opacity:0});break}if(a.length>0){const h=i.animate(a,{duration:o,easing:r});h.onfinish=()=>s()}else s()})}function O(i){switch(i){case"bounce":case"elastic":return 600;case"flip":return 400;default:return 300}}function D(i){switch(i){case"bounce":return"cubic-bezier(0.68, -0.55, 0.265, 1.55)";case"elastic":return"cubic-bezier(0.175, 0.885, 0.32, 1.275)";case"flip":return"cubic-bezier(0.4, 0, 0.2, 1)";default:return"ease-out"}}function z(i){const e=i.position||"bottom-right";let t="200px",s="150px",o="400px",r="400px",a="300px";i.height?t=d(i.height):(t="200px",s="150px",o="400px"),i.width?(r=d(i.width),a=d(i.width)):(r="400px",a="300px");const n={position:"fixed",zIndex:String(i.zIndex),background:"#fff",borderRadius:"8px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",border:"1px solid #e5e7eb",overflow:"hidden",maxWidth:r,minWidth:a,height:t,minHeight:s,maxHeight:o};switch(e){case"top-left":return{...n,top:"20px",left:"20px"};case"top-center":return{...n,top:"20px",left:"50%",transform:"translateX(-50%)"};case"top-right":return{...n,top:"20px",right:"20px"};case"bottom-left":return{...n,bottom:"20px",left:"20px"};case"bottom-center":return{...n,bottom:"20px",left:"50%",transform:"translateX(-50%)"};case"bottom-right":default:return{...n,bottom:"20px",right:"20px"}}}function P(i){const e=i.position||"center",t=i.offset;let s="400px",o="90vw",r="auto",a="200px",n="90vh";i.width?s=d(i.width):(s="400px",o="90vw"),i.height?r=d(i.height):(r="auto",a="200px",n="90vh");const c={position:"fixed",zIndex:String(i.zIndex),background:"#fff",borderRadius:"12px",boxShadow:"0 10px 25px rgba(0, 0, 0, 0.15)",overflow:"hidden",width:s,maxWidth:o,height:r,minHeight:a,maxHeight:n},h=$(e,t);return i.responsive&&A()?(c.width="calc(100% - 40px)",c.maxWidth="400px",{...c,top:"50%",left:"50%",transform:"translate(-50%, -50%)"}):{...c,...h}}function K(i){return{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",zIndex:String(i.zIndex)}}function F(i){let e="100%",t="auto",s="100px",o="100%",r="100%";return i.width&&(e=d(i.width),o=d(i.width),r=d(i.width)),i.height?t=d(i.height):(t="auto",s="100px"),i.maxWidth&&(o=d(i.maxWidth)),i.minWidth&&(r=d(i.minWidth)),{position:"relative",top:"auto",left:"auto",width:e,height:t,minHeight:s,maxWidth:o,minWidth:r,border:"1px solid #e5e7eb",borderRadius:"8px",display:"block",margin:"10px 0"}}function H(i){const e=i.buttonPosition||"bottom-right",t=i.buttonSize||"medium",s=i.buttonColor||"#007bff";let o="60px";t==="custom"?o=i.width?String(i.width):"60px":o={small:"40px",medium:"60px",large:"80px"}[t]||"60px";let r="auto",a="auto",n="auto",c="auto",h="";switch(e){case"top-left":r="20px",n="20px";break;case"top-center":r="20px",n="50%",h="translateX(-50%)";break;case"top-right":r="20px",c="20px";break;case"center-left":r="50%",n="20px",h="translateY(-50%)";break;case"center":r="50%",n="50%",h="translate(-50%, -50%)";break;case"center-right":r="50%",c="20px",h="translateY(-50%)";break;case"bottom-left":a="20px",n="20px";break;case"bottom-center":a="20px",n="50%",h="translateX(-50%)";break;case"bottom-right":default:a="20px",c="20px";break}return{position:"fixed",top:r,bottom:a,left:n,right:c,transform:h,width:o,height:o,borderRadius:"50%",border:"none",background:s,color:"white",fontSize:t==="small"?"16px":t==="large"?"32px":"24px",cursor:"pointer",zIndex:String((i.zIndex||9999)-1),boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)",transition:"all 0.3s ease"}}function W(i){const e=i.position||"right";let t;switch(e){case"left":case"center-left":case"top-left":case"bottom-left":t="left";break;case"right":case"center-right":case"top-right":case"bottom-right":default:t="right";break}let s="500px",o="90vw";return i.width?s=d(i.width):(s="500px",o="90vw"),{position:"fixed",top:"0",[t]:"0",height:"100vh",width:s,maxWidth:o,zIndex:String(i.zIndex),background:"#fff",boxShadow:t==="left"?"4px 0 30px rgba(0, 0, 0, 0.2)":"-4px 0 30px rgba(0, 0, 0, 0.2)",overflowY:"auto",borderTopLeftRadius:t==="right"?"12px":"0",borderBottomLeftRadius:t==="right"?"12px":"0",borderTopRightRadius:t==="left"?"12px":"0",borderBottomRightRadius:t==="left"?"12px":"0"}}function B(i){const e=i.position||"center";let t="90vw",s="600px",o="auto",r="200px",a="80vh";i.width?t=d(i.width):(t="500px",s="90vw"),i.height?o=d(i.height):(o="auto",r="300px",a="90vh");const n={position:"fixed",zIndex:String(i.zIndex),background:"#fff",borderRadius:"12px",boxShadow:"0 20px 40px rgba(0, 0, 0, 0.2)",overflow:"hidden",width:t,maxWidth:s,height:o,minHeight:r,maxHeight:a};switch(e){case"top":case"top-center":return{...n,top:"10%",left:"50%",transform:"translateX(-50%)"};case"bottom":case"bottom-center":return{...n,bottom:"10%",left:"50%",transform:"translateX(-50%)"};case"left":case"center-left":return{...n,top:"50%",left:"10%",transform:"translateY(-50%)"};case"right":case"center-right":return{...n,top:"50%",right:"10%",transform:"translateY(-50%)"};case"center":default:return{...n,top:"50%",left:"50%",transform:"translate(-50%, -50%)"}}}function N(i){const e=i.position||"right";let t;switch(e){case"left":case"center-left":case"top-left":case"bottom-left":t="left";break;case"right":case"center-right":case"top-right":case"bottom-right":t="right";break;case"center":case"top-center":case"bottom-center":default:t="right";break}let s="400px",o="80vw";return i.width?s=d(i.width):(s="400px",o="80vw"),{position:"fixed",[t]:"0",top:"0",height:"100vh",width:s,maxWidth:o,borderTopLeftRadius:t==="right"?"12px":"0",borderBottomLeftRadius:t==="right"?"12px":"0",borderTopRightRadius:t==="left"?"12px":"0",borderBottomRightRadius:t==="left"?"12px":"0",zIndex:String(i.zIndex),background:"#fff",boxShadow:t==="right"?"-4px 0 20px rgba(0, 0, 0, 0.15)":"4px 0 20px rgba(0, 0, 0, 0.15)",overflowY:"auto"}}function U(i){const e=i.position||"bottom";console.log("🎨 [DRAWER STYLES] Generating styles for position:",e);let t;switch(e){case"center":case"top-center":case"bottom-center":t="bottom";break;case"center-left":t="left";break;case"center-right":t="right";break;case"top-left":case"top-right":t="top";break;case"bottom-left":case"bottom-right":t="bottom";break;default:t=e}console.log("🎨 [DRAWER STYLES] Mapped position:",t);const s=t==="left"||t==="right";console.log("🎨 [DRAWER STYLES] Is horizontal:",s);let o="400px",r="400px",a="80vh",n="80vw";i.width?o=d(i.width):o=t==="left"||t==="right"?"400px":"100vw",i.height?r=d(i.height):r=t==="bottom"||t==="top"?"400px":"100vh",a=t==="bottom"||t==="top"?"80vh":"100vh",n=t==="left"||t==="right"?"80vw":"100vw";const c={position:"fixed",[t]:"0",width:o,height:r,maxWidth:n,maxHeight:a,...s?{top:"0",borderTopLeftRadius:t==="right"?"12px":"0",borderBottomLeftRadius:t==="right"?"12px":"0",borderTopRightRadius:t==="left"?"12px":"0",borderBottomRightRadius:t==="left"?"12px":"0"}:{left:"0",right:"0",borderTopLeftRadius:t==="bottom"?"12px":"0",borderTopRightRadius:t==="bottom"?"12px":"0",borderBottomLeftRadius:t==="top"?"12px":"0",borderBottomRightRadius:t==="top"?"12px":"0"},zIndex:String(i.zIndex),background:"#fff",boxShadow:{bottom:"0 -4px 20px rgba(0, 0, 0, 0.15)",top:"0 4px 20px rgba(0, 0, 0, 0.15)",left:"4px 0 20px rgba(0, 0, 0, 0.15)",right:"-4px 0 20px rgba(0, 0, 0, 0.15)"}[t]};return console.log("🎨 [DRAWER STYLES] Generated styles:",c),c}function Y(){const i=window.innerWidth;return i<=768?"mobile":i<=1024?"tablet":"desktop"}function I(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function w(i,e){Object.assign(i.style,e)}function V(){return{width:Math.max(document.documentElement.clientWidth||0,window.innerWidth||0),height:Math.max(document.documentElement.clientHeight||0,window.innerHeight||0)}}function q(i,e){const t=V(),s=i.getBoundingClientRect();return{x:Math.max(0,Math.min(e.x,t.width-s.width)),y:Math.max(0,Math.min(e.y,t.height-s.height))}}function v(i,e){return typeof i=="boolean"?i?3e3:-1:i===void 0?-1:typeof i=="string"?J(i):X(i,e)}function J(i){const e=i.match(/^(\d+(?:\.\d+)?)([smhd])$/);if(!e)throw new Error(`Invalid time format: ${i}. Expected format: "5s", "10m", "2h", "30d"`);const[,t,s]=e,o=parseFloat(t);switch(s){case"s":return Math.round(o*1e3);case"m":return Math.round(o*60*1e3);case"h":return Math.round(o*3600*1e3);case"d":return Math.round(o*86400*1e3);default:throw new Error(`Unknown time unit: ${s}. Supported: s, m, h, d`)}}function X(i,e){switch(e){case"seconds":return i*1e3;case"minutes":return i*60*1e3;case"hours":return i*3600*1e3;case"days":return i*86400*1e3;default:throw new Error(`Unknown default unit: ${e}`)}}const x={autoClose:"seconds",triggerDelay:"seconds",triggerCooldown:"minutes",submissionExpiry:"days"};class j{constructor(e,t={}){l(this,"element");l(this,"options");l(this,"originalFocus",null);l(this,"focusableElements",[]);l(this,"isTrappingFocus",!1);l(this,"isHandlingFocus",!1);this.element=e,this.options=t,this.setupAccessibility()}setupAccessibility(){this.options.ariaLabel&&this.element.setAttribute("aria-label",this.options.ariaLabel),this.options.ariaDescribedBy&&this.element.setAttribute("aria-describedby",this.options.ariaDescribedBy),this.element.setAttribute("role",this.options.role||"dialog"),this.element.setAttribute("aria-modal","true"),this.element.setAttribute("tabindex","-1"),this.respectUserPreferences()}respectUserPreferences(){window.matchMedia("(prefers-reduced-motion: reduce)").matches&&(this.element.style.setProperty("--feedal-animation-duration","0s"),this.element.classList.add("feedal-reduced-motion")),window.matchMedia("(prefers-contrast: high)").matches&&this.element.classList.add("feedal-high-contrast"),window.matchMedia("(prefers-color-scheme: dark)").matches&&this.element.classList.add("feedal-dark-preference")}enableFocusTrap(){this.options.focusTrap&&(this.originalFocus=document.activeElement,this.updateFocusableElements(),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),document.addEventListener("focusin",this.handleFocusIn.bind(this)),this.focusableElements.length>0?this.focusableElements[0].focus():this.element.focus(),this.isTrappingFocus=!0)}disableFocusTrap(){this.isTrappingFocus&&(this.element.removeEventListener("keydown",this.handleKeyDown.bind(this)),document.removeEventListener("focusin",this.handleFocusIn.bind(this)),this.originalFocus&&document.contains(this.originalFocus)&&this.originalFocus.focus(),this.isTrappingFocus=!1)}updateFocusableElements(){const e=["button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","a[href]",'[tabindex]:not([tabindex="-1"])',"iframe"].join(", ");this.focusableElements=Array.from(this.element.querySelectorAll(e))}handleKeyDown(e){if(e.key==="Escape"){this.handleEscapeKey(e);return}e.key==="Tab"&&this.handleTabKey(e)}handleEscapeKey(e){e.preventDefault(),this.element.dispatchEvent(new CustomEvent("feedal:escape",{bubbles:!0}))}handleTabKey(e){if(this.focusableElements.length===0){e.preventDefault();return}const t=this.focusableElements[0],s=this.focusableElements[this.focusableElements.length-1],o=this.focusableElements.indexOf(document.activeElement);e.shiftKey?(document.activeElement===t||o===-1)&&(e.preventDefault(),s.focus()):(document.activeElement===s||o===-1)&&(e.preventDefault(),t.focus())}handleFocusIn(e){if(this.isHandlingFocus)return;const t=e.target;this.element.contains(t)||(e.preventDefault(),this.isHandlingFocus=!0,this.focusableElements.length>0?this.focusableElements[0].focus():this.element.focus(),setTimeout(()=>{this.isHandlingFocus=!1},10))}announceToScreenReader(e,t="polite"){const s=document.createElement("div");s.setAttribute("aria-live",t),s.setAttribute("aria-atomic","true"),s.style.position="absolute",s.style.left="-10000px",s.style.width="1px",s.style.height="1px",s.style.overflow="hidden",document.body.appendChild(s),setTimeout(()=>{s.textContent=e,setTimeout(()=>{document.body.contains(s)&&document.body.removeChild(s)},1e3)},100)}addKeyboardShortcuts(){this.element.addEventListener("keydown",e=>{if((e.ctrlKey||e.metaKey)&&e.key==="Enter"){const t=new CustomEvent("feedal:submit-shortcut",{bubbles:!0});this.element.dispatchEvent(t)}})}destroy(){this.disableFocusTrap()}}const G=`
/* Accessibility styles */
.feedal-reduced-motion * {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
.feedal-high-contrast {
border: 2px solid #000 !important;
background: #fff !important;
color: #000 !important;
}
.feedal-high-contrast button {
border: 2px solid #000 !important;
background: #fff !important;
color: #000 !important;
}
.feedal-high-contrast button:hover,
.feedal-high-contrast button:focus {
background: #000 !important;
color: #fff !important;
}
/* Focus indicators */
.feedal-widget *:focus {
outline: 2px solid #4A90E2;
outline-offset: 2px;
}
.feedal-widget *:focus:not(:focus-visible) {
outline: none;
}
/* Screen reader only text */
.feedal-sr-only {
position: absolute !important;
width: 1px !important;
height: 1px !important;
padding: 0 !important;
margin: -1px !important;
overflow: hidden !important;
clip: rect(0, 0, 0, 0) !important;
white-space: nowrap !important;
border: 0 !important;
}
`;class Q{constructor(e={}){l(this,"options");l(this,"intersectionObserver");l(this,"performanceObserver");l(this,"metrics",new Map);this.options={lazyLoad:!0,preloadDelay:100,intersectionThreshold:.1,performanceMonitoring:!1,criticalPath:!1,...e},this.options.performanceMonitoring&&this.initPerformanceMonitoring()}setupLazyLoading(e,t){if(!this.options.lazyLoad||!("IntersectionObserver"in window)){t();return}this.intersectionObserver=new IntersectionObserver(s=>{s.forEach(o=>{var r;o.isIntersecting&&(t(),(r=this.intersectionObserver)==null||r.unobserve(e))})},{threshold:this.options.intersectionThreshold,rootMargin:"50px"}),this.intersectionObserver.observe(e)}preloadResources(e,t){if(!this.options.criticalPath)return;const s=document.createElement("link");s.rel="dns-prefetch",s.href=new URL(e).origin,document.head.appendChild(s);const o=document.createElement("link");o.rel="preconnect",o.href=e,document.head.appendChild(o),console.log("Preconnect added for:",o.href);const r=document.createElement("link");r.rel="prefetch",r.href=`${e}${t}?preload=true&s=e`,document.head.appendChild(r)}createOptimizedScrollHandler(e){let t=!1;return()=>{t||(requestAnimationFrame(()=>{e(),t=!1}),t=!0)}}addPassiveEventListener(e,t,s){const o={passive:!0,capture:!1};e.addEventListener(t,s,o)}createOptimizedResizeHandler(e,t=250){let s,o=window.innerWidth,r=window.innerHeight;return()=>{const a=window.innerWidth,n=window.innerHeight;(a!==o||n!==r)&&(clearTimeout(s),s=setTimeout(()=>{e(),o=a,r=n},t))}}initPerformanceMonitoring(){if("PerformanceObserver"in window){this.performanceObserver=new PerformanceObserver(e=>{e.getEntries().forEach(t=>{if(t.entryType==="navigation"){const s=t;this.metrics.set("domContentLoaded",s.domContentLoadedEventEnd-s.domContentLoadedEventStart),this.metrics.set("loadComplete",s.loadEventEnd-s.loadEventStart)}t.entryType==="paint"&&this.metrics.set(t.name,t.startTime),t.entryType==="largest-contentful-paint"&&this.metrics.set("lcp",t.startTime)})});try{this.performanceObserver.observe({entryTypes:["navigation","paint","largest-contentful-paint"]})}catch{console.warn("Some performance metrics not available")}}}markPerformance(e){"performance"in window&&"mark"in performance&&performance.mark(`feedal-${e}`),this.metrics.set(e,Date.now())}measurePerformance(e,t,s){if("performance"in window&&"measure"in performance){const a=`feedal-${e}`,n=`feedal-${t}`,c=s?`feedal-${s}`:void 0;try{return performance.measure(a,n,c),performance.getEntriesByName(a)[0].duration}catch{const b=this.metrics.get(t)||0;return(s&&this.metrics.get(s)||Date.now())-b}}const o=this.metrics.get(t)||0;return(s&&this.metrics.get(s)||Date.now())-o}getMetrics(){const e={};if(this.metrics.forEach((t,s)=>{e[s]=t}),"performance"in window)try{const t=performance.getEntriesByType("navigation")[0];t&&(e.ttfb=t.responseStart-t.requestStart,e.domInteractive=t.domInteractive-t.fetchStart,e.domComplete=t.domComplete-t.fetchStart)}catch{}return e}optimizeIframeLoading(e){e.loading="lazy",e.setAttribute("importance","low"),e.setAttribute("referrerpolicy","no-referrer-when-downgrade"),e.setAttribute("allow","accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture")}trackMemoryUsage(){if("memory"in performance){const e=performance.memory;this.metrics.set("memoryUsed",e.usedJSHeapSize),this.metrics.set("memoryTotal",e.totalJSHeapSize),this.metrics.set("memoryLimit",e.jsHeapSizeLimit)}}destroy(){this.intersectionObserver&&this.intersectionObserver.disconnect(),this.performanceObserver&&this.performanceObserver.disconnect(),this.metrics.clear()}}function Z(i){const e=document.createElement("link");e.rel="dns-prefetch",e.href=new URL(i).origin,document.head.appendChild(e);const t=document.createElement("link");t.rel="preconnect",t.href=new URL(i).origin,document.head.appendChild(t)}function _(i){const e=document.createElement("style");e.textContent=i,e.setAttribute("data-feedal-critical","true");const t=document.head.querySelector('link[rel="stylesheet"], style');t?document.head.insertBefore(e,t):document.head.appendChild(e)}class ee{constructor(e,t,s){l(this,"options");l(this,"performanceManager");l(this,"state");l(this,"listeners",[]);l(this,"timers",new Set);l(this,"onTrigger");this.options=e,this.performanceManager=t,this.onTrigger=s,this.state={sessionStartTime:Date.now(),lastActivityTime:Date.now(),hasTriggered:!1,cooldownUntil:0,exitIntentTriggered:!1}}setupTrigger(){const{trigger:e}=this.options;switch(e){case"exit-intent":this.setupExitIntentTrigger();break;case"element-visible":this.setupElementVisibleTrigger();break;case"session-duration":this.setupSessionDurationTrigger();break;case"idle":this.setupIdleTrigger();break}}setupExitIntentTrigger(){let e=!1;const t=v(this.options.triggerCooldown,x.triggerCooldown),s=o=>{if(o.clientY<=0&&!e&&this.canTrigger()){e=!0,this.state.exitIntentTriggered=!0,this.state.cooldownUntil=Date.now()+t,this.performanceManager.markPerformance("exit-intent-detected"),this.trigger();const r=setTimeout(()=>{e=!1},t);this.timers.add(r)}};this.isMobile()||(document.addEventListener("mouseleave",s),this.listeners.push(()=>document.removeEventListener("mouseleave",s)))}setupElementVisibleTrigger(){if(!this.options.triggerElement){console.warn("triggerElement is required for element-visible trigger");return}const e=typeof this.options.triggerElement=="string"?document.querySelector(this.options.triggerElement):this.options.triggerElement;if(!e){console.warn(`Element not found: ${this.options.triggerElement}`);return}const t=this.options.triggerThreshold||.5,s=v(this.options.triggerDelay,x.triggerDelay);let o;const r=new IntersectionObserver(a=>{a.forEach(n=>{n.isIntersecting&&n.intersectionRatio>=t&&this.canTrigger()?(o=setTimeout(()=>{this.canTrigger()&&(this.performanceManager.markPerformance("element-visible-triggered"),this.trigger())},s),this.timers.add(o)):o&&(clearTimeout(o),this.timers.delete(o))})},{threshold:t});r.observe(e),this.listeners.push(()=>r.disconnect())}setupSessionDurationTrigger(){const e=v(this.options.triggerDelay,x.triggerDelay),t=()=>{Date.now()-this.state.sessionStartTime>=e&&this.canTrigger()&&(this.performanceManager.markPerformance("session-duration-reached"),this.trigger())},s=setInterval(t,3e4);this.listeners.push(()=>clearInterval(s));const o=()=>{this.canTrigger()&&t()};this.performanceManager.addPassiveEventListener(document,"click",o),this.performanceManager.addPassiveEventListener(document,"scroll",o),this.performanceManager.addPassiveEventListener(document,"keydown",o),this.listeners.push(()=>{document.removeEventListener("click",o),document.removeEventListener("scroll",o),document.removeEventListener("keydown",o)})}setupIdleTrigger(){const e=v(this.options.triggerDelay,x.triggerDelay);let t;const s=()=>{this.state.lastActivityTime=Date.now(),t&&(clearTimeout(t),this.timers.delete(t)),t=setTimeout(()=>{this.canTrigger()&&(this.performanceManager.markPerformance("idle-state-detected"),this.trigger())},e),this.timers.add(t)};["mousedown","mousemove","keypress","scroll","touchstart","click"].forEach(r=>{this.performanceManager.addPassiveEventListener(document,r,s),this.listeners.push(()=>document.removeEventListener(r,s))}),s()}canTrigger(){return!this.state.hasTriggered&&Date.now()>this.state.cooldownUntil}trigger(){this.canTrigger()&&(this.state.hasTriggered=!0,this.onTrigger())}isMobile(){return window.innerWidth<=768||/Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}reset(){this.state.hasTriggered=!1,this.state.exitIntentTriggered=!1,this.state.lastActivityTime=Date.now(),this.state.cooldownUntil=0}getState(){return{...this.state}}destroy(){this.timers.forEach(e=>clearTimeout(e)),this.timers.clear(),this.listeners.forEach(e=>e()),this.listeners=[]}}const p=class p{constructor(e,t={}){l(this,"options");l(this,"formId");this.formId=e,this.options={rememberSubmission:!0,submissionExpiry:30*24*60*60*1e3,storageType:"local",...t}}hasSubmitted(){if(!this.options.rememberSubmission)return console.log("Submission checking disabled in options"),!1;const e=this.getSubmittedSessionKey();if(!e)return console.log("No submitted session key found"),!1;const t=Date.now();if((this.options.submissionExpiry||0)>0)try{const o=JSON.parse(e);if(o.expiresAt&&t>o.expiresAt)return console.log("Submitted session key expired, removing"),this.clearSubmittedSessionKey(),!1}catch{return console.warn("Failed to parse submitted session key, removing corrupted data"),this.clearSubmittedSessionKey(),!1}return console.log("Form has been submitted with valid session key"),!0}recordSubmission(){if(!this.options.rememberSubmission){console.log("Submission recording disabled in options");return}const e=this.getRenderedSessionKey();if(e){const t=`${p.submittedKeyPrefix}${this.formId}`,s=this.options.submissionExpiry;if(s&&Number(s)>0){const o=Date.now()+Number(s),r={sessionKey:e,expiresAt:o};switch(this.options.storageType){case"local":typeof localStorage<"u"?(localStorage.setItem(t,JSON.stringify(r)),console.log("Saved to localStorage:",t,"=",JSON.stringify(r))):console.warn("localStorage not available");break;case"session":typeof sessionStorage<"u"?(sessionStorage.setItem(t,JSON.stringify(r)),console.log("Saved to sessionStorage:",t,"=",JSON.stringify(r))):console.warn("sessionStorage not available");break;case"cookie":this.setCookie(t,JSON.stringify(r),this.options.submissionExpiry),console.log("Saved to cookie:",t,"=",JSON.stringify(r));break}console.log(`Stored submitted session key with expiration: ${new Date(o).toISOString()}`)}else{switch(this.options.storageType){case"local":typeof localStorage<"u"?(localStorage.setItem(t,e),console.log("Saved to localStorage:",t,"=",e)):console.warn("localStorage not available");break;case"session":typeof sessionStorage<"u"?(sessionStorage.setItem(t,e),console.log("Saved to sessionStorage:",t,"=",e)):console.warn("sessionStorage not available");break;case"cookie":this.setCookie(t,e,this.options.submissionExpiry),console.log("Saved to cookie:",t,"=",e);break}console.log("Stored submitted session key without expiration (persistent)")}this.clearRenderedSessionKey(),console.log("Cleared rendered session key")}else console.warn("No rendered session key found to record submission")}clearSubmission(){this.clearSubmittedSessionKey(),this.clearRenderedSessionKey(),console.log("Cleared all submission records for form:",this.formId)}static resetAllSubmissions(){if(typeof localStorage<"u"){const e=[];for(let t=0;t<localStorage.length;t++){const s=localStorage.key(t);s&&(s.startsWith(p.storageKeyPrefix)||s.startsWith(p.renderedKeyPrefix)||s.startsWith(p.submittedKeyPrefix))&&e.push(s)}e.forEach(t=>{localStorage.removeItem(t),console.log("Removed localStorage key:",t)})}if(typeof sessionStorage<"u"){const e=[];for(let t=0;t<sessionStorage.length;t++){const s=sessionStorage.key(t);s&&(s.startsWith(p.storageKeyPrefix)||s.startsWith(p.renderedKeyPrefix)||s.startsWith(p.submittedKeyPrefix))&&e.push(s)}e.forEach(t=>{sessionStorage.removeItem(t),console.log("Removed sessionStorage key:",t)})}document.cookie.split(";").forEach(e=>{const t=e.trim().split("=")[0];(t.startsWith(p.storageKeyPrefix)||t.startsWith(p.renderedKeyPrefix)||t.startsWith(p.submittedKeyPrefix))&&(document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;",console.log("Removed cookie:",t))}),console.log("All submission records cleared from all storage types")}setRenderedSessionKey(e){if(!this.options.rememberSubmission)return;const t=`${p.renderedKeyPrefix}${this.formId}`;this.setStorageValue(t,e),console.log("Stored rendered session key:",e,"for form:",this.formId)}getRenderedSessionKey(){if(!this.options.rememberSubmission)return null;const e=`${p.renderedKeyPrefix}${this.formId}`;return this.getStorageValue(e)}clearRenderedSessionKey(){const e=`${p.renderedKeyPrefix}${this.formId}`;this.removeStorageValue(e),console.log("Cleared rendered session key for form:",this.formId)}setSubmittedSessionKey(e){if(!this.options.rememberSubmission)return;const t=`${p.submittedKeyPrefix}${this.formId}`,s=this.options.submissionExpiry;if(s&&Number(s)>0){const o=Date.now()+Number(s),r={sessionKey:e,expiresAt:o};this.setStorageValue(t,JSON.stringify(r)),console.log(`Stored submitted session key with expiration: ${new Date(o).toISOString()}`)}else this.setStorageValue(t,e),console.log("Stored submitted session key without expiration (persistent)")}getSubmittedSessionKey(){if(!this.options.rememberSubmission)return null;const e=`${p.submittedKeyPrefix}${this.formId}`,t=this.getStorageValue(e);if(!t)return null;try{const s=JSON.parse(t);if(!s||typeof s!="object"||!s.sessionKey)return console.warn(`Invalid stored session key data for form ${this.formId}. Removing.`),this.removeStorageValue(e),null;const o=s.expiresAt;return o&&Date.now()>o?(this.removeStorageValue(e),console.log(`Submitted session key expired for form ${this.formId}. Removing.`),null):s.sessionKey}catch(s){return console.warn(`Failed to parse stored session key for form ${this.formId}. Removing corrupted data.`,s),this.removeStorageValue(e),null}}clearSubmittedSessionKey(){const e=`${p.submittedKeyPrefix}${this.formId}`;this.removeStorageValue(e),console.log("Cleared submitted session key for form:",this.formId)}cleanupExpiredKeys(){if(!this.options.rememberSubmission)return;this.getSubmittedSessionKey()&&console.log("Expired keys cleanup completed for form:",this.formId)}clearAllFormKeys(){this.clearRenderedSessionKey(),this.clearSubmittedSessionKey(),console.log("Cleared all form keys for form:",this.formId)}updateSessionKey(e){console.log("Updating session key from",this.options.sessionKey,"to",e),this.options.sessionKey=e}isSessionKeyValid(e){if(!this.options.rememberSubmission)return!1;if(this.options.sessionKey&&this.options.sessionKey!==e)return console.log("Session key changed, stored key is invalid"),!1;const t=this.getSubmittedSessionKey();if(!t)return!1;const s=Date.now();if((this.options.submissionExpiry||0)>0)try{const r=JSON.parse(t);if(r.expiresAt&&s>r.expiresAt)return console.log("Session key validation - expired"),!1}catch{return console.warn("Failed to parse session key for validation, removing corrupted data"),this.clearSubmittedSessionKey(),!1}return console.log("Session key validation - valid"),!0}setStorageValue(e,t){switch(this.options.storageType){case"local":typeof localStorage<"u"&&localStorage.setItem(e,t);break;case"session":typeof sessionStorage<"u"&&sessionStorage.setItem(e,t);break;case"cookie":this.setCookie(e,t,this.options.submissionExpiry);break}}getStorageValue(e){switch(this.options.storageType){case"local":if(typeof localStorage<"u")return localStorage.getItem(e);break;case"session":if(typeof sessionStorage<"u")return sessionStorage.getItem(e);break;case"cookie":return this.getCookie(e)}return null}removeStorageValue(e){switch(this.options.storageType){case"local":typeof localStorage<"u"&&localStorage.removeItem(e);break;case"session":typeof sessionStorage<"u"&&sessionStorage.removeItem(e);break;case"cookie":this.deleteCookie(e);break}}setCookie(e,t,s){let o=`${e}=${t}; path=/`;if(s){const r=new Date;r.setTime(r.getTime()+s),o+=`; expires=${r.toUTCString()}`}document.cookie=o}getCookie(e){const t=document.cookie.split(";");for(let s=0;s<t.length;s++){const o=t[s].trim();if(o.startsWith(e+"="))return o.substring(e.length+1)}return null}deleteCookie(e){document.cookie=`${e}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`}};l(p,"storageKeyPrefix","feedal-submission-"),l(p,"renderedKeyPrefix","feedal-rendered-"),l(p,"submittedKeyPrefix","feedal-submitted-");let T=p;const m=class m{constructor(e){l(this,"options");l(this,"iframe");l(this,"wrapper");l(this,"overlay");l(this,"isOpen",!1);l(this,"messageReceived",!1);l(this,"messageListener");l(this,"resizeListener");l(this,"accessibilityManager");l(this,"performanceManager");l(this,"triggerManager");l(this,"submissionManager");l(this,"dragHandlers");l(this,"resizeHandlers");l(this,"focusTrapCleanup");l(this,"buttonElement");this.options={...g,...e},this.validateOptions(),this.performanceManager=new Q({lazyLoad:!0,performanceMonitoring:!0,criticalPath:!0}),this.submissionManager=new T(this.options.formId,{rememberSubmission:this.options.rememberSubmission,submissionExpiry:v(this.options.submissionExpiry,x.submissionExpiry),storageType:this.options.storageType,sessionKey:this.options.sessionKey}),this.performanceManager.markPerformance("widget-created"),m.stylesInjected||(_(G),m.stylesInjected=!0),this.options.host&&(Z(this.options.host),this.performanceManager.preloadResources(this.options.host,this.options.formId)),this.setupEventListeners(),this.options.formId&&m.instances.set(this.options.formId,this)}open(){this.isOpen||(console.log("Opening widget for form:",this.options.formId),this.isOpen=!0,this.createIframe())}close(){this.isOpen&&(this.performanceManager.markPerformance("widget-close-start"),this.accessibilityManager&&this.accessibilityManager.announceToScreenReader("Feedback form closed"),this.cleanupWidget().then(()=>{var e,t;this.isOpen=!1,this.accessibilityManager&&(this.accessibilityManager.destroy(),this.accessibilityManager=void 0),this.cleanupEnhancedFeatures(),this.performanceManager.markPerformance("widget-close-end"),(t=(e=this.options).onClose)==null||t.call(e)}))}toggle(){this.isOpen?this.close():this.open()}destroy(){this.performanceManager.markPerformance("widget-destroy"),this.cleanupWidget(),this.cleanup(),this.accessibilityManager&&this.accessibilityManager.destroy(),this.triggerManager&&this.triggerManager.destroy(),this.cleanupEnhancedFeatures(),this.performanceManager.destroy(),this.options.formId&&m.instances.delete(this.options.formId)}updateOptions(e){this.options={...this.options,...e},this.validateOptions(),e.trigger&&this.triggerManager&&(this.triggerManager.destroy(),this.setupTriggers()),this.isOpen&&(this.close(),setTimeout(()=>this.open(),100))}getPerformanceMetrics(){const e=this.performanceManager.getMetrics();if(this.triggerManager){const t=this.triggerManager.getState();e.sessionDuration=Date.now()-t.sessionStartTime,e.timeSinceLastActivity=Date.now()-t.lastActivityTime,e.hasTriggered=t.hasTriggered?1:0}return e}getTriggerState(){var e;return((e=this.triggerManager)==null?void 0:e.getState())||null}resetTrigger(){var e;(e=this.triggerManager)==null||e.reset()}collapse(){if(this.options.collapsible&&this.wrapper){const e=this.wrapper.dataset.collapsed==="true";this.wrapper.dataset.collapsed=(!e).toString(),e?this.wrapper.style.height=this.options.height?d(this.options.height):"600px":this.wrapper.style.height="40px"}}get isVisible(){return this.isOpen}get element(){return this.wrapper||this.iframe||null}static getInstance(e){return m.instances.get(e)}static destroyAll(){m.instances.forEach(e=>e.destroy()),m.instances.clear()}resetSubmissionHistory(){this.submissionManager.clearAllFormKeys(),console.log(`Submission history cleared for form ${this.options.formId}.`)}static resetAllSubmissions(){T.resetAllSubmissions(),console.log("All submission history cleared.")}validateOptions(){if(!this.options.formId)throw new Error("formId is required");if(!S(this.options.formId))throw new Error("Invalid form ID. Must be alphanumeric with dashes and underscores.");if(this.options.mode==="embedded"&&!this.options.containerId)throw new Error("containerId is required for embedded mode");if(this.options.trigger==="element-visible"&&!this.options.triggerElement)throw new Error("triggerElement is required for element-visible trigger")}setupEventListeners(){this.messageListener=e=>{this.handleMessage(e)},this.resizeListener=this.performanceManager.createOptimizedResizeHandler(()=>{this.isOpen&&this.options.responsive&&this.handleResize()},250),window.addEventListener("message",this.messageListener),this.performanceManager.addPassiveEventListener(window,"resize",this.resizeListener),this.setupTriggers()}setupTriggers(){const{trigger:e}=this.options;switch(e){case"auto":setTimeout(()=>this.open(),v(this.options.triggerDelay,x.triggerDelay));break;case"time":setTimeout(()=>this.open(),v(this.options.triggerDelay,x.triggerDelay));break;case"click":const t=this.options.triggerElement?typeof this.options.triggerElement=="string"?document.querySelector(this.options.triggerElement):this.options.triggerElement:null;t&&t.addEventListener("click",()=>this.open());break;case"scroll":const s=this.performanceManager.createOptimizedScrollHandler(()=>{const o=window.scrollY/(document.documentElement.scrollHeight-window.innerHeight)*100,r=this.options.triggerThreshold||50;o>r&&(this.open(),window.removeEventListener("scroll",s))});this.performanceManager.addPassiveEventListener(window,"scroll",s);break;case"exit-intent":case"element-visible":case"session-duration":case"idle":this.triggerManager=new ee(this.options,this.performanceManager,()=>this.open()),this.triggerManager.setupTrigger();break}}createIframe(){if(this.iframe)return;const e=R(this.options);console.log("=== OPTIONS DEBUG ==="),console.log("this.options:",this.options),console.log("queryParams object:",e);const t=this.submissionManager.getSubmittedSessionKey();t?(e.append("stored_session_key",t),console.log("Adding stored submitted session key to iframe:",t)):console.log("No stored submitted session key available"),this.iframe=document.createElement("iframe");const s=`${this.options.host}${this.options.formId}?${e.toString()}`;console.log("=== IFRAME CREATION DEBUG ==="),console.log("this.options.host:",this.options.host),console.log("this.options.formId:",this.options.formId),console.log("queryParams.toString():",e.toString()),console.log("Constructed iframeSrc:",s),this.iframe.src=s,console.log("=== IFRAME SRC SET ==="),console.log("Mode:",this.options.mode),console.log("Iframe src set to:",s),console.log("Iframe src attribute after setting:",this.iframe.src),console.log("Timestamp:",new Date().toISOString());try{const o=new URL(s);console.log("URL validation passed:",o.href)}catch(o){console.error("URL validation failed:",o)}this.iframe.addEventListener("load",()=>{var o,r;console.log("=== IFRAME LOADED SUCCESSFULLY ==="),console.log("Iframe loaded with src:",(o=this.iframe)==null?void 0:o.src),console.log("Iframe in DOM:",this.iframe?document.body.contains(this.iframe):!1),console.log("Iframe parent element:",(r=this.iframe)==null?void 0:r.parentElement)}),this.iframe.addEventListener("error",o=>{var r;console.error("=== IFRAME LOAD ERROR ==="),console.error("Iframe failed to load:",o),console.error("Iframe src at error:",(r=this.iframe)==null?void 0:r.src)}),this.iframe.addEventListener("beforeunload",()=>{console.log("=== IFRAME BEFORE UNLOAD ==="),console.log("Iframe is about to unload/change")}),this.iframe.style.border="none",this.iframe.style.background="transparent",this.iframe.style.width="100%",this.iframe.style.minHeight="100px",this.iframe.style.opacity="1",this.iframe.style.visibility="visible",this.iframe.style.position="relative",this.iframe.style.top="auto",this.iframe.style.left="auto",this.iframe.style.zIndex="auto",this.iframe.setAttribute("scrolling","no"),this.performanceManager.optimizeIframeLoading(this.iframe),this.options.ariaLabel&&this.iframe.setAttribute("aria-label",this.options.ariaLabel),this.iframe.setAttribute("title","Feedal Feedback Form"),this.createWrapper(),this.wrapper&&(this.wrapper.style.opacity="0",this.wrapper.style.visibility="hidden",this.wrapper.style.pointerEvents="none",this.wrapper.style.position="fixed",this.wrapper.style.top="0",this.wrapper.style.left="0",this.wrapper.style.width="400px",this.wrapper.style.height="600px",this.wrapper.style.zIndex="-9999",this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.style.position="relative",this.iframe.style.top="auto",this.iframe.style.left="auto",this.wrapper.appendChild(this.iframe),document.body.appendChild(this.wrapper),console.log("=== IFRAME ADDED TO WRAPPER ==="),console.log("Iframe created and added directly to wrapper (100% size, ready to load)"),console.log("Final iframe src:",this.iframe.src),console.log("Iframe element:",this.iframe),console.log("Iframe in wrapper:",this.wrapper.contains(this.iframe)),console.log("Wrapper created and added to DOM (hidden but loadable)"))}setupAccessibility(){const e=this.wrapper||this.iframe;e&&(e.classList.add("feedal-widget"),this.accessibilityManager=new j(e,{ariaLabel:this.options.ariaLabel||"Feedback form",focusTrap:this.shouldUseFocusTrap(),announceOnOpen:!0,announceOnClose:!0}),this.shouldUseFocusTrap()&&(this.accessibilityManager.enableFocusTrap(),this.accessibilityManager.announceToScreenReader("Feedback form opened")),this.accessibilityManager.addKeyboardShortcuts(),e.addEventListener("feedal:escape",()=>{this.shouldUseFocusTrap()&&this.close()}),e.addEventListener("feedal:submit-shortcut",()=>{var t;this.iframe&&((t=this.iframe.contentWindow)==null||t.postMessage({type:"feedal:submit-shortcut"},"*"))}))}shouldUseFocusTrap(){return["fullscreen","popup","modal","slide-over"].includes(this.options.mode||"popup")&&this.options.focusTrap!==!1}showWidget(){var t,s;if(!this.iframe||!this.wrapper)return;if(this.wrapper.style.visibility==="visible"){console.log("Widget already shown, skipping...");return}console.log("Showing widget..."),this.wrapper.style.opacity="1",this.wrapper.style.visibility="visible",this.wrapper.style.pointerEvents="auto",this.wrapper.style.position="fixed",this.wrapper.style.top="auto",this.wrapper.style.left="auto",this.wrapper.style.width="auto",this.wrapper.style.height="auto",this.wrapper.style.zIndex="auto",this.iframe.style.opacity="1",this.iframe.style.visibility="visible",this.renderWidget(),this.setupAccessibility(),this.performanceManager.markPerformance("widget-open-end");const e=this.performanceManager.measurePerformance("open-duration","widget-open-start","widget-open-end");(s=(t=this.options).onOpen)==null||s.call(t),typeof window<"u"&&window.location.hostname==="localhost"&&console.log(`Feedal widget opened in ${e.toFixed(2)}ms`)}renderWidget(){if(!this.iframe)return;const{mode:e}=this.options;switch(e){case"fullscreen":this.renderFullscreen();break;case"embedded":this.renderEmbedded();break;case"popup":this.renderPopup();break;case"drawer":this.renderDrawer();break;case"button":this.renderButton();break;case"sidebar":this.renderSidebar();break;case"toast":this.renderToast();break;case"inline":this.renderInline();break;case"modal":this.renderModal();break;case"slide-over":this.renderSlideOver();break;default:this.renderPopup()}}renderFullscreen(){if(!this.iframe||!this.wrapper)return;const e=K(this.options);w(this.wrapper,e),this.options.showCloseButton&&this.addCloseButton(),this.applyEnterAnimation(this.wrapper)}renderEmbedded(){var s,o;if(!this.iframe||!this.options.containerId)return;const e=document.getElementById(this.options.containerId);if(!e)throw new Error(`Container with ID "${this.options.containerId}" not found`);const t=F(this.options);w(this.iframe,t),e.appendChild(this.iframe),this.setupResizeObserver(),(o=(s=this.options).onLoad)==null||o.call(s)}renderPopup(){if(!this.iframe||!this.wrapper)return;this.wrapper.style.visibility==="hidden"&&(console.log("Showing previously hidden wrapper for popup mode"),this.wrapper.style.opacity="1",this.wrapper.style.visibility="visible",this.wrapper.style.pointerEvents="auto",this.wrapper.style.position="fixed",this.wrapper.style.top="auto",this.wrapper.style.left="auto",this.wrapper.style.width="auto",this.wrapper.style.height="auto",this.wrapper.style.zIndex="auto",this.iframe.style.opacity="1",this.iframe.style.visibility="visible");const e=P(this.options);w(this.wrapper,e),this.options.showCloseButton&&this.addCloseButton(),this.options.overlay&&this.createOverlay(),this.setupEnhancedFeatures(),this.applyEnterAnimation(this.wrapper)}renderDrawer(){if(!this.iframe||!this.wrapper)return;console.log("🎯 [DRAWER] Rendering drawer with options:",this.options);const e=U(this.options);console.log("🎯 [DRAWER] Generated drawer styles:",e),w(this.wrapper,e),console.log("🎯 [DRAWER] Applied styles to wrapper"),this.options.showCloseButton&&this.addCloseButton(),this.applyEnterAnimation(this.wrapper),console.log("🎯 [DRAWER] Drawer rendering completed")}renderSidebar(){if(!this.iframe||!this.wrapper)return;const e=N(this.options);w(this.wrapper,e),this.options.showCloseButton&&this.addCloseButton(),this.options.overlay&&this.createOverlay(),this.applyEnterAnimation(this.wrapper)}renderToast(){if(!this.iframe||!this.wrapper)return;const e=z(this.options);w(this.wrapper,e),this.options.showCloseButton&&this.addCloseButton(),this.applyEnterAnimation(this.wrapper)}renderInline(){if(!this.iframe)return;const e=this.options.triggerElement?typeof this.options.triggerElement=="string"?document.querySelector(this.options.triggerElement):this.options.triggerElement:document.body;if(!e)throw new Error("No target element found for inline mode");this.options.width?this.iframe.style.width=d(this.options.width):this.iframe.style.width="100%",this.options.height?this.iframe.style.height=d(this.options.height):(this.iframe.style.height="400px",this.iframe.style.minHeight="200px"),this.iframe.style.border="1px solid #e5e7eb",this.iframe.style.borderRadius="8px",this.iframe.style.display="block",this.iframe.style.margin="10px 0",e.appendChild(this.iframe),this.applyEnterAnimation(this.iframe)}renderModal(){if(!this.iframe||!this.wrapper)return;const e=B(this.options);w(this.wrapper,e),this.options.showCloseButton&&this.addCloseButton(),this.options.overlay&&this.createOverlay(),this.setupEnhancedFeatures(),this.applyEnterAnimation(this.wrapper)}renderSlideOver(){if(!this.iframe||!this.wrapper)return;const e=W(this.options);w(this.wrapper,e),this.options.showCloseButton&&this.addCloseButton(),this.options.overlay&&this.createOverlay(),this.setupEnhancedFeatures(),this.applyEnterAnimation(this.wrapper)}renderButton(){const e=document.createElement("button");this.options.buttonText?e.textContent=this.options.buttonText:e.textContent=this.options.buttonIcon||"👍";const t=H(this.options);w(e,t),e.setAttribute("aria-label","Open feedback form"),e.setAttribute("role","button"),e.setAttribute("tabindex","0"),e.addEventListener("mouseenter",()=>{e.style.transform="scale(1.1)",e.style.boxShadow="0 6px 16px rgba(0, 0, 0, 0.2)"}),e.addEventListener("mouseleave",()=>{e.style.transform="scale(1)",e.style.boxShadow="0 4px 12px rgba(0, 0, 0, 0.15)"}),e.addEventListener("click",()=>{e.style.display="none",this.options.mode="popup",this.renderPopup()}),e.addEventListener("keydown",s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),e.click())}),document.body.appendChild(e),this.buttonElement=e}setupEnhancedFeatures(){this.wrapper&&(this.options.draggable&&this.setupDraggable(),this.options.resizable&&this.setupResizable(),this.options.collapsible&&this.setupCollapsible())}setupDraggable(){if(!this.wrapper)return;let e=!1,t={x:0,y:0};const s=a=>{e=!0;const n=this.wrapper.getBoundingClientRect();t={x:a.clientX-n.left,y:a.clientY-n.top},this.wrapper.style.cursor="grabbing",document.addEventListener("mousemove",o),document.addEventListener("mouseup",r)},o=a=>{var h,b;if(!e||!this.wrapper)return;const n={x:a.clientX-t.x,y:a.clientY-t.y},c=q(this.wrapper,n);this.wrapper.style.left=`${c.x}px`,this.wrapper.style.top=`${c.y}px`,this.wrapper.style.transform="none",(b=(h=this.options).onMove)==null||b.call(h,c)},r=()=>{e=!1,this.wrapper&&(this.wrapper.style.cursor=""),document.removeEventListener("mousemove",o),document.removeEventListener("mouseup"