blocfeed 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import {j,k,l,m as m$1,a,i,b as b$1}from'./chunk-QPAFC4IL.js';import {createContext,useMemo,useState,useEffect,useContext,useRef,useCallback}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';import {AnimatePresence,motion}from'framer-motion';var $=createContext(null);function J(e){let t=useMemo(()=>j({...e.config??{},blocfeed_id:e.blocfeed_id}),[]),[l,i]=useState(()=>t.getState());return useEffect(()=>t.subscribe(i),[t]),useEffect(()=>t.setConfig({...e.config??{},blocfeed_id:e.blocfeed_id}),[t,e.config,e.blocfeed_id]),useEffect(()=>()=>t.destroy(),[t]),jsx($.Provider,{value:{controller:t,state:l},children:e.children})}var be="blocfeed-styles-v1",ct=`
2
+ import {k,l,o,m,p,a,j,i,b as b$1}from'./chunk-LAK7UUTC.js';import {createContext,forwardRef,useState,useEffect,useRef,useMemo,useImperativeHandle,useCallback,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';import {AnimatePresence,motion}from'framer-motion';var U=createContext(null);function ee(e){let t=useMemo(()=>j({...e.config??{},blocfeed_id:e.blocfeed_id}),[]),[n,o]=useState(()=>t.getState());return useEffect(()=>t.subscribe(o),[t]),useEffect(()=>t.setConfig({...e.config??{},blocfeed_id:e.blocfeed_id}),[t,e.config,e.blocfeed_id]),useEffect(()=>()=>t.destroy(),[t]),jsx(U.Provider,{value:{controller:t,state:n},children:e.children})}var we="blocfeed-styles-v1",xt=`
3
3
  :where([data-blocfeed-ui-root]),
4
4
  :where([data-blocfeed-ui-root]) * {
5
5
  box-sizing: border-box;
@@ -20,6 +20,52 @@ import {j,k,l,m as m$1,a,i,b as b$1}from'./chunk-QPAFC4IL.js';import {createCont
20
20
  color: var(--bf-panel-fg);
21
21
  }
22
22
 
23
+ /* ------------------------------------------------------------------ */
24
+ /* Light theme */
25
+ /* ------------------------------------------------------------------ */
26
+
27
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) {
28
+ --bf-panel-bg: rgba(255, 255, 255, 0.98);
29
+ --bf-panel-fg: rgb(17, 24, 39);
30
+ --bf-muted: rgba(17, 24, 39, 0.6);
31
+ --bf-border: rgba(0, 0, 0, 0.12);
32
+ --bf-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
33
+ }
34
+
35
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-textarea {
36
+ border-color: rgba(0, 0, 0, 0.14);
37
+ background: rgba(0, 0, 0, 0.04);
38
+ color: var(--bf-panel-fg);
39
+ }
40
+
41
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-panelHeader {
42
+ border-bottom-color: rgba(0, 0, 0, 0.08);
43
+ }
44
+
45
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-title {
46
+ color: rgba(17, 24, 39, 0.85);
47
+ }
48
+
49
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-error {
50
+ color: rgb(185, 28, 28);
51
+ }
52
+
53
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-watermark a {
54
+ color: rgba(17, 24, 39, 0.35);
55
+ }
56
+
57
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-watermark {
58
+ border-top-color: rgba(0, 0, 0, 0.06);
59
+ }
60
+
61
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-highlight {
62
+ box-shadow: 0 0 0 9999px rgba(255, 255, 255, 0.42);
63
+ }
64
+
65
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-blocker {
66
+ background: rgba(255, 255, 255, 0.35);
67
+ }
68
+
23
69
  /* ------------------------------------------------------------------ */
24
70
  /* Trigger button \u2014 default bottom-right */
25
71
  /* ------------------------------------------------------------------ */
@@ -272,6 +318,45 @@ import {j,k,l,m as m$1,a,i,b as b$1}from'./chunk-QPAFC4IL.js';import {createCont
272
318
  color: rgba(243, 244, 246, 0.9);
273
319
  }
274
320
 
321
+ /* ------------------------------------------------------------------ */
322
+ /* Category pills */
323
+ /* ------------------------------------------------------------------ */
324
+
325
+ :where([data-blocfeed-ui-root]) .bf-pills {
326
+ display: flex;
327
+ flex-wrap: wrap;
328
+ gap: 6px;
329
+ }
330
+
331
+ :where([data-blocfeed-ui-root]) .bf-pill {
332
+ padding: 4px 10px;
333
+ border-radius: 999px;
334
+ border: 1px solid var(--bf-border);
335
+ background: transparent;
336
+ color: var(--bf-muted);
337
+ font-size: 12px;
338
+ font-family: var(--bf-font);
339
+ cursor: pointer;
340
+ user-select: none;
341
+ transition: border-color 0.15s, color 0.15s, background 0.15s;
342
+ }
343
+
344
+ :where([data-blocfeed-ui-root]) .bf-pill:hover {
345
+ border-color: var(--bf-accent);
346
+ color: var(--bf-panel-fg);
347
+ }
348
+
349
+ :where([data-blocfeed-ui-root]) .bf-pill-active {
350
+ border-color: var(--bf-accent);
351
+ background: var(--bf-accent);
352
+ color: white;
353
+ }
354
+
355
+ :where([data-blocfeed-ui-root]) .bf-pill[disabled] {
356
+ opacity: 0.6;
357
+ cursor: not-allowed;
358
+ }
359
+
275
360
  /* ------------------------------------------------------------------ */
276
361
  /* Capture spinner (item 12) */
277
362
  /* ------------------------------------------------------------------ */
@@ -463,6 +548,57 @@ import {j,k,l,m as m$1,a,i,b as b$1}from'./chunk-QPAFC4IL.js';import {createCont
463
548
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
464
549
  }
465
550
 
551
+ /* ------------------------------------------------------------------ */
552
+ /* Security warning banner */
553
+ /* ------------------------------------------------------------------ */
554
+
555
+ :where([data-blocfeed-ui-root]) .bf-security-banner {
556
+ position: fixed;
557
+ top: 8px;
558
+ right: 8px;
559
+ z-index: var(--bf-z);
560
+ max-width: 360px;
561
+ padding: 10px 14px;
562
+ border-radius: 10px;
563
+ border-left: 3px solid var(--bf-danger);
564
+ background: rgba(239, 68, 68, 0.12);
565
+ color: rgb(254, 202, 202);
566
+ font-family: var(--bf-font);
567
+ font-size: 12px;
568
+ line-height: 1.5;
569
+ pointer-events: auto;
570
+ animation: bf-panel-in 0.2s ease-out;
571
+ }
572
+
573
+ :where([data-blocfeed-ui-root][data-bf-theme="light"]) .bf-security-banner {
574
+ background: rgba(239, 68, 68, 0.08);
575
+ color: rgb(185, 28, 28);
576
+ }
577
+
578
+ :where([data-blocfeed-ui-root]) .bf-security-banner strong {
579
+ display: block;
580
+ margin-bottom: 4px;
581
+ font-size: 13px;
582
+ }
583
+
584
+ :where([data-blocfeed-ui-root]) .bf-security-banner-dismiss {
585
+ position: absolute;
586
+ top: 6px;
587
+ right: 6px;
588
+ background: none;
589
+ border: none;
590
+ color: inherit;
591
+ opacity: 0.6;
592
+ cursor: pointer;
593
+ padding: 2px 4px;
594
+ font-size: 14px;
595
+ line-height: 1;
596
+ }
597
+
598
+ :where([data-blocfeed-ui-root]) .bf-security-banner-dismiss:hover {
599
+ opacity: 1;
600
+ }
601
+
466
602
  /* ------------------------------------------------------------------ */
467
603
  /* Reduced motion */
468
604
  /* ------------------------------------------------------------------ */
@@ -499,5 +635,5 @@ import {j,k,l,m as m$1,a,i,b as b$1}from'./chunk-QPAFC4IL.js';import {createCont
499
635
  animation: none;
500
636
  }
501
637
  }
502
- `;function ge(){if(!a()||document.getElementById(be))return;let e=document.createElement("style");e.id=be,e.textContent=ct,document.head.appendChild(e);}var me={triggerLabel:"Feedback",panelTitle:"Feedback",hintText:"Click an element to attach your feedback. Press Esc to cancel.",cancelButton:"Cancel",rePickButton:"Re-pick",closeButton:"Close",textareaPlaceholder:"What's happening? What did you expect?",screenshotElement:"Screenshot element",screenshotFullPage:"Full page",capturingText:"Capturing screenshots\u2026",submittingText:"Submitting\u2026",successText:"Sent. Thank you!",toastText:"Feedback sent",sendButton:"Send"};function he(e){return e?{...me,...e}:me}function Z(){let e=useContext($);if(!e)throw new Error("useBlocFeed must be used within a <BlocFeedProvider />");return {state:e.state,controller:e.controller,start:e.controller.start,stop:e.controller.stop,clearSelection:e.controller.clearSelection,submit:e.controller.submit}}function m(e){switch(e){case "bottom-left":return "bf-trigger bf-trigger-bl";case "top-right":return "bf-trigger bf-trigger-tr";case "top-left":return "bf-trigger bf-trigger-tl";default:return "bf-trigger"}}function f({size:e=14}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:jsx("path",{d:"M20 6L9 17l-5-5",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function xe({size:e=14}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:jsx("path",{d:"M21 11.5a8.38 8.38 0 01-.9 3.8 8.5 8.5 0 01-7.6 4.7 8.38 8.38 0 01-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 01-.9-3.8 8.5 8.5 0 014.7-7.6 8.38 8.38 0 013.8-.9h.5a8.48 8.48 0 018 8v.5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function ye({size:e=16}){return jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[jsx("path",{d:"M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),jsx("path",{d:"M22 6l-10 7L2 6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function we({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){return l?jsxs("button",{className:m(e),type:"button",onClick:t,"aria-label":i,children:[c?jsx("span",{style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:14})}):jsxs(Fragment,{children:[jsx("span",{className:"bf-dot","aria-hidden":"true"}),i]}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]}):null}function b(){let[e,t]=useState(()=>typeof window>"u"?false:window.matchMedia("(prefers-reduced-motion: reduce)").matches);return useEffect(()=>{let l=window.matchMedia("(prefers-reduced-motion: reduce)"),i=r=>t(r.matches);return l.addEventListener("change",i),()=>l.removeEventListener("change",i)},[]),e}var mt={duration:.18,ease:"easeOut"},ht={duration:0};function Te({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){let[a,s]=useState(false),o=b(),n=o?ht:mt;return jsx(AnimatePresence,{mode:"wait",children:l&&jsx(motion.button,{className:m(e),type:"button",onClick:t,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"aria-label":i,initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:n,whileTap:{scale:.92},style:{overflow:"hidden"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:n,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:14})},"success"):jsxs(Fragment,{children:[jsx(motion.span,{className:"bf-dot","aria-hidden":"true",animate:o?{}:{scale:a?1:[1,1.2,1],boxShadow:a?"0 0 0 4px rgba(99, 102, 241, 0.18)":["0 0 0 4px rgba(99, 102, 241, 0.18)","0 0 0 8px rgba(99, 102, 241, 0.28)","0 0 0 4px rgba(99, 102, 241, 0.18)"]},transition:a||o?n:{duration:2,repeat:1/0,ease:"easeInOut"}}),jsx(AnimatePresence,{mode:"wait",children:a&&jsx(motion.span,{initial:{opacity:0,x:o?0:-6},animate:{opacity:1,x:0},exit:{opacity:0,x:o?0:-6},transition:n,style:{whiteSpace:"nowrap"},children:i},"label")}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"dot")})}var wt={duration:.18,ease:"easeOut"},Ee={duration:0};function Ce({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){let[a,s]=useState(false),o=b(),n=o?Ee:wt;return jsx(AnimatePresence,{mode:"wait",children:l&&jsxs(motion.div,{className:m(e),initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{y:8,opacity:0},transition:n,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),style:{background:"transparent",border:"none",boxShadow:"none",padding:0},children:[jsx(AnimatePresence,{mode:"wait",children:a&&jsx(motion.div,{initial:{opacity:0,y:o?0:4},animate:{opacity:1,y:0},exit:{opacity:0,y:o?0:4},transition:n,style:{position:"absolute",bottom:"calc(100% + 8px)",left:"50%",transform:"translateX(-50%)",padding:"6px 12px",borderRadius:"8px",background:"var(--bf-panel-bg)",border:"1px solid var(--bf-border)",boxShadow:"var(--bf-shadow)",whiteSpace:"nowrap",fontSize:"12px",color:"var(--bf-panel-fg)",pointerEvents:"none"},children:i},"tooltip")}),jsxs(motion.button,{type:"button",onClick:t,"aria-label":i,style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:"40px",height:"40px",borderRadius:"50%",border:"1px solid var(--bf-border)",background:"var(--bf-panel-bg)",color:"var(--bf-panel-fg)",boxShadow:"var(--bf-shadow)",cursor:"pointer",padding:0},animate:o?{}:{y:[0,-3,0]},transition:o?Ee:{y:{duration:3,repeat:1/0,ease:"easeInOut"}},whileHover:{scale:1.1,borderColor:"var(--bf-accent)"},whileTap:{scale:.9},children:[c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:n,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:16})},"success"):jsx(xe,{size:16}),r>0&&jsx("span",{className:"bf-badge bf-badge-float","aria-label":`${r} queued`,children:r})]})]},"bubble")})}var Pt={duration:.2,ease:"easeOut"},Et={duration:0};function Be(e){return e==="bottom-left"||e==="top-left"}function St(e){return `bf-trigger-edge ${Be(e)?"bf-trigger-edge-left":"bf-trigger-edge-right"}`}function Fe({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){let[a,s]=useState(false),o=Be(e),n=b(),u=n?Et:Pt;return jsx(AnimatePresence,{mode:"wait",children:l&&jsx(motion.button,{className:St(e),type:"button",onClick:t,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"aria-label":i,initial:{opacity:0,width:0},animate:{opacity:1,width:a?140:22,height:a?40:90},exit:{width:0,opacity:0},transition:u,whileTap:{scale:.97},style:{top:"50%",translateY:"-50%"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:u,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:14})},"success"):jsxs(Fragment,{children:[jsxs(motion.span,{animate:{rotate:n||a?0:o?-90:90,opacity:a?1:.6},transition:u,style:{display:"flex",alignItems:"center",gap:"8px",whiteSpace:"nowrap",fontSize:"12px",letterSpacing:"0.5px",textTransform:"uppercase"},children:[a&&jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:{duration:.12},style:{width:"6px",height:"6px",borderRadius:"50%",background:"var(--bf-accent)",flexShrink:0}}),i]}),jsx(motion.span,{"aria-hidden":"true",animate:{opacity:a?1:0},transition:{duration:.12},style:{position:"absolute",top:0,bottom:0,[o?"left":"right"]:0,width:"2px",background:"var(--bf-accent)"}}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"edge-tab")})}var Bt={duration:.18,ease:"easeOut"},Ft={duration:0};function Me({delay:e,hovered:t,reduced:l}){return l?null:jsx(motion.span,{"aria-hidden":"true",style:{position:"absolute",width:"10px",height:"10px",borderRadius:"50%",border:"2px solid var(--bf-accent)",pointerEvents:"none"},animate:t?{scale:1,opacity:0}:{scale:[1,1.8],opacity:[.5,0]},transition:t?{duration:.15}:{duration:2,repeat:1/0,delay:e,ease:"easeOut"}})}function ze({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){let[a,s]=useState(false),o=b(),n=o?Ft:Bt;return jsx(AnimatePresence,{mode:"wait",children:l&&jsx(motion.button,{className:m(e),type:"button",onClick:t,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"aria-label":i,initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:n,whileTap:{scale:.92},style:{overflow:"hidden"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:n,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:14})},"success"):jsxs(Fragment,{children:[jsxs("span",{style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:"10px",height:"10px",flexShrink:0},children:[jsx(Me,{delay:0,hovered:a,reduced:o}),jsx(Me,{delay:.7,hovered:a,reduced:o}),jsx(motion.span,{className:"bf-dot","aria-hidden":"true",style:{position:"relative",zIndex:1}})]}),jsx(AnimatePresence,{mode:"wait",children:a&&jsx(motion.span,{initial:{opacity:0,x:o?0:-6},animate:{opacity:1,x:0},exit:{opacity:0,x:o?0:-6},transition:n,style:{whiteSpace:"nowrap"},children:i},"label")}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"pulse-ring")})}var zt={duration:.18,ease:"easeOut"},It={duration:0};function At(e){switch(e){case "bottom-left":return "bf-trigger-minimal bf-trigger-bl";case "top-right":return "bf-trigger-minimal bf-trigger-tr";case "top-left":return "bf-trigger-minimal bf-trigger-tl";default:return "bf-trigger-minimal"}}function We({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){let[a,s]=useState(false),o=b(),n=o?It:zt;return jsx(AnimatePresence,{mode:"wait",children:l&&jsxs(motion.button,{className:At(e),type:"button",onClick:t,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"aria-label":i,initial:{opacity:0,y:o?0:5},animate:{opacity:a?1:.65,y:0},exit:{opacity:0,y:o?0:5},transition:n,whileTap:{scale:.95},children:[c?jsx("span",{style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:14})}):jsxs(Fragment,{children:[jsx("span",{children:i}),r>0&&jsx("span",{className:"bf-badge",style:{marginLeft:"4px"},"aria-label":`${r} queued`,children:r})]}),!o&&jsx(motion.span,{"aria-hidden":"true",style:{position:"absolute",bottom:4,left:4,right:4,height:"2px",background:"var(--bf-accent)",borderRadius:"1px",transformOrigin:"left"},initial:false,animate:{scaleX:a?1:0},transition:n})]},"minimal")})}var Ot={duration:.18,ease:"easeOut"},Ht={duration:0};function Oe({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){let[a,s]=useState(false),o=b(),n=o?Ht:Ot;return jsx(AnimatePresence,{mode:"wait",children:l&&jsx(motion.button,{className:m(e),type:"button",onClick:t,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"aria-label":i,initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:n,whileTap:{scale:.9},style:{overflow:"hidden"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:n,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:14})},"success"):jsxs(Fragment,{children:[jsx(motion.span,{style:{display:"inline-flex",flexShrink:0},animate:o?{}:a?{scale:1.2,rotate:0}:{rotate:[-5,5,-5]},transition:a||o?n:{duration:3,repeat:1/0,ease:"easeInOut"},children:jsx(ye,{size:16})}),jsx(AnimatePresence,{mode:"wait",children:a&&jsx(motion.span,{initial:{opacity:0,x:o?0:-8},animate:{opacity:1,x:0},exit:{opacity:0,x:o?0:-8},transition:n,style:{whiteSpace:"nowrap"},children:i},"label")}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"icon-pop")})}var Xt={duration:.18,ease:"easeOut"},Yt={duration:0};function Ke({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){let[a,s]=useState(false),o=b(),n=o?Yt:Xt;return jsx(AnimatePresence,{mode:"wait",children:l&&jsx(motion.button,{className:m(e),type:"button",onClick:t,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"aria-label":i,initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:n,whileTap:{scale:.92},style:{overflow:"hidden"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:n,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:14})},"success"):jsxs(Fragment,{children:[jsxs("span",{style:{position:"relative",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"10px",height:"10px",flexShrink:0},children:[jsx(motion.span,{"aria-hidden":"true",style:{width:"10px",height:"10px",borderRadius:"50%",background:"var(--bf-accent)",position:"relative",zIndex:1},animate:o?{}:{opacity:a?1:[.5,1,.5],boxShadow:a?"0 0 8px 2px var(--bf-accent)":["0 0 4px 1px var(--bf-accent)","0 0 12px 4px var(--bf-accent)","0 0 4px 1px var(--bf-accent)"]},transition:a||o?n:{duration:2,repeat:1/0,ease:"easeInOut"}}),!a&&!o&&jsx(motion.span,{"aria-hidden":"true",style:{position:"absolute",width:"18px",height:"2px",background:"linear-gradient(90deg, var(--bf-accent), transparent)",transformOrigin:"left center",left:"5px",top:"4px"},animate:{rotate:[0,360]},transition:{duration:4,repeat:1/0,ease:"linear"}})]}),jsx(AnimatePresence,{mode:"wait",children:a&&jsx(motion.span,{initial:{opacity:0,x:o?0:-6},animate:{opacity:1,x:0},exit:{opacity:0,x:o?0:-6},transition:n,style:{whiteSpace:"nowrap"},children:i},"label")}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"beacon")})}var Gt={duration:.18,ease:"easeOut"},Jt={duration:0};function Ue({position:e,onClick:t,isVisible:l,label:i,queueCount:r,showSuccess:c}){let[a,s]=useState(false),[o,n]=useState(0),u=b(),H=u?Jt:Gt,g=useRef(null);useEffect(()=>{if(g.current&&(clearInterval(g.current),g.current=null),!l||a||u){n(a||u?i.length:0);return}let E=8,K=i.length*2+E*2,x=0;return g.current=setInterval(()=>{x=(x+1)%K,x<=i.length?n(x):x<=i.length+E?n(i.length):x<=i.length*2+E?n(i.length*2+E-x):n(0);},100),()=>{g.current&&(clearInterval(g.current),g.current=null);}},[l,a,u,i]);let D=i.slice(0,o);return jsx(AnimatePresence,{mode:"wait",children:l&&jsx(motion.button,{className:m(e),type:"button",onClick:t,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"aria-label":i,initial:{opacity:0,y:u?0:5},animate:{opacity:1,y:0},exit:{opacity:0,y:u?0:5},transition:H,whileTap:{scale:.95},style:{minWidth:"44px"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:H,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(f,{size:14})},"success"):jsxs(Fragment,{children:[jsx("span",{className:"bf-dot","aria-hidden":"true"}),jsxs("span",{style:{whiteSpace:"nowrap",minWidth:"1ch"},children:[D,jsx("span",{className:"bf-cursor","aria-hidden":"true"})]}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"typewriter")})}function je(e){switch(e){case "dot":return Te;case "bubble":return Ce;case "edge-tab":return Fe;case "pulse-ring":return ze;case "minimal":return We;case "icon-pop":return Oe;case "beacon":return Ke;case "typewriter":return Ue;default:return we}}function Ve(e,t,l){return Math.max(t,Math.min(l,e))}function eo(e,t,l="bottom-right"){let r=window.innerWidth,c=window.innerHeight,a;a=Ve(e.x,12,Math.max(12,r-t-12));let s=e.y+e.height+12,o=Math.max(12,e.y-240);return {top:s+240<=c?s:o,left:a}}function to(e){let{rect:t}=e,l={left:`${t.x}px`,top:`${t.y}px`,width:`${Math.max(0,t.width)}px`,height:`${Math.max(0,t.height)}px`};return jsx("div",{className:"bf-highlight",style:l,"aria-hidden":"true"})}function oo(e){let t=useRef(null);return useEffect(()=>{if(!e||!t.current)return;t.current.querySelector(".bf-textarea")?.focus();let i=r=>{if(r.key!=="Tab"||!t.current)return;let c=t.current.querySelectorAll('button:not([disabled]), textarea:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])');if(c.length===0)return;let a=c[0],s=c[c.length-1];r.shiftKey&&document.activeElement===a?(r.preventDefault(),s.focus()):!r.shiftKey&&document.activeElement===s&&(r.preventDefault(),a.focus());};return document.addEventListener("keydown",i,{capture:true}),()=>document.removeEventListener("keydown",i,{capture:true})},[e]),t}function ro(e){let{state:t,controller:l,start:i$1,stop:r,clearSelection:c,submit:a}=Z(),s=e.config.ui?.position,o=he(e.config.ui?.strings),n=e.config.ui?.branding!==false,[u,H]=useState(null),[g,D]=useState(""),[E,K]=useState(e.config.capture?.element??true),[x,ee]=useState(e.config.capture?.fullPage??false),[Je,te]=useState(null),oe=t.phase==="review"||t.phase==="capturing"||t.phase==="submitting"||t.phase==="error"||t.phase==="success",Ze=oo(oe),[qe,et]=useState(0);useEffect(()=>{t.phase==="idle"&&et(i());},[t.phase]);let[tt,re]=useState(false),ie=useRef(t.phase);useEffect(()=>{if(ie.current==="success"&&t.phase==="idle"){re(true);let p=window.setTimeout(()=>re(false),1500);return ()=>window.clearTimeout(p)}ie.current=t.phase;},[t.phase]),useEffect(()=>{let p=e.config.ui?.shortcut;if(!p)return;let L=p.toLowerCase().split("+").map(v=>v.trim()),z=L[L.length-1]||"",B=new Set(L.slice(0,-1)),ae=v=>{let it=/Mac|iPod|iPhone|iPad/.test(navigator.platform);if(B.has("mod")){if(it?!v.metaKey:!v.ctrlKey)return}else if(B.has("ctrl")&&!v.ctrlKey||(B.has("meta")||B.has("cmd"))&&!v.metaKey)return;B.has("shift")&&!v.shiftKey||(B.has("alt")||B.has("option"))&&!v.altKey||v.key.toLowerCase()===z&&(v.preventDefault(),t.phase==="idle"?i$1():r());};return document.addEventListener("keydown",ae),()=>document.removeEventListener("keydown",ae)},[e.config.ui?.shortcut,t.phase,i$1,r]),useEffect(()=>l.subscribeHover(H),[l]),useEffect(()=>{let p=l.__unsafeGetSelectedElement();if(!p||t.phase==="idle"||t.phase==="picking"){te(null);return}let L=()=>{te(b$1(p.getBoundingClientRect()));};L();let z=()=>L();return window.addEventListener("scroll",z,{capture:true,passive:true}),window.addEventListener("resize",z,{passive:true}),()=>{window.removeEventListener("scroll",z,{capture:true}),window.removeEventListener("resize",z);}},[l,t.phase,t.selection?.selector]),useEffect(()=>{t.phase==="review"&&(D(""),K(e.config.capture?.element??true),ee(e.config.capture?.fullPage??false));},[t.phase,t.selection?.selector,e.config.capture?.element,e.config.capture?.fullPage]),useEffect(()=>{if(t.phase!=="success")return;let p=window.setTimeout(()=>r(),1200);return ()=>window.clearTimeout(p)},[t.phase,r]);let k=t.phase==="capturing"||t.phase==="submitting",S=t.phase==="picking"?u?.rect??null:Je??t.selection?.rect??null,Q=useMemo(()=>S?eo(S,360,s):null,[S?.x,S?.y,S?.width,S?.height,s]),ne=t.lastError?.message,V=useCallback(()=>{a(g,{capture:{element:E,fullPage:x}});},[a,g,E,x]),ot=useCallback(p=>{(p.metaKey||p.ctrlKey)&&p.key==="Enter"&&g.trim().length>0&&!k&&(p.preventDefault(),V());},[V,g,k]),rt=je(e.config.ui?.triggerStyle);return jsxs(Fragment,{children:[jsx(rt,{position:s,onClick:()=>i$1(),isVisible:t.phase==="idle",label:e.config.ui?.triggerLabel??o.triggerLabel,queueCount:qe,showSuccess:tt}),t.phase!=="idle"&&jsxs("div",{className:"bf-overlay",role:"presentation",children:[t.phase!=="picking"&&jsx("div",{className:"bf-blocker",role:"presentation",onClick:()=>r()}),S&&jsx(to,{rect:S}),t.phase==="picking"&&jsxs("div",{className:"bf-hint",role:"status","aria-live":"polite",children:[jsx("p",{id:"bf-hint-text",children:o.hintText}),jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),"aria-label":o.cancelButton,children:o.cancelButton})]}),oe&&Q&&jsxs("div",{ref:Ze,className:"bf-panel",style:{left:Q.left,top:Q.top},role:"dialog","aria-modal":"true","aria-label":"Feedback form",children:[jsxs("div",{className:"bf-panelHeader",children:[jsx("div",{className:"bf-title",id:"bf-panel-title",children:o.panelTitle}),jsxs("div",{className:"bf-row",style:{justifyContent:"flex-end"},children:[jsx("button",{type:"button",className:"bf-btn",onClick:()=>c(),disabled:k,"aria-label":o.rePickButton,children:o.rePickButton}),jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),disabled:k,"aria-label":o.closeButton,children:o.closeButton})]})]}),jsxs("div",{className:"bf-panelBody",children:[jsx("textarea",{className:"bf-textarea",placeholder:o.textareaPlaceholder,value:g,onChange:p=>D(p.target.value),onKeyDown:ot,disabled:k,"aria-label":o.panelTitle}),jsxs("div",{className:"bf-row",role:"group","aria-label":o.screenshotElement,children:[jsxs("label",{children:[jsx("input",{type:"checkbox",checked:E,onChange:p=>K(p.target.checked),disabled:k}),o.screenshotElement]}),jsxs("label",{children:[jsx("input",{type:"checkbox",checked:x,onChange:p=>ee(p.target.checked),disabled:k}),o.screenshotFullPage]})]}),t.phase==="capturing"&&jsxs("div",{className:"bf-status",role:"status","aria-live":"polite",children:[jsx("span",{className:"bf-spinner","aria-hidden":"true"}),o.capturingText]}),t.phase==="submitting"&&jsxs("div",{className:"bf-status",role:"status","aria-live":"polite",children:[jsx("span",{className:"bf-spinner","aria-hidden":"true"}),o.submittingText]}),t.phase==="success"&&jsx("div",{className:"bf-status",role:"status","aria-live":"polite",children:o.successText}),t.phase==="error"&&ne&&jsx("div",{className:"bf-error",role:"alert",children:ne}),jsxs("div",{className:"bf-actions",children:[jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),disabled:k,"aria-label":o.cancelButton,children:o.cancelButton}),jsx("button",{type:"button",className:"bf-btn bf-btnPrimary",onClick:V,disabled:k||g.trim().length===0,"aria-label":o.sendButton,children:o.sendButton})]})]}),n&&jsx("div",{className:"bf-watermark",children:jsx("a",{href:"https://blocfeed.com",target:"_blank",rel:"noopener noreferrer",children:"Powered by BlocFeed"})})]})]}),t.phase==="success"&&jsx("div",{className:"bf-toast",role:"status","aria-live":"polite",children:o.toastText})]})}function io(e){let t={...e.config??{},blocfeed_id:e.blocfeed_id},[l$1,i]=useState(null),r=!!t.diagnostics;useEffect(()=>{if(r)return k(t.diagnostics),()=>l()},[r]);let c=useRef(e.config?.metadata?.enrich);c.current=e.config?.metadata?.enrich;let a=useMemo(()=>{if(e.config)return {...e.config,metadata:{...e.config.metadata,enrich:async s=>{let o=c.current,n=o?await o(s):{},u=m$1();return {...n,...u.consoleLogs.length>0?{_consoleLogs:u.consoleLogs}:{},...u.networkErrors.length>0?{_networkErrors:u.networkErrors}:{}}}}}},[]);return useEffect(()=>{ge();let s=document.createElement("div");s.setAttribute("data-blocfeed-ui-root","true"),s.setAttribute("data-blocfeed-ui","true");let o=t.ui?.zIndex;typeof o=="number"&&s.style.setProperty("--bf-z",String(o));let n=t.ui?.theme;return n&&(n.accentColor&&s.style.setProperty("--bf-accent",n.accentColor),n.panelBackground&&s.style.setProperty("--bf-panel-bg",n.panelBackground),n.panelForeground&&s.style.setProperty("--bf-panel-fg",n.panelForeground),n.fontFamily&&s.style.setProperty("--bf-font",n.fontFamily)),document.body.appendChild(s),i(s),()=>{s.remove(),i(null);}},[t.ui?.zIndex,t.ui?.theme?.accentColor,t.ui?.theme?.panelBackground,t.ui?.theme?.panelForeground,t.ui?.theme?.fontFamily]),l$1?createPortal(jsx(J,{blocfeed_id:t.blocfeed_id,...a?{config:a}:{},children:jsx(ro,{config:t})}),l$1):null}
503
- export{J as BlocFeedProvider,io as BlocFeedWidget,Z as useBlocFeed};
638
+ `;function ve(){if(!a()||document.getElementById(we))return;let e=document.createElement("style");e.id=we,e.textContent=xt,document.head.appendChild(e);}var ke={triggerLabel:"Feedback",panelTitle:"Feedback",hintText:"Click an element to attach your feedback. Press Esc to cancel.",cancelButton:"Cancel",rePickButton:"Re-pick",closeButton:"Close",textareaPlaceholder:"What's happening? What did you expect?",screenshotElement:"Screenshot element",screenshotFullPage:"Full page",capturingText:"Capturing screenshots\u2026",submittingText:"Submitting\u2026",successText:"Sent. Thank you!",toastText:"Feedback sent",sendButton:"Send",categoryBug:"Bug",categoryFeature:"Feature",categoryUx:"UX",categoryGeneral:"General"};function Te(e){return e?{...ke,...e}:ke}function te(){let e=useContext(U);if(!e)throw new Error("useBlocFeed must be used within a <BlocFeedProvider />");return {state:e.state,controller:e.controller,start:e.controller.start,stop:e.controller.stop,clearSelection:e.controller.clearSelection,submit:e.controller.submit}}function y(e){switch(e){case "bottom-left":return "bf-trigger bf-trigger-bl";case "top-right":return "bf-trigger bf-trigger-tr";case "top-left":return "bf-trigger bf-trigger-tl";default:return "bf-trigger"}}function b({size:e=14}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:jsx("path",{d:"M20 6L9 17l-5-5",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Se({size:e=14}){return jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:jsx("path",{d:"M21 11.5a8.38 8.38 0 01-.9 3.8 8.5 8.5 0 01-7.6 4.7 8.38 8.38 0 01-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 01-.9-3.8 8.5 8.5 0 014.7-7.6 8.38 8.38 0 013.8-.9h.5a8.48 8.48 0 018 8v.5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function Pe({size:e=16}){return jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[jsx("path",{d:"M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),jsx("path",{d:"M22 6l-10 7L2 6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}function Ce({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){return n?jsxs("button",{className:y(e),type:"button",onClick:t,"aria-label":o,children:[c?jsx("span",{style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:14})}):jsxs(Fragment,{children:[jsx("span",{className:"bf-dot","aria-hidden":"true"}),o]}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]}):null}function g(){let[e,t]=useState(()=>typeof window>"u"?false:window.matchMedia("(prefers-reduced-motion: reduce)").matches);return useEffect(()=>{let n=window.matchMedia("(prefers-reduced-motion: reduce)"),o=r=>t(r.matches);return n.addEventListener("change",o),()=>n.removeEventListener("change",o)},[]),e}var Pt={duration:.18,ease:"easeOut"},Et={duration:0};function Be({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){let[i,l]=useState(false),a=g(),s=a?Et:Pt;return jsx(AnimatePresence,{mode:"wait",children:n&&jsx(motion.button,{className:y(e),type:"button",onClick:t,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),"aria-label":o,initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:s,whileTap:{scale:.92},style:{overflow:"hidden"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:s,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:14})},"success"):jsxs(Fragment,{children:[jsx(motion.span,{className:"bf-dot","aria-hidden":"true",animate:a?{}:{scale:i?1:[1,1.2,1],boxShadow:i?"0 0 0 4px rgba(99, 102, 241, 0.18)":["0 0 0 4px rgba(99, 102, 241, 0.18)","0 0 0 8px rgba(99, 102, 241, 0.28)","0 0 0 4px rgba(99, 102, 241, 0.18)"]},transition:i||a?s:{duration:2,repeat:1/0,ease:"easeInOut"}}),jsx(AnimatePresence,{mode:"wait",children:i&&jsx(motion.span,{initial:{opacity:0,x:a?0:-6},animate:{opacity:1,x:0},exit:{opacity:0,x:a?0:-6},transition:s,style:{whiteSpace:"nowrap"},children:o},"label")}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"dot")})}var Nt={duration:.18,ease:"easeOut"},Re={duration:0};function Le({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){let[i,l]=useState(false),a=g(),s=a?Re:Nt;return jsx(AnimatePresence,{mode:"wait",children:n&&jsxs(motion.div,{className:y(e),initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{y:8,opacity:0},transition:s,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),style:{background:"transparent",border:"none",boxShadow:"none",padding:0},children:[jsx(AnimatePresence,{mode:"wait",children:i&&jsx(motion.div,{initial:{opacity:0,y:a?0:4},animate:{opacity:1,y:0},exit:{opacity:0,y:a?0:4},transition:s,style:{position:"absolute",bottom:"calc(100% + 8px)",left:"50%",transform:"translateX(-50%)",padding:"6px 12px",borderRadius:"8px",background:"var(--bf-panel-bg)",border:"1px solid var(--bf-border)",boxShadow:"var(--bf-shadow)",whiteSpace:"nowrap",fontSize:"12px",color:"var(--bf-panel-fg)",pointerEvents:"none"},children:o},"tooltip")}),jsxs(motion.button,{type:"button",onClick:t,"aria-label":o,style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:"40px",height:"40px",borderRadius:"50%",border:"1px solid var(--bf-border)",background:"var(--bf-panel-bg)",color:"var(--bf-panel-fg)",boxShadow:"var(--bf-shadow)",cursor:"pointer",padding:0},animate:a?{}:{y:[0,-3,0]},transition:a?Re:{y:{duration:3,repeat:1/0,ease:"easeInOut"}},whileHover:{scale:1.1,borderColor:"var(--bf-accent)"},whileTap:{scale:.9},children:[c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:s,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:16})},"success"):jsx(Se,{size:16}),r>0&&jsx("span",{className:"bf-badge bf-badge-float","aria-label":`${r} queued`,children:r})]})]},"bubble")})}var Lt={duration:.2,ease:"easeOut"},zt={duration:0};function Ae(e){return e==="bottom-left"||e==="top-left"}function At(e){return `bf-trigger-edge ${Ae(e)?"bf-trigger-edge-left":"bf-trigger-edge-right"}`}function Ie({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){let[i,l]=useState(false),a=Ae(e),s=g(),m=s?zt:Lt;return jsx(AnimatePresence,{mode:"wait",children:n&&jsx(motion.button,{className:At(e),type:"button",onClick:t,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),"aria-label":o,initial:{opacity:0,width:0},animate:{opacity:1,width:i?140:22,height:i?40:90},exit:{width:0,opacity:0},transition:m,whileTap:{scale:.97},style:{top:"50%",translateY:"-50%"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:m,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:14})},"success"):jsxs(Fragment,{children:[jsxs(motion.span,{animate:{rotate:s||i?0:a?-90:90,opacity:i?1:.6},transition:m,style:{display:"flex",alignItems:"center",gap:"8px",whiteSpace:"nowrap",fontSize:"12px",letterSpacing:"0.5px",textTransform:"uppercase"},children:[i&&jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:{duration:.12},style:{width:"6px",height:"6px",borderRadius:"50%",background:"var(--bf-accent)",flexShrink:0}}),o]}),jsx(motion.span,{"aria-hidden":"true",animate:{opacity:i?1:0},transition:{duration:.12},style:{position:"absolute",top:0,bottom:0,[a?"left":"right"]:0,width:"2px",background:"var(--bf-accent)"}}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"edge-tab")})}var _t={duration:.18,ease:"easeOut"},Ht={duration:0};function _e({delay:e,hovered:t,reduced:n}){return n?null:jsx(motion.span,{"aria-hidden":"true",style:{position:"absolute",width:"10px",height:"10px",borderRadius:"50%",border:"2px solid var(--bf-accent)",pointerEvents:"none"},animate:t?{scale:1,opacity:0}:{scale:[1,1.8],opacity:[.5,0]},transition:t?{duration:.15}:{duration:2,repeat:1/0,delay:e,ease:"easeOut"}})}function Oe({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){let[i,l]=useState(false),a=g(),s=a?Ht:_t;return jsx(AnimatePresence,{mode:"wait",children:n&&jsx(motion.button,{className:y(e),type:"button",onClick:t,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),"aria-label":o,initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:s,whileTap:{scale:.92},style:{overflow:"hidden"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:s,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:14})},"success"):jsxs(Fragment,{children:[jsxs("span",{style:{position:"relative",display:"flex",alignItems:"center",justifyContent:"center",width:"10px",height:"10px",flexShrink:0},children:[jsx(_e,{delay:0,hovered:i,reduced:a}),jsx(_e,{delay:.7,hovered:i,reduced:a}),jsx(motion.span,{className:"bf-dot","aria-hidden":"true",style:{position:"relative",zIndex:1}})]}),jsx(AnimatePresence,{mode:"wait",children:i&&jsx(motion.span,{initial:{opacity:0,x:a?0:-6},animate:{opacity:1,x:0},exit:{opacity:0,x:a?0:-6},transition:s,style:{whiteSpace:"nowrap"},children:o},"label")}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"pulse-ring")})}var $t={duration:.18,ease:"easeOut"},Ut={duration:0};function Xt(e){switch(e){case "bottom-left":return "bf-trigger-minimal bf-trigger-bl";case "top-right":return "bf-trigger-minimal bf-trigger-tr";case "top-left":return "bf-trigger-minimal bf-trigger-tl";default:return "bf-trigger-minimal"}}function $e({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){let[i,l]=useState(false),a=g(),s=a?Ut:$t;return jsx(AnimatePresence,{mode:"wait",children:n&&jsxs(motion.button,{className:Xt(e),type:"button",onClick:t,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),"aria-label":o,initial:{opacity:0,y:a?0:5},animate:{opacity:i?1:.65,y:0},exit:{opacity:0,y:a?0:5},transition:s,whileTap:{scale:.95},children:[c?jsx("span",{style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:14})}):jsxs(Fragment,{children:[jsx("span",{children:o}),r>0&&jsx("span",{className:"bf-badge",style:{marginLeft:"4px"},"aria-label":`${r} queued`,children:r})]}),!a&&jsx(motion.span,{"aria-hidden":"true",style:{position:"absolute",bottom:4,left:4,right:4,height:"2px",background:"var(--bf-accent)",borderRadius:"1px",transformOrigin:"left"},initial:false,animate:{scaleX:i?1:0},transition:s})]},"minimal")})}var Qt={duration:.18,ease:"easeOut"},jt={duration:0};function Xe({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){let[i,l]=useState(false),a=g(),s=a?jt:Qt;return jsx(AnimatePresence,{mode:"wait",children:n&&jsx(motion.button,{className:y(e),type:"button",onClick:t,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),"aria-label":o,initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:s,whileTap:{scale:.9},style:{overflow:"hidden"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:s,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:14})},"success"):jsxs(Fragment,{children:[jsx(motion.span,{style:{display:"inline-flex",flexShrink:0},animate:a?{}:i?{scale:1.2,rotate:0}:{rotate:[-5,5,-5]},transition:i||a?s:{duration:3,repeat:1/0,ease:"easeInOut"},children:jsx(Pe,{size:16})}),jsx(AnimatePresence,{mode:"wait",children:i&&jsx(motion.span,{initial:{opacity:0,x:a?0:-8},animate:{opacity:1,x:0},exit:{opacity:0,x:a?0:-8},transition:s,style:{whiteSpace:"nowrap"},children:o},"label")}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"icon-pop")})}var Zt={duration:.18,ease:"easeOut"},eo={duration:0};function Qe({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){let[i,l]=useState(false),a=g(),s=a?eo:Zt;return jsx(AnimatePresence,{mode:"wait",children:n&&jsx(motion.button,{className:y(e),type:"button",onClick:t,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),"aria-label":o,initial:{scale:0,opacity:0},animate:{scale:1,opacity:1},exit:{scale:0,opacity:0},transition:s,whileTap:{scale:.92},style:{overflow:"hidden"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:s,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:14})},"success"):jsxs(Fragment,{children:[jsxs("span",{style:{position:"relative",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"10px",height:"10px",flexShrink:0},children:[jsx(motion.span,{"aria-hidden":"true",style:{width:"10px",height:"10px",borderRadius:"50%",background:"var(--bf-accent)",position:"relative",zIndex:1},animate:a?{}:{opacity:i?1:[.5,1,.5],boxShadow:i?"0 0 8px 2px var(--bf-accent)":["0 0 4px 1px var(--bf-accent)","0 0 12px 4px var(--bf-accent)","0 0 4px 1px var(--bf-accent)"]},transition:i||a?s:{duration:2,repeat:1/0,ease:"easeInOut"}}),!i&&!a&&jsx(motion.span,{"aria-hidden":"true",style:{position:"absolute",width:"18px",height:"2px",background:"linear-gradient(90deg, var(--bf-accent), transparent)",transformOrigin:"left center",left:"5px",top:"4px"},animate:{rotate:[0,360]},transition:{duration:4,repeat:1/0,ease:"linear"}})]}),jsx(AnimatePresence,{mode:"wait",children:i&&jsx(motion.span,{initial:{opacity:0,x:a?0:-6},animate:{opacity:1,x:0},exit:{opacity:0,x:a?0:-6},transition:s,style:{whiteSpace:"nowrap"},children:o},"label")}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"beacon")})}var io={duration:.18,ease:"easeOut"},no={duration:0};function Je({position:e,onClick:t,isVisible:n,label:o,queueCount:r,showSuccess:c}){let[i,l]=useState(false),[a,s]=useState(0),m=g(),M=m?no:io,p=useRef(null);useEffect(()=>{if(p.current&&(clearInterval(p.current),p.current=null),!n||i||m){s(i||m?o.length:0);return}let u=8,E=o.length*2+u*2,x=0;return p.current=setInterval(()=>{x=(x+1)%E,x<=o.length?s(x):x<=o.length+u?s(o.length):x<=o.length*2+u?s(o.length*2+u-x):s(0);},100),()=>{p.current&&(clearInterval(p.current),p.current=null);}},[n,i,m,o]);let T=o.slice(0,a);return jsx(AnimatePresence,{mode:"wait",children:n&&jsx(motion.button,{className:y(e),type:"button",onClick:t,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),"aria-label":o,initial:{opacity:0,y:m?0:5},animate:{opacity:1,y:0},exit:{opacity:0,y:m?0:5},transition:M,whileTap:{scale:.95},style:{minWidth:"44px"},children:c?jsx(motion.span,{initial:{scale:0},animate:{scale:1},transition:M,style:{display:"inline-flex",color:"var(--bf-accent)"},children:jsx(b,{size:14})},"success"):jsxs(Fragment,{children:[jsx("span",{className:"bf-dot","aria-hidden":"true"}),jsxs("span",{style:{whiteSpace:"nowrap",minWidth:"1ch"},children:[T,jsx("span",{className:"bf-cursor","aria-hidden":"true"})]}),r>0&&jsx("span",{className:"bf-badge","aria-label":`${r} queued`,children:r})]})},"typewriter")})}function Ze(e){switch(e){case "dot":return Be;case "bubble":return Le;case "edge-tab":return Ie;case "pulse-ring":return Oe;case "minimal":return $e;case "icon-pop":return Xe;case "beacon":return Qe;case "typewriter":return Je;default:return Ce}}function tt(e,t,n){return Math.max(t,Math.min(n,e))}function fo(e,t,n="bottom-right"){let r=window.innerWidth,c=window.innerHeight,i;i=tt(e.x,12,Math.max(12,r-t-12));let l=e.y+e.height+12,a=Math.max(12,e.y-240);return {top:l+240<=c?l:a,left:i}}function uo(e){let{rect:t}=e,n={left:`${t.x}px`,top:`${t.y}px`,width:`${Math.max(0,t.width)}px`,height:`${Math.max(0,t.height)}px`};return jsx("div",{className:"bf-highlight",style:n,"aria-hidden":"true"})}function bo(e){let t=useRef(null);return useEffect(()=>{if(!e||!t.current)return;t.current.querySelector(".bf-textarea")?.focus();let o=r=>{if(r.key!=="Tab"||!t.current)return;let c=t.current.querySelectorAll('button:not([disabled]), textarea:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])');if(c.length===0)return;let i=c[0],l=c[c.length-1];r.shiftKey&&document.activeElement===i?(r.preventDefault(),l.focus()):!r.shiftKey&&document.activeElement===l&&(r.preventDefault(),i.focus());};return document.addEventListener("keydown",o,{capture:true}),()=>document.removeEventListener("keydown",o,{capture:true})},[e]),t}function go(e,t){return e?typeof e=="function"?e(t):e.some(n=>n.endsWith("*")?t.startsWith(n.slice(0,-1)):t===n):true}function mo(e){let[t,n]=useState(()=>typeof window<"u"?window.location.pathname:"/");return useEffect(()=>{if(typeof window>"u")return;let o=()=>n(window.location.pathname);window.addEventListener("popstate",o);let r=history.pushState,c=history.replaceState;return history.pushState=function(...i){r.apply(this,i),o();},history.replaceState=function(...i){c.apply(this,i),o();},()=>{window.removeEventListener("popstate",o),history.pushState=r,history.replaceState=c;}},[]),go(e,t)}function ho(e){let[t,n]=useState(()=>!e||e==="dark"?"dark":e==="light"?"light":typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(e!=="auto"){n(e==="light"?"light":"dark");return}let o=window.matchMedia("(prefers-color-scheme: dark)"),r=c=>n(c.matches?"dark":"light");return n(o.matches?"dark":"light"),o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[e]),t}var xo=["bug","feature","ux","general"],yo={bug:"categoryBug",feature:"categoryFeature",ux:"categoryUx",general:"categoryGeneral"};function wo(e){let{state:t,controller:n,start:o,stop:r,clearSelection:c,submit:i$1}=te(),l=e.config.ui?.position,a=Te(e.config.ui?.strings),s=e.config.ui?.branding!==false,[m,M]=useState(null),[p$1,T]=useState(""),[u,E]=useState(e.config.capture?.element??true),[x,re]=useState(e.config.capture?.fullPage??false),[rt,ae]=useState(null),[O,ie]=useState(void 0),ne=e.config.ui?.categories??xo,[at,it]=useState(false),[j,nt]=useState(0);useEffect(()=>{let d=window.setTimeout(()=>{let N=p();nt(N.findings.length);},500);return ()=>window.clearTimeout(d)},[]),useImperativeHandle(e.handleRef,()=>({open:o,close:r,submit:d=>i$1(d),get isOpen(){return t.phase!=="idle"}}),[o,r,i$1,t.phase]);let se=t.phase==="review"||t.phase==="capturing"||t.phase==="submitting"||t.phase==="error"||t.phase==="success",st=bo(se),[lt,ct]=useState(0);useEffect(()=>{t.phase==="idle"&&ct(i());},[t.phase]);let[dt,le]=useState(false),ce=useRef(t.phase);useEffect(()=>{if(ce.current==="success"&&t.phase==="idle"){le(true);let d=window.setTimeout(()=>le(false),1500);return ()=>window.clearTimeout(d)}ce.current=t.phase;},[t.phase]),useEffect(()=>{let d=e.config.ui?.shortcut;if(!d)return;let N=d.toLowerCase().split("+").map(P=>P.trim()),W=N[N.length-1]||"",L=new Set(N.slice(0,-1)),pe=P=>{let ut=/Mac|iPod|iPhone|iPad/.test(navigator.platform);if(L.has("mod")){if(ut?!P.metaKey:!P.ctrlKey)return}else if(L.has("ctrl")&&!P.ctrlKey||(L.has("meta")||L.has("cmd"))&&!P.metaKey)return;L.has("shift")&&!P.shiftKey||(L.has("alt")||L.has("option"))&&!P.altKey||P.key.toLowerCase()===W&&(P.preventDefault(),t.phase==="idle"?o():r());};return document.addEventListener("keydown",pe),()=>document.removeEventListener("keydown",pe)},[e.config.ui?.shortcut,t.phase,o,r]),useEffect(()=>n.subscribeHover(M),[n]),useEffect(()=>{let d=n.__unsafeGetSelectedElement();if(!d||t.phase==="idle"||t.phase==="picking"){ae(null);return}let N=()=>{ae(b$1(d.getBoundingClientRect()));};N();let W=()=>N();return window.addEventListener("scroll",W,{capture:true,passive:true}),window.addEventListener("resize",W,{passive:true}),()=>{window.removeEventListener("scroll",W,{capture:true}),window.removeEventListener("resize",W);}},[n,t.phase,t.selection?.selector]),useEffect(()=>{t.phase==="review"&&(T(""),E(e.config.capture?.element??true),re(e.config.capture?.fullPage??false),ie(void 0));},[t.phase,t.selection?.selector,e.config.capture?.element,e.config.capture?.fullPage]),useEffect(()=>{if(t.phase!=="success")return;let d=window.setTimeout(()=>r(),1200);return ()=>window.clearTimeout(d)},[t.phase,r]);let S=t.phase==="capturing"||t.phase==="submitting",B=t.phase==="picking"?m?.rect??null:rt??t.selection?.rect??null,V=useMemo(()=>B?fo(B,360,l):null,[B?.x,B?.y,B?.width,B?.height,l]),de=t.lastError?.message,q=useCallback(()=>{let d={capture:{element:u,fullPage:x}};O&&(d.category=O),i$1(p$1,d);},[i$1,p$1,u,x,O]),pt=useCallback(d=>{(d.metaKey||d.ctrlKey)&&d.key==="Enter"&&p$1.trim().length>0&&!S&&(d.preventDefault(),q());},[q,p$1,S]),ft=Ze(e.config.ui?.triggerStyle);return jsxs(Fragment,{children:[jsx(ft,{position:l,onClick:()=>o(),isVisible:t.phase==="idle",label:e.config.ui?.triggerLabel??a.triggerLabel,queueCount:lt,showSuccess:dt}),t.phase!=="idle"&&jsxs("div",{className:"bf-overlay",role:"presentation",children:[t.phase!=="picking"&&jsx("div",{className:"bf-blocker",role:"presentation",onClick:()=>r()}),B&&jsx(uo,{rect:B}),t.phase==="picking"&&jsxs("div",{className:"bf-hint",role:"status","aria-live":"polite",children:[jsx("p",{id:"bf-hint-text",children:a.hintText}),jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),"aria-label":a.cancelButton,children:a.cancelButton})]}),se&&V&&jsxs("div",{ref:st,className:"bf-panel",style:{left:V.left,top:V.top},role:"dialog","aria-modal":"true","aria-label":"Feedback form",children:[jsxs("div",{className:"bf-panelHeader",children:[jsx("div",{className:"bf-title",id:"bf-panel-title",children:a.panelTitle}),jsxs("div",{className:"bf-row",style:{justifyContent:"flex-end"},children:[jsx("button",{type:"button",className:"bf-btn",onClick:()=>c(),disabled:S,"aria-label":a.rePickButton,children:a.rePickButton}),jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),disabled:S,"aria-label":a.closeButton,children:a.closeButton})]})]}),jsxs("div",{className:"bf-panelBody",children:[jsx("textarea",{className:"bf-textarea",placeholder:a.textareaPlaceholder,value:p$1,onChange:d=>T(d.target.value),onKeyDown:pt,disabled:S,"aria-label":a.panelTitle}),ne.length>0&&jsx("div",{className:"bf-pills",role:"group","aria-label":"Feedback category",children:ne.map(d=>jsx("button",{type:"button",className:`bf-pill${O===d?" bf-pill-active":""}`,onClick:()=>ie(O===d?void 0:d),disabled:S,children:a[yo[d]]},d))}),jsxs("div",{className:"bf-row",role:"group","aria-label":a.screenshotElement,children:[jsxs("label",{children:[jsx("input",{type:"checkbox",checked:u,onChange:d=>E(d.target.checked),disabled:S}),a.screenshotElement]}),jsxs("label",{children:[jsx("input",{type:"checkbox",checked:x,onChange:d=>re(d.target.checked),disabled:S}),a.screenshotFullPage]})]}),t.phase==="capturing"&&jsxs("div",{className:"bf-status",role:"status","aria-live":"polite",children:[jsx("span",{className:"bf-spinner","aria-hidden":"true"}),a.capturingText]}),t.phase==="submitting"&&jsxs("div",{className:"bf-status",role:"status","aria-live":"polite",children:[jsx("span",{className:"bf-spinner","aria-hidden":"true"}),a.submittingText]}),t.phase==="success"&&jsx("div",{className:"bf-status",role:"status","aria-live":"polite",children:a.successText}),t.phase==="error"&&de&&jsx("div",{className:"bf-error",role:"alert",children:de}),jsxs("div",{className:"bf-actions",children:[jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),disabled:S,"aria-label":a.cancelButton,children:a.cancelButton}),jsx("button",{type:"button",className:"bf-btn bf-btnPrimary",onClick:q,disabled:S||p$1.trim().length===0,"aria-label":a.sendButton,children:a.sendButton})]})]}),s&&jsx("div",{className:"bf-watermark",children:jsx("a",{href:"https://blocfeed.com",target:"_blank",rel:"noopener noreferrer",children:"Powered by BlocFeed"})})]})]}),t.phase==="success"&&jsx("div",{className:"bf-toast",role:"status","aria-live":"polite",children:a.toastText}),j>0&&!at&&jsxs("div",{className:"bf-security-banner",role:"alert",children:[jsx("button",{type:"button",className:"bf-security-banner-dismiss",onClick:()=>it(true),"aria-label":"Dismiss",children:"\xD7"}),jsx("strong",{children:"Security Warning"}),j," potential secret",j>1?"s":""," exposed in client code. Check your environment variables."]})]})}var vo=forwardRef(function(t,n){let o$1={...t.config??{},blocfeed_id:t.blocfeed_id},[r,c]=useState(null),i=mo(o$1.ui?.showOn),l$1=ho(o$1.ui?.theme?.mode),a=!!o$1.diagnostics;useEffect(()=>{if(a)return k(o$1.diagnostics),()=>l()},[a]);let s=!!o$1.security;useEffect(()=>{s&&o(o$1.security);},[s]);let m$1=useRef(t.config?.metadata?.enrich);m$1.current=t.config?.metadata?.enrich;let M=useMemo(()=>{if(t.config)return {...t.config,metadata:{...t.config.metadata,enrich:async p$1=>{let T=m$1.current,u=T?await T(p$1):{},E=m(),x=p();return {...u,...E.consoleLogs.length>0?{_consoleLogs:E.consoleLogs}:{},...E.networkErrors.length>0?{_networkErrors:E.networkErrors}:{},...x.findings.length>0?{_securityFindings:x.findings}:{}}}}}},[]);return useEffect(()=>{ve();let p=document.createElement("div");p.setAttribute("data-blocfeed-ui-root","true"),p.setAttribute("data-blocfeed-ui","true"),p.setAttribute("data-bf-theme",l$1);let T=o$1.ui?.zIndex;typeof T=="number"&&p.style.setProperty("--bf-z",String(T));let u=o$1.ui?.theme;return u&&(u.accentColor&&p.style.setProperty("--bf-accent",u.accentColor),u.panelBackground&&p.style.setProperty("--bf-panel-bg",u.panelBackground),u.panelForeground&&p.style.setProperty("--bf-panel-fg",u.panelForeground),u.fontFamily&&p.style.setProperty("--bf-font",u.fontFamily)),document.body.appendChild(p),c(p),()=>{p.remove(),c(null);}},[o$1.ui?.zIndex,o$1.ui?.theme?.accentColor,o$1.ui?.theme?.panelBackground,o$1.ui?.theme?.panelForeground,o$1.ui?.theme?.fontFamily,l$1]),useEffect(()=>{r&&r.setAttribute("data-bf-theme",l$1);},[r,l$1]),!i||!r?null:createPortal(jsx(ee,{blocfeed_id:o$1.blocfeed_id,...M?{config:M}:{},children:jsx(wo,{config:o$1,handleRef:n})}),r)});
639
+ export{ee as BlocFeedProvider,vo as BlocFeedWidget,te as useBlocFeed};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blocfeed",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "Drop-in feedback + screenshot widget for React.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,2 +0,0 @@
1
- 'use strict';function m(){return typeof window<"u"&&typeof document<"u"}function te(e){let t=globalThis.CSS;return typeof t?.escape=="function"?t.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,n=>{let r=n.codePointAt(0);return r===void 0?"":`\\${r.toString(16)} `})}function Q(e){return {x:e.x,y:e.y,width:e.width,height:e.height}}function Te(e){return {x:e.x+window.scrollX,y:e.y+window.scrollY,width:e.width,height:e.height}}function Re(e){return e.replace(/\s+/g," ").trim()}function Ae(e,t=140){let n=e.textContent;if(!n)return;let r=Re(n);if(r)return r.length<=t?r:`${r.slice(0,t-1)}\u2026`}function Ce(e){let t=1;for(let n=e.previousElementSibling;n;n=n.previousElementSibling)n.tagName===e.tagName&&(t+=1);return t}var oe=["data-testid","data-test-id","data-test","data-qa","data-cy"],ne="data-blocfeed-component";function Me(e){let t=e.closest(`[${ne}]`);if(!t)return;let r=t.getAttribute(ne)?.trim();return r||void 0}function Be(e){for(let t of oe){let n=e.closest(`[${t}]`);if(!n)continue;let o=n.getAttribute(t)?.trim();if(o)return o}}function Le(e){try{let t=e,n=Object.getOwnPropertyNames(t);for(let r of n)if(r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$")){let o=t[r];if(o&&typeof o=="object")return o}}catch{}return null}function B(e){if(e&&typeof e!="string"){if(typeof e=="function"){let t=e;return typeof t.displayName=="string"&&t.displayName?t.displayName:typeof t.name=="string"&&t.name?t.name:void 0}if(typeof e=="object"){let t=e,n=t.displayName;if(typeof n=="string"&&n)return n;let r=t.render;if(typeof r=="function"){let i=r;if(typeof i.displayName=="string"&&i.displayName)return i.displayName;if(typeof i.name=="string"&&i.name)return i.name}let o=t.type;return B(o)}}}function _e(e){let t=Le(e);if(!t)return;let n=t._debugOwner!==void 0;if(n){let i=t._debugOwner;for(let a=0;i&&a<50;a+=1){let s=B(i.type)??B(i.elementType);if(s)return s;i=i._debugOwner;}}let r=t,o=n?80:10;for(let i=0;r&&i<o;i+=1){let a=B(r.type)??B(r.elementType);if(a)return a;r=r.return;}}function Ie(e){let t=e.tagName.toLowerCase(),n=e.getAttribute("id");if(n)return `#${te(n)}`;for(let r of oe){let o=e.getAttribute(r);if(o)return `${t}[${r}="${te(o)}"]`}return `${t}:nth-of-type(${Ce(e)})`}function De(e,t=10){let n=[],r=e;for(;r&&n.length<t;){let o=Ie(r);if(n.unshift(o),o.startsWith("#"))break;r=r.parentElement;}return n.join(" > ")}function re(e,t){if(!t||t.length===0)return false;for(let n of t)if(e.closest(n))return true;return false}function W(e,t){if(!e||re(e,t.ignoreSelectors))return null;let n=e;for(;n;){if(re(n,t.ignoreSelectors))return null;if(t.isSelectable?.(n)??Ne(n))return n;n=n.parentElement;}return null}function Ne(e){let t=e.tagName;return !(t==="HTML"||t==="BODY")}function ie(e){let t=e.getBoundingClientRect(),n={selector:De(e),tagName:e.tagName.toLowerCase(),rect:Q(t),pageRect:Te(t)},r=e.getAttribute("id");r&&(n.id=r);let o=e.className;typeof o=="string"&&o.trim()&&(n.className=o);let i=Ae(e);i&&(n.textSnippet=i);let a=Me(e)??_e(e);a&&(n.componentName=a);let s=Be(e);return s&&(n.testId=s),n}var z=null;async function ae(){return z||(z=import('html-to-image')),z}async function Ue(e){return await new Promise((t,n)=>{let r=new Image;r.onload=()=>t({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>n(new Error("Failed to load generated screenshot")),r.src=e;})}async function se(e,t){let{width:n,height:r}=await Ue(e);return {dataUrl:e,mime:t,width:n,height:r}}function A(e){if(e?.aborted)throw new Error("Aborted")}function le(){return {async captureElement(e,t){if(!m())throw new Error("captureElement can only run in the browser");A(t.signal);let n=await ae();A(t.signal);let r=t.mime==="image/jpeg"?await n.toJpeg(e,{quality:t.quality??.92,pixelRatio:t.pixelRatio}):await n.toPng(e,{pixelRatio:t.pixelRatio});return A(t.signal),await se(r,t.mime)},async captureFullPage(e){if(!m())throw new Error("captureFullPage can only run in the browser");A(e.signal);let t=document.documentElement,n=Math.max(t.scrollWidth,t.clientWidth),r=Math.max(t.scrollHeight,t.clientHeight),o=Math.min(1,e.maxDimension/Math.max(n,r)),i=Math.max(1,Math.round(n*o)),a=Math.max(1,Math.round(r*o)),s=await ae();A(e.signal);let f=e.mime==="image/jpeg"?await s.toJpeg(t,{width:i,height:a,quality:e.quality??.92,pixelRatio:e.pixelRatio}):await s.toPng(t,{width:i,height:a,pixelRatio:e.pixelRatio});return A(e.signal),await se(f,e.mime)}}}function Oe(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return "Unknown error"}}function p(e,t,n){let r={kind:e,message:Oe(t)};return n&&(r.detail=n),r}var He=12e3,qe=2048,$e=.92;function ce(){return Date.now()}function je(e){return new Promise((t,n)=>{let r=()=>n(new Error("Aborted"));if(e.aborted){r();return}e.addEventListener("abort",r,{once:true});})}async function ue(e,t,n){let r=new Promise((i,a)=>{let s=setTimeout(()=>a(new Error("Timeout")),t);typeof s.unref=="function"&&s.unref();}),o=[e,r];return n&&o.push(je(n)),await Promise.race(o)}function Qe(e){if(!m())return 1;let t=window.devicePixelRatio||1,n=e?.pixelRatio??Math.min(t,2);return Math.max(.1,n)}function We(e){return !!(e?.element||e?.fullPage)}function de(e){let t={mime:e.mime,pixelRatio:e.pixelRatio,maxDimension:e.maxDimension};return e.includeQuality&&(t.quality=e.quality),e.signal&&(t.signal=e.signal),t}async function fe(e){let{selectionElement:t,capture:n,signal:r}=e;if(!m()||!We(n))return;let o=ce(),i=[],a=n?.timeoutMs??He,s=n?.maxDimension??qe,f=n?.mime??"image/png",g=n?.quality??$e,w=n?.adapter??le(),y={},E=Qe(n);if(n?.element&&t)try{let c=t.getBoundingClientRect(),u=Math.min(1,s/Math.max(c.width,c.height)),v=Math.min(E,E*u),x=await ue(Promise.resolve(w.captureElement(t,{...de({mime:f,quality:g,pixelRatio:v,maxDimension:s,includeQuality:f==="image/jpeg",...r?{signal:r}:{}})})),a,r);y.element=x;}catch(c){if(r?.aborted)throw c;i.push(p("capture_failed",c,{target:"element"}));}if(n?.fullPage)try{let c=await ue(Promise.resolve(w.captureFullPage(de({mime:f,quality:g,pixelRatio:E,maxDimension:s,includeQuality:f==="image/jpeg",...r?{signal:r}:{}}))),a,r);y.fullPage=c;}catch(c){if(r?.aborted)throw c;i.push(p("capture_failed",c,{target:"fullPage"}));}let h=ce(),l={startedAt:o,finishedAt:h,durationMs:Math.max(0,h-o)};return i.length>0&&(l.errors=i),{...y,diagnostics:l}}function ze(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}}function Je(){return m()?{url:window.location.href,title:document.title,referrer:document.referrer||void 0,userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,viewport:{width:window.innerWidth,height:window.innerHeight},screen:{width:window.screen.width,height:window.screen.height},scroll:{x:window.scrollX,y:window.scrollY},devicePixelRatio:window.devicePixelRatio||1,timezone:ze()}:{}}function Ye(e){if(!e)return {};let t={};return e.id&&(t.userId=e.id),e.email&&(t.userEmail=e.email),e.name&&(t.userName=e.name),t}async function me(e){let{config:t,context:n,user:r}=e;if(t?.enabled===false)return {};let o={...Je(),...Ye(r)},i=t?.enrich;if(!i)return o;try{let a=await i(n);return {...o,...a}}catch(a){let s=p("unknown",a);return {...o,blocfeedMetadataError:s.message}}}var J="blocfeed-queue",Ke=50;function Y(){if(!m())return [];try{let e=localStorage.getItem(J);if(!e)return [];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return []}}function K(e){if(m())try{e.length===0?localStorage.removeItem(J):localStorage.setItem(J,JSON.stringify(e));}catch{}}function Xe(e){let t={...e};if(t.screenshots){let n={...t.screenshots};n.element&&(n.element={...n.element,dataUrl:""}),n.fullPage&&(n.fullPage={...n.fullPage,dataUrl:""}),t.screenshots=n;}return t}function X(e){let t=Y(),n=Xe(e);for(n.metadata={...n.metadata,_queued:true},t.push({payload:n,timestamp:Date.now()});t.length>Ke;)t.shift();K(t);}function pe(){let e=Y();return e.length===0?[]:(K([]),e.map(t=>t.payload))}function vt(){K([]);}function Pt(){return Y().length}function G(e){let t=null,n=null,r=(...o)=>{n=o,t===null&&(t=requestAnimationFrame(()=>{if(t=null,!n)return;let i=n;n=null,e(...i);}));};return r.cancel=()=>{t!==null&&cancelAnimationFrame(t),t=null,n=null;},r}function U(e){return e instanceof Element?!!e.closest("[data-blocfeed-ui]"):false}function O(e){e.stopPropagation(),e.stopImmediatePropagation?.();}function ge(e,t){if(!m())throw new Error("BlocFeed picker can only run in a browser environment.");let n=e.ignoreSelectors,r=e.isSelectable,o={};n&&n.length>0&&(o.ignoreSelectors=n),r&&(o.isSelectable=r);let i=null,a=null,s=(l,c=false)=>{if(!l){i=null,a=null,t.onHover(null);return}let u=Q(l.getBoundingClientRect()),v=`${Math.round(u.x)}:${Math.round(u.y)}:${Math.round(u.width)}:${Math.round(u.height)}`;!c&&l===i&&v===a||(i=l,a=v,t.onHover({element:l,rect:u}));},f=G(l=>{if(U(l.target))return;let c=document.elementFromPoint(l.clientX,l.clientY),u=W(c,o);s(u);}),g=G(()=>{i&&s(i,true);}),w=l=>{U(l.target)||(O(l),l.pointerType==="mouse"&&l.preventDefault());},y=l=>{U(l.target)||(O(l),l.pointerType==="mouse"&&l.preventDefault());},E=l=>{if(U(l.target))return;O(l),l.preventDefault();let c=document.elementFromPoint(l.clientX,l.clientY),u=W(c,o);u&&t.onSelect({element:u,descriptor:ie(u)});},h=l=>{l.key==="Escape"&&(O(l),l.preventDefault(),t.onCancel());};return window.addEventListener("pointermove",f,{capture:true,passive:true}),window.addEventListener("pointerdown",w,{capture:true}),window.addEventListener("pointerup",y,{capture:true}),window.addEventListener("click",E,{capture:true}),window.addEventListener("keydown",h,{capture:true}),window.addEventListener("scroll",g,{capture:true,passive:true}),window.addEventListener("resize",g,{passive:true}),{stop(){window.removeEventListener("pointermove",f,{capture:true}),window.removeEventListener("pointerdown",w,{capture:true}),window.removeEventListener("pointerup",y,{capture:true}),window.removeEventListener("click",E,{capture:true}),window.removeEventListener("keydown",h,{capture:true}),window.removeEventListener("scroll",g,{capture:true}),window.removeEventListener("resize",g),f.cancel(),g.cancel(),t.onHover(null);}}}var Ge=12e3,Ze=2,Ve=500,et=2e3,ye="https://blocfeed.com/api/feedback",he=0;function we(e,t){return new Promise((n,r)=>{if(t?.aborted){r(new Error("Aborted"));return}let o=setTimeout(n,e),i=()=>{clearTimeout(o),r(new Error("Aborted"));};t?.addEventListener("abort",i,{once:true});})}function tt(e){return e>=500&&e<=599}function nt(e){let[t,n]=e.split(",",2);if(!t||!n)throw new Error("Invalid data URL");let o=/data:(.*?);base64/.exec(t)?.[1]||"application/octet-stream",i=atob(n),a=new Uint8Array(i.length);for(let s=0;s<i.length;s+=1)a[s]=i.charCodeAt(s);return new Blob([a],{type:o})}function rt(e){let t={},n={...e};if(n.screenshots){let r={},o={...n.screenshots};o.element&&(t.element=o.element.dataUrl,r.element={mime:o.element.mime,width:o.element.width,height:o.element.height},o.element={...o.element,dataUrl:""}),o.fullPage&&(t.fullPage=o.fullPage.dataUrl,r.fullPage={mime:o.fullPage.mime,width:o.fullPage.width,height:o.fullPage.height},o.fullPage={...o.fullPage,dataUrl:""}),n.screenshots=o,(r.element||r.fullPage)&&(n.screenshot_intent=r);}return {lean:n,extracted:t}}async function be(e,t,n){let r=nt(t);await fetch(e,{method:"PUT",body:r,headers:{"content-type":r.type},...n?{signal:n}:{}});}async function ot(e){let{feedbackId:t,extracted:n,screenshots:r,signal:o}=e,i={};n.element&&r?.element&&(i.element={dataUrl:n.element,mime:r.element.mime,width:r.element.width,height:r.element.height}),n.fullPage&&r?.fullPage&&(i.fullPage={dataUrl:n.fullPage,mime:r.fullPage.mime,width:r.fullPage.width,height:r.fullPage.height}),Object.keys(i).length!==0&&await fetch(`${ye}/${t}/screenshots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i),...o?{signal:o}:{}});}async function Ee(e){let{signal:t,transport:n}=e;if(Date.now()-he<et)return {ok:false,error:p("configuration",new Error("Please wait before submitting again"))};let o=n?.timeoutMs??Ge,i=n?.maxAttempts??Ze,a=n?.backoffMs??Ve,s=!!(e.payload.screenshots?.element?.dataUrl||e.payload.screenshots?.fullPage?.dataUrl),{lean:f,extracted:g}=s?rt(e.payload):{lean:e.payload,extracted:{}},w={...g,...e.screenshotDataUrls};for(let y=1;y<=i;y+=1){let E=new AbortController,h=setTimeout(()=>E.abort(),o),l=()=>E.abort();t&&t.addEventListener("abort",l,{once:true});try{let c=await fetch(ye,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(f),signal:E.signal});if(c.ok){he=Date.now();let u;try{u=await c.json();}catch{}if((w.element||w.fullPage)&&u){let d=u.upload_urls;if(d){let S=[];w.element&&d.element&&S.push(be(d.element,w.element,t)),w.fullPage&&d.fullPage&&S.push(be(d.fullPage,w.fullPage,t));try{await Promise.all(S);}catch{}}else if(u.feedback_id)try{await ot({feedbackId:u.feedback_id,extracted:w,screenshots:e.payload.screenshots,...t?{signal:t}:{}});}catch{}}let x={ok:!0,status:c.status};return u&&(x.apiResponse=u),x}if(y<i&&tt(c.status)){let u=.85+Math.random()*.3,v=Math.round(a*2**(y-1)*u);await we(v,t);continue}return {ok:!1,status:c.status,error:p("api_failed",new Error(`HTTP ${c.status}`))}}catch(c){if(E.signal.aborted||t?.aborted)return {ok:false,error:p("aborted",c)};if(y<i){let u=.85+Math.random()*.3,v=Math.round(a*2**(y-1)*u);await we(v,t);continue}return {ok:false,error:p("api_failed",c)}}finally{clearTimeout(h),t&&t.removeEventListener("abort",l);}}return {ok:false,error:p("api_failed",new Error("Failed"))}}async function Z(e){let{signal:t,transport:n}=e,r={ok:false};try{let o={payload:e.payload,...t?{signal:t}:{},...n?{transport:n}:{}};r.api=await Ee(o),r.ok=!!r.api?.ok;}catch(o){r.api={ok:false,error:p("api_failed",o)},r.ok=false;}return {payload:e.payload,result:r}}var it=["[data-blocfeed-ui]","[data-blocfeed-ignore]"];function at(e){let t=[...it,...e?.ignoreSelectors??[]],n=Array.from(new Set(t));return {...e,ignoreSelectors:n}}function ke(){return {phase:"idle"}}function st(e){if(e.ok)return false;let t=e.api;return t?t.status&&t.status>=400&&t.status<500||t.error?.kind==="aborted"||t.error?.kind==="configuration"?false:!t.ok:true}function $t(e){let t=e,n=ke(),r=new Set,o=new Set,i=null,a=null,s=null,f=null,g=0,w=null,y=()=>{for(let d of r)d(n);},E=d=>{for(let S of o)S(d);},h=d=>{n=d,y();},l=()=>{g+=1,f?.abort(),f=null;},c=()=>{i?.stop(),i=null,E(null),s!==null&&m()&&(document.documentElement.style.cursor=s,s=null);},u=()=>{l(),c(),a=null,h(ke());},v=()=>{if(!m())return;c(),a=null;let d=at(t.picker);s=document.documentElement.style.cursor,document.documentElement.style.cursor="crosshair",h({phase:"picking"}),i=ge(d,{onHover:E,onSelect:({element:S,descriptor:N})=>{a=S,c(),h({phase:"review",selection:N});},onCancel:()=>{u();}});},x=()=>{let d=pe();if(d.length!==0)for(let S of d)Z({payload:S,...t.transport?{transport:t.transport}:{}}).catch(()=>{X(S);});};if(m()){setTimeout(x,1e3);let d=()=>x();window.addEventListener("online",d),w=()=>window.removeEventListener("online",d);}return {getState:()=>n,subscribe(d){return r.add(d),()=>r.delete(d)},subscribeHover(d){return o.add(d),()=>o.delete(d)},start(){n.phase==="capturing"||n.phase==="submitting"||n.phase!=="picking"&&v();},stop(){u();},clearSelection(){n.phase==="capturing"||n.phase==="submitting"||v();},setConfig(d){t=d;},async submit(d,S){if(!m()){let b=p("configuration",new Error("BlocFeed submit can only run in the browser"));return h({phase:"error",lastError:b}),{ok:false}}let N=t.blocfeed_id?.trim?.()??"";if(!N){let F={phase:"error",lastError:p("configuration",new Error("Missing blocfeed_id. Create a project in BlocFeed and pass its blocfeed_id."))};return n.selection&&(F.selection=n.selection),h(F),{ok:false}}if(n.phase==="capturing"||n.phase==="submitting")return {ok:false};let C=g+1;g=C,f?.abort(),f=new AbortController;let T=f.signal,k=n.selection,q=S?.capture?{...t.capture,...S.capture}:t.capture,V=!!(q?.element||q?.fullPage),ee={phase:V?"capturing":"submitting"};k&&(ee.selection=k),h(ee);try{let b=V?await fe({selectionElement:a,capture:q,signal:T}):void 0;if(T.aborted||g!==C)return {ok:!1};let F={phase:"submitting"};k&&(F.selection=k),b&&(F.capture=b),h(F);let R={};k&&(R.selection=k),b&&(R.capture=b);let xe=await me({config:t.metadata,context:R,...t.user?{user:t.user}:{}}),M={version:1,createdAt:new Date().toISOString(),blocfeed_id:N,message:d,metadata:xe};t.user&&(M.user=t.user),k&&(M.selection=k),b&&(M.screenshots=b);let{result:P}=await Z({payload:M,signal:T,...t.transport?{transport:t.transport}:{}});if(T.aborted||g!==C)return P;if(P.ok){let j={phase:"success",lastSubmit:P};return k&&(j.selection=k),b&&(j.capture=b),h(j),P}st(P)&&X(M);let Fe=P.api?.error??p("unknown",new Error("Submission failed")),$={phase:"error",lastSubmit:P,lastError:Fe};return k&&($.selection=k),b&&($.capture=b),h($),P}catch(b){if(T.aborted||g!==C)return {ok:false};let R={phase:"error",lastError:T.aborted?p("aborted",b):p("unknown",b)};return k&&(R.selection=k),h(R),{ok:false}}finally{g===C&&(f=null);}},__unsafeGetSelectedElement(){return a},destroy(){u(),r.clear(),o.clear(),w?.(),w=null;}}}var L=[],_=[],ve=20,Pe=15,I={},D=null,H=false;function lt(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function ct(e,t){let n=t.map(lt).join(" "),r=t.find(i=>i instanceof Error),o={level:e,message:n.slice(0,2e3),timestamp:Date.now()};for(r?.stack&&(o.stack=r.stack.slice(0,2e3)),L.push(o);L.length>ve;)L.shift();}function Se(e){if(!e.url.includes("blocfeed.com"))for(_.push(e);_.length>Pe;)_.shift();}function Wt(e={}){if(!(H||!m())){if(H=true,ve=e.consoleLimit??20,Pe=e.networkLimit??15,e.console!==false){let t=e.consoleLevels??["error","warn"];for(let n of t)I[n]=console[n],console[n]=(...r)=>{ct(n,r),I[n]?.apply(console,r);};}if(e.network!==false&&typeof window.fetch=="function"){D=window.fetch;let t=D;window.fetch=async function(r,o){let i=typeof r=="string"?r:r instanceof URL?r.toString():r.url,a=(o?.method??"GET").toUpperCase(),s=Date.now();try{let f=await t.call(window,r,o);return f.ok||Se({url:i.slice(0,500),method:a,status:f.status,statusText:f.statusText,timestamp:s,durationMs:Date.now()-s}),f}catch(f){throw Se({url:i.slice(0,500),method:a,status:0,statusText:f instanceof Error?f.message:"Network error",timestamp:s,durationMs:Date.now()-s}),f}};}}}function zt(){if(H){for(let[e,t]of Object.entries(I))console[e]=t;for(let e of Object.keys(I))delete I[e];D&&(window.fetch=D,D=null),H=false;}}function Jt(){return {consoleLogs:[...L],networkErrors:[..._]}}function Yt(){L=[],_=[];}
2
- exports.a=m;exports.b=Q;exports.c=le;exports.d=fe;exports.e=me;exports.f=X;exports.g=pe;exports.h=vt;exports.i=Pt;exports.j=$t;exports.k=Wt;exports.l=zt;exports.m=Jt;exports.n=Yt;
@@ -1,2 +0,0 @@
1
- function m(){return typeof window<"u"&&typeof document<"u"}function te(e){let t=globalThis.CSS;return typeof t?.escape=="function"?t.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,n=>{let r=n.codePointAt(0);return r===void 0?"":`\\${r.toString(16)} `})}function Q(e){return {x:e.x,y:e.y,width:e.width,height:e.height}}function Te(e){return {x:e.x+window.scrollX,y:e.y+window.scrollY,width:e.width,height:e.height}}function Re(e){return e.replace(/\s+/g," ").trim()}function Ae(e,t=140){let n=e.textContent;if(!n)return;let r=Re(n);if(r)return r.length<=t?r:`${r.slice(0,t-1)}\u2026`}function Ce(e){let t=1;for(let n=e.previousElementSibling;n;n=n.previousElementSibling)n.tagName===e.tagName&&(t+=1);return t}var oe=["data-testid","data-test-id","data-test","data-qa","data-cy"],ne="data-blocfeed-component";function Me(e){let t=e.closest(`[${ne}]`);if(!t)return;let r=t.getAttribute(ne)?.trim();return r||void 0}function Be(e){for(let t of oe){let n=e.closest(`[${t}]`);if(!n)continue;let o=n.getAttribute(t)?.trim();if(o)return o}}function Le(e){try{let t=e,n=Object.getOwnPropertyNames(t);for(let r of n)if(r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$")){let o=t[r];if(o&&typeof o=="object")return o}}catch{}return null}function B(e){if(e&&typeof e!="string"){if(typeof e=="function"){let t=e;return typeof t.displayName=="string"&&t.displayName?t.displayName:typeof t.name=="string"&&t.name?t.name:void 0}if(typeof e=="object"){let t=e,n=t.displayName;if(typeof n=="string"&&n)return n;let r=t.render;if(typeof r=="function"){let i=r;if(typeof i.displayName=="string"&&i.displayName)return i.displayName;if(typeof i.name=="string"&&i.name)return i.name}let o=t.type;return B(o)}}}function _e(e){let t=Le(e);if(!t)return;let n=t._debugOwner!==void 0;if(n){let i=t._debugOwner;for(let a=0;i&&a<50;a+=1){let s=B(i.type)??B(i.elementType);if(s)return s;i=i._debugOwner;}}let r=t,o=n?80:10;for(let i=0;r&&i<o;i+=1){let a=B(r.type)??B(r.elementType);if(a)return a;r=r.return;}}function Ie(e){let t=e.tagName.toLowerCase(),n=e.getAttribute("id");if(n)return `#${te(n)}`;for(let r of oe){let o=e.getAttribute(r);if(o)return `${t}[${r}="${te(o)}"]`}return `${t}:nth-of-type(${Ce(e)})`}function De(e,t=10){let n=[],r=e;for(;r&&n.length<t;){let o=Ie(r);if(n.unshift(o),o.startsWith("#"))break;r=r.parentElement;}return n.join(" > ")}function re(e,t){if(!t||t.length===0)return false;for(let n of t)if(e.closest(n))return true;return false}function W(e,t){if(!e||re(e,t.ignoreSelectors))return null;let n=e;for(;n;){if(re(n,t.ignoreSelectors))return null;if(t.isSelectable?.(n)??Ne(n))return n;n=n.parentElement;}return null}function Ne(e){let t=e.tagName;return !(t==="HTML"||t==="BODY")}function ie(e){let t=e.getBoundingClientRect(),n={selector:De(e),tagName:e.tagName.toLowerCase(),rect:Q(t),pageRect:Te(t)},r=e.getAttribute("id");r&&(n.id=r);let o=e.className;typeof o=="string"&&o.trim()&&(n.className=o);let i=Ae(e);i&&(n.textSnippet=i);let a=Me(e)??_e(e);a&&(n.componentName=a);let s=Be(e);return s&&(n.testId=s),n}var z=null;async function ae(){return z||(z=import('html-to-image')),z}async function Ue(e){return await new Promise((t,n)=>{let r=new Image;r.onload=()=>t({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>n(new Error("Failed to load generated screenshot")),r.src=e;})}async function se(e,t){let{width:n,height:r}=await Ue(e);return {dataUrl:e,mime:t,width:n,height:r}}function A(e){if(e?.aborted)throw new Error("Aborted")}function le(){return {async captureElement(e,t){if(!m())throw new Error("captureElement can only run in the browser");A(t.signal);let n=await ae();A(t.signal);let r=t.mime==="image/jpeg"?await n.toJpeg(e,{quality:t.quality??.92,pixelRatio:t.pixelRatio}):await n.toPng(e,{pixelRatio:t.pixelRatio});return A(t.signal),await se(r,t.mime)},async captureFullPage(e){if(!m())throw new Error("captureFullPage can only run in the browser");A(e.signal);let t=document.documentElement,n=Math.max(t.scrollWidth,t.clientWidth),r=Math.max(t.scrollHeight,t.clientHeight),o=Math.min(1,e.maxDimension/Math.max(n,r)),i=Math.max(1,Math.round(n*o)),a=Math.max(1,Math.round(r*o)),s=await ae();A(e.signal);let f=e.mime==="image/jpeg"?await s.toJpeg(t,{width:i,height:a,quality:e.quality??.92,pixelRatio:e.pixelRatio}):await s.toPng(t,{width:i,height:a,pixelRatio:e.pixelRatio});return A(e.signal),await se(f,e.mime)}}}function Oe(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return "Unknown error"}}function p(e,t,n){let r={kind:e,message:Oe(t)};return n&&(r.detail=n),r}var He=12e3,qe=2048,$e=.92;function ce(){return Date.now()}function je(e){return new Promise((t,n)=>{let r=()=>n(new Error("Aborted"));if(e.aborted){r();return}e.addEventListener("abort",r,{once:true});})}async function ue(e,t,n){let r=new Promise((i,a)=>{let s=setTimeout(()=>a(new Error("Timeout")),t);typeof s.unref=="function"&&s.unref();}),o=[e,r];return n&&o.push(je(n)),await Promise.race(o)}function Qe(e){if(!m())return 1;let t=window.devicePixelRatio||1,n=e?.pixelRatio??Math.min(t,2);return Math.max(.1,n)}function We(e){return !!(e?.element||e?.fullPage)}function de(e){let t={mime:e.mime,pixelRatio:e.pixelRatio,maxDimension:e.maxDimension};return e.includeQuality&&(t.quality=e.quality),e.signal&&(t.signal=e.signal),t}async function fe(e){let{selectionElement:t,capture:n,signal:r}=e;if(!m()||!We(n))return;let o=ce(),i=[],a=n?.timeoutMs??He,s=n?.maxDimension??qe,f=n?.mime??"image/png",g=n?.quality??$e,w=n?.adapter??le(),y={},E=Qe(n);if(n?.element&&t)try{let c=t.getBoundingClientRect(),u=Math.min(1,s/Math.max(c.width,c.height)),v=Math.min(E,E*u),x=await ue(Promise.resolve(w.captureElement(t,{...de({mime:f,quality:g,pixelRatio:v,maxDimension:s,includeQuality:f==="image/jpeg",...r?{signal:r}:{}})})),a,r);y.element=x;}catch(c){if(r?.aborted)throw c;i.push(p("capture_failed",c,{target:"element"}));}if(n?.fullPage)try{let c=await ue(Promise.resolve(w.captureFullPage(de({mime:f,quality:g,pixelRatio:E,maxDimension:s,includeQuality:f==="image/jpeg",...r?{signal:r}:{}}))),a,r);y.fullPage=c;}catch(c){if(r?.aborted)throw c;i.push(p("capture_failed",c,{target:"fullPage"}));}let h=ce(),l={startedAt:o,finishedAt:h,durationMs:Math.max(0,h-o)};return i.length>0&&(l.errors=i),{...y,diagnostics:l}}function ze(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}}function Je(){return m()?{url:window.location.href,title:document.title,referrer:document.referrer||void 0,userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,viewport:{width:window.innerWidth,height:window.innerHeight},screen:{width:window.screen.width,height:window.screen.height},scroll:{x:window.scrollX,y:window.scrollY},devicePixelRatio:window.devicePixelRatio||1,timezone:ze()}:{}}function Ye(e){if(!e)return {};let t={};return e.id&&(t.userId=e.id),e.email&&(t.userEmail=e.email),e.name&&(t.userName=e.name),t}async function me(e){let{config:t,context:n,user:r}=e;if(t?.enabled===false)return {};let o={...Je(),...Ye(r)},i=t?.enrich;if(!i)return o;try{let a=await i(n);return {...o,...a}}catch(a){let s=p("unknown",a);return {...o,blocfeedMetadataError:s.message}}}var J="blocfeed-queue",Ke=50;function Y(){if(!m())return [];try{let e=localStorage.getItem(J);if(!e)return [];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return []}}function K(e){if(m())try{e.length===0?localStorage.removeItem(J):localStorage.setItem(J,JSON.stringify(e));}catch{}}function Xe(e){let t={...e};if(t.screenshots){let n={...t.screenshots};n.element&&(n.element={...n.element,dataUrl:""}),n.fullPage&&(n.fullPage={...n.fullPage,dataUrl:""}),t.screenshots=n;}return t}function X(e){let t=Y(),n=Xe(e);for(n.metadata={...n.metadata,_queued:true},t.push({payload:n,timestamp:Date.now()});t.length>Ke;)t.shift();K(t);}function pe(){let e=Y();return e.length===0?[]:(K([]),e.map(t=>t.payload))}function vt(){K([]);}function Pt(){return Y().length}function G(e){let t=null,n=null,r=(...o)=>{n=o,t===null&&(t=requestAnimationFrame(()=>{if(t=null,!n)return;let i=n;n=null,e(...i);}));};return r.cancel=()=>{t!==null&&cancelAnimationFrame(t),t=null,n=null;},r}function U(e){return e instanceof Element?!!e.closest("[data-blocfeed-ui]"):false}function O(e){e.stopPropagation(),e.stopImmediatePropagation?.();}function ge(e,t){if(!m())throw new Error("BlocFeed picker can only run in a browser environment.");let n=e.ignoreSelectors,r=e.isSelectable,o={};n&&n.length>0&&(o.ignoreSelectors=n),r&&(o.isSelectable=r);let i=null,a=null,s=(l,c=false)=>{if(!l){i=null,a=null,t.onHover(null);return}let u=Q(l.getBoundingClientRect()),v=`${Math.round(u.x)}:${Math.round(u.y)}:${Math.round(u.width)}:${Math.round(u.height)}`;!c&&l===i&&v===a||(i=l,a=v,t.onHover({element:l,rect:u}));},f=G(l=>{if(U(l.target))return;let c=document.elementFromPoint(l.clientX,l.clientY),u=W(c,o);s(u);}),g=G(()=>{i&&s(i,true);}),w=l=>{U(l.target)||(O(l),l.pointerType==="mouse"&&l.preventDefault());},y=l=>{U(l.target)||(O(l),l.pointerType==="mouse"&&l.preventDefault());},E=l=>{if(U(l.target))return;O(l),l.preventDefault();let c=document.elementFromPoint(l.clientX,l.clientY),u=W(c,o);u&&t.onSelect({element:u,descriptor:ie(u)});},h=l=>{l.key==="Escape"&&(O(l),l.preventDefault(),t.onCancel());};return window.addEventListener("pointermove",f,{capture:true,passive:true}),window.addEventListener("pointerdown",w,{capture:true}),window.addEventListener("pointerup",y,{capture:true}),window.addEventListener("click",E,{capture:true}),window.addEventListener("keydown",h,{capture:true}),window.addEventListener("scroll",g,{capture:true,passive:true}),window.addEventListener("resize",g,{passive:true}),{stop(){window.removeEventListener("pointermove",f,{capture:true}),window.removeEventListener("pointerdown",w,{capture:true}),window.removeEventListener("pointerup",y,{capture:true}),window.removeEventListener("click",E,{capture:true}),window.removeEventListener("keydown",h,{capture:true}),window.removeEventListener("scroll",g,{capture:true}),window.removeEventListener("resize",g),f.cancel(),g.cancel(),t.onHover(null);}}}var Ge=12e3,Ze=2,Ve=500,et=2e3,ye="https://blocfeed.com/api/feedback",he=0;function we(e,t){return new Promise((n,r)=>{if(t?.aborted){r(new Error("Aborted"));return}let o=setTimeout(n,e),i=()=>{clearTimeout(o),r(new Error("Aborted"));};t?.addEventListener("abort",i,{once:true});})}function tt(e){return e>=500&&e<=599}function nt(e){let[t,n]=e.split(",",2);if(!t||!n)throw new Error("Invalid data URL");let o=/data:(.*?);base64/.exec(t)?.[1]||"application/octet-stream",i=atob(n),a=new Uint8Array(i.length);for(let s=0;s<i.length;s+=1)a[s]=i.charCodeAt(s);return new Blob([a],{type:o})}function rt(e){let t={},n={...e};if(n.screenshots){let r={},o={...n.screenshots};o.element&&(t.element=o.element.dataUrl,r.element={mime:o.element.mime,width:o.element.width,height:o.element.height},o.element={...o.element,dataUrl:""}),o.fullPage&&(t.fullPage=o.fullPage.dataUrl,r.fullPage={mime:o.fullPage.mime,width:o.fullPage.width,height:o.fullPage.height},o.fullPage={...o.fullPage,dataUrl:""}),n.screenshots=o,(r.element||r.fullPage)&&(n.screenshot_intent=r);}return {lean:n,extracted:t}}async function be(e,t,n){let r=nt(t);await fetch(e,{method:"PUT",body:r,headers:{"content-type":r.type},...n?{signal:n}:{}});}async function ot(e){let{feedbackId:t,extracted:n,screenshots:r,signal:o}=e,i={};n.element&&r?.element&&(i.element={dataUrl:n.element,mime:r.element.mime,width:r.element.width,height:r.element.height}),n.fullPage&&r?.fullPage&&(i.fullPage={dataUrl:n.fullPage,mime:r.fullPage.mime,width:r.fullPage.width,height:r.fullPage.height}),Object.keys(i).length!==0&&await fetch(`${ye}/${t}/screenshots`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i),...o?{signal:o}:{}});}async function Ee(e){let{signal:t,transport:n}=e;if(Date.now()-he<et)return {ok:false,error:p("configuration",new Error("Please wait before submitting again"))};let o=n?.timeoutMs??Ge,i=n?.maxAttempts??Ze,a=n?.backoffMs??Ve,s=!!(e.payload.screenshots?.element?.dataUrl||e.payload.screenshots?.fullPage?.dataUrl),{lean:f,extracted:g}=s?rt(e.payload):{lean:e.payload,extracted:{}},w={...g,...e.screenshotDataUrls};for(let y=1;y<=i;y+=1){let E=new AbortController,h=setTimeout(()=>E.abort(),o),l=()=>E.abort();t&&t.addEventListener("abort",l,{once:true});try{let c=await fetch(ye,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(f),signal:E.signal});if(c.ok){he=Date.now();let u;try{u=await c.json();}catch{}if((w.element||w.fullPage)&&u){let d=u.upload_urls;if(d){let S=[];w.element&&d.element&&S.push(be(d.element,w.element,t)),w.fullPage&&d.fullPage&&S.push(be(d.fullPage,w.fullPage,t));try{await Promise.all(S);}catch{}}else if(u.feedback_id)try{await ot({feedbackId:u.feedback_id,extracted:w,screenshots:e.payload.screenshots,...t?{signal:t}:{}});}catch{}}let x={ok:!0,status:c.status};return u&&(x.apiResponse=u),x}if(y<i&&tt(c.status)){let u=.85+Math.random()*.3,v=Math.round(a*2**(y-1)*u);await we(v,t);continue}return {ok:!1,status:c.status,error:p("api_failed",new Error(`HTTP ${c.status}`))}}catch(c){if(E.signal.aborted||t?.aborted)return {ok:false,error:p("aborted",c)};if(y<i){let u=.85+Math.random()*.3,v=Math.round(a*2**(y-1)*u);await we(v,t);continue}return {ok:false,error:p("api_failed",c)}}finally{clearTimeout(h),t&&t.removeEventListener("abort",l);}}return {ok:false,error:p("api_failed",new Error("Failed"))}}async function Z(e){let{signal:t,transport:n}=e,r={ok:false};try{let o={payload:e.payload,...t?{signal:t}:{},...n?{transport:n}:{}};r.api=await Ee(o),r.ok=!!r.api?.ok;}catch(o){r.api={ok:false,error:p("api_failed",o)},r.ok=false;}return {payload:e.payload,result:r}}var it=["[data-blocfeed-ui]","[data-blocfeed-ignore]"];function at(e){let t=[...it,...e?.ignoreSelectors??[]],n=Array.from(new Set(t));return {...e,ignoreSelectors:n}}function ke(){return {phase:"idle"}}function st(e){if(e.ok)return false;let t=e.api;return t?t.status&&t.status>=400&&t.status<500||t.error?.kind==="aborted"||t.error?.kind==="configuration"?false:!t.ok:true}function $t(e){let t=e,n=ke(),r=new Set,o=new Set,i=null,a=null,s=null,f=null,g=0,w=null,y=()=>{for(let d of r)d(n);},E=d=>{for(let S of o)S(d);},h=d=>{n=d,y();},l=()=>{g+=1,f?.abort(),f=null;},c=()=>{i?.stop(),i=null,E(null),s!==null&&m()&&(document.documentElement.style.cursor=s,s=null);},u=()=>{l(),c(),a=null,h(ke());},v=()=>{if(!m())return;c(),a=null;let d=at(t.picker);s=document.documentElement.style.cursor,document.documentElement.style.cursor="crosshair",h({phase:"picking"}),i=ge(d,{onHover:E,onSelect:({element:S,descriptor:N})=>{a=S,c(),h({phase:"review",selection:N});},onCancel:()=>{u();}});},x=()=>{let d=pe();if(d.length!==0)for(let S of d)Z({payload:S,...t.transport?{transport:t.transport}:{}}).catch(()=>{X(S);});};if(m()){setTimeout(x,1e3);let d=()=>x();window.addEventListener("online",d),w=()=>window.removeEventListener("online",d);}return {getState:()=>n,subscribe(d){return r.add(d),()=>r.delete(d)},subscribeHover(d){return o.add(d),()=>o.delete(d)},start(){n.phase==="capturing"||n.phase==="submitting"||n.phase!=="picking"&&v();},stop(){u();},clearSelection(){n.phase==="capturing"||n.phase==="submitting"||v();},setConfig(d){t=d;},async submit(d,S){if(!m()){let b=p("configuration",new Error("BlocFeed submit can only run in the browser"));return h({phase:"error",lastError:b}),{ok:false}}let N=t.blocfeed_id?.trim?.()??"";if(!N){let F={phase:"error",lastError:p("configuration",new Error("Missing blocfeed_id. Create a project in BlocFeed and pass its blocfeed_id."))};return n.selection&&(F.selection=n.selection),h(F),{ok:false}}if(n.phase==="capturing"||n.phase==="submitting")return {ok:false};let C=g+1;g=C,f?.abort(),f=new AbortController;let T=f.signal,k=n.selection,q=S?.capture?{...t.capture,...S.capture}:t.capture,V=!!(q?.element||q?.fullPage),ee={phase:V?"capturing":"submitting"};k&&(ee.selection=k),h(ee);try{let b=V?await fe({selectionElement:a,capture:q,signal:T}):void 0;if(T.aborted||g!==C)return {ok:!1};let F={phase:"submitting"};k&&(F.selection=k),b&&(F.capture=b),h(F);let R={};k&&(R.selection=k),b&&(R.capture=b);let xe=await me({config:t.metadata,context:R,...t.user?{user:t.user}:{}}),M={version:1,createdAt:new Date().toISOString(),blocfeed_id:N,message:d,metadata:xe};t.user&&(M.user=t.user),k&&(M.selection=k),b&&(M.screenshots=b);let{result:P}=await Z({payload:M,signal:T,...t.transport?{transport:t.transport}:{}});if(T.aborted||g!==C)return P;if(P.ok){let j={phase:"success",lastSubmit:P};return k&&(j.selection=k),b&&(j.capture=b),h(j),P}st(P)&&X(M);let Fe=P.api?.error??p("unknown",new Error("Submission failed")),$={phase:"error",lastSubmit:P,lastError:Fe};return k&&($.selection=k),b&&($.capture=b),h($),P}catch(b){if(T.aborted||g!==C)return {ok:false};let R={phase:"error",lastError:T.aborted?p("aborted",b):p("unknown",b)};return k&&(R.selection=k),h(R),{ok:false}}finally{g===C&&(f=null);}},__unsafeGetSelectedElement(){return a},destroy(){u(),r.clear(),o.clear(),w?.(),w=null;}}}var L=[],_=[],ve=20,Pe=15,I={},D=null,H=false;function lt(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return String(e)}}function ct(e,t){let n=t.map(lt).join(" "),r=t.find(i=>i instanceof Error),o={level:e,message:n.slice(0,2e3),timestamp:Date.now()};for(r?.stack&&(o.stack=r.stack.slice(0,2e3)),L.push(o);L.length>ve;)L.shift();}function Se(e){if(!e.url.includes("blocfeed.com"))for(_.push(e);_.length>Pe;)_.shift();}function Wt(e={}){if(!(H||!m())){if(H=true,ve=e.consoleLimit??20,Pe=e.networkLimit??15,e.console!==false){let t=e.consoleLevels??["error","warn"];for(let n of t)I[n]=console[n],console[n]=(...r)=>{ct(n,r),I[n]?.apply(console,r);};}if(e.network!==false&&typeof window.fetch=="function"){D=window.fetch;let t=D;window.fetch=async function(r,o){let i=typeof r=="string"?r:r instanceof URL?r.toString():r.url,a=(o?.method??"GET").toUpperCase(),s=Date.now();try{let f=await t.call(window,r,o);return f.ok||Se({url:i.slice(0,500),method:a,status:f.status,statusText:f.statusText,timestamp:s,durationMs:Date.now()-s}),f}catch(f){throw Se({url:i.slice(0,500),method:a,status:0,statusText:f instanceof Error?f.message:"Network error",timestamp:s,durationMs:Date.now()-s}),f}};}}}function zt(){if(H){for(let[e,t]of Object.entries(I))console[e]=t;for(let e of Object.keys(I))delete I[e];D&&(window.fetch=D,D=null),H=false;}}function Jt(){return {consoleLogs:[...L],networkErrors:[..._]}}function Yt(){L=[],_=[];}
2
- export{m as a,Q as b,le as c,fe as d,me as e,X as f,pe as g,vt as h,Pt as i,$t as j,Wt as k,zt as l,Jt as m,Yt as n};