pipeup 0.5.0 → 0.5.2
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/README.md +2 -2
- package/dist/pipeup.core.js +1 -10
- package/dist/pipeup.esm.js +1 -10
- package/dist/pipeup.min.js +1 -10
- package/dist/types/core.d.ts +4 -2
- package/dist/types/model/animals.d.ts +3 -0
- package/dist/types/ui/addons.d.ts +11 -0
- package/dist/types/ui/animals.d.ts +1 -1
- package/dist/types/ui/layout.d.ts +2 -0
- package/dist/types/ui/notes.d.ts +2 -0
- package/dist/types/ui/styles.d.ts +1 -1
- package/dist/types/ui/theme.d.ts +2 -0
- package/dist/types/ui/thread-view.d.ts +2 -1
- package/package.json +2 -1
package/dist/pipeup.esm.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
function ge(e){let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function $e(e){let t=atob(e.replace(/-/g,"+").replace(/_/g,"/")),n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return n}function qn(e=16){return ge(crypto.getRandomValues(new Uint8Array(e)))}function ve(e){return new TextEncoder().encode(e)}function Ge(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(Ge).join(",")+"]";let t=e;return"{"+Object.keys(t).filter(n=>t[n]!==void 0).sort().map(n=>JSON.stringify(n)+":"+Ge(t[n])).join(",")+"}"}function Re(e){return e.replace(/\s+/g," ").trim()}function He(e){let t=Re(e),n=2166136261;for(let o=0;o<t.length;o++)n^=t.charCodeAt(o),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")}var sr=/^[A-Za-z0-9_-]{43}$/,ar=512,Xe=new Map;async function sn(){let e=await crypto.subtle.generateKey({name:"Ed25519"},!1,["sign","verify"]),t=new Uint8Array(await crypto.subtle.exportKey("raw",e.publicKey));return{publicKey:ge(t),privateKey:e.privateKey}}async function Ct(e,t){let n=await crypto.subtle.sign({name:"Ed25519"},e.privateKey,t);return ge(new Uint8Array(n))}async function Kn(e,t,n){if(!sr.test(e))return!1;try{if(ge($e(e))!==e)return!1;let o=Xe.get(e);if(!o){Xe.size>=ar&&Xe.delete(Xe.keys().next().value),o=crypto.subtle.importKey("raw",$e(e),{name:"Ed25519"},!0,["verify"]),Xe.set(e,o);let r=o;r.catch(()=>{Xe.get(e)===r&&Xe.delete(e)})}return await crypto.subtle.verify({name:"Ed25519"},await o,$e(n),t)}catch{return!1}}var Pt=1e4,lr=2**18,ln=2**40,dn=2**47,j={doc:64,path:2e3,snapshot:500,anchorId:200,quote:1e4,context:64,viewEntries:16,viewKey:64,viewValue:200},dr=/^[0-9a-f]{8}$/,an=/^[A-Za-z0-9_-]{43}$/,cr=/^[A-Za-z0-9_-]{43}$/,pr=new Set(["create","reply","edit","delete","resolve","reopen"]);async function Wn(e,t){if(e.author!==t.publicKey)throw new Error("pipeup: an op must be signed by its author");return{body:e,sig:await Ct(t,ve(Ge(e)))}}var Ae=(e,t)=>typeof e=="string"&&e.length<=t,it=e=>!!e&&typeof e=="object",zn=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=1;function cn(e){if(!it(e))return!1;let{id:t,path:n,fingerprint:o,snapshot:r,quote:s,point:l,view:d}=e;if(!Ae(n,j.path)||!Ae(r,j.snapshot)||typeof o!="string"||!dr.test(o)||t!==void 0&&(!Ae(t,j.anchorId)||t==="")||s!==void 0&&(!it(s)||!Ae(s.exact,j.quote)||s.exact===""||!Ae(s.prefix,j.context)||!Ae(s.suffix,j.context))||l!==void 0&&(!it(l)||!zn(l.x)||!zn(l.y)))return!1;if(d!==void 0){if(!it(d)||Array.isArray(d))return!1;let m=Object.entries(d);if(m.length>j.viewEntries||!m.every(([u,v])=>u.length<=j.viewKey&&Ae(v,j.viewValue)))return!1}return!0}function Yn(e){if(!it(e))return!1;let{body:t,sig:n}=e;if(typeof n!="string"||!it(t)||JSON.stringify({body:t,sig:n}).length>lr)return!1;let o=t;return!(o.v!==1||typeof o.id!="string"||!an.test(o.id)||!pr.has(o.kind)||!Ae(o.doc,j.doc)||o.doc===""||typeof o.thread!="string"||!an.test(o.thread)||typeof o.author!="string"||!cr.test(o.author)||typeof o.name!="string"||o.name.length>80||o.name!==o.name.trim()||typeof o.clock!="number"||!Number.isSafeInteger(o.clock)||o.clock<1||o.clock>ln||typeof o.at!="number"||!Number.isSafeInteger(o.at)||o.at<0||o.at>dn||o.text!==void 0&&(!Ae(o.text,Pt)||o.text!==o.text.trim())||o.target!==void 0&&(typeof o.target!="string"||!an.test(o.target))||(o.kind==="create"||o.kind==="reply"||o.kind==="edit")&&!o.text||(o.kind==="reply"||o.kind==="edit"||o.kind==="delete")&&!o.target||o.kind==="create"&&(o.id!==o.thread||!cn(o.anchor)))}function jn(e){return Kn(e.body.author,ve(Ge(e.body)),e.sig)}function Gn(e,t){return e.body.clock!==t.body.clock?e.body.clock-t.body.clock:e.body.at!==t.body.at?e.body.at-t.body.at:e.body.author!==t.body.author?e.body.author<t.body.author?-1:1:e.body.id!==t.body.id?e.body.id<t.body.id?-1:1:0}function Jn(e){let t=new Map,n=new Map,o=new Map;for(let{body:r}of[...e].sort(Gn)){if(r.name&&o.set(r.author,r.name),r.kind==="create"){if(t.has(r.id)||!r.anchor||r.text===void 0)continue;let d=Xn(r.id,r.author,r.name,r.text,r.at);t.set(r.id,{id:r.id,anchor:r.anchor,root:d,resolved:!1}),n.set(r.id,{comment:d,thread:r.id});continue}let s=t.get(r.thread);if(!s)continue;if(r.kind==="resolve"||r.kind==="reopen"){s.resolved=r.kind==="resolve";continue}let l=r.target?n.get(r.target):void 0;if(!(!l||l.thread!==r.thread)){if(r.kind==="reply"){if(n.has(r.id)||r.text===void 0)continue;let d=Xn(r.id,r.author,r.name,r.text,r.at);s.root.replies.push(d),n.set(r.id,{comment:d,thread:r.thread});continue}r.author!==l.comment.author||l.comment.deleted||(r.kind==="edit"&&r.text!==void 0&&(l.comment.text=r.text,l.comment.edited=!0),r.kind==="delete"&&(l.comment.text="",l.comment.deleted=!0))}}for(let{comment:r}of n.values())r.name||(r.unnamed=!0,r.name=o.get(r.author)??"");return[...t.values()]}function Xn(e,t,n,o,r){return{id:e,author:t,name:n,text:o,at:r,edited:!1,deleted:!1,replies:[]}}async function pn(e){let t={...e,id:void 0,thread:e.kind==="create"?void 0:e.thread},n=await crypto.subtle.digest("SHA-256",ve(Ge(t)));return ge(new Uint8Array(n))}var Ot=class{constructor(t){this.doc=t}ops=new Map;clock=0;createAt=new Map;threadAt=new Map;get size(){return this.ops.size}all(){return[...this.ops.values()]}threads(){return Jn(this.ops.values())}async add(t){let n=[];for(let o of t){if(!Yn(o)||o.body.doc!==this.doc||this.ops.has(o.body.id)||o.body.id!==await pn(o.body)||!await jn(o))continue;let r={body:o.body,sig:o.sig};this.ops.set(r.body.id,r),this.clock=Math.max(this.clock,r.body.clock),r.body.kind==="create"&&this.createAt.set(r.body.author,Math.max(this.createAt.get(r.body.author)??0,r.body.at)),this.threadAt.set(r.body.thread,Math.max(this.threadAt.get(r.body.thread)??0,r.body.at)),n.push(r)}return n}async append(t,n,o){let r={v:1,...o,id:"",thread:o.kind==="create"?"":o.thread,doc:this.doc,author:t.publicKey,name:n,clock:Math.min(this.clock+1,ln),at:Math.min(Math.max(Date.now(),o.kind==="create"?(this.createAt.get(t.publicKey)??0)+1:(this.threadAt.get(o.thread)??0)+1),dn)};r.id=await pn(r);let s=this.ops.get(r.id);if(s)return s;r.kind==="create"&&(r.thread=r.id);let[l]=await this.add([await Wn(r,t)]);if(!l)throw new Error("pipeup: could not record this change");return l}};var ur=/^([A-Za-z0-9_-]{16}):([A-Za-z0-9_-]{43})$/;function fr(){return`${qn(12)}:${ge(crypto.getRandomValues(new Uint8Array(32)))}`}async function un(e){let t=ur.exec(e.trim()),n=t?.[1],o=t?.[2];if(!n||!o)throw new Error('pipeup: data-pipeup-doc must look like "<id>:<key>", as made by newDocumentAttribute()');let r=await crypto.subtle.importKey("raw",$e(o),{name:"AES-GCM"},!1,["encrypt","decrypt"]);return{id:n,key:r}}async function Qn(e,t,n){let o=crypto.getRandomValues(new Uint8Array(12)),r=await crypto.subtle.encrypt({name:"AES-GCM",iv:o,additionalData:ve(n)},e,ve(t));return{iv:ge(o),data:ge(new Uint8Array(r))}}async function Zn(e,t,n){try{let o=await crypto.subtle.decrypt({name:"AES-GCM",iv:$e(t.iv),additionalData:ve(n)},e,$e(t.data));return new TextDecoder().decode(o)}catch{throw new Error("pipeup: this feedback could not be opened with this document")}}var mr=5e6,eo=e=>`pipeup-file:${e}`;async function to(e,t,n){let o=n?{pipeup:1,doc:e,sealed:!0,...await Qn(n,JSON.stringify(t),eo(e))}:{pipeup:1,doc:e,sealed:!1,ops:t};return JSON.stringify(o,null,2)}async function no(e,t,n){if(e.length>mr)throw new Error("pipeup: this feedback file is too large");let o;try{o=JSON.parse(e)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}if(!o||typeof o!="object"||o.pipeup!==1||typeof o.doc!="string")throw new Error("pipeup: this is not an Pipeup feedback file");if(o.doc!==t)throw new Error("pipeup: this feedback is for a different document");if(!o.sealed)return Array.isArray(o.ops)?o.ops:[];if(!n)throw new Error("pipeup: this feedback is sealed, and this page has no document key");if(typeof o.iv!="string"||typeof o.data!="string")throw new Error("pipeup: this is not an Pipeup feedback file");let r;try{r=await Zn(n,{iv:o.iv,data:o.data},eo(t))}catch{throw new Error("pipeup: this feedback could not be opened with this document's key")}let s;try{s=JSON.parse(r)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}return Array.isArray(s)?s:[]}var hr=5e3,gr=/^[a-z][a-z0-9-]{1,23}\/[a-z][a-z0-9-]{0,31}$/,oo=80,Ee=class extends Error{constructor(n,o,r=1){super("pipeup: shown here, but not saved yet");this.id=n;this.cause=o;this.count=r;this.name="UnsavedChangeError"}},ct=class e{constructor(t,n){this.log=t;this.options=n;this.displayName=n.name.trim()?ro(n.name):""}listeners=new Set;cache=[];comments=new Map;displayName;de=Promise.resolve();unsaved=[];static async open(t){if(typeof t.doc!="string"||t.doc===""||t.doc.length>j.doc)throw new Error(`pipeup: the document id must be 1 to ${j.doc} characters`);let n=new Ot(t.doc),o=await t.store.load(t.doc),r=o.length-(await n.add(o)).length;r&&console.warn(`pipeup: ${r} saved change${r===1?"":"s"} on this page couldn't be read; kept as saved`);let s=new e(n,t);return s.refresh(!1),s}get id(){return this.options.doc}get me(){return this.options.identity.publicKey}get name(){return this.displayName}set name(t){this.displayName=ro(t),this.refresh(!0,[],"")}threads(){return this.cache}ops(){return this.log.all()}onChange(t){return this.listeners.add(t),()=>this.listeners.delete(t)}comment(t,n){return this.enqueue(()=>this.write({kind:"create",anchor:t,text:fn(n)}))}reply(t,n){return this.enqueue(()=>this.write({kind:"reply",thread:this.find(t).thread,target:t,text:fn(n)}))}edit(t,n){return this.enqueue(async()=>{let{thread:o}=this.mine(t);await this.write({kind:"edit",thread:o,target:t,text:fn(n)})})}remove(t){return this.enqueue(async()=>{let{thread:n}=this.mine(t);await this.write({kind:"delete",thread:n,target:t})})}resolve(t){return this.enqueue(async()=>{await this.write({kind:"resolve",thread:this.thread(t)})})}reopen(t){return this.enqueue(async()=>{await this.write({kind:"reopen",thread:this.thread(t)})})}sign(t,n){if(!gr.test(t))throw new Error('pipeup: a signing purpose looks like "<add-on id>/<name>"');return Ct(this.options.identity,ve(`pipeup:${t}
|
|
2
|
-
${n}`))}flush(){return this.enqueue(()=>this.persist())}exportFile(){return to(this.options.doc,this.log.all(),this.options.key)}async importFile(t){return this.merge(await no(t,this.options.doc,this.options.key),"file")}merge(t,n){return t.length>hr?Promise.reject(new RangeError("pipeup: too many changes to merge at once")):this.enqueue(async()=>{let o=await this.log.add([...t]);this.unsaved.push(...o),o.length>0&&this.refresh(!0,o,n);try{await this.persist()}catch(r){throw o.length>0?new Ee(o[0].body.id,r,o.length):r}return o.length})}enqueue(t){let n=this.de.then(t);return this.de=n.catch(()=>{}),n}async write(t){let n=await this.log.append(this.options.identity,this.displayName,t);this.unsaved.push(n),this.refresh(!0,[n],"local");try{await this.persist()}catch(o){throw new Ee(n.body.id,o)}return n.body.id}async persist(){if(this.unsaved.length===0)return;let t=[...this.unsaved];await this.options.store.append(this.options.doc,t),this.unsaved=this.unsaved.filter(n=>!t.includes(n))}refresh(t,n=[],o=""){this.cache=this.log.threads(),this.comments.clear();let r=(s,l)=>{s.unnamed&&s.author===this.me&&this.displayName&&(s.name=this.displayName),this.comments.set(s.id,{comment:s,thread:l});for(let d of s.replies)r(d,l)};for(let s of this.cache)r(s.root,s.id);if(t)for(let s of this.listeners)try{s(this.cache,n,o)}catch(l){globalThis.reportError?.(l)}}find(t){let n=this.comments.get(t);if(!n)throw new Error("pipeup: there is no comment with that id");return n}mine(t){let n=this.find(t);if(n.comment.author!==this.me)throw new Error("pipeup: only the writer can change a comment");return n}thread(t){if(!this.cache.some(n=>n.id===t))throw new Error("pipeup: there is no thread with that id");return t}};function fn(e){let t=e.trim();if(!t)throw new Error("pipeup: a comment needs some words");if(t.length>Pt)throw new Error(`pipeup: comments are limited to ${Pt} characters`);return t}function ro(e){let t=e.replace(/\s+/g," ").trim();if(!t||t.length>oo)throw new Error(`pipeup: choose a name of 1 to ${oo} characters`);return t}var pt=class{docs=new Map;profile=null;async load(t){return[...this.docs.get(t)?.values()??[]]}async append(t,n){let o=this.docs.get(t);o||this.docs.set(t,o=new Map);for(let r of n)o.set(r.body.id,r)}async loadProfile(){return this.profile}async saveProfile(t){this.profile=t}async saveProfileIfAbsent(t){return this.profile||(this.profile=t),this.profile}},io="",vr="Reviewer";async function ut(e,t=io){let n=await e.loadProfile();if(n)return n.name===vr?{...n,name:""}:n;let o={identity:await sn(),name:t};return e.saveProfileIfAbsent(o)}var ft=class e{constructor(t){this.db=t}static open(t="pipeup"){return new Promise((n,o)=>{let r=indexedDB.open(t,1);r.onupgradeneeded=()=>{let s=r.result;s.createObjectStore("ops",{keyPath:["doc","id"]}).createIndex("doc","doc"),s.createObjectStore("meta")},r.onsuccess=()=>{let s=r.result;s.onversionchange=()=>s.close(),n(new e(s))},r.onerror=()=>o(r.error??new Error("pipeup: could not open local storage"))})}close(){this.db.close()}async load(t){return(await this.request("ops","readonly",o=>o.index("doc").getAll(t))).map(o=>o.op)}async append(t,n){if(n.length===0)return;let o=this.db.transaction("ops","readwrite"),r=o.objectStore("ops"),s=so(o);try{for(let l of n)r.put({doc:t,id:l.body.id,op:l})}catch(l){throw o.abort(),s.catch(()=>{}),l}await s}async loadProfile(){return await this.request("meta","readonly",t=>t.get("profile"))??null}async saveProfile(t){await this.request("meta","readwrite",n=>n.put(t,"profile"))}async saveProfileIfAbsent(t){let n=this.db.transaction("meta","readwrite"),o=n.objectStore("meta"),r=so(n),s=t,l=o.get("profile");return l.onsuccess=()=>{l.result?s=l.result:o.put(t,"profile")},await r,s}request(t,n,o){return new Promise((r,s)=>{let l=o(this.db.transaction(t,n).objectStore(t));l.onsuccess=()=>r(l.result),l.onerror=()=>s(l.error??new Error("pipeup: local storage request failed"))})}};function so(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error??new Error("pipeup: local storage write failed")),e.onabort=()=>n(e.error??new Error("pipeup: local storage write aborted"))})}function mt(e){let n=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_TEXT),o=[],r="";for(let s=n.nextNode();s;s=n.nextNode())o.push({node:s,start:r.length}),r+=s.data;return{text:r,nodes:o}}function mn(e,t,n){let r=(e.ownerDocument??e).createRange();return r.setStart(e,0),r.setEnd(t,n),r.toString().length}function hn(e,t,n){let o=ao(e,t,!1),r=ao(e,n,!0);if(!o||!r||n<t)return null;let s=o.node.ownerDocument.createRange();return s.setStart(o.node,o.offset),s.setEnd(r.node,r.offset),s}function ao(e,t,n){let o=e.nodes.find(r=>t>=r.start&&t<r.start+r.node.data.length+Number(n));return o&&{node:o.node,offset:t-o.start}}var lo=32,po=200,yr="p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,pre,figcaption,dt,dd,summary,caption";function uo(e){return e.nodeType===Node.ELEMENT_NODE?e:e.parentElement}function fo(e,t){for(let n=uo(e)?.closest("[data-pipeup-id]")??null;n;){if(!t.contains(n))return null;let o=n.getAttribute("data-pipeup-id")??"";if(o!==""&&o.length<=j.anchorId)return n;n=n.parentElement?.closest("[data-pipeup-id]")??null}return null}function It(e,t,n){return e.slice(t,n).replace(/^[\uDC00-\uDFFF]|[\uD800-\uDBFF]$/g,"")}function wr(e,t){let n=br(e,t);if(n.length>j.path)throw new Error("pipeup: this element is nested too deeply to comment on \u2014 give a nearby container a data-pipeup-id");return n}function mo(e){if(!cn(e))throw new Error("pipeup: could not describe this place on the page");return e}function Nt(e,t){let n=uo(e),o=n?.closest(yr)??null;return o&&t.contains(o)?o:n&&t.contains(n)?n:t}function br(e,t){if(e===t)return"";let n=[];for(let o=t;o&&o!==e;o=o.parentElement){let r=1;for(let s=o.previousElementSibling;s;s=s.previousElementSibling)s.tagName===o.tagName&&r++;n.unshift(`${o.tagName.toLowerCase()}:nth-of-type(${r})`)}return":scope > "+n.join(" > ")}function gn(e,t,n){if(!t.contains(e.commonAncestorContainer))throw new Error("pipeup: the selection is outside the commentable area");let o=fo(e.commonAncestorContainer,t),r=o??t,{text:s}=mt(r),l=mn(r,e.startContainer,e.startOffset),d=mn(r,e.endContainer,e.endOffset),m=s.slice(l,d);if(m==="")throw new Error("pipeup: select some text to comment on");if(m.length>j.quote)throw new Error(`pipeup: selections are limited to ${j.quote} characters`);let u=It(s,Math.max(0,l-lo),l),v=It(s,d,d+lo);return mo({...o?{id:o.getAttribute("data-pipeup-id")??""}:{},path:"",quote:{exact:m,prefix:u,suffix:v},...n?{view:n}:{},fingerprint:He(Nt(e.startContainer,t).textContent??""),snapshot:It(Re(u+m+v),0,po)})}function vn(e,t,n,o){let r=fo(e,t);return mo({...r?{id:r.getAttribute("data-pipeup-id")??""}:{},path:wr(r??t,e),...n?{point:{x:co(n.x),y:co(n.y)}}:{},...o?{view:o}:{},fingerprint:He(e.textContent??""),snapshot:It(Re(e.textContent??""),0,po)})}function co(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function ho(e,t,n){let o=Array.from({length:t.length+1},(l,d)=>d),r=[...o],s=[t.length];for(let l=1;l<=e.length;l++){r[0]=n?0:l;for(let d=1;d<=t.length;d++){let m=e.charCodeAt(l-1)===t.charCodeAt(d-1)?0:1;r[d]=Math.min(o[d]+1,r[d-1]+1,o[d-1]+m)}s.push(r[t.length]),[o,r]=[r,o]}return s}var xr=(e,t)=>ho(e,t,!1).pop();function go(e,t,n){let o=t.length;if(o===0)return null;let r=-1,s=1/0;if(ho(e,t,!0).forEach((m,u)=>{u&&m<s&&(s=m,r=u)}),s>n)return null;let l=Math.max(0,r-o),d=1/0;for(let m=Math.max(0,r-o-n);m<=Math.min(r,r-o+n);m++){let u=xr(e.slice(m,r),t);u<d&&(d=u,l=m)}return{start:l,end:r,distance:d}}var ht={state:"orphaned",element:null,range:null},Er=5e4,kr=300,Sr=12,Tr=":scope > ";function Ar(e,t){for(let n of e.querySelectorAll("[data-pipeup-id]"))if(n.getAttribute("data-pipeup-id")===t)return n;return null}function $t(e,t,n={}){let o=e.id?Ar(t,e.id):t;return e.quote?Mr(e,e.quote,o,t,n.fuzzy!==!1):Lr(e,o)}function Lr(e,t){if(!t)return ht;let n=t;if(e.path){if(!e.path.startsWith(Tr))return ht;try{n=t.querySelector(e.path)}catch{return ht}}return n?{state:He(n.textContent??"")===e.fingerprint?"attached":"moved",element:n,range:null}:ht}function Mr(e,t,n,o,r){let s=n??o,l=mt(s),d=Cr(l.text,t);if(d>=0){let m=hn(l,d,d+t.exact.length);if(m){let u=Nt(m.startContainer,o);return{state:n!==null&&He(u.textContent??"")===e.fingerprint?"attached":"moved",element:u,range:m}}}if(r){let m=s===o?l:mt(o);if(m.text.length<=Er&&t.exact.length>=Sr&&t.exact.length<=kr){let u=go(m.text,t.exact,Math.floor(t.exact.length/4)),v=u?hn(m,u.start,u.end):null;if(v)return{state:"moved",element:Nt(v.startContainer,o),range:v}}}return ht}function Cr(e,t){if(!t.exact)return-1;let n=-1,o=-1;for(let r=e.indexOf(t.exact);r!==-1;r=e.indexOf(t.exact,r+1)){let s=e.slice(Math.max(0,r-t.prefix.length),r),l=e.slice(r+t.exact.length,r+t.exact.length+t.suffix.length),d=Or(s,t.prefix)+Pr(l,t.suffix);d>o&&(n=r,o=d)}return n}function Pr(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function Or(e,t){let n=0;for(;n<e.length&&n<t.length&&e[e.length-1-n]===t[t.length-1-n];)n++;return n}var Ir={A:"Link",BUTTON:"Button",P:"Paragraph",LI:"List item",IMG:"Image",TABLE:"Table",TD:"Cell",TH:"Cell",FIGURE:"Figure",SVG:"Graphic",CANVAS:"Graphic",LABEL:"Label",INPUT:"Field",SELECT:"Field",TEXTAREA:"Field",SUMMARY:"Question",BLOCKQUOTE:"Quote",SECTION:"Section",H1:"Heading",H2:"Heading",H3:"Heading",H4:"Heading",H5:"Heading",H6:"Heading"},Nr=40;function Rt(e){return e.getAttribute("data-pipeup-label")||Ir[e.tagName.toUpperCase()]||"Block"}function wn(e){return yn(Re(e.getAttribute("aria-label")??e.getAttribute("alt")??e.innerText??e.textContent??""),Nr)}function De(e){let t=e.getAttribute("data-pipeup-label");if(t)return t;let n=wn(e);return n?`${Rt(e)} \xB7 ${n}`:Rt(e)}function bn(e,t,n){let o=e.id??null,r=e.quote?.exact??null,s=e.point?`${Math.round(e.point.x*100)}% across, ${Math.round(e.point.y*100)}% down the element`:null,l=t.element;if(t.state==="orphaned"||!l)return{where:`No longer on the page (it read: "${e.snapshot}")`,element:null,id:o,quote:r,pin:s};let d=[],m=e.view?.slide;if(m){let v=l.closest("[data-pipeup-slide]")?.querySelector("h1,h2,h3")?.textContent;d.push(`Slide ${m}`+(v?` "${yn(Re(v))}"`:""))}else{let v=Ht(e.view);v&&d.push(v);let x=$r(l,n);x&&d.push(`Section "${yn(Re(x.textContent??""))}"`)}let u=De(l);return d.push(u),{where:d.join(" \u203A "),element:u,id:o,quote:r,pin:s}}function Ht(e){return e?e.label||Object.entries(e).filter(([t,n])=>n&&t!=="slide").map(([,t])=>t).join(" \xB7 "):""}function $r(e,t){let n=null;for(let o of t.querySelectorAll("h1,h2,h3")){if(o===e||o.contains(e))break;if(o.compareDocumentPosition(e)&4)n=o;else break}return n}function yn(e,t=60){return e.length>t?e.slice(0,t-1)+"\u2026":e}var st=["Otter","Fox","Owl","Bear","Rabbit"],xn=["Red","Orange","Yellow","Green","Teal","Blue","Purple","Pink","Brown","Grey"];function vo(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),(t^t>>>16)>>>0}var En=e=>vo(e)%st.length,kn=e=>Math.floor(vo(e)/st.length)%xn.length,ye=e=>`${xn[kn(e)]} ${st[En(e)]}`,fe=e=>e.name||ye(e.author);var Rr="Each thread says where it is: the slide or section, the element (its data-pipeup-id attribute in the HTML), and the exact quoted text or pin position. Work through the open threads in order, and for each one say what you changed or why you did not.";function at(e,t){let n=Math.max(0,Math.round((t-e)/1e3));if(n<60)return"just now";let o=Math.round(n/60);if(o<60)return`${o}m ago`;let r=Math.round(o/60);return r<48?`${r}h ago`:`${Math.round(r/24)}d ago`}function Sn(e,t,n,o){return t==="ai"?yo(e,"## Comment thread",o,n):wo(e)}function Tn(e,t,n){let o=e.filter(d=>!d.thread.resolved);if(t==="text")return o.map(wo).join(`
|
|
3
|
-
`);let r=e.length-o.length,s=[`# Review comments: ${ie(n.title)}`,"",`- **Page:** ${ie(n.url)}`,`- **Exported:** ${n.exportedAt.toISOString()}`,`- **Open threads:** ${o.length}${r?` (${r} resolved, not included)`:""}`,"",Rr,"",""].join(`
|
|
4
|
-
`),l=n.exportedAt.getTime();return s+o.map((d,m)=>yo(d,`## Thread ${m+1}`,l)).join(`
|
|
5
|
-
`)}function ie(e){return e.replace(/\s+/g," ").trim()}function yo(e,t,n,o){let{thread:r,location:s}=e,l=r.root.replies.length,d=[`${t} \xB7 ${r.resolved?"resolved":"open"}`];if(d.push(`- **Thread:** ${r.id}`),o&&d.push(`- **Page:** ${ie(o)}`),d.push(`- **Where:** ${ie(s.where)}`),s.id){let m=ie(s.id.replace(/`/g,""));d.push(`- **Element:** \`[data-pipeup-id="${m}"]\`${s.element?` (${ie(s.element)})`:""}`)}s.quote&&d.push(`- **Quoted text:** "${ie(s.quote)}"`),s.pin&&d.push(`- **Pin:** ${ie(s.pin)}`),d.push(`- **Started by:** ${ie(fe(r.root))}, ${at(r.root.at,n)}${l?` \xB7 ${l} ${l===1?"reply":"replies"}`:""}`,"",`**${ie(fe(r.root))}** (${at(r.root.at,n)}): ${Dt(r.root," ")}`);for(let m of r.root.replies)d.push(`- **${ie(fe(m))}** (${at(m.at,n)}): ${Dt(m," ")} <!-- comment:${m.id} -->`);return d.join(`
|
|
6
|
-
`)+`
|
|
7
|
-
`}function wo(e){let{thread:t,location:n}=e,o=[ie(n.where)+(n.quote?`, on the text "${ie(n.quote)}"`:""),`${ie(fe(t.root))}: ${Dt(t.root," ")}`];for(let r of t.root.replies)o.push(` ${ie(fe(r))}: ${Dt(r," ")}`);return o.join(`
|
|
8
|
-
`)+`
|
|
9
|
-
`}function Dt(e,t){return e.deleted?"(deleted)":e.text.replace(/\r\n|\r|\n/g,`
|
|
10
|
-
`+t)+(e.edited?" (edited)":"")}var bo="0.5.0";function y(e,t={},...n){let o=document.createElement(e);for(let[r,s]of Object.entries(t))s===void 0||s===!1||(r==="class"?o.className=String(s):o.setAttribute(r,s===!0?"":s));for(let r of n)r!=null&&r!==!1&&o.append(r);return o}function Q(e,t){let n=e.getRootNode().activeElement;t&&n instanceof HTMLElement&&e.contains(n)&&n.blur(),e.inert=t}function Bt(e,t,n=null){let o=e.getRootNode().activeElement,r=!1;for(let s=t.length;s--;n=t[s])t[s].nextSibling!==n&&(r=!!e.insertBefore(t[s],n));return r&&o&&t.some(s=>s.contains(o))&&o.focus({preventScroll:!0}),r}var lt=()=>{let e=window.getSelection();return e&&!e.isCollapsed&&e.toString().trim()?e:null};function we(e,t){return e.length>t?e.slice(0,t-1)+"\u2026":e}function Be(e,t,n=4){e.style.left=`${t.left-n}px`,e.style.top=`${t.top-n}px`,e.style.width=`${t.width+n*2}px`,e.style.height=`${t.height+n*2}px`}var Hr=/\bhttps?:\/\/[^\s<>"'`]+/gi,Dr=`.,;:!?'"]}`,Br=2048,Fr=/[\u202A-\u202E\u2066-\u2069]/;function Vr(e){let t=0,n=0;for(let r of e)r==="("?t++:r===")"&&n++;let o=e.length;for(;o>0;){let r=e[o-1];if(r===")"&&n>t)n--;else if(!Dr.includes(r))break;o--}return e.slice(0,o)}function Ft(e){let t=[],n=0;for(let o of e.matchAll(Hr)){if(o[0].length>Br||Fr.test(o[0]))continue;let r=Vr(o[0]),s=o.index??0,l;try{let m=new URL(r);if(m.protocol!=="http:"&&m.protocol!=="https:")continue;l=m.href}catch{continue}s>n&&t.push(e.slice(n,s));let d=y("a",{href:l,target:"_blank",rel:"noopener noreferrer"},r);d.addEventListener("click",m=>m.stopPropagation()),t.push(d),n=s+r.length}return n<e.length&&t.push(e.slice(n)),t}var xo="http://www.w3.org/2000/svg",_r={comment:["M20.5 11.5a8 8 0 0 1-11.7 7.1L4 19.8l1.2-4.4A8 8 0 1 1 20.5 11.5z","M12.3 8.2v6.6M9 11.5h6.6"],send:["M21 12L3.5 4.5 6.2 12l-2.7 7.5zM6.2 12H13"],copy:["M10 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2z","M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"],resolve:["M5 12.5l4.5 4.5L19 7.5"],reopen:["M3 12a9 9 0 1 0 3-6.7","M3 4v5h5"],lines:["M4 7h16M4 12h10M4 17h7"],list:["M3 6.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M3 12a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M3 17.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M9 6.5h11M9 12h11M9 17.5h7"],expand:["M14 4h6v6M20 4l-6 6M10 20H4v-6M4 20l6-6M20 14v6h-6M20 20l-6-6M4 10V4h6M4 4l6 6"],pin:["M6 18v-6a6 6 0 1 1 6 6z"],shrink:["M20 10h-6V4M14 10l6-6M4 14h6v6M10 14l-6 6M14 20v-6h6M14 14l6 6M10 4v6H4M10 10L4 4"],bubble:["M20.5 11.5a8 8 0 0 1-11.7 7.1L4 19.8l1.2-4.4A8 8 0 1 1 20.5 11.5z"],close:["M6 6l12 12M18 6L6 18"],edit:["M4 20h4L19 9l-4-4L4 16z"]};function Z(e,t=15,n){let o=Le(_r[e],t);return n&&o.setAttribute("stroke-width",String(n)),o}function Le(e,t){let n=document.createElementNS(xo,"svg"),o={width:String(t),height:String(t),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[r,s]of Object.entries(o))n.setAttribute(r,s);for(let r of e){let s=document.createElementNS(xo,"path");s.setAttribute("d",r),n.append(s)}return n}var Vt=(e,t,n)=>`M${e} ${t}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 -${2*n} 0`,Ur={Otter:"M4 13.2C4 9.2 7.6 6.5 12 6.5s8 2.7 8 6.7-3.6 6.3-8 6.3-8-2.3-8-6.3zM5.6 9.6a1.8 1.8 0 1 1 2.7-2.3M18.4 9.6a1.8 1.8 0 1 0-2.7-2.3M9.2 11.6h.01M14.8 11.6h.01M11 14h2l-1 1zM9.8 15.8l-3.2.4M9.9 17l-2.7 1.1M14.2 15.8l3.2.4M14.1 17l2.7 1.1",Fox:"M3.5 4l5 3.5h7l5-3.5-1.5 8.5L12 20l-7-7.5zM9 12h.01M15 12h.01M12 17h.01",Owl:`M5 4.5l3 2.5h8l3-2.5V14a7 7 0 0 1-14 0z${Vt(7.4,11.5,1.9)}${Vt(12.8,11.5,1.9)}M11.3 14.6l.7 1 .7-1`,Bear:`${Vt(5,13.5,7)}M8.9 7.22A2.8 2.8 0 1 0 5.89 10.09M18.11 10.09A2.8 2.8 0 1 0 15.1 7.22M9.4 12.6h.01M14.6 12.6h.01M10.3 16.4c0-1 .8-1.6 1.7-1.6s1.7.6 1.7 1.6-.8 1.6-1.7 1.6-1.7-.6-1.7-1.6z`,Rabbit:`${Vt(6.5,15.5,5.5)}M9.6 10.5C8.2 6.5 8.4 2.5 9.8 2.5s2.4 3.5 1.6 7.5M14.4 10.5c1.4-4 1.2-8-.2-8s-2.4 3.5-1.6 7.5M10 15h.01M14 15h.01M11.3 17.3l.7.5.7-.5`};function Eo(e){let t=/[\p{L}\p{N}]/u.exec(e);if(!t)return"";let n=t[0].toUpperCase();return[...n].length===1?n:t[0]}var gt=(e,t)=>Eo(t)||ye(e);function Me(e,t){return y("span",{class:`av c${kn(e)}`,"aria-hidden":"true","data-animal":ye(e)},Eo(t)||Le([Ur[st[En(e)]]],24))}var qr=320;function _t(e,t){setTimeout(()=>{e.remove(),t?.()},qr)}function Ut(e){return requestAnimationFrame(()=>{e.offsetWidth,e.classList.add("in")}),e}var An=null,Ln=e=>{An=e},ko=()=>An?.note()??null,vt="pu-source";function qt(e){let t=y("textarea",{class:"input",rows:"1","aria-label":e.label}),n=y("button",{class:"send",type:"button","aria-label":"Send",title:"Send",inert:!0},Z("send")),o=y("span",{class:"tools"});o.hidden=!0;let r=y("div",{class:"row"},e.before,t,o,n),s=e.kind??"comment",l=!1,d=new Set,m=()=>{for(let c of[...d])c()},u=()=>{let c=t.value.trim()!=="";n.classList.toggle("show",c),n.inert=!c,t.style.height="auto",t.style.height=`${Math.max(27,t.scrollHeight)}px`},v=()=>{let c=-1,k=0,L=(p,w)=>{c<0&&(c=t.selectionStart,k=0);let M=t.value.slice(0,c),P=p&&M&&!/\s$/.test(M)&&!/^\s/.test(p)?" ":"";t.setRangeText(P+p,c,c+k,"end"),k=P.length+p.length,w&&(c=-1),u()};return{update:p=>L(p,!1),commit:p=>L(p,!0),cancel:()=>{c>=0&&k&&t.setRangeText("",c,c+k,"end"),c=-1,k=0,u()}}},x=new Map,T=()=>{let c=(An?.tools()??[]).filter(k=>k.available?.()!==!1);for(let[k,L]of x)c.some(p=>p.id===k)||(L.remove(),x.delete(k));for(let k of c){if(x.has(k.id))continue;let L=y("button",{class:"ib tool",type:"button","aria-label":k.label,title:k.label,"aria-pressed":"false"},Le(k.icon,15));L.addEventListener("mousedown",p=>p.preventDefault()),L.addEventListener("click",p=>{p.stopPropagation();try{k.press({kind:s,thread:e.thread?.()??null,text:()=>t.value,focus:()=>t.focus({preventScroll:!0}),connected:()=>r.isConnected,setPressed:w=>L.setAttribute("aria-pressed",String(w)),dictate:v,onEnd:w=>(d.add(w),()=>d.delete(w))})}catch(w){globalThis.reportError?.(w)}}),x.set(k.id,L),o.append(L)}o.hidden=x.size===0};T(),r.addEventListener(vt,T);let C=async()=>{let c=t.value.trim();if(!(!c||l)){l=!0;try{await e.V(c),n.matches(":focus")&&t.focus(),t.value="",u(),m()}catch{}finally{l=!1}}};return r.addEventListener("mousedown",c=>{c.target===t||n.contains(c.target)||o.contains(c.target)||(c.preventDefault(),t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}),t.addEventListener("input",u),t.addEventListener("keydown",c=>{c.stopPropagation(),c.key==="Enter"&&!c.shiftKey&&!c.isComposing?(c.preventDefault(),C()):c.key==="Escape"&&(c.preventDefault(),t.value="",u(),t.blur(),m(),e._?.())}),n.addEventListener("click",c=>{c.stopPropagation(),C()}),{element:r,input:t,focus:()=>t.focus({preventScroll:!0})}}var zt=1,So=["sync","menu","notify","note","composer","panel","styles","status","overlay","here","sign"],Kr=/^[a-z][a-z0-9-]{1,23}$/,zr=new Set(["local","file","page","user","pipeup","presence","sync"]),Wr=1e4,Wt=class{constructor(t,n,o){this.ctx=t;this.shadow=n;this.after=o;Ln({tools:()=>this.U,note:()=>[...this.X.values()].at(-1)??null})}G=0;$=[];X=new Map;J=new Map;U=[];Q=new Set;R=new Set;q=new Set;K=new Map;k=new Map;z=new Map;remote={n:0,who:new Set};last=0;timer=0;ce="";subscribe(t){return this.q.add(t),()=>void this.q.delete(t)}changed(t){t&&this.G++;for(let n of[...this.q])n(t);for(let n of this.ctx.t.querySelectorAll(".row, .draft"))n.dispatchEvent(new Event(vt))}H(t,n){let o=this.z.get(t)??this.z.set(t,new Set).get(t),r=()=>void(o.delete(r)&&n());return o.add(r),r}pe(){return[...this.J.values()].map(t=>t.text).join(" \xB7 ")}Ae(t,n){return this.$.push(n),this.changed(!0),{update:()=>this.changed(!1),remove:this.H(t,()=>{this.$.splice(this.$.indexOf(n),1),this.changed(!0)})}}ue(t,n,o){o?t.set(n,o):t.delete(n),this.changed(!1)}Le(t,n){return this.U.push(n),this.changed(!1),this.H(t,()=>{this.U.splice(this.U.indexOf(n),1),this.changed(!1)})}closed(){return this.ctx.state.hidden&&!this.ctx.state.c}Me(t,n){this.closed()?this.k.set(t,n):this.ctx.Z(n)}flush(){if(this.closed()||this.k.size===0)return;let t=[...this.k.values()].at(-1);this.k.clear(),this.ctx.Z(t)}Ce(){return this.shadow.activeElement instanceof HTMLTextAreaElement||[...this.ctx.t.querySelectorAll("textarea")].some(t=>t.value.trim()!=="")}Pe(t){this.ctx.state.hidden||this.ctx.w(t)}Oe(t,n){if(!(n==="local"||n==="")){for(let{body:o}of t)o.author===this.ctx.doc.me||o.kind!=="create"&&o.kind!=="reply"||(this.remote.n++,this.remote.who.add(o.name||ye(o.author)));this.fe()}}fe(t=Math.max(0,this.last+Wr-Date.now())){this.timer||!this.remote.n||(this.timer=window.setTimeout(()=>{if(this.timer=0,this.ctx.state.hidden||this.Ce())return this.fe(1e3);let{n,who:o}=this.remote;this.remote={n:0,who:new Set},this.last=Date.now(),this.ctx.w(`${n} new comment${n===1?"":"s"} from ${o.size===1?[...o][0]:`${o.size} people`}`)},t))}Ie(t){let n=this.K.get(t);return n||(n=y("div",{class:"ov","aria-hidden":"true","data-addon":t}),this.ctx.t.insertBefore(n,this.after.nextSibling),this.K.set(t,n)),n}Ne(t,n){let o=this.ctx.host.ownerDocument.defaultView?.CSSStyleSheet,r=o&&"replaceSync"in o.prototype&&"adoptedStyleSheets"in this.shadow?new o:null;r&&(r.replaceSync(n),this.shadow.adoptedStyleSheets=[...this.shadow.adoptedStyleSheets,r]);let s=r??this.shadow.appendChild(y("style",{},n));return this.H(t,()=>r?this.shadow.adoptedStyleSheets=this.shadow.adoptedStyleSheets.filter(l=>l!==r):s.remove())}he(t,n,o){return n.add(o),this.H(t,()=>n.delete(o))}$e(t,n){return this.he(t,this.Q,n)}Re(t,n){let o=this.he(t,this.R,n);return this.call(this.R,n,this.ge()),o}ge(){let{state:t}=this.ctx,n=this.shadow.activeElement;return{shown:!t.hidden,commentMode:t.l,allOpen:t.d,dark:this.ctx.t.classList.contains("dark"),view:this.ctx.p.view(),writing:n instanceof HTMLTextAreaElement?n.closest("[data-thread]")?.dataset.thread??"":null}}S(){for(let o of[...this.Q])this.call(this.Q,o);if(this.R.size===0)return;let t=this.ge(),n=JSON.stringify(t);if(n!==this.ce){this.ce=n;for(let o of[...this.R])this.call(this.R,o,t)}}call(t,n,...o){try{n(...o)}catch(r){t.delete(n),globalThis.reportError?.(r)}}He(t,n,o){let r=this.ctx.t,s=this.shadow.activeElement,l=y("button",{class:"ib",type:"button","aria-label":"Close"},Le(["M6 6l12 12M18 6L6 18"],15)),d=y("div",{class:"xp",role:"dialog","aria-label":o.label,"data-addon":t},y("div",{class:"hd"},y("span",{},o.label),l),y("div",{class:"xb"},n)),m=[...r.children].filter(x=>x instanceof HTMLElement&&!x.inert);for(let x of m)x.inert=!0;r.append(d),d.offsetWidth,d.classList.add("show");let u=x=>{x.key==="Escape"&&(x.stopPropagation(),x.preventDefault(),v())},v=this.H(t,()=>{window.removeEventListener("keydown",u,!0);for(let x of m)x.inert=!1;d.classList.remove("show"),d.inert=!0,window.setTimeout(()=>d.remove(),300),s?.focus?.({preventScroll:!0});try{o.onClose?.()}catch(x){globalThis.reportError?.(x)}});return l.addEventListener("click",v),window.addEventListener("keydown",u,!0),(d.querySelector("button, input, textarea, select, a[href]")??d).focus?.({preventScroll:!0}),{close:v}}clear(t){for(let n of[...this.z.get(t)??[]])n();this.z.delete(t),this.K.get(t)?.remove(),this.K.delete(t);for(let n of[this.X,this.J,this.k])n.delete(t);this.changed(!0)}destroy(){window.clearTimeout(this.timer),Ln(null),this.q.clear()}},wt=new Map,yt=null,Fe=(()=>{let e=globalThis.Pipeup;return e?.VERSION?e:null})();function Yr(){return Fe?Fe.addons():[...wt.values()].map(e=>({...e.info}))}function Kt(e){if(Fe)return Fe.use(e);let t=l=>console.warn(`pipeup: ${l}`),n=e;if(!n||typeof n!="object"||typeof n.id!="string"||!Kr.test(n.id)||zr.has(n.id)||typeof n.setup!="function"||typeof n.network?.says!="string")return t("an add-on needs an id of 2 to 24 lowercase letters, digits and dashes (not a reserved one), a setup function and a network statement");if(wt.has(n.id))return t(`the add-on "${n.id}" is already registered; the second is ignored`);let o={id:n.id,version:String(n.version??""),network:n.network,state:"waiting"},r=(n.needs??[]).find(l=>!So.includes(l));n.api!==zt?(o.state="off",o.reason=`needs add-on API ${String(n.api)}; this Pipeup has ${zt}`):r&&(o.state="off",o.reason=`this Pipeup has no ${r} slot`);let s={addon:e,info:o};wt.set(n.id,s),yt?.i&&o.state==="waiting"&&Ao(s,yt)}function To(){if(Fe)return!0;let e=globalThis,t=e.pipeupAddons;if(Array.isArray(t))for(let n of t)Kt(n);else if(t&&typeof t=="object"&&t.push!==Kt)return!1;return e.pipeupAddons={push:Kt},!0}function jr(e){return e instanceof Error?e.message:String(e)}async function Ao(e,t){let{addon:n,info:o}=e,r=new AbortController,s=new Set,{surface:l,doc:d}=t,m=()=>!r.signal.aborted,u=Object.assign(()=>{},{update(){},remove(){},close(){}}),v=p=>(...w)=>m()?p(...w):u,x={id:d.id,me:d.me,get name(){return d.name},threads:()=>d.threads(),ops:()=>d.ops(),onChange:p=>{let w=d.onChange(p);return s.add(w),()=>{w(),s.delete(w)}}},T=n.id,C={api:zt,version:t.version,document:x,root:t.root,ephemeral:t.ephemeral,signal:r.signal,has:p=>So.includes(p),off:p=>{k=String(p)},merge:p=>m()?d.merge(p,T):Promise.resolve(0),addMenuItem:v(p=>l.Ae(T,p)),notify:v(p=>l.Me(T,p)),announce:v(p=>l.Pe(p)),setComposerNote:v(p=>l.ue(l.X,T,p)),addComposerTool:v(p=>l.Le(T,p)),openPanel:v((p,w)=>l.He(T,p,w)),addStyles:v(p=>l.Ne(T,p)),setStatus:v(p=>l.ue(l.J,T,p)),overlay:()=>l.Ie(T),onFrame:v(p=>l.$e(T,p)),where:p=>l.ctx.p.view(p),isHere:p=>l.ctx.p.u(p),go:p=>l.ctx.p.W(p),onUi:v(p=>l.Re(T,p)),avatar:(p,w)=>{let M=Me(p,w);return M.classList.add("in"),M},sign:(p,w)=>d.sign(`${T}/${p}`,w)},c,k,L=()=>{if(m()){r.abort();for(let p of[...s])p();try{c?.()}catch(p){globalThis.reportError?.(p)}l.clear(T),o.state==="on"&&(o.state="waiting")}};e.stop=L;try{if(c=await n.setup(C),!m()){c?.();return}if(k!==void 0){L(),o.state="off",o.reason=k;return}o.state="on",delete o.reason}catch(p){o.state="failed",o.reason=jr(p),L(),o.state="failed",globalThis.reportError?.(p)}}function Lo(e){let t={...e,i:!0};yt=t;for(let n of wt.values())n.info.state==="waiting"&&Ao(n,t);return()=>{t.i=!1,yt===t&&(yt=null);for(let n of[...wt.values()].reverse())n.stop?.(),delete n.stop;e.surface.destroy()}}var Gr={code:"KeyC"},bt=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform)?"\u21E7\u2325C":"Shift+Alt+C",Mn="Shift+Alt+C";function Mo(e){return e.code===Gr.code&&e.shiftKey&&e.altKey&&!e.metaKey&&!e.ctrlKey&&!e.repeat&&!e.getModifierState("AltGraph")}function Xr(e){let t=y("button",{class:"me",type:"button",tabindex:"-1","aria-hidden":"true"});t.addEventListener("mousedown",p=>p.preventDefault());let n=qt({label:"Comment",kind:"comment",before:t,V:e.V,_:e._}),o=y("div",{class:"note"}),r=()=>{let p=ko();o.textContent=p??"",o.hidden=!p};r();let s=y("div",{class:"say"}),l=y("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"}),d=y("div",{class:"nf"},l),m=y("div",{class:"you"},s,d),u="",v=!1,x=()=>{let p=e.name(),w=p?"change":"add your name";if(t.title=p?"Change your name":"Add your name",!t.lastChild||u!==p){let P=Me(e.me,p),b=t.lastChild;b?(Ut(P),_t(b)):P.classList.add("in"),t.append(P),u=p}let M=y("button",{type:"button"},w);M.addEventListener("click",C),s.replaceChildren(y("span",{class:"nm"},p||`You're ${ye(e.me)}`)," \xB7 ",M)},T=p=>{m.classList.toggle("naming",p),Q(s,p),Q(d,!p)};function C(p){p.stopPropagation(),l.value=e.name(),T(!0),l.focus({preventScroll:!0}),l.select()}let c=()=>{T(!1),n.focus()};t.addEventListener("click",C),l.addEventListener("keydown",p=>{if(p.stopPropagation(),p.key==="Escape")p.preventDefault(),c();else if(p.key==="Enter"){p.preventDefault();let w=l.value.trim();if(!w||w===e.name())return c();if(v)return;v=!0,e.rename(w).finally(()=>{v=!1,x(),c()})}}),x(),T(!1);let k=y("div",{class:"ctx"},e.label),L=y("div",{class:"draft"},k,o,n.element,m);return L.addEventListener(vt,r),{element:L,ve:()=>{let{selectionStart:p,selectionEnd:w}=n.input;return()=>{n.focus(),n.input.setSelectionRange(p,w)}},ee:p=>{k.hidden=p},ye:p=>{k.textContent=p},focus:()=>n.focus(),De:()=>n.input.value.trim()===""}}function Yt(e,t){let n=Xr({label:t.label,me:e.doc.me,name:()=>e.c.name(),rename:o=>e.c.rename(o),V:o=>e.Be(o),_:()=>e.Fe()});return e.D(n),n}function jt(e,t){if(t.state==="orphaned"||!t.element||e.quote)return null;let n=t.element.getBoundingClientRect();if(!n.width&&!n.height)return null;if(e.point)return{x:n.left+e.point.x*n.width,y:n.top+e.point.y*n.height};let o=t.element.ownerDocument.createRange();o.selectNodeContents(t.element);let r=o.getBoundingClientRect();return{x:r.width?Math.min(n.right-8,r.right+6):n.right-8,y:(r.height?r.top:n.top)+8}}function xt(e){return e.range?[...e.range.getClientRects()]:[]}function Cn(e,t){let n=xt(t)[0];if(n)return n.top;if(t.state==="orphaned"||!t.element)return null;let o=t.element.getBoundingClientRect();return e.point?o.top+e.point.y*o.height:o.top}function Et(e,t){let n=xt(t).at(-1);if(n)return{x:n.left,y:n.bottom,below:!0};let o=jt(e,t);return o?{...o,below:!1}:null}function Co(e,t,n){for(let o of n)if(e>=o.left&&e<=o.right&&t>=o.top&&t<=o.bottom)return!0;return!1}function Po(e,t,n=10){let o=[...e].sort((d,m)=>d.T-m.T),r=new Array(o.length).fill(0),s=o.findIndex(d=>d.id===t),l=d=>o[d];if(s<0)o.forEach((d,m)=>{r[m]=m===0?d.T:Math.max(d.T,(r[m-1]??0)+l(m-1).height+n)});else{r[s]=l(s).T;for(let d=s+1;d<o.length;d++)r[d]=Math.max(l(d).T,(r[d-1]??0)+l(d-1).height+n);for(let d=s-1;d>=0;d--)r[d]=Math.min(l(d).T,(r[d+1]??0)-l(d).height-n)}return new Map(o.map((d,m)=>[d.id,r[m]??0]))}var kt=320,Je=300,Jr=480,Qe=()=>window.innerWidth<=Jr;function Gt(e){let t=window.innerWidth;return{width:e&&!Qe()?t-kt:t,height:window.innerHeight}}function Xt(e,t,n,o=12){let r,s;return e.below?(r=Math.min(e.x,n.width-t.width-o),s=e.y+8,s+t.height>n.height-o&&(s=e.y-t.height-40)):(r=e.x+14,r+t.width>n.width-o&&(r=e.x-t.width-28),s=Math.min(e.y-12,n.height-t.height-o)),{left:Math.max(o,r),top:Math.max(o,s)}}function Oo(e,t,n,o=12,r=44){let s=e.top-r>=8,l=e.top+e.height+8+(s?0:r),d=e.top-8-(s?r:0)-t.height,m=l+t.height<=n.height-o||d<o,u=m?l:d;return{above:!m,left:Math.max(o,Math.min(e.left,n.width-t.width-o)),top:Math.max(o,u)}}function Jt(e,t,n){let o=e.top-t.height-10;return o<8&&(o=e.top+e.height+10),{left:Math.max(8,Math.min(e.left+e.width/2-t.width/2,n.width-t.width-8)),top:o}}function Qt(e,t){let n=e.resolved.get(t.id);return n?.range?.startContainer??n?.element??null}var Ve=e=>(t,n)=>{let o=Qt(e,t),r=Qt(e,n),s=l=>l.anchor.point??{x:0,y:-1};return o!==r?!r||o&&o.compareDocumentPosition(r)&4?-1:1:s(t).y-s(n).y||s(t).x-s(n).x};var Zt=e=>`${e} ${e===1?"reply":"replies"}`;function dt(e,t,n){let o={...n},r=e.id,s=y("div",{class:"rbox always"},y("div",{},qt({label:"Reply",kind:"reply",thread:()=>r,V:p=>t.reply(r,p),_:t.close}).element)),l=y("div",{}),d=y("span",{class:"note"},"This thread was resolved. Your words are kept until you send or clear them.");d.hidden=!0,s.prepend(d);let m=y("div",{}),u=null,v=y("div",{},m,y("div",{class:"more"},l)),x=new Map,T=new Map,C=new Map,c=p=>{let w=gt(p.author,p.name),M=x.get(p.id),P=M?.e;if((!P||M.key!==w)&&(P=Ut(Me(p.author,p.name)),M)){let H=M.e;C.set(p.id,H),_t(H,()=>C.get(p.id)===H&&C.delete(p.id))}P.title=fe(p),T.set(p.id,{key:w,e:P});let b=C.get(p.id);return b?[b,P]:[P]},k=(p,w,M)=>{let P=y("button",{class:"ib",type:"button","aria-label":w,title:w},Z(p));return P.addEventListener("click",b=>{b.stopPropagation(),M()}),P};function L(p,w={}){Object.assign(o,w),r=p.id;let M=(o.now??Date.now)(),P=p.root.replies.length,b=K=>y("span",{class:"who"},`${fe(K)} \xB7 ${at(K.at,M)}`),H=K=>y("div",{class:K.deleted?"tx del":"tx"},...K.deleted?["Deleted"]:[...Ft(K.text),K.edited?" (edited)":""]),_=p.resolved?"Resolved"+(P?` \xB7 ${Zt(P)}`:""):P?Zt(P):"",F=y("div",{class:o.Y==="column"&&_?"ft has-rest":"ft"},o.Y==="column"&&_?y("span",{class:"rest"},_):null,y("span",{class:"hover"},b(p.root),y("span",{class:"acts"},k("copy","Copy thread",()=>t.copy(p.id)),p.resolved?k("reopen","Reopen",()=>void t.reopen(p.id)):k("resolve","Resolve",()=>void t.resolve(p.id))))),q=o.lost?y("div",{class:"ctx"},`${o.place||"No longer on the page"} \u2014 it read \u201C${we(o.lost,120)}\u201D`):o.quote?y("div",{class:"ctx"},`\u201C${we(o.quote,80)}\u201D`):null;T=new Map;let J=y("div",{class:"root"},...c(p.root),q,H(p.root),F);m.replaceWith(J),m=J,u?.remove(),u=P?y("div",{class:"rps"},...p.root.replies.map(K=>y("div",{class:"it"},...c(K),H(K),y("div",{class:"rft"},b(K))))):null,u&&l.prepend(u),x=T;let D=s.querySelector("textarea").value.trim()!=="";d.hidden=!(p.resolved&&D),p.resolved&&!D?s.remove():s.parentNode!==l&&l.append(s),v.className=p.resolved?"thread resolved":"thread",v.setAttribute("data-thread",p.id)}return L(e),{element:v,update:L}}var Qr="a,button,input,select,textarea,label,summary,[role=button],[contenteditable]",Zr=400;function Pn(e,t){let n=new Map,o=y("div",{class:"tip",role:"tooltip"}),r=y("div",{class:"mark"}),s=y("div",{class:"pop",role:"dialog","aria-label":"Comment thread"});o.inert=s.inert=!0,e.t.append(r,o,s);let l=y("div",{class:"bub pin ghost","aria-hidden":"true"}),d=[],m=null,u=null,v=null,x=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,T=0,C=null,c=null,k=null,L=0,p=A=>d.find(N=>N.id===A)??null,w=()=>t.te||e.state.d,M=!1,P=A=>{let N=e.resolved.get(A.id);return N?Et(A.anchor,N):null};function b(A,N,R){let{left:B,top:z}=Xt(N,{width:A.offsetWidth||R,height:A.offsetHeight},Gt(e.state.d));A.style.left=`${B}px`,A.style.top=`${z}px`}function H(A){let N=A&&w()&&e.state.i!==A?p(A):null,R=N?P(N):null;if(!N||!R){k=null,o.classList.remove("show"),Q(o,!0);return}if(k!==N.id){let B=N.root.replies.length;o.replaceChildren(y("div",{class:"tx clamp"},...N.root.deleted?["Deleted"]:Ft(N.root.text)),y("div",{class:"who"},`${fe(N.root)}${B?` \xB7 ${B} ${B===1?"reply":"replies"}`:""}`)),k=N.id}b(o,R,260),o.classList.contains("show")||o.offsetWidth,o.classList.add("show"),o.inert=!1}function _(A){C=A,H(A),e.L(A)}function F(A){if(window.clearTimeout(L),A!==null){_(A);return}L=window.setTimeout(()=>_(null),w()?Zr:0)}o.addEventListener("mouseenter",()=>window.clearTimeout(L)),o.addEventListener("mouseleave",()=>F(null)),o.addEventListener("click",A=>{A.stopPropagation();let N=k;N&&(window.clearTimeout(L),_(null),e.open(N))});function q(A){let N=n.get(A.id);if(N)return N;let R=y("button",{class:"bub",type:"button","data-thread":A.id});return R.addEventListener("mouseenter",()=>F(A.id)),R.addEventListener("mouseleave",()=>F(null)),R.addEventListener("click",B=>{B.stopPropagation(),H(null),e.open(A.id)}),e.t.insertBefore(R,r),n.set(A.id,R),R}let J=!1;function D(){let A=e.state.o,N=v&&A&&!A.anchor.quote&&!A.anchor.point?A.resolved.element:null;if(N){let{left:B,top:z,above:V}=Oo(N.getBoundingClientRect(),{width:s.offsetWidth||Je,height:s.offsetHeight},{width:window.innerWidth,height:window.innerHeight}),U=v?.above!==null&&v?.above!==V;if(v&&(v.above=V),U&&oe())return;s.style.left=`${B}px`,s.style.top=`${z}px`;return}let R=v&&A?Et(A.anchor,A.resolved):m?P(m):null;R&&b(s,R,Je)}let K=A=>e.state.l&&!A.anchor.quote&&!A.anchor.point;function oe(A=()=>{}){return window.clearTimeout(T),x?(s.classList.remove("show"),T=window.setTimeout(()=>{A(),D(),s.classList.add("show")},220),!0):(A(),s.classList.add("glide"),T=window.setTimeout(()=>s.classList.remove("glide"),450),!1)}function ke(){if(!w())return null;let A=e.state.o;return A?A.anchor.quote||A.anchor.point||e.state.l?null:A.resolved.element:!m||m.anchor.quote||m.anchor.point?null:e.resolved.get(m.id)?.element??null}function se(A){d=A;let N=new Set;for(let V of A){if(!e.B(V)||V.anchor.quote)continue;let U=e.resolved.get(V.id);if(!U||U.state==="orphaned")continue;N.add(V.id);let W=q(V);W.classList.toggle("done",V.resolved),W.classList.toggle("on",e.state.i===V.id),W.classList.toggle("pin",V.anchor.point!==void 0);let ee=`Comment on ${De(U.element)}: ${we(V.root.text,60)}`;W.getAttribute("aria-label")!==ee&&W.setAttribute("aria-label",ee)}Bt(e.t,A.filter(V=>N.has(V.id)).sort(Ve(e)).map(V=>n.get(V.id)),r);for(let[V,U]of n)N.has(V)||(U.classList.remove("in"),n.delete(V),window.setTimeout(()=>U.remove(),300));H(C),M!==e.state.d&&s.classList.contains("show")&&!x&&oe(),M=e.state.d;let R=t.te?e.state.o:null;if(R){let V=R.anchor.point??R.resolved.element;v?.of!==R?(window.clearTimeout(T),s.classList.remove("glide"),v={s:Yt(e,R),of:R,at:V,above:null},v.s.ee(K(R)),s.replaceChildren(v.s.element),s.inert=!1,v.s.focus(),m=null,u=null,D(),s.classList.add("show")):v&&(v.at!==V&&(v.at=V,v.above=null,oe(()=>v?.s.ye(R.label))),v.s.ee(K(R)));let U=!e.p.u(R.anchor.view);U!==J&&(J=U,s.classList.toggle("show",!U),s.inert=U,U||D());return}v&&(window.clearTimeout(T),s.classList.remove("glide"),v=null,J=!1,e.D(null));let B=w()&&e.state.i?p(e.state.i):null;if(!B||!e.B(B)){m=null,u=null,s.classList.remove("show"),Q(s,!0);return}let z=B.anchor.quote?.exact??null;!m||!u||m.id!==B.id?(u=dt(B,e.j,{Y:"popover",quote:z}),s.replaceChildren(u.element),m=B,D(),s.classList.add("show"),s.inert=!1):m!==B&&(u.update(B,{quote:z}),m=B)}function le(){for(let[B,z]of n){let V=p(B),U=e.resolved.get(B),W=V&&U?jt(V.anchor,U):null;if(!W||W.y<-40||W.y>window.innerHeight+40){z.style.visibility="hidden";continue}z.style.visibility="",z.style.left=`${W.x}px`,z.style.top=`${W.y}px`,z.classList.contains("in")||(z.offsetWidth,z.classList.add("in"))}let A=e.state.o,N=A?.anchor.point&&e.p.u(A.anchor.view)?jt(A.anchor,A.resolved):null;N?(l.style.left=`${N.x}px`,l.style.top=`${N.y}px`,l.classList.contains("in")||(e.t.insertBefore(l,r),l.offsetWidth,l.classList.add("in"))):l.classList.contains("in")&&(l.classList.remove("in"),window.setTimeout(()=>l.classList.contains("in")||l.remove(),300)),s.classList.contains("show")&&D();let R=ke();r.classList.toggle("show",R!==null),R&&Be(r,R.getBoundingClientRect(),4)}let de=A=>{if(e.m(A)){let R=A.composedPath()[0];c!==null&&!(R instanceof Element&&R.closest(".tip,.bub"))&&F(null),c=null;return}let N=e.ne(A.clientX,A.clientY)?.id??null;N!==c&&(c=N,F(N))},Se=A=>{if(e.m(A))return;let N=window.getSelection();if(N&&!N.isCollapsed||(e.state.l?A.altKey:A.target instanceof Element&&A.target.closest(Qr)))return;let R=e.ne(A.clientX,A.clientY);R&&(e.we(A),H(null),e.open(R.id))};return window.addEventListener("pointermove",de,{capture:!0,passive:!0}),window.addEventListener("click",Se,!0),{f:se,S:le,destroy(){window.clearTimeout(L),window.clearTimeout(T),window.removeEventListener("pointermove",de,!0),window.removeEventListener("click",Se,!0),e.D(null);for(let A of n.values())A.remove();l.remove(),o.remove(),r.remove(),s.remove()}}}var ei={display:"block",position:"static",clips:!1,off:!1},ti=48,ni="button link img figure region list listitem tab tabpanel article navigation complementary banner contentinfo form search group dialog menu menuitem checkbox switch radio slider textbox combobox option row cell heading table".split(" ").map(e=>`[role=${e}]`),oi=["button,a,input,select,textarea,label,summary,details,img,svg,canvas,video,picture,figure,figcaption,table,th,td","li,ul,ol,dl,dt,dd,p,h1,h2,h3,h4,h5,h6,blockquote,pre","section,article,aside,nav,header,footer,main,form,fieldset",...ni].join(","),On="a,button,label,summary,[role=button],[role=link],[role=tab],[role=option],[role=menuitem]",ri=`${On},input,select,textarea,img,svg,canvas,video,picture,[role=img]`,Io=24,ii=.6,en=2,In=(e,t)=>Math.abs(e.left-t.left)<=en&&Math.abs(e.top-t.top)<=en&&Math.abs(e.width-t.width)<=en&&Math.abs(e.height-t.height)<=en;function No(e,t){let n=t.s(e);if(n.width<2||n.height<2)return!1;if(e.hasAttribute("data-pipeup-id"))return!0;let o=t.oe();return n.width*n.height<=ii*o.width*o.height&&(e.matches(oi)||t.Ve(e)||e.childElementCount>1&&!e.parentElement?.closest(On)&&t._e(e))}function St(e,t,n){if(e===t||!t.contains(e)||e.closest("[data-pipeup-ignore]"))return null;let o=null;for(let s=e;s&&s!==t&&!o;s=s.parentElement)No(s,n)&&(o=s);if(!o||o.hasAttribute("data-pipeup-id"))return o;let r=n.s(o);for(let s=o.parentElement;s&&s!==t&&In(n.s(s),r);s=s.parentElement)if(s.hasAttribute("data-pipeup-id"))return s;return o}function Nn(e,t,n){let o=n.s(e);for(let r=e.parentElement;r&&r!==t;){let s=St(r,t,n);if(!s)return null;if(!In(n.s(s),o))return s;r=s.parentElement}return null}function $o(){return{s:e=>e.getBoundingClientRect(),Ve:e=>{let t=getComputedStyle(e),n=t.backgroundColor!=="transparent"&&!/,\s*0\)$/.test(t.backgroundColor),o=["top","right","bottom","left"].some(r=>parseFloat(t.getPropertyValue(`border-${r}-width`))>0);return n||o||t.backgroundImage!=="none"||t.boxShadow!=="none"},_e:e=>/^(inline-)?(flex|grid)$/.test(getComputedStyle(e).display),flow:e=>{let t=getComputedStyle(e),n=[t.overflowX,t.overflowY];return{display:t.display,position:t.position,clips:n.some(o=>o==="hidden"||o==="clip")&&!n.some(o=>o==="auto"||o==="scroll")&&e!==document.documentElement&&e!==document.body,off:t.pointerEvents==="none"}},oe:()=>({width:innerWidth,height:innerHeight})}}var si=(e,t)=>e.left<t.left+t.width&&t.left<e.left+e.width&&e.top<t.top+t.height&&t.top<e.top+e.height,ai=(e,t)=>{let n=Math.max(e.left,t.left),o=Math.max(e.top,t.top);return{left:n,top:o,width:Math.max(0,Math.min(e.left+e.width,t.left+t.width)-n),height:Math.max(0,Math.min(e.top+e.height,t.top+t.height)-o)}};function $n(e,t,n=()=>!0){let o=[],r=(s,l,d,m,u,v)=>{for(let x of s.children){if(x.hasAttribute("data-pipeup-ignore")||x.getAttribute("aria-hidden")==="true"||!n(x))continue;let T=t.flow?.(x)??ei,C=x.offsetParent,c=T.position==="fixed"||T.position==="absolute"&&!!m&&!(C&&m.contains(C)),k=c?null:d,L=t.s(x),p=L.width>0&&L.height>0;if(k&&p&&!si(L,k))continue;let w=x.matches(On),P=(T.display.startsWith("inline")||v)&&!x.matches(ri)&&(T.display==="inline"||L.height<=ti),b=L.width<=Io&&L.height<=Io,H=x.hasAttribute("data-pipeup-id")||!u&&!T.off&&!P&&!(b&&!w),_=l;H&&No(x,t)&&(l&&In(t.s(l.e),L)?(x.hasAttribute("data-pipeup-id")||!l.e.hasAttribute("data-pipeup-id"))&&(l.e=x):o.push(_={e:x,I:l,E:0}));let F=T.clips&&p;r(x,_,F?k?ai(k,L):L:k,F?x:c?null:m,u||w,/^inline-(flex|grid)$/.test(T.display)||v&&/(flex|grid)$/.test(T.display))}};r(e,null,null,null,!1,!1);for(let s=o.length-1;s>=0;s--){let l=o[s];l.I&&(l.I.E=Math.max(l.I.E,l.E+1))}return o}var Ze=(e,t)=>e.filter(n=>n.E<=t&&(!n.I||n.I.E>t)),Ro=(e,t)=>e.filter(n=>n.I===t);var tn="a,button,summary,[role=button],[role=link],[role=switch],[role=tab],[role=checkbox],input[type=checkbox],input[type=radio],input[type=submit],input[type=button],input[type=reset]",li=`${tn},input,select,textarea,[contenteditable]:not([contenteditable=false]),[tabindex]:not([tabindex="-1"])`,Ho=["click","dblclick","auxclick","submit","contextmenu","dragstart"],Do=[...["over","out","enter","leave","down","up"].flatMap(e=>[`pointer${e}`,`mouse${e}`]),"mousemove","touchstart","touchmove","touchend","touchcancel"],di=400,Rn="Tab moves between blocks \xB7 \u2191 \u2193 change level \xB7 Enter comments \xB7 Esc to finish \xB7 F7 selects text",ci=4,pi=150;function Bo(e){let t=$o(),n=y("span",{hidden:!0},Rn),o=y("div",{class:"pick"},n),r=[0,1].map(()=>{let i=y("div",{class:"km",tabindex:"-1",role:"button"},y("span",{hidden:!0}),y("span",{hidden:!0}));return i.inert=!0,i.addEventListener("keydown",rt),i.addEventListener("click",f=>{f.stopPropagation(),je()}),i.addEventListener("focus",()=>o.classList.add("kf")),i.addEventListener("blur",()=>o.classList.remove("kf")),i}),s=y("span",{class:"lbl"}),l=(i,f,a,g)=>{let S=y("button",{class:"nb",type:"button","aria-label":i,title:f},Z(a,16));return S.addEventListener("click",O=>{O.stopPropagation(),g()}),S},d=l("Around it","Select the block around it","expand",xe),m=l("Inside it","Select a block inside it","shrink",Ie),u=l("Pin","Pin its centre","pin",()=>e.be(()=>W(c??b,{x:.5,y:.5}))),v=y("div",{class:"namebar",role:"group","aria-label":"Chosen block"},s,d,m,u);v.inert=!0;let x=e.t.querySelector(".launch");for(let i of[o,...r,v])e.t.insertBefore(i,x);v.addEventListener("mousedown",i=>i.preventDefault());let T=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,C=null,c=null,k=null,L=null,p=0,w=()=>{},M=null,P=()=>{},b=null,H=0,_=0,F=!1,q=null,J=null,D=null,K=0,oe=-1,ke=!0,se=null,le=null,de=i=>!e.m(i)&&!(i.target instanceof Element&&i.target.closest("[data-pipeup-ignore]"));function Se(){L&&(o.classList.toggle("glide",performance.now()<p),Be(o,L.getBoundingClientRect(),4))}function A(){if(!M)return;v.classList.toggle("glide",performance.now()<p&&v.classList.contains("show"));let{left:i,top:f}=Jt(M.getBoundingClientRect(),{width:v.offsetWidth||200,height:v.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});v.style.left=`${i}px`,v.style.top=`${f}px`}function N(i,f){L=i,p=f?performance.now()+di:0,Se(),o.classList.add("show")}function R(i,f){let a=getComputedStyle(i);if(a.opacity==="0")return f(),()=>{};let g=0,S=()=>{window.clearTimeout(g),i.removeEventListener("transitionend",$)},O=()=>{S(),f()},$=X=>{X.target===i&&X.propertyName==="opacity"&&O()},Y=Math.max(...a.transitionDuration.split(",").map(X=>parseFloat(X)*1e3||0));return g=window.setTimeout(O,Y+100),i.addEventListener("transitionend",$),S}function B(i){if(i!==C){if(C=i,w(),!i){o.classList.remove("show");return}getComputedStyle(o).opacity==="0"?N(i,!1):T?(o.classList.remove("show"),w=R(o,()=>N(i,!1))):N(i,!0)}}function z(i){c=i,o.classList.toggle("on",i!==null),B(i),V(i)}function V(i){P(),v.inert=!i,i?T?(v.classList.remove("show"),P=R(v,()=>U(i))):U(i):(v.classList.remove("show"),M=null)}function U(i){s.textContent=s.title=De(i),d.hidden=Nn(i,e.root,t)===null,m.hidden=(b?We(i).length:$n(i,t,me).length)===0;let f=v.classList.contains("show");M=i,A(),f||(v.offsetWidth,v.classList.add("show"))}function W(i,f){let a;try{a=vn(i,e.root,f,e.p.view(i))}catch(O){e.re(O);return}let g={anchor:a,label:f?`Pin on ${De(i).replace(/^[A-Z](?=[a-z])/,O=>O.toLowerCase())}`:De(i),ranges:[],resolved:{state:"attached",element:i,range:null}},S=e.state.o;b&&(b=i,oe=-1),z(f?null:i),k=S??g,e.Ue(g),e.w(f?g.label:`Commenting on ${g.label}`)}function ee(i){e.be(()=>W(i))}function _e(i){let f=(i.target instanceof Element?St(i.target,e.root,t):null)??e.root;f!==e.root&&(q=f);let a=f.getBoundingClientRect();a.width&&a.height&&W(f,{x:(i.clientX-a.left)/a.width,y:(i.clientY-a.top)/a.height})}function be(i){let f=window.getSelection();if(f&&!f.isCollapsed)return;if(e.state.o&&(i.altKey||!e.C())){e.N();return}if(!i.altKey&&e.ne(i.clientX,i.clientY))return;if(e.state.i&&e.open(null),b&&i.detail&&he(),i.altKey){_e(i);return}let a=i.target instanceof Element?St(i.target,e.root,t):null;a&&(q=a),a?W(a):(e.N(),z(null))}let Ue=i=>{if(e.m(i))return;if(!de(i)){c||B(null);return}if(i.stopPropagation(),c||e.state.o)return;let f=!lt()&&i.target instanceof Element?St(i.target,e.root,t):null;if(b){if(!f||f===b||(K+=Math.abs(i.movementX)+Math.abs(i.movementY),K<=ci))return;he()}f&&(q=f),B(f)},Ce=()=>{lt()&&(b&&he(),c||B(null))},te=i=>{de(i)&&(i.stopPropagation(),(i.type==="pointerdown"||i.type==="mousedown")&&i.target instanceof Element&&i.target.closest(li)&&i.preventDefault())},qe=i=>{if(!de(i))return;let f=i.target;if((f===le||f.form&&f.form===le?.form)&&(i.type==="submit"||i.type==="click"&&!i.detail)){le=i.type==="click"&&f.type==="submit"?f.form:null;return}i.preventDefault(),i.stopPropagation(),i.type==="click"&&!e.state.c&&!e.qe(i)&&be(i)},G=i=>{if(le=null,h="",i.key==="Tab"&&Te(i))return i.preventDefault(),i.stopPropagation(),h=i.key,e.N(),e.state.i&&e.open(null),e.state.c&&(e.state.c=!1,e.f()),Oe(i.shiftKey?-1:1);if(!(!de(i)||!(i.target instanceof Element)))if((i.key==="Enter"||i.key===" ")&&i.target.closest(tn)){if(!b){le=i.target;return}i.preventDefault(),i.stopPropagation()}else i.key==="Enter"&&!b&&i.target.form&&(le=i.target)},Te=i=>{if(i.ctrlKey||i.metaKey||i.altKey||i.isComposing)return!1;let f=i.composedPath()[0];return!(f instanceof Element)||r.some(a=>a===f)?!1:e.m(i)?!!f.closest(".launch,.menu")&&!f.closest("input,textarea,select,[contenteditable]"):!i.composedPath().some(a=>a instanceof Element&&a.hasAttribute("data-pipeup-ignore"))},ce=()=>e.t.getRootNode().activeElement,pe=()=>r.some(i=>i===ce()),me=i=>(i.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0})!==!1||getComputedStyle(i).display==="contents")&&e.p.u(e.p.view(i)),re=()=>(se?.some(i=>!i.e.isConnected)&&(se=null),se??=$n(e.root,t,me)),Pe=i=>re().find(f=>f.e===i),ae=(i,f=!1)=>{let a=i.getBoundingClientRect();return a.bottom>0&&a.top<window.innerHeight&&(!f||a.top>=0)},Ke=()=>{let i=Ze(re(),0);return i.find(f=>ae(f.e,!0))??i.find(f=>ae(f.e))??i[0]},ze=i=>e.doc.threads().filter(f=>e.B(f)&&i.contains(Qt(e,f))).sort(Ve(e));function nt(i,f){let[a,g]=i.children,S=Ze(re(),H),O=ze(f).length;a.textContent=`${Rt(f)}, ${S.findIndex(X=>X.e===f)+1} of ${S.length}${O?`, has ${O} comment${O===1?"":"s"}`:""}`;let $=(f.innerText??f.textContent??"").length<=pi;g.textContent=wn(f);let Y=ke?[n]:[];ke=!1,i.ariaLabelledByElements!==void 0?(i.ariaLabelledByElements=$?[a,f]:[a,g],i.ariaDescribedByElements=$?Y:[...Y,f]):i.setAttribute("aria-label",`${a.textContent}, ${g.textContent}`)}function ne(i,f=!0){K=0;let a=re(),g=a.find(O=>O.e===i);if(g&&!Ze(a,H).includes(g)&&(H=g.E),i!==b&&(oe=-1),i!==c&&(c=null),b=i,B(i),V(i),i.scrollIntoView({block:"nearest",inline:"nearest",behavior:T?"auto":"smooth"}),!f)return;e.Ke();let S=r[_^=1];nt(S,i),Be(S,i.getBoundingClientRect(),4),S.inert=!1,S.focus({preventScroll:!0}),r[_^1].inert=!0}function ue(){se=null;let i=document.activeElement;J=ce()??i;let f=Pe(q),a=f??(i&&i!==document.body&&e.root.contains(i)&&!i.closest("[data-pipeup-ignore]")?re().filter(g=>g.e.contains(i)).pop():void 0)??Ke();return a?(f||(H=a.E),F=!0,ne(a.e),!0):!1}function he(){let i=pe();q=b,b=null,B(null),V(null);for(let f of r)Q(f,!0);return i}function ot(){let i=J;i&&i!==document.body&&i.isConnected&&i.focus?.({preventScroll:!0}),(!i||i===document.body||!i.matches?.(":focus"))&&e.t.querySelector(".launch .mode")?.focus({preventScroll:!0})}function We(i){let f=Pe(i);return f?Ro(re(),f):[]}function Ye(i){let f=Ze(re(),H),a=f.findIndex(S=>S.e===b),g=f[a<0?i>0?0:f.length-1:(a+i+f.length)%f.length];g&&ne(g.e)}function Oe(i){if(b)return Ye(i);se=null;let f=document.activeElement;J=ce()??f;let a=q?.isConnected?q:null,g=a&&Pe(a),S;if(g){H=g.E;let O=Ze(re(),H),$=O.indexOf(g);S=O[($+i+O.length)%O.length]}else if(a){H=0;let O=Ze(re(),0),$=X=>(a.compareDocumentPosition(X.e)&Node.DOCUMENT_POSITION_FOLLOWING)!==0,Y=X=>X.e.contains(a);i>0?S=O.find(X=>$(X)&&!Y(X))??O[0]:S=O.filter(X=>!$(X)&&!Y(X)).pop()??O[O.length-1]}else S=Ke(),S&&(H=S.E);if(!S)return e.w("Nothing here to comment on");F=!0,ne(S.e)}function xe(){let i=c??b,f=i&&Nn(i,e.root,t);if(!f)return e.w("Nothing around it");if((!D||!i.contains(D))&&(D=i),c)return ee(f);ne(f)}function Ie(){let i=c??b,f=i?We(i):[],a=f.find(g=>D&&g.e.contains(D))??f.find(g=>ae(g.e))??f[0];if(!a)return e.w("Nothing inside it");c?ee(a.e):ne(a.e)}function je(i=!1){if(!b)return;if(e.state.o&&!e.C())return e.ze();if(!i)return W(b);let f=ze(b);if(!f.length)return e.w("No comments on this block");oe=(oe+1)%f.length,e.open(f[oe].id),f.length>1&&e.w(`Comment ${oe+1} of ${f.length} on this block`)}function rt(i){if(["Tab","ArrowUp","ArrowDown","Enter"," ","Escape"].includes(i.key)&&!(i.key.startsWith("Arrow")&&(i.metaKey||i.ctrlKey||i.altKey))){if(i.preventDefault(),i.stopPropagation(),h=i.key,i.key==="Escape")return void e.ie();if(i.key==="Enter"||i.key===" ")return je(i.shiftKey&&i.key==="Enter");i.key==="Tab"&&e.N(),e.state.i&&e.open(null),i.key==="Tab"?Ye(i.shiftKey?-1:1):i.key==="ArrowUp"?xe():Ie()}}let Ne=()=>{let i=ce();return i?!!i.closest("[inert]"):!document.activeElement||document.activeElement===document.body},h="",E=!1,I=i=>{E&&window.removeEventListener("keyup",I,!0),i.key===h&&(h="",i.preventDefault(),i.stopPropagation())};window.addEventListener("keyup",I,!0),window.addEventListener("pointermove",Ue,!0),document.addEventListener("selectionchange",Ce);for(let i of Do)window.addEventListener(i,te,!0);for(let i of Ho)window.addEventListener(i,qe,!0);return window.addEventListener("keydown",G,!0),{ie(){return c?(z(null),!0):!1},se:()=>b!==null,We:()=>F&&!b,xe:ue,ae(){b&&!pe()&&ne(b)},f(){if(se=null,b&&!(b.isConnected&&me(b))){let a=Ke();a?ne(a.e,pe()||Ne()):he()}let i=e.t.querySelector(".launch");if(i&&v.nextElementSibling!==i&&!pe()&&!v.contains(ce()))for(let a of[o,...r,v])e.t.insertBefore(a,i);let f=e.state.o;k&&f!==k?(k=null,z(null),b&&ne(b,Ne())):f&&!k&&(C||c)&&z(null)},S(){Se(),A(),b&&Be(r[_],b.getBoundingClientRect(),4)},destroy(){he()&&ot();for(let i of r)i.remove();w(),P(),E=!0,h||window.removeEventListener("keyup",I,!0),window.removeEventListener("pointermove",Ue,!0),document.removeEventListener("selectionchange",Ce);for(let i of Do)window.removeEventListener(i,te,!0);for(let i of Ho)window.removeEventListener(i,qe,!0);window.removeEventListener("keydown",G,!0),o.classList.remove("show"),v.classList.remove("show"),Q(v,!0),R(o,()=>o.remove()),R(v,()=>v.remove())}}}var ui=300,fi=32,mi=220,Tt=320,hi=24,Fo=24;function Hn(e,t=!1){let n=e.ownerDocument.documentElement,o=n.getAttribute("data-pipeup-layout");if(o==="bubbles"||e.querySelector("[data-pipeup-slide]"))return null;let r=e.querySelector("article, main, [role=main]")??(o==="column"?e:null);if(!r)return null;if(n.hasAttribute("data-pipeup-reserve")){let d=n.clientWidth,u=getComputedStyle(r).maxWidth,v;return u.endsWith("px")?v=parseFloat(u):u.endsWith("%")?v=parseFloat(u)/100*d:v=r.getBoundingClientRect().width,o!=="column"&&d<v+Tt-(t?hi:0)?null:{x:d-Tt+Fo,width:Tt-2*Fo}}let s=r.getBoundingClientRect().right;if(window.innerWidth-s<ui&&o!=="column")return null;let l=s+fi;return{x:l,width:Math.max(220,Math.min(300,window.innerWidth-l-16))}}function Dn(e,t){let n=e.resolved.get(t.id);return!n||n.state==="orphaned"&&!e.k.has(t.id)}function Vo(e){let t=y("div",{class:"col"});e.t.append(t);let n=new Map,o=null,r=new ResizeObserver(()=>d()),s=c=>Dn(e,c);function l(c){let k=e.resolved.get(c.id),L=k?Cn(c.anchor,k):null;return L===null?Number.POSITIVE_INFINITY:L+window.scrollY-4}function d(){let c=[],k=[];for(let[P,b]of n){let H=l(b.thread);if(Number.isFinite(H))b.placed=H;else if(e.k.has(P)){if(b.placed===null){b.e.classList.add("wait");continue}H=b.placed}Number.isFinite(H)?c.push({id:P,T:H,height:b.e.offsetHeight}):k.push({id:P,height:b.e.offsetHeight})}let L=e.state.o,p=L?Cn(L.anchor,L.resolved):null;o&&p!==null&&c.push({id:"draft",T:p+window.scrollY-4,height:o.e.offsetHeight});let w=Po(c,o?"draft":e.state.i),M=Math.max(0,...c.map(P=>(w.get(P.id)??0)+P.height))+24;for(let P of k)w.set(P.id,M),M+=P.height+10;for(let[P,b]of n){if(b.e.classList.contains("wait")){if(!w.has(P))continue;b.e.style.transition="none",b.e.style.transform=`translateY(${Math.round(w.get(P))}px)`,b.e.offsetWidth,b.e.style.transition="",b.e.classList.remove("wait");continue}b.e.style.transform=`translateY(${Math.round(w.get(P)??0)}px)`}o&&(o.e.style.transform=`translateY(${Math.round(w.get("draft")??0)}px)`)}function m(c,k){c.thread=k,c.lost=s(k),c.view.update(k,{lost:c.lost?k.anchor.snapshot:null})}function u(c){let k=s(c),L=dt(c,e.j,{Y:"column",lost:k?c.anchor.snapshot:null}),p=y("div",{class:"th","data-thread":c.id},y("button",{class:"opn sr",type:"button","data-thread":c.id}),L.element);return p.style.transition="none",p.addEventListener("mouseenter",()=>e.L(c.id)),p.addEventListener("mouseleave",()=>e.L(null)),p.addEventListener("click",()=>e.open(c.id)),t.append(p),r.observe(p),{e:p,thread:c,lost:k,placed:null,view:L}}function v(c){r.unobserve(c),c.classList.add("out"),window.setTimeout(()=>c.remove(),mi)}function x(){let c=e.state.o;if(o&&o.of!==c&&(v(o.e),o=null,c||e.D(null)),!c)return;let k=!o;if(o)o.s.ye(c.label);else{let L=Yt(e,c),p=y("div",{class:"th on"},L.element);p.style.transition="none",t.append(p),r.observe(p),o={e:p,s:L,of:c}}o.s.ee(e.state.l&&!c.anchor.quote&&!c.anchor.point),k&&o.s.focus()}function T(c){Q(t,e.state.d);let k=new Set,L=[],p=e.state.i!==null||e.state.o!==null;for(let w of c){if(!e.B(w))continue;k.add(w.id);let M=n.get(w.id);M?(M.thread!==w||M.lost!==s(w))&&m(M,w):(M=u(w),n.set(w.id,M),L.push(M.e));let P=M.e,b=e.state.i===w.id;P.classList.toggle("on",b);let H=P.firstElementChild,_=w.root.replies.length;H.setAttribute("aria-label",`Open thread: ${we(w.root.text,60)}, ${Zt(_)}`),H.setAttribute("aria-expanded",String(b)),Q(H,b);let F=P.querySelector(".more");F&&Q(F,!b),P.classList.toggle("dim",p&&!b),P.classList.toggle("hot",e.state.L===w.id&&!b),P.classList.toggle("resolved",w.resolved),P.classList.toggle("lost",M.lost)}for(let[w,M]of n)k.has(w)||(n.delete(w),v(M.e));x(),Bt(t,c.filter(w=>k.has(w.id)).sort(Ve(e)).map(w=>n.get(w.id).e),o?.e??null)&&t.offsetWidth,d(),o&&L.push(o.e);for(let w of L)w.offsetWidth,w.style.transition=""}function C(){let c=Hn(e.root,!0);c&&(t.style.width=`${c.width}px`,t.style.transform=`translate(${c.x}px, ${-window.scrollY}px)`)}return{f:T,S:C,destroy(){r.disconnect(),e.D(null),t.remove()}}}var _o="[data-pipeup-ignore],input,textarea,select,[contenteditable]:not([contenteditable=false])";function Uo(e){let t=y("button",{type:"button","aria-label":"Comment",title:"Comment"},Z("comment",17)),n=y("div",{class:"selbar"},t);n.inert=!0,e.t.append(n);let o=null,r=0,s=!1,l=C=>{let c=C&&(C.nodeType===Node.ELEMENT_NODE?C:C.parentElement);return!!c&&e.root.contains(c)&&!c.closest(_o)};function d(){if(!o)return;let{left:C,top:c}=Jt(o.getBoundingClientRect(),{width:n.offsetWidth||36,height:n.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});n.style.left=`${C}px`,n.style.top=`${c}px`}function m(){o=null,n.inert=!0,n.classList.remove("show")}function u(C=!1){let c=lt();if(!e.state.l||!c||!l(c.anchorNode)||!l(c.focusNode)){m();return}!o&&!C&&e.w("Enter comments on the selected words"),o=c.getRangeAt(0).cloneRange(),d(),n.inert=!1,n.classList.add("show")}t.addEventListener("mousedown",C=>C.preventDefault()),t.addEventListener("click",C=>{if(C.stopPropagation(),e.state.o&&!e.C())return e.N();let c=o;if(!c)return;let k;try{k=gn(c,e.root,e.p.view(c.commonAncestorContainer))}catch(p){e.re(p),m();return}let L=we(c.toString().replace(/\s+/g," ").trim(),60);window.getSelection()?.removeAllRanges(),m(),e.Ye({anchor:k,label:`\u201C${L}\u201D`,ranges:[c],resolved:{state:"attached",element:null,range:c}})});let v=()=>{window.clearTimeout(r),r=window.setTimeout(()=>s||u(),250),o&&(lt()||m())};document.addEventListener("selectionchange",v);let x=C=>{C.type!=="keyup"&&(s=C.type==="mousedown"),!(s||e.m(C))&&window.setTimeout(()=>u(C.type==="mouseup"),0)};window.addEventListener("mousedown",x,!0),window.addEventListener("mouseup",x,!0),window.addEventListener("keyup",x,!0);let T=C=>{C.key!=="Enter"||!o||e.m(C)||C.target instanceof Element&&C.target.closest(`${_o},${tn}`)||(C.preventDefault(),C.stopPropagation(),t.click())};return window.addEventListener("keydown",T,!0),{f(){!e.state.l&&o&&m()},S(){o&&d()},destroy(){window.removeEventListener("mousedown",x,!0),window.removeEventListener("mouseup",x,!0),window.removeEventListener("keyup",x,!0),window.removeEventListener("keydown",T,!0),window.clearTimeout(r),document.removeEventListener("selectionchange",v),n.remove()}}}async function Bn(e,t){try{await navigator.clipboard.writeText(e);return}catch{}let n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.cssText="position:fixed;opacity:0;pointer-events:none",t.append(n),n.select();let o=document.execCommand("copy");if(n.remove(),!o)throw new Error("pipeup: your browser blocked copying")}var gi=3e3,qo="Hidden on the page";function Ko(e){let t=[y("span",{class:"n"}),y("span",{class:"n"})],n=Z("comment",20,1.4);n.lastElementChild.setAttribute("stroke-width","1.6");let o=y("button",{class:"mode",type:"button","aria-label":"Comment","aria-keyshortcuts":Mn,"aria-haspopup":"menu","aria-expanded":"false"},y("span",{class:"plus"},n),y("span",{class:"cnt"},Z("bubble",34,1.4),...t),y("span",{class:"dot"})),r=document.createTextNode("Comment"),s=y("span",{class:"ttip","aria-hidden":"true"},r,y("small",{},bt)),l=y("div",{class:"launch"},o,s),d=y("div",{class:"menu",role:"menu","aria-label":"Comments"}),m=y("div",{class:"list",role:"menu","aria-label":"All comments"}),u=y("span",{class:"pn"}),v=y("button",{class:"ib",type:"button","aria-label":"Close"},Z("close")),x=y("button",{class:"hs",type:"button",role:"switch","aria-checked":"false"},"Show resolved",y("span",{class:"sw","aria-hidden":"true"}));x.addEventListener("click",h=>{h.stopPropagation(),e.c.je()});let T=y("div",{class:"all",role:"dialog","aria-label":"All comments"},y("div",{class:"hd"},y("span",{},"All comments"),u,x,v),m),C=y("div",{class:"pop side",role:"dialog","aria-label":"Comment thread"});d.inert=T.inert=C.inert=!0,e.t.append(d,l,T);let c=!1,k=null,L=0,p=[],w=0,M=null,P=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,b=h=>{c=e.state.c=h,h&&e.addons.flush(),window.clearTimeout(L),L=0,h||k?.(!0),d.classList.toggle("show",h),Q(d,!h),o.setAttribute("aria-expanded",String(h))},H=(h,E=!1)=>{e.state.d!==h&&(e.state.d=h,e.f(),h?(_(m)[0]??v).focus({preventScroll:!0}):E&&o.focus({preventScroll:!0}))},_=(h=d)=>[...h.querySelectorAll(".mi")],F=()=>d.getRootNode().activeElement,q=()=>{b(!1),o.focus({preventScroll:!0})},J=h=>{let E=_(h.currentTarget);if(E.length===0)return;let I=F(),i=E.indexOf(I),f=a=>{h.preventDefault(),E[(a+E.length)%E.length]?.focus({preventScroll:!0})};h.key==="ArrowDown"?f(i+1):h.key==="ArrowUp"?f(i<0?E.length-1:i-1):h.key==="Home"?f(0):h.key==="End"&&f(E.length-1)};d.addEventListener("keydown",J),m.addEventListener("keydown",J),v.addEventListener("click",h=>{h.stopPropagation(),H(!1,!0)});let D=h=>Dn(e,h),K=h=>p.filter(E=>!E.resolved&&(h===void 0||e.F(E)===h)).length,oe=()=>K(!1),ke=()=>K(!0),se=()=>K(),le=h=>{let E=h.anchor.view?.slide,I=e.p.u(h.anchor.view)?"":Ht(h.anchor.view);return E&&e.p.slide()!==null?`On slide ${E}`:I?`In ${I}`:qo},de=(h,E,I="")=>y("div",{role:"group","aria-label":I?`${h} \xB7 ${I}`:h},y("div",{class:"sec","aria-hidden":"true"},h,I&&y("b",{},I)),...E);function Se(h,E){let I=e.p.slide(),i=new Map;for(let f of h){let a=f.thread,g=I!==null?a.anchor.view?.slide??I:e.F(a)?e.p.u(a.anchor.view)?"":Ht(a.anchor.view):null;i.set(g,[...i.get(g)??[],f])}if(I===null){let f=i.get(null)??[];return i.delete(null),[...f.map(E),...[...i].map(([a,g])=>de(a||qo,g.map(E)))]}return[...i].sort(([f],[a])=>Number(f)-Number(a)||0).map(([f,a])=>de(`Slide ${f} \xB7 ${a.filter(g=>!g.thread.resolved).length} open`,a.map(E),f===I?"This slide":""))}function A(){let h=F()?.dataset.thread,E=e.c.all().filter(a=>!a.thread.resolved||e.state.M),I=a=>{let g=a.thread,S=Me(g.root.author,g.root.name);S.classList.add("in");let O=y("button",{class:g.resolved?"mi done":"mi",type:"button",role:"menuitem","data-thread":g.id},S,y("span",{},y("span",{class:"clamp"},g.root.deleted?"Deleted":g.root.text),y("small",{},D(g)?`\u201C${we(g.anchor.snapshot,80)}\u201D`:a.location.where)));return O.addEventListener("click",$=>{$.stopPropagation(),N(g.id,O.getBoundingClientRect().top)}),O},i=E.filter(a=>D(a.thread));u.textContent=String(se()),x.setAttribute("aria-checked",String(e.state.M)),m.replaceChildren(E.length?"":y("div",{class:"sec",role:"presentation"},"No open comments"),...Se(E.filter(a=>!D(a.thread)),I),i.length?de("No longer on the page",i.map(I)):"");let f=_(m);h&&f.find(a=>a.dataset.thread===h)?.focus({preventScroll:!0})}function N(h,E){Qe()&&(e.state.O=!0,H(!1)),B(h,E)}let R="";function B(h,E){let I=p.find(i=>i.id===h);if(I){if(R=h,!e.F(I))return z(I,E);if(e.state.o&&!e.C())return e.N();e.p.W(I.anchor.view??{}).then(()=>{e.Ee();let i=p.find(f=>f.id===h);i&&R===h&&(e.state.d||e.state.O)&&z(i,E)})}}function z(h,E){let I=h.id,i=e.resolved.get(I),f=i&&!D(h)&&!e.F(h)?i.element??i.range?.startContainer.parentElement??null:null;if(f?.scrollIntoView({block:"center",inline:"nearest",behavior:P?"auto":"smooth"}),f&&i&&Et(h.anchor,i)&&f.checkVisibility?.({visibilityProperty:!0})!==!1){U(),e.open(I);return}e.open(null),Qe()&&(e.state.O=!0,e.f()),V(h,E)}function V(h,E){let I=!D(h)&&e.F(h),i={quote:h.anchor.quote?.exact??null,lost:D(h)||I?h.anchor.snapshot:null,place:I?le(h):null};if(M?.id===h.id?M.view.update(h,i):(M={id:h.id,view:dt(h,e.j,{Y:"popover",...i})},C.replaceChildren(M.view.element)),E===void 0)return;C.isConnected||(e.t.insertBefore(C,T),C.offsetWidth);let f=Gt(e.state.d),{left:a,top:g}=Xt({x:f.width,y:E,below:!1},{width:Je,height:C.offsetHeight},f);C.style.left=`${a}px`,C.style.top=`${g}px`,C.classList.add("show"),C.inert=!1,e.Ge(h.id)}function U(h=!1){M&&(M=null,C.classList.remove("show"),Q(C,!0),h&&e.state.O&&(e.state.O=!1,e.f()))}function W(h,E,I=!1,...i){let f=y("button",{class:"mi",type:"button",role:I?"menuitemcheckbox":"menuitem"},h,y("span",{class:"lb"}),...i,I&&y("span",{class:"sw","aria-hidden":"true"}),y("span",{class:"tt","aria-hidden":"true"}));return f.addEventListener("click",a=>{a.stopPropagation(),E(a)}),f}let ee=(h,E,I,i)=>{let f=h.querySelector(".lb");f.textContent!==E&&(f.textContent=E),h.querySelector(".tt").textContent=I,h.setAttribute("aria-description",I),i!==void 0&&h.setAttribute("aria-checked",String(i))},_e=()=>y("div",{class:"sep",role:"separator"}),be=y("span",{class:"ma"}),Ue=y("span",{class:"kc"}),Ce="",te=W(be,ot,!1,Ue);te.dataset.item="name";let qe=W(Z("copy"),()=>{q(),e.c.copyAll("ai")}),G=W(Z("lines"),()=>{q(),e.c.copyAll("text")}),Te=y("span",{class:"kc"}),ce=W(Z("list"),()=>{b(!1),H(!0)},!1,Te),pe=W(Z("comment"),h=>{let E=!e.state.l&&h.detail===0;e.Xe(!e.state.l,E),E&&b(!1)},!0,y("span",{class:"kc","aria-hidden":"true"},bt));pe.dataset.item="comment",pe.setAttribute("aria-keyshortcuts",Mn);let me=y("div",{class:"sec",role:"presentation"}),re=_e(),Pe=_e(),ae=new Map,Ke=h=>{let E=ae.get(h);return E||(E=W(Le(h.icon,15),()=>{h.checked||q(),Promise.resolve().then(()=>h.select()).catch(I=>e.re(I)).finally(()=>c&&ue())},!!h.checked,y("span",{class:"kc"})),ae.set(h,E)),E},ze=()=>[te,re,qe,G,ce,...e.addons.$.map(Ke),Pe,pe],nt=-1,ne=h=>{try{return h()}catch(E){return globalThis.reportError?.(E),""}};function ue(){let h=se(),E=e.c.name(),I=E||ye(e.doc.me);if(ee(te,I,E?"The name on your comments":"Add a name to show on your comments"),te.setAttribute("aria-label",`${I}, ${E?"edit":"add"} your name`),Ue.replaceChildren(E?Z("edit",13):"Add name"),gt(e.doc.me,E)!==Ce){Ce=gt(e.doc.me,E);let f=Me(e.doc.me,E);f.classList.add("in"),be.replaceChildren(f)}ee(qe,"Copy as Markdown","Markdown, with where each thread is"),ee(G,"Copy as Text","Just the words"),ee(ce,"All comments","Every thread, and where it is"),Te.textContent=h?String(h):"";let i=e.addons.pe();me.textContent=i,i?!me.isConnected&&d.contains(te)&&d.prepend(me):me.remove();for(let f of e.addons.$){let a=ae.get(f);if(!a)continue;let g;try{g=f.checked?.()}catch(S){globalThis.reportError?.(S)}ee(a,ne(f.label),ne(f.hint),g),a.querySelector(".kc").textContent=f.count?ne(f.count):""}ee(pe,"Start commenting",e.state.l?"Turn off to hide the comments again":"Shows the comments; choose any part of the page to comment on it",e.state.l)}function he(){ue(),(nt!==e.addons.G||!d.contains(te))&&(d.replaceChildren(...ze()),nt=e.addons.G,ue())}function ot(){let h=y("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"});h.value=e.c.name();let E=y("div",{class:"ed"},be.cloneNode(!0),h),I=(i,f=!1)=>{if(k!==I)return;k=null;let a=h.value.trim();i&&a&&a!==e.c.name()&&e.c.rename(a).then(ue),E.replaceWith(te),f&&te.focus({preventScroll:!0})};k=I,h.addEventListener("keydown",i=>{i.stopPropagation(),(i.key==="Enter"||i.key==="Escape")&&(i.preventDefault(),I(i.key==="Enter",!0))}),h.addEventListener("blur",()=>I(!0)),te.replaceWith(E),h.focus({preventScroll:!0})}o.addEventListener("click",h=>{if(h.stopPropagation(),c){b(!1);return}he(),b(!0),h.detail===0&&_().at(-1)?.focus({preventScroll:!0})});let We=!1,Ye=()=>{We=T.contains(F())},Oe=h=>{let E=h.composedPath();c&&!E.includes(d)&&!E.includes(o)&&(b(!1),e.state.l&&!e.m(h)&&(e.we(h),h.preventDefault(),h.stopPropagation())),e.state.d&&!e.m(h)&&H(!1,We&&(!document.activeElement||document.activeElement===document.body)),!E.includes(C)&&!E.includes(T)&&U(!0)},xe=h=>{if(!c||h.pointerType==="touch"||h.type==="pointerout"&&h.relatedTarget)return;let E=h.composedPath();h.type==="pointerover"&&(E.includes(d)||E.includes(o))?(window.clearTimeout(L),L=0):L||(L=window.setTimeout(()=>{L=0,k||b(!1)},gi))},Ie={n:0,label:""},je=()=>{let{n:h,label:E}=Ie,I=e.addons.pe(),i=`Comment${e.state.l?", comment mode on":""}${E?`, ${E}`:h?`, ${h} open`:""}${I?`, ${I}`:""}`;o.getAttribute("aria-label")!==i&&o.setAttribute("aria-label",i);let f=(E||"Comment")+(I?` \xB7 ${I}`:"");r.data!==f&&(r.data=f)},rt=e.addons.subscribe(h=>{je(),!(!c||k)&&(h?he():ue())});window.addEventListener("pointerdown",Ye,!0),window.addEventListener("click",Oe,!0),window.addEventListener("pointerover",xe,!0),window.addEventListener("pointerout",xe,!0);let Ne=h=>{if(h.key!=="Escape"||k)return;let E=h.composedPath()[0];if(c)q();else if(e.state.d&&!(E instanceof HTMLTextAreaElement&&!T.contains(E)))H(!1,!0);else if(M)U(!0),e.j.close();else return;h.stopPropagation()};return window.addEventListener("keydown",Ne,!0),{f(h){p=h;let E=oe();if(E!==w){if(E){let[a,g]=t[0].classList.contains("on")?t:[t[1],t[0]];g.textContent=E>99?"99+":String(E),g.classList.toggle("s",E>99),a.classList.remove("on"),g.classList.add("on")}o.classList.toggle("has",E>0),w=E}let I=ke(),i=I?`${E} here \xB7 ${I} ${e.p.slide()!==null?"on other slides":"in other views"}`:"";o.classList.toggle("else",I>0),Ie={n:E,label:i},je(),o.classList.toggle("on",e.state.l),c&&!e.state.c&&b(!1),c&&ue();let f=e.state.d;if(T.classList.toggle("full",Qe()),T.classList.contains("show")!==f&&(T.classList.toggle("show",f),Q(T,!f)),f&&A(),M){let a=h.find(g=>g.id===M?.id);!a||e.state.i||a.resolved&&!e.state.M?U():V(a)}},S(){},destroy(){rt(),window.removeEventListener("pointerdown",Ye,!0),window.removeEventListener("click",Oe,!0),window.removeEventListener("pointerover",xe,!0),window.removeEventListener("pointerout",xe,!0),window.clearTimeout(L),window.removeEventListener("keydown",Ne,!0),d.remove(),T.remove(),C.remove(),l.remove()}}}var At="[data-pipeup-slide]",zo=1e3,Wo=["scroll","resize","keyup","click","transitionend","slidechanged"],Fn=null,Mt=null,nn=new Set,Vn=new Set,Lt=e=>{try{e()}catch(t){globalThis.reportError?.(t)}};function vi(e){let t=null;if(e){t={};let n=0;for(let[o,r]of Object.entries(e))if(!(typeof r!="string"||o==="slide"||o.length>j.viewKey||r.length>j.viewValue)){if(++n>=j.viewEntries)break;t[o]=r}}Fn=t;for(let n of Vn)n()}function yi(e){return nn.add(e),()=>void nn.delete(e)}function on(e){Mt=typeof e?.current=="function"&&typeof e.go=="function"?e:null}function wi(e,t,n){let o=t.oe(),r=null,s=0,l=0;for(let d of e){if(!t.shown(d))continue;let m=t.s(d),u=Math.min(m.left+m.width,o.width)-Math.max(m.left,0),v=Math.min(m.top+m.height,o.height)-Math.max(m.top,0);if(u<=0||v<=0)continue;let x=Math.round(u*v),T=t.opacity(d);(x>s||x===s&&(T>l||T===l&&d===n))&&(r=d,s=x,l=T)}return r}function bi(e,t,n){return t!==null?e?.slide===void 0||e.slide===t:!e||!n?!0:Object.entries(e).every(([o,r])=>o==="label"||o==="slide"||n[o]===r)}function xi(){return{s:e=>e.getBoundingClientRect(),shown:e=>e.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0})!==!1,opacity:e=>parseFloat(getComputedStyle(e).opacity)||0,oe:()=>({width:window.innerWidth,height:window.innerHeight})}}var Yo=()=>{let e=window.Reveal;return typeof e?.getIndices=="function"&&typeof e.slide=="function"?e:null};function jo(e,t,n=xi()){let o=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,r=null,s=null,l=0,d=!1,m=()=>[...e.querySelectorAll(At)],u=()=>[...e.querySelectorAll(".slides > section")],v=w=>typeof w=="string"&&w.length>0&&w.length<=j.viewValue?w:null,x=w=>v(w?.getAttribute("data-pipeup-slide"));function T(){if(Mt){let M=null;if(Lt(()=>{let P=Mt.current();Number.isInteger(P)&&P>0&&(M=String(P))}),M!==null)return M}let w=Yo();if(w){let M=null;if(Lt(()=>{let P=w.getIndices().h,b=u()[P];M=x(b?.matches(At)?b:b?.querySelector(At))??v(String(P+1))}),M!==null)return M}return r&&!r.isConnected&&(r=null),r=wi(m(),n,r)??r,x(r)}function C(){l=0,s=T(),t()}let c=()=>{!l&&!d&&(l=requestAnimationFrame(C))},k=w=>bi(w,s,Fn);function L(w){if(k(w))return Promise.resolve(!0);let M=w.slide,P=Yo(),b=m().find(F=>x(F)===M),H=/^[1-9]\d{0,5}$/.test(M??"");if(H&&Mt)Lt(()=>Mt.go(Number(M)));else if(H&&P){let F=b?u().findIndex(q=>q===b||q.contains(b)):-1;Lt(()=>P.slide(F>=0?F:Number(M)-1))}else if(nn.size)for(let F of nn)Lt(()=>F({...w}));else if(b)b.scrollIntoView({block:"start",behavior:o?"auto":"smooth"});else return Promise.resolve(!1);let _=performance.now();return new Promise(F=>{let q=K=>{clearTimeout(J),F(K)},J=setTimeout(()=>q(!1),zo),D=()=>{if(d)return q(!1);if(s=T(),k(w))return q(!0);if(performance.now()-_>=zo)return q(!1);requestAnimationFrame(D)};requestAnimationFrame(D)})}let p=new MutationObserver(w=>{w.some(M=>M.target instanceof Element&&M.target.matches(At))&&c()});p.observe(e,{subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]});for(let w of Wo)window.addEventListener(w,c,{capture:!0,passive:!0});return Vn.add(c),s=T(),{slide:()=>s,view(w){let M=w instanceof Element?w:w?.parentElement,P=x(M?.closest(At))??s,b={...P!==null?{slide:P}:{},...Fn};return Object.keys(b).length?b:void 0},u:k,W:L,destroy(){d=!0,cancelAnimationFrame(l),p.disconnect();for(let w of Wo)window.removeEventListener(w,c,!0);Vn.delete(c)}}}var _n=["pipeup-quote","pipeup-on","pipeup-done"],Ei={"pipeup-quote":[[250,227,188,.75],[250,200,100,.28]],"pipeup-on":[[247,212,154,.95],[250,200,100,.42]],"pipeup-done":[[180,178,169,.22],[180,178,169,.2]]},ki=(e,t)=>_n.map(n=>{let[o,r,s,l]=Ei[n][e?1:0];return`::highlight(${n}){background-color:rgba(${o},${r},${s},${+(l*t).toFixed(3)})}`}).join("");function Xo(){return typeof CSS<"u"&&"highlights"in CSS&&typeof Highlight<"u"}var Si="<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><rect x='7' y='7' width='23' height='23' rx='4' fill='none' stroke='#534AB7' stroke-width='2' stroke-dasharray='4 3'/><path d='M3 2v15l4-3.5 3 6.5 2.5-1.2-3-6.3H15z' fill='#fff' stroke='#2C2C2A' stroke-width='1.2' stroke-linejoin='round'/></svg>",Ti=`:not([data-pipeup-ignore],[data-pipeup-ignore] *){cursor:url("data:image/svg+xml,${encodeURIComponent(Si)}") 3 2,crosshair!important}`;function Jo(e=document,t=!1){let n=e.defaultView?.CSSStyleSheet;if(!n||!("replaceSync"in n.prototype)||!("adoptedStyleSheets"in e))return{ke(){},Se(){},le(){},Te(){},remove:()=>Go()};let o=new n,r=null,s=!1,l=1,d=0,m="",u=0,v=()=>o.replaceSync(ki(t,l)+(r===null?"":`:root{--pipeup-gutter:${r}px}`)+(s?Ti:"")+(d||m?`html{--pipeup-panel:${d}px;${d?`margin-right:${d}px!important;`:""}${m}}`:""));return v(),e.adoptedStyleSheets=[...e.adoptedStyleSheets,o],{ke(x){x!==r&&(r=x,v())},Se(x){x!==s&&(s=x,v())},le(x){l=x,v()},Te(x,T){x!==d&&(d=x,m=T?"":"transition:margin-right .34s cubic-bezier(.4,0,.2,1)!important",clearTimeout(u),!x&&m&&(u=window.setTimeout(()=>{m="",v()},400)),v())},remove(){clearTimeout(u),e.adoptedStyleSheets=e.adoptedStyleSheets.filter(x=>x!==o),Go()}}}function Qo(e){if(Xo())for(let t of _n)CSS.highlights.set(t,new Highlight(...e[t.slice(7)]))}function Go(){if(Xo())for(let e of _n)CSS.highlights.delete(e)}var Un=':host{all:initial}*{box-sizing:border-box}button{appearance:none;font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}svg{display:block}.layer{all:initial;display:block;position:fixed;inset:0;pointer-events:none;font:13px/1.5 var(--pu-font,system-ui,sans-serif);color:var(--k);--k:#2C2C2A;--mu:#5F5E5A;--fa:#888780;--ln:#E5E3DA;--ru:#ECEAE2;--so:#FAFAF7;--su:#FFFFFF;--ho:#F1EFE8;--as:color-mix(in srgb,var(--pu-accent,#534AB7) 12%,transparent);--sh:0 8px 28px rgba(44,44,42,.1);--in:.26s;--mv:.34s;--out:.2s;--pl:1.2s;--eo:cubic-bezier(.22,.61,.36,1);--eio:cubic-bezier(.4,0,.2,1);--ei:cubic-bezier(.4,0,1,1);--pu-text:var(--k);--pu-muted:var(--mu);--pu-faint:var(--fa);--pu-line:var(--ln);--pu-surface:var(--su);--pu-soft:var(--so);--pu-hover:var(--ho);--pu-shadow:var(--sh);--pu-ease:var(--eo)}.layer.dark{--k:#ECEBE6;--mu:#B4B2A9;--fa:#8D8B84;--ln:#3A3936;--ru:#34332F;--so:#22221F;--su:#1B1B19;--ho:#2C2C29;--sh:0 8px 28px rgba(0,0,0,.45)}.layer.hidden .bub,.layer.hidden .col,.layer.hidden .pop,.layer.hidden .tip,.layer.hidden .mark,.layer.hidden .selbar{opacity:0!important;pointer-events:none!important}.tx{font-size:14px;line-height:1.5;color:var(--k);white-space:pre-wrap;overflow-wrap:anywhere}.tx.del,.who,.rest,.ctx{color:var(--fa)}.who,.rest{font-size:12px}.who{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.rft>.who{display:block}.ctx[hidden]{display:none}.ctx{font-size:12px;margin-bottom:3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.clamp{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.tx a{color:var(--pu-accent);text-decoration:underline;text-decoration-thickness:1px;text-underline-offset:2px}.ft,.rft{display:grid;grid-template-rows:0fr;opacity:0;transition:grid-template-rows var(--in) var(--eo),opacity var(--in) var(--eo)}.ft>*,.rft>*{overflow:hidden;min-height:0;display:flex;align-items:center}.root:hover>.ft,.root:focus-within>.ft,.it:hover>.rft,.it:focus-within>.rft{grid-template-rows:1fr;opacity:1}.ft.has-rest{grid-template-rows:1fr;opacity:1}.ft.has-rest>*{grid-area:1/1}.ft .hover{opacity:0;transition:opacity var(--in) var(--eo)}.ft .rest{transition:opacity var(--in) var(--eo)}.root:hover>.ft .hover,.root:focus-within>.ft .hover,.ft:not(.has-rest) .hover{opacity:1}.root:hover>.ft .rest,.root:focus-within>.ft .rest{opacity:0}.acts{margin-left:6px;display:flex;flex:none}.ib{width:24px;height:22px;display:grid;place-items:center;border-radius:6px;color:var(--mu);transition:background-color .2s var(--eo),color .2s var(--eo)}.ib:hover,.ib:focus-visible{background:var(--ho);color:var(--k);outline:none}.rps,.rbox{padding-left:14px}.rps .it{padding-top:6px}.more{display:grid;grid-template-rows:1fr;transition:grid-template-rows var(--mv) var(--eio)}.more>div{overflow:hidden;min-height:0}.th:not(.on) .more{grid-template-rows:0fr}.row{display:flex;align-items:center;gap:8px;padding:8px 0 2px;cursor:text}.input{flex:1;min-width:0;height:27px;display:block;border:0;border-bottom:1px solid var(--ln);outline:none;resize:none;overflow:hidden;font:inherit;font-size:14px;line-height:1.5;padding:3px 0;color:var(--k);background:transparent;transition:border-color var(--in) var(--eo)}.row:hover .input,.input:hover{border-bottom-color:var(--mu)}.input:focus{border-bottom-color:var(--pu-accent)}.ed{display:flex;gap:10px;align-items:center;min-height:34px;padding:6px 10px}.ed .input{font-size:13px;height:22px}.root,.it{position:relative;padding-right:30px}.av{display:grid;place-items:center;width:22px;height:22px;border-radius:32%;font-size:12px;font-weight:600;line-height:1;opacity:0;transform:scale(.85);transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.av.in{opacity:1;transform:none}.av svg{width:80%;height:80%}.root>.av,.it>.av{position:absolute;top:0;right:0}.it>.av{top:6px}.av{--av-l:92%;--av-d:30%;--s:60%;background:hsl(var(--h) var(--s) var(--av-l));color:hsl(var(--h) var(--s) var(--av-d))}.dark .av{--av-l:20%;--av-d:78%}.c0{--h:0}.c1{--h:25}.c2{--h:50}.c3{--h:130}.c4{--h:175}.c5{--h:215}.c6{--h:270}.c7{--h:330}.c8{--h:28;--s:35%}.c9{--h:220;--s:8%}.me{flex:none;display:grid}.me>.av{grid-area:1/1;width:26px;height:26px;font-size:13px}.you{display:grid;padding:0 34px;min-height:24px;font-size:12px;color:var(--fa)}.you>*{grid-area:1/1;display:flex;align-items:center;min-width:0;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.say{white-space:pre;overflow:hidden}.nm{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.say button{flex:none}.say button{color:var(--mu);text-decoration:underline;text-decoration-color:var(--ln);text-underline-offset:2px;transition:color .2s var(--eo)}.say button:hover,.say button:focus-visible{color:var(--pu-accent);outline:none}.nf{opacity:0;transform:translateY(-4px);pointer-events:none}.nf .input{font-size:13px;height:24px}.you.naming .nf{opacity:1;transform:none;pointer-events:auto}.you.naming .say{opacity:0;pointer-events:none}.send{width:26px;height:26px;border-radius:50%;display:grid;place-items:center;color:var(--pu-accent);flex:none;opacity:0;pointer-events:none;transition:opacity var(--in) var(--eo),background-color .2s var(--eo)}.send.show{opacity:1;pointer-events:auto}.send:hover{background:var(--as)}.bub{position:fixed;left:0;top:0;width:20px;height:20px;margin:-20px 0 0 -2px;border-radius:50% 50% 50% 0;background:var(--pu-accent);border:2px solid var(--su);box-shadow:0 1px 4px #0003;pointer-events:auto;opacity:0;transform:translateY(-6px) scale(.9);transform-origin:2px 20px;transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.bub.in{opacity:1;transform:none;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.bub.in:hover,.bub.on{transform:scale(1.18)}.bub.done{background:var(--fa)}.bub.ghost{pointer-events:none}.tip,.pop,.menu,.all,.xp,.toast,.selbar,.namebar,.ttip,.tt,.mode{background:var(--su);border:1px solid var(--ln);box-shadow:var(--sh)}.tip{position:fixed;max-width:260px;border-radius:10px;padding:7px 10px;opacity:0;transform:translateY(3px);transition:opacity .22s var(--eo),transform .26s var(--eo)}.tip.show{opacity:1;transform:none;pointer-events:auto;cursor:pointer;transition:opacity .22s var(--eo),transform .26s var(--eo),left var(--mv) var(--eio),top var(--mv) var(--eio)}.pop{position:fixed;width:var(--pu-pop);border-radius:12px;padding:10px 12px 8px;pointer-events:none;opacity:0;transform:translateY(6px) scale(.98);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.pop.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo)}.pop.show.glide{transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo),left var(--mv) var(--eio),top var(--mv) var(--eio)}.mark{position:fixed;border:2px solid color-mix(in srgb,var(--pu-accent) 50%,transparent);background:var(--as);border-radius:8px;opacity:0;transition:opacity .3s var(--eo)}.mark.show{opacity:1}.pulse{position:fixed;border:2px solid var(--pu-accent);border-radius:8px;background:var(--as);animation:pu-pulse var(--pl) var(--eio) forwards}@keyframes pu-pulse{0%{opacity:0;transform:scale(.985)}35%{opacity:.85;transform:scale(1)}to{opacity:0;transform:scale(1.02)}}.col{position:fixed;left:0;top:0;pointer-events:none;transition:opacity var(--in) var(--eo)}.th{position:absolute;left:0;right:0;top:0;padding:4px 4px 4px 12px;pointer-events:auto;cursor:pointer;box-shadow:inset 2px 0 0 transparent;transition:transform var(--mv) var(--eio),box-shadow var(--in) var(--eo),opacity var(--in) var(--eo)}.th.hot{box-shadow:inset 2px 0 0 var(--ln)}.th.on{box-shadow:inset 2px 0 0 var(--pu-accent);cursor:default}.th.dim{opacity:.45}.th.resolved:not(.on):not(.hot){opacity:.6}.th.lost .ctx{white-space:normal}.th.wait{opacity:0!important;pointer-events:none}.th.out{opacity:0!important;pointer-events:none;transition:opacity var(--out) var(--ei)}.th:has(.opn:focus-visible){box-shadow:inset 2px 0 0 var(--ln);outline:2px solid var(--pu-accent);outline-offset:2px;border-radius:4px}.selbar{position:fixed;display:flex;border-radius:10px;padding:2px;opacity:0;transform:translateY(4px);pointer-events:none;transition:opacity var(--in) var(--eo),transform .3s var(--eo)}.selbar.show{opacity:1;transform:none;pointer-events:auto}.selbar button{width:32px;height:30px;display:grid;place-items:center;border-radius:8px;color:var(--pu-accent);transition:background-color .2s var(--eo)}.selbar button:hover,.selbar button:focus-visible{background:var(--as);outline:none}.pick{position:fixed;left:0;top:0;border:2px solid color-mix(in srgb,var(--pu-accent) 70%,transparent);background:color-mix(in srgb,var(--pu-accent) 6%,transparent);border-radius:8px;pointer-events:none;opacity:0;transition:opacity var(--out) var(--ei),border-color var(--out) var(--ei),border-width var(--out) var(--ei),box-shadow var(--out) var(--ei)}.pick.show{opacity:1;transition-duration:var(--in);transition-timing-function:var(--eo)}.pick.show.glide{transition-property:all;transition-duration:var(--mv);transition-timing-function:var(--eio)}.pick.on{border-color:var(--pu-accent)}.pick.kf{border:3px solid var(--pu-accent);box-shadow:0 0 0 2px var(--su)}.km{position:fixed;left:0;top:0;pointer-events:none;outline:none}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.namebar{position:fixed;left:0;top:0;display:flex;align-items:center;gap:2px;padding:2px 2px 2px 10px;border-radius:10px;font-size:12px;color:var(--mu);white-space:nowrap;pointer-events:none;opacity:0;transform:translateY(4px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.namebar.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform .3s var(--eo)}.namebar.show.glide{transition-property:all;transition-duration:var(--mv);transition-timing-function:var(--eio)}.namebar .lbl{margin-right:6px;max-width:260px;overflow:hidden;text-overflow:ellipsis}.namebar .nb{padding:4px;display:grid;place-items:center;border-radius:7px;transition:background-color .2s var(--eo),color .2s var(--eo)}.namebar .nb:hover,.namebar .nb:focus-visible{background:var(--ho);color:var(--k);outline:none}.namebar .nb[hidden]{display:none}.launch{position:fixed;right:20px;bottom:20px;pointer-events:auto}.launch .mode{position:relative;display:grid;place-items:center;width:46px;height:46px;border-radius:50%;transition:background-color .3s var(--eo),color .3s var(--eo)}.mode>*,.cnt>*{grid-area:1/1}.mode>*{display:grid;place-items:center;transition:opacity var(--in) var(--eo)}.cnt,.has>.plus{opacity:0}.has>.cnt{opacity:1}.n{font-size:12px;font-weight:500;line-height:1;margin:-1.4px 0 0 1.4px;font-variant-numeric:tabular-nums;opacity:0;transition:opacity var(--in) var(--eo)}.n.s{font-size:9.5px;letter-spacing:-.04em}.n.on{opacity:1}.launch .mode:hover,.launch .mode[aria-expanded=true]{background:var(--ho)}.launch .mode.on{background:var(--pu-accent);color:#fff}.mode>.dot{position:absolute;top:3px;right:3px;width:9px;height:9px;border-radius:50%;background:var(--pu-accent);border:2px solid var(--su);opacity:0}.mode.else>.dot{opacity:1}.ttip{position:absolute;right:0;bottom:54px;white-space:nowrap;border-radius:8px;padding:4px 9px;font-size:12px;pointer-events:none;opacity:0;transform:translateY(3px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.ttip small{margin-left:8px}.ttip small,.mi .kc{font-size:12px;color:var(--fa)}.mode:hover+.ttip,.mode:focus-visible+.ttip{opacity:1;transform:none;transition:opacity var(--in) var(--eo) .5s,transform var(--in) var(--eo) .5s}.launch .mode[aria-expanded=true]+.ttip{opacity:0;transition:opacity var(--out) var(--ei)}@media(hover:none){.ttip,.tt{display:none}}.menu{position:fixed;right:20px;bottom:76px;width:290px;border-radius:12px;padding:4px;pointer-events:none;opacity:0;transform:translateY(6px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.menu.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo)}.mi{position:relative;display:flex;gap:10px;align-items:center;width:100%;min-height:34px;text-align:left;padding:6px 10px;border-radius:8px;transition:background-color .2s var(--eo)}.mi:hover,.mi:focus-visible{background:var(--so);outline:none}.mi svg{color:var(--mu);flex:none}.mi small{display:block;color:var(--fa);font-size:12px}.lb{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ma{flex:none;display:grid;margin:-2px 0}.ma .av{width:20px;height:20px;font-size:11px}.mi .av svg{color:inherit}.sep{height:1px;margin:4px 10px;background:var(--ru)}.tt{position:absolute;right:calc(100% + 14px);top:50%;translate:0 -50%;width:max-content;max-width:220px;padding:4px 9px;border-radius:8px;font-size:12px;line-height:1.4;color:var(--mu);pointer-events:none;opacity:0;transform:translate(3px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.mi:hover>.tt,.mi:focus-visible>.tt{opacity:1;transform:none;transition:opacity var(--in) var(--eo) .5s,transform var(--in) var(--eo) .5s}@media(max-width:600px){.tt{right:8px;top:auto;bottom:100%;translate:none;transform:translateY(3px)}}.sw{position:relative;flex:none;width:26px;height:16px;border-radius:8px;background:var(--ln);transition:background-color var(--mv) var(--eio)}.sw:before,.sw:after{content:"";position:absolute;top:2px;left:2px;width:12px;height:12px;border-radius:50%;background:#fff;box-shadow:0 1px 2px #00000040;transition:transform var(--mv) var(--eio),opacity var(--mv) var(--eio)}.sw:before{opacity:0;transform:translate(10px)}[aria-checked=true]>.sw{background:var(--pu-accent)}[aria-checked=true]>.sw:after{transform:translate(10px)}.tools{display:flex;flex:none;gap:2px}.tools[hidden]{display:none}.tool[aria-pressed=true]{background:var(--as);color:var(--pu-accent)}.note{display:block;padding:0 0 4px;font-size:12px;color:var(--fa)}.note[hidden]{display:none}.ov{position:absolute;inset:0;pointer-events:none;overflow:hidden}.xb{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px 16px 16px;font-size:13px}.xb p{margin:0 0 10px}.all,.xp{position:fixed;top:0;right:0;bottom:0;width:var(--pu-panel);display:flex;flex-direction:column;border-width:0 0 0 1px;opacity:0;transform:translate(100%);transition:transform var(--out) var(--ei),opacity var(--out) var(--ei)}.all.show,.xp.show{opacity:1;transform:none;pointer-events:auto;transition:transform var(--mv) var(--eo),opacity var(--in) var(--eo)}.all.full{width:100%}.hd{display:flex;align-items:center;gap:8px;padding:12px 10px 8px 16px;font-weight:600}.pn{font-weight:400;color:var(--fa)}.hs{margin-left:auto;display:flex;align-items:center;gap:6px;padding:3px 4px 3px 6px;border-radius:6px;font-size:12px;font-weight:400;color:var(--mu);transition:background-color .2s var(--eo)}.hs:hover,.hs:focus-visible{background:var(--ho);outline:none}.list{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px}.all .mi{align-items:flex-start}.all .mi>.av{flex:none}.all .mi>span:last-child{flex:1;min-width:0}.all .mi small{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.all .mi.done{opacity:.6}.layer.listing .col{opacity:0;transition:opacity var(--out) var(--ei)}.sec{padding:8px 10px 2px;font-size:12px;color:var(--fa)}.sec b{margin-left:6px;font-weight:500;color:var(--pu-accent)}.toast{position:fixed;left:50%;bottom:28px;border-radius:10px;padding:8px 14px;font-size:13px;opacity:0;transform:translate(-50%,6px);transition:opacity .3s var(--eo),transform .36s var(--eo)}.toast.show{opacity:1;transform:translate(-50%)}@media(forced-colors:active){.pick.kf{border:3px solid Highlight}.layer :is(.ib,.mi,.nb,.hs,.selbar button,.say button,.xb button):focus-visible{outline:2px solid Highlight}}@media(prefers-reduced-motion:reduce){.bub,.bub.in,.bub.in:hover,.bub.on,.tip,.pop,.selbar,.menu,.all,.xp,.ttip,.tt,.toast{transform:none!important}.sw:after{transform:none!important;transition-property:opacity}[aria-checked=true]>.sw:after{opacity:0}[aria-checked=true]>.sw:before{opacity:1}.th{transition-property:opacity,box-shadow}.tip.show{transition-property:opacity}.pick,.pick.show{transition:opacity .16s ease-in-out}.all,.all.show,.xp,.xp.show{transition-property:opacity}.namebar,.namebar.show{transform:none!important;transition:opacity .16s ease-in-out}.av,.nf{transform:none!important}@keyframes pu-pulse{0%{opacity:0}35%{opacity:.85}to{opacity:0}}}';var Zo="#534AB7",Ai="rgb(0, 0, 238)";function er(e){let t=/rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)/.exec(e);if(!t||t[1]===void 0||t[2]===void 0||t[3]===void 0)return null;let n=t[4]===void 0?1:t[4].endsWith("%")?parseFloat(t[4])/100:parseFloat(t[4]);return{r:Number(t[1]),g:Number(t[2]),b:Number(t[3]),a:n}}function Li(e){let t=n=>{let o=n/255;return o<=.03928?o/12.92:((o+.055)/1.055)**2.4};return .2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}function tr(e){let t=e.ownerDocument,n=t.defaultView;if(!n)return{font:"system-ui, sans-serif",accent:Zo,dark:!1};let o=t.documentElement,r=n.getComputedStyle(e).fontFamily||"system-ui, sans-serif",s=(n.getComputedStyle(o).getPropertyValue("--pipeup-accent")||o.style.getPropertyValue("--pipeup-accent")).trim(),l=e.querySelector("a[href]"),d=l?n.getComputedStyle(l).color:"",m=s||(d&&d!==Ai?d:Zo),u=er(n.getComputedStyle(t.body).backgroundColor);(!u||u.a===0)&&(u=er(n.getComputedStyle(o).backgroundColor));let v=u&&u.a>0?Li(u)<.2:n.matchMedia?.("(prefers-color-scheme: dark)").matches===!0&&/dark/.test(n.getComputedStyle(o).colorScheme||"");return{font:r,accent:m,dark:!!v}}function nr(e,t){e.style.setProperty("--pu-font",t.font),e.style.setProperty("--pu-accent",t.accent),e.classList.toggle("dark",t.dark)}function or(e,t=document){let n=t.createElement("pipeup-root");n.setAttribute("data-pipeup-ignore",""),n.style.cssText="position:fixed!important;inset:0!important;pointer-events:none!important;z-index:2147483000!important;display:block!important;margin:0!important;visibility:visible!important;opacity:1!important;transform:none!important;filter:none!important;";let o=n.attachShadow({mode:"open"}),r=t.defaultView?.CSSStyleSheet;if(r&&"replaceSync"in r.prototype&&"adoptedStyleSheets"in o){let l=new r;l.replaceSync(Un),o.adoptedStyleSheets=[l]}else{let l=t.createElement("style");l.textContent=Un,o.append(l)}let s=t.createElement("div");return s.className="layer",s.style.setProperty("--pu-panel",`${kt}px`),s.style.setProperty("--pu-pop",`${Je}px`),nr(s,e),o.append(s),t.documentElement.append(n),{element:n,shadow:o,t:s,destroy:()=>n.remove()}}var Mi=40,Ci=250,Pi=120,Oi=2400,Ii=4e3,Ni=1e4;function rr(e,t=!1){return Hn(e,t)?"column":"bubbles"}function $i(e){return[...e.state.mode==="column"?[Vo(e),Pn(e,{te:!1})]:[Pn(e,{te:!0})],Uo(e),Ko(e)]}var Ri=1e3,rn="Shown here, but not saved yet \u2014 it will be saved with your next change",et=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";function ir(e){let t=tr(e.root),n=or(t),o=Jo(document,t.dark);o.le(0);let r=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,s=document.documentElement.hasAttribute("data-pipeup-reserve"),l=new Map,d=new Set,m=new WeakSet,u={i:null,L:null,M:!1,hidden:!0,mode:rr(e.root),o:null,l:!1,d:!1,O:!1,c:!1},v=y("div",{class:"toast",role:"status","aria-live":"polite"}),x=y("div",{class:"sr","aria-live":"polite"});n.t.append(v,x);let T=null,C=[],c=null,k=!1,L=0,p=0,w=0,M=0,P=0,b=new Set,H="",_=new Map,F=jo(e.root,()=>{!k&&U()&&G()}),q=!1,J=0;function D(a,g=Oi,S=!1,O=!1){k||(q=S,v.textContent=a,O?v.setAttribute("aria-hidden","true"):v.removeAttribute("aria-hidden"),v.classList.add("show"),window.clearTimeout(L),L=window.setTimeout(()=>v.classList.remove("show"),g))}function K(){q&&(q=!1,window.clearTimeout(L),v.classList.remove("show"))}function oe(a){x.textContent="",cancelAnimationFrame(J),J=requestAnimationFrame(()=>x.textContent=a)}function ke(a){D(et(a))}function se(a){throw ke(a),a}let le=a=>({thread:a,location:bn(a.anchor,l.get(a.id)??$t(a.anchor,e.root),e.root)}),de=a=>(n.t.querySelector(`[data-thread="${a}"] .rbox textarea`)?.value.trim()??"")!=="",Se=a=>u.i!==a||u.M?!1:(c?.se()?c.ae():n.t.querySelector(".launch .mode")?.focus({preventScroll:!0}),!0),A={reply:async(a,g)=>{try{await e.doc.reply(a,g)}catch(S){S instanceof Ee?D(rn):se(S)}},resolve:async a=>{try{await e.doc.resolve(a),D("Resolved \xB7 Show resolved brings it back")}catch(g){D(g instanceof Ee?`Resolved \xB7 ${rn}`:et(g))}Se(a)&&(u.i=null)},reopen:async a=>{try{await e.doc.reopen(a),D("Reopened")}catch(g){D(g instanceof Ee?`Reopened \xB7 ${rn}`:et(g))}},close:()=>{ae(null);let a=Te&&n.t.querySelector(Te);a?a.focus({preventScroll:!0}):c?.ae(),Te=""},copy:a=>{try{let g=e.doc.threads().find(O=>O.id===a);if(!g)return;let S=Sn(le(g),"ai",location.href,Date.now());Bn(S,n.t).then(()=>D("Thread copied as Markdown for AI"),O=>D(et(O)))}catch(g){D(et(g))}}},N={copyAll:async a=>{let g=N.all(),S=Tn(g,a,{title:document.title,url:location.href,exportedAt:new Date});try{await Bn(S,n.t);let O=g.filter($=>!$.thread.resolved).length;D(`Copied ${O} thread${O===1?"":"s"}${a==="ai"?" as Markdown for AI":""}`)}catch(O){D(et(O))}},je:()=>{u.M=!u.M,G()},rename:async a=>{let g=a.replace(/\s+/g," ").trim();try{await We(g)?D(`New comments will say ${g}, but this browser couldn't remember it`):D(`New comments will say ${g}`)}catch(S){D(et(S))}},name:()=>e.doc.name,all:()=>[...e.doc.threads()].sort(Ve(B)).map(le)},R={},B={get addons(){return R.surface},doc:e.doc,root:e.root,t:n.t,host:n.element,state:u,resolved:l,k:d,j:A,c:N,p:F,F:a=>b.has(a.id),Ee:()=>{U()&&G()},B:a=>!u.hidden&&(!a.resolved||u.M||de(a.id))&&!b.has(a.id),Je:(a,g)=>{for(let S of e.doc.threads()){let O=l.get(S.id);if(S.anchor.quote&&B.B(S)&&O?.range&&Co(a,g,xt(O)))return S}return null},ne:(a,g)=>B.C()?B.Je(a,g):null,m:a=>a.composedPath().includes(n.element),we:a=>void m.add(a),qe:a=>m.has(a),open:ae,Ge:a=>re(a),L:Ke,Ye:ze,Ue:nt,C:()=>!T||T.De(),be:a=>{let g=T?.ve();a(),g?.()},ze:()=>{let a=u.o?.anchor.view,g=T?.ve();Promise.resolve(F.u(a)||F.W(a??{}).then(()=>B.Ee())).then(g)},Be:Ye,Fe:ne,Xe:ue,N:ot,D:a=>{T=a},Z:D,w:oe,Ke:K,re:ke,Qe:Oe,f:G,ie:he},z=R.surface=new Wt(B,n.shadow,x);function V(a){let g=performance.now(),S=e.doc.threads();for(let O of S){if(a&&!a.has(O.id))continue;let $=performance.now()-g<Mi,Y=$t(O.anchor,e.root,{fuzzy:$});l.set(O.id,Y),!$&&Y.state==="orphaned"?d.add(O.id):d.delete(O.id)}for(let O of[...l.keys()])S.some($=>$.id===O)||l.delete(O);d.size===0?(window.clearTimeout(M),M=0):M===0&&(M=window.setTimeout(()=>{M=0,!k&&(V(new Set(d)),G())},Ci))}function U(){let a=new Set,g=F.slide()!==null,S=new Set;for(let $ of e.doc.threads()){S.add($.id);let Y=l.get($.id)?.element;(!F.u($.anchor.view)||!g&&Y?.checkVisibility?.({visibilityProperty:!0})===!1)&&a.add($.id)}b=a;for(let $ of _.keys())S.has($)||_.delete($);let O=`${F.slide()}|${[...a].join()}`;return O===H?!1:(H=O,!0)}function W(a){let g=[],S=[],O=[];for(let $ of a){let Y=l.get($.id);$.resolved&&!u.M||!Y?.range||b.has($.id)||($.id===u.i||$.id===u.L?S.push(Y.range):$.resolved?O.push(Y.range):g.push(Y.range))}u.o&&F.u(u.o.anchor.view)&&S.push(...u.o.ranges),Qo({quote:g,on:S,done:O})}let ee=0,_e=0,be=0;function Ue(a){if(a===_e)return;_e=a,cancelAnimationFrame(be);let g=ee,S=performance.now(),O=a?260:200,$=Y=>{let X=Math.min(1,(Y-S)/O);ee=g+(a-g)*(a?1-(1-X)**3:X*X),o.le(ee),X<1&&(be=requestAnimationFrame($))};be=requestAnimationFrame($)}let Ce=0,te=0;function qe(a){a!==Ce&&(Ce=a,o.Te(a,r),window.clearTimeout(te),te=window.setTimeout(()=>{V(),G()},r?0:400))}function G(){if(k)return;let a=e.doc.threads();if(U(),u.i&&b.has(u.i)){let S=n.t.querySelector(`[data-thread="${u.i}"] .rbox textarea`)?.value;S&&_.set(u.i,S),u.i=null}u.hidden=!u.l&&!u.d&&!u.O&&!u.o,u.hidden&&(u.i=null),Ue(u.hidden?0:1),n.t.classList.toggle("hidden",u.hidden),n.t.classList.toggle("listing",u.d);let g=u.d&&!Qe();qe(g?kt:0),o.ke(s?u.mode==="column"&&!u.hidden&&!g?Tt:0:null),W(a);for(let S of C)S.f(a);c?.f(a),u.hidden||z.flush()}let Te="",ce=()=>n.t.getRootNode().activeElement,pe="input,textarea,select,[contenteditable]:not([contenteditable=false])",me=()=>{let a=ce();return a instanceof HTMLTextAreaElement&&a.value!==""||!!document.activeElement?.matches(pe)};function re(a,g=me(),S=ce()){let O=[...n.t.querySelectorAll(`[data-thread="${a}"] .rbox textarea`)].find(Y=>!Y.closest("[inert]")),$=S?.getAttribute("data-thread");Te=$?`.${S.classList[0]}[data-thread="${$}"]`:"",!(g||!O)&&O.focus({preventScroll:!0})}function Pe(){let a=u.o;return!a||B.C()?!1:(F.u(a.anchor.view)||F.W(a.anchor.view??{}),!0)}function ae(a,g=!1){if(a&&Pe())return;if(u.i===a&&!u.o)return a?re(a):void 0;let S=!g&&me(),O=ce();if(a||(u.O=!1),u.i=a,a&&(u.o=null,Oe(a)),G(),a){let $=_.get(a),Y=$&&n.t.querySelector(`[data-thread="${a}"] .rbox textarea`);Y&&!Y.value&&(Y.value=$,Y.dispatchEvent(new Event("input",{bubbles:!0}))),_.delete(a),g&&c?.se()?c.ae():re(a,S,O)}}function Ke(a){u.L!==a&&(u.L=a,a&&a!==u.i&&Oe(a),G())}function ze(a){K(),u.d=!1,u.o=a,u.i=null,G()}function nt(a){if(!u.o)return ze(a);Object.assign(u.o,a),G()}function ne(){u.o&&(u.o=null,G())}function ue(a,g=!1){u.l!==a&&(u.l=a,o.Se(a),a?(u.i=null,u.d=!1,c=Bo(B)):(K(),c?.destroy(),c=null,oe("Comment mode off")),G(),c&&(g&&c.xe(),g?c.se()?D(Rn,Ni,!0,!0):D("Nothing here to comment on"):D(`Click anything to comment, or Tab between blocks \xB7 Option-click (Alt-click) to pin \xB7 ${bt} or Esc to finish`,Ii,!0)))}function he(){u.o&&(F.u(u.o.anchor.view)||B.C())?ne():u.i?ae(null):c&&!c.ie()&&ue(!1)}function ot(){if(u.o){Pe()||ne();return}u.i&&ae(null)}async function We(a){try{return await e.onName(a),!1}catch(g){if(e.doc.name!==a)throw g;return!0}}async function Ye(a){let g=u.o;if(g)try{let S=await e.doc.comment(g.anchor,a);u.o=null,V(new Set([S])),ae(S,!0)}catch(S){if(S instanceof Ee){u.o=null,V(new Set([S.id])),ae(S.id,!0),D(rn);return}se(S)}}function Oe(a){let g=l.get(a);if(!g||g.state==="orphaned")return;let S=g.range?xt(g):g.element?[g.element.getBoundingClientRect()]:[];for(let O of S.slice(0,6)){let $=y("div",{class:"pulse"});Be($,O,4),n.t.prepend($),window.setTimeout(()=>$.remove(),1300)}}function xe(){for(let a of C)a.destroy();C=$i(B),G()}let Ie=()=>{if(!k){for(let a of C)a.S();c?.S(),z.S(),P=requestAnimationFrame(Ie)}},je=a=>{let g=a.composedPath()[0];return g instanceof Element&&g.closest(pe)!==null},rt=a=>{if(a.key==="Escape")return he();if(Mo(a)&&!a.isComposing&&!a.defaultPrevented&&!je(a)){if(a.preventDefault(),c?.We()&&c.xe())return;ue(!u.l,!0)}},Ne=a=>{if(B.m(a)||m.has(a))return;let g=window.getSelection();g&&!g.isCollapsed||ot()},h=()=>{let a=rr(e.root,u.mode==="column");a!==u.mode?(u.mode=a,xe()):G()};function E(){let a=performance.now();p===0&&(w=a),window.clearTimeout(p);let g=Math.min(Pi,Math.max(0,w+Ri-a));p=window.setTimeout(()=>{p=0,V(),G()},g)}let I=new MutationObserver(a=>{a.every(g=>n.element.contains(g.target))||E()});window.addEventListener("keydown",rt),window.addEventListener("click",Ne),window.addEventListener("resize",h),I.observe(e.root,{subtree:!0,childList:!0,characterData:!0});let i=new ResizeObserver(E);i.observe(e.root);let f=e.doc.onChange((a,g,S)=>{z.Oe(g,S),V(),G()});return V(),xe(),P=requestAnimationFrame(Ie),{ctx:B,destroy(){k=!0,cancelAnimationFrame(P),cancelAnimationFrame(be),cancelAnimationFrame(J),F.destroy(),window.clearTimeout(te),window.clearTimeout(L),window.clearTimeout(p),window.clearTimeout(M),I.disconnect(),i.disconnect(),f(),window.removeEventListener("keydown",rt),window.removeEventListener("click",Ne),window.removeEventListener("resize",h),c?.destroy();for(let a of C)a.destroy();z.destroy(),o.remove(),n.destroy()}}}var tt=null,Hi=4e3;function Di(e={}){if(Fe)return Fe.mount(e);if(!To())return Promise.reject(new Error("pipeup: another copy of Pipeup owns the add-on queue. Remove one script."));if(tt)return tt;let t=Fi(e,()=>t).catch(n=>{throw tt===t&&(tt=null),n});return tt=t,t}function Bi(e,t){return new Promise((n,o)=>{let r=setTimeout(()=>o(new Error("timed out")),t);e.then(n,o).finally(()=>clearTimeout(r))})}async function Fi(e,t){let n=document.documentElement.getAttribute("data-pipeup-doc"),{id:o,key:r}=n?await un(n):{id:`page-${He(location.origin+location.pathname)}`,key:null},s,l=!1,d;if(e.store)s=e.store,d=await ut(s);else try{let c=ft.open();s=await Bi(c,Hi).catch(k=>{throw c.then(L=>L.close(),()=>{}),k}),d=await ut(s)}catch{s=new pt,l=!0,d=await ut(s)}let m=e.name?.trim();m&&m!==d.name&&(d={...d,name:m},await s.saveProfile(d));let u=await ct.open({doc:o,key:r,store:s,identity:d.identity,name:d.name});on(e.slides??null);let v;try{v=ir({doc:u,root:e.root??document.body,onName:async c=>{u.name=c,d={...d,name:c},await s.saveProfile(d)}})}catch(c){throw on(null),c}l&&v.ctx.Z("This browser can't keep comments for this page \u2014 copy the comments (Copy as Markdown) to keep them");let x=()=>void u.flush().catch(c=>globalThis.reportError?.(c)),T=Lo({surface:v.ctx.addons,doc:u,root:e.root??document.body,ephemeral:l,version:bo}),C=!1;return window.addEventListener("pagehide",x),{document:u,flush:()=>u.flush(),unmount:()=>{C||(C=!0,window.removeEventListener("pagehide",x),T(),v.destroy(),on(null),tt===t()&&(tt=null))}}}export{zt as ADDON_API,st as ANIMALS,xn as COLOURS,io as DEFAULT_PROFILE_NAME,ft as IndexedDbStore,pt as MemoryStore,ct as PipeupDocument,Ee as UnsavedChangeError,bo as VERSION,Yr as addons,ye as animalName,Tn as copyAll,Sn as copyThread,sn as createIdentity,vn as describeElement,gn as describeRange,at as formatAgo,De as labelOf,ut as loadOrCreateProfile,bn as locate,Di as mount,fe as nameOf,fr as newDocumentAttribute,yi as onReveal,un as parseDocumentAttribute,$t as resolveAnchor,vi as setViewState,Kt as use};
|
|
1
|
+
function e(e){let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function t(e){let t=atob(e.replace(/-/g,"+").replace(/_/g,"/")),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function n(e){return(new TextEncoder).encode(e)}function o(e){if(null===e||"object"!=typeof e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(o).join(",")+"]";let t=e;return"{"+Object.keys(t).filter(e=>void 0!==t[e]).sort().map(e=>JSON.stringify(e)+":"+o(t[e])).join(",")+"}"}function i(e){return e.replace(/\s+/g," ").trim()}function r(e){let t=i(e),n=2166136261;for(let e=0;e<t.length;e++)n^=t.charCodeAt(e),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")}var a=/^[A-Za-z0-9_-]{43}$/,l=new Map;async function s(){let t=await crypto.subtle.generateKey({name:"Ed25519"},!1,["sign","verify"]);return{publicKey:e(new Uint8Array(await crypto.subtle.exportKey("raw",t.publicKey))),privateKey:t.privateKey}}async function d(t,n){let o=await crypto.subtle.sign({name:"Ed25519"},t.privateKey,n);return e(new Uint8Array(o))}var c=2**40,u=2**47,p=1e4,h=/^[0-9a-f]{8}$/,f=/^[A-Za-z0-9_-]{43}$/,m=/^[A-Za-z0-9_-]{43}$/,v=new Set(["create","reply","edit","delete","resolve","reopen"]);async function g(e,t){if(e.author!==t.publicKey)throw new Error("pipeup: an op must be signed by its author");return{body:e,sig:await d(t,n(o(e)))}}var w=(e,t)=>"string"==typeof e&&e.length<=t,y=e=>!!e&&"object"==typeof e,b=e=>"number"==typeof e&&Number.isFinite(e)&&e>=0&&e<=1;function x(e){if(!y(e))return!1;let{id:t,path:n,fingerprint:o,snapshot:i,quote:r,point:a,view:l}=e;if(!(w(n,2e3)&&w(i,500)&&"string"==typeof o&&h.test(o)&&(void 0===t||w(t,200)&&""!==t)&&(void 0===r||y(r)&&w(r.exact,p)&&""!==r.exact&&w(r.prefix,64)&&w(r.suffix,64))&&(void 0===a||y(a)&&b(a.x)&&b(a.y))))return!1;if(void 0!==l){if(!y(l)||Array.isArray(l))return!1;let e=Object.entries(l);if(e.length>16||!e.every(([e,t])=>e.length<=64&&w(t,200)))return!1}return!0}function k(e){if(!y(e))return!1;let{body:t,sig:n}=e;if("string"!=typeof n||!y(t)||JSON.stringify({body:t,sig:n}).length>262144)return!1;let o=t;return!(1!==o.v||"string"!=typeof o.id||!f.test(o.id)||!v.has(o.kind)||!w(o.doc,64)||""===o.doc||"string"!=typeof o.thread||!f.test(o.thread)||"string"!=typeof o.author||!m.test(o.author)||"string"!=typeof o.name||o.name.length>80||o.name!==o.name.trim()||"number"!=typeof o.clock||!Number.isSafeInteger(o.clock)||o.clock<1||o.clock>c||"number"!=typeof o.at||!Number.isSafeInteger(o.at)||o.at<0||o.at>u||void 0!==o.text&&(!w(o.text,1e4)||o.text!==o.text.trim())||void 0!==o.target&&("string"!=typeof o.target||!f.test(o.target))||("create"===o.kind||"reply"===o.kind||"edit"===o.kind)&&!o.text||("reply"===o.kind||"edit"===o.kind||"delete"===o.kind)&&!o.target||"create"===o.kind&&(o.id!==o.thread||!x(o.anchor)))}function E(i){return async function(n,o,i){if(!a.test(n))return!1;try{if(e(t(n))!==n)return!1;let r=l.get(n);if(!r){l.size>=512&&l.delete(l.keys().next().value),r=crypto.subtle.importKey("raw",t(n),{name:"Ed25519"},!0,["verify"]),l.set(n,r);let e=r;e.catch(()=>{l.get(n)===e&&l.delete(n)})}return await crypto.subtle.verify({name:"Ed25519"},await r,t(i),o)}catch{return!1}}(i.body.author,n(o(i.body)),i.sig)}function S(e,t){return e.body.clock!==t.body.clock?e.body.clock-t.body.clock:e.body.at!==t.body.at?e.body.at-t.body.at:e.body.author!==t.body.author?e.body.author<t.body.author?-1:1:e.body.id!==t.body.id?e.body.id<t.body.id?-1:1:0}function L(e,t,n,o,i){return{id:e,author:t,name:n,text:o,at:i,edited:!1,deleted:!1,replies:[]}}async function M(t){let i={...t,id:void 0,thread:"create"===t.kind?void 0:t.thread},r=await crypto.subtle.digest("SHA-256",n(o(i)));return e(new Uint8Array(r))}var $=class{constructor(e){this.doc=e}ops=new Map;clock=0;createAt=new Map;threadAt=new Map;get size(){return this.ops.size}all(){return[...this.ops.values()]}threads(){return function(e){let t=new Map,n=new Map,o=new Map;for(let{body:i}of[...e].sort(S)){if(i.name&&o.set(i.author,i.name),"create"===i.kind){if(t.has(i.id)||!i.anchor||void 0===i.text)continue;let e=L(i.id,i.author,i.name,i.text,i.at);t.set(i.id,{id:i.id,anchor:i.anchor,root:e,resolved:!1}),n.set(i.id,{comment:e,thread:i.id});continue}let e=t.get(i.thread);if(!e)continue;if("resolve"===i.kind||"reopen"===i.kind){e.resolved="resolve"===i.kind;continue}let r=i.target?n.get(i.target):void 0;if(r&&r.thread===i.thread){if("reply"===i.kind){if(n.has(i.id)||void 0===i.text)continue;let t=L(i.id,i.author,i.name,i.text,i.at);e.root.replies.push(t),n.set(i.id,{comment:t,thread:i.thread});continue}i.author!==r.comment.author||r.comment.deleted||("edit"===i.kind&&void 0!==i.text&&(r.comment.text=i.text,r.comment.edited=!0),"delete"===i.kind&&(r.comment.text="",r.comment.deleted=!0))}}for(let{comment:e}of n.values())e.name||(e.unnamed=!0,e.name=o.get(e.author)??"");return[...t.values()]}(this.ops.values())}async add(e){let t=[];for(let n of e){if(!k(n)||n.body.doc!==this.doc||this.ops.has(n.body.id)||n.body.id!==await M(n.body)||!await E(n))continue;let e={body:n.body,sig:n.sig};this.ops.set(e.body.id,e),this.clock=Math.max(this.clock,e.body.clock),"create"===e.body.kind&&this.createAt.set(e.body.author,Math.max(this.createAt.get(e.body.author)??0,e.body.at)),this.threadAt.set(e.body.thread,Math.max(this.threadAt.get(e.body.thread)??0,e.body.at)),t.push(e)}return t}async append(e,t,n){let o={v:1,...n,id:"",thread:"create"===n.kind?"":n.thread,doc:this.doc,author:e.publicKey,name:t,clock:Math.min(this.clock+1,c),at:Math.min(Math.max(Date.now(),"create"===n.kind?(this.createAt.get(e.publicKey)??0)+1:(this.threadAt.get(n.thread)??0)+1),u)};o.id=await M(o);let i=this.ops.get(o.id);if(i)return i;"create"===o.kind&&(o.thread=o.id);let[r]=await this.add([await g(o,e)]);if(!r)throw new Error("pipeup: could not record this change");return r}},A=["Otter","Fox","Owl","Bear","Rabbit"],C=["Red","Orange","Yellow","Green","Teal","Blue","Purple","Pink","Brown","Grey"];function T(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),(t^t>>>16)>>>0}var P=e=>T(e)%A.length,N=e=>Math.floor(T(e)/A.length)%C.length,q=e=>`${C[N(e)]} ${A[P(e)]}`,z=e=>e.name||q(e.author),O="AI assistant",D=e=>e===O||e.startsWith(`${O} `),R=/^([A-Za-z0-9_-]{16}):([A-Za-z0-9_-]{43})$/;function F(){return`${function(t=16){return e(crypto.getRandomValues(new Uint8Array(t)))}(12)}:${e(crypto.getRandomValues(new Uint8Array(32)))}`}async function H(e){let n=R.exec(e.trim()),o=n?.[1],i=n?.[2];if(!o||!i)throw new Error('pipeup: data-pipeup-doc must look like "<id>:<key>", as made by newDocumentAttribute()');return{id:o,key:await crypto.subtle.importKey("raw",t(i),{name:"AES-GCM"},!1,["encrypt","decrypt"])}}async function I(t,o,i){let r=crypto.getRandomValues(new Uint8Array(12)),a=await crypto.subtle.encrypt({name:"AES-GCM",iv:r,additionalData:n(i)},t,n(o));return{iv:e(r),data:e(new Uint8Array(a))}}var B=e=>`pipeup-file:${e}`;var W=/^[a-z][a-z0-9-]{1,23}\/[a-z][a-z0-9-]{0,31}$/,j=class extends Error{constructor(e,t,n=1){super("pipeup: shown here, but not saved yet"),this.id=e,this.cause=t,this.count=n,this.name="UnsavedChangeError"}},K=class e{constructor(e,t){this.log=e,this.options=t,this.displayName=t.name.trim()?Y(t.name):""}listeners=new Set;cache=[];comments=new Map;displayName;le=Promise.resolve();unsaved=[];static async open(t){if("string"!=typeof t.doc||""===t.doc||t.doc.length>64)throw new Error("pipeup: the document id must be 1 to 64 characters");let n=new $(t.doc),o=await t.store.load(t.doc),i=o.length-(await n.add(o)).length;i&&console.warn(`pipeup: ${i} saved change${1===i?"":"s"} on this page couldn't be read; kept as saved`);let r=new e(n,t);return r.refresh(!1),r}get id(){return this.options.doc}get me(){return this.options.identity.publicKey}get name(){return this.displayName}set name(e){this.displayName=Y(e),this.refresh(!0,[],"")}threads(){return this.cache}ops(){return this.log.all()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}comment(e,t){return this.enqueue(()=>this.write({kind:"create",anchor:e,text:V(t)}))}reply(e,t){return this.enqueue(()=>this.write({kind:"reply",thread:this.find(e).thread,target:e,text:V(t)}))}edit(e,t){return this.enqueue(async()=>{let{thread:n}=this.mine(e);await this.write({kind:"edit",thread:n,target:e,text:V(t)})})}remove(e){return this.enqueue(async()=>{let{thread:t}=this.mine(e);await this.write({kind:"delete",thread:t,target:e})})}resolve(e){return this.enqueue(async()=>{await this.write({kind:"resolve",thread:this.thread(e)})})}reopen(e){return this.enqueue(async()=>{await this.write({kind:"reopen",thread:this.thread(e)})})}sign(e,t){if(!W.test(e))throw new Error('pipeup: a signing purpose looks like "<add-on id>/<name>"');return d(this.options.identity,n(`pipeup:${e}\n${t}`))}flush(){return this.enqueue(()=>this.persist())}exportFile(){return async function(e,t,n){let o=n?{pipeup:1,doc:e,sealed:!0,...await I(n,JSON.stringify(t),B(e))}:{pipeup:1,doc:e,sealed:!1,ops:t};return JSON.stringify(o,null,2)}(this.options.doc,this.log.all(),this.options.key)}async importFile(e){return this.merge(await async function(e,o,i){if(e.length>5e6)throw new Error("pipeup: this feedback file is too large");let r,a,l;try{r=JSON.parse(e)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}if(!r||"object"!=typeof r||1!==r.pipeup||"string"!=typeof r.doc)throw new Error("pipeup: this is not an Pipeup feedback file");if(r.doc!==o)throw new Error("pipeup: this feedback is for a different document");if(!r.sealed)return Array.isArray(r.ops)?r.ops:[];if(!i)throw new Error("pipeup: this feedback is sealed, and this page has no document key");if("string"!=typeof r.iv||"string"!=typeof r.data)throw new Error("pipeup: this is not an Pipeup feedback file");try{a=await async function(e,o,i){try{let r=await crypto.subtle.decrypt({name:"AES-GCM",iv:t(o.iv),additionalData:n(i)},e,t(o.data));return(new TextDecoder).decode(r)}catch{throw new Error("pipeup: this feedback could not be opened with this document")}}(i,{iv:r.iv,data:r.data},B(o))}catch{throw new Error("pipeup: this feedback could not be opened with this document's key")}try{l=JSON.parse(a)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}return Array.isArray(l)?l:[]}(e,this.options.doc,this.options.key),"file")}merge(e,t){return e.length>5e3?Promise.reject(new RangeError("pipeup: too many changes to merge at once")):this.enqueue(async()=>{let n=await this.log.add([...e]);this.unsaved.push(...n),n.length>0&&this.refresh(!0,n,t);try{await this.persist()}catch(e){throw n.length>0?new j(n[0].body.id,e,n.length):e}return n.length})}enqueue(e){let t=this.le.then(e);return this.le=t.catch(()=>{}),t}async write(e){let t=await this.log.append(this.options.identity,this.displayName,e);this.unsaved.push(t),this.refresh(!0,[t],"local");try{await this.persist()}catch(e){throw new j(t.body.id,e)}return t.body.id}async persist(){if(0===this.unsaved.length)return;let e=[...this.unsaved];await this.options.store.append(this.options.doc,e),this.unsaved=this.unsaved.filter(t=>!e.includes(t))}refresh(e,t=[],n=""){this.cache=this.log.threads(),this.comments.clear();let o=(e,t)=>{e.unnamed&&e.author===this.me&&this.displayName&&(e.name=this.displayName),this.comments.set(e.id,{comment:e,thread:t});for(let n of e.replies)o(n,t)};for(let e of this.cache)o(e.root,e.id);if(e)for(let e of this.listeners)try{e(this.cache,t,n)}catch(e){globalThis.reportError?.(e)}}find(e){let t=this.comments.get(e);if(!t)throw new Error("pipeup: there is no comment with that id");return t}mine(e){let t=this.find(e);if(t.comment.author!==this.me)throw new Error("pipeup: only the writer can change a comment");return t}thread(e){if(!this.cache.some(t=>t.id===e))throw new Error("pipeup: there is no thread with that id");return e}};function V(e){let t=e.trim();if(!t)throw new Error("pipeup: a comment needs some words");if(t.length>1e4)throw new Error("pipeup: comments are limited to 10000 characters");return t}function Y(e){let t=e.replace(/\s+/g," ").trim();if(!t||t.length>80)throw new Error("pipeup: choose a name of 1 to 80 characters");if(D(t))throw new Error("pipeup: that name is kept for AI replies; choose another");return t}var U=class{docs=new Map;profile=null;async load(e){return[...this.docs.get(e)?.values()??[]]}async append(e,t){let n=this.docs.get(e);n||this.docs.set(e,n=new Map);for(let e of t)n.set(e.body.id,e)}async loadProfile(){return this.profile}async saveProfile(e){this.profile=e}async saveProfileIfAbsent(e){return this.profile||(this.profile=e),this.profile}},_="";async function G(e,t=""){let n=await e.loadProfile();if(n)return"Reviewer"===n.name?{...n,name:""}:n;let o={identity:await s(),name:t};return e.saveProfileIfAbsent(o)}var J=class e{constructor(e){this.db=e}static open(t="pipeup"){return new Promise((n,o)=>{let i=indexedDB.open(t,1);i.onupgradeneeded=()=>{let e=i.result;e.createObjectStore("ops",{keyPath:["doc","id"]}).createIndex("doc","doc"),e.createObjectStore("meta")},i.onsuccess=()=>{let t=i.result;t.onversionchange=()=>t.close(),n(new e(t))},i.onerror=()=>o(i.error??new Error("pipeup: could not open local storage"))})}close(){this.db.close()}async load(e){return(await this.request("ops","readonly",t=>t.index("doc").getAll(e))).map(e=>e.op)}async append(e,t){if(0===t.length)return;let n=this.db.transaction("ops","readwrite"),o=n.objectStore("ops"),i=X(n);try{for(let n of t)o.put({doc:e,id:n.body.id,op:n})}catch(e){throw n.abort(),i.catch(()=>{}),e}await i}async loadProfile(){return await this.request("meta","readonly",e=>e.get("profile"))??null}async saveProfile(e){await this.request("meta","readwrite",t=>t.put(e,"profile"))}async saveProfileIfAbsent(e){let t=this.db.transaction("meta","readwrite"),n=t.objectStore("meta"),o=X(t),i=e,r=n.get("profile");return r.onsuccess=()=>{r.result?i=r.result:n.put(e,"profile")},await o,i}request(e,t,n){return new Promise((o,i)=>{let r=n(this.db.transaction(e,t).objectStore(e));r.onsuccess=()=>o(r.result),r.onerror=()=>i(r.error??new Error("pipeup: local storage request failed"))})}};function X(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error??new Error("pipeup: local storage write failed")),e.onabort=()=>n(e.error??new Error("pipeup: local storage write aborted"))})}function Z(e){let t=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[],o="";for(let e=t.nextNode();e;e=t.nextNode())n.push({node:e,start:o.length}),o+=e.data;return{text:o,nodes:n}}function Q(e,t,n){let o=(e.ownerDocument??e).createRange();return o.setStart(e,0),o.setEnd(t,n),o.toString().length}function ee(e,t,n){let o=te(e,t,!1),i=te(e,n,!0);if(!o||!i||n<t)return null;let r=o.node.ownerDocument.createRange();return r.setStart(o.node,o.offset),r.setEnd(i.node,i.offset),r}function te(e,t,n){let o=e.nodes.find(e=>t>=e.start&&t<e.start+e.node.data.length+Number(n));return o&&{node:o.node,offset:t-o.start}}function ne(e){return e.nodeType===Node.ELEMENT_NODE?e:e.parentElement}function oe(e,t){for(let n=ne(e)?.closest("[data-pipeup-id]")??null;n;){if(!t.contains(n))return null;let e=n.getAttribute("data-pipeup-id")??"";if(""!==e&&e.length<=200)return n;n=n.parentElement?.closest("[data-pipeup-id]")??null}return null}function ie(e,t,n){return e.slice(t,n).replace(/^[\uDC00-\uDFFF]|[\uD800-\uDBFF]$/g,"")}function re(e,t){let n=function(e,t){if(e===t)return"";let n=[];for(let o=t;o&&o!==e;o=o.parentElement){let e=1;for(let t=o.previousElementSibling;t;t=t.previousElementSibling)t.tagName===o.tagName&&e++;n.unshift(`${o.tagName.toLowerCase()}:nth-of-type(${e})`)}return":scope > "+n.join(" > ")}(e,t);if(n.length>2e3)throw new Error("pipeup: this element is nested too deeply to comment on — give a nearby container a data-pipeup-id");return n}function ae(e){if(!x(e))throw new Error("pipeup: could not describe this place on the page");return e}function le(e,t){let n=ne(e),o=n?.closest("p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,pre,figcaption,dt,dd,summary,caption")??null;return o&&t.contains(o)?o:n&&t.contains(n)?n:t}function se(e,t,n){if(!t.contains(e.commonAncestorContainer))throw new Error("pipeup: the selection is outside the commentable area");let o=oe(e.commonAncestorContainer,t),a=o??t,{text:l}=Z(a),s=Q(a,e.startContainer,e.startOffset),d=Q(a,e.endContainer,e.endOffset),c=l.slice(s,d);if(""===c)throw new Error("pipeup: select some text to comment on");if(c.length>p)throw new Error("pipeup: selections are limited to 10000 characters");let u=ie(l,Math.max(0,s-32),s),h=ie(l,d,d+32);return ae({...o?{id:o.getAttribute("data-pipeup-id")??""}:{},path:"",quote:{exact:c,prefix:u,suffix:h},...n?{view:n}:{},fingerprint:r(le(e.startContainer,t).textContent??""),snapshot:ie(i(u+c+h),0,200)})}function de(e,t,n,o){let a=oe(e,t);return ae({...a?{id:a.getAttribute("data-pipeup-id")??""}:{},path:re(a??t,e),...n?{point:{x:ce(n.x),y:ce(n.y)}}:{},...o?{view:o}:{},fingerprint:r(e.textContent??""),snapshot:ie(i(e.textContent??""),0,200)})}function ce(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function ue(e,t,n){let o=Array.from({length:t.length+1},(e,t)=>t),i=[...o],r=[t.length];for(let a=1;a<=e.length;a++){i[0]=n?0:a;for(let n=1;n<=t.length;n++){let r=e.charCodeAt(a-1)===t.charCodeAt(n-1)?0:1;i[n]=Math.min(o[n]+1,i[n-1]+1,o[n-1]+r)}r.push(i[t.length]),[o,i]=[i,o]}return r}var pe=(e,t)=>ue(e,t,!1).pop(),he={state:"orphaned",element:null,range:null};function fe(e,t,n={}){let o=e.id?function(e,t){for(let n of e.querySelectorAll("[data-pipeup-id]"))if(n.getAttribute("data-pipeup-id")===t)return n;return null}(t,e.id):t;return e.quote?function(e,t,n,o,i){let a=n??o,l=Z(a),s=function(e,t){if(!t.exact)return-1;let n=-1,o=-1;for(let i=e.indexOf(t.exact);-1!==i;i=e.indexOf(t.exact,i+1)){let r=e.slice(Math.max(0,i-t.prefix.length),i),a=e.slice(i+t.exact.length,i+t.exact.length+t.suffix.length),l=ve(r,t.prefix)+me(a,t.suffix);l>o&&(n=i,o=l)}return n}(l.text,t);if(s>=0){let i=ee(l,s,s+t.exact.length);if(i){let t=le(i.startContainer,o);return{state:null!==n&&r(t.textContent??"")===e.fingerprint?"attached":"moved",element:t,range:i}}}if(i){let e=a===o?l:Z(o);if(e.text.length<=5e4&&t.exact.length>=12&&t.exact.length<=300){let n=function(e,t,n){let o=t.length;if(0===o)return null;let i=-1,r=1/0;if(ue(e,t,!0).forEach((e,t)=>{t&&e<r&&(r=e,i=t)}),r>n)return null;let a=Math.max(0,i-o),l=1/0;for(let r=Math.max(0,i-o-n);r<=Math.min(i,i-o+n);r++){let n=pe(e.slice(r,i),t);n<l&&(l=n,a=r)}return{start:a,end:i,distance:l}}(e.text,t.exact,Math.floor(t.exact.length/4)),i=n?ee(e,n.start,n.end):null;if(i)return{state:"moved",element:le(i.startContainer,o),range:i}}}return he}(e,e.quote,o,t,!1!==n.fuzzy):function(e,t){if(!t)return he;let n=t;if(e.path){if(!e.path.startsWith(":scope > "))return he;try{n=t.querySelector(e.path)}catch{return he}}return n?{state:r(n.textContent??"")===e.fingerprint?"attached":"moved",element:n,range:null}:he}(e,o)}function me(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function ve(e,t){let n=0;for(;n<e.length&&n<t.length&&e[e.length-1-n]===t[t.length-1-n];)n++;return n}var ge={A:"Link",BUTTON:"Button",P:"Paragraph",LI:"List item",IMG:"Image",TABLE:"Table",TD:"Cell",TH:"Cell",FIGURE:"Figure",SVG:"Graphic",CANVAS:"Graphic",LABEL:"Label",INPUT:"Field",SELECT:"Field",TEXTAREA:"Field",SUMMARY:"Question",BLOCKQUOTE:"Quote",SECTION:"Section",H1:"Heading",H2:"Heading",H3:"Heading",H4:"Heading",H5:"Heading",H6:"Heading"};function we(e){return e.getAttribute("data-pipeup-label")||ge[e.tagName.toUpperCase()]||"Block"}function ye(e){return Ee(i(e.getAttribute("aria-label")??e.getAttribute("alt")??e.innerText??e.textContent??""),40)}function be(e){let t=e.getAttribute("data-pipeup-label");if(t)return t;let n=ye(e);return n?`${we(e)} · ${n}`:we(e)}function xe(e,t,n){let o=e.id??null,r=e.quote?.exact??null,a=e.point?`${Math.round(100*e.point.x)}% across, ${Math.round(100*e.point.y)}% down the element`:null,l=t.element;if("orphaned"===t.state||!l)return{where:`No longer on the page (it read: "${e.snapshot}")`,element:null,id:o,quote:r,pin:a};let s=[],d=e.view?.slide;if(d){let e=l.closest("[data-pipeup-slide]")?.querySelector("h1,h2,h3")?.textContent;s.push(`Slide ${d}`+(e?` "${Ee(i(e))}"`:""))}else{let t=ke(e.view);t&&s.push(t);let o=function(e,t){let n=null;for(let o of t.querySelectorAll("h1,h2,h3")){if(o===e||o.contains(e))break;if(!(4&o.compareDocumentPosition(e)))break;n=o}return n}(l,n);o&&s.push(`Section "${Ee(i(o.textContent??""))}"`)}let c=be(l);return s.push(c),{where:s.join(" › "),element:c,id:o,quote:r,pin:a}}function ke(e){return e?e.label||Object.entries(e).filter(([e,t])=>t&&"slide"!==e).map(([,e])=>e).join(" · "):""}function Ee(e,t=60){return e.length>t?e.slice(0,t-1)+"…":e}var Se="Each thread says where it is: the slide or section, the element (its data-pipeup-id attribute in the HTML), and the exact quoted text or pin position. Work through the open threads in order, and for each one say what you changed or why you did not.";function Le(e,t){let n=Math.max(0,Math.round((t-e)/1e3));if(n<60)return"just now";let o=Math.round(n/60);if(o<60)return`${o}m ago`;let i=Math.round(o/60);return i<48?`${i}h ago`:`${Math.round(i/24)}d ago`}function Me(e,t,n,o){return"ai"===t?Ce(e,"## Comment thread",o,n):Te(e)}function $e(e,t,n){let o=e.filter(e=>!e.thread.resolved);if("text"===t)return o.map(Te).join("\n");let i=e.length-o.length,r=[`# Review comments: ${Ae(n.title)}`,"",`- **Page:** ${Ae(n.url)}`,`- **Exported:** ${n.exportedAt.toISOString()}`,`- **Open threads:** ${o.length}${i?` (${i} resolved, not included)`:""}`,"",Se,"",""].join("\n"),a=n.exportedAt.getTime();return r+o.map((e,t)=>Ce(e,`## Thread ${t+1}`,a)).join("\n")}function Ae(e){return e.replace(/\s+/g," ").trim()}function Ce(e,t,n,o){let{thread:i,location:r}=e,a=i.root.replies.length,l=[`${t} · ${i.resolved?"resolved":"open"}`];if(l.push(`- **Thread:** ${i.id}`),o&&l.push(`- **Page:** ${Ae(o)}`),l.push(`- **Where:** ${Ae(r.where)}`),r.id){let e=Ae(r.id.replace(/`/g,""));l.push(`- **Element:** \`[data-pipeup-id="${e}"]\`${r.element?` (${Ae(r.element)})`:""}`)}r.quote&&l.push(`- **Quoted text:** "${Ae(r.quote)}"`),r.pin&&l.push(`- **Pin:** ${Ae(r.pin)}`),l.push(`- **Started by:** ${Ae(z(i.root))}, ${Le(i.root.at,n)}${a?` · ${a} ${1===a?"reply":"replies"}`:""}`,"",`**${Ae(z(i.root))}** (${Le(i.root.at,n)}): ${Pe(i.root," ")}`);for(let e of i.root.replies)l.push(`- **${Ae(z(e))}** (${Le(e.at,n)}): ${Pe(e," ")} \x3c!-- comment:${e.id} --\x3e`);return l.join("\n")+"\n"}function Te(e){let{thread:t,location:n}=e,o=[Ae(n.where)+(n.quote?`, on the text "${Ae(n.quote)}"`:""),`${Ae(z(t.root))}: ${Pe(t.root," ")}`];for(let e of t.root.replies)o.push(` ${Ae(z(e))}: ${Pe(e," ")}`);return o.join("\n")+"\n"}function Pe(e,t){return e.deleted?"(deleted)":e.text.replace(/\r\n|\r|\n/g,"\n"+t)+(e.edited?" (edited)":"")}var Ne="0.5.2";function qe(e,t={},...n){let o=document.createElement(e);for(let[e,n]of Object.entries(t))void 0===n||!1===n||("class"===e?o.className=String(n):o.setAttribute(e,!0===n?"":n));for(let e of n)null!=e&&!1!==e&&o.append(e);return o}function ze(e,t){let n=e.getRootNode().activeElement;t&&n instanceof HTMLElement&&e.contains(n)&&n.blur(),e.inert=t}function Oe(e,t,n=null){let o=e.getRootNode().activeElement,i=!1;for(let o=t.length;o--;n=t[o])t[o].nextSibling!==n&&(i=!!e.insertBefore(t[o],n));return i&&o&&t.some(e=>e.contains(o))&&o.focus({preventScroll:!0}),i}var De=()=>{let e=window.getSelection();return e&&!e.isCollapsed&&e.toString().trim()?e:null};function Re(e,t){return e.length>t?e.slice(0,t-1)+"…":e}function Fe(e,t,n=4){e.style.left=t.left-n+"px",e.style.top=t.top-n+"px",e.style.width=`${t.width+2*n}px`,e.style.height=`${t.height+2*n}px`}var He=/\bhttps?:\/\/[^\s<>"'`]+/gi,Ie=/[\u202A-\u202E\u2066-\u2069]/;function Be(e){let t=0,n=0;for(let o of e)"("===o?t++:")"===o&&n++;let o=e.length;for(;o>0;){let i=e[o-1];if(")"===i&&n>t)n--;else if(!".,;:!?'\"]}".includes(i))break;o--}return e.slice(0,o)}function We(e){let t=[],n=0;for(let o of e.matchAll(He)){if(o[0].length>2048||Ie.test(o[0]))continue;let i,r=Be(o[0]),a=o.index??0;try{let e=new URL(r);if("http:"!==e.protocol&&"https:"!==e.protocol)continue;i=e.href}catch{continue}a>n&&t.push(e.slice(n,a));let l=qe("a",{href:i,target:"_blank",rel:"noopener noreferrer"},r);l.addEventListener("click",e=>e.stopPropagation()),t.push(l),n=a+r.length}return n<e.length&&t.push(e.slice(n)),t}var je="http://www.w3.org/2000/svg",Ke={comment:["M20.5 11.5a8 8 0 0 1-11.7 7.1L4 19.8l1.2-4.4A8 8 0 1 1 20.5 11.5z","M12.3 8.2v6.6M9 11.5h6.6"],send:["M21 12L3.5 4.5 6.2 12l-2.7 7.5zM6.2 12H13"],copy:["M10 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2z","M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"],resolve:["M5 12.5l4.5 4.5L19 7.5"],reopen:["M3 12a9 9 0 1 0 3-6.7","M3 4v5h5"],lines:["M4 7h16M4 12h10M4 17h7"],list:["M3 6.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M3 12a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M3 17.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M9 6.5h11M9 12h11M9 17.5h7"],expand:["M14 4h6v6M20 4l-6 6M10 20H4v-6M4 20l6-6M20 14v6h-6M20 20l-6-6M4 10V4h6M4 4l6 6"],pin:["M6 18v-6a6 6 0 1 1 6 6z"],shrink:["M20 10h-6V4M14 10l6-6M4 14h6v6M10 14l-6 6M14 20v-6h6M14 14l6 6M10 4v6H4M10 10L4 4"],bubble:["M20.5 11.5a8 8 0 0 1-11.7 7.1L4 19.8l1.2-4.4A8 8 0 1 1 20.5 11.5z"],close:["M6 6l12 12M18 6L6 18"],edit:["M4 20h4L19 9l-4-4L4 16z"]};function Ve(e,t=15,n){let o=Ye(Ke[e],t);return n&&o.setAttribute("stroke-width",String(n)),o}function Ye(e,t){let n=document.createElementNS(je,"svg"),o={width:String(t),height:String(t),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[e,t]of Object.entries(o))n.setAttribute(e,t);for(let t of e){let e=document.createElementNS(je,"path");e.setAttribute("d",t),n.append(e)}return n}var Ue=(e,t,n)=>`M${e} ${t}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 -${2*n} 0`,_e={Otter:"M4 13.2C4 9.2 7.6 6.5 12 6.5s8 2.7 8 6.7-3.6 6.3-8 6.3-8-2.3-8-6.3zM5.6 9.6a1.8 1.8 0 1 1 2.7-2.3M18.4 9.6a1.8 1.8 0 1 0-2.7-2.3M9.2 11.6h.01M14.8 11.6h.01M11 14h2l-1 1zM9.8 15.8l-3.2.4M9.9 17l-2.7 1.1M14.2 15.8l3.2.4M14.1 17l2.7 1.1",Fox:"M3.5 4l5 3.5h7l5-3.5-1.5 8.5L12 20l-7-7.5zM9 12h.01M15 12h.01M12 17h.01",Owl:`M5 4.5l3 2.5h8l3-2.5V14a7 7 0 0 1-14 0z${Ue(7.4,11.5,1.9)}${Ue(12.8,11.5,1.9)}M11.3 14.6l.7 1 .7-1`,Bear:`${Ue(5,13.5,7)}M8.9 7.22A2.8 2.8 0 1 0 5.89 10.09M18.11 10.09A2.8 2.8 0 1 0 15.1 7.22M9.4 12.6h.01M14.6 12.6h.01M10.3 16.4c0-1 .8-1.6 1.7-1.6s1.7.6 1.7 1.6-.8 1.6-1.7 1.6-1.7-.6-1.7-1.6z`,Rabbit:`${Ue(6.5,15.5,5.5)}M9.6 10.5C8.2 6.5 8.4 2.5 9.8 2.5s2.4 3.5 1.6 7.5M14.4 10.5c1.4-4 1.2-8-.2-8s-2.4 3.5-1.6 7.5M10 15h.01M14 15h.01M11.3 17.3l.7.5.7-.5`};function Ge(e){let t=/[\p{L}\p{N}]/u.exec(e);if(!t)return"";let n=t[0].toUpperCase();return 1===[...n].length?n:t[0]}var Je=(e,t)=>Ge(t)||q(e);function Xe(e,t,n=!1){return D(t)?qe("span",{class:n?"av ai busy":"av ai","aria-hidden":"true"},"AI"):qe("span",{class:`av c${N(e)}`,"aria-hidden":"true","data-animal":q(e)},Ge(t)||Ye([_e[A[P(e)]]],24))}function Ze(e,t){setTimeout(()=>{e.remove(),t?.()},320)}function Qe(e){return requestAnimationFrame(()=>{e.offsetWidth,e.classList.add("in")}),e}var et=new Map,tt=null,nt=e=>{tt=e},ot="pu-source";function it(e){let t=qe("textarea",{class:"input",rows:"1","aria-label":e.label}),n=qe("button",{class:"send",type:"button","aria-label":"Send",title:"Send",inert:!0},Ve("send")),o=qe("span",{class:"tools"});o.hidden=!0;let i=qe("div",{class:"row"},e.before,t,o,n),r=e.kind??"comment",a=!1,l=new Set,s=()=>{for(let e of[...l])e()},d=()=>{let e=""!==t.value.trim();n.classList.toggle("show",e),n.inert=!e,t.style.height="auto",t.style.height=`${Math.max(27,t.scrollHeight)}px`},c=()=>{let e=-1,n=0,o=(o,i)=>{e<0&&(e=t.selectionStart,n=0);let r=t.value.slice(0,e),a=o&&r&&!/\s$/.test(r)&&!/^\s/.test(o)?" ":"";t.setRangeText(a+o,e,e+n,"end"),n=a.length+o.length,i&&(e=-1),d()};return{update:e=>o(e,!1),commit:e=>o(e,!0),cancel:()=>{e>=0&&n&&t.setRangeText("",e,e+n,"end"),e=-1,n=0,d()}}},u=new Map,p=()=>{let n=(tt?.tools()??[]).filter(e=>!1!==e.available?.());for(let[e,t]of u)n.some(t=>t.id===e)||(t.remove(),u.delete(e));for(let a of n){if(u.has(a.id))continue;let n=qe("button",{class:"ib tool",type:"button","aria-label":a.label,title:a.label,"aria-pressed":"false"},Ye(a.icon,15));n.addEventListener("mousedown",e=>e.preventDefault()),n.addEventListener("click",o=>{o.stopPropagation();try{a.press({kind:r,thread:e.thread?.()??null,text:()=>t.value,focus:()=>t.focus({preventScroll:!0}),connected:()=>i.isConnected,setPressed:e=>n.setAttribute("aria-pressed",String(e)),dictate:c,onEnd:e=>(l.add(e),()=>l.delete(e))})}catch(e){globalThis.reportError?.(e)}}),u.set(a.id,n),o.append(n)}o.hidden=0===u.size};p(),i.addEventListener(ot,p);let h=async()=>{let o=t.value.trim();if(o&&!a){a=!0;try{await e.V(o),n.matches(":focus")&&t.focus(),t.value="",d(),s()}catch{}finally{a=!1}}};return i.addEventListener("mousedown",e=>{e.target===t||n.contains(e.target)||o.contains(e.target)||(e.preventDefault(),t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}),t.addEventListener("input",d),t.addEventListener("keydown",n=>{n.stopPropagation(),"Enter"!==n.key||n.shiftKey||n.isComposing?"Escape"===n.key&&(n.preventDefault(),t.value="",d(),t.blur(),s(),e._?.()):(n.preventDefault(),h())}),n.addEventListener("click",e=>{e.stopPropagation(),h()}),{element:i,input:t,focus:()=>t.focus({preventScroll:!0})}}var rt=1,at=["sync","menu","notify","note","composer","panel","styles","status","overlay","here","sign"],lt=/^[a-z][a-z0-9-]{1,23}$/,st=new Set(["local","file","page","user","pipeup","presence","sync"]),dt=class{constructor(e,t,n){this.ctx=e,this.shadow=t,this.after=n,nt({tools:()=>this.q,note:()=>[...this.j.values()].at(-1)??null})}Y=0;N=[];j=new Map;writing=new Map;paint=0;G=new Map;q=[];X=new Set;I=new Set;U=new Set;K=new Map;S=new Map;z=new Map;remote={n:0,who:new Set};last=0;timer=0;ce="";subscribe(e){return this.U.add(e),()=>{this.U.delete(e)}}changed(e){e&&this.Y++;for(let t of[...this.U])t(e);for(let e of this.ctx.t.querySelectorAll(".row, .draft"))e.dispatchEvent(new Event(ot))}$(e,t){let n=this.z.get(e)??this.z.set(e,new Set).get(e),o=()=>{n.delete(o)&&t()};return n.add(o),o}de(){return[...this.G.values()].map(e=>e.text).join(" · ")}Ae(e,t){return this.N.push(t),this.changed(!0),{update:()=>this.changed(!1),remove:this.$(e,()=>{this.N.splice(this.N.indexOf(t),1),this.changed(!0)})}}setThread(e,t,n){let o=this.writing.get(e)??this.writing.set(e,new Set).get(e);null===n?(et.delete(t),o.delete(t)):(et.set(t,n),o.add(t)),this.repaint()}repaint(){this.paint||(this.paint=window.requestAnimationFrame(()=>{this.paint=0,this.ctx.m()}))}pe(e,t,n){n?e.set(t,n):e.delete(t),this.changed(!1)}Me(e,t){return this.q.push(t),this.changed(!1),this.$(e,()=>{this.q.splice(this.q.indexOf(t),1),this.changed(!1)})}closed(){return this.ctx.state.hidden&&!this.ctx.state.c}Le(e,t){this.closed()?this.S.set(e,t):this.ctx.J(t)}flush(){if(this.closed()||0===this.S.size)return;let e=[...this.S.values()].at(-1);this.S.clear(),this.ctx.J(e)}Ce(){return this.shadow.activeElement instanceof HTMLTextAreaElement||[...this.ctx.t.querySelectorAll("textarea")].some(e=>""!==e.value.trim())}Pe(e){this.ctx.state.hidden||this.ctx.E(e)}Oe(e,t){if("local"!==t&&""!==t){for(let{body:t}of e)t.author===this.ctx.doc.me||"create"!==t.kind&&"reply"!==t.kind||(this.remote.n++,this.remote.who.add(t.name||q(t.author)));this.ue()}}ue(e=Math.max(0,this.last+1e4-Date.now())){this.timer||!this.remote.n||(this.timer=window.setTimeout(()=>{if(this.timer=0,this.ctx.state.hidden||this.Ce())return this.ue(1e3);let{n:e,who:t}=this.remote;this.remote={n:0,who:new Set},this.last=Date.now(),this.ctx.E(`${e} new comment${1===e?"":"s"} from ${1===t.size?[...t][0]:`${t.size} people`}`)},e))}Ne(e){let t=this.K.get(e);return t||(t=qe("div",{class:"ov","aria-hidden":"true","data-addon":e}),this.ctx.t.insertBefore(t,this.after.nextSibling),this.K.set(e,t)),t}Ie(e,t){let n=this.ctx.host.ownerDocument.defaultView?.CSSStyleSheet,o=n&&"replaceSync"in n.prototype&&"adoptedStyleSheets"in this.shadow?new n:null;o&&(o.replaceSync(t),this.shadow.adoptedStyleSheets=[...this.shadow.adoptedStyleSheets,o]);let i=o??this.shadow.appendChild(qe("style",{},t));return this.$(e,()=>o?this.shadow.adoptedStyleSheets=this.shadow.adoptedStyleSheets.filter(e=>e!==o):i.remove())}fe(e,t,n){return t.add(n),this.$(e,()=>t.delete(n))}$e(e,t){return this.fe(e,this.X,t)}Re(e,t){let n=this.fe(e,this.I,t);return this.call(this.I,t,this.he()),n}he(){let{state:e}=this.ctx,t=this.shadow.activeElement;return{shown:!e.hidden,commentMode:e.l,allOpen:e.d,dark:this.ctx.t.classList.contains("dark"),view:this.ctx.p.view(),writing:t instanceof HTMLTextAreaElement?t.closest("[data-thread]")?.dataset.thread??"":null}}T(){for(let e of[...this.X])this.call(this.X,e);if(0===this.I.size)return;let e=this.he(),t=JSON.stringify(e);if(t!==this.ce){this.ce=t;for(let t of[...this.I])this.call(this.I,t,e)}}call(e,t,...n){try{t(...n)}catch(n){e.delete(t),globalThis.reportError?.(n)}}He(e,t,n){let o=this.ctx.t,i=this.shadow.activeElement,r=qe("button",{class:"ib",type:"button","aria-label":"Close"},Ye(["M6 6l12 12M18 6L6 18"],15)),a=qe("div",{class:"xp",role:"dialog","aria-label":n.label,"data-addon":e},qe("div",{class:"hd"},qe("span",{},n.label),r),qe("div",{class:"xb"},t)),l=[...o.children].filter(e=>e instanceof HTMLElement&&!e.inert);for(let e of l)e.inert=!0;o.append(a),a.offsetWidth,a.classList.add("show");let s=e=>{"Escape"===e.key&&(e.stopPropagation(),e.preventDefault(),d())},d=this.$(e,()=>{window.removeEventListener("keydown",s,!0);for(let e of l)e.inert=!1;a.classList.remove("show"),a.inert=!0,window.setTimeout(()=>a.remove(),300),i?.focus?.({preventScroll:!0});try{n.onClose?.()}catch(e){globalThis.reportError?.(e)}});return r.addEventListener("click",d),window.addEventListener("keydown",s,!0),(a.querySelector("button, input, textarea, select, a[href]")??a).focus?.({preventScroll:!0}),{close:d}}clear(e){for(let t of[...this.z.get(e)??[]])t();this.z.delete(e),this.K.get(e)?.remove(),this.K.delete(e);for(let t of[this.j,this.G,this.S])t.delete(e);for(let t of this.writing.get(e)??[])et.delete(t);this.writing.delete(e),this.repaint(),this.changed(!0)}destroy(){window.clearTimeout(this.timer),nt(null),this.U.clear()}},ct=new Map,ut=null,pt=(()=>{let e=globalThis.Pipeup;return e?.VERSION?e:null})();function ht(){return pt?pt.addons():[...ct.values()].map(e=>({...e.info}))}function ft(e){if(pt)return pt.use(e);let t=e=>console.warn(`pipeup: ${e}`),n=e;if(!n||"object"!=typeof n||"string"!=typeof n.id||!lt.test(n.id)||st.has(n.id)||"function"!=typeof n.setup||"string"!=typeof n.network?.says)return t("an add-on needs an id of 2 to 24 lowercase letters, digits and dashes (not a reserved one), a setup function and a network statement");if(ct.has(n.id))return t(`the add-on "${n.id}" is already registered; the second is ignored`);let o={id:n.id,version:String(n.version??""),network:n.network,state:"waiting"},i=(n.needs??[]).find(e=>!at.includes(e));1!==n.api?(o.state="off",o.reason=`needs add-on API ${String(n.api)}; this Pipeup has 1`):i&&(o.state="off",o.reason=`this Pipeup has no ${i} slot`);let r={addon:e,info:o};ct.set(n.id,r),ut?.i&&"waiting"===o.state&&mt(r,ut)}async function mt(e,t){let n,o,{addon:i,info:r}=e,a=new AbortController,l=new Set,{surface:s,doc:d}=t,c=()=>!a.signal.aborted,u=Object.assign(()=>{},{update(){},remove(){},close(){}}),p=e=>(...t)=>c()?e(...t):u,h={id:d.id,me:d.me,get name(){return d.name},threads:()=>d.threads(),ops:()=>d.ops(),onChange:e=>{let t=d.onChange(e);return l.add(t),()=>{t(),l.delete(t)}}},f=i.id,m={api:1,version:t.version,document:h,root:t.root,ephemeral:t.ephemeral,signal:a.signal,has:e=>at.includes(e),off:e=>{o=String(e)},merge:e=>c()?d.merge(e,f):Promise.resolve(0),addMenuItem:p(e=>s.Ae(f,e)),notify:p(e=>s.Le(f,e)),announce:p(e=>s.Pe(e)),setComposerNote:p(e=>s.pe(s.j,f,e)),setThreadNote:p((e,t)=>s.setThread(f,e,t)),addComposerTool:p(e=>s.Me(f,e)),openPanel:p((e,t)=>s.He(f,e,t)),addStyles:p(e=>s.Ie(f,e)),setStatus:p(e=>s.pe(s.G,f,e)),overlay:()=>s.Ne(f),onFrame:p(e=>s.$e(f,e)),where:e=>s.ctx.p.view(e),isHere:e=>s.ctx.p.u(e),go:e=>s.ctx.p.W(e),onUi:p(e=>s.Re(f,e)),avatar:(e,t)=>{let n=Xe(e,t);return n.classList.add("in"),n},sign:(e,t)=>d.sign(`${f}/${e}`,t)},v=()=>{if(c()){a.abort();for(let e of[...l])e();try{n?.()}catch(e){globalThis.reportError?.(e)}s.clear(f),"on"===r.state&&(r.state="waiting")}};e.stop=v;try{if(n=await i.setup(m),!c())return void n?.();if(void 0!==o)return v(),r.state="off",void(r.reason=o);r.state="on",delete r.reason}catch(e){r.state="failed",r.reason=function(e){return e instanceof Error?e.message:String(e)}(e),v(),r.state="failed",globalThis.reportError?.(e)}}var vt=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform)?"⇧⌥C":"Shift+Alt+C",gt="Shift+Alt+C";function wt(e,t){let n=function(e){let t=qe("button",{class:"me",type:"button",tabindex:"-1","aria-hidden":"true"});t.addEventListener("mousedown",e=>e.preventDefault());let n=it({label:"Comment",kind:"comment",before:t,V:e.V,_:e._}),o=qe("div",{class:"note"}),i=()=>{let e=tt?.note()??null;o.textContent=e??"",o.hidden=!e};i();let r=qe("div",{class:"say"}),a=qe("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"}),l=qe("div",{class:"nf"},a),s=qe("div",{class:"you"},r,l),d="",c=!1,u=()=>{let n=e.name(),o=n?"change":"add your name";if(t.title=n?"Change your name":"Add your name",!t.lastChild||d!==n){let o=Xe(e.me,n),i=t.lastChild;i?(Qe(o),Ze(i)):o.classList.add("in"),t.append(o),d=n}let i=qe("button",{type:"button"},o);i.addEventListener("click",h),r.replaceChildren(qe("span",{class:"nm"},n||`You're ${q(e.me)}`)," · ",i)},p=e=>{s.classList.toggle("naming",e),ze(r,e),ze(l,!e)};function h(t){t.stopPropagation(),a.value=e.name(),p(!0),a.focus({preventScroll:!0}),a.select()}let f=()=>{p(!1),n.focus()};t.addEventListener("click",h),a.addEventListener("keydown",t=>{if(t.stopPropagation(),"Escape"===t.key)t.preventDefault(),f();else if("Enter"===t.key){t.preventDefault();let n=a.value.trim();if(!n||n===e.name())return f();if(c)return;c=!0,e.rename(n).finally(()=>{c=!1,u(),f()})}}),u(),p(!1);let m=qe("div",{class:"ctx"},e.label),v=qe("div",{class:"draft"},m,o,n.element,s);return v.addEventListener(ot,i),{element:v,ge:()=>{let{selectionStart:e,selectionEnd:t}=n.input;return()=>{n.focus(),n.input.setSelectionRange(e,t)}},Q:e=>{m.hidden=e},ve:e=>{m.textContent=e},focus:()=>n.focus(),De:()=>""===n.input.value.trim()}}({label:t.label,me:e.doc.me,name:()=>e.c.name(),rename:t=>e.c.rename(t),V:t=>e.Be(t),_:()=>e.Fe()});return e.R(n),n}function yt(e,t){if("orphaned"===t.state||!t.element||e.quote)return null;let n=t.element.getBoundingClientRect();if(!n.width&&!n.height)return null;if(e.point)return{x:n.left+e.point.x*n.width,y:n.top+e.point.y*n.height};let o=t.element.ownerDocument.createRange();o.selectNodeContents(t.element);let i=o.getBoundingClientRect();return{x:i.width?Math.min(n.right-8,i.right+6):n.right-8,y:(i.height?i.top:n.top)+8}}function bt(e){return e.range?[...e.range.getClientRects()]:[]}function xt(e,t){let n=bt(t)[0];if(n)return n.top;if("orphaned"===t.state||!t.element)return null;let o=t.element.getBoundingClientRect();return e.point?o.top+e.point.y*o.height:o.top}function kt(e,t){let n=bt(t).at(-1);if(n)return{x:n.left,y:n.bottom,below:!0};let o=yt(e,t);return o?{...o,below:!1}:null}function Et(e,t,n){for(let o of n)if(e>=o.left&&e<=o.right&&t>=o.top&&t<=o.bottom)return!0;return!1}var St=()=>window.innerWidth>=900?400:300,Lt=()=>window.innerWidth<=480;function Mt(e,t,n){let o=e.top-t.height-10;return o<8&&(o=e.top+e.height+10),{left:Math.max(8,Math.min(e.left+e.width/2-t.width/2,n.width-t.width-8)),top:o}}function $t(e,t){let n=e.resolved.get(t.id);return n?.range?.startContainer??n?.element??null}var At=e=>(t,n)=>{let o=$t(e,t),i=$t(e,n),r=e=>e.anchor.point??{x:0,y:-1};return o!==i?!i||o&&4&o.compareDocumentPosition(i)?-1:1:r(t).y-r(n).y||r(t).x-r(n).x},Ct=e=>`${e} ${1===e?"reply":"replies"}`;function Tt(e,t,n){let o={...n},i=e.id,r=qe("div",{class:"rbox always"},qe("div",{},it({label:"Reply",kind:"reply",thread:()=>i,V:e=>t.reply(i,e),_:t.close}).element)),a=qe("div",{}),l=qe("span",{class:"note"},"This thread was resolved. Your words are kept until you send or clear them.");l.hidden=!0,r.prepend(l);let s=qe("div",{}),d=null,c=qe("div",{},s,qe("div",{class:"more"},a)),u=new Map,p=new Map,h=new Map,f=e=>{let t=Je(e.author,e.name),n=u.get(e.id),o=n?.e;if((!o||n.key!==t)&&(o=Qe(Xe(e.author,e.name)),n)){let t=n.e;h.set(e.id,t),Ze(t,()=>h.get(e.id)===t&&h.delete(e.id))}o.title=z(e),p.set(e.id,{key:t,e:o});let i=h.get(e.id);return i?[i,o]:[o]},m=(e,t,n)=>{let o=qe("button",{class:"ib",type:"button","aria-label":t,title:t},Ve(e));return o.addEventListener("click",e=>{e.stopPropagation(),n()}),o};function v(e,n={}){Object.assign(o,n),i=e.id;let h=(o.now??Date.now)(),v=e.root.replies.length,g=e=>qe("span",{class:"who"},`${z(e)} · ${Le(e.at,h)}`),w=e=>qe("div",{class:e.deleted?"tx del":"tx"},...e.deleted?["Deleted"]:[...We(e.text),e.edited?" (edited)":""]),y=e.resolved?"Resolved"+(v?` · ${Ct(v)}`:""):v?Ct(v):"",b=qe("div",{class:"column"===o.H?y?"ft has-rest":"ft":"ft open"},"column"===o.H&&y?qe("span",{class:"rest"},y):null,qe("span",{class:"hover"},g(e.root),qe("span",{class:"acts"},m("copy","Copy thread",()=>t.copy(e.id)),e.resolved?m("reopen","Reopen",()=>{t.reopen(e.id)}):m("resolve","Resolve",()=>{t.resolve(e.id)})))),x=o.lost?qe("div",{class:"ctx"},`${o.place||"No longer on the page"} — it read “${Re(o.lost,120)}”`):o.quote?qe("div",{class:"ctx"},`“${Re(o.quote,80)}”`):null;p=new Map;let k=qe("div",{class:"root"},...f(e.root),x,w(e.root),b);s.replaceWith(k),s=k,d?.remove();let E=et.get(e.id);d=v||void 0!==E?qe("div",{class:"rps"},...e.root.replies.map(e=>qe("div",{class:"it"},...f(e),w(e),qe("div",{class:"column"===o.H?"rft":"rft open"},g(e)))),void 0===E?null:qe("div",{class:"it ghost"},Xe("",O,!0),qe("div",{class:"tx"},E,qe("span",{class:"dots"},qe("i"),qe("i"),qe("i"))),qe("div",{class:"rft open"},qe("span",{class:"who"},`${O} · writing now`)))):null,d&&a.prepend(d),u=p;let S=""!==r.querySelector("textarea").value.trim();l.hidden=!(e.resolved&&S),e.resolved&&!S?r.remove():r.parentNode!==a&&a.append(r),c.className=e.resolved?"thread resolved":"thread",c.setAttribute("data-thread",e.id)}return v(e),{element:c,update:v}}function Pt(e,t){let n=new Map,o=qe("div",{class:"tip",role:"tooltip"}),i=qe("div",{class:"mark"}),r=qe("div",{class:"pop",role:"dialog","aria-label":"Comment thread"});o.inert=r.inert=!0,e.t.append(i,o,r);let a,l=qe("div",{class:"bub pin ghost","aria-hidden":"true"}),s=[],d=null,c=null,u=null,p=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,h=0,f=null,m=null,v=null,g=0,w=e=>s.find(t=>t.id===e)??null,y=()=>t.Z||e.state.d,b=!1,x=t=>{let n=e.resolved.get(t.id);return n?kt(t.anchor,n):null};function k(t,n,o){let{left:i,top:r}=function(e,t,n,o=12){let i,r;return e.below?(i=Math.min(e.x,n.width-t.width-o),r=e.y+8,r+t.height>n.height-o&&(r=e.y-t.height-40)):(i=e.x+14,i+t.width>n.width-o&&(i=e.x-t.width-28),r=Math.min(e.y-12,n.height-t.height-o)),{left:Math.max(o,i),top:Math.max(o,r)}}(n,{width:t.offsetWidth||o,height:t.offsetHeight},function(e){let t=window.innerWidth;return{width:e&&!Lt()?t-320:t,height:window.innerHeight}}(e.state.d));t.style.left=`${i}px`,t.style.top=`${r}px`}function E(t){let n=t&&y()&&e.state.i!==t?w(t):null,i=n?x(n):null;if(!n||!i)return v=null,o.classList.remove("show"),void ze(o,!0);if(v!==n.id){let e=n.root.replies.length;o.replaceChildren(qe("div",{class:"tx clamp"},...n.root.deleted?["Deleted"]:We(n.root.text)),qe("div",{class:"who"},`${z(n.root)}${e?` · ${e} ${1===e?"reply":"replies"}`:""}`)),v=n.id}k(o,i,260),o.classList.contains("show")||o.offsetWidth,o.classList.add("show"),o.inert=!1}function S(t){f=t,E(t),e.f(t)}function L(e){window.clearTimeout(g),null===e?g=window.setTimeout(()=>S(null),y()?400:0):S(e)}function M(t){let o=n.get(t.id);if(o)return o;let r=qe("button",{class:"bub",type:"button","data-thread":t.id});return r.addEventListener("mouseenter",()=>L(t.id)),r.addEventListener("mouseleave",()=>L(null)),r.addEventListener("click",n=>{n.stopPropagation(),E(null),e.open(t.id)}),e.t.insertBefore(r,i),n.set(t.id,r),r}o.addEventListener("mouseenter",()=>window.clearTimeout(g)),o.addEventListener("mouseleave",()=>L(null)),o.addEventListener("click",t=>{t.stopPropagation();let n=v;n&&(window.clearTimeout(g),S(null),e.open(n))});let $=!1;function A(){let t=e.state.o,n=u&&t&&!t.anchor.quote&&!t.anchor.point?t.resolved.element:null;if(n){let{left:e,top:t,above:o}=function(e,t,n,o=12,i=44){let r=e.top-i>=8,a=e.top+e.height+8+(r?0:i),l=e.top-8-(r?i:0)-t.height,s=a+t.height<=n.height-o||l<o,d=s?a:l;return{above:!s,left:Math.max(o,Math.min(e.left,n.width-t.width-o)),top:Math.max(o,d)}}(n.getBoundingClientRect(),{width:r.offsetWidth||St(),height:r.offsetHeight},{width:window.innerWidth,height:window.innerHeight}),i=null!==u?.above&&u?.above!==o;if(u&&(u.above=o),i&&T())return;return r.style.left=`${e}px`,void(r.style.top=`${t}px`)}let o=u&&t?kt(t.anchor,t.resolved):d?x(d):null;o&&k(r,o,St())}let C=t=>e.state.l&&!t.anchor.quote&&!t.anchor.point;function T(e=()=>{}){return window.clearTimeout(h),p?(r.classList.remove("show"),h=window.setTimeout(()=>{e(),A(),r.classList.add("show")},220),!0):(e(),r.classList.add("glide"),h=window.setTimeout(()=>r.classList.remove("glide"),450),!1)}let P=t=>{if(e.w(t)){let e=t.composedPath()[0];return null!==m&&!(e instanceof Element&&e.closest(".tip,.bub"))&&L(null),void(m=null)}let n=e.te(t.clientX,t.clientY)?.id??null;n!==m&&(m=n,L(n))},N=t=>{if(e.w(t))return;let n=window.getSelection();if(n&&!n.isCollapsed||(e.state.l?t.altKey:t.target instanceof Element&&t.target.closest("a,button,input,select,textarea,label,summary,[role=button],[contenteditable]")))return;let o=e.te(t.clientX,t.clientY);o&&(e.ye(t),E(null),e.open(o.id))};return window.addEventListener("pointermove",P,{capture:!0,passive:!0}),window.addEventListener("click",N,!0),{m:function(o){s=o;let l=new Set;for(let t of o){if(!e.D(t)||t.anchor.quote)continue;let n=e.resolved.get(t.id);if(!n||"orphaned"===n.state)continue;l.add(t.id);let o=M(t);o.classList.toggle("done",t.resolved),o.classList.toggle("on",e.state.i===t.id),o.classList.toggle("pin",void 0!==t.anchor.point);let i=`Comment on ${be(n.element)}: ${Re(t.root.text,60)}`;o.getAttribute("aria-label")!==i&&o.setAttribute("aria-label",i)}Oe(e.t,o.filter(e=>l.has(e.id)).sort(At(e)).map(e=>n.get(e.id)),i);for(let[e,t]of n)l.has(e)||(t.classList.remove("in"),n.delete(e),window.setTimeout(()=>t.remove(),300));E(f),b!==e.state.d&&r.classList.contains("show")&&!p&&T(),b=e.state.d;let m=t.Z?e.state.o:null;if(m){let t=m.anchor.point??m.resolved.element;u?.of!==m?(window.clearTimeout(h),r.classList.remove("glide"),u={s:wt(e,m),of:m,at:t,above:null},u.s.Q(C(m)),r.replaceChildren(u.s.element),r.inert=!1,u.s.focus(),d=null,c=null,A(),r.classList.add("show")):u&&(u.at!==t&&(u.at=t,u.above=null,T(()=>u?.s.ve(m.label))),u.s.Q(C(m)));let n=!e.p.u(m.anchor.view);return void(n!==$&&($=n,r.classList.toggle("show",!n),r.inert=n,n||A()))}u&&(window.clearTimeout(h),r.classList.remove("glide"),u=null,$=!1,e.R(null));let v=y()&&e.state.i?w(e.state.i):null;if(!v||!e.D(v))return d=null,c=null,r.classList.remove("show"),void ze(r,!0);let g=v.anchor.quote?.exact??null;d&&c&&d.id===v.id?(d!==v||a!==et.get(v.id))&&(c.update(v,{quote:g}),d=v,a=et.get(v.id)):(c=Tt(v,e.ee,{H:"popover",quote:g}),r.replaceChildren(c.element),d=v,a=et.get(v.id),A(),r.classList.add("show"),r.inert=!1)},T:function(){for(let[t,o]of n){let n=w(t),i=e.resolved.get(t),r=n&&i?yt(n.anchor,i):null;!r||r.y<-40||r.y>window.innerHeight+40?o.style.visibility="hidden":(o.style.visibility="",o.style.left=`${r.x}px`,o.style.top=`${r.y}px`,o.classList.contains("in")||(o.offsetWidth,o.classList.add("in")))}let t=e.state.o,o=t?.anchor.point&&e.p.u(t.anchor.view)?yt(t.anchor,t.resolved):null;o?(l.style.left=`${o.x}px`,l.style.top=`${o.y}px`,l.classList.contains("in")||(e.t.insertBefore(l,i),l.offsetWidth,l.classList.add("in"))):l.classList.contains("in")&&(l.classList.remove("in"),window.setTimeout(()=>l.classList.contains("in")||l.remove(),300)),r.classList.contains("show")&&A();let a=function(){if(!y())return null;let t=e.state.o;return t?t.anchor.quote||t.anchor.point||e.state.l?null:t.resolved.element:!d||d.anchor.quote||d.anchor.point?null:e.resolved.get(d.id)?.element??null}();i.classList.toggle("show",null!==a),a&&Fe(i,a.getBoundingClientRect(),4)},destroy(){window.clearTimeout(g),window.clearTimeout(h),window.removeEventListener("pointermove",P,!0),window.removeEventListener("click",N,!0),e.R(null);for(let e of n.values())e.remove();l.remove(),o.remove(),i.remove(),r.remove()}}}var Nt={display:"block",position:"static",clips:!1,off:!1},qt=["button,a,input,select,textarea,label,summary,details,img,svg,canvas,video,picture,figure,figcaption,table,th,td","li,ul,ol,dl,dt,dd,p,h1,h2,h3,h4,h5,h6,blockquote,pre","section,article,aside,nav,header,footer,main,form,fieldset",..."button link img figure region list listitem tab tabpanel article navigation complementary banner contentinfo form search group dialog menu menuitem checkbox switch radio slider textbox combobox option row cell heading table".split(" ").map(e=>`[role=${e}]`)].join(","),zt="a,button,label,summary,[role=button],[role=link],[role=tab],[role=option],[role=menuitem]",Ot=`${zt},input,select,textarea,img,svg,canvas,video,picture,[role=img]`,Dt=(e,t)=>Math.abs(e.left-t.left)<=2&&Math.abs(e.top-t.top)<=2&&Math.abs(e.width-t.width)<=2&&Math.abs(e.height-t.height)<=2;function Rt(e,t){let n=t.s(e);if(n.width<2||n.height<2)return!1;if(e.hasAttribute("data-pipeup-id"))return!0;let o=t.ne();return n.width*n.height<=.6*o.width*o.height&&(e.matches(qt)||t.Ve(e)||e.childElementCount>1&&!e.parentElement?.closest(zt)&&t._e(e))}function Ft(e,t,n){if(e===t||!t.contains(e)||e.closest("[data-pipeup-ignore]"))return null;let o=null;for(let i=e;i&&i!==t&&!o;i=i.parentElement)Rt(i,n)&&(o=i);if(!o||o.hasAttribute("data-pipeup-id"))return o;let i=n.s(o);for(let e=o.parentElement;e&&e!==t&&Dt(n.s(e),i);e=e.parentElement)if(e.hasAttribute("data-pipeup-id"))return e;return o}function Ht(e,t,n){let o=n.s(e);for(let i=e.parentElement;i&&i!==t;){let e=Ft(i,t,n);if(!e)return null;if(!Dt(n.s(e),o))return e;i=e.parentElement}return null}var It=(e,t)=>e.left<t.left+t.width&&t.left<e.left+e.width&&e.top<t.top+t.height&&t.top<e.top+e.height,Bt=(e,t)=>{let n=Math.max(e.left,t.left),o=Math.max(e.top,t.top);return{left:n,top:o,width:Math.max(0,Math.min(e.left+e.width,t.left+t.width)-n),height:Math.max(0,Math.min(e.top+e.height,t.top+t.height)-o)}};function Wt(e,t,n=()=>!0){let o=[],i=(e,r,a,l,s,d)=>{for(let c of e.children){if(c.hasAttribute("data-pipeup-ignore")||"true"===c.getAttribute("aria-hidden")||!n(c))continue;let e=t.flow?.(c)??Nt,u=c.offsetParent,p="fixed"===e.position||"absolute"===e.position&&!!l&&!(u&&l.contains(u)),h=p?null:a,f=t.s(c),m=f.width>0&&f.height>0;if(h&&m&&!It(f,h))continue;let v=c.matches(zt),g=(e.display.startsWith("inline")||d)&&!c.matches(Ot)&&("inline"===e.display||f.height<=48),w=f.width<=24&&f.height<=24,y=r;(c.hasAttribute("data-pipeup-id")||!s&&!e.off&&!g&&(!w||v))&&Rt(c,t)&&(r&&Dt(t.s(r.e),f)?(c.hasAttribute("data-pipeup-id")||!r.e.hasAttribute("data-pipeup-id"))&&(r.e=c):o.push(y={e:c,O:r,k:0}));let b=e.clips&&m;i(c,y,b?h?Bt(h,f):f:h,b?c:p?null:l,s||v,/^inline-(flex|grid)$/.test(e.display)||d&&/(flex|grid)$/.test(e.display))}};i(e,null,null,null,!1,!1);for(let e=o.length-1;e>=0;e--){let t=o[e];t.O&&(t.O.k=Math.max(t.O.k,t.k+1))}return o}var jt=(e,t)=>e.filter(e=>e.k<=t&&(!e.O||e.O.k>t)),Kt="a,button,summary,[role=button],[role=link],[role=switch],[role=tab],[role=checkbox],input[type=checkbox],input[type=radio],input[type=submit],input[type=button],input[type=reset]",Vt=`${Kt},input,select,textarea,[contenteditable]:not([contenteditable=false]),[tabindex]:not([tabindex="-1"])`,Yt=["click","dblclick","auxclick","submit","contextmenu","dragstart"],Ut=[...["over","out","enter","leave","down","up"].flatMap(e=>[`pointer${e}`,`mouse${e}`]),"mousemove","touchstart","touchmove","touchend","touchcancel"],_t="Tab moves between blocks · ↑ ↓ change level · Enter comments · Esc to finish · F7 selects text";function Gt(e){let t={s:e=>e.getBoundingClientRect(),Ve:e=>{let t=getComputedStyle(e),n="transparent"!==t.backgroundColor&&!/,\s*0\)$/.test(t.backgroundColor),o=["top","right","bottom","left"].some(e=>parseFloat(t.getPropertyValue(`border-${e}-width`))>0);return n||o||"none"!==t.backgroundImage||"none"!==t.boxShadow},_e:e=>/^(inline-)?(flex|grid)$/.test(getComputedStyle(e).display),flow:e=>{let t=getComputedStyle(e),n=[t.overflowX,t.overflowY];return{display:t.display,position:t.position,clips:n.some(e=>"hidden"===e||"clip"===e)&&!n.some(e=>"auto"===e||"scroll"===e)&&e!==document.documentElement&&e!==document.body,off:"none"===t.pointerEvents}},ne:()=>({width:innerWidth,height:innerHeight})},n=qe("span",{hidden:!0},_t),o=qe("div",{class:"pick"},n),i=[0,1].map(()=>{let e=qe("div",{class:"km",tabindex:"-1",role:"button"},qe("span",{hidden:!0}),qe("span",{hidden:!0}));return e.inert=!0,e.addEventListener("keydown",pe),e.addEventListener("click",e=>{e.stopPropagation(),ue()}),e.addEventListener("focus",()=>o.classList.add("kf")),e.addEventListener("blur",()=>o.classList.remove("kf")),e}),r=qe("span",{class:"lbl"}),a=(e,t,n,o)=>{let i=qe("button",{class:"nb",type:"button","aria-label":e,title:t},Ve(n,16));return i.addEventListener("click",e=>{e.stopPropagation(),o()}),i},l=a("Around it","Select the block around it","expand",se),s=a("Inside it","Select a block inside it","shrink",ce),d=a("Pin","Pin its centre","pin",()=>e.we(()=>W(f??x,{x:.5,y:.5}))),c=qe("div",{class:"namebar",role:"group","aria-label":"Chosen block"},r,l,s,d);c.inert=!0;let u=e.t.querySelector(".launch");for(let t of[o,...i,c])e.t.insertBefore(t,u);c.addEventListener("mousedown",e=>e.preventDefault());let p=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,h=null,f=null,m=null,v=null,g=0,w=()=>{},y=null,b=()=>{},x=null,k=0,E=0,S=!1,L=null,M=null,$=null,A=0,C=-1,T=!0,P=null,N=null,q=t=>!(e.w(t)||t.target instanceof Element&&t.target.closest("[data-pipeup-ignore]"));function z(){v&&(o.classList.toggle("glide",performance.now()<g),Fe(o,v.getBoundingClientRect(),4))}function O(){if(!y)return;c.classList.toggle("glide",performance.now()<g&&c.classList.contains("show"));let{left:e,top:t}=Mt(y.getBoundingClientRect(),{width:c.offsetWidth||200,height:c.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});c.style.left=`${e}px`,c.style.top=`${t}px`}function D(e,t){v=e,g=t?performance.now()+400:0,z(),o.classList.add("show")}function R(e,t){let n=getComputedStyle(e);if("0"===n.opacity)return t(),()=>{};let o=0,i=()=>{window.clearTimeout(o),e.removeEventListener("transitionend",a)},r=()=>{i(),t()},a=t=>{t.target===e&&"opacity"===t.propertyName&&r()},l=Math.max(...n.transitionDuration.split(",").map(e=>1e3*parseFloat(e)||0));return o=window.setTimeout(r,l+100),e.addEventListener("transitionend",a),i}function F(e){if(e!==h){if(h=e,w(),!e)return void o.classList.remove("show");"0"===getComputedStyle(o).opacity?D(e,!1):p?(o.classList.remove("show"),w=R(o,()=>D(e,!1))):D(e,!0)}}function H(e){f=e,o.classList.toggle("on",null!==e),F(e),I(e)}function I(e){b(),c.inert=!e,e?p?(c.classList.remove("show"),b=R(c,()=>B(e))):B(e):(c.classList.remove("show"),y=null)}function B(n){r.textContent=r.title=be(n),l.hidden=null===Ht(n,e.root,t),s.hidden=0===(x?ae(n).length:Wt(n,t,Z).length);let o=c.classList.contains("show");y=n,O(),o||(c.offsetWidth,c.classList.add("show"))}function W(t,n){let o;try{o=de(t,e.root,n,e.p.view(t))}catch(t){return void e.oe(t)}let i={anchor:o,label:n?`Pin on ${be(t).replace(/^[A-Z](?=[a-z])/,e=>e.toLowerCase())}`:be(t),ranges:[],resolved:{state:"attached",element:t,range:null}},r=e.state.o;x&&(x=t,C=-1),H(n?null:t),m=r??i,e.qe(i),e.E(n?i.label:`Commenting on ${i.label}`)}function j(t){e.we(()=>W(t))}let K=n=>{if(e.w(n))return;if(!q(n))return void(f||F(null));if(n.stopPropagation(),f||e.state.o)return;let o=!De()&&n.target instanceof Element?Ft(n.target,e.root,t):null;if(x){if(!o||o===x||(A+=Math.abs(n.movementX)+Math.abs(n.movementY),A<=4))return;re()}o&&(L=o),F(o)},V=()=>{De()&&(x&&re(),f||F(null))},Y=e=>{q(e)&&(e.stopPropagation(),("pointerdown"===e.type||"mousedown"===e.type)&&e.target instanceof Element&&e.target.closest(Vt)&&e.preventDefault())},U=n=>{if(!q(n))return;let o=n.target;!(o===N||o.form&&o.form===N?.form)||"submit"!==n.type&&("click"!==n.type||n.detail)?(n.preventDefault(),n.stopPropagation(),"click"===n.type&&!e.state.c&&!e.Ue(n)&&function(n){let o=window.getSelection();if(o&&!o.isCollapsed)return;if(e.state.o&&(n.altKey||!e.L()))return void e.B();if(!n.altKey&&e.te(n.clientX,n.clientY))return;if(e.state.i&&e.open(null),x&&n.detail&&re(),n.altKey)return void function(n){let o=(n.target instanceof Element?Ft(n.target,e.root,t):null)??e.root;o!==e.root&&(L=o);let i=o.getBoundingClientRect();i.width&&i.height&&W(o,{x:(n.clientX-i.left)/i.width,y:(n.clientY-i.top)/i.height})}(n);let i=n.target instanceof Element?Ft(n.target,e.root,t):null;i&&(L=i),i?W(i):(e.B(),H(null))}(n)):N="click"===n.type&&"submit"===o.type?o.form:null},_=t=>{if(N=null,fe="","Tab"===t.key&&G(t))return t.preventDefault(),t.stopPropagation(),fe=t.key,e.B(),e.state.i&&e.open(null),e.state.c&&(e.state.c=!1,e.m()),function(t){if(x)return le(t);P=null;let n=document.activeElement;M=J()??n;let o,i=L?.isConnected?L:null,r=i&&ee(i);if(r){k=r.k;let e=jt(Q(),k),n=e.indexOf(r);o=e[(n+t+e.length)%e.length]}else if(i){k=0;let e=jt(Q(),0),n=e=>0!==(i.compareDocumentPosition(e.e)&Node.DOCUMENT_POSITION_FOLLOWING),r=e=>e.e.contains(i);o=t>0?e.find(e=>n(e)&&!r(e))??e[0]:e.filter(e=>!n(e)&&!r(e)).pop()??e[e.length-1]}else o=ne(),o&&(k=o.k);if(!o)return e.E("Nothing here to comment on");S=!0,ie(o.e)}(t.shiftKey?-1:1);if(q(t)&&t.target instanceof Element)if("Enter"!==t.key&&" "!==t.key||!t.target.closest(Kt))"Enter"===t.key&&!x&&t.target.form&&(N=t.target);else{if(!x)return void(N=t.target);t.preventDefault(),t.stopPropagation()}},G=t=>{if(t.ctrlKey||t.metaKey||t.altKey||t.isComposing)return!1;let n=t.composedPath()[0];return n instanceof Element&&!i.some(e=>e===n)&&(e.w(t)?!!n.closest(".launch,.menu")&&!n.closest("input,textarea,select,[contenteditable]"):!t.composedPath().some(e=>e instanceof Element&&e.hasAttribute("data-pipeup-ignore")))},J=()=>e.t.getRootNode().activeElement,X=()=>i.some(e=>e===J()),Z=t=>(!1!==t.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0})||"contents"===getComputedStyle(t).display)&&e.p.u(e.p.view(t)),Q=()=>(P?.some(e=>!e.e.isConnected)&&(P=null),P??=Wt(e.root,t,Z)),ee=e=>Q().find(t=>t.e===e),te=(e,t=!1)=>{let n=e.getBoundingClientRect();return n.bottom>0&&n.top<window.innerHeight&&(!t||n.top>=0)},ne=()=>{let e=jt(Q(),0);return e.find(e=>te(e.e,!0))??e.find(e=>te(e.e))??e[0]},oe=t=>e.doc.threads().filter(n=>e.D(n)&&t.contains($t(e,n))).sort(At(e));function ie(t,o=!0){A=0;let r=Q(),a=r.find(e=>e.e===t);if(a&&!jt(r,k).includes(a)&&(k=a.k),t!==x&&(C=-1),t!==f&&(f=null),x=t,F(t),I(t),t.scrollIntoView({block:"nearest",inline:"nearest",behavior:p?"auto":"smooth"}),!o)return;e.Ke();let l=i[E^=1];(function(e,t){let[o,i]=e.children,r=jt(Q(),k),a=oe(t).length;o.textContent=`${we(t)}, ${r.findIndex(e=>e.e===t)+1} of ${r.length}${a?`, has ${a} comment${1===a?"":"s"}`:""}`;let l=(t.innerText??t.textContent??"").length<=150;i.textContent=ye(t);let s=T?[n]:[];T=!1,void 0!==e.ariaLabelledByElements?(e.ariaLabelledByElements=l?[o,t]:[o,i],e.ariaDescribedByElements=l?s:[...s,t]):e.setAttribute("aria-label",`${o.textContent}, ${i.textContent}`)})(l,t),Fe(l,t.getBoundingClientRect(),4),l.inert=!1,l.focus({preventScroll:!0}),i[1^E].inert=!0}function re(){let e=X();L=x,x=null,F(null),I(null);for(let e of i)ze(e,!0);return e}function ae(e){let t=ee(e);return t?((e,t)=>e.filter(e=>e.O===t))(Q(),t):[]}function le(e){let t=jt(Q(),k),n=t.findIndex(e=>e.e===x),o=t[n<0?e>0?0:t.length-1:(n+e+t.length)%t.length];o&&ie(o.e)}function se(){let n=f??x,o=n&&Ht(n,e.root,t);return o?((!$||!n.contains($))&&($=n),f?j(o):void ie(o)):e.E("Nothing around it")}function ce(){let t=f??x,n=t?ae(t):[],o=n.find(e=>$&&e.e.contains($))??n.find(e=>te(e.e))??n[0];if(!o)return e.E("Nothing inside it");f?j(o.e):ie(o.e)}function ue(t=!1){if(!x)return;if(e.state.o&&!e.L())return e.ze();if(!t)return W(x);let n=oe(x);if(!n.length)return e.E("No comments on this block");C=(C+1)%n.length,e.open(n[C].id),n.length>1&&e.E(`Comment ${C+1} of ${n.length} on this block`)}function pe(t){if(["Tab","ArrowUp","ArrowDown","Enter"," ","Escape"].includes(t.key)&&(!t.key.startsWith("Arrow")||!(t.metaKey||t.ctrlKey||t.altKey))){if(t.preventDefault(),t.stopPropagation(),fe=t.key,"Escape"===t.key)return void e.re();if("Enter"===t.key||" "===t.key)return ue(t.shiftKey&&"Enter"===t.key);"Tab"===t.key&&e.B(),e.state.i&&e.open(null),"Tab"===t.key?le(t.shiftKey?-1:1):"ArrowUp"===t.key?se():ce()}}let he=()=>{let e=J();return e?!!e.closest("[inert]"):!document.activeElement||document.activeElement===document.body},fe="",me=!1,ve=e=>{me&&window.removeEventListener("keyup",ve,!0),e.key===fe&&(fe="",e.preventDefault(),e.stopPropagation())};window.addEventListener("keyup",ve,!0),window.addEventListener("pointermove",K,!0),document.addEventListener("selectionchange",V);for(let e of Ut)window.addEventListener(e,Y,!0);for(let e of Yt)window.addEventListener(e,U,!0);return window.addEventListener("keydown",_,!0),{re:()=>!!f&&(H(null),!0),ie:()=>null!==x,We:()=>S&&!x,be:function(){P=null;let t=document.activeElement;M=J()??t;let n=ee(L),o=n??(t&&t!==document.body&&e.root.contains(t)&&!t.closest("[data-pipeup-ignore]")?Q().filter(e=>e.e.contains(t)).pop():void 0)??ne();return!!o&&(n||(k=o.k),S=!0,ie(o.e),!0)},se(){x&&!X()&&ie(x)},m(){if(P=null,x&&(!x.isConnected||!Z(x))){let e=ne();e?ie(e.e,X()||he()):re()}let t=e.t.querySelector(".launch");if(t&&c.nextElementSibling!==t&&!X()&&!c.contains(J()))for(let n of[o,...i,c])e.t.insertBefore(n,t);let n=e.state.o;m&&n!==m?(m=null,H(null),x&&ie(x,he())):(n||e.state.i)&&!m&&(h||f)&&H(null)},T(){z(),O(),x&&Fe(i[E],x.getBoundingClientRect(),4)},destroy(){re()&&function(){let t=M;t&&t!==document.body&&t.isConnected&&t.focus?.({preventScroll:!0}),(!t||t===document.body||!t.matches?.(":focus"))&&e.t.querySelector(".launch .mode")?.focus({preventScroll:!0})}();for(let e of i)e.remove();w(),b(),me=!0,fe||window.removeEventListener("keyup",ve,!0),window.removeEventListener("pointermove",K,!0),document.removeEventListener("selectionchange",V);for(let e of Ut)window.removeEventListener(e,Y,!0);for(let e of Yt)window.removeEventListener(e,U,!0);window.removeEventListener("keydown",_,!0),o.classList.remove("show"),c.classList.remove("show"),ze(c,!0),R(o,()=>o.remove()),R(c,()=>c.remove())}}}function Jt(e,t=!1){let n=e.ownerDocument.documentElement,o=n.getAttribute("data-pipeup-layout");if("bubbles"===o||e.querySelector("[data-pipeup-slide]"))return null;let i=e.querySelector("article, main, [role=main]")??("column"===o?e:null);if(!i)return null;if(n.hasAttribute("data-pipeup-reserve")){let e,r=n.clientWidth,a=getComputedStyle(i).maxWidth;return e=a.endsWith("px")?parseFloat(a):a.endsWith("%")?parseFloat(a)/100*r:i.getBoundingClientRect().width,"column"!==o&&r<e+320-(t?24:0)?null:{x:r-320+24,width:272}}let r=i.getBoundingClientRect().right;if(window.innerWidth-r<300&&"column"!==o)return null;let a=r+32;return{x:a,width:Math.max(220,Math.min(300,window.innerWidth-a-16))}}function Xt(e,t){let n=e.resolved.get(t.id);return!n||"orphaned"===n.state&&!e.S.has(t.id)}function Zt(e){let t=qe("div",{class:"col"});e.t.append(t);let n=new Map,o=null,i=new ResizeObserver(()=>l()),r=t=>Xt(e,t);function a(t){let n=e.resolved.get(t.id),o=n?xt(t.anchor,n):null;return null===o?Number.POSITIVE_INFINITY:o+window.scrollY-4}function l(){let t=[],i=[];for(let[o,r]of n){let n=a(r.thread);if(Number.isFinite(n))r.placed=n;else if(e.S.has(o)){if(null===r.placed){r.e.classList.add("wait");continue}n=r.placed}Number.isFinite(n)?t.push({id:o,M:n,height:r.e.offsetHeight}):i.push({id:o,height:r.e.offsetHeight})}let r=e.state.o,l=r?xt(r.anchor,r.resolved):null;o&&null!==l&&t.push({id:"draft",M:l+window.scrollY-4,height:o.e.offsetHeight});let s=function(e,t,n=10){let o=[...e].sort((e,t)=>e.M-t.M),i=new Array(o.length).fill(0),r=o.findIndex(e=>e.id===t),a=e=>o[e];if(r<0)o.forEach((e,t)=>{i[t]=0===t?e.M:Math.max(e.M,(i[t-1]??0)+a(t-1).height+n)});else{i[r]=a(r).M;for(let e=r+1;e<o.length;e++)i[e]=Math.max(a(e).M,(i[e-1]??0)+a(e-1).height+n);for(let e=r-1;e>=0;e--)i[e]=Math.min(a(e).M,(i[e+1]??0)-a(e).height-n)}return new Map(o.map((e,t)=>[e.id,i[t]??0]))}(t,o?"draft":e.state.i),d=Math.max(0,...t.map(e=>(s.get(e.id)??0)+e.height))+24;for(let e of i)s.set(e.id,d),d+=e.height+10;for(let[e,t]of n)if(t.e.classList.contains("wait")){if(!s.has(e))continue;t.e.style.transition="none",t.e.style.transform=`translateY(${Math.round(s.get(e))}px)`,t.e.offsetWidth,t.e.style.transition="",t.e.classList.remove("wait")}else t.e.style.transform=`translateY(${Math.round(s.get(e)??0)}px)`;o&&(o.e.style.transform=`translateY(${Math.round(s.get("draft")??0)}px)`)}function s(e,t){e.thread=t,e.note=et.get(t.id),e.lost=r(t),e.view.update(t,{lost:e.lost?t.anchor.snapshot:null})}function d(n){let o=r(n),a=Tt(n,e.ee,{H:"column",lost:o?n.anchor.snapshot:null}),l=qe("div",{class:"th","data-thread":n.id},qe("button",{class:"opn sr",type:"button","data-thread":n.id}),a.element);return l.style.transition="none",l.addEventListener("mouseenter",()=>e.f(n.id)),l.addEventListener("mouseleave",()=>e.f(null)),l.addEventListener("click",()=>e.open(n.id)),t.append(l),i.observe(l),{e:l,thread:n,lost:o,placed:null,view:a}}function c(e){i.unobserve(e),e.classList.add("out"),window.setTimeout(()=>e.remove(),220)}return{m:function(a){ze(t,e.state.d);let u=new Set,p=[],h=null!==e.state.i||null!==e.state.o;for(let t of a){if(!e.D(t))continue;u.add(t.id);let o=n.get(t.id);o?(o.thread!==t||o.lost!==r(t)||o.note!==et.get(t.id))&&s(o,t):(o=d(t),n.set(t.id,o),p.push(o.e));let i=o.e,a=e.state.i===t.id;i.classList.toggle("on",a);let l=i.firstElementChild,c=t.root.replies.length;l.setAttribute("aria-label",`Open thread: ${Re(t.root.text,60)}, ${Ct(c)}`),l.setAttribute("aria-expanded",String(a)),ze(l,a);let f=i.querySelector(".more");f&&ze(f,!a),i.classList.toggle("dim",h&&!a),i.classList.toggle("hot",e.state.f===t.id&&!a),i.classList.toggle("resolved",t.resolved),i.classList.toggle("lost",o.lost)}for(let[e,t]of n)u.has(e)||(n.delete(e),c(t.e));(function(){let n=e.state.o;if(o&&o.of!==n&&(c(o.e),o=null,n||e.R(null)),!n)return;let r=!o;if(o)o.s.ve(n.label);else{let r=wt(e,n),a=qe("div",{class:"th on"},r.element);a.style.transition="none",t.append(a),i.observe(a),o={e:a,s:r,of:n}}o.s.Q(e.state.l&&!n.anchor.quote&&!n.anchor.point),r&&o.s.focus()})(),Oe(t,a.filter(e=>u.has(e.id)).sort(At(e)).map(e=>n.get(e.id).e),o?.e??null)&&t.offsetWidth,l(),o&&p.push(o.e);for(let e of p)e.offsetWidth,e.style.transition=""},T:function(){let n=Jt(e.root,!0);n&&(t.style.width=`${n.width}px`,t.style.transform=`translate(${n.x}px, ${-window.scrollY}px)`)},destroy(){i.disconnect(),e.R(null),t.remove()}}}var Qt="[data-pipeup-ignore],input,textarea,select,[contenteditable]:not([contenteditable=false])";function en(e){let t=qe("button",{type:"button","aria-label":"Comment",title:"Comment"},Ve("comment",17)),n=qe("div",{class:"selbar"},t);n.inert=!0,e.t.append(n);let o=null,i=0,r=!1,a=t=>{let n=t&&(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement);return!!n&&e.root.contains(n)&&!n.closest(Qt)};function l(){if(!o)return;let{left:e,top:t}=Mt(o.getBoundingClientRect(),{width:n.offsetWidth||36,height:n.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});n.style.left=`${e}px`,n.style.top=`${t}px`}function s(){o=null,n.inert=!0,n.classList.remove("show")}function d(t=!1){let i=De();e.state.l&&i&&a(i.anchorNode)&&a(i.focusNode)?(!o&&!t&&e.E("Enter comments on the selected words"),o=i.getRangeAt(0).cloneRange(),l(),n.inert=!1,n.classList.add("show")):s()}t.addEventListener("mousedown",e=>e.preventDefault()),t.addEventListener("click",t=>{if(t.stopPropagation(),e.state.o&&!e.L())return e.B();let n,i=o;if(!i)return;try{n=se(i,e.root,e.p.view(i.commonAncestorContainer))}catch(t){return e.oe(t),void s()}let r=Re(i.toString().replace(/\s+/g," ").trim(),60);window.getSelection()?.removeAllRanges(),s(),e.Ye({anchor:n,label:`“${r}”`,ranges:[i],resolved:{state:"attached",element:null,range:i}})});let c=()=>{window.clearTimeout(i),i=window.setTimeout(()=>r||d(),250),o&&(De()||s())};document.addEventListener("selectionchange",c);let u=t=>{"keyup"!==t.type&&(r="mousedown"===t.type),!r&&!e.w(t)&&window.setTimeout(()=>d("mouseup"===t.type),0)};window.addEventListener("mousedown",u,!0),window.addEventListener("mouseup",u,!0),window.addEventListener("keyup",u,!0);let p=n=>{"Enter"!==n.key||!o||e.w(n)||n.target instanceof Element&&n.target.closest(`${Qt},${Kt}`)||(n.preventDefault(),n.stopPropagation(),t.click())};return window.addEventListener("keydown",p,!0),{m(){!e.state.l&&o&&s()},T(){o&&l()},destroy(){window.removeEventListener("mousedown",u,!0),window.removeEventListener("mouseup",u,!0),window.removeEventListener("keyup",u,!0),window.removeEventListener("keydown",p,!0),window.clearTimeout(i),document.removeEventListener("selectionchange",c),n.remove()}}}async function tn(e,t){try{return void await navigator.clipboard.writeText(e)}catch{}let n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.cssText="position:fixed;opacity:0;pointer-events:none",t.append(n),n.select();let o=document.execCommand("copy");if(n.remove(),!o)throw new Error("pipeup: your browser blocked copying")}var nn="Hidden on the page";function on(e){let t=[qe("span",{class:"n"}),qe("span",{class:"n"})],n=Ve("comment",20,1.4);n.lastElementChild.setAttribute("stroke-width","1.6");let o=qe("button",{class:"mode",type:"button","aria-label":"Comment","aria-keyshortcuts":gt,"aria-haspopup":"menu","aria-expanded":"false"},qe("span",{class:"plus"},n),qe("span",{class:"cnt"},Ve("bubble",34,1.4),...t),qe("span",{class:"dot"})),i=document.createTextNode("Comment"),r=qe("span",{class:"ttip","aria-hidden":"true"},i,qe("small",{},vt)),a=qe("div",{class:"launch"},o,r),l=qe("div",{class:"menu",role:"menu","aria-label":"Comments"}),s=qe("div",{class:"list",role:"menu","aria-label":"All comments"}),d=qe("span",{class:"pn"}),c=qe("button",{class:"ib",type:"button","aria-label":"Close"},Ve("close")),u=qe("button",{class:"hs",type:"button",role:"switch","aria-checked":"false"},"Show resolved",qe("span",{class:"sw","aria-hidden":"true"}));u.addEventListener("click",t=>{t.stopPropagation(),e.c.je()});let p=qe("div",{class:"all",role:"dialog","aria-label":"All comments"},qe("div",{class:"hd"},qe("span",{},"All comments"),d,u,c),s),h=document.createElementNS("http://www.w3.org/2000/svg","svg");h.setAttribute("class","cx"),h.setAttribute("aria-hidden","true");let f=document.createElementNS("http://www.w3.org/2000/svg","path"),m=document.createElementNS("http://www.w3.org/2000/svg","circle");m.setAttribute("r","4"),h.append(f,m),l.inert=p.inert=!0,e.t.append(l,a,h,p);let v=!1,g=null,w=0,y=[],b=0,x=null,k=null,E=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,S=t=>{v=e.state.c=t,t&&e.addons.flush(),window.clearTimeout(w),w=0,t||g?.(!0),l.classList.toggle("show",t),ze(l,!t),o.setAttribute("aria-expanded",String(t))},L=(t,n=!1)=>{e.state.d!==t&&(e.state.d=t,e.m(),t?(M(s)[0]??c).focus({preventScroll:!0}):n&&o.focus({preventScroll:!0}))},M=(e=l)=>[...e.querySelectorAll(".mi")],$=()=>l.getRootNode().activeElement,A=()=>{S(!1),o.focus({preventScroll:!0})},C=e=>{let t=M(e.currentTarget);if(0===t.length)return;let n=$(),o=t.indexOf(n),i=n=>{e.preventDefault(),t[(n+t.length)%t.length]?.focus({preventScroll:!0})};"ArrowDown"===e.key?i(o+1):"ArrowUp"===e.key?i(o<0?t.length-1:o-1):"Home"===e.key?i(0):"End"===e.key&&i(t.length-1)};l.addEventListener("keydown",C),s.addEventListener("keydown",C),c.addEventListener("click",e=>{e.stopPropagation(),L(!1,!0)});let T=t=>Xt(e,t),P=t=>y.filter(n=>!n.resolved&&(void 0===t||e.F(n)===t)).length,N=()=>P(),z=t=>{let n=t.anchor.view?.slide,o=e.p.u(t.anchor.view)?"":ke(t.anchor.view);return n&&null!==e.p.slide()?`On slide ${n}`:o?`In ${o}`:nn},O=(e,t,n="")=>qe("div",{role:"group","aria-label":n?`${e} · ${n}`:e},qe("div",{class:"sec","aria-hidden":"true"},e,n&&qe("b",{},n)),...t);function D(){let t=$(),n=t?.dataset.thread,o=null!==k&&k.element.contains(t),i=e.c.all().filter(t=>!t.thread.resolved||e.state.C||t.thread.id===x),r=t=>{let n=t.thread,o=n.id===x,i=Xe(n.root.author,n.root.name);i.classList.add("in");let r=qe("button",{class:`mi${n.resolved?" done":""}${o?" open":""}`,type:"button",role:"menuitem","aria-expanded":String(o),"data-thread":n.id},i,qe("span",{},qe("span",{class:"clamp"},n.root.deleted?"Deleted":n.root.text),qe("small",{},T(n)?`“${Re(n.anchor.snapshot,80)}”`:t.location.where)));r.addEventListener("click",t=>{t.stopPropagation(),function(t){if(x===t)return H(!0);let n=y.find(e=>e.id===t);if(n){if(x=F=t,k=Tt(n,{...e.ee,close:()=>H(!0)},R(n)),D(),k.element.querySelector("textarea")?.focus({preventScroll:!0}),!e.F(n))return I(n);e.state.o&&!e.L()||e.p.W(n.anchor.view??{}).then(()=>{e.xe();let n=y.find(e=>e.id===t);n&&F===t&&x===t&&I(n)})}}(n.id)});let a=document.createDocumentFragment();return a.append(r),o&&k&&(k.update(n,R(n)),a.append(qe("div",{class:"xr",role:"region","aria-label":"Comment thread"},k.element))),a},a=i.filter(e=>T(e.thread));d.textContent=String(N()),u.setAttribute("aria-checked",String(e.state.C)),s.replaceChildren(i.length?"":qe("div",{class:"sec",role:"presentation"},"No open comments"),...function(t,n){let o=e.p.slide(),i=new Map;for(let n of t){let t=n.thread,r=null!==o?t.anchor.view?.slide??o:e.F(t)?e.p.u(t.anchor.view)?"":ke(t.anchor.view):null;i.set(r,[...i.get(r)??[],n])}if(null===o){let e=i.get(null)??[];return i.delete(null),[...e.map(n),...[...i].map(([e,t])=>O(e||nn,t.map(n)))]}return[...i].sort(([e],[t])=>Number(e)-Number(t)||0).map(([e,t])=>O(`Slide ${e} · ${t.filter(e=>!e.thread.resolved).length} open`,t.map(n),e===o?"This slide":""))}(i.filter(e=>!T(e.thread)),r),a.length?O("No longer on the page",a.map(r)):""),o?k.element.querySelector("textarea")?.focus({preventScroll:!0}):n&&M(s).find(e=>e.dataset.thread===n)?.focus({preventScroll:!0})}function R(t){let n=!T(t)&&e.F(t);return{H:"popover",quote:t.anchor.quote?.exact??null,lost:T(t)||n?t.anchor.snapshot:null,place:n?z(t):null}}let F="";function H(t=!1){if(!x)return;let n=x;x=k=null,e.f(null),D(),t&&M(s).find(e=>e.dataset.thread===n)?.focus({preventScroll:!0})}function I(t){let n=e.resolved.get(t.id),o=n&&!T(t)?n.element??n.range?.startContainer.parentElement??null:null;o?.scrollIntoView({block:"center",inline:"nearest",behavior:E?"auto":"smooth"}),o&&e.f(t.id)}function B(e,t,n=!1,...o){let i=qe("button",{class:"mi",type:"button",role:n?"menuitemcheckbox":"menuitem"},e,qe("span",{class:"lb"}),...o,n&&qe("span",{class:"sw","aria-hidden":"true"}),qe("span",{class:"tt","aria-hidden":"true"}));return i.addEventListener("click",e=>{e.stopPropagation(),t(e)}),i}let W=(e,t,n,o)=>{let i=e.querySelector(".lb");i.textContent!==t&&(i.textContent=t),e.querySelector(".tt").textContent=n,e.setAttribute("aria-description",n),void 0!==o&&e.setAttribute("aria-checked",String(o))},j=()=>qe("div",{class:"sep",role:"separator"}),K=qe("span",{class:"ma"}),V=qe("span",{class:"kc"}),Y="",U=B(K,function(){let t=qe("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"});t.value=e.c.name();let n=qe("div",{class:"ed"},K.cloneNode(!0),t),o=(i,r=!1)=>{if(g!==o)return;g=null;let a=t.value.trim();i&&a&&a!==e.c.name()&&e.c.rename(a).then(ae),n.replaceWith(U),r&&U.focus({preventScroll:!0})};g=o,t.addEventListener("keydown",e=>{e.stopPropagation(),("Enter"===e.key||"Escape"===e.key)&&(e.preventDefault(),o("Enter"===e.key,!0))}),t.addEventListener("blur",()=>o(!0)),U.replaceWith(n),t.focus({preventScroll:!0})},!1,V);U.dataset.item="name";let _=B(Ve("copy"),()=>{A(),e.c.copyAll("ai")}),G=B(Ve("lines"),()=>{A(),e.c.copyAll("text")}),J=qe("span",{class:"kc"}),X=B(Ve("list"),()=>{S(!1),L(!0)},!1,J),Z=B(Ve("comment"),t=>{let n=!e.state.l&&0===t.detail;e.Ge(!e.state.l,n),n&&S(!1)},!0,qe("span",{class:"kc","aria-hidden":"true"},vt));Z.dataset.item="comment",Z.setAttribute("aria-keyshortcuts",gt);let Q=qe("div",{class:"sec",role:"presentation"}),ee=j(),te=j(),ne=new Map,oe=t=>{let n=ne.get(t);return n||(n=B(Ye(t.icon,15),()=>{t.checked||A(),Promise.resolve().then(()=>t.select()).catch(t=>e.oe(t)).finally(()=>v&&ae())},!!t.checked,qe("span",{class:"kc"})),ne.set(t,n)),n},ie=-1,re=e=>{try{return e()}catch(e){return globalThis.reportError?.(e),""}};function ae(){let t=N(),n=e.c.name(),o=n||q(e.doc.me);if(W(U,o,n?"The name on your comments":"Add a name to show on your comments"),U.setAttribute("aria-label",`${o}, ${n?"edit":"add"} your name`),V.replaceChildren(n?Ve("edit",13):"Add name"),Je(e.doc.me,n)!==Y){Y=Je(e.doc.me,n);let t=Xe(e.doc.me,n);t.classList.add("in"),K.replaceChildren(t)}W(_,"Copy as Markdown","Markdown, with where each thread is"),W(G,"Copy as Text","Just the words"),W(X,"All comments","Every thread, and where it is"),J.textContent=t?String(t):"";let i=e.addons.de();Q.textContent=i,i?!Q.isConnected&&l.contains(U)&&l.prepend(Q):Q.remove();for(let t of e.addons.N){let e,n=ne.get(t);if(n){try{e=t.checked?.()}catch(e){globalThis.reportError?.(e)}W(n,re(t.label),re(t.hint),e),n.querySelector(".kc").textContent=t.count?re(t.count):""}}W(Z,"Start commenting",e.state.l?"Turn off to hide the comments again":"Shows the comments; choose any part of the page to comment on it",e.state.l)}function le(){ae(),(ie!==e.addons.Y||!l.contains(U))&&(l.replaceChildren(U,ee,_,G,X,...e.addons.N.map(oe),te,Z),ie=e.addons.Y,ae())}o.addEventListener("click",e=>{e.stopPropagation(),v?S(!1):(le(),S(!0),0===e.detail&&M().at(-1)?.focus({preventScroll:!0}))});let se=!1,de=()=>{se=p.contains($())},ce=t=>{let n=t.composedPath();v&&!n.includes(l)&&!n.includes(o)&&(S(!1),e.state.l&&!e.w(t)&&(e.ye(t),t.preventDefault(),t.stopPropagation())),e.state.d&&!e.w(t)&&L(!1,se&&(!document.activeElement||document.activeElement===document.body))},ue=e=>{if(!v||"touch"===e.pointerType||"pointerout"===e.type&&e.relatedTarget)return;let t=e.composedPath();"pointerover"===e.type&&(t.includes(l)||t.includes(o))?(window.clearTimeout(w),w=0):w||(w=window.setTimeout(()=>{w=0,g||S(!1)},3e3))},pe={n:0,label:""},he=()=>{let{n:t,label:n}=pe,r=e.addons.de(),a=`Comment${e.state.l?", comment mode on":""}${n?`, ${n}`:t?`, ${t} open`:""}${r?`, ${r}`:""}`;o.getAttribute("aria-label")!==a&&o.setAttribute("aria-label",a);let l=(n||"Comment")+(r?` · ${r}`:"");i.data!==l&&(i.data=l)},fe=e.addons.subscribe(e=>{he(),v&&!g&&(e?le():ae())});window.addEventListener("pointerdown",de,!0),window.addEventListener("click",ce,!0),window.addEventListener("pointerover",ue,!0),window.addEventListener("pointerout",ue,!0);let me=t=>{if("Escape"!==t.key||g)return;let n=t.composedPath()[0];if(v)A();else{if(!e.state.d||n instanceof HTMLTextAreaElement&&!p.contains(n))return;x?H(!0):L(!1,!0)}t.stopPropagation()};return window.addEventListener("keydown",me,!0),{m(n){y=n;let i=P(!1);if(i!==b){if(i){let[e,n]=t[0].classList.contains("on")?t:[t[1],t[0]];n.textContent=i>99?"99+":String(i),n.classList.toggle("s",i>99),e.classList.remove("on"),n.classList.add("on")}o.classList.toggle("has",i>0),b=i}let r=P(!0),a=r?`${i} here · ${r} ${null!==e.p.slide()?"on other slides":"in other views"}`:"";o.classList.toggle("else",r>0),pe={n:i,label:a},he(),o.classList.toggle("on",e.state.l),v&&!e.state.c&&S(!1),v&&ae();let l=e.state.d;p.classList.toggle("full",Lt()),p.classList.contains("show")!==l&&(p.classList.toggle("show",l),ze(p,!l)),x&&(!l||!n.some(e=>e.id===x))&&(x=k=null,e.state.f=null),l&&D()},T:function(){let t=x?y.find(e=>e.id===x):null,n=x?s.querySelector(".mi.open"):null,o=t&&function(t){let n=e.resolved.get(t.id),o=!n||Lt()||T(t)||e.F(t)?null:kt(t.anchor,n),i=n?.element??n?.range?.startContainer.parentElement;return o&&!1!==i?.checkVisibility?.({visibilityProperty:!0})&&o.x>=0&&o.x<=window.innerWidth-320&&o.y>=0&&o.y<=window.innerHeight?{x:o.x,y:o.y}:null}(t),i=n?.getBoundingClientRect(),r=s.getBoundingClientRect();if(!o||!i||i.top+12<r.top||i.top+12>r.bottom)return void h.classList.remove("show");let a=i.left,l=i.top+14,d=Math.max(40,(a-o.x)/2);f.setAttribute("d",`M${a} ${l}C${a-d} ${l} ${o.x+d} ${o.y} ${o.x} ${o.y}`),m.setAttribute("cx",String(o.x)),m.setAttribute("cy",String(o.y)),h.classList.add("show")},destroy(){fe(),window.removeEventListener("pointerdown",de,!0),window.removeEventListener("click",ce,!0),window.removeEventListener("pointerover",ue,!0),window.removeEventListener("pointerout",ue,!0),window.clearTimeout(w),window.removeEventListener("keydown",me,!0),l.remove(),p.remove(),h.remove(),a.remove()}}}var rn="[data-pipeup-slide]",an=["scroll","resize","keyup","click","transitionend","slidechanged"],ln=null,sn=null,dn=new Set,cn=new Set,un=e=>{try{e()}catch(e){globalThis.reportError?.(e)}};function pn(e){let t=null;if(e){t={};let n=0;for(let[o,i]of Object.entries(e))if(!("string"!=typeof i||"slide"===o||o.length>64||i.length>200)){if(++n>=16)break;t[o]=i}}ln=t;for(let e of cn)e()}function hn(e){return dn.add(e),()=>{dn.delete(e)}}function fn(e){sn="function"==typeof e?.current&&"function"==typeof e.go?e:null}var mn=()=>{let e=window.Reveal;return"function"==typeof e?.getIndices&&"function"==typeof e.slide?e:null};var vn=["pipeup-quote","pipeup-on","pipeup-done"],gn={"pipeup-quote":[[250,227,188,.75],[250,200,100,.28]],"pipeup-on":[[247,212,154,.95],[250,200,100,.42]],"pipeup-done":[[180,178,169,.22],[180,178,169,.2]]};function wn(){return typeof CSS<"u"&&"highlights"in CSS&&typeof Highlight<"u"}var yn=`:not([data-pipeup-ignore],[data-pipeup-ignore] *){cursor:url("data:image/svg+xml,${encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><rect x='7' y='7' width='23' height='23' rx='4' fill='none' stroke='#534AB7' stroke-width='2' stroke-dasharray='4 3'/><path d='M3 2v15l4-3.5 3 6.5 2.5-1.2-3-6.3H15z' fill='#fff' stroke='#2C2C2A' stroke-width='1.2' stroke-linejoin='round'/></svg>")}") 3 2,crosshair!important}`;function bn(){if(wn())for(let e of vn)CSS.highlights.delete(e)}var xn=':host{all:initial}*{box-sizing:border-box}button{appearance:none;font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}svg{display:block}.layer{all:initial;display:block;position:fixed;inset:0;pointer-events:none;font:13px/1.5 var(--pu-font,system-ui,sans-serif);color:var(--k);--k:#2C2C2A;--mu:#5F5E5A;--fa:#888780;--ln:#E5E3DA;--ru:#ECEAE2;--so:#FAFAF7;--su:#FFFFFF;--ho:#F1EFE8;--as:color-mix(in srgb,var(--pu-accent,#534AB7) 12%,transparent);--sh:0 8px 28px rgba(44,44,42,.1);--in:.26s;--mv:.34s;--out:.2s;--pl:1.2s;--eo:cubic-bezier(.22,.61,.36,1);--eio:cubic-bezier(.4,0,.2,1);--ei:cubic-bezier(.4,0,1,1);--pu-text:var(--k);--pu-muted:var(--mu);--pu-faint:var(--fa);--pu-line:var(--ln);--pu-surface:var(--su);--pu-soft:var(--so);--pu-hover:var(--ho);--pu-shadow:var(--sh);--pu-ease:var(--eo)}.layer.dark{--k:#ECEBE6;--mu:#B4B2A9;--fa:#8D8B84;--ln:#3A3936;--ru:#34332F;--so:#22221F;--su:#1B1B19;--ho:#2C2C29;--sh:0 8px 28px rgba(0,0,0,.45)}.layer.hidden .bub,.layer.hidden .col,.layer.hidden .pop,.layer.hidden .tip,.layer.hidden .mark,.layer.hidden .selbar{opacity:0!important;pointer-events:none!important}.tx{font-size:14px;line-height:1.5;color:var(--k);white-space:pre-wrap;overflow-wrap:anywhere}.tx.del,.who,.rest,.ctx{color:var(--fa)}.who,.rest{font-size:12px}.who{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.rft>.who{display:block}.ctx[hidden]{display:none}.ctx{font-size:12px;margin-bottom:3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.clamp{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.tx a{color:var(--pu-accent);text-decoration:underline;text-decoration-thickness:1px;text-underline-offset:2px}.ft,.rft{display:grid;grid-template-rows:0fr;opacity:0;transition:grid-template-rows var(--in) var(--eo),opacity var(--in) var(--eo)}.ft>*,.rft>*{overflow:hidden;min-height:0;display:flex;align-items:center}.root:hover>.ft,.root:focus-within>.ft,.it:hover>.rft,.it:focus-within>.rft{grid-template-rows:1fr;opacity:1}.ft.has-rest,.ft.open,.rft.open{grid-template-rows:1fr;opacity:1}.ft.has-rest>*{grid-area:1/1}.ft .hover{opacity:0;transition:opacity var(--in) var(--eo)}.ft .rest{transition:opacity var(--in) var(--eo)}.root:hover>.ft .hover,.root:focus-within>.ft .hover,.ft:not(.has-rest) .hover{opacity:1}.root:hover>.ft .rest,.root:focus-within>.ft .rest{opacity:0}.acts{margin-left:6px;display:flex;flex:none}.ib{width:24px;height:22px;display:grid;place-items:center;border-radius:6px;color:var(--mu);transition:background-color .2s var(--eo),color .2s var(--eo)}.ib:hover,.ib:focus-visible{background:var(--ho);color:var(--k);outline:none}.rps,.rbox{padding-left:14px}.rps .it{padding-top:6px}.more{display:grid;grid-template-rows:1fr;transition:grid-template-rows var(--mv) var(--eio)}.more>div{overflow:hidden;min-height:0}.th:not(.on) .more{grid-template-rows:0fr}.row{display:flex;align-items:center;gap:8px;padding:8px 0 2px;cursor:text}.input{flex:1;min-width:0;height:27px;display:block;border:0;border-bottom:1px solid var(--ln);outline:none;resize:none;overflow:hidden;font:inherit;font-size:14px;line-height:1.5;padding:3px 0;color:var(--k);background:transparent;transition:border-color var(--in) var(--eo)}.row:hover .input,.input:hover{border-bottom-color:var(--mu)}.input:focus{border-bottom-color:var(--pu-accent)}.ed{display:flex;gap:10px;align-items:center;min-height:34px;padding:6px 10px}.ed .input{font-size:13px;height:22px}.root,.it{position:relative;padding-right:30px}.av{display:grid;place-items:center;width:22px;height:22px;border-radius:32%;font-size:12px;font-weight:600;line-height:1;opacity:0;transform:scale(.85);transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.av.in{opacity:1;transform:none}.av svg{width:80%;height:80%}.root>.av,.it>.av{position:absolute;top:0;right:0}.it>.av{top:6px}.av{--av-l:92%;--av-d:30%;--s:60%;background:hsl(var(--h) var(--s) var(--av-l));color:hsl(var(--h) var(--s) var(--av-d))}.dark .av{--av-l:20%;--av-d:78%}.av.ai{position:relative;border-radius:50%;background:var(--su);color:var(--pu-accent);font-size:9px;letter-spacing:.02em;box-shadow:0 0 0 1.5px var(--pu-accent)}.av.ai:after{content:"";position:absolute;inset:-4px;border-radius:50%;box-shadow:0 0 9px 1px color-mix(in srgb,var(--pu-accent) 45%,transparent);opacity:.3;animation:pu-breathe 3.8s var(--eio) infinite;pointer-events:none}.av.ai.busy:after{animation-duration:2.2s}@keyframes pu-breathe{0%,to{opacity:.25;transform:scale(1)}50%{opacity:1;transform:scale(1.1)}}.ghost .dots{display:inline-flex;gap:3px;margin-left:4px;vertical-align:middle}.ghost .dots i{width:4px;height:4px;border-radius:50%;background:var(--fa);animation:pu-dot 1.6s var(--eio) infinite}.ghost .dots i:nth-child(2){animation-delay:.2s}.ghost .dots i:nth-child(3){animation-delay:.4s}@keyframes pu-dot{0%,to{opacity:.25}50%{opacity:1}}.c0{--h:0}.c1{--h:25}.c2{--h:50}.c3{--h:130}.c4{--h:175}.c5{--h:215}.c6{--h:270}.c7{--h:330}.c8{--h:28;--s:35%}.c9{--h:220;--s:8%}.me{flex:none;display:grid}.me>.av{grid-area:1/1;width:26px;height:26px;font-size:13px}.you{display:grid;padding:0 34px;min-height:24px;font-size:12px;color:var(--fa)}.you>*{grid-area:1/1;display:flex;align-items:center;min-width:0;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.say{white-space:pre;overflow:hidden}.nm{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.say button{flex:none}.say button{color:var(--mu);text-decoration:underline;text-decoration-color:var(--ln);text-underline-offset:2px;transition:color .2s var(--eo)}.say button:hover,.say button:focus-visible{color:var(--pu-accent);outline:none}.nf{opacity:0;transform:translateY(-4px);pointer-events:none}.nf .input{font-size:13px;height:24px}.you.naming .nf{opacity:1;transform:none;pointer-events:auto}.you.naming .say{opacity:0;pointer-events:none}.send{width:26px;height:26px;border-radius:50%;display:grid;place-items:center;color:var(--pu-accent);flex:none;opacity:0;pointer-events:none;transition:opacity var(--in) var(--eo),background-color .2s var(--eo)}.send.show{opacity:1;pointer-events:auto}.send:hover{background:var(--as)}.bub{position:fixed;left:0;top:0;width:20px;height:20px;margin:-20px 0 0 -2px;border-radius:50% 50% 50% 0;background:var(--pu-accent);border:2px solid var(--su);box-shadow:0 1px 4px #0003;pointer-events:auto;opacity:0;transform:translateY(-6px) scale(.9);transform-origin:2px 20px;transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.bub.in{opacity:1;transform:none;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.bub.in:hover,.bub.on{transform:scale(1.18)}.bub.done{background:var(--fa)}.bub.ghost{pointer-events:none}.tip,.pop,.menu,.all,.xp,.toast,.selbar,.namebar,.ttip,.tt,.mode{background:var(--su);border:1px solid var(--ln);box-shadow:var(--sh)}.tip{position:fixed;max-width:260px;border-radius:10px;padding:7px 10px;opacity:0;transform:translateY(3px);transition:opacity .22s var(--eo),transform .26s var(--eo)}.tip.show{opacity:1;transform:none;pointer-events:auto;cursor:pointer;transition:opacity .22s var(--eo),transform .26s var(--eo),left var(--mv) var(--eio),top var(--mv) var(--eio)}.pop{position:fixed;width:var(--pu-pop);border-radius:12px;padding:10px 12px 8px;pointer-events:none;opacity:0;transform:translateY(6px) scale(.98);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.pop.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo)}.pop.show.glide{transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo),left var(--mv) var(--eio),top var(--mv) var(--eio)}.mark{position:fixed;border:2px solid color-mix(in srgb,var(--pu-accent) 50%,transparent);background:var(--as);border-radius:8px;opacity:0;transition:opacity .3s var(--eo)}.mark.show{opacity:1}.pulse{position:fixed;border:2px solid var(--pu-accent);border-radius:8px;background:var(--as);animation:pu-pulse var(--pl) var(--eio) forwards}@keyframes pu-pulse{0%{opacity:0;transform:scale(.985)}35%{opacity:.85;transform:scale(1)}to{opacity:0;transform:scale(1.02)}}.col{position:fixed;left:0;top:0;pointer-events:none;transition:opacity var(--in) var(--eo)}.th{position:absolute;left:0;right:0;top:0;padding:4px 4px 4px 12px;pointer-events:auto;cursor:pointer;box-shadow:inset 2px 0 0 transparent;transition:transform var(--mv) var(--eio),box-shadow var(--in) var(--eo),opacity var(--in) var(--eo)}.th.hot{box-shadow:inset 2px 0 0 var(--ln)}.th.on{box-shadow:inset 2px 0 0 var(--pu-accent);cursor:default}.th.dim{opacity:.45}.th.resolved:not(.on):not(.hot){opacity:.6}.th.lost .ctx{white-space:normal}.th.wait{opacity:0!important;pointer-events:none}.th.out{opacity:0!important;pointer-events:none;transition:opacity var(--out) var(--ei)}.th:has(.opn:focus-visible){box-shadow:inset 2px 0 0 var(--ln);outline:2px solid var(--pu-accent);outline-offset:2px;border-radius:4px}.selbar{position:fixed;display:flex;border-radius:10px;padding:2px;opacity:0;transform:translateY(4px);pointer-events:none;transition:opacity var(--in) var(--eo),transform .3s var(--eo)}.selbar.show{opacity:1;transform:none;pointer-events:auto}.selbar button{width:32px;height:30px;display:grid;place-items:center;border-radius:8px;color:var(--pu-accent);transition:background-color .2s var(--eo)}.selbar button:hover,.selbar button:focus-visible{background:var(--as);outline:none}.pick{position:fixed;left:0;top:0;border:2px solid color-mix(in srgb,var(--pu-accent) 70%,transparent);background:color-mix(in srgb,var(--pu-accent) 6%,transparent);border-radius:8px;pointer-events:none;opacity:0;transition:opacity var(--out) var(--ei),border-color var(--out) var(--ei),border-width var(--out) var(--ei),box-shadow var(--out) var(--ei)}.pick.show{opacity:1;transition-duration:var(--in);transition-timing-function:var(--eo)}.pick.show.glide{transition-property:all;transition-duration:var(--mv);transition-timing-function:var(--eio)}.pick.on{border-color:var(--pu-accent)}.pick.kf{border:3px solid var(--pu-accent);box-shadow:0 0 0 2px var(--su)}.km{position:fixed;left:0;top:0;pointer-events:none;outline:none}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.namebar{position:fixed;left:0;top:0;display:flex;align-items:center;gap:2px;padding:2px 2px 2px 10px;border-radius:10px;font-size:12px;color:var(--mu);white-space:nowrap;pointer-events:none;opacity:0;transform:translateY(4px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.namebar.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform .3s var(--eo)}.namebar.show.glide{transition-property:all;transition-duration:var(--mv);transition-timing-function:var(--eio)}.namebar .lbl{margin-right:6px;max-width:260px;overflow:hidden;text-overflow:ellipsis}.namebar .nb{padding:4px;display:grid;place-items:center;border-radius:7px;transition:background-color .2s var(--eo),color .2s var(--eo)}.namebar .nb:hover,.namebar .nb:focus-visible{background:var(--ho);color:var(--k);outline:none}.namebar .nb[hidden]{display:none}.launch{position:fixed;right:20px;bottom:20px;pointer-events:auto}.launch .mode{position:relative;display:grid;place-items:center;width:46px;height:46px;border-radius:50%;transition:background-color .3s var(--eo),color .3s var(--eo)}.mode>*,.cnt>*{grid-area:1/1}.mode>*{display:grid;place-items:center;transition:opacity var(--in) var(--eo)}.cnt,.has>.plus{opacity:0}.has>.cnt{opacity:1}.n{font-size:12px;font-weight:500;line-height:1;margin:-1.4px 0 0 1.4px;font-variant-numeric:tabular-nums;opacity:0;transition:opacity var(--in) var(--eo)}.n.s{font-size:9.5px;letter-spacing:-.04em}.n.on{opacity:1}.launch .mode:hover,.launch .mode[aria-expanded=true]{background:var(--ho)}.launch .mode.on{background:var(--pu-accent);color:var(--pu-on,#fff)}.mode>.dot{position:absolute;top:3px;right:3px;width:9px;height:9px;border-radius:50%;background:var(--pu-accent);border:2px solid var(--su);opacity:0}.mode.else>.dot{opacity:1}.ttip{position:absolute;right:0;bottom:54px;white-space:nowrap;border-radius:8px;padding:4px 9px;font-size:12px;pointer-events:none;opacity:0;transform:translateY(3px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.ttip small{margin-left:8px}.ttip small,.mi .kc{font-size:12px;color:var(--fa)}.mode:hover+.ttip,.mode:focus-visible+.ttip{opacity:1;transform:none;transition:opacity var(--in) var(--eo) .5s,transform var(--in) var(--eo) .5s}.launch .mode[aria-expanded=true]+.ttip{opacity:0;transition:opacity var(--out) var(--ei)}@media(hover:none){.ttip,.tt{display:none}}.menu{position:fixed;right:20px;bottom:76px;width:290px;border-radius:12px;padding:4px;pointer-events:none;opacity:0;transform:translateY(6px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.menu.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo)}.mi{position:relative;display:flex;gap:10px;align-items:center;width:100%;min-height:34px;text-align:left;padding:6px 10px;border-radius:8px;transition:background-color .2s var(--eo)}.mi:hover,.mi:focus-visible{background:var(--so);outline:none}.mi svg{color:var(--mu);flex:none}.mi small{display:block;color:var(--fa);font-size:12px}.lb{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ma{flex:none;display:grid;margin:-2px 0}.ma .av{width:20px;height:20px;font-size:11px}.mi .av svg{color:inherit}.sep{height:1px;margin:4px 10px;background:var(--ru)}.tt{position:absolute;right:calc(100% + 14px);top:50%;translate:0 -50%;width:max-content;max-width:220px;padding:4px 9px;border-radius:8px;font-size:12px;line-height:1.4;color:var(--mu);pointer-events:none;opacity:0;transform:translate(3px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.mi:hover>.tt,.mi:focus-visible>.tt{opacity:1;transform:none;transition:opacity var(--in) var(--eo) .5s,transform var(--in) var(--eo) .5s}@media(max-width:600px){.tt{right:8px;top:auto;bottom:100%;translate:none;transform:translateY(3px)}}.sw{position:relative;flex:none;width:26px;height:16px;border-radius:8px;background:var(--ln);transition:background-color var(--mv) var(--eio)}.sw:before,.sw:after{content:"";position:absolute;top:2px;left:2px;width:12px;height:12px;border-radius:50%;background:#fff;box-shadow:0 1px 2px #00000040;transition:transform var(--mv) var(--eio),opacity var(--mv) var(--eio)}.sw:before{opacity:0;transform:translate(10px)}[aria-checked=true]>.sw{background:var(--pu-accent)}[aria-checked=true]>.sw:after{transform:translate(10px)}.tools{display:flex;flex:none;gap:2px}.tools[hidden]{display:none}.tool[aria-pressed=true]{background:var(--as);color:var(--pu-accent)}.note{display:block;padding:0 0 4px;font-size:12px;color:var(--fa)}.note[hidden]{display:none}.ov{position:absolute;inset:0;pointer-events:none;overflow:hidden}.xb{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px 16px 16px;font-size:13px}.xb p{margin:0 0 10px}.all,.xp{position:fixed;top:0;right:0;bottom:0;width:var(--pu-panel);display:flex;flex-direction:column;border-width:0 0 0 1px;opacity:0;transform:translate(100%);transition:transform var(--out) var(--ei),opacity var(--out) var(--ei)}.all.show,.xp.show{opacity:1;transform:none;pointer-events:auto;transition:transform var(--mv) var(--eo),opacity var(--in) var(--eo)}.all.full{width:100%}.hd{display:flex;align-items:center;gap:8px;padding:12px 10px 8px 16px;font-weight:600}.pn{font-weight:400;color:var(--fa)}.hs{margin-left:auto;display:flex;align-items:center;gap:6px;padding:3px 4px 3px 6px;border-radius:6px;font-size:12px;font-weight:400;color:var(--mu);transition:background-color .2s var(--eo)}.hs:hover,.hs:focus-visible{background:var(--ho);outline:none}.list{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px}.all .mi{align-items:flex-start}.all .mi>.av{flex:none}.all .mi>span:last-child{flex:1;min-width:0}.all .mi small{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.all .mi.done{opacity:.6}.all .mi.open{background:var(--so)}.all .mi.open>.av,.all .mi.open .clamp{display:none}.xr{padding:2px 12px 10px 16px}.cx{position:fixed;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none;opacity:0;transition:opacity var(--in) var(--eo)}.cx.show{opacity:1}.cx path{fill:none;stroke:var(--pu-accent);stroke-width:1.5;stroke-linecap:round;opacity:.7}.cx circle{fill:var(--pu-accent)}.layer.listing .col{opacity:0;transition:opacity var(--out) var(--ei)}.sec{padding:8px 10px 2px;font-size:12px;color:var(--fa)}.sec b{margin-left:6px;font-weight:500;color:var(--pu-accent)}.toast{position:fixed;left:50%;bottom:28px;border-radius:10px;padding:8px 14px;font-size:13px;opacity:0;transform:translate(-50%,6px);transition:opacity .3s var(--eo),transform .36s var(--eo)}.toast.show{opacity:1;transform:translate(-50%)}@media(forced-colors:active){.pick.kf{border:3px solid Highlight}.layer :is(.ib,.mi,.nb,.hs,.selbar button,.say button,.xb button):focus-visible{outline:2px solid Highlight}}@media(prefers-reduced-motion:reduce){.bub,.bub.in,.bub.in:hover,.bub.on,.tip,.pop,.selbar,.menu,.all,.xp,.ttip,.tt,.toast{transform:none!important}.sw:after{transform:none!important;transition-property:opacity}[aria-checked=true]>.sw:after{opacity:0}[aria-checked=true]>.sw:before{opacity:1}.th{transition-property:opacity,box-shadow}.tip.show{transition-property:opacity}.pick,.pick.show{transition:opacity .16s ease-in-out}.all,.all.show,.xp,.xp.show{transition-property:opacity}.namebar,.namebar.show{transform:none!important;transition:opacity .16s ease-in-out}.av,.nf{transform:none!important}.av.ai:after{animation:none;opacity:.5}.ghost .dots i{animation:none;opacity:.6}@keyframes pu-pulse{0%{opacity:0}35%{opacity:.85}to{opacity:0}}}',kn="#534AB7";function En(e){let t=/rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)/.exec(e);if(!t||void 0===t[1]||void 0===t[2]||void 0===t[3])return null;let n=void 0===t[4]?1:t[4].endsWith("%")?parseFloat(t[4])/100:parseFloat(t[4]);return{r:Number(t[1]),g:Number(t[2]),b:Number(t[3]),a:n}}function Sn(e){let t=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return.2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}var Ln=(e,t)=>(Math.max(e,t)+.05)/(Math.min(e,t)+.05);function Mn(e){let t=e.ownerDocument,n=t.defaultView;if(!n)return{font:"system-ui, sans-serif",accent:kn,dark:!1,on:"#fff"};let o=t.documentElement,i=n.getComputedStyle(e).fontFamily||"system-ui, sans-serif",r=(n.getComputedStyle(o).getPropertyValue("--pipeup-accent")||o.style.getPropertyValue("--pipeup-accent")).trim(),a=e.querySelector("a[href]"),l=a?n.getComputedStyle(a).color:"",s=En(n.getComputedStyle(t.body).backgroundColor);(!s||0===s.a)&&(s=En(n.getComputedStyle(o).backgroundColor));let d=!!(s&&s.a>0?Sn(s)<.2:!0===n.matchMedia?.("(prefers-color-scheme: dark)").matches&&/dark/.test(n.getComputedStyle(o).colorScheme||"")),c=l&&"rgb(0, 0, 238)"!==l?En(l):null,u=c&&Ln(Sn(c),d?.011:1)>=3,p=r||(u?l:d?"#9A94EE":kn),h=En(p);return{font:i,accent:p,dark:d,on:h&&Ln(Sn(h),1)<3?"#111":"#fff"}}function $n(e,t){e.style.setProperty("--pu-font",t.font),e.style.setProperty("--pu-accent",t.accent),e.style.setProperty("--pu-on",t.on),e.classList.toggle("dark",t.dark)}function An(e,t=!1){return Jt(e,t)?"column":"bubbles"}var Cn="Shown here, but not saved yet — it will be saved with your next change",Tn=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";function Pn(e){let t=Mn(e.root),n=function(e,t=document){let n=t.createElement("pipeup-root");n.setAttribute("data-pipeup-ignore",""),n.style.cssText="position:fixed!important;inset:0!important;pointer-events:none!important;z-index:2147483000!important;display:block!important;margin:0!important;visibility:visible!important;opacity:1!important;transform:none!important;filter:none!important;";let o=n.attachShadow({mode:"open"}),i=t.defaultView?.CSSStyleSheet;if(i&&"replaceSync"in i.prototype&&"adoptedStyleSheets"in o){let e=new i;e.replaceSync(xn),o.adoptedStyleSheets=[e]}else{let e=t.createElement("style");e.textContent=xn,o.append(e)}let r=t.createElement("div");return r.className="layer",r.style.setProperty("--pu-panel","320px"),r.style.setProperty("--pu-pop",`${St()}px`),$n(r,e),o.append(r),t.documentElement.append(n),{element:n,shadow:o,t:r,destroy:()=>n.remove()}}(t),o=function(e=document,t=!1){let n=e.defaultView?.CSSStyleSheet;if(!n||!("replaceSync"in n.prototype)||!("adoptedStyleSheets"in e))return{Ee(){},ke(){},ae(){},Se(){},remove:()=>bn()};let o=new n,i=null,r=!1,a=1,l=0,s="",d=0,c=()=>o.replaceSync(((e,t)=>vn.map(n=>{let[o,i,r,a]=gn[n][e?1:0];return`::highlight(${n}){background-color:rgba(${o},${i},${r},${+(a*t).toFixed(3)})}`}).join(""))(t,a)+(null===i?"":`:root{--pipeup-gutter:${i}px}`)+(r?yn:"")+(l||s?`html{--pipeup-panel:${l}px;${l?`margin-right:${l}px!important;`:""}${s}}`:""));return c(),e.adoptedStyleSheets=[...e.adoptedStyleSheets,o],{Ee(e){e!==i&&(i=e,c())},ke(e){e!==r&&(r=e,c())},ae(e){a=e,c()},Se(e,t){e!==l&&(l=e,s=t?"":"transition:margin-right .34s cubic-bezier(.4,0,.2,1)!important",clearTimeout(d),!e&&s&&(d=window.setTimeout(()=>{s="",c()},400)),c())},remove(){clearTimeout(d),e.adoptedStyleSheets=e.adoptedStyleSheets.filter(e=>e!==o),bn()}}}(document,t.dark);o.ae(0);let i=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,r=document.documentElement.hasAttribute("data-pipeup-reserve"),a=new Map,l=new Set,s=new WeakSet,d={i:null,f:null,C:!1,hidden:!0,mode:An(e.root),o:null,l:!1,d:!1,Te:!1,c:!1},c=qe("div",{class:"toast",role:"status","aria-live":"polite"}),u=qe("div",{class:"sr","aria-live":"polite"});n.t.append(c,u);let p=null,h=[],f=null,m=!1,v=0,g=0,w=0,y=0,b=0,x=new Set,k="",E=new Map,S=function(e,t,n=function(){return{s:e=>e.getBoundingClientRect(),shown:e=>!1!==e.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0}),opacity:e=>parseFloat(getComputedStyle(e).opacity)||0,ne:()=>({width:window.innerWidth,height:window.innerHeight})}}()){let o=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,i=null,r=null,a=0,l=!1,s=()=>[...e.querySelectorAll(rn)],d=()=>[...e.querySelectorAll(".slides > section")],c=e=>"string"==typeof e&&e.length>0&&e.length<=200?e:null,u=e=>c(e?.getAttribute("data-pipeup-slide"));function p(){if(sn){let e=null;if(un(()=>{let t=sn.current();Number.isInteger(t)&&t>0&&(e=String(t))}),null!==e)return e}let e=mn();if(e){let t=null;if(un(()=>{let n=e.getIndices().h,o=d()[n];t=u(o?.matches(rn)?o:o?.querySelector(rn))??c(String(n+1))}),null!==t)return t}return i&&!i.isConnected&&(i=null),i=function(e,t,n){let o=t.ne(),i=null,r=0,a=0;for(let l of e){if(!t.shown(l))continue;let e=t.s(l),s=Math.min(e.left+e.width,o.width)-Math.max(e.left,0),d=Math.min(e.top+e.height,o.height)-Math.max(e.top,0);if(s<=0||d<=0)continue;let c=Math.round(s*d),u=t.opacity(l);(c>r||c===r&&(u>a||u===a&&l===n))&&(i=l,r=c,a=u)}return i}(s(),n,i)??i,u(i)}function h(){a=0,r=p(),t()}let f=()=>{!a&&!l&&(a=requestAnimationFrame(h))},m=e=>function(e,t,n){return null!==t?void 0===e?.slide||e.slide===t:!e||!n||Object.entries(e).every(([e,t])=>"label"===e||"slide"===e||n[e]===t)}(e,r,ln),v=new MutationObserver(e=>{e.some(e=>e.target instanceof Element&&e.target.matches(rn))&&f()});v.observe(e,{subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]});for(let e of an)window.addEventListener(e,f,{capture:!0,passive:!0});return cn.add(f),r=p(),{slide:()=>r,view(e){let t=e instanceof Element?e:e?.parentElement,n=u(t?.closest(rn))??r,o={...null!==n?{slide:n}:{},...ln};return Object.keys(o).length?o:void 0},u:m,W:function(e){if(m(e))return Promise.resolve(!0);let t=e.slide,n=mn(),i=s().find(e=>u(e)===t),a=/^[1-9]\d{0,5}$/.test(t??"");if(a&&sn)un(()=>sn.go(Number(t)));else if(a&&n){let e=i?d().findIndex(e=>e===i||e.contains(i)):-1;un(()=>n.slide(e>=0?e:Number(t)-1))}else if(dn.size)for(let t of dn)un(()=>t({...e}));else{if(!i)return Promise.resolve(!1);i.scrollIntoView({block:"start",behavior:o?"auto":"smooth"})}let c=performance.now();return new Promise(t=>{let n=e=>{clearTimeout(o),t(e)},o=setTimeout(()=>n(!1),1e3),i=()=>l?n(!1):(r=p(),m(e)?n(!0):performance.now()-c>=1e3?n(!1):void requestAnimationFrame(i));requestAnimationFrame(i)})},destroy(){l=!0,cancelAnimationFrame(a),v.disconnect();for(let e of an)window.removeEventListener(e,f,!0);cn.delete(f)}}}(e.root,()=>{!m&&H()&&Y()}),L=!1,M=0;function $(e,t=2400,n=!1,o=!1){m||(L=n,c.textContent=e,o?c.setAttribute("aria-hidden","true"):c.removeAttribute("aria-hidden"),c.classList.add("show"),window.clearTimeout(v),v=window.setTimeout(()=>c.classList.remove("show"),t))}function A(){L&&(L=!1,window.clearTimeout(v),c.classList.remove("show"))}function C(e){u.textContent="",cancelAnimationFrame(M),M=requestAnimationFrame(()=>u.textContent=e)}function T(e){$(Tn(e))}function P(e){throw T(e),e}let N=t=>({thread:t,location:xe(t.anchor,a.get(t.id)??fe(t.anchor,e.root),e.root)}),q={reply:async(t,n)=>{try{await e.doc.reply(t,n)}catch(e){e instanceof j?$(Cn):P(e)}},resolve:async t=>{try{await e.doc.resolve(t),$("Resolved · Show resolved brings it back")}catch(e){$(e instanceof j?`Resolved · ${Cn}`:Tn(e))}(e=>d.i===e&&!d.C&&(f?.ie()?f.se():n.t.querySelector(".launch .mode")?.focus({preventScroll:!0}),!0))(t)&&(d.i=null)},reopen:async t=>{try{await e.doc.reopen(t),$("Reopened")}catch(e){$(e instanceof j?`Reopened · ${Cn}`:Tn(e))}},close:()=>{Q(null);let e=U&&n.t.querySelector(U);e?e.focus({preventScroll:!0}):f?.se(),U=""},copy:t=>{try{let o=e.doc.threads().find(e=>e.id===t);if(!o)return;tn(Me(N(o),"ai",location.href,Date.now()),n.t).then(()=>$("Thread copied as Markdown for AI"),e=>$(Tn(e)))}catch(e){$(Tn(e))}}},z={copyAll:async e=>{let t=z.all(),o=$e(t,e,{title:document.title,url:location.href,exportedAt:new Date});try{await tn(o,n.t);let i=t.filter(e=>!e.thread.resolved).length;$(`Copied ${i} thread${1===i?"":"s"}${"ai"===e?" as Markdown for AI":""}`)}catch(e){$(Tn(e))}},je:()=>{d.C=!d.C,Y()},rename:async t=>{let n=t.replace(/\s+/g," ").trim();try{await async function(t){try{return await e.onName(t),!1}catch(n){if(e.doc.name!==t)throw n;return!0}}(n)?$(`New comments will say ${n}, but this browser couldn't remember it`):$(`New comments will say ${n}`)}catch(e){$(Tn(e))}},name:()=>e.doc.name,all:()=>[...e.doc.threads()].sort(At(D)).map(N)},O={},D={get addons(){return O.surface},doc:e.doc,root:e.root,t:n.t,host:n.element,state:d,resolved:a,S:l,ee:q,c:z,p:S,F:e=>x.has(e.id),xe:()=>{H()&&Y()},D:e=>!d.hidden&&(!e.resolved||d.C||(e=>""!==(n.t.querySelector(`[data-thread="${e}"] .rbox textarea`)?.value.trim()??""))(e.id))&&!x.has(e.id),Xe:(t,n)=>{for(let o of e.doc.threads()){let e=a.get(o.id);if(o.anchor.quote&&D.D(o)&&e?.range&&Et(t,n,bt(e)))return o}return null},te:(e,t)=>D.L()?D.Xe(e,t):null,w:e=>e.composedPath().includes(n.element),ye:e=>{s.add(e)},Ue:e=>s.has(e),open:Q,Je:e=>X(e),f:function(e){d.f!==e&&(d.f=e,e&&e!==d.i&&re(e),Y())},Ye:ee,qe:function(e){if(!d.o)return ee(e);Object.assign(d.o,e),Y()},L:()=>!p||p.De(),we:e=>{let t=p?.ge();e(),t?.()},ze:()=>{let e=d.o?.anchor.view,t=p?.ge();Promise.resolve(S.u(e)||S.W(e??{}).then(()=>D.xe())).then(t)},Be:async function(t){let n=d.o;if(n)try{let o=await e.doc.comment(n.anchor,t);d.o=null,F(new Set([o])),Q(o,!0)}catch(e){if(e instanceof j)return d.o=null,F(new Set([e.id])),Q(e.id,!0),void $(Cn);P(e)}},Fe:te,Ge:ne,B:ie,R:e=>{p=e},J:$,E:C,Ke:A,oe:T,Qe:re,m:Y,re:oe},R=O.surface=new dt(D,n.shadow,u);function F(t){let n=performance.now(),o=e.doc.threads();for(let i of o){if(t&&!t.has(i.id))continue;let o=performance.now()-n<40,r=fe(i.anchor,e.root,{fuzzy:o});a.set(i.id,r),o||"orphaned"!==r.state?l.delete(i.id):l.add(i.id)}for(let e of[...a.keys()])o.some(t=>t.id===e)||a.delete(e);0===l.size?(window.clearTimeout(y),y=0):0===y&&(y=window.setTimeout(()=>{y=0,!m&&(F(new Set(l)),Y())},250))}function H(){let t=new Set,n=null!==S.slide(),o=new Set;for(let i of e.doc.threads()){o.add(i.id);let e=a.get(i.id)?.element;(!S.u(i.anchor.view)||!n&&!1===e?.checkVisibility?.({visibilityProperty:!0}))&&t.add(i.id)}x=t;for(let e of E.keys())o.has(e)||E.delete(e);let i=`${S.slide()}|${[...t].join()}`;return i!==k&&(k=i,!0)}let I=0,B=0,W=0,K=0,V=0;function Y(){if(m)return;let t=e.doc.threads();if(H(),d.i&&x.has(d.i)){let e=n.t.querySelector(`[data-thread="${d.i}"] .rbox textarea`)?.value;e&&E.set(d.i,e),d.i=null}d.hidden=!(d.l||d.d||d.Te||d.o),d.hidden&&(d.i=null),function(e){if(e===B)return;B=e,cancelAnimationFrame(W);let t=I,n=performance.now(),i=e?260:200,r=a=>{let l=Math.min(1,(a-n)/i);I=t+(e-t)*(e?1-(1-l)**3:l*l),o.ae(I),l<1&&(W=requestAnimationFrame(r))};W=requestAnimationFrame(r)}(d.hidden?0:1),n.t.classList.toggle("hidden",d.hidden),n.t.classList.toggle("listing",d.d);let l=d.d&&!Lt();(function(e){e!==K&&(K=e,o.Se(e,i),window.clearTimeout(V),V=window.setTimeout(()=>{F(),Y()},i?0:400))})(l?320:0),o.Ee(r?"column"!==d.mode||d.hidden||l?0:320:null),function(e){let t=[],n=[],o=[];for(let i of e){let e=a.get(i.id);i.resolved&&!d.C||!e?.range||x.has(i.id)||(i.id===d.i||i.id===d.f?n.push(e.range):i.resolved?o.push(e.range):t.push(e.range))}d.o&&S.u(d.o.anchor.view)&&n.push(...d.o.ranges),function(e){if(wn())for(let t of vn)CSS.highlights.set(t,new Highlight(...e[t.slice(7)]))}({quote:t,on:n,done:o})}(t);for(let e of h)e.m(t);f?.m(t),d.hidden||R.flush()}let U="",_=()=>n.t.getRootNode().activeElement,G="input,textarea,select,[contenteditable]:not([contenteditable=false])",J=()=>{let e=_();return e instanceof HTMLTextAreaElement&&""!==e.value||!!document.activeElement?.matches(G)};function X(e,t=J(),o=_()){let i=[...n.t.querySelectorAll(`[data-thread="${e}"] .rbox textarea`)].find(e=>!e.closest("[inert]")),r=o?.getAttribute("data-thread");U=r?`.${o.classList[0]}[data-thread="${r}"]`:"",!t&&i&&i.focus({preventScroll:!0})}function Z(){let e=d.o;return!(!e||D.L()||(S.u(e.anchor.view)||S.W(e.anchor.view??{}),0))}function Q(e,t=!1){if(e&&Z())return;if(d.i===e&&!d.o)return e?X(e):void 0;let o=!t&&J(),i=_();if(e||(d.Te=!1),d.i=e,e&&(d.o=null,re(e)),Y(),e){let r=E.get(e),a=r&&n.t.querySelector(`[data-thread="${e}"] .rbox textarea`);a&&!a.value&&(a.value=r,a.dispatchEvent(new Event("input",{bubbles:!0}))),E.delete(e),t&&f?.ie()?f.se():X(e,o,i)}}function ee(e){A(),d.d=!1,d.o=e,d.i=null,Y()}function te(){d.o&&(d.o=null,Y())}function ne(e,t=!1){d.l!==e&&(d.l=e,o.ke(e),e?(d.i=null,d.d=!1,f=Gt(D)):(A(),f?.destroy(),f=null,C("Comment mode off")),Y(),f&&(t&&f.be(),t?f.ie()?$(_t,1e4,!0,!0):$("Nothing here to comment on"):$(`Click anything to comment, or Tab between blocks · Option-click (Alt-click) to pin · ${vt} or Esc to finish`,4e3,!0)))}function oe(){d.o&&(S.u(d.o.anchor.view)||D.L())?te():d.i?Q(null):f&&!f.re()&&ne(!1)}function ie(){d.o?Z()||te():d.i&&Q(null)}function re(e){let t=a.get(e);if(!t||"orphaned"===t.state)return;let o=t.range?bt(t):t.element?[t.element.getBoundingClientRect()]:[];for(let e of o.slice(0,6)){let t=qe("div",{class:"pulse"});Fe(t,e,4),n.t.prepend(t),window.setTimeout(()=>t.remove(),1300)}}function ae(){for(let e of h)e.destroy();h=function(e){return[..."column"===e.state.mode?[Zt(e),Pt(e,{Z:!1})]:[Pt(e,{Z:!0})],en(e),on(e)]}(D),Y()}let le=()=>{if(!m){for(let e of h)e.T();f?.T(),R.T(),b=requestAnimationFrame(le)}},se=e=>{if("Escape"===e.key)return oe();if(function(e){return"KeyC"===e.code&&e.shiftKey&&e.altKey&&!e.metaKey&&!e.ctrlKey&&!e.repeat&&!e.getModifierState("AltGraph")}(e)&&!e.isComposing&&!e.defaultPrevented&&!(e=>{let t=e.composedPath()[0];return t instanceof Element&&null!==t.closest(G)})(e)){if(e.preventDefault(),f?.We()&&f.be())return;ne(!d.l,!0)}},de=e=>{if(D.w(e)||s.has(e))return;let t=window.getSelection();t&&!t.isCollapsed||ie()},ce=()=>{n.t.style.setProperty("--pu-pop",`${St()}px`);let t=An(e.root,"column"===d.mode);t!==d.mode?(d.mode=t,ae()):Y()};function ue(){let e=performance.now();0===g&&(w=e),window.clearTimeout(g);let t=Math.min(120,Math.max(0,w+1e3-e));g=window.setTimeout(()=>{g=0,F(),Y()},t)}let pe=new MutationObserver(e=>{e.every(e=>n.element.contains(e.target))||ue()});window.addEventListener("keydown",se),window.addEventListener("click",de),window.addEventListener("resize",ce),pe.observe(e.root,{subtree:!0,childList:!0,characterData:!0});let he=new MutationObserver(()=>$n(n.t,Mn(e.root)));for(let e of[document.documentElement,document.body])he.observe(e,{attributes:!0});let me=new ResizeObserver(ue);me.observe(e.root);let ve=e.doc.onChange((e,t,n)=>{R.Oe(t,n),F(),Y()});return F(),ae(),b=requestAnimationFrame(le),{ctx:D,destroy(){m=!0,cancelAnimationFrame(b),cancelAnimationFrame(W),cancelAnimationFrame(M),S.destroy(),window.clearTimeout(V),window.clearTimeout(v),window.clearTimeout(g),window.clearTimeout(y),pe.disconnect(),me.disconnect(),he.disconnect(),ve(),window.removeEventListener("keydown",se),window.removeEventListener("click",de),window.removeEventListener("resize",ce),f?.destroy();for(let e of h)e.destroy();R.destroy(),o.remove(),n.destroy()}}}var Nn=null;function qn(e={}){if(pt)return pt.mount(e);if(!function(){if(pt)return!0;let e=globalThis,t=e.pipeupAddons;if(Array.isArray(t))for(let e of t)ft(e);else if(t&&"object"==typeof t&&t.push!==ft)return!1;return e.pipeupAddons={push:ft},!0}())return Promise.reject(new Error("pipeup: another copy of Pipeup owns the add-on queue. Remove one script."));if(Nn)return Nn;let t=async function(e,t){let n,o,i=document.documentElement.getAttribute("data-pipeup-doc"),{id:a,key:l}=i?await H(i):{id:`page-${r(location.origin+location.pathname)}`,key:null},s=!1;if(e.store)n=e.store,o=await G(n);else try{let e=J.open();n=await function(e){return new Promise((t,n)=>{let o=setTimeout(()=>n(new Error("timed out")),4e3);e.then(t,n).finally(()=>clearTimeout(o))})}(e).catch(t=>{throw e.then(e=>e.close(),()=>{}),t}),o=await G(n)}catch{n=new U,s=!0,o=await G(n)}let d=e.name?.trim();d&&d!==o.name&&(o={...o,name:d},await n.saveProfile(o));let c,u=await K.open({doc:a,key:l,store:n,identity:o.identity,name:o.name});fn(e.slides??null);try{c=Pn({doc:u,root:e.root??document.body,onName:async e=>{u.name=e,o={...o,name:e},await n.saveProfile(o)}})}catch(e){throw fn(null),e}s&&c.ctx.J("This browser can't keep comments for this page — copy the comments (Copy as Markdown) to keep them");let p=()=>{u.flush().catch(e=>globalThis.reportError?.(e))},h=function(e){let t={...e,i:!0};ut=t;for(let e of ct.values())"waiting"===e.info.state&&mt(e,t);return()=>{t.i=!1,ut===t&&(ut=null);for(let e of[...ct.values()].reverse())e.stop?.(),delete e.stop;e.surface.destroy()}}({surface:c.ctx.addons,doc:u,root:e.root??document.body,ephemeral:s,version:Ne}),f=!1;return window.addEventListener("pagehide",p),{document:u,flush:()=>u.flush(),unmount:()=>{f||(f=!0,window.removeEventListener("pagehide",p),h(),c.destroy(),fn(null),Nn===t()&&(Nn=null))}}}(e,()=>t).catch(e=>{throw Nn===t&&(Nn=null),e});return Nn=t,t}export{rt as ADDON_API,O as AI_NAME,A as ANIMALS,C as COLOURS,_ as DEFAULT_PROFILE_NAME,J as IndexedDbStore,U as MemoryStore,K as PipeupDocument,j as UnsavedChangeError,Ne as VERSION,ht as addons,q as animalName,M as computeOpId,$e as copyAll,Me as copyThread,s as createIdentity,de as describeElement,se as describeRange,Le as formatAgo,D as isAiName,be as labelOf,G as loadOrCreateProfile,xe as locate,qn as mount,z as nameOf,F as newDocumentAttribute,hn as onReveal,H as parseDocumentAttribute,fe as resolveAnchor,pn as setViewState,g as signOp,ft as use};
|