pipeup 0.4.0-beta.1 → 0.4.0-beta.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.
@@ -1,9 +1,9 @@
1
- function se(e){let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function we(e){let t=e.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((e.length+3)%4),n=atob(t),o=new Uint8Array(n.length);for(let r=0;r<n.length;r++)o[r]=n.charCodeAt(r);return o}function Qt(e=16){return se(crypto.getRandomValues(new Uint8Array(e)))}function de(e){return new TextEncoder().encode(e)}function xe(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(xe).join(",")+"]";let t=e;return"{"+Object.keys(t).filter(n=>t[n]!==void 0).sort().map(n=>JSON.stringify(n)+":"+xe(t[n])).join(",")+"}"}function ye(e){return e.replace(/\s+/g," ").trim()}function be(e){let t=ye(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 io=/^[A-Za-z0-9_-]{43}$/,ao=512,Ee=new Map;async function St(){let e=await crypto.subtle.generateKey({name:"Ed25519"},!1,["sign","verify"]),t=new Uint8Array(await crypto.subtle.exportKey("raw",e.publicKey));return{publicKey:se(t),privateKey:e.privateKey}}async function Jt(e,t){let n=await crypto.subtle.sign({name:"Ed25519"},e.privateKey,t);return se(new Uint8Array(n))}async function en(e,t,n){if(!io.test(e))return!1;try{if(se(we(e))!==e)return!1;let o=Ee.get(e);if(!o){Ee.size>=ao&&Ee.delete(Ee.keys().next().value),o=crypto.subtle.importKey("raw",we(e),{name:"Ed25519"},!0,["verify"]),Ee.set(e,o);let r=o;r.catch(()=>{Ee.get(e)===r&&Ee.delete(e)})}return await crypto.subtle.verify({name:"Ed25519"},await o,we(n),t)}catch{return!1}}var ot=1e4,Lt=2**40,rt=2**47,z={doc:64,path:2e3,snapshot:500,anchorId:200,quote:1e4,context:64,viewEntries:16,viewKey:64,viewValue:200},so=/^[0-9a-f]{8}$/,At=/^[A-Za-z0-9_-]{43}$/,lo=/^[A-Za-z0-9_-]{43}$/,co=new Set(["create","reply","edit","delete","resolve","reopen"]);async function nn(e,t){if(e.author!==t.publicKey)throw new Error("pipeup: an op must be signed by its author");return{body:e,sig:await Jt(t,de(xe(e)))}}var ue=(e,t)=>typeof e=="string"&&e.length<=t,tn=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=1;function Mt(e){if(!e||typeof e!="object")return!1;let{id:t,path:n,fingerprint:o,snapshot:r,quote:i,point:s,view:a}=e;if(!ue(n,z.path)||!ue(r,z.snapshot)||typeof o!="string"||!so.test(o)||t!==void 0&&(!ue(t,z.anchorId)||t===""))return!1;if(i!==void 0){if(!i||typeof i!="object")return!1;let p=i;if(!ue(p.exact,z.quote)||p.exact===""||!ue(p.prefix,z.context)||!ue(p.suffix,z.context))return!1}if(s!==void 0){if(!s||typeof s!="object")return!1;let p=s;if(!tn(p.x)||!tn(p.y))return!1}if(a!==void 0){if(!a||typeof a!="object"||Array.isArray(a))return!1;let p=Object.entries(a);if(p.length>z.viewEntries||!p.every(([l,d])=>l.length<=z.viewKey&&ue(d,z.viewValue)))return!1}return!0}function on(e){if(!e||typeof e!="object")return!1;let{body:t,sig:n}=e;if(typeof n!="string"||!t||typeof t!="object")return!1;let o=t;return!(o.v!==1||typeof o.id!="string"||!At.test(o.id)||typeof o.kind!="string"||!co.has(o.kind)||!ue(o.doc,z.doc)||o.doc===""||typeof o.thread!="string"||!At.test(o.thread)||typeof o.author!="string"||!lo.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>Lt||typeof o.at!="number"||!Number.isSafeInteger(o.at)||o.at<0||o.at>rt||o.text!==void 0&&(!ue(o.text,ot)||o.text!==o.text.trim())||o.target!==void 0&&(typeof o.target!="string"||!At.test(o.target))||(o.kind==="create"||o.kind==="reply"||o.kind==="edit")&&(typeof o.text!="string"||o.text.trim()==="")||(o.kind==="reply"||o.kind==="edit"||o.kind==="delete")&&!o.target||o.kind==="create"&&(o.id!==o.thread||!Mt(o.anchor)))}function rn(e){return en(e.body.author,de(xe(e.body)),e.sig)}function an(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 ln(e){let t=new Map,n=new Map,o=new Map;for(let{body:r}of[...e].sort(an)){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 a=sn(r.id,r.author,r.name,r.text,r.at);t.set(r.id,{id:r.id,anchor:r.anchor,root:a,resolved:!1}),n.set(r.id,{comment:a,thread:r.id});continue}let i=t.get(r.thread);if(!i)continue;if(r.kind==="resolve"||r.kind==="reopen"){i.resolved=r.kind==="resolve";continue}let s=r.target?n.get(r.target):void 0;if(!(!s||s.thread!==r.thread)){if(r.kind==="reply"){if(n.has(r.id)||r.text===void 0)continue;let a=sn(r.id,r.author,r.name,r.text,r.at);i.root.replies.push(a),n.set(r.id,{comment:a,thread:r.thread});continue}r.author!==s.comment.author||s.comment.deleted||(r.kind==="edit"&&r.text!==void 0&&(s.comment.text=r.text,s.comment.edited=!0),r.kind==="delete"&&(s.comment.text="",s.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 sn(e,t,n,o,r){return{id:e,author:t,name:n,text:o,at:r,edited:!1,deleted:!1,replies:[]}}async function Ct(e){let t={...e,id:void 0,thread:e.kind==="create"?void 0:e.thread},n=await crypto.subtle.digest("SHA-256",de(xe(t)));return se(new Uint8Array(n))}var it=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 ln(this.ops.values())}async add(t){let n=[];for(let o of t)!on(o)||o.body.doc!==this.doc||this.ops.has(o.body.id)||o.body.id!==await Ct(o.body)||!await rn(o)||(this.ops.set(o.body.id,o),this.clock=Math.max(this.clock,o.body.clock),o.body.kind==="create"&&this.createAt.set(o.body.author,Math.max(this.createAt.get(o.body.author)??0,o.body.at)),this.threadAt.set(o.body.thread,Math.max(this.threadAt.get(o.body.thread)??0,o.body.at)),n.push(o));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,Lt),at:Math.min(Math.max(Date.now(),o.kind==="create"?(this.createAt.get(t.publicKey)??0)+1:(this.threadAt.get(o.thread)??0)+1),rt)};for(let a=0;;a++){if(a===1e3)throw new Error("pipeup: could not record this change");if(r.id=await Ct(r),!this.ops.has(r.id)||r.at>=rt)break;r.at+=1}let i=this.ops.get(r.id);if(i)return i;r.kind==="create"&&(r.thread=r.id);let[s]=await this.add([await nn(r,t)]);if(!s)throw new Error("pipeup: could not record this change");return s}};var po=/^([A-Za-z0-9_-]{16}):([A-Za-z0-9_-]{43})$/;function uo(){return`${Qt(12)}:${se(crypto.getRandomValues(new Uint8Array(32)))}`}async function Pt(e){let t=po.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",we(o),{name:"AES-GCM"},!1,["encrypt","decrypt"]);return{id:n,key:r}}async function cn(e,t,n){let o=crypto.getRandomValues(new Uint8Array(12)),r=await crypto.subtle.encrypt({name:"AES-GCM",iv:o,additionalData:de(n)},e,de(t));return{iv:se(o),data:se(new Uint8Array(r))}}async function pn(e,t,n){try{let o=await crypto.subtle.decrypt({name:"AES-GCM",iv:we(t.iv),additionalData:de(n)},e,we(t.data));return new TextDecoder().decode(o)}catch{throw new Error("pipeup: this feedback could not be opened with this document")}}var mo=5e6,dn=e=>`pipeup-file:${e}`;async function un(e,t,n){let o=n?{pipeup:1,doc:e,sealed:!0,...await cn(n,JSON.stringify(t),dn(e))}:{pipeup:1,doc:e,sealed:!1,ops:t};return JSON.stringify(o,null,2)}async function mn(e,t,n){if(e.length>mo)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 pn(n,{iv:o.iv,data:o.data},dn(t))}catch{throw new Error("pipeup: this feedback could not be opened with this document's key")}let i;try{i=JSON.parse(r)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}return Array.isArray(i)?i:[]}var fn=80,le=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"}},qe=class e{constructor(t,n){this.log=t;this.options=n;this.displayName=n.name.trim()?hn(n.name):""}listeners=new Set;cache=[];comments=new Map;displayName;queue=Promise.resolve();unsaved=[];static async open(t){if(typeof t.doc!="string"||t.doc===""||t.doc.length>z.doc)throw new Error(`pipeup: the document id must be 1 to ${z.doc} characters`);let n=new it(t.doc);await n.add(await t.store.load(t.doc));let o=new e(n,t);return o.refresh(!1),o}get id(){return this.options.doc}get me(){return this.options.identity.publicKey}get name(){return this.displayName}set name(t){this.displayName=hn(t),this.refresh(!0)}threads(){return this.cache}onChange(t){return this.listeners.add(t),()=>this.listeners.delete(t)}comment(t,n){return this.enqueue(()=>this.write({kind:"create",anchor:t,text:Ot(n)}))}reply(t,n){return this.enqueue(()=>this.write({kind:"reply",thread:this.find(t).thread,target:t,text:Ot(n)}))}edit(t,n){return this.enqueue(async()=>{let{thread:o}=this.mine(t);await this.write({kind:"edit",thread:o,target:t,text:Ot(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)})})}flush(){return this.enqueue(()=>this.persist())}exportFile(){return un(this.options.doc,this.log.all(),this.options.key)}importFile(t){return this.enqueue(async()=>{let n=await this.log.add(await mn(t,this.options.doc,this.options.key));this.unsaved.push(...n),n.length>0&&this.refresh(!0);try{await this.persist()}catch(o){throw n.length>0?new le(n[0].body.id,o,n.length):o}return n.length})}enqueue(t){let n=this.queue.then(t);return this.queue=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);try{await this.persist()}catch(o){throw new le(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){this.cache=this.log.threads(),this.comments.clear();let n=(o,r)=>{o.unnamed&&o.author===this.me&&this.displayName&&(o.name=this.displayName),this.comments.set(o.id,{comment:o,thread:r});for(let i of o.replies)n(i,r)};for(let o of this.cache)n(o.root,o.id);if(t)for(let o of this.listeners)try{o(this.cache)}catch(r){globalThis.reportError?.(r)}}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 Ot(e){let t=e.trim();if(!t)throw new Error("pipeup: a comment needs some words");if(t.length>ot)throw new Error(`pipeup: comments are limited to ${ot} characters`);return t}function hn(e){let t=e.replace(/\s+/g," ").trim();if(!t||t.length>fn)throw new Error(`pipeup: choose a name of 1 to ${fn} characters`);return t}var Ve=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}},gn="",fo="Reviewer";async function Ue(e,t=gn){let n=await e.loadProfile();if(n)return n.name===fo?{...n,name:""}:n;let o={identity:await St(),name:t};return e.saveProfileIfAbsent(o)}var Ke=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 i=r.result;i.createObjectStore("ops",{keyPath:["doc","id"]}).createIndex("doc","doc"),i.createObjectStore("meta")},r.onsuccess=()=>{let i=r.result;i.onversionchange=()=>i.close(),n(new e(i))},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"),i=ho(o);try{for(let s of n)r.put({doc:t,id:s.body.id,op:s})}catch(s){throw o.abort(),i.catch(()=>{}),s}await i}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){return new Promise((n,o)=>{let r=this.db.transaction("meta","readwrite"),i=r.objectStore("meta"),s=t;r.oncomplete=()=>n(s),r.onerror=()=>o(r.error??new Error("pipeup: local storage write failed")),r.onabort=()=>o(r.error??new Error("pipeup: local storage write aborted"));let a=i.get("profile");a.onsuccess=()=>{a.result?s=a.result:i.put(t,"profile")}})}request(t,n,o){return new Promise((r,i)=>{let s=o(this.db.transaction(t,n).objectStore(t));s.onsuccess=()=>r(s.result),s.onerror=()=>i(s.error??new Error("pipeup: local storage request failed"))})}};function ho(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 ze(e){let n=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_TEXT),o=[],r="";for(let i=n.nextNode();i;i=n.nextNode())o.push({node:i,start:r.length}),r+=i.data;return{text:r,nodes:o}}function Rt(e,t,n){let r=(e.ownerDocument??e).createRange();return r.setStart(e,0),r.setEnd(t,n),r.toString().length}function It(e,t,n){let o=vn(e,t,!1),r=vn(e,n,!0);if(!o||!r||n<t)return null;let i=o.node.ownerDocument.createRange();return i.setStart(o.node,o.offset),i.setEnd(r.node,r.offset),i}function vn(e,t,n){for(let r of e.nodes){let i=r.start+r.node.data.length;if(t>=r.start&&(t<i||n&&t===i))return{node:r.node,offset:t-r.start}}let o=e.nodes[e.nodes.length-1];return o&&t===o.start+o.node.data.length?{node:o.node,offset:o.node.data.length}:null}var wn=32,bn=200,go="p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,pre,figcaption,dt,dd,summary,caption";function xn(e){return e.nodeType===Node.ELEMENT_NODE?e:e.parentElement}function En(e,t){for(let n=xn(e)?.closest("[data-pipeup-id]")??null;n;){if(!t.contains(n))return null;let o=n.getAttribute("data-pipeup-id")??"";if(o!==""&&o.length<=z.anchorId)return n;n=n.parentElement?.closest("[data-pipeup-id]")??null}return null}function vo(e){let t=e;return/[\uD800-\uDBFF]$/.test(t)&&(t=t.slice(0,-1)),/^[\uDC00-\uDFFF]/.test(t)&&(t=t.slice(1)),t}function at(e,t,n){return vo(e.slice(t,n))}function wo(e,t){let n=yo(e,t);if(n.length>z.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 kn(e){if(!Mt(e))throw new Error("pipeup: could not describe this place on the page");return e}function st(e,t){let n=xn(e),o=n?.closest(go)??null;return o&&t.contains(o)?o:n&&t.contains(n)?n:t}function yo(e,t){if(e===t)return"";let n=[];for(let o=t;o&&o!==e;o=o.parentElement){let r=1;for(let i=o.previousElementSibling;i;i=i.previousElementSibling)i.tagName===o.tagName&&r++;n.unshift(`${o.tagName.toLowerCase()}:nth-of-type(${r})`)}return":scope > "+n.join(" > ")}function Nt(e,t,n){if(!t.contains(e.commonAncestorContainer))throw new Error("pipeup: the selection is outside the commentable area");let o=En(e.commonAncestorContainer,t),r=o??t,{text:i}=ze(r),s=Rt(r,e.startContainer,e.startOffset),a=Rt(r,e.endContainer,e.endOffset),p=i.slice(s,a);if(p==="")throw new Error("pipeup: select some text to comment on");if(p.length>z.quote)throw new Error(`pipeup: selections are limited to ${z.quote} characters`);let l=at(i,Math.max(0,s-wn),s),d=at(i,a,a+wn);return kn({...o?{id:o.getAttribute("data-pipeup-id")??""}:{},path:"",quote:{exact:p,prefix:l,suffix:d},...n?{view:n}:{},fingerprint:be(st(e.startContainer,t).textContent??""),snapshot:at(ye(l+p+d),0,bn)})}function lt(e,t,n,o){let r=En(e,t);return kn({...r?{id:r.getAttribute("data-pipeup-id")??""}:{},path:wo(r??t,e),...n?{point:{x:yn(n.x),y:yn(n.y)}}:{},...o?{view:o}:{},fingerprint:be(e.textContent??""),snapshot:at(ye(e.textContent??""),0,bn)})}function yn(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function bo(e,t){let n=Array.from({length:t.length+1},(r,i)=>i),o=new Array(t.length+1).fill(0);for(let r=1;r<=e.length;r++){o[0]=r;for(let i=1;i<=t.length;i++){let s=e.charCodeAt(r-1)===t.charCodeAt(i-1)?0:1;o[i]=Math.min((n[i]??0)+1,(o[i-1]??0)+1,(n[i-1]??0)+s)}[n,o]=[o,n]}return n[t.length]??0}function Tn(e,t,n){let o=t.length;if(o===0)return null;let r=Array.from({length:o+1},(d,y)=>y),i=new Array(o+1).fill(0),s=-1,a=1/0;for(let d=1;d<=e.length;d++){i[0]=0;let y=e.charCodeAt(d-1);for(let h=1;h<=o;h++){let x=t.charCodeAt(h-1)===y?0:1;i[h]=Math.min((r[h]??0)+1,(i[h-1]??0)+1,(r[h-1]??0)+x)}let E=i[o]??1/0;E<a&&(a=E,s=d),[r,i]=[i,r]}if(a>n)return null;let p=Math.max(0,s-o),l=1/0;for(let d=Math.max(0,s-o-n);d<=Math.min(s,s-o+n);d++){let y=bo(e.slice(d,s),t);y<l&&(l=y,p=d)}return{start:p,end:s,distance:l}}var We={state:"orphaned",element:null,range:null},xo=5e4,Eo=300,ko=12,To=":scope > ";function So(e,t){for(let n of e.querySelectorAll("[data-pipeup-id]"))if(n.getAttribute("data-pipeup-id")===t)return n;return null}function ct(e,t,n={}){let o=e.id?So(t,e.id):t;return e.quote?Lo(e,e.quote,o,t,n.fuzzy!==!1):Ao(e,o)}function Ao(e,t){if(!t)return We;let n=t;if(e.path){if(!e.path.startsWith(To))return We;try{n=t.querySelector(e.path)}catch{return We}}return n?{state:be(n.textContent??"")===e.fingerprint?"attached":"moved",element:n,range:null}:We}function Lo(e,t,n,o,r){let i=n??o,s=ze(i),a=Mo(s.text,t);if(a>=0){let p=It(s,a,a+t.exact.length);if(p){let l=st(p.startContainer,o);return{state:n!==null&&be(l.textContent??"")===e.fingerprint?"attached":"moved",element:l,range:p}}}if(r){let p=i===o?s:ze(o);if(p.text.length<=xo&&t.exact.length>=ko&&t.exact.length<=Eo){let l=Tn(p.text,t.exact,Math.floor(t.exact.length/4)),d=l?It(p,l.start,l.end):null;if(d)return{state:"moved",element:st(d.startContainer,o),range:d}}}return We}function Mo(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 i=e.slice(Math.max(0,r-t.prefix.length),r),s=e.slice(r+t.exact.length,r+t.exact.length+t.suffix.length),a=Po(i,t.prefix)+Co(s,t.suffix);a>o&&(n=r,o=a)}return n}function Co(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function Po(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 Oo={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"},Ro=40;function Re(e){let t=e.getAttribute("data-pipeup-label");if(t)return t;let n=Oo[e.tagName.toUpperCase()]??"Block",o=ye(e.getAttribute("aria-label")??e.getAttribute("alt")??e.innerText??e.textContent??"");return o?`${n} \xB7 ${$t(o,Ro)}`:n}function Dt(e,t,n){let o=e.id??null,r=e.quote?.exact??null,i=e.point?`${Math.round(e.point.x*100)}% across, ${Math.round(e.point.y*100)}% down the element`:null,s=t.element;if(t.state==="orphaned"||!s)return{where:`No longer on the page (it read: "${e.snapshot}")`,element:null,id:o,quote:r,pin:i};let a=[],p=e.view?.slide;if(p){let d=s.closest("[data-pipeup-slide]")?.querySelector("h1,h2,h3")?.textContent;a.push(`Slide ${p}`+(d?` "${$t(ye(d))}"`:""))}else{let d=Io(s,n);d&&a.push(`Section "${$t(ye(d.textContent??""))}"`)}let l=Re(s);return a.push(l),{where:a.join(" \u203A "),element:l,id:o,quote:r,pin:i}}function Io(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)&Node.DOCUMENT_POSITION_FOLLOWING)n=o;else break}return n}function $t(e,t=60){return e.length>t?e.slice(0,t-1)+"\u2026":e}var Ie=["Otter","Fox","Owl","Bear","Rabbit"],Bt=["Red","Orange","Yellow","Green","Teal","Blue","Purple","Pink","Brown","Grey"];function Sn(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 Ht=e=>Sn(e)%Ie.length,Ft=e=>Math.floor(Sn(e)/Ie.length)%Bt.length,me=e=>`${Bt[Ft(e)]} ${Ie[Ht(e)]}`,ie=e=>e.name||me(e.author);var No="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 Ne(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 _t(e,t,n,o){return t==="ai"?An(e,"## Comment thread",o,n):Ln(e)}function qt(e,t,n){let o=e.filter(a=>!a.thread.resolved);if(t==="text")return o.map(Ln).join(`
2
- `);let r=e.length-o.length,i=[`# Review comments: ${Z(n.title)}`,"",`- **Page:** ${Z(n.url)}`,`- **Exported:** ${n.exportedAt.toISOString()}`,`- **Open threads:** ${o.length}${r?` (${r} resolved, not included)`:""}`,"",No,"",""].join(`
3
- `),s=n.exportedAt.getTime();return i+o.map((a,p)=>An(a,`## Thread ${p+1}`,s)).join(`
4
- `)}function Z(e){return e.replace(/\s+/g," ").trim()}function An(e,t,n,o){let{thread:r,location:i}=e,s=r.root.replies.length,a=[`${t} \xB7 ${r.resolved?"resolved":"open"}`];if(a.push(`- **Thread:** ${r.id}`),o&&a.push(`- **Page:** ${Z(o)}`),a.push(`- **Where:** ${Z(i.where)}`),i.id){let p=Z(i.id.replace(/`/g,""));a.push(`- **Element:** \`[data-pipeup-id="${p}"]\`${i.element?` (${Z(i.element)})`:""}`)}i.quote&&a.push(`- **Quoted text:** "${Z(i.quote)}"`),i.pin&&a.push(`- **Pin:** ${Z(i.pin)}`),a.push(`- **Started by:** ${Z(ie(r.root))}, ${Ne(r.root.at,n)}${s?` \xB7 ${s} ${s===1?"reply":"replies"}`:""}`,"",`**${Z(ie(r.root))}** (${Ne(r.root.at,n)}): ${pt(r.root," ")}`);for(let p of r.root.replies)a.push(`- **${Z(ie(p))}** (${Ne(p.at,n)}): ${pt(p," ")} <!-- comment:${p.id} -->`);return a.join(`
1
+ function ce(e){let t="";for(let o of e)t+=String.fromCharCode(o);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function xe(e){let t=e.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((e.length+3)%4),o=atob(t),n=new Uint8Array(o.length);for(let r=0;r<o.length;r++)n[r]=o.charCodeAt(r);return n}function mn(e=16){return ce(crypto.getRandomValues(new Uint8Array(e)))}function fe(e){return new TextEncoder().encode(e)}function Te(e){if(e===null||typeof e!="object")return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(Te).join(",")+"]";let t=e;return"{"+Object.keys(t).filter(o=>t[o]!==void 0).sort().map(o=>JSON.stringify(o)+":"+Te(t[o])).join(",")+"}"}function Ee(e){return e.replace(/\s+/g," ").trim()}function ke(e){let t=Ee(e),o=2166136261;for(let n=0;n<t.length;n++)o^=t.charCodeAt(n),o=Math.imul(o,16777619)>>>0;return o.toString(16).padStart(8,"0")}var To=/^[A-Za-z0-9_-]{43}$/,Ao=512,Ae=new Map;async function Ht(){let e=await crypto.subtle.generateKey({name:"Ed25519"},!1,["sign","verify"]),t=new Uint8Array(await crypto.subtle.exportKey("raw",e.publicKey));return{publicKey:ce(t),privateKey:e.privateKey}}async function fn(e,t){let o=await crypto.subtle.sign({name:"Ed25519"},e.privateKey,t);return ce(new Uint8Array(o))}async function hn(e,t,o){if(!To.test(e))return!1;try{if(ce(xe(e))!==e)return!1;let n=Ae.get(e);if(!n){Ae.size>=Ao&&Ae.delete(Ae.keys().next().value),n=crypto.subtle.importKey("raw",xe(e),{name:"Ed25519"},!0,["verify"]),Ae.set(e,n);let r=n;r.catch(()=>{Ae.get(e)===r&&Ae.delete(e)})}return await crypto.subtle.verify({name:"Ed25519"},await n,xe(o),t)}catch{return!1}}var ft=1e4,Ft=2**40,ht=2**47,G={doc:64,path:2e3,snapshot:500,anchorId:200,quote:1e4,context:64,viewEntries:16,viewKey:64,viewValue:200},Lo=/^[0-9a-f]{8}$/,Bt=/^[A-Za-z0-9_-]{43}$/,Mo=/^[A-Za-z0-9_-]{43}$/,Co=new Set(["create","reply","edit","delete","resolve","reopen"]);async function vn(e,t){if(e.author!==t.publicKey)throw new Error("pipeup: an op must be signed by its author");return{body:e,sig:await fn(t,fe(Te(e)))}}var he=(e,t)=>typeof e=="string"&&e.length<=t,gn=e=>typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=1;function Vt(e){if(!e||typeof e!="object")return!1;let{id:t,path:o,fingerprint:n,snapshot:r,quote:i,point:a,view:s}=e;if(!he(o,G.path)||!he(r,G.snapshot)||typeof n!="string"||!Lo.test(n)||t!==void 0&&(!he(t,G.anchorId)||t===""))return!1;if(i!==void 0){if(!i||typeof i!="object")return!1;let d=i;if(!he(d.exact,G.quote)||d.exact===""||!he(d.prefix,G.context)||!he(d.suffix,G.context))return!1}if(a!==void 0){if(!a||typeof a!="object")return!1;let d=a;if(!gn(d.x)||!gn(d.y))return!1}if(s!==void 0){if(!s||typeof s!="object"||Array.isArray(s))return!1;let d=Object.entries(s);if(d.length>G.viewEntries||!d.every(([c,p])=>c.length<=G.viewKey&&he(p,G.viewValue)))return!1}return!0}function wn(e){if(!e||typeof e!="object")return!1;let{body:t,sig:o}=e;if(typeof o!="string"||!t||typeof t!="object")return!1;let n=t;return!(n.v!==1||typeof n.id!="string"||!Bt.test(n.id)||typeof n.kind!="string"||!Co.has(n.kind)||!he(n.doc,G.doc)||n.doc===""||typeof n.thread!="string"||!Bt.test(n.thread)||typeof n.author!="string"||!Mo.test(n.author)||typeof n.name!="string"||n.name.length>80||n.name!==n.name.trim()||typeof n.clock!="number"||!Number.isSafeInteger(n.clock)||n.clock<1||n.clock>Ft||typeof n.at!="number"||!Number.isSafeInteger(n.at)||n.at<0||n.at>ht||n.text!==void 0&&(!he(n.text,ft)||n.text!==n.text.trim())||n.target!==void 0&&(typeof n.target!="string"||!Bt.test(n.target))||(n.kind==="create"||n.kind==="reply"||n.kind==="edit")&&(typeof n.text!="string"||n.text.trim()==="")||(n.kind==="reply"||n.kind==="edit"||n.kind==="delete")&&!n.target||n.kind==="create"&&(n.id!==n.thread||!Vt(n.anchor)))}function yn(e){return hn(e.body.author,fe(Te(e.body)),e.sig)}function bn(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 En(e){let t=new Map,o=new Map,n=new Map;for(let{body:r}of[...e].sort(bn)){if(r.name&&n.set(r.author,r.name),r.kind==="create"){if(t.has(r.id)||!r.anchor||r.text===void 0)continue;let s=xn(r.id,r.author,r.name,r.text,r.at);t.set(r.id,{id:r.id,anchor:r.anchor,root:s,resolved:!1}),o.set(r.id,{comment:s,thread:r.id});continue}let i=t.get(r.thread);if(!i)continue;if(r.kind==="resolve"||r.kind==="reopen"){i.resolved=r.kind==="resolve";continue}let a=r.target?o.get(r.target):void 0;if(!(!a||a.thread!==r.thread)){if(r.kind==="reply"){if(o.has(r.id)||r.text===void 0)continue;let s=xn(r.id,r.author,r.name,r.text,r.at);i.root.replies.push(s),o.set(r.id,{comment:s,thread:r.thread});continue}r.author!==a.comment.author||a.comment.deleted||(r.kind==="edit"&&r.text!==void 0&&(a.comment.text=r.text,a.comment.edited=!0),r.kind==="delete"&&(a.comment.text="",a.comment.deleted=!0))}}for(let{comment:r}of o.values())r.name||(r.unnamed=!0,r.name=n.get(r.author)??"");return[...t.values()]}function xn(e,t,o,n,r){return{id:e,author:t,name:o,text:n,at:r,edited:!1,deleted:!1,replies:[]}}async function _t(e){let t={...e,id:void 0,thread:e.kind==="create"?void 0:e.thread},o=await crypto.subtle.digest("SHA-256",fe(Te(t)));return ce(new Uint8Array(o))}var gt=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 En(this.ops.values())}async add(t){let o=[];for(let n of t)!wn(n)||n.body.doc!==this.doc||this.ops.has(n.body.id)||n.body.id!==await _t(n.body)||!await yn(n)||(this.ops.set(n.body.id,n),this.clock=Math.max(this.clock,n.body.clock),n.body.kind==="create"&&this.createAt.set(n.body.author,Math.max(this.createAt.get(n.body.author)??0,n.body.at)),this.threadAt.set(n.body.thread,Math.max(this.threadAt.get(n.body.thread)??0,n.body.at)),o.push(n));return o}async append(t,o,n){let r={v:1,...n,id:"",thread:n.kind==="create"?"":n.thread,doc:this.doc,author:t.publicKey,name:o,clock:Math.min(this.clock+1,Ft),at:Math.min(Math.max(Date.now(),n.kind==="create"?(this.createAt.get(t.publicKey)??0)+1:(this.threadAt.get(n.thread)??0)+1),ht)};for(let s=0;;s++){if(s===1e3)throw new Error("pipeup: could not record this change");if(r.id=await _t(r),!this.ops.has(r.id)||r.at>=ht)break;r.at+=1}let i=this.ops.get(r.id);if(i)return i;r.kind==="create"&&(r.thread=r.id);let[a]=await this.add([await vn(r,t)]);if(!a)throw new Error("pipeup: could not record this change");return a}};var Po=/^([A-Za-z0-9_-]{16}):([A-Za-z0-9_-]{43})$/;function Oo(){return`${mn(12)}:${ce(crypto.getRandomValues(new Uint8Array(32)))}`}async function qt(e){let t=Po.exec(e.trim()),o=t?.[1],n=t?.[2];if(!o||!n)throw new Error('pipeup: data-pipeup-doc must look like "<id>:<key>", as made by newDocumentAttribute()');let r=await crypto.subtle.importKey("raw",xe(n),{name:"AES-GCM"},!1,["encrypt","decrypt"]);return{id:o,key:r}}async function kn(e,t,o){let n=crypto.getRandomValues(new Uint8Array(12)),r=await crypto.subtle.encrypt({name:"AES-GCM",iv:n,additionalData:fe(o)},e,fe(t));return{iv:ce(n),data:ce(new Uint8Array(r))}}async function Sn(e,t,o){try{let n=await crypto.subtle.decrypt({name:"AES-GCM",iv:xe(t.iv),additionalData:fe(o)},e,xe(t.data));return new TextDecoder().decode(n)}catch{throw new Error("pipeup: this feedback could not be opened with this document")}}var Ro=5e6,Tn=e=>`pipeup-file:${e}`;async function An(e,t,o){let n=o?{pipeup:1,doc:e,sealed:!0,...await kn(o,JSON.stringify(t),Tn(e))}:{pipeup:1,doc:e,sealed:!1,ops:t};return JSON.stringify(n,null,2)}async function Ln(e,t,o){if(e.length>Ro)throw new Error("pipeup: this feedback file is too large");let n;try{n=JSON.parse(e)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}if(!n||typeof n!="object"||n.pipeup!==1||typeof n.doc!="string")throw new Error("pipeup: this is not an Pipeup feedback file");if(n.doc!==t)throw new Error("pipeup: this feedback is for a different document");if(!n.sealed)return Array.isArray(n.ops)?n.ops:[];if(!o)throw new Error("pipeup: this feedback is sealed, and this page has no document key");if(typeof n.iv!="string"||typeof n.data!="string")throw new Error("pipeup: this is not an Pipeup feedback file");let r;try{r=await Sn(o,{iv:n.iv,data:n.data},Tn(t))}catch{throw new Error("pipeup: this feedback could not be opened with this document's key")}let i;try{i=JSON.parse(r)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}return Array.isArray(i)?i:[]}var Mn=80,de=class extends Error{constructor(o,n,r=1){super("pipeup: shown here, but not saved yet");this.id=o;this.cause=n;this.count=r;this.name="UnsavedChangeError"}},je=class e{constructor(t,o){this.log=t;this.options=o;this.displayName=o.name.trim()?Cn(o.name):""}listeners=new Set;cache=[];comments=new Map;displayName;queue=Promise.resolve();unsaved=[];static async open(t){if(typeof t.doc!="string"||t.doc===""||t.doc.length>G.doc)throw new Error(`pipeup: the document id must be 1 to ${G.doc} characters`);let o=new gt(t.doc);await o.add(await t.store.load(t.doc));let n=new e(o,t);return n.refresh(!1),n}get id(){return this.options.doc}get me(){return this.options.identity.publicKey}get name(){return this.displayName}set name(t){this.displayName=Cn(t),this.refresh(!0)}threads(){return this.cache}onChange(t){return this.listeners.add(t),()=>this.listeners.delete(t)}comment(t,o){return this.enqueue(()=>this.write({kind:"create",anchor:t,text:Ut(o)}))}reply(t,o){return this.enqueue(()=>this.write({kind:"reply",thread:this.find(t).thread,target:t,text:Ut(o)}))}edit(t,o){return this.enqueue(async()=>{let{thread:n}=this.mine(t);await this.write({kind:"edit",thread:n,target:t,text:Ut(o)})})}remove(t){return this.enqueue(async()=>{let{thread:o}=this.mine(t);await this.write({kind:"delete",thread:o,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)})})}flush(){return this.enqueue(()=>this.persist())}exportFile(){return An(this.options.doc,this.log.all(),this.options.key)}importFile(t){return this.enqueue(async()=>{let o=await this.log.add(await Ln(t,this.options.doc,this.options.key));this.unsaved.push(...o),o.length>0&&this.refresh(!0);try{await this.persist()}catch(n){throw o.length>0?new de(o[0].body.id,n,o.length):n}return o.length})}enqueue(t){let o=this.queue.then(t);return this.queue=o.catch(()=>{}),o}async write(t){let o=await this.log.append(this.options.identity,this.displayName,t);this.unsaved.push(o),this.refresh(!0);try{await this.persist()}catch(n){throw new de(o.body.id,n)}return o.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(o=>!t.includes(o))}refresh(t){this.cache=this.log.threads(),this.comments.clear();let o=(n,r)=>{n.unnamed&&n.author===this.me&&this.displayName&&(n.name=this.displayName),this.comments.set(n.id,{comment:n,thread:r});for(let i of n.replies)o(i,r)};for(let n of this.cache)o(n.root,n.id);if(t)for(let n of this.listeners)try{n(this.cache)}catch(r){globalThis.reportError?.(r)}}find(t){let o=this.comments.get(t);if(!o)throw new Error("pipeup: there is no comment with that id");return o}mine(t){let o=this.find(t);if(o.comment.author!==this.me)throw new Error("pipeup: only the writer can change a comment");return o}thread(t){if(!this.cache.some(o=>o.id===t))throw new Error("pipeup: there is no thread with that id");return t}};function Ut(e){let t=e.trim();if(!t)throw new Error("pipeup: a comment needs some words");if(t.length>ft)throw new Error(`pipeup: comments are limited to ${ft} characters`);return t}function Cn(e){let t=e.replace(/\s+/g," ").trim();if(!t||t.length>Mn)throw new Error(`pipeup: choose a name of 1 to ${Mn} characters`);return t}var Ye=class{docs=new Map;profile=null;async load(t){return[...this.docs.get(t)?.values()??[]]}async append(t,o){let n=this.docs.get(t);n||this.docs.set(t,n=new Map);for(let r of o)n.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}},Pn="",Io="Reviewer";async function Ge(e,t=Pn){let o=await e.loadProfile();if(o)return o.name===Io?{...o,name:""}:o;let n={identity:await Ht(),name:t};return e.saveProfileIfAbsent(n)}var Xe=class e{constructor(t){this.db=t}static open(t="pipeup"){return new Promise((o,n)=>{let r=indexedDB.open(t,1);r.onupgradeneeded=()=>{let i=r.result;i.createObjectStore("ops",{keyPath:["doc","id"]}).createIndex("doc","doc"),i.createObjectStore("meta")},r.onsuccess=()=>{let i=r.result;i.onversionchange=()=>i.close(),o(new e(i))},r.onerror=()=>n(r.error??new Error("pipeup: could not open local storage"))})}close(){this.db.close()}async load(t){return(await this.request("ops","readonly",n=>n.index("doc").getAll(t))).map(n=>n.op)}async append(t,o){if(o.length===0)return;let n=this.db.transaction("ops","readwrite"),r=n.objectStore("ops"),i=No(n);try{for(let a of o)r.put({doc:t,id:a.body.id,op:a})}catch(a){throw n.abort(),i.catch(()=>{}),a}await i}async loadProfile(){return await this.request("meta","readonly",t=>t.get("profile"))??null}async saveProfile(t){await this.request("meta","readwrite",o=>o.put(t,"profile"))}async saveProfileIfAbsent(t){return new Promise((o,n)=>{let r=this.db.transaction("meta","readwrite"),i=r.objectStore("meta"),a=t;r.oncomplete=()=>o(a),r.onerror=()=>n(r.error??new Error("pipeup: local storage write failed")),r.onabort=()=>n(r.error??new Error("pipeup: local storage write aborted"));let s=i.get("profile");s.onsuccess=()=>{s.result?a=s.result:i.put(t,"profile")}})}request(t,o,n){return new Promise((r,i)=>{let a=n(this.db.transaction(t,o).objectStore(t));a.onsuccess=()=>r(a.result),a.onerror=()=>i(a.error??new Error("pipeup: local storage request failed"))})}};function No(e){return new Promise((t,o)=>{e.oncomplete=()=>t(),e.onerror=()=>o(e.error??new Error("pipeup: local storage write failed")),e.onabort=()=>o(e.error??new Error("pipeup: local storage write aborted"))})}function Je(e){let o=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[],r="";for(let i=o.nextNode();i;i=o.nextNode())n.push({node:i,start:r.length}),r+=i.data;return{text:r,nodes:n}}function zt(e,t,o){let r=(e.ownerDocument??e).createRange();return r.setStart(e,0),r.setEnd(t,o),r.toString().length}function Kt(e,t,o){let n=On(e,t,!1),r=On(e,o,!0);if(!n||!r||o<t)return null;let i=n.node.ownerDocument.createRange();return i.setStart(n.node,n.offset),i.setEnd(r.node,r.offset),i}function On(e,t,o){for(let r of e.nodes){let i=r.start+r.node.data.length;if(t>=r.start&&(t<i||o&&t===i))return{node:r.node,offset:t-r.start}}let n=e.nodes[e.nodes.length-1];return n&&t===n.start+n.node.data.length?{node:n.node,offset:n.node.data.length}:null}var Rn=32,Nn=200,$o="p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,pre,figcaption,dt,dd,summary,caption";function $n(e){return e.nodeType===Node.ELEMENT_NODE?e:e.parentElement}function Dn(e,t){for(let o=$n(e)?.closest("[data-pipeup-id]")??null;o;){if(!t.contains(o))return null;let n=o.getAttribute("data-pipeup-id")??"";if(n!==""&&n.length<=G.anchorId)return o;o=o.parentElement?.closest("[data-pipeup-id]")??null}return null}function Do(e){let t=e;return/[\uD800-\uDBFF]$/.test(t)&&(t=t.slice(0,-1)),/^[\uDC00-\uDFFF]/.test(t)&&(t=t.slice(1)),t}function vt(e,t,o){return Do(e.slice(t,o))}function Ho(e,t){let o=Bo(e,t);if(o.length>G.path)throw new Error("pipeup: this element is nested too deeply to comment on \u2014 give a nearby container a data-pipeup-id");return o}function Hn(e){if(!Vt(e))throw new Error("pipeup: could not describe this place on the page");return e}function wt(e,t){let o=$n(e),n=o?.closest($o)??null;return n&&t.contains(n)?n:o&&t.contains(o)?o:t}function Bo(e,t){if(e===t)return"";let o=[];for(let n=t;n&&n!==e;n=n.parentElement){let r=1;for(let i=n.previousElementSibling;i;i=i.previousElementSibling)i.tagName===n.tagName&&r++;o.unshift(`${n.tagName.toLowerCase()}:nth-of-type(${r})`)}return":scope > "+o.join(" > ")}function Wt(e,t,o){if(!t.contains(e.commonAncestorContainer))throw new Error("pipeup: the selection is outside the commentable area");let n=Dn(e.commonAncestorContainer,t),r=n??t,{text:i}=Je(r),a=zt(r,e.startContainer,e.startOffset),s=zt(r,e.endContainer,e.endOffset),d=i.slice(a,s);if(d==="")throw new Error("pipeup: select some text to comment on");if(d.length>G.quote)throw new Error(`pipeup: selections are limited to ${G.quote} characters`);let c=vt(i,Math.max(0,a-Rn),a),p=vt(i,s,s+Rn);return Hn({...n?{id:n.getAttribute("data-pipeup-id")??""}:{},path:"",quote:{exact:d,prefix:c,suffix:p},...o?{view:o}:{},fingerprint:ke(wt(e.startContainer,t).textContent??""),snapshot:vt(Ee(c+d+p),0,Nn)})}function yt(e,t,o,n){let r=Dn(e,t);return Hn({...r?{id:r.getAttribute("data-pipeup-id")??""}:{},path:Ho(r??t,e),...o?{point:{x:In(o.x),y:In(o.y)}}:{},...n?{view:n}:{},fingerprint:ke(e.textContent??""),snapshot:vt(Ee(e.textContent??""),0,Nn)})}function In(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function Fo(e,t){let o=Array.from({length:t.length+1},(r,i)=>i),n=new Array(t.length+1).fill(0);for(let r=1;r<=e.length;r++){n[0]=r;for(let i=1;i<=t.length;i++){let a=e.charCodeAt(r-1)===t.charCodeAt(i-1)?0:1;n[i]=Math.min((o[i]??0)+1,(n[i-1]??0)+1,(o[i-1]??0)+a)}[o,n]=[n,o]}return o[t.length]??0}function Bn(e,t,o){let n=t.length;if(n===0)return null;let r=Array.from({length:n+1},(p,x)=>x),i=new Array(n+1).fill(0),a=-1,s=1/0;for(let p=1;p<=e.length;p++){i[0]=0;let x=e.charCodeAt(p-1);for(let f=1;f<=n;f++){let S=t.charCodeAt(f-1)===x?0:1;i[f]=Math.min((r[f]??0)+1,(i[f-1]??0)+1,(r[f-1]??0)+S)}let T=i[n]??1/0;T<s&&(s=T,a=p),[r,i]=[i,r]}if(s>o)return null;let d=Math.max(0,a-n),c=1/0;for(let p=Math.max(0,a-n-o);p<=Math.min(a,a-n+o);p++){let x=Fo(e.slice(p,a),t);x<c&&(c=x,d=p)}return{start:d,end:a,distance:c}}var Ze={state:"orphaned",element:null,range:null},Vo=5e4,_o=300,qo=12,Uo=":scope > ";function zo(e,t){for(let o of e.querySelectorAll("[data-pipeup-id]"))if(o.getAttribute("data-pipeup-id")===t)return o;return null}function bt(e,t,o={}){let n=e.id?zo(t,e.id):t;return e.quote?Wo(e,e.quote,n,t,o.fuzzy!==!1):Ko(e,n)}function Ko(e,t){if(!t)return Ze;let o=t;if(e.path){if(!e.path.startsWith(Uo))return Ze;try{o=t.querySelector(e.path)}catch{return Ze}}return o?{state:ke(o.textContent??"")===e.fingerprint?"attached":"moved",element:o,range:null}:Ze}function Wo(e,t,o,n,r){let i=o??n,a=Je(i),s=jo(a.text,t);if(s>=0){let d=Kt(a,s,s+t.exact.length);if(d){let c=wt(d.startContainer,n);return{state:o!==null&&ke(c.textContent??"")===e.fingerprint?"attached":"moved",element:c,range:d}}}if(r){let d=i===n?a:Je(n);if(d.text.length<=Vo&&t.exact.length>=qo&&t.exact.length<=_o){let c=Bn(d.text,t.exact,Math.floor(t.exact.length/4)),p=c?Kt(d,c.start,c.end):null;if(p)return{state:"moved",element:wt(p.startContainer,n),range:p}}}return Ze}function jo(e,t){if(!t.exact)return-1;let o=-1,n=-1;for(let r=e.indexOf(t.exact);r!==-1;r=e.indexOf(t.exact,r+1)){let i=e.slice(Math.max(0,r-t.prefix.length),r),a=e.slice(r+t.exact.length,r+t.exact.length+t.suffix.length),s=Go(i,t.prefix)+Yo(a,t.suffix);s>n&&(o=r,n=s)}return o}function Yo(e,t){let o=0;for(;o<e.length&&o<t.length&&e[o]===t[o];)o++;return o}function Go(e,t){let o=0;for(;o<e.length&&o<t.length&&e[e.length-1-o]===t[t.length-1-o];)o++;return o}var Xo={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"},Jo=40;function Ne(e){let t=e.getAttribute("data-pipeup-label");if(t)return t;let o=Xo[e.tagName.toUpperCase()]??"Block",n=Ee(e.getAttribute("aria-label")??e.getAttribute("alt")??e.innerText??e.textContent??"");return n?`${o} \xB7 ${jt(n,Jo)}`:o}function Yt(e,t,o){let n=e.id??null,r=e.quote?.exact??null,i=e.point?`${Math.round(e.point.x*100)}% across, ${Math.round(e.point.y*100)}% down the element`:null,a=t.element;if(t.state==="orphaned"||!a)return{where:`No longer on the page (it read: "${e.snapshot}")`,element:null,id:n,quote:r,pin:i};let s=[],d=e.view?.slide;if(d){let p=a.closest("[data-pipeup-slide]")?.querySelector("h1,h2,h3")?.textContent;s.push(`Slide ${d}`+(p?` "${jt(Ee(p))}"`:""))}else{let p=xt(e.view);p&&s.push(p);let x=Zo(a,o);x&&s.push(`Section "${jt(Ee(x.textContent??""))}"`)}let c=Ne(a);return s.push(c),{where:s.join(" \u203A "),element:c,id:n,quote:r,pin:i}}function xt(e){return e?e.label||Object.entries(e).filter(([t,o])=>o&&t!=="slide").map(([,t])=>t).join(" \xB7 "):""}function Zo(e,t){let o=null;for(let n of t.querySelectorAll("h1,h2,h3")){if(n===e||n.contains(e))break;if(n.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING)o=n;else break}return o}function jt(e,t=60){return e.length>t?e.slice(0,t-1)+"\u2026":e}var $e=["Otter","Fox","Owl","Bear","Rabbit"],Gt=["Red","Orange","Yellow","Green","Teal","Blue","Purple","Pink","Brown","Grey"];function Fn(e){let t=2166136261;for(let o=0;o<e.length;o++)t=Math.imul(t^e.charCodeAt(o),16777619);return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),(t^t>>>16)>>>0}var Xt=e=>Fn(e)%$e.length,Jt=e=>Math.floor(Fn(e)/$e.length)%Gt.length,ge=e=>`${Gt[Jt(e)]} ${$e[Xt(e)]}`,ie=e=>e.name||ge(e.author);var Qo="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 De(e,t){let o=Math.max(0,Math.round((t-e)/1e3));if(o<60)return"just now";let n=Math.round(o/60);if(n<60)return`${n}m ago`;let r=Math.round(n/60);return r<48?`${r}h ago`:`${Math.round(r/24)}d ago`}function Zt(e,t,o,n){return t==="ai"?Vn(e,"## Comment thread",n,o):_n(e)}function Qt(e,t,o){let n=e.filter(s=>!s.thread.resolved);if(t==="text")return n.map(_n).join(`
2
+ `);let r=e.length-n.length,i=[`# Review comments: ${te(o.title)}`,"",`- **Page:** ${te(o.url)}`,`- **Exported:** ${o.exportedAt.toISOString()}`,`- **Open threads:** ${n.length}${r?` (${r} resolved, not included)`:""}`,"",Qo,"",""].join(`
3
+ `),a=o.exportedAt.getTime();return i+n.map((s,d)=>Vn(s,`## Thread ${d+1}`,a)).join(`
4
+ `)}function te(e){return e.replace(/\s+/g," ").trim()}function Vn(e,t,o,n){let{thread:r,location:i}=e,a=r.root.replies.length,s=[`${t} \xB7 ${r.resolved?"resolved":"open"}`];if(s.push(`- **Thread:** ${r.id}`),n&&s.push(`- **Page:** ${te(n)}`),s.push(`- **Where:** ${te(i.where)}`),i.id){let d=te(i.id.replace(/`/g,""));s.push(`- **Element:** \`[data-pipeup-id="${d}"]\`${i.element?` (${te(i.element)})`:""}`)}i.quote&&s.push(`- **Quoted text:** "${te(i.quote)}"`),i.pin&&s.push(`- **Pin:** ${te(i.pin)}`),s.push(`- **Started by:** ${te(ie(r.root))}, ${De(r.root.at,o)}${a?` \xB7 ${a} ${a===1?"reply":"replies"}`:""}`,"",`**${te(ie(r.root))}** (${De(r.root.at,o)}): ${Et(r.root," ")}`);for(let d of r.root.replies)s.push(`- **${te(ie(d))}** (${De(d.at,o)}): ${Et(d," ")} <!-- comment:${d.id} -->`);return s.join(`
5
5
  `)+`
6
- `}function Ln(e){let{thread:t,location:n}=e,o=[Z(n.where)+(n.quote?`, on the text "${Z(n.quote)}"`:""),`${Z(ie(t.root))}: ${pt(t.root," ")}`];for(let r of t.root.replies)o.push(` ${Z(ie(r))}: ${pt(r," ")}`);return o.join(`
6
+ `}function _n(e){let{thread:t,location:o}=e,n=[te(o.where)+(o.quote?`, on the text "${te(o.quote)}"`:""),`${te(ie(t.root))}: ${Et(t.root," ")}`];for(let r of t.root.replies)n.push(` ${te(ie(r))}: ${Et(r," ")}`);return n.join(`
7
7
  `)+`
8
- `}function pt(e,t){return e.deleted?"(deleted)":e.text.replace(/\r\n|\r|\n/g,`
9
- `+t)+(e.edited?" (edited)":"")}var si="0.4.0-beta.1";function m(e,t={},...n){let o=document.createElement(e);for(let[r,i]of Object.entries(t))i===void 0||i===!1||(r==="class"?o.className=String(i):o.setAttribute(r,i===!0?"":i));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 fe(e,t){return e.length>t?e.slice(0,t-1)+"\u2026":e}function $e(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 $o=/\bhttps?:\/\/[^\s<>"'`]+/gi,Do=`.,;:!?'"]}`,Bo=2048,Ho=/[\u202A-\u202E\u2066-\u2069]/;function Fo(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(!Do.includes(r))break;o--}return e.slice(0,o)}function dt(e){let t=[],n=0;for(let o of e.matchAll($o)){if(o[0].length>Bo||Ho.test(o[0]))continue;let r=Fo(o[0]),i=o.index??0,s;try{let p=new URL(r);if(p.protocol!=="http:"&&p.protocol!=="https:")continue;s=p.href}catch{continue}i>n&&t.push(e.slice(n,i));let a=m("a",{href:s,target:"_blank",rel:"noopener noreferrer"},r);a.addEventListener("click",p=>p.stopPropagation()),t.push(a),n=i+r.length}return n<e.length&&t.push(e.slice(n)),t}var he={code:"KeyC",mods:{shift:!0,alt:!0,meta:!1,ctrl:!1},mac:{label:"\u21E7\u2325C",aria:"Shift+Alt+C"},other:{label:"Shift+Alt+C",aria:"Shift+Alt+C"}},Mn=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform),Ye=(Mn?he.mac:he.other).label,Vt=(Mn?he.mac:he.other).aria;function Cn(e){return e.code===he.code&&e.shiftKey===he.mods.shift&&e.altKey===he.mods.alt&&e.metaKey===he.mods.meta&&e.ctrlKey===he.mods.ctrl&&!e.repeat&&!e.getModifierState("AltGraph")}var Pn="http://www.w3.org/2000/svg",_o={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"],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 W(e,t=15,n){let o=Ut(_o[e],t);return n&&o.setAttribute("stroke-width",String(n)),o}function Ut(e,t){let n=document.createElementNS(Pn,"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,i]of Object.entries(o))n.setAttribute(r,i);for(let r of e){let i=document.createElementNS(Pn,"path");i.setAttribute("d",r),n.append(i)}return n}var ut=(e,t,n)=>`M${e} ${t}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 -${2*n} 0`,qo={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${ut(7.4,11.5,1.9)}${ut(12.8,11.5,1.9)}M11.3 14.6l.7 1 .7-1`,Bear:`${ut(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:`${ut(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 On(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 je=(e,t)=>On(t)||me(e);function ke(e,t){return m("span",{class:`av c${Ft(e)}`,"aria-hidden":"true","data-animal":me(e)},On(t)||Ut([qo[Ie[Ht(e)]]],24))}var Vo=320;function mt(e,t){setTimeout(()=>{e.remove(),t?.()},Vo)}function ft(e){return requestAnimationFrame(()=>{e.offsetWidth,e.classList.add("in")}),e}function ht(e){let t=m("textarea",{class:"input",rows:"1","aria-label":e.label}),n=m("button",{class:"send",type:"button","aria-label":"Send",title:"Send"},W("send")),o=m("div",{class:"row"},e.before,t,n),r=!1,i=()=>{n.classList.toggle("show",t.value.trim()!==""),t.style.height="auto",t.style.height=`${Math.max(27,t.scrollHeight)}px`},s=async()=>{let a=t.value.trim();if(!(!a||r)){r=!0;try{await e.onSend(a),t.value="",i()}catch{}finally{r=!1}}};return o.addEventListener("mousedown",a=>{a.target===t||n.contains(a.target)||(a.preventDefault(),t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}),t.addEventListener("input",i),t.addEventListener("keydown",a=>{a.stopPropagation(),a.key==="Enter"&&!a.shiftKey&&!a.isComposing?(a.preventDefault(),s()):a.key==="Escape"&&(a.preventDefault(),t.value="",i(),t.blur(),e.onCancel?.())}),n.addEventListener("click",a=>{a.stopPropagation(),s()}),{element:o,input:t,focus:()=>t.focus({preventScroll:!0}),clear:()=>{t.value="",i()}}}function Uo(e){let t=m("button",{class:"me",type:"button",tabindex:"-1","aria-hidden":"true"});t.addEventListener("mousedown",v=>v.preventDefault());let n=ht({label:"Comment",before:t,onSend:e.onSend,onCancel:e.onCancel}),o=m("div",{class:"say"}),r=m("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"}),i=m("div",{class:"nf"},r),s=m("div",{class:"you"},o,i),a="",p=!1,l=()=>{let v=e.name(),w=v?"change":"add your name";if(t.title=v?"Change your name":"Add your name",!t.lastChild||a!==v){let T=ke(e.me,v),A=t.lastChild;A?(ft(T),mt(A)):T.classList.add("in"),t.append(T),a=v}let L=m("button",{type:"button"},w);L.addEventListener("click",y),o.replaceChildren(m("span",{class:"nm"},v||`You're ${me(e.me)}`)," \xB7 ",L)},d=v=>{s.classList.toggle("naming",v),Q(o,v),Q(i,!v)};function y(v){v.stopPropagation(),r.value=e.name(),d(!0),r.focus({preventScroll:!0}),r.select()}let E=()=>{d(!1),n.focus()};t.addEventListener("click",y),r.addEventListener("keydown",v=>{if(v.stopPropagation(),v.key==="Escape")v.preventDefault(),E();else if(v.key==="Enter"){v.preventDefault();let w=r.value.trim();if(!w||w===e.name())return E();if(p)return;p=!0,e.rename(w).finally(()=>{p=!1,l(),E()})}}),l(),d(!1);let h=m("div",{class:"ctx"},e.label);return{element:m("div",{class:"draft"},h,n.element,s),caret:()=>{let{selectionStart:v,selectionEnd:w}=n.input;return()=>{n.focus(),n.input.setSelectionRange(v,w)}},hideLabel:v=>{h.hidden=v},setLabel:v=>{h.textContent=v},focus:()=>n.focus(),isEmpty:()=>n.input.value.trim()===""}}function gt(e,t){let n=Uo({label:t.label,me:e.doc.me,name:()=>e.menu.name(),rename:o=>e.menu.rename(o),onSend:o=>e.postDraft(o),onCancel:()=>e.cancelDraft()});return e.registerDraft(n),n}function vt(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 Ge(e){return e.range?[...e.range.getClientRects()]:[]}function Kt(e,t){let n=Ge(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 Xe(e,t){let n=Ge(t).at(-1);if(n)return{x:n.left,y:n.bottom,below:!0};let o=vt(e,t);return o?{...o,below:!1}:null}function Rn(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 In(e,t,n=10){let o=[...e].sort((a,p)=>a.want-p.want),r=new Array(o.length).fill(0),i=o.findIndex(a=>a.id===t),s=a=>o[a];if(i<0)o.forEach((a,p)=>{r[p]=p===0?a.want:Math.max(a.want,(r[p-1]??0)+s(p-1).height+n)});else{r[i]=s(i).want;for(let a=i+1;a<o.length;a++)r[a]=Math.max(s(a).want,(r[a-1]??0)+s(a-1).height+n);for(let a=i-1;a>=0;a--)r[a]=Math.min(s(a).want,(r[a+1]??0)-s(a).height-n)}return new Map(o.map((a,p)=>[a.id,r[p]??0]))}var Ze=320,Te=300,Ko=480,Se=()=>window.innerWidth<=Ko;function wt(e){let t=window.innerWidth;return{width:e&&!Se()?t-Ze:t,height:window.innerHeight}}function yt(e,t,n,o=12){let r,i;return e.below?(r=Math.min(e.x,n.width-t.width-o),i=e.y+8,i+t.height>n.height-o&&(i=e.y-t.height-40)):(r=e.x+14,r+t.width>n.width-o&&(r=e.x-t.width-28),i=Math.min(e.y-12,n.height-t.height-o)),{left:Math.max(o,r),top:Math.max(o,i)}}function Nn(e,t,n,o=12,r=44){let i=e.top-r>=8,s=e.top+e.height+8+(i?0:r),a=e.top-8-(i?r:0)-t.height,p=s+t.height<=n.height-o||a<o,l=p?s:a;return{above:!p,left:Math.max(o,Math.min(e.left,n.width-t.width-o)),top:Math.max(o,l)}}function bt(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}}var $n=e=>`${e} ${e===1?"reply":"replies"}`;function De(e,t,n){let o={...n},r=e.id,i=m("div",{class:"rbox always"},m("div",{},ht({label:"Reply",onSend:w=>t.reply(r,w),onCancel:t.close}).element)),s=m("div",{}),a=m("div",{}),p=null,l=m("div",{},a,m("div",{class:"more"},s)),d=new Map,y=new Map,E=new Map,h=w=>{let L=je(w.author,w.name),T=d.get(w.id),A=T?.el;if((!A||T.key!==L)&&(A=ft(ke(w.author,w.name)),T)){let C=T.el;E.set(w.id,C),mt(C,()=>E.get(w.id)===C&&E.delete(w.id))}A.title=ie(w),y.set(w.id,{key:L,el:A});let P=E.get(w.id);return P?[P,A]:[A]},x=(w,L,T)=>{let A=m("button",{class:"ib",type:"button","aria-label":L,title:L},W(w));return A.addEventListener("click",P=>{P.stopPropagation(),T()}),A};function v(w,L={}){Object.assign(o,L),r=w.id;let T=(o.now??Date.now)(),A=w.root.replies.length,P=F=>m("span",{class:"who"},`${ie(F)} \xB7 ${Ne(F.at,T)}`),C=F=>m("div",{class:F.deleted?"tx del":"tx"},...F.deleted?["Deleted"]:[...dt(F.text),F.edited?" (edited)":""]),V=w.resolved?"Resolved"+(A?` \xB7 ${$n(A)}`:""):A?$n(A):"",G=m("div",{class:o.variant==="column"&&V?"ft has-rest":"ft"},o.variant==="column"&&V?m("span",{class:"rest"},V):null,m("span",{class:"hover"},P(w.root),m("span",{class:"acts"},x("copy","Copy thread",()=>t.copy(w.id)),w.resolved?x("reopen","Reopen",()=>void t.reopen(w.id)):x("resolve","Resolve",()=>void t.resolve(w.id))))),Y=o.lost?m("div",{class:"ctx"},`No longer on the page \u2014 it read \u201C${fe(o.lost,120)}\u201D`):o.quote?m("div",{class:"ctx"},`\u201C${fe(o.quote,80)}\u201D`):null;y=new Map;let oe=m("div",{class:"root"},...h(w.root),Y,C(w.root),G);a.replaceWith(oe),a=oe,p?.remove(),p=A?m("div",{class:"rps"},...w.root.replies.map(F=>m("div",{class:"it"},...h(F),C(F),m("div",{class:"rft"},P(F))))):null,p&&s.prepend(p),d=y,w.resolved?i.remove():i.parentNode!==s&&s.append(i),l.className=w.resolved?"thread resolved":"thread",l.setAttribute("data-thread",w.id)}return v(e),{element:l,update:v}}var zo="a,button,input,select,textarea,label,summary,[role=button],[contenteditable]",Wo=400;function zt(e,t){let n=new Map,o=m("div",{class:"tip",role:"tooltip"}),r=m("div",{class:"mark"}),i=m("div",{class:"pop",role:"dialog","aria-label":"Comment thread"});o.inert=i.inert=!0,e.layer.append(r,o,i);let s=m("div",{class:"bub pin ghost","aria-hidden":"true"}),a=[],p=null,l=null,d=null,y=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,E=0,h=null,x=null,v=null,w=0,L=f=>a.find(S=>S.id===f)??null,T=()=>t.popovers||e.state.listing,A=!1,P=f=>{let S=e.resolved.get(f.id);return S?Xe(f.anchor,S):null};function C(f,S,M){let{left:D,top:O}=yt(S,{width:f.offsetWidth||M,height:f.offsetHeight},wt(e.state.listing));f.style.left=`${D}px`,f.style.top=`${O}px`}function V(f){let S=f&&T()&&e.state.active!==f?L(f):null,M=S?P(S):null;if(!S||!M){v=null,o.classList.remove("show"),Q(o,!0);return}if(v!==S.id){let D=S.root.replies.length;o.replaceChildren(m("div",{class:"tx clamp"},...S.root.deleted?["Deleted"]:dt(S.root.text)),m("div",{class:"who"},`${ie(S.root)}${D?` \xB7 ${D} ${D===1?"reply":"replies"}`:""}`)),v=S.id}C(o,M,260),o.classList.contains("show")||o.offsetWidth,o.classList.add("show"),o.inert=!1}function G(f){h=f,V(f),e.hot(f)}function Y(f){if(window.clearTimeout(w),f!==null){G(f);return}w=window.setTimeout(()=>G(null),T()?Wo:0)}o.addEventListener("mouseenter",()=>window.clearTimeout(w)),o.addEventListener("mouseleave",()=>Y(null)),o.addEventListener("click",f=>{f.stopPropagation();let S=v;S&&(window.clearTimeout(w),G(null),e.open(S))});function oe(f){let S=n.get(f.id);if(S)return S;let M=m("button",{class:"bub",type:"button","aria-label":`Comment: ${fe(f.root.text,60)}`});return M.addEventListener("mouseenter",()=>Y(f.id)),M.addEventListener("mouseleave",()=>Y(null)),M.addEventListener("click",D=>{D.stopPropagation(),V(null),e.open(f.id)}),e.layer.insertBefore(M,r),n.set(f.id,M),M}function F(){let f=e.state.draft,S=d&&f&&!f.anchor.quote&&!f.anchor.point?f.resolved.element:null;if(S){let{left:D,top:O,above:_}=Nn(S.getBoundingClientRect(),{width:i.offsetWidth||Te,height:i.offsetHeight},{width:window.innerWidth,height:window.innerHeight}),U=d?.above!==null&&d?.above!==_;if(d&&(d.above=_),U&&ce())return;i.style.left=`${D}px`,i.style.top=`${O}px`;return}let M=d&&f?Xe(f.anchor,f.resolved):p?P(p):null;M&&C(i,M,Te)}let ae=f=>e.state.commenting&&!f.anchor.quote&&!f.anchor.point;function ce(){return window.clearTimeout(E),y?(i.classList.remove("show"),E=window.setTimeout(()=>{F(),i.classList.add("show")},220),!0):(i.classList.add("glide"),E=window.setTimeout(()=>i.classList.remove("glide"),450),!1)}function j(f){if(window.clearTimeout(E),y){i.classList.remove("show"),E=window.setTimeout(()=>{d?.box.setLabel(f),F(),i.classList.add("show")},220);return}d?.box.setLabel(f),i.classList.add("glide"),E=window.setTimeout(()=>i.classList.remove("glide"),450)}function J(){if(!T())return null;let f=e.state.draft;return f?f.anchor.quote||f.anchor.point||e.state.commenting?null:f.resolved.element:!p||p.anchor.quote||p.anchor.point?null:e.resolved.get(p.id)?.element??null}function pe(f){a=f;let S=new Set;for(let _ of f){if(!e.visible(_)||_.anchor.quote)continue;let U=e.resolved.get(_.id);if(!U||U.state==="orphaned")continue;S.add(_.id);let X=oe(_);X.classList.toggle("done",_.resolved),X.classList.toggle("on",e.state.active===_.id),X.classList.toggle("pin",_.anchor.point!==void 0)}for(let[_,U]of n)S.has(_)||(U.classList.remove("in"),n.delete(_),window.setTimeout(()=>U.remove(),300));V(h),A!==e.state.listing&&i.classList.contains("show")&&!y&&(window.clearTimeout(E),i.classList.add("glide"),E=window.setTimeout(()=>i.classList.remove("glide"),450)),A=e.state.listing;let M=t.popovers?e.state.draft:null;if(M){d?.of!==M?(window.clearTimeout(E),i.classList.remove("glide"),d={box:gt(e,M),of:M,at:M.resolved.element,above:null},d.box.hideLabel(ae(M)),i.replaceChildren(d.box.element),i.inert=!1,d.box.focus(),p=null,l=null,F(),i.classList.add("show")):d&&(d.at!==M.resolved.element&&(d.at=M.resolved.element,d.above=null,j(M.label)),d.box.hideLabel(ae(M)));return}d&&(window.clearTimeout(E),i.classList.remove("glide"),d=null,e.registerDraft(null));let D=T()&&e.state.active?L(e.state.active):null;if(!D||!e.visible(D)){p=null,l=null,i.classList.remove("show"),Q(i,!0);return}let O=D.anchor.quote?.exact??null;!p||!l||p.id!==D.id?(l=De(D,e.actions,{variant:"popover",quote:O}),i.replaceChildren(l.element),p=D,F(),i.classList.add("show"),i.inert=!1):p!==D&&(l.update(D,{quote:O}),p=D)}function te(){for(let[D,O]of n){let _=L(D),U=e.resolved.get(D),X=_&&U?vt(_.anchor,U):null;if(!X||X.y<-40||X.y>window.innerHeight+40){O.style.visibility="hidden";continue}O.style.visibility="",O.style.left=`${X.x}px`,O.style.top=`${X.y}px`,O.classList.contains("in")||(O.offsetWidth,O.classList.add("in"))}let f=e.state.draft,S=f?.anchor.point?vt(f.anchor,f.resolved):null;S?(s.style.left=`${S.x}px`,s.style.top=`${S.y}px`,s.classList.contains("in")||(e.layer.insertBefore(s,r),s.offsetWidth,s.classList.add("in"))):s.classList.contains("in")&&(s.classList.remove("in"),window.setTimeout(()=>s.classList.contains("in")||s.remove(),300)),i.classList.contains("show")&&F();let M=J();r.classList.toggle("show",M!==null),M&&$e(r,M.getBoundingClientRect(),4)}let u=f=>{if(e.owns(f)){let M=f.composedPath()[0];x!==null&&!(M instanceof Element&&M.closest(".tip,.bub"))&&Y(null),x=null;return}let S=e.readsAt(f.clientX,f.clientY)?.id??null;S!==x&&(x=S,Y(S))},N=f=>{if(e.owns(f))return;let S=window.getSelection();if(S&&!S.isCollapsed||(e.state.commenting?f.altKey:f.target instanceof Element&&f.target.closest(zo)))return;let M=e.readsAt(f.clientX,f.clientY);M&&(e.claim(f),V(null),e.open(M.id))};return window.addEventListener("pointermove",u,{capture:!0,passive:!0}),window.addEventListener("click",N,!0),{render:pe,frame:te,destroy(){window.clearTimeout(w),window.clearTimeout(E),window.removeEventListener("pointermove",u,!0),window.removeEventListener("click",N,!0),e.registerDraft(null);for(let f of n.values())f.remove();s.remove(),o.remove(),r.remove(),i.remove()}}}var Yo="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}]`),jo=["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",...Yo].join(","),Go="a,button,label,summary,[role=button],[role=link],[role=tab],[role=option],[role=menuitem]",Xo=.6,xt=2,Dn=(e,t)=>Math.abs(e.left-t.left)<=xt&&Math.abs(e.top-t.top)<=xt&&Math.abs(e.width-t.width)<=xt&&Math.abs(e.height-t.height)<=xt;function Qe(e,t,n){if(e===t||!t.contains(e)||e.closest("[data-pipeup-ignore]"))return null;let o=n.viewport(),r=Xo*o.width*o.height,i=null;for(let a=e;a&&a!==t;a=a.parentElement){let p=n.box(a);if(!(p.width<2||p.height<2)){if(a.hasAttribute("data-pipeup-id")){i=a;break}if(!(p.width*p.height>r)&&(a.matches(jo)||n.drawn(a)||a.childElementCount>1&&!a.parentElement?.closest(Go)&&n.grouped(a))){i=a;break}}}if(!i||i.hasAttribute("data-pipeup-id"))return i;let s=n.box(i);for(let a=i.parentElement;a&&a!==t&&Dn(n.box(a),s);a=a.parentElement)if(a.hasAttribute("data-pipeup-id"))return a;return i}function Wt(e,t,n){let o=n.box(e);for(let r=e.parentElement;r&&r!==t;){let i=Qe(r,t,n);if(!i)return null;if(!Dn(n.box(i),o))return i;r=i.parentElement}return null}function Bn(e=window){return{box:t=>t.getBoundingClientRect(),drawn:t=>{let n=e.getComputedStyle(t),o=n.backgroundColor!=="transparent"&&!/,\s*0\)$/.test(n.backgroundColor),r=["top","right","bottom","left"].some(i=>parseFloat(n.getPropertyValue(`border-${i}-width`))>0);return o||r||n.backgroundImage!=="none"||n.boxShadow!=="none"},grouped:t=>/^(inline-)?(flex|grid)$/.test(e.getComputedStyle(t).display),viewport:()=>({width:e.innerWidth,height:e.innerHeight})}}var _n="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]",Zo=`${_n},input,select,textarea,[contenteditable]:not([contenteditable=false]),[tabindex]:not([tabindex="-1"])`,Hn=["click","dblclick","auxclick","submit","contextmenu","dragstart"],Fn=[...["over","out","enter","leave","down","up"].flatMap(e=>[`pointer${e}`,`mouse${e}`]),"mousemove","touchstart","touchmove","touchend","touchcancel"],Qo=400;function qn(e,t=Bn()){let n=m("div",{class:"pick"});e.layer.append(n);let o=m("span",{class:"lbl"}),r=m("button",{class:"nb",type:"button","aria-label":"Select the block around it",title:"Select the block around it"},W("expand",16)),i=m("div",{class:"namebar",role:"toolbar","aria-label":"Chosen block"},o,r);i.inert=!0,e.layer.append(i),i.addEventListener("mousedown",u=>u.preventDefault()),r.addEventListener("click",u=>{u.stopPropagation();let N=p&&Wt(p,e.root,t);N&&Y(N)});let s=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,a=null,p=null,l=null,d=null,y=0,E=()=>{},h=null,x=()=>{},v=u=>!e.owns(u)&&!(u.target instanceof Element&&u.target.closest("[data-pipeup-ignore]"));function w(){d&&(n.classList.toggle("glide",performance.now()<y),$e(n,d.getBoundingClientRect(),4))}function L(){if(!h)return;i.classList.toggle("glide",performance.now()<y&&i.classList.contains("show"));let u=h.getBoundingClientRect(),{left:N,top:f}=bt({left:u.left,top:u.top,width:u.width,height:u.height},{width:i.offsetWidth||200,height:i.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});i.style.left=`${N}px`,i.style.top=`${f}px`}function T(u,N){d=u,y=N?performance.now()+Qo:0,w(),n.classList.add("show")}function A(u,N){let f=getComputedStyle(u);if(f.opacity==="0")return N(),()=>{};let S=0,M=()=>{window.clearTimeout(S),u.removeEventListener("transitionend",O)},D=()=>{M(),N()},O=U=>{U.target===u&&U.propertyName==="opacity"&&D()},_=Math.max(...f.transitionDuration.split(",").map(U=>parseFloat(U)*1e3||0));return S=window.setTimeout(D,_+100),u.addEventListener("transitionend",O),M}function P(u){if(u!==a){if(a=u,E(),!u){n.classList.remove("show");return}getComputedStyle(n).opacity==="0"?T(u,!1):s?(n.classList.remove("show"),E=A(n,()=>T(u,!1))):T(u,!0)}}function C(u){p=u,n.classList.toggle("on",u!==null),P(u),x(),i.inert=!u,u?s?(i.classList.remove("show"),x=A(i,()=>V(u))):V(u):(i.classList.remove("show"),h=null)}function V(u){o.textContent=o.title=Re(u);let N=Wt(u,e.root,t)===null;r.hidden=N;let f=i.classList.contains("show");h=u,L(),f||(i.offsetWidth,i.classList.add("show"))}function G(u){let N;try{N=lt(u,e.root)}catch(M){e.report(M);return}let f={anchor:N,label:Re(u),ranges:[],resolved:{state:"attached",element:u,range:null}},S=e.state.draft;C(u),l=S??{...f,ranges:[]},S?e.moveDraft({...f,ranges:[]}):e.startDraft(l)}function Y(u){e.keepCaret(()=>G(u))}function oe(u){let N=(u.target instanceof Element?Qe(u.target,e.root,t):null)??e.root,f=N.getBoundingClientRect();if(!f.width||!f.height)return;let S={x:(u.clientX-f.left)/f.width,y:(u.clientY-f.top)/f.height},M;try{M=lt(N,e.root,S)}catch(O){e.report(O);return}let D=Re(N).replace(/^[A-Z](?=[a-z])/,O=>O.toLowerCase());C(null),P(null),e.startDraft({anchor:M,label:`Pin on ${D}`,ranges:[],resolved:{state:"attached",element:N,range:null}})}function F(u){let N=window.getSelection();if(N&&!N.isCollapsed)return;if(e.state.draft&&(u.altKey||!e.draftEmpty())){e.dismiss();return}if(!u.altKey&&e.readsAt(u.clientX,u.clientY))return;if(e.state.active&&e.open(null),u.altKey){oe(u);return}let f=u.target instanceof Element?Qe(u.target,e.root,t):null;f?G(f):(e.dismiss(),C(null))}let ae=u=>{if(!e.owns(u)){if(!v(u)){p||P(null);return}u.stopPropagation(),!(p||e.state.draft)&&P(!ce()&&u.target instanceof Element?Qe(u.target,e.root,t):null)}},ce=()=>{let u=window.getSelection();return!!u&&!u.isCollapsed&&u.toString().trim()!==""},j=()=>{!p&&ce()&&P(null)},J=u=>{v(u)&&(u.stopPropagation(),(u.type==="pointerdown"||u.type==="mousedown")&&u.target instanceof Element&&u.target.closest(Zo)&&u.preventDefault())},pe=u=>{v(u)&&(u.preventDefault(),u.stopPropagation(),u.type==="click"&&!e.state.menu&&!e.claimed(u)&&F(u))},te=u=>{(u.key==="Enter"||u.key===" ")&&v(u)&&u.target instanceof Element&&u.target.closest(_n)&&(u.preventDefault(),u.stopPropagation())};window.addEventListener("pointermove",ae,!0),document.addEventListener("selectionchange",j);for(let u of Fn)window.addEventListener(u,J,!0);for(let u of Hn)window.addEventListener(u,pe,!0);return window.addEventListener("keydown",te,!0),{back(){return p?(C(null),!0):!1},render(){let u=e.state.draft;l&&u!==l?(l=null,C(null)):u&&!l&&(a||p)&&C(null)},frame(){w(),L()},destroy(){E(),x(),window.removeEventListener("pointermove",ae,!0),document.removeEventListener("selectionchange",j);for(let u of Fn)window.removeEventListener(u,J,!0);for(let u of Hn)window.removeEventListener(u,pe,!0);window.removeEventListener("keydown",te,!0),n.classList.remove("show"),i.classList.remove("show"),Q(i,!0),A(n,()=>n.remove()),A(i,()=>i.remove())}}}var Jo=300,er=32,Yt=220,Je=320,tr=24,Vn=24;function jt(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 a=n.clientWidth,l=getComputedStyle(r).maxWidth,d;return l.endsWith("px")?d=parseFloat(l):l.endsWith("%")?d=parseFloat(l)/100*a:d=r.getBoundingClientRect().width,o!=="column"&&a<d+Je-(t?tr:0)?null:{x:a-Je+Vn,width:Je-2*Vn}}let i=r.getBoundingClientRect().right;if(window.innerWidth-i<Jo&&o!=="column")return null;let s=i+er;return{x:s,width:Math.max(220,Math.min(300,window.innerWidth-s-16))}}function Gt(e,t){let n=e.resolved.get(t.id);return!n||n.state==="orphaned"&&!e.pending.has(t.id)}function Un(e){let t=m("div",{class:"col"});e.layer.append(t);let n=new Map,o=null,r=new ResizeObserver(()=>a()),i=h=>Gt(e,h);function s(h){let x=e.resolved.get(h.id),v=x?Kt(h.anchor,x):null;return v===null?Number.POSITIVE_INFINITY:v+window.scrollY-4}function a(){let h=[],x=[];for(let[A,P]of n){let C=s(P.thread);if(Number.isFinite(C))P.placed=C;else if(e.pending.has(A)){if(P.placed===null){P.el.classList.add("wait");continue}C=P.placed}Number.isFinite(C)?h.push({id:A,want:C,height:P.el.offsetHeight}):x.push({id:A,height:P.el.offsetHeight})}let v=e.state.draft,w=v?Kt(v.anchor,v.resolved):null;o&&w!==null&&h.push({id:"draft",want:w+window.scrollY-4,height:o.el.offsetHeight});let L=In(h,o?"draft":e.state.active),T=Math.max(0,...h.map(A=>(L.get(A.id)??0)+A.height))+24;for(let A of x)L.set(A.id,T),T+=A.height+10;for(let[A,P]of n){if(P.el.classList.contains("wait")){if(!L.has(A))continue;P.el.style.transition="none",P.el.style.transform=`translateY(${Math.round(L.get(A))}px)`,P.el.offsetWidth,P.el.style.transition="",P.el.classList.remove("wait");continue}P.el.style.transform=`translateY(${Math.round(L.get(A)??0)}px)`}o&&(o.el.style.transform=`translateY(${Math.round(L.get("draft")??0)}px)`)}function p(h,x){h.thread=x,h.lost=i(x),h.view.update(x,{lost:h.lost?x.anchor.snapshot:null})}function l(h){let x=i(h),v=De(h,e.actions,{variant:"column",lost:x?h.anchor.snapshot:null}),w=m("div",{class:"th","data-thread":h.id},v.element);return w.style.transition="none",w.addEventListener("mouseenter",()=>e.hot(h.id)),w.addEventListener("mouseleave",()=>e.hot(null)),w.addEventListener("click",()=>e.open(h.id)),t.append(w),r.observe(w),{el:w,thread:h,lost:x,placed:null,view:v}}function d(){let h=e.state.draft;if(o&&h&&o.of!==h){let x=o.el;r.unobserve(x),x.classList.add("out"),window.setTimeout(()=>x.remove(),Yt),o=null}if(h&&o&&(o.box.setLabel(h.label),o.box.hideLabel(e.state.commenting&&!h.anchor.quote&&!h.anchor.point)),h&&!o){let x=gt(e,h),v=m("div",{class:"th on"},x.element);v.style.transition="none",t.append(v),r.observe(v),o={el:v,box:x,of:h},x.hideLabel(e.state.commenting&&!h.anchor.quote&&!h.anchor.point),x.focus()}else if(!h&&o){let x=o.el;r.unobserve(x),x.classList.add("out"),window.setTimeout(()=>x.remove(),Yt),o=null,e.registerDraft(null)}}function y(h){Q(t,e.state.listing);let x=new Set,v=[],w=e.state.active!==null||e.state.draft!==null;for(let L of h){if(!e.visible(L))continue;x.add(L.id);let T=n.get(L.id);T?(T.thread!==L||T.lost!==i(L))&&p(T,L):(T=l(L),n.set(L.id,T),v.push(T.el));let A=T.el;A.classList.toggle("on",e.state.active===L.id);let P=A.querySelector(".more");P&&Q(P,e.state.active!==L.id),A.classList.toggle("dim",w&&e.state.active!==L.id),A.classList.toggle("hot",e.state.hot===L.id&&e.state.active!==L.id),A.classList.toggle("resolved",L.resolved),A.classList.toggle("lost",T.lost)}for(let[L,T]of n)x.has(L)||(n.delete(L),r.unobserve(T.el),T.el.classList.add("out"),window.setTimeout(()=>T.el.remove(),Yt));d(),a(),o&&v.push(o.el);for(let L of v)L.offsetWidth,L.style.transition=""}function E(){let h=jt(e.root,!0);h&&(t.style.width=`${h.width}px`,t.style.transform=`translate(${h.x}px, ${-window.scrollY}px)`)}return{render:y,frame:E,destroy(){r.disconnect(),e.registerDraft(null),t.remove()}}}var nr="[data-pipeup-ignore],input,textarea,select,[contenteditable]:not([contenteditable=false])";function Kn(e){let t=m("button",{type:"button","aria-label":"Comment",title:"Comment"},W("comment",17)),n=m("div",{class:"selbar"},t);n.inert=!0,e.layer.append(n);let o=null,r=d=>{let y=d&&(d.nodeType===Node.ELEMENT_NODE?d:d.parentElement);return!!y&&e.root.contains(y)&&!y.closest(nr)};function i(){if(!o)return;let d=o.getBoundingClientRect(),{left:y,top:E}=bt({left:d.left,top:d.top,width:d.width,height:d.height},{width:n.offsetWidth||36,height:n.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});n.style.left=`${y}px`,n.style.top=`${E}px`}function s(){o=null,n.inert=!0,n.classList.remove("show")}function a(){let d=window.getSelection();if(!e.state.commenting||!d||d.isCollapsed||d.rangeCount===0||!d.toString().trim()||!r(d.anchorNode)||!r(d.focusNode)){s();return}o=d.getRangeAt(0).cloneRange(),i(),n.inert=!1,n.classList.add("show")}t.addEventListener("mousedown",d=>d.preventDefault()),t.addEventListener("click",d=>{d.stopPropagation();let y=o;if(!y)return;let E;try{E=Nt(y,e.root)}catch(x){e.report(x),s();return}let h=fe(y.toString().replace(/\s+/g," ").trim(),60);window.getSelection()?.removeAllRanges(),s(),e.startDraft({anchor:E,label:`\u201C${h}\u201D`,ranges:[y],resolved:{state:"attached",element:null,range:y}})});let p=()=>{if(!o)return;let d=window.getSelection();(!d||d.isCollapsed||!d.toString().trim())&&s()};document.addEventListener("selectionchange",p);let l=d=>{e.owns(d)||window.setTimeout(a,0)};return window.addEventListener("mouseup",l,!0),window.addEventListener("keyup",l,!0),{render(){!e.state.commenting&&o&&s()},frame(){o&&i()},destroy(){window.removeEventListener("mouseup",l,!0),window.removeEventListener("keyup",l,!0),document.removeEventListener("selectionchange",p),n.remove()}}}async function Xt(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 or=3e3;function zn(e){let t=[m("span",{class:"n"}),m("span",{class:"n"})],n=W("comment",20,1.4);n.lastElementChild.setAttribute("stroke-width","1.6");let o=m("button",{class:"mode",type:"button","aria-label":"Comment","aria-keyshortcuts":Vt,"aria-haspopup":"menu","aria-expanded":"false"},m("span",{class:"plus"},n),m("span",{class:"cnt"},W("bubble",34,1.4),...t)),r=m("span",{class:"ttip","aria-hidden":"true"},"Comment",m("small",{},Ye)),i=m("div",{class:"launch"},o,r),s=m("div",{class:"menu",role:"menu","aria-label":"Comments"}),a=m("div",{class:"list",role:"menu","aria-label":"All comments"}),p=m("span",{class:"pn"}),l=m("button",{class:"ib",type:"button","aria-label":"Close"},W("close")),d=m("button",{class:"hs",type:"button",role:"switch","aria-checked":"false"},"Show resolved",m("span",{class:"sw","aria-hidden":"true"}));d.addEventListener("click",g=>{g.stopPropagation(),e.menu.toggleResolved()});let y=m("div",{class:"all",role:"dialog","aria-label":"All comments"},m("div",{class:"hd"},m("span",{},"All comments"),p,d,l),a),E=m("div",{class:"pop side",role:"dialog","aria-label":"Comment thread"});s.inert=y.inert=E.inert=!0,e.layer.append(s,i,y);let h=!1,x=null,v=0,w=[],L=0,T=null,A=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,P=g=>{h=e.state.menu=g,window.clearTimeout(v),v=0,g||x?.(!0),s.classList.toggle("show",g),Q(s,!g),o.setAttribute("aria-expanded",String(g))},C=(g,k=!1)=>{e.state.listing!==g&&(e.state.listing=g,e.render(),g?(V(a)[0]??l).focus({preventScroll:!0}):k&&o.focus({preventScroll:!0}))},V=(g=s)=>[...g.querySelectorAll(".mi")],G=()=>s.getRootNode().activeElement,Y=()=>{P(!1),o.focus({preventScroll:!0})},oe=g=>{let k=V(g.currentTarget);if(k.length===0)return;let $=G(),I=k.indexOf($),H=K=>{g.preventDefault(),k[(K+k.length)%k.length]?.focus({preventScroll:!0})};g.key==="ArrowDown"?H(I+1):g.key==="ArrowUp"?H(I<0?k.length-1:I-1):g.key==="Home"?H(0):g.key==="End"&&H(k.length-1)};s.addEventListener("keydown",oe),a.addEventListener("keydown",oe),l.addEventListener("click",g=>{g.stopPropagation(),C(!1,!0)});let F=g=>Gt(e,g),ae=()=>w.filter(g=>!g.resolved).length;function ce(){let g=V(a).indexOf(G()),k=e.menu.all().filter(ne=>!ne.thread.resolved||e.state.showResolved),$=ne=>{let re=ne.thread,_e=ke(re.root.author,re.root.name);_e.classList.add("in");let Oe=m("button",{class:re.resolved?"mi done":"mi",type:"button",role:"menuitem","data-thread":re.id},_e,m("span",{},m("span",{class:"clamp"},re.root.deleted?"Deleted":re.root.text),m("small",{},F(re)?`\u201C${fe(re.anchor.snapshot,80)}\u201D`:ne.location.where)));return Oe.addEventListener("click",Tt=>{Tt.stopPropagation(),j(re.id,Oe.getBoundingClientRect().top)}),Oe},I=k.filter(ne=>F(ne.thread)),H="No longer on the page";p.textContent=String(ae()),d.setAttribute("aria-checked",String(e.state.showResolved)),a.replaceChildren(k.length?"":m("div",{class:"sec",role:"presentation"},"No open comments"),...k.filter(ne=>!F(ne.thread)).map($),I.length?m("div",{role:"group","aria-label":H},m("div",{class:"sec","aria-hidden":"true"},H),...I.map($)):"");let K=V(a);g>=0&&K[Math.min(g,K.length-1)]?.focus({preventScroll:!0})}function j(g,k){Se()&&(e.state.reading=!0,C(!1)),J(g,k)}function J(g,k){let $=w.find(K=>K.id===g),I=e.resolved.get(g);if(!$)return;let H=I&&!F($)?I.element??I.range?.startContainer.parentElement??null:null;if(H?.scrollIntoView({block:"center",inline:"nearest",behavior:A?"auto":"smooth"}),H&&I&&Xe($.anchor,I)&&H.checkVisibility?.({visibilityProperty:!0})!==!1){te(),e.open(g);return}e.open(null),Se()&&(e.state.reading=!0,e.render()),pe($,k)}function pe(g,k){let $={quote:g.anchor.quote?.exact??null,lost:F(g)?g.anchor.snapshot:null};if(T?.id===g.id?T.view.update(g,$):(T={id:g.id,view:De(g,e.actions,{variant:"popover",...$})},E.replaceChildren(T.view.element)),k===void 0)return;E.isConnected||(e.layer.insertBefore(E,y),E.offsetWidth);let I=wt(e.state.listing),{left:H,top:K}=yt({x:I.width,y:k,below:!1},{width:Te,height:E.offsetHeight},I);E.style.left=`${H}px`,E.style.top=`${K}px`,E.classList.add("show"),E.inert=!1,e.focusReply(g.id)}function te(g=!1){T&&(T=null,E.classList.remove("show"),Q(E,!0),g&&e.state.reading&&(e.state.reading=!1,e.render()))}function u(g,k,$,I=!1,...H){let K=m("button",{class:"mi",type:"button",role:I?"menuitemcheckbox":"menuitem"},g,m("span",{class:"lb"},k),...H,I&&m("span",{class:"sw","aria-hidden":"true"}),m("span",{class:"tt","aria-hidden":"true"}));return K.addEventListener("click",ne=>{ne.stopPropagation(),$()}),K}let N=(g,k,$,I)=>{let H=g.querySelector(".lb");H.textContent!==k&&(H.textContent=k),g.querySelector(".tt").textContent=$,g.setAttribute("aria-description",$),I!==void 0&&g.setAttribute("aria-checked",String(I))},f=()=>m("div",{class:"sep",role:"separator"}),S=m("span",{class:"ma"}),M=m("span",{class:"kc"}),D="",O=u(S,"",kt,!1,M);O.dataset.item="name";let _=u(W("copy"),"Copy as Markdown",()=>{Y(),e.menu.copyAll("ai")}),U=u(W("lines"),"Copy as Text",()=>{Y(),e.menu.copyAll("text")}),X=m("span",{class:"kc"}),Be=u(W("list"),"All comments",()=>{P(!1),C(!0)},!1,X),ge=u(W("comment"),"Start commenting",()=>e.setCommenting(!e.state.commenting),!0,m("span",{class:"kc","aria-hidden":"true"},Ye));ge.dataset.item="comment",ge.setAttribute("aria-keyshortcuts",Vt);let ve=[O,f(),_,U,Be,f(),ge];function He(){let g=ae(),k=e.menu.name(),$=k||me(e.doc.me);if(N(O,$,k?"The name on your comments":"Add a name to show on your comments"),O.setAttribute("aria-label",`${$}, ${k?"edit":"add"} your name`),M.replaceChildren(k?W("edit",13):"Add name"),je(e.doc.me,k)!==D){D=je(e.doc.me,k);let I=ke(e.doc.me,k);I.classList.add("in"),S.replaceChildren(I)}N(_,"Copy as Markdown","Markdown, with where each thread is"),N(U,"Copy as Text","Just the words"),N(Be,"All comments","Every thread, and where it is"),X.textContent=g?String(g):"",N(ge,"Start commenting",e.state.commenting?"Turn off to hide the comments again":"Shows the comments; choose any part of the page to comment on it",e.state.commenting)}function et(){He(),s.firstChild!==O&&s.replaceChildren(...ve)}function kt(){let g=m("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"});g.value=e.menu.name();let k=m("div",{class:"ed"},S.cloneNode(!0),g),$=(I,H=!1)=>{if(x!==$)return;x=null;let K=g.value.trim();I&&K&&K!==e.menu.name()&&e.menu.rename(K).then(He),k.replaceWith(O),H&&O.focus({preventScroll:!0})};x=$,g.addEventListener("keydown",I=>{I.stopPropagation(),(I.key==="Enter"||I.key==="Escape")&&(I.preventDefault(),$(I.key==="Enter",!0))}),g.addEventListener("blur",()=>$(!0)),O.replaceWith(k),g.focus({preventScroll:!0})}o.addEventListener("click",g=>{if(g.stopPropagation(),h){P(!1);return}et(),P(!0),g.detail===0&&V().at(-1)?.focus({preventScroll:!0})});let Me=!1,Ce=()=>{Me=y.contains(G())},Fe=g=>{let k=g.composedPath();h&&!k.includes(s)&&!k.includes(o)&&(P(!1),e.state.commenting&&!e.owns(g)&&(e.claim(g),g.preventDefault(),g.stopPropagation())),e.state.listing&&!e.owns(g)&&C(!1,Me&&(!document.activeElement||document.activeElement===document.body)),!k.includes(E)&&!k.includes(y)&&te(!0)},Pe=g=>{if(!h||g.pointerType==="touch"||g.type==="pointerout"&&g.relatedTarget)return;let k=g.composedPath();g.type==="pointerover"&&(k.includes(s)||k.includes(o))?(window.clearTimeout(v),v=0):v||(v=window.setTimeout(()=>{v=0,x||P(!1)},or))};window.addEventListener("pointerdown",Ce,!0),window.addEventListener("click",Fe,!0),window.addEventListener("pointerover",Pe,!0),window.addEventListener("pointerout",Pe,!0);let tt=g=>{if(g.key!=="Escape"||x)return;let k=g.composedPath()[0];if(h)Y();else if(e.state.listing&&!(k instanceof HTMLTextAreaElement&&!y.contains(k)))C(!1,!0);else if(T)te(!0),e.actions.close();else return;g.stopPropagation()};return window.addEventListener("keydown",tt,!0),{render(g){w=g;let k=ae();if(k!==L){if(k){let[I,H]=t[0].classList.contains("on")?t:[t[1],t[0]];H.textContent=k>99?"99+":String(k),H.classList.toggle("s",k>99),I.classList.remove("on"),H.classList.add("on")}o.classList.toggle("has",k>0),o.setAttribute("aria-label",k?`Comment, ${k} open`:"Comment"),L=k}o.classList.toggle("on",e.state.commenting),h&&He();let $=e.state.listing;if(y.classList.toggle("full",Se()),y.classList.contains("show")!==$&&(y.classList.toggle("show",$),Q(y,!$)),$&&ce(),T){let I=g.find(H=>H.id===T?.id);!I||e.state.active||I.resolved&&!e.state.showResolved?te():pe(I)}},frame(){},destroy(){window.removeEventListener("pointerdown",Ce,!0),window.removeEventListener("click",Fe,!0),window.removeEventListener("pointerover",Pe,!0),window.removeEventListener("pointerout",Pe,!0),window.clearTimeout(v),window.removeEventListener("keydown",tt,!0),s.remove(),y.remove(),E.remove(),i.remove()}}}var Yn=["pipeup-quote","pipeup-on","pipeup-done"],rr={"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]]},ir=(e,t)=>Yn.map(n=>{let[o,r,i,s]=rr[n][e?1:0];return`::highlight(${n}){background-color:rgba(${o},${r},${i},${+(s*t).toFixed(3)})}`}).join("");function jn(){return typeof CSS<"u"&&"highlights"in CSS&&typeof Highlight<"u"}var ar="<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>",sr=`:not([data-pipeup-ignore],[data-pipeup-ignore] *){cursor:url("data:image/svg+xml,${encodeURIComponent(ar)}") 3 2,crosshair!important}`;function Gn(e=document,t=!1){let n=e.defaultView?.CSSStyleSheet;if(!n||!("replaceSync"in n.prototype)||!("adoptedStyleSheets"in e))return{gutter(){},picking(){},fade(){},room(){},remove:()=>Wn()};let o=new n,r=null,i=!1,s=1,a=0,p="",l=0,d=()=>o.replaceSync(ir(t,s)+(r===null?"":`:root{--pipeup-gutter:${r}px}`)+(i?sr:"")+(a||p?`html{--pipeup-panel:${a}px;${a?`margin-right:${a}px!important;`:""}${p}}`:""));return d(),e.adoptedStyleSheets=[...e.adoptedStyleSheets,o],{gutter(y){y!==r&&(r=y,d())},picking(y){y!==i&&(i=y,d())},fade(y){s=y,d()},room(y,E){y!==a&&(a=y,p=E?"":"transition:margin-right .34s cubic-bezier(.4,0,.2,1)!important",clearTimeout(l),!y&&p&&(l=window.setTimeout(()=>{p="",d()},400)),d())},remove(){clearTimeout(l),e.adoptedStyleSheets=e.adoptedStyleSheets.filter(y=>y!==o),Wn()}}}function Xn(e){jn()&&(CSS.highlights.set("pipeup-quote",new Highlight(...e.quote)),CSS.highlights.set("pipeup-on",new Highlight(...e.on)),CSS.highlights.set("pipeup-done",new Highlight(...e.done)))}function Wn(){if(jn())for(let e of Yn)CSS.highlights.delete(e)}var Zt=':host{all:initial}*{box-sizing:border-box}button{-webkit-appearance:none;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(--pu-ink);--pu-ink:#2C2C2A;--pu-muted:#5F5E5A;--pu-faint:#888780;--pu-line:#E5E3DA;--pu-rule:#ECEAE2;--pu-soft:#FAFAF7;--pu-surface:#FFFFFF;--pu-hover:#F1EFE8;--pu-accent-soft:color-mix(in srgb,var(--pu-accent,#534AB7) 12%,transparent);--pu-shadow:0 8px 28px rgba(44,44,42,.1);--pu-enter:.26s;--pu-move:.34s;--pu-exit:.2s;--pu-pulse:1.2s;--pu-eo:cubic-bezier(.22,.61,.36,1);--pu-eio:cubic-bezier(.4,0,.2,1);--pu-ei:cubic-bezier(.4,0,1,1)}.layer.dark{--pu-ink:#ECEBE6;--pu-muted:#B4B2A9;--pu-faint:#8D8B84;--pu-line:#3A3936;--pu-rule:#34332F;--pu-soft:#22221F;--pu-surface:#1B1B19;--pu-hover:#2C2C29;--pu-shadow: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(--pu-ink);white-space:pre-wrap;overflow-wrap:anywhere}.tx.del,.who,.rest,.ctx{color:var(--pu-faint)}.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(--pu-enter) var(--pu-eo),opacity var(--pu-enter) var(--pu-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(--pu-enter) var(--pu-eo)}.ft .rest{transition:opacity var(--pu-enter) var(--pu-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(--pu-muted);transition:background-color .2s var(--pu-eo),color .2s var(--pu-eo)}.ib:hover,.ib:focus-visible{background:var(--pu-hover);color:var(--pu-ink);outline:none}.rps,.rbox{padding-left:14px}.rps .it{padding-top:6px}.more{display:grid;grid-template-rows:1fr;transition:grid-template-rows var(--pu-move) var(--pu-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(--pu-line);outline:none;resize:none;overflow:hidden;font:inherit;font-size:14px;line-height:1.5;padding:3px 0;color:var(--pu-ink);background:transparent;transition:border-color var(--pu-enter) var(--pu-eo)}.row:hover .input,.input:hover{border-bottom-color:var(--pu-muted)}.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(--pu-enter) var(--pu-eo),transform var(--pu-enter) var(--pu-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(--pu-faint)}.you>*{grid-area:1/1;display:flex;align-items:center;min-width:0;transition:opacity var(--pu-enter) var(--pu-eo),transform var(--pu-enter) var(--pu-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(--pu-muted);text-decoration:underline;text-decoration-color:var(--pu-line);text-underline-offset:2px;transition:color .2s var(--pu-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(--pu-enter) var(--pu-eo),background-color .2s var(--pu-eo)}.send.show{opacity:1;pointer-events:auto}.send:hover{background:var(--pu-accent-soft)}.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(--pu-surface);box-shadow:0 1px 4px #0003;pointer-events:auto;opacity:0;transform:translateY(-6px) scale(.9);transform-origin:2px 20px;transition:opacity var(--pu-exit) var(--pu-ei),transform var(--pu-exit) var(--pu-ei)}.bub.in{opacity:1;transform:none;transition:opacity var(--pu-enter) var(--pu-eo),transform var(--pu-enter) var(--pu-eo)}.bub.in:hover,.bub.on{transform:scale(1.18)}.bub.done{background:var(--pu-faint)}.bub.ghost{pointer-events:none}.tip,.pop,.menu,.all,.toast,.selbar{background:var(--pu-surface);border:1px solid var(--pu-line);box-shadow:var(--pu-shadow)}.tip{position:fixed;max-width:260px;border-radius:10px;padding:7px 10px;opacity:0;transform:translateY(3px);transition:opacity .22s var(--pu-eo),transform .26s var(--pu-eo)}.tip.show{opacity:1;transform:none;pointer-events:auto;cursor:pointer;transition:opacity .22s var(--pu-eo),transform .26s var(--pu-eo),left var(--pu-move) var(--pu-eio),top var(--pu-move) var(--pu-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(--pu-exit) var(--pu-ei),transform var(--pu-exit) var(--pu-ei)}.pop.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--pu-enter) var(--pu-eo),transform var(--pu-move) var(--pu-eo)}.pop.show.glide{transition:opacity var(--pu-enter) var(--pu-eo),transform var(--pu-move) var(--pu-eo),left var(--pu-move) var(--pu-eio),top var(--pu-move) var(--pu-eio)}.mark{position:fixed;border:2px solid color-mix(in srgb,var(--pu-accent) 50%,transparent);background:var(--pu-accent-soft);border-radius:8px;opacity:0;transition:opacity .3s var(--pu-eo)}.mark.show{opacity:1}.pulse{position:fixed;border:2px solid var(--pu-accent);border-radius:8px;background:var(--pu-accent-soft);animation:pu-pulse var(--pu-pulse) var(--pu-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(--pu-enter) var(--pu-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(--pu-move) var(--pu-eio),box-shadow var(--pu-enter) var(--pu-eo),opacity var(--pu-enter) var(--pu-eo)}.th.hot{box-shadow:inset 2px 0 0 var(--pu-line)}.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(--pu-exit) var(--pu-ei)}.selbar{position:fixed;display:flex;border-radius:10px;padding:2px;opacity:0;transform:translateY(4px);pointer-events:none;transition:opacity var(--pu-enter) var(--pu-eo),transform .3s var(--pu-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(--pu-eo)}.selbar button:hover,.selbar button:focus-visible{background:var(--pu-accent-soft);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(--pu-exit) var(--pu-ei),border-color var(--pu-exit) var(--pu-ei)}.pick.show{opacity:1;transition-duration:var(--pu-enter);transition-timing-function:var(--pu-eo)}.pick.show.glide{transition-property:all;transition-duration:var(--pu-move);transition-timing-function:var(--pu-eio)}.pick.on{border-color:var(--pu-accent)}.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(--pu-muted);white-space:nowrap;background:var(--pu-surface);border:1px solid var(--pu-line);box-shadow:var(--pu-shadow);pointer-events:none;opacity:0;transform:translateY(4px);transition:opacity var(--pu-exit) var(--pu-ei),transform var(--pu-exit) var(--pu-ei)}.namebar.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--pu-enter) var(--pu-eo),transform .3s var(--pu-eo)}.namebar.show.glide{transition-property:all;transition-duration:var(--pu-move);transition-timing-function:var(--pu-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(--pu-eo),color .2s var(--pu-eo)}.namebar .nb:hover,.namebar .nb:focus-visible{background:var(--pu-hover);color:var(--pu-ink);outline:none}.namebar .nb[hidden]{display:none}.launch{position:fixed;right:20px;bottom:20px;pointer-events:auto}.launch .mode{display:grid;place-items:center;width:46px;height:46px;border-radius:50%;background:var(--pu-surface);border:1px solid var(--pu-line);box-shadow:var(--pu-shadow);transition:background-color .3s var(--pu-eo),color .3s var(--pu-eo)}.mode>*,.cnt>*{grid-area:1/1}.mode>*{display:grid;place-items:center;transition:opacity var(--pu-enter) var(--pu-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(--pu-enter) var(--pu-eo)}.n.s{font-size:9.5px;letter-spacing:-.04em}.n.on{opacity:1}.launch .mode:hover,.launch .mode[aria-expanded=true]{background:var(--pu-hover)}.launch .mode.on{background:var(--pu-accent);color:#fff}.ttip{position:absolute;right:0;bottom:54px;white-space:nowrap;border-radius:8px;padding:4px 9px;font-size:12px;background:var(--pu-surface);border:1px solid var(--pu-line);box-shadow:var(--pu-shadow);pointer-events:none;opacity:0;transform:translateY(3px);transition:opacity var(--pu-exit) var(--pu-ei),transform var(--pu-exit) var(--pu-ei)}.ttip small{margin-left:8px}.ttip small,.mi .kc{font-size:12px;color:var(--pu-faint)}.mode:hover+.ttip,.mode:focus-visible+.ttip{opacity:1;transform:none;transition:opacity var(--pu-enter) var(--pu-eo) .5s,transform var(--pu-enter) var(--pu-eo) .5s}.launch .mode[aria-expanded=true]+.ttip{opacity:0;transition:opacity var(--pu-exit) var(--pu-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(--pu-exit) var(--pu-ei),transform var(--pu-exit) var(--pu-ei)}.menu.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--pu-enter) var(--pu-eo),transform var(--pu-move) var(--pu-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(--pu-eo)}.mi:hover,.mi:focus-visible{background:var(--pu-soft);outline:none}.mi svg{color:var(--pu-muted);flex:none}.mi small{display:block;color:var(--pu-faint);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(--pu-rule)}.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(--pu-muted);background:var(--pu-surface);border:1px solid var(--pu-line);box-shadow:var(--pu-shadow);pointer-events:none;opacity:0;transform:translate(3px);transition:opacity var(--pu-exit) var(--pu-ei),transform var(--pu-exit) var(--pu-ei)}.mi:hover>.tt,.mi:focus-visible>.tt{opacity:1;transform:none;transition:opacity var(--pu-enter) var(--pu-eo) .5s,transform var(--pu-enter) var(--pu-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(--pu-line);transition:background-color var(--pu-move) var(--pu-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(--pu-move) var(--pu-eio),opacity var(--pu-move) var(--pu-eio)}.sw:before{opacity:0;transform:translate(10px)}[aria-checked=true]>.sw{background:var(--pu-accent)}[aria-checked=true]>.sw:after{transform:translate(10px)}.all{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(--pu-exit) var(--pu-ei),opacity var(--pu-exit) var(--pu-ei)}.all.show{opacity:1;transform:none;pointer-events:auto;transition:transform var(--pu-move) var(--pu-eo),opacity var(--pu-enter) var(--pu-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(--pu-faint)}.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(--pu-muted);transition:background-color .2s var(--pu-eo)}.hs:hover,.hs:focus-visible{background:var(--pu-hover);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 .av svg{margin:0}.all .mi.done{opacity:.6}.layer.listing .col{opacity:0;transition:opacity var(--pu-exit) var(--pu-ei)}.sec{padding:8px 10px 2px;font-size:12px;color:var(--pu-faint)}.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(--pu-eo),transform .36s var(--pu-eo)}.toast.show{opacity:1;transform:translate(-50%)}@media(prefers-reduced-motion:reduce){.bub,.bub.in,.bub.in:hover,.bub.on,.tip,.pop,.selbar,.menu,.all,.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{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 Zn="#534AB7",lr="rgb(0, 0, 238)";function Qn(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 cr(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 Jn(e){let t=e.ownerDocument,n=t.defaultView;if(!n)return{font:"system-ui, sans-serif",accent:Zn,dark:!1};let o=t.documentElement,r=n.getComputedStyle(e).fontFamily||"system-ui, sans-serif",i=(n.getComputedStyle(o).getPropertyValue("--pipeup-accent")||o.style.getPropertyValue("--pipeup-accent")).trim(),s=e.querySelector("a[href]"),a=s?n.getComputedStyle(s).color:"",p=i||(a&&a!==lr?a:Zn),l=Qn(n.getComputedStyle(t.body).backgroundColor);(!l||l.a===0)&&(l=Qn(n.getComputedStyle(o).backgroundColor));let d=l&&l.a>0?cr(l)<.2:n.matchMedia?.("(prefers-color-scheme: dark)").matches===!0&&/dark/.test(n.getComputedStyle(o).colorScheme||"");return{font:r,accent:p,dark:!!d}}function eo(e,t){e.style.setProperty("--pu-font",t.font),e.style.setProperty("--pu-accent",t.accent),e.classList.toggle("dark",t.dark)}function to(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 s=new r;s.replaceSync(Zt),o.adoptedStyleSheets=[s]}else{let s=t.createElement("style");s.textContent=Zt,o.append(s)}let i=t.createElement("div");return i.className="layer",i.style.setProperty("--pu-panel",`${Ze}px`),i.style.setProperty("--pu-pop",`${Te}px`),eo(i,e),o.append(i),t.documentElement.append(n),{element:n,shadow:o,layer:i,destroy:()=>n.remove()}}var pr=40,dr=250,ur=120,mr=2400,no=4e3;function oo(e,t=!1){return jt(e,t)?"column":"bubbles"}function fr(e){return[...e.state.mode==="column"?[Un(e),zt(e,{popovers:!1})]:[zt(e,{popovers:!0})],Kn(e),zn(e)]}var hr=1e3,Et="Shown here, but not saved yet \u2014 it will be saved with your next change",Ae=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";function ro(e){let t=Jn(e.root),n=to(t),o=Gn(document,t.dark);o.fade(0);let r=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,i=document.documentElement.hasAttribute("data-pipeup-reserve"),s=new Map,a=new Set,p=new WeakSet,l={active:null,hot:null,showResolved:!1,hidden:!0,mode:oo(e.root),draft:null,commenting:!1,listing:!1,reading:!1,menu:!1},d=m("div",{class:"toast",role:"status","aria-live":"polite"});n.layer.append(d);let y=null,E=[],h=null,x=!1,v=0,w=0,L=0,T=0,A=0,P=!1;function C(c,b=mr){x||(P=b===no,d.textContent=c,d.classList.add("show"),window.clearTimeout(v),v=window.setTimeout(()=>d.classList.remove("show"),b))}function V(){P&&(P=!1,window.clearTimeout(v),d.classList.remove("show"))}function G(c){C(Ae(c))}function Y(c){throw G(c),c}let oe=c=>({thread:c,location:Dt(c.anchor,s.get(c.id)??ct(c.anchor,e.root),e.root)}),F={reply:async(c,b)=>{try{await e.doc.reply(c,b)}catch(R){R instanceof le?C(Et):Y(R)}},resolve:async c=>{try{await e.doc.resolve(c),l.active===c&&!l.showResolved&&(l.active=null),C("Resolved \xB7 Show resolved brings it back")}catch(b){b instanceof le?(l.active===c&&!l.showResolved&&(l.active=null),C(`Resolved \xB7 ${Et}`)):C(Ae(b))}},reopen:async c=>{try{await e.doc.reopen(c),C("Reopened")}catch(b){C(b instanceof le?`Reopened \xB7 ${Et}`:Ae(b))}},close:()=>{ve(null),_&&U(_)?.focus({preventScroll:!0}),_=""},copy:c=>{try{let b=e.doc.threads().find(B=>B.id===c);if(!b)return;let R=_t(oe(b),"ai",location.href,Date.now());Xt(R,n.layer).then(()=>C("Thread copied as Markdown for AI"),B=>C(Ae(B)))}catch(b){C(Ae(b))}}};function ae(c){let b=R=>s.get(R.id)?.element??null;return[...c].sort((R,B)=>{let q=b(R),ee=b(B);return!q||!ee?q?-1:ee?1:0:q===ee?0:q.compareDocumentPosition(ee)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1})}let ce={copyAll:async c=>{let b=ce.all(),R=qt(b,c,{title:document.title,url:location.href,exportedAt:new Date});try{await Xt(R,n.layer);let B=b.filter(q=>!q.thread.resolved).length;C(`Copied ${B} thread${B===1?"":"s"}${c==="ai"?" as Markdown for AI":""}`)}catch(B){C(Ae(B))}},toggleResolved:()=>{l.showResolved=!l.showResolved,O()},rename:async c=>{let b=c.replace(/\s+/g," ").trim();try{await Pe(b)?C(`New comments will say ${b}, but this browser couldn't remember it`):C(`New comments will say ${b}`)}catch(R){C(Ae(R))}},name:()=>e.doc.name,all:()=>ae(e.doc.threads()).map(oe)},j={doc:e.doc,root:e.root,layer:n.layer,host:n.element,state:l,resolved:s,pending:a,actions:F,menu:ce,visible:c=>!l.hidden&&(!c.resolved||l.showResolved),quoteAt:(c,b)=>{for(let R of e.doc.threads()){let B=s.get(R.id);if(R.anchor.quote&&j.visible(R)&&B?.range&&Rn(c,b,Ge(B)))return R}return null},readsAt:(c,b)=>j.draftEmpty()?j.quoteAt(c,b):null,owns:c=>c.composedPath().includes(n.element),claim:c=>void p.add(c),claimed:c=>p.has(c),open:ve,focusReply:c=>ge(c),hot:He,startDraft:et,moveDraft:kt,draftEmpty:()=>!y||y.isEmpty(),keepCaret:c=>{let b=y?.caret();c(),b?.()},postDraft:tt,cancelDraft:Me,setCommenting:Ce,dismiss:Fe,registerDraft:c=>{y=c},toast:C,report:G,pulse:g,render:O};function J(c){let b=performance.now(),R=e.doc.threads();for(let B of R){if(c&&!c.has(B.id))continue;let q=performance.now()-b<pr,ee=ct(B.anchor,e.root,{fuzzy:q});s.set(B.id,ee),!q&&ee.state==="orphaned"?a.add(B.id):a.delete(B.id)}for(let B of[...s.keys()])R.some(q=>q.id===B)||s.delete(B);a.size===0?(window.clearTimeout(T),T=0):T===0&&(T=window.setTimeout(()=>{T=0,!x&&(J(new Set(a)),O())},dr))}function pe(c){let b=[],R=[],B=[];for(let q of c){let ee=s.get(q.id);q.resolved&&!l.showResolved||!ee?.range||(q.id===l.active||q.id===l.hot?R.push(ee.range):q.resolved?B.push(ee.range):b.push(ee.range))}l.draft&&R.push(...l.draft.ranges),Xn({quote:b,on:R,done:B})}let te=0,u=0,N=0;function f(c){if(c===u)return;u=c,cancelAnimationFrame(N);let b=te,R=performance.now(),B=c?260:200,q=ee=>{let nt=Math.min(1,(ee-R)/B);te=b+(c-b)*(c?1-(1-nt)**3:nt*nt),o.fade(te),nt<1&&(N=requestAnimationFrame(q))};N=requestAnimationFrame(q)}let S=0,M=0;function D(c){c!==S&&(S=c,o.room(c,r),window.clearTimeout(M),M=window.setTimeout(()=>{J(),O()},r?0:400))}function O(){if(x)return;let c=e.doc.threads();l.hidden=!l.commenting&&!l.listing&&!l.reading&&!l.draft,l.hidden&&(l.active=null),f(l.hidden?0:1),n.layer.classList.toggle("hidden",l.hidden),n.layer.classList.toggle("listing",l.listing);let b=l.listing&&!Se();D(b?Ze:0),o.gutter(i?l.mode==="column"&&!l.hidden&&!b?Je:0:null),pe(c);for(let R of E)R.render(c);h?.render(c)}let _="",U=c=>n.layer.querySelector(`.all .mi[data-thread="${c}"]`),X="input,textarea,select,[contenteditable]:not([contenteditable=false])",Be=()=>{let c=n.layer.getRootNode().activeElement;return c instanceof HTMLTextAreaElement&&c.value!==""||!!document.activeElement?.matches(X)};function ge(c,b=Be()){let R=[...n.layer.querySelectorAll(`[data-thread="${c}"] .rbox textarea`)].find(B=>!B.closest("[inert]"));b||!R||(_=n.layer.getRootNode().activeElement?.getAttribute("data-thread")??"",R.focus({preventScroll:!0}))}function ve(c){if(c&&l.draft&&!j.draftEmpty())return;if(l.active===c&&!l.draft)return c?ge(c):void 0;let b=Be();c||(l.reading=!1),l.active=c,c&&(l.draft=null,g(c)),O(),c&&ge(c,b)}function He(c){l.hot!==c&&(l.hot=c,c&&c!==l.active&&g(c),O())}function et(c){V(),l.listing=!1,l.draft=c,l.active=null,O()}function kt(c){if(!l.draft)return et(c);Object.assign(l.draft,c),O()}function Me(){l.draft&&(l.draft=null,O())}function Ce(c){l.commenting!==c&&(l.commenting=c,o.picking(c),c?(l.active=null,l.listing=!1,C(`Click anything to comment \xB7 Option-click (Alt-click) to pin \xB7 ${Ye} or Esc to finish`,no),h=qn(j)):(V(),h?.destroy(),h=null),O())}function Fe(){if(l.draft){j.draftEmpty()&&Me();return}l.active&&ve(null)}async function Pe(c){try{return await e.onName(c),!1}catch(b){if(e.doc.name!==c)throw b;return!0}}async function tt(c){let b=l.draft;if(b)try{let R=await e.doc.comment(b.anchor,c);l.draft=null,J(new Set([R])),ve(R)}catch(R){if(R instanceof le){l.draft=null,J(new Set([R.id])),ve(R.id),C(Et);return}Y(R)}}function g(c){let b=s.get(c);if(!b||b.state==="orphaned")return;let R=b.range?Ge(b):b.element?[b.element.getBoundingClientRect()]:[];for(let B of R.slice(0,6)){let q=m("div",{class:"pulse"});$e(q,B,4),n.layer.prepend(q),window.setTimeout(()=>q.remove(),1300)}}function k(){for(let c of E)c.destroy();E=fr(j),O()}let $=()=>{if(!x){for(let c of E)c.frame();h?.frame(),A=requestAnimationFrame($)}},I=c=>{let b=c.composedPath()[0];return b instanceof Element&&b.closest(X)!==null},H=c=>{if(c.key==="Escape"){l.draft?Me():l.active?ve(null):h&&!h.back()&&Ce(!1);return}Cn(c)&&!c.isComposing&&!c.defaultPrevented&&!I(c)&&(c.preventDefault(),Ce(!l.commenting))},K=c=>{if(j.owns(c)||p.has(c))return;let b=window.getSelection();b&&!b.isCollapsed||Fe()},ne=()=>{let c=oo(e.root,l.mode==="column");c!==l.mode?(l.mode=c,k()):O()};function re(){let c=performance.now();w===0&&(L=c),window.clearTimeout(w);let b=Math.min(ur,Math.max(0,L+hr-c));w=window.setTimeout(()=>{w=0,J(),O()},b)}let _e=new MutationObserver(c=>{c.every(b=>n.element.contains(b.target))||re()});window.addEventListener("keydown",H),window.addEventListener("click",K),window.addEventListener("resize",ne),_e.observe(e.root,{subtree:!0,childList:!0,characterData:!0});let Oe=typeof ResizeObserver>"u"?null:new ResizeObserver(re);Oe?.observe(e.root);let Tt=e.doc.onChange(()=>{J(),O()});return J(),k(),A=requestAnimationFrame($),{ctx:j,destroy(){x=!0,cancelAnimationFrame(A),cancelAnimationFrame(N),window.clearTimeout(M),window.clearTimeout(v),window.clearTimeout(w),window.clearTimeout(T),_e.disconnect(),Oe?.disconnect(),Tt(),window.removeEventListener("keydown",H),window.removeEventListener("click",K),window.removeEventListener("resize",ne),h?.destroy();for(let c of E)c.destroy();o.remove(),n.destroy()}}}var Le=null,gr=4e3;function vr(e={}){if(Le)return Le;let t=yr(e,()=>t).catch(n=>{throw Le===t&&(Le=null),n});return Le=t,t}function wr(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 yr(e,t){let n=document.documentElement.getAttribute("data-pipeup-doc"),{id:o,key:r}=n?await Pt(n):{id:`page-${be(location.origin+location.pathname)}`,key:null},i,s=!1,a;if(e.store)i=e.store,a=await Ue(i);else try{let h=Ke.open();i=await wr(h,gr).catch(x=>{throw h.then(v=>v.close(),()=>{}),x}),a=await Ue(i)}catch{i=new Ve,s=!0,a=await Ue(i)}let p=e.name?.trim();p&&p!==a.name&&(a={...a,name:p},await i.saveProfile(a));let l=await qe.open({doc:o,key:r,store:i,identity:a.identity,name:a.name}),d=ro({doc:l,root:e.root??document.body,onName:async h=>{l.name=h,a={...a,name:h},await i.saveProfile(a)}});s&&d.ctx.toast("This browser can't keep comments for this page \u2014 copy the comments (Copy as Markdown) to keep them");let y=()=>void l.flush().catch(h=>globalThis.reportError?.(h)),E=!1;return window.addEventListener("pagehide",y),{document:l,flush:()=>l.flush(),unmount:()=>{E||(E=!0,window.removeEventListener("pagehide",y),d.destroy(),Le===t()&&(Le=null))}}}export{Ie as ANIMALS,Bt as COLOURS,gn as DEFAULT_PROFILE_NAME,Ke as IndexedDbStore,Ve as MemoryStore,qe as PipeupDocument,le as UnsavedChangeError,si as VERSION,me as animalName,qt as copyAll,_t as copyThread,St as createIdentity,lt as describeElement,Nt as describeRange,Ne as formatAgo,Re as labelOf,Ue as loadOrCreateProfile,Dt as locate,vr as mount,ie as nameOf,uo as newDocumentAttribute,Pt as parseDocumentAttribute,ct as resolveAnchor};
8
+ `}function Et(e,t){return e.deleted?"(deleted)":e.text.replace(/\r\n|\r|\n/g,`
9
+ `+t)+(e.edited?" (edited)":"")}var Oi="0.4.0-beta.2";function h(e,t={},...o){let n=document.createElement(e);for(let[r,i]of Object.entries(t))i===void 0||i===!1||(r==="class"?n.className=String(i):n.setAttribute(r,i===!0?"":i));for(let r of o)r!=null&&r!==!1&&n.append(r);return n}function ne(e,t){let o=e.getRootNode().activeElement;t&&o instanceof HTMLElement&&e.contains(o)&&o.blur(),e.inert=t}function ve(e,t){return e.length>t?e.slice(0,t-1)+"\u2026":e}function He(e,t,o=4){e.style.left=`${t.left-o}px`,e.style.top=`${t.top-o}px`,e.style.width=`${t.width+o*2}px`,e.style.height=`${t.height+o*2}px`}var er=/\bhttps?:\/\/[^\s<>"'`]+/gi,tr=`.,;:!?'"]}`,nr=2048,or=/[\u202A-\u202E\u2066-\u2069]/;function rr(e){let t=0,o=0;for(let r of e)r==="("?t++:r===")"&&o++;let n=e.length;for(;n>0;){let r=e[n-1];if(r===")"&&o>t)o--;else if(!tr.includes(r))break;n--}return e.slice(0,n)}function kt(e){let t=[],o=0;for(let n of e.matchAll(er)){if(n[0].length>nr||or.test(n[0]))continue;let r=rr(n[0]),i=n.index??0,a;try{let d=new URL(r);if(d.protocol!=="http:"&&d.protocol!=="https:")continue;a=d.href}catch{continue}i>o&&t.push(e.slice(o,i));let s=h("a",{href:a,target:"_blank",rel:"noopener noreferrer"},r);s.addEventListener("click",d=>d.stopPropagation()),t.push(s),o=i+r.length}return o<e.length&&t.push(e.slice(o)),t}var we={code:"KeyC",mods:{shift:!0,alt:!0,meta:!1,ctrl:!1},mac:{label:"\u21E7\u2325C",aria:"Shift+Alt+C"},other:{label:"Shift+Alt+C",aria:"Shift+Alt+C"}},qn=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform),Qe=(qn?we.mac:we.other).label,en=(qn?we.mac:we.other).aria;function Un(e){return e.code===we.code&&e.shiftKey===we.mods.shift&&e.altKey===we.mods.alt&&e.metaKey===we.mods.meta&&e.ctrlKey===we.mods.ctrl&&!e.repeat&&!e.getModifierState("AltGraph")}var zn="http://www.w3.org/2000/svg",ir={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"],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 Q(e,t=15,o){let n=tn(ir[e],t);return o&&n.setAttribute("stroke-width",String(o)),n}function tn(e,t){let o=document.createElementNS(zn,"svg"),n={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,i]of Object.entries(n))o.setAttribute(r,i);for(let r of e){let i=document.createElementNS(zn,"path");i.setAttribute("d",r),o.append(i)}return o}var St=(e,t,o)=>`M${e} ${t}a${o} ${o} 0 1 0 ${2*o} 0a${o} ${o} 0 1 0 -${2*o} 0`,sr={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${St(7.4,11.5,1.9)}${St(12.8,11.5,1.9)}M11.3 14.6l.7 1 .7-1`,Bear:`${St(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:`${St(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 Kn(e){let t=/[\p{L}\p{N}]/u.exec(e);if(!t)return"";let o=t[0].toUpperCase();return[...o].length===1?o:t[0]}var et=(e,t)=>Kn(t)||ge(e);function Le(e,t){return h("span",{class:`av c${Jt(e)}`,"aria-hidden":"true","data-animal":ge(e)},Kn(t)||tn([sr[$e[Xt(e)]]],24))}var ar=320;function Tt(e,t){setTimeout(()=>{e.remove(),t?.()},ar)}function At(e){return requestAnimationFrame(()=>{e.offsetWidth,e.classList.add("in")}),e}function Lt(e){let t=h("textarea",{class:"input",rows:"1","aria-label":e.label}),o=h("button",{class:"send",type:"button","aria-label":"Send",title:"Send"},Q("send")),n=h("div",{class:"row"},e.before,t,o),r=!1,i=()=>{o.classList.toggle("show",t.value.trim()!==""),t.style.height="auto",t.style.height=`${Math.max(27,t.scrollHeight)}px`},a=async()=>{let s=t.value.trim();if(!(!s||r)){r=!0;try{await e.M(s),t.value="",i()}catch{}finally{r=!1}}};return n.addEventListener("mousedown",s=>{s.target===t||o.contains(s.target)||(s.preventDefault(),t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}),t.addEventListener("input",i),t.addEventListener("keydown",s=>{s.stopPropagation(),s.key==="Enter"&&!s.shiftKey&&!s.isComposing?(s.preventDefault(),a()):s.key==="Escape"&&(s.preventDefault(),t.value="",i(),t.blur(),e.C?.())}),o.addEventListener("click",s=>{s.stopPropagation(),a()}),{element:n,input:t,focus:()=>t.focus({preventScroll:!0}),clear:()=>{t.value="",i()}}}function lr(e){let t=h("button",{class:"me",type:"button",tabindex:"-1","aria-hidden":"true"});t.addEventListener("mousedown",y=>y.preventDefault());let o=Lt({label:"Comment",before:t,M:e.M,C:e.C}),n=h("div",{class:"say"}),r=h("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"}),i=h("div",{class:"nf"},r),a=h("div",{class:"you"},n,i),s="",d=!1,c=()=>{let y=e.name(),w=y?"change":"add your name";if(t.title=y?"Change your name":"Add your name",!t.lastChild||s!==y){let b=Le(e.me,y),v=t.lastChild;v?(At(b),Tt(v)):b.classList.add("in"),t.append(b),s=y}let A=h("button",{type:"button"},w);A.addEventListener("click",x),n.replaceChildren(h("span",{class:"nm"},y||`You're ${ge(e.me)}`)," \xB7 ",A)},p=y=>{a.classList.toggle("naming",y),ne(n,y),ne(i,!y)};function x(y){y.stopPropagation(),r.value=e.name(),p(!0),r.focus({preventScroll:!0}),r.select()}let T=()=>{p(!1),o.focus()};t.addEventListener("click",x),r.addEventListener("keydown",y=>{if(y.stopPropagation(),y.key==="Escape")y.preventDefault(),T();else if(y.key==="Enter"){y.preventDefault();let w=r.value.trim();if(!w||w===e.name())return T();if(d)return;d=!0,e.rename(w).finally(()=>{d=!1,c(),T()})}}),c(),p(!1);let f=h("div",{class:"ctx"},e.label);return{element:h("div",{class:"draft"},f,o.element,a),G:()=>{let{selectionStart:y,selectionEnd:w}=o.input;return()=>{o.focus(),o.input.setSelectionRange(y,w)}},O:y=>{f.hidden=y},D:y=>{f.textContent=y},focus:()=>o.focus(),X:()=>o.input.value.trim()===""}}function Mt(e,t){let o=lr({label:t.label,me:e.doc.me,name:()=>e.l.name(),rename:n=>e.l.rename(n),M:n=>e.J(n),C:()=>e.Z()});return e.L(o),o}function Ct(e,t){if(t.state==="orphaned"||!t.element||e.quote)return null;let o=t.element.getBoundingClientRect();if(!o.width&&!o.height)return null;if(e.point)return{x:o.left+e.point.x*o.width,y:o.top+e.point.y*o.height};let n=t.element.ownerDocument.createRange();n.selectNodeContents(t.element);let r=n.getBoundingClientRect();return{x:r.width?Math.min(o.right-8,r.right+6):o.right-8,y:(r.height?r.top:o.top)+8}}function tt(e){return e.range?[...e.range.getClientRects()]:[]}function nn(e,t){let o=tt(t)[0];if(o)return o.top;if(t.state==="orphaned"||!t.element)return null;let n=t.element.getBoundingClientRect();return e.point?n.top+e.point.y*n.height:n.top}function nt(e,t){let o=tt(t).at(-1);if(o)return{x:o.left,y:o.bottom,below:!0};let n=Ct(e,t);return n?{...n,below:!1}:null}function Wn(e,t,o){for(let n of o)if(e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom)return!0;return!1}function jn(e,t,o=10){let n=[...e].sort((s,d)=>s.u-d.u),r=new Array(n.length).fill(0),i=n.findIndex(s=>s.id===t),a=s=>n[s];if(i<0)n.forEach((s,d)=>{r[d]=d===0?s.u:Math.max(s.u,(r[d-1]??0)+a(d-1).height+o)});else{r[i]=a(i).u;for(let s=i+1;s<n.length;s++)r[s]=Math.max(a(s).u,(r[s-1]??0)+a(s-1).height+o);for(let s=i-1;s>=0;s--)r[s]=Math.min(a(s).u,(r[s+1]??0)-a(s).height-o)}return new Map(n.map((s,d)=>[s.id,r[d]??0]))}var ot=320,Me=300,cr=480,Ce=()=>window.innerWidth<=cr;function Pt(e){let t=window.innerWidth;return{width:e&&!Ce()?t-ot:t,height:window.innerHeight}}function Ot(e,t,o,n=12){let r,i;return e.below?(r=Math.min(e.x,o.width-t.width-n),i=e.y+8,i+t.height>o.height-n&&(i=e.y-t.height-40)):(r=e.x+14,r+t.width>o.width-n&&(r=e.x-t.width-28),i=Math.min(e.y-12,o.height-t.height-n)),{left:Math.max(n,r),top:Math.max(n,i)}}function Yn(e,t,o,n=12,r=44){let i=e.top-r>=8,a=e.top+e.height+8+(i?0:r),s=e.top-8-(i?r:0)-t.height,d=a+t.height<=o.height-n||s<n,c=d?a:s;return{above:!d,left:Math.max(n,Math.min(e.left,o.width-t.width-n)),top:Math.max(n,c)}}function Rt(e,t,o){let n=e.top-t.height-10;return n<8&&(n=e.top+e.height+10),{left:Math.max(8,Math.min(e.left+e.width/2-t.width/2,o.width-t.width-8)),top:n}}var Gn=e=>`${e} ${e===1?"reply":"replies"}`;function Be(e,t,o){let n={...o},r=e.id,i=h("div",{class:"rbox always"},h("div",{},Lt({label:"Reply",M:w=>t.reply(r,w),C:t.close}).element)),a=h("div",{}),s=h("div",{}),d=null,c=h("div",{},s,h("div",{class:"more"},a)),p=new Map,x=new Map,T=new Map,f=w=>{let A=et(w.author,w.name),b=p.get(w.id),v=b?.el;if((!v||b.key!==A)&&(v=At(Le(w.author,w.name)),b)){let I=b.el;T.set(w.id,I),Tt(I,()=>T.get(w.id)===I&&T.delete(w.id))}v.title=ie(w),x.set(w.id,{key:A,el:v});let L=T.get(w.id);return L?[L,v]:[v]},S=(w,A,b)=>{let v=h("button",{class:"ib",type:"button","aria-label":A,title:A},Q(w));return v.addEventListener("click",L=>{L.stopPropagation(),b()}),v};function y(w,A={}){Object.assign(n,A),r=w.id;let b=(n.now??Date.now)(),v=w.root.replies.length,L=j=>h("span",{class:"who"},`${ie(j)} \xB7 ${De(j.at,b)}`),I=j=>h("div",{class:j.deleted?"tx del":"tx"},...j.deleted?["Deleted"]:[...kt(j.text),j.edited?" (edited)":""]),z=w.resolved?"Resolved"+(v?` \xB7 ${Gn(v)}`:""):v?Gn(v):"",W=h("div",{class:n.R==="column"&&z?"ft has-rest":"ft"},n.R==="column"&&z?h("span",{class:"rest"},z):null,h("span",{class:"hover"},L(w.root),h("span",{class:"acts"},S("copy","Copy thread",()=>t.copy(w.id)),w.resolved?S("reopen","Reopen",()=>void t.reopen(w.id)):S("resolve","Resolve",()=>void t.resolve(w.id))))),K=n.lost?h("div",{class:"ctx"},`${n.place||"No longer on the page"} \u2014 it read \u201C${ve(n.lost,120)}\u201D`):n.quote?h("div",{class:"ctx"},`\u201C${ve(n.quote,80)}\u201D`):null;x=new Map;let H=h("div",{class:"root"},...f(w.root),K,I(w.root),W);s.replaceWith(H),s=H,d?.remove(),d=v?h("div",{class:"rps"},...w.root.replies.map(j=>h("div",{class:"it"},...f(j),I(j),h("div",{class:"rft"},L(j))))):null,d&&a.prepend(d),p=x,w.resolved?i.remove():i.parentNode!==a&&a.append(i),c.className=w.resolved?"thread resolved":"thread",c.setAttribute("data-thread",w.id)}return y(e),{element:c,update:y}}var dr="a,button,input,select,textarea,label,summary,[role=button],[contenteditable]",pr=400;function on(e,t){let o=new Map,n=h("div",{class:"tip",role:"tooltip"}),r=h("div",{class:"mark"}),i=h("div",{class:"pop",role:"dialog","aria-label":"Comment thread"});n.inert=i.inert=!0,e.n.append(r,n,i);let a=h("div",{class:"bub pin ghost","aria-hidden":"true"}),s=[],d=null,c=null,p=null,x=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,T=0,f=null,S=null,y=null,w=0,A=g=>s.find(M=>M.id===g)??null,b=()=>t.H||e.state.o,v=!1,L=g=>{let M=e.resolved.get(g.id);return M?nt(g.anchor,M):null};function I(g,M,R){let{left:B,top:Y}=Ot(M,{width:g.offsetWidth||R,height:g.offsetHeight},Pt(e.state.o));g.style.left=`${B}px`,g.style.top=`${Y}px`}function z(g){let M=g&&b()&&e.state.t!==g?A(g):null,R=M?L(M):null;if(!M||!R){y=null,n.classList.remove("show"),ne(n,!0);return}if(y!==M.id){let B=M.root.replies.length;n.replaceChildren(h("div",{class:"tx clamp"},...M.root.deleted?["Deleted"]:kt(M.root.text)),h("div",{class:"who"},`${ie(M.root)}${B?` \xB7 ${B} ${B===1?"reply":"replies"}`:""}`)),y=M.id}I(n,R,260),n.classList.contains("show")||n.offsetWidth,n.classList.add("show"),n.inert=!1}function W(g){f=g,z(g),e.m(g)}function K(g){if(window.clearTimeout(w),g!==null){W(g);return}w=window.setTimeout(()=>W(null),b()?pr:0)}n.addEventListener("mouseenter",()=>window.clearTimeout(w)),n.addEventListener("mouseleave",()=>K(null)),n.addEventListener("click",g=>{g.stopPropagation();let M=y;M&&(window.clearTimeout(w),W(null),e.open(M))});function H(g){let M=o.get(g.id);if(M)return M;let R=h("button",{class:"bub",type:"button","aria-label":`Comment: ${ve(g.root.text,60)}`});return R.addEventListener("mouseenter",()=>K(g.id)),R.addEventListener("mouseleave",()=>K(null)),R.addEventListener("click",B=>{B.stopPropagation(),z(null),e.open(g.id)}),e.n.insertBefore(R,r),o.set(g.id,R),R}let j=!1;function X(){let g=e.state.e,M=p&&g&&!g.anchor.quote&&!g.anchor.point?g.resolved.element:null;if(M){let{left:B,top:Y,above:F}=Yn(M.getBoundingClientRect(),{width:i.offsetWidth||Me,height:i.offsetHeight},{width:window.innerWidth,height:window.innerHeight}),J=p?.above!==null&&p?.above!==F;if(p&&(p.above=F),J&&pe())return;i.style.left=`${B}px`,i.style.top=`${Y}px`;return}let R=p&&g?nt(g.anchor,g.resolved):d?L(d):null;R&&I(i,R,Me)}let re=g=>e.state.s&&!g.anchor.quote&&!g.anchor.point;function pe(){return window.clearTimeout(T),x?(i.classList.remove("show"),T=window.setTimeout(()=>{X(),i.classList.add("show")},220),!0):(i.classList.add("glide"),T=window.setTimeout(()=>i.classList.remove("glide"),450),!1)}function ue(g){if(window.clearTimeout(T),x){i.classList.remove("show"),T=window.setTimeout(()=>{p?.i.D(g),X(),i.classList.add("show")},220);return}p?.i.D(g),i.classList.add("glide"),T=window.setTimeout(()=>i.classList.remove("glide"),450)}function ye(){if(!b())return null;let g=e.state.e;return g?g.anchor.quote||g.anchor.point||e.state.s?null:g.resolved.element:!d||d.anchor.quote||d.anchor.point?null:e.resolved.get(d.id)?.element??null}function se(g){s=g;let M=new Set;for(let F of g){if(!e.I(F)||F.anchor.quote)continue;let J=e.resolved.get(F.id);if(!J||J.state==="orphaned")continue;M.add(F.id);let oe=H(F);oe.classList.toggle("done",F.resolved),oe.classList.toggle("on",e.state.t===F.id),oe.classList.toggle("pin",F.anchor.point!==void 0)}for(let[F,J]of o)M.has(F)||(J.classList.remove("in"),o.delete(F),window.setTimeout(()=>J.remove(),300));z(f),v!==e.state.o&&i.classList.contains("show")&&!x&&(window.clearTimeout(T),i.classList.add("glide"),T=window.setTimeout(()=>i.classList.remove("glide"),450)),v=e.state.o;let R=t.H?e.state.e:null;if(R){p?.of!==R?(window.clearTimeout(T),i.classList.remove("glide"),p={i:Mt(e,R),of:R,at:R.resolved.element,above:null},p.i.O(re(R)),i.replaceChildren(p.i.element),i.inert=!1,p.i.focus(),d=null,c=null,X(),i.classList.add("show")):p&&(p.at!==R.resolved.element&&(p.at=R.resolved.element,p.above=null,ue(R.label)),p.i.O(re(R)));let F=!e.c.f(R.anchor.view);F!==j&&(j=F,i.classList.toggle("show",!F),i.inert=F,F||X());return}p&&(window.clearTimeout(T),i.classList.remove("glide"),p=null,j=!1,e.L(null));let B=b()&&e.state.t?A(e.state.t):null;if(!B||!e.I(B)){d=null,c=null,i.classList.remove("show"),ne(i,!0);return}let Y=B.anchor.quote?.exact??null;!d||!c||d.id!==B.id?(c=Be(B,e.N,{R:"popover",quote:Y}),i.replaceChildren(c.element),d=B,X(),i.classList.add("show"),i.inert=!1):d!==B&&(c.update(B,{quote:Y}),d=B)}function u(){for(let[B,Y]of o){let F=A(B),J=e.resolved.get(B),oe=F&&J?Ct(F.anchor,J):null;if(!oe||oe.y<-40||oe.y>window.innerHeight+40){Y.style.visibility="hidden";continue}Y.style.visibility="",Y.style.left=`${oe.x}px`,Y.style.top=`${oe.y}px`,Y.classList.contains("in")||(Y.offsetWidth,Y.classList.add("in"))}let g=e.state.e,M=g?.anchor.point&&e.c.f(g.anchor.view)?Ct(g.anchor,g.resolved):null;M?(a.style.left=`${M.x}px`,a.style.top=`${M.y}px`,a.classList.contains("in")||(e.n.insertBefore(a,r),a.offsetWidth,a.classList.add("in"))):a.classList.contains("in")&&(a.classList.remove("in"),window.setTimeout(()=>a.classList.contains("in")||a.remove(),300)),i.classList.contains("show")&&X();let R=ye();r.classList.toggle("show",R!==null),R&&He(r,R.getBoundingClientRect(),4)}let V=g=>{if(e.w(g)){let R=g.composedPath()[0];S!==null&&!(R instanceof Element&&R.closest(".tip,.bub"))&&K(null),S=null;return}let M=e.B(g.clientX,g.clientY)?.id??null;M!==S&&(S=M,K(M))},U=g=>{if(e.w(g))return;let M=window.getSelection();if(M&&!M.isCollapsed||(e.state.s?g.altKey:g.target instanceof Element&&g.target.closest(dr)))return;let R=e.B(g.clientX,g.clientY);R&&(e.U(g),z(null),e.open(R.id))};return window.addEventListener("pointermove",V,{capture:!0,passive:!0}),window.addEventListener("click",U,!0),{d:se,k:u,destroy(){window.clearTimeout(w),window.clearTimeout(T),window.removeEventListener("pointermove",V,!0),window.removeEventListener("click",U,!0),e.L(null);for(let g of o.values())g.remove();a.remove(),n.remove(),r.remove(),i.remove()}}}var ur="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}]`),mr=["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",...ur].join(","),fr="a,button,label,summary,[role=button],[role=link],[role=tab],[role=option],[role=menuitem]",hr=.6,It=2,Xn=(e,t)=>Math.abs(e.left-t.left)<=It&&Math.abs(e.top-t.top)<=It&&Math.abs(e.width-t.width)<=It&&Math.abs(e.height-t.height)<=It;function rt(e,t,o){if(e===t||!t.contains(e)||e.closest("[data-pipeup-ignore]"))return null;let n=o.F(),r=hr*n.width*n.height,i=null;for(let s=e;s&&s!==t;s=s.parentElement){let d=o.i(s);if(!(d.width<2||d.height<2)){if(s.hasAttribute("data-pipeup-id")){i=s;break}if(!(d.width*d.height>r)&&(s.matches(mr)||o.Q(s)||s.childElementCount>1&&!s.parentElement?.closest(fr)&&o.ee(s))){i=s;break}}}if(!i||i.hasAttribute("data-pipeup-id"))return i;let a=o.i(i);for(let s=i.parentElement;s&&s!==t&&Xn(o.i(s),a);s=s.parentElement)if(s.hasAttribute("data-pipeup-id"))return s;return i}function rn(e,t,o){let n=o.i(e);for(let r=e.parentElement;r&&r!==t;){let i=rt(r,t,o);if(!i)return null;if(!Xn(o.i(i),n))return i;r=i.parentElement}return null}function Jn(e=window){return{i:t=>t.getBoundingClientRect(),Q:t=>{let o=e.getComputedStyle(t),n=o.backgroundColor!=="transparent"&&!/,\s*0\)$/.test(o.backgroundColor),r=["top","right","bottom","left"].some(i=>parseFloat(o.getPropertyValue(`border-${i}-width`))>0);return n||r||o.backgroundImage!=="none"||o.boxShadow!=="none"},ee:t=>/^(inline-)?(flex|grid)$/.test(e.getComputedStyle(t).display),F:()=>({width:e.innerWidth,height:e.innerHeight})}}var eo="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]",gr=`${eo},input,select,textarea,[contenteditable]:not([contenteditable=false]),[tabindex]:not([tabindex="-1"])`,Zn=["click","dblclick","auxclick","submit","contextmenu","dragstart"],Qn=[...["over","out","enter","leave","down","up"].flatMap(e=>[`pointer${e}`,`mouse${e}`]),"mousemove","touchstart","touchmove","touchend","touchcancel"],vr=400;function to(e,t=Jn()){let o=h("div",{class:"pick"});e.n.append(o);let n=h("span",{class:"lbl"}),r=h("button",{class:"nb",type:"button","aria-label":"Select the block around it",title:"Select the block around it"},Q("expand",16)),i=h("div",{class:"namebar",role:"toolbar","aria-label":"Chosen block"},n,r);i.inert=!0,e.n.append(i),i.addEventListener("mousedown",u=>u.preventDefault()),r.addEventListener("click",u=>{u.stopPropagation();let V=d&&rn(d,e.root,t);V&&K(V)});let a=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,s=null,d=null,c=null,p=null,x=0,T=()=>{},f=null,S=()=>{},y=u=>!e.w(u)&&!(u.target instanceof Element&&u.target.closest("[data-pipeup-ignore]"));function w(){p&&(o.classList.toggle("glide",performance.now()<x),He(o,p.getBoundingClientRect(),4))}function A(){if(!f)return;i.classList.toggle("glide",performance.now()<x&&i.classList.contains("show"));let u=f.getBoundingClientRect(),{left:V,top:U}=Rt({left:u.left,top:u.top,width:u.width,height:u.height},{width:i.offsetWidth||200,height:i.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});i.style.left=`${V}px`,i.style.top=`${U}px`}function b(u,V){p=u,x=V?performance.now()+vr:0,w(),o.classList.add("show")}function v(u,V){let U=getComputedStyle(u);if(U.opacity==="0")return V(),()=>{};let g=0,M=()=>{window.clearTimeout(g),u.removeEventListener("transitionend",B)},R=()=>{M(),V()},B=F=>{F.target===u&&F.propertyName==="opacity"&&R()},Y=Math.max(...U.transitionDuration.split(",").map(F=>parseFloat(F)*1e3||0));return g=window.setTimeout(R,Y+100),u.addEventListener("transitionend",B),M}function L(u){if(u!==s){if(s=u,T(),!u){o.classList.remove("show");return}getComputedStyle(o).opacity==="0"?b(u,!1):a?(o.classList.remove("show"),T=v(o,()=>b(u,!1))):b(u,!0)}}function I(u){d=u,o.classList.toggle("on",u!==null),L(u),S(),i.inert=!u,u?a?(i.classList.remove("show"),S=v(i,()=>z(u))):z(u):(i.classList.remove("show"),f=null)}function z(u){n.textContent=n.title=Ne(u);let V=rn(u,e.root,t)===null;r.hidden=V;let U=i.classList.contains("show");f=u,A(),U||(i.offsetWidth,i.classList.add("show"))}function W(u){let V;try{V=yt(u,e.root,void 0,e.c.view(u))}catch(M){e.V(M);return}let U={anchor:V,label:Ne(u),ranges:[],resolved:{state:"attached",element:u,range:null}},g=e.state.e;I(u),c=g??{...U,ranges:[]},g?e.te({...U,ranges:[]}):e._(c)}function K(u){e.ne(()=>W(u))}function H(u){let V=(u.target instanceof Element?rt(u.target,e.root,t):null)??e.root,U=V.getBoundingClientRect();if(!U.width||!U.height)return;let g={x:(u.clientX-U.left)/U.width,y:(u.clientY-U.top)/U.height},M;try{M=yt(V,e.root,g,e.c.view(V))}catch(B){e.V(B);return}let R=Ne(V).replace(/^[A-Z](?=[a-z])/,B=>B.toLowerCase());I(null),L(null),e._({anchor:M,label:`Pin on ${R}`,ranges:[],resolved:{state:"attached",element:V,range:null}})}function j(u){let V=window.getSelection();if(V&&!V.isCollapsed)return;if(e.state.e&&(u.altKey||!e.S())){e.$();return}if(!u.altKey&&e.B(u.clientX,u.clientY))return;if(e.state.t&&e.open(null),u.altKey){H(u);return}let U=u.target instanceof Element?rt(u.target,e.root,t):null;U?W(U):(e.$(),I(null))}let X=u=>{if(!e.w(u)){if(!y(u)){d||L(null);return}u.stopPropagation(),!(d||e.state.e)&&L(!re()&&u.target instanceof Element?rt(u.target,e.root,t):null)}},re=()=>{let u=window.getSelection();return!!u&&!u.isCollapsed&&u.toString().trim()!==""},pe=()=>{!d&&re()&&L(null)},ue=u=>{y(u)&&(u.stopPropagation(),(u.type==="pointerdown"||u.type==="mousedown")&&u.target instanceof Element&&u.target.closest(gr)&&u.preventDefault())},ye=u=>{y(u)&&(u.preventDefault(),u.stopPropagation(),u.type==="click"&&!e.state.l&&!e.oe(u)&&j(u))},se=u=>{(u.key==="Enter"||u.key===" ")&&y(u)&&u.target instanceof Element&&u.target.closest(eo)&&(u.preventDefault(),u.stopPropagation())};window.addEventListener("pointermove",X,!0),document.addEventListener("selectionchange",pe);for(let u of Qn)window.addEventListener(u,ue,!0);for(let u of Zn)window.addEventListener(u,ye,!0);return window.addEventListener("keydown",se,!0),{back(){return d?(I(null),!0):!1},d(){let u=e.state.e;c&&u!==c?(c=null,I(null)):u&&!c&&(s||d)&&I(null)},k(){w(),A()},destroy(){T(),S(),window.removeEventListener("pointermove",X,!0),document.removeEventListener("selectionchange",pe);for(let u of Qn)window.removeEventListener(u,ue,!0);for(let u of Zn)window.removeEventListener(u,ye,!0);window.removeEventListener("keydown",se,!0),o.classList.remove("show"),i.classList.remove("show"),ne(i,!0),v(o,()=>o.remove()),v(i,()=>i.remove())}}}var wr=300,yr=32,sn=220,it=320,br=24,no=24;function an(e,t=!1){let o=e.ownerDocument.documentElement,n=o.getAttribute("data-pipeup-layout");if(n==="bubbles"||e.querySelector("[data-pipeup-slide]"))return null;let r=e.querySelector("article, main, [role=main]")??(n==="column"?e:null);if(!r)return null;if(o.hasAttribute("data-pipeup-reserve")){let s=o.clientWidth,c=getComputedStyle(r).maxWidth,p;return c.endsWith("px")?p=parseFloat(c):c.endsWith("%")?p=parseFloat(c)/100*s:p=r.getBoundingClientRect().width,n!=="column"&&s<p+it-(t?br:0)?null:{x:s-it+no,width:it-2*no}}let i=r.getBoundingClientRect().right;if(window.innerWidth-i<wr&&n!=="column")return null;let a=i+yr;return{x:a,width:Math.max(220,Math.min(300,window.innerWidth-a-16))}}function ln(e,t){let o=e.resolved.get(t.id);return!o||o.state==="orphaned"&&!e.z.has(t.id)}function oo(e){let t=h("div",{class:"col"});e.n.append(t);let o=new Map,n=null,r=new ResizeObserver(()=>s()),i=f=>ln(e,f);function a(f){let S=e.resolved.get(f.id),y=S?nn(f.anchor,S):null;return y===null?Number.POSITIVE_INFINITY:y+window.scrollY-4}function s(){let f=[],S=[];for(let[v,L]of o){let I=a(L.thread);if(Number.isFinite(I))L.placed=I;else if(e.z.has(v)){if(L.placed===null){L.el.classList.add("wait");continue}I=L.placed}Number.isFinite(I)?f.push({id:v,u:I,height:L.el.offsetHeight}):S.push({id:v,height:L.el.offsetHeight})}let y=e.state.e,w=y?nn(y.anchor,y.resolved):null;n&&w!==null&&f.push({id:"draft",u:w+window.scrollY-4,height:n.el.offsetHeight});let A=jn(f,n?"draft":e.state.t),b=Math.max(0,...f.map(v=>(A.get(v.id)??0)+v.height))+24;for(let v of S)A.set(v.id,b),b+=v.height+10;for(let[v,L]of o){if(L.el.classList.contains("wait")){if(!A.has(v))continue;L.el.style.transition="none",L.el.style.transform=`translateY(${Math.round(A.get(v))}px)`,L.el.offsetWidth,L.el.style.transition="",L.el.classList.remove("wait");continue}L.el.style.transform=`translateY(${Math.round(A.get(v)??0)}px)`}n&&(n.el.style.transform=`translateY(${Math.round(A.get("draft")??0)}px)`)}function d(f,S){f.thread=S,f.lost=i(S),f.view.update(S,{lost:f.lost?S.anchor.snapshot:null})}function c(f){let S=i(f),y=Be(f,e.N,{R:"column",lost:S?f.anchor.snapshot:null}),w=h("div",{class:"th","data-thread":f.id},y.element);return w.style.transition="none",w.addEventListener("mouseenter",()=>e.m(f.id)),w.addEventListener("mouseleave",()=>e.m(null)),w.addEventListener("click",()=>e.open(f.id)),t.append(w),r.observe(w),{el:w,thread:f,lost:S,placed:null,view:y}}function p(){let f=e.state.e;if(n&&f&&n.of!==f){let S=n.el;r.unobserve(S),S.classList.add("out"),window.setTimeout(()=>S.remove(),sn),n=null}if(f&&n&&(n.i.D(f.label),n.i.O(e.state.s&&!f.anchor.quote&&!f.anchor.point)),f&&!n){let S=Mt(e,f),y=h("div",{class:"th on"},S.element);y.style.transition="none",t.append(y),r.observe(y),n={el:y,i:S,of:f},S.O(e.state.s&&!f.anchor.quote&&!f.anchor.point),S.focus()}else if(!f&&n){let S=n.el;r.unobserve(S),S.classList.add("out"),window.setTimeout(()=>S.remove(),sn),n=null,e.L(null)}}function x(f){ne(t,e.state.o);let S=new Set,y=[],w=e.state.t!==null||e.state.e!==null;for(let A of f){if(!e.I(A))continue;S.add(A.id);let b=o.get(A.id);b?(b.thread!==A||b.lost!==i(A))&&d(b,A):(b=c(A),o.set(A.id,b),y.push(b.el));let v=b.el;v.classList.toggle("on",e.state.t===A.id);let L=v.querySelector(".more");L&&ne(L,e.state.t!==A.id),v.classList.toggle("dim",w&&e.state.t!==A.id),v.classList.toggle("hot",e.state.m===A.id&&e.state.t!==A.id),v.classList.toggle("resolved",A.resolved),v.classList.toggle("lost",b.lost)}for(let[A,b]of o)S.has(A)||(o.delete(A),r.unobserve(b.el),b.el.classList.add("out"),window.setTimeout(()=>b.el.remove(),sn));p(),s(),n&&y.push(n.el);for(let A of y)A.offsetWidth,A.style.transition=""}function T(){let f=an(e.root,!0);f&&(t.style.width=`${f.width}px`,t.style.transform=`translate(${f.x}px, ${-window.scrollY}px)`)}return{d:x,k:T,destroy(){r.disconnect(),e.L(null),t.remove()}}}var xr="[data-pipeup-ignore],input,textarea,select,[contenteditable]:not([contenteditable=false])";function ro(e){let t=h("button",{type:"button","aria-label":"Comment",title:"Comment"},Q("comment",17)),o=h("div",{class:"selbar"},t);o.inert=!0,e.n.append(o);let n=null,r=p=>{let x=p&&(p.nodeType===Node.ELEMENT_NODE?p:p.parentElement);return!!x&&e.root.contains(x)&&!x.closest(xr)};function i(){if(!n)return;let p=n.getBoundingClientRect(),{left:x,top:T}=Rt({left:p.left,top:p.top,width:p.width,height:p.height},{width:o.offsetWidth||36,height:o.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});o.style.left=`${x}px`,o.style.top=`${T}px`}function a(){n=null,o.inert=!0,o.classList.remove("show")}function s(){let p=window.getSelection();if(!e.state.s||!p||p.isCollapsed||p.rangeCount===0||!p.toString().trim()||!r(p.anchorNode)||!r(p.focusNode)){a();return}n=p.getRangeAt(0).cloneRange(),i(),o.inert=!1,o.classList.add("show")}t.addEventListener("mousedown",p=>p.preventDefault()),t.addEventListener("click",p=>{if(p.stopPropagation(),e.state.e&&!e.S())return e.$();let x=n;if(!x)return;let T;try{T=Wt(x,e.root,e.c.view(x.commonAncestorContainer))}catch(S){e.V(S),a();return}let f=ve(x.toString().replace(/\s+/g," ").trim(),60);window.getSelection()?.removeAllRanges(),a(),e._({anchor:T,label:`\u201C${f}\u201D`,ranges:[x],resolved:{state:"attached",element:null,range:x}})});let d=()=>{if(!n)return;let p=window.getSelection();(!p||p.isCollapsed||!p.toString().trim())&&a()};document.addEventListener("selectionchange",d);let c=p=>{e.w(p)||window.setTimeout(s,0)};return window.addEventListener("mouseup",c,!0),window.addEventListener("keyup",c,!0),{d(){!e.state.s&&n&&a()},k(){n&&i()},destroy(){window.removeEventListener("mouseup",c,!0),window.removeEventListener("keyup",c,!0),document.removeEventListener("selectionchange",d),o.remove()}}}async function cn(e,t){try{await navigator.clipboard.writeText(e);return}catch{}let o=document.createElement("textarea");o.value=e,o.setAttribute("readonly",""),o.style.cssText="position:fixed;opacity:0;pointer-events:none",t.append(o),o.select();let n=document.execCommand("copy");if(o.remove(),!n)throw new Error("pipeup: your browser blocked copying")}var Er=3e3,io="Hidden on the page";function so(e){let t=[h("span",{class:"n"}),h("span",{class:"n"})],o=Q("comment",20,1.4);o.lastElementChild.setAttribute("stroke-width","1.6");let n=h("button",{class:"mode",type:"button","aria-label":"Comment","aria-keyshortcuts":en,"aria-haspopup":"menu","aria-expanded":"false"},h("span",{class:"plus"},o),h("span",{class:"cnt"},Q("bubble",34,1.4),...t),h("span",{class:"dot"})),r=document.createTextNode("Comment"),i=h("span",{class:"ttip","aria-hidden":"true"},r,h("small",{},Qe)),a=h("div",{class:"launch"},n,i),s=h("div",{class:"menu",role:"menu","aria-label":"Comments"}),d=h("div",{class:"list",role:"menu","aria-label":"All comments"}),c=h("span",{class:"pn"}),p=h("button",{class:"ib",type:"button","aria-label":"Close"},Q("close")),x=h("button",{class:"hs",type:"button",role:"switch","aria-checked":"false"},"Show resolved",h("span",{class:"sw","aria-hidden":"true"}));x.addEventListener("click",m=>{m.stopPropagation(),e.l.re()});let T=h("div",{class:"all",role:"dialog","aria-label":"All comments"},h("div",{class:"hd"},h("span",{},"All comments"),c,x,p),d),f=h("div",{class:"pop side",role:"dialog","aria-label":"Comment thread"});s.inert=T.inert=f.inert=!0,e.n.append(s,a,T);let S=!1,y=null,w=0,A=[],b=0,v=null,L=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,I=m=>{S=e.state.l=m,window.clearTimeout(w),w=0,m||y?.(!0),s.classList.toggle("show",m),ne(s,!m),n.setAttribute("aria-expanded",String(m))},z=(m,E=!1)=>{e.state.o!==m&&(e.state.o=m,e.d(),m?(W(d)[0]??p).focus({preventScroll:!0}):E&&n.focus({preventScroll:!0}))},W=(m=s)=>[...m.querySelectorAll(".mi")],K=()=>s.getRootNode().activeElement,H=()=>{I(!1),n.focus({preventScroll:!0})},j=m=>{let E=W(m.currentTarget);if(E.length===0)return;let O=K(),C=E.indexOf(O),D=N=>{m.preventDefault(),E[(N+E.length)%E.length]?.focus({preventScroll:!0})};m.key==="ArrowDown"?D(C+1):m.key==="ArrowUp"?D(C<0?E.length-1:C-1):m.key==="Home"?D(0):m.key==="End"&&D(E.length-1)};s.addEventListener("keydown",j),d.addEventListener("keydown",j),p.addEventListener("click",m=>{m.stopPropagation(),z(!1,!0)});let X=m=>ln(e,m),re=()=>A.filter(m=>!m.resolved&&!e.T(m)).length,pe=()=>A.filter(m=>!m.resolved&&e.T(m)).length,ue=()=>A.filter(m=>!m.resolved).length,ye=m=>{let E=m.anchor.view?.slide,O=e.c.f(m.anchor.view)?"":xt(m.anchor.view);return E&&e.c.slide()!==null?`On slide ${E}`:O?`In ${O}`:io},se=(m,E,O="")=>h("div",{role:"group","aria-label":O?`${m} \xB7 ${O}`:m},h("div",{class:"sec","aria-hidden":"true"},m,O&&h("b",{},O)),...E);function u(m,E){let O=e.c.slide(),C=new Map;for(let D of m){let N=D.thread,q=O!==null?N.anchor.view?.slide??O:e.T(N)?e.c.f(N.anchor.view)?"":xt(N.anchor.view):null;C.set(q,[...C.get(q)??[],D])}if(O===null){let D=C.get(null)??[];return C.delete(null),[...D.map(E),...[...C].map(([N,q])=>se(N||io,q.map(E)))]}return[...C].sort(([D],[N])=>Number(D)-Number(N)||0).map(([D,N])=>se(`Slide ${D} \xB7 ${N.filter(q=>!q.thread.resolved).length} open`,N.map(E),D===O?"This slide":""))}function V(){let m=K()?.dataset.thread,E=e.l.all().filter(N=>!N.thread.resolved||e.state.p),O=N=>{let q=N.thread,le=Le(q.root.author,q.root.name);le.classList.add("in");let We=h("button",{class:q.resolved?"mi done":"mi",type:"button",role:"menuitem","data-thread":q.id},le,h("span",{},h("span",{class:"clamp"},q.root.deleted?"Deleted":q.root.text),h("small",{},X(q)?`\u201C${ve(q.anchor.snapshot,80)}\u201D`:N.location.where)));return We.addEventListener("click",l=>{l.stopPropagation(),U(q.id,We.getBoundingClientRect().top)}),We},C=E.filter(N=>X(N.thread));c.textContent=String(ue()),x.setAttribute("aria-checked",String(e.state.p)),d.replaceChildren(E.length?"":h("div",{class:"sec",role:"presentation"},"No open comments"),...u(E.filter(N=>!X(N.thread)),O),C.length?se("No longer on the page",C.map(O)):"");let D=W(d);m&&D.find(N=>N.dataset.thread===m)?.focus({preventScroll:!0})}function U(m,E){Ce()&&(e.state.E=!0,z(!1)),M(m,E)}let g="";function M(m,E){let O=A.find(C=>C.id===m);if(O){if(g=m,!e.T(O))return R(O,E);if(e.state.e&&!e.S())return e.$();e.c.K(O.anchor.view??{}).then(()=>{e.ie();let C=A.find(D=>D.id===m);C&&g===m&&(e.state.o||e.state.E)&&R(C,E)})}}function R(m,E){let O=m.id,C=e.resolved.get(O),D=C&&!X(m)&&!e.T(m)?C.element??C.range?.startContainer.parentElement??null:null;if(D?.scrollIntoView({block:"center",inline:"nearest",behavior:L?"auto":"smooth"}),D&&C&&nt(m.anchor,C)&&D.checkVisibility?.({visibilityProperty:!0})!==!1){Y(),e.open(O);return}e.open(null),Ce()&&(e.state.E=!0,e.d()),B(m,E)}function B(m,E){let O=!X(m)&&e.T(m),C={quote:m.anchor.quote?.exact??null,lost:X(m)||O?m.anchor.snapshot:null,place:O?ye(m):null};if(v?.id===m.id?v.view.update(m,C):(v={id:m.id,view:Be(m,e.N,{R:"popover",...C})},f.replaceChildren(v.view.element)),E===void 0)return;f.isConnected||(e.n.insertBefore(f,T),f.offsetWidth);let D=Pt(e.state.o),{left:N,top:q}=Ot({x:D.width,y:E,below:!1},{width:Me,height:f.offsetHeight},D);f.style.left=`${N}px`,f.style.top=`${q}px`,f.classList.add("show"),f.inert=!1,e.se(m.id)}function Y(m=!1){v&&(v=null,f.classList.remove("show"),ne(f,!0),m&&e.state.E&&(e.state.E=!1,e.d()))}function F(m,E,O,C=!1,...D){let N=h("button",{class:"mi",type:"button",role:C?"menuitemcheckbox":"menuitem"},m,h("span",{class:"lb"},E),...D,C&&h("span",{class:"sw","aria-hidden":"true"}),h("span",{class:"tt","aria-hidden":"true"}));return N.addEventListener("click",q=>{q.stopPropagation(),O()}),N}let J=(m,E,O,C)=>{let D=m.querySelector(".lb");D.textContent!==E&&(D.textContent=E),m.querySelector(".tt").textContent=O,m.setAttribute("aria-description",O),C!==void 0&&m.setAttribute("aria-checked",String(C))},oe=()=>h("div",{class:"sep",role:"separator"}),Z=h("span",{class:"ma"}),Se=h("span",{class:"kc"}),ct="",ae=F(Z,"",Ue,!1,Se);ae.dataset.item="name";let Fe=F(Q("copy"),"Copy as Markdown",()=>{H(),e.l.copyAll("ai")}),Re=F(Q("lines"),"Copy as Text",()=>{H(),e.l.copyAll("text")}),Ve=h("span",{class:"kc"}),me=F(Q("list"),"All comments",()=>{I(!1),z(!0)},!1,Ve),Ie=F(Q("comment"),"Start commenting",()=>e.ae(!e.state.s),!0,h("span",{class:"kc","aria-hidden":"true"},Qe));Ie.dataset.item="comment",Ie.setAttribute("aria-keyshortcuts",en);let dt=[ae,oe(),Fe,Re,me,oe(),Ie];function _e(){let m=ue(),E=e.l.name(),O=E||ge(e.doc.me);if(J(ae,O,E?"The name on your comments":"Add a name to show on your comments"),ae.setAttribute("aria-label",`${O}, ${E?"edit":"add"} your name`),Se.replaceChildren(E?Q("edit",13):"Add name"),et(e.doc.me,E)!==ct){ct=et(e.doc.me,E);let C=Le(e.doc.me,E);C.classList.add("in"),Z.replaceChildren(C)}J(Fe,"Copy as Markdown","Markdown, with where each thread is"),J(Re,"Copy as Text","Just the words"),J(me,"All comments","Every thread, and where it is"),Ve.textContent=m?String(m):"",J(Ie,"Start commenting",e.state.s?"Turn off to hide the comments again":"Shows the comments; choose any part of the page to comment on it",e.state.s)}function qe(){_e(),s.firstChild!==ae&&s.replaceChildren(...dt)}function Ue(){let m=h("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"});m.value=e.l.name();let E=h("div",{class:"ed"},Z.cloneNode(!0),m),O=(C,D=!1)=>{if(y!==O)return;y=null;let N=m.value.trim();C&&N&&N!==e.l.name()&&e.l.rename(N).then(_e),E.replaceWith(ae),D&&ae.focus({preventScroll:!0})};y=O,m.addEventListener("keydown",C=>{C.stopPropagation(),(C.key==="Enter"||C.key==="Escape")&&(C.preventDefault(),O(C.key==="Enter",!0))}),m.addEventListener("blur",()=>O(!0)),ae.replaceWith(E),m.focus({preventScroll:!0})}n.addEventListener("click",m=>{if(m.stopPropagation(),S){I(!1);return}qe(),I(!0),m.detail===0&&W().at(-1)?.focus({preventScroll:!0})});let ze=!1,pt=()=>{ze=T.contains(K())},ut=m=>{let E=m.composedPath();S&&!E.includes(s)&&!E.includes(n)&&(I(!1),e.state.s&&!e.w(m)&&(e.U(m),m.preventDefault(),m.stopPropagation())),e.state.o&&!e.w(m)&&z(!1,ze&&(!document.activeElement||document.activeElement===document.body)),!E.includes(f)&&!E.includes(T)&&Y(!0)},be=m=>{if(!S||m.pointerType==="touch"||m.type==="pointerout"&&m.relatedTarget)return;let E=m.composedPath();m.type==="pointerover"&&(E.includes(s)||E.includes(n))?(window.clearTimeout(w),w=0):w||(w=window.setTimeout(()=>{w=0,y||I(!1)},Er))};window.addEventListener("pointerdown",pt,!0),window.addEventListener("click",ut,!0),window.addEventListener("pointerover",be,!0),window.addEventListener("pointerout",be,!0);let Ke=m=>{if(m.key!=="Escape"||y)return;let E=m.composedPath()[0];if(S)H();else if(e.state.o&&!(E instanceof HTMLTextAreaElement&&!T.contains(E)))z(!1,!0);else if(v)Y(!0),e.N.close();else return;m.stopPropagation()};return window.addEventListener("keydown",Ke,!0),{d(m){A=m;let E=re();if(E!==b){if(E){let[q,le]=t[0].classList.contains("on")?t:[t[1],t[0]];le.textContent=E>99?"99+":String(E),le.classList.toggle("s",E>99),q.classList.remove("on"),le.classList.add("on")}n.classList.toggle("has",E>0),b=E}let O=pe(),C=O?`${E} here \xB7 ${O} ${e.c.slide()!==null?"on other slides":"in other views"}`:"";n.classList.toggle("else",O>0);let D=C?`Comment, ${C}`:E?`Comment, ${E} open`:"Comment";n.getAttribute("aria-label")!==D&&n.setAttribute("aria-label",D),r.data!==(C||"Comment")&&(r.data=C||"Comment"),n.classList.toggle("on",e.state.s),S&&_e();let N=e.state.o;if(T.classList.toggle("full",Ce()),T.classList.contains("show")!==N&&(T.classList.toggle("show",N),ne(T,!N)),N&&V(),v){let q=m.find(le=>le.id===v?.id);!q||e.state.t||q.resolved&&!e.state.p?Y():B(q)}},k(){},destroy(){window.removeEventListener("pointerdown",pt,!0),window.removeEventListener("click",ut,!0),window.removeEventListener("pointerover",be,!0),window.removeEventListener("pointerout",be,!0),window.clearTimeout(w),window.removeEventListener("keydown",Ke,!0),s.remove(),T.remove(),f.remove(),a.remove()}}}var st="[data-pipeup-slide]",ao=1e3,lo=["scroll","resize","keyup","click","transitionend","slidechanged"],dn=null,lt=null,Nt=new Set,pn=new Set,at=e=>{try{e()}catch(t){globalThis.reportError?.(t)}};function kr(e){let t=null;if(e){t={};let o=0;for(let[n,r]of Object.entries(e))if(!(typeof r!="string"||n==="slide"||n.length>G.viewKey||r.length>G.viewValue)){if(++o>=G.viewEntries)break;t[n]=r}}dn=t;for(let o of pn)o()}function Sr(e){return Nt.add(e),()=>void Nt.delete(e)}function $t(e){lt=typeof e?.current=="function"&&typeof e.go=="function"?e:null}function Tr(e,t,o){let n=t.F(),r=null,i=0,a=0;for(let s of e){if(!t.shown(s))continue;let d=t.i(s),c=Math.min(d.left+d.width,n.width)-Math.max(d.left,0),p=Math.min(d.top+d.height,n.height)-Math.max(d.top,0);if(c<=0||p<=0)continue;let x=Math.round(c*p),T=t.opacity(s);(x>i||x===i&&(T>a||T===a&&s===o))&&(r=s,i=x,a=T)}return r}function Ar(e,t,o){return t!==null?e?.slide===void 0||e.slide===t:!e||!o?!0:Object.entries(e).every(([n,r])=>n==="label"||n==="slide"||o[n]===r)}function Lr(){return{i:e=>e.getBoundingClientRect(),shown:e=>e.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0})!==!1,opacity:e=>parseFloat(getComputedStyle(e).opacity)||0,F:()=>({width:window.innerWidth,height:window.innerHeight})}}var co=()=>{let e=window.Reveal;return typeof e?.getIndices=="function"&&typeof e.slide=="function"?e:null};function po(e,t,o=Lr()){let n=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,r=null,i=null,a=0,s=!1,d=()=>[...e.querySelectorAll(st)],c=()=>[...e.querySelectorAll(".slides > section")],p=b=>typeof b=="string"&&b.length>0&&b.length<=G.viewValue?b:null,x=b=>p(b?.getAttribute("data-pipeup-slide"));function T(){if(lt){let v=null;if(at(()=>{let L=lt.current();Number.isInteger(L)&&L>0&&(v=String(L))}),v!==null)return v}let b=co();if(b){let v=null;if(at(()=>{let L=b.getIndices().h,I=c()[L];v=x(I?.matches(st)?I:I?.querySelector(st))??p(String(L+1))}),v!==null)return v}return r&&!r.isConnected&&(r=null),r=Tr(d(),o,r)??r,x(r)}function f(){a=0,i=T(),t()}let S=()=>{!a&&!s&&(a=requestAnimationFrame(f))},y=b=>Ar(b,i,dn);function w(b){if(y(b))return Promise.resolve(!0);let v=b.slide,L=co(),I=d().find(K=>x(K)===v),z=/^[1-9]\d{0,5}$/.test(v??"");if(z&&lt)at(()=>lt.go(Number(v)));else if(z&&L){let K=I?c().findIndex(H=>H===I||H.contains(I)):-1;at(()=>L.slide(K>=0?K:Number(v)-1))}else if(Nt.size)for(let K of Nt)at(()=>K({...b}));else if(I)I.scrollIntoView({block:"start",behavior:n?"auto":"smooth"});else return Promise.resolve(!1);let W=performance.now();return new Promise(K=>{let H=re=>{clearTimeout(j),K(re)},j=setTimeout(()=>H(!1),ao),X=()=>{if(s)return H(!1);if(i=T(),y(b))return H(!0);if(performance.now()-W>=ao)return H(!1);requestAnimationFrame(X)};requestAnimationFrame(X)})}let A=new MutationObserver(b=>{b.some(v=>v.target instanceof Element&&v.target.matches(st))&&S()});A.observe(e,{subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]});for(let b of lo)window.addEventListener(b,S,{capture:!0,passive:!0});return pn.add(S),i=T(),{slide:()=>i,view(b){let v=b instanceof Element?b:b?.parentElement,L=x(v?.closest(st))??i,I={...L!==null?{slide:L}:{},...dn};return Object.keys(I).length?I:void 0},f:y,K:w,destroy(){s=!0,cancelAnimationFrame(a),A.disconnect();for(let b of lo)window.removeEventListener(b,S,!0);pn.delete(S)}}}var mo=["pipeup-quote","pipeup-on","pipeup-done"],Mr={"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]]},Cr=(e,t)=>mo.map(o=>{let[n,r,i,a]=Mr[o][e?1:0];return`::highlight(${o}){background-color:rgba(${n},${r},${i},${+(a*t).toFixed(3)})}`}).join("");function fo(){return typeof CSS<"u"&&"highlights"in CSS&&typeof Highlight<"u"}var Pr="<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>",Or=`:not([data-pipeup-ignore],[data-pipeup-ignore] *){cursor:url("data:image/svg+xml,${encodeURIComponent(Pr)}") 3 2,crosshair!important}`;function ho(e=document,t=!1){let o=e.defaultView?.CSSStyleSheet;if(!o||!("replaceSync"in o.prototype)||!("adoptedStyleSheets"in e))return{W(){},j(){},q(){},Y(){},remove:()=>uo()};let n=new o,r=null,i=!1,a=1,s=0,d="",c=0,p=()=>n.replaceSync(Cr(t,a)+(r===null?"":`:root{--pipeup-gutter:${r}px}`)+(i?Or:"")+(s||d?`html{--pipeup-panel:${s}px;${s?`margin-right:${s}px!important;`:""}${d}}`:""));return p(),e.adoptedStyleSheets=[...e.adoptedStyleSheets,n],{W(x){x!==r&&(r=x,p())},j(x){x!==i&&(i=x,p())},q(x){a=x,p()},Y(x,T){x!==s&&(s=x,d=T?"":"transition:margin-right .34s cubic-bezier(.4,0,.2,1)!important",clearTimeout(c),!x&&d&&(c=window.setTimeout(()=>{d="",p()},400)),p())},remove(){clearTimeout(c),e.adoptedStyleSheets=e.adoptedStyleSheets.filter(x=>x!==n),uo()}}}function go(e){fo()&&(CSS.highlights.set("pipeup-quote",new Highlight(...e.quote)),CSS.highlights.set("pipeup-on",new Highlight(...e.on)),CSS.highlights.set("pipeup-done",new Highlight(...e.done)))}function uo(){if(fo())for(let e of mo)CSS.highlights.delete(e)}var un=':host{all:initial}*{box-sizing:border-box}button{-webkit-appearance:none;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)}.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,.toast,.selbar{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)}.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)}.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)}.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;background:var(--su);border:1px solid var(--ln);box-shadow:var(--sh);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%;background:var(--su);border:1px solid var(--ln);box-shadow:var(--sh);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;background:var(--su);border:1px solid var(--ln);box-shadow:var(--sh);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);background:var(--su);border:1px solid var(--ln);box-shadow:var(--sh);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)}.all{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{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 .av svg{margin:0}.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(prefers-reduced-motion:reduce){.bub,.bub.in,.bub.in:hover,.bub.on,.tip,.pop,.selbar,.menu,.all,.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{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 vo="#534AB7",Rr="rgb(0, 0, 238)";function wo(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 o=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:o}}function Ir(e){let t=o=>{let n=o/255;return n<=.03928?n/12.92:((n+.055)/1.055)**2.4};return .2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}function yo(e){let t=e.ownerDocument,o=t.defaultView;if(!o)return{font:"system-ui, sans-serif",accent:vo,dark:!1};let n=t.documentElement,r=o.getComputedStyle(e).fontFamily||"system-ui, sans-serif",i=(o.getComputedStyle(n).getPropertyValue("--pipeup-accent")||n.style.getPropertyValue("--pipeup-accent")).trim(),a=e.querySelector("a[href]"),s=a?o.getComputedStyle(a).color:"",d=i||(s&&s!==Rr?s:vo),c=wo(o.getComputedStyle(t.body).backgroundColor);(!c||c.a===0)&&(c=wo(o.getComputedStyle(n).backgroundColor));let p=c&&c.a>0?Ir(c)<.2:o.matchMedia?.("(prefers-color-scheme: dark)").matches===!0&&/dark/.test(o.getComputedStyle(n).colorScheme||"");return{font:r,accent:d,dark:!!p}}function bo(e,t){e.style.setProperty("--pu-font",t.font),e.style.setProperty("--pu-accent",t.accent),e.classList.toggle("dark",t.dark)}function xo(e,t=document){let o=t.createElement("pipeup-root");o.setAttribute("data-pipeup-ignore",""),o.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 n=o.attachShadow({mode:"open"}),r=t.defaultView?.CSSStyleSheet;if(r&&"replaceSync"in r.prototype&&"adoptedStyleSheets"in n){let a=new r;a.replaceSync(un),n.adoptedStyleSheets=[a]}else{let a=t.createElement("style");a.textContent=un,n.append(a)}let i=t.createElement("div");return i.className="layer",i.style.setProperty("--pu-panel",`${ot}px`),i.style.setProperty("--pu-pop",`${Me}px`),bo(i,e),n.append(i),t.documentElement.append(o),{element:o,shadow:n,n:i,destroy:()=>o.remove()}}var Nr=40,$r=250,Dr=120,Hr=2400,Eo=4e3;function ko(e,t=!1){return an(e,t)?"column":"bubbles"}function Br(e){return[...e.state.mode==="column"?[oo(e),on(e,{H:!1})]:[on(e,{H:!0})],ro(e),so(e)]}var Fr=1e3,Dt="Shown here, but not saved yet \u2014 it will be saved with your next change",Pe=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";function So(e){let t=yo(e.root),o=xo(t),n=ho(document,t.dark);n.q(0);let r=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches===!0,i=document.documentElement.hasAttribute("data-pipeup-reserve"),a=new Map,s=new Set,d=new WeakSet,c={t:null,m:null,p:!1,hidden:!0,mode:ko(e.root),e:null,s:!1,o:!1,E:!1,l:!1},p=h("div",{class:"toast",role:"status","aria-live":"polite"});o.n.append(p);let x=null,T=[],f=null,S=!1,y=0,w=0,A=0,b=0,v=0,L=new Set,I="",z=new Map,W=po(e.root,()=>{!S&&U()&&Z()}),K=!1;function H(l,k=Hr){S||(K=k===Eo,p.textContent=l,p.classList.add("show"),window.clearTimeout(y),y=window.setTimeout(()=>p.classList.remove("show"),k))}function j(){K&&(K=!1,window.clearTimeout(y),p.classList.remove("show"))}function X(l){H(Pe(l))}function re(l){throw X(l),l}let pe=l=>({thread:l,location:Yt(l.anchor,a.get(l.id)??bt(l.anchor,e.root),e.root)}),ue={reply:async(l,k)=>{try{await e.doc.reply(l,k)}catch(P){P instanceof de?H(Dt):re(P)}},resolve:async l=>{try{await e.doc.resolve(l),c.t===l&&!c.p&&(c.t=null),H("Resolved \xB7 Show resolved brings it back")}catch(k){k instanceof de?(c.t===l&&!c.p&&(c.t=null),H(`Resolved \xB7 ${Dt}`)):H(Pe(k))}},reopen:async l=>{try{await e.doc.reopen(l),H("Reopened")}catch(k){H(k instanceof de?`Reopened \xB7 ${Dt}`:Pe(k))}},close:()=>{me(null),Se&&ct(Se)?.focus({preventScroll:!0}),Se=""},copy:l=>{try{let k=e.doc.threads().find($=>$.id===l);if(!k)return;let P=Zt(pe(k),"ai",location.href,Date.now());cn(P,o.n).then(()=>H("Thread copied as Markdown for AI"),$=>H(Pe($)))}catch(k){H(Pe(k))}}};function ye(l){let k=P=>a.get(P.id)?.element??null;return[...l].sort((P,$)=>{let _=k(P),ee=k($);return!_||!ee?_?-1:ee?1:0:_===ee?0:_.compareDocumentPosition(ee)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1})}let se={copyAll:async l=>{let k=se.all(),P=Qt(k,l,{title:document.title,url:location.href,exportedAt:new Date});try{await cn(P,o.n);let $=k.filter(_=>!_.thread.resolved).length;H(`Copied ${$} thread${$===1?"":"s"}${l==="ai"?" as Markdown for AI":""}`)}catch($){H(Pe($))}},re:()=>{c.p=!c.p,Z()},rename:async l=>{let k=l.replace(/\s+/g," ").trim();try{await pt(k)?H(`New comments will say ${k}, but this browser couldn't remember it`):H(`New comments will say ${k}`)}catch(P){H(Pe(P))}},name:()=>e.doc.name,all:()=>ye(e.doc.threads()).map(pe)},u={doc:e.doc,root:e.root,n:o.n,host:o.element,state:c,resolved:a,z:s,N:ue,l:se,c:W,T:l=>L.has(l.id),ie:()=>{U()&&Z()},I:l=>!c.hidden&&(!l.resolved||c.p)&&!L.has(l.id),le:(l,k)=>{for(let P of e.doc.threads()){let $=a.get(P.id);if(P.anchor.quote&&u.I(P)&&$?.range&&Wn(l,k,tt($)))return P}return null},B:(l,k)=>u.S()?u.le(l,k):null,w:l=>l.composedPath().includes(o.element),U:l=>void d.add(l),oe:l=>d.has(l),open:me,se:l=>Re(l),m:Ie,_:dt,te:_e,S:()=>!x||x.X(),ne:l=>{let k=x?.G();l(),k?.()},J:ut,Z:qe,ae:Ue,$:ze,L:l=>{x=l},ce:H,V:X,de:be,d:Z};function V(l){let k=performance.now(),P=e.doc.threads();for(let $ of P){if(l&&!l.has($.id))continue;let _=performance.now()-k<Nr,ee=bt($.anchor,e.root,{fuzzy:_});a.set($.id,ee),!_&&ee.state==="orphaned"?s.add($.id):s.delete($.id)}for(let $ of[...a.keys()])P.some(_=>_.id===$)||a.delete($);s.size===0?(window.clearTimeout(b),b=0):b===0&&(b=window.setTimeout(()=>{b=0,!S&&(V(new Set(s)),Z())},$r))}function U(){let l=new Set,k=W.slide()!==null,P=new Set;for(let _ of e.doc.threads()){P.add(_.id);let ee=a.get(_.id)?.element;(!W.f(_.anchor.view)||!k&&ee?.checkVisibility?.({visibilityProperty:!0})===!1)&&l.add(_.id)}L=l;for(let _ of z.keys())P.has(_)||z.delete(_);let $=`${W.slide()}|${[...l].join()}`;return $===I?!1:(I=$,!0)}function g(l){let k=[],P=[],$=[];for(let _ of l){let ee=a.get(_.id);_.resolved&&!c.p||!ee?.range||L.has(_.id)||(_.id===c.t||_.id===c.m?P.push(ee.range):_.resolved?$.push(ee.range):k.push(ee.range))}c.e&&W.f(c.e.anchor.view)&&P.push(...c.e.ranges),go({quote:k,on:P,done:$})}let M=0,R=0,B=0;function Y(l){if(l===R)return;R=l,cancelAnimationFrame(B);let k=M,P=performance.now(),$=l?260:200,_=ee=>{let mt=Math.min(1,(ee-P)/$);M=k+(l-k)*(l?1-(1-mt)**3:mt*mt),n.q(M),mt<1&&(B=requestAnimationFrame(_))};B=requestAnimationFrame(_)}let F=0,J=0;function oe(l){l!==F&&(F=l,n.Y(l,r),window.clearTimeout(J),J=window.setTimeout(()=>{V(),Z()},r?0:400))}function Z(){if(S)return;let l=e.doc.threads();if(U(),c.t&&L.has(c.t)){let P=o.n.querySelector(`[data-thread="${c.t}"] .rbox textarea`)?.value;P&&z.set(c.t,P),c.t=null}c.hidden=!c.s&&!c.o&&!c.E&&!c.e,c.hidden&&(c.t=null),Y(c.hidden?0:1),o.n.classList.toggle("hidden",c.hidden),o.n.classList.toggle("listing",c.o);let k=c.o&&!Ce();oe(k?ot:0),n.W(i?c.mode==="column"&&!c.hidden&&!k?it:0:null),g(l);for(let P of T)P.d(l);f?.d(l)}let Se="",ct=l=>o.n.querySelector(`.all .mi[data-thread="${l}"]`),ae="input,textarea,select,[contenteditable]:not([contenteditable=false])",Fe=()=>{let l=o.n.getRootNode().activeElement;return l instanceof HTMLTextAreaElement&&l.value!==""||!!document.activeElement?.matches(ae)};function Re(l,k=Fe()){let P=[...o.n.querySelectorAll(`[data-thread="${l}"] .rbox textarea`)].find($=>!$.closest("[inert]"));k||!P||(Se=o.n.getRootNode().activeElement?.getAttribute("data-thread")??"",P.focus({preventScroll:!0}))}function Ve(){let l=c.e;return!l||u.S()?!1:(W.f(l.anchor.view)||W.K(l.anchor.view??{}),!0)}function me(l){if(l&&Ve())return;if(c.t===l&&!c.e)return l?Re(l):void 0;let k=Fe();if(l||(c.E=!1),c.t=l,l&&(c.e=null,be(l)),Z(),l){let P=z.get(l),$=P&&o.n.querySelector(`[data-thread="${l}"] .rbox textarea`);$&&!$.value&&($.value=P,$.dispatchEvent(new Event("input",{bubbles:!0}))),z.delete(l),Re(l,k)}}function Ie(l){c.m!==l&&(c.m=l,l&&l!==c.t&&be(l),Z())}function dt(l){j(),c.o=!1,c.e=l,c.t=null,Z()}function _e(l){if(!c.e)return dt(l);Object.assign(c.e,l),Z()}function qe(){c.e&&(c.e=null,Z())}function Ue(l){c.s!==l&&(c.s=l,n.j(l),l?(c.t=null,c.o=!1,H(`Click anything to comment \xB7 Option-click (Alt-click) to pin \xB7 ${Qe} or Esc to finish`,Eo),f=to(u)):(j(),f?.destroy(),f=null),Z())}function ze(){if(c.e){Ve()||qe();return}c.t&&me(null)}async function pt(l){try{return await e.onName(l),!1}catch(k){if(e.doc.name!==l)throw k;return!0}}async function ut(l){let k=c.e;if(k)try{let P=await e.doc.comment(k.anchor,l);c.e=null,V(new Set([P])),me(P)}catch(P){if(P instanceof de){c.e=null,V(new Set([P.id])),me(P.id),H(Dt);return}re(P)}}function be(l){let k=a.get(l);if(!k||k.state==="orphaned")return;let P=k.range?tt(k):k.element?[k.element.getBoundingClientRect()]:[];for(let $ of P.slice(0,6)){let _=h("div",{class:"pulse"});He(_,$,4),o.n.prepend(_),window.setTimeout(()=>_.remove(),1300)}}function Ke(){for(let l of T)l.destroy();T=Br(u),Z()}let m=()=>{if(!S){for(let l of T)l.k();f?.k(),v=requestAnimationFrame(m)}},E=l=>{let k=l.composedPath()[0];return k instanceof Element&&k.closest(ae)!==null},O=l=>{if(l.key==="Escape"){c.e&&(W.f(c.e.anchor.view)||u.S())?qe():c.t?me(null):f&&!f.back()&&Ue(!1);return}Un(l)&&!l.isComposing&&!l.defaultPrevented&&!E(l)&&(l.preventDefault(),Ue(!c.s))},C=l=>{if(u.w(l)||d.has(l))return;let k=window.getSelection();k&&!k.isCollapsed||ze()},D=()=>{let l=ko(e.root,c.mode==="column");l!==c.mode?(c.mode=l,Ke()):Z()};function N(){let l=performance.now();w===0&&(A=l),window.clearTimeout(w);let k=Math.min(Dr,Math.max(0,A+Fr-l));w=window.setTimeout(()=>{w=0,V(),Z()},k)}let q=new MutationObserver(l=>{l.every(k=>o.element.contains(k.target))||N()});window.addEventListener("keydown",O),window.addEventListener("click",C),window.addEventListener("resize",D),q.observe(e.root,{subtree:!0,childList:!0,characterData:!0});let le=typeof ResizeObserver>"u"?null:new ResizeObserver(N);le?.observe(e.root);let We=e.doc.onChange(()=>{V(),Z()});return V(),Ke(),v=requestAnimationFrame(m),{ctx:u,destroy(){S=!0,cancelAnimationFrame(v),cancelAnimationFrame(B),W.destroy(),window.clearTimeout(J),window.clearTimeout(y),window.clearTimeout(w),window.clearTimeout(b),q.disconnect(),le?.disconnect(),We(),window.removeEventListener("keydown",O),window.removeEventListener("click",C),window.removeEventListener("resize",D),f?.destroy();for(let l of T)l.destroy();n.remove(),o.destroy()}}}var Oe=null,Vr=4e3;function _r(e={}){if(Oe)return Oe;let t=Ur(e,()=>t).catch(o=>{throw Oe===t&&(Oe=null),o});return Oe=t,t}function qr(e,t){return new Promise((o,n)=>{let r=setTimeout(()=>n(new Error("timed out")),t);e.then(o,n).finally(()=>clearTimeout(r))})}async function Ur(e,t){let o=document.documentElement.getAttribute("data-pipeup-doc"),{id:n,key:r}=o?await qt(o):{id:`page-${ke(location.origin+location.pathname)}`,key:null},i,a=!1,s;if(e.store)i=e.store,s=await Ge(i);else try{let f=Xe.open();i=await qr(f,Vr).catch(S=>{throw f.then(y=>y.close(),()=>{}),S}),s=await Ge(i)}catch{i=new Ye,a=!0,s=await Ge(i)}let d=e.name?.trim();d&&d!==s.name&&(s={...s,name:d},await i.saveProfile(s));let c=await je.open({doc:n,key:r,store:i,identity:s.identity,name:s.name});$t(e.slides??null);let p;try{p=So({doc:c,root:e.root??document.body,onName:async f=>{c.name=f,s={...s,name:f},await i.saveProfile(s)}})}catch(f){throw $t(null),f}a&&p.ctx.ce("This browser can't keep comments for this page \u2014 copy the comments (Copy as Markdown) to keep them");let x=()=>void c.flush().catch(f=>globalThis.reportError?.(f)),T=!1;return window.addEventListener("pagehide",x),{document:c,flush:()=>c.flush(),unmount:()=>{T||(T=!0,window.removeEventListener("pagehide",x),p.destroy(),$t(null),Oe===t()&&(Oe=null))}}}export{$e as ANIMALS,Gt as COLOURS,Pn as DEFAULT_PROFILE_NAME,Xe as IndexedDbStore,Ye as MemoryStore,je as PipeupDocument,de as UnsavedChangeError,Oi as VERSION,ge as animalName,Qt as copyAll,Zt as copyThread,Ht as createIdentity,yt as describeElement,Wt as describeRange,De as formatAgo,Ne as labelOf,Ge as loadOrCreateProfile,Yt as locate,_r as mount,ie as nameOf,Oo as newDocumentAttribute,Sr as onReveal,qt as parseDocumentAttribute,bt as resolveAnchor,kr as setViewState};