@qaiddev/quests-embed 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- (function(b,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(b=typeof globalThis<"u"?globalThis:b||self,v(b.QaidQuests={}))})(this,(function(b){"use strict";const v=`*{box-sizing:border-box}button{cursor:pointer;font-family:inherit}:where(.qaid-q-root){--qaid-q-card-bg: light-dark(#ffffff, #1f2937);--qaid-q-card-fg: light-dark(#1f2937, #f9fafb);--qaid-q-card-border: light-dark(#e5e7eb, #374151);--qaid-q-card-radius: 1rem;--qaid-q-card-padding: 1.5rem;--qaid-q-card-shadow: 0 25px 50px -12px light-dark(rgba(0, 0, 0, .25), rgba(0, 0, 0, .6));--qaid-q-muted-fg: light-dark(#6b7280, #9ca3af);--qaid-q-progress-track: light-dark(#e5e7eb, #374151);--qaid-q-btn-radius: .5rem;--qaid-q-btn-padding-y: .625rem;--qaid-q-btn-padding-x: 1.125rem;--qaid-q-btn-font-weight: 500;--qaid-q-btn-primary-bg: var(--qaid-q-accent, #10b981);--qaid-q-btn-primary-fg: var(--qaid-q-accent-text, #ffffff);--qaid-q-btn-primary-border: transparent;--qaid-q-btn-secondary-bg: transparent;--qaid-q-btn-secondary-fg: light-dark(#374151, #d1d5db);--qaid-q-btn-secondary-border: light-dark(#d1d5db, #4b5563);--qaid-q-btn-secondary-hover-bg: light-dark(#f3f4f6, #374151);--qaid-q-option-bg: light-dark(#ffffff, #111827);--qaid-q-option-bg-selected: color-mix(in srgb, var(--qaid-q-accent, #10b981) 10%, transparent);--qaid-q-option-bg-hover: light-dark(#f9fafb, #1f2937);--qaid-q-option-fg: light-dark(#1f2937, #f9fafb);--qaid-q-option-border: light-dark(#e5e7eb, #374151);--qaid-q-option-border-selected: var(--qaid-q-accent, #10b981);--qaid-q-option-border-hover: light-dark(#9ca3af, #4b5563);--qaid-q-option-radius: .625rem;--qaid-q-option-padding: .75rem .875rem;--qaid-q-marker-bg: light-dark(#ffffff, #111827);--qaid-q-marker-bg-selected: var(--qaid-q-accent, #10b981);--qaid-q-marker-border: light-dark(#d1d5db, #4b5563);--qaid-q-marker-icon: light-dark(#ffffff, #1f2937);--qaid-q-marker-radius: 50%;--qaid-q-input-bg: light-dark(#ffffff, #111827);--qaid-q-input-fg: light-dark(#1f2937, #f9fafb);--qaid-q-input-border: light-dark(#d1d5db, #374151);--qaid-q-input-radius: .625rem;--qaid-q-input-padding: .75rem .875rem;--qaid-q-input-placeholder: light-dark(#9ca3af, #6b7280);--qaid-q-gap: .75rem;--qaid-q-section-gap: 1.25rem}:where(.qaid-q-root.qaid-q-theme-light){--qaid-q-card-bg: #ffffff;--qaid-q-card-fg: #1f2937;--qaid-q-card-border: #e5e7eb;--qaid-q-card-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25);--qaid-q-muted-fg: #6b7280;--qaid-q-progress-track: #e5e7eb;--qaid-q-btn-secondary-fg: #374151;--qaid-q-btn-secondary-border: #d1d5db;--qaid-q-btn-secondary-hover-bg: #f3f4f6;--qaid-q-option-bg: #ffffff;--qaid-q-option-bg-hover: #f9fafb;--qaid-q-option-fg: #1f2937;--qaid-q-option-border: #e5e7eb;--qaid-q-option-border-hover: #9ca3af;--qaid-q-marker-bg: #ffffff;--qaid-q-marker-border: #d1d5db;--qaid-q-marker-icon: #ffffff;--qaid-q-input-bg: #ffffff;--qaid-q-input-fg: #1f2937;--qaid-q-input-border: #d1d5db;--qaid-q-input-placeholder: #9ca3af}:where(.qaid-q-root.qaid-q-theme-dark){--qaid-q-card-bg: #1f2937;--qaid-q-card-fg: #f9fafb;--qaid-q-card-border: #374151;--qaid-q-card-shadow: 0 25px 50px -12px rgba(0, 0, 0, .6);--qaid-q-muted-fg: #9ca3af;--qaid-q-progress-track: #374151;--qaid-q-btn-secondary-fg: #d1d5db;--qaid-q-btn-secondary-border: #4b5563;--qaid-q-btn-secondary-hover-bg: #374151;--qaid-q-option-bg: #111827;--qaid-q-option-bg-hover: #1f2937;--qaid-q-option-fg: #f9fafb;--qaid-q-option-border: #374151;--qaid-q-option-border-hover: #4b5563;--qaid-q-marker-bg: #111827;--qaid-q-marker-border: #4b5563;--qaid-q-marker-icon: #1f2937;--qaid-q-input-bg: #111827;--qaid-q-input-fg: #f9fafb;--qaid-q-input-border: #374151;--qaid-q-input-placeholder: #6b7280}.qaid-q-root{color-scheme:light dark;font-family:var(--qaid-font-family, system-ui, -apple-system, sans-serif);font-size:var(--qaid-font-size, 16px);color:var(--qaid-q-card-fg)}.qaid-q-root.qaid-q-theme-light{color-scheme:light}.qaid-q-root.qaid-q-theme-dark{color-scheme:dark}.qaid-q-backdrop{position:fixed;inset:0;z-index:45;background:rgba(0,0,0,var(--qaid-backdrop-opacity, .4));animation:qaid-q-fade .18s ease-out}@keyframes qaid-q-fade{0%{opacity:0}to{opacity:1}}.qaid-q-modal{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:50;width:var(--qaid-modal-width, 480px);max-width:calc(100vw - 32px);max-height:calc(100vh - 32px);pointer-events:auto;display:flex;flex-direction:column}.qaid-q-card{background:var(--qaid-q-card-bg);color:var(--qaid-q-card-fg);border-radius:var(--qaid-q-card-radius);box-shadow:var(--qaid-q-card-shadow);padding:var(--qaid-q-card-padding);overflow:hidden;display:flex;flex-direction:column;min-height:0}:where(.qaid-q-root.qaid-q-inline) .qaid-q-card{box-shadow:none;border:1px solid var(--qaid-q-card-border);flex:1;min-height:0}:where(.qaid-q-root.qaid-q-inline){height:100%;display:flex;flex-direction:column;min-height:0}.qaid-q-header{display:flex;align-items:center;justify-content:space-between;gap:.75rem;margin-bottom:1rem}.qaid-q-title{font-size:1.125em;font-weight:700;margin:0;color:var(--qaid-q-card-fg)}.qaid-q-step-counter{font-size:.875em;color:var(--qaid-q-muted-fg);font-variant-numeric:tabular-nums;white-space:nowrap}.qaid-q-close{width:28px;height:28px;padding:0;border:none;border-radius:50%;background:transparent;color:var(--qaid-q-muted-fg);display:inline-flex;align-items:center;justify-content:center;-webkit-appearance:none;appearance:none}.qaid-q-close:hover{background:var(--qaid-q-btn-secondary-hover-bg);color:var(--qaid-q-card-fg)}.qaid-q-close:focus-visible{outline:none;box-shadow:0 0 0 3px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 30%,transparent)}.qaid-q-progress{position:relative;height:4px;background:var(--qaid-q-progress-track);border-radius:9999px;overflow:hidden;margin-bottom:var(--qaid-q-section-gap)}.qaid-q-progress--inline{flex:1;min-width:60px;margin-bottom:0}.qaid-q-progress-fill{position:absolute;inset:0 auto 0 0;background:var(--qaid-q-accent, #10b981);border-radius:9999px;transition:width .3s ease;width:0%}.qaid-q-body{flex:1;min-height:0;overflow-y:auto}.qaid-q-step{display:flex;flex-direction:column;gap:var(--qaid-q-gap);animation:qaid-q-slide .22s ease-out}@keyframes qaid-q-slide{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.qaid-q-no-motion .qaid-q-step,.qaid-q-no-motion.qaid-q-root{animation:none!important}.qaid-q-label{font-size:1.125em;font-weight:600;margin:0;color:var(--qaid-q-card-fg);line-height:1.35}.qaid-q-label .qaid-q-required{color:var(--qaid-q-error, #ef4444);margin-left:.25rem}.qaid-q-description{font-size:.875em;color:var(--qaid-q-muted-fg);margin:0;line-height:1.4}.qaid-q-error{font-size:.8125em;color:var(--qaid-q-error, #ef4444);margin:0}.qaid-q-error:empty{display:none}.qaid-q-input,.qaid-q-textarea{width:100%;padding:var(--qaid-q-input-padding);border:1px solid var(--qaid-q-input-border);border-radius:var(--qaid-q-input-radius);font-family:inherit;font-size:1em;background:var(--qaid-q-input-bg);color:var(--qaid-q-input-fg);transition:border-color .15s,box-shadow .15s;-webkit-appearance:none;appearance:none}.qaid-q-textarea{min-height:7rem;resize:vertical;font-family:inherit}.qaid-q-input:focus,.qaid-q-textarea:focus{outline:none;border-color:var(--qaid-q-focus, #6366f1);box-shadow:0 0 0 3px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 20%,transparent)}.qaid-q-input::placeholder,.qaid-q-textarea::placeholder{color:var(--qaid-q-input-placeholder)}.qaid-q-currency{position:relative}.qaid-q-currency-prefix{position:absolute;left:.875rem;top:50%;transform:translateY(-50%);color:var(--qaid-q-muted-fg);font-size:1em;font-weight:500;pointer-events:none}.qaid-q-currency .qaid-q-input{padding-left:2.25rem}.qaid-q-range-wrap{display:flex;flex-direction:column;gap:.5rem;padding:.5rem 0}.qaid-q-range-value{font-size:2em;font-weight:700;text-align:center;font-variant-numeric:tabular-nums;color:var(--qaid-q-accent, #10b981)}.qaid-q-range-value .qaid-q-range-unit{font-size:.5em;font-weight:500;color:var(--qaid-q-muted-fg);margin-left:.25rem}.qaid-q-range{width:100%;-webkit-appearance:none;appearance:none;height:6px;border-radius:9999px;background:var(--qaid-q-progress-track);outline:none}.qaid-q-range::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:24px;height:24px;border-radius:50%;background:var(--qaid-q-accent, #10b981);border:3px solid var(--qaid-q-card-bg);box-shadow:0 2px 6px #0003;cursor:pointer;transition:transform .1s}.qaid-q-range::-moz-range-thumb{width:24px;height:24px;border-radius:50%;background:var(--qaid-q-accent, #10b981);border:3px solid var(--qaid-q-card-bg);box-shadow:0 2px 6px #0003;cursor:pointer}.qaid-q-range:focus-visible::-webkit-slider-thumb{box-shadow:0 0 0 6px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 30%,transparent)}.qaid-q-range:focus-visible::-moz-range-thumb{box-shadow:0 0 0 6px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 30%,transparent)}.qaid-q-range-bounds{display:flex;justify-content:space-between;font-size:.8125em;color:var(--qaid-q-muted-fg);font-variant-numeric:tabular-nums}.qaid-q-options{display:flex;flex-direction:column;gap:.5rem}.qaid-q-option{display:flex;align-items:flex-start;gap:.625rem;padding:var(--qaid-q-option-padding);border:1px solid var(--qaid-q-option-border);border-radius:var(--qaid-q-option-radius);background:var(--qaid-q-option-bg);text-align:left;font-size:1em;color:var(--qaid-q-option-fg);cursor:pointer;transition:border-color .12s,background .12s,box-shadow .12s;-webkit-appearance:none;appearance:none;width:100%}.qaid-q-option:hover{border-color:var(--qaid-q-option-border-hover);background:var(--qaid-q-option-bg-hover)}.qaid-q-option:focus-visible{outline:none;border-color:var(--qaid-q-focus, #6366f1);box-shadow:0 0 0 3px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 25%,transparent)}.qaid-q-option.qaid-q-selected{border-color:var(--qaid-q-option-border-selected);background:var(--qaid-q-option-bg-selected)}.qaid-q-option-marker{flex-shrink:0;width:1.25rem;height:1.25rem;border:2px solid var(--qaid-q-marker-border);border-radius:var(--qaid-q-marker-radius);display:inline-flex;align-items:center;justify-content:center;margin-top:.125rem;background:var(--qaid-q-marker-bg);transition:border-color .12s,background .12s}.qaid-q-option.qaid-q-multi .qaid-q-option-marker{border-radius:.25rem}.qaid-q-option.qaid-q-selected .qaid-q-option-marker{border-color:var(--qaid-q-marker-bg-selected);background:var(--qaid-q-marker-bg-selected)}.qaid-q-option.qaid-q-selected .qaid-q-option-marker:after{content:"";display:block;width:.5rem;height:.5rem;border-radius:50%;background:var(--qaid-q-marker-icon)}.qaid-q-option.qaid-q-multi.qaid-q-selected .qaid-q-option-marker:after{content:"";display:block;width:70%;height:70%;border-radius:0;background:var(--qaid-q-marker-icon);-webkit-mask-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round' d='M5 12l4 4L19 7'/></svg>");mask-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round' d='M5 12l4 4L19 7'/></svg>");-webkit-mask-size:contain;mask-size:contain;-webkit-mask-position:center;mask-position:center;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;transform:none}.qaid-q-option-body{flex:1;min-width:0;display:flex;flex-direction:column;gap:.125rem}.qaid-q-option-image{display:block;width:48px;height:48px;aspect-ratio:1 / 1;object-fit:cover;border-radius:.375rem;background:var(--qaid-q-progress-track);flex-shrink:0}.qaid-q-options--image-horizontal .qaid-q-option-body{flex-direction:row;align-items:center;gap:.75rem}.qaid-q-options--image-horizontal .qaid-q-option-body>:not(.qaid-q-option-image){flex:1;min-width:0;display:flex;flex-direction:column;gap:.125rem}.qaid-q-options--image-vertical{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:.5rem}.qaid-q-options--image-vertical .qaid-q-option{flex-direction:column;align-items:stretch;text-align:center;padding:.75rem;gap:.5rem}.qaid-q-options--image-vertical .qaid-q-option-body{align-items:center;text-align:center}.qaid-q-options--image-vertical .qaid-q-option-image{width:100%;height:auto;max-width:100%}.qaid-q-options--image-vertical .qaid-q-option-marker{position:absolute;top:.5rem;right:.5rem;margin-top:0}.qaid-q-options--image-vertical .qaid-q-option{position:relative}.qaid-q-options--image-vertical .qaid-q-option-key{position:absolute;top:.5rem;left:.5rem;align-self:auto}.qaid-q-option-label{font-weight:500;line-height:1.3}.qaid-q-option-desc{font-size:.8125em;color:var(--qaid-q-muted-fg);line-height:1.4}.qaid-q-option-key{flex-shrink:0;align-self:center;font-size:.7em;font-weight:600;padding:.125rem .375rem;border-radius:.25rem;background:var(--qaid-q-progress-track);color:var(--qaid-q-muted-fg);font-variant-numeric:tabular-nums}.qaid-q-footer{display:flex;align-items:center;justify-content:space-between;gap:.5rem;margin-top:var(--qaid-q-section-gap)}.qaid-q-footer--inline-progress{justify-content:flex-start;gap:.75rem}.qaid-q-footer-left,.qaid-q-footer-right{display:flex;gap:.5rem}.qaid-q-btn{padding:var(--qaid-q-btn-padding-y) var(--qaid-q-btn-padding-x);border-radius:var(--qaid-q-btn-radius);font-size:var(--qaid-q-btn-font-size, .9375em);font-weight:var(--qaid-q-btn-font-weight);border:1px solid transparent;cursor:pointer;transition:filter .15s,background .15s,color .15s;-webkit-appearance:none;appearance:none}.qaid-q-btn:focus-visible{outline:none;box-shadow:0 0 0 3px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 30%,transparent)}.qaid-q-btn-secondary{background:var(--qaid-q-btn-secondary-bg);border-color:var(--qaid-q-btn-secondary-border);color:var(--qaid-q-btn-secondary-fg)}.qaid-q-btn-secondary:hover{background:var(--qaid-q-btn-secondary-hover-bg)}.qaid-q-btn-primary{background:var(--qaid-q-btn-primary-bg);color:var(--qaid-q-btn-primary-fg);border-color:var(--qaid-q-btn-primary-border)}.qaid-q-btn-primary:hover{filter:brightness(.9)}.qaid-q-btn-primary:disabled{opacity:.5;cursor:not-allowed;filter:none}.qaid-q-done{display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;gap:.5rem;padding:1.5rem 0;flex:1;min-height:0}.qaid-q-done-icon{width:48px;height:48px;border-radius:50%;background:color-mix(in srgb,var(--qaid-q-accent, #10b981) 18%,transparent);color:var(--qaid-q-accent, #10b981);display:inline-flex;align-items:center;justify-content:center;margin-bottom:.5rem}.qaid-q-done-title{font-size:1.25em;font-weight:700;margin:0}.qaid-q-done-message{color:var(--qaid-q-muted-fg);margin:0}.qaid-q-saving{display:inline-flex;align-items:center;gap:.375rem;font-size:.75em;color:var(--qaid-q-muted-fg);opacity:0;transition:opacity .2s}.qaid-q-saving.qaid-q-visible{opacity:1}.qaid-q-saving-dot{width:6px;height:6px;border-radius:50%;background:var(--qaid-q-accent, #10b981);animation:qaid-q-pulse 1.2s ease-in-out infinite}@keyframes qaid-q-pulse{0%,to{opacity:.3}50%{opacity:1}}:where(.qaid-q-root.qaid-q-unstyled) :where(.qaid-q-card,.qaid-q-header,.qaid-q-title,.qaid-q-description,.qaid-q-step,.qaid-q-label,.qaid-q-options,.qaid-q-option,.qaid-q-option-marker,.qaid-q-option-body,.qaid-q-option-label,.qaid-q-option-desc,.qaid-q-input,.qaid-q-textarea,.qaid-q-currency,.qaid-q-currency-prefix,.qaid-q-range,.qaid-q-range-wrap,.qaid-q-range-value,.qaid-q-btn,.qaid-q-footer,.qaid-q-progress,.qaid-q-progress-fill,.qaid-q-step-counter,.qaid-q-error,.qaid-q-saving,.qaid-q-done,.qaid-q-done-icon,.qaid-q-done-title,.qaid-q-done-message){all:unset;display:revert;box-sizing:border-box}.qaid-q-input:focus-visible,.qaid-q-textarea:focus-visible,.qaid-q-option:focus-visible,.qaid-q-btn:focus-visible,.qaid-q-close:focus-visible,.qaid-q-range:focus-visible{outline:2px solid transparent;outline-offset:2px}@media(prefers-reduced-motion:reduce){.qaid-q-root *,.qaid-q-root *:before,.qaid-q-root *:after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}.qaid-q-range::-webkit-slider-thumb{transition:none!important}.qaid-q-range::-moz-range-thumb{transition:none!important}}@media(forced-colors:active){.qaid-q-input:focus-visible,.qaid-q-textarea:focus-visible,.qaid-q-option:focus-visible,.qaid-q-btn:focus-visible,.qaid-q-close:focus-visible,.qaid-q-range:focus-visible{outline:2px solid Highlight;outline-offset:2px}.qaid-q-card{border:1px solid CanvasText}.qaid-q-input,.qaid-q-textarea,.qaid-q-option{border-color:CanvasText}.qaid-q-option.qaid-q-selected{border-color:Highlight}.qaid-q-option.qaid-q-selected .qaid-q-option-marker{forced-color-adjust:none;background:Highlight;border-color:Highlight}.qaid-q-option.qaid-q-selected .qaid-q-option-marker:after{background:HighlightText}.qaid-q-progress{forced-color-adjust:none;background:Canvas;border:1px solid CanvasText}.qaid-q-progress-fill{forced-color-adjust:none;background:Highlight}}`,V={default:"",minimal:":where(.qaid-q-root){--qaid-q-card-radius: 0;--qaid-q-card-shadow: none;--qaid-q-btn-radius: 0;--qaid-q-option-radius: 0;--qaid-q-option-bg-selected: transparent;--qaid-q-input-radius: 0}",pill:":where(.qaid-q-root){--qaid-q-card-radius: 1.5rem;--qaid-q-btn-radius: 9999px;--qaid-q-btn-padding-x: 1.5rem;--qaid-q-option-radius: 9999px;--qaid-q-option-padding: .75rem 1.125rem;--qaid-q-input-radius: 9999px;--qaid-q-input-padding: .75rem 1.125rem}",dense:":where(.qaid-q-root){--qaid-q-card-padding: 1rem;--qaid-q-btn-padding-y: .5rem;--qaid-q-btn-padding-x: .875rem;--qaid-q-option-padding: .5rem .625rem;--qaid-q-input-padding: .5rem .625rem;--qaid-q-gap: .5rem;--qaid-q-section-gap: .875rem}"};function D(t){return V[t]??""}function H(t,e,i){const[a,n,s]=[t,e,i].map(r=>(r=r/255,r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4)));return .2126*a+.7152*n+.0722*s}function R(t){if(t.startsWith("#")){const i=t.slice(1),a=i.length===3?i.split("").map(s=>s+s).join(""):i,n=parseInt(a,16);return{r:n>>16&255,g:n>>8&255,b:n&255}}const e=t.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);return e?{r:parseInt(e[1]),g:parseInt(e[2]),b:parseInt(e[3])}:null}function k(t){const e=R(t);return e&&H(e.r,e.g,e.b)>.4?"black":"white"}function O(t={}){const e={};return t.accentColor!==void 0&&(e["--qaid-q-accent"]=t.accentColor,e["--qaid-q-accent-text"]=k(t.accentColor)),t.errorColor!==void 0&&(e["--qaid-q-error"]=t.errorColor),t.focusColor!==void 0&&(e["--qaid-q-focus"]=t.focusColor,e["--qaid-q-focus-text"]=k(t.focusColor)),t.modalWidth!==void 0&&(e["--qaid-modal-width"]=`${t.modalWidth}px`),t.backdropOpacity!==void 0&&(e["--qaid-backdrop-opacity"]=String(t.backdropOpacity)),t.fontFamily!==void 0&&(e["--qaid-font-family"]=t.fontFamily),t.fontSize!==void 0&&(e["--qaid-font-size"]=`${t.fontSize}px`),e}function P(t,e){for(const[i,a]of Object.entries(e))t.style.setProperty(i,a)}function j(){return v}function U(t){return D(t)}function y(t){let e=null;return{setInvalid(i){t.setAttribute("aria-invalid","true");const a=(t.getAttribute("aria-describedby")??"").split(/\s+/).filter(Boolean);a.includes(i)||a.push(i),t.setAttribute("aria-describedby",a.join(" ")),e=i},clearInvalid(){if(t.removeAttribute("aria-invalid"),e){const i=(t.getAttribute("aria-describedby")??"").split(/\s+/).filter(Boolean).filter(a=>a!==e);i.length?t.setAttribute("aria-describedby",i.join(" ")):t.removeAttribute("aria-describedby"),e=null}}}}function $(t){switch(t.question.type){case"text":return F(t.question,t);case"currency":return M(t.question,t);case"range":return B(t.question,t);case"date":return Y(t.question,t);case"multiple-choice":return W(t.question,t)}}function F(t,e){const i=typeof e.initialValue=="string"?e.initialValue:"";let a;if(t.multiline){const n=document.createElement("textarea");n.className="qaid-q-textarea",n.value=i,t.placeholder&&(n.placeholder=t.placeholder),t.maxLength&&(n.maxLength=t.maxLength),a=n}else{const n=document.createElement("input");n.className="qaid-q-input",n.type=t.inputType??"text",n.value=i,t.placeholder&&(n.placeholder=t.placeholder),t.maxLength&&(n.maxLength=t.maxLength),n.setAttribute("autocomplete",Q(t.inputType)),a=n}return a.setAttribute("aria-label",t.label),t.required&&a.setAttribute("aria-required","true"),a.addEventListener("input",()=>{e.onChange(a.value)}),a.addEventListener("keydown",(n=>{if(n.key==="Enter"){if(t.multiline){(n.metaKey||n.ctrlKey)&&(n.preventDefault(),e.onSubmit());return}n.isComposing||(n.preventDefault(),e.onSubmit())}})),{element:a,focus:()=>{a.focus();const n=a.value.length;try{a.setSelectionRange(n,n)}catch{}},getValue:()=>a.value,isValid:()=>{if(!t.required)return!0;const n=a.value.trim();return!(n.length===0||t.minLength&&n.length<t.minLength)},...y(a)}}function Q(t){switch(t){case"email":return"email";case"tel":return"tel";case"url":return"url";default:return"off"}}function M(t,e){const i=document.createElement("div");i.className="qaid-q-currency";const a=document.createElement("span");a.className="qaid-q-currency-prefix",a.textContent=K(t.currency??"USD",t.locale),i.appendChild(a);const n=document.createElement("input");return n.className="qaid-q-input",n.type="number",n.inputMode="decimal",n.step="0.01",typeof t.min=="number"&&(n.min=String(t.min)),typeof t.max=="number"&&(n.max=String(t.max)),t.placeholder&&(n.placeholder=t.placeholder),typeof e.initialValue=="number"?n.value=String(e.initialValue):typeof e.initialValue=="string"&&e.initialValue!==""&&(n.value=e.initialValue),n.setAttribute("aria-label",t.label),t.required&&n.setAttribute("aria-required","true"),n.addEventListener("input",()=>{const s=n.value;if(s==="")e.onChange(null);else{const r=Number(s);e.onChange(Number.isNaN(r)?null:r)}}),n.addEventListener("keydown",s=>{s.key==="Enter"&&!s.isComposing&&(s.preventDefault(),e.onSubmit())}),i.appendChild(n),{element:i,focus:()=>n.focus(),getValue:()=>{if(n.value==="")return null;const s=Number(n.value);return Number.isNaN(s)?null:s},isValid:()=>{const s=n.value===""?null:Number(n.value);return!(t.required&&(s===null||Number.isNaN(s))||s!==null&&!Number.isNaN(s)&&(typeof t.min=="number"&&s<t.min||typeof t.max=="number"&&s>t.max))},...y(n)}}function K(t,e){try{return new Intl.NumberFormat(e,{style:"currency",currency:t,currencyDisplay:"narrowSymbol",maximumFractionDigits:0}).formatToParts(0).find(s=>s.type==="currency")?.value??t}catch{return t}}function B(t,e){const i=document.createElement("div");i.className="qaid-q-range-wrap";const a=document.createElement("div");a.className="qaid-q-range-value";const n=document.createElement("span");if(a.appendChild(n),t.unit){const o=document.createElement("span");o.className="qaid-q-range-unit",o.textContent=t.unit,a.appendChild(o)}const s=typeof e.initialValue=="number"?e.initialValue:t.defaultValue??t.min,r=document.createElement("input");r.className="qaid-q-range",r.type="range",r.min=String(t.min),r.max=String(t.max),r.step=String(t.step??1),r.value=String(s),r.setAttribute("aria-label",t.label),r.setAttribute("aria-valuemin",String(t.min)),r.setAttribute("aria-valuemax",String(t.max));const c=()=>{n.textContent=r.value,r.setAttribute("aria-valuenow",r.value)};c(),r.addEventListener("input",()=>{c(),e.onChange(Number(r.value))}),r.addEventListener("keydown",o=>{o.key==="Enter"&&(o.preventDefault(),e.onSubmit())});const q=document.createElement("div");q.className="qaid-q-range-bounds";const p=document.createElement("span");p.textContent=`${t.min}${t.unit??""}`;const m=document.createElement("span");return m.textContent=`${t.max}${t.unit??""}`,q.appendChild(p),q.appendChild(m),i.appendChild(a),i.appendChild(r),i.appendChild(q),queueMicrotask(()=>e.onChange(Number(r.value))),{element:i,focus:()=>r.focus(),getValue:()=>Number(r.value),isValid:()=>!0,...y(r)}}function Y(t,e){const i=document.createElement("input");return i.className="qaid-q-input",i.type="date",t.min&&(i.min=t.min),t.max&&(i.max=t.max),typeof e.initialValue=="string"&&(i.value=e.initialValue),i.setAttribute("aria-label",t.label),t.required&&i.setAttribute("aria-required","true"),i.addEventListener("input",()=>{e.onChange(i.value||null)}),i.addEventListener("keydown",a=>{a.key==="Enter"&&!a.isComposing&&(a.preventDefault(),e.onSubmit())}),{element:i,focus:()=>i.focus(),getValue:()=>i.value||null,isValid:()=>t.required?i.value!=="":!0,...y(i)}}function W(t,e){const i=document.createElement("div"),a=t.imageAlignment??"horizontal",s=t.options.some(o=>!!o.image)?a==="vertical"?" qaid-q-options--image-vertical":" qaid-q-options--image-horizontal":"";i.className=`qaid-q-options${s}`,i.setAttribute("role",t.multiple?"group":"radiogroup"),i.setAttribute("aria-label",t.label),t.required&&i.setAttribute("aria-required","true");const r=new Set;if(t.multiple&&Array.isArray(e.initialValue))for(const o of e.initialValue)r.add(o);else!t.multiple&&typeof e.initialValue=="string"&&r.add(e.initialValue);const c=[];t.options.forEach((o,u)=>{const d=document.createElement("button");d.type="button",d.className=`qaid-q-option${t.multiple?" qaid-q-multi":""}`,d.dataset.value=o.value,d.setAttribute("role",t.multiple?"checkbox":"radio"),d.setAttribute("aria-checked",r.has(o.value)?"true":"false"),r.has(o.value)&&d.classList.add("qaid-q-selected");const f=document.createElement("span");f.className="qaid-q-option-marker",f.setAttribute("aria-hidden","true");const g=document.createElement("span");if(g.className="qaid-q-option-body",o.image){const l=document.createElement("img");l.className="qaid-q-option-image",l.src=o.image,l.alt="",l.loading="lazy",l.decoding="async",g.appendChild(l)}const h=document.createElement("span");if(h.className="qaid-q-option-label",h.textContent=o.label,g.appendChild(h),o.description){const l=document.createElement("span");l.className="qaid-q-option-desc",l.textContent=o.description,g.appendChild(l)}if(d.appendChild(f),d.appendChild(g),u<9){const l=document.createElement("span");l.className="qaid-q-option-key",l.textContent=String(u+1),l.setAttribute("aria-hidden","true"),d.appendChild(l)}d.addEventListener("click",()=>p(u)),d.addEventListener("keydown",l=>{if(l.key==="ArrowDown"||l.key==="ArrowRight"){l.preventDefault(),q((u+1)%c.length);return}if(l.key==="ArrowUp"||l.key==="ArrowLeft"){l.preventDefault(),q((u-1+c.length)%c.length);return}!t.multiple&&l.key==="Enter"&&r.size>0&&(l.preventDefault(),e.onSubmit())}),c.push(d),i.appendChild(d)}),i.addEventListener("keydown",o=>{const u=o.key;if(u.length===1&&u>="1"&&u<="9"){const d=parseInt(u,10)-1;d<c.length&&(o.preventDefault(),p(d),q(d))}});function q(o){c[o]?.focus()}function p(o){const u=t.options[o].value;t.multiple?r.has(u)?r.delete(u):r.add(u):(r.clear(),r.add(u)),c.forEach(d=>{const f=d.dataset.value,g=r.has(f);d.classList.toggle("qaid-q-selected",g),d.setAttribute("aria-checked",g?"true":"false")}),e.onChange(m()),!t.multiple&&e.autoAdvance&&setTimeout(()=>e.onAutoAdvance(),180)}function m(){if(t.multiple)return Array.from(r);const o=r.values().next();return o.done?null:o.value}return{element:i,focus:()=>{(c.find(u=>u.classList.contains("qaid-q-selected"))??c[0])?.focus()},getValue:()=>m(),isValid:()=>t.required?r.size>0:!0,...y(i)}}function C(t,e){return t.questions.filter(i=>i.visibleIf?x(i.visibleIf,e):!0)}function x(t,e){if("allOf"in t){for(const n of t.allOf)if(!x(n,e))return!1;return!0}if("anyOf"in t){for(const n of t.anyOf)if(x(n,e))return!0;return!1}const i=e[t.questionId],a=i!=null&&!(typeof i=="string"&&i.trim()==="")&&!(Array.isArray(i)&&i.length===0);return"answered"in t?t.answered?a:!a:a?"equals"in t?w(i,t.equals):"notEquals"in t?!w(i,t.notEquals):"in"in t?t.in.some(n=>w(i,n)):!1:!1}function w(t,e){return Array.isArray(t)?t.some(i=>i===e):t===e}const A="data-qaid-a11y-live",_="position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;",G=["a[href]","button","input","textarea","select","[tabindex]"].join(",");function J(t){return t.ownerDocument||document}function X(t,e){const i=e?"assertive":"polite",a=t.querySelector(`[${A}="${i}"]`);if(a)return a;const s=J(t).createElement("div");return s.setAttribute(A,i),s.setAttribute("role",e?"alert":"status"),s.setAttribute("aria-live",e?"assertive":"polite"),s.setAttribute("aria-atomic","true"),s.style.cssText=_,t.appendChild(s),s}function E(t,e,i={}){const a=X(t,!!i.assertive);a.textContent="",a.textContent=e}function Z(t){return t.hasAttribute("disabled")?!0:t.disabled===!0}function ee(t){let e=t;for(;e;){if(e.hasAttribute("hidden"))return!0;const i=e.style;if(i&&(i.display==="none"||i.visibility==="hidden"||i.visibility==="collapse"))return!0;e=e.parentElement}return!1}function S(t){return Array.from(t.querySelectorAll(G)).filter(i=>!(i.getAttribute("tabindex")==="-1"||i instanceof HTMLInputElement&&i.type==="hidden"||i instanceof HTMLAnchorElement&&!i.getAttribute("href")||Z(i)||ee(i)))}function I(t){let e=t.activeElement;for(;e&&e.shadowRoot&&e.shadowRoot.activeElement;)e=e.shadowRoot.activeElement;return e instanceof HTMLElement?e:null}function te(t){const e=t.ownerDocument||document;let i=!1;const a=s=>{if(s.key!=="Tab")return;const r=S(t);if(r.length===0){s.preventDefault(),t.focus();return}const c=r[0],q=r[r.length-1],p=I(e),m=p?r.indexOf(p)!==-1:!1;s.shiftKey?(!m||p===c)&&(s.preventDefault(),q.focus()):(!m||p===q)&&(s.preventDefault(),c.focus())};t.addEventListener("keydown",a);const n=S(t);return n.length>0?n[0].focus():(t.hasAttribute("tabindex")||(t.setAttribute("tabindex","-1"),i=!0),t.focus()),{release(){t.removeEventListener("keydown",a),i&&(t.removeAttribute("tabindex"),i=!1)}}}function ie(){return I(document)}function ae(t){if(!(!t||typeof t.focus!="function"))try{t.focus()}catch{}}function ne(t,e={}){t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),e.labelledbyId&&t.setAttribute("aria-labelledby",e.labelledbyId),e.describedbyId&&t.setAttribute("aria-describedby",e.describedbyId),e.label&&t.setAttribute("aria-label",e.label)}function re(t,e){let i=t;for(;i&&i!==e;){const a=i.parentNode;if(a===e)return i;if(a&&a.host){i=a.host;continue}if(!a)return null;i=a}return null}function se(t){const i=(t.ownerDocument||document).body;if(!i)return()=>{};const a=re(t,i),n=[];return Array.from(i.children).forEach(s=>{if(!(s instanceof HTMLElement)||a&&s===a)return;const r=s.inert===!0,c=s.getAttribute("aria-hidden");r&&c==="true"||(s.inert=!0,s.setAttribute("aria-hidden","true"),n.push({el:s,prevInert:r,prevAriaHidden:c}))}),function(){for(;n.length;){const r=n.pop();r&&(r.el.inert=r.prevInert,r.prevAriaHidden===null?r.el.removeAttribute("aria-hidden"):r.el.setAttribute("aria-hidden",r.prevAriaHidden))}}}const N="qaid_visitor_id";function oe(){try{let t=localStorage.getItem(N);return t||(t=crypto.randomUUID(),localStorage.setItem(N,t)),t}catch{return crypto.randomUUID()}}const de='<svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><path d="M2 2l10 10M12 2L2 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill="none"/></svg>',le='<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12l4 4L19 7" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>';class T{config;questionnaire=null;inlineQuestionnaire;configUrl;state="LOADING";stepIndex=0;visibleQuestions=[];pendingGoToStep=null;hasRenderedStep=!1;answers={};responseId=null;visitorId;pendingSaveTimer=null;pendingSaveQuestionId=null;pendingSaveValue=null;inflightSaves=0;shadowHost=null;shadowRoot=null;isUserContainer=!1;rootEl=null;cardEl=null;titleEl=null;stepCounterEl=null;progressEl=null;progressFillEl=null;bodyEl=null;footerEl=null;savingEl=null;backdropEl=null;currentInput=null;boundKeyDown;savedOpener=null;focusTrap=null;inertRestore=null;cssVars={};hostThemeOverrides;hostInlineVars;themeUrl;themeDocument;hostCss;constructor(e){this.config={endpoint:e.endpoint,apiKey:e.apiKey??"",container:e.container??"",zIndex:e.zIndex??50,colors:{accent:e.colors?.accent??e.colors?.positive??"#10b981",error:e.colors?.error??e.colors?.negative??"#ef4444",focus:e.colors?.focus??e.colors?.marker??"#6366f1"},modalWidth:e.modalWidth??480,backdropOpacity:e.backdropOpacity??.4,fontFamily:e.fontFamily??"system-ui, -apple-system, sans-serif",fontSize:e.fontSize??16,css:e.css??"",autoAdvance:e.autoAdvance??!1,saveDebounceMs:e.saveDebounceMs??500,autoFocus:e.autoFocus??!0,animate:e.animate??!0,progressPosition:e.progressPosition,theme:e.theme??"auto",unstyled:e.unstyled??!1,preset:e.preset??"default"},this.hostThemeOverrides={preset:e.preset!==void 0,mode:e.theme!==void 0,unstyled:e.unstyled!==void 0,css:e.css!==void 0},this.hostInlineVars={accentColor:e.colors?.accent??e.colors?.positive,errorColor:e.colors?.error??e.colors?.negative,focusColor:e.colors?.focus??e.colors?.marker,modalWidth:e.modalWidth,backdropOpacity:e.backdropOpacity,fontFamily:e.fontFamily,fontSize:e.fontSize},this.themeUrl=e.themeUrl,this.themeDocument=e.themeDocument,this.hostCss=e.css??"",this.inlineQuestionnaire=e.questionnaire,this.configUrl=e.configUrl,this.visitorId=oe(),this.boundKeyDown=this.handleKeyDown.bind(this),this.init()}async init(){this.cssVars=O(this.hostInlineVars),this.mountShell(),this.renderLoading();try{const[e,i]=await Promise.all([this.loadQuestionnaire(),this.loadTheme()]);if(!e||!e.questions||e.questions.length===0)throw new Error("Questionnaire is empty");if(this.questionnaire=e,this.applyResolvedTheme(i),this.recomputeVisible(),this.pendingGoToStep){const a=this.visibleQuestions.findIndex(n=>n.id===this.pendingGoToStep);a!==-1&&(this.stepIndex=a),this.pendingGoToStep=null}this.createResponse(),this.state="READY",this.renderHeader(),this.renderStep(),this.setupModalA11y()}catch(e){this.state="ERROR",this.renderError(e)}}async loadTheme(){if(this.themeDocument)return this.themeDocument;if(!this.themeUrl)return null;try{const e=await fetch(this.themeUrl,{headers:{Accept:"application/json"}});return e.ok?await e.json():(console.warn(`[quests-embed] theme fetch failed (${e.status}) — rendering with defaults`),null)}catch(e){return console.warn("[quests-embed] theme fetch error — rendering with defaults",e),null}}applyResolvedTheme(e){if(!this.shadowRoot||!this.rootEl)return;const i=this.hostThemeOverrides.preset?this.config.preset:e?.preset??this.config.preset,a=this.hostThemeOverrides.mode?this.config.theme:e?.mode??this.config.theme,n=this.hostThemeOverrides.unstyled?this.config.unstyled:e?.unstyled??this.config.unstyled;this.rootEl.classList.toggle("qaid-q-theme-light",a==="light"),this.rootEl.classList.toggle("qaid-q-theme-dark",a==="dark"),this.rootEl.classList.toggle("qaid-q-unstyled",!!n);const s=[];if(e?.tokens&&Object.keys(e.tokens).length>0){const r=Object.entries(e.tokens).filter(([,c])=>typeof c=="string"&&c.trim()!=="").map(([c,q])=>` ${c}: ${q};`).join(`
2
- `);r&&s.push(`:where(.qaid-q-root) {
1
+ (function(b,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(b=typeof globalThis<"u"?globalThis:b||self,v(b.QaidQuests={}))})(this,(function(b){"use strict";const v=`*{box-sizing:border-box}button{cursor:pointer;font-family:inherit}:where(.qaid-q-root){--qaid-q-card-bg: light-dark(#ffffff, #1f2937);--qaid-q-card-fg: light-dark(#1f2937, #f9fafb);--qaid-q-card-border: light-dark(#e5e7eb, #374151);--qaid-q-card-radius: 1rem;--qaid-q-card-padding: 1.5rem;--qaid-q-card-shadow: 0 25px 50px -12px light-dark(rgba(0, 0, 0, .25), rgba(0, 0, 0, .6));--qaid-q-muted-fg: light-dark(#6b7280, #9ca3af);--qaid-q-progress-track: light-dark(#e5e7eb, #374151);--qaid-q-btn-radius: .5rem;--qaid-q-btn-padding-y: .625rem;--qaid-q-btn-padding-x: 1.125rem;--qaid-q-btn-font-weight: 500;--qaid-q-btn-primary-bg: var(--qaid-q-accent, #10b981);--qaid-q-btn-primary-fg: var(--qaid-q-accent-text, #ffffff);--qaid-q-btn-primary-border: transparent;--qaid-q-btn-secondary-bg: transparent;--qaid-q-btn-secondary-fg: light-dark(#374151, #d1d5db);--qaid-q-btn-secondary-border: light-dark(#d1d5db, #4b5563);--qaid-q-btn-secondary-hover-bg: light-dark(#f3f4f6, #374151);--qaid-q-option-bg: light-dark(#ffffff, #111827);--qaid-q-option-bg-selected: color-mix(in srgb, var(--qaid-q-accent, #10b981) 10%, transparent);--qaid-q-option-bg-hover: light-dark(#f9fafb, #1f2937);--qaid-q-option-fg: light-dark(#1f2937, #f9fafb);--qaid-q-option-border: light-dark(#e5e7eb, #374151);--qaid-q-option-border-selected: var(--qaid-q-accent, #10b981);--qaid-q-option-border-hover: light-dark(#9ca3af, #4b5563);--qaid-q-option-radius: .625rem;--qaid-q-option-padding: .75rem .875rem;--qaid-q-marker-bg: light-dark(#ffffff, #111827);--qaid-q-marker-bg-selected: var(--qaid-q-accent, #10b981);--qaid-q-marker-border: light-dark(#d1d5db, #4b5563);--qaid-q-marker-icon: light-dark(#ffffff, #1f2937);--qaid-q-marker-radius: 50%;--qaid-q-input-bg: light-dark(#ffffff, #111827);--qaid-q-input-fg: light-dark(#1f2937, #f9fafb);--qaid-q-input-border: light-dark(#d1d5db, #374151);--qaid-q-input-radius: .625rem;--qaid-q-input-padding: .75rem .875rem;--qaid-q-input-placeholder: light-dark(#9ca3af, #6b7280);--qaid-q-gap: .75rem;--qaid-q-section-gap: 1.25rem}:where(.qaid-q-root.qaid-q-theme-light){--qaid-q-card-bg: #ffffff;--qaid-q-card-fg: #1f2937;--qaid-q-card-border: #e5e7eb;--qaid-q-card-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25);--qaid-q-muted-fg: #6b7280;--qaid-q-progress-track: #e5e7eb;--qaid-q-btn-secondary-fg: #374151;--qaid-q-btn-secondary-border: #d1d5db;--qaid-q-btn-secondary-hover-bg: #f3f4f6;--qaid-q-option-bg: #ffffff;--qaid-q-option-bg-hover: #f9fafb;--qaid-q-option-fg: #1f2937;--qaid-q-option-border: #e5e7eb;--qaid-q-option-border-hover: #9ca3af;--qaid-q-marker-bg: #ffffff;--qaid-q-marker-border: #d1d5db;--qaid-q-marker-icon: #ffffff;--qaid-q-input-bg: #ffffff;--qaid-q-input-fg: #1f2937;--qaid-q-input-border: #d1d5db;--qaid-q-input-placeholder: #9ca3af}:where(.qaid-q-root.qaid-q-theme-dark){--qaid-q-card-bg: #1f2937;--qaid-q-card-fg: #f9fafb;--qaid-q-card-border: #374151;--qaid-q-card-shadow: 0 25px 50px -12px rgba(0, 0, 0, .6);--qaid-q-muted-fg: #9ca3af;--qaid-q-progress-track: #374151;--qaid-q-btn-secondary-fg: #d1d5db;--qaid-q-btn-secondary-border: #4b5563;--qaid-q-btn-secondary-hover-bg: #374151;--qaid-q-option-bg: #111827;--qaid-q-option-bg-hover: #1f2937;--qaid-q-option-fg: #f9fafb;--qaid-q-option-border: #374151;--qaid-q-option-border-hover: #4b5563;--qaid-q-marker-bg: #111827;--qaid-q-marker-border: #4b5563;--qaid-q-marker-icon: #1f2937;--qaid-q-input-bg: #111827;--qaid-q-input-fg: #f9fafb;--qaid-q-input-border: #374151;--qaid-q-input-placeholder: #6b7280}.qaid-q-root{color-scheme:light dark;font-family:var(--qaid-font-family, system-ui, -apple-system, sans-serif);font-size:var(--qaid-font-size, 16px);color:var(--qaid-q-card-fg)}.qaid-q-root.qaid-q-theme-light{color-scheme:light}.qaid-q-root.qaid-q-theme-dark{color-scheme:dark}.qaid-q-backdrop{position:fixed;inset:0;z-index:45;background:rgba(0,0,0,var(--qaid-backdrop-opacity, .4));animation:qaid-q-fade .18s ease-out}@keyframes qaid-q-fade{0%{opacity:0}to{opacity:1}}.qaid-q-modal{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:50;width:var(--qaid-modal-width, 480px);max-width:calc(100vw - 32px);max-height:calc(100vh - 32px);pointer-events:auto;display:flex;flex-direction:column}.qaid-q-card{background:var(--qaid-q-card-bg);color:var(--qaid-q-card-fg);border-radius:var(--qaid-q-card-radius);box-shadow:var(--qaid-q-card-shadow);padding:var(--qaid-q-card-padding);overflow:hidden;display:flex;flex-direction:column;min-height:0}:where(.qaid-q-root.qaid-q-inline) .qaid-q-card{box-shadow:none;border:1px solid var(--qaid-q-card-border);flex:1;min-height:0}:where(.qaid-q-root.qaid-q-inline){height:100%;display:flex;flex-direction:column;min-height:0}.qaid-q-header{display:flex;align-items:center;justify-content:space-between;gap:.75rem;margin-bottom:1rem}.qaid-q-title{font-size:1.125em;font-weight:700;margin:0;color:var(--qaid-q-card-fg)}.qaid-q-step-counter{font-size:.875em;color:var(--qaid-q-muted-fg);font-variant-numeric:tabular-nums;white-space:nowrap}.qaid-q-close{width:28px;height:28px;padding:0;border:none;border-radius:50%;background:transparent;color:var(--qaid-q-muted-fg);display:inline-flex;align-items:center;justify-content:center;-webkit-appearance:none;appearance:none}.qaid-q-close:hover{background:var(--qaid-q-btn-secondary-hover-bg);color:var(--qaid-q-card-fg)}.qaid-q-close:focus-visible{outline:none;box-shadow:0 0 0 3px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 30%,transparent)}.qaid-q-progress{position:relative;height:4px;background:var(--qaid-q-progress-track);border-radius:9999px;overflow:hidden;margin-bottom:var(--qaid-q-section-gap)}.qaid-q-progress--inline{flex:1;min-width:60px;margin-bottom:0}.qaid-q-progress-fill{position:absolute;inset:0 auto 0 0;background:var(--qaid-q-accent, #10b981);border-radius:9999px;transition:width .3s ease;width:0%}.qaid-q-body{flex:1;min-height:0;overflow-y:auto;position:relative}.qaid-q-body[data-qaid-scroll=top]{-webkit-mask-image:linear-gradient(to bottom,#000 calc(100% - 2.5rem),transparent 100%);mask-image:linear-gradient(to bottom,#000 calc(100% - 2.5rem),transparent 100%)}.qaid-q-body[data-qaid-scroll=middle]{-webkit-mask-image:linear-gradient(to bottom,transparent 0,#000 2rem,#000 calc(100% - 2.5rem),transparent 100%);mask-image:linear-gradient(to bottom,transparent 0,#000 2rem,#000 calc(100% - 2.5rem),transparent 100%)}.qaid-q-body[data-qaid-scroll=bottom]{-webkit-mask-image:linear-gradient(to bottom,transparent 0,#000 2rem);mask-image:linear-gradient(to bottom,transparent 0,#000 2rem)}.qaid-q-scroll-cue{position:sticky;bottom:0;left:0;display:flex;justify-content:center;align-items:flex-end;height:1.5rem;margin-top:-1.5rem;pointer-events:none;color:var(--qaid-q-muted-fg)}.qaid-q-scroll-cue[hidden]{display:none}.qaid-q-scroll-cue svg{width:1.125rem;height:1.125rem;animation:qaid-q-nudge 1.6s ease-in-out infinite}@keyframes qaid-q-nudge{0%,to{transform:translateY(-2px);opacity:.55}50%{transform:translateY(2px);opacity:1}}.qaid-q-card[data-qaid-fit=compact] .qaid-q-options--image-vertical{grid-template-columns:repeat(auto-fit,minmax(104px,1fr));gap:.375rem}.qaid-q-card[data-qaid-fit=compact] .qaid-q-options--image-vertical .qaid-q-option{padding:.5rem;gap:.375rem}.qaid-q-card[data-qaid-fit=compact] .qaid-q-options--image-vertical .qaid-q-option-image{max-height:5.5rem;object-fit:contain}.qaid-q-card[data-qaid-fit=compact] .qaid-q-option-desc{font-size:.75em}.qaid-q-card[data-qaid-fit=compact] .qaid-q-step{gap:calc(var(--qaid-q-gap) * .6)}.qaid-q-card[data-qaid-fit=compact] .qaid-q-options--image-horizontal .qaid-q-option-image{width:36px;height:36px}.qaid-q-step{display:flex;flex-direction:column;gap:var(--qaid-q-gap);animation:qaid-q-slide .22s ease-out}@keyframes qaid-q-slide{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.qaid-q-no-motion .qaid-q-step,.qaid-q-no-motion.qaid-q-root{animation:none!important}.qaid-q-label{font-size:1.125em;font-weight:600;margin:0;color:var(--qaid-q-card-fg);line-height:1.35}.qaid-q-label .qaid-q-required{color:var(--qaid-q-error, #ef4444);margin-left:.25rem}.qaid-q-description{font-size:.875em;color:var(--qaid-q-muted-fg);margin:0;line-height:1.4}.qaid-q-error{font-size:.8125em;color:var(--qaid-q-error, #ef4444);margin:0}.qaid-q-error:empty{display:none}.qaid-q-input,.qaid-q-textarea{width:100%;padding:var(--qaid-q-input-padding);border:1px solid var(--qaid-q-input-border);border-radius:var(--qaid-q-input-radius);font-family:inherit;font-size:1em;background:var(--qaid-q-input-bg);color:var(--qaid-q-input-fg);transition:border-color .15s,box-shadow .15s;-webkit-appearance:none;appearance:none}.qaid-q-textarea{min-height:7rem;resize:vertical;font-family:inherit}.qaid-q-input:focus,.qaid-q-textarea:focus{outline:none;border-color:var(--qaid-q-focus, #6366f1);box-shadow:0 0 0 3px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 20%,transparent)}.qaid-q-input::placeholder,.qaid-q-textarea::placeholder{color:var(--qaid-q-input-placeholder)}.qaid-q-currency{position:relative}.qaid-q-currency-prefix{position:absolute;left:.875rem;top:50%;transform:translateY(-50%);color:var(--qaid-q-muted-fg);font-size:1em;font-weight:500;pointer-events:none}.qaid-q-currency .qaid-q-input{padding-left:2.25rem}.qaid-q-range-wrap{display:flex;flex-direction:column;gap:.5rem;padding:.5rem 0}.qaid-q-range-value{font-size:2em;font-weight:700;text-align:center;font-variant-numeric:tabular-nums;color:var(--qaid-q-accent, #10b981)}.qaid-q-range-value .qaid-q-range-unit{font-size:.5em;font-weight:500;color:var(--qaid-q-muted-fg);margin-left:.25rem}.qaid-q-range{width:100%;-webkit-appearance:none;appearance:none;height:6px;border-radius:9999px;background:var(--qaid-q-progress-track);outline:none}.qaid-q-range::-webkit-slider-thumb{-webkit-appearance:none;appearance:none;width:24px;height:24px;border-radius:50%;background:var(--qaid-q-accent, #10b981);border:3px solid var(--qaid-q-card-bg);box-shadow:0 2px 6px #0003;cursor:pointer;transition:transform .1s}.qaid-q-range::-moz-range-thumb{width:24px;height:24px;border-radius:50%;background:var(--qaid-q-accent, #10b981);border:3px solid var(--qaid-q-card-bg);box-shadow:0 2px 6px #0003;cursor:pointer}.qaid-q-range:focus-visible::-webkit-slider-thumb{box-shadow:0 0 0 6px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 30%,transparent)}.qaid-q-range:focus-visible::-moz-range-thumb{box-shadow:0 0 0 6px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 30%,transparent)}.qaid-q-range-bounds{display:flex;justify-content:space-between;font-size:.8125em;color:var(--qaid-q-muted-fg);font-variant-numeric:tabular-nums}.qaid-q-options{display:flex;flex-direction:column;gap:.5rem}.qaid-q-option{display:flex;align-items:flex-start;gap:.625rem;padding:var(--qaid-q-option-padding);border:1px solid var(--qaid-q-option-border);border-radius:var(--qaid-q-option-radius);background:var(--qaid-q-option-bg);text-align:left;font-size:1em;color:var(--qaid-q-option-fg);cursor:pointer;transition:border-color .12s,background .12s,box-shadow .12s;-webkit-appearance:none;appearance:none;width:100%}.qaid-q-option:hover{border-color:var(--qaid-q-option-border-hover);background:var(--qaid-q-option-bg-hover)}.qaid-q-option:focus-visible{outline:none;border-color:var(--qaid-q-focus, #6366f1);box-shadow:0 0 0 3px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 25%,transparent)}.qaid-q-option.qaid-q-selected{border-color:var(--qaid-q-option-border-selected);background:var(--qaid-q-option-bg-selected)}.qaid-q-option-marker{flex-shrink:0;width:1.25rem;height:1.25rem;border:2px solid var(--qaid-q-marker-border);border-radius:var(--qaid-q-marker-radius);display:inline-flex;align-items:center;justify-content:center;margin-top:.125rem;background:var(--qaid-q-marker-bg);transition:border-color .12s,background .12s}.qaid-q-option.qaid-q-multi .qaid-q-option-marker{border-radius:.25rem}.qaid-q-option.qaid-q-selected .qaid-q-option-marker{border-color:var(--qaid-q-marker-bg-selected);background:var(--qaid-q-marker-bg-selected)}.qaid-q-option.qaid-q-selected .qaid-q-option-marker:after{content:"";display:block;width:.5rem;height:.5rem;border-radius:50%;background:var(--qaid-q-marker-icon)}.qaid-q-option.qaid-q-multi.qaid-q-selected .qaid-q-option-marker:after{content:"";display:block;width:70%;height:70%;border-radius:0;background:var(--qaid-q-marker-icon);-webkit-mask-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round' d='M5 12l4 4L19 7'/></svg>");mask-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round' d='M5 12l4 4L19 7'/></svg>");-webkit-mask-size:contain;mask-size:contain;-webkit-mask-position:center;mask-position:center;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;transform:none}.qaid-q-option-body{flex:1;min-width:0;display:flex;flex-direction:column;gap:.125rem}.qaid-q-option-image{display:block;width:48px;height:48px;aspect-ratio:1 / 1;object-fit:cover;border-radius:.375rem;background:var(--qaid-q-progress-track);flex-shrink:0}.qaid-q-options--image-horizontal .qaid-q-option-body{flex-direction:row;align-items:center;gap:.75rem}.qaid-q-options--image-horizontal .qaid-q-option-body>:not(.qaid-q-option-image){flex:1;min-width:0;display:flex;flex-direction:column;gap:.125rem}.qaid-q-options--image-vertical{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:.5rem}.qaid-q-options--image-vertical .qaid-q-option{flex-direction:column;align-items:stretch;text-align:center;padding:.75rem;gap:.5rem}.qaid-q-options--image-vertical .qaid-q-option-body{align-items:center;text-align:center}.qaid-q-options--image-vertical .qaid-q-option-image{width:100%;height:auto;max-width:100%}.qaid-q-options--image-vertical .qaid-q-option-marker{position:absolute;top:.5rem;right:.5rem;margin-top:0}.qaid-q-options--image-vertical .qaid-q-option{position:relative}.qaid-q-options--image-vertical .qaid-q-option-key{position:absolute;top:.5rem;left:.5rem;align-self:auto}.qaid-q-option-label{font-weight:500;line-height:1.3}.qaid-q-option-desc{font-size:.8125em;color:var(--qaid-q-muted-fg);line-height:1.4}.qaid-q-option-key{flex-shrink:0;align-self:center;font-size:.7em;font-weight:600;padding:.125rem .375rem;border-radius:.25rem;background:var(--qaid-q-progress-track);color:var(--qaid-q-muted-fg);font-variant-numeric:tabular-nums}.qaid-q-footer{display:flex;align-items:center;justify-content:space-between;gap:.5rem;margin-top:var(--qaid-q-section-gap)}.qaid-q-footer--inline-progress{justify-content:flex-start;gap:.75rem}.qaid-q-footer-left,.qaid-q-footer-right{display:flex;gap:.5rem}.qaid-q-btn{padding:var(--qaid-q-btn-padding-y) var(--qaid-q-btn-padding-x);border-radius:var(--qaid-q-btn-radius);font-size:var(--qaid-q-btn-font-size, .9375em);font-weight:var(--qaid-q-btn-font-weight);border:1px solid transparent;cursor:pointer;transition:filter .15s,background .15s,color .15s;-webkit-appearance:none;appearance:none}.qaid-q-btn:focus-visible{outline:none;box-shadow:0 0 0 3px color-mix(in srgb,var(--qaid-q-focus, #6366f1) 30%,transparent)}.qaid-q-btn-secondary{background:var(--qaid-q-btn-secondary-bg);border-color:var(--qaid-q-btn-secondary-border);color:var(--qaid-q-btn-secondary-fg)}.qaid-q-btn-secondary:hover{background:var(--qaid-q-btn-secondary-hover-bg)}.qaid-q-btn-primary{background:var(--qaid-q-btn-primary-bg);color:var(--qaid-q-btn-primary-fg);border-color:var(--qaid-q-btn-primary-border)}.qaid-q-btn-primary:hover{filter:brightness(.9)}.qaid-q-btn-primary:disabled{opacity:.5;cursor:not-allowed;filter:none}.qaid-q-done{display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;gap:.5rem;padding:1.5rem 0;flex:1;min-height:0}.qaid-q-done-icon{width:48px;height:48px;border-radius:50%;background:color-mix(in srgb,var(--qaid-q-accent, #10b981) 18%,transparent);color:var(--qaid-q-accent, #10b981);display:inline-flex;align-items:center;justify-content:center;margin-bottom:.5rem}.qaid-q-done-title{font-size:1.25em;font-weight:700;margin:0}.qaid-q-done-message{color:var(--qaid-q-muted-fg);margin:0}.qaid-q-saving{display:inline-flex;align-items:center;gap:.375rem;font-size:.75em;color:var(--qaid-q-muted-fg);opacity:0;transition:opacity .2s}.qaid-q-saving.qaid-q-visible{opacity:1}.qaid-q-saving-dot{width:6px;height:6px;border-radius:50%;background:var(--qaid-q-accent, #10b981);animation:qaid-q-pulse 1.2s ease-in-out infinite}@keyframes qaid-q-pulse{0%,to{opacity:.3}50%{opacity:1}}:where(.qaid-q-root.qaid-q-unstyled) :where(.qaid-q-card,.qaid-q-header,.qaid-q-title,.qaid-q-description,.qaid-q-step,.qaid-q-label,.qaid-q-options,.qaid-q-option,.qaid-q-option-marker,.qaid-q-option-body,.qaid-q-option-label,.qaid-q-option-desc,.qaid-q-input,.qaid-q-textarea,.qaid-q-currency,.qaid-q-currency-prefix,.qaid-q-range,.qaid-q-range-wrap,.qaid-q-range-value,.qaid-q-btn,.qaid-q-footer,.qaid-q-progress,.qaid-q-progress-fill,.qaid-q-step-counter,.qaid-q-error,.qaid-q-saving,.qaid-q-done,.qaid-q-done-icon,.qaid-q-done-title,.qaid-q-done-message){all:unset;display:revert;box-sizing:border-box}.qaid-q-input:focus-visible,.qaid-q-textarea:focus-visible,.qaid-q-option:focus-visible,.qaid-q-btn:focus-visible,.qaid-q-close:focus-visible,.qaid-q-range:focus-visible{outline:2px solid transparent;outline-offset:2px}@media(prefers-reduced-motion:reduce){.qaid-q-root *,.qaid-q-root *:before,.qaid-q-root *:after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important;scroll-behavior:auto!important}.qaid-q-range::-webkit-slider-thumb{transition:none!important}.qaid-q-range::-moz-range-thumb{transition:none!important}}@media(forced-colors:active){.qaid-q-input:focus-visible,.qaid-q-textarea:focus-visible,.qaid-q-option:focus-visible,.qaid-q-btn:focus-visible,.qaid-q-close:focus-visible,.qaid-q-range:focus-visible{outline:2px solid Highlight;outline-offset:2px}.qaid-q-card{border:1px solid CanvasText}.qaid-q-input,.qaid-q-textarea,.qaid-q-option{border-color:CanvasText}.qaid-q-option.qaid-q-selected{border-color:Highlight}.qaid-q-option.qaid-q-selected .qaid-q-option-marker{forced-color-adjust:none;background:Highlight;border-color:Highlight}.qaid-q-option.qaid-q-selected .qaid-q-option-marker:after{background:HighlightText}.qaid-q-progress{forced-color-adjust:none;background:Canvas;border:1px solid CanvasText}.qaid-q-progress-fill{forced-color-adjust:none;background:Highlight}}`,D={default:"",minimal:":where(.qaid-q-root){--qaid-q-card-radius: 0;--qaid-q-card-shadow: none;--qaid-q-btn-radius: 0;--qaid-q-option-radius: 0;--qaid-q-option-bg-selected: transparent;--qaid-q-input-radius: 0}",pill:":where(.qaid-q-root){--qaid-q-card-radius: 1.5rem;--qaid-q-btn-radius: 9999px;--qaid-q-btn-padding-x: 1.5rem;--qaid-q-option-radius: 9999px;--qaid-q-option-padding: .75rem 1.125rem;--qaid-q-input-radius: 9999px;--qaid-q-input-padding: .75rem 1.125rem}",dense:":where(.qaid-q-root){--qaid-q-card-padding: 1rem;--qaid-q-btn-padding-y: .5rem;--qaid-q-btn-padding-x: .875rem;--qaid-q-option-padding: .5rem .625rem;--qaid-q-input-padding: .5rem .625rem;--qaid-q-gap: .5rem;--qaid-q-section-gap: .875rem}"};function O(t){return D[t]??""}function V(t,e,i){const[a,n,o]=[t,e,i].map(r=>(r=r/255,r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4)));return .2126*a+.7152*n+.0722*o}function R(t){if(t.startsWith("#")){const i=t.slice(1),a=i.length===3?i.split("").map(o=>o+o).join(""):i,n=parseInt(a,16);return{r:n>>16&255,g:n>>8&255,b:n&255}}const e=t.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);return e?{r:parseInt(e[1]),g:parseInt(e[2]),b:parseInt(e[3])}:null}function C(t){const e=R(t);return e&&V(e.r,e.g,e.b)>.4?"black":"white"}function P(t={}){const e={};return t.accentColor!==void 0&&(e["--qaid-q-accent"]=t.accentColor,e["--qaid-q-accent-text"]=C(t.accentColor)),t.errorColor!==void 0&&(e["--qaid-q-error"]=t.errorColor),t.focusColor!==void 0&&(e["--qaid-q-focus"]=t.focusColor,e["--qaid-q-focus-text"]=C(t.focusColor)),t.modalWidth!==void 0&&(e["--qaid-modal-width"]=`${t.modalWidth}px`),t.backdropOpacity!==void 0&&(e["--qaid-backdrop-opacity"]=String(t.backdropOpacity)),t.fontFamily!==void 0&&(e["--qaid-font-family"]=t.fontFamily),t.fontSize!==void 0&&(e["--qaid-font-size"]=`${t.fontSize}px`),e}function j(t,e){for(const[i,a]of Object.entries(e))t.style.setProperty(i,a)}function U(){return v}function M(t){return O(t)}function y(t){let e=null;return{setInvalid(i){t.setAttribute("aria-invalid","true");const a=(t.getAttribute("aria-describedby")??"").split(/\s+/).filter(Boolean);a.includes(i)||a.push(i),t.setAttribute("aria-describedby",a.join(" ")),e=i},clearInvalid(){if(t.removeAttribute("aria-invalid"),e){const i=(t.getAttribute("aria-describedby")??"").split(/\s+/).filter(Boolean).filter(a=>a!==e);i.length?t.setAttribute("aria-describedby",i.join(" ")):t.removeAttribute("aria-describedby"),e=null}}}}function F(t){switch(t.question.type){case"text":return $(t.question,t);case"currency":return K(t.question,t);case"range":return Y(t.question,t);case"date":return _(t.question,t);case"multiple-choice":return W(t.question,t)}}function $(t,e){const i=typeof e.initialValue=="string"?e.initialValue:"";let a;if(t.multiline){const n=document.createElement("textarea");n.className="qaid-q-textarea",n.value=i,t.placeholder&&(n.placeholder=t.placeholder),t.maxLength&&(n.maxLength=t.maxLength),a=n}else{const n=document.createElement("input");n.className="qaid-q-input",n.type=t.inputType??"text",n.value=i,t.placeholder&&(n.placeholder=t.placeholder),t.maxLength&&(n.maxLength=t.maxLength),n.setAttribute("autocomplete",Q(t.inputType)),a=n}return a.setAttribute("aria-label",t.label),t.required&&a.setAttribute("aria-required","true"),a.addEventListener("input",()=>{e.onChange(a.value)}),a.addEventListener("keydown",(n=>{if(n.key==="Enter"){if(t.multiline){(n.metaKey||n.ctrlKey)&&(n.preventDefault(),e.onSubmit());return}n.isComposing||(n.preventDefault(),e.onSubmit())}})),{element:a,focus:()=>{a.focus();const n=a.value.length;try{a.setSelectionRange(n,n)}catch{}},getValue:()=>a.value,isValid:()=>{if(!t.required)return!0;const n=a.value.trim();return!(n.length===0||t.minLength&&n.length<t.minLength)},...y(a)}}function Q(t){switch(t){case"email":return"email";case"tel":return"tel";case"url":return"url";default:return"off"}}function K(t,e){const i=document.createElement("div");i.className="qaid-q-currency";const a=document.createElement("span");a.className="qaid-q-currency-prefix",a.textContent=B(t.currency??"USD",t.locale),i.appendChild(a);const n=document.createElement("input");return n.className="qaid-q-input",n.type="number",n.inputMode="decimal",n.step="0.01",typeof t.min=="number"&&(n.min=String(t.min)),typeof t.max=="number"&&(n.max=String(t.max)),t.placeholder&&(n.placeholder=t.placeholder),typeof e.initialValue=="number"?n.value=String(e.initialValue):typeof e.initialValue=="string"&&e.initialValue!==""&&(n.value=e.initialValue),n.setAttribute("aria-label",t.label),t.required&&n.setAttribute("aria-required","true"),n.addEventListener("input",()=>{const o=n.value;if(o==="")e.onChange(null);else{const r=Number(o);e.onChange(Number.isNaN(r)?null:r)}}),n.addEventListener("keydown",o=>{o.key==="Enter"&&!o.isComposing&&(o.preventDefault(),e.onSubmit())}),i.appendChild(n),{element:i,focus:()=>n.focus(),getValue:()=>{if(n.value==="")return null;const o=Number(n.value);return Number.isNaN(o)?null:o},isValid:()=>{const o=n.value===""?null:Number(n.value);return!(t.required&&(o===null||Number.isNaN(o))||o!==null&&!Number.isNaN(o)&&(typeof t.min=="number"&&o<t.min||typeof t.max=="number"&&o>t.max))},...y(n)}}function B(t,e){try{return new Intl.NumberFormat(e,{style:"currency",currency:t,currencyDisplay:"narrowSymbol",maximumFractionDigits:0}).formatToParts(0).find(o=>o.type==="currency")?.value??t}catch{return t}}function Y(t,e){const i=document.createElement("div");i.className="qaid-q-range-wrap";const a=document.createElement("div");a.className="qaid-q-range-value";const n=document.createElement("span");if(a.appendChild(n),t.unit){const s=document.createElement("span");s.className="qaid-q-range-unit",s.textContent=t.unit,a.appendChild(s)}const o=typeof e.initialValue=="number"?e.initialValue:t.defaultValue??t.min,r=document.createElement("input");r.className="qaid-q-range",r.type="range",r.min=String(t.min),r.max=String(t.max),r.step=String(t.step??1),r.value=String(o),r.setAttribute("aria-label",t.label),r.setAttribute("aria-valuemin",String(t.min)),r.setAttribute("aria-valuemax",String(t.max));const c=()=>{n.textContent=r.value,r.setAttribute("aria-valuenow",r.value)};c(),r.addEventListener("input",()=>{c(),e.onChange(Number(r.value))}),r.addEventListener("keydown",s=>{s.key==="Enter"&&(s.preventDefault(),e.onSubmit())});const q=document.createElement("div");q.className="qaid-q-range-bounds";const p=document.createElement("span");p.textContent=`${t.min}${t.unit??""}`;const f=document.createElement("span");return f.textContent=`${t.max}${t.unit??""}`,q.appendChild(p),q.appendChild(f),i.appendChild(a),i.appendChild(r),i.appendChild(q),queueMicrotask(()=>e.onChange(Number(r.value))),{element:i,focus:()=>r.focus(),getValue:()=>Number(r.value),isValid:()=>!0,...y(r)}}function _(t,e){const i=document.createElement("input");return i.className="qaid-q-input",i.type="date",t.min&&(i.min=t.min),t.max&&(i.max=t.max),typeof e.initialValue=="string"&&(i.value=e.initialValue),i.setAttribute("aria-label",t.label),t.required&&i.setAttribute("aria-required","true"),i.addEventListener("input",()=>{e.onChange(i.value||null)}),i.addEventListener("keydown",a=>{a.key==="Enter"&&!a.isComposing&&(a.preventDefault(),e.onSubmit())}),{element:i,focus:()=>i.focus(),getValue:()=>i.value||null,isValid:()=>t.required?i.value!=="":!0,...y(i)}}function W(t,e){const i=document.createElement("div"),a=t.imageAlignment??"horizontal",o=t.options.some(s=>!!s.image)?a==="vertical"?" qaid-q-options--image-vertical":" qaid-q-options--image-horizontal":"";i.className=`qaid-q-options${o}`,i.setAttribute("role",t.multiple?"group":"radiogroup"),i.setAttribute("aria-label",t.label),t.required&&i.setAttribute("aria-required","true");const r=new Set;if(t.multiple&&Array.isArray(e.initialValue))for(const s of e.initialValue)r.add(s);else!t.multiple&&typeof e.initialValue=="string"&&r.add(e.initialValue);const c=[];t.options.forEach((s,u)=>{const d=document.createElement("button");d.type="button",d.className=`qaid-q-option${t.multiple?" qaid-q-multi":""}`,d.dataset.value=s.value,d.setAttribute("role",t.multiple?"checkbox":"radio"),d.setAttribute("aria-checked",r.has(s.value)?"true":"false"),r.has(s.value)&&d.classList.add("qaid-q-selected");const m=document.createElement("span");m.className="qaid-q-option-marker",m.setAttribute("aria-hidden","true");const g=document.createElement("span");if(g.className="qaid-q-option-body",s.image){const l=document.createElement("img");l.className="qaid-q-option-image",l.src=s.image,l.alt="",l.loading="lazy",l.decoding="async",g.appendChild(l)}const h=document.createElement("span");if(h.className="qaid-q-option-label",h.textContent=s.label,g.appendChild(h),s.description){const l=document.createElement("span");l.className="qaid-q-option-desc",l.textContent=s.description,g.appendChild(l)}if(d.appendChild(m),d.appendChild(g),u<9){const l=document.createElement("span");l.className="qaid-q-option-key",l.textContent=String(u+1),l.setAttribute("aria-hidden","true"),d.appendChild(l)}d.addEventListener("click",()=>p(u)),d.addEventListener("keydown",l=>{if(l.key==="ArrowDown"||l.key==="ArrowRight"){l.preventDefault(),q((u+1)%c.length);return}if(l.key==="ArrowUp"||l.key==="ArrowLeft"){l.preventDefault(),q((u-1+c.length)%c.length);return}!t.multiple&&l.key==="Enter"&&r.size>0&&(l.preventDefault(),e.onSubmit())}),c.push(d),i.appendChild(d)}),i.addEventListener("keydown",s=>{const u=s.key;if(u.length===1&&u>="1"&&u<="9"){const d=parseInt(u,10)-1;d<c.length&&(s.preventDefault(),p(d),q(d))}});function q(s){c[s]?.focus()}function p(s){const u=t.options[s].value;t.multiple?r.has(u)?r.delete(u):r.add(u):(r.clear(),r.add(u)),c.forEach(d=>{const m=d.dataset.value,g=r.has(m);d.classList.toggle("qaid-q-selected",g),d.setAttribute("aria-checked",g?"true":"false")}),e.onChange(f()),!t.multiple&&e.autoAdvance&&setTimeout(()=>e.onAutoAdvance(),180)}function f(){if(t.multiple)return Array.from(r);const s=r.values().next();return s.done?null:s.value}return{element:i,focus:()=>{(c.find(u=>u.classList.contains("qaid-q-selected"))??c[0])?.focus()},getValue:()=>f(),isValid:()=>t.required?r.size>0:!0,...y(i)}}function A(t,e){return t.questions.filter(i=>i.visibleIf?x(i.visibleIf,e):!0)}function x(t,e){if("allOf"in t){for(const n of t.allOf)if(!x(n,e))return!1;return!0}if("anyOf"in t){for(const n of t.anyOf)if(x(n,e))return!0;return!1}const i=e[t.questionId],a=i!=null&&!(typeof i=="string"&&i.trim()==="")&&!(Array.isArray(i)&&i.length===0);return"answered"in t?t.answered?a:!a:a?"equals"in t?w(i,t.equals):"notEquals"in t?!w(i,t.notEquals):"in"in t?t.in.some(n=>w(i,n)):!1:!1}function w(t,e){return Array.isArray(t)?t.some(i=>i===e):t===e}const G=360,k=2;function J(t){const e=t.scrollHeight-t.clientHeight;return e<=k?"none":t.scrollTop<=k?"top":t.scrollTop>=e-k?"bottom":"middle"}function X(t,e){const i=J(t);if(t.setAttribute("data-qaid-scroll",i),e){const a=i==="top"||i==="middle";e.hidden=!a}return i}function Z(t,e){const i=e>0&&e<G?"compact":"roomy";return t.setAttribute("data-qaid-fit",i),i}function ee(t,e,i){const a=()=>{X(t,i),Z(e,t.clientHeight)};t.addEventListener("scroll",a,{passive:!0});let n=null;return typeof ResizeObserver=="function"&&(n=new ResizeObserver(a),n.observe(t)),a(),{refresh:a,destroy(){t.removeEventListener("scroll",a),n?.disconnect()}}}const S="data-qaid-a11y-live",te="position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;",ie=["a[href]","button","input","textarea","select","[tabindex]"].join(",");function ae(t){return t.ownerDocument||document}function ne(t,e){const i=e?"assertive":"polite",a=t.querySelector(`[${S}="${i}"]`);if(a)return a;const o=ae(t).createElement("div");return o.setAttribute(S,i),o.setAttribute("role",e?"alert":"status"),o.setAttribute("aria-live",e?"assertive":"polite"),o.setAttribute("aria-atomic","true"),o.style.cssText=te,t.appendChild(o),o}function E(t,e,i={}){const a=ne(t,!!i.assertive);a.textContent="",a.textContent=e}function re(t){return t.hasAttribute("disabled")?!0:t.disabled===!0}function oe(t){let e=t;for(;e;){if(e.hasAttribute("hidden"))return!0;const i=e.style;if(i&&(i.display==="none"||i.visibility==="hidden"||i.visibility==="collapse"))return!0;e=e.parentElement}return!1}function I(t){return Array.from(t.querySelectorAll(ie)).filter(i=>!(i.getAttribute("tabindex")==="-1"||i instanceof HTMLInputElement&&i.type==="hidden"||i instanceof HTMLAnchorElement&&!i.getAttribute("href")||re(i)||oe(i)))}function T(t){let e=t.activeElement;for(;e&&e.shadowRoot&&e.shadowRoot.activeElement;)e=e.shadowRoot.activeElement;return e instanceof HTMLElement?e:null}function se(t){const e=t.ownerDocument||document;let i=!1;const a=o=>{if(o.key!=="Tab")return;const r=I(t);if(r.length===0){o.preventDefault(),t.focus();return}const c=r[0],q=r[r.length-1],p=T(e),f=p?r.indexOf(p)!==-1:!1;o.shiftKey?(!f||p===c)&&(o.preventDefault(),q.focus()):(!f||p===q)&&(o.preventDefault(),c.focus())};t.addEventListener("keydown",a);const n=I(t);return n.length>0?n[0].focus():(t.hasAttribute("tabindex")||(t.setAttribute("tabindex","-1"),i=!0),t.focus()),{release(){t.removeEventListener("keydown",a),i&&(t.removeAttribute("tabindex"),i=!1)}}}function de(){return T(document)}function le(t){if(!(!t||typeof t.focus!="function"))try{t.focus()}catch{}}function ce(t,e={}){t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),e.labelledbyId&&t.setAttribute("aria-labelledby",e.labelledbyId),e.describedbyId&&t.setAttribute("aria-describedby",e.describedbyId),e.label&&t.setAttribute("aria-label",e.label)}function ue(t,e){let i=t;for(;i&&i!==e;){const a=i.parentNode;if(a===e)return i;if(a&&a.host){i=a.host;continue}if(!a)return null;i=a}return null}function he(t){const i=(t.ownerDocument||document).body;if(!i)return()=>{};const a=ue(t,i),n=[];return Array.from(i.children).forEach(o=>{if(!(o instanceof HTMLElement)||a&&o===a)return;const r=o.inert===!0,c=o.getAttribute("aria-hidden");r&&c==="true"||(o.inert=!0,o.setAttribute("aria-hidden","true"),n.push({el:o,prevInert:r,prevAriaHidden:c}))}),function(){for(;n.length;){const r=n.pop();r&&(r.el.inert=r.prevInert,r.prevAriaHidden===null?r.el.removeAttribute("aria-hidden"):r.el.setAttribute("aria-hidden",r.prevAriaHidden))}}}const N="qaid_visitor_id";function qe(){try{let t=localStorage.getItem(N);return t||(t=crypto.randomUUID(),localStorage.setItem(N,t)),t}catch{return crypto.randomUUID()}}const pe='<svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true"><path d="M2 2l10 10M12 2L2 12" stroke="currentColor" stroke-width="2" stroke-linecap="round" fill="none"/></svg>',me='<svg width="24" height="24" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12l4 4L19 7" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>';class L{config;questionnaire=null;inlineQuestionnaire;configUrl;state="LOADING";stepIndex=0;visibleQuestions=[];pendingGoToStep=null;hasRenderedStep=!1;answers={};responseId=null;visitorId;pendingSaveTimer=null;pendingSaveQuestionId=null;pendingSaveValue=null;inflightSaves=0;shadowHost=null;shadowRoot=null;isUserContainer=!1;rootEl=null;cardEl=null;titleEl=null;stepCounterEl=null;progressEl=null;progressFillEl=null;bodyEl=null;scrollCueEl=null;overflow=null;footerEl=null;savingEl=null;backdropEl=null;currentInput=null;boundKeyDown;savedOpener=null;focusTrap=null;inertRestore=null;cssVars={};hostThemeOverrides;hostInlineVars;themeUrl;themeDocument;hostCss;metadata;onCompleteCb;onCloseCb;closed=!1;constructor(e){this.config={endpoint:e.endpoint,apiKey:e.apiKey??"",container:e.container??"",zIndex:e.zIndex??50,colors:{accent:e.colors?.accent??e.colors?.positive??"#10b981",error:e.colors?.error??e.colors?.negative??"#ef4444",focus:e.colors?.focus??e.colors?.marker??"#6366f1"},modalWidth:e.modalWidth??480,backdropOpacity:e.backdropOpacity??.4,fontFamily:e.fontFamily??"system-ui, -apple-system, sans-serif",fontSize:e.fontSize??16,css:e.css??"",autoAdvance:e.autoAdvance??!1,saveDebounceMs:e.saveDebounceMs??500,autoFocus:e.autoFocus??!0,animate:e.animate??!0,progressPosition:e.progressPosition,theme:e.theme??"auto",unstyled:e.unstyled??!1,preset:e.preset??"default"},this.hostThemeOverrides={preset:e.preset!==void 0,mode:e.theme!==void 0,unstyled:e.unstyled!==void 0,css:e.css!==void 0},this.hostInlineVars={accentColor:e.colors?.accent??e.colors?.positive,errorColor:e.colors?.error??e.colors?.negative,focusColor:e.colors?.focus??e.colors?.marker,modalWidth:e.modalWidth,backdropOpacity:e.backdropOpacity,fontFamily:e.fontFamily,fontSize:e.fontSize},this.themeUrl=e.themeUrl,this.themeDocument=e.themeDocument,this.hostCss=e.css??"",this.metadata=e.metadata,this.onCompleteCb=e.onComplete,this.onCloseCb=e.onClose,this.inlineQuestionnaire=e.questionnaire,this.configUrl=e.configUrl,this.visitorId=qe(),this.boundKeyDown=this.handleKeyDown.bind(this),this.init()}async init(){this.cssVars=P(this.hostInlineVars),this.mountShell(),this.renderLoading();try{const[e,i]=await Promise.all([this.loadQuestionnaire(),this.loadTheme()]);if(!e||!e.questions||e.questions.length===0)throw new Error("Questionnaire is empty");if(this.questionnaire=e,this.applyResolvedTheme(i),this.recomputeVisible(),this.pendingGoToStep){const a=this.visibleQuestions.findIndex(n=>n.id===this.pendingGoToStep);a!==-1&&(this.stepIndex=a),this.pendingGoToStep=null}this.createResponse(),this.state="READY",this.renderHeader(),this.renderStep(),this.setupModalA11y()}catch(e){this.state="ERROR",this.renderError(e)}}async loadTheme(){if(this.themeDocument)return this.themeDocument;if(!this.themeUrl)return null;try{const e=await fetch(this.themeUrl,{headers:{Accept:"application/json"}});return e.ok?await e.json():(console.warn(`[quests-embed] theme fetch failed (${e.status}) — rendering with defaults`),null)}catch(e){return console.warn("[quests-embed] theme fetch error — rendering with defaults",e),null}}applyResolvedTheme(e){if(!this.shadowRoot||!this.rootEl)return;const i=this.hostThemeOverrides.preset?this.config.preset:e?.preset??this.config.preset,a=this.hostThemeOverrides.mode?this.config.theme:e?.mode??this.config.theme,n=this.hostThemeOverrides.unstyled?this.config.unstyled:e?.unstyled??this.config.unstyled;this.rootEl.classList.toggle("qaid-q-theme-light",a==="light"),this.rootEl.classList.toggle("qaid-q-theme-dark",a==="dark"),this.rootEl.classList.toggle("qaid-q-unstyled",!!n);const o=[];if(e?.tokens&&Object.keys(e.tokens).length>0){const r=Object.entries(e.tokens).filter(([,c])=>typeof c=="string"&&c.trim()!=="").map(([c,q])=>` ${c}: ${q};`).join(`
2
+ `);r&&o.push(`:where(.qaid-q-root) {
3
3
  ${r}
4
- }`)}if(i&&i!=="default"){const r=U(i);r&&s.push(r)}if(e?.css&&e.css.trim()!==""&&s.push(e.css),this.hostCss&&this.hostCss.trim()!==""&&s.push(this.hostCss),s.length>0){const r=document.createElement("style");r.setAttribute("data-qaid-q-theme",""),r.textContent=s.join(`
4
+ }`)}if(i&&i!=="default"){const r=M(i);r&&o.push(r)}if(e?.css&&e.css.trim()!==""&&o.push(e.css),this.hostCss&&this.hostCss.trim()!==""&&o.push(this.hostCss),o.length>0){const r=document.createElement("style");r.setAttribute("data-qaid-q-theme",""),r.textContent=o.join(`
5
5
 
6
- `),this.shadowRoot.appendChild(r)}}async loadQuestionnaire(){if(this.inlineQuestionnaire)return this.inlineQuestionnaire;if(!this.configUrl)throw new Error("No questionnaire or configUrl provided");const e=await fetch(this.configUrl,{headers:{Accept:"application/json"}});if(!e.ok)throw new Error(`Failed to load questionnaire (${e.status})`);return await e.json()}mountShell(){this.shadowHost=document.createElement("div"),this.shadowHost.setAttribute("data-qaid-quests","");const e=this.config.container?document.querySelector(this.config.container):null;e?(this.shadowHost.style.display="block",this.shadowHost.style.height="100%",this.shadowHost.style.minHeight="0",e.appendChild(this.shadowHost),this.isUserContainer=!0):(this.savedOpener=ie(),this.shadowHost.style.position="fixed",this.shadowHost.style.inset="0",this.shadowHost.style.zIndex=String(this.config.zIndex),this.shadowHost.style.pointerEvents="none",document.body.appendChild(this.shadowHost)),this.shadowRoot=this.shadowHost.attachShadow({mode:"open"});const i=document.createElement("style");if(i.textContent=j(),this.shadowRoot.appendChild(i),this.rootEl=document.createElement("div"),this.rootEl.className=["qaid-q-root",this.isUserContainer?"qaid-q-inline":"",this.config.animate?"":"qaid-q-no-motion"].filter(Boolean).join(" "),P(this.rootEl,this.cssVars),this.isUserContainer)this.cardEl=document.createElement("div"),this.cardEl.className="qaid-q-card",this.rootEl.appendChild(this.cardEl);else{this.backdropEl=document.createElement("div"),this.backdropEl.className="qaid-q-backdrop",this.backdropEl.addEventListener("click",()=>this.close()),this.rootEl.appendChild(this.backdropEl);const a=document.createElement("div");a.className="qaid-q-modal",this.cardEl=document.createElement("div"),this.cardEl.className="qaid-q-card",a.appendChild(this.cardEl),this.rootEl.appendChild(a)}this.shadowRoot.appendChild(this.rootEl),!this.isUserContainer&&this.shadowHost&&(this.shadowHost.style.pointerEvents="auto"),!this.isUserContainer&&this.cardEl&&ne(this.cardEl),document.addEventListener("keydown",this.boundKeyDown)}renderLoading(){if(!this.cardEl)return;this.cardEl.replaceChildren();const e=document.createElement("p");e.className="qaid-q-description",e.textContent="Loading…",this.cardEl.appendChild(e),this.shadowRoot&&E(this.shadowRoot,"Loading")}renderError(e){if(!this.cardEl)return;this.cardEl.replaceChildren();const i=document.createElement("h3");i.className="qaid-q-title",i.textContent="Couldn't load form";const a=e instanceof Error?e.message:String(e),n=document.createElement("p");n.className="qaid-q-description",n.textContent=a,this.cardEl.appendChild(i),this.cardEl.appendChild(n),this.shadowRoot&&E(this.shadowRoot,`Couldn't load form. ${a}`,{assertive:!0})}effectiveProgressPosition(){return this.config.progressPosition??this.questionnaire?.progressPosition??"top"}renderHeader(){if(!this.cardEl||!this.questionnaire)return;this.cardEl.replaceChildren();const e=!!this.questionnaire.hideProgress||this.questionnaire.questions.length<=1,i=!e&&this.effectiveProgressPosition()==="bottom",a=!!this.questionnaire.hideTitle,n=!!this.questionnaire.title&&!a,s=!!this.questionnaire.description&&!a,r=!this.isUserContainer,c=r||!i&&!e;this.savingEl=document.createElement("div"),this.savingEl.className="qaid-q-saving";const q=document.createElement("span");q.className="qaid-q-saving-dot";const p=document.createElement("span");p.textContent="Saving…",this.savingEl.appendChild(q),this.savingEl.appendChild(p),this.stepCounterEl=document.createElement("div"),this.stepCounterEl.className="qaid-q-step-counter",this.progressEl=document.createElement("div"),this.progressEl.className=i?"qaid-q-progress qaid-q-progress--inline":"qaid-q-progress",this.progressFillEl=document.createElement("div"),this.progressFillEl.className="qaid-q-progress-fill",this.progressEl.appendChild(this.progressFillEl);const m=n||c;if(m){const o=document.createElement("div");o.className="qaid-q-header";const u=document.createElement("div");n&&(this.titleEl=document.createElement("h2"),this.titleEl.className="qaid-q-title",this.titleEl.textContent=this.questionnaire.title,u.appendChild(this.titleEl));const d=document.createElement("div");if(d.style.display="flex",d.style.alignItems="center",d.style.gap="0.5rem",i||(d.appendChild(this.savingEl),e||d.appendChild(this.stepCounterEl)),r){const f=document.createElement("button");f.type="button",f.className="qaid-q-close",f.setAttribute("aria-label","Close form"),f.innerHTML=de,f.addEventListener("click",()=>this.close()),d.appendChild(f)}o.appendChild(u),o.appendChild(d),this.cardEl.appendChild(o)}if(!this.isUserContainer&&this.cardEl&&(this.titleEl?(this.titleEl.id=this.titleEl.id||"qaid-q-dialog-title",this.cardEl.setAttribute("aria-labelledby",this.titleEl.id),this.cardEl.removeAttribute("aria-label")):(this.cardEl.removeAttribute("aria-labelledby"),this.cardEl.setAttribute("aria-label",this.questionnaire.title??"Questionnaire"))),s){const o=document.createElement("p");o.className="qaid-q-description",o.textContent=this.questionnaire.description,o.style.marginTop=m?"-0.5rem":"0",o.style.marginBottom="0.75rem",this.cardEl.appendChild(o)}!i&&!e&&this.cardEl.appendChild(this.progressEl),this.bodyEl=document.createElement("div"),this.bodyEl.className="qaid-q-body",this.cardEl.appendChild(this.bodyEl),this.footerEl=document.createElement("div"),this.footerEl.className="qaid-q-footer",this.cardEl.appendChild(this.footerEl)}renderStep(){if(!this.questionnaire||!this.bodyEl||!this.footerEl)return;const e=this.visibleQuestions.length;if(e===0){this.submit();return}this.stepIndex>=e&&(this.stepIndex=e-1);const i=this.stepIndex,a=this.visibleQuestions[i];if(this.stepCounterEl&&(this.stepCounterEl.textContent=`${i+1} / ${e}`),this.progressFillEl){const h=(i+1)/e*100;this.progressFillEl.style.width=`${h}%`}this.progressEl&&(this.progressEl.setAttribute("role","progressbar"),this.progressEl.setAttribute("aria-label","Progress"),this.progressEl.setAttribute("aria-valuemin","0"),this.progressEl.setAttribute("aria-valuemax",String(e)),this.progressEl.setAttribute("aria-valuenow",String(i+1)),this.progressEl.setAttribute("aria-valuetext",`Question ${i+1} of ${e}`)),this.shadowRoot&&e>1&&E(this.shadowRoot,`Step ${i+1} of ${e}`);const n=document.createElement("div");n.className="qaid-q-step",n.setAttribute("role","group"),n.setAttribute("aria-labelledby",`qaid-q-label-${i}`);const s=document.createElement("label");if(s.id=`qaid-q-label-${i}`,s.className="qaid-q-label",s.textContent=a.label,a.required){const h=document.createElement("span");h.className="qaid-q-required",h.textContent="*",h.setAttribute("aria-label","required"),s.appendChild(h)}if(n.appendChild(s),a.description){const h=document.createElement("p");h.className="qaid-q-description",h.textContent=a.description,n.appendChild(h)}const r=document.createElement("p");r.className="qaid-q-error",r.id=`qaid-q-error-${i}`,r.setAttribute("aria-live","polite");const c=this.answers[a.id]??null,q=i===e-1,p=$({question:a,initialValue:c,onChange:h=>{this.handleAnswerChange(a,h),r.textContent&&(r.textContent="",this.currentInput?.clearInvalid())},onSubmit:()=>this.advance(a,r),onAutoAdvance:()=>this.advance(a,r),autoAdvance:this.config.autoAdvance});this.currentInput=p,n.appendChild(p.element),n.appendChild(r),this.bodyEl.replaceChildren(n),this.footerEl.replaceChildren();const o=!(!!this.questionnaire.hideProgress||this.questionnaire.questions.length<=1)&&this.effectiveProgressPosition()==="bottom",u=i>0?(()=>{const h=document.createElement("button");return h.type="button",h.className="qaid-q-btn qaid-q-btn-secondary",h.textContent=this.questionnaire.backLabel??"Back",h.addEventListener("click",()=>this.back()),h})():null,d=document.createElement("button");if(d.type="button",d.className="qaid-q-btn qaid-q-btn-primary",d.textContent=q?this.questionnaire.submitLabel??"Submit":this.questionnaire.nextLabel??"Next",d.addEventListener("click",()=>this.advance(a,r)),o)this.footerEl.classList.add("qaid-q-footer--inline-progress"),u&&this.footerEl.appendChild(u),this.progressEl&&this.footerEl.appendChild(this.progressEl),this.savingEl&&this.footerEl.appendChild(this.savingEl),this.stepCounterEl&&this.footerEl.appendChild(this.stepCounterEl),this.footerEl.appendChild(d);else{this.footerEl.classList.remove("qaid-q-footer--inline-progress");const h=document.createElement("div");h.className="qaid-q-footer-left";const l=document.createElement("div");l.className="qaid-q-footer-right",u&&h.appendChild(u),l.appendChild(d),this.footerEl.appendChild(h),this.footerEl.appendChild(l)}const f=!this.hasRenderedStep;this.hasRenderedStep=!0,(!f||this.config.autoFocus)&&requestAnimationFrame(()=>p.focus())}renderDone(){if(!this.cardEl||!this.questionnaire)return;this.cardEl.replaceChildren();const e=document.createElement("div");e.className="qaid-q-done";const i=document.createElement("div");i.className="qaid-q-done-icon",i.innerHTML=le,e.appendChild(i);const a=document.createElement("h3");a.className="qaid-q-done-title";const n=this.questionnaire.thankYouTitle??"Thank you!";if(a.textContent=n,a.setAttribute("tabindex","-1"),e.appendChild(a),this.questionnaire.thankYouMessage){const s=document.createElement("p");s.className="qaid-q-done-message",s.textContent=this.questionnaire.thankYouMessage,e.appendChild(s)}if(!this.isUserContainer){const s=document.createElement("button");s.type="button",s.className="qaid-q-btn qaid-q-btn-primary",s.textContent="Close",s.style.marginTop="1rem",s.addEventListener("click",()=>this.close()),e.appendChild(s)}if(this.cardEl.appendChild(e),requestAnimationFrame(()=>a.focus()),this.shadowRoot){const s=this.questionnaire.thankYouMessage?`${n}. ${this.questionnaire.thankYouMessage}`:n;E(this.shadowRoot,s)}}advance(e,i){if(!this.currentInput||!this.questionnaire)return;if(!this.currentInput.isValid()){i.textContent=ce(e),this.currentInput.setInvalid(i.id),this.currentInput.focus();return}if(this.handleAnswerChange(e,this.currentInput.getValue(),{immediate:!0}),this.stepIndex===this.visibleQuestions.length-1){this.submit();return}this.stepIndex++,this.renderStep()}back(){this.flushPendingSave(),this.stepIndex>0&&(this.stepIndex--,this.recomputeVisible(),this.stepIndex>=this.visibleQuestions.length&&(this.stepIndex=Math.max(0,this.visibleQuestions.length-1)),this.renderStep())}recomputeVisible(){this.questionnaire&&(this.visibleQuestions=C(this.questionnaire,this.answers))}handleAnswerChange(e,i,a={}){this.answers[e.id]=i,this.recomputeVisible();const n=e.type==="text"||e.type==="currency"||e.type==="range";if(a.immediate||!n){this.flushPendingSave(),this.saveAnswer(e.id,i);return}this.pendingSaveQuestionId=e.id,this.pendingSaveValue=i,this.pendingSaveTimer&&clearTimeout(this.pendingSaveTimer),this.pendingSaveTimer=setTimeout(()=>{this.flushPendingSave()},this.config.saveDebounceMs)}flushPendingSave(){if(this.pendingSaveTimer&&(clearTimeout(this.pendingSaveTimer),this.pendingSaveTimer=null),this.pendingSaveQuestionId!==null){const e=this.pendingSaveQuestionId,i=this.pendingSaveValue;this.pendingSaveQuestionId=null,this.pendingSaveValue=null,this.saveAnswer(e,i)}}saveAnswer(e,i){this.showSaving(!0),this.inflightSaves++,this.doSave(e,i).finally(()=>{this.inflightSaves--,this.inflightSaves===0&&this.showSaving(!1)})}async doSave(e,i){let a=0;for(;this.responseId===null&&a<5e3;)await new Promise(n=>setTimeout(n,50)),a+=50;if(this.responseId!==null)try{await fetch(`${this.config.endpoint}/${this.responseId}`,{method:"PATCH",headers:this.jsonHeaders(),body:JSON.stringify({questionId:e,value:i})})}catch(n){console.error("[quests-embed] failed to save answer:",n)}}async createResponse(){try{const e=await fetch(this.config.endpoint,{method:"POST",headers:this.jsonHeaders(),body:JSON.stringify({apiKey:this.config.apiKey||void 0,questId:this.questionnaire?.id,pageUrl:window.location.href,visitorId:this.visitorId,userAgent:navigator.userAgent})});if(e.ok){const i=await e.json();this.responseId=i.id}}catch(e){console.error("[quests-embed] failed to create response:",e)}}async submit(){for(this.flushPendingSave();this.inflightSaves>0;)await new Promise(e=>setTimeout(e,50));if(this.responseId!==null)try{await fetch(`${this.config.endpoint}/${this.responseId}/submit`,{method:"POST",headers:this.jsonHeaders(),body:JSON.stringify({answers:this.answers})})}catch(e){console.error("[quests-embed] failed to submit:",e)}this.state="DONE",this.renderDone()}jsonHeaders(){const e={"Content-Type":"application/json",Accept:"application/json"};return this.config.apiKey&&(e["X-API-Key"]=this.config.apiKey),e}showSaving(e){this.savingEl&&this.savingEl.classList.toggle("qaid-q-visible",e)}handleKeyDown(e){e.key==="Escape"&&!this.isUserContainer&&this.state!=="DONE"&&this.close()}setupModalA11y(){this.isUserContainer||!this.cardEl||this.focusTrap||(this.focusTrap=te(this.cardEl),this.inertRestore=se(this.cardEl))}close(){this.flushPendingSave(),this.destroy()}destroy(){document.removeEventListener("keydown",this.boundKeyDown),this.pendingSaveTimer&&(clearTimeout(this.pendingSaveTimer),this.pendingSaveTimer=null),this.focusTrap&&(this.focusTrap.release(),this.focusTrap=null),this.inertRestore&&(this.inertRestore(),this.inertRestore=null),!this.isUserContainer&&this.savedOpener&&ae(this.savedOpener),this.savedOpener=null,this.shadowHost&&(this.shadowHost.remove(),this.shadowHost=null,this.shadowRoot=null),this.rootEl=null,this.cardEl=null,this.bodyEl=null,this.footerEl=null,this.titleEl=null,this.stepCounterEl=null,this.progressFillEl=null,this.savingEl=null,this.backdropEl=null,this.currentInput=null}getAnswers(){return{...this.answers}}getCurrentQuestionId(){if(this.state!=="READY")return null;const e=this.visibleQuestions[this.stepIndex];return e?e.id:null}goToStep(e){if(this.state!=="READY"||!this.questionnaire)return this.pendingGoToStep=e,!1;const i=this.visibleQuestions.findIndex(a=>a.id===e);return i===-1?!1:(i===this.stepIndex||(this.flushPendingSave(),this.stepIndex=i,this.renderStep()),!0)}}function ce(t){switch(t.type){case"text":return t.minLength?`Please enter at least ${t.minLength} characters.`:"This field is required.";case"currency":return"Please enter a valid amount.";case"date":return"Please pick a date.";case"multiple-choice":return t.multiple?"Please select at least one option.":"Please select an option.";case"range":return"Please choose a value."}}function L(t){return document.querySelector(t)?.textContent?.trim()??""}function ue(){const t=document.querySelector('script[type="application/json"][data-quests-config]');if(!t)return null;const e=t.textContent?.trim();if(!e)return null;try{const i=JSON.parse(e);return i.cssSelector&&!i.css&&(i.css=L(i.cssSelector),delete i.cssSelector),i}catch{return null}}function he(t){const e=t.getAttribute("data-endpoint");if(!e)return null;const i=t.getAttribute("data-config-url"),a=t.getAttribute("data-api-key"),n=t.getAttribute("data-container"),s=t.getAttribute("data-zindex"),r=t.getAttribute("data-positive-color"),c=t.getAttribute("data-negative-color"),q=t.getAttribute("data-marker-color"),p=t.getAttribute("data-modal-width"),m=t.getAttribute("data-backdrop-opacity"),o=t.getAttribute("data-font-family"),u=t.getAttribute("data-font-size"),d=t.getAttribute("data-css-selector"),f=t.getAttribute("data-auto-advance"),g=t.getAttribute("data-save-debounce-ms"),h=t.getAttribute("data-theme-url"),l=t.getAttribute("data-preset"),z=t.getAttribute("data-theme"),qe=t.getAttribute("data-unstyled");return{endpoint:e,configUrl:i??void 0,apiKey:a??void 0,container:n??void 0,zIndex:s?parseInt(s,10):void 0,colors:{positive:r??void 0,negative:c??void 0,marker:q??void 0},modalWidth:p?parseInt(p,10):void 0,backdropOpacity:m?parseFloat(m):void 0,fontFamily:o??void 0,fontSize:u?parseInt(u,10):void 0,css:d?L(d):void 0,autoAdvance:f==="true"?!0:void 0,saveDebounceMs:g?parseInt(g,10):void 0,themeUrl:h??void 0,preset:l||void 0,theme:z||void 0,unstyled:qe==="true"?!0:void 0}}if(typeof document<"u"){const t=()=>{const e=document.currentScript,i=ue(),a=e?he(e):null,n=i??a;n?.endpoint&&(n.configUrl||n.questionnaire)&&new T(n)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t):t()}b.QaidQuests=T,b.evaluateRule=x,b.getVisibleQuestions=C,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
6
+ `),this.shadowRoot.appendChild(r)}}async loadQuestionnaire(){if(this.inlineQuestionnaire)return this.inlineQuestionnaire;if(!this.configUrl)throw new Error("No questionnaire or configUrl provided");const e=await fetch(this.configUrl,{headers:{Accept:"application/json"}});if(!e.ok)throw new Error(`Failed to load questionnaire (${e.status})`);return await e.json()}mountShell(){this.shadowHost=document.createElement("div"),this.shadowHost.setAttribute("data-qaid-quests","");const e=this.config.container?document.querySelector(this.config.container):null;e?(this.shadowHost.style.display="block",this.shadowHost.style.height="100%",this.shadowHost.style.minHeight="0",e.appendChild(this.shadowHost),this.isUserContainer=!0):(this.savedOpener=de(),this.shadowHost.style.position="fixed",this.shadowHost.style.inset="0",this.shadowHost.style.zIndex=String(this.config.zIndex),this.shadowHost.style.pointerEvents="none",document.body.appendChild(this.shadowHost)),this.shadowRoot=this.shadowHost.attachShadow({mode:"open"});const i=document.createElement("style");if(i.textContent=U(),this.shadowRoot.appendChild(i),this.rootEl=document.createElement("div"),this.rootEl.className=["qaid-q-root",this.isUserContainer?"qaid-q-inline":"",this.config.animate?"":"qaid-q-no-motion"].filter(Boolean).join(" "),j(this.rootEl,this.cssVars),this.isUserContainer)this.cardEl=document.createElement("div"),this.cardEl.className="qaid-q-card",this.rootEl.appendChild(this.cardEl);else{this.backdropEl=document.createElement("div"),this.backdropEl.className="qaid-q-backdrop",this.backdropEl.addEventListener("click",()=>this.close()),this.rootEl.appendChild(this.backdropEl);const a=document.createElement("div");a.className="qaid-q-modal",this.cardEl=document.createElement("div"),this.cardEl.className="qaid-q-card",a.appendChild(this.cardEl),this.rootEl.appendChild(a)}this.shadowRoot.appendChild(this.rootEl),!this.isUserContainer&&this.shadowHost&&(this.shadowHost.style.pointerEvents="auto"),!this.isUserContainer&&this.cardEl&&ce(this.cardEl),document.addEventListener("keydown",this.boundKeyDown)}renderLoading(){if(!this.cardEl)return;this.cardEl.replaceChildren();const e=document.createElement("p");e.className="qaid-q-description",e.textContent="Loading…",this.cardEl.appendChild(e),this.shadowRoot&&E(this.shadowRoot,"Loading")}renderError(e){if(!this.cardEl)return;this.cardEl.replaceChildren();const i=document.createElement("h3");i.className="qaid-q-title",i.textContent="Couldn't load form";const a=e instanceof Error?e.message:String(e),n=document.createElement("p");n.className="qaid-q-description",n.textContent=a,this.cardEl.appendChild(i),this.cardEl.appendChild(n),this.shadowRoot&&E(this.shadowRoot,`Couldn't load form. ${a}`,{assertive:!0})}effectiveProgressPosition(){return this.config.progressPosition??this.questionnaire?.progressPosition??"top"}renderHeader(){if(!this.cardEl||!this.questionnaire)return;this.cardEl.replaceChildren();const e=!!this.questionnaire.hideProgress||this.questionnaire.questions.length<=1,i=!e&&this.effectiveProgressPosition()==="bottom",a=!!this.questionnaire.hideTitle,n=!!this.questionnaire.title&&!a,o=!!this.questionnaire.description&&!a,r=!this.isUserContainer,c=r||!i&&!e;this.savingEl=document.createElement("div"),this.savingEl.className="qaid-q-saving";const q=document.createElement("span");q.className="qaid-q-saving-dot";const p=document.createElement("span");p.textContent="Saving…",this.savingEl.appendChild(q),this.savingEl.appendChild(p),this.stepCounterEl=document.createElement("div"),this.stepCounterEl.className="qaid-q-step-counter",this.progressEl=document.createElement("div"),this.progressEl.className=i?"qaid-q-progress qaid-q-progress--inline":"qaid-q-progress",this.progressFillEl=document.createElement("div"),this.progressFillEl.className="qaid-q-progress-fill",this.progressEl.appendChild(this.progressFillEl);const f=n||c;if(f){const s=document.createElement("div");s.className="qaid-q-header";const u=document.createElement("div");n&&(this.titleEl=document.createElement("h2"),this.titleEl.className="qaid-q-title",this.titleEl.textContent=this.questionnaire.title,u.appendChild(this.titleEl));const d=document.createElement("div");if(d.style.display="flex",d.style.alignItems="center",d.style.gap="0.5rem",i||(d.appendChild(this.savingEl),e||d.appendChild(this.stepCounterEl)),r){const m=document.createElement("button");m.type="button",m.className="qaid-q-close",m.setAttribute("aria-label","Close form"),m.innerHTML=pe,m.addEventListener("click",()=>this.close()),d.appendChild(m)}s.appendChild(u),s.appendChild(d),this.cardEl.appendChild(s)}if(!this.isUserContainer&&this.cardEl&&(this.titleEl?(this.titleEl.id=this.titleEl.id||"qaid-q-dialog-title",this.cardEl.setAttribute("aria-labelledby",this.titleEl.id),this.cardEl.removeAttribute("aria-label")):(this.cardEl.removeAttribute("aria-labelledby"),this.cardEl.setAttribute("aria-label",this.questionnaire.title??"Questionnaire"))),o){const s=document.createElement("p");s.className="qaid-q-description",s.textContent=this.questionnaire.description,s.style.marginTop=f?"-0.5rem":"0",s.style.marginBottom="0.75rem",this.cardEl.appendChild(s)}!i&&!e&&this.cardEl.appendChild(this.progressEl),this.bodyEl=document.createElement("div"),this.bodyEl.className="qaid-q-body",this.cardEl.appendChild(this.bodyEl),this.footerEl=document.createElement("div"),this.footerEl.className="qaid-q-footer",this.cardEl.appendChild(this.footerEl),this.scrollCueEl=document.createElement("div"),this.scrollCueEl.className="qaid-q-scroll-cue",this.scrollCueEl.setAttribute("aria-hidden","true"),this.scrollCueEl.hidden=!0,this.scrollCueEl.innerHTML='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>',this.bodyEl.appendChild(this.scrollCueEl),this.overflow=ee(this.bodyEl,this.cardEl,this.scrollCueEl)}renderStep(){if(!this.questionnaire||!this.bodyEl||!this.footerEl)return;const e=this.visibleQuestions.length;if(e===0){this.submit();return}this.stepIndex>=e&&(this.stepIndex=e-1);const i=this.stepIndex,a=this.visibleQuestions[i];if(this.stepCounterEl&&(this.stepCounterEl.textContent=`${i+1} / ${e}`),this.progressFillEl){const h=(i+1)/e*100;this.progressFillEl.style.width=`${h}%`}this.progressEl&&(this.progressEl.setAttribute("role","progressbar"),this.progressEl.setAttribute("aria-label","Progress"),this.progressEl.setAttribute("aria-valuemin","0"),this.progressEl.setAttribute("aria-valuemax",String(e)),this.progressEl.setAttribute("aria-valuenow",String(i+1)),this.progressEl.setAttribute("aria-valuetext",`Question ${i+1} of ${e}`)),this.shadowRoot&&e>1&&E(this.shadowRoot,`Step ${i+1} of ${e}`);const n=document.createElement("div");n.className="qaid-q-step",n.setAttribute("role","group"),n.setAttribute("aria-labelledby",`qaid-q-label-${i}`);const o=document.createElement("label");if(o.id=`qaid-q-label-${i}`,o.className="qaid-q-label",o.textContent=a.label,a.required){const h=document.createElement("span");h.className="qaid-q-required",h.textContent="*",h.setAttribute("aria-label","required"),o.appendChild(h)}if(n.appendChild(o),a.description){const h=document.createElement("p");h.className="qaid-q-description",h.textContent=a.description,n.appendChild(h)}const r=document.createElement("p");r.className="qaid-q-error",r.id=`qaid-q-error-${i}`,r.setAttribute("aria-live","polite");const c=this.answers[a.id]??null,q=i===e-1,p=F({question:a,initialValue:c,onChange:h=>{this.handleAnswerChange(a,h),r.textContent&&(r.textContent="",this.currentInput?.clearInvalid())},onSubmit:()=>this.advance(a,r),onAutoAdvance:()=>this.advance(a,r),autoAdvance:this.config.autoAdvance});this.currentInput=p,n.appendChild(p.element),n.appendChild(r),this.bodyEl.replaceChildren(n),this.scrollCueEl&&this.bodyEl.appendChild(this.scrollCueEl),this.bodyEl.scrollTop=0,this.overflow?.refresh(),this.footerEl.replaceChildren();const s=!(!!this.questionnaire.hideProgress||this.questionnaire.questions.length<=1)&&this.effectiveProgressPosition()==="bottom",u=i>0?(()=>{const h=document.createElement("button");return h.type="button",h.className="qaid-q-btn qaid-q-btn-secondary",h.textContent=this.questionnaire.backLabel??"Back",h.addEventListener("click",()=>this.back()),h})():null,d=document.createElement("button");if(d.type="button",d.className="qaid-q-btn qaid-q-btn-primary",d.textContent=q?this.questionnaire.submitLabel??"Submit":this.questionnaire.nextLabel??"Next",d.addEventListener("click",()=>this.advance(a,r)),s)this.footerEl.classList.add("qaid-q-footer--inline-progress"),u&&this.footerEl.appendChild(u),this.progressEl&&this.footerEl.appendChild(this.progressEl),this.savingEl&&this.footerEl.appendChild(this.savingEl),this.stepCounterEl&&this.footerEl.appendChild(this.stepCounterEl),this.footerEl.appendChild(d);else{this.footerEl.classList.remove("qaid-q-footer--inline-progress");const h=document.createElement("div");h.className="qaid-q-footer-left";const l=document.createElement("div");l.className="qaid-q-footer-right",u&&h.appendChild(u),l.appendChild(d),this.footerEl.appendChild(h),this.footerEl.appendChild(l)}const m=!this.hasRenderedStep;this.hasRenderedStep=!0,(!m||this.config.autoFocus)&&requestAnimationFrame(()=>p.focus())}renderDone(){if(!this.cardEl||!this.questionnaire)return;this.cardEl.replaceChildren();const e=document.createElement("div");e.className="qaid-q-done";const i=document.createElement("div");i.className="qaid-q-done-icon",i.innerHTML=me,e.appendChild(i);const a=document.createElement("h3");a.className="qaid-q-done-title";const n=this.questionnaire.thankYouTitle??"Thank you!";if(a.textContent=n,a.setAttribute("tabindex","-1"),e.appendChild(a),this.questionnaire.thankYouMessage){const o=document.createElement("p");o.className="qaid-q-done-message",o.textContent=this.questionnaire.thankYouMessage,e.appendChild(o)}if(!this.isUserContainer){const o=document.createElement("button");o.type="button",o.className="qaid-q-btn qaid-q-btn-primary",o.textContent="Close",o.style.marginTop="1rem",o.addEventListener("click",()=>this.close()),e.appendChild(o)}if(this.cardEl.appendChild(e),requestAnimationFrame(()=>a.focus()),this.shadowRoot){const o=this.questionnaire.thankYouMessage?`${n}. ${this.questionnaire.thankYouMessage}`:n;E(this.shadowRoot,o)}}advance(e,i){if(!this.currentInput||!this.questionnaire)return;if(!this.currentInput.isValid()){i.textContent=fe(e),this.currentInput.setInvalid(i.id),this.currentInput.focus();return}if(this.handleAnswerChange(e,this.currentInput.getValue(),{immediate:!0}),this.stepIndex===this.visibleQuestions.length-1){this.submit();return}this.stepIndex++,this.renderStep()}back(){this.flushPendingSave(),this.stepIndex>0&&(this.stepIndex--,this.recomputeVisible(),this.stepIndex>=this.visibleQuestions.length&&(this.stepIndex=Math.max(0,this.visibleQuestions.length-1)),this.renderStep())}recomputeVisible(){this.questionnaire&&(this.visibleQuestions=A(this.questionnaire,this.answers))}handleAnswerChange(e,i,a={}){this.answers[e.id]=i,this.recomputeVisible();const n=e.type==="text"||e.type==="currency"||e.type==="range";if(a.immediate||!n){this.flushPendingSave(),this.saveAnswer(e.id,i);return}this.pendingSaveQuestionId=e.id,this.pendingSaveValue=i,this.pendingSaveTimer&&clearTimeout(this.pendingSaveTimer),this.pendingSaveTimer=setTimeout(()=>{this.flushPendingSave()},this.config.saveDebounceMs)}flushPendingSave(){if(this.pendingSaveTimer&&(clearTimeout(this.pendingSaveTimer),this.pendingSaveTimer=null),this.pendingSaveQuestionId!==null){const e=this.pendingSaveQuestionId,i=this.pendingSaveValue;this.pendingSaveQuestionId=null,this.pendingSaveValue=null,this.saveAnswer(e,i)}}saveAnswer(e,i){this.showSaving(!0),this.inflightSaves++,this.doSave(e,i).finally(()=>{this.inflightSaves--,this.inflightSaves===0&&this.showSaving(!1)})}async doSave(e,i){let a=0;for(;this.responseId===null&&a<5e3;)await new Promise(n=>setTimeout(n,50)),a+=50;if(this.responseId!==null)try{await fetch(`${this.config.endpoint}/${this.responseId}`,{method:"PATCH",headers:this.jsonHeaders(),body:JSON.stringify({questionId:e,value:i})})}catch(n){console.error("[quests-embed] failed to save answer:",n)}}async createResponse(){try{const e=await fetch(this.config.endpoint,{method:"POST",headers:this.jsonHeaders(),body:JSON.stringify({apiKey:this.config.apiKey||void 0,questId:this.questionnaire?.id,pageUrl:window.location.href,visitorId:this.visitorId,userAgent:navigator.userAgent,metadata:this.metadata})});if(e.ok){const i=await e.json();this.responseId=i.id}}catch(e){console.error("[quests-embed] failed to create response:",e)}}async submit(){for(this.flushPendingSave();this.inflightSaves>0;)await new Promise(e=>setTimeout(e,50));if(this.responseId!==null)try{await fetch(`${this.config.endpoint}/${this.responseId}/submit`,{method:"POST",headers:this.jsonHeaders(),body:JSON.stringify({answers:this.answers})})}catch(e){console.error("[quests-embed] failed to submit:",e)}if(this.state="DONE",this.renderDone(),this.onCompleteCb)try{this.onCompleteCb({...this.answers})}catch(e){console.error("[quests-embed] onComplete handler threw:",e)}}jsonHeaders(){const e={"Content-Type":"application/json",Accept:"application/json"};return this.config.apiKey&&(e["X-API-Key"]=this.config.apiKey),e}showSaving(e){this.savingEl&&this.savingEl.classList.toggle("qaid-q-visible",e)}handleKeyDown(e){e.key==="Escape"&&!this.isUserContainer&&this.state!=="DONE"&&this.close()}setupModalA11y(){this.isUserContainer||!this.cardEl||this.focusTrap||(this.focusTrap=se(this.cardEl),this.inertRestore=he(this.cardEl))}close(){this.flushPendingSave(),this.destroy()}destroy(){if(document.removeEventListener("keydown",this.boundKeyDown),this.pendingSaveTimer&&(clearTimeout(this.pendingSaveTimer),this.pendingSaveTimer=null),this.focusTrap&&(this.focusTrap.release(),this.focusTrap=null),this.inertRestore&&(this.inertRestore(),this.inertRestore=null),!this.isUserContainer&&this.savedOpener&&le(this.savedOpener),this.savedOpener=null,this.shadowHost&&(this.shadowHost.remove(),this.shadowHost=null,this.shadowRoot=null),this.rootEl=null,this.cardEl=null,this.overflow?.destroy(),this.overflow=null,this.bodyEl=null,this.scrollCueEl=null,this.footerEl=null,this.titleEl=null,this.stepCounterEl=null,this.progressFillEl=null,this.savingEl=null,this.backdropEl=null,this.currentInput=null,!this.closed&&(this.closed=!0,this.onCloseCb))try{this.onCloseCb()}catch(e){console.error("[quests-embed] onClose handler threw:",e)}}getAnswers(){return{...this.answers}}getCurrentQuestionId(){if(this.state!=="READY")return null;const e=this.visibleQuestions[this.stepIndex];return e?e.id:null}goToStep(e){if(this.state!=="READY"||!this.questionnaire)return this.pendingGoToStep=e,!1;const i=this.visibleQuestions.findIndex(a=>a.id===e);return i===-1?!1:(i===this.stepIndex||(this.flushPendingSave(),this.stepIndex=i,this.renderStep()),!0)}}function fe(t){switch(t.type){case"text":return t.minLength?`Please enter at least ${t.minLength} characters.`:"This field is required.";case"currency":return"Please enter a valid amount.";case"date":return"Please pick a date.";case"multiple-choice":return t.multiple?"Please select at least one option.":"Please select an option.";case"range":return"Please choose a value."}}function z(t){return document.querySelector(t)?.textContent?.trim()??""}function ge(){const t=document.querySelector('script[type="application/json"][data-quests-config]');if(!t)return null;const e=t.textContent?.trim();if(!e)return null;try{const i=JSON.parse(e);return i.cssSelector&&!i.css&&(i.css=z(i.cssSelector),delete i.cssSelector),i}catch{return null}}function be(t){const e=t.getAttribute("data-endpoint");if(!e)return null;const i=t.getAttribute("data-config-url"),a=t.getAttribute("data-api-key"),n=t.getAttribute("data-container"),o=t.getAttribute("data-zindex"),r=t.getAttribute("data-positive-color"),c=t.getAttribute("data-negative-color"),q=t.getAttribute("data-marker-color"),p=t.getAttribute("data-modal-width"),f=t.getAttribute("data-backdrop-opacity"),s=t.getAttribute("data-font-family"),u=t.getAttribute("data-font-size"),d=t.getAttribute("data-css-selector"),m=t.getAttribute("data-auto-advance"),g=t.getAttribute("data-save-debounce-ms"),h=t.getAttribute("data-theme-url"),l=t.getAttribute("data-preset"),H=t.getAttribute("data-theme"),ve=t.getAttribute("data-unstyled");return{endpoint:e,configUrl:i??void 0,apiKey:a??void 0,container:n??void 0,zIndex:o?parseInt(o,10):void 0,colors:{positive:r??void 0,negative:c??void 0,marker:q??void 0},modalWidth:p?parseInt(p,10):void 0,backdropOpacity:f?parseFloat(f):void 0,fontFamily:s??void 0,fontSize:u?parseInt(u,10):void 0,css:d?z(d):void 0,autoAdvance:m==="true"?!0:void 0,saveDebounceMs:g?parseInt(g,10):void 0,themeUrl:h??void 0,preset:l||void 0,theme:H||void 0,unstyled:ve==="true"?!0:void 0}}if(typeof document<"u"){const t=()=>{const e=document.currentScript,i=ge(),a=e?be(e):null,n=i??a;n?.endpoint&&(n.configUrl||n.questionnaire)&&new L(n)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t):t()}b.QaidQuests=L,b.evaluateRule=x,b.getVisibleQuestions=A,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
7
7
  //# sourceMappingURL=qaid-quests.umd.cjs.map