blocfeed 0.2.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  - (none)
6
6
 
7
+ ## 0.2.1 — 2026-02-17
8
+
9
+ - Fix: submit endpoint now uses the apex domain (`POST https://blocfeed.com/api/feedback`) to avoid TLS issues when `www.blocfeed.com` is misconfigured.
10
+
7
11
  ## 0.2.0 — 2026-02-17
8
12
 
9
13
  - **Breaking**: `blocfeed_id` is now required for `BlocFeedWidget`, `BlocFeedProvider`, and all submissions.
package/README.md CHANGED
@@ -20,11 +20,11 @@ Peer deps: `react`, `react-dom`.
20
20
 
21
21
  ## Get your `blocfeed_id`
22
22
 
23
- Create a project in the BlocFeed dashboard (`https://www.blocfeed.com`). Each project has a unique `blocfeed_id` that the SDK uses to link incoming feedback to the correct project.
23
+ Create a project in the BlocFeed dashboard (`https://blocfeed.com`). Each project has a unique `blocfeed_id` that the SDK uses to link incoming feedback to the correct project.
24
24
 
25
25
  ## Submission endpoint
26
26
 
27
- Submissions are sent to the BlocFeed platform ingestion API at `https://www.blocfeed.com/api/feedback`. Custom/external endpoints are intentionally not supported.
27
+ Submissions are sent to the BlocFeed platform ingestion API at `https://blocfeed.com/api/feedback`. Custom/external endpoints are intentionally not supported.
28
28
 
29
29
  ## Next.js (App Router) — copy/paste
30
30
 
@@ -1,2 +1,2 @@
1
- function b(){return typeof window<"u"&&typeof document<"u"}function W(e){let n=globalThis.CSS;return typeof n?.escape=="function"?n.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,t=>{let r=t.codePointAt(0);return r===void 0?"":`\\${r.toString(16)} `})}function H(e){return {x:e.x,y:e.y,width:e.width,height:e.height}}function de(e){return {x:e.x+window.scrollX,y:e.y+window.scrollY,width:e.width,height:e.height}}function fe(e){return e.replace(/\s+/g," ").trim()}function me(e,n=140){let t=e.textContent;if(!t)return;let r=fe(t);if(r)return r.length<=n?r:`${r.slice(0,n-1)}\u2026`}function pe(e){let n=1;for(let t=e.previousElementSibling;t;t=t.previousElementSibling)t.tagName===e.tagName&&(n+=1);return n}var K=["data-testid","data-test-id","data-test","data-qa","data-cy"],z="data-blocfeed-component";function ge(e){let n=e.closest(`[${z}]`);if(!n)return;let r=n.getAttribute(z)?.trim();return r||void 0}function we(e){for(let n of K){let t=e.closest(`[${n}]`);if(!t)continue;let o=t.getAttribute(n)?.trim();if(o)return o}}function he(e){try{let n=e,t=Object.getOwnPropertyNames(n);for(let r of t)if(r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$")){let o=n[r];if(o&&typeof o=="object")return o}}catch{}return null}function C(e){if(e&&typeof e!="string"){if(typeof e=="function"){let n=e;return typeof n.displayName=="string"&&n.displayName?n.displayName:typeof n.name=="string"&&n.name?n.name:void 0}if(typeof e=="object"){let n=e,t=n.displayName;if(typeof t=="string"&&t)return t;let r=n.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=n.type;return C(o)}}}function be(e){let n=he(e);if(!n)return;let t=n._debugOwner;for(let o=0;t&&o<50;o+=1){let i=C(t.type)??C(t.elementType);if(i)return i;t=t._debugOwner;}let r=n;for(let o=0;r&&o<80;o+=1){let i=C(r.type)??C(r.elementType);if(i)return i;r=r.return;}}function ye(e){let n=e.tagName.toLowerCase(),t=e.getAttribute("id");if(t)return `#${W(t)}`;for(let r of K){let o=e.getAttribute(r);if(o)return `${n}[${r}="${W(o)}"]`}return `${n}:nth-of-type(${pe(e)})`}function Ee(e,n=10){let t=[],r=e;for(;r&&t.length<n;){let o=ye(r);if(t.unshift(o),o.startsWith("#"))break;r=r.parentElement;}return t.join(" > ")}function Y(e,n){if(!n||n.length===0)return false;for(let t of n)if(e.closest(t))return true;return false}function N(e,n){if(!e||Y(e,n.ignoreSelectors))return null;let t=e;for(;t;){if(Y(t,n.ignoreSelectors))return null;if(n.isSelectable?.(t)??ve(t))return t;t=t.parentElement;}return null}function ve(e){let n=e.tagName;return !(n==="HTML"||n==="BODY")}function Q(e){let n=e.getBoundingClientRect(),t={selector:Ee(e),tagName:e.tagName.toLowerCase(),rect:H(n),pageRect:de(n)},r=e.getAttribute("id");r&&(t.id=r);let o=e.className;typeof o=="string"&&o.trim()&&(t.className=o);let i=me(e);i&&(t.textSnippet=i);let l=ge(e)??be(e);l&&(t.componentName=l);let s=we(e);return s&&(t.testId=s),t}var O=null;async function X(){return O||(O=import('html-to-image')),O}async function Se(e){return await new Promise((n,t)=>{let r=new Image;r.onload=()=>n({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>t(new Error("Failed to load generated screenshot")),r.src=e;})}async function J(e,n){let{width:t,height:r}=await Se(e);return {dataUrl:e,mime:n,width:t,height:r}}function T(e){if(e?.aborted)throw new Error("Aborted")}function G(){return {async captureElement(e,n){if(!b())throw new Error("captureElement can only run in the browser");T(n.signal);let t=await X();T(n.signal);let r=n.mime==="image/jpeg"?await t.toJpeg(e,{quality:n.quality??.92,pixelRatio:n.pixelRatio}):await t.toPng(e,{pixelRatio:n.pixelRatio});return T(n.signal),await J(r,n.mime)},async captureFullPage(e){if(!b())throw new Error("captureFullPage can only run in the browser");T(e.signal);let n=document.documentElement,t=Math.max(n.scrollWidth,n.clientWidth),r=Math.max(n.scrollHeight,n.clientHeight),o=Math.min(1,e.maxDimension/Math.max(t,r)),i=Math.max(1,Math.round(t*o)),l=Math.max(1,Math.round(r*o)),s=await X();T(e.signal);let u=e.mime==="image/jpeg"?await s.toJpeg(n,{width:i,height:l,quality:e.quality??.92,pixelRatio:e.pixelRatio}):await s.toPng(n,{width:i,height:l,pixelRatio:e.pixelRatio});return T(e.signal),await J(u,e.mime)}}}function ke(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return "Unknown error"}}function m(e,n,t){let r={kind:e,message:ke(n)};return t&&(r.detail=t),r}var Fe=12e3,xe=2048,Pe=.92;function Z(){return Date.now()}function Te(e){return new Promise((n,t)=>{let r=()=>t(new Error("Aborted"));if(e.aborted){r();return}e.addEventListener("abort",r,{once:true});})}async function V(e,n,t){let r=new Promise((i,l)=>{let s=setTimeout(()=>l(new Error("Timeout")),n);typeof s.unref=="function"&&s.unref();}),o=[e,r];return t&&o.push(Te(t)),await Promise.race(o)}function Ae(e){if(!b())return 1;let n=window.devicePixelRatio||1,t=e?.pixelRatio??Math.min(n,2);return Math.max(.1,t)}function Ce(e){return !!(e?.element||e?.fullPage)}function ee(e){let n={mime:e.mime,pixelRatio:e.pixelRatio,maxDimension:e.maxDimension};return e.includeQuality&&(n.quality=e.quality),e.signal&&(n.signal=e.signal),n}async function te(e){let{selectionElement:n,capture:t,signal:r}=e;if(!b()||!Ce(t))return;let o=Z(),i=[],l=t?.timeoutMs??Fe,s=t?.maxDimension??xe,u=t?.mime??"image/png",d=t?.quality??Pe,v=t?.adapter??G(),y={},p=Ae(t);if(t?.element&&n)try{let f=n.getBoundingClientRect(),g=Math.min(1,s/Math.max(f.width,f.height)),c=Math.min(p,p*g),E=await V(Promise.resolve(v.captureElement(n,{...ee({mime:u,quality:d,pixelRatio:c,maxDimension:s,includeQuality:u==="image/jpeg",...r?{signal:r}:{}})})),l,r);y.element=E;}catch(f){if(r?.aborted)throw f;i.push(m("capture_failed",f,{target:"element"}));}if(t?.fullPage)try{let f=await V(Promise.resolve(v.captureFullPage(ee({mime:u,quality:d,pixelRatio:p,maxDimension:s,includeQuality:u==="image/jpeg",...r?{signal:r}:{}}))),l,r);y.fullPage=f;}catch(f){if(r?.aborted)throw f;i.push(m("capture_failed",f,{target:"fullPage"}));}let S=Z(),a={startedAt:o,finishedAt:S,durationMs:Math.max(0,S-o)};return i.length>0&&(a.errors=i),{...y,diagnostics:a}}function Re(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}}function Me(){return b()?{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:Re()}:{}}async function ne(e){let{config:n,context:t}=e;if(n?.enabled===false)return {};let r=Me(),o=n?.enrich;if(!o)return r;try{let i=await o(t);return {...r,...i}}catch(i){let l=m("unknown",i);return {...r,blocfeedMetadataError:l.message}}}function U(e){let n=null,t=null,r=(...o)=>{t=o,n===null&&(n=requestAnimationFrame(()=>{if(n=null,!t)return;let i=t;t=null,e(...i);}));};return r.cancel=()=>{n!==null&&cancelAnimationFrame(n),n=null,t=null;},r}function M(e){return e instanceof Element?!!e.closest("[data-blocfeed-ui]"):false}function B(e){e.stopPropagation(),e.stopImmediatePropagation?.();}function re(e,n){if(!b())throw new Error("BlocFeed picker can only run in a browser environment.");let t=e.ignoreSelectors,r=e.isSelectable,o={};t&&t.length>0&&(o.ignoreSelectors=t),r&&(o.isSelectable=r);let i=null,l=null,s=(a,f=false)=>{if(!a){i=null,l=null,n.onHover(null);return}let g=H(a.getBoundingClientRect()),c=`${Math.round(g.x)}:${Math.round(g.y)}:${Math.round(g.width)}:${Math.round(g.height)}`;!f&&a===i&&c===l||(i=a,l=c,n.onHover({element:a,rect:g}));},u=U(a=>{if(M(a.target))return;let f=document.elementFromPoint(a.clientX,a.clientY),g=N(f,o);s(g);}),d=U(()=>{i&&s(i,true);}),v=a=>{M(a.target)||(B(a),a.pointerType==="mouse"&&a.preventDefault());},y=a=>{M(a.target)||(B(a),a.pointerType==="mouse"&&a.preventDefault());},p=a=>{if(M(a.target))return;B(a),a.preventDefault();let f=document.elementFromPoint(a.clientX,a.clientY),g=N(f,o);g&&n.onSelect({element:g,descriptor:Q(g)});},S=a=>{a.key==="Escape"&&(B(a),a.preventDefault(),n.onCancel());};return window.addEventListener("pointermove",u,{capture:true,passive:true}),window.addEventListener("pointerdown",v,{capture:true}),window.addEventListener("pointerup",y,{capture:true}),window.addEventListener("click",p,{capture:true}),window.addEventListener("keydown",S,{capture:true}),window.addEventListener("scroll",d,{capture:true,passive:true}),window.addEventListener("resize",d,{passive:true}),{stop(){window.removeEventListener("pointermove",u,{capture:true}),window.removeEventListener("pointerdown",v,{capture:true}),window.removeEventListener("pointerup",y,{capture:true}),window.removeEventListener("click",p,{capture:true}),window.removeEventListener("keydown",S,{capture:true}),window.removeEventListener("scroll",d,{capture:true}),window.removeEventListener("resize",d),u.cancel(),d.cancel(),n.onHover(null);}}}var Be=12e3,$=2,oe=500,_e="https://www.blocfeed.com/api/feedback";function ie(e,n){return new Promise((t,r)=>{if(n?.aborted){r(new Error("Aborted"));return}let o=setTimeout(t,e),i=()=>{clearTimeout(o),r(new Error("Aborted"));};n?.addEventListener("abort",i,{once:true});})}function Le(e){return e>=500&&e<=599}async function ae(e){let{payload:n,signal:t}=e;for(let r=1;r<=$;r+=1){let o=new AbortController,i=setTimeout(()=>o.abort(),Be),l=()=>o.abort();t&&t.addEventListener("abort",l,{once:true});try{let s=await fetch(_e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n),signal:o.signal});if(s.ok)return {ok:!0,status:s.status};if(r<$&&Le(s.status)){let u=.85+Math.random()*.3,d=Math.round(oe*2**(r-1)*u);await ie(d,t);continue}return {ok:!1,status:s.status,error:m("api_failed",new Error(`HTTP ${s.status}`))}}catch(s){if(o.signal.aborted||t?.aborted)return {ok:false,error:m("aborted",s)};if(r<$){let u=.85+Math.random()*.3,d=Math.round(oe*2**(r-1)*u);await ie(d,t);continue}return {ok:false,error:m("api_failed",s)}}finally{clearTimeout(i),t&&t.removeEventListener("abort",l);}}return {ok:false,error:m("api_failed",new Error("Failed"))}}async function se(e){let{signal:n}=e,t={ok:false};try{let r=n?{payload:e.payload,signal:n}:{payload:e.payload};t.api=await ae(r),t.ok=!!t.api?.ok;}catch(r){t.api={ok:false,error:m("api_failed",r)},t.ok=false;}return {payload:e.payload,result:t}}var Ie=["[data-blocfeed-ui]","[data-blocfeed-ignore]"];function De(e){let n=[...Ie,...e?.ignoreSelectors??[]],t=Array.from(new Set(n));return {...e,ignoreSelectors:t}}function le(){return {phase:"idle"}}function ut(e){let n=e,t=le(),r=new Set,o=new Set,i=null,l=null,s=null,u=null,d=0,v=()=>{for(let c of r)c(t);},y=c=>{for(let E of o)E(c);},p=c=>{t=c,v();},S=()=>{d+=1,u?.abort(),u=null;},a=()=>{i?.stop(),i=null,y(null),s!==null&&b()&&(document.documentElement.style.cursor=s,s=null);},f=()=>{S(),a(),l=null,p(le());},g=()=>{if(!b())return;a(),l=null;let c=De(n.picker);s=document.documentElement.style.cursor,document.documentElement.style.cursor="crosshair",p({phase:"picking"}),i=re(c,{onHover:y,onSelect:({element:E,descriptor:R})=>{l=E,a(),p({phase:"review",selection:R});},onCancel:()=>{f();}});};return {getState:()=>t,subscribe(c){return r.add(c),()=>r.delete(c)},subscribeHover(c){return o.add(c),()=>o.delete(c)},start(){t.phase==="capturing"||t.phase==="submitting"||t.phase!=="picking"&&g();},stop(){f();},clearSelection(){t.phase==="capturing"||t.phase==="submitting"||g();},setConfig(c){n=c;},async submit(c,E){if(!b()){let w=m("configuration",new Error("BlocFeed submit can only run in the browser"));return p({phase:"error",lastError:w}),{ok:false}}let R=n.blocfeed_id?.trim?.()??"";if(!R){let k={phase:"error",lastError:m("configuration",new Error("Missing blocfeed_id. Create a project in BlocFeed and pass its blocfeed_id."))};return t.selection&&(k.selection=t.selection),p(k),{ok:false}}if(t.phase==="capturing"||t.phase==="submitting")return {ok:false};let A=d+1;d=A,u?.abort(),u=new AbortController;let x=u.signal,h=t.selection,_=E?.capture?{...n.capture,...E.capture}:n.capture,q=!!(_?.element||_?.fullPage),j={phase:q?"capturing":"submitting"};h&&(j.selection=h),p(j);try{let w=q?await te({selectionElement:l,capture:_,signal:x}):void 0;if(x.aborted||d!==A)return {ok:!1};let k={phase:"submitting"};h&&(k.selection=h),w&&(k.capture=w),p(k);let P={};h&&(P.selection=h),w&&(P.capture=w);let ce=await ne({config:n.metadata,context:P}),L={version:1,createdAt:new Date().toISOString(),blocfeed_id:R,message:c,metadata:ce};h&&(L.selection=h),w&&(L.screenshots=w);let{result:F}=await se({payload:L,signal:x});if(x.aborted||d!==A)return F;if(F.ok){let D={phase:"success",lastSubmit:F};return h&&(D.selection=h),w&&(D.capture=w),p(D),F}let ue=F.api?.error??m("unknown",new Error("Submission failed")),I={phase:"error",lastSubmit:F,lastError:ue};return h&&(I.selection=h),w&&(I.capture=w),p(I),F}catch(w){if(x.aborted||d!==A)return {ok:false};let P={phase:"error",lastError:x.aborted?m("aborted",w):m("unknown",w)};return h&&(P.selection=h),p(P),{ok:false}}finally{d===A&&(u=null);}},__unsafeGetSelectedElement(){return l},destroy(){f(),r.clear(),o.clear();}}}
1
+ function b(){return typeof window<"u"&&typeof document<"u"}function W(e){let n=globalThis.CSS;return typeof n?.escape=="function"?n.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,t=>{let r=t.codePointAt(0);return r===void 0?"":`\\${r.toString(16)} `})}function H(e){return {x:e.x,y:e.y,width:e.width,height:e.height}}function de(e){return {x:e.x+window.scrollX,y:e.y+window.scrollY,width:e.width,height:e.height}}function fe(e){return e.replace(/\s+/g," ").trim()}function me(e,n=140){let t=e.textContent;if(!t)return;let r=fe(t);if(r)return r.length<=n?r:`${r.slice(0,n-1)}\u2026`}function pe(e){let n=1;for(let t=e.previousElementSibling;t;t=t.previousElementSibling)t.tagName===e.tagName&&(n+=1);return n}var K=["data-testid","data-test-id","data-test","data-qa","data-cy"],z="data-blocfeed-component";function ge(e){let n=e.closest(`[${z}]`);if(!n)return;let r=n.getAttribute(z)?.trim();return r||void 0}function we(e){for(let n of K){let t=e.closest(`[${n}]`);if(!t)continue;let o=t.getAttribute(n)?.trim();if(o)return o}}function he(e){try{let n=e,t=Object.getOwnPropertyNames(n);for(let r of t)if(r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$")){let o=n[r];if(o&&typeof o=="object")return o}}catch{}return null}function C(e){if(e&&typeof e!="string"){if(typeof e=="function"){let n=e;return typeof n.displayName=="string"&&n.displayName?n.displayName:typeof n.name=="string"&&n.name?n.name:void 0}if(typeof e=="object"){let n=e,t=n.displayName;if(typeof t=="string"&&t)return t;let r=n.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=n.type;return C(o)}}}function be(e){let n=he(e);if(!n)return;let t=n._debugOwner;for(let o=0;t&&o<50;o+=1){let i=C(t.type)??C(t.elementType);if(i)return i;t=t._debugOwner;}let r=n;for(let o=0;r&&o<80;o+=1){let i=C(r.type)??C(r.elementType);if(i)return i;r=r.return;}}function ye(e){let n=e.tagName.toLowerCase(),t=e.getAttribute("id");if(t)return `#${W(t)}`;for(let r of K){let o=e.getAttribute(r);if(o)return `${n}[${r}="${W(o)}"]`}return `${n}:nth-of-type(${pe(e)})`}function Ee(e,n=10){let t=[],r=e;for(;r&&t.length<n;){let o=ye(r);if(t.unshift(o),o.startsWith("#"))break;r=r.parentElement;}return t.join(" > ")}function Y(e,n){if(!n||n.length===0)return false;for(let t of n)if(e.closest(t))return true;return false}function N(e,n){if(!e||Y(e,n.ignoreSelectors))return null;let t=e;for(;t;){if(Y(t,n.ignoreSelectors))return null;if(n.isSelectable?.(t)??ve(t))return t;t=t.parentElement;}return null}function ve(e){let n=e.tagName;return !(n==="HTML"||n==="BODY")}function Q(e){let n=e.getBoundingClientRect(),t={selector:Ee(e),tagName:e.tagName.toLowerCase(),rect:H(n),pageRect:de(n)},r=e.getAttribute("id");r&&(t.id=r);let o=e.className;typeof o=="string"&&o.trim()&&(t.className=o);let i=me(e);i&&(t.textSnippet=i);let l=ge(e)??be(e);l&&(t.componentName=l);let s=we(e);return s&&(t.testId=s),t}var O=null;async function X(){return O||(O=import('html-to-image')),O}async function Se(e){return await new Promise((n,t)=>{let r=new Image;r.onload=()=>n({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>t(new Error("Failed to load generated screenshot")),r.src=e;})}async function J(e,n){let{width:t,height:r}=await Se(e);return {dataUrl:e,mime:n,width:t,height:r}}function T(e){if(e?.aborted)throw new Error("Aborted")}function G(){return {async captureElement(e,n){if(!b())throw new Error("captureElement can only run in the browser");T(n.signal);let t=await X();T(n.signal);let r=n.mime==="image/jpeg"?await t.toJpeg(e,{quality:n.quality??.92,pixelRatio:n.pixelRatio}):await t.toPng(e,{pixelRatio:n.pixelRatio});return T(n.signal),await J(r,n.mime)},async captureFullPage(e){if(!b())throw new Error("captureFullPage can only run in the browser");T(e.signal);let n=document.documentElement,t=Math.max(n.scrollWidth,n.clientWidth),r=Math.max(n.scrollHeight,n.clientHeight),o=Math.min(1,e.maxDimension/Math.max(t,r)),i=Math.max(1,Math.round(t*o)),l=Math.max(1,Math.round(r*o)),s=await X();T(e.signal);let u=e.mime==="image/jpeg"?await s.toJpeg(n,{width:i,height:l,quality:e.quality??.92,pixelRatio:e.pixelRatio}):await s.toPng(n,{width:i,height:l,pixelRatio:e.pixelRatio});return T(e.signal),await J(u,e.mime)}}}function ke(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return "Unknown error"}}function m(e,n,t){let r={kind:e,message:ke(n)};return t&&(r.detail=t),r}var Fe=12e3,xe=2048,Pe=.92;function Z(){return Date.now()}function Te(e){return new Promise((n,t)=>{let r=()=>t(new Error("Aborted"));if(e.aborted){r();return}e.addEventListener("abort",r,{once:true});})}async function V(e,n,t){let r=new Promise((i,l)=>{let s=setTimeout(()=>l(new Error("Timeout")),n);typeof s.unref=="function"&&s.unref();}),o=[e,r];return t&&o.push(Te(t)),await Promise.race(o)}function Ae(e){if(!b())return 1;let n=window.devicePixelRatio||1,t=e?.pixelRatio??Math.min(n,2);return Math.max(.1,t)}function Ce(e){return !!(e?.element||e?.fullPage)}function ee(e){let n={mime:e.mime,pixelRatio:e.pixelRatio,maxDimension:e.maxDimension};return e.includeQuality&&(n.quality=e.quality),e.signal&&(n.signal=e.signal),n}async function te(e){let{selectionElement:n,capture:t,signal:r}=e;if(!b()||!Ce(t))return;let o=Z(),i=[],l=t?.timeoutMs??Fe,s=t?.maxDimension??xe,u=t?.mime??"image/png",d=t?.quality??Pe,v=t?.adapter??G(),y={},p=Ae(t);if(t?.element&&n)try{let f=n.getBoundingClientRect(),g=Math.min(1,s/Math.max(f.width,f.height)),c=Math.min(p,p*g),E=await V(Promise.resolve(v.captureElement(n,{...ee({mime:u,quality:d,pixelRatio:c,maxDimension:s,includeQuality:u==="image/jpeg",...r?{signal:r}:{}})})),l,r);y.element=E;}catch(f){if(r?.aborted)throw f;i.push(m("capture_failed",f,{target:"element"}));}if(t?.fullPage)try{let f=await V(Promise.resolve(v.captureFullPage(ee({mime:u,quality:d,pixelRatio:p,maxDimension:s,includeQuality:u==="image/jpeg",...r?{signal:r}:{}}))),l,r);y.fullPage=f;}catch(f){if(r?.aborted)throw f;i.push(m("capture_failed",f,{target:"fullPage"}));}let S=Z(),a={startedAt:o,finishedAt:S,durationMs:Math.max(0,S-o)};return i.length>0&&(a.errors=i),{...y,diagnostics:a}}function Re(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}}function Me(){return b()?{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:Re()}:{}}async function ne(e){let{config:n,context:t}=e;if(n?.enabled===false)return {};let r=Me(),o=n?.enrich;if(!o)return r;try{let i=await o(t);return {...r,...i}}catch(i){let l=m("unknown",i);return {...r,blocfeedMetadataError:l.message}}}function U(e){let n=null,t=null,r=(...o)=>{t=o,n===null&&(n=requestAnimationFrame(()=>{if(n=null,!t)return;let i=t;t=null,e(...i);}));};return r.cancel=()=>{n!==null&&cancelAnimationFrame(n),n=null,t=null;},r}function M(e){return e instanceof Element?!!e.closest("[data-blocfeed-ui]"):false}function B(e){e.stopPropagation(),e.stopImmediatePropagation?.();}function re(e,n){if(!b())throw new Error("BlocFeed picker can only run in a browser environment.");let t=e.ignoreSelectors,r=e.isSelectable,o={};t&&t.length>0&&(o.ignoreSelectors=t),r&&(o.isSelectable=r);let i=null,l=null,s=(a,f=false)=>{if(!a){i=null,l=null,n.onHover(null);return}let g=H(a.getBoundingClientRect()),c=`${Math.round(g.x)}:${Math.round(g.y)}:${Math.round(g.width)}:${Math.round(g.height)}`;!f&&a===i&&c===l||(i=a,l=c,n.onHover({element:a,rect:g}));},u=U(a=>{if(M(a.target))return;let f=document.elementFromPoint(a.clientX,a.clientY),g=N(f,o);s(g);}),d=U(()=>{i&&s(i,true);}),v=a=>{M(a.target)||(B(a),a.pointerType==="mouse"&&a.preventDefault());},y=a=>{M(a.target)||(B(a),a.pointerType==="mouse"&&a.preventDefault());},p=a=>{if(M(a.target))return;B(a),a.preventDefault();let f=document.elementFromPoint(a.clientX,a.clientY),g=N(f,o);g&&n.onSelect({element:g,descriptor:Q(g)});},S=a=>{a.key==="Escape"&&(B(a),a.preventDefault(),n.onCancel());};return window.addEventListener("pointermove",u,{capture:true,passive:true}),window.addEventListener("pointerdown",v,{capture:true}),window.addEventListener("pointerup",y,{capture:true}),window.addEventListener("click",p,{capture:true}),window.addEventListener("keydown",S,{capture:true}),window.addEventListener("scroll",d,{capture:true,passive:true}),window.addEventListener("resize",d,{passive:true}),{stop(){window.removeEventListener("pointermove",u,{capture:true}),window.removeEventListener("pointerdown",v,{capture:true}),window.removeEventListener("pointerup",y,{capture:true}),window.removeEventListener("click",p,{capture:true}),window.removeEventListener("keydown",S,{capture:true}),window.removeEventListener("scroll",d,{capture:true}),window.removeEventListener("resize",d),u.cancel(),d.cancel(),n.onHover(null);}}}var Be=12e3,$=2,oe=500,_e="https://blocfeed.com/api/feedback";function ie(e,n){return new Promise((t,r)=>{if(n?.aborted){r(new Error("Aborted"));return}let o=setTimeout(t,e),i=()=>{clearTimeout(o),r(new Error("Aborted"));};n?.addEventListener("abort",i,{once:true});})}function Le(e){return e>=500&&e<=599}async function ae(e){let{payload:n,signal:t}=e;for(let r=1;r<=$;r+=1){let o=new AbortController,i=setTimeout(()=>o.abort(),Be),l=()=>o.abort();t&&t.addEventListener("abort",l,{once:true});try{let s=await fetch(_e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n),signal:o.signal});if(s.ok)return {ok:!0,status:s.status};if(r<$&&Le(s.status)){let u=.85+Math.random()*.3,d=Math.round(oe*2**(r-1)*u);await ie(d,t);continue}return {ok:!1,status:s.status,error:m("api_failed",new Error(`HTTP ${s.status}`))}}catch(s){if(o.signal.aborted||t?.aborted)return {ok:false,error:m("aborted",s)};if(r<$){let u=.85+Math.random()*.3,d=Math.round(oe*2**(r-1)*u);await ie(d,t);continue}return {ok:false,error:m("api_failed",s)}}finally{clearTimeout(i),t&&t.removeEventListener("abort",l);}}return {ok:false,error:m("api_failed",new Error("Failed"))}}async function se(e){let{signal:n}=e,t={ok:false};try{let r=n?{payload:e.payload,signal:n}:{payload:e.payload};t.api=await ae(r),t.ok=!!t.api?.ok;}catch(r){t.api={ok:false,error:m("api_failed",r)},t.ok=false;}return {payload:e.payload,result:t}}var Ie=["[data-blocfeed-ui]","[data-blocfeed-ignore]"];function De(e){let n=[...Ie,...e?.ignoreSelectors??[]],t=Array.from(new Set(n));return {...e,ignoreSelectors:t}}function le(){return {phase:"idle"}}function ut(e){let n=e,t=le(),r=new Set,o=new Set,i=null,l=null,s=null,u=null,d=0,v=()=>{for(let c of r)c(t);},y=c=>{for(let E of o)E(c);},p=c=>{t=c,v();},S=()=>{d+=1,u?.abort(),u=null;},a=()=>{i?.stop(),i=null,y(null),s!==null&&b()&&(document.documentElement.style.cursor=s,s=null);},f=()=>{S(),a(),l=null,p(le());},g=()=>{if(!b())return;a(),l=null;let c=De(n.picker);s=document.documentElement.style.cursor,document.documentElement.style.cursor="crosshair",p({phase:"picking"}),i=re(c,{onHover:y,onSelect:({element:E,descriptor:R})=>{l=E,a(),p({phase:"review",selection:R});},onCancel:()=>{f();}});};return {getState:()=>t,subscribe(c){return r.add(c),()=>r.delete(c)},subscribeHover(c){return o.add(c),()=>o.delete(c)},start(){t.phase==="capturing"||t.phase==="submitting"||t.phase!=="picking"&&g();},stop(){f();},clearSelection(){t.phase==="capturing"||t.phase==="submitting"||g();},setConfig(c){n=c;},async submit(c,E){if(!b()){let w=m("configuration",new Error("BlocFeed submit can only run in the browser"));return p({phase:"error",lastError:w}),{ok:false}}let R=n.blocfeed_id?.trim?.()??"";if(!R){let k={phase:"error",lastError:m("configuration",new Error("Missing blocfeed_id. Create a project in BlocFeed and pass its blocfeed_id."))};return t.selection&&(k.selection=t.selection),p(k),{ok:false}}if(t.phase==="capturing"||t.phase==="submitting")return {ok:false};let A=d+1;d=A,u?.abort(),u=new AbortController;let x=u.signal,h=t.selection,_=E?.capture?{...n.capture,...E.capture}:n.capture,q=!!(_?.element||_?.fullPage),j={phase:q?"capturing":"submitting"};h&&(j.selection=h),p(j);try{let w=q?await te({selectionElement:l,capture:_,signal:x}):void 0;if(x.aborted||d!==A)return {ok:!1};let k={phase:"submitting"};h&&(k.selection=h),w&&(k.capture=w),p(k);let P={};h&&(P.selection=h),w&&(P.capture=w);let ce=await ne({config:n.metadata,context:P}),L={version:1,createdAt:new Date().toISOString(),blocfeed_id:R,message:c,metadata:ce};h&&(L.selection=h),w&&(L.screenshots=w);let{result:F}=await se({payload:L,signal:x});if(x.aborted||d!==A)return F;if(F.ok){let D={phase:"success",lastSubmit:F};return h&&(D.selection=h),w&&(D.capture=w),p(D),F}let ue=F.api?.error??m("unknown",new Error("Submission failed")),I={phase:"error",lastSubmit:F,lastError:ue};return h&&(I.selection=h),w&&(I.capture=w),p(I),F}catch(w){if(x.aborted||d!==A)return {ok:false};let P={phase:"error",lastError:x.aborted?m("aborted",w):m("unknown",w)};return h&&(P.selection=h),p(P),{ok:false}}finally{d===A&&(u=null);}},__unsafeGetSelectedElement(){return l},destroy(){f(),r.clear(),o.clear();}}}
2
2
  export{b as a,H as b,G as c,te as d,ne as e,ut as f};
@@ -1,2 +1,2 @@
1
- 'use strict';function b(){return typeof window<"u"&&typeof document<"u"}function W(e){let n=globalThis.CSS;return typeof n?.escape=="function"?n.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,t=>{let r=t.codePointAt(0);return r===void 0?"":`\\${r.toString(16)} `})}function H(e){return {x:e.x,y:e.y,width:e.width,height:e.height}}function de(e){return {x:e.x+window.scrollX,y:e.y+window.scrollY,width:e.width,height:e.height}}function fe(e){return e.replace(/\s+/g," ").trim()}function me(e,n=140){let t=e.textContent;if(!t)return;let r=fe(t);if(r)return r.length<=n?r:`${r.slice(0,n-1)}\u2026`}function pe(e){let n=1;for(let t=e.previousElementSibling;t;t=t.previousElementSibling)t.tagName===e.tagName&&(n+=1);return n}var K=["data-testid","data-test-id","data-test","data-qa","data-cy"],z="data-blocfeed-component";function ge(e){let n=e.closest(`[${z}]`);if(!n)return;let r=n.getAttribute(z)?.trim();return r||void 0}function we(e){for(let n of K){let t=e.closest(`[${n}]`);if(!t)continue;let o=t.getAttribute(n)?.trim();if(o)return o}}function he(e){try{let n=e,t=Object.getOwnPropertyNames(n);for(let r of t)if(r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$")){let o=n[r];if(o&&typeof o=="object")return o}}catch{}return null}function C(e){if(e&&typeof e!="string"){if(typeof e=="function"){let n=e;return typeof n.displayName=="string"&&n.displayName?n.displayName:typeof n.name=="string"&&n.name?n.name:void 0}if(typeof e=="object"){let n=e,t=n.displayName;if(typeof t=="string"&&t)return t;let r=n.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=n.type;return C(o)}}}function be(e){let n=he(e);if(!n)return;let t=n._debugOwner;for(let o=0;t&&o<50;o+=1){let i=C(t.type)??C(t.elementType);if(i)return i;t=t._debugOwner;}let r=n;for(let o=0;r&&o<80;o+=1){let i=C(r.type)??C(r.elementType);if(i)return i;r=r.return;}}function ye(e){let n=e.tagName.toLowerCase(),t=e.getAttribute("id");if(t)return `#${W(t)}`;for(let r of K){let o=e.getAttribute(r);if(o)return `${n}[${r}="${W(o)}"]`}return `${n}:nth-of-type(${pe(e)})`}function Ee(e,n=10){let t=[],r=e;for(;r&&t.length<n;){let o=ye(r);if(t.unshift(o),o.startsWith("#"))break;r=r.parentElement;}return t.join(" > ")}function Y(e,n){if(!n||n.length===0)return false;for(let t of n)if(e.closest(t))return true;return false}function N(e,n){if(!e||Y(e,n.ignoreSelectors))return null;let t=e;for(;t;){if(Y(t,n.ignoreSelectors))return null;if(n.isSelectable?.(t)??ve(t))return t;t=t.parentElement;}return null}function ve(e){let n=e.tagName;return !(n==="HTML"||n==="BODY")}function Q(e){let n=e.getBoundingClientRect(),t={selector:Ee(e),tagName:e.tagName.toLowerCase(),rect:H(n),pageRect:de(n)},r=e.getAttribute("id");r&&(t.id=r);let o=e.className;typeof o=="string"&&o.trim()&&(t.className=o);let i=me(e);i&&(t.textSnippet=i);let l=ge(e)??be(e);l&&(t.componentName=l);let s=we(e);return s&&(t.testId=s),t}var O=null;async function X(){return O||(O=import('html-to-image')),O}async function Se(e){return await new Promise((n,t)=>{let r=new Image;r.onload=()=>n({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>t(new Error("Failed to load generated screenshot")),r.src=e;})}async function J(e,n){let{width:t,height:r}=await Se(e);return {dataUrl:e,mime:n,width:t,height:r}}function T(e){if(e?.aborted)throw new Error("Aborted")}function G(){return {async captureElement(e,n){if(!b())throw new Error("captureElement can only run in the browser");T(n.signal);let t=await X();T(n.signal);let r=n.mime==="image/jpeg"?await t.toJpeg(e,{quality:n.quality??.92,pixelRatio:n.pixelRatio}):await t.toPng(e,{pixelRatio:n.pixelRatio});return T(n.signal),await J(r,n.mime)},async captureFullPage(e){if(!b())throw new Error("captureFullPage can only run in the browser");T(e.signal);let n=document.documentElement,t=Math.max(n.scrollWidth,n.clientWidth),r=Math.max(n.scrollHeight,n.clientHeight),o=Math.min(1,e.maxDimension/Math.max(t,r)),i=Math.max(1,Math.round(t*o)),l=Math.max(1,Math.round(r*o)),s=await X();T(e.signal);let u=e.mime==="image/jpeg"?await s.toJpeg(n,{width:i,height:l,quality:e.quality??.92,pixelRatio:e.pixelRatio}):await s.toPng(n,{width:i,height:l,pixelRatio:e.pixelRatio});return T(e.signal),await J(u,e.mime)}}}function ke(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return "Unknown error"}}function m(e,n,t){let r={kind:e,message:ke(n)};return t&&(r.detail=t),r}var Fe=12e3,xe=2048,Pe=.92;function Z(){return Date.now()}function Te(e){return new Promise((n,t)=>{let r=()=>t(new Error("Aborted"));if(e.aborted){r();return}e.addEventListener("abort",r,{once:true});})}async function V(e,n,t){let r=new Promise((i,l)=>{let s=setTimeout(()=>l(new Error("Timeout")),n);typeof s.unref=="function"&&s.unref();}),o=[e,r];return t&&o.push(Te(t)),await Promise.race(o)}function Ae(e){if(!b())return 1;let n=window.devicePixelRatio||1,t=e?.pixelRatio??Math.min(n,2);return Math.max(.1,t)}function Ce(e){return !!(e?.element||e?.fullPage)}function ee(e){let n={mime:e.mime,pixelRatio:e.pixelRatio,maxDimension:e.maxDimension};return e.includeQuality&&(n.quality=e.quality),e.signal&&(n.signal=e.signal),n}async function te(e){let{selectionElement:n,capture:t,signal:r}=e;if(!b()||!Ce(t))return;let o=Z(),i=[],l=t?.timeoutMs??Fe,s=t?.maxDimension??xe,u=t?.mime??"image/png",d=t?.quality??Pe,v=t?.adapter??G(),y={},p=Ae(t);if(t?.element&&n)try{let f=n.getBoundingClientRect(),g=Math.min(1,s/Math.max(f.width,f.height)),c=Math.min(p,p*g),E=await V(Promise.resolve(v.captureElement(n,{...ee({mime:u,quality:d,pixelRatio:c,maxDimension:s,includeQuality:u==="image/jpeg",...r?{signal:r}:{}})})),l,r);y.element=E;}catch(f){if(r?.aborted)throw f;i.push(m("capture_failed",f,{target:"element"}));}if(t?.fullPage)try{let f=await V(Promise.resolve(v.captureFullPage(ee({mime:u,quality:d,pixelRatio:p,maxDimension:s,includeQuality:u==="image/jpeg",...r?{signal:r}:{}}))),l,r);y.fullPage=f;}catch(f){if(r?.aborted)throw f;i.push(m("capture_failed",f,{target:"fullPage"}));}let S=Z(),a={startedAt:o,finishedAt:S,durationMs:Math.max(0,S-o)};return i.length>0&&(a.errors=i),{...y,diagnostics:a}}function Re(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}}function Me(){return b()?{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:Re()}:{}}async function ne(e){let{config:n,context:t}=e;if(n?.enabled===false)return {};let r=Me(),o=n?.enrich;if(!o)return r;try{let i=await o(t);return {...r,...i}}catch(i){let l=m("unknown",i);return {...r,blocfeedMetadataError:l.message}}}function U(e){let n=null,t=null,r=(...o)=>{t=o,n===null&&(n=requestAnimationFrame(()=>{if(n=null,!t)return;let i=t;t=null,e(...i);}));};return r.cancel=()=>{n!==null&&cancelAnimationFrame(n),n=null,t=null;},r}function M(e){return e instanceof Element?!!e.closest("[data-blocfeed-ui]"):false}function B(e){e.stopPropagation(),e.stopImmediatePropagation?.();}function re(e,n){if(!b())throw new Error("BlocFeed picker can only run in a browser environment.");let t=e.ignoreSelectors,r=e.isSelectable,o={};t&&t.length>0&&(o.ignoreSelectors=t),r&&(o.isSelectable=r);let i=null,l=null,s=(a,f=false)=>{if(!a){i=null,l=null,n.onHover(null);return}let g=H(a.getBoundingClientRect()),c=`${Math.round(g.x)}:${Math.round(g.y)}:${Math.round(g.width)}:${Math.round(g.height)}`;!f&&a===i&&c===l||(i=a,l=c,n.onHover({element:a,rect:g}));},u=U(a=>{if(M(a.target))return;let f=document.elementFromPoint(a.clientX,a.clientY),g=N(f,o);s(g);}),d=U(()=>{i&&s(i,true);}),v=a=>{M(a.target)||(B(a),a.pointerType==="mouse"&&a.preventDefault());},y=a=>{M(a.target)||(B(a),a.pointerType==="mouse"&&a.preventDefault());},p=a=>{if(M(a.target))return;B(a),a.preventDefault();let f=document.elementFromPoint(a.clientX,a.clientY),g=N(f,o);g&&n.onSelect({element:g,descriptor:Q(g)});},S=a=>{a.key==="Escape"&&(B(a),a.preventDefault(),n.onCancel());};return window.addEventListener("pointermove",u,{capture:true,passive:true}),window.addEventListener("pointerdown",v,{capture:true}),window.addEventListener("pointerup",y,{capture:true}),window.addEventListener("click",p,{capture:true}),window.addEventListener("keydown",S,{capture:true}),window.addEventListener("scroll",d,{capture:true,passive:true}),window.addEventListener("resize",d,{passive:true}),{stop(){window.removeEventListener("pointermove",u,{capture:true}),window.removeEventListener("pointerdown",v,{capture:true}),window.removeEventListener("pointerup",y,{capture:true}),window.removeEventListener("click",p,{capture:true}),window.removeEventListener("keydown",S,{capture:true}),window.removeEventListener("scroll",d,{capture:true}),window.removeEventListener("resize",d),u.cancel(),d.cancel(),n.onHover(null);}}}var Be=12e3,$=2,oe=500,_e="https://www.blocfeed.com/api/feedback";function ie(e,n){return new Promise((t,r)=>{if(n?.aborted){r(new Error("Aborted"));return}let o=setTimeout(t,e),i=()=>{clearTimeout(o),r(new Error("Aborted"));};n?.addEventListener("abort",i,{once:true});})}function Le(e){return e>=500&&e<=599}async function ae(e){let{payload:n,signal:t}=e;for(let r=1;r<=$;r+=1){let o=new AbortController,i=setTimeout(()=>o.abort(),Be),l=()=>o.abort();t&&t.addEventListener("abort",l,{once:true});try{let s=await fetch(_e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n),signal:o.signal});if(s.ok)return {ok:!0,status:s.status};if(r<$&&Le(s.status)){let u=.85+Math.random()*.3,d=Math.round(oe*2**(r-1)*u);await ie(d,t);continue}return {ok:!1,status:s.status,error:m("api_failed",new Error(`HTTP ${s.status}`))}}catch(s){if(o.signal.aborted||t?.aborted)return {ok:false,error:m("aborted",s)};if(r<$){let u=.85+Math.random()*.3,d=Math.round(oe*2**(r-1)*u);await ie(d,t);continue}return {ok:false,error:m("api_failed",s)}}finally{clearTimeout(i),t&&t.removeEventListener("abort",l);}}return {ok:false,error:m("api_failed",new Error("Failed"))}}async function se(e){let{signal:n}=e,t={ok:false};try{let r=n?{payload:e.payload,signal:n}:{payload:e.payload};t.api=await ae(r),t.ok=!!t.api?.ok;}catch(r){t.api={ok:false,error:m("api_failed",r)},t.ok=false;}return {payload:e.payload,result:t}}var Ie=["[data-blocfeed-ui]","[data-blocfeed-ignore]"];function De(e){let n=[...Ie,...e?.ignoreSelectors??[]],t=Array.from(new Set(n));return {...e,ignoreSelectors:t}}function le(){return {phase:"idle"}}function ut(e){let n=e,t=le(),r=new Set,o=new Set,i=null,l=null,s=null,u=null,d=0,v=()=>{for(let c of r)c(t);},y=c=>{for(let E of o)E(c);},p=c=>{t=c,v();},S=()=>{d+=1,u?.abort(),u=null;},a=()=>{i?.stop(),i=null,y(null),s!==null&&b()&&(document.documentElement.style.cursor=s,s=null);},f=()=>{S(),a(),l=null,p(le());},g=()=>{if(!b())return;a(),l=null;let c=De(n.picker);s=document.documentElement.style.cursor,document.documentElement.style.cursor="crosshair",p({phase:"picking"}),i=re(c,{onHover:y,onSelect:({element:E,descriptor:R})=>{l=E,a(),p({phase:"review",selection:R});},onCancel:()=>{f();}});};return {getState:()=>t,subscribe(c){return r.add(c),()=>r.delete(c)},subscribeHover(c){return o.add(c),()=>o.delete(c)},start(){t.phase==="capturing"||t.phase==="submitting"||t.phase!=="picking"&&g();},stop(){f();},clearSelection(){t.phase==="capturing"||t.phase==="submitting"||g();},setConfig(c){n=c;},async submit(c,E){if(!b()){let w=m("configuration",new Error("BlocFeed submit can only run in the browser"));return p({phase:"error",lastError:w}),{ok:false}}let R=n.blocfeed_id?.trim?.()??"";if(!R){let k={phase:"error",lastError:m("configuration",new Error("Missing blocfeed_id. Create a project in BlocFeed and pass its blocfeed_id."))};return t.selection&&(k.selection=t.selection),p(k),{ok:false}}if(t.phase==="capturing"||t.phase==="submitting")return {ok:false};let A=d+1;d=A,u?.abort(),u=new AbortController;let x=u.signal,h=t.selection,_=E?.capture?{...n.capture,...E.capture}:n.capture,q=!!(_?.element||_?.fullPage),j={phase:q?"capturing":"submitting"};h&&(j.selection=h),p(j);try{let w=q?await te({selectionElement:l,capture:_,signal:x}):void 0;if(x.aborted||d!==A)return {ok:!1};let k={phase:"submitting"};h&&(k.selection=h),w&&(k.capture=w),p(k);let P={};h&&(P.selection=h),w&&(P.capture=w);let ce=await ne({config:n.metadata,context:P}),L={version:1,createdAt:new Date().toISOString(),blocfeed_id:R,message:c,metadata:ce};h&&(L.selection=h),w&&(L.screenshots=w);let{result:F}=await se({payload:L,signal:x});if(x.aborted||d!==A)return F;if(F.ok){let D={phase:"success",lastSubmit:F};return h&&(D.selection=h),w&&(D.capture=w),p(D),F}let ue=F.api?.error??m("unknown",new Error("Submission failed")),I={phase:"error",lastSubmit:F,lastError:ue};return h&&(I.selection=h),w&&(I.capture=w),p(I),F}catch(w){if(x.aborted||d!==A)return {ok:false};let P={phase:"error",lastError:x.aborted?m("aborted",w):m("unknown",w)};return h&&(P.selection=h),p(P),{ok:false}}finally{d===A&&(u=null);}},__unsafeGetSelectedElement(){return l},destroy(){f(),r.clear(),o.clear();}}}
1
+ 'use strict';function b(){return typeof window<"u"&&typeof document<"u"}function W(e){let n=globalThis.CSS;return typeof n?.escape=="function"?n.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,t=>{let r=t.codePointAt(0);return r===void 0?"":`\\${r.toString(16)} `})}function H(e){return {x:e.x,y:e.y,width:e.width,height:e.height}}function de(e){return {x:e.x+window.scrollX,y:e.y+window.scrollY,width:e.width,height:e.height}}function fe(e){return e.replace(/\s+/g," ").trim()}function me(e,n=140){let t=e.textContent;if(!t)return;let r=fe(t);if(r)return r.length<=n?r:`${r.slice(0,n-1)}\u2026`}function pe(e){let n=1;for(let t=e.previousElementSibling;t;t=t.previousElementSibling)t.tagName===e.tagName&&(n+=1);return n}var K=["data-testid","data-test-id","data-test","data-qa","data-cy"],z="data-blocfeed-component";function ge(e){let n=e.closest(`[${z}]`);if(!n)return;let r=n.getAttribute(z)?.trim();return r||void 0}function we(e){for(let n of K){let t=e.closest(`[${n}]`);if(!t)continue;let o=t.getAttribute(n)?.trim();if(o)return o}}function he(e){try{let n=e,t=Object.getOwnPropertyNames(n);for(let r of t)if(r.startsWith("__reactFiber$")||r.startsWith("__reactInternalInstance$")){let o=n[r];if(o&&typeof o=="object")return o}}catch{}return null}function C(e){if(e&&typeof e!="string"){if(typeof e=="function"){let n=e;return typeof n.displayName=="string"&&n.displayName?n.displayName:typeof n.name=="string"&&n.name?n.name:void 0}if(typeof e=="object"){let n=e,t=n.displayName;if(typeof t=="string"&&t)return t;let r=n.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=n.type;return C(o)}}}function be(e){let n=he(e);if(!n)return;let t=n._debugOwner;for(let o=0;t&&o<50;o+=1){let i=C(t.type)??C(t.elementType);if(i)return i;t=t._debugOwner;}let r=n;for(let o=0;r&&o<80;o+=1){let i=C(r.type)??C(r.elementType);if(i)return i;r=r.return;}}function ye(e){let n=e.tagName.toLowerCase(),t=e.getAttribute("id");if(t)return `#${W(t)}`;for(let r of K){let o=e.getAttribute(r);if(o)return `${n}[${r}="${W(o)}"]`}return `${n}:nth-of-type(${pe(e)})`}function Ee(e,n=10){let t=[],r=e;for(;r&&t.length<n;){let o=ye(r);if(t.unshift(o),o.startsWith("#"))break;r=r.parentElement;}return t.join(" > ")}function Y(e,n){if(!n||n.length===0)return false;for(let t of n)if(e.closest(t))return true;return false}function N(e,n){if(!e||Y(e,n.ignoreSelectors))return null;let t=e;for(;t;){if(Y(t,n.ignoreSelectors))return null;if(n.isSelectable?.(t)??ve(t))return t;t=t.parentElement;}return null}function ve(e){let n=e.tagName;return !(n==="HTML"||n==="BODY")}function Q(e){let n=e.getBoundingClientRect(),t={selector:Ee(e),tagName:e.tagName.toLowerCase(),rect:H(n),pageRect:de(n)},r=e.getAttribute("id");r&&(t.id=r);let o=e.className;typeof o=="string"&&o.trim()&&(t.className=o);let i=me(e);i&&(t.textSnippet=i);let l=ge(e)??be(e);l&&(t.componentName=l);let s=we(e);return s&&(t.testId=s),t}var O=null;async function X(){return O||(O=import('html-to-image')),O}async function Se(e){return await new Promise((n,t)=>{let r=new Image;r.onload=()=>n({width:r.naturalWidth,height:r.naturalHeight}),r.onerror=()=>t(new Error("Failed to load generated screenshot")),r.src=e;})}async function J(e,n){let{width:t,height:r}=await Se(e);return {dataUrl:e,mime:n,width:t,height:r}}function T(e){if(e?.aborted)throw new Error("Aborted")}function G(){return {async captureElement(e,n){if(!b())throw new Error("captureElement can only run in the browser");T(n.signal);let t=await X();T(n.signal);let r=n.mime==="image/jpeg"?await t.toJpeg(e,{quality:n.quality??.92,pixelRatio:n.pixelRatio}):await t.toPng(e,{pixelRatio:n.pixelRatio});return T(n.signal),await J(r,n.mime)},async captureFullPage(e){if(!b())throw new Error("captureFullPage can only run in the browser");T(e.signal);let n=document.documentElement,t=Math.max(n.scrollWidth,n.clientWidth),r=Math.max(n.scrollHeight,n.clientHeight),o=Math.min(1,e.maxDimension/Math.max(t,r)),i=Math.max(1,Math.round(t*o)),l=Math.max(1,Math.round(r*o)),s=await X();T(e.signal);let u=e.mime==="image/jpeg"?await s.toJpeg(n,{width:i,height:l,quality:e.quality??.92,pixelRatio:e.pixelRatio}):await s.toPng(n,{width:i,height:l,pixelRatio:e.pixelRatio});return T(e.signal),await J(u,e.mime)}}}function ke(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;try{return JSON.stringify(e)}catch{return "Unknown error"}}function m(e,n,t){let r={kind:e,message:ke(n)};return t&&(r.detail=t),r}var Fe=12e3,xe=2048,Pe=.92;function Z(){return Date.now()}function Te(e){return new Promise((n,t)=>{let r=()=>t(new Error("Aborted"));if(e.aborted){r();return}e.addEventListener("abort",r,{once:true});})}async function V(e,n,t){let r=new Promise((i,l)=>{let s=setTimeout(()=>l(new Error("Timeout")),n);typeof s.unref=="function"&&s.unref();}),o=[e,r];return t&&o.push(Te(t)),await Promise.race(o)}function Ae(e){if(!b())return 1;let n=window.devicePixelRatio||1,t=e?.pixelRatio??Math.min(n,2);return Math.max(.1,t)}function Ce(e){return !!(e?.element||e?.fullPage)}function ee(e){let n={mime:e.mime,pixelRatio:e.pixelRatio,maxDimension:e.maxDimension};return e.includeQuality&&(n.quality=e.quality),e.signal&&(n.signal=e.signal),n}async function te(e){let{selectionElement:n,capture:t,signal:r}=e;if(!b()||!Ce(t))return;let o=Z(),i=[],l=t?.timeoutMs??Fe,s=t?.maxDimension??xe,u=t?.mime??"image/png",d=t?.quality??Pe,v=t?.adapter??G(),y={},p=Ae(t);if(t?.element&&n)try{let f=n.getBoundingClientRect(),g=Math.min(1,s/Math.max(f.width,f.height)),c=Math.min(p,p*g),E=await V(Promise.resolve(v.captureElement(n,{...ee({mime:u,quality:d,pixelRatio:c,maxDimension:s,includeQuality:u==="image/jpeg",...r?{signal:r}:{}})})),l,r);y.element=E;}catch(f){if(r?.aborted)throw f;i.push(m("capture_failed",f,{target:"element"}));}if(t?.fullPage)try{let f=await V(Promise.resolve(v.captureFullPage(ee({mime:u,quality:d,pixelRatio:p,maxDimension:s,includeQuality:u==="image/jpeg",...r?{signal:r}:{}}))),l,r);y.fullPage=f;}catch(f){if(r?.aborted)throw f;i.push(m("capture_failed",f,{target:"fullPage"}));}let S=Z(),a={startedAt:o,finishedAt:S,durationMs:Math.max(0,S-o)};return i.length>0&&(a.errors=i),{...y,diagnostics:a}}function Re(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return}}function Me(){return b()?{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:Re()}:{}}async function ne(e){let{config:n,context:t}=e;if(n?.enabled===false)return {};let r=Me(),o=n?.enrich;if(!o)return r;try{let i=await o(t);return {...r,...i}}catch(i){let l=m("unknown",i);return {...r,blocfeedMetadataError:l.message}}}function U(e){let n=null,t=null,r=(...o)=>{t=o,n===null&&(n=requestAnimationFrame(()=>{if(n=null,!t)return;let i=t;t=null,e(...i);}));};return r.cancel=()=>{n!==null&&cancelAnimationFrame(n),n=null,t=null;},r}function M(e){return e instanceof Element?!!e.closest("[data-blocfeed-ui]"):false}function B(e){e.stopPropagation(),e.stopImmediatePropagation?.();}function re(e,n){if(!b())throw new Error("BlocFeed picker can only run in a browser environment.");let t=e.ignoreSelectors,r=e.isSelectable,o={};t&&t.length>0&&(o.ignoreSelectors=t),r&&(o.isSelectable=r);let i=null,l=null,s=(a,f=false)=>{if(!a){i=null,l=null,n.onHover(null);return}let g=H(a.getBoundingClientRect()),c=`${Math.round(g.x)}:${Math.round(g.y)}:${Math.round(g.width)}:${Math.round(g.height)}`;!f&&a===i&&c===l||(i=a,l=c,n.onHover({element:a,rect:g}));},u=U(a=>{if(M(a.target))return;let f=document.elementFromPoint(a.clientX,a.clientY),g=N(f,o);s(g);}),d=U(()=>{i&&s(i,true);}),v=a=>{M(a.target)||(B(a),a.pointerType==="mouse"&&a.preventDefault());},y=a=>{M(a.target)||(B(a),a.pointerType==="mouse"&&a.preventDefault());},p=a=>{if(M(a.target))return;B(a),a.preventDefault();let f=document.elementFromPoint(a.clientX,a.clientY),g=N(f,o);g&&n.onSelect({element:g,descriptor:Q(g)});},S=a=>{a.key==="Escape"&&(B(a),a.preventDefault(),n.onCancel());};return window.addEventListener("pointermove",u,{capture:true,passive:true}),window.addEventListener("pointerdown",v,{capture:true}),window.addEventListener("pointerup",y,{capture:true}),window.addEventListener("click",p,{capture:true}),window.addEventListener("keydown",S,{capture:true}),window.addEventListener("scroll",d,{capture:true,passive:true}),window.addEventListener("resize",d,{passive:true}),{stop(){window.removeEventListener("pointermove",u,{capture:true}),window.removeEventListener("pointerdown",v,{capture:true}),window.removeEventListener("pointerup",y,{capture:true}),window.removeEventListener("click",p,{capture:true}),window.removeEventListener("keydown",S,{capture:true}),window.removeEventListener("scroll",d,{capture:true}),window.removeEventListener("resize",d),u.cancel(),d.cancel(),n.onHover(null);}}}var Be=12e3,$=2,oe=500,_e="https://blocfeed.com/api/feedback";function ie(e,n){return new Promise((t,r)=>{if(n?.aborted){r(new Error("Aborted"));return}let o=setTimeout(t,e),i=()=>{clearTimeout(o),r(new Error("Aborted"));};n?.addEventListener("abort",i,{once:true});})}function Le(e){return e>=500&&e<=599}async function ae(e){let{payload:n,signal:t}=e;for(let r=1;r<=$;r+=1){let o=new AbortController,i=setTimeout(()=>o.abort(),Be),l=()=>o.abort();t&&t.addEventListener("abort",l,{once:true});try{let s=await fetch(_e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n),signal:o.signal});if(s.ok)return {ok:!0,status:s.status};if(r<$&&Le(s.status)){let u=.85+Math.random()*.3,d=Math.round(oe*2**(r-1)*u);await ie(d,t);continue}return {ok:!1,status:s.status,error:m("api_failed",new Error(`HTTP ${s.status}`))}}catch(s){if(o.signal.aborted||t?.aborted)return {ok:false,error:m("aborted",s)};if(r<$){let u=.85+Math.random()*.3,d=Math.round(oe*2**(r-1)*u);await ie(d,t);continue}return {ok:false,error:m("api_failed",s)}}finally{clearTimeout(i),t&&t.removeEventListener("abort",l);}}return {ok:false,error:m("api_failed",new Error("Failed"))}}async function se(e){let{signal:n}=e,t={ok:false};try{let r=n?{payload:e.payload,signal:n}:{payload:e.payload};t.api=await ae(r),t.ok=!!t.api?.ok;}catch(r){t.api={ok:false,error:m("api_failed",r)},t.ok=false;}return {payload:e.payload,result:t}}var Ie=["[data-blocfeed-ui]","[data-blocfeed-ignore]"];function De(e){let n=[...Ie,...e?.ignoreSelectors??[]],t=Array.from(new Set(n));return {...e,ignoreSelectors:t}}function le(){return {phase:"idle"}}function ut(e){let n=e,t=le(),r=new Set,o=new Set,i=null,l=null,s=null,u=null,d=0,v=()=>{for(let c of r)c(t);},y=c=>{for(let E of o)E(c);},p=c=>{t=c,v();},S=()=>{d+=1,u?.abort(),u=null;},a=()=>{i?.stop(),i=null,y(null),s!==null&&b()&&(document.documentElement.style.cursor=s,s=null);},f=()=>{S(),a(),l=null,p(le());},g=()=>{if(!b())return;a(),l=null;let c=De(n.picker);s=document.documentElement.style.cursor,document.documentElement.style.cursor="crosshair",p({phase:"picking"}),i=re(c,{onHover:y,onSelect:({element:E,descriptor:R})=>{l=E,a(),p({phase:"review",selection:R});},onCancel:()=>{f();}});};return {getState:()=>t,subscribe(c){return r.add(c),()=>r.delete(c)},subscribeHover(c){return o.add(c),()=>o.delete(c)},start(){t.phase==="capturing"||t.phase==="submitting"||t.phase!=="picking"&&g();},stop(){f();},clearSelection(){t.phase==="capturing"||t.phase==="submitting"||g();},setConfig(c){n=c;},async submit(c,E){if(!b()){let w=m("configuration",new Error("BlocFeed submit can only run in the browser"));return p({phase:"error",lastError:w}),{ok:false}}let R=n.blocfeed_id?.trim?.()??"";if(!R){let k={phase:"error",lastError:m("configuration",new Error("Missing blocfeed_id. Create a project in BlocFeed and pass its blocfeed_id."))};return t.selection&&(k.selection=t.selection),p(k),{ok:false}}if(t.phase==="capturing"||t.phase==="submitting")return {ok:false};let A=d+1;d=A,u?.abort(),u=new AbortController;let x=u.signal,h=t.selection,_=E?.capture?{...n.capture,...E.capture}:n.capture,q=!!(_?.element||_?.fullPage),j={phase:q?"capturing":"submitting"};h&&(j.selection=h),p(j);try{let w=q?await te({selectionElement:l,capture:_,signal:x}):void 0;if(x.aborted||d!==A)return {ok:!1};let k={phase:"submitting"};h&&(k.selection=h),w&&(k.capture=w),p(k);let P={};h&&(P.selection=h),w&&(P.capture=w);let ce=await ne({config:n.metadata,context:P}),L={version:1,createdAt:new Date().toISOString(),blocfeed_id:R,message:c,metadata:ce};h&&(L.selection=h),w&&(L.screenshots=w);let{result:F}=await se({payload:L,signal:x});if(x.aborted||d!==A)return F;if(F.ok){let D={phase:"success",lastSubmit:F};return h&&(D.selection=h),w&&(D.capture=w),p(D),F}let ue=F.api?.error??m("unknown",new Error("Submission failed")),I={phase:"error",lastSubmit:F,lastError:ue};return h&&(I.selection=h),w&&(I.capture=w),p(I),F}catch(w){if(x.aborted||d!==A)return {ok:false};let P={phase:"error",lastError:x.aborted?m("aborted",w):m("unknown",w)};return h&&(P.selection=h),p(P),{ok:false}}finally{d===A&&(u=null);}},__unsafeGetSelectedElement(){return l},destroy(){f(),r.clear(),o.clear();}}}
2
2
  exports.a=b;exports.b=H;exports.c=G;exports.d=te;exports.e=ne;exports.f=ut;
package/dist/engine.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkNMFAZKHE_cjs=require('./chunk-NMFAZKHE.cjs');function d(n){let[r,o]=n.split(",",2);if(!r||!o)throw new Error("Invalid data URL");let c=/data:(.*?);base64/.exec(r)?.[1]||"application/octet-stream",t=atob(o),a=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)a[e]=t.charCodeAt(e);return new Blob([a],{type:c})}Object.defineProperty(exports,"collectMetadata",{enumerable:true,get:function(){return chunkNMFAZKHE_cjs.e}});Object.defineProperty(exports,"createBlocFeedController",{enumerable:true,get:function(){return chunkNMFAZKHE_cjs.f}});Object.defineProperty(exports,"createHtmlToImageAdapter",{enumerable:true,get:function(){return chunkNMFAZKHE_cjs.c}});Object.defineProperty(exports,"runCapture",{enumerable:true,get:function(){return chunkNMFAZKHE_cjs.d}});exports.dataUrlToBlob=d;
1
+ 'use strict';var chunkPEPIK3FN_cjs=require('./chunk-PEPIK3FN.cjs');function d(n){let[r,o]=n.split(",",2);if(!r||!o)throw new Error("Invalid data URL");let c=/data:(.*?);base64/.exec(r)?.[1]||"application/octet-stream",t=atob(o),a=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)a[e]=t.charCodeAt(e);return new Blob([a],{type:c})}Object.defineProperty(exports,"collectMetadata",{enumerable:true,get:function(){return chunkPEPIK3FN_cjs.e}});Object.defineProperty(exports,"createBlocFeedController",{enumerable:true,get:function(){return chunkPEPIK3FN_cjs.f}});Object.defineProperty(exports,"createHtmlToImageAdapter",{enumerable:true,get:function(){return chunkPEPIK3FN_cjs.c}});Object.defineProperty(exports,"runCapture",{enumerable:true,get:function(){return chunkPEPIK3FN_cjs.d}});exports.dataUrlToBlob=d;
package/dist/engine.js CHANGED
@@ -1 +1 @@
1
- export{e as collectMetadata,f as createBlocFeedController,c as createHtmlToImageAdapter,d as runCapture}from'./chunk-H36VLJXX.js';function d(n){let[r,o]=n.split(",",2);if(!r||!o)throw new Error("Invalid data URL");let c=/data:(.*?);base64/.exec(r)?.[1]||"application/octet-stream",t=atob(o),a=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)a[e]=t.charCodeAt(e);return new Blob([a],{type:c})}export{d as dataUrlToBlob};
1
+ export{e as collectMetadata,f as createBlocFeedController,c as createHtmlToImageAdapter,d as runCapture}from'./chunk-37P3GL6V.js';function d(n){let[r,o]=n.split(",",2);if(!r||!o)throw new Error("Invalid data URL");let c=/data:(.*?);base64/.exec(r)?.[1]||"application/octet-stream",t=atob(o),a=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)a[e]=t.charCodeAt(e);return new Blob([a],{type:c})}export{d as dataUrlToBlob};
package/dist/main.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- 'use strict';var chunkNMFAZKHE_cjs=require('./chunk-NMFAZKHE.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');var g=react.createContext(null);function w(t){let e=react.useMemo(()=>chunkNMFAZKHE_cjs.f({...t.config??{},blocfeed_id:t.blocfeed_id}),[]),[a,l]=react.useState(()=>e.getState());return react.useEffect(()=>e.subscribe(l),[e]),react.useEffect(()=>e.setConfig({...t.config??{},blocfeed_id:t.blocfeed_id}),[e,t.config,t.blocfeed_id]),react.useEffect(()=>()=>e.destroy(),[e]),jsxRuntime.jsx(g.Provider,{value:{controller:e,state:a},children:t.children})}var H="blocfeed-styles-v1",D=`
2
+ 'use strict';var chunkPEPIK3FN_cjs=require('./chunk-PEPIK3FN.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');var g=react.createContext(null);function w(t){let e=react.useMemo(()=>chunkPEPIK3FN_cjs.f({...t.config??{},blocfeed_id:t.blocfeed_id}),[]),[a,l]=react.useState(()=>e.getState());return react.useEffect(()=>e.subscribe(l),[e]),react.useEffect(()=>e.setConfig({...t.config??{},blocfeed_id:t.blocfeed_id}),[e,t.config,t.blocfeed_id]),react.useEffect(()=>()=>e.destroy(),[e]),jsxRuntime.jsx(g.Provider,{value:{controller:e,state:a},children:t.children})}var H="blocfeed-styles-v1",D=`
3
3
  :where([data-blocfeed-ui-root]),
4
4
  :where([data-blocfeed-ui-root]) * {
5
5
  box-sizing: border-box;
@@ -220,4 +220,4 @@
220
220
  font-size: 13px;
221
221
  color: rgba(243, 244, 246, 0.9);
222
222
  }
223
- `;function T(){if(!chunkNMFAZKHE_cjs.a()||document.getElementById(H))return;let t=document.createElement("style");t.id=H,t.textContent=D,document.head.appendChild(t);}function y(){let t=react.useContext(g);if(!t)throw new Error("useBlocFeed must be used within a <BlocFeedProvider />");return {state:t.state,controller:t.controller,start:t.controller.start,stop:t.controller.stop,clearSelection:t.controller.clearSelection,submit:t.controller.submit}}function X(t,e,a){return Math.max(e,Math.min(a,t))}function G(t,e){let l=window.innerWidth,r=window.innerHeight,s=X(t.x,12,Math.max(12,l-e-12)),p=t.y+t.height+12,m=Math.max(12,t.y-240);return {top:p+240<=r?p:m,left:s}}function V(t){let{rect:e}=t,a={left:`${e.x}px`,top:`${e.y}px`,width:`${Math.max(0,e.width)}px`,height:`${Math.max(0,e.height)}px`};return jsxRuntime.jsx("div",{className:"bf-highlight",style:a})}function Y(t){let{state:e,controller:a,start:l,stop:r,clearSelection:s,submit:p}=y(),[m,C]=react.useState(null),[h,F]=react.useState(""),[B,k]=react.useState(t.config.capture?.element??true),[S,P]=react.useState(t.config.capture?.fullPage??false),[A,N]=react.useState(null);react.useEffect(()=>a.subscribeHover(C),[a]),react.useEffect(()=>{let n=a.__unsafeGetSelectedElement();if(!n||e.phase==="idle"||e.phase==="picking"){N(null);return}let z=()=>{N(chunkNMFAZKHE_cjs.b(n.getBoundingClientRect()));};z();let u=()=>z();return window.addEventListener("scroll",u,{capture:true,passive:true}),window.addEventListener("resize",u,{passive:true}),()=>{window.removeEventListener("scroll",u,{capture:true}),window.removeEventListener("resize",u);}},[a,e.phase,e.selection?.selector]),react.useEffect(()=>{e.phase==="review"&&(F(""),k(t.config.capture?.element??true),P(t.config.capture?.fullPage??false));},[e.phase,e.selection?.selector,t.config.capture?.element,t.config.capture?.fullPage]),react.useEffect(()=>{if(e.phase!=="success")return;let n=window.setTimeout(()=>r(),1200);return ()=>window.clearTimeout(n)},[e.phase,r]);let d=e.phase==="capturing"||e.phase==="submitting",c=e.phase==="picking"?m?.rect??null:A??e.selection?.rect??null,x=react.useMemo(()=>c?G(c,360):null,[c?.x,c?.y,c?.width,c?.height]),R=e.lastError?.message;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e.phase==="idle"&&jsxRuntime.jsxs("button",{className:"bf-trigger",type:"button",onClick:()=>l(),"aria-label":"Give feedback",children:[jsxRuntime.jsx("span",{className:"bf-dot","aria-hidden":"true"}),"Feedback"]}),e.phase!=="idle"&&jsxRuntime.jsxs("div",{className:"bf-overlay",children:[e.phase!=="picking"&&jsxRuntime.jsx("div",{className:"bf-blocker",role:"presentation",onClick:()=>r()}),c&&jsxRuntime.jsx(V,{rect:c}),e.phase==="picking"&&jsxRuntime.jsxs("div",{className:"bf-hint",children:[jsxRuntime.jsxs("p",{children:["Click an element to attach your feedback. Press ",jsxRuntime.jsx("strong",{children:"Esc"})," to cancel."]}),jsxRuntime.jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),children:"Cancel"})]}),(e.phase==="review"||e.phase==="capturing"||e.phase==="submitting"||e.phase==="error"||e.phase==="success")&&x&&jsxRuntime.jsxs("div",{className:"bf-panel",style:{left:x.left,top:x.top},children:[jsxRuntime.jsxs("div",{className:"bf-panelHeader",children:[jsxRuntime.jsx("div",{className:"bf-title",children:"Feedback"}),jsxRuntime.jsxs("div",{className:"bf-row",style:{justifyContent:"flex-end"},children:[jsxRuntime.jsx("button",{type:"button",className:"bf-btn",onClick:()=>s(),disabled:d,children:"Re-pick"}),jsxRuntime.jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),disabled:d,children:"Close"})]})]}),jsxRuntime.jsxs("div",{className:"bf-panelBody",children:[jsxRuntime.jsx("textarea",{className:"bf-textarea",placeholder:"What\u2019s happening? What did you expect?",value:h,onChange:n=>F(n.target.value),disabled:d}),jsxRuntime.jsxs("div",{className:"bf-row",children:[jsxRuntime.jsxs("label",{children:[jsxRuntime.jsx("input",{type:"checkbox",checked:B,onChange:n=>k(n.target.checked),disabled:d}),"Screenshot element"]}),jsxRuntime.jsxs("label",{children:[jsxRuntime.jsx("input",{type:"checkbox",checked:S,onChange:n=>P(n.target.checked),disabled:d}),"Full page"]})]}),e.phase==="capturing"&&jsxRuntime.jsx("div",{className:"bf-status",children:"Capturing screenshots\u2026"}),e.phase==="submitting"&&jsxRuntime.jsx("div",{className:"bf-status",children:"Submitting\u2026"}),e.phase==="success"&&jsxRuntime.jsx("div",{className:"bf-status",children:"Sent. Thank you!"}),e.phase==="error"&&R&&jsxRuntime.jsx("div",{className:"bf-error",children:R}),jsxRuntime.jsxs("div",{className:"bf-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),disabled:d,children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",className:"bf-btn bf-btnPrimary",onClick:()=>p(h,{capture:{element:B,fullPage:S}}),disabled:d||h.trim().length===0,children:"Send"})]})]})]})]}),e.phase==="success"&&jsxRuntime.jsx("div",{className:"bf-toast","aria-live":"polite",children:"Feedback sent"})]})}function q(t){let e={...t.config??{},blocfeed_id:t.blocfeed_id},[a,l]=react.useState(null);return react.useEffect(()=>{T();let r=document.createElement("div");r.setAttribute("data-blocfeed-ui-root","true"),r.setAttribute("data-blocfeed-ui","true");let s=e.ui?.zIndex;return typeof s=="number"&&r.style.setProperty("--bf-z",String(s)),document.body.appendChild(r),l(r),()=>{r.remove(),l(null);}},[e.ui?.zIndex]),a?reactDom.createPortal(jsxRuntime.jsx(w,{blocfeed_id:e.blocfeed_id,...t.config?{config:t.config}:{},children:jsxRuntime.jsx(Y,{config:e})}),a):null}exports.BlocFeedProvider=w;exports.BlocFeedWidget=q;exports.useBlocFeed=y;
223
+ `;function T(){if(!chunkPEPIK3FN_cjs.a()||document.getElementById(H))return;let t=document.createElement("style");t.id=H,t.textContent=D,document.head.appendChild(t);}function y(){let t=react.useContext(g);if(!t)throw new Error("useBlocFeed must be used within a <BlocFeedProvider />");return {state:t.state,controller:t.controller,start:t.controller.start,stop:t.controller.stop,clearSelection:t.controller.clearSelection,submit:t.controller.submit}}function X(t,e,a){return Math.max(e,Math.min(a,t))}function G(t,e){let l=window.innerWidth,r=window.innerHeight,s=X(t.x,12,Math.max(12,l-e-12)),p=t.y+t.height+12,m=Math.max(12,t.y-240);return {top:p+240<=r?p:m,left:s}}function V(t){let{rect:e}=t,a={left:`${e.x}px`,top:`${e.y}px`,width:`${Math.max(0,e.width)}px`,height:`${Math.max(0,e.height)}px`};return jsxRuntime.jsx("div",{className:"bf-highlight",style:a})}function Y(t){let{state:e,controller:a,start:l,stop:r,clearSelection:s,submit:p}=y(),[m,C]=react.useState(null),[h,F]=react.useState(""),[B,k]=react.useState(t.config.capture?.element??true),[S,P]=react.useState(t.config.capture?.fullPage??false),[A,N]=react.useState(null);react.useEffect(()=>a.subscribeHover(C),[a]),react.useEffect(()=>{let n=a.__unsafeGetSelectedElement();if(!n||e.phase==="idle"||e.phase==="picking"){N(null);return}let z=()=>{N(chunkPEPIK3FN_cjs.b(n.getBoundingClientRect()));};z();let u=()=>z();return window.addEventListener("scroll",u,{capture:true,passive:true}),window.addEventListener("resize",u,{passive:true}),()=>{window.removeEventListener("scroll",u,{capture:true}),window.removeEventListener("resize",u);}},[a,e.phase,e.selection?.selector]),react.useEffect(()=>{e.phase==="review"&&(F(""),k(t.config.capture?.element??true),P(t.config.capture?.fullPage??false));},[e.phase,e.selection?.selector,t.config.capture?.element,t.config.capture?.fullPage]),react.useEffect(()=>{if(e.phase!=="success")return;let n=window.setTimeout(()=>r(),1200);return ()=>window.clearTimeout(n)},[e.phase,r]);let d=e.phase==="capturing"||e.phase==="submitting",c=e.phase==="picking"?m?.rect??null:A??e.selection?.rect??null,x=react.useMemo(()=>c?G(c,360):null,[c?.x,c?.y,c?.width,c?.height]),R=e.lastError?.message;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[e.phase==="idle"&&jsxRuntime.jsxs("button",{className:"bf-trigger",type:"button",onClick:()=>l(),"aria-label":"Give feedback",children:[jsxRuntime.jsx("span",{className:"bf-dot","aria-hidden":"true"}),"Feedback"]}),e.phase!=="idle"&&jsxRuntime.jsxs("div",{className:"bf-overlay",children:[e.phase!=="picking"&&jsxRuntime.jsx("div",{className:"bf-blocker",role:"presentation",onClick:()=>r()}),c&&jsxRuntime.jsx(V,{rect:c}),e.phase==="picking"&&jsxRuntime.jsxs("div",{className:"bf-hint",children:[jsxRuntime.jsxs("p",{children:["Click an element to attach your feedback. Press ",jsxRuntime.jsx("strong",{children:"Esc"})," to cancel."]}),jsxRuntime.jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),children:"Cancel"})]}),(e.phase==="review"||e.phase==="capturing"||e.phase==="submitting"||e.phase==="error"||e.phase==="success")&&x&&jsxRuntime.jsxs("div",{className:"bf-panel",style:{left:x.left,top:x.top},children:[jsxRuntime.jsxs("div",{className:"bf-panelHeader",children:[jsxRuntime.jsx("div",{className:"bf-title",children:"Feedback"}),jsxRuntime.jsxs("div",{className:"bf-row",style:{justifyContent:"flex-end"},children:[jsxRuntime.jsx("button",{type:"button",className:"bf-btn",onClick:()=>s(),disabled:d,children:"Re-pick"}),jsxRuntime.jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),disabled:d,children:"Close"})]})]}),jsxRuntime.jsxs("div",{className:"bf-panelBody",children:[jsxRuntime.jsx("textarea",{className:"bf-textarea",placeholder:"What\u2019s happening? What did you expect?",value:h,onChange:n=>F(n.target.value),disabled:d}),jsxRuntime.jsxs("div",{className:"bf-row",children:[jsxRuntime.jsxs("label",{children:[jsxRuntime.jsx("input",{type:"checkbox",checked:B,onChange:n=>k(n.target.checked),disabled:d}),"Screenshot element"]}),jsxRuntime.jsxs("label",{children:[jsxRuntime.jsx("input",{type:"checkbox",checked:S,onChange:n=>P(n.target.checked),disabled:d}),"Full page"]})]}),e.phase==="capturing"&&jsxRuntime.jsx("div",{className:"bf-status",children:"Capturing screenshots\u2026"}),e.phase==="submitting"&&jsxRuntime.jsx("div",{className:"bf-status",children:"Submitting\u2026"}),e.phase==="success"&&jsxRuntime.jsx("div",{className:"bf-status",children:"Sent. Thank you!"}),e.phase==="error"&&R&&jsxRuntime.jsx("div",{className:"bf-error",children:R}),jsxRuntime.jsxs("div",{className:"bf-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"bf-btn",onClick:()=>r(),disabled:d,children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",className:"bf-btn bf-btnPrimary",onClick:()=>p(h,{capture:{element:B,fullPage:S}}),disabled:d||h.trim().length===0,children:"Send"})]})]})]})]}),e.phase==="success"&&jsxRuntime.jsx("div",{className:"bf-toast","aria-live":"polite",children:"Feedback sent"})]})}function q(t){let e={...t.config??{},blocfeed_id:t.blocfeed_id},[a,l]=react.useState(null);return react.useEffect(()=>{T();let r=document.createElement("div");r.setAttribute("data-blocfeed-ui-root","true"),r.setAttribute("data-blocfeed-ui","true");let s=e.ui?.zIndex;return typeof s=="number"&&r.style.setProperty("--bf-z",String(s)),document.body.appendChild(r),l(r),()=>{r.remove(),l(null);}},[e.ui?.zIndex]),a?reactDom.createPortal(jsxRuntime.jsx(w,{blocfeed_id:e.blocfeed_id,...t.config?{config:t.config}:{},children:jsxRuntime.jsx(Y,{config:e})}),a):null}exports.BlocFeedProvider=w;exports.BlocFeedWidget=q;exports.useBlocFeed=y;
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import {f,a,b}from'./chunk-H36VLJXX.js';import {createContext,useMemo,useState,useEffect,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';var g=createContext(null);function w(t){let e=useMemo(()=>f({...t.config??{},blocfeed_id:t.blocfeed_id}),[]),[a,l]=useState(()=>e.getState());return useEffect(()=>e.subscribe(l),[e]),useEffect(()=>e.setConfig({...t.config??{},blocfeed_id:t.blocfeed_id}),[e,t.config,t.blocfeed_id]),useEffect(()=>()=>e.destroy(),[e]),jsx(g.Provider,{value:{controller:e,state:a},children:t.children})}var H="blocfeed-styles-v1",D=`
2
+ import {f,a,b}from'./chunk-37P3GL6V.js';import {createContext,useMemo,useState,useEffect,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';var g=createContext(null);function w(t){let e=useMemo(()=>f({...t.config??{},blocfeed_id:t.blocfeed_id}),[]),[a,l]=useState(()=>e.getState());return useEffect(()=>e.subscribe(l),[e]),useEffect(()=>e.setConfig({...t.config??{},blocfeed_id:t.blocfeed_id}),[e,t.config,t.blocfeed_id]),useEffect(()=>()=>e.destroy(),[e]),jsx(g.Provider,{value:{controller:e,state:a},children:t.children})}var H="blocfeed-styles-v1",D=`
3
3
  :where([data-blocfeed-ui-root]),
4
4
  :where([data-blocfeed-ui-root]) * {
5
5
  box-sizing: border-box;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blocfeed",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Drop-in feedback + screenshot widget for React.",
5
5
  "license": "MIT",
6
6
  "type": "module",