hypothesis 1.976.0 → 1.977.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.
@@ -556,7 +556,7 @@ t.addEventListener("touchstart",i,c),t.addEventListener("wheel",i,c)),a&&Lp(t),i
556
556
  },s=t>0?`${o} (${t} available)`:o;return po(bo,{classes:Ur("text-color-text","SelectionTab",{"is-selected":r}),onClick:a,onMouseDown:a,pressed:!!r,role:"tab",tabIndex:0,title:s,children:po(m,{children:[e,t>0&&!n&&po("span",{className:"text-tiny",style:"position:relative;bottom:3px;left:2px",children:t})]})})}var Fp=ri((function({annotationsService:e,isLoading:t,settings:n}){const r=ii(),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 po("div",{className:"hyp-u-vertical-spacing--4 SelectionTabs__container",children:[po("div",{className:"hyp-u-layout-row hyp-u-horizontal-spacing--6 SelectionTabs",role:"tablist",children:[po(Bp,{count:a,isWaitingToAnchor:l,isSelected:"annotation"===o,label:"Annotations",onSelect:()=>c("annotation"),children:"Annotations"}),po(Bp,{count:i,isWaitingToAnchor:l,isSelected:"note"===o,label:"Page notes",onSelect:()=>c("note"),
557
557
  children:"Page Notes"}),s>0&&po(Bp,{count:s,isWaitingToAnchor:l,isSelected:"orphan"===o,label:"Orphans",onSelect:()=>c("orphan"),children:"Orphans"})]}),"note"===o&&n.enableExperimentalNewNoteButton&&po("div",{className:"hyp-u-layout-row--justify-right",children:po(bo,{"data-testid":"new-note-button",icon:"add",onClick:()=>e.createPageNote(),variant:"primary",style:ti(["ctaBackgroundColor"],n),children:"New note"})}),!t&&h&&po(ko,{classes:"text-center",children:po("span",{"data-testid":"notes-unavailable-message",children:"There are no page notes in this group."})}),!t&&u&&po(ko,{classes:"text-center",children:po("span",{"data-testid":"annotations-unavailable-message",children:["There are no annotations in this group.",po("br",{}),"Create one by selecting some text and clicking the"," ",po(Mo,{classes:"m-0.5 inline -mt-0.5",name:"annotate",title:"Annotate"})," ","button."]})})]})}),["annotationsService","settings"]);var jp=ri((function({frameSync:e,onLogin:t,onSignUp:n,loadAnnotationsService:r,streamer:o}){
558
558
  const i=Ki(),a=ii(),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?ji(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=to(s);Qr((()=>{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]),Qr((()=>{v?(e.focusAnnotations([v]),e.scrollToAnnotation(v),a.selectTab(p)):d&&a.selectTab(p)}),[p,e,d,v,a]);const C=a.hasFetchedProfile();return Qr((()=>{C&&(f||u)&&o.connect({applyUpdatesImmediately:!1})}),[C,u,f,o]),po("div",{children:[po("h2",{className:"sr-only",children:"Annotations"}),w&&po(Ep,{}),po(Dp,{onLogin:t,onSignUp:n}),y&&po(wp,{errorType:"annotation",onLoginRequest:t,showClearSelection:!0}),_&&po(wp,{
559
- errorType:"group",onLoginRequest:t}),x&&po(Fp,{isLoading:c}),po(bp,{threads:i.children}),k&&po(Tp,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var Hp=ri((function({api:e,toastMessenger:t}){const n=ii(),r=n.routeParams().q,o=ro((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...yi(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return Qr((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),po(bp,{threads:Ki().children})}),["api","toastMessenger"]);class Up{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.976.0",this.userAgent=n.navigator.userAgent,this.urls=t.map((e=>e.uri)).join(", ")||a,
559
+ errorType:"group",onLoginRequest:t}),x&&po(Fp,{isLoading:c}),po(bp,{threads:i.children}),k&&po(Tp,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var Hp=ri((function({api:e,toastMessenger:t}){const n=ii(),r=n.routeParams().q,o=ro((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...yi(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return Qr((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),po(bp,{threads:Ki().children})}),["api","toastMessenger"]);class Up{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.977.0",this.userAgent=n.navigator.userAgent,this.urls=t.map((e=>e.uri)).join(", ")||a,
560
560
  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 qp(e){const t=P(e);return!(null==t||!t.authority)&&t.authority!==e.authDomain}function $p({commandName:e,iconName:t}){return po("span",{className:"whitespace-nowrap",children:[po(Mo,{name:t,classes:Ur("mx-1 -mt-1","text-color-text-light inline")}),po("em",{children:e})]})}var Gp=ri((function({settings:e}){const t=!qp(e);return po("ol",{className:"list-decimal pl-10 space-y-2",children:[po("li",{children:["To create an annotation, select text and then select the"," ",po($p,{iconName:"annotate",commandName:"Annotate"})," ","button."]}),po("li",{
561
561
  children:["To create a highlight (",po(zo,{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"," ",po($p,{iconName:"highlight",commandName:"Highlight"})," ","button."]}),t&&po("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"," ",po(zo,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/how-to-join-a-private-group/",target:"_blank",children:"join link"}),")."]}),po("li",{children:["To reply to an annotation, select the"," ",po($p,{iconName:"reply",commandName:"Reply"})," button."]})]})}),["settings"]);var Vp=ri((function({toastMessenger:e,versionData:t}){return po("div",{className:"hyp-u-vertical-spacing",children:[po("dl",{className:"VersionInfo",children:[po("dt",{className:"VersionInfo__key",children:"Version"}),po("dd",{
562
562
  className:"VersionInfo__value",children:t.version}),po("dt",{className:"VersionInfo__key",children:"User Agent"}),po("dd",{className:"VersionInfo__value",children:t.userAgent}),po("dt",{className:"VersionInfo__key",children:"URL"}),po("dd",{className:"VersionInfo__value",children:t.urls}),po("dt",{className:"VersionInfo__key",children:"Fingerprint"}),po("dd",{className:"VersionInfo__value",children:t.fingerprint}),po("dt",{className:"VersionInfo__key",children:"Account"}),po("dd",{className:"VersionInfo__value",children:t.account}),po("dt",{className:"VersionInfo__key",children:"Date"}),po("dd",{className:"VersionInfo__value",children:t.timestamp})]}),po("div",{className:"hyp-u-layout-row--justify-center",children:po(bo,{onClick:()=>{try{ba(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 Wp({children:e,onClick:t}){return po(wo,{
@@ -584,7 +584,7 @@ className:Ur("HypothesisApp","js-thread-list-scroll-root",{"theme-clean":h,"Hypo
584
584
  ;function Sm({error:e}){return po("div",{className:"LaunchErrorPanel",children:po(Ho,{title:"Unable to start Hypothesis",children:e.message})})}class Cm{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?fa(e.user):ga(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:"+q(8),l=Object.assign({created:t.toISOString(),group:r,permissions:va(i,r,n),tags:[],text:"",updated:t.toISOString(),user:i,user_info:a,$tag:s,hidden:!1,links:{},document:{title:""}},e);return Ni(l)&&(l.permissions=fa(i)),l}create(e,t=new Date){const n=this._initialize(e,t);this._store.addAnnotations([n]),this._store.deleteNewAndEmptyDrafts(),Ni(n)||this._store.createDraft(n,{tags:n.tags,text:n.text,isPrivate:!Ci(n)}),
585
585
  Mi(n)?this._store.selectTab("note"):zi(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:Ci(e)?ga(t,e.group):fa(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=Si(e)?this._api.annotation.create({},n):this._api.annotation.update({id:e.id},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])})),
586
586
  this._store.removeDraft(e),this._store.addAnnotations([r]),r}}Cm.$inject=["api","store"];class Am 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 Em(e,t){let n,r;try{n=await fetch(e,t)}catch(t){throw new Am(e,null,t.message)}if(204===n.status)return null;try{r=await n.json()}catch(t){throw new Am(e,n,"Failed to parse response")}var o;if(!n.ok)throw new Am(e,n,null===(o=r)||void 0===o?void 0:o.reason);return r}function Tm(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 Nm(e){const t={};for(const n in e)e.hasOwnProperty(n)&&"$"!==n[0]&&(t[n]=e[n]);return t}class Lm{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}){
587
- 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.976.0"};l&&(u.Authorization="Bearer "+l);const h=r();h&&(u["X-Client-Id"]=h);const{url:d,unusedParams:p}=Tm(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 Em(m.toString(),{body:s?JSON.stringify(Nm(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")},this.groups={
587
+ 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.977.0"};l&&(u.Authorization="Bearer "+l);const h=r();h&&(u["X-Client-Id"]=h);const{url:d,unusedParams:p}=Tm(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 Em(m.toString(),{body:s?JSON.stringify(Nm(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")},this.groups={
588
588
  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}}Lm.$inject=["apiRoutes","auth","store"];var Mm={};function zm(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 Om=zm;zm.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},zm.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},zm.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime()
589
589
  ;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},zm.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)},zm.prototype.try=function(e){
590
590
  console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},zm.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},zm.prototype.start=zm.prototype.try,zm.prototype.errors=function(){return this._errors},zm.prototype.attempts=function(){return this._attempts},zm.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=Om;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))
@@ -595,60 +595,61 @@ const t=`left=${e.screen.width/2-237.5},top=${e.screen.height/2-215},width=475,h
595
595
  ;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=Fm.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}}
596
596
  jm.$inject=["$window","apiRoutes","localStorage","settings","toastMessenger"];class Hm{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),Rm((()=>this._annotationsService.save(t))).catch((()=>{this._failed.add(n)})).finally((()=>{this._saving.delete(n)})))}))}))}isSaving(){return this._saving.size>0}}Hm.$inject=["annotationsService","store"];var Um=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 qm(e,t,n){
597
597
  const r=Array.isArray(t),o=()=>r?t.map((e=>e())):t();let i=o();return e((()=>{const e=o();if(r?Um(e,i):e===i)return;const t=i;i=e,n(e,t)}))}class $m{constructor(e,t){this._frameSync=e,this._store=t}init(){const e=()=>this._store.profile().features;qm(this._store.subscribe,[e,()=>this._store.frames()],(()=>{this._frameSync.notifyHost("featureFlagsUpdated",e()||{})}))}}function Gm(e,t){return!!function(e){if(null===e||"object"!=typeof e)return!1;for(let t of["frame1","frame2","type"])if("string"!=typeof e[t])return!1;return!0}(e)&&JSON.stringify(e,Object.keys(t).sort())===JSON.stringify(t,Object.keys(t).sort())}$m.$inject=["frameSync","store"];class Vm{constructor({hostFrame:e,source:t}){this._hostFrame=e,this._source=t,this._listeners=new ha}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),
598
- !t)throw new Error("Invalid request of channel/port");return new Promise(((t,n)=>{const r=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:e,type:"request"},"*")},o=setInterval(r,250),i=setTimeout((()=>{clearInterval(o),n(new Error(`Unable to establish ${this._source}-${e} communication channel`))}),2e4),a=this._listeners.add(window,"message",(n=>{const{data:r,ports:s}=n;Gm(r,{frame1:this._source,frame2:e,type:"offer"})&&(clearInterval(o),clearTimeout(i),this._listeners.remove(a),t(s[0]))}));r()}))}}class Wm{constructor(){this._port=null,this._methods=new Map,this._sequence=1,this._callbacks=new Map,this._listeners=new ha,this._pendingCalls=[]}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();for(let[e,t]of this._pendingCalls)this.call(e,...t);this._pendingCalls=[]}destroy(){var e;this._destroyed=!0,this._listeners.removeAll(),
599
- null===(e=this._port)||void 0===e||e.close()}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));const o={arguments:t,method:e,protocol:"frame-rpc",sequence:n,version:"1.0.0"};this._port.postMessage(o)}_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){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 Ym({$tag:e,target:t,uri:n}){return{$tag:e,target:t,uri:n}}class Km{constructor(e,t,n){this._window=e,this._annotationsService=t,
600
- this._store=n,this._portFinder=new Vm({hostFrame:this._window.parent,source:"sidebar"}),this._listeners=new ha,this._hostRPC=new Wm,this._guestRPC=[],this._inFrame=new Set,this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0;qm(this._store.subscribe,[()=>this._store.allAnnotations(),()=>this._store.frames()],(([t,n],[r])=>{let o=0;const i=new Set,a=[];t.forEach((e=>{ki(e)||(Ci(e)&&++o,i.add(e.$tag),this._inFrame.has(e.$tag)||a.push(e))}));const s=r.filter((e=>!i.has(e.$tag)));a.length>0&&(this._guestRPC.forEach((e=>e.call("loadAnnotations",a.map(Ym)))),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 Wm;t.on("documentInfoChanged",(e=>{this._store.connectFrame({id:e.frameIdentifier,
601
- metadata:e.metadata,uri:e.uri})})),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 n={};const r=ua((()=>{this._store.updateAnchorStatus(n),n={}}),10);t.on("syncAnchoringStatus",(({$tag:e,$orphan:t})=>{this._inFrame.add(e),n[e]=t?"orphan":"anchored",r()})),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=>{this._store.toggleSelectedAnnotations(this._store.findIDsForTags(e))})),t.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")})),t.on("closeSidebar",(()=>{this._hostRPC.call("closeSidebar")})),
602
- this._guestRPC.push(t),t.connect(e),t.call("setHighlightsVisible",this._highlightsVisible)}_setupHostEvents(){this._hostRPC.on("sidebarOpened",(()=>{this._store.setSidebarOpened(!0)})),this._hostRPC.on("frameDestroyed",(e=>{const t=this._store.frames().find((t=>t.id===e));t&&this._store.destroyFrame(t)})),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._hostRPC.call("ready"),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;Gm(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(),this._listeners.removeAll()}}function Xm(e){
603
- return Object.keys(e).reduce(((e,t)=>(e[t]=t,e)),{})}Km.$inject=["$window","annotationsService","store"];const Zm={id:"__default__",name:"__DEFAULT__",logo:"data:image/svg+xml;utf8,"+encodeURIComponent(Yo)};const Jm=["organization","scopes"];class Qm{constructor(e,t,n,r,o,i){this._store=e,this._api=t,this._auth=n,this._settings=o,this._toastMessenger=i,this._serviceConfig=P(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,qm(this._store.subscribe,(()=>this._mainURI()),(()=>{this.load()})),
604
- qm(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=Zm)}))}(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:Jm})}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
605
- ;i&&(a=this._fetchGroup(i).then((e=>(this._store.clearDirectLinkedGroupFetchFailed(),e))).catch((()=>(this._store.setDirectLinkedGroupFetchFailed(),null))));const s={expand:Jm},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:Jm}),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(J(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:Jm});let n;const r=async e=>{try{return await this._fetchGroup(e)}catch(e){return n=e,null}
606
- },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=>!ki(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"})}}Qm.$inject=["store","api","auth","session","settings","toastMessenger"];class ef{
607
- 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 tm(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)})),
608
- 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}),ki(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),!ki(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}}ef.$inject=["api","store","streamer","streamFilter"];class tf{constructor(){this._store={}}getItem(e){return e in this._store?this._store[e]:null}
609
- setItem(e,t){this._store[e]=t}removeItem(e){delete this._store[e]}}class nf{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 tf}}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)}}nf.$inject=["$window"];const rf={annotationPrivacy:"hypothesis.privacy",focusedGroup:"hypothesis.groups.focus"};class of{constructor(e,t){this._storage=e,this._store=t}init(){Object.keys(rf).forEach((e=>{const t=this._storage.getItem(rf[e]);this._store.setDefault(e,t)})),qm(this._store.subscribe,(()=>this._store.getDefaults()),((e,t)=>{for(let n in e)t[n]!==e[n]&&n in rf&&this._storage.setItem(rf[n],e[n])}))}}of.$inject=["localStorage","store"];class af{constructor(e,t){this._window=e,
610
- 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){
611
- this._window.history.pushState({},"",this.routeUrl(e,t)),this.sync()}}af.$inject=["$window","store"];class sf{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}`)}}}sf.$inject=["apiRoutes","store"];class lf{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=P(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=Rm((()=>{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(){
612
- 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?Cr({id:e.userid}):Cr(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()}}lf.$inject=["store","api","auth","settings","toastMessenger"];class cf{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 uf extends Jp{constructor(e){super();const t=[];let n
613
- ;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 hf{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=q(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})))
614
- ;t.length&&this._store.removeAnnotations(t),this._store.clearPendingUpdates()}_handleSocketError(e,t){K("Error connecting to H push notification service:",t);const n=new URL(e).hostname;-1!==["localhost","127.0.0.1"].indexOf(n)&&K("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 K("Received unsupported notification",t.type)}_sendClientConfig(e){
615
- 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 uf(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))),
616
- 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,qm(this._store.subscribe,(()=>this._store.profile().userid),(()=>{this._reconnect()}))),this._socket||await this._reconnect()}}hf.$inject=["store","apiRoutes","auth","groups","session"];class df{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(`^${Z(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)
617
- ;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)}}df.$inject=["localStorage"];class pf{constructor(e){this._store=e}forceVisible(e){e.children.forEach((e=>{this.forceVisible(e)})),e.visible||this._store.setForcedVisible(e.id,!0)}}pf.$inject=["store"];class mf{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=q(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 ff(e,t,n){return t in e?Object.defineProperty(e,t,{
618
- value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function gf(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 vf(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?gf(Object(n),!0).forEach((function(t){ff(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):gf(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function yf(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. "}mf.$inject=["store"];var _f="function"==typeof Symbol&&Symbol.observable||"@@observable",bf=function(){return Math.random().toString(36).substring(7).split("").join(".")},wf={INIT:"@@redux/INIT"+bf(),
619
- REPLACE:"@@redux/REPLACE"+bf(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+bf()}};function xf(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 kf(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(yf(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(yf(1));return n(kf)(e,t)}if("function"!=typeof e)throw new Error(yf(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(yf(3));return i}function h(e){if("function"!=typeof e)throw new Error(yf(4));if(l)throw new Error(yf(5));var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error(yf(6));t=!1,c();var n=s.indexOf(e);s.splice(n,1),a=null}}}function d(e){if(!xf(e))throw new Error(yf(7));if(void 0===e.type)throw new Error(yf(8))
620
- ;if(l)throw new Error(yf(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(yf(10));o=e,d({type:wf.REPLACE})}function m(){var e,t=h;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(yf(11));function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[_f]=function(){return this},e}return d({type:wf.INIT}),(r={dispatch:d,subscribe:h,getState:u,replaceReducer:p})[_f]=m,r}function Sf(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:wf.INIT}))throw new Error(yf(12));if(void 0===n(void 0,{type:wf.PROBE_UNKNOWN_ACTION()}))throw new Error(yf(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,
621
- new Error(yf(14));o[l]=h,r=r||h!==u}return(r=r||a.length!==Object.keys(e).length)?o:e}}function Cf(e,t){return function(){return t(e.apply(this,arguments))}}function Af(){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 Ef(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 Tf=Ef();Tf.withExtraArgument=Ef;var Nf=Tf;function Lf(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(){
622
- 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(yf(15))},o={getState:n.getState,dispatch:function(){return r.apply(void 0,arguments)}},i=t.map((function(e){return e(o)}));return r=Af.apply(void 0,i)(n.dispatch),vf(vf({},n),{},{dispatch:r})}}}(...[Nf],...n);const s=kf(Sf(o),r,a),l=Object.assign({},...e.map((e=>e.actionCreators))),c=function(e,t){if("function"==typeof e)return Cf(e,t);if("object"!=typeof e||null===e)throw new Error(yf(16));var n={};for(var r in e){var o=e[r];"function"==typeof o&&(n[r]=Cf(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)
623
- ;return Object.assign(s,c,u),s}function Mf(e,t){if(!(e instanceof Function)){const t=e;e=()=>t}return{initialState:e,...t}}function zf(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 Of={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,
624
- 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})},If=Xm(Of);const Rf=Mf({activeAnnotationSaveRequests:[],activeApiRequests:0,activeAnnotationFetches:0,hasFetchedAnnotations:!1,annotationResultCount:null},{reducers:Of,namespace:"activity",actionCreators:{annotationFetchStarted:function(){return{type:If.ANNOTATION_FETCH_STARTED}},annotationFetchFinished:function(){return{type:If.ANNOTATION_FETCH_FINISHED}},annotationSaveStarted:function(e){return{type:If.ANNOTATION_SAVE_STARTED,annotation:e}},annotationSaveFinished:function(e){return{type:If.ANNOTATION_SAVE_FINISHED,annotation:e}},apiRequestStarted:function(){return{
625
- type:If.API_REQUEST_STARTED}},apiRequestFinished:function(){return{type:If.API_REQUEST_FINISHED}},setAnnotationResultCount:function(e){return{type:If.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 Pf=function(e,t){return e===t};function Df(e,t){var n,r,o="object"==typeof t?t:{equalityCheck:t},i=o.equalityCheck,a=void 0===i?Pf: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"},
626
- 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 Bf(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(", ")
627
- ;throw new Error("createSelector expects all input-selectors to be functions, but received the following types: ["+n+"]")}return t}function Ff(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=Bf(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 jf=Ff(Df)
628
- ;function Hf(e,t){return e.reduce(((e,n)=>t(n)?e+1:e),0)}function Uf(e){const t={};return e.forEach((e=>t[e]=!0)),t}function qf(e){return Object.keys(e).filter((t=>!0===e[t]))}const $f={CHANGE_ROUTE:(e,{name:t,params:n})=>({name:t,params:n})},Gf=Xm($f);const Vf=Mf({name:null,params:{}},{namespace:"route",reducers:$f,actionCreators:{changeRoute:function(e,t={}){return{type:Gf.CHANGE_ROUTE,name:e,params:t}}},selectors:{route:function(e){return e.name},routeParams:function(e){return e.params}}});function Wf(e,t){return e.find((e=>e.id===t))}function Yf(e,t){return e.find((e=>e.$tag===t))}const Kf={ADD_ANNOTATIONS:function(e,t){const n={},r={},o=[],i=[],a=[];let s=e.nextTag;return t.annotations.forEach((t=>{let i;t.id&&(i=Wf(e.annotations,t.id)),!i&&t.$tag&&(i=Yf(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)})),
629
- e.annotations.forEach((e=>{n[e.id]||r[e.$tag]||i.push(e)})),{annotations:o.concat(a).concat(i),nextTag:s}},CLEAR_ANNOTATIONS:function(){return{annotations:[],focused:{},highlighted:{}}},FOCUS_ANNOTATIONS:function(e,t){return{focused:Uf(t.focusedTags)}},HIDE_ANNOTATION:function(e,t){return{annotations:e.annotations.map((e=>e.id!==t.id?e:{...e,hidden:!0}))}},HIGHLIGHT_ANNOTATIONS:function(e,t){return{highlighted:t.highlighted}},REMOVE_ANNOTATIONS:function(e,t){return{annotations:[...t.remainingAnnotations]}},UNHIDE_ANNOTATION:function(e,t){return{annotations:e.annotations.map((e=>e.id!==t.id?e:Object.assign({},e,{hidden:!1})))}},UPDATE_ANCHOR_STATUS:function(e,t){return{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:function(e,t){return{annotations:e.annotations.map((e=>{if(e.id&&e.id===t.id){
630
- if(e.flagged===t.isFlagged)return e;const n=Object.assign({},e,{flagged:t.isFlagged});if(n.moderation){const r=t.isFlagged?1:-1;n.moderation=Object.assign({},e.moderation,{flagCount:e.moderation.flagCount+r})}return n}return e}))}}},Xf=Xm(Kf);function Zf(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:Xf.REMOVE_ANNOTATIONS,annotationsToRemove:e,remainingAnnotations:r})}}function Jf(e){return{type:Xf.UPDATE_ANCHOR_STATUS,statusUpdates:e}}const Qf=Mf({annotations:[],focused:{},highlighted:{},nextTag:1},{namespace:"annotations",reducers:Kf,actionCreators:{addAnnotations:function(e){return function(t,n){const r=e.filter((e=>!Wf(n().annotations.annotations,e.id)));if(t({type:Xf.ADD_ANNOTATIONS,annotations:e,currentAnnotationCount:n().annotations.annotations.length}),"sidebar"!==Vf.selectors.route(n().route))return
631
- ;const o=r.filter(Ei).map((e=>e.id));o.length>0&&setTimeout((()=>{const e=n().annotations.annotations,r=o.map((t=>Wf(e,t))).filter((e=>e&&Ei(e))).reduce(((e,t)=>(e[t.$tag]="timeout",e)),{});t(Jf(r))}),500)}},clearAnnotations:function(){return{type:Xf.CLEAR_ANNOTATIONS}},focusAnnotations:function(e){return{type:Xf.FOCUS_ANNOTATIONS,focusedTags:e}},hideAnnotation:function(e){return{type:Xf.HIDE_ANNOTATION,id:e}},highlightAnnotations:function(e){return{type:Xf.HIGHLIGHT_ANNOTATIONS,highlighted:Uf(e)}},removeAnnotations:Zf,unhideAnnotation:function(e){return{type:Xf.UNHIDE_ANNOTATION,id:e}},updateAnchorStatus:Jf,updateFlagStatus:function(e,t){return{type:Xf.UPDATE_FLAG_STATUS,id:e,isFlagged:t}}},selectors:{allAnnotations:function(e){return e.annotations},annotationCount:jf((e=>e.annotations),(e=>Hf(e,zi))),annotationExists:function(e,t){return e.annotations.some((e=>e.id===t))},findAnnotationByID:function(e,t){return Wf(e.annotations,t)},findIDsForTags:function(e,t){const n=[];return t.forEach((t=>{
632
- const r=Yf(e.annotations,t);r&&r.id&&n.push(r.id)})),n},focusedAnnotations:jf((e=>e.focused),(e=>qf(e))),highlightedAnnotations:jf((e=>e.highlighted),(e=>qf(e))),isAnnotationFocused:function(e,t){return!0===e.focused[t]},isWaitingToAnchorAnnotations:jf((e=>e.annotations),(e=>e.some(Ei))),newAnnotations:jf((e=>e.annotations),(e=>e.filter((e=>Si(e)&&!Ni(e))))),newHighlights:jf((e=>e.annotations),(e=>e.filter((e=>Si(e)&&Ni(e))))),noteCount:jf((e=>e.annotations),(e=>Hf(e,Mi))),orphanCount:jf((e=>e.annotations),(e=>Hf(e,Li))),savedAnnotations:function(e){return e.annotations.filter((e=>!Si(e)))}}}),eg={SET_DEFAULT:function(e,t){return{[t.defaultKey]:t.value}}},tg=Xm(eg);const ng=Mf({annotationPrivacy:null,focusedGroup:null},{namespace:"defaults",reducers:eg,actionCreators:{setDefault:function(e,t){return{type:tg.SET_DEFAULT,defaultKey:e,value:t}}},selectors:{getDefault:function(e,t){return e[t]},getDefaults:function(e){return e}}});const rg={UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED:(e,t)=>({
633
- directLinkedGroupFetchFailed:t.directLinkedGroupFetchFailed}),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}}},og=Xm(rg);const ig=Mf((function(e){return{directLinkedGroupId:e.group||null,directLinkedAnnotationId:e.annotations||null,directLinkedGroupFetchFailed:!1}}),{namespace:"directLinked",reducers:rg,actionCreators:{setDirectLinkedGroupFetchFailed:function(){return{type:og.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!0}},setDirectLinkedGroupId:function(e){return{type:og.UPDATE_DIRECT_LINKED_GROUP_ID,directLinkedGroupId:e}},setDirectLinkedAnnotationId:function(e){return{type:og.UPDATE_DIRECT_LINKED_ANNOTATION_ID,directLinkedAnnotationId:e}},
634
- clearDirectLinkedGroupFetchFailed:function(){return{type:og.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!1}},clearDirectLinkedIds:function(){return{type:og.CLEAR_DIRECT_LINKED_IDS}}},selectors:{directLinkedAnnotationId:function(e){return e.directLinkedAnnotationId},directLinkedGroupFetchFailed:function(e){return e.directLinkedGroupFetchFailed},directLinkedGroupId:function(e){return e.directLinkedGroupId}}});class ag{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 sg={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}},lg=Xm(sg);function cg(e){return{type:lg.REMOVE_DRAFT,annotation:e}}
635
- function ug(e,t){const n=e;for(let e=0;e<n.length;e++){const r=n[e];if(r.match(t))return r}return null}function hg(e,t){const n=ug(e,t);return n?n.isEmpty()?null:n:null}const dg=jf((e=>e),(e=>e.filter((e=>!e.annotation.id)).map((e=>e.annotation)))),pg=Mf([],{namespace:"drafts",reducers:sg,actionCreators:{createDraft:function(e,t){return{type:lg.UPDATE_DRAFT,draft:new ag(e,t)}},deleteNewAndEmptyDrafts:function(){return(e,t)=>{const n=t().drafts.filter((e=>Si(e.annotation)&&!hg(t().drafts,e.annotation))).map((t=>(e(cg(t.annotation)),t.annotation)));e(Zf(n))}},discardAllDrafts:function(){return{type:lg.DISCARD_ALL_DRAFTS}},removeDraft:cg},selectors:{countDrafts:function(e){return e.length},getDraft:ug,getDraftIfNotEmpty:hg,unsavedAnnotations:dg}});function mg(e){var t,n;return!!(null!==(t=e.user)&&void 0!==t&&t.username||null!==(n=e.user)&&void 0!==n&&n.userid)}function fg(e){if(!mg(e))return{};const t=e.user.username||e.user.userid||"";return{user:{value:t,display:e.user.displayName||t}}}const gg={
636
- CHANGE_FOCUS_MODE_USER:function(e,t){return{focusActive:mg({user:t.user}),focusFilters:fg({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}}},vg=Xm(gg);const yg=jf((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)||""}})),_g=jf((e=>e.filters),(e=>e.focusActive),(e=>e.focusFilters),((e,t,n)=>t?{...n,...e}:{...e}));const bg=jf((e=>_g(e)),(e=>{const t={};return Object.keys(e).forEach((n=>t[n]=e[n].value)),t}));const wg=Mf((function(e){const t=e.focus||{};return{filters:{},focusActive:mg(t),focusFilters:fg(t),
637
- query:e.query||null}}),{namespace:"filters",reducers:gg,actionCreators:{changeFocusModeUser:function(e){return{type:vg.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:vg.SET_FOCUS_MODE,active:!1}),n({type:vg.SET_FILTER,filterName:e,filterOption:t})}},setFilterQuery:function(e){return{type:vg.SET_FILTER_QUERY,query:e}},toggleFocusMode:function(e){return{type:vg.SET_FOCUS_MODE,active:e}}},selectors:{filterQuery:function(e){return e.query},focusState:yg,getFilter:function(e,t){return _g(e)[t]},getFilters:_g,getFilterValues:bg,getFocusFilters:function(e){return e.focusFilters},hasAppliedFilter:function(e){return!(!e.query&&!Object.keys(_g(e)).length)}}}),xg={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,{
638
- isAnnotationFetchComplete:t.isAnnotationFetchComplete}):e))}},kg=Xm(xg);const Sg=jf((e=>e),(e=>e.find((e=>!e.id))||null));const Cg=Ff(Df,Um)((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)),Ag=Mf([],{namespace:"frames",reducers:xg,actionCreators:{connectFrame:function(e){return{type:kg.CONNECT_FRAME,frame:e}},destroyFrame:function(e){return{type:kg.DESTROY_FRAME,frame:e}},updateFrameAnnotationFetchStatus:function(e,t){return{type:kg.UPDATE_FRAME_ANNOTATION_FETCH_STATUS,isAnnotationFetchComplete:t,uri:e}}},selectors:{frames:function(e){return e},mainFrame:Sg,searchUris:Cg}}),Eg={features:{},preferences:{},userid:null};const Tg={UPDATE_PROFILE:function(e,t){return{profile:{...t.profile}}}},Ng=Xm(Tg);const Lg=Mf((function(e){var t;return{
639
- defaultAuthority:null!==(t=null==e?void 0:e.authDomain)&&void 0!==t?t:"",profile:Eg}}),{namespace:"session",reducers:Tg,actionCreators:{updateProfile:function(e){return{type:Ng.UPDATE_PROFILE,profile:e}}},selectors:{defaultAuthority:function(e){return e.defaultAuthority},hasFetchedProfile:function(e){return e.profile!==Eg},isFeatureEnabled:function(e,t){return!!e.profile.features[t]},isLoggedIn:function(e){return null!==e.profile.userid},profile:function(e){return e.profile}}}),Mg={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){
640
- const n=t.groups;let r=e.focusedGroupId;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:[]})},zg=Xm(Mg);function Og(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 Ig(e,t){return e.groups.find((e=>e.id===t))}const Rg=jf((e=>Og(e)),(e=>e.filter((e=>!e.isMember&&e.isScopedToUri)))),Pg=jf((e=>Og(e)),(e=>e.filter((e=>e.isScopedToUri)))),Dg=jf((e=>Og(e.groups)),(e=>Lg.selectors.isLoggedIn(e.session)),((e,t)=>t?e.filter((e=>e.isMember)):[])),Bg=jf((e=>Og(e.groups)),(e=>Dg(e)),(e=>Rg(e.groups)),((e,t,n)=>e.filter((e=>!t.includes(e)&&!n.includes(e))))),Fg=Mf({filteredGroupIds:null,groups:[],focusedGroupId:null},{namespace:"groups",reducers:Mg,actionCreators:{filterGroups:function(e){return{type:zg.FILTER_GROUPS,filteredGroupIds:e}},focusGroup:function(e){return{
641
- type:zg.FOCUS_GROUP,id:e}},loadGroups:function(e){return{type:zg.LOAD_GROUPS,groups:e}},clearGroups:function(){return{type:zg.CLEAR_GROUPS}}},selectors:{allGroups:function(e){return e.groups},filteredGroups:Og,filteredGroupIds:function(e){return e.filteredGroupIds},focusedGroup:function(e){return e.focusedGroupId?Ig(e,e.focusedGroupId):null},focusedGroupId:function(e){return e.focusedGroupId},getFeaturedGroups:Rg,getGroup:Ig,getInScopeGroups:Pg},rootSelectors:{getCurrentlyViewingGroups:Bg,getMyGroups:Dg}}),jg={UPDATE_LINKS:(e,t)=>({...t.links})},Hg=Xm(jg);const Ug=Mf(null,{namespace:"links",reducers:jg,actionCreators:{updateLinks:function(e){return{type:Hg.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}=Tm(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},
642
- pendingDeletions:{...t.pendingDeletions}}),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:{}})},$g=Xm(qg);const Gg=jf((e=>[e.pendingUpdates,e.pendingDeletions]),(([e,t])=>Object.keys(e).length+Object.keys(t).length));const Vg=Mf({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
643
- ;e.group!==Fg.selectors.focusedGroupId(t)&&"sidebar"===Vf.selectors.route(n)||(o[e.id]=e)})),t.forEach((e=>{const t=e.id;delete o[t];const n=r().annotations;Qf.selectors.annotationExists(n,t)&&(i[t]=!0)})),n({type:$g.RECEIVE_REAL_TIME_UPDATES,pendingUpdates:o,pendingDeletions:i})}},clearPendingUpdates:function(){return{type:$g.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:Gg}}),Wg={annotation:"Location",note:"Oldest",orphan:"Location"};function Yg(e){const t={};return e.annotations&&!e.query&&(t[e.annotations]=!0),t}const Kg=(e,t)=>t===e?{}:{selectedTab:e,sortKey:Wg[e]},Xg={CLEAR_SELECTION:function(){return{forcedVisible:{},selected:{}}},SELECT_ANNOTATIONS:function(e,t){return{selected:t.selection}},SELECT_TAB:function(e,t){return Kg(t.tab,e.selectedTab)},SET_EXPANDED:function(e,t){const n={...e.expanded}
644
- ;return n[t.id]=t.expanded,{expanded:n}},SET_FORCED_VISIBLE:function(e,t){return{forcedVisible:{...e.forcedVisible,[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=>!ki(e))),r=Hf(t.annotations,Mi)===n.length;return 0===t.currentAnnotationCount&&r?Kg("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===Hf(t.remainingAnnotations,Li)&&(n="annotation");const r=e=>(t.annotationsToRemove.forEach((t=>{t.id&&delete e[t.id],t.$tag&&delete e[t.$tag]})),e);return{...Kg(n,e.selectedTab),expanded:r({
645
- ...e.expanded}),forcedVisible:r({...e.forcedVisible}),selected:r({...e.selected})}}},Zg=Xm(Xg);function Jg(e){return e.expanded}const Qg=jf((e=>e.forcedVisible),(e=>qf(e))),ev=jf((e=>e.selected),(e=>qf(e).length>0)),tv=jf((e=>e.selected),(e=>qf(e)));function nv(e){return e.selectedTab}const rv=jf((e=>e),(e=>({expanded:Jg(e),forcedVisible:Qg(e),selected:tv(e),sortKey:ov(e),selectedTab:nv(e)})));function ov(e){return e.sortKey}const iv=jf((e=>e.selectedTab),(e=>{const t=["Newest","Oldest"];return"note"!==e&&t.push("Location"),t})),av=Mf((function(e){return{selected:Yg(e),expanded:Yg(e)||{},forcedVisible:{},selectedTab:"annotation",sortKey:Wg.annotation}}),{namespace:"selection",reducers:Xg,actionCreators:{clearSelection:function(){return{type:Zg.CLEAR_SELECTION}},selectAnnotations:function(e){return t=>{t({type:Zg.CLEAR_SELECTION}),t({type:Zg.SELECT_ANNOTATIONS,selection:Uf(e)})}},selectTab:function(e){return{type:Zg.SELECT_TAB,tab:e}},setExpanded:function(e,t){return{type:Zg.SET_EXPANDED,id:e,expanded:t}},
646
- setForcedVisible:function(e,t){return{type:Zg.SET_FORCED_VISIBLE,id:e,visible:t}},setSortKey:function(e){return{type:Zg.SET_SORT_KEY,key:e}},toggleSelectedAnnotations:function(e){return{type:Zg.TOGGLE_SELECTED_ANNOTATIONS,toggleIds:e}}},selectors:{expandedMap:Jg,forcedVisibleThreads:Qg,hasSelectedAnnotations:ev,selectedAnnotations:tv,selectedTab:nv,selectionState:rv,sortKey:ov,sortKeys:iv}}),sv={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}}},lv=Xm(sv);const cv=Mf({activePanelName:null},{namespace:"sidebarPanels",reducers:sv,actionCreators:{openSidebarPanel:function(e){return{type:lv.OPEN_SIDEBAR_PANEL,panelName:e}},closeSidebarPanel:function(e){return{type:lv.CLOSE_SIDEBAR_PANEL,
647
- panelName:e}},toggleSidebarPanel:function(e,t){return{type:lv.TOGGLE_SIDEBAR_PANEL,panelName:e,panelState:t}}},selectors:{isSidebarPanelOpen:function(e,t){return e.activePanelName===t}}}),uv={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))}}},hv=Xm(uv);const dv=Mf({messages:[]},{namespace:"toastMessages",reducers:uv,actionCreators:{addToastMessage:function(e){return{type:hv.ADD_MESSAGE,message:e}},removeToastMessage:function(e){return{type:hv.REMOVE_MESSAGE,id:e}},updateToastMessage:function(e){return{type:hv.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))}}}),pv={
648
- SET_SIDEBAR_OPENED:(e,t)=>!0===t.opened?{sidebarHasOpened:!0}:{}},mv=Xm(pv);const fv=Mf({sidebarHasOpened:!1},{namespace:"viewer",reducers:pv,actionCreators:{setSidebarOpened:function(e){return{type:mv.SET_SIDEBAR_OPENED,opened:e}}},selectors:{hasSidebarOpened:function(e){return e.sidebarHasOpened}}});function gv(e){return Lf([Rf,Qf,ng,ig,pg,wg,Ag,Ug,Fg,Vg,Vf,av,Lg,cv,dv,fv],[e],[zf])}gv.$inject=["settings"];class vv{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){
649
- 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)}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 yv=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),_v=function(e){const{version:t,origin:n}=R(e.location.href)
650
- ;return"1.976.0"!==t?(console.warn(`The Hypothesis sidebar is using a different version (1.976.0) than the host page (${t}). It may not work.`),!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 bv(e,t){e.setClientId(t.clientId)}function wv(e,t,n){e.load(),t.load(),n.sync()}function xv(e,t,n,r){e.init(),t.init(),n.init(),r.init()}function kv(e,t){"sidebar"===t.route()&&e.connect()}yv.sentry&&_v&&function(e){const t=function(){let e=import.meta.url;return e?new URL(e).origin:null}(),n=t?[t]:void 0;wr({dsn:e.dsn,environment:e.environment,allowUrls:n,ignoreErrors:["Network request failed","Object Not Found Matching Id"],release:"1.976.0",beforeSend:(e,t)=>{if(Sr>=5)return K("Client-side Sentry quota reached. No further Sentry events will be sent"),null;++Sr;try{
651
- 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{Yt("host_config",R(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>"))),kr(((e,t)=>{Wt(e,{tags:{context:t}})}))}(yv.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=>{"string"==typeof e.type&&"dir"in e.props&&"auto"===e.props.dir&&(e.props.dir=""),t&&t(e)}}}(),bv.$inject=["api","streamer"],wv.$inject=["groups","session","router"],xv.$inject=["autosaveService","features","persistedDefaults","serviceURL"],kv.$inject=["frameSync","store"],function(e,{reset:t=!1}={}){t&&mo.clear()
652
- ;for(let[t,n]of Object.entries(e))mo.set(t,n)}(Ko);const Sv=document.querySelector("hypothesis-app");!function(e=window){e.addEventListener("message",te)}(),async function(e,t=window){const n=H(window),r=n.requestConfigFromFrame;if(!r)return V(e,n);if("string"==typeof r)return await G(e,t);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 W(e,o,r.origin),...n.group?{group:n.group}:{}}}throw new Error("Improper `requestConfigFromFrame` object. Both `ancestorLevel` and `origin` need to be specified")}(yv).then((e=>{!function(e,t){const n=new vv
653
- ;n.register("annotationsService",Cm).register("api",Lm).register("apiRoutes",Dm).register("auth",jm).register("autosaveService",Hm).register("features",$m).register("frameSync",Km).register("groups",Qm).register("loadAnnotationsService",ef).register("localStorage",nf).register("persistedDefaults",of).register("router",af).register("serviceURL",sf).register("session",lf).register("streamer",hf).register("streamFilter",cf).register("tags",df).register("threadsService",pf).register("toastMessenger",mf).register("store",{factory:gv}),n.register("$window",{value:window}).register("settings",{value:e}),n.run(xv),n.run(bv),n.run(wv),n.run(ee),n.run(kv),I(po(ni.Provider,{value:n,children:po(km,{})}),t)}(e,Sv)})).catch((e=>function(e,t){console.error("Failed to start Hypothesis client: ",e),I(po(Sm,{error:e}),t)}(e,Sv)));
598
+ !t)throw new Error("Invalid request of channel/port");return new Promise(((t,n)=>{const r=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:e,type:"request"},"*")},o=setInterval(r,250),i=setTimeout((()=>{clearInterval(o),n(new Error(`Unable to establish ${this._source}-${e} communication channel`))}),2e4),a=this._listeners.add(window,"message",(n=>{const{data:r,ports:s}=n;Gm(r,{frame1:this._source,frame2:e,type:"offer"})&&(clearInterval(o),clearTimeout(i),this._listeners.remove(a),t(s[0]))}));r()}))}}class Wm{constructor(){this._port=null,this._methods=new Map,this._sequence=1,this._callbacks=new Map,this._listeners=new ha,this._pendingCalls=[]}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();for(let[e,t]of this._pendingCalls)this.call(e,...t);this._pendingCalls=[]}disconnect(){const e=this._port;return this._port=null,
599
+ this._listeners.removeAll(),e}destroy(){const e=this.disconnect();null==e||e.close(),this._destroyed=!0}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));const o={arguments:t,method:e,protocol:"frame-rpc",sequence:n,version:"1.0.0"};this._port.postMessage(o)}_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){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 Ym({$tag:e,target:t,uri:n}){return{$tag:e,target:t,uri:n}}function Km(e,t){
600
+ const n=e.find((e=>e.uri===t.uri));return n||e.find((e=>null===e.id))}class Xm{constructor(e,t,n){this._window=e,this._annotationsService=t,this._store=n,this._portFinder=new Vm({hostFrame:this._window.parent,source:"sidebar"}),this._listeners=new ha,this._hostRPC=new Wm,this._guestRPC=new Map,this._nextGuestId=0,this._inFrame=new Set,this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0;qm(this._store.subscribe,[()=>this._store.allAnnotations(),()=>this._store.frames()],(([t,n],[r])=>{let o=0;const i=new Set,a=[];t.forEach((e=>{ki(e)||(Ci(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=Km(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(Ym))}a.forEach((e=>{this._inFrame.add(e.$tag)}))}s.forEach((e=>{
601
+ 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 Wm;++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({id:e.frameIdentifier,metadata:e.metadata,uri:e.uri})})),t.on("frameDestroyed",(()=>{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"),
602
+ this._annotationsService.create(e)}));let r={};const o=ua((()=>{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=>{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")
603
+ ;this._hostRPC.connect(e),this._hostRPC.call("ready"),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;Gm(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(),this._listeners.removeAll()}}function Zm(e){return Object.keys(e).reduce(((e,t)=>(e[t]=t,e)),{})}Xm.$inject=["$window","annotationsService","store"];const Jm={id:"__default__",name:"__DEFAULT__",logo:"data:image/svg+xml;utf8,"+encodeURIComponent(Yo)};const Qm=["organization","scopes"];class ef{constructor(e,t,n,r,o,i){this._store=e,this._api=t,this._auth=n,this._settings=o,this._toastMessenger=i,this._serviceConfig=P(o),this._reloadSetUp=!1}_mainURI(){var e,t
604
+ ;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,qm(this._store.subscribe,(()=>this._mainURI()),(()=>{this.load()})),qm(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=Jm)}))}(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))}
605
+ _fetchGroup(e){return this._api.group.read({id:e,expand:Qm})}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;i&&(a=this._fetchGroup(i).then((e=>(this._store.clearDirectLinkedGroupFetchFailed(),e))).catch((()=>(this._store.setDirectLinkedGroupFetchFailed(),null))));const s={expand:Qm},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:Qm}),this._api.groups.list(s),this._auth.getAccessToken(),o,a]);p&&!u.some((e=>e.id===p.id))&&u.push(p);let m=null
606
+ ;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(J(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:Qm});let n;const r=async e=>{try{return await this._fetchGroup(e)}catch(e){return n=e,null}},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}`)}
607
+ 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=>!ki(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"})}}ef.$inject=["store","api","auth","session","settings","toastMessenger"];class tf{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()
608
+ });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 tm(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)})),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}),ki(t)&&(t=await this._api.annotation.get({
609
+ 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),!ki(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}}tf.$inject=["api","store","streamer","streamFilter"];class nf{constructor(){this._store={}}getItem(e){return e in this._store?this._store[e]:null}setItem(e,t){this._store[e]=t}removeItem(e){delete this._store[e]}}class rf{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 nf}}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)}
610
+ removeItem(e){this._storage.removeItem(e)}}rf.$inject=["$window"];const of={annotationPrivacy:"hypothesis.privacy",focusedGroup:"hypothesis.groups.focus"};class af{constructor(e,t){this._storage=e,this._store=t}init(){Object.keys(of).forEach((e=>{const t=this._storage.getItem(of[e]);this._store.setDefault(e,t)})),qm(this._store.subscribe,(()=>this._store.getDefaults()),((e,t)=>{for(let n in e)t[n]!==e[n]&&n in of&&this._storage.setItem(of[n],e[n])}))}}af.$inject=["localStorage","store"];class sf{constructor(e,t){this._window=e,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":
611
+ {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){this._window.history.pushState({},"",this.routeUrl(e,t)),this.sync()}}sf.$inject=["$window","store"];class lf{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}`)}}}lf.$inject=["apiRoutes","store"];class cf{constructor(e,t,n,r,o){var i,a;this._api=t,this._auth=n,this._store=e,this._toastMessenger=o,
612
+ this._authority=null!==(i=null===(a=P(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=Rm((()=>{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(){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?Cr({id:e.userid}):Cr(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(){
613
+ return this._lastLoad=null,this._lastLoadTime=null,this.load()}}cf.$inject=["store","api","auth","settings","toastMessenger"];class uf{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 hf extends Jp{constructor(e){super();const t=[];let n;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")},
614
+ n.onerror=e=>{this.emit("error",e)},n.onmessage=e=>{this.emit("message",e)}})()}}class df{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=q(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})));t.length&&this._store.removeAnnotations(t),this._store.clearPendingUpdates()}_handleSocketError(e,t){K("Error connecting to H push notification service:",t);const n=new URL(e).hostname;-1!==["localhost","127.0.0.1"].indexOf(n)&&K("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){
615
+ 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 K("Received unsupported notification",t.type)}_sendClientConfig(e){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){
616
+ 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 hf(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))),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,qm(this._store.subscribe,(()=>this._store.profile().userid),(()=>{this._reconnect()}))),
617
+ this._socket||await this._reconnect()}}df.$inject=["store","apiRoutes","auth","groups","session"];class pf{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(`^${Z(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);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)}}pf.$inject=["localStorage"];class mf{constructor(e){this._store=e}forceVisible(e){e.children.forEach((e=>{this.forceVisible(e)})),e.visible||this._store.setForcedVisible(e.id,!0)}}mf.$inject=["store"];class ff{constructor(e){this._store=e}
618
+ 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=q(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 gf(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function vf(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 yf(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{}
619
+ ;t%2?vf(Object(n),!0).forEach((function(t){gf(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):vf(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _f(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. "}ff.$inject=["store"];var bf="function"==typeof Symbol&&Symbol.observable||"@@observable",wf=function(){return Math.random().toString(36).substring(7).split("").join(".")},xf={INIT:"@@redux/INIT"+wf(),REPLACE:"@@redux/REPLACE"+wf(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+wf()}};function kf(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 Sf(e,t,n){var r
620
+ ;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(_f(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(_f(1));return n(Sf)(e,t)}if("function"!=typeof e)throw new Error(_f(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(_f(3));return i}function h(e){if("function"!=typeof e)throw new Error(_f(4));if(l)throw new Error(_f(5));var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error(_f(6));t=!1,c();var n=s.indexOf(e);s.splice(n,1),a=null}}}function d(e){if(!kf(e))throw new Error(_f(7));if(void 0===e.type)throw new Error(_f(8));if(l)throw new Error(_f(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(_f(10));o=e,d({type:xf.REPLACE})}function m(){var e,t=h;return(e={subscribe:function(e){
621
+ if("object"!=typeof e||null===e)throw new Error(_f(11));function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[bf]=function(){return this},e}return d({type:xf.INIT}),(r={dispatch:d,subscribe:h,getState:u,replaceReducer:p})[bf]=m,r}function Cf(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:xf.INIT}))throw new Error(_f(12));if(void 0===n(void 0,{type:xf.PROBE_UNKNOWN_ACTION()}))throw new Error(_f(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,new Error(_f(14));o[l]=h,r=r||h!==u}return(r=r||a.length!==Object.keys(e).length)?o:e}}function Af(e,t){return function(){return t(e.apply(this,arguments))}}function Ef(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n]
622
+ ;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 Tf(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 Nf=Tf();Nf.withExtraArgument=Tf;var Lf=Nf;function Mf(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(){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(_f(15))},o={getState:n.getState,dispatch:function(){return r.apply(void 0,arguments)}},i=t.map((function(e){
623
+ return e(o)}));return r=Ef.apply(void 0,i)(n.dispatch),yf(yf({},n),{},{dispatch:r})}}}(...[Lf],...n);const s=Sf(Cf(o),r,a),l=Object.assign({},...e.map((e=>e.actionCreators))),c=function(e,t){if("function"==typeof e)return Af(e,t);if("object"!=typeof e||null===e)throw new Error(_f(16));var n={};for(var r in e){var o=e[r];"function"==typeof o&&(n[r]=Af(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);return Object.assign(s,c,u),s}function zf(e,t){if(!(e instanceof Function)){const t=e;e=()=>t}return{initialState:e,...t}}function Of(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),
624
+ console.log("Prev State:",e.getState()),console.log("Action:",r),n(r),console.log("Next State:",e.getState()),console.groupEnd()}}}const If={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,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")
625
+ ;return{...e,hasFetchedAnnotations:!0,activeAnnotationFetches:e.activeAnnotationFetches-1}},SET_ANNOTATION_RESULT_COUNT:(e,t)=>({annotationResultCount:t.resultCount})},Rf=Zm(If);const Pf=zf({activeAnnotationSaveRequests:[],activeApiRequests:0,activeAnnotationFetches:0,hasFetchedAnnotations:!1,annotationResultCount:null},{reducers:If,namespace:"activity",actionCreators:{annotationFetchStarted:function(){return{type:Rf.ANNOTATION_FETCH_STARTED}},annotationFetchFinished:function(){return{type:Rf.ANNOTATION_FETCH_FINISHED}},annotationSaveStarted:function(e){return{type:Rf.ANNOTATION_SAVE_STARTED,annotation:e}},annotationSaveFinished:function(e){return{type:Rf.ANNOTATION_SAVE_FINISHED,annotation:e}},apiRequestStarted:function(){return{type:Rf.API_REQUEST_STARTED}},apiRequestFinished:function(){return{type:Rf.API_REQUEST_FINISHED}},setAnnotationResultCount:function(e){return{type:Rf.SET_ANNOTATION_RESULT_COUNT,resultCount:e}}},selectors:{hasFetchedAnnotations:function(e){return e.hasFetchedAnnotations},
626
+ 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 Df=function(e,t){return e===t};function Bf(e,t){var n,r,o="object"==typeof t?t:{equalityCheck:t},i=o.equalityCheck,a=void 0===i?Df: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"},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{
627
+ 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 Ff(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(", ");throw new Error("createSelector expects all input-selectors to be functions, but received the following types: ["+n+"]")}return t}function jf(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()),
628
+ "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=Ff(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 Hf=jf(Bf);function Uf(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 $f(e){return Object.keys(e).filter((t=>!0===e[t]))}const Gf={CHANGE_ROUTE:(e,{name:t,params:n})=>({name:t,params:n})},Vf=Zm(Gf);const Wf=zf({name:null,params:{}},{namespace:"route",reducers:Gf,actionCreators:{changeRoute:function(e,t={}){return{type:Vf.CHANGE_ROUTE,name:e,params:t}}},
629
+ selectors:{route:function(e){return e.name},routeParams:function(e){return e.params}}});function Yf(e,t){return e.find((e=>e.id===t))}function Kf(e,t){return e.find((e=>e.$tag===t))}const Xf={ADD_ANNOTATIONS:function(e,t){const n={},r={},o=[],i=[],a=[];let s=e.nextTag;return t.annotations.forEach((t=>{let i;t.id&&(i=Yf(e.annotations,t.id)),!i&&t.$tag&&(i=Kf(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)})),e.annotations.forEach((e=>{n[e.id]||r[e.$tag]||i.push(e)})),{annotations:o.concat(a).concat(i),nextTag:s}},CLEAR_ANNOTATIONS:function(){return{annotations:[],focused:{},highlighted:{}}},FOCUS_ANNOTATIONS:function(e,t){return{focused:qf(t.focusedTags)}},HIDE_ANNOTATION:function(e,t){return{annotations:e.annotations.map((e=>e.id!==t.id?e:{...e,hidden:!0}))}},HIGHLIGHT_ANNOTATIONS:function(e,t){return{
630
+ highlighted:t.highlighted}},REMOVE_ANNOTATIONS:function(e,t){return{annotations:[...t.remainingAnnotations]}},UNHIDE_ANNOTATION:function(e,t){return{annotations:e.annotations.map((e=>e.id!==t.id?e:Object.assign({},e,{hidden:!1})))}},UPDATE_ANCHOR_STATUS:function(e,t){return{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:function(e,t){return{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){const r=t.isFlagged?1:-1;n.moderation=Object.assign({},e.moderation,{flagCount:e.moderation.flagCount+r})}return n}return e}))}}},Zf=Zm(Xf);function Jf(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)})),
631
+ e.filter((e=>!(e.id&&e.id in n||e.$tag&&e.$tag in r)))}(n().annotations.annotations,e);t({type:Zf.REMOVE_ANNOTATIONS,annotationsToRemove:e,remainingAnnotations:r})}}function Qf(e){return{type:Zf.UPDATE_ANCHOR_STATUS,statusUpdates:e}}const eg=zf({annotations:[],focused:{},highlighted:{},nextTag:1},{namespace:"annotations",reducers:Xf,actionCreators:{addAnnotations:function(e){return function(t,n){const r=e.filter((e=>!Yf(n().annotations.annotations,e.id)));if(t({type:Zf.ADD_ANNOTATIONS,annotations:e,currentAnnotationCount:n().annotations.annotations.length}),"sidebar"!==Wf.selectors.route(n().route))return;const o=r.filter(Ei).map((e=>e.id));o.length>0&&setTimeout((()=>{const e=n().annotations.annotations,r=o.map((t=>Yf(e,t))).filter((e=>e&&Ei(e))).reduce(((e,t)=>(e[t.$tag]="timeout",e)),{});t(Qf(r))}),500)}},clearAnnotations:function(){return{type:Zf.CLEAR_ANNOTATIONS}},focusAnnotations:function(e){return{type:Zf.FOCUS_ANNOTATIONS,focusedTags:e}},hideAnnotation:function(e){return{type:Zf.HIDE_ANNOTATION,id:e}
632
+ },highlightAnnotations:function(e){return{type:Zf.HIGHLIGHT_ANNOTATIONS,highlighted:qf(e)}},removeAnnotations:Jf,unhideAnnotation:function(e){return{type:Zf.UNHIDE_ANNOTATION,id:e}},updateAnchorStatus:Qf,updateFlagStatus:function(e,t){return{type:Zf.UPDATE_FLAG_STATUS,id:e,isFlagged:t}}},selectors:{allAnnotations:function(e){return e.annotations},annotationCount:Hf((e=>e.annotations),(e=>Uf(e,zi))),annotationExists:function(e,t){return e.annotations.some((e=>e.id===t))},findAnnotationByID:function(e,t){return Yf(e.annotations,t)},findIDsForTags:function(e,t){const n=[];return t.forEach((t=>{const r=Kf(e.annotations,t);r&&r.id&&n.push(r.id)})),n},focusedAnnotations:Hf((e=>e.focused),(e=>$f(e))),highlightedAnnotations:Hf((e=>e.highlighted),(e=>$f(e))),isAnnotationFocused:function(e,t){return!0===e.focused[t]},isWaitingToAnchorAnnotations:Hf((e=>e.annotations),(e=>e.some(Ei))),newAnnotations:Hf((e=>e.annotations),(e=>e.filter((e=>Si(e)&&!Ni(e))))),
633
+ newHighlights:Hf((e=>e.annotations),(e=>e.filter((e=>Si(e)&&Ni(e))))),noteCount:Hf((e=>e.annotations),(e=>Uf(e,Mi))),orphanCount:Hf((e=>e.annotations),(e=>Uf(e,Li))),savedAnnotations:function(e){return e.annotations.filter((e=>!Si(e)))}}}),tg={SET_DEFAULT:function(e,t){return{[t.defaultKey]:t.value}}},ng=Zm(tg);const rg=zf({annotationPrivacy:null,focusedGroup:null},{namespace:"defaults",reducers:tg,actionCreators:{setDefault:function(e,t){return{type:ng.SET_DEFAULT,defaultKey:e,value:t}}},selectors:{getDefault:function(e,t){return e[t]},getDefaults:function(e){return e}}});const og={UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED:(e,t)=>({directLinkedGroupFetchFailed:t.directLinkedGroupFetchFailed}),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{
634
+ directLinkedAnnotationId:null,directLinkedGroupId:null,directLinkedGroupFetchFailed:!1}}},ig=Zm(og);const ag=zf((function(e){return{directLinkedGroupId:e.group||null,directLinkedAnnotationId:e.annotations||null,directLinkedGroupFetchFailed:!1}}),{namespace:"directLinked",reducers:og,actionCreators:{setDirectLinkedGroupFetchFailed:function(){return{type:ig.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!0}},setDirectLinkedGroupId:function(e){return{type:ig.UPDATE_DIRECT_LINKED_GROUP_ID,directLinkedGroupId:e}},setDirectLinkedAnnotationId:function(e){return{type:ig.UPDATE_DIRECT_LINKED_ANNOTATION_ID,directLinkedAnnotationId:e}},clearDirectLinkedGroupFetchFailed:function(){return{type:ig.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!1}},clearDirectLinkedIds:function(){return{type:ig.CLEAR_DIRECT_LINKED_IDS}}},selectors:{directLinkedAnnotationId:function(e){return e.directLinkedAnnotationId},directLinkedGroupFetchFailed:function(e){return e.directLinkedGroupFetchFailed
635
+ },directLinkedGroupId:function(e){return e.directLinkedGroupId}}});class sg{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 lg={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}},cg=Zm(lg);function ug(e){return{type:cg.REMOVE_DRAFT,annotation:e}}function hg(e,t){const n=e;for(let e=0;e<n.length;e++){const r=n[e];if(r.match(t))return r}return null}function dg(e,t){const n=hg(e,t);return n?n.isEmpty()?null:n:null}const pg=Hf((e=>e),(e=>e.filter((e=>!e.annotation.id)).map((e=>e.annotation)))),mg=zf([],{namespace:"drafts",reducers:lg,actionCreators:{createDraft:function(e,t){return{type:cg.UPDATE_DRAFT,
636
+ draft:new sg(e,t)}},deleteNewAndEmptyDrafts:function(){return(e,t)=>{const n=t().drafts.filter((e=>Si(e.annotation)&&!dg(t().drafts,e.annotation))).map((t=>(e(ug(t.annotation)),t.annotation)));e(Jf(n))}},discardAllDrafts:function(){return{type:cg.DISCARD_ALL_DRAFTS}},removeDraft:ug},selectors:{countDrafts:function(e){return e.length},getDraft:hg,getDraftIfNotEmpty:dg,unsavedAnnotations:pg}});function fg(e){var t,n;return!!(null!==(t=e.user)&&void 0!==t&&t.username||null!==(n=e.user)&&void 0!==n&&n.userid)}function gg(e){if(!fg(e))return{};const t=e.user.username||e.user.userid||"";return{user:{value:t,display:e.user.displayName||t}}}const vg={CHANGE_FOCUS_MODE_USER:function(e,t){return{focusActive:fg({user:t.user}),focusFilters:gg({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}},
637
+ 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}}},yg=Zm(vg);const _g=Hf((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)||""}})),bg=Hf((e=>e.filters),(e=>e.focusActive),(e=>e.focusFilters),((e,t,n)=>t?{...n,...e}:{...e}));const wg=Hf((e=>bg(e)),(e=>{const t={};return Object.keys(e).forEach((n=>t[n]=e[n].value)),t}));const xg=zf((function(e){const t=e.focus||{};return{filters:{},focusActive:fg(t),focusFilters:gg(t),query:e.query||null}}),{namespace:"filters",reducers:vg,actionCreators:{changeFocusModeUser:function(e){return{type:yg.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:yg.SET_FOCUS_MODE,active:!1}),n({type:yg.SET_FILTER,filterName:e,filterOption:t})}},
638
+ setFilterQuery:function(e){return{type:yg.SET_FILTER_QUERY,query:e}},toggleFocusMode:function(e){return{type:yg.SET_FOCUS_MODE,active:e}}},selectors:{filterQuery:function(e){return e.query},focusState:_g,getFilter:function(e,t){return bg(e)[t]},getFilters:bg,getFilterValues:wg,getFocusFilters:function(e){return e.focusFilters},hasAppliedFilter:function(e){return!(!e.query&&!Object.keys(bg(e)).length)}}}),kg={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))}},Sg=Zm(kg);const Cg=Hf((e=>e),(e=>e.find((e=>!e.id))||null));const Ag=jf(Bf,Um)((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
639
+ }(t))),[])),(e=>e)),Eg=zf([],{namespace:"frames",reducers:kg,actionCreators:{connectFrame:function(e){return{type:Sg.CONNECT_FRAME,frame:e}},destroyFrame:function(e){return{type:Sg.DESTROY_FRAME,frame:e}},updateFrameAnnotationFetchStatus:function(e,t){return{type:Sg.UPDATE_FRAME_ANNOTATION_FETCH_STATUS,isAnnotationFetchComplete:t,uri:e}}},selectors:{frames:function(e){return e},mainFrame:Cg,searchUris:Ag}}),Tg={features:{},preferences:{},userid:null};const Ng={UPDATE_PROFILE:function(e,t){return{profile:{...t.profile}}}},Lg=Zm(Ng);const Mg=zf((function(e){var t;return{defaultAuthority:null!==(t=null==e?void 0:e.authDomain)&&void 0!==t?t:"",profile:Tg}}),{namespace:"session",reducers:Ng,actionCreators:{updateProfile:function(e){return{type:Lg.UPDATE_PROFILE,profile:e}}},selectors:{defaultAuthority:function(e){return e.defaultAuthority},hasFetchedProfile:function(e){return e.profile!==Tg},isFeatureEnabled:function(e,t){return!!e.profile.features[t]},isLoggedIn:function(e){return null!==e.profile.userid},
640
+ profile:function(e){return e.profile}}}),zg={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;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:[]})},Og=Zm(zg);function Ig(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 Rg(e,t){
641
+ return e.groups.find((e=>e.id===t))}const Pg=Hf((e=>Ig(e)),(e=>e.filter((e=>!e.isMember&&e.isScopedToUri)))),Dg=Hf((e=>Ig(e)),(e=>e.filter((e=>e.isScopedToUri)))),Bg=Hf((e=>Ig(e.groups)),(e=>Mg.selectors.isLoggedIn(e.session)),((e,t)=>t?e.filter((e=>e.isMember)):[])),Fg=Hf((e=>Ig(e.groups)),(e=>Bg(e)),(e=>Pg(e.groups)),((e,t,n)=>e.filter((e=>!t.includes(e)&&!n.includes(e))))),jg=zf({filteredGroupIds:null,groups:[],focusedGroupId:null},{namespace:"groups",reducers:zg,actionCreators:{filterGroups:function(e){return{type:Og.FILTER_GROUPS,filteredGroupIds:e}},focusGroup:function(e){return{type:Og.FOCUS_GROUP,id:e}},loadGroups:function(e){return{type:Og.LOAD_GROUPS,groups:e}},clearGroups:function(){return{type:Og.CLEAR_GROUPS}}},selectors:{allGroups:function(e){return e.groups},filteredGroups:Ig,filteredGroupIds:function(e){return e.filteredGroupIds},focusedGroup:function(e){return e.focusedGroupId?Rg(e,e.focusedGroupId):null},focusedGroupId:function(e){return e.focusedGroupId},getFeaturedGroups:Pg,getGroup:Rg,
642
+ getInScopeGroups:Dg},rootSelectors:{getCurrentlyViewingGroups:Fg,getMyGroups:Bg}}),Hg={UPDATE_LINKS:(e,t)=>({...t.links})},Ug=Zm(Hg);const qg=zf(null,{namespace:"links",reducers:Hg,actionCreators:{updateLinks:function(e){return{type:Ug.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}=Tm(r,n),a=Object.keys(i);if(a.length>0)throw new Error(`Unused parameters: ${a.join(", ")}`);return o}}}),$g={RECEIVE_REAL_TIME_UPDATES:(e,t)=>({pendingUpdates:{...t.pendingUpdates},pendingDeletions:{...t.pendingDeletions}}),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}},
643
+ FOCUS_GROUP:()=>({pendingUpdates:{},pendingDeletions:{}})},Gg=Zm($g);const Vg=Hf((e=>[e.pendingUpdates,e.pendingDeletions]),(([e,t])=>Object.keys(e).length+Object.keys(t).length));const Wg=zf({pendingUpdates:{},pendingDeletions:{}},{namespace:"realTimeUpdates",reducers:$g,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!==jg.selectors.focusedGroupId(t)&&"sidebar"===Wf.selectors.route(n)||(o[e.id]=e)})),t.forEach((e=>{const t=e.id;delete o[t];const n=r().annotations;eg.selectors.annotationExists(n,t)&&(i[t]=!0)})),n({type:Gg.RECEIVE_REAL_TIME_UPDATES,pendingUpdates:o,pendingDeletions:i})}},clearPendingUpdates:function(){return{type:Gg.CLEAR_PENDING_UPDATES}}},selectors:{hasPendingDeletion:function(e,t){return e.pendingDeletions.hasOwnProperty(t)},pendingDeletions:function(e){return e.pendingDeletions},
644
+ pendingUpdates:function(e){return e.pendingUpdates},pendingUpdateCount:Vg}}),Yg={annotation:"Location",note:"Oldest",orphan:"Location"};function Kg(e){const t={};return e.annotations&&!e.query&&(t[e.annotations]=!0),t}const Xg=(e,t)=>t===e?{}:{selectedTab:e,sortKey:Yg[e]},Zg={CLEAR_SELECTION:function(){return{forcedVisible:{},selected:{}}},SELECT_ANNOTATIONS:function(e,t){return{selected:t.selection}},SELECT_TAB:function(e,t){return Xg(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,[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=>!ki(e))),r=Uf(t.annotations,Mi)===n.length;return 0===t.currentAnnotationCount&&r?Xg("note",e.selectedTab):{}},CHANGE_FOCUS_MODE_USER:function(){
645
+ 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===Uf(t.remainingAnnotations,Li)&&(n="annotation");const r=e=>(t.annotationsToRemove.forEach((t=>{t.id&&delete e[t.id],t.$tag&&delete e[t.$tag]})),e);return{...Xg(n,e.selectedTab),expanded:r({...e.expanded}),forcedVisible:r({...e.forcedVisible}),selected:r({...e.selected})}}},Jg=Zm(Zg);function Qg(e){return e.expanded}const ev=Hf((e=>e.forcedVisible),(e=>$f(e))),tv=Hf((e=>e.selected),(e=>$f(e).length>0)),nv=Hf((e=>e.selected),(e=>$f(e)));function rv(e){return e.selectedTab}const ov=Hf((e=>e),(e=>({expanded:Qg(e),forcedVisible:ev(e),selected:nv(e),sortKey:iv(e),selectedTab:rv(e)})));function iv(e){return e.sortKey}const av=Hf((e=>e.selectedTab),(e=>{const t=["Newest","Oldest"]
646
+ ;return"note"!==e&&t.push("Location"),t})),sv=zf((function(e){return{selected:Kg(e),expanded:Kg(e)||{},forcedVisible:{},selectedTab:"annotation",sortKey:Yg.annotation}}),{namespace:"selection",reducers:Zg,actionCreators:{clearSelection:function(){return{type:Jg.CLEAR_SELECTION}},selectAnnotations:function(e){return t=>{t({type:Jg.CLEAR_SELECTION}),t({type:Jg.SELECT_ANNOTATIONS,selection:qf(e)})}},selectTab:function(e){return{type:Jg.SELECT_TAB,tab:e}},setExpanded:function(e,t){return{type:Jg.SET_EXPANDED,id:e,expanded:t}},setForcedVisible:function(e,t){return{type:Jg.SET_FORCED_VISIBLE,id:e,visible:t}},setSortKey:function(e){return{type:Jg.SET_SORT_KEY,key:e}},toggleSelectedAnnotations:function(e){return{type:Jg.TOGGLE_SELECTED_ANNOTATIONS,toggleIds:e}}},selectors:{expandedMap:Qg,forcedVisibleThreads:ev,hasSelectedAnnotations:tv,selectedAnnotations:nv,selectedTab:rv,selectionState:ov,sortKey:iv,sortKeys:av}}),lv={OPEN_SIDEBAR_PANEL:function(e,t){return{activePanelName:t.panelName}},
647
+ 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}}},cv=Zm(lv);const uv=zf({activePanelName:null},{namespace:"sidebarPanels",reducers:lv,actionCreators:{openSidebarPanel:function(e){return{type:cv.OPEN_SIDEBAR_PANEL,panelName:e}},closeSidebarPanel:function(e){return{type:cv.CLOSE_SIDEBAR_PANEL,panelName:e}},toggleSidebarPanel:function(e,t){return{type:cv.TOGGLE_SIDEBAR_PANEL,panelName:e,panelState:t}}},selectors:{isSidebarPanelOpen:function(e,t){return e.activePanelName===t}}}),hv={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))}}},dv=Zm(hv)
648
+ ;const pv=zf({messages:[]},{namespace:"toastMessages",reducers:hv,actionCreators:{addToastMessage:function(e){return{type:dv.ADD_MESSAGE,message:e}},removeToastMessage:function(e){return{type:dv.REMOVE_MESSAGE,id:e}},updateToastMessage:function(e){return{type:dv.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))}}}),mv={SET_SIDEBAR_OPENED:(e,t)=>!0===t.opened?{sidebarHasOpened:!0}:{}},fv=Zm(mv);const gv=zf({sidebarHasOpened:!1},{namespace:"viewer",reducers:mv,actionCreators:{setSidebarOpened:function(e){return{type:fv.SET_SIDEBAR_OPENED,opened:e}}},selectors:{hasSidebarOpened:function(e){return e.sidebarHasOpened}}});function vv(e){return Mf([Pf,eg,rg,ag,mg,xg,Eg,qg,jg,Wg,Wf,sv,Mg,uv,pv,gv],[e],[Of])}vv.$inject=["settings"];class yv{constructor(){this._providers=new Map,this._instances=new Map,this._constructing=new Set}
649
+ 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)}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,{
650
+ factory:e});try{return this.get(t)}finally{this._instances.delete(t),this._providers.delete(t)}}}const _v=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),bv=function(e){const{version:t,origin:n}=R(e.location.href);return"1.977.0"!==t?(console.warn(`The Hypothesis sidebar is using a different version (1.977.0) than the host page (${t}). It may not work.`),!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 wv(e,t){e.setClientId(t.clientId)}function xv(e,t,n){e.load(),t.load(),n.sync()}function kv(e,t,n,r){e.init(),t.init(),n.init(),r.init()}function Sv(e,t){
651
+ "sidebar"===t.route()&&e.connect()}_v.sentry&&bv&&function(e){const t=function(){let e=import.meta.url;return e?new URL(e).origin:null}(),n=t?[t]:void 0;wr({dsn:e.dsn,environment:e.environment,allowUrls:n,ignoreErrors:["Network request failed","Object Not Found Matching Id"],release:"1.977.0",beforeSend:(e,t)=>{if(Sr>=5)return K("Client-side Sentry quota reached. No further Sentry events will be sent"),null;++Sr;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{Yt("host_config",R(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>"))),kr(((e,t)=>{Wt(e,{tags:{context:t}})}))}(_v.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{
652
+ document.createElement("div").dir="auto"}catch(e){t=!0}if(t){const t=e.vnode;e.vnode=e=>{"string"==typeof e.type&&"dir"in e.props&&"auto"===e.props.dir&&(e.props.dir=""),t&&t(e)}}}(),wv.$inject=["api","streamer"],xv.$inject=["groups","session","router"],kv.$inject=["autosaveService","features","persistedDefaults","serviceURL"],Sv.$inject=["frameSync","store"],function(e,{reset:t=!1}={}){t&&mo.clear();for(let[t,n]of Object.entries(e))mo.set(t,n)}(Ko);const Cv=document.querySelector("hypothesis-app");!function(e=window){e.addEventListener("message",te)}(),async function(e,t=window){const n=H(window),r=n.requestConfigFromFrame;if(!r)return V(e,n);if("string"==typeof r)return await G(e,t);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
653
+ }(r.ancestorLevel,t);return{...await W(e,o,r.origin),...n.group?{group:n.group}:{}}}throw new Error("Improper `requestConfigFromFrame` object. Both `ancestorLevel` and `origin` need to be specified")}(_v).then((e=>{!function(e,t){const n=new yv;n.register("annotationsService",Cm).register("api",Lm).register("apiRoutes",Dm).register("auth",jm).register("autosaveService",Hm).register("features",$m).register("frameSync",Xm).register("groups",ef).register("loadAnnotationsService",tf).register("localStorage",rf).register("persistedDefaults",af).register("router",sf).register("serviceURL",lf).register("session",cf).register("streamer",df).register("streamFilter",uf).register("tags",pf).register("threadsService",mf).register("toastMessenger",ff).register("store",{factory:vv}),n.register("$window",{value:window}).register("settings",{value:e}),n.run(kv),n.run(wv),n.run(xv),n.run(ee),n.run(Sv),I(po(ni.Provider,{value:n,children:po(km,{})}),t)}(e,Cv)})).catch((e=>function(e,t){
654
+ console.error("Failed to start Hypothesis client: ",e),I(po(Sm,{error:e}),t)}(e,Cv)));
654
655
  //# sourceMappingURL=sidebar.bundle.js.map