hypothesis 1.1006.0 → 1.1007.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,9 +112,10 @@ annotate:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox
112
112
  "arrow-left":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 12L3 8l4-4M4 8h9-9z"></path></g></svg>\n',"arrow-right":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 4l4 4-4 4m3-4H3h9z"></path></g></svg>\n',cancel:Lo,"caret-right":Qo,
113
113
  "cc-std":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="currentColor" stroke="none" d="M7.985 0c2.238 0 4.143.781 5.715 2.343a7.694 7.694 0 011.714 2.579C15.804 5.888 16 6.914 16 8a8.164 8.164 0 01-.579 3.078 7.344 7.344 0 01-1.707 2.536 8.222 8.222 0 01-2.657 1.772c-.99.41-2.014.614-3.071.614a7.775 7.775 0 01-3.036-.607 8.047 8.047 0 01-2.6-1.757A7.846 7.846 0 010 8c0-1.057.202-2.074.607-3.05A8.033 8.033 0 012.371 2.33C3.895.777 5.766 0 7.985 0zm.03 1.443c-1.83 0-3.367.638-4.615 1.914a6.878 6.878 0 00-1.45 2.15A6.301 6.301 0 001.443 8c0 .858.168 1.684.507 2.479a6.627 6.627 0 001.45 2.129 6.593 6.593 0 002.129 1.428c.79.329 1.619.493 2.485.493.857 0 1.688-.166 2.494-.5a6.91 6.91 0 002.178-1.442c1.247-1.22 1.871-2.748 1.871-4.586a6.57 6.57 0 00-.486-2.515 6.397 6.397 0 00-1.413-2.114C11.37 2.086 9.824 1.443 8.014 1.443zm-.1 5.229l-1.073.557c-.114-.238-.254-.405-.42-.5a.95.95 0 00-.465-.143c-.714 0-1.072.472-1.072 1.415 0 .428.09.77.271 1.028.181.257.448.386.8.386.467 0 .796-.229.987-.686l.985.5a2.35 2.35 0 01-2.1 1.257c-.714 0-1.29-.218-1.729-.657-.438-.438-.657-1.047-.657-1.828 0-.762.222-1.367.665-1.814.442-.448 1.002-.672 1.678-.672.991 0 1.7.385 2.13 1.157zm4.613 0l-1.057.557c-.114-.238-.255-.405-.421-.5a.972.972 0 00-.479-.143c-.714 0-1.072.472-1.072 1.415 0 .428.091.77.272 1.028.18.257.447.386.8.386.466 0 .795-.229.985-.686l1 .5c-.218.39-.514.698-.885.922a2.308 2.308 0 01-1.214.335c-.724 0-1.302-.218-1.735-.657-.434-.438-.65-1.047-.65-1.828 0-.762.22-1.367.664-1.814.442-.448 1.002-.672 1.678-.672.99 0 1.696.385 2.114 1.157z"></path></g></svg>',
114
114
  "cc-zero":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="currentColor" stroke="none" d="M7.983 0c2.238 0 4.148.78 5.72 2.342a7.662 7.662 0 011.715 2.582c.39.962.582 1.99.582 3.076a8.13 8.13 0 01-.583 3.087 7.262 7.262 0 01-1.703 2.526 8.213 8.213 0 01-2.655 1.77c-.99.41-2.018.617-3.076.617a7.902 7.902 0 01-3.042-.6 8.301 8.301 0 01-2.6-1.759A8.087 8.087 0 01.6 11.042 7.84 7.84 0 010 8c0-1.057.2-2.07.6-3.042a8.12 8.12 0 011.77-2.633C3.893.772 5.764 0 7.983 0zm.034 1.44c-1.829 0-3.369.64-4.616 1.915a6.962 6.962 0 00-1.457 2.157 6.388 6.388 0 000 4.969 6.83 6.83 0 003.585 3.558c.79.324 1.62.487 2.488.487.857 0 1.681-.165 2.482-.498a6.88 6.88 0 002.184-1.446C13.931 11.364 14.56 9.838 14.56 8a6.57 6.57 0 00-.487-2.515 6.418 6.418 0 00-1.418-2.118C11.37 2.081 9.826 1.44 8.017 1.44zM8 3.395c2.641 0 3.305 2.492 3.305 4.605 0 2.113-.664 4.605-3.305 4.605S4.694 10.113 4.694 8l.007-.355c.073-2.027.804-4.25 3.299-4.25zm1.316 3.227L7.35 10.017c-.274.412-.083.645.219.774l.135.044c.091.022.19.034.297.034 1.357 0 1.422-1.938 1.422-2.869l-.007-.409a7.282 7.282 0 00-.06-.72l-.04-.25zM8 5.132c-1.258 0-1.406 1.66-1.421 2.646L6.577 8c0 .24.005.544.035.865l.027.244 1.759-3.232c.182-.316.09-.542-.101-.706A1.222 1.222 0 008 5.13z"></path></g></svg>',
115
- "collapse-menu":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 10l4-4 4 4"></path></g></svg>',collapsed:Qo,copy:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 15H1V5h3m11-4v10H7V1h8z"></path></g></svg>',
116
- edit:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 4l1 1-9 9-2 1 1-2 9-9zm3-3l1 1-1 1-1-1 1-1z"></path></g></svg>\n',email:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 3v10h14V3H1zm0 0l7 6 7-6H1z"></path></g></svg>',
117
- "expand-menu":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">\n <path fill="currentColor" fill-rule="nonzero" d="M7.456 11.788L1.226 5.92a.695.695 0 0 1 0-1.025l.726-.684a.804.804 0 0 1 1.087-.001L8 8.861l4.961-4.65a.804.804 0 0 1 1.087.001l.727.684c.3.283.3.742 0 1.025l-6.23 5.867a.804.804 0 0 1-1.09 0z"/>\n</svg>',error:Lo,external:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 3h6v6m-1-5l-9 9 9-9z"></path></g></svg>',
115
+ "collapse-menu":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 10l4-4 4 4"></path></g></svg>',collapse:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 11l-4 4 4-4zm-3-1h4v4m9-13l-4 4 4-4zm-1 5h-4V2"></path></g></svg>',collapsed:Qo,
116
+ copy:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 15H1V5h3m11-4v10H7V1h8z"></path></g></svg>',edit:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 4l1 1-9 9-2 1 1-2 9-9zm3-3l1 1-1 1-1-1 1-1z"></path></g></svg>\n',
117
+ email:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 3v10h14V3H1zm0 0l7 6 7-6H1z"></path></g></svg>',"expand-menu":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">\n <path fill="currentColor" fill-rule="nonzero" d="M7.456 11.788L1.226 5.92a.695.695 0 0 1 0-1.025l.726-.684a.804.804 0 0 1 1.087-.001L8 8.861l4.961-4.65a.804.804 0 0 1 1.087.001l.727.684c.3.283.3.742 0 1.025l-6.23 5.867a.804.804 0 0 1-1.09 0z"/>\n</svg>',error:Lo,
118
+ expand:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2 14l4-4-4 4zm3 1H1v-4m13-9l-4 4 4-4zm-3-1h4v4"></path></g></svg>',external:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 3h6v6m-1-5l-9 9 9-9z"></path></g></svg>',
118
119
  facebook:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="currentColor" stroke="none" d="M15.999 8.049c0-4.445-3.582-8.049-8-8.049S0 3.604 0 8.049C0 12.066 2.925 15.396 6.75 16v-5.624H4.717V8.049H6.75V6.276c0-2.018 1.195-3.132 3.022-3.132.875 0 1.79.157 1.79.157v1.981h-1.008c-.994 0-1.304.62-1.304 1.257v1.51h2.219l-.355 2.327H9.25V16c3.825-.604 6.75-3.934 6.75-7.951z"></path></g></svg>',flag:'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 9v6V1h12l-4 4 4 4H3z"></path></g></svg>',
119
120
  "flag--active":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="currentColor" stroke="none" d="M2 1a1 1 0 01.883-.993L3 0h12c.852 0 1.297.986.783 1.623l-.076.084L12.415 5l3.292 3.293c.575.575.253 1.523-.485 1.684l-.108.017L15 10H4v5a1 1 0 01-1.993.117L2 15V1z"></path></g></svg>',
120
121
  "format-bold":'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><g fill-rule="evenodd"><rect fill="none" stroke="none" x="0" y="0" width="16" height="16"></rect><path fill="currentColor" stroke="none" d="M8.661 16c.805 0 1.536-.117 2.193-.351a4.953 4.953 0 001.69-.993c.47-.428.831-.947 1.081-1.557s.375-1.287.375-2.03c0-.29-.038-.588-.114-.893a4.123 4.123 0 00-.325-.87 3.937 3.937 0 00-.495-.754 4.412 4.412 0 00-.604-.597c-.17-.126-.17-.264 0-.412.381-.335.699-.772.953-1.311.254-.54.382-1.062.382-1.568 0-.64-.132-1.244-.394-1.813a4.628 4.628 0 00-1.081-1.484c-.458-.42-1-.753-1.627-.999A5.531 5.531 0 008.66 0h-6.14a.534.534 0 00-.362.14A.415.415 0 002 .456v15.086c0 .119.053.225.159.318.106.093.227.139.362.139h6.14zm-.127-9.852H5.826c-.17 0-.254-.075-.254-.223V3.437c0-.157.085-.235.254-.235h2.708c.45 0 .847.145 1.195.435.347.29.521.633.521 1.027 0 .394-.174.74-.521 1.038a1.784 1.784 0 01-1.195.446zm0 6.65H5.826c-.17 0-.254-.075-.254-.223v-2.99c0-.157.085-.235.254-.235h2.708c.56 0 1.004.177 1.335.53.33.353.495.75.495 1.188 0 .454-.165.856-.495 1.205-.33.35-.776.525-1.335.525z"></path></g></svg>',
@@ -515,142 +516,143 @@ o=n.subParser("makeMarkdown.strikethrough")(e,t);break;case"a":o=n.subParser("ma
515
516
  var r,o,i="",a=[[],[]],s=e.querySelectorAll("thead>tr>th"),l=e.querySelectorAll("tbody>tr");for(r=0;r<s.length;++r){var c=n.subParser("makeMarkdown.tableCell")(s[r],t),u="---";if(s[r].hasAttribute("style"))switch(s[r].getAttribute("style").toLowerCase().replace(/\s/g,"")){case"text-align:left;":u=":---";break;case"text-align:right;":u="---:";break;case"text-align:center;":u=":---:"}a[0][r]=c.trim(),a[1][r]=u}for(r=0;r<l.length;++r){var h=a.push([])-1,d=l[r].getElementsByTagName("td");for(o=0;o<s.length;++o){var p=" ";void 0!==d[o]&&(p=n.subParser("makeMarkdown.tableCell")(d[o],t)),a[h].push(p)}}var m=3;for(r=0;r<a.length;++r)for(o=0;o<a[r].length;++o){var f=a[r][o].length;f>m&&(m=f)}for(r=0;r<a.length;++r){for(o=0;o<a[r].length;++o)1===r?":"===a[r][o].slice(-1)?a[r][o]=n.helper.padEnd(a[r][o].slice(-1),m-1,"-")+":":a[r][o]=n.helper.padEnd(a[r][o],m,"-"):a[r][o]=n.helper.padEnd(a[r][o],m);i+="| "+a[r].join(" | ")+" |\n"}return i.trim()})),n.subParser("makeMarkdown.tableCell",(function(e,t){var r=""
516
517
  ;if(!e.hasChildNodes())return"";for(var o=e.childNodes,i=o.length,a=0;a<i;++a)r+=n.subParser("makeMarkdown.node")(o[a],t,!0);return r.trim()})),n.subParser("makeMarkdown.txt",(function(e){var t=e.nodeValue;return t=(t=t.replace(/ +/g," ")).replace(/¨NBSP;/g," "),t=(t=(t=(t=(t=(t=(t=(t=(t=n.helper.unescapeHTMLEntities(t)).replace(/([*_~|`])/g,"\\$1")).replace(/^(\s*)>/g,"\\$1>")).replace(/^#/gm,"\\#")).replace(/^(\s*)([-=]{3,})(\s*)$/,"$1\\$2$3")).replace(/^( {0,3}\d+)\./gm,"$1\\.")).replace(/^( {0,3})([+-])/gm,"$1\\$2")).replace(/]([\s]*)\(/g,"\\]$1\\(")).replace(/^ {0,3}\[([\S \t]*?)]:/gm,"\\[$1]:")}));e.exports?e.exports=n:this.showdown=n}).call(W)}(bd);var wd=bd.exports;const xd=Ds(window);function kd(){return[{type:"output",filter:function(e){return e.replace(/<a href=/g,'<a target="_blank" href=')}}]}let Sd;function Cd(e){return"{math:"+e.toString()+"}"}function Ad(e){const t=function(e){const t=[];let n=0,r=e;for(;;){const e=r.indexOf("$$",n),o=r.indexOf("\\(",n);if(-1===e&&-1===o)break;let i,a
517
518
  ;if(-1!==e&&(-1===o||e<o)?(i=e,a=r.indexOf("$$",i+2)):(i=o,a=r.indexOf("\\)",i+2)),-1===a)break;a+=2;const s=t.length+1,l=Cd(s);let c;t.push({id:s,expression:r.slice(i+2,a-2),inline:-1!==o}),c=-1!==o?l:"\n\n"+l+"\n\n",r=r.slice(0,i)+c+r.slice(a),n=i+c.length}return{mathBlocks:t,content:r}}(e),n=xd.sanitize(function(e){return Sd||(Sd=new wd.Converter({extensions:[kd],simplifiedAutoLink:!0,literalMidWordUnderscores:!0,strikethrough:!0})),Sd.makeHtml(e)}(t.content)),r=function(e,t){return t.reduce(((e,t)=>{let n;try{n=t.inline?_d(t.expression):_d(t.expression,{displayMode:!0})}catch(e){n=Fs(t.expression)}return e.replace(Cd(t.id),n)}),e)}(n,t.mathBlocks);return r}function Ed({markdown:e="",textClass:t={},textStyle:n={}}){const r=lo((()=>e?Ad(e):""),[e]),o=so();io((()=>{!function(e,{className:t}={}){const n=Array.from(e.getElementsByTagName("a"));for(let e of n){const n=Ha(e);n&&(t?n.className=t:n.style.width="350px")}}(o.current,{className:"w-full md:w-[380px]"})}),[e]);return _o("div",{
518
- className:"w-full break-words cursor-text",dir:"auto",lang:"",children:_o("div",{className:Yr("styled-text",t),"data-testid":"styled-text",ref:o,dangerouslySetInnerHTML:{__html:r},style:n})})}function Td({annotation:e,tags:t}){const n=hi(),r=n.defaultAuthority(),o=lo((()=>!ii(e.user,r)),[e,r]),i=e=>n.getLink("search.tag",{tag:e});return _o("ul",{className:"TagList","aria-label":"Annotation tags",children:t.map((e=>_o("li",{className:"TagList__item",children:[o&&_o("a",{className:"TagList__link",href:i(e),lang:"",target:"_blank",rel:"noopener noreferrer","aria-label":`Tag: ${e}`,title:`View annotations with tag: ${e}`,children:e}),!o&&_o("span",{className:"TagList__text","aria-label":`Tag: ${e}`,lang:"",children:e})]},e)))})}xd.addHook("afterSanitizeAttributes",(e=>{"target"in e&&e.setAttribute("target","_blank")}));var Nd=ci((function({annotation:e,settings:t}){var n,r
519
- ;const[o,i]=ro(!0),[a,s]=ro(!1),l=hi().getDraft(e),c=o?"More":"Less",u=null!==(n=null==l?void 0:l.tags)&&void 0!==n?n:e.tags,h=null!==(r=null==l?void 0:l.text)&&void 0!==r?r:e.text,d=h.length>0,p=u.length>0,m=si(["annotationFontFamily"],t);return _o("div",{className:"hyp-u-vertical-spacing--2",children:[d&&_o(Pa,{collapse:o,collapsedHeight:400,inlineControls:!1,onCollapsibleChanged:s,onToggleCollapsed:i,overflowThreshold:20,children:_o(Ed,{textStyle:m,markdown:h,textClass:{AnnotationBody__text:!0,"p-redacted-content":Pi(e)}})}),a&&_o("div",{className:"hyp-u-layout-row--justify-right",children:_o(Ao,{expanded:!o,onClick:()=>i(!o),title:`Toggle visibility of full annotation text: Show ${c}`,children:c})}),p&&_o(Td,{annotation:e,tags:u})]})}),["settings"]);const Md=0,Ld=1;function zd(e,t,n,r){let o=e.selectionStart,i=e.selectionEnd;return o>=t+n?(o+=r.length-n,i+=r.length-n):i<=t||(o<=t&&i>=t+n?i+=r.length-n:o<t&&i<t+n?o=t:o<t+n&&i>t+n?i+=r.length-n:t<o&&t+n>i&&(o=t,i=t+n)),{
520
- text:e.text.slice(0,t)+r+e.text.slice(t+n),selectionStart:o,selectionEnd:i}}function Od(e,t=Md){const n=e.text.slice(e.selectionStart,e.selectionEnd);let r,o="";if(t===Ld&&(o="!"),n.match(/[a-z]+:\/\/.*/)){const t="Description";return r=zd(e,e.selectionStart,n.length,o+"["+t+"]("+n+")"),r.selectionStart=e.selectionStart+o.length+1,r.selectionEnd=r.selectionStart+t.length,r}{const t=o+"["+n+"](",i="http://insert-your-link-here.com";return r=zd(e,e.selectionStart,n.length,t+i+")"),r.selectionStart=e.selectionStart+t.length,r.selectionEnd=r.selectionStart+i.length,r}}function Id(e,t,n,r){void 0===n&&(n=t);const o=e.text.slice(e.selectionStart-t.length,e.selectionStart),i=e.text.slice(e.selectionEnd,e.selectionEnd+t.length);let a=e;return e.selectionStart===e.selectionEnd&&r&&(a=zd(e,e.selectionStart,0,r),a.selectionStart=a.selectionEnd-r.length),o===t&&i===n?(a=zd(a,a.selectionStart-t.length,t.length,""),a=zd(a,a.selectionEnd,n.length,"")):(a=zd(a,a.selectionStart,0,t),a=zd(a,a.selectionEnd,0,n)),a}
521
- function Pd(e,t){const n=e.indexOf("\n",t);return n<0?e.length:n}function Rd(e,t,n,r){let o=function(e,t){const n=e.lastIndexOf("\n",t);return n<0?0:n+1}(e.text,t),i=Pd(e.text,t);for(;i<=Pd(e.text,n);){const t=i===e.text.length,a=i-o,s=Pd((e=r(e,o,i)).text,o)-o;if(n+=s-a,t)break;o=o+s+1,i=Pd(e.text,o)}return e}function Dd(e,t){const n=e.selectionStart,r=e.selectionEnd;let o=!0;return Rd(e,n,r,((e,n)=>(e.text.slice(n,n+t.length)!==t&&(o=!1),e))),Rd(e,n,r,o?(e,n)=>zd(e,n,t.length,""):(e,n)=>e.text.slice(n,n+t.length)===t?e:zd(e,n,0,t))}const Bd={bold:"b",italic:"i",link:"l",quote:"q",image:"g",numlist:"o",list:"u"};function Fd({buttonRef:e,disabled:t=!1,iconName:n="",label:r,onClick:o,shortcutKey:i,tabIndex:a,title:s=""}){const l=lo((()=>((e=window.navigator.userAgent)=>e.indexOf("Mac OS")>=0)()?"Cmd":"Ctrl"),[]);let c=s;i&&(c+=` (${l}-${i.toUpperCase()})`);const u={buttonRef:e,disabled:t,icon:n,onClick:o,tabIndex:a,title:c};return r?_o(Ao,{classes:"font-normal TransparentButton",...u,children:r}):_o(Co,{
522
- classes:"MarkdownEditor__toolbar-button",...u})}function jd({isPreviewing:e,onCommand:t,onTogglePreview:n}){const r=0,o=1,i=2,a=3,s=4,l=5,c=6,u=7,h=8,d=9,p=10,[m,f]=ro(0),g=so([]).current;if(0===g.length)for(let e=0;e<=p;e++)g.push({current:null});const v=e=>m===e?0:-1;return _o("div",{className:"hyp-u-layout-row hyp-u-border--left hyp-u-border--right hyp-u-border--top hyp-u-bg-color--white MarkdownEditor__toolbar",role:"toolbar","aria-label":"Markdown editor toolbar",onKeyDown:t=>{let n=0;const r=p-1;e&&(n=h);let o=null;switch(Fo(t.key)){case"ArrowLeft":o=m<=n?r:m-1;break;case"ArrowRight":o=m>=r?n:m+1;break;case"Home":o=n;break;case"End":o=r}var i;null!==o&&(f(i=o),g[i].current.focus(),t.preventDefault())},children:[_o(Fd,{disabled:e,iconName:"format-bold",onClick:()=>t("bold"),shortcutKey:Bd.bold,buttonRef:g[r],tabIndex:v(r),title:"Bold"}),_o(Fd,{disabled:e,iconName:"format-italic",onClick:()=>t("italic"),shortcutKey:Bd.italic,buttonRef:g[o],tabIndex:v(o),title:"Italic"}),_o(Fd,{disabled:e,
523
- iconName:"format-quote",onClick:()=>t("quote"),shortcutKey:Bd.quote,buttonRef:g[i],tabIndex:v(i),title:"Quote"}),_o(Fd,{disabled:e,iconName:"link",onClick:()=>t("link"),shortcutKey:Bd.link,buttonRef:g[a],tabIndex:v(a),title:"Insert link"}),_o(Fd,{disabled:e,iconName:"image",onClick:()=>t("image"),shortcutKey:Bd.image,buttonRef:g[s],tabIndex:v(s),title:"Insert image"}),_o(Fd,{disabled:e,iconName:"format-functions",onClick:()=>t("math"),buttonRef:g[l],tabIndex:v(l),title:"Insert math (LaTeX is supported)"}),_o(Fd,{disabled:e,iconName:"format-list-numbered",onClick:()=>t("numlist"),shortcutKey:Bd.numlist,buttonRef:g[c],tabIndex:v(c),title:"Numbered list"}),_o(Fd,{disabled:e,iconName:"format-list-unordered",onClick:()=>t("list"),shortcutKey:Bd.list,buttonRef:g[u],tabIndex:v(u),title:"Bulleted list"}),_o("span",{className:"hyp-u-stretch"}),_o("div",{className:"hyp-u-layout-row--center",children:_o(Bo,{href:"https://web.hypothes.is/help/formatting-annotations-with-markdown/",target:"_blank",
524
- classes:"text-tiny IconOnlyLink",linkRef:g[h],tabIndex:v(h),title:"Formatting help","aria-label":"Formatting help",children:_o(Do,{name:"help"})})}),_o(Fd,{label:e?"Write":"Preview",onClick:n,buttonRef:g[d],tabIndex:v(d)})]})}function Hd({label:e="",onEditText:t=(()=>{}),text:n="",textStyle:r={}}){const[o,i]=ro(!1),a=so(null);io((()=>{var e;o||(null===(e=a.current)||void 0===e||e.focus())}),[o]);const s=e=>{a.current&&(!function(e,t){const n=e=>{const n=e({text:t.value,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd});t.value=n.text,t.selectionStart=n.selectionStart,t.selectionEnd=n.selectionEnd,t.focus()},r=e=>{const t=e.text.slice(0,e.selectionStart);return 0===t.length||"\n"===t.slice(-1)||"$$"===t.slice(-2)?Id(e,"$$","$$","Insert LaTeX"):Id(e,"\\(","\\)","Insert LaTeX")};switch(e){case"bold":n((e=>Id(e,"**","**","Bold")));break;case"italic":n((e=>Id(e,"*","*","Italic")));break;case"quote":n((e=>Dd(e,"> ")));break;case"link":n((e=>Od(e)));break;case"image":n((e=>Od(e,Ld)));break;case"math":n(r)
525
- ;break;case"numlist":n((e=>Dd(e,"1. ")));break;case"list":n((e=>Dd(e,"* ")));break;default:throw new Error(`Unknown toolbar command "${e}"`)}}(e,a.current),t({text:a.current.value}))};return _o("div",{className:"leading-none",children:[_o(jd,{onCommand:s,isPreviewing:o,onTogglePreview:()=>i(!o)}),o?_o(Ed,{markdown:n,textClass:{"hyp-u-border":!0,"hyp-u-bg-color--grey-1":!0,"hyp-u-padding":!0},textStyle:r}):_o("textarea",{"aria-label":e,className:"MarkdownEditor__input",dir:"auto",ref:a,onClick:e=>e.stopPropagation(),onKeyDown:e=>{if(e.ctrlKey||e.metaKey)for(let[t,n]of Object.entries(Bd))n===Fo(e.key)&&(e.stopPropagation(),e.preventDefault(),s(t))},onInput:e=>{t({text:e.target.value})},value:n,style:r})]})}const qd=e=>e;function Ud({activeItem:e=-1,id:t,itemPrefixId:n,list:r,listFormatter:o=qd,onSelectItem:i,open:a=!1}){const s=lo((()=>r.map(((t,r)=>{const a=n?{id:`${n}${r}`}:{};return _o("li",{role:"option","aria-selected":(e===r).toString(),className:Yr({"is-selected":e===r},"AutocompleteList__li"),
526
- onClick:()=>{i(t)},...a,children:o(t,r)},`AutocompleteList-${r}`)}))),[e,n,r,o,i]),l=t?{id:t}:{},c=0===r.length||!a;return _o("div",{className:Yr({"is-hidden":c},"AutocompleteList"),children:_o("ul",{className:"AutocompleteList__items",tabIndex:-1,"aria-label":"Suggestions",role:"listbox",...l,children:s})})}let $d=0;var Gd=ci((function({onAddTag:e,onRemoveTag:t,onTagInput:n,tagList:r,tags:o}){const i=so(),[a,s]=ro([]),[l,c]=ro(-1),[u,h]=ro(!1),[d]=ro((()=>(++$d,`TagEditor-${$d}`))),p=so();Ho(p,u,(()=>{h(!1)}));const m=()=>i.current.value.trim(),f=()=>m()&&m().length>0,g=()=>{i.current.value="",null==n||n("")},v=t=>{e(t)&&(h(!1),c(-1),g(),i.current.focus())},y=e=>{let t=l+e;t<-1?t=a.length-1:t>=a.length&&(t=-1),c(t)},_=l>=0?`${d}-AutocompleteList-item-${l}`:"";return _o("div",{className:"TagEditor",children:[_o("ul",{className:"TagEditor__tags","aria-label":"Suggested tags for annotation",children:r.map((e=>_o("li",{className:"TagEditor__item","aria-label":`Tag: ${e}`,children:[_o("span",{lang:"",
527
- className:"TagEditor__edit",children:e}),_o("button",{onClick:()=>{t(e)},"aria-label":`Remove Tag: ${e}`,title:`Remove Tag: ${e}`,className:"TagEditor__delete",children:_o(Do,{name:"cancel"})})]},`${e}`)))}),_o("span",{id:d,className:"TagEditor__combobox-wrapper",ref:p,role:"combobox","aria-expanded":u.toString(),"aria-owns":`${d}-AutocompleteList`,"aria-haspopup":"listbox",children:[_o("input",{onInput:()=>{null==n||n(m()),(()=>{if(f()){const e=o.filter(m());s(((e,t)=>{const n=[];return e.forEach((e=>{t.indexOf(e)<0&&n.push(e)})),n.sort()})(e,r)),h(e.length>0)}else h(!1);c(-1)})()},onKeyDown:e=>{switch(Fo(e.key)){case"ArrowUp":y(-1),e.preventDefault();break;case"ArrowDown":y(1),e.preventDefault();break;case"Escape":g(),e.preventDefault();break;case"Enter":case",":v(-1===l?m():a[l]),e.preventDefault();break;case"Tab":if(!f())break;-1!==l?v(a[l]):1===a.length?v(a[0]):v(m()),e.preventDefault()}},onFocus:()=>{f()&&h(!0)},ref:i,placeholder:"Add new tags",className:"TagEditor__input",type:"text",
528
- autoComplete:"off","aria-autocomplete":"list","aria-activedescendant":_,"aria-controls":`${d}-AutocompleteList`,dir:"auto"}),_o(Ud,{id:`${d}-AutocompleteList`,list:a,listFormatter:e=>{const t=m().toLowerCase(),n=e.toLowerCase().indexOf(t);if(-1===n)return _o("span",{children:e});const r=e.slice(0,n),o=e.slice(n,n+t.length),i=e.slice(n+t.length);return _o("span",{children:[_o("strong",{children:r}),o,_o("strong",{children:i})]})},open:u,onSelectItem:e=>{e&&v(e)},itemPrefixId:`${d}-AutocompleteList-item-`,activeItem:l})]})]})}),["tags"]);function Vd(){return _o("div",{className:"hyp-u-padding--top hyp-u-border--top text-sm leading-none",children:_o(Bo,{classes:"hyp-u-layout-row--align-center p-link--muted",href:"http://creativecommons.org/publicdomain/zero/1.0/",target:"_blank",title:"View more information about the Creative Commons Public Domain dedication",children:[_o(Do,{name:"cc-std",classes:"text-tiny"}),_o(Do,{name:"cc-zero",classes:"hyp-u-margin--left--1 text-tiny"}),_o("div",{
529
- className:"hyp-u-margin--left--2",children:"Annotations can be freely reused by anyone for any purpose."})]})})}function Wd(e){return null!==e.offsetParent}function Yd({className:e,closeMenu:t,children:n,visible:r}){const o=so();io((()=>{let e=null;return r&&(e=setTimeout((()=>{const e=o.current.querySelector('[role^="menuitem"]');e&&e.focus()}))),()=>{clearTimeout(e)}}),[r]);return _o("div",{role:"menu",className:e,ref:o,onKeyDown:e=>{const n=Array.from(o.current.querySelectorAll('[role^="menuitem"]')).filter(Wd);let r=n.findIndex((e=>e.contains(document.activeElement))),i=!1;switch(Fo(e.key)){case"ArrowLeft":case"Escape":t&&(t(e),i=!0);break;case"ArrowUp":r-=1,r<0&&(r=n.length-1),i=!0;break;case"ArrowDown":r+=1,r===n.length&&(r=0),i=!0;break;case"Home":r=0,i=!0;break;case"End":r=n.length-1,i=!0}i&&r>=0&&(e.stopPropagation(),e.preventDefault(),n[r].focus())},children:n})}function Kd({className:e}){return _o("svg",{className:Yr("Menu__arrow",e),width:15,height:8,children:_o("path",{d:"M0 8 L7 0 L15 8",
530
- stroke:"currentColor",strokeWidth:"2"})})}let Xd=!1;const Zd=()=>{};function Jd({align:e="left",arrowClass:t="",children:n,containerPositioned:r=!0,contentClass:o,defaultOpen:i=!1,label:a,open:s,onOpenChanged:l,menuIndicator:c=!0,title:u}){let[h,d]=ro(i);"boolean"==typeof s&&(h=s,d=l||Zd);const p=so(h);io((()=>{"function"==typeof l&&p.current!==h&&(p.current=h,l(h))}),[h,l]);const f=e=>{if("mousedown"===e.type)Xd=!0;else if("click"===e.type&&Xd)return Xd=!1,e.stopPropagation(),void e.preventDefault();d(!h)},g=co((()=>d(!1)),[d]),v=so();Ho(v,h,g);const y=e=>e.stopPropagation();return _o("div",{className:"Menu",ref:v,style:{position:r?"relative":"static"},onClick:y,onMouseDown:y,children:[_o("button",{"aria-expanded":h?"true":"false","aria-haspopup":!0,className:"Menu__toggle",onMouseDown:f,onClick:f,"aria-label":u,title:u,children:_o("span",{className:"Menu__toggle-wrapper",children:[a,c&&_o("span",{className:Yr("Menu__toggle-arrow",h&&"is-open"),children:_o(wo,{name:"expand-menu",className:"Menu__toggle-icon"
531
- })})]})}),h&&_o(m,{children:[_o(Kd,{className:t}),_o("div",{className:Yr("Menu__content",`Menu__content--align-${e}`,o),role:"menu",tabIndex:-1,onClick:g,onKeyDown:e=>{const t=Fo(e.key);"Enter"!==t&&" "!==t||setTimeout((()=>{g()}))},children:_o(Yd,{visible:!0,children:n})})]})]})}function Qd({children:e,visible:t}){const n=so(),[r,o]=ro(t?"auto":0),[i,a]=ro(t);io((()=>{if(t===(0!==r))return;const e=n.current;t?(e.style.display="",a(!0),o(e.scrollHeight)):(e.style.height=`${e.scrollHeight}px`,e.getBoundingClientRect(),o(0))}),[r,t]);return _o("div",{ontransitionend:co((()=>{t?o("auto"):a(!1)}),[o,t]),ref:n,style:{display:i?"":"none",height:r,overflow:"auto"===r?"visible":"hidden",transition:"height 0.15s ease-in"},children:e})}function ep({href:e,icon:t,iconAlt:n,isDisabled:r,isExpanded:o,isSelected:i,isSubmenuItem:a,isSubmenuVisible:s,label:l,onClick:c,onToggleSubmenu:u,submenu:h}){const d=t&&-1!==t.indexOf("/"),p=t||a,f=t&&a,g=so();let v=null,y=null;t&&"blank"!==t&&(y=d?_o("img",{className:"MenuItem__icon",
532
- alt:n,src:t}):_o(wo,{name:t,className:"MenuItem__icon"}));const _=a?null:y,b=a?y:null;let w;const x="boolean"==typeof s,k="boolean"==typeof i;io((()=>()=>{clearTimeout(v)}),[]);const S=e=>{switch(Fo(e.key)){case"ArrowRight":u&&(e.stopPropagation(),e.preventDefault(),u(e));break;case"Enter":case" ":c&&c(e)}};return w=e?_o("a",{ref:g,className:Yr("MenuItem",{"is-submenu":a,"is-disabled":r}),href:e,target:"_blank",tabIndex:-1,rel:"noopener noreferrer",role:"menuitem",onKeyDown:S,children:[p&&_o("div",{className:"MenuItem__icon-container",children:_}),_o("span",{className:"MenuItem__label",children:l}),f&&_o("div",{className:"MenuItem__icon-container",children:b})]}):_o("div",{ref:g,className:Yr("MenuItem",{"is-submenu":a,"is-disabled":r,"is-expanded":o,"is-selected":i}),tabIndex:-1,onKeyDown:S,onClick:c,role:k?"menuitemradio":"menuitem","aria-checked":k?i:void 0,"aria-haspopup":x,"aria-expanded":x?s:void 0,children:[p&&_o("div",{className:"MenuItem__icon-container",children:_}),_o("span",{
533
- className:"MenuItem__label",children:l}),f&&_o("div",{className:"MenuItem__icon-container",children:b}),x&&_o("div",{role:"none",icon:s?"collapse-menu":"expand-menu",className:"MenuItem__toggle",onClick:u,title:`Show actions for ${l}`,children:_o(wo,{name:s?"collapse-menu":"expand-menu",className:"MenuItem__toggle-icon"})})]}),_o(m,{children:[w,x&&_o(Qd,{visible:s,children:_o(Yd,{closeMenu:e=>{u&&u(e),v=setTimeout((()=>{g.current.focus()}))},visible:s,className:"MenuItem__submenu",children:h})})]})}var tp=ci((function({annotation:e,isDisabled:t,onSave:n,settings:r}){const o=hi(),i=o.getDraft(e),a=o.getGroup(e.group);if(!a)return null;const s=i?i.isPrivate:!Ca(e.permissions),l=s?"Only Me":a.name,c=t=>{o.createDraft(e,{...i,isPrivate:"private"===t}),Ni(e)||o.setDefault("annotationPrivacy",t)},u=si(["ctaTextColor","ctaBackgroundColor"],r),h=_o("div",{className:"annotation-publish-button__menu-label",style:u,children:_o(Do,{name:"expand-menu"})});return _o("div",{
534
- className:"hyp-u-layout-row hyp-u-horizontal-spacing--4",children:[_o("div",{className:"annotation-publish-button",children:[_o(Ao,{classes:"PublishControlButton","data-testid":"publish-control-button",style:u,onClick:n,disabled:t,size:"large",variant:"primary",children:["Post to ",l]}),_o("div",{className:"annotation-publish-button__menu-wrapper",style:u,children:_o(Jd,{arrowClass:"annotation-publish-button__menu-arrow",containerPositioned:!1,contentClass:"annotation-publish-button__menu-content",label:h,menuIndicator:!1,title:"Change annotation sharing setting",align:"left",children:[_o(ep,{icon:"open"===a.type?"public":"groups",label:a.name,isSelected:!s,onClick:()=>c("shared")}),_o(ep,{icon:"lock",label:"Only Me",isSelected:s,onClick:()=>c("private")})]})})]}),_o("div",{children:_o(Ao,{icon:"cancel",onClick:()=>{o.removeDraft(e),Li(e)&&o.removeAnnotations([e])},size:"large",children:"Cancel"})})]})}),["settings"]);var np=ci((function({annotation:e,annotationsService:t,settings:n,tags:r,toastMessenger:o}){
535
- const[i,a]=ro(null),s=hi(),l=s.getDraft(e),c=s.getGroup(e.group);if(!l)return null;const u=!l.isPrivate&&c&&"private"!==c.type,h=l.tags,d=l.text,p=!d&&!h.length,m=({tags:e})=>{s.createDraft(l.annotation,{...l,tags:e})},f=e=>{if(!e||h.indexOf(e)>=0)return!1;const t=[...h,e];return r.store(t),m({tags:t}),!0},g=async()=>{i&&f(i);try{await t.save(e)}catch(e){o.error("Saving annotation failed")}};return _o("div",{className:"hyp-u-vertical-spacing AnnotationEditor",onKeyDown:e=>{const t=Fo(e.key);p||(e.metaKey||e.ctrlKey)&&"Enter"===t&&(e.stopPropagation(),e.preventDefault(),g())},children:[_o(Hd,{textStyle:si(["annotationFontFamily"],n),label:"Annotation body",text:d,onEditText:({text:e})=>{s.createDraft(l.annotation,{...l,text:e})}}),_o(Gd,{onAddTag:f,onRemoveTag:e=>{const t=[...h],n=t.indexOf(e);return n>=0&&(t.splice(n,1),m({tags:t}),!0)},onTagInput:a,tagList:h}),_o("div",{className:"hyp-u-layout-row annotation__form-actions",children:_o(tp,{annotation:e,isDisabled:p,onSave:g})}),u&&_o(Vd,{})]})
536
- }),["annotationsService","settings","tags","toastMessenger"]);function rp(e,t,n){var r;return(n||t)&&null!==(r=e.user_info)&&void 0!==r&&r.display_name?e.user_info.display_name:oi(e.user)}function op({domain:e,link:t,title:n}){return _o("div",{className:"hyp-u-layout-row hyp-u-horizontal-spacing--2",children:[_o("div",{className:"text-color-text-light",children:['on "',t?_o(Bo,{href:t,target:"_blank",children:n}):_o("span",{children:n}),'"']}),e&&_o("span",{className:"text-color-text-light",children:["(",e,")"]})]})}function ip({annotation:e}){const t=hi().getGroup(e.group),n=null==t?void 0:t.links.html,r=Aa(e.permissions);return _o("div",{className:"hyp-u-layout-row--align-baseline",children:[t&&n&&_o(Bo,{classes:"hyp-u-layout-row--align-baseline hyp-u-horizontal-spacing--2 p-link--muted p-link--hover-muted",href:t.links.html,target:"_blank",children:["open"===t.type?_o(Do,{classes:"text-tiny",name:"public"}):_o(Do,{classes:"text-tiny",name:"groups"}),_o("span",{children:t.name})]}),r&&!n&&_o("span",{
537
- className:"hyp-u-layout-row--align-baseline text-color-text-light",children:_o("span",{"data-testid":"private-info",children:"Only me"})})]})}let ap={};function sp(e,t){return t-e}function lp(e,t,n=window.Intl){const r=JSON.stringify(t);let o=ap[r];return o||(o=ap[r]=new n.DateTimeFormat(void 0,t)),o.format(e)}const cp=[{test:(e,t)=>sp(e,t)<3e4,formatter:()=>"Just now",nextUpdate:1e3},{test:(e,t)=>sp(e,t)<6e4,formatter:function(e,t){return`${Math.floor(sp(e,t)/1e3)} secs ago`},nextUpdate:1e3},{test:(e,t)=>sp(e,t)<36e5,formatter:function(e,t){const n=Math.floor(sp(e,t)/6e4);return`${n} min${n>1?"s":""} ago`},nextUpdate:6e4},{test:(e,t)=>sp(e,t)<864e5,formatter:function(e,t){const n=Math.floor(sp(e,t)/36e5);return`${n} hr${n>1?"s":""} ago`},nextUpdate:36e5},{test:(e,t)=>e.getFullYear()===t.getFullYear(),formatter:function(e,t,n){return lp(e,{month:"short",day:"numeric"},n)},nextUpdate:null}],up={test:()=>!0,formatter:function(e,t,n){return lp(e,{day:"numeric",month:"short",year:"numeric"},n)},nextUpdate:null}
538
- ;function hp(e,t){for(let n of cp)if(n.test(e,t))return n;return up}function dp(e){return!isNaN(e.valueOf())}function pp(e,t){let n;const r=new Date(e),o=()=>{const e=function(e,t){if(!e||!dp(e)||!dp(t))return null;let n=hp(e,t).nextUpdate;return null===n?null:(n=Math.max(n,5e3),n=Math.min(n,20736e5),n)}(r,new Date);if(null===e)return;n=setTimeout((()=>{t(),o()}),e+500)};return o(),()=>clearTimeout(n)}function mp(e,t,n){return e?hp(e,t).formatter(e,t,n):""}function fp(e,t){return lp(e,{year:"numeric",month:"short",day:"2-digit",weekday:"long",hour:"2-digit",minute:"2-digit"},t)}function gp({annotationCreated:e,annotationUpdated:t,annotationUrl:n,withEditedTimestamp:r}){const[o,i]=ro((()=>new Date)),a=lo((()=>new Date(e)),[e]),s=lo((()=>r&&new Date(t)),[t,r]),l=lo((()=>({absolute:fp(a),relative:mp(a,o)})),[a,o]),c=lo((()=>s?{absolute:fp(s),relative:mp(s,o)}:{}),[s,o]);io((()=>pp(s?t:e,(()=>i(new Date)))),[e,t,a,s,o]);const u=c&&c.relative!==l.relative?`edited ${c.relative}`:"edited";return _o("div",{
539
- children:[r&&_o("span",{className:"text-color-text-light text-sm italic","data-testid":"timestamp-edited",title:c.absolute,children:["(",u,")"," "]}),n?_o(Bo,{classes:"p-link--muted p-link--hover-muted",target:"_blank",title:l.absolute,href:n,children:l.relative}):_o("span",{className:"color-text-color-light","data-testid":"timestamp-created",title:l.absolute,children:l.relative})]})}function vp({authorLink:e,displayName:t}){const n=_o("h3",{className:"text-color-text font-bold",children:t});return e?_o(Bo,{href:e,target:"_blank",children:n}):_o("div",{children:n})}var yp=ci((function({annotation:e,isEditing:t,replyCount:n,threadIsCollapsed:r,settings:o}){var i;const a=hi(),s=a.defaultAuthority(),l=a.isFeatureEnabled("client_display_names"),c=ii(e.user,s),u=rp(e,c,l),h=(()=>{var t;return c?null!==(t=o.usernameUrl&&`${o.usernameUrl}${oi(e.user)}`)&&void 0!==t?t:void 0:a.getLink("user",{user:e.user})
540
- })(),d=Ni(e)&&r,p=Aa(e.permissions),m=(null===(i=e.links)||void 0===i?void 0:i.html)||"",f=!t&&e.created,g=lo((()=>function(e){if(!e.updated||!e.created||e.updated===e.created)return!1;const t=new Date(e.created).getTime(),n=new Date(e.updated).getTime();return!isNaN(t)&&!isNaN(n)&&n-t>2e3}(e)&&!d),[e,d]),v=`${n} ${n>1?"replies":"reply"}`,y=n>0&&d,_=!Ni(e),b=function(e){return{domain:Ei(e),titleText:Ti(e),titleLink:Ai(e)}}(e),w=m&&b.titleLink?b.titleLink:"",x="sidebar"!==a.route()&&b.titleText;return _o("header",{children:[_o("div",{className:"hyp-u-layout-row--align-baseline hyp-u-horizontal-spacing--2 flex-wrap-reverse",children:[p&&!t&&_o(Do,{classes:"text-tiny",name:"lock",title:"This annotation is visible only to you"}),_o(vp,{authorLink:h,displayName:u}),y&&_o(Eo,{onClick:()=>a.setExpanded(e.id,!0),title:"Expand replies",children:v}),f&&_o("div",{className:"hyp-u-layout-row--justify-right hyp-u-stretch",children:_o(gp,{annotationCreated:e.created,annotationUpdated:e.updated,annotationUrl:m,
541
- withEditedTimestamp:g})})]}),_&&_o("div",{className:"hyp-u-layout-row--align-baseline hyp-u-horizontal-spacing--2 flex-wrap-reverse",children:[_o(ip,{annotation:e}),!t&&Ri(e)&&_o(Do,{name:"highlight",title:"This is a highlight. Click 'edit' to add a note or tag.",classes:"text-tiny text-color-text-light"}),x&&_o(op,{domain:b.domain,link:w,title:b.titleText})]})]})}),["settings"]);var _p=ci((function({annotation:e,isFocused:t,settings:n={}}){return _o("div",{className:Yr({"is-orphan":Di(e)}),children:_o(Pa,{collapsedHeight:35,inlineControls:!0,overflowThreshold:20,children:_o("blockquote",{className:Yr("p-quoted-text",{"is-focused":t,"p-redacted-content":Di(e)}),dir:"auto",lang:"",style:si(["selectionFontFamily"],n),children:Hi(e)})})})}),["settings"]);function bp({onToggleReplies:e,replyCount:t,threadIsCollapsed:n}){const r=`${n?"Show replies":"Hide replies"} (${t})`;return _o(Eo,{onClick:e,title:r,children:r})}
542
- var wp=ci((function({annotation:e,hasAppliedFilter:t,isReply:n,onToggleReplies:r,replyCount:o,threadIsCollapsed:i,annotationsService:a}){const s=n&&i,l=hi(),c=e&&!!Hi(e),u=e&&l.isAnnotationFocused(e.$tag),h=e&&l.isSavingAnnotation(e),d=e&&!!l.getDraft(e)&&!h,p=l.profile().userid,f=!h&&!d,g=!n&&!t&&o>0;return _o("article",{className:Yr("hyp-u-vertical-spacing",{"is-collapsed":i,"is-focused":u}),children:[e&&_o(m,{children:[_o(yp,{annotation:e,isEditing:d,replyCount:o,threadIsCollapsed:i}),c&&_o(_p,{annotation:e,isFocused:u}),!s&&!d&&_o(Nd,{annotation:e}),d&&_o(np,{annotation:e})]}),!e&&!s&&_o("div",{children:_o("em",{children:"Message not available."})}),!s&&_o("footer",{children:_o("div",{className:"hyp-u-layout-row",children:[g&&_o(bp,{onToggleReplies:r,replyCount:o,threadIsCollapsed:i}),h&&_o("div",{className:"hyp-u-layout-row--justify-right hyp-u-stretch","data-testid":"saving-message",children:"Saving..."}),e&&f&&Mi(e)&&_o(Mo,{classes:"hyp-u-stretch",children:_o(za,{annotation:e,onReply:()=>{
543
- e&&Mi(e)&&a.reply(e,p)}})})]})})]})}),["annotationsService"]);var xp=ci((function({annotation:e,api:t,toastMessenger:n}){const r=hi(),o=function(e){return e.moderation?e.moderation.flagCount:null}(e);return null!==o&&(o>0||e.hidden)?_o("div",{className:Yr("flex gap-x-3 bg-grey-1 text-color-text font-semibold","mb-2 ",{"-mt-3 -ml-3 -mr-3":!Ni(e),"-mr-3":Ni(e)}),children:[_o("div",{className:Yr("p-3 text-white",{"bg-red-error":!e.hidden,"bg-grey-6":e.hidden}),children:_o(Do,{name:e.hidden?"hide":"flag"})}),_o("div",{className:"self-center grow",children:[!e.hidden&&_o("span",{children:["Flagged for review by ",o," ",1===o?"user":"users"]}),e.hidden&&_o("span",{children:"Hidden from users"})]}),_o("div",{className:"self-center pr-2",children:_o(Ao,{classes:"py-1 bg-slate-1",onClick:e.hidden?()=>{const o=e.id;t.annotation.unhide({id:o}).then((()=>{r.unhideAnnotation(o)})).catch((()=>{n.error("Failed to unhide annotation")}))}:()=>{const o=e.id;t.annotation.hide({id:o}).then((()=>{r.hideAnnotation(o)
544
- })).catch((()=>{n.error("Failed to hide annotation")}))},title:e.hidden?"Make this annotation visible to everyone":"Hide this annotationn from non-moderators",variant:"dark",children:e.hidden?"Unhide":"Hide"})})]}):null}),["api","toastMessenger"]);function kp({annotation:e,...t}){const n=hi(),r=e&&n.isSavingAnnotation(e),o=e&&!!n.getDraft(e)&&!r;return e?_o("div",{className:"Thread__top-annotation-header",children:_o(yp,{annotation:e,isEditing:o,...t})}):null}var Sp=ci((function e({thread:t,threadsService:n}){const r=!t.collapsed,o=Ki(t)>0,i=!!t.parent,a=t.collapsed?"collapsed":"expand-menu",s=t.collapsed?"Expand replies":"Collapse replies",l=t.children.filter((e=>Xi(e)>0)),c=hi(),u=c.hasAppliedFilter(),h=co((()=>c.setExpanded(t.id,!!t.collapsed)),[c,t.id,t.collapsed]),d=lo((()=>t.visible&&_o(m,{children:[t.annotation&&_o(xp,{annotation:t.annotation}),_o(wp,{annotation:t.annotation,hasAppliedFilter:u,isReply:!!t.parent,onToggleReplies:h,replyCount:t.replyCount,threadIsCollapsed:t.collapsed})]
545
- })),[u,h,t.annotation,t.parent,t.replyCount,t.collapsed,t.visible]);return _o("section",{className:Yr("Thread",{"Thread--reply":t.depth>0,"is-collapsed":t.collapsed}),children:[i&&_o("div",{className:"Thread__collapse",children:_o("div",{className:"Thread__collapse-button-container",children:_o(Co,{classes:"NonResponsiveIconButton",expanded:!t.collapsed,icon:a,title:s,onClick:h,size:"medium",variant:"light"})})}),_o("div",{className:"Thread__content",children:[d,o&&_o(m,{children:[!t.parent&&_o(kp,{annotation:t.annotation,replyCount:t.replyCount,threadIsCollapsed:t.collapsed}),_o("div",{className:"Thread__hidden-toggle-button-container",children:_o(Ao,{onClick:()=>n.forceVisible(t),children:["Show ",Ki(t)," more in conversation"]})})]}),r&&_o("ul",{className:"Thread__children",children:l.map((t=>_o("li",{children:_o(e,{thread:t,threadsService:n})},t.id)))})]})]})}),["threadsService"]);var Cp=ci((function({frameSync:e,thread:t}){
546
- const n=hi(),r=t.annotation&&t.annotation.$tag,o=r&&n.isAnnotationFocused(r),i=lo((()=>va((t=>{const n=t?[t]:[];e.focusAnnotations(n)}),10)),[e]),a=co((t=>{e.scrollToAnnotation(t)}),[e]),s=lo((()=>_o(Sp,{thread:t})),[t]);return _o("div",{onClick:e=>{var t;(t=e.target).closest("button")||t.closest("a")||a(r)},onMouseEnter:()=>i(r),onMouseLeave:()=>i(null),className:Yr("ThreadCard p-3",{"is-focused":o}),children:s},t.id)}),["frameSync"]);function Ap(){const e=document.querySelector(".js-thread-list-scroll-root");if(!e)throw new Error("Scroll container is missing");return e}function Ep(e){return Math.max(e-e%50,0)}function Tp({threads:e}){const[t,n]=ro(0),[r,o]=ro(0);ao((()=>{const e=new ya,t=Ap();n(t.clientHeight),o(Ep(t.scrollTop));const r=va((()=>{n(t.clientHeight),o(Ep(t.scrollTop))}),10,{maxWait:100});return e.add(t,"scroll",r),e.add(window,"resize",r),()=>{e.removeAll(),r.cancel()}}),[])
547
- ;const[i,a]=ro({}),[s,l]=ro(null),c=e,{offscreenLowerHeight:u,offscreenUpperHeight:h,visibleThreads:d}=lo((()=>function(e,t,n,r,o=_a){const{defaultHeight:i,marginAbove:a,marginBelow:s}=o,l=[];let c=0,u=0,h=0;return e.forEach((e=>{const o=t[e.id]||i;c+o<n-a?u+=o:c<n+r+s?l.push(e):h+=o,c+=o})),{visibleThreads:l,offscreenUpperHeight:u,offscreenLowerHeight:h}}(c,i,r,t)),[c,i,r,t]),p=hi(),m=(()=>{const e=p.unsavedAnnotations();return e.length?e[e.length-1].$tag:null})();return io((()=>{m&&(p.setForcedVisible(m,!0),l(m))}),[p,m]),io((()=>{if(!s)return;const e=c.findIndex((e=>e.id===s));if(-1===e)return;l(null);const t=c.slice(0,e).reduce(((e,t)=>e+(e=>i[e.id]||_a.defaultHeight)(t)),0);Ap().scrollTop=t}),[s,c,i]),io((()=>{a((e=>{const t={};for(let{id:n}of d){const r=document.getElementById(n);if(!r)return console.warn("ThreadList could not measure thread. Element not found."),e;const o=ba(r);o!==e[n]&&(t[n]=o)}return 0===Object.keys(t).length?e:{...e,...t}}))}),[d]),_o("div",{children:[_o("div",{style:{height:h}
548
- }),d.map((e=>_o("div",{className:"ThreadList__card",id:e.id,children:_o(Cp,{thread:e})},e.id))),_o("div",{style:{height:u}})]})}function Np({errorType:e,onLoginRequest:t,showClearSelection:n=!1}){const r=hi(),o=r.isLoggedIn();return _o("div",{className:"mb-4",children:_o(Wo,{icon:"restricted",title:"annotation"===e?"Annotation unavailable":"Group unavailable",children:[_o("p",{children:o?"group"===e?"The current URL links to a group, but that group cannot be found,\n or you do not have permission to view the annotations in that group.":"The current URL links to an annotation, but that annotation\n cannot be found, or you do not have permission to view it.":`The ${e} associated with the current URL is unavailable.\n You may need to log in to see it.`}),_o("div",{className:"hyp-u-layout-row--justify-right hyp-u-horizontal-spacing",children:[n&&_o(Ao,{variant:o?"primary":void 0,onClick:()=>r.clearSelection(),children:"Show all annotations"}),!o&&_o(Ao,{variant:"primary",onClick:t,
549
- children:"Log in"})]})]})})}var Mp=ci((function({loadAnnotationsService:e,onLogin:t}){const n=hi(),r=n.routeParams().id,o=na(),i=n.profile().userid,[a,s]=ro(!1);return io((()=>{s(!1),n.clearAnnotations(),e.loadThread(r).then((e=>{const t=e.filter((e=>0===(e.references||[]).length))[0];t&&(e.forEach((e=>n.setExpanded(e.id,!0))),t.id!==r&&n.highlightAnnotations([r]))})).catch((()=>{s(!0)}))}),[r,i,e,n]),_o(m,{children:[a&&_o(Np,{errorType:"annotation",onLoginRequest:t}),_o(Tp,{threads:o.children})]})}),["loadAnnotationsService"]);function Lp({actionButton:e,additionalCount:t=0,entitySingular:n="annotation",entityPlural:r="annotations",filterQuery:o,focusDisplayName:i,resultCount:a}){return _o("div",{className:"FilterStatus",children:hi().isLoading()?_o("div",{className:"hyp-u-layout-row--center",children:_o(Ko,{})}):_o("div",{className:"hyp-u-layout-row--align-center",children:[_o("div",{className:"FilterStatus__text",children:[a>0&&_o("span",{children:"Showing "}),_o("span",{className:"filter-facet",
550
- children:[a>0?a:"No"," ",1===a?n:r]}),o&&_o("span",{children:[" ","for"," ",_o("span",{className:"filter-facet--pre",children:`'${o}'`})]}),i&&_o("span",{children:[" ","by ",_o("span",{className:"filter-facet",children:i})]}),t>0&&_o("span",{className:"filter-facet--muted",children:[" ","(and ",t," more)"]})]}),_o("div",{children:e})]})})}function zp({filterState:e,rootThread:t}){const n=hi(),r=n.directLinkedAnnotationId(),o=n.annotationCount(),i=(t.children||[]).filter((e=>e.annotation&&e.visible)).length-e.selectedCount,a=!e.focusConfigured&&!r?`Show all (${o})`:"Show all",s=_o(Ao,{title:a,variant:"primary",onClick:()=>n.clearSelection(),icon:"cancel",children:a});return _o(Lp,{resultCount:e.selectedCount,additionalCount:i,actionButton:s})}function Op({filterState:e,rootThread:t}){const n=hi(),r=Xi(t)-e.forcedVisibleCount,o=_o(Ao,{icon:"cancel",variant:"primary",title:"Clear search",onClick:()=>n.clearSelection(),children:"Clear search"});return _o(Lp,{actionButton:o,additionalCount:e.forcedVisibleCount,
551
- entitySingular:"result",entityPlural:"results",filterQuery:e.filterQuery,focusDisplayName:e.focusDisplayName,resultCount:r})}function Ip({filterState:e,rootThread:t}){const n=hi(),r=Xi(t)-e.forcedVisibleCount,o={};e.forcedVisibleCount>0?(o.onClick=()=>n.clearSelection(),o.title="Reset filters"):(o.onClick=()=>n.toggleFocusMode(),o.title=e.focusActive?"Show all":`Show only ${e.focusDisplayName}`);const i=e.focusActive?e.focusDisplayName:"",a=_o(Ao,{variant:"primary",...o,children:o.title});return _o(Lp,{resultCount:r,actionButton:a,additionalCount:e.forcedVisibleCount,filterQuery:e.filterQuery,focusDisplayName:i})}function Pp(){const e=na(),t=hi(),n=t.focusState(),r=t.forcedVisibleThreads().length,o=t.filterQuery(),i=t.selectedAnnotations().length,a=lo((()=>({filterQuery:o,focusActive:n.active,focusConfigured:n.configured,focusDisplayName:n.displayName,forcedVisibleCount:r,selectedCount:i})),[n,r,o,i]);return a.selectedCount>0?_o(zp,{filterState:a,rootThread:e}):a.filterQuery?_o(Op,{filterState:a,rootThread:e
552
- }):a.focusConfigured?_o(Ip,{filterState:a,rootThread:e}):null}function Rp({onLogin:e}){const t=hi();return _o("div",{className:"LoggedOutMessage",children:[_o("span",{children:["This is a public annotation created with Hypothesis. ",_o("br",{}),"To reply or make your own annotations on this document,"," ",_o("a",{className:"LoggedOutMessage__link",href:t.getLink("signup"),target:"_blank",rel:"noopener noreferrer",children:"create a free account"})," ","or"," ",_o(Eo,{classes:"InlineLinkButton InlineLinkButton--underlined",onClick:e,variant:"dark",children:"log in"}),"."]}),_o("div",{className:"LoggedOutMessage__logo",children:_o("a",{href:"https://hypothes.is","aria-label":"Hypothesis homepage",title:"Hypothesis homepage",children:_o(Do,{name:"logo",classes:"w-16 h-16 hyp-u-color--grey-7"})})})]})}function Dp(e,t,n){e.self===e?e.scrollTo(t,n):(e.scrollLeft=t,e.scrollTop=n)}function Bp(e){var t=e._scrollSettings;if(t){var n=t.maxSynchronousAlignments,r=function(e,t){
553
- var n,r,o,i,a,s,l,c=e.align,u=e.target.getBoundingClientRect(),h=c&&null!=c.left?c.left:.5,d=c&&null!=c.top?c.top:.5,p=c&&null!=c.leftOffset?c.leftOffset:0,m=c&&null!=c.topOffset?c.topOffset:0,f=h,g=d;if(e.isWindow(t))s=Math.min(u.width,t.innerWidth),l=Math.min(u.height,t.innerHeight),r=u.left+t.pageXOffset-t.innerWidth*f+s*f,o=u.top+t.pageYOffset-t.innerHeight*g+l*g,r-=p,o-=m,r=e.align.lockX?t.pageXOffset:r,o=e.align.lockY?t.pageYOffset:o,i=r-t.pageXOffset,a=o-t.pageYOffset;else{s=u.width,l=u.height,n=t.getBoundingClientRect();var v=u.left-(n.left-t.scrollLeft),y=u.top-(n.top-t.scrollTop);r=v+s*f-t.clientWidth*f,o=y+l*g-t.clientHeight*g,r-=p,o-=m,r=Math.max(Math.min(r,t.scrollWidth-t.clientWidth),0),o=Math.max(Math.min(o,t.scrollHeight-t.clientHeight),0),r=e.align.lockX?t.scrollLeft:r,o=e.align.lockY?t.scrollTop:o,i=r-t.scrollLeft,a=o-t.scrollTop}return{x:r,y:o,differenceX:i,differenceY:a}}(t,e),o=Date.now()-t.startTime,i=Math.min(1/t.time*o,1);if(t.endIterations>=n)return Dp(e,r.x,r.y),
554
- e._scrollSettings=null,t.end("complete");var a=1-t.ease(i);if(Dp(e,r.x-r.differenceX*a,r.y-r.differenceY*a),o>=t.time)return t.endIterations++,t.scrollAncestor&&Bp(t.scrollAncestor),void Bp(e);!function(e){if("requestAnimationFrame"in window)return window.requestAnimationFrame(e);setTimeout(e,16)}(Bp.bind(null,e))}}function Fp(e){return e.self===e}function jp(e){return"pageXOffset"in e||(e.scrollHeight!==e.clientHeight||e.scrollWidth!==e.clientWidth)&&"hidden"!==getComputedStyle(e).overflow}function Hp(){return!0}function qp(e){if(e.assignedSlot)return qp(e.assignedSlot);if(e.parentElement)return"BODY"===e.parentElement.tagName?e.parentElement.ownerDocument.defaultView||e.parentElement.ownerDocument.ownerWindow:e.parentElement;if(e.getRootNode){var t=e.getRootNode();if(11===t.nodeType)return t.host}}var Up=function(e,t,n){if(e){"function"==typeof t&&(n=t,t=null),t||(t={}),t.time=isNaN(t.time)?1e3:t.time,t.ease=t.ease||function(e){return 1-Math.pow(1-e,e/2)},t.align=t.align||{}
555
- ;var r=qp(e),o=1,i=t.validTarget||Hp,a=t.isScrollable;t.debug&&(console.log("About to scroll to",e),r||console.error("Target did not have a parent, is it mounted in the DOM?"));for(var s=[];r;)if(t.debug&&console.log("Scrolling parent node",r),i(r,o)&&(a?a(r,jp):jp(r))&&(o++,s.push(r)),!(r=qp(r))){l("complete");break}return s.reduce(((n,r,o)=>function(e,t,n,r,o){var i,a=!t._scrollSettings,s=t._scrollSettings,l=Date.now(),c={passive:!0};function u(e){t._scrollSettings=null,t.parentElement&&t.parentElement._scrollSettings&&t.parentElement._scrollSettings.end(e),n.debug&&console.log("Scrolling ended with type",e,"for",t),o(e),i&&(t.removeEventListener("touchstart",i,c),t.removeEventListener("wheel",i,c))}s&&s.end("canceled");var h=n.maxSynchronousAlignments;return null==h&&(h=3),t._scrollSettings={startTime:l,endIterations:0,target:e,time:n.time,ease:n.ease,align:n.align,isWindow:n.isWindow||Fp,maxSynchronousAlignments:h,end:u,scrollAncestor:r},"cancellable"in n&&!n.cancellable||(i=u.bind(null,"canceled"),
556
- t.addEventListener("touchstart",i,c),t.addEventListener("wheel",i,c)),a&&Bp(t),i}(e,r,t,s[o+1],l)),null)}function l(e){--o||n&&n(e)}};function $p({children:e,icon:t="",panelName:n,title:r,onActiveChanged:o}){const i=hi(),a=i.isSidebarPanelOpen(n),s=so(null),l=so(a);io((()=>{l.current!==a&&(l.current=a,a&&s.current&&Up(s.current),"function"==typeof o&&o(a))}),[a,o]);const c=co((()=>{i.toggleSidebarPanel(n,!1)}),[i,n]);return _o(Qd,{visible:a,children:_o("div",{ref:s,className:"mb-4",children:_o(Wo,{title:r,icon:t,onClose:c,children:e})})})}function Gp({onLogin:e,onSignUp:t}){return hi().isLoggedIn()?null:_o($p,{icon:"restricted",title:"Login needed",panelName:"loginPrompt",children:[_o("p",{children:"Please log in to create annotations or highlights."}),_o(Mo,{children:[_o(Ao,{title:"Sign up",onClick:t,children:"Sign up"}),_o(Ao,{title:"Log in",variant:"primary",onClick:e,children:"Log in"})]})]})}function Vp({children:e,count:t,isWaitingToAnchor:n,isSelected:r,label:o,onSelect:i}){const a=()=>{r||i()
557
- },s=t>0?`${o} (${t} available)`:o;return _o(Ao,{classes:Yr("text-color-text","SelectionTab",{"is-selected":r}),onClick:a,onMouseDown:a,pressed:!!r,role:"tab",tabIndex:0,title:s,children:_o(m,{children:[e,t>0&&!n&&_o("span",{className:"text-tiny",style:"position:relative;bottom:3px;left:2px",children:t})]})})}var Wp=ci((function({annotationsService:e,isLoading:t,settings:n}){const r=hi(),o=r.selectedTab(),i=r.noteCount(),a=r.annotationCount(),s=r.orphanCount(),l=r.isWaitingToAnchorAnnotations(),c=e=>{r.clearSelection(),r.selectTab(e)},u="annotation"===o&&0===a&&!l,h="note"===o&&0===i;return _o("div",{className:"hyp-u-vertical-spacing--4 SelectionTabs__container",children:[_o("div",{className:"hyp-u-layout-row hyp-u-horizontal-spacing--6 SelectionTabs",role:"tablist",children:[_o(Vp,{count:a,isWaitingToAnchor:l,isSelected:"annotation"===o,label:"Annotations",onSelect:()=>c("annotation"),children:"Annotations"}),_o(Vp,{count:i,isWaitingToAnchor:l,isSelected:"note"===o,label:"Page notes",onSelect:()=>c("note"),
558
- children:"Page Notes"}),s>0&&_o(Vp,{count:s,isWaitingToAnchor:l,isSelected:"orphan"===o,label:"Orphans",onSelect:()=>c("orphan"),children:"Orphans"})]}),"note"===o&&n.enableExperimentalNewNoteButton&&_o("div",{className:"hyp-u-layout-row--justify-right",children:_o(Ao,{"data-testid":"new-note-button",icon:"add",onClick:()=>e.createPageNote(),variant:"primary",style:si(["ctaBackgroundColor"],n),children:"New note"})}),!t&&h&&_o(No,{classes:"text-center",children:_o("span",{"data-testid":"notes-unavailable-message",children:"There are no page notes in this group."})}),!t&&u&&_o(No,{classes:"text-center",children:_o("span",{"data-testid":"annotations-unavailable-message",children:["There are no annotations in this group.",_o("br",{}),"Create one by selecting some text and clicking the"," ",_o(Do,{classes:"m-0.5 inline -mt-0.5",name:"annotate",title:"Annotate"})," ","button."]})})]})}),["annotationsService","settings"]);var Yp=ci((function({frameSync:e,onLogin:t,onSignUp:n,loadAnnotationsService:r,streamer:o}){
559
- const i=na(),a=hi(),s=a.focusedGroupId(),l=a.hasAppliedFilter()||a.hasSelectedAnnotations(),c=a.isLoading(),u=a.isLoggedIn(),h=a.directLinkedAnnotationId(),d=h?a.findAnnotationByID(h):void 0,p=d?Wi(d):"annotation",m=a.searchUris(),f=a.hasSidebarOpened(),g=a.profile().userid,v=d&&!1===d.$orphan?d.$tag:null,y=!(c||!h)&&!d,_=a.directLinkedGroupFetchFailed(),b=y||_,w=!b,x=!b&&!l,k=h&&!u&&!y&&!c,S=so(s);io((()=>{if(!S.current||S.current!==s){if(S.current){let e=a.focusState().active;a.clearSelection(),e&&a.toggleFocusMode(!0)}S.current=s}s&&m.length&&r.load({groupId:s,uris:m})}),[a,r,s,g,m]),io((()=>{v?(e.focusAnnotations([v]),e.scrollToAnnotation(v),a.selectTab(p)):d&&a.selectTab(p)}),[p,e,d,v,a]);const C=a.hasFetchedProfile();return io((()=>{C&&(f||u)&&o.connect({applyUpdatesImmediately:!1})}),[C,u,f,o]),_o("div",{children:[_o("h2",{className:"sr-only",children:"Annotations"}),w&&_o(Pp,{}),_o(Gp,{onLogin:t,onSignUp:n}),y&&_o(Np,{errorType:"annotation",onLoginRequest:t,showClearSelection:!0}),_&&_o(Np,{
560
- errorType:"group",onLoginRequest:t}),x&&_o(Wp,{isLoading:c}),_o(Tp,{threads:i.children}),k&&_o(Rp,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var Kp=ci((function({api:e,toastMessenger:t}){const n=hi(),r=n.routeParams().q,o=co((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...Si(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return io((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),_o(Tp,{threads:na().children})}),["api","toastMessenger"]);class Xp{constructor(e,t,n=window){var r,o,i;const a="N/A";let s=a;e.userid&&(s=e.userid,e.displayName&&(s=`${e.displayName} (${s})`)),this.version="1.1006.0",this.userAgent=n.navigator.userAgent,this.urls=t.map((e=>e.uri)).join(", ")||a,
561
- this.fingerprint=null!==(r=null===(o=t[0])||void 0===o||null===(i=o.metadata)||void 0===i?void 0:i.documentFingerprint)&&void 0!==r?r:a,this.account=s,this.timestamp=(new Date).toString()}asFormattedString(){return`Version: ${this.version}\nUser Agent: ${this.userAgent}\nURL: ${this.urls}\nFingerprint: ${this.fingerprint}\nAccount: ${this.account}\nDate: ${this.timestamp}\n`}asEncodedURLString(){return encodeURIComponent(this.asFormattedString())}}function Zp(e){const t=R(e);return!(null==t||!t.authority)&&t.authority!==e.authDomain}function Jp({commandName:e,iconName:t}){return _o("span",{className:"whitespace-nowrap",children:[_o(Do,{name:t,classes:Yr("mx-1 -mt-1","text-color-text-light inline")}),_o("em",{children:e})]})}var Qp=ci((function({settings:e}){const t=!Zp(e);return _o("ol",{className:"list-decimal pl-10 space-y-2",children:[_o("li",{children:["To create an annotation, select text and then select the"," ",_o(Jp,{iconName:"annotate",commandName:"Annotate"})," ","button."]}),_o("li",{
562
- children:["To create a highlight (",_o(Bo,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/why-are-highlights-private-by-default/",target:"_blank",children:"visible only to you"}),"), select text and then select the"," ",_o(Jp,{iconName:"highlight",commandName:"Highlight"})," ","button."]}),t&&_o("li",{children:["To annotate in a private group, select the group from the groups dropdown. Don't see your group? Ask the group creator to send a"," ",_o(Bo,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/how-to-join-a-private-group/",target:"_blank",children:"join link"}),")."]}),_o("li",{children:["To reply to an annotation, select the"," ",_o(Jp,{iconName:"reply",commandName:"Reply"})," button."]})]})}),["settings"]);var em=ci((function({toastMessenger:e,versionData:t}){return _o("div",{className:"hyp-u-vertical-spacing",children:[_o("dl",{className:"VersionInfo",children:[_o("dt",{className:"VersionInfo__key",children:"Version"}),_o("dd",{
563
- className:"VersionInfo__value",children:t.version}),_o("dt",{className:"VersionInfo__key",children:"User Agent"}),_o("dd",{className:"VersionInfo__value",children:t.userAgent}),_o("dt",{className:"VersionInfo__key",children:"URL"}),_o("dd",{className:"VersionInfo__value",children:t.urls}),_o("dt",{className:"VersionInfo__key",children:"Fingerprint"}),_o("dd",{className:"VersionInfo__value",children:t.fingerprint}),_o("dt",{className:"VersionInfo__key",children:"Account"}),_o("dd",{className:"VersionInfo__value",children:t.account}),_o("dt",{className:"VersionInfo__key",children:"Date"}),_o("dd",{className:"VersionInfo__value",children:t.timestamp})]}),_o("div",{className:"hyp-u-layout-row--justify-center",children:_o(Ao,{onClick:()=>{try{Ea(t.asFormattedString()),e.success("Copied version info to clipboard")}catch(t){e.error("Unable to copy version info")}},icon:"copy",children:"Copy version details"})})]})}),["toastMessenger"]);function tm({children:e,onClick:t}){return _o(Eo,{
564
- classes:"leading-none text-brand",onClick:t,children:[e,_o(Do,{classes:"ml-1",name:"arrow-right"})]})}function nm({linkText:e,url:t}){return _o("div",{className:"flex-1 border-r last-of-type:border-r-0",children:_o(Bo,{href:t,classes:"flex items-center justify-center space-x-2 text-color-text-light text-lg font-medium",target:"_blank",children:[_o("span",{children:e})," ",_o(Do,{name:"external",classes:"w-3 h-3"})]})})}var rm=ci((function({auth:e,session:t}){const n=hi(),r=n.frames(),o=n.mainFrame(),i=!!n.profile().preferences.show_sidebar_tutorial,[a,s]=ro("tutorial"),l=lo((()=>{const t=e||{status:"logged-out"},n=[...r].sort(((e,t)=>e===o?-1:t===o?1:0));return new Xp(t,n)}),[e,r,o]),c=`https://web.hypothes.is/get-help/?sys_info=${l.asEncodedURLString()}`,u=(e,t)=>{e.preventDefault(),s(t)};return _o($p,{title:"Help",panelName:"help",onActiveChanged:co((e=>{!e&&i&&t.dismissSidebarTutorial()}),[t,i]),children:_o("div",{className:"space-y-4",children:[_o("div",{className:"flex items-center",children:[_o("h3",{
565
- className:"grow text-lg font-medium","data-testid":"subpanel-title",children:{tutorial:"Getting started",versionInfo:"About this version"}[a]}),"versionInfo"===a&&_o(tm,{onClick:e=>u(e,"tutorial"),children:"Getting started"}),"tutorial"===a&&_o(tm,{onClick:e=>u(e,"versionInfo"),children:"About this version"})]}),_o("div",{className:"border-y py-4",children:["tutorial"===a&&_o(Qp,{}),"versionInfo"===a&&_o(em,{versionData:l})]}),_o("div",{className:"flex items-center",children:[_o(nm,{linkText:"Help topics",url:"https://web.hypothes.is/help/"}),_o(nm,{linkText:"New support ticket",url:c})]})]})})}),["session"]),om={exports:{}};function im(){}im.prototype={on:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){var r=this;function o(){r.off(e,o),t.apply(n,arguments)}return o._=t,this.on(e,o,n)},emit:function(e){for(var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),r=0,o=n.length;r<o;r++)n[r].fn.apply(n[r].ctx,t);return this},
566
- off:function(e,t){var n=this.e||(this.e={}),r=n[e],o=[];if(r&&t)for(var i=0,a=r.length;i<a;i++)r[i].fn!==t&&r[i].fn._!==t&&o.push(r[i]);return o.length?n[e]=o:delete n[e],this}},om.exports=im;var am=om.exports.TinyEmitter=im;class sm extends Error{constructor(e){super(`Results size exceeds ${e}`)}}function lm(e){return 0===e?50:200}class cm extends am{constructor(e,{getPageSize:t=lm,separateReplies:n=!0,incremental:r=!0,maxResults:o=null,sortBy:i="created",sortOrder:a="asc"}={}){super(),this._searchFn=e,this._getPageSize=t,this._separateReplies=n,this._incremental=r,this._maxResults=o,this._sortBy=i,this._sortOrder=a,this._canceled=!1,this._results=[],this._resultCount=null}async _getPage(e,t,n=0){const r=this._getPageSize(n),o={limit:r,sort:this._sortBy,order:this._sortOrder,_separate_replies:this._separateReplies,...e};t&&(o.search_after=t);try{const t=await this._searchFn(o);if(this._canceled)return;if(null===this._resultCount&&(this._resultCount=t.total,this.emit("resultCount",this._resultCount)),
567
- this._maxResults&&t.total>this._maxResults)return this.emit("error",new sm(this._maxResults)),void this.emit("end");const i=t.rows.concat(t.replies||[]);this._incremental?this.emit("results",i):this._results=this._results.concat(i);const a=i.length===r,s=i.length>0?i[i.length-1][this._sortBy]:null;a&&s?this._getPage(e,s,n+1):(this._incremental||this.emit("results",this._results),this.emit("end"))}catch(e){if(this._canceled)return;this.emit("error",e),this.emit("end")}}get(e){this._results=[],this._resultCount=null,this._getPage(e)}cancel(){this._canceled=!0,this.emit("end")}}function um({defaultOption:e,icon:t,onSelect:n,options:r,selectedOption:o,title:i}){const a=[e,...r],s=null!=o?o:e,l=_o("span",{className:"FilterSelect__menu-label",children:[t&&_o(Do,{name:t,classes:"text-xl hyp-u-margin--right--3"}),s.display]});return _o(Jd,{label:l,title:i,contentClass:"FilterSelect__menu",children:a.map((e=>_o(ep,{onClick:()=>n(e),isSelected:e.value===s.value,label:e.display},e.value)))})}function hm(){
568
- const e=hi(),t=e.getFilter("user"),n=function(){const e=hi(),t=e.allAnnotations(),n=e.defaultAuthority(),r=e.isFeatureEnabled("client_display_names"),o=e.getFocusFilters(),i=oi(e.profile().userid);return lo((()=>{const e={};if(t.forEach((t=>{const o=oi(t.user);e[o]=rp(t,ii(t.user,n),r)})),o.user){const t=oi(o.user.value)||o.user.value;e[t]=o.user.display}const a=Object.keys(e).map((t=>({display:t===i?`${e[t]} (Me)`:e[t],value:t})));return a.sort(((e,t)=>i===e.value?-1:i===t.value?1:e.display.localeCompare(t.display))),a}),[t,i,n,r,o.user])}();return _o(um,{defaultOption:{value:"",display:"Everybody"},icon:"profile",onSelect:t=>e.setFilter("user",t),options:n,selectedOption:t,title:"Filter by user"})}function dm({forcedVisibleCount:e,isFiltered:t,isLoading:n,resultCount:r}){const o=na(),i=n?r:Xi(o),a=o.children.length>0,s=t&&e>0,l=i-e,c=o.children.length;return _o("div",{className:"hyp-u-layout-row NotebookResultCount",children:[n&&_o(Ko,{size:"small"}),!n&&_o("h2",{children:[!a&&_o("strong",{
569
- children:"No results"}),a&&t&&_o("strong",{children:[l," ",1===l?"result":"results"]}),a&&!t&&_o("strong",{children:[c," ",1===c?"thread":"threads"]})]}),s&&_o("h3",{children:["(and ",e," more)"]}),!t&&a&&_o("h3",{children:["(",i," ",1===i?"annotation":"annotations",")"]})]})}function pm({currentPage:e,onChangePage:t,totalPages:n}){const r=e<n,o=e>1,i=function(e,t,n=5){if(t<=1)return[];const r=new Set([1,e,t]);let o=1;for(;r.size<Math.min(t,n);)e+o<=t&&r.add(e+o),e-o>=1&&r.add(e-o),++o;const i=[];return[...r].sort(((e,t)=>e-t)).forEach(((e,t,n)=>{t>0&&e-n[t-1]>1&&i.push(null),i.push(e)})),i}(e,n),a=(e,n)=>{t(e),null==n||n.blur()};return _o("div",{className:"PaginationNavigation",children:[_o("div",{className:"PaginationNavigation__relative PaginationNavigation__prev",children:o&&_o(Ao,{classes:"PaginationPageButton",icon:"arrow-left",title:"Go to previous page",onClick:t=>a(e-1,t.target),variant:"dark",children:"prev"})}),_o("ul",{className:"PaginationNavigation__pages",children:i.map(((t,n)=>_o("li",{
570
- children:null===t?_o("div",{className:"PaginationNavigation__gap",children:"..."}):_o(Ao,{classes:"PaginationPageButton",title:`Go to page ${t}`,pressed:t===e,onClick:e=>a(t,e.target),variant:"dark",children:t.toString()},`page-${n}`)},n)))}),_o("div",{className:"PaginationNavigation__relative PaginationNavigation__next",children:r&&_o(Ao,{classes:"PaginationPageButton",icon:"arrow-right",iconPosition:"right",title:"Go to next page",onClick:t=>a(e+1,t.target),variant:"dark",children:"next"})})]})}function mm({currentPage:e,isLoading:t,onChangePage:n,threads:r,pageSize:o=25}){const{paginatedThreads:i,totalPages:a}=lo((()=>{const t=r.filter((e=>Xi(e)>0)),n=(e-1)*o,i=n+o,a=Math.ceil(t.length/o);return{paginatedThreads:t.slice(n,i),totalPages:a}}),[r,e,o]);return _o(m,{children:[_o(Tp,{threads:i}),!t&&_o(pm,{currentPage:e,onChangePage:n,totalPages:a})]})}var fm=ci((function({loadAnnotationsService:e,streamer:t}){var n
571
- ;const r=hi(),o=r.getFilterValues(),i=r.focusedGroup(),a=r.forcedVisibleThreads().length,s=r.hasAppliedFilter(),l=r.isLoading(),c=r.annotationResultCount(),u=r.pendingUpdateCount(),h=na(),d=null!==(n=null==i?void 0:i.name)&&void 0!==n?n:"",p=(null==i?void 0:i.id)||r.directLinkedGroupId(),m=so(1),[f,g]=ro(1),[v,y]=ro(!1),_=e=>{e instanceof sm&&y(!0)},b=r.hasFetchedProfile();io((()=>{b&&t.connect({applyUpdatesImmediately:!1})}),[b,t]),io((()=>{r.setSortKey("Newest"),p&&e.load({groupId:p,sortBy:"updated",sortOrder:"desc",maxResults:5e3,onError:_,streamFilterBy:"group"})}),[e,p,r]);const w=e=>{g(e)};io((()=>{w(1)}),[o,i]);const x=so(null);ao((()=>{f!==m.current&&(x.current&&Up(x.current),m.current=f)}),[f]);const k=`Show ${u} new or updated ${u>1?"annotations":"annotation"}`;return _o("div",{className:"NotebookView",children:[_o("header",{className:"NotebookView__heading",ref:x,children:_o("h1",{className:"NotebookView__group-name",children:d})}),_o("div",{className:"NotebookView__filters",children:_o(hm,{})
572
- }),_o("div",{className:"NotebookView__results hyp-u-layout-row--align-center text-lg font-medium",children:[u>0&&!s&&_o(Co,{icon:"refresh",onClick:()=>t.applyPendingUpdates(),variant:"primary",title:k}),_o(dm,{forcedVisibleCount:a,isFiltered:s,isLoading:l,resultCount:c})]}),_o("div",{className:"NotebookView__items",children:[v&&_o("div",{className:"NotebookView__messages",children:_o(Wo,{title:"Too many results to show",children:["This preview of the Notebook can show"," ",_o("strong",{children:["up to ",5e3," results"]})," at a time (there are"," ",c," to show here)."," ",_o("a",{href:"mailto:support@hypothes.is?subject=Hypothesis%20Notebook&body=Please%20notify%20me%20when%20the%20Hypothesis%20Notebook%20is%20updated%20to%20support%20more%20than%205000%20annotations",children:"Contact us"})," ","if you would like to be notified when support for more annotations is available."]})}),_o(mm,{currentPage:f,isLoading:l,onChangePage:w,threads:h.children})]})]})}),["loadAnnotationsService","streamer"])
573
- ;var gm=ci((function({toastMessenger:e}){const t=hi(),n=t.mainFrame(),r=t.focusedGroup(),o=`Share Annotations in ${r&&r.name||"..."}`,i=r&&n,a=i&&(s=n.uri,l=r.id,wa(s)?`https://hyp.is/go?url=${encodeURIComponent(s)}&group=${l}`:null);var s,l;return _o($p,{title:o,panelName:"shareGroupAnnotations",children:[!i&&_o("div",{className:"flex flex-row items-center justify-center",children:_o(Ko,{})}),i&&_o("div",{className:"text-color-text-light space-y-3",children:a?_o(m,{children:[_o("div",{className:"text-color-text font-medium","data-testid":"sharing-intro",children:"private"===r.type?_o("p",{children:"Use this link to share these annotations with other group members:"}):_o("p",{children:"Use this link to share these annotations with anyone:"})}),_o("div",{children:_o(Jo,{children:[_o(Zo,{"aria-label":"Use this URL to share these annotations",type:"text",value:a,readOnly:!0}),_o(Co,{icon:"copy",onClick:()=>{try{Ea(a),e.success("Copied share link to clipboard")}catch(t){e.error("Unable to copy link")}},
574
- title:"Copy share link",variant:"dark"})]})}),_o("p",{"data-testid":"sharing-details",children:["private"===r.type?_o("span",{children:["Annotations in the private group"," ",_o("em",{children:r.name})," are only visible to group members."]}):_o("span",{children:["Anyone using this link may view the annotations in the group"," ",_o("em",{children:r.name}),"."]})," ",_o("span",{children:["Private (",_o(Do,{name:"lock",classes:"inline -mt-0.5"})," ",_o("em",{children:"Only Me"}),") annotations are only visible to you."]})]}),_o("div",{className:"text-[24px]",children:_o(Na,{shareURI:a})})]}):_o("p",{"data-testid":"no-sharing",children:"These annotations cannot be shared because this document is not available on the web."})})]})}),["toastMessenger"]);function vm({message:e,onDismiss:t}){const n=e.type.charAt(0).toUpperCase()+e.type.slice(1),r="notice"===e.type?"cancel":e.type;return _o("li",{className:Yr("toast-message-container",{"is-dismissed":e.isDismissed}),onClick:()=>t(e.id),children:_o("div",{
575
- className:Yr("toast-message",`toast-message--${e.type}`),children:[_o("div",{className:"toast-message__type",children:_o(Do,{name:r,classes:"toast-message__icon"})}),_o("div",{className:"toast-message__message",children:[_o("strong",{children:[n,": "]}),e.message,e.moreInfoURL&&_o("div",{className:"toast-message__link",children:_o("a",{href:e.moreInfoURL,onClick:e=>e.stopPropagation(),target:"_new",children:"More info"})})]})]})})}var ym=ci((function({toastMessenger:e}){return _o("div",{children:_o("ul",{"aria-live":"polite","aria-relevant":"additions",className:"ToastMessages",children:hi().getToastMessages().map((t=>_o(vm,{message:t,onDismiss:t=>e.dismiss(t)},t.id)))})})}),["toastMessenger"]);function _m(e){return e.organization&&e.organization.name}function bm(e){const t={};return e.forEach((e=>{if("object"!=typeof e.organization)return;const n="__default__"===(r=e.organization).id?"__default__":`${r.name.toLowerCase()}${r.id}`;var r;void 0===t[n]&&(t[n]=Object.assign({},e.organization),t[n].groups=[]),
576
- function(e,t){const n=Object.assign({},e),r=t.groups;!r.length&&e.organization.logo&&(n.logo=e.organization.logo),r.push(n)}(e,t[n])})),t}function wm(e){const t=bm(e),n=[],r=[];return Object.keys(t).sort().forEach((e=>{"__default__"===e?n.push(...t[e].groups):r.push(...t[e].groups)})),n.length&&r.push(...n),r}function xm({heading:e,children:t}){return _o(m,{children:[e&&_o("h2",{className:"MenuSection__heading",children:e}),_o("ul",{className:"MenuSection__content",children:x(t).map((e=>_o("li",{children:e},e.key)))})]})}var km=ci((function({isExpanded:e,group:t,groups:n,onExpand:r,toastMessenger:o}){const i=t.links.html,a=i||t.canLeave,s=t.scopes&&!t.scopes.enforced||t.isScopedToUri,l=hi(),c=l.focusedGroupId(),u=t.id===c,h=t=>{t.stopPropagation(),t.preventDefault(),r(!e)},d="private"===t.type?"Copy invite link":"Copy activity link";return _o(ep,{icon:t.logo||"blank",iconAlt:_m(t),isDisabled:!s,isExpanded:!!a&&e,isSelected:u,isSubmenuVisible:a?e:void 0,label:t.name,onClick:s?()=>{
577
- l.clearDirectLinkedGroupFetchFailed(),l.clearDirectLinkedIds(),n.focus(t.id)}:h,onToggleSubmenu:h,submenu:_o(m,{children:[_o("ul",{children:[i&&_o("li",{children:_o(ep,{href:i,icon:"external",isSubmenuItem:!0,label:"View group activity"})}),i&&_o("li",{children:_o(ep,{onClick:()=>(e=>{try{Ea(e),o.success(`Copied link for "${t.name}"`)}catch(e){o.error("Unable to copy link")}})(i),icon:"copy",isSubmenuItem:!0,label:d})}),t.canLeave&&_o("li",{children:_o(ep,{icon:"leave",isSubmenuItem:!0,label:"Leave group",onClick:async()=>{const e=`Are you sure you want to leave the group "${t.name}"?`;await ni({title:"Leave group?",message:e,confirmAction:"Leave"})&&n.leave(t.id)}})})]}),!s&&_o("p",{className:"GroupListItem__footer",children:"This group is restricted to specific URLs."})]})})}),["groups","toastMessenger"]);function Sm({expandedGroup:e,onExpandGroup:t,groups:n,heading:r}){return _o(xm,{heading:r,children:n.map((n=>_o(km,{isExpanded:n===e,onExpand:e=>t(e?n:null),group:n},n.id)))})}
578
- var Cm=ci((function({settings:e}){const t=hi(),n=t.getCurrentlyViewingGroups(),r=t.getFeaturedGroups(),o=t.getMyGroups(),i=t.focusedGroup(),a=t.profile().userid,s=lo((()=>wm(o)),[o]),l=lo((()=>wm(r)),[r]),c=lo((()=>wm(n)),[n]),u=t.defaultAuthority(),h=a&&!ii(a,u),d=t.getLink("groups.new"),[p,m]=ro(null);let f;if(i){const t=i.organization.logo||function(e){const t=R(e);return t&&t.icon?t.icon:null}(e)||"",n=_m(i)?_m(i):"";f=_o("span",{className:"GroupList__menu-label",children:[t&&_o("img",{className:"GroupList__menu-icon",src:t,alt:n}),i.name]})}else f=_o("span",{children:""});return!!Zp(e)&&n.length+r.length+o.length<2?f:_o(Jd,{align:"left",contentClass:"GroupList__content",label:f,onOpenChanged:()=>m(null),title:i?`Select group (now viewing: ${i.name})`:"Select group",children:[c.length>0&&_o(Sm,{expandedGroup:p,onExpandGroup:m,heading:"Currently Viewing",groups:c}),l.length>0&&_o(Sm,{expandedGroup:p,onExpandGroup:m,heading:"Featured Groups",groups:l}),s.length>0&&_o(Sm,{expandedGroup:p,onExpandGroup:m,
579
- heading:"My Groups",groups:s}),h&&_o(ep,{icon:"add",href:d,label:"New private group"})]})}),["settings"]);function Am({alwaysExpanded:e,query:t,onSearch:n}){const r=hi().isLoading(),o=so(),[i,a]=ro(t),[s,l]=ro(t);return t!==i&&(l(t),a(t)),_o("form",{action:"#",className:"SearchInput__form",name:"searchForm",onSubmit:e=>{e.preventDefault(),(o.current.value||i)&&n(o.current.value)},children:[_o("input",{"aria-label":"Search",className:Yr("SearchInput__input",{"is-expanded":e||t}),dir:"auto",type:"text",name:"query",placeholder:r?"Loading…":"Search…",disabled:r,ref:o,value:s||"",onInput:e=>l(e.target.value)}),!r&&_o("div",{className:"SearchInput__button-container",children:_o(Co,{icon:"search",onClick:()=>o.current.focus(),size:"small",title:"Search annotations"})}),r&&_o("div",{style:"margin:0.5em 0",children:_o(Ko,{size:"small"})})]})}function Em(){const e=hi(),t=e.sortKey(),n=e.sortKeys().map((n=>_o(ep,{label:n,onClick:()=>e.setSortKey(n),isSelected:n===t},n))),r=_o("span",{className:"TopBar__menu-label",
580
- children:_o(Do,{name:"sort",classes:"TopBar__menu-icon"})});return _o("div",{className:"SortMenu",children:_o(Jd,{label:r,title:`Sort by ${t}`,align:"right",menuIndicator:!1,children:n})})}var Tm=ci((function({router:e}){return _o(Am,{query:hi().routeParams().q,onSearch:t=>{e.navigate("stream",{q:t})},alwaysExpanded:!0})}),["router"]);var Nm=ci((function({auth:e,frameSync:t,onLogout:n,settings:r}){const o=hi(),i=o.defaultAuthority(),a=ii(e.userid,i),s=R(r),l=o.isFeatureEnabled("notebook_launch"),[c,u]=ro(!1),h=e=>s&&!!s[e],d=!a||h("onProfileRequestProvided"),p=!a||h("onLogoutRequestProvided"),m=()=>{t.notifyHost("openNotebook",o.focusedGroupId())},f=()=>a&&t.notifyHost("profileRequested"),g=(()=>{const t={};return d&&(a||(t.href=o.getLink("user",{user:e.username})),t.onClick=f),t})(),v=_o("span",{className:"TopBar__menu-label",children:_o(Do,{name:"profile",classes:"TopBar__menu-icon"})});return _o("div",{className:"UserMenu",onKeyDown:e=>{"n"===e.key&&(m(),u(!1))},children:_o(Jd,{label:v,title:e.displayName,
581
- align:"right",open:c,onOpenChanged:u,children:[_o(xm,{children:[_o(ep,{label:e.displayName,isDisabled:!d,...g}),!a&&_o(ep,{label:"Account settings",href:o.getLink("account.settings")}),l&&_o(ep,{label:"Open notebook",onClick:()=>m()})]}),p&&_o(xm,{children:_o(ep,{label:"Log out",onClick:n})})]})})}),["frameSync","settings"]);var Mm=ci((function({auth:e,frameSync:t,isSidebar:n,onLogin:r,onLogout:o,onSignUp:i,settings:a,streamer:s}){const l=!Zp(a),c=si(["accentColor"],a),u=hi(),h=u.filterQuery(),d=u.pendingUpdateCount(),p=u.isSidebarPanelOpen("help"),f=u.isSidebarPanelOpen("shareGroupAnnotations"),g=()=>{const e=R(a);e&&e.onHelpRequestProvided?t.notifyHost("helpRequested"):u.toggleSidebarPanel("help")},v=_o(m,{children:["unknown"===e.status&&_o("span",{className:"TopBar__login-links",children:""}),"logged-out"===e.status&&_o("span",{className:"TopBar__login-links text-lg font-medium hyp-u-horizontal-spacing--2",children:[_o(Eo,{classes:"InlineLinkButton",onClick:i,style:c,variant:"primary",children:"Sign up"
582
- }),_o("div",{children:"/"}),_o(Eo,{classes:"InlineLinkButton",onClick:r,style:c,variant:"primary",children:"Log in"})]}),"logged-in"===e.status&&_o(Nm,{auth:e,onLogout:o})]});return _o("div",{className:"TopBar",children:[!n&&_o("div",{className:"TopBar__inner content",children:[_o(Tm,{}),_o("div",{className:"hyp-u-stretch"}),_o(Co,{icon:"help",expanded:p,onClick:g,size:"small",title:"Help"}),v]}),n&&_o("div",{className:"TopBar__inner content",children:[_o(Cm,{}),_o("div",{className:"hyp-u-stretch"}),d>0&&_o(Co,{icon:"refresh",onClick:()=>s.applyPendingUpdates(),size:"small",variant:"primary",title:`Show ${d} new/updated ${1===d?"annotation":"annotations"}`}),_o(Am,{query:h||null,onSearch:u.setFilterQuery}),_o(Em,{}),l&&_o(Co,{icon:"share",expanded:f,onClick:()=>{u.toggleSidebarPanel("shareGroupAnnotations")},size:"small",title:"Share annotations on this page"}),_o(Co,{icon:"help",expanded:p,onClick:g,size:"small",title:"Help"}),v]})]})}),["frameSync","settings","streamer"])
583
- ;var Lm=ci((function({auth:e,frameSync:t,settings:n,session:r,toastMessenger:o}){const i=hi(),a=i.hasFetchedProfile(),s=i.profile(),l=i.route(),c=lo((()=>a?function(e){const t=ri(e.userid);if(t&&e.userid){let n=t.username;return e.user_info&&e.user_info.display_name&&(n=e.user_info.display_name),{status:"logged-in",displayName:n,userid:e.userid,username:t.username}}return{status:"logged-out"}}(s):{status:"unknown"}),[a,s]),u=lo((()=>si(["appBackgroundColor"],n)),[n]),h="clean"===n.theme,d="sidebar"===l;io((()=>{(function(e,t,n){const r="object"==typeof t.preferences&&!!t.preferences.show_sidebar_tutorial,o=R(n)||{onHelpRequestProvided:!1};return e&&!o.onHelpRequestProvided&&r})(d,s,n)&&i.openSidebarPanel("help")}),[d,s,n,i]);const p=async()=>{if(R(n))t.notifyHost("loginRequested");else try{await e.login(),i.closeSidebarPanel("loginPrompt"),i.clearGroups(),r.reload()}catch(e){o.error(e.message)}},m=()=>{R(n)?t.notifyHost("signupRequested"):window.open(i.getLink("signup"))};return _o("div",{
584
- className:Yr("HypothesisApp","js-thread-list-scroll-root",{"theme-clean":h,"HypothesisApp--notebook":"notebook"===l}),style:u,children:["notebook"!==l&&_o(Mm,{auth:c,onLogin:p,onSignUp:m,onLogout:async()=>{await(async()=>{const e=i.countDrafts();if(0===e)return!0;let t="";return 1===e?t="You have an unsaved annotation.\nDo you really want to discard this draft?":e>1&&(t="You have "+e+" unsaved annotations.\nDo you really want to discard these drafts?"),ni({title:"Discard drafts?",message:t,confirmAction:"Discard"})})()&&(i.clearGroups(),i.removeAnnotations(i.unsavedAnnotations()),i.discardAllDrafts(),R(n)?t.notifyHost("logoutRequested"):r.logout())},isSidebar:d}),_o("div",{className:"HypothesisApp__content",children:[_o(ym,{}),_o(rm,{auth:"logged-in"===c.status?c:{}}),_o(gm,{}),l&&_o("main",{children:["annotation"===l&&_o(Mp,{onLogin:p}),"notebook"===l&&_o(fm,{}),"stream"===l&&_o(Kp,{}),"sidebar"===l&&_o(Yp,{onLogin:p,onSignUp:m})]})]})]})}),["auth","frameSync","session","settings","toastMessenger"])
585
- ;function zm({error:e}){return _o("div",{className:"LaunchErrorPanel",children:_o(Wo,{title:"Unable to start Hypothesis",children:e.message})})}class Om{constructor(e,t){this._api=e,this._store=t}_applyDraftChanges(e){const t={},n=this._store.getDraft(e);return n&&(t.tags=n.tags,t.text=n.text,t.permissions=n.isPrivate?xa(e.user):ka(e.user,e.group)),{...e,...t}}_initialize(e,t=new Date){const n=this._store.getDefault("annotationPrivacy"),r=this._store.focusedGroupId(),o=this._store.profile();if(!r)throw new Error("Cannot create annotation without a group");const i=o.userid,a=o.user_info,s="s:"+H(8),l=Object.assign({created:t.toISOString(),group:r,permissions:Sa(i,r,n),tags:[],text:"",updated:t.toISOString(),user:i,user_info:a,$tag:s,hidden:!1,links:{},document:{title:""}},e);return Ri(l)&&(l.permissions=xa(i)),l}create(e,t=new Date){const n=this._initialize(e,t);this._store.addAnnotations([n]),this._store.deleteNewAndEmptyDrafts(),Ri(n)||this._store.createDraft(n,{tags:n.tags,text:n.text,isPrivate:!zi(n)}),
519
+ className:"w-full break-words cursor-text",dir:"auto",lang:"",children:_o("div",{className:Yr("styled-text",t),"data-testid":"styled-text",ref:o,dangerouslySetInnerHTML:{__html:r},style:n})})}function Td({children:e}){return _o("ul",{className:"flex flex-wrap gap-2 leading-none","aria-label":"Annotation tags",children:e})}function Nd({href:e,onRemoveTag:t,tag:n}){return _o("li",{className:"flex items-center border rounded-sm bg-grey-0",children:[_o("div",{className:"grow px-1.5 py-1 touch:p-2",children:e?_o(Bo,{classes:"text-color-text-light hover:text-brand",href:e,lang:"",target:"_blank","aria-label":`Tag: ${n}`,title:`View annotations with tag: ${n}`,children:n}):_o("span",{className:"text-color-text-light cursor-default","aria-label":`Tag: ${n}`,lang:"",children:n})}),t&&_o("button",{className:Yr("px-1.5 py-1 touch:p-2","border-l rounded-sm rounded-l-none","text-grey-6 hover:text-color-text hover:bg-grey-2","transition-colors duration-200","hyp-u-outline-on-keyboard-focus--inset"),onClick:()=>{t(n)},
520
+ title:`Remove tag: ${n}`,children:_o(Do,{classes:"font-base",name:"cancel",title:`Remove ${n}`})})]})}xd.addHook("afterSanitizeAttributes",(e=>{"target"in e&&e.setAttribute("target","_blank")}));var Md=ci((function({annotation:e,settings:t}){var n,r;const[o,i]=ro(!0),[a,s]=ro(!1),l=hi(),c=l.defaultAuthority(),u=l.getDraft(e),h=o?"More":"Less",d=null!==(n=null==u?void 0:u.tags)&&void 0!==n?n:e.tags,p=null!==(r=null==u?void 0:u.text)&&void 0!==r?r:e.text,m=p.length>0,f=d.length>0,g=si(["annotationFontFamily"],t),v=lo((()=>e&&!ii(null==e?void 0:e.user,c)),[e,c]),y=e=>l.getLink("search.tag",{tag:e});return _o("div",{className:"space-y-4",children:[m&&_o(Pa,{collapse:o,collapsedHeight:400,inlineControls:!1,onCollapsibleChanged:s,onToggleCollapsed:i,overflowThreshold:20,children:_o(Ed,{textStyle:g,markdown:p,textClass:{"p-redacted-content":Pi(e)}})}),(a||f)&&_o("div",{className:"flex flex-row gap-x-2",children:[_o("div",{className:"grow",children:f&&_o(Td,{children:d.map((e=>_o(Nd,{tag:e,href:v?y(e):void 0},e)))})
521
+ }),a&&_o("div",{children:_o(Ao,{classes:Yr("-mt-3","text-grey-7 font-normal"),expanded:!o,onClick:()=>i(!o),title:`Toggle visibility of full annotation text: Show ${h}`,children:_o("div",{className:"flex items-center gap-x-2",children:[_o(Do,{classes:"!text-tiny",name:o?"expand":"collapse",title:o?"expand":"collapse"}),_o("div",{children:h})]})})})]})]})}),["settings"]);const Ld=0,zd=1;function Od(e,t,n,r){let o=e.selectionStart,i=e.selectionEnd;return o>=t+n?(o+=r.length-n,i+=r.length-n):i<=t||(o<=t&&i>=t+n?i+=r.length-n:o<t&&i<t+n?o=t:o<t+n&&i>t+n?i+=r.length-n:t<o&&t+n>i&&(o=t,i=t+n)),{text:e.text.slice(0,t)+r+e.text.slice(t+n),selectionStart:o,selectionEnd:i}}function Id(e,t=Ld){const n=e.text.slice(e.selectionStart,e.selectionEnd);let r,o="";if(t===zd&&(o="!"),n.match(/[a-z]+:\/\/.*/)){const t="Description";return r=Od(e,e.selectionStart,n.length,o+"["+t+"]("+n+")"),r.selectionStart=e.selectionStart+o.length+1,r.selectionEnd=r.selectionStart+t.length,r}{
522
+ const t=o+"["+n+"](",i="http://insert-your-link-here.com";return r=Od(e,e.selectionStart,n.length,t+i+")"),r.selectionStart=e.selectionStart+t.length,r.selectionEnd=r.selectionStart+i.length,r}}function Pd(e,t,n,r){void 0===n&&(n=t);const o=e.text.slice(e.selectionStart-t.length,e.selectionStart),i=e.text.slice(e.selectionEnd,e.selectionEnd+t.length);let a=e;return e.selectionStart===e.selectionEnd&&r&&(a=Od(e,e.selectionStart,0,r),a.selectionStart=a.selectionEnd-r.length),o===t&&i===n?(a=Od(a,a.selectionStart-t.length,t.length,""),a=Od(a,a.selectionEnd,n.length,"")):(a=Od(a,a.selectionStart,0,t),a=Od(a,a.selectionEnd,0,n)),a}function Rd(e,t){const n=e.indexOf("\n",t);return n<0?e.length:n}function Dd(e,t,n,r){let o=function(e,t){const n=e.lastIndexOf("\n",t);return n<0?0:n+1}(e.text,t),i=Rd(e.text,t);for(;i<=Rd(e.text,n);){const t=i===e.text.length,a=i-o,s=Rd((e=r(e,o,i)).text,o)-o;if(n+=s-a,t)break;o=o+s+1,i=Rd(e.text,o)}return e}function Bd(e,t){const n=e.selectionStart,r=e.selectionEnd;let o=!0
523
+ ;return Dd(e,n,r,((e,n)=>(e.text.slice(n,n+t.length)!==t&&(o=!1),e))),Dd(e,n,r,o?(e,n)=>Od(e,n,t.length,""):(e,n)=>e.text.slice(n,n+t.length)===t?e:Od(e,n,0,t))}const Fd={bold:"b",italic:"i",link:"l",quote:"q",image:"g",numlist:"o",list:"u"};function jd({buttonRef:e,disabled:t=!1,iconName:n="",label:r,onClick:o,shortcutKey:i,tabIndex:a,title:s=""}){const l=lo((()=>((e=window.navigator.userAgent)=>e.indexOf("Mac OS")>=0)()?"Cmd":"Ctrl"),[]);let c=s;i&&(c+=` (${l}-${i.toUpperCase()})`);const u={buttonRef:e,disabled:t,icon:n,onClick:o,tabIndex:a,title:c};return r?_o(Ao,{classes:"font-normal TransparentButton",...u,children:r}):_o(Co,{classes:"MarkdownEditor__toolbar-button",...u})}function Hd({isPreviewing:e,onCommand:t,onTogglePreview:n}){const r=0,o=1,i=2,a=3,s=4,l=5,c=6,u=7,h=8,d=9,p=10,[m,f]=ro(0),g=so([]).current;if(0===g.length)for(let e=0;e<=p;e++)g.push({current:null});const v=e=>m===e?0:-1;return _o("div",{
524
+ className:"hyp-u-layout-row hyp-u-border--left hyp-u-border--right hyp-u-border--top hyp-u-bg-color--white MarkdownEditor__toolbar",role:"toolbar","aria-label":"Markdown editor toolbar",onKeyDown:t=>{let n=0;const r=p-1;e&&(n=h);let o=null;switch(Fo(t.key)){case"ArrowLeft":o=m<=n?r:m-1;break;case"ArrowRight":o=m>=r?n:m+1;break;case"Home":o=n;break;case"End":o=r}var i;null!==o&&(f(i=o),g[i].current.focus(),t.preventDefault())},children:[_o(jd,{disabled:e,iconName:"format-bold",onClick:()=>t("bold"),shortcutKey:Fd.bold,buttonRef:g[r],tabIndex:v(r),title:"Bold"}),_o(jd,{disabled:e,iconName:"format-italic",onClick:()=>t("italic"),shortcutKey:Fd.italic,buttonRef:g[o],tabIndex:v(o),title:"Italic"}),_o(jd,{disabled:e,iconName:"format-quote",onClick:()=>t("quote"),shortcutKey:Fd.quote,buttonRef:g[i],tabIndex:v(i),title:"Quote"}),_o(jd,{disabled:e,iconName:"link",onClick:()=>t("link"),shortcutKey:Fd.link,buttonRef:g[a],tabIndex:v(a),title:"Insert link"}),_o(jd,{disabled:e,iconName:"image",onClick:()=>t("image"),
525
+ shortcutKey:Fd.image,buttonRef:g[s],tabIndex:v(s),title:"Insert image"}),_o(jd,{disabled:e,iconName:"format-functions",onClick:()=>t("math"),buttonRef:g[l],tabIndex:v(l),title:"Insert math (LaTeX is supported)"}),_o(jd,{disabled:e,iconName:"format-list-numbered",onClick:()=>t("numlist"),shortcutKey:Fd.numlist,buttonRef:g[c],tabIndex:v(c),title:"Numbered list"}),_o(jd,{disabled:e,iconName:"format-list-unordered",onClick:()=>t("list"),shortcutKey:Fd.list,buttonRef:g[u],tabIndex:v(u),title:"Bulleted list"}),_o("span",{className:"hyp-u-stretch"}),_o("div",{className:"hyp-u-layout-row--center",children:_o(Bo,{href:"https://web.hypothes.is/help/formatting-annotations-with-markdown/",target:"_blank",classes:"text-tiny IconOnlyLink",linkRef:g[h],tabIndex:v(h),title:"Formatting help","aria-label":"Formatting help",children:_o(Do,{name:"help"})})}),_o(jd,{label:e?"Write":"Preview",onClick:n,buttonRef:g[d],tabIndex:v(d)})]})}function qd({label:e="",onEditText:t=(()=>{}),text:n="",textStyle:r={}}){
526
+ const[o,i]=ro(!1),a=so(null);io((()=>{var e;o||(null===(e=a.current)||void 0===e||e.focus())}),[o]);const s=e=>{a.current&&(!function(e,t){const n=e=>{const n=e({text:t.value,selectionStart:t.selectionStart,selectionEnd:t.selectionEnd});t.value=n.text,t.selectionStart=n.selectionStart,t.selectionEnd=n.selectionEnd,t.focus()},r=e=>{const t=e.text.slice(0,e.selectionStart);return 0===t.length||"\n"===t.slice(-1)||"$$"===t.slice(-2)?Pd(e,"$$","$$","Insert LaTeX"):Pd(e,"\\(","\\)","Insert LaTeX")};switch(e){case"bold":n((e=>Pd(e,"**","**","Bold")));break;case"italic":n((e=>Pd(e,"*","*","Italic")));break;case"quote":n((e=>Bd(e,"> ")));break;case"link":n((e=>Id(e)));break;case"image":n((e=>Id(e,zd)));break;case"math":n(r);break;case"numlist":n((e=>Bd(e,"1. ")));break;case"list":n((e=>Bd(e,"* ")));break;default:throw new Error(`Unknown toolbar command "${e}"`)}}(e,a.current),t({text:a.current.value}))};return _o("div",{className:"leading-none",children:[_o(Hd,{onCommand:s,isPreviewing:o,onTogglePreview:()=>i(!o)
527
+ }),o?_o(Ed,{markdown:n,textClass:{"hyp-u-border":!0,"hyp-u-bg-color--grey-1":!0,"hyp-u-padding":!0},textStyle:r}):_o("textarea",{"aria-label":e,className:"MarkdownEditor__input",dir:"auto",ref:a,onClick:e=>e.stopPropagation(),onKeyDown:e=>{if(e.ctrlKey||e.metaKey)for(let[t,n]of Object.entries(Fd))n===Fo(e.key)&&(e.stopPropagation(),e.preventDefault(),s(t))},onInput:e=>{t({text:e.target.value})},value:n,style:r})]})}const Ud=e=>e;function $d({activeItem:e=-1,id:t,itemPrefixId:n,list:r,listFormatter:o=Ud,onSelectItem:i,open:a=!1}){const s=lo((()=>r.map(((t,r)=>{const a=n?{id:`${n}${r}`}:{};return _o("li",{role:"option","aria-selected":(e===r).toString(),className:Yr({"is-selected":e===r},"AutocompleteList__li"),onClick:()=>{i(t)},...a,children:o(t,r)},`AutocompleteList-${r}`)}))),[e,n,r,o,i]),l=t?{id:t}:{},c=0===r.length||!a;return _o("div",{className:Yr({"is-hidden":c},"AutocompleteList"),children:_o("ul",{className:"AutocompleteList__items",tabIndex:-1,"aria-label":"Suggestions",role:"listbox",...l,children:s
528
+ })})}let Gd=0;var Vd=ci((function({onAddTag:e,onRemoveTag:t,onTagInput:n,tagList:r,tags:o}){const i=so(),[a,s]=ro([]),[l,c]=ro(-1),[u,h]=ro(!1),[d]=ro((()=>(++Gd,`TagEditor-${Gd}`))),p=so();Ho(p,u,(()=>{h(!1)}));const m=()=>i.current.value.trim(),f=()=>m()&&m().length>0,g=()=>{i.current.value="",null==n||n("")},v=t=>{e(t)&&(h(!1),c(-1),g(),i.current.focus())},y=e=>{let t=l+e;t<-1?t=a.length-1:t>=a.length&&(t=-1),c(t)},_=l>=0?`${d}-AutocompleteList-item-${l}`:"";return _o("div",{className:"TagEditor space-y-4",children:[_o(Td,{children:r.map((e=>_o(Nd,{onRemoveTag:t,tag:e},e)))}),_o("div",{id:d,className:"TagEditor__combobox-wrapper",ref:p,role:"combobox","aria-expanded":u.toString(),"aria-owns":`${d}-AutocompleteList`,"aria-haspopup":"listbox",children:[_o("input",{onInput:()=>{null==n||n(m()),(()=>{if(f()){const e=o.filter(m());s(((e,t)=>{const n=[];return e.forEach((e=>{t.indexOf(e)<0&&n.push(e)})),n.sort()})(e,r)),h(e.length>0)}else h(!1);c(-1)})()},onKeyDown:e=>{switch(Fo(e.key)){case"ArrowUp":y(-1),
529
+ e.preventDefault();break;case"ArrowDown":y(1),e.preventDefault();break;case"Escape":g(),e.preventDefault();break;case"Enter":case",":v(-1===l?m():a[l]),e.preventDefault();break;case"Tab":if(!f())break;-1!==l?v(a[l]):1===a.length?v(a[0]):v(m()),e.preventDefault()}},onFocus:()=>{f()&&h(!0)},ref:i,placeholder:"Add new tags",className:"TagEditor__input",type:"text",autoComplete:"off","aria-autocomplete":"list","aria-activedescendant":_,"aria-controls":`${d}-AutocompleteList`,dir:"auto"}),_o($d,{id:`${d}-AutocompleteList`,list:a,listFormatter:e=>{const t=m().toLowerCase(),n=e.toLowerCase().indexOf(t);if(-1===n)return _o("span",{children:e});const r=e.slice(0,n),o=e.slice(n,n+t.length),i=e.slice(n+t.length);return _o("span",{children:[_o("strong",{children:r}),o,_o("strong",{children:i})]})},open:u,onSelectItem:e=>{e&&v(e)},itemPrefixId:`${d}-AutocompleteList-item-`,activeItem:l})]})]})}),["tags"]);function Wd(){return _o("div",{className:"hyp-u-padding--top hyp-u-border--top text-sm leading-none",children:_o(Bo,{
530
+ classes:"hyp-u-layout-row--align-center p-link--muted",href:"http://creativecommons.org/publicdomain/zero/1.0/",target:"_blank",title:"View more information about the Creative Commons Public Domain dedication",children:[_o(Do,{name:"cc-std",classes:"text-tiny"}),_o(Do,{name:"cc-zero",classes:"hyp-u-margin--left--1 text-tiny"}),_o("div",{className:"hyp-u-margin--left--2",children:"Annotations can be freely reused by anyone for any purpose."})]})})}function Yd(e){return null!==e.offsetParent}function Kd({className:e,closeMenu:t,children:n,visible:r}){const o=so();io((()=>{let e=null;return r&&(e=setTimeout((()=>{const e=o.current.querySelector('[role^="menuitem"]');e&&e.focus()}))),()=>{clearTimeout(e)}}),[r]);return _o("div",{role:"menu",className:e,ref:o,onKeyDown:e=>{const n=Array.from(o.current.querySelectorAll('[role^="menuitem"]')).filter(Yd);let r=n.findIndex((e=>e.contains(document.activeElement))),i=!1;switch(Fo(e.key)){case"ArrowLeft":case"Escape":t&&(t(e),i=!0);break;case"ArrowUp":r-=1,
531
+ r<0&&(r=n.length-1),i=!0;break;case"ArrowDown":r+=1,r===n.length&&(r=0),i=!0;break;case"Home":r=0,i=!0;break;case"End":r=n.length-1,i=!0}i&&r>=0&&(e.stopPropagation(),e.preventDefault(),n[r].focus())},children:n})}function Xd({className:e}){return _o("svg",{className:Yr("Menu__arrow",e),width:15,height:8,children:_o("path",{d:"M0 8 L7 0 L15 8",stroke:"currentColor",strokeWidth:"2"})})}let Zd=!1;const Jd=()=>{};function Qd({align:e="left",arrowClass:t="",children:n,containerPositioned:r=!0,contentClass:o,defaultOpen:i=!1,label:a,open:s,onOpenChanged:l,menuIndicator:c=!0,title:u}){let[h,d]=ro(i);"boolean"==typeof s&&(h=s,d=l||Jd);const p=so(h);io((()=>{"function"==typeof l&&p.current!==h&&(p.current=h,l(h))}),[h,l]);const f=e=>{if("mousedown"===e.type)Zd=!0;else if("click"===e.type&&Zd)return Zd=!1,e.stopPropagation(),void e.preventDefault();d(!h)},g=co((()=>d(!1)),[d]),v=so();Ho(v,h,g);const y=e=>e.stopPropagation();return _o("div",{className:"Menu",ref:v,style:{position:r?"relative":"static"},onClick:y,
532
+ onMouseDown:y,children:[_o("button",{"aria-expanded":h?"true":"false","aria-haspopup":!0,className:"Menu__toggle",onMouseDown:f,onClick:f,"aria-label":u,title:u,children:_o("span",{className:"Menu__toggle-wrapper",children:[a,c&&_o("span",{className:Yr("Menu__toggle-arrow",h&&"is-open"),children:_o(wo,{name:"expand-menu",className:"Menu__toggle-icon"})})]})}),h&&_o(m,{children:[_o(Xd,{className:t}),_o("div",{className:Yr("Menu__content",`Menu__content--align-${e}`,o),role:"menu",tabIndex:-1,onClick:g,onKeyDown:e=>{const t=Fo(e.key);"Enter"!==t&&" "!==t||setTimeout((()=>{g()}))},children:_o(Kd,{visible:!0,children:n})})]})]})}function ep({children:e,visible:t}){const n=so(),[r,o]=ro(t?"auto":0),[i,a]=ro(t);io((()=>{if(t===(0!==r))return;const e=n.current;t?(e.style.display="",a(!0),o(e.scrollHeight)):(e.style.height=`${e.scrollHeight}px`,e.getBoundingClientRect(),o(0))}),[r,t]);return _o("div",{ontransitionend:co((()=>{t?o("auto"):a(!1)}),[o,t]),ref:n,style:{display:i?"":"none",height:r,
533
+ overflow:"auto"===r?"visible":"hidden",transition:"height 0.15s ease-in"},children:e})}function tp({href:e,icon:t,iconAlt:n,isDisabled:r,isExpanded:o,isSelected:i,isSubmenuItem:a,isSubmenuVisible:s,label:l,onClick:c,onToggleSubmenu:u,submenu:h}){const d=t&&-1!==t.indexOf("/"),p=t||a,f=t&&a,g=so();let v=null,y=null;t&&"blank"!==t&&(y=d?_o("img",{className:"MenuItem__icon",alt:n,src:t}):_o(wo,{name:t,className:"MenuItem__icon"}));const _=a?null:y,b=a?y:null;let w;const x="boolean"==typeof s,k="boolean"==typeof i;io((()=>()=>{clearTimeout(v)}),[]);const S=e=>{switch(Fo(e.key)){case"ArrowRight":u&&(e.stopPropagation(),e.preventDefault(),u(e));break;case"Enter":case" ":c&&c(e)}};return w=e?_o("a",{ref:g,className:Yr("MenuItem",{"is-submenu":a,"is-disabled":r}),href:e,target:"_blank",tabIndex:-1,rel:"noopener noreferrer",role:"menuitem",onKeyDown:S,children:[p&&_o("div",{className:"MenuItem__icon-container",children:_}),_o("span",{className:"MenuItem__label",children:l}),f&&_o("div",{
534
+ className:"MenuItem__icon-container",children:b})]}):_o("div",{ref:g,className:Yr("MenuItem",{"is-submenu":a,"is-disabled":r,"is-expanded":o,"is-selected":i}),tabIndex:-1,onKeyDown:S,onClick:c,role:k?"menuitemradio":"menuitem","aria-checked":k?i:void 0,"aria-haspopup":x,"aria-expanded":x?s:void 0,children:[p&&_o("div",{className:"MenuItem__icon-container",children:_}),_o("span",{className:"MenuItem__label",children:l}),f&&_o("div",{className:"MenuItem__icon-container",children:b}),x&&_o("div",{role:"none",icon:s?"collapse-menu":"expand-menu",className:"MenuItem__toggle",onClick:u,title:`Show actions for ${l}`,children:_o(wo,{name:s?"collapse-menu":"expand-menu",className:"MenuItem__toggle-icon"})})]}),_o(m,{children:[w,x&&_o(ep,{visible:s,children:_o(Kd,{closeMenu:e=>{u&&u(e),v=setTimeout((()=>{g.current.focus()}))},visible:s,className:"MenuItem__submenu",children:h})})]})}var np=ci((function({annotation:e,isDisabled:t,onSave:n,settings:r}){const o=hi(),i=o.getDraft(e),a=o.getGroup(e.group);if(!a)return null
535
+ ;const s=i?i.isPrivate:!Ca(e.permissions),l=s?"Only Me":a.name,c=t=>{o.createDraft(e,{...i,isPrivate:"private"===t}),Ni(e)||o.setDefault("annotationPrivacy",t)},u=si(["ctaTextColor","ctaBackgroundColor"],r),h=_o("div",{className:"annotation-publish-button__menu-label",style:u,children:_o(Do,{name:"expand-menu"})});return _o("div",{className:"hyp-u-layout-row hyp-u-horizontal-spacing--4",children:[_o("div",{className:"annotation-publish-button",children:[_o(Ao,{classes:"PublishControlButton","data-testid":"publish-control-button",style:u,onClick:n,disabled:t,size:"large",variant:"primary",children:["Post to ",l]}),_o("div",{className:"annotation-publish-button__menu-wrapper",style:u,children:_o(Qd,{arrowClass:"annotation-publish-button__menu-arrow",containerPositioned:!1,contentClass:"annotation-publish-button__menu-content",label:h,menuIndicator:!1,title:"Change annotation sharing setting",align:"left",children:[_o(tp,{icon:"open"===a.type?"public":"groups",label:a.name,isSelected:!s,onClick:()=>c("shared")
536
+ }),_o(tp,{icon:"lock",label:"Only Me",isSelected:s,onClick:()=>c("private")})]})})]}),_o("div",{children:_o(Ao,{icon:"cancel",onClick:()=>{o.removeDraft(e),Li(e)&&o.removeAnnotations([e])},size:"large",children:"Cancel"})})]})}),["settings"]);var rp=ci((function({annotation:e,annotationsService:t,settings:n,tags:r,toastMessenger:o}){const[i,a]=ro(null),s=hi(),l=s.getDraft(e),c=s.getGroup(e.group);if(!l)return null;const u=!l.isPrivate&&c&&"private"!==c.type,h=l.tags,d=l.text,p=!d&&!h.length,m=({tags:e})=>{s.createDraft(l.annotation,{...l,tags:e})},f=e=>{if(!e||h.indexOf(e)>=0)return!1;const t=[...h,e];return r.store(t),m({tags:t}),!0},g=async()=>{i&&f(i);try{await t.save(e)}catch(e){o.error("Saving annotation failed")}};return _o("div",{className:"hyp-u-vertical-spacing AnnotationEditor",onKeyDown:e=>{const t=Fo(e.key);p||(e.metaKey||e.ctrlKey)&&"Enter"===t&&(e.stopPropagation(),e.preventDefault(),g())},children:[_o(qd,{textStyle:si(["annotationFontFamily"],n),label:"Annotation body",text:d,
537
+ onEditText:({text:e})=>{s.createDraft(l.annotation,{...l,text:e})}}),_o(Vd,{onAddTag:f,onRemoveTag:e=>{const t=[...h],n=t.indexOf(e);return n>=0&&(t.splice(n,1),m({tags:t}),!0)},onTagInput:a,tagList:h}),_o("div",{className:"hyp-u-layout-row annotation__form-actions",children:_o(np,{annotation:e,isDisabled:p,onSave:g})}),u&&_o(Wd,{})]})}),["annotationsService","settings","tags","toastMessenger"]);function op(e,t,n){var r;return(n||t)&&null!==(r=e.user_info)&&void 0!==r&&r.display_name?e.user_info.display_name:oi(e.user)}function ip({domain:e,link:t,title:n}){return _o("div",{className:"hyp-u-layout-row hyp-u-horizontal-spacing--2",children:[_o("div",{className:"text-color-text-light",children:['on "',t?_o(Bo,{href:t,target:"_blank",children:n}):_o("span",{children:n}),'"']}),e&&_o("span",{className:"text-color-text-light",children:["(",e,")"]})]})}function ap({annotation:e}){const t=hi().getGroup(e.group),n=null==t?void 0:t.links.html,r=Aa(e.permissions);return _o("div",{
538
+ className:"hyp-u-layout-row--align-baseline",children:[t&&n&&_o(Bo,{classes:"hyp-u-layout-row--align-baseline hyp-u-horizontal-spacing--2 p-link--muted p-link--hover-muted",href:t.links.html,target:"_blank",children:["open"===t.type?_o(Do,{classes:"text-tiny",name:"public"}):_o(Do,{classes:"text-tiny",name:"groups"}),_o("span",{children:t.name})]}),r&&!n&&_o("span",{className:"hyp-u-layout-row--align-baseline text-color-text-light",children:_o("span",{"data-testid":"private-info",children:"Only me"})})]})}let sp={};function lp(e,t){return t-e}function cp(e,t,n=window.Intl){const r=JSON.stringify(t);let o=sp[r];return o||(o=sp[r]=new n.DateTimeFormat(void 0,t)),o.format(e)}const up=[{test:(e,t)=>lp(e,t)<3e4,formatter:()=>"Just now",nextUpdate:1e3},{test:(e,t)=>lp(e,t)<6e4,formatter:function(e,t){return`${Math.floor(lp(e,t)/1e3)} secs ago`},nextUpdate:1e3},{test:(e,t)=>lp(e,t)<36e5,formatter:function(e,t){const n=Math.floor(lp(e,t)/6e4);return`${n} min${n>1?"s":""} ago`},nextUpdate:6e4},{
539
+ test:(e,t)=>lp(e,t)<864e5,formatter:function(e,t){const n=Math.floor(lp(e,t)/36e5);return`${n} hr${n>1?"s":""} ago`},nextUpdate:36e5},{test:(e,t)=>e.getFullYear()===t.getFullYear(),formatter:function(e,t,n){return cp(e,{month:"short",day:"numeric"},n)},nextUpdate:null}],hp={test:()=>!0,formatter:function(e,t,n){return cp(e,{day:"numeric",month:"short",year:"numeric"},n)},nextUpdate:null};function dp(e,t){for(let n of up)if(n.test(e,t))return n;return hp}function pp(e){return!isNaN(e.valueOf())}function mp(e,t){let n;const r=new Date(e),o=()=>{const e=function(e,t){if(!e||!pp(e)||!pp(t))return null;let n=dp(e,t).nextUpdate;return null===n?null:(n=Math.max(n,5e3),n=Math.min(n,20736e5),n)}(r,new Date);if(null===e)return;n=setTimeout((()=>{t(),o()}),e+500)};return o(),()=>clearTimeout(n)}function fp(e,t,n){return e?dp(e,t).formatter(e,t,n):""}function gp(e,t){return cp(e,{year:"numeric",month:"short",day:"2-digit",weekday:"long",hour:"2-digit",minute:"2-digit"},t)}
540
+ function vp({annotationCreated:e,annotationUpdated:t,annotationUrl:n,withEditedTimestamp:r}){const[o,i]=ro((()=>new Date)),a=lo((()=>new Date(e)),[e]),s=lo((()=>r&&new Date(t)),[t,r]),l=lo((()=>({absolute:gp(a),relative:fp(a,o)})),[a,o]),c=lo((()=>s?{absolute:gp(s),relative:fp(s,o)}:{}),[s,o]);io((()=>mp(s?t:e,(()=>i(new Date)))),[e,t,a,s,o]);const u=c&&c.relative!==l.relative?`edited ${c.relative}`:"edited";return _o("div",{children:[r&&_o("span",{className:"text-color-text-light text-sm italic","data-testid":"timestamp-edited",title:c.absolute,children:["(",u,")"," "]}),n?_o(Bo,{classes:"p-link--muted p-link--hover-muted",target:"_blank",title:l.absolute,href:n,children:l.relative}):_o("span",{className:"color-text-color-light","data-testid":"timestamp-created",title:l.absolute,children:l.relative})]})}function yp({authorLink:e,displayName:t}){const n=_o("h3",{className:"text-color-text font-bold",children:t});return e?_o(Bo,{href:e,target:"_blank",children:n}):_o("div",{children:n})}
541
+ var _p=ci((function({annotation:e,isEditing:t,replyCount:n,threadIsCollapsed:r,settings:o}){var i;const a=hi(),s=a.defaultAuthority(),l=a.isFeatureEnabled("client_display_names"),c=ii(e.user,s),u=op(e,c,l),h=(()=>{var t;return c?null!==(t=o.usernameUrl&&`${o.usernameUrl}${oi(e.user)}`)&&void 0!==t?t:void 0:a.getLink("user",{user:e.user})})(),d=Ni(e)&&r,p=Aa(e.permissions),m=(null===(i=e.links)||void 0===i?void 0:i.html)||"",f=!t&&e.created,g=lo((()=>function(e){if(!e.updated||!e.created||e.updated===e.created)return!1;const t=new Date(e.created).getTime(),n=new Date(e.updated).getTime();return!isNaN(t)&&!isNaN(n)&&n-t>2e3}(e)&&!d),[e,d]),v=`${n} ${n>1?"replies":"reply"}`,y=n>0&&d,_=!Ni(e),b=function(e){return{domain:Ei(e),titleText:Ti(e),titleLink:Ai(e)}}(e),w=m&&b.titleLink?b.titleLink:"",x="sidebar"!==a.route()&&b.titleText;return _o("header",{children:[_o("div",{className:"hyp-u-layout-row--align-baseline hyp-u-horizontal-spacing--2 flex-wrap-reverse",children:[p&&!t&&_o(Do,{classes:"text-tiny",
542
+ name:"lock",title:"This annotation is visible only to you"}),_o(yp,{authorLink:h,displayName:u}),y&&_o(Eo,{onClick:()=>a.setExpanded(e.id,!0),title:"Expand replies",children:v}),f&&_o("div",{className:"hyp-u-layout-row--justify-right hyp-u-stretch",children:_o(vp,{annotationCreated:e.created,annotationUpdated:e.updated,annotationUrl:m,withEditedTimestamp:g})})]}),_&&_o("div",{className:"hyp-u-layout-row--align-baseline hyp-u-horizontal-spacing--2 flex-wrap-reverse",children:[_o(ap,{annotation:e}),!t&&Ri(e)&&_o(Do,{name:"highlight",title:"This is a highlight. Click 'edit' to add a note or tag.",classes:"text-tiny text-color-text-light"}),x&&_o(ip,{domain:b.domain,link:w,title:b.titleText})]})]})}),["settings"]);var bp=ci((function({annotation:e,isFocused:t,settings:n={}}){return _o("div",{className:Yr({"is-orphan":Di(e)}),children:_o(Pa,{collapsedHeight:35,inlineControls:!0,overflowThreshold:20,children:_o("blockquote",{className:Yr("p-quoted-text",{"is-focused":t,"p-redacted-content":Di(e)}),dir:"auto",
543
+ lang:"",style:si(["selectionFontFamily"],n),children:Hi(e)})})})}),["settings"]);function wp({onToggleReplies:e,replyCount:t,threadIsCollapsed:n}){const r=`${n?"Show replies":"Hide replies"} (${t})`;return _o(Eo,{onClick:e,title:r,children:r})}var xp=ci((function({annotation:e,hasAppliedFilter:t,isReply:n,onToggleReplies:r,replyCount:o,threadIsCollapsed:i,annotationsService:a}){const s=n&&i,l=hi(),c=e&&!!Hi(e),u=e&&l.isAnnotationFocused(e.$tag),h=e&&l.isSavingAnnotation(e),d=e&&!!l.getDraft(e)&&!h,p=l.profile().userid,f=!h&&!d,g=!n&&!t&&o>0;return _o("article",{className:Yr("hyp-u-vertical-spacing",{"is-collapsed":i,"is-focused":u}),children:[e&&_o(m,{children:[_o(_p,{annotation:e,isEditing:d,replyCount:o,threadIsCollapsed:i}),c&&_o(bp,{annotation:e,isFocused:u}),!s&&!d&&_o(Md,{annotation:e}),d&&_o(rp,{annotation:e})]}),!e&&!s&&_o("div",{children:_o("em",{children:"Message not available."})}),!s&&_o("footer",{children:_o("div",{className:"hyp-u-layout-row",children:[g&&_o(wp,{onToggleReplies:r,replyCount:o,
544
+ threadIsCollapsed:i}),h&&_o("div",{className:"hyp-u-layout-row--justify-right hyp-u-stretch","data-testid":"saving-message",children:"Saving..."}),e&&f&&Mi(e)&&_o(Mo,{classes:"hyp-u-stretch",children:_o(za,{annotation:e,onReply:()=>{e&&Mi(e)&&a.reply(e,p)}})})]})})]})}),["annotationsService"]);var kp=ci((function({annotation:e,api:t,toastMessenger:n}){const r=hi(),o=function(e){return e.moderation?e.moderation.flagCount:null}(e);return null!==o&&(o>0||e.hidden)?_o("div",{className:Yr("flex gap-x-3 bg-grey-1 text-color-text font-semibold","mb-2 ",{"-mt-3 -ml-3 -mr-3":!Ni(e),"-mr-3":Ni(e)}),children:[_o("div",{className:Yr("p-3 text-white",{"bg-red-error":!e.hidden,"bg-grey-6":e.hidden}),children:_o(Do,{name:e.hidden?"hide":"flag"})}),_o("div",{className:"self-center grow",children:[!e.hidden&&_o("span",{children:["Flagged for review by ",o," ",1===o?"user":"users"]}),e.hidden&&_o("span",{children:"Hidden from users"})]}),_o("div",{className:"self-center pr-2",children:_o(Ao,{classes:"py-1 bg-slate-1",
545
+ onClick:e.hidden?()=>{const o=e.id;t.annotation.unhide({id:o}).then((()=>{r.unhideAnnotation(o)})).catch((()=>{n.error("Failed to unhide annotation")}))}:()=>{const o=e.id;t.annotation.hide({id:o}).then((()=>{r.hideAnnotation(o)})).catch((()=>{n.error("Failed to hide annotation")}))},title:e.hidden?"Make this annotation visible to everyone":"Hide this annotationn from non-moderators",variant:"dark",children:e.hidden?"Unhide":"Hide"})})]}):null}),["api","toastMessenger"]);function Sp({annotation:e,...t}){const n=hi(),r=e&&n.isSavingAnnotation(e),o=e&&!!n.getDraft(e)&&!r;return e?_o("div",{className:"Thread__top-annotation-header",children:_o(_p,{annotation:e,isEditing:o,...t})}):null}var Cp=ci((function e({thread:t,threadsService:n}){
546
+ const r=!t.collapsed,o=Ki(t)>0,i=!!t.parent,a=t.collapsed?"collapsed":"expand-menu",s=t.collapsed?"Expand replies":"Collapse replies",l=t.children.filter((e=>Xi(e)>0)),c=hi(),u=c.hasAppliedFilter(),h=co((()=>c.setExpanded(t.id,!!t.collapsed)),[c,t.id,t.collapsed]),d=lo((()=>t.visible&&_o(m,{children:[t.annotation&&_o(kp,{annotation:t.annotation}),_o(xp,{annotation:t.annotation,hasAppliedFilter:u,isReply:!!t.parent,onToggleReplies:h,replyCount:t.replyCount,threadIsCollapsed:t.collapsed})]})),[u,h,t.annotation,t.parent,t.replyCount,t.collapsed,t.visible]);return _o("section",{className:Yr("Thread",{"Thread--reply":t.depth>0,"is-collapsed":t.collapsed}),children:[i&&_o("div",{className:"Thread__collapse",children:_o("div",{className:"Thread__collapse-button-container",children:_o(Co,{classes:"NonResponsiveIconButton",expanded:!t.collapsed,icon:a,title:s,onClick:h,size:"medium",variant:"light"})})}),_o("div",{className:"Thread__content",children:[d,o&&_o(m,{children:[!t.parent&&_o(Sp,{annotation:t.annotation,
547
+ replyCount:t.replyCount,threadIsCollapsed:t.collapsed}),_o("div",{className:"Thread__hidden-toggle-button-container",children:_o(Ao,{onClick:()=>n.forceVisible(t),children:["Show ",Ki(t)," more in conversation"]})})]}),r&&_o("ul",{className:"Thread__children",children:l.map((t=>_o("li",{children:_o(e,{thread:t,threadsService:n})},t.id)))})]})]})}),["threadsService"]);var Ap=ci((function({frameSync:e,thread:t}){const n=hi(),r=t.annotation&&t.annotation.$tag,o=r&&n.isAnnotationFocused(r),i=lo((()=>va((t=>{const n=t?[t]:[];e.focusAnnotations(n)}),10)),[e]),a=co((t=>{e.scrollToAnnotation(t)}),[e]),s=lo((()=>_o(Cp,{thread:t})),[t]);return _o("div",{onClick:e=>{var t;(t=e.target).closest("button")||t.closest("a")||a(r)},onMouseEnter:()=>i(r),onMouseLeave:()=>i(null),className:Yr("ThreadCard p-3",{"is-focused":o}),children:s},t.id)}),["frameSync"]);function Ep(){const e=document.querySelector(".js-thread-list-scroll-root");if(!e)throw new Error("Scroll container is missing");return e}function Tp(e){
548
+ return Math.max(e-e%50,0)}function Np({threads:e}){const[t,n]=ro(0),[r,o]=ro(0);ao((()=>{const e=new ya,t=Ep();n(t.clientHeight),o(Tp(t.scrollTop));const r=va((()=>{n(t.clientHeight),o(Tp(t.scrollTop))}),10,{maxWait:100});return e.add(t,"scroll",r),e.add(window,"resize",r),()=>{e.removeAll(),r.cancel()}}),[]);const[i,a]=ro({}),[s,l]=ro(null),c=e,{offscreenLowerHeight:u,offscreenUpperHeight:h,visibleThreads:d}=lo((()=>function(e,t,n,r,o=_a){const{defaultHeight:i,marginAbove:a,marginBelow:s}=o,l=[];let c=0,u=0,h=0;return e.forEach((e=>{const o=t[e.id]||i;c+o<n-a?u+=o:c<n+r+s?l.push(e):h+=o,c+=o})),{visibleThreads:l,offscreenUpperHeight:u,offscreenLowerHeight:h}}(c,i,r,t)),[c,i,r,t]),p=hi(),m=(()=>{const e=p.unsavedAnnotations();return e.length?e[e.length-1].$tag:null})();return io((()=>{m&&(p.setForcedVisible(m,!0),l(m))}),[p,m]),io((()=>{if(!s)return;const e=c.findIndex((e=>e.id===s));if(-1===e)return;l(null);const t=c.slice(0,e).reduce(((e,t)=>e+(e=>i[e.id]||_a.defaultHeight)(t)),0);Ep().scrollTop=t
549
+ }),[s,c,i]),io((()=>{a((e=>{const t={};for(let{id:n}of d){const r=document.getElementById(n);if(!r)return console.warn("ThreadList could not measure thread. Element not found."),e;const o=ba(r);o!==e[n]&&(t[n]=o)}return 0===Object.keys(t).length?e:{...e,...t}}))}),[d]),_o("div",{children:[_o("div",{style:{height:h}}),d.map((e=>_o("div",{className:"ThreadList__card",id:e.id,children:_o(Ap,{thread:e})},e.id))),_o("div",{style:{height:u}})]})}function Mp({errorType:e,onLoginRequest:t,showClearSelection:n=!1}){const r=hi(),o=r.isLoggedIn();return _o("div",{className:"mb-4",children:_o(Wo,{icon:"restricted",title:"annotation"===e?"Annotation unavailable":"Group unavailable",children:[_o("p",{
550
+ children:o?"group"===e?"The current URL links to a group, but that group cannot be found,\n or you do not have permission to view the annotations in that group.":"The current URL links to an annotation, but that annotation\n cannot be found, or you do not have permission to view it.":`The ${e} associated with the current URL is unavailable.\n You may need to log in to see it.`}),_o("div",{className:"hyp-u-layout-row--justify-right hyp-u-horizontal-spacing",children:[n&&_o(Ao,{variant:o?"primary":void 0,onClick:()=>r.clearSelection(),children:"Show all annotations"}),!o&&_o(Ao,{variant:"primary",onClick:t,children:"Log in"})]})]})})}var Lp=ci((function({loadAnnotationsService:e,onLogin:t}){const n=hi(),r=n.routeParams().id,o=na(),i=n.profile().userid,[a,s]=ro(!1);return io((()=>{s(!1),n.clearAnnotations(),e.loadThread(r).then((e=>{const t=e.filter((e=>0===(e.references||[]).length))[0];t&&(e.forEach((e=>n.setExpanded(e.id,!0))),t.id!==r&&n.highlightAnnotations([r]))})).catch((()=>{s(!0)}))
551
+ }),[r,i,e,n]),_o(m,{children:[a&&_o(Mp,{errorType:"annotation",onLoginRequest:t}),_o(Np,{threads:o.children})]})}),["loadAnnotationsService"]);function zp({actionButton:e,additionalCount:t=0,entitySingular:n="annotation",entityPlural:r="annotations",filterQuery:o,focusDisplayName:i,resultCount:a}){return _o("div",{className:"FilterStatus",children:hi().isLoading()?_o("div",{className:"hyp-u-layout-row--center",children:_o(Ko,{})}):_o("div",{className:"hyp-u-layout-row--align-center",children:[_o("div",{className:"FilterStatus__text",children:[a>0&&_o("span",{children:"Showing "}),_o("span",{className:"filter-facet",children:[a>0?a:"No"," ",1===a?n:r]}),o&&_o("span",{children:[" ","for"," ",_o("span",{className:"filter-facet--pre",children:`'${o}'`})]}),i&&_o("span",{children:[" ","by ",_o("span",{className:"filter-facet",children:i})]}),t>0&&_o("span",{className:"filter-facet--muted",children:[" ","(and ",t," more)"]})]}),_o("div",{children:e})]})})}function Op({filterState:e,rootThread:t}){
552
+ const n=hi(),r=n.directLinkedAnnotationId(),o=n.annotationCount(),i=(t.children||[]).filter((e=>e.annotation&&e.visible)).length-e.selectedCount,a=!e.focusConfigured&&!r?`Show all (${o})`:"Show all",s=_o(Ao,{title:a,variant:"primary",onClick:()=>n.clearSelection(),icon:"cancel",children:a});return _o(zp,{resultCount:e.selectedCount,additionalCount:i,actionButton:s})}function Ip({filterState:e,rootThread:t}){const n=hi(),r=Xi(t)-e.forcedVisibleCount,o=_o(Ao,{icon:"cancel",variant:"primary",title:"Clear search",onClick:()=>n.clearSelection(),children:"Clear search"});return _o(zp,{actionButton:o,additionalCount:e.forcedVisibleCount,entitySingular:"result",entityPlural:"results",filterQuery:e.filterQuery,focusDisplayName:e.focusDisplayName,resultCount:r})}function Pp({filterState:e,rootThread:t}){const n=hi(),r=Xi(t)-e.forcedVisibleCount,o={};e.forcedVisibleCount>0?(o.onClick=()=>n.clearSelection(),o.title="Reset filters"):(o.onClick=()=>n.toggleFocusMode(),
553
+ o.title=e.focusActive?"Show all":`Show only ${e.focusDisplayName}`);const i=e.focusActive?e.focusDisplayName:"",a=_o(Ao,{variant:"primary",...o,children:o.title});return _o(zp,{resultCount:r,actionButton:a,additionalCount:e.forcedVisibleCount,filterQuery:e.filterQuery,focusDisplayName:i})}function Rp(){const e=na(),t=hi(),n=t.focusState(),r=t.forcedVisibleThreads().length,o=t.filterQuery(),i=t.selectedAnnotations().length,a=lo((()=>({filterQuery:o,focusActive:n.active,focusConfigured:n.configured,focusDisplayName:n.displayName,forcedVisibleCount:r,selectedCount:i})),[n,r,o,i]);return a.selectedCount>0?_o(Op,{filterState:a,rootThread:e}):a.filterQuery?_o(Ip,{filterState:a,rootThread:e}):a.focusConfigured?_o(Pp,{filterState:a,rootThread:e}):null}function Dp({onLogin:e}){const t=hi();return _o("div",{className:"LoggedOutMessage",children:[_o("span",{children:["This is a public annotation created with Hypothesis. ",_o("br",{}),"To reply or make your own annotations on this document,"," ",_o("a",{
554
+ className:"LoggedOutMessage__link",href:t.getLink("signup"),target:"_blank",rel:"noopener noreferrer",children:"create a free account"})," ","or"," ",_o(Eo,{classes:"InlineLinkButton InlineLinkButton--underlined",onClick:e,variant:"dark",children:"log in"}),"."]}),_o("div",{className:"LoggedOutMessage__logo",children:_o("a",{href:"https://hypothes.is","aria-label":"Hypothesis homepage",title:"Hypothesis homepage",children:_o(Do,{name:"logo",classes:"w-16 h-16 hyp-u-color--grey-7"})})})]})}function Bp(e,t,n){e.self===e?e.scrollTo(t,n):(e.scrollLeft=t,e.scrollTop=n)}function Fp(e){var t=e._scrollSettings;if(t){var n=t.maxSynchronousAlignments,r=function(e,t){var n,r,o,i,a,s,l,c=e.align,u=e.target.getBoundingClientRect(),h=c&&null!=c.left?c.left:.5,d=c&&null!=c.top?c.top:.5,p=c&&null!=c.leftOffset?c.leftOffset:0,m=c&&null!=c.topOffset?c.topOffset:0,f=h,g=d;if(e.isWindow(t))s=Math.min(u.width,t.innerWidth),l=Math.min(u.height,t.innerHeight),r=u.left+t.pageXOffset-t.innerWidth*f+s*f,
555
+ o=u.top+t.pageYOffset-t.innerHeight*g+l*g,r-=p,o-=m,r=e.align.lockX?t.pageXOffset:r,o=e.align.lockY?t.pageYOffset:o,i=r-t.pageXOffset,a=o-t.pageYOffset;else{s=u.width,l=u.height,n=t.getBoundingClientRect();var v=u.left-(n.left-t.scrollLeft),y=u.top-(n.top-t.scrollTop);r=v+s*f-t.clientWidth*f,o=y+l*g-t.clientHeight*g,r-=p,o-=m,r=Math.max(Math.min(r,t.scrollWidth-t.clientWidth),0),o=Math.max(Math.min(o,t.scrollHeight-t.clientHeight),0),r=e.align.lockX?t.scrollLeft:r,o=e.align.lockY?t.scrollTop:o,i=r-t.scrollLeft,a=o-t.scrollTop}return{x:r,y:o,differenceX:i,differenceY:a}}(t,e),o=Date.now()-t.startTime,i=Math.min(1/t.time*o,1);if(t.endIterations>=n)return Bp(e,r.x,r.y),e._scrollSettings=null,t.end("complete");var a=1-t.ease(i);if(Bp(e,r.x-r.differenceX*a,r.y-r.differenceY*a),o>=t.time)return t.endIterations++,t.scrollAncestor&&Fp(t.scrollAncestor),void Fp(e);!function(e){if("requestAnimationFrame"in window)return window.requestAnimationFrame(e);setTimeout(e,16)}(Fp.bind(null,e))}}function jp(e){return e.self===e
556
+ }function Hp(e){return"pageXOffset"in e||(e.scrollHeight!==e.clientHeight||e.scrollWidth!==e.clientWidth)&&"hidden"!==getComputedStyle(e).overflow}function qp(){return!0}function Up(e){if(e.assignedSlot)return Up(e.assignedSlot);if(e.parentElement)return"BODY"===e.parentElement.tagName?e.parentElement.ownerDocument.defaultView||e.parentElement.ownerDocument.ownerWindow:e.parentElement;if(e.getRootNode){var t=e.getRootNode();if(11===t.nodeType)return t.host}}var $p=function(e,t,n){if(e){"function"==typeof t&&(n=t,t=null),t||(t={}),t.time=isNaN(t.time)?1e3:t.time,t.ease=t.ease||function(e){return 1-Math.pow(1-e,e/2)},t.align=t.align||{};var r=Up(e),o=1,i=t.validTarget||qp,a=t.isScrollable;t.debug&&(console.log("About to scroll to",e),r||console.error("Target did not have a parent, is it mounted in the DOM?"));for(var s=[];r;)if(t.debug&&console.log("Scrolling parent node",r),i(r,o)&&(a?a(r,Hp):Hp(r))&&(o++,s.push(r)),!(r=Up(r))){l("complete");break}return s.reduce(((n,r,o)=>function(e,t,n,r,o){
557
+ var i,a=!t._scrollSettings,s=t._scrollSettings,l=Date.now(),c={passive:!0};function u(e){t._scrollSettings=null,t.parentElement&&t.parentElement._scrollSettings&&t.parentElement._scrollSettings.end(e),n.debug&&console.log("Scrolling ended with type",e,"for",t),o(e),i&&(t.removeEventListener("touchstart",i,c),t.removeEventListener("wheel",i,c))}s&&s.end("canceled");var h=n.maxSynchronousAlignments;return null==h&&(h=3),t._scrollSettings={startTime:l,endIterations:0,target:e,time:n.time,ease:n.ease,align:n.align,isWindow:n.isWindow||jp,maxSynchronousAlignments:h,end:u,scrollAncestor:r},"cancellable"in n&&!n.cancellable||(i=u.bind(null,"canceled"),t.addEventListener("touchstart",i,c),t.addEventListener("wheel",i,c)),a&&Fp(t),i}(e,r,t,s[o+1],l)),null)}function l(e){--o||n&&n(e)}};function Gp({children:e,icon:t="",panelName:n,title:r,onActiveChanged:o}){const i=hi(),a=i.isSidebarPanelOpen(n),s=so(null),l=so(a);io((()=>{l.current!==a&&(l.current=a,a&&s.current&&$p(s.current),"function"==typeof o&&o(a))}),[a,o])
558
+ ;const c=co((()=>{i.toggleSidebarPanel(n,!1)}),[i,n]);return _o(ep,{visible:a,children:_o("div",{ref:s,className:"mb-4",children:_o(Wo,{title:r,icon:t,onClose:c,children:e})})})}function Vp({onLogin:e,onSignUp:t}){return hi().isLoggedIn()?null:_o(Gp,{icon:"restricted",title:"Login needed",panelName:"loginPrompt",children:[_o("p",{children:"Please log in to create annotations or highlights."}),_o(Mo,{children:[_o(Ao,{title:"Sign up",onClick:t,children:"Sign up"}),_o(Ao,{title:"Log in",variant:"primary",onClick:e,children:"Log in"})]})]})}function Wp({children:e,count:t,isWaitingToAnchor:n,isSelected:r,label:o,onSelect:i}){const a=()=>{r||i()},s=t>0?`${o} (${t} available)`:o;return _o(Ao,{classes:Yr("text-color-text","SelectionTab",{"is-selected":r}),onClick:a,onMouseDown:a,pressed:!!r,role:"tab",tabIndex:0,title:s,children:_o(m,{children:[e,t>0&&!n&&_o("span",{className:"text-tiny",style:"position:relative;bottom:3px;left:2px",children:t})]})})}
559
+ var Yp=ci((function({annotationsService:e,isLoading:t,settings:n}){const r=hi(),o=r.selectedTab(),i=r.noteCount(),a=r.annotationCount(),s=r.orphanCount(),l=r.isWaitingToAnchorAnnotations(),c=e=>{r.clearSelection(),r.selectTab(e)},u="annotation"===o&&0===a&&!l,h="note"===o&&0===i;return _o("div",{className:"hyp-u-vertical-spacing--4 SelectionTabs__container",children:[_o("div",{className:"hyp-u-layout-row hyp-u-horizontal-spacing--6 SelectionTabs",role:"tablist",children:[_o(Wp,{count:a,isWaitingToAnchor:l,isSelected:"annotation"===o,label:"Annotations",onSelect:()=>c("annotation"),children:"Annotations"}),_o(Wp,{count:i,isWaitingToAnchor:l,isSelected:"note"===o,label:"Page notes",onSelect:()=>c("note"),children:"Page Notes"}),s>0&&_o(Wp,{count:s,isWaitingToAnchor:l,isSelected:"orphan"===o,label:"Orphans",onSelect:()=>c("orphan"),children:"Orphans"})]}),"note"===o&&n.enableExperimentalNewNoteButton&&_o("div",{className:"hyp-u-layout-row--justify-right",children:_o(Ao,{"data-testid":"new-note-button",
560
+ icon:"add",onClick:()=>e.createPageNote(),variant:"primary",style:si(["ctaBackgroundColor"],n),children:"New note"})}),!t&&h&&_o(No,{classes:"text-center",children:_o("span",{"data-testid":"notes-unavailable-message",children:"There are no page notes in this group."})}),!t&&u&&_o(No,{classes:"text-center",children:_o("span",{"data-testid":"annotations-unavailable-message",children:["There are no annotations in this group.",_o("br",{}),"Create one by selecting some text and clicking the"," ",_o(Do,{classes:"m-0.5 inline -mt-0.5",name:"annotate",title:"Annotate"})," ","button."]})})]})}),["annotationsService","settings"]);var Kp=ci((function({frameSync:e,onLogin:t,onSignUp:n,loadAnnotationsService:r,streamer:o}){
561
+ const i=na(),a=hi(),s=a.focusedGroupId(),l=a.hasAppliedFilter()||a.hasSelectedAnnotations(),c=a.isLoading(),u=a.isLoggedIn(),h=a.directLinkedAnnotationId(),d=h?a.findAnnotationByID(h):void 0,p=d?Wi(d):"annotation",m=a.searchUris(),f=a.hasSidebarOpened(),g=a.profile().userid,v=d&&!1===d.$orphan?d.$tag:null,y=!(c||!h)&&!d,_=a.directLinkedGroupFetchFailed(),b=y||_,w=!b,x=!b&&!l,k=h&&!u&&!y&&!c,S=so(s);io((()=>{if(!S.current||S.current!==s){if(S.current){let e=a.focusState().active;a.clearSelection(),e&&a.toggleFocusMode(!0)}S.current=s}s&&m.length&&r.load({groupId:s,uris:m})}),[a,r,s,g,m]),io((()=>{v?(e.focusAnnotations([v]),e.scrollToAnnotation(v),a.selectTab(p)):d&&a.selectTab(p)}),[p,e,d,v,a]);const C=a.hasFetchedProfile();return io((()=>{C&&(f||u)&&o.connect({applyUpdatesImmediately:!1})}),[C,u,f,o]),_o("div",{children:[_o("h2",{className:"sr-only",children:"Annotations"}),w&&_o(Rp,{}),_o(Vp,{onLogin:t,onSignUp:n}),y&&_o(Mp,{errorType:"annotation",onLoginRequest:t,showClearSelection:!0}),_&&_o(Mp,{
562
+ errorType:"group",onLoginRequest:t}),x&&_o(Yp,{isLoading:c}),_o(Np,{threads:i.children}),k&&_o(Dp,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var Xp=ci((function({api:e,toastMessenger:t}){const n=hi(),r=n.routeParams().q,o=co((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...Si(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return io((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),_o(Np,{threads:na().children})}),["api","toastMessenger"]);class Zp{constructor(e,t,n=window){var r,o,i;const a="N/A";let s=a;e.userid&&(s=e.userid,e.displayName&&(s=`${e.displayName} (${s})`)),this.version="1.1007.0",this.userAgent=n.navigator.userAgent,this.urls=t.map((e=>e.uri)).join(", ")||a,
563
+ this.fingerprint=null!==(r=null===(o=t[0])||void 0===o||null===(i=o.metadata)||void 0===i?void 0:i.documentFingerprint)&&void 0!==r?r:a,this.account=s,this.timestamp=(new Date).toString()}asFormattedString(){return`Version: ${this.version}\nUser Agent: ${this.userAgent}\nURL: ${this.urls}\nFingerprint: ${this.fingerprint}\nAccount: ${this.account}\nDate: ${this.timestamp}\n`}asEncodedURLString(){return encodeURIComponent(this.asFormattedString())}}function Jp(e){const t=R(e);return!(null==t||!t.authority)&&t.authority!==e.authDomain}function Qp({commandName:e,iconName:t}){return _o("span",{className:"whitespace-nowrap",children:[_o(Do,{name:t,classes:Yr("mx-1 -mt-1","text-color-text-light inline")}),_o("em",{children:e})]})}var em=ci((function({settings:e}){const t=!Jp(e);return _o("ol",{className:"list-decimal pl-10 space-y-2",children:[_o("li",{children:["To create an annotation, select text and then select the"," ",_o(Qp,{iconName:"annotate",commandName:"Annotate"})," ","button."]}),_o("li",{
564
+ children:["To create a highlight (",_o(Bo,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/why-are-highlights-private-by-default/",target:"_blank",children:"visible only to you"}),"), select text and then select the"," ",_o(Qp,{iconName:"highlight",commandName:"Highlight"})," ","button."]}),t&&_o("li",{children:["To annotate in a private group, select the group from the groups dropdown. Don't see your group? Ask the group creator to send a"," ",_o(Bo,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/how-to-join-a-private-group/",target:"_blank",children:"join link"}),")."]}),_o("li",{children:["To reply to an annotation, select the"," ",_o(Qp,{iconName:"reply",commandName:"Reply"})," button."]})]})}),["settings"]);var tm=ci((function({toastMessenger:e,versionData:t}){return _o("div",{className:"hyp-u-vertical-spacing",children:[_o("dl",{className:"VersionInfo",children:[_o("dt",{className:"VersionInfo__key",children:"Version"}),_o("dd",{
565
+ className:"VersionInfo__value",children:t.version}),_o("dt",{className:"VersionInfo__key",children:"User Agent"}),_o("dd",{className:"VersionInfo__value",children:t.userAgent}),_o("dt",{className:"VersionInfo__key",children:"URL"}),_o("dd",{className:"VersionInfo__value",children:t.urls}),_o("dt",{className:"VersionInfo__key",children:"Fingerprint"}),_o("dd",{className:"VersionInfo__value",children:t.fingerprint}),_o("dt",{className:"VersionInfo__key",children:"Account"}),_o("dd",{className:"VersionInfo__value",children:t.account}),_o("dt",{className:"VersionInfo__key",children:"Date"}),_o("dd",{className:"VersionInfo__value",children:t.timestamp})]}),_o("div",{className:"hyp-u-layout-row--justify-center",children:_o(Ao,{onClick:()=>{try{Ea(t.asFormattedString()),e.success("Copied version info to clipboard")}catch(t){e.error("Unable to copy version info")}},icon:"copy",children:"Copy version details"})})]})}),["toastMessenger"]);function nm({children:e,onClick:t}){return _o(Eo,{
566
+ classes:"leading-none text-brand",onClick:t,children:[e,_o(Do,{classes:"ml-1",name:"arrow-right"})]})}function rm({linkText:e,url:t}){return _o("div",{className:"flex-1 border-r last-of-type:border-r-0",children:_o(Bo,{href:t,classes:"flex items-center justify-center space-x-2 text-color-text-light text-lg font-medium",target:"_blank",children:[_o("span",{children:e})," ",_o(Do,{name:"external",classes:"w-3 h-3"})]})})}var om=ci((function({auth:e,session:t}){const n=hi(),r=n.frames(),o=n.mainFrame(),i=!!n.profile().preferences.show_sidebar_tutorial,[a,s]=ro("tutorial"),l=lo((()=>{const t=e||{status:"logged-out"},n=[...r].sort(((e,t)=>e===o?-1:t===o?1:0));return new Zp(t,n)}),[e,r,o]),c=`https://web.hypothes.is/get-help/?sys_info=${l.asEncodedURLString()}`,u=(e,t)=>{e.preventDefault(),s(t)};return _o(Gp,{title:"Help",panelName:"help",onActiveChanged:co((e=>{!e&&i&&t.dismissSidebarTutorial()}),[t,i]),children:_o("div",{className:"space-y-4",children:[_o("div",{className:"flex items-center",children:[_o("h3",{
567
+ className:"grow text-lg font-medium","data-testid":"subpanel-title",children:{tutorial:"Getting started",versionInfo:"About this version"}[a]}),"versionInfo"===a&&_o(nm,{onClick:e=>u(e,"tutorial"),children:"Getting started"}),"tutorial"===a&&_o(nm,{onClick:e=>u(e,"versionInfo"),children:"About this version"})]}),_o("div",{className:"border-y py-4",children:["tutorial"===a&&_o(em,{}),"versionInfo"===a&&_o(tm,{versionData:l})]}),_o("div",{className:"flex items-center",children:[_o(rm,{linkText:"Help topics",url:"https://web.hypothes.is/help/"}),_o(rm,{linkText:"New support ticket",url:c})]})]})})}),["session"]),im={exports:{}};function am(){}am.prototype={on:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){var r=this;function o(){r.off(e,o),t.apply(n,arguments)}return o._=t,this.on(e,o,n)},emit:function(e){for(var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),r=0,o=n.length;r<o;r++)n[r].fn.apply(n[r].ctx,t);return this},
568
+ off:function(e,t){var n=this.e||(this.e={}),r=n[e],o=[];if(r&&t)for(var i=0,a=r.length;i<a;i++)r[i].fn!==t&&r[i].fn._!==t&&o.push(r[i]);return o.length?n[e]=o:delete n[e],this}},im.exports=am;var sm=im.exports.TinyEmitter=am;class lm extends Error{constructor(e){super(`Results size exceeds ${e}`)}}function cm(e){return 0===e?50:200}class um extends sm{constructor(e,{getPageSize:t=cm,separateReplies:n=!0,incremental:r=!0,maxResults:o=null,sortBy:i="created",sortOrder:a="asc"}={}){super(),this._searchFn=e,this._getPageSize=t,this._separateReplies=n,this._incremental=r,this._maxResults=o,this._sortBy=i,this._sortOrder=a,this._canceled=!1,this._results=[],this._resultCount=null}async _getPage(e,t,n=0){const r=this._getPageSize(n),o={limit:r,sort:this._sortBy,order:this._sortOrder,_separate_replies:this._separateReplies,...e};t&&(o.search_after=t);try{const t=await this._searchFn(o);if(this._canceled)return;if(null===this._resultCount&&(this._resultCount=t.total,this.emit("resultCount",this._resultCount)),
569
+ this._maxResults&&t.total>this._maxResults)return this.emit("error",new lm(this._maxResults)),void this.emit("end");const i=t.rows.concat(t.replies||[]);this._incremental?this.emit("results",i):this._results=this._results.concat(i);const a=i.length===r,s=i.length>0?i[i.length-1][this._sortBy]:null;a&&s?this._getPage(e,s,n+1):(this._incremental||this.emit("results",this._results),this.emit("end"))}catch(e){if(this._canceled)return;this.emit("error",e),this.emit("end")}}get(e){this._results=[],this._resultCount=null,this._getPage(e)}cancel(){this._canceled=!0,this.emit("end")}}function hm({defaultOption:e,icon:t,onSelect:n,options:r,selectedOption:o,title:i}){const a=[e,...r],s=null!=o?o:e,l=_o("span",{className:"FilterSelect__menu-label",children:[t&&_o(Do,{name:t,classes:"text-xl hyp-u-margin--right--3"}),s.display]});return _o(Qd,{label:l,title:i,contentClass:"FilterSelect__menu",children:a.map((e=>_o(tp,{onClick:()=>n(e),isSelected:e.value===s.value,label:e.display},e.value)))})}function dm(){
570
+ const e=hi(),t=e.getFilter("user"),n=function(){const e=hi(),t=e.allAnnotations(),n=e.defaultAuthority(),r=e.isFeatureEnabled("client_display_names"),o=e.getFocusFilters(),i=oi(e.profile().userid);return lo((()=>{const e={};if(t.forEach((t=>{const o=oi(t.user);e[o]=op(t,ii(t.user,n),r)})),o.user){const t=oi(o.user.value)||o.user.value;e[t]=o.user.display}const a=Object.keys(e).map((t=>({display:t===i?`${e[t]} (Me)`:e[t],value:t})));return a.sort(((e,t)=>i===e.value?-1:i===t.value?1:e.display.localeCompare(t.display))),a}),[t,i,n,r,o.user])}();return _o(hm,{defaultOption:{value:"",display:"Everybody"},icon:"profile",onSelect:t=>e.setFilter("user",t),options:n,selectedOption:t,title:"Filter by user"})}function pm({forcedVisibleCount:e,isFiltered:t,isLoading:n,resultCount:r}){const o=na(),i=n?r:Xi(o),a=o.children.length>0,s=t&&e>0,l=i-e,c=o.children.length;return _o("div",{className:"hyp-u-layout-row NotebookResultCount",children:[n&&_o(Ko,{size:"small"}),!n&&_o("h2",{children:[!a&&_o("strong",{
571
+ children:"No results"}),a&&t&&_o("strong",{children:[l," ",1===l?"result":"results"]}),a&&!t&&_o("strong",{children:[c," ",1===c?"thread":"threads"]})]}),s&&_o("h3",{children:["(and ",e," more)"]}),!t&&a&&_o("h3",{children:["(",i," ",1===i?"annotation":"annotations",")"]})]})}function mm({currentPage:e,onChangePage:t,totalPages:n}){const r=e<n,o=e>1,i=function(e,t,n=5){if(t<=1)return[];const r=new Set([1,e,t]);let o=1;for(;r.size<Math.min(t,n);)e+o<=t&&r.add(e+o),e-o>=1&&r.add(e-o),++o;const i=[];return[...r].sort(((e,t)=>e-t)).forEach(((e,t,n)=>{t>0&&e-n[t-1]>1&&i.push(null),i.push(e)})),i}(e,n),a=(e,n)=>{t(e),null==n||n.blur()};return _o("div",{className:"PaginationNavigation",children:[_o("div",{className:"PaginationNavigation__relative PaginationNavigation__prev",children:o&&_o(Ao,{classes:"PaginationPageButton",icon:"arrow-left",title:"Go to previous page",onClick:t=>a(e-1,t.target),variant:"dark",children:"prev"})}),_o("ul",{className:"PaginationNavigation__pages",children:i.map(((t,n)=>_o("li",{
572
+ children:null===t?_o("div",{className:"PaginationNavigation__gap",children:"..."}):_o(Ao,{classes:"PaginationPageButton",title:`Go to page ${t}`,pressed:t===e,onClick:e=>a(t,e.target),variant:"dark",children:t.toString()},`page-${n}`)},n)))}),_o("div",{className:"PaginationNavigation__relative PaginationNavigation__next",children:r&&_o(Ao,{classes:"PaginationPageButton",icon:"arrow-right",iconPosition:"right",title:"Go to next page",onClick:t=>a(e+1,t.target),variant:"dark",children:"next"})})]})}function fm({currentPage:e,isLoading:t,onChangePage:n,threads:r,pageSize:o=25}){const{paginatedThreads:i,totalPages:a}=lo((()=>{const t=r.filter((e=>Xi(e)>0)),n=(e-1)*o,i=n+o,a=Math.ceil(t.length/o);return{paginatedThreads:t.slice(n,i),totalPages:a}}),[r,e,o]);return _o(m,{children:[_o(Np,{threads:i}),!t&&_o(mm,{currentPage:e,onChangePage:n,totalPages:a})]})}var gm=ci((function({loadAnnotationsService:e,streamer:t}){var n
573
+ ;const r=hi(),o=r.getFilterValues(),i=r.focusedGroup(),a=r.forcedVisibleThreads().length,s=r.hasAppliedFilter(),l=r.isLoading(),c=r.annotationResultCount(),u=r.pendingUpdateCount(),h=na(),d=null!==(n=null==i?void 0:i.name)&&void 0!==n?n:"",p=(null==i?void 0:i.id)||r.directLinkedGroupId(),m=so(1),[f,g]=ro(1),[v,y]=ro(!1),_=e=>{e instanceof lm&&y(!0)},b=r.hasFetchedProfile();io((()=>{b&&t.connect({applyUpdatesImmediately:!1})}),[b,t]),io((()=>{r.setSortKey("Newest"),p&&e.load({groupId:p,sortBy:"updated",sortOrder:"desc",maxResults:5e3,onError:_,streamFilterBy:"group"})}),[e,p,r]);const w=e=>{g(e)};io((()=>{w(1)}),[o,i]);const x=so(null);ao((()=>{f!==m.current&&(x.current&&$p(x.current),m.current=f)}),[f]);const k=`Show ${u} new or updated ${u>1?"annotations":"annotation"}`;return _o("div",{className:"NotebookView",children:[_o("header",{className:"NotebookView__heading",ref:x,children:_o("h1",{className:"NotebookView__group-name",children:d})}),_o("div",{className:"NotebookView__filters",children:_o(dm,{})
574
+ }),_o("div",{className:"NotebookView__results hyp-u-layout-row--align-center text-lg font-medium",children:[u>0&&!s&&_o(Co,{icon:"refresh",onClick:()=>t.applyPendingUpdates(),variant:"primary",title:k}),_o(pm,{forcedVisibleCount:a,isFiltered:s,isLoading:l,resultCount:c})]}),_o("div",{className:"NotebookView__items",children:[v&&_o("div",{className:"NotebookView__messages",children:_o(Wo,{title:"Too many results to show",children:["This preview of the Notebook can show"," ",_o("strong",{children:["up to ",5e3," results"]})," at a time (there are"," ",c," to show here)."," ",_o("a",{href:"mailto:support@hypothes.is?subject=Hypothesis%20Notebook&body=Please%20notify%20me%20when%20the%20Hypothesis%20Notebook%20is%20updated%20to%20support%20more%20than%205000%20annotations",children:"Contact us"})," ","if you would like to be notified when support for more annotations is available."]})}),_o(fm,{currentPage:f,isLoading:l,onChangePage:w,threads:h.children})]})]})}),["loadAnnotationsService","streamer"])
575
+ ;var vm=ci((function({toastMessenger:e}){const t=hi(),n=t.mainFrame(),r=t.focusedGroup(),o=`Share Annotations in ${r&&r.name||"..."}`,i=r&&n,a=i&&(s=n.uri,l=r.id,wa(s)?`https://hyp.is/go?url=${encodeURIComponent(s)}&group=${l}`:null);var s,l;return _o(Gp,{title:o,panelName:"shareGroupAnnotations",children:[!i&&_o("div",{className:"flex flex-row items-center justify-center",children:_o(Ko,{})}),i&&_o("div",{className:"text-color-text-light space-y-3",children:a?_o(m,{children:[_o("div",{className:"text-color-text font-medium","data-testid":"sharing-intro",children:"private"===r.type?_o("p",{children:"Use this link to share these annotations with other group members:"}):_o("p",{children:"Use this link to share these annotations with anyone:"})}),_o("div",{children:_o(Jo,{children:[_o(Zo,{"aria-label":"Use this URL to share these annotations",type:"text",value:a,readOnly:!0}),_o(Co,{icon:"copy",onClick:()=>{try{Ea(a),e.success("Copied share link to clipboard")}catch(t){e.error("Unable to copy link")}},
576
+ title:"Copy share link",variant:"dark"})]})}),_o("p",{"data-testid":"sharing-details",children:["private"===r.type?_o("span",{children:["Annotations in the private group"," ",_o("em",{children:r.name})," are only visible to group members."]}):_o("span",{children:["Anyone using this link may view the annotations in the group"," ",_o("em",{children:r.name}),"."]})," ",_o("span",{children:["Private (",_o(Do,{name:"lock",classes:"inline -mt-0.5"})," ",_o("em",{children:"Only Me"}),") annotations are only visible to you."]})]}),_o("div",{className:"text-[24px]",children:_o(Na,{shareURI:a})})]}):_o("p",{"data-testid":"no-sharing",children:"These annotations cannot be shared because this document is not available on the web."})})]})}),["toastMessenger"]);function ym({message:e,onDismiss:t}){const n=e.type.charAt(0).toUpperCase()+e.type.slice(1),r="notice"===e.type?"cancel":e.type;return _o("li",{className:Yr("toast-message-container",{"is-dismissed":e.isDismissed}),onClick:()=>t(e.id),children:_o("div",{
577
+ className:Yr("toast-message",`toast-message--${e.type}`),children:[_o("div",{className:"toast-message__type",children:_o(Do,{name:r,classes:"toast-message__icon"})}),_o("div",{className:"toast-message__message",children:[_o("strong",{children:[n,": "]}),e.message,e.moreInfoURL&&_o("div",{className:"toast-message__link",children:_o("a",{href:e.moreInfoURL,onClick:e=>e.stopPropagation(),target:"_new",children:"More info"})})]})]})})}var _m=ci((function({toastMessenger:e}){return _o("div",{children:_o("ul",{"aria-live":"polite","aria-relevant":"additions",className:"ToastMessages",children:hi().getToastMessages().map((t=>_o(ym,{message:t,onDismiss:t=>e.dismiss(t)},t.id)))})})}),["toastMessenger"]);function bm(e){return e.organization&&e.organization.name}function wm(e){const t={};return e.forEach((e=>{if("object"!=typeof e.organization)return;const n="__default__"===(r=e.organization).id?"__default__":`${r.name.toLowerCase()}${r.id}`;var r;void 0===t[n]&&(t[n]=Object.assign({},e.organization),t[n].groups=[]),
578
+ function(e,t){const n=Object.assign({},e),r=t.groups;!r.length&&e.organization.logo&&(n.logo=e.organization.logo),r.push(n)}(e,t[n])})),t}function xm(e){const t=wm(e),n=[],r=[];return Object.keys(t).sort().forEach((e=>{"__default__"===e?n.push(...t[e].groups):r.push(...t[e].groups)})),n.length&&r.push(...n),r}function km({heading:e,children:t}){return _o(m,{children:[e&&_o("h2",{className:"MenuSection__heading",children:e}),_o("ul",{className:"MenuSection__content",children:x(t).map((e=>_o("li",{children:e},e.key)))})]})}var Sm=ci((function({isExpanded:e,group:t,groups:n,onExpand:r,toastMessenger:o}){const i=t.links.html,a=i||t.canLeave,s=t.scopes&&!t.scopes.enforced||t.isScopedToUri,l=hi(),c=l.focusedGroupId(),u=t.id===c,h=t=>{t.stopPropagation(),t.preventDefault(),r(!e)},d="private"===t.type?"Copy invite link":"Copy activity link";return _o(tp,{icon:t.logo||"blank",iconAlt:bm(t),isDisabled:!s,isExpanded:!!a&&e,isSelected:u,isSubmenuVisible:a?e:void 0,label:t.name,onClick:s?()=>{
579
+ l.clearDirectLinkedGroupFetchFailed(),l.clearDirectLinkedIds(),n.focus(t.id)}:h,onToggleSubmenu:h,submenu:_o(m,{children:[_o("ul",{children:[i&&_o("li",{children:_o(tp,{href:i,icon:"external",isSubmenuItem:!0,label:"View group activity"})}),i&&_o("li",{children:_o(tp,{onClick:()=>(e=>{try{Ea(e),o.success(`Copied link for "${t.name}"`)}catch(e){o.error("Unable to copy link")}})(i),icon:"copy",isSubmenuItem:!0,label:d})}),t.canLeave&&_o("li",{children:_o(tp,{icon:"leave",isSubmenuItem:!0,label:"Leave group",onClick:async()=>{const e=`Are you sure you want to leave the group "${t.name}"?`;await ni({title:"Leave group?",message:e,confirmAction:"Leave"})&&n.leave(t.id)}})})]}),!s&&_o("p",{className:"GroupListItem__footer",children:"This group is restricted to specific URLs."})]})})}),["groups","toastMessenger"]);function Cm({expandedGroup:e,onExpandGroup:t,groups:n,heading:r}){return _o(km,{heading:r,children:n.map((n=>_o(Sm,{isExpanded:n===e,onExpand:e=>t(e?n:null),group:n},n.id)))})}
580
+ var Am=ci((function({settings:e}){const t=hi(),n=t.getCurrentlyViewingGroups(),r=t.getFeaturedGroups(),o=t.getMyGroups(),i=t.focusedGroup(),a=t.profile().userid,s=lo((()=>xm(o)),[o]),l=lo((()=>xm(r)),[r]),c=lo((()=>xm(n)),[n]),u=t.defaultAuthority(),h=a&&!ii(a,u),d=t.getLink("groups.new"),[p,m]=ro(null);let f;if(i){const t=i.organization.logo||function(e){const t=R(e);return t&&t.icon?t.icon:null}(e)||"",n=bm(i)?bm(i):"";f=_o("span",{className:"GroupList__menu-label",children:[t&&_o("img",{className:"GroupList__menu-icon",src:t,alt:n}),i.name]})}else f=_o("span",{children:"…"});return!!Jp(e)&&n.length+r.length+o.length<2?f:_o(Qd,{align:"left",contentClass:"GroupList__content",label:f,onOpenChanged:()=>m(null),title:i?`Select group (now viewing: ${i.name})`:"Select group",children:[c.length>0&&_o(Cm,{expandedGroup:p,onExpandGroup:m,heading:"Currently Viewing",groups:c}),l.length>0&&_o(Cm,{expandedGroup:p,onExpandGroup:m,heading:"Featured Groups",groups:l}),s.length>0&&_o(Cm,{expandedGroup:p,onExpandGroup:m,
581
+ heading:"My Groups",groups:s}),h&&_o(tp,{icon:"add",href:d,label:"New private group"})]})}),["settings"]);function Em({alwaysExpanded:e,query:t,onSearch:n}){const r=hi().isLoading(),o=so(),[i,a]=ro(t),[s,l]=ro(t);return t!==i&&(l(t),a(t)),_o("form",{action:"#",className:"SearchInput__form",name:"searchForm",onSubmit:e=>{e.preventDefault(),(o.current.value||i)&&n(o.current.value)},children:[_o("input",{"aria-label":"Search",className:Yr("SearchInput__input",{"is-expanded":e||t}),dir:"auto",type:"text",name:"query",placeholder:r?"Loading…":"Search…",disabled:r,ref:o,value:s||"",onInput:e=>l(e.target.value)}),!r&&_o("div",{className:"SearchInput__button-container",children:_o(Co,{icon:"search",onClick:()=>o.current.focus(),size:"small",title:"Search annotations"})}),r&&_o("div",{style:"margin:0.5em 0",children:_o(Ko,{size:"small"})})]})}function Tm(){const e=hi(),t=e.sortKey(),n=e.sortKeys().map((n=>_o(tp,{label:n,onClick:()=>e.setSortKey(n),isSelected:n===t},n))),r=_o("span",{className:"TopBar__menu-label",
582
+ children:_o(Do,{name:"sort",classes:"TopBar__menu-icon"})});return _o("div",{className:"SortMenu",children:_o(Qd,{label:r,title:`Sort by ${t}`,align:"right",menuIndicator:!1,children:n})})}var Nm=ci((function({router:e}){return _o(Em,{query:hi().routeParams().q,onSearch:t=>{e.navigate("stream",{q:t})},alwaysExpanded:!0})}),["router"]);var Mm=ci((function({auth:e,frameSync:t,onLogout:n,settings:r}){const o=hi(),i=o.defaultAuthority(),a=ii(e.userid,i),s=R(r),l=o.isFeatureEnabled("notebook_launch"),[c,u]=ro(!1),h=e=>s&&!!s[e],d=!a||h("onProfileRequestProvided"),p=!a||h("onLogoutRequestProvided"),m=()=>{t.notifyHost("openNotebook",o.focusedGroupId())},f=()=>a&&t.notifyHost("profileRequested"),g=(()=>{const t={};return d&&(a||(t.href=o.getLink("user",{user:e.username})),t.onClick=f),t})(),v=_o("span",{className:"TopBar__menu-label",children:_o(Do,{name:"profile",classes:"TopBar__menu-icon"})});return _o("div",{className:"UserMenu",onKeyDown:e=>{"n"===e.key&&(m(),u(!1))},children:_o(Qd,{label:v,title:e.displayName,
583
+ align:"right",open:c,onOpenChanged:u,children:[_o(km,{children:[_o(tp,{label:e.displayName,isDisabled:!d,...g}),!a&&_o(tp,{label:"Account settings",href:o.getLink("account.settings")}),l&&_o(tp,{label:"Open notebook",onClick:()=>m()})]}),p&&_o(km,{children:_o(tp,{label:"Log out",onClick:n})})]})})}),["frameSync","settings"]);var Lm=ci((function({auth:e,frameSync:t,isSidebar:n,onLogin:r,onLogout:o,onSignUp:i,settings:a,streamer:s}){const l=!Jp(a),c=si(["accentColor"],a),u=hi(),h=u.filterQuery(),d=u.pendingUpdateCount(),p=u.isSidebarPanelOpen("help"),f=u.isSidebarPanelOpen("shareGroupAnnotations"),g=()=>{const e=R(a);e&&e.onHelpRequestProvided?t.notifyHost("helpRequested"):u.toggleSidebarPanel("help")},v=_o(m,{children:["unknown"===e.status&&_o("span",{className:"TopBar__login-links",children:""}),"logged-out"===e.status&&_o("span",{className:"TopBar__login-links text-lg font-medium hyp-u-horizontal-spacing--2",children:[_o(Eo,{classes:"InlineLinkButton",onClick:i,style:c,variant:"primary",children:"Sign up"
584
+ }),_o("div",{children:"/"}),_o(Eo,{classes:"InlineLinkButton",onClick:r,style:c,variant:"primary",children:"Log in"})]}),"logged-in"===e.status&&_o(Mm,{auth:e,onLogout:o})]});return _o("div",{className:"TopBar",children:[!n&&_o("div",{className:"TopBar__inner content",children:[_o(Nm,{}),_o("div",{className:"hyp-u-stretch"}),_o(Co,{icon:"help",expanded:p,onClick:g,size:"small",title:"Help"}),v]}),n&&_o("div",{className:"TopBar__inner content",children:[_o(Am,{}),_o("div",{className:"hyp-u-stretch"}),d>0&&_o(Co,{icon:"refresh",onClick:()=>s.applyPendingUpdates(),size:"small",variant:"primary",title:`Show ${d} new/updated ${1===d?"annotation":"annotations"}`}),_o(Em,{query:h||null,onSearch:u.setFilterQuery}),_o(Tm,{}),l&&_o(Co,{icon:"share",expanded:f,onClick:()=>{u.toggleSidebarPanel("shareGroupAnnotations")},size:"small",title:"Share annotations on this page"}),_o(Co,{icon:"help",expanded:p,onClick:g,size:"small",title:"Help"}),v]})]})}),["frameSync","settings","streamer"])
585
+ ;var zm=ci((function({auth:e,frameSync:t,settings:n,session:r,toastMessenger:o}){const i=hi(),a=i.hasFetchedProfile(),s=i.profile(),l=i.route(),c=lo((()=>a?function(e){const t=ri(e.userid);if(t&&e.userid){let n=t.username;return e.user_info&&e.user_info.display_name&&(n=e.user_info.display_name),{status:"logged-in",displayName:n,userid:e.userid,username:t.username}}return{status:"logged-out"}}(s):{status:"unknown"}),[a,s]),u=lo((()=>si(["appBackgroundColor"],n)),[n]),h="clean"===n.theme,d="sidebar"===l;io((()=>{(function(e,t,n){const r="object"==typeof t.preferences&&!!t.preferences.show_sidebar_tutorial,o=R(n)||{onHelpRequestProvided:!1};return e&&!o.onHelpRequestProvided&&r})(d,s,n)&&i.openSidebarPanel("help")}),[d,s,n,i]);const p=async()=>{if(R(n))t.notifyHost("loginRequested");else try{await e.login(),i.closeSidebarPanel("loginPrompt"),i.clearGroups(),r.reload()}catch(e){o.error(e.message)}},m=()=>{R(n)?t.notifyHost("signupRequested"):window.open(i.getLink("signup"))};return _o("div",{
586
+ className:Yr("HypothesisApp","js-thread-list-scroll-root",{"theme-clean":h,"HypothesisApp--notebook":"notebook"===l}),style:u,children:["notebook"!==l&&_o(Lm,{auth:c,onLogin:p,onSignUp:m,onLogout:async()=>{await(async()=>{const e=i.countDrafts();if(0===e)return!0;let t="";return 1===e?t="You have an unsaved annotation.\nDo you really want to discard this draft?":e>1&&(t="You have "+e+" unsaved annotations.\nDo you really want to discard these drafts?"),ni({title:"Discard drafts?",message:t,confirmAction:"Discard"})})()&&(i.clearGroups(),i.removeAnnotations(i.unsavedAnnotations()),i.discardAllDrafts(),R(n)?t.notifyHost("logoutRequested"):r.logout())},isSidebar:d}),_o("div",{className:"HypothesisApp__content",children:[_o(_m,{}),_o(om,{auth:"logged-in"===c.status?c:{}}),_o(vm,{}),l&&_o("main",{children:["annotation"===l&&_o(Lp,{onLogin:p}),"notebook"===l&&_o(gm,{}),"stream"===l&&_o(Xp,{}),"sidebar"===l&&_o(Kp,{onLogin:p,onSignUp:m})]})]})]})}),["auth","frameSync","session","settings","toastMessenger"])
587
+ ;function Om({error:e}){return _o("div",{className:"LaunchErrorPanel",children:_o(Wo,{title:"Unable to start Hypothesis",children:e.message})})}class Im{constructor(e,t){this._api=e,this._store=t}_applyDraftChanges(e){const t={},n=this._store.getDraft(e);return n&&(t.tags=n.tags,t.text=n.text,t.permissions=n.isPrivate?xa(e.user):ka(e.user,e.group)),{...e,...t}}_initialize(e,t=new Date){const n=this._store.getDefault("annotationPrivacy"),r=this._store.focusedGroupId(),o=this._store.profile();if(!r)throw new Error("Cannot create annotation without a group");const i=o.userid,a=o.user_info,s="s:"+H(8),l=Object.assign({created:t.toISOString(),group:r,permissions:Sa(i,r,n),tags:[],text:"",updated:t.toISOString(),user:i,user_info:a,$tag:s,hidden:!1,links:{},document:{title:""}},e);return Ri(l)&&(l.permissions=xa(i)),l}create(e,t=new Date){const n=this._initialize(e,t);this._store.addAnnotations([n]),this._store.deleteNewAndEmptyDrafts(),Ri(n)||this._store.createDraft(n,{tags:n.tags,text:n.text,isPrivate:!zi(n)}),
586
588
  Bi(n)?this._store.selectTab("note"):Fi(n)&&this._store.selectTab("annotation"),(n.references||[]).forEach((e=>{this._store.setExpanded(e,!0)}))}createPageNote(){const e=this._store.mainFrame();if(!this._store.isLoggedIn())return void this._store.openSidebarPanel("loginPrompt");if(!e)return;const t={target:[],uri:e.uri};this.create(t)}async delete(e){await this._api.annotation.delete({id:e.id}),this._store.removeAnnotations([e])}async flag(e){await this._api.annotation.flag({id:e.id}),this._store.updateFlagStatus(e.id,!0)}reply(e,t){const n={group:e.group,permissions:zi(e)?ka(t,e.group):xa(t),references:(e.references||[]).concat(e.id),target:[{source:e.target[0].source}],uri:e.uri};this.create(n)}async save(e){let t;const n=this._applyDraftChanges(e);let r;t=Mi(e)?this._api.annotation.update({id:e.id},n):this._api.annotation.create({},n),this._store.annotationSaveStarted(e);try{r=await t}finally{this._store.annotationSaveFinished(e)}return Object.keys(e).forEach((t=>{"$"===t[0]&&(r[t]=e[t])})),
587
- this._store.removeDraft(e),this._store.addAnnotations([r]),r}}Om.$inject=["api","store"];class Im extends Error{constructor(e,t,n=""){let r="Network request failed";t&&(r+=` (${t.status})`),n&&(r+=`: ${n}`),super(r),this.url=e,this.response=t,this.reason=n}}async function Pm(e,t){let n,r;try{n=await fetch(e,t)}catch(t){throw new Im(e,null,t.message)}if(204===n.status)return null;try{r=await n.json()}catch(t){throw new Im(e,n,"Failed to parse response")}var o;if(!n.ok)throw new Im(e,n,null===(o=r)||void 0===o?void 0:o.reason);return r}function Rm(e,t){const n={};for(const r in t)if(t.hasOwnProperty(r)){const o=t[r],i=":"+r;-1!==e.indexOf(i)?e=e.replace(i,encodeURIComponent(String(o))):n[r]=o}return{url:e,unusedParams:n}}function Dm(e){const t={};for(const n in e)e.hasOwnProperty(n)&&"$"!==n[0]&&(t[n]=e[n]);return t}class Bm{constructor(e,t,n){const r=e.routes();this._clientId=null;const o=()=>this._clientId,i=e=>function(e,t,{getAccessToken:n,getClientId:r,onRequestStarted:o,onRequestFinished:i}){
588
- return async(a,s)=>{o();try{const[o,l]=await Promise.all([e,n()]),c=function(e,t){let n=e;return t.split(".").forEach((e=>{n=n[e]})),n}(o,t),u={"Content-Type":"application/json","Hypothesis-Client-Version":"1.1006.0"};l&&(u.Authorization="Bearer "+l);const h=r();h&&(u["X-Client-Id"]=h);const{url:d,unusedParams:p}=Rm(c.url,a),m=new URL(d);for(let[e,t]of Object.entries(p)){Array.isArray(t)||(t=[t]);for(let n of t)null!=n&&m.searchParams.append(e,n.toString())}return await Pm(m.toString(),{body:s?JSON.stringify(Dm(s)):null,headers:u,method:c.method})}finally{i()}}}(r,e,{getAccessToken:t.getAccessToken,getClientId:o,onRequestStarted:n.apiRequestStarted,onRequestFinished:n.apiRequestFinished});this.search=i("search"),this.annotation={create:i("annotation.create"),delete:i("annotation.delete"),get:i("annotation.read"),update:i("annotation.update"),flag:i("annotation.flag"),hide:i("annotation.hide"),unhide:i("annotation.unhide")},this.group={member:{delete:i("group.member.delete")},read:i("group.read")},
589
- this.groups={list:i("groups.read")},this.profile={groups:{read:i("profile.groups.read")},read:i("profile.read"),update:i("profile.update")}}setClientId(e){this._clientId=e}}Bm.$inject=["apiRoutes","auth","store"];var Fm={};function jm(e,t){"boolean"==typeof t&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var Hm=jm;jm.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},jm.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},jm.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime()
590
- ;if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(void 0===n){if(!this._cachedTimeouts)return!1;this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1)}var r=this;return this._timer=setTimeout((function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout((function(){r._operationTimeoutCb(r._attempts)}),r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)}),n),this._options.unref&&this._timer.unref(),!0},jm.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){n._operationTimeoutCb()}),n._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},jm.prototype.try=function(e){
591
- console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},jm.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},jm.prototype.start=jm.prototype.try,jm.prototype.errors=function(){return this._errors},jm.prototype.attempts=function(){return this._attempts},jm.prototype.mainError=function(){if(0===this._errors.length)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var o=this._errors[r],i=o.message,a=(e[i]||0)+1;e[i]=a,a>=n&&(t=o,n=a)}return t},function(e){var t=Hm;e.operation=function(n){var r=e.timeouts(n);return new t(r,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<t.retries;o++)r.push(this.createTimeout(o,t))
592
- ;return e&&e.forever&&!r.length&&r.push(this.createTimeout(o,t)),r.sort((function(e,t){return e-t})),r},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*Math.max(t.minTimeout,1)*Math.pow(t.factor,e));return r=Math.min(r,t.maxTimeout)},e.wrap=function(t,n,r){if(n instanceof Array&&(r=n,n=null),!r)for(var o in r=[],t)"function"==typeof t[o]&&r.push(o);for(var i=0;i<r.length;i++){var a=r[i],s=t[a];t[a]=function(r){var o=e.operation(n),i=Array.prototype.slice.call(arguments,1),a=i.pop();i.push((function(e){o.retry(e)||(e&&(arguments[0]=o.mainError()),a.apply(this,arguments))})),o.attempt((function(){r.apply(t,i)}))}.bind(t,s),t[a].options=n}}}(Fm);var qm=Fm;function Um(e,t){return new Promise(((n,r)=>{const o=qm.operation(t);o.attempt((async()=>{try{const t=await e();o.retry(),n(t)}catch(e){o.retry(e)||r(e)}}))}))}function $m(e){return Um((()=>Pm(e)))}class Gm{constructor(e){this._apiUrl=e.apiUrl,this._routeCache=null,this._linkCache=null}routes(){
593
- return this._routeCache||(this._routeCache=$m(this._apiUrl).then((e=>e.links))),this._routeCache}links(){return this._linkCache||(this._linkCache=this.routes().then((e=>$m(e.links.url)))),this._linkCache}}Gm.$inject=["settings"];class Vm extends Error{constructor(e,t){super(e),this.cause=t}}class Wm{constructor(e){this.clientId=e.clientId,this.tokenEndpoint=e.tokenEndpoint,this.authorizationEndpoint=e.authorizationEndpoint,this.revokeEndpoint=e.revokeEndpoint}exchangeAuthCode(e){return this._getAccessToken({client_id:this.clientId,grant_type:"authorization_code",code:e})}exchangeGrantToken(e){return this._getAccessToken({grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:e})}refreshToken(e){return this._getAccessToken({grant_type:"refresh_token",refresh_token:e})}async revokeToken(e){try{await this._formPost(this.revokeEndpoint,{token:e})}catch(e){throw new Vm("Failed to revoke access token",e)}}authorize(e,t){const n=H(16),r=new Promise(((t,r)=>{e.addEventListener("message",(function o(i){
594
- "object"==typeof i.data&&i.data.state===n&&("authorization_response"===i.data.type&&t(i.data),"authorization_canceled"===i.data.type&&r(new Error("Authorization window was closed")),e.removeEventListener("message",o))}))})),o=new URL(this.authorizationEndpoint);return o.searchParams.set("client_id",this.clientId),o.searchParams.set("origin",e.location.origin),o.searchParams.set("response_mode","web_message"),o.searchParams.set("response_type","code"),o.searchParams.set("state",n),t.location=o.toString(),r.then((e=>e.code))}async _formPost(e,t){const n=new URLSearchParams;for(let[e,r]of Object.entries(t))n.set(e,r);n.sort();return Pm(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()})}async _getAccessToken(e){let t;try{t=await this._formPost(this.tokenEndpoint,e)}catch(e){throw new Vm("Failed to fetch access token",e)}return{accessToken:t.access_token,expiresAt:Date.now()+1e3*(t.expires_in-10),refreshToken:t.refresh_token}}static openAuthPopupWindow(e){
595
- const t=`left=${e.screen.width/2-237.5},top=${e.screen.height/2-215},width=475,height=430`,n=e.open("about:blank","Log in to Hypothesis",t);if(!n)throw new Error("Failed to open login window");return n}}class Ym extends am{constructor(e,t,n,r,o){let i,a,s;super();const l=(c="token",u=r.apiUrl,new URL(c,u).href);var c,u;function h(){let e=new URL(r.apiUrl).hostname;return e=e.replace(/\./g,"%2E"),`hypothesis.oauth.${e}.token`}function d(e){n.setObject(h(),e)}const p=async()=>{if(s)return s;const e=await t.links();return s=new Wm({clientId:r.oauthClientId,authorizationEndpoint:e["oauth.authorize"],revokeEndpoint:e["oauth.revoke"],tokenEndpoint:l}),s},m=()=>{var e;return null===(e=R(r))||void 0===e?void 0:e.grantToken},f=async()=>{if(!a){const e=m();void 0!==e?a=e?p().then((t=>t.exchangeGrantToken(e))).catch((e=>{var t;throw t="You must reload the page to annotate.",o.error(`Hypothesis login lost: ${t}`,{autoDismiss:!1}),e})):Promise.resolve(null):i?(a=(async e=>{const t=await p(),n=await t.exchangeAuthCode(e)
596
- ;return d(n),n})(i),i=null):a=Promise.resolve(function(){const e=n.getObject(h());return e&&"string"==typeof e.accessToken&&"string"==typeof e.refreshToken&&"number"==typeof e.expiresAt?{accessToken:e.accessToken,refreshToken:e.refreshToken,expiresAt:e.expiresAt}:null}())}const e=a,t=await a;if(!t)return null;if(e!==a)return f();if(Date.now()>t.expiresAt){const e=m();return a=(async(e,t)=>{const n=await p();let r;try{if(r=await n.refreshToken(e),Date.now()>r.expiresAt)throw new Error("Refreshed token expired in the past")}catch{return null}return t.persist&&d(r),r})(t.refreshToken,{persist:void 0===e}),f()}return t.accessToken};(()=>{e.addEventListener("storage",(({key:e})=>{e===h()&&(a=null,this.emit("oauthTokensChanged"))}))})(),this.login=async function(){const t=Wm.openAuthPopupWindow(e),n=await p(),r=await n.authorize(e,t);i=r,a=null},this.logout=async function(){const[e,t]=await Promise.all([a,p()]);e&&await t.revokeToken(e.accessToken),a=Promise.resolve(null),n.removeItem(h())},this.getAccessToken=f}}
597
- Ym.$inject=["$window","apiRoutes","localStorage","settings","toastMessenger"];class Km{constructor(e,t){this._annotationsService=e,this._store=t,this._saving=new Set,this._failed=new Set}init(){const e=e=>!this._saving.has(e)&&!this._failed.has(e);this._store.subscribe((()=>{this._store.newHighlights().forEach((t=>{const n=t.$tag;e(n)&&(this._saving.add(n),Um((()=>this._annotationsService.save(t))).catch((()=>{this._failed.add(n)})).finally((()=>{this._saving.delete(n)})))}))}))}isSaving(){return this._saving.size>0}}Km.$inject=["annotationsService","store"];var Xm=function(e,t,n,r){var o=n?n.call(r,e,t):void 0;if(void 0!==o)return!!o;if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(var s=Object.prototype.hasOwnProperty.bind(t),l=0;l<i.length;l++){var c=i[l];if(!s(c))return!1;var u=e[c],h=t[c];if(!1===(o=n?n.call(r,u,h,c):void 0)||void 0===o&&u!==h)return!1}return!0};function Zm(e,t,n){
598
- const r=Array.isArray(t),o=()=>r?t.map((e=>e())):t();let i=o();return e((()=>{const e=o();if(r?Xm(e,i):e===i)return;const t=i;i=e,n(e,t)}))}class Jm{constructor(e,t){this._frameSync=e,this._store=t}init(){const e=()=>this._store.profile().features;Zm(this._store.subscribe,[e,()=>this._store.frames()],(()=>{this._frameSync.notifyHost("featureFlagsUpdated",e()||{})}))}}function Qm(e,t){return!!function(e){if(null===e||"object"!=typeof e)return!1;for(let t of["frame1","frame2","type","requestId"])if("string"!=typeof e[t])return!1;return!0}(e)&&JSON.stringify(e,Object.keys(t).sort())===JSON.stringify(t,Object.keys(t).sort())}Jm.$inject=["frameSync","store"];class ef{constructor({hostFrame:e,source:t}){this._hostFrame=e,this._source=t,this._listeners=new ya}destroy(){this._listeners.removeAll()}async discover(e){let t=!1;if(("guest"===this._source&&"host"===e||"guest"===this._source&&"sidebar"===e||"sidebar"===this._source&&"host"===e||"notebook"===this._source&&"sidebar"===e)&&(t=!0),
599
- !t)throw new Error("Invalid request of channel/port");const n=H(6);return new Promise(((t,r)=>{const o=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:e,type:"request",requestId:n},"*")},i=setInterval(o,250),a=setTimeout((()=>{clearInterval(i),r(new Error(`Unable to establish ${this._source}-${e} communication channel`))}),2e4),s=this._listeners.add(window,"message",(r=>{const{data:o,ports:l}=r;Qm(o,{frame1:this._source,frame2:e,type:"offer",requestId:n})&&(clearInterval(i),clearTimeout(a),this._listeners.remove(s),t(l[0]))}));o()}))}}function tf(e,t,n=[],r=-1){e.postMessage({protocol:"frame-rpc",version:"1.0.0",arguments:n,method:t,sequence:r})}class nf{constructor({userAgent:e=navigator.userAgent,currentWindow:t=window}={}){this._port=null,this._methods=new Map,this._sequence=1,this._callbacks=new Map,this._listeners=new ya,this._listeners.add(t,"unload",(()=>{this._port&&(tf(this._port,"close"),t!==t.parent&&function(e){const t=e.match(/\bAppleWebKit\/([0-9]+)\b/)
600
- ;return!!t&&!(parseInt(t[1])<=537)}(e)&&t.parent.postMessage({type:"hypothesisPortClosed"},"*",[this._port]))})),this._pendingCalls=[],this._receivedCloseEvent=!1}on(e,t){if(this._port)throw new Error("Cannot add a method handler after a port is connected");this._methods.set(e,t)}connect(e){this._port=e,this._listeners.add(e,"message",(e=>this._handle(e))),e.start(),tf(e,"connect");for(let[e,t]of this._pendingCalls)this.call(e,...t);this._pendingCalls=[]}destroy(){this._port&&(tf(this._port,"close"),this._port.close()),this._destroyed=!0,this._listeners.removeAll()}call(e,...t){if(this._port||this._pendingCalls.push([e,t]),!this._port||this._destroyed)return;const n=this._sequence++,r=t[t.length-1];"function"==typeof r&&(this._callbacks.set(n,r),t=t.slice(0,-1)),tf(this._port,e,t,n)}_parseMessage({data:e}){return e&&"object"==typeof e?"frame-rpc"!==e.protocol||"1.0.0"!==e.version?null:Array.isArray(e.arguments)?e:null:null}_handle(e){const t=this._parseMessage(e),n=this._port;if(t&&n)if("method"in t){
601
- if("close"===t.method){if(this._receivedCloseEvent)return;this._receivedCloseEvent=!0}const e=this._methods.get(t.method);if(!e)return;const r=(...e)=>{const r={arguments:e,protocol:"frame-rpc",response:t.sequence,version:"1.0.0"};n.postMessage(r)};e(...t.arguments,r)}else if("response"in t){const e=this._callbacks.get(t.response);this._callbacks.delete(t.response),e&&e(...t.arguments)}}}function rf({$tag:e,target:t,uri:n}){return{$tag:e,target:t,uri:n}}function of(e,t){const n=e.find((e=>e.uri===t.uri));if(n)return n;const r=e.find((e=>null===e.id));return r||e[0]}class af{constructor(e,t,n){this._window=e,this._annotationsService=t,this._store=n,this._portFinder=new ef({hostFrame:this._window.parent,source:"sidebar"}),this._listeners=new ya,this._hostRPC=new nf,this._guestRPC=new Map,this._nextGuestId=0,this._inFrame=new Set,this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0
602
- ;Zm(this._store.subscribe,[()=>this._store.allAnnotations(),()=>this._store.frames()],(([t,n],[r])=>{let o=0;const i=new Set,a=[];t.forEach((e=>{Ni(e)||(zi(e)&&++o,i.add(e.$tag),this._inFrame.has(e.$tag)||a.push(e))}));const s=r.filter((e=>!i.has(e.$tag)));if(a.length>0){const e=new Map;for(let t of a){var l;const r=of(n,t);if(!r)continue;const o=null!==(l=e.get(r.id))&&void 0!==l?l:[];o.push(t),e.set(r.id,o)}for(let[t,n]of e){const e=this._guestRPC.get(t);e&&e.call("loadAnnotations",n.map(rf))}a.forEach((e=>{this._inFrame.add(e.$tag)}))}s.forEach((e=>{this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag))),this._inFrame.delete(e.$tag)})),n.length>0&&n.every((e=>e.isAnnotationFetchComplete))&&(0!==o&&o===e||(this._hostRPC.call("publicAnnotationCountChanged",o),e=o))}))}_connectGuest(e){const t=new nf;++this._nextGuestId;let n=`temp-${this._nextGuestId}`;this._guestRPC.set(n,t),t.on("documentInfoChanged",(e=>{this._guestRPC.delete(n),n=e.frameIdentifier,this._guestRPC.set(n,t),this._store.connectFrame({
589
+ this._store.removeDraft(e),this._store.addAnnotations([r]),r}}Im.$inject=["api","store"];class Pm extends Error{constructor(e,t,n=""){let r="Network request failed";t&&(r+=` (${t.status})`),n&&(r+=`: ${n}`),super(r),this.url=e,this.response=t,this.reason=n}}async function Rm(e,t){let n,r;try{n=await fetch(e,t)}catch(t){throw new Pm(e,null,t.message)}if(204===n.status)return null;try{r=await n.json()}catch(t){throw new Pm(e,n,"Failed to parse response")}var o;if(!n.ok)throw new Pm(e,n,null===(o=r)||void 0===o?void 0:o.reason);return r}function Dm(e,t){const n={};for(const r in t)if(t.hasOwnProperty(r)){const o=t[r],i=":"+r;-1!==e.indexOf(i)?e=e.replace(i,encodeURIComponent(String(o))):n[r]=o}return{url:e,unusedParams:n}}function Bm(e){const t={};for(const n in e)e.hasOwnProperty(n)&&"$"!==n[0]&&(t[n]=e[n]);return t}class Fm{constructor(e,t,n){const r=e.routes();this._clientId=null;const o=()=>this._clientId,i=e=>function(e,t,{getAccessToken:n,getClientId:r,onRequestStarted:o,onRequestFinished:i}){
590
+ return async(a,s)=>{o();try{const[o,l]=await Promise.all([e,n()]),c=function(e,t){let n=e;return t.split(".").forEach((e=>{n=n[e]})),n}(o,t),u={"Content-Type":"application/json","Hypothesis-Client-Version":"1.1007.0"};l&&(u.Authorization="Bearer "+l);const h=r();h&&(u["X-Client-Id"]=h);const{url:d,unusedParams:p}=Dm(c.url,a),m=new URL(d);for(let[e,t]of Object.entries(p)){Array.isArray(t)||(t=[t]);for(let n of t)null!=n&&m.searchParams.append(e,n.toString())}return await Rm(m.toString(),{body:s?JSON.stringify(Bm(s)):null,headers:u,method:c.method})}finally{i()}}}(r,e,{getAccessToken:t.getAccessToken,getClientId:o,onRequestStarted:n.apiRequestStarted,onRequestFinished:n.apiRequestFinished});this.search=i("search"),this.annotation={create:i("annotation.create"),delete:i("annotation.delete"),get:i("annotation.read"),update:i("annotation.update"),flag:i("annotation.flag"),hide:i("annotation.hide"),unhide:i("annotation.unhide")},this.group={member:{delete:i("group.member.delete")},read:i("group.read")},
591
+ this.groups={list:i("groups.read")},this.profile={groups:{read:i("profile.groups.read")},read:i("profile.read"),update:i("profile.update")}}setClientId(e){this._clientId=e}}Fm.$inject=["apiRoutes","auth","store"];var jm={};function Hm(e,t){"boolean"==typeof t&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var qm=Hm;Hm.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},Hm.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},Hm.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime()
592
+ ;if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(void 0===n){if(!this._cachedTimeouts)return!1;this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1)}var r=this;return this._timer=setTimeout((function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout((function(){r._operationTimeoutCb(r._attempts)}),r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)}),n),this._options.unref&&this._timer.unref(),!0},Hm.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){n._operationTimeoutCb()}),n._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},Hm.prototype.try=function(e){
593
+ console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},Hm.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},Hm.prototype.start=Hm.prototype.try,Hm.prototype.errors=function(){return this._errors},Hm.prototype.attempts=function(){return this._attempts},Hm.prototype.mainError=function(){if(0===this._errors.length)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var o=this._errors[r],i=o.message,a=(e[i]||0)+1;e[i]=a,a>=n&&(t=o,n=a)}return t},function(e){var t=qm;e.operation=function(n){var r=e.timeouts(n);return new t(r,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<t.retries;o++)r.push(this.createTimeout(o,t))
594
+ ;return e&&e.forever&&!r.length&&r.push(this.createTimeout(o,t)),r.sort((function(e,t){return e-t})),r},e.createTimeout=function(e,t){var n=t.randomize?Math.random()+1:1,r=Math.round(n*Math.max(t.minTimeout,1)*Math.pow(t.factor,e));return r=Math.min(r,t.maxTimeout)},e.wrap=function(t,n,r){if(n instanceof Array&&(r=n,n=null),!r)for(var o in r=[],t)"function"==typeof t[o]&&r.push(o);for(var i=0;i<r.length;i++){var a=r[i],s=t[a];t[a]=function(r){var o=e.operation(n),i=Array.prototype.slice.call(arguments,1),a=i.pop();i.push((function(e){o.retry(e)||(e&&(arguments[0]=o.mainError()),a.apply(this,arguments))})),o.attempt((function(){r.apply(t,i)}))}.bind(t,s),t[a].options=n}}}(jm);var Um=jm;function $m(e,t){return new Promise(((n,r)=>{const o=Um.operation(t);o.attempt((async()=>{try{const t=await e();o.retry(),n(t)}catch(e){o.retry(e)||r(e)}}))}))}function Gm(e){return $m((()=>Rm(e)))}class Vm{constructor(e){this._apiUrl=e.apiUrl,this._routeCache=null,this._linkCache=null}routes(){
595
+ return this._routeCache||(this._routeCache=Gm(this._apiUrl).then((e=>e.links))),this._routeCache}links(){return this._linkCache||(this._linkCache=this.routes().then((e=>Gm(e.links.url)))),this._linkCache}}Vm.$inject=["settings"];class Wm extends Error{constructor(e,t){super(e),this.cause=t}}class Ym{constructor(e){this.clientId=e.clientId,this.tokenEndpoint=e.tokenEndpoint,this.authorizationEndpoint=e.authorizationEndpoint,this.revokeEndpoint=e.revokeEndpoint}exchangeAuthCode(e){return this._getAccessToken({client_id:this.clientId,grant_type:"authorization_code",code:e})}exchangeGrantToken(e){return this._getAccessToken({grant_type:"urn:ietf:params:oauth:grant-type:jwt-bearer",assertion:e})}refreshToken(e){return this._getAccessToken({grant_type:"refresh_token",refresh_token:e})}async revokeToken(e){try{await this._formPost(this.revokeEndpoint,{token:e})}catch(e){throw new Wm("Failed to revoke access token",e)}}authorize(e,t){const n=H(16),r=new Promise(((t,r)=>{e.addEventListener("message",(function o(i){
596
+ "object"==typeof i.data&&i.data.state===n&&("authorization_response"===i.data.type&&t(i.data),"authorization_canceled"===i.data.type&&r(new Error("Authorization window was closed")),e.removeEventListener("message",o))}))})),o=new URL(this.authorizationEndpoint);return o.searchParams.set("client_id",this.clientId),o.searchParams.set("origin",e.location.origin),o.searchParams.set("response_mode","web_message"),o.searchParams.set("response_type","code"),o.searchParams.set("state",n),t.location=o.toString(),r.then((e=>e.code))}async _formPost(e,t){const n=new URLSearchParams;for(let[e,r]of Object.entries(t))n.set(e,r);n.sort();return Rm(e,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:n.toString()})}async _getAccessToken(e){let t;try{t=await this._formPost(this.tokenEndpoint,e)}catch(e){throw new Wm("Failed to fetch access token",e)}return{accessToken:t.access_token,expiresAt:Date.now()+1e3*(t.expires_in-10),refreshToken:t.refresh_token}}static openAuthPopupWindow(e){
597
+ const t=`left=${e.screen.width/2-237.5},top=${e.screen.height/2-215},width=475,height=430`,n=e.open("about:blank","Log in to Hypothesis",t);if(!n)throw new Error("Failed to open login window");return n}}class Km extends sm{constructor(e,t,n,r,o){let i,a,s;super();const l=(c="token",u=r.apiUrl,new URL(c,u).href);var c,u;function h(){let e=new URL(r.apiUrl).hostname;return e=e.replace(/\./g,"%2E"),`hypothesis.oauth.${e}.token`}function d(e){n.setObject(h(),e)}const p=async()=>{if(s)return s;const e=await t.links();return s=new Ym({clientId:r.oauthClientId,authorizationEndpoint:e["oauth.authorize"],revokeEndpoint:e["oauth.revoke"],tokenEndpoint:l}),s},m=()=>{var e;return null===(e=R(r))||void 0===e?void 0:e.grantToken},f=async()=>{if(!a){const e=m();void 0!==e?a=e?p().then((t=>t.exchangeGrantToken(e))).catch((e=>{var t;throw t="You must reload the page to annotate.",o.error(`Hypothesis login lost: ${t}`,{autoDismiss:!1}),e})):Promise.resolve(null):i?(a=(async e=>{const t=await p(),n=await t.exchangeAuthCode(e)
598
+ ;return d(n),n})(i),i=null):a=Promise.resolve(function(){const e=n.getObject(h());return e&&"string"==typeof e.accessToken&&"string"==typeof e.refreshToken&&"number"==typeof e.expiresAt?{accessToken:e.accessToken,refreshToken:e.refreshToken,expiresAt:e.expiresAt}:null}())}const e=a,t=await a;if(!t)return null;if(e!==a)return f();if(Date.now()>t.expiresAt){const e=m();return a=(async(e,t)=>{const n=await p();let r;try{if(r=await n.refreshToken(e),Date.now()>r.expiresAt)throw new Error("Refreshed token expired in the past")}catch{return null}return t.persist&&d(r),r})(t.refreshToken,{persist:void 0===e}),f()}return t.accessToken};(()=>{e.addEventListener("storage",(({key:e})=>{e===h()&&(a=null,this.emit("oauthTokensChanged"))}))})(),this.login=async function(){const t=Ym.openAuthPopupWindow(e),n=await p(),r=await n.authorize(e,t);i=r,a=null},this.logout=async function(){const[e,t]=await Promise.all([a,p()]);e&&await t.revokeToken(e.accessToken),a=Promise.resolve(null),n.removeItem(h())},this.getAccessToken=f}}
599
+ Km.$inject=["$window","apiRoutes","localStorage","settings","toastMessenger"];class Xm{constructor(e,t){this._annotationsService=e,this._store=t,this._saving=new Set,this._failed=new Set}init(){const e=e=>!this._saving.has(e)&&!this._failed.has(e);this._store.subscribe((()=>{this._store.newHighlights().forEach((t=>{const n=t.$tag;e(n)&&(this._saving.add(n),$m((()=>this._annotationsService.save(t))).catch((()=>{this._failed.add(n)})).finally((()=>{this._saving.delete(n)})))}))}))}isSaving(){return this._saving.size>0}}Xm.$inject=["annotationsService","store"];var Zm=function(e,t,n,r){var o=n?n.call(r,e,t):void 0;if(void 0!==o)return!!o;if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(var s=Object.prototype.hasOwnProperty.bind(t),l=0;l<i.length;l++){var c=i[l];if(!s(c))return!1;var u=e[c],h=t[c];if(!1===(o=n?n.call(r,u,h,c):void 0)||void 0===o&&u!==h)return!1}return!0};function Jm(e,t,n){
600
+ const r=Array.isArray(t),o=()=>r?t.map((e=>e())):t();let i=o();return e((()=>{const e=o();if(r?Zm(e,i):e===i)return;const t=i;i=e,n(e,t)}))}class Qm{constructor(e,t){this._frameSync=e,this._store=t}init(){const e=()=>this._store.profile().features;Jm(this._store.subscribe,[e,()=>this._store.frames()],(()=>{this._frameSync.notifyHost("featureFlagsUpdated",e()||{})}))}}function ef(e,t){return!!function(e){if(null===e||"object"!=typeof e)return!1;for(let t of["frame1","frame2","type","requestId"])if("string"!=typeof e[t])return!1;return!0}(e)&&JSON.stringify(e,Object.keys(t).sort())===JSON.stringify(t,Object.keys(t).sort())}Qm.$inject=["frameSync","store"];class tf{constructor({hostFrame:e,source:t}){this._hostFrame=e,this._source=t,this._listeners=new ya}destroy(){this._listeners.removeAll()}async discover(e){let t=!1;if(("guest"===this._source&&"host"===e||"guest"===this._source&&"sidebar"===e||"sidebar"===this._source&&"host"===e||"notebook"===this._source&&"sidebar"===e)&&(t=!0),
601
+ !t)throw new Error("Invalid request of channel/port");const n=H(6);return new Promise(((t,r)=>{const o=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:e,type:"request",requestId:n},"*")},i=setInterval(o,250),a=setTimeout((()=>{clearInterval(i),r(new Error(`Unable to establish ${this._source}-${e} communication channel`))}),2e4),s=this._listeners.add(window,"message",(r=>{const{data:o,ports:l}=r;ef(o,{frame1:this._source,frame2:e,type:"offer",requestId:n})&&(clearInterval(i),clearTimeout(a),this._listeners.remove(s),t(l[0]))}));o()}))}}function nf(e,t,n=[],r=-1){e.postMessage({protocol:"frame-rpc",version:"1.0.0",arguments:n,method:t,sequence:r})}class rf{constructor({userAgent:e=navigator.userAgent,currentWindow:t=window}={}){this._port=null,this._methods=new Map,this._sequence=1,this._callbacks=new Map,this._listeners=new ya,this._listeners.add(t,"unload",(()=>{this._port&&(nf(this._port,"close"),t!==t.parent&&function(e){const t=e.match(/\bAppleWebKit\/([0-9]+)\b/)
602
+ ;return!!t&&!(parseInt(t[1])<=537)}(e)&&t.parent.postMessage({type:"hypothesisPortClosed"},"*",[this._port]))})),this._pendingCalls=[],this._receivedCloseEvent=!1}on(e,t){if(this._port)throw new Error("Cannot add a method handler after a port is connected");this._methods.set(e,t)}connect(e){this._port=e,this._listeners.add(e,"message",(e=>this._handle(e))),e.start(),nf(e,"connect");for(let[e,t]of this._pendingCalls)this.call(e,...t);this._pendingCalls=[]}destroy(){this._port&&(nf(this._port,"close"),this._port.close()),this._destroyed=!0,this._listeners.removeAll()}call(e,...t){if(this._port||this._pendingCalls.push([e,t]),!this._port||this._destroyed)return;const n=this._sequence++,r=t[t.length-1];"function"==typeof r&&(this._callbacks.set(n,r),t=t.slice(0,-1)),nf(this._port,e,t,n)}_parseMessage({data:e}){return e&&"object"==typeof e?"frame-rpc"!==e.protocol||"1.0.0"!==e.version?null:Array.isArray(e.arguments)?e:null:null}_handle(e){const t=this._parseMessage(e),n=this._port;if(t&&n)if("method"in t){
603
+ if("close"===t.method){if(this._receivedCloseEvent)return;this._receivedCloseEvent=!0}const e=this._methods.get(t.method);if(!e)return;const r=(...e)=>{const r={arguments:e,protocol:"frame-rpc",response:t.sequence,version:"1.0.0"};n.postMessage(r)};e(...t.arguments,r)}else if("response"in t){const e=this._callbacks.get(t.response);this._callbacks.delete(t.response),e&&e(...t.arguments)}}}function of({$tag:e,target:t,uri:n}){return{$tag:e,target:t,uri:n}}function af(e,t){const n=e.find((e=>e.uri===t.uri));if(n)return n;const r=e.find((e=>null===e.id));return r||e[0]}class sf{constructor(e,t,n){this._window=e,this._annotationsService=t,this._store=n,this._portFinder=new tf({hostFrame:this._window.parent,source:"sidebar"}),this._listeners=new ya,this._hostRPC=new rf,this._guestRPC=new Map,this._nextGuestId=0,this._inFrame=new Set,this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0
604
+ ;Jm(this._store.subscribe,[()=>this._store.allAnnotations(),()=>this._store.frames()],(([t,n],[r])=>{let o=0;const i=new Set,a=[];t.forEach((e=>{Ni(e)||(zi(e)&&++o,i.add(e.$tag),this._inFrame.has(e.$tag)||a.push(e))}));const s=r.filter((e=>!i.has(e.$tag)));if(a.length>0){const e=new Map;for(let t of a){var l;const r=af(n,t);if(!r)continue;const o=null!==(l=e.get(r.id))&&void 0!==l?l:[];o.push(t),e.set(r.id,o)}for(let[t,n]of e){const e=this._guestRPC.get(t);e&&e.call("loadAnnotations",n.map(of))}a.forEach((e=>{this._inFrame.add(e.$tag)}))}s.forEach((e=>{this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag))),this._inFrame.delete(e.$tag)})),n.length>0&&n.every((e=>e.isAnnotationFetchComplete))&&(0!==o&&o===e||(this._hostRPC.call("publicAnnotationCountChanged",o),e=o))}))}_connectGuest(e){const t=new rf;++this._nextGuestId;let n=`temp-${this._nextGuestId}`;this._guestRPC.set(n,t),t.on("documentInfoChanged",(e=>{this._guestRPC.delete(n),n=e.frameIdentifier,this._guestRPC.set(n,t),this._store.connectFrame({
603
605
  id:e.frameIdentifier,metadata:e.metadata,uri:e.uri})})),t.on("close",(()=>{const e=this._store.frames().find((e=>e.id===n));e&&this._store.destroyFrame(e),t.destroy(),this._guestRPC.delete(n)})),t.on("createAnnotation",(e=>{if(!this._store.isLoggedIn())return this._hostRPC.call("openSidebar"),this._store.openSidebarPanel("loginPrompt"),void this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag)));this._inFrame.add(e.$tag),e.$highlight||this._hostRPC.call("openSidebar"),this._hostRPC.call("showHighlights"),this._annotationsService.create(e)}));let r={};const o=va((()=>{this._store.updateAnchorStatus(r),r={}}),10);t.on("syncAnchoringStatus",(({$tag:e,$orphan:t})=>{this._inFrame.add(e),r[e]=t?"orphan":"anchored",o()})),t.on("showAnnotations",(e=>{this._store.selectAnnotations(this._store.findIDsForTags(e)),this._store.selectTab("annotation")})),t.on("focusAnnotations",(e=>{this._store.focusAnnotations(e||[])})),t.on("toggleAnnotationSelection",(e=>{
604
- this._store.toggleSelectedAnnotations(this._store.findIDsForTags(e))})),t.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")})),t.on("closeSidebar",(()=>{this._hostRPC.call("closeSidebar")})),t.connect(e),t.call("setHighlightsVisible",this._highlightsVisible)}_setupHostEvents(){this._hostRPC.on("sidebarOpened",(()=>{this._store.setSidebarOpened(!0)})),this._hostRPC.on("setHighlightsVisible",(e=>{this._highlightsVisible=e,this._guestRPC.forEach((t=>t.call("setHighlightsVisible",e)))}))}async connect(){const e=await this._portFinder.discover("host");this._hostRPC.connect(e),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;Qm(t,{frame1:"guest",frame2:"sidebar",type:"offer"})&&this._connectGuest(n[0])}))}notifyHost(e,...t){this._hostRPC.call(e,...t)}focusAnnotations(e){this._store.focusAnnotations(e),this._guestRPC.forEach((t=>t.call("focusAnnotations",e)))}scrollToAnnotation(e){this._guestRPC.forEach((t=>t.call("scrollToAnnotation",e)))}destroy(){this._portFinder.destroy(),
605
- this._listeners.removeAll()}}function sf(e){return Object.keys(e).reduce(((e,t)=>(e[t]=t,e)),{})}af.$inject=["$window","annotationsService","store"];const lf={id:"__default__",name:"__DEFAULT__",logo:"data:image/svg+xml;utf8,"+encodeURIComponent(ei)};const cf=["organization","scopes"];class uf{constructor(e,t,n,r,o,i){this._store=e,this._api=t,this._auth=n,this._settings=o,this._toastMessenger=i,this._serviceConfig=R(o),this._reloadSetUp=!1}_mainURI(){var e,t;return null!==(e=null===(t=this._store.mainFrame())||void 0===t?void 0:t.uri)&&void 0!==e?e:null}async _filterGroups(e,t,n,r){if(r){const t=e.find((e=>e.id===r));t&&!t.isScopedToUri&&t.scopes&&t.scopes.enforced&&(e=e.filter((e=>e.id!==r)),this._store.setDirectLinkedGroupFetchFailed(),r=null)}if(t)return e;const o=e.some((e=>"__world__"!==e.id&&e.isScopedToUri));return o?"__world__"===r||"__world__"===n?e:e.filter((e=>"__world__"!==e.id)):e}_setupAutoReload(){this._reloadSetUp||(this._reloadSetUp=!0,Zm(this._store.subscribe,(()=>this._mainURI()),(()=>{
606
- this.load()})),Zm(this._store.subscribe,[()=>this._store.hasFetchedProfile(),()=>this._store.profile().userid],((e,[t])=>{t&&this.load()})))}_addGroupsToStore(e,t){!function(e){e.forEach((e=>{e.organization&&"object"==typeof e.organization||(e.organization=lf)}))}(e);const n=0===this._store.allGroups().length,r=this._store.getDefault("focusedGroup");this._store.loadGroups(e),n&&(t&&e.some((e=>e.id===t))?this.focus(t):r&&e.some((e=>e.id===r))&&this.focus(r))}_fetchGroup(e){return this._api.group.read({id:e,expand:cf})}async _loadGroupsForUserAndDocument(){var e;const t=()=>function(e,t){const n=t(e);return null!==n?Promise.resolve(n):new Promise((n=>{const r=e.subscribe((()=>{const o=t(e);null!==o&&(r(),n(o))}))}))}(this._store,(()=>this._mainURI()));let n=null;"sidebar"===this._store.route()&&(n=await t()),this._setupAutoReload();const r=this._store.directLinkedAnnotationId();let o=null;r&&(o=this._api.annotation.get({id:r}).catch((()=>null)));const i=this._store.directLinkedGroupId();let a=null
607
- ;i&&(a=this._fetchGroup(i).then((e=>(this._store.clearDirectLinkedGroupFetchFailed(),e))).catch((()=>(this._store.setDirectLinkedGroupFetchFailed(),null))));const s={expand:cf},l=null===(e=this._serviceConfig)||void 0===e?void 0:e.authority;l&&(s.authority=l),n&&(s.document_uri=n);const[c,u,h,d,p]=await Promise.all([this._api.profile.groups.read({expand:cf}),this._api.groups.list(s),this._auth.getAccessToken(),o,a]);p&&!u.some((e=>e.id===p.id))&&u.push(p);let m=null;if(d){m=d.group;const e=c.concat(u).find((e=>e.id===d.group));if(!e)try{const e=await this._fetchGroup(d.group);u.push(e)}catch(e){this._toastMessenger.error("Unable to fetch group for linked annotation")}}const f=null!==h,g=await this._filterGroups(K(c,u,n,this._settings),f,m,i),v=m||i||null;return this._addGroupsToStore(g,v),g}async _loadServiceSpecifiedGroups(e){const t=await this._api.profile.groups.read({expand:cf});let n;const r=async e=>{try{return await this._fetchGroup(e)}catch(e){return n=e,null}
608
- },o=await Promise.all(e.map((e=>t.find((t=>t.id===e||t.groupid===e))||r(e)))),i=o.filter((e=>null!==e)),a=this._store.directLinkedGroupId();return this._addGroupsToStore(i,a),n&&this._toastMessenger.error(`Unable to fetch groups: ${n.message}`,{autoDismiss:!1}),i}async load(){var e;if(null!==(e=this._serviceConfig)&&void 0!==e&&e.groups){let e=[];try{e=await this._serviceConfig.groups}catch(e){this._toastMessenger.error(`Unable to fetch group configuration: ${e.message}`)}return this._loadServiceSpecifiedGroups(e)}return this._loadGroupsForUserAndDocument()}focus(e){const t=this._store.focusedGroupId();this._store.focusGroup(e);const n=this._store.focusedGroupId();if(t!==n&&null!==t&&n){const e=this._store.newAnnotations().filter((e=>!Ni(e))).map((e=>({...e,group:n})));e.length&&this._store.addAnnotations(e),this._store.setDefault("focusedGroup",n)}}leave(e){return this._api.group.member.delete({pubid:e,userid:"me"})}}uf.$inject=["store","api","auth","session","settings","toastMessenger"];class hf{
609
- constructor(e,t,n,r){this._api=e,this._store=t,this._streamer=n,this._streamFilter=r,this._searchClient=null}load({groupId:e,uris:t,onError:n,maxResults:r,sortBy:o,sortOrder:i,streamFilterBy:a="uri"}){if(this._store.removeAnnotations(this._store.savedAnnotations()),this._searchClient&&this._searchClient.cancel(),"group"===a)this._streamFilter.resetFilter().addClause("/group","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()});else t&&t.length>0&&(this._streamFilter.resetFilter().addClause("/uri","one_of",t),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}));const s={incremental:!0,separateReplies:!1,maxResults:r,sortBy:o,sortOrder:i};this._searchClient=new cm(this._api.search,s),this._searchClient.on("resultCount",(e=>{this._store.setAnnotationResultCount(e)})),this._searchClient.on("results",(e=>{e.length&&this._store.addAnnotations(e)})),this._searchClient.on("error",(e=>{"function"==typeof n?n(e):console.error(e)})),
610
- this._searchClient.on("end",(()=>{this._searchClient=null,t&&t.length>0&&this._store.frames().forEach((e=>{t.indexOf(e.uri)>=0&&this._store.updateFrameAnnotationFetchStatus(e.uri,!0)})),this._store.annotationFetchFinished()})),this._store.annotationFetchStarted(),this._searchClient.get({group:e,uri:t})}async loadThread(e){let t,n;this._store.clearAnnotations();try{this._store.annotationFetchStarted(),t=await this._api.annotation.get({id:e}),Ni(t)&&(t=await this._api.annotation.get({id:t.references[0]})),n=await this._api.search({references:t.id})}finally{this._store.annotationFetchFinished()}const r=[t,...n.rows];if(this._store.addAnnotations(r),!Ni(t)){const e=t.id;this._streamFilter.addClause("/references","one_of",e,!0).addClause("/id","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}),this._streamer.connect()}return r}}hf.$inject=["api","store","streamer","streamFilter"];class df{constructor(){this._store={}}getItem(e){return e in this._store?this._store[e]:null}
611
- setItem(e,t){this._store[e]=t}removeItem(e){delete this._store[e]}}class pf{constructor(e){let t="hypothesis.testKey";try{this._storage=e.localStorage,e.localStorage.setItem(t,t),e.localStorage.getItem(t),e.localStorage.removeItem(t)}catch(e){this._storage=new df}}getItem(e){return this._storage.getItem(e)}getObject(e){const t=this._storage.getItem(e);return t?JSON.parse(t):null}setItem(e,t){this._storage.setItem(e,t)}setObject(e,t){const n=JSON.stringify(t);this._storage.setItem(e,n)}removeItem(e){this._storage.removeItem(e)}}pf.$inject=["$window"];const mf={annotationPrivacy:"hypothesis.privacy",focusedGroup:"hypothesis.groups.focus"};class ff{constructor(e,t){this._storage=e,this._store=t}init(){Object.keys(mf).forEach((e=>{const t=this._storage.getItem(mf[e]);this._store.setDefault(e,t)})),Zm(this._store.subscribe,(()=>this._store.getDefaults()),((e,t)=>{for(let n in e)t[n]!==e[n]&&n in mf&&this._storage.setItem(mf[n],e[n])}))}}ff.$inject=["localStorage","store"];class gf{constructor(e,t){this._window=e,
606
+ this._store.toggleSelectedAnnotations(this._store.findIDsForTags(e))})),t.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")})),t.on("closeSidebar",(()=>{this._hostRPC.call("closeSidebar")})),t.connect(e),t.call("setHighlightsVisible",this._highlightsVisible)}_setupHostEvents(){this._hostRPC.on("sidebarOpened",(()=>{this._store.setSidebarOpened(!0)})),this._hostRPC.on("setHighlightsVisible",(e=>{this._highlightsVisible=e,this._guestRPC.forEach((t=>t.call("setHighlightsVisible",e)))}))}async connect(){const e=await this._portFinder.discover("host");this._hostRPC.connect(e),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;ef(t,{frame1:"guest",frame2:"sidebar",type:"offer"})&&this._connectGuest(n[0])}))}notifyHost(e,...t){this._hostRPC.call(e,...t)}focusAnnotations(e){this._store.focusAnnotations(e),this._guestRPC.forEach((t=>t.call("focusAnnotations",e)))}scrollToAnnotation(e){this._guestRPC.forEach((t=>t.call("scrollToAnnotation",e)))}destroy(){this._portFinder.destroy(),
607
+ this._listeners.removeAll()}}function lf(e){return Object.keys(e).reduce(((e,t)=>(e[t]=t,e)),{})}sf.$inject=["$window","annotationsService","store"];const cf={id:"__default__",name:"__DEFAULT__",logo:"data:image/svg+xml;utf8,"+encodeURIComponent(ei)};const uf=["organization","scopes"];class hf{constructor(e,t,n,r,o,i){this._store=e,this._api=t,this._auth=n,this._settings=o,this._toastMessenger=i,this._serviceConfig=R(o),this._reloadSetUp=!1}_mainURI(){var e,t;return null!==(e=null===(t=this._store.mainFrame())||void 0===t?void 0:t.uri)&&void 0!==e?e:null}async _filterGroups(e,t,n,r){if(r){const t=e.find((e=>e.id===r));t&&!t.isScopedToUri&&t.scopes&&t.scopes.enforced&&(e=e.filter((e=>e.id!==r)),this._store.setDirectLinkedGroupFetchFailed(),r=null)}if(t)return e;const o=e.some((e=>"__world__"!==e.id&&e.isScopedToUri));return o?"__world__"===r||"__world__"===n?e:e.filter((e=>"__world__"!==e.id)):e}_setupAutoReload(){this._reloadSetUp||(this._reloadSetUp=!0,Jm(this._store.subscribe,(()=>this._mainURI()),(()=>{
608
+ this.load()})),Jm(this._store.subscribe,[()=>this._store.hasFetchedProfile(),()=>this._store.profile().userid],((e,[t])=>{t&&this.load()})))}_addGroupsToStore(e,t){!function(e){e.forEach((e=>{e.organization&&"object"==typeof e.organization||(e.organization=cf)}))}(e);const n=0===this._store.allGroups().length,r=this._store.getDefault("focusedGroup");this._store.loadGroups(e),n&&(t&&e.some((e=>e.id===t))?this.focus(t):r&&e.some((e=>e.id===r))&&this.focus(r))}_fetchGroup(e){return this._api.group.read({id:e,expand:uf})}async _loadGroupsForUserAndDocument(){var e;const t=()=>function(e,t){const n=t(e);return null!==n?Promise.resolve(n):new Promise((n=>{const r=e.subscribe((()=>{const o=t(e);null!==o&&(r(),n(o))}))}))}(this._store,(()=>this._mainURI()));let n=null;"sidebar"===this._store.route()&&(n=await t()),this._setupAutoReload();const r=this._store.directLinkedAnnotationId();let o=null;r&&(o=this._api.annotation.get({id:r}).catch((()=>null)));const i=this._store.directLinkedGroupId();let a=null
609
+ ;i&&(a=this._fetchGroup(i).then((e=>(this._store.clearDirectLinkedGroupFetchFailed(),e))).catch((()=>(this._store.setDirectLinkedGroupFetchFailed(),null))));const s={expand:uf},l=null===(e=this._serviceConfig)||void 0===e?void 0:e.authority;l&&(s.authority=l),n&&(s.document_uri=n);const[c,u,h,d,p]=await Promise.all([this._api.profile.groups.read({expand:uf}),this._api.groups.list(s),this._auth.getAccessToken(),o,a]);p&&!u.some((e=>e.id===p.id))&&u.push(p);let m=null;if(d){m=d.group;const e=c.concat(u).find((e=>e.id===d.group));if(!e)try{const e=await this._fetchGroup(d.group);u.push(e)}catch(e){this._toastMessenger.error("Unable to fetch group for linked annotation")}}const f=null!==h,g=await this._filterGroups(K(c,u,n,this._settings),f,m,i),v=m||i||null;return this._addGroupsToStore(g,v),g}async _loadServiceSpecifiedGroups(e){const t=await this._api.profile.groups.read({expand:uf});let n;const r=async e=>{try{return await this._fetchGroup(e)}catch(e){return n=e,null}
610
+ },o=await Promise.all(e.map((e=>t.find((t=>t.id===e||t.groupid===e))||r(e)))),i=o.filter((e=>null!==e)),a=this._store.directLinkedGroupId();return this._addGroupsToStore(i,a),n&&this._toastMessenger.error(`Unable to fetch groups: ${n.message}`,{autoDismiss:!1}),i}async load(){var e;if(null!==(e=this._serviceConfig)&&void 0!==e&&e.groups){let e=[];try{e=await this._serviceConfig.groups}catch(e){this._toastMessenger.error(`Unable to fetch group configuration: ${e.message}`)}return this._loadServiceSpecifiedGroups(e)}return this._loadGroupsForUserAndDocument()}focus(e){const t=this._store.focusedGroupId();this._store.focusGroup(e);const n=this._store.focusedGroupId();if(t!==n&&null!==t&&n){const e=this._store.newAnnotations().filter((e=>!Ni(e))).map((e=>({...e,group:n})));e.length&&this._store.addAnnotations(e),this._store.setDefault("focusedGroup",n)}}leave(e){return this._api.group.member.delete({pubid:e,userid:"me"})}}hf.$inject=["store","api","auth","session","settings","toastMessenger"];class df{
611
+ constructor(e,t,n,r){this._api=e,this._store=t,this._streamer=n,this._streamFilter=r,this._searchClient=null}load({groupId:e,uris:t,onError:n,maxResults:r,sortBy:o,sortOrder:i,streamFilterBy:a="uri"}){if(this._store.removeAnnotations(this._store.savedAnnotations()),this._searchClient&&this._searchClient.cancel(),"group"===a)this._streamFilter.resetFilter().addClause("/group","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()});else t&&t.length>0&&(this._streamFilter.resetFilter().addClause("/uri","one_of",t),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}));const s={incremental:!0,separateReplies:!1,maxResults:r,sortBy:o,sortOrder:i};this._searchClient=new um(this._api.search,s),this._searchClient.on("resultCount",(e=>{this._store.setAnnotationResultCount(e)})),this._searchClient.on("results",(e=>{e.length&&this._store.addAnnotations(e)})),this._searchClient.on("error",(e=>{"function"==typeof n?n(e):console.error(e)})),
612
+ this._searchClient.on("end",(()=>{this._searchClient=null,t&&t.length>0&&this._store.frames().forEach((e=>{t.indexOf(e.uri)>=0&&this._store.updateFrameAnnotationFetchStatus(e.uri,!0)})),this._store.annotationFetchFinished()})),this._store.annotationFetchStarted(),this._searchClient.get({group:e,uri:t})}async loadThread(e){let t,n;this._store.clearAnnotations();try{this._store.annotationFetchStarted(),t=await this._api.annotation.get({id:e}),Ni(t)&&(t=await this._api.annotation.get({id:t.references[0]})),n=await this._api.search({references:t.id})}finally{this._store.annotationFetchFinished()}const r=[t,...n.rows];if(this._store.addAnnotations(r),!Ni(t)){const e=t.id;this._streamFilter.addClause("/references","one_of",e,!0).addClause("/id","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}),this._streamer.connect()}return r}}df.$inject=["api","store","streamer","streamFilter"];class pf{constructor(){this._store={}}getItem(e){return e in this._store?this._store[e]:null}
613
+ setItem(e,t){this._store[e]=t}removeItem(e){delete this._store[e]}}class mf{constructor(e){let t="hypothesis.testKey";try{this._storage=e.localStorage,e.localStorage.setItem(t,t),e.localStorage.getItem(t),e.localStorage.removeItem(t)}catch(e){this._storage=new pf}}getItem(e){return this._storage.getItem(e)}getObject(e){const t=this._storage.getItem(e);return t?JSON.parse(t):null}setItem(e,t){this._storage.setItem(e,t)}setObject(e,t){const n=JSON.stringify(t);this._storage.setItem(e,n)}removeItem(e){this._storage.removeItem(e)}}mf.$inject=["$window"];const ff={annotationPrivacy:"hypothesis.privacy",focusedGroup:"hypothesis.groups.focus"};class gf{constructor(e,t){this._storage=e,this._store=t}init(){Object.keys(ff).forEach((e=>{const t=this._storage.getItem(ff[e]);this._store.setDefault(e,t)})),Jm(this._store.subscribe,(()=>this._store.getDefaults()),((e,t)=>{for(let n in e)t[n]!==e[n]&&n in ff&&this._storage.setItem(ff[n],e[n])}))}}gf.$inject=["localStorage","store"];class vf{constructor(e,t){this._window=e,
612
614
  this._store=t,this._didRegisterPopstateListener=!1}currentRoute(){const e=this._window.location.pathname.slice(1).split("/"),t=new URLSearchParams(this._window.location.search),n={};for(let[e,r]of t)n[e]=r;"client"===e[0]&&e.shift();let r;switch(e[0].replace(/\.html$/,"")){case"a":r="annotation",n.id=e[1]||"";break;case"notebook":r="notebook";break;case"stream":r="stream";break;default:r="sidebar"}return{route:r,params:n}}routeUrl(e,t={}){let n;const r={...t};switch(e){case"annotation":{const e=t.id;delete r.id,n=`/a/${e}`}break;case"notebook":n="/notebook";break;case"stream":n="/stream";break;default:throw new Error(`Cannot generate URL for route "${e}"`)}let o=!1;const i=new URLSearchParams;for(let[e,t]of Object.entries(r))o=!0,i.set(e,t);return o&&(n+="?"+i.toString()),n}sync(){const{route:e,params:t}=this.currentRoute();this._store.changeRoute(e,t),this._didRegisterPopstateListener||(this._window.addEventListener("popstate",(()=>{this.sync()})),this._didRegisterPopstateListener=!0)}navigate(e,t){
613
- this._window.history.pushState({},"",this.routeUrl(e,t)),this.sync()}}gf.$inject=["$window","store"];class vf{constructor(e,t){this._apiRoutes=e,this._store=t}async init(){try{const e=await this._apiRoutes.links();this._store.updateLinks(e)}catch(e){console.warn(`Failed to fetch Hypothesis links: ${e.message}`)}}}vf.$inject=["apiRoutes","store"];class yf{constructor(e,t,n,r,o){var i,a;this._api=t,this._auth=n,this._store=e,this._toastMessenger=o,this._authority=null!==(i=null===(a=R(r))||void 0===a?void 0:a.authority)&&void 0!==i?i:null,this._lastLoad=null,this._lastLoadTime=null,n.on("oauthTokensChanged",(()=>this.reload()))}load(){return(!this._lastLoad||!this._lastLoadTime||Date.now()-this._lastLoadTime>3e5)&&(this._lastLoadTime=Date.now(),this._lastLoad=Um((()=>{const e=this._authority?{authority:this._authority}:{};return this._api.profile.read(e)})).then((e=>(this.update(e),this._lastLoadTime=Date.now(),e))).catch((e=>{throw this._lastLoadTime=null,e}))),this._lastLoad}async dismissSidebarTutorial(){
614
- const e=await this._api.profile.update({},{preferences:{show_sidebar_tutorial:!1}});this.update(e)}update(e){const t=this._store.profile(),n=e.userid!==t.userid;return this._store.updateProfile(e),this._lastLoad=Promise.resolve(e),this._lastLoadTime=Date.now(),n&&(e.userid?Lr({id:e.userid}):Lr(null)),e}async logout(){try{return await this._auth.logout(),this.reload()}catch(e){throw this._toastMessenger.error("Log out failed"),new Error(e)}}reload(){return this._lastLoad=null,this._lastLoadTime=null,this.load()}}yf.$inject=["store","api","auth","settings","toastMessenger"];class _f{constructor(){this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}}}addClause(e,t,n,r=!1){return this._filter.clauses.push({field:e,operator:t,value:n,case_sensitive:r}),this}getFilter(){return this._filter}resetFilter(){return this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}},this}}class bf extends am{constructor(e){super();const t=[];let n
615
- ;const r=()=>{for(;t.length>0;){const e=JSON.stringify(t.shift());n.send(e)}};this.close=()=>{n.close(1e3)},this.send=e=>{t.push(e),this.isConnected()&&r()},this.isConnected=()=>n.readyState===WebSocket.OPEN,(()=>{n=new WebSocket(e),n.onopen=e=>{r(),this.emit("open",e)},n.onclose=e=>{if(1e3===e.code||1001===e.code)return void this.emit("close",e);const t=new Error(`WebSocket closed abnormally, code: ${e.code}`);console.warn(t),this.emit("disconnect")},n.onerror=e=>{this.emit("error",e)},n.onmessage=e=>{this.emit("message",e)}})()}}class wf{constructor(e,t,n,r,o){this._auth=n,this._groups=r,this._session=o,this._store=e,this._websocketURL=t.links().then((e=>e.websocket)),this.clientId=H(32),this._socket=null,this._updateImmediately=!0,this._configMessages={},this._reconnectionAttempts=0,this._reconnectSetUp=!1}applyPendingUpdates(){const e=Object.values(this._store.pendingUpdates());e.length&&this._store.addAnnotations(e);const t=Object.keys(this._store.pendingDeletions()).map((e=>({id:e})))
615
+ this._window.history.pushState({},"",this.routeUrl(e,t)),this.sync()}}vf.$inject=["$window","store"];class yf{constructor(e,t){this._apiRoutes=e,this._store=t}async init(){try{const e=await this._apiRoutes.links();this._store.updateLinks(e)}catch(e){console.warn(`Failed to fetch Hypothesis links: ${e.message}`)}}}yf.$inject=["apiRoutes","store"];class _f{constructor(e,t,n,r,o){var i,a;this._api=t,this._auth=n,this._store=e,this._toastMessenger=o,this._authority=null!==(i=null===(a=R(r))||void 0===a?void 0:a.authority)&&void 0!==i?i:null,this._lastLoad=null,this._lastLoadTime=null,n.on("oauthTokensChanged",(()=>this.reload()))}load(){return(!this._lastLoad||!this._lastLoadTime||Date.now()-this._lastLoadTime>3e5)&&(this._lastLoadTime=Date.now(),this._lastLoad=$m((()=>{const e=this._authority?{authority:this._authority}:{};return this._api.profile.read(e)})).then((e=>(this.update(e),this._lastLoadTime=Date.now(),e))).catch((e=>{throw this._lastLoadTime=null,e}))),this._lastLoad}async dismissSidebarTutorial(){
616
+ const e=await this._api.profile.update({},{preferences:{show_sidebar_tutorial:!1}});this.update(e)}update(e){const t=this._store.profile(),n=e.userid!==t.userid;return this._store.updateProfile(e),this._lastLoad=Promise.resolve(e),this._lastLoadTime=Date.now(),n&&(e.userid?Lr({id:e.userid}):Lr(null)),e}async logout(){try{return await this._auth.logout(),this.reload()}catch(e){throw this._toastMessenger.error("Log out failed"),new Error(e)}}reload(){return this._lastLoad=null,this._lastLoadTime=null,this.load()}}_f.$inject=["store","api","auth","settings","toastMessenger"];class bf{constructor(){this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}}}addClause(e,t,n,r=!1){return this._filter.clauses.push({field:e,operator:t,value:n,case_sensitive:r}),this}getFilter(){return this._filter}resetFilter(){return this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}},this}}class wf extends sm{constructor(e){super();const t=[];let n
617
+ ;const r=()=>{for(;t.length>0;){const e=JSON.stringify(t.shift());n.send(e)}};this.close=()=>{n.close(1e3)},this.send=e=>{t.push(e),this.isConnected()&&r()},this.isConnected=()=>n.readyState===WebSocket.OPEN,(()=>{n=new WebSocket(e),n.onopen=e=>{r(),this.emit("open",e)},n.onclose=e=>{if(1e3===e.code||1001===e.code)return void this.emit("close",e);const t=new Error(`WebSocket closed abnormally, code: ${e.code}`);console.warn(t),this.emit("disconnect")},n.onerror=e=>{this.emit("error",e)},n.onmessage=e=>{this.emit("message",e)}})()}}class xf{constructor(e,t,n,r,o){this._auth=n,this._groups=r,this._session=o,this._store=e,this._websocketURL=t.links().then((e=>e.websocket)),this.clientId=H(32),this._socket=null,this._updateImmediately=!0,this._configMessages={},this._reconnectionAttempts=0,this._reconnectSetUp=!1}applyPendingUpdates(){const e=Object.values(this._store.pendingUpdates());e.length&&this._store.addAnnotations(e);const t=Object.keys(this._store.pendingDeletions()).map((e=>({id:e})))
616
618
  ;t.length&&this._store.removeAnnotations(t),this._store.clearPendingUpdates()}_handleSocketError(e,t){V("Error connecting to H push notification service:",t);const n=new URL(e).hostname;-1!==["localhost","127.0.0.1"].indexOf(n)&&V("Check that your H service is configured to allow WebSocket connections from "+window.location.origin)}_handleSocketMessage(e){const t=JSON.parse(e.data);if(t)if("annotation-notification"===t.type){const e=t.payload;switch(t.options.action){case"create":case"update":case"past":this._store.receiveRealTimeUpdates({updatedAnnotations:e});break;case"delete":this._store.receiveRealTimeUpdates({deletedAnnotations:e})}this._updateImmediately&&this.applyPendingUpdates()}else if("session-change"===t.type)this._session.update(t.model),this._groups.load();else if("whoyouare"===t.type){const e=this._store.profile().userid;t.userid!==e&&console.warn('WebSocket user ID "%s" does not match logged-in ID "%s"',t.userid,e)}else V("Received unsupported notification",t.type)}_sendClientConfig(e){
617
- Object.keys(this._configMessages).forEach((t=>{this._configMessages[t]&&e.send(this._configMessages[t])}))}setConfig(e,t){var n;this._configMessages[e]=t,null!==(n=this._socket)&&void 0!==n&&n.isConnected()&&this._socket.send(t)}async _reconnect(){var e;const t=await this._websocketURL;if(!t)return;let n,r;null===(e=this._socket)||void 0===e||e.close();try{n=await this._auth.getAccessToken()}catch(e){throw console.error("Failed to fetch token for WebSocket authentication",e),e}if(n){const e=new URL(t);e.searchParams.set("access_token",n),r=e.toString()}else r=t;const o=new bf(r);o.on("open",(()=>{this._reconnectionAttempts=0,this._sendClientConfig(o)})),o.on("disconnect",(()=>{if(++this._reconnectionAttempts,this._reconnectionAttempts<10){const e=1e3*2**this._reconnectionAttempts;setTimeout((()=>this._reconnect()),e)}else console.error("Gave up trying to reconnect to Hypothesis real time update service")})),o.on("error",(e=>this._handleSocketError(t,e))),o.on("message",(e=>this._handleSocketMessage(e))),
618
- this._socket=o,this.setConfig("client-id",{messageType:"client_id",value:this.clientId}),this.setConfig("auth-check",{type:"whoami",id:1})}async connect(e={}){var t;this._updateImmediately=null===(t=e.applyUpdatesImmediately)||void 0===t||t,this._reconnectSetUp||(this._reconnectSetUp=!0,Zm(this._store.subscribe,(()=>this._store.profile().userid),(()=>{this._reconnect()}))),this._socket||await this._reconnect()}}wf.$inject=["store","apiRoutes","auth","groups","session"];class xf{constructor(e){this._storage=e}filter(e,t=null){const n=this._storage.getObject("hypothesis.user.tags.list")||[];let r=0;return n.filter((n=>{if(null!==t&&r>=t)return!1;const o=n.split(/\W+/),i=new RegExp(`^${Y(e)}`,"i");return!(!o.some((e=>e.match(i)))&&!n.match(i))&&(++r,!0)}))}store(e){const t=this._storage.getObject("hypothesis.user.tags.map")||{};e.forEach((e=>{t[e]?(t[e].count+=1,t[e].updated=Date.now()):t[e]={text:e,count:1,updated:Date.now()}})),this._storage.setObject("hypothesis.user.tags.map",t)
619
- ;const n=Object.keys(t).sort(((e,n)=>t[e].count!==t[n].count?t[n].count-t[e].count:e.localeCompare(n)));this._storage.setObject("hypothesis.user.tags.list",n)}}xf.$inject=["localStorage"];class kf{constructor(e){this._store=e}forceVisible(e){e.children.forEach((e=>{this.forceVisible(e)})),e.visible||this._store.setForcedVisible(e.id,!0)}}kf.$inject=["store"];class Sf{constructor(e){this._store=e}dismiss(e){const t=this._store.getToastMessage(e);t&&!t.isDismissed&&(this._store.updateToastMessage({...t,isDismissed:!0}),setTimeout((()=>{this._store.removeToastMessage(e)}),500))}_addMessage(e,t,{autoDismiss:n=!0,moreInfoURL:r=""}={}){if(this._store.hasToastMessage(e,t))return;const o=H(10),i={type:e,id:o,message:t,moreInfoURL:r};this._store.addToastMessage({isDismissed:!1,...i}),n&&setTimeout((()=>{this.dismiss(o)}),5e3)}error(e,t){this._addMessage("error",e,t)}success(e,t){this._addMessage("success",e,t)}notice(e,t){this._addMessage("notice",e,t)}}function Cf(e,t,n){return t in e?Object.defineProperty(e,t,{
620
- value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Af(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Ef(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Af(Object(n),!0).forEach((function(t){Cf(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Af(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Tf(e){return"Minified Redux error #"+e+"; visit https://redux.js.org/Errors?code="+e+" for the full message or use the non-minified dev environment for full errors. "}Sf.$inject=["store"];var Nf="function"==typeof Symbol&&Symbol.observable||"@@observable",Mf=function(){return Math.random().toString(36).substring(7).split("").join(".")},Lf={INIT:"@@redux/INIT"+Mf(),
621
- REPLACE:"@@redux/REPLACE"+Mf(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Mf()}};function zf(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Of(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(Tf(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(Tf(1));return n(Of)(e,t)}if("function"!=typeof e)throw new Error(Tf(2));var o=e,i=t,a=[],s=a,l=!1;function c(){s===a&&(s=a.slice())}function u(){if(l)throw new Error(Tf(3));return i}function h(e){if("function"!=typeof e)throw new Error(Tf(4));if(l)throw new Error(Tf(5));var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error(Tf(6));t=!1,c();var n=s.indexOf(e);s.splice(n,1),a=null}}}function d(e){if(!zf(e))throw new Error(Tf(7));if(void 0===e.type)throw new Error(Tf(8))
622
- ;if(l)throw new Error(Tf(9));try{l=!0,i=o(i,e)}finally{l=!1}for(var t=a=s,n=0;n<t.length;n++){(0,t[n])()}return e}function p(e){if("function"!=typeof e)throw new Error(Tf(10));o=e,d({type:Lf.REPLACE})}function m(){var e,t=h;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(Tf(11));function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[Nf]=function(){return this},e}return d({type:Lf.INIT}),(r={dispatch:d,subscribe:h,getState:u,replaceReducer:p})[Nf]=m,r}function If(e){for(var t=Object.keys(e),n={},r=0;r<t.length;r++){var o=t[r];"function"==typeof e[o]&&(n[o]=e[o])}var i,a=Object.keys(n);try{!function(e){Object.keys(e).forEach((function(t){var n=e[t];if(void 0===n(void 0,{type:Lf.INIT}))throw new Error(Tf(12));if(void 0===n(void 0,{type:Lf.PROBE_UNKNOWN_ACTION()}))throw new Error(Tf(13))}))}(n)}catch(e){i=e}return function(e,t){if(void 0===e&&(e={}),i)throw i;for(var r=!1,o={},s=0;s<a.length;s++){var l=a[s],c=n[l],u=e[l],h=c(u,t);if(void 0===h)throw t&&t.type,
623
- new Error(Tf(14));o[l]=h,r=r||h!==u}return(r=r||a.length!==Object.keys(e).length)?o:e}}function Pf(e,t){return function(){return t(e.apply(this,arguments))}}function Rf(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}function Df(e){return function(t){var n=t.dispatch,r=t.getState;return function(t){return function(o){return"function"==typeof o?o(n,r,e):t(o)}}}}var Bf=Df();Bf.withExtraArgument=Df;var Ff=Bf;function jf(e,t=[],n=[]){const r={},o={},i={};e.forEach((e=>{e.namespace?(r[e.namespace]=e.initialState(...t),o[e.namespace]=function(e){return(t={},n)=>{const r=e[n.type];if(!r)return t;const o=r(t,n);return Array.isArray(o)?o:{...t,...o}}}(e.reducers),i[e.namespace]={selectors:e.selectors,rootSelectors:e.rootSelectors||{}}):console.warn("Store module does not specify a namespace",e)}));const a=function(){
624
- for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){return function(){var n=e.apply(void 0,arguments),r=function(){throw new Error(Tf(15))},o={getState:n.getState,dispatch:function(){return r.apply(void 0,arguments)}},i=t.map((function(e){return e(o)}));return r=Rf.apply(void 0,i)(n.dispatch),Ef(Ef({},n),{},{dispatch:r})}}}(...[Ff],...n);const s=Of(If(o),r,a),l=Object.assign({},...e.map((e=>e.actionCreators))),c=function(e,t){if("function"==typeof e)return Pf(e,t);if("object"!=typeof e||null===e)throw new Error(Tf(16));var n={};for(var r in e){var o=e[r];"function"==typeof o&&(n[r]=Pf(o,t))}return n}(l,s.dispatch),u=function(e,t){const n={};return Object.keys(e).forEach((r=>{const{selectors:o,rootSelectors:i={}}=e[r];Object.keys(o).forEach((e=>{if(n[e])throw new Error(`Duplicate selector "${e}"`);n[e]=(...n)=>o[e](t()[r],...n)})),Object.keys(i).forEach((e=>{if(n[e])throw new Error(`Duplicate selector "${e}"`);n[e]=(...n)=>i[e](t(),...n)}))})),n}(i,s.getState)
625
- ;return Object.assign(s,c,u),s}function Hf(e,t){if(!(e instanceof Function)){const t=e;e=()=>t}return{initialState:e,...t}}function qf(e){let t=0;return function(n){return function(r){if(!window.debug)return void n(r);++t;const o=r.type+" ("+t.toString()+")";console.group(o),console.log("Prev State:",e.getState()),console.log("Action:",r),n(r),console.log("Next State:",e.getState()),console.groupEnd()}}}const Uf={API_REQUEST_STARTED:e=>({...e,activeApiRequests:e.activeApiRequests+1}),API_REQUEST_FINISHED(e){if(0===e.activeApiRequests)throw new Error("API_REQUEST_FINISHED action when no requests were active");return{...e,activeApiRequests:e.activeApiRequests-1}},ANNOTATION_SAVE_STARTED(e,t){let n=[];t.annotation.$tag&&!e.activeAnnotationSaveRequests.includes(t.annotation.$tag)&&n.push(t.annotation.$tag);const r=e.activeAnnotationSaveRequests.concat(n);return{...e,activeAnnotationSaveRequests:r}},ANNOTATION_SAVE_FINISHED(e,t){const n=e.activeAnnotationSaveRequests.filter((e=>e!==t.annotation.$tag));return{...e,
626
- activeAnnotationSaveRequests:n}},ANNOTATION_FETCH_STARTED:e=>({...e,activeAnnotationFetches:e.activeAnnotationFetches+1}),ANNOTATION_FETCH_FINISHED(e){if(0===e.activeAnnotationFetches)throw new Error("ANNOTATION_FETCH_FINISHED action when no annotation fetches were active");return{...e,hasFetchedAnnotations:!0,activeAnnotationFetches:e.activeAnnotationFetches-1}},SET_ANNOTATION_RESULT_COUNT:(e,t)=>({annotationResultCount:t.resultCount})},$f=sf(Uf);const Gf=Hf({activeAnnotationSaveRequests:[],activeApiRequests:0,activeAnnotationFetches:0,hasFetchedAnnotations:!1,annotationResultCount:null},{reducers:Uf,namespace:"activity",actionCreators:{annotationFetchStarted:function(){return{type:$f.ANNOTATION_FETCH_STARTED}},annotationFetchFinished:function(){return{type:$f.ANNOTATION_FETCH_FINISHED}},annotationSaveStarted:function(e){return{type:$f.ANNOTATION_SAVE_STARTED,annotation:e}},annotationSaveFinished:function(e){return{type:$f.ANNOTATION_SAVE_FINISHED,annotation:e}},apiRequestStarted:function(){return{
627
- type:$f.API_REQUEST_STARTED}},apiRequestFinished:function(){return{type:$f.API_REQUEST_FINISHED}},setAnnotationResultCount:function(e){return{type:$f.SET_ANNOTATION_RESULT_COUNT,resultCount:e}}},selectors:{hasFetchedAnnotations:function(e){return e.hasFetchedAnnotations},isLoading:function(e){return e.activeApiRequests>0||!e.hasFetchedAnnotations},isFetchingAnnotations:function(e){return e.activeAnnotationFetches>0},isSavingAnnotation:function(e,t){return!!t.$tag&&e.activeAnnotationSaveRequests.includes(t.$tag)},annotationResultCount:function(e){return e.annotationResultCount}}});var Vf=function(e,t){return e===t};function Wf(e,t){var n,r,o="object"==typeof t?t:{equalityCheck:t},i=o.equalityCheck,a=void 0===i?Vf:i,s=o.maxSize,l=void 0===s?1:s,c=o.resultEqualityCheck,u=function(e){return function(t,n){if(null===t||null===n||t.length!==n.length)return!1;for(var r=t.length,o=0;o<r;o++)if(!e(t[o],n[o]))return!1;return!0}}(a),h=1===l?(n=u,{get:function(e){return r&&n(r.key,e)?r.value:"NOT_FOUND"},
628
- put:function(e,t){r={key:e,value:t}},getEntries:function(){return r?[r]:[]},clear:function(){r=void 0}}):function(e,t){var n=[];function r(e){var r=n.findIndex((function(n){return t(e,n.key)}));if(r>-1){var o=n[r];return r>0&&(n.splice(r,1),n.unshift(o)),o.value}return"NOT_FOUND"}return{get:r,put:function(t,o){"NOT_FOUND"===r(t)&&(n.unshift({key:t,value:o}),n.length>e&&n.pop())},getEntries:function(){return n},clear:function(){n=[]}}}(l,u);function d(){var t=h.get(arguments);if("NOT_FOUND"===t){if(t=e.apply(null,arguments),c){var n=h.getEntries(),r=n.find((function(e){return c(e.value,t)}));r&&(t=r.value)}h.put(arguments,t)}return t}return d.clearCache=function(){return h.clear()},d}function Yf(e){var t=Array.isArray(e[0])?e[0]:e;if(!t.every((function(e){return"function"==typeof e}))){var n=t.map((function(e){return"function"==typeof e?"function "+(e.name||"unnamed")+"()":typeof e})).join(", ")
629
- ;throw new Error("createSelector expects all input-selectors to be functions, but received the following types: ["+n+"]")}return t}function Kf(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=function(){for(var t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];var i,a=0,s={memoizeOptions:void 0},l=r.pop();if("object"==typeof l&&(s=l,l=r.pop()),"function"!=typeof l)throw new Error("createSelector expects an output function after the inputs, but received: ["+typeof l+"]");var c=s,u=c.memoizeOptions,h=void 0===u?n:u,d=Array.isArray(h)?h:[h],p=Yf(r),m=e.apply(void 0,[function(){return a++,l.apply(null,arguments)}].concat(d)),f=e((function(){for(var e=[],t=p.length,n=0;n<t;n++)e.push(p[n].apply(null,arguments));return i=m.apply(null,e)}));return Object.assign(f,{resultFunc:l,memoizedResultFunc:m,dependencies:p,lastResult:function(){return i},recomputations:function(){return a},resetRecomputations:function(){return a=0}}),f};return o}var Xf=Kf(Wf)
630
- ;function Zf(e,t){return e.reduce(((e,n)=>t(n)?e+1:e),0)}function Jf(e){const t={};return e.forEach((e=>t[e]=!0)),t}function Qf(e){return Object.keys(e).filter((t=>!0===e[t]))}const eg={CHANGE_ROUTE:(e,{name:t,params:n})=>({name:t,params:n})},tg=sf(eg);const ng=Hf({name:null,params:{}},{namespace:"route",reducers:eg,actionCreators:{changeRoute:function(e,t={}){return{type:tg.CHANGE_ROUTE,name:e,params:t}}},selectors:{route:function(e){return e.name},routeParams:function(e){return e.params}}});function rg(e,t){return e.find((e=>e.id===t))}function og(e,t){return e.find((e=>e.$tag===t))}const ig={ADD_ANNOTATIONS(e,t){const n={},r={},o=[],i=[],a=[];let s=e.nextTag;return t.annotations.forEach((t=>{let i;t.id&&(i=rg(e.annotations,t.id)),!i&&t.$tag&&(i=og(e.annotations,t.$tag)),i?(a.push(Object.assign({},i,t)),t.id&&(n[t.id]=!0),i.$tag&&(r[i.$tag]=!0)):(o.push(function(e,t){let n=e.$orphan;return e.id||(n=!1),Object.assign({},e,{$anchorTimeout:!1,$tag:e.$tag||t,$orphan:n})}(t,"t"+s)),++s)})),
631
- e.annotations.forEach((e=>{n[e.id]||r[e.$tag]||i.push(e)})),{annotations:o.concat(a).concat(i),nextTag:s}},CLEAR_ANNOTATIONS:()=>({annotations:[],focused:{},highlighted:{}}),FOCUS_ANNOTATIONS:(e,t)=>({focused:Jf(t.focusedTags)}),HIDE_ANNOTATION:(e,t)=>({annotations:e.annotations.map((e=>e.id!==t.id?e:{...e,hidden:!0}))}),HIGHLIGHT_ANNOTATIONS:(e,t)=>({highlighted:t.highlighted}),REMOVE_ANNOTATIONS:(e,t)=>({annotations:[...t.remainingAnnotations]}),UNHIDE_ANNOTATION:(e,t)=>({annotations:e.annotations.map((e=>e.id!==t.id?e:Object.assign({},e,{hidden:!1})))}),UPDATE_ANCHOR_STATUS:(e,t)=>({annotations:e.annotations.map((e=>{if(!t.statusUpdates.hasOwnProperty(e.$tag))return e;const n=t.statusUpdates[e.$tag];return"timeout"===n?Object.assign({},e,{$anchorTimeout:!0}):Object.assign({},e,{$orphan:"orphan"===n})}))}),UPDATE_FLAG_STATUS:(e,t)=>({annotations:e.annotations.map((e=>{if(e.id&&e.id===t.id){if(e.flagged===t.isFlagged)return e;const n=Object.assign({},e,{flagged:t.isFlagged});if(n.moderation){
632
- const e=t.isFlagged?1:-1;n.moderation={...n.moderation,flagCount:n.moderation.flagCount+e}}return n}return e}))})},ag=sf(ig);function sg(e){return(t,n)=>{const r=function(e,t){const n={},r={};return t.forEach((e=>{e.id&&(n[e.id]=!0),e.$tag&&(r[e.$tag]=!0)})),e.filter((e=>!(e.id&&e.id in n||e.$tag&&e.$tag in r)))}(n().annotations.annotations,e);t({type:ag.REMOVE_ANNOTATIONS,annotationsToRemove:e,remainingAnnotations:r})}}function lg(e){return{type:ag.UPDATE_ANCHOR_STATUS,statusUpdates:e}}const cg=Hf({annotations:[],focused:{},highlighted:{},nextTag:1},{namespace:"annotations",reducers:ig,actionCreators:{addAnnotations:function(e){return function(t,n){const r=e.filter((e=>!e.id||!rg(n().annotations.annotations,e.id)));if(t({type:ag.ADD_ANNOTATIONS,annotations:e,currentAnnotationCount:n().annotations.annotations.length}),"sidebar"!==ng.selectors.route(n().route))return;const o=r.filter(Ii).map((e=>e.id));o.length>0&&setTimeout((()=>{
633
- const e=n().annotations.annotations,r=o.map((t=>t?rg(e,t):null)).filter((e=>e&&Ii(e))).reduce(((e,t)=>(e[t.$tag]="timeout",e)),{});t(lg(r))}),500)}},clearAnnotations:function(){return{type:ag.CLEAR_ANNOTATIONS}},focusAnnotations:function(e){return{type:ag.FOCUS_ANNOTATIONS,focusedTags:e}},hideAnnotation:function(e){return{type:ag.HIDE_ANNOTATION,id:e}},highlightAnnotations:function(e){return{type:ag.HIGHLIGHT_ANNOTATIONS,highlighted:Jf(e)}},removeAnnotations:sg,unhideAnnotation:function(e){return{type:ag.UNHIDE_ANNOTATION,id:e}},updateAnchorStatus:lg,updateFlagStatus:function(e,t){return{type:ag.UPDATE_FLAG_STATUS,id:e,isFlagged:t}}},selectors:{allAnnotations:function(e){return e.annotations},annotationCount:Xf((e=>e.annotations),(e=>Zf(e,Fi))),annotationExists:function(e,t){return e.annotations.some((e=>e.id===t))},findAnnotationByID:function(e,t){return rg(e.annotations,t)},findIDsForTags:function(e,t){const n=[];return t.forEach((t=>{const r=og(e.annotations,t);r&&r.id&&n.push(r.id)})),n},
634
- focusedAnnotations:Xf((e=>e.focused),(e=>Qf(e))),highlightedAnnotations:Xf((e=>e.highlighted),(e=>Qf(e))),isAnnotationFocused:function(e,t){return!0===e.focused[t]},isWaitingToAnchorAnnotations:Xf((e=>e.annotations),(e=>e.some(Ii))),newAnnotations:Xf((e=>e.annotations),(e=>e.filter((e=>Li(e)&&!Ri(e))))),newHighlights:Xf((e=>e.annotations),(e=>e.filter((e=>Li(e)&&Ri(e))))),noteCount:Xf((e=>e.annotations),(e=>Zf(e,Bi))),orphanCount:Xf((e=>e.annotations),(e=>Zf(e,Di))),savedAnnotations:function(e){return e.annotations.filter((e=>Mi(e)))}}}),ug={SET_DEFAULT:function(e,t){return{[t.defaultKey]:t.value}}},hg=sf(ug);const dg=Hf({annotationPrivacy:null,focusedGroup:null},{namespace:"defaults",reducers:ug,actionCreators:{setDefault:function(e,t){return{type:hg.SET_DEFAULT,defaultKey:e,value:t}}},selectors:{getDefault:function(e,t){return e[t]},getDefaults:function(e){return e}}});const pg={UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED:(e,t)=>({directLinkedGroupFetchFailed:t.directLinkedGroupFetchFailed}),
635
- UPDATE_DIRECT_LINKED_GROUP_ID:(e,t)=>({directLinkedGroupId:t.directLinkedGroupId}),UPDATE_DIRECT_LINKED_ANNOTATION_ID:(e,t)=>({directLinkedAnnotationId:t.directLinkedAnnotationId}),CLEAR_DIRECT_LINKED_IDS:()=>({directLinkedAnnotationId:null,directLinkedGroupId:null}),CLEAR_SELECTION:function(){return{directLinkedAnnotationId:null,directLinkedGroupId:null,directLinkedGroupFetchFailed:!1}}},mg=sf(pg);const fg=Hf((function(e){return{directLinkedGroupId:e.group||null,directLinkedAnnotationId:e.annotations||null,directLinkedGroupFetchFailed:!1}}),{namespace:"directLinked",reducers:pg,actionCreators:{setDirectLinkedGroupFetchFailed:function(){return{type:mg.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!0}},setDirectLinkedGroupId:function(e){return{type:mg.UPDATE_DIRECT_LINKED_GROUP_ID,directLinkedGroupId:e}},setDirectLinkedAnnotationId:function(e){return{type:mg.UPDATE_DIRECT_LINKED_ANNOTATION_ID,directLinkedAnnotationId:e}},clearDirectLinkedGroupFetchFailed:function(){return{
636
- type:mg.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!1}},clearDirectLinkedIds:function(){return{type:mg.CLEAR_DIRECT_LINKED_IDS}}},selectors:{directLinkedAnnotationId:function(e){return e.directLinkedAnnotationId},directLinkedGroupFetchFailed:function(e){return e.directLinkedGroupFetchFailed},directLinkedGroupId:function(e){return e.directLinkedGroupId}}});class gg{constructor(e,t){this.annotation={id:e.id,$tag:e.$tag},this.isPrivate=t.isPrivate,this.tags=t.tags,this.text=t.text}match(e){return this.annotation.$tag&&e.$tag===this.annotation.$tag||this.annotation.id&&e.id===this.annotation.id}isEmpty(){return!this.text&&0===this.tags.length}}const vg={DISCARD_ALL_DRAFTS:function(){return[]},REMOVE_DRAFT:function(e,t){return e.filter((e=>!e.match(t.annotation)))},UPDATE_DRAFT:function(e,t){const n=e.filter((e=>!e.match(t.draft.annotation)));return n.push(t.draft),n}},yg=sf(vg);function _g(e){return{type:yg.REMOVE_DRAFT,annotation:e}}function bg(e,t){const n=e
637
- ;for(let e=0;e<n.length;e++){const r=n[e];if(r.match(t))return r}return null}function wg(e,t){const n=bg(e,t);return n?n.isEmpty()?null:n:null}const xg=Xf((e=>e),(e=>e.filter((e=>!e.annotation.id)).map((e=>e.annotation)))),kg=Hf([],{namespace:"drafts",reducers:vg,actionCreators:{createDraft:function(e,t){return{type:yg.UPDATE_DRAFT,draft:new gg(e,t)}},deleteNewAndEmptyDrafts:function(){return(e,t)=>{const n=t().drafts.filter((e=>Li(e.annotation)&&!wg(t().drafts,e.annotation))).map((t=>(e(_g(t.annotation)),t.annotation)));e(sg(n))}},discardAllDrafts:function(){return{type:yg.DISCARD_ALL_DRAFTS}},removeDraft:_g},selectors:{countDrafts:function(e){return e.length},getDraft:bg,getDraftIfNotEmpty:wg,unsavedAnnotations:xg}});function Sg(e){var t,n;return!!(null!==(t=e.user)&&void 0!==t&&t.username||null!==(n=e.user)&&void 0!==n&&n.userid)}function Cg(e){if(!Sg(e))return{};const t=e.user.username||e.user.userid||"";return{user:{value:t,display:e.user.displayName||t}}}const Ag={CHANGE_FOCUS_MODE_USER:function(e,t){
638
- return{focusActive:Sg({user:t.user}),focusFilters:Cg({user:t.user})}},SET_FILTER:function(e,t){var n;const r={...e.filters,[t.filterName]:t.filterOption};return""===(null===(n=t.filterOption)||void 0===n?void 0:n.value)&&delete r[t.filterName],{filters:r}},SET_FILTER_QUERY:function(e,t){return{query:t.query}},SET_FOCUS_MODE:function(e,t){var n;return{focusActive:null!==(n=t.active)&&void 0!==n?n:!e.focusActive}},CLEAR_SELECTION:function(){return{filters:{},focusActive:!1,query:null}}},Eg=sf(Ag);const Tg=Xf((e=>e.focusActive),(e=>e.focusFilters),((e,t)=>{var n;return{active:e,configured:!(null==t||!t.user),displayName:(null==t||null===(n=t.user)||void 0===n?void 0:n.display)||""}})),Ng=Xf((e=>e.filters),(e=>e.focusActive),(e=>e.focusFilters),((e,t,n)=>t?{...n,...e}:{...e}));const Mg=Xf((e=>Ng(e)),(e=>{const t={};return Object.keys(e).forEach((n=>t[n]=e[n].value)),t}));const Lg=Hf((function(e){const t=e.focus||{};return{filters:{},focusActive:Sg(t),focusFilters:Cg(t),query:e.query||null}}),{namespace:"filters",
639
- reducers:Ag,actionCreators:{changeFocusModeUser:function(e){return{type:Eg.CHANGE_FOCUS_MODE_USER,user:e}},setFilter:function(e,t){return(n,r)=>{var o;null!==(o=r().filters.focusFilters)&&void 0!==o&&o[e]&&n({type:Eg.SET_FOCUS_MODE,active:!1}),n({type:Eg.SET_FILTER,filterName:e,filterOption:t})}},setFilterQuery:function(e){return{type:Eg.SET_FILTER_QUERY,query:e}},toggleFocusMode:function(e){return{type:Eg.SET_FOCUS_MODE,active:e}}},selectors:{filterQuery:function(e){return e.query},focusState:Tg,getFilter:function(e,t){return Ng(e)[t]},getFilters:Ng,getFilterValues:Mg,getFocusFilters:function(e){return e.focusFilters},hasAppliedFilter:function(e){return!(!e.query&&!Object.keys(Ng(e)).length)}}}),zg={CONNECT_FRAME:function(e,t){return[...e,t.frame]},DESTROY_FRAME:function(e,t){return e.filter((e=>e!==t.frame))},UPDATE_FRAME_ANNOTATION_FETCH_STATUS:function(e,t){return e.map((e=>e.uri&&e.uri===t.uri?Object.assign({},e,{isAnnotationFetchComplete:t.isAnnotationFetchComplete}):e))}},Og=sf(zg)
640
- ;const Ig=Xf((e=>e),(e=>e.find((e=>!e.id))||null));const Pg=Kf(Wf,Xm)((e=>e.reduce(((e,t)=>e.concat(function(e){let t=[e.uri];return e.metadata&&e.metadata.documentFingerprint&&(t=e.metadata.link.map((e=>e.href))),e.metadata&&e.metadata.link&&e.metadata.link.forEach((e=>{e.href.startsWith("doi:")&&t.push(e.href)})),t}(t))),[])),(e=>e)),Rg=Hf([],{namespace:"frames",reducers:zg,actionCreators:{connectFrame:function(e){return{type:Og.CONNECT_FRAME,frame:e}},destroyFrame:function(e){return{type:Og.DESTROY_FRAME,frame:e}},updateFrameAnnotationFetchStatus:function(e,t){return{type:Og.UPDATE_FRAME_ANNOTATION_FETCH_STATUS,isAnnotationFetchComplete:t,uri:e}}},selectors:{frames:function(e){return e},mainFrame:Ig,searchUris:Pg}}),Dg={features:{},preferences:{},userid:null};const Bg={UPDATE_PROFILE:function(e,t){return{profile:{...t.profile}}}},Fg=sf(Bg);const jg=Hf((function(e){var t;return{defaultAuthority:null!==(t=null==e?void 0:e.authDomain)&&void 0!==t?t:"",profile:Dg}}),{namespace:"session",reducers:Bg,
641
- actionCreators:{updateProfile:function(e){return{type:Fg.UPDATE_PROFILE,profile:e}}},selectors:{defaultAuthority:function(e){return e.defaultAuthority},hasFetchedProfile:function(e){return e.profile!==Dg},isFeatureEnabled:function(e,t){return!!e.profile.features[t]},isLoggedIn:function(e){return null!==e.profile.userid},profile:function(e){return e.profile}}}),Hg={FILTER_GROUPS(e,t){var n;if(null===(n=t.filteredGroupIds)||void 0===n||!n.length)return{filteredGroupIds:null};const r=e.groups.filter((e=>t.filteredGroupIds.includes(e.id)));if(!r.length)return{filteredGroupIds:null};let o=e.focusedGroupId;return o&&t.filteredGroupIds.includes(o)||(o=r[0].id),{filteredGroupIds:t.filteredGroupIds,focusedGroupId:o}},FOCUS_GROUP(e,t){const n=e.groups.find((e=>e.id===t.id));return n?{focusedGroupId:t.id}:(console.error(`Attempted to focus group ${t.id} which is not loaded`),{})},LOAD_GROUPS(e,t){const n=t.groups;let r=e.focusedGroupId
642
- ;return null!==e.focusedGroupId&&n.find((t=>t.id===e.focusedGroupId))||(r=n.length>0?n[0].id:null),{focusedGroupId:r,groups:t.groups}},CLEAR_GROUPS:()=>({filteredGroupIds:null,focusedGroupId:null,groups:[]})},qg=sf(Hg);function Ug(e){return e.filteredGroupIds?e.groups.filter((t=>{var n;return null===(n=e.filteredGroupIds)||void 0===n?void 0:n.includes(t.id)})):e.groups}function $g(e,t){return e.groups.find((e=>e.id===t))}const Gg=Xf((e=>Ug(e)),(e=>e.filter((e=>!e.isMember&&e.isScopedToUri)))),Vg=Xf((e=>Ug(e)),(e=>e.filter((e=>e.isScopedToUri)))),Wg=Xf((e=>Ug(e.groups)),(e=>jg.selectors.isLoggedIn(e.session)),((e,t)=>t?e.filter((e=>e.isMember)):[])),Yg=Xf((e=>Ug(e.groups)),(e=>Wg(e)),(e=>Gg(e.groups)),((e,t,n)=>e.filter((e=>!t.includes(e)&&!n.includes(e))))),Kg=Hf({filteredGroupIds:null,groups:[],focusedGroupId:null},{namespace:"groups",reducers:Hg,actionCreators:{filterGroups:function(e){return{type:qg.FILTER_GROUPS,filteredGroupIds:e}},focusGroup:function(e){return{type:qg.FOCUS_GROUP,id:e}},
643
- loadGroups:function(e){return{type:qg.LOAD_GROUPS,groups:e}},clearGroups:function(){return{type:qg.CLEAR_GROUPS}}},selectors:{allGroups:function(e){return e.groups},filteredGroups:Ug,filteredGroupIds:function(e){return e.filteredGroupIds},focusedGroup:function(e){return e.focusedGroupId?$g(e,e.focusedGroupId):null},focusedGroupId:function(e){return e.focusedGroupId},getFeaturedGroups:Gg,getGroup:$g,getInScopeGroups:Vg},rootSelectors:{getCurrentlyViewingGroups:Yg,getMyGroups:Wg}}),Xg={UPDATE_LINKS:(e,t)=>({...t.links})},Zg=sf(Xg);const Jg=Hf(null,{namespace:"links",reducers:Xg,actionCreators:{updateLinks:function(e){return{type:Zg.UPDATE_LINKS,links:e}}},selectors:{getLink:function(e,t,n={}){if(!e)return"";const r=e[t];if(!r)throw new Error(`Unknown link "${t}"`);const{url:o,unusedParams:i}=Rm(r,n),a=Object.keys(i);if(a.length>0)throw new Error(`Unused parameters: ${a.join(", ")}`);return o}}}),Qg={RECEIVE_REAL_TIME_UPDATES:(e,t)=>({pendingUpdates:{...t.pendingUpdates},pendingDeletions:{...t.pendingDeletions}
644
- }),CLEAR_PENDING_UPDATES:()=>({pendingUpdates:{},pendingDeletions:{}}),ADD_ANNOTATIONS(e,{annotations:t}){const n={...e.pendingUpdates};return t.forEach((e=>delete n[e.id])),{pendingUpdates:n}},REMOVE_ANNOTATIONS(e,{annotationsToRemove:t}){const n={...e.pendingUpdates},r={...e.pendingDeletions};return t.forEach((e=>{delete n[e.id],delete r[e.id]})),{pendingUpdates:n,pendingDeletions:r}},FOCUS_GROUP:()=>({pendingUpdates:{},pendingDeletions:{}})},ev=sf(Qg);const tv=Xf((e=>[e.pendingUpdates,e.pendingDeletions]),(([e,t])=>Object.keys(e).length+Object.keys(t).length));const nv=Hf({pendingUpdates:{},pendingDeletions:{}},{namespace:"realTimeUpdates",reducers:Qg,actionCreators:{receiveRealTimeUpdates:function({updatedAnnotations:e=[],deletedAnnotations:t=[]}){return(n,r)=>{const o={...r().realTimeUpdates.pendingUpdates},i={...r().realTimeUpdates.pendingDeletions};e.forEach((e=>{const t=r().groups,n=r().route;e.group!==Kg.selectors.focusedGroupId(t)&&"sidebar"===ng.selectors.route(n)||(o[e.id]=e)})),t.forEach((e=>{
645
- const t=e.id;delete o[t];const n=r().annotations;cg.selectors.annotationExists(n,t)&&(i[t]=!0)})),n({type:ev.RECEIVE_REAL_TIME_UPDATES,pendingUpdates:o,pendingDeletions:i})}},clearPendingUpdates:function(){return{type:ev.CLEAR_PENDING_UPDATES}}},selectors:{hasPendingDeletion:function(e,t){return e.pendingDeletions.hasOwnProperty(t)},pendingDeletions:function(e){return e.pendingDeletions},pendingUpdates:function(e){return e.pendingUpdates},pendingUpdateCount:tv}}),rv={annotation:"Location",note:"Oldest",orphan:"Location"};function ov(e){const t={};return e.annotations&&!e.query&&(t[e.annotations]=!0),t}const iv=(e,t)=>t===e?{}:{selectedTab:e,sortKey:rv[e]},av={CLEAR_SELECTION:function(){return{forcedVisible:{},selected:{}}},SELECT_ANNOTATIONS:function(e,t){return{selected:t.selection}},SELECT_TAB:function(e,t){return iv(t.tab,e.selectedTab)},SET_EXPANDED:function(e,t){const n={...e.expanded};return n[t.id]=t.expanded,{expanded:n}},SET_FORCED_VISIBLE:function(e,t){return{forcedVisible:{...e.forcedVisible,
646
- [t.id]:t.visible}}},SET_SORT_KEY:function(e,t){return{sortKey:t.key}},TOGGLE_SELECTED_ANNOTATIONS:function(e,t){const n={...e.selected};return t.toggleIds.forEach((e=>{n[e]=!n[e]})),{selected:n}},ADD_ANNOTATIONS(e,t){const n=t.annotations.filter((e=>!Ni(e))),r=Zf(t.annotations,Bi)===n.length;return 0===t.currentAnnotationCount&&r?iv("note",e.selectedTab):{}},CHANGE_FOCUS_MODE_USER:function(){return{forcedVisible:{},selected:{}}},SET_FILTER:function(){return{forcedVisible:{},selected:{},expanded:{}}},SET_FILTER_QUERY:function(){return{forcedVisible:{},selected:{},expanded:{}}},SET_FOCUS_MODE:function(){return{forcedVisible:{},selected:{}}},REMOVE_ANNOTATIONS:function(e,t){let n=e.selectedTab;"orphan"===n&&0===Zf(t.remainingAnnotations,Di)&&(n="annotation");const r=e=>(t.annotationsToRemove.forEach((t=>{t.id&&delete e[t.id],t.$tag&&delete e[t.$tag]})),e);return{...iv(n,e.selectedTab),expanded:r({...e.expanded}),forcedVisible:r({...e.forcedVisible}),selected:r({...e.selected})}}},sv=sf(av);function lv(e){
647
- return e.expanded}const cv=Xf((e=>e.forcedVisible),(e=>Qf(e))),uv=Xf((e=>e.selected),(e=>Qf(e).length>0)),hv=Xf((e=>e.selected),(e=>Qf(e)));function dv(e){return e.selectedTab}const pv=Xf((e=>e),(e=>({expanded:lv(e),forcedVisible:cv(e),selected:hv(e),sortKey:mv(e),selectedTab:dv(e)})));function mv(e){return e.sortKey}const fv=Xf((e=>e.selectedTab),(e=>{const t=["Newest","Oldest"];return"note"!==e&&t.push("Location"),t})),gv=Hf((function(e){return{selected:ov(e),expanded:ov(e)||{},forcedVisible:{},selectedTab:"annotation",sortKey:rv.annotation}}),{namespace:"selection",reducers:av,actionCreators:{clearSelection:function(){return{type:sv.CLEAR_SELECTION}},selectAnnotations:function(e){return t=>{t({type:sv.CLEAR_SELECTION}),t({type:sv.SELECT_ANNOTATIONS,selection:Jf(e)})}},selectTab:function(e){return{type:sv.SELECT_TAB,tab:e}},setExpanded:function(e,t){return{type:sv.SET_EXPANDED,id:e,expanded:t}},setForcedVisible:function(e,t){return{type:sv.SET_FORCED_VISIBLE,id:e,visible:t}},setSortKey:function(e){return{
648
- type:sv.SET_SORT_KEY,key:e}},toggleSelectedAnnotations:function(e){return{type:sv.TOGGLE_SELECTED_ANNOTATIONS,toggleIds:e}}},selectors:{expandedMap:lv,forcedVisibleThreads:cv,hasSelectedAnnotations:uv,selectedAnnotations:hv,selectedTab:dv,selectionState:pv,sortKey:mv,sortKeys:fv}}),vv={OPEN_SIDEBAR_PANEL:function(e,t){return{activePanelName:t.panelName}},CLOSE_SIDEBAR_PANEL:function(e,t){let n=e.activePanelName;return t.panelName===n&&(n=null),{activePanelName:n}},TOGGLE_SIDEBAR_PANEL:function(e,t){let n;const r=e.activePanelName===t.panelName,o=void 0!==t.panelState?t.panelState:!r;return n=o?t.panelName:r&&!o?null:e.activePanelName,{activePanelName:n}}},yv=sf(vv);const _v=Hf({activePanelName:null},{namespace:"sidebarPanels",reducers:vv,actionCreators:{openSidebarPanel:function(e){return{type:yv.OPEN_SIDEBAR_PANEL,panelName:e}},closeSidebarPanel:function(e){return{type:yv.CLOSE_SIDEBAR_PANEL,panelName:e}},toggleSidebarPanel:function(e,t){return{type:yv.TOGGLE_SIDEBAR_PANEL,panelName:e,panelState:t}}},
649
- selectors:{isSidebarPanelOpen:function(e,t){return e.activePanelName===t}}}),bv={ADD_MESSAGE:function(e,t){return{messages:e.messages.concat({...t.message})}},REMOVE_MESSAGE:function(e,t){return{messages:e.messages.filter((e=>e.id!==t.id))}},UPDATE_MESSAGE:function(e,t){return{messages:e.messages.map((e=>e.id&&e.id===t.message.id?{...t.message}:e))}}},wv=sf(bv);const xv=Hf({messages:[]},{namespace:"toastMessages",reducers:bv,actionCreators:{addToastMessage:function(e){return{type:wv.ADD_MESSAGE,message:e}},removeToastMessage:function(e){return{type:wv.REMOVE_MESSAGE,id:e}},updateToastMessage:function(e){return{type:wv.UPDATE_MESSAGE,message:e}}},selectors:{getToastMessage:function(e,t){return e.messages.find((e=>e.id===t))},getToastMessages:function(e){return e.messages},hasToastMessage:function(e,t,n){return e.messages.some((e=>e.type===t&&e.message===n))}}}),kv={SET_SIDEBAR_OPENED:(e,t)=>!0===t.opened?{sidebarHasOpened:!0}:{}},Sv=sf(kv);const Cv=Hf({sidebarHasOpened:!1},{namespace:"viewer",reducers:kv,
650
- actionCreators:{setSidebarOpened:function(e){return{type:Sv.SET_SIDEBAR_OPENED,opened:e}}},selectors:{hasSidebarOpened:function(e){return e.sidebarHasOpened}}});function Av(e){return jf([Gf,cg,dg,fg,kg,Lg,Rg,Jg,Kg,nv,ng,gv,jg,_v,xv,Cv],[e],[qf])}Av.$inject=["settings"];class Ev{constructor(){this._providers=new Map,this._instances=new Map,this._constructing=new Set}get(e){if(this._instances.has(e))return this._instances.get(e);const t=this._providers.get(e);if(!t)throw new Error(`"${e}" is not registered`);if("value"in t)return this._instances.set(e,t.value),t.value;if(this._constructing.has(e))throw new Error(`Encountered a circular dependency when constructing "${e}"`);this._constructing.add(e);try{const n=[],r="class"in t&&t.class.$inject||"factory"in t&&t.factory.$inject||[];for(const t of r)try{n.push(this.get(t))}catch(n){const r=new Error(`Failed to construct dependency "${t}" of "${e}": ${n.message}`);throw r.cause=n,r}let o;if(t.class)o=new t.class(...n);else{o=(0,t.factory)(...n)}
651
- return this._instances.set(e,o),o}finally{this._constructing.delete(e)}}register(e,t){if("function"==typeof t)t={class:t};else if(!function(e){return"object"==typeof e&&null!==e&&("value"in e||"function"==typeof e.class||"function"==typeof e.factory)}(t))throw new Error(`Invalid provider for "${e}"`);return this._providers.set(e,t),this}run(e){const t="Injector.run";this.register(t,{factory:e});try{return this.get(t)}finally{this._instances.delete(t),this._providers.delete(t)}}}const Tv=function(t){for(var n={},r=t.querySelectorAll("script.js-hypothesis-config"),o=0;o<r.length;o++){var i=void 0;try{i=JSON.parse(r[o].textContent||"")}catch(e){console.warn("Could not parse settings from js-hypothesis-config tags",e),i={}}e(n,i)}return n}(document),Nv=function(e){const{version:t,origin:n}=P(e.location.href);return"1.1006.0"!==t?(console.warn(`The Hypothesis sidebar is using a different version (1.1006.0) than the host page (${t}). It may not work.`),
652
- !1):"null"===e.origin?(console.warn("Hypothesis has been loaded in a sandboxed frame. This is not supported."),!1):e.origin===n||(console.warn(`The Hypothesis sidebar is running in a different origin (${e.origin}) than expected (${n}). It may not work.`),!1)}(window);function Mv(e,t){e.setClientId(t.clientId)}function Lv(e,t,n){e.load(),t.load(),n.sync()}function zv(e,t,n,r){e.init(),t.init(),n.init(),r.init()}function Ov(e,t){"sidebar"===t.route()&&e.connect()}Tv.sentry&&Nv&&function(e){const t=function(){let e=import.meta.url;return e?new URL(e).origin:null}(),n=t?[t]:void 0;Er({dsn:e.dsn,environment:e.environment,allowUrls:n,ignoreErrors:["Network request failed","Object Not Found Matching Id"],release:"1.1006.0",beforeSend:(e,t)=>{if(Mr>=5)return V("Client-side Sentry quota reached. No further Sentry events will be sent"),null;++Mr;try{const n=t&&t.originalException;n instanceof Event&&Object.assign(e.extra,{type:n.type,detail:n.detail,isTrusted:n.isTrusted})}catch(e){}return e}});try{
653
- Yt("host_config",P(window.location.href))}catch(e){}Yt("loaded_scripts",Array.from(document.querySelectorAll("script")).filter((e=>!e.type||e.type.match(/javascript|module/))).map((e=>e.src||"<inline>"))),Nr(((e,t)=>{Wt(e,{tags:{context:t}})}))}(Tv.sentry),function(e){e.addEventListener("click",(e=>{const t=e.target;if("A"===t.tagName){const e=t;"_blank"===e.target&&(e.rel="noopener")}}))}(document.body),function(e=n){let t=!1;try{document.createElement("div").dir="auto"}catch(e){t=!0}if(t){const t=e.vnode;e.vnode=e=>{if("string"==typeof e.type){const t=e.props;"dir"in t&&"auto"===t.dir&&(t.dir="")}t&&t(e)}}}(),Mv.$inject=["api","streamer"],Lv.$inject=["groups","session","router"],zv.$inject=["autosaveService","features","persistedDefaults","serviceURL"],Ov.$inject=["frameSync","store"],function(e,{reset:t=!1}={}){t&&bo.clear();for(let[t,n]of Object.entries(e))bo.set(t,n)}(ti);const Iv=document.querySelector("hypothesis-app");!function(e=window){e.addEventListener("message",J)}(),async function(e,t=window){
619
+ Object.keys(this._configMessages).forEach((t=>{this._configMessages[t]&&e.send(this._configMessages[t])}))}setConfig(e,t){var n;this._configMessages[e]=t,null!==(n=this._socket)&&void 0!==n&&n.isConnected()&&this._socket.send(t)}async _reconnect(){var e;const t=await this._websocketURL;if(!t)return;let n,r;null===(e=this._socket)||void 0===e||e.close();try{n=await this._auth.getAccessToken()}catch(e){throw console.error("Failed to fetch token for WebSocket authentication",e),e}if(n){const e=new URL(t);e.searchParams.set("access_token",n),r=e.toString()}else r=t;const o=new wf(r);o.on("open",(()=>{this._reconnectionAttempts=0,this._sendClientConfig(o)})),o.on("disconnect",(()=>{if(++this._reconnectionAttempts,this._reconnectionAttempts<10){const e=1e3*2**this._reconnectionAttempts;setTimeout((()=>this._reconnect()),e)}else console.error("Gave up trying to reconnect to Hypothesis real time update service")})),o.on("error",(e=>this._handleSocketError(t,e))),o.on("message",(e=>this._handleSocketMessage(e))),
620
+ this._socket=o,this.setConfig("client-id",{messageType:"client_id",value:this.clientId}),this.setConfig("auth-check",{type:"whoami",id:1})}async connect(e={}){var t;this._updateImmediately=null===(t=e.applyUpdatesImmediately)||void 0===t||t,this._reconnectSetUp||(this._reconnectSetUp=!0,Jm(this._store.subscribe,(()=>this._store.profile().userid),(()=>{this._reconnect()}))),this._socket||await this._reconnect()}}xf.$inject=["store","apiRoutes","auth","groups","session"];class kf{constructor(e){this._storage=e}filter(e,t=null){const n=this._storage.getObject("hypothesis.user.tags.list")||[];let r=0;return n.filter((n=>{if(null!==t&&r>=t)return!1;const o=n.split(/\W+/),i=new RegExp(`^${Y(e)}`,"i");return!(!o.some((e=>e.match(i)))&&!n.match(i))&&(++r,!0)}))}store(e){const t=this._storage.getObject("hypothesis.user.tags.map")||{};e.forEach((e=>{t[e]?(t[e].count+=1,t[e].updated=Date.now()):t[e]={text:e,count:1,updated:Date.now()}})),this._storage.setObject("hypothesis.user.tags.map",t)
621
+ ;const n=Object.keys(t).sort(((e,n)=>t[e].count!==t[n].count?t[n].count-t[e].count:e.localeCompare(n)));this._storage.setObject("hypothesis.user.tags.list",n)}}kf.$inject=["localStorage"];class Sf{constructor(e){this._store=e}forceVisible(e){e.children.forEach((e=>{this.forceVisible(e)})),e.visible||this._store.setForcedVisible(e.id,!0)}}Sf.$inject=["store"];class Cf{constructor(e){this._store=e}dismiss(e){const t=this._store.getToastMessage(e);t&&!t.isDismissed&&(this._store.updateToastMessage({...t,isDismissed:!0}),setTimeout((()=>{this._store.removeToastMessage(e)}),500))}_addMessage(e,t,{autoDismiss:n=!0,moreInfoURL:r=""}={}){if(this._store.hasToastMessage(e,t))return;const o=H(10),i={type:e,id:o,message:t,moreInfoURL:r};this._store.addToastMessage({isDismissed:!1,...i}),n&&setTimeout((()=>{this.dismiss(o)}),5e3)}error(e,t){this._addMessage("error",e,t)}success(e,t){this._addMessage("success",e,t)}notice(e,t){this._addMessage("notice",e,t)}}function Af(e,t,n){return t in e?Object.defineProperty(e,t,{
622
+ value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ef(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Tf(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ef(Object(n),!0).forEach((function(t){Af(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ef(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Nf(e){return"Minified Redux error #"+e+"; visit https://redux.js.org/Errors?code="+e+" for the full message or use the non-minified dev environment for full errors. "}Cf.$inject=["store"];var Mf="function"==typeof Symbol&&Symbol.observable||"@@observable",Lf=function(){return Math.random().toString(36).substring(7).split("").join(".")},zf={INIT:"@@redux/INIT"+Lf(),
623
+ REPLACE:"@@redux/REPLACE"+Lf(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Lf()}};function Of(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function If(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(Nf(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(Nf(1));return n(If)(e,t)}if("function"!=typeof e)throw new Error(Nf(2));var o=e,i=t,a=[],s=a,l=!1;function c(){s===a&&(s=a.slice())}function u(){if(l)throw new Error(Nf(3));return i}function h(e){if("function"!=typeof e)throw new Error(Nf(4));if(l)throw new Error(Nf(5));var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error(Nf(6));t=!1,c();var n=s.indexOf(e);s.splice(n,1),a=null}}}function d(e){if(!Of(e))throw new Error(Nf(7));if(void 0===e.type)throw new Error(Nf(8))
624
+ ;if(l)throw new Error(Nf(9));try{l=!0,i=o(i,e)}finally{l=!1}for(var t=a=s,n=0;n<t.length;n++){(0,t[n])()}return e}function p(e){if("function"!=typeof e)throw new Error(Nf(10));o=e,d({type:zf.REPLACE})}function m(){var e,t=h;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(Nf(11));function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[Mf]=function(){return this},e}return d({type:zf.INIT}),(r={dispatch:d,subscribe:h,getState:u,replaceReducer:p})[Mf]=m,r}function Pf(e){for(var t=Object.keys(e),n={},r=0;r<t.length;r++){var o=t[r];"function"==typeof e[o]&&(n[o]=e[o])}var i,a=Object.keys(n);try{!function(e){Object.keys(e).forEach((function(t){var n=e[t];if(void 0===n(void 0,{type:zf.INIT}))throw new Error(Nf(12));if(void 0===n(void 0,{type:zf.PROBE_UNKNOWN_ACTION()}))throw new Error(Nf(13))}))}(n)}catch(e){i=e}return function(e,t){if(void 0===e&&(e={}),i)throw i;for(var r=!1,o={},s=0;s<a.length;s++){var l=a[s],c=n[l],u=e[l],h=c(u,t);if(void 0===h)throw t&&t.type,
625
+ new Error(Nf(14));o[l]=h,r=r||h!==u}return(r=r||a.length!==Object.keys(e).length)?o:e}}function Rf(e,t){return function(){return t(e.apply(this,arguments))}}function Df(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}function Bf(e){return function(t){var n=t.dispatch,r=t.getState;return function(t){return function(o){return"function"==typeof o?o(n,r,e):t(o)}}}}var Ff=Bf();Ff.withExtraArgument=Bf;var jf=Ff;function Hf(e,t=[],n=[]){const r={},o={},i={};e.forEach((e=>{e.namespace?(r[e.namespace]=e.initialState(...t),o[e.namespace]=function(e){return(t={},n)=>{const r=e[n.type];if(!r)return t;const o=r(t,n);return Array.isArray(o)?o:{...t,...o}}}(e.reducers),i[e.namespace]={selectors:e.selectors,rootSelectors:e.rootSelectors||{}}):console.warn("Store module does not specify a namespace",e)}));const a=function(){
626
+ for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){return function(){var n=e.apply(void 0,arguments),r=function(){throw new Error(Nf(15))},o={getState:n.getState,dispatch:function(){return r.apply(void 0,arguments)}},i=t.map((function(e){return e(o)}));return r=Df.apply(void 0,i)(n.dispatch),Tf(Tf({},n),{},{dispatch:r})}}}(...[jf],...n);const s=If(Pf(o),r,a),l=Object.assign({},...e.map((e=>e.actionCreators))),c=function(e,t){if("function"==typeof e)return Rf(e,t);if("object"!=typeof e||null===e)throw new Error(Nf(16));var n={};for(var r in e){var o=e[r];"function"==typeof o&&(n[r]=Rf(o,t))}return n}(l,s.dispatch),u=function(e,t){const n={};return Object.keys(e).forEach((r=>{const{selectors:o,rootSelectors:i={}}=e[r];Object.keys(o).forEach((e=>{if(n[e])throw new Error(`Duplicate selector "${e}"`);n[e]=(...n)=>o[e](t()[r],...n)})),Object.keys(i).forEach((e=>{if(n[e])throw new Error(`Duplicate selector "${e}"`);n[e]=(...n)=>i[e](t(),...n)}))})),n}(i,s.getState)
627
+ ;return Object.assign(s,c,u),s}function qf(e,t){if(!(e instanceof Function)){const t=e;e=()=>t}return{initialState:e,...t}}function Uf(e){let t=0;return function(n){return function(r){if(!window.debug)return void n(r);++t;const o=r.type+" ("+t.toString()+")";console.group(o),console.log("Prev State:",e.getState()),console.log("Action:",r),n(r),console.log("Next State:",e.getState()),console.groupEnd()}}}const $f={API_REQUEST_STARTED:e=>({...e,activeApiRequests:e.activeApiRequests+1}),API_REQUEST_FINISHED(e){if(0===e.activeApiRequests)throw new Error("API_REQUEST_FINISHED action when no requests were active");return{...e,activeApiRequests:e.activeApiRequests-1}},ANNOTATION_SAVE_STARTED(e,t){let n=[];t.annotation.$tag&&!e.activeAnnotationSaveRequests.includes(t.annotation.$tag)&&n.push(t.annotation.$tag);const r=e.activeAnnotationSaveRequests.concat(n);return{...e,activeAnnotationSaveRequests:r}},ANNOTATION_SAVE_FINISHED(e,t){const n=e.activeAnnotationSaveRequests.filter((e=>e!==t.annotation.$tag));return{...e,
628
+ activeAnnotationSaveRequests:n}},ANNOTATION_FETCH_STARTED:e=>({...e,activeAnnotationFetches:e.activeAnnotationFetches+1}),ANNOTATION_FETCH_FINISHED(e){if(0===e.activeAnnotationFetches)throw new Error("ANNOTATION_FETCH_FINISHED action when no annotation fetches were active");return{...e,hasFetchedAnnotations:!0,activeAnnotationFetches:e.activeAnnotationFetches-1}},SET_ANNOTATION_RESULT_COUNT:(e,t)=>({annotationResultCount:t.resultCount})},Gf=lf($f);const Vf=qf({activeAnnotationSaveRequests:[],activeApiRequests:0,activeAnnotationFetches:0,hasFetchedAnnotations:!1,annotationResultCount:null},{reducers:$f,namespace:"activity",actionCreators:{annotationFetchStarted:function(){return{type:Gf.ANNOTATION_FETCH_STARTED}},annotationFetchFinished:function(){return{type:Gf.ANNOTATION_FETCH_FINISHED}},annotationSaveStarted:function(e){return{type:Gf.ANNOTATION_SAVE_STARTED,annotation:e}},annotationSaveFinished:function(e){return{type:Gf.ANNOTATION_SAVE_FINISHED,annotation:e}},apiRequestStarted:function(){return{
629
+ type:Gf.API_REQUEST_STARTED}},apiRequestFinished:function(){return{type:Gf.API_REQUEST_FINISHED}},setAnnotationResultCount:function(e){return{type:Gf.SET_ANNOTATION_RESULT_COUNT,resultCount:e}}},selectors:{hasFetchedAnnotations:function(e){return e.hasFetchedAnnotations},isLoading:function(e){return e.activeApiRequests>0||!e.hasFetchedAnnotations},isFetchingAnnotations:function(e){return e.activeAnnotationFetches>0},isSavingAnnotation:function(e,t){return!!t.$tag&&e.activeAnnotationSaveRequests.includes(t.$tag)},annotationResultCount:function(e){return e.annotationResultCount}}});var Wf=function(e,t){return e===t};function Yf(e,t){var n,r,o="object"==typeof t?t:{equalityCheck:t},i=o.equalityCheck,a=void 0===i?Wf:i,s=o.maxSize,l=void 0===s?1:s,c=o.resultEqualityCheck,u=function(e){return function(t,n){if(null===t||null===n||t.length!==n.length)return!1;for(var r=t.length,o=0;o<r;o++)if(!e(t[o],n[o]))return!1;return!0}}(a),h=1===l?(n=u,{get:function(e){return r&&n(r.key,e)?r.value:"NOT_FOUND"},
630
+ put:function(e,t){r={key:e,value:t}},getEntries:function(){return r?[r]:[]},clear:function(){r=void 0}}):function(e,t){var n=[];function r(e){var r=n.findIndex((function(n){return t(e,n.key)}));if(r>-1){var o=n[r];return r>0&&(n.splice(r,1),n.unshift(o)),o.value}return"NOT_FOUND"}return{get:r,put:function(t,o){"NOT_FOUND"===r(t)&&(n.unshift({key:t,value:o}),n.length>e&&n.pop())},getEntries:function(){return n},clear:function(){n=[]}}}(l,u);function d(){var t=h.get(arguments);if("NOT_FOUND"===t){if(t=e.apply(null,arguments),c){var n=h.getEntries(),r=n.find((function(e){return c(e.value,t)}));r&&(t=r.value)}h.put(arguments,t)}return t}return d.clearCache=function(){return h.clear()},d}function Kf(e){var t=Array.isArray(e[0])?e[0]:e;if(!t.every((function(e){return"function"==typeof e}))){var n=t.map((function(e){return"function"==typeof e?"function "+(e.name||"unnamed")+"()":typeof e})).join(", ")
631
+ ;throw new Error("createSelector expects all input-selectors to be functions, but received the following types: ["+n+"]")}return t}function Xf(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=function(){for(var t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];var i,a=0,s={memoizeOptions:void 0},l=r.pop();if("object"==typeof l&&(s=l,l=r.pop()),"function"!=typeof l)throw new Error("createSelector expects an output function after the inputs, but received: ["+typeof l+"]");var c=s,u=c.memoizeOptions,h=void 0===u?n:u,d=Array.isArray(h)?h:[h],p=Kf(r),m=e.apply(void 0,[function(){return a++,l.apply(null,arguments)}].concat(d)),f=e((function(){for(var e=[],t=p.length,n=0;n<t;n++)e.push(p[n].apply(null,arguments));return i=m.apply(null,e)}));return Object.assign(f,{resultFunc:l,memoizedResultFunc:m,dependencies:p,lastResult:function(){return i},recomputations:function(){return a},resetRecomputations:function(){return a=0}}),f};return o}var Zf=Xf(Yf)
632
+ ;function Jf(e,t){return e.reduce(((e,n)=>t(n)?e+1:e),0)}function Qf(e){const t={};return e.forEach((e=>t[e]=!0)),t}function eg(e){return Object.keys(e).filter((t=>!0===e[t]))}const tg={CHANGE_ROUTE:(e,{name:t,params:n})=>({name:t,params:n})},ng=lf(tg);const rg=qf({name:null,params:{}},{namespace:"route",reducers:tg,actionCreators:{changeRoute:function(e,t={}){return{type:ng.CHANGE_ROUTE,name:e,params:t}}},selectors:{route:function(e){return e.name},routeParams:function(e){return e.params}}});function og(e,t){return e.find((e=>e.id===t))}function ig(e,t){return e.find((e=>e.$tag===t))}const ag={ADD_ANNOTATIONS(e,t){const n={},r={},o=[],i=[],a=[];let s=e.nextTag;return t.annotations.forEach((t=>{let i;t.id&&(i=og(e.annotations,t.id)),!i&&t.$tag&&(i=ig(e.annotations,t.$tag)),i?(a.push(Object.assign({},i,t)),t.id&&(n[t.id]=!0),i.$tag&&(r[i.$tag]=!0)):(o.push(function(e,t){let n=e.$orphan;return e.id||(n=!1),Object.assign({},e,{$anchorTimeout:!1,$tag:e.$tag||t,$orphan:n})}(t,"t"+s)),++s)})),
633
+ e.annotations.forEach((e=>{n[e.id]||r[e.$tag]||i.push(e)})),{annotations:o.concat(a).concat(i),nextTag:s}},CLEAR_ANNOTATIONS:()=>({annotations:[],focused:{},highlighted:{}}),FOCUS_ANNOTATIONS:(e,t)=>({focused:Qf(t.focusedTags)}),HIDE_ANNOTATION:(e,t)=>({annotations:e.annotations.map((e=>e.id!==t.id?e:{...e,hidden:!0}))}),HIGHLIGHT_ANNOTATIONS:(e,t)=>({highlighted:t.highlighted}),REMOVE_ANNOTATIONS:(e,t)=>({annotations:[...t.remainingAnnotations]}),UNHIDE_ANNOTATION:(e,t)=>({annotations:e.annotations.map((e=>e.id!==t.id?e:Object.assign({},e,{hidden:!1})))}),UPDATE_ANCHOR_STATUS:(e,t)=>({annotations:e.annotations.map((e=>{if(!t.statusUpdates.hasOwnProperty(e.$tag))return e;const n=t.statusUpdates[e.$tag];return"timeout"===n?Object.assign({},e,{$anchorTimeout:!0}):Object.assign({},e,{$orphan:"orphan"===n})}))}),UPDATE_FLAG_STATUS:(e,t)=>({annotations:e.annotations.map((e=>{if(e.id&&e.id===t.id){if(e.flagged===t.isFlagged)return e;const n=Object.assign({},e,{flagged:t.isFlagged});if(n.moderation){
634
+ const e=t.isFlagged?1:-1;n.moderation={...n.moderation,flagCount:n.moderation.flagCount+e}}return n}return e}))})},sg=lf(ag);function lg(e){return(t,n)=>{const r=function(e,t){const n={},r={};return t.forEach((e=>{e.id&&(n[e.id]=!0),e.$tag&&(r[e.$tag]=!0)})),e.filter((e=>!(e.id&&e.id in n||e.$tag&&e.$tag in r)))}(n().annotations.annotations,e);t({type:sg.REMOVE_ANNOTATIONS,annotationsToRemove:e,remainingAnnotations:r})}}function cg(e){return{type:sg.UPDATE_ANCHOR_STATUS,statusUpdates:e}}const ug=qf({annotations:[],focused:{},highlighted:{},nextTag:1},{namespace:"annotations",reducers:ag,actionCreators:{addAnnotations:function(e){return function(t,n){const r=e.filter((e=>!e.id||!og(n().annotations.annotations,e.id)));if(t({type:sg.ADD_ANNOTATIONS,annotations:e,currentAnnotationCount:n().annotations.annotations.length}),"sidebar"!==rg.selectors.route(n().route))return;const o=r.filter(Ii).map((e=>e.id));o.length>0&&setTimeout((()=>{
635
+ const e=n().annotations.annotations,r=o.map((t=>t?og(e,t):null)).filter((e=>e&&Ii(e))).reduce(((e,t)=>(e[t.$tag]="timeout",e)),{});t(cg(r))}),500)}},clearAnnotations:function(){return{type:sg.CLEAR_ANNOTATIONS}},focusAnnotations:function(e){return{type:sg.FOCUS_ANNOTATIONS,focusedTags:e}},hideAnnotation:function(e){return{type:sg.HIDE_ANNOTATION,id:e}},highlightAnnotations:function(e){return{type:sg.HIGHLIGHT_ANNOTATIONS,highlighted:Qf(e)}},removeAnnotations:lg,unhideAnnotation:function(e){return{type:sg.UNHIDE_ANNOTATION,id:e}},updateAnchorStatus:cg,updateFlagStatus:function(e,t){return{type:sg.UPDATE_FLAG_STATUS,id:e,isFlagged:t}}},selectors:{allAnnotations:function(e){return e.annotations},annotationCount:Zf((e=>e.annotations),(e=>Jf(e,Fi))),annotationExists:function(e,t){return e.annotations.some((e=>e.id===t))},findAnnotationByID:function(e,t){return og(e.annotations,t)},findIDsForTags:function(e,t){const n=[];return t.forEach((t=>{const r=ig(e.annotations,t);r&&r.id&&n.push(r.id)})),n},
636
+ focusedAnnotations:Zf((e=>e.focused),(e=>eg(e))),highlightedAnnotations:Zf((e=>e.highlighted),(e=>eg(e))),isAnnotationFocused:function(e,t){return!0===e.focused[t]},isWaitingToAnchorAnnotations:Zf((e=>e.annotations),(e=>e.some(Ii))),newAnnotations:Zf((e=>e.annotations),(e=>e.filter((e=>Li(e)&&!Ri(e))))),newHighlights:Zf((e=>e.annotations),(e=>e.filter((e=>Li(e)&&Ri(e))))),noteCount:Zf((e=>e.annotations),(e=>Jf(e,Bi))),orphanCount:Zf((e=>e.annotations),(e=>Jf(e,Di))),savedAnnotations:function(e){return e.annotations.filter((e=>Mi(e)))}}}),hg={SET_DEFAULT:function(e,t){return{[t.defaultKey]:t.value}}},dg=lf(hg);const pg=qf({annotationPrivacy:null,focusedGroup:null},{namespace:"defaults",reducers:hg,actionCreators:{setDefault:function(e,t){return{type:dg.SET_DEFAULT,defaultKey:e,value:t}}},selectors:{getDefault:function(e,t){return e[t]},getDefaults:function(e){return e}}});const mg={UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED:(e,t)=>({directLinkedGroupFetchFailed:t.directLinkedGroupFetchFailed}),
637
+ UPDATE_DIRECT_LINKED_GROUP_ID:(e,t)=>({directLinkedGroupId:t.directLinkedGroupId}),UPDATE_DIRECT_LINKED_ANNOTATION_ID:(e,t)=>({directLinkedAnnotationId:t.directLinkedAnnotationId}),CLEAR_DIRECT_LINKED_IDS:()=>({directLinkedAnnotationId:null,directLinkedGroupId:null}),CLEAR_SELECTION:function(){return{directLinkedAnnotationId:null,directLinkedGroupId:null,directLinkedGroupFetchFailed:!1}}},fg=lf(mg);const gg=qf((function(e){return{directLinkedGroupId:e.group||null,directLinkedAnnotationId:e.annotations||null,directLinkedGroupFetchFailed:!1}}),{namespace:"directLinked",reducers:mg,actionCreators:{setDirectLinkedGroupFetchFailed:function(){return{type:fg.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!0}},setDirectLinkedGroupId:function(e){return{type:fg.UPDATE_DIRECT_LINKED_GROUP_ID,directLinkedGroupId:e}},setDirectLinkedAnnotationId:function(e){return{type:fg.UPDATE_DIRECT_LINKED_ANNOTATION_ID,directLinkedAnnotationId:e}},clearDirectLinkedGroupFetchFailed:function(){return{
638
+ type:fg.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!1}},clearDirectLinkedIds:function(){return{type:fg.CLEAR_DIRECT_LINKED_IDS}}},selectors:{directLinkedAnnotationId:function(e){return e.directLinkedAnnotationId},directLinkedGroupFetchFailed:function(e){return e.directLinkedGroupFetchFailed},directLinkedGroupId:function(e){return e.directLinkedGroupId}}});class vg{constructor(e,t){this.annotation={id:e.id,$tag:e.$tag},this.isPrivate=t.isPrivate,this.tags=t.tags,this.text=t.text}match(e){return this.annotation.$tag&&e.$tag===this.annotation.$tag||this.annotation.id&&e.id===this.annotation.id}isEmpty(){return!this.text&&0===this.tags.length}}const yg={DISCARD_ALL_DRAFTS:function(){return[]},REMOVE_DRAFT:function(e,t){return e.filter((e=>!e.match(t.annotation)))},UPDATE_DRAFT:function(e,t){const n=e.filter((e=>!e.match(t.draft.annotation)));return n.push(t.draft),n}},_g=lf(yg);function bg(e){return{type:_g.REMOVE_DRAFT,annotation:e}}function wg(e,t){const n=e
639
+ ;for(let e=0;e<n.length;e++){const r=n[e];if(r.match(t))return r}return null}function xg(e,t){const n=wg(e,t);return n?n.isEmpty()?null:n:null}const kg=Zf((e=>e),(e=>e.filter((e=>!e.annotation.id)).map((e=>e.annotation)))),Sg=qf([],{namespace:"drafts",reducers:yg,actionCreators:{createDraft:function(e,t){return{type:_g.UPDATE_DRAFT,draft:new vg(e,t)}},deleteNewAndEmptyDrafts:function(){return(e,t)=>{const n=t().drafts.filter((e=>Li(e.annotation)&&!xg(t().drafts,e.annotation))).map((t=>(e(bg(t.annotation)),t.annotation)));e(lg(n))}},discardAllDrafts:function(){return{type:_g.DISCARD_ALL_DRAFTS}},removeDraft:bg},selectors:{countDrafts:function(e){return e.length},getDraft:wg,getDraftIfNotEmpty:xg,unsavedAnnotations:kg}});function Cg(e){var t,n;return!!(null!==(t=e.user)&&void 0!==t&&t.username||null!==(n=e.user)&&void 0!==n&&n.userid)}function Ag(e){if(!Cg(e))return{};const t=e.user.username||e.user.userid||"";return{user:{value:t,display:e.user.displayName||t}}}const Eg={CHANGE_FOCUS_MODE_USER:function(e,t){
640
+ return{focusActive:Cg({user:t.user}),focusFilters:Ag({user:t.user})}},SET_FILTER:function(e,t){var n;const r={...e.filters,[t.filterName]:t.filterOption};return""===(null===(n=t.filterOption)||void 0===n?void 0:n.value)&&delete r[t.filterName],{filters:r}},SET_FILTER_QUERY:function(e,t){return{query:t.query}},SET_FOCUS_MODE:function(e,t){var n;return{focusActive:null!==(n=t.active)&&void 0!==n?n:!e.focusActive}},CLEAR_SELECTION:function(){return{filters:{},focusActive:!1,query:null}}},Tg=lf(Eg);const Ng=Zf((e=>e.focusActive),(e=>e.focusFilters),((e,t)=>{var n;return{active:e,configured:!(null==t||!t.user),displayName:(null==t||null===(n=t.user)||void 0===n?void 0:n.display)||""}})),Mg=Zf((e=>e.filters),(e=>e.focusActive),(e=>e.focusFilters),((e,t,n)=>t?{...n,...e}:{...e}));const Lg=Zf((e=>Mg(e)),(e=>{const t={};return Object.keys(e).forEach((n=>t[n]=e[n].value)),t}));const zg=qf((function(e){const t=e.focus||{};return{filters:{},focusActive:Cg(t),focusFilters:Ag(t),query:e.query||null}}),{namespace:"filters",
641
+ reducers:Eg,actionCreators:{changeFocusModeUser:function(e){return{type:Tg.CHANGE_FOCUS_MODE_USER,user:e}},setFilter:function(e,t){return(n,r)=>{var o;null!==(o=r().filters.focusFilters)&&void 0!==o&&o[e]&&n({type:Tg.SET_FOCUS_MODE,active:!1}),n({type:Tg.SET_FILTER,filterName:e,filterOption:t})}},setFilterQuery:function(e){return{type:Tg.SET_FILTER_QUERY,query:e}},toggleFocusMode:function(e){return{type:Tg.SET_FOCUS_MODE,active:e}}},selectors:{filterQuery:function(e){return e.query},focusState:Ng,getFilter:function(e,t){return Mg(e)[t]},getFilters:Mg,getFilterValues:Lg,getFocusFilters:function(e){return e.focusFilters},hasAppliedFilter:function(e){return!(!e.query&&!Object.keys(Mg(e)).length)}}}),Og={CONNECT_FRAME:function(e,t){return[...e,t.frame]},DESTROY_FRAME:function(e,t){return e.filter((e=>e!==t.frame))},UPDATE_FRAME_ANNOTATION_FETCH_STATUS:function(e,t){return e.map((e=>e.uri&&e.uri===t.uri?Object.assign({},e,{isAnnotationFetchComplete:t.isAnnotationFetchComplete}):e))}},Ig=lf(Og)
642
+ ;const Pg=Zf((e=>e),(e=>e.find((e=>!e.id))||null));const Rg=Xf(Yf,Zm)((e=>e.reduce(((e,t)=>e.concat(function(e){let t=[e.uri];return e.metadata&&e.metadata.documentFingerprint&&(t=e.metadata.link.map((e=>e.href))),e.metadata&&e.metadata.link&&e.metadata.link.forEach((e=>{e.href.startsWith("doi:")&&t.push(e.href)})),t}(t))),[])),(e=>e)),Dg=qf([],{namespace:"frames",reducers:Og,actionCreators:{connectFrame:function(e){return{type:Ig.CONNECT_FRAME,frame:e}},destroyFrame:function(e){return{type:Ig.DESTROY_FRAME,frame:e}},updateFrameAnnotationFetchStatus:function(e,t){return{type:Ig.UPDATE_FRAME_ANNOTATION_FETCH_STATUS,isAnnotationFetchComplete:t,uri:e}}},selectors:{frames:function(e){return e},mainFrame:Pg,searchUris:Rg}}),Bg={features:{},preferences:{},userid:null};const Fg={UPDATE_PROFILE:function(e,t){return{profile:{...t.profile}}}},jg=lf(Fg);const Hg=qf((function(e){var t;return{defaultAuthority:null!==(t=null==e?void 0:e.authDomain)&&void 0!==t?t:"",profile:Bg}}),{namespace:"session",reducers:Fg,
643
+ actionCreators:{updateProfile:function(e){return{type:jg.UPDATE_PROFILE,profile:e}}},selectors:{defaultAuthority:function(e){return e.defaultAuthority},hasFetchedProfile:function(e){return e.profile!==Bg},isFeatureEnabled:function(e,t){return!!e.profile.features[t]},isLoggedIn:function(e){return null!==e.profile.userid},profile:function(e){return e.profile}}}),qg={FILTER_GROUPS(e,t){var n;if(null===(n=t.filteredGroupIds)||void 0===n||!n.length)return{filteredGroupIds:null};const r=e.groups.filter((e=>t.filteredGroupIds.includes(e.id)));if(!r.length)return{filteredGroupIds:null};let o=e.focusedGroupId;return o&&t.filteredGroupIds.includes(o)||(o=r[0].id),{filteredGroupIds:t.filteredGroupIds,focusedGroupId:o}},FOCUS_GROUP(e,t){const n=e.groups.find((e=>e.id===t.id));return n?{focusedGroupId:t.id}:(console.error(`Attempted to focus group ${t.id} which is not loaded`),{})},LOAD_GROUPS(e,t){const n=t.groups;let r=e.focusedGroupId
644
+ ;return null!==e.focusedGroupId&&n.find((t=>t.id===e.focusedGroupId))||(r=n.length>0?n[0].id:null),{focusedGroupId:r,groups:t.groups}},CLEAR_GROUPS:()=>({filteredGroupIds:null,focusedGroupId:null,groups:[]})},Ug=lf(qg);function $g(e){return e.filteredGroupIds?e.groups.filter((t=>{var n;return null===(n=e.filteredGroupIds)||void 0===n?void 0:n.includes(t.id)})):e.groups}function Gg(e,t){return e.groups.find((e=>e.id===t))}const Vg=Zf((e=>$g(e)),(e=>e.filter((e=>!e.isMember&&e.isScopedToUri)))),Wg=Zf((e=>$g(e)),(e=>e.filter((e=>e.isScopedToUri)))),Yg=Zf((e=>$g(e.groups)),(e=>Hg.selectors.isLoggedIn(e.session)),((e,t)=>t?e.filter((e=>e.isMember)):[])),Kg=Zf((e=>$g(e.groups)),(e=>Yg(e)),(e=>Vg(e.groups)),((e,t,n)=>e.filter((e=>!t.includes(e)&&!n.includes(e))))),Xg=qf({filteredGroupIds:null,groups:[],focusedGroupId:null},{namespace:"groups",reducers:qg,actionCreators:{filterGroups:function(e){return{type:Ug.FILTER_GROUPS,filteredGroupIds:e}},focusGroup:function(e){return{type:Ug.FOCUS_GROUP,id:e}},
645
+ loadGroups:function(e){return{type:Ug.LOAD_GROUPS,groups:e}},clearGroups:function(){return{type:Ug.CLEAR_GROUPS}}},selectors:{allGroups:function(e){return e.groups},filteredGroups:$g,filteredGroupIds:function(e){return e.filteredGroupIds},focusedGroup:function(e){return e.focusedGroupId?Gg(e,e.focusedGroupId):null},focusedGroupId:function(e){return e.focusedGroupId},getFeaturedGroups:Vg,getGroup:Gg,getInScopeGroups:Wg},rootSelectors:{getCurrentlyViewingGroups:Kg,getMyGroups:Yg}}),Zg={UPDATE_LINKS:(e,t)=>({...t.links})},Jg=lf(Zg);const Qg=qf(null,{namespace:"links",reducers:Zg,actionCreators:{updateLinks:function(e){return{type:Jg.UPDATE_LINKS,links:e}}},selectors:{getLink:function(e,t,n={}){if(!e)return"";const r=e[t];if(!r)throw new Error(`Unknown link "${t}"`);const{url:o,unusedParams:i}=Dm(r,n),a=Object.keys(i);if(a.length>0)throw new Error(`Unused parameters: ${a.join(", ")}`);return o}}}),ev={RECEIVE_REAL_TIME_UPDATES:(e,t)=>({pendingUpdates:{...t.pendingUpdates},pendingDeletions:{...t.pendingDeletions}
646
+ }),CLEAR_PENDING_UPDATES:()=>({pendingUpdates:{},pendingDeletions:{}}),ADD_ANNOTATIONS(e,{annotations:t}){const n={...e.pendingUpdates};return t.forEach((e=>delete n[e.id])),{pendingUpdates:n}},REMOVE_ANNOTATIONS(e,{annotationsToRemove:t}){const n={...e.pendingUpdates},r={...e.pendingDeletions};return t.forEach((e=>{delete n[e.id],delete r[e.id]})),{pendingUpdates:n,pendingDeletions:r}},FOCUS_GROUP:()=>({pendingUpdates:{},pendingDeletions:{}})},tv=lf(ev);const nv=Zf((e=>[e.pendingUpdates,e.pendingDeletions]),(([e,t])=>Object.keys(e).length+Object.keys(t).length));const rv=qf({pendingUpdates:{},pendingDeletions:{}},{namespace:"realTimeUpdates",reducers:ev,actionCreators:{receiveRealTimeUpdates:function({updatedAnnotations:e=[],deletedAnnotations:t=[]}){return(n,r)=>{const o={...r().realTimeUpdates.pendingUpdates},i={...r().realTimeUpdates.pendingDeletions};e.forEach((e=>{const t=r().groups,n=r().route;e.group!==Xg.selectors.focusedGroupId(t)&&"sidebar"===rg.selectors.route(n)||(o[e.id]=e)})),t.forEach((e=>{
647
+ const t=e.id;delete o[t];const n=r().annotations;ug.selectors.annotationExists(n,t)&&(i[t]=!0)})),n({type:tv.RECEIVE_REAL_TIME_UPDATES,pendingUpdates:o,pendingDeletions:i})}},clearPendingUpdates:function(){return{type:tv.CLEAR_PENDING_UPDATES}}},selectors:{hasPendingDeletion:function(e,t){return e.pendingDeletions.hasOwnProperty(t)},pendingDeletions:function(e){return e.pendingDeletions},pendingUpdates:function(e){return e.pendingUpdates},pendingUpdateCount:nv}}),ov={annotation:"Location",note:"Oldest",orphan:"Location"};function iv(e){const t={};return e.annotations&&!e.query&&(t[e.annotations]=!0),t}const av=(e,t)=>t===e?{}:{selectedTab:e,sortKey:ov[e]},sv={CLEAR_SELECTION:function(){return{forcedVisible:{},selected:{}}},SELECT_ANNOTATIONS:function(e,t){return{selected:t.selection}},SELECT_TAB:function(e,t){return av(t.tab,e.selectedTab)},SET_EXPANDED:function(e,t){const n={...e.expanded};return n[t.id]=t.expanded,{expanded:n}},SET_FORCED_VISIBLE:function(e,t){return{forcedVisible:{...e.forcedVisible,
648
+ [t.id]:t.visible}}},SET_SORT_KEY:function(e,t){return{sortKey:t.key}},TOGGLE_SELECTED_ANNOTATIONS:function(e,t){const n={...e.selected};return t.toggleIds.forEach((e=>{n[e]=!n[e]})),{selected:n}},ADD_ANNOTATIONS(e,t){const n=t.annotations.filter((e=>!Ni(e))),r=Jf(t.annotations,Bi)===n.length;return 0===t.currentAnnotationCount&&r?av("note",e.selectedTab):{}},CHANGE_FOCUS_MODE_USER:function(){return{forcedVisible:{},selected:{}}},SET_FILTER:function(){return{forcedVisible:{},selected:{},expanded:{}}},SET_FILTER_QUERY:function(){return{forcedVisible:{},selected:{},expanded:{}}},SET_FOCUS_MODE:function(){return{forcedVisible:{},selected:{}}},REMOVE_ANNOTATIONS:function(e,t){let n=e.selectedTab;"orphan"===n&&0===Jf(t.remainingAnnotations,Di)&&(n="annotation");const r=e=>(t.annotationsToRemove.forEach((t=>{t.id&&delete e[t.id],t.$tag&&delete e[t.$tag]})),e);return{...av(n,e.selectedTab),expanded:r({...e.expanded}),forcedVisible:r({...e.forcedVisible}),selected:r({...e.selected})}}},lv=lf(sv);function cv(e){
649
+ return e.expanded}const uv=Zf((e=>e.forcedVisible),(e=>eg(e))),hv=Zf((e=>e.selected),(e=>eg(e).length>0)),dv=Zf((e=>e.selected),(e=>eg(e)));function pv(e){return e.selectedTab}const mv=Zf((e=>e),(e=>({expanded:cv(e),forcedVisible:uv(e),selected:dv(e),sortKey:fv(e),selectedTab:pv(e)})));function fv(e){return e.sortKey}const gv=Zf((e=>e.selectedTab),(e=>{const t=["Newest","Oldest"];return"note"!==e&&t.push("Location"),t})),vv=qf((function(e){return{selected:iv(e),expanded:iv(e)||{},forcedVisible:{},selectedTab:"annotation",sortKey:ov.annotation}}),{namespace:"selection",reducers:sv,actionCreators:{clearSelection:function(){return{type:lv.CLEAR_SELECTION}},selectAnnotations:function(e){return t=>{t({type:lv.CLEAR_SELECTION}),t({type:lv.SELECT_ANNOTATIONS,selection:Qf(e)})}},selectTab:function(e){return{type:lv.SELECT_TAB,tab:e}},setExpanded:function(e,t){return{type:lv.SET_EXPANDED,id:e,expanded:t}},setForcedVisible:function(e,t){return{type:lv.SET_FORCED_VISIBLE,id:e,visible:t}},setSortKey:function(e){return{
650
+ type:lv.SET_SORT_KEY,key:e}},toggleSelectedAnnotations:function(e){return{type:lv.TOGGLE_SELECTED_ANNOTATIONS,toggleIds:e}}},selectors:{expandedMap:cv,forcedVisibleThreads:uv,hasSelectedAnnotations:hv,selectedAnnotations:dv,selectedTab:pv,selectionState:mv,sortKey:fv,sortKeys:gv}}),yv={OPEN_SIDEBAR_PANEL:function(e,t){return{activePanelName:t.panelName}},CLOSE_SIDEBAR_PANEL:function(e,t){let n=e.activePanelName;return t.panelName===n&&(n=null),{activePanelName:n}},TOGGLE_SIDEBAR_PANEL:function(e,t){let n;const r=e.activePanelName===t.panelName,o=void 0!==t.panelState?t.panelState:!r;return n=o?t.panelName:r&&!o?null:e.activePanelName,{activePanelName:n}}},_v=lf(yv);const bv=qf({activePanelName:null},{namespace:"sidebarPanels",reducers:yv,actionCreators:{openSidebarPanel:function(e){return{type:_v.OPEN_SIDEBAR_PANEL,panelName:e}},closeSidebarPanel:function(e){return{type:_v.CLOSE_SIDEBAR_PANEL,panelName:e}},toggleSidebarPanel:function(e,t){return{type:_v.TOGGLE_SIDEBAR_PANEL,panelName:e,panelState:t}}},
651
+ selectors:{isSidebarPanelOpen:function(e,t){return e.activePanelName===t}}}),wv={ADD_MESSAGE:function(e,t){return{messages:e.messages.concat({...t.message})}},REMOVE_MESSAGE:function(e,t){return{messages:e.messages.filter((e=>e.id!==t.id))}},UPDATE_MESSAGE:function(e,t){return{messages:e.messages.map((e=>e.id&&e.id===t.message.id?{...t.message}:e))}}},xv=lf(wv);const kv=qf({messages:[]},{namespace:"toastMessages",reducers:wv,actionCreators:{addToastMessage:function(e){return{type:xv.ADD_MESSAGE,message:e}},removeToastMessage:function(e){return{type:xv.REMOVE_MESSAGE,id:e}},updateToastMessage:function(e){return{type:xv.UPDATE_MESSAGE,message:e}}},selectors:{getToastMessage:function(e,t){return e.messages.find((e=>e.id===t))},getToastMessages:function(e){return e.messages},hasToastMessage:function(e,t,n){return e.messages.some((e=>e.type===t&&e.message===n))}}}),Sv={SET_SIDEBAR_OPENED:(e,t)=>!0===t.opened?{sidebarHasOpened:!0}:{}},Cv=lf(Sv);const Av=qf({sidebarHasOpened:!1},{namespace:"viewer",reducers:Sv,
652
+ actionCreators:{setSidebarOpened:function(e){return{type:Cv.SET_SIDEBAR_OPENED,opened:e}}},selectors:{hasSidebarOpened:function(e){return e.sidebarHasOpened}}});function Ev(e){return Hf([Vf,ug,pg,gg,Sg,zg,Dg,Qg,Xg,rv,rg,vv,Hg,bv,kv,Av],[e],[Uf])}Ev.$inject=["settings"];class Tv{constructor(){this._providers=new Map,this._instances=new Map,this._constructing=new Set}get(e){if(this._instances.has(e))return this._instances.get(e);const t=this._providers.get(e);if(!t)throw new Error(`"${e}" is not registered`);if("value"in t)return this._instances.set(e,t.value),t.value;if(this._constructing.has(e))throw new Error(`Encountered a circular dependency when constructing "${e}"`);this._constructing.add(e);try{const n=[],r="class"in t&&t.class.$inject||"factory"in t&&t.factory.$inject||[];for(const t of r)try{n.push(this.get(t))}catch(n){const r=new Error(`Failed to construct dependency "${t}" of "${e}": ${n.message}`);throw r.cause=n,r}let o;if(t.class)o=new t.class(...n);else{o=(0,t.factory)(...n)}
653
+ return this._instances.set(e,o),o}finally{this._constructing.delete(e)}}register(e,t){if("function"==typeof t)t={class:t};else if(!function(e){return"object"==typeof e&&null!==e&&("value"in e||"function"==typeof e.class||"function"==typeof e.factory)}(t))throw new Error(`Invalid provider for "${e}"`);return this._providers.set(e,t),this}run(e){const t="Injector.run";this.register(t,{factory:e});try{return this.get(t)}finally{this._instances.delete(t),this._providers.delete(t)}}}const Nv=function(t){for(var n={},r=t.querySelectorAll("script.js-hypothesis-config"),o=0;o<r.length;o++){var i=void 0;try{i=JSON.parse(r[o].textContent||"")}catch(e){console.warn("Could not parse settings from js-hypothesis-config tags",e),i={}}e(n,i)}return n}(document),Mv=function(e){const{version:t,origin:n}=P(e.location.href);return"1.1007.0"!==t?(console.warn(`The Hypothesis sidebar is using a different version (1.1007.0) than the host page (${t}). It may not work.`),
654
+ !1):"null"===e.origin?(console.warn("Hypothesis has been loaded in a sandboxed frame. This is not supported."),!1):e.origin===n||(console.warn(`The Hypothesis sidebar is running in a different origin (${e.origin}) than expected (${n}). It may not work.`),!1)}(window);function Lv(e,t){e.setClientId(t.clientId)}function zv(e,t,n){e.load(),t.load(),n.sync()}function Ov(e,t,n,r){e.init(),t.init(),n.init(),r.init()}function Iv(e,t){"sidebar"===t.route()&&e.connect()}Nv.sentry&&Mv&&function(e){const t=function(){let e=import.meta.url;return e?new URL(e).origin:null}(),n=t?[t]:void 0;Er({dsn:e.dsn,environment:e.environment,allowUrls:n,ignoreErrors:["Network request failed","Object Not Found Matching Id"],release:"1.1007.0",beforeSend:(e,t)=>{if(Mr>=5)return V("Client-side Sentry quota reached. No further Sentry events will be sent"),null;++Mr;try{const n=t&&t.originalException;n instanceof Event&&Object.assign(e.extra,{type:n.type,detail:n.detail,isTrusted:n.isTrusted})}catch(e){}return e}});try{
655
+ Yt("host_config",P(window.location.href))}catch(e){}Yt("loaded_scripts",Array.from(document.querySelectorAll("script")).filter((e=>!e.type||e.type.match(/javascript|module/))).map((e=>e.src||"<inline>"))),Nr(((e,t)=>{Wt(e,{tags:{context:t}})}))}(Nv.sentry),function(e){e.addEventListener("click",(e=>{const t=e.target;if("A"===t.tagName){const e=t;"_blank"===e.target&&(e.rel="noopener")}}))}(document.body),function(e=n){let t=!1;try{document.createElement("div").dir="auto"}catch(e){t=!0}if(t){const t=e.vnode;e.vnode=e=>{if("string"==typeof e.type){const t=e.props;"dir"in t&&"auto"===t.dir&&(t.dir="")}t&&t(e)}}}(),Lv.$inject=["api","streamer"],zv.$inject=["groups","session","router"],Ov.$inject=["autosaveService","features","persistedDefaults","serviceURL"],Iv.$inject=["frameSync","store"],function(e,{reset:t=!1}={}){t&&bo.clear();for(let[t,n]of Object.entries(e))bo.set(t,n)}(ti);const Pv=document.querySelector("hypothesis-app");!function(e=window){e.addEventListener("message",J)}(),async function(e,t=window){
654
656
  const n=function(e){const t=P(e.location.href),n=["annotations","group","query","appType","openSidebar","showHighlights","services","branding","enableExperimentalNewNoteButton","focus","requestConfigFromFrame","theme","usernameUrl"],r={openSidebar:D,requestConfigFromFrame:e=>{if("string"==typeof e)return e;const t=function(e){return"object"==typeof e&&null!==e?e:{}}(e);return{origin:F(t.origin),ancestorLevel:B(t.ancestorLevel)}}};return Object.keys(t).reduce(((e,o)=>(-1!==n.indexOf(o)&&null!==t[o]&&(r[o]?e[o]=r[o](t[o]):e[o]=t[o]),e)),{})}(window),r=n.requestConfigFromFrame;if(!r)return U(e,n);if("number"==typeof r.ancestorLevel&&"string"==typeof r.origin){const o=function(e,t=window){let n=t;for(let t=0;t<e;t++){if(n===n.top)throw new Error("The target parent frame has exceeded the ancestor tree. Try reducing the `requestConfigFromFrame.ancestorLevel` value in the `hypothesisConfig`");n=n.parent}return n}(r.ancestorLevel,t);return{...await $(e,o,r.origin),...n.group?{group:n.group}:{}}}
655
- throw new Error("Improper `requestConfigFromFrame` object. Both `ancestorLevel` and `origin` need to be specified")}(Tv).then((e=>{!function(e,t){const n=new Ev;n.register("annotationsService",Om).register("api",Bm).register("apiRoutes",Gm).register("auth",Ym).register("autosaveService",Km).register("features",Jm).register("frameSync",af).register("groups",uf).register("loadAnnotationsService",hf).register("localStorage",pf).register("persistedDefaults",ff).register("router",gf).register("serviceURL",vf).register("session",yf).register("streamer",wf).register("streamFilter",_f).register("tags",xf).register("threadsService",kf).register("toastMessenger",Sf).register("store",{factory:Av}),n.register("$window",{value:window}).register("settings",{value:e}),n.run(zv),n.run(Mv),n.run(Lv),n.run(Z),n.run(Ov),I(_o(li.Provider,{value:n,children:_o(Lm,{})}),t)}(e,Iv)})).catch((e=>function(e,t){console.error("Failed to start Hypothesis client: ",e),I(_o(zm,{error:e}),t)}(e,Iv)));
657
+ throw new Error("Improper `requestConfigFromFrame` object. Both `ancestorLevel` and `origin` need to be specified")}(Nv).then((e=>{!function(e,t){const n=new Tv;n.register("annotationsService",Im).register("api",Fm).register("apiRoutes",Vm).register("auth",Km).register("autosaveService",Xm).register("features",Qm).register("frameSync",sf).register("groups",hf).register("loadAnnotationsService",df).register("localStorage",mf).register("persistedDefaults",gf).register("router",vf).register("serviceURL",yf).register("session",_f).register("streamer",xf).register("streamFilter",bf).register("tags",kf).register("threadsService",Sf).register("toastMessenger",Cf).register("store",{factory:Ev}),n.register("$window",{value:window}).register("settings",{value:e}),n.run(Ov),n.run(Lv),n.run(zv),n.run(Z),n.run(Iv),I(_o(li.Provider,{value:n,children:_o(zm,{})}),t)}(e,Pv)})).catch((e=>function(e,t){console.error("Failed to start Hypothesis client: ",e),I(_o(Om,{error:e}),t)}(e,Pv)));
656
658
  //# sourceMappingURL=sidebar.bundle.js.map