@weatherboard/annotation 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/dist/arming.d.cts CHANGED
@@ -12,11 +12,14 @@ import { type BuildInfo } from "./protocol.cjs";
12
12
  *
13
13
  * 1. read the three parameters
14
14
  * 2. **strip them from the URL** with `replaceState`, before anything else
15
- * 3. keep the capture token for the tab
16
- * 4. answer *is this page armed* — from the COOKIE, never from the URL
17
- *
18
- * Step 4 is the runtime half of the kill-switch and step 2 is not decoration;
19
- * both are argued at length below.
15
+ * 3. answer *is this page armed* — from the COOKIE, never from the URL
16
+ * 4. only then, and only if armed, keep the capture token for the tab
17
+ *
18
+ * Step 3 is the runtime half of the kill-switch and step 2 is not decoration;
19
+ * both are argued at length below. Steps 3 and 4 were the other way round
20
+ * until A-254, which is how an unarmed page came to persist an
21
+ * attacker-supplied token — the argument, and the measurement that settled it,
22
+ * are at the gate itself in `readArming`.
20
23
  *
21
24
  * ===========================================================================
22
25
  * TWO CREDENTIALS, AND THIS FILE TOUCHES THEM DIFFERENTLY ON PURPOSE
package/dist/arming.d.mts CHANGED
@@ -12,11 +12,14 @@ import { type BuildInfo } from "./protocol.mjs";
12
12
  *
13
13
  * 1. read the three parameters
14
14
  * 2. **strip them from the URL** with `replaceState`, before anything else
15
- * 3. keep the capture token for the tab
16
- * 4. answer *is this page armed* — from the COOKIE, never from the URL
17
- *
18
- * Step 4 is the runtime half of the kill-switch and step 2 is not decoration;
19
- * both are argued at length below.
15
+ * 3. answer *is this page armed* — from the COOKIE, never from the URL
16
+ * 4. only then, and only if armed, keep the capture token for the tab
17
+ *
18
+ * Step 3 is the runtime half of the kill-switch and step 2 is not decoration;
19
+ * both are argued at length below. Steps 3 and 4 were the other way round
20
+ * until A-254, which is how an unarmed page came to persist an
21
+ * attacker-supplied token — the argument, and the measurement that settled it,
22
+ * are at the gate itself in `readArming`.
20
23
  *
21
24
  * ===========================================================================
22
25
  * TWO CREDENTIALS, AND THIS FILE TOUCHES THEM DIFFERENTLY ON PURPOSE
package/dist/arming.d.ts CHANGED
@@ -12,11 +12,14 @@ import { type BuildInfo } from "./protocol.js";
12
12
  *
13
13
  * 1. read the three parameters
14
14
  * 2. **strip them from the URL** with `replaceState`, before anything else
15
- * 3. keep the capture token for the tab
16
- * 4. answer *is this page armed* — from the COOKIE, never from the URL
17
- *
18
- * Step 4 is the runtime half of the kill-switch and step 2 is not decoration;
19
- * both are argued at length below.
15
+ * 3. answer *is this page armed* — from the COOKIE, never from the URL
16
+ * 4. only then, and only if armed, keep the capture token for the tab
17
+ *
18
+ * Step 3 is the runtime half of the kill-switch and step 2 is not decoration;
19
+ * both are argued at length below. Steps 3 and 4 were the other way round
20
+ * until A-254, which is how an unarmed page came to persist an
21
+ * attacker-supplied token — the argument, and the measurement that settled it,
22
+ * are at the gate itself in `readArming`.
20
23
  *
21
24
  * ===========================================================================
22
25
  * TWO CREDENTIALS, AND THIS FILE TOUCHES THEM DIFFERENTLY ON PURPOSE
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var xe=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var Et=Object.prototype.hasOwnProperty;var Ve=e=>{throw TypeError(e)};var At=(e,t)=>{for(var n in t)xe(e,n,{get:t[n],enumerable:!0})},xt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of yt(t))!Et.call(e,r)&&r!==n&&xe(e,r,{get:()=>t[r],enumerable:!(o=bt(t,r))||o.enumerable});return e};var Tt=e=>xt(xe({},"__esModule",{value:!0}),e);var je=(e,t,n)=>t.has(e)||Ve("Cannot "+n);var L=(e,t,n)=>(je(e,t,"read from private field"),n?n.call(e):t.get(e)),Te=(e,t,n)=>t.has(e)?Ve("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ye=(e,t,n,o)=>(je(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var Dt={};At(Dt,{ANNOTATION_ARMED_COOKIE:()=>ie,ANNOTATION_ARMED_COOKIES:()=>z,ANNOTATION_ARMED_VALUE:()=>Se,ANNOTATION_TOKEN_PARAM:()=>ve,ANNOTATION_TOKEN_PARAMS:()=>Y,CAPTURE_TOKEN_PARAM:()=>V,CAPTURE_TOKEN_STORAGE_KEY:()=>ee,DEFAULT_LABELS:()=>Ke,DEFAULT_LIMIT:()=>ct,HTTP_TRANSPORT_TIMEOUT_MS:()=>Le,LEGACY_ANNOTATION_ARMED_COOKIE:()=>we,LEGACY_ANNOTATION_TOKEN_PARAM:()=>Ce,MAX_CHAIN:()=>Re,MAX_SCREENSHOT_BYTES:()=>et,MAX_SCREENSHOT_EDGE:()=>tt,MAX_TEXT:()=>ue,NAME_ATTR:()=>re,OVERLAY_ID:()=>Oe,REVIEW_RUN_PARAM:()=>j,REVIEW_RUN_STORAGE_KEY:()=>te,RingBuffer:()=>K,SCREENSHOT_TIMEOUT_MS:()=>nt,SDK_VERSION:()=>G,SRC_ATTR:()=>W,TOOLBAR_ID:()=>Be,armedCookie:()=>Je,assertConcreteEndpoint:()=>Ie,assertConcreteOrigin:()=>D,attachScreenshot:()=>Q,captureScreenshot:()=>He,captureScreenshotSync:()=>De,clearedCookie:()=>se,collectSourceChain:()=>ke,createAnnotationSdk:()=>he,createAnnotationToolbar:()=>$e,createEgress:()=>fe,createOverlay:()=>ce,defaultStateCollectorOptions:()=>Ge,describeArg:()=>qe,domPath:()=>Me,emptyAnnotationState:()=>ot,findAnnotatedAncestor:()=>_e,findCaptureSource:()=>Pe,firstStack:()=>ye,fitWithin:()=>Ue,formatConsoleArgs:()=>Xe,httpTransport:()=>Qe,installStateCollector:()=>dt,intrinsicSize:()=>Fe,isAnnotatableBuild:()=>be,isAnnotationArmed:()=>le,isFailedStatus:()=>Ee,isMediaElement:()=>Z,isParentMessage:()=>ae,mountAnnotation:()=>lt,parseSourceRef:()=>de,postMessageTransport:()=>me,readAnnotationToken:()=>Ze,readArming:()=>at,resolveScreenshotOptions:()=>ge,resolveTarget:()=>pe,safeIssueUrl:()=>J,selectionOf:()=>ze,summariseText:()=>Ne});module.exports=Tt(Dt);var G="1",W="data-src",re="data-src-name";function ze(e){return e.selection==="region"?"region":"element"}var vt=new Set(["annotate:enable","annotate:disable","annotate:ping"]);function ae(e){if(typeof e!="object"||e===null)return!1;let t=e.type;return typeof t=="string"&&vt.has(t)}function D(e){if(!e||e==="*")throw new Error("[annotation] a concrete parent origin is required; '*' would broadcast annotation payloads to any embedder.");return e}var ve="ai_annotate",ie="ai_annotate_armed",V="ai_capture",j="ai_run",Se="1";function Je(e=ie){return`${e}=${Se}; Path=/; SameSite=Lax; Secure`}function se(e){return`${e}=; Path=/; SameSite=Lax; Secure; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT`}var Ce="pits_annotate",we="pits_annotate_armed",Y=[ve,Ce],z=[ie,we];function le(e){return e.split(";").some(t=>{let n=t.trimStart();return z.some(o=>n.startsWith(`${o}=`))})}function Ze(e){for(let t of Y){let n=e.get(t);if(n!==null&&n.length>0)return n}return null}var Oe="ai-annotation-overlay",St="2147483000";function ce(e){let t=e.createElement("div");t.id=Oe,t.style.cssText=["position:fixed","top:0","left:0","pointer-events:none",`z-index:${St}`,"display:none","box-sizing:border-box","border:2px solid #2563eb","background:rgba(37,99,235,0.12)","border-radius:2px"].join(";");let n=e.createElement("div");return n.style.cssText=["position:absolute","left:0","top:-20px","font:11px/16px ui-monospace,SFMono-Regular,Menlo,monospace","color:#fff","background:#2563eb","padding:1px 5px","border-radius:2px","white-space:nowrap","max-width:60vw","overflow:hidden","text-overflow:ellipsis"].join(";"),t.appendChild(n),e.body.appendChild(t),{show(o,r){t.style.display="block",t.style.transform=`translate(${o.x}px, ${o.y}px)`,t.style.width=`${o.w}px`,t.style.height=`${o.h}px`,n.style.top=o.y<20?"100%":"-20px",n.textContent=r??"",n.style.display=r?"block":"none"},hide(){t.style.display="none"},destroy(){t.remove()},contains(o){return o instanceof Node&&t.contains(o)}}}var ue=200,Re=8;function de(e){if(!e)return null;let t=e.lastIndexOf(":");if(t<=0)return null;let n=e.lastIndexOf(":",t-1);if(n<=0)return null;let o=e.slice(0,n),r=Number(e.slice(n+1,t)),a=Number(e.slice(t+1));return!o||!Number.isFinite(r)||!Number.isFinite(a)?null:{file:o,line:r,column:a}}function ke(e,t=Re){let n=[],o=e;for(;o&&n.length<t;){let r=de(o.getAttribute(W));if(r){let a=n[n.length-1];a&&a.file===r.file&&a.line===r.line||n.push(r)}o=o.parentElement}return n}function _e(e){let t=e;for(;t;){if(de(t.getAttribute(W)))return t;t=t.parentElement}return null}function Ct(e){let t=e.classList;return(typeof t?.value=="string"?t.value:"").split(/\s+/).filter(Boolean)}function Me(e,t=6){let n=[],o=e;for(;o&&n.length<t;){let r=(o.tagName||"").toLowerCase();if(!r||r==="html")break;let a=r;if(o.id)return n.unshift(`${r}#${o.id}`),n.join(" > ");let i=Ct(o).slice(0,2);if(i.length>0&&(a+=`.${i.join(".")}`),n.unshift(a),r==="body")break;o=o.parentElement}return n.join(" > ")}function Ne(e){if(!e)return;let t=e.replace(/\s+/g," ").trim();if(t)return t.length>ue?`${t.slice(0,ue-1)}\u2026`:t}function pe(e,t){let n=_e(e),o=ke(e),r=o[0],a={domPath:Me(e),boundingBox:t.boundingBox};r&&(a.source=r),o.length>0&&(a.sourceChain=o);let i=n?.getAttribute(re);i&&(a.componentName=i);let c=Ne(e.textContent);return c&&(a.textContent=c),a}var wt=2048;function J(e){if(typeof e!="string"||e.length===0||e.length>wt)return;let t;try{t=new URL(e)}catch{return}if(!(t.protocol!=="https:"&&t.protocol!=="http:"))return t.href}function me(e,t=window){let n=D(e);return{name:"postMessage",carries:()=>!0,send(o){t.parent.postMessage(o,n)}}}function Ie(e){if(!e||e==="*")throw new Error("[annotation] a concrete ingest endpoint is required; '*' is not an address and an empty one posts nowhere.");let t;try{t=new URL(e)}catch{throw new Error(`[annotation] the ingest endpoint must be an absolute URL, got ${JSON.stringify(e)}; a relative one resolves against the product's own origin and the capture is lost there.`)}if(t.protocol!=="https:"&&t.protocol!=="http:")throw new Error(`[annotation] the ingest endpoint must be http(s), got ${t.protocol}`);return t.toString()}var Le=8e3;function Qe(e){let t=Ie(e.endpoint);if(!e.captureToken)throw new Error("[annotation] a capture token is required; the ingest rejects an unsigned capture and the reviewer would only find out after writing one.");let n=e.captureToken,o=e.timeoutMs??Le,r=e.fetch??globalThis.fetch;return{name:"http",carries:a=>a==="annotate:capture",async send(a){if(!r)throw new Error("[annotation] no fetch implementation is available for the ingest");let i=new AbortController,c=setTimeout(()=>i.abort(),o);try{let f=await r(t,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${n}`},credentials:"omit",body:JSON.stringify(a),signal:i.signal});if(!f.ok)throw new Error(`[annotation] the ingest rejected the capture: HTTP ${f.status}`);try{let h=await f.json?.(),g=J(h?.issueUrl);if(g!==void 0)return{issueUrl:g}}catch{}return{}}catch(f){throw i.signal.aborted?new Error(`[annotation] the capture timed out after ${o}ms`,{cause:f}):f}finally{clearTimeout(c)}}}}function fe(e,t){let n=(o,r)=>{let a={message:o,transport:e.name,error:r};if(t){t(a);return}console.error("[annotation] a capture could not be delivered",a)};return async o=>{if(!e.carries(o.type))return{status:"declined"};try{return{status:"sent",receipt:await e.send(o)??{}}}catch(r){return n(o,r),{status:"failed",error:r}}}}var et=49152,tt=480,nt=250,Ot=[{edge:480,quality:.7},{edge:240,quality:.5}],Rt=["image/webp","image/jpeg"];function ge(e,t){let n=e===!1?{enabled:!1}:e??{};return{enabled:n.enabled??!0,maxBytes:n.maxBytes??49152,maxEdge:n.maxEdge??480,timeoutMs:n.timeoutMs??250,createCanvas:n.createCanvas??(()=>t?.createElement("canvas")??null)}}var kt=new Set(["IMG","CANVAS","VIDEO"]),_t="img,canvas,video",Mt=4;function Z(e){return!!e&&kt.has(e.tagName.toUpperCase())}function Pe(e,t=Mt){if(!e)return null;if(Z(e))return e;let n=e.querySelector?.(_t)??null;if(Z(n))return n;let o=e.parentElement??null;for(let r=0;o&&r<t;r++){if(Z(o))return o;o=o.parentElement??null}return null}function Fe(e){let t=e.tagName.toUpperCase(),n=t==="IMG"?{w:e.naturalWidth,h:e.naturalHeight}:t==="VIDEO"?{w:e.videoWidth,h:e.videoHeight}:{w:e.width,h:e.height},o=Math.floor(n.w??0),r=Math.floor(n.h??0);return!Number.isFinite(o)||!Number.isFinite(r)||o<1||r<1||t==="IMG"&&e.complete===!1?null:{w:o,h:r}}function Ue(e,t){let n=Math.min(1,t/Math.max(e.w,e.h));return{w:Math.max(1,Math.round(e.w*n)),h:Math.max(1,Math.round(e.h*n))}}function Nt(e,t,n,o){let r;try{r=o.createCanvas()}catch{return null}if(!r)return null;try{r.width=t.w,r.height=t.h;let a=r.getContext("2d");if(!a)return null;a.drawImage(e,0,0,t.w,t.h);for(let i of Rt){let c;try{c=r.toDataURL(i,n)}catch{return null}if(!(typeof c!="string"||!c.startsWith(`data:${i}`)))return c.length<=o.maxBytes?c:null}return null}catch{return null}}function De(e,t){if(!t.enabled)return null;let n=Pe(e);if(!n)return null;let o=Fe(n);if(!o)return null;for(let r of Ot){let a=Ue(o,Math.min(t.maxEdge,r.edge)),i=Nt(n,a,r.quality,t);if(i)return{dataUrl:i,region:"element"}}return null}function He(e,t){return t.enabled?new Promise(n=>{let o=!1,r=i=>{o||(o=!0,n(i))},a=setTimeout(()=>r(null),t.timeoutMs);a.unref?.(),Promise.resolve().then(()=>De(e,t)).then(r,()=>r(null)).finally(()=>clearTimeout(a))}):Promise.resolve(null)}async function Q(e,t,n){let o;try{o=await He(t,n)}catch{o=null}return o?{...e,screenshot:o}:e}var It={consoleErrors:[],failedRequests:[],featureFlags:{}},ot=()=>({...It});function he(e){let t=e.parentOrigin===void 0?null:D(e.parentOrigin),n=window,o=n.document,r=ge(e.screenshot,o),a=!1,i=null,c=0,f=null,h=!1,g=e.transport??(t===null?null:me(t,n));if(g===null)throw new Error("[annotation] the SDK needs a `transport` or a `parentOrigin`; with neither there is nowhere for a capture to go and every one of them would be lost in silence.");let p=fe(g,e.onEgressError),d=l=>{let u=l.getBoundingClientRect();return{x:u.x,y:u.y,w:u.width,h:u.height}},T=l=>pe(l,{boundingBox:d(l)}),x=l=>{if(l.componentName&&l.source){let u=l.source.file.split("/").pop()??l.source.file;return`${l.componentName} \xB7 ${u}:${l.source.line}`}return l.source?`${l.source.file}:${l.source.line}`:l.componentName??null},A=l=>{!a||h||c||(c=n.requestAnimationFrame(()=>{c=0;let u=o.elementFromPoint(l.clientX,l.clientY);if(!u||i&&i.contains(u)||e.ignoreElement?.(u)||u===f)return;f=u;let b=T(u);i?.show(b.boundingBox,x(b)),p({type:"annotate:hover",target:b})}))},R=(l,u)=>({schemaVersion:1,capturedAt:new Date().toISOString(),build:e.build,page:{url:n.location.href,route:e.getRoute(),viewport:{w:n.innerWidth,h:n.innerHeight,dpr:n.devicePixelRatio},userAgent:n.navigator.userAgent},target:T(l),state:{consoleErrors:u.consoleErrors,failedRequests:u.failedRequests,featureFlags:u.featureFlags},comment:""}),N=l=>{let u={type:"annotate:capture",payload:l},b=()=>{p(u).then(O=>e.onCaptureResult?.(O,b))};b()},k=l=>{if(!a)return;let u=l.target;if(!(u instanceof Element)||e.ignoreElement?.(u)||(l.preventDefault(),l.stopPropagation(),h))return;let b=R(u,e.getState()),O=e.collectComment;if(!O){if(!r.enabled){N(b);return}Q(b,u,r).then(S=>N(S),()=>N(b));return}let B={x:l.clientX,y:l.clientY},$=r.enabled?Q(b,u,r).then(S=>S,()=>b):Promise.resolve(b),I=()=>{h=!0;let S=null,oe=O({target:b.target,point:B}).then(E=>E,E=>(S={error:E},null));Promise.all([$,oe]).then(([E,U])=>{if(h=!1,S!==null){e.onCaptureResult?.({status:"failed",error:S.error},I);return}U!==null&&N(U===""?E:{...E,comment:U})})};I()},P=l=>{!a||h||l.key!=="Escape"||(p({type:"annotate:cancel"}),_())};function F(){a||(a=!0,i??(i=ce(o)),o.addEventListener("mousemove",A,!0),o.addEventListener("click",k,!0),o.addEventListener("keydown",P,!0))}function _(){a&&(a=!1,f=null,c&&(n.cancelAnimationFrame(c),c=0),o.removeEventListener("mousemove",A,!0),o.removeEventListener("click",k,!0),o.removeEventListener("keydown",P,!0),i?.hide())}let v=l=>{if(l.origin===t&&ae(l.data))switch(l.data.type){case"annotate:enable":F();break;case"annotate:disable":_();break;case"annotate:ping":p({type:"annotate:ready",sdkVersion:"1",build:e.build});break}};return t!==null&&n.addEventListener("message",v),p({type:"annotate:ready",sdkVersion:"1",build:e.build}),{enable:F,disable:_,isEnabled:()=>a,destroy(){_(),t!==null&&n.removeEventListener("message",v),i?.destroy(),i=null}}}var ee="ai.annotation.capture",te="ai.annotation.run",rt=[...Y,V,j];function w(e,t){try{return e()}catch{return t}}function Lt(e){return w(()=>e?.sessionStorage??null,null)}function at(e={}){let t=e.doc??document,n=t.defaultView??null,o=e.storage===void 0?Lt(n):e.storage,r=e.url??t.URL,a=w(()=>new URL(r),null),i=null,c=null;if(a!==null&&(i=a.searchParams.get(V)||null,c=a.searchParams.get(j)||null,rt.some(g=>a.searchParams.has(g)))){for(let p of rt)a.searchParams.delete(p);let g=e.history??n?.history;w(()=>{g?.replaceState(n?.history?.state??null,"",a.toString())},void 0)}o&&(i!==null?w(()=>o.setItem(ee,i),void 0):i=w(()=>o.getItem(ee),null),c!==null?w(()=>o.setItem(te,c),void 0):c=w(()=>o.getItem(te),null));let f=()=>{for(let h of z)w(()=>{t.cookie=se(h)},void 0);o&&(w(()=>o.removeItem(ee),void 0),w(()=>o.removeItem(te),void 0))};return{armed:le(w(()=>t.cookie,"")),captureToken:i,runId:c,disarm:f}}var Pt=["preview","staging","development"];function be(e){return Pt.includes(e.env)}var Ke={region:"Annotation",expand:"Open the annotation toolbar",collapse:"Close the annotation toolbar",start:"Start annotating",stop:"Stop annotating",done:"Done",comment:"What is wrong here?",placeholder:"The heading wraps onto three lines on mobile\u2026",send:"Send",cancel:"Cancel",sent:"Sent",issue:"View issue",failed:"That did not send",retry:"Retry"},Be="ai-annotation-toolbar",Ft="2147483001",st=288,it=190,H=12,Ut=`
1
+ "use strict";var xe=Object.defineProperty;var bt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var Et=Object.prototype.hasOwnProperty;var Ve=e=>{throw TypeError(e)};var At=(e,t)=>{for(var n in t)xe(e,n,{get:t[n],enumerable:!0})},xt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of yt(t))!Et.call(e,r)&&r!==n&&xe(e,r,{get:()=>t[r],enumerable:!(o=bt(t,r))||o.enumerable});return e};var Tt=e=>xt(xe({},"__esModule",{value:!0}),e);var je=(e,t,n)=>t.has(e)||Ve("Cannot "+n);var L=(e,t,n)=>(je(e,t,"read from private field"),n?n.call(e):t.get(e)),Te=(e,t,n)=>t.has(e)?Ve("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Ye=(e,t,n,o)=>(je(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var Dt={};At(Dt,{ANNOTATION_ARMED_COOKIE:()=>ie,ANNOTATION_ARMED_COOKIES:()=>z,ANNOTATION_ARMED_VALUE:()=>Se,ANNOTATION_TOKEN_PARAM:()=>ve,ANNOTATION_TOKEN_PARAMS:()=>Y,CAPTURE_TOKEN_PARAM:()=>V,CAPTURE_TOKEN_STORAGE_KEY:()=>ee,DEFAULT_LABELS:()=>Ke,DEFAULT_LIMIT:()=>ct,HTTP_TRANSPORT_TIMEOUT_MS:()=>Le,LEGACY_ANNOTATION_ARMED_COOKIE:()=>we,LEGACY_ANNOTATION_TOKEN_PARAM:()=>Ce,MAX_CHAIN:()=>Re,MAX_SCREENSHOT_BYTES:()=>et,MAX_SCREENSHOT_EDGE:()=>tt,MAX_TEXT:()=>ue,NAME_ATTR:()=>re,OVERLAY_ID:()=>Oe,REVIEW_RUN_PARAM:()=>j,REVIEW_RUN_STORAGE_KEY:()=>te,RingBuffer:()=>K,SCREENSHOT_TIMEOUT_MS:()=>nt,SDK_VERSION:()=>G,SRC_ATTR:()=>W,TOOLBAR_ID:()=>Be,armedCookie:()=>Je,assertConcreteEndpoint:()=>Ie,assertConcreteOrigin:()=>D,attachScreenshot:()=>Q,captureScreenshot:()=>He,captureScreenshotSync:()=>De,clearedCookie:()=>se,collectSourceChain:()=>ke,createAnnotationSdk:()=>he,createAnnotationToolbar:()=>$e,createEgress:()=>fe,createOverlay:()=>ce,defaultStateCollectorOptions:()=>Ge,describeArg:()=>qe,domPath:()=>Me,emptyAnnotationState:()=>ot,findAnnotatedAncestor:()=>_e,findCaptureSource:()=>Pe,firstStack:()=>ye,fitWithin:()=>Ue,formatConsoleArgs:()=>Xe,httpTransport:()=>Qe,installStateCollector:()=>dt,intrinsicSize:()=>Fe,isAnnotatableBuild:()=>be,isAnnotationArmed:()=>le,isFailedStatus:()=>Ee,isMediaElement:()=>Z,isParentMessage:()=>ae,mountAnnotation:()=>lt,parseSourceRef:()=>de,postMessageTransport:()=>me,readAnnotationToken:()=>Ze,readArming:()=>at,resolveScreenshotOptions:()=>ge,resolveTarget:()=>pe,safeIssueUrl:()=>J,selectionOf:()=>ze,summariseText:()=>Ne});module.exports=Tt(Dt);var G="1",W="data-src",re="data-src-name";function ze(e){return e.selection==="region"?"region":"element"}var vt=new Set(["annotate:enable","annotate:disable","annotate:ping"]);function ae(e){if(typeof e!="object"||e===null)return!1;let t=e.type;return typeof t=="string"&&vt.has(t)}function D(e){if(!e||e==="*")throw new Error("[annotation] a concrete parent origin is required; '*' would broadcast annotation payloads to any embedder.");return e}var ve="ai_annotate",ie="ai_annotate_armed",V="ai_capture",j="ai_run",Se="1";function Je(e=ie){return`${e}=${Se}; Path=/; SameSite=Lax; Secure`}function se(e){return`${e}=; Path=/; SameSite=Lax; Secure; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT`}var Ce="pits_annotate",we="pits_annotate_armed",Y=[ve,Ce],z=[ie,we];function le(e){return e.split(";").some(t=>{let n=t.trimStart();return z.some(o=>n.startsWith(`${o}=`))})}function Ze(e){for(let t of Y){let n=e.get(t);if(n!==null&&n.length>0)return n}return null}var Oe="ai-annotation-overlay",St="2147483000";function ce(e){let t=e.createElement("div");t.id=Oe,t.style.cssText=["position:fixed","top:0","left:0","pointer-events:none",`z-index:${St}`,"display:none","box-sizing:border-box","border:2px solid #2563eb","background:rgba(37,99,235,0.12)","border-radius:2px"].join(";");let n=e.createElement("div");return n.style.cssText=["position:absolute","left:0","top:-20px","font:11px/16px ui-monospace,SFMono-Regular,Menlo,monospace","color:#fff","background:#2563eb","padding:1px 5px","border-radius:2px","white-space:nowrap","max-width:60vw","overflow:hidden","text-overflow:ellipsis"].join(";"),t.appendChild(n),e.body.appendChild(t),{show(o,r){t.style.display="block",t.style.transform=`translate(${o.x}px, ${o.y}px)`,t.style.width=`${o.w}px`,t.style.height=`${o.h}px`,n.style.top=o.y<20?"100%":"-20px",n.textContent=r??"",n.style.display=r?"block":"none"},hide(){t.style.display="none"},destroy(){t.remove()},contains(o){return o instanceof Node&&t.contains(o)}}}var ue=200,Re=8;function de(e){if(!e)return null;let t=e.lastIndexOf(":");if(t<=0)return null;let n=e.lastIndexOf(":",t-1);if(n<=0)return null;let o=e.slice(0,n),r=Number(e.slice(n+1,t)),a=Number(e.slice(t+1));return!o||!Number.isFinite(r)||!Number.isFinite(a)?null:{file:o,line:r,column:a}}function ke(e,t=Re){let n=[],o=e;for(;o&&n.length<t;){let r=de(o.getAttribute(W));if(r){let a=n[n.length-1];a&&a.file===r.file&&a.line===r.line||n.push(r)}o=o.parentElement}return n}function _e(e){let t=e;for(;t;){if(de(t.getAttribute(W)))return t;t=t.parentElement}return null}function Ct(e){let t=e.classList;return(typeof t?.value=="string"?t.value:"").split(/\s+/).filter(Boolean)}function Me(e,t=6){let n=[],o=e;for(;o&&n.length<t;){let r=(o.tagName||"").toLowerCase();if(!r||r==="html")break;let a=r;if(o.id)return n.unshift(`${r}#${o.id}`),n.join(" > ");let i=Ct(o).slice(0,2);if(i.length>0&&(a+=`.${i.join(".")}`),n.unshift(a),r==="body")break;o=o.parentElement}return n.join(" > ")}function Ne(e){if(!e)return;let t=e.replace(/\s+/g," ").trim();if(t)return t.length>ue?`${t.slice(0,ue-1)}\u2026`:t}function pe(e,t){let n=_e(e),o=ke(e),r=o[0],a={domPath:Me(e),boundingBox:t.boundingBox};r&&(a.source=r),o.length>0&&(a.sourceChain=o);let i=n?.getAttribute(re);i&&(a.componentName=i);let c=Ne(e.textContent);return c&&(a.textContent=c),a}var wt=2048;function J(e){if(typeof e!="string"||e.length===0||e.length>wt)return;let t;try{t=new URL(e)}catch{return}if(!(t.protocol!=="https:"&&t.protocol!=="http:"))return t.href}function me(e,t=window){let n=D(e);return{name:"postMessage",carries:()=>!0,send(o){t.parent.postMessage(o,n)}}}function Ie(e){if(!e||e==="*")throw new Error("[annotation] a concrete ingest endpoint is required; '*' is not an address and an empty one posts nowhere.");let t;try{t=new URL(e)}catch{throw new Error(`[annotation] the ingest endpoint must be an absolute URL, got ${JSON.stringify(e)}; a relative one resolves against the product's own origin and the capture is lost there.`)}if(t.protocol!=="https:"&&t.protocol!=="http:")throw new Error(`[annotation] the ingest endpoint must be http(s), got ${t.protocol}`);return t.toString()}var Le=8e3;function Qe(e){let t=Ie(e.endpoint);if(!e.captureToken)throw new Error("[annotation] a capture token is required; the ingest rejects an unsigned capture and the reviewer would only find out after writing one.");let n=e.captureToken,o=e.timeoutMs??Le,r=e.fetch??globalThis.fetch;return{name:"http",carries:a=>a==="annotate:capture",async send(a){if(!r)throw new Error("[annotation] no fetch implementation is available for the ingest");let i=new AbortController,c=setTimeout(()=>i.abort(),o);try{let m=await r(t,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${n}`},credentials:"omit",body:JSON.stringify(a),signal:i.signal});if(!m.ok)throw new Error(`[annotation] the ingest rejected the capture: HTTP ${m.status}`);try{let g=await m.json?.(),h=J(g?.issueUrl);if(h!==void 0)return{issueUrl:h}}catch{}return{}}catch(m){throw i.signal.aborted?new Error(`[annotation] the capture timed out after ${o}ms`,{cause:m}):m}finally{clearTimeout(c)}}}}function fe(e,t){let n=(o,r)=>{let a={message:o,transport:e.name,error:r};if(t){t(a);return}console.error("[annotation] a capture could not be delivered",a)};return async o=>{if(!e.carries(o.type))return{status:"declined"};try{return{status:"sent",receipt:await e.send(o)??{}}}catch(r){return n(o,r),{status:"failed",error:r}}}}var et=49152,tt=480,nt=250,Ot=[{edge:480,quality:.7},{edge:240,quality:.5}],Rt=["image/webp","image/jpeg"];function ge(e,t){let n=e===!1?{enabled:!1}:e??{};return{enabled:n.enabled??!0,maxBytes:n.maxBytes??49152,maxEdge:n.maxEdge??480,timeoutMs:n.timeoutMs??250,createCanvas:n.createCanvas??(()=>t?.createElement("canvas")??null)}}var kt=new Set(["IMG","CANVAS","VIDEO"]),_t="img,canvas,video",Mt=4;function Z(e){return!!e&&kt.has(e.tagName.toUpperCase())}function Pe(e,t=Mt){if(!e)return null;if(Z(e))return e;let n=e.querySelector?.(_t)??null;if(Z(n))return n;let o=e.parentElement??null;for(let r=0;o&&r<t;r++){if(Z(o))return o;o=o.parentElement??null}return null}function Fe(e){let t=e.tagName.toUpperCase(),n=t==="IMG"?{w:e.naturalWidth,h:e.naturalHeight}:t==="VIDEO"?{w:e.videoWidth,h:e.videoHeight}:{w:e.width,h:e.height},o=Math.floor(n.w??0),r=Math.floor(n.h??0);return!Number.isFinite(o)||!Number.isFinite(r)||o<1||r<1||t==="IMG"&&e.complete===!1?null:{w:o,h:r}}function Ue(e,t){let n=Math.min(1,t/Math.max(e.w,e.h));return{w:Math.max(1,Math.round(e.w*n)),h:Math.max(1,Math.round(e.h*n))}}function Nt(e,t,n,o){let r;try{r=o.createCanvas()}catch{return null}if(!r)return null;try{r.width=t.w,r.height=t.h;let a=r.getContext("2d");if(!a)return null;a.drawImage(e,0,0,t.w,t.h);for(let i of Rt){let c;try{c=r.toDataURL(i,n)}catch{return null}if(!(typeof c!="string"||!c.startsWith(`data:${i}`)))return c.length<=o.maxBytes?c:null}return null}catch{return null}}function De(e,t){if(!t.enabled)return null;let n=Pe(e);if(!n)return null;let o=Fe(n);if(!o)return null;for(let r of Ot){let a=Ue(o,Math.min(t.maxEdge,r.edge)),i=Nt(n,a,r.quality,t);if(i)return{dataUrl:i,region:"element"}}return null}function He(e,t){return t.enabled?new Promise(n=>{let o=!1,r=i=>{o||(o=!0,n(i))},a=setTimeout(()=>r(null),t.timeoutMs);a.unref?.(),Promise.resolve().then(()=>De(e,t)).then(r,()=>r(null)).finally(()=>clearTimeout(a))}):Promise.resolve(null)}async function Q(e,t,n){let o;try{o=await He(t,n)}catch{o=null}return o?{...e,screenshot:o}:e}var It={consoleErrors:[],failedRequests:[],featureFlags:{}},ot=()=>({...It});function he(e){let t=e.parentOrigin===void 0?null:D(e.parentOrigin),n=window,o=n.document,r=ge(e.screenshot,o),a=!1,i=null,c=0,m=null,g=!1,h=e.transport??(t===null?null:me(t,n));if(h===null)throw new Error("[annotation] the SDK needs a `transport` or a `parentOrigin`; with neither there is nowhere for a capture to go and every one of them would be lost in silence.");let p=fe(h,e.onEgressError),d=l=>{let u=l.getBoundingClientRect();return{x:u.x,y:u.y,w:u.width,h:u.height}},T=l=>pe(l,{boundingBox:d(l)}),x=l=>{if(l.componentName&&l.source){let u=l.source.file.split("/").pop()??l.source.file;return`${l.componentName} \xB7 ${u}:${l.source.line}`}return l.source?`${l.source.file}:${l.source.line}`:l.componentName??null},A=l=>{!a||g||c||(c=n.requestAnimationFrame(()=>{c=0;let u=o.elementFromPoint(l.clientX,l.clientY);if(!u||i&&i.contains(u)||e.ignoreElement?.(u)||u===m)return;m=u;let b=T(u);i?.show(b.boundingBox,x(b)),p({type:"annotate:hover",target:b})}))},R=(l,u)=>({schemaVersion:1,capturedAt:new Date().toISOString(),build:e.build,page:{url:n.location.href,route:e.getRoute(),viewport:{w:n.innerWidth,h:n.innerHeight,dpr:n.devicePixelRatio},userAgent:n.navigator.userAgent},target:T(l),state:{consoleErrors:u.consoleErrors,failedRequests:u.failedRequests,featureFlags:u.featureFlags},comment:""}),N=l=>{let u={type:"annotate:capture",payload:l},b=()=>{p(u).then(O=>e.onCaptureResult?.(O,b))};b()},k=l=>{if(!a)return;let u=l.target;if(!(u instanceof Element)||e.ignoreElement?.(u)||(l.preventDefault(),l.stopPropagation(),g))return;let b=R(u,e.getState()),O=e.collectComment;if(!O){if(!r.enabled){N(b);return}Q(b,u,r).then(S=>N(S),()=>N(b));return}let B={x:l.clientX,y:l.clientY},$=r.enabled?Q(b,u,r).then(S=>S,()=>b):Promise.resolve(b),I=()=>{g=!0;let S=null,oe=O({target:b.target,point:B}).then(E=>E,E=>(S={error:E},null));Promise.all([$,oe]).then(([E,U])=>{if(g=!1,S!==null){e.onCaptureResult?.({status:"failed",error:S.error},I);return}U!==null&&N(U===""?E:{...E,comment:U})})};I()},P=l=>{!a||g||l.key!=="Escape"||(p({type:"annotate:cancel"}),_())};function F(){a||(a=!0,i??(i=ce(o)),o.addEventListener("mousemove",A,!0),o.addEventListener("click",k,!0),o.addEventListener("keydown",P,!0))}function _(){a&&(a=!1,m=null,c&&(n.cancelAnimationFrame(c),c=0),o.removeEventListener("mousemove",A,!0),o.removeEventListener("click",k,!0),o.removeEventListener("keydown",P,!0),i?.hide())}let v=l=>{if(l.origin===t&&ae(l.data))switch(l.data.type){case"annotate:enable":F();break;case"annotate:disable":_();break;case"annotate:ping":p({type:"annotate:ready",sdkVersion:"1",build:e.build});break}};return t!==null&&n.addEventListener("message",v),p({type:"annotate:ready",sdkVersion:"1",build:e.build}),{enable:F,disable:_,isEnabled:()=>a,destroy(){_(),t!==null&&n.removeEventListener("message",v),i?.destroy(),i=null}}}var ee="ai.annotation.capture",te="ai.annotation.run",rt=[...Y,V,j];function w(e,t){try{return e()}catch{return t}}function Lt(e){return w(()=>e?.sessionStorage??null,null)}function at(e={}){let t=e.doc??document,n=t.defaultView??null,o=e.storage===void 0?Lt(n):e.storage,r=e.url??t.URL,a=w(()=>new URL(r),null),i=null,c=null;if(a!==null&&(i=a.searchParams.get(V)||null,c=a.searchParams.get(j)||null,rt.some(p=>a.searchParams.has(p)))){for(let d of rt)a.searchParams.delete(d);let p=e.history??n?.history;w(()=>{p?.replaceState(n?.history?.state??null,"",a.toString())},void 0)}let m=()=>{for(let h of z)w(()=>{t.cookie=se(h)},void 0);o&&(w(()=>o.removeItem(ee),void 0),w(()=>o.removeItem(te),void 0))},g=le(w(()=>t.cookie,""));return g?(o&&(i!==null?w(()=>o.setItem(ee,i),void 0):i=w(()=>o.getItem(ee),null),c!==null?w(()=>o.setItem(te,c),void 0):c=w(()=>o.getItem(te),null)),{armed:g,captureToken:i,runId:c,disarm:m}):{armed:!1,captureToken:null,runId:null,disarm:m}}var Pt=["preview","staging","development"];function be(e){return Pt.includes(e.env)}var Ke={region:"Annotation",expand:"Open the annotation toolbar",collapse:"Close the annotation toolbar",start:"Start annotating",stop:"Stop annotating",done:"Done",comment:"What is wrong here?",placeholder:"The heading wraps onto three lines on mobile\u2026",send:"Send",cancel:"Cancel",sent:"Sent",issue:"View issue",failed:"That did not send",retry:"Retry"},Be="ai-annotation-toolbar",Ft="2147483001",st=288,it=190,H=12,Ut=`
2
2
  :host{
3
3
  --ai-bg:#fff;
4
4
  --ai-fg:#18181b;
@@ -61,5 +61,5 @@ textarea:focus-visible{outline:2px solid var(--ai-accent);outline-offset:1px}
61
61
  .toast a{color:var(--ai-invert-fg)}
62
62
  .toast button{background:transparent;border-color:var(--ai-invert-line);
63
63
  color:var(--ai-invert-fg)}
64
- `;function m(e,t,n){let o=e.createElement(t);if(n)for(let r of Object.keys(n))o.setAttribute(r,n[r]??"");return o}function $e(e={}){let t={...Ke,...e.labels},n=e.doc??document,o=e.win??window;if(e.armed===!1)return{owns:()=>!1,attach:()=>{},collectComment:()=>Promise.resolve(""),showResult:()=>{},isExpanded:()=>!1,destroy:()=>{}};let r=m(n,"div",{id:Be}),a=r.attachShadow({mode:"open"}),i=m(n,"style");i.textContent=Ut,a.appendChild(i);let c=m(n,"style");a.appendChild(c);let f=m(n,"div",{id:"ai-annotation-bar",class:"bar",role:"region","aria-label":t.region}),h=m(n,"div",{class:"panel",id:"ai-annotation-panel",hidden:""}),g=m(n,"button",{type:"button",id:"ai-annotation-toggle",class:"toggle","aria-pressed":"false"});g.textContent=t.start;let p=m(n,"button",{type:"button",id:"ai-annotation-done"});p.textContent=t.done,h.appendChild(g),h.appendChild(p);let d=m(n,"button",{type:"button",id:"ai-annotation-pill",class:"pill","aria-expanded":"false","aria-controls":"ai-annotation-panel","aria-label":t.expand}),T=m(n,"span",{class:"dot","aria-hidden":"true"}),x=m(n,"span");x.textContent=t.region,d.appendChild(T),d.appendChild(x),f.appendChild(d),f.appendChild(h),a.appendChild(f);let A=m(n,"div",{id:"ai-annotation-composer",class:"composer",role:"dialog","aria-modal":"false","aria-labelledby":"ai-annotation-comment",hidden:""}),R=m(n,"p",{class:"where"}),N=m(n,"label",{id:"ai-annotation-comment",for:"ai-annotation-input"});N.textContent=t.comment;let k=m(n,"textarea",{id:"ai-annotation-input",placeholder:t.placeholder,rows:"3"}),P=m(n,"button",{type:"button",id:"ai-annotation-cancel"});P.textContent=t.cancel;let F=m(n,"button",{type:"button",id:"ai-annotation-send",class:"primary"});F.textContent=t.send;let _=m(n,"div",{class:"row"});_.appendChild(P),_.appendChild(F),A.appendChild(R),A.appendChild(N),A.appendChild(k),A.appendChild(_),a.appendChild(A);let v=m(n,"div",{id:"ai-annotation-toast",class:"toast",role:"status",hidden:""}),l=m(n,"span"),u=m(n,"a",{id:"ai-annotation-issue",target:"_blank",rel:"noopener noreferrer",hidden:""}),b=m(n,"button",{type:"button",id:"ai-annotation-retry",hidden:""});b.textContent=t.retry,v.appendChild(l),v.appendChild(u),v.appendChild(b),a.appendChild(v),n.body.appendChild(r);let O=null,B=!1,$=null,I=null,S=null,oe=()=>{},E=(s,y)=>{y?s.removeAttribute("hidden"):s.setAttribute("hidden","")},U=s=>{B=s,E(h,s),d.setAttribute("aria-expanded",String(s)),d.setAttribute("aria-label",s?t.collapse:t.expand)},Ae=s=>{g.setAttribute("aria-pressed",String(s)),g.textContent=s?t.stop:t.start,f.setAttribute("class",s?"bar on":"bar"),s?O?.enable():O?.disable()};d.addEventListener("click",()=>U(!B)),g.addEventListener("click",()=>{Ae(O?.isEnabled()!==!0)});let We=()=>{S!==null&&clearTimeout(S),q(null),r.remove()};p.addEventListener("click",()=>{Ae(!1),U(!1),e.onDone?.(),We()});let q=s=>{let y=$;$=null,E(A,!1),y&&y(s),I instanceof HTMLElement&&I.focus(),I=null};P.addEventListener("click",()=>q(null)),F.addEventListener("click",()=>q(k.value)),A.addEventListener("keydown",s=>{if(s.key==="Escape"){s.stopPropagation(),q(null);return}s.key==="Enter"&&(s.metaKey||s.ctrlKey)&&(s.preventDefault(),q(k.value))});let pt=s=>new Promise(y=>{$=y,k.value="",R.textContent=mt(s),ft(s),E(v,!1),E(A,!0),I=n.activeElement,k.focus()});function mt(s){let{source:y,componentName:C}=s.target;return y?`${y.file}:${y.line}`:C??""}function ft(s){let y=s.target.boundingBox,C=y.y+y.h+H,X=C+it<=o.innerHeight?C:Math.max(H,y.y-it-H),ht=Math.min(Math.max(H,y.x),Math.max(H,o.innerWidth-st-H));c.textContent=`.composer{left:${Math.round(ht)}px;top:${Math.round(X)}px}`}let gt=(s,y)=>{S!==null&&clearTimeout(S);let C=s.status==="sent",X=s.status==="sent"?J(s.receipt.issueUrl):void 0;v.setAttribute("class",C?"toast":"toast bad"),v.setAttribute("role",C?"status":"alert"),l.textContent=C?t.sent:t.failed,E(u,C&&X!==void 0),X!==void 0&&(u.setAttribute("href",X),u.textContent=t.issue),E(b,!C),E(v,!0),C&&(S=setTimeout(()=>E(v,!1),6e3)),oe=y};return b.addEventListener("click",()=>{E(v,!1),oe()}),{owns:s=>s instanceof Node&&(s===r||r.contains(s)),attach:s=>{O=s,Ae(s.isEnabled())},collectComment:pt,showResult:gt,isExpanded:()=>B,destroy:We}}function lt(e){let t=e.toolbar?.armed;if(e.arming&&t!==void 0)throw new Error("[annotation] pass `arming` OR `toolbar.armed`, not both; two answers to whether this page may offer an annotation UI is how one of them stops being checked.");let n=(e.arming?e.arming.armed:t)!==!1&&be(e.build),o=$e({...e.toolbar,armed:n,onDone:()=>{e.arming?.disarm(),r.destroy(),e.toolbar?.onDone?.()}}),r=he({...e,collectComment:o.collectComment,onCaptureResult:o.showResult,ignoreElement:o.owns});return o.attach(r),{sdk:r,toolbar:o,destroy(){o.destroy(),r.destroy()}}}var ct=20;var M,ne,K=class{constructor(t=20){Te(this,M,[]);Te(this,ne);Ye(this,ne,Math.max(1,t))}push(t){L(this,M).push(t),L(this,M).length>L(this,ne)&&L(this,M).shift()}toArray(){return[...L(this,M)]}get size(){return L(this,M).length}};M=new WeakMap,ne=new WeakMap;function qe(e){if(typeof e=="string")return e;if(e instanceof Error)return`${e.name}: ${e.message}`;if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="object")try{return JSON.stringify(e)??String(e)}catch{try{return`[${Object.getPrototypeOf(e)?.constructor?.name??"object"}]`}catch{return"[object]"}}try{return String(e)}catch{return"[unrenderable]"}}var ut=(e,t)=>e.length>t?`${e.slice(0,t-1)}\u2026`:e;function Xe(e){return ut(e.map(qe).join(" "),500)}function ye(e){for(let t of e)if(t instanceof Error&&typeof t.stack=="string")return ut(t.stack,2e3)}function Ee(e){return e===0||e<200||e>=300}var Ge=()=>({limit:20,getFeatureFlags:()=>({}),now:()=>new Date().toISOString()});function dt(e,t=Ge()){let n=new K(t.limit),o=new K(t.limit),r=(p,d)=>{n.push({level:p,message:Xe(d),...ye(d)?{stack:ye(d)}:{},at:t.now()})},a=e.console.error,i=e.console.warn;e.console.error=function(...d){try{r("error",d)}catch{}return a.apply(e.console,d)},e.console.warn=function(...d){try{r("warn",d)}catch{}return i.apply(e.console,d)};let c=e.fetch,f=(p,d)=>{let T=typeof p=="string"?p:p instanceof URL?p.href:p?.url??String(p),x=d?.method??p?.method??"GET";return{url:T,method:x.toUpperCase()}};typeof c=="function"&&(e.fetch=async function(d,T){try{let x=await c.call(e,d,T);if(Ee(x.status)){let{url:A,method:R}=f(d,T);o.push({url:A,method:R,status:x.status,at:t.now()})}return x}catch(x){let{url:A,method:R}=f(d,T);throw o.push({url:A,method:R,status:0,at:t.now()}),x}});let h=e.XMLHttpRequest,g=h?.prototype?.open;return typeof g=="function"&&(h.prototype.open=function(d,T,...x){return this.__aiAnnotateMethod=d.toUpperCase(),this.__aiAnnotateUrl=String(T),this.addEventListener("loadend",()=>{try{Ee(this.status)&&o.push({url:this.__aiAnnotateUrl??"",method:this.__aiAnnotateMethod??"GET",status:this.status,at:t.now()})}catch{}}),g.apply(this,[d,T,...x])}),{getState(){return{consoleErrors:n.toArray(),failedRequests:o.toArray(),featureFlags:t.getFeatureFlags()}},destroy(){e.console.error=a,e.console.warn=i,typeof c=="function"&&(e.fetch=c),typeof g=="function"&&(h.prototype.open=g)}}}
64
+ `;function f(e,t,n){let o=e.createElement(t);if(n)for(let r of Object.keys(n))o.setAttribute(r,n[r]??"");return o}function $e(e={}){let t={...Ke,...e.labels},n=e.doc??document,o=e.win??window;if(e.armed===!1)return{owns:()=>!1,attach:()=>{},collectComment:()=>Promise.resolve(""),showResult:()=>{},isExpanded:()=>!1,destroy:()=>{}};let r=f(n,"div",{id:Be}),a=r.attachShadow({mode:"open"}),i=f(n,"style");i.textContent=Ut,a.appendChild(i);let c=f(n,"style");a.appendChild(c);let m=f(n,"div",{id:"ai-annotation-bar",class:"bar",role:"region","aria-label":t.region}),g=f(n,"div",{class:"panel",id:"ai-annotation-panel",hidden:""}),h=f(n,"button",{type:"button",id:"ai-annotation-toggle",class:"toggle","aria-pressed":"false"});h.textContent=t.start;let p=f(n,"button",{type:"button",id:"ai-annotation-done"});p.textContent=t.done,g.appendChild(h),g.appendChild(p);let d=f(n,"button",{type:"button",id:"ai-annotation-pill",class:"pill","aria-expanded":"false","aria-controls":"ai-annotation-panel","aria-label":t.expand}),T=f(n,"span",{class:"dot","aria-hidden":"true"}),x=f(n,"span");x.textContent=t.region,d.appendChild(T),d.appendChild(x),m.appendChild(d),m.appendChild(g),a.appendChild(m);let A=f(n,"div",{id:"ai-annotation-composer",class:"composer",role:"dialog","aria-modal":"false","aria-labelledby":"ai-annotation-comment",hidden:""}),R=f(n,"p",{class:"where"}),N=f(n,"label",{id:"ai-annotation-comment",for:"ai-annotation-input"});N.textContent=t.comment;let k=f(n,"textarea",{id:"ai-annotation-input",placeholder:t.placeholder,rows:"3"}),P=f(n,"button",{type:"button",id:"ai-annotation-cancel"});P.textContent=t.cancel;let F=f(n,"button",{type:"button",id:"ai-annotation-send",class:"primary"});F.textContent=t.send;let _=f(n,"div",{class:"row"});_.appendChild(P),_.appendChild(F),A.appendChild(R),A.appendChild(N),A.appendChild(k),A.appendChild(_),a.appendChild(A);let v=f(n,"div",{id:"ai-annotation-toast",class:"toast",role:"status",hidden:""}),l=f(n,"span"),u=f(n,"a",{id:"ai-annotation-issue",target:"_blank",rel:"noopener noreferrer",hidden:""}),b=f(n,"button",{type:"button",id:"ai-annotation-retry",hidden:""});b.textContent=t.retry,v.appendChild(l),v.appendChild(u),v.appendChild(b),a.appendChild(v),n.body.appendChild(r);let O=null,B=!1,$=null,I=null,S=null,oe=()=>{},E=(s,y)=>{y?s.removeAttribute("hidden"):s.setAttribute("hidden","")},U=s=>{B=s,E(g,s),d.setAttribute("aria-expanded",String(s)),d.setAttribute("aria-label",s?t.collapse:t.expand)},Ae=s=>{h.setAttribute("aria-pressed",String(s)),h.textContent=s?t.stop:t.start,m.setAttribute("class",s?"bar on":"bar"),s?O?.enable():O?.disable()};d.addEventListener("click",()=>U(!B)),h.addEventListener("click",()=>{Ae(O?.isEnabled()!==!0)});let We=()=>{S!==null&&clearTimeout(S),q(null),r.remove()};p.addEventListener("click",()=>{Ae(!1),U(!1),e.onDone?.(),We()});let q=s=>{let y=$;$=null,E(A,!1),y&&y(s),I instanceof HTMLElement&&I.focus(),I=null};P.addEventListener("click",()=>q(null)),F.addEventListener("click",()=>q(k.value)),A.addEventListener("keydown",s=>{if(s.key==="Escape"){s.stopPropagation(),q(null);return}s.key==="Enter"&&(s.metaKey||s.ctrlKey)&&(s.preventDefault(),q(k.value))});let pt=s=>new Promise(y=>{$=y,k.value="",R.textContent=mt(s),ft(s),E(v,!1),E(A,!0),I=n.activeElement,k.focus()});function mt(s){let{source:y,componentName:C}=s.target;return y?`${y.file}:${y.line}`:C??""}function ft(s){let y=s.target.boundingBox,C=y.y+y.h+H,X=C+it<=o.innerHeight?C:Math.max(H,y.y-it-H),ht=Math.min(Math.max(H,y.x),Math.max(H,o.innerWidth-st-H));c.textContent=`.composer{left:${Math.round(ht)}px;top:${Math.round(X)}px}`}let gt=(s,y)=>{S!==null&&clearTimeout(S);let C=s.status==="sent",X=s.status==="sent"?J(s.receipt.issueUrl):void 0;v.setAttribute("class",C?"toast":"toast bad"),v.setAttribute("role",C?"status":"alert"),l.textContent=C?t.sent:t.failed,E(u,C&&X!==void 0),X!==void 0&&(u.setAttribute("href",X),u.textContent=t.issue),E(b,!C),E(v,!0),C&&(S=setTimeout(()=>E(v,!1),6e3)),oe=y};return b.addEventListener("click",()=>{E(v,!1),oe()}),{owns:s=>s instanceof Node&&(s===r||r.contains(s)),attach:s=>{O=s,Ae(s.isEnabled())},collectComment:pt,showResult:gt,isExpanded:()=>B,destroy:We}}function lt(e){let t=e.toolbar?.armed;if(e.arming&&t!==void 0)throw new Error("[annotation] pass `arming` OR `toolbar.armed`, not both; two answers to whether this page may offer an annotation UI is how one of them stops being checked.");let n=(e.arming?e.arming.armed:t)!==!1&&be(e.build),o=$e({...e.toolbar,armed:n,onDone:()=>{e.arming?.disarm(),r.destroy(),e.toolbar?.onDone?.()}}),r=he({...e,collectComment:o.collectComment,onCaptureResult:o.showResult,ignoreElement:o.owns});return o.attach(r),{sdk:r,toolbar:o,destroy(){o.destroy(),r.destroy()}}}var ct=20;var M,ne,K=class{constructor(t=20){Te(this,M,[]);Te(this,ne);Ye(this,ne,Math.max(1,t))}push(t){L(this,M).push(t),L(this,M).length>L(this,ne)&&L(this,M).shift()}toArray(){return[...L(this,M)]}get size(){return L(this,M).length}};M=new WeakMap,ne=new WeakMap;function qe(e){if(typeof e=="string")return e;if(e instanceof Error)return`${e.name}: ${e.message}`;if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="object")try{return JSON.stringify(e)??String(e)}catch{try{return`[${Object.getPrototypeOf(e)?.constructor?.name??"object"}]`}catch{return"[object]"}}try{return String(e)}catch{return"[unrenderable]"}}var ut=(e,t)=>e.length>t?`${e.slice(0,t-1)}\u2026`:e;function Xe(e){return ut(e.map(qe).join(" "),500)}function ye(e){for(let t of e)if(t instanceof Error&&typeof t.stack=="string")return ut(t.stack,2e3)}function Ee(e){return e===0||e<200||e>=300}var Ge=()=>({limit:20,getFeatureFlags:()=>({}),now:()=>new Date().toISOString()});function dt(e,t=Ge()){let n=new K(t.limit),o=new K(t.limit),r=(p,d)=>{n.push({level:p,message:Xe(d),...ye(d)?{stack:ye(d)}:{},at:t.now()})},a=e.console.error,i=e.console.warn;e.console.error=function(...d){try{r("error",d)}catch{}return a.apply(e.console,d)},e.console.warn=function(...d){try{r("warn",d)}catch{}return i.apply(e.console,d)};let c=e.fetch,m=(p,d)=>{let T=typeof p=="string"?p:p instanceof URL?p.href:p?.url??String(p),x=d?.method??p?.method??"GET";return{url:T,method:x.toUpperCase()}};typeof c=="function"&&(e.fetch=async function(d,T){try{let x=await c.call(e,d,T);if(Ee(x.status)){let{url:A,method:R}=m(d,T);o.push({url:A,method:R,status:x.status,at:t.now()})}return x}catch(x){let{url:A,method:R}=m(d,T);throw o.push({url:A,method:R,status:0,at:t.now()}),x}});let g=e.XMLHttpRequest,h=g?.prototype?.open;return typeof h=="function"&&(g.prototype.open=function(d,T,...x){return this.__aiAnnotateMethod=d.toUpperCase(),this.__aiAnnotateUrl=String(T),this.addEventListener("loadend",()=>{try{Ee(this.status)&&o.push({url:this.__aiAnnotateUrl??"",method:this.__aiAnnotateMethod??"GET",status:this.status,at:t.now()})}catch{}}),h.apply(this,[d,T,...x])}),{getState(){return{consoleErrors:n.toArray(),failedRequests:o.toArray(),featureFlags:t.getFeatureFlags()}},destroy(){e.console.error=a,e.console.warn=i,typeof c=="function"&&(e.fetch=c),typeof h=="function"&&(g.prototype.open=h)}}}
65
65
  //# sourceMappingURL=index.cjs.map