@snippyly/plugin-staging 1.0.909 → 1.0.911
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/package.json +1 -1
- package/snippyly-live.min.js +1 -1
- package/snippyly-toolbar.js +277 -277
- package/snippyly-toolbar.min.js +277 -277
- package/snippyly.js +1 -1
- package/snippyly.min.js +1 -1
package/package.json
CHANGED
package/snippyly-live.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t){const e="1.0.767",s=["review","feedback"],n="_sfls",i="sf_review",r=2e3;function o(t){try{return"undefined"!=typeof CSS&&"function"==typeof CSS.escape?CSS.escape(t):t.replace(/([^a-zA-Z0-9_-])/g,"\\$1")}catch(e){return t}}function a(t,e){try{return!!e&&1===t.querySelectorAll(`#${o(e)}`).length}catch(t){return!1}}function l(t){try{let e=1,s=t.previousElementSibling;for(;s;)s.tagName===t.tagName&&(e+=1),s=s.previousElementSibling;return e}catch(t){return 1}}function c(t,e){try{const s=t.getAttribute("id")||"";if(a(e,s))return d([`#${o(s)}`]);const n=[];let i=t;for(;i;){const s=i.tagName.toLowerCase();if("body"===s||"html"===s){n.unshift("html"===s?"html":"body");break}const r=i.getAttribute("id")||"";if(i!==t&&a(e,r)){n.unshift(`#${o(r)}`);break}n.unshift(`${s}:nth-of-type(${l(i)})`),i=i.parentElement}return d(n)}catch(e){return console.warn("[superflow live] buildSelector failed:",e),t&&t.tagName?t.tagName.toLowerCase():"body"}}function d(t){try{const e=t.slice();let s=e.join(" > ");for(;s.length>r&&e.length>1;)e.shift(),s=e.join(" > ");return s.length>r?s.slice(0,r):s}catch(e){return t.join(" > ")}}function h(t){return Number.isFinite(t)?Math.round(100*Math.min(100,Math.max(0,t)))/100:0}const f=["invalid","expired","revoked","exhausted","origin-mismatch","disabled","not-found","rate-limited","internal"],p=["invalid","expired","revoked","exhausted"];async function u(t,e,s){try{const n=await t.fetchFn(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:{subEventType:e,...s}})});if(!n||!n.ok)return{kind:"transport"};let i;try{i=await n.json()}catch(t){return{kind:"transport"}}const r=i&&"object"==typeof i?i.result:void 0;if(null==r||"object"!=typeof r)return{kind:"transport"};const o=r.error;return o&&"object"==typeof o?{kind:"error",code:x(o.code)}:{kind:"ok",result:r}}catch(t){return{kind:"transport"}}}function x(t){try{return"string"==typeof t&&f.includes(t)?t:"internal"}catch(t){return"internal"}}const g="superflow-live",b=5e3,v="Superflow",y="Continue to request changes on this site",m="Continue",w="Continuing...",k="Not now",N="This link has expired.",I="Send me a fresh one",S="Sending...",P="Check your email.",L="Could not send. Try again.",C="Request a change",R="Request a change",$="My requests",T="Close",M="Click the part of the page you want changed. Press Esc to cancel.",q="What should change here?",z="Send",F="Sending...",j="Cancel",A="Sent. We'll reply here.",E="Too many requests right now. Try again in a minute.",K="Could not send. Try again.",U="Loading...",O="No requests yet.",Y="Could not load requests.",B="Reply",D="Reply",G="You",W="Agency",_="Received",X="We're on it",H="Done";function J(t,e,s={}){const n=t.createElement(e);return s.className&&(n.className=s.className),void 0!==s.text&&(n.textContent=s.text),s.testId&&n.setAttribute("data-testid",s.testId),s.attrs&&Object.keys(s.attrs).forEach((t=>n.setAttribute(t,s.attrs[t]))),n}function Z(t,e,s,n="sf-btn"){return J(t,"button",{className:n,text:e,testId:s,attrs:{type:"button"}})}function Q(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function V(t){try{const e=new URL(t);return e.searchParams.delete(i),e.toString()}catch(e){return t}}function tt(t){const e="string"==typeof t?t:"";return e.length>200?`${e.slice(0,200)}…`:e}function et(t){if("string"!=typeof t||!t)return"";try{return new URL(t).pathname}catch(e){return t}}function st(t){try{if(null==t||""===t)return"";const e=new Date(t);return Number.isNaN(e.getTime())?"":e.toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch(t){return""}}function nt(t){switch(t){case"working":return X;case"done":return H;default:return _}}function it(t,e){try{return t?t.getItem(e):null}catch(t){return null}}class rt{constructor(t){this.host=null,this.root=null,this.session=null,this.grant=null,this.tab=null,this.panel=null,this.listBody=null,this.pick=null,this.form=null,this.warned=new Set,this.deps=t,this.api=function(t){const e=t.origin;return{redeemLiveReviewToken:s=>u(t,"redeemLiveReviewToken",{token:s,origin:e,userAgent:t.userAgent}),validateLiveSession:s=>u(t,"validateLiveSession",{session:s,origin:e}),createLiveRequest:s=>u(t,"createLiveRequest",{session:s.session,origin:e,pageUrl:s.pageUrl,text:s.text,...s.anchor?{anchor:s.anchor}:{},viewport:s.viewport,userAgent:t.userAgent,...s.versionId?{versionId:s.versionId}:{}}),listMyLiveRequests:s=>u(t,"listMyLiveRequests",{session:s,origin:e}),replyToLiveRequest:(s,n,i)=>u(t,"replyToLiveRequest",{session:s,origin:e,annotationId:n,text:i}),requestFreshLink:s=>u(t,"requestFreshLink",{token:s,origin:e})}}({fetchFn:t.fetchFn,endpoint:t.endpoint,origin:this.origin(),userAgent:t.userAgent})}async start(){var t;try{const{doc:e,win:s,storage:r}=this.deps;if(e.querySelector(g))return"skipped";const o=new URLSearchParams((null===(t=s.location)||void 0===t?void 0:t.search)||"").get(i),a=it(r,n);return o?(this.showPrompt(o),"prompt"):a?this.validate(a):"none"}catch(t){return this.warn("start failed, drawing nothing",t),"none"}}async validate(t){try{const e=await this.api.validateLiveSession(t);return"transport"===e.kind?"kept":"error"===e.kind?(this.clearSession(),"cleared"):this.acceptGrant(t,e.result)}catch(t){return this.warn("validate failed, drawing nothing",t),"kept"}}acceptGrant(t,e){try{return e&&e.project&&!1!==e.project.enabled?(this.session=t,this.grant=e,this.drawTab(),"tab"):"disabled"}catch(t){return this.warn("acceptGrant failed",t),"disabled"}}showPrompt(t){try{const e=this.deps.doc,s=this.ensureRoot(),n=J(e,"div",{className:"sf-ui sf-card-box",testId:"sf-live-prompt",attrs:{role:"dialog"}});n.appendChild(J(e,"div",{className:"sf-brand",text:v})),n.appendChild(J(e,"div",{text:y,attrs:{style:"margin-top:6px"}}));const i=J(e,"div",{className:"sf-row"}),r=Z(e,m,"sf-live-continue"),o=Z(e,k,"sf-live-not-now","sf-btn sf-btn--ghost");i.appendChild(r),i.appendChild(o),n.appendChild(i),r.addEventListener("click",(()=>{this.redeem(t,n,r)})),o.addEventListener("click",(()=>{this.dismissPrompt(n)})),s.appendChild(n)}catch(t){this.warn("showPrompt failed",t)}}async dismissPrompt(t){try{t.remove();const e=it(this.deps.storage,n);e?await this.validate(e):this.teardownIfEmpty()}catch(t){this.warn("dismissPrompt failed",t)}}async redeem(t,e,s){try{if(s.disabled)return;s.disabled=!0,s.textContent=w;const n=await this.api.redeemLiveReviewToken(t);if("ok"===n.kind)return this.storeSession(n.result.session),this.clearStoredToolbarFlags(),this.stripTokenFromLocation(),e.remove(),void this.acceptGrant(n.result.session,n.result);if("error"===n.kind&&p.includes(n.code))return void this.showExpired(t,e);e.remove(),this.teardownIfEmpty(),this.warn(`redeem refused (${"error"===n.kind?n.code:"transport"})`)}catch(t){this.warn("redeem failed",t),e.remove(),this.teardownIfEmpty()}}showExpired(t,e){try{const s=this.deps.doc;Q(e),e.setAttribute("data-testid","sf-live-expired"),e.appendChild(J(s,"div",{className:"sf-brand",text:v}));const n=J(s,"div",{text:N,testId:"sf-live-expired-line",attrs:{style:"margin-top:6px"}});e.appendChild(n);const i=J(s,"div",{className:"sf-row"}),r=Z(s,I,"sf-live-fresh-link");i.appendChild(r),e.appendChild(i),r.addEventListener("click",(()=>{this.requestFreshLink(t,n,r)}))}catch(t){this.warn("showExpired failed",t)}}async requestFreshLink(t,e,s){try{if(s.disabled)return;s.disabled=!0,s.textContent=S;const n=await this.api.requestFreshLink(t);if("ok"===n.kind&&n.result&&n.result.sent)return e.textContent=P,void s.remove();e.textContent=L,s.disabled=!1,s.textContent=I}catch(t){this.warn("requestFreshLink failed",t),e.textContent=L,s.disabled=!1,s.textContent=I}}drawTab(){try{const t=this.deps.doc,e=this.ensureRoot(),s=this.side(),n=J(t,"button",{className:`sf-ui sf-tab sf-tab--${s}`,testId:"sf-live-tab",attrs:{type:"button","data-side":s}}),i=this.grant&&this.grant.project&&this.grant.project.buttonLabel||C;n.appendChild(J(t,"span",{className:"sf-tab-label",text:i,testId:"sf-live-tab-label"})),n.appendChild(J(t,"span",{className:"sf-tab-brand",text:v})),n.addEventListener("click",(()=>this.togglePanel())),e.appendChild(n),this.tab=n}catch(t){this.warn("drawTab failed",t)}}togglePanel(){try{this.panel?this.closePanel():this.openPanel()}catch(t){this.warn("togglePanel failed",t)}}openPanel(){try{const t=this.deps.doc,e=this.ensureRoot(),s=J(t,"div",{className:`sf-ui sf-panel sf-panel--${this.side()}`,testId:"sf-live-panel",attrs:{role:"dialog"}}),n=J(t,"div",{className:"sf-panel-head"});n.appendChild(J(t,"div",{className:"sf-brand",text:v}));const i=J(t,"button",{className:"sf-close",text:"×",testId:"sf-live-close",attrs:{type:"button","aria-label":T}});i.addEventListener("click",(()=>this.closePanel())),n.appendChild(i),s.appendChild(n);const r=J(t,"div",{className:"sf-views"}),o=Z(t,R,"sf-live-view-request","sf-view-btn"),a=Z(t,$,"sf-live-view-list","sf-view-btn sf-view-btn--active");o.addEventListener("click",(()=>this.startPick())),a.addEventListener("click",(()=>{this.showList()})),r.appendChild(o),r.appendChild(a),s.appendChild(r);const l=J(t,"div",{className:"sf-panel-body",testId:"sf-live-list"});s.appendChild(l),e.appendChild(s),this.panel=s,this.listBody=l,this.showList()}catch(t){this.warn("openPanel failed",t)}}closePanel(){try{this.panel&&this.panel.remove(),this.panel=null,this.listBody=null}catch(t){this.warn("closePanel failed",t)}}async showList(){const t=this.listBody;try{if(!t||!this.session)return;Q(t),t.appendChild(J(this.deps.doc,"div",{className:"sf-muted",text:U,testId:"sf-live-loading"}));const e=await this.api.listMyLiveRequests(this.session);if(this.listBody!==t)return;if(Q(t),"ok"===e.kind)return void this.renderList(t,Array.isArray(e.result.requests)?e.result.requests:[]);if("error"===e.kind&&p.includes(e.code))return void this.endSession();t.appendChild(J(this.deps.doc,"div",{className:"sf-status sf-status--error",text:Y,testId:"sf-live-list-error"}))}catch(e){this.warn("showList failed",e),t&&(Q(t),t.appendChild(J(this.deps.doc,"div",{className:"sf-status sf-status--error",text:Y,testId:"sf-live-list-error"})))}}renderList(t,e){try{if(0===e.length)return void t.appendChild(J(this.deps.doc,"div",{className:"sf-muted",text:O,testId:"sf-live-empty"}));e.forEach((e=>t.appendChild(this.renderCard(e))))}catch(t){this.warn("renderList failed",t)}}renderCard(t){const e=this.deps.doc,s=J(e,"div",{className:"sf-card",testId:"sf-live-card",attrs:{"data-state":String(t.state||"received"),"data-annotation-id":String(t.annotationId||"")}});try{const n=J(e,"div",{className:"sf-card-head"});n.appendChild(J(e,"span",{className:`sf-chip sf-chip--${t.state||"received"}`,text:nt(t.state),testId:"sf-live-state"})),n.appendChild(J(e,"span",{className:"sf-date",text:st(t.createdAt),testId:"sf-live-date"})),s.appendChild(n),s.appendChild(J(e,"div",{className:"sf-card-text",text:tt(t.text),testId:"sf-live-card-text"})),s.appendChild(J(e,"div",{className:"sf-card-path",text:et(t.pageUrl),testId:"sf-live-card-path"}));const i=J(e,"div",{className:"sf-replies",testId:"sf-live-replies"});(Array.isArray(t.replies)?t.replies:[]).forEach((t=>i.appendChild(this.renderReply(t)))),s.appendChild(i);const r=J(e,"div",{className:"sf-reply-box"}),o=J(e,"input",{className:"sf-input",testId:"sf-live-reply-input",attrs:{type:"text",maxlength:String(b),placeholder:B}}),a=Z(e,D,"sf-live-reply-send","sf-btn sf-btn--small");r.appendChild(o),r.appendChild(a),s.appendChild(r);const l=J(e,"div",{className:"sf-status",testId:"sf-live-reply-status"});s.appendChild(l),a.addEventListener("click",(()=>{this.reply(t,o,a,i,l)}))}catch(t){this.warn("renderCard failed",t)}return s}renderReply(t){const e=this.deps.doc,s=!(!t||!t.fromClient),n=J(e,"div",{className:"sf-reply"+(s?" sf-reply--you":""),testId:"sf-live-reply",attrs:{"data-from":s?"you":"agency"}});return n.appendChild(J(e,"span",{className:"sf-reply-from",text:s?G:W})),n.appendChild(J(e,"div",{className:"sf-reply-text",text:"string"==typeof(null==t?void 0:t.text)?t.text:""})),n}async reply(t,e,s,n,i){try{const r=(e.value||"").trim().slice(0,b);if(!r||!this.session||s.disabled)return;s.disabled=!0,i.className="sf-status",i.textContent="";const o=await this.api.replyToLiveRequest(this.session,t.annotationId,r);if(s.disabled=!1,"ok"===o.kind){const t=o.result&&o.result.reply?o.result.reply:{commentId:"",text:r,fromClient:!0,createdAt:this.deps.now()};return n.appendChild(this.renderReply({...t,fromClient:!0})),void(e.value="")}i.className="sf-status sf-status--error",i.textContent="error"===o.kind&&"rate-limited"===o.code?E:K}catch(t){this.warn("reply failed",t),s.disabled=!1,i.className="sf-status sf-status--error",i.textContent=K}}startPick(){try{if(this.pick)return;const t=this.deps.doc,e=this.ensureRoot();this.closePanel(),this.removeForm(),this.tab&&this.tab.classList.add("sf-hidden");const s=J(t,"div",{className:"sf-highlight sf-hidden",testId:"sf-live-highlight"}),n=J(t,"div",{className:"sf-ui sf-hint",text:M,testId:"sf-live-hint"});e.appendChild(s),e.appendChild(n);const i={highlight:s,hint:n,onMove:t=>this.onPickMove(t),onClick:t=>this.onPickClick(t),onKey:t=>this.onPickKey(t)};this.pick=i,t.addEventListener("mousemove",i.onMove,!0),t.addEventListener("click",i.onClick,!0),t.addEventListener("keydown",i.onKey,!0)}catch(t){this.warn("startPick failed",t)}}endPick(){try{const t=this.pick;if(!t)return;const e=this.deps.doc;e.removeEventListener("mousemove",t.onMove,!0),e.removeEventListener("click",t.onClick,!0),e.removeEventListener("keydown",t.onKey,!0),t.highlight.remove(),t.hint.remove(),this.pick=null}catch(t){this.warn("endPick failed",t)}}cancelPick(){try{this.endPick(),this.showTab()}catch(t){this.warn("cancelPick failed",t)}}isOurs(t){try{return!!this.host&&t instanceof Node&&(t===this.host||this.host.contains(t))}catch(t){return!1}}hostGone(){try{return!this.host||!this.host.isConnected}catch(t){return!0}}onPickMove(t){try{const e=this.pick;if(!e)return;if(this.hostGone())return void this.endPick();const s=t.target;if(!(s instanceof Element)||this.isOurs(s))return void e.highlight.classList.add("sf-hidden");const n=s.getBoundingClientRect(),i=this.deps.win;e.highlight.style.left=`${n.left+(i.scrollX||0)}px`,e.highlight.style.top=`${n.top+(i.scrollY||0)}px`,e.highlight.style.width=`${n.width}px`,e.highlight.style.height=`${n.height}px`,e.highlight.classList.remove("sf-hidden")}catch(t){this.warn("onPickMove failed",t)}}onPickClick(t){try{if(!this.pick)return;if(this.hostGone())return void this.endPick();const e=t.target;if(!(e instanceof Element)||this.isOurs(e))return;t.preventDefault(),t.stopPropagation(),"function"==typeof t.stopImmediatePropagation&&t.stopImmediatePropagation();const s=this.deps.win,n=function(t,e,s,n,i){try{const r=t.getBoundingClientRect(),o=t.getAttribute("id")||"",a={version:"1.0",tagName:t.tagName.toLowerCase(),elementSelector:c(t,n),leftPercentage:r.width>0?h((e-r.left)/r.width*100):0,topPercentage:r.height>0?h((s-r.top)/r.height*100):0,boundingBox:{x:Math.round(r.left+(i.scrollX||0)),y:Math.round(r.top+(i.scrollY||0)),w:Math.round(r.width),h:Math.round(r.height)}};return o&&(a.id=o),a}catch(t){return console.warn("[superflow live] computeAnchor failed:",t),{version:"1.0",tagName:"body",elementSelector:"body",leftPercentage:0,topPercentage:0,boundingBox:{x:0,y:0,w:0,h:0}}}}(e,t.clientX,t.clientY,this.deps.doc,{scrollX:s.scrollX||0,scrollY:s.scrollY||0});this.endPick(),this.showForm(n,t.clientX,t.clientY)}catch(t){this.warn("onPickClick failed",t),this.cancelPick()}}onPickKey(t){try{"Escape"!==t.key&&"Esc"!==t.key||(t.preventDefault(),this.cancelPick())}catch(t){this.warn("onPickKey failed",t)}}showForm(t,e,s){try{const n=this.deps.doc,i=this.deps.win,r=this.ensureRoot();this.removeForm();const o=J(n,"div",{className:"sf-ui sf-form",testId:"sf-live-form",attrs:{role:"dialog"}}),a=300,l=190,c=Math.max(8,Math.min(e+12,(i.innerWidth||a+16)-a-8)),d=Math.max(8,Math.min(s+12,(i.innerHeight||l+16)-l-8));o.style.left=`${c}px`,o.style.top=`${d}px`,o.appendChild(J(n,"div",{className:"sf-brand",text:v}));const h=J(n,"textarea",{className:"sf-textarea",testId:"sf-live-textarea",attrs:{maxlength:String(b),placeholder:q,style:"margin-top:8px"}});o.appendChild(h);const f=J(n,"div",{className:"sf-row"}),p=Z(n,z,"sf-live-send"),u=Z(n,j,"sf-live-cancel","sf-btn sf-btn--ghost");f.appendChild(p),f.appendChild(u),o.appendChild(f);const x=J(n,"div",{className:"sf-status",testId:"sf-live-status",attrs:{role:"status"}});o.appendChild(x),p.addEventListener("click",(()=>{this.send(t,e,s,o,h,p,x)})),u.addEventListener("click",(()=>{this.removeForm(),this.showTab()})),r.appendChild(o),this.form=o;try{h.focus()}catch(t){}}catch(t){this.warn("showForm failed",t),this.showTab()}}removeForm(){try{this.form&&this.form.remove(),this.form=null}catch(t){this.warn("removeForm failed",t)}}async send(t,e,s,n,i,r,o){var a;try{const l=(i.value||"").trim().slice(0,b);if(!l)return void i.focus();if(!this.session||r.disabled)return;r.disabled=!0,r.textContent=F,o.className="sf-status",o.textContent="";const c=this.deps.win,d=await this.api.createLiveRequest({session:this.session,pageUrl:V((null===(a=c.location)||void 0===a?void 0:a.href)||""),text:l,anchor:t,viewport:{w:c.innerWidth||0,h:c.innerHeight||0}});if("ok"===d.kind)return this.placeMarker(e,s),Q(n),n.appendChild(J(this.deps.doc,"div",{className:"sf-brand",text:v})),n.appendChild(J(this.deps.doc,"div",{text:A,testId:"sf-live-sent",attrs:{role:"status",style:"margin-top:6px"}})),this.showTab(),void setTimeout((()=>{this.form===n&&this.removeForm()}),4e3);r.disabled=!1,r.textContent=z,o.className="sf-status sf-status--error",o.textContent="error"===d.kind&&"rate-limited"===d.code?E:K}catch(t){this.warn("send failed",t),r.disabled=!1,r.textContent=z,o.className="sf-status sf-status--error",o.textContent=K}}placeMarker(t,e){try{const s=this.ensureRoot(),n=this.deps.win,i=J(this.deps.doc,"div",{className:"sf-marker",testId:"sf-live-marker"});i.style.left=`${t+(n.scrollX||0)}px`,i.style.top=`${e+(n.scrollY||0)}px`,s.appendChild(i)}catch(t){this.warn("placeMarker failed",t)}}ensureRoot(){if(this.root)return this.root;const t=this.deps.doc,e=J(t,g,{attrs:{"data-sf-live":this.deps.version}});e.style.cssText="position:absolute;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483577;";const s=e.attachShadow({mode:"open"}),n=t.createElement("style");return this.deps.nonce&&(n.nonce=this.deps.nonce),n.textContent='\n:host { all: initial; }\n* { box-sizing: border-box; }\n.sf-ui {\n font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;\n font-size: 14px;\n line-height: 1.4;\n color: #16202a;\n -webkit-font-smoothing: antialiased;\n}\n.sf-card-box {\n position: fixed;\n right: 16px;\n bottom: 16px;\n width: 300px;\n max-width: calc(100vw - 32px);\n background: #fff;\n border: 1px solid #e3e8ee;\n border-radius: 10px;\n box-shadow: 0 8px 24px rgba(22, 32, 42, 0.16);\n padding: 14px 16px;\n}\n.sf-brand {\n font-size: 11px;\n font-weight: 600;\n letter-spacing: 0.04em;\n text-transform: uppercase;\n color: #5b6b7a;\n}\n.sf-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }\n.sf-btn {\n font: inherit;\n font-weight: 600;\n border: 1px solid #16202a;\n border-radius: 8px;\n background: #16202a;\n color: #fff;\n padding: 7px 12px;\n cursor: pointer;\n}\n.sf-btn:disabled { opacity: 0.6; cursor: default; }\n.sf-btn--ghost { background: #fff; color: #16202a; }\n.sf-btn--small { padding: 4px 8px; font-size: 12px; }\n.sf-link {\n font: inherit;\n background: none;\n border: 0;\n padding: 0;\n color: #5b6b7a;\n cursor: pointer;\n text-decoration: underline;\n}\n.sf-tab {\n position: fixed;\n top: 50%;\n transform: translateY(-50%);\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n gap: 2px;\n font: inherit;\n border: 1px solid #16202a;\n background: #16202a;\n color: #fff;\n padding: 10px 14px;\n cursor: pointer;\n box-shadow: 0 6px 18px rgba(22, 32, 42, 0.2);\n}\n.sf-tab--right { right: 0; border-right: 0; border-radius: 10px 0 0 10px; }\n.sf-tab--left { left: 0; border-left: 0; border-radius: 0 10px 10px 0; align-items: flex-end; }\n.sf-tab-label { font-weight: 600; }\n.sf-tab-brand { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.7; }\n.sf-hidden { display: none !important; }\n.sf-panel {\n position: fixed;\n top: 50%;\n transform: translateY(-50%);\n width: 340px;\n max-width: calc(100vw - 32px);\n max-height: 72vh;\n display: flex;\n flex-direction: column;\n background: #fff;\n border: 1px solid #e3e8ee;\n border-radius: 12px;\n box-shadow: 0 12px 32px rgba(22, 32, 42, 0.2);\n overflow: hidden;\n}\n.sf-panel--right { right: 16px; }\n.sf-panel--left { left: 16px; }\n.sf-panel-head {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 10px 10px 10px 14px;\n border-bottom: 1px solid #e3e8ee;\n}\n.sf-panel-head .sf-brand { flex: 1; }\n.sf-close {\n font: inherit;\n font-size: 18px;\n line-height: 1;\n border: 0;\n background: none;\n cursor: pointer;\n color: #5b6b7a;\n padding: 4px 6px;\n}\n.sf-views { display: flex; gap: 6px; padding: 10px 14px 0; }\n.sf-view-btn {\n font: inherit;\n font-weight: 600;\n border: 1px solid #e3e8ee;\n border-radius: 999px;\n background: #fff;\n color: #16202a;\n padding: 5px 10px;\n cursor: pointer;\n}\n.sf-view-btn--active { background: #16202a; border-color: #16202a; color: #fff; }\n.sf-panel-body { padding: 12px 14px 14px; overflow: auto; }\n.sf-muted { color: #5b6b7a; }\n.sf-hint {\n position: fixed;\n top: 12px;\n left: 50%;\n transform: translateX(-50%);\n background: #16202a;\n color: #fff;\n padding: 8px 14px;\n border-radius: 999px;\n box-shadow: 0 6px 18px rgba(22, 32, 42, 0.25);\n white-space: nowrap;\n}\n.sf-highlight {\n position: absolute;\n pointer-events: none;\n border: 2px solid #1f6feb;\n background: rgba(31, 111, 235, 0.08);\n border-radius: 3px;\n}\n.sf-marker {\n position: absolute;\n width: 14px;\n height: 14px;\n margin: -7px 0 0 -7px;\n border-radius: 50%;\n background: #1f6feb;\n border: 2px solid #fff;\n box-shadow: 0 2px 6px rgba(22, 32, 42, 0.3);\n pointer-events: none;\n}\n.sf-form {\n position: fixed;\n width: 300px;\n max-width: calc(100vw - 16px);\n background: #fff;\n border: 1px solid #e3e8ee;\n border-radius: 10px;\n box-shadow: 0 8px 24px rgba(22, 32, 42, 0.18);\n padding: 12px;\n}\n.sf-textarea, .sf-input {\n font: inherit;\n width: 100%;\n border: 1px solid #c9d2dc;\n border-radius: 8px;\n padding: 8px;\n resize: vertical;\n color: #16202a;\n background: #fff;\n}\n.sf-textarea { min-height: 84px; }\n.sf-status { margin-top: 8px; min-height: 1.2em; }\n.sf-status--error { color: #b42318; }\n.sf-card {\n border: 1px solid #e3e8ee;\n border-radius: 10px;\n padding: 10px 12px;\n margin-bottom: 10px;\n}\n.sf-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }\n.sf-chip {\n font-size: 11px;\n font-weight: 600;\n border-radius: 999px;\n padding: 2px 8px;\n background: #eef2f6;\n color: #16202a;\n}\n.sf-chip--working { background: #fff4d6; color: #7a4b00; }\n.sf-chip--done { background: #dcf5e6; color: #0f5132; }\n.sf-date { font-size: 12px; color: #5b6b7a; }\n.sf-card-text { white-space: pre-wrap; word-break: break-word; }\n.sf-card-path { font-size: 12px; color: #5b6b7a; margin-top: 4px; word-break: break-all; }\n.sf-replies { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }\n.sf-reply {\n max-width: 88%;\n border-radius: 8px;\n padding: 6px 8px;\n background: #eef2f6;\n align-self: flex-start;\n}\n.sf-reply--you { background: #e4eefc; align-self: flex-end; text-align: right; }\n.sf-reply-from { display: block; font-size: 11px; font-weight: 600; color: #5b6b7a; margin-bottom: 2px; }\n.sf-reply-text { white-space: pre-wrap; word-break: break-word; }\n.sf-reply-box { display: flex; gap: 6px; margin-top: 8px; }\n',s.appendChild(n),(t.documentElement||t.body).appendChild(e),this.host=e,this.root=s,s}showTab(){try{this.tab&&this.tab.classList.remove("sf-hidden")}catch(t){this.warn("showTab failed",t)}}side(){try{return this.grant&&this.grant.project&&"left"===this.grant.project.buttonPosition?"left":"right"}catch(t){return"right"}}origin(){var t;try{return(null===(t=this.deps.win.location)||void 0===t?void 0:t.origin)||""}catch(t){return""}}storeSession(t){try{this.deps.storage&&this.deps.storage.setItem(n,t)}catch(t){this.warn("could not store the live session",t)}}clearStoredToolbarFlags(){try{if(!this.deps.storage)return;for(const t of s)this.deps.storage.removeItem(t)}catch(t){this.warn("could not clear the stored review flags",t)}}clearSession(){try{this.deps.storage&&this.deps.storage.removeItem(n)}catch(t){this.warn("could not clear the live session",t)}}endSession(){try{this.clearSession(),this.session=null,this.endPick(),this.removeForm(),this.closePanel(),this.host&&this.host.remove(),this.host=null,this.root=null,this.tab=null}catch(t){this.warn("endSession failed",t)}}teardownIfEmpty(){try{this.host&&this.root&&this.root.children.length<=1&&(this.host.remove(),this.host=null,this.root=null)}catch(t){this.warn("teardownIfEmpty failed",t)}}stripTokenFromLocation(){var t;try{const e=this.deps.win,s=(null===(t=e.location)||void 0===t?void 0:t.href)||"",n=V(s);n!==s&&e.history&&"function"==typeof e.history.replaceState&&e.history.replaceState(e.history.state,"",n)}catch(t){this.warn("could not strip the token from the URL",t)}}warn(t,e){try{if(this.warned.has(t))return;this.warned.add(t),void 0===e?console.warn(`[superflow live] ${t}`):console.warn(`[superflow live] ${t}:`,e)}catch(t){}}}function ot(t){const s=t;try{return s.SuperflowLive||(s.SuperflowLive={version:e,ready:!1}),s.SuperflowLive}catch(t){return console.warn("[superflow live] registerLiveBundle failed:",t),{version:e,ready:!1}}}function at(t){try{const e=t.getElementById("superflowToolbarScript");if(!e||!e.src)return{apiKey:null,projectId:null};const s=new URL(e.src).searchParams;return{apiKey:s.get("apiKey"),projectId:s.get("projectId")}}catch(t){return{apiKey:null,projectId:null}}}function lt(t){try{const e=t.currentScript;return e&&(e.nonce||e.getAttribute("nonce"))||null}catch(t){return null}}const ct=ot(window),dt=at(document);(function(t){try{return new rt(t).start()}catch(t){return console.warn("[superflow live] runLive failed, drawing nothing:",t),Promise.resolve("none")}})({win:window,doc:document,storage:function(t){try{return t.localStorage||null}catch(t){return null}}(window),fetchFn:(t,e)=>window.fetch(t,e),now:()=>Date.now(),endpoint:"https://us-central1-snipply-sdk-staging.cloudfunctions.net/anonymoushandler",staging:!0,nonce:lt(document),version:e,apiKey:dt.apiKey,projectId:dt.projectId,userAgent:"undefined"!=typeof navigator?navigator.userAgent:""}).then((()=>{ct.ready=!0})).catch((t=>{console.warn("[superflow live] runLive failed:",t),ct.ready=!0})),t.currentScriptNonce=lt,t.readInstallParams=at,t.registerLiveBundle=ot}({});
|
|
1
|
+
!function(t){const e="1.0.769",s=["review","feedback"],n="_sfls",i="sf_review",r=2e3;function o(t){try{return"undefined"!=typeof CSS&&"function"==typeof CSS.escape?CSS.escape(t):t.replace(/([^a-zA-Z0-9_-])/g,"\\$1")}catch(e){return t}}function a(t,e){try{return!!e&&1===t.querySelectorAll(`#${o(e)}`).length}catch(t){return!1}}function l(t){try{let e=1,s=t.previousElementSibling;for(;s;)s.tagName===t.tagName&&(e+=1),s=s.previousElementSibling;return e}catch(t){return 1}}function c(t,e){try{const s=t.getAttribute("id")||"";if(a(e,s))return d([`#${o(s)}`]);const n=[];let i=t;for(;i;){const s=i.tagName.toLowerCase();if("body"===s||"html"===s){n.unshift("html"===s?"html":"body");break}const r=i.getAttribute("id")||"";if(i!==t&&a(e,r)){n.unshift(`#${o(r)}`);break}n.unshift(`${s}:nth-of-type(${l(i)})`),i=i.parentElement}return d(n)}catch(e){return console.warn("[superflow live] buildSelector failed:",e),t&&t.tagName?t.tagName.toLowerCase():"body"}}function d(t){try{const e=t.slice();let s=e.join(" > ");for(;s.length>r&&e.length>1;)e.shift(),s=e.join(" > ");return s.length>r?s.slice(0,r):s}catch(e){return t.join(" > ")}}function h(t){return Number.isFinite(t)?Math.round(100*Math.min(100,Math.max(0,t)))/100:0}const f=["invalid","expired","revoked","exhausted","origin-mismatch","disabled","not-found","rate-limited","internal"],p=["invalid","expired","revoked","exhausted"];async function u(t,e,s){try{const n=await t.fetchFn(t.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({data:{subEventType:e,...s}})});if(!n||!n.ok)return{kind:"transport"};let i;try{i=await n.json()}catch(t){return{kind:"transport"}}const r=i&&"object"==typeof i?i.result:void 0;if(null==r||"object"!=typeof r)return{kind:"transport"};const o=r.error;return o&&"object"==typeof o?{kind:"error",code:x(o.code)}:{kind:"ok",result:r}}catch(t){return{kind:"transport"}}}function x(t){try{return"string"==typeof t&&f.includes(t)?t:"internal"}catch(t){return"internal"}}const g="superflow-live",b=5e3,v="Superflow",y="Continue to request changes on this site",m="Continue",w="Continuing...",k="Not now",N="This link has expired.",I="Send me a fresh one",S="Sending...",P="Check your email.",L="Could not send. Try again.",C="Request a change",R="Request a change",$="My requests",T="Close",M="Click the part of the page you want changed. Press Esc to cancel.",q="What should change here?",z="Send",F="Sending...",j="Cancel",A="Sent. We'll reply here.",E="Too many requests right now. Try again in a minute.",K="Could not send. Try again.",U="Loading...",O="No requests yet.",Y="Could not load requests.",B="Reply",D="Reply",G="You",W="Agency",_="Received",X="We're on it",H="Done";function J(t,e,s={}){const n=t.createElement(e);return s.className&&(n.className=s.className),void 0!==s.text&&(n.textContent=s.text),s.testId&&n.setAttribute("data-testid",s.testId),s.attrs&&Object.keys(s.attrs).forEach((t=>n.setAttribute(t,s.attrs[t]))),n}function Z(t,e,s,n="sf-btn"){return J(t,"button",{className:n,text:e,testId:s,attrs:{type:"button"}})}function Q(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function V(t){try{const e=new URL(t);return e.searchParams.delete(i),e.toString()}catch(e){return t}}function tt(t){const e="string"==typeof t?t:"";return e.length>200?`${e.slice(0,200)}…`:e}function et(t){if("string"!=typeof t||!t)return"";try{return new URL(t).pathname}catch(e){return t}}function st(t){try{if(null==t||""===t)return"";const e=new Date(t);return Number.isNaN(e.getTime())?"":e.toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch(t){return""}}function nt(t){switch(t){case"working":return X;case"done":return H;default:return _}}function it(t,e){try{return t?t.getItem(e):null}catch(t){return null}}class rt{constructor(t){this.host=null,this.root=null,this.session=null,this.grant=null,this.tab=null,this.panel=null,this.listBody=null,this.pick=null,this.form=null,this.warned=new Set,this.deps=t,this.api=function(t){const e=t.origin;return{redeemLiveReviewToken:s=>u(t,"redeemLiveReviewToken",{token:s,origin:e,userAgent:t.userAgent}),validateLiveSession:s=>u(t,"validateLiveSession",{session:s,origin:e}),createLiveRequest:s=>u(t,"createLiveRequest",{session:s.session,origin:e,pageUrl:s.pageUrl,text:s.text,...s.anchor?{anchor:s.anchor}:{},viewport:s.viewport,userAgent:t.userAgent,...s.versionId?{versionId:s.versionId}:{}}),listMyLiveRequests:s=>u(t,"listMyLiveRequests",{session:s,origin:e}),replyToLiveRequest:(s,n,i)=>u(t,"replyToLiveRequest",{session:s,origin:e,annotationId:n,text:i}),requestFreshLink:s=>u(t,"requestFreshLink",{token:s,origin:e})}}({fetchFn:t.fetchFn,endpoint:t.endpoint,origin:this.origin(),userAgent:t.userAgent})}async start(){var t;try{const{doc:e,win:s,storage:r}=this.deps;if(e.querySelector(g))return"skipped";const o=new URLSearchParams((null===(t=s.location)||void 0===t?void 0:t.search)||"").get(i),a=it(r,n);return o?(this.showPrompt(o),"prompt"):a?this.validate(a):"none"}catch(t){return this.warn("start failed, drawing nothing",t),"none"}}async validate(t){try{const e=await this.api.validateLiveSession(t);return"transport"===e.kind?"kept":"error"===e.kind?(this.clearSession(),"cleared"):this.acceptGrant(t,e.result)}catch(t){return this.warn("validate failed, drawing nothing",t),"kept"}}acceptGrant(t,e){try{return e&&e.project&&!1!==e.project.enabled?(this.session=t,this.grant=e,this.drawTab(),"tab"):"disabled"}catch(t){return this.warn("acceptGrant failed",t),"disabled"}}showPrompt(t){try{const e=this.deps.doc,s=this.ensureRoot(),n=J(e,"div",{className:"sf-ui sf-card-box",testId:"sf-live-prompt",attrs:{role:"dialog"}});n.appendChild(J(e,"div",{className:"sf-brand",text:v})),n.appendChild(J(e,"div",{text:y,attrs:{style:"margin-top:6px"}}));const i=J(e,"div",{className:"sf-row"}),r=Z(e,m,"sf-live-continue"),o=Z(e,k,"sf-live-not-now","sf-btn sf-btn--ghost");i.appendChild(r),i.appendChild(o),n.appendChild(i),r.addEventListener("click",(()=>{this.redeem(t,n,r)})),o.addEventListener("click",(()=>{this.dismissPrompt(n)})),s.appendChild(n)}catch(t){this.warn("showPrompt failed",t)}}async dismissPrompt(t){try{t.remove();const e=it(this.deps.storage,n);e?await this.validate(e):this.teardownIfEmpty()}catch(t){this.warn("dismissPrompt failed",t)}}async redeem(t,e,s){try{if(s.disabled)return;s.disabled=!0,s.textContent=w;const n=await this.api.redeemLiveReviewToken(t);if("ok"===n.kind)return this.storeSession(n.result.session),this.clearStoredToolbarFlags(),this.stripTokenFromLocation(),e.remove(),void this.acceptGrant(n.result.session,n.result);if("error"===n.kind&&p.includes(n.code))return void this.showExpired(t,e);e.remove(),this.teardownIfEmpty(),this.warn(`redeem refused (${"error"===n.kind?n.code:"transport"})`)}catch(t){this.warn("redeem failed",t),e.remove(),this.teardownIfEmpty()}}showExpired(t,e){try{const s=this.deps.doc;Q(e),e.setAttribute("data-testid","sf-live-expired"),e.appendChild(J(s,"div",{className:"sf-brand",text:v}));const n=J(s,"div",{text:N,testId:"sf-live-expired-line",attrs:{style:"margin-top:6px"}});e.appendChild(n);const i=J(s,"div",{className:"sf-row"}),r=Z(s,I,"sf-live-fresh-link");i.appendChild(r),e.appendChild(i),r.addEventListener("click",(()=>{this.requestFreshLink(t,n,r)}))}catch(t){this.warn("showExpired failed",t)}}async requestFreshLink(t,e,s){try{if(s.disabled)return;s.disabled=!0,s.textContent=S;const n=await this.api.requestFreshLink(t);if("ok"===n.kind&&n.result&&n.result.sent)return e.textContent=P,void s.remove();e.textContent=L,s.disabled=!1,s.textContent=I}catch(t){this.warn("requestFreshLink failed",t),e.textContent=L,s.disabled=!1,s.textContent=I}}drawTab(){try{const t=this.deps.doc,e=this.ensureRoot(),s=this.side(),n=J(t,"button",{className:`sf-ui sf-tab sf-tab--${s}`,testId:"sf-live-tab",attrs:{type:"button","data-side":s}}),i=this.grant&&this.grant.project&&this.grant.project.buttonLabel||C;n.appendChild(J(t,"span",{className:"sf-tab-label",text:i,testId:"sf-live-tab-label"})),n.appendChild(J(t,"span",{className:"sf-tab-brand",text:v})),n.addEventListener("click",(()=>this.togglePanel())),e.appendChild(n),this.tab=n}catch(t){this.warn("drawTab failed",t)}}togglePanel(){try{this.panel?this.closePanel():this.openPanel()}catch(t){this.warn("togglePanel failed",t)}}openPanel(){try{const t=this.deps.doc,e=this.ensureRoot(),s=J(t,"div",{className:`sf-ui sf-panel sf-panel--${this.side()}`,testId:"sf-live-panel",attrs:{role:"dialog"}}),n=J(t,"div",{className:"sf-panel-head"});n.appendChild(J(t,"div",{className:"sf-brand",text:v}));const i=J(t,"button",{className:"sf-close",text:"×",testId:"sf-live-close",attrs:{type:"button","aria-label":T}});i.addEventListener("click",(()=>this.closePanel())),n.appendChild(i),s.appendChild(n);const r=J(t,"div",{className:"sf-views"}),o=Z(t,R,"sf-live-view-request","sf-view-btn"),a=Z(t,$,"sf-live-view-list","sf-view-btn sf-view-btn--active");o.addEventListener("click",(()=>this.startPick())),a.addEventListener("click",(()=>{this.showList()})),r.appendChild(o),r.appendChild(a),s.appendChild(r);const l=J(t,"div",{className:"sf-panel-body",testId:"sf-live-list"});s.appendChild(l),e.appendChild(s),this.panel=s,this.listBody=l,this.showList()}catch(t){this.warn("openPanel failed",t)}}closePanel(){try{this.panel&&this.panel.remove(),this.panel=null,this.listBody=null}catch(t){this.warn("closePanel failed",t)}}async showList(){const t=this.listBody;try{if(!t||!this.session)return;Q(t),t.appendChild(J(this.deps.doc,"div",{className:"sf-muted",text:U,testId:"sf-live-loading"}));const e=await this.api.listMyLiveRequests(this.session);if(this.listBody!==t)return;if(Q(t),"ok"===e.kind)return void this.renderList(t,Array.isArray(e.result.requests)?e.result.requests:[]);if("error"===e.kind&&p.includes(e.code))return void this.endSession();t.appendChild(J(this.deps.doc,"div",{className:"sf-status sf-status--error",text:Y,testId:"sf-live-list-error"}))}catch(e){this.warn("showList failed",e),t&&(Q(t),t.appendChild(J(this.deps.doc,"div",{className:"sf-status sf-status--error",text:Y,testId:"sf-live-list-error"})))}}renderList(t,e){try{if(0===e.length)return void t.appendChild(J(this.deps.doc,"div",{className:"sf-muted",text:O,testId:"sf-live-empty"}));e.forEach((e=>t.appendChild(this.renderCard(e))))}catch(t){this.warn("renderList failed",t)}}renderCard(t){const e=this.deps.doc,s=J(e,"div",{className:"sf-card",testId:"sf-live-card",attrs:{"data-state":String(t.state||"received"),"data-annotation-id":String(t.annotationId||"")}});try{const n=J(e,"div",{className:"sf-card-head"});n.appendChild(J(e,"span",{className:`sf-chip sf-chip--${t.state||"received"}`,text:nt(t.state),testId:"sf-live-state"})),n.appendChild(J(e,"span",{className:"sf-date",text:st(t.createdAt),testId:"sf-live-date"})),s.appendChild(n),s.appendChild(J(e,"div",{className:"sf-card-text",text:tt(t.text),testId:"sf-live-card-text"})),s.appendChild(J(e,"div",{className:"sf-card-path",text:et(t.pageUrl),testId:"sf-live-card-path"}));const i=J(e,"div",{className:"sf-replies",testId:"sf-live-replies"});(Array.isArray(t.replies)?t.replies:[]).forEach((t=>i.appendChild(this.renderReply(t)))),s.appendChild(i);const r=J(e,"div",{className:"sf-reply-box"}),o=J(e,"input",{className:"sf-input",testId:"sf-live-reply-input",attrs:{type:"text",maxlength:String(b),placeholder:B}}),a=Z(e,D,"sf-live-reply-send","sf-btn sf-btn--small");r.appendChild(o),r.appendChild(a),s.appendChild(r);const l=J(e,"div",{className:"sf-status",testId:"sf-live-reply-status"});s.appendChild(l),a.addEventListener("click",(()=>{this.reply(t,o,a,i,l)}))}catch(t){this.warn("renderCard failed",t)}return s}renderReply(t){const e=this.deps.doc,s=!(!t||!t.fromClient),n=J(e,"div",{className:"sf-reply"+(s?" sf-reply--you":""),testId:"sf-live-reply",attrs:{"data-from":s?"you":"agency"}});return n.appendChild(J(e,"span",{className:"sf-reply-from",text:s?G:W})),n.appendChild(J(e,"div",{className:"sf-reply-text",text:"string"==typeof(null==t?void 0:t.text)?t.text:""})),n}async reply(t,e,s,n,i){try{const r=(e.value||"").trim().slice(0,b);if(!r||!this.session||s.disabled)return;s.disabled=!0,i.className="sf-status",i.textContent="";const o=await this.api.replyToLiveRequest(this.session,t.annotationId,r);if(s.disabled=!1,"ok"===o.kind){const t=o.result&&o.result.reply?o.result.reply:{commentId:"",text:r,fromClient:!0,createdAt:this.deps.now()};return n.appendChild(this.renderReply({...t,fromClient:!0})),void(e.value="")}i.className="sf-status sf-status--error",i.textContent="error"===o.kind&&"rate-limited"===o.code?E:K}catch(t){this.warn("reply failed",t),s.disabled=!1,i.className="sf-status sf-status--error",i.textContent=K}}startPick(){try{if(this.pick)return;const t=this.deps.doc,e=this.ensureRoot();this.closePanel(),this.removeForm(),this.tab&&this.tab.classList.add("sf-hidden");const s=J(t,"div",{className:"sf-highlight sf-hidden",testId:"sf-live-highlight"}),n=J(t,"div",{className:"sf-ui sf-hint",text:M,testId:"sf-live-hint"});e.appendChild(s),e.appendChild(n);const i={highlight:s,hint:n,onMove:t=>this.onPickMove(t),onClick:t=>this.onPickClick(t),onKey:t=>this.onPickKey(t)};this.pick=i,t.addEventListener("mousemove",i.onMove,!0),t.addEventListener("click",i.onClick,!0),t.addEventListener("keydown",i.onKey,!0)}catch(t){this.warn("startPick failed",t)}}endPick(){try{const t=this.pick;if(!t)return;const e=this.deps.doc;e.removeEventListener("mousemove",t.onMove,!0),e.removeEventListener("click",t.onClick,!0),e.removeEventListener("keydown",t.onKey,!0),t.highlight.remove(),t.hint.remove(),this.pick=null}catch(t){this.warn("endPick failed",t)}}cancelPick(){try{this.endPick(),this.showTab()}catch(t){this.warn("cancelPick failed",t)}}isOurs(t){try{return!!this.host&&t instanceof Node&&(t===this.host||this.host.contains(t))}catch(t){return!1}}hostGone(){try{return!this.host||!this.host.isConnected}catch(t){return!0}}onPickMove(t){try{const e=this.pick;if(!e)return;if(this.hostGone())return void this.endPick();const s=t.target;if(!(s instanceof Element)||this.isOurs(s))return void e.highlight.classList.add("sf-hidden");const n=s.getBoundingClientRect(),i=this.deps.win;e.highlight.style.left=`${n.left+(i.scrollX||0)}px`,e.highlight.style.top=`${n.top+(i.scrollY||0)}px`,e.highlight.style.width=`${n.width}px`,e.highlight.style.height=`${n.height}px`,e.highlight.classList.remove("sf-hidden")}catch(t){this.warn("onPickMove failed",t)}}onPickClick(t){try{if(!this.pick)return;if(this.hostGone())return void this.endPick();const e=t.target;if(!(e instanceof Element)||this.isOurs(e))return;t.preventDefault(),t.stopPropagation(),"function"==typeof t.stopImmediatePropagation&&t.stopImmediatePropagation();const s=this.deps.win,n=function(t,e,s,n,i){try{const r=t.getBoundingClientRect(),o=t.getAttribute("id")||"",a={version:"1.0",tagName:t.tagName.toLowerCase(),elementSelector:c(t,n),leftPercentage:r.width>0?h((e-r.left)/r.width*100):0,topPercentage:r.height>0?h((s-r.top)/r.height*100):0,boundingBox:{x:Math.round(r.left+(i.scrollX||0)),y:Math.round(r.top+(i.scrollY||0)),w:Math.round(r.width),h:Math.round(r.height)}};return o&&(a.id=o),a}catch(t){return console.warn("[superflow live] computeAnchor failed:",t),{version:"1.0",tagName:"body",elementSelector:"body",leftPercentage:0,topPercentage:0,boundingBox:{x:0,y:0,w:0,h:0}}}}(e,t.clientX,t.clientY,this.deps.doc,{scrollX:s.scrollX||0,scrollY:s.scrollY||0});this.endPick(),this.showForm(n,t.clientX,t.clientY)}catch(t){this.warn("onPickClick failed",t),this.cancelPick()}}onPickKey(t){try{"Escape"!==t.key&&"Esc"!==t.key||(t.preventDefault(),this.cancelPick())}catch(t){this.warn("onPickKey failed",t)}}showForm(t,e,s){try{const n=this.deps.doc,i=this.deps.win,r=this.ensureRoot();this.removeForm();const o=J(n,"div",{className:"sf-ui sf-form",testId:"sf-live-form",attrs:{role:"dialog"}}),a=300,l=190,c=Math.max(8,Math.min(e+12,(i.innerWidth||a+16)-a-8)),d=Math.max(8,Math.min(s+12,(i.innerHeight||l+16)-l-8));o.style.left=`${c}px`,o.style.top=`${d}px`,o.appendChild(J(n,"div",{className:"sf-brand",text:v}));const h=J(n,"textarea",{className:"sf-textarea",testId:"sf-live-textarea",attrs:{maxlength:String(b),placeholder:q,style:"margin-top:8px"}});o.appendChild(h);const f=J(n,"div",{className:"sf-row"}),p=Z(n,z,"sf-live-send"),u=Z(n,j,"sf-live-cancel","sf-btn sf-btn--ghost");f.appendChild(p),f.appendChild(u),o.appendChild(f);const x=J(n,"div",{className:"sf-status",testId:"sf-live-status",attrs:{role:"status"}});o.appendChild(x),p.addEventListener("click",(()=>{this.send(t,e,s,o,h,p,x)})),u.addEventListener("click",(()=>{this.removeForm(),this.showTab()})),r.appendChild(o),this.form=o;try{h.focus()}catch(t){}}catch(t){this.warn("showForm failed",t),this.showTab()}}removeForm(){try{this.form&&this.form.remove(),this.form=null}catch(t){this.warn("removeForm failed",t)}}async send(t,e,s,n,i,r,o){var a;try{const l=(i.value||"").trim().slice(0,b);if(!l)return void i.focus();if(!this.session||r.disabled)return;r.disabled=!0,r.textContent=F,o.className="sf-status",o.textContent="";const c=this.deps.win,d=await this.api.createLiveRequest({session:this.session,pageUrl:V((null===(a=c.location)||void 0===a?void 0:a.href)||""),text:l,anchor:t,viewport:{w:c.innerWidth||0,h:c.innerHeight||0}});if("ok"===d.kind)return this.placeMarker(e,s),Q(n),n.appendChild(J(this.deps.doc,"div",{className:"sf-brand",text:v})),n.appendChild(J(this.deps.doc,"div",{text:A,testId:"sf-live-sent",attrs:{role:"status",style:"margin-top:6px"}})),this.showTab(),void setTimeout((()=>{this.form===n&&this.removeForm()}),4e3);r.disabled=!1,r.textContent=z,o.className="sf-status sf-status--error",o.textContent="error"===d.kind&&"rate-limited"===d.code?E:K}catch(t){this.warn("send failed",t),r.disabled=!1,r.textContent=z,o.className="sf-status sf-status--error",o.textContent=K}}placeMarker(t,e){try{const s=this.ensureRoot(),n=this.deps.win,i=J(this.deps.doc,"div",{className:"sf-marker",testId:"sf-live-marker"});i.style.left=`${t+(n.scrollX||0)}px`,i.style.top=`${e+(n.scrollY||0)}px`,s.appendChild(i)}catch(t){this.warn("placeMarker failed",t)}}ensureRoot(){if(this.root)return this.root;const t=this.deps.doc,e=J(t,g,{attrs:{"data-sf-live":this.deps.version}});e.style.cssText="position:absolute;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483577;";const s=e.attachShadow({mode:"open"}),n=t.createElement("style");return this.deps.nonce&&(n.nonce=this.deps.nonce),n.textContent='\n:host { all: initial; }\n* { box-sizing: border-box; }\n.sf-ui {\n font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;\n font-size: 14px;\n line-height: 1.4;\n color: #16202a;\n -webkit-font-smoothing: antialiased;\n}\n.sf-card-box {\n position: fixed;\n right: 16px;\n bottom: 16px;\n width: 300px;\n max-width: calc(100vw - 32px);\n background: #fff;\n border: 1px solid #e3e8ee;\n border-radius: 10px;\n box-shadow: 0 8px 24px rgba(22, 32, 42, 0.16);\n padding: 14px 16px;\n}\n.sf-brand {\n font-size: 11px;\n font-weight: 600;\n letter-spacing: 0.04em;\n text-transform: uppercase;\n color: #5b6b7a;\n}\n.sf-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }\n.sf-btn {\n font: inherit;\n font-weight: 600;\n border: 1px solid #16202a;\n border-radius: 8px;\n background: #16202a;\n color: #fff;\n padding: 7px 12px;\n cursor: pointer;\n}\n.sf-btn:disabled { opacity: 0.6; cursor: default; }\n.sf-btn--ghost { background: #fff; color: #16202a; }\n.sf-btn--small { padding: 4px 8px; font-size: 12px; }\n.sf-link {\n font: inherit;\n background: none;\n border: 0;\n padding: 0;\n color: #5b6b7a;\n cursor: pointer;\n text-decoration: underline;\n}\n.sf-tab {\n position: fixed;\n top: 50%;\n transform: translateY(-50%);\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n gap: 2px;\n font: inherit;\n border: 1px solid #16202a;\n background: #16202a;\n color: #fff;\n padding: 10px 14px;\n cursor: pointer;\n box-shadow: 0 6px 18px rgba(22, 32, 42, 0.2);\n}\n.sf-tab--right { right: 0; border-right: 0; border-radius: 10px 0 0 10px; }\n.sf-tab--left { left: 0; border-left: 0; border-radius: 0 10px 10px 0; align-items: flex-end; }\n.sf-tab-label { font-weight: 600; }\n.sf-tab-brand { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.7; }\n.sf-hidden { display: none !important; }\n.sf-panel {\n position: fixed;\n top: 50%;\n transform: translateY(-50%);\n width: 340px;\n max-width: calc(100vw - 32px);\n max-height: 72vh;\n display: flex;\n flex-direction: column;\n background: #fff;\n border: 1px solid #e3e8ee;\n border-radius: 12px;\n box-shadow: 0 12px 32px rgba(22, 32, 42, 0.2);\n overflow: hidden;\n}\n.sf-panel--right { right: 16px; }\n.sf-panel--left { left: 16px; }\n.sf-panel-head {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 10px 10px 10px 14px;\n border-bottom: 1px solid #e3e8ee;\n}\n.sf-panel-head .sf-brand { flex: 1; }\n.sf-close {\n font: inherit;\n font-size: 18px;\n line-height: 1;\n border: 0;\n background: none;\n cursor: pointer;\n color: #5b6b7a;\n padding: 4px 6px;\n}\n.sf-views { display: flex; gap: 6px; padding: 10px 14px 0; }\n.sf-view-btn {\n font: inherit;\n font-weight: 600;\n border: 1px solid #e3e8ee;\n border-radius: 999px;\n background: #fff;\n color: #16202a;\n padding: 5px 10px;\n cursor: pointer;\n}\n.sf-view-btn--active { background: #16202a; border-color: #16202a; color: #fff; }\n.sf-panel-body { padding: 12px 14px 14px; overflow: auto; }\n.sf-muted { color: #5b6b7a; }\n.sf-hint {\n position: fixed;\n top: 12px;\n left: 50%;\n transform: translateX(-50%);\n background: #16202a;\n color: #fff;\n padding: 8px 14px;\n border-radius: 999px;\n box-shadow: 0 6px 18px rgba(22, 32, 42, 0.25);\n white-space: nowrap;\n}\n.sf-highlight {\n position: absolute;\n pointer-events: none;\n border: 2px solid #1f6feb;\n background: rgba(31, 111, 235, 0.08);\n border-radius: 3px;\n}\n.sf-marker {\n position: absolute;\n width: 14px;\n height: 14px;\n margin: -7px 0 0 -7px;\n border-radius: 50%;\n background: #1f6feb;\n border: 2px solid #fff;\n box-shadow: 0 2px 6px rgba(22, 32, 42, 0.3);\n pointer-events: none;\n}\n.sf-form {\n position: fixed;\n width: 300px;\n max-width: calc(100vw - 16px);\n background: #fff;\n border: 1px solid #e3e8ee;\n border-radius: 10px;\n box-shadow: 0 8px 24px rgba(22, 32, 42, 0.18);\n padding: 12px;\n}\n.sf-textarea, .sf-input {\n font: inherit;\n width: 100%;\n border: 1px solid #c9d2dc;\n border-radius: 8px;\n padding: 8px;\n resize: vertical;\n color: #16202a;\n background: #fff;\n}\n.sf-textarea { min-height: 84px; }\n.sf-status { margin-top: 8px; min-height: 1.2em; }\n.sf-status--error { color: #b42318; }\n.sf-card {\n border: 1px solid #e3e8ee;\n border-radius: 10px;\n padding: 10px 12px;\n margin-bottom: 10px;\n}\n.sf-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }\n.sf-chip {\n font-size: 11px;\n font-weight: 600;\n border-radius: 999px;\n padding: 2px 8px;\n background: #eef2f6;\n color: #16202a;\n}\n.sf-chip--working { background: #fff4d6; color: #7a4b00; }\n.sf-chip--done { background: #dcf5e6; color: #0f5132; }\n.sf-date { font-size: 12px; color: #5b6b7a; }\n.sf-card-text { white-space: pre-wrap; word-break: break-word; }\n.sf-card-path { font-size: 12px; color: #5b6b7a; margin-top: 4px; word-break: break-all; }\n.sf-replies { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }\n.sf-reply {\n max-width: 88%;\n border-radius: 8px;\n padding: 6px 8px;\n background: #eef2f6;\n align-self: flex-start;\n}\n.sf-reply--you { background: #e4eefc; align-self: flex-end; text-align: right; }\n.sf-reply-from { display: block; font-size: 11px; font-weight: 600; color: #5b6b7a; margin-bottom: 2px; }\n.sf-reply-text { white-space: pre-wrap; word-break: break-word; }\n.sf-reply-box { display: flex; gap: 6px; margin-top: 8px; }\n',s.appendChild(n),(t.documentElement||t.body).appendChild(e),this.host=e,this.root=s,s}showTab(){try{this.tab&&this.tab.classList.remove("sf-hidden")}catch(t){this.warn("showTab failed",t)}}side(){try{return this.grant&&this.grant.project&&"left"===this.grant.project.buttonPosition?"left":"right"}catch(t){return"right"}}origin(){var t;try{return(null===(t=this.deps.win.location)||void 0===t?void 0:t.origin)||""}catch(t){return""}}storeSession(t){try{this.deps.storage&&this.deps.storage.setItem(n,t)}catch(t){this.warn("could not store the live session",t)}}clearStoredToolbarFlags(){try{if(!this.deps.storage)return;for(const t of s)this.deps.storage.removeItem(t)}catch(t){this.warn("could not clear the stored review flags",t)}}clearSession(){try{this.deps.storage&&this.deps.storage.removeItem(n)}catch(t){this.warn("could not clear the live session",t)}}endSession(){try{this.clearSession(),this.session=null,this.endPick(),this.removeForm(),this.closePanel(),this.host&&this.host.remove(),this.host=null,this.root=null,this.tab=null}catch(t){this.warn("endSession failed",t)}}teardownIfEmpty(){try{this.host&&this.root&&this.root.children.length<=1&&(this.host.remove(),this.host=null,this.root=null)}catch(t){this.warn("teardownIfEmpty failed",t)}}stripTokenFromLocation(){var t;try{const e=this.deps.win,s=(null===(t=e.location)||void 0===t?void 0:t.href)||"",n=V(s);n!==s&&e.history&&"function"==typeof e.history.replaceState&&e.history.replaceState(e.history.state,"",n)}catch(t){this.warn("could not strip the token from the URL",t)}}warn(t,e){try{if(this.warned.has(t))return;this.warned.add(t),void 0===e?console.warn(`[superflow live] ${t}`):console.warn(`[superflow live] ${t}:`,e)}catch(t){}}}function ot(t){const s=t;try{return s.SuperflowLive||(s.SuperflowLive={version:e,ready:!1}),s.SuperflowLive}catch(t){return console.warn("[superflow live] registerLiveBundle failed:",t),{version:e,ready:!1}}}function at(t){try{const e=t.getElementById("superflowToolbarScript");if(!e||!e.src)return{apiKey:null,projectId:null};const s=new URL(e.src).searchParams;return{apiKey:s.get("apiKey"),projectId:s.get("projectId")}}catch(t){return{apiKey:null,projectId:null}}}function lt(t){try{const e=t.currentScript;return e&&(e.nonce||e.getAttribute("nonce"))||null}catch(t){return null}}const ct=ot(window),dt=at(document);(function(t){try{return new rt(t).start()}catch(t){return console.warn("[superflow live] runLive failed, drawing nothing:",t),Promise.resolve("none")}})({win:window,doc:document,storage:function(t){try{return t.localStorage||null}catch(t){return null}}(window),fetchFn:(t,e)=>window.fetch(t,e),now:()=>Date.now(),endpoint:"https://us-central1-snipply-sdk-staging.cloudfunctions.net/anonymoushandler",staging:!0,nonce:lt(document),version:e,apiKey:dt.apiKey,projectId:dt.projectId,userAgent:"undefined"!=typeof navigator?navigator.userAgent:""}).then((()=>{ct.ready=!0})).catch((t=>{console.warn("[superflow live] runLive failed:",t),ct.ready=!0})),t.currentScriptNonce=lt,t.readInstallParams=at,t.registerLiveBundle=ot}({});
|