pipeup 0.4.0-beta.1 → 0.4.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -11
- package/dist/pipeup.core.js +7 -7
- package/dist/pipeup.esm.js +7 -7
- package/dist/pipeup.min.js +7 -7
- package/dist/types/anchor/locate.d.ts +7 -1
- package/dist/types/core.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/ui/comment-mode.d.ts +14 -1
- package/dist/types/ui/context.d.ts +18 -3
- package/dist/types/ui/dom.d.ts +2 -0
- package/dist/types/ui/here.d.ts +62 -0
- package/dist/types/ui/icons.d.ts +2 -0
- package/dist/types/ui/mount.d.ts +3 -0
- package/dist/types/ui/order.d.ts +6 -0
- package/dist/types/ui/pick.d.ts +18 -0
- package/dist/types/ui/styles.d.ts +1 -1
- package/dist/types/ui/thread-view.d.ts +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Comments and feedback right on any HTML page: documents, slide decks and whole sites.
|
|
4
4
|
|
|
5
|
-
> **Alpha (0.4.0-beta.
|
|
5
|
+
> **Alpha (0.4.0-beta.3).** The API and the stored comment format may change before 1.0; pin an exact version.
|
|
6
6
|
> Website and Try pages: https://pipeup-ai.github.io/pipeup/ · Source: https://github.com/pipeup-ai/pipeup
|
|
7
7
|
|
|
8
8
|
Pipeup: signed comment operations, threads with one-level replies, anchors that survive page changes,
|
|
9
9
|
local storage, sealed feedback files, copy for AI, and the UI: comments in a column beside documents or as
|
|
10
10
|
bubbles, comment mode for blocks and pins on any page, and an opt-in reserved gutter. It is one file
|
|
11
|
-
(at most
|
|
11
|
+
(at most 36 KB gzip) so it works from `file://` with nothing else to load.
|
|
12
12
|
|
|
13
13
|
Nobody has to give a name. Each reviewer is an animal in a colour ("Red Fox": 5 animals, 10 colours),
|
|
14
14
|
picked from their identity so it is the same on every page, shown as a squircle avatar (the animal drawn in its
|
|
@@ -21,7 +21,7 @@ As a classic script (also works from `file://`), it mounts itself on pages that
|
|
|
21
21
|
```html
|
|
22
22
|
<html data-pipeup-doc="<id>:<key>">
|
|
23
23
|
...
|
|
24
|
-
<script src="https://cdn.jsdelivr.net/npm/pipeup@0.4.0-beta.
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/pipeup@0.4.0-beta.3/dist/pipeup.min.js" integrity="sha384-…" crossorigin="anonymous" defer></script>
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
Each release's notes on GitHub give the `integrity` value
|
|
@@ -32,7 +32,7 @@ Install with `npm i pipeup`. From a bundler (no side effects; call `mount` yours
|
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
34
|
import { mount } from "pipeup";
|
|
35
|
-
const pipeup = await mount({ name: "Sam" }); // options: root, name (optional), store
|
|
35
|
+
const pipeup = await mount({ name: "Sam" }); // options: root, name (optional), store, slides
|
|
36
36
|
await pipeup.flush(); // write any unsaved changes now (this also happens when the page is hidden)
|
|
37
37
|
pipeup.unmount(); // remove Pipeup from the page; the comments stay saved
|
|
38
38
|
```
|
|
@@ -41,11 +41,18 @@ Pages designed for review can reserve a comment gutter: add `data-pipeup-reserve
|
|
|
41
41
|
page out with `var(--pipeup-gutter, 0px)`. While All comments is open the page is moved over for it and its
|
|
42
42
|
width is published as `--pipeup-panel`, so fixed bars can use `right: var(--pipeup-panel, 0px)` — see [examples/review-document.html](https://github.com/pipeup-ai/pipeup/blob/main/libs/ts/pipeup/examples/review-document.html).
|
|
43
43
|
|
|
44
|
+
Comments belong to where they were made. On a deck (slides marked `data-pipeup-slide`, or reveal.js) only the
|
|
45
|
+
current slide's comments show; the control counts those and a small dot marks comments on other slides, and All
|
|
46
|
+
comments groups every thread by slide. Choosing one goes to its slide and opens it there. Pages with tabs or
|
|
47
|
+
routes report their view with `Pipeup.setViewState({ tab: "faq", label: "FAQ tab" })` and go to one with
|
|
48
|
+
`Pipeup.onReveal((view) => showTab(view.tab))`; a deck can pass `mount({ slides: { current, go } })` or use the
|
|
49
|
+
same `onReveal`. Without a way to go there, the comment opens beside the panel with a snapshot of what it was on.
|
|
50
|
+
|
|
44
51
|
Examples in the source repository, one per kind of page, each following the agent skill's guidance (open from disk after `npm run build`):
|
|
45
52
|
|
|
46
53
|
- [examples/review-document.html](https://github.com/pipeup-ai/pipeup/blob/main/libs/ts/pipeup/examples/review-document.html) — a document: centred reading area with a reserved comment gutter.
|
|
47
54
|
- [examples/review-site.html](https://github.com/pipeup-ai/pipeup/blob/main/libs/ts/pipeup/examples/review-site.html) — a site: clear blocks with stable ids for comment mode and pins; navigation ignored.
|
|
48
|
-
- [examples/review-deck.html](https://github.com/pipeup-ai/pipeup/blob/main/libs/ts/pipeup/examples/review-deck.html) — a deck: one marked element per slide; slide controls ignored so they keep working
|
|
55
|
+
- [examples/review-deck.html](https://github.com/pipeup-ai/pipeup/blob/main/libs/ts/pipeup/examples/review-deck.html) — a deck: one marked element per slide; slide controls ignored so they keep working, and one line so Pipeup can go to a comment's slide.
|
|
49
56
|
|
|
50
57
|
Comments show only while someone is reviewing: in comment mode, while All comments is open, or while a comment
|
|
51
58
|
is being written. With comment mode off (as every page opens) the page is the author's alone; the control still
|
|
@@ -62,20 +69,28 @@ has nowhere to show); the panel closes with its close button, Esc or a click on
|
|
|
62
69
|
fixes to the window don't move over with the page.
|
|
63
70
|
|
|
64
71
|
Comment mode (press **Shift+Alt+C**, or **⇧⌥C** on a Mac, or switch on Start commenting in the control's menu) lets reviewers comment on blocks and drop pins
|
|
65
|
-
(Option-click,
|
|
72
|
+
(Option-click, Alt-click, or the naming bar's Pin) on any page. While it is on, clicks and submits on the page do
|
|
66
73
|
nothing, and selecting text offers a comment icon, clicking a highlight opens its thread, and
|
|
67
|
-
clicking a block opens its comment box at once (a bar names the block
|
|
68
|
-
block around it, keeping what you typed). Esc steps back: the box and its block together, then comment mode (or an open
|
|
74
|
+
clicking a block opens its comment box at once (a bar names the block; Around it and Inside it move the box to the
|
|
75
|
+
block around it or inside it, keeping what you typed, and Pin makes it a pin at the block's centre). Esc steps back: the box and its block together, then comment mode (or an open
|
|
69
76
|
comment, then comment mode). It is a quiet page, not a
|
|
70
77
|
sandbox:
|
|
71
78
|
|
|
72
79
|
- CSS `:hover` styles still apply.
|
|
73
80
|
- A page's own capture-phase listeners on `window`, added before Pipeup, can still hear events.
|
|
74
|
-
- Esc also reaches the page's own key handlers.
|
|
81
|
+
- Esc also reaches the page's own key handlers, except while the block cursor has focus.
|
|
75
82
|
- The browser's own right-click menu is switched off in comment mode.
|
|
76
83
|
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
From the keyboard, comment mode started with the shortcut (or Start commenting chosen with Enter) puts a **block
|
|
85
|
+
cursor** on the block that has focus, or the first block in view. Tab and Shift+Tab move between blocks at one
|
|
86
|
+
level, ↑ goes to the block around it and ↓ to a block inside it, Enter comments, Shift+Enter opens the comments
|
|
87
|
+
already there one at a time, and Esc puts the cursor away (focus goes back where it was; the shortcut brings it
|
|
88
|
+
back), then leaves comment mode. Screen readers hear "Paragraph, 3 of 12, has 1 comment" and the block's own words;
|
|
89
|
+
Pipeup never writes `tabindex`, ids or ARIA into the page. After each comment, focus is back on the same block.
|
|
90
|
+
While the cursor is not in use, Enter and Space on the page's own controls do what the page expects, and Enter in
|
|
91
|
+
a form field submits the form. Words
|
|
92
|
+
selected with caret browsing (F7) or a screen reader show the comment icon once the selection settles, and Enter
|
|
93
|
+
comments on them.
|
|
79
94
|
|
|
80
95
|
`pipeup/core` is the headless core only, for tools that never draw UI:
|
|
81
96
|
|
package/dist/pipeup.core.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function f(t){let e="";for(let n of t)e+=String.fromCharCode(n);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function g(t){let e=t.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((t.length+3)%4),n=atob(e),r=new Uint8Array(n.length);for(let o=0;o<n.length;o++)r[o]=n.charCodeAt(o);return r}function Q(t=16){return f(crypto.getRandomValues(new Uint8Array(t)))}function m(t){return new TextEncoder().encode(t)}function w(t){if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return"["+t.map(w).join(",")+"]";let e=t;return"{"+Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>JSON.stringify(n)+":"+w(e[n])).join(",")+"}"}function y(t){return t.replace(/\s+/g," ").trim()}function E(t){let e=y(t),n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")}var ke=/^[A-Za-z0-9_-]{43}$/,Te=512,b=new Map;async function R(){let t=await crypto.subtle.generateKey({name:"Ed25519"},!1,["sign","verify"]),e=new Uint8Array(await crypto.subtle.exportKey("raw",t.publicKey));return{publicKey:f(e),privateKey:t.privateKey}}async function J(t,e){let n=await crypto.subtle.sign({name:"Ed25519"},t.privateKey,e);return f(new Uint8Array(n))}async function V(t,e,n){if(!ke.test(t))return!1;try{if(f(g(t))!==t)return!1;let r=b.get(t);if(!r){b.size>=Te&&b.delete(b.keys().next().value),r=crypto.subtle.importKey("raw",g(t),{name:"Ed25519"},!0,["verify"]),b.set(t,r);let o=r;o.catch(()=>{b.get(t)===o&&b.delete(t)})}return await crypto.subtle.verify({name:"Ed25519"},await r,g(n),e)}catch{return!1}}var k=1e4,D=2**40,T=2**47,l={doc:64,path:2e3,snapshot:500,anchorId:200,quote:1e4,context:64,viewEntries:16,viewKey:64,viewValue:200},Ie=/^[0-9a-f]{8}$/,L=/^[A-Za-z0-9_-]{43}$/,Ce=/^[A-Za-z0-9_-]{43}$/,Me=new Set(["create","reply","edit","delete","resolve","reopen"]);async function Y(t,e){if(t.author!==e.publicKey)throw new Error("pipeup: an op must be signed by its author");return{body:t,sig:await J(e,m(w(t)))}}var h=(t,e)=>typeof t=="string"&&t.length<=e,W=t=>typeof t=="number"&&Number.isFinite(t)&&t>=0&&t<=1;function B(t){if(!t||typeof t!="object")return!1;let{id:e,path:n,fingerprint:r,snapshot:o,quote:i,point:s,view:a}=t;if(!h(n,l.path)||!h(o,l.snapshot)||typeof r!="string"||!Ie.test(r)||e!==void 0&&(!h(e,l.anchorId)||e===""))return!1;if(i!==void 0){if(!i||typeof i!="object")return!1;let c=i;if(!h(c.exact,l.quote)||c.exact===""||!h(c.prefix,l.context)||!h(c.suffix,l.context))return!1}if(s!==void 0){if(!s||typeof s!="object")return!1;let c=s;if(!W(c.x)||!W(c.y))return!1}if(a!==void 0){if(!a||typeof a!="object"||Array.isArray(a))return!1;let c=Object.entries(a);if(c.length>l.viewEntries||!c.every(([p,d])=>p.length<=l.viewKey&&h(d,l.viewValue)))return!1}return!0}function ee(t){if(!t||typeof t!="object")return!1;let{body:e,sig:n}=t;if(typeof n!="string"||!e||typeof e!="object")return!1;let r=e;return!(r.v!==1||typeof r.id!="string"||!L.test(r.id)||typeof r.kind!="string"||!Me.has(r.kind)||!h(r.doc,l.doc)||r.doc===""||typeof r.thread!="string"||!L.test(r.thread)||typeof r.author!="string"||!Ce.test(r.author)||typeof r.name!="string"||r.name.length>80||r.name!==r.name.trim()||typeof r.clock!="number"||!Number.isSafeInteger(r.clock)||r.clock<1||r.clock>D||typeof r.at!="number"||!Number.isSafeInteger(r.at)||r.at<0||r.at>T||r.text!==void 0&&(!h(r.text,k)||r.text!==r.text.trim())||r.target!==void 0&&(typeof r.target!="string"||!L.test(r.target))||(r.kind==="create"||r.kind==="reply"||r.kind==="edit")&&(typeof r.text!="string"||r.text.trim()==="")||(r.kind==="reply"||r.kind==="edit"||r.kind==="delete")&&!r.target||r.kind==="create"&&(r.id!==r.thread||!B(r.anchor)))}function te(t){return V(t.body.author,m(w(t.body)),t.sig)}function re(t,e){return t.body.clock!==e.body.clock?t.body.clock-e.body.clock:t.body.at!==e.body.at?t.body.at-e.body.at:t.body.author!==e.body.author?t.body.author<e.body.author?-1:1:t.body.id!==e.body.id?t.body.id<e.body.id?-1:1:0}function oe(t){let e=new Map,n=new Map,r=new Map;for(let{body:o}of[...t].sort(re)){if(o.name&&r.set(o.author,o.name),o.kind==="create"){if(e.has(o.id)||!o.anchor||o.text===void 0)continue;let a=ne(o.id,o.author,o.name,o.text,o.at);e.set(o.id,{id:o.id,anchor:o.anchor,root:a,resolved:!1}),n.set(o.id,{comment:a,thread:o.id});continue}let i=e.get(o.thread);if(!i)continue;if(o.kind==="resolve"||o.kind==="reopen"){i.resolved=o.kind==="resolve";continue}let s=o.target?n.get(o.target):void 0;if(!(!s||s.thread!==o.thread)){if(o.kind==="reply"){if(n.has(o.id)||o.text===void 0)continue;let a=ne(o.id,o.author,o.name,o.text,o.at);i.root.replies.push(a),n.set(o.id,{comment:a,thread:o.thread});continue}o.author!==s.comment.author||s.comment.deleted||(o.kind==="edit"&&o.text!==void 0&&(s.comment.text=o.text,s.comment.edited=!0),o.kind==="delete"&&(s.comment.text="",s.comment.deleted=!0))}}for(let{comment:o}of n.values())o.name||(o.unnamed=!0,o.name=r.get(o.author)??"");return[...e.values()]}function ne(t,e,n,r,o){return{id:t,author:e,name:n,text:r,at:o,edited:!1,deleted:!1,replies:[]}}async function _(t){let e={...t,id:void 0,thread:t.kind==="create"?void 0:t.thread},n=await crypto.subtle.digest("SHA-256",m(w(e)));return f(new Uint8Array(n))}var I=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 oe(this.ops.values())}async add(e){let n=[];for(let r of e)!ee(r)||r.body.doc!==this.doc||this.ops.has(r.body.id)||r.body.id!==await _(r.body)||!await te(r)||(this.ops.set(r.body.id,r),this.clock=Math.max(this.clock,r.body.clock),r.body.kind==="create"&&this.createAt.set(r.body.author,Math.max(this.createAt.get(r.body.author)??0,r.body.at)),this.threadAt.set(r.body.thread,Math.max(this.threadAt.get(r.body.thread)??0,r.body.at)),n.push(r));return n}async append(e,n,r){let o={v:1,...r,id:"",thread:r.kind==="create"?"":r.thread,doc:this.doc,author:e.publicKey,name:n,clock:Math.min(this.clock+1,D),at:Math.min(Math.max(Date.now(),r.kind==="create"?(this.createAt.get(e.publicKey)??0)+1:(this.threadAt.get(r.thread)??0)+1),T)};for(let a=0;;a++){if(a===1e3)throw new Error("pipeup: could not record this change");if(o.id=await _(o),!this.ops.has(o.id)||o.at>=T)break;o.at+=1}let i=this.ops.get(o.id);if(i)return i;o.kind==="create"&&(o.thread=o.id);let[s]=await this.add([await Y(o,e)]);if(!s)throw new Error("pipeup: could not record this change");return s}};var Ne=/^([A-Za-z0-9_-]{16}):([A-Za-z0-9_-]{43})$/;function $e(){return`${Q(12)}:${f(crypto.getRandomValues(new Uint8Array(32)))}`}async function Fe(t){let e=Ne.exec(t.trim()),n=e?.[1],r=e?.[2];if(!n||!r)throw new Error('pipeup: data-pipeup-doc must look like "<id>:<key>", as made by newDocumentAttribute()');let o=await crypto.subtle.importKey("raw",g(r),{name:"AES-GCM"},!1,["encrypt","decrypt"]);return{id:n,key:o}}async function ie(t,e,n){let r=crypto.getRandomValues(new Uint8Array(12)),o=await crypto.subtle.encrypt({name:"AES-GCM",iv:r,additionalData:m(n)},t,m(e));return{iv:f(r),data:f(new Uint8Array(o))}}async function se(t,e,n){try{let r=await crypto.subtle.decrypt({name:"AES-GCM",iv:g(e.iv),additionalData:m(n)},t,g(e.data));return new TextDecoder().decode(r)}catch{throw new Error("pipeup: this feedback could not be opened with this document")}}var Re=5e6,ae=t=>`pipeup-file:${t}`;async function ce(t,e,n){let r=n?{pipeup:1,doc:t,sealed:!0,...await ie(n,JSON.stringify(e),ae(t))}:{pipeup:1,doc:t,sealed:!1,ops:e};return JSON.stringify(r,null,2)}async function de(t,e,n){if(t.length>Re)throw new Error("pipeup: this feedback file is too large");let r;try{r=JSON.parse(t)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}if(!r||typeof r!="object"||r.pipeup!==1||typeof r.doc!="string")throw new Error("pipeup: this is not an Pipeup feedback file");if(r.doc!==e)throw new Error("pipeup: this feedback is for a different document");if(!r.sealed)return Array.isArray(r.ops)?r.ops:[];if(!n)throw new Error("pipeup: this feedback is sealed, and this page has no document key");if(typeof r.iv!="string"||typeof r.data!="string")throw new Error("pipeup: this is not an Pipeup feedback file");let o;try{o=await se(n,{iv:r.iv,data:r.data},ae(e))}catch{throw new Error("pipeup: this feedback could not be opened with this document's key")}let i;try{i=JSON.parse(o)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}return Array.isArray(i)?i:[]}var pe=80,v=class extends Error{constructor(n,r,o=1){super("pipeup: shown here, but not saved yet");this.id=n;this.cause=r;this.count=o;this.name="UnsavedChangeError"}},K=class t{constructor(e,n){this.log=e;this.options=n;this.displayName=n.name.trim()?le(n.name):""}listeners=new Set;cache=[];comments=new Map;displayName;queue=Promise.resolve();unsaved=[];static async open(e){if(typeof e.doc!="string"||e.doc===""||e.doc.length>l.doc)throw new Error(`pipeup: the document id must be 1 to ${l.doc} characters`);let n=new I(e.doc);await n.add(await e.store.load(e.doc));let r=new t(n,e);return r.refresh(!1),r}get id(){return this.options.doc}get me(){return this.options.identity.publicKey}get name(){return this.displayName}set name(e){this.displayName=le(e),this.refresh(!0)}threads(){return this.cache}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}comment(e,n){return this.enqueue(()=>this.write({kind:"create",anchor:e,text:U(n)}))}reply(e,n){return this.enqueue(()=>this.write({kind:"reply",thread:this.find(e).thread,target:e,text:U(n)}))}edit(e,n){return this.enqueue(async()=>{let{thread:r}=this.mine(e);await this.write({kind:"edit",thread:r,target:e,text:U(n)})})}remove(e){return this.enqueue(async()=>{let{thread:n}=this.mine(e);await this.write({kind:"delete",thread:n,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)})})}flush(){return this.enqueue(()=>this.persist())}exportFile(){return ce(this.options.doc,this.log.all(),this.options.key)}importFile(e){return this.enqueue(async()=>{let n=await this.log.add(await de(e,this.options.doc,this.options.key));this.unsaved.push(...n),n.length>0&&this.refresh(!0);try{await this.persist()}catch(r){throw n.length>0?new v(n[0].body.id,r,n.length):r}return n.length})}enqueue(e){let n=this.queue.then(e);return this.queue=n.catch(()=>{}),n}async write(e){let n=await this.log.append(this.options.identity,this.displayName,e);this.unsaved.push(n),this.refresh(!0);try{await this.persist()}catch(r){throw new v(n.body.id,r)}return n.body.id}async persist(){if(this.unsaved.length===0)return;let e=[...this.unsaved];await this.options.store.append(this.options.doc,e),this.unsaved=this.unsaved.filter(n=>!e.includes(n))}refresh(e){this.cache=this.log.threads(),this.comments.clear();let n=(r,o)=>{r.unnamed&&r.author===this.me&&this.displayName&&(r.name=this.displayName),this.comments.set(r.id,{comment:r,thread:o});for(let i of r.replies)n(i,o)};for(let r of this.cache)n(r.root,r.id);if(e)for(let r of this.listeners)try{r(this.cache)}catch(o){globalThis.reportError?.(o)}}find(e){let n=this.comments.get(e);if(!n)throw new Error("pipeup: there is no comment with that id");return n}mine(e){let n=this.find(e);if(n.comment.author!==this.me)throw new Error("pipeup: only the writer can change a comment");return n}thread(e){if(!this.cache.some(n=>n.id===e))throw new Error("pipeup: there is no thread with that id");return e}};function U(t){let e=t.trim();if(!e)throw new Error("pipeup: a comment needs some words");if(e.length>k)throw new Error(`pipeup: comments are limited to ${k} characters`);return e}function le(t){let e=t.replace(/\s+/g," ").trim();if(!e||e.length>pe)throw new Error(`pipeup: choose a name of 1 to ${pe} characters`);return e}var q=class{docs=new Map;profile=null;async load(e){return[...this.docs.get(e)?.values()??[]]}async append(e,n){let r=this.docs.get(e);r||this.docs.set(e,r=new Map);for(let o of n)r.set(o.body.id,o)}async loadProfile(){return this.profile}async saveProfile(e){this.profile=e}async saveProfileIfAbsent(e){return this.profile||(this.profile=e),this.profile}},ue="",Le="Reviewer";async function De(t,e=ue){let n=await t.loadProfile();if(n)return n.name===Le?{...n,name:""}:n;let r={identity:await R(),name:e};return t.saveProfileIfAbsent(r)}var j=class t{constructor(e){this.db=e}static open(e="pipeup"){return new Promise((n,r)=>{let o=indexedDB.open(e,1);o.onupgradeneeded=()=>{let i=o.result;i.createObjectStore("ops",{keyPath:["doc","id"]}).createIndex("doc","doc"),i.createObjectStore("meta")},o.onsuccess=()=>{let i=o.result;i.onversionchange=()=>i.close(),n(new t(i))},o.onerror=()=>r(o.error??new Error("pipeup: could not open local storage"))})}close(){this.db.close()}async load(e){return(await this.request("ops","readonly",r=>r.index("doc").getAll(e))).map(r=>r.op)}async append(e,n){if(n.length===0)return;let r=this.db.transaction("ops","readwrite"),o=r.objectStore("ops"),i=Be(r);try{for(let s of n)o.put({doc:e,id:s.body.id,op:s})}catch(s){throw r.abort(),i.catch(()=>{}),s}await i}async loadProfile(){return await this.request("meta","readonly",e=>e.get("profile"))??null}async saveProfile(e){await this.request("meta","readwrite",n=>n.put(e,"profile"))}async saveProfileIfAbsent(e){return new Promise((n,r)=>{let o=this.db.transaction("meta","readwrite"),i=o.objectStore("meta"),s=e;o.oncomplete=()=>n(s),o.onerror=()=>r(o.error??new Error("pipeup: local storage write failed")),o.onabort=()=>r(o.error??new Error("pipeup: local storage write aborted"));let a=i.get("profile");a.onsuccess=()=>{a.result?s=a.result:i.put(e,"profile")}})}request(e,n,r){return new Promise((o,i)=>{let s=r(this.db.transaction(e,n).objectStore(e));s.onsuccess=()=>o(s.result),s.onerror=()=>i(s.error??new Error("pipeup: local storage request failed"))})}};function Be(t){return new Promise((e,n)=>{t.oncomplete=()=>e(),t.onerror=()=>n(t.error??new Error("pipeup: local storage write failed")),t.onabort=()=>n(t.error??new Error("pipeup: local storage write aborted"))})}function P(t){let n=(t.ownerDocument??t).createTreeWalker(t,NodeFilter.SHOW_TEXT),r=[],o="";for(let i=n.nextNode();i;i=n.nextNode())r.push({node:i,start:o.length}),o+=i.data;return{text:o,nodes:r}}function H(t,e,n){let o=(t.ownerDocument??t).createRange();return o.setStart(t,0),o.setEnd(e,n),o.toString().length}function z(t,e,n){let r=fe(t,e,!1),o=fe(t,n,!0);if(!r||!o||n<e)return null;let i=r.node.ownerDocument.createRange();return i.setStart(r.node,r.offset),i.setEnd(o.node,o.offset),i}function fe(t,e,n){for(let o of t.nodes){let i=o.start+o.node.data.length;if(e>=o.start&&(e<i||n&&e===i))return{node:o.node,offset:e-o.start}}let r=t.nodes[t.nodes.length-1];return r&&e===r.start+r.node.data.length?{node:r.node,offset:r.node.data.length}:null}var me=32,ge=200,_e="p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,pre,figcaption,dt,dd,summary,caption";function ye(t){return t.nodeType===Node.ELEMENT_NODE?t:t.parentElement}function xe(t,e){for(let n=ye(t)?.closest("[data-pipeup-id]")??null;n;){if(!e.contains(n))return null;let r=n.getAttribute("data-pipeup-id")??"";if(r!==""&&r.length<=l.anchorId)return n;n=n.parentElement?.closest("[data-pipeup-id]")??null}return null}function Ue(t){let e=t;return/[\uD800-\uDBFF]$/.test(e)&&(e=e.slice(0,-1)),/^[\uDC00-\uDFFF]/.test(e)&&(e=e.slice(1)),e}function C(t,e,n){return Ue(t.slice(e,n))}function Ke(t,e){let n=qe(t,e);if(n.length>l.path)throw new Error("pipeup: this element is nested too deeply to comment on \u2014 give a nearby container a data-pipeup-id");return n}function we(t){if(!B(t))throw new Error("pipeup: could not describe this place on the page");return t}function M(t,e){let n=ye(t),r=n?.closest(_e)??null;return r&&e.contains(r)?r:n&&e.contains(n)?n:e}function qe(t,e){if(t===e)return"";let n=[];for(let r=e;r&&r!==t;r=r.parentElement){let o=1;for(let i=r.previousElementSibling;i;i=i.previousElementSibling)i.tagName===r.tagName&&o++;n.unshift(`${r.tagName.toLowerCase()}:nth-of-type(${o})`)}return":scope > "+n.join(" > ")}function je(t,e,n){if(!e.contains(t.commonAncestorContainer))throw new Error("pipeup: the selection is outside the commentable area");let r=xe(t.commonAncestorContainer,e),o=r??e,{text:i}=P(o),s=H(o,t.startContainer,t.startOffset),a=H(o,t.endContainer,t.endOffset),c=i.slice(s,a);if(c==="")throw new Error("pipeup: select some text to comment on");if(c.length>l.quote)throw new Error(`pipeup: selections are limited to ${l.quote} characters`);let p=C(i,Math.max(0,s-me),s),d=C(i,a,a+me);return we({...r?{id:r.getAttribute("data-pipeup-id")??""}:{},path:"",quote:{exact:c,prefix:p,suffix:d},...n?{view:n}:{},fingerprint:E(M(t.startContainer,e).textContent??""),snapshot:C(y(p+c+d),0,ge)})}function He(t,e,n,r){let o=xe(t,e);return we({...o?{id:o.getAttribute("data-pipeup-id")??""}:{},path:Ke(o??e,t),...n?{point:{x:he(n.x),y:he(n.y)}}:{},...r?{view:r}:{},fingerprint:E(t.textContent??""),snapshot:C(y(t.textContent??""),0,ge)})}function he(t){return Number.isFinite(t)?Math.min(1,Math.max(0,t)):0}function ze(t,e){let n=Array.from({length:e.length+1},(o,i)=>i),r=new Array(e.length+1).fill(0);for(let o=1;o<=t.length;o++){r[0]=o;for(let i=1;i<=e.length;i++){let s=t.charCodeAt(o-1)===e.charCodeAt(i-1)?0:1;r[i]=Math.min((n[i]??0)+1,(r[i-1]??0)+1,(n[i-1]??0)+s)}[n,r]=[r,n]}return n[e.length]??0}function be(t,e,n){let r=e.length;if(r===0)return null;let o=Array.from({length:r+1},(d,O)=>O),i=new Array(r+1).fill(0),s=-1,a=1/0;for(let d=1;d<=t.length;d++){i[0]=0;let O=t.charCodeAt(d-1);for(let x=1;x<=r;x++){let Se=e.charCodeAt(x-1)===O?0:1;i[x]=Math.min((o[x]??0)+1,(i[x-1]??0)+1,(o[x-1]??0)+Se)}let Z=i[r]??1/0;Z<a&&(a=Z,s=d),[o,i]=[i,o]}if(a>n)return null;let c=Math.max(0,s-r),p=1/0;for(let d=Math.max(0,s-r-n);d<=Math.min(s,s-r+n);d++){let O=ze(t.slice(d,s),e);O<p&&(p=O,c=d)}return{start:c,end:s,distance:p}}var S={state:"orphaned",element:null,range:null},Xe=5e4,Ge=300,Ze=12,Qe=":scope > ";function Je(t,e){for(let n of t.querySelectorAll("[data-pipeup-id]"))if(n.getAttribute("data-pipeup-id")===e)return n;return null}function Ve(t,e,n={}){let r=t.id?Je(e,t.id):e;return t.quote?Ye(t,t.quote,r,e,n.fuzzy!==!1):We(t,r)}function We(t,e){if(!e)return S;let n=e;if(t.path){if(!t.path.startsWith(Qe))return S;try{n=e.querySelector(t.path)}catch{return S}}return n?{state:E(n.textContent??"")===t.fingerprint?"attached":"moved",element:n,range:null}:S}function Ye(t,e,n,r,o){let i=n??r,s=P(i),a=et(s.text,e);if(a>=0){let c=z(s,a,a+e.exact.length);if(c){let p=M(c.startContainer,r);return{state:n!==null&&E(p.textContent??"")===t.fingerprint?"attached":"moved",element:p,range:c}}}if(o){let c=i===r?s:P(r);if(c.text.length<=Xe&&e.exact.length>=Ze&&e.exact.length<=Ge){let p=be(c.text,e.exact,Math.floor(e.exact.length/4)),d=p?z(c,p.start,p.end):null;if(d)return{state:"moved",element:M(d.startContainer,r),range:d}}}return S}function et(t,e){if(!e.exact)return-1;let n=-1,r=-1;for(let o=t.indexOf(e.exact);o!==-1;o=t.indexOf(e.exact,o+1)){let i=t.slice(Math.max(0,o-e.prefix.length),o),s=t.slice(o+e.exact.length,o+e.exact.length+e.suffix.length),a=rt(i,e.prefix)+tt(s,e.suffix);a>r&&(n=o,r=a)}return n}function tt(t,e){let n=0;for(;n<t.length&&n<e.length&&t[n]===e[n];)n++;return n}function rt(t,e){let n=0;for(;n<t.length&&n<e.length&&t[t.length-1-n]===e[e.length-1-n];)n++;return n}var nt={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"},ot=40;function Ae(t){let e=t.getAttribute("data-pipeup-label");if(e)return e;let n=nt[t.tagName.toUpperCase()]??"Block",r=y(t.getAttribute("aria-label")??t.getAttribute("alt")??t.innerText??t.textContent??"");return r?`${n} \xB7 ${X(r,ot)}`:n}function it(t,e,n){let r=t.id??null,o=t.quote?.exact??null,i=t.point?`${Math.round(t.point.x*100)}% across, ${Math.round(t.point.y*100)}% down the element`:null,s=e.element;if(e.state==="orphaned"||!s)return{where:`No longer on the page (it read: "${t.snapshot}")`,element:null,id:r,quote:o,pin:i};let a=[],c=t.view?.slide;if(c){let d=s.closest("[data-pipeup-slide]")?.querySelector("h1,h2,h3")?.textContent;a.push(`Slide ${c}`+(d?` "${X(y(d))}"`:""))}else{let d=st(s,n);d&&a.push(`Section "${X(y(d.textContent??""))}"`)}let p=Ae(s);return a.push(p),{where:a.join(" \u203A "),element:p,id:r,quote:o,pin:i}}function st(t,e){let n=null;for(let r of e.querySelectorAll("h1,h2,h3")){if(r===t||r.contains(t))break;if(r.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING)n=r;else break}return n}function X(t,e=60){return t.length>e?t.slice(0,e-1)+"\u2026":t}var N=["Otter","Fox","Owl","Bear","Rabbit"],G=["Red","Orange","Yellow","Green","Teal","Blue","Purple","Pink","Brown","Grey"];function Oe(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e=Math.imul(e^e>>>16,2246822507),e=Math.imul(e^e>>>13,3266489909),(e^e>>>16)>>>0}var at=t=>Oe(t)%N.length,ct=t=>Math.floor(Oe(t)/N.length)%G.length,Ee=t=>`${G[ct(t)]} ${N[at(t)]}`,A=t=>t.name||Ee(t.author);var dt="Each thread says where it is: the slide or section, the element (its data-pipeup-id attribute in the HTML), and the exact quoted text or pin position. Work through the open threads in order, and for each one say what you changed or why you did not.";function $(t,e){let n=Math.max(0,Math.round((e-t)/1e3));if(n<60)return"just now";let r=Math.round(n/60);if(r<60)return`${r}m ago`;let o=Math.round(r/60);return o<48?`${o}h ago`:`${Math.round(o/24)}d ago`}function pt(t,e,n,r){return e==="ai"?ve(t,"## Comment thread",r,n):Pe(t)}function lt(t,e,n){let r=t.filter(a=>!a.thread.resolved);if(e==="text")return r.map(Pe).join(`
|
|
2
|
-
`);let o=t.length-r.length,i=[`# Review comments: ${u(n.title)}`,"",`- **Page:** ${u(n.url)}`,`- **Exported:** ${n.exportedAt.toISOString()}`,`- **Open threads:** ${r.length}${o?` (${o} resolved, not included)`:""}`,"",
|
|
3
|
-
`),s=n.exportedAt.getTime();return i+r.map((a,c)=>
|
|
4
|
-
`)}function u(t){return t.replace(/\s+/g," ").trim()}function
|
|
1
|
+
function f(t){let e="";for(let n of t)e+=String.fromCharCode(n);return btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function y(t){let e=t.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((t.length+3)%4),n=atob(e),r=new Uint8Array(n.length);for(let o=0;o<n.length;o++)r[o]=n.charCodeAt(o);return r}function Q(t=16){return f(crypto.getRandomValues(new Uint8Array(t)))}function h(t){return new TextEncoder().encode(t)}function b(t){if(t===null||typeof t!="object")return JSON.stringify(t);if(Array.isArray(t))return"["+t.map(b).join(",")+"]";let e=t;return"{"+Object.keys(e).filter(n=>e[n]!==void 0).sort().map(n=>JSON.stringify(n)+":"+b(e[n])).join(",")+"}"}function x(t){return t.replace(/\s+/g," ").trim()}function O(t){let e=x(t),n=2166136261;for(let r=0;r<e.length;r++)n^=e.charCodeAt(r),n=Math.imul(n,16777619)>>>0;return n.toString(16).padStart(8,"0")}var Te=/^[A-Za-z0-9_-]{43}$/,Ie=512,A=new Map;async function F(){let t=await crypto.subtle.generateKey({name:"Ed25519"},!1,["sign","verify"]),e=new Uint8Array(await crypto.subtle.exportKey("raw",t.publicKey));return{publicKey:f(e),privateKey:t.privateKey}}async function J(t,e){let n=await crypto.subtle.sign({name:"Ed25519"},t.privateKey,e);return f(new Uint8Array(n))}async function V(t,e,n){if(!Te.test(t))return!1;try{if(f(y(t))!==t)return!1;let r=A.get(t);if(!r){A.size>=Ie&&A.delete(A.keys().next().value),r=crypto.subtle.importKey("raw",y(t),{name:"Ed25519"},!0,["verify"]),A.set(t,r);let o=r;o.catch(()=>{A.get(t)===o&&A.delete(t)})}return await crypto.subtle.verify({name:"Ed25519"},await r,y(n),e)}catch{return!1}}var k=1e4,L=2**40,T=2**47,l={doc:64,path:2e3,snapshot:500,anchorId:200,quote:1e4,context:64,viewEntries:16,viewKey:64,viewValue:200},Ce=/^[0-9a-f]{8}$/,D=/^[A-Za-z0-9_-]{43}$/,Me=/^[A-Za-z0-9_-]{43}$/,Ne=new Set(["create","reply","edit","delete","resolve","reopen"]);async function W(t,e){if(t.author!==e.publicKey)throw new Error("pipeup: an op must be signed by its author");return{body:t,sig:await J(e,h(b(t)))}}var g=(t,e)=>typeof t=="string"&&t.length<=e,Y=t=>typeof t=="number"&&Number.isFinite(t)&&t>=0&&t<=1;function B(t){if(!t||typeof t!="object")return!1;let{id:e,path:n,fingerprint:r,snapshot:o,quote:i,point:s,view:a}=t;if(!g(n,l.path)||!g(o,l.snapshot)||typeof r!="string"||!Ce.test(r)||e!==void 0&&(!g(e,l.anchorId)||e===""))return!1;if(i!==void 0){if(!i||typeof i!="object")return!1;let c=i;if(!g(c.exact,l.quote)||c.exact===""||!g(c.prefix,l.context)||!g(c.suffix,l.context))return!1}if(s!==void 0){if(!s||typeof s!="object")return!1;let c=s;if(!Y(c.x)||!Y(c.y))return!1}if(a!==void 0){if(!a||typeof a!="object"||Array.isArray(a))return!1;let c=Object.entries(a);if(c.length>l.viewEntries||!c.every(([p,d])=>p.length<=l.viewKey&&g(d,l.viewValue)))return!1}return!0}function ee(t){if(!t||typeof t!="object")return!1;let{body:e,sig:n}=t;if(typeof n!="string"||!e||typeof e!="object")return!1;let r=e;return!(r.v!==1||typeof r.id!="string"||!D.test(r.id)||typeof r.kind!="string"||!Ne.has(r.kind)||!g(r.doc,l.doc)||r.doc===""||typeof r.thread!="string"||!D.test(r.thread)||typeof r.author!="string"||!Me.test(r.author)||typeof r.name!="string"||r.name.length>80||r.name!==r.name.trim()||typeof r.clock!="number"||!Number.isSafeInteger(r.clock)||r.clock<1||r.clock>L||typeof r.at!="number"||!Number.isSafeInteger(r.at)||r.at<0||r.at>T||r.text!==void 0&&(!g(r.text,k)||r.text!==r.text.trim())||r.target!==void 0&&(typeof r.target!="string"||!D.test(r.target))||(r.kind==="create"||r.kind==="reply"||r.kind==="edit")&&(typeof r.text!="string"||r.text.trim()==="")||(r.kind==="reply"||r.kind==="edit"||r.kind==="delete")&&!r.target||r.kind==="create"&&(r.id!==r.thread||!B(r.anchor)))}function te(t){return V(t.body.author,h(b(t.body)),t.sig)}function re(t,e){return t.body.clock!==e.body.clock?t.body.clock-e.body.clock:t.body.at!==e.body.at?t.body.at-e.body.at:t.body.author!==e.body.author?t.body.author<e.body.author?-1:1:t.body.id!==e.body.id?t.body.id<e.body.id?-1:1:0}function oe(t){let e=new Map,n=new Map,r=new Map;for(let{body:o}of[...t].sort(re)){if(o.name&&r.set(o.author,o.name),o.kind==="create"){if(e.has(o.id)||!o.anchor||o.text===void 0)continue;let a=ne(o.id,o.author,o.name,o.text,o.at);e.set(o.id,{id:o.id,anchor:o.anchor,root:a,resolved:!1}),n.set(o.id,{comment:a,thread:o.id});continue}let i=e.get(o.thread);if(!i)continue;if(o.kind==="resolve"||o.kind==="reopen"){i.resolved=o.kind==="resolve";continue}let s=o.target?n.get(o.target):void 0;if(!(!s||s.thread!==o.thread)){if(o.kind==="reply"){if(n.has(o.id)||o.text===void 0)continue;let a=ne(o.id,o.author,o.name,o.text,o.at);i.root.replies.push(a),n.set(o.id,{comment:a,thread:o.thread});continue}o.author!==s.comment.author||s.comment.deleted||(o.kind==="edit"&&o.text!==void 0&&(s.comment.text=o.text,s.comment.edited=!0),o.kind==="delete"&&(s.comment.text="",s.comment.deleted=!0))}}for(let{comment:o}of n.values())o.name||(o.unnamed=!0,o.name=r.get(o.author)??"");return[...e.values()]}function ne(t,e,n,r,o){return{id:t,author:e,name:n,text:r,at:o,edited:!1,deleted:!1,replies:[]}}async function _(t){let e={...t,id:void 0,thread:t.kind==="create"?void 0:t.thread},n=await crypto.subtle.digest("SHA-256",h(b(e)));return f(new Uint8Array(n))}var I=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 oe(this.ops.values())}async add(e){let n=[];for(let r of e)!ee(r)||r.body.doc!==this.doc||this.ops.has(r.body.id)||r.body.id!==await _(r.body)||!await te(r)||(this.ops.set(r.body.id,r),this.clock=Math.max(this.clock,r.body.clock),r.body.kind==="create"&&this.createAt.set(r.body.author,Math.max(this.createAt.get(r.body.author)??0,r.body.at)),this.threadAt.set(r.body.thread,Math.max(this.threadAt.get(r.body.thread)??0,r.body.at)),n.push(r));return n}async append(e,n,r){let o={v:1,...r,id:"",thread:r.kind==="create"?"":r.thread,doc:this.doc,author:e.publicKey,name:n,clock:Math.min(this.clock+1,L),at:Math.min(Math.max(Date.now(),r.kind==="create"?(this.createAt.get(e.publicKey)??0)+1:(this.threadAt.get(r.thread)??0)+1),T)};for(let a=0;;a++){if(a===1e3)throw new Error("pipeup: could not record this change");if(o.id=await _(o),!this.ops.has(o.id)||o.at>=T)break;o.at+=1}let i=this.ops.get(o.id);if(i)return i;o.kind==="create"&&(o.thread=o.id);let[s]=await this.add([await W(o,e)]);if(!s)throw new Error("pipeup: could not record this change");return s}};var $e=/^([A-Za-z0-9_-]{16}):([A-Za-z0-9_-]{43})$/;function Re(){return`${Q(12)}:${f(crypto.getRandomValues(new Uint8Array(32)))}`}async function Fe(t){let e=$e.exec(t.trim()),n=e?.[1],r=e?.[2];if(!n||!r)throw new Error('pipeup: data-pipeup-doc must look like "<id>:<key>", as made by newDocumentAttribute()');let o=await crypto.subtle.importKey("raw",y(r),{name:"AES-GCM"},!1,["encrypt","decrypt"]);return{id:n,key:o}}async function ie(t,e,n){let r=crypto.getRandomValues(new Uint8Array(12)),o=await crypto.subtle.encrypt({name:"AES-GCM",iv:r,additionalData:h(n)},t,h(e));return{iv:f(r),data:f(new Uint8Array(o))}}async function se(t,e,n){try{let r=await crypto.subtle.decrypt({name:"AES-GCM",iv:y(e.iv),additionalData:h(n)},t,y(e.data));return new TextDecoder().decode(r)}catch{throw new Error("pipeup: this feedback could not be opened with this document")}}var De=5e6,ae=t=>`pipeup-file:${t}`;async function ce(t,e,n){let r=n?{pipeup:1,doc:t,sealed:!0,...await ie(n,JSON.stringify(e),ae(t))}:{pipeup:1,doc:t,sealed:!1,ops:e};return JSON.stringify(r,null,2)}async function de(t,e,n){if(t.length>De)throw new Error("pipeup: this feedback file is too large");let r;try{r=JSON.parse(t)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}if(!r||typeof r!="object"||r.pipeup!==1||typeof r.doc!="string")throw new Error("pipeup: this is not an Pipeup feedback file");if(r.doc!==e)throw new Error("pipeup: this feedback is for a different document");if(!r.sealed)return Array.isArray(r.ops)?r.ops:[];if(!n)throw new Error("pipeup: this feedback is sealed, and this page has no document key");if(typeof r.iv!="string"||typeof r.data!="string")throw new Error("pipeup: this is not an Pipeup feedback file");let o;try{o=await se(n,{iv:r.iv,data:r.data},ae(e))}catch{throw new Error("pipeup: this feedback could not be opened with this document's key")}let i;try{i=JSON.parse(o)}catch{throw new Error("pipeup: this is not an Pipeup feedback file")}return Array.isArray(i)?i:[]}var pe=80,v=class extends Error{constructor(n,r,o=1){super("pipeup: shown here, but not saved yet");this.id=n;this.cause=r;this.count=o;this.name="UnsavedChangeError"}},U=class t{constructor(e,n){this.log=e;this.options=n;this.displayName=n.name.trim()?le(n.name):""}listeners=new Set;cache=[];comments=new Map;displayName;queue=Promise.resolve();unsaved=[];static async open(e){if(typeof e.doc!="string"||e.doc===""||e.doc.length>l.doc)throw new Error(`pipeup: the document id must be 1 to ${l.doc} characters`);let n=new I(e.doc);await n.add(await e.store.load(e.doc));let r=new t(n,e);return r.refresh(!1),r}get id(){return this.options.doc}get me(){return this.options.identity.publicKey}get name(){return this.displayName}set name(e){this.displayName=le(e),this.refresh(!0)}threads(){return this.cache}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}comment(e,n){return this.enqueue(()=>this.write({kind:"create",anchor:e,text:K(n)}))}reply(e,n){return this.enqueue(()=>this.write({kind:"reply",thread:this.find(e).thread,target:e,text:K(n)}))}edit(e,n){return this.enqueue(async()=>{let{thread:r}=this.mine(e);await this.write({kind:"edit",thread:r,target:e,text:K(n)})})}remove(e){return this.enqueue(async()=>{let{thread:n}=this.mine(e);await this.write({kind:"delete",thread:n,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)})})}flush(){return this.enqueue(()=>this.persist())}exportFile(){return ce(this.options.doc,this.log.all(),this.options.key)}importFile(e){return this.enqueue(async()=>{let n=await this.log.add(await de(e,this.options.doc,this.options.key));this.unsaved.push(...n),n.length>0&&this.refresh(!0);try{await this.persist()}catch(r){throw n.length>0?new v(n[0].body.id,r,n.length):r}return n.length})}enqueue(e){let n=this.queue.then(e);return this.queue=n.catch(()=>{}),n}async write(e){let n=await this.log.append(this.options.identity,this.displayName,e);this.unsaved.push(n),this.refresh(!0);try{await this.persist()}catch(r){throw new v(n.body.id,r)}return n.body.id}async persist(){if(this.unsaved.length===0)return;let e=[...this.unsaved];await this.options.store.append(this.options.doc,e),this.unsaved=this.unsaved.filter(n=>!e.includes(n))}refresh(e){this.cache=this.log.threads(),this.comments.clear();let n=(r,o)=>{r.unnamed&&r.author===this.me&&this.displayName&&(r.name=this.displayName),this.comments.set(r.id,{comment:r,thread:o});for(let i of r.replies)n(i,o)};for(let r of this.cache)n(r.root,r.id);if(e)for(let r of this.listeners)try{r(this.cache)}catch(o){globalThis.reportError?.(o)}}find(e){let n=this.comments.get(e);if(!n)throw new Error("pipeup: there is no comment with that id");return n}mine(e){let n=this.find(e);if(n.comment.author!==this.me)throw new Error("pipeup: only the writer can change a comment");return n}thread(e){if(!this.cache.some(n=>n.id===e))throw new Error("pipeup: there is no thread with that id");return e}};function K(t){let e=t.trim();if(!e)throw new Error("pipeup: a comment needs some words");if(e.length>k)throw new Error(`pipeup: comments are limited to ${k} characters`);return e}function le(t){let e=t.replace(/\s+/g," ").trim();if(!e||e.length>pe)throw new Error(`pipeup: choose a name of 1 to ${pe} characters`);return e}var q=class{docs=new Map;profile=null;async load(e){return[...this.docs.get(e)?.values()??[]]}async append(e,n){let r=this.docs.get(e);r||this.docs.set(e,r=new Map);for(let o of n)r.set(o.body.id,o)}async loadProfile(){return this.profile}async saveProfile(e){this.profile=e}async saveProfileIfAbsent(e){return this.profile||(this.profile=e),this.profile}},ue="",Le="Reviewer";async function Be(t,e=ue){let n=await t.loadProfile();if(n)return n.name===Le?{...n,name:""}:n;let r={identity:await F(),name:e};return t.saveProfileIfAbsent(r)}var j=class t{constructor(e){this.db=e}static open(e="pipeup"){return new Promise((n,r)=>{let o=indexedDB.open(e,1);o.onupgradeneeded=()=>{let i=o.result;i.createObjectStore("ops",{keyPath:["doc","id"]}).createIndex("doc","doc"),i.createObjectStore("meta")},o.onsuccess=()=>{let i=o.result;i.onversionchange=()=>i.close(),n(new t(i))},o.onerror=()=>r(o.error??new Error("pipeup: could not open local storage"))})}close(){this.db.close()}async load(e){return(await this.request("ops","readonly",r=>r.index("doc").getAll(e))).map(r=>r.op)}async append(e,n){if(n.length===0)return;let r=this.db.transaction("ops","readwrite"),o=r.objectStore("ops"),i=_e(r);try{for(let s of n)o.put({doc:e,id:s.body.id,op:s})}catch(s){throw r.abort(),i.catch(()=>{}),s}await i}async loadProfile(){return await this.request("meta","readonly",e=>e.get("profile"))??null}async saveProfile(e){await this.request("meta","readwrite",n=>n.put(e,"profile"))}async saveProfileIfAbsent(e){return new Promise((n,r)=>{let o=this.db.transaction("meta","readwrite"),i=o.objectStore("meta"),s=e;o.oncomplete=()=>n(s),o.onerror=()=>r(o.error??new Error("pipeup: local storage write failed")),o.onabort=()=>r(o.error??new Error("pipeup: local storage write aborted"));let a=i.get("profile");a.onsuccess=()=>{a.result?s=a.result:i.put(e,"profile")}})}request(e,n,r){return new Promise((o,i)=>{let s=r(this.db.transaction(e,n).objectStore(e));s.onsuccess=()=>o(s.result),s.onerror=()=>i(s.error??new Error("pipeup: local storage request failed"))})}};function _e(t){return new Promise((e,n)=>{t.oncomplete=()=>e(),t.onerror=()=>n(t.error??new Error("pipeup: local storage write failed")),t.onabort=()=>n(t.error??new Error("pipeup: local storage write aborted"))})}function P(t){let n=(t.ownerDocument??t).createTreeWalker(t,NodeFilter.SHOW_TEXT),r=[],o="";for(let i=n.nextNode();i;i=n.nextNode())r.push({node:i,start:o.length}),o+=i.data;return{text:o,nodes:r}}function H(t,e,n){let o=(t.ownerDocument??t).createRange();return o.setStart(t,0),o.setEnd(e,n),o.toString().length}function z(t,e,n){let r=fe(t,e,!1),o=fe(t,n,!0);if(!r||!o||n<e)return null;let i=r.node.ownerDocument.createRange();return i.setStart(r.node,r.offset),i.setEnd(o.node,o.offset),i}function fe(t,e,n){for(let o of t.nodes){let i=o.start+o.node.data.length;if(e>=o.start&&(e<i||n&&e===i))return{node:o.node,offset:e-o.start}}let r=t.nodes[t.nodes.length-1];return r&&e===r.start+r.node.data.length?{node:r.node,offset:r.node.data.length}:null}var me=32,ge=200,Ke="p,li,h1,h2,h3,h4,h5,h6,td,th,blockquote,pre,figcaption,dt,dd,summary,caption";function ye(t){return t.nodeType===Node.ELEMENT_NODE?t:t.parentElement}function xe(t,e){for(let n=ye(t)?.closest("[data-pipeup-id]")??null;n;){if(!e.contains(n))return null;let r=n.getAttribute("data-pipeup-id")??"";if(r!==""&&r.length<=l.anchorId)return n;n=n.parentElement?.closest("[data-pipeup-id]")??null}return null}function Ue(t){let e=t;return/[\uD800-\uDBFF]$/.test(e)&&(e=e.slice(0,-1)),/^[\uDC00-\uDFFF]/.test(e)&&(e=e.slice(1)),e}function C(t,e,n){return Ue(t.slice(e,n))}function qe(t,e){let n=je(t,e);if(n.length>l.path)throw new Error("pipeup: this element is nested too deeply to comment on \u2014 give a nearby container a data-pipeup-id");return n}function we(t){if(!B(t))throw new Error("pipeup: could not describe this place on the page");return t}function M(t,e){let n=ye(t),r=n?.closest(Ke)??null;return r&&e.contains(r)?r:n&&e.contains(n)?n:e}function je(t,e){if(t===e)return"";let n=[];for(let r=e;r&&r!==t;r=r.parentElement){let o=1;for(let i=r.previousElementSibling;i;i=i.previousElementSibling)i.tagName===r.tagName&&o++;n.unshift(`${r.tagName.toLowerCase()}:nth-of-type(${o})`)}return":scope > "+n.join(" > ")}function He(t,e,n){if(!e.contains(t.commonAncestorContainer))throw new Error("pipeup: the selection is outside the commentable area");let r=xe(t.commonAncestorContainer,e),o=r??e,{text:i}=P(o),s=H(o,t.startContainer,t.startOffset),a=H(o,t.endContainer,t.endOffset),c=i.slice(s,a);if(c==="")throw new Error("pipeup: select some text to comment on");if(c.length>l.quote)throw new Error(`pipeup: selections are limited to ${l.quote} characters`);let p=C(i,Math.max(0,s-me),s),d=C(i,a,a+me);return we({...r?{id:r.getAttribute("data-pipeup-id")??""}:{},path:"",quote:{exact:c,prefix:p,suffix:d},...n?{view:n}:{},fingerprint:O(M(t.startContainer,e).textContent??""),snapshot:C(x(p+c+d),0,ge)})}function ze(t,e,n,r){let o=xe(t,e);return we({...o?{id:o.getAttribute("data-pipeup-id")??""}:{},path:qe(o??e,t),...n?{point:{x:he(n.x),y:he(n.y)}}:{},...r?{view:r}:{},fingerprint:O(t.textContent??""),snapshot:C(x(t.textContent??""),0,ge)})}function he(t){return Number.isFinite(t)?Math.min(1,Math.max(0,t)):0}function Xe(t,e){let n=Array.from({length:e.length+1},(o,i)=>i),r=new Array(e.length+1).fill(0);for(let o=1;o<=t.length;o++){r[0]=o;for(let i=1;i<=e.length;i++){let s=t.charCodeAt(o-1)===e.charCodeAt(i-1)?0:1;r[i]=Math.min((n[i]??0)+1,(r[i-1]??0)+1,(n[i-1]??0)+s)}[n,r]=[r,n]}return n[e.length]??0}function be(t,e,n){let r=e.length;if(r===0)return null;let o=Array.from({length:r+1},(d,m)=>m),i=new Array(r+1).fill(0),s=-1,a=1/0;for(let d=1;d<=t.length;d++){i[0]=0;let m=t.charCodeAt(d-1);for(let w=1;w<=r;w++){let ke=e.charCodeAt(w-1)===m?0:1;i[w]=Math.min((o[w]??0)+1,(i[w-1]??0)+1,(o[w-1]??0)+ke)}let Z=i[r]??1/0;Z<a&&(a=Z,s=d),[o,i]=[i,o]}if(a>n)return null;let c=Math.max(0,s-r),p=1/0;for(let d=Math.max(0,s-r-n);d<=Math.min(s,s-r+n);d++){let m=Xe(t.slice(d,s),e);m<p&&(p=m,c=d)}return{start:c,end:s,distance:p}}var S={state:"orphaned",element:null,range:null},Ge=5e4,Ze=300,Qe=12,Je=":scope > ";function Ve(t,e){for(let n of t.querySelectorAll("[data-pipeup-id]"))if(n.getAttribute("data-pipeup-id")===e)return n;return null}function Ye(t,e,n={}){let r=t.id?Ve(e,t.id):e;return t.quote?et(t,t.quote,r,e,n.fuzzy!==!1):We(t,r)}function We(t,e){if(!e)return S;let n=e;if(t.path){if(!t.path.startsWith(Je))return S;try{n=e.querySelector(t.path)}catch{return S}}return n?{state:O(n.textContent??"")===t.fingerprint?"attached":"moved",element:n,range:null}:S}function et(t,e,n,r,o){let i=n??r,s=P(i),a=tt(s.text,e);if(a>=0){let c=z(s,a,a+e.exact.length);if(c){let p=M(c.startContainer,r);return{state:n!==null&&O(p.textContent??"")===t.fingerprint?"attached":"moved",element:p,range:c}}}if(o){let c=i===r?s:P(r);if(c.text.length<=Ge&&e.exact.length>=Qe&&e.exact.length<=Ze){let p=be(c.text,e.exact,Math.floor(e.exact.length/4)),d=p?z(c,p.start,p.end):null;if(d)return{state:"moved",element:M(d.startContainer,r),range:d}}}return S}function tt(t,e){if(!e.exact)return-1;let n=-1,r=-1;for(let o=t.indexOf(e.exact);o!==-1;o=t.indexOf(e.exact,o+1)){let i=t.slice(Math.max(0,o-e.prefix.length),o),s=t.slice(o+e.exact.length,o+e.exact.length+e.suffix.length),a=nt(i,e.prefix)+rt(s,e.suffix);a>r&&(n=o,r=a)}return n}function rt(t,e){let n=0;for(;n<t.length&&n<e.length&&t[n]===e[n];)n++;return n}function nt(t,e){let n=0;for(;n<t.length&&n<e.length&&t[t.length-1-n]===e[e.length-1-n];)n++;return n}var ot={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"},it=40;function Ae(t){return t.getAttribute("data-pipeup-label")||ot[t.tagName.toUpperCase()]||"Block"}function st(t){return X(x(t.getAttribute("aria-label")??t.getAttribute("alt")??t.innerText??t.textContent??""),it)}function Ee(t){let e=t.getAttribute("data-pipeup-label");if(e)return e;let n=st(t);return n?`${Ae(t)} \xB7 ${n}`:Ae(t)}function at(t,e,n){let r=t.id??null,o=t.quote?.exact??null,i=t.point?`${Math.round(t.point.x*100)}% across, ${Math.round(t.point.y*100)}% down the element`:null,s=e.element;if(e.state==="orphaned"||!s)return{where:`No longer on the page (it read: "${t.snapshot}")`,element:null,id:r,quote:o,pin:i};let a=[],c=t.view?.slide;if(c){let d=s.closest("[data-pipeup-slide]")?.querySelector("h1,h2,h3")?.textContent;a.push(`Slide ${c}`+(d?` "${X(x(d))}"`:""))}else{let d=ct(t.view);d&&a.push(d);let m=dt(s,n);m&&a.push(`Section "${X(x(m.textContent??""))}"`)}let p=Ee(s);return a.push(p),{where:a.join(" \u203A "),element:p,id:r,quote:o,pin:i}}function ct(t){return t?t.label||Object.entries(t).filter(([e,n])=>n&&e!=="slide").map(([,e])=>e).join(" \xB7 "):""}function dt(t,e){let n=null;for(let r of e.querySelectorAll("h1,h2,h3")){if(r===t||r.contains(t))break;if(r.compareDocumentPosition(t)&4)n=r;else break}return n}function X(t,e=60){return t.length>e?t.slice(0,e-1)+"\u2026":t}var N=["Otter","Fox","Owl","Bear","Rabbit"],G=["Red","Orange","Yellow","Green","Teal","Blue","Purple","Pink","Brown","Grey"];function Oe(t){let e=2166136261;for(let n=0;n<t.length;n++)e=Math.imul(e^t.charCodeAt(n),16777619);return e=Math.imul(e^e>>>16,2246822507),e=Math.imul(e^e>>>13,3266489909),(e^e>>>16)>>>0}var pt=t=>Oe(t)%N.length,lt=t=>Math.floor(Oe(t)/N.length)%G.length,ve=t=>`${G[lt(t)]} ${N[pt(t)]}`,E=t=>t.name||ve(t.author);var ut="Each thread says where it is: the slide or section, the element (its data-pipeup-id attribute in the HTML), and the exact quoted text or pin position. Work through the open threads in order, and for each one say what you changed or why you did not.";function $(t,e){let n=Math.max(0,Math.round((e-t)/1e3));if(n<60)return"just now";let r=Math.round(n/60);if(r<60)return`${r}m ago`;let o=Math.round(r/60);return o<48?`${o}h ago`:`${Math.round(o/24)}d ago`}function ft(t,e,n,r){return e==="ai"?Pe(t,"## Comment thread",r,n):Se(t)}function mt(t,e,n){let r=t.filter(a=>!a.thread.resolved);if(e==="text")return r.map(Se).join(`
|
|
2
|
+
`);let o=t.length-r.length,i=[`# Review comments: ${u(n.title)}`,"",`- **Page:** ${u(n.url)}`,`- **Exported:** ${n.exportedAt.toISOString()}`,`- **Open threads:** ${r.length}${o?` (${o} resolved, not included)`:""}`,"",ut,"",""].join(`
|
|
3
|
+
`),s=n.exportedAt.getTime();return i+r.map((a,c)=>Pe(a,`## Thread ${c+1}`,s)).join(`
|
|
4
|
+
`)}function u(t){return t.replace(/\s+/g," ").trim()}function Pe(t,e,n,r){let{thread:o,location:i}=t,s=o.root.replies.length,a=[`${e} \xB7 ${o.resolved?"resolved":"open"}`];if(a.push(`- **Thread:** ${o.id}`),r&&a.push(`- **Page:** ${u(r)}`),a.push(`- **Where:** ${u(i.where)}`),i.id){let c=u(i.id.replace(/`/g,""));a.push(`- **Element:** \`[data-pipeup-id="${c}"]\`${i.element?` (${u(i.element)})`:""}`)}i.quote&&a.push(`- **Quoted text:** "${u(i.quote)}"`),i.pin&&a.push(`- **Pin:** ${u(i.pin)}`),a.push(`- **Started by:** ${u(E(o.root))}, ${$(o.root.at,n)}${s?` \xB7 ${s} ${s===1?"reply":"replies"}`:""}`,"",`**${u(E(o.root))}** (${$(o.root.at,n)}): ${R(o.root," ")}`);for(let c of o.root.replies)a.push(`- **${u(E(c))}** (${$(c.at,n)}): ${R(c," ")} <!-- comment:${c.id} -->`);return a.join(`
|
|
5
5
|
`)+`
|
|
6
|
-
`}function
|
|
6
|
+
`}function Se(t){let{thread:e,location:n}=t,r=[u(n.where)+(n.quote?`, on the text "${u(n.quote)}"`:""),`${u(E(e.root))}: ${R(e.root," ")}`];for(let o of e.root.replies)r.push(` ${u(E(o))}: ${R(o," ")}`);return r.join(`
|
|
7
7
|
`)+`
|
|
8
|
-
`}function
|
|
9
|
-
`+e)+(t.edited?" (edited)":"")}var
|
|
8
|
+
`}function R(t,e){return t.deleted?"(deleted)":t.text.replace(/\r\n|\r|\n/g,`
|
|
9
|
+
`+e)+(t.edited?" (edited)":"")}var rr="0.4.0-beta.3";export{N as ANIMALS,G as COLOURS,ue as DEFAULT_PROFILE_NAME,j as IndexedDbStore,q as MemoryStore,U as PipeupDocument,v as UnsavedChangeError,rr as VERSION,ve as animalName,mt as copyAll,ft as copyThread,F as createIdentity,ze as describeElement,He as describeRange,$ as formatAgo,Ee as labelOf,Be as loadOrCreateProfile,at as locate,E as nameOf,Re as newDocumentAttribute,Fe as parseDocumentAttribute,Ye as resolveAnchor};
|