@prose-reader/react-reader 1.229.0 → 1.231.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.
@@ -1,2 +1,2 @@
1
- (function(b,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react"),require("reactjrx"),require("rxjs"),require("@chakra-ui/react"),require("react-icons/lu"),require("react-dom"),require("react-icons/bs"),require("@prose-reader/core"),require("react-icons/ri"),require("react-icons/rx"),require("react-icons/hi"),require("rc-slider"),require("rc-slider/assets/index.css"),require("react-icons/io"),require("react-icons/md")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","reactjrx","rxjs","@chakra-ui/react","react-icons/lu","react-dom","react-icons/bs","@prose-reader/core","react-icons/ri","react-icons/rx","react-icons/hi","rc-slider","rc-slider/assets/index.css","react-icons/io","react-icons/md"],e):(b=typeof globalThis<"u"?globalThis:b||self,e(b["prose-react-reader"]={},b.jsxRuntime,b.React,b.reactjrx,b.rxjs,b.react,b.lu,b.reactDom,b.bs,b.core,b.ri,b.rx,b.hi,b.RcSlider,null,b.io,b.md))})(this,function(b,e,a,p,g,t,C,ne,F,q,se,N,te,le,to,Y,K){"use strict";function re(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const s in o)if(s!=="default"){const l=Object.getOwnPropertyDescriptor(o,s);Object.defineProperty(n,s,l.get?l:{enumerable:!0,get:()=>o[s]})}}return n.default=o,Object.freeze(n)}const w=re(a),Q=a.createContext({reader:void 0,quickMenuSignal:p.signal({default:!1}),notificationsSubject:new g.Subject}),ie=a.memo(({children:o,reader:n,quickMenuOpen:s,onQuickMenuOpenChange:l})=>{const[,r]=p.useSignalState(()=>p.signal({default:s})),i=p.useConstant(()=>new g.Subject),d=p.useLiveRef(l),h=a.useMemo(()=>({quickMenuSignal:r,reader:n,notificationsSubject:i}),[r,n,i]);return a.useEffect(()=>{r.setValue(s)},[s,r]),p.useSubscribe(()=>r.pipe(g.tap(d.current)),[r,d]),e.jsx(Q.Provider,{value:h,children:o})}),ae=w.forwardRef(function(n,s){return e.jsx(t.IconButton,{variant:"ghost","aria-label":"Close",ref:s,...n,children:n.children??e.jsx(C.LuX,{})})}),O=w.forwardRef(function(n,s){const{children:l,portalled:r=!0,portalRef:i,backdrop:d=!0,...h}=n;return e.jsxs(t.Portal,{disabled:!r,container:i,children:[d&&e.jsx(t.Dialog.Backdrop,{}),e.jsx(t.Dialog.Positioner,{children:e.jsx(t.Dialog.Content,{ref:s,...h,asChild:!1,children:l})})]})}),m=w.forwardRef(function(n,s){return e.jsx(t.Dialog.CloseTrigger,{position:"absolute",top:"2",insetEnd:"2",...n,asChild:!0,children:e.jsx(ae,{size:"sm",ref:s,children:n.children})})}),D=t.Dialog.Root,A=t.Dialog.Footer,E=t.Dialog.Header,z=t.Dialog.Body;t.Dialog.Backdrop;const L=t.Dialog.Title;t.Dialog.Description,t.Dialog.Trigger;const M=t.Dialog.ActionTrigger,_=()=>a.useContext(Q),k=()=>{const{reader:o}=_();return o},X=o=>!!o&&"__PROSE_READER_ENHANCER_SEARCH"in o,$=o=>!!o&&"__PROSE_READER_ENHANCER_ANNOTATIONS"in o,Z=o=>!!o&&"__PROSE_READER_ENHANCER_GALLERY"in o,ce=o=>{const n=k(),s=$(n)?n:void 0;return{data:p.useObserve(()=>s==null?void 0:s.annotations.annotations$.pipe(g.map(r=>r.find(i=>i.id===o)),g.filter(p.isDefined),g.switchMap(r=>s.locateResource(r))),[s])}},J=({id:o,onNavigate:n})=>{var r,i;const s=k(),{data:l}=ce(o);return e.jsx(t.List.Item,{children:e.jsxs(t.Link,{href:"#",onClick:()=>{n(),s==null||s.navigation.goToCfi((l==null?void 0:l.meta.cfi)??"")},children:[(r=l==null?void 0:l.resource)!=null&&r.notes?e.jsx(t.List.Indicator,{asChild:!0,children:e.jsx(C.LuNotebookPen,{})}):e.jsx(t.List.Indicator,{asChild:!0,visibility:"hidden",children:e.jsx(C.LuNotebookPen,{})}),e.jsxs(t.Stack,{gap:0,children:[e.jsx(t.Text,{lineClamp:2,fontSize:"md",children:l!=null&&l.meta.range?l==null?void 0:l.meta.range.toString():e.jsx("i",{children:e.jsx("b",{children:"unknown (not loaded)"})})}),e.jsx(t.Text,{fontStyle:"italic",fontWeight:"bold",fontSize:"sm",children:`Book page: ${((i=l==null?void 0:l.meta)==null?void 0:i.absolutePageIndex)!==void 0?l.meta.absolutePageIndex+1:"unknown (not loaded)"}`})]})]})})},W=()=>{const o=k(),n=$(o)?o:void 0;return{data:p.useObserve(()=>n==null?void 0:n.annotations.annotations$.pipe(g.switchMap(l=>n.locateResource(l))),[n])}},de=({onNavigate:o})=>{const{data:n}=W();return e.jsx(t.List.Root,{overflowY:"auto",gap:3,pt:4,variant:"plain",children:n==null?void 0:n.map(s=>e.jsx(J,{id:s.resource.id,onNavigate:o},s.resource.id))})},he=()=>{const{data:o}=W();return{data:o==null?void 0:o.filter(n=>!n.meta.range)}},ge=({onNavigate:o})=>{const{data:n}=he();return e.jsx(t.List.Root,{overflowY:"auto",gap:3,pt:4,variant:"plain",children:n==null?void 0:n.map(s=>e.jsx(J,{id:s.resource.id,onNavigate:o},s.resource.id))})},pe=a.memo(({onNavigate:o,defaultTab:n})=>{const[s,l]=a.useState(n??"bookmarks");return e.jsxs(t.Tabs.Root,{value:s,onValueChange:r=>l(r.value),children:[e.jsxs(t.Tabs.List,{children:[e.jsxs(t.Tabs.Trigger,{value:"bookmarks",children:[e.jsx(C.LuBookmark,{}),"Bookmarks"]}),e.jsxs(t.Tabs.Trigger,{value:"annotations",children:[e.jsx(C.LuNotebookPen,{}),"Annotations"]}),e.jsx(t.Tabs.Indicator,{})]}),e.jsx(t.Tabs.Content,{value:"bookmarks",children:e.jsx(ge,{onNavigate:o})}),e.jsx(t.Tabs.Content,{value:"annotations",children:e.jsx(de,{onNavigate:o})})]})}),fe=a.memo(({openWith:o,setOpen:n,onNavigate:s})=>e.jsx(D,{lazyMount:!0,placement:"center",open:!!o,onOpenChange:l=>n(l.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:e.jsxs(O,{height:"100%",children:[e.jsx(E,{children:e.jsx(L,{children:"Annotations"})}),e.jsx(z,{flex:1,children:e.jsx(pe,{onNavigate:s,defaultTab:o})}),e.jsx(A,{children:e.jsx(M,{asChild:!0,children:e.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),e.jsx(m,{})]})})),ue=a.memo(({children:o})=>{const n=k(),s=p.useObserve(()=>n==null?void 0:n.spine.element$,[n]);return s?e.jsx(e.Fragment,{children:ne.createPortal(o,s)}):null}),be=({absolutePageIndex:o,itemIndex:n})=>{const s=k(),l=p.useObserve(()=>s==null?void 0:s.spine.spineItemsManager.items$,[s]);return{spineItem:a.useMemo(()=>{if(n!==void 0)return s==null?void 0:s.spine.spineItemsManager.get(n);if(o!==void 0){const{itemIndex:i}=(s==null?void 0:s.spine.locator.getSpineInfoFromAbsolutePageIndex({absolutePageIndex:o}))??{};return s==null?void 0:s.spine.spineItemsManager.get(i)}},[n,o,s,l])}},ve=({absolutePageIndex:o,itemIndex:n})=>{const{spineItem:s}=be({absolutePageIndex:o,itemIndex:n});return p.useObserve(()=>(s==null?void 0:s.isReady$)??g.of(!1),[s])},j="data-bookmark-area",R=()=>{const o=k();return $(o)?o:void 0},ke=o=>{const n=R();return p.useObserve(()=>n==null?void 0:n.annotations.candidates$.pipe(g.map(s=>s[o])),[n])},Se=a.memo(({absolutePageIndex:o,left:n,top:s,width:l})=>{const r=R(),i=ve({absolutePageIndex:o}),{data:d}=W(),h=d==null?void 0:d.find(c=>{var v;return((v=c==null?void 0:c.meta)==null?void 0:v.absolutePageIndex)===o&&c.meta.range===void 0}),u=ke(o);return!i||!u?null:e.jsx(t.Presence,{present:!0,lazyMount:!0,animationName:{_open:"fade-in",_closed:"fade-out"},animationDuration:"moderate",children:e.jsx(t.Box,{"data-bookmark-area":j,position:"absolute",left:n+l,transform:"translateX(-100%)",top:s,p:2,children:h?e.jsx(t.IconButton,{"aria-label":"bookmark",opacity:.5,_hover:{opacity:1},onClick:()=>{r==null||r.annotations.delete(h.resource.id)},size:"lg",variant:"ghost",_icon:{boxSize:"36px"},children:e.jsx(F.BsBookmarkXFill,{})}):e.jsx(t.IconButton,{"aria-label":"bookmark",onClick:()=>{r==null||r.annotations.annotateAbsolutePage({absolutePageIndex:o})},size:"lg",bgColor:"white",opacity:.5,_hover:{opacity:1},variant:"ghost",_icon:{boxSize:"36px"},children:e.jsx(F.BsBookmarkPlus,{})})})})}),Ce=a.memo(()=>{const o=k(),n=p.useObserve(()=>o==null?void 0:o.layoutInfo$,[o]);return e.jsx(ue,{children:n==null?void 0:n.pages.map(({absoluteLayout:{left:s,top:l,width:r}},i)=>e.jsx(Se,{absolutePageIndex:i,left:s,top:l,width:r},i))})}),V=t.createToaster({placement:"bottom-end",pauseOnPageIdle:!0}),Te=()=>e.jsx(t.Portal,{children:e.jsx(t.Toaster,{toaster:V,insetInline:{mdDown:"4"},children:o=>{var n;return e.jsxs(t.Toast.Root,{width:{md:"sm"},children:[o.type==="loading"?e.jsx(t.Spinner,{size:"sm",color:"blue.solid"}):e.jsx(t.Toast.Indicator,{}),e.jsxs(t.Stack,{gap:"1",flex:"1",maxWidth:"100%",children:[o.title&&e.jsx(t.Toast.Title,{children:o.title}),o.description&&e.jsx(t.Toast.Description,{children:o.description})]}),o.action&&e.jsx(t.Toast.ActionTrigger,{children:o.action.label}),((n=o.meta)==null?void 0:n.closable)&&e.jsx(t.Toast.CloseTrigger,{})]})}})}),Ie={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function ye(){const[o,n]=a.useState(null),[s,l]=a.useState(Ie),r=a.useMemo(()=>new ResizeObserver(i=>{if(i[0]){const{x:d,y:h,width:u,height:c,top:v,left:f,bottom:T,right:I}=i[0].contentRect;l({x:d,y:h,width:u,height:c,top:v,left:f,bottom:T,right:I})}}),[]);return a.useLayoutEffect(()=>{if(o)return r.observe(o),()=>{r.disconnect()}},[o,r]),[n,s,o]}const xe=(o,n,s)=>{const l=k(),r=Z(l)?l:void 0;p.useSubscribe(()=>{if(!r||!o)return g.NEVER;const i=n.layout.layout$.pipe(g.startWith(n.layout.layoutInfo),g.distinctUntilChanged(q.isShallowEqual)),d=q.observeIntersection(o).pipe(g.map(h=>h.some(u=>u.isIntersecting)));return i.pipe(g.throttleTime(100,void 0,{trailing:!0}),g.switchMap(()=>d.pipe(g.tap(h=>{h||(o.innerHTML="")}),g.filter(h=>h),g.first()).pipe(g.switchMap(()=>(o.innerHTML="",r==null?void 0:r.gallery.snapshot(n,o,s))))))},[r,n,s,o])},Pe=a.memo(({item:o,onNavigated:n})=>{var h;const[s,l,r]=ye(),i=k();xe(r,o,l);const d=p.useObserve(()=>i==null?void 0:i.locateResource(o,{mode:"shallow"}),[i,o]);return e.jsxs(t.Box,{width:"100%",aspectRatio:"2/3",border:"1px solid",borderColor:"border",borderRadius:"md","data-grid-item":!0,cursor:"pointer",position:"relative",overflow:"hidden",onClick:()=>{n(),i==null||i.navigation.goToSpineItem({indexOrId:o})},children:[e.jsx(t.Box,{height:"100%",width:"100%",overflow:"hidden",pointerEvents:"none",ref:s}),e.jsxs(t.Text,{position:"absolute",bottom:0,left:"0",right:"0",textAlign:"center",bgColor:"white",p:4,fontSize:"xs",children:["Page ",(((h=d==null?void 0:d.meta)==null?void 0:h.absolutePageIndex)??0)+1]})]})}),we=a.memo(({open:o,setOpen:n})=>{const s=k(),l=p.useObserve(()=>s==null?void 0:s.spineItemsManager.items$,[s]);return e.jsx(D,{lazyMount:!0,placement:"center",open:o,onOpenChange:r=>n(r.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:e.jsxs(O,{height:"100%",children:[e.jsx(E,{children:e.jsx(L,{children:"Gallery"})}),e.jsx(z,{children:e.jsx(t.Box,{gridTemplateColumns:["repeat(2, minmax(0, 1fr))","repeat(3, minmax(0, 1fr))"],display:"grid",gap:[2,4],pt:2,"data-grid":!0,children:l==null?void 0:l.map(r=>e.jsx(Pe,{item:r,onNavigated:()=>{n(!1)}},r.item.id))})}),e.jsx(A,{children:e.jsx(M,{asChild:!0,children:e.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),e.jsx(m,{})]})})}),Be="@prose-reader/react-reader",Oe="1.228.0",me=a.memo(({open:o,setOpen:n})=>e.jsx(D,{lazyMount:!0,placement:"center",open:o,onOpenChange:s=>n(s.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:e.jsxs(O,{children:[e.jsx(E,{children:e.jsx(L,{children:"Help"})}),e.jsxs(z,{overflowY:"auto",flex:1,children:[e.jsx(t.Heading,{mb:2,as:"h3",size:"lg",children:"Shortcuts"}),e.jsxs(t.HStack,{mb:1,children:[e.jsx(t.Kbd,{children:e.jsx(C.LuArrowBigRight,{})})," ",e.jsx(t.Text,{children:"Navigate to right page"})]}),e.jsxs(t.HStack,{mb:1,children:[e.jsx(t.Kbd,{children:e.jsx(C.LuArrowBigLeft,{})})," ",e.jsx(t.Text,{children:"Navigate to left page"})]}),e.jsx(t.Heading,{mb:2,mt:4,as:"h3",size:"lg",children:"About"}),e.jsxs(t.Text,{children:[Be," version: ",Oe]})]}),e.jsx(A,{children:e.jsx(M,{asChild:!0,children:e.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),e.jsx(m,{})]})})),B=()=>{const o=k();return p.useObserve(()=>o?g.combineLatest([o.pagination.state$,o.context.state$]).pipe(g.map(([n,s])=>{var r;const l=(r=s.manifest)==null?void 0:r.spineItems.every(i=>{var d;return(d=i.mediaType)==null?void 0:d.startsWith("image/")});return{...n,hasChapters:!s.isFullyPrePaginated&&!l}})):g.NEVER,[o])},De=()=>{const o=B(),n=Math.floor(((o==null?void 0:o.percentageEstimateOfBook)??0)*100),s=n>0?n:1;return(o==null?void 0:o.percentageEstimateOfBook)===void 0?null:e.jsx(t.Box,{position:"absolute",right:0,bottom:0,p:2,color:"black",children:e.jsxs(t.Text,{fontSize:"sm",children:[s," %"]})})},Ae=()=>{const[o,n]=a.useState(new Date);return a.useEffect(()=>{const s=setInterval(()=>{n(new Date)},6e4);return()=>clearInterval(s)},[]),o},Ee=o=>{const n=Ae();return e.jsx(t.Text,{fontSize:"xs",...o,children:n.toLocaleTimeString(navigator.language,{hour:"2-digit",minute:"2-digit"})})},G=()=>{const{quickMenuSignal:o}=_();return[p.useSignalValue(o),o.setValue,o]},ze=()=>{const[o]=G();return e.jsx(t.Box,{position:"absolute",left:0,bottom:0,p:2,color:o?void 0:"colorPalette.contrast",children:e.jsx(Ee,{})})},Le=()=>{const o=k();p.useSubscribe(()=>o==null?void 0:o.links$.subscribe(n=>{if(n.type==="click"&&q.isHtmlTagElement(n.target,"a")){if(!n.target.href)return;const s=new URL(n.target.href);window.location.host!==s.host&&confirm("You are going to be redirected to external link")&&window.open(n.target.href,"__blank")}}),[o])},Me=()=>{const o=k(),{notificationsSubject:n}=_();p.useSubscribe(()=>o==null?void 0:o.zoom.isZooming$.pipe(g.switchMap(s=>{if(!s)return g.EMPTY;const l=new g.Subject;return n.next({key:"zoom",title:"Zooming",duration:999999,abort:l}),g.NEVER.pipe(g.finalize(()=>{l.next(),l.complete()}))})),[o])},_e=()=>{const o=k(),{notificationsSubject:n}=_();p.useSubscribe(()=>o==null?void 0:o.settings.values$.pipe(g.map(({fontScale:s})=>s),g.distinctUntilChanged(),g.skip(1),g.tap(s=>{n.next({key:"fontScaleChange",title:"Font size changed",description:`${s*100} %`})})),[o,n])},$e=()=>{const{notificationsSubject:o}=_();_e(),Me(),p.useSubscribe(()=>o.pipe(g.filter(p.isDefined),g.mergeMap(n=>{const s=n.duration??3e3,l=V.create({title:n.title,description:n.description,duration:s}),r=o.pipe(g.skip(1),g.filter(i=>!!n.key&&(i==null?void 0:i.key)===n.key));return g.merge(g.timer(s),n.abort??g.NEVER,r).pipe(g.first(),g.finalize(()=>{V.dismiss(l)}))})),[o])},He=w.forwardRef(function(n,s){const{showArrow:l,children:r,portalled:i=!0,content:d,portalRef:h,...u}=n;return e.jsxs(t.Popover.Root,{...u,positioning:{...u.positioning,gutter:4},children:[e.jsx(t.Popover.Trigger,{asChild:!0,children:r}),e.jsx(t.Portal,{disabled:!i,container:h,children:e.jsx(t.Popover.Positioner,{children:e.jsxs(t.Popover.Content,{width:"auto",px:"2",py:"1",textStyle:"xs",rounded:"sm",ref:s,children:[l&&e.jsx(t.Popover.Arrow,{children:e.jsx(t.Popover.ArrowTip,{})}),d]})})})]})}),Ne=w.forwardRef(function(n,s){const{children:l,...r}=n;return e.jsx(He,{content:l,...r,ref:s,children:e.jsx(t.IconButton,{variant:"ghost","aria-label":"info",size:"2xs",colorPalette:"gray",children:e.jsx(te.HiOutlineInformationCircle,{})})})}),Fe=w.forwardRef(function(n,s){return e.jsx(t.Progress.Track,{...n,ref:s,children:e.jsx(t.Progress.Range,{})})});w.forwardRef(function(n,s){const{children:l,info:r,...i}=n;return e.jsxs(t.Progress.Label,{...i,ref:s,children:[l,r&&e.jsx(Ne,{children:r})]})});const qe=t.Progress.Root,We=t.Progress.ValueText,U=()=>{const o=B(),n=(o==null?void 0:o.numberOfTotalPages)===1,s=((o==null?void 0:o.beginNumberOfPagesInSpineItem)??0)>1,l=((o==null?void 0:o.endNumberOfPagesInSpineItem)??0)>1,r=(o!=null&&o.hasChapters?o==null?void 0:o.beginPageIndexInSpineItem:o==null?void 0:o.beginAbsolutePageIndex)??0,i=(o!=null&&o.hasChapters?o==null?void 0:o.endPageIndexInSpineItem:o==null?void 0:o.endAbsolutePageIndex)??0,[d=0,h=0]=[r,i].sort((v,f)=>v-f),u=(o==null?void 0:o.beginPageIndexInSpineItem)!==(o==null?void 0:o.endPageIndexInSpineItem)||(o==null?void 0:o.beginSpineItemIndex)!==(o==null?void 0:o.endSpineItemIndex),c=o!=null&&o.hasChapters?o==null?void 0:o.beginNumberOfPagesInSpineItem:o==null?void 0:o.numberOfTotalPages;return{hasOnlyOnePage:n,beginPageIndex:r,endPageIndex:i,isBeginWithinChapter:s,isEndWithinChapter:l,beginAndEndAreDifferent:u,totalApproximatePages:c,leftPageIndex:d,rightPageIndex:h}},Ve=()=>{const o=B(),{hasOnlyOnePage:n,leftPageIndex:s,rightPageIndex:l,totalApproximatePages:r,beginAndEndAreDifferent:i}=U(),d=Math.round(((o==null?void 0:o.percentageEstimateOfBook)??0)*100),h=c=>c!=null&&c.subChapter?`${c.title} / ${h(c.subChapter)}`:(c==null?void 0:c.title)||"",u=h(o==null?void 0:o.beginChapterInfo);return e.jsxs(t.Stack,{alignItems:"center",gap:1,maxW:"100%",overflow:"auto",children:[e.jsx(qe,{value:d,size:"xs",width:150,children:e.jsxs(t.HStack,{justifyContent:"space-between",children:[e.jsx(Fe,{width:110}),e.jsx(We,{children:`${d}%`})]})}),e.jsx(t.Text,{truncate:!0,maxWidth:"100%",fontSize:"sm",mt:1,children:u?`Chapter: ${u}`:" "}),!n&&e.jsxs(t.HStack,{children:[e.jsx(t.Text,{fontSize:"xs",children:i?`${s+1} - ${l+1} of ${r}`:`${s+1} of ${r}`}),!!(o!=null&&o.hasChapters)&&e.jsxs(e.Fragment,{children:[e.jsx(t.Text,{children:"-"}),e.jsxs(t.Text,{fontSize:"xs",children:["(",((o==null?void 0:o.beginAbsolutePageIndex)??0)+1,")"]})]})]})]})},ee=a.memo(({children:o,position:n,...s})=>e.jsx(t.Presence,{display:"flex",flexDirection:"row",width:"100%",position:"absolute",...n==="bottom"?{bottom:0}:{top:0},animationName:n==="bottom"?{_open:"slide-from-bottom, fade-in",_closed:"slide-to-bottom, fade-out"}:{_open:"slide-from-top, fade-in",_closed:"slide-to-top, fade-out"},animationDuration:"moderate",bgColor:"bg.panel",alignItems:"center",justifyContent:"center",shadow:"md",p:4,...s,children:o})),Ge=t.chakra(le),Ue=a.memo(o=>e.jsx(t.Box,{display:"contents",css:{"--bg":"colors.bg","--bg-emphasized":"colors.bg.emphasized","--color-solid":"colors.colorPalette.solid"},children:e.jsx(Ge,{keyboard:!1,style:{padding:0},css:{"& > .rc-slider-handle:focus-visible":{boxShadow:"0 0 0 2px var(--color-solid) !important"},"& > .rc-slider-handle:active":{boxShadow:"0 0 5px var(--color-solid) !important"},"& > .rc-slider-handle.rc-slider-handle-dragging":{boxShadow:"0 0 0 3px var(--color-solid) !important"}},styles:{rail:{height:"8px",top:"50%",transform:"translateY(-50%)",backgroundColor:"var(--bg-emphasized)"},track:{height:"8px",top:"50%",transform:"translateY(-50%)",backgroundColor:"var(--color-solid)"},handle:{width:"24px",height:"24px",top:"50%",borderColor:"var(--color-solid)",transform:`translate(${o.reverse?"50%":"-50%"}, -50%)`,backgroundColor:"var(--bg)",marginTop:"0px"}},...o})})),Ye=()=>{const o=B(),n=o==null?void 0:o.isUsingSpread,{beginPageIndex:s,totalApproximatePages:l=0}=U(),r=n?Math.floor((s||0)/2):s,[i,d]=p.useSignalState(()=>p.signal({default:r||0})),h=0,u=Math.max(0,n?Math.floor((l-1)/2):l-1);return a.useEffect(()=>{d.update(r||0)},[r,d]),{value:i,valueSignal:d,min:h,max:u}},Ke=o=>{const n=k(),s=B(),{manifest:l}=p.useObserve(()=>n==null?void 0:n.context.state$,[n])??{},r=(l==null?void 0:l.readingDirection)==="rtl",i=s==null?void 0:s.isUsingSpread,{totalApproximatePages:d=0,isBeginWithinChapter:h}=U(),u=1,c=h,{value:v,valueSignal:f,min:T,max:I}=Ye(),y=a.useCallback(P=>{const[S=0]=Array.isArray(P)?P:[P];f.setValue(S);const H=i?Math.floor(S)*2:Math.floor(S);c?n==null||n.navigation.goToPageOfSpineItem({pageIndex:H,spineItemId:n.pagination.state.beginSpineItemIndex??0,animation:!1}):n==null||n.navigation.goToAbsolutePageIndex({absolutePageIndex:H,animation:!1})},[n,i,f,c]);return p.useSubscribe(()=>n==null?void 0:n.navigation.throttleLock({duration:100,trigger:f.subject}),[n,f]),d===1||i&&d===2?e.jsx(t.Box,{style:o.style}):e.jsx(Ue,{value:[v],max:I,min:T,reverse:r,step:u,onChange:y,...o})},Qe=a.memo(({open:o,onItemClick:n})=>{const s=k(),l=p.useObserve(()=>s==null?void 0:s.navigation.state$,[s]),r=p.useObserve(()=>s==null?void 0:s.settings.values$,[s]),i=(r==null?void 0:r.computedPageTurnDirection)==="vertical",[d,h]=a.useState(!0);return e.jsxs(ee,{present:o,position:"bottom",display:"flex",flexDirection:"column",overflow:"auto",pb:8,children:[e.jsxs(t.HStack,{flex:1,alignItems:"center",justifyContent:"center",children:[e.jsx(t.IconButton,{"aria-label":"left",size:"lg",variant:"ghost",flexShrink:0,onClick:()=>s==null?void 0:s.navigation.goToLeftOrTopSpineItem(),disabled:!(l!=null&&l.canGoLeftSpineItem)&&!(l!=null&&l.canGoTopSpineItem),children:i?e.jsx(N.RxDoubleArrowUp,{}):e.jsx(N.RxDoubleArrowLeft,{})}),e.jsxs(t.Stack,{flex:1,maxW:400,gap:2,alignItems:"center",overflow:"auto",px:4,children:[e.jsx(Ve,{}),e.jsx(Ke,{style:{width:"100%",maxWidth:"300px",height:"35px"}})]}),e.jsx(t.IconButton,{"aria-label":"right",size:"lg",flexShrink:0,variant:"ghost",disabled:!(l!=null&&l.canGoRightSpineItem)&&!(l!=null&&l.canGoBottomSpineItem),onClick:()=>{s==null||s.navigation.goToRightOrBottomSpineItem()},children:i?e.jsx(N.RxDoubleArrowDown,{}):e.jsx(N.RxDoubleArrowRight,{})})]}),e.jsx(t.HStack,{alignSelf:"stretch",alignItems:"center",justifyContent:"center",children:e.jsxs(t.Collapsible.Root,{open:d,flex:1,onOpenChange:({open:u})=>{h(u)},children:[e.jsx(t.Collapsible.Trigger,{paddingY:"3",width:"100%",display:"flex",justifyContent:"center",children:e.jsx(C.LuChevronDown,{style:{transform:d?"rotate(0deg)":"rotate(180deg)"}})}),e.jsxs(t.Collapsible.Content,{display:"flex",justifyContent:"center",children:[e.jsx(t.IconButton,{"aria-label":"Help",size:"lg",variant:"ghost",onClick:()=>n("help"),children:e.jsx(C.LuCircleHelp,{})}),e.jsx(t.IconButton,{"aria-label":"Table of contents",size:"lg",variant:"ghost",onClick:()=>n("toc"),children:e.jsx(C.LuTableOfContents,{})}),X(s)&&e.jsx(t.IconButton,{"aria-label":"Search",size:"lg",variant:"ghost",onClick:()=>n("search"),children:e.jsx(C.LuSearch,{})}),$(s)&&e.jsx(t.IconButton,{"aria-label":"Bookmarks",size:"lg",variant:"ghost",onClick:()=>n("bookmarks"),children:e.jsx(F.BsBookmarks,{})}),$(s)&&e.jsx(t.IconButton,{"aria-label":"Annotations",size:"lg",variant:"ghost",onClick:()=>n("annotations"),children:e.jsx(C.LuNotebookPen,{})}),e.jsx(t.IconButton,{"aria-label":"Thumbnails",size:"lg",variant:(s==null?void 0:s.settings.values.viewportMode)==="thumbnails"?"solid":"ghost",onClick:()=>{s==null||s.settings.update({viewportMode:(s==null?void 0:s.settings.values.viewportMode)==="normal"?"thumbnails":"normal"})},children:e.jsx(C.LuGalleryHorizontal,{})}),Z(s)&&e.jsx(t.IconButton,{"aria-label":"Gallery",size:"lg",variant:"ghost",onClick:()=>n("gallery"),children:e.jsx(se.RiGalleryView2,{})})]})]})})]})}),Xe=()=>{const[o,n]=a.useState(!1),s=a.useCallback(()=>document.fullscreenElement?document.exitFullscreen().catch(console.error).then(()=>{n(!1)}):document.documentElement.requestFullscreen({navigationUI:"hide"}).catch(console.error).then(()=>{n(!0)}),[]);return a.useEffect(()=>{function l(){n(!!document.fullscreenElement)}return document.addEventListener("fullscreenchange",l),()=>{document.removeEventListener("fullscreenchange",l)}},[]),{isFullscreen:o,onToggleFullscreenClick:s}},Ze=a.memo(({open:o,onItemClick:n})=>{const s=k(),l=p.useObserve(()=>s==null?void 0:s.context.manifest$,[s]),{isFullscreen:r,onToggleFullscreenClick:i}=Xe();return e.jsxs(ee,{present:o,position:"top",height:"80px",justifyContent:"space-between",children:[e.jsx(t.IconButton,{"aria-label":"left",size:"lg",variant:"ghost",flexShrink:0,onClick:()=>n("back"),children:e.jsx(Y.IoIosArrowBack,{})}),e.jsx(t.Stack,{flex:1,maxW:600,gap:1,alignItems:"center",overflow:"auto",px:4,children:e.jsx(t.Text,{truncate:!0,maxWidth:"100%",children:l==null?void 0:l.title})}),e.jsxs(t.HStack,{children:[e.jsx(t.IconButton,{"aria-label":"right",size:"lg",flexShrink:0,variant:"ghost",onClick:()=>n("more"),children:e.jsx(Y.IoMdMore,{})}),e.jsx(t.IconButton,{"aria-label":"right",size:"lg",flexShrink:0,variant:"ghost",onClick:i,children:r?e.jsx(K.MdFullscreenExit,{}):e.jsx(K.MdFullscreen,{})})]})]})}),Je=a.memo(({onItemClick:o})=>{const[n]=G();return e.jsxs(e.Fragment,{children:[e.jsx(Ze,{open:n,onItemClick:o}),e.jsx(Qe,{open:n,onItemClick:o})]})}),je=a.memo(({contextText:o="",startOffset:n=0,text:s,cfi:l="#",onClick:r,absolutePageIndex:i})=>{const h=o.substring(Math.max(n-15,0),Math.max(n,0)),u=o.substring(Math.min(n+s.length,o.length-1),Math.min(n+s.length+15,o.length-1));return e.jsxs(t.Link,{href:l,style:{margin:5,overflow:"hidden"},onClick:c=>{c.preventDefault(),r(l)},display:"flex",flexDirection:"column",alignItems:"flex-start",gap:0,children:[e.jsxs(t.Text,{lineClamp:1,as:"cite",style:{display:"block"},children:['"',h,e.jsx("b",{children:s}),u,'"']}),e.jsx(t.Text,{fontSize:"sm",color:"gray.500",style:{textDecoration:"none"},children:`Book page: ${i!==void 0?i+1:"unknown (not loaded)"}`})]})}),Re=a.memo(({onNavigate:o})=>{const[n,s]=a.useState(""),l=k(),r=X(l)?l:void 0,i=f=>{s(f.target.value)},d=a.useCallback(f=>{o(),l==null||l.navigation.goToCfi(f)},[l,o]),h=p.useObserve(()=>r==null?void 0:r.search.search(n).pipe(g.map(f=>({type:"end",data:f})),g.startWith({type:"start"})),[l,n]),u=(h==null?void 0:h.type)==="start",c=(h==null?void 0:h.type)==="end"?h.data:[],v=p.useObserve(()=>l==null?void 0:l.locateResource(c.slice(0,100)),[c]);return e.jsxs(t.Stack,{flex:1,height:"100%",children:[e.jsx(t.Box,{px:4,children:e.jsx(t.Input,{placeholder:"Type something...",value:n,onChange:i,borderRadius:0})}),e.jsxs(t.Box,{px:4,pb:4,mt:2,flex:1,style:{overflow:"hidden",overflowY:"auto"},children:[u&&e.jsx(t.Text,{children:"Searching ..."}),!u&&c.length===0&&e.jsx("p",{children:"There are no results"}),!u&&c.length>=0&&e.jsxs(t.Stack,{children:[e.jsxs(t.Heading,{as:"h2",size:"md",children:[c.length," result(s)"]}),e.jsx(t.Stack,{gap:0,children:v==null?void 0:v.map((f,T)=>{var I,y,x,P,S,H,oe;return e.jsx(je,{contextText:((x=(y=(I=f.meta)==null?void 0:I.range)==null?void 0:y.startContainer.parentElement)==null?void 0:x.textContent)??"",pageIndex:(P=f.meta)==null?void 0:P.itemPageIndex,startOffset:((H=(S=f.meta)==null?void 0:S.range)==null?void 0:H.startOffset)??0,text:n,cfi:f.meta.cfi,onClick:d,absolutePageIndex:(oe=f.meta)==null?void 0:oe.absolutePageIndex},T)})})]})]})]})}),eo=a.memo(({open:o,setOpen:n,onNavigate:s})=>e.jsx(D,{lazyMount:!0,placement:"center",open:o,onOpenChange:l=>n(l.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:e.jsxs(O,{height:"100%",children:[e.jsx(E,{children:e.jsx(L,{children:"Search"})}),e.jsx(z,{flex:1,children:e.jsx(Re,{onNavigate:s})}),e.jsx(A,{children:e.jsx(M,{asChild:!0,children:e.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),e.jsx(m,{})]})})),oo=a.memo(({onNavigate:o})=>{const n=k(),{manifest:s,assumedRenditionLayout:l}=p.useObserve(()=>n==null?void 0:n.context.state$,[n])??{},{nav:r}=s??{},i=B();r!=null&&r.toc;const{beginSpineItemIndex:d,beginPageIndexInSpineItem:h}=i??{},u=(l==="reflowable"?h:d)||0;let c=i==null?void 0:i.beginChapterInfo;for(;c!=null&&c.subChapter;)c=c==null?void 0:c.subChapter;const v=(f,T,I)=>e.jsxs(a.Fragment,{children:[e.jsx(t.List.Item,{pl:4*(I+1),style:{display:"flex",alignItems:"center"},children:e.jsxs(t.Link,{onClick:()=>{o(),n==null||n.navigation.goToUrl(f.href)},href:"#",children:[(c==null?void 0:c.path)===f.path&&e.jsx(t.List.Indicator,{asChild:!0,children:e.jsx(C.LuCircleCheck,{})}),(c==null?void 0:c.path)!==f.path&&e.jsx(t.List.Indicator,{asChild:!0,visibility:"hidden",children:e.jsx(C.LuCircleCheck,{})}),e.jsxs(t.Stack,{gap:0,children:[e.jsx(t.Text,{fontSize:"md",children:f.title||f.path}),(c==null?void 0:c.path)===f.path&&e.jsx(t.Text,{fontStyle:"italic",fontWeight:"bold",fontSize:"sm",children:`Currently on page ${u+1}`})]})]})}),f.contents.length>0&&e.jsx(t.List.Root,{as:"div",gap:2,children:f.contents.map((y,x)=>v(y,x,I+1))})]},T);return e.jsx(t.List.Root,{gap:3,overflowY:"auto",py:4,flex:1,children:r==null?void 0:r.toc.map((f,T)=>v(f,T,0))})}),no=a.memo(({open:o,setOpen:n,onNavigate:s})=>e.jsx(D,{lazyMount:!0,placement:"center",open:o,onOpenChange:l=>n(l.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:e.jsxs(O,{children:[e.jsx(E,{children:e.jsx(L,{children:"Table of Contents"})}),e.jsx(z,{overflowY:"auto",flex:1,children:e.jsx(oo,{onNavigate:s})}),e.jsx(A,{children:e.jsx(M,{asChild:!0,children:e.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),e.jsx(m,{})]})})),so=({enableFloatingTime:o=!0,enableFloatingProgress:n=!0,onItemClick:s})=>{const[l,r]=a.useState(!1),[i,d]=a.useState(!1),[h,u]=a.useState(!1),[c,v]=a.useState(void 0),[f,T]=a.useState(!1),[I,y]=G(),x=a.useCallback(()=>{r(!1),d(!1),u(!1),v(void 0),y(!1),T(!1)},[y]),P=a.useCallback(S=>{S==="annotations"?v("annotations"):S==="search"?u(!0):S==="help"?d(!0):S==="toc"?r(!0):S==="bookmarks"?v("bookmarks"):S==="gallery"&&T(!0),s==null||s(S)},[s]);return Le(),$e(),e.jsxs(e.Fragment,{children:[n&&e.jsx(t.Presence,{present:!I,animationName:{_open:"fade-in",_closed:"fade-out"},animationDuration:"moderate",children:e.jsx(De,{})}),e.jsx(we,{open:f,setOpen:T}),e.jsx(Je,{onItemClick:P}),e.jsx(Ce,{}),e.jsx(me,{open:i,setOpen:d}),e.jsx(no,{open:l,setOpen:r,onNavigate:x}),e.jsx(eo,{open:h,setOpen:u,onNavigate:x}),e.jsx(fe,{openWith:c,setOpen:S=>v(S?"annotations":void 0),onNavigate:x}),e.jsx(t.Presence,{present:o||I,animationName:{_open:"fade-in",_closed:"fade-out"},animationDuration:"slow",overflow:"hidden",children:e.jsx(ze,{})}),e.jsx(Te,{})]})};b.BOOKMARK_AREA_DATA_ATTRIBUTE=j,b.ReactReader=so,b.ReactReaderProvider=ie,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
1
+ (function(b,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("react"),require("reactjrx"),require("rxjs"),require("@chakra-ui/react"),require("react-icons/lu"),require("react-dom"),require("@prose-reader/enhancer-gestures"),require("@prose-reader/core"),require("react-icons/bs"),require("react-icons/ri"),require("react-icons/rx"),require("react-icons/hi"),require("rc-slider"),require("rc-slider/assets/index.css"),require("react-icons/io"),require("react-icons/md")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","reactjrx","rxjs","@chakra-ui/react","react-icons/lu","react-dom","@prose-reader/enhancer-gestures","@prose-reader/core","react-icons/bs","react-icons/ri","react-icons/rx","react-icons/hi","rc-slider","rc-slider/assets/index.css","react-icons/io","react-icons/md"],o):(b=typeof globalThis<"u"?globalThis:b||self,o(b["prose-react-reader"]={},b.jsxRuntime,b.React,b.reactjrx,b.rxjs,b.react,b.lu,b.reactDom,b.enhancerGestures,b.core,b.bs,b.ri,b.rx,b.hi,b.RcSlider,null,b.io,b.md))})(this,function(b,o,a,u,g,t,I,ee,oe,q,ne,se,N,te,re,ro,U,Y){"use strict";function le(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(n,s,r.get?r:{enumerable:!0,get:()=>e[s]})}}return n.default=e,Object.freeze(n)}const w=le(a),K=a.createContext({reader:void 0,quickMenuSignal:u.signal({default:!1}),notificationsSubject:new g.Subject}),ie=a.memo(({children:e,reader:n,quickMenuOpen:s,onQuickMenuOpenChange:r})=>{const[,l]=u.useSignalState(()=>u.signal({default:s})),i=u.useConstant(()=>new g.Subject),h=u.useLiveRef(r),c=a.useMemo(()=>({quickMenuSignal:l,reader:n,notificationsSubject:i}),[l,n,i]);return a.useEffect(()=>{l.setValue(s)},[s,l]),u.useSubscribe(()=>l.pipe(g.tap(h.current)),[l,h]),o.jsx(K.Provider,{value:c,children:e})}),ae=w.forwardRef(function(n,s){return o.jsx(t.IconButton,{variant:"ghost","aria-label":"Close",ref:s,...n,children:n.children??o.jsx(I.LuX,{})})}),m=w.forwardRef(function(n,s){const{children:r,portalled:l=!0,portalRef:i,backdrop:h=!0,...c}=n;return o.jsxs(t.Portal,{disabled:!l,container:i,children:[h&&o.jsx(t.Dialog.Backdrop,{}),o.jsx(t.Dialog.Positioner,{children:o.jsx(t.Dialog.Content,{ref:s,...c,asChild:!1,children:r})})]})}),B=w.forwardRef(function(n,s){return o.jsx(t.Dialog.CloseTrigger,{position:"absolute",top:"2",insetEnd:"2",...n,asChild:!0,children:o.jsx(ae,{size:"sm",ref:s,children:n.children})})}),D=t.Dialog.Root,A=t.Dialog.Footer,E=t.Dialog.Header,L=t.Dialog.Body;t.Dialog.Backdrop;const M=t.Dialog.Title;t.Dialog.Description,t.Dialog.Trigger;const z=t.Dialog.ActionTrigger,_=()=>a.useContext(K),v=()=>{const{reader:e}=_();return e},Q=e=>!!e&&"__PROSE_READER_ENHANCER_SEARCH"in e,$=e=>!!e&&"__PROSE_READER_ENHANCER_ANNOTATIONS"in e,Z=e=>!!e&&"__PROSE_READER_ENHANCER_GALLERY"in e,ce=e=>{const n=v(),s=$(n)?n:void 0;return{data:u.useObserve(()=>s==null?void 0:s.annotations.annotations$.pipe(g.map(l=>l.find(i=>i.id===e)),g.filter(u.isDefined),g.switchMap(l=>s.locateResource(l))),[s])}},X=({id:e,onNavigate:n})=>{var l,i;const s=v(),{data:r}=ce(e);return o.jsx(t.List.Item,{children:o.jsxs(t.Link,{href:"#",onClick:()=>{n(),s==null||s.navigation.goToCfi((r==null?void 0:r.meta.cfi)??"")},children:[(l=r==null?void 0:r.resource)!=null&&l.notes?o.jsx(t.List.Indicator,{asChild:!0,children:o.jsx(I.LuNotebookPen,{})}):o.jsx(t.List.Indicator,{asChild:!0,visibility:"hidden",children:o.jsx(I.LuNotebookPen,{})}),o.jsxs(t.Stack,{gap:0,children:[o.jsx(t.Text,{lineClamp:2,fontSize:"md",children:r!=null&&r.meta.range?r==null?void 0:r.meta.range.toString():o.jsx("i",{children:o.jsx("b",{children:"unknown (not loaded)"})})}),o.jsx(t.Text,{fontStyle:"italic",fontWeight:"bold",fontSize:"sm",children:`Book page: ${((i=r==null?void 0:r.meta)==null?void 0:i.absolutePageIndex)!==void 0?r.meta.absolutePageIndex+1:"unknown (not loaded)"}`})]})]})})},F=()=>{const e=v(),n=$(e)?e:void 0;return{data:u.useObserve(()=>n==null?void 0:n.annotations.annotations$.pipe(g.switchMap(r=>n.locateResource(r))),[n])}},de=({onNavigate:e})=>{const{data:n}=F();return o.jsx(t.List.Root,{overflowY:"auto",gap:3,pt:4,variant:"plain",children:n==null?void 0:n.map(s=>o.jsx(X,{id:s.resource.id,onNavigate:e},s.resource.id))})},he=()=>{const{data:e}=F();return{data:e==null?void 0:e.filter(n=>!n.meta.range)}},ge=({onNavigate:e})=>{const{data:n}=he();return o.jsx(t.List.Root,{overflowY:"auto",gap:3,pt:4,variant:"plain",children:n==null?void 0:n.map(s=>o.jsx(X,{id:s.resource.id,onNavigate:e},s.resource.id))})},pe=a.memo(({onNavigate:e,defaultTab:n})=>{const[s,r]=a.useState(n??"bookmarks");return o.jsxs(t.Tabs.Root,{value:s,onValueChange:l=>r(l.value),children:[o.jsxs(t.Tabs.List,{children:[o.jsxs(t.Tabs.Trigger,{value:"bookmarks",children:[o.jsx(I.LuBookmark,{}),"Bookmarks"]}),o.jsxs(t.Tabs.Trigger,{value:"annotations",children:[o.jsx(I.LuNotebookPen,{}),"Annotations"]}),o.jsx(t.Tabs.Indicator,{})]}),o.jsx(t.Tabs.Content,{value:"bookmarks",children:o.jsx(ge,{onNavigate:e})}),o.jsx(t.Tabs.Content,{value:"annotations",children:o.jsx(de,{onNavigate:e})})]})}),fe=a.memo(({openWith:e,setOpen:n,onNavigate:s})=>o.jsx(D,{lazyMount:!0,placement:"center",open:!!e,onOpenChange:r=>n(r.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:o.jsxs(m,{height:"100%",children:[o.jsx(E,{children:o.jsx(M,{children:"Annotations"})}),o.jsx(L,{flex:1,children:o.jsx(pe,{onNavigate:s,defaultTab:e})}),o.jsx(A,{children:o.jsx(z,{asChild:!0,children:o.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),o.jsx(B,{})]})})),ue=a.memo(({children:e})=>{const n=v(),s=u.useObserve(()=>n==null?void 0:n.spine.element$,[n]);return s?o.jsx(o.Fragment,{children:ee.createPortal(e,s)}):null}),be=({absolutePageIndex:e,itemIndex:n})=>{const s=v(),r=u.useObserve(()=>s==null?void 0:s.spine.spineItemsManager.items$,[s]);return{spineItem:a.useMemo(()=>{if(n!==void 0)return s==null?void 0:s.spine.spineItemsManager.get(n);if(e!==void 0){const{itemIndex:i}=(s==null?void 0:s.spine.locator.getSpineInfoFromAbsolutePageIndex({absolutePageIndex:e}))??{};return s==null?void 0:s.spine.spineItemsManager.get(i)}},[n,e,s,r])}},ve=({absolutePageIndex:e,itemIndex:n})=>{const{spineItem:s}=be({absolutePageIndex:e,itemIndex:n});return u.useObserve(()=>(s==null?void 0:s.isReady$)??g.of(!1),[s])},J="data-bookmark-area",Se=a.memo(({absolutePageIndex:e,left:n,top:s,width:r})=>{const l=ve({absolutePageIndex:e}),{data:i}=F(),h=i==null?void 0:i.find(f=>{var d;return((d=f==null?void 0:f.meta)==null?void 0:d.absolutePageIndex)===e&&f.meta.range===void 0});if(!l)return null;const c=r*.1/2;return o.jsx(t.Presence,{present:!!h,lazyMount:!0,animationName:{_open:"fade-in",_closed:"fade-out"},animationDuration:"moderate",children:o.jsx(t.Box,{"data-bookmark-area":J,position:"absolute",left:n+r,transform:"translateX(-100%)",pointerEvents:"none",top:s,width:c,height:c,_before:{content:'""',position:"absolute",top:0,left:0,width:0,height:0,borderTop:`${c}px solid #03030373`,borderLeft:`${c}px solid transparent`}})})}),Te=a.memo(()=>{const e=v(),n=u.useObserve(()=>e==null?void 0:e.layoutInfo$,[e]);return o.jsx(ue,{children:n==null?void 0:n.pages.map(({absoluteLayout:{left:s,top:r,width:l}},i)=>o.jsx(Se,{absolutePageIndex:i,left:s,top:r,width:l},i))})}),Ce=()=>{const e=v();return $(e)?e:void 0},Ie=()=>{const e=Ce(),{data:n}=F();a.useEffect(()=>e?e.gestures.hooks.register("beforeTapGesture",({event$:r})=>r.pipe(g.withLatestFrom(e==null?void 0:e.annotations.candidates$),g.map(([l,i])=>{if(!l.page)return!0;const{spineItem:h,spineItemPageIndex:c,spineItemPagePosition:f,pageSize:d}=l.page;if(oe.isPositionInArea(f,{type:"corner",corner:"top-right",size:10,unit:"%"},d)){const p=e.spine.pages.fromSpineItemPageIndex(h,c);if(!p)return!0;const T=n==null?void 0:n.find(k=>{var y;return((y=k==null?void 0:k.meta)==null?void 0:y.absolutePageIndex)===p.absolutePageIndex&&k.meta.range===void 0});if(T)return e==null||e.annotations.delete(T.resource.id),!1;if(i==null?void 0:i[p.absolutePageIndex])return e==null||e.annotations.annotateAbsolutePage({absolutePageIndex:p.absolutePageIndex}),!1}return!0}))):void 0,[e,n])},W=t.createToaster({placement:"bottom-end",pauseOnPageIdle:!0}),ke=()=>o.jsx(t.Portal,{children:o.jsx(t.Toaster,{toaster:W,insetInline:{mdDown:"4"},children:e=>{var n;return o.jsxs(t.Toast.Root,{width:{md:"sm"},children:[e.type==="loading"?o.jsx(t.Spinner,{size:"sm",color:"blue.solid"}):o.jsx(t.Toast.Indicator,{}),o.jsxs(t.Stack,{gap:"1",flex:"1",maxWidth:"100%",children:[e.title&&o.jsx(t.Toast.Title,{children:e.title}),e.description&&o.jsx(t.Toast.Description,{children:e.description})]}),e.action&&o.jsx(t.Toast.ActionTrigger,{children:e.action.label}),((n=e.meta)==null?void 0:n.closable)&&o.jsx(t.Toast.CloseTrigger,{})]})}})}),Pe={x:0,y:0,width:0,height:0,top:0,left:0,bottom:0,right:0};function ye(){const[e,n]=a.useState(null),[s,r]=a.useState(Pe),l=a.useMemo(()=>new ResizeObserver(i=>{if(i[0]){const{x:h,y:c,width:f,height:d,top:S,left:p,bottom:T,right:P}=i[0].contentRect;r({x:h,y:c,width:f,height:d,top:S,left:p,bottom:T,right:P})}}),[]);return a.useLayoutEffect(()=>{if(e)return l.observe(e),()=>{l.disconnect()}},[e,l]),[n,s,e]}const xe=(e,n,s)=>{const r=v(),l=Z(r)?r:void 0;u.useSubscribe(()=>{if(!l||!e)return g.NEVER;const i=n.layout.layout$.pipe(g.startWith(n.layout.layoutInfo),g.distinctUntilChanged(q.isShallowEqual)),h=q.observeIntersection(e).pipe(g.map(c=>c.some(f=>f.isIntersecting)));return i.pipe(g.throttleTime(100,void 0,{trailing:!0}),g.switchMap(()=>h.pipe(g.tap(c=>{c||(e.innerHTML="")}),g.filter(c=>c),g.first()).pipe(g.switchMap(()=>(e.innerHTML="",l==null?void 0:l.gallery.snapshot(n,e,s))))))},[l,n,s,e])},we=a.memo(({item:e,onNavigated:n})=>{var c;const[s,r,l]=ye(),i=v();xe(l,e,r);const h=u.useObserve(()=>i==null?void 0:i.locateResource(e,{mode:"shallow"}),[i,e]);return o.jsxs(t.Box,{width:"100%",aspectRatio:"2/3",border:"1px solid",borderColor:"border",borderRadius:"md","data-grid-item":!0,cursor:"pointer",position:"relative",overflow:"hidden",onClick:()=>{n(),i==null||i.navigation.goToSpineItem({indexOrId:e})},children:[o.jsx(t.Box,{height:"100%",width:"100%",overflow:"hidden",pointerEvents:"none",ref:s}),o.jsxs(t.Text,{position:"absolute",bottom:0,left:"0",right:"0",textAlign:"center",bgColor:"white",p:4,fontSize:"xs",children:["Page ",(((c=h==null?void 0:h.meta)==null?void 0:c.absolutePageIndex)??0)+1]})]})}),Oe=a.memo(({open:e,setOpen:n})=>{const s=v(),r=u.useObserve(()=>s==null?void 0:s.spineItemsManager.items$,[s]);return o.jsx(D,{lazyMount:!0,placement:"center",open:e,onOpenChange:l=>n(l.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:o.jsxs(m,{height:"100%",children:[o.jsx(E,{children:o.jsx(M,{children:"Gallery"})}),o.jsx(L,{children:o.jsx(t.Box,{gridTemplateColumns:["repeat(2, minmax(0, 1fr))","repeat(3, minmax(0, 1fr))"],display:"grid",gap:[2,4],pt:2,"data-grid":!0,children:r==null?void 0:r.map(l=>o.jsx(we,{item:l,onNavigated:()=>{n(!1)}},l.item.id))})}),o.jsx(A,{children:o.jsx(z,{asChild:!0,children:o.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),o.jsx(B,{})]})})}),me="@prose-reader/react-reader",Be="1.230.0",De=a.memo(({open:e,setOpen:n})=>o.jsx(D,{lazyMount:!0,placement:"center",open:e,onOpenChange:s=>n(s.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:o.jsxs(m,{children:[o.jsx(E,{children:o.jsx(M,{children:"Help"})}),o.jsxs(L,{overflowY:"auto",flex:1,children:[o.jsx(t.Heading,{mb:2,as:"h3",size:"lg",children:"Shortcuts"}),o.jsxs(t.HStack,{mb:1,children:[o.jsx(t.Kbd,{children:o.jsx(I.LuArrowBigRight,{})})," ",o.jsx(t.Text,{children:"Navigate to right page"})]}),o.jsxs(t.HStack,{mb:1,children:[o.jsx(t.Kbd,{children:o.jsx(I.LuArrowBigLeft,{})})," ",o.jsx(t.Text,{children:"Navigate to left page"})]}),o.jsx(t.Heading,{mb:2,mt:4,as:"h3",size:"lg",children:"About"}),o.jsxs(t.Text,{children:[me," version: ",Be]})]}),o.jsx(A,{children:o.jsx(z,{asChild:!0,children:o.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),o.jsx(B,{})]})})),O=()=>{const e=v();return u.useObserve(()=>e?g.combineLatest([e.pagination.state$,e.context.state$]).pipe(g.map(([n,s])=>{var l;const r=(l=s.manifest)==null?void 0:l.spineItems.every(i=>{var h;return(h=i.mediaType)==null?void 0:h.startsWith("image/")});return{...n,hasChapters:!s.isFullyPrePaginated&&!r}})):g.NEVER,[e])},Ae=()=>{const e=O(),n=Math.floor(((e==null?void 0:e.percentageEstimateOfBook)??0)*100),s=n>0?n:1;return(e==null?void 0:e.percentageEstimateOfBook)===void 0?null:o.jsx(t.Box,{position:"absolute",right:0,bottom:0,p:2,color:"black",children:o.jsxs(t.Text,{fontSize:"sm",children:[s," %"]})})},Ee=()=>{const[e,n]=a.useState(new Date);return a.useEffect(()=>{const s=setInterval(()=>{n(new Date)},6e4);return()=>clearInterval(s)},[]),e},Le=e=>{const n=Ee();return o.jsx(t.Text,{fontSize:"xs",...e,children:n.toLocaleTimeString(navigator.language,{hour:"2-digit",minute:"2-digit"})})},G=()=>{const{quickMenuSignal:e}=_();return[u.useSignalValue(e),e.setValue,e]},Me=()=>{const[e]=G();return o.jsx(t.Box,{position:"absolute",left:0,bottom:0,p:2,color:e?void 0:"colorPalette.contrast",children:o.jsx(Le,{})})},ze=()=>{const e=v();u.useSubscribe(()=>e==null?void 0:e.links$.subscribe(n=>{if(n.type==="click"&&q.isHtmlTagElement(n.target,"a")){if(!n.target.href)return;const s=new URL(n.target.href);window.location.host!==s.host&&confirm("You are going to be redirected to external link")&&window.open(n.target.href,"__blank")}}),[e])},_e=()=>{const e=v(),{notificationsSubject:n}=_();u.useSubscribe(()=>e==null?void 0:e.zoom.isZooming$.pipe(g.switchMap(s=>{if(!s)return g.EMPTY;const r=new g.Subject;return n.next({key:"zoom",title:"Zooming",duration:999999,abort:r}),g.NEVER.pipe(g.finalize(()=>{r.next(),r.complete()}))})),[e])},$e=()=>{const e=v(),{notificationsSubject:n}=_();u.useSubscribe(()=>e==null?void 0:e.settings.values$.pipe(g.map(({fontScale:s})=>s),g.distinctUntilChanged(),g.skip(1),g.tap(s=>{n.next({key:"fontScaleChange",title:"Font size changed",description:`${s*100} %`})})),[e,n])},He=()=>{const{notificationsSubject:e}=_();$e(),_e(),u.useSubscribe(()=>e.pipe(g.filter(u.isDefined),g.mergeMap(n=>{const s=n.duration??3e3,r=W.create({title:n.title,description:n.description,duration:s}),l=e.pipe(g.skip(1),g.filter(i=>!!n.key&&(i==null?void 0:i.key)===n.key));return g.merge(g.timer(s),n.abort??g.NEVER,l).pipe(g.first(),g.finalize(()=>{W.dismiss(r)}))})),[e])},Ne=w.forwardRef(function(n,s){const{showArrow:r,children:l,portalled:i=!0,content:h,portalRef:c,...f}=n;return o.jsxs(t.Popover.Root,{...f,positioning:{...f.positioning,gutter:4},children:[o.jsx(t.Popover.Trigger,{asChild:!0,children:l}),o.jsx(t.Portal,{disabled:!i,container:c,children:o.jsx(t.Popover.Positioner,{children:o.jsxs(t.Popover.Content,{width:"auto",px:"2",py:"1",textStyle:"xs",rounded:"sm",ref:s,children:[r&&o.jsx(t.Popover.Arrow,{children:o.jsx(t.Popover.ArrowTip,{})}),h]})})})]})}),Fe=w.forwardRef(function(n,s){const{children:r,...l}=n;return o.jsx(Ne,{content:r,...l,ref:s,children:o.jsx(t.IconButton,{variant:"ghost","aria-label":"info",size:"2xs",colorPalette:"gray",children:o.jsx(te.HiOutlineInformationCircle,{})})})}),qe=w.forwardRef(function(n,s){return o.jsx(t.Progress.Track,{...n,ref:s,children:o.jsx(t.Progress.Range,{})})});w.forwardRef(function(n,s){const{children:r,info:l,...i}=n;return o.jsxs(t.Progress.Label,{...i,ref:s,children:[r,l&&o.jsx(Fe,{children:l})]})});const We=t.Progress.Root,Ge=t.Progress.ValueText,V=()=>{const e=O(),n=(e==null?void 0:e.numberOfTotalPages)===1,s=((e==null?void 0:e.beginNumberOfPagesInSpineItem)??0)>1,r=((e==null?void 0:e.endNumberOfPagesInSpineItem)??0)>1,l=(e!=null&&e.hasChapters?e==null?void 0:e.beginPageIndexInSpineItem:e==null?void 0:e.beginAbsolutePageIndex)??0,i=(e!=null&&e.hasChapters?e==null?void 0:e.endPageIndexInSpineItem:e==null?void 0:e.endAbsolutePageIndex)??0,[h=0,c=0]=[l,i].sort((S,p)=>S-p),f=(e==null?void 0:e.beginPageIndexInSpineItem)!==(e==null?void 0:e.endPageIndexInSpineItem)||(e==null?void 0:e.beginSpineItemIndex)!==(e==null?void 0:e.endSpineItemIndex),d=e!=null&&e.hasChapters?e==null?void 0:e.beginNumberOfPagesInSpineItem:e==null?void 0:e.numberOfTotalPages;return{hasOnlyOnePage:n,beginPageIndex:l,endPageIndex:i,isBeginWithinChapter:s,isEndWithinChapter:r,beginAndEndAreDifferent:f,totalApproximatePages:d,leftPageIndex:h,rightPageIndex:c}},Ve=()=>{const e=O(),{hasOnlyOnePage:n,leftPageIndex:s,rightPageIndex:r,totalApproximatePages:l,beginAndEndAreDifferent:i}=V(),h=Math.round(((e==null?void 0:e.percentageEstimateOfBook)??0)*100),c=d=>d!=null&&d.subChapter?`${d.title} / ${c(d.subChapter)}`:(d==null?void 0:d.title)||"",f=c(e==null?void 0:e.beginChapterInfo);return o.jsxs(t.Stack,{alignItems:"center",gap:1,maxW:"100%",overflow:"auto",children:[o.jsx(We,{value:h,size:"xs",width:150,children:o.jsxs(t.HStack,{justifyContent:"space-between",children:[o.jsx(qe,{width:110}),o.jsx(Ge,{children:`${h}%`})]})}),o.jsx(t.Text,{truncate:!0,maxWidth:"100%",fontSize:"sm",mt:1,children:f?`Chapter: ${f}`:" "}),!n&&o.jsxs(t.HStack,{children:[o.jsx(t.Text,{fontSize:"xs",children:i?`${s+1} - ${r+1} of ${l}`:`${s+1} of ${l}`}),!!(e!=null&&e.hasChapters)&&o.jsxs(o.Fragment,{children:[o.jsx(t.Text,{children:"-"}),o.jsxs(t.Text,{fontSize:"xs",children:["(",((e==null?void 0:e.beginAbsolutePageIndex)??0)+1,")"]})]})]})]})},j=a.memo(({children:e,position:n,...s})=>o.jsx(t.Presence,{display:"flex",flexDirection:"row",width:"100%",position:"absolute",...n==="bottom"?{bottom:0}:{top:0},animationName:n==="bottom"?{_open:"slide-from-bottom, fade-in",_closed:"slide-to-bottom, fade-out"}:{_open:"slide-from-top, fade-in",_closed:"slide-to-top, fade-out"},animationDuration:"moderate",bgColor:"bg.panel",alignItems:"center",justifyContent:"center",shadow:"md",p:4,...s,children:e})),Ue=t.chakra(re),Ye=a.memo(e=>o.jsx(t.Box,{display:"contents",css:{"--bg":"colors.bg","--bg-emphasized":"colors.bg.emphasized","--color-solid":"colors.colorPalette.solid"},children:o.jsx(Ue,{keyboard:!1,style:{padding:0},css:{"& > .rc-slider-handle:focus-visible":{boxShadow:"0 0 0 2px var(--color-solid) !important"},"& > .rc-slider-handle:active":{boxShadow:"0 0 5px var(--color-solid) !important"},"& > .rc-slider-handle.rc-slider-handle-dragging":{boxShadow:"0 0 0 3px var(--color-solid) !important"}},styles:{rail:{height:"8px",top:"50%",transform:"translateY(-50%)",backgroundColor:"var(--bg-emphasized)"},track:{height:"8px",top:"50%",transform:"translateY(-50%)",backgroundColor:"var(--color-solid)"},handle:{width:"24px",height:"24px",top:"50%",borderColor:"var(--color-solid)",transform:`translate(${e.reverse?"50%":"-50%"}, -50%)`,backgroundColor:"var(--bg)",marginTop:"0px"}},...e})})),Ke=()=>{const e=O(),n=e==null?void 0:e.isUsingSpread,{beginPageIndex:s,totalApproximatePages:r=0}=V(),l=n?Math.floor((s||0)/2):s,[i,h]=u.useSignalState(()=>u.signal({default:l||0})),c=0,f=Math.max(0,n?Math.floor((r-1)/2):r-1);return a.useEffect(()=>{h.update(l||0)},[l,h]),{value:i,valueSignal:h,min:c,max:f}},Qe=e=>{const n=v(),s=O(),{manifest:r}=u.useObserve(()=>n==null?void 0:n.context.state$,[n])??{},l=(r==null?void 0:r.readingDirection)==="rtl",i=s==null?void 0:s.isUsingSpread,{totalApproximatePages:h=0,isBeginWithinChapter:c}=V(),f=1,d=c,{value:S,valueSignal:p,min:T,max:P}=Ke(),k=a.useCallback(x=>{const[C=0]=Array.isArray(x)?x:[x];p.setValue(C);const H=i?Math.floor(C)*2:Math.floor(C);d?n==null||n.navigation.goToPageOfSpineItem({pageIndex:H,spineItemId:n.pagination.state.beginSpineItemIndex??0,animation:!1}):n==null||n.navigation.goToAbsolutePageIndex({absolutePageIndex:H,animation:!1})},[n,i,p,d]);return u.useSubscribe(()=>n==null?void 0:n.navigation.throttleLock({duration:100,trigger:p.subject}),[n,p]),h===1||i&&h===2?o.jsx(t.Box,{style:e.style}):o.jsx(Ye,{value:[S],max:P,min:T,reverse:l,step:f,onChange:k,...e})},Ze=a.memo(({open:e,onItemClick:n})=>{const s=v(),r=u.useObserve(()=>s==null?void 0:s.navigation.state$,[s]),l=u.useObserve(()=>s==null?void 0:s.settings.values$,[s]),i=(l==null?void 0:l.computedPageTurnDirection)==="vertical",[h,c]=a.useState(!0);return o.jsxs(j,{present:e,position:"bottom",display:"flex",flexDirection:"column",overflow:"auto",pb:8,children:[o.jsxs(t.HStack,{flex:1,alignItems:"center",justifyContent:"center",maxWidth:"100%",children:[o.jsx(t.IconButton,{"aria-label":"left",size:"lg",variant:"ghost",flexShrink:0,onClick:()=>s==null?void 0:s.navigation.goToLeftOrTopSpineItem(),disabled:!(r!=null&&r.canGoLeftSpineItem)&&!(r!=null&&r.canGoTopSpineItem),children:i?o.jsx(N.RxDoubleArrowUp,{}):o.jsx(N.RxDoubleArrowLeft,{})}),o.jsxs(t.Stack,{flex:1,maxW:400,gap:2,alignItems:"center",overflow:"auto",px:4,children:[o.jsx(Ve,{}),o.jsx(Qe,{style:{width:"100%",maxWidth:"300px",height:"35px"}})]}),o.jsx(t.IconButton,{"aria-label":"right",size:"lg",flexShrink:0,variant:"ghost",disabled:!(r!=null&&r.canGoRightSpineItem)&&!(r!=null&&r.canGoBottomSpineItem),onClick:()=>{s==null||s.navigation.goToRightOrBottomSpineItem()},children:i?o.jsx(N.RxDoubleArrowDown,{}):o.jsx(N.RxDoubleArrowRight,{})})]}),o.jsx(t.HStack,{alignSelf:"stretch",alignItems:"center",justifyContent:"center",children:o.jsxs(t.Collapsible.Root,{open:h,flex:1,onOpenChange:({open:f})=>{c(f)},children:[o.jsx(t.Collapsible.Trigger,{paddingY:"3",width:"100%",display:"flex",justifyContent:"center",children:o.jsx(I.LuChevronDown,{style:{transform:h?"rotate(0deg)":"rotate(180deg)"}})}),o.jsxs(t.Collapsible.Content,{display:"flex",justifyContent:"center",children:[o.jsx(t.IconButton,{"aria-label":"Help",size:"lg",variant:"ghost",onClick:()=>n("help"),children:o.jsx(I.LuCircleHelp,{})}),o.jsx(t.IconButton,{"aria-label":"Table of contents",size:"lg",variant:"ghost",onClick:()=>n("toc"),children:o.jsx(I.LuTableOfContents,{})}),Q(s)&&o.jsx(t.IconButton,{"aria-label":"Search",size:"lg",variant:"ghost",onClick:()=>n("search"),children:o.jsx(I.LuSearch,{})}),$(s)&&o.jsx(t.IconButton,{"aria-label":"Bookmarks",size:"lg",variant:"ghost",onClick:()=>n("bookmarks"),children:o.jsx(ne.BsBookmarks,{})}),$(s)&&o.jsx(t.IconButton,{"aria-label":"Annotations",size:"lg",variant:"ghost",onClick:()=>n("annotations"),children:o.jsx(I.LuNotebookPen,{})}),o.jsx(t.IconButton,{"aria-label":"Thumbnails",size:"lg",variant:(s==null?void 0:s.settings.values.viewportMode)==="thumbnails"?"solid":"ghost",onClick:()=>{s==null||s.settings.update({viewportMode:(s==null?void 0:s.settings.values.viewportMode)==="normal"?"thumbnails":"normal"})},children:o.jsx(I.LuGalleryHorizontal,{})}),Z(s)&&o.jsx(t.IconButton,{"aria-label":"Gallery",size:"lg",variant:"ghost",onClick:()=>n("gallery"),children:o.jsx(se.RiGalleryView2,{})})]})]})})]})}),Xe=()=>{const[e,n]=a.useState(!1),s=a.useCallback(()=>document.fullscreenElement?document.exitFullscreen().catch(console.error).then(()=>{n(!1)}):document.documentElement.requestFullscreen({navigationUI:"hide"}).catch(console.error).then(()=>{n(!0)}),[]);return a.useEffect(()=>{function r(){n(!!document.fullscreenElement)}return document.addEventListener("fullscreenchange",r),()=>{document.removeEventListener("fullscreenchange",r)}},[]),{isFullscreen:e,onToggleFullscreenClick:s}},Je=a.memo(({open:e,onItemClick:n})=>{const s=v(),r=u.useObserve(()=>s==null?void 0:s.context.manifest$,[s]),{isFullscreen:l,onToggleFullscreenClick:i}=Xe();return o.jsxs(j,{present:e,position:"top",height:"80px",justifyContent:"space-between",children:[o.jsx(t.IconButton,{"aria-label":"left",size:"lg",variant:"ghost",flexShrink:0,onClick:()=>n("back"),children:o.jsx(U.IoIosArrowBack,{})}),o.jsx(t.Stack,{flex:1,maxW:600,gap:1,alignItems:"center",overflow:"auto",px:4,children:o.jsx(t.Text,{truncate:!0,maxWidth:"100%",children:r==null?void 0:r.title})}),o.jsxs(t.HStack,{children:[o.jsx(t.IconButton,{"aria-label":"right",size:"lg",flexShrink:0,variant:"ghost",onClick:()=>n("more"),children:o.jsx(U.IoMdMore,{})}),o.jsx(t.IconButton,{"aria-label":"right",size:"lg",flexShrink:0,variant:"ghost",onClick:i,children:l?o.jsx(Y.MdFullscreenExit,{}):o.jsx(Y.MdFullscreen,{})})]})]})}),je=a.memo(({onItemClick:e})=>{const[n]=G();return o.jsxs(o.Fragment,{children:[o.jsx(Je,{open:n,onItemClick:e}),o.jsx(Ze,{open:n,onItemClick:e})]})}),Re=a.memo(({contextText:e="",startOffset:n=0,text:s,cfi:r="#",onClick:l,absolutePageIndex:i})=>{const c=e.substring(Math.max(n-15,0),Math.max(n,0)),f=e.substring(Math.min(n+s.length,e.length-1),Math.min(n+s.length+15,e.length-1));return o.jsxs(t.Link,{href:r,style:{margin:5,overflow:"hidden"},onClick:d=>{d.preventDefault(),l(r)},display:"flex",flexDirection:"column",alignItems:"flex-start",gap:0,children:[o.jsxs(t.Text,{lineClamp:1,as:"cite",style:{display:"block"},children:['"',c,o.jsx("b",{children:s}),f,'"']}),o.jsx(t.Text,{fontSize:"sm",color:"gray.500",style:{textDecoration:"none"},children:`Book page: ${i!==void 0?i+1:"unknown (not loaded)"}`})]})}),eo=a.memo(({onNavigate:e})=>{const[n,s]=a.useState(""),r=v(),l=Q(r)?r:void 0,i=p=>{s(p.target.value)},h=a.useCallback(p=>{e(),r==null||r.navigation.goToCfi(p)},[r,e]),c=u.useObserve(()=>l==null?void 0:l.search.search(n).pipe(g.map(p=>({type:"end",data:p})),g.startWith({type:"start"})),[r,n]),f=(c==null?void 0:c.type)==="start",d=(c==null?void 0:c.type)==="end"?c.data:[],S=u.useObserve(()=>r==null?void 0:r.locateResource(d.slice(0,100)),[d]);return o.jsxs(t.Stack,{flex:1,height:"100%",children:[o.jsx(t.Box,{px:4,children:o.jsx(t.Input,{placeholder:"Type something...",value:n,onChange:i,borderRadius:0})}),o.jsxs(t.Box,{px:4,pb:4,mt:2,flex:1,style:{overflow:"hidden",overflowY:"auto"},children:[f&&o.jsx(t.Text,{children:"Searching ..."}),!f&&d.length===0&&o.jsx("p",{children:"There are no results"}),!f&&d.length>=0&&o.jsxs(t.Stack,{children:[o.jsxs(t.Heading,{as:"h2",size:"md",children:[d.length," result(s)"]}),o.jsx(t.Stack,{gap:0,children:S==null?void 0:S.map((p,T)=>{var P,k,y,x,C,H,R;return o.jsx(Re,{contextText:((y=(k=(P=p.meta)==null?void 0:P.range)==null?void 0:k.startContainer.parentElement)==null?void 0:y.textContent)??"",pageIndex:(x=p.meta)==null?void 0:x.itemPageIndex,startOffset:((H=(C=p.meta)==null?void 0:C.range)==null?void 0:H.startOffset)??0,text:n,cfi:p.meta.cfi,onClick:h,absolutePageIndex:(R=p.meta)==null?void 0:R.absolutePageIndex},T)})})]})]})]})}),oo=a.memo(({open:e,setOpen:n,onNavigate:s})=>o.jsx(D,{lazyMount:!0,placement:"center",open:e,onOpenChange:r=>n(r.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:o.jsxs(m,{height:"100%",children:[o.jsx(E,{children:o.jsx(M,{children:"Search"})}),o.jsx(L,{flex:1,children:o.jsx(eo,{onNavigate:s})}),o.jsx(A,{children:o.jsx(z,{asChild:!0,children:o.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),o.jsx(B,{})]})})),no=a.memo(({onNavigate:e})=>{const n=v(),{manifest:s,assumedRenditionLayout:r}=u.useObserve(()=>n==null?void 0:n.context.state$,[n])??{},{nav:l}=s??{},i=O();l!=null&&l.toc;const{beginSpineItemIndex:h,beginPageIndexInSpineItem:c}=i??{},f=(r==="reflowable"?c:h)||0;let d=i==null?void 0:i.beginChapterInfo;for(;d!=null&&d.subChapter;)d=d==null?void 0:d.subChapter;const S=(p,T,P)=>o.jsxs(a.Fragment,{children:[o.jsx(t.List.Item,{pl:4*(P+1),style:{display:"flex",alignItems:"center"},children:o.jsxs(t.Link,{onClick:()=>{e(),n==null||n.navigation.goToUrl(p.href)},href:"#",children:[(d==null?void 0:d.path)===p.path&&o.jsx(t.List.Indicator,{asChild:!0,children:o.jsx(I.LuCircleCheck,{})}),(d==null?void 0:d.path)!==p.path&&o.jsx(t.List.Indicator,{asChild:!0,visibility:"hidden",children:o.jsx(I.LuCircleCheck,{})}),o.jsxs(t.Stack,{gap:0,children:[o.jsx(t.Text,{fontSize:"md",children:p.title||p.path}),(d==null?void 0:d.path)===p.path&&o.jsx(t.Text,{fontStyle:"italic",fontWeight:"bold",fontSize:"sm",children:`Currently on page ${f+1}`})]})]})}),p.contents.length>0&&o.jsx(t.List.Root,{as:"div",gap:2,children:p.contents.map((k,y)=>S(k,y,P+1))})]},T);return o.jsx(t.List.Root,{gap:3,overflowY:"auto",py:4,flex:1,children:l==null?void 0:l.toc.map((p,T)=>S(p,T,0))})}),so=a.memo(({open:e,setOpen:n,onNavigate:s})=>o.jsx(D,{lazyMount:!0,placement:"center",open:e,onOpenChange:r=>n(r.open),size:{mdDown:"full",md:"lg"},scrollBehavior:"inside",children:o.jsxs(m,{children:[o.jsx(E,{children:o.jsx(M,{children:"Table of Contents"})}),o.jsx(L,{overflowY:"auto",flex:1,children:o.jsx(no,{onNavigate:s})}),o.jsx(A,{children:o.jsx(z,{asChild:!0,children:o.jsx(t.Button,{variant:"outline",children:"Cancel"})})}),o.jsx(B,{})]})})),to=({enableFloatingTime:e=!0,enableFloatingProgress:n=!0,onItemClick:s})=>{const[r,l]=a.useState(!1),[i,h]=a.useState(!1),[c,f]=a.useState(!1),[d,S]=a.useState(void 0),[p,T]=a.useState(!1),[P,k]=G(),y=a.useCallback(()=>{l(!1),h(!1),f(!1),S(void 0),k(!1),T(!1)},[k]),x=a.useCallback(C=>{C==="annotations"?S("annotations"):C==="search"?f(!0):C==="help"?h(!0):C==="toc"?l(!0):C==="bookmarks"?S("bookmarks"):C==="gallery"&&T(!0),s==null||s(C)},[s]);return ze(),He(),Ie(),o.jsxs(o.Fragment,{children:[n&&o.jsx(t.Presence,{present:!P,animationName:{_open:"fade-in",_closed:"fade-out"},animationDuration:"moderate",children:o.jsx(Ae,{})}),o.jsx(Oe,{open:p,setOpen:T}),o.jsx(je,{onItemClick:x}),o.jsx(Te,{}),o.jsx(De,{open:i,setOpen:h}),o.jsx(so,{open:r,setOpen:l,onNavigate:y}),o.jsx(oo,{open:c,setOpen:f,onNavigate:y}),o.jsx(fe,{openWith:d,setOpen:C=>S(C?"annotations":void 0),onNavigate:y}),o.jsx(t.Presence,{present:e||P,animationName:{_open:"fade-in",_closed:"fade-out"},animationDuration:"slow",overflow:"hidden",children:o.jsx(Me,{})}),o.jsx(ke,{})]})};b.BOOKMARK_AREA_DATA_ATTRIBUTE=J,b.ReactReader=to,b.ReactReaderProvider=ie,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
2
2
  //# sourceMappingURL=index.umd.cjs.map