pipeup 0.6.0 → 0.7.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +3 -3
  2. package/cli/link.d.mts +17 -0
  3. package/cli/link.mjs +78 -4
  4. package/cli/pipeup.mjs +22 -7
  5. package/dist/pipeup.agents.js +2 -0
  6. package/dist/pipeup.core.js +1 -1
  7. package/dist/pipeup.esm.js +1 -1
  8. package/dist/pipeup.min.js +1 -1
  9. package/dist/types/core.d.ts +3 -1
  10. package/dist/types/crypto/portable.d.ts +15 -0
  11. package/dist/types/document.d.ts +20 -4
  12. package/dist/types/export/agent.d.ts +5 -0
  13. package/dist/types/export/format.d.ts +3 -1
  14. package/dist/types/index.d.ts +3 -1
  15. package/dist/types/model/animals.d.ts +7 -1
  16. package/dist/types/model/fold.d.ts +2 -0
  17. package/dist/types/model/ops.d.ts +5 -0
  18. package/dist/types/model/types.d.ts +28 -2
  19. package/dist/types/ui/addons.d.ts +22 -1
  20. package/dist/types/ui/animals.d.ts +1 -1
  21. package/dist/types/ui/app.d.ts +6 -0
  22. package/dist/types/ui/composer.d.ts +6 -1
  23. package/dist/types/ui/context.d.ts +16 -10
  24. package/dist/types/ui/draft-view.d.ts +5 -1
  25. package/dist/types/ui/highlights.d.ts +2 -0
  26. package/dist/types/ui/icons.d.ts +2 -0
  27. package/dist/types/ui/identity.d.ts +27 -0
  28. package/dist/types/ui/launcher.d.ts +0 -5
  29. package/dist/types/ui/legible.d.ts +27 -0
  30. package/dist/types/ui/mentions.d.ts +46 -0
  31. package/dist/types/ui/mount.d.ts +3 -0
  32. package/dist/types/ui/reactions.d.ts +31 -0
  33. package/dist/types/ui/styles.d.ts +1 -1
  34. package/dist/types/ui/theme.d.ts +31 -2
  35. package/dist/types/ui/thread-view.d.ts +12 -2
  36. package/package.json +1 -1
  37. package/skills/pipeup-add/SKILL.md +10 -5
  38. package/skills/pipeup-apply/SKILL.md +7 -5
  39. package/skills/pipeup-integrate/SKILL.md +20 -11
  40. package/skills/pipeup-send-to-git-setup/SKILL.md +1 -1
  41. package/skills/pipeup-summarise/SKILL.md +1 -1
  42. package/dist/types/export/prompt.d.ts +0 -12
  43. package/dist/types/ui/link.d.ts +0 -22
  44. package/dist/types/ui/replies.d.ts +0 -33
@@ -1 +1 @@
1
- function e(e){let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function t(e){let t=atob(e.replace(/-/g,"+").replace(/_/g,"/")),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function n(e){return(new TextEncoder).encode(e)}function o(e){if(null===e||"object"!=typeof e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(o).join(",")+"]";let t=e;return"{"+Object.keys(t).filter(e=>void 0!==t[e]).sort().map(e=>JSON.stringify(e)+":"+o(t[e])).join(",")+"}"}function r(e){return e.replace(/\s+/g," ").trim()}function i(e){let t=r(e),n=2166136261;for(let e=0;e<t.length;e++)n^=t.charCodeAt(e),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")}var a=/^[A-Za-z0-9_-]{43}$/,l=new Map;async function s(){let t=await crypto.subtle.generateKey({name:"Ed25519"},!1,["sign","verify"]);return{publicKey:e(new Uint8Array(await crypto.subtle.exportKey("raw",t.publicKey))),privateKey:t.privateKey}}async function d(t,n){let o=await crypto.subtle.sign({name:"Ed25519"},t.privateKey,n);return e(new Uint8Array(o))}var c=2**40,p=2**47,u=1e4,h=/^[0-9a-f]{8}$/,f=/^[A-Za-z0-9_-]{43}$/,m=/^[A-Za-z0-9_-]{43}$/,v=new Set(["create","reply","edit","delete","resolve","reopen","addressed"]);async function g(e,t){if(e.author!==t.publicKey)throw new Error("pipeup: an op must be signed by its author");return{body:e,sig:await d(t,n(o(e)))}}var w=(e,t)=>"string"==typeof e&&e.length<=t,y=e=>!!e&&"object"==typeof e,b=e=>"number"==typeof e&&Number.isFinite(e)&&e>=0&&e<=1;function x(e){if(!y(e))return!1;let{id:t,path:n,fingerprint:o,snapshot:r,quote:i,point:a,view:l}=e;if(!(w(n,2e3)&&w(r,500)&&"string"==typeof o&&h.test(o)&&(void 0===t||w(t,200)&&""!==t)&&(void 0===i||y(i)&&w(i.exact,u)&&""!==i.exact&&w(i.prefix,64)&&w(i.suffix,64))&&(void 0===a||y(a)&&b(a.x)&&b(a.y))))return!1;if(void 0!==l){if(!y(l)||Array.isArray(l))return!1;let e=Object.entries(l);if(e.length>16||!e.every(([e,t])=>e.length<=64&&w(t,200)))return!1}return!0}function k(e){if(!y(e))return!1;let{body:t,sig:n}=e;if("string"!=typeof n||!y(t)||JSON.stringify({body:t,sig:n}).length>262144)return!1;let o=t;return!(1!==o.v||"string"!=typeof o.id||!f.test(o.id)||!v.has(o.kind)||!w(o.doc,64)||""===o.doc||"string"!=typeof o.thread||!f.test(o.thread)||"string"!=typeof o.author||!m.test(o.author)||"string"!=typeof o.name||o.name.length>80||o.name!==o.name.trim()||"number"!=typeof o.clock||!Number.isSafeInteger(o.clock)||o.clock<1||o.clock>c||"number"!=typeof o.at||!Number.isSafeInteger(o.at)||o.at<0||o.at>p||void 0!==o.text&&(!w(o.text,1e4)||o.text!==o.text.trim())||void 0!==o.target&&("string"!=typeof o.target||!f.test(o.target))||("create"===o.kind||"reply"===o.kind||"edit"===o.kind||"addressed"===o.kind)&&!o.text||("reply"===o.kind||"edit"===o.kind||"delete"===o.kind)&&!o.target||"create"===o.kind&&(o.id!==o.thread||!x(o.anchor)))}function E(r){return async function(n,o,r){if(!a.test(n))return!1;try{if(e(t(n))!==n)return!1;let i=l.get(n);if(!i){l.size>=512&&l.delete(l.keys().next().value),i=crypto.subtle.importKey("raw",t(n),{name:"Ed25519"},!0,["verify"]),l.set(n,i);let e=i;e.catch(()=>{l.get(n)===e&&l.delete(n)})}return await crypto.subtle.verify({name:"Ed25519"},await i,t(r),o)}catch{return!1}}(r.body.author,n(o(r.body)),r.sig)}function $(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 S(e,t,n,o,r){return{id:e,author:t,name:n,text:o,at:r,edited:!1,deleted:!1,replies:[]}}async function L(t){let r={...t,id:void 0,thread:"create"===t.kind?void 0:t.thread},i=await crypto.subtle.digest("SHA-256",n(o(r)));return e(new Uint8Array(i))}var A=class{constructor(e){this.doc=e}ops=new Map;clock=0;createAt=new Map;threadAt=new Map;get size(){return this.ops.size}all(){return[...this.ops.values()]}threads(){return function(e){let t=new Map,n=new Map,o=new Map;for(let{body:r}of[...e].sort($)){if(r.name&&o.set(r.author,r.name),"create"===r.kind){if(t.has(r.id)||!r.anchor||void 0===r.text)continue;let e=S(r.id,r.author,r.name,r.text,r.at);t.set(r.id,{id:r.id,anchor:r.anchor,root:e,resolved:!1}),n.set(r.id,{comment:e,thread:r.id});continue}let e=t.get(r.thread);if(!e)continue;if("resolve"===r.kind||"reopen"===r.kind){e.resolved="resolve"===r.kind,"reopen"===r.kind&&delete e.addressed;continue}if("addressed"===r.kind){void 0!==r.text&&(e.addressed={text:r.text,author:r.author,name:r.name,at:r.at});continue}let i=r.target?n.get(r.target):void 0;if(i&&i.thread===r.thread){if("reply"===r.kind){if(n.has(r.id)||void 0===r.text)continue;let t=S(r.id,r.author,r.name,r.text,r.at);e.root.replies.push(t),n.set(r.id,{comment:t,thread:r.thread});continue}r.author!==i.comment.author||i.comment.deleted||("edit"===r.kind&&void 0!==r.text&&(i.comment.text=r.text,i.comment.edited=!0),"delete"===r.kind&&(i.comment.text="",i.comment.deleted=!0))}}for(let{comment:e}of n.values())e.name||(e.unnamed=!0,e.name=o.get(e.author)??"");return[...t.values()]}(this.ops.values())}async add(e){let t=[];for(let n of e){if(!k(n)||n.body.doc!==this.doc||this.ops.has(n.body.id)||n.body.id!==await L(n.body)||!await E(n))continue;let e={body:n.body,sig:n.sig};this.ops.set(e.body.id,e),this.clock=Math.max(this.clock,e.body.clock),"create"===e.body.kind&&this.createAt.set(e.body.author,Math.max(this.createAt.get(e.body.author)??0,e.body.at)),this.threadAt.set(e.body.thread,Math.max(this.threadAt.get(e.body.thread)??0,e.body.at)),t.push(e)}return t}async append(e,t,n){let o={v:1,...n,id:"",thread:"create"===n.kind?"":n.thread,doc:this.doc,author:e.publicKey,name:t,clock:Math.min(this.clock+1,c),at:Math.min(Math.max(Date.now(),"create"===n.kind?(this.createAt.get(e.publicKey)??0)+1:(this.threadAt.get(n.thread)??0)+1),p)};o.id=await L(o);let r=this.ops.get(o.id);if(r)return r;"create"===o.kind&&(o.thread=o.id);let[i]=await this.add([await g(o,e)]);if(!i)throw new Error("pipeup: could not record this change");return i}},M=["Otter","Fox","Owl","Bear","Rabbit"],C=["Red","Orange","Yellow","Green","Teal","Blue","Purple","Pink","Brown","Grey"];function T(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return t=Math.imul(t^t>>>16,2246822507),t=Math.imul(t^t>>>13,3266489909),(t^t>>>16)>>>0}var P=e=>T(e)%M.length,N=e=>Math.floor(T(e)/M.length)%C.length,q=e=>`${C[N(e)]} ${M[P(e)]}`,z=e=>e.name.replace(/^AI assistant · /,"")||q(e.author),R="AI assistant",O=e=>e===R||e.startsWith(`${R} `),D=/^([A-Za-z0-9_-]{16}):([A-Za-z0-9_-]{43})$/;function I(){return`${function(t=16){return e(crypto.getRandomValues(new Uint8Array(t)))}(12)}:${e(crypto.getRandomValues(new Uint8Array(32)))}`}async function F(e){let n=D.exec(e.trim()),o=n?.[1],r=n?.[2];if(!o||!r)throw new Error('pipeup: data-pipeup-doc must look like "<id>:<key>", as made by newDocumentAttribute()');return{id:o,key:await crypto.subtle.importKey("raw",t(r),{name:"AES-GCM"},!1,["encrypt","decrypt"])}}async function B(t,o,r){let i=crypto.getRandomValues(new Uint8Array(12)),a=await crypto.subtle.encrypt({name:"AES-GCM",iv:i,additionalData:n(r)},t,n(o));return{iv:e(i),data:e(new Uint8Array(a))}}var H=e=>`pipeup-file:${e}`;var j=/^[a-z][a-z0-9-]{1,23}\/[a-z][a-z0-9-]{0,31}$/,W=class extends Error{constructor(e,t,n=1){super("pipeup: shown here, but not saved yet"),this.id=e,this.cause=t,this.count=n,this.name="UnsavedChangeError"}},K=class e{constructor(e,t){this.log=e,this.options=t,this.displayName=t.name.trim()?U(t.name):""}listeners=new Set;cache=[];comments=new Map;displayName;le=Promise.resolve();unsaved=[];static async open(t){if("string"!=typeof t.doc||""===t.doc||t.doc.length>64)throw new Error("pipeup: the document id must be 1 to 64 characters");let n=new A(t.doc),o=await t.store.load(t.doc),r=o.length-(await n.add(o)).length;r&&console.warn(`pipeup: ${r} saved change${1===r?"":"s"} on this page couldn't be read; kept as saved`);let i=new e(n,t);return i.refresh(!1),i}get id(){return this.options.doc}get me(){return this.options.identity.publicKey}get name(){return this.displayName}set name(e){this.displayName=U(e),this.refresh(!0,[],"")}threads(){return this.cache}ops(){return this.log.all()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}comment(e,t){return this.enqueue(()=>this.write({kind:"create",anchor:e,text:Y(t)}))}reply(e,t){return this.enqueue(()=>this.write({kind:"reply",thread:this.find(e).thread,target:e,text:Y(t)}))}edit(e,t){return this.enqueue(async()=>{let{thread:n}=this.mine(e);await this.write({kind:"edit",thread:n,target:e,text:Y(t)})})}remove(e){return this.enqueue(async()=>{let{thread:t}=this.mine(e);await this.write({kind:"delete",thread:t,target:e})})}resolve(e){return this.enqueue(async()=>{await this.write({kind:"resolve",thread:this.thread(e)})})}reopen(e){return this.enqueue(async()=>{await this.write({kind:"reopen",thread:this.thread(e)})})}sign(e,t){if(!j.test(e))throw new Error('pipeup: a signing purpose looks like "<add-on id>/<name>"');return d(this.options.identity,n(`pipeup:${e}\n${t}`))}flush(){return this.enqueue(()=>this.persist())}exportFile(){return async function(e,t,n){let o=n?{pipeup:1,doc:e,sealed:!0,...await B(n,JSON.stringify(t),H(e))}:{pipeup:1,doc:e,sealed:!1,ops:t};return JSON.stringify(o,null,2)}(this.options.doc,this.log.all(),this.options.key)}async importFile(e){return this.merge(await async function(e,o,r){if(e.length>5e6)throw new Error("pipeup: this feedback file is too large");let i,a,l;try{i=JSON.parse(e)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}if(!i||"object"!=typeof i||1!==i.pipeup||"string"!=typeof i.doc)throw new Error("pipeup: this is not an Pipeup feedback file");if(i.doc!==o)throw new Error("pipeup: this feedback is for a different document");if(!i.sealed)return Array.isArray(i.ops)?i.ops:[];if(!r)throw new Error("pipeup: this feedback is sealed, and this page has no document key");if("string"!=typeof i.iv||"string"!=typeof i.data)throw new Error("pipeup: this is not an Pipeup feedback file");try{a=await async function(e,o,r){try{let i=await crypto.subtle.decrypt({name:"AES-GCM",iv:t(o.iv),additionalData:n(r)},e,t(o.data));return(new TextDecoder).decode(i)}catch{throw new Error("pipeup: this feedback could not be opened with this document")}}(r,{iv:i.iv,data:i.data},H(o))}catch{throw new Error("pipeup: this feedback could not be opened with this document's key")}try{l=JSON.parse(a)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}return Array.isArray(l)?l:[]}(e,this.options.doc,this.options.key),"file")}merge(e,t){return e.length>5e3?Promise.reject(new RangeError("pipeup: too many changes to merge at once")):this.enqueue(async()=>{let n=await this.log.add([...e]);this.unsaved.push(...n),n.length>0&&this.refresh(!0,n,t);try{await this.persist()}catch(e){throw n.length>0?new W(n[0].body.id,e,n.length):e}return n.length})}enqueue(e){let t=this.le.then(e);return this.le=t.catch(()=>{}),t}async write(e){let t=await this.log.append(this.options.identity,this.displayName,e);this.unsaved.push(t),this.refresh(!0,[t],"local");try{await this.persist()}catch(e){throw new W(t.body.id,e)}return t.body.id}async persist(){if(0===this.unsaved.length)return;let e=[...this.unsaved];await this.options.store.append(this.options.doc,e),this.unsaved=this.unsaved.filter(t=>!e.includes(t))}refresh(e,t=[],n=""){this.cache=this.log.threads(),this.comments.clear();let o=(e,t)=>{e.unnamed&&e.author===this.me&&this.displayName&&(e.name=this.displayName),this.comments.set(e.id,{comment:e,thread:t});for(let n of e.replies)o(n,t)};for(let e of this.cache)o(e.root,e.id);if(e)for(let e of this.listeners)try{e(this.cache,t,n)}catch(e){globalThis.reportError?.(e)}}find(e){let t=this.comments.get(e);if(!t)throw new Error("pipeup: there is no comment with that id");return t}mine(e){let t=this.find(e);if(t.comment.author!==this.me)throw new Error("pipeup: only the writer can change a comment");return t}thread(e){if(!this.cache.some(t=>t.id===e))throw new Error("pipeup: there is no thread with that id");return e}};function Y(e){let t=e.trim();if(!t)throw new Error("pipeup: a comment needs some words");if(t.length>1e4)throw new Error("pipeup: comments are limited to 10000 characters");return t}function U(e){let t=e.replace(/\s+/g," ").trim();if(!t||t.length>80)throw new Error("pipeup: choose a name of 1 to 80 characters");if(O(t))throw new Error("pipeup: that name is kept for AI replies; choose another");return t}var V=class{docs=new Map;profile=null;async load(e){return[...this.docs.get(e)?.values()??[]]}async append(e,t){let n=this.docs.get(e);n||this.docs.set(e,n=new Map);for(let e of t)n.set(e.body.id,e)}async loadProfile(){return this.profile}async saveProfile(e){this.profile=e}async saveProfileIfAbsent(e){return this.profile||(this.profile=e),this.profile}},_="";async function G(e,t=""){let n=await e.loadProfile();if(n)return"Reviewer"===n.name?{...n,name:""}:n;let o={identity:await s(),name:t};return e.saveProfileIfAbsent(o)}var J=class e{constructor(e){this.db=e}static open(t="pipeup"){return new Promise((n,o)=>{let r=indexedDB.open(t,1);r.onupgradeneeded=()=>{let e=r.result;e.createObjectStore("ops",{keyPath:["doc","id"]}).createIndex("doc","doc"),e.createObjectStore("meta")},r.onsuccess=()=>{let t=r.result;t.onversionchange=()=>t.close(),n(new e(t))},r.onerror=()=>o(r.error??new Error("pipeup: could not open local storage"))})}close(){this.db.close()}async load(e){return(await this.request("ops","readonly",t=>t.index("doc").getAll(e))).map(e=>e.op)}async append(e,t){if(0===t.length)return;let n=this.db.transaction("ops","readwrite"),o=n.objectStore("ops"),r=X(n);try{for(let n of t)o.put({doc:e,id:n.body.id,op:n})}catch(e){throw n.abort(),r.catch(()=>{}),e}await r}async loadProfile(){return await this.request("meta","readonly",e=>e.get("profile"))??null}async saveProfile(e){await this.request("meta","readwrite",t=>t.put(e,"profile"))}async saveProfileIfAbsent(e){let t=this.db.transaction("meta","readwrite"),n=t.objectStore("meta"),o=X(t),r=e,i=n.get("profile");return i.onsuccess=()=>{i.result?r=i.result:n.put(e,"profile")},await o,r}request(e,t,n){return new Promise((o,r)=>{let i=n(this.db.transaction(e,t).objectStore(e));i.onsuccess=()=>o(i.result),i.onerror=()=>r(i.error??new Error("pipeup: local storage request failed"))})}};function X(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onerror=()=>n(e.error??new Error("pipeup: local storage write failed")),e.onabort=()=>n(e.error??new Error("pipeup: local storage write aborted"))})}function Z(e){let t=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[],o="";for(let e=t.nextNode();e;e=t.nextNode())n.push({node:e,start:o.length}),o+=e.data;return{text:o,nodes:n}}function Q(e,t,n){let o=(e.ownerDocument??e).createRange();return o.setStart(e,0),o.setEnd(t,n),o.toString().length}function ee(e,t,n){let o=te(e,t,!1),r=te(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 te(e,t,n){let o=e.nodes.find(e=>t>=e.start&&t<e.start+e.node.data.length+Number(n));return o&&{node:o.node,offset:t-o.start}}function ne(e){return e.nodeType===Node.ELEMENT_NODE?e:e.parentElement}function oe(e,t){for(let n=ne(e)?.closest("[data-pipeup-id]")??null;n;){if(!t.contains(n))return null;let e=n.getAttribute("data-pipeup-id")??"";if(""!==e&&e.length<=200)return n;n=n.parentElement?.closest("[data-pipeup-id]")??null}return null}function re(e,t,n){return e.slice(t,n).replace(/^[\uDC00-\uDFFF]|[\uD800-\uDBFF]$/g,"")}function ie(e,t){let n=function(e,t){if(e===t)return"";let n=[];for(let o=t;o&&o!==e;o=o.parentElement){let e=1;for(let t=o.previousElementSibling;t;t=t.previousElementSibling)t.tagName===o.tagName&&e++;n.unshift(`${o.tagName.toLowerCase()}:nth-of-type(${e})`)}return":scope > "+n.join(" > ")}(e,t);if(n.length>2e3)throw new Error("pipeup: this element is nested too deeply to comment on — give a nearby container a data-pipeup-id");return n}function ae(e){if(!x(e))throw new Error("pipeup: could not describe this place on the page");return e}function le(e,t){let n=ne(e),o=n?.closest("p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,pre,figcaption,dt,dd,summary,caption")??null;return o&&t.contains(o)?o:n&&t.contains(n)?n:t}function se(e,t,n){if(!t.contains(e.commonAncestorContainer))throw new Error("pipeup: the selection is outside the commentable area");let o=oe(e.commonAncestorContainer,t),a=o??t,{text:l}=Z(a),s=Q(a,e.startContainer,e.startOffset),d=Q(a,e.endContainer,e.endOffset),c=l.slice(s,d);if(""===c)throw new Error("pipeup: select some text to comment on");if(c.length>u)throw new Error("pipeup: selections are limited to 10000 characters");let p=re(l,Math.max(0,s-32),s),h=re(l,d,d+32);return ae({...o?{id:o.getAttribute("data-pipeup-id")??""}:{},path:"",quote:{exact:c,prefix:p,suffix:h},...n?{view:n}:{},fingerprint:i(le(e.startContainer,t).textContent??""),snapshot:re(r(p+c+h),0,200)})}function de(e,t,n,o){let a=oe(e,t);return ae({...a?{id:a.getAttribute("data-pipeup-id")??""}:{},path:ie(a??t,e),...n?{point:{x:ce(n.x),y:ce(n.y)}}:{},...o?{view:o}:{},fingerprint:i(e.textContent??""),snapshot:re(r(e.textContent??""),0,200)})}function ce(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function pe(e,t,n){let o=Array.from({length:t.length+1},(e,t)=>t),r=[...o],i=[t.length];for(let a=1;a<=e.length;a++){r[0]=n?0:a;for(let n=1;n<=t.length;n++){let i=e.charCodeAt(a-1)===t.charCodeAt(n-1)?0:1;r[n]=Math.min(o[n]+1,r[n-1]+1,o[n-1]+i)}i.push(r[t.length]),[o,r]=[r,o]}return i}var ue=(e,t)=>pe(e,t,!1).pop(),he={state:"orphaned",element:null,range:null};function fe(e,t,n={}){let o=e.id?function(e,t){for(let n of e.querySelectorAll("[data-pipeup-id]"))if(n.getAttribute("data-pipeup-id")===t)return n;return null}(t,e.id):t;return e.quote?function(e,t,n,o,r){let a=n??o,l=Z(a),s=function(e,t){if(!t.exact)return-1;let n=-1,o=-1;for(let r=e.indexOf(t.exact);-1!==r;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),l=ve(i,t.prefix)+me(a,t.suffix);l>o&&(n=r,o=l)}return n}(l.text,t);if(s>=0){let r=ee(l,s,s+t.exact.length);if(r){let t=le(r.startContainer,o);return{state:null!==n&&i(t.textContent??"")===e.fingerprint?"attached":"moved",element:t,range:r}}}if(r){let e=a===o?l:Z(o);if(e.text.length<=5e4&&t.exact.length>=12&&t.exact.length<=300){let n=function(e,t,n){let o=t.length;if(0===o)return null;let r=-1,i=1/0;if(pe(e,t,!0).forEach((e,t)=>{t&&e<i&&(i=e,r=t)}),i>n)return null;let a=Math.max(0,r-o),l=1/0;for(let i=Math.max(0,r-o-n);i<=Math.min(r,r-o+n);i++){let n=ue(e.slice(i,r),t);n<l&&(l=n,a=i)}return{start:a,end:r,distance:l}}(e.text,t.exact,Math.floor(t.exact.length/4)),r=n?ee(e,n.start,n.end):null;if(r)return{state:"moved",element:le(r.startContainer,o),range:r}}}return he}(e,e.quote,o,t,!1!==n.fuzzy):function(e,t){if(!t)return he;let n=t;if(e.path){if(!e.path.startsWith(":scope > "))return he;try{n=t.querySelector(e.path)}catch{return he}}return n?{state:i(n.textContent??"")===e.fingerprint?"attached":"moved",element:n,range:null}:he}(e,o)}function me(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function ve(e,t){let n=0;for(;n<e.length&&n<t.length&&e[e.length-1-n]===t[t.length-1-n];)n++;return n}var ge={A:"Link",BUTTON:"Button",P:"Paragraph",LI:"List item",IMG:"Image",TABLE:"Table",TD:"Cell",TH:"Cell",FIGURE:"Figure",SVG:"Graphic",CANVAS:"Graphic",LABEL:"Label",INPUT:"Field",SELECT:"Field",TEXTAREA:"Field",SUMMARY:"Question",BLOCKQUOTE:"Quote",SECTION:"Section",H1:"Heading",H2:"Heading",H3:"Heading",H4:"Heading",H5:"Heading",H6:"Heading"};function we(e){return e.getAttribute("data-pipeup-label")||ge[e.tagName.toUpperCase()]||"Block"}function ye(e){return Ee(r(e.getAttribute("aria-label")??e.getAttribute("alt")??e.innerText??e.textContent??""),40)}function be(e){let t=e.getAttribute("data-pipeup-label");if(t)return t;let n=ye(e);return n?`${we(e)} · ${n}`:we(e)}function xe(e,t,n){let o=e.id??null,i=e.quote?.exact??null,a=e.point?`${Math.round(100*e.point.x)}% across, ${Math.round(100*e.point.y)}% down the element`:null,l=t.element;if("orphaned"===t.state||!l)return{where:`No longer on the page (it read: "${e.snapshot}")`,element:null,id:o,quote:i,pin:a};let s=[],d=e.view?.slide;if(d){let e=l.closest("[data-pipeup-slide]")?.querySelector("h1,h2,h3")?.textContent;s.push(`Slide ${d}`+(e?` "${Ee(r(e))}"`:""))}else{let t=ke(e.view);t&&s.push(t);let o=function(e,t){let n=null;for(let o of t.querySelectorAll("h1,h2,h3")){if(o===e||o.contains(e))break;if(!(4&o.compareDocumentPosition(e)))break;n=o}return n}(l,n);o&&s.push(`Section "${Ee(r(o.textContent??""))}"`)}let c=be(l);return s.push(c),{where:s.join(" › "),element:c,id:o,quote:i,pin:a}}function ke(e){return e?e.label||Object.entries(e).filter(([e,t])=>t&&"slide"!==e).map(([,e])=>e).join(" · "):""}function Ee(e,t=60){return e.length>t?e.slice(0,t-1)+"…":e}var $e="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. Answer in the thread (the Pipeup skill says how) and mark it addressed; never resolve it, the author does.";function Se(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 Le(e,t,n,o){return"ai"===t?Ce(e,"## Comment thread",o,n):Te(e)}function Ae(e,t,n){let o=n.all?e:e.filter(e=>!e.thread.resolved);if("text"===t)return o.map(Te).join("\n");let r=n.all?0:e.length-o.length,i=[`# Review comments: ${Me(n.title)}`,"",`- **Page:** ${Me(n.url)}`,`- **Exported:** ${n.exportedAt.toISOString()}`,`- **Open threads:** ${e.length-e.filter(e=>e.thread.resolved).length}${r?` (${r} resolved, not included)`:n.all?" (resolved ones included)":""}`,"",$e,"",""].join("\n"),a=n.exportedAt.getTime();return i+o.map((e,t)=>Ce(e,`## Thread ${t+1}`,a)).join("\n")}function Me(e){return e.replace(/\s+/g," ").trim()}function Ce(e,t,n,o){let{thread:r,location:i}=e,a=r.root.replies.length,l=[`${t} · ${r.resolved?"resolved":r.addressed?"open, addressed":"open"}`];if(l.push(`- **Thread:** ${r.id}`),o&&l.push(`- **Page:** ${Me(o)}`),l.push(`- **Where:** ${Me(i.where)}`),i.id){let e=Me(i.id.replace(/`/g,""));l.push(`- **Element:** \`[data-pipeup-id="${e}"]\`${i.element?` (${Me(i.element)})`:""}`)}i.quote&&l.push(`- **Quoted text:** "${Me(i.quote)}"`),i.pin&&l.push(`- **Pin:** ${Me(i.pin)}`),r.addressed&&!r.resolved&&l.push(`- **Addressed:** ${Me(r.addressed.text)} (${Me(z(r.addressed))}, ${Se(r.addressed.at,n)})`),l.push(`- **Started by:** ${Me(z(r.root))}, ${Se(r.root.at,n)}${a?` · ${a} ${1===a?"reply":"replies"}`:""}`,"",`**${Me(z(r.root))}** (${Se(r.root.at,n)}): ${Pe(r.root," ")}`);for(let e of r.root.replies)l.push(`- **${Me(z(e))}** (${Se(e.at,n)}): ${Pe(e," ")} \x3c!-- comment:${e.id} --\x3e`);return l.join("\n")+"\n"}function Te(e){let{thread:t,location:n}=e,o=[Me(n.where)+(n.quote?`, on the text "${Me(n.quote)}"`:""),`${Me(z(t.root))}: ${Pe(t.root," ")}`];for(let e of t.root.replies)o.push(` ${Me(z(e))}: ${Pe(e," ")}`);return o.join("\n")+"\n"}function Pe(e,t){return e.deleted?"(deleted)":e.text.replace(/\r\n|\r|\n/g,"\n"+t)+(e.edited?" (edited)":"")}var Ne="0.6.0",qe=new Map,ze=new Map,Re=new Map,Oe={},De=e=>`${qe.get(e)??""}|${ze.get(e)??""}`;function Ie(e,t={},...n){let o=document.createElement(e);for(let[e,n]of Object.entries(t))void 0===n||!1===n||("class"===e?o.className=String(n):o.setAttribute(e,!0===n?"":n));for(let e of n)null!=e&&!1!==e&&o.append(e);return o}function Fe(e,t){let n=e.getRootNode().activeElement;t&&n instanceof HTMLElement&&e.contains(n)&&n.blur(),e.inert=t}function Be(e,t,n=null){let o=e.getRootNode().activeElement,r=!1;for(let o=t.length;o--;n=t[o])t[o].nextSibling!==n&&(r=!!e.insertBefore(t[o],n));return r&&o&&t.some(e=>e.contains(o))&&o.focus({preventScroll:!0}),r}var He=()=>{let e=window.getSelection();return e&&!e.isCollapsed&&e.toString().trim()?e:null};function je(e,t){return e.length>t?e.slice(0,t-1)+"…":e}function We(e,t,n=4){e.style.left=t.left-n+"px",e.style.top=t.top-n+"px",e.style.width=`${t.width+2*n}px`,e.style.height=`${t.height+2*n}px`}var Ke=/\bhttps?:\/\/[^\s<>"'`]+/gi,Ye=/[\u202A-\u202E\u2066-\u2069]/;function Ue(e){let t=0,n=0;for(let o of e)"("===o?t++:")"===o&&n++;let o=e.length;for(;o>0;){let r=e[o-1];if(")"===r&&n>t)n--;else if(!".,;:!?'\"]}".includes(r))break;o--}return e.slice(0,o)}function Ve(e){let t=[],n=e.split("\n").filter(e=>{let n=/^\[(\d{1,2})\]:?\s+(\S+)(?:\s+([^|]{1,40}?))?(?:\s*\|\s*(.{1,300}))?$/.exec(e.trim()),o=n?.[2]?function(e){return/^slide:\d{1,4}$/.test(e)||/^quote:\S{1,300}$/.test(e)?e:function(e){if(e.length>2048||Ye.test(e))return null;try{let t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol?t.href:null}catch{return null}}(e)}(n[2]):null;return n?.[1]&&o&&t.push({n:n[1],to:o,label:n[3]?.trim()??"",says:n[4]?.trim()??""}),!(n?.[1]&&o)}).join("\n").replace(/\s*\[\d{1,2}\]/g,"").trim();if(!t.length)return _e(e);let o=t.slice(0,4).map(e=>{let t=e.to.startsWith("slide:"),n=e.label||(t?`Slide ${e.to.slice(6)}`:`[${e.n}]`),o=[t?Ie("i",{class:"sl"}):null,Ie("span",{},t||""===e.label?n:`[${e.n}] ${n}`),e.says?Ie("span",{class:"rc",role:"tooltip"},e.says):null];if(/^https?:/.test(e.to)){let t=Ie("a",{class:"ref",href:e.to,target:"_blank",rel:"noopener noreferrer",title:e.says?void 0:e.to},...o);return t.addEventListener("click",e=>e.stopPropagation()),t}let r=Ie("button",{class:"ref",type:"button",title:e.says?void 0:t?n:`Show where: ${n}`},...o);return r.addEventListener("click",t=>{t.stopPropagation(),Oe.go?.(e.to)}),r});return[..._e(n),Ie("div",{class:"refs"},...o)]}function _e(e){let t=[],n=0;for(let o of e.matchAll(Ke)){if(o[0].length>2048||Ye.test(o[0]))continue;let r,i=Ue(o[0]),a=o.index??0;try{let e=new URL(i);if("http:"!==e.protocol&&"https:"!==e.protocol)continue;r=e.href}catch{continue}a>n&&t.push(e.slice(n,a));let l=Ie("a",{href:r,target:"_blank",rel:"noopener noreferrer"},i);l.addEventListener("click",e=>e.stopPropagation()),t.push(l),n=a+i.length}return n<e.length&&t.push(e.slice(n)),t}var Ge="http://www.w3.org/2000/svg",Je={comment:["M20.5 11.5a8 8 0 0 1-11.7 7.1L4 19.8l1.2-4.4A8 8 0 1 1 20.5 11.5z","M12.3 8.2v6.6M9 11.5h6.6"],send:["M21 12L3.5 4.5 6.2 12l-2.7 7.5zM6.2 12H13"],copy:["M10 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2z","M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"],resolve:["M5 12.5l4.5 4.5L19 7.5"],reopen:["M3 12a9 9 0 1 0 3-6.7","M3 4v5h5"],lines:["M4 7h16M4 12h10M4 17h7"],list:["M3 6.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M3 12a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M3 17.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M9 6.5h11M9 12h11M9 17.5h7"],expand:["M14 4h6v6M20 4l-6 6M10 20H4v-6M4 20l6-6M20 14v6h-6M20 20l-6-6M4 10V4h6M4 4l6 6"],pin:["M6 18v-6a6 6 0 1 1 6 6z"],shrink:["M20 10h-6V4M14 10l6-6M4 14h6v6M10 14l-6 6M14 20v-6h6M14 14l6 6M10 4v6H4M10 10L4 4"],bubble:["M20.5 11.5a8 8 0 0 1-11.7 7.1L4 19.8l1.2-4.4A8 8 0 1 1 20.5 11.5z"],close:["M6 6l12 12M18 6L6 18"],edit:["M4 20h4L19 9l-4-4L4 16z"]};function Xe(e,t=15,n){let o=Ze(Je[e],t);return n&&o.setAttribute("stroke-width",String(n)),o}function Ze(e,t){let n=document.createElementNS(Ge,"svg"),o={width:String(t),height:String(t),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[e,t]of Object.entries(o))n.setAttribute(e,t);for(let t of e){let e=document.createElementNS(Ge,"path");e.setAttribute("d",t),n.append(e)}return n}var Qe=(e,t,n)=>`M${e} ${t}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 -${2*n} 0`,et={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${Qe(7.4,11.5,1.9)}${Qe(12.8,11.5,1.9)}M11.3 14.6l.7 1 .7-1`,Bear:`${Qe(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:`${Qe(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 tt(e){let t=/[\p{L}\p{N}]/u.exec(e);if(!t)return"";let n=t[0].toUpperCase();return 1===[...n].length?n:t[0]}var nt=(e,t)=>tt(t)||q(e);function ot(e,t,n=!1){return O(t)?Ie("span",{class:n?"av ai busy":"av ai","aria-hidden":"true"},"AI"):Ie("span",{class:`av c${N(e)}`,"aria-hidden":"true","data-animal":q(e)},tt(t)||Ze([et[M[P(e)]]],24))}function rt(e,t){setTimeout(()=>{e.remove(),t?.()},320)}function it(e){return requestAnimationFrame(()=>{e.offsetWidth,e.classList.add("in")}),e}var at=null,lt=e=>{at=e},st="pu-source";function dt(e){let t=Ie("textarea",{class:"input",rows:"1","aria-label":e.label}),n=Ie("button",{class:"send",type:"button","aria-label":"Send",title:"Send",inert:!0},Xe("send")),o=Ie("span",{class:"tools"});o.hidden=!0;let r=Ie("div",{class:"row"},e.before,t,o,n),i=e.kind??"comment",a=!1,l=new Set,s=()=>{for(let e of[...l])e()},d=()=>{let e=""!==t.value.trim();n.classList.toggle("show",e),n.inert=!e,t.style.height="auto",t.style.height=`${Math.max(27,t.scrollHeight)}px`},c=()=>{let e=-1,n=0,o=(o,r)=>{e<0&&(e=t.selectionStart,n=0);let i=t.value.slice(0,e),a=o&&i&&!/\s$/.test(i)&&!/^\s/.test(o)?" ":"";t.setRangeText(a+o,e,e+n,"end"),n=a.length+o.length,r&&(e=-1),d()};return{update:e=>o(e,!1),commit:e=>o(e,!0),cancel:()=>{e>=0&&n&&t.setRangeText("",e,e+n,"end"),e=-1,n=0,d()}}},p=new Map,u=()=>{let n=(at?.tools()??[]).filter(e=>!1!==e.available?.());for(let[e,t]of p)n.some(t=>t.id===e)||(t.remove(),p.delete(e));for(let a of n){if(p.has(a.id))continue;let n=Ie("button",{class:"ib tool",type:"button","aria-label":a.label,title:a.label,"aria-pressed":"false"},Ze(a.icon,15));n.addEventListener("mousedown",e=>e.preventDefault()),n.addEventListener("click",o=>{o.stopPropagation();try{a.press({kind:i,thread:e.thread?.()??null,text:()=>t.value,focus:()=>t.focus({preventScroll:!0}),connected:()=>r.isConnected,setPressed:e=>n.setAttribute("aria-pressed",String(e)),dictate:c,onEnd:e=>(l.add(e),()=>l.delete(e))})}catch(e){globalThis.reportError?.(e)}}),p.set(a.id,n),o.append(n)}o.hidden=0===p.size};u(),r.addEventListener(st,u);let h=async()=>{let o=t.value.trim();if(o&&!a){a=!0;try{await e.q(o),n.matches(":focus")&&t.focus(),t.value="",d(),s()}catch{}finally{a=!1}}};return r.addEventListener("mousedown",e=>{e.target===t||n.contains(e.target)||o.contains(e.target)||(e.preventDefault(),t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}),t.addEventListener("input",d),t.addEventListener("keydown",n=>{n.stopPropagation(),"Enter"!==n.key||n.shiftKey||n.isComposing?"Escape"===n.key&&(n.preventDefault(),t.value="",d(),t.blur(),s(),e.U?.()):(n.preventDefault(),h())}),n.addEventListener("click",e=>{e.stopPropagation(),h()}),{element:r,input:t,focus:()=>t.focus({preventScroll:!0})}}var ct=1,pt=["sync","menu","notify","note","composer","panel","styles","status","overlay","here","sign"],ut=/^[a-z][a-z0-9-]{1,23}$/,ht=new Set(["local","file","page","user","pipeup","presence","sync"]),ft=class{constructor(e,t,n){this.ctx=e,this.shadow=t,this.after=n,lt({tools:()=>this.K,note:()=>[...this.X.values()].at(-1)??null})}G=0;$=[];X=new Map;writing=new Map;marked=new Map;paint=0;J=new Map;K=[];Q=new Set;I=new Set;z=new Set;W=new Map;S=new Map;j=new Map;remote={n:0,who:new Set};last=0;timer=0;de="";subscribe(e){return this.z.add(e),()=>{this.z.delete(e)}}changed(e){e&&this.G++;for(let t of[...this.z])t(e);for(let e of this.ctx.t.querySelectorAll(".row, .draft"))e.dispatchEvent(new Event(st))}N(e,t){let n=this.j.get(e)??this.j.set(e,new Set).get(e),o=()=>{n.delete(o)&&t()};return n.add(o),o}ce(){return[...this.J.values()].map(e=>e.text).join(" · ")}Ae(e,t){return this.$.push(t),this.changed(!0),{update:()=>this.changed(!1),remove:this.N(e,()=>{this.$.splice(this.$.indexOf(t),1),this.changed(!0)})}}setThread(e,t,n){let o=this.writing.get(e)??this.writing.set(e,new Set).get(e);null===n?(qe.delete(t),o.delete(t)):(qe.set(t,n),o.add(t)),this.repaint()}setMark(e,t,n,o){let r=this.marked.get(e)??this.marked.set(e,new Set).get(e);if(null===n){if(Re.delete(t),!ze.delete(t))return;r.delete(t)}else{if(ze.get(t)===n&&!!Re.get(t)==!!o)return;ze.set(t,n),o?Re.set(t,o):Re.delete(t),r.add(t)}this.repaint()}repaint(){this.paint||(this.paint=window.requestAnimationFrame(()=>{this.paint=0,this.ctx.u()}))}pe(e,t,n){n?e.set(t,n):e.delete(t),this.changed(!1)}Me(e,t){return this.K.push(t),this.changed(!1),this.N(e,()=>{this.K.splice(this.K.indexOf(t),1),this.changed(!1)})}closed(){return this.ctx.state.hidden&&!this.ctx.state.s}Le(e,t){this.closed()?this.S.set(e,t):this.ctx.Y(t)}flush(){if(this.closed()||0===this.S.size)return;let e=[...this.S.values()].at(-1);this.S.clear(),this.ctx.Y(e)}Ce(){return this.shadow.activeElement instanceof HTMLTextAreaElement||[...this.ctx.t.querySelectorAll("textarea")].some(e=>""!==e.value.trim())}Pe(e){this.ctx.state.hidden||this.ctx.E(e)}Oe(e,t){if("local"!==t&&""!==t){for(let{body:t}of e)t.author===this.ctx.doc.me||"create"!==t.kind&&"reply"!==t.kind||(this.remote.n++,this.remote.who.add(t.name||q(t.author)));this.ue()}}ue(e=Math.max(0,this.last+1e4-Date.now())){this.timer||!this.remote.n||(this.timer=window.setTimeout(()=>{if(this.timer=0,this.ctx.state.hidden||this.Ce())return this.ue(1e3);let{n:e,who:t}=this.remote;this.remote={n:0,who:new Set},this.last=Date.now(),this.ctx.E(`${e} new comment${1===e?"":"s"} from ${1===t.size?[...t][0]:`${t.size} people`}`)},e))}$e(e){let t=this.W.get(e);return t||(t=Ie("div",{class:"ov","aria-hidden":"true","data-addon":e}),this.ctx.t.insertBefore(t,this.after.nextSibling),this.W.set(e,t)),t}Ie(e,t){let n=this.ctx.host.ownerDocument.defaultView?.CSSStyleSheet,o=n&&"replaceSync"in n.prototype&&"adoptedStyleSheets"in this.shadow?new n:null;o&&(o.replaceSync(t),this.shadow.adoptedStyleSheets=[...this.shadow.adoptedStyleSheets,o]);let r=o??this.shadow.appendChild(Ie("style",{},t));return this.N(e,()=>o?this.shadow.adoptedStyleSheets=this.shadow.adoptedStyleSheets.filter(e=>e!==o):r.remove())}fe(e,t,n){return t.add(n),this.N(e,()=>t.delete(n))}Ne(e,t){return this.fe(e,this.Q,t)}Re(e,t){let n=this.fe(e,this.I,t);return this.call(this.I,t,this.he()),n}he(){let{state:e}=this.ctx,t=this.shadow.activeElement;return{shown:!e.hidden,commentMode:e.d,allOpen:e.c,dark:this.ctx.t.classList.contains("dark"),view:this.ctx.p.view(),writing:t instanceof HTMLTextAreaElement?t.closest("[data-thread]")?.dataset.thread??"":null}}T(){for(let e of[...this.Q])this.call(this.Q,e);if(0===this.I.size)return;let e=this.he(),t=JSON.stringify(e);if(t!==this.de){this.de=t;for(let t of[...this.I])this.call(this.I,t,e)}}call(e,t,...n){try{t(...n)}catch(n){e.delete(t),globalThis.reportError?.(n)}}He(e,t,n){let o=this.ctx.t,r=this.shadow.activeElement,i=Ie("button",{class:"ib",type:"button","aria-label":"Close"},Ze(["M6 6l12 12M18 6L6 18"],15)),a=Ie("div",{class:"xp",role:"dialog","aria-label":n.label,"data-addon":e},Ie("div",{class:"hd"},Ie("span",{},n.label),i),Ie("div",{class:"xb"},t)),l=[...o.children].filter(e=>e instanceof HTMLElement&&!e.inert);for(let e of l)e.inert=!0;o.append(a),a.offsetWidth,a.classList.add("show");let s=e=>{"Escape"===e.key&&(e.stopPropagation(),e.preventDefault(),d())},d=this.N(e,()=>{window.removeEventListener("keydown",s,!0);for(let e of l)e.inert=!1;a.classList.remove("show"),a.inert=!0,window.setTimeout(()=>a.remove(),300),r?.focus?.({preventScroll:!0});try{n.onClose?.()}catch(e){globalThis.reportError?.(e)}});return i.addEventListener("click",d),window.addEventListener("keydown",s,!0),(a.querySelector("button, input, textarea, select, a[href]")??a).focus?.({preventScroll:!0}),{close:d}}clear(e){for(let t of[...this.j.get(e)??[]])t();this.j.delete(e),this.W.get(e)?.remove(),this.W.delete(e);for(let t of[this.X,this.J,this.S])t.delete(e);for(let t of this.writing.get(e)??[])qe.delete(t);this.writing.delete(e);for(let t of this.marked.get(e)??[])ze.delete(t),Re.delete(t);this.marked.delete(e),this.repaint(),this.changed(!0)}destroy(){window.clearTimeout(this.timer),lt(null),this.z.clear()}},mt=new Map,vt=null,gt=(()=>{let e=globalThis.Pipeup;return e?.VERSION?e:null})();function wt(){return gt?gt.addons():[...mt.values()].map(e=>({...e.info}))}function yt(e){if(gt)return gt.use(e);let t=e=>console.warn(`pipeup: ${e}`),n=e;if(!n||"object"!=typeof n||"string"!=typeof n.id||!ut.test(n.id)||ht.has(n.id)||"function"!=typeof n.setup||"string"!=typeof n.network?.says)return t("an add-on needs an id of 2 to 24 lowercase letters, digits and dashes (not a reserved one), a setup function and a network statement");if(mt.has(n.id))return t(`the add-on "${n.id}" is already registered; the second is ignored`);let o={id:n.id,version:String(n.version??""),network:n.network,state:"waiting"},r=(n.needs??[]).find(e=>!pt.includes(e));!function(e){let t=typeof document>"u"?null:document.documentElement.getAttribute("data-pipeup-addons");return null===t||t.toLowerCase().split(/[\s,]+/).includes(e)}(n.id)?(o.state="off",o.reason="this page doesn't allow it",t(`the add-on "${n.id}" is not in this page's data-pipeup-addons list, so it is off`)):1!==n.api?(o.state="off",o.reason=`needs add-on API ${String(n.api)}; this Pipeup has 1`):r&&(o.state="off",o.reason=`this Pipeup has no ${r} slot`);let i={addon:e,info:o};mt.set(n.id,i),vt?.i&&"waiting"===o.state&&bt(i,vt)}async function bt(e,t){let n,o,{addon:r,info:i}=e,a=new AbortController,l=new Set,{surface:s,doc:d}=t,c=()=>!a.signal.aborted,p=Object.assign(()=>{},{update(){},remove(){},close(){}}),u=e=>(...t)=>c()?e(...t):p,h={id:d.id,me:d.me,get name(){return d.name},threads:()=>d.threads(),ops:()=>d.ops(),onChange:e=>{let t=d.onChange(e);return l.add(t),()=>{t(),l.delete(t)}}},f=r.id,m={api:1,version:t.version,document:h,root:t.root,ephemeral:t.ephemeral,signal:a.signal,has:e=>pt.includes(e),off:e=>{o=String(e)},merge:e=>c()?d.merge(e,f):Promise.resolve(0),addMenuItem:u(e=>s.Ae(f,e)),notify:u(e=>s.Le(f,e)),announce:u(e=>s.Pe(e)),setComposerNote:u(e=>s.pe(s.X,f,e)),setThreadNote:u((e,t)=>s.setThread(f,e,t)),setThreadMark:u((e,t,n)=>s.setMark(f,e,t,n)),addComposerTool:u(e=>s.Me(f,e)),openPanel:u((e,t)=>s.He(f,e,t)),addStyles:u(e=>s.Ie(f,e)),setStatus:u(e=>s.pe(s.J,f,e)),overlay:()=>s.$e(f),onFrame:u(e=>s.Ne(f,e)),where:e=>s.ctx.p.view(e),isHere:e=>s.ctx.p.f(e),go:e=>s.ctx.p.R(e),onUi:u(e=>s.Re(f,e)),avatar:(e,t)=>{let n=ot(e,t);return n.classList.add("in"),n},sign:(e,t)=>d.sign(`${f}/${e}`,t)},v=()=>{if(c()){a.abort();for(let e of[...l])e();try{n?.()}catch(e){globalThis.reportError?.(e)}s.clear(f),"on"===i.state&&(i.state="waiting")}};e.stop=v;try{if(n=await r.setup(m),!c())return void n?.();if(void 0!==o)return v(),i.state="off",void(i.reason=o);i.state="on",delete i.reason}catch(e){i.state="failed",i.reason=function(e){return e instanceof Error?e.message:String(e)}(e),v(),i.state="failed",globalThis.reportError?.(e)}}function xt(e,t){return{markdown:Ae(e,"ai",t),threads:e.filter(e=>t.all||!e.thread.resolved).map(({thread:e,location:t})=>{let n={id:e.id,state:e.resolved?"resolved":e.addressed?"addressed":"open",where:t.where,comments:[e.root,...e.root.replies].map(e=>({id:e.id,by:z(e),agent:O(e.name),at:new Date(e.at).toISOString(),text:e.deleted?"":e.text}))};return t.id&&(n.element=t.id),t.quote&&(n.quote=t.quote),t.pin&&(n.pin=t.pin),e.addressed&&!e.resolved&&(n.addressed={note:e.addressed.text,by:z(e.addressed)}),n})}}var kt=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform)?"⇧⌥C":"Shift+Alt+C",Et="Shift+Alt+C";function $t(e,t){let n=function(e){let t=Ie("button",{class:"me",type:"button",tabindex:"-1","aria-hidden":"true"});t.addEventListener("mousedown",e=>e.preventDefault());let n=dt({label:"Comment",kind:"comment",before:t,q:e.q,U:e.U}),o=Ie("div",{class:"note"}),r=()=>{let e=at?.note()??null;o.textContent=e??"",o.hidden=!e};r();let i=Ie("div",{class:"say"}),a=Ie("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"}),l=Ie("div",{class:"nf"},a),s=Ie("div",{class:"you"},i,l),d="",c=!1,p=()=>{let n=e.name(),o=n?"change":"add your name";if(t.title=n?"Change your name":"Add your name",!t.lastChild||d!==n){let o=ot(e.me,n),r=t.lastChild;r?(it(o),rt(r)):o.classList.add("in"),t.append(o),d=n}let r=Ie("button",{type:"button"},o);r.addEventListener("click",h),i.replaceChildren(Ie("span",{class:"nm"},n||`You're ${q(e.me)}`)," · ",r)},u=e=>{s.classList.toggle("naming",e),Fe(i,e),Fe(l,!e)};function h(t){t.stopPropagation(),a.value=e.name(),u(!0),a.focus({preventScroll:!0}),a.select()}let f=()=>{u(!1),n.focus()};t.addEventListener("click",h),a.addEventListener("keydown",t=>{if(t.stopPropagation(),"Escape"===t.key)t.preventDefault(),f();else if("Enter"===t.key){t.preventDefault();let n=a.value.trim();if(!n||n===e.name())return f();if(c)return;c=!0,e.rename(n).finally(()=>{c=!1,p(),f()})}}),p(),u(!1);let m=Ie("div",{class:"ctx"},e.label),v=Ie("div",{class:"draft"},m,o,n.element,s);return v.addEventListener(st,r),{element:v,ge:()=>{let{selectionStart:e,selectionEnd:t}=n.input;return()=>{n.focus(),n.input.setSelectionRange(e,t)}},Z:e=>{m.hidden=e},ve:e=>{m.textContent=e},focus:()=>n.focus(),De:()=>""===n.input.value.trim()}}({label:t.label,me:e.doc.me,name:()=>e.s.name(),rename:t=>e.s.rename(t),q:t=>e.Be(t),U:()=>e.Fe()});return e.H(n),n}function St(e,t){if("orphaned"===t.state||!t.element||e.quote)return null;let n=t.element.getBoundingClientRect();if(!n.width&&!n.height)return null;if(e.point)return{x:n.left+e.point.x*n.width,y:n.top+e.point.y*n.height};let o=t.element.ownerDocument.createRange();o.selectNodeContents(t.element);let 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 Lt(e){return e.range?[...e.range.getClientRects()]:[]}function At(e,t){let n=Lt(t)[0];if(n)return n.top;if("orphaned"===t.state||!t.element)return null;let o=t.element.getBoundingClientRect();return e.point?o.top+e.point.y*o.height:o.top}function Mt(e,t){let n=Lt(t).at(-1);if(n)return{x:n.left,y:n.bottom,below:!0};let o=St(e,t);return o?{...o,below:!1}:null}function Ct(e,t,n){for(let o of n)if(e>=o.left&&e<=o.right&&t>=o.top&&t<=o.bottom)return!0;return!1}var Tt=()=>window.innerWidth>=900?400:300,Pt=()=>window.innerWidth<=480;function Nt(e,t,n){let o=e.top-t.height-10;return o<8&&(o=e.top+e.height+10),{left:Math.max(8,Math.min(e.left+e.width/2-t.width/2,n.width-t.width-8)),top:o}}function qt(e,t){let n=e.resolved.get(t.id);return n?.range?.startContainer??n?.element??null}var zt=e=>(t,n)=>{let o=qt(e,t),r=qt(e,n),i=e=>e.anchor.point??{x:0,y:-1};return o!==r?!r||o&&4&o.compareDocumentPosition(r)?-1:1:i(t).y-i(n).y||i(t).x-i(n).x},Rt=e=>`${e} ${1===e?"reply":"replies"}`;function Ot(e,t,n){let o={...n},r=e.id,i=Ie("div",{class:"rbox always"},Ie("div",{},dt({label:"Reply",kind:"reply",thread:()=>r,q:e=>t.reply(r,e),U:t.close}).element)),a=Ie("div",{}),l=Ie("span",{class:"note"},"This thread was resolved. Your words are kept until you send or clear them.");l.hidden=!0,i.prepend(l);let s=Ie("div",{}),d=null,c=null,p=null,u="",h=Ie("div",{},s,Ie("div",{class:"more"},a)),f=new Map,m=new Map,v=new Map,g=e=>{let t=nt(e.author,e.name),n=f.get(e.id),o=n?.e;if((!o||n.key!==t)&&(o=it(ot(e.author,e.name)),n)){let t=n.e;v.set(e.id,t),rt(t,()=>v.get(e.id)===t&&v.delete(e.id))}o.title=z(e),m.set(e.id,{key:t,e:o});let r=v.get(e.id);return r?[r,o]:[o]},w=(e,t,n)=>{let o=Ie("button",{class:"ib",type:"button","aria-label":t,title:t},Xe(e));return o.addEventListener("click",e=>{e.stopPropagation(),n()}),o};function y(e,n={}){Object.assign(o,n),r=e.id;let v=(o.now??Date.now)(),y=e.root.replies.length,b=e=>Ie("span",{class:"who"},`${z(e)} · ${Se(e.at,v)}`),x=e=>Ie("div",{class:e.deleted?"tx del":"tx"},...e.deleted?["Deleted"]:[...O(e.name)?Ve(e.text):_e(e.text),e.edited?" (edited)":""]),k=e.resolved?"Resolved"+(y?` · ${Rt(y)}`:""):e.addressed?"Addressed"+(y?` · ${Rt(y)}`:""):y?Rt(y):"",E=Ie("div",{class:"column"===o.D?k?"ft has-rest":"ft":"ft open"},"column"===o.D&&k?Ie("span",{class:"rest"},k):null,Ie("span",{class:"hover"},b(e.root),Ie("span",{class:"acts"},w("copy","Copy thread",()=>t.copy(e.id)),e.resolved?w("reopen","Reopen",()=>{t.reopen(e.id)}):w("resolve","Resolve",()=>{t.resolve(e.id)})))),$=o.lost?Ie("div",{class:"ctx"},`${o.place||"No longer on the page"} — it read “${je(o.lost,120)}”`):o.quote?Ie("div",{class:"ctx"},`“${je(o.quote,80)}”`):null;m=new Map;let S=Ie("div",{class:"root"},...g(e.root),$,x(e.root),E);s.replaceWith(S),s=S,d?.remove();let L=qe.get(e.id);d=y||void 0!==L?Ie("div",{class:"rps"},...e.root.replies.map(e=>Ie("div",{class:"it"},...g(e),x(e),Ie("div",{class:"column"===o.D?"rft":"rft open"},b(e)))),void 0===L?null:Ie("div",{class:"it ghost"},ot("",R,!0),Ie("div",{class:"tx"},L,Ie("span",{class:"dots"},Ie("i"),Ie("i"),Ie("i"))),Ie("div",{class:"rft open"},Ie("span",{class:"who"},`${R} · writing now`)))):null,d&&a.prepend(d);let A=e.addressed&&!e.resolved?e.addressed:null,M=A?`${A.text}|${A.author}|${A.at}`:"";if(M!==u&&(p?.remove(),p=null,u=M,A)){let n=(e,t)=>{let n=Ie("button",{type:"button"},e);return n.addEventListener("click",e=>{e.stopPropagation(),t()}),n};p=Ie("div",{class:"adr"},Ie("small",{},`Addressed · ${z(A)} · ${Se(A.at,v)}`),A.text,Ie("div",{class:"go"},n("Resolve",()=>{t.resolve(e.id)}),n("Still not right",()=>{t.notRight(e.id)})))}p&&a.insertBefore(p,c??(i.parentNode===a?i:null)),c?.remove();let C=ze.get(e.id),T=Re.get(e.id);if(c=void 0===C?null:Ie("div",{class:"seen"},Ie("i"),C),c&&T){let e=Ie("button",{type:"button"},"Check again");e.addEventListener("click",e=>{e.stopPropagation(),T()}),c.append(e)}c&&a.insertBefore(c,i.parentNode===a?i:null),f=m;let P=""!==i.querySelector("textarea").value.trim();l.hidden=!(e.resolved&&P),e.resolved&&!P?i.remove():i.parentNode!==a&&a.append(i),h.className=e.resolved?"thread resolved":"thread",h.setAttribute("data-thread",e.id)}return y(e),{element:h,update:y}}function Dt(e,t){let n=new Map,o=Ie("div",{class:"tip",role:"tooltip"}),r=Ie("div",{class:"mark"}),i=Ie("div",{class:"pop",role:"dialog","aria-label":"Comment thread"});o.inert=i.inert=!0,e.t.append(r,o,i);let a,l=Ie("div",{class:"bub pin ghost","aria-hidden":"true"}),s=[],d=null,c=null,p=null,u=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,h=0,f=null,m=null,v=null,g=0,w=e=>s.find(t=>t.id===e)??null,y=()=>t.ee||e.state.c,b=!1,x=t=>{let n=e.resolved.get(t.id);return n?Mt(t.anchor,n):null};function k(t,n,o){let{left:r,top:i}=function(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)}}(n,{width:t.offsetWidth||o,height:t.offsetHeight},function(e){let t=window.innerWidth;return{width:e&&!Pt()?t-320:t,height:window.innerHeight}}(e.state.c));t.style.left=`${r}px`,t.style.top=`${i}px`}function E(t){let n=t&&y()&&e.state.i!==t?w(t):null,r=n?x(n):null;if(!n||!r)return v=null,o.classList.remove("show"),void Fe(o,!0);if(v!==n.id){let e=n.root.replies.length;o.replaceChildren(Ie("div",{class:"tx clamp"},...n.root.deleted?["Deleted"]:_e(n.root.text)),Ie("div",{class:"who"},`${z(n.root)}${e?` · ${e} ${1===e?"reply":"replies"}`:""}`)),v=n.id}k(o,r,260),o.classList.contains("show")||o.offsetWidth,o.classList.add("show"),o.inert=!1}function $(t){f=t,E(t),e.m(t)}function S(e){window.clearTimeout(g),null===e?g=window.setTimeout(()=>$(null),y()?400:0):$(e)}function L(t){let o=n.get(t.id);if(o)return o;let i=Ie("button",{class:"bub",type:"button","data-thread":t.id});return i.addEventListener("mouseenter",()=>S(t.id)),i.addEventListener("mouseleave",()=>S(null)),i.addEventListener("click",n=>{n.stopPropagation(),E(null),e.open(t.id)}),e.t.insertBefore(i,r),n.set(t.id,i),i}o.addEventListener("mouseenter",()=>window.clearTimeout(g)),o.addEventListener("mouseleave",()=>S(null)),o.addEventListener("click",t=>{t.stopPropagation();let n=v;n&&(window.clearTimeout(g),$(null),e.open(n))});let A=!1;function M(){let t=e.state.o,n=p&&t&&!t.anchor.quote&&!t.anchor.point?t.resolved.element:null;if(n){let{left:e,top:t,above:o}=function(e,t,n,o=12,r=44){let i=e.top-r>=8,a=e.top+e.height+8+(i?0:r),l=e.top-8-(i?r:0)-t.height,s=a+t.height<=n.height-o||l<o,d=s?a:l;return{above:!s,left:Math.max(o,Math.min(e.left,n.width-t.width-o)),top:Math.max(o,d)}}(n.getBoundingClientRect(),{width:i.offsetWidth||Tt(),height:i.offsetHeight},{width:window.innerWidth,height:window.innerHeight}),r=null!==p?.above&&p?.above!==o;if(p&&(p.above=o),r&&T())return;return i.style.left=`${e}px`,void(i.style.top=`${t}px`)}let o=p&&t?Mt(t.anchor,t.resolved):d?x(d):null;o&&k(i,o,Tt())}let C=t=>e.state.d&&!t.anchor.quote&&!t.anchor.point;function T(e=()=>{}){return window.clearTimeout(h),u?(i.classList.remove("show"),h=window.setTimeout(()=>{e(),M(),i.classList.add("show")},220),!0):(e(),i.classList.add("glide"),h=window.setTimeout(()=>i.classList.remove("glide"),450),!1)}let P=t=>{if(e.w(t)){let e=t.composedPath()[0];return null!==m&&!(e instanceof Element&&e.closest(".tip,.bub"))&&S(null),void(m=null)}let n=e.ne(t.clientX,t.clientY)?.id??null;n!==m&&(m=n,S(n))},N=t=>{if(e.w(t))return;let n=window.getSelection();if(n&&!n.isCollapsed||(e.state.d?t.altKey:t.target instanceof Element&&t.target.closest("a,button,input,select,textarea,label,summary,[role=button],[contenteditable]")))return;let o=e.ne(t.clientX,t.clientY);o&&(e.ye(t),E(null),e.open(o.id))};return window.addEventListener("pointermove",P,{capture:!0,passive:!0}),window.addEventListener("click",N,!0),{u:function(o){s=o;let l=new Set;for(let t of o){if(!e.B(t)||t.anchor.quote)continue;let n=e.resolved.get(t.id);if(!n||"orphaned"===n.state)continue;l.add(t.id);let o=L(t);o.classList.toggle("done",t.resolved),o.classList.toggle("on",e.state.i===t.id),o.classList.toggle("pin",void 0!==t.anchor.point);let r=`Comment on ${be(n.element)}: ${je(t.root.text,60)}`;o.getAttribute("aria-label")!==r&&o.setAttribute("aria-label",r)}Be(e.t,o.filter(e=>l.has(e.id)).sort(zt(e)).map(e=>n.get(e.id)),r);for(let[e,t]of n)l.has(e)||(t.classList.remove("in"),n.delete(e),window.setTimeout(()=>t.remove(),300));E(f),b!==e.state.c&&i.classList.contains("show")&&!u&&T(),b=e.state.c;let m=t.ee?e.state.o:null;if(m){let t=m.anchor.point??m.resolved.element;p?.of!==m?(window.clearTimeout(h),i.classList.remove("glide"),p={l:$t(e,m),of:m,at:t,above:null},p.l.Z(C(m)),i.replaceChildren(p.l.element),i.inert=!1,p.l.focus(),d=null,c=null,M(),i.classList.add("show")):p&&(p.at!==t&&(p.at=t,p.above=null,T(()=>p?.l.ve(m.label))),p.l.Z(C(m)));let n=!e.p.f(m.anchor.view);return void(n!==A&&(A=n,i.classList.toggle("show",!n),i.inert=n,n||M()))}p&&(window.clearTimeout(h),i.classList.remove("glide"),p=null,A=!1,e.H(null));let v=y()&&e.state.i?w(e.state.i):null;if(!v||!e.B(v))return d=null,c=null,i.classList.remove("show"),void Fe(i,!0);let g=v.anchor.quote?.exact??null;d&&c&&d.id===v.id?(d!==v||a!==De(v.id))&&(c.update(v,{quote:g}),d=v,a=De(v.id)):(c=Ot(v,e.te,{D:"popover",quote:g}),i.replaceChildren(c.element),d=v,a=De(v.id),M(),i.classList.add("show"),i.inert=!1)},T:function(){for(let[t,o]of n){let n=w(t),r=e.resolved.get(t),i=n&&r?St(n.anchor,r):null;!i||i.y<-40||i.y>window.innerHeight+40?o.style.visibility="hidden":(o.style.visibility="",o.style.left=`${i.x}px`,o.style.top=`${i.y}px`,o.classList.contains("in")||(o.offsetWidth,o.classList.add("in")))}let t=e.state.o,o=t?.anchor.point&&e.p.f(t.anchor.view)?St(t.anchor,t.resolved):null;o?(l.style.left=`${o.x}px`,l.style.top=`${o.y}px`,l.classList.contains("in")||(e.t.insertBefore(l,r),l.offsetWidth,l.classList.add("in"))):l.classList.contains("in")&&(l.classList.remove("in"),window.setTimeout(()=>l.classList.contains("in")||l.remove(),300)),i.classList.contains("show")&&M();let a=function(){if(!y())return null;let t=e.state.o;return t?t.anchor.quote||t.anchor.point||e.state.d?null:t.resolved.element:!d||d.anchor.quote||d.anchor.point?null:e.resolved.get(d.id)?.element??null}();r.classList.toggle("show",null!==a),a&&We(r,a.getBoundingClientRect(),4)},destroy(){window.clearTimeout(g),window.clearTimeout(h),window.removeEventListener("pointermove",P,!0),window.removeEventListener("click",N,!0),e.H(null);for(let e of n.values())e.remove();l.remove(),o.remove(),r.remove(),i.remove()}}}var It={display:"block",position:"static",clips:!1,off:!1},Ft=["button,a,input,select,textarea,label,summary,details,img,svg,canvas,video,picture,figure,figcaption,table,th,td","li,ul,ol,dl,dt,dd,p,h1,h2,h3,h4,h5,h6,blockquote,pre","section,article,aside,nav,header,footer,main,form,fieldset",..."button link img figure region list listitem tab tabpanel article navigation complementary banner contentinfo form search group dialog menu menuitem checkbox switch radio slider textbox combobox option row cell heading table".split(" ").map(e=>`[role=${e}]`)].join(","),Bt="a,button,label,summary,[role=button],[role=link],[role=tab],[role=option],[role=menuitem]",Ht=`${Bt},input,select,textarea,img,svg,canvas,video,picture,[role=img]`,jt=(e,t)=>Math.abs(e.left-t.left)<=2&&Math.abs(e.top-t.top)<=2&&Math.abs(e.width-t.width)<=2&&Math.abs(e.height-t.height)<=2;function Wt(e,t){let n=t.l(e);if(n.width<2||n.height<2)return!1;if(e.hasAttribute("data-pipeup-id"))return!0;let o=t.oe();return n.width*n.height<=.6*o.width*o.height&&(e.matches(Ft)||t.Ve(e)||e.childElementCount>1&&!e.parentElement?.closest(Bt)&&t._e(e))}function Kt(e,t,n){if(e===t||!t.contains(e)||e.closest("[data-pipeup-ignore]"))return null;let o=null;for(let r=e;r&&r!==t&&!o;r=r.parentElement)Wt(r,n)&&(o=r);if(!o||o.hasAttribute("data-pipeup-id"))return o;let r=n.l(o);for(let e=o.parentElement;e&&e!==t&&jt(n.l(e),r);e=e.parentElement)if(e.hasAttribute("data-pipeup-id"))return e;return o}function Yt(e,t,n){let o=n.l(e);for(let r=e.parentElement;r&&r!==t;){let e=Kt(r,t,n);if(!e)return null;if(!jt(n.l(e),o))return e;r=e.parentElement}return null}var Ut=(e,t)=>e.left<t.left+t.width&&t.left<e.left+e.width&&e.top<t.top+t.height&&t.top<e.top+e.height,Vt=(e,t)=>{let n=Math.max(e.left,t.left),o=Math.max(e.top,t.top);return{left:n,top:o,width:Math.max(0,Math.min(e.left+e.width,t.left+t.width)-n),height:Math.max(0,Math.min(e.top+e.height,t.top+t.height)-o)}};function _t(e,t,n=()=>!0){let o=[],r=(e,i,a,l,s,d)=>{for(let c of e.children){if(c.hasAttribute("data-pipeup-ignore")||"true"===c.getAttribute("aria-hidden")||!n(c))continue;let e=t.flow?.(c)??It,p=c.offsetParent,u="fixed"===e.position||"absolute"===e.position&&!!l&&!(p&&l.contains(p)),h=u?null:a,f=t.l(c),m=f.width>0&&f.height>0;if(h&&m&&!Ut(f,h))continue;let v=c.matches(Bt),g=(e.display.startsWith("inline")||d)&&!c.matches(Ht)&&("inline"===e.display||f.height<=48),w=f.width<=24&&f.height<=24,y=i;(c.hasAttribute("data-pipeup-id")||!s&&!e.off&&!g&&(!w||v))&&Wt(c,t)&&(i&&jt(t.l(i.e),f)?(c.hasAttribute("data-pipeup-id")||!i.e.hasAttribute("data-pipeup-id"))&&(i.e=c):o.push(y={e:c,O:i,k:0}));let b=e.clips&&m;r(c,y,b?h?Vt(h,f):f:h,b?c:u?null:l,s||v,/^inline-(flex|grid)$/.test(e.display)||d&&/(flex|grid)$/.test(e.display))}};r(e,null,null,null,!1,!1);for(let e=o.length-1;e>=0;e--){let t=o[e];t.O&&(t.O.k=Math.max(t.O.k,t.k+1))}return o}var Gt=(e,t)=>e.filter(e=>e.k<=t&&(!e.O||e.O.k>t)),Jt="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]",Xt=`${Jt},input,select,textarea,[contenteditable]:not([contenteditable=false]),[tabindex]:not([tabindex="-1"])`,Zt=["click","dblclick","auxclick","submit","contextmenu","dragstart"],Qt=[...["over","out","enter","leave","down","up"].flatMap(e=>[`pointer${e}`,`mouse${e}`]),"mousemove","touchstart","touchmove","touchend","touchcancel"],en="Tab moves between blocks · ↑ ↓ change level · Enter comments · Esc to finish · F7 selects text";function tn(e){let t={l:e=>e.getBoundingClientRect(),Ve:e=>{let t=getComputedStyle(e),n="transparent"!==t.backgroundColor&&!/,\s*0\)$/.test(t.backgroundColor),o=["top","right","bottom","left"].some(e=>parseFloat(t.getPropertyValue(`border-${e}-width`))>0);return n||o||"none"!==t.backgroundImage||"none"!==t.boxShadow},_e:e=>/^(inline-)?(flex|grid)$/.test(getComputedStyle(e).display),flow:e=>{let t=getComputedStyle(e),n=[t.overflowX,t.overflowY];return{display:t.display,position:t.position,clips:n.some(e=>"hidden"===e||"clip"===e)&&!n.some(e=>"auto"===e||"scroll"===e)&&e!==document.documentElement&&e!==document.body,off:"none"===t.pointerEvents}},oe:()=>({width:innerWidth,height:innerHeight})},n=Ie("span",{hidden:!0},en),o=Ie("div",{class:"pick"},n),r=[0,1].map(()=>{let e=Ie("div",{class:"km",tabindex:"-1",role:"button"},Ie("span",{hidden:!0}),Ie("span",{hidden:!0}));return e.inert=!0,e.addEventListener("keydown",ue),e.addEventListener("click",e=>{e.stopPropagation(),pe()}),e.addEventListener("focus",()=>o.classList.add("kf")),e.addEventListener("blur",()=>o.classList.remove("kf")),e}),i=Ie("span",{class:"lbl"}),a=(e,t,n,o)=>{let r=Ie("button",{class:"nb",type:"button","aria-label":e,title:t},Xe(n,16));return r.addEventListener("click",e=>{e.stopPropagation(),o()}),r},l=a("Around it","Select the block around it","expand",se),s=a("Inside it","Select a block inside it","shrink",ce),d=a("Pin","Pin its centre","pin",()=>e.we(()=>j(f??x,{x:.5,y:.5}))),c=Ie("div",{class:"namebar",role:"group","aria-label":"Chosen block"},i,l,s,d);c.inert=!0;let p=e.t.querySelector(".launch");for(let t of[o,...r,c])e.t.insertBefore(t,p);c.addEventListener("mousedown",e=>e.preventDefault());let u=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,h=null,f=null,m=null,v=null,g=0,w=()=>{},y=null,b=()=>{},x=null,k=0,E=0,$=!1,S=null,L=null,A=null,M=0,C=-1,T=!0,P=null,N=null,q=t=>!(e.w(t)||t.target instanceof Element&&t.target.closest("[data-pipeup-ignore]"));function z(){v&&(o.classList.toggle("glide",performance.now()<g),We(o,v.getBoundingClientRect(),4))}function R(){if(!y)return;c.classList.toggle("glide",performance.now()<g&&c.classList.contains("show"));let{left:e,top:t}=Nt(y.getBoundingClientRect(),{width:c.offsetWidth||200,height:c.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});c.style.left=`${e}px`,c.style.top=`${t}px`}function O(e,t){v=e,g=t?performance.now()+400:0,z(),o.classList.add("show")}function D(e,t){let n=getComputedStyle(e);if("0"===n.opacity)return t(),()=>{};let o=0,r=()=>{window.clearTimeout(o),e.removeEventListener("transitionend",a)},i=()=>{r(),t()},a=t=>{t.target===e&&"opacity"===t.propertyName&&i()},l=Math.max(...n.transitionDuration.split(",").map(e=>1e3*parseFloat(e)||0));return o=window.setTimeout(i,l+100),e.addEventListener("transitionend",a),r}function I(e){if(e!==h){if(h=e,w(),!e)return void o.classList.remove("show");"0"===getComputedStyle(o).opacity?O(e,!1):u?(o.classList.remove("show"),w=D(o,()=>O(e,!1))):O(e,!0)}}function F(e){f=e,o.classList.toggle("on",null!==e),I(e),B(e)}function B(e){b(),c.inert=!e,e?u?(c.classList.remove("show"),b=D(c,()=>H(e))):H(e):(c.classList.remove("show"),y=null)}function H(n){i.textContent=i.title=be(n),l.hidden=null===Yt(n,e.root,t),s.hidden=0===(x?ae(n).length:_t(n,t,Z).length);let o=c.classList.contains("show");y=n,R(),o||(c.offsetWidth,c.classList.add("show"))}function j(t,n){let o;try{o=de(t,e.root,n,e.p.view(t))}catch(t){return void e.F(t)}let r={anchor:o,label:n?`Pin on ${be(t).replace(/^[A-Z](?=[a-z])/,e=>e.toLowerCase())}`:be(t),ranges:[],resolved:{state:"attached",element:t,range:null}},i=e.state.o;x&&(x=t,C=-1),F(n?null:t),m=i??r,e.qe(r),e.E(n?r.label:`Commenting on ${r.label}`)}function W(t){e.we(()=>j(t))}let K=n=>{if(e.w(n))return;if(!q(n))return void(f||I(null));if(n.stopPropagation(),f||e.state.o)return;let o=!He()&&n.target instanceof Element?Kt(n.target,e.root,t):null;if(x){if(!o||o===x||(M+=Math.abs(n.movementX)+Math.abs(n.movementY),M<=4))return;ie()}o&&(S=o),I(o)},Y=()=>{He()&&(x&&ie(),f||I(null))},U=e=>{q(e)&&(e.stopPropagation(),("pointerdown"===e.type||"mousedown"===e.type)&&e.target instanceof Element&&e.target.closest(Xt)&&e.preventDefault())},V=n=>{if(!q(n))return;let o=n.target;!(o===N||o.form&&o.form===N?.form)||"submit"!==n.type&&("click"!==n.type||n.detail)?(n.preventDefault(),n.stopPropagation(),"click"===n.type&&!e.state.s&&!e.Ue(n)&&function(n){let o=window.getSelection();if(o&&!o.isCollapsed)return;if(e.state.o&&(n.altKey||!e.L()))return void e.V();if(!n.altKey&&e.ne(n.clientX,n.clientY))return;if(e.state.i&&e.open(null),x&&n.detail&&ie(),n.altKey)return void function(n){let o=(n.target instanceof Element?Kt(n.target,e.root,t):null)??e.root;o!==e.root&&(S=o);let r=o.getBoundingClientRect();r.width&&r.height&&j(o,{x:(n.clientX-r.left)/r.width,y:(n.clientY-r.top)/r.height})}(n);let r=n.target instanceof Element?Kt(n.target,e.root,t):null;r&&(S=r),r?j(r):(e.V(),F(null))}(n)):N="click"===n.type&&"submit"===o.type?o.form:null},_=t=>{if(N=null,fe="","Tab"===t.key&&G(t))return t.preventDefault(),t.stopPropagation(),fe=t.key,e.V(),e.state.i&&e.open(null),e.state.s&&(e.state.s=!1,e.u()),function(t){if(x)return le(t);P=null;let n=document.activeElement;L=J()??n;let o,r=S?.isConnected?S:null,i=r&&ee(r);if(i){k=i.k;let e=Gt(Q(),k),n=e.indexOf(i);o=e[(n+t+e.length)%e.length]}else if(r){k=0;let e=Gt(Q(),0),n=e=>0!==(r.compareDocumentPosition(e.e)&Node.DOCUMENT_POSITION_FOLLOWING),i=e=>e.e.contains(r);o=t>0?e.find(e=>n(e)&&!i(e))??e[0]:e.filter(e=>!n(e)&&!i(e)).pop()??e[e.length-1]}else o=ne(),o&&(k=o.k);if(!o)return e.E("Nothing here to comment on");$=!0,re(o.e)}(t.shiftKey?-1:1);if(q(t)&&t.target instanceof Element)if("Enter"!==t.key&&" "!==t.key||!t.target.closest(Jt))"Enter"===t.key&&!x&&t.target.form&&(N=t.target);else{if(!x)return void(N=t.target);t.preventDefault(),t.stopPropagation()}},G=t=>{if(t.ctrlKey||t.metaKey||t.altKey||t.isComposing)return!1;let n=t.composedPath()[0];return n instanceof Element&&!r.some(e=>e===n)&&(e.w(t)?!!n.closest(".launch,.menu")&&!n.closest("input,textarea,select,[contenteditable]"):!t.composedPath().some(e=>e instanceof Element&&e.hasAttribute("data-pipeup-ignore")))},J=()=>e.t.getRootNode().activeElement,X=()=>r.some(e=>e===J()),Z=t=>(!1!==t.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0})||"contents"===getComputedStyle(t).display)&&e.p.f(e.p.view(t)),Q=()=>(P?.some(e=>!e.e.isConnected)&&(P=null),P??=_t(e.root,t,Z)),ee=e=>Q().find(t=>t.e===e),te=(e,t=!1)=>{let n=e.getBoundingClientRect();return n.bottom>0&&n.top<window.innerHeight&&(!t||n.top>=0)},ne=()=>{let e=Gt(Q(),0);return e.find(e=>te(e.e,!0))??e.find(e=>te(e.e))??e[0]},oe=t=>e.doc.threads().filter(n=>e.B(n)&&t.contains(qt(e,n))).sort(zt(e));function re(t,o=!0){M=0;let i=Q(),a=i.find(e=>e.e===t);if(a&&!Gt(i,k).includes(a)&&(k=a.k),t!==x&&(C=-1),t!==f&&(f=null),x=t,I(t),B(t),t.scrollIntoView({block:"nearest",inline:"nearest",behavior:u?"auto":"smooth"}),!o)return;e.Ke();let l=r[E^=1];(function(e,t){let[o,r]=e.children,i=Gt(Q(),k),a=oe(t).length;o.textContent=`${we(t)}, ${i.findIndex(e=>e.e===t)+1} of ${i.length}${a?`, has ${a} comment${1===a?"":"s"}`:""}`;let l=(t.innerText??t.textContent??"").length<=150;r.textContent=ye(t);let s=T?[n]:[];T=!1,void 0!==e.ariaLabelledByElements?(e.ariaLabelledByElements=l?[o,t]:[o,r],e.ariaDescribedByElements=l?s:[...s,t]):e.setAttribute("aria-label",`${o.textContent}, ${r.textContent}`)})(l,t),We(l,t.getBoundingClientRect(),4),l.inert=!1,l.focus({preventScroll:!0}),r[1^E].inert=!0}function ie(){let e=X();S=x,x=null,I(null),B(null);for(let e of r)Fe(e,!0);return e}function ae(e){let t=ee(e);return t?((e,t)=>e.filter(e=>e.O===t))(Q(),t):[]}function le(e){let t=Gt(Q(),k),n=t.findIndex(e=>e.e===x),o=t[n<0?e>0?0:t.length-1:(n+e+t.length)%t.length];o&&re(o.e)}function se(){let n=f??x,o=n&&Yt(n,e.root,t);return o?((!A||!n.contains(A))&&(A=n),f?W(o):void re(o)):e.E("Nothing around it")}function ce(){let t=f??x,n=t?ae(t):[],o=n.find(e=>A&&e.e.contains(A))??n.find(e=>te(e.e))??n[0];if(!o)return e.E("Nothing inside it");f?W(o.e):re(o.e)}function pe(t=!1){if(!x)return;if(e.state.o&&!e.L())return e.ze();if(!t)return j(x);let n=oe(x);if(!n.length)return e.E("No comments on this block");C=(C+1)%n.length,e.open(n[C].id),n.length>1&&e.E(`Comment ${C+1} of ${n.length} on this block`)}function ue(t){if(["Tab","ArrowUp","ArrowDown","Enter"," ","Escape"].includes(t.key)&&(!t.key.startsWith("Arrow")||!(t.metaKey||t.ctrlKey||t.altKey))){if(t.preventDefault(),t.stopPropagation(),fe=t.key,"Escape"===t.key)return void e.re();if("Enter"===t.key||" "===t.key)return pe(t.shiftKey&&"Enter"===t.key);"Tab"===t.key&&e.V(),e.state.i&&e.open(null),"Tab"===t.key?le(t.shiftKey?-1:1):"ArrowUp"===t.key?se():ce()}}let he=()=>{let e=J();return e?!!e.closest("[inert]"):!document.activeElement||document.activeElement===document.body},fe="",me=!1,ve=e=>{me&&window.removeEventListener("keyup",ve,!0),e.key===fe&&(fe="",e.preventDefault(),e.stopPropagation())};window.addEventListener("keyup",ve,!0),window.addEventListener("pointermove",K,!0),document.addEventListener("selectionchange",Y);for(let e of Qt)window.addEventListener(e,U,!0);for(let e of Zt)window.addEventListener(e,V,!0);return window.addEventListener("keydown",_,!0),{re:()=>!!f&&(F(null),!0),ie:()=>null!==x,We:()=>$&&!x,be:function(){P=null;let t=document.activeElement;L=J()??t;let n=ee(S),o=n??(t&&t!==document.body&&e.root.contains(t)&&!t.closest("[data-pipeup-ignore]")?Q().filter(e=>e.e.contains(t)).pop():void 0)??ne();return!!o&&(n||(k=o.k),$=!0,re(o.e),!0)},se(){x&&!X()&&re(x)},u(){if(P=null,x&&(!x.isConnected||!Z(x))){let e=ne();e?re(e.e,X()||he()):ie()}let t=e.t.querySelector(".launch");if(t&&c.nextElementSibling!==t&&!X()&&!c.contains(J()))for(let n of[o,...r,c])e.t.insertBefore(n,t);let n=e.state.o;m&&n!==m?(m=null,F(null),x&&re(x,he())):(n||e.state.i)&&!m&&(h||f)&&F(null)},T(){z(),R(),x&&We(r[E],x.getBoundingClientRect(),4)},destroy(){ie()&&function(){let t=L;t&&t!==document.body&&t.isConnected&&t.focus?.({preventScroll:!0}),(!t||t===document.body||!t.matches?.(":focus"))&&e.t.querySelector(".launch .mode")?.focus({preventScroll:!0})}();for(let e of r)e.remove();w(),b(),me=!0,fe||window.removeEventListener("keyup",ve,!0),window.removeEventListener("pointermove",K,!0),document.removeEventListener("selectionchange",Y);for(let e of Qt)window.removeEventListener(e,U,!0);for(let e of Zt)window.removeEventListener(e,V,!0);window.removeEventListener("keydown",_,!0),o.classList.remove("show"),c.classList.remove("show"),Fe(c,!0),D(o,()=>o.remove()),D(c,()=>c.remove())}}}function nn(e,t=!1){let n=e.ownerDocument.documentElement,o=n.getAttribute("data-pipeup-layout");if("bubbles"===o||e.querySelector("[data-pipeup-slide]"))return null;let r=e.querySelector("article, main, [role=main]")??("column"===o?e:null);if(!r)return null;if(n.hasAttribute("data-pipeup-reserve")){let e,i=n.clientWidth,a=getComputedStyle(r).maxWidth;return e=a.endsWith("px")?parseFloat(a):a.endsWith("%")?parseFloat(a)/100*i:r.getBoundingClientRect().width,"column"!==o&&i<e+320-(t?24:0)?null:{x:i-320+24,width:272}}let i=r.getBoundingClientRect().right;if(window.innerWidth-i<300&&"column"!==o)return null;let a=i+32;return{x:a,width:Math.max(220,Math.min(300,window.innerWidth-a-16))}}function on(e,t){let n=e.resolved.get(t.id);return!n||"orphaned"===n.state&&!e.S.has(t.id)}function rn(e){let t=Ie("div",{class:"col"});e.t.append(t);let n=new Map,o=null,r=new ResizeObserver(()=>l()),i=t=>on(e,t);function a(t){let n=e.resolved.get(t.id),o=n?At(t.anchor,n):null;return null===o?Number.POSITIVE_INFINITY:o+window.scrollY-4}function l(){let t=[],r=[];for(let[o,i]of n){let n=a(i.thread);if(Number.isFinite(n))i.placed=n;else if(e.S.has(o)){if(null===i.placed){i.e.classList.add("wait");continue}n=i.placed}Number.isFinite(n)?t.push({id:o,M:n,height:i.e.offsetHeight}):r.push({id:o,height:i.e.offsetHeight})}let i=e.state.o,l=i?At(i.anchor,i.resolved):null;o&&null!==l&&t.push({id:"draft",M:l+window.scrollY-4,height:o.e.offsetHeight});let s=function(e,t,n=10){let o=[...e].sort((e,t)=>e.M-t.M),r=new Array(o.length).fill(0),i=o.findIndex(e=>e.id===t),a=e=>o[e];if(i<0)o.forEach((e,t)=>{r[t]=0===t?e.M:Math.max(e.M,(r[t-1]??0)+a(t-1).height+n)});else{r[i]=a(i).M;for(let e=i+1;e<o.length;e++)r[e]=Math.max(a(e).M,(r[e-1]??0)+a(e-1).height+n);for(let e=i-1;e>=0;e--)r[e]=Math.min(a(e).M,(r[e+1]??0)-a(e).height-n)}return new Map(o.map((e,t)=>[e.id,r[t]??0]))}(t,o?"draft":e.state.i),d=Math.max(0,...t.map(e=>(s.get(e.id)??0)+e.height))+24;for(let e of r)s.set(e.id,d),d+=e.height+10;for(let[e,t]of n)if(t.e.classList.contains("wait")){if(!s.has(e))continue;t.e.style.transition="none",t.e.style.transform=`translateY(${Math.round(s.get(e))}px)`,t.e.offsetWidth,t.e.style.transition="",t.e.classList.remove("wait")}else t.e.style.transform=`translateY(${Math.round(s.get(e)??0)}px)`;o&&(o.e.style.transform=`translateY(${Math.round(s.get("draft")??0)}px)`)}function s(e,t){e.thread=t,e.note=De(t.id),e.lost=i(t),e.view.update(t,{lost:e.lost?t.anchor.snapshot:null})}function d(n){let o=i(n),a=Ot(n,e.te,{D:"column",lost:o?n.anchor.snapshot:null}),l=Ie("div",{class:"th","data-thread":n.id},Ie("button",{class:"opn sr",type:"button","data-thread":n.id}),a.element);return l.style.transition="none",l.addEventListener("mouseenter",()=>e.m(n.id)),l.addEventListener("mouseleave",()=>e.m(null)),l.addEventListener("click",()=>e.open(n.id)),t.append(l),r.observe(l),{e:l,thread:n,lost:o,placed:null,view:a}}function c(e){r.unobserve(e),e.classList.add("out"),window.setTimeout(()=>e.remove(),220)}return{u:function(a){Fe(t,e.state.c);let p=new Set,u=[],h=null!==e.state.i||null!==e.state.o;for(let t of a){if(!e.B(t))continue;p.add(t.id);let o=n.get(t.id);o?(o.thread!==t||o.lost!==i(t)||o.note!==De(t.id))&&s(o,t):(o=d(t),n.set(t.id,o),u.push(o.e));let r=o.e,a=e.state.i===t.id;r.classList.toggle("on",a);let l=r.firstElementChild,c=t.root.replies.length;l.setAttribute("aria-label",`Open thread: ${je(t.root.text,60)}, ${Rt(c)}`),l.setAttribute("aria-expanded",String(a)),Fe(l,a);let f=r.querySelector(".more");f&&Fe(f,!a),r.classList.toggle("dim",h&&!a),r.classList.toggle("hot",e.state.m===t.id&&!a),r.classList.toggle("resolved",t.resolved),r.classList.toggle("lost",o.lost)}for(let[e,t]of n)p.has(e)||(n.delete(e),c(t.e));(function(){let n=e.state.o;if(o&&o.of!==n&&(c(o.e),o=null,n||e.H(null)),!n)return;let i=!o;if(o)o.l.ve(n.label);else{let i=$t(e,n),a=Ie("div",{class:"th on"},i.element);a.style.transition="none",t.append(a),r.observe(a),o={e:a,l:i,of:n}}o.l.Z(e.state.d&&!n.anchor.quote&&!n.anchor.point),i&&o.l.focus()})(),Be(t,a.filter(e=>p.has(e.id)).sort(zt(e)).map(e=>n.get(e.id).e),o?.e??null)&&t.offsetWidth,l(),o&&u.push(o.e);for(let e of u)e.offsetWidth,e.style.transition=""},T:function(){let n=nn(e.root,!0);n&&(t.style.width=`${n.width}px`,t.style.transform=`translate(${n.x}px, ${-window.scrollY}px)`)},destroy(){r.disconnect(),e.H(null),t.remove()}}}var an="[data-pipeup-ignore],input,textarea,select,[contenteditable]:not([contenteditable=false])";function ln(e){let t=Ie("button",{type:"button","aria-label":"Comment",title:"Comment"},Xe("comment",17)),n=Ie("div",{class:"selbar"},t);n.inert=!0,e.t.append(n);let o=null,r=0,i=!1,a=t=>{let n=t&&(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement);return!!n&&e.root.contains(n)&&!n.closest(an)};function l(){if(!o)return;let{left:e,top:t}=Nt(o.getBoundingClientRect(),{width:n.offsetWidth||36,height:n.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});n.style.left=`${e}px`,n.style.top=`${t}px`}function s(){o=null,n.inert=!0,n.classList.remove("show")}function d(t=!1){let r=He();e.state.d&&r&&a(r.anchorNode)&&a(r.focusNode)?(!o&&!t&&e.E("Enter comments on the selected words"),o=r.getRangeAt(0).cloneRange(),l(),n.inert=!1,n.classList.add("show")):s()}t.addEventListener("mousedown",e=>e.preventDefault()),t.addEventListener("click",t=>{if(t.stopPropagation(),e.state.o&&!e.L())return e.V();let n,r=o;if(!r)return;try{n=se(r,e.root,e.p.view(r.commonAncestorContainer))}catch(t){return e.F(t),void s()}let i=je(r.toString().replace(/\s+/g," ").trim(),60);window.getSelection()?.removeAllRanges(),s(),e.je({anchor:n,label:`“${i}”`,ranges:[r],resolved:{state:"attached",element:null,range:r}})});let c=()=>{window.clearTimeout(r),r=window.setTimeout(()=>i||d(),250),o&&(He()||s())};document.addEventListener("selectionchange",c);let p=t=>{"keyup"!==t.type&&(i="mousedown"===t.type),!i&&!e.w(t)&&window.setTimeout(()=>d("mouseup"===t.type),0)};window.addEventListener("mousedown",p,!0),window.addEventListener("mouseup",p,!0),window.addEventListener("keyup",p,!0);let u=n=>{"Enter"!==n.key||!o||e.w(n)||n.target instanceof Element&&n.target.closest(`${an},${Jt}`)||(n.preventDefault(),n.stopPropagation(),t.click())};return window.addEventListener("keydown",u,!0),{u(){!e.state.d&&o&&s()},T(){o&&l()},destroy(){window.removeEventListener("mousedown",p,!0),window.removeEventListener("mouseup",p,!0),window.removeEventListener("keyup",p,!0),window.removeEventListener("keydown",u,!0),window.clearTimeout(r),document.removeEventListener("selectionchange",c),n.remove()}}}async function sn(e,t){try{return void await navigator.clipboard.writeText(e)}catch{}let n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.cssText="position:fixed;opacity:0;pointer-events:none",t.append(n),n.select();let o=document.execCommand("copy");if(n.remove(),!o)throw new Error("pipeup: your browser blocked copying")}var dn="Hidden on the page";function cn(e){let t=[Ie("span",{class:"n"}),Ie("span",{class:"n"})],n=Xe("comment",20,1.4);n.lastElementChild.setAttribute("stroke-width","1.6");let o=Ie("button",{class:"mode",type:"button","aria-label":"Comment","aria-keyshortcuts":Et,"aria-haspopup":"menu","aria-expanded":"false"},Ie("span",{class:"plus"},n),Ie("span",{class:"cnt"},Xe("bubble",34,1.4),...t),Ie("span",{class:"dot"})),r=document.createTextNode("Comment"),i=Ie("span",{class:"ttip","aria-hidden":"true"},r,Ie("small",{},kt)),a=Ie("div",{class:"launch"},o,i),l=Ie("div",{class:"menu",role:"menu","aria-label":"Comments"}),s=Ie("div",{class:"list",role:"menu","aria-label":"All comments"}),d=Ie("span",{class:"pn"}),c=Ie("button",{class:"ib",type:"button","aria-label":"Close"},Xe("close")),p=Ie("button",{class:"hs",type:"button",role:"switch","aria-checked":"false"},"Show resolved",Ie("span",{class:"sw","aria-hidden":"true"}));p.addEventListener("click",t=>{t.stopPropagation(),e.s.Ye()});let u=Ie("span",{}),h=Ie("button",{type:"button"},"Check for replies"),f=Ie("div",{class:"ag"},u,h);f.hidden=!e.replies.enabled,h.addEventListener("click",t=>{t.stopPropagation(),h.disabled=!0,e.replies.check().then(t=>e.Y(t?`${t} new ${1===t?"reply":"replies"}`:"No new replies"),t=>e.F(t)).finally(()=>{h.disabled=!1,e.u()})});let m=Ie("div",{class:"all",role:"dialog","aria-label":"All comments"},Ie("div",{class:"hd"},Ie("span",{},"All comments"),d,p,c),f,s),v=document.createElementNS("http://www.w3.org/2000/svg","svg");v.setAttribute("class","cx"),v.setAttribute("aria-hidden","true");let g=document.createElementNS("http://www.w3.org/2000/svg","path"),w=document.createElementNS("http://www.w3.org/2000/svg","circle");w.setAttribute("r","4"),v.append(g,w),l.inert=m.inert=!0,e.t.append(l,a,v,m);let y=!1,b=null,x=0,k=[],E=0,$=null,S=null,L=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,A=t=>{y=e.state.s=t,t&&e.addons.flush(),window.clearTimeout(x),x=0,t||b?.(!0),l.classList.toggle("show",t),Fe(l,!t),o.setAttribute("aria-expanded",String(t))},M=(t,n=!1)=>{e.state.c!==t&&(e.state.c=t,e.u(),t?(C(s)[0]??c).focus({preventScroll:!0}):n&&o.focus({preventScroll:!0}))},C=(e=l)=>[...e.querySelectorAll(".mi")],T=()=>l.getRootNode().activeElement,P=()=>{A(!1),o.focus({preventScroll:!0})},N=e=>{let t=C(e.currentTarget);if(0===t.length)return;let n=T(),o=t.indexOf(n),r=n=>{e.preventDefault(),t[(n+t.length)%t.length]?.focus({preventScroll:!0})};"ArrowDown"===e.key?r(o+1):"ArrowUp"===e.key?r(o<0?t.length-1:o-1):"Home"===e.key?r(0):"End"===e.key&&r(t.length-1)};l.addEventListener("keydown",N),s.addEventListener("keydown",N),c.addEventListener("click",e=>{e.stopPropagation(),M(!1,!0)});let z=t=>on(e,t),R=t=>k.filter(n=>!n.resolved&&(void 0===t||e._(n)===t)).length,O=()=>R(),D=t=>{let n=t.anchor.view?.slide,o=e.p.f(t.anchor.view)?"":ke(t.anchor.view);return n&&null!==e.p.slide()?`On slide ${n}`:o?`In ${o}`:dn},I=(e,t,n="")=>Ie("div",{role:"group","aria-label":n?`${e} · ${n}`:e},Ie("div",{class:"sec","aria-hidden":"true"},e,n&&Ie("b",{},n)),...t);function F(){let t=T(),n=t?.dataset.thread,o=null!==S&&S.element.contains(t),r=e.s.all().filter(t=>!t.thread.resolved||e.state.C||t.thread.id===$),i=t=>{let n=t.thread,o=n.id===$,r=ot(n.root.author,n.root.name);r.classList.add("in");let i=Ie("button",{class:`mi${n.resolved?" done":""}${o?" open":""}`,type:"button",role:"menuitem","aria-expanded":String(o),"data-thread":n.id},r,Ie("span",{},Ie("span",{class:"clamp"},n.root.deleted?"Deleted":n.root.text),Ie("small",{},z(n)?`“${je(n.anchor.snapshot,80)}”`:t.location.where)));i.addEventListener("click",t=>{t.stopPropagation(),function(t){if($===t)return j(!0);let n=k.find(e=>e.id===t);if(n){if($=H=t,S=Ot(n,{...e.te,close:()=>j(!0)},B(n)),F(),S.element.querySelector("textarea")?.focus({preventScroll:!0}),!e._(n))return W(n);e.state.o&&!e.L()||e.p.R(n.anchor.view??{}).then(()=>{e.xe();let n=k.find(e=>e.id===t);n&&H===t&&$===t&&W(n)})}}(n.id)});let a=document.createDocumentFragment();return a.append(i),o&&S&&(S.update(n,B(n)),a.append(Ie("div",{class:"xr",role:"region","aria-label":"Comment thread"},S.element))),a},a=r.filter(e=>z(e.thread));d.textContent=String(O()),p.setAttribute("aria-checked",String(e.state.C)),s.replaceChildren(r.length?"":Ie("div",{class:"sec",role:"presentation"},"No open comments"),...function(t,n){let o=e.p.slide(),r=new Map;for(let n of t){let t=n.thread,i=null!==o?t.anchor.view?.slide??o:e._(t)?e.p.f(t.anchor.view)?"":ke(t.anchor.view):null;r.set(i,[...r.get(i)??[],n])}if(null===o){let e=r.get(null)??[];return r.delete(null),[...e.map(n),...[...r].map(([e,t])=>I(e||dn,t.map(n)))]}return[...r].sort(([e],[t])=>Number(e)-Number(t)||0).map(([e,t])=>I(`Slide ${e} · ${t.filter(e=>!e.thread.resolved).length} open`,t.map(n),e===o?"This slide":""))}(r.filter(e=>!z(e.thread)),i),a.length?I("No longer on the page",a.map(i)):""),o?S.element.querySelector("textarea")?.focus({preventScroll:!0}):n&&C(s).find(e=>e.dataset.thread===n)?.focus({preventScroll:!0})}function B(t){let n=!z(t)&&e._(t);return{D:"popover",quote:t.anchor.quote?.exact??null,lost:z(t)||n?t.anchor.snapshot:null,place:n?D(t):null}}let H="";function j(t=!1){if(!$)return;let n=$;$=S=null,e.m(null),F(),t&&C(s).find(e=>e.dataset.thread===n)?.focus({preventScroll:!0})}function W(t){let n=e.resolved.get(t.id),o=n&&!z(t)?n.element??n.range?.startContainer.parentElement??null:null;o?.scrollIntoView({block:"center",inline:"nearest",behavior:L?"auto":"smooth"}),o&&e.m(t.id)}function K(e,t,n=!1,...o){let r=Ie("button",{class:"mi",type:"button",role:n?"menuitemcheckbox":"menuitem"},e,Ie("span",{class:"lb"}),...o,n&&Ie("span",{class:"sw","aria-hidden":"true"}),Ie("span",{class:"tt","aria-hidden":"true"}));return r.addEventListener("click",e=>{e.stopPropagation(),t(e)}),r}let Y=(e,t,n,o)=>{let r=e.querySelector(".lb");r.textContent!==t&&(r.textContent=t),e.querySelector(".tt").textContent=n,e.setAttribute("aria-description",n),void 0!==o&&e.setAttribute("aria-checked",String(o))},U=()=>Ie("div",{class:"sep",role:"separator"}),V=Ie("span",{class:"ma"}),_=Ie("span",{class:"kc"}),G="",J=K(V,function(){let t=Ie("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"});t.value=e.s.name();let n=Ie("div",{class:"ed"},V.cloneNode(!0),t),o=(r,i=!1)=>{if(b!==o)return;b=null;let a=t.value.trim();r&&a&&a!==e.s.name()&&e.s.rename(a).then(ue),n.replaceWith(J),i&&J.focus({preventScroll:!0})};b=o,t.addEventListener("keydown",e=>{e.stopPropagation(),("Enter"===e.key||"Escape"===e.key)&&(e.preventDefault(),o("Enter"===e.key,!0))}),t.addEventListener("blur",()=>o(!0)),J.replaceWith(n),t.focus({preventScroll:!0})},!1,_);J.dataset.item="name";let X=K(Xe("copy"),()=>{P(),e.s.copyAll("ai")}),Z=K(Xe("lines"),()=>{P(),e.s.copyAll("text")}),Q=K(Xe("copy"),()=>{P(),e.s.copyPrompt()}),ee=K(Xe("send"),()=>{e.link.set(!e.link.on()).then(ue,t=>e.F(t))},!0),te=Ie("div",{class:"sec",role:"presentation"}),ne=Ie("span",{class:"kc"}),oe=K(Xe("list"),()=>{A(!1),M(!0)},!1,ne),re=K(Xe("comment"),t=>{let n=!e.state.d&&0===t.detail;e.Ge(!e.state.d,n),n&&A(!1)},!0,Ie("span",{class:"kc","aria-hidden":"true"},kt));re.dataset.item="comment",re.setAttribute("aria-keyshortcuts",Et);let ie=Ie("div",{class:"sec",role:"presentation"}),ae=U(),le=U(),se=new Map,de=t=>{let n=se.get(t);return n||(n=K(Ze(t.icon,15),()=>{t.checked||P(),Promise.resolve().then(()=>t.select()).catch(t=>e.F(t)).finally(()=>y&&ue())},!!t.checked,Ie("span",{class:"kc"})),se.set(t,n)),n},ce=-1,pe=e=>{try{return e()}catch(e){return globalThis.reportError?.(e),""}};function ue(){let t=O(),n=e.s.name(),o=n||q(e.doc.me);if(Y(J,o,n?"The name on your comments":"Add a name to show on your comments"),J.setAttribute("aria-label",`${o}, ${n?"edit":"add"} your name`),_.replaceChildren(n?Xe("edit",13):"Add name"),nt(e.doc.me,n)!==G){G=nt(e.doc.me,n);let t=ot(e.doc.me,n);t.classList.add("in"),V.replaceChildren(t)}Y(X,"Copy as Markdown","Markdown, with where each thread is"),Y(Z,"Copy as Text","Just the words"),Y(Q,"Copy a prompt for my agent","Tells an AI agent where the comments are and how to answer them");let r=e.replies.who()||e.link.agent;te.textContent=e.link.on()?`Sharing comments with ${r||"your agent"}`:`${r||"An AI agent"} can answer comments here`,Y(ee,"Share with my agent","Sends this page's comments to the program running on this computer, and nothing else",e.link.on()),Y(oe,"All comments","Every thread, and where it is"),ne.textContent=t?String(t):"";let i=e.addons.ce();ie.textContent=i,i?!ie.isConnected&&l.contains(J)&&l.prepend(ie):ie.remove();for(let t of e.addons.$){let e,n=se.get(t);if(n){try{e=t.checked?.()}catch(e){globalThis.reportError?.(e)}Y(n,pe(t.label),pe(t.hint),e),n.querySelector(".kc").textContent=t.count?pe(t.count):""}}Y(re,"Start commenting",e.state.d?"Turn off to hide the comments again":"Shows the comments; choose any part of the page to comment on it",e.state.d)}function he(){ue(),(ce!==e.addons.G||!l.contains(J))&&(l.replaceChildren(J,ae,...e.replies.enabled||e.link.enabled?[te]:[],X,Z,Q,...e.link.enabled?[ee]:[],oe,...e.addons.$.map(de),le,re),ce=e.addons.G,ue())}o.addEventListener("click",e=>{e.stopPropagation(),y?A(!1):(he(),A(!0),0===e.detail&&C().at(-1)?.focus({preventScroll:!0}))});let fe=!1,me=()=>{fe=m.contains(T())},ve=t=>{let n=t.composedPath();y&&!n.includes(l)&&!n.includes(o)&&(A(!1),e.state.d&&!e.w(t)&&(e.ye(t),t.preventDefault(),t.stopPropagation())),e.state.c&&!e.w(t)&&M(!1,fe&&(!document.activeElement||document.activeElement===document.body))},ge=e=>{if(!y||"touch"===e.pointerType||"pointerout"===e.type&&e.relatedTarget)return;let t=e.composedPath();"pointerover"===e.type&&(t.includes(l)||t.includes(o))?(window.clearTimeout(x),x=0):x||(x=window.setTimeout(()=>{x=0,b||A(!1)},3e3))},we={n:0,label:""},ye=()=>{let{n:t,label:n}=we,i=e.addons.ce(),a=`Comment${e.state.d?", comment mode on":""}${n?`, ${n}`:t?`, ${t} open`:""}${i?`, ${i}`:""}`;o.getAttribute("aria-label")!==a&&o.setAttribute("aria-label",a);let l=(n||"Comment")+(i?` · ${i}`:"");r.data!==l&&(r.data=l)},be=e.addons.subscribe(e=>{ye(),y&&!b&&(e?he():ue())});window.addEventListener("pointerdown",me,!0),window.addEventListener("click",ve,!0),window.addEventListener("pointerover",ge,!0),window.addEventListener("pointerout",ge,!0);let xe=t=>{if("Escape"!==t.key||b)return;let n=t.composedPath()[0];if(y)P();else{if(!e.state.c||n instanceof HTMLTextAreaElement&&!m.contains(n))return;$?j(!0):M(!1,!0)}t.stopPropagation()};return window.addEventListener("keydown",xe,!0),{u(n){k=n;let r=R(!1);if(r!==E){if(r){let[e,n]=t[0].classList.contains("on")?t:[t[1],t[0]];n.textContent=r>99?"99+":String(r),n.classList.toggle("s",r>99),e.classList.remove("on"),n.classList.add("on")}o.classList.toggle("has",r>0),E=r}let i=R(!0),a=i?`${r} here · ${i} ${null!==e.p.slide()?"on other slides":"in other views"}`:"";if(o.classList.toggle("else",i>0),we={n:r,label:a},ye(),o.classList.toggle("on",e.state.d),y&&!e.state.s&&A(!1),y&&ue(),e.replies.enabled){let t=e.replies.tally(n),o=e.replies.who()||e.link.agent||"An agent",r=t.answered?`${o} has answered ${t.answered} of ${t.open} open comments${t.addressed?`; ${t.addressed} ${1===t.addressed?"is":"are"} marked addressed`:""}`:"No replies from an agent yet",i=e.replies.ignored(),a=(e.link.on()?`Sharing with ${e.link.agent||"your agent"} · `:"")+r+(i?` · ${i} from other writers ignored`:"")+(t.stray?` · replies for ${t.stray} comment${1===t.stray?"":"s"} this page doesn't have`:"");u.textContent!==a&&(u.textContent=a)}let l=e.state.c;m.classList.toggle("full",Pt()),m.classList.contains("show")!==l&&(m.classList.toggle("show",l),Fe(m,!l)),$&&(!l||!n.some(e=>e.id===$))&&($=S=null,e.state.m=null),l&&F()},T:function(){let t=$?k.find(e=>e.id===$):null,n=$?s.querySelector(".mi.open"):null,o=t&&function(t){let n=e.resolved.get(t.id),o=n?.element??n?.range?.startContainer.parentElement;if(!n||Pt()||z(t)||e._(t)||!1===o?.checkVisibility?.({visibilityProperty:!0}))return null;let r=e.t.querySelector(`.bub[data-thread="${t.id}"]`)?.getBoundingClientRect(),i=n.range?Lt(n).at(-1):void 0,a=o?.closest("p,li,h1,h2,h3,h4,h5,h6,blockquote,td,th,figcaption,div")?.getBoundingClientRect().right,l=n.element?.getBoundingClientRect(),s=Mt(t.anchor,n),d=r?.width?{x:r.right+1,y:r.top+r.height/2,from:"right",bubble:!0}:i?{x:Math.max(i.right,a??0)+4,y:(i.top+i.bottom)/2,from:"right"}:l?{x:l.left+l.width/2,y:l.top,from:"top"}:s&&{x:s.x,y:s.y,from:"right"};return d&&d.x>=0&&d.x<=window.innerWidth-320&&d.y>=0&&d.y<=window.innerHeight?d:null}(t),r=n?.getBoundingClientRect(),i=s.getBoundingClientRect();if(!o||!r||r.top+12<i.top||r.top+12>i.bottom)return void v.classList.remove("show");let a,l=r.left,d=r.top+14;if("right"===o.from&&l-o.x>60){let e=o.x+28,t=o.y>=d?1:-1,n=Math.min(24,Math.abs(o.y-d)/2);a=`M${l} ${d}C${l-24} ${d} ${e} ${d} ${e} ${d+t*n}L${e} ${o.y-t*n}C${e} ${o.y} ${e} ${o.y} ${o.x} ${o.y}`}else{let e=o.y-8,t=l-40,n=e>=d?1:-1,r=Math.min(20,Math.abs(e-d)/2);a=`M${l} ${d}C${l-20} ${d} ${t} ${d} ${t} ${d+n*r}L${t} ${e-n*r}C${t} ${e} ${t} ${e} ${t-r} ${e}L${o.x+8} ${e}C${o.x} ${e} ${o.x} ${e} ${o.x} ${o.y}`}g.setAttribute("d",a),w.setAttribute("r",o.bubble?"0":"4"),w.setAttribute("cx",String(o.x)),w.setAttribute("cy",String(o.y)),v.classList.add("show")},destroy(){be(),window.removeEventListener("pointerdown",me,!0),window.removeEventListener("click",ve,!0),window.removeEventListener("pointerover",ge,!0),window.removeEventListener("pointerout",ge,!0),window.clearTimeout(x),window.removeEventListener("keydown",xe,!0),l.remove(),m.remove(),v.remove(),a.remove()}}}var pn="[data-pipeup-slide]",un=["scroll","resize","keyup","click","transitionend","slidechanged"],hn=null,fn=null,mn=new Set,vn=new Set,gn=e=>{try{e()}catch(e){globalThis.reportError?.(e)}};function wn(e){let t=null;if(e){t={};let n=0;for(let[o,r]of Object.entries(e))if(!("string"!=typeof r||"slide"===o||o.length>64||r.length>200)){if(++n>=16)break;t[o]=r}}hn=t;for(let e of vn)e()}function yn(e){return mn.add(e),()=>{mn.delete(e)}}function bn(e){fn="function"==typeof e?.current&&"function"==typeof e.go?e:null}var xn=()=>{let e=window.Reveal;return"function"==typeof e?.getIndices&&"function"==typeof e.slide?e:null};var kn=["pipeup-quote","pipeup-on","pipeup-done"],En={"pipeup-quote":[[250,227,188,.75],[250,200,100,.28]],"pipeup-on":[[247,212,154,.95],[250,200,100,.42]],"pipeup-done":[[180,178,169,.22],[180,178,169,.2]]};function $n(){return typeof CSS<"u"&&"highlights"in CSS&&typeof Highlight<"u"}var Sn=`:not([data-pipeup-ignore],[data-pipeup-ignore] *){cursor:url("data:image/svg+xml,${encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><rect x='7' y='7' width='23' height='23' rx='4' fill='none' stroke='#534AB7' stroke-width='2' stroke-dasharray='4 3'/><path d='M3 2v15l4-3.5 3 6.5 2.5-1.2-3-6.3H15z' fill='#fff' stroke='#2C2C2A' stroke-width='1.2' stroke-linejoin='round'/></svg>")}") 3 2,crosshair!important}`;function Ln(){if($n())for(let e of kn)CSS.highlights.delete(e)}var An=':host{all:initial}*{box-sizing:border-box}button{appearance:none;font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}svg{display:block}.layer{all:initial;display:block;position:fixed;inset:0;pointer-events:none;font:13px/1.5 var(--pu-font,system-ui,sans-serif);color:var(--k);--k:#2C2C2A;--mu:#5F5E5A;--fa:#888780;--ln:#E5E3DA;--ru:#ECEAE2;--so:#FAFAF7;--su:#FFFFFF;--ho:#F1EFE8;--as:color-mix(in srgb,var(--pu-accent,#534AB7) 12%,transparent);--sh:0 8px 28px rgba(44,44,42,.1);--in:.26s;--mv:.34s;--out:.2s;--pl:1.2s;--eo:cubic-bezier(.22,.61,.36,1);--eio:cubic-bezier(.4,0,.2,1);--ei:cubic-bezier(.4,0,1,1);--pu-text:var(--k);--pu-muted:var(--mu);--pu-faint:var(--fa);--pu-line:var(--ln);--pu-surface:var(--su);--pu-soft:var(--so);--pu-hover:var(--ho);--pu-shadow:var(--sh);--pu-ease:var(--eo)}.layer.dark{--k:#ECEBE6;--mu:#B4B2A9;--fa:#8D8B84;--ln:#3A3936;--ru:#34332F;--so:#22221F;--su:#1B1B19;--ho:#2C2C29;--sh:0 8px 28px rgba(0,0,0,.45)}.layer.hidden .bub,.layer.hidden .col,.layer.hidden .pop,.layer.hidden .tip,.layer.hidden .mark,.layer.hidden .selbar{opacity:0!important;pointer-events:none!important}.tx{font-size:14px;line-height:1.5;color:var(--k);white-space:pre-wrap;overflow-wrap:anywhere}.tx.del,.who,.rest,.ctx{color:var(--fa)}.who,.rest{font-size:12px}.who{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.rft>.who{display:block}.ctx[hidden]{display:none}.ctx{font-size:12px;margin-bottom:3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.clamp{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.tx a{color:var(--pu-accent);text-decoration:underline;text-decoration-thickness:1px;text-underline-offset:2px}.ft,.rft{display:grid;grid-template-rows:0fr;opacity:0;transition:grid-template-rows var(--in) var(--eo),opacity var(--in) var(--eo)}.ft>*,.rft>*{overflow:hidden;min-height:0;display:flex;align-items:center}.root:hover>.ft,.root:focus-within>.ft,.it:hover>.rft,.it:focus-within>.rft{grid-template-rows:1fr;opacity:1}.ft.has-rest,.ft.open,.rft.open{grid-template-rows:1fr;opacity:1}.ft.has-rest>*{grid-area:1/1}.ft .hover{opacity:0;transition:opacity var(--in) var(--eo)}.ft .rest{transition:opacity var(--in) var(--eo)}.root:hover>.ft .hover,.root:focus-within>.ft .hover,.ft:not(.has-rest) .hover{opacity:1}.root:hover>.ft .rest,.root:focus-within>.ft .rest{opacity:0}.acts{margin-left:6px;display:flex;flex:none}.ib{width:24px;height:22px;display:grid;place-items:center;border-radius:6px;color:var(--mu);transition:background-color .2s var(--eo),color .2s var(--eo)}.ib:hover,.ib:focus-visible{background:var(--ho);color:var(--k);outline:none}.rps,.rbox{padding-left:14px}.rps .it{padding-top:6px}.more{display:grid;grid-template-rows:1fr;transition:grid-template-rows var(--mv) var(--eio)}.more>div{overflow:hidden;min-height:0}.th:not(.on) .more{grid-template-rows:0fr}.row{display:flex;align-items:center;gap:8px;padding:8px 0 2px;cursor:text}.input{flex:1;min-width:0;height:27px;display:block;border:0;border-bottom:1px solid var(--ln);outline:none;resize:none;overflow:hidden;font:inherit;font-size:14px;line-height:1.5;padding:3px 0;color:var(--k);background:transparent;transition:border-color var(--in) var(--eo)}.row:hover .input,.input:hover{border-bottom-color:var(--mu)}.input:focus{border-bottom-color:var(--pu-accent)}.ed{display:flex;gap:10px;align-items:center;min-height:34px;padding:6px 10px}.ed .input{font-size:13px;height:22px}.root,.it{position:relative;padding-right:30px}.av{display:grid;place-items:center;width:22px;height:22px;border-radius:32%;font-size:12px;font-weight:600;line-height:1;opacity:0;transform:scale(.85);transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.av.in{opacity:1;transform:none}.av svg{width:80%;height:80%}.root>.av,.it>.av{position:absolute;top:0;right:0}.it>.av{top:6px}.av{--av-l:92%;--av-d:30%;--s:60%;background:hsl(var(--h) var(--s) var(--av-l));color:hsl(var(--h) var(--s) var(--av-d))}.dark .av{--av-l:20%;--av-d:78%}.av.ai{position:relative;border-radius:50%;background:var(--su);color:var(--pu-accent);font-size:9px;letter-spacing:.02em}.av.ai:before,.av.ai:after{content:"";position:absolute;inset:3px;border-radius:50%;border:1.5px solid var(--pu-accent);pointer-events:none}.av.ai:after{animation:pu-pulse-ring 3s var(--eo) infinite}.av.ai.busy:after{animation-duration:1.6s}.root>.av.ai,.it>.av.ai{position:absolute}@keyframes pu-pulse-ring{0%{opacity:.7;transform:scale(1)}80%,to{opacity:0;transform:scale(1.375)}}.refs{display:flex;flex-wrap:wrap;gap:4px;margin-top:6px;white-space:normal}.refs .ref{display:inline-flex;align-items:center;gap:5px;max-width:160px;padding:1px 9px;border:1px solid var(--ln);border-radius:999px;background:var(--so);color:var(--mu);font:inherit;font-size:11.5px;line-height:1.6;text-decoration:none;cursor:pointer;transition:background-color .2s var(--eo),color .2s var(--eo),border-color .2s var(--eo)}.refs .ref:hover,.refs .ref:focus-visible{background:var(--as);color:var(--pu-accent);border-color:var(--pu-accent);outline:none}.ref span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.refs .ref{position:relative}.ref .rc{position:absolute;left:0;top:calc(100% + 6px);z-index:3;width:max-content;max-width:min(240px,70vw);padding:6px 9px;border:1px solid var(--ln);border-radius:8px;background:var(--su);box-shadow:var(--sh);color:var(--k);font-size:12px;line-height:1.45;white-space:normal;text-align:left;overflow:visible;opacity:0;visibility:hidden;transform:translateY(-3px);pointer-events:none;transition:opacity .2s var(--eo),transform .2s var(--eo),visibility 0s .2s}.ref:hover .rc,.ref:focus-visible .rc{opacity:1;visibility:visible;transform:none;transition-delay:0s}.ref .sl{width:10px;height:7px;border:1.3px solid currentColor;border-radius:2px;flex:none}.seen{display:flex;align-items:center;gap:6px;padding:6px 0 0 14px;font-size:12px;color:var(--fa)}.seen button{margin-left:auto;padding:0 6px;border:0;border-radius:6px;background:none;color:var(--fa);font:inherit;cursor:pointer;transition:color .2s var(--eo),background-color .2s var(--eo)}.seen button:hover,.seen button:focus-visible{color:var(--pu-accent);background:var(--as);outline:none}.seen i{width:12px;height:12px;border-radius:50%;border:1.5px solid var(--pu-accent);flex:none}.ghost .dots{display:inline-flex;gap:3px;margin-left:4px;vertical-align:middle}.ghost .dots i{width:4px;height:4px;border-radius:50%;background:var(--fa);animation:pu-dot 1.6s var(--eio) infinite}.ghost .dots i:nth-child(2){animation-delay:.2s}.ghost .dots i:nth-child(3){animation-delay:.4s}@keyframes pu-dot{0%,to{opacity:.25}50%{opacity:1}}.c0{--h:0}.c1{--h:25}.c2{--h:50}.c3{--h:130}.c4{--h:175}.c5{--h:215}.c6{--h:270}.c7{--h:330}.c8{--h:28;--s:35%}.c9{--h:220;--s:8%}.me{flex:none;display:grid}.me>.av{grid-area:1/1;width:26px;height:26px;font-size:13px}.you{display:grid;padding:0 34px;min-height:24px;font-size:12px;color:var(--fa)}.you>*{grid-area:1/1;display:flex;align-items:center;min-width:0;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.say{white-space:pre;overflow:hidden}.nm{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.say button{flex:none}.say button{color:var(--mu);text-decoration:underline;text-decoration-color:var(--ln);text-underline-offset:2px;transition:color .2s var(--eo)}.say button:hover,.say button:focus-visible{color:var(--pu-accent);outline:none}.nf{opacity:0;transform:translateY(-4px);pointer-events:none}.nf .input{font-size:13px;height:24px}.you.naming .nf{opacity:1;transform:none;pointer-events:auto}.you.naming .say{opacity:0;pointer-events:none}.send{width:26px;height:26px;border-radius:50%;display:grid;place-items:center;color:var(--pu-accent);flex:none;opacity:0;pointer-events:none;transition:opacity var(--in) var(--eo),background-color .2s var(--eo)}.send.show{opacity:1;pointer-events:auto}.send:hover{background:var(--as)}.bub{position:fixed;left:0;top:0;width:20px;height:20px;margin:-20px 0 0 -2px;border-radius:50% 50% 50% 0;background:var(--pu-accent);border:2px solid var(--su);box-shadow:0 1px 4px #0003;pointer-events:auto;opacity:0;transform:translateY(-6px) scale(.9);transform-origin:2px 20px;transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.bub.in{opacity:1;transform:none;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.bub.in:hover,.bub.on{transform:scale(1.18)}.bub.done{background:var(--fa)}.bub.ghost{pointer-events:none}.tip,.pop,.menu,.all,.xp,.toast,.selbar,.namebar,.ttip,.tt,.mode{background:var(--su);border:1px solid var(--ln);box-shadow:var(--sh)}.tip{position:fixed;max-width:260px;border-radius:10px;padding:7px 10px;opacity:0;transform:translateY(3px);transition:opacity .22s var(--eo),transform .26s var(--eo)}.tip.show{opacity:1;transform:none;pointer-events:auto;cursor:pointer;transition:opacity .22s var(--eo),transform .26s var(--eo),left var(--mv) var(--eio),top var(--mv) var(--eio)}.pop{position:fixed;width:var(--pu-pop);border-radius:12px;padding:10px 12px 8px;pointer-events:none;opacity:0;transform:translateY(6px) scale(.98);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.pop.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo)}.pop.show.glide{transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo),left var(--mv) var(--eio),top var(--mv) var(--eio)}.mark{position:fixed;border:2px solid color-mix(in srgb,var(--pu-accent) 50%,transparent);background:var(--as);border-radius:8px;opacity:0;transition:opacity .3s var(--eo)}.mark.show{opacity:1}.pulse{position:fixed;border:2px solid var(--pu-accent);border-radius:8px;background:var(--as);animation:pu-pulse var(--pl) var(--eio) forwards}@keyframes pu-pulse{0%{opacity:0;transform:scale(.985)}35%{opacity:.85;transform:scale(1)}to{opacity:0;transform:scale(1.02)}}.col{position:fixed;left:0;top:0;pointer-events:none;transition:opacity var(--in) var(--eo)}.th{position:absolute;left:0;right:0;top:0;padding:4px 4px 4px 12px;pointer-events:auto;cursor:pointer;box-shadow:inset 2px 0 0 transparent;transition:transform var(--mv) var(--eio),box-shadow var(--in) var(--eo),opacity var(--in) var(--eo)}.th.hot{box-shadow:inset 2px 0 0 var(--ln)}.th.on{box-shadow:inset 2px 0 0 var(--pu-accent);cursor:default}.th.dim{opacity:.45}.th.resolved:not(.on):not(.hot){opacity:.6}.th.lost .ctx{white-space:normal}.th.wait{opacity:0!important;pointer-events:none}.th.out{opacity:0!important;pointer-events:none;transition:opacity var(--out) var(--ei)}.th:has(.opn:focus-visible){box-shadow:inset 2px 0 0 var(--ln);outline:2px solid var(--pu-accent);outline-offset:2px;border-radius:4px}.selbar{position:fixed;display:flex;border-radius:10px;padding:2px;opacity:0;transform:translateY(4px);pointer-events:none;transition:opacity var(--in) var(--eo),transform .3s var(--eo)}.selbar.show{opacity:1;transform:none;pointer-events:auto}.selbar button{width:32px;height:30px;display:grid;place-items:center;border-radius:8px;color:var(--pu-accent);transition:background-color .2s var(--eo)}.selbar button:hover,.selbar button:focus-visible{background:var(--as);outline:none}.pick{position:fixed;left:0;top:0;border:2px solid color-mix(in srgb,var(--pu-accent) 70%,transparent);background:color-mix(in srgb,var(--pu-accent) 6%,transparent);border-radius:8px;pointer-events:none;opacity:0;transition:opacity var(--out) var(--ei),border-color var(--out) var(--ei),border-width var(--out) var(--ei),box-shadow var(--out) var(--ei)}.pick.show{opacity:1;transition-duration:var(--in);transition-timing-function:var(--eo)}.pick.show.glide{transition-property:all;transition-duration:var(--mv);transition-timing-function:var(--eio)}.pick.on{border-color:var(--pu-accent)}.pick.kf{border:3px solid var(--pu-accent);box-shadow:0 0 0 2px var(--su)}.km{position:fixed;left:0;top:0;pointer-events:none;outline:none}.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.namebar{position:fixed;left:0;top:0;display:flex;align-items:center;gap:2px;padding:2px 2px 2px 10px;border-radius:10px;font-size:12px;color:var(--mu);white-space:nowrap;pointer-events:none;opacity:0;transform:translateY(4px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.namebar.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform .3s var(--eo)}.namebar.show.glide{transition-property:all;transition-duration:var(--mv);transition-timing-function:var(--eio)}.namebar .lbl{margin-right:6px;max-width:260px;overflow:hidden;text-overflow:ellipsis}.namebar .nb{padding:4px;display:grid;place-items:center;border-radius:7px;transition:background-color .2s var(--eo),color .2s var(--eo)}.namebar .nb:hover,.namebar .nb:focus-visible{background:var(--ho);color:var(--k);outline:none}.namebar .nb[hidden]{display:none}.launch{position:fixed;right:20px;bottom:20px;pointer-events:auto}.launch .mode{position:relative;display:grid;place-items:center;width:46px;height:46px;border-radius:50%;transition:background-color .3s var(--eo),color .3s var(--eo)}.mode>*,.cnt>*{grid-area:1/1}.mode>*{display:grid;place-items:center;transition:opacity var(--in) var(--eo)}.cnt,.has>.plus{opacity:0}.has>.cnt{opacity:1}.n{font-size:12px;font-weight:500;line-height:1;margin:-1.4px 0 0 1.4px;font-variant-numeric:tabular-nums;opacity:0;transition:opacity var(--in) var(--eo)}.n.s{font-size:9.5px;letter-spacing:-.04em}.n.on{opacity:1}.launch .mode:hover,.launch .mode[aria-expanded=true]{background:var(--ho)}.launch .mode.on{background:var(--pu-accent);color:var(--pu-on,#fff)}.mode>.dot{position:absolute;top:3px;right:3px;width:9px;height:9px;border-radius:50%;background:var(--pu-accent);border:2px solid var(--su);opacity:0}.mode.else>.dot{opacity:1}.ttip{position:absolute;right:0;bottom:54px;white-space:nowrap;border-radius:8px;padding:4px 9px;font-size:12px;pointer-events:none;opacity:0;transform:translateY(3px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.ttip small{margin-left:8px}.ttip small,.mi .kc{font-size:12px;color:var(--fa)}.mode:hover+.ttip,.mode:focus-visible+.ttip{opacity:1;transform:none;transition:opacity var(--in) var(--eo) .5s,transform var(--in) var(--eo) .5s}.launch .mode[aria-expanded=true]+.ttip{opacity:0;transition:opacity var(--out) var(--ei)}@media(hover:none){.ttip,.tt{display:none}}.menu{position:fixed;right:20px;bottom:76px;width:290px;border-radius:12px;padding:4px;pointer-events:none;opacity:0;transform:translateY(6px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.menu.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo)}.mi{position:relative;display:flex;gap:10px;align-items:center;width:100%;min-height:34px;text-align:left;padding:6px 10px;border-radius:8px;transition:background-color .2s var(--eo)}.mi:hover,.mi:focus-visible{background:var(--so);outline:none}.mi svg{color:var(--mu);flex:none}.mi small{display:block;color:var(--fa);font-size:12px}.lb{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ma{flex:none;display:grid;margin:-2px 0}.ma .av{width:20px;height:20px;font-size:11px}.mi .av svg{color:inherit}.sep{height:1px;margin:4px 10px;background:var(--ru)}.tt{position:absolute;right:calc(100% + 14px);top:50%;translate:0 -50%;width:max-content;max-width:220px;padding:4px 9px;border-radius:8px;font-size:12px;line-height:1.4;color:var(--mu);pointer-events:none;opacity:0;transform:translate(3px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.mi:hover>.tt,.mi:focus-visible>.tt{opacity:1;transform:none;transition:opacity var(--in) var(--eo) .5s,transform var(--in) var(--eo) .5s}@media(max-width:600px){.tt{right:8px;top:auto;bottom:100%;translate:none;transform:translateY(3px)}}.sw{position:relative;flex:none;width:26px;height:16px;border-radius:8px;background:var(--ln);transition:background-color var(--mv) var(--eio)}.sw:before,.sw:after{content:"";position:absolute;top:2px;left:2px;width:12px;height:12px;border-radius:50%;background:#fff;box-shadow:0 1px 2px #00000040;transition:transform var(--mv) var(--eio),opacity var(--mv) var(--eio)}.sw:before{opacity:0;transform:translate(10px)}[aria-checked=true]>.sw{background:var(--pu-accent)}[aria-checked=true]>.sw:after{transform:translate(10px)}.tools{display:flex;flex:none;gap:2px}.tools[hidden]{display:none}.tool[aria-pressed=true]{background:var(--as);color:var(--pu-accent)}.note{display:block;padding:0 0 4px;font-size:12px;color:var(--fa)}.note[hidden]{display:none}.ov{position:absolute;inset:0;pointer-events:none;overflow:hidden}.xb{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px 16px 16px;font-size:13px}.xb p{margin:0 0 10px}.all,.xp{position:fixed;top:0;right:0;bottom:0;width:var(--pu-panel);display:flex;flex-direction:column;border-width:0 0 0 1px;opacity:0;transform:translate(100%);transition:transform var(--out) var(--ei),opacity var(--out) var(--ei)}.all.show,.xp.show{opacity:1;transform:none;pointer-events:auto;transition:transform var(--mv) var(--eo),opacity var(--in) var(--eo)}.all.full{width:100%}.hd{display:flex;align-items:center;gap:8px;padding:12px 10px 8px 16px;font-weight:600}.pn{font-weight:400;color:var(--fa)}.hs{margin-left:auto;display:flex;align-items:center;gap:6px;padding:3px 4px 3px 6px;border-radius:6px;font-size:12px;font-weight:400;color:var(--mu);transition:background-color .2s var(--eo)}.hs:hover,.hs:focus-visible{background:var(--ho);outline:none}.list{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px}.all .mi{align-items:flex-start}.all .mi>.av{flex:none}.all .mi>span:last-child{flex:1;min-width:0}.all .mi small{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.all .mi.done{opacity:.6}.all .mi.open{background:var(--so)}.all .mi.open>.av,.all .mi.open .clamp{display:none}.xr{padding:2px 12px 10px 16px}.cx{position:fixed;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none;opacity:0;transition:opacity var(--in) var(--eo)}.cx.show{opacity:1}.cx path{fill:none;stroke:var(--pu-accent);stroke-width:1.5;stroke-linecap:round;opacity:.7}.cx circle{fill:var(--pu-accent)}.layer.listing .col{opacity:0;transition:opacity var(--out) var(--ei)}.sec{padding:8px 10px 2px;font-size:12px;color:var(--fa)}.ag{display:flex;align-items:center;gap:8px;padding:6px 14px;font-size:12px;color:var(--fa);border-bottom:1px solid var(--ln)}.ag[hidden]{display:none}.ag button{margin-left:auto;flex:none;padding:0 6px;border-radius:6px;color:var(--fa);transition:color .2s var(--eo),background-color .2s var(--eo)}.ag button:hover:not(:disabled),.ag button:focus-visible{color:var(--pu-accent);background:var(--as);outline:none}.ag button:disabled{opacity:.5;cursor:default}.adr{margin:8px 0 0 14px;padding:8px 10px;border-radius:8px;background:var(--so);font-size:13px;color:var(--k);animation:pu-in var(--mv) var(--eo) both}.adr small{display:block;font-size:12px;color:var(--fa)}.adr .go{display:flex;gap:6px;margin-top:6px}.adr .go button{padding:2px 8px;border-radius:6px;font-size:12px;color:var(--mu);transition:color .2s var(--eo),background-color .2s var(--eo)}.adr .go button:hover,.adr .go button:focus-visible{color:var(--pu-accent);background:var(--as);outline:none}@keyframes pu-in{0%{opacity:0;transform:translateY(3px)}to{opacity:1;transform:none}}.sec b{margin-left:6px;font-weight:500;color:var(--pu-accent)}.toast{position:fixed;left:50%;bottom:28px;border-radius:10px;padding:8px 14px;font-size:13px;opacity:0;transform:translate(-50%,6px);transition:opacity .3s var(--eo),transform .36s var(--eo)}.toast.show{opacity:1;transform:translate(-50%)}@media(forced-colors:active){.pick.kf{border:3px solid Highlight}.layer :is(.ib,.mi,.nb,.hs,.selbar button,.say button,.xb button):focus-visible{outline:2px solid Highlight}}@media(prefers-reduced-motion:reduce){@keyframes pu-in{0%{opacity:0}to{opacity:1}}.bub,.bub.in,.bub.in:hover,.bub.on,.tip,.pop,.selbar,.menu,.all,.xp,.ttip,.tt,.toast,.ref .rc{transform:none!important}.sw:after{transform:none!important;transition-property:opacity}[aria-checked=true]>.sw:after{opacity:0}[aria-checked=true]>.sw:before{opacity:1}.th{transition-property:opacity,box-shadow}.tip.show{transition-property:opacity}.pick,.pick.show{transition:opacity .16s ease-in-out}.all,.all.show,.xp,.xp.show{transition-property:opacity}.namebar,.namebar.show{transform:none!important;transition:opacity .16s ease-in-out}.av,.nf{transform:none!important}.av.ai:after{animation:none;opacity:0}.ghost .dots i{animation:none;opacity:.6}@keyframes pu-pulse{0%{opacity:0}35%{opacity:.85}to{opacity:0}}}',Mn="#534AB7";function Cn(e){let t=/rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)/.exec(e);if(!t||void 0===t[1]||void 0===t[2]||void 0===t[3])return null;let n=void 0===t[4]?1:t[4].endsWith("%")?parseFloat(t[4])/100:parseFloat(t[4]);return{r:Number(t[1]),g:Number(t[2]),b:Number(t[3]),a:n}}function Tn(e){let t=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return.2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}var Pn=(e,t)=>(Math.max(e,t)+.05)/(Math.min(e,t)+.05);function Nn(e){let t=e.ownerDocument,n=t.defaultView;if(!n)return{font:"system-ui, sans-serif",accent:Mn,dark:!1,on:"#fff"};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(),a=e.querySelector("a[href]"),l=a?n.getComputedStyle(a).color:"",s=Cn(n.getComputedStyle(t.body).backgroundColor);(!s||0===s.a)&&(s=Cn(n.getComputedStyle(o).backgroundColor));let d=!!(s&&s.a>0?Tn(s)<.2:!0===n.matchMedia?.("(prefers-color-scheme: dark)").matches&&/dark/.test(n.getComputedStyle(o).colorScheme||"")),c=l&&"rgb(0, 0, 238)"!==l?Cn(l):null,p=c&&Pn(Tn(c),d?.011:1)>=3,u=i||(p?l:d?"#9A94EE":Mn),h=Cn(u);return{font:r,accent:u,dark:d,on:h&&Pn(Tn(h),1)<3?"#111":"#fff"}}function qn(e,t){e.style.setProperty("--pu-font",t.font),e.style.setProperty("--pu-accent",t.accent),e.style.setProperty("--pu-on",t.on),e.classList.toggle("dark",t.dark)}var zn=/^\/__pipeup\/[A-Za-z0-9_-]{16,}$/,Rn=/^[A-Za-z0-9_-]{43}$/;function On(){let e=document.documentElement.getAttribute("data-pipeup-replies");try{let t=location.href.split(/[?#]/)[0],n=new URL(e??(/\/$/.test(t)?`${t}index.replies.js`:t.replace(/\.[^./]*$/,"")+".replies.js"),location.href),o="file:"===n.protocol?"file:"===location.protocol:n.origin===location.origin;return o||console.warn("pipeup: the replies file must be on this site or this computer; ignoring it"),o?n.href:null}catch{return null}}function Dn(e,t=!1){return nn(e,t)?"column":"bubbles"}var In="Shown here, but not saved yet — it will be saved with your next change",Fn=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";function Bn(e){let t=Nn(e.root),n=function(e,t=document){let n=t.createElement("pipeup-root");n.setAttribute("data-pipeup-ignore",""),n.style.cssText="position:fixed!important;inset:0!important;pointer-events:none!important;z-index:2147483000!important;display:block!important;margin:0!important;visibility:visible!important;opacity:1!important;transform:none!important;filter:none!important;";let o=n.attachShadow({mode:"open"}),r=t.defaultView?.CSSStyleSheet;if(r&&"replaceSync"in r.prototype&&"adoptedStyleSheets"in o){let e=new r;e.replaceSync(An),o.adoptedStyleSheets=[e]}else{let e=t.createElement("style");e.textContent=An,o.append(e)}let i=t.createElement("div");return i.className="layer",i.style.setProperty("--pu-panel","320px"),i.style.setProperty("--pu-pop",`${Tt()}px`),qn(i,e),o.append(i),t.documentElement.append(n),{element:n,shadow:o,t:i,destroy:()=>n.remove()}}(t),o=function(e=document,t=!1){let n=e.defaultView?.CSSStyleSheet;if(!n||!("replaceSync"in n.prototype)||!("adoptedStyleSheets"in e))return{Ee(){},ke(){},ae(){},Se(){},remove:()=>Ln()};let o=new n,r=null,i=!1,a=1,l=0,s="",d=0,c=()=>o.replaceSync(((e,t)=>kn.map(n=>{let[o,r,i,a]=En[n][e?1:0];return`::highlight(${n}){background-color:rgba(${o},${r},${i},${+(a*t).toFixed(3)})}`}).join(""))(t,a)+(null===r?"":`:root{--pipeup-gutter:${r}px}`)+(i?Sn:"")+(l||s?`html{--pipeup-panel:${l}px;${l?`margin-right:${l}px!important;`:""}${s}}`:""));return c(),e.adoptedStyleSheets=[...e.adoptedStyleSheets,o],{Ee(e){e!==r&&(r=e,c())},ke(e){e!==i&&(i=e,c())},ae(e){a=e,c()},Se(e,t){e!==l&&(l=e,s=t?"":"transition:margin-right .34s cubic-bezier(.4,0,.2,1)!important",clearTimeout(d),!e&&s&&(d=window.setTimeout(()=>{s="",c()},400)),c())},remove(){clearTimeout(d),e.adoptedStyleSheets=e.adoptedStyleSheets.filter(e=>e!==o),Ln()}}}(document,t.dark);o.ae(0);let r=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,i=document.documentElement.hasAttribute("data-pipeup-reserve"),a=new Map,l=new Set,s=new WeakSet,d={i:null,m:null,C:!1,hidden:!0,mode:Dn(e.root),o:null,d:!1,c:!1,Te:!1,s:!1},c=Ie("div",{class:"toast",role:"status","aria-live":"polite"}),p=Ie("div",{class:"sr","aria-live":"polite"});n.t.append(c,p);let u=null,h=[],f=null,m=!1,v=0,g=0,w=0,y=0,b=0,x=new Set,k="",E=new Map,$=function(e,t,n=function(){return{l:e=>e.getBoundingClientRect(),shown:e=>!1!==e.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0}),opacity:e=>parseFloat(getComputedStyle(e).opacity)||0,oe:()=>({width:window.innerWidth,height:window.innerHeight})}}()){let o=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,r=null,i=null,a=0,l=!1,s=()=>[...e.querySelectorAll(pn)],d=()=>[...e.querySelectorAll(".slides > section")],c=e=>"string"==typeof e&&e.length>0&&e.length<=200?e:null,p=e=>c(e?.getAttribute("data-pipeup-slide"));function u(){if(fn){let e=null;if(gn(()=>{let t=fn.current();Number.isInteger(t)&&t>0&&(e=String(t))}),null!==e)return e}let e=xn();if(e){let t=null;if(gn(()=>{let n=e.getIndices().h,o=d()[n];t=p(o?.matches(pn)?o:o?.querySelector(pn))??c(String(n+1))}),null!==t)return t}return r&&!r.isConnected&&(r=null),r=function(e,t,n){let o=t.oe(),r=null,i=0,a=0;for(let l of e){if(!t.shown(l))continue;let e=t.l(l),s=Math.min(e.left+e.width,o.width)-Math.max(e.left,0),d=Math.min(e.top+e.height,o.height)-Math.max(e.top,0);if(s<=0||d<=0)continue;let c=Math.round(s*d),p=t.opacity(l);(c>i||c===i&&(p>a||p===a&&l===n))&&(r=l,i=c,a=p)}return r}(s(),n,r)??r,p(r)}function h(){a=0,i=u(),t()}let f=()=>{!a&&!l&&(a=requestAnimationFrame(h))},m=e=>function(e,t,n){return null!==t?void 0===e?.slide||e.slide===t:!e||!n||Object.entries(e).every(([e,t])=>"label"===e||"slide"===e||n[e]===t)}(e,i,hn),v=new MutationObserver(e=>{e.some(e=>e.target instanceof Element&&e.target.matches(pn))&&f()});v.observe(e,{subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]});for(let e of un)window.addEventListener(e,f,{capture:!0,passive:!0});return vn.add(f),i=u(),{slide:()=>i,view(e){let t=e instanceof Element?e:e?.parentElement,n=p(t?.closest(pn))??i,o={...null!==n?{slide:n}:{},...hn};return Object.keys(o).length?o:void 0},f:m,R:function(e){if(m(e))return Promise.resolve(!0);let t=e.slide,n=xn(),r=s().find(e=>p(e)===t),a=/^[1-9]\d{0,5}$/.test(t??"");if(a&&fn)gn(()=>fn.go(Number(t)));else if(a&&n){let e=r?d().findIndex(e=>e===r||e.contains(r)):-1;gn(()=>n.slide(e>=0?e:Number(t)-1))}else if(mn.size)for(let t of mn)gn(()=>t({...e}));else{if(!r)return Promise.resolve(!1);r.scrollIntoView({block:"start",behavior:o?"auto":"smooth"})}let c=performance.now();return new Promise(t=>{let n=e=>{clearTimeout(o),t(e)},o=setTimeout(()=>n(!1),1e3),r=()=>l?n(!1):(i=u(),m(e)?n(!0):performance.now()-c>=1e3?n(!1):void requestAnimationFrame(r));requestAnimationFrame(r)})},destroy(){l=!0,cancelAnimationFrame(a),v.disconnect();for(let e of un)window.removeEventListener(e,f,!0);vn.delete(f)}}}(e.root,()=>{!m&&j()&&G()}),S=!1,L=0;function A(e,t=2400,n=!1,o=!1){m||(S=n,c.textContent=e,o?c.setAttribute("aria-hidden","true"):c.removeAttribute("aria-hidden"),c.classList.add("show"),window.clearTimeout(v),v=window.setTimeout(()=>c.classList.remove("show"),t))}function M(){S&&(S=!1,window.clearTimeout(v),c.classList.remove("show"))}function C(e){p.textContent="",cancelAnimationFrame(L),L=requestAnimationFrame(()=>p.textContent=e)}function T(e){A(Fn(e))}function P(e){throw T(e),e}let N=t=>({thread:t,location:xe(t.anchor,a.get(t.id)??fe(t.anchor,e.root),e.root)}),q={reply:async(t,n)=>{try{await e.doc.reply(t,n)}catch(e){e instanceof W?A(In):P(e)}},resolve:async t=>{try{await e.doc.resolve(t),A("Resolved · Show resolved brings it back")}catch(e){A(e instanceof W?`Resolved · ${In}`:Fn(e))}(e=>d.i===e&&!d.C&&(f?.ie()?f.se():n.t.querySelector(".launch .mode")?.focus({preventScroll:!0}),!0))(t)&&(d.i=null)},reopen:async t=>{try{await e.doc.reopen(t),A("Reopened")}catch(e){A(e instanceof W?`Reopened · ${In}`:Fn(e))}},notRight:async t=>{try{await e.doc.reopen(t)}catch(e){A(e instanceof W?`Reopened · ${In}`:Fn(e))}ee(t)},close:()=>{ne(null);let e=J&&n.t.querySelector(J);e?e.focus({preventScroll:!0}):f?.se(),J=""},copy:t=>{try{let o=e.doc.threads().find(e=>e.id===t);if(!o)return;sn(Le(N(o),"ai",location.href,Date.now()),n.t).then(()=>A("Thread copied as Markdown for AI"),e=>A(Fn(e)))}catch(e){A(Fn(e))}}},z=function(e){let t=function(){let e=document.documentElement.getAttribute("data-pipeup-agents")??"";return[...new Set(e.split(/[\s,]+/).filter(e=>Rn.test(e)))]}(),n=0,o="",r=null;async function i(){let r=globalThis.pipeupReplies;if(!Array.isArray(r))return 0;let i=r.splice(0),a=[];for(let r of i){let i=r;if("pipeup-replies"===i?.format&&i.doc===e.doc.id&&Array.isArray(i.ops))for(let e of i.ops){let r=e?.body;r&&t.includes(r.author)&&("reply"===r.kind||"addressed"===r.kind)?(a.push(e),O(r.name)&&(o=r.name.replace(/^AI assistant\s*·?\s*/,""))):n++}}return a.length?e.doc.merge(a,"agent"):0}async function a(){if(!t.length)return 0;let n=await i();return await function(){let t=On();return t?(r?.remove(),new Promise((n,o)=>{let i=document.createElement("script");r=i,i.src=`${t}?${Date.now()}`;let a=e=>{window.clearTimeout(l),i.remove(),r===i&&(r=null),e?o(new Error(`pipeup: ${e}`)):n()},l=window.setTimeout(()=>a("the replies file didn't answer"),4e3);i.addEventListener("load",()=>a()),i.addEventListener("error",()=>a("there is no replies file yet")),e.t.append(i)})):Promise.reject(new Error("pipeup: the replies file can't be read from here"))}(),n+await i()}let l=!1,s=()=>{l||document.hidden||(l=!0,a().catch(()=>{}).finally(()=>l=!1))},d=0;return t.length?(s(),d=window.setInterval(s,4e3),document.addEventListener("visibilitychange",s)):i(),{enabled:t.length>0,ignored:()=>n,who:()=>o,check:a,tally:n=>{let o=n.filter(e=>!e.resolved),r=new Set(n.map(e=>e.id));return{stray:new Set(e.doc.ops().filter(e=>t.includes(e.body.author)&&!r.has(e.body.thread)).map(e=>e.body.thread)).size,open:o.length,answered:o.filter(e=>e.root.replies.some(e=>t.includes(e.author))).length,addressed:o.filter(e=>e.addressed).length}},destroy:()=>{window.clearInterval(d),document.removeEventListener("visibilitychange",s),r?.remove()}}}({doc:e.doc,t:n.t}),R=function(e){let t=document.documentElement,n=t.getAttribute("data-pipeup-link")??"",o=zn.test(n),r=!1,i=0,a=()=>{};async function l(){let t=!1;try{t=(await fetch(`${n}/comments`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e.snapshot())})).ok}catch{}if(!t)throw new Error("pipeup: the link to your agent isn't reachable; your comments are safe here")}let s=()=>{window.clearTimeout(i),a(),a=()=>{},r=!1};return{enabled:o,agent:t.getAttribute("data-pipeup-link-agent")??"",file:t.getAttribute("data-pipeup-link-file")??"",on:()=>r,set:async t=>{if(o){if(!t)return s(),void e.refresh();await l(),r=!0,a=e.changes(()=>{window.clearTimeout(i),i=window.setTimeout(()=>{l().catch(t=>{s(),e.refresh(),globalThis.reportError?.(t)})},300)}),e.refresh()}},destroy:s}}({snapshot:()=>{let e=D.all(),t={title:document.title,url:location.href,exportedAt:new Date};return{v:1,at:t.exportedAt.toISOString(),title:t.title,open:xt(e,t),all:xt(e,{...t,all:!0})}},changes:t=>e.doc.onChange(t),refresh:()=>G()}),D={copyAll:async e=>{let t=D.all(),o=Ae(t,e,{title:document.title,url:location.href,exportedAt:new Date});try{await sn(o,n.t);let r=t.filter(e=>!e.thread.resolved).length;A(`Copied ${r} thread${1===r?"":"s"}${"ai"===e?" as Markdown for AI":""}`)}catch(e){A(Fn(e))}},copyPrompt:async()=>{try{await sn(function(e){let t=e=>e.replace(/\s+/g," ").trim();return[`Act on the review comments on this page, which uses Pipeup: ${t(e.title)} (${t(e.url)}).`,"",e.file?`1. Read the comments: \`npx pipeup comments ${e.file}\` (add --all for resolved ones). If it says nothing is shared, ask me to switch on Share with my agent.`:"1. Read the comments. Open the page in a browser and run `await Pipeup.comments()`, then read `.markdown`. If you can't run the page, ask me to paste its Copy as Markdown.","2. Work through the open threads in order. For each, make the change I approved, or say why you didn't. Ask me before changing anything I haven't approved, and answer a question with an answer.",e.replies?`3. Answer in each thread: \`npx pipeup reply --page ${e.file||"<the page's file>"} --thread <Thread id> "what you changed and where" --addressed "short note"\`. That writes ${t(e.replies)}.`+(e.listed?"":" The page doesn't list your key yet: run `npx pipeup agent --name <your name>` and tell me the attribute to add."):"3. Tell me what you would reply in each thread, in words I can paste.","4. Only mark a thread addressed. Never resolve, reopen, edit or delete: I close threads. Keep your key out of the page and its folder, and never answer as me.","","Guide: https://pipeup-ai.github.io/pipeup/skills/pipeup-apply/SKILL.md"].join("\n")}({title:document.title,url:location.href,replies:On(),file:R.enabled?R.file:"",listed:z.enabled}),n.t),A("Copied a prompt for your agent")}catch(e){A(Fn(e))}},Ye:()=>{d.C=!d.C,G()},rename:async t=>{let n=t.replace(/\s+/g," ").trim();try{await async function(t){try{return await e.onName(t),!1}catch(n){if(e.doc.name!==t)throw n;return!0}}(n)?A(`New comments will say ${n}, but this browser couldn't remember it`):A(`New comments will say ${n}`)}catch(e){A(Fn(e))}},name:()=>e.doc.name,all:()=>[...e.doc.threads()].sort(zt(F)).map(N)},I={},F={get addons(){return I.surface},doc:e.doc,root:e.root,t:n.t,host:n.element,state:d,resolved:a,S:l,te:q,s:D,replies:z,link:R,p:$,_:e=>x.has(e.id),xe:()=>{j()&&G()},B:e=>!d.hidden&&(!e.resolved||d.C||(e=>""!==(n.t.querySelector(`[data-thread="${e}"] .rbox textarea`)?.value.trim()??""))(e.id))&&!x.has(e.id),Xe:(t,n)=>{for(let o of e.doc.threads()){let e=a.get(o.id);if(o.anchor.quote&&F.B(o)&&e?.range&&Ct(t,n,Lt(e)))return o}return null},ne:(e,t)=>F.L()?F.Xe(e,t):null,w:e=>e.composedPath().includes(n.element),ye:e=>{s.add(e)},Ue:e=>s.has(e),open:ne,Je:e=>ee(e),m:function(e){d.m!==e&&(d.m=e,e&&e!==d.i&&se(e),G())},je:oe,qe:function(e){if(!d.o)return oe(e);Object.assign(d.o,e),G()},L:()=>!u||u.De(),we:e=>{let t=u?.ge();e(),t?.()},ze:()=>{let e=d.o?.anchor.view,t=u?.ge();Promise.resolve($.f(e)||$.R(e??{}).then(()=>F.xe())).then(t)},Be:async function(t){let n=d.o;if(n)try{let o=await e.doc.comment(n.anchor,t);d.o=null,H(new Set([o])),ne(o,!0)}catch(e){if(e instanceof W)return d.o=null,H(new Set([e.id])),ne(e.id,!0),void A(In);P(e)}},Fe:re,Ge:ie,V:le,H:e=>{u=e},Y:A,E:C,Ke:M,F:T,Qe:se,u:G,re:ae},B=I.surface=new ft(F,n.shadow,p);function H(t){let n=performance.now(),o=e.doc.threads();for(let r of o){if(t&&!t.has(r.id))continue;let o=performance.now()-n<40,i=fe(r.anchor,e.root,{fuzzy:o});a.set(r.id,i),o||"orphaned"!==i.state?l.delete(r.id):l.add(r.id)}for(let e of[...a.keys()])o.some(t=>t.id===e)||a.delete(e);0===l.size?(window.clearTimeout(y),y=0):0===y&&(y=window.setTimeout(()=>{y=0,!m&&(H(new Set(l)),G())},250))}function j(){let t=new Set,n=null!==$.slide(),o=new Set;for(let r of e.doc.threads()){o.add(r.id);let e=a.get(r.id)?.element;(!$.f(r.anchor.view)||!n&&!1===e?.checkVisibility?.({visibilityProperty:!0}))&&t.add(r.id)}x=t;for(let e of E.keys())o.has(e)||E.delete(e);let r=`${$.slide()}|${[...t].join()}`;return r!==k&&(k=r,!0)}let K=0,Y=0,U=0,V=0,_=0;function G(){if(m)return;let t=e.doc.threads();if(j(),d.i&&x.has(d.i)){let e=n.t.querySelector(`[data-thread="${d.i}"] .rbox textarea`)?.value;e&&E.set(d.i,e),d.i=null}d.hidden=!(d.d||d.c||d.Te||d.o),d.hidden&&(d.i=null),function(e){if(e===Y)return;Y=e,cancelAnimationFrame(U);let t=K,n=performance.now(),r=e?260:200,i=a=>{let l=Math.min(1,(a-n)/r);K=t+(e-t)*(e?1-(1-l)**3:l*l),o.ae(K),l<1&&(U=requestAnimationFrame(i))};U=requestAnimationFrame(i)}(d.hidden?0:1),n.t.classList.toggle("hidden",d.hidden),n.t.classList.toggle("listing",d.c);let l=d.c&&!Pt();(function(e){e!==V&&(V=e,o.Se(e,r),window.clearTimeout(_),_=window.setTimeout(()=>{H(),G()},r?0:400))})(l?320:0),o.Ee(i?"column"!==d.mode||d.hidden||l?0:320:null),function(e){let t=[],n=[],o=[];for(let r of e){let e=a.get(r.id);r.resolved&&!d.C||!e?.range||x.has(r.id)||(r.id===d.i||r.id===d.m?n.push(e.range):r.resolved?o.push(e.range):t.push(e.range))}d.o&&$.f(d.o.anchor.view)&&n.push(...d.o.ranges),function(e){if($n())for(let t of kn)CSS.highlights.set(t,new Highlight(...e[t.slice(7)]))}({quote:t,on:n,done:o})}(t);for(let e of h)e.u(t);f?.u(t),d.hidden||B.flush()}let J="",X=()=>n.t.getRootNode().activeElement,Z="input,textarea,select,[contenteditable]:not([contenteditable=false])",Q=()=>{let e=X();return e instanceof HTMLTextAreaElement&&""!==e.value||!!document.activeElement?.matches(Z)};function ee(e,t=Q(),o=X()){let r=[...n.t.querySelectorAll(`[data-thread="${e}"] .rbox textarea`)].find(e=>!e.closest("[inert]")),i=o?.getAttribute("data-thread");J=i?`.${o.classList[0]}[data-thread="${i}"]`:"",!t&&r&&r.focus({preventScroll:!0})}function te(){let e=d.o;return!(!e||F.L()||($.f(e.anchor.view)||$.R(e.anchor.view??{}),0))}function ne(e,t=!1){if(e&&te())return;if(d.i===e&&!d.o)return e?ee(e):void 0;let o=!t&&Q(),r=X();if(e||(d.Te=!1),d.i=e,e&&(d.o=null,se(e)),G(),e){let i=E.get(e),a=i&&n.t.querySelector(`[data-thread="${e}"] .rbox textarea`);a&&!a.value&&(a.value=i,a.dispatchEvent(new Event("input",{bubbles:!0}))),E.delete(e),t&&f?.ie()?f.se():ee(e,o,r)}}function oe(e){M(),d.c=!1,d.o=e,d.i=null,G()}function re(){d.o&&(d.o=null,G())}function ie(e,t=!1){d.d!==e&&(d.d=e,o.ke(e),e?(d.i=null,d.c=!1,f=tn(F)):(M(),f?.destroy(),f=null,C("Comment mode off")),G(),f&&(t&&f.be(),t?f.ie()?A(en,1e4,!0,!0):A("Nothing here to comment on"):A(`Click anything to comment, or Tab between blocks · Option-click (Alt-click) to pin · ${kt} or Esc to finish`,4e3,!0)))}function ae(){d.o&&($.f(d.o.anchor.view)||F.L())?re():d.i?ne(null):f&&!f.re()&&ie(!1)}function le(){d.o?te()||re():d.i&&ne(null)}function se(e){let t=a.get(e);!t||"orphaned"===t.state||de(t.range?Lt(t):t.element?[t.element.getBoundingClientRect()]:[])}function de(e){for(let t of e.slice(0,6)){let e=Ie("div",{class:"pulse"});We(e,t,4),n.t.prepend(e),window.setTimeout(()=>e.remove(),1300)}}function ce(){for(let e of h)e.destroy();h=function(e){return[..."column"===e.state.mode?[rn(e),Dt(e,{ee:!1})]:[Dt(e,{ee:!0})],ln(e),cn(e)]}(F),G()}Oe.go=t=>{if(t.startsWith("slide:"))return void $.R({slide:t.slice(6)});let n=decodeURIComponent(t.slice(6)).replace(/\s+/g," ").toLowerCase(),o=[...e.root.querySelectorAll("p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,figcaption,dt,dd")].find(e=>(e.textContent??"").replace(/\s+/g," ").toLowerCase().includes(n));o&&(o.scrollIntoView({block:"center",behavior:r?"auto":"smooth"}),window.setTimeout(()=>de([o.getBoundingClientRect()]),r?0:450))};let pe=()=>{if(!m){for(let e of h)e.T();f?.T(),B.T(),b=requestAnimationFrame(pe)}},ue=e=>{if("Escape"===e.key)return ae();if(function(e){return"KeyC"===e.code&&e.shiftKey&&e.altKey&&!e.metaKey&&!e.ctrlKey&&!e.repeat&&!e.getModifierState("AltGraph")}(e)&&!e.isComposing&&!e.defaultPrevented&&!(e=>{let t=e.composedPath()[0];return t instanceof Element&&null!==t.closest(Z)})(e)){if(e.preventDefault(),f?.We()&&f.be())return;ie(!d.d,!0)}},he=e=>{if(F.w(e)||s.has(e))return;let t=window.getSelection();t&&!t.isCollapsed||le()},me=()=>{n.t.style.setProperty("--pu-pop",`${Tt()}px`);let t=Dn(e.root,"column"===d.mode);t!==d.mode?(d.mode=t,ce()):G()};function ve(){let e=performance.now();0===g&&(w=e),window.clearTimeout(g);let t=Math.min(120,Math.max(0,w+1e3-e));g=window.setTimeout(()=>{g=0,H(),G()},t)}let ge=new MutationObserver(e=>{e.every(e=>n.element.contains(e.target))||ve()});window.addEventListener("keydown",ue),window.addEventListener("click",he),window.addEventListener("resize",me),ge.observe(e.root,{subtree:!0,childList:!0,characterData:!0});let we=new MutationObserver(()=>qn(n.t,Nn(e.root)));for(let e of[document.documentElement,document.body])we.observe(e,{attributes:!0});let ye=new ResizeObserver(ve);ye.observe(e.root);let be=e.doc.onChange((e,t,n)=>{B.Oe(t,n),H(),G()});return H(),ce(),b=requestAnimationFrame(pe),{ctx:F,destroy(){m=!0,cancelAnimationFrame(b),cancelAnimationFrame(U),cancelAnimationFrame(L),$.destroy(),window.clearTimeout(_),window.clearTimeout(v),window.clearTimeout(g),window.clearTimeout(y),ge.disconnect(),Oe.go=void 0,ye.disconnect(),we.disconnect(),be(),window.removeEventListener("keydown",ue),window.removeEventListener("click",he),window.removeEventListener("resize",me),f?.destroy();for(let e of h)e.destroy();B.destroy(),z.destroy(),R.destroy(),o.remove(),n.destroy()}}}var Hn=null;function jn(e={}){if(gt)return gt.mount(e);if(!function(){if(gt)return!0;let e=globalThis,t=e.pipeupAddons;if(Array.isArray(t))for(let e of t)yt(e);else if(t&&"object"==typeof t&&t.push!==yt)return!1;return e.pipeupAddons={push:yt},!0}())return Promise.reject(new Error("pipeup: another copy of Pipeup owns the add-on queue. Remove one script."));if(Hn)return Hn;let t=async function(e,t){let n,o,r=document.documentElement.getAttribute("data-pipeup-doc"),{id:a,key:l}=r?await F(r):{id:`page-${i(location.origin+location.pathname)}`,key:null},s=!1;if(e.store)n=e.store,o=await G(n);else try{let e=J.open();n=await function(e){return new Promise((t,n)=>{let o=setTimeout(()=>n(new Error("timed out")),4e3);e.then(t,n).finally(()=>clearTimeout(o))})}(e).catch(t=>{throw e.then(e=>e.close(),()=>{}),t}),o=await G(n)}catch{n=new V,s=!0,o=await G(n)}let d=e.name?.trim();d&&d!==o.name&&(o={...o,name:d},await n.saveProfile(o));let c,p=await K.open({doc:a,key:l,store:n,identity:o.identity,name:o.name});bn(e.slides??null);try{c=Bn({doc:p,root:e.root??document.body,onName:async e=>{p.name=e,o={...o,name:e},await n.saveProfile(o)}})}catch(e){throw bn(null),e}s&&c.ctx.Y("This browser can't keep comments for this page — copy the comments (Copy as Markdown) to keep them");let u=()=>{p.flush().catch(e=>globalThis.reportError?.(e))},h=function(e){let t={...e,i:!0};vt=t;for(let e of mt.values())"waiting"===e.info.state&&bt(e,t);return()=>{t.i=!1,vt===t&&(vt=null);for(let e of[...mt.values()].reverse())e.stop?.(),delete e.stop;e.surface.destroy()}}({surface:c.ctx.addons,doc:p,root:e.root??document.body,ephemeral:s,version:Ne}),f=!1;return window.addEventListener("pagehide",u),{document:p,comments:({all:e=!1}={})=>xt(c.ctx.s.all(),{title:document.title,url:location.href,exportedAt:new Date,all:e}),flush:()=>p.flush(),unmount:()=>{f||(f=!0,window.removeEventListener("pagehide",u),h(),c.destroy(),bn(null),Hn===t()&&(Hn=null))}}}(e,()=>t).catch(e=>{throw Hn===t&&(Hn=null),e});return Hn=t,t}async function Wn(e){if(!Hn)throw new Error("pipeup: Pipeup hasn't started on this page");return(await Hn).comments(e)}export{ct as ADDON_API,R as AI_NAME,M as ANIMALS,C as COLOURS,_ as DEFAULT_PROFILE_NAME,J as IndexedDbStore,V as MemoryStore,K as PipeupDocument,W as UnsavedChangeError,Ne as VERSION,wt as addons,q as animalName,Wn as comments,L as computeOpId,Ae as copyAll,Le as copyThread,s as createIdentity,de as describeElement,se as describeRange,Se as formatAgo,O as isAiName,be as labelOf,G as loadOrCreateProfile,xe as locate,jn as mount,z as nameOf,I as newDocumentAttribute,yn as onReveal,F as parseDocumentAttribute,fe as resolveAnchor,wn as setViewState,g as signOp,yt as use};
1
+ function e(e){let t="";for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function t(e){let t=atob(e.replace(/-/g,"+").replace(/_/g,"/")),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function n(e){return(new TextEncoder).encode(e)}function o(e){if(null===e||"object"!=typeof e)return JSON.stringify(e);if(Array.isArray(e))return"["+e.map(o).join(",")+"]";let t=e;return"{"+Object.keys(t).filter(e=>void 0!==t[e]).sort().map(e=>JSON.stringify(e)+":"+o(t[e])).join(",")+"}"}function r(e){return e.replace(/\s+/g," ").trim()}function i(e){let t=r(e),n=2166136261;for(let e=0;e<t.length;e++)n^=t.charCodeAt(e),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")}var a=/^[A-Za-z0-9_-]{43}$/,l=new Map;async function s(){let t=await crypto.subtle.generateKey({name:"Ed25519"},!1,["sign","verify"]);return{publicKey:e(new Uint8Array(await crypto.subtle.exportKey("raw",t.publicKey))),privateKey:t.privateKey}}async function d(t,n){let o=await crypto.subtle.sign({name:"Ed25519"},t.privateKey,n);return e(new Uint8Array(o))}var c="0123456789ABCDEFGHJKMNPQRSTVWXYZ",p=Uint8Array.from([48,46,2,1,0,48,5,6,3,43,101,112,4,34,4,32]);function u(e){let t=0,n=0,o="";for(let r of e)for(n=n<<8|r,t+=8;t>=5;)o+=c[n>>>t-5&31],t-=5;return t&&(o+=c[n<<5-t&31]),o}function h(e){let t=2166136261;for(let n of e)t=Math.imul(t^n,16777619);t=Math.imul(t^t>>>15,739982445);let n="";for(let e=0;e<4;e++,t>>>=5)n+=c[31&t];return n}function f(e){return`PU1-${(u(e)+h(e)).match(/.{1,4}/g).join("-")}`}async function m(e){let t=new Uint8Array(p.length+e.length);t.set(p),t.set(e,p.length);let n=await crypto.subtle.importKey("pkcs8",t,{name:"Ed25519"},!0,["sign"]);return{publicKey:(await crypto.subtle.exportKey("jwk",n)).x,privateKey:n}}var g=["Otter","Fox","Owl","Bear","Rabbit"],v=["Red","Orange","Yellow","Green","Teal","Blue","Purple","Pink","Brown","Grey"];function w(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 y=e=>w(e)%g.length,b=e=>Math.floor(w(e)/g.length)%v.length,x=e=>`${v[b(e)]} ${g[y(e)]}`,k=e=>{let t=e.name.replace(/^AI assistant · /,"")||x(e.author);return e.alike?`${t} · ${function(e){let t=w(`id:${e}`),n="";for(let e=0;e<4;e++,t>>>=5)n+="0123456789ABCDEFGHJKMNPQRSTVWXYZ"[31&t];return n}(e.author)}`:t},E="AI assistant",$=e=>e===E||e.startsWith(`${E} `),S=2**40,L=2**47,C=1e4,M=/^[0-9a-f]{8}$/,A=/^[A-Za-z0-9_-]{43}$/,T=/^(?:[^\s@<>"]{1,64}@[^\s@<>"]{1,190}\.[^\s@<>"]{2,24}|gh:[A-Za-z0-9-]{1,39})$/,P=/^(?:[A-Za-z0-9_-]{43}|(?:host|gh):[A-Za-z0-9._@-]{1,64})$/,q=/^[A-Za-z0-9_-]{43}$/,N=new Set(["create","reply","edit","delete","resolve","reopen","addressed","react","unreact","seen","contact","uncontact"]),R=/^(?:\p{Regional_Indicator}{2}|[#*0-9]\uFE0F?\u20E3|\p{Extended_Pictographic}(?:\uFE0F|\p{Emoji_Modifier})?(?:\u200D\p{Extended_Pictographic}(?:\uFE0F|\p{Emoji_Modifier})?)*)$/u,z=e=>"string"==typeof e&&R.test(e)&&[...e].length<=16;async function D(e,t){if(e.author!==t.publicKey)throw new Error("pipeup: an op must be signed by its author");return{body:e,sig:await d(t,n(o(e)))}}var O=(e,t)=>"string"==typeof e&&e.length<=t,F=e=>!!e&&"object"==typeof e,I=e=>"number"==typeof e&&Number.isFinite(e)&&e>=0&&e<=1;function B(e){if(!F(e))return!1;let{id:t,path:n,fingerprint:o,snapshot:r,quote:i,point:a,view:l}=e;if(!(O(n,2e3)&&O(r,500)&&"string"==typeof o&&M.test(o)&&(void 0===t||O(t,200)&&""!==t)&&(void 0===i||F(i)&&O(i.exact,C)&&""!==i.exact&&O(i.prefix,64)&&O(i.suffix,64))&&(void 0===a||F(a)&&I(a.x)&&I(a.y))))return!1;if(void 0!==l){if(!F(l)||Array.isArray(l))return!1;let e=Object.entries(l);if(e.length>16||!e.every(([e,t])=>e.length<=64&&O(t,200)))return!1}return!0}function j(e){if(!F(e))return!1;let{body:t,sig:n}=e;if("string"!=typeof n||!F(t)||JSON.stringify({body:t,sig:n}).length>262144)return!1;let o=t;if(1!==o.v||"string"!=typeof o.id||!A.test(o.id)||!N.has(o.kind)||!O(o.doc,64)||""===o.doc||"string"!=typeof o.thread||!A.test(o.thread)||"string"!=typeof o.author||!q.test(o.author)||"string"!=typeof o.name||o.name.length>80||o.name!==o.name.trim()||"number"!=typeof o.clock||!Number.isSafeInteger(o.clock)||o.clock<1||o.clock>S||"number"!=typeof o.at||!Number.isSafeInteger(o.at)||o.at<0||o.at>L||void 0!==o.text&&(!O(o.text,1e4)||o.text!==o.text.trim())||void 0!==o.target&&("string"!=typeof o.target||!A.test(o.target))||("create"===o.kind||"reply"===o.kind||"edit"===o.kind||"addressed"===o.kind)&&!o.text||("reply"===o.kind||"edit"===o.kind||"delete"===o.kind)&&!o.target)return!1;if(void 0!==o.mentions){if("create"!==o.kind&&"reply"!==o.kind&&"edit"!==o.kind||!Array.isArray(o.mentions)||o.mentions.length>20)return!1;let e=o.text?.length??0;for(let t of o.mentions){if(!F(t)||!Number.isSafeInteger(t.start)||!Number.isSafeInteger(t.end))return!1;let{start:n,end:o,ref:r}=t;if(n<0||o<=n||o>e||"string"!=typeof r||!P.test(r))return!1}}return!(!("contact"!==o.kind||"string"==typeof o.text&&T.test(o.text))||"seen"===o.kind&&!o.target||!("react"!==o.kind&&"unreact"!==o.kind||o.target&&z(o.text))||!("create"!==o.kind||o.id===o.thread&&B(o.anchor)))}function H(r){return async function(n,o,r){if(!a.test(n))return!1;try{if(e(t(n))!==n)return!1;let i=l.get(n);if(!i){l.size>=512&&l.delete(l.keys().next().value),i=crypto.subtle.importKey("raw",t(n),{name:"Ed25519"},!0,["verify"]),l.set(n,i);let e=i;e.catch(()=>{l.get(n)===e&&l.delete(n)})}return await crypto.subtle.verify({name:"Ed25519"},await i,t(r),o)}catch{return!1}}(r.body.author,n(o(r.body)),r.sig)}function W(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 U(e,t,n,o,r,i){let a={id:e,author:t,name:n,text:o,at:r,edited:!1,deleted:!1,replies:[],reactions:[]};return i?.length&&(a.mentions=i),a}async function K(t){let r={...t,id:void 0,thread:"create"===t.kind?void 0:t.thread},i=await crypto.subtle.digest("SHA-256",n(o(r)));return e(new Uint8Array(i))}var Y=class{constructor(e){this.doc=e}ops=new Map;clock=0;createAt=new Map;threadAt=new Map;get size(){return this.ops.size}all(){return[...this.ops.values()]}threads(){return function(e){let t=new Map,n=new Map,o=new Map;for(let{body:r}of[...e].sort(W)){if(r.name&&o.set(r.author,r.name),"create"===r.kind){if(t.has(r.id)||!r.anchor||void 0===r.text)continue;let e=U(r.id,r.author,r.name,r.text,r.at,r.mentions);t.set(r.id,{id:r.id,anchor:r.anchor,root:e,resolved:!1}),n.set(r.id,{comment:e,thread:r.id});continue}let e=t.get(r.thread);if(!e)continue;if("resolve"===r.kind||"reopen"===r.kind){e.resolved="resolve"===r.kind,"reopen"===r.kind&&delete e.addressed;continue}if("addressed"===r.kind){void 0!==r.text&&(e.addressed={text:r.text,author:r.author,name:r.name,at:r.at});continue}let i=r.target?n.get(r.target):void 0;if(i&&i.thread===r.thread){if("reply"===r.kind){if(n.has(r.id)||void 0===r.text)continue;let t=U(r.id,r.author,r.name,r.text,r.at,r.mentions);e.root.replies.push(t),n.set(r.id,{comment:t,thread:r.thread});continue}if("seen"===r.kind){let e=i.comment.seenBy??=[];e.includes(r.author)||e.push(r.author);continue}if("react"===r.kind||"unreact"===r.kind){if(void 0===r.text||i.comment.deleted)continue;let e=i.comment.reactions,t=e.find(e=>e.emoji===r.text);if("react"===r.kind){let n={author:r.author,name:r.name};t?t.by.some(e=>e.author===r.author)||t.by.push(n):e.length<12&&e.push({emoji:r.text,by:[n]})}else t&&(t.by=t.by.filter(e=>e.author!==r.author),t.by.length||e.splice(e.indexOf(t),1));continue}r.author!==i.comment.author||i.comment.deleted||("edit"===r.kind&&void 0!==r.text&&(i.comment.text=r.text,i.comment.edited=!0,r.mentions?i.comment.mentions=r.mentions:delete i.comment.mentions),"delete"===r.kind&&(i.comment.text="",i.comment.deleted=!0,i.comment.reactions=[],delete i.comment.mentions))}}for(let{comment:e}of n.values()){e.name||(e.unnamed=!0,e.name=o.get(e.author)??"");for(let t of e.reactions)for(let e of t.by)e.name||=o.get(e.author)??""}let r=new Map,i=(e,t)=>{let n=k({author:e,name:t}).toLowerCase();(r.get(n)??r.set(n,new Set).get(n)).add(e)};for(let{comment:e}of n.values()){i(e.author,e.name);for(let t of e.reactions)for(let e of t.by)i(e.author,e.name)}let a=(e,t)=>(r.get(k({author:e,name:t}).toLowerCase())?.size??0)>1;for(let{comment:e}of n.values()){a(e.author,e.name)&&(e.alike=!0);for(let t of e.reactions)for(let e of t.by)a(e.author,e.name)&&(e.alike=!0)}return[...t.values()]}(this.ops.values())}async add(e){let t=[];for(let n of e){if(!j(n)||n.body.doc!==this.doc||this.ops.has(n.body.id)||n.body.id!==await K(n.body)||!await H(n))continue;let e={body:n.body,sig:n.sig};this.ops.set(e.body.id,e),this.clock=Math.max(this.clock,e.body.clock),"create"===e.body.kind&&this.createAt.set(e.body.author,Math.max(this.createAt.get(e.body.author)??0,e.body.at)),this.threadAt.set(e.body.thread,Math.max(this.threadAt.get(e.body.thread)??0,e.body.at)),t.push(e)}return t}async append(e,t,n){let o={v:1,...n,id:"",thread:"create"===n.kind?"":n.thread,doc:this.doc,author:e.publicKey,name:t,clock:Math.min(this.clock+1,S),at:Math.min(Math.max(Date.now(),"create"===n.kind?(this.createAt.get(e.publicKey)??0)+1:(this.threadAt.get(n.thread)??0)+1),L)};o.id=await K(o);let r=this.ops.get(o.id);if(r)return r;"create"===o.kind&&(o.thread=o.id);let[i]=await this.add([await D(o,e)]);if(!i)throw new Error("pipeup: could not record this change");return i}},V=/^([A-Za-z0-9_-]{16}):([A-Za-z0-9_-]{43})$/;function _(){return`${function(t=16){return e(crypto.getRandomValues(new Uint8Array(t)))}(12)}:${e(crypto.getRandomValues(new Uint8Array(32)))}`}async function G(e){let n=V.exec(e.trim()),o=n?.[1],r=n?.[2];if(!o||!r)throw new Error('pipeup: data-pipeup-doc must look like "<id>:<key>", as made by newDocumentAttribute()');return{id:o,key:await crypto.subtle.importKey("raw",t(r),{name:"AES-GCM"},!1,["encrypt","decrypt"])}}async function Z(t,o,r){let i=crypto.getRandomValues(new Uint8Array(12)),a=await crypto.subtle.encrypt({name:"AES-GCM",iv:i,additionalData:n(r)},t,n(o));return{iv:e(i),data:e(new Uint8Array(a))}}var J=e=>`pipeup-file:${e}`;var X=/^[a-z][a-z0-9-]{1,23}\/[a-z][a-z0-9-]{0,31}$/,Q=class extends Error{constructor(e,t,n=1){super("pipeup: shown here, but not saved yet"),this.id=e,this.cause=t,this.count=n,this.name="UnsavedChangeError"}},ee=class e{constructor(e,t){this.log=e,this.options=t,this.displayName=t.name.trim()?oe(t.name):""}listeners=new Set;cache=[];comments=new Map;displayName;de=Promise.resolve();unsaved=[];static async open(t){if("string"!=typeof t.doc||""===t.doc||t.doc.length>64)throw new Error("pipeup: the document id must be 1 to 64 characters");let n=new Y(t.doc),o=await t.store.load(t.doc),r=o.length-(await n.add(o)).length;r&&console.warn(`pipeup: ${r} saved change${1===r?"":"s"} on this page couldn't be read; kept as saved`);let i=new e(n,t);return i.refresh(!1),i}get id(){return this.options.doc}get me(){return this.options.identity.publicKey}get name(){return this.displayName}set name(e){this.displayName=oe(e),this.refresh(!0,[],"")}threads(){return this.cache}ops(){return this.log.all()}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}comment(e,t,n){return this.enqueue(()=>this.write({kind:"create",anchor:e,text:te(t),...n?.length?{mentions:n}:{}}))}reply(e,t,n){return this.enqueue(()=>this.write({kind:"reply",thread:this.find(e).thread,target:e,text:te(t),...n?.length?{mentions:n}:{}}))}edit(e,t,n){return this.enqueue(async()=>{let{thread:o}=this.mine(e);await this.write({kind:"edit",thread:o,target:e,text:te(t),...n?.length?{mentions:n}:{}})})}remove(e){return this.enqueue(async()=>{let{thread:t}=this.mine(e);await this.write({kind:"delete",thread:t,target:e})})}contact(e){let t=e.trim();return T.test(t)?this.enqueue(async()=>{await this.write({kind:"contact",thread:this.me,text:t})}):Promise.reject(new Error("pipeup: that isn't an email address or a GitHub name"))}uncontact(){return this.enqueue(async()=>{await this.write({kind:"uncontact",thread:this.me})})}contacts(){let e=new Map;for(let{body:t}of[...this.log.all()].sort(W))"contact"===t.kind&&t.text?e.set(t.author,t.text):"uncontact"===t.kind&&e.delete(t.author);return e}get portable(){return this.options.identity.privateKey.extractable}identityCode(){return async function(e){if(!e.privateKey.extractable)return null;let n=await crypto.subtle.exportKey("jwk",e.privateKey);return n.d?f(t(n.d)):null}(this.options.identity)}seen(e){return this.enqueue(async()=>{for(let t of e){let e=this.comments.get(t);e&&!e.comment.seenBy?.includes(this.me)&&await this.write({kind:"seen",thread:e.thread,target:t})}})}react(e,t){return this.enqueue(async()=>{await this.write({kind:"react",thread:this.find(e).thread,target:e,text:ne(t)})})}unreact(e,t){return this.enqueue(async()=>{await this.write({kind:"unreact",thread:this.find(e).thread,target:e,text:ne(t)})})}resolve(e){return this.enqueue(async()=>{await this.write({kind:"resolve",thread:this.thread(e)})})}reopen(e){return this.enqueue(async()=>{await this.write({kind:"reopen",thread:this.thread(e)})})}sign(e,t){if(!X.test(e))throw new Error('pipeup: a signing purpose looks like "<add-on id>/<name>"');return d(this.options.identity,n(`pipeup:${e}\n${t}`))}flush(){return this.enqueue(()=>this.persist())}exportFile(){return async function(e,t,n){let o=n?{pipeup:1,doc:e,sealed:!0,...await Z(n,JSON.stringify(t),J(e))}:{pipeup:1,doc:e,sealed:!1,ops:t};return JSON.stringify(o,null,2)}(this.options.doc,this.log.all(),this.options.key)}async importFile(e){return this.merge(await async function(e,o,r){if(e.length>5e6)throw new Error("pipeup: this feedback file is too large");let i,a,l;try{i=JSON.parse(e)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}if(!i||"object"!=typeof i||1!==i.pipeup||"string"!=typeof i.doc)throw new Error("pipeup: this is not an Pipeup feedback file");if(i.doc!==o)throw new Error("pipeup: this feedback is for a different document");if(!i.sealed)return Array.isArray(i.ops)?i.ops:[];if(!r)throw new Error("pipeup: this feedback is sealed, and this page has no document key");if("string"!=typeof i.iv||"string"!=typeof i.data)throw new Error("pipeup: this is not an Pipeup feedback file");try{a=await async function(e,o,r){try{let i=await crypto.subtle.decrypt({name:"AES-GCM",iv:t(o.iv),additionalData:n(r)},e,t(o.data));return(new TextDecoder).decode(i)}catch{throw new Error("pipeup: this feedback could not be opened with this document")}}(r,{iv:i.iv,data:i.data},J(o))}catch{throw new Error("pipeup: this feedback could not be opened with this document's key")}try{l=JSON.parse(a)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}return Array.isArray(l)?l:[]}(e,this.options.doc,this.options.key),"file")}merge(e,t){return e.length>5e3?Promise.reject(new RangeError("pipeup: too many changes to merge at once")):this.enqueue(async()=>{let n=await this.log.add([...e]);this.unsaved.push(...n),n.length>0&&this.refresh(!0,n,t);try{await this.persist()}catch(e){throw n.length>0?new Q(n[0].body.id,e,n.length):e}return n.length})}enqueue(e){let t=this.de.then(e);return this.de=t.catch(()=>{}),t}async write(e){let t=await this.log.append(this.options.identity,this.displayName,e);this.unsaved.push(t),this.refresh(!0,[t],"local");try{await this.persist()}catch(e){throw new Q(t.body.id,e)}return t.body.id}async persist(){if(0===this.unsaved.length)return;let e=[...this.unsaved];await this.options.store.append(this.options.doc,e),this.unsaved=this.unsaved.filter(t=>!e.includes(t))}refresh(e,t=[],n=""){this.cache=this.log.threads(),this.comments.clear();let o=(e,t)=>{e.unnamed&&e.author===this.me&&this.displayName&&(e.name=this.displayName),this.comments.set(e.id,{comment:e,thread:t});for(let n of e.replies)o(n,t)};for(let e of this.cache)o(e.root,e.id);if(e)for(let e of this.listeners)try{e(this.cache,t,n)}catch(e){globalThis.reportError?.(e)}}find(e){let t=this.comments.get(e);if(!t)throw new Error("pipeup: there is no comment with that id");return t}mine(e){let t=this.find(e);if(t.comment.author!==this.me)throw new Error("pipeup: only the writer can change a comment");return t}thread(e){if(!this.cache.some(t=>t.id===e))throw new Error("pipeup: there is no thread with that id");return e}};function te(e){let t=e.trim();if(!t)throw new Error("pipeup: a comment needs some words");if(t.length>1e4)throw new Error("pipeup: comments are limited to 10000 characters");return t}function ne(e){if(!z(e))throw new Error("pipeup: a reaction is one emoji");return e}function oe(e){let t=e.replace(/\s+/g," ").trim();if(!t||t.length>80)throw new Error("pipeup: choose a name of 1 to 80 characters");if($(t))throw new Error("pipeup: that name is kept for AI replies; choose another");return t}var re=class{docs=new Map;profile=null;async load(e){return[...this.docs.get(e)?.values()??[]]}async append(e,t){let n=this.docs.get(e);n||this.docs.set(e,n=new Map);for(let e of t)n.set(e.body.id,e)}async loadProfile(){return this.profile}async saveProfile(e){this.profile=e}async saveProfileIfAbsent(e){return this.profile||(this.profile=e),this.profile}},ie="";async function ae(e,t=""){let n=await e.loadProfile();if(n)return"Reviewer"===n.name?{...n,name:""}:n;let o={identity:await s(),name:t};return e.saveProfileIfAbsent(o)}var le=class e{constructor(e){this.db=e}static open(t="pipeup"){return new Promise((n,o)=>{let r=indexedDB.open(t,1);r.onupgradeneeded=()=>{let e=r.result;e.createObjectStore("ops",{keyPath:["doc","id"]}).createIndex("doc","doc"),e.createObjectStore("meta")},r.onsuccess=()=>{let t=r.result;t.onversionchange=()=>t.close(),n(new e(t))},r.onerror=()=>o(r.error??new Error("pipeup: could not open local storage"))})}close(){this.db.close()}async load(e){return(await this.request("ops","readonly",t=>t.index("doc").getAll(e))).map(e=>e.op)}async append(e,t){if(0===t.length)return;let n=this.db.transaction("ops","readwrite"),o=n.objectStore("ops"),r=se(n);try{for(let n of t)o.put({doc:e,id:n.body.id,op:n})}catch(e){throw n.abort(),r.catch(()=>{}),e}await r}async loadProfile(){return await this.request("meta","readonly",e=>e.get("profile"))??null}async saveProfile(e){await this.request("meta","readwrite",t=>t.put(e,"profile"))}async saveProfileIfAbsent(e){let t=this.db.transaction("meta","readwrite"),n=t.objectStore("meta"),o=se(t),r=e,i=n.get("profile");return i.onsuccess=()=>{i.result?r=i.result:n.put(e,"profile")},await o,r}request(e,t,n){return new Promise((o,r)=>{let i=n(this.db.transaction(e,t).objectStore(e));i.onsuccess=()=>o(i.result),i.onerror=()=>r(i.error??new Error("pipeup: local storage request failed"))})}};function se(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 de(e){let t=(e.ownerDocument??e).createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[],o="";for(let e=t.nextNode();e;e=t.nextNode())n.push({node:e,start:o.length}),o+=e.data;return{text:o,nodes:n}}function ce(e,t,n){let o=(e.ownerDocument??e).createRange();return o.setStart(e,0),o.setEnd(t,n),o.toString().length}function pe(e,t,n){let o=ue(e,t,!1),r=ue(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 ue(e,t,n){let o=e.nodes.find(e=>t>=e.start&&t<e.start+e.node.data.length+Number(n));return o&&{node:o.node,offset:t-o.start}}function he(e){return e.nodeType===Node.ELEMENT_NODE?e:e.parentElement}function fe(e,t){for(let n=he(e)?.closest("[data-pipeup-id]")??null;n;){if(!t.contains(n))return null;let e=n.getAttribute("data-pipeup-id")??"";if(""!==e&&e.length<=200)return n;n=n.parentElement?.closest("[data-pipeup-id]")??null}return null}function me(e,t,n){return e.slice(t,n).replace(/^[\uDC00-\uDFFF]|[\uD800-\uDBFF]$/g,"")}function ge(e,t){let n=function(e,t){if(e===t)return"";let n=[];for(let o=t;o&&o!==e;o=o.parentElement){let e=1;for(let t=o.previousElementSibling;t;t=t.previousElementSibling)t.tagName===o.tagName&&e++;n.unshift(`${o.tagName.toLowerCase()}:nth-of-type(${e})`)}return":scope > "+n.join(" > ")}(e,t);if(n.length>2e3)throw new Error("pipeup: this element is nested too deeply to comment on — give a nearby container a data-pipeup-id");return n}function ve(e){if(!B(e))throw new Error("pipeup: could not describe this place on the page");return e}function we(e,t){let n=he(e),o=n?.closest("p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,pre,figcaption,dt,dd,summary,caption")??null;return o&&t.contains(o)?o:n&&t.contains(n)?n:t}function ye(e,t,n){if(!t.contains(e.commonAncestorContainer))throw new Error("pipeup: the selection is outside the commentable area");let o=fe(e.commonAncestorContainer,t),a=o??t,{text:l}=de(a),s=ce(a,e.startContainer,e.startOffset),d=ce(a,e.endContainer,e.endOffset),c=l.slice(s,d);if(""===c)throw new Error("pipeup: select some text to comment on");if(c.length>C)throw new Error("pipeup: selections are limited to 10000 characters");let p=me(l,Math.max(0,s-32),s),u=me(l,d,d+32);return ve({...o?{id:o.getAttribute("data-pipeup-id")??""}:{},path:"",quote:{exact:c,prefix:p,suffix:u},...n?{view:n}:{},fingerprint:i(we(e.startContainer,t).textContent??""),snapshot:me(r(p+c+u),0,200)})}function be(e,t,n,o){let a=fe(e,t);return ve({...a?{id:a.getAttribute("data-pipeup-id")??""}:{},path:ge(a??t,e),...n?{point:{x:xe(n.x),y:xe(n.y)}}:{},...o?{view:o}:{},fingerprint:i(e.textContent??""),snapshot:me(r(e.textContent??""),0,200)})}function xe(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function ke(e,t,n){let o=Array.from({length:t.length+1},(e,t)=>t),r=[...o],i=[t.length];for(let a=1;a<=e.length;a++){r[0]=n?0:a;for(let n=1;n<=t.length;n++){let i=e.charCodeAt(a-1)===t.charCodeAt(n-1)?0:1;r[n]=Math.min(o[n]+1,r[n-1]+1,o[n-1]+i)}i.push(r[t.length]),[o,r]=[r,o]}return i}var Ee=(e,t)=>ke(e,t,!1).pop(),$e={state:"orphaned",element:null,range:null};function Se(e,t,n={}){let o=e.id?function(e,t){for(let n of e.querySelectorAll("[data-pipeup-id]"))if(n.getAttribute("data-pipeup-id")===t)return n;return null}(t,e.id):t;return e.quote?function(e,t,n,o,r){let a=n??o,l=de(a),s=function(e,t){if(!t.exact)return-1;let n=-1,o=-1;for(let r=e.indexOf(t.exact);-1!==r;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),l=Ce(i,t.prefix)+Le(a,t.suffix);l>o&&(n=r,o=l)}return n}(l.text,t);if(s>=0){let r=pe(l,s,s+t.exact.length);if(r){let t=we(r.startContainer,o);return{state:null!==n&&i(t.textContent??"")===e.fingerprint?"attached":"moved",element:t,range:r}}}if(r){let e=a===o?l:de(o);if(e.text.length<=5e4&&t.exact.length>=12&&t.exact.length<=300){let n=function(e,t,n){let o=t.length;if(0===o)return null;let r=-1,i=1/0;if(ke(e,t,!0).forEach((e,t)=>{t&&e<i&&(i=e,r=t)}),i>n)return null;let a=Math.max(0,r-o),l=1/0;for(let i=Math.max(0,r-o-n);i<=Math.min(r,r-o+n);i++){let n=Ee(e.slice(i,r),t);n<l&&(l=n,a=i)}return{start:a,end:r,distance:l}}(e.text,t.exact,Math.floor(t.exact.length/4)),r=n?pe(e,n.start,n.end):null;if(r)return{state:"moved",element:we(r.startContainer,o),range:r}}}return $e}(e,e.quote,o,t,!1!==n.fuzzy):function(e,t){if(!t)return $e;let n=t;if(e.path){if(!e.path.startsWith(":scope > "))return $e;try{n=t.querySelector(e.path)}catch{return $e}}return n?{state:i(n.textContent??"")===e.fingerprint?"attached":"moved",element:n,range:null}:$e}(e,o)}function Le(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function Ce(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 Me={A:"Link",BUTTON:"Button",P:"Paragraph",LI:"List item",IMG:"Image",TABLE:"Table",TD:"Cell",TH:"Cell",FIGURE:"Figure",SVG:"Graphic",CANVAS:"Graphic",LABEL:"Label",INPUT:"Field",SELECT:"Field",TEXTAREA:"Field",SUMMARY:"Question",BLOCKQUOTE:"Quote",SECTION:"Section",H1:"Heading",H2:"Heading",H3:"Heading",H4:"Heading",H5:"Heading",H6:"Heading"};function Ae(e){return e.getAttribute("data-pipeup-label")||Me[e.tagName.toUpperCase()]||"Block"}function Te(e){return Re(r(e.getAttribute("aria-label")??e.getAttribute("alt")??e.innerText??e.textContent??""),40)}function Pe(e){let t=e.getAttribute("data-pipeup-label");if(t)return t;let n=Te(e);return n?`${Ae(e)} · ${n}`:Ae(e)}function qe(e,t,n){let o=e.id??null,i=e.quote?.exact??null,a=e.point?`${Math.round(100*e.point.x)}% across, ${Math.round(100*e.point.y)}% down the element`:null,l=t.element;if("orphaned"===t.state||!l)return{where:`No longer on the page (it read: "${e.snapshot}")`,element:null,id:o,quote:i,pin:a};let s=[],d=e.view?.slide;if(d){let e=l.closest("[data-pipeup-slide]")?.querySelector("h1,h2,h3")?.textContent;s.push(`Slide ${d}`+(e?` "${Re(r(e))}"`:""))}else{let t=Ne(e.view);t&&s.push(t);let o=function(e,t){let n=null;for(let o of t.querySelectorAll("h1,h2,h3")){if(o===e||o.contains(e))break;if(!(4&o.compareDocumentPosition(e)))break;n=o}return n}(l,n);o&&s.push(`Section "${Re(r(o.textContent??""))}"`)}let c=Pe(l);return s.push(c),{where:s.join(" › "),element:c,id:o,quote:i,pin:a}}function Ne(e){return e?e.label||Object.entries(e).filter(([e,t])=>t&&"slide"!==e).map(([,e])=>e).join(" · "):""}function Re(e,t=60){return e.length>t?e.slice(0,t-1)+"…":e}var ze="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. Answer in the thread (the Pipeup skill says how) and mark it addressed; never resolve it, the author does.";function De(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 Oe(e,t,n,o){return"ai"===t?je(e,"## Comment thread",o,n):He(e)}function Fe(e,t,n){let o=n.all?e:e.filter(e=>!e.thread.resolved);if("text"===t)return o.map(He).join("\n");let r=n.all?0:e.length-o.length,i=[`# Review comments: ${Be(n.title)}`,"",`- **Page:** ${Be(n.url)}`,`- **Exported:** ${n.exportedAt.toISOString()}`,`- **Open threads:** ${e.length-e.filter(e=>e.thread.resolved).length}${r?` (${r} resolved, not included)`:n.all?" (resolved ones included)":""}`,"",ze,"",""].join("\n"),a=n.exportedAt.getTime();return i+o.map((e,t)=>je(e,`## Thread ${t+1}`,a)).join("\n")}function Ie(e){return e.reactions.map(e=>`${e.emoji} ${e.by.length} (${e.by.map(e=>Be(k(e))).join(", ")})`).join(" · ")}function Be(e){return e.replace(/\s+/g," ").trim()}function je(e,t,n,o){let{thread:r,location:i}=e,a=r.root.replies.length,l=[`${t} · ${r.resolved?"resolved":r.addressed?"open, addressed":"open"}`];if(l.push(`- **Thread:** ${r.id}`),o&&l.push(`- **Page:** ${Be(o)}`),l.push(`- **Where:** ${Be(i.where)}`),i.id){let e=Be(i.id.replace(/`/g,""));l.push(`- **Element:** \`[data-pipeup-id="${e}"]\`${i.element?` (${Be(i.element)})`:""}`)}i.quote&&l.push(`- **Quoted text:** "${Be(i.quote)}"`),i.pin&&l.push(`- **Pin:** ${Be(i.pin)}`),r.addressed&&!r.resolved&&l.push(`- **Addressed:** ${Be(r.addressed.text)} (${Be(k(r.addressed))}, ${De(r.addressed.at,n)})`),l.push(`- **Started by:** ${Be(k(r.root))}, ${De(r.root.at,n)}${a?` · ${a} ${1===a?"reply":"replies"}`:""}`,"",`**${Be(k(r.root))}** (${De(r.root.at,n)}): ${We(r.root," ")}`),r.root.reactions.length&&l.push(`Reactions: ${Ie(r.root)}`);for(let e of r.root.replies)l.push(`- **${Be(k(e))}** (${De(e.at,n)}): ${We(e," ")} \x3c!-- comment:${e.id} --\x3e`),e.reactions.length&&l.push(` - Reactions: ${Ie(e)}`);return l.join("\n")+"\n"}function He(e){let{thread:t,location:n}=e,o=[Be(n.where)+(n.quote?`, on the text "${Be(n.quote)}"`:""),`${Be(k(t.root))}: ${We(t.root," ")}`];t.root.reactions.length&&o.push(` Reactions: ${Ie(t.root)}`);for(let e of t.root.replies)o.push(` ${Be(k(e))}: ${We(e," ")}`),e.reactions.length&&o.push(` Reactions: ${Ie(e)}`);return o.join("\n")+"\n"}function We(e,t){return e.deleted?"(deleted)":e.text.replace(/\r\n|\r|\n/g,"\n"+t)+(e.edited?" (edited)":"")}var Ue="0.7.0-beta.1",Ke="2026-10-13",Ye=new Map,Ve=new Map,_e=new Map,Ge={},Ze=e=>`${Ye.get(e)??""}|${Ve.get(e)??""}`;function Je(e,t={},...n){let o=document.createElement(e);for(let[e,n]of Object.entries(t))void 0===n||!1===n||("class"===e?o.className=String(n):o.setAttribute(e,!0===n?"":n));for(let e of n)null!=e&&!1!==e&&o.append(e);return o}function Xe(e,t){let n=e.getRootNode().activeElement;t&&n instanceof HTMLElement&&e.contains(n)&&n.blur(),e.inert=t}function Qe(e,t,n=null){let o=e.getRootNode().activeElement,r=!1;for(let o=t.length;o--;n=t[o])t[o].nextSibling!==n&&(r=!!e.insertBefore(t[o],n));return r&&o&&t.some(e=>e.contains(o))&&o.focus({preventScroll:!0}),r}var et=()=>{let e=window.getSelection();return e&&!e.isCollapsed&&e.toString().trim()?e:null};function tt(e,t){return e.length>t?e.slice(0,t-1)+"…":e}function nt(e,t,n=4){e.style.left=t.left-n+"px",e.style.top=t.top-n+"px",e.style.width=`${t.width+2*n}px`,e.style.height=`${t.height+2*n}px`}var ot=/\bhttps?:\/\/[^\s<>"'`]+/gi,rt=/[\u202A-\u202E\u2066-\u2069]/;function it(e){let t=0,n=0;for(let o of e)"("===o?t++:")"===o&&n++;let o=e.length;for(;o>0;){let r=e[o-1];if(")"===r&&n>t)n--;else if(!".,;:!?'\"]}".includes(r))break;o--}return e.slice(0,o)}function at(e){let t=[],n=0;for(let o of e.matchAll(ot)){if(o[0].length>2048||rt.test(o[0]))continue;let r,i=it(o[0]),a=o.index??0;try{let e=new URL(i);if("http:"!==e.protocol&&"https:"!==e.protocol)continue;r=e.href}catch{continue}a>n&&t.push(e.slice(n,a));let l=Je("a",{href:r,target:"_blank",rel:"noopener noreferrer"},i);l.addEventListener("click",e=>e.stopPropagation()),t.push(l),n=a+i.length}return n<e.length&&t.push(e.slice(n)),t}var lt="http://www.w3.org/2000/svg",st={comment:["M20.5 11.5a8 8 0 0 1-11.7 7.1L4 19.8l1.2-4.4A8 8 0 1 1 20.5 11.5z","M12.3 8.2v6.6M9 11.5h6.6"],send:["M21 12L3.5 4.5 6.2 12l-2.7 7.5zM6.2 12H13"],copy:["M10 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-8a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2z","M16 8V6a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h2"],resolve:["M5 12.5l4.5 4.5L19 7.5"],reopen:["M3 12a9 9 0 1 0 3-6.7","M3 4v5h5"],lines:["M4 7h16M4 12h10M4 17h7"],list:["M3 6.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M3 12a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M3 17.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0M9 6.5h11M9 12h11M9 17.5h7"],expand:["M14 4h6v6M20 4l-6 6M10 20H4v-6M4 20l6-6M20 14v6h-6M20 20l-6-6M4 10V4h6M4 4l6 6"],pin:["M6 18v-6a6 6 0 1 1 6 6z"],shrink:["M20 10h-6V4M14 10l6-6M4 14h6v6M10 14l-6 6M14 20v-6h6M14 14l6 6M10 4v6H4M10 10L4 4"],bubble:["M20.5 11.5a8 8 0 0 1-11.7 7.1L4 19.8l1.2-4.4A8 8 0 1 1 20.5 11.5z"],close:["M6 6l12 12M18 6L6 18"],smile:["M12 3a9 9 0 1 0 0 18a9 9 0 0 0 0-18z","M8.5 14a4.5 4.5 0 0 0 7 0","M9 9.6h.01M15 9.6h.01"],edit:["M4 20h4L19 9l-4-4L4 16z"],look:["M12 3a9 9 0 1 0 0 18a9 9 0 0 0 0-18z","M12 3v18"]};function dt(e,t=15,n){let o=ct(st[e],t);return n&&o.setAttribute("stroke-width",String(n)),o}function ct(e,t){let n=document.createElementNS(lt,"svg"),o={width:String(t),height:String(t),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"};for(let[e,t]of Object.entries(o))n.setAttribute(e,t);for(let t of e){let e=document.createElementNS(lt,"path");e.setAttribute("d",t),n.append(e)}return n}var pt=(e,t,n)=>`M${e} ${t}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 -${2*n} 0`,ut={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${pt(7.4,11.5,1.9)}${pt(12.8,11.5,1.9)}M11.3 14.6l.7 1 .7-1`,Bear:`${pt(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:`${pt(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 ht(e){let t=/[\p{L}\p{N}]/u.exec(e);if(!t)return"";let n=t[0].toUpperCase();return 1===[...n].length?n:t[0]}var ft=(e,t)=>ht(t)||x(e);function mt(e,t){return $(t)?Je("span",{class:"av ai","data-pipeup-ai":"","aria-hidden":"true"},"AI"):Je("span",{class:`av c${b(e)}`,"aria-hidden":"true","data-animal":x(e)},ht(t)||ct([ut[g[y(e)]]],24))}function gt(e,t){setTimeout(()=>{e.remove(),t?.()},320)}function vt(e){return requestAnimationFrame(()=>{e.offsetWidth,e.classList.add("in")}),e}var wt=/^[A-Za-z0-9_-]{43}$/,yt=/^(?:host|gh):[A-Za-z0-9._@-]{1,64}$/,bt=[],xt=new Set;function kt(e){bt=e.filter(e=>e&&"string"==typeof e.name&&e.name.trim()&&yt.test(e.ref)).slice(0,500).map(e=>({ref:e.ref,name:e.name.trim().slice(0,80),...e.agent?{agent:!0}:{}}));for(let e of[...xt])e()}function Et(e,t){let n=new Map,o=e=>{e.ref!==t&&!n.has(e.ref)&&n.set(e.ref,e)},r=e=>o({ref:e.author,name:k(e),...$(e.name)?{agent:!0}:{}});for(let t of e)for(let e of[t.root,...t.root.replies])if(!e.deleted){r(e);for(let t of e.reactions)for(let e of t.by)r({...e})}for(let e of(document.documentElement.getAttribute("data-pipeup-agents")??"").split(/[\s,]+/).filter(e=>wt.test(e)))o({ref:e,name:"AI agent",agent:!0});for(let e of bt)o(e);return[...n.values()].sort((e,t)=>e.name.localeCompare(t.name))}var $t=(e,t)=>!!e.mentions?.some(e=>t.includes(e.ref)),St=[],Lt=e=>[e,...St],Ct=(e,t)=>[e.root,...e.root.replies].some(e=>e.author!==t&&!e.deleted&&$t(e,Lt(t))),Mt=null,At=e=>{Mt=e},Tt="pu-source";function Pt(e){let t=Je("textarea",{class:"input",rows:"1","aria-label":e.label}),n=Je("button",{class:"send",type:"button","aria-label":"Send",title:"Send",inert:!0},dt("send")),o=Je("span",{class:"tools"});o.hidden=!0;let r=Je("div",{class:"row"},e.before,t,o,n),i=e.kind??"comment",a=!1,l=new Set,s=()=>{for(let e of[...l])e()},d=()=>{let e=""!==t.value.trim();n.classList.toggle("show",e),n.inert=!e,t.style.height="auto",t.style.height=`${Math.max(27,t.scrollHeight)}px`},c=()=>{let e=-1,n=0,o=(o,r)=>{e<0&&(e=t.selectionStart,n=0);let i=t.value.slice(0,e),a=o&&i&&!/\s$/.test(i)&&!/^\s/.test(o)?" ":"";t.setRangeText(a+o,e,e+n,"end"),n=a.length+o.length,r&&(e=-1),d()};return{update:e=>o(e,!1),commit:e=>o(e,!0),cancel:()=>{e>=0&&n&&t.setRangeText("",e,e+n,"end"),e=-1,n=0,d()}}},p=new Map,u=()=>{let n=(Mt?.tools()??[]).filter(e=>!1!==e.available?.());for(let[e,t]of p)n.some(t=>t.id===e)||(t.remove(),p.delete(e));for(let a of n){if(p.has(a.id))continue;let n=Je("button",{class:"ib tool",type:"button","aria-label":a.label,title:a.label,"aria-pressed":"false"},ct(a.icon,15));n.addEventListener("mousedown",e=>e.preventDefault()),n.addEventListener("click",o=>{o.stopPropagation();try{a.press({kind:i,thread:e.thread?.()??null,text:()=>t.value,focus:()=>t.focus({preventScroll:!0}),connected:()=>r.isConnected,setPressed:e=>n.setAttribute("aria-pressed",String(e)),dictate:c,onEnd:e=>(l.add(e),()=>l.delete(e))})}catch(e){globalThis.reportError?.(e)}}),p.set(a.id,n),o.append(n)}o.hidden=0===p.size};u(),r.addEventListener(Tt,u);let h=[],f=Je("ul",{class:"mnl",role:"listbox","aria-label":"People"}),m=Je("span",{class:"mn-sr","aria-live":"polite"}),g=`mn-${Math.random().toString(36).slice(2,8)}`;f.id=g;let v=[],w=0,y=null;e.people&&(t.setAttribute("aria-autocomplete","list"),t.setAttribute("aria-haspopup","listbox"),t.setAttribute("aria-controls",g),r.append(f,m));let b=()=>{v=[],f.classList.remove("show"),t.removeAttribute("aria-activedescendant"),window.setTimeout(()=>!v.length&&f.replaceChildren(),220)},x=()=>{for(let[e,n]of[...f.children].entries()){let o=e===w;n.setAttribute("aria-selected",String(o)),n.classList.toggle("on",o),o&&t.setAttribute("aria-activedescendant",n.id)}},k=e=>{let n=v[e];if(!n||!y)return;let o=t.selectionStart;t.setRangeText(`@${n.name} `,y.start,o,"end"),h.push({label:n.name,ref:n.ref}),b(),d()},E=async()=>{let o=t.value.trim();if(o&&!a){a=!0;try{await e.U(o,h.length?function(e,t){let n=[];for(let o of t){let t=`@${o.label}`,r=0;for(;;){let i=e.indexOf(t,r);if(i<0)break;let a=i+t.length;if((0===i||/\s/.test(e[i-1]))&&(a===e.length||!/[\p{L}\p{N}_]/u.test(e[a]))&&!n.some(e=>i<e.end&&a>e.start)){n.push({start:i,end:a,ref:o.ref});break}r=i+1}}return n.sort((e,t)=>e.start-t.start).slice(0,20)}(o,h):[]),n.matches(":focus")&&t.focus(),t.value="",h.length=0,b(),d(),s()}catch{}finally{a=!1}}};return r.addEventListener("mousedown",e=>{e.target===t||n.contains(e.target)||o.contains(e.target)||(e.preventDefault(),t.focus({preventScroll:!0}),t.setSelectionRange(t.value.length,t.value.length))}),t.addEventListener("input",()=>{d(),e.people&&(()=>{if(y=t.selectionStart===t.selectionEnd?function(e){let t=/(^|\s)@([^\s@]*(?:\s[^\s@]*)?)$/.exec(e);return t?{start:t.index+t[1].length,query:t[2]}:null}(t.value.slice(0,t.selectionStart)):null,v=y&&e.people?function(e,t){let n=t.trim().toLowerCase(),o=e.filter(e=>e.name.toLowerCase().startsWith(n)),r=n?e.filter(e=>!o.includes(e)&&e.name.toLowerCase().includes(n)):[];return[...o,...r].slice(0,8)}(e.people(),y.query):[],!v.length)return b();w=Math.min(w,v.length-1),f.replaceChildren(...v.map((e,t)=>{let n=Je("li",{role:"option",id:`${g}-${t}`,class:e.agent?"agent":""},Je("span",{},e.name),e.agent?Je("small",{},"AI agent"):null);return n.addEventListener("mousedown",e=>{e.preventDefault(),k(t)}),n})),f.classList.add("show"),m.textContent=`${v.length} ${1===v.length?"person":"people"}`,x()})()}),t.addEventListener("blur",()=>v.length&&b()),t.addEventListener("keydown",n=>{if(n.stopPropagation(),v.length&&!n.isComposing){if("ArrowDown"===n.key||"ArrowUp"===n.key)return n.preventDefault(),w=(w+("ArrowDown"===n.key?1:v.length-1))%v.length,x();if("Enter"===n.key||"Tab"===n.key)return n.preventDefault(),k(w);if("Escape"===n.key)return n.preventDefault(),b()}"Enter"!==n.key||n.shiftKey||n.isComposing?"Escape"===n.key&&(n.preventDefault(),t.value="",d(),t.blur(),s(),e._?.()):(n.preventDefault(),E())}),n.addEventListener("click",e=>{e.stopPropagation(),E()}),{element:r,input:t,focus:()=>t.focus({preventScroll:!0})}}var qt=1,Nt=["sync","menu","notify","note","composer","panel","styles","status","overlay","here","sign","listnote","reactions"],Rt=/^[a-z][a-z0-9-]{1,23}$/,zt=new Set(["local","file","page","user","pipeup","presence","sync"]),Dt=class{constructor(e,t,n){this.ctx=e,this.shadow=t,this.after=n,At({tools:()=>this.K,note:()=>[...this.X.values()].at(-1)??null})}G=0;I=[];X=new Map;writing=new Map;marked=new Map;paint=0;J=new Map;listNotes=new Map;picker=null;pickerOwner="";K=[];Z=new Set;R=new Set;z=new Set;j=new Map;T=new Map;W=new Map;remote={n:0,who:new Set};last=0;timer=0;pe="";subscribe(e){return this.z.add(e),()=>{this.z.delete(e)}}changed(e){e&&this.G++;for(let t of[...this.z])t(e);for(let e of this.ctx.t.querySelectorAll(".row, .draft"))e.dispatchEvent(new Event(Tt))}N(e,t){let n=this.W.get(e)??this.W.set(e,new Set).get(e),o=()=>{n.delete(o)&&t()};return n.add(o),o}ue(){return[...this.J.values()].map(e=>e.text).join(" · ")}Le(e,t){return this.I.push(t),this.changed(!0),{update:()=>this.changed(!1),remove:this.N(e,()=>{this.I.splice(this.I.indexOf(t),1),this.changed(!0)})}}setThread(e,t,n){let o=this.writing.get(e)??this.writing.set(e,new Set).get(e);null===n?(Ye.delete(t),o.delete(t)):(Ye.set(t,n),o.add(t)),this.repaint()}setMark(e,t,n,o){let r=this.marked.get(e)??this.marked.set(e,new Set).get(e);if(null===n){if(_e.delete(t),!Ve.delete(t))return;r.delete(t)}else{if(Ve.get(t)===n&&!!_e.get(t)==!!o)return;Ve.set(t,n),o?_e.set(t,o):_e.delete(t),r.add(t)}this.repaint()}repaint(){this.paint||(this.paint=window.requestAnimationFrame(()=>{this.paint=0,this.ctx.f()}))}Q(e,t,n){n?e.set(t,n):e.delete(t),this.changed(!1)}setPicker(e,t){t?(this.picker=t,this.pickerOwner=e):this.pickerOwner===e&&(this.picker=null,this.pickerOwner=""),this.changed(!1)}Me(e,t){return this.K.push(t),this.changed(!1),this.N(e,()=>{this.K.splice(this.K.indexOf(t),1),this.changed(!1)})}closed(){return this.ctx.state.hidden&&!this.ctx.state.s}Ce(e,t){this.closed()?this.T.set(e,t):this.ctx.ee(t)}flush(){if(this.closed()||0===this.T.size)return;let e=[...this.T.values()].at(-1);this.T.clear(),this.ctx.ee(e)}Pe(){return this.shadow.activeElement instanceof HTMLTextAreaElement||[...this.ctx.t.querySelectorAll("textarea")].some(e=>""!==e.value.trim())}$e(e){this.ctx.state.hidden||this.ctx.E(e)}Oe(e,t){if("local"!==t&&""!==t){for(let{body:t}of e)t.author===this.ctx.doc.me||"create"!==t.kind&&"reply"!==t.kind||(this.remote.n++,this.remote.who.add(t.name||x(t.author)));this.fe()}}fe(e=Math.max(0,this.last+1e4-Date.now())){this.timer||!this.remote.n||(this.timer=window.setTimeout(()=>{if(this.timer=0,this.ctx.state.hidden||this.Pe())return this.fe(1e3);let{n:e,who:t}=this.remote;this.remote={n:0,who:new Set},this.last=Date.now(),this.ctx.E(`${e} new comment${1===e?"":"s"} from ${1===t.size?[...t][0]:`${t.size} people`}`)},e))}Ie(e){let t=this.j.get(e);return t||(t=Je("div",{class:"ov","aria-hidden":"true","data-addon":e}),this.ctx.t.insertBefore(t,this.after.nextSibling),this.j.set(e,t)),t}Re(e,t){let n=this.ctx.host.ownerDocument.defaultView?.CSSStyleSheet,o=n&&"replaceSync"in n.prototype&&"adoptedStyleSheets"in this.shadow?new n:null;o&&(o.replaceSync(t),this.shadow.adoptedStyleSheets=[...this.shadow.adoptedStyleSheets,o]);let r=o??this.shadow.appendChild(Je("style",{},t));return this.N(e,()=>o?this.shadow.adoptedStyleSheets=this.shadow.adoptedStyleSheets.filter(e=>e!==o):r.remove())}he(e,t,n){return t.add(n),this.N(e,()=>t.delete(n))}Ne(e,t){return this.he(e,this.Z,t)}He(e,t){let n=this.he(e,this.R,t);return this.call(this.R,t,this.ge()),n}ge(){let{state:e}=this.ctx,t=this.shadow.activeElement;return{shown:!e.hidden,commentMode:e.c,allOpen:e.p,dark:this.ctx.t.classList.contains("dark"),view:this.ctx.u.view(),writing:t instanceof HTMLTextAreaElement?t.closest("[data-thread]")?.dataset.thread??"":null}}L(){for(let e of[...this.Z])this.call(this.Z,e);if(0===this.R.size)return;let e=this.ge(),t=JSON.stringify(e);if(t!==this.pe){this.pe=t;for(let t of[...this.R])this.call(this.R,t,e)}}call(e,t,...n){try{t(...n)}catch(n){e.delete(t),globalThis.reportError?.(n)}}De(e,t,n){let o=this.ctx.t,r=this.shadow.activeElement,i=Je("button",{class:"ib",type:"button","aria-label":"Close"},ct(["M6 6l12 12M18 6L6 18"],15)),a=Je("div",{class:"xp",role:"dialog","aria-label":n.label,"data-addon":e},Je("div",{class:"hd"},Je("span",{},n.label),i),Je("div",{class:"xb"},t)),l=[...o.children].filter(e=>e instanceof HTMLElement&&!e.inert);for(let e of l)e.inert=!0;o.append(a),a.offsetWidth,a.classList.add("show");let s=e=>{"Escape"===e.key&&(e.stopPropagation(),e.preventDefault(),d())},d=this.N(e,()=>{window.removeEventListener("keydown",s,!0);for(let e of l)e.inert=!1;a.classList.remove("show"),a.inert=!0,window.setTimeout(()=>a.remove(),300),r?.focus?.({preventScroll:!0});try{n.onClose?.()}catch(e){globalThis.reportError?.(e)}});return i.addEventListener("click",d),window.addEventListener("keydown",s,!0),(a.querySelector("button, input, textarea, select, a[href]")??a).focus?.({preventScroll:!0}),{close:d}}clear(e){for(let t of[...this.W.get(e)??[]])t();this.W.delete(e),this.j.get(e)?.remove(),this.j.delete(e);for(let t of[this.X,this.J,this.listNotes,this.T])t.delete(e);this.setPicker(e,null);for(let t of this.writing.get(e)??[])Ye.delete(t);this.writing.delete(e);for(let t of this.marked.get(e)??[])Ve.delete(t),_e.delete(t);this.marked.delete(e),this.repaint(),this.changed(!0)}destroy(){window.clearTimeout(this.timer),At(null),this.z.clear()}},Ot=new Map,Ft=null,It=(()=>{let e=globalThis.Pipeup;return e?.VERSION?e:null})();function Bt(){return It?It.addons():[...Ot.values()].map(e=>({...e.info}))}function jt(e){if(It)return It.use(e);let t=e=>console.warn(`pipeup: ${e}`),n=e;if(!n||"object"!=typeof n||"string"!=typeof n.id||!Rt.test(n.id)||zt.has(n.id)||"function"!=typeof n.setup||"string"!=typeof n.network?.says)return t("an add-on needs an id of 2 to 24 lowercase letters, digits and dashes (not a reserved one), a setup function and a network statement");if(Ot.has(n.id))return t(`the add-on "${n.id}" is already registered; the second is ignored`);let o={id:n.id,version:String(n.version??""),network:n.network,state:"waiting"},r=(n.needs??[]).find(e=>!Nt.includes(e));!function(e){let t=typeof document>"u"?null:document.documentElement.getAttribute("data-pipeup-addons");return null===t||t.toLowerCase().split(/[\s,]+/).includes(e)}(n.id)?(o.state="off",o.reason="this page doesn't allow it",t(`the add-on "${n.id}" is not in this page's data-pipeup-addons list, so it is off`)):1!==n.api?(o.state="off",o.reason=`needs add-on API ${String(n.api)}; this Pipeup has 1`):r&&(o.state="off",o.reason=`this Pipeup has no ${r} slot`);let i={addon:e,info:o};Ot.set(n.id,i),Ft?.i&&"waiting"===o.state&&Ht(i,Ft)}async function Ht(e,t){let n,o,{addon:r,info:i}=e,a=new AbortController,l=new Set,{surface:s,doc:d}=t,c=()=>!a.signal.aborted,p=Object.assign(()=>{},{update(){},remove(){},close(){}}),u=e=>(...t)=>c()?e(...t):p,h={id:d.id,me:d.me,get name(){return d.name},threads:()=>d.threads(),ops:()=>d.ops(),contacts:()=>d.contacts(),onChange:e=>{let t=d.onChange(e);return l.add(t),()=>{t(),l.delete(t)}}},f=r.id,m={api:1,version:t.version,document:h,root:t.root,ephemeral:t.ephemeral,signal:a.signal,has:e=>Nt.includes(e),off:e=>{o=String(e)},merge:e=>c()?d.merge(e,f):Promise.resolve(0),addMenuItem:u(e=>s.Le(f,e)),notify:u(e=>s.Ce(f,e)),announce:u(e=>s.$e(e)),setComposerNote:u(e=>s.Q(s.X,f,e)),setThreadNote:u((e,t)=>s.setThread(f,e,t)),setThreadMark:u((e,t,n)=>s.setMark(f,e,t,n)),addComposerTool:u(e=>s.Me(f,e)),openPanel:u((e,t)=>s.De(f,e,t)),addStyles:u(e=>s.Re(f,e)),setStatus:u(e=>s.Q(s.J,f,e)),setListNote:u(e=>s.Q(s.listNotes,f,e)),setReactionPicker:u(e=>s.setPicker(f,e)),overlay:()=>s.Ie(f),onFrame:u(e=>s.Ne(f,e)),where:e=>s.ctx.u.view(e),isHere:e=>s.ctx.u.m(e),go:e=>s.ctx.u.H(e),onUi:u(e=>s.He(f,e)),avatar:(e,t)=>{let n=mt(e,t);return n.classList.add("in"),n},sign:(e,t)=>d.sign(`${f}/${e}`,t)},g=()=>{if(c()){a.abort();for(let e of[...l])e();try{n?.()}catch(e){globalThis.reportError?.(e)}s.clear(f),"on"===i.state&&(i.state="waiting")}};e.stop=g;try{if(n=await r.setup(m),!c())return void n?.();if(void 0!==o)return g(),i.state="off",void(i.reason=o);i.state="on",delete i.reason}catch(e){i.state="failed",i.reason=function(e){return e instanceof Error?e.message:String(e)}(e),g(),i.state="failed",globalThis.reportError?.(e)}}var Wt=typeof navigator<"u"&&/Mac|iP(hone|ad|od)/.test(navigator.platform)?"⇧⌥C":"Shift+Alt+C",Ut="Shift+Alt+C";function Kt(e,t){let n=function(e){let t=Je("button",{class:"me",type:"button",tabindex:"-1","aria-hidden":"true"});t.addEventListener("mousedown",e=>e.preventDefault());let n=Pt({label:"Comment",kind:"comment",before:t,U:e.U,_:e._,people:e.people}),o=Je("div",{class:"note"}),r=()=>{let e=Mt?.note()??null;o.textContent=e??"",o.hidden=!e};r();let i=Je("div",{class:"say"}),a=Je("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"}),l=Je("div",{class:"nf"},a),s=Je("div",{class:"you"},i,l),d="",c=!1,p=()=>{let n=e.name(),o=n?"change":"add your name";if(t.title=n?"Change your name":"Add your name",!t.lastChild||d!==n){let o=mt(e.me,n),r=t.lastChild;r?(vt(o),gt(r)):o.classList.add("in"),t.append(o),d=n}let r=Je("button",{type:"button"},o);r.addEventListener("click",h),i.replaceChildren(Je("span",{class:"nm"},n||`You're ${x(e.me)}`)," · ",r)},u=e=>{s.classList.toggle("naming",e),Xe(i,e),Xe(l,!e)};function h(t){t.stopPropagation(),a.value=e.name(),u(!0),a.focus({preventScroll:!0}),a.select()}let f=()=>{u(!1),n.focus()};t.addEventListener("click",h),a.addEventListener("keydown",t=>{if(t.stopPropagation(),"Escape"===t.key)t.preventDefault(),f();else if("Enter"===t.key){t.preventDefault();let n=a.value.trim();if(!n||n===e.name())return f();if(c)return;c=!0,e.rename(n).finally(()=>{c=!1,p(),f()})}}),p(),u(!1);let m=Je("div",{class:"ctx"},e.label),g=Je("div",{class:"draft"},m,o,n.element,s);return g.addEventListener(Tt,r),{element:g,ve:()=>{let{selectionStart:e,selectionEnd:t}=n.input;return()=>{n.focus(),n.input.setSelectionRange(e,t)}},te:e=>{m.hidden=e},ye:e=>{m.textContent=e},focus:()=>n.focus(),Be:()=>""===n.input.value.trim()}}({label:t.label,me:e.doc.me,name:()=>e.s.name(),rename:t=>e.s.rename(t),U:(t,n)=>e.Fe(t,n),people:()=>e.people(),_:()=>e.qe()});return e.D(n),n}function Yt(e,t){if("orphaned"===t.state||!t.element||e.quote)return null;let n=t.element.getBoundingClientRect();if(!n.width&&!n.height)return null;if(e.point)return{x:n.left+e.point.x*n.width,y:n.top+e.point.y*n.height};let o=t.element.ownerDocument.createRange();o.selectNodeContents(t.element);let 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 Vt(e){return e.range?[...e.range.getClientRects()]:[]}function _t(e,t){let n=Vt(t)[0];if(n)return n.top;if("orphaned"===t.state||!t.element)return null;let o=t.element.getBoundingClientRect();return e.point?o.top+e.point.y*o.height:o.top}function Gt(e,t){let n=Vt(t).at(-1);if(n)return{x:n.left,y:n.bottom,below:!0};let o=Yt(e,t);return o?{...o,below:!1}:null}function Zt(e,t,n){for(let o of n)if(e>=o.left&&e<=o.right&&t>=o.top&&t<=o.bottom)return!0;return!1}var Jt=()=>window.innerWidth>=900?400:300,Xt=()=>window.innerWidth<=480;function Qt(e,t,n){let o=e.top-t.height-10;return o<8&&(o=e.top+e.height+10),{left:Math.max(8,Math.min(e.left+e.width/2-t.width/2,n.width-t.width-8)),top:o}}function en(e,t){let n=e.resolved.get(t.id);return n?.range?.startContainer??n?.element??null}var tn=e=>(t,n)=>{let o=en(e,t),r=en(e,n),i=e=>e.anchor.point??{x:0,y:-1};return o!==r?!r||o&&4&o.compareDocumentPosition(r)?-1:1:i(t).y-i(n).y||i(t).x-i(n).x},nn=["👍","❤️","😂","🎉","😮","🙏"],on={"👍":"Thumbs up","❤️":"Heart","😂":"Laughing","🎉":"Party popper","😮":"Surprised","🙏":"Thanks"};var rn=e=>`${e} ${1===e?"reply":"replies"}`;function an(e,t,n){let o={...n},r=e.id,i=Je("div",{class:"rbox always"},Je("div",{},Pt({label:"Reply",kind:"reply",thread:()=>r,people:()=>t.people(),U:(e,n)=>t.reply(r,e,n),_:t.close}).element)),a=Je("div",{}),l=Je("span",{class:"note"},"This thread was resolved. Your words are kept until you send or clear them.");l.hidden=!0,i.prepend(l);let s=Je("div",{}),d=null,c=null,p=null,u="",h=Je("div",{},s,Je("div",{class:"more"},a)),f=new Set,m=new Set,g=e,v=new Map,w=new Map,y=new Map,b=e=>{let t=ft(e.author,e.name),n=v.get(e.id),o=n?.e;if((!o||n.key!==t)&&(o=vt(mt(e.author,e.name)),n)){let t=n.e;y.set(e.id,t),gt(t,()=>y.get(e.id)===t&&y.delete(e.id))}o.title=k(e),w.set(e.id,{key:t,e:o});let r=y.get(e.id);return r?[r,o]:[o]},x=(e,t,n)=>{let o=Je("button",{class:"ib",type:"button","aria-label":t,title:t},dt(e));return o.addEventListener("click",e=>{e.stopPropagation(),n()}),o};function S(e,n={}){Object.assign(o,n),r=e.id,g=e;let y=(o.now??Date.now)(),L=e.root.replies.length,C=e=>Je("span",{class:"who"},`${k(e)} · ${De(e.at,y)}`),M=e=>{let n=t=>$(e.name)?function(e){let t=[],n=e.split("\n").filter(e=>{let n=/^\[(\d{1,2})\]:?\s+(\S+)(?:\s+([^|]{1,40}?))?(?:\s*\|\s*(.{1,300}))?$/.exec(e.trim()),o=n?.[2]?function(e){return/^slide:\d{1,4}$/.test(e)||/^quote:\S{1,300}$/.test(e)?e:function(e){if(e.length>2048||rt.test(e))return null;try{let t=new URL(e);return"http:"===t.protocol||"https:"===t.protocol?t.href:null}catch{return null}}(e)}(n[2]):null;return n?.[1]&&o&&t.push({n:n[1],to:o,label:n[3]?.trim()??"",says:n[4]?.trim()??""}),!(n?.[1]&&o)}).join("\n").replace(/\s*\[\d{1,2}\]/g,"").trim();if(!t.length)return at(e);let o=t.slice(0,4).map(e=>{let t=e.to.startsWith("slide:"),n=e.label||(t?`Slide ${e.to.slice(6)}`:`[${e.n}]`),o=[t?Je("i",{class:"sl"}):null,Je("span",{},t||""===e.label?n:`[${e.n}] ${n}`),e.says?Je("span",{class:"rc",role:"tooltip"},e.says):null];if(/^https?:/.test(e.to)){let t=Je("a",{class:"ref",href:e.to,target:"_blank",rel:"noopener noreferrer",title:e.says?void 0:e.to},...o);return t.addEventListener("click",e=>e.stopPropagation()),t}let r=Je("button",{class:"ref",type:"button",title:e.says?void 0:t?n:`Show where: ${n}`},...o);return r.addEventListener("click",t=>{t.stopPropagation(),Ge.go?.(e.to)}),r});return[...at(n),Je("div",{class:"refs"},...o)]}(t):at(t);if(!e.mentions?.length)return n(e.text);let o=[],r=0;for(let i of e.mentions)i.start<r||(o.push(...n(e.text.slice(r,i.start))),o.push(Je("span",{class:$t(e,[t.me])&&i.ref===t.me?"mn me":"mn"},e.text.slice(i.start,i.end))),r=i.end);return[...o,...n(e.text.slice(r))]},A=e=>Je("div",{class:e.deleted?"tx del":"tx"},...e.deleted?["Deleted"]:[...M(e),e.edited?" (edited)":""]),T=n=>function(e,t){if(e.deleted||!e.reactions.length&&!t.quick)return null;let n=n=>e.reactions.find(e=>e.emoji===n)?.by.some(e=>e.author===t.me)??!1,o=e.reactions.map(o=>{let r=n(o.emoji),i=o.by.length,a=[...r?["You"]:[],...o.by.filter(e=>e.author!==t.me).map(e=>k(e))],l=`${e.id}|${o.emoji}`,s=Je("button",{class:`ref rx${r?" mine":""}${t.seen.has(l)?"":" new"}`,type:"button","aria-pressed":String(r),"aria-label":`${t.picker?.name(o.emoji)??on[o.emoji]??"Reaction"}, ${i} ${1===i?"person":"people"}${r?", including you":""}`},Je("span",{},o.emoji),Je("span",{class:"n"},String(i)),Je("span",{class:"rc"},a.join(", ")));return t.seen.add(l),s.disabled=t.resolved,s.addEventListener("click",e=>{e.stopPropagation(),t.react(o.emoji,!r)}),s}),r=t.quick&&!t.resolved?Je("div",{class:"rxq"+(t.seen.has(`${e.id}|quick`)?"":" new"),role:"group","aria-label":"React"},...nn.map(e=>{let o=Je("button",{class:"rxo",type:"button","aria-label":on[e],"aria-pressed":String(n(e))},e);return o.addEventListener("click",o=>{o.stopPropagation(),t.react(e,!n(e))}),o}),t.picker?function(e,t){let n=Je("button",{class:"rxo",type:"button","aria-label":"More reactions","aria-haspopup":"dialog"},"…");return n.addEventListener("click",o=>{o.stopPropagation(),function(e,t,n){let o=e.closest(".layer");if(!o)return;o.querySelector(".rxp")?.remove();let r=e.getBoundingClientRect(),i=Math.max(8,Math.min(r.left,window.innerWidth-320-8)),a=r.bottom+6+340<=window.innerHeight-8?r.bottom+6:Math.max(8,r.top-340-6),l=Je("div",{class:"rxp",role:"dialog","aria-label":"Choose a reaction"});l.style.cssText=`left:${i}px;top:${a}px`;let s=!1,d={},c=e=>{e.composedPath().includes(l)||p()},p=()=>{s||(s=!0,window.removeEventListener("pointerdown",c,!0),d.off?.(),l.classList.remove("show"),l.inert=!0,window.setTimeout(()=>l.remove(),260),e.focus({preventScroll:!0}))};l.addEventListener("keydown",e=>{"Escape"===e.key&&(e.stopPropagation(),e.preventDefault(),p())}),d.off=t.fill(l,e=>{p(),n(e)}),window.addEventListener("pointerdown",c,!0),o.append(l),l.offsetWidth,l.classList.add("show"),l.querySelector("input,button")?.focus({preventScroll:!0})}(n,e,t)}),n}(t.picker,e=>t.react(e,!n(e))):null):null;return r?t.seen.add(`${e.id}|quick`):t.seen.delete(`${e.id}|quick`),Je("div",{class:"refs rxs"},...o,r)}(n,{me:t.me,picker:t.picker(),resolved:e.resolved,quick:f.has(n.id),seen:m,react:(e,o)=>{f.delete(n.id),t.react(n.id,e,o),S(g)}}),P=t=>e.resolved||t.deleted?null:x("smile","React",()=>{f.delete(t.id)||f.add(t.id),S(g)}),q=e.resolved?"Resolved"+(L?` · ${rn(L)}`:""):e.addressed?"Addressed"+(L?` · ${rn(L)}`:""):L?rn(L):"",N=Je("div",{class:"column"===o.B?q?"ft has-rest":"ft":"ft open"},"column"===o.B&&q?Je("span",{class:"rest"},q):null,Je("span",{class:"hover"},C(e.root),Je("span",{class:"acts"},P(e.root),x("copy","Copy thread",()=>t.copy(e.id)),e.resolved?x("reopen","Reopen",()=>{t.reopen(e.id)}):x("resolve","Resolve",()=>{t.resolve(e.id)})))),R=o.lost?Je("div",{class:"ctx"},`${o.place||"No longer on the page"} — it read “${tt(o.lost,120)}”`):o.quote?Je("div",{class:"ctx"},`“${tt(o.quote,80)}”`):null;w=new Map;let z=Je("div",{class:"root"},...b(e.root),R,A(e.root),T(e.root),N);s.replaceWith(z),s=z,d?.remove();let D=Ye.get(e.id);d=L||void 0!==D?Je("div",{class:"rps"},...e.root.replies.map(e=>Je("div",{class:"it"},...b(e),A(e),T(e),Je("div",{class:"column"===o.B?"rft":"rft open"},Je("span",{class:"rrow"},C(e),Je("span",{class:"acts"},P(e)))))),void 0===D?null:Je("div",{class:"it ghost","data-pipeup-writing":"row"},mt("",E),Je("div",{class:"tx","data-pipeup-writing":"words"},D),Je("div",{class:"rft open"},Je("span",{class:"who"},`${E} · writing now`)))):null,d&&a.prepend(d);let O=e.addressed&&!e.resolved?e.addressed:null,F=O?`${O.text}|${O.author}|${O.at}`:"";if(F!==u&&(p?.remove(),p=null,u=F,O)){let n=(e,t)=>{let n=Je("button",{type:"button"},e);return n.addEventListener("click",e=>{e.stopPropagation(),t()}),n};p=Je("div",{class:"adr"},Je("small",{},`Addressed · ${k(O)} · ${De(O.at,y)}`),O.text,Je("div",{class:"go"},n("Resolve",()=>{t.resolve(e.id)}),n("Still not right",()=>{t.notRight(e.id)})))}p&&a.insertBefore(p,c??(i.parentNode===a?i:null)),c?.remove();let I=Ve.get(e.id),B=_e.get(e.id);if(c=void 0===I?null:Je("div",{class:"seen"},Je("i"),I),c&&B){let e=Je("button",{type:"button"},"Check again");e.addEventListener("click",e=>{e.stopPropagation(),B()}),c.append(e)}c&&a.insertBefore(c,i.parentNode===a?i:null),v=w;let j=""!==i.querySelector("textarea").value.trim();l.hidden=!(e.resolved&&j),e.resolved&&!j?i.remove():i.parentNode!==a&&a.append(i),h.className=e.resolved?"thread resolved":"thread",h.setAttribute("data-thread",e.id)}return S(e),{element:h,update:S}}function ln(e,t){let n=new Map,o=Je("div",{class:"tip",role:"tooltip"}),r=Je("div",{class:"mark"}),i=Je("div",{class:"pop",role:"dialog","aria-label":"Comment thread"});o.inert=i.inert=!0,e.t.append(r,o,i);let a,l=Je("div",{class:"bub pin ghost","aria-hidden":"true"}),s=[],d=null,c=null,p=null,u=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,h=0,f=null,m=null,g=null,v=0,w=e=>s.find(t=>t.id===e)??null,y=()=>t.ne||e.state.p,b=!1,x=t=>{let n=e.resolved.get(t.id);return n?Gt(t.anchor,n):null};function E(t,n,o){let{left:r,top:i}=function(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)}}(n,{width:t.offsetWidth||o,height:t.offsetHeight},function(e){let t=window.innerWidth;return{width:e&&!Xt()?t-320:t,height:window.innerHeight}}(e.state.p));t.style.left=`${r}px`,t.style.top=`${i}px`}function $(t){let n=t&&y()&&e.state.i!==t?w(t):null,r=n?x(n):null;if(!n||!r)return g=null,o.classList.remove("show"),void Xe(o,!0);if(g!==n.id){let e=n.root.replies.length;o.replaceChildren(Je("div",{class:"tx clamp"},...n.root.deleted?["Deleted"]:at(n.root.text)),Je("div",{class:"who"},`${k(n.root)}${e?` · ${e} ${1===e?"reply":"replies"}`:""}`)),g=n.id}E(o,r,260),o.classList.contains("show")||o.offsetWidth,o.classList.add("show"),o.inert=!1}function S(t){f=t,$(t),e.w(t)}function L(e){window.clearTimeout(v),null===e?v=window.setTimeout(()=>S(null),y()?400:0):S(e)}function C(t){let o=n.get(t.id);if(o)return o;let i=Je("button",{class:"bub",type:"button","data-thread":t.id});return i.addEventListener("mouseenter",()=>L(t.id)),i.addEventListener("mouseleave",()=>L(null)),i.addEventListener("click",n=>{n.stopPropagation(),$(null),e.open(t.id)}),e.t.insertBefore(i,r),n.set(t.id,i),i}o.addEventListener("mouseenter",()=>window.clearTimeout(v)),o.addEventListener("mouseleave",()=>L(null)),o.addEventListener("click",t=>{t.stopPropagation();let n=g;n&&(window.clearTimeout(v),S(null),e.open(n))});let M=!1;function A(){let t=e.state.o,n=p&&t&&!t.anchor.quote&&!t.anchor.point?t.resolved.element:null;if(n){let{left:e,top:t,above:o}=function(e,t,n,o=12,r=44){let i=e.top-r>=8,a=e.top+e.height+8+(i?0:r),l=e.top-8-(i?r:0)-t.height,s=a+t.height<=n.height-o||l<o,d=s?a:l;return{above:!s,left:Math.max(o,Math.min(e.left,n.width-t.width-o)),top:Math.max(o,d)}}(n.getBoundingClientRect(),{width:i.offsetWidth||Jt(),height:i.offsetHeight},{width:window.innerWidth,height:window.innerHeight}),r=null!==p?.above&&p?.above!==o;if(p&&(p.above=o),r&&P())return;return i.style.left=`${e}px`,void(i.style.top=`${t}px`)}let o=p&&t?Gt(t.anchor,t.resolved):d?x(d):null;o&&E(i,o,Jt())}let T=t=>e.state.c&&!t.anchor.quote&&!t.anchor.point;function P(e=()=>{}){return window.clearTimeout(h),u?(i.classList.remove("show"),h=window.setTimeout(()=>{e(),A(),i.classList.add("show")},220),!0):(e(),i.classList.add("glide"),h=window.setTimeout(()=>i.classList.remove("glide"),450),!1)}let q=t=>{if(e.k(t)){let e=t.composedPath()[0];return null!==m&&!(e instanceof Element&&e.closest(".tip,.bub"))&&L(null),void(m=null)}let n=e.re(t.clientX,t.clientY)?.id??null;n!==m&&(m=n,L(n))},N=t=>{if(e.k(t))return;let n=window.getSelection();if(n&&!n.isCollapsed||(e.state.c?t.altKey:t.target instanceof Element&&t.target.closest("a,button,input,select,textarea,label,summary,[role=button],[contenteditable]")))return;let o=e.re(t.clientX,t.clientY);o&&(e.we(t),$(null),e.open(o.id))};return window.addEventListener("pointermove",q,{capture:!0,passive:!0}),window.addEventListener("click",N,!0),{f:function(o){s=o;let l=new Set;for(let t of o){if(!e.F(t)||t.anchor.quote)continue;let n=e.resolved.get(t.id);if(!n||"orphaned"===n.state)continue;l.add(t.id);let o=C(t);o.classList.toggle("done",t.resolved),o.classList.toggle("on",e.state.i===t.id),o.classList.toggle("pin",void 0!==t.anchor.point);let r=`Comment on ${Pe(n.element)}: ${tt(t.root.text,60)}`;o.getAttribute("aria-label")!==r&&o.setAttribute("aria-label",r)}Qe(e.t,o.filter(e=>l.has(e.id)).sort(tn(e)).map(e=>n.get(e.id)),r);for(let[e,t]of n)l.has(e)||(t.classList.remove("in"),n.delete(e),window.setTimeout(()=>t.remove(),300));$(f),b!==e.state.p&&i.classList.contains("show")&&!u&&P(),b=e.state.p;let m=t.ne?e.state.o:null;if(m){let t=m.anchor.point??m.resolved.element;p?.of!==m?(window.clearTimeout(h),i.classList.remove("glide"),p={l:Kt(e,m),of:m,at:t,above:null},p.l.te(T(m)),i.replaceChildren(p.l.element),i.inert=!1,p.l.focus(),d=null,c=null,A(),i.classList.add("show")):p&&(p.at!==t&&(p.at=t,p.above=null,P(()=>p?.l.ye(m.label))),p.l.te(T(m)));let n=!e.u.m(m.anchor.view);return void(n!==M&&(M=n,i.classList.toggle("show",!n),i.inert=n,n||A()))}p&&(window.clearTimeout(h),i.classList.remove("glide"),p=null,M=!1,e.D(null));let g=y()&&e.state.i?w(e.state.i):null;if(!g||!e.F(g))return d=null,c=null,i.classList.remove("show"),void Xe(i,!0);let v=g.anchor.quote?.exact??null;d&&c&&d.id===g.id?(d!==g||a!==Ze(g.id))&&(c.update(g,{quote:v}),d=g,a=Ze(g.id)):(c=an(g,e.oe,{B:"popover",quote:v}),i.replaceChildren(c.element),d=g,a=Ze(g.id),A(),i.classList.add("show"),i.inert=!1)},L:function(){for(let[t,o]of n){let n=w(t),r=e.resolved.get(t),i=n&&r?Yt(n.anchor,r):null;!i||i.y<-40||i.y>window.innerHeight+40?o.style.visibility="hidden":(o.style.visibility="",o.style.left=`${i.x}px`,o.style.top=`${i.y}px`,o.classList.contains("in")||(o.offsetWidth,o.classList.add("in")))}let t=e.state.o,o=t?.anchor.point&&e.u.m(t.anchor.view)?Yt(t.anchor,t.resolved):null;o?(l.style.left=`${o.x}px`,l.style.top=`${o.y}px`,l.classList.contains("in")||(e.t.insertBefore(l,r),l.offsetWidth,l.classList.add("in"))):l.classList.contains("in")&&(l.classList.remove("in"),window.setTimeout(()=>l.classList.contains("in")||l.remove(),300)),i.classList.contains("show")&&A();let a=function(){if(!y())return null;let t=e.state.o;return t?t.anchor.quote||t.anchor.point||e.state.c?null:t.resolved.element:!d||d.anchor.quote||d.anchor.point?null:e.resolved.get(d.id)?.element??null}();r.classList.toggle("show",null!==a),a&&nt(r,a.getBoundingClientRect(),4)},destroy(){window.clearTimeout(v),window.clearTimeout(h),window.removeEventListener("pointermove",q,!0),window.removeEventListener("click",N,!0),e.D(null);for(let e of n.values())e.remove();l.remove(),o.remove(),r.remove(),i.remove()}}}var sn={display:"block",position:"static",clips:!1,off:!1},dn=["button,a,input,select,textarea,label,summary,details,img,svg,canvas,video,picture,figure,figcaption,table,th,td","li,ul,ol,dl,dt,dd,p,h1,h2,h3,h4,h5,h6,blockquote,pre","section,article,aside,nav,header,footer,main,form,fieldset",..."button link img figure region list listitem tab tabpanel article navigation complementary banner contentinfo form search group dialog menu menuitem checkbox switch radio slider textbox combobox option row cell heading table".split(" ").map(e=>`[role=${e}]`)].join(","),cn="a,button,label,summary,[role=button],[role=link],[role=tab],[role=option],[role=menuitem]",pn=`${cn},input,select,textarea,img,svg,canvas,video,picture,[role=img]`,un=(e,t)=>Math.abs(e.left-t.left)<=2&&Math.abs(e.top-t.top)<=2&&Math.abs(e.width-t.width)<=2&&Math.abs(e.height-t.height)<=2;function hn(e,t){let n=t.l(e);if(n.width<2||n.height<2)return!1;if(e.hasAttribute("data-pipeup-id"))return!0;let o=t.ie();return n.width*n.height<=.6*o.width*o.height&&(e.matches(dn)||t.Ve(e)||e.childElementCount>1&&!e.parentElement?.closest(cn)&&t.Ue(e))}function fn(e,t,n){if(e===t||!t.contains(e)||e.closest("[data-pipeup-ignore]"))return null;let o=null;for(let r=e;r&&r!==t&&!o;r=r.parentElement)hn(r,n)&&(o=r);if(!o||o.hasAttribute("data-pipeup-id"))return o;let r=n.l(o);for(let e=o.parentElement;e&&e!==t&&un(n.l(e),r);e=e.parentElement)if(e.hasAttribute("data-pipeup-id"))return e;return o}function mn(e,t,n){let o=n.l(e);for(let r=e.parentElement;r&&r!==t;){let e=fn(r,t,n);if(!e)return null;if(!un(n.l(e),o))return e;r=e.parentElement}return null}var gn=(e,t)=>e.left<t.left+t.width&&t.left<e.left+e.width&&e.top<t.top+t.height&&t.top<e.top+e.height,vn=(e,t)=>{let n=Math.max(e.left,t.left),o=Math.max(e.top,t.top);return{left:n,top:o,width:Math.max(0,Math.min(e.left+e.width,t.left+t.width)-n),height:Math.max(0,Math.min(e.top+e.height,t.top+t.height)-o)}};function wn(e,t,n=()=>!0){let o=[],r=(e,i,a,l,s,d)=>{for(let c of e.children){if(c.hasAttribute("data-pipeup-ignore")||"true"===c.getAttribute("aria-hidden")||!n(c))continue;let e=t.flow?.(c)??sn,p=c.offsetParent,u="fixed"===e.position||"absolute"===e.position&&!!l&&!(p&&l.contains(p)),h=u?null:a,f=t.l(c),m=f.width>0&&f.height>0;if(h&&m&&!gn(f,h))continue;let g=c.matches(cn),v=(e.display.startsWith("inline")||d)&&!c.matches(pn)&&("inline"===e.display||f.height<=48),w=f.width<=24&&f.height<=24,y=i;(c.hasAttribute("data-pipeup-id")||!s&&!e.off&&!v&&(!w||g))&&hn(c,t)&&(i&&un(t.l(i.e),f)?(c.hasAttribute("data-pipeup-id")||!i.e.hasAttribute("data-pipeup-id"))&&(i.e=c):o.push(y={e:c,O:i,S:0}));let b=e.clips&&m;r(c,y,b?h?vn(h,f):f:h,b?c:u?null:l,s||g,/^inline-(flex|grid)$/.test(e.display)||d&&/(flex|grid)$/.test(e.display))}};r(e,null,null,null,!1,!1);for(let e=o.length-1;e>=0;e--){let t=o[e];t.O&&(t.O.S=Math.max(t.O.S,t.S+1))}return o}var yn=(e,t)=>e.filter(e=>e.S<=t&&(!e.O||e.O.S>t)),bn="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]",xn=`${bn},input,select,textarea,[contenteditable]:not([contenteditable=false]),[tabindex]:not([tabindex="-1"])`,kn=["click","dblclick","auxclick","submit","contextmenu","dragstart"],En=[...["over","out","enter","leave","down","up"].flatMap(e=>[`pointer${e}`,`mouse${e}`]),"mousemove","touchstart","touchmove","touchend","touchcancel"],$n="Tab moves between blocks · ↑ ↓ change level · Enter comments · Esc to finish · F7 selects text";function Sn(e){let t={l:e=>e.getBoundingClientRect(),Ve:e=>{let t=getComputedStyle(e),n="transparent"!==t.backgroundColor&&!/,\s*0\)$/.test(t.backgroundColor),o=["top","right","bottom","left"].some(e=>parseFloat(t.getPropertyValue(`border-${e}-width`))>0);return n||o||"none"!==t.backgroundImage||"none"!==t.boxShadow},Ue:e=>/^(inline-)?(flex|grid)$/.test(getComputedStyle(e).display),flow:e=>{let t=getComputedStyle(e),n=[t.overflowX,t.overflowY];return{display:t.display,position:t.position,clips:n.some(e=>"hidden"===e||"clip"===e)&&!n.some(e=>"auto"===e||"scroll"===e)&&e!==document.documentElement&&e!==document.body,off:"none"===t.pointerEvents}},ie:()=>({width:innerWidth,height:innerHeight})},n=Je("span",{hidden:!0},$n),o=Je("div",{class:"pick"},n),r=[0,1].map(()=>{let e=Je("div",{class:"km",tabindex:"-1",role:"button"},Je("span",{hidden:!0}),Je("span",{hidden:!0}));return e.inert=!0,e.addEventListener("keydown",pe),e.addEventListener("click",e=>{e.stopPropagation(),ce()}),e.addEventListener("focus",()=>o.classList.add("kf")),e.addEventListener("blur",()=>o.classList.remove("kf")),e}),i=Je("span",{class:"lbl"}),a=(e,t,n,o)=>{let r=Je("button",{class:"nb",type:"button","aria-label":e,title:t},dt(n,16));return r.addEventListener("click",e=>{e.stopPropagation(),o()}),r},l=a("Around it","Select the block around it","expand",se),s=a("Inside it","Select a block inside it","shrink",de),d=a("Pin","Pin its centre","pin",()=>e.be(()=>H(f??x,{x:.5,y:.5}))),c=Je("div",{class:"namebar",role:"group","aria-label":"Chosen block"},i,l,s,d);c.inert=!0;let p=e.t.querySelector(".launch");for(let t of[o,...r,c])e.t.insertBefore(t,p);c.addEventListener("mousedown",e=>e.preventDefault());let u=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,h=null,f=null,m=null,g=null,v=0,w=()=>{},y=null,b=()=>{},x=null,k=0,E=0,$=!1,S=null,L=null,C=null,M=0,A=-1,T=!0,P=null,q=null,N=t=>!(e.k(t)||t.target instanceof Element&&t.target.closest("[data-pipeup-ignore]"));function R(){g&&(o.classList.toggle("glide",performance.now()<v),nt(o,g.getBoundingClientRect(),4))}function z(){if(!y)return;c.classList.toggle("glide",performance.now()<v&&c.classList.contains("show"));let{left:e,top:t}=Qt(y.getBoundingClientRect(),{width:c.offsetWidth||200,height:c.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});c.style.left=`${e}px`,c.style.top=`${t}px`}function D(e,t){g=e,v=t?performance.now()+400:0,R(),o.classList.add("show")}function O(e,t){let n=getComputedStyle(e);if("0"===n.opacity)return t(),()=>{};let o=0,r=()=>{window.clearTimeout(o),e.removeEventListener("transitionend",a)},i=()=>{r(),t()},a=t=>{t.target===e&&"opacity"===t.propertyName&&i()},l=Math.max(...n.transitionDuration.split(",").map(e=>1e3*parseFloat(e)||0));return o=window.setTimeout(i,l+100),e.addEventListener("transitionend",a),r}function F(e){if(e!==h){if(h=e,w(),!e)return void o.classList.remove("show");"0"===getComputedStyle(o).opacity?D(e,!1):u?(o.classList.remove("show"),w=O(o,()=>D(e,!1))):D(e,!0)}}function I(e){f=e,o.classList.toggle("on",null!==e),F(e),B(e)}function B(e){b(),c.inert=!e,e?u?(c.classList.remove("show"),b=O(c,()=>j(e))):j(e):(c.classList.remove("show"),y=null)}function j(n){i.textContent=i.title=Pe(n),l.hidden=null===mn(n,e.root,t),s.hidden=0===(x?ae(n).length:wn(n,t,X).length);let o=c.classList.contains("show");y=n,z(),o||(c.offsetWidth,c.classList.add("show"))}function H(t,n){let o;try{o=be(t,e.root,n,e.u.view(t))}catch(t){return void e.Y(t)}let r={anchor:o,label:n?`Pin on ${Pe(t).replace(/^[A-Z](?=[a-z])/,e=>e.toLowerCase())}`:Pe(t),ranges:[],resolved:{state:"attached",element:t,range:null}},i=e.state.o;x&&(x=t,A=-1),I(n?null:t),m=i??r,e._e(r),e.E(n?r.label:`Commenting on ${r.label}`)}function W(t){e.be(()=>H(t))}let U=n=>{if(e.k(n))return;if(!N(n))return void(f||F(null));if(n.stopPropagation(),f||e.state.o)return;let o=!et()&&n.target instanceof Element?fn(n.target,e.root,t):null;if(x){if(!o||o===x||(M+=Math.abs(n.movementX)+Math.abs(n.movementY),M<=4))return;ie()}o&&(S=o),F(o)},K=()=>{et()&&(x&&ie(),f||F(null))},Y=e=>{N(e)&&(e.stopPropagation(),("pointerdown"===e.type||"mousedown"===e.type)&&e.target instanceof Element&&e.target.closest(xn)&&e.preventDefault())},V=n=>{if(!N(n))return;let o=n.target;!(o===q||o.form&&o.form===q?.form)||"submit"!==n.type&&("click"!==n.type||n.detail)?(n.preventDefault(),n.stopPropagation(),"click"===n.type&&!e.state.s&&!e.Ke(n)&&function(n){let o=window.getSelection();if(o&&!o.isCollapsed)return;if(e.state.o&&(n.altKey||!e.C()))return void e.q();if(!n.altKey&&e.re(n.clientX,n.clientY))return;if(e.state.i&&e.open(null),x&&n.detail&&ie(),n.altKey)return void function(n){let o=(n.target instanceof Element?fn(n.target,e.root,t):null)??e.root;o!==e.root&&(S=o);let r=o.getBoundingClientRect();r.width&&r.height&&H(o,{x:(n.clientX-r.left)/r.width,y:(n.clientY-r.top)/r.height})}(n);let r=n.target instanceof Element?fn(n.target,e.root,t):null;r&&(S=r),r?H(r):(e.q(),I(null))}(n)):q="click"===n.type&&"submit"===o.type?o.form:null},_=t=>{if(q=null,he="","Tab"===t.key&&G(t))return t.preventDefault(),t.stopPropagation(),he=t.key,e.q(),e.state.i&&e.open(null),e.state.s&&(e.state.s=!1,e.f()),function(t){if(x)return le(t);P=null;let n=document.activeElement;L=Z()??n;let o,r=S?.isConnected?S:null,i=r&&ee(r);if(i){k=i.S;let e=yn(Q(),k),n=e.indexOf(i);o=e[(n+t+e.length)%e.length]}else if(r){k=0;let e=yn(Q(),0),n=e=>0!==(r.compareDocumentPosition(e.e)&Node.DOCUMENT_POSITION_FOLLOWING),i=e=>e.e.contains(r);o=t>0?e.find(e=>n(e)&&!i(e))??e[0]:e.filter(e=>!n(e)&&!i(e)).pop()??e[e.length-1]}else o=ne(),o&&(k=o.S);if(!o)return e.E("Nothing here to comment on");$=!0,re(o.e)}(t.shiftKey?-1:1);if(N(t)&&t.target instanceof Element)if("Enter"!==t.key&&" "!==t.key||!t.target.closest(bn))"Enter"===t.key&&!x&&t.target.form&&(q=t.target);else{if(!x)return void(q=t.target);t.preventDefault(),t.stopPropagation()}},G=t=>{if(t.ctrlKey||t.metaKey||t.altKey||t.isComposing)return!1;let n=t.composedPath()[0];return n instanceof Element&&!r.some(e=>e===n)&&(e.k(t)?!!n.closest(".launch,.menu")&&!n.closest("input,textarea,select,[contenteditable]"):!t.composedPath().some(e=>e instanceof Element&&e.hasAttribute("data-pipeup-ignore")))},Z=()=>e.t.getRootNode().activeElement,J=()=>r.some(e=>e===Z()),X=t=>(!1!==t.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0})||"contents"===getComputedStyle(t).display)&&e.u.m(e.u.view(t)),Q=()=>(P?.some(e=>!e.e.isConnected)&&(P=null),P??=wn(e.root,t,X)),ee=e=>Q().find(t=>t.e===e),te=(e,t=!1)=>{let n=e.getBoundingClientRect();return n.bottom>0&&n.top<window.innerHeight&&(!t||n.top>=0)},ne=()=>{let e=yn(Q(),0);return e.find(e=>te(e.e,!0))??e.find(e=>te(e.e))??e[0]},oe=t=>e.doc.threads().filter(n=>e.F(n)&&t.contains(en(e,n))).sort(tn(e));function re(t,o=!0){M=0;let i=Q(),a=i.find(e=>e.e===t);if(a&&!yn(i,k).includes(a)&&(k=a.S),t!==x&&(A=-1),t!==f&&(f=null),x=t,F(t),B(t),t.scrollIntoView({block:"nearest",inline:"nearest",behavior:u?"auto":"smooth"}),!o)return;e.ze();let l=r[E^=1];(function(e,t){let[o,r]=e.children,i=yn(Q(),k),a=oe(t).length;o.textContent=`${Ae(t)}, ${i.findIndex(e=>e.e===t)+1} of ${i.length}${a?`, has ${a} comment${1===a?"":"s"}`:""}`;let l=(t.innerText??t.textContent??"").length<=150;r.textContent=Te(t);let s=T?[n]:[];T=!1,void 0!==e.ariaLabelledByElements?(e.ariaLabelledByElements=l?[o,t]:[o,r],e.ariaDescribedByElements=l?s:[...s,t]):e.setAttribute("aria-label",`${o.textContent}, ${r.textContent}`)})(l,t),nt(l,t.getBoundingClientRect(),4),l.inert=!1,l.focus({preventScroll:!0}),r[1^E].inert=!0}function ie(){let e=J();S=x,x=null,F(null),B(null);for(let e of r)Xe(e,!0);return e}function ae(e){let t=ee(e);return t?((e,t)=>e.filter(e=>e.O===t))(Q(),t):[]}function le(e){let t=yn(Q(),k),n=t.findIndex(e=>e.e===x),o=t[n<0?e>0?0:t.length-1:(n+e+t.length)%t.length];o&&re(o.e)}function se(){let n=f??x,o=n&&mn(n,e.root,t);return o?((!C||!n.contains(C))&&(C=n),f?W(o):void re(o)):e.E("Nothing around it")}function de(){let t=f??x,n=t?ae(t):[],o=n.find(e=>C&&e.e.contains(C))??n.find(e=>te(e.e))??n[0];if(!o)return e.E("Nothing inside it");f?W(o.e):re(o.e)}function ce(t=!1){if(!x)return;if(e.state.o&&!e.C())return e.je();if(!t)return H(x);let n=oe(x);if(!n.length)return e.E("No comments on this block");A=(A+1)%n.length,e.open(n[A].id),n.length>1&&e.E(`Comment ${A+1} of ${n.length} on this block`)}function pe(t){if(["Tab","ArrowUp","ArrowDown","Enter"," ","Escape"].includes(t.key)&&(!t.key.startsWith("Arrow")||!(t.metaKey||t.ctrlKey||t.altKey))){if(t.preventDefault(),t.stopPropagation(),he=t.key,"Escape"===t.key)return void e.se();if("Enter"===t.key||" "===t.key)return ce(t.shiftKey&&"Enter"===t.key);"Tab"===t.key&&e.q(),e.state.i&&e.open(null),"Tab"===t.key?le(t.shiftKey?-1:1):"ArrowUp"===t.key?se():de()}}let ue=()=>{let e=Z();return e?!!e.closest("[inert]"):!document.activeElement||document.activeElement===document.body},he="",fe=!1,me=e=>{fe&&window.removeEventListener("keyup",me,!0),e.key===he&&(he="",e.preventDefault(),e.stopPropagation())};window.addEventListener("keyup",me,!0),window.addEventListener("pointermove",U,!0),document.addEventListener("selectionchange",K);for(let e of En)window.addEventListener(e,Y,!0);for(let e of kn)window.addEventListener(e,V,!0);return window.addEventListener("keydown",_,!0),{se:()=>!!f&&(I(null),!0),ae:()=>null!==x,We:()=>$&&!x,xe:function(){P=null;let t=document.activeElement;L=Z()??t;let n=ee(S),o=n??(t&&t!==document.body&&e.root.contains(t)&&!t.closest("[data-pipeup-ignore]")?Q().filter(e=>e.e.contains(t)).pop():void 0)??ne();return!!o&&(n||(k=o.S),$=!0,re(o.e),!0)},le(){x&&!J()&&re(x)},f(){if(P=null,x&&(!x.isConnected||!X(x))){let e=ne();e?re(e.e,J()||ue()):ie()}let t=e.t.querySelector(".launch");if(t&&c.nextElementSibling!==t&&!J()&&!c.contains(Z()))for(let n of[o,...r,c])e.t.insertBefore(n,t);let n=e.state.o;m&&n!==m?(m=null,I(null),x&&re(x,ue())):(n||e.state.i)&&!m&&(h||f)&&I(null)},L(){R(),z(),x&&nt(r[E],x.getBoundingClientRect(),4)},destroy(){ie()&&function(){let t=L;t&&t!==document.body&&t.isConnected&&t.focus?.({preventScroll:!0}),(!t||t===document.body||!t.matches?.(":focus"))&&e.t.querySelector(".launch .mode")?.focus({preventScroll:!0})}();for(let e of r)e.remove();w(),b(),fe=!0,he||window.removeEventListener("keyup",me,!0),window.removeEventListener("pointermove",U,!0),document.removeEventListener("selectionchange",K);for(let e of En)window.removeEventListener(e,Y,!0);for(let e of kn)window.removeEventListener(e,V,!0);window.removeEventListener("keydown",_,!0),o.classList.remove("show"),c.classList.remove("show"),Xe(c,!0),O(o,()=>o.remove()),O(c,()=>c.remove())}}}function Ln(e,t=!1){let n=e.ownerDocument.documentElement,o=n.getAttribute("data-pipeup-layout");if("bubbles"===o||e.querySelector("[data-pipeup-slide]"))return null;let r=e.querySelector("article, main, [role=main]")??("column"===o?e:null);if(!r)return null;if(n.hasAttribute("data-pipeup-reserve")){let e,i=n.clientWidth,a=getComputedStyle(r).maxWidth;return e=a.endsWith("px")?parseFloat(a):a.endsWith("%")?parseFloat(a)/100*i:r.getBoundingClientRect().width,"column"!==o&&i<e+320-(t?24:0)?null:{x:i-320+24,width:272}}let i=r.getBoundingClientRect().right;if(window.innerWidth-i<300&&"column"!==o)return null;let a=i+32;return{x:a,width:Math.max(220,Math.min(300,window.innerWidth-a-16))}}function Cn(e,t){let n=e.resolved.get(t.id);return!n||"orphaned"===n.state&&!e.T.has(t.id)}function Mn(e){let t=Je("div",{class:"col"});e.t.append(t);let n=new Map,o=null,r=new ResizeObserver(()=>l()),i=t=>Cn(e,t);function a(t){let n=e.resolved.get(t.id),o=n?_t(t.anchor,n):null;return null===o?Number.POSITIVE_INFINITY:o+window.scrollY-4}function l(){let t=[],r=[];for(let[o,i]of n){let n=a(i.thread);if(Number.isFinite(n))i.placed=n;else if(e.T.has(o)){if(null===i.placed){i.e.classList.add("wait");continue}n=i.placed}Number.isFinite(n)?t.push({id:o,M:n,height:i.e.offsetHeight}):r.push({id:o,height:i.e.offsetHeight})}let i=e.state.o,l=i?_t(i.anchor,i.resolved):null;o&&null!==l&&t.push({id:"draft",M:l+window.scrollY-4,height:o.e.offsetHeight});let s=function(e,t,n=10){let o=[...e].sort((e,t)=>e.M-t.M),r=new Array(o.length).fill(0),i=o.findIndex(e=>e.id===t),a=e=>o[e];if(i<0)o.forEach((e,t)=>{r[t]=0===t?e.M:Math.max(e.M,(r[t-1]??0)+a(t-1).height+n)});else{r[i]=a(i).M;for(let e=i+1;e<o.length;e++)r[e]=Math.max(a(e).M,(r[e-1]??0)+a(e-1).height+n);for(let e=i-1;e>=0;e--)r[e]=Math.min(a(e).M,(r[e+1]??0)-a(e).height-n)}return new Map(o.map((e,t)=>[e.id,r[t]??0]))}(t,o?"draft":e.state.i),d=Math.max(0,...t.map(e=>(s.get(e.id)??0)+e.height))+24;for(let e of r)s.set(e.id,d),d+=e.height+10;for(let[e,t]of n)if(t.e.classList.contains("wait")){if(!s.has(e))continue;t.e.style.transition="none",t.e.style.transform=`translateY(${Math.round(s.get(e))}px)`,t.e.offsetWidth,t.e.style.transition="",t.e.classList.remove("wait")}else t.e.style.transform=`translateY(${Math.round(s.get(e)??0)}px)`;o&&(o.e.style.transform=`translateY(${Math.round(s.get("draft")??0)}px)`)}function s(e,t){e.thread=t,e.note=Ze(t.id),e.lost=i(t),e.view.update(t,{lost:e.lost?t.anchor.snapshot:null})}function d(n){let o=i(n),a=an(n,e.oe,{B:"column",lost:o?n.anchor.snapshot:null}),l=Je("div",{class:"th","data-thread":n.id},Je("button",{class:"opn sr",type:"button","data-thread":n.id}),a.element);return l.style.transition="none",l.addEventListener("mouseenter",()=>e.w(n.id)),l.addEventListener("mouseleave",()=>e.w(null)),l.addEventListener("click",()=>e.open(n.id)),t.append(l),r.observe(l),{e:l,thread:n,lost:o,placed:null,view:a}}function c(e){r.unobserve(e),e.classList.add("out"),window.setTimeout(()=>e.remove(),220)}return{f:function(a){Xe(t,e.state.p);let p=new Set,u=[],h=null!==e.state.i||null!==e.state.o;for(let t of a){if(!e.F(t))continue;p.add(t.id);let o=n.get(t.id);o?(o.thread!==t||o.lost!==i(t)||o.note!==Ze(t.id))&&s(o,t):(o=d(t),n.set(t.id,o),u.push(o.e));let r=o.e,a=e.state.i===t.id;r.classList.toggle("on",a);let l=r.firstElementChild,c=t.root.replies.length;l.setAttribute("aria-label",`Open thread: ${tt(t.root.text,60)}, ${rn(c)}`),l.setAttribute("aria-expanded",String(a)),Xe(l,a);let f=r.querySelector(".more");f&&Xe(f,!a),r.classList.toggle("dim",h&&!a),r.classList.toggle("hot",e.state.w===t.id&&!a),r.classList.toggle("resolved",t.resolved),r.classList.toggle("lost",o.lost)}for(let[e,t]of n)p.has(e)||(n.delete(e),c(t.e));(function(){let n=e.state.o;if(o&&o.of!==n&&(c(o.e),o=null,n||e.D(null)),!n)return;let i=!o;if(o)o.l.ye(n.label);else{let i=Kt(e,n),a=Je("div",{class:"th on"},i.element);a.style.transition="none",t.append(a),r.observe(a),o={e:a,l:i,of:n}}o.l.te(e.state.c&&!n.anchor.quote&&!n.anchor.point),i&&o.l.focus()})(),Qe(t,a.filter(e=>p.has(e.id)).sort(tn(e)).map(e=>n.get(e.id).e),o?.e??null)&&t.offsetWidth,l(),o&&u.push(o.e);for(let e of u)e.offsetWidth,e.style.transition=""},L:function(){let n=Ln(e.root,!0);n&&(t.style.width=`${n.width}px`,t.style.transform=`translate(${n.x}px, ${-window.scrollY}px)`)},destroy(){r.disconnect(),e.D(null),t.remove()}}}var An="[data-pipeup-ignore],input,textarea,select,[contenteditable]:not([contenteditable=false])";function Tn(e){let t=Je("button",{type:"button","aria-label":"Comment",title:"Comment"},dt("comment",17)),n=Je("div",{class:"selbar"},t);n.inert=!0,e.t.append(n);let o=null,r=0,i=!1,a=t=>{let n=t&&(t.nodeType===Node.ELEMENT_NODE?t:t.parentElement);return!!n&&e.root.contains(n)&&!n.closest(An)};function l(){if(!o)return;let{left:e,top:t}=Qt(o.getBoundingClientRect(),{width:n.offsetWidth||36,height:n.offsetHeight||34},{width:window.innerWidth,height:window.innerHeight});n.style.left=`${e}px`,n.style.top=`${t}px`}function s(){o=null,n.inert=!0,n.classList.remove("show")}function d(t=!1){let r=et();e.state.c&&r&&a(r.anchorNode)&&a(r.focusNode)?(!o&&!t&&e.E("Enter comments on the selected words"),o=r.getRangeAt(0).cloneRange(),l(),n.inert=!1,n.classList.add("show")):s()}t.addEventListener("mousedown",e=>e.preventDefault()),t.addEventListener("click",t=>{if(t.stopPropagation(),e.state.o&&!e.C())return e.q();let n,r=o;if(!r)return;try{n=ye(r,e.root,e.u.view(r.commonAncestorContainer))}catch(t){return e.Y(t),void s()}let i=tt(r.toString().replace(/\s+/g," ").trim(),60);window.getSelection()?.removeAllRanges(),s(),e.Ye({anchor:n,label:`“${i}”`,ranges:[r],resolved:{state:"attached",element:null,range:r}})});let c=()=>{window.clearTimeout(r),r=window.setTimeout(()=>i||d(),250),o&&(et()||s())};document.addEventListener("selectionchange",c);let p=t=>{"keyup"!==t.type&&(i="mousedown"===t.type),!i&&!e.k(t)&&window.setTimeout(()=>d("mouseup"===t.type),0)};window.addEventListener("mousedown",p,!0),window.addEventListener("mouseup",p,!0),window.addEventListener("keyup",p,!0);let u=n=>{"Enter"!==n.key||!o||e.k(n)||n.target instanceof Element&&n.target.closest(`${An},${bn}`)||(n.preventDefault(),n.stopPropagation(),t.click())};return window.addEventListener("keydown",u,!0),{f(){!e.state.c&&o&&s()},L(){o&&l()},destroy(){window.removeEventListener("mousedown",p,!0),window.removeEventListener("mouseup",p,!0),window.removeEventListener("keyup",p,!0),window.removeEventListener("keydown",u,!0),window.clearTimeout(r),document.removeEventListener("selectionchange",c),n.remove()}}}async function Pn(e,t){try{return void await navigator.clipboard.writeText(e)}catch{}let n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.cssText="position:fixed;opacity:0;pointer-events:none",t.append(n),n.select();let o=document.execCommand("copy");if(n.remove(),!o)throw new Error("pipeup: your browser blocked copying")}var qn="Hidden on the page",Nn=["auto","light","dark"];function Rn(e){let t=[Je("span",{class:"n"}),Je("span",{class:"n"})],n=dt("comment",20,1.4);n.lastElementChild.setAttribute("stroke-width","1.6");let o=Je("button",{class:"mode",type:"button","aria-label":"Comment","aria-keyshortcuts":Ut,"aria-haspopup":"menu","aria-expanded":"false"},Je("span",{class:"plus"},n),Je("span",{class:"cnt"},dt("bubble",34,1.4),...t),Je("span",{class:"dot"})),r=document.createTextNode("Comment"),i=Je("span",{class:"ttip","aria-hidden":"true"},r,Je("small",{},Wt)),a=Je("div",{class:"launch"},o,i),l=Je("div",{class:"menu",role:"menu","aria-label":"Comments"}),s=Je("div",{class:"list",role:"menu","aria-label":"All comments"}),d=Je("span",{class:"pn"}),c=Je("button",{class:"ib",type:"button","aria-label":"Close"},dt("close")),p=Je("button",{class:"hs",type:"button",role:"switch","aria-checked":"false"},"Show resolved",Je("span",{class:"sw","aria-hidden":"true"}));p.addEventListener("click",t=>{t.stopPropagation(),e.s.Ge()});let u=Je("button",{class:"hs",type:"button",role:"switch","aria-checked":"false"},"Mentions of me",Je("span",{class:"sw","aria-hidden":"true"}));u.hidden=!0,u.addEventListener("click",t=>{t.stopPropagation(),e.s.toggleMine()});let h=Je("div",{class:"lns"}),f=new Map,m=Je("div",{class:"all",role:"dialog","aria-label":"All comments"},Je("div",{class:"hd"},Je("span",{},"All comments"),d,u,p,c),h,s),g=document.createElementNS("http://www.w3.org/2000/svg","svg");g.setAttribute("class","cx"),g.setAttribute("aria-hidden","true");let v=document.createElementNS("http://www.w3.org/2000/svg","path"),w=document.createElementNS("http://www.w3.org/2000/svg","circle");w.setAttribute("r","4"),g.append(v,w),l.inert=m.inert=!0,e.t.append(l,a,g,m);let y=!1,b=null,k=0,E=[],$=0,S=null,L=null,C=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,M=t=>{y=e.state.s=t,t&&e.addons.flush(),window.clearTimeout(k),k=0,t||b?.(!0),l.classList.toggle("show",t),Xe(l,!t),o.setAttribute("aria-expanded",String(t))},A=(t,n=!1)=>{e.state.p!==t&&(e.state.p=t,e.f(),t?(T(s)[0]??c).focus({preventScroll:!0}):n&&o.focus({preventScroll:!0}))},T=(e=l)=>[...e.querySelectorAll(".mi")],P=()=>l.getRootNode().activeElement,q=()=>{M(!1),o.focus({preventScroll:!0})},N=e=>{let t=T(e.currentTarget);if(0===t.length)return;let n=P(),o=t.indexOf(n),r=n=>{e.preventDefault(),t[(n+t.length)%t.length]?.focus({preventScroll:!0})};"ArrowDown"===e.key?r(o+1):"ArrowUp"===e.key?r(o<0?t.length-1:o-1):"Home"===e.key?r(0):"End"===e.key&&r(t.length-1)};l.addEventListener("keydown",N),s.addEventListener("keydown",N),c.addEventListener("click",e=>{e.stopPropagation(),A(!1,!0)});let R=t=>Cn(e,t),z=t=>E.filter(n=>!n.resolved&&(void 0===t||e.V(n)===t)).length,D=()=>z(),O=t=>{let n=t.anchor.view?.slide,o=e.u.m(t.anchor.view)?"":Ne(t.anchor.view);return n&&null!==e.u.slide()?`On slide ${n}`:o?`In ${o}`:qn},F=(e,t,n="")=>Je("div",{role:"group","aria-label":n?`${e} · ${n}`:e},Je("div",{class:"sec","aria-hidden":"true"},e,n&&Je("b",{},n)),...t);function I(){let t=P(),n=t?.dataset.thread,o=null!==L&&L.element.contains(t),r=e.s.all(),i=r.some(t=>Ct(t.thread,e.doc.me)),a=r.filter(t=>!t.thread.resolved||e.state.$||t.thread.id===S).filter(t=>!(e.state.mine&&i)||Ct(t.thread,e.doc.me)),l=t=>{let n=t.thread,o=n.id===S,r=mt(n.root.author,n.root.name);r.classList.add("in");let i=Je("button",{class:`mi${n.resolved?" done":""}${o?" open":""}`,type:"button",role:"menuitem","aria-expanded":String(o),"data-thread":n.id},r,Je("span",{},Je("span",{class:"clamp"},n.root.deleted?"Deleted":n.root.text),Je("small",{},(R(n)?`“${tt(n.anchor.snapshot,80)}”`:t.location.where)+(n.root.reactions.length?` · ${n.root.reactions.map(e=>`${e.emoji} ${e.by.length}`).join(" ")}`:""))));i.addEventListener("click",t=>{t.stopPropagation(),function(t){if(S===t)return H(!0);let n=E.find(e=>e.id===t);if(n){if(S=j=t,L=an(n,{...e.oe,close:()=>H(!0)},B(n)),e.seen(n),I(),L.element.querySelector("textarea")?.focus({preventScroll:!0}),!e.V(n))return W(n);e.state.o&&!e.C()||e.u.H(n.anchor.view??{}).then(()=>{e.ke();let n=E.find(e=>e.id===t);n&&j===t&&S===t&&W(n)})}}(n.id)});let a=document.createDocumentFragment();return a.append(i),o&&L&&(L.update(n,B(n)),a.append(Je("div",{class:"xr",role:"region","aria-label":"Comment thread"},L.element))),a},c=a.filter(e=>R(e.thread));d.textContent=String(D()),p.setAttribute("aria-checked",String(e.state.$)),u.hidden=!i,u.setAttribute("aria-checked",String(e.state.mine&&i)),s.replaceChildren(a.length?"":Je("div",{class:"sec",role:"presentation"},"No open comments"),...function(t,n){let o=e.u.slide(),r=new Map;for(let n of t){let t=n.thread,i=null!==o?t.anchor.view?.slide??o:e.V(t)?e.u.m(t.anchor.view)?"":Ne(t.anchor.view):null;r.set(i,[...r.get(i)??[],n])}if(null===o){let e=r.get(null)??[];return r.delete(null),[...e.map(n),...[...r].map(([e,t])=>F(e||qn,t.map(n)))]}return[...r].sort(([e],[t])=>Number(e)-Number(t)||0).map(([e,t])=>F(`Slide ${e} · ${t.filter(e=>!e.thread.resolved).length} open`,t.map(n),e===o?"This slide":""))}(a.filter(e=>!R(e.thread)),l),c.length?F("No longer on the page",c.map(l)):""),o?L.element.querySelector("textarea")?.focus({preventScroll:!0}):n&&T(s).find(e=>e.dataset.thread===n)?.focus({preventScroll:!0})}function B(t){let n=!R(t)&&e.V(t);return{B:"popover",quote:t.anchor.quote?.exact??null,lost:R(t)||n?t.anchor.snapshot:null,place:n?O(t):null}}let j="";function H(t=!1){if(!S)return;let n=S;S=L=null,e.w(null),I(),t&&T(s).find(e=>e.dataset.thread===n)?.focus({preventScroll:!0})}function W(t){let n=e.resolved.get(t.id),o=n&&!R(t)?n.element??n.range?.startContainer.parentElement??null:null;o?.scrollIntoView({block:"center",inline:"nearest",behavior:C?"auto":"smooth"}),o&&e.w(t.id)}function U(e,t,n=!1,...o){let r=Je("button",{class:"mi",type:"button",role:n?"menuitemcheckbox":"menuitem"},e,Je("span",{class:"lb"}),...o,n&&Je("span",{class:"sw","aria-hidden":"true"}),Je("span",{class:"tt","aria-hidden":"true"}));return r.addEventListener("click",e=>{e.stopPropagation(),t(e)}),r}let K=(e,t,n,o)=>{let r=e.querySelector(".lb");r.textContent!==t&&(r.textContent=t),e.querySelector(".tt").textContent=n,e.setAttribute("aria-description",n),void 0!==o&&e.setAttribute("aria-checked",String(o))},Y=()=>Je("div",{class:"sep",role:"separator"}),V=Je("span",{class:"ma"}),_=Je("span",{class:"kc"}),G="",Z=U(V,function(){let t=Je("input",{class:"input",type:"text",maxlength:"80","aria-label":"Your name"});t.value=e.s.name();let n=Je("div",{class:"ed"},V.cloneNode(!0),t),o=(r,i=!1)=>{if(b!==o)return;b=null;let a=t.value.trim();r&&a&&a!==e.s.name()&&e.s.rename(a).then(ue),n.replaceWith(Z),i&&Z.focus({preventScroll:!0})};b=o,t.addEventListener("keydown",e=>{e.stopPropagation(),("Enter"===e.key||"Escape"===e.key)&&(e.preventDefault(),o("Enter"===e.key,!0))}),t.addEventListener("blur",()=>o(!0)),Z.replaceWith(n),t.focus({preventScroll:!0})},!1,_);Z.dataset.item="name";let J=U(dt("edit"),()=>{q(),e.s.identity()}),X=U(dt("copy"),()=>{q(),e.s.copyAll("ai")}),Q=U(dt("lines"),()=>{q(),e.s.copyAll("text")}),ee=Je("span",{class:"kc"}),te=U(dt("look"),()=>{e.s.setLook(Nn[(Nn.indexOf(e.s.look())+1)%3]),ue()},!1,ee),ne=Je("span",{class:"kc"}),oe=U(dt("list"),()=>{M(!1),A(!0)},!1,ne),re=U(dt("comment"),t=>{let n=!e.state.c&&0===t.detail;e.Xe(!e.state.c,n),n&&M(!1)},!0,Je("span",{class:"kc","aria-hidden":"true"},Wt));re.dataset.item="comment",re.setAttribute("aria-keyshortcuts",Ut);let ie=Je("div",{class:"sec",role:"presentation"}),ae=Y(),le=Y(),se=new Map,de=t=>{let n=se.get(t);return n||(n=U(ct(t.icon,15),()=>{t.checked||q(),Promise.resolve().then(()=>t.select()).catch(t=>e.Y(t)).finally(()=>y&&ue())},!!t.checked,Je("span",{class:"kc"})),se.set(t,n)),n},ce=-1,pe=e=>{try{return e()}catch(e){return globalThis.reportError?.(e),""}};function ue(){let t=D(),n=e.s.name(),o=n||x(e.doc.me);if(K(Z,o,n?"The name on your comments":"Add a name to show on your comments"),Z.setAttribute("aria-label",`${o}, ${n?"edit":"add"} your name`),_.replaceChildren(n?dt("edit",13):"Add name"),ft(e.doc.me,n)!==G){G=ft(e.doc.me,n);let t=mt(e.doc.me,n);t.classList.add("in"),V.replaceChildren(t)}K(J,"My identity","Back it up, or use one you backed up"),K(X,"Copy as Markdown","Markdown, with where each thread is"),K(Q,"Copy as Text","Just the words");let r=["Automatic","Light","Dark"][Nn.indexOf(e.s.look())];K(te,"Look",`${r}. Automatic follows the page; press to change`),ee.textContent=r,K(oe,"All comments","Every thread, and where it is"),ne.textContent=t?String(t):"";let i=e.addons.ue();ie.textContent=i,i?!ie.isConnected&&l.contains(Z)&&l.prepend(ie):ie.remove();for(let t of e.addons.I){let e,n=se.get(t);if(n){try{e=t.checked?.()}catch(e){globalThis.reportError?.(e)}K(n,pe(t.label),pe(t.hint),e),n.querySelector(".kc").textContent=t.count?pe(t.count):""}}K(re,"Start commenting",e.state.c?"Turn off to hide the comments again":"Shows the comments; choose any part of the page to comment on it",e.state.c)}function he(){ue(),(ce!==e.addons.G||!l.contains(Z))&&(l.replaceChildren(Z,J,ae,X,Q,te,oe,...e.addons.I.map(de),le,re),ce=e.addons.G,ue())}o.addEventListener("click",e=>{e.stopPropagation(),y?M(!1):(he(),M(!0),0===e.detail&&T().at(-1)?.focus({preventScroll:!0}))});let fe=!1,me=()=>{fe=m.contains(P())},ge=t=>{let n=t.composedPath();y&&!n.includes(l)&&!n.includes(o)&&(M(!1),e.state.c&&!e.k(t)&&(e.we(t),t.preventDefault(),t.stopPropagation())),e.state.p&&!e.k(t)&&A(!1,fe&&(!document.activeElement||document.activeElement===document.body))},ve=e=>{if(!y||"touch"===e.pointerType||"pointerout"===e.type&&e.relatedTarget)return;let t=e.composedPath();"pointerover"===e.type&&(t.includes(l)||t.includes(o))?(window.clearTimeout(k),k=0):k||(k=window.setTimeout(()=>{k=0,b||M(!1)},3e3))},we={n:0,label:""},ye=()=>{let{n:t,label:n}=we,i=e.addons.ue(),a=`Comment${e.state.c?", comment mode on":""}${n?`, ${n}`:t?`, ${t} open`:""}${i?`, ${i}`:""}`;o.getAttribute("aria-label")!==a&&o.setAttribute("aria-label",a);let l=(n||"Comment")+(i?` · ${i}`:"");r.data!==l&&(r.data=l)},be=e.addons.subscribe(t=>{ye(),(()=>{for(let[t,n]of f)e.addons.listNotes.has(t)||(f.delete(t),n.row.classList.remove("show"),setTimeout(()=>n.row.remove(),320));for(let[t,n]of e.addons.listNotes){let o=f.get(t);if(!o){let e=Je("span",{}),r=Je("div",{class:"ln"},Je("div",{class:"lw"},Je("div",{class:"ag"},e)));r.dataset.addon=t,o={row:r,words:e,btn:null,note:n},f.set(t,o),h.append(r),requestAnimationFrame(()=>{r.offsetWidth,r.classList.add("show")})}if(o.note=n,o.words.textContent!==n.text&&(o.words.textContent=n.text),n.action&&!o.btn){let t=Je("button",{type:"button"}),n=o;t.addEventListener("click",o=>{o.stopPropagation();let r=n.note.action;r&&(t.disabled=!0,r.run().catch(t=>e.Y(t)).finally(()=>{t.disabled=!1,e.f()}))}),o.btn=t,o.words.after(t)}else!n.action&&o.btn&&(o.btn.remove(),o.btn=null);o.btn&&n.action&&o.btn.textContent!==n.action.label&&(o.btn.textContent=n.action.label)}})(),y&&!b&&(t?he():ue())});window.addEventListener("pointerdown",me,!0),window.addEventListener("click",ge,!0),window.addEventListener("pointerover",ve,!0),window.addEventListener("pointerout",ve,!0);let xe=t=>{if("Escape"!==t.key||b||t.composedPath().some(e=>e instanceof Element&&e.classList.contains("rxp")))return;let n=t.composedPath()[0];if(y)q();else{if(!e.state.p||n instanceof HTMLTextAreaElement&&!m.contains(n))return;S?H(!0):A(!1,!0)}t.stopPropagation()};return window.addEventListener("keydown",xe,!0),{f(n){E=n;let r=z(!1);if(r!==$){if(r){let[e,n]=t[0].classList.contains("on")?t:[t[1],t[0]];n.textContent=r>99?"99+":String(r),n.classList.toggle("s",r>99),e.classList.remove("on"),n.classList.add("on")}o.classList.toggle("has",r>0),$=r}let i=z(!0),a=i?`${r} here · ${i} ${null!==e.u.slide()?"on other slides":"in other views"}`:"";o.classList.toggle("else",i>0),we={n:r,label:a},ye(),o.classList.toggle("on",e.state.c),y&&!e.state.s&&M(!1),y&&ue();let l=e.state.p;m.classList.toggle("full",Xt()),m.classList.contains("show")!==l&&(m.classList.toggle("show",l),Xe(m,!l)),S&&(!l||!n.some(e=>e.id===S))&&(S=L=null,e.state.w=null),l&&I()},L:function(){let t=S?E.find(e=>e.id===S):null,n=S?s.querySelector(".mi.open"):null,o=t&&function(t){let n=e.resolved.get(t.id),o=n?.element??n?.range?.startContainer.parentElement;if(!n||Xt()||R(t)||e.V(t)||!1===o?.checkVisibility?.({visibilityProperty:!0}))return null;let r=e.t.querySelector(`.bub[data-thread="${t.id}"]`)?.getBoundingClientRect(),i=n.range?Vt(n).at(-1):void 0,a=o?.closest("p,li,h1,h2,h3,h4,h5,h6,blockquote,td,th,figcaption,div")?.getBoundingClientRect().right,l=n.element?.getBoundingClientRect(),s=Gt(t.anchor,n),d=r?.width?{x:r.right+1,y:r.top+r.height/2,from:"right",bubble:!0}:i?{x:Math.max(i.right,a??0)+4,y:(i.top+i.bottom)/2,from:"right"}:l?{x:l.left+l.width/2,y:l.top,from:"top"}:s&&{x:s.x,y:s.y,from:"right"};return d&&d.x>=0&&d.x<=window.innerWidth-320&&d.y>=0&&d.y<=window.innerHeight?d:null}(t),r=n?.getBoundingClientRect(),i=s.getBoundingClientRect();if(!o||!r||r.top+12<i.top||r.top+12>i.bottom)return void g.classList.remove("show");let a,l=r.left,d=r.top+14;if("right"===o.from&&l-o.x>60){let e=o.x+28,t=o.y>=d?1:-1,n=Math.min(24,Math.abs(o.y-d)/2);a=`M${l} ${d}C${l-24} ${d} ${e} ${d} ${e} ${d+t*n}L${e} ${o.y-t*n}C${e} ${o.y} ${e} ${o.y} ${o.x} ${o.y}`}else{let e=o.y-8,t=l-40,n=e>=d?1:-1,r=Math.min(20,Math.abs(e-d)/2);a=`M${l} ${d}C${l-20} ${d} ${t} ${d} ${t} ${d+n*r}L${t} ${e-n*r}C${t} ${e} ${t} ${e} ${t-r} ${e}L${o.x+8} ${e}C${o.x} ${e} ${o.x} ${e} ${o.x} ${o.y}`}v.setAttribute("d",a),w.setAttribute("r",o.bubble?"0":"4"),w.setAttribute("cx",String(o.x)),w.setAttribute("cy",String(o.y)),g.classList.add("show")},destroy(){be(),window.removeEventListener("pointerdown",me,!0),window.removeEventListener("click",ge,!0),window.removeEventListener("pointerover",ve,!0),window.removeEventListener("pointerout",ve,!0),window.clearTimeout(k),window.removeEventListener("keydown",xe,!0),l.remove(),m.remove(),g.remove(),a.remove()}}}var zn="[data-pipeup-slide]",Dn=["scroll","resize","keyup","click","transitionend","slidechanged"],On=null,Fn=null,In=new Set,Bn=new Set,jn=e=>{try{e()}catch(e){globalThis.reportError?.(e)}};function Hn(e){let t=null;if(e){t={};let n=0;for(let[o,r]of Object.entries(e))if(!("string"!=typeof r||"slide"===o||o.length>64||r.length>200)){if(++n>=16)break;t[o]=r}}On=t;for(let e of Bn)e()}function Wn(e){return In.add(e),()=>{In.delete(e)}}function Un(e){Fn="function"==typeof e?.current&&"function"==typeof e.go?e:null}var Kn=()=>{let e=window.Reveal;return"function"==typeof e?.getIndices&&"function"==typeof e.slide?e:null};var Yn=["pipeup-quote","pipeup-on","pipeup-done"],Vn={"pipeup-quote":[[250,227,188,.75],[250,200,100,.28]],"pipeup-on":[[247,212,154,.95],[250,200,100,.42]],"pipeup-done":[[180,178,169,.22],[180,178,169,.2]]};function _n(){return typeof CSS<"u"&&"highlights"in CSS&&typeof Highlight<"u"}var Gn=`:not([data-pipeup-ignore],[data-pipeup-ignore] *){cursor:url("data:image/svg+xml,${encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><rect x='7' y='7' width='23' height='23' rx='4' fill='none' stroke='#534AB7' stroke-width='2' stroke-dasharray='4 3'/><path d='M3 2v15l4-3.5 3 6.5 2.5-1.2-3-6.3H15z' fill='#fff' stroke='#2C2C2A' stroke-width='1.2' stroke-linejoin='round'/></svg>")}") 3 2,crosshair!important}`;function Zn(){if(_n())for(let e of Yn)CSS.highlights.delete(e)}var Jn,Xn=':host{all:initial;direction:ltr;unicode-bidi:normal}*{box-sizing:border-box}button{appearance:none;font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}svg{display:block}.layer{all:initial;direction:ltr;unicode-bidi:normal;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:#6B6A64;--ln:#E5E3DA;--ru:#ECEAE2;--so:#FAFAF7;--su:#FFFFFF;--ho:#F1EFE8;--as:color-mix(in srgb,var(--pu-accent,#534AB7) 12%,transparent);--sh:0 8px 28px rgba(44,44,42,.1);--in:.26s;--mv:.34s;--out:.2s;--pl:1.2s;--eo:cubic-bezier(.22,.61,.36,1);--eio:cubic-bezier(.4,0,.2,1);--ei:cubic-bezier(.4,0,1,1);--pu-text:var(--k);--pu-muted:var(--mu);--pu-faint:var(--fa);--pu-line:var(--ln);--pu-surface:var(--su);--pu-soft:var(--so);--pu-hover:var(--ho);--pu-shadow:var(--sh);--pu-ease:var(--eo)}.layer{transition:opacity .24s var(--eo)}.layer.sw{opacity:0;transition-duration:.16s;transition-timing-function:var(--ei)}.layer.dark{--k:#ECEBE6;--mu:#B4B2A9;--fa:#9A9892;--ln:#3A3936;--ru:#34332F;--so:#22221F;--su:#1B1B19;--ho:#2C2C29;--sh:0 8px 28px rgba(0,0,0,.45)}.layer.hidden .bub,.layer.hidden .col,.layer.hidden .pop,.layer.hidden .tip,.layer.hidden .mark,.layer.hidden .selbar{opacity:0!important;pointer-events:none!important}.tx{font-size:14px;line-height:1.5;color:var(--k);white-space:pre-wrap;overflow-wrap:anywhere}.tx.del,.who,.rest,.ctx{color:var(--fa)}.who,.rest{font-size:12px}.who{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.rft>.who{display:block}.ctx[hidden]{display:none}.ctx{font-size:12px;margin-bottom:3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.clamp{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.tx a{color:var(--pu-accent);text-decoration:underline;text-decoration-thickness:1px;text-underline-offset:2px}.ft,.rft{display:grid;grid-template-rows:0fr;opacity:0;transition:grid-template-rows var(--in) var(--eo),opacity var(--in) var(--eo)}.ft>*,.rft>*{overflow:hidden;min-height:0;display:flex;align-items:center}.root:hover>.ft,.root:focus-within>.ft,.it:hover>.rft,.it:focus-within>.rft{grid-template-rows:1fr;opacity:1}.ft.has-rest,.ft.open,.rft.open{grid-template-rows:1fr;opacity:1}.ft.has-rest>*{grid-area:1/1}.ft .hover{opacity:0;transition:opacity var(--in) var(--eo)}.ft .rest{transition:opacity var(--in) var(--eo)}.root:hover>.ft .hover,.root:focus-within>.ft .hover,.ft:not(.has-rest) .hover{opacity:1}.root:hover>.ft .rest,.root:focus-within>.ft .rest{opacity:0}.acts{margin-left:6px;display:flex;flex:none}.ib{width:24px;height:22px;display:grid;place-items:center;border-radius:6px;color:var(--mu);transition:background-color .2s var(--eo),color .2s var(--eo)}.ib:hover,.ib:focus-visible{background:var(--ho);color:var(--k);outline:none}.rps,.rbox{padding-left:14px}.rps .it{padding-top:6px}.more{display:grid;grid-template-rows:1fr;transition:grid-template-rows var(--mv) var(--eio)}.more>div{overflow:hidden;min-height:0}.th:not(.on) .more{grid-template-rows:0fr}.row{position:relative;display:flex;align-items:center;gap:8px;padding:8px 0 2px;cursor:text}.input{flex:1;min-width:0;height:27px;display:block;border:0;border-bottom:1px solid var(--ln);outline:none;resize:none;overflow:hidden;font:inherit;font-size:14px;line-height:1.5;padding:3px 0;color:var(--k);background:transparent;transition:border-color var(--in) var(--eo)}.row:hover .input,.input:hover{border-bottom-color:var(--mu)}.input:focus{border-bottom-color:var(--pu-accent)}.ed{display:flex;gap:10px;align-items:center;min-height:34px;padding:6px 10px}.ed .input{font-size:13px;height:22px}.root,.it{position:relative;padding-right:30px}.av{display:grid;place-items:center;width:22px;height:22px;border-radius:32%;font-size:12px;font-weight:600;line-height:1;opacity:0;transform:scale(.85);transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.av.in{opacity:1;transform:none}.av svg{width:80%;height:80%}.root>.av,.it>.av{position:absolute;top:0;right:0}.it>.av{top:6px}.av{--av-l:92%;--av-d:30%;--s:60%;background:hsl(var(--h) var(--s) var(--av-l));color:hsl(var(--h) var(--s) var(--av-d))}.dark .av{--av-l:20%;--av-d:78%}.av.ai{position:relative;border-radius:50%;background:var(--su);color:var(--pu-accent);font-size:9px;letter-spacing:.02em}.av.ai:before{content:"";position:absolute;inset:3px;border-radius:50%;border:1.5px solid var(--pu-accent);pointer-events:none}.root>.av.ai,.it>.av.ai{position:absolute}.refs{display:flex;flex-wrap:wrap;gap:4px;margin-top:6px;white-space:normal}.refs .ref{display:inline-flex;align-items:center;gap:5px;max-width:160px;padding:1px 9px;border:1px solid var(--ln);border-radius:999px;background:var(--so);color:var(--mu);font:inherit;font-size:11.5px;line-height:1.6;text-decoration:none;cursor:pointer;transition:background-color .2s var(--eo),color .2s var(--eo),border-color .2s var(--eo)}.refs .ref:hover,.refs .ref:focus-visible{background:var(--as);color:var(--pu-accent);border-color:var(--pu-accent);outline:none}.ref span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rxp{position:fixed;width:320px;height:340px;border-radius:12px;overflow:hidden;pointer-events:none;opacity:0;transform:translateY(4px);transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.rxp.show{opacity:1;transform:none;pointer-events:auto}.mn{border-radius:4px;padding:0 2px;background:var(--as);color:var(--pu-accent)}.mn.me{font-weight:600}.mnl{position:absolute;left:0;bottom:100%;margin:0 0 4px;padding:4px;list-style:none;min-width:180px;max-width:100%;border:1px solid var(--ln);border-radius:10px;background:var(--su);box-shadow:var(--sh);opacity:0;transform:translateY(4px);pointer-events:none;z-index:4;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.mnl.show{opacity:1;transform:none;pointer-events:auto}.mnl li{display:flex;align-items:baseline;gap:8px;padding:5px 8px;border-radius:6px;font-size:13px;color:var(--k);cursor:pointer}.mnl li small{font-size:11px;color:var(--fa)}.mnl li.on,.mnl li:hover{background:var(--as);color:var(--pu-accent)}.dlg{position:fixed;left:50%;top:18vh;width:min(380px,calc(100vw - 32px));padding:16px 18px;border:1px solid var(--ln);border-radius:14px;background:var(--su);box-shadow:var(--sh);color:var(--k);opacity:0;transform:translate(-50%,6px);pointer-events:none;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.dlg.show{opacity:1;transform:translate(-50%);pointer-events:auto}.dlg-t{margin:0 0 8px;font-size:15px;font-weight:600}.dlg-b p{margin:0 0 8px;font-size:13px;line-height:1.5;color:var(--mu)}.dlg-c{display:block;margin:8px 0;padding:8px 10px;border-radius:8px;background:var(--so);font:12px/1.6 ui-monospace,monospace;word-break:break-all;user-select:all}.dlg-f{width:100%;margin:6px 0;padding:8px;border:1px solid var(--ln);border-radius:8px;background:var(--so);color:var(--k);font:12px/1.5 ui-monospace,monospace}.dlg-m{min-height:1.2em;margin:4px 0;font-size:12px;color:var(--pu-accent)}.dlg-a{display:flex;gap:6px;justify-content:flex-end;margin-top:6px}.dlg-btn{padding:6px 12px;border:1px solid var(--ln);border-radius:8px;font-size:13px;color:var(--k);transition:background-color .2s var(--eo)}.dlg-btn:hover,.dlg-btn:focus-visible{background:var(--ho);outline:none}.dlg-btn.primary{border-color:var(--pu-accent);color:var(--pu-accent)}.toast.act{pointer-events:auto}.ta{margin-left:4px;color:var(--pu-accent);text-decoration:underline;text-underline-offset:2px}.dlg-h{margin:12px 0 4px;font-size:13px;font-weight:600}.rx .n{font-size:11px}.rx.mine{background:var(--as);color:var(--pu-accent);border-color:var(--pu-accent)}.rx:disabled{cursor:default;opacity:.7}.rx.new,.rxq.new{animation:pu-in var(--mv) var(--eo) both}.rxs{align-items:center}.rxq{display:inline-flex;gap:2px}.rxo{padding:2px 5px;border-radius:8px;font-size:16px;line-height:1.3;transition:background-color .2s var(--eo)}.rxo:hover,.rxo:focus-visible,.rxo[aria-pressed=true]{background:var(--as);outline:none}.rrow{min-width:0;flex:1;display:flex;align-items:center}.refs .ref{position:relative}.ref .rc{position:absolute;left:0;top:calc(100% + 6px);z-index:3;width:max-content;max-width:min(240px,70vw);padding:6px 9px;border:1px solid var(--ln);border-radius:8px;background:var(--su);box-shadow:var(--sh);color:var(--k);font-size:12px;line-height:1.45;white-space:normal;text-align:left;overflow:visible;opacity:0;visibility:hidden;transform:translateY(-3px);pointer-events:none;transition:opacity .2s var(--eo),transform .2s var(--eo),visibility 0s .2s}.ref:hover .rc,.ref:focus-visible .rc{opacity:1;visibility:visible;transform:none;transition-delay:0s}.ref .sl{width:10px;height:7px;border:1.3px solid currentColor;border-radius:2px;flex:none}.seen{display:flex;align-items:center;gap:6px;padding:6px 0 0 14px;font-size:12px;color:var(--fa)}.seen button{margin-left:auto;padding:0 6px;border:0;border-radius:6px;background:none;color:var(--fa);font:inherit;cursor:pointer;transition:color .2s var(--eo),background-color .2s var(--eo)}.seen button:hover,.seen button:focus-visible{color:var(--pu-accent);background:var(--as);outline:none}.seen i{width:12px;height:12px;border-radius:50%;border:1.5px solid var(--pu-accent);flex:none}.c0{--h:0}.c1{--h:25}.c2{--h:50}.c3{--h:130}.c4{--h:175}.c5{--h:215}.c6{--h:270}.c7{--h:330}.c8{--h:28;--s:35%}.c9{--h:220;--s:8%}.me{flex:none;display:grid}.me>.av{grid-area:1/1;width:26px;height:26px;font-size:13px}.you{display:grid;padding:0 34px;min-height:24px;font-size:12px;color:var(--fa)}.you>*{grid-area:1/1;display:flex;align-items:center;min-width:0;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.say{white-space:pre;overflow:hidden}.nm{min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.say button{flex:none}.say button{color:var(--mu);text-decoration:underline;text-decoration-color:var(--ln);text-underline-offset:2px;transition:color .2s var(--eo)}.say button:hover,.say button:focus-visible{color:var(--pu-accent);outline:none}.nf{opacity:0;transform:translateY(-4px);pointer-events:none}.nf .input{font-size:13px;height:24px}.you.naming .nf{opacity:1;transform:none;pointer-events:auto}.you.naming .say{opacity:0;pointer-events:none}.send{width:26px;height:26px;border-radius:50%;display:grid;place-items:center;color:var(--pu-accent);flex:none;opacity:0;pointer-events:none;transition:opacity var(--in) var(--eo),background-color .2s var(--eo)}.send.show{opacity:1;pointer-events:auto}.send:hover{background:var(--as)}.bub{position:fixed;left:0;top:0;width:20px;height:20px;margin:-20px 0 0 -2px;border-radius:50% 50% 50% 0;background:var(--pu-accent);border:2px solid var(--su);box-shadow:0 1px 4px #0003;pointer-events:auto;opacity:0;transform:translateY(-6px) scale(.9);transform-origin:2px 20px;transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.bub.in{opacity:1;transform:none;transition:opacity var(--in) var(--eo),transform var(--in) var(--eo)}.bub.in:hover,.bub.on{transform:scale(1.18)}.bub.done{background:var(--fa)}.bub.ghost{pointer-events:none}.tip,.pop,.menu,.all,.xp,.toast,.selbar,.namebar,.ttip,.tt,.mode,.rxp{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;background:var(--su);border-radius:8px;pointer-events:auto;cursor:pointer;box-shadow:inset 2px 0 0 transparent;transition:transform var(--mv) var(--eio),box-shadow var(--in) var(--eo),opacity var(--in) var(--eo)}.th.hot{box-shadow:inset 2px 0 0 var(--ln)}.th.on{box-shadow:inset 2px 0 0 var(--pu-accent);cursor:default}.th.dim{opacity:.45}.th.resolved:not(.on):not(.hot){opacity:.6}.th.lost .ctx{white-space:normal}.th.wait{opacity:0!important;pointer-events:none}.th.out{opacity:0!important;pointer-events:none;transition:opacity var(--out) var(--ei)}.th:has(.opn:focus-visible){box-shadow:inset 2px 0 0 var(--ln);outline:2px solid var(--pu-accent);outline-offset:2px;border-radius:4px}.selbar{position:fixed;display:flex;border-radius:10px;padding:2px;opacity:0;transform:translateY(4px);pointer-events:none;transition:opacity var(--in) var(--eo),transform .3s var(--eo)}.selbar.show{opacity:1;transform:none;pointer-events:auto}.selbar button{width:32px;height:30px;display:grid;place-items:center;border-radius:8px;color:var(--pu-accent);transition:background-color .2s var(--eo)}.selbar button:hover,.selbar button:focus-visible{background:var(--as);outline:none}.pick{position:fixed;left:0;top:0;border:2px solid color-mix(in srgb,var(--pu-accent) 70%,transparent);background:color-mix(in srgb,var(--pu-accent) 6%,transparent);border-radius:8px;pointer-events:none;opacity:0;transition:opacity var(--out) var(--ei),border-color var(--out) var(--ei),border-width var(--out) var(--ei),box-shadow var(--out) var(--ei)}.pick.show{opacity:1;transition-duration:var(--in);transition-timing-function:var(--eo)}.pick.show.glide{transition-property:all;transition-duration:var(--mv);transition-timing-function:var(--eio)}.pick.on{border-color:var(--pu-accent)}.pick.kf{border:3px solid var(--pu-accent);box-shadow:0 0 0 2px var(--su)}.km{position:fixed;left:0;top:0;pointer-events:none;outline:none}.sr,.mn-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.namebar{position:fixed;left:0;top:0;display:flex;align-items:center;gap:2px;padding:2px 2px 2px 10px;border-radius:10px;font-size:12px;color:var(--mu);white-space:nowrap;pointer-events:none;opacity:0;transform:translateY(4px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.namebar.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform .3s var(--eo)}.namebar.show.glide{transition-property:all;transition-duration:var(--mv);transition-timing-function:var(--eio)}.namebar .lbl{margin-right:6px;max-width:260px;overflow:hidden;text-overflow:ellipsis}.namebar .nb{padding:4px;display:grid;place-items:center;border-radius:7px;transition:background-color .2s var(--eo),color .2s var(--eo)}.namebar .nb:hover,.namebar .nb:focus-visible{background:var(--ho);color:var(--k);outline:none}.namebar .nb[hidden]{display:none}.launch{position:fixed;right:20px;bottom:20px;pointer-events:auto}.launch .mode{position:relative;display:grid;place-items:center;width:46px;height:46px;border-radius:50%;transition:background-color .3s var(--eo),color .3s var(--eo)}.mode>*,.cnt>*{grid-area:1/1}.mode>*{display:grid;place-items:center;transition:opacity var(--in) var(--eo)}.cnt,.has>.plus{opacity:0}.has>.cnt{opacity:1}.n{font-size:12px;font-weight:500;line-height:1;margin:-1.4px 0 0 1.4px;font-variant-numeric:tabular-nums;opacity:0;transition:opacity var(--in) var(--eo)}.n.s{font-size:9.5px;letter-spacing:-.04em}.n.on{opacity:1}.launch .mode:hover,.launch .mode[aria-expanded=true]{background:var(--ho)}.launch .mode.on{background:var(--pu-accent);color:var(--pu-on,#fff)}.mode>.dot{position:absolute;top:3px;right:3px;width:9px;height:9px;border-radius:50%;background:var(--pu-accent);border:2px solid var(--su);opacity:0}.mode.else>.dot{opacity:1}.ttip{position:absolute;right:0;bottom:54px;white-space:nowrap;border-radius:8px;padding:4px 9px;font-size:12px;pointer-events:none;opacity:0;transform:translateY(3px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.ttip small{margin-left:8px}.ttip small,.mi .kc{font-size:12px;color:var(--fa)}.mode:hover+.ttip,.mode:focus-visible+.ttip{opacity:1;transform:none;transition:opacity var(--in) var(--eo) .5s,transform var(--in) var(--eo) .5s}.launch .mode[aria-expanded=true]+.ttip{opacity:0;transition:opacity var(--out) var(--ei)}@media(hover:none){.ttip,.tt{display:none}}.menu{position:fixed;right:20px;bottom:76px;width:290px;border-radius:12px;padding:4px;pointer-events:none;opacity:0;transform:translateY(6px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.menu.show{opacity:1;transform:none;pointer-events:auto;transition:opacity var(--in) var(--eo),transform var(--mv) var(--eo)}.mi{position:relative;display:flex;gap:10px;align-items:center;width:100%;min-height:34px;text-align:left;padding:6px 10px;border-radius:8px;transition:background-color .2s var(--eo)}.mi:hover,.mi:focus-visible{background:var(--so);outline:none}.mi svg{color:var(--mu);flex:none}.mi small{display:block;color:var(--fa);font-size:12px}.lb{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ma{flex:none;display:grid;margin:-2px 0}.ma .av{width:20px;height:20px;font-size:11px}.mi .av svg{color:inherit}.sep{height:1px;margin:4px 10px;background:var(--ru)}.tt{position:absolute;right:calc(100% + 14px);top:50%;translate:0 -50%;width:max-content;max-width:220px;padding:4px 9px;border-radius:8px;font-size:12px;line-height:1.4;color:var(--mu);pointer-events:none;opacity:0;transform:translate(3px);transition:opacity var(--out) var(--ei),transform var(--out) var(--ei)}.mi:hover>.tt,.mi:focus-visible>.tt{opacity:1;transform:none;transition:opacity var(--in) var(--eo) .5s,transform var(--in) var(--eo) .5s}@media(max-width:600px){.tt{right:8px;top:auto;bottom:100%;translate:none;transform:translateY(3px)}}.sw{position:relative;flex:none;width:26px;height:16px;border-radius:8px;background:var(--ln);transition:background-color var(--mv) var(--eio)}.sw:before,.sw:after{content:"";position:absolute;top:2px;left:2px;width:12px;height:12px;border-radius:50%;background:#fff;box-shadow:0 1px 2px #00000040;transition:transform var(--mv) var(--eio),opacity var(--mv) var(--eio)}.sw:before{opacity:0;transform:translate(10px)}[aria-checked=true]>.sw{background:var(--pu-accent)}[aria-checked=true]>.sw:after{transform:translate(10px)}.tools{display:flex;flex:none;gap:2px}.tools[hidden]{display:none}.tool[aria-pressed=true]{background:var(--as);color:var(--pu-accent)}.note{display:block;padding:0 0 4px;font-size:12px;color:var(--fa)}.note[hidden]{display:none}.ov{position:absolute;inset:0;pointer-events:none;overflow:hidden}.xb{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px 16px 16px;font-size:13px}.xb p{margin:0 0 10px}.all,.xp{position:fixed;top:0;right:0;bottom:0;width:var(--pu-panel);display:flex;flex-direction:column;border-width:0 0 0 1px;opacity:0;transform:translate(100%);transition:transform var(--out) var(--ei),opacity var(--out) var(--ei)}.all.show,.xp.show{opacity:1;transform:none;pointer-events:auto;transition:transform var(--mv) var(--eo),opacity var(--in) var(--eo)}.all.full{width:100%}.hd{display:flex;align-items:center;gap:8px;padding:12px 10px 8px 16px;font-weight:600}.pn{font-weight:400;color:var(--fa)}.hs{margin-left:auto;display:flex;align-items:center;gap:6px;padding:3px 4px 3px 6px;border-radius:6px;font-size:12px;font-weight:400;color:var(--mu);transition:background-color .2s var(--eo)}.hs:hover,.hs:focus-visible{background:var(--ho);outline:none}.list{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px}.all .mi{align-items:flex-start}.all .mi>.av{flex:none}.all .mi>span:last-child{flex:1;min-width:0}.all .mi small{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.all .mi.done{opacity:.6}.all .mi.open{background:var(--so)}.all .mi.open>.av,.all .mi.open .clamp{display:none}.xr{padding:2px 12px 10px 16px}.cx{position:fixed;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none;opacity:0;transition:opacity var(--in) var(--eo)}.cx.show{opacity:1}.cx path{fill:none;stroke:var(--pu-accent);stroke-width:1.5;stroke-linecap:round;opacity:.7}.cx circle{fill:var(--pu-accent)}.layer.listing .col{opacity:0;transition:opacity var(--out) var(--ei)}.sec{padding:8px 10px 2px;font-size:12px;color:var(--fa)}.ag{display:flex;align-items:center;gap:8px;padding:6px 14px;font-size:12px;color:var(--fa);border-bottom:1px solid var(--ln)}.ag[hidden]{display:none}.lns{display:flex;flex-direction:column}.ln{display:grid;grid-template-rows:0fr;opacity:0;transition:grid-template-rows var(--in) var(--eo),opacity var(--in) var(--eo)}.ln.show{grid-template-rows:1fr;opacity:1}.ln>.lw{overflow:hidden;min-height:0}.ag button{margin-left:auto;flex:none;padding:0 6px;border-radius:6px;color:var(--fa);transition:color .2s var(--eo),background-color .2s var(--eo)}.ag button:hover:not(:disabled),.ag button:focus-visible{color:var(--pu-accent);background:var(--as);outline:none}.ag button:disabled{opacity:.5;cursor:default}.adr{margin:8px 0 0 14px;padding:8px 10px;border-radius:8px;background:var(--so);font-size:13px;color:var(--k);animation:pu-in var(--mv) var(--eo) both}.adr small{display:block;font-size:12px;color:var(--fa)}.adr .go{display:flex;gap:6px;margin-top:6px}.adr .go button{padding:2px 8px;border-radius:6px;font-size:12px;color:var(--mu);transition:color .2s var(--eo),background-color .2s var(--eo)}.adr .go button:hover,.adr .go button:focus-visible{color:var(--pu-accent);background:var(--as);outline:none}@keyframes pu-in{0%{opacity:0;transform:translateY(3px)}to{opacity:1;transform:none}}.sec b{margin-left:6px;font-weight:500;color:var(--pu-accent)}.toast{position:fixed;left:50%;bottom:28px;border-radius:10px;padding:8px 14px;font-size:13px;opacity:0;transform:translate(-50%,6px);transition:opacity .3s var(--eo),transform .36s var(--eo)}.toast.show{opacity:1;transform:translate(-50%)}@media(forced-colors:active){.pick.kf{border:3px solid Highlight}.layer :is(.ib,.mi,.nb,.hs,.selbar button,.say button,.xb button):focus-visible{outline:2px solid Highlight}}@media(prefers-reduced-motion:reduce){.ln{transition-property:opacity}@keyframes pu-in{0%{opacity:0}to{opacity:1}}.bub,.bub.in,.bub.in:hover,.bub.on,.tip,.pop,.selbar,.menu,.all,.xp,.ttip,.tt,.toast,.ref .rc,.rxp,.mnl{transform:none!important}.dlg{transform:translate(-50%)!important}.sw:after{transform:none!important;transition-property:opacity}[aria-checked=true]>.sw:after{opacity:0}[aria-checked=true]>.sw:before{opacity:1}.th{transition-property:opacity,box-shadow}.tip.show{transition-property:opacity}.pick,.pick.show{transition:opacity .16s ease-in-out}.all,.all.show,.xp,.xp.show{transition-property:opacity}.namebar,.namebar.show{transform:none!important;transition:opacity .16s ease-in-out}.av,.nf{transform:none!important}@keyframes pu-pulse{0%{opacity:0}35%{opacity:.85}to{opacity:0}}}',Qn="#534AB7";function eo(e,t){let n=function(e){let t=/rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)/.exec(e);if(!t||void 0===t[1]||void 0===t[2]||void 0===t[3])return null;let n=void 0===t[4]?1:t[4].endsWith("%")?parseFloat(t[4])/100:parseFloat(t[4]);return{r:Number(t[1]),g:Number(t[2]),b:Number(t[3]),a:n}}(e);if(n||!e||"transparent"===e)return n;try{if(Jn??=t.createElement("canvas").getContext("2d",{willReadFrequently:!0})??null,!Jn)return null;Jn.clearRect(0,0,1,1),Jn.fillStyle="#000",Jn.fillStyle=e,Jn.fillRect(0,0,1,1);let[n,o,r,i]=Jn.getImageData(0,0,1,1).data;return{r:n,g:o,b:r,a:i/255}}catch{return null}}function to(e){let t=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return.2126*t(e.r)+.7152*t(e.g)+.0722*t(e.b)}var no=(e,t)=>(Math.max(e,t)+.05)/(Math.min(e,t)+.05),oo=[[.92,.25],[.92,.6],[.5,.45]];function ro(e){let t=e.defaultView,n=e.documentElement,o=t?.getComputedStyle(n).colorScheme||"",r=/dark/.test(o)&&(!/light/.test(o)||!0===t?.matchMedia?.("(prefers-color-scheme: dark)").matches),i=t?eo(t.getComputedStyle(n).backgroundColor,e):null;return t&&e.body&&(!i||i.a<.5)&&(i=eo(t.getComputedStyle(e.body).backgroundColor,e)),i&&i.a>=.5?i:r?{r:0,g:0,b:0}:{r:255,g:255,b:255}}function io(e,t){let n=e.ownerDocument,o=n.defaultView,r="dark"===t;if(!o)return{font:"system-ui, sans-serif",accent:Qn,dark:r,on:"#fff"};let i=n.documentElement,a=o.getComputedStyle(e).fontFamily||"system-ui, sans-serif",l=(o.getComputedStyle(i).getPropertyValue("--pipeup-accent")||i.style.getPropertyValue("--pipeup-accent")).trim(),s=e.querySelector("a[href]"),d=s?o.getComputedStyle(s).color:"",c=d&&"rgb(0, 0, 238)"!==d?eo(d,n):null,p=c&&no(to(c),r?.011:1)>=3,u=l||(p?d:r?"#9A94EE":Qn),h=eo(u,n);return{font:a,accent:u,dark:r,on:h&&no(to(h),1)<3?"#111":"#fff"}}function ao(e,t){e.style.setProperty("--pu-font",t.font),e.style.setProperty("--pu-accent",t.accent),e.style.setProperty("--pu-on",t.on),e.classList.toggle("dark",t.dark)}var lo={light:["#2C2C2A","#FFFFFF"],dark:["#ECEBE6","#1B1B19"]},so=[["opacity","1"],["filter","none"],["backdrop-filter","none"],["mix-blend-mode","normal"],["transform","none"],["clip-path","none"],["mask-image","none"],["zoom","1"]];function co(e,t,n){let[o,r]=lo[e].map(e=>{let[o,r,i]=(e=>[1,3,5].map(t=>parseInt(e.slice(t,t+2),16)))(e).map((e,o)=>t*e+(1-t)*n[o]);return to({r:o,g:r,b:i})});return((e,t)=>(Math.max(e,t)+.05)/(Math.min(e,t)+.05))(o,r)}var po={shape:"That doesn't look like a recovery code. It starts with PU1 and is about 60 characters long.",mistake:"The code has a mistake in it. Check it against where you kept it, character by character."};function uo(e,t=!1){return Ln(e,t)?"column":"bubbles"}var ho="Shown here, but not saved yet — it will be saved with your next change",fo=e=>e instanceof Error?e.message.replace(/^pipeup: /,""):"Something went wrong";function mo(e){let t="pipeup:look",n="auto";try{let e=localStorage.getItem(t);("light"===e||"dark"===e)&&(n=e)}catch{}let o,r=!1,i="",a=()=>{let e="auto"!==n?n:function(e){let t=e.documentElement.getAttribute("data-pipeup-theme")??e.body?.getAttribute("data-pipeup-theme");return"light"===t||"dark"===t?t:null}(document),t=e??(function(e,t=!1){let n=e.defaultView;if(!n)return!1;let o=e.documentElement,r=to(ro(e)),i=(t,n)=>{try{if(e.elementsFromPoint)return e.elementsFromPoint(t,n)}catch{}return e.body?[e.body,o]:[o]},a=0;for(let[t,o]of oo){let l=r;for(let r of i(n.innerWidth*t,n.innerHeight*o)){if(r.closest("[data-pipeup-ignore]"))continue;let t=r.getBoundingClientRect();if(t.width*t.height<.25*n.innerWidth*n.innerHeight)continue;let o=eo(n.getComputedStyle(r).backgroundColor,e);if(o&&o.a>=.5){l=to(o);break}}a+=l}let l=a/oo.length;return l<.18||!(l>.32)&&t}(document,r)?"dark":"light");o=function(e,t,n){let o=e.defaultView?.getComputedStyle(e.documentElement),r=so.flatMap(([e,t])=>{let n=o?.getPropertyValue(e).trim();return n&&n!==t?[`${e}: ${n}`]:[]}),i=Math.min(1,Math.max(0,parseFloat(o?.opacity??"1")||1)),{r:a,g:l,b:s}=ro(e);return{look:t,source:n,ratio:co(t,i,[a,l,s]),effects:r}}(document,t,"auto"!==n?"reviewer":e?"author":"page");let a=function(e){return!e.effects.length&&e.ratio>=3?null:`pipeup: the page's styles on <html> (${e.effects.join("; ")||"none"}) change how everything on the page looks, Pipeup included, and can't be undone from inside it. `+(e.ratio<3?"Pipeup's words may be hard to read. ":"")+"Move those styles to <body> or a wrapper."}(o);return a&&a!==i&&console.warn(i=a),t};r="dark"===a();let l=io(e.root,r?"dark":"light"),s=function(e,t=document){let n=t.createElement("pipeup-root");n.setAttribute("data-pipeup-ignore",""),n.style.cssText="position:fixed!important;inset:0!important;pointer-events:none!important;z-index:2147483000!important;display:block!important;margin:0!important;visibility:visible!important;opacity:1!important;transform:none!important;filter:none!important;";let o=n.attachShadow({mode:"open"}),r=t.defaultView?.CSSStyleSheet;if(r&&"replaceSync"in r.prototype&&"adoptedStyleSheets"in o){let e=new r;e.replaceSync(Xn),o.adoptedStyleSheets=[e]}else{let e=t.createElement("style");e.textContent=Xn,o.append(e)}let i=t.createElement("div");return i.className="layer",i.style.setProperty("--pu-panel","320px"),i.style.setProperty("--pu-pop",`${Jt()}px`),ao(i,e),o.append(i),t.documentElement.append(n),{element:n,shadow:o,t:i,destroy:()=>n.remove()}}(l),d=function(e=document,t=!1){let n=e.defaultView?.CSSStyleSheet;if(!n||!("replaceSync"in n.prototype)||!("adoptedStyleSheets"in e))return{Ee(){},Se(){},ce(){},dark(){},Te(){},remove:()=>Zn()};let o=new n,r=null,i=!1,a=1,l=t,s=0,d="",c=0,p=()=>o.replaceSync(((e,t)=>Yn.map(n=>{let[o,r,i,a]=Vn[n][e?1:0];return`::highlight(${n}){background-color:rgba(${o},${r},${i},${+(a*t).toFixed(3)})}`}).join(""))(l,a)+(null===r?"":`:root{--pipeup-gutter:${r}px}`)+(i?Gn:"")+(s||d?`html{--pipeup-panel:${s}px;${s?`margin-right:${s}px!important;`:""}${d}}`:""));return p(),e.adoptedStyleSheets=[...e.adoptedStyleSheets,o],{Ee(e){e!==r&&(r=e,p())},Se(e){e!==i&&(i=e,p())},ce(e){a=e,p()},dark(e){e!==l&&(l=e,p())},Te(e,t){e!==s&&(s=e,d=t?"":"transition:margin-right .34s cubic-bezier(.4,0,.2,1)!important",clearTimeout(c),!e&&d&&(c=window.setTimeout(()=>{d="",p()},400)),p())},remove(){clearTimeout(c),e.adoptedStyleSheets=e.adoptedStyleSheets.filter(e=>e!==o),Zn()}}}(document,l.dark);d.ce(0);let p=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,g=document.documentElement.hasAttribute("data-pipeup-reserve"),v=new Map,w=new Set,y=new WeakSet,b={i:null,w:null,$:!1,mine:!1,hidden:!0,mode:uo(e.root),o:null,c:!1,p:!1,Ae:!1,s:!1},E=Je("div",{class:"toast",role:"status","aria-live":"polite"}),$=Je("div",{class:"sr","aria-live":"polite"});s.t.append(E,$);let S=null,L=[],C=null,M=!1,A=0,T=0,P=0,q=0,N=0,R=new Set,z="",D=new Map,O=function(e,t,n=function(){return{l:e=>e.getBoundingClientRect(),shown:e=>!1!==e.checkVisibility?.({opacityProperty:!0,visibilityProperty:!0}),opacity:e=>parseFloat(getComputedStyle(e).opacity)||0,ie:()=>({width:window.innerWidth,height:window.innerHeight})}}()){let o=!0===window.matchMedia?.("(prefers-reduced-motion: reduce)").matches,r=null,i=null,a=0,l=!1,s=()=>[...e.querySelectorAll(zn)],d=()=>[...e.querySelectorAll(".slides > section")],c=e=>"string"==typeof e&&e.length>0&&e.length<=200?e:null,p=e=>c(e?.getAttribute("data-pipeup-slide"));function u(){if(Fn){let e=null;if(jn(()=>{let t=Fn.current();Number.isInteger(t)&&t>0&&(e=String(t))}),null!==e)return e}let e=Kn();if(e){let t=null;if(jn(()=>{let n=e.getIndices().h,o=d()[n];t=p(o?.matches(zn)?o:o?.querySelector(zn))??c(String(n+1))}),null!==t)return t}return r&&!r.isConnected&&(r=null),r=function(e,t,n){let o=t.ie(),r=null,i=0,a=0;for(let l of e){if(!t.shown(l))continue;let e=t.l(l),s=Math.min(e.left+e.width,o.width)-Math.max(e.left,0),d=Math.min(e.top+e.height,o.height)-Math.max(e.top,0);if(s<=0||d<=0)continue;let c=Math.round(s*d),p=t.opacity(l);(c>i||c===i&&(p>a||p===a&&l===n))&&(r=l,i=c,a=p)}return r}(s(),n,r)??r,p(r)}function h(){a=0,i=u(),t()}let f=()=>{!a&&!l&&(a=requestAnimationFrame(h))},m=e=>function(e,t,n){return null!==t?void 0===e?.slide||e.slide===t:!e||!n||Object.entries(e).every(([e,t])=>"label"===e||"slide"===e||n[e]===t)}(e,i,On),g=new MutationObserver(e=>{e.some(e=>e.target instanceof Element&&e.target.matches(zn))&&f()});g.observe(e,{subtree:!0,attributes:!0,attributeFilter:["class","style","hidden"]});for(let e of Dn)window.addEventListener(e,f,{capture:!0,passive:!0});return Bn.add(f),i=u(),{slide:()=>i,view(e){let t=e instanceof Element?e:e?.parentElement,n=p(t?.closest(zn))??i,o={...null!==n?{slide:n}:{},...On};return Object.keys(o).length?o:void 0},m,H:function(e){if(m(e))return Promise.resolve(!0);let t=e.slide,n=Kn(),r=s().find(e=>p(e)===t),a=/^[1-9]\d{0,5}$/.test(t??"");if(a&&Fn)jn(()=>Fn.go(Number(t)));else if(a&&n){let e=r?d().findIndex(e=>e===r||e.contains(r)):-1;jn(()=>n.slide(e>=0?e:Number(t)-1))}else if(In.size)for(let t of In)jn(()=>t({...e}));else{if(!r)return Promise.resolve(!1);r.scrollIntoView({block:"start",behavior:o?"auto":"smooth"})}let c=performance.now();return new Promise(t=>{let n=e=>{clearTimeout(o),t(e)},o=setTimeout(()=>n(!1),1e3),r=()=>l?n(!1):(i=u(),m(e)?n(!0):performance.now()-c>=1e3?n(!1):void requestAnimationFrame(r));requestAnimationFrame(r)})},destroy(){l=!0,cancelAnimationFrame(a),g.disconnect();for(let e of Dn)window.removeEventListener(e,f,!0);Bn.delete(f)}}}(e.root,()=>{!M&&X()&&ie()}),F=!1,I=0;function B(e,t=2400,n=!1,o=!1,r){M||(F=n,E.textContent=e,E.classList.toggle("act",!!r),r&&E.append(" ",Je("a",{class:"ta",href:r.href,target:"_blank",rel:"noopener noreferrer"},r.label)),o?E.setAttribute("aria-hidden","true"):E.removeAttribute("aria-hidden"),E.classList.add("show"),window.clearTimeout(A),A=window.setTimeout(()=>E.classList.remove("show"),t))}function j(){F&&(F=!1,window.clearTimeout(A),E.classList.remove("show"))}function H(e){$.textContent="",cancelAnimationFrame(I),I=requestAnimationFrame(()=>$.textContent=e)}function W(e){B(fo(e))}function U(e){throw W(e),e}let K=t=>({thread:t,location:qe(t.anchor,v.get(t.id)??Se(t.anchor,e.root),e.root)}),Y={me:e.doc.me,picker:()=>Z.picker,people:()=>Et(e.doc.threads(),e.doc.me),react:async(t,n,o)=>{try{await(o?e.doc.react(t,n):e.doc.unreact(t,n))}catch(e){e instanceof Q?B(ho):U(e)}},reply:async(t,n,o)=>{try{await e.doc.reply(t,n,o),ue(o,n)}catch(e){e instanceof Q?B(ho):U(e)}},resolve:async t=>{try{await e.doc.resolve(t),B("Resolved · Show resolved brings it back")}catch(e){B(e instanceof Q?`Resolved · ${ho}`:fo(e))}(e=>b.i===e&&!b.$&&(C?.ae()?C.le():s.t.querySelector(".launch .mode")?.focus({preventScroll:!0}),!0))(t)&&(b.i=null)},reopen:async t=>{try{await e.doc.reopen(t),B("Reopened")}catch(e){B(e instanceof Q?`Reopened · ${ho}`:fo(e))}},notRight:async t=>{try{await e.doc.reopen(t)}catch(e){B(e instanceof Q?`Reopened · ${ho}`:fo(e))}ce(t)},close:()=>{me(null);let e=ae&&s.t.querySelector(ae);e?e.focus({preventScroll:!0}):C?.le(),ae=""},copy:t=>{try{let n=e.doc.threads().find(e=>e.id===t);if(!n)return;Pn(Oe(K(n),"ai",location.href,Date.now()),s.t).then(()=>B("Thread copied as Markdown for AI"),e=>B(fo(e)))}catch(e){B(fo(e))}}},V={look:()=>n,setLook(e){n=e;try{"auto"===e?localStorage.removeItem(t):localStorage.setItem(t,e)}catch{}Ne(a())},copyAll:async e=>{let t=V.all(),n=Fe(t,e,{title:document.title,url:location.href,exportedAt:new Date});try{await Pn(n,s.t);let o=t.filter(e=>!e.thread.resolved).length;B(`Copied ${o} thread${1===o?"":"s"}${"ai"===e?" as Markdown for AI":""}`)}catch(e){B(fo(e))}},Ge:()=>{b.$=!b.$,ie()},identity:()=>function(e,t){e.querySelector(".dlg")?.remove();let n=Je("div",{class:"dlg",role:"dialog","aria-label":"Your identity"}),o=Je("h2",{class:"dlg-t"}),r=Je("div",{class:"dlg-b"}),i=Je("p",{class:"dlg-m",role:"status"}),a=Je("div",{class:"dlg-a"});n.append(o,r,i,a);let l=!1,s=(e=!1)=>{l||(l=!0,n.classList.remove("show"),n.inert=!0,window.setTimeout(()=>n.remove(),260),e&&t.reload())},d=(e,t,n=!1)=>{let o=Je("button",{class:n?"dlg-btn primary":"dlg-btn",type:"button"},e);return o.addEventListener("click",()=>{t()}),o},c=(...e)=>e.map(e=>Je("p",{},e)),p=e=>i.textContent=e,u=(n,i)=>{o.textContent=i?"Your portable identity":"Back up my identity";let l=Je("code",{class:"dlg-c"},n);l.tabIndex=0,r.replaceChildren(...c("This code is you. Keep it somewhere safe, like a password manager. Anyone who has it can write as you, and Pipeup never sends it anywhere. Without it, a cleared browser starts you over as someone new."),l),a.replaceChildren(d("Copy code",()=>t.copy(n).then(()=>p("Copied."),()=>p("Your browser blocked copying; select the code and copy it by hand."))),d("Save as a file",()=>{let t=URL.createObjectURL(new Blob([`${n}\n`],{type:"text/plain"})),o=Je("a",{href:t,download:"pipeup-identity.pipeup-id"});e.append(o),o.click(),o.remove(),window.setTimeout(()=>URL.revokeObjectURL(t),1e3),p("Saved. Keep the file somewhere safe.")}),d(i?"Done, and use it now":"Done",()=>s(i),!0)),i&&p("It is kept in this browser now. Reload to use it; your earlier comments stay as they are.")};o.textContent="My identity",r.replaceChildren(...c(t.portable?"Your identity is portable: you have a recovery code for it.":"Your identity stays in this browser, so a cleared browser, or another computer, starts you over as someone new."));let h=Je("input",{class:"dlg-f",type:"text",maxlength:"120","aria-label":"Email or GitHub name",spellcheck:"false",placeholder:"you@example.org or gh:yourname"});h.value=t.contact.value;let f=d("Share",async()=>{let e=await t.contact.share(h.value);m.hidden=!e&&!t.contact.value,e&&(m.hidden=!1),p(e?"Shared with everyone who has this page's comments.":"That isn't an email address or a GitHub name (gh:yourname).")}),m=d("Stop sharing",async()=>{await t.contact.stop(),h.value="",m.hidden=!0,p("Stopped. People who see this page's comments from now on won't see it.")});m.hidden=!t.contact.value,r.append(Je("h3",{class:"dlg-h"},"Let people reach you"),...c("If you share an email address or a GitHub name, people who mention you can offer to let you know. Everyone who has this page's comments can see it."),h,Je("div",{class:"dlg-a"},m,f)),a.replaceChildren(d("Close",()=>s()),d("Use a recovery code",()=>{p(""),o.textContent="Use my identity";let e=Je("textarea",{class:"dlg-f",rows:"3","aria-label":"Recovery code",spellcheck:"false"}),n=Je("input",{type:"file",accept:".pipeup-id,text/plain","aria-label":"Choose a recovery file"});n.addEventListener("change",async()=>{let t=await(n.files?.[0]?.text());t&&(e.value=t.trim())}),r.replaceChildren(...c("Paste the recovery code you backed up, or choose its file. This replaces the identity in this browser."),e,n),a.replaceChildren(d("Cancel",()=>s()),d("Use this identity",async()=>{let n=await t.use(e.value);if(n)return p(po[n]);p(""),o.textContent="Done",r.replaceChildren(...c("Your identity is back. Comments you wrote on this page before stay as they are, and show as written by an earlier you.")),a.replaceChildren(d("Reload",()=>s(!0),!0))},!0))}),d(t.portable?"Back up my identity":"Make it portable",()=>{p(""),t.portable?(o.textContent="Back up my identity",r.replaceChildren(...c("One moment…")),t.code().then(e=>e?u(e,!1):p("This identity can't be backed up."))):(o.textContent="Make my identity portable",r.replaceChildren(...c("Your identity stays in this browser, and can't be taken out of it. To use it on another browser or computer, Pipeup makes you a new one that you can back up with a recovery code.",t.hasComments?"Comments you wrote before stay as they are, and show as written by an earlier you.":"You haven't written comments here yet, so nothing is left behind.")),a.replaceChildren(d("Not now",()=>s()),d("Make it portable",async()=>{try{u(await t.make(),!0)}catch{p("Something went wrong. Nothing was changed.")}},!0)))},!0)),n.addEventListener("keydown",e=>{e.stopPropagation(),"Escape"===e.key&&(e.preventDefault(),s())}),e.append(n),n.offsetWidth,n.classList.add("show"),n.querySelector("textarea, button.primary, button")?.focus({preventScroll:!0})}(s.t,{portable:e.doc.portable,code:()=>e.doc.identityCode(),make:async()=>{let t=await async function(){let e=crypto.getRandomValues(new Uint8Array(32));return{identity:await m(e),code:f(e)}}();return await e.onIdentity(t.identity),t.code},use:async t=>{let n=await async function(e){let t=e.toUpperCase().replace(/[\s-]+/g,"");if(!t.startsWith("PU1")||59!==t.length)return{problem:"shape"};let n=t.slice(3).replace(/O/g,"0").replace(/[IL]/g,"1").replace(/U/g,"V"),o=function(e){let t=0,n=0,o=[];for(let r of e){let e=c.indexOf(r);if(e<0)return null;n=n<<5|e,t+=5,t>=8&&(o.push(n>>>t-8&255),t-=8)}return Uint8Array.from(o)}(n.slice(0,52));if(!o||o.length<32)return{problem:"shape"};let r=o.slice(0,32);return h(r)!==n.slice(52)||u(r)!==n.slice(0,52)?{problem:"mistake"}:{identity:await m(r)}}(t);return"problem"in n?n.problem:(await e.onIdentity(n.identity),null)},copy:e=>Pn(e,s.t),reload:()=>location.reload(),contact:{value:e.doc.contacts().get(e.doc.me)??"",share:t=>e.doc.contact(t).then(()=>!0,()=>!1),stop:()=>e.doc.uncontact()},hasComments:e.doc.threads().some(t=>[t.root,...t.root.replies].some(t=>t.author===e.doc.me))}),toggleMine:()=>{b.mine=!b.mine,ie()},rename:async t=>{let n=t.replace(/\s+/g," ").trim();try{await async function(t){try{return await e.onName(t),!1}catch(n){if(e.doc.name!==t)throw n;return!0}}(n)?B(`New comments will say ${n}, but this browser couldn't remember it`):B(`New comments will say ${n}`)}catch(e){B(fo(e))}},name:()=>e.doc.name,all:()=>[...e.doc.threads()].sort(tn(G)).map(K)},_={},G={get addons(){return _.surface},doc:e.doc,root:e.root,t:s.t,host:s.element,state:b,resolved:v,T:w,oe:Y,s:V,u:O,V:e=>R.has(e.id),ke:()=>{X()&&ie()},F:e=>!b.hidden&&(!e.resolved||b.$||(e=>""!==(s.t.querySelector(`[data-thread="${e}"] .rbox textarea`)?.value.trim()??""))(e.id))&&!R.has(e.id),Je:(t,n)=>{for(let o of e.doc.threads()){let e=v.get(o.id);if(o.anchor.quote&&G.F(o)&&e?.range&&Zt(t,n,Vt(e)))return o}return null},re:(e,t)=>G.C()?G.Je(e,t):null,k:e=>e.composedPath().includes(s.element),we:e=>{y.add(e)},Ke:e=>y.has(e),open:me,Ze:e=>ce(e),w:function(e){b.w!==e&&(b.w=e,e&&e!==b.i&&xe(e),ie())},Ye:ge,_e:function(e){if(!b.o)return ge(e);Object.assign(b.o,e),ie()},C:()=>!S||S.Be(),be:e=>{let t=S?.ve();e(),t?.()},je:()=>{let e=b.o?.anchor.view,t=S?.ve();Promise.resolve(O.m(e)||O.H(e??{}).then(()=>G.ke())).then(t)},Fe:async function(t,n){let o=b.o;if(o)try{let r=await e.doc.comment(o.anchor,t,n);ue(n,t),b.o=null,J(new Set([r])),me(r,!0)}catch(e){if(e instanceof Q)return b.o=null,J(new Set([e.id])),me(e.id,!0),void B(ho);U(e)}},seen:he,people:()=>Et(e.doc.threads(),e.doc.me),qe:ve,Xe:we,q:be,D:e=>{S=e},ee:B,E:H,ze:j,Y:W,Qe:xe,f:ie,se:ye},Z=_.surface=new Dt(G,s.shadow,$);function J(t){let n=performance.now(),o=e.doc.threads();for(let r of o){if(t&&!t.has(r.id))continue;let o=performance.now()-n<40,i=Se(r.anchor,e.root,{fuzzy:o});v.set(r.id,i),o||"orphaned"!==i.state?w.delete(r.id):w.add(r.id)}for(let e of[...v.keys()])o.some(t=>t.id===e)||v.delete(e);0===w.size?(window.clearTimeout(q),q=0):0===q&&(q=window.setTimeout(()=>{q=0,!M&&(J(new Set(w)),ie())},250))}function X(){let t=new Set,n=null!==O.slide(),o=new Set;for(let r of e.doc.threads()){o.add(r.id);let e=v.get(r.id)?.element;(!O.m(r.anchor.view)||!n&&!1===e?.checkVisibility?.({visibilityProperty:!0}))&&t.add(r.id)}R=t;for(let e of D.keys())o.has(e)||D.delete(e);let r=`${O.slide()}|${[...t].join()}`;return r!==z&&(z=r,!0)}let ee=0,te=0,ne=0,oe=0,re=0;function ie(){if(M)return;let t=e.doc.threads();if(X(),b.i&&R.has(b.i)){let e=s.t.querySelector(`[data-thread="${b.i}"] .rbox textarea`)?.value;e&&D.set(b.i,e),b.i=null}b.hidden=!(b.c||b.p||b.Ae||b.o),b.hidden&&(b.i=null),b.hidden||function(t){let n=function(e,t){let n=Lt(t),o=[];for(let r of e)for(let e of[r.root,...r.root.replies])e.author!==t&&!e.deleted&&$t(e,n)&&!e.seenBy?.includes(t)&&o.push({thread:r,comment:e});return o}(t,e.doc.me).filter(e=>!fe.has(e.comment.id));if(!n.length)return;for(let e of n)fe.add(e.comment.id);let o=[...new Set(n.map(e=>k(e.comment)))];B(`${1===o.length?o[0]:`${o.length} people`} mentioned you in ${n.length} comment${1===n.length?"":"s"}`)}(t),function(e){if(e===te)return;te=e,cancelAnimationFrame(ne);let t=ee,n=performance.now(),o=e?260:200,r=i=>{let a=Math.min(1,(i-n)/o);ee=t+(e-t)*(e?1-(1-a)**3:a*a),d.ce(ee),a<1&&(ne=requestAnimationFrame(r))};ne=requestAnimationFrame(r)}(b.hidden?0:1),s.t.classList.toggle("hidden",b.hidden),s.t.classList.toggle("listing",b.p);let n=b.p&&!Xt();(function(e){e!==oe&&(oe=e,d.Te(e,p),window.clearTimeout(re),re=window.setTimeout(()=>{J(),ie()},p?0:400))})(n?320:0),d.Ee(g?"column"!==b.mode||b.hidden||n?0:320:null),function(e){let t=[],n=[],o=[];for(let r of e){let e=v.get(r.id);r.resolved&&!b.$||!e?.range||R.has(r.id)||(r.id===b.i||r.id===b.w?n.push(e.range):r.resolved?o.push(e.range):t.push(e.range))}b.o&&O.m(b.o.anchor.view)&&n.push(...b.o.ranges),function(e){if(_n())for(let t of Yn)CSS.highlights.set(t,new Highlight(...e[t.slice(7)]))}({quote:t,on:n,done:o})}(t);for(let e of L)e.f(t);C?.f(t),b.hidden||Z.flush()}let ae="",le=()=>s.t.getRootNode().activeElement,se="input,textarea,select,[contenteditable]:not([contenteditable=false])",de=()=>{let e=le();return e instanceof HTMLTextAreaElement&&""!==e.value||!!document.activeElement?.matches(se)};function ce(e,t=de(),n=le()){let o=[...s.t.querySelectorAll(`[data-thread="${e}"] .rbox textarea`)].find(e=>!e.closest("[inert]")),r=n?.getAttribute("data-thread");ae=r?`.${n.classList[0]}[data-thread="${r}"]`:"",!t&&o&&o.focus({preventScroll:!0})}function pe(){let e=b.o;return!(!e||G.C()||(O.m(e.anchor.view)||O.H(e.anchor.view??{}),0))}function ue(t,n){let o=e.doc.contacts(),r=new Map;for(let e of t??[]){let t=o.get(e.ref);t?.includes("@")&&r.set(t,n.slice(e.start+1,e.end))}if(!r.size)return;let i=e.doc.name||x(e.doc.me),a=`${i} mentioned you on ${document.title}`,l=`${i} mentioned you in a comment on "${document.title}":\n\n${n}\n\n${location.href}`,s=[...r.values()];B(`Let ${1===s.length?s[0]:`${s.length} people`} know?`,9e3,!1,!1,{label:"Open my email",href:`mailto:${[...r.keys()].join(",")}?subject=${encodeURIComponent(a)}&body=${encodeURIComponent(l)}`})}function he(t){let n=[t.root,...t.root.replies].filter(t=>t.author!==e.doc.me&&!t.deleted&&$t(t,Lt(e.doc.me))).map(e=>e.id);n.length&&e.doc.seen(n).catch(()=>{})}let fe=new Set;function me(t,n=!1){if(t&&pe())return;if(b.i===t&&!b.o)return t?ce(t):void 0;let o=!n&&de(),r=le();if(t||(b.Ae=!1),b.i=t,t){b.o=null,xe(t);let n=e.doc.threads().find(e=>e.id===t);n&&he(n)}if(ie(),t){let e=D.get(t),i=e&&s.t.querySelector(`[data-thread="${t}"] .rbox textarea`);i&&!i.value&&(i.value=e,i.dispatchEvent(new Event("input",{bubbles:!0}))),D.delete(t),n&&C?.ae()?C.le():ce(t,o,r)}}function ge(e){j(),b.p=!1,b.o=e,b.i=null,ie()}function ve(){b.o&&(b.o=null,ie())}function we(e,t=!1){b.c!==e&&(b.c=e,d.Se(e),e?(b.i=null,b.p=!1,C=Sn(G)):(j(),C?.destroy(),C=null,H("Comment mode off")),ie(),C&&(t&&C.xe(),t?C.ae()?B($n,1e4,!0,!0):B("Nothing here to comment on"):B(`Click anything to comment, or Tab between blocks · Option-click (Alt-click) to pin · ${Wt} or Esc to finish`,4e3,!0)))}function ye(){b.o&&(O.m(b.o.anchor.view)||G.C())?ve():b.i?me(null):C&&!C.se()&&we(!1)}function be(){b.o?pe()||ve():b.i&&me(null)}function xe(e){let t=v.get(e);!t||"orphaned"===t.state||ke(t.range?Vt(t):t.element?[t.element.getBoundingClientRect()]:[])}function ke(e){for(let t of e.slice(0,6)){let e=Je("div",{class:"pulse"});nt(e,t,4),s.t.prepend(e),window.setTimeout(()=>e.remove(),1300)}}function Ee(){for(let e of L)e.destroy();L=function(e){return[..."column"===e.state.mode?[Mn(e),ln(e,{ne:!1})]:[ln(e,{ne:!0})],Tn(e),Rn(e)]}(G),ie()}Ge.go=t=>{if(t.startsWith("slide:"))return void O.H({slide:t.slice(6)});let n=decodeURIComponent(t.slice(6)).replace(/\s+/g," ").toLowerCase(),o=[...e.root.querySelectorAll("p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,figcaption,dt,dd")].find(e=>(e.textContent??"").replace(/\s+/g," ").toLowerCase().includes(n));o&&(o.scrollIntoView({block:"center",behavior:p?"auto":"smooth"}),window.setTimeout(()=>ke([o.getBoundingClientRect()]),p?0:450))};let $e=()=>{if(!M){for(let e of L)e.L();C?.L(),Z.L(),N=requestAnimationFrame($e)}},Le=e=>{if("Escape"===e.key)return ye();if(function(e){return"KeyC"===e.code&&e.shiftKey&&e.altKey&&!e.metaKey&&!e.ctrlKey&&!e.repeat&&!e.getModifierState("AltGraph")}(e)&&!e.isComposing&&!e.defaultPrevented&&!(e=>{let t=e.composedPath()[0];return t instanceof Element&&null!==t.closest(se)})(e)){if(e.preventDefault(),C?.We()&&C.xe())return;we(!b.c,!0)}},Ce=e=>{if(G.k(e)||y.has(e))return;let t=window.getSelection();t&&!t.isCollapsed||be()},Me=()=>{s.t.style.setProperty("--pu-pop",`${Jt()}px`);let t=uo(e.root,"column"===b.mode);t!==b.mode?(b.mode=t,Ee()):ie()};function Ae(){let e=performance.now();0===T&&(P=e),window.clearTimeout(T);let t=Math.min(120,Math.max(0,P+1e3-e));T=window.setTimeout(()=>{T=0,J(),ie()},t)}let Te=new MutationObserver(e=>{e.every(e=>s.element.contains(e.target))||Ae()});window.addEventListener("keydown",Le),window.addEventListener("click",Ce),window.addEventListener("resize",Me),Te.observe(e.root,{subtree:!0,childList:!0,characterData:!0});let Pe=0,Ne=t=>{let n="dark"===t;n!==r&&(r=n,window.clearTimeout(Pe),s.t.classList.add("sw"),Pe=window.setTimeout(()=>{ao(s.t,io(e.root,t)),d.dark(n),s.t.classList.remove("sw")},170))},Re=()=>Ne(a()),ze=0,De=()=>{ze||(ze=window.setTimeout(()=>{Re(),ze=window.setTimeout(()=>{ze=0,Re()},450)},150))},Ie=new MutationObserver(e=>{e.every(e=>e.target===s.element)||De()});Ie.observe(document.documentElement,{attributes:!0,subtree:!0});let Be=window.matchMedia?.("(prefers-color-scheme: dark)");Be?.addEventListener?.("change",De);let je=new ResizeObserver(Ae);je.observe(e.root);let He=e.doc.onChange((e,t,n)=>{Z.Oe(t,n),J(),ie()});return J(),Ee(),N=requestAnimationFrame($e),{ctx:G,appearance:()=>o,destroy(){M=!0,cancelAnimationFrame(N),cancelAnimationFrame(ne),cancelAnimationFrame(I),O.destroy(),window.clearTimeout(re),window.clearTimeout(A),window.clearTimeout(T),window.clearTimeout(q),Te.disconnect(),Ge.go=void 0,je.disconnect(),Ie.disconnect(),Be?.removeEventListener?.("change",De),window.clearTimeout(ze),window.clearTimeout(Pe),He(),window.removeEventListener("keydown",Le),window.removeEventListener("click",Ce),window.removeEventListener("resize",Me),C?.destroy();for(let e of L)e.destroy();Z.destroy(),d.remove(),s.destroy()}}}var go=null;function vo(e={}){if(It)return It.mount(e);if(!function(){if(It)return!0;let e=globalThis,t=e.pipeupAddons;if(Array.isArray(t))for(let e of t)jt(e);else if(t&&"object"==typeof t&&t.push!==jt)return!1;return e.pipeupAddons={push:jt},!0}())return Promise.reject(new Error("pipeup: another copy of Pipeup owns the add-on queue. Remove one script."));if(go)return go;let t=async function(e,t){let n,o,r=document.documentElement.getAttribute("data-pipeup-doc"),{id:a,key:l}=r?await G(r):{id:`page-${i(location.origin+location.pathname)}`,key:null},s=!1;if(e.store)n=e.store,o=await ae(n);else try{let e=le.open();n=await function(e){return new Promise((t,n)=>{let o=setTimeout(()=>n(new Error("timed out")),4e3);e.then(t,n).finally(()=>clearTimeout(o))})}(e).catch(t=>{throw e.then(e=>e.close(),()=>{}),t}),o=await ae(n)}catch{n=new re,s=!0,o=await ae(n)}let d=e.name?.trim();d&&d!==o.name&&(o={...o,name:d},await n.saveProfile(o)),navigator.storage?.persist?.().catch(()=>{});let c,p=await ee.open({doc:a,key:l,store:n,identity:o.identity,name:o.name});Un(e.slides??null);try{c=mo({doc:p,root:e.root??document.body,onName:async e=>{p.name=e,o={...o,name:e},await n.saveProfile(o)},onIdentity:async e=>{o={...o,identity:e},await n.saveProfile(o)}})}catch(e){throw Un(null),e}s&&c.ctx.ee("This browser can't keep comments for this page — copy the comments (Copy as Markdown) to keep them");let u=()=>{p.flush().catch(e=>globalThis.reportError?.(e))},h=function(e){let t={...e,i:!0};Ft=t;for(let e of Ot.values())"waiting"===e.info.state&&Ht(e,t);return()=>{t.i=!1,Ft===t&&(Ft=null);for(let e of[...Ot.values()].reverse())e.stop?.(),delete e.stop;e.surface.destroy()}}({surface:c.ctx.addons,doc:p,root:e.root??document.body,ephemeral:s,version:Ue}),f=/\S/.test(document.documentElement.getAttribute("data-pipeup-agents")??"")?window.setTimeout(()=>{Bt().some(e=>"agents"===e.id)||console.warn("pipeup: this page lists an agent (data-pipeup-agents), but the agents add-on isn't on the page, so replies won't show. Add @pipeup/agents (see the Add-ons page).")},1e3):0;"off"!==document.documentElement.getAttribute("data-pipeup-updates")&&Date.now()-Date.parse(Ke)>31536e6&&console.info(`pipeup: this is Pipeup ${Ue}, from ${Ke}; newer versions exist. See https://github.com/pipeup-ai/pipeup/blob/main/CHANGELOG.md`);let m=!1;return window.addEventListener("pagehide",u),{document:p,comments:({all:e=!1}={})=>function(e,t){return{markdown:Fe(e,"ai",t),threads:e.filter(e=>t.all||!e.thread.resolved).map(({thread:e,location:t})=>{let n={id:e.id,state:e.resolved?"resolved":e.addressed?"addressed":"open",where:t.where,comments:[e.root,...e.root.replies].map(e=>({id:e.id,by:k(e),agent:$(e.name),at:new Date(e.at).toISOString(),text:e.deleted?"":e.text,...e.reactions.length?{reactions:e.reactions.map(e=>({emoji:e.emoji,by:e.by.map(k)}))}:{}}))};return t.id&&(n.element=t.id),t.quote&&(n.quote=t.quote),t.pin&&(n.pin=t.pin),e.addressed&&!e.resolved&&(n.addressed={note:e.addressed.text,by:k(e.addressed)}),n})}}(c.ctx.s.all(),{title:document.title,url:location.href,exportedAt:new Date,all:e}),appearance:()=>({...c.appearance()}),flush:()=>p.flush(),unmount:()=>{m||(m=!0,window.removeEventListener("pagehide",u),window.clearTimeout(f),h(),c.destroy(),Un(null),go===t()&&(go=null))}}}(e,()=>t).catch(e=>{throw go===t&&(go=null),e});return go=t,t}async function wo(e){if(!go)throw new Error("pipeup: Pipeup hasn't started on this page");return(await go).comments(e)}export{qt as ADDON_API,E as AI_NAME,g as ANIMALS,Ke as BUILT,v as COLOURS,ie as DEFAULT_PROFILE_NAME,le as IndexedDbStore,re as MemoryStore,ee as PipeupDocument,Q as UnsavedChangeError,Ue as VERSION,Bt as addons,x as animalName,wo as comments,K as computeOpId,Fe as copyAll,Oe as copyThread,s as createIdentity,be as describeElement,ye as describeRange,De as formatAgo,$ as isAiName,Pe as labelOf,ae as loadOrCreateProfile,qe as locate,vo as mount,k as nameOf,_ as newDocumentAttribute,Wn as onReveal,G as parseDocumentAttribute,Se as resolveAnchor,kt as setPeople,Hn as setViewState,D as signOp,jt as use};