@weatherboard/annotation 0.3.0 → 0.6.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.
Files changed (66) hide show
  1. package/ADOPTING.md +146 -11
  2. package/COMPATIBILITY.md +15 -0
  3. package/README.md +33 -8
  4. package/dist/anchor.cjs +1 -1
  5. package/dist/anchor.cjs.map +2 -2
  6. package/dist/anchor.mjs +1 -1
  7. package/dist/anchor.mjs.map +2 -2
  8. package/dist/arming.d.cts +1 -3
  9. package/dist/arming.d.mts +1 -3
  10. package/dist/arming.d.ts +1 -3
  11. package/dist/bootstrap-runtime.d.cts +30 -0
  12. package/dist/bootstrap-runtime.d.mts +30 -0
  13. package/dist/bootstrap-runtime.d.ts +30 -0
  14. package/dist/bootstrap.cjs +2 -0
  15. package/dist/bootstrap.cjs.map +7 -0
  16. package/dist/bootstrap.d.cts +7 -0
  17. package/dist/bootstrap.d.mts +7 -0
  18. package/dist/bootstrap.d.ts +7 -0
  19. package/dist/bootstrap.mjs +2 -0
  20. package/dist/bootstrap.mjs.map +7 -0
  21. package/dist/host.cjs +1 -1
  22. package/dist/host.cjs.map +3 -3
  23. package/dist/host.mjs +1 -1
  24. package/dist/host.mjs.map +3 -3
  25. package/dist/index.cjs +4 -4
  26. package/dist/index.cjs.map +4 -4
  27. package/dist/index.d.cts +1 -1
  28. package/dist/index.d.mts +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.mjs +4 -4
  31. package/dist/index.mjs.map +4 -4
  32. package/dist/markers.cjs +11 -4
  33. package/dist/markers.cjs.map +3 -3
  34. package/dist/markers.d.cts +39 -2
  35. package/dist/markers.d.mts +39 -2
  36. package/dist/markers.d.ts +39 -2
  37. package/dist/markers.mjs +11 -4
  38. package/dist/markers.mjs.map +3 -3
  39. package/dist/protocol.cjs +1 -1
  40. package/dist/protocol.cjs.map +3 -3
  41. package/dist/protocol.d.cts +7 -0
  42. package/dist/protocol.d.mts +7 -0
  43. package/dist/protocol.d.ts +7 -0
  44. package/dist/protocol.mjs +1 -1
  45. package/dist/protocol.mjs.map +3 -3
  46. package/dist/read.cjs +1 -1
  47. package/dist/read.cjs.map +3 -3
  48. package/dist/read.d.cts +46 -1
  49. package/dist/read.d.mts +46 -1
  50. package/dist/read.d.ts +46 -1
  51. package/dist/read.mjs +1 -1
  52. package/dist/read.mjs.map +3 -3
  53. package/dist/selection.cjs +5 -0
  54. package/dist/selection.cjs.map +7 -0
  55. package/dist/selection.d.cts +27 -0
  56. package/dist/selection.d.mts +27 -0
  57. package/dist/selection.d.ts +27 -0
  58. package/dist/selection.mjs +5 -0
  59. package/dist/selection.mjs.map +7 -0
  60. package/dist/session.d.cts +10 -0
  61. package/dist/session.d.mts +10 -0
  62. package/dist/session.d.ts +10 -0
  63. package/dist/transport.d.cts +10 -0
  64. package/dist/transport.d.mts +10 -0
  65. package/dist/transport.d.ts +10 -0
  66. package/package.json +37 -12
@@ -88,8 +88,25 @@ export declare const MARKERS_ID = "ai-annotation-markers";
88
88
  export interface AnnotationMarkerLabels {
89
89
  /** The region the whole layer announces itself as. */
90
90
  region: string;
91
- /** Built with the two counts: `(total, shown) => string`. */
92
- count: (total: number, shown: number) => string;
91
+ /**
92
+ * Built with the three counts: `(total, shown, resolvedHidden) => string`.
93
+ *
94
+ * `resolvedHidden` is a third argument rather than a separate line because a
95
+ * count in one place and a caveat in another is how a reader concludes the
96
+ * first number was the whole answer. A consumer overriding this with a
97
+ * two-parameter function still typechecks and still gets the first two
98
+ * numbers — but it will not say what is being held back, which is the one
99
+ * thing this argument exists for.
100
+ */
101
+ count: (total: number, shown: number, resolvedHidden: number) => string;
102
+ /**
103
+ * The control that widens the read, and the label it carries in each state.
104
+ *
105
+ * A count with no way to act on it is a fact a reviewer can do nothing with;
106
+ * a control with no count is one nobody knows to press. Both, or neither.
107
+ */
108
+ showResolved: (resolvedHidden: number) => string;
109
+ hideResolved: string;
93
110
  /** Shown before the first read completes. */
94
111
  loading: string;
95
112
  /** The console answered and refused. `reason` is the envelope's, or empty. */
@@ -131,6 +148,15 @@ export interface AnnotationMarkersOptions {
131
148
  */
132
149
  path?: string;
133
150
  labels?: Partial<AnnotationMarkerLabels>;
151
+ /**
152
+ * Start with the resolved captures showing (A-288/A-323). Defaults to `false`.
153
+ *
154
+ * The default matches the console's, deliberately: a layer that asked for
155
+ * everything on every page would put the default back where A-288 decided it
156
+ * should not be, from the other side of the wire, and nobody would see it in
157
+ * the console's code.
158
+ */
159
+ showResolved?: boolean;
134
160
  /** For the age in the freshness line. Defaults to `Date.now`. */
135
161
  now?: () => number;
136
162
  }
@@ -151,6 +177,17 @@ export interface MarkerRender {
151
177
  * though it were `shown`. See this file's header.
152
178
  */
153
179
  anchored: number;
180
+ /**
181
+ * The envelope's `resolvedHidden` — finished captures the console held back.
182
+ *
183
+ * Zero while `showingResolved` is true, because nothing is then being held
184
+ * back. That is the console's number and not an inference: a layer that
185
+ * remembered the previous read's figure would keep reporting it after the
186
+ * capture had been archived.
187
+ */
188
+ resolvedHidden: number;
189
+ /** Whether this render asked for `?resolved=include`. */
190
+ showingResolved: boolean;
154
191
  /** Distinct elements drawn on. Lower than `shown` wherever markers clustered. */
155
192
  clusters: number;
156
193
  /** The envelope's `asOf` — the console's Linear cursor, or `""`. */
package/dist/markers.d.ts CHANGED
@@ -88,8 +88,25 @@ export declare const MARKERS_ID = "ai-annotation-markers";
88
88
  export interface AnnotationMarkerLabels {
89
89
  /** The region the whole layer announces itself as. */
90
90
  region: string;
91
- /** Built with the two counts: `(total, shown) => string`. */
92
- count: (total: number, shown: number) => string;
91
+ /**
92
+ * Built with the three counts: `(total, shown, resolvedHidden) => string`.
93
+ *
94
+ * `resolvedHidden` is a third argument rather than a separate line because a
95
+ * count in one place and a caveat in another is how a reader concludes the
96
+ * first number was the whole answer. A consumer overriding this with a
97
+ * two-parameter function still typechecks and still gets the first two
98
+ * numbers — but it will not say what is being held back, which is the one
99
+ * thing this argument exists for.
100
+ */
101
+ count: (total: number, shown: number, resolvedHidden: number) => string;
102
+ /**
103
+ * The control that widens the read, and the label it carries in each state.
104
+ *
105
+ * A count with no way to act on it is a fact a reviewer can do nothing with;
106
+ * a control with no count is one nobody knows to press. Both, or neither.
107
+ */
108
+ showResolved: (resolvedHidden: number) => string;
109
+ hideResolved: string;
93
110
  /** Shown before the first read completes. */
94
111
  loading: string;
95
112
  /** The console answered and refused. `reason` is the envelope's, or empty. */
@@ -131,6 +148,15 @@ export interface AnnotationMarkersOptions {
131
148
  */
132
149
  path?: string;
133
150
  labels?: Partial<AnnotationMarkerLabels>;
151
+ /**
152
+ * Start with the resolved captures showing (A-288/A-323). Defaults to `false`.
153
+ *
154
+ * The default matches the console's, deliberately: a layer that asked for
155
+ * everything on every page would put the default back where A-288 decided it
156
+ * should not be, from the other side of the wire, and nobody would see it in
157
+ * the console's code.
158
+ */
159
+ showResolved?: boolean;
134
160
  /** For the age in the freshness line. Defaults to `Date.now`. */
135
161
  now?: () => number;
136
162
  }
@@ -151,6 +177,17 @@ export interface MarkerRender {
151
177
  * though it were `shown`. See this file's header.
152
178
  */
153
179
  anchored: number;
180
+ /**
181
+ * The envelope's `resolvedHidden` — finished captures the console held back.
182
+ *
183
+ * Zero while `showingResolved` is true, because nothing is then being held
184
+ * back. That is the console's number and not an inference: a layer that
185
+ * remembered the previous read's figure would keep reporting it after the
186
+ * capture had been archived.
187
+ */
188
+ resolvedHidden: number;
189
+ /** Whether this render asked for `?resolved=include`. */
190
+ showingResolved: boolean;
154
191
  /** Distinct elements drawn on. Lower than `shown` wherever markers clustered. */
155
192
  clusters: number;
156
193
  /** The envelope's `asOf` — the console's Linear cursor, or `""`. */
package/dist/markers.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var y="data-src";var P=8;function T(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 K(e,t=P){let n=[],r=e;for(;r&&n.length<t;){let o=T(r.getAttribute(y));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 F(e){let t=e;for(;t;){if(T(t.getAttribute(y)))return t;t=t.parentElement}return null}function I(e,t){return e.file!==t.file||e.line!==t.line?!1:e.column===void 0||t.column===void 0?!0:e.column===t.column}function X(e,t){if(e.length===0)return!1;if(e.length<P){if(t.length!==e.length)return!1}else if(t.length<e.length)return!1;return e.every((n,r)=>{let o=t[r];return o!==void 0&&I(n,o)})}function H(e,t){let n={file:e.file,line:e.line};e.column!==void 0&&(n.column=e.column);let r=t.querySelectorAll(`[${y}]`),o=[];for(let a=0;a<r.length;a++){let i=r[a],c=T(i.getAttribute(y));if(!c||!I(n,c))continue;let d=T(F(i.parentElement)?.getAttribute(y)??null);d&&I(d,c)||o.push(i)}return o}function U(e,t){switch(e.kind){case"route":{if(!e.path)return"none";let n=t.location?.pathname;return!n||n!==e.path?"none":t.body??"none"}case"dom-path":{if(!e.path)return"none";let n;try{n=t.querySelectorAll(e.path)}catch{return"none"}return n.length===0?"none":n.length>1?"ambiguous":n[0]}case"source-ref":{if(e.chain.length===0)return"none";let n=H(e,t).filter(r=>X(e.chain,K(r)));return n.length===0?"none":n.length>1?"ambiguous":n[0]}default:return"none"}}var j="ai-annotation-markers",W="2147483002",G={region:"Annotations on this page",count:(e,t)=>e===0?"No annotations on this page":`${e} annotation${e===1?"":"s"} here, ${t} shown`,loading:"Looking for annotations\u2026",refused:e=>e==="retired-link"?"This annotation link is an older format the console no longer accepts. Open Request changes again.":e==="rate-limited"?"The console is rate-limiting this page's reads. Wait a moment.":"The console refused this page's read.",unreachable:"Could not reach the console for this page's annotations.",noCredential:"No read credential, so annotations were not requested.",asOf:e=>`status as of ${e} ago`,freshnessUnknown:"the console cannot say how fresh these statuses are",close:"Close"},$={total:0,shown:0,ambiguous:0,unresolved:0,anchored:0,clusters:0,asOf:"",line:""},Y=`
1
+ var T="data-src";var H=8;function N(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)),i=Number(e.slice(t+1));return!r||!Number.isFinite(o)||!Number.isFinite(i)?null:{file:r,line:o,column:i}}function j(e,t=H){let n=[],r=e;for(;r&&n.length<t;){let o=N(r.getAttribute(T));if(o){let i=n[n.length-1];i&&i.file===o.file&&i.line===o.line||n.push(o)}r=r.parentElement}return n}function q(e){let t=e;for(;t;){if(N(t.getAttribute(T)))return t;t=t.parentElement}return null}function B(e,t){return e.file!==t.file||e.line!==t.line?!1:e.column===void 0||t.column===void 0?!0:e.column===t.column}function J(e,t){if(e.length===0)return!1;if(e.length<H){if(t.length!==e.length)return!1}else if(t.length<e.length)return!1;return e.every((n,r)=>{let o=t[r];return o!==void 0&&B(n,o)})}function Z(e,t){let n={file:e.file,line:e.line};e.column!==void 0&&(n.column=e.column);let r=t.querySelectorAll(`[${T}]`),o=[];for(let i=0;i<r.length;i++){let s=r[i],c=N(s.getAttribute(T));if(!c||!B(n,c))continue;let d=N(q(s.parentElement)?.getAttribute(T)??null);d&&B(d,c)||o.push(s)}return o}function V(e,t){switch(e.kind){case"route":{if(!e.path)return"none";let n=t.location?.pathname;return!n||n!==e.path?"none":t.body??"none"}case"dom-path":{if(!e.path)return"none";let n;try{n=t.querySelectorAll(e.path)}catch{return"none"}return n.length===0?"none":n.length>1?"ambiguous":n[0]}case"source-ref":{if(e.chain.length===0)return"none";let n=Z(e,t).filter(r=>J(e.chain,j(r)));return n.length===0?"none":n.length>1?"ambiguous":n[0]}default:return"none"}}var X="ai-annotation-markers",Q="2147483002",ee={region:"Annotations on this page",count:(e,t,n)=>{let r=e===0?"No annotations on this page":`${e} annotation${e===1?"":"s"} here, ${t} shown`;return n>0?`${r} \xB7 ${n} resolved`:r},showResolved:e=>`Show ${e} resolved annotation${e===1?"":"s"}`,hideResolved:"Hide resolved annotations",loading:"Looking for annotations\u2026",refused:e=>e==="retired-link"?"This annotation link is an older format the console no longer accepts. Open Request changes again.":e==="rate-limited"?"The console is rate-limiting this page's reads. Wait a moment.":"The console refused this page's read.",unreachable:"Could not reach the console for this page's annotations.",noCredential:"No read credential, so annotations were not requested.",asOf:e=>`status as of ${e} ago`,freshnessUnknown:"the console cannot say how fresh these statuses are",close:"Close"},F={total:0,shown:0,ambiguous:0,unresolved:0,anchored:0,resolvedHidden:0,showingResolved:!1,clusters:0,asOf:"",line:""},ne=`
2
2
  :host{
3
3
  --ai-bg:#fff;
4
4
  --ai-fg:#18181b;
@@ -19,7 +19,7 @@ var y="data-src";var P=8;function T(e){if(!e)return null;let t=e.lastIndexOf(":"
19
19
  --ai-radius-pill:999px;
20
20
  --ai-pin:22px;
21
21
  --ai-edge:16px;
22
- all:initial;position:fixed;inset:0;z-index:${W};pointer-events:none;
22
+ all:initial;position:fixed;inset:0;z-index:${Q};pointer-events:none;
23
23
  font:13px/1.45 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
24
24
  color:var(--ai-fg);color-scheme:light}
25
25
  *,*::before,*::after{box-sizing:border-box}
@@ -28,7 +28,14 @@ var y="data-src";var P=8;function T(e){if(!e)return null;let t=e.lastIndexOf(":"
28
28
  position:absolute;left:var(--ai-edge);bottom:var(--ai-edge);pointer-events:auto;
29
29
  background:var(--ai-invert-bg);color:var(--ai-invert-fg);
30
30
  border-radius:var(--ai-radius-pill);
31
- padding:var(--ai-space-2) var(--ai-space-5);max-width:min(60vw,420px)}
31
+ padding:var(--ai-space-2) var(--ai-space-5);max-width:min(60vw,420px);
32
+ display:flex;align-items:center;gap:var(--ai-space-3);flex-wrap:wrap}
33
+ .toggle{
34
+ pointer-events:auto;font:inherit;font-size:12px;white-space:nowrap;
35
+ background:var(--ai-invert-bg);color:var(--ai-invert-fg);
36
+ border:1px solid var(--ai-invert-fg);border-radius:var(--ai-radius-pill);
37
+ padding:0 var(--ai-space-3);cursor:pointer}
38
+ .toggle:focus-visible{outline:2px solid var(--ai-invert-fg);outline-offset:2px}
32
39
  .pin{
33
40
  position:absolute;pointer-events:auto;
34
41
  width:var(--ai-pin);height:var(--ai-pin);
@@ -53,5 +60,5 @@ var y="data-src";var P=8;function T(e){if(!e)return null;let t=e.lastIndexOf(":"
53
60
  background:var(--ai-bg);color:var(--ai-fg);border:1px solid var(--ai-line);
54
61
  border-radius:var(--ai-radius-control);
55
62
  padding:var(--ai-space-1) var(--ai-space-4);cursor:pointer}
56
- `,w=22,A=4,q=(e,t,n)=>Math.min(Math.max(e,t),n),z=w+2,J=128;function Z(e,t,n){let{left:r,top:o}=e,a=(i,c)=>t.some(d=>Math.abs(d.left-i)<w&&Math.abs(d.top-c)<w);for(let i=0;i<J;i+=1){if(!a(r,o))return{left:r,top:o};if(o+=z,o>n&&(o=A,r-=z,r<A))break}return{left:e.left,top:e.top}}function u(e,t,n){let r=e.createElement(t);if(n)for(let o of Object.keys(n))r.setAttribute(o,n[o]??"");return r}function Q(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);if(r<24){let i=n%60;return i===0?`${r}h`:`${r}h ${i}m`}let o=Math.floor(r/24),a=r%24;return a===0?`${o}d`:`${o}d ${a}h`}function ee(e,t){let n=new Map,r=0,o=0;for(let a of e){let i=U(a.anchor,t);if(i==="ambiguous"){r+=1;continue}if(i==="none"){o+=1;continue}let c=n.get(i);c?c.push(a):n.set(i,[a])}return{clusters:[...n].map(([a,i])=>({element:a,markers:i})),ambiguous:r,unresolved:o}}function le(e){let t={...G,...e.labels};if(e.armed===!1)return{refresh:()=>Promise.resolve($),owns:()=>!1,last:()=>null,destroy:()=>{}};let n=e.doc??document,r=e.win??n.defaultView??window,o=e.now??Date.now,a=u(n,"div",{id:j}),i=a.attachShadow({mode:"open"}),c=u(n,"style");c.textContent=Y,i.appendChild(c);let d=u(n,"style");i.appendChild(d);let R=u(n,"div",{class:"count",role:"status","aria-label":t.region});R.textContent=t.loading,i.appendChild(R);let g=u(n,"div",{class:"panel",role:"dialog","aria-modal":"false","aria-label":t.region,hidden:""});i.appendChild(g),n.body.appendChild(a);let C=null,k=[],S=!1;function N(){if(k.length===0){d.textContent="";return}let s=r.innerWidth||0,p=r.innerHeight||0,h=[],b=[];k.forEach(({element:v},l)=>{let E=v.getBoundingClientRect(),f=q(Math.round(E.right-11),A,Math.max(A,s-w-A)),m=q(Math.round(E.top-11),A,Math.max(A,p-w-A)),x=Z({left:f,top:m},h,p-w-A);h.push(x),b.push(`.pin[data-i="${l}"]{left:${x.left}px;top:${x.top}px}`)}),d.textContent=b.join("")}let M=()=>{S||N()};r.addEventListener("scroll",M,!0),r.addEventListener("resize",M);function L(){for(g.setAttribute("hidden","");g.firstChild;)g.removeChild(g.firstChild)}function V(s,p){L();for(let f of s){let m=u(n,"div",{class:"entry"}),x=u(n,"p",{class:"who"}),_=f.createdAt?new Date(f.createdAt):null;x.textContent=_!==null&&!Number.isNaN(_.getTime())?`${f.reviewer} \xB7 ${_.toISOString().slice(0,10)}`:f.reviewer,m.appendChild(x);let D=u(n,"p",{class:"what"});D.textContent=f.comment,m.appendChild(D);let B=u(n,"p",{class:"state"});B.textContent=f.status.display,m.appendChild(B),g.appendChild(m)}let h=u(n,"p",{class:"fresh"}),b=C?.asOf??"",v=b===""?NaN:Date.parse(b);h.textContent=Number.isNaN(v)?t.freshnessUnknown:t.asOf(Q(o()-v)),g.appendChild(h);let l=u(n,"button",{type:"button",class:"close"});l.textContent=t.close,l.addEventListener("click",()=>L()),g.appendChild(l);let E=p.getBoundingClientRect();d.textContent=`${d.textContent??""}.panel{left:${Math.round(Math.max(8,E.right-320))}px;top:${Math.round(E.top+20)}px}`,g.removeAttribute("hidden")}function O(s,p){for(let{pin:l}of k)l.remove();if(k=[],L(),s===null){R.textContent=p??t.unreachable;let l={...$,line:R.textContent};return C=l,N(),l}let h=ee(s.annotations,n),b=0;h.clusters.forEach((l,E)=>{let f=l.element,m=u(n,"button",{type:"button",class:"pin","data-i":String(E),"aria-label":`${l.markers.length} annotation${l.markers.length===1?"":"s"}`});m.textContent=l.markers.length===1?"1":String(l.markers.length),m.addEventListener("click",x=>{x.preventDefault(),x.stopPropagation(),V(l.markers,f)}),i.appendChild(m),k.push({pin:m,element:f}),b+=l.markers.length}),R.textContent=s.ok||s.reason===void 0?t.count(s.total,b):t.refused(s.reason);let v={total:s.total,shown:b,ambiguous:h.ambiguous,unresolved:h.unresolved,anchored:s.anchored,clusters:h.clusters.length,asOf:s.asOf,line:R.textContent??""};return C=v,N(),v}return{async refresh(){if(S)return $;if(e.reader===null)return O(null,t.noCredential);let s=e.path??n.location?.pathname??"/";try{let p=await e.reader.read(s);return O(p,null)}catch{return O(null,t.unreachable)}},owns(s){if(s===a)return!0;let p=s;return typeof p?.closest=="function"?p.closest(`#${j}`)===a:!1},last:()=>C,destroy(){S=!0,r.removeEventListener("scroll",M,!0),r.removeEventListener("resize",M);for(let{pin:s}of k)s.remove();k=[],a.remove()}}}export{G as DEFAULT_MARKER_LABELS,j as MARKERS_ID,Q as formatMarkerAge,Z as freeSpot,le as mountAnnotationMarkers,ee as placeMarkers};
63
+ `,C=22,v=4,W=(e,t,n)=>Math.min(Math.max(e,t),n),Y=C+2,te=128;function re(e,t,n){let{left:r,top:o}=e,i=(s,c)=>t.some(d=>Math.abs(d.left-s)<C&&Math.abs(d.top-c)<C);for(let s=0;s<te;s+=1){if(!i(r,o))return{left:r,top:o};if(o+=Y,o>n&&(o=v,r-=Y,r<v))break}return{left:e.left,top:e.top}}function u(e,t,n){let r=e.createElement(t);if(n)for(let o of Object.keys(n))r.setAttribute(o,n[o]??"");return r}function oe(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);if(r<24){let s=n%60;return s===0?`${r}h`:`${r}h ${s}m`}let o=Math.floor(r/24),i=r%24;return i===0?`${o}d`:`${o}d ${i}h`}function ae(e,t){let n=new Map,r=0,o=0;for(let i of e){let s=V(i.anchor,t);if(s==="ambiguous"){r+=1;continue}if(s==="none"){o+=1;continue}let c=n.get(s);c?c.push(i):n.set(s,[i])}return{clusters:[...n].map(([i,s])=>({element:i,markers:s})),ambiguous:r,unresolved:o}}function fe(e){let t={...ee,...e.labels};if(e.armed===!1)return{refresh:()=>Promise.resolve(F),owns:()=>!1,last:()=>null,destroy:()=>{}};let n=e.doc??document,r=e.win??n.defaultView??window,o=e.now??Date.now,i=u(n,"div",{id:X}),s=i.attachShadow({mode:"open"}),c=u(n,"style");c.textContent=ne,s.appendChild(c);let d=u(n,"style");s.appendChild(d);let L=u(n,"div",{class:"count",role:"status","aria-label":t.region}),k=u(n,"span",{class:"count-text"});k.textContent=t.loading,L.appendChild(k);let A=u(n,"button",{type:"button",class:"toggle",hidden:""});L.appendChild(A),s.appendChild(L);let h=u(n,"div",{class:"panel",role:"dialog","aria-modal":"false","aria-label":t.region,hidden:""});s.appendChild(h),n.body.appendChild(i);let M=null,E=[],S=!1,w=e.showResolved===!0;function _(a){if(w)A.textContent=t.hideResolved;else if(a>0)A.textContent=t.showResolved(a);else{A.setAttribute("hidden",""),A.textContent="";return}A.setAttribute("aria-pressed",w?"true":"false"),A.removeAttribute("hidden")}function P(){if(E.length===0){d.textContent="";return}let a=r.innerWidth||0,p=r.innerHeight||0,g=[],b=[];E.forEach(({element:R},l)=>{let y=R.getBoundingClientRect(),f=W(Math.round(y.right-11),v,Math.max(v,a-C-v)),m=W(Math.round(y.top-11),v,Math.max(v,p-C-v)),x=re({left:f,top:m},g,p-C-v);g.push(x),b.push(`.pin[data-i="${l}"]{left:${x.left}px;top:${x.top}px}`)}),d.textContent=b.join("")}let O=()=>{S||P()};r.addEventListener("scroll",O,!0),r.addEventListener("resize",O);function I(){for(h.setAttribute("hidden","");h.firstChild;)h.removeChild(h.firstChild)}function G(a,p){I();for(let f of a){let m=u(n,"div",{class:"entry"}),x=u(n,"p",{class:"who"}),D=f.createdAt?new Date(f.createdAt):null;x.textContent=D!==null&&!Number.isNaN(D.getTime())?`${f.reviewer} \xB7 ${D.toISOString().slice(0,10)}`:f.reviewer,m.appendChild(x);let U=u(n,"p",{class:"what"});U.textContent=f.comment,m.appendChild(U);let z=u(n,"p",{class:"state"});z.textContent=f.status.display,m.appendChild(z),h.appendChild(m)}let g=u(n,"p",{class:"fresh"}),b=M?.asOf??"",R=b===""?NaN:Date.parse(b);g.textContent=Number.isNaN(R)?t.freshnessUnknown:t.asOf(oe(o()-R)),h.appendChild(g);let l=u(n,"button",{type:"button",class:"close"});l.textContent=t.close,l.addEventListener("click",()=>I()),h.appendChild(l);let y=p.getBoundingClientRect();d.textContent=`${d.textContent??""}.panel{left:${Math.round(Math.max(8,y.right-320))}px;top:${Math.round(y.top+20)}px}`,h.removeAttribute("hidden")}function $(a,p){for(let{pin:l}of E)l.remove();if(E=[],I(),a===null){k.textContent=p??t.unreachable,_(0);let l={...F,showingResolved:w,line:k.textContent};return M=l,P(),l}let g=ae(a.annotations,n),b=0;g.clusters.forEach((l,y)=>{let f=l.element,m=u(n,"button",{type:"button",class:"pin","data-i":String(y),"aria-label":`${l.markers.length} annotation${l.markers.length===1?"":"s"}`});m.textContent=l.markers.length===1?"1":String(l.markers.length),m.addEventListener("click",x=>{x.preventDefault(),x.stopPropagation(),G(l.markers,f)}),s.appendChild(m),E.push({pin:m,element:f}),b+=l.markers.length}),k.textContent=a.ok||a.reason===void 0?t.count(a.total,b,a.resolvedHidden):t.refused(a.reason),_(a.resolvedHidden);let R={total:a.total,shown:b,ambiguous:g.ambiguous,unresolved:g.unresolved,anchored:a.anchored,resolvedHidden:a.resolvedHidden,showingResolved:w,clusters:g.clusters.length,asOf:a.asOf,line:k.textContent??""};return M=R,P(),R}A.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),!S&&(w=!w,_(M?.resolvedHidden??0),k.textContent=t.loading,K.refresh())});let K={async refresh(){if(S)return F;if(e.reader===null)return $(null,t.noCredential);let a=e.path??n.location?.pathname??"/";try{let p=await e.reader.read(a,{includeResolved:w});return $(p,null)}catch{return $(null,t.unreachable)}},owns(a){if(a===i)return!0;let p=a;return typeof p?.closest=="function"?p.closest(`#${X}`)===i:!1},last:()=>M,destroy(){S=!0,r.removeEventListener("scroll",O,!0),r.removeEventListener("resize",O);for(let{pin:a}of E)a.remove();E=[],i.remove()}};return K}export{ee as DEFAULT_MARKER_LABELS,X as MARKERS_ID,oe as formatMarkerAge,re as freeSpot,fe as mountAnnotationMarkers,ae as placeMarkers};
57
64
  //# sourceMappingURL=markers.mjs.map