@weatherboard/annotation 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -26,9 +26,12 @@
26
26
  * exactly one consumer in one repository; a published package with a hundred
27
27
  * has to make the two halves separately installable or the split is decorative.
28
28
  */
29
- export { createAnnotationSdk, emptyAnnotationState, type AnnotationSdk, type AnnotationSdkOptions, type AnnotationState, } from "./sdk.cjs";
29
+ export { createAnnotationSdk, emptyAnnotationState, type AnnotationSdk, type AnnotationSdkOptions, type AnnotationState, type CommentCollector, type CommentRequest, } from "./sdk.cjs";
30
+ export { assertConcreteEndpoint, createEgress, httpTransport, postMessageTransport, safeIssueUrl, HTTP_TRANSPORT_TIMEOUT_MS, type AnnotationTransport, type EgressErrorHandler, type EgressFailure, type EgressOutcome, type FetchLike, type FrameMessageKind, type HttpTransportOptions, type SendReceipt, } from "./transport.cjs";
31
+ export { createAnnotationToolbar, mountAnnotation, DEFAULT_LABELS, TOOLBAR_ID, type AnnotationToolbar, type AnnotationToolbarLabels, type AnnotationToolbarOptions, type MountAnnotationOptions, type MountedAnnotation, } from "./toolbar.cjs";
32
+ export { isAnnotatableBuild, readArming, CAPTURE_TOKEN_STORAGE_KEY, REVIEW_RUN_STORAGE_KEY, type Arming, type ArmingOptions, type StorageLike, } from "./arming.cjs";
30
33
  export { createOverlay, OVERLAY_ID, type Overlay } from "./overlay.cjs";
31
34
  export { attachScreenshot, captureScreenshot, captureScreenshotSync, resolveScreenshotOptions, findCaptureSource, isMediaElement, intrinsicSize, fitWithin, MAX_SCREENSHOT_BYTES, MAX_SCREENSHOT_EDGE, SCREENSHOT_TIMEOUT_MS, type CanvasLike, type CanvasContextLike, type CaptureCandidate, type Screenshot, type ScreenshotOptions, } from "./screenshot.cjs";
32
35
  export { installStateCollector, defaultStateCollectorOptions, RingBuffer, describeArg, formatConsoleArgs, firstStack, isFailedStatus, DEFAULT_LIMIT, type StateCollector, type StateCollectorOptions, } from "./state.cjs";
33
36
  export { parseSourceRef, collectSourceChain, findAnnotatedAncestor, domPath, summariseText, resolveTarget, SRC_ATTR, NAME_ATTR, MAX_TEXT, MAX_CHAIN, type ElementLike, } from "./target.cjs";
34
- export { ANNOTATION_ARMED_COOKIE, ANNOTATION_ARMED_COOKIES, ANNOTATION_TOKEN_PARAM, ANNOTATION_TOKEN_PARAMS, isAnnotationArmed, LEGACY_ANNOTATION_ARMED_COOKIE, LEGACY_ANNOTATION_TOKEN_PARAM, readAnnotationToken, SDK_VERSION, isParentMessage, assertConcreteOrigin, type AnnotationPayload, type BuildInfo, type ConsoleEntry, type FrameToParent, type NetworkEntry, type ParentToFrame, type SourceRef, type TargetInfo, } from "./protocol.cjs";
37
+ export { ANNOTATION_ARMED_COOKIE, ANNOTATION_ARMED_COOKIES, ANNOTATION_TOKEN_PARAM, ANNOTATION_ARMED_VALUE, ANNOTATION_TOKEN_PARAMS, armedCookie, CAPTURE_TOKEN_PARAM, clearedCookie, isAnnotationArmed, REVIEW_RUN_PARAM, LEGACY_ANNOTATION_ARMED_COOKIE, LEGACY_ANNOTATION_TOKEN_PARAM, readAnnotationToken, selectionOf, SDK_VERSION, isParentMessage, assertConcreteOrigin, type AnnotationPayload, type BuildInfo, type ConsoleEntry, type FrameToParent, type NetworkEntry, type ParentToFrame, type SourceRef, type TargetInfo, } from "./protocol.cjs";
package/dist/index.d.mts CHANGED
@@ -26,9 +26,12 @@
26
26
  * exactly one consumer in one repository; a published package with a hundred
27
27
  * has to make the two halves separately installable or the split is decorative.
28
28
  */
29
- export { createAnnotationSdk, emptyAnnotationState, type AnnotationSdk, type AnnotationSdkOptions, type AnnotationState, } from "./sdk.mjs";
29
+ export { createAnnotationSdk, emptyAnnotationState, type AnnotationSdk, type AnnotationSdkOptions, type AnnotationState, type CommentCollector, type CommentRequest, } from "./sdk.mjs";
30
+ export { assertConcreteEndpoint, createEgress, httpTransport, postMessageTransport, safeIssueUrl, HTTP_TRANSPORT_TIMEOUT_MS, type AnnotationTransport, type EgressErrorHandler, type EgressFailure, type EgressOutcome, type FetchLike, type FrameMessageKind, type HttpTransportOptions, type SendReceipt, } from "./transport.mjs";
31
+ export { createAnnotationToolbar, mountAnnotation, DEFAULT_LABELS, TOOLBAR_ID, type AnnotationToolbar, type AnnotationToolbarLabels, type AnnotationToolbarOptions, type MountAnnotationOptions, type MountedAnnotation, } from "./toolbar.mjs";
32
+ export { isAnnotatableBuild, readArming, CAPTURE_TOKEN_STORAGE_KEY, REVIEW_RUN_STORAGE_KEY, type Arming, type ArmingOptions, type StorageLike, } from "./arming.mjs";
30
33
  export { createOverlay, OVERLAY_ID, type Overlay } from "./overlay.mjs";
31
34
  export { attachScreenshot, captureScreenshot, captureScreenshotSync, resolveScreenshotOptions, findCaptureSource, isMediaElement, intrinsicSize, fitWithin, MAX_SCREENSHOT_BYTES, MAX_SCREENSHOT_EDGE, SCREENSHOT_TIMEOUT_MS, type CanvasLike, type CanvasContextLike, type CaptureCandidate, type Screenshot, type ScreenshotOptions, } from "./screenshot.mjs";
32
35
  export { installStateCollector, defaultStateCollectorOptions, RingBuffer, describeArg, formatConsoleArgs, firstStack, isFailedStatus, DEFAULT_LIMIT, type StateCollector, type StateCollectorOptions, } from "./state.mjs";
33
36
  export { parseSourceRef, collectSourceChain, findAnnotatedAncestor, domPath, summariseText, resolveTarget, SRC_ATTR, NAME_ATTR, MAX_TEXT, MAX_CHAIN, type ElementLike, } from "./target.mjs";
34
- export { ANNOTATION_ARMED_COOKIE, ANNOTATION_ARMED_COOKIES, ANNOTATION_TOKEN_PARAM, ANNOTATION_TOKEN_PARAMS, isAnnotationArmed, LEGACY_ANNOTATION_ARMED_COOKIE, LEGACY_ANNOTATION_TOKEN_PARAM, readAnnotationToken, SDK_VERSION, isParentMessage, assertConcreteOrigin, type AnnotationPayload, type BuildInfo, type ConsoleEntry, type FrameToParent, type NetworkEntry, type ParentToFrame, type SourceRef, type TargetInfo, } from "./protocol.mjs";
37
+ export { ANNOTATION_ARMED_COOKIE, ANNOTATION_ARMED_COOKIES, ANNOTATION_TOKEN_PARAM, ANNOTATION_ARMED_VALUE, ANNOTATION_TOKEN_PARAMS, armedCookie, CAPTURE_TOKEN_PARAM, clearedCookie, isAnnotationArmed, REVIEW_RUN_PARAM, LEGACY_ANNOTATION_ARMED_COOKIE, LEGACY_ANNOTATION_TOKEN_PARAM, readAnnotationToken, selectionOf, SDK_VERSION, isParentMessage, assertConcreteOrigin, type AnnotationPayload, type BuildInfo, type ConsoleEntry, type FrameToParent, type NetworkEntry, type ParentToFrame, type SourceRef, type TargetInfo, } from "./protocol.mjs";
package/dist/index.d.ts CHANGED
@@ -26,9 +26,12 @@
26
26
  * exactly one consumer in one repository; a published package with a hundred
27
27
  * has to make the two halves separately installable or the split is decorative.
28
28
  */
29
- export { createAnnotationSdk, emptyAnnotationState, type AnnotationSdk, type AnnotationSdkOptions, type AnnotationState, } from "./sdk.js";
29
+ export { createAnnotationSdk, emptyAnnotationState, type AnnotationSdk, type AnnotationSdkOptions, type AnnotationState, type CommentCollector, type CommentRequest, } from "./sdk.js";
30
+ export { assertConcreteEndpoint, createEgress, httpTransport, postMessageTransport, safeIssueUrl, HTTP_TRANSPORT_TIMEOUT_MS, type AnnotationTransport, type EgressErrorHandler, type EgressFailure, type EgressOutcome, type FetchLike, type FrameMessageKind, type HttpTransportOptions, type SendReceipt, } from "./transport.js";
31
+ export { createAnnotationToolbar, mountAnnotation, DEFAULT_LABELS, TOOLBAR_ID, type AnnotationToolbar, type AnnotationToolbarLabels, type AnnotationToolbarOptions, type MountAnnotationOptions, type MountedAnnotation, } from "./toolbar.js";
32
+ export { isAnnotatableBuild, readArming, CAPTURE_TOKEN_STORAGE_KEY, REVIEW_RUN_STORAGE_KEY, type Arming, type ArmingOptions, type StorageLike, } from "./arming.js";
30
33
  export { createOverlay, OVERLAY_ID, type Overlay } from "./overlay.js";
31
34
  export { attachScreenshot, captureScreenshot, captureScreenshotSync, resolveScreenshotOptions, findCaptureSource, isMediaElement, intrinsicSize, fitWithin, MAX_SCREENSHOT_BYTES, MAX_SCREENSHOT_EDGE, SCREENSHOT_TIMEOUT_MS, type CanvasLike, type CanvasContextLike, type CaptureCandidate, type Screenshot, type ScreenshotOptions, } from "./screenshot.js";
32
35
  export { installStateCollector, defaultStateCollectorOptions, RingBuffer, describeArg, formatConsoleArgs, firstStack, isFailedStatus, DEFAULT_LIMIT, type StateCollector, type StateCollectorOptions, } from "./state.js";
33
36
  export { parseSourceRef, collectSourceChain, findAnnotatedAncestor, domPath, summariseText, resolveTarget, SRC_ATTR, NAME_ATTR, MAX_TEXT, MAX_CHAIN, type ElementLike, } from "./target.js";
34
- export { ANNOTATION_ARMED_COOKIE, ANNOTATION_ARMED_COOKIES, ANNOTATION_TOKEN_PARAM, ANNOTATION_TOKEN_PARAMS, isAnnotationArmed, LEGACY_ANNOTATION_ARMED_COOKIE, LEGACY_ANNOTATION_TOKEN_PARAM, readAnnotationToken, SDK_VERSION, isParentMessage, assertConcreteOrigin, type AnnotationPayload, type BuildInfo, type ConsoleEntry, type FrameToParent, type NetworkEntry, type ParentToFrame, type SourceRef, type TargetInfo, } from "./protocol.js";
37
+ export { ANNOTATION_ARMED_COOKIE, ANNOTATION_ARMED_COOKIES, ANNOTATION_TOKEN_PARAM, ANNOTATION_ARMED_VALUE, ANNOTATION_TOKEN_PARAMS, armedCookie, CAPTURE_TOKEN_PARAM, clearedCookie, isAnnotationArmed, REVIEW_RUN_PARAM, LEGACY_ANNOTATION_ARMED_COOKIE, LEGACY_ANNOTATION_TOKEN_PARAM, readAnnotationToken, selectionOf, SDK_VERSION, isParentMessage, assertConcreteOrigin, type AnnotationPayload, type BuildInfo, type ConsoleEntry, type FrameToParent, type NetworkEntry, type ParentToFrame, type SourceRef, type TargetInfo, } from "./protocol.js";
package/dist/index.mjs CHANGED
@@ -1,2 +1,65 @@
1
- var B=e=>{throw TypeError(e)};var $=(e,t,n)=>t.has(e)||B("Cannot "+n);var y=(e,t,n)=>($(e,t,"read from private field"),n?n.call(e):t.get(e)),w=(e,t,n)=>t.has(e)?B("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),K=(e,t,n,r)=>($(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);var O="1",v="data-src",R="data-src-name",fe=new Set(["annotate:enable","annotate:disable","annotate:ping"]);function N(e){if(typeof e!="object"||e===null)return!1;let t=e.type;return typeof t=="string"&&fe.has(t)}function M(e){if(!e||e==="*")throw new Error("[annotation] a concrete parent origin is required; '*' would broadcast annotation payloads to any embedder.");return e}var G="ai_annotate",j="ai_annotate_armed",V="pits_annotate",W="pits_annotate_armed",Y=[G,V],J=[j,W];function me(e){return e.split(";").some(t=>{let n=t.trimStart();return J.some(r=>n.startsWith(`${r}=`))})}function he(e){for(let t of Y){let n=e.get(t);if(n!==null&&n.length>0)return n}return null}var Z="ai-annotation-overlay",ge="2147483000";function k(e){let t=e.createElement("div");t.id=Z,t.style.cssText=["position:fixed","top:0","left:0","pointer-events:none",`z-index:${ge}`,"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(r,o){t.style.display="block",t.style.transform=`translate(${r.x}px, ${r.y}px)`,t.style.width=`${r.w}px`,t.style.height=`${r.h}px`,n.style.top=r.y<20?"100%":"-20px",n.textContent=o??"",n.style.display=o?"block":"none"},hide(){t.style.display="none"},destroy(){t.remove()},contains(r){return r instanceof Node&&t.contains(r)}}}var I=200,z=8;function L(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 r=e.slice(0,n),o=Number(e.slice(n+1,t)),a=Number(e.slice(t+1));return!r||!Number.isFinite(o)||!Number.isFinite(a)?null:{file:r,line:o,column:a}}function Q(e,t=z){let n=[],r=e;for(;r&&n.length<t;){let o=L(r.getAttribute(v));if(o){let a=n[n.length-1];a&&a.file===o.file&&a.line===o.line||n.push(o)}r=r.parentElement}return n}function ee(e){let t=e;for(;t;){if(L(t.getAttribute(v)))return t;t=t.parentElement}return null}function ye(e){let t=e.classList;return(typeof t?.value=="string"?t.value:"").split(/\s+/).filter(Boolean)}function te(e,t=6){let n=[],r=e;for(;r&&n.length<t;){let o=(r.tagName||"").toLowerCase();if(!o||o==="html")break;let a=o;if(r.id)return n.unshift(`${o}#${r.id}`),n.join(" > ");let i=ye(r).slice(0,2);if(i.length>0&&(a+=`.${i.join(".")}`),n.unshift(a),o==="body")break;r=r.parentElement}return n.join(" > ")}function ne(e){if(!e)return;let t=e.replace(/\s+/g," ").trim();if(t)return t.length>I?`${t.slice(0,I-1)}\u2026`:t}function P(e,t){let n=ee(e),r=Q(e),o=r[0],a={domPath:te(e),boundingBox:t.boundingBox};o&&(a.source=o),r.length>0&&(a.sourceChain=r);let i=n?.getAttribute(R);i&&(a.componentName=i);let l=ne(e.textContent);return l&&(a.textContent=l),a}var Ee=49152,Ae=480,Se=250,be=[{edge:480,quality:.7},{edge:240,quality:.5}],xe=["image/webp","image/jpeg"];function F(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 Te=new Set(["IMG","CANVAS","VIDEO"]),Ce="img,canvas,video",Oe=4;function _(e){return!!e&&Te.has(e.tagName.toUpperCase())}function re(e,t=Oe){if(!e)return null;if(_(e))return e;let n=e.querySelector?.(Ce)??null;if(_(n))return n;let r=e.parentElement??null;for(let o=0;r&&o<t;o++){if(_(r))return r;r=r.parentElement??null}return null}function oe(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},r=Math.floor(n.w??0),o=Math.floor(n.h??0);return!Number.isFinite(r)||!Number.isFinite(o)||r<1||o<1||t==="IMG"&&e.complete===!1?null:{w:r,h:o}}function ae(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 ve(e,t,n,r){let o;try{o=r.createCanvas()}catch{return null}if(!o)return null;try{o.width=t.w,o.height=t.h;let a=o.getContext("2d");if(!a)return null;a.drawImage(e,0,0,t.w,t.h);for(let i of xe){let l;try{l=o.toDataURL(i,n)}catch{return null}if(!(typeof l!="string"||!l.startsWith(`data:${i}`)))return l.length<=r.maxBytes?l:null}return null}catch{return null}}function se(e,t){if(!t.enabled)return null;let n=re(e);if(!n)return null;let r=oe(n);if(!r)return null;for(let o of be){let a=ae(r,Math.min(t.maxEdge,o.edge)),i=ve(n,a,o.quality,t);if(i)return{dataUrl:i,region:"element"}}return null}function ie(e,t){return t.enabled?new Promise(n=>{let r=!1,o=i=>{r||(r=!0,n(i))},a=setTimeout(()=>o(null),t.timeoutMs);a.unref?.(),Promise.resolve().then(()=>se(e,t)).then(o,()=>o(null)).finally(()=>clearTimeout(a))}):Promise.resolve(null)}async function D(e,t,n){let r;try{r=await ie(t,n)}catch{r=null}return r?{...e,screenshot:r}:e}var _e={consoleErrors:[],failedRequests:[],featureFlags:{}},we=()=>({..._e});function Re(e){let t=M(e.parentOrigin),n=window,r=n.document,o=F(e.screenshot,r),a=!1,i=null,l=0,E=null,p=s=>{n.parent.postMessage(s,t)},A=s=>{let c=s.getBoundingClientRect();return{x:c.x,y:c.y,w:c.width,h:c.height}},d=s=>P(s,{boundingBox:A(s)}),u=s=>{if(s.componentName&&s.source){let c=s.source.file.split("/").pop()??s.source.file;return`${s.componentName} \xB7 ${c}:${s.source.line}`}return s.source?`${s.source.file}:${s.source.line}`:s.componentName??null},f=s=>{a&&(l||(l=n.requestAnimationFrame(()=>{l=0;let c=r.elementFromPoint(s.clientX,s.clientY);if(!c||i&&i.contains(c)||c===E)return;E=c;let g=d(c);i?.show(g.boundingBox,u(g)),p({type:"annotate:hover",target:g})})))},m=(s,c)=>({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:d(s),state:{consoleErrors:c.consoleErrors,failedRequests:c.failedRequests,featureFlags:c.featureFlags},comment:""}),S=s=>{if(!a)return;let c=s.target;if(!(c instanceof Element))return;s.preventDefault(),s.stopPropagation();let g=m(c,e.getState());if(!o.enabled){p({type:"annotate:capture",payload:g});return}D(g,c,o).then(pe=>p({type:"annotate:capture",payload:pe}),()=>p({type:"annotate:capture",payload:g}))},b=s=>{!a||s.key!=="Escape"||(p({type:"annotate:cancel"}),C())};function H(){a||(a=!0,i??(i=k(r)),r.addEventListener("mousemove",f,!0),r.addEventListener("click",S,!0),r.addEventListener("keydown",b,!0))}function C(){a&&(a=!1,E=null,l&&(n.cancelAnimationFrame(l),l=0),r.removeEventListener("mousemove",f,!0),r.removeEventListener("click",S,!0),r.removeEventListener("keydown",b,!0),i?.hide())}let U=s=>{if(s.origin===t&&N(s.data))switch(s.data.type){case"annotate:enable":H();break;case"annotate:disable":C();break;case"annotate:ping":p({type:"annotate:ready",sdkVersion:"1",build:e.build});break}};return n.addEventListener("message",U),p({type:"annotate:ready",sdkVersion:"1",build:e.build}),{enable:H,disable:C,isEnabled:()=>a,destroy(){C(),n.removeEventListener("message",U),i?.destroy(),i=null}}}var Ne=20;var h,T,x=class{constructor(t=20){w(this,h,[]);w(this,T);K(this,T,Math.max(1,t))}push(t){y(this,h).push(t),y(this,h).length>y(this,T)&&y(this,h).shift()}toArray(){return[...y(this,h)]}get size(){return y(this,h).length}};h=new WeakMap,T=new WeakMap;function le(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 ue=(e,t)=>e.length>t?`${e.slice(0,t-1)}\u2026`:e;function ce(e){return ue(e.map(le).join(" "),500)}function q(e){for(let t of e)if(t instanceof Error&&typeof t.stack=="string")return ue(t.stack,2e3)}function X(e){return e===0||e<200||e>=300}var de=()=>({limit:20,getFeatureFlags:()=>({}),now:()=>new Date().toISOString()});function Me(e,t=de()){let n=new x(t.limit),r=new x(t.limit),o=(d,u)=>{n.push({level:d,message:ce(u),...q(u)?{stack:q(u)}:{},at:t.now()})},a=e.console.error,i=e.console.warn;e.console.error=function(...u){try{o("error",u)}catch{}return a.apply(e.console,u)},e.console.warn=function(...u){try{o("warn",u)}catch{}return i.apply(e.console,u)};let l=e.fetch,E=(d,u)=>{let f=typeof d=="string"?d:d instanceof URL?d.href:d?.url??String(d),m=u?.method??d?.method??"GET";return{url:f,method:m.toUpperCase()}};typeof l=="function"&&(e.fetch=async function(u,f){try{let m=await l.call(e,u,f);if(X(m.status)){let{url:S,method:b}=E(u,f);r.push({url:S,method:b,status:m.status,at:t.now()})}return m}catch(m){let{url:S,method:b}=E(u,f);throw r.push({url:S,method:b,status:0,at:t.now()}),m}});let p=e.XMLHttpRequest,A=p?.prototype?.open;return typeof A=="function"&&(p.prototype.open=function(u,f,...m){return this.__aiAnnotateMethod=u.toUpperCase(),this.__aiAnnotateUrl=String(f),this.addEventListener("loadend",()=>{try{X(this.status)&&r.push({url:this.__aiAnnotateUrl??"",method:this.__aiAnnotateMethod??"GET",status:this.status,at:t.now()})}catch{}}),A.apply(this,[u,f,...m])}),{getState(){return{consoleErrors:n.toArray(),failedRequests:r.toArray(),featureFlags:t.getFeatureFlags()}},destroy(){e.console.error=a,e.console.warn=i,typeof l=="function"&&(e.fetch=l),typeof A=="function"&&(p.prototype.open=A)}}}export{j as ANNOTATION_ARMED_COOKIE,J as ANNOTATION_ARMED_COOKIES,G as ANNOTATION_TOKEN_PARAM,Y as ANNOTATION_TOKEN_PARAMS,Ne as DEFAULT_LIMIT,W as LEGACY_ANNOTATION_ARMED_COOKIE,V as LEGACY_ANNOTATION_TOKEN_PARAM,z as MAX_CHAIN,Ee as MAX_SCREENSHOT_BYTES,Ae as MAX_SCREENSHOT_EDGE,I as MAX_TEXT,R as NAME_ATTR,Z as OVERLAY_ID,x as RingBuffer,Se as SCREENSHOT_TIMEOUT_MS,O as SDK_VERSION,v as SRC_ATTR,M as assertConcreteOrigin,D as attachScreenshot,ie as captureScreenshot,se as captureScreenshotSync,Q as collectSourceChain,Re as createAnnotationSdk,k as createOverlay,de as defaultStateCollectorOptions,le as describeArg,te as domPath,we as emptyAnnotationState,ee as findAnnotatedAncestor,re as findCaptureSource,q as firstStack,ae as fitWithin,ce as formatConsoleArgs,Me as installStateCollector,oe as intrinsicSize,me as isAnnotationArmed,X as isFailedStatus,_ as isMediaElement,N as isParentMessage,L as parseSourceRef,he as readAnnotationToken,F as resolveScreenshotOptions,P as resolveTarget,ne as summariseText};
1
+ var ve=e=>{throw TypeError(e)};var Se=(e,t,n)=>t.has(e)||ve("Cannot "+n);var L=(e,t,n)=>(Se(e,t,"read from private field"),n?n.call(e):t.get(e)),ae=(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),Ce=(e,t,n,o)=>(Se(e,t,"write to private field"),o?o.call(e,n):t.set(e,n),n);var V="1",j="data-src",ie="data-src-name";function rt(e){return e.selection==="region"?"region":"element"}var at=new Set(["annotate:enable","annotate:disable","annotate:ping"]);function se(e){if(typeof e!="object"||e===null)return!1;let t=e.type;return typeof t=="string"&&at.has(t)}function q(e){if(!e||e==="*")throw new Error("[annotation] a concrete parent origin is required; '*' would broadcast annotation payloads to any embedder.");return e}var we="ai_annotate",le="ai_annotate_armed",Y="ai_capture",z="ai_run",Oe="1";function it(e=le){return`${e}=${Oe}; Path=/; SameSite=Lax; Secure`}function ce(e){return`${e}=; Path=/; SameSite=Lax; Secure; Max-Age=0; Expires=Thu, 01 Jan 1970 00:00:00 GMT`}var Re="pits_annotate",ke="pits_annotate_armed",J=[we,Re],Z=[le,ke];function ue(e){return e.split(";").some(t=>{let n=t.trimStart();return Z.some(o=>n.startsWith(`${o}=`))})}function st(e){for(let t of J){let n=e.get(t);if(n!==null&&n.length>0)return n}return null}var _e="ai-annotation-overlay",lt="2147483000";function de(e){let t=e.createElement("div");t.id=_e,t.style.cssText=["position:fixed","top:0","left:0","pointer-events:none",`z-index:${lt}`,"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 pe=200,Me=8;function me(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 Ne(e,t=Me){let n=[],o=e;for(;o&&n.length<t;){let r=me(o.getAttribute(j));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 Ie(e){let t=e;for(;t;){if(me(t.getAttribute(j)))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 Le(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 Pe(e){if(!e)return;let t=e.replace(/\s+/g," ").trim();if(t)return t.length>pe?`${t.slice(0,pe-1)}\u2026`:t}function fe(e,t){let n=Ie(e),o=Ne(e),r=o[0],a={domPath:Le(e),boundingBox:t.boundingBox};r&&(a.source=r),o.length>0&&(a.sourceChain=o);let i=n?.getAttribute(ie);i&&(a.componentName=i);let c=Pe(e.textContent);return c&&(a.textContent=c),a}var ut=2048;function Q(e){if(typeof e!="string"||e.length===0||e.length>ut)return;let t;try{t=new URL(e)}catch{return}if(!(t.protocol!=="https:"&&t.protocol!=="http:"))return t.href}function ge(e,t=window){let n=q(e);return{name:"postMessage",carries:()=>!0,send(o){t.parent.postMessage(o,n)}}}function Fe(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 Ue=8e3;function dt(e){let t=Fe(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??Ue,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=Q(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 he(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 pt=49152,mt=480,ft=250,gt=[{edge:480,quality:.7},{edge:240,quality:.5}],ht=["image/webp","image/jpeg"];function be(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 bt=new Set(["IMG","CANVAS","VIDEO"]),yt="img,canvas,video",Et=4;function ee(e){return!!e&&bt.has(e.tagName.toUpperCase())}function De(e,t=Et){if(!e)return null;if(ee(e))return e;let n=e.querySelector?.(yt)??null;if(ee(n))return n;let o=e.parentElement??null;for(let r=0;o&&r<t;r++){if(ee(o))return o;o=o.parentElement??null}return null}function He(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 Ke(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 At(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 ht){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 Be(e,t){if(!t.enabled)return null;let n=De(e);if(!n)return null;let o=He(n);if(!o)return null;for(let r of gt){let a=Ke(o,Math.min(t.maxEdge,r.edge)),i=At(n,a,r.quality,t);if(i)return{dataUrl:i,region:"element"}}return null}function $e(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(()=>Be(e,t)).then(r,()=>r(null)).finally(()=>clearTimeout(a))}):Promise.resolve(null)}async function te(e,t,n){let o;try{o=await $e(t,n)}catch{o=null}return o?{...e,screenshot:o}:e}var xt={consoleErrors:[],failedRequests:[],featureFlags:{}},Tt=()=>({...xt});function ye(e){let t=e.parentOrigin===void 0?null:q(e.parentOrigin),n=window,o=n.document,r=be(e.screenshot,o),a=!1,i=null,c=0,f=null,h=!1,g=e.transport??(t===null?null:ge(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=he(g,e.onEgressError),d=l=>{let u=l.getBoundingClientRect();return{x:u.x,y:u.y,w:u.width,h:u.height}},T=l=>fe(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}te(b,u,r).then(S=>N(S),()=>N(b));return}let H={x:l.clientX,y:l.clientY},K=r.enabled?te(b,u,r).then(S=>S,()=>b):Promise.resolve(b),I=()=>{h=!0;let S=null,W=O({target:b.target,point:H}).then(E=>E,E=>(S={error:E},null));Promise.all([K,W]).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=de(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&&se(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 ne="ai.annotation.capture",oe="ai.annotation.run",qe=[...J,Y,z];function w(e,t){try{return e()}catch{return t}}function vt(e){return w(()=>e?.sessionStorage??null,null)}function St(e={}){let t=e.doc??document,n=t.defaultView??null,o=e.storage===void 0?vt(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(Y)||null,c=a.searchParams.get(z)||null,qe.some(g=>a.searchParams.has(g)))){for(let p of qe)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(ne,i),void 0):i=w(()=>o.getItem(ne),null),c!==null?w(()=>o.setItem(oe,c),void 0):c=w(()=>o.getItem(oe),null));let f=()=>{for(let h of Z)w(()=>{t.cookie=ce(h)},void 0);o&&(w(()=>o.removeItem(ne),void 0),w(()=>o.removeItem(oe),void 0))};return{armed:ue(w(()=>t.cookie,"")),captureToken:i,runId:c,disarm:f}}var Ct=["preview","staging","development"];function Ee(e){return Ct.includes(e.env)}var Ge={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"},We="ai-annotation-toolbar",wt="2147483001",Ve=288,Xe=190,D=12,Ot=`
2
+ :host{
3
+ --ai-bg:#fff;
4
+ --ai-fg:#18181b;
5
+ --ai-line:#d4d4d8;
6
+ --ai-line-soft:#e4e4e7;
7
+ --ai-muted:#52525b;
8
+ --ai-idle:#a1a1aa;
9
+ --ai-accent:#2563eb;
10
+ --ai-invert-bg:#18181b;
11
+ --ai-invert-fg:#fafafa;
12
+ --ai-invert-line:#52525b;
13
+ --ai-bad:#7f1d1d;
14
+ --ai-space-2:6px;
15
+ --ai-space-3:8px;
16
+ --ai-space-4:10px;
17
+ --ai-space-5:12px;
18
+ --ai-radius-control:6px;
19
+ --ai-radius-card:8px;
20
+ --ai-radius-pill:999px;
21
+ all:initial;position:fixed;right:16px;bottom:16px;z-index:${wt};
22
+ font:13px/1.45 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
23
+ color-scheme:light}
24
+ *,*::before,*::after{box-sizing:border-box}
25
+ [hidden]{display:none!important}
26
+ .pill{order:2}
27
+ .bar{display:flex;align-items:center;gap:var(--ai-space-2);justify-content:flex-end}
28
+ button{font:inherit;margin:0;border:1px solid var(--ai-line);
29
+ border-radius:var(--ai-radius-control);background:var(--ai-bg);color:var(--ai-fg);
30
+ padding:var(--ai-space-2) var(--ai-space-4);cursor:pointer}
31
+ button:focus-visible{outline:2px solid var(--ai-accent);outline-offset:2px}
32
+ .pill{border-radius:var(--ai-radius-pill);background:var(--ai-invert-bg);
33
+ color:var(--ai-invert-fg);border-color:var(--ai-invert-bg);
34
+ padding:var(--ai-space-2) var(--ai-space-5);display:flex;align-items:center;
35
+ gap:var(--ai-space-2)}
36
+ .dot{width:8px;height:8px;border-radius:var(--ai-radius-pill);
37
+ background:var(--ai-idle);display:block}
38
+ .on .dot{background:var(--ai-accent)}
39
+ .panel{display:flex;gap:var(--ai-space-2);align-items:center;background:var(--ai-bg);
40
+ border:1px solid var(--ai-line-soft);border-radius:var(--ai-radius-card);
41
+ padding:var(--ai-space-2)}
42
+ .toggle[aria-pressed="true"]{background:var(--ai-accent);border-color:var(--ai-accent);
43
+ color:var(--ai-invert-fg)}
44
+ .composer{position:fixed;width:${Ve}px;background:var(--ai-bg);color:var(--ai-fg);
45
+ border:1px solid var(--ai-line);border-radius:var(--ai-radius-card);
46
+ padding:var(--ai-space-4);display:flex;flex-direction:column;gap:var(--ai-space-3)}
47
+ .where{margin:0;font:11px/16px ui-monospace,SFMono-Regular,Menlo,monospace;
48
+ color:var(--ai-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
49
+ label{font-weight:600}
50
+ textarea{font:inherit;width:100%;min-height:76px;resize:vertical;
51
+ padding:var(--ai-space-2) var(--ai-space-3);border:1px solid var(--ai-line);
52
+ border-radius:var(--ai-radius-control);background:var(--ai-bg);color:var(--ai-fg)}
53
+ textarea:focus-visible{outline:2px solid var(--ai-accent);outline-offset:1px}
54
+ .row{display:flex;gap:var(--ai-space-2);justify-content:flex-end}
55
+ .primary{background:var(--ai-accent);border-color:var(--ai-accent);color:var(--ai-invert-fg)}
56
+ .toast{position:fixed;right:16px;bottom:64px;max-width:320px;
57
+ background:var(--ai-invert-bg);color:var(--ai-invert-fg);
58
+ border-radius:var(--ai-radius-card);padding:var(--ai-space-3) var(--ai-space-4);
59
+ display:flex;align-items:center;gap:var(--ai-space-3)}
60
+ .toast.bad{background:var(--ai-bad)}
61
+ .toast a{color:var(--ai-invert-fg)}
62
+ .toast button{background:transparent;border-color:var(--ai-invert-line);
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 je(e={}){let t={...Ge,...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:We}),a=r.attachShadow({mode:"open"}),i=m(n,"style");i.textContent=Ot,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,H=!1,K=null,I=null,S=null,W=()=>{},E=(s,y)=>{y?s.removeAttribute("hidden"):s.setAttribute("hidden","")},U=s=>{H=s,E(h,s),d.setAttribute("aria-expanded",String(s)),d.setAttribute("aria-label",s?t.collapse:t.expand)},re=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(!H)),g.addEventListener("click",()=>{re(O?.isEnabled()!==!0)});let Te=()=>{S!==null&&clearTimeout(S),B(null),r.remove()};p.addEventListener("click",()=>{re(!1),U(!1),e.onDone?.(),Te()});let B=s=>{let y=K;K=null,E(A,!1),y&&y(s),I instanceof HTMLElement&&I.focus(),I=null};P.addEventListener("click",()=>B(null)),F.addEventListener("click",()=>B(k.value)),A.addEventListener("keydown",s=>{if(s.key==="Escape"){s.stopPropagation(),B(null);return}s.key==="Enter"&&(s.metaKey||s.ctrlKey)&&(s.preventDefault(),B(k.value))});let Qe=s=>new Promise(y=>{K=y,k.value="",R.textContent=et(s),tt(s),E(v,!1),E(A,!0),I=n.activeElement,k.focus()});function et(s){let{source:y,componentName:C}=s.target;return y?`${y.file}:${y.line}`:C??""}function tt(s){let y=s.target.boundingBox,C=y.y+y.h+D,$=C+Xe<=o.innerHeight?C:Math.max(D,y.y-Xe-D),ot=Math.min(Math.max(D,y.x),Math.max(D,o.innerWidth-Ve-D));c.textContent=`.composer{left:${Math.round(ot)}px;top:${Math.round($)}px}`}let nt=(s,y)=>{S!==null&&clearTimeout(S);let C=s.status==="sent",$=s.status==="sent"?Q(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&&$!==void 0),$!==void 0&&(u.setAttribute("href",$),u.textContent=t.issue),E(b,!C),E(v,!0),C&&(S=setTimeout(()=>E(v,!1),6e3)),W=y};return b.addEventListener("click",()=>{E(v,!1),W()}),{owns:s=>s instanceof Node&&(s===r||r.contains(s)),attach:s=>{O=s,re(s.isEnabled())},collectComment:Qe,showResult:nt,isExpanded:()=>H,destroy:Te}}function Rt(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&&Ee(e.build),o=je({...e.toolbar,armed:n,onDone:()=>{e.arming?.disarm(),r.destroy(),e.toolbar?.onDone?.()}}),r=ye({...e,collectComment:o.collectComment,onCaptureResult:o.showResult,ignoreElement:o.owns});return o.attach(r),{sdk:r,toolbar:o,destroy(){o.destroy(),r.destroy()}}}var kt=20;var M,G,X=class{constructor(t=20){ae(this,M,[]);ae(this,G);Ce(this,G,Math.max(1,t))}push(t){L(this,M).push(t),L(this,M).length>L(this,G)&&L(this,M).shift()}toArray(){return[...L(this,M)]}get size(){return L(this,M).length}};M=new WeakMap,G=new WeakMap;function Ye(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 ze=(e,t)=>e.length>t?`${e.slice(0,t-1)}\u2026`:e;function Je(e){return ze(e.map(Ye).join(" "),500)}function Ae(e){for(let t of e)if(t instanceof Error&&typeof t.stack=="string")return ze(t.stack,2e3)}function xe(e){return e===0||e<200||e>=300}var Ze=()=>({limit:20,getFeatureFlags:()=>({}),now:()=>new Date().toISOString()});function _t(e,t=Ze()){let n=new X(t.limit),o=new X(t.limit),r=(p,d)=>{n.push({level:p,message:Je(d),...Ae(d)?{stack:Ae(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(xe(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{xe(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)}}}export{le as ANNOTATION_ARMED_COOKIE,Z as ANNOTATION_ARMED_COOKIES,Oe as ANNOTATION_ARMED_VALUE,we as ANNOTATION_TOKEN_PARAM,J as ANNOTATION_TOKEN_PARAMS,Y as CAPTURE_TOKEN_PARAM,ne as CAPTURE_TOKEN_STORAGE_KEY,Ge as DEFAULT_LABELS,kt as DEFAULT_LIMIT,Ue as HTTP_TRANSPORT_TIMEOUT_MS,ke as LEGACY_ANNOTATION_ARMED_COOKIE,Re as LEGACY_ANNOTATION_TOKEN_PARAM,Me as MAX_CHAIN,pt as MAX_SCREENSHOT_BYTES,mt as MAX_SCREENSHOT_EDGE,pe as MAX_TEXT,ie as NAME_ATTR,_e as OVERLAY_ID,z as REVIEW_RUN_PARAM,oe as REVIEW_RUN_STORAGE_KEY,X as RingBuffer,ft as SCREENSHOT_TIMEOUT_MS,V as SDK_VERSION,j as SRC_ATTR,We as TOOLBAR_ID,it as armedCookie,Fe as assertConcreteEndpoint,q as assertConcreteOrigin,te as attachScreenshot,$e as captureScreenshot,Be as captureScreenshotSync,ce as clearedCookie,Ne as collectSourceChain,ye as createAnnotationSdk,je as createAnnotationToolbar,he as createEgress,de as createOverlay,Ze as defaultStateCollectorOptions,Ye as describeArg,Le as domPath,Tt as emptyAnnotationState,Ie as findAnnotatedAncestor,De as findCaptureSource,Ae as firstStack,Ke as fitWithin,Je as formatConsoleArgs,dt as httpTransport,_t as installStateCollector,He as intrinsicSize,Ee as isAnnotatableBuild,ue as isAnnotationArmed,xe as isFailedStatus,ee as isMediaElement,se as isParentMessage,Rt as mountAnnotation,me as parseSourceRef,ge as postMessageTransport,st as readAnnotationToken,St as readArming,be as resolveScreenshotOptions,fe as resolveTarget,Q as safeIssueUrl,rt as selectionOf,Pe as summariseText};
2
65
  //# sourceMappingURL=index.mjs.map