@weatherboard/annotation 0.3.0 → 0.4.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/ADOPTING.md +49 -5
- package/dist/markers.cjs +11 -4
- package/dist/markers.cjs.map +3 -3
- package/dist/markers.d.cts +39 -2
- package/dist/markers.d.mts +39 -2
- package/dist/markers.d.ts +39 -2
- package/dist/markers.mjs +11 -4
- package/dist/markers.mjs.map +3 -3
- package/dist/read.cjs +1 -1
- package/dist/read.cjs.map +3 -3
- package/dist/read.d.cts +46 -1
- package/dist/read.d.mts +46 -1
- package/dist/read.d.ts +46 -1
- package/dist/read.mjs +1 -1
- package/dist/read.mjs.map +3 -3
- package/package.json +4 -4
package/dist/markers.d.mts
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
|
-
/**
|
|
92
|
-
|
|
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
|
-
/**
|
|
92
|
-
|
|
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
|
|
1
|
+
var C="data-src";var B=8;function S(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=B){let n=[],r=e;for(;r&&n.length<t;){let o=S(r.getAttribute(C));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(S(t.getAttribute(C)))return t;t=t.parentElement}return null}function H(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<B){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&&H(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(`[${C}]`),o=[];for(let i=0;i<r.length;i++){let s=r[i],c=S(s.getAttribute(C));if(!c||!H(n,c))continue;let d=S(q(s.parentElement)?.getAttribute(C)??null);d&&H(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"},K={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:${
|
|
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
|
-
`,
|
|
63
|
+
`,T=22,v=4,W=(e,t,n)=>Math.min(Math.max(e,t),n),G=T+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)<T&&Math.abs(d.top-c)<T);for(let s=0;s<te;s+=1){if(!i(r,o))return{left:r,top:o};if(o+=G,o>n&&(o=v,r-=G,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(K),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 O=u(n,"div",{class:"count",role:"status","aria-label":t.region}),k=u(n,"span",{class:"count-text"});k.textContent=t.loading,O.appendChild(k);let A=u(n,"button",{type:"button",class:"toggle",hidden:""});O.appendChild(A),s.appendChild(O);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=[],N=!1,R=e.showResolved===!0;function _(a){if(R)A.textContent=t.hideResolved;else if(a>0)A.textContent=t.showResolved(a);else{A.setAttribute("hidden",""),A.textContent="";return}A.setAttribute("aria-pressed",R?"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:w},l)=>{let y=w.getBoundingClientRect(),f=W(Math.round(y.right-11),v,Math.max(v,a-T-v)),m=W(Math.round(y.top-11),v,Math.max(v,p-T-v)),x=re({left:f,top:m},g,p-T-v);g.push(x),b.push(`.pin[data-i="${l}"]{left:${x.left}px;top:${x.top}px}`)}),d.textContent=b.join("")}let L=()=>{N||P()};r.addEventListener("scroll",L,!0),r.addEventListener("resize",L);function I(){for(h.setAttribute("hidden","");h.firstChild;)h.removeChild(h.firstChild)}function Y(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??"",w=b===""?NaN:Date.parse(b);g.textContent=Number.isNaN(w)?t.freshnessUnknown:t.asOf(oe(o()-w)),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={...K,showingResolved:R,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(),Y(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 w={total:a.total,shown:b,ambiguous:g.ambiguous,unresolved:g.unresolved,anchored:a.anchored,resolvedHidden:a.resolvedHidden,showingResolved:R,clusters:g.clusters.length,asOf:a.asOf,line:k.textContent??""};return M=w,P(),w}A.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),!N&&(R=!R,_(M?.resolvedHidden??0),k.textContent=t.loading,F.refresh())});let F={async refresh(){if(N)return K;if(e.reader===null)return $(null,t.noCredential);let a=e.path??n.location?.pathname??"/";try{let p=await e.reader.read(a,{includeResolved:R});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(){N=!0,r.removeEventListener("scroll",L,!0),r.removeEventListener("resize",L);for(let{pin:a}of E)a.remove();E=[],i.remove()}};return F}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
|