hypothesis 1.962.0 → 1.963.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.
@@ -564,7 +564,7 @@ t.addEventListener("touchstart",i,c),t.addEventListener("wheel",i,c)),a&&Qd(t),i
564
564
  },s=t>0?`${o} (${t} available)`:o;return Rr(Ur,{classes:hr("u-color-text","SelectionTab",{"is-selected":r}),onClick:a,onMouseDown:a,pressed:!!r,role:"tab",tabIndex:0,title:s,children:Rr(m,{children:[e,t>0&&!n&&Rr("span",{className:"u-font--xsmall",style:"position:relative;bottom:3px;left:2px",children:t})]})})}var lp=Eo((function({annotationsService:e,isLoading:t,settings:n}){const r=To(),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 Rr("div",{className:"hyp-u-vertical-spacing--4 SelectionTabs__container",children:[Rr("div",{className:"hyp-u-layout-row hyp-u-horizontal-spacing--6 SelectionTabs",role:"tablist",children:[Rr(sp,{count:a,isWaitingToAnchor:l,isSelected:"annotation"===o,label:"Annotations",onSelect:()=>c("annotation"),children:"Annotations"}),Rr(sp,{count:i,isWaitingToAnchor:l,isSelected:"note"===o,label:"Page notes",onSelect:()=>c("note"),
565
565
  children:"Page Notes"}),s>0&&Rr(sp,{count:s,isWaitingToAnchor:l,isSelected:"orphan"===o,label:"Orphans",onSelect:()=>c("orphan"),children:"Orphans"})]}),"note"===o&&n.enableExperimentalNewNoteButton&&Rr("div",{className:"hyp-u-layout-row--justify-right",children:Rr(Ur,{"data-testid":"new-note-button",icon:"add",onClick:()=>e.createPageNote(),variant:"primary",style:So(["ctaBackgroundColor"],n),children:"New note"})}),!t&&h&&Rr(Gr,{classes:"u-text--centered",children:Rr("span",{"data-testid":"notes-unavailable-message",children:"There are no page notes in this group."})}),!t&&u&&Rr(Gr,{classes:"u-text--centered",children:Rr("span",{"data-testid":"annotations-unavailable-message",children:["There are no annotations in this group.",Rr("br",{}),"Create one by selecting some text and clicking the"," ",Rr(Qr,{classes:"hyp-u-margin--1 u-inline",name:"annotate",title:"Annotate"})," ","button."]})})]})}),["annotationsService","settings"])
566
566
  ;var cp=Eo((function({frameSync:e,onLogin:t,onSignUp:n,loadAnnotationsService:r,streamer:o}){const i=yi(),a=To(),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?ci(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=Sr(s);xr((()=>{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]),xr((()=>{v?(e.focusAnnotations([v]),e.scrollToAnnotation(v),a.selectTab(p)):d&&a.selectTab(p)}),[p,e,d,v,a]);const C=a.hasFetchedProfile();return xr((()=>{C&&(f||u)&&o.connect({applyUpdatesImmediately:!1})}),[C,u,f,o]),Rr("div",{children:[Rr("h2",{className:"u-screen-reader-only",children:"Annotations"}),w&&Rr(Xd,{}),Rr(ap,{onLogin:t,
567
- onSignUp:n}),y&&Rr($d,{errorType:"annotation",onLoginRequest:t,showClearSelection:!0}),_&&Rr($d,{errorType:"group",onLoginRequest:t}),x&&Rr(lp,{isLoading:c}),Rr(qd,{threads:i.children}),k&&Rr(Zd,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var up=Eo((function({api:e,toastMessenger:t}){const n=To(),r=n.routeParams().q,o=Er((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...Ho(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return xr((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),Rr(qd,{threads:yi().children})}),["api","toastMessenger"]);class hp{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.962.0",this.userAgent=n.navigator.userAgent,this.urls=t.map((e=>e.uri)).join(", ")||a,
567
+ onSignUp:n}),y&&Rr($d,{errorType:"annotation",onLoginRequest:t,showClearSelection:!0}),_&&Rr($d,{errorType:"group",onLoginRequest:t}),x&&Rr(lp,{isLoading:c}),Rr(qd,{threads:i.children}),k&&Rr(Zd,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var up=Eo((function({api:e,toastMessenger:t}){const n=To(),r=n.routeParams().q,o=Er((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...Ho(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return xr((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),Rr(qd,{threads:yi().children})}),["api","toastMessenger"]);class hp{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.963.0",this.userAgent=n.navigator.userAgent,this.urls=t.map((e=>e.uri)).join(", ")||a,
568
568
  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 dp(e){const t=P(e);return!(null==t||!t.authority)&&t.authority!==e.authDomain}function pp({commandName:e,iconName:t}){return Rr("span",{className:"Tutorial__instruction",children:[Rr(Qr,{name:t,classes:"hyp-u-margin--right--1 hyp-u-color--grey-6 u-inline Tutorial__icon"}),Rr("em",{children:e})]})}var mp=Eo((function({settings:e}){const t=!dp(e);return Rr("ol",{className:"Tutorial__list",children:[Rr("li",{className:"Tutorial__item",children:["To create an annotation, select text and then select the"," ",Rr(pp,{iconName:"annotate",commandName:"Annotate"
569
569
  })," ","button."]}),Rr("li",{className:"Tutorial__item",children:["To create a highlight (",Rr("a",{href:"https://web.hypothes.is/help/why-are-highlights-private-by-default/",target:"_blank",rel:"noopener noreferrer",children:"visible only to you"}),"), select text and then select the"," ",Rr(pp,{iconName:"highlight",commandName:"Highlight"})," ","button."]}),t&&Rr("li",{className:"Tutorial__item",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"," ",Rr("a",{href:"https://web.hypothes.is/help/how-to-join-a-private-group/",target:"_blank",rel:"noopener noreferrer",children:"join link"}),")."]}),Rr("li",{className:"Tutorial__item",children:["To reply to an annotation, select the"," ",Rr(pp,{iconName:"reply",commandName:"Reply"})," button."]})]})}),["settings"]);var fp=Eo((function({toastMessenger:e,versionData:t}){return Rr("div",{className:"hyp-u-vertical-spacing",children:[Rr("dl",{className:"VersionInfo",
570
570
  children:[Rr("dt",{className:"VersionInfo__key",children:"Version"}),Rr("dd",{className:"VersionInfo__value",children:t.version}),Rr("dt",{className:"VersionInfo__key",children:"User Agent"}),Rr("dd",{className:"VersionInfo__value",children:t.userAgent}),Rr("dt",{className:"VersionInfo__key",children:"URL"}),Rr("dd",{className:"VersionInfo__value",children:t.urls}),Rr("dt",{className:"VersionInfo__key",children:"Fingerprint"}),Rr("dd",{className:"VersionInfo__value",children:t.fingerprint}),Rr("dt",{className:"VersionInfo__key",children:"Account"}),Rr("dd",{className:"VersionInfo__value",children:t.account}),Rr("dt",{className:"VersionInfo__key",children:"Date"}),Rr("dd",{className:"VersionInfo__value",children:t.timestamp})]}),Rr("div",{className:"hyp-u-layout-row--justify-center",children:Rr(Ur,{onClick:()=>{try{qi(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"])
@@ -592,7 +592,7 @@ await e.login(),i.closeSidebarPanel("loginPrompt"),i.clearGroups(),r.reload()}ca
592
592
  children:["annotation"===l&&Rr(Gd,{onLogin:p}),"notebook"===l&&Rr(Np,{}),"stream"===l&&Rr(up,{}),"sidebar"===l&&Rr(cp,{onLogin:p,onSignUp:m})]})]})]})}),["auth","frameSync","session","settings","toastMessenger"]);function Vp({error:e}){return Rr("div",{className:"LaunchErrorPanel",children:Rr(co,{title:"Unable to start Hypothesis",children:e.message})})}class Wp{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?Bi(e.user):Fi(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:ji(i,r,n),tags:[],text:"",updated:t.toISOString(),user:i,user_info:a,$tag:s,hidden:!1,links:{},document:{title:""}},e)
593
593
  ;return Jo(l)&&(l.permissions=Bi(i)),l}create(e,t=new Date){const n=this._initialize(e,t);this._store.addAnnotations([n]),this._store.deleteNewAndEmptyDrafts(),Jo(n)||this._store.createDraft(n,{tags:n.tags,text:n.text,isPrivate:!Yo(n)}),ei(n)?this._store.selectTab("note"):ti(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:Yo(e)?Fi(t,e.group):Bi(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
594
594
  ;t=Wo(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])})),this._store.removeDraft(e),this._store.addAnnotations([r]),r}}Wp.$inject=["api","store"];class Yp 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 Kp(e,t){let n,r;try{n=await fetch(e,t)}catch(t){throw new Yp(e,null,t.message)}if(204===n.status)return null;try{r=await n.json()}catch(t){throw new Yp(e,n,"Failed to parse response")}var o;if(!n.ok)throw new Yp(e,n,null===(o=r)||void 0===o?void 0:o.reason);return r}function Xp(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 Zp(e){const t={}
595
- ;for(const n in e)e.hasOwnProperty(n)&&"$"!==n[0]&&(t[n]=e[n]);return t}class Jp{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}){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.962.0"};l&&(u.Authorization="Bearer "+l);const h=r();h&&(u["X-Client-Id"]=h);const{url:d,unusedParams:p}=Xp(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 Kp(m.toString(),{body:s?JSON.stringify(Zp(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={
595
+ ;for(const n in e)e.hasOwnProperty(n)&&"$"!==n[0]&&(t[n]=e[n]);return t}class Jp{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}){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.963.0"};l&&(u.Authorization="Bearer "+l);const h=r();h&&(u["X-Client-Id"]=h);const{url:d,unusedParams:p}=Xp(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 Kp(m.toString(),{body:s?JSON.stringify(Zp(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={
596
596
  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={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}}Jp.$inject=["apiRoutes","auth","store"];var Qp={};function em(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 tm=em;em.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},
597
597
  em.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},em.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime();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},em.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb))
598
598
  ;var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){n._operationTimeoutCb()}),n._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},em.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},em.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},em.prototype.start=em.prototype.try,em.prototype.errors=function(){return this._errors},em.prototype.attempts=function(){return this._attempts},em.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=tm;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,
@@ -602,63 +602,62 @@ await this._formPost(this.revokeEndpoint,{token:e})}catch(e){throw new am("Faile
602
602
  }catch(e){throw new am("Failed to fetch access token",e)}return{accessToken:t.access_token,expiresAt:Date.now()+1e3*(t.expires_in-10),refreshToken:t.refresh_token}}static openAuthPopupWindow(e){const t=`left=${e.screen.width/2-237.5},top=${e.screen.height/2-215},width=475,height=430`,n=e.open("about:blank","Log in to Hypothesis",t);if(!n)throw new Error("Failed to open login window");return n}}class lm extends bp{constructor(e,t,n,r,o){let i,a,s;super();const l=(c="token",u=r.apiUrl,new URL(c,u).href);var c,u;function h(){let e=new URL(r.apiUrl).hostname;return e=e.replace(/\./g,"%2E"),`hypothesis.oauth.${e}.token`}function d(e){n.setObject(h(),e)}const p=async()=>{if(s)return s;const e=await t.links();return s=new sm({clientId:r.oauthClientId,authorizationEndpoint:e["oauth.authorize"],revokeEndpoint:e["oauth.revoke"],tokenEndpoint:l}),s},m=()=>{var e;return null===(e=P(r))||void 0===e?void 0:e.grantToken},f=async()=>{if(!a){const e=m();void 0!==e?a=e?p().then((t=>t.exchangeGrantToken(e))).catch((e=>{var t
603
603
  ;throw t="You must reload the page to annotate.",o.error(`Hypothesis login lost: ${t}`,{autoDismiss:!1}),e})):Promise.resolve(null):i?(a=(async e=>{const t=await p(),n=await t.exchangeAuthCode(e);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(){
604
604
  const t=sm.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}}lm.$inject=["$window","apiRoutes","localStorage","settings","toastMessenger"];class cm{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}}cm.$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)
605
- ;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 hm(e,t,n){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 dm{constructor(e,t){this._frameSync=e,this._store=t}init(){const e=()=>this._store.profile().features;hm(this._store.subscribe,[e,()=>this._store.frames()],(()=>{this._frameSync.notifyHost("featureFlagsUpdated",e()||{})}))}}dm.$inject=["frameSync","store"];class pm{constructor(e,t){this._port=e,this._methods=t,this._sequence=0,this._callbacks={},this._destroyed=!1,this._listeners=new Ii,this._listeners.add(this._port,"message",(e=>this._handle(e))),this._port.start()}destroy(){this._destroyed=!0,this._listeners.removeAll(),this._port.close()}call(e,...t){if(this._destroyed)return;const n=this._sequence++,r=t[t.length-1]
606
- ;"function"==typeof r&&(this._callbacks[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);if(null!==t)if("method"in t){if(!this._methods.hasOwnProperty(t.method))return;const e=(...e)=>{const n={arguments:e,protocol:"frame-rpc",response:t.sequence,version:"1.0.0"};this._port.postMessage(n)};this._methods[t.method](...t.arguments,e)}else if("response"in t){const e=this._callbacks[t.response];delete this._callbacks[t.response],e&&e(...t.arguments)}}}class mm{constructor(){this.links=[],this.channelListeners={}}destroy(){this.links.forEach((e=>e.destroy())),this.links=[]}createChannel(e){const t=new pm(e,this.channelListeners);return this.links.push(t),t}call(e,...t){let n;const r=t[t.length-1];"function"==typeof r&&(n=r,t=t.slice(0,-1));const o=e=>t=>{
607
- throw e.destroy(),this.links=this.links.filter((t=>t!==e)),t},i=this.links.map((n=>{const r=new Promise(((r,o)=>{const i=setTimeout((()=>r(null)),1e3);try{n.call(e,...t,((e,t)=>{clearTimeout(i),e?o(e):r(t)}))}catch(e){o(e)}}));return r.catch(o(n))}));let a=Promise.all(i);return n&&(a=a.then((e=>n(null,e))).catch((e=>n(e)))),a}on(e,t){if(this.links.length>0)throw new Error(`Listener '${e}' can't be registered because a channel has already been created`);if(this.channelListeners[e])throw new Error(`Listener '${e}' already bound in Bridge`);return this.channelListeners[e]=t,this}}function fm(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())}class gm{constructor({hostFrame:e,source:t}){this._hostFrame=e,this._source=t,this._listeners=new Ii}destroy(){this._listeners.removeAll()}async discover(e){let t=!1
608
- ;if(("guest"===this._source&&"host"===e||"guest"===this._source&&"sidebar"===e||"sidebar"===this._source&&"host"===e||"notebook"===this._source&&"sidebar"===e)&&(t=!0),!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;fm(r,{frame1:this._source,frame2:e,type:"offer"})&&(clearInterval(o),clearTimeout(i),this._listeners.remove(a),t(s[0]))}));r()}))}}function vm({$tag:e,target:t,uri:n}){return{$tag:e,target:t,uri:n}}class ym{constructor(e,t,n){this._window=e,this._annotationsService=t,this._store=n,this._portFinder=new gm({hostFrame:this._window.parent,source:"sidebar"}),this._listeners=new Ii,this._hostRPC=new mm,this._guestRPC=new mm,this._inFrame=new Set,
609
- this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupSyncFromGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0;hm(this._store.subscribe,[()=>this._store.allAnnotations(),()=>this._store.frames()],(([t,n],[r])=>{let o=0;const i=new Set,a=[];t.forEach((e=>{Vo(e)||(Yo(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.call("loadAnnotations",a.map(vm)),a.forEach((e=>{this._inFrame.add(e.$tag)}))),s.forEach((e=>{this._guestRPC.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))}))}_setupSyncFromGuests(){this._guestRPC.on("createAnnotation",(e=>{if(!this._store.isLoggedIn())return this._hostRPC.call("openSidebar"),this._store.openSidebarPanel("loginPrompt"),void this._guestRPC.call("deleteAnnotation",e.$tag);this._inFrame.add(e.$tag),
610
- e.$highlight||this._hostRPC.call("openSidebar"),this._hostRPC.call("showHighlights"),this._annotationsService.create(e)}));let e={};const t=zi((()=>{this._store.updateAnchorStatus(e),e={}}),10);this._guestRPC.on("syncAnchoringStatus",(({$tag:n,$orphan:r})=>{this._inFrame.add(n),e[n]=r?"orphan":"anchored",t()})),this._guestRPC.on("showAnnotations",(e=>{this._store.selectAnnotations(this._store.findIDsForTags(e)),this._store.selectTab("annotation")})),this._guestRPC.on("focusAnnotations",(e=>{this._store.focusAnnotations(e||[])})),this._guestRPC.on("toggleAnnotationSelection",(e=>{this._store.toggleSelectedAnnotations(this._store.findIDsForTags(e))})),this._guestRPC.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")})),this._guestRPC.on("closeSidebar",(()=>{this._hostRPC.call("closeSidebar")}))}_addGuestFrame(e){e.call("setHighlightsVisible",this._highlightsVisible),e.call("getDocumentInfo",((t,n)=>{t?e.destroy():this._store.connectFrame({id:n.frameIdentifier,metadata:n.metadata,uri:n.uri})}))}
611
- _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.call("setHighlightsVisible",e)}))}async connect(){const e=await this._portFinder.discover("host");this._hostRPC.createChannel(e),this._hostRPC.call("ready"),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;if(fm(t,{frame1:"guest",frame2:"sidebar",type:"offer"})){const e=this._guestRPC.createChannel(n[0]);this._addGuestFrame(e)}}))}notifyHost(e,...t){this._hostRPC.call(e,...t)}focusAnnotations(e){this._store.focusAnnotations(e),this._guestRPC.call("focusAnnotations",e)}scrollToAnnotation(e){this._guestRPC.call("scrollToAnnotation",e)}destroy(){this._portFinder.destroy(),this._listeners.removeAll()}}function _m(e){return Object.keys(e).reduce(((e,t)=>(e[t]=t,e)),{})}
612
- ym.$inject=["$window","annotationsService","store"];const bm={id:"__default__",name:"__DEFAULT__",logo:"data:image/svg+xml;utf8,"+encodeURIComponent(vo)};const wm=["organization","scopes"];class xm{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,hm(this._store.subscribe,(()=>this._mainURI()),(()=>{this.load()})),
613
- hm(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=bm)}))}(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:wm})}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
614
- ;i&&(a=this._fetchGroup(i).then((e=>(this._store.clearDirectLinkedGroupFetchFailed(),e))).catch((()=>(this._store.setDirectLinkedGroupFetchFailed(),null))));const s={expand:wm},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:wm}),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:wm});let n;const r=async e=>{try{return await this._fetchGroup(e)}catch(e){return n=e,null}
615
- },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=>!Vo(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"})}}xm.$inject=["store","api","auth","session","settings","toastMessenger"];class km{
616
- 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 kp(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)})),
617
- 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}),Vo(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),!Vo(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}}km.$inject=["api","store","streamer","streamFilter"];class Sm{constructor(){this._store={}}getItem(e){return e in this._store?this._store[e]:null}
618
- setItem(e,t){this._store[e]=t}removeItem(e){delete this._store[e]}}class Cm{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 Sm}}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)}}Cm.$inject=["$window"];const Em={annotationPrivacy:"hypothesis.privacy",focusedGroup:"hypothesis.groups.focus"};class Am{constructor(e,t){this._storage=e,this._store=t}init(){Object.keys(Em).forEach((e=>{const t=this._storage.getItem(Em[e]);this._store.setDefault(e,t)})),hm(this._store.subscribe,(()=>this._store.getDefaults()),((e,t)=>{for(let n in e)t[n]!==e[n]&&n in Em&&this._storage.setItem(Em[n],e[n])}))}}Am.$inject=["localStorage","store"];class Tm{constructor(e,t){this._window=e,
619
- 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){
620
- this._window.history.pushState({},"",this.routeUrl(e,t)),this.sync()}}Tm.$inject=["$window","store"];class Nm{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}`)}}}Nm.$inject=["apiRoutes","store"];class Lm{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(){
621
- 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?Yn({id:e.userid}):Yn(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()}}Lm.$inject=["store","api","auth","settings","toastMessenger"];class Mm{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 Om extends bp{constructor(e){super();const t=[];let n
622
- ;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 zm{constructor(e,t,n,r,o){this._auth=t,this._groups=n,this._session=r,this._store=e,this._websocketURL=o.websocketUrl,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})))
623
- ;t.length&&this._store.removeAnnotations(t),this._store.clearPendingUpdates()}_handleSocketError(e){K("Error connecting to H push notification service:",e);const t=new URL(this._websocketURL).hostname;-1!==["localhost","127.0.0.1"].indexOf(t)&&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)}
624
- _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;if(!this._websocketURL)return;let t,n;null===(e=this._socket)||void 0===e||e.close();try{t=await this._auth.getAccessToken()}catch(e){throw console.error("Failed to fetch token for WebSocket authentication",e),e}if(t){const e=new URL(this._websocketURL);e.searchParams.set("access_token",t),n=e.toString()}else n=this._websocketURL;const r=new Om(n);r.on("open",(()=>{this._reconnectionAttempts=0,this._sendClientConfig(r)})),r.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")})),r.on("error",(e=>this._handleSocketError(e))),
625
- r.on("message",(e=>this._handleSocketMessage(e))),this._socket=r,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,hm(this._store.subscribe,(()=>this._store.profile().userid),(()=>{this._reconnect()}))),this._socket||await this._reconnect()}}zm.$inject=["store","auth","groups","session","settings"];class Im{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()}})),
626
- 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)}}Im.$inject=["localStorage"];class Rm{constructor(e){this._store=e}forceVisible(e){e.children.forEach((e=>{this.forceVisible(e)})),e.visible||this._store.setForcedVisible(e.id,!0)}}Rm.$inject=["store"];class Pm{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)}}
627
- function Dm(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Bm(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 Fm(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Bm(Object(n),!0).forEach((function(t){Dm(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Bm(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function jm(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. "}Pm.$inject=["store"];var Hm="function"==typeof Symbol&&Symbol.observable||"@@observable",Um=function(){
628
- return Math.random().toString(36).substring(7).split("").join(".")},qm={INIT:"@@redux/INIT"+Um(),REPLACE:"@@redux/REPLACE"+Um(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Um()}};function $m(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 Gm(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(jm(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(jm(1));return n(Gm)(e,t)}if("function"!=typeof e)throw new Error(jm(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(jm(3));return i}function h(e){if("function"!=typeof e)throw new Error(jm(4));if(l)throw new Error(jm(5));var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error(jm(6));t=!1,c();var n=s.indexOf(e);s.splice(n,1),a=null}}}
629
- function d(e){if(!$m(e))throw new Error(jm(7));if(void 0===e.type)throw new Error(jm(8));if(l)throw new Error(jm(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(jm(10));o=e,d({type:qm.REPLACE})}function m(){var e,t=h;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(jm(11));function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[Hm]=function(){return this},e}return d({type:qm.INIT}),(r={dispatch:d,subscribe:h,getState:u,replaceReducer:p})[Hm]=m,r}function Vm(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:qm.INIT}))throw new Error(jm(12));if(void 0===n(void 0,{type:qm.PROBE_UNKNOWN_ACTION()}))throw new Error(jm(13))}))}(n)}catch(e){i=e}return function(e,t){if(void 0===e&&(e={}),i)throw i
630
- ;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(jm(14));o[l]=h,r=r||h!==u}return(r=r||a.length!==Object.keys(e).length)?o:e}}function Wm(e,t){return function(){return t(e.apply(this,arguments))}}function Ym(){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 Km(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 Xm=Km();Xm.withExtraArgument=Km;var Zm=Xm;function Jm(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||{}
631
- }):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(jm(15))},o={getState:n.getState,dispatch:function(){return r.apply(void 0,arguments)}},i=t.map((function(e){return e(o)}));return r=Ym.apply(void 0,i)(n.dispatch),Fm(Fm({},n),{},{dispatch:r})}}}(...[Zm],...n);const s=Gm(Vm(o),r,a),l=Object.assign({},...e.map((e=>e.actionCreators))),c=function(e,t){if("function"==typeof e)return Wm(e,t);if("object"!=typeof e||null===e)throw new Error(jm(16));var n={};for(var r in e){var o=e[r];"function"==typeof o&&(n[r]=Wm(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=>{
632
- 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 Qm(e,t){if(!(e instanceof Function)){const t=e;e=()=>t}return{initialState:e,...t}}function ef(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 tf={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}},
633
- 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");return{...e,hasFetchedAnnotations:!0,activeAnnotationFetches:e.activeAnnotationFetches-1}},SET_ANNOTATION_RESULT_COUNT:(e,t)=>({annotationResultCount:t.resultCount})},nf=_m(tf);var rf=Qm({activeAnnotationSaveRequests:[],activeApiRequests:0,activeAnnotationFetches:0,hasFetchedAnnotations:!1,annotationResultCount:null},{reducers:tf,namespace:"activity",actionCreators:{annotationFetchStarted:function(){return{type:nf.ANNOTATION_FETCH_STARTED}},annotationFetchFinished:function(){return{type:nf.ANNOTATION_FETCH_FINISHED}},annotationSaveStarted:function(e){return{type:nf.ANNOTATION_SAVE_STARTED,annotation:e}},
634
- annotationSaveFinished:function(e){return{type:nf.ANNOTATION_SAVE_FINISHED,annotation:e}},apiRequestStarted:function(){return{type:nf.API_REQUEST_STARTED}},apiRequestFinished:function(){return{type:nf.API_REQUEST_FINISHED}},setAnnotationResultCount:function(e){return{type:nf.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 of=function(e,t){return e===t};function af(e,t){var n,r,o="object"==typeof t?t:{equalityCheck:t},i=o.equalityCheck,a=void 0===i?of: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
635
- ;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{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 sf(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){
636
- 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 lf(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=sf(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(){
637
- return a},resetRecomputations:function(){return a=0}}),f};return o}var cf=lf(af);function uf(e,t){return e.reduce(((e,n)=>t(n)?e+1:e),0)}function hf(e){const t={};return e.forEach((e=>t[e]=!0)),t}function df(e){return Object.keys(e).filter((t=>!0===e[t]))}const pf={CHANGE_ROUTE:(e,{name:t,params:n})=>({name:t,params:n})},mf=_m(pf);var ff=Qm({name:null,params:{}},{namespace:"route",reducers:pf,actionCreators:{changeRoute:function(e,t={}){return{type:mf.CHANGE_ROUTE,name:e,params:t}}},selectors:{route:function(e){return e.name},routeParams:function(e){return e.params}}});function gf(e,t){return e.find((e=>e.id===t))}function vf(e,t){return e.find((e=>e.$tag===t))}const yf={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=gf(e.annotations,t.id)),!i&&t.$tag&&(i=vf(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),
638
- 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:hf(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){
639
- 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}))}}},_f=_m(yf);function bf(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:_f.REMOVE_ANNOTATIONS,annotationsToRemove:e,remainingAnnotations:r})}}function wf(e){return{type:_f.UPDATE_ANCHOR_STATUS,statusUpdates:e}}const xf=cf((e=>e.annotations),(e=>uf(e,ti)));const kf=cf((e=>e.focused),(e=>df(e))),Sf=cf((e=>e.highlighted),(e=>df(e)))
640
- ;const Cf=cf((e=>e.annotations),(e=>e.some(Xo))),Ef=cf((e=>e.annotations),(e=>e.filter((e=>Wo(e)&&!Jo(e))))),Af=cf((e=>e.annotations),(e=>e.filter((e=>Wo(e)&&Jo(e))))),Tf=cf((e=>e.annotations),(e=>uf(e,ei))),Nf=cf((e=>e.annotations),(e=>uf(e,Qo)));var Lf=Qm({annotations:[],focused:{},highlighted:{},nextTag:1},{namespace:"annotations",reducers:yf,actionCreators:{addAnnotations:function(e){return function(t,n){const r=e.filter((e=>!gf(n().annotations.annotations,e.id)));if(t({type:_f.ADD_ANNOTATIONS,annotations:e,currentAnnotationCount:n().annotations.annotations.length}),"sidebar"!==ff.selectors.route(n().route))return;const o=r.filter(Xo).map((e=>e.id));o.length>0&&setTimeout((()=>{const e=n().annotations.annotations,r=o.map((t=>gf(e,t))).filter((e=>e&&Xo(e))).reduce(((e,t)=>(e[t.$tag]="timeout",e)),{});t(wf(r))}),500)}},clearAnnotations:function(){return{type:_f.CLEAR_ANNOTATIONS}},focusAnnotations:function(e){return{type:_f.FOCUS_ANNOTATIONS,focusedTags:e}},hideAnnotation:function(e){return{
641
- type:_f.HIDE_ANNOTATION,id:e}},highlightAnnotations:function(e){return{type:_f.HIGHLIGHT_ANNOTATIONS,highlighted:hf(e)}},removeAnnotations:bf,unhideAnnotation:function(e){return{type:_f.UNHIDE_ANNOTATION,id:e}},updateAnchorStatus:wf,updateFlagStatus:function(e,t){return{type:_f.UPDATE_FLAG_STATUS,id:e,isFlagged:t}}},selectors:{allAnnotations:function(e){return e.annotations},annotationCount:xf,annotationExists:function(e,t){return e.annotations.some((e=>e.id===t))},findAnnotationByID:function(e,t){return gf(e.annotations,t)},findIDsForTags:function(e,t){const n=[];return t.forEach((t=>{const r=vf(e.annotations,t);r&&r.id&&n.push(r.id)})),n},focusedAnnotations:kf,highlightedAnnotations:Sf,isAnnotationFocused:function(e,t){return!0===e.focused[t]},isWaitingToAnchorAnnotations:Cf,newAnnotations:Ef,newHighlights:Af,noteCount:Tf,orphanCount:Nf,savedAnnotations:function(e){return e.annotations.filter((e=>!Wo(e)))}}});const Mf={SET_DEFAULT:function(e,t){return{[t.defaultKey]:t.value}}},Of=_m(Mf);var zf=Qm({
642
- annotationPrivacy:null,focusedGroup:null},{namespace:"defaults",reducers:Mf,actionCreators:{setDefault:function(e,t){return{type:Of.SET_DEFAULT,defaultKey:e,value:t}}},selectors:{getDefault:function(e,t){return e[t]},getDefaults:function(e){return e}}});const If={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{directLinkedAnnotationId:null,directLinkedGroupId:null,directLinkedGroupFetchFailed:!1}}},Rf=_m(If);var Pf=Qm((function(e){return{directLinkedGroupId:e.group||null,directLinkedAnnotationId:e.annotations||null,directLinkedGroupFetchFailed:!1}}),{namespace:"directLinked",reducers:If,actionCreators:{setDirectLinkedGroupFetchFailed:function(){
643
- return{type:Rf.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!0}},setDirectLinkedGroupId:function(e){return{type:Rf.UPDATE_DIRECT_LINKED_GROUP_ID,directLinkedGroupId:e}},setDirectLinkedAnnotationId:function(e){return{type:Rf.UPDATE_DIRECT_LINKED_ANNOTATION_ID,directLinkedAnnotationId:e}},clearDirectLinkedGroupFetchFailed:function(){return{type:Rf.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!1}},clearDirectLinkedIds:function(){return{type:Rf.CLEAR_DIRECT_LINKED_IDS}}},selectors:{directLinkedAnnotationId:function(e){return e.directLinkedAnnotationId},directLinkedGroupFetchFailed:function(e){return e.directLinkedGroupFetchFailed},directLinkedGroupId:function(e){return e.directLinkedGroupId}}});class Df{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(){
644
- return!this.text&&0===this.tags.length}}const Bf={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}},Ff=_m(Bf);function jf(e){return{type:Ff.REMOVE_DRAFT,annotation:e}}function Hf(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 Uf(e,t){const n=Hf(e,t);return n?n.isEmpty()?null:n:null}const qf=cf((e=>e),(e=>e.filter((e=>!e.annotation.id)).map((e=>e.annotation))));var $f=Qm([],{namespace:"drafts",reducers:Bf,actionCreators:{createDraft:function(e,t){return{type:Ff.UPDATE_DRAFT,draft:new Df(e,t)}},deleteNewAndEmptyDrafts:function(){return(e,t)=>{const n=t().drafts.filter((e=>Wo(e.annotation)&&!Uf(t().drafts,e.annotation))).map((t=>(e(jf(t.annotation)),t.annotation)));e(bf(n))}},discardAllDrafts:function(){return{type:Ff.DISCARD_ALL_DRAFTS}},removeDraft:jf},selectors:{countDrafts:function(e){
645
- return e.length},getDraft:Hf,getDraftIfNotEmpty:Uf,unsavedAnnotations:qf}});function Gf(e){var t,n;return!!(null!==(t=e.user)&&void 0!==t&&t.username||null!==(n=e.user)&&void 0!==n&&n.userid)}function Vf(e){if(!Gf(e))return{};const t=e.user.username||e.user.userid||"";return{user:{value:t,display:e.user.displayName||t}}}const Wf={CHANGE_FOCUS_MODE_USER:function(e,t){return{focusActive:Gf({user:t.user}),focusFilters:Vf({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}}},Yf=_m(Wf);const Kf=cf((e=>e.focusActive),(e=>e.focusFilters),((e,t)=>{var n;return{active:e,configured:!(null==t||!t.user),
646
- displayName:(null==t||null===(n=t.user)||void 0===n?void 0:n.display)||""}})),Xf=cf((e=>e.filters),(e=>e.focusActive),(e=>e.focusFilters),((e,t,n)=>t?{...n,...e}:{...e}));const Zf=cf((e=>Xf(e)),(e=>{const t={};return Object.keys(e).forEach((n=>t[n]=e[n].value)),t}));var Jf=Qm((function(e){const t=e.focus||{};return{filters:{},focusActive:Gf(t),focusFilters:Vf(t),query:e.query||null}}),{namespace:"filters",reducers:Wf,actionCreators:{changeFocusModeUser:function(e){return{type:Yf.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:Yf.SET_FOCUS_MODE,active:!1}),n({type:Yf.SET_FILTER,filterName:e,filterOption:t})}},setFilterQuery:function(e){return{type:Yf.SET_FILTER_QUERY,query:e}},toggleFocusMode:function(e){return{type:Yf.SET_FOCUS_MODE,active:e}}},selectors:{filterQuery:function(e){return e.query},focusState:Kf,getFilter:function(e,t){return Xf(e)[t]},getFilters:Xf,getFilterValues:Zf,getFocusFilters:function(e){
647
- return e.focusFilters},hasAppliedFilter:function(e){return!(!e.query&&!Object.keys(Xf(e)).length)}}});const Qf={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))}},eg=_m(Qf);const tg=cf((e=>e),(e=>e.find((e=>!e.id))||null));const ng=lf(af,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));var rg=Qm([],{namespace:"frames",reducers:Qf,actionCreators:{connectFrame:function(e){return{type:eg.CONNECT_FRAME,frame:e}},destroyFrame:function(e){return{type:eg.DESTROY_FRAME,frame:e}},updateFrameAnnotationFetchStatus:function(e,t){return{
648
- type:eg.UPDATE_FRAME_ANNOTATION_FETCH_STATUS,isAnnotationFetchComplete:t,uri:e}}},selectors:{frames:function(e){return e},mainFrame:tg,searchUris:ng}});const og={features:{},preferences:{},userid:null};const ig={UPDATE_PROFILE:function(e,t){return{profile:{...t.profile}}}},ag=_m(ig);var sg=Qm((function(e){var t;return{defaultAuthority:null!==(t=null==e?void 0:e.authDomain)&&void 0!==t?t:"",profile:og}}),{namespace:"session",reducers:ig,actionCreators:{updateProfile:function(e){return{type:ag.UPDATE_PROFILE,profile:e}}},selectors:{defaultAuthority:function(e){return e.defaultAuthority},hasFetchedProfile:function(e){return e.profile!==og},isFeatureEnabled:function(e,t){return!!e.profile.features[t]},isLoggedIn:function(e){return null!==e.profile.userid},profile:function(e){return e.profile}}});const lg={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{
649
- 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:[]})},cg=_m(lg);function ug(e){return e.filteredGroupIds?e.groups.filter((t=>{var n;return null===(n=e.filteredGroupIds)||void 0===n?void 0:n.includes(t.id)})):e.groups}function hg(e,t){return e.groups.find((e=>e.id===t))}
650
- const dg=cf((e=>ug(e)),(e=>e.filter((e=>!e.isMember&&e.isScopedToUri)))),pg=cf((e=>ug(e)),(e=>e.filter((e=>e.isScopedToUri)))),mg=cf((e=>ug(e.groups)),(e=>sg.selectors.isLoggedIn(e.session)),((e,t)=>t?e.filter((e=>e.isMember)):[])),fg=cf((e=>ug(e.groups)),(e=>mg(e)),(e=>dg(e.groups)),((e,t,n)=>e.filter((e=>!t.includes(e)&&!n.includes(e)))));var gg=Qm({filteredGroupIds:null,groups:[],focusedGroupId:null},{namespace:"groups",reducers:lg,actionCreators:{filterGroups:function(e){return{type:cg.FILTER_GROUPS,filteredGroupIds:e}},focusGroup:function(e){return{type:cg.FOCUS_GROUP,id:e}},loadGroups:function(e){return{type:cg.LOAD_GROUPS,groups:e}},clearGroups:function(){return{type:cg.CLEAR_GROUPS}}},selectors:{allGroups:function(e){return e.groups},filteredGroups:ug,filteredGroupIds:function(e){return e.filteredGroupIds},focusedGroup:function(e){return e.focusedGroupId?hg(e,e.focusedGroupId):null},focusedGroupId:function(e){return e.focusedGroupId},getFeaturedGroups:dg,getGroup:hg,getInScopeGroups:pg},
651
- rootSelectors:{getCurrentlyViewingGroups:fg,getMyGroups:mg}});const vg={UPDATE_LINKS:(e,t)=>({...t.links})},yg=_m(vg);var _g=Qm(null,{namespace:"links",reducers:vg,actionCreators:{updateLinks:function(e){return{type:yg.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}=Xp(r,n),a=Object.keys(i);if(a.length>0)throw new Error(`Unused parameters: ${a.join(", ")}`);return o}}});const bg={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}},FOCUS_GROUP:()=>({
652
- pendingUpdates:{},pendingDeletions:{}})},wg=_m(bg);const xg=cf((e=>[e.pendingUpdates,e.pendingDeletions]),(([e,t])=>Object.keys(e).length+Object.keys(t).length));var kg=Qm({pendingUpdates:{},pendingDeletions:{}},{namespace:"realTimeUpdates",reducers:bg,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!==gg.selectors.focusedGroupId(t)&&"sidebar"===ff.selectors.route(n)||(o[e.id]=e)})),t.forEach((e=>{const t=e.id;delete o[t];const n=r().annotations;Lf.selectors.annotationExists(n,t)&&(i[t]=!0)})),n({type:wg.RECEIVE_REAL_TIME_UPDATES,pendingUpdates:o,pendingDeletions:i})}},clearPendingUpdates:function(){return{type:wg.CLEAR_PENDING_UPDATES}}},selectors:{hasPendingDeletion:function(e,t){return e.pendingDeletions.hasOwnProperty(t)},pendingDeletions:function(e){return e.pendingDeletions},
653
- pendingUpdates:function(e){return e.pendingUpdates},pendingUpdateCount:xg}});const Sg={annotation:"Location",note:"Oldest",orphan:"Location"};function Cg(e){const t={};return e.annotations&&!e.query&&(t[e.annotations]=!0),t}const Eg=(e,t)=>t===e?{}:{selectedTab:e,sortKey:Sg[e]},Ag={CLEAR_SELECTION:function(){return{forcedVisible:{},selected:{}}},SELECT_ANNOTATIONS:function(e,t){return{selected:t.selection}},SELECT_TAB:function(e,t){return Eg(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=>!Vo(e))),r=uf(t.annotations,ei)===n.length;return 0===t.currentAnnotationCount&&r?Eg("note",e.selectedTab):{}},
654
- 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===uf(t.remainingAnnotations,Qo)&&(n="annotation");const r=e=>(t.annotationsToRemove.forEach((t=>{t.id&&delete e[t.id],t.$tag&&delete e[t.$tag]})),e);return{...Eg(n,e.selectedTab),expanded:r({...e.expanded}),forcedVisible:r({...e.forcedVisible}),selected:r({...e.selected})}}},Tg=_m(Ag);function Ng(e){return e.expanded}const Lg=cf((e=>e.forcedVisible),(e=>df(e))),Mg=cf((e=>e.selected),(e=>df(e).length>0)),Og=cf((e=>e.selected),(e=>df(e)));function zg(e){return e.selectedTab}const Ig=cf((e=>e),(e=>({expanded:Ng(e),forcedVisible:Lg(e),selected:Og(e),sortKey:Rg(e),selectedTab:zg(e)})));function Rg(e){return e.sortKey}const Pg=cf((e=>e.selectedTab),(e=>{
655
- const t=["Newest","Oldest"];return"note"!==e&&t.push("Location"),t}));var Dg=Qm((function(e){return{selected:Cg(e),expanded:Cg(e)||{},forcedVisible:{},selectedTab:"annotation",sortKey:Sg.annotation}}),{namespace:"selection",reducers:Ag,actionCreators:{clearSelection:function(){return{type:Tg.CLEAR_SELECTION}},selectAnnotations:function(e){return t=>{t({type:Tg.CLEAR_SELECTION}),t({type:Tg.SELECT_ANNOTATIONS,selection:hf(e)})}},selectTab:function(e){return{type:Tg.SELECT_TAB,tab:e}},setExpanded:function(e,t){return{type:Tg.SET_EXPANDED,id:e,expanded:t}},setForcedVisible:function(e,t){return{type:Tg.SET_FORCED_VISIBLE,id:e,visible:t}},setSortKey:function(e){return{type:Tg.SET_SORT_KEY,key:e}},toggleSelectedAnnotations:function(e){return{type:Tg.TOGGLE_SELECTED_ANNOTATIONS,toggleIds:e}}},selectors:{expandedMap:Ng,forcedVisibleThreads:Lg,hasSelectedAnnotations:Mg,selectedAnnotations:Og,selectedTab:zg,selectionState:Ig,sortKey:Rg,sortKeys:Pg}});const Bg={OPEN_SIDEBAR_PANEL:function(e,t){return{
656
- 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}}},Fg=_m(Bg);var jg=Qm({activePanelName:null},{namespace:"sidebarPanels",reducers:Bg,actionCreators:{openSidebarPanel:function(e){return{type:Fg.OPEN_SIDEBAR_PANEL,panelName:e}},closeSidebarPanel:function(e){return{type:Fg.CLOSE_SIDEBAR_PANEL,panelName:e}},toggleSidebarPanel:function(e,t){return{type:Fg.TOGGLE_SIDEBAR_PANEL,panelName:e,panelState:t}}},selectors:{isSidebarPanelOpen:function(e,t){return e.activePanelName===t}}});const Hg={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{
657
- messages:e.messages.map((e=>e.id&&e.id===t.message.id?{...t.message}:e))}}},Ug=_m(Hg);var qg=Qm({messages:[]},{namespace:"toastMessages",reducers:Hg,actionCreators:{addToastMessage:function(e){return{type:Ug.ADD_MESSAGE,message:e}},removeToastMessage:function(e){return{type:Ug.REMOVE_MESSAGE,id:e}},updateToastMessage:function(e){return{type:Ug.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))}}});const $g={SET_SIDEBAR_OPENED:(e,t)=>!0===t.opened?{sidebarHasOpened:!0}:{}},Gg=_m($g);var Vg=Qm({sidebarHasOpened:!1},{namespace:"viewer",reducers:$g,actionCreators:{setSidebarOpened:function(e){return{type:Gg.SET_SIDEBAR_OPENED,opened:e}}},selectors:{hasSidebarOpened:function(e){return e.sidebarHasOpened}}});function Wg(e){return Jm([rf,Lf,zf,Pf,$f,Jf,rg,_g,gg,kg,ff,Dg,sg,jg,qg,Vg],[e],[ef])}Wg.$inject=["settings"];class Yg{
605
+ ;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 hm(e,t,n){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 dm{constructor(e,t){this._frameSync=e,this._store=t}init(){const e=()=>this._store.profile().features;hm(this._store.subscribe,[e,()=>this._store.frames()],(()=>{this._frameSync.notifyHost("featureFlagsUpdated",e()||{})}))}}function pm(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())}dm.$inject=["frameSync","store"];class mm{constructor({hostFrame:e,source:t}){this._hostFrame=e,this._source=t,this._listeners=new Ii}destroy(){
606
+ 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),!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;pm(r,{frame1:this._source,frame2:e,type:"offer"})&&(clearInterval(o),clearTimeout(i),this._listeners.remove(a),t(s[0]))}));r()}))}}class fm{constructor(){this._port=null,this._methods=new Map,this._sequence=1,this._callbacks=new Map,this._listeners=new Ii,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){
607
+ 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(),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){
608
+ const e=this._callbacks.get(t.response);this._callbacks.delete(t.response),e&&e(...t.arguments)}}}function gm({$tag:e,target:t,uri:n}){return{$tag:e,target:t,uri:n}}class vm{constructor(e,t,n){this._window=e,this._annotationsService=t,this._store=n,this._portFinder=new mm({hostFrame:this._window.parent,source:"sidebar"}),this._listeners=new Ii,this._hostRPC=new fm,this._guestRPC=[],this._inFrame=new Set,this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0;hm(this._store.subscribe,[()=>this._store.allAnnotations(),()=>this._store.frames()],(([t,n],[r])=>{let o=0;const i=new Set,a=[];t.forEach((e=>{Vo(e)||(Yo(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(gm)))),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)})),
609
+ n.length>0&&n.every((e=>e.isAnnotationFetchComplete))&&(0!==o&&o===e||(this._hostRPC.call("publicAnnotationCountChanged",o),e=o))}))}_connectGuest(e){const t=new fm;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=zi((()=>{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))})),
610
+ t.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")})),t.on("closeSidebar",(()=>{this._hostRPC.call("closeSidebar")})),this._guestRPC.push(t),t.connect(e),t.call("setHighlightsVisible",this._highlightsVisible),t.call("getDocumentInfo",((e,n)=>{e?t.destroy():this._store.connectFrame({id:n.frameIdentifier,metadata:n.metadata,uri:n.uri})}))}_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;pm(t,{frame1:"guest",frame2:"sidebar",type:"offer"})&&this._connectGuest(n[0])}))}notifyHost(e,...t){this._hostRPC.call(e,...t)}
611
+ 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 ym(e){return Object.keys(e).reduce(((e,t)=>(e[t]=t,e)),{})}vm.$inject=["$window","annotationsService","store"];const _m={id:"__default__",name:"__DEFAULT__",logo:"data:image/svg+xml;utf8,"+encodeURIComponent(vo)};const bm=["organization","scopes"];class wm{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
612
+ ;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,hm(this._store.subscribe,(()=>this._mainURI()),(()=>{this.load()})),hm(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=_m)}))}(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:bm})}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
613
+ ;"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:bm},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:bm}),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
614
+ ;return this._addGroupsToStore(g,v),g}async _loadServiceSpecifiedGroups(e){const t=await this._api.profile.groups.read({expand:bm});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}`)}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=>!Vo(e))).map((e=>({...e,group:n})))
615
+ ;e.length&&this._store.addAnnotations(e),this._store.setDefault("focusedGroup",n)}}leave(e){return this._api.group.member.delete({pubid:e,userid:"me"})}}wm.$inject=["store","api","auth","session","settings","toastMessenger"];class xm{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 kp(this._api.search,s),
616
+ 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}),Vo(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),!Vo(t)){const e=t.id;this._streamFilter.addClause("/references","one_of",e,!0).addClause("/id","equals",e,!0),
617
+ this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}),this._streamer.connect()}return r}}xm.$inject=["api","store","streamer","streamFilter"];class km{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 Sm{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 km}}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)}}Sm.$inject=["$window"];const Cm={annotationPrivacy:"hypothesis.privacy",focusedGroup:"hypothesis.groups.focus"};class Em{constructor(e,t){this._storage=e,this._store=t}init(){Object.keys(Cm).forEach((e=>{
618
+ const t=this._storage.getItem(Cm[e]);this._store.setDefault(e,t)})),hm(this._store.subscribe,(()=>this._store.getDefaults()),((e,t)=>{for(let n in e)t[n]!==e[n]&&n in Cm&&this._storage.setItem(Cm[n],e[n])}))}}Em.$inject=["localStorage","store"];class Am{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":{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
619
+ ;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()}}Am.$inject=["$window","store"];class Tm{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}`)}}}Tm.$inject=["apiRoutes","store"];class Nm{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(){
620
+ 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?Yn({id:e.userid}):Yn(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()}}Nm.$inject=["store","api","auth","settings","toastMessenger"];class Lm{constructor(){this._filter={match_policy:"include_any",
621
+ 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 Mm extends bp{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")},n.onerror=e=>{this.emit("error",e)},n.onmessage=e=>{this.emit("message",e)}})()}}class Om{constructor(e,t,n,r,o){this._auth=t,this._groups=n,this._session=r,this._store=e,
622
+ this._websocketURL=o.websocketUrl,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){K("Error connecting to H push notification service:",e);const t=new URL(this._websocketURL).hostname;-1!==["localhost","127.0.0.1"].indexOf(t)&&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})}
623
+ 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;if(!this._websocketURL)return;let t,n;null===(e=this._socket)||void 0===e||e.close();try{t=await this._auth.getAccessToken()}catch(e){throw console.error("Failed to fetch token for WebSocket authentication",e),e}if(t){const e=new URL(this._websocketURL);e.searchParams.set("access_token",t),n=e.toString()}else n=this._websocketURL;const r=new Mm(n);r.on("open",(()=>{this._reconnectionAttempts=0,
624
+ this._sendClientConfig(r)})),r.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")})),r.on("error",(e=>this._handleSocketError(e))),r.on("message",(e=>this._handleSocketMessage(e))),this._socket=r,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,hm(this._store.subscribe,(()=>this._store.profile().userid),(()=>{this._reconnect()}))),this._socket||await this._reconnect()}}Om.$inject=["store","auth","groups","session","settings"];class zm{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=>{
625
+ 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)}}zm.$inject=["localStorage"];class Im{constructor(e){this._store=e}forceVisible(e){e.children.forEach((e=>{this.forceVisible(e)})),e.visible||this._store.setForcedVisible(e.id,!0)}}Im.$inject=["store"];class Rm{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=""}={}){
626
+ 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 Pm(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Dm(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 Bm(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Dm(Object(n),!0).forEach((function(t){Pm(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Dm(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}
627
+ function Fm(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. "}Rm.$inject=["store"];var jm="function"==typeof Symbol&&Symbol.observable||"@@observable",Hm=function(){return Math.random().toString(36).substring(7).split("").join(".")},Um={INIT:"@@redux/INIT"+Hm(),REPLACE:"@@redux/REPLACE"+Hm(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Hm()}};function qm(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 $m(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(Fm(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(Fm(1));return n($m)(e,t)}if("function"!=typeof e)throw new Error(Fm(2));var o=e,i=t,a=[],s=a,l=!1;function c(){
628
+ s===a&&(s=a.slice())}function u(){if(l)throw new Error(Fm(3));return i}function h(e){if("function"!=typeof e)throw new Error(Fm(4));if(l)throw new Error(Fm(5));var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error(Fm(6));t=!1,c();var n=s.indexOf(e);s.splice(n,1),a=null}}}function d(e){if(!qm(e))throw new Error(Fm(7));if(void 0===e.type)throw new Error(Fm(8));if(l)throw new Error(Fm(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(Fm(10));o=e,d({type:Um.REPLACE})}function m(){var e,t=h;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(Fm(11));function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[jm]=function(){return this},e}return d({type:Um.INIT}),(r={dispatch:d,subscribe:h,getState:u,replaceReducer:p})[jm]=m,r}function Gm(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{
629
+ !function(e){Object.keys(e).forEach((function(t){var n=e[t];if(void 0===n(void 0,{type:Um.INIT}))throw new Error(Fm(12));if(void 0===n(void 0,{type:Um.PROBE_UNKNOWN_ACTION()}))throw new Error(Fm(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(Fm(14));o[l]=h,r=r||h!==u}return(r=r||a.length!==Object.keys(e).length)?o:e}}function Vm(e,t){return function(){return t(e.apply(this,arguments))}}function Wm(){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 Ym(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 Km=Ym();Km.withExtraArgument=Ym;var Xm=Km;function Zm(e,t=[],n=[]){const r={},o={},i={};e.forEach((e=>{
630
+ 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(Fm(15))},o={getState:n.getState,dispatch:function(){return r.apply(void 0,arguments)}},i=t.map((function(e){return e(o)}));return r=Wm.apply(void 0,i)(n.dispatch),Bm(Bm({},n),{},{dispatch:r})}}}(...[Xm],...n);const s=$m(Gm(o),r,a),l=Object.assign({},...e.map((e=>e.actionCreators))),c=function(e,t){if("function"==typeof e)return Vm(e,t);if("object"!=typeof e||null===e)throw new Error(Fm(16));var n={};for(var r in e){var o=e[r];"function"==typeof o&&(n[r]=Vm(o,t))}return n
631
+ }(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 Jm(e,t){if(!(e instanceof Function)){const t=e;e=()=>t}return{initialState:e,...t}}function Qm(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 ef={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,
632
+ 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");return{...e,hasFetchedAnnotations:!0,activeAnnotationFetches:e.activeAnnotationFetches-1}},SET_ANNOTATION_RESULT_COUNT:(e,t)=>({annotationResultCount:t.resultCount})},tf=ym(ef);var nf=Jm({activeAnnotationSaveRequests:[],activeApiRequests:0,activeAnnotationFetches:0,hasFetchedAnnotations:!1,annotationResultCount:null},{reducers:ef,namespace:"activity",
633
+ actionCreators:{annotationFetchStarted:function(){return{type:tf.ANNOTATION_FETCH_STARTED}},annotationFetchFinished:function(){return{type:tf.ANNOTATION_FETCH_FINISHED}},annotationSaveStarted:function(e){return{type:tf.ANNOTATION_SAVE_STARTED,annotation:e}},annotationSaveFinished:function(e){return{type:tf.ANNOTATION_SAVE_FINISHED,annotation:e}},apiRequestStarted:function(){return{type:tf.API_REQUEST_STARTED}},apiRequestFinished:function(){return{type:tf.API_REQUEST_FINISHED}},setAnnotationResultCount:function(e){return{type:tf.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 rf=function(e,t){return e===t};function of(e,t){
634
+ var n,r,o="object"==typeof t?t:{equalityCheck:t},i=o.equalityCheck,a=void 0===i?rf: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{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}
635
+ return d.clearCache=function(){return h.clear()},d}function af(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 sf(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=af(r),m=e.apply(void 0,[function(){return a++,l.apply(null,arguments)}].concat(d)),f=e((function(){
636
+ 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 lf=sf(of);function cf(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 hf(e){return Object.keys(e).filter((t=>!0===e[t]))}const df={CHANGE_ROUTE:(e,{name:t,params:n})=>({name:t,params:n})},pf=ym(df);var mf=Jm({name:null,params:{}},{namespace:"route",reducers:df,actionCreators:{changeRoute:function(e,t={}){return{type:pf.CHANGE_ROUTE,name:e,params:t}}},selectors:{route:function(e){return e.name},routeParams:function(e){return e.params}}});function ff(e,t){return e.find((e=>e.id===t))}function gf(e,t){return e.find((e=>e.$tag===t))}const vf={ADD_ANNOTATIONS:function(e,t){const n={},r={},o=[],i=[],a=[];let s=e.nextTag;return t.annotations.forEach((t=>{
637
+ let i;t.id&&(i=ff(e.annotations,t.id)),!i&&t.$tag&&(i=gf(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: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=>{
638
+ 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}))}}},yf=ym(vf);function _f(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:yf.REMOVE_ANNOTATIONS,annotationsToRemove:e,remainingAnnotations:r})}}function bf(e){return{type:yf.UPDATE_ANCHOR_STATUS,statusUpdates:e}}const wf=lf((e=>e.annotations),(e=>cf(e,ti)));const xf=lf((e=>e.focused),(e=>hf(e))),kf=lf((e=>e.highlighted),(e=>hf(e)))
639
+ ;const Sf=lf((e=>e.annotations),(e=>e.some(Xo))),Cf=lf((e=>e.annotations),(e=>e.filter((e=>Wo(e)&&!Jo(e))))),Ef=lf((e=>e.annotations),(e=>e.filter((e=>Wo(e)&&Jo(e))))),Af=lf((e=>e.annotations),(e=>cf(e,ei))),Tf=lf((e=>e.annotations),(e=>cf(e,Qo)));var Nf=Jm({annotations:[],focused:{},highlighted:{},nextTag:1},{namespace:"annotations",reducers:vf,actionCreators:{addAnnotations:function(e){return function(t,n){const r=e.filter((e=>!ff(n().annotations.annotations,e.id)));if(t({type:yf.ADD_ANNOTATIONS,annotations:e,currentAnnotationCount:n().annotations.annotations.length}),"sidebar"!==mf.selectors.route(n().route))return;const o=r.filter(Xo).map((e=>e.id));o.length>0&&setTimeout((()=>{const e=n().annotations.annotations,r=o.map((t=>ff(e,t))).filter((e=>e&&Xo(e))).reduce(((e,t)=>(e[t.$tag]="timeout",e)),{});t(bf(r))}),500)}},clearAnnotations:function(){return{type:yf.CLEAR_ANNOTATIONS}},focusAnnotations:function(e){return{type:yf.FOCUS_ANNOTATIONS,focusedTags:e}},hideAnnotation:function(e){return{
640
+ type:yf.HIDE_ANNOTATION,id:e}},highlightAnnotations:function(e){return{type:yf.HIGHLIGHT_ANNOTATIONS,highlighted:uf(e)}},removeAnnotations:_f,unhideAnnotation:function(e){return{type:yf.UNHIDE_ANNOTATION,id:e}},updateAnchorStatus:bf,updateFlagStatus:function(e,t){return{type:yf.UPDATE_FLAG_STATUS,id:e,isFlagged:t}}},selectors:{allAnnotations:function(e){return e.annotations},annotationCount:wf,annotationExists:function(e,t){return e.annotations.some((e=>e.id===t))},findAnnotationByID:function(e,t){return ff(e.annotations,t)},findIDsForTags:function(e,t){const n=[];return t.forEach((t=>{const r=gf(e.annotations,t);r&&r.id&&n.push(r.id)})),n},focusedAnnotations:xf,highlightedAnnotations:kf,isAnnotationFocused:function(e,t){return!0===e.focused[t]},isWaitingToAnchorAnnotations:Sf,newAnnotations:Cf,newHighlights:Ef,noteCount:Af,orphanCount:Tf,savedAnnotations:function(e){return e.annotations.filter((e=>!Wo(e)))}}});const Lf={SET_DEFAULT:function(e,t){return{[t.defaultKey]:t.value}}},Mf=ym(Lf);var Of=Jm({
641
+ annotationPrivacy:null,focusedGroup:null},{namespace:"defaults",reducers:Lf,actionCreators:{setDefault:function(e,t){return{type:Mf.SET_DEFAULT,defaultKey:e,value:t}}},selectors:{getDefault:function(e,t){return e[t]},getDefaults:function(e){return e}}});const zf={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{directLinkedAnnotationId:null,directLinkedGroupId:null,directLinkedGroupFetchFailed:!1}}},If=ym(zf);var Rf=Jm((function(e){return{directLinkedGroupId:e.group||null,directLinkedAnnotationId:e.annotations||null,directLinkedGroupFetchFailed:!1}}),{namespace:"directLinked",reducers:zf,actionCreators:{setDirectLinkedGroupFetchFailed:function(){
642
+ return{type:If.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!0}},setDirectLinkedGroupId:function(e){return{type:If.UPDATE_DIRECT_LINKED_GROUP_ID,directLinkedGroupId:e}},setDirectLinkedAnnotationId:function(e){return{type:If.UPDATE_DIRECT_LINKED_ANNOTATION_ID,directLinkedAnnotationId:e}},clearDirectLinkedGroupFetchFailed:function(){return{type:If.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!1}},clearDirectLinkedIds:function(){return{type:If.CLEAR_DIRECT_LINKED_IDS}}},selectors:{directLinkedAnnotationId:function(e){return e.directLinkedAnnotationId},directLinkedGroupFetchFailed:function(e){return e.directLinkedGroupFetchFailed},directLinkedGroupId:function(e){return e.directLinkedGroupId}}});class Pf{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(){
643
+ return!this.text&&0===this.tags.length}}const Df={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}},Bf=ym(Df);function Ff(e){return{type:Bf.REMOVE_DRAFT,annotation:e}}function jf(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 Hf(e,t){const n=jf(e,t);return n?n.isEmpty()?null:n:null}const Uf=lf((e=>e),(e=>e.filter((e=>!e.annotation.id)).map((e=>e.annotation))));var qf=Jm([],{namespace:"drafts",reducers:Df,actionCreators:{createDraft:function(e,t){return{type:Bf.UPDATE_DRAFT,draft:new Pf(e,t)}},deleteNewAndEmptyDrafts:function(){return(e,t)=>{const n=t().drafts.filter((e=>Wo(e.annotation)&&!Hf(t().drafts,e.annotation))).map((t=>(e(Ff(t.annotation)),t.annotation)));e(_f(n))}},discardAllDrafts:function(){return{type:Bf.DISCARD_ALL_DRAFTS}},removeDraft:Ff},selectors:{countDrafts:function(e){
644
+ return e.length},getDraft:jf,getDraftIfNotEmpty:Hf,unsavedAnnotations:Uf}});function $f(e){var t,n;return!!(null!==(t=e.user)&&void 0!==t&&t.username||null!==(n=e.user)&&void 0!==n&&n.userid)}function Gf(e){if(!$f(e))return{};const t=e.user.username||e.user.userid||"";return{user:{value:t,display:e.user.displayName||t}}}const Vf={CHANGE_FOCUS_MODE_USER:function(e,t){return{focusActive:$f({user:t.user}),focusFilters:Gf({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}}},Wf=ym(Vf);const Yf=lf((e=>e.focusActive),(e=>e.focusFilters),((e,t)=>{var n;return{active:e,configured:!(null==t||!t.user),
645
+ displayName:(null==t||null===(n=t.user)||void 0===n?void 0:n.display)||""}})),Kf=lf((e=>e.filters),(e=>e.focusActive),(e=>e.focusFilters),((e,t,n)=>t?{...n,...e}:{...e}));const Xf=lf((e=>Kf(e)),(e=>{const t={};return Object.keys(e).forEach((n=>t[n]=e[n].value)),t}));var Zf=Jm((function(e){const t=e.focus||{};return{filters:{},focusActive:$f(t),focusFilters:Gf(t),query:e.query||null}}),{namespace:"filters",reducers:Vf,actionCreators:{changeFocusModeUser:function(e){return{type:Wf.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:Wf.SET_FOCUS_MODE,active:!1}),n({type:Wf.SET_FILTER,filterName:e,filterOption:t})}},setFilterQuery:function(e){return{type:Wf.SET_FILTER_QUERY,query:e}},toggleFocusMode:function(e){return{type:Wf.SET_FOCUS_MODE,active:e}}},selectors:{filterQuery:function(e){return e.query},focusState:Yf,getFilter:function(e,t){return Kf(e)[t]},getFilters:Kf,getFilterValues:Xf,getFocusFilters:function(e){
646
+ return e.focusFilters},hasAppliedFilter:function(e){return!(!e.query&&!Object.keys(Kf(e)).length)}}});const Jf={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))}},Qf=ym(Jf);const eg=lf((e=>e),(e=>e.find((e=>!e.id))||null));const tg=sf(of,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));var ng=Jm([],{namespace:"frames",reducers:Jf,actionCreators:{connectFrame:function(e){return{type:Qf.CONNECT_FRAME,frame:e}},destroyFrame:function(e){return{type:Qf.DESTROY_FRAME,frame:e}},updateFrameAnnotationFetchStatus:function(e,t){return{
647
+ type:Qf.UPDATE_FRAME_ANNOTATION_FETCH_STATUS,isAnnotationFetchComplete:t,uri:e}}},selectors:{frames:function(e){return e},mainFrame:eg,searchUris:tg}});const rg={features:{},preferences:{},userid:null};const og={UPDATE_PROFILE:function(e,t){return{profile:{...t.profile}}}},ig=ym(og);var ag=Jm((function(e){var t;return{defaultAuthority:null!==(t=null==e?void 0:e.authDomain)&&void 0!==t?t:"",profile:rg}}),{namespace:"session",reducers:og,actionCreators:{updateProfile:function(e){return{type:ig.UPDATE_PROFILE,profile:e}}},selectors:{defaultAuthority:function(e){return e.defaultAuthority},hasFetchedProfile:function(e){return e.profile!==rg},isFeatureEnabled:function(e,t){return!!e.profile.features[t]},isLoggedIn:function(e){return null!==e.profile.userid},profile:function(e){return e.profile}}});const sg={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{
648
+ 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:[]})},lg=ym(sg);function cg(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 ug(e,t){return e.groups.find((e=>e.id===t))}
649
+ const hg=lf((e=>cg(e)),(e=>e.filter((e=>!e.isMember&&e.isScopedToUri)))),dg=lf((e=>cg(e)),(e=>e.filter((e=>e.isScopedToUri)))),pg=lf((e=>cg(e.groups)),(e=>ag.selectors.isLoggedIn(e.session)),((e,t)=>t?e.filter((e=>e.isMember)):[])),mg=lf((e=>cg(e.groups)),(e=>pg(e)),(e=>hg(e.groups)),((e,t,n)=>e.filter((e=>!t.includes(e)&&!n.includes(e)))));var fg=Jm({filteredGroupIds:null,groups:[],focusedGroupId:null},{namespace:"groups",reducers:sg,actionCreators:{filterGroups:function(e){return{type:lg.FILTER_GROUPS,filteredGroupIds:e}},focusGroup:function(e){return{type:lg.FOCUS_GROUP,id:e}},loadGroups:function(e){return{type:lg.LOAD_GROUPS,groups:e}},clearGroups:function(){return{type:lg.CLEAR_GROUPS}}},selectors:{allGroups:function(e){return e.groups},filteredGroups:cg,filteredGroupIds:function(e){return e.filteredGroupIds},focusedGroup:function(e){return e.focusedGroupId?ug(e,e.focusedGroupId):null},focusedGroupId:function(e){return e.focusedGroupId},getFeaturedGroups:hg,getGroup:ug,getInScopeGroups:dg},
650
+ rootSelectors:{getCurrentlyViewingGroups:mg,getMyGroups:pg}});const gg={UPDATE_LINKS:(e,t)=>({...t.links})},vg=ym(gg);var yg=Jm(null,{namespace:"links",reducers:gg,actionCreators:{updateLinks:function(e){return{type:vg.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}=Xp(r,n),a=Object.keys(i);if(a.length>0)throw new Error(`Unused parameters: ${a.join(", ")}`);return o}}});const _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}},FOCUS_GROUP:()=>({
651
+ pendingUpdates:{},pendingDeletions:{}})},bg=ym(_g);const wg=lf((e=>[e.pendingUpdates,e.pendingDeletions]),(([e,t])=>Object.keys(e).length+Object.keys(t).length));var xg=Jm({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!==fg.selectors.focusedGroupId(t)&&"sidebar"===mf.selectors.route(n)||(o[e.id]=e)})),t.forEach((e=>{const t=e.id;delete o[t];const n=r().annotations;Nf.selectors.annotationExists(n,t)&&(i[t]=!0)})),n({type:bg.RECEIVE_REAL_TIME_UPDATES,pendingUpdates:o,pendingDeletions:i})}},clearPendingUpdates:function(){return{type:bg.CLEAR_PENDING_UPDATES}}},selectors:{hasPendingDeletion:function(e,t){return e.pendingDeletions.hasOwnProperty(t)},pendingDeletions:function(e){return e.pendingDeletions},
652
+ pendingUpdates:function(e){return e.pendingUpdates},pendingUpdateCount:wg}});const kg={annotation:"Location",note:"Oldest",orphan:"Location"};function Sg(e){const t={};return e.annotations&&!e.query&&(t[e.annotations]=!0),t}const Cg=(e,t)=>t===e?{}:{selectedTab:e,sortKey:kg[e]},Eg={CLEAR_SELECTION:function(){return{forcedVisible:{},selected:{}}},SELECT_ANNOTATIONS:function(e,t){return{selected:t.selection}},SELECT_TAB:function(e,t){return Cg(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=>!Vo(e))),r=cf(t.annotations,ei)===n.length;return 0===t.currentAnnotationCount&&r?Cg("note",e.selectedTab):{}},
653
+ 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===cf(t.remainingAnnotations,Qo)&&(n="annotation");const r=e=>(t.annotationsToRemove.forEach((t=>{t.id&&delete e[t.id],t.$tag&&delete e[t.$tag]})),e);return{...Cg(n,e.selectedTab),expanded:r({...e.expanded}),forcedVisible:r({...e.forcedVisible}),selected:r({...e.selected})}}},Ag=ym(Eg);function Tg(e){return e.expanded}const Ng=lf((e=>e.forcedVisible),(e=>hf(e))),Lg=lf((e=>e.selected),(e=>hf(e).length>0)),Mg=lf((e=>e.selected),(e=>hf(e)));function Og(e){return e.selectedTab}const zg=lf((e=>e),(e=>({expanded:Tg(e),forcedVisible:Ng(e),selected:Mg(e),sortKey:Ig(e),selectedTab:Og(e)})));function Ig(e){return e.sortKey}const Rg=lf((e=>e.selectedTab),(e=>{
654
+ const t=["Newest","Oldest"];return"note"!==e&&t.push("Location"),t}));var Pg=Jm((function(e){return{selected:Sg(e),expanded:Sg(e)||{},forcedVisible:{},selectedTab:"annotation",sortKey:kg.annotation}}),{namespace:"selection",reducers:Eg,actionCreators:{clearSelection:function(){return{type:Ag.CLEAR_SELECTION}},selectAnnotations:function(e){return t=>{t({type:Ag.CLEAR_SELECTION}),t({type:Ag.SELECT_ANNOTATIONS,selection:uf(e)})}},selectTab:function(e){return{type:Ag.SELECT_TAB,tab:e}},setExpanded:function(e,t){return{type:Ag.SET_EXPANDED,id:e,expanded:t}},setForcedVisible:function(e,t){return{type:Ag.SET_FORCED_VISIBLE,id:e,visible:t}},setSortKey:function(e){return{type:Ag.SET_SORT_KEY,key:e}},toggleSelectedAnnotations:function(e){return{type:Ag.TOGGLE_SELECTED_ANNOTATIONS,toggleIds:e}}},selectors:{expandedMap:Tg,forcedVisibleThreads:Ng,hasSelectedAnnotations:Lg,selectedAnnotations:Mg,selectedTab:Og,selectionState:zg,sortKey:Ig,sortKeys:Rg}});const Dg={OPEN_SIDEBAR_PANEL:function(e,t){return{
655
+ 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}}},Bg=ym(Dg);var Fg=Jm({activePanelName:null},{namespace:"sidebarPanels",reducers:Dg,actionCreators:{openSidebarPanel:function(e){return{type:Bg.OPEN_SIDEBAR_PANEL,panelName:e}},closeSidebarPanel:function(e){return{type:Bg.CLOSE_SIDEBAR_PANEL,panelName:e}},toggleSidebarPanel:function(e,t){return{type:Bg.TOGGLE_SIDEBAR_PANEL,panelName:e,panelState:t}}},selectors:{isSidebarPanelOpen:function(e,t){return e.activePanelName===t}}});const jg={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{
656
+ messages:e.messages.map((e=>e.id&&e.id===t.message.id?{...t.message}:e))}}},Hg=ym(jg);var Ug=Jm({messages:[]},{namespace:"toastMessages",reducers:jg,actionCreators:{addToastMessage:function(e){return{type:Hg.ADD_MESSAGE,message:e}},removeToastMessage:function(e){return{type:Hg.REMOVE_MESSAGE,id:e}},updateToastMessage:function(e){return{type:Hg.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))}}});const qg={SET_SIDEBAR_OPENED:(e,t)=>!0===t.opened?{sidebarHasOpened:!0}:{}},$g=ym(qg);var Gg=Jm({sidebarHasOpened:!1},{namespace:"viewer",reducers:qg,actionCreators:{setSidebarOpened:function(e){return{type:$g.SET_SIDEBAR_OPENED,opened:e}}},selectors:{hasSidebarOpened:function(e){return e.sidebarHasOpened}}});function Vg(e){return Zm([nf,Nf,Of,Rf,qf,Zf,ng,yg,fg,xg,mf,Pg,ag,Fg,Ug,Gg],[e],[Qm])}Vg.$inject=["settings"];class Wg{
658
657
  constructor(){this._providers=new Map,this._instances=new Map,this._constructing=new Set}get(e){if(this._instances.has(e))return this._instances.get(e);const t=this._providers.get(e);if(!t)throw new Error(`"${e}" is not registered`);if("value"in t)return this._instances.set(e,t.value),t.value;if(this._constructing.has(e))throw new Error(`Encountered a circular dependency when constructing "${e}"`);this._constructing.add(e);try{const n=[],r="class"in t&&t.class.$inject||"factory"in t&&t.factory.$inject||[];for(const t of r)try{n.push(this.get(t))}catch(n){const r=new Error(`Failed to construct dependency "${t}" of "${e}": ${n.message}`);throw r.cause=n,r}let o;if(t.class)o=new t.class(...n);else{o=(0,t.factory)(...n)}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)
659
- }(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 Kg=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),Xg=function(e){const{version:t,origin:n}=R(e.location.href);return"1.962.0"!==t?(console.warn(`The Hypothesis sidebar is using a different version (1.962.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 Zg(e,t){e.setClientId(t.clientId)}
660
- function Jg(e,t,n){e.load(),t.load(),n.sync()}function Qg(e,t,n,r){e.init(),t.init(),n.init(),r.init()}function ev(e,t){"sidebar"===t.route()&&e.connect()}Kg.sentry&&Xg&&function(e){const t=function(){let e=import.meta.url;return e?new URL(e).origin:null}(),n=t?[t]:void 0;Gn({dsn:e.dsn,environment:e.environment,allowUrls:n,ignoreErrors:["Network request failed","Object Not Found Matching Id"],release:"1.962.0",beforeSend:(e,t)=>{if(Wn>=5)return K("Client-side Sentry quota reached. No further Sentry events will be sent"),null;++Wn;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{jt("host_config",R(window.location.href))}catch(e){}jt("loaded_scripts",Array.from(document.querySelectorAll("script")).filter((e=>!e.type||e.type.match(/javascript|module/))).map((e=>e.src||"<inline>"))),Vn(((e,t)=>{Ft(e,{tags:{context:t}})}))}(Kg.sentry),function(e){e.addEventListener("click",(e=>{const t=e.target
661
- ;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)}}}(),Zg.$inject=["api","streamer"],Jg.$inject=["groups","session","router"],Qg.$inject=["autosaveService","features","persistedDefaults","serviceURL"],ev.$inject=["frameSync","store"],function(e,{reset:t=!1}={}){t&&Pr.clear();for(let[t,n]of Object.entries(e))Pr.set(t,n)}(yo);const tv=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++){
662
- 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")}(Kg).then((e=>{!function(e,t){const n=new Yg;n.register("annotationsService",Wp).register("api",Jp).register("apiRoutes",im).register("auth",lm).register("autosaveService",cm).register("features",dm).register("frameSync",ym).register("groups",xm).register("loadAnnotationsService",km).register("localStorage",Cm).register("persistedDefaults",Am).register("router",Tm).register("serviceURL",Nm).register("session",Lm).register("streamer",zm).register("streamFilter",Mm).register("tags",Im).register("threadsService",Rm).register("toastMessenger",Pm).register("store",{factory:Wg}),n.register("$window",{value:window
663
- }).register("settings",{value:e}),n.run(Qg),n.run(Zg),n.run(Jg),n.run(ee),n.run(ev),I(Rr(Co.Provider,{value:n,children:Rr(Gp,{})}),t)}(e,tv)})).catch((e=>function(e,t){console.error("Failed to start Hypothesis client: ",e),I(Rr(Vp,{error:e}),t)}(e,tv)));
658
+ }(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 Yg=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),Kg=function(e){const{version:t,origin:n}=R(e.location.href);return"1.963.0"!==t?(console.warn(`The Hypothesis sidebar is using a different version (1.963.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 Xg(e,t){e.setClientId(t.clientId)}
659
+ function Zg(e,t,n){e.load(),t.load(),n.sync()}function Jg(e,t,n,r){e.init(),t.init(),n.init(),r.init()}function Qg(e,t){"sidebar"===t.route()&&e.connect()}Yg.sentry&&Kg&&function(e){const t=function(){let e=import.meta.url;return e?new URL(e).origin:null}(),n=t?[t]:void 0;Gn({dsn:e.dsn,environment:e.environment,allowUrls:n,ignoreErrors:["Network request failed","Object Not Found Matching Id"],release:"1.963.0",beforeSend:(e,t)=>{if(Wn>=5)return K("Client-side Sentry quota reached. No further Sentry events will be sent"),null;++Wn;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{jt("host_config",R(window.location.href))}catch(e){}jt("loaded_scripts",Array.from(document.querySelectorAll("script")).filter((e=>!e.type||e.type.match(/javascript|module/))).map((e=>e.src||"<inline>"))),Vn(((e,t)=>{Ft(e,{tags:{context:t}})}))}(Yg.sentry),function(e){e.addEventListener("click",(e=>{const t=e.target
660
+ ;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)}}}(),Xg.$inject=["api","streamer"],Zg.$inject=["groups","session","router"],Jg.$inject=["autosaveService","features","persistedDefaults","serviceURL"],Qg.$inject=["frameSync","store"],function(e,{reset:t=!1}={}){t&&Pr.clear();for(let[t,n]of Object.entries(e))Pr.set(t,n)}(yo);const ev=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++){
661
+ 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")}(Yg).then((e=>{!function(e,t){const n=new Wg;n.register("annotationsService",Wp).register("api",Jp).register("apiRoutes",im).register("auth",lm).register("autosaveService",cm).register("features",dm).register("frameSync",vm).register("groups",wm).register("loadAnnotationsService",xm).register("localStorage",Sm).register("persistedDefaults",Em).register("router",Am).register("serviceURL",Tm).register("session",Nm).register("streamer",Om).register("streamFilter",Lm).register("tags",zm).register("threadsService",Im).register("toastMessenger",Rm).register("store",{factory:Vg}),n.register("$window",{value:window
662
+ }).register("settings",{value:e}),n.run(Jg),n.run(Xg),n.run(Zg),n.run(ee),n.run(Qg),I(Rr(Co.Provider,{value:n,children:Rr(Gp,{})}),t)}(e,ev)})).catch((e=>function(e,t){console.error("Failed to start Hypothesis client: ",e),I(Rr(Vp,{error:e}),t)}(e,ev)));
664
663
  //# sourceMappingURL=sidebar.bundle.js.map