@inputbuffer/feedback 0.1.1 → 0.2.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.
package/README.md CHANGED
@@ -236,8 +236,14 @@ Supported attributes:
236
236
  | `theme-selected` | Background color of the selected thumb. |
237
237
  | `theme-selected-color` | Icon color of the selected thumb. |
238
238
  | `inject-styles` | Set to `"false"` to skip automatic style injection. |
239
-
240
- > **Note:** `colorScheme`, `showLabel`, `modalTitle`, `modalPlaceholder`, `showTitleField`, `showEmailField`, and `source` are not available as web component attributes. Use `InputBufferIO.createBar(config)` for those options.
239
+ | `color-scheme` | `"light"`, `"dark"`, or `"auto"`. |
240
+ | `show-label` | `"true"` to show the label, `"false"` to hide it. |
241
+ | `modal-title` | Title shown above the feedback textarea. |
242
+ | `modal-placeholder` | Placeholder text for the feedback textarea. |
243
+ | `show-title-field` | `"true"` to show an optional title input. |
244
+ | `show-email-field` | `"true"` to show an optional email input. |
245
+ | `source` | Identifier for the feedback source. |
246
+ | `user-id` | Stable user identifier for reaction deduplication. When set, only one reaction per user is recorded per target (all-time). When omitted, deduplication falls back to IP address with a 24-hour window. |
241
247
 
242
248
  ### `InputBufferIO.createBar(config)`
243
249
 
@@ -275,6 +281,7 @@ document.getElementById('my-slot').appendChild(bar.element);
275
281
  | `showEmailField` | boolean | `false` | Show/hide the email field in the follow-up popover. |
276
282
  | `showTitleField` | boolean | `false` | Show/hide the title field in the follow-up popover. |
277
283
  | `source` | string | — | Tag identifying which of your surfaces this widget is embedded on (e.g. `"ios-app"`, `"docs-site"`). Stored on every submission for filtering in the dashboard. |
284
+ | `userId` | string | — | Stable user identifier for reaction deduplication. When set, only one reaction per user is recorded per target (all-time). When omitted, deduplication falls back to IP address with a 24-hour window. |
278
285
  | `injectStyles` | boolean | `true` | Set to `false` to skip automatic style injection. |
279
286
 
280
287
  ### `bar.on(event, handler)`
@@ -291,7 +298,7 @@ bar.on('error', (err) => console.error('Submission failed:', err));
291
298
 
292
299
  | Event | Handler signature | When it fires |
293
300
  |---|---|---|
294
- | `vote` | `({ sentiment: 'positive' \| 'negative' }) => void` | User clicks a thumb before submitting. |
301
+ | `vote` | `({ sentiment: 'positive' \| 'negative' }) => void` | User clicks a thumb. The reaction is recorded immediately via the reactions API (if a `target` is configured), and the selection is persisted in `localStorage` for 24 hours so it survives page reloads. |
295
302
  | `open` | `({ sentiment: 'positive' \| 'negative' }) => void` | The follow-up popover opens. |
296
303
  | `submit` | `({ id: string }) => void` | Feedback was submitted successfully. |
297
304
  | `close` | `() => void` | The follow-up popover closes. |
@@ -631,6 +638,27 @@ document.getElementById('my-slot').appendChild(bar.element);
631
638
  </script>
632
639
  ```
633
640
 
641
+ ## `source` vs `target`
642
+
643
+ These are two separate concepts:
644
+
645
+ - **`source`** — *where* your widget is deployed. Identifies the platform or product surface,
646
+ e.g. `"website"`, `"ios-app"`, `"chrome-extension"`. Use this to filter feedback by deployment
647
+ environment in your dashboard.
648
+
649
+ - **`target`** — *what* the feedback is about. A structured object describing the specific content
650
+ or feature, e.g. a REST endpoint, a docs page, or a CLI command. Use this to group feedback by
651
+ the thing being reviewed, regardless of where the widget is embedded.
652
+
653
+ You can use both together:
654
+ ```js
655
+ InputBufferIO.createBar({
656
+ apiKey: 'YOUR_WIDGET_TOKEN',
657
+ source: 'website',
658
+ target: { type: 'documentation', metadata: { page_slug: 'getting-started' } },
659
+ });
660
+
661
+
634
662
  ---
635
663
 
636
664
  ## License
package/dist/api.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { OpenOptions } from './types.js';
1
+ import type { OpenOptions, TargetSpec } from './types.js';
2
2
  export declare const WIDGET_VERSION: string;
3
3
  export declare function submitFeedback(apiKey: string, description: string, email: string | null, title: string | null, options?: OpenOptions, apiUrl?: string): Promise<{
4
4
  id: string;
5
5
  }>;
6
+ export declare function submitReaction(apiKey: string, reactionValue: 1 | -1, target: TargetSpec, userId?: string | null, apiUrl?: string): Promise<void>;
package/dist/bar.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- var S="0.1.1",U="https://inputbuffer.io/api/v0/inputs";async function M(t,o,b,s,r,h){var p;let a={description:o};if(s&&(a.title=s),b&&(a.contactEmail=b),r!=null&&r.sentiment&&(a.sentiment=r.sentiment),r!=null&&r.source&&(a.source=r.source),r!=null&&r.target){let i=r.target;a.targets=[{target_type:i.type,...i.targetId&&{target_id:i.targetId},...i.displayName&&{display_name:i.displayName},...i.dedupKey&&{dedup_key:i.dedupKey},metadata:i.metadata}]}let l=new AbortController,m=setTimeout(()=>l.abort(),1e4),c;try{c=await fetch(h!=null?h:U,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${S} (javascript)`},body:JSON.stringify(a),credentials:"omit",signal:l.signal})}finally{clearTimeout(m)}if(!c.ok){let i=await c.json().catch(()=>({}));throw new Error(((p=i==null?void 0:i.error)==null?void 0:p.message)||"Submission failed. Please try again.")}return c.json()}function R(t){let o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("width","18"),o.setAttribute("height","18"),o.setAttribute("fill","currentColor"),o.setAttribute("aria-hidden","true"),o.style.display="block";let b=document.createElementNS("http://www.w3.org/2000/svg","path");return b.setAttribute("d",t),o.appendChild(b),o}var $="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",q="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function _(t){var O,H;let o,b={vote:[],open:[],submit:[],close:[],error:[]};function s(e,g){var y;(y=b[e])==null||y.forEach(C=>C(g))}let r=document.createElement("div"),h=t.colorScheme==="dark"?" ib-theme-dark":t.colorScheme==="light"?" ib-theme-light":"";r.className="ib-bar-wrapper"+(t.placement==="fixed"?" ib-bar-wrapper--fixed":"")+h;let{theme:a={}}=t;a.primary&&r.style.setProperty("--ib-primary",a.primary),a.background&&r.style.setProperty("--ib-background",a.background),a.surface&&r.style.setProperty("--ib-surface",a.surface),a.text&&r.style.setProperty("--ib-text",a.text),a.selected&&r.style.setProperty("--ib-selected",a.selected),a.selectedColor&&r.style.setProperty("--ib-selected-color",a.selectedColor);let l=document.createElement("div");l.className="ib-bar";let m=document.createElement("div");m.className="ib-bar-label-area";let c=document.createElement("span");c.className="ib-bar-label",c.textContent=(O=t.label)!=null?O:"Was this helpful?",m.appendChild(c);let p=document.createElement("div");p.className="ib-bar-actions"+(t.showLabel===!1?" ib-bar-actions--no-label":"");let i=document.createElement("button");i.type="button",i.className="ib-bar-btn ib-bar-btn--up",i.setAttribute("aria-label","Yes"),i.appendChild(R($));let d=document.createElement("button");d.type="button",d.className="ib-bar-btn ib-bar-btn--down",d.setAttribute("aria-label","No"),d.appendChild(R(q)),p.appendChild(i),p.appendChild(d),t.showLabel!==!1&&l.appendChild(m),l.appendChild(p);let n=document.createElement("div");n.className="ib-bar-popover",n.setAttribute("role","dialog"),n.setAttribute("aria-modal","false");let N=document.createElement("div");if(N.className="ib-bar-header",t.modalTitle){n.setAttribute("aria-labelledby","ib-bar-title");let e=document.createElement("p");e.id="ib-bar-title",e.className="ib-bar-title",e.textContent=t.modalTitle,N.appendChild(e)}else n.setAttribute("aria-label","Feedback");let f=document.createElement("div");f.className="ib-bar-body";let v=document.createElement("textarea");v.className="ib-bar-textarea",v.placeholder=(H=t.modalPlaceholder)!=null?H:"What's on your mind?",v.setAttribute("aria-label","Feedback");let x=document.createElement("p");x.className="ib-bar-error";let B=document.createElement("p");B.className="ib-bar-success";let u=document.createElement("button");if(u.type="button",u.className="ib-bar-submit",u.textContent="Send feedback",t.showTitleField===!0){let e=document.createElement("input");e.type="text",e.className="ib-bar-title-input",e.placeholder="Title (optional)",e.setAttribute("aria-label","Feedback title"),f.appendChild(e)}if(f.appendChild(v),t.showEmailField===!0){let e=document.createElement("input");e.type="email",e.className="ib-bar-email",e.placeholder="Your email (optional)",e.setAttribute("aria-label","Email address"),f.appendChild(e)}f.appendChild(x),f.appendChild(B);let A=document.createElement("div");A.className="ib-bar-footer",A.appendChild(u);let I=document.createElement("div");I.className="ib-branding";let w=document.createElement("a");w.href="https://inputbuffer.io",w.target="_blank",w.rel="noopener noreferrer",w.textContent="Powered by inputbuffer.io",I.appendChild(w),A.appendChild(I),f.appendChild(A),n.appendChild(N),n.appendChild(f),r.appendChild(n),r.appendChild(l);function E(){let e=l.getBoundingClientRect();n.style.top=`${e.top-n.offsetHeight-8}px`,n.style.left=`${e.right-320}px`}function z(e){o=e,n.classList.add("ib-bar-popover--visible"),requestAnimationFrame(E),x.textContent="",B.textContent="",v.focus(),setTimeout(()=>document.addEventListener("click",T),0),document.addEventListener("keydown",P),window.addEventListener("scroll",E,{passive:!0}),window.addEventListener("resize",E,{passive:!0}),s("open",{sentiment:e})}function L(){n.classList.contains("ib-bar-popover--visible")&&(n.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",T),document.removeEventListener("keydown",P),window.removeEventListener("scroll",E),window.removeEventListener("resize",E),v.value="",s("close"))}function W(){i.classList.remove("ib-bar-btn--active"),d.classList.remove("ib-bar-btn--active"),o=void 0}function T(e){r.contains(e.target)||L()}function P(e){e.key==="Escape"&&L()}async function K(){let e=v.value.trim();if(e.length<10){x.textContent="Please enter at least 10 characters.";return}x.textContent="",u.disabled=!0,u.textContent="Sending\u2026";let g=n.querySelector(".ib-bar-title-input"),y=(g==null?void 0:g.value.trim())||null,C=n.querySelector(".ib-bar-email"),G=(C==null?void 0:C.value.trim())||null;try{let k=await M(t.apiKey,e,G,y,{sentiment:o,target:t.target,source:t.source},t.apiUrl);s("submit",k),B.textContent="Thanks for your feedback!",u.textContent="Send feedback",setTimeout(()=>{L(),W()},2e3)}catch(k){s("error",k instanceof Error?k:new Error("Something went wrong.")),x.textContent=k instanceof Error?k.message:"Something went wrong.",u.disabled=!1,u.textContent="Send feedback"}}function j(e){i.classList.remove("ib-bar-btn--active"),d.classList.remove("ib-bar-btn--active"),e.classList.add("ib-bar-btn--active")}return i.addEventListener("click",()=>{s("vote",{sentiment:"positive"}),j(i),z("positive")}),d.addEventListener("click",()=>{s("vote",{sentiment:"negative"}),j(d),z("negative")}),u.addEventListener("click",K),{element:r,on(e,g){var y;(y=b[e])==null||y.push(g)},destroy(){L(),r.remove()}}}var D=`/* InputBuffer Feedback Bar Styles
1
+ var C=class extends Error{constructor(i){super(i.detail),this.name="ApiError",this.type=i.type,this.status=i.status,this.detail=i.detail,this.category=i.category,this.field=i.field}};var N="0.2.0",ee="https://inputbuffer.io/api/v0/inputs";async function W(t,i,s,g,d,h){var p,u,v,n;let l={description:i};if(g&&(l.title=g),s&&(l.contact_email=s),d!=null&&d.source&&(l.source=d.source),d!=null&&d.target){let o=d.target;l.targets=[{type:o.type,metadata:o.metadata}]}let a=new AbortController,x=setTimeout(()=>a.abort(),1e4),r;try{r=await fetch(h!=null?h:ee,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${N} (javascript)`},body:JSON.stringify(l),credentials:"omit",signal:a.signal})}finally{clearTimeout(x)}if(!r.ok){let o=await r.json().catch(()=>({}));throw new C({type:(p=o.type)!=null?p:"https://inputbuffer.io/problems/internal-error",title:(u=o.title)!=null?u:"Error",detail:(v=o.detail)!=null?v:"Submission failed. Please try again.",status:(n=o.status)!=null?n:r.status,category:o.category,field:o.field})}let{data:c}=await r.json();return{id:c.id}}var te="https://inputbuffer.io/api/v0/reactions";async function U(t,i,s,g,d){var c,p,u,v;let h=d?d.replace(/\/inputs$/,"/reactions"):te,l={reaction_value:i,target:{type:s.type,metadata:s.metadata}};g&&(l.user_id=g);let a=new AbortController,x=setTimeout(()=>a.abort(),1e4),r;try{r=await fetch(h,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${N} (javascript)`},body:JSON.stringify(l),credentials:"omit",signal:a.signal})}finally{clearTimeout(x)}if(!r.ok){let n=await r.json().catch(()=>({}));throw new C({type:(c=n.type)!=null?c:"https://inputbuffer.io/problems/internal-error",title:(p=n.title)!=null?p:"Error",detail:(u=n.detail)!=null?u:"Submission failed. Please try again.",status:(v=n.status)!=null?v:r.status,category:n.category,field:n.field})}}function V(t){let i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width","18"),i.setAttribute("height","18"),i.setAttribute("fill","currentColor"),i.setAttribute("aria-hidden","true"),i.style.display="block";let s=document.createElementNS("http://www.w3.org/2000/svg","path");return s.setAttribute("d",t),i.appendChild(s),i}var re="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ie="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z",ae=24*60*60*1e3;function O(t){var $,K;let i;function s(){let e=t.target;return e?`ib:reaction:${t.apiKey}:${e.type}:${JSON.stringify(e.metadata)}`:`ib:reaction:${t.apiKey}:${window.location.pathname}`}function g(){try{let e=localStorage.getItem(s());if(!e)return null;let{sentiment:f,ts:m}=JSON.parse(e);return Date.now()-m>ae?(localStorage.removeItem(s()),null):f}catch{return null}}function d(e){try{localStorage.setItem(s(),JSON.stringify({sentiment:e,ts:Date.now()}))}catch{}}let h={vote:[],open:[],submit:[],close:[],error:[]};function l(e,f){var m;(m=h[e])==null||m.forEach(B=>B(f))}let a=document.createElement("div"),x=t.colorScheme==="dark"?" ib-theme-dark":t.colorScheme==="light"?" ib-theme-light":"";a.className="ib-bar-wrapper"+(t.placement==="fixed"?" ib-bar-wrapper--fixed":"")+x;let{theme:r={}}=t;r.primary&&a.style.setProperty("--ib-primary",r.primary),r.background&&a.style.setProperty("--ib-background",r.background),r.surface&&a.style.setProperty("--ib-surface",r.surface),r.text&&a.style.setProperty("--ib-text",r.text),r.selected&&a.style.setProperty("--ib-selected",r.selected),r.selectedColor&&a.style.setProperty("--ib-selected-color",r.selectedColor);let c=document.createElement("div");c.className="ib-bar";let p=document.createElement("div");p.className="ib-bar-label-area";let u=document.createElement("span");u.className="ib-bar-label",u.textContent=($=t.label)!=null?$:"Was this helpful?",p.appendChild(u);let v=document.createElement("div");v.className="ib-bar-actions"+(t.showLabel===!1?" ib-bar-actions--no-label":"");let n=document.createElement("button");n.type="button",n.className="ib-bar-btn ib-bar-btn--up",n.setAttribute("aria-label","Yes"),n.appendChild(V(re));let o=document.createElement("button");o.type="button",o.className="ib-bar-btn ib-bar-btn--down",o.setAttribute("aria-label","No"),o.appendChild(V(ie)),v.appendChild(n),v.appendChild(o),t.showLabel!==!1&&c.appendChild(p),c.appendChild(v);let b=document.createElement("div");b.className="ib-bar-popover",b.setAttribute("role","dialog"),b.setAttribute("aria-modal","false");let F=document.createElement("div");if(F.className="ib-bar-header",t.modalTitle){b.setAttribute("aria-labelledby","ib-bar-title");let e=document.createElement("p");e.id="ib-bar-title",e.className="ib-bar-title",e.textContent=t.modalTitle,F.appendChild(e)}else b.setAttribute("aria-label","Feedback");let w=document.createElement("div");w.className="ib-bar-body";let k=document.createElement("textarea");k.className="ib-bar-textarea",k.placeholder=(K=t.modalPlaceholder)!=null?K:"What's on your mind?",k.setAttribute("aria-label","Feedback");let S=document.createElement("p");S.className="ib-bar-error";let I=document.createElement("p");I.className="ib-bar-success";let y=document.createElement("button");if(y.type="button",y.className="ib-bar-submit",y.textContent="Send feedback",t.showTitleField===!0){let e=document.createElement("input");e.type="text",e.className="ib-bar-title-input",e.placeholder="Title (optional)",e.setAttribute("aria-label","Feedback title"),w.appendChild(e)}if(w.appendChild(k),t.showEmailField===!0){let e=document.createElement("input");e.type="email",e.className="ib-bar-email",e.placeholder="Your email (optional)",e.setAttribute("aria-label","Email address"),w.appendChild(e)}w.appendChild(S),w.appendChild(I);let L=document.createElement("div");L.className="ib-bar-footer",L.appendChild(y);let P=document.createElement("div");P.className="ib-branding";let T=document.createElement("a");T.href="https://inputbuffer.io",T.target="_blank",T.rel="noopener noreferrer",T.textContent="Powered by inputbuffer.io",P.appendChild(T),L.appendChild(P),w.appendChild(L),b.appendChild(F),b.appendChild(w),a.appendChild(b),a.appendChild(c);function A(){let e=c.getBoundingClientRect();b.style.top=`${e.top-b.offsetHeight-8}px`,b.style.left=`${e.right-320}px`}function q(e){i=e,b.classList.add("ib-bar-popover--visible"),requestAnimationFrame(A),S.textContent="",I.textContent="",k.focus(),setTimeout(()=>document.addEventListener("click",j),0),document.addEventListener("keydown",D),window.addEventListener("scroll",A,{passive:!0}),window.addEventListener("resize",A,{passive:!0}),l("open",{sentiment:e})}function _(){b.classList.contains("ib-bar-popover--visible")&&(b.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",j),document.removeEventListener("keydown",D),window.removeEventListener("scroll",A),window.removeEventListener("resize",A),k.value="",l("close"))}function X(){n.classList.remove("ib-bar-btn--active"),o.classList.remove("ib-bar-btn--active"),i=void 0}function j(e){a.contains(e.target)||_()}function D(e){e.key==="Escape"&&_()}async function Y(){let e=k.value.trim();if(e.length<10){S.textContent="Please enter at least 10 characters.";return}S.textContent="",y.disabled=!0,y.textContent="Sending\u2026";let f=b.querySelector(".ib-bar-title-input"),m=(f==null?void 0:f.value.trim())||null,B=b.querySelector(".ib-bar-email"),Q=(B==null?void 0:B.value.trim())||null;try{let E=await W(t.apiKey,e,Q,m,{sentiment:i,target:t.target,source:t.source},t.apiUrl);l("submit",E),I.textContent="Thanks for your feedback!",y.textContent="Send feedback",setTimeout(()=>{_(),X()},2e3)}catch(E){l("error",E instanceof Error?E:new Error("Something went wrong."));let Z=E instanceof C&&E.category==="user"?E.detail:"Something went wrong. Please try again.";S.textContent=Z,y.disabled=!1,y.textContent="Send feedback"}}function M(e){n.classList.remove("ib-bar-btn--active"),o.classList.remove("ib-bar-btn--active"),e.classList.add("ib-bar-btn--active")}let z=g();z&&(i=z,M(z==="positive"?n:o));function H(e,f){var m;d(e),M(f),q(e),l("vote",{sentiment:e}),t.target&&U(t.apiKey,e==="positive"?1:-1,t.target,(m=t.userId)!=null?m:null,t.apiUrl).catch(()=>{})}return n.addEventListener("click",()=>H("positive",n)),o.addEventListener("click",()=>H("negative",o)),y.addEventListener("click",Y),{element:a,on(e,f){var m;(m=h[e])==null||m.push(f)},destroy(){_(),a.remove()}}}var G=`/* InputBuffer Feedback Bar Styles
2
2
  * .ib-bar-* and .ib-bar-popover* classes are stable public API \u2014 do not rename them.
3
3
  * Developers may target these classes from their own stylesheets to customize the widget.
4
4
  */
@@ -319,4 +319,4 @@ var S="0.1.1",U="https://inputbuffer.io/api/v0/inputs";async function M(t,o,b,s,
319
319
  --ib-radius: 8px;
320
320
  --ib-radius-input: 4px;
321
321
  }
322
- `;function V(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let t=document.createElement("style");t.id="ib-bar-styles",t.textContent=D,document.head.appendChild(t)}function J(t){return t.injectStyles!==!1&&V(),_(t)}var F=class extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var a,l,m,c,p,i,d;let b=this.getAttribute("api-key");if(!b)return;let s=this.getAttribute("inject-styles");(s===null?!0:s!=="false")&&V();let h=this.getAttribute("placement");this._bar=_({apiKey:b,apiUrl:(a=this.getAttribute("api-url"))!=null?a:void 0,label:(l=this.getAttribute("label"))!=null?l:void 0,placement:h==="fixed"?"fixed":"inline",theme:{primary:(m=this.getAttribute("theme-primary"))!=null?m:void 0,background:(c=this.getAttribute("theme-background"))!=null?c:void 0,text:(p=this.getAttribute("theme-text"))!=null?p:void 0,selected:(i=this.getAttribute("theme-selected"))!=null?i:void 0,selectedColor:(d=this.getAttribute("theme-selected-color"))!=null?d:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var b;(b=this._bar)==null||b.destroy(),this._bar=null}};typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",F);var X={createBar:J,version:S};typeof window!="undefined"&&(window.InputBufferIO=X);export{X as InputBufferIO,J as createBar};
322
+ `;function J(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let t=document.createElement("style");t.id="ib-bar-styles",t.textContent=G,document.head.appendChild(t)}function oe(t){return t.injectStyles!==!1&&J(),O(t)}var R=class extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var l,a,x,r,c,p,u;let s=this.getAttribute("api-key");if(!s)return;let g=this.getAttribute("inject-styles");(g===null?!0:g!=="false")&&J();let h=this.getAttribute("placement");this._bar=O({apiKey:s,apiUrl:(l=this.getAttribute("api-url"))!=null?l:void 0,label:(a=this.getAttribute("label"))!=null?a:void 0,placement:h==="fixed"?"fixed":"inline",theme:{primary:(x=this.getAttribute("theme-primary"))!=null?x:void 0,background:(r=this.getAttribute("theme-background"))!=null?r:void 0,text:(c=this.getAttribute("theme-text"))!=null?c:void 0,selected:(p=this.getAttribute("theme-selected"))!=null?p:void 0,selectedColor:(u=this.getAttribute("theme-selected-color"))!=null?u:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var s;(s=this._bar)==null||s.destroy(),this._bar=null}};typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",R);var se={createBar:oe,version:N};typeof window!="undefined"&&(window.InputBufferIO=se);export{se as InputBufferIO,oe as createBar};
package/dist/bar.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{var S="0.1.1",U="https://inputbuffer.io/api/v0/inputs";async function M(t,o,b,s,r,h){var p;let a={description:o};if(s&&(a.title=s),b&&(a.contactEmail=b),r!=null&&r.sentiment&&(a.sentiment=r.sentiment),r!=null&&r.source&&(a.source=r.source),r!=null&&r.target){let i=r.target;a.targets=[{target_type:i.type,...i.targetId&&{target_id:i.targetId},...i.displayName&&{display_name:i.displayName},...i.dedupKey&&{dedup_key:i.dedupKey},metadata:i.metadata}]}let l=new AbortController,m=setTimeout(()=>l.abort(),1e4),c;try{c=await fetch(h!=null?h:U,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${S} (javascript)`},body:JSON.stringify(a),credentials:"omit",signal:l.signal})}finally{clearTimeout(m)}if(!c.ok){let i=await c.json().catch(()=>({}));throw new Error(((p=i==null?void 0:i.error)==null?void 0:p.message)||"Submission failed. Please try again.")}return c.json()}function R(t){let o=document.createElementNS("http://www.w3.org/2000/svg","svg");o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("width","18"),o.setAttribute("height","18"),o.setAttribute("fill","currentColor"),o.setAttribute("aria-hidden","true"),o.style.display="block";let b=document.createElementNS("http://www.w3.org/2000/svg","path");return b.setAttribute("d",t),o.appendChild(b),o}var $="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",q="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function _(t){var O,H;let o,b={vote:[],open:[],submit:[],close:[],error:[]};function s(e,g){var y;(y=b[e])==null||y.forEach(C=>C(g))}let r=document.createElement("div"),h=t.colorScheme==="dark"?" ib-theme-dark":t.colorScheme==="light"?" ib-theme-light":"";r.className="ib-bar-wrapper"+(t.placement==="fixed"?" ib-bar-wrapper--fixed":"")+h;let{theme:a={}}=t;a.primary&&r.style.setProperty("--ib-primary",a.primary),a.background&&r.style.setProperty("--ib-background",a.background),a.surface&&r.style.setProperty("--ib-surface",a.surface),a.text&&r.style.setProperty("--ib-text",a.text),a.selected&&r.style.setProperty("--ib-selected",a.selected),a.selectedColor&&r.style.setProperty("--ib-selected-color",a.selectedColor);let l=document.createElement("div");l.className="ib-bar";let m=document.createElement("div");m.className="ib-bar-label-area";let c=document.createElement("span");c.className="ib-bar-label",c.textContent=(O=t.label)!=null?O:"Was this helpful?",m.appendChild(c);let p=document.createElement("div");p.className="ib-bar-actions"+(t.showLabel===!1?" ib-bar-actions--no-label":"");let i=document.createElement("button");i.type="button",i.className="ib-bar-btn ib-bar-btn--up",i.setAttribute("aria-label","Yes"),i.appendChild(R($));let d=document.createElement("button");d.type="button",d.className="ib-bar-btn ib-bar-btn--down",d.setAttribute("aria-label","No"),d.appendChild(R(q)),p.appendChild(i),p.appendChild(d),t.showLabel!==!1&&l.appendChild(m),l.appendChild(p);let n=document.createElement("div");n.className="ib-bar-popover",n.setAttribute("role","dialog"),n.setAttribute("aria-modal","false");let N=document.createElement("div");if(N.className="ib-bar-header",t.modalTitle){n.setAttribute("aria-labelledby","ib-bar-title");let e=document.createElement("p");e.id="ib-bar-title",e.className="ib-bar-title",e.textContent=t.modalTitle,N.appendChild(e)}else n.setAttribute("aria-label","Feedback");let f=document.createElement("div");f.className="ib-bar-body";let v=document.createElement("textarea");v.className="ib-bar-textarea",v.placeholder=(H=t.modalPlaceholder)!=null?H:"What's on your mind?",v.setAttribute("aria-label","Feedback");let x=document.createElement("p");x.className="ib-bar-error";let B=document.createElement("p");B.className="ib-bar-success";let u=document.createElement("button");if(u.type="button",u.className="ib-bar-submit",u.textContent="Send feedback",t.showTitleField===!0){let e=document.createElement("input");e.type="text",e.className="ib-bar-title-input",e.placeholder="Title (optional)",e.setAttribute("aria-label","Feedback title"),f.appendChild(e)}if(f.appendChild(v),t.showEmailField===!0){let e=document.createElement("input");e.type="email",e.className="ib-bar-email",e.placeholder="Your email (optional)",e.setAttribute("aria-label","Email address"),f.appendChild(e)}f.appendChild(x),f.appendChild(B);let A=document.createElement("div");A.className="ib-bar-footer",A.appendChild(u);let I=document.createElement("div");I.className="ib-branding";let w=document.createElement("a");w.href="https://inputbuffer.io",w.target="_blank",w.rel="noopener noreferrer",w.textContent="Powered by inputbuffer.io",I.appendChild(w),A.appendChild(I),f.appendChild(A),n.appendChild(N),n.appendChild(f),r.appendChild(n),r.appendChild(l);function E(){let e=l.getBoundingClientRect();n.style.top=`${e.top-n.offsetHeight-8}px`,n.style.left=`${e.right-320}px`}function z(e){o=e,n.classList.add("ib-bar-popover--visible"),requestAnimationFrame(E),x.textContent="",B.textContent="",v.focus(),setTimeout(()=>document.addEventListener("click",T),0),document.addEventListener("keydown",P),window.addEventListener("scroll",E,{passive:!0}),window.addEventListener("resize",E,{passive:!0}),s("open",{sentiment:e})}function L(){n.classList.contains("ib-bar-popover--visible")&&(n.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",T),document.removeEventListener("keydown",P),window.removeEventListener("scroll",E),window.removeEventListener("resize",E),v.value="",s("close"))}function W(){i.classList.remove("ib-bar-btn--active"),d.classList.remove("ib-bar-btn--active"),o=void 0}function T(e){r.contains(e.target)||L()}function P(e){e.key==="Escape"&&L()}async function K(){let e=v.value.trim();if(e.length<10){x.textContent="Please enter at least 10 characters.";return}x.textContent="",u.disabled=!0,u.textContent="Sending\u2026";let g=n.querySelector(".ib-bar-title-input"),y=(g==null?void 0:g.value.trim())||null,C=n.querySelector(".ib-bar-email"),G=(C==null?void 0:C.value.trim())||null;try{let k=await M(t.apiKey,e,G,y,{sentiment:o,target:t.target,source:t.source},t.apiUrl);s("submit",k),B.textContent="Thanks for your feedback!",u.textContent="Send feedback",setTimeout(()=>{L(),W()},2e3)}catch(k){s("error",k instanceof Error?k:new Error("Something went wrong.")),x.textContent=k instanceof Error?k.message:"Something went wrong.",u.disabled=!1,u.textContent="Send feedback"}}function j(e){i.classList.remove("ib-bar-btn--active"),d.classList.remove("ib-bar-btn--active"),e.classList.add("ib-bar-btn--active")}return i.addEventListener("click",()=>{s("vote",{sentiment:"positive"}),j(i),z("positive")}),d.addEventListener("click",()=>{s("vote",{sentiment:"negative"}),j(d),z("negative")}),u.addEventListener("click",K),{element:r,on(e,g){var y;(y=b[e])==null||y.push(g)},destroy(){L(),r.remove()}}}var D=`/* InputBuffer Feedback Bar Styles
1
+ "use strict";(()=>{var C=class extends Error{constructor(i){super(i.detail),this.name="ApiError",this.type=i.type,this.status=i.status,this.detail=i.detail,this.category=i.category,this.field=i.field}};var N="0.2.0",ee="https://inputbuffer.io/api/v0/inputs";async function W(t,i,s,g,d,h){var p,u,v,n;let l={description:i};if(g&&(l.title=g),s&&(l.contact_email=s),d!=null&&d.source&&(l.source=d.source),d!=null&&d.target){let o=d.target;l.targets=[{type:o.type,metadata:o.metadata}]}let a=new AbortController,x=setTimeout(()=>a.abort(),1e4),r;try{r=await fetch(h!=null?h:ee,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${N} (javascript)`},body:JSON.stringify(l),credentials:"omit",signal:a.signal})}finally{clearTimeout(x)}if(!r.ok){let o=await r.json().catch(()=>({}));throw new C({type:(p=o.type)!=null?p:"https://inputbuffer.io/problems/internal-error",title:(u=o.title)!=null?u:"Error",detail:(v=o.detail)!=null?v:"Submission failed. Please try again.",status:(n=o.status)!=null?n:r.status,category:o.category,field:o.field})}let{data:c}=await r.json();return{id:c.id}}var te="https://inputbuffer.io/api/v0/reactions";async function U(t,i,s,g,d){var c,p,u,v;let h=d?d.replace(/\/inputs$/,"/reactions"):te,l={reaction_value:i,target:{type:s.type,metadata:s.metadata}};g&&(l.user_id=g);let a=new AbortController,x=setTimeout(()=>a.abort(),1e4),r;try{r=await fetch(h,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${N} (javascript)`},body:JSON.stringify(l),credentials:"omit",signal:a.signal})}finally{clearTimeout(x)}if(!r.ok){let n=await r.json().catch(()=>({}));throw new C({type:(c=n.type)!=null?c:"https://inputbuffer.io/problems/internal-error",title:(p=n.title)!=null?p:"Error",detail:(u=n.detail)!=null?u:"Submission failed. Please try again.",status:(v=n.status)!=null?v:r.status,category:n.category,field:n.field})}}function V(t){let i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width","18"),i.setAttribute("height","18"),i.setAttribute("fill","currentColor"),i.setAttribute("aria-hidden","true"),i.style.display="block";let s=document.createElementNS("http://www.w3.org/2000/svg","path");return s.setAttribute("d",t),i.appendChild(s),i}var re="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ie="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z",ae=24*60*60*1e3;function O(t){var $,K;let i;function s(){let e=t.target;return e?`ib:reaction:${t.apiKey}:${e.type}:${JSON.stringify(e.metadata)}`:`ib:reaction:${t.apiKey}:${window.location.pathname}`}function g(){try{let e=localStorage.getItem(s());if(!e)return null;let{sentiment:f,ts:m}=JSON.parse(e);return Date.now()-m>ae?(localStorage.removeItem(s()),null):f}catch{return null}}function d(e){try{localStorage.setItem(s(),JSON.stringify({sentiment:e,ts:Date.now()}))}catch{}}let h={vote:[],open:[],submit:[],close:[],error:[]};function l(e,f){var m;(m=h[e])==null||m.forEach(B=>B(f))}let a=document.createElement("div"),x=t.colorScheme==="dark"?" ib-theme-dark":t.colorScheme==="light"?" ib-theme-light":"";a.className="ib-bar-wrapper"+(t.placement==="fixed"?" ib-bar-wrapper--fixed":"")+x;let{theme:r={}}=t;r.primary&&a.style.setProperty("--ib-primary",r.primary),r.background&&a.style.setProperty("--ib-background",r.background),r.surface&&a.style.setProperty("--ib-surface",r.surface),r.text&&a.style.setProperty("--ib-text",r.text),r.selected&&a.style.setProperty("--ib-selected",r.selected),r.selectedColor&&a.style.setProperty("--ib-selected-color",r.selectedColor);let c=document.createElement("div");c.className="ib-bar";let p=document.createElement("div");p.className="ib-bar-label-area";let u=document.createElement("span");u.className="ib-bar-label",u.textContent=($=t.label)!=null?$:"Was this helpful?",p.appendChild(u);let v=document.createElement("div");v.className="ib-bar-actions"+(t.showLabel===!1?" ib-bar-actions--no-label":"");let n=document.createElement("button");n.type="button",n.className="ib-bar-btn ib-bar-btn--up",n.setAttribute("aria-label","Yes"),n.appendChild(V(re));let o=document.createElement("button");o.type="button",o.className="ib-bar-btn ib-bar-btn--down",o.setAttribute("aria-label","No"),o.appendChild(V(ie)),v.appendChild(n),v.appendChild(o),t.showLabel!==!1&&c.appendChild(p),c.appendChild(v);let b=document.createElement("div");b.className="ib-bar-popover",b.setAttribute("role","dialog"),b.setAttribute("aria-modal","false");let F=document.createElement("div");if(F.className="ib-bar-header",t.modalTitle){b.setAttribute("aria-labelledby","ib-bar-title");let e=document.createElement("p");e.id="ib-bar-title",e.className="ib-bar-title",e.textContent=t.modalTitle,F.appendChild(e)}else b.setAttribute("aria-label","Feedback");let w=document.createElement("div");w.className="ib-bar-body";let k=document.createElement("textarea");k.className="ib-bar-textarea",k.placeholder=(K=t.modalPlaceholder)!=null?K:"What's on your mind?",k.setAttribute("aria-label","Feedback");let S=document.createElement("p");S.className="ib-bar-error";let I=document.createElement("p");I.className="ib-bar-success";let y=document.createElement("button");if(y.type="button",y.className="ib-bar-submit",y.textContent="Send feedback",t.showTitleField===!0){let e=document.createElement("input");e.type="text",e.className="ib-bar-title-input",e.placeholder="Title (optional)",e.setAttribute("aria-label","Feedback title"),w.appendChild(e)}if(w.appendChild(k),t.showEmailField===!0){let e=document.createElement("input");e.type="email",e.className="ib-bar-email",e.placeholder="Your email (optional)",e.setAttribute("aria-label","Email address"),w.appendChild(e)}w.appendChild(S),w.appendChild(I);let L=document.createElement("div");L.className="ib-bar-footer",L.appendChild(y);let P=document.createElement("div");P.className="ib-branding";let T=document.createElement("a");T.href="https://inputbuffer.io",T.target="_blank",T.rel="noopener noreferrer",T.textContent="Powered by inputbuffer.io",P.appendChild(T),L.appendChild(P),w.appendChild(L),b.appendChild(F),b.appendChild(w),a.appendChild(b),a.appendChild(c);function A(){let e=c.getBoundingClientRect();b.style.top=`${e.top-b.offsetHeight-8}px`,b.style.left=`${e.right-320}px`}function q(e){i=e,b.classList.add("ib-bar-popover--visible"),requestAnimationFrame(A),S.textContent="",I.textContent="",k.focus(),setTimeout(()=>document.addEventListener("click",j),0),document.addEventListener("keydown",D),window.addEventListener("scroll",A,{passive:!0}),window.addEventListener("resize",A,{passive:!0}),l("open",{sentiment:e})}function _(){b.classList.contains("ib-bar-popover--visible")&&(b.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",j),document.removeEventListener("keydown",D),window.removeEventListener("scroll",A),window.removeEventListener("resize",A),k.value="",l("close"))}function X(){n.classList.remove("ib-bar-btn--active"),o.classList.remove("ib-bar-btn--active"),i=void 0}function j(e){a.contains(e.target)||_()}function D(e){e.key==="Escape"&&_()}async function Y(){let e=k.value.trim();if(e.length<10){S.textContent="Please enter at least 10 characters.";return}S.textContent="",y.disabled=!0,y.textContent="Sending\u2026";let f=b.querySelector(".ib-bar-title-input"),m=(f==null?void 0:f.value.trim())||null,B=b.querySelector(".ib-bar-email"),Q=(B==null?void 0:B.value.trim())||null;try{let E=await W(t.apiKey,e,Q,m,{sentiment:i,target:t.target,source:t.source},t.apiUrl);l("submit",E),I.textContent="Thanks for your feedback!",y.textContent="Send feedback",setTimeout(()=>{_(),X()},2e3)}catch(E){l("error",E instanceof Error?E:new Error("Something went wrong."));let Z=E instanceof C&&E.category==="user"?E.detail:"Something went wrong. Please try again.";S.textContent=Z,y.disabled=!1,y.textContent="Send feedback"}}function M(e){n.classList.remove("ib-bar-btn--active"),o.classList.remove("ib-bar-btn--active"),e.classList.add("ib-bar-btn--active")}let z=g();z&&(i=z,M(z==="positive"?n:o));function H(e,f){var m;d(e),M(f),q(e),l("vote",{sentiment:e}),t.target&&U(t.apiKey,e==="positive"?1:-1,t.target,(m=t.userId)!=null?m:null,t.apiUrl).catch(()=>{})}return n.addEventListener("click",()=>H("positive",n)),o.addEventListener("click",()=>H("negative",o)),y.addEventListener("click",Y),{element:a,on(e,f){var m;(m=h[e])==null||m.push(f)},destroy(){_(),a.remove()}}}var G=`/* InputBuffer Feedback Bar Styles
2
2
  * .ib-bar-* and .ib-bar-popover* classes are stable public API \u2014 do not rename them.
3
3
  * Developers may target these classes from their own stylesheets to customize the widget.
4
4
  */
@@ -319,4 +319,4 @@
319
319
  --ib-radius: 8px;
320
320
  --ib-radius-input: 4px;
321
321
  }
322
- `;function V(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let t=document.createElement("style");t.id="ib-bar-styles",t.textContent=D,document.head.appendChild(t)}function J(t){return t.injectStyles!==!1&&V(),_(t)}var F=class extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var a,l,m,c,p,i,d;let b=this.getAttribute("api-key");if(!b)return;let s=this.getAttribute("inject-styles");(s===null?!0:s!=="false")&&V();let h=this.getAttribute("placement");this._bar=_({apiKey:b,apiUrl:(a=this.getAttribute("api-url"))!=null?a:void 0,label:(l=this.getAttribute("label"))!=null?l:void 0,placement:h==="fixed"?"fixed":"inline",theme:{primary:(m=this.getAttribute("theme-primary"))!=null?m:void 0,background:(c=this.getAttribute("theme-background"))!=null?c:void 0,text:(p=this.getAttribute("theme-text"))!=null?p:void 0,selected:(i=this.getAttribute("theme-selected"))!=null?i:void 0,selectedColor:(d=this.getAttribute("theme-selected-color"))!=null?d:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var b;(b=this._bar)==null||b.destroy(),this._bar=null}};typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",F);var X={createBar:J,version:S};typeof window!="undefined"&&(window.InputBufferIO=X);})();
322
+ `;function J(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let t=document.createElement("style");t.id="ib-bar-styles",t.textContent=G,document.head.appendChild(t)}function oe(t){return t.injectStyles!==!1&&J(),O(t)}var R=class extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var l,a,x,r,c,p,u;let s=this.getAttribute("api-key");if(!s)return;let g=this.getAttribute("inject-styles");(g===null?!0:g!=="false")&&J();let h=this.getAttribute("placement");this._bar=O({apiKey:s,apiUrl:(l=this.getAttribute("api-url"))!=null?l:void 0,label:(a=this.getAttribute("label"))!=null?a:void 0,placement:h==="fixed"?"fixed":"inline",theme:{primary:(x=this.getAttribute("theme-primary"))!=null?x:void 0,background:(r=this.getAttribute("theme-background"))!=null?r:void 0,text:(c=this.getAttribute("theme-text"))!=null?c:void 0,selected:(p=this.getAttribute("theme-selected"))!=null?p:void 0,selectedColor:(u=this.getAttribute("theme-selected-color"))!=null?u:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var s;(s=this._bar)==null||s.destroy(),this._bar=null}};typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",R);var se={createBar:oe,version:N};typeof window!="undefined"&&(window.InputBufferIO=se);})();
package/dist/modal.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- function B(a){let i=document.getElementById("ib-modal");if(!i)return;let{theme:e={}}=a;e.primary&&i.style.setProperty("--ib-primary",e.primary),e.background&&i.style.setProperty("--ib-background",e.background),e.surface&&i.style.setProperty("--ib-surface",e.surface),e.text&&i.style.setProperty("--ib-text",e.text),e.selected&&i.style.setProperty("--ib-selected",e.selected),e.selectedColor&&i.style.setProperty("--ib-selected-color",e.selectedColor)}var L="0.1.1",V="https://inputbuffer.io/api/v0/inputs";async function N(a,i,e,b,n,s){var y;let m={description:i};if(b&&(m.title=b),e&&(m.contactEmail=e),n!=null&&n.sentiment&&(m.sentiment=n.sentiment),n!=null&&n.source&&(m.source=n.source),n!=null&&n.target){let l=n.target;m.targets=[{target_type:l.type,...l.targetId&&{target_id:l.targetId},...l.displayName&&{display_name:l.displayName},...l.dedupKey&&{dedup_key:l.dedupKey},metadata:l.metadata}]}let u=new AbortController,h=setTimeout(()=>u.abort(),1e4),c;try{c=await fetch(s!=null?s:V,{method:"POST",headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${L} (javascript)`},body:JSON.stringify(m),credentials:"omit",signal:u.signal})}finally{clearTimeout(h)}if(!c.ok){let l=await c.json().catch(()=>({}));throw new Error(((y=l==null?void 0:l.error)==null?void 0:y.message)||"Submission failed. Please try again.")}return c.json()}function z(a){let i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width","18"),i.setAttribute("height","18"),i.setAttribute("fill","currentColor"),i.setAttribute("aria-hidden","true"),i.style.display="block";let e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d",a),i.appendChild(e),i}var U="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",_="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function S(a){let i=null,e,b,n=null,s=null,m=null,u=null,h=null,c=null,y=null,l=null,w=null,H=[],A=[],I=[];function M(t){if(t.key==="Escape"){k();return}if(t.key==="Tab"&&i){let o=Array.from(i.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(o.length===0)return;let f=o[0],d=o[o.length-1];t.shiftKey?document.activeElement===f&&(t.preventDefault(),d.focus()):document.activeElement===d&&(t.preventDefault(),f.focus())}}async function W(){var o,f;if(!s||!h)return;let t=s.value.trim();if(t.length<10){c&&(c.textContent="Please enter at least 10 characters.",c.style.display="block");return}c&&(c.style.display="none"),h.disabled=!0,h.textContent="Sending\u2026";try{let d=(u==null?void 0:u.value.trim())||((o=e==null?void 0:e.prefill)==null?void 0:o.email)||null,p=(m==null?void 0:m.value.trim())||null,x=b!=null?b:e==null?void 0:e.sentiment,C=await N(a.apiKey,t,d||null,p,{...e,sentiment:x,source:(f=e==null?void 0:e.source)!=null?f:a.source},a.apiUrl);y&&(y.textContent="Thanks for your feedback!",y.style.display="block"),H.forEach(E=>E(C)),n=setTimeout(()=>k(),2e3)}catch(d){let p=d instanceof Error?d:new Error("Unknown error");c&&(c.textContent="Something went wrong. Please try again.",c.style.display="block"),I.forEach(x=>x(p)),h.disabled=!1,h.textContent="Send feedback"}}function D(){let t=document.createElement("div");t.id="ib-overlay";let o=document.createElement("div");o.id="ib-modal",a.colorScheme==="dark"?o.classList.add("ib-theme-dark"):a.colorScheme==="light"&&o.classList.add("ib-theme-light"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true");let f=document.createElement("div");if(f.id="ib-modal-header",w=f,a.title?(o.setAttribute("aria-labelledby","ib-title"),l=document.createElement("h2"),l.id="ib-title",l.className="ib-modal-title",l.textContent=a.title,f.appendChild(l)):o.setAttribute("aria-label","Feedback"),a.showSentiment){let v,g,T=document.createElement("div");T.className="ib-modal-sentiment",v=document.createElement("button"),v.type="button",v.className="ib-modal-thumb ib-modal-thumb--up",v.setAttribute("aria-label","Helpful"),v.appendChild(z(U)),g=document.createElement("button"),g.type="button",g.className="ib-modal-thumb ib-modal-thumb--down",g.setAttribute("aria-label","Not helpful"),g.appendChild(z(_)),v.addEventListener("click",()=>{v.classList.add("ib-modal-thumb--active"),g.classList.remove("ib-modal-thumb--active"),b="positive"}),g.addEventListener("click",()=>{g.classList.add("ib-modal-thumb--active"),v.classList.remove("ib-modal-thumb--active"),b="negative"}),T.appendChild(v),T.appendChild(g),f.appendChild(T)}let d=document.createElement("button");d.id="ib-close",d.className="ib-modal-close",d.textContent="\xD7",d.setAttribute("aria-label","Close feedback form"),d.addEventListener("click",k),f.appendChild(d);let p=document.createElement("div");p.id="ib-modal-body",s=document.createElement("textarea"),s.id="ib-textarea",s.className="ib-modal-textarea",s.placeholder=a.placeholder||"What's on your mind?",s.setAttribute("aria-label","Feedback"),h=document.createElement("button"),h.id="ib-submit",h.className="ib-modal-submit",h.textContent="Send feedback",h.addEventListener("click",W),y=document.createElement("p"),y.id="ib-success",y.className="ib-modal-success",c=document.createElement("p"),c.id="ib-error",c.className="ib-modal-error",a.showTitleField===!0&&(m=document.createElement("input"),m.id="ib-title-input",m.className="ib-modal-title-input",m.type="text",m.placeholder="Title (optional)",m.setAttribute("aria-label","Feedback title"),p.appendChild(m)),p.appendChild(s),a.showEmailField===!0&&(u=document.createElement("input"),u.id="ib-email",u.className="ib-modal-email",u.type="email",u.placeholder="Your email (optional)",u.setAttribute("aria-label","Email address"),p.appendChild(u)),p.appendChild(c),p.appendChild(y);let x=document.createElement("div");x.className="ib-modal-footer",x.appendChild(h);let C=document.createElement("div");C.className="ib-branding";let E=document.createElement("a");return E.href="https://inputbuffer.io",E.target="_blank",E.rel="noopener noreferrer",E.textContent="Powered by inputbuffer.io",C.appendChild(E),x.appendChild(C),p.appendChild(x),o.appendChild(f),o.appendChild(p),t.appendChild(o),t.addEventListener("click",v=>{v.target===t&&k()}),document.addEventListener("keydown",M),t}function F(t){var o,f;if(!i){if(e=t,i=D(),document.body.appendChild(i),B(a),t!=null&&t.title){if(l)l.textContent=t.title;else if(w){let d=i.querySelector("#ib-modal");d.removeAttribute("aria-label"),d.setAttribute("aria-labelledby","ib-title"),l=document.createElement("h2"),l.id="ib-title",l.className="ib-modal-title",l.textContent=t.title,w.prepend(l)}}if(t!=null&&t.sentiment){b=t.sentiment;let d=i.querySelector(".ib-modal-thumb--up"),p=i.querySelector(".ib-modal-thumb--down");t.sentiment==="positive"?d==null||d.classList.add("ib-modal-thumb--active"):t.sentiment==="negative"&&(p==null||p.classList.add("ib-modal-thumb--active"))}s&&((o=t==null?void 0:t.prefill)!=null&&o.description)&&(s.value=t.prefill.description),u&&((f=t==null?void 0:t.prefill)!=null&&f.email)&&(u.value=t.prefill.email),s==null||s.focus()}}function k(){i&&(n!==null&&(clearTimeout(n),n=null),document.removeEventListener("keydown",M),i.remove(),i=null,s=null,m=null,u=null,h=null,c=null,y=null,l=null,w=null,e=void 0,b=void 0,A.forEach(t=>t()))}function R(t,o){t==="submit"?H.push(o):t==="close"?A.push(o):t==="error"&&I.push(o)}function K(){k()}return{open:F,close:k,on:R,destroy:K}}var O=`/* InputBuffer Modal Styles
1
+ var w=class extends Error{constructor(e){super(e.detail),this.name="ApiError",this.type=e.type,this.status=e.status,this.detail=e.detail,this.category=e.category,this.field=e.field}};function B(r){let e=document.getElementById("ib-modal");if(!e)return;let{theme:t={}}=r;t.primary&&e.style.setProperty("--ib-primary",t.primary),t.background&&e.style.setProperty("--ib-background",t.background),t.surface&&e.style.setProperty("--ib-surface",t.surface),t.text&&e.style.setProperty("--ib-text",t.text),t.selected&&e.style.setProperty("--ib-selected",t.selected),t.selectedColor&&e.style.setProperty("--ib-selected-color",t.selectedColor)}var I="0.2.0",K="https://inputbuffer.io/api/v0/inputs";async function P(r,e,t,d,c,l){var u,k,L,A;let b={description:e};if(d&&(b.title=d),t&&(b.contact_email=t),c!=null&&c.source&&(b.source=c.source),c!=null&&c.target){let h=c.target;b.targets=[{type:h.type,metadata:h.metadata}]}let m=new AbortController,g=setTimeout(()=>m.abort(),1e4),s;try{s=await fetch(l!=null?l:K,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${I} (javascript)`},body:JSON.stringify(b),credentials:"omit",signal:m.signal})}finally{clearTimeout(g)}if(!s.ok){let h=await s.json().catch(()=>({}));throw new w({type:(u=h.type)!=null?u:"https://inputbuffer.io/problems/internal-error",title:(k=h.title)!=null?k:"Error",detail:(L=h.detail)!=null?L:"Submission failed. Please try again.",status:(A=h.status)!=null?A:s.status,category:h.category,field:h.field})}let{data:v}=await s.json();return{id:v.id}}function O(r){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("width","18"),e.setAttribute("height","18"),e.setAttribute("fill","currentColor"),e.setAttribute("aria-hidden","true"),e.style.display="block";let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",r),e.appendChild(t),e}var V="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",q="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function N(r){let e=null,t,d,c=null,l=null,b=null,m=null,g=null,s=null,v=null,u=null,k=null,L=[],A=[],h=[];function M(i){if(i.key==="Escape"){T();return}if(i.key==="Tab"&&e){let o=Array.from(e.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(o.length===0)return;let f=o[0],n=o[o.length-1];i.shiftKey?document.activeElement===f&&(i.preventDefault(),n.focus()):document.activeElement===n&&(i.preventDefault(),f.focus())}}async function W(){var o,f;if(!l||!g)return;let i=l.value.trim();if(i.length<10){s&&(s.textContent="Please enter at least 10 characters.",s.style.display="block");return}s&&(s.style.display="none"),g.disabled=!0,g.textContent="Sending\u2026";try{let n=(m==null?void 0:m.value.trim())||((o=t==null?void 0:t.prefill)==null?void 0:o.email)||null,p=(b==null?void 0:b.value.trim())||null,x=d!=null?d:t==null?void 0:t.sentiment,H=await P(r.apiKey,i,n||null,p,{...t,sentiment:x,source:(f=t==null?void 0:t.source)!=null?f:r.source},r.apiUrl);v&&(v.textContent="Thanks for your feedback!",v.style.display="block"),L.forEach(C=>C(H)),c=setTimeout(()=>T(),2e3)}catch(n){let p=n instanceof Error?n:new Error("Unknown error");if(s){let x=n instanceof w&&n.category==="user"?n.detail:"Something went wrong. Please try again.";s.textContent=x,s.style.display="block"}h.forEach(x=>x(p)),g.disabled=!1,g.textContent="Send feedback"}}function F(){let i=document.createElement("div");i.id="ib-overlay";let o=document.createElement("div");o.id="ib-modal",r.colorScheme==="dark"?o.classList.add("ib-theme-dark"):r.colorScheme==="light"&&o.classList.add("ib-theme-light"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true");let f=document.createElement("div");if(f.id="ib-modal-header",k=f,r.title?(o.setAttribute("aria-labelledby","ib-title"),u=document.createElement("h2"),u.id="ib-title",u.className="ib-modal-title",u.textContent=r.title,f.appendChild(u)):o.setAttribute("aria-label","Feedback"),r.showSentiment){let y,E,S=document.createElement("div");S.className="ib-modal-sentiment",y=document.createElement("button"),y.type="button",y.className="ib-modal-thumb ib-modal-thumb--up",y.setAttribute("aria-label","Helpful"),y.appendChild(O(V)),E=document.createElement("button"),E.type="button",E.className="ib-modal-thumb ib-modal-thumb--down",E.setAttribute("aria-label","Not helpful"),E.appendChild(O(q)),y.addEventListener("click",()=>{y.classList.add("ib-modal-thumb--active"),E.classList.remove("ib-modal-thumb--active"),d="positive"}),E.addEventListener("click",()=>{E.classList.add("ib-modal-thumb--active"),y.classList.remove("ib-modal-thumb--active"),d="negative"}),S.appendChild(y),S.appendChild(E),f.appendChild(S)}let n=document.createElement("button");n.id="ib-close",n.className="ib-modal-close",n.textContent="\xD7",n.setAttribute("aria-label","Close feedback form"),n.addEventListener("click",T),f.appendChild(n);let p=document.createElement("div");p.id="ib-modal-body",l=document.createElement("textarea"),l.id="ib-textarea",l.className="ib-modal-textarea",l.placeholder=r.placeholder||"What's on your mind?",l.setAttribute("aria-label","Feedback"),g=document.createElement("button"),g.id="ib-submit",g.className="ib-modal-submit",g.textContent="Send feedback",g.addEventListener("click",W),v=document.createElement("p"),v.id="ib-success",v.className="ib-modal-success",s=document.createElement("p"),s.id="ib-error",s.className="ib-modal-error",r.showTitleField===!0&&(b=document.createElement("input"),b.id="ib-title-input",b.className="ib-modal-title-input",b.type="text",b.placeholder="Title (optional)",b.setAttribute("aria-label","Feedback title"),p.appendChild(b)),p.appendChild(l),r.showEmailField===!0&&(m=document.createElement("input"),m.id="ib-email",m.className="ib-modal-email",m.type="email",m.placeholder="Your email (optional)",m.setAttribute("aria-label","Email address"),p.appendChild(m)),p.appendChild(s),p.appendChild(v);let x=document.createElement("div");x.className="ib-modal-footer",x.appendChild(g);let H=document.createElement("div");H.className="ib-branding";let C=document.createElement("a");return C.href="https://inputbuffer.io",C.target="_blank",C.rel="noopener noreferrer",C.textContent="Powered by inputbuffer.io",H.appendChild(C),x.appendChild(H),p.appendChild(x),o.appendChild(f),o.appendChild(p),i.appendChild(o),i.addEventListener("click",y=>{y.target===i&&T()}),document.addEventListener("keydown",M),i}function R(i){var o,f;if(!e){if(t=i,e=F(),document.body.appendChild(e),B(r),i!=null&&i.title){if(u)u.textContent=i.title;else if(k){let n=e.querySelector("#ib-modal");n.removeAttribute("aria-label"),n.setAttribute("aria-labelledby","ib-title"),u=document.createElement("h2"),u.id="ib-title",u.className="ib-modal-title",u.textContent=i.title,k.prepend(u)}}if(i!=null&&i.sentiment){d=i.sentiment;let n=e.querySelector(".ib-modal-thumb--up"),p=e.querySelector(".ib-modal-thumb--down");i.sentiment==="positive"?n==null||n.classList.add("ib-modal-thumb--active"):i.sentiment==="negative"&&(p==null||p.classList.add("ib-modal-thumb--active"))}l&&((o=i==null?void 0:i.prefill)!=null&&o.description)&&(l.value=i.prefill.description),m&&((f=i==null?void 0:i.prefill)!=null&&f.email)&&(m.value=i.prefill.email),l==null||l.focus()}}function T(){e&&(c!==null&&(clearTimeout(c),c=null),document.removeEventListener("keydown",M),e.remove(),e=null,l=null,b=null,m=null,g=null,s=null,v=null,u=null,k=null,t=void 0,d=void 0,A.forEach(i=>i()))}function _(i,o){i==="submit"?L.push(o):i==="close"?A.push(o):i==="error"&&h.push(o)}function U(){T()}return{open:R,close:T,on:_,destroy:U}}var z=`/* InputBuffer Modal Styles
2
2
  * All #ib-* IDs are stable public API \u2014 do not rename them.
3
3
  * Developers may target these IDs from their own stylesheets to customize the widget.
4
4
  */
@@ -306,4 +306,4 @@ function B(a){let i=document.getElementById("ib-modal");if(!i)return;let{theme:e
306
306
  --ib-radius: 8px;
307
307
  --ib-radius-input: 4px;
308
308
  }
309
- `;var r=document.currentScript;function G(){if(document.getElementById("ib-modal-styles"))return;let a=document.createElement("style");a.id="ib-modal-styles",a.textContent=O,document.head.appendChild(a)}function P(a){a.injectStyles!==!1&&G();let i=S(a),e=null,b=null;return a.attachTo&&(e=document.querySelector(a.attachTo),e&&(b=()=>i.open(),e.addEventListener("click",b))),{open:n=>i.open(n),close:()=>i.close(),on:(n,s)=>i.on(n,s),destroy:()=>{e&&b&&(e.removeEventListener("click",b),e=null,b=null),i.destroy()}}}var j={createModal:P,version:L};window.InputBufferIO=j;(function(){let i=r==null?void 0:r.dataset.apiKey;if(!i)return;let e=r==null?void 0:r.dataset.injectStyles,b=P({apiKey:i,apiUrl:r==null?void 0:r.dataset.apiUrl,attachTo:r==null?void 0:r.dataset.attachTo,injectStyles:e===void 0?!0:e!=="false",theme:{primary:r==null?void 0:r.dataset.themePrimary,background:r==null?void 0:r.dataset.themeBackground,text:r==null?void 0:r.dataset.themeText,selected:r==null?void 0:r.dataset.themeSelected,selectedColor:r==null?void 0:r.dataset.themeSelectedColor}});j._defaultInstance=b})();export{j as InputBufferIO,P as createModal};
309
+ `;var a=document.currentScript;function $(){if(document.getElementById("ib-modal-styles"))return;let r=document.createElement("style");r.id="ib-modal-styles",r.textContent=z,document.head.appendChild(r)}function j(r){r.injectStyles!==!1&&$();let e=N(r),t=null,d=null;return r.attachTo&&(t=document.querySelector(r.attachTo),t&&(d=()=>e.open(),t.addEventListener("click",d))),{open:c=>e.open(c),close:()=>e.close(),on:(c,l)=>e.on(c,l),destroy:()=>{t&&d&&(t.removeEventListener("click",d),t=null,d=null),e.destroy()}}}var D={createModal:j,version:I};window.InputBufferIO=D;(function(){let e=a==null?void 0:a.dataset.apiKey;if(!e)return;let t=a==null?void 0:a.dataset.injectStyles,d=j({apiKey:e,apiUrl:a==null?void 0:a.dataset.apiUrl,attachTo:a==null?void 0:a.dataset.attachTo,injectStyles:t===void 0?!0:t!=="false",theme:{primary:a==null?void 0:a.dataset.themePrimary,background:a==null?void 0:a.dataset.themeBackground,text:a==null?void 0:a.dataset.themeText,selected:a==null?void 0:a.dataset.themeSelected,selectedColor:a==null?void 0:a.dataset.themeSelectedColor}});D._defaultInstance=d})();export{D as InputBufferIO,j as createModal};
package/dist/modal.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{function B(a){let i=document.getElementById("ib-modal");if(!i)return;let{theme:e={}}=a;e.primary&&i.style.setProperty("--ib-primary",e.primary),e.background&&i.style.setProperty("--ib-background",e.background),e.surface&&i.style.setProperty("--ib-surface",e.surface),e.text&&i.style.setProperty("--ib-text",e.text),e.selected&&i.style.setProperty("--ib-selected",e.selected),e.selectedColor&&i.style.setProperty("--ib-selected-color",e.selectedColor)}var L="0.1.1",V="https://inputbuffer.io/api/v0/inputs";async function N(a,i,e,b,n,s){var y;let m={description:i};if(b&&(m.title=b),e&&(m.contactEmail=e),n!=null&&n.sentiment&&(m.sentiment=n.sentiment),n!=null&&n.source&&(m.source=n.source),n!=null&&n.target){let l=n.target;m.targets=[{target_type:l.type,...l.targetId&&{target_id:l.targetId},...l.displayName&&{display_name:l.displayName},...l.dedupKey&&{dedup_key:l.dedupKey},metadata:l.metadata}]}let u=new AbortController,h=setTimeout(()=>u.abort(),1e4),c;try{c=await fetch(s!=null?s:V,{method:"POST",headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${L} (javascript)`},body:JSON.stringify(m),credentials:"omit",signal:u.signal})}finally{clearTimeout(h)}if(!c.ok){let l=await c.json().catch(()=>({}));throw new Error(((y=l==null?void 0:l.error)==null?void 0:y.message)||"Submission failed. Please try again.")}return c.json()}function z(a){let i=document.createElementNS("http://www.w3.org/2000/svg","svg");i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("width","18"),i.setAttribute("height","18"),i.setAttribute("fill","currentColor"),i.setAttribute("aria-hidden","true"),i.style.display="block";let e=document.createElementNS("http://www.w3.org/2000/svg","path");return e.setAttribute("d",a),i.appendChild(e),i}var U="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",_="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function S(a){let i=null,e,b,n=null,s=null,m=null,u=null,h=null,c=null,y=null,l=null,w=null,H=[],A=[],I=[];function M(t){if(t.key==="Escape"){k();return}if(t.key==="Tab"&&i){let o=Array.from(i.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(o.length===0)return;let f=o[0],d=o[o.length-1];t.shiftKey?document.activeElement===f&&(t.preventDefault(),d.focus()):document.activeElement===d&&(t.preventDefault(),f.focus())}}async function W(){var o,f;if(!s||!h)return;let t=s.value.trim();if(t.length<10){c&&(c.textContent="Please enter at least 10 characters.",c.style.display="block");return}c&&(c.style.display="none"),h.disabled=!0,h.textContent="Sending\u2026";try{let d=(u==null?void 0:u.value.trim())||((o=e==null?void 0:e.prefill)==null?void 0:o.email)||null,p=(m==null?void 0:m.value.trim())||null,x=b!=null?b:e==null?void 0:e.sentiment,C=await N(a.apiKey,t,d||null,p,{...e,sentiment:x,source:(f=e==null?void 0:e.source)!=null?f:a.source},a.apiUrl);y&&(y.textContent="Thanks for your feedback!",y.style.display="block"),H.forEach(E=>E(C)),n=setTimeout(()=>k(),2e3)}catch(d){let p=d instanceof Error?d:new Error("Unknown error");c&&(c.textContent="Something went wrong. Please try again.",c.style.display="block"),I.forEach(x=>x(p)),h.disabled=!1,h.textContent="Send feedback"}}function D(){let t=document.createElement("div");t.id="ib-overlay";let o=document.createElement("div");o.id="ib-modal",a.colorScheme==="dark"?o.classList.add("ib-theme-dark"):a.colorScheme==="light"&&o.classList.add("ib-theme-light"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true");let f=document.createElement("div");if(f.id="ib-modal-header",w=f,a.title?(o.setAttribute("aria-labelledby","ib-title"),l=document.createElement("h2"),l.id="ib-title",l.className="ib-modal-title",l.textContent=a.title,f.appendChild(l)):o.setAttribute("aria-label","Feedback"),a.showSentiment){let v,g,T=document.createElement("div");T.className="ib-modal-sentiment",v=document.createElement("button"),v.type="button",v.className="ib-modal-thumb ib-modal-thumb--up",v.setAttribute("aria-label","Helpful"),v.appendChild(z(U)),g=document.createElement("button"),g.type="button",g.className="ib-modal-thumb ib-modal-thumb--down",g.setAttribute("aria-label","Not helpful"),g.appendChild(z(_)),v.addEventListener("click",()=>{v.classList.add("ib-modal-thumb--active"),g.classList.remove("ib-modal-thumb--active"),b="positive"}),g.addEventListener("click",()=>{g.classList.add("ib-modal-thumb--active"),v.classList.remove("ib-modal-thumb--active"),b="negative"}),T.appendChild(v),T.appendChild(g),f.appendChild(T)}let d=document.createElement("button");d.id="ib-close",d.className="ib-modal-close",d.textContent="\xD7",d.setAttribute("aria-label","Close feedback form"),d.addEventListener("click",k),f.appendChild(d);let p=document.createElement("div");p.id="ib-modal-body",s=document.createElement("textarea"),s.id="ib-textarea",s.className="ib-modal-textarea",s.placeholder=a.placeholder||"What's on your mind?",s.setAttribute("aria-label","Feedback"),h=document.createElement("button"),h.id="ib-submit",h.className="ib-modal-submit",h.textContent="Send feedback",h.addEventListener("click",W),y=document.createElement("p"),y.id="ib-success",y.className="ib-modal-success",c=document.createElement("p"),c.id="ib-error",c.className="ib-modal-error",a.showTitleField===!0&&(m=document.createElement("input"),m.id="ib-title-input",m.className="ib-modal-title-input",m.type="text",m.placeholder="Title (optional)",m.setAttribute("aria-label","Feedback title"),p.appendChild(m)),p.appendChild(s),a.showEmailField===!0&&(u=document.createElement("input"),u.id="ib-email",u.className="ib-modal-email",u.type="email",u.placeholder="Your email (optional)",u.setAttribute("aria-label","Email address"),p.appendChild(u)),p.appendChild(c),p.appendChild(y);let x=document.createElement("div");x.className="ib-modal-footer",x.appendChild(h);let C=document.createElement("div");C.className="ib-branding";let E=document.createElement("a");return E.href="https://inputbuffer.io",E.target="_blank",E.rel="noopener noreferrer",E.textContent="Powered by inputbuffer.io",C.appendChild(E),x.appendChild(C),p.appendChild(x),o.appendChild(f),o.appendChild(p),t.appendChild(o),t.addEventListener("click",v=>{v.target===t&&k()}),document.addEventListener("keydown",M),t}function F(t){var o,f;if(!i){if(e=t,i=D(),document.body.appendChild(i),B(a),t!=null&&t.title){if(l)l.textContent=t.title;else if(w){let d=i.querySelector("#ib-modal");d.removeAttribute("aria-label"),d.setAttribute("aria-labelledby","ib-title"),l=document.createElement("h2"),l.id="ib-title",l.className="ib-modal-title",l.textContent=t.title,w.prepend(l)}}if(t!=null&&t.sentiment){b=t.sentiment;let d=i.querySelector(".ib-modal-thumb--up"),p=i.querySelector(".ib-modal-thumb--down");t.sentiment==="positive"?d==null||d.classList.add("ib-modal-thumb--active"):t.sentiment==="negative"&&(p==null||p.classList.add("ib-modal-thumb--active"))}s&&((o=t==null?void 0:t.prefill)!=null&&o.description)&&(s.value=t.prefill.description),u&&((f=t==null?void 0:t.prefill)!=null&&f.email)&&(u.value=t.prefill.email),s==null||s.focus()}}function k(){i&&(n!==null&&(clearTimeout(n),n=null),document.removeEventListener("keydown",M),i.remove(),i=null,s=null,m=null,u=null,h=null,c=null,y=null,l=null,w=null,e=void 0,b=void 0,A.forEach(t=>t()))}function R(t,o){t==="submit"?H.push(o):t==="close"?A.push(o):t==="error"&&I.push(o)}function K(){k()}return{open:F,close:k,on:R,destroy:K}}var O=`/* InputBuffer Modal Styles
1
+ "use strict";(()=>{var w=class extends Error{constructor(e){super(e.detail),this.name="ApiError",this.type=e.type,this.status=e.status,this.detail=e.detail,this.category=e.category,this.field=e.field}};function B(r){let e=document.getElementById("ib-modal");if(!e)return;let{theme:t={}}=r;t.primary&&e.style.setProperty("--ib-primary",t.primary),t.background&&e.style.setProperty("--ib-background",t.background),t.surface&&e.style.setProperty("--ib-surface",t.surface),t.text&&e.style.setProperty("--ib-text",t.text),t.selected&&e.style.setProperty("--ib-selected",t.selected),t.selectedColor&&e.style.setProperty("--ib-selected-color",t.selectedColor)}var I="0.2.0",K="https://inputbuffer.io/api/v0/inputs";async function P(r,e,t,d,c,l){var u,k,L,A;let b={description:e};if(d&&(b.title=d),t&&(b.contact_email=t),c!=null&&c.source&&(b.source=c.source),c!=null&&c.target){let h=c.target;b.targets=[{type:h.type,metadata:h.metadata}]}let m=new AbortController,g=setTimeout(()=>m.abort(),1e4),s;try{s=await fetch(l!=null?l:K,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${I} (javascript)`},body:JSON.stringify(b),credentials:"omit",signal:m.signal})}finally{clearTimeout(g)}if(!s.ok){let h=await s.json().catch(()=>({}));throw new w({type:(u=h.type)!=null?u:"https://inputbuffer.io/problems/internal-error",title:(k=h.title)!=null?k:"Error",detail:(L=h.detail)!=null?L:"Submission failed. Please try again.",status:(A=h.status)!=null?A:s.status,category:h.category,field:h.field})}let{data:v}=await s.json();return{id:v.id}}function O(r){let e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("width","18"),e.setAttribute("height","18"),e.setAttribute("fill","currentColor"),e.setAttribute("aria-hidden","true"),e.style.display="block";let t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",r),e.appendChild(t),e}var V="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",q="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function N(r){let e=null,t,d,c=null,l=null,b=null,m=null,g=null,s=null,v=null,u=null,k=null,L=[],A=[],h=[];function M(i){if(i.key==="Escape"){T();return}if(i.key==="Tab"&&e){let o=Array.from(e.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(o.length===0)return;let f=o[0],n=o[o.length-1];i.shiftKey?document.activeElement===f&&(i.preventDefault(),n.focus()):document.activeElement===n&&(i.preventDefault(),f.focus())}}async function W(){var o,f;if(!l||!g)return;let i=l.value.trim();if(i.length<10){s&&(s.textContent="Please enter at least 10 characters.",s.style.display="block");return}s&&(s.style.display="none"),g.disabled=!0,g.textContent="Sending\u2026";try{let n=(m==null?void 0:m.value.trim())||((o=t==null?void 0:t.prefill)==null?void 0:o.email)||null,p=(b==null?void 0:b.value.trim())||null,x=d!=null?d:t==null?void 0:t.sentiment,H=await P(r.apiKey,i,n||null,p,{...t,sentiment:x,source:(f=t==null?void 0:t.source)!=null?f:r.source},r.apiUrl);v&&(v.textContent="Thanks for your feedback!",v.style.display="block"),L.forEach(C=>C(H)),c=setTimeout(()=>T(),2e3)}catch(n){let p=n instanceof Error?n:new Error("Unknown error");if(s){let x=n instanceof w&&n.category==="user"?n.detail:"Something went wrong. Please try again.";s.textContent=x,s.style.display="block"}h.forEach(x=>x(p)),g.disabled=!1,g.textContent="Send feedback"}}function F(){let i=document.createElement("div");i.id="ib-overlay";let o=document.createElement("div");o.id="ib-modal",r.colorScheme==="dark"?o.classList.add("ib-theme-dark"):r.colorScheme==="light"&&o.classList.add("ib-theme-light"),o.setAttribute("role","dialog"),o.setAttribute("aria-modal","true");let f=document.createElement("div");if(f.id="ib-modal-header",k=f,r.title?(o.setAttribute("aria-labelledby","ib-title"),u=document.createElement("h2"),u.id="ib-title",u.className="ib-modal-title",u.textContent=r.title,f.appendChild(u)):o.setAttribute("aria-label","Feedback"),r.showSentiment){let y,E,S=document.createElement("div");S.className="ib-modal-sentiment",y=document.createElement("button"),y.type="button",y.className="ib-modal-thumb ib-modal-thumb--up",y.setAttribute("aria-label","Helpful"),y.appendChild(O(V)),E=document.createElement("button"),E.type="button",E.className="ib-modal-thumb ib-modal-thumb--down",E.setAttribute("aria-label","Not helpful"),E.appendChild(O(q)),y.addEventListener("click",()=>{y.classList.add("ib-modal-thumb--active"),E.classList.remove("ib-modal-thumb--active"),d="positive"}),E.addEventListener("click",()=>{E.classList.add("ib-modal-thumb--active"),y.classList.remove("ib-modal-thumb--active"),d="negative"}),S.appendChild(y),S.appendChild(E),f.appendChild(S)}let n=document.createElement("button");n.id="ib-close",n.className="ib-modal-close",n.textContent="\xD7",n.setAttribute("aria-label","Close feedback form"),n.addEventListener("click",T),f.appendChild(n);let p=document.createElement("div");p.id="ib-modal-body",l=document.createElement("textarea"),l.id="ib-textarea",l.className="ib-modal-textarea",l.placeholder=r.placeholder||"What's on your mind?",l.setAttribute("aria-label","Feedback"),g=document.createElement("button"),g.id="ib-submit",g.className="ib-modal-submit",g.textContent="Send feedback",g.addEventListener("click",W),v=document.createElement("p"),v.id="ib-success",v.className="ib-modal-success",s=document.createElement("p"),s.id="ib-error",s.className="ib-modal-error",r.showTitleField===!0&&(b=document.createElement("input"),b.id="ib-title-input",b.className="ib-modal-title-input",b.type="text",b.placeholder="Title (optional)",b.setAttribute("aria-label","Feedback title"),p.appendChild(b)),p.appendChild(l),r.showEmailField===!0&&(m=document.createElement("input"),m.id="ib-email",m.className="ib-modal-email",m.type="email",m.placeholder="Your email (optional)",m.setAttribute("aria-label","Email address"),p.appendChild(m)),p.appendChild(s),p.appendChild(v);let x=document.createElement("div");x.className="ib-modal-footer",x.appendChild(g);let H=document.createElement("div");H.className="ib-branding";let C=document.createElement("a");return C.href="https://inputbuffer.io",C.target="_blank",C.rel="noopener noreferrer",C.textContent="Powered by inputbuffer.io",H.appendChild(C),x.appendChild(H),p.appendChild(x),o.appendChild(f),o.appendChild(p),i.appendChild(o),i.addEventListener("click",y=>{y.target===i&&T()}),document.addEventListener("keydown",M),i}function R(i){var o,f;if(!e){if(t=i,e=F(),document.body.appendChild(e),B(r),i!=null&&i.title){if(u)u.textContent=i.title;else if(k){let n=e.querySelector("#ib-modal");n.removeAttribute("aria-label"),n.setAttribute("aria-labelledby","ib-title"),u=document.createElement("h2"),u.id="ib-title",u.className="ib-modal-title",u.textContent=i.title,k.prepend(u)}}if(i!=null&&i.sentiment){d=i.sentiment;let n=e.querySelector(".ib-modal-thumb--up"),p=e.querySelector(".ib-modal-thumb--down");i.sentiment==="positive"?n==null||n.classList.add("ib-modal-thumb--active"):i.sentiment==="negative"&&(p==null||p.classList.add("ib-modal-thumb--active"))}l&&((o=i==null?void 0:i.prefill)!=null&&o.description)&&(l.value=i.prefill.description),m&&((f=i==null?void 0:i.prefill)!=null&&f.email)&&(m.value=i.prefill.email),l==null||l.focus()}}function T(){e&&(c!==null&&(clearTimeout(c),c=null),document.removeEventListener("keydown",M),e.remove(),e=null,l=null,b=null,m=null,g=null,s=null,v=null,u=null,k=null,t=void 0,d=void 0,A.forEach(i=>i()))}function _(i,o){i==="submit"?L.push(o):i==="close"?A.push(o):i==="error"&&h.push(o)}function U(){T()}return{open:R,close:T,on:_,destroy:U}}var z=`/* InputBuffer Modal Styles
2
2
  * All #ib-* IDs are stable public API \u2014 do not rename them.
3
3
  * Developers may target these IDs from their own stylesheets to customize the widget.
4
4
  */
@@ -306,4 +306,4 @@
306
306
  --ib-radius: 8px;
307
307
  --ib-radius-input: 4px;
308
308
  }
309
- `;var r=document.currentScript;function G(){if(document.getElementById("ib-modal-styles"))return;let a=document.createElement("style");a.id="ib-modal-styles",a.textContent=O,document.head.appendChild(a)}function P(a){a.injectStyles!==!1&&G();let i=S(a),e=null,b=null;return a.attachTo&&(e=document.querySelector(a.attachTo),e&&(b=()=>i.open(),e.addEventListener("click",b))),{open:n=>i.open(n),close:()=>i.close(),on:(n,s)=>i.on(n,s),destroy:()=>{e&&b&&(e.removeEventListener("click",b),e=null,b=null),i.destroy()}}}var j={createModal:P,version:L};window.InputBufferIO=j;(function(){let i=r==null?void 0:r.dataset.apiKey;if(!i)return;let e=r==null?void 0:r.dataset.injectStyles,b=P({apiKey:i,apiUrl:r==null?void 0:r.dataset.apiUrl,attachTo:r==null?void 0:r.dataset.attachTo,injectStyles:e===void 0?!0:e!=="false",theme:{primary:r==null?void 0:r.dataset.themePrimary,background:r==null?void 0:r.dataset.themeBackground,text:r==null?void 0:r.dataset.themeText,selected:r==null?void 0:r.dataset.themeSelected,selectedColor:r==null?void 0:r.dataset.themeSelectedColor}});j._defaultInstance=b})();})();
309
+ `;var a=document.currentScript;function $(){if(document.getElementById("ib-modal-styles"))return;let r=document.createElement("style");r.id="ib-modal-styles",r.textContent=z,document.head.appendChild(r)}function j(r){r.injectStyles!==!1&&$();let e=N(r),t=null,d=null;return r.attachTo&&(t=document.querySelector(r.attachTo),t&&(d=()=>e.open(),t.addEventListener("click",d))),{open:c=>e.open(c),close:()=>e.close(),on:(c,l)=>e.on(c,l),destroy:()=>{t&&d&&(t.removeEventListener("click",d),t=null,d=null),e.destroy()}}}var D={createModal:j,version:I};window.InputBufferIO=D;(function(){let e=a==null?void 0:a.dataset.apiKey;if(!e)return;let t=a==null?void 0:a.dataset.injectStyles,d=j({apiKey:e,apiUrl:a==null?void 0:a.dataset.apiUrl,attachTo:a==null?void 0:a.dataset.attachTo,injectStyles:t===void 0?!0:t!=="false",theme:{primary:a==null?void 0:a.dataset.themePrimary,background:a==null?void 0:a.dataset.themeBackground,text:a==null?void 0:a.dataset.themeText,selected:a==null?void 0:a.dataset.themeSelected,selectedColor:a==null?void 0:a.dataset.themeSelectedColor}});D._defaultInstance=d})();})();
package/dist/types.d.ts CHANGED
@@ -1,32 +1,43 @@
1
- interface BaseTargetSpec {
2
- targetId?: string;
3
- displayName?: string;
4
- dedupKey?: string;
1
+ export interface ProblemDetails {
2
+ type: string;
3
+ title: string;
4
+ detail: string;
5
+ status: number;
6
+ category?: 'config' | 'user';
7
+ field?: string;
5
8
  }
6
- export interface RestEndpointTarget extends BaseTargetSpec {
9
+ export declare class ApiError extends Error {
10
+ type: string;
11
+ status: number;
12
+ detail: string;
13
+ category?: 'config' | 'user';
14
+ field?: string;
15
+ constructor(problem: ProblemDetails);
16
+ }
17
+ export interface RestEndpointTarget {
7
18
  type: 'rest_endpoint';
8
19
  metadata?: {
9
- method?: string;
10
- path?: string;
20
+ method: string;
21
+ path: string;
11
22
  host?: string;
12
23
  api_version?: string;
13
24
  };
14
25
  }
15
- export interface DocumentationTarget extends BaseTargetSpec {
26
+ export interface DocumentationTarget {
16
27
  type: 'documentation';
17
28
  metadata?: {
18
- page_url?: string;
19
- page_slug?: string;
29
+ page_url: string;
20
30
  section_heading?: string;
21
31
  doc_version?: string;
22
32
  };
23
33
  }
24
- export interface CliCommandTarget extends BaseTargetSpec {
34
+ export interface CliCommandTarget {
25
35
  type: 'cli_command';
26
36
  metadata?: {
27
- command?: string;
37
+ command: string;
28
38
  subcommand?: string;
29
39
  cli_version?: string;
40
+ args?: string[];
30
41
  };
31
42
  }
32
43
  export type TargetSpec = RestEndpointTarget | DocumentationTarget | CliCommandTarget;
@@ -55,6 +66,7 @@ export interface FeedbackBarConfig {
55
66
  showTitleField?: boolean;
56
67
  injectStyles?: boolean;
57
68
  source?: string;
69
+ userId?: string;
58
70
  }
59
71
  export interface FeedbackBarInstance {
60
72
  element: HTMLElement;
@@ -97,4 +109,3 @@ export interface WidgetInstance {
97
109
  }) => void) | (() => void) | ((err: Error) => void)): void;
98
110
  destroy(): void;
99
111
  }
100
- export {};
@@ -1,4 +1,4 @@
1
- function K(e){let t=document.getElementById("ib-modal");if(!t)return;let{theme:i={}}=e;i.primary&&t.style.setProperty("--ib-primary",i.primary),i.background&&t.style.setProperty("--ib-background",i.background),i.surface&&t.style.setProperty("--ib-surface",i.surface),i.text&&t.style.setProperty("--ib-text",i.text),i.selected&&t.style.setProperty("--ib-selected",i.selected),i.selectedColor&&t.style.setProperty("--ib-selected-color",i.selectedColor)}var D="0.1.1",Q="https://inputbuffer.io/api/v0/inputs";async function W(e,t,i,d,o,m){var y;let l={description:t};if(d&&(l.title=d),i&&(l.contactEmail=i),o!=null&&o.sentiment&&(l.sentiment=o.sentiment),o!=null&&o.source&&(l.source=o.source),o!=null&&o.target){let n=o.target;l.targets=[{target_type:n.type,...n.targetId&&{target_id:n.targetId},...n.displayName&&{display_name:n.displayName},...n.dedupKey&&{dedup_key:n.dedupKey},metadata:n.metadata}]}let c=new AbortController,h=setTimeout(()=>c.abort(),1e4),u;try{u=await fetch(m!=null?m:Q,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${D} (javascript)`},body:JSON.stringify(l),credentials:"omit",signal:c.signal})}finally{clearTimeout(h)}if(!u.ok){let n=await u.json().catch(()=>({}));throw new Error(((y=n==null?void 0:n.error)==null?void 0:y.message)||"Submission failed. Please try again.")}return u.json()}function U(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var Z="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ee="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function _(e){let t=null,i,d,o=null,m=null,l=null,c=null,h=null,u=null,y=null,n=null,x=null,f=[],S=[],C=[];function A(r){if(r.key==="Escape"){L();return}if(r.key==="Tab"&&t){let s=Array.from(t.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(s.length===0)return;let v=s[0],p=s[s.length-1];r.shiftKey?document.activeElement===v&&(r.preventDefault(),p.focus()):document.activeElement===p&&(r.preventDefault(),v.focus())}}async function H(){var s,v;if(!m||!h)return;let r=m.value.trim();if(r.length<10){u&&(u.textContent="Please enter at least 10 characters.",u.style.display="block");return}u&&(u.style.display="none"),h.disabled=!0,h.textContent="Sending\u2026";try{let p=(c==null?void 0:c.value.trim())||((s=i==null?void 0:i.prefill)==null?void 0:s.email)||null,g=(l==null?void 0:l.value.trim())||null,B=d!=null?d:i==null?void 0:i.sentiment,N=await W(e.apiKey,r,p||null,g,{...i,sentiment:B,source:(v=i==null?void 0:i.source)!=null?v:e.source},e.apiUrl);y&&(y.textContent="Thanks for your feedback!",y.style.display="block"),f.forEach(T=>T(N)),o=setTimeout(()=>L(),2e3)}catch(p){let g=p instanceof Error?p:new Error("Unknown error");u&&(u.textContent="Something went wrong. Please try again.",u.style.display="block"),C.forEach(B=>B(g)),h.disabled=!1,h.textContent="Send feedback"}}function F(){let r=document.createElement("div");r.id="ib-overlay";let s=document.createElement("div");s.id="ib-modal",e.colorScheme==="dark"?s.classList.add("ib-theme-dark"):e.colorScheme==="light"&&s.classList.add("ib-theme-light"),s.setAttribute("role","dialog"),s.setAttribute("aria-modal","true");let v=document.createElement("div");if(v.id="ib-modal-header",x=v,e.title?(s.setAttribute("aria-labelledby","ib-title"),n=document.createElement("h2"),n.id="ib-title",n.className="ib-modal-title",n.textContent=e.title,v.appendChild(n)):s.setAttribute("aria-label","Feedback"),e.showSentiment){let k,w,a=document.createElement("div");a.className="ib-modal-sentiment",k=document.createElement("button"),k.type="button",k.className="ib-modal-thumb ib-modal-thumb--up",k.setAttribute("aria-label","Helpful"),k.appendChild(U(Z)),w=document.createElement("button"),w.type="button",w.className="ib-modal-thumb ib-modal-thumb--down",w.setAttribute("aria-label","Not helpful"),w.appendChild(U(ee)),k.addEventListener("click",()=>{k.classList.add("ib-modal-thumb--active"),w.classList.remove("ib-modal-thumb--active"),d="positive"}),w.addEventListener("click",()=>{w.classList.add("ib-modal-thumb--active"),k.classList.remove("ib-modal-thumb--active"),d="negative"}),a.appendChild(k),a.appendChild(w),v.appendChild(a)}let p=document.createElement("button");p.id="ib-close",p.className="ib-modal-close",p.textContent="\xD7",p.setAttribute("aria-label","Close feedback form"),p.addEventListener("click",L),v.appendChild(p);let g=document.createElement("div");g.id="ib-modal-body",m=document.createElement("textarea"),m.id="ib-textarea",m.className="ib-modal-textarea",m.placeholder=e.placeholder||"What's on your mind?",m.setAttribute("aria-label","Feedback"),h=document.createElement("button"),h.id="ib-submit",h.className="ib-modal-submit",h.textContent="Send feedback",h.addEventListener("click",H),y=document.createElement("p"),y.id="ib-success",y.className="ib-modal-success",u=document.createElement("p"),u.id="ib-error",u.className="ib-modal-error",e.showTitleField===!0&&(l=document.createElement("input"),l.id="ib-title-input",l.className="ib-modal-title-input",l.type="text",l.placeholder="Title (optional)",l.setAttribute("aria-label","Feedback title"),g.appendChild(l)),g.appendChild(m),e.showEmailField===!0&&(c=document.createElement("input"),c.id="ib-email",c.className="ib-modal-email",c.type="email",c.placeholder="Your email (optional)",c.setAttribute("aria-label","Email address"),g.appendChild(c)),g.appendChild(u),g.appendChild(y);let B=document.createElement("div");B.className="ib-modal-footer",B.appendChild(h);let N=document.createElement("div");N.className="ib-branding";let T=document.createElement("a");return T.href="https://inputbuffer.io",T.target="_blank",T.rel="noopener noreferrer",T.textContent="Powered by inputbuffer.io",N.appendChild(T),B.appendChild(N),g.appendChild(B),s.appendChild(v),s.appendChild(g),r.appendChild(s),r.addEventListener("click",k=>{k.target===r&&L()}),document.addEventListener("keydown",A),r}function E(r){var s,v;if(!t){if(i=r,t=F(),document.body.appendChild(t),K(e),r!=null&&r.title){if(n)n.textContent=r.title;else if(x){let p=t.querySelector("#ib-modal");p.removeAttribute("aria-label"),p.setAttribute("aria-labelledby","ib-title"),n=document.createElement("h2"),n.id="ib-title",n.className="ib-modal-title",n.textContent=r.title,x.prepend(n)}}if(r!=null&&r.sentiment){d=r.sentiment;let p=t.querySelector(".ib-modal-thumb--up"),g=t.querySelector(".ib-modal-thumb--down");r.sentiment==="positive"?p==null||p.classList.add("ib-modal-thumb--active"):r.sentiment==="negative"&&(g==null||g.classList.add("ib-modal-thumb--active"))}m&&((s=r==null?void 0:r.prefill)!=null&&s.description)&&(m.value=r.prefill.description),c&&((v=r==null?void 0:r.prefill)!=null&&v.email)&&(c.value=r.prefill.email),m==null||m.focus()}}function L(){t&&(o!==null&&(clearTimeout(o),o=null),document.removeEventListener("keydown",A),t.remove(),t=null,m=null,l=null,c=null,h=null,u=null,y=null,n=null,x=null,i=void 0,d=void 0,S.forEach(r=>r()))}function O(r,s){r==="submit"?f.push(s):r==="close"?S.push(s):r==="error"&&C.push(s)}function I(){L()}return{open:E,close:L,on:O,destroy:I}}function V(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var te="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ie="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function R(e){var k,w;let t,i={vote:[],open:[],submit:[],close:[],error:[]};function d(a,M){var z;(z=i[a])==null||z.forEach(j=>j(M))}let o=document.createElement("div"),m=e.colorScheme==="dark"?" ib-theme-dark":e.colorScheme==="light"?" ib-theme-light":"";o.className="ib-bar-wrapper"+(e.placement==="fixed"?" ib-bar-wrapper--fixed":"")+m;let{theme:l={}}=e;l.primary&&o.style.setProperty("--ib-primary",l.primary),l.background&&o.style.setProperty("--ib-background",l.background),l.surface&&o.style.setProperty("--ib-surface",l.surface),l.text&&o.style.setProperty("--ib-text",l.text),l.selected&&o.style.setProperty("--ib-selected",l.selected),l.selectedColor&&o.style.setProperty("--ib-selected-color",l.selectedColor);let c=document.createElement("div");c.className="ib-bar";let h=document.createElement("div");h.className="ib-bar-label-area";let u=document.createElement("span");u.className="ib-bar-label",u.textContent=(k=e.label)!=null?k:"Was this helpful?",h.appendChild(u);let y=document.createElement("div");y.className="ib-bar-actions"+(e.showLabel===!1?" ib-bar-actions--no-label":"");let n=document.createElement("button");n.type="button",n.className="ib-bar-btn ib-bar-btn--up",n.setAttribute("aria-label","Yes"),n.appendChild(V(te));let x=document.createElement("button");x.type="button",x.className="ib-bar-btn ib-bar-btn--down",x.setAttribute("aria-label","No"),x.appendChild(V(ie)),y.appendChild(n),y.appendChild(x),e.showLabel!==!1&&c.appendChild(h),c.appendChild(y);let f=document.createElement("div");f.className="ib-bar-popover",f.setAttribute("role","dialog"),f.setAttribute("aria-modal","false");let S=document.createElement("div");if(S.className="ib-bar-header",e.modalTitle){f.setAttribute("aria-labelledby","ib-bar-title");let a=document.createElement("p");a.id="ib-bar-title",a.className="ib-bar-title",a.textContent=e.modalTitle,S.appendChild(a)}else f.setAttribute("aria-label","Feedback");let C=document.createElement("div");C.className="ib-bar-body";let A=document.createElement("textarea");A.className="ib-bar-textarea",A.placeholder=(w=e.modalPlaceholder)!=null?w:"What's on your mind?",A.setAttribute("aria-label","Feedback");let H=document.createElement("p");H.className="ib-bar-error";let F=document.createElement("p");F.className="ib-bar-success";let E=document.createElement("button");if(E.type="button",E.className="ib-bar-submit",E.textContent="Send feedback",e.showTitleField===!0){let a=document.createElement("input");a.type="text",a.className="ib-bar-title-input",a.placeholder="Title (optional)",a.setAttribute("aria-label","Feedback title"),C.appendChild(a)}if(C.appendChild(A),e.showEmailField===!0){let a=document.createElement("input");a.type="email",a.className="ib-bar-email",a.placeholder="Your email (optional)",a.setAttribute("aria-label","Email address"),C.appendChild(a)}C.appendChild(H),C.appendChild(F);let L=document.createElement("div");L.className="ib-bar-footer",L.appendChild(E);let O=document.createElement("div");O.className="ib-branding";let I=document.createElement("a");I.href="https://inputbuffer.io",I.target="_blank",I.rel="noopener noreferrer",I.textContent="Powered by inputbuffer.io",O.appendChild(I),L.appendChild(O),C.appendChild(L),f.appendChild(S),f.appendChild(C),o.appendChild(f),o.appendChild(c);function r(){let a=c.getBoundingClientRect();f.style.top=`${a.top-f.offsetHeight-8}px`,f.style.left=`${a.right-320}px`}function s(a){t=a,f.classList.add("ib-bar-popover--visible"),requestAnimationFrame(r),H.textContent="",F.textContent="",A.focus(),setTimeout(()=>document.addEventListener("click",g),0),document.addEventListener("keydown",B),window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r,{passive:!0}),d("open",{sentiment:a})}function v(){f.classList.contains("ib-bar-popover--visible")&&(f.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",g),document.removeEventListener("keydown",B),window.removeEventListener("scroll",r),window.removeEventListener("resize",r),A.value="",d("close"))}function p(){n.classList.remove("ib-bar-btn--active"),x.classList.remove("ib-bar-btn--active"),t=void 0}function g(a){o.contains(a.target)||v()}function B(a){a.key==="Escape"&&v()}async function N(){let a=A.value.trim();if(a.length<10){H.textContent="Please enter at least 10 characters.";return}H.textContent="",E.disabled=!0,E.textContent="Sending\u2026";let M=f.querySelector(".ib-bar-title-input"),z=(M==null?void 0:M.value.trim())||null,j=f.querySelector(".ib-bar-email"),X=(j==null?void 0:j.value.trim())||null;try{let P=await W(e.apiKey,a,X,z,{sentiment:t,target:e.target,source:e.source},e.apiUrl);d("submit",P),F.textContent="Thanks for your feedback!",E.textContent="Send feedback",setTimeout(()=>{v(),p()},2e3)}catch(P){d("error",P instanceof Error?P:new Error("Something went wrong.")),H.textContent=P instanceof Error?P.message:"Something went wrong.",E.disabled=!1,E.textContent="Send feedback"}}function T(a){n.classList.remove("ib-bar-btn--active"),x.classList.remove("ib-bar-btn--active"),a.classList.add("ib-bar-btn--active")}return n.addEventListener("click",()=>{d("vote",{sentiment:"positive"}),T(n),s("positive")}),x.addEventListener("click",()=>{d("vote",{sentiment:"negative"}),T(x),s("negative")}),E.addEventListener("click",N),{element:o,on(a,M){var z;(z=i[a])==null||z.push(M)},destroy(){v(),o.remove()}}}var q=`/* InputBuffer Modal Styles
1
+ var z=class extends Error{constructor(t){super(t.detail),this.name="ApiError",this.type=t.type,this.status=t.status,this.detail=t.detail,this.category=t.category,this.field=t.field}};function G(e){let t=document.getElementById("ib-modal");if(!t)return;let{theme:i={}}=e;i.primary&&t.style.setProperty("--ib-primary",i.primary),i.background&&t.style.setProperty("--ib-background",i.background),i.surface&&t.style.setProperty("--ib-surface",i.surface),i.text&&t.style.setProperty("--ib-text",i.text),i.selected&&t.style.setProperty("--ib-selected",i.selected),i.selectedColor&&t.style.setProperty("--ib-selected-color",i.selectedColor)}var W="0.2.0",ne="https://inputbuffer.io/api/v0/inputs";async function _(e,t,i,d,u,m){var p,k,w,f;let c={description:t};if(d&&(c.title=d),i&&(c.contact_email=i),u!=null&&u.source&&(c.source=u.source),u!=null&&u.target){let h=u.target;c.targets=[{type:h.type,metadata:h.metadata}]}let n=new AbortController,y=setTimeout(()=>n.abort(),1e4),o;try{o=await fetch(m!=null?m:ne,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${W} (javascript)`},body:JSON.stringify(c),credentials:"omit",signal:n.signal})}finally{clearTimeout(y)}if(!o.ok){let h=await o.json().catch(()=>({}));throw new z({type:(p=h.type)!=null?p:"https://inputbuffer.io/problems/internal-error",title:(k=h.title)!=null?k:"Error",detail:(w=h.detail)!=null?w:"Submission failed. Please try again.",status:(f=h.status)!=null?f:o.status,category:h.category,field:h.field})}let{data:g}=await o.json();return{id:g.id}}var le="https://inputbuffer.io/api/v0/reactions";async function J(e,t,i,d,u){var g,p,k,w;let m=u?u.replace(/\/inputs$/,"/reactions"):le,c={reaction_value:t,target:{type:i.type,metadata:i.metadata}};d&&(c.user_id=d);let n=new AbortController,y=setTimeout(()=>n.abort(),1e4),o;try{o=await fetch(m,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${W} (javascript)`},body:JSON.stringify(c),credentials:"omit",signal:n.signal})}finally{clearTimeout(y)}if(!o.ok){let f=await o.json().catch(()=>({}));throw new z({type:(g=f.type)!=null?g:"https://inputbuffer.io/problems/internal-error",title:(p=f.title)!=null?p:"Error",detail:(k=f.detail)!=null?k:"Submission failed. Please try again.",status:(w=f.status)!=null?w:o.status,category:f.category,field:f.field})}}function Y(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var se="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",de="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function X(e){let t=null,i,d,u=null,m=null,c=null,n=null,y=null,o=null,g=null,p=null,k=null,w=[],f=[],h=[];function v(a){if(a.key==="Escape"){C();return}if(a.key==="Tab"&&t){let b=Array.from(t.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(b.length===0)return;let x=b[0],l=b[b.length-1];a.shiftKey?document.activeElement===x&&(a.preventDefault(),l.focus()):document.activeElement===l&&(a.preventDefault(),x.focus())}}async function P(){var b,x;if(!m||!y)return;let a=m.value.trim();if(a.length<10){o&&(o.textContent="Please enter at least 10 characters.",o.style.display="block");return}o&&(o.style.display="none"),y.disabled=!0,y.textContent="Sending\u2026";try{let l=(n==null?void 0:n.value.trim())||((b=i==null?void 0:i.prefill)==null?void 0:b.email)||null,E=(c==null?void 0:c.value.trim())||null,T=d!=null?d:i==null?void 0:i.sentiment,O=await _(e.apiKey,a,l||null,E,{...i,sentiment:T,source:(x=i==null?void 0:i.source)!=null?x:e.source},e.apiUrl);g&&(g.textContent="Thanks for your feedback!",g.style.display="block"),w.forEach(M=>M(O)),u=setTimeout(()=>C(),2e3)}catch(l){let E=l instanceof Error?l:new Error("Unknown error");if(o){let T=l instanceof z&&l.category==="user"?l.detail:"Something went wrong. Please try again.";o.textContent=T,o.style.display="block"}h.forEach(T=>T(E)),y.disabled=!1,y.textContent="Send feedback"}}function L(){let a=document.createElement("div");a.id="ib-overlay";let b=document.createElement("div");b.id="ib-modal",e.colorScheme==="dark"?b.classList.add("ib-theme-dark"):e.colorScheme==="light"&&b.classList.add("ib-theme-light"),b.setAttribute("role","dialog"),b.setAttribute("aria-modal","true");let x=document.createElement("div");if(x.id="ib-modal-header",k=x,e.title?(b.setAttribute("aria-labelledby","ib-title"),p=document.createElement("h2"),p.id="ib-title",p.className="ib-modal-title",p.textContent=e.title,x.appendChild(p)):b.setAttribute("aria-label","Feedback"),e.showSentiment){let A,H,j=document.createElement("div");j.className="ib-modal-sentiment",A=document.createElement("button"),A.type="button",A.className="ib-modal-thumb ib-modal-thumb--up",A.setAttribute("aria-label","Helpful"),A.appendChild(Y(se)),H=document.createElement("button"),H.type="button",H.className="ib-modal-thumb ib-modal-thumb--down",H.setAttribute("aria-label","Not helpful"),H.appendChild(Y(de)),A.addEventListener("click",()=>{A.classList.add("ib-modal-thumb--active"),H.classList.remove("ib-modal-thumb--active"),d="positive"}),H.addEventListener("click",()=>{H.classList.add("ib-modal-thumb--active"),A.classList.remove("ib-modal-thumb--active"),d="negative"}),j.appendChild(A),j.appendChild(H),x.appendChild(j)}let l=document.createElement("button");l.id="ib-close",l.className="ib-modal-close",l.textContent="\xD7",l.setAttribute("aria-label","Close feedback form"),l.addEventListener("click",C),x.appendChild(l);let E=document.createElement("div");E.id="ib-modal-body",m=document.createElement("textarea"),m.id="ib-textarea",m.className="ib-modal-textarea",m.placeholder=e.placeholder||"What's on your mind?",m.setAttribute("aria-label","Feedback"),y=document.createElement("button"),y.id="ib-submit",y.className="ib-modal-submit",y.textContent="Send feedback",y.addEventListener("click",P),g=document.createElement("p"),g.id="ib-success",g.className="ib-modal-success",o=document.createElement("p"),o.id="ib-error",o.className="ib-modal-error",e.showTitleField===!0&&(c=document.createElement("input"),c.id="ib-title-input",c.className="ib-modal-title-input",c.type="text",c.placeholder="Title (optional)",c.setAttribute("aria-label","Feedback title"),E.appendChild(c)),E.appendChild(m),e.showEmailField===!0&&(n=document.createElement("input"),n.id="ib-email",n.className="ib-modal-email",n.type="email",n.placeholder="Your email (optional)",n.setAttribute("aria-label","Email address"),E.appendChild(n)),E.appendChild(o),E.appendChild(g);let T=document.createElement("div");T.className="ib-modal-footer",T.appendChild(y);let O=document.createElement("div");O.className="ib-branding";let M=document.createElement("a");return M.href="https://inputbuffer.io",M.target="_blank",M.rel="noopener noreferrer",M.textContent="Powered by inputbuffer.io",O.appendChild(M),T.appendChild(O),E.appendChild(T),b.appendChild(x),b.appendChild(E),a.appendChild(b),a.addEventListener("click",A=>{A.target===a&&C()}),document.addEventListener("keydown",v),a}function B(a){var b,x;if(!t){if(i=a,t=L(),document.body.appendChild(t),G(e),a!=null&&a.title){if(p)p.textContent=a.title;else if(k){let l=t.querySelector("#ib-modal");l.removeAttribute("aria-label"),l.setAttribute("aria-labelledby","ib-title"),p=document.createElement("h2"),p.id="ib-title",p.className="ib-modal-title",p.textContent=a.title,k.prepend(p)}}if(a!=null&&a.sentiment){d=a.sentiment;let l=t.querySelector(".ib-modal-thumb--up"),E=t.querySelector(".ib-modal-thumb--down");a.sentiment==="positive"?l==null||l.classList.add("ib-modal-thumb--active"):a.sentiment==="negative"&&(E==null||E.classList.add("ib-modal-thumb--active"))}m&&((b=a==null?void 0:a.prefill)!=null&&b.description)&&(m.value=a.prefill.description),n&&((x=a==null?void 0:a.prefill)!=null&&x.email)&&(n.value=a.prefill.email),m==null||m.focus()}}function C(){t&&(u!==null&&(clearTimeout(u),u=null),document.removeEventListener("keydown",v),t.remove(),t=null,m=null,c=null,n=null,y=null,o=null,g=null,p=null,k=null,i=void 0,d=void 0,f.forEach(a=>a()))}function F(a,b){a==="submit"?w.push(b):a==="close"?f.push(b):a==="error"&&h.push(b)}function S(){C()}return{open:B,close:C,on:F,destroy:S}}function Q(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var be="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ce="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z",ue=24*60*60*1e3;function U(e){var V,q;let t;function i(){let r=e.target;return r?`ib:reaction:${e.apiKey}:${r.type}:${JSON.stringify(r.metadata)}`:`ib:reaction:${e.apiKey}:${window.location.pathname}`}function d(){try{let r=localStorage.getItem(i());if(!r)return null;let{sentiment:N,ts:I}=JSON.parse(r);return Date.now()-I>ue?(localStorage.removeItem(i()),null):N}catch{return null}}function u(r){try{localStorage.setItem(i(),JSON.stringify({sentiment:r,ts:Date.now()}))}catch{}}let m={vote:[],open:[],submit:[],close:[],error:[]};function c(r,N){var I;(I=m[r])==null||I.forEach(R=>R(N))}let n=document.createElement("div"),y=e.colorScheme==="dark"?" ib-theme-dark":e.colorScheme==="light"?" ib-theme-light":"";n.className="ib-bar-wrapper"+(e.placement==="fixed"?" ib-bar-wrapper--fixed":"")+y;let{theme:o={}}=e;o.primary&&n.style.setProperty("--ib-primary",o.primary),o.background&&n.style.setProperty("--ib-background",o.background),o.surface&&n.style.setProperty("--ib-surface",o.surface),o.text&&n.style.setProperty("--ib-text",o.text),o.selected&&n.style.setProperty("--ib-selected",o.selected),o.selectedColor&&n.style.setProperty("--ib-selected-color",o.selectedColor);let g=document.createElement("div");g.className="ib-bar";let p=document.createElement("div");p.className="ib-bar-label-area";let k=document.createElement("span");k.className="ib-bar-label",k.textContent=(V=e.label)!=null?V:"Was this helpful?",p.appendChild(k);let w=document.createElement("div");w.className="ib-bar-actions"+(e.showLabel===!1?" ib-bar-actions--no-label":"");let f=document.createElement("button");f.type="button",f.className="ib-bar-btn ib-bar-btn--up",f.setAttribute("aria-label","Yes"),f.appendChild(Q(be));let h=document.createElement("button");h.type="button",h.className="ib-bar-btn ib-bar-btn--down",h.setAttribute("aria-label","No"),h.appendChild(Q(ce)),w.appendChild(f),w.appendChild(h),e.showLabel!==!1&&g.appendChild(p),g.appendChild(w);let v=document.createElement("div");v.className="ib-bar-popover",v.setAttribute("role","dialog"),v.setAttribute("aria-modal","false");let P=document.createElement("div");if(P.className="ib-bar-header",e.modalTitle){v.setAttribute("aria-labelledby","ib-bar-title");let r=document.createElement("p");r.id="ib-bar-title",r.className="ib-bar-title",r.textContent=e.modalTitle,P.appendChild(r)}else v.setAttribute("aria-label","Feedback");let L=document.createElement("div");L.className="ib-bar-body";let B=document.createElement("textarea");B.className="ib-bar-textarea",B.placeholder=(q=e.modalPlaceholder)!=null?q:"What's on your mind?",B.setAttribute("aria-label","Feedback");let C=document.createElement("p");C.className="ib-bar-error";let F=document.createElement("p");F.className="ib-bar-success";let S=document.createElement("button");if(S.type="button",S.className="ib-bar-submit",S.textContent="Send feedback",e.showTitleField===!0){let r=document.createElement("input");r.type="text",r.className="ib-bar-title-input",r.placeholder="Title (optional)",r.setAttribute("aria-label","Feedback title"),L.appendChild(r)}if(L.appendChild(B),e.showEmailField===!0){let r=document.createElement("input");r.type="email",r.className="ib-bar-email",r.placeholder="Your email (optional)",r.setAttribute("aria-label","Email address"),L.appendChild(r)}L.appendChild(C),L.appendChild(F);let a=document.createElement("div");a.className="ib-bar-footer",a.appendChild(S);let b=document.createElement("div");b.className="ib-branding";let x=document.createElement("a");x.href="https://inputbuffer.io",x.target="_blank",x.rel="noopener noreferrer",x.textContent="Powered by inputbuffer.io",b.appendChild(x),a.appendChild(b),L.appendChild(a),v.appendChild(P),v.appendChild(L),n.appendChild(v),n.appendChild(g);function l(){let r=g.getBoundingClientRect();v.style.top=`${r.top-v.offsetHeight-8}px`,v.style.left=`${r.right-320}px`}function E(r){t=r,v.classList.add("ib-bar-popover--visible"),requestAnimationFrame(l),C.textContent="",F.textContent="",B.focus(),setTimeout(()=>document.addEventListener("click",M),0),document.addEventListener("keydown",A),window.addEventListener("scroll",l,{passive:!0}),window.addEventListener("resize",l,{passive:!0}),c("open",{sentiment:r})}function T(){v.classList.contains("ib-bar-popover--visible")&&(v.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",M),document.removeEventListener("keydown",A),window.removeEventListener("scroll",l),window.removeEventListener("resize",l),B.value="",c("close"))}function O(){f.classList.remove("ib-bar-btn--active"),h.classList.remove("ib-bar-btn--active"),t=void 0}function M(r){n.contains(r.target)||T()}function A(r){r.key==="Escape"&&T()}async function H(){let r=B.value.trim();if(r.length<10){C.textContent="Please enter at least 10 characters.";return}C.textContent="",S.disabled=!0,S.textContent="Sending\u2026";let N=v.querySelector(".ib-bar-title-input"),I=(N==null?void 0:N.value.trim())||null,R=v.querySelector(".ib-bar-email"),ae=(R==null?void 0:R.value.trim())||null;try{let D=await _(e.apiKey,r,ae,I,{sentiment:t,target:e.target,source:e.source},e.apiUrl);c("submit",D),F.textContent="Thanks for your feedback!",S.textContent="Send feedback",setTimeout(()=>{T(),O()},2e3)}catch(D){c("error",D instanceof Error?D:new Error("Something went wrong."));let oe=D instanceof z&&D.category==="user"?D.detail:"Something went wrong. Please try again.";C.textContent=oe,S.disabled=!1,S.textContent="Send feedback"}}function j(r){f.classList.remove("ib-bar-btn--active"),h.classList.remove("ib-bar-btn--active"),r.classList.add("ib-bar-btn--active")}let K=d();K&&(t=K,j(K==="positive"?f:h));function $(r,N){var I;u(r),j(N),E(r),c("vote",{sentiment:r}),e.target&&J(e.apiKey,r==="positive"?1:-1,e.target,(I=e.userId)!=null?I:null,e.apiUrl).catch(()=>{})}return f.addEventListener("click",()=>$("positive",f)),h.addEventListener("click",()=>$("negative",h)),S.addEventListener("click",H),{element:n,on(r,N){var I;(I=m[r])==null||I.push(N)},destroy(){T(),n.remove()}}}var Z=`/* InputBuffer Modal Styles
2
2
  * All #ib-* IDs are stable public API \u2014 do not rename them.
3
3
  * Developers may target these IDs from their own stylesheets to customize the widget.
4
4
  */
@@ -306,7 +306,7 @@ function K(e){let t=document.getElementById("ib-modal");if(!t)return;let{theme:i
306
306
  --ib-radius: 8px;
307
307
  --ib-radius-input: 4px;
308
308
  }
309
- `;var G=`/* InputBuffer Feedback Bar Styles
309
+ `;var ee=`/* InputBuffer Feedback Bar Styles
310
310
  * .ib-bar-* and .ib-bar-popover* classes are stable public API \u2014 do not rename them.
311
311
  * Developers may target these classes from their own stylesheets to customize the widget.
312
312
  */
@@ -627,4 +627,4 @@ function K(e){let t=document.getElementById("ib-modal");if(!t)return;let{theme:i
627
627
  --ib-radius: 8px;
628
628
  --ib-radius-input: 4px;
629
629
  }
630
- `;var b=typeof document!="undefined"?document.currentScript:null;function oe(){if(typeof document=="undefined"||document.getElementById("ib-modal-styles"))return;let e=document.createElement("style");e.id="ib-modal-styles",e.textContent=q,document.head.appendChild(e)}function $(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let e=document.createElement("style");e.id="ib-bar-styles",e.textContent=G,document.head.appendChild(e)}function Y(e){e.injectStyles!==!1&&oe();let t=_(e),i=null,d=null;return e.attachTo&&(i=document.querySelector(e.attachTo),i&&(d=()=>t.open(),i.addEventListener("click",d))),{open:o=>t.open(o),close:()=>t.close(),on:(o,m)=>t.on(o,m),destroy:()=>{i&&d&&(i.removeEventListener("click",d),i=null,d=null),t.destroy()}}}function ne(e){return e.injectStyles!==!1&&$(),R(e)}if(typeof HTMLElement!="undefined"){class e extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var c,h,u,y,n,x,f;let d=this.getAttribute("api-key");if(!d)return;let o=this.getAttribute("inject-styles");(o===null?!0:o!=="false")&&$();let l=this.getAttribute("placement");this._bar=R({apiKey:d,apiUrl:(c=this.getAttribute("api-url"))!=null?c:void 0,label:(h=this.getAttribute("label"))!=null?h:void 0,placement:l==="fixed"?"fixed":"inline",theme:{primary:(u=this.getAttribute("theme-primary"))!=null?u:void 0,background:(y=this.getAttribute("theme-background"))!=null?y:void 0,text:(n=this.getAttribute("theme-text"))!=null?n:void 0,selected:(x=this.getAttribute("theme-selected"))!=null?x:void 0,selectedColor:(f=this.getAttribute("theme-selected-color"))!=null?f:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var d;(d=this._bar)==null||d.destroy(),this._bar=null}}typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",e)}var J={createModal:Y,createBar:ne,version:D};typeof window!="undefined"&&(window.InputBufferIO=J);(function(){if(typeof window=="undefined")return;let t=b==null?void 0:b.dataset.apiKey;if(!t)return;let i=b==null?void 0:b.dataset.injectStyles,d=b==null?void 0:b.dataset.colorScheme,o=Y({apiKey:t,apiUrl:b==null?void 0:b.dataset.apiUrl,attachTo:b==null?void 0:b.dataset.attachTo,injectStyles:i===void 0?!0:i!=="false",colorScheme:d,theme:{primary:b==null?void 0:b.dataset.themePrimary,background:b==null?void 0:b.dataset.themeBackground,text:b==null?void 0:b.dataset.themeText,selected:b==null?void 0:b.dataset.themeSelected,selectedColor:b==null?void 0:b.dataset.themeSelectedColor}});J._defaultInstance=o})();export{J as InputBufferIO};
630
+ `;var s=typeof document!="undefined"?document.currentScript:null;function fe(){if(typeof document=="undefined"||document.getElementById("ib-modal-styles"))return;let e=document.createElement("style");e.id="ib-modal-styles",e.textContent=Z,document.head.appendChild(e)}function te(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let e=document.createElement("style");e.id="ib-bar-styles",e.textContent=ee,document.head.appendChild(e)}function ie(e){e.injectStyles!==!1&&fe();let t=X(e),i=null,d=null;return e.attachTo&&(i=document.querySelector(e.attachTo),i&&(d=()=>t.open(),i.addEventListener("click",d))),{open:u=>t.open(u),close:()=>t.close(),on:(u,m)=>t.on(u,m),destroy:()=>{i&&d&&(i.removeEventListener("click",d),i=null,d=null),t.destroy()}}}function he(e){return e.injectStyles!==!1&&te(),U(e)}if(typeof HTMLElement!="undefined"){class e extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var g,p,k,w,f,h,v,P,L,B,C,F;let d=this.getAttribute("api-key");if(!d)return;let u=this.getAttribute("inject-styles");(u===null?!0:u!=="false")&&te();let c=this.getAttribute("placement"),n=this.getAttribute("show-label"),y=this.getAttribute("show-title-field"),o=this.getAttribute("show-email-field");this._bar=U({apiKey:d,apiUrl:(g=this.getAttribute("api-url"))!=null?g:void 0,label:(p=this.getAttribute("label"))!=null?p:void 0,placement:c==="fixed"?"fixed":"inline",colorScheme:(k=this.getAttribute("color-scheme"))!=null?k:void 0,showLabel:n===null?void 0:n==="true",modalTitle:(w=this.getAttribute("modal-title"))!=null?w:void 0,modalPlaceholder:(f=this.getAttribute("modal-placeholder"))!=null?f:void 0,showTitleField:y===null?void 0:y==="true",showEmailField:o===null?void 0:o==="true",source:(h=this.getAttribute("source"))!=null?h:void 0,userId:(v=this.getAttribute("user-id"))!=null?v:void 0,theme:{primary:(P=this.getAttribute("theme-primary"))!=null?P:void 0,background:(L=this.getAttribute("theme-background"))!=null?L:void 0,text:(B=this.getAttribute("theme-text"))!=null?B:void 0,selected:(C=this.getAttribute("theme-selected"))!=null?C:void 0,selectedColor:(F=this.getAttribute("theme-selected-color"))!=null?F:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var d;(d=this._bar)==null||d.destroy(),this._bar=null}}typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",e)}var re={createModal:ie,createBar:he,version:W};typeof window!="undefined"&&(window.InputBufferIO=re);(function(){if(typeof window=="undefined")return;let t=s==null?void 0:s.dataset.apiKey;if(!t)return;let i=s==null?void 0:s.dataset.injectStyles,d=s==null?void 0:s.dataset.colorScheme,u=ie({apiKey:t,apiUrl:s==null?void 0:s.dataset.apiUrl,attachTo:s==null?void 0:s.dataset.attachTo,injectStyles:i===void 0?!0:i!=="false",colorScheme:d,theme:{primary:s==null?void 0:s.dataset.themePrimary,background:s==null?void 0:s.dataset.themeBackground,text:s==null?void 0:s.dataset.themeText,selected:s==null?void 0:s.dataset.themeSelected,selectedColor:s==null?void 0:s.dataset.themeSelectedColor}});re._defaultInstance=u})();export{re as InputBufferIO};
package/dist/widget.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{function K(e){let t=document.getElementById("ib-modal");if(!t)return;let{theme:i={}}=e;i.primary&&t.style.setProperty("--ib-primary",i.primary),i.background&&t.style.setProperty("--ib-background",i.background),i.surface&&t.style.setProperty("--ib-surface",i.surface),i.text&&t.style.setProperty("--ib-text",i.text),i.selected&&t.style.setProperty("--ib-selected",i.selected),i.selectedColor&&t.style.setProperty("--ib-selected-color",i.selectedColor)}var D="0.1.1",Q="https://inputbuffer.io/api/v0/inputs";async function W(e,t,i,d,o,m){var y;let l={description:t};if(d&&(l.title=d),i&&(l.contactEmail=i),o!=null&&o.sentiment&&(l.sentiment=o.sentiment),o!=null&&o.source&&(l.source=o.source),o!=null&&o.target){let n=o.target;l.targets=[{target_type:n.type,...n.targetId&&{target_id:n.targetId},...n.displayName&&{display_name:n.displayName},...n.dedupKey&&{dedup_key:n.dedupKey},metadata:n.metadata}]}let c=new AbortController,h=setTimeout(()=>c.abort(),1e4),u;try{u=await fetch(m!=null?m:Q,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${D} (javascript)`},body:JSON.stringify(l),credentials:"omit",signal:c.signal})}finally{clearTimeout(h)}if(!u.ok){let n=await u.json().catch(()=>({}));throw new Error(((y=n==null?void 0:n.error)==null?void 0:y.message)||"Submission failed. Please try again.")}return u.json()}function U(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var Z="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ee="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function _(e){let t=null,i,d,o=null,m=null,l=null,c=null,h=null,u=null,y=null,n=null,x=null,f=[],S=[],C=[];function A(r){if(r.key==="Escape"){L();return}if(r.key==="Tab"&&t){let s=Array.from(t.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(s.length===0)return;let v=s[0],p=s[s.length-1];r.shiftKey?document.activeElement===v&&(r.preventDefault(),p.focus()):document.activeElement===p&&(r.preventDefault(),v.focus())}}async function H(){var s,v;if(!m||!h)return;let r=m.value.trim();if(r.length<10){u&&(u.textContent="Please enter at least 10 characters.",u.style.display="block");return}u&&(u.style.display="none"),h.disabled=!0,h.textContent="Sending\u2026";try{let p=(c==null?void 0:c.value.trim())||((s=i==null?void 0:i.prefill)==null?void 0:s.email)||null,g=(l==null?void 0:l.value.trim())||null,B=d!=null?d:i==null?void 0:i.sentiment,N=await W(e.apiKey,r,p||null,g,{...i,sentiment:B,source:(v=i==null?void 0:i.source)!=null?v:e.source},e.apiUrl);y&&(y.textContent="Thanks for your feedback!",y.style.display="block"),f.forEach(T=>T(N)),o=setTimeout(()=>L(),2e3)}catch(p){let g=p instanceof Error?p:new Error("Unknown error");u&&(u.textContent="Something went wrong. Please try again.",u.style.display="block"),C.forEach(B=>B(g)),h.disabled=!1,h.textContent="Send feedback"}}function F(){let r=document.createElement("div");r.id="ib-overlay";let s=document.createElement("div");s.id="ib-modal",e.colorScheme==="dark"?s.classList.add("ib-theme-dark"):e.colorScheme==="light"&&s.classList.add("ib-theme-light"),s.setAttribute("role","dialog"),s.setAttribute("aria-modal","true");let v=document.createElement("div");if(v.id="ib-modal-header",x=v,e.title?(s.setAttribute("aria-labelledby","ib-title"),n=document.createElement("h2"),n.id="ib-title",n.className="ib-modal-title",n.textContent=e.title,v.appendChild(n)):s.setAttribute("aria-label","Feedback"),e.showSentiment){let k,w,a=document.createElement("div");a.className="ib-modal-sentiment",k=document.createElement("button"),k.type="button",k.className="ib-modal-thumb ib-modal-thumb--up",k.setAttribute("aria-label","Helpful"),k.appendChild(U(Z)),w=document.createElement("button"),w.type="button",w.className="ib-modal-thumb ib-modal-thumb--down",w.setAttribute("aria-label","Not helpful"),w.appendChild(U(ee)),k.addEventListener("click",()=>{k.classList.add("ib-modal-thumb--active"),w.classList.remove("ib-modal-thumb--active"),d="positive"}),w.addEventListener("click",()=>{w.classList.add("ib-modal-thumb--active"),k.classList.remove("ib-modal-thumb--active"),d="negative"}),a.appendChild(k),a.appendChild(w),v.appendChild(a)}let p=document.createElement("button");p.id="ib-close",p.className="ib-modal-close",p.textContent="\xD7",p.setAttribute("aria-label","Close feedback form"),p.addEventListener("click",L),v.appendChild(p);let g=document.createElement("div");g.id="ib-modal-body",m=document.createElement("textarea"),m.id="ib-textarea",m.className="ib-modal-textarea",m.placeholder=e.placeholder||"What's on your mind?",m.setAttribute("aria-label","Feedback"),h=document.createElement("button"),h.id="ib-submit",h.className="ib-modal-submit",h.textContent="Send feedback",h.addEventListener("click",H),y=document.createElement("p"),y.id="ib-success",y.className="ib-modal-success",u=document.createElement("p"),u.id="ib-error",u.className="ib-modal-error",e.showTitleField===!0&&(l=document.createElement("input"),l.id="ib-title-input",l.className="ib-modal-title-input",l.type="text",l.placeholder="Title (optional)",l.setAttribute("aria-label","Feedback title"),g.appendChild(l)),g.appendChild(m),e.showEmailField===!0&&(c=document.createElement("input"),c.id="ib-email",c.className="ib-modal-email",c.type="email",c.placeholder="Your email (optional)",c.setAttribute("aria-label","Email address"),g.appendChild(c)),g.appendChild(u),g.appendChild(y);let B=document.createElement("div");B.className="ib-modal-footer",B.appendChild(h);let N=document.createElement("div");N.className="ib-branding";let T=document.createElement("a");return T.href="https://inputbuffer.io",T.target="_blank",T.rel="noopener noreferrer",T.textContent="Powered by inputbuffer.io",N.appendChild(T),B.appendChild(N),g.appendChild(B),s.appendChild(v),s.appendChild(g),r.appendChild(s),r.addEventListener("click",k=>{k.target===r&&L()}),document.addEventListener("keydown",A),r}function E(r){var s,v;if(!t){if(i=r,t=F(),document.body.appendChild(t),K(e),r!=null&&r.title){if(n)n.textContent=r.title;else if(x){let p=t.querySelector("#ib-modal");p.removeAttribute("aria-label"),p.setAttribute("aria-labelledby","ib-title"),n=document.createElement("h2"),n.id="ib-title",n.className="ib-modal-title",n.textContent=r.title,x.prepend(n)}}if(r!=null&&r.sentiment){d=r.sentiment;let p=t.querySelector(".ib-modal-thumb--up"),g=t.querySelector(".ib-modal-thumb--down");r.sentiment==="positive"?p==null||p.classList.add("ib-modal-thumb--active"):r.sentiment==="negative"&&(g==null||g.classList.add("ib-modal-thumb--active"))}m&&((s=r==null?void 0:r.prefill)!=null&&s.description)&&(m.value=r.prefill.description),c&&((v=r==null?void 0:r.prefill)!=null&&v.email)&&(c.value=r.prefill.email),m==null||m.focus()}}function L(){t&&(o!==null&&(clearTimeout(o),o=null),document.removeEventListener("keydown",A),t.remove(),t=null,m=null,l=null,c=null,h=null,u=null,y=null,n=null,x=null,i=void 0,d=void 0,S.forEach(r=>r()))}function O(r,s){r==="submit"?f.push(s):r==="close"?S.push(s):r==="error"&&C.push(s)}function I(){L()}return{open:E,close:L,on:O,destroy:I}}function V(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var te="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ie="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function R(e){var k,w;let t,i={vote:[],open:[],submit:[],close:[],error:[]};function d(a,M){var z;(z=i[a])==null||z.forEach(j=>j(M))}let o=document.createElement("div"),m=e.colorScheme==="dark"?" ib-theme-dark":e.colorScheme==="light"?" ib-theme-light":"";o.className="ib-bar-wrapper"+(e.placement==="fixed"?" ib-bar-wrapper--fixed":"")+m;let{theme:l={}}=e;l.primary&&o.style.setProperty("--ib-primary",l.primary),l.background&&o.style.setProperty("--ib-background",l.background),l.surface&&o.style.setProperty("--ib-surface",l.surface),l.text&&o.style.setProperty("--ib-text",l.text),l.selected&&o.style.setProperty("--ib-selected",l.selected),l.selectedColor&&o.style.setProperty("--ib-selected-color",l.selectedColor);let c=document.createElement("div");c.className="ib-bar";let h=document.createElement("div");h.className="ib-bar-label-area";let u=document.createElement("span");u.className="ib-bar-label",u.textContent=(k=e.label)!=null?k:"Was this helpful?",h.appendChild(u);let y=document.createElement("div");y.className="ib-bar-actions"+(e.showLabel===!1?" ib-bar-actions--no-label":"");let n=document.createElement("button");n.type="button",n.className="ib-bar-btn ib-bar-btn--up",n.setAttribute("aria-label","Yes"),n.appendChild(V(te));let x=document.createElement("button");x.type="button",x.className="ib-bar-btn ib-bar-btn--down",x.setAttribute("aria-label","No"),x.appendChild(V(ie)),y.appendChild(n),y.appendChild(x),e.showLabel!==!1&&c.appendChild(h),c.appendChild(y);let f=document.createElement("div");f.className="ib-bar-popover",f.setAttribute("role","dialog"),f.setAttribute("aria-modal","false");let S=document.createElement("div");if(S.className="ib-bar-header",e.modalTitle){f.setAttribute("aria-labelledby","ib-bar-title");let a=document.createElement("p");a.id="ib-bar-title",a.className="ib-bar-title",a.textContent=e.modalTitle,S.appendChild(a)}else f.setAttribute("aria-label","Feedback");let C=document.createElement("div");C.className="ib-bar-body";let A=document.createElement("textarea");A.className="ib-bar-textarea",A.placeholder=(w=e.modalPlaceholder)!=null?w:"What's on your mind?",A.setAttribute("aria-label","Feedback");let H=document.createElement("p");H.className="ib-bar-error";let F=document.createElement("p");F.className="ib-bar-success";let E=document.createElement("button");if(E.type="button",E.className="ib-bar-submit",E.textContent="Send feedback",e.showTitleField===!0){let a=document.createElement("input");a.type="text",a.className="ib-bar-title-input",a.placeholder="Title (optional)",a.setAttribute("aria-label","Feedback title"),C.appendChild(a)}if(C.appendChild(A),e.showEmailField===!0){let a=document.createElement("input");a.type="email",a.className="ib-bar-email",a.placeholder="Your email (optional)",a.setAttribute("aria-label","Email address"),C.appendChild(a)}C.appendChild(H),C.appendChild(F);let L=document.createElement("div");L.className="ib-bar-footer",L.appendChild(E);let O=document.createElement("div");O.className="ib-branding";let I=document.createElement("a");I.href="https://inputbuffer.io",I.target="_blank",I.rel="noopener noreferrer",I.textContent="Powered by inputbuffer.io",O.appendChild(I),L.appendChild(O),C.appendChild(L),f.appendChild(S),f.appendChild(C),o.appendChild(f),o.appendChild(c);function r(){let a=c.getBoundingClientRect();f.style.top=`${a.top-f.offsetHeight-8}px`,f.style.left=`${a.right-320}px`}function s(a){t=a,f.classList.add("ib-bar-popover--visible"),requestAnimationFrame(r),H.textContent="",F.textContent="",A.focus(),setTimeout(()=>document.addEventListener("click",g),0),document.addEventListener("keydown",B),window.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",r,{passive:!0}),d("open",{sentiment:a})}function v(){f.classList.contains("ib-bar-popover--visible")&&(f.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",g),document.removeEventListener("keydown",B),window.removeEventListener("scroll",r),window.removeEventListener("resize",r),A.value="",d("close"))}function p(){n.classList.remove("ib-bar-btn--active"),x.classList.remove("ib-bar-btn--active"),t=void 0}function g(a){o.contains(a.target)||v()}function B(a){a.key==="Escape"&&v()}async function N(){let a=A.value.trim();if(a.length<10){H.textContent="Please enter at least 10 characters.";return}H.textContent="",E.disabled=!0,E.textContent="Sending\u2026";let M=f.querySelector(".ib-bar-title-input"),z=(M==null?void 0:M.value.trim())||null,j=f.querySelector(".ib-bar-email"),X=(j==null?void 0:j.value.trim())||null;try{let P=await W(e.apiKey,a,X,z,{sentiment:t,target:e.target,source:e.source},e.apiUrl);d("submit",P),F.textContent="Thanks for your feedback!",E.textContent="Send feedback",setTimeout(()=>{v(),p()},2e3)}catch(P){d("error",P instanceof Error?P:new Error("Something went wrong.")),H.textContent=P instanceof Error?P.message:"Something went wrong.",E.disabled=!1,E.textContent="Send feedback"}}function T(a){n.classList.remove("ib-bar-btn--active"),x.classList.remove("ib-bar-btn--active"),a.classList.add("ib-bar-btn--active")}return n.addEventListener("click",()=>{d("vote",{sentiment:"positive"}),T(n),s("positive")}),x.addEventListener("click",()=>{d("vote",{sentiment:"negative"}),T(x),s("negative")}),E.addEventListener("click",N),{element:o,on(a,M){var z;(z=i[a])==null||z.push(M)},destroy(){v(),o.remove()}}}var q=`/* InputBuffer Modal Styles
1
+ "use strict";(()=>{var z=class extends Error{constructor(t){super(t.detail),this.name="ApiError",this.type=t.type,this.status=t.status,this.detail=t.detail,this.category=t.category,this.field=t.field}};function G(e){let t=document.getElementById("ib-modal");if(!t)return;let{theme:i={}}=e;i.primary&&t.style.setProperty("--ib-primary",i.primary),i.background&&t.style.setProperty("--ib-background",i.background),i.surface&&t.style.setProperty("--ib-surface",i.surface),i.text&&t.style.setProperty("--ib-text",i.text),i.selected&&t.style.setProperty("--ib-selected",i.selected),i.selectedColor&&t.style.setProperty("--ib-selected-color",i.selectedColor)}var W="0.2.0",ne="https://inputbuffer.io/api/v0/inputs";async function _(e,t,i,d,u,m){var p,k,w,f;let c={description:t};if(d&&(c.title=d),i&&(c.contact_email=i),u!=null&&u.source&&(c.source=u.source),u!=null&&u.target){let h=u.target;c.targets=[{type:h.type,metadata:h.metadata}]}let n=new AbortController,y=setTimeout(()=>n.abort(),1e4),o;try{o=await fetch(m!=null?m:ne,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${W} (javascript)`},body:JSON.stringify(c),credentials:"omit",signal:n.signal})}finally{clearTimeout(y)}if(!o.ok){let h=await o.json().catch(()=>({}));throw new z({type:(p=h.type)!=null?p:"https://inputbuffer.io/problems/internal-error",title:(k=h.title)!=null?k:"Error",detail:(w=h.detail)!=null?w:"Submission failed. Please try again.",status:(f=h.status)!=null?f:o.status,category:h.category,field:h.field})}let{data:g}=await o.json();return{id:g.id}}var le="https://inputbuffer.io/api/v0/reactions";async function J(e,t,i,d,u){var g,p,k,w;let m=u?u.replace(/\/inputs$/,"/reactions"):le,c={reaction_value:t,target:{type:i.type,metadata:i.metadata}};d&&(c.user_id=d);let n=new AbortController,y=setTimeout(()=>n.abort(),1e4),o;try{o=await fetch(m,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json","X-IB-Client":`inputbuffer-widget/${W} (javascript)`},body:JSON.stringify(c),credentials:"omit",signal:n.signal})}finally{clearTimeout(y)}if(!o.ok){let f=await o.json().catch(()=>({}));throw new z({type:(g=f.type)!=null?g:"https://inputbuffer.io/problems/internal-error",title:(p=f.title)!=null?p:"Error",detail:(k=f.detail)!=null?k:"Submission failed. Please try again.",status:(w=f.status)!=null?w:o.status,category:f.category,field:f.field})}}function Y(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var se="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",de="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z";function X(e){let t=null,i,d,u=null,m=null,c=null,n=null,y=null,o=null,g=null,p=null,k=null,w=[],f=[],h=[];function v(a){if(a.key==="Escape"){C();return}if(a.key==="Tab"&&t){let b=Array.from(t.querySelectorAll('button:not([disabled]), input:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'));if(b.length===0)return;let x=b[0],l=b[b.length-1];a.shiftKey?document.activeElement===x&&(a.preventDefault(),l.focus()):document.activeElement===l&&(a.preventDefault(),x.focus())}}async function P(){var b,x;if(!m||!y)return;let a=m.value.trim();if(a.length<10){o&&(o.textContent="Please enter at least 10 characters.",o.style.display="block");return}o&&(o.style.display="none"),y.disabled=!0,y.textContent="Sending\u2026";try{let l=(n==null?void 0:n.value.trim())||((b=i==null?void 0:i.prefill)==null?void 0:b.email)||null,E=(c==null?void 0:c.value.trim())||null,T=d!=null?d:i==null?void 0:i.sentiment,O=await _(e.apiKey,a,l||null,E,{...i,sentiment:T,source:(x=i==null?void 0:i.source)!=null?x:e.source},e.apiUrl);g&&(g.textContent="Thanks for your feedback!",g.style.display="block"),w.forEach(M=>M(O)),u=setTimeout(()=>C(),2e3)}catch(l){let E=l instanceof Error?l:new Error("Unknown error");if(o){let T=l instanceof z&&l.category==="user"?l.detail:"Something went wrong. Please try again.";o.textContent=T,o.style.display="block"}h.forEach(T=>T(E)),y.disabled=!1,y.textContent="Send feedback"}}function L(){let a=document.createElement("div");a.id="ib-overlay";let b=document.createElement("div");b.id="ib-modal",e.colorScheme==="dark"?b.classList.add("ib-theme-dark"):e.colorScheme==="light"&&b.classList.add("ib-theme-light"),b.setAttribute("role","dialog"),b.setAttribute("aria-modal","true");let x=document.createElement("div");if(x.id="ib-modal-header",k=x,e.title?(b.setAttribute("aria-labelledby","ib-title"),p=document.createElement("h2"),p.id="ib-title",p.className="ib-modal-title",p.textContent=e.title,x.appendChild(p)):b.setAttribute("aria-label","Feedback"),e.showSentiment){let A,H,j=document.createElement("div");j.className="ib-modal-sentiment",A=document.createElement("button"),A.type="button",A.className="ib-modal-thumb ib-modal-thumb--up",A.setAttribute("aria-label","Helpful"),A.appendChild(Y(se)),H=document.createElement("button"),H.type="button",H.className="ib-modal-thumb ib-modal-thumb--down",H.setAttribute("aria-label","Not helpful"),H.appendChild(Y(de)),A.addEventListener("click",()=>{A.classList.add("ib-modal-thumb--active"),H.classList.remove("ib-modal-thumb--active"),d="positive"}),H.addEventListener("click",()=>{H.classList.add("ib-modal-thumb--active"),A.classList.remove("ib-modal-thumb--active"),d="negative"}),j.appendChild(A),j.appendChild(H),x.appendChild(j)}let l=document.createElement("button");l.id="ib-close",l.className="ib-modal-close",l.textContent="\xD7",l.setAttribute("aria-label","Close feedback form"),l.addEventListener("click",C),x.appendChild(l);let E=document.createElement("div");E.id="ib-modal-body",m=document.createElement("textarea"),m.id="ib-textarea",m.className="ib-modal-textarea",m.placeholder=e.placeholder||"What's on your mind?",m.setAttribute("aria-label","Feedback"),y=document.createElement("button"),y.id="ib-submit",y.className="ib-modal-submit",y.textContent="Send feedback",y.addEventListener("click",P),g=document.createElement("p"),g.id="ib-success",g.className="ib-modal-success",o=document.createElement("p"),o.id="ib-error",o.className="ib-modal-error",e.showTitleField===!0&&(c=document.createElement("input"),c.id="ib-title-input",c.className="ib-modal-title-input",c.type="text",c.placeholder="Title (optional)",c.setAttribute("aria-label","Feedback title"),E.appendChild(c)),E.appendChild(m),e.showEmailField===!0&&(n=document.createElement("input"),n.id="ib-email",n.className="ib-modal-email",n.type="email",n.placeholder="Your email (optional)",n.setAttribute("aria-label","Email address"),E.appendChild(n)),E.appendChild(o),E.appendChild(g);let T=document.createElement("div");T.className="ib-modal-footer",T.appendChild(y);let O=document.createElement("div");O.className="ib-branding";let M=document.createElement("a");return M.href="https://inputbuffer.io",M.target="_blank",M.rel="noopener noreferrer",M.textContent="Powered by inputbuffer.io",O.appendChild(M),T.appendChild(O),E.appendChild(T),b.appendChild(x),b.appendChild(E),a.appendChild(b),a.addEventListener("click",A=>{A.target===a&&C()}),document.addEventListener("keydown",v),a}function B(a){var b,x;if(!t){if(i=a,t=L(),document.body.appendChild(t),G(e),a!=null&&a.title){if(p)p.textContent=a.title;else if(k){let l=t.querySelector("#ib-modal");l.removeAttribute("aria-label"),l.setAttribute("aria-labelledby","ib-title"),p=document.createElement("h2"),p.id="ib-title",p.className="ib-modal-title",p.textContent=a.title,k.prepend(p)}}if(a!=null&&a.sentiment){d=a.sentiment;let l=t.querySelector(".ib-modal-thumb--up"),E=t.querySelector(".ib-modal-thumb--down");a.sentiment==="positive"?l==null||l.classList.add("ib-modal-thumb--active"):a.sentiment==="negative"&&(E==null||E.classList.add("ib-modal-thumb--active"))}m&&((b=a==null?void 0:a.prefill)!=null&&b.description)&&(m.value=a.prefill.description),n&&((x=a==null?void 0:a.prefill)!=null&&x.email)&&(n.value=a.prefill.email),m==null||m.focus()}}function C(){t&&(u!==null&&(clearTimeout(u),u=null),document.removeEventListener("keydown",v),t.remove(),t=null,m=null,c=null,n=null,y=null,o=null,g=null,p=null,k=null,i=void 0,d=void 0,f.forEach(a=>a()))}function F(a,b){a==="submit"?w.push(b):a==="close"?f.push(b):a==="error"&&h.push(b)}function S(){C()}return{open:B,close:C,on:F,destroy:S}}function Q(e){let t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("width","18"),t.setAttribute("height","18"),t.setAttribute("fill","currentColor"),t.setAttribute("aria-hidden","true"),t.style.display="block";let i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",e),t.appendChild(i),t}var be="M9 21h9c.83 0 1.54-.5 1.84-1.22l3.02-7.05c.09-.23.14-.47.14-.73v-2c0-1.1-.9-2-2-2h-6.31l.95-4.57.03-.32c0-.41-.17-.79-.44-1.06L14.17 1 7.59 7.59C7.22 7.95 7 8.45 7 9v10c0 1.1.9 2 2 2zM9 9l4.34-4.34L12 10h9v2l-3 7H9V9zM1 9h2v12H1z",ce="M15 3H6c-.83 0-1.54.5-1.84 1.22l-3.02 7.05c-.09.23-.14.47-.14.73v2c0 1.1.9 2 2 2h6.31l-.95 4.57-.03.32c0 .41.17.79.44 1.06L10.83 23l6.59-6.59c.36-.36.58-.86.58-1.41V5c0-1.1-.9-2-2-2zm0 12l-4.34 4.34L12 14H3v-2l3-7h9v10zm4-12h2v12h-2z",ue=24*60*60*1e3;function U(e){var V,q;let t;function i(){let r=e.target;return r?`ib:reaction:${e.apiKey}:${r.type}:${JSON.stringify(r.metadata)}`:`ib:reaction:${e.apiKey}:${window.location.pathname}`}function d(){try{let r=localStorage.getItem(i());if(!r)return null;let{sentiment:N,ts:I}=JSON.parse(r);return Date.now()-I>ue?(localStorage.removeItem(i()),null):N}catch{return null}}function u(r){try{localStorage.setItem(i(),JSON.stringify({sentiment:r,ts:Date.now()}))}catch{}}let m={vote:[],open:[],submit:[],close:[],error:[]};function c(r,N){var I;(I=m[r])==null||I.forEach(R=>R(N))}let n=document.createElement("div"),y=e.colorScheme==="dark"?" ib-theme-dark":e.colorScheme==="light"?" ib-theme-light":"";n.className="ib-bar-wrapper"+(e.placement==="fixed"?" ib-bar-wrapper--fixed":"")+y;let{theme:o={}}=e;o.primary&&n.style.setProperty("--ib-primary",o.primary),o.background&&n.style.setProperty("--ib-background",o.background),o.surface&&n.style.setProperty("--ib-surface",o.surface),o.text&&n.style.setProperty("--ib-text",o.text),o.selected&&n.style.setProperty("--ib-selected",o.selected),o.selectedColor&&n.style.setProperty("--ib-selected-color",o.selectedColor);let g=document.createElement("div");g.className="ib-bar";let p=document.createElement("div");p.className="ib-bar-label-area";let k=document.createElement("span");k.className="ib-bar-label",k.textContent=(V=e.label)!=null?V:"Was this helpful?",p.appendChild(k);let w=document.createElement("div");w.className="ib-bar-actions"+(e.showLabel===!1?" ib-bar-actions--no-label":"");let f=document.createElement("button");f.type="button",f.className="ib-bar-btn ib-bar-btn--up",f.setAttribute("aria-label","Yes"),f.appendChild(Q(be));let h=document.createElement("button");h.type="button",h.className="ib-bar-btn ib-bar-btn--down",h.setAttribute("aria-label","No"),h.appendChild(Q(ce)),w.appendChild(f),w.appendChild(h),e.showLabel!==!1&&g.appendChild(p),g.appendChild(w);let v=document.createElement("div");v.className="ib-bar-popover",v.setAttribute("role","dialog"),v.setAttribute("aria-modal","false");let P=document.createElement("div");if(P.className="ib-bar-header",e.modalTitle){v.setAttribute("aria-labelledby","ib-bar-title");let r=document.createElement("p");r.id="ib-bar-title",r.className="ib-bar-title",r.textContent=e.modalTitle,P.appendChild(r)}else v.setAttribute("aria-label","Feedback");let L=document.createElement("div");L.className="ib-bar-body";let B=document.createElement("textarea");B.className="ib-bar-textarea",B.placeholder=(q=e.modalPlaceholder)!=null?q:"What's on your mind?",B.setAttribute("aria-label","Feedback");let C=document.createElement("p");C.className="ib-bar-error";let F=document.createElement("p");F.className="ib-bar-success";let S=document.createElement("button");if(S.type="button",S.className="ib-bar-submit",S.textContent="Send feedback",e.showTitleField===!0){let r=document.createElement("input");r.type="text",r.className="ib-bar-title-input",r.placeholder="Title (optional)",r.setAttribute("aria-label","Feedback title"),L.appendChild(r)}if(L.appendChild(B),e.showEmailField===!0){let r=document.createElement("input");r.type="email",r.className="ib-bar-email",r.placeholder="Your email (optional)",r.setAttribute("aria-label","Email address"),L.appendChild(r)}L.appendChild(C),L.appendChild(F);let a=document.createElement("div");a.className="ib-bar-footer",a.appendChild(S);let b=document.createElement("div");b.className="ib-branding";let x=document.createElement("a");x.href="https://inputbuffer.io",x.target="_blank",x.rel="noopener noreferrer",x.textContent="Powered by inputbuffer.io",b.appendChild(x),a.appendChild(b),L.appendChild(a),v.appendChild(P),v.appendChild(L),n.appendChild(v),n.appendChild(g);function l(){let r=g.getBoundingClientRect();v.style.top=`${r.top-v.offsetHeight-8}px`,v.style.left=`${r.right-320}px`}function E(r){t=r,v.classList.add("ib-bar-popover--visible"),requestAnimationFrame(l),C.textContent="",F.textContent="",B.focus(),setTimeout(()=>document.addEventListener("click",M),0),document.addEventListener("keydown",A),window.addEventListener("scroll",l,{passive:!0}),window.addEventListener("resize",l,{passive:!0}),c("open",{sentiment:r})}function T(){v.classList.contains("ib-bar-popover--visible")&&(v.classList.remove("ib-bar-popover--visible"),document.removeEventListener("click",M),document.removeEventListener("keydown",A),window.removeEventListener("scroll",l),window.removeEventListener("resize",l),B.value="",c("close"))}function O(){f.classList.remove("ib-bar-btn--active"),h.classList.remove("ib-bar-btn--active"),t=void 0}function M(r){n.contains(r.target)||T()}function A(r){r.key==="Escape"&&T()}async function H(){let r=B.value.trim();if(r.length<10){C.textContent="Please enter at least 10 characters.";return}C.textContent="",S.disabled=!0,S.textContent="Sending\u2026";let N=v.querySelector(".ib-bar-title-input"),I=(N==null?void 0:N.value.trim())||null,R=v.querySelector(".ib-bar-email"),ae=(R==null?void 0:R.value.trim())||null;try{let D=await _(e.apiKey,r,ae,I,{sentiment:t,target:e.target,source:e.source},e.apiUrl);c("submit",D),F.textContent="Thanks for your feedback!",S.textContent="Send feedback",setTimeout(()=>{T(),O()},2e3)}catch(D){c("error",D instanceof Error?D:new Error("Something went wrong."));let oe=D instanceof z&&D.category==="user"?D.detail:"Something went wrong. Please try again.";C.textContent=oe,S.disabled=!1,S.textContent="Send feedback"}}function j(r){f.classList.remove("ib-bar-btn--active"),h.classList.remove("ib-bar-btn--active"),r.classList.add("ib-bar-btn--active")}let K=d();K&&(t=K,j(K==="positive"?f:h));function $(r,N){var I;u(r),j(N),E(r),c("vote",{sentiment:r}),e.target&&J(e.apiKey,r==="positive"?1:-1,e.target,(I=e.userId)!=null?I:null,e.apiUrl).catch(()=>{})}return f.addEventListener("click",()=>$("positive",f)),h.addEventListener("click",()=>$("negative",h)),S.addEventListener("click",H),{element:n,on(r,N){var I;(I=m[r])==null||I.push(N)},destroy(){T(),n.remove()}}}var Z=`/* InputBuffer Modal Styles
2
2
  * All #ib-* IDs are stable public API \u2014 do not rename them.
3
3
  * Developers may target these IDs from their own stylesheets to customize the widget.
4
4
  */
@@ -306,7 +306,7 @@
306
306
  --ib-radius: 8px;
307
307
  --ib-radius-input: 4px;
308
308
  }
309
- `;var G=`/* InputBuffer Feedback Bar Styles
309
+ `;var ee=`/* InputBuffer Feedback Bar Styles
310
310
  * .ib-bar-* and .ib-bar-popover* classes are stable public API \u2014 do not rename them.
311
311
  * Developers may target these classes from their own stylesheets to customize the widget.
312
312
  */
@@ -627,4 +627,4 @@
627
627
  --ib-radius: 8px;
628
628
  --ib-radius-input: 4px;
629
629
  }
630
- `;var b=typeof document!="undefined"?document.currentScript:null;function oe(){if(typeof document=="undefined"||document.getElementById("ib-modal-styles"))return;let e=document.createElement("style");e.id="ib-modal-styles",e.textContent=q,document.head.appendChild(e)}function $(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let e=document.createElement("style");e.id="ib-bar-styles",e.textContent=G,document.head.appendChild(e)}function Y(e){e.injectStyles!==!1&&oe();let t=_(e),i=null,d=null;return e.attachTo&&(i=document.querySelector(e.attachTo),i&&(d=()=>t.open(),i.addEventListener("click",d))),{open:o=>t.open(o),close:()=>t.close(),on:(o,m)=>t.on(o,m),destroy:()=>{i&&d&&(i.removeEventListener("click",d),i=null,d=null),t.destroy()}}}function ne(e){return e.injectStyles!==!1&&$(),R(e)}if(typeof HTMLElement!="undefined"){class e extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var c,h,u,y,n,x,f;let d=this.getAttribute("api-key");if(!d)return;let o=this.getAttribute("inject-styles");(o===null?!0:o!=="false")&&$();let l=this.getAttribute("placement");this._bar=R({apiKey:d,apiUrl:(c=this.getAttribute("api-url"))!=null?c:void 0,label:(h=this.getAttribute("label"))!=null?h:void 0,placement:l==="fixed"?"fixed":"inline",theme:{primary:(u=this.getAttribute("theme-primary"))!=null?u:void 0,background:(y=this.getAttribute("theme-background"))!=null?y:void 0,text:(n=this.getAttribute("theme-text"))!=null?n:void 0,selected:(x=this.getAttribute("theme-selected"))!=null?x:void 0,selectedColor:(f=this.getAttribute("theme-selected-color"))!=null?f:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var d;(d=this._bar)==null||d.destroy(),this._bar=null}}typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",e)}var J={createModal:Y,createBar:ne,version:D};typeof window!="undefined"&&(window.InputBufferIO=J);(function(){if(typeof window=="undefined")return;let t=b==null?void 0:b.dataset.apiKey;if(!t)return;let i=b==null?void 0:b.dataset.injectStyles,d=b==null?void 0:b.dataset.colorScheme,o=Y({apiKey:t,apiUrl:b==null?void 0:b.dataset.apiUrl,attachTo:b==null?void 0:b.dataset.attachTo,injectStyles:i===void 0?!0:i!=="false",colorScheme:d,theme:{primary:b==null?void 0:b.dataset.themePrimary,background:b==null?void 0:b.dataset.themeBackground,text:b==null?void 0:b.dataset.themeText,selected:b==null?void 0:b.dataset.themeSelected,selectedColor:b==null?void 0:b.dataset.themeSelectedColor}});J._defaultInstance=o})();})();
630
+ `;var s=typeof document!="undefined"?document.currentScript:null;function fe(){if(typeof document=="undefined"||document.getElementById("ib-modal-styles"))return;let e=document.createElement("style");e.id="ib-modal-styles",e.textContent=Z,document.head.appendChild(e)}function te(){if(typeof document=="undefined"||document.getElementById("ib-bar-styles"))return;let e=document.createElement("style");e.id="ib-bar-styles",e.textContent=ee,document.head.appendChild(e)}function ie(e){e.injectStyles!==!1&&fe();let t=X(e),i=null,d=null;return e.attachTo&&(i=document.querySelector(e.attachTo),i&&(d=()=>t.open(),i.addEventListener("click",d))),{open:u=>t.open(u),close:()=>t.close(),on:(u,m)=>t.on(u,m),destroy:()=>{i&&d&&(i.removeEventListener("click",d),i=null,d=null),t.destroy()}}}function he(e){return e.injectStyles!==!1&&te(),U(e)}if(typeof HTMLElement!="undefined"){class e extends HTMLElement{constructor(){super(...arguments);this._bar=null}connectedCallback(){var g,p,k,w,f,h,v,P,L,B,C,F;let d=this.getAttribute("api-key");if(!d)return;let u=this.getAttribute("inject-styles");(u===null?!0:u!=="false")&&te();let c=this.getAttribute("placement"),n=this.getAttribute("show-label"),y=this.getAttribute("show-title-field"),o=this.getAttribute("show-email-field");this._bar=U({apiKey:d,apiUrl:(g=this.getAttribute("api-url"))!=null?g:void 0,label:(p=this.getAttribute("label"))!=null?p:void 0,placement:c==="fixed"?"fixed":"inline",colorScheme:(k=this.getAttribute("color-scheme"))!=null?k:void 0,showLabel:n===null?void 0:n==="true",modalTitle:(w=this.getAttribute("modal-title"))!=null?w:void 0,modalPlaceholder:(f=this.getAttribute("modal-placeholder"))!=null?f:void 0,showTitleField:y===null?void 0:y==="true",showEmailField:o===null?void 0:o==="true",source:(h=this.getAttribute("source"))!=null?h:void 0,userId:(v=this.getAttribute("user-id"))!=null?v:void 0,theme:{primary:(P=this.getAttribute("theme-primary"))!=null?P:void 0,background:(L=this.getAttribute("theme-background"))!=null?L:void 0,text:(B=this.getAttribute("theme-text"))!=null?B:void 0,selected:(C=this.getAttribute("theme-selected"))!=null?C:void 0,selectedColor:(F=this.getAttribute("theme-selected-color"))!=null?F:void 0}}),this.appendChild(this._bar.element)}disconnectedCallback(){var d;(d=this._bar)==null||d.destroy(),this._bar=null}}typeof customElements!="undefined"&&!customElements.get("inputbuffer-feedback")&&customElements.define("inputbuffer-feedback",e)}var re={createModal:ie,createBar:he,version:W};typeof window!="undefined"&&(window.InputBufferIO=re);(function(){if(typeof window=="undefined")return;let t=s==null?void 0:s.dataset.apiKey;if(!t)return;let i=s==null?void 0:s.dataset.injectStyles,d=s==null?void 0:s.dataset.colorScheme,u=ie({apiKey:t,apiUrl:s==null?void 0:s.dataset.apiUrl,attachTo:s==null?void 0:s.dataset.attachTo,injectStyles:i===void 0?!0:i!=="false",colorScheme:d,theme:{primary:s==null?void 0:s.dataset.themePrimary,background:s==null?void 0:s.dataset.themeBackground,text:s==null?void 0:s.dataset.themeText,selected:s==null?void 0:s.dataset.themeSelected,selectedColor:s==null?void 0:s.dataset.themeSelectedColor}});re._defaultInstance=u})();})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inputbuffer/feedback",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Collect feedback from any website with a single script tag.",
5
5
  "type": "module",
6
6
  "main": "dist/widget.js",