PageSourceSearch

https://www.tracefiction.com/assets/MyStories-2W7CujgA.js

js tracefiction.com collected 2026-09-24 14:54:44 UTC 256,305 bytes, 6 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/story-updates-surfaces.component-BLIxEdkQ.js","assets/vendor-react-2mXWPygV.js","assets/vendor-ui-CZXIQ_Np.js","assets/index-Bc0LLRT4.js","assets/vendor-app-BYWHQm7D.js","assets/index-BgT5wyQ-.css","assets/slide-over.component-CCZg3JXC.js","assets/use-overlay-focus-return-Ds4tDfMz.js","assets/story-update-context.component-DzwcKtA4.js","assets/story-update-context-BbLd27cF.css","assets/story-updates-surfaces-BoSqp_lX.css"])))=>i.map(i=>d[i]);
2import{n as ll,q as je,u as pt,B as de,R as Mn,r as yt,w as Ve,c as L,L as ta,I as ct,a as jn,b as dt,S as aa,d as cl,e as dl,i as ul,C as $r,f as xs,g as ml,M as Wr,h as Br,j as bs,k as pl,F as Vr,l as Hr,m as Ur,o as In,p as Yr,s as Kr,t as hl,v as xl,A as bl,x as gl,y as gs,z as fl,_ as zr}from"./index-Bc0LLRT4.js";import{r,j as e,u as On,R as Ze,h as vl,L as yl,c as wl}from"./vendor-react-2mXWPygV.js";import{w as na,x as da,y as Pt,z as jl,E as Nl,F as Sl}from"./vendor-app-BYWHQm7D.js";import{u as Dn,Z as Nn,_ as qr,b as et,w as vt,H as wt,W as ut,$ as kl,s as Cl,a0 as Gr,a1 as Ma,M as _l,a2 as Ia,a3 as mt,a4 as Rl,a5 as Oa,a6 as fs,a7 as sa,J as Sn,a8 as Qr,a9 as Xr,aa as vs,Y as Ll,N as Zr,O as Jr,ab as Al,Q as ei,R as ti,S as ai,ac as Zt,U as it,ad as kn,P as Tl,v as Va,ae as It,af as El,z as Fn,ag as Ha,ah as Pl,ai as ys,K as Ml,aj as Il,L as ws,ak as ni,al as si,am as Ol,an as js,E as Dl,D as Fl,e as $l,f as Wl,ao as Bl,g as Vl,h as Ns,ap as Hl}from"./vendor-ui-CZXIQ_Np.js";import{L as Z,a as Oe,b as xe,c as Qe,d as $n,e as Ft,f as Wn,g as Bn,h as Vn,i as Ye,r as gt,j as Ul,k as Ss,R as ks,l as Yl,m as Kl,S as zl,A as ql,u as Gl,n as Ql}from"./useLibraryStickyChromeHeight-CGPsH5fd.js";import{C as $t,M as Cn,b as Xl,i as ri,m as Zl,a as Jl,c as ec,d as tc,s as ac,e as nc,f as sc,g as rc,h as ic,j as oc,k as rn,l as Qt,n as Cs,o as on,p as lc,q as ii,r as cc,t as ka,A as dc,u as _s,v as uc,w as mc,x as pc}from"./useMinLg-k9XJBU-I.js";import{A as hc}from"./archive-masthead.component-Bn-wSQ5z.js";import{M as xc,a as Rs}from"./mobile-primary-header.component-ClXKNzc7.js";import{L as bc,A as Ls}from"./archive-state-frame.component-DQO0Rx0D.js";import{d as oi,f as li,p as ci,u as di,s as gc,a as fc,b as vc,t as yc,h as wc,F as jc,I as Nc,c as Sc,e as kc}from"./setup-paths-By5omJzB.js";import{R as Cc}from"./rating.component-BcxABB4_.js";import{S as ra}from"./story-update-context.component-DzwcKtA4.js";import{S as ui,a as mi,b as pi}from"./slide-over.component-CCZg3JXC.js";import{l as hi,b as _c,u as Rc,a as Lc,c as Ac,C as Tc,T as Ec}from"./useCollectionActionDialog-DpqwS7vO.js";import{u as Pc}from"./use-overlay-focus-return-Ds4tDfMz.js";import"./first-story-activation-BLMmSc5Z.js";function Mc({enabled:t,libraryRevision:a,getActivityMarker:n}){const s=r.useRef(null),i=na({queryKey:je.accountAdvocacyActivityMarker(a),queryFn:n,enabled:t&&a>0,staleTime:0,gcTime:0,retry:1});r.useEffect(()=>{const o=i.data?.latest_activity_at??null;!o||o===s.current||ll(o)&&(s.current=o)},[i.data?.latest_activity_at])}function ln(t="api_limit"){window.dispatchEvent(new CustomEvent("trace:openUpgrade",{detail:{source:t}}))}const Wt=["No Archive Warnings Apply","Creator Chose Not To Use Archive Warnings","Graphic Depictions Of Violence","Major Character Death","Rape/Non-Con","Underage"],Ic="grid min-w-0 gap-5 sm:gap-4 sm:grid-cols-2 lg:grid-cols-3",Da=["F/F","F/M","Gen","M/M","Multi","Other"];function Oc(t,a){return t.includes(a)?t.filter(n=>n!==a):[...t,a]}function Dc(t){return t.split(/(?:\s*[/,&]\s*|\s+x\s+|\s+×\s+)/i).map(a=>a.trim()).filter(Boolean)}function Fa(t){const a=new Map;for(const n of t)for(const s of Dc(n))a.set(s,(a.get(s)??0)+1);return Array.from(a.entries()).sort((n,s)=>n[1]!==s[1]?s[1]-n[1]:n[0].localeCompare(s[0],void 0,{sensitivity:"base"})).map(([n])=>n)}function cn(t){return t.toLocaleString("en-US")}function Fc(t){return gt(t)}function ze({id:t,title:a,count:n=0,children:s,open:i,onToggle:o,onReset:c}){const u=i,l=`filter-section-${t}`;return e.jsxs("section",{className:"df-section",children:[e.jsxs("button",{type:"button",className:"df-section-trigger focus-visible:outline-none focus-visible:shadow-ring","aria-expanded":u,"aria-controls":l,onClick:()=>o(t),children:[e.jsxs("span",{className:"df-section-label",children:[a,n>
20?e.jsx("span",{className:"df-section-count",children:n}):null]}),e.jsxs("span",{className:"df-section-meta",children:[c&&n>0&&u?e.jsx("span",{className:"df-section-reset",onClick:m=>{m.stopPropagation(),c()},children:"reset"}):null,e.jsx(Dn,{className:L("df-section-chevron",u&&"is-open"),"aria-hidden":!0})]})]}),u?e.jsx("div",{id:l,className:"df-section-body",children:s}):null]})}function $c({label:t,status:a,active:n,dotClassName:s,count:i,onClick:o}){return e.jsxs("button",{type:"button","aria-pressed":n,"data-status":a.toLowerCase(),className:L("df-reading-row focus-visible:outline-none focus-visible:shadow-ring",n&&"is-on"),onClick:o,children:[e.jsxs("span",{className:"df-reading-main",children:[e.jsx("span",{className:L("df-reading-dot",s),"aria-hidden":!0}),e.jsx("span",{className:"min-w-0 truncate",children:t})]}),typeof i<"u"?e.jsx("span",{className:"df-reading-count",children:i}):null]})}function Wc({storyUpdatesEnabled:t,filters:a,onChange:n,onReset:s,id:i,activeChips:o=[],resultCount:c,totalCount:u,suggestions:l}){const m=pt(),d=l??m,[x,y]=r.useState(()=>new Set(["reading-state","completion","ratings","tags-fandoms","archive-metadata"])),g=r.useCallback(v=>{y($=>{const f=new Set($);return f.has(v)?f.delete(v):f.add(v),f})},[]),N=r.useCallback(v=>x.has(v),[x]),S=a.statuses.length,C=a.platforms.length,_=a.completionStatus.length,p=a.ratings.length+(a.minRating?1:0)+(a.entryRating==="UNRATED"?1:0),b=(a.minWords||a.maxWords?1:0)+(a.minKudos||a.maxKudos?1:0),k=a.lastReadAfter||a.lastReadBefore?1:0,j=a.notes??(a.hasNotes?"WITH":"ANY"),O=j!=="ANY"?1:0,R=(a.tag?1:0)+(a.workTag?1:0)+a.fandoms.length,F=a.categoryFilter.length+a.pairMembers.length+(a.pairExact&&a.pairMembers.length?1:0)+a.characters.length+a.includeWarnings.length,A=(a.excludeTag?1:0)+(a.excludeWorkTag?1:0)+a.excludePairMembers.length+(a.excludePairExact&&a.excludePairMembers.length?1:0)+a.excludeCharacters.length+a.excludeFandoms.length+a.excludeCategoryFilter.length+a.excludeWarnings.length,z=typeof c=="number"&&typeof u=="number"?`${cn(c)} of ${cn(u)} matching · `:"",Q=v=>{const $=new Set(v);n({...a,includeWarnings:v,excludeWarnings:a.excludeWarnings.filter(f=>!$.has(f))})},te=v=>{const $=new Set(v);n({...a,excludeWarnings:v,includeWarnings:a.includeWarnings.filter(f=>!$.has(f))})};return e.jsxs("section",{id:i,"aria-label":"Advanced filters",className:"df-rail",children:[e.jsxs("div",{className:"df-head",children:[e.jsxs("div",{className:"df-title-row",children:[e.jsx("h2",{className:"df-title",children:"Filters"}),typeof c=="number"?e.jsxs("span",{className:"df-result-pill",children:[cn(c)," stories"]}):null]}),e.jsx("button",{type:"button",className:"df-reset",onClick:s,children:"Reset"})]}),e.jsxs("p",{className:"df-summary",children:[e.jsxs("span",{children:[e.jsx("strong",{children:o.length})," active"]}),z?e.jsxs("span",{children:[" · ",z.replace(/\s*·\s*$/,"")]}):null,e.jsx("span",{children:" · applies as you go"})]}),t?e.jsx(ze,{id:"story-updates",title:"Story updates",count:a.storyUpdates==="NEW"?1:0,open:N("story-updates"),onToggle:g,onReset:()=>n({...a,storyUpdates:"ANY"}),children:e.jsx(Oe,{title:"New updates",sub:"Saved stories with an unseen AO3 announcement.",checked:a.storyUpdates==="NEW",onChange:v=>n({...a,storyUpdates:v?"NEW":"ANY"})})}):null,e.jsx(ze,{id:"reading-state",title:"Reader status",count:S,open:N("reading-state"),onToggle:g,onReset:()=>n({...a,statuses:[]}),children:e.jsx("div",{className:"df-reading-list",children:Mn.map(v=>e.jsx($c,{label:yt(v),status:v,active:a.statuses.includes(v),dotClassName:Fc(v),onClick:()=>n({...a,statuses:Oc(a.statuses,v)})},v))})}),e.jsx(ze,{id:"completion",title:"Work status",count:_,open:N("completion"),onToggle:g,onReset:()=>n({...a,completionStatus:[]}),children:e.jsx(Qe,{values:a.completionStatus,onChange:v=>n({...a,completionStatus:v}),options:[{value:"complete",label:Ve("complete")},{value:"wip",label:Ve("wip")},{value:"hiatus",label:Ve("hiatus")},{value:"abandoned",label:Ve("abandoned")}]})}),e.jsx(ze,{id:"source",title:"Source",count:C,open:N("source"),onToggle:g,onReset:()=>n({...a,platforms:[]}),children:e.jsx(Z,{label:"Platform",hint:"source",children:e.jsx(xe,{values:a.platforms,onChange:v=>n({...a,platforms:v}),getOptions:v=>d.suggestPlatforms(v),triggerPlaceholder:"Any platform",searchPlaceholder:"Search platforms...",maxChips:2})})}),e.jsxs(ze,{id:"ratings",title:"Ratings",count:p,open:N("ratings"),onToggle:g,onReset:()=>n({...a,ratings:[],minRating:void 0,entryRating:"ANY"}),children:[e.jsx(Z,{label:"Archive rating",hint:"from source",children:e.jsx(Wn,{values:a.ratings,onChange:v=>n({...a,ratings:v})})}),e.jsx(Z,{label:"Your rating",hint:"user-set",children:e.jsx(Bn,{value:a.minRating,entryRating:a.entryRating,onChange:v=>n({...a,minRating:v,entryRating:v?"ANY":a.entryRating}),onEntryRatingChange:v=>n({...a,entryRating:v,minRating:void 0})})})]}),e.jsxs(ze,{id:"length-popularity",title:"Length & Popularity",count:b,open:N("length-popularity"),onToggle:g,onReset:()=>n({...a,minWords:void 0,maxWords:void 0,minKudos:void 0,maxKudos:void 0}),children:[e.jsxs(Z,{label:"Word count",hint:"words",children:[e.jsx($n,{min:a.minWords,max:a.maxWords,onChange:({min:v,max:$})=>n({...a,minWords:v,maxWords:$})}),e.jsx(Ft,{min:a.minWords,max:a.maxWords,onChange:({min:v,max:$})=>n({...a,minWords:v,maxWords:$})})]}),e.jsx(Z,{label:"Kudos / favs",hint:"range",children:e.jsx(Ft,{min:a.minKudos,max:a.maxKudos,onChange:({min:v,max:$})=>n({...a,minKudos:v,maxKudos:$}),unit:"kudos"})})]}),e.jsx(ze,{id:"date",title:"Date",count:k,open:N("date"),onToggle:g,onReset:()=>n({...a,lastReadAfter:"",lastReadBefore:""}),children:e.jsx(Z,{label:"Read between",hint:"date range",children:e.jsx(Vn,{start:a.lastReadAfter,end:a.lastReadBefore,onChange:({start:v,end:$})=>n({...a,lastReadAfter:v,lastReadBefore:$})})})}
2),e.jsxs(ze,{id:"tags-fandoms",title:"Tags & Fandoms",count:R,open:N("tags-fandoms"),onToggle:g,onReset:()=>n({...a,tag:"",workTag:"",fandoms:[]}),children:[e.jsx(Z,{label:"Fandom",hint:`${a.fandoms.length} selected`,children:e.jsx(xe,{values:a.fandoms,onChange:v=>n({...a,fandoms:v}),getOptions:v=>m.isReady?m.suggestFandoms(v,50):Promise.resolve([]),triggerPlaceholder:"Any fandom",searchPlaceholder:"Search all fandoms...",maxChips:2})}),e.jsx(Z,{label:"Library tag",hint:"yours",children:e.jsx(Ye,{value:a.tag,getOptions:v=>d.suggestLibraryTags(v),placeholder:"Any tag",searchPlaceholder:"Search your tags...",onChange:v=>n({...a,tag:v})})}),e.jsx(Z,{label:"AO3 tag",hint:"from source",children:e.jsx(Ye,{value:a.workTag,getOptions:v=>d.suggestWorkTags(v),placeholder:"Any AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:v=>n({...a,workTag:v})})})]}),e.jsxs(ze,{id:"archive-metadata",title:"Archive Metadata",count:F,open:N("archive-metadata"),onToggle:g,onReset:()=>n({...a,categoryFilter:[],pairMembers:[],pairExact:!1,characters:[],includeWarnings:[]}),children:[e.jsx(Z,{label:"Categories",hint:"from source",children:e.jsx(Qe,{values:a.categoryFilter,onChange:v=>n({...a,categoryFilter:v}),options:Da.map(v=>({value:v,label:v}))})}),e.jsx(Z,{label:"Must include relationships",hint:`${a.pairMembers.length} selected`,children:e.jsx(xe,{values:a.pairMembers,onChange:v=>n({...a,pairMembers:v}),getOptions:v=>m.isReady?m.suggestRelationships(v,50):Promise.resolve([]),transformOptions:Fa,triggerPlaceholder:"Any relationships",searchPlaceholder:"Type to search relationships..."})}),e.jsx(Oe,{title:"Exact relationships only",checked:a.pairExact,onChange:v=>n({...a,pairExact:v})}),e.jsx(Z,{label:"Must include characters",hint:`${a.characters.length} selected`,children:e.jsx(xe,{values:a.characters,onChange:v=>n({...a,characters:v}),getOptions:v=>m.isReady?m.suggestCharacters(v,50):Promise.resolve([]),triggerPlaceholder:"Any characters",searchPlaceholder:"Type to search characters..."})}),e.jsx(Z,{label:"Include warnings",hint:`${a.includeWarnings.length} selected`,children:e.jsx(xe,{values:a.includeWarnings,onChange:Q,options:[...Wt],triggerPlaceholder:"Any warnings",searchPlaceholder:"Search warnings...",maxChips:2})})]}),e.jsxs(ze,{id:"notes-flags",title:"Notes",count:O,open:N("notes-flags"),onToggle:g,onReset:()=>n({...a,hasNotes:!1,notes:"ANY"}),children:[e.jsx(Oe,{title:"Stories with notes",sub:"Your private notes.",checked:j==="WITH",onChange:v=>n({...a,hasNotes:!1,notes:v?"WITH":"ANY"})}),e.jsx(Oe,{title:"Stories without notes",sub:"Empty private notes.",checked:j==="WITHOUT",onChange:v=>n({...a,hasNotes:!1,notes:v?"WITHOUT":"ANY"})})]}),e.jsxs(ze,{id:"hide",title:"Hide From Results",count:A,open:N("hide"),onToggle:g,onReset:()=>n({...a,excludeTag:"",excludeWorkTag:"",excludePairMembers:[],excludePairExact:!1,excludeCharacters:[],excludeFandoms:[],excludeCategoryFilter:[],excludeWarnings:[]}),children:[e.jsx(Z,{label:"Hidden library tag",children:e.jsx(Ye,{value:a.excludeTag,getOptions:v=>d.suggestLibraryTags(v),placeholder:"Hide library tag",searchPlaceholder:"Search your tags...",onChange:v=>n({...a,excludeTag:v})})}),e.jsx(Z,{label:"Hidden AO3 tag",children:e.jsx(Ye,{value:a.excludeWorkTag,getOptions:v=>d.suggestWorkTags(v),placeholder:"Hide AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:v=>n({...a,excludeWorkTag:v})})}),e.jsx(Z,{label:"Hidden relationships",hint:`${a.excludePairMembers.length} selected`,children:e.jsx(xe,{values:a.excludePairMembers,onChange:v=>n({...a,excludePairMembers:v}),getOptions:v=>m.isReady?m.suggestRelationships(v,50):Promise.resolve([]),transformOptions:Fa,triggerPlaceholder:"Hide relationship",searchPlaceholder:"Type to search relationships..."})}),e.jsx(Oe,{title:"Exact hidden relationships only",checked:a.excludePairExact,onChange:v=>n({...a,excludePairExact:v})}),e.jsx(Z,{label:"Hidden characters",hint:`${a.excludeCharacters.length} selected`,children:e.jsx(xe,{values:a.excludeCharacters,onChange:v=>n({...a,excludeCharacters:v}),getOptions:v=>m.isReady?m.suggestCharacters(v,50):Promise.resolve([]),triggerPlaceholder:"Hide characters",searchPlaceholder:"Type to search characters..."})}),e.jsx(Z,{label:"Hidden fandoms",hint:`${a.excludeFandoms.length} selected`,children:e.jsx(xe,{values:a.excludeFandoms,onChange:v=>n({...a,excludeFandoms:v}),getOptions:v=>m.isReady?m.suggestFandoms(v,50):Promise.resolve([]),triggerPlaceholder:"Hide fandoms",searchPlaceholder:"Search all fandoms..."})}),e.jsx(Z,{label:"Hidden categories",children:e.jsx(Qe,{values:a.excludeCategoryFilter,onChange:v=>n({...a,excludeCategoryFilter:v}),options:Da.map(v=>({value:v,label:v}))})}),e.jsx(Z,{label:"Excluded warnings",hint:`${a.excludeWarnings.length} selected`,children:e.jsx(xe,{values:a.excludeWarnings,onChange:te,options:[...Wt],triggerPlaceholder:"No exclusions",searchPlaceholder:"Search warnings...",maxChips:2})})]})]})}function As({storyUpdatesEnabled:t=!0,filters:a,onChange:n,onReset:s,id:i="filters-panel",activeChips:o,resultCount:c,totalCount:u,variant:l="default",suggestions:m}){const d=pt(),x=m??d,y=Ic,g="min-w-0",N="mb-1 text-xs font-medium text-content-muted",S=p=>{const b=new Set(p);n({...a,includeWarnings:p,excludeWarnings:a.excludeWarnings.filter(k=>!b.has(k))})},C=p=>{const b=new Set(p);n({...a,excludeWarnings:p,includeWarnings:a.includeWarnings.filter(k=>!b.has(k))})},_=a.notes??(a.hasNotes?"WITH":"ANY");return l==="rail"?e.jsx(Wc,{storyUpdatesEnabled:t,id:i,filters:a,onChange:n,onReset:s,activeChips:o,resultCount:c,totalCount:u,suggestions:m}):e.jsxs("section",{id:i,"aria-label":"Filters",className:l==="overlay"?"mt-0 w-full max-w-full overflow-x-hidden border-0 bg-transparent p-4 shadow-none":"mt-3 w-full max-w-full overflow-x-hidden rounded-2xl border border-border bg-surface-1 p-4 shadow-sm",children:[e.jsxs("div",{className:"mb-4 flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-sm font-semibold text-content-primary",children:"Filters"})}),e.jsx(de,{variant:"link",onClick:s,children:"Reset"})]}),e.jsxs("div",{className:y,children:[t?e.jsx(Z,{label:"Story updates",children:e.jsx(Oe,{title:"New updates",sub:"Unseen announcements for saved stories.",checked:a.storyUpdates==="NEW",onCh
2ange:p=>n({...a,storyUpdates:p?"NEW":"ANY"})})}):null,e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Platforms"}),e.jsx(xe,{values:a.platforms,onChange:p=>n({...a,platforms:p}),getOptions:p=>x.suggestPlatforms(p),triggerPlaceholder:"Any platform",searchPlaceholder:"Search platforms...",maxChips:2})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Reader status"}),e.jsx(Qe,{values:a.statuses,onChange:p=>n({...a,statuses:p}),options:Mn.map(p=>({value:p,label:yt(p)}))})]}),e.jsxs(Z,{label:"Word count",hint:"words",children:[e.jsx($n,{min:a.minWords,max:a.maxWords,onChange:({min:p,max:b})=>n({...a,minWords:p,maxWords:b})}),e.jsx(Ft,{min:a.minWords,max:a.maxWords,onChange:({min:p,max:b})=>n({...a,minWords:p,maxWords:b})})]}),e.jsx(Z,{label:"Kudos / favs",hint:"range",children:e.jsx(Ft,{min:a.minKudos,max:a.maxKudos,onChange:({min:p,max:b})=>n({...a,minKudos:p,maxKudos:b}),unit:"kudos"})}),e.jsx(Z,{label:"Archive rating",hint:"from source",children:e.jsx(Wn,{values:a.ratings,onChange:p=>n({...a,ratings:p})})}),e.jsx(Z,{label:"Your rating",hint:"user-set",children:e.jsx(Bn,{value:a.minRating,entryRating:a.entryRating,onChange:p=>n({...a,minRating:p,entryRating:p?"ANY":a.entryRating}),onEntryRatingChange:p=>n({...a,entryRating:p,minRating:void 0})})}),e.jsx(Z,{label:"Last read",hint:"date range",children:e.jsx(Vn,{start:a.lastReadAfter,end:a.lastReadBefore,onChange:({start:p,end:b})=>n({...a,lastReadAfter:p,lastReadBefore:b})})}),e.jsxs(Z,{label:"Notes",children:[e.jsx(Oe,{title:"Stories with notes",sub:"Your private notes.",checked:_==="WITH",onChange:p=>n({...a,hasNotes:!1,notes:p?"WITH":"ANY"})}),e.jsx(Oe,{title:"Stories without notes",sub:"Empty private notes.",checked:_==="WITHOUT",onChange:p=>n({...a,hasNotes:!1,notes:p?"WITHOUT":"ANY"})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Work status"}),e.jsx(Qe,{values:a.completionStatus,onChange:p=>n({...a,completionStatus:p}),options:[{value:"complete",label:Ve("complete")},{value:"wip",label:Ve("wip")},{value:"hiatus",label:Ve("hiatus")},{value:"abandoned",label:Ve("abandoned")}]})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Your library tags (exact)"}),e.jsx(Ye,{value:a.tag,getOptions:p=>x.suggestLibraryTags(p),placeholder:"Any tag",searchPlaceholder:"Search your tags...",onChange:p=>n({...a,tag:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"AO3 tags"}),e.jsx(Ye,{value:a.workTag,getOptions:p=>x.suggestWorkTags(p),placeholder:"Any AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:p=>n({...a,workTag:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Romantic pairs"}),e.jsx(xe,{values:a.pairMembers,onChange:p=>n({...a,pairMembers:p}),getOptions:p=>d.isReady?d.suggestRelationships(p,50):Promise.resolve([]),transformOptions:Fa,triggerPlaceholder:"Any relationships",searchPlaceholder:"Type to search relationships..."}),e.jsx(Oe,{title:"Exact pairs only",checked:a.pairExact,onChange:p=>n({...a,pairExact:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Characters (all)"}),e.jsx(xe,{values:a.characters,onChange:p=>n({...a,characters:p}),getOptions:p=>d.isReady?d.suggestCharacters(p,50):Promise.resolve([]),triggerPlaceholder:"Any characters",searchPlaceholder:"Type to search characters..."})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Fandoms (any)"}),e.jsx(xe,{values:a.fandoms,onChange:p=>n({...a,fandoms:p}),getOptions:p=>d.isReady?d.suggestFandoms(p,50):Promise.resolve([]),triggerPlaceholder:"Any fandom",searchPlaceholder:"Search all fandoms..."})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Categories (any)"}),e.jsx(Qe,{values:a.categoryFilter,onChange:p=>n({...a,categoryFilter:p}),options:Da.map(p=>({value:p,label:p}))})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Archive warnings (any)"}),e.jsx(xe,{values:a.includeWarnings,onChange:S,options:[...Wt],triggerPlaceholder:"Any warnings",searchPlaceholder:"Search warnings…",maxChips:2})]})]}),e.jsxs("div",{className:"col-span-full my-3 flex items-center gap-3",children:[e.jsx("div",{className:"h-px flex-1 bg-border"}),e.jsx("span",{className:"shrink-0 text-xs font-semibold uppercase tracking-wider text-content-muted",children:"Hide from results"}),e.jsx("div",{className:"h-px flex-1 bg-border"})]}),e.jsxs("div",{className:y,children:[e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Your library tags"}),e.jsx(Ye,{value:a.excludeTag,getOptions:p=>x.suggestLibraryTags(p),placeholder:"Hide library tag",searchPlaceholder:"Search your tags...",onChange:p=>n({...a,excludeTag:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"AO3 tags"}),e.jsx(Ye,{value:a.excludeWorkTag,getOptions:p=>x.suggestWorkTags(p),placeholder:"Hide AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:p=>n({...a,excludeWorkTag:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Romantic pairs"}),e.jsx(xe,{values:a.excludePairMembers,onChange:p=>n({...a,excludePairMembers:p}),getOptions:p=>d.isReady?d.suggestRelationships(p,50):Promise.resolve([]),transformOptions:Fa,triggerPlaceholder:"Hide relationship",searchPlaceholder:"Type to search relationships..."}),e.jsx(Oe,{title:"Exact pairs only",checked:a.excludePairExact,onChange:p=>n({...a,excludePairExact:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Characters (any)"}),e.jsx(xe,{values:a.excludeCharacters,onChange:p=>n({...a,excludeCharacters:p}),getOptions:p=>d.isReady?d.suggestCharacters(p,50):Promise.resolve([]),triggerPlaceholder:"Hide characters",searchPlaceholder:"Type to search characters..."})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Fandoms (any)"}),e.jsx(xe,{values:a.excludeFandoms,onChange:p=>n({...a,excludeFandoms:p}),getOptions:p=>d.isReady?d.suggestFandoms(p,50):Promise.resolve([]),triggerPlaceholder:"Hide fandoms",searchPlaceholder:"Search all fandoms..."})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Categories (any)"}),e.jsx(Qe,{values:a.excludeCategoryFilter,onChange:p=>n({...a,excludeCategoryFilter:p}),options:Da.map(p=>({value:p,label:p}))})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Archive warnings (any)"}),e.jsx(xe,{values:a.excludeWarnings,onChange:C,options:[...Wt],triggerPlaceholder:"No exclusions",searchPlaceholder:"Search warnings…",maxChips:2})]})]})]})}const xi=["F/F","F/M","Gen","M/M","Multi","Other"],Bc={SAVED:gt("SAVED"),READING:gt("READING"),CAUGHT_UP:gt("CAUGHT_UP"),PAUSED:gt("PAUSED"),FINISHED:gt("FINISHED"),DROPPED:gt("DROPPED")};function Vc(t,a){return t.includes(a)?t.filter(n=>n!==a):[...t,a]}function Hc(t){return t.split(/(?:\s*[/,&]\s*|\s+x\s+|\s+×\s+)/i).map(a=>
2a.trim()).filter(Boolean)}function bi(t){const a=new Map;for(const n of t)for(const s of Hc(n))a.set(s,(a.get(s)??0)+1);return Array.from(a.entries()).sort((n,s)=>n[1]!==s[1]?s[1]-n[1]:n[0].localeCompare(s[0],void 0,{sensitivity:"base"})).map(([n])=>n)}function dn(t){return t.toLocaleString("en-US")}function qe({title:t,children:a,className:n,defaultOpen:s=!0,count:i,onReset:o}){const[c,u]=r.useState(s),l=c?qr:Dn;return e.jsxs("section",{className:L("mf-section first:border-t-0",n),children:[e.jsxs("button",{type:"button",className:"mf-section-trigger focus-visible:outline-none focus-visible:shadow-ring","aria-expanded":c,onClick:()=>u(m=>!m),children:[e.jsxs("span",{className:"mf-section-label",children:[t,i&&i>0?e.jsx("span",{className:"mf-section-count",children:i}):null]}),e.jsxs("span",{className:"mf-section-meta",children:[o&&i&&i>0?e.jsx("span",{className:"mf-section-reset",onClick:m=>{m.stopPropagation(),o()},children:"reset"}):null,e.jsx(l,{className:L("mf-section-chevron",c&&"is-open"),"aria-hidden":!0})]})]}),c?e.jsx("div",{className:"mf-section-body",children:a}):null]})}function Uc({label:t,status:a,count:n,active:s,disabled:i,disabledReason:o,dotClass:c,onClick:u}){return e.jsxs("button",{type:"button","aria-pressed":s,"aria-label":t,"data-status":a?.toLowerCase(),disabled:i,onClick:u,className:L("mf-reading-row focus-visible:outline-none focus-visible:shadow-ring",s&&"is-on",i&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:L("h-1.5 w-1.5 rounded-full",c??"bg-border-strong"),"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:t})]}),i&&o?e.jsx("span",{className:"mf-reading-reason",children:o}):n?e.jsx("span",{className:"mf-reading-count",children:n}):null]})}function Yc({activeChips:t,onResetAll:a,resultCount:n,totalCount:s}){const i=n===0;return e.jsxs("div",{className:"mf-header-compact",children:[e.jsxs("div",{className:"mf-header-title-row",children:[e.jsx("h2",{className:"mf-header-title",children:"Filters"}),e.jsx("p",{className:L("mf-header-count",i&&"is-zero"),children:i?`0 of ${dn(s)}`:`${dn(n)} of ${dn(s)}`})]}),a?e.jsx("button",{type:"button",className:"mf-header-reset",disabled:t.length===0,onClick:a,children:"Reset"}):null]})}function Kc({filters:t,onChange:a}){const n=t.statuses.length;return e.jsx(qe,{title:"Reader status",count:n,children:e.jsx("div",{className:"mf-reading-list",role:"group","aria-label":"Reader status filters",children:Mn.map(s=>{const i=t.statuses.includes(s);return e.jsx(Uc,{label:yt(s),status:s,active:i,dotClass:Bc[s],onClick:()=>a({...t,statuses:Vc(t.statuses,s)})},s)})})})}function zc({filters:t,onChange:a}){return e.jsx(qe,{title:"Story updates",count:t.storyUpdates==="NEW"?1:0,onReset:()=>a({...t,storyUpdates:"ANY"}),children:e.jsx(Oe,{title:"New updates",sub:"Saved stories with an unseen AO3 announcement.",checked:t.storyUpdates==="NEW",onChange:n=>a({...t,storyUpdates:n?"NEW":"ANY"})})})}function qc({searchValue:t,onSearchChange:a}){return e.jsx("section",{className:"mf-search-section",children:e.jsx(Z,{label:"Search",children:e.jsx(Ul,{value:t,onChange:a,placeholder:"Title, author, fandom, notes, tags...",leadingIcon:e.jsx(Nn,{className:"h-4 w-4"}),clearable:!0})})})}function Gc({filters:t,onChange:a}){return e.jsx(qe,{title:"Work status",count:t.completionStatus.length,onReset:()=>a({...t,completionStatus:[]}),children:e.jsx(Qe,{values:t.completionStatus,onChange:n=>a({...t,completionStatus:n}),options:[{value:"complete",label:Ve("complete")},{value:"wip",label:Ve("wip")},{value:"hiatus",label:Ve("hiatus")},{value:"abandoned",label:Ve("abandoned")}]})})}function Qc({filters:t,onChange:a,suggestions:n}){return e.jsx(qe,{title:"Source",count:t.platforms.length,onReset:()=>a({...t,platforms:[]}),children:e.jsx(Z,{label:"Platform",hint:"source",children:e.jsx(xe,{values:t.platforms,onChange:s=>a({...t,platforms:s}),getOptions:s=>n.suggestPlatforms(s),triggerPlaceholder:"Any platform",searchPlaceholder:"Search platforms...",maxChips:2})})})}function Xc({filters:t,onChange:a}){return e.jsxs(qe,{title:"Ratings",count:t.ratings.length+(t.minRating?1:0)+(t.entryRating==="UNRATED"?1:0),onReset:()=>a({...t,ratings:[],minRating:void 0,entryRating:"ANY"}),children:[e.jsx(Z,{label:"Archive rating",hint:"from source",children:e.jsx(Wn,{values:t.ratings,onChange:n=>a({...t,ratings:n})})}),e.jsx(Z,{label:"Your rating",hint:"user-set",children:e.jsx(Bn,{value:t.minRating,entryRating:t.entryRating,onChange:n=>a({...t,minRating:n,entryRating:n?"ANY":t.entryRating}),onEntryRatingChange:n=>a({...t,entryRating:n,minRating:void 0})})})]})}function Zc({filters:t,onChange:a}){return e.jsxs(qe,{title:"Length & popularity",count:(t.minWords||t.maxWords?1:0)+(t.minKudos||t.maxKudos?1:0),onReset:()=>a({...t,minWords:void 0,maxWords:void 0,minKudos:void 0,maxKudos:void 0}),children:[e.jsxs(Z,{label:"Word count",hint:"words",children:[e.jsx($n,{min:t.minWords,max:t.maxWords,onChange:({min:n,max:s})=>a({...t,minWords:n,maxWords:s})}),e.jsx(Ft,{min:t.minWords,max:t.maxWords,onChange:({min:n,max:s})=>a({...t,minWords:n,maxWords:s})})]}),e.jsx(Z,{label:"Kudos / favs",hint:"range",children:e.jsx(Ft,{min:t.minKudos,max:t.maxKudos,onChange:({min:n,max:s})=>a({...t,minKudos:n,maxKudos:s}),unit:"kudos"})})]})}
2function Jc({filters:t,onChange:a}){const n=t.notes??(t.hasNotes?"WITH":"ANY");return e.jsxs(qe,{title:"Notes",count:n!=="ANY"?1:0,onReset:()=>a({...t,hasNotes:!1,notes:"ANY"}),children:[e.jsx(Oe,{title:"Stories with your notes",sub:"Find stories you've left private notes on.",checked:n==="WITH",onChange:s=>a({...t,hasNotes:!1,notes:s?"WITH":"ANY"})}),e.jsx(Oe,{title:"Stories without your notes",sub:"Find stories where your private note is still empty.",checked:n==="WITHOUT",onChange:s=>a({...t,hasNotes:!1,notes:s?"WITHOUT":"ANY"})})]})}function ed({filters:t,onChange:a}){return e.jsx(qe,{title:"Date",count:t.lastReadAfter||t.lastReadBefore?1:0,onReset:()=>a({...t,lastReadAfter:"",lastReadBefore:""}),children:e.jsx(Z,{label:"Read between",hint:"date range",children:e.jsx(Vn,{start:t.lastReadAfter,end:t.lastReadBefore,onChange:({start:n,end:s})=>a({...t,lastReadAfter:n,lastReadBefore:s})})})})}function td({filters:t,onChange:a,suggestions:n}){const s=pt();return e.jsxs(qe,{title:"Tags and fandoms",count:t.fandoms.length+(t.tag?1:0)+(t.workTag?1:0),onReset:()=>a({...t,fandoms:[],tag:"",workTag:""}),children:[e.jsx(Z,{label:"Fandom",hint:`${t.fandoms.length} selected`,children:e.jsx(xe,{values:t.fandoms,onChange:i=>a({...t,fandoms:i}),getOptions:i=>s.isReady?s.suggestFandoms(i,50):Promise.resolve([]),triggerPlaceholder:"Any fandom",searchPlaceholder:"Search all fandoms...",maxChips:2})}),e.jsxs("div",{className:"mf-tag-stack",children:[e.jsx(Z,{label:"Library tag",hint:"yours",children:e.jsx(Ye,{value:t.tag,onChange:i=>a({...t,tag:i}),getOptions:i=>n.suggestLibraryTags(i),placeholder:"Any tag",searchPlaceholder:"Search your tags..."})}),e.jsx(Z,{label:"AO3 tag",hint:"from source",children:e.jsx(Ye,{value:t.workTag,onChange:i=>a({...t,workTag:i}),getOptions:i=>n.suggestWorkTags(i),placeholder:"Any AO3 tag",searchPlaceholder:"Search AO3 tags..."})})]})]})}function ad({filters:t,onChange:a}){const n=pt(),s=i=>{const o=new Set(i);a({...t,includeWarnings:i,excludeWarnings:t.excludeWarnings.filter(c=>!o.has(c))})};return e.jsxs(qe,{title:"Archive metadata",count:t.categoryFilter.length+t.pairMembers.length+(t.pairExact&&t.pairMembers.length?1:0)+t.characters.length+t.includeWarnings.length,onReset:()=>a({...t,categoryFilter:[],pairMembers:[],pairExact:!1,characters:[],includeWarnings:[]}),children:[e.jsx(Z,{label:"Categories",hint:"from source",children:e.jsx(Qe,{values:t.categoryFilter,onChange:i=>a({...t,categoryFilter:i}),options:xi.map(i=>({value:i,label:i}))})}),e.jsx(Z,{label:"Must include relationships",hint:`${t.pairMembers.length} selected`,children:e.jsx(Ss,{values:t.pairMembers,onChange:i=>a({...t,pairMembers:i}),getOptions:i=>n.isReady?n.suggestRelationships(i,50):Promise.resolve([]),transformOptions:bi,searchPlaceholder:"Type to search relationships..."})}),e.jsx(Oe,{title:"Exact relationships only",checked:t.pairExact,onChange:i=>a({...t,pairExact:i})}),e.jsx(Z,{label:"Must include characters",hint:`${t.characters.length} selected`,children:e.jsx(Ss,{values:t.characters,onChange:i=>a({...t,characters:i}),getOptions:i=>n.isReady?n.suggestCharacters(i,50):Promise.resolve([]),searchPlaceholder:"Type to search characters..."})}),e.jsx(Z,{label:"Include warnings",hint:`${t.includeWarnings.length} selected`,children:e.jsx(xe,{values:t.includeWarnings,onChange:s,options:[...Wt],triggerPlaceholder:"Any warnings",searchPlaceholder:"Search warnings",maxChips:2})})]})}function nd({filters:t,onChange:a,suggestions:n}){const s=pt(),i=o=>{const c=new Set(o);a({...t,excludeWarnings:o,includeWarnings:t.includeWarnings.filter(u=>!c.has(u))})};return e.jsxs(qe,{title:"Hide from results",defaultOpen:!1,count:(t.excludeTag?1:0)+(t.excludeWorkTag?1:0)+t.excludePairMembers.length+(t.excludePairExact&&t.excludePairMembers.length?1:0)+t.excludeCharacters.length+t.excludeFandoms.length+t.excludeCategoryFilter.length+t.excludeWarnings.length,onReset:()=>a({...t,excludeTag:"",excludeWorkTag:"",excludePairMembers:[],excludePairExact:!1,excludeCharacters:[],excludeFandoms:[],excludeCategoryFilter:[],excludeWarnings:[]}),children:[e.jsxs("div",{className:"mf-tag-stack",children:[e.jsx(Z,{label:"Hidden library tag",children:e.jsx(Ye,{value:t.excludeTag,getOptions:o=>n.suggestLibraryTags(o),placeholder:"Hide library tag",searchPlaceholder:"Search your tags...",onChange:o=>a({...t,excludeTag:o})})}),e.jsx(Z,{label:"Hidden AO3 tag",children:e.jsx(Ye,{value:t.excludeWorkTag,getOptions:o=>n.suggestWorkTags(o),placeholder:"Hide AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:o=>a({...t,excludeWorkTag:o})})})]}),e.jsx(Z,{label:"Hidden relationships",hint:`${t.excludePairMembers.length} selected`,children:e.jsx(xe,{values:t.excludePairMembers,onChange:o=>a({...t,excludePairMembers:o}),getOptions:o=>s.isReady?s.suggestRelationships(o,50):Promise.resolve([]),transformOptions:bi,triggerPlaceholder:"Hide relationship",searchPlaceholder:"Type to search relationships..."})}),e.jsx(Oe,{title:"Exact hidden relationships only",checked:t.excludePairExact,onChange:o=>a({...t,excludePairExact:o})}),e.jsx(Z,{label:"Hidden characters",hint:`${t.excludeCharacters.length} selected`,children:e.jsx(xe,{values:t.excludeCharacters,onChange:o=>a({...t,excludeCharacters:o}),getOptions:o=>s.isReady?s.suggestCharacters(o,50):Promise.resolve([]),triggerPlaceholder:"Hide characters",searchPlaceholder:"Type to search characters..."})}),e.jsx(Z,{label:"Hidden fandoms",hint:`${t.excludeFandoms.length} selected`,children:e.jsx(xe,{values:t.excludeFandoms,onChange:o=>a({...t,excludeFandoms:o}),getOptions:o=>s.isReady?s.suggestFandoms(o,50):Promise.resolve([]),triggerPlaceholder:"Hide fandoms",searchPlaceholder:"Search all fandoms..."})}),e.jsx(Z,{label:"Hidden categories",children:e.jsx(Qe,{values:t.excludeCategoryFilter,onChange:o=>a({...t,excludeCategoryFilter:o}),options:xi.map(o=>({value:o,label:o}))})}),e.jsx(Z,{label:"Excluded warnings",hint:`${t.excludeWarnings.length} selected`,children:e.jsx(xe,{values:t.excludeWarnings,onChange:i,options:[...Wt],triggerPlaceholder:"No exclusions",searchPlaceholder:"Search warnings",maxChips:2})})]})}function sd({storyUpdatesEnabled:t=!0,filters:a,onChange:n,onSearchChange:s,searchValue:i,suggestions:o}){const c=pt(),u=o??c;return e.jsxs(e.Fragment,{children:[e.jsx(qc,{searchValue:i,onSearchChange:s}),t?e.jsx(zc,{filters:a,onChange:n}):null,e.jsx(Kc,{filters:a,onChange:n}),e.jsx(Gc,{filters:a,onChange:n}),e.jsx(Qc,{filters:a,onChange:n,suggestions:u}),e.jsx(Xc,{filters:a,onChange:n}),e.jsx(Zc,{filters:a,onChange:n}),e.jsx(Jc,{filters:a,onChange:n}),e.jsx(ed,{filters:a,onChange:n}),e.jsx(td,{filters:a,onChange:n,suggestions:u}),e.jsx(ad,{filters:a,onChange:n}),e.jsx(nd,{filters:a,onChange:n,suggestions:u})]})}const rd="relative z-30 hidden border-y border-[var(--line)] bg-[color-mix(in_oklab,var(--paper-2)_86%,transparent)] sm:block",i
2d="mx-auto flex w-full max-w-[96rem] items-center gap-4 px-[18px] py-3 sm:px-12 lg:px-16",gi="inline-flex shrink-0 items-center gap-2 font-mono text-[10px] font-medium uppercase leading-none text-[var(--ink-4)] [&_svg]:h-3.5 [&_svg]:w-3.5",od="flex min-w-0 flex-1 items-center gap-2 overflow-x-auto pb-0.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",ld=et(["inline-flex min-h-9 max-w-[18rem] shrink-0 items-center gap-2 rounded-pill border px-3.5","font-sans text-[13px] font-medium leading-none outline-none transition-colors","focus-visible:shadow-ring [&_svg]:h-3.5 [&_svg]:w-3.5"].join(" "),{variants:{active:{true:"border-[var(--ink)] bg-[var(--archive-inverse-surface)] text-[var(--archive-inverse-text)]",false:"border-[var(--line-strong)] bg-transparent text-[var(--ink-2)] hover:border-[var(--ink-3)] hover:text-[var(--ink)]"},dirty:{true:"border-[var(--honey)] shadow-[0_0_0_2px_color-mix(in_oklab,var(--honey)_24%,transparent)]",false:""}},defaultVariants:{active:!1,dirty:!1}}),cd="min-w-0 truncate",ia="rounded-pill bg-[color-mix(in_oklab,var(--ink)_10%,transparent)] px-1.5 py-0.5 font-mono text-[10.5px] leading-none text-current opacity-70",Ts="inline-flex min-h-9 shrink-0 items-center rounded-pill border border-[var(--line)] px-3 font-mono text-[10px] font-medium uppercase leading-none text-[var(--ink-4)]",$a="h-1.5 w-1.5 shrink-0 rounded-pill bg-[var(--honey)]",dd="inline-flex min-h-9 shrink-0 items-center gap-1.5 rounded-pill border border-[var(--line-strong)] bg-transparent px-3 font-sans text-[13px] font-medium leading-none text-[var(--ink-3)] outline-none transition-colors hover:border-[var(--ink-3)] hover:text-[var(--ink)] focus-visible:shadow-ring [&_svg]:h-3.5 [&_svg]:w-3.5",ud="ml-auto flex shrink-0 items-center gap-2",md="inline-flex min-h-10 items-center gap-2 rounded-pill border border-[color-mix(in_oklab,var(--honey)_45%,var(--line))] bg-[color-mix(in_oklab,var(--honey)_12%,transparent)] py-1 pl-3 pr-1",pd="inline-flex items-center gap-2 whitespace-nowrap text-[12.5px] font-medium text-[var(--ink)]",Ot="mx-auto w-full max-w-[96rem] px-[18px] pb-3 font-sans text-xs leading-snug text-[var(--ink-3)] sm:px-12 lg:px-16",Es="mx-auto w-full max-w-[96rem] px-[18px] pb-4 sm:px-12 lg:px-16",hd="overflow-hidden rounded-sm border border-[var(--line-strong)] bg-[var(--paper-2)] shadow-[var(--shadow-popover)]",xd="rounded-sm bg-[color-mix(in_oklab,var(--paper-2)_74%,transparent)]",bd="flex items-start justify-between gap-3 border-b border-[var(--line)] px-4 py-3",gd="flex items-start justify-between gap-3 px-4 pb-2 pt-3",fi="font-mono text-[10px] font-medium uppercase text-[var(--ink-4)]",vi="mt-1 font-landing-serif text-xl font-medium leading-tight text-[var(--ink)]",yi="mt-1 max-w-2xl text-sm leading-snug text-[var(--ink-3)]",fd="p-4",vd="px-4 pb-3 pt-1",yd="rounded-sm bg-[color-mix(in_oklab,var(--card)_70%,transparent)] p-3",wd="font-mono text-[9.5px] font-medium uppercase text-[var(--ink-4)]",jd="mt-2 flex flex-wrap items-center gap-2 text-sm text-[var(--ink-2)]",un="inline-flex min-h-7 max-w-full items-center rounded-pill border border-[var(--line-strong)] bg-[var(--paper-2)] px-2.5 font-mono text-[10.5px] font-medium uppercase leading-none text-[var(--ink-3)]",Nd="grid gap-3 md:grid-cols-[minmax(0,1fr)_12.5rem]",Sd="max-h-[26rem] space-y-2 overflow-y-auto px-2 py-2 [scrollbar-width:thin]",kd="grid min-h-14 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-xs border border-[var(--line)] bg-[var(--card)] px-2 py-2",Cd="roun
2ded-xs border border-[var(--line)] bg-[color-mix(in_oklab,var(--card)_72%,transparent)]",_d="flex items-center justify-between gap-3 border-b border-[var(--line)] px-3 py-2 font-mono text-[9.5px] font-medium uppercase text-[var(--ink-4)]",Rd="grid min-h-16 grid-cols-[2rem_2rem_minmax(0,1fr)_2rem_2rem] items-center gap-2 border-t border-[var(--line)] px-2 py-2 first:border-t-0",Ld="hidden shrink-0 text-[var(--ink-5)] sm:inline-flex [&_svg]:h-4 [&_svg]:w-4",Ad="grid w-8 shrink-0 grid-rows-2 gap-1",Ps="inline-flex h-6 w-8 items-center justify-center rounded-2xs border border-[var(--line-strong)] text-[var(--ink-4)] outline-none transition-colors hover:border-[var(--ink-3)] hover:text-[var(--ink)] focus-visible:shadow-ring disabled:cursor-not-allowed disabled:opacity-35 [&_svg]:h-3.5 [&_svg]:w-3.5",Td="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-xs border border-[var(--line-strong)] text-[var(--ink-4)] outline-none transition-colors hover:border-[var(--ink-3)] hover:text-[var(--ink)] focus-visible:shadow-ring aria-pressed:border-[color-mix(in_oklab,var(--honey)_55%,var(--line))] aria-pressed:bg-[color-mix(in_oklab,var(--honey)_13%,transparent)] aria-pressed:text-[var(--honey)] [&_svg]:h-4 [&_svg]:w-4",Ms="flex min-w-0 flex-1 items-center gap-1.5 text-left outline-none focus-visible:shadow-ring",Is="block min-w-0 truncate text-sm font-semibold leading-snug text-[var(--ink)]",Os="mt-0.5 block min-w-0 truncate font-mono text-[10.5px] uppercase leading-none text-[var(--ink-4)]",Ed="min-w-0 space-y-1.5",Pd="h-9 w-full min-w-0 rounded-xs border border-[var(--line-strong)] bg-[var(--paper-2)] px-2.5 font-sans text-sm text-[var(--ink)] outline-none focus-visible:shadow-ring",Md="flex flex-wrap items-center gap-2",wi="mt-1 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-xs leading-snug",ji="text-[var(--ink-3)]",Ni="font-medium text-[var(--rust)]",Si="text-[var(--ink-3)]",ki="mt-1 rounded-xs border border-[color-mix(in_oklab,var(--rust)_35%,var(--line))] bg-[color-mix(in_oklab,var(--rust)_8%,transparent)] px-2.5 py-2 text-xs leading-snug text-[var(--rust)]",Id="px-3 py-3 text-sm leading-snug text-[var(--ink-3)]",Od="rounded-sm border border-[var(--line-strong)] bg-[var(--card)] p-3",Dd="mb-3 flex items-center justify-between gap-3",Fd="flex min-w-0 gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",Ds="inline-flex min-h-10 max-w-[17rem] shrink-0 items-center gap-2 rounded-sm border border-[var(--line-strong)] bg-[var(--paper-2)] px-3 text-sm font-medium leading-none text-[var(--ink-2)] outline-none transition-colors focus-visible:shadow-ring aria-pressed:border-[var(--ink)] aria-pressed:bg-[var(--ink)] aria-pressed:text-[var(--paper)] [&_svg]:h-4 [&_svg]:w-4",$d="mt-3 rounded-sm border border-[color-mix(in_oklab,var(--honey)_42%,var(--line))] bg-[color-mix(in_oklab,var(--honey)_11%,transparent)] p-3",Wd="text-sm leading-snug text-[var(--ink-2)]",Bd="mt-3 grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.75rem] gap-2",_n="mt-3 text-sm leading-snug text-[var(--ink-3)]",Ci="mt-3 rounded-sm border border-[color-mix(in_oklab,var(--rust)_32%,var(--line))] bg-[color-mix(in_oklab,var(--rust)_8%,transparent)] p-3 text-sm leading-snug text-[var(--ink-2)]",Je="all";function Be(t){return t.toLocaleString("en-US")}function mn(t){return t.trim().replace(/\s+/g," ").toLocaleLowerCase()}function Rn(t){const a=t.trim();return a?a.length>ta?`Use ${ta} characters or fewer.`:null:"Enter a view name."}function _i({name:t,existingNames:a,currentName:n}){const s=mn(t);if(!s)return!1;const i=n?mn(n):null;return a.some(o=>{const c=mn(o);return c===s&&c!==i})}function Ri(t,a){const n=t==="all"?a:t.liveCount;return typeof n!="number"?null:t==="all"?`${Be(n)} stories in All Library`:`${Be(n)} matching stories`}function Li(t,a){return r.useMemo(()=>t.find(n=>n.id===a)??null,[a,t])}function Ai({pinned:t,active:a}){return t?a?e.jsx(Gr,{"aria-hidden":!0}):e.jsx(Ma,{"aria-hidden":!0}):e.jsx(vt,{"aria-hidden":!0})}function Vd({item:t,allLibraryCount:a}){const n=t==="all"?a:t.liveCount;if(typeof n!="number")return null;const s=Ri(t,a);return e.jsx("span",{className:ia,"aria-label":s??void 0,children:Be(n)})}function pn({item:t,active:a,dirty:n,allLibraryCount:s,onSelect:i}){const o=t==="all",c=o?"All Library":t.name,u=Ri(t,s),l=[a?`Active Library View: ${c}`:`Select Library View: ${c}`,!o&&t.pinned?"pinned":null,u,a&&n?"unsaved edits":null].filter(m=>!!m);return e.jsxs("button",{type:"button",className:ld({active:a,dirty:a&&n}),"aria-pressed":a,"aria-label":l.join(", "),onClick:i,children:[o?e.jsx(vt,{"aria-hidden":!0}):e.jsx(Ai,{pinned:t.pinned,active:a}),e.jsx("span",{className:cd,children:c}),e.jsx(Vd,{item:t,allLibraryCount:s}),a&&n?e.jsx("span",{className:$a,"aria-hidden":!0}):null]})}function Ti({activeView:t,dirty:a,hasAdHocQuery:n,activeFilterCount:s,handlers:i,mutationState:o,onBeforeOpenPanel:c,compact:u=!1}
2){const l=!!t&&o?.updatingViewId===t?.id,m=o?.creating===!0;return t&&a?u?e.jsxs("div",{className:$d,children:[e.jsxs("p",{className:Wd,children:[e.jsx("strong",{children:t.name})," has unsaved edits."]}),e.jsxs("div",{className:Bd,children:[e.jsx(de,{type:"button",size:"sm",variant:"solid",onClick:i.onUpdateView,loading:l,disabled:l,"aria-label":`Update ${t.name} with current filters`,leftIcon:e.jsx(ut,{}),children:"Update"}),e.jsx(de,{type:"button",size:"sm",variant:"outline",onClick:d=>{c?.(d.currentTarget),i.onOpenSave(!0)},disabled:m,"aria-label":"Save current edits as a new Library View",leftIcon:e.jsx(_l,{}),children:"Save new"}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":"Revert to saved view",title:"Revert to saved view",onClick:i.onRevertView,className:"h-[var(--control-h)] w-full rounded-sm",children:e.jsx(Ia,{"aria-hidden":!0})})]})]}):e.jsxs("div",{className:md,children:[e.jsxs("span",{className:pd,children:[e.jsx("span",{className:$a,"aria-hidden":!0}),"Unsaved edits"]}),e.jsx(de,{type:"button",size:"sm",variant:"solid",onClick:i.onUpdateView,loading:l,disabled:l,"aria-label":`Update ${t.name} with current filters`,leftIcon:e.jsx(ut,{}),children:"Update"}),e.jsx(de,{type:"button",size:"sm",variant:"outline",onClick:d=>{c?.(d.currentTarget),i.onOpenSave(!0)},disabled:m,"aria-label":"Save current edits as a new Library View",children:"Save as new"}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":"Revert to saved view",title:"Revert to saved view",onClick:i.onRevertView,children:e.jsx(Ia,{"aria-hidden":!0})})]}):!t&&n?u?e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("p",{className:"min-w-0 flex-1 text-sm leading-snug text-[var(--ink-3)]",children:[e.jsx("strong",{className:"text-[var(--ink)]",children:s})," ","active refinements are not saved yet."]}),e.jsx(de,{type:"button",size:"sm",variant:"solid",onClick:d=>{c?.(d.currentTarget),i.onOpenSave(!1)},disabled:m,"aria-label":`Save ${s} active refinements as a Library View`,leftIcon:e.jsx(mt,{}),children:"Save"})]}):e.jsx(de,{type:"button",size:"sm",variant:"solid",onClick:d=>{c?.(d.currentTarget),i.onOpenSave(!1)},disabled:m,"aria-label":`Save ${s} active refinements as a Library View`,leftIcon:e.jsx(mt,{}),children:"Save current view"}):t&&u?e.jsxs("p",{className:_n,children:["Showing ",e.jsx("strong",{className:"text-[var(--ink)]",children:t.name}),".",t.summary?` ${t.summary}.`:null]}):e.jsx(de,{type:"button",size:"sm",variant:"outline",disabled:!0,children:"Save current view"})}function Ei({isError:t,isLoading:a,hasViews:n,compact:s=!1}){return t?e.jsx("p",{className:s?Ci:Ot,children:"Saved views could not load. All Library is still available."}):a?e.jsx("p",{className:s?_n:Ot,children:"Loading saved views."}):n?null:e.jsx("p",{className:s?_n:Ot,children:"No saved views yet. Refine All Library and save a private view to return later."})}function Hd({views:t,activeViewId:a,dirty:n,hasAdHocQuery:s,isError:i=!1,isLoading:o=!1,allLibraryCount:c,visibleCount:u,activeFilterCount:l,capturedQuery:m,panelMode:d=null,saveAsNew:x=!1,zeroResultView:y=!1,overflowLabel:g,mutationState:N,handlers:S}){const C=r.useRef(null),_=Li(t,a),p=a===null||a===Je,b=d==="manage",k=t.filter(A=>A.pinned),j=t.filter(A=>!A.pinned),O=_&&!_.pinned?[_]:j.slice(0,k.length>5?0:1),R=r.useCallback(A=>{C.current=A},[]),F=r.useCallback(()=>{S.onClosePanel(),window.setTimeout(()=>{C.current?.focus()},0)},[S]);return e.jsx("section",{"aria-label":"Library Views",children:e.jsxs("div",{className:rd,children:[e.jsxs("div",{className:id,children:[e.jsxs("span",{className:gi,children:[e.jsx(vt,{"aria-hidden":!0}),"Library views"]}),e.jsxs("div",{className:od,role:"list","aria-label":"Saved Library Views",children:[e.jsx(pn,{item:"all",active:p,dirty:n&&p,allLibraryCount:c,onSelect:()=>S.onSelectView(Je)}),k.map(A=>e.jsx(pn,{item:A,active:A.id===a,dirty:n,allLibraryCount:c,onSelect:()=>S.onSelectView(A.id)},A.id)),O.map(A=>e.jsx(pn,{item:A,active:A.id===a,dirty:n,allLibraryCount:c,onSelect:()=>S.onSelectView(A.id)},A.id)),e.jsxs("button",{type:"button",className:dd,"aria-label":b?"Close Manage Library Views":`Manage Library Views, ${t.length} saved views`,"aria-expanded":b,onClick:A=>{if(R(A.currentTarget),b){F();return}S.onOpenManage()},children:[b?e.jsx(wt,{"aria-hidden":!0}):e.jsx(Cl,{"aria-hidden":!0}
2),b?"Close":"Manage",b?null:e.jsx("span",{className:ia,children:t.length})]}),o?e.jsx("span",{className:Ts,children:"Loading"}):null,i?e.jsx("span",{className:Ts,children:"Unavailable"}):null]}),e.jsx("div",{className:ud,children:e.jsx(Ti,{activeView:_,dirty:n,hasAdHocQuery:s,activeFilterCount:l,handlers:S,mutationState:N,onBeforeOpenPanel:R})})]}),g?e.jsx("p",{className:Ot,children:g}):o||i||t.length===0?e.jsx(Ei,{isError:i,isLoading:o,hasViews:t.length>0}):s&&!_?e.jsxs("p",{className:Ot,children:[l," active refinements on All Library. Save them to return to this exact slice later."]}):y?e.jsxs("p",{className:Ot,children:["This active view currently matches ",Be(u)," ","stories. The saved query stays available and will fill again as your Library changes."]}):null,d==="save"?e.jsx("div",{className:Es,children:e.jsx(Pi,{capturedQuery:m,saveAsNew:x,activeView:_,existingNames:t.map(A=>A.name),isPending:N?.creating,errorMessage:N?.errorMessage,onClose:F,onSave:A=>{if(S.onSaveView){S.onSaveView(A);return}S.onSelectView(_?.id??Je)}})}):null,d==="manage"?e.jsx("div",{className:Es,children:e.jsx(Mi,{views:t,activeViewId:a,allLibraryCount:c,mutationState:N,onClose:F,onSelectView:S.onSelectView,onTogglePin:S.onTogglePin,onRenameView:S.onRenameView,onDeleteView:S.onDeleteView,onMoveView:S.onMoveView})}):null]})})}function Ud({activeView:t,dirty:a}){return t?{id:"library-view",label:a?"View edited":"View",value:t.name,ariaLabel:a?`Library View ${t.name}, unsaved edits`:`Library View ${t.name}`}:null}function Fs({title:t,eyebrow:a="Library views",description:n}){return e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"mf-header-eyebrow",children:[e.jsx(vt,{className:"h-4 w-4","aria-hidden":!0}),a]}),e.jsx("h2",{className:"mf-header-title",children:t}),n?e.jsx("p",{className:"mf-header-count",children:n}):null]})}function Yd({views:t,activeViewId:a,dirty:n,hasAdHocQuery:s,isError:i=!1,isLoading:o=!1,allLibraryCount:c,visibleCount:u,activeFilterCount:l,zeroResultView:m=!1,mutationState:d,handlers:x}){const y=Li(t,a),g=a===null||a===Je,N=t.filter(C=>C.pinned),S=y&&!y.pinned?[y,...N.filter(C=>C.id!==y.id)]:N;return e.jsx(Cn,{title:"Library Views",children:e.jsxs("div",{className:Od,children:[e.jsxs("div",{className:Dd,children:[e.jsxs("span",{className:gi,children:[e.jsx(vt,{"aria-hidden":!0}),"Views"]}),e.jsx("button",{type:"button",className:"text-xs font-medium text-[var(--ink-3)] outline-none hover:text-[var(--ink)] focus-visible:shadow-ring","aria-label":`Manage Library Views, ${t.length} saved views`,onClick:x.onOpenManage,children:"Manage"})]}),e.jsxs("div",{className:Fd,"aria-label":"Saved Library Views",children:[e.jsxs("button",{type:"button",className:Ds,"aria-pressed":g,"aria-label":`Select Library View: All Library, ${Be(c)} stories in All Library${g&&n?", unsaved edits":""}`,onClick:()=>x.onSelectView(Je),children:[e.jsx(vt,{"aria-hidden":!0}),e.jsx("span",{className:"min-w-0 truncate",children:"All Library"}),e.jsx("span",{className:ia,children:Be(c)}),g&&n?e.jsx("span",{className:$a}):null]}),S.map(C=>e.jsxs("button",{type:"button",className:Ds,"aria-pressed":C.id===a,"aria-label":[C.id===a?`Active Library View: ${C.name}`:`Select Library View: ${C.name}`,C.pinned?"pinned":null,typeof C.liveCount=="number"?`${Be(C.liveCount)} matching stories`:null,C.id===a&&n?"unsaved edits":null].filter(Boolean).join(", "),onClick:()=>x.onSelectView(C.id),children:[e.jsx(Ai,{pinned:C.pinned,active:C.id===a}),e.jsx("span",{className:"min-w-0 truncate",children:C.name}),typeof C.liveCount=="number"?e.jsx("span",{className:ia,children:Be(C.liveCount)}):null,C.id===a&&n?e.jsx("span",{className:$a}):null]},C.id))]}),e.jsx(Ti,{activeView:y,dirty:n,hasAdHocQuery:s,activeFilterCount:l,handlers:x,mutationState:d,compact:!0}),o||i||t.length===0?e.jsx(Ei,{isError:i,isLoading:o,hasViews:t.length>0,compact:!0}):null,m?e.jsxs("div",{className:Ci,children:["This saved view matches ",e.jsx("strong",{children:Be(u)})," ","stories right now. It remains private and will update automatically when matching stories appear."]}):null]})})}function Pi({capturedQuery:t,saveAsNew:a,activeView:n,existingNames:s=[],isPending:i=!1,errorMessage:o,onClose:c,onSave:u,showHeader:l=!0}){const m=a&&n?`${n.name} copy`:"",[d,x]=r.useState(m),[y,g]=r.useState(!1),[N,S]=r.useState(!!m),[C,_]=r.useState(!1),p=r.useRef(null),b=r.useId(),k=r.useId(),j=r.useId(),O=a?"Save as a new view":"Save current view",R=d.trim(),F=Rn(d),z=!!(F&&(N||C||R.length>ta))?F:null,Q=_i({name:d,existingNames:s,currentName:void 0}),te=!F&&!i,v=[j,z?b:null,Q?k:null].filter(f=>!!f).join(" ");r.useEffect(()=>{p.current?.focus(),p.current?.select()},[]);const $=r.useCallback(()=>{_(!0),te&&u({name:R,pinned:y})},[te,u,y,_,R]);return e.jsxs("section",{className:l?xd:"rounded-sm border border-[var(--line-strong)] bg-[var(--card)]","aria-label":O,children:[l?e.jsxs("div",{className:gd,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:fi,children:"Private saved query"}),e.jsx("h3",{className:vi,children:O}),e.jsx("p",{className:yi,children:"Captures search, sort, and filters. Stories stay in your Library; the result set updates as metadata changes."})]}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":"Close save view panel",onClick:c,children:e.jsx(wt,{"aria-hidden":!0})})]}):null,e.jsxs("div",{className:L(l?vd:fd,Nd),children:[e.jsxs("div",{className:"min-w-0 space-y-2.5",children:[e.jsxs("label",{className:"tf-row block",children:[e.jsxs("span",{className:"tf-label",children:[e.jsx("span",{children:"View name"}),e.jsx("span",{className:"tf-hint",children:"private to you"})]}),e.jsx("span",{className:"tf-field is-focus mt-1",children:e.jsx("input",{ref:p,value:d,onChange:f=>{S(!0),x(f.currentTarget.value)},onBlur:()=>S(!0),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),$())},placeholder:"Longfic in progress","aria-invalid":!!z,"aria-describedby":v})}),e.jsxs("span",{className:wi,children:[e.jsxs("span",{id:j,className:ji,children:[R.length,"/",ta," characters"]}),z?e.jsx("span",{id:b,className:Ni,role:"alert",children:z}):Q?e.jsx("span",{id:k,className:Si,children:"Duplicate names are allowed."}):null]})]}),o?e.jsx("div",{className:ki,role:"alert",children:o}):null,e.jsxs("div",{className:yd,children:[e.jsx("p",{className:wd,children:"Captured query"}),e.jsxs("div",{className:jd,children:[e.jsxs("span",{className:un,children:["Sort: ",t.sortLabel]}),t.search?e.jsxs("span",{className:un,children:["Search: ",t.search]}):null,t.chips.length?t.chips.map(f=>e.jsx("span",{className:un,children:f},f)):e.jsx("span",{className:"text-sm italic text-[var(--ink-4)]",children:"No filters. This view saves the whole shelf with the selected sort."})]})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 rounded-sm bg-[color-mix(in_oklab,var(--card)_70%,transparent)] p-3",children:[e.jsxs("button",{type:"button",className:"tf-toggle-row rounded-sm","aria-pressed":y,disabled:i,onClick:()=>g(f=>!f),children:[e.jsxs("span",{className:"tf-toggle-main",children:[e.jsx("span",{className:"tf-toggle-title",children:"Pin to views row"}),e.jsx("span",{className:"tf-toggle-sub",children:"Pinned views can show a live count."})]}),e.jsx("span",{className:L("tf-switch",y&&"is-on"),"aria-hidden":!0})]}),e.jsxs("div",{className:"mt-auto flex gap-2",children:[e.jsx(de,{type:"button",variant:"outline",onClick:c,disabled:i,children:"Cancel"}),e.jsx(de,{type:"button",variant:"solid",className:"flex-1",disabled:!te,loading:i,onClick:$,leftIcon:e.jsx(ut,{}),children:"Save view"})]})]})]})]})}function Mi({views:t,activeViewId:a,allLibraryCount:n,mutationState:s,onClose:i,onSelectView:o,onTogglePin:c,onRenameView:u,onDeleteView:l,onMoveView:m,showHeader:d=!0}){const x=t.filter(f=>f.pinned),y=t.filter(f=>!f.pinned),g=x[0]?.id??y[0]?.id??null,N=r.useRef(null),S=r.useRef(null),C=r.useRef(null),[_,p]=r.useState(null),[b,k]=r.useState(""),[j,O]=r.useState(null),R=r.useMemo(()=>t.map(f=>f.name),[t]),F=!!(s?.creating||s?.updatingViewId||s?.deletingViewId||s?.reorderingViewId);r.useEffect(()=>{N.current?.focus()},[]),r.useEffect(()=>{_&&(S.current?.focus(),S.current?.select())},[_]),r.useEffect(()=>{j&&(t.some(f=>f.id===j.id)||O(null))},[j,t]);const A=r.useCallback(()=>{O(null),window.setTimeout(()=>{C.current?.focus()},0)},[O]),z=r.useCallback(f=>{p(f.id),k(f.name)},[]),Q=r.useCallback(()=>{p(null),k("")},[]),te=r.useCallback(f=>{const U=b.trim();if(!Rn(b)){if(U===f.name){Q();return}u(f.id,U),Q()}},[Q,b,u]),v=(f,U,oe,se)=>{const G=_===f.id,I=s?.updatingViewId===f.id,E=s?.deletingViewId===f.id,Y=s?.reorderingViewId===f.id,W=G?Rn(b):null,J=G&&_i({name:b,existingNames:R,currentName:f.name}),X=G&&!W&&b.trim()!==f.name&&!I,ee=`library-view-rename-help-${f.id}`,le=`library-view-rename-error-${f.id}`,ae=`library-view-rename-duplicate-${f.id}`;return e.jsxs("div",{className:Rd,children:[e.jsxs("div",{className:Ad,"aria-label":`Reorder ${f.name}`,children:[e.jsx("button",{type:"button",className:Ps,"aria-label":`Move ${f.name} up in ${se}`,title:`Move ${f.name} up`,disabled:oe===0||!!s?.reorderingViewId,onClick:()=>m(f.id,"up"),children:e.jsx(qr,{"aria-hidden":!0})}),e.jsx("button",{type:"button",className:Ps,"aria-label":`Move ${f.name} down in ${se}`,title:`Move ${f.name} down`,disabled:oe===U.length-1||!!s?.reorderingViewId,onClick:()=>m(f.id,"down"),children:e.jsx(Dn,{"aria-hidden":!0})})]}),e.jsx("button",{type:"button","aria-label":f.pinned?`Unpin ${f.name}`:`Pin ${f.name}`,"aria-pressed":f.pinned,className:Td,disabled:F,onClick:()=>c(f.id),children:I?e.jsx("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":!0}):f.pinned?e.jsx(Gr,{"aria-hidden":!0}):e.jsx(Ma,{"aria-hidden":!0})}),G?e.jsxs("form",{className:Ed,onSubmit:P=>{P.preventDefault(),te(f)},children:[e.jsxs("label",{className:"sr-only",htmlFor:`library-view-rename-${f.id}`,children:["Rename ",f.name]}),e.jsx("input",{id:`library-view-rename-${f.id}
2`,ref:S,className:Pd,value:b,onChange:P=>k(P.currentTarget.value),onKeyDown:P=>{P.key==="Escape"&&(P.preventDefault(),Q())},"aria-invalid":!!W,"aria-describedby":[ee,W?le:null,J?ae:null].filter(Boolean).join(" ")}),e.jsxs("span",{className:wi,children:[e.jsxs("span",{id:ee,className:ji,children:[b.trim().length,"/",ta," characters"]}),W?e.jsx("span",{id:le,className:Ni,role:"alert",children:W}):J?e.jsx("span",{id:ae,className:Si,children:"Duplicate names are allowed."}):null]}),e.jsxs("div",{className:Md,children:[e.jsx(de,{type:"button",variant:"ghost",size:"sm",onClick:Q,disabled:I,children:"Cancel"}),e.jsx(de,{type:"submit",variant:"solid",size:"sm",loading:I,disabled:!X,children:"Rename"})]})]}):e.jsx("button",{type:"button",ref:f.id===g?N:void 0,className:Ms,"aria-label":[f.id===a?`Active Library View: ${f.name}`:`Select Library View: ${f.name}`,f.pinned?"pinned":"unpinned",typeof f.liveCount=="number"?`${Be(f.liveCount)} matching stories`:"no live count"].join(", "),"aria-pressed":f.id===a,onClick:()=>o(f.id),children:e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:Is,children:f.name}),e.jsxs("span",{className:Os,children:[f.pinned&&typeof f.liveCount=="number"?`${Be(f.liveCount)} stories · `:"unpinned · no live count · ",f.summary]})]})}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":`Rename ${f.name}`,title:`Rename ${f.name}`,disabled:F||G,onClick:()=>z(f),children:e.jsx(Rl,{"aria-hidden":!0})}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":`Delete ${f.name}`,title:`Delete ${f.name}`,loading:E,disabled:F||G||Y,onClick:P=>{C.current=P.currentTarget,O(f)},className:"text-[var(--rust)] hover:text-[var(--rust)]",children:e.jsx(Oa,{"aria-hidden":!0})})]},f.id)},$=(f,U,oe)=>e.jsxs("div",{className:Cd,children:[e.jsxs("div",{className:_d,children:[e.jsx("span",{children:f}),e.jsx("span",{"aria-label":`${U.length} ${f.toLowerCase()}`,children:U.length})]}),U.length?U.map((se,G)=>v(se,U,G,f)):e.jsx("p",{className:Id,children:oe})]});return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:d?hd:"rounded-sm border border-[var(--line-strong)] bg-[var(--card)]","aria-label":"Manage Library Views",children:[d?e.jsxs("div",{className:bd,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:fi,children:"Manage views"}),e.jsx("h3",{className:vi,children:"Reorder, pin, rename, or delete"}),e.jsx("p",{className:yi,children:"Deleting a view removes only the saved query. Stories and Collections stay in your Library."})]}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":"Close manage views panel",onClick:i,children:e.jsx(wt,{"aria-hidden":!0})})]}):null,e.jsxs("div",{className:Sd,children:[s?.errorMessage?e.jsx("div",{className:ki,role:"alert",children:s.errorMessage}):null,e.jsxs("div",{className:kd,children:[e.jsx("span",{className:Ld,children:e.jsx(kl,{"aria-hidden":!0})}),e.jsx("button",{type:"button",ref:g?void 0:N,className:Ms,"aria-label":`Select Library View: All Library, ${Be(n)} stories in All Library`,"aria-pressed":!a,onClick:()=>o(Je),children:e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:Is,children:"All Library"}),e.jsx("span",{className:Os,children:"System view"})]})}),e.jsx("span",{className:ia,children:Be(n)})]}),$("Pinned views",x,"Pin saved views to keep them in the desktop row."),$("Unpinned views",y,"Unpinned views stay private and available from Manage.")]})]}),e.jsx($t,{open:!!j,surface:"archive",variant:"danger",title:j?`Delete "${j.name}" view?`:"Delete saved view?",description:"This deletes only the saved Library View. It does not delete stories, Collections, notes, tags, or reading progress.",confirmLabel:"Delete view",cancelLabel:"Cancel",loading:!!(j&&s?.deletingViewId===j.id),onCancel:A,onConfirm:()=>{j&&(l(j.id),O(null))}})]})}const Kd=Xl,zd=`${ri} ${ac} hidden min-w-0 sm:flex`,qd=`${ri} ${Zl}`,Gd=`${nc} sm:min-w-[280px] sm:flex-[1_1_32rem]`,Qd=sc,Xd=rc,Zd=ic,Jd="inline-flex h-10 shrink-0 items-center justify-center gap-2 rounded-[10px] border border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] px-3 font-sans text-[13px] font-medium leading-none text-[var(--ink-2)] outline-none transition hover:border-[var(--line-strong)] hover:bg-[var(--card)] hover:text-[var(--ink)] focus-visible:shadow-ring data-[popup-open]:border-[var(--line-strong)] data-[popup-open]:bg-[var(--card)] data-[popup-open]:text-[var(--ink)]",eu="h-3.5 w-3.5 shrink-0",tu="inline-flex shrink-0 items-center gap-0.5 rounded-[10px] border border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] p-[3px]",au="inline-flex h-8 items-center gap-1.5 rounded-[7px] border border-transparent px-3 font-sans text-[12.5px] font-medium leading-none tracking-normal text-[var(--ink-3)] transition hover:text-[var(--ink)] [&_svg]:h-[14px] [&_svg]:w-[14px] [&_svg]:shrink-0",nu="border-[var(--line-strong)] bg-[var(--card)] text-[var(--ink)] hover:text-[var(--ink)] [&_svg]:text-[var(--rust)]",su="flex items-stretch gap-2 border-b border-[var(--line)] bg-[var(--paper)] px-4 pb-3 sm:hidden",ru="grid min-h-10 min-w-0 flex-1 grid-cols-2 gap-0.5 rounded-[10px] border border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] p-[3px]",iu="inline-flex min-w-0 items-center justify-center gap-1.5 rounded-[7px] border border-transparent px-2 text-[12.5px] font-medium leading-none text-[var(--ink-3)] transition hover:text-[var(--ink)] [&_svg]:h-[15px] [&_svg]:w-[15px] [&_svg]:shrink-0",ou="border-[var(--line-strong)] bg-[var(--card)] text-[var(--ink)] [&_svg]:text-[var(--rust)]",$s="inline-flex min-h-10 shrink-0 items-center justify-center gap-1.5 rounded-[10px] border border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] px-3 text-[12.5px] font-medium leading-none text-[var(--ink-2)] outline-none transition hover:border-[var(--line-strong)] hover:bg-[var(--card-2)] hover:text-[var(--ink)] focus-visible:shadow-ring aria-expanded:border-[var(--line-strong)] aria-expanded:bg-[var(--card-2)] [&_svg]:h-[14px] [&_svg]:w-[14px] [&_svg]:shrink-0",lu="absolute right-1 top-1 inline-flex h-4 min-w-4 items-center justify-center rounded-pill bg-[var(--rust)] px-1 font-mono text-[9px] font-semibold leading-none text-[var(--paper)]",cu="flex w-full max-w-full min-w-0 items-stretch gap-2",du="max-h-64 overflow-hidden opacity-100 transition-[max-height,opacity,transform] duration-[260ms] ease-[cubic-bezier(.2,.7,.2,1)] motion-reduce:transition-opacity motion-reduce:duration-[80ms]",uu="max-h-0 -translate-y-1.5 opacity-0 motion-reduce:translate-y-0",mu="space-y-3",Ii=tc,pu=Jl,hu=ec,xu="ml-auto shrink-0 font-mono text-[11px] uppercase leading-none tracking-[0.18em] text-[var(--ink-4)]",ua={value:"LAST_READ_DESC",label:"Recently read",shortLabel:"Recent"},oa=[{value:"BEST_MATCH",label:"Search relevance",shortLabel:"Relevance"},ua,{value:"STORY_UPDATE_DESC",label:"Recently updated",shortLabel:"Updates"},{value:"WORK_UPDATED_DESC",label:"Work updated",shortLabel:"Work updated"},{value:"UPDATED_DESC",label:"Recently edited",shortLabel:"Edited"},{value:"TITLE_ASC",label:"Title (A–Z)",shortLabel:"Title A–Z"},{value:"TITLE_DESC",label:"Title (Z–A)",shortLabel:"Title Z–A"},{value:"RATING_DESC",label:"Star rating (high → low)",shortLabel:"Stars high"},{value:"RATING_ASC",label:"Star rating (low → high)",shortLabel:"Stars low"}],ot="tf-opt outline-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-45 data-[highlighted]:bg-[var(--paper-2)] data-[highlighted]:text-[var(--ink)]",Jt="tf-label px-[14px] pb-1 pt-2",bu=[{value:"compact",label:"Compact",description:"Scan reading activity quickly",icon:Ll},{value:"browse",label:"Detailed",description:"Show more story details and controls",icon:vt}];function gu({sortOptions:t,bulkMode:a,canAdd:n,onAdd:s,shareCount:i,shareTitle:o,onShare:c,canCreateCollectionFromTags:u,canCreateCollectionFromCurrentFilter:l,onCreateCollectionFromTags:m,onCreateCollectionFromCurrentFilter:d,onToggleBulk:x,sort:y,onSortChange:g,showAdd:N=!0,showSelect:S=!0,showSort:C=!0,triggerAriaLabel:_="More library actions"}){return e.jsxs(Zr,{children:[e.jsx(Jr,{className:L(Ii,"data-[popup-open]:border-[var(--ink-3)] data-[popup-open]:text-[var(--ink)]"),"aria-label":_,children:e.jsx(Tl,{"aria-hidden":!0})}),e.jsx(ei,{children:e.jsx(ti,{side:"bottom",align:"end",sideOffset:6,children:e.jsxs(ai,{className:"library-app archive-editorial-shell tf-pop !relative !left-auto !right-auto !top-auto !z-[1340] !min-w-[14rem] outline-none",children:[e.jsxs(Zt,{children:[e.jsx("div",{className:Jt,children:"Library"}),N&&n&&!a?e.jsx(it,{className:ot,onClick:()=>{s()},children:e.jsx("span",{className:"tf-opt-label",children:"Add manually"})}):null,e.jsxs(it,{className:ot,disabled:i===0,onClick:()=>{i>0&&c()},title:o,children:[e.jsx("span",{className:"tf-opt-label",children:"Share"}),i>0?e.jsx("span",{className:"tf-opt-meta",children:i}):null]}),S?e.jsx(it,{className:ot,onClick:()=>{x()},children:e.jsx("span",{className:"tf-opt-label",children:a?"Cancel selection":"Select stories"})}):null]}),a?null:e.jsxs(e.Fragment,{children:[e.jsx(kn,{className:"my-1 h-px bg-[var(--line)]"}),e.jsxs(Zt,{children:[e.jsx("div",{className:Jt,children:"Collections"}),e.jsx(it,{className:ot,disabled:!l,onClick:()=>{l&&d?.()},children:e.jsx("span",{className:"tf-opt-label",children:"Create collection from current filters"})}),e.jsx(it,{className:ot,disabled:!u,onClick:()=>{u&&m?.()},children:e.jsx("span",{className:"tf-opt-label",children:"Create collection from private tags"})})]})]}),C?e.jsxs(e.Fragment,{children:[e.jsx(kn,{className:"my-1 h-px bg-[var(--line)]"}),e.jsx("div",{className:Jt,children:"Sort by"}),e.jsx(Zt,{children:t.map(p=>e.jsxs(it,{className:L(ot,y===p.value&&"is-on"),onClick:()=>
2g(p.value),children:[e.jsx("span",{className:"tf-opt-label",children:p.label}),y===p.value?e.jsx("span",{className:"tf-opt-mark","aria-hidden":!0,children:e.jsx(sa,{})}):null]},p.value))})]}):null]})})})]})}function Oi(t,a=oa){return a.find(n=>n.value===t)??ua}function fu({sortOptions:t,sort:a,onSortChange:n,groupingMode:s,onGroupingModeChange:i}){const o=Oi(a,t),c=s==="series"?" · Series":"";return e.jsxs(Zr,{children:[e.jsxs(Jr,{className:Jd,"aria-label":`Change sort, current sort ${o.label}${s==="series"?", grouped by series":""}`,children:[e.jsxs("span",{children:[o.shortLabel,c]}),e.jsx(Al,{className:eu,"aria-hidden":!0})]}),e.jsx(ei,{children:e.jsx(ti,{side:"bottom",align:"end",sideOffset:6,children:e.jsxs(ai,{className:"library-app archive-editorial-shell tf-pop !relative !left-auto !right-auto !top-auto !z-[1340] !min-w-[13rem] outline-none",children:[e.jsx("div",{className:Jt,children:"Sort by"}),e.jsx(Zt,{children:t.map(u=>e.jsxs(it,{className:L(ot,a===u.value&&"is-on"),onClick:()=>n(u.value),children:[e.jsx("span",{className:"tf-opt-label",children:u.label}),a===u.value?e.jsx("span",{className:"tf-opt-mark","aria-hidden":!0,children:e.jsx(sa,{})}):null]},u.value))}),e.jsx(kn,{className:"my-1 h-px bg-[var(--line)]"}),e.jsx("div",{className:Jt,children:"Group by"}),e.jsx(Zt,{children:[{value:"none",label:"No grouping"},{value:"series",label:"Series"}].map(u=>e.jsxs(it,{className:L(ot,s===u.value&&"is-on"),onClick:()=>i?.(u.value),children:[e.jsx("span",{className:"tf-opt-label",children:u.label}),s===u.value?e.jsx("span",{className:"tf-opt-mark","aria-hidden":!0,children:e.jsx(sa,{})}):null]},u.value))})]})})})]})}function vu({sortOptions:t=oa,sort:a,onSortChange:n,groupingMode:s="none",onGroupingModeChange:i}){return e.jsxs(e.Fragment,{children:[e.jsx(Cn,{title:"Sort by",children:e.jsx(Cs,{label:"Sort library stories",children:t.map(o=>e.jsx(on,{active:a===o.value,onClick:()=>n(o.value),children:o.label},o.value))})}),e.jsx(Cn,{title:"Group by",children:e.jsxs(Cs,{label:"Group library stories",children:[e.jsx(on,{active:s==="none",onClick:()=>i?.("none"),children:"No grouping"}),e.jsx(on,{active:s==="series",onClick:()=>i?.("series"),children:"Series"})]})})]})}function yu({storyUpdatesEnabled:t=!0,totalCount:a,resultCount:n,bulkMode:s,onToggleBulk:i,canAdd:o,onAdd:c,selectedCount:u,visibleCount:l,onShare:m,canCreateCollectionFromTags:d=!1,canCreateCollectionFromCurrentFilter:x=!1,onCreateCollectionFromTags:y,onCreateCollectionFromCurrentFilter:g,searchValue:N,onSearchChange:S,onClearSearch:C,searchRef:_,sort:p,onSortChange:b,showFilters:k,onToggleFilters:j,activeFilterCount:O,filtersPanelId:R="filters-panel",mobileChips:F=[],mobilePresentation:A="default",mobileRuntime:z="browser",mobileChromeState:Q="full",mobileTitle:te="Library.",mobileTitleAriaLabel:v,mobileStats:$,mobileCollapsedStats:f,onMobileSearchActiveChange:U,densityMode:oe="compact",onDensityModeChange:se,groupingMode:G="none",onGroupingModeChange:I,variant:E="default"}){const[Y,W]=r.useState(!1),[J,X]=r.useState(!1),[ee,le]=r.useState(!1),[ae,P]=r.useState(!1),re=u||l,me=u?`Share selected stories (${u})`:`Share visible stories (${l})`,ce=n??l,We=typeof n=="number"?`Show ${n.toLocaleString()} ${n===1?"story":"stories"}`:"Show stories",pe=typeof a=="number"?`${ce.toLocaleString()} of ${a.toLocaleString()} matching`:null,De=E==="sticky",Se=t?oa:oa.filter(ke=>ke.value!=="STORY_UPDATE_DESC"),M=Oi(p,Se),T=G==="series"?`${M.shortLabel} · Series`:M.shortLabel,K=F,q=Q==="collapsed",fe=ee||ae;r.useEffect(()=>{U?.(fe)},[fe,U]);const be=()=>W(!1),we=ke=>{be(),ke()},ve=ke=>e.jsxs("div",{className:Gd,children:[e.jsx(Nn,{className:Qd,"aria-hidden":!0}),e.jsx(jn,{placeholder:"Search title, author, fandom, tag...",value:N,onChange:ge=>S(ge.target.value),ref:ke,"data-library-toolbar-search":!0,className:Xd}),N&&e.jsx(ct,{type:"button","aria-label":"Clear search",onClick:C,className:Zd,variant:"ghost",children:"×"})]}),Te=(ke=!1)=>e.jsx("div",{className:ke?ru:tu,role:"group","aria-label":"Library density",children:bu.map(ge=>{const tt=ge.icon;return e.jsxs("button",{type:"button",className:L(ke?iu:au,oe===ge.value&&(ke?ou:nu)),"aria-pressed":oe===ge.value,title:ge.description,onClick:()=>se?.(ge.value),children:[e.jsx(tt,{"aria-hidden":!0}),ge.label]},ge.value)})}),He=()=>e.jsx(xc,{title:te,titleAriaLabel:v,collapsedTitle:te,meta:$,collapsedMeta:f,collapsed:q,runtime:z,className:"relative",actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Rs,"aria-label":"Search library","aria-haspopup":"dialog","aria-expanded":ee,"aria-controls":"library-mobile-search-sheet",onClick:()=>le(!0),children:e.jsx(Nn,{"aria-hidden":!0})}),e.jsxs("button",{type:"button",className:Rs,"aria-label":O?`Open filters, ${O} active`:"Open filters","aria-expanded":k,"aria-controls":R,onClick:j,children:[e.jsx(vs,{"aria-hidden":!0}),O?e.jsx("span",{className:lu,children:O}):null]})]}),controls:e.jsxs("div",{className:cu,children:[Te(!0),e.jsxs("button",{type:"button",className:$s,"aria-label":`Sort library stories, current sort ${M.label}${G==="series"?", grouped by series":""}`,"aria-haspopup":"dialog","aria-expanded":J,"aria-controls":"library-mobile-sort-sheet",onClick:()=>X(!0),title:"Sort library stories",children:[e.jsx(fs,{"aria-hidden":!0}),e.jsx("span",{children:T})]})]})});return e.jsxs("div",{"data-archive-toolbar":!0,"data-library-toolbar":!0,"data-runtime":z,"data-chrome":Q,className:Kd,children:[A==="nativeCompact"?He():e.jsxs("div",{className:L(du,q&&uu),"data-library-mobile-browser-collapse-region":!0,"aria-hidden":q,children:[e.jsx(oc,{className:qd,searchLabel:"Search library",searchPlaceholder:"Search title, author, tag...",searchValue:N,onSearchChange:S,onClearSearch:C,searchRef:_,searchInputProps:{"data-library-toolbar-search":!0,onBlur:()=>P(!1),onFocus:()=>P(!0),tabIndex:q?-1:void 0},refineIconOnly:!0,refineActiveCount:O,refineExpanded:k,refineControlsId:R,onRefine:j,moreLabel:"More library actions",moreExpanded:Y,moreControlsId:"library-mobile-actions-sheet",onMore:()=>W(!0),chips:K,chipRailLabel:"Active library refinements",controlsTabIndex:q?-1:void 0}),e.jsxs("div",{className:su,children:[Te(!0),e.jsxs("button",{type:"button",className:$s,"aria-label":`Sort library stories, current sort ${M.label}${G==="series"?", grouped by series":""}`,"aria-haspopup":"dialog","aria-expanded":J,"aria-controls":"library-mobile-sort-sheet",tabIndex:q?-1:void 0,onClick:()=>X(!0),title:"Sort library stories",children:[e.jsx(fs,{"aria-hidden":!0}),e.jsx("span",{children:T})]})]})]}),e.jsx(rn,{id:"library-mobile-sort-sheet",open:J,onOpenChange:X,title:"Sort library",eyebrow:"Sort",closeLabel:"Close library sort",footer:e.jsx("button",{type:"button",className:"a-btn is-primary w-full justify-center",onClick:()=>X(!1),children:We}),children:e.jsx(vu,{sortOptions:Se,sort:p,onSortChange:b,groupingMode:G,onGroupingModeChange:I})}),e.jsx(rn,{id:"library-mobile-search-sheet",open:ee,onOpenChange:le,title:"Search library",eyebrow:"Search",closeLabel:"Close library search",footer
2:e.jsx("button",{type:"button",className:"a-btn is-primary w-full justify-center",onClick:()=>le(!1),children:"Done"}),children:e.jsx("div",{className:mu,children:ve(_)})}),e.jsxs(rn,{id:"library-mobile-actions-sheet",open:Y,onOpenChange:W,title:"Library actions",eyebrow:"More",closeLabel:"Close library actions",children:[o&&!s?e.jsx(Qt,{icon:e.jsx(mt,{}),label:"Add manually",description:"For SpaceBattles, Royal Road, Wattpad, and other unsupported sites",onClick:()=>we(c)}):null,e.jsx(Qt,{icon:e.jsx(sa,{}),label:s?"Done selecting":"Select stories",description:"Bulk status, tags, collections",onClick:()=>we(i)}),e.jsx(Qt,{icon:e.jsx(Sn,{}),label:u?"Share selected stories":"Share visible stories",description:me,disabled:re===0,onClick:()=>{re>0&&we(m)}}),s?null:e.jsxs(e.Fragment,{children:[e.jsx(Qt,{icon:e.jsx(Qr,{}),label:"Create collection from current filters",description:"Use the matching Library result set",disabled:!x,onClick:()=>{x&&we(g??(()=>{}))}}),e.jsx(Qt,{icon:e.jsx(Xr,{}),label:"Create collection from private tags",description:"Seed a collection from your tag set",disabled:!d,onClick:()=>{d&&we(y??(()=>{}))}})]})]}),e.jsxs("div",{className:L(zd,De&&"sm:py-3"),"data-archive-toolbar-surface":!0,children:[ve(_),Te(),e.jsx(fu,{sortOptions:Se,sort:p,onSortChange:b,groupingMode:G,onGroupingModeChange:I}),e.jsxs("button",{type:"button",className:pu,onClick:i,"aria-pressed":s,"aria-label":s?"Done selecting stories":"Select stories",title:s?"Done":"Select stories",children:[e.jsx(sa,{"aria-hidden":!0}),e.jsx("span",{children:s?"Done":"Select"})]}),e.jsxs("button",{type:"button",className:L(Ii,k&&"border-[var(--ink-3)] text-[var(--ink)]"),onClick:j,title:"Filter your library","aria-label":O?`Open filters, ${O} active`:"Open filters","aria-expanded":k,"aria-controls":R,children:[e.jsx(vs,{"aria-hidden":!0}),O?e.jsx("span",{className:hu,children:O}):null]}),e.jsx(gu,{sortOptions:Se,bulkMode:s,canAdd:o,onAdd:c,shareCount:re,shareTitle:me,onShare:m,canCreateCollectionFromTags:d,canCreateCollectionFromCurrentFilter:x,onCreateCollectionFromTags:y,onCreateCollectionFromCurrentFilter:g,onToggleBulk:i,sort:p,onSortChange:b,showAdd:!0,showSelect:!1,showSort:!1,triggerAriaLabel:"More desktop library actions"}),pe?e.jsx("p",{className:xu,children:pe}):null]})]})}const Ca=et("relative z-0 mx-auto grid min-w-0 max-w-none grid-cols-1 items-start gap-0",{variants:{splitDetail:{false:"",true:"lg:mt-5"},densityMode:{compact:"gap-0 max-sm:-mx-4",browse:"gap-0 max-[899px]:pt-[13px] max-sm:gap-3"}},defaultVariants:{splitDetail:!1,densityMode:"compact"}}),wu="",ju="min-[900px]:overflow-hidden min-[900px]:rounded-[12px] min-[900px]:border min-[900px]:border-[var(--line)] min-[900px]:bg-[var(--card-sunk,var(--paper-2))]",Nu="hidden min-[900px]:grid min-[900px]:min-h-[34px] min-[900px]:grid-cols-[140px_minmax(0,1fr)_52px_124px_34px] min-[900px]:items-center min-[900px]:gap-[18px] min-[900px]:border-b min-[900px]:border-[var(--line)] min-[900px]:px-4 min-[900px]:pl-5",_a="font-mono text-[9.5px] font-medium uppercase leading-none tracking-[0.14em] text-[var(--ink-4)]",Su="col-span-full min-w-0",ku="grid min-h-13 grid-cols-[26px_minmax(0,1fr)_44px] items-stretch border-b border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] min-[900px]:min-h-8 min-[900px]:grid-cols-[30px_minmax(0,1fr)_32px]",Ws="flex min-w-0 items-center gap-2 px-2 py-2 text-left outline-none transition hover:bg-[color-mix(in_oklab,var(--card)_72%,transparent)] focus-visible:shadow-ring min-[900px]:px-3 min-[900px]:py-1",Cu="size-3.5 shrink-0 text-[var(--ink-3)] transition-transform motion-reduce:transition-none",Bs="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-2 gap-y-0.5",Vs="font-mono text-[9px] font-semibold uppercase leading-none tracking-[0.16em] text-[var(--ink-4)]",Hs="max-w-full truncate font-mono text-[10.5px] font-medium uppercase leading-tight tracking-[0.14em] text-[var(--ink-2)]",Us="min-w-0 font-sans text-[11.5px] leading-snug text-[var(--ink-4)]",_u="inline-flex min-h-11 w-11 shrink-0 items-center justify-center self-stretch text-[var(--ink-3)] outline-none transition hover:bg-[var(--card)] hover:text-[var(--rust)] focu
2s-visible:shadow-ring min-[900px]:min-h-8 min-[900px]:w-8 [&_svg]:size-3.5",Ru="min-w-0",Lu="grid min-w-0 grid-cols-[26px_minmax(0,1fr)] min-[900px]:grid-cols-[30px_minmax(0,1fr)]",Au="min-w-0",Tu="relative min-h-full text-[var(--ink-4)]",Eu="absolute bottom-0 right-2 top-0 w-px bg-[var(--line-strong,var(--line))]",Pu="absolute right-[5px] top-1/2 h-px w-[7px] -translate-y-1/2 bg-[var(--line-strong,var(--line))]",Mu="right-1 h-0.5 w-[9px] bg-[var(--rust)]",Iu="absolute right-[17px] top-1/2 -translate-y-1/2 font-mono text-[9px] leading-none text-[var(--ink-4)]",Ou="text-[var(--rust)]";function Du({onAddManually:t}){const a=On(),n=r.useMemo(()=>oi(),[]),s=r.useMemo(()=>li(n),[n]),i=r.useMemo(()=>ci(n),[n]),o=r.useMemo(()=>null,[a.search]),c=di({fixtureStatus:o});if(c.status.phase==="checking")return e.jsx(Di,{});const u=c.status.phase==="detected";return e.jsxs("div",{className:"mx-auto flex min-h-[calc(100svh_-_13rem)] w-full max-w-3xl flex-col justify-center px-4 pb-8 pt-4 sm:min-h-0 sm:px-1 sm:pb-12 sm:pt-8",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3 font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:[e.jsx(Va,{className:"h-4 w-4 text-[var(--accent-editorial)]","aria-hidden":!0}),"My Library",e.jsx("span",{className:"h-px w-10 bg-border-strong","aria-hidden":!0}),"0 stories"]}),e.jsx("h2",{className:"font-landing-serif text-3xl font-semibold leading-tight text-content-primary sm:text-4xl",children:u?"Trace is installed.":"Add stories to your library."}),e.jsx("p",{className:"mt-3 max-w-[58ch] text-base leading-7 text-content-muted",children:u?"Open AO3 or FanFiction.net and use Trace as you browse to start adding stories.":"Add the Trace extension to save stories as you browse, or add one manually."}),e.jsxs("div",{className:"mt-6 flex flex-col gap-2 sm:flex-row sm:flex-wrap",children:[u?e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:"https://archiveofourown.org/works",target:"_blank",rel:"noopener noreferrer",className:L(dt({variant:"solid",size:"lg"}),"min-h-11 justify-center"),children:["Open AO3",e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]}),e.jsxs("a",{href:"https://www.fanfiction.net/",target:"_blank",rel:"noopener noreferrer",className:L(dt({variant:"outline",size:"lg"}),"min-h-11 justify-center bg-surface-1"),children:["Open FanFiction.net",e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]})]}):i?.href?e.jsxs("a",{href:i.href,target:"_blank",rel:"noopener noreferrer","aria-label":`Add Trace from ${i.label}`,className:L(dt({variant:"solid",size:"lg"}),"min-h-11 justify-center"),children:["Add Trace extension",e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]}):null,e.jsx(de,{type:"button",variant:"ghost",size:"lg",className:"min-h-11 justify-center",onClick:t,leftIcon:e.jsx(mt,{className:"h-4 w-4","aria-hidden":!0}),children:"Add manually"})]}),e.jsxs("p",{className:"mt-5 text-xs leading-5 text-content-muted",children:[u?"Extension not working? ":"Need help installing? ",e.jsx(aa,{to:s,className:"font-semibold text-content-primary underline decoration-border-strong underline-offset-4",children:"Open setup help"}),"."]})]})}function Fu(t){return new URLSearchParams(t).get("activation")==="extension-installed"}function $u({setupHref:t,onAddManually:a,showManualFallback:n=!0}){return e.jsxs("div",{className:"relative rounded-xs border border-border bg-[color-mix(in_oklab,var(--library-surface-lowest)_62%,var(--library-bg))] p-5 pl-6 before:absolute before:bottom-4 before:left-0 before:top-4 before:w-1 before:bg-[var(--library-secondary)]",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsx("span",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-xs border border-border bg-surface-2 text-content-muted",children:e.jsx(Fn,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:"Setup guide"}),e.jsx("p",{className:"font-landing-serif text-xl font-semibold leading-tight text-content-primary",children:"Want more setup help?"})]})]}),e.jsx("p",{className:"text-sm leading-relaxed text-content-muted",children:"Open the full guide for install links, screenshots, Safari permissions, recovery steps, and setup paths for other devices."}),e.jsxs(aa,{to:t,className:L(dt({variant:"solid",size:"lg"}),"mt-5 w-full justify-center sm:w-auto"),children:["Open setup guide",e.jsx(Ha,{className:"h-4 w-4","aria-hidden":!0})]}),n?e.jsxs("div",{className:"mt-5 border-t border-border-subtle pt-5",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:"Fallback"}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-content-muted",children:"Use manual add for unsupported browsers, archives, or reading formats the Trace extension cannot save yet."}),e.jsx(de,{variant:"outline",size:"lg",onClick:a,className:"mt-4 w-full justify-center sm:w-auto",leftIcon:e.jsx(mt,{className:"h-4 w-4","aria-hidden":!0}),children:"Add manually"})]}):null]})}function Wu({installTarget:t,setupHref:a,onAddManually:n,setupPath:s}){const i=r.useId(),o=s==="ios-safari";return e.jsxs("section",{className:"relative min-h-[25rem] max-w-3xl overflow-hidden rounded-xs border border-border bg-surface-1 p-5 pl-6 shadow-sm before:absolute before:bottom-0 before:left-0 before:top-0 before:w-1 before:bg-[var(--forest)] sm:min-h-80 sm:p-6 sm:pl-7","aria-labelledby":i,children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-sm border border-[color-mix(in_oklab,var(--forest)_22%,var(--border))] bg-[var(--forest-soft)] text-[var(--forest)]","aria-hidden":!0,
2children:e.jsx(Fn,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-[var(--forest)]",children:o?"Trace app needed":"Extension not detected"}),e.jsx("h3",{id:i,className:"mt-1 font-landing-serif text-2xl font-semibold leading-tight text-content-primary",children:o?"Install the Trace app.":"Install the Trace extension."})]})]}),e.jsx("p",{className:"mt-4 max-w-[56ch] text-sm leading-relaxed text-content-muted",children:o?"Install the app, sign in, then enable the Safari extension.":"Trace is not installed in this browser yet. Install it once, then Trace can connect automatically."}),e.jsx("div",{className:"mt-6 flex flex-col gap-2 sm:flex-row sm:items-center",children:t?.href?e.jsxs("a",{href:t.href,target:"_blank",rel:"noopener noreferrer","aria-label":`Install Trace from ${t.label}`,className:L(dt({variant:"solid",size:"lg"}),"min-h-11 justify-center"),children:[o?"Install app":"Install extension",e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]}):e.jsxs(aa,{to:a,className:L(dt({variant:"solid",size:"lg"}),"min-h-11 justify-center"),children:["Open setup guide",e.jsx(Ha,{className:"h-4 w-4","aria-hidden":!0})]})}),e.jsxs("p",{className:"mt-5 border-t border-border-subtle pt-4 text-sm leading-6 text-content-muted",children:["Not using AO3 or FanFiction.net?"," ",e.jsx("button",{type:"button",className:"font-semibold text-content-primary underline decoration-border-strong underline-offset-4 hover:text-[var(--forest)]",onClick:n,children:"Add manually"}),"."]}),e.jsxs("p",{className:"mt-4 text-xs leading-5 text-content-muted",children:["Need help?"," ",e.jsx(aa,{to:a,className:"font-semibold text-content-primary underline decoration-border-strong underline-offset-4",children:"Open setup guide"}),"."]})]})}function Di(){return e.jsxs("div",{role:"status","aria-label":"Checking Trace extension",className:"mt-6 max-w-3xl",children:[e.jsx("span",{className:"sr-only",children:"Checking Trace extension"}),e.jsx("div",{className:"h-10 w-64 max-w-full animate-pulse rounded-xs bg-surface-2"}),e.jsx("div",{className:"mt-3 h-5 w-80 max-w-full animate-pulse rounded-xs bg-surface-2"}),e.jsxs("div",{className:"relative mt-6 min-h-[20rem] overflow-hidden rounded-xs border border-border bg-surface-1 p-5 pl-6 shadow-sm before:absolute before:bottom-0 before:left-0 before:top-0 before:w-1 before:bg-border-strong sm:min-h-72 sm:p-6 sm:pl-7","aria-hidden":!0,children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-sm border border-border-subtle bg-surface-2 text-content-muted",children:e.jsx(Ia,{className:"h-5 w-5 animate-spin"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"h-3 w-24 animate-pulse rounded-xs bg-surface-2"}),e.jsx("div",{className:"mt-3 h-7 w-56 max-w-full animate-pulse rounded-xs bg-surface-2"})]})]}),e.jsx("div",{className:"mt-6 h-4 w-full max-w-[32rem] animate-pulse rounded-xs bg-surface-2"}),e.jsx("div",{className:"mt-3 h-4 w-3/4 max-w-[26rem] animate-pulse rounded-xs bg-surface-2"}),e.jsx("div",{className:"mt-8 h-11 w-full max-w-[38rem] animate-pulse rounded-xs bg-surface-2"})]})]})}function Bu(t){return t==="ios-safari"?"Install app":"Install extension"}function Vu(t){return t==="ios-app"}function Hu(t){return t.connected?!0:t.phase==="detected"&&t.authState==="unknown"}function Uu({onAddManually:t}){const a=On(),n=r.useMemo(()=>null,[a.search]),s=r.useMemo(()=>n??oi(),[n]),i=r.useMemo(()=>li(s),[s]),o=r.useMemo(()=>ci(s),[s]),c=r.useMemo(()=>null,[a.search]),u=r.useMemo(()=>null,[a.search]),l=r.useMemo(()=>null,[a.search]),m=Vu(s),d=r.useMemo(()=>Fu(a.search),[a.search]),x=di({enabled:!m,fixtureStatus:m?null:c}),y=kc(s)?"extension":"fallback",g=r.useMemo(()=>gc(s),[s]),N=r.useMemo(()=>fc(s),[s]),S=r.useCallback(z=>{cl(z,{surface:"library_empty"})},[]),C=da(),_=pt(),p=r.useCallback(async({handoffAt:z,baselineLibraryCount:Q})=>{if(u!=null)return!0;if(!_.isReady)return!1;const te=await C.fetchQuery({queryKey:je.me,queryFn:()=>_.me(),staleTime:0});
2return vc({libraryCount:te.library_count,firstStoryCompletedAt:te.first_story_completed_at,handoffAt:z,baselineLibraryCount:Q})},[_,u,C]),b=r.useCallback(()=>{C.invalidateQueries({queryKey:je.me}),C.invalidateQueries({queryKey:je.library.all})},[C]),k=yc(x.status),j=r.useCallback(z=>{S({...z,extensionPhase:x.status.phase,extensionConnected:x.status.connected,extensionAuthState:x.status.authState,extensionBrowserKind:x.status.browserKind,archiveHostKind:x.status.lastArchiveHostKind,archiveActionKind:x.status.lastArchiveActionKind,archiveErrorKind:x.status.lastArchiveErrorKind,firstSaveSeen:x.status.firstSaveSeen,extensionFirstStoryAddSupported:k,recentArchiveActivity:wc(x.status),libraryCountState:"empty"})},[k,x.status,S]),O=y==="extension"&&Hu(x.status),R=y==="extension"&&d&&x.status.phase==="checking",F=y==="extension"&&!R&&(x.status.phase==="checking"||x.status.phase==="not_detected"),A=O||m||R||F;return e.jsxs("div",{"data-testid":"library-empty-state",className:L("mx-auto w-full max-w-5xl px-4 sm:px-1 sm:pb-12 sm:pt-8",A?"flex min-h-[calc(100svh_-_13rem)] flex-col justify-center pb-6 pt-3 sm:block sm:min-h-0":"pb-28 pt-4"),children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3 font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:[e.jsx(Va,{className:"h-4 w-4 text-[var(--accent-editorial)]","aria-hidden":!0}),"My Library",e.jsx("span",{className:"h-px w-10 bg-border-strong","aria-hidden":!0}),"0 stories"]}),R?e.jsx(Di,{}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"max-w-3xl font-landing-serif text-3xl font-semibold leading-tight text-content-primary sm:text-4xl",children:O?e.jsxs(e.Fragment,{children:["Add your"," ",e.jsx("em",{className:"font-normal italic text-[var(--rust)]",children:"first story."})]}):m?"Trace for Safari.":F?"Install Trace to start.":"Add your first story."}),e.jsx("p",{className:L("mt-3 max-w-2xl text-base leading-7 text-content-muted",A?"min-h-14":"min-h-20 sm:min-h-14"),children:O?e.jsx(e.Fragment,{children:"Paste a story URL below."}):m?e.jsx(e.Fragment,{children:"Finish the step below."}):F?e.jsx(e.Fragment,{children:"Trace did not find the extension in this browser yet."}):e.jsx(e.Fragment,{children:"Set up Trace once, then it can track stories and keep your place as you read. It only takes a few minutes. Start with the live step below, or open the full guide for screenshots and extra context."})}),e.jsxs("div",{className:L("mt-5 text-left sm:mt-6",A?"max-w-3xl":"grid gap-4 lg:grid-cols-[minmax(0,1.08fr)_minmax(0,0.92fr)]"),children:[O?e.jsx(jc,{setupHref:i,extensionFirstStoryAddSupported:k,analyticsVariant:"compact",pathSupport:y,onAnalyticsEvent:j,manualAddAction:{onClick:t}}):m?e.jsx(Nc,{setupHref:i,isAuthenticated:!0,serverLibraryCount:0,confirmFirstStorySaved:p,onFirstStorySuccess:b,onAnalyticsEvent:S,analyticsVariant:"compact",manualAddAction:{onClick:t},fixtureState:u,fixtureVerificationState:l??"idle"}):F?e.jsx(Wu,{installTarget:o,setupHref:i,onAddManually:t,setupPath:s}):e.jsx(Sc,{status:x.status,libraryCount:0,pathSupport:y,stepLabels:g,stateCopy:N,onCheckAgain:x.checkAgain,onAnalyticsEvent:S,variant:"compact",completeAction:null,setupHref:i,installAction:o?.href?e.jsxs("a",{href:o.href,target:"_blank",rel:"noopener noreferrer","aria-label":`Install Trace from ${o.label}`,className:L(dt({variant:"solid",size:"sm"}),"min-h-10"),children:[Bu(s),e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]}):void 0,authAction:e.jsx(aa,{to:i,className:L(dt({variant:"solid",size:"sm"}),"min-h-10"),children:"Open setup guide"}),manualAddAction:e.jsx(de,{variant:"outline",size:"sm",onClick:t,className:"min-h-10",leftIcon:e.jsx(mt,{className:"h-4 w-4","aria-hidden":!0}),children:"Add manually"})}),!O&&!R&&!F&&!m?e.jsx($u,{setupHref:i,onAddManually:t,showManualFallback:y!=="fallback"&&!x.status.firstSaveSeen}):null]}),!O&&!R&&!F&&!m?e.jsxs("details",{className:"mt-8 rounded-xs border border-border-subtle bg-surface-1 px-4 py-4 text-sm leading-relaxed text-content-muted",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-content-primary",children:[e.jsx(El,{className:"mr-2 inline h-5 w-5 shrink-0 text-content-muted","aria-hidden":!0}),"What Trace can see"]}),e.jsx("p",{className:"mt-3 max-w-3xl",children:"The extension reads supported archive pages you open. It does not ask for AO3 or FFN credentials, read story text, or inspect unrelated browsing. If AO3 or FFN shows nothing after Trace connects, allow the extension on that site, refresh, and try a story, listing, or bookmarks page."})]}):null]})]})}function Yu({onAddManually:t,firstStoryCompleted:a}){return a?e.jsx(Du,{onAddManually:t}):e.jsx(Uu,{onAddManually:t})}function Ku(t,a){return t||a?"No results. Try clearing filters or changing your search.":"No stories yet. Add one by URL to get started."}const zu=et(["@container group relative min-w-0 cursor-pointer overflow-visible text-left","bg-transparent","shadow-none outline-none","transition-[border-color,box-shadow] duration-100 ease-out","hover:bg-[color-mix(in_oklab,var(--paper-2)_35%,transparent)]","focus-visible:outline-none focus-visible:shadow-ring"].join(" "),{variants:{selected:{true:["bg-[color-mix(in_oklab,var(--rust-soft)_22%,transparent)]","shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--rust)_38%,transparent)]"].join(" ")},bulkMode:{true:""},isBehind:{true:""},densityMode:{compact:["border-b border-[var(--line)]","min-[900px]:before:bottom-0 min-[900px]:before:top-0 min-[900px]:before:rounded-none","max-[899px]:mb-0 max-[899px]:rounded-none max-[899px]:border-x-0 max-[899px]:border-t-0 max-[899px]:bg-transparent max-[899px]:shadow-none","max-[899px]:before:bottom-[11px] max-[899px]:before:top-[11px] max-[899px]:before:w-1 max-[899px]:before:rounded-r-[4px]"].join(" "),browse:["border-b border-[var(--line)]","max-[899px]:mb-[11px] max-[899px]:overflow-hidden max-[899px]:rounded-[5px] max-[899px]:border max-[899px]:border-[var(--line)] max-[899px]:bg-[var(--card)]","max-[899px]:shadow-none max-[899px]:before:hidden"].join(" ")},isEvaluating:{true:["z-[30] rounded-sm border border-[color-mix(in_oklab,var(--honey)_35%,var(--line))]","bg-[color-mix(in_oklab,var(--honey)_8%,var(--paper))]","shadow-[0_12px_28px_color-mix(in_oklab,var(--ink)_10%,transparent)]","max-[899px]:rounded-[5px] max-[899px]:border-0 max-[899px]:bg-[var(--card-2)] max-[899px]:shadow-[inset_0_0_0_1px_var(--line-strong)]"].join(" ")},celebrate:{true:"animate-card-pop"},statusChrome:{none:"",current:["trace-row-wash--current","bg-[color-mix(in_oklab,var(--status-reading)_15%,var(--paper))]","hover:bg-[color-mix(in_oklab,var(--status-reading)_19%,var(--paper))]","max-[899px]:!bg-[color-mix(in_oklab,var(--status-reading)_20%,var(--paper))]","max-[899px]:h
2over:!bg-[color-mix(in_oklab,var(--status-reading)_23%,var(--paper))]"].join(" ")}},defaultVariants:{statusChrome:"none",densityMode:"browse"}}),qu="max-[899px]:select-none max-[899px]:touch-pan-y max-[899px]:overscroll-x-contain max-[899px]:overflow-hidden",Gu=et(["absolute bottom-0 right-0 top-0 z-[30] hidden overflow-hidden border-0","rounded-r-[5px] bg-danger-600 text-[var(--solid-button-fg)]","font-mono text-micro font-semibold uppercase leading-none tracking-[0.08em]","shadow-[inset_1px_0_0_color-mix(in_oklab,var(--danger-700)_52%,transparent)] max-[899px]:inline-flex","disabled:cursor-not-allowed disabled:opacity-55"].join(" "),{variants:{open:{true:"pointer-events-auto opacity-100",false:"pointer-events-none opacity-0"}},defaultVariants:{open:!1}}),Qu="absolute inset-y-0 right-0 flex w-[88px] flex-col items-center justify-center gap-1 px-2",Xu="grid h-6 w-6 shrink-0 place-items-center text-white",Zu="h-5 w-5 shrink-0",Ju="relative z-[30] min-w-0 will-change-transform [backface-visibility:hidden]",em="max-[899px]:shadow-[6px_0_18px_-14px_color-mix(in_oklab,var(--ink)_70%,transparent)]",tm="cursor-grabbing",am=["hidden min-w-0 grid-cols-[minmax(0,1fr)_190px] gap-x-6","px-[26px] py-[22px] text-[var(--ink)] @min-[900px]:grid"].join(" "),nm="min-w-0",sm="mt-[9px] flex min-w-0 flex-wrap items-baseline gap-x-[11px] gap-y-1",rm="inline-flex h-[18px] w-[18px] shrink-0 translate-y-[2px] items-center justify-center",im="min-w-0 max-w-[min(100%,42rem)] font-landing-serif text-[23px] font-medium leading-[1.12] tracking-normal text-[var(--ink)]",Ln="font-medium text-[var(--ink-2)]",om="inline-flex shrink-0 items-center gap-0.5 font-mono text-[10px] font-medium uppercase leading-none tracking-[0.06em] text-[var(--rust)] underline-offset-2 hover:underline",lm="mt-1.5 flex min-w-0 flex-wrap items-center gap-x-[9px] gap-y-1 font-sans text-[13.5px] leading-snug text-[var(--ink-3)]",cm="inline-flex max-w-full items-center truncate rounded-2xs border border-[var(--line)] px-1.5 py-0.5 font-mono text-[9px] font-medium uppercase leading-none tracking-[0.08em] text-[var(--ink-4)]",dm=et(["inline-flex min-h-5 items-center rounded-pill border px-2","font-mono text-micro font-semibold uppercase leading-none tracking-[0.1em]"].join(" "),{variants:{tone:{neutral:"border-[color-mix(in_oklab,var(--library-outline)_18%,transparent)] bg-[color-mix(in_oklab,var(--paper-2)_62%,transparent)] text-[var(--ink-3)]",wip:"border-[color-mix(in_oklab,var(--honey)_42%,transparent)] bg-[color-mix(in_oklab,var(--honey)_13%,var(--library-surface-lowest))] text-[color-mix(in_oklab,var(--honey)_82%,var(--ink))]",complete:"border-[color-mix(in_oklab,var(--status-completed)_36%,transparent)] bg-[color-mix(in_oklab,var(--status-completed)_12%,var(--library-surface-lowest))] text-[var(--status-completed)]",hiatus:"border-[color-mix(in_oklab,var(--status-paused)_38%,transparent)] bg-[color-mix(in_oklab,var(--status-paused)_12%,var(--library-surface-lowest))] text-[var(--status-paused)]",abandoned:"border-[color-mix(in_oklab,var(--rust)_38%,transparent)] bg-[color-mix(in_oklab,var(--rust)_11%,var(--library-surface-lowest))] text-[var(--rust)]",catchup:"border-[color-mix(in_oklab,var(--status-caught-up)_34%,transparent)] bg-[color-mix(in_oklab,var(--status-caught-up)_12%,var(--library-surface-lowest))] text-[var(--status-caught-up)]"}},defaultVariants:{tone:"neutral"}}),um="mt-3.5",mm="mt-[11px] max-w-[600px] font-sans text-sm leading-[1.55] text-[var(--ink-2)]",Fi="text-[var(--ink-3)]",pm="mt-2.5 flex min-w-0 flex-wrap gap-x-2 gap-y-1.5",Dt="inline-block min-w-0 max-w-[12.5rem] shrink-0 overflow-hidden text-ellipsis whitespace-nowrap rounded-pill border border-[var(--line)] bg-transparent px-2.5 py-1 text-xs leading-none text-[var(--ink-3)] @max-[899px]:max-w-[9.75rem]",$i="border-[var(--line-strong)] bg-[var(--card-2)] font-medium text-[var(--ink)]",hm="border-dashed border-[color-mix(in_oklab,var(--honey)_30%,transparent)] text-[var(--honey)]",xm="flex min-w-[190px] flex-col items-end gap-2 pt-0.5 text-right text-xs text-[var(--ink-3)]",bm="flex w-full min-w-0 items-center gap-[9px]",gm="shrink-0 whitespace-nowrap font-mono text-[11px] leading-none text-[var(--ink-4)]",Ys=["relative grid min-w-0 grid-cols-1 px-4 pb-4 pt-[14px] text-[var(--ink)]","@min-[900px]:hidden"].join(" "),Ks="flex min-w-0 items-start gap-2",zs="min-w-0 flex-1 font-landing-serif text-[19px] font-medium leading-[1.16] tracking-normal text-[var(--ink)]",qs="mt-1 min-w-0 text-[12.5px] leading-snug text-[var(--ink-3)]",Gs="mt-[9px] max-w-none text-[13.5px] leading-[1.5] text-[var(--ink-2)]",Qs="mb-2 flex min-w-0 items-center gap-2",Wi=et(["trace-mobile-browse-status-chip inline-flex min-w-0 shrink-0 items-center gap-1.5 rounded-[5px] border px-[9px] py-1","font-mono text-[9.5px] font-medium uppercase leading-none tracking-[0.13em]"].join(" "),{variants:{tone
2:{neutral:"border-[var(--status-planning-border)] bg-[var(--status-planning-container)] text-[var(--status-planning-on-container)]",reading:"border-[var(--status-reading-border)] bg-[var(--status-reading-container)] text-[var(--status-reading-on-container)]",catchup:"border-[var(--status-caught-up-border)] bg-[var(--status-caught-up-container)] text-[var(--status-caught-up-on-container)]",completed:"border-[var(--status-completed-border)] bg-[var(--status-completed-container)] text-[var(--status-completed-on-container)]",paused:"border-[var(--status-paused-border)] bg-[var(--status-paused-container)] text-[var(--status-paused-on-container)]",planning:"border-[var(--status-planning-border)] bg-[var(--status-planning-container)] text-[var(--status-planning-on-container)]",dropped:"border-[var(--status-dropped-border)] bg-[var(--status-dropped-container)] text-[var(--status-dropped-on-container)]"}},defaultVariants:{tone:"neutral"}}),fm="h-1.5 w-1.5 shrink-0 rounded-pill bg-current",Xs="ml-auto shrink-0 font-mono text-[10px] font-medium uppercase leading-none tracking-normal",vm="hidden max-[899px]:flex min-w-0 items-center gap-2 border-b border-[color-mix(in_oklab,var(--honey)_22%,transparent)] bg-[color-mix(in_oklab,var(--honey)_10%,var(--card-2))] px-4 py-2",ym="font-mono text-[9px] font-medium uppercase leading-none tracking-[0.16em] text-[var(--honey)]",wm="ml-auto min-w-0 truncate font-mono text-[9px] uppercase leading-none tracking-[0.12em] text-[var(--ink-4)]",jm="mt-[7px] flex min-w-0 items-center gap-[7px]",Nm=et("h-1.5 w-1.5 shrink-0 rounded-[2px]",{variants:{tone:{neutral:"bg-[var(--ink-3)]",wip:"bg-[var(--ink-3)]",complete:"bg-[var(--status-completed)]",hiatus:"bg-[var(--status-paused)]",abandoned:"bg-[var(--rust)]",catchup:"bg-[var(--status-caught-up)]"}},defaultVariants:{tone:"neutral"}}),Sm=et("min-w-0 truncate font-mono text-[10px] font-medium uppercase leading-none tracking-[0.1em]",{variants:{tone:{neutral:"text-[var(--ink-3)]",wip:"text-[var(--ink-3)]",complete:"text-[var(--status-completed)]",hiatus:"text-[var(--status-paused)]",abandoned:"text-[var(--rust)]",catchup:"text-[var(--status-caught-up)]"}},defaultVariants:{tone:"neutral"}}),km="mt-2 flex min-w-0 flex-nowrap gap-1.5 overflow-hidden",Cm=["relative","before:content-['']","before:absolute before:left-0 before:top-0 before:bottom-0","before:w-[3px]","before:rounded-none","before:opacity-100 before:transition-[opacity,filter] before:duration-100 before:ease-out","group-hover:before:brightness-[1.06]","before:pointer-events-none"].join(" ");function _m(t){switch(t){case"reading":return"before:bg-[var(--status-reading)]";case"catchup":return"before:bg-[var(--status-caught-up)]";case"completed":return"before:bg-[var(--status-completed)]";case"paused":return"before:bg-[var(--status-paused)]";case"dropped":return"before:bg-[var(--status-dropped)]";case"planning":return"before:bg-[var(--status-planning)]";default:return"before:bg-[var(--status-planning)]"}}const Rm="before:bg-[var(--status-reading)]";function Bi(t){switch(t){case"reading":return"bg-[var(--status-reading)]";case"catchup":return"bg-[var(--status-caught-up)]";case"completed":return"bg-[var(--status-completed)]";case"paused":return"bg-[var(--status-paused)]";case"dropped":return"bg-[var(--status-dropped)]";case"planning":return"bg-[var(--status-planning)]";default:return"bg-[var(--status-planning)]"}}function Lm(t){switch(t){case"reading":return"var(--status-reading-progress)";case"catchup":return"var(--status-caught-up-progress)";case"completed":return"var(--status-completed-progress)";case"paused":return"var(--status-paused-progress)";case"dropped":return"var(--status-dropped-progress)";case"planning":return"var(--status-planning-progress)";default:return"var(--status-planning-progress)"}}const Am="inline-flex items-center h-[20px] px-2 rounded-pill border border-border text-xs leading-none text-content-muted",Tm="trace-mobile-readonly-stars mt-[13px] hidden min-w-0 items-center gap-[3px] text-[15px] @max-[899px]:flex",Em="text-[var(--honey)]",Pm="text-[var(--ink-5)]",Mm="inline-flex min-w-0",Zs="mt-[13px] flex min-w-0 items-center gap-[11px]",Js="h-[3px] min-w-0 flex-1 overflow-hidden rounded-pill bg-[var(--ink-5)]",er="block h-full min-w-[2px] rounded-pill bg-[color:var(--mobile-browse-progress-color)]",tr="shrink-0 whitespace-nowrap font-mono text-xs leading-none text-[var(--ink-2)]",ar=["trace-mobile-progress-control inline-flex min-h-11 w-full shrink-0 items-center justify-between gap-2 rounded-[18px] border border-border-subtle","bg-[color-mix(in_oklab,var(--library-surface-low)_82%,var(--library-surface-lowest))] px-3","font-mono text-[13px] font-bold tabular-nums text-content-primary shadow-[0_1px_3px_color-mix(in_oklab,var(--library-primary)_7%,transparent)]"].join(" "),nr=["inline-flex h-8 w-8 items-center justify-center rounded-full","text-base font-bold leading-none text-[var(--library-primary)]","transition hover:bg-[color-mix(in_oklab,var(--library-primary)_10%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),Im="min-w-[6.3rem] text-center leading-none",la=et(["mt-[2px] shrink-0","inline-grid place-items-center","h-[18px] w-[18px] rounded-full","bg-[var(--success-600)] text-[var(--bg-app)]","text-[12px] font-extrabold","pointer-events-none select-none","transition-all duration-300","opacity-0 scale-[0.75]"].join(" "),{variants:{show:{true:"opacity-100 scale-100"}}}),Om="",Dm=["inline-flex shrink-0 items-center gap-0 rounded-pill border border-[var(--line)]","bg-[var(--paper-2)] p-0.5","font-mono text-xs tabular-nums text-[var(--ink)]"].join(" "),sr=["inline-flex h-[22px] w-[22px] items-center justify-center rounded-full border-0 bg-transparent","text-sm leading-none text-[var(--ink-3)] transition","hover:bg-[var(--paper-3)] hover:text-[var(--ink)]","disabled:cursor-not-allowed disabled:opacity-35"].join(" "),Fm="min-w-[46px] px-1 text-center leading-none",$m=["h-[3px] w-[120px] overflow-hidden rounded-pill border border-[color-mix(in_oklab,var(--library-outline)_12%,transparent)]","bg-[color-mix(in_oklab,var(--library-outline)_16%,var(--paper-3))]"].join(" "),Wm="block h-full min-w-[2px] rounded-pill bg-[color:var(--desktop-progress-color)] opacity-[0.85] transition-[width,background-color] duration-300",Bm=["grid min-h-[54px] min-w-0 grid-cols-[140px_minmax(0,1fr)_52px_124px_34px] items-center gap-[18px]","px-4 py-0 pl-5 text-[var(--ink)]","@max-[899px]:gri
2d-cols-1 @max-[899px]:gap-2 @max-[899px]:px-4 @max-[899px]:py-3.5 @max-[899px]:pl-[20px]"].join(" "),Vm="trace-compact-desktop-row hidden min-[900px]:grid",Hm=["trace-mobile-compact-row relative block min-w-0 px-4 py-[13px] pl-[18px] text-[var(--ink)]","min-[900px]:hidden"].join(" "),Um="flex min-w-0 items-baseline gap-3",Ym="min-w-0 flex-1 truncate font-landing-serif text-[16.5px] font-medium leading-[1.2] tracking-normal text-[var(--ink)]",Km="shrink-0 whitespace-nowrap font-mono text-xs leading-none text-[var(--ink-2)]",Wa="text-[var(--ink-4)]",zm="mt-[5px] flex min-w-0 items-center gap-2",qm="h-[7px] w-[7px] shrink-0 rounded-pill",Gm="shrink-0 whitespace-nowrap text-[12.5px] leading-none text-[var(--ink-3)]",Qm="font-semibold text-[var(--status-reading)]",Xm="min-w-0 flex-1 truncate whitespace-nowrap text-[12.5px] leading-none text-[var(--ink-4)]",Zm="pointer-events-none mt-[13px] mb-px h-[3px] overflow-hidden rounded-pill bg-[color-mix(in_oklab,var(--ink)_10%,transparent)]",Jm="block h-full rounded-pill bg-[var(--mobile-compact-progress-color)]",ep="min-w-0",tp="flex min-w-0 items-center gap-2",ap="h-[7px] w-[7px] shrink-0 rounded-pill",np="min-w-0 truncate font-sans text-[13px] font-medium leading-none text-[var(--ink-3)]",sp="font-semibold text-[var(--status-reading)]",rp="flex min-w-0 items-center gap-2",ip="min-w-0 flex-1 truncate font-landing-serif text-[16.5px] font-medium leading-[1.16] tracking-normal text-[var(--ink)] @max-[899px]:text-[15.5px]",op="mt-1 flex min-w-0 items-center gap-x-2 overflow-hidden whitespace-nowrap text-[12.5px] leading-none text-[var(--ink-4)] @max-[899px]:gap-x-2",lp="min-w-0 truncate font-semibold text-[var(--ink-3)]",cp="justify-self-start text-[9.5px]",dp="flex min-w-0 shrink-0 flex-col items-end gap-1.5 text-right @max-[899px]:min-w-0 @max-[899px]:items-stretch @max-[899px]:text-left",up="whitespace-nowrap font-mono text-[12.5px] font-medium leading-none tabular-nums text-[var(--ink-2)]",mp="font-mono text-[10.5px] leading-none text-[var(--honey)]",rr="flex h-[30px] w-[30px] items-center justify-center",pp="inline-flex h-[30px] w-[30px] items-center justify-center rounded-[8px] border border-[var(--line)] bg-transparent font-mono text-[15px] leading-none text-[var(--ink-3)] opacity-0 outline-none transition hover:border-[var(--line-strong)] hover:bg-[var(--card)] hover:text-[var(--ink)] focus-visible:opacity-100 focus-visible:shadow-ring group-hover:opacity-100 disabled:cursor-not-allowed disabled:opacity-0 group-hover:disabled:opacity-35",hp=["flex min-w-0 items-center justify-between gap-3","border-b border-[color-mix(in_oklab,var(--honey)_24%,var(--line))]","px-[22px] py-3 @max-[899px]:hidden"].join(" "),xp="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-1",bp="font-mono text-[10px] font-semibold uppercase leading-none tracking-[0.18em] text-[var(--honey)]",gp="text-xs leading-none text-[var(--ink-3)]",fp="flex shrink-0 items-center gap-2",ir="inline-flex min-h-10 w-full items-center justify-center gap-1.5 rounded-[9px] border border-[var(--line)] bg-transparent px-2 text-xs font-medium leading-none text-[var(--ink-2)] transition hover:border-[var(--ink-3)] hover:text-[var(--ink)] disabled:cursor-not-allowed disabled:opacity-45 @min-[900px]:min-h-8 @min-[900px]:w-auto @min-[900px]:rounded-[5px] @min-[900px]:px-3",vp="inline-flex min-h-10 w-full items-center justify-center gap-1.5 rounded-[9px] border border-[var(--line)] bg-transparent px-2 text-xs font-medium leading-none text-[var(--rust)] transition hover:border-[color-mix(in_oklab,var(--rust)_42%,var(--line))] hover:text-[var(--rust)] @min-[900px]:ml-auto @min-[900px]:min-h-8 @min-[900px]:w-auto @min-[900px]:rounded-[5px] @min-[900px]:border-transparent @min-[900px]:px-0",ea="h-3.5 w-3.5 shrink-0",yp="@min-[900px]:hidden",wp="hidden @min-[900px]:inline",jp="inline-flex min-h-8 items-center justify-center gap-1.5 rounded-[5px] border border-transparent bg-transparent px-1 text-xs font-medium leading-none text-[var(--ink-3)] transition hover:text-[var(--ink)]",Np="mb-2 block font-mono text-[10px] font-semibold uppercase leading-none tracking-[0.16em] text-[var(--ink-4)]",Vi="mt-3 inline-flex min-w-0 items-center gap-2 rounded-[5px] border border-[color-mix(in_oklab,var(--honey)_24%,transparent)] bg-[
2color-mix(in_oklab,var(--honey)_8%,var(--paper))] px-2 py-1",Hi="font-mono text-[11px] leading-none text-[var(--ink-4)]",Ui="text-[var(--honey)]",Sp="font-mono text-[11px] leading-none text-[var(--ink-3)]",kp="min-h-[96px] w-full resize-y rounded-[5px] border border-[var(--line-strong)] bg-[color-mix(in_oklab,var(--paper-2)_72%,var(--paper))] px-3 py-2 text-sm leading-relaxed text-[var(--ink)] outline-none transition placeholder:text-[var(--ink-4)] focus:border-[var(--honey)] focus:shadow-[0_0_0_2px_color-mix(in_oklab,var(--honey)_18%,transparent)]",Cp="ml-auto text-right font-mono text-[10px] leading-none text-[var(--ink-4)]",or="min-w-0",lr="mb-3 flex min-w-0 flex-wrap gap-1.5",_p="inline-flex items-center gap-1.5 border-[color-mix(in_oklab,var(--forest)_32%,transparent)] bg-[var(--forest-soft)] text-[var(--forest)]",Rp="h-1 w-1 shrink-0 rounded-pill bg-[var(--forest)]",Lp="inline-flex min-h-6 items-center gap-1 rounded-pill border border-dashed border-[var(--line-strong)] bg-transparent px-2.5 text-xs leading-none text-[var(--ink-4)] transition hover:border-[var(--ink-4)] hover:text-[var(--ink-2)] disabled:cursor-not-allowed disabled:opacity-50",Ap="inline-flex min-h-6 max-w-full items-center gap-1 rounded-pill border border-dashed border-[var(--line-strong)] bg-transparent px-2 py-0.5",Tp="min-w-0 w-28 bg-transparent text-xs leading-none text-[var(--ink)] outline-none placeholder:text-[var(--ink-4)]",Ep="rounded-pill px-1.5 text-[11px] font-medium leading-none text-[var(--rust)] disabled:text-[var(--ink-4)]",Pp="text-xs leading-none text-[var(--ink-4)]",Mp="mt-3 grid min-w-0 grid-cols-3 gap-2 @min-[900px]:flex @min-[900px]:items-center",Ip="mt-[13px] min-w-0",Op="mt-3 min-w-0",Dp="mt-3 min-w-0",Fp="block w-full min-w-0 rounded-[5px] border border-[var(--line)] bg-[color-mix(in_oklab,var(--paper-2)_64%,var(--paper))] px-3 py-2 text-left font-landing-serif text-sm italic leading-relaxed text-[var(--ink-2)] transition hover:border-[var(--ink-4)]",$p="block w-full min-w-0 rounded-[5px] border border-dashed border-[var(--line-strong)] bg-transparent px-3 py-2 text-left text-sm leading-relaxed text-[var(--ink-4)] transition hover:border-[var(--ink-4)] hover:text-[var(--ink-2)]",Wp="min-w-0",Bp="mt-2 flex min-w-0 items-center gap-2",Vp="inline-flex min-h-8 items-center justify-center rounded-[5px] border border-[color-mix(in_oklab,var(--honey)_45%,var(--line))] bg-[var(--honey)] px-3 text-xs font-semibold leading-none text-[var(--ink)] transition hover:bg-[color-mix(in_oklab,var(--honey)_90%,var(--paper))]",Hp="inline-flex min-h-8 items-center justify-center rounded-[5px] border border-[var(--line)] bg-transparent px-3 text-xs font-semibold leading-none text-[var(--ink-3)] transition hover:border-[var(--ink-3)] hover:text-[var(--ink)]",Up="flex min-w-0 items-center",Yp="mt-4 flex min-w-0 flex-wrap gap-x-8 gap-y-4",Kp="min-w-0 flex-[1_1_18rem]",zp="min-w-0 flex-[2_1_22rem]",qp="flex w-full min-w-0 flex-col items-end gap-2 text-right",Gp=t=>ul(t)?dl[t]:"neutral",Qp=new Set(["DebugAuthor","debugauthor","DEBUGAUTHOR"].map(t=>t.toLowerCase()));function Xp(t){return t.filter(a=>!Qp.has(a.trim().toLowerCase()))}const An='button,a,input,textarea,select,[role="combobox"],[role="listbox"],[role="radiogroup"],[role="menuitem"],[data-card-interactive]',Zp=260,Jp=220,eh="(max-width: 899px)",th=470,Mt=88,cr=14,hn=6,ah=16,nh=-.42,sh=.36;function rh(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia(eh).matches}function ih(t){return t instanceof Element&&!!t.closest(An)}function dr(){return typeof performance<"u"?performance.now():Date.now()}function ur(t){if(t<-Mt){const a=Math.abs(t)-Mt,n=cr*(1-Math.exp(-a/64));return-Mt-Math.min(cr,n)}return Math.max(-Mt,Math.min(0,t))}function oh(t,a){return a?"text-[var(--ink-4)]":"text-[var(--rust)]"}function Yi(t){return typeof t.chapters_published=="number"&&t.chapters_published>0?Math.floor(t.chapters_published):null}function lh(t){return typeof t.chapters_planned=="number"&&t.chapters_planned>0?Math.floor(t.chapters_planned):null}function ch(t){return t!=="unknown"}function Ki(t){const a=t.workStatusOverride?.trim();if(a){const s=xs({workStatusOverride:a,completionStatus:t.completionStatus,chaptersPublished:t.chapters_published,chaptersPlanned:t.chapters_planned});return{workStatus:s.work_status,provenance:s.work_status_provenance}}if(t.work_status!=null){const s=ml(t.work_status);return{workStatus:s,provenance:t.work_status_provenance??(s==="unknown"?"unknown":"source")}}const n=xs({completionStatus:t.completionStatus,chaptersPublished:t.chapters_published,chaptersPlanned:t.chapters_planned});return{workStatus:n.work_status,provenance:n.work_status_provenance}}function dh(t){return ch(t.workStatus)?t.provenance==="override"?!0:t.provenance==="source"&&t.workStatus!=="wip":!1}function uh(t){return t==="wip"?"ONGOING":t==="complete"?"COMPLETE":t==="hiatus"?"HIATUS":"ABANDONED"}function mh(t){const a=[];if(dh(t)){const{workStatus:n}=t;a.push({label:uh(n),tone:n})}return a}function ph(t){const a=t.sourceHost?.toLowerCase()??"";return(t.source?.toUpperCase()??"")==="AO3"||a.includes("archiveofourown")}function hh(t){try{const a=new Date(t);return Number.isNaN(a.getTime())?"":a.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return""}}function xh(t,a){const n=Yl(a,t),s=Math.max(0,Math.floor(Number(t.progress.value??0))),i=Number.isFinite(n)&&n>0?Math.floor(n):void 0,o=i?Math.min(s,i):s,m=(t.progress.unit==="CHAPTER"?Yi(a):null)??i,d=Ki(a),x=null,y=void 0,g=Gp(t.status),N=a.source||"Open",S=Xp(a.authors||[]).join(", "),C=(a.canonicalFandoms?.length?a.canonicalFandoms:a.fandoms||[]).filter(
2Boolean).join(" / "),_=typeof a.words=="number"&&a.words>0?`${a.words.toLocaleString()} words`:null,p=typeof a.words=="number"&&a.words>0?a.words.toLocaleString():null,b=Kl(a,t),k=t.progress.unit==="CHAPTER"?b==="?"?`Chapter ${o}`:`Chapter ${o} / ${b}`:i?`Chapter ${o} / ${i}`:`Chapter ${o}`,j=Number(t.progress.value||0),O=t.progress.unit==="PERCENT"?Math.max(0,Math.min(100,j)):t.progress.unit==="WORD"?Number(t.progress.total||0)>0?Math.max(0,Math.min(100,j/Number(t.progress.total||0)*100)):0:typeof i=="number"&&i>0?Math.max(0,Math.min(100,o/i*100)):0,R=hh(a.updatedDate??""),F=x,A=R?`Work updated ${R}`:null,z=null,Q=void 0,te=[F,A].filter(Boolean).join(" · ")||null;return{progressValue:s,progressTotal:i,editableChapterMax:m,shownNow:o,behindCount:null,badgeLabel:x,badgeTitle:y,verified:a.verified!==!1,isBehind:!1,tone:g,site:N,authorLine:S,fandomLine:C,externalOpenHref:ii(a,t),externalOpenNotice:lc(a,t),hasTags:(t.tags||[]).some(Boolean),updatedLabel:R,isDropped:t.status==="DROPPED",wordCountLabel:_,mobileWordCountLabel:p,denomLabel:b,progressChapterLine:k,desktopActivityLabel:te,desktopCatchupLabel:F,desktopUpdatedLabel:A,stateSignals:mh(d),cardUpdateLabel:z,cardUpdateTitle:Q,visualProgressPercent:O,visualProgressColor:Lm(g)}}function zi(t){return t.status!=="SAVED"}function bh({filled:t}){return e.jsx("svg",{viewBox:"0 0 24 24",className:"h-[1em] w-[1em]","aria-hidden":"true",children:e.jsx("path",{d:"M12 3.5l2.6 5.3 5.9.9-4.2 4.1 1 5.8L12 17l-5.3 2.6 1-5.8L3.5 9.7l5.9-.9L12 3.5Z",fill:t?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinejoin:"round"})})}function gh({value:t}){const a=Math.max(0,Math.min(5,Math.floor(Number(t)||0)));return e.jsx("div",{className:Tm,"aria-label":a?`${a} star rating`:"Not rated",children:[1,2,3,4,5].map(n=>e.jsx("span",{className:n<=a?Em:Pm,children:e.jsx(bh,{filled:n<=a})},n))})}function ca({series:t}){return t?e.jsxs("span",{className:cm,title:t.name,children:[t.name,t.position!=null?` · Part ${t.position}`:""]}):null}function Ta({children:t,className:a}){return e.jsx("div",{className:a,"data-card-interactive":"",onClick:n=>n.stopPropagation(),children:t})}function qi({status:t,tone:a,isCurrent:n}){return e.jsxs("span",{className:Wi({tone:a}),children:[e.jsx("span",{className:fm,"aria-hidden":!0}),e.jsxs("span",{children:[yt(t),n?" · last read":""]})]})}function Ua(t,a){return t.progress.unit==="CHAPTER"?t.status==="SAVED"?"—":String(a.shownNow):t.progress.unit==="WORD"?`${Number(t.progress.value||0).toLocaleString()}w`:`${Math.round(Number(t.progress.value||0))}%`}function Ya(t,a){return t.progress.unit==="CHAPTER"?String(a.denomLabel):null}function fh({entry:t,vm:a}){const n=Ua(t,a),s=Ya(t,a);return e.jsxs("div",{className:bm,children:[e.jsx(eo,{vm:a}),e.jsxs("span",{className:gm,children:[n,s?e.jsxs("span",{className:Wa,children:[" / ",s]}):null]})]})}function vh(t,a){return t==null?null:a!=null&&a>t?`${t} of ${a} posted`:null}function yh(t){const{workStatus:a,provenance:n}=Ki(t),s=Yi(t),i=lh(t);if(a==="complete")return{label:"Complete",tone:"complete"};if(a==="hiatus")return{label:"Hiatus",tone:"hiatus"};if(a==="abandoned")return{label:"Abandoned",tone:"abandoned"};if(a==="wip"&&n==="override")return{label:"Ongoing",tone:"wip"};const o=vh(s,i);return o?{label:o,tone:"neutral"}:s!=null?{label:"Status unknown",tone:"neutral"}:null}function Tn({story:t}){const a=yh(t);return a?e.jsxs("div",{className:jm,children:[e.jsx("span",{className:Nm({tone:a.tone}),"aria-hidden":!0}),e.jsx("span",{className:Sm({tone:a.tone}),children:a.label})]}):null}const wh=r.memo(function({showStoryUpdates:a=!0,entry:n,story:s,onOpen:i,onEnterEvaluate:o,onExitEvaluate:c,onOpenDetails:u,onAddToCollection:l,onShare:m,onChangeStatus:d,onIncrementChapter:x,onDecrementChapter:y,onSetChapterValue:g,onChangeRating:N,onChangeNotes:S,onChangeTags:C,bulkMode:_=!1,selected:p=!1,onToggleSelect:b,onStartBulkSelect:k,onRemoveFromLibrary:j,removing:O=!1,onLayoutPointerLockChange:R,desktopVariant:F="metadata",isMostRecentReading:A=!1,densityMode:z="browse",isEvaluating:Q=!1,seriesContext:te=null,className:v}){const $=xh(n,s),{progressTotal:f,shownNow:U,denomLabel:oe,progressChapterLine:se,site:G,isDropped:I,externalOpenHref:E,externalOpenNotice:Y}=$,[W,J]=r.useState(!1),X=n.status==="FINISHED"||typeof f=="number"&&f>0&&$.progressValue>=f,ee=r.useRef(X);r.useEffect(()=>{let D=null;return!ee.current&&X&&(J(!0),D=setTimeout(()=>J(!1),600)),ee.current=X,()=>{D&&clearTimeout(D)}},[X]),r.useEffect(()=>{ee.current=X},[n.id,X]);const le=r.useRef(null),ae=r.useRef(null),P=r.useRef(null),re=r.useRef(null),me=r.useRef(!1),[ce,We]=r.useState(!1),[pe,De]=r.useState(!1),Se=Pl(0),M=ys(Se,D=>`translate3d(${D}px, 0, 0)`),T=ys(Se,D=>Math.max(0,Math.min(Mt,-D))),K=Ml(),q=()=>{P.current&&(clearTimeout(P.current),P.current=null)},fe=r.useCallback(()=>{re.current?.stop(),re.current=null},[]),be=r.useCallback((D,H={})=>{fe();const Ne=D?-Mt:0;
2if(We(D),De(!1),K||H.immediate){Se.set(Ne);return}re.current=Il(Se,Ne,{type:"spring",stiffness:680,damping:46,mass:.72,velocity:(H.velocity??0)*1e3,restDelta:.2,restSpeed:1.6})},[Se,K,fe]);r.useEffect(()=>()=>{q(),fe()},[fe]),r.useEffect(()=>{_&&(q(),ae.current=null,be(!1,{immediate:!0}))},[_,be]),r.useEffect(()=>{q(),ae.current=null,be(!1,{immediate:!0})},[n.id,be]);const we=!_&&!Q,ve=we&&!!j,Te=we&&!!k,He=pe||ce,ke=pe?"dragging":ce?"open":"closed",ge=D=>{if(D.pointerType!=="touch"||!rh()||ih(D.target)||!ve&&!Te&&!ce)return;const H=D.pointerId,Ne=dr(),Ge=ur(Se.get());fe(),ae.current={pointerId:H,startX:D.clientX,startY:D.clientY,baseOffset:Ge,dragging:!1,lastOffset:Ge,lastClientX:D.clientX,lastMoveAt:Ne,velocityX:0,wasOpen:ce,longPressFired:!1},q(),Te&&!ce&&(P.current=setTimeout(()=>{const Ie=ae.current;!Ie||Ie.pointerId!==H||Ie.dragging||(Ie.longPressFired=!0,me.current=!0,be(!1,{immediate:!0}),k?.())},th))},tt=D=>{const H=ae.current;if(!H||H.pointerId!==D.pointerId||H.longPressFired)return;const Ne=D.clientX-H.startX,Ge=D.clientY-H.startY,Ie=Math.abs(Ne),Fe=Math.abs(Ge);if(!H.dragging&&Fe>ah&&Fe>Ie){q(),ae.current=null;return}if(!ve){(Ie>hn||Fe>hn)&&q();return}if(!H.dragging){if(Ie<hn||Ie<=Fe)return;if(!H.wasOpen&&Ne>0){q(),ae.current=null;return}H.dragging=!0,q(),De(!0);try{D.currentTarget.setPointerCapture(D.pointerId)}catch{}}const ha=ur(H.baseOffset+Ne),Ee=dr(),Ae=Math.max(1,Ee-H.lastMoveAt);H.velocityX=(D.clientX-H.lastClientX)/Ae,H.lastClientX=D.clientX,H.lastMoveAt=Ee,H.lastOffset=ha,Se.set(ha),D.preventDefault()},ht=D=>{const H=ae.current;if(!(!H||H.pointerId!==D.pointerId)){q(),ae.current=null;try{D.currentTarget.releasePointerCapture(D.pointerId)}catch{}if(H.longPressFired){me.current=!0;return}if(H.dragging){const Ne=H.velocityX<nh?H.lastOffset<=-40:H.velocityX>sh?!1:H.lastOffset<=-46;be(Ne,{velocity:H.velocityX}),me.current=!0;return}ce&&(be(!1),me.current=!0)}},ye=D=>{const H=ae.current;if(!(!H||H.pointerId!==D.pointerId)){q(),ae.current=null;try{D.currentTarget.releasePointerCapture(D.pointerId)}catch{}H.dragging&&be(H.wasOpen)}},Re=D=>{D.stopPropagation(),!(O||!j)&&(be(!1,{immediate:!0}),j())},Ke=n.progress.unit==="CHAPTER"?e.jsx(Rh,{value:n.progress.value,shownNow:U,denomLabel:oe,max:$.editableChapterMax,onCommit:g,onIncrement:x,onDecrement:y}):e.jsx("button",{type:"button",className:L(Am,"min-h-10 bg-transparent sm:min-h-[20px]"),onClick:()=>i(),children:n.progress.unit==="WORD"?`${Number(n.progress.value||0).toLocaleString()} w`:`${Math.round(Number(n.progress.value||0))}%`}),jt=n.progress.unit==="CHAPTER"?e.jsxs("div",{className:ar,"data-card-interactive":"",onClick:D=>D.stopPropagation(),children:[e.jsx("button",{type:"button",className:nr,onClick:y,disabled:U<=0,"aria-label":"Decrease chapter",children:"−"}),e.jsxs("span",{className:Im,"aria-label":se,children:[e.jsx("span",{className:"text-content-muted",children:"Ch."})," ",U,e.jsx("span",{className:"px-1 text-content-muted",children:"/"}),oe]}),e.jsx("button",{type:"button",className:nr,onClick:x,disabled:typeof $.editableChapterMax=="number"&&U>=$.editableChapterMax,"aria-label":"Increase chapter",children:"+"})]}):e.jsx("button",{type:"button",className:ar,"data-card-interactive":"",onClick:D=>{D.stopPropagation(),i()},children:n.progress.unit==="WORD"?`${Number(n.progress.value||0).toLocaleString()} w`:`${Math.round(Number(n.progress.value||0))}%`}),Le=e.jsx(Ta,{children:e.jsx(ks,{value:n.status??"",onChange:D=>d(D),ariaLabel:`Reading status for ${s.title}`})}),Pe=e.jsx(Ta,{children:e.jsx(ks,{value:n.status??"",onChange:D=>d(D),ariaLabel:`Reading status for ${s.title}`,className:L("trace-state-select--mobile-chip",Wi({tone:$.tone}))})}),Me=()=>zi(n)?e.jsx(Ta,{className:Mm,children:e.jsx(Cc,{value:n.rating??0,onChange:N,size:"card",className:"trace-row-stars"})}):null,xt=D=>{const H=L(om,oh(G,I),D);return E&&!_?e.jsxs("a",{href:E,target:"_blank",rel:"noopener noreferrer",className:H,title:Y??`Open on ${G}`,"aria-label":Y?`Open on ${G} in new tab. ${Y}`:`Open on ${G} in new tab`,onClick:Ne=>Ne.stopPropagation(),children:[G,e.jsx("span",{"aria-hidden":!0,
2children:" ↗"})]}):e.jsx("span",{className:H,children:G})},at=_?e.jsx("span",{className:rm,"data-card-interactive":"",onClick:D=>D.stopPropagation(),children:e.jsx($r,{checked:p,onCheckedChange:()=>b?.(),"aria-label":`Select ${s.title}`})}):void 0,ma=p?"none":A&&z==="compact"?"current":"none",Nt=()=>{if(_){b?.();return}if(z==="browse"){if(!Q&&o){o();return}if(Q&&c){c();return}}i()},pa=_?`Select ${s.title}`:z==="browse"&&Q&&c?`Collapse evaluation for ${s.title}`:z==="browse"&&!Q&&o?`Evaluate ${s.title}`:`Open ${s.title}`,St=D=>{if(me.current){me.current=!1,D.preventDefault(),D.stopPropagation();return}if(ce){be(!1),D.preventDefault(),D.stopPropagation();return}if(_){D.stopPropagation(),b?.();return}const H=D.target;H&&H.closest(An)||Nt()};return e.jsxs("article",{ref:le,className:L(Om,Cm,A&&z==="compact"?Rm:_m($.tone),zu({selected:p,bulkMode:_,isBehind:$.isBehind,celebrate:W,statusChrome:ma,densityMode:z,isEvaluating:Q}),(ve||Te)&&qu,v),"data-mobile-swipe":ke,tabIndex:_?0:-1,role:"button","aria-label":pa,onPointerEnter:()=>R?.(1),onPointerLeave:()=>R?.(-1),onPointerDown:ge,onPointerMove:tt,onPointerUp:ht,onPointerCancel:ye,onClick:St,onKeyDown:D=>{if(D.key==="Enter"||D.key===" "){const H=D.target;if(H&&H.closest(An))return;D.preventDefault(),_?b?.():Nt()}},children:[j?e.jsx(ws.button,{type:"button",className:Gu({open:He}),style:{width:T},"data-card-interactive":"","data-state":ke,"aria-hidden":!He,tabIndex:ce?0:-1,disabled:O,"aria-label":`Remove ${s.title} from library`,onClick:Re,children:e.jsxs("span",{className:Qu,children:[e.jsx("span",{className:Xu,"aria-hidden":!0,children:e.jsx(Oa,{className:Zu})}),e.jsx("span",{children:O?"Removing":"Remove"})]})}):null,e.jsx(ws.div,{className:L(Ju,He&&em,pe&&tm),style:{transform:M},children:z==="compact"?e.jsx(jh,{showStoryUpdates:a,entry:n,story:s,vm:$,bulkMode:_,celebrate:W,selectControl:at,renderRatingControl:Me,renderSource:xt,isMostRecentReading:A,isEvaluating:Q,onChangeNotes:S,onChangeTags:C,onAddToCollection:l,onShare:m,onOpenDetails:u??i,seriesContext:te,onIncrementChapter:x,canIncrementChapter:!(typeof $.editableChapterMax=="number"&&U>=$.editableChapterMax)}):e.jsxs(e.Fragment,{children:[Q?e.jsx(Sh,{onDone:c}):null,e.jsx(Th,{showStoryUpdates:a,entry:n,story:s,vm:$,bulkMode:_,celebrate:W,selectControl:at,mobileProgressControl:jt,mobileStatusChipSelect:Pe,onExitEvaluate:c,renderRatingControl:Me,renderSource:xt,isMostRecentReading:A,isEvaluating:Q,onChangeNotes:S,onChangeTags:C,onAddToCollection:l,onShare:m,onOpenDetails:u??i,seriesContext:te}),e.jsx(Eh,{showStoryUpdates:a,entry:n,story:s,vm:$,bulkMode:_,celebrate:W,selectControl:at,actionProgressControl:Ke,statusSelect:Le,desktopVariant:F,renderRatingControl:Me,renderSource:xt,isMostRecentReading:A,isEvaluating:Q,onChangeNotes:S,onChangeTags:C,onAddToCollection:l,onShare:m,onOpenDetails:u??i,seriesContext:te})]})})]})});function jh({showStoryUpdates:t,entry:a,story:n,vm:s,bulkMode:i,celebrate:o,selectControl:c,renderSource:u,isMostRecentReading:l,seriesContext:m,onIncrementChapter:d,canIncrementChapter:x}){const y=Ua(a,s),g=Ya(a,s),N=l?"Last read":yt(a.status),S=s.cardUpdateLabel;return e.jsxs(e.Fragment,{children:[e.jsx(Nh,{showStoryUpdates:t,entry:a,story:n,vm:s,
2celebrate:o,selectControl:c,isMostRecentReading:l,seriesContext:m}),e.jsxs("div",{className:L(Bm,Vm),children:[e.jsxs("div",{className:tp,children:[c,e.jsx("span",{className:L(ap,Bi(s.tone)),"aria-hidden":!0}),e.jsx("span",{className:L(np,l&&sp),children:N})]}),e.jsxs("div",{className:ep,children:[e.jsxs("div",{className:rp,children:[e.jsx("h3",{className:ip,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,o?e.jsx("span",{className:la({show:o}),"aria-hidden":!0,children:"✓"}):null]}),e.jsxs("div",{className:op,children:[s.authorLine?e.jsx("span",{className:lp,children:s.authorLine}):null,s.authorLine&&s.fandomLine?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,s.fandomLine?e.jsx("span",{className:"truncate",children:s.fandomLine}):null,m?e.jsx(ca,{series:m}):null]})]}),i?e.jsx("span",{}):u(cp),e.jsxs("div",{className:dp,children:[e.jsxs("span",{className:up,children:[y,g?e.jsxs("span",{className:"text-[var(--ink-4)]",children:[" / ",g]}):null]}),S?e.jsx("span",{className:mp,title:s.cardUpdateTitle??void 0,children:S}):null]}),a.progress.unit==="CHAPTER"?e.jsx(Ta,{className:rr,children:e.jsx("button",{type:"button",className:pp,onClick:d,disabled:!x,"aria-label":"Increase chapter on compact row",children:"+"})}):e.jsx("span",{className:rr,"aria-hidden":!0})]})]})}
2function Nh({showStoryUpdates:t,entry:a,story:n,vm:s,celebrate:i,selectControl:o,isMostRecentReading:c,seriesContext:u}){const l=Ua(a,s),m=Ya(a,s),d=c?"Last read":yt(a.status),x=a.status==="READING";return e.jsxs("div",{className:Hm,children:[e.jsxs("div",{className:Um,children:[o,e.jsx("h3",{className:Ym,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,i?e.jsx("span",{className:la({show:i}),"aria-hidden":!0,children:"✓"}):null,e.jsxs("span",{className:Km,children:[l,m?e.jsxs("span",{className:Wa,children:[" ","/ ",m]}):null]})]}),e.jsxs("div",{className:zm,children:[e.jsx("span",{className:L(qm,Bi(s.tone)),"aria-hidden":!0}),e.jsx("span",{className:L(Gm,c&&Qm),children:d}),s.fandomLine?e.jsxs("span",{className:Xm,children:["· ",s.fandomLine]}):null,u?e.jsx(ca,{series:u}):null]}),x?e.jsx("div",{className:Zm,"aria-hidden":!0,children:e.jsx("span",{className:Jm,style:{width:`${s.visualProgressPercent}%`,"--mobile-compact-progress-color":s.visualProgressColor}})}):null]})}function Sh({onDone:t}){return e.jsxs("div",{className:hp,"data-card-interactive":"",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:xp,children:[e.jsx("span",{className:bp,children:"Evaluating"}),e.jsx("span",{className:gp,children:"Changes save as you go"})]}),e.jsx("div",{className:fp,children:e.jsxs("button",{type:"button",className:jp,onClick:t,children:["Done",e.jsx(wt,{className:ea,"aria-hidden":!0})]})})]})}function Bt({children:t}){return e.jsx("div",{className:Np,children:t})}function kh(t){return t.trim().replace(/\s+/g," ")}function Ch(t,a){const n=kh(a);return n?t.some(i=>i.trim().toLowerCase()===n.toLowerCase())?t:[...t,n]:t}function _h({tags:t,onChangeTags:a}){const[n,s]=r.useState(!1),[i,o]=r.useState(""),c=()=>{o(""),s(!1)},u=l=>{l.preventDefault();const m=Ch(t,i);m!==t&&a?.(m),c()};return n?e.jsxs("form",{className:Ap,"data-card-interactive":"",onClick:l=>l.stopPropagation(),onSubmit:u,children:[e.jsx("input",{"aria-label":"New private tag",autoFocus:!0,className:Tp,value:i,maxLength:48,onChange:l=>o(l.target.value),onKeyDown:l=>{l.key==="Escape"&&(l.preventDefault(),c())}}),e.jsx("button",{type:"submit",className:Ep,disabled:!i.trim(),children:"Add"})]}):e.jsxs("button",{type:"button",className:Lp,"data-card-interactive":"",disabled:!a,"aria-label":"Add private tag",onClick:l=>{l.stopPropagation(),a&&s(!0)},children:[e.jsx(mt,{className:ea,"aria-hidden":!0}),"tag"]})}function Gi({entry:t,story:a,onChangeTags:n}){const{publicTags:s,privateTags:i}=Zi(a,t),o=i.slice(0,5),c=s.slice(0,5),u=Math.max(0,s.length-c.length);return e.jsxs("div",{className:Op,children:[e.jsxs("div",{className:or,children:[e.jsx(Bt,{children:"Your tags"}),e.jsxs("div",{className:lr,children:[o.map(l=>e.jsxs("span",{className:L(Dt,_p),children:[e.jsx("span",{className:Rp,"aria-hidden":!0}),l]},`private:${l}`)),e.jsx(_h,{tags:i,onChangeTags:n})]})]}),e.jsxs("div",{className:or,children:[e.jsx(Bt,{children:"Source tags"}),e.jsxs("div",{className:lr,children:[c.length?c.map(l=>e.jsx("span",{className:L(Dt,l.tone==="relationship"&&$i),title:l.value,children:l.value},`source:${l.tone}:${l.value}`)):e.jsx("span",{className:Pp,children:"No source tags"}),u>0?e.jsxs("span",{className:L(Dt,"trace-row-chip--muted"),children:["+",u]}):null]})]})]})}function Qi({entryId:t,note:a,onChangeNotes:n}){const[s,i]=r.useState(!1),[o,c]=r.useState(a??"");if(r.useEffect(()=>{c(a??""),i(!1)},[t,a]),s)return e.jsxs("div",{className:Wp,"data-card-interactive":"",onClick:l=>l.stopPropagation(),children:[e.jsx("textarea",{"aria-label":"Private note",className:kp,value:o,maxLength:1200,readOnly:!n,placeholder:"What did you think? Where did you leave off?",onChange:l=>c(l.target.value)}),e.jsxs("div",{className:Bp,children:[e.jsx("button",{type:"button",className:Vp,onClick:()=>{n?.(o),i(!1)},children:"Save note"}),e.jsx("button",{type:"button",className:Hp,onClick:()=>{c(a??""),i(!1)},children:"Cancel"}),e.jsxs("span",{className:Cp,children:[o.length.toLocaleString()," chars"]})]})]});const u=o.trim();return e.jsx("button",{type:"button",className:u?Fp:$p,"data-card-interactive":"",onClick:l=>{l.stopPropagation(),i(!0)},children:u||"Add a note"})}function Xi({onAddToCollection:t,onShare:a,onOpenDetails:n}){return e.jsxs("div",{className:Mp,"data-card-interactive":"",children:[e.jsxs("button",{type:"button",className:ir,disabled:!t,onClick:s=>{s.stopPropagation(),t?.()},children:[e.jsx(Qr,{className:ea,"aria-hidden":!0}),"Collection"]}),e.jsxs("button",{type:"button",className:ir,disabled:!a,onClick:s=>{s.stopPropagation(),a?.()},children:[e.jsx(ni,{className:ea,"aria-hidden":!0}),"Copy link"]}),e.jsxs("button",{type:"button",className:vp,onClick:s=>{s.stopPropagation(),n()},children:[e.jsx("span",{className:yp,children:"Details"}),e.jsx("span",{className:wp,children:"View full details"}),e.jsx(si,{className:ea,"aria-hidden":!0})]})]})}function Rh({value:t,shownNow:a,denomLabel:n,max:s,onCommit:i,onIncrement:o,onDecrement:c}){const[u,l]=r.useState(String(t));r.useEffect(()=>{l(String(t))},[t]);const m=d=>{const x=Number(d.replace(/[^\d]/g,"")),y=Number.isFinite(x)?x:0,g=Math.max(0,Math.min(s??y,y));i(g),l(String(g))};return e.jsxs("div",{className:Dm,onClick:d=>d.stopPropagation(),children:[e.jsx("button",{type:"button",className:sr,onClick:c,disabled:a<=0,"aria-label":"Decrease chapter on desktop",children:"−"}),e.jsxs("span",{className:Fm,children:[e.jsx("input",{"aria-label":"Chapter",type:"text",inputMode:"numeric",pattern:"[0-9]*",value:u,size:Math.min(4,Math.max(2,u.length||1)),onChange:d=>l(d.target.value),onBlur:d=>m(d.target.value),onKeyDown:d=>{d.key==="Enter"&&m(d.currentTarget.value)},className:"h-5 min-w-0 rounded-none border-0 bg-transparent p-0 text-center font-mono text-[13px] leading-none text-content-primary outline-none focus-visible:shadow-[0_1px_0_var(--library-secondary)]"}),e.jsx("span",{className:"px-1 text-content-muted",children:"/"}),e.jsx("span",{children:n})]}),e.jsx("button",{type:"button",className:sr,onClick:o,disabled:typeof s=="number"&&a>=s,"aria-label":"Increase chapter on desktop",children:"+"})]})}function Lh(t){const a=t.contentRating?.trim();return a?`Rated ${a}`:null}function Ah(t,a){return[a.fandomLine,a.wordCountLabel,Lh(t)].filter(n=>!!n)}function Zi(t,a){const{chips:n,hiddenPrimaryCount:s}=Mh(t,{relationshipLimit:1}
2),i=(a.tags??[]).filter(Boolean);return{publicTags:n,hiddenPublicCount:s,privateTags:i}}function Ji({story:t,entry:a,maxPublic:n=4,maxPrivate:s=3,mobile:i=!1}){const{publicTags:o,hiddenPublicCount:c,privateTags:u}=Zi(t,a),l=o.slice(0,n),m=u.slice(0,s),d=c+Math.max(0,o.length-l.length)+Math.max(0,u.length-m.length);return!l.length&&!m.length&&d===0?null:e.jsxs("div",{className:L(i?L(km,"trace-row-tags--mobile"):pm),children:[l.map(x=>e.jsx("span",{className:L(Dt,x.tone==="relationship"&&$i,"trace-row-chip"),title:x.value,children:x.value},`public:${x.tone}:${x.value}`)),m.map(x=>e.jsxs("span",{className:L(Dt,hm,"trace-row-chip trace-row-chip--private"),title:x,children:["#",x]},`private:${x}`)),d>0?e.jsxs("span",{className:L(Dt,"trace-row-chip trace-row-chip--muted"),children:["+",d]}):null]})}function Th({showStoryUpdates:t,entry:a,story:n,vm:s,bulkMode:i,celebrate:o,selectControl:c,mobileProgressControl:u,mobileStatusChipSelect:l,renderRatingControl:m,renderSource:d,isMostRecentReading:x,isEvaluating:y,onChangeNotes:g,onChangeTags:N,onAddToCollection:S,onShare:C,onOpenDetails:_,seriesContext:p}){const b=!!a.notes?.trim()&&!i,k=a.status==="SAVED"||!a.notes?.trim()||b,j=[s.fandomLine,s.wordCountLabel].filter(F=>!!F),O=Ua(a,s),R=Ya(a,s);return y?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:vm,"data-card-interactive":"",onClick:F=>F.stopPropagation(),children:[e.jsx("span",{className:ym,children:"Evaluating"}),e.jsx("span",{className:wm,children:"Tap card to close"})]}),e.jsxs("div",{className:Ys,children:[e.jsxs("div",{className:Qs,children:[l,i?null:d(Xs)]}),e.jsxs("div",{className:Ks,children:[c,e.jsx("h3",{className:zs,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,e.jsx("span",{className:la({show:o}),"aria-hidden":!0,children:"✓"})]}),s.authorLine||j.length||p?e.jsxs("div",{className:qs,title:s.authorLine,children:[s.authorLine?e.jsxs(e.Fragment,{children:["by ",e.jsx("span",{className:Ln,children:s.authorLine})]}
2):null,s.authorLine&&j.length?" · ":null,j.map((F,A)=>e.jsxs(Ze.Fragment,{children:[A>0?" · ":null,F]},F)),p?e.jsxs(e.Fragment,{children:[s.authorLine||j.length?" · ":null,e.jsx(ca,{series:p})]}):null]}):null,k?e.jsx(En,{story:n,className:L(Gs,b&&Fi),lines:"line-clamp-5",maxChars:260}):null,zi(a)?e.jsxs("div",{className:Vi,children:[m(),e.jsx("span",{className:L(Hi,(a.rating??0)>0&&Ui),children:(a.rating??0)>0?`${a.rating}.0`:"rate"})]}):null,i?null:e.jsx(Gi,{story:n,entry:a,onChangeTags:N}),e.jsxs("div",{className:Ip,children:[e.jsx(Bt,{children:"Status & progress"}),u,e.jsxs("div",{className:Zs,children:[e.jsx("div",{className:Js,role:"meter","aria-label":s.progressChapterLine,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(s.visualProgressPercent),children:e.jsx("span",{className:er,style:{width:`${s.visualProgressPercent}%`,"--mobile-browse-progress-color":s.visualProgressColor}})}),e.jsxs("span",{className:tr,children:[O,R?e.jsxs("span",{className:Wa,children:[" ","/ ",R]}):null]})]}),e.jsx(Tn,{story:n})]}),i?null:e.jsxs("div",{className:Dp,children:[e.jsx(Bt,{children:"Your note"}),e.jsx(Qi,{entryId:a.id,note:a.notes,onChangeNotes:g}),e.jsx(Xi,{onAddToCollection:S,onShare:C,onOpenDetails:_})]})]})]}):e.jsxs("div",{className:Ys,children:[e.jsxs("div",{className:Qs,children:[e.jsx(qi,{status:a.status,tone:s.tone,isCurrent:x}),i?null:d(Xs)]}),e.jsxs("div",{className:Ks,children:[c,e.jsx("h3",{className:zs,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,e.jsx("span",{className:la({show:o}),"aria-hidden":!0,children:"✓"})]}),s.authorLine||j.length||p?e.jsxs("div",{className:qs,title:s.authorLine,children:[s.authorLine?e.jsxs(e.Fragment,{children:["by ",e.jsx("span",{className:Ln,children:s.authorLine})]}
2):null,s.authorLine&&j.length?" · ":null,j.map((F,A)=>e.jsxs(Ze.Fragment,{children:[A>0?" · ":null,F]},F)),p?e.jsxs(e.Fragment,{children:[s.authorLine||j.length?" · ":null,e.jsx(ca,{series:p})]}):null]}):null,e.jsx(En,{story:n,className:Gs,lines:"line-clamp-2",maxChars:165}),e.jsx(gh,{value:a.rating}),i?null:e.jsx(Ji,{story:n,entry:a,maxPublic:2,maxPrivate:0,mobile:!0}),e.jsxs("div",{className:Zs,children:[e.jsx("div",{className:Js,role:"meter","aria-label":s.progressChapterLine,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(s.visualProgressPercent),children:e.jsx("span",{className:er,style:{width:`${s.visualProgressPercent}%`,"--mobile-browse-progress-color":s.visualProgressColor}})}),e.jsxs("span",{className:tr,children:[O,R?e.jsxs("span",{className:Wa,children:[" ","/ ",R]}):null]})]}),e.jsx(Tn,{story:n})]})}function Eh({showStoryUpdates:t,...a}){return e.jsx(Ph,{showStoryUpdates:t,...a})}function Ph({showStoryUpdates:t,entry:a,story:n,vm:s,bulkMode:i,celebrate:o,selectControl:c,actionProgressControl:u,statusSelect:l,renderRatingControl:m,renderSource:d,isMostRecentReading:x,isEvaluating:y,onChangeNotes:g,onChangeTags:N,onAddToCollection:S,onShare:C,onOpenDetails:_,seriesContext:p}){const b=Ah(n,s),k=m(),j=!!a.notes?.trim()&&!i,O=a.status==="SAVED"||!a.notes?.trim()||j;return e.jsxs("div",{className:am,children:[e.jsxs("div",{className:nm,children:[y?e.jsx("div",{className:Up,children:l}):e.jsx(qi,{status:a.status,tone:s.tone,isCurrent:x}),e.jsxs("div",{className:sm,children:[c,e.jsx("h3",{className:im,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,d(),e.jsx("span",{className:la({show:o}),"aria-hidden":!0,children:"✓"})]}),e.jsxs("div",{className:lm,children:[s.authorLine?e.jsxs("span",{children:["by ",e.jsx("span",{className:Ln,children:s.authorLine})]}):null,b.map(R=>e.jsx("span",{children:R},R)),e.jsx(ca,{series:p}),typeof n.kudos=="number"&&n.kudos>0?e.jsxs("span",{children:[n.kudos.toLocaleString()," kudos"]}):null,a.reReadCount>0?e.jsxs("span",{children:[a.reReadCount+1,"× read"]}):null,s.verified?null:e.jsx("span",{children:"unverified"}),s.stateSignals.map(R=>e.jsx("span",{className:dm({tone:R.tone}),children:R.label},`state:${R.label}`))]}),O?e.jsx(En,{story:n,className:L(mm,j&&Fi),lines:y?"line-clamp-5":"line-clamp-2",maxChars:y?520:j?Jp:Zp}):null,k?e.jsxs("div",{className:y?Vi:um,children:[k,y?e.jsx("span",{className:L(Hi,(a.rating??0)>0&&Ui),children:(a.rating??0)>0?`${a.rating}.0`:"rate it"}):null]}):null,!i&&!y?e.jsx(Ji,{story:n,entry:a,maxPublic:6,maxPrivate:3}):null,!i&&y?e.jsxs("div",{className:Yp,children:[e.jsx("div",{className:Kp,children:e.jsx(Gi,{story:n,entry:a,onChangeTags:N})}),e.jsxs("div",{className:zp,children:[e.jsx(Bt,{children:"Your note"}),e.jsx(Qi,{entryId:a.id,note:a.notes,onChangeNotes:g}),e.jsx(Xi,{onAddToCollection:S,onShare:C,onOpenDetails:_})]})]}):null]}),e.jsx("aside",{className:xm,"aria-label":`Tracking for ${n.title}`,children:y?e.jsxs("div",{className:qp,children:[e.jsx(Bt,{children:"Progress"}),u,e.jsx(eo,{vm:s}),e.jsxs("span",{className:Sp,children:[s.progressChapterLine," · ",Math.round(s.visualProgressPercent),"%"]}),e.jsx(Tn,{story:n})]}):e.jsx(fh,{entry:a,vm:s})})]})}function eo({vm:t}){return e.jsx("div",{className:$m,role:"meter","aria-label":t.progressChapterLine,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(t.visualProgressPercent),children:e.jsx("span",{className:Wm,style:{width:`${t.visualProgressPercent}%`,"--desktop-progress-color":t.visualProgressColor}})})}function En({story:t,className:a,lines:n="line-clamp-2",maxChars:s}){const i=t.summary?.trim();if(!i)return null;const o=typeof s=="number"&&i.length>s?`${i.slice(0,Math.max(0,s-3)).trimEnd().replace(/[.,;:!?-]+$/,"")}...`:i;return e.jsx("p",{className:L(n,"text-sm leading-snug text-content-muted",a),children:o})}function xn(t){return Array.from(new Set(t.filter(Boolean)))}function Mh(t,a={}){const n=xn(t.relationships??[]),s=xn(t.canonicalCharacters?.length?t.canonicalCharacters:t.characters),i=Math.max(0,Math.floor(a.relationshipLimit??1)),o=n.length?n.slice(0,i):s,c=n.length?"relationship":"character",u=n.length?Math.max(0,n.length-o.length):0,l=ph(t)?xn(t.
2workTags??[]):[],m=new Set,d=[];for(const x of o){const y=x.toLowerCase();m.has(y)||(m.add(y),d.push({value:x,tone:c}))}if(n.length)for(const x of n.slice(o.length))m.add(x.toLowerCase());for(const x of l){const y=x.toLowerCase();m.has(y)||(m.add(y),d.push({value:x,tone:"tag"}))}return{chips:d,hiddenPrimaryCount:u}}function mr({position:t,cap:a,active:n=!1}){return e.jsxs("span",{className:Tu,"aria-hidden":"true",children:[e.jsx("span",{className:L(Eu,a==="header"&&"top-1/2",a==="end"&&"bottom-1/2",a==="solo"&&"bottom-1/2 top-1/2")}),a!=="header"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:L(Pu,n&&Mu)}),t!=null?e.jsx("span",{className:L(Iu,n&&Ou),children:t}):null]}):null]})}function Ih(t){const a=Array.from(new Set(t)).sort((s,i)=>s-i);return a.length?a.length===1?`Part ${a[0]}`:a.every((s,i)=>i===0||s===a[i-1]+1)?`Parts ${a[0]}–${a[a.length-1]}`:`Parts ${a.join(", ")}`:null}const Oh=({storyUpdatesEnabled:t=!0,gridRef:a,isLoading:n,isFetching:s=!1,isError:i,visible:o,storiesMap:c,activeFilterCount:u,debouncedSearch:l,bulkMode:m,isSelected:d,onToggleSelect:x,onStartBulkSelect:y,onRemoveEntry:g,removingEntryId:N=null,onOpenDetails:S,onChangeStatus:C,onIncrementChapter:_,onDecrementChapter:p,onSetChapterValue:b,onChangeRating:k,onChangeNotes:j,onChangeTags:O,onAddToCollection:R,onShareStory:F,onLayoutPointerLockChange:A,deferredRecencyReorderIds:z=[],onDeferredRecencyEntryExit:Q,mostRecentReadingEntryId:te,loadMoreRef:v,hasNextPage:$,isFetchingNextPage:f,onFetchNextPage:U,onAddManually:oe,firstStoryCompleted:se=!1,onRetry:G,splitDetailOpen:I=!1,densityMode:E="compact",groupingMode:Y="none",evaluatingEntryId:W=null,onStartEvaluate:J,onCloseEvaluate:X,getDesktopCardVariant:ee,getDesktopCardVariantLabel:le})=>{const[ae,P]=r.useState(()=>new Set),re=!u&&!l,me=n,ce=!n&&!i&&o.length>0,We=r.useMemo(()=>Y==="series"?cc(o,c):o.map(M=>({kind:"entry",entry:M})),[Y,c,o]),pe=m||u>0||l.trim().length>0,De=r.useCallback(M=>{P(T=>{const K=new Set(T);return K.has(M)?K.delete(M):K.add(M),K})},[]),Se=r.useCallback((M,T,K)=>{const q=c[M.storyId];if(!q)return null;const fe=Y==="series"&&!K?ka(q):null,be=ee?.(M,T),we=le?.(M,T);return e.jsxs(Dh,{className:K?Lu:void 0,active:z.includes(M.id),onExit:()=>Q?.(M.id),children:[K?e.jsx(mr,{position:K.position,cap:K.cap,active:K.active}):null,e.jsxs("div",{className:K?Au:void 0,children:[we?e.jsxs("div",{className:"mb-2 flex flex-wrap items-baseline justify-between gap-2 px-1",children:[e.jsx("div",{className:"text-2xs font-bold uppercase tracking-[0.18em] text-content-muted",children:we.label}),we.note?e.jsx("div",{className:"text-xs text-content-subtle",children:we.note}):null]}):null,e.jsx(wh,{showStoryUpdates:t,entry:M,story:q,seriesContext:fe,onOpen:()=>S(M.id),onEnterEvaluate:()=>J?.(M.id),onExitEvaluate:X,onOpenDetails:()=>S(M.id),onAddToCollection:()=>R?.(M.id),onShare:F?()=>F(M.id):void 0,onChangeStatus:ve=>C(M.id,ve),onIncrementChapter:()=>_(M.id),onDecrementChapter:()=>p(M.id),onSetChapterValue:ve=>b(M.id,ve),onChangeRating:ve=>k(M.id,ve),onChangeNotes:j?ve=>j(M.id,ve):void 0,onChangeTags:O?ve=>O(M.id,ve):void 0,bulkMode:m,selected:d(M.id),onToggleSelect:()=>x(M.id),onStartBulkSelect:y?()=>y(M.id):void 0,onRemoveFromLibrary:g?()=>g(M.id):void 0,removing:N===M.id,onLayoutPointerLockChange:A,desktopVariant:be,isMostRecentReading:M.id===te,densityMode:E,isEvaluating:W===M.id})]})]},M.id)},[m,t,z,E,W,ee,le,Y,d,te,R,j,k,C,O,X,p,Q,_,A,S,g,b,F,y,J,x,N,c]);return e.jsxs("div",{ref:a,className:L("mt-0",I&&"lg:mt-0"),"aria-busy":n||s,children:[me&&e.jsxs("div",{className:L(Ca({splitDetail:I,densityMode:E})),"aria-busy":"true","aria-label":"Loading library stories",children:[e.jsx("p",{className:"col-span-full px-4 text-xs font-medium text-content-muted sm:px-0",children:"Loading library stories"}),Array.from({length:4}).map((M,T)=>e.jsx(bc,{},T))]}),!n&&i&&e.jsx("div",{className:L(Ca({splitDetail:I,densityMode:E})),children:e.jsx(Ls,{chrome:"bare",variant:"error",title:"We couldn't reach your library.",description:"A sync hiccup, almost certainly on our side. Your stories are safe; nothing has been lost.",detail:"Trace · err · LIB.503",actions:G?e.jsx(de,{variant:"solid",size:"lg",onClick:G,children:"Try again"}):null,className:"col-span-full"})}),!n&&!i&&o.length===0&&re&&oe&&e.jsx(Yu,{onAddManually:oe,firstStoryCompleted:se}),!n&&!i&&o.length===0&&!re&&e.jsx("div",{className:L(Ca({splitDetail:I,densityMode:E})),children:e.jsx(Ls,{chrome:"bare",variant:"no-results",title:Ku(u,l),description:"Loosen a filter, or clear them all to see your full library.",className:"col-span-full"})}),ce&&e.jsxs("div",{className:L(Ca({splitDetail:I,densityMode:E}),E==="compact"&&ju),children:[E==="compact"?e.jsxs("div",{className:Nu,"aria-hidden":"true",children:[e.jsx("span",{className:_a,children:"Status"}),e.jsx("span",{className:_a,children:"Story"}),e.jsx("span",{className:_a,children:"Src"}),e.jsx("span",{className:L(_a,"text-right"),children:"Chapter"}),e.jsx("span",{})]}):null,We.map((M,T)=>{if(M.kind==="entry")return Se(M.entry,T);const K=pe||!ae.has(M.key),q=`library-series-${T}
2`,fe=M.entries.map(Re=>ka(c[Re.storyId])?.position).filter(Re=>Re!=null),be=Ih(fe),we=u>0||l.trim().length>0,ve=`${M.entries.length}${we?" matching":""} in library`,Te=M.entries.find(Re=>Re.id===M.anchorEntryId)??M.entries[0],He=Te?ka(c[Te.storyId])?.position??null:null,ke=M.entries.filter(Re=>d(Re.id)).length,ge=ke===M.entries.length,tt=K?M.entries:Te?[Te]:[],ht=K?`${ve}${be?` · ${be}`:""}`:`${ve}${He!=null?` · showing part ${He}`:""} · ${Math.max(0,M.entries.length-1)} hidden`,ye=()=>{M.entries.forEach(Re=>{(ge?d(Re.id):!d(Re.id))&&x(Re.id)})};return e.jsxs("section",{className:Su,"aria-label":`${M.name} series`,children:[e.jsxs("div",{className:ku,children:[e.jsx(mr,{cap:"header"}),m?e.jsxs("div",{className:Ws,children:[e.jsx($r,{checked:ge,indeterminate:ke>0&&!ge,onCheckedChange:ye,"aria-label":`Select ${M.entries.length} loaded stories from ${M.name}`}),e.jsxs("span",{className:Bs,children:[e.jsx("span",{className:Vs,children:"Series"}),e.jsx("span",{className:Hs,children:M.name}),e.jsx("span",{className:Us,children:ke>0?`${ke} of ${M.entries.length} selected`:ht})]})]}):e.jsxs("button",{type:"button",className:Ws,"aria-expanded":K,"aria-controls":q,disabled:pe,title:pe?u>0?"Series stay expanded while filters are active":"Series stay expanded while searching":void 0,onClick:()=>De(M.key),children:[e.jsx(si,{"aria-hidden":!0,className:L(Cu,K&&"rotate-90")}),e.jsxs("span",{className:Bs,children:[e.jsx("span",{className:Vs,children:"Series"}),e.jsx("span",{className:Hs,children:M.name}),e.jsx("span",{className:Us,children:ht})]})]}),M.url?e.jsx("a",{className:_u,href:M.url,target:"_blank",rel:"noreferrer","aria-label":`Open ${M.name} series on source`,children:e.jsx(It,{"aria-hidden":!0})}):e.jsx("span",{"aria-hidden":!0})]}),e.jsx("div",{className:Ru,id:q,role:"group","aria-label":`${M.name}, ${M.entries.length} stories in your library`,children:tt.map((Re,Ke)=>{const jt=ka(c[Re.storyId])?.position??null,Le=K?Ke===0?"start":Ke===tt.length-1?"end":"middle":"solo";return Se(Re,T+Ke,{position:jt,cap:Le,active:Re.id===M.anchorEntryId})})})]},M.key)})]}),e.jsx("div",{ref:v,className:"h-px","aria-hidden":"true"}),$&&e.jsx("div",{className:"flex flex-col items-center gap-4 pt-10",children:e.jsx(de,{className:"library-load-more",variant:f?"ghost":"outline",disabled:f,loading:f,onClick:U,children:f?"Loading…":"Load more"})})]})};function Dh({active:t,onExit:a,className:n,children:s}){const i=r.useRef(null);return r.useEffect(()=>{if(!t||typeof IntersectionObserver>"u")return;const o=i.current;if(!o)return;let c=!1;const u=new IntersectionObserver(l=>{const m=l[0];!m||c||m.isIntersecting||(c=!0,a())},{root:null,threshold:0});return u.observe(o),()=>u.disconnect()},[t,a]),e.jsx("div",{ref:i,className:L(wu,n),children:s})}const Fh=t=>{if(!Number.isFinite(t)||t<=0)return"";const a=Math.max(0,Math.min(5,Math.round(t)));return"★".repeat(a)+"☆".repeat(5-a)},$h=t=>typeof t=="number"?t>=1e3?`${Math.round(t/100)/10}k`:`${t}`:"",pr=(t="",a=300)=>t.length>a?t.slice(0,a-1)+"…":t,lt=(t="")=>t.replace(/\s+/g," ").trim(),bn=(t,a=" • ")=>t.filter(Boolean).join(a),Wh=new Set(["\\","`","*","_","{","}","[","]"]),Vt=(t="")=>Array.from(t,a=>Wh.has(a)?`\\${a}`:a).join(""),Bh=t=>{const a=Vt(lt(t.title));return t.canonicalUrl?`**[${a}](${t.canonicalUrl})**`:`**${a}**`},Vh=t=>{const a=t.map(n=>lt(n)).filter(Boolean).join(", ");return a?` by ${Vt(a)}`:""},Hh=t=>t.split(/\n+/).map(lt).filter(Boolean).map(a=>`> ${Vt(a)}`).join(`
3`),Uh=t=>t.split(/\n+/).map(lt).filter(Boolean).map(a=>`> Private note: ${Vt(a)}`).join(`
4`),Yh=t=>Array.isArray(t)?t.map(a=>typeof a=="string"?a.trim():String(a??"").trim()).filter(Boolean):typeof t=="string"&&t.trim()?[t.trim()]:[],Kh=t=>{const a=(()=>{try{return t.canonicalUrl?new URL(t.canonicalUrl).hostname.replace(/^www\./,""):""}catch{return""}})(),n=a.toLowerCase();return t.source||(n.includes("archiveofourown")?"AO3":n.includes("fanfiction")?"FFN":a)},zh=(t,a,n,s)=>{const i=[],o=s?.trim();return o&&i.push(`## ${o}`,""),t.forEach((c,u)=>{const l=a[c.storyId];if(!l)return;const m=n.includeSummary,d=n.includeRelationships,x=n.includeNotes,y=Kh(l),g=Bh(l),N=Vh(l.authors||[]),S=l.words?`${$h(l.words)} words`:"",C=n.includeRating?Fh(c.rating):"",_=n.includeRating&&C?C:"",p=l.fandoms?.length?lt(l.fandoms.join(" / ")):"",b=Yh(l.relationships),k=d&&b.length?Vt(lt(b.join(", "))):"",j=m&&l.summary?pr(lt(l.summary),420):"",O=x&&c.notes?pr(lt(c.notes),420):"";i.push(`${g}${N}`);const R=bn([y||"",S,_]),F=bn([p?Vt(p):"",k]," · "),A=bn([R,F]," · ");A&&i.push("",A),j&&i.push("",Hh(j)),O&&i.push("",Uh(O)),u!==t.length-1&&i.push("")}),i.join(`
5`)},qh=t=>{if(!Number.isFinite(t)||t<=0)return"";const a=Math.max(0,Math.min(5,Math.round(t)));return"★".repeat(a)+"☆".repeat(5-a)},Gh=t=>typeof t=="number"?t>=1e3?`${Math.round(t/100)/10}k`:`${t}`:"",hr=(t="",a=300)=>t.length>a?t.slice(0,a-1)+"…":t,Ra=(t="")=>t.replace(/\s+/g," ").trim(),gn=(t,a=" · ")=>t.filter(Boolean).join(a),Qh=t=>Array.isArray(t)?t.map(a=>
5typeof a=="string"?a.trim():String(a??"").trim()).filter(Boolean):typeof t=="string"&&t.trim()?[t.trim()]:[],Xh=t=>{const a=(()=>{try{return t.canonicalUrl?new URL(t.canonicalUrl).hostname.replace(/^www\./,""):""}catch{return""}})(),n=a.toLowerCase();return t.source||(n.includes("archiveofourown")?"AO3":n.includes("fanfiction")?"FFN":a)},Zh=(t,a,n,s)=>{const i=[],o=s?.trim();return o&&i.push(o,""),t.forEach((c,u)=>{const l=a[c.storyId];if(!l)return;const m=n.includeSummary,d=n.includeRelationships,x=n.includeNotes,y=Xh(l),g=(l.authors||[]).join(", "),N=l.words?`${Gh(l.words)} words`:"",S=n.includeRating?qh(c.rating):"",C=n.includeRating&&S?S:"",_=l.fandoms?.length?Ra(l.fandoms.join(" / ")):"",p=Qh(l.relationships),b=d&&p.length?Ra(p.join(", ")):"",k=m&&l.summary?hr(Ra(l.summary),420):"",j=x&&c.notes?hr(Ra(c.notes),420):"";i.push(`${l.title}${g?` - ${g}`:""}`),l.canonicalUrl&&i.push(l.canonicalUrl);const O=gn([y||"",N,C]),R=gn([_,b]," · "),F=gn([O,R]," · ");F&&i.push(F),k&&i.push("",k),j&&i.push("",`Private note: ${j}`),u!==t.length-1&&i.push("")}),i.join(`
6`)};function Jh({selected:t,options:a=[],getOptions:n,onChange:s,id:i,placeholder:o="Select tags…",multi:c=!0,allowCreate:u=!0,triggerClassName:l,panelClassName:m}){return e.jsx(zl,{id:i,value:t,onChange:s,getOptions:n,options:a,placeholder:o,searchPlaceholder:"Search tags…",ariaLabel:o,multi:c,allowCreate:u,showClear:!0,showDone:!0,maxChips:3,transformOptions:d=>Array.from(new Set(d.map(x=>x.trim()).filter(Boolean))).sort((x,y)=>x.localeCompare(y,void 0,{sensitivity:"base"})),className:"w-full",triggerClassName:l,panelClassName:m})}const ex="library-app archive-editorial-shell flex h-full min-h-0 w-full flex-col overflow-hidden bg-[var(--paper)] bg-none text-[var(--ink)]",tx="min-h-0 flex-1 overflow-y-auto overscroll-contain px-[22px] py-[18px] [-webkit-overflow-scrolling:touch]",fn="space-y-3 border-t border-[var(--line)] py-4 first:border-t-0 first:pt-0",ax="flex items-start gap-3",nx=["mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-[6px]","bg-[var(--forest)] font-[var(--landing-font-mono)]","text-[10.5px] font-bold text-[var(--paper)]"].join(" "),sx="text-[14px] font-semibold leading-tight text-[var(--ink)]",rx="space-y-3",ix="flex flex-col gap-1.5",ox=t=>["flex w-full cursor-pointer items-start gap-3 rounded-[10px] border px-[14px] py-3 text-left","font-[var(--landing-font-sans)] transition","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]",t?"border-[var(--ink-3)] bg-[var(--card-2)]":"border-[var(--line)] bg-[var(--card)] hover:border-[var(--line-strong)]","disabled:cursor-not-allowed disabled:opacity-50"].join(" "),lx=t=>["mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border-[1.5px]",t?"border-[var(--forest-deep)] bg-[var(--forest-deep)]":"border-[var(--ink-4)] bg-transparent"].join(" "),cx="h-1.5 w-1.5 rounded-full bg-[var(--paper)]",dx="min-w-0 flex-1",ux="block text-[14px] font-medium leading-snug text-[var(--ink)]",mx="mt-0.5 block font-[var(--landing-font-mono)] text-[11.5px] leading-snug text-[var(--ink-3)]",px="shrink-0 font-[var(--landing-font-mono)] text-[11.5px] text-[var(--ink-4)]",hx="min-w-0 space-y-3",xx="grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-start",bx=["!min-h-[42px] !rounded-[10px] !border !border-[var(--line)]","!bg-[var(--card)] !px-3 !py-2","!font-[var(--landing-font-sans)] !text-[14px] !text-[var(--ink)]","hover:!border-[var(--line-strong)] hover:!bg-[var(--card)]","aria-expanded:!border-[var(--honey)] aria-expanded:!bg-[var(--paper)]","aria-expanded:!shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]"].join(" "),gx=["library-app archive-editorial-shell","!rounded-[12px] !border-[var(--line-strong)] !bg-[var(--card)] !shadow-[var(--shadow-modal)]","[&>div:first-child]:!border-[var(--line)] [&>div:first-child]:!bg-[var(--card)]","[&>div:last-child]:!border-[var(--line)] [&>div:last-child]:!bg-[var(--paper-2)]"].join(" "),fx="tf-segmented tf-segmented--sm",xr=t=>["tf-seg",t?"is-on":""].filter(Boolean).join(" "),vx="flex flex-wrap items-baseline gap-x-1.5",yx="text-[14px] font-medium text-[var(--ink)]",wx="font-[var(--landing-font-mono)] text-[11.5px] leading-relaxed text-[var(--ink-3)]",jx="space-y-1.5",Nx="border-l-[3px] border-[var(--honey)] bg-[var(--card)] px-3 py-2",Sx="truncate font-[var(--landing-font-serif)] text-[15px] font-medium leading-tight text-[var(--ink)]",kx="mt-0.5 truncate font-[var(--landing-font-mono)] text-[11.5px] leading-snug text-[var(--ink-3)]",Cx="px-3 font-[var(--landing-font-mono)] text-[11.5px] text-[var(--ink-4)]",_x="border-l-[3px] border-[var(--rust)] bg-[
6color-mix(in_oklab,var(--rust)_8%,transparent)] px-3 py-2 text-[13px] text-[var(--rust)]",Rx="space-y-2",La="a-form-label",Lx="tf-field",Ax="a-form-hint",Tx="grid gap-4 sm:grid-cols-[minmax(0,0.75fr)_minmax(0,1.25fr)]",Ex="tf-segmented",br=t=>["tf-seg",t?"is-on":""].filter(Boolean).join(" "),Px="flex flex-col gap-1",Mx="tf-toggle-row",Ix=t=>["tf-switch",t?"is-on":""].filter(Boolean).join(" "),Ox="tf-toggle-main",Dx="tf-toggle-title",Fx="tf-toggle-sub",$x="space-y-3",Wx="text-[14px] font-medium leading-tight text-[var(--ink)]",Bx="mt-0.5 font-[var(--landing-font-mono)] text-[11.5px] leading-snug text-[var(--ink-3)]",Vx="flex items-start gap-2 text-[12px] leading-relaxed text-[var(--ink-3)]",Hx="text-[var(--rust)]",Ux="flex flex-wrap items-center gap-2",gr="a-btn is-secondary is-sm",Yx="tf-field tf-field--textarea",Kx="min-h-40 w-full resize-y font-[var(--landing-font-mono)] text-[12px] leading-[1.65]",zx="a-panelfoot shrink-0",qx="flex-1",Gx="a-btn is-ghost",Qx="a-btn is-secondary max-sm:hidden",Xx="a-btn is-primary",Xt=50,Zx=3,to={selected:"Selected stories",visible:"Visible view",tag:"Tagged stories"},Jx={selected:"Checked in the library",visible:"Matches the current filters",tag:"Matches selected library tags"};function ao(t){return`${t} ${t===1?"story":"stories"}`}function eb(t){if(!t)return"Story unavailable";const a=t.authors.filter(Boolean).join(", ")||"Unknown author",n=t.fandoms.filter(Boolean)[0]??"Unknown fandom";return`${a} - ${n}`}function tb(t,a){switch(t){case"copied":return"Copied to clipboard.";case"error":return"Copy failed. The preview remains selectable.";case"unavailable":return"No shareable stories for this scope.";case"idle":return`Ready to copy ${ao(a)}.`}}function vn({step:t,title:a}){return e.jsxs("div",{className:ax,children:[e.jsx("span",{className:nx,children:t}),e.jsx("h3",{className:sx,children:a})]})}function ab({selectedCount:t,visibleCount:a,tagShareCount:n,shareSource:s,onChangeShareSource:i}){const o=[{value:"visible",count:a},{value:"selected",count:t},{value:"tag",count:n}];return e.jsx("div",{className:ix,role:"group","aria-label":"Share scope",children:o.map(c=>{const u=s===c.value,l=c.value==="selected"&&t===0;return e.jsxs("button",{type:"button",disabled:l,"aria-pressed":u,className:ox(u),onClick:()=>i(c.value),children:[e.jsx("span",{className:lx(u),"aria-hidden":!0,children:u?e.jsx("span",{className:cx}):null}),e.jsxs("span",{className:dx,children:[e.jsx("span",{className:ux,children:to[c.value]}),e.jsx("span",{className:mx,children:l?"Select stories first":Jx[c.value]})]}),e.jsx("span",{className:px,children:c.count})]},c.value)})})}function nb({clipboardFormat:t,onChange:a}){return e.jsxs("div",{className:Ex,role:"group","aria-label":"Clipboard format",children:[e.jsx("button",{type:"button","aria-pressed":t==="markdown",className:br(t==="markdown"),onClick:()=>a("markdown"),children:"Markdown"}),e.jsx("button",{type:"button","aria-pressed":t==="plaintext",className:br(t==="plaintext"),onClick:()=>a("plaintext"),children:"Plain text"})]})}function sb({shareOpts:t,onChangeShareOpts:a}){const n=[{key:"includeRating",label:"Rating",sub:"Five-star rating you set."},{key:"includeRelationships",label:"Relationships",sub:"AO3 ship tags from source."},{key:"includeSummary",label:"Summary",sub:"First 280 characters of the source blurb."},{key:"includeNotes",label:"Private notes",sub:"Stay off by default. Toggle on with care."}];return e.jsx("div",{className:Px,children:n.map(s=>{const i=t[s.key];return e.jsxs("button",{type:"button","aria-pressed":i,"aria-label":s.label,className:Mx,onClick:()=>a(o=>({...o,[s.key]:!o[s.key]})),children:[e.jsx("span",{className:Ix(i),"aria-hidden":!0}),e.jsxs("span",{className:Ox,children:[e.jsx("span",{className:Dx,children:s.label}),e.jsx("span",{className:Fx,children:s.sub})]})]},s.key)})})}function rb({open:t,onClose:a,selectedCount:n,visibleCount:s,tagShareCount:i,shareTotalCount:o,getEntriesForShareBatch:c,storiesMap:u,shareSource:l,onChangeShareSource:m,allTags:d,shareTags:x,onChangeShareTags:y,shareTagMatchMode:g,onChangeShareTagMatchMode:N,shareTitle:S,onChangeShareTitle:C,shareOpts:_,onChangeShareOpts:p,onToast:b}){const[k,j]=r.useState("markdown"),[O,R]=r.useState(!1),[F,A]=r.useState(!1),[z,Q]=r.useState(0),te=r.useMemo(()=>({..._,format:"Detailed"}),[_]),v=o,$=Math.max(1,Math.ceil(v/Xt)),f=Math.min(z,$-1),U=f*Xt,oe=Math.min(U+Xt,v),se=r.useMemo(()=>c(U,Xt),[c,U]),G=$>1;r.useEffect(()=>{R(!1),A(!1),Q(0)},[l,x,g]),r.useEffect(()=>{z>=$&&Q($-1)},[$,z]);const I=r.useMemo(()=>zh(se,u,te,S),[se,u,te,S]),E=r.useMemo(()=>Zh(se,u,te,S),[se,u,te,S]),Y=k==="markdown"?I:E,W=se.length>0,J=se.slice(0,Zx).map(P=>({entry:P,story:u[P.storyId]})),X=Math.max(0,v-J.length),ee=F?"error":W?O?"copied":"idle":"unavailable",le=async()=>
6{if(W)try{await navigator.clipboard.writeText(Y),R(!0),A(!1),window.setTimeout(()=>R(!1),1400),b?.(G?`Batch ${f+1} copied`:k==="markdown"?"Markdown copied":"Plain text copied")}catch{A(!0),b?.("Copy failed")}},ae=()=>{if(!W)return;const P=(S.trim()||"trace-stories").toLocaleLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48),re=new Blob([I],{type:"text/markdown;charset=utf-8"}),me=URL.createObjectURL(re),ce=document.createElement("a");ce.href=me,ce.download=`${P||"trace-stories"}.md`,document.body.append(ce),ce.click(),ce.remove(),URL.revokeObjectURL(me),b?.("Markdown downloaded")};return e.jsx(ui,{open:t,title:"Share",onClose:a,variant:"library",size:"lg",desktopPresentation:"sheet",desktopBackdrop:"transparent",hideHeader:!0,hideHeaderClose:!0,hideFooter:!0,panelClassName:pi.share,bodyClassName:mi,children:e.jsxs(dc,{eyebrow:"Share",title:"Share stories",onClose:a,closeLabel:"Close share drawer",className:ex,bodyClassName:tx,footerClassName:zx,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Gx,onClick:a,children:"Cancel"}),e.jsx("span",{className:qx}),e.jsx("button",{type:"button",className:Qx,onClick:ae,disabled:!W,children:"Download .md"}),e.jsxs("button",{type:"button",className:Xx,onClick:le,disabled:!W,children:[O?e.jsx(ut,{"aria-hidden":!0}):e.jsx(ni,{"aria-hidden":!0}),O?"Copied":k==="markdown"?"Copy Markdown":"Copy plain text"]})]}),children:[e.jsxs("section",{className:fn,children:[e.jsx(vn,{step:1,title:"Select what stories to share"}),e.jsxs("div",{className:rx,children:[e.jsx(ab,{selectedCount:n,visibleCount:s,tagShareCount:i,shareSource:l,onChangeShareSource:m}),e.jsxs("div",{className:hx,children:[l==="tag"?e.jsxs("div",{className:xx,children:[e.jsx(Jh,{selected:x,options:d,multi:!0,allowCreate:!1,placeholder:"Pick tags...",triggerClassName:bx,panelClassName:gx,onChange:y}),e.jsxs("div",{className:fx,role:"group","aria-label":"Tag match",children:[e.jsx("button",{type:"button","aria-pressed":g==="any",className:xr(g==="any"),onClick:()=>N("any"),children:"Any tag"}),e.jsx("button",{type:"button","aria-pressed":g==="all",className:xr(g==="all"),onClick:()=>N("all"),children:"Every tag"})]})]}):null,e.jsxs("div",{className:vx,children:[e.jsx("span",{className:yx,children:ao(v)}),e.jsxs("span",{className:wx,children:["from ",to[l].toLowerCase()]})]}),e.jsxs("div",{className:jx,children:[J.map(({entry:P,story:re})=>e.jsxs("div",{className:Nx,children:[e.jsx("div",{className:Sx,children:re?.title??"Story unavailable"}),e.jsx("div",{className:kx,children:eb(re)})]},P.id)),X>0?e.jsxs("div",{className:Cx,children:["+",X," more in this share"]}):null,J.length?null:e.jsx("div",{className:_x,children:"No stories match this scope."})]})]})]})]}),e.jsxs("section",{className:fn,children:[e.jsx(vn,{step:2,title:"Choose format and included details"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:Rx,children:[e.jsx("label",{className:La,htmlFor:"share-title",children:"List title"}),e.jsx("div",{className:Lx,children:e.jsx("input",{id:"share-title",placeholder:"Optional heading",value:S,onChange:P=>C(P.target.value),"aria-describedby":"share-title-help"})}),e.jsx("p",{id:"share-title-help",className:Ax,children:"Included as the heading at the top of the copied Markdown or plain-text list."})]}),e.jsxs("div",{className:Tx,children:[e.jsxs("div",{children:[e.jsx("div",{className:La,children:"Format"}),e.jsx(nb,{clipboardFormat:k,onChange:j})]}),e.jsxs("div",{children:[e.jsx("div",{className:La,children:"Details included"}),e.jsx(sb,{shareOpts:_,onChangeShareOpts:p})]})]})]})]}),e.jsxs("section",{className:fn,children:[e.jsx(vn,{step:3,title:"Copy"}),e.jsxs("div",{className:$x,children:[e.jsxs("div",{children:[e.jsx("div",{className:Wx,children:v===0?"No stories ready to copy":G?`Batch ${f+1} of ${$}`:`${v} ${v===1?"story":"stories"} ready to copy`}),v>0?e.jsxs("div",{className:Bx,children:["Copying ",U+1,"-",oe," of ",v,G?`, ${Xt} at a time.`:"."]}):null]}),e.jsxs("div",{className:L(Vx,(ee==="error"||ee==="unavailable")&&Hx),children:[ee==="error"||ee==="unavailable"?e.jsx(Ol,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}):O?e.jsx(ut,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null,e.jsx("span",{children:tb(ee,v)})]}),G?e.jsxs("div",{className:Ux,"aria-label":"Share batch",children:[e.jsx("button",{type:"button",className:gr,disabled:f===0,onClick:()=>Q(P=>Math.max(0,P-1)),children:"Previous batch"}),e.jsx("button",{type:"button",className:gr,disabled:f>=$-1,onClick:()=>Q(P=>Math.min($-1,P+1)),children:"Next batch"})]}):null,e.jsxs("div",{children:[e.jsx("div",{className:La,children:"Output preview"}),e.jsx("div",{className:Yx,children:e.jsx("textarea",{className:Kx,rows:8,readOnly:!0,value:Y,"aria-label":k==="markdown"?"Markdown preview":"Plain text preview"})})]})]})]})]})})}
6const ib=["hidden sm:flex","sticky top-0 z-[1300]","items-center gap-2 overflow-x-auto","border-b border-[color-mix(in_oklab,var(--honey)_34%,var(--line-strong))]","bg-[color-mix(in_oklab,var(--honey)_18%,var(--paper))] px-8 py-3 text-[var(--ink)] shadow-[0_14px_28px_color-mix(in_oklab,var(--honey)_10%,transparent)]","max-w-full min-w-0 [-webkit-overflow-scrolling:touch]"].join(" "),ob="shrink-0",lb="font-mono text-xs tracking-[0.04em] text-[var(--ink)]",fr="mx-1 h-4 w-px shrink-0 bg-[color-mix(in_oklab,var(--ink)_14%,transparent)]",cb="min-w-3 flex-1",vr=["inline-flex min-h-8 shrink-0 items-center justify-center rounded-sm border-0 bg-transparent px-2","text-[12.5px] text-[var(--ink-3)] transition","hover:text-[var(--ink)] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),db=["inline-flex min-h-8 shrink-0 items-center justify-center rounded-[8px] border border-[var(--ink)]","bg-[var(--ink)] px-3 font-mono text-[11px] font-semibold uppercase leading-none tracking-[0.08em] text-[var(--paper)] transition","hover:bg-[color-mix(in_oklab,var(--ink)_88%,var(--rust))] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--ink)_18%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),ft=["inline-flex min-h-8 shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-[8px]","border border-[var(--line-strong)]","bg-[color-mix(in_oklab,var(--paper)_78%,transparent)] px-2.5","text-[12.5px] text-[var(--ink)] transition","hover:border-[color-mix(in_oklab,var(--honey)_34%,var(--line-strong))] hover:bg-[color-mix(in_oklab,var(--honey)_10%,var(--paper))]","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-45","[&_svg]:h-[13px] [&_svg]:w-[13px]"].join(" "),ub="!text-[var(--rust)] hover:!text-[var(--rust)]",mb=["inline-flex min-h-8 shrink-0 items-center justify-center rounded-sm border-0 bg-transparent px-2","text-[12.5px] text-[var(--archive-inverse-muted)] transition","hover:text-[var(--archive-inverse-text)] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),pb=["inline-flex min-h-9 shrink-0 items-center justify-center rounded-[9px] border border-[color-mix(in_oklab,var(--honey)_52%,transparent)]","bg-[var(--honey)] px-3 font-mono text-[11px] font-semibold uppercase leading-none tracking-[0.08em] text-[var(--ink)]","shadow-[0_8px_18px_-12px_var(--honey)] transition hover:bg-[color-mix(in_oklab,var(--honey)_90%,var(--paper))]","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_28%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),hb=["inline-flex min-h-8 shrink-0 items-center justify-center rounded-[8px] border border-[color-mix(in_oklab,var(--honey)_45%,transparent)]","bg-[color-mix(in_oklab,var(--honey)_18%,transparent)] px-3 font-mono text-[10.5px] font-semibold uppercase leading-none tracking-[0.08em] text-[var(--archive-inverse-text)] transition","hover:bg-[color-mix(in_oklab,var(--honey)_26%,transparent)] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]"].join(" "),xb="!text-[var(--rust)] hover:!text-[var(--rust)]",bb=["fixed inset-x-0 z-[45]","grid gap-2 sm:hidden","rounded-t-[16px] bg-[var(--archive-inverse-surface)] px-4 py-3 text-[var(--archive-inverse-text)] shadow-[0_-18px_32px_-16px_rgba(0,0,0,0.45)]"].join(" "),gb="bottom-0 pb-[calc(0.75rem+env(safe-area-inset-bottom))]",fb="flex min-w-0 items-center justify-between gap-2",vb="flex min-w-0 items-center gap-1.5",yb="font-mono text-xs tracking-[0.04em] text-[var(--archive-inverse-text)]",wb="flex shrink-0 items-center gap-1",jb="grid grid-cols-3 gap-1.5",Lt=["inline-flex min-h-10 min-w-0 items-center justify-center gap-1.5 rounded-[8px]","border border-[var(--archive-inverse-line)]","bg-[var(--archive-inverse-control)] px-2","text-[12px] text-[var(--archive-inverse-text)] transition","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-45","[&_svg]:h-[13px] [&_svg]:w-[13px]"].join(" "),Nb=["fixed inset-x-0 top-0 z-[44]","sm:hidden","cursor-default border-0 bg-[color-mix(in_oklab,var(--content-primary)_10%,transparent)] p-0"].join(" "),Sb="bottom-[calc(8.75rem+env(safe-area-inset-bottom))]",kb=["fixed inset-x-0 z-[46]","sm:hidden","mx-2","overflow-y-auto overscroll-contain","rounded-t-xl rounded-b-lg border border-[var(--archive-inverse-line)] bg-[var(--archive-inverse-surface)] p-3 text-[var(--archive-inverse-text)] shadow-overlay [-webkit-overflow-scrolling:touch]"].join(" "),Cb=["bottom-[calc(8.75rem+env(safe-area-inset-bottom))]","max-h-[min(68dvh,calc(100dvh-9.5rem-env(safe-area-inset-top)-env(safe-area-inset-bottom)))]"].join(" "),_b="mb-3",Rb="h-1 w-10 rounded-full bg-[var(--archive-inverse-line)]",Lb="flex items-start justify-between gap-3 pb-2",Ab="text-sm font-semibold leading-tight text-[var(--archive-inverse-text)]",Tb="mt-0.5 text-xs text-[var(--archive-inverse-subtle)]",Eb="mt-2 overflow-hidden rounded-sm border border-[var(--archive-inverse-line)] bg-[var(--archive-inverse-control)]",Pb=["flex w-full items-center justify-between gap-3 px-3 py-3 text-left","border-b border-[var(--archive-inverse-line)] last:border-b-0","transition-colors hover:bg-[var(--archive-inverse-control-hover)] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-45"].join(" "),Mb="min-w-0",Ib="block text-sm font-medium leading-tight text-[var(--archive-inverse-text)]",Ob="mt-2 grid gap-2",Db="grid grid-cols-2 gap-2",Fb="flex flex-wrap gap-1.5",$b=["inline-flex min-h-7 max-w-full items-center rounded-pill border border-[var(--archive-inverse-line)]","bg-[var(--archive-inverse-control)] px-2.5 text-xs text-[var(--archive-inverse-muted)]","transition-colors hover:border-[var(--archive-inverse-line)] hover:text-[var(--archive-inverse-text)]","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]"].join(" "),Wb=["hidden sm:block fixed inset-x-8 bottom-[calc(4.75rem+env(safe-area-inset-bottom))] z-[1300]","mx-auto max-w-7xl rounded-[12px] border border-[var(--line-strong)] bg-[var(--paper)] p-3 text-[var(--ink)] shadow-[var(--shadow-md)]"].join(" "),Bb="flex flex-wrap gap-2",Vb=ft,Hb="grid grid-cols-[minmax(14rem,22rem)_auto_auto_minmax(0,1fr)] items-center gap-2",yr="text-xs text-[var(--ink-3)]",wr=t=>t.trim().toLowerCase();
6function Ub(t,a){const n=wr(a);return n?(t.tags??[]).map(wr).includes(n):!1}const jr=[{value:"SAVED",label:"Saved"},{value:"READING",label:"Reading"},{value:"CAUGHT_UP",label:"Caught up"},{value:"PAUSED",label:"Paused"},{value:"FINISHED",label:"Finished"},{value:"DROPPED",label:"Dropped"}];function Yb({selectedCount:t,visibleCount:a,totalCount:n,loadedCount:s,onSelectAllVisible:i,onSelectAllLibrary:o,onBulkSetStatus:c,onBulkCatchUp:u,bulkTag:l,onBulkTagChange:m,allTags:d,onBulkAddTag:x,onBulkRemoveTag:y,selectedEntries:g,onExitBulkMode:N,onAddToCollection:S,onShare:C,onBulkRemove:_,bulkRemoving:p=!1}){const b=t===0,[k,j]=r.useState(!1),[O,R]=r.useState(!1),[F,A]=r.useState(null),[z,Q]=r.useState(!1),te=r.useRef(null),[v,$]=r.useState("status");r.useEffect(()=>{t===0&&(A(null),Q(!1))},[t]),r.useEffect(()=>{z||$("status")},[z]);const f=l.trim(),U=a.toLocaleString(),oe=typeof n=="number"?n.toLocaleString():null,se=typeof s=="number"?s.toLocaleString():null,G=!!o&&typeof n=="number"&&typeof s=="number"&&s>=n&&n>a&&n>0,I=oe?`Select all ${oe}`:se?`Select all ${se}`:"Select all",{haveCount:E,missingCount:Y}=r.useMemo(()=>{const P=f.trim();if(!P)return{haveCount:0,missingCount:0};let re=0;for(const me of g)Ub(me,P)&&re++;return{haveCount:re,missingCount:g.length-re}},[g,f]),W=g.length>0&&f&&Y>0,J=g.length>0&&f&&E>0,X=r.useMemo(()=>{const P=f.toLowerCase();return d.filter(re=>{const me=re.trim();return!me||me===f?!1:P?me.toLowerCase().includes(P):!0}).slice(0,6)},[d,f]),ee=()=>{Q(!1),$("status")},le=P=>{c(P),ee()},ae=()=>{u(),ee(),R(!1)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:L(bb,gb),role:"region","aria-label":"Bulk selection",children:[e.jsxs("div",{className:fb,children:[e.jsx("div",{className:vb,children:e.jsxs("span",{className:yb,"aria-live":"polite",children:[e.jsx("strong",{children:t})," selected"]})}),e.jsxs("div",{className:wb,children:[e.jsxs("button",{type:"button",className:mb,onClick:i,children:["Select ",U]}),e.jsx("button",{type:"button",className:pb,onClick:N,children:"Done selecting"})]})]}),e.jsxs("div",{className:jb,children:[S?e.jsxs("button",{type:"button",className:Lt,onClick:S,disabled:b,children:[e.jsx(js,{"aria-hidden":!0}),"Collect"]}):null,e.jsxs("button",{type:"button",className:Lt,onClick:()=>{$("status"),Q(!0)},disabled:b,children:[e.jsx(Ma,{"aria-hidden":!0}),"State"]}),e.jsxs("button",{type:"button",className:Lt,onClick:()=>R(!0),disabled:b,children:[e.jsx(ut,{"aria-hidden":!0}),"Caught up"]}),C?e.jsxs("button",{type:"button",className:Lt,onClick:C,disabled:b,children:[e.jsx(Sn,{"aria-hidden":!0}),"Share"]}):null,e.jsxs("button",{type:"button",className:Lt,onClick:()=>{$("tags"),Q(!0)},disabled:b,children:[e.jsx(Xr,{"aria-hidden":!0}),"Tag"]}),_?e.jsxs("button",{type:"button",className:L(Lt,xb),onClick:()=>j(!0),disabled:b||p,children:[e.jsx(Oa,{"aria-hidden":!0}),"Remove"]}):null]})]}),z?e.jsx("button",{type:"button",className:L(Nb,Sb),"aria-label":"Close bulk actions",onClick:ee}):null,z?e.jsxs("div",{ref:te,"data-mobile-sheet-drag-target":"",className:L(kb,Cb),role:"dialog","aria-label":v==="status"?"Set bulk status":"Edit bulk tags",children:[e.jsx(Wr,{className:_b,indicatorClassName:Rb,targetRef:te,onDismiss:ee}),e.jsxs("div",{className:Lb,children:[e.jsxs("div",{children:[e.jsx("div",{className:Ab,children:v==="status"?"Set reader status":"Edit tags"}),e.jsxs("div",{className:Tb,children:[t," selected"]})]}),e.jsx("button",{type:"button",className:hb,onClick:ee,children:"Done"})]}),v==="status"?e.jsx("div",{className:Eb,children:jr.map(P=>e.jsx("button",{type:"button",className:Pb,disabled:b,onClick:()=>le(P.value),children:e.jsx("span",{className:Mb,children:e.jsx("span",{className:Ib,children:P.label})})},P.value))}):e.jsxs("div",{className:Ob,children:[e.jsx(jn,{size:"sm",fullWidth:!0,placeholder:"Tag...",disabled:b,value:l,onChange:P=>m(P.target.value),"aria-label":"Bulk tag"}),X.length?e.jsx("div",{className:Fb,"aria-label":"Tag suggestions",children:X.map(P=>e.jsx("button",{type:"button",className:$b,onClick:()=>m(P),children:P},P))}):null,e.jsxs("div",{className:Db,children:[e.jsxs(de,{variant:"outline",size:"sm",onClick:()=>x(f),disabled:!W,children:["Add",f?` to ${Y}`:""]}),e.jsxs(de,{variant:"outline",size:"sm",onClick:()=>y(f),disabled:!J,children:["Remove",f?` from ${E}`:""]})]}),f&&g.length>0?e.jsxs("span",{className:yr,children:["On selected: ",E," have it, ",Y," don't"]}):null]})]}):null,e.jsxs("div",{className:ib,role:"region","aria-label":"Bulk actions",children:[e.jsx("div",{className:ob,children:e.jsxs("span",{className:lb,"aria-live":"polite",children:[e.jsx("strong",{children:t})," selected",e.jsxs("span",{children:[" · of ",U," visible"]})]})}),e.jsx("span",{className:fr,"aria-hidden":!0}),e.jsxs("button",{type:"button",className:vr,onClick:i,children:["Select all ",U]}),oe&&G?e.jsx("button",{type:"button",className:vr,onClick:o,children:I}):null,e.jsx("span",{className:cb}),S?e.jsxs("button",{type:"button",className:ft,onClick:S,disabled:b,children:[e.jsx(js,{"aria-hidden":!0}),"Add to collection"]}):null,e.jsxs("button",{type:"button",className:ft,onClick:()=>A(P=>P==="status"?null:"status"),disabled:b,children:[e.jsx(Ma,{"aria-hidden":!0}),"Change status"]}),e.jsxs("button",{type:"button",className:ft,onClick:()=>R(!0),disabled:b,children:[e.jsx(ut,{"aria-hidden":!0}),"Mark caught up"]}),C?e.jsxs("button",{type:"button",className:ft,onClick:C,disabled:b,children:[e.jsx(Sn,{"aria-hidden":!0}),"Share"]}):null,e.jsxs("button",{type:"button",className:ft,onClick:()=>A(P=>P==="tags"?null:"tags"),disabled:b,children:[e.jsx(mt,{"aria-hidden":!0}),"Tag"]}),_?e.jsxs("button",{type:"button",className:L(ft,ub),onClick:()=>j(!0),disabled:b||p,children:[e.jsx(Oa,{"aria-hidden":!0}),"Remove"]}):null,e.jsx("span",{className:fr,"aria-hidden":!0}),e.jsx("button",{type:"button",className:db,onClick:N,children:"Done selecting"})]}),F?e.jsx("div",{className:Wb,role:"region","aria-label":"Bulk subactions",children:F==="status"?e.jsx("div",{className:Bb,children:jr.map(P=>e.jsx("button",{type:"button",className:Vb,disabled:b,onClick:()=>{c(P.value),A(null)},children:P.label},P.value))}):e.jsxs("div",{className:Hb,children:[e.jsx(jn,{size:"sm",fullWidth:!0,placeholder:"Tag...",disabled:b,value:l,onCh
6ange:P=>m(P.target.value),"aria-label":"Bulk tag"}),e.jsxs(de,{variant:"outline",size:"sm",onClick:()=>x(f),disabled:!W,children:["Add",f?` to ${Y}`:""]}),e.jsxs(de,{variant:"outline",size:"sm",onClick:()=>y(f),disabled:!J,children:["Remove",f?` from ${E}`:""]}),f&&g.length>0?e.jsxs("span",{className:yr,children:["On selected: ",E," have it, ",Y," don't"]}):null]})}):null,_&&e.jsx($t,{open:k,title:"Remove from library",description:`Remove ${t} stor${t===1?"y":"ies"} from your library? This can't be undone.`,confirmLabel:"Remove",variant:"danger",loading:p,onConfirm:()=>{j(!1),_()},onCancel:()=>j(!1)}),e.jsx($t,{open:O,title:"Catch up selected stories?",description:`Update progress to the latest known chapter for ${t} selected stor${t===1?"y":"ies"}?`,confirmLabel:"Catch up",onConfirm:ae,onCancel:()=>R(!1)})]})}function Kb({onCancel:t,onConfirm:a,open:n}){const[s,i]=r.useState(null),[o,c]=r.useState("");r.useEffect(()=>{n||(i(null),c(""))},[n]);const u=s==="today"?_s():s==="date"?o:null,l=s==="unknown"||s==="today"||!!u;return e.jsx($t,{confirmDisabled:!l,confirmLabel:"Mark finished",description:"Choose the finish date to apply to every selected story.",onCancel:t,onConfirm:()=>a(uc(u)),open:n,surface:"archive",title:"Finish selected stories",children:e.jsxs("div",{className:"mt-4 grid gap-3",role:"radiogroup","aria-label":"Bulk finish date",children:[[["today","Today"],["date","Choose a date"],["unknown","Date unknown"]].map(([m,d])=>e.jsxs("label",{className:"flex items-center gap-3 text-sm",children:[e.jsx("input",{checked:s===m,name:"bulk-finish-date",onCh
6ange:()=>i(m),type:"radio",value:m}),e.jsx("span",{children:d})]},m)),s==="date"?e.jsx("input",{"aria-label":"Shared finish date",className:"tf-field",max:_s(),onChange:m=>c(m.target.value),type:"date",value:o}):null]})})}const zb="https://archiveofourown.org/works",qb="https://www.fanfiction.net/",Gb={1:{eyebrow:"Your first story is saved",title:"Keep reading as usual.",body:"On AO3 or FanFiction.net, use Add to Trace or simply open a story and let auto-track save it. Reading on another site? Use Add manually and keep reading as usual.",icon:Va},2:{eyebrow:"Build your library",title:"Add a whole page at once.",body:"You can also add a whole supported listing or bookmarks page: open the Trace extension and choose Import this page.",icon:Fn},3:{eyebrow:"As your library grows",title:"Make it yours.",body:"Use filters and collections to organize your library. Add private notes, ratings, and tags to remember what mattered.",icon:Dl}};function Qb({step:t,pending:a=!1,error:n=null,onAdvance:s,onDismiss:i,onComplete:o,onOpenArchive:c}){const u=Gb[t],l=u.icon,m=r.useRef(null),d=r.useRef(t),[x,y]=r.useState(null),g=a||x!==null;r.useEffect(()=>{d.current!==t&&(d.current=t,m.current?.focus())},[t]);const N=r.useCallback(async(S,C)=>{if(!g){y(S);try{if(!await o()||!C)return;c?c(C):window.location.assign(C)}finally{y(null)}}},[g,o,c]);return e.jsxs("section",{"aria-label":"Getting started with your library",className:"relative mb-5 overflow-hidden rounded-lg border border-[color-mix(in_oklab,var(--forest)_24%,var(--border))] bg-surface-1 p-5 pl-6 shadow-sm before:absolute before:bottom-0 before:left-0 before:top-0 before:w-1 before:bg-[var(--forest)] sm:p-6 sm:pl-7",children:[e.jsx("button",{type:"button","aria-label":"Skip getting started guide",onClick:i,disabled:g,className:"absolute right-3 top-3 inline-flex h-11 w-11 items-center justify-center rounded-lg text-content-muted transition hover:bg-surface-2 hover:text-content-primary focus-visible:shadow-ring disabled:cursor-wait disabled:opacity-50",children:e.jsx(wt,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"flex items-start gap-4 pr-10",children:[e.jsx("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-sm border border-[color-mix(in_oklab,var(--forest)_22%,var(--border))] bg-[var(--forest-soft)] text-[var(--forest)]","aria-hidden":!0,children:e.jsx(l,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-[var(--forest)]",children:u.eyebrow}),e.jsx("h2",{ref:m,tabIndex:-1,className:"mt-1 font-landing-serif text-2xl font-semibold leading-tight text-content-primary outline-none",children:u.title})]})]}),e.jsx("p",{className:"mt-4 max-w-[58ch] text-sm leading-6 text-content-muted",children:u.body}),e.jsxs("div",{className:"mt-5 flex items-center gap-2","aria-label":`Step ${t} of 3`,children:[[1,2,3].map(S=>e.jsx("span",{className:L("h-1.5 rounded-pill transition-[width,background-color]",S===t?"w-8 bg-[var(--forest)]":S<t?"w-4 bg-[color-mix(in_oklab,var(--forest)_55%,var(--border))]":"w-4 bg-border"),"aria-hidden":!0},S)),e.jsxs("span",{className:"ml-1 font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:[t," of 3"]})]}),n?e.jsx("p",{className:"mt-4 text-sm text-[var(--rust)]",role:"alert",children:n}):null,t<3?e.jsx(de,{type:"button",variant:"solid",size:"lg",className:"mt-5 min-h-11 justify-center",onClick:s,disabled:g,loading:g,rightIcon:e.jsx(Ha,{className:"h-4 w-4","aria-hidden":!0}),children:"Next"}):e.jsxs("div",{className:"mt-5 flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsx(de,{type:"button",variant:"solid",size:"lg",className:"min-h-11 justify-center",onClick:()=>{N("ao3",zb)},disabled:g,loading:x==="ao3",children:"Open AO3"}),e.jsx(de,{type:"button",variant:"outline",size:"lg",className:"min-h-11 justify-center bg-surface-1",onClick:()=>{N("ffn",qb)},disabled:g,loading:x==="ffn",children:"Open FanFiction.net"}),e.jsx(de,{type:"button",variant:"ghost",size:"lg",className:"min-h-11 justify-center",onClick:()=>{N("library")},disabled:g,loading:x==="library",children:"Stay in My Library"})]})]})}function Xb({chips:t,onClear:a,onClearAll:n}){return t.length?e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-x-auto border-b border-[var(--line)] px-4 pb-3 pt-0 sm:flex-wrap sm:overflow-visible sm:px-8 sm:pt-2","aria-label":"Active library filters",children:[t.map(s=>e.jsx(ql,{label:s.label,value:s.value,removeLabel:`Remove ${s.ariaLabel} filter`,onRemove:()=>
6a(s.id),className:"max-w-64 shrink-0 sm:max-w-72"},s.id)),t.length>1?e.jsx("button",{type:"button",onClick:n,className:"inline-flex min-h-8 shrink-0 items-center rounded-pill px-3 font-mono text-[10.5px] font-medium uppercase leading-none tracking-[0.18em] text-[var(--rust)] transition hover:bg-[var(--paper-2)] focus-visible:outline-none focus-visible:shadow-ring",children:"Clear"}):null]}):null}function Zb(){const[t,a]=vl(),n=r.useCallback(b=>{const k=t.toString(),j=new URLSearchParams(t);b(j),j.toString()!==k&&a(j,{replace:!0})},[a,t]),s=t.get("q")??"",i=t.get("libraryViewId")||null,o=t.get("view");r.useEffect(()=>{o!==null&&n(b=>{b.delete("view")})},[n,o]);const c=t.get("catchup"),u=c==="UP"||c==="BEHIND"||c==="ANY"?c:"ANY",l=t.get("panel"),m=l==="add"||l==="share"||l==="details"?l:null,d=t.get("sort"),x=d&&Br(d)?d:"LAST_READ_DESC",y=m==="details"?t.get("entryId")??void 0:void 0,g=r.useCallback(b=>{n(k=>{const j=b??"";j.trim()?k.set("q",j):k.delete("q")})},[n]),N=r.useCallback(b=>{n(k=>{k.set("sort",b)})},[n]),S=r.useCallback(b=>{n(k=>{b==="ANY"?k.delete("catchup"):k.set("catchup",b)})},[n]),C=r.useCallback(b=>{n(k=>{const j=b?.trim();j?k.set("libraryViewId",j):k.delete("libraryViewId")})},[n]),_=r.useCallback((b,k)=>{n(j=>{j.set("panel",b),b==="details"&&k?.entryId?j.set("entryId",k.entryId):j.delete("entryId")})},[n]),p=r.useCallback(()=>{n(b=>{b.delete("panel"),b.delete("entryId")})},[n]);return{q:s,sort:x,panel:m,entryId:y,catchup:u,libraryViewId:i,setQ:g,setSort:N,setCatchup:S,setLibraryViewId:C,openPanel:_,closePanel:p}}function Jb(t){return(t??[]).map(a=>a.trim()).filter(a=>a.length>0)}function $e(t){const a=Jb(t);return a.length?a.length<=2?a.join(", "):`${a.slice(0,2).join(", ")} +${a.length-2}`:null}const eg={general:"General / K-K+",teen:"Teen / T",mature:"Mature / M",explicit:"Explicit",not_rated:"Not rated"},tg=t=>eg[t]??pl(t);function Aa(t){return t.toLocaleString("en-US")}function Nr(t){return t.trim().slice(0,10)}function ie(t,a,n,s){const i=s?.trim();i&&t.push({id:a,label:n,value:i,ariaLabel:`${n}: ${i}`})}function no(t,a){const n=[];return ie(n,"search","Search",a),ie(n,"ratings","Content rating",$e(t.ratings.map(tg))),ie(n,"platforms","Platforms",$e(t.platforms)),ie(n,"statuses","Reader status",$e(t.statuses.map(s=>yt(s)))),t.catchup==="UP"?ie(n,"catchup","Catch-up",bs("UP")):t.catchup==="BEHIND"&&ie(n,"catchup","Catch-up",bs("BEHIND")),t.storyUpdates==="NEW"&&ie(n,"storyUpdates","Story updates","New updates"),typeof t.minWords=="number"&&ie(n,"minWords","Words",`${Aa(t.minWords)}+`),typeof t.maxWords=="number"&&ie(n,"maxWords","Words",`≤ ${Aa(t.maxWords)}`),typeof t.minKudos=="number"&&ie(n,"minKudos","Favs/kudos",`${Aa(t.minKudos)}+`),typeof t.maxKudos=="number"&&ie(n,"maxKudos","Favs/kudos",`≤ ${Aa(t.maxKudos)}`),typeof t.minRating=="number"?ie(n,"minRating","Rating",`${t.minRating}+ stars`):t.entryRating==="UNRATED"&&ie(n,"entryRating","Rating","Unrated only"),t.lastReadAfter.trim()&&ie(n,"lastReadAfter","Read after",Nr(t.lastReadAfter)),t.lastReadBefore.trim()&&ie(n,"lastReadBefore","Read before",Nr(t.lastReadBefore)),t.notes==="WITH"||t.hasNotes?ie(n,"hasNotes","Notes","With notes"):t.notes==="WITHOUT"&&ie(n,"hasNotes","Notes","Without notes"),ie(n,"completionStatus","Work status",$e(t.completionStatus.map(s=>Ve(s)))),ie(n,"tag","Library tag",t.tag),ie(n,"workTag","AO3 tag",t.workTag),ie(n,"pairMembers","Pairs",$e(t.pairMembers)),t.pairExact&&t.pairMembers.length&&ie(n,"pairExact","Pairs","Exact only"),ie(n,"characters","Characters",$e(t.characters)),ie(n,"fandoms","Fandoms",$e(t.fandoms)),ie(n,"categoryFilter","Categories",$e(t.categoryFilter)),ie(n,"includeWarnings","Warnings",$e(t.includeWarnings)),ie(n,"excludeTag","Hide tag",t.excludeTag),ie(n,"excludeWorkTag","Hide AO3 tag",t.excludeWorkTag),ie(n,"excludePairMembers","Hide pairs",$e(t.excludePairMembers)),t.excludePairExact&&t.excludePairMembers.length&&ie(n,"excludePairExact","Hide pairs","Exact only"),ie(n,"excludeCharacters","Hide characters",$e(t.excludeCharacters)),ie(n,"excludeFandoms","Hide fandoms",$e(t.excludeFandoms)),ie(n,"excludeCategoryFilter","Hide categories",$e(t.excludeCategoryFilter)),ie(n,"excludeWarnings","Hide warnings",$e(t.excludeWarnings)),n}const ag=new Intl.NumberFormat("en-US",{maximumFractionDigits:1,notation:"compact"});
6function Et(t){return t.toLocaleString("en-US")}function ng(t){return t>=1e4?ag.format(t):Et(t)}function sg({entries:t,storiesMap:a,totalCount:n,visibleCount:s,activeFilterCount:i,hasQuery:o=!1}){const c=t.filter(x=>x.status==="READING").length,u=t.filter(x=>x.status==="CAUGHT_UP").length,l=t.filter(x=>x.status==="FINISHED").length,m=t.reduce((x,y)=>{const g=a[y.storyId]?.words;return x+(typeof g=="number"?g:0)},0),d=[{value:Et(n),label:n===1?"story saved":"saved"}];return(i>0||o)&&d.push({value:Et(s),label:"matching now"}),c>0&&d.push({value:Et(c),label:"reading"}),u>0&&d.push({value:Et(u),label:"caught up"}),l>0&&d.push({value:Et(l),label:"finished"}),m>0&&d.push({value:ng(m),label:"words tracked"}),d.slice(0,5)}function rg(t){const a=t.lastReadAt??t.updatedAt,n=a?Date.parse(a):Number.NaN;return Number.isFinite(n)?n:null}function ig(t){if(t.status==="SAVED")return null;const a=t.lastReadAt?Date.parse(t.lastReadAt):Number.NaN;return Number.isFinite(a)?a:t.status!=="READING"&&t.status!=="CAUGHT_UP"?null:rg(t)}function og(t){let a=null,n=Number.NEGATIVE_INFINITY;for(const s of t){const i=ig(s);i==null||i<=n||(a=s.id,n=i)}return a}const yn=Vr,lg=({overCap:t,atCap:a,totalCount:n})=>e.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-3 rounded-xl border border-border bg-surface-2/60 p-3",children:[e.jsx("span",{className:"text-sm text-content-subtle",children:t?`You're over the free limit (${yn}). Trace Unlimited lets you keep adding stories.`:a?`You’ve hit the free limit (${yn}).`:`Almost at the free limit (${n}/${yn}).`}),e.jsx(de,{variant:"cta",onClick:()=>window.dispatchEvent(new CustomEvent("trace:openUpgrade",{detail:{source:"library_cap"}})),children:"See Trace Unlimited"})]});function cg({pending:t=!1,error:a=null,onDismiss:n}){return e.jsxs("aside",{"aria-labelledby":"reader-launch-note-heading",className:"relative my-5 overflow-hidden border-y border-[color-mix(in_oklab,var(--rust)_24%,var(--border))] bg-[color-mix(in_oklab,var(--surface-1)_92%,var(--rust-soft))] py-4 pl-5 pr-12 sm:border sm:py-5 sm:pl-6 sm:pr-14",children:[e.jsx("span",{"aria-hidden":!0,className:"absolute bottom-0 left-0 top-0 w-1 bg-[var(--rust)]"}),e.jsx(ct,{type:"button",variant:"ghost",size:"lg","aria-label":"Hide Trace Reader note",onClick:()=>{n()},disabled:t,loading:t,className:"absolute right-1.5 top-1.5 text-content-muted sm:right-2 sm:top-2",children:e.jsx(wt,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:gap-5",children:[e.jsx("span",{"aria-hidden":!0,className:"hidden h-11 w-11 shrink-0 items-center justify-center border border-[color-mix(in_oklab,var(--rust)_28%,var(--border))] bg-[var(--rust-soft)] text-[var(--rust)] sm:flex",children:e.jsx(Va,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-[var(--rust)]",children:"New app"}),e.jsx("h2",{id:"reader-launch-note-heading",className:"mt-1 font-landing-serif text-xl font-semibold leading-tight text-content-primary sm:text-2xl",children:"Trace now tracks the AO3 stories you read offline."}),e.jsx("p",{className:"mt-2 max-w-[72ch] text-sm leading-6 text-content-muted",children:"The extension automatically tracks stories you read on AO3. Trace Reader now does the same for downloaded EPUBs, with statuses, ratings and notes you can update as you read. It's built for fanfiction and accessibility, and your EPUB files and story text stay on your device."}),a?e.jsx("p",{className:"mt-2 text-sm text-[var(--rust)]",role:"alert",children:a}):null]}),e.jsx(de,{nativeButton:!1,render:e.jsx(yl,{to:"/reader"}),variant:"outline",size:"lg",className:"min-h-11 shrink-0 self-start bg-surface-1 sm:self-center",rightIcon:e.jsx(Ha,{"aria-hidden":!0}),children:"See Trace Reader"})]})]})}function dg({accountLoading:t,isPro:a,nearCap:n,atCap:s}){return!t&&!a&&(n||s)}const so="(max-width: 639px)";function ug(t){if(typeof window>"u"||!window.matchMedia)return()=>{};const a=window.matchMedia(so);return a.addEventListener?(a.addEventListener("change",t),()=>a.removeEventListener("change",t)):(a.addListener(t),()=>a.removeListener(t))}function mg(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia(so).matches}function pg(){return!1}function hg(){return r.useSyncExternalStore(ug,mg,pg)}function xg({showFilters:t,children:a,filtersPanel:n,mobileFiltersHeader:s,mobileFiltersBody:i,mobileFiltersFooter:o,stickyTopClass:c="top-16",
6sticky:u=!0,runtime:l="browser",chromeState:m="full",stickyChromeRef:d,visibleCount:x,onCloseFilters:y}){const g=hg(),N=!!i,C=t&&!!(i??n)&&g,_=Pc(C),p=r.useRef(null),b=o?.applyLabel??(typeof x=="number"?`Show ${x.toLocaleString()} results`:"Apply filters"),k=!!o?.applyDisabled,j=o?.onApply??y,O=e.jsx(Fl,{open:C,modal:!0,onOpenChange:R=>{R||y?.()},children:e.jsxs($l,{children:[e.jsx(Wl,{className:L("library-app archive-editorial-shell library-filter-mobile-backdrop fixed inset-0 z-[1300] sm:hidden",N&&"!bg-[rgba(8,10,7,0.55)]")}),e.jsx(Bl,{className:L("fixed inset-0 z-[1310] flex w-screen max-w-full overflow-hidden overscroll-none sm:hidden",N&&"items-end pointer-events-none"),children:e.jsx(Vl,{ref:p,"data-mobile-sheet-drag-target":"",finalFocus:_,className:L("library-app archive-editorial-shell library-filter-mobile-shell flex w-full max-w-full flex-col overflow-x-hidden outline-none",N?"pointer-events-auto max-h-[min(88dvh,calc(100dvh_-_env(safe-area-inset-top)_-_0.75rem))] overflow-hidden rounded-t-lg border border-[var(--line-strong)] shadow-[0_-20px_50px_-24px_rgba(0,0,0,0.6)]":"h-full","motion-reduce:transition-none"),children:N?e.jsxs(e.Fragment,{children:[e.jsx(Ns,{className:"sr-only",children:"Filter and sort"}),y?e.jsx(Wr,{className:"library-filter-mobile-handle",targetRef:p,onDismiss:y}):null,e.jsxs("div",{className:"library-filter-mobile-header flex w-full max-w-full shrink-0 items-start justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 flex-1",children:s}),e.jsx("button",{type:"button",className:"library-filter-mobile-close flex shrink-0 items-center justify-center focus-visible:outline-none","aria-label":"Close filters",onClick:y,children:e.jsx(wt,{className:"h-5 w-5","aria-hidden":!0})})]}),e.jsx("div",{className:"library-filter-mobile-body min-h-0 w-full max-w-full flex-1 overflow-x-hidden overflow-y-auto overscroll-contain [-webkit-overflow-scrolling:touch]",children:i}),o?e.jsx("div",{className:"library-filter-mobile-footer w-full max-w-full shrink-0",children:e.jsxs("div",{className:L("grid gap-2","grid-cols-[7rem_minmax(0,1fr)]"),children:[e.jsx(de,{type:"button",variant:"outline",onClick:o.onReset,leftIcon:e.jsx(Ia,{}),children:"Reset"}),e.jsx(de,{type:"button",variant:k?"outline":"solid",disabled:k,onClick:j,leftIcon:k?void 0:e.jsx(ut,{}),className:L(k&&"cursor-not-allowed"),children:b})]})}):null]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex w-full max-w-full shrink-0 items-center justify-between border-b border-border px-4 pb-3 pt-[calc(env(safe-area-inset-top)+0.75rem)]",children:[e.jsx(Ns,{className:"text-lg font-semibold text-content-primary",children:"Filters"}),e.jsx(Hl,{type:"button",className:"flex h-10 w-10 items-center justify-center rounded-lg text-content-muted transition-colors hover:bg-surface-2 hover:text-content-primary","aria-label":"Close filters",children:e.jsx("svg",{viewBox:"0 0 24 24",className:"h-5 w-5","aria-hidden":!0,children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})})})]}),e.jsx("div",{className:"min-h-0 w-full max-w-full flex-1 overflow-x-hidden overflow-y-auto overscroll-contain [-webkit-overflow-scrolling:touch]",children:n}),e.jsx("div",{className:"w-full max-w-full shrink-0 border-t border-border bg-surface-1 px-4 pt-3 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",children:e.jsx(de,{variant:"solid",size:"lg",className:"w-full",onClick:y,children:typeof x=="number"?`Show ${x.toLocaleString()} results`:"Apply filters"})})]})})})]})});return e.jsxs("div",{ref:d,"data-library-sticky-chrome":!0,"data-runtime":l,"data-chrome":m,className:L(mc,"z-[40]",u===!0?["sticky","bg-[color-mix(in_oklab,var(--library-bg)_88%,transparent)] backdrop-blur-sm",c]:u==="mobile"?["relative bg-transparent","max-sm:sticky max-sm:bg-[color-mix(in_oklab,var(--library-bg)_88%,transparent)] max-sm:backdrop-blur-sm",c]:"relative bg-transparent"),children:[a,t&&n&&!g?e.jsx("div",{className:L("absolute left-0 right-0 top-full z-[50] mt-1","overflow-x-hidden overflow-y-auto rounded-2xl border border-border-subtle bg-surface-1 shadow-lg","max-h-[min(70vh,calc(100dvh-8rem))]","hidden sm:block xl:hidden"),role:"region","aria-label":"Library filters",children:n}):null,O]})}function ro(t){return t==="LAST_READ_DESC"||t==="UPDATED_DESC"||t==="WORK_UPDATED_DESC"}function Ea(t,a){const n=new Map(a.map(o=>[o.id,o])),s=new Set,i=[];for(const o of t){const c=n.get(o);c&&(i.push(c),s.add(o))}for(const o of a)s.has(o.id)||i.push(o);return i}const bg=(t,a,n,s)=>{const i=m=>(a[m]?.title??"").toLowerCase(),o=m=>{const d=m?Date.parse(m):Number.NaN;return Number.isFinite(d)?d:0},c=s?.priorOrder,u=ro(n)&&s?.freezeUpdatedOrder&&c&&c.length>0;let l;return n==="BEST_MATCH"||n==="STORY_UPDATE_DESC"?l=[...t]:n==="LAST_READ_DESC"?u?l=Ea(c,t):l=[...t].sort((m,d)=>o(d.lastReadAt??d.updatedAt)-o(m.lastReadAt??m.updatedAt)):n==="WORK_UPDATED_DESC"?u?l=Ea(c,t):l=[...t].sort((m,d)=>{const x=o(a[d.storyId]?.updatedDate)-o(a[m.storyId]?.updatedDate);return x!==0?x:o(d.lastReadAt??d.updatedAt)-o(m.lastReadAt??m.updatedAt)}):n==="TITLE_ASC"?l=[...t].sort((m,d)=>i(m.storyId).localeCompare(i(d.storyId),void 0,{sensitivity:"base"})):n==="TITLE_DESC"?l=[...t].sort((m,d)=>i(d.storyId).localeCompare(i(m.storyId),void 0,{sensitivity:"base"})):n==="RATING_DESC"?l=[...t].sort((m,d)=>{const x=Number.isFinite(m.rating)?m.rating:0,g=(Number.isFinite(d.rating)?d.rating:0)-x;return g!==0?g:i(m.storyId).localeCompare(i(d.storyId),void 0,{sensitivity:"base"})}):n==="RATING_ASC"?l=[...t].sort((m,d)=>{const x=Number.isFinite(m.rating)?m.rating:0,y=Number.isFinite(d.rating)?d.rating:0,g=x-y;return g!==0?g:i(m.storyId).localeCompare(i(d.storyId),void 0,{sensitivity:"base"})}):u?l=Ea(c,t):l=[...t].sort((m,d)=>o(d.updatedAt)-o(m.updatedAt)),l};function gg({entries:t,storiesMap:a,sort:n,listIdentityKey:s}){const i=r.useRef(0),o=r.useRef([]),c=r.useRef([]),u=r.useRef(new Set),l=r.useRef(s),[m,d]=r.useState(0),[x,y]=r.useState(0),g=r.useCallback(b=>{const k=i.current;b===1?(k===0&&(o.current=[...c.current]),i.current=k+1):(i.current=Math.max(0,k-1),i.current===0&&(o.current=[])),d(j=>j+1)},[]),N=r.useCallback(()=>{i.current!==0&&(i.current=0,o.current=[],d(b=>b+1))},[]),S=r.useCallback(b=>{ro(n)&&(u.current.has(b)||(u.current.add(b),y(k=>k+1)))},[n]),C=r.useCallback(b=>{u.current.delete(b)&&(N(),y(k=>k+1))},[N]);r.useEffect(()=>{l.current!==s&&(l.current=s,i.current=0,o.current=[],u.current.clear(),d(b=>b+1),y(b=>b+1))},[s]),r.useEffect(()=>{if(!u.current.size)return;const b=new Set(t.map(j=>j.id));let k=!1;for(const j of u.current)b.has(j)||(u.current.delete(j),k=!0);k&&y(j=>j+1)},[t]);const _=r.useMemo(()=>{const b=i.current>0,k=b&&o.current.length>0?{freezeUpdatedOrder:!0,priorOrder:o.current}:void 0,j=bg(t,a,n,k),R=!b&&u.current.size>
60&&c.current.length>0?Ea(c.current,j):j;return b||(c.current=R.map(F=>F.id)),R},[t,a,n,m,x]),p=r.useMemo(()=>Array.from(u.current),[x]);return{visible:_,onLayoutPointerLockChange:g,markEntryForDeferredRecencyReorder:S,deferredRecencyReorderIds:p,onDeferredRecencyEntryExit:C}}function fg({visible:t,entries:a,storiesMap:n,queuePatch:s,deleteEntry:i,pushToast:o,invalidateLibrary:c,resetKey:u}){const[l,m]=r.useState(!1),[d,x]=r.useState(new Set),[y,g]=r.useState(!1),[N,S]=r.useState(""),[C,_]=r.useState(!1),p=r.useCallback(()=>{g(!1),x(new Set)},[]);r.useEffect(()=>{!l||!y||x(I=>{const E=new Set(I);return t.forEach(Y=>E.add(Y.id)),E})},[t,l,y]),r.useEffect(()=>{g(!1),p()},[u,p]),r.useEffect(()=>{l||p()},[l,p]);const b=r.useCallback(I=>d.has(I),[d]),k=r.useCallback(I=>{g(!1),x(E=>{const Y=new Set(E);return Y.has(I)?Y.delete(I):Y.add(I),Y})},[]),j=r.useCallback(()=>{x(new Set(t.map(I=>I.id))),g(!0)},[t]),O=r.useCallback(()=>{x(new Set(a.map(I=>I.id))),g(!1)},[a]),R=r.useMemo(()=>{const I={};return a.forEach(E=>I[E.id]=E),I},[a]),F=r.useCallback(I=>{const E=R[I];return E?n[E.storyId]:void 0},[R,n]),A=r.useCallback(I=>typeof I?.chapters_published=="number"?I.chapters_published:void 0,[]),z=r.useCallback((I,E)=>{d.forEach(Y=>{const W=R[Y];if(!W){s(Y,{status:I,completion:E});return}const J=n[W.storyId],X=hi(W,J,I);s(Y,E?{...X,completion:E}:X)}),o(`Set reader status on ${d.size} stor${d.size===1?"y":"ies"}`)},[d,R,n,s,o]),Q=r.useCallback(I=>{if(I==="FINISHED"){_(!0);return}z(I)},[z]),te=r.useCallback(I=>{z("FINISHED",I),_(!1)},[z]),v=r.useCallback(I=>{const E=(I||"").trim();if(!E)return;let Y=0;d.forEach(W=>{const J=R[W];if(!J)return;const X=J.tags||[];X.includes(E)||(s(W,{tags:[...X,E]}),Y++)}),Y&&o(`Added “${E}” to ${Y} stor${Y===1?"y":"ies"}`)},[d,R,s,o]),$=r.useCallback(I=>{const E=(I||"").trim();if(!E)return;let Y=0;d.forEach(W=>{const J=R[W];if(!J)return;const X=J.tags||[];X.includes(E)&&(s(W,{tags:X.filter(ee=>ee!==E)}),Y++)}),Y&&o(`Removed “${E}” from ${Y} stor${Y===1?"y":"ies"}`)},[d,R,s,o]),f=r.useCallback(()=>{let I=0;d.forEach(E=>{const Y=R[E],W=F(E);if(!Y||Y.progress.unit!=="CHAPTER")return;const J=A(W);if(typeof J!="number")return;const X=typeof Y.progress.total=="number"?Math.min(Y.progress.total,J):J;Y.progress.value!==X&&(s(E,{progress:{...Y.progress,value:X}}),I++)}),I&&o(`Caught up ${I} stor${I===1?"y":"ies"}`)},[d,R,F,A,s,o]),U=r.useMemo(()=>Array.from(d).map(I=>R[I]).filter(Boolean),[d,R]),[oe,se]=r.useState(!1),G=r.useCallback(async()=>{const I=Array.from(d);if(!I.length)return;se(!0);let E=0;const W=(await Promise.allSettled(I.map(async J=>{await i(J),E++}))).filter(J=>J.status==="rejected").length;se(!1),E>0?o(W?`Removed ${E} stor${E===1?"y":"ies"} (${W} failed)`:`Removed ${E} stor${E===1?"y":"ies"} from library`):W&&o("Failed to remove stories"),p(),c()},[d,i,o,p,c]);return{bulkMode:l,setBulkMode:m,selected:d,selectedCount:d.size,bulkTag:N,setBulkTag:S,selectAllActive:y,isSelected:b,toggleOne:k,selectAllVisible:j,selectAllLoaded:O,clearSelection:p,bulkSetStatus:Q,bulkAddTag:v,bulkRemoveTag:$,bulkCatchUp:f,bulkRemove:G,bulkRemoving:oe,bulkFinishPending:C,cancelBulkFinished:()=>_(!1),confirmBulkFinished:te,selectedEntries:U}}const vg="trace:library-scroll-position:",Pn="[data-app-shell-scroll]",yg="window";function io(){return document.querySelector(Pn)}function wg(t){const a=window.getComputedStyle(t).overflowY;return a!=="visible"&&a!=="hidden"&&t.scrollHeight>t.clientHeight+2}function Hn(){const t=io();return t&&wg(t)?t:null}function Ka(){const t=Hn();return t?Math.max(0,t.scrollTop):Math.max(0,window.scrollY||document.documentElement.scrollTop||document.body.scrollTop||0)}function jg(t){const a=Hn();return a?(typeof a.scrollTo=="function"?a.scrollTo({top:t,behavior:"auto"}):a.scrollTop=t,Math.max(0,a.scrollTop)):(typeof window.scrollTo=="function"&&window.scrollTo({top:t,behavior:"auto"}),document.documentElement.scrollTop=t,document.body.scrollTop=t,Ka())}function Ng(){const t=Hn();return t?Math.max(0,t.scrollHeight-t.clientHeight):Math.max(0,document.documentElement.scrollHeight-window.innerHeight,document.body.scrollHeight-window.innerHeight)}function oo(t){try{const a=window.sessionStorage.getItem(t),n=a?Number.parseInt(a,10):Number.NaN;return Number.isFinite(n)&&n>0?n:0}catch{return 0}}function Sr(t,a=Ka()){try{window.sessionStorage.setItem(t,String(Math.round(Math.max(0,a))))}catch{}}function lo(t){return typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(t):window.setTimeout(()=>t(Date.now()),0)}function co(t){if(typeof window.cancelAnimationFrame=="function"){window.cancelAnimationFrame(t);return}window.clearTimeout(t)}function Sg(t){return t.currentTarget instanceof HTMLElement?Math.max(0,t.currentTarget.scrollTop):Ka()}function kg(t){const a=r.useRef(0);r.useEffect(()=>{a.current=oo(t)},[t]);const n=r.useCallback(()=>{const i=Ka();a.current=i,Sr(t,i)},[t]),s=r.useCallback(()=>{Sr(t,a.current)},[t]);return r.useEffect(()=>{let i=0;const o=()=>n(),c=m=>{a.current=Sg(m),!i&&(i=lo(()=>{i=0,s()}))},u=()=>{document.visibilityState==="hidden"&&o()},l=io();return window.addEventListener("scroll",c,{passive:!0}),l?.addEventListener("scroll",c,{passive:!0}),window.addEventListener("pagehide",o),document.addEventListener("visibilitychange",u),()=>{i&&co(i),s(),window.removeEventListener("scroll",c),l?.removeEventListener("scroll",c),window.removeEventListener("pagehide",o),document.removeEventListener("visibilitychange",u)}},[s,n,t]),n}function Cg(t){const a=t?.post_first_story_onboarding;return!!(t?.first_story_completed_at&&!t.library_discovery_dismissed&&a&&a.status!=="completed"&&a.status!=="dism
6issed")}function _g({account:t,patchUiSettings:a}){const n=da(),[s,i]=r.useState(null),c=t?.post_first_story_onboarding?.step??1,u=Pt({mutationFn:y=>a({post_first_story_onboarding:y}),onSuccess:y=>{n.setQueryData(je.me,g=>g&&{...g,library_discovery_dismissed:y.library_discovery_dismissed,post_first_story_onboarding:y.post_first_story_onboarding})}}),l=r.useCallback(async y=>{i(null);try{return await u.mutateAsync(y),!0}catch{return i("We couldn't save your progress. Try again."),!1}},[u]),m=r.useCallback(()=>{const y=Math.min(3,c+1);return l({version:1,status:"in_progress",step:y})},[l,c]),d=r.useCallback(()=>l({version:1,status:"dismissed",step:c}),[l,c]),x=r.useCallback(()=>l({version:1,status:"completed",step:3}),[l]);return{show:Cg(t),step:c,pending:u.isPending,error:s,advance:m,dismiss:d,complete:x}}const wn="reader-1.0.0";function Rg({enabled:t,getNotice:a,dismissNotice:n}){const s=da(),[i,o]=r.useState(null),c=je.accountReleaseNotice(wn),u=na({queryKey:c,queryFn:()=>a(wn),enabled:t,staleTime:1/0}),l=Pt({mutationFn:()=>n(wn),onSuccess:d=>{s.setQueryData(c,{notice_id:d.notice_id,dismissed:d.dismissed})}}),m=r.useCallback(async()=>{o(null);try{return await l.mutateAsync(),!0}catch{return o("We couldn't hide this note. Try again."),!1}},[l]);return{show:u.data?.dismissed===!1,pending:l.isPending,error:i,dismiss:m}}const kr="trace:story-updates-education-v1:dismissed";function Lg(){const[t,a]=r.useState(()=>{try{return window.localStorage.getItem(kr)==="true"}catch{return!1}}),n=r.useCallback(()=>{a(!0);try{window.localStorage.setItem(kr,"true")}catch{}},[]);return{dismissed:t,dismiss:n}}function Ag(t,a){if(!Hr())return;const n=window.webkit?.messageHandlers?.traceWidget;if(!n)return;const s=t.find(o=>o.status==="READING");if(!s){n.postMessage({title:"",author:"",fandom:"",progressCurrent:0,progressTotal:null,status:""});return}const i=a[s.storyId];n.postMessage({title:i?.title??"",author:(i?.authors??[])[0]??"",fandom:(i?.fandoms??[])[0]??"",progressCurrent:s.progress?.value??0,progressTotal:s.progress?.total??null,status:s.status})}const uo="(max-width: 639px)",Tg="window",Eg=8,Cr=64;function Pg(t){if(typeof window>"u"||!window.matchMedia)return()=>{};const a=window.matchMedia(uo);return a.addEventListener?(a.addEventListener("change",t),()=>a.removeEventListener("change",t)):(a.addListener(t),()=>a.removeListener(t))}function Mg(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia(uo).matches}function Ig(){return!1}function Og(){return r.useSyncExternalStore(Pg,Mg,Ig)}function Dg(t){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(t):window.setTimeout(()=>t(Date.now()),0)}function Fg(t){if(typeof window<"u"&&window.cancelAnimationFrame){window.cancelAnimationFrame(t);return}window.clearTimeout(t)}function $g(t){return typeof window>"u"||typeof document>"u"?null:t===Tg?window:document.querySelector(t)}function _r(t){return t===window?Math.max(0,window.scrollY||document.documentElement.scrollTop||document.body.scrollTop||0):Math.max(0,t.scrollTop)}function Wg({enabled:t,freezeFull:a=!1,resetKey:n,scrollContainerSelector:s}){const i=Og(),[o,c]=r.useState("full");return r.useEffect(()=>{c("full")},[n]),r.useEffect(()=>{if(!t||!i||a){c("full");return}const u=$g(s);if(!u){c("full");return}let l=_r(u),m=0;l>Cr&&c("collapsed");const d=()=>{m=0;const y=_r(u),g=y-l;if(l=y,y<=Eg){c("full");return}if(g>0&&y>Cr){c("collapsed");return}g<-6&&c("full")},x=()=>{m||(m=Dg(d))};return u.addEventListener("scroll",x,{passive:!0}),()=>{m&&Fg(m),u.removeEventListener("scroll",x)}},[t,a,i,s]),!t||!i||a?"full":o}function Rr(t){const a=t?document.querySelector(t):null;return a?Math.max(0,a.scrollTop):window.scrollY||document.documentElement.scrollTop||document.body.scrollTop||0}function Bg(t){return t instanceof Element?!!t.closest('a,button,input,textarea,select,[role="slider"],[role="combobox"],[role="listbox"],[role="radiogroup"],[role="progressbar"]'):!1}function Vg({enabled:t,blocked:a=!1,scrollContainerSelector:n,onRefresh:s}){const[i,o]=r.useState(0),[c,u]=r.useState(!1),l=r.useRef(0),m=r.useRef(!1),d=r.useRef(0),x=r.useRef(!1),y=r.useRef(s);return r.useEffect(()=>{y.current=s},[s]),r.useEffect(()=>{if(!t||a){o(0),m.current=!1,d.current=0;return}const g=52,N=88,S=k=>{x.current||Bg(k.target)||Rr(n)>2||(m.current=!0,l.current=k.touches[0].clientY,d.current=0)},C=k=>{if(!m.current||x.current)return;if(Rr(n)>2){m.current=!1,d.current=0,o(0);return}const j=k.touches[0].clientY-l.current;if(j<=0){d.current=0,o(0);return}const O=Math.min(j*.42,N);d.current=O,o(O)},_=()=>{if(!m.current)return;m.current=!1;const k=d.current;d.current=0,o(0),!(k<g||x.current)&&(x.current=!0,u(!0),Promise.resolve(y.current()).c
6atch(()=>{}).finally(()=>{x.current=!1,u(!1)}))},p=()=>_(),b=()=>{m.current=!1,d.current=0,o(0)};return window.addEventListener("touchstart",S,{passive:!0}),window.addEventListener("touchmove",C,{passive:!0}),window.addEventListener("touchend",p,{passive:!0}),window.addEventListener("touchcancel",b,{passive:!0}),()=>{window.removeEventListener("touchstart",S),window.removeEventListener("touchmove",C),window.removeEventListener("touchend",p),window.removeEventListener("touchcancel",b)}},[t,a,n]),{pullPx:i,refreshing:c}}function Hg({pullPx:t,refreshing:a,className:n}){const s=t>6||a,i=a?1:Math.min(1,Math.max(0,t/56));return e.jsx("div",{className:L("pointer-events-none fixed left-0 right-0 top-0 z-[45] flex justify-center","pt-[max(0.5rem,calc(env(safe-area-inset-top)+4px))]",n),"aria-hidden":!0,children:e.jsx("div",{className:L("flex h-9 w-9 items-center justify-center rounded-full border border-border","bg-surface-1/95 shadow-md backdrop-blur-[2px]","transition-[opacity,transform] duration-150"),style:{opacity:s?i:0,transform:`translateY(${Math.min(10,t*.12)}px)`},children:s&&e.jsx("span",{className:L("inline-block h-4 w-4 rounded-full border-2 border-accent border-t-transparent",a&&"animate-spin")})})})}function Ug(){const[t,a]=r.useState(!1);return r.useEffect(()=>{const n=window.matchMedia("(hover: none) and (pointer: coarse)"),s=()=>a(n.matches);return s(),n.addEventListener("change",s),()=>n.removeEventListener("change",s)},[]),t}function Lr(t,a=500){const n=r.useRef(null),s=r.useRef(t);return r.useEffect(()=>{s.current=t},[t]),r.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),r.useCallback((...i)=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>s.current(...i),a)},[a])}function Yg({addOpen:t,shareOpen:a,detailsOpen:n,showFilters:s,onClosePanel:i,onCloseFilters:o,onFocusSearch:c}){const u=r.useCallback(l=>{if((l.ctrlKey||l.metaKey)&&l.key.toLowerCase()==="k"){l.preventDefault(),c();return}if(l.key==="Escape"){if(s){o();return}(t||a||n)&&i()}},[t,a,n,s,i,o,c]);r.useEffect(()=>(window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)),[u])}function Kg(t){return r.useMemo(()=>{let a=0;const n=t.notes??(t.hasNotes?"WITH":"ANY");return t.ratings?.length&&a++,t.platforms?.length&&a++,typeof t.minWords=="number"&&a++,typeof t.maxWords=="number"&&a++,typeof t.minKudos=="number"&&a++,typeof t.maxKudos=="number"&&a++,typeof t.minRating=="number"&&a++,t.entryRating==="UNRATED"&&a++,n!=="ANY"&&a++,t.tag?.trim()&&a++,t.workTag?.trim()&&a++,t.statuses?.length&&a++,t.pairMembers?.length&&a++,t.pairExact&&t.pairMembers?.length&&a++,t.characters?.length&&a++,t.fandoms?.length&&a++,t.catchup!=="ANY"&&a++,t.storyUpdates==="NEW"&&a++,t.completionStatus?.length&&a++,t.excludeWarnings?.length&&a++,t.includeWarnings?.length&&a++,t.categoryFilter?.length&&a++,t.excludeTag?.trim()&&a++,t.excludeWorkTag?.trim()&&a++,t.excludePairMembers?.length&&a++,t.excludePairExact&&t.excludePairMembers?.length&&a++,t.excludeCharacters?.length&&a++,t.excludeFandoms?.length&&a++,t.excludeCategoryFilter?.length&&a++,t.lastReadAfter?.trim()&&a++,t.lastReadBefore?.trim()&&a++,a},[t])}function zg(t,a){return{sort:t.sort==="STORY_UPDATE_DESC"?"LAST_READ_DESC":t.sort,filters:t.filters.storyUpdates==="NEW"?{...t.filters,storyUpdates:"ANY"}:t.filters}}const Ar=["page","limit"],Tr=t=>typeof t=="object"&&t!==null,Er=(t,a)=>Object.prototype.hasOwnProperty.call(t,a);function Ba(t){if(!Tr(t))return;const a=[];for(const s of Ar)Er(t,s)&&t[s]!==void 0&&a.push(s);const n=t.filters;if(Tr(n))for(const s of Ar)Er(n,s)&&n[s]!==void 0&&a.push(`filters.${s}`);if(a.length)throw new Error(`Saved Library View queries cannot include pagination fields: ${a.join(", ")}`)}function Ht(t={}){return{ratings:Ur(t.ratings),platforms:[...t.platforms??[]],minWords:t.minWords,maxWords:t.maxWords,minKudos:t.minKudos,maxKudos:t.maxKudos,minRating:t.minRating,entryRating:t.entryRating??"ANY",notes:t.notes??"ANY",hasNotes:t.hasNotes??!1,tag:t.tag??"",workTag:t.workTag??"",statuses:[...t.statuses??[]],pairMembers:[...t.pairMembers??[]],pairExact:t.pairExact??!1,characters:[...t.characters??[]],fandoms:[...t.fandoms??[]],catchup:t.catchup??"ANY",storyUpdates:t.storyUpdates??"ANY",completionStatus:[...t.completionStatus??[]],excludeWarnings:[...t.excludeWarnings??[]],includeWarnings:[...t.includeWarnings??[]],categoryFilter:[...t.categoryFilter??[]],excludeTag:t.excludeTag??"",excludeWorkTag:t.excludeWorkTag??"",excludePairMembers:[...t.excludePairMembers??[]],excludePairExact:t.excludePairExact??!1,excludeCharacters:[...t.excludeCharacters??[]],excludeFandoms:[...t.excludeFandoms??[]],excludeCategoryFilter:[...t.excludeCategoryFilter??[]],lastReadAfter:t.lastReadAfter??"",lastReadBefore:t.lastReadBefore??""}}function Un(t){return Ba(t),Ba(t.filters),In.parse(Yr({search:t.search,sort:t.sort,filters:t.filters}))}const Ue=t=>{const a=Array.from(new Set((t??[]).map(n=>
6n.trim()).filter(Boolean))).sort((n,s)=>n.localeCompare(s));return a.length?a:void 0},qg=t=>{const a=Array.from(new Set((t??[]).map(Kr).filter(Boolean))).sort((n,s)=>n.localeCompare(s));return a.length?a:void 0},Gg=t=>{const a=Array.from(new Set(t??[])).sort((n,s)=>n.localeCompare(s));return a.length?a:void 0},Qg=t=>{const a=Ur(t);return a.length?a:void 0},At=t=>t?.trim()||void 0,Xg=t=>Object.fromEntries(Object.entries(t).filter(([,a])=>a!==void 0));function Zg(t){const a=Ue(t.pairMembers),n=Ue(t.excludePairMembers),s=t.notes==="ANY"?void 0:t.notes??(t.hasNotes?"WITH":void 0);return Xg({ratings:Qg(t.ratings),platforms:qg(t.platforms),minWords:t.minWords,maxWords:t.maxWords,minKudos:t.minKudos,maxKudos:t.maxKudos,notes:s,tag:At(t.tag),workTag:At(t.workTag),statuses:Gg(t.statuses),pairMembers:a,pairExact:a&&t.pairExact?!0:void 0,characters:Ue(t.characters),relationships:Ue(t.relationships),fandoms:Ue(t.fandoms),completionStatus:Ue(t.completionStatus),excludeWarnings:Ue(t.excludeWarnings),includeWarnings:Ue(t.includeWarnings),categoryFilter:Ue(t.categoryFilter),excludeTag:At(t.excludeTag),excludeWorkTag:At(t.excludeWorkTag),excludePairMembers:n,excludePairExact:n&&t.excludePairExact?!0:void 0,excludeCharacters:Ue(t.excludeCharacters),excludeFandoms:Ue(t.excludeFandoms),excludeCategoryFilter:Ue(t.excludeCategoryFilter),lastReadAfter:At(t.lastReadAfter),lastReadBefore:At(t.lastReadBefore),minEntryRating:t.minEntryRating,entryRating:t.entryRating==="UNRATED"?"UNRATED":void 0,catchup:t.catchup==="ANY"?void 0:t.catchup,storyUpdates:t.storyUpdates==="NEW"?"NEW":void 0})}function mo(t){Ba(t);const a=In.parse(t);return{search:a.search,sort:a.sort,filters:Zg(a.filters)}}const Pr=t=>JSON.stringify(mo(t));function Mr(t,a){return t?Pr(t)!==Pr(Un(a)):!1}function Pa(t){Ba(t);const a=In.parse(t),n=a.filters,s=n.notes??(n.hasNotes?"WITH":"ANY");return{search:a.search,sort:a.sort,filters:Ht({ratings:n.ratings,platforms:n.platforms?.map(Kr),minWords:n.minWords,maxWords:n.maxWords,minKudos:n.minKudos,maxKudos:n.maxKudos,minRating:n.minEntryRating,entryRating:n.entryRating??"ANY",notes:s,hasNotes:s==="WITH",tag:n.tag,workTag:n.workTag,statuses:n.statuses,pairMembers:n.pairMembers,pairExact:n.pairExact,characters:n.characters,fandoms:n.fandoms,catchup:n.catchup??"ANY",storyUpdates:n.storyUpdates??"ANY",completionStatus:n.completionStatus,excludeWarnings:n.excludeWarnings,includeWarnings:n.includeWarnings,categoryFilter:n.categoryFilter,excludeTag:n.excludeTag,excludeWorkTag:n.excludeWorkTag,excludePairMembers:n.excludePairMembers,excludePairExact:n.excludePairExact,excludeCharacters:n.excludeCharacters,excludeFandoms:n.excludeFandoms,excludeCategoryFilter:n.excludeCategoryFilter,lastReadAfter:n.lastReadAfter,lastReadBefore:n.lastReadBefore})}}const Jg={search:"",sort:ua.value,filters:Ht()},ef=mo(Un(Jg));function tf(t){return oa.find(a=>a.value===t)?.label??t}function po(t){const a=no(t.filters,t.search).filter(n=>n.id!=="search").map(n=>`${n.label}: ${n.value}`);return{sortLabel:tf(t.sort),search:t.search.trim(),chips:a}}function af(t){const a=Pa(t),n=po(a),s=[n.search?`Search: ${n.search}`:null,a.sort!==ua.value?`Sort: ${n.sortLabel}`:null,...n.chips.slice(0,2)].filter(o=>!!o);if(!s.length)return"Whole Library";const i=n.chips.length-Math.min(n.chips.length,2);return i>0?`${s.join(" · ")} · +${i}`:s.join(" · ")}function Ir(t){return{id:t.view_id,name:t.name,summary:af(t.query),query:t.query,pinned:t.pinned,liveCount:t.pinned?t.live_count:void 0}}function nf(t){return[...t].sort((a,n)=>a.position!==n.position?a.position-n.position:a.created_at.localeCompare(n.created_at))}function Or(t,a){const n=t?.views??[],i=n.some(o=>o.view_id===a.view_id)?n.map(o=>o.view_id===a.view_id?a:o):[...n,a];return{views:nf(i)}}function sf(t,a){return t&&{views:t.views.filter(n=>n.view_id!==a)}}function rf(t,a,n){const s=t.find(l=>l.view_id===a);if(!s)return null;const i=t.filter(l=>l.pinned===s.pinned),o=i.findIndex(l=>l.view_id===a),c=n==="up"?o-1:o+1,u=i[c];return u?t.map(l=>l.view_id===s.view_id?u:l.view_id===u.view_id?s:l):null}function of({api:t,libraryViewId:a,setLibraryViewId:n,searchInput:s,sort:i,filters:o,setSearchInput:c,setDebouncedSearch:u,setSort:l,setFilters:m,setShowFilters:d,onToast:x}){const y=da(),g=r.useRef(null),N=r.useRef(!1),S=r.useRef(!1),C=r.useRef(!1),_=r.useRef(!1),[p,b]=r.useState("refine"),[k,j]=r.useState(!1),[O,R]=r.useState(null),[F,A]=r.useState(!1),z=a&&a!==Je?a:null,[Q,te]=r.useState(z);r.useEffect(()=>{te(z)},[z]);const v=na({queryKey:je.libraryViews.list(),queryFn:()=>t.listLibraryViews(),enabled:t.isReady,staleTime:6e4}),$=Q,f=r.useMemo(()=>v.data?.views??[],[v.data?.views]),U=$?f.find(T=>T.view_id===$)??null:null,oe=r.useMemo(()=>f.map(Ir),[f]),se=r.useMemo(()=>U?Ir(U):null,[U]),G=r.useMemo(()=>({search:s,sort:i,filters:o}),[o,s,i]),I=r.useMemo(()=>Un(G),[G]),E=r.useMemo(()=>po(G),[G]),Y=r.useMemo(()=>Mr(U?.query,G),[U?.query,G]),W=r.useMemo(()=>Mr(ef,G),[G]),J=r.useCallback(T=>{c(T.search),u(T.search),l(T.sort),m(T.filters)},[u,m,c,l]),X=r.useCallback(()=>{g.current=null,te(null),n(null),J({search:"",sort:ua.value,filters:Ht()}),b("refine"),j(!1),R(null),A(!1)},[J,n]),ee=r.useCallback(()=>{y.invalidateQueries({queryKey:je.libraryViews.list()})},[y]),le=Pt({mutationFn:T=>t.createLibraryView({name:T.name,pinned:T.pinned,query:I}),onSuccess:T=>{y.setQueryData(je.libraryViews.list(),K=>Or(K,T.view)),g.current=T.view.view_id,te(T.view.view_id),n(T.view.view_id),b("refine"),j(!1),R(null),A(!1),ee(),x?.("Library View saved")},onError:()=>x?.("Failed to save Library View"),onSettled:()=>{N.current=!1}}),ae=Pt({mutationFn:({viewId:T,payload:K})=>t.updateLibraryView(T,K),onSuccess:T=>{y.setQueryData(je.libraryViews.list(),K=>Or(K,T.view)),T.view.view_id===a&&(g.current=T.view.view_id),ee(),x?.("Library View updated")},onError:()=>x?.("Failed to update Library View"),onSettled:()=>{S.current=!1}}),P=Pt({mutationFn:T=>t.deleteLibraryView(T),onSuccess:(T,K)=>{y.setQueryData(je.libraryViews.list(),q=>sf(q,K)),a===K&&X(),ee(),x?.("Library View deleted")},onError:()=>x?.("Failed to delete Library View"),onSettled:()=>{C.current=!1}}),re=Pt({mutationFn:({orderedViewIds:T})=>t.reorderLibraryViews({view_ids:T}),onSuccess:T=>{y.setQueryData(je.libraryViews.list(),T),ee(),x?.("Library Views reordered")},onError:()=>x?.("Failed to reorder Library Views"),onSettled:()=>{_.current=!1}}),me=r.useMemo(()=>{const T=le.error?"Failed to save Library View.":ae.error?"Failed to update Library View.":P.error?"Failed to delete Library View.":re.error?"Failed to reorder Library Views.":null;return{creating:le.isPending,updatingViewId:ae.isPending?ae.variables?.viewId??null:null,deletingViewId:P.isPending?P.variables??null:null,reorderingViewId:re.isPending?re.variables?.viewId??null:null,errorMessage:T}},[le.error,le.isPending,P.error,P.isPending,P.variables,re.error,re.isPending,re.variables?.viewId,ae.error,ae.isPending,ae.variables?.viewId]),ce=r.useCallback(T=>{if(T===Je){X();return}const K=f.find(fe=>fe.view_id===T);if(!K)return;const q=Pa(K.query);te(K.view_id),J(q),g.current=K.view_id,n(K.view_id),b("refine"),j(!1)},[J,f,X,n]);r.useEffect(()=>{if(!$){g.current=null,a===Je&&X();return}if(!v.isSuccess)return;const T=f.find(K=>K.view_id===$);if(!T){X(),x?.("Library View unavailable; showing All Library");return}g.current!==$&&(J(Pa(T.query)),g.current=T.view_id)},[J,a,f,x,$,X,v.isSuccess]);const We=r.useMemo(()=>({onSelectView:ce,onOpenSave:(T=!1)=>{j(T),b("save"),d(!0)},onOpenManage:()=>{j(!1),b("manage"),d(!0)},onSaveView:T=>{N.current||le.isPending||(N.current=!0,le.mutate(T))},onUpdateView:()=>{U&&(S.current||ae.isPending||(S.current=!0,ae.mutate({viewId:U.view_id,payload:{query:I},kind:"query"})))},onRevertView:()=>{U&&(J(Pa(U.query)),g.current=U.view_id,b("refine"))},onClosePanel:()=>{b("refine"),j(!1)},onTogglePin:T=>{if(S.current||ae.isPending)return;const K=f.find(q=>q.view_id===T);K&&(S.current=!0,ae.mutate({viewId:T,payload:{pinned:!K.pinned},kind:"pin"}))},onRenameView:(T,K)=>{if(S.current||ae.isPending)return;const q=f.find(be=>be.view_id===T);if(!q)return;const fe=K.trim();
6!fe||fe===q.name||(S.current=!0,ae.mutate({viewId:T,payload:{name:fe},kind:"rename"}))},onDeleteView:T=>{C.current||P.isPending||(C.current=!0,P.mutate(T))},onMoveView:(T,K)=>{if(_.current||re.isPending)return;const q=rf(f,T,K);q&&(_.current=!0,re.mutate({viewId:T,orderedViewIds:q.map(fe=>fe.view_id)}))}}),[U,J,le,I,P,f,re,ce,d,ae]),pe=r.useMemo(()=>({...We,onSelectView:T=>{ce(T),R(null),A(!1)},onOpenSave:(T=!1)=>{A(T),R("save")},onOpenManage:()=>{A(!1),R("manage")},onClosePanel:()=>{R(null),A(!1)},onRevertView:()=>{We.onRevertView(),R(null),A(!1)}}),[We,ce]),De=se?Ud({activeView:se,dirty:Y}):null,Se=r.useCallback(()=>{b("refine"),j(!1),d(!0)},[d]),M=r.useCallback(()=>{d(!1),b("refine"),j(!1)},[d]);return{activeLibraryView:U,activeViewId:$,activeViewItem:se,capturedQuery:E,closeSheet:M,createLibraryView:le,currentSavedQuery:I,desktopHandlers:pe,desktopPanelMode:O,desktopSaveAsNew:F,dirty:Y,handlers:We,hasAdHocQuery:W,mutationState:me,openRefineSheet:Se,reorderLibraryViews:re,saveAsNew:k,sheetMode:p,toolbarChip:De,updateLibraryView:ae,viewItems:oe,viewsQuery:v}}const ho="trace:library-view-state-v1";function Dr(t){return typeof t=="object"&&t!==null}function lf(t){return typeof t=="string"?t:""}function cf(){try{const t=window.sessionStorage.getItem(ho);if(!t)return null;const a=JSON.parse(t);if(!Dr(a))return null;const n=Br(a.sort)?a.sort:"LAST_READ_DESC",s=Ht(Dr(a.filters)?a.filters:{});return{search:lf(a.search),sort:n,filters:s}}catch{return null}}function df(t){try{window.sessionStorage.setItem(ho,JSON.stringify({search:t.search,sort:t.sort,filters:Ht(t.filters)}))}catch{}}const Fr=Vr,uf=300,mf=500,Tt=!1;Ze.lazy(async()=>({default:(await zr(()=>import("./story-updates-surfaces.component-BLIxEdkQ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]))).StoryUpdatesEducation}));Ze.lazy(async()=>({default:(await zr(()=>import("./story-updates-surfaces.component-BLIxEdkQ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]))).StoryUpdatesLibraryShortcut}));function pf(t){return t instanceof Error?t.message:String(t)}function hf(t,a){return typeof t=="object"&&t!==null&&"status"in t&&t.status===a}const xo="trace.libraryDensityMode",bo="trace.libraryGroupingMode",xf={statuses:"Status",completionStatus:"Work",tag:"Tag",workTag:"AO3",excludeTag:"Hide tag",excludeWorkTag:"Hide AO3",minWords:"Words",maxWords:"Words",minKudos:"Kudos",maxKudos:"Kudos",entryRating:"Rating",hasNotes:"Notes",storyUpdates:"Updates"},bf=new Intl.NumberFormat("en-US",{maximumFractionDigits:1,notation:"compact"});function gf(t){return t.replace(/^(≤\s*)?([\d,]+)(\+)?$/,(a,n,s,i)=>{const o=Number(s.replace(/,/g,""));return!Number.isFinite(o)||o<1e4?a:`${n??""}${bf.format(o).toLowerCase()}${i??""}`})}function ff(t,a){return xf[t]??a}function vf(t,a){return t==="minWords"||t==="maxWords"||t==="minKudos"||t==="maxKudos"?gf(a):a}function yf(){try{const t=window.localStorage.getItem(xo);return t==="browse"||t==="compact"?t:"compact"}catch{return"compact"}}function wf(t){try{window.localStorage.setItem(xo,t)}catch{}}function jf(){try{return window.localStorage.getItem(bo)==="series"?"series":"none"}catch{return"none"}}function Nf(t){try{window.localStorage.setItem(bo,t)}catch{}}function qf(){const t=pt(),a=Hr(),s=hl()==="app",i=da(),o=wl(),c=On(),u=r.useRef(cf()),l=r.useMemo(()=>new URLSearchParams(c.search),[c.search]),m=l.has("q"),d=l.has("sort"),x=l.has("catchup"),y=r.useCallback((h=!0)=>{i.invalidateQueries({queryKey:je.library.all}),i.invalidateQueries({queryKey:je.suggestions}),i.invalidateQueries({queryKey:je.stats.all}),h&&i.invalidateQueries({queryKey:je.me})},[i]),g=r.useCallback(()=>{i.invalidateQueries({queryKey:je.suggestions}),i.invalidateQueries({queryKey:je.stats.all})},[i]),{q:N,sort:S,panel:C,entryId:_,catchup:p,setQ:b,setSort:k,setCatchup:j,libraryViewId:O,setLibraryViewId:R,openPanel:F,closePanel:A}=Zb(),[z,Q]=r.useState(!1),[te,v]=r.useState(""),[$,f]=r.useState(!1),[U,oe]=r.useState(m?N:u.current?.search??N),[se,G]=r.useState(m?N:u.current?.search??N),I=zg({sort:d?S:u.current?.sort??S,filters:Ht({...u.current?.filters??{},catchup:x?p:u.current?.filters.catchup??p})}),[E,Y]=r.useState(I.sort),[W,J]=r.useState(I.filters),X=r.useCallback(h=>{Y(w=>{const B=typeof h=="function"?h(w):h;return B==="STORY_UPDATE_DESC"?"LAST_READ_DESC":B})},[]),ee=r.useCallback(h=>{J(w=>{const B=typeof h=="function"?h(w):h;return B.storyUpdates==="NEW"?{...B,storyUpdates:"ANY"}:B})},[]),[le,ae]=r.useState(yf),[P,re]=r.useState(jf),[me,ce]=r.useState(null);r.useEffect(()=>{m&&oe(N)},[m,N]),r.useEffect(()=>{d&&X(S)},[d,X,S]),r.useEffect(()=>wf(le),[le]),r.useEffect(()=>Nf(P),[P]),r.useEffect(()=>{le==="compact"&&ce(null)},[le]);const We=Lr(h=>G(h),uf);r.useEffect(()=>{We(U)},[U,We]),r.useEffect(()=>{b(se)},[se,b]),r.useEffect(()=>{E!==S&&k(E)},[E,S,k]);const{data:pe,isLoading:De,refetch:Se}=na({queryKey:je.me,queryFn:()=>t.me(),enabled:t.isReady,staleTime:6e4}),M=!!pe?.pro,T=_g({account:pe,patchUiSettings:t.patchAccountUiSettings}),K=Rg({enabled:!!pe,getNotice:t.getAccountReleaseNotice,dismissNotice:t.dismissAccountReleaseNotice});Lg(),na({queryKey:je.library.storyUpdatesCount,queryFn:()=>t.listLibrary({search:"",sort:"STORY_UPDATE_DESC",page:1,limit:1,filters:{storyUpdates:"NEW"}}),select:h=>h.total??0,enabled:Tt,staleTime:6e4});const[q,fe]=r.useState(!1);r.useEffect(()=>{x&&ee(h=>h.catchup===p?h:{...h,catchup:p})},[p,x,ee]),r.useEffect(()=>{W.catchup!==p&&j(W.catchup)},[W.catchup,p,j]),r.useEffect(()=>{df({search:U,sort:E,filters:W})},[W,U,E]);const be=r.useMemo(()=>JSON.stringify({q:se,sort:E,filters:W}),[se,E,W]),we=r.useMemo(()=>`${vg}${be}`,[be]),ve=kg(we);r.useEffect(()=>xl(h=>{`${c.pathname}
6${c.search}`===h.returnTo&&(ve(),o(`/library/${h.entryId}`,{state:{libraryReturnTo:h.returnTo}}))}),[c.pathname,c.search,o,ve]);const Te=C==="add",He=C==="share",ke=C==="details",ge=!1;r.useEffect(()=>{if(ke){if(_){o(`/library/${_}`,{replace:!0});return}A()}},[A,_,ke,o]);const tt=async h=>{Q(!0),v("");try{await t.manualEntry(h),A(),y(),Ce("Added to your library"),gs()}catch(w){const B=pf(w);throw(B.includes("FREE_LIMIT_REACHED")||hf(w,402))&&ln("library_cap"),v(B||"Failed to add story"),w}finally{Q(!1)}},ht=50,ye=jl({queryKey:je.library.list({search:se,sort:E,filters:W,limit:ht}),queryFn:({pageParam:h})=>t.listLibrary({search:se,sort:E,page:1,limit:ht,cursor:typeof h=="string"?h:void 0,pagination:"cursor",filters:W}),getNextPageParam:h=>h?.hasMore&&h.nextCursor?h.nextCursor:void 0,enabled:t.isReady,retry:2,retryDelay:h=>Math.min(1e3*2**h,8e3),initialPageParam:null,placeholderData:Sl,staleTime:5*6e4,gcTime:10*6e4,refetchOnWindowFocus:!1,refetchOnMount:"always"});Mc({enabled:a&&t.isReady&&ye.isSuccess,libraryRevision:ye.dataUpdatedAt,getActivityMarker:t.getAdvocacyActivityMarker});const Re=Ug(),Ke=r.useCallback(()=>ye.refetch(),[ye]);r.useEffect(()=>{let h=0;const w=()=>{h&&window.clearTimeout(h),h=window.setTimeout(()=>{h=0,Ke()},350)},B=()=>{w()},ue=()=>{document.visibilityState==="visible"&&w()},_e=()=>{w()};return window.addEventListener("focus",B),window.addEventListener("pageshow",_e),document.addEventListener("visibilitychange",ue),()=>{window.removeEventListener("focus",B),window.removeEventListener("pageshow",_e),document.removeEventListener("visibilitychange",ue),h&&window.clearTimeout(h)}},[Ke]),r.useEffect(()=>{const h=w=>{w.source===window&&w.origin===window.location.origin&&w.data?.type==="TRACE_LIBRARY_INVALIDATED"&&(y(),Ke())};return window.addEventListener("message",h),()=>{window.removeEventListener("message",h)}},[y,Ke]);const jt=Vg({enabled:(Re||a)&&!q,scrollContainerSelector:a?Pn:void 0,onRefresh:Ke}),Le=ye.data?.pages?.[0]?.total??0,Pe=typeof pe?.library_count=="number"?pe.library_count:Le,Me=Le,xt=typeof pe?.cap?.limit=="number"?pe.cap.limit:Fr,at=!De&&!M&&(pe?.cap?.over===!0||Pe>=xt),ma=r.useCallback(()=>{if(at){ln("library_cap");return}v(""),F("add")},[at,F]),Nt=r.useRef(!1);r.useEffect(()=>{if(!Te){Nt.current=!1;return}!at||Nt.current||(Nt.current=!0,A(),ln("library_cap"))},[Te,A,at]);const pa=r.useMemo(()=>{const h=(ye.data?.pages??[]).flatMap(ue=>ue?.data??[]),w=new Set,B=[];for(const ue of h){const _e=String(ue.entry.entry_id);w.has(_e)||(w.add(_e),B.push(ue))}return B},[ye.data]),St=!!ye.data?.pages?.length,D=ye.isLoading&&!St,H=ye.isError&&!St,{hasNextPage:Ne,fetchNextPage:Ge,isFetchingNextPage:Ie}=ye,Fe=r.useRef(null),ha=Ze.useCallback(h=>{if(Fe.current&&(Fe.current.disconnect(),Fe.current=null),!h||!Ne)return;const w=new IntersectionObserver(B=>{B[0].isIntersecting&&Ne&&!Ie&&Ge()},{rootMargin:"1200px 0px 1200px 0px"});w.observe(h),Fe.current=w},[Ne,Ie,Ge]);r.useEffect(()=>(!Ne&&Fe.current&&(Fe.current.disconnect(),Fe.current=null),()=>{Fe.current?.disconnect(),Fe.current=null}),[Ne]);const{storiesMap:Ee,entries:Ae}=r.useMemo(()=>_c(pa),[pa]);r.useEffect(()=>{Ag(Ae,Ee)},[Ae,Ee]);const[go,Yn]=r.useState(null),[fo,Kn]=r.useState(null),Ut=r.useRef(null),Ce=Ze.useCallback((h,w=3e3,B=null)=>{Yn(h),Kn(B),Ut.current&&clearTimeout(Ut.current),Ut.current=setTimeout(()=>{Yn(null),Kn(null)},w)},[]);r.useEffect(()=>()=>{Ut.current&&clearTimeout(Ut.current)},[ee]);const V=of({api:t,libraryViewId:O,setLibraryViewId:R,searchInput:U,sort:E,filters:W,setSearchInput:oe,setDebouncedSearch:G,setSort:X,setFilters:ee,setShowFilters:fe,onToast:Ce}),zn=r.useRef(0),{updateEntry:qn,queuePatch:Gn,flushNow:xa}=Rc({patchEntry:t.patchEntry,bulkPatchEntries:t.bulkPatchEntries,queryKeyPrefix:je.library.all,onPatchSettled:g,onPatchSuccess:({entryId:h,patch:w})=>{fl(h,w),gs()},flushMs:200,onPatchError:h=>{if(h.status!==429)return;const w=Date.now();if(w-zn.current<4e3)return;zn.current=w;const B=h.retryAfterSec,ue=typeof B=="number"&&B>0?` Try again in ~${B}s.`:"";Ce(`Too many updates too quickly.${ue} Saving will resume in a moment.`,5e3)}}),Qn=r.useMemo(()=>{const h=new Set;return Ae.forEach(w=>
6(w.tags||[]).forEach(B=>h.add(B))),Array.from(h).sort((w,B)=>w.localeCompare(B))},[Ae]),{visible:he,onLayoutPointerLockChange:vo,markEntryForDeferredRecencyReorder:ba,deferredRecencyReorderIds:yo,onDeferredRecencyEntryExit:wo}=gg({entries:Ae,storiesMap:Ee,sort:E,listIdentityKey:be}),Xn=r.useRef(!1);r.useEffect(()=>{Xn.current||!pe||pe.first_story_completed_at!==null||he.length===0||(Xn.current=!0,Se())},[pe,Se,he.length]);const za=r.useRef(null);r.useEffect(()=>{if(!ye.isSuccess||za.current===we)return;const h=oo(we);if(h<=0){za.current=we;return}let w=!1,B=0,ue=0,_e=0,Gt=!1;const Sa=()=>{if(w)return;const ol=jg(h);if(Math.abs(ol-h)<=4||B>=48){za.current=we;return}Ng()+4<h&&Ne&&!Ie&&!Gt&&(Gt=!0,Ge().finally(()=>{Gt=!1})),B+=1,ue=window.setTimeout(Sa,50)};return _e=lo(Sa),()=>{w=!0,_e&&co(_e),ue&&window.clearTimeout(ue)}},[Ge,Ne,Ie,ye.isSuccess,we,he.length]);const jo=r.useMemo(()=>og(Ae),[Ae]);r.useEffect(()=>{me&&(he.some(h=>h.id===me)||ce(null))},[me,he]);const Yt=r.useCallback((h,w)=>(ba(h),qn(h,w)),[ba,qn]),bt=r.useCallback((h,w)=>{ba(h),Gn(h,w)},[ba,Gn]),No=r.useRef(null),Zn=r.useRef(null);Gl(Zn);const nt=r.useMemo(()=>_?Ae.find(h=>h.id===_):void 0,[Ae,_]);nt&&Ee[nt.storyId],pc();const ga=!1,Jn=ge,[es,ts]=r.useState(!1),[So,as]=r.useState(!1),[qa,ns]=r.useState(null),ko=async()=>{if(nt){as(!0);try{await t.deleteEntry(nt.id),Ce("Removed from library"),ts(!1),A(),y()}catch(h){console.error(h),Ce("Failed to remove")}finally{as(!1)}}},Co=Ze.useCallback(async h=>{if(!qa){ns(h);try{await t.deleteEntry(h),Ce("Removed from library"),nt?.id===h&&A(),y()}catch{Ce("Failed to remove")}finally{ns(null)}}},[t,A,y,nt?.id,Ce,qa]),[Sf,kf]=r.useState(0),[Cf,_f]=r.useState(""),[Rf,Lf]=r.useState([]);r.useEffect(()=>{},[ge,nt]),Lr((h,w)=>{bt(h,w)},mf);const[Xe,Ga]=r.useState("visible"),[Qa,_o]=r.useState([]),[Xa,Ro]=r.useState("any"),[Lo,Ao]=r.useState(""),[To,Eo]=r.useState({includeSummary:!0,includeRating:!1,includeRelationships:!0,includeNotes:!1,format:"Detailed"}),ne=fg({visible:he,entries:Ae,storiesMap:Ee,queuePatch:bt,deleteEntry:t.deleteEntry,pushToast:Ce,invalidateLibrary:()=>y(),resetKey:be}),st=Lc(),fa=r.useMemo(()=>Qa.map(h=>h.trim()).filter(Boolean),[Qa]),va=r.useCallback(h=>{if(!fa.length)return!1;const w=h.tags||[];return Xa==="all"?fa.every(B=>w.includes(B)):w.some(B=>fa.includes(B))},[fa,Xa]),Za=r.useMemo(()=>{let h=0;for(const w of he)va(w)&&(h+=1);return h},[he,va]),Po=r.useMemo(()=>Xe==="selected"?ne.selectedEntries.length:Xe==="visible"?he.length:Xe==="tag"?Za:0,[Xe,ne.selectedEntries.length,he.length,Za]),Mo=r.useCallback((h,w)=>{if(w<=0)return[];if(Xe==="selected")return ne.selectedEntries.slice(h,h+w);if(Xe==="visible")return he.slice(h,h+w);if(Xe!=="tag")return[];const B=[];let ue=0;for(const _e of he)if(va(_e)&&(ue>=h&&B.length<w&&B.push(_e),ue+=1,B.length>=w))break;return B},[Xe,ne.selectedEntries,he,va]),ss=r.useRef(null),kt=r.useCallback(()=>{for(const h of document.querySelectorAll("[data-library-toolbar-search]"))if(h.offsetParent!==null){h.focus();return}ss.current?.focus()},[]);Yg({addOpen:Te,shareOpen:He,detailsOpen:ge,showFilters:q,onClosePanel:A,onCloseFilters:V.closeSheet,onFocusSearch:kt});const Ct=Kg(W),Ja=U.trim().length>0||se.trim().length>0,Io=!!O||V.viewItems.length>0||V.viewsQuery.isError,ya=Ct>0||Ja||Io||q,Oo=!De&&typeof pe?.library_count=="number"&&pe.library_count===0,Do=St&&Le===0&&he.length===0,Fo=!t.isReady||De||!St&&!H&&(ye.isPending||ye.isLoading||ye.fetchStatus==="fetching"),$o=!H&&!ya&&he.length===0&&ye.fetchStatus==="fetching",en=!H&&!ya&&he.length===0&&!$o&&(Oo||Do),tn=!H&&!en&&!ya&&he.length===0&&Fo,Kt=D&&!en&&!tn,_t=!en&&!tn&&(Kt||H||Le>0||ya),Wo=_t||Le>0||he.length>0,Bo=r.useMemo(()=>sg({entries:Ae,storiesMap:Ee,totalCount:Le,visibleCount:he.length,activeFilterCount:Ct,hasQuery:Ja}),[Ct,Ae,Ja,Ee,Le,he.length]),wa=r.useMemo(()=>Ae.filter(h=>h.status==="READING").length,[Ae]),Vo=r.useMemo(()=>{const h=Pe.toLocaleString(),w=wa.toLocaleString();return`${h} saved · ${w} reading`},[Pe,wa]),Ho=r.useMemo(()=>`${Pe.toLocaleString()} · ${wa.toLocaleString()}`,[Pe,wa]),an=s?"standalone":"browser",Uo=s?Pn:yg,Yo=Wg({enabled:s&&_t,freezeFull:$||q,resetKey:c.pathname,scrollC
6ontainerSelector:Uo}),rs=an==="standalone"?Yo:"full",Ko=r.useCallback(()=>{if(q){V.closeSheet();return}V.openRefineSheet()},[V,q]),Rt=r.useCallback(()=>{ee({ratings:[],platforms:[],hasNotes:!1,notes:"ANY",tag:"",workTag:"",statuses:[],minWords:void 0,maxWords:void 0,minKudos:void 0,maxKudos:void 0,minRating:void 0,entryRating:"ANY",pairMembers:[],pairExact:!1,characters:[],fandoms:[],catchup:"ANY",storyUpdates:"ANY",completionStatus:[],excludeWarnings:[],includeWarnings:[],categoryFilter:[],excludeTag:"",excludeWorkTag:"",excludePairMembers:[],excludePairExact:!1,excludeCharacters:[],excludeFandoms:[],excludeCategoryFilter:[],lastReadAfter:"",lastReadBefore:""})},[ee]);r.useCallback(()=>{R(null),ee(h=>({...h,storyUpdates:"NEW"})),X("STORY_UPDATE_DESC"),fe(!1)},[ee,R,X]);const zt=r.useCallback(h=>{if(h==="search"){oe(""),G(""),kt();return}ee(w=>{switch(h){case"ratings":return{...w,ratings:[]};case"platforms":return{...w,platforms:[]};case"minWords":return{...w,minWords:void 0};case"maxWords":return{...w,maxWords:void 0};case"minKudos":return{...w,minKudos:void 0};case"maxKudos":return{...w,maxKudos:void 0};case"minRating":return{...w,minRating:void 0,entryRating:"ANY"};case"entryRating":return{...w,entryRating:"ANY"};case"hasNotes":return{...w,hasNotes:!1,notes:"ANY"};case"tag":return{...w,tag:""};case"workTag":return{...w,workTag:""};case"statuses":return{...w,statuses:[]};case"pairMembers":return{...w,pairMembers:[],pairExact:!1};case"pairExact":return{...w,pairExact:!1};case"characters":return{...w,characters:[]};case"fandoms":return{...w,fandoms:[]};case"catchup":return{...w,catchup:"ANY"};case"storyUpdates":return{...w,storyUpdates:"ANY"};case"completionStatus":return{...w,completionStatus:[]};case"includeWarnings":return{...w,includeWarnings:[]};case"categoryFilter":return{...w,categoryFilter:[]};case"excludeTag":return{...w,excludeTag:""};case"excludeWorkTag":return{...w,excludeWorkTag:""};case"excludePairMembers":return{...w,excludePairMembers:[],excludePairExact:!1};case"excludePairExact":return{...w,excludePairExact:!1};case"excludeCharacters":return{...w,excludeCharacters:[]};case"excludeFandoms":return{...w,excludeFandoms:[]};case"excludeCategoryFilter":return{...w,excludeCategoryFilter:[]};case"excludeWarnings":return{...w,excludeWarnings:[]};case"lastReadAfter":return{...w,lastReadAfter:""};case"lastReadBefore":return{...w,lastReadBefore:""};default:return w}})},[kt,ee]),is=r.useCallback(()=>{oe(""),G(""),Rt(),kt()},[kt,Rt]),nn=r.useCallback(()=>{oe(""),G(""),Rt()},[Rt]),rt=r.useMemo(()=>no(W,U),[W,U]),zo=V.activeViewItem?[]:rt,os=r.useMemo(()=>rt.map(h=>({id:h.id,label:ff(h.id,h.label),value:vf(h.id,h.value),ariaLabel:`${h.ariaLabel} filter`,onRemove:()=>zt(h.id)})),[rt,zt]),qo=r.useMemo(()=>[...V.toolbarChip?[V.toolbarChip]:[],...V.activeViewItem?[]:os],[V.activeViewItem,V.toolbarChip,os]),ls=r.useMemo(()=>Yr({search:se,sort:E,filters:W}),[se,E,W]),sn=Pe>=xt,Go=Pe>xt,Qo=typeof Le=="number"&&Le>=Fr-2&&!sn,cs=dg({accountLoading:De,isPro:M,nearCap:Qo,atCap:sn}),ds=K.show&&Le>0&&!De&&!D&&!H&&!T.show&&!ne.bulkMode&&!cs,qt=r.useMemo(()=>{const h={};return Ae.forEach(w=>h[w.id]=w),h},[Ae]),ja=h=>qt[h],us=h=>{const w=Ee[h.storyId];return typeof w?.chapters_published=="number"?w.chapters_published:void 0},Xo=Ze.useCallback(async h=>{const w=qt[h],B=w?Ee[w.storyId]:void 0,ue=w&&B?ii(B,w):null;if(!ue){Ce("No source URL to copy");return}try{await navigator.clipboard.writeText(ue),Ce("Story link copied")}catch{Ce("Could not copy story link")}},[qt,Ee,Ce]),Zo=Ze.useCallback((h,w)=>{const B=qt[h];if(!B){Yt(h,{status:w});return}const ue=Ee[B.storyId],_e=hi(B,ue,w),Gt=Yt(h,_e);if(_e.progress?.value,w==="FINISHED"&&B.status!=="FINISHED"){const Sa=Ac(B);Ce("Finished today",5e3,{label:"Undo",onClick:async()=>{await Gt.catch(()=>{}),await Yt(h,Sa).catch(()=>{}),Ce("Completion undone")}})}},[qt,Ee,Yt,ge,nt?.id,Ce]),Jo=h=>{const w=ja(h);if(!w||w.progress.unit!=="CHAPTER")return;const B=w.progress.total??us(w)??1/0,ue=Math.min((w.progress.value||0)+1,typeof B=="number"?B:1/0);ue!==(w.progress.value||0)&&bt(h,{progress:{...w.progress,value:ue}})},el=h=>{const w=ja(h);if(!w||w.progress.unit!=="CHAPTER")return;const B=Math.max((w.progress.value||0)-1,0);B!==(w.progress.value||0)&&bt(h,{progress:{...w.progress,value:B}})},[Na,ms]=r.useState(null),tl=async h=>{try{await t.startReread(h),Ce("Starting re-read!"),y(!1)}catch(w){Ce("Failed to start re-read"),console.error(w)}ms(null)},al=(h,w)=>{const B=ja(h);if(!B||B.progress.unit!=="CHAPTER")return;const ue=B.progress.total??us(B)??void 0;let _e=Math.max(0,Number(w)||0);typeof ue=="number"&&(_e=Math.min(_e,ue)),_e!==(B.progress.value||0)&&bt(h,{progress:{...B.progress,value:_e}})},ps=r.useRef(!1);r.useEffect(()=>{ps.current&&!ge&&xa(),ps.current=ge},[ge,xa]),r.useEffect(()=>()=>xa(),[xa]);const nl=q?V.sheetMode==="save"?e.jsx(Fs,{title:V.saveAsNew?"Save as new":"Save current view",description:"Private saved query"}):V.sheetMode==="manage"?e.jsx(Fs,{title:"Manage views",description:"Pin, rename, and remove saved queries"}):e.jsx(Yc,{activeChips:rt,onResetAll:nn,resultCount:Me,totalCount:Pe}):null,sl=q?V.sheetMode==="save"?e.jsx(Pi,{capturedQuery:V.capturedQuery,saveAsNew:V.saveAsNew,activeView:V.activeViewItem,existingNames:V.viewItems.map(h=>h.name),isPending:V.createLibraryView.isPending,errorMessage:V.mutationState.errorMessage,showHeader:!1,onClose:V.handlers.onClosePanel,onSave:h=>V.handlers.onSaveView?.(h)}):V.sheetMode==="manage"?e.jsx(Mi,{views:V.viewItems,activeViewId:V.activeViewItem?.id??null,allLibraryCount:Pe,mutationState:V.mutationState,showHeader:!1,onClose:V.handlers.onClosePanel,onSelectView:V.handlers.onSelectView,onTogglePin:V.handlers.onTogglePin,onRenameView:V.handlers.onRenameView,onDeleteView:V.handlers.onDeleteView,onMoveView:V.handlers.onMoveView}):e.jsxs(e.Fragment,{children:[e.jsx(Yd,{views:V.viewItems,activeViewId:V.activeViewId,dirty:V.dirty,hasAdHocQuery:V.hasAdHocQuery,isError:V.viewsQuery.isError,isLoading:V.viewsQuery.isLoading,allLibraryCount:Pe,visibleCount:Me,activeFilterCount:rt.length,zeroResultView:!!(V.activeViewItem&&!Kt&&!H&&Me===0),mutationState:V.mutationState,handlers:V.handlers}),e.jsx(sd,{storyUpdatesEnabled:Tt,filters:W,onChange:ee,searchValue:U,onSearchChange:oe,activeChips:rt,onClearActiveFilter:zt,onClearAllActiveFilters:nn,visibleCount:Me})]}):null,hs=Me===0,rl=q&&V.sheetMode==="refine"?{onReset:nn,applyLabel:hs?"Show 0 results":`Show ${Me.toLocaleStr
6ing()}`,applyDisabled:hs}:null,il=ne.bulkMode||Te||He||q||st.open||es||!!Na||Jn;return e.jsxs(e.Fragment,{children:[e.jsxs(Nl,{children:[e.jsx("title",{children:"trace — My Library"}),e.jsx("meta",{name:"robots",content:"noindex, nofollow"})]}),e.jsxs(bl,{className:"archive-editorial-shell",mobileDockHidden:il,children:[ne.bulkMode&&e.jsx(Yb,{selectedCount:ne.selectedCount,visibleCount:he.length,loadedCount:Ae.length,totalCount:Le,onSelectAllVisible:ne.selectAllVisible,onSelectAllLibrary:ne.selectAllLoaded,onClearSelection:ne.clearSelection,onBulkSetStatus:ne.bulkSetStatus,onBulkCatchUp:ne.bulkCatchUp,bulkTag:ne.bulkTag,onBulkTagChange:ne.setBulkTag,allTags:Qn,onBulkAddTag:ne.bulkAddTag,onBulkRemoveTag:ne.bulkRemoveTag,selectedEntries:ne.selectedEntries,onExitBulkMode:()=>ne.setBulkMode(!1),onAddToCollection:()=>st.openForEntries(ne.selectedEntries),onShare:()=>{Ga("selected"),F("share")},onBulkRemove:ne.bulkRemove,bulkRemoving:ne.bulkRemoving}),e.jsxs("div",{className:"library-main-canvas","data-advocacy-prompt-blocker":D||H||T.show||ds?"":void 0,children:[e.jsx(Hg,{pullPx:jt.pullPx,refreshing:jt.refreshing}),Wo?e.jsx("div",{className:"relative z-0",children:e.jsx(hc,{eyebrow:"Reading archive",className:L("relative z-[1]",s&&"max-sm:hidden"),title:"Library.",titleId:"library-page-heading",stats:Bo,mobileStatLimit:2,density:"compact",spacing:"ledger"})}):null,_t?e.jsx(Hd,{views:V.viewItems,activeViewId:V.activeViewId,dirty:V.activeViewItem?V.dirty:V.hasAdHocQuery,hasAdHocQuery:V.hasAdHocQuery,isError:V.viewsQuery.isError,isLoading:V.viewsQuery.isLoading,allLibraryCount:Pe,visibleCount:Me,activeFilterCount:rt.length,zeroResultView:!!(V.activeViewItem&&!Kt&&!H&&Me===0),capturedQuery:V.capturedQuery,panelMode:V.desktopPanelMode,saveAsNew:V.desktopSaveAsNew,mutationState:V.mutationState,handlers:V.desktopHandlers}):null,e.jsxs("div",{className:L("relative mx-auto w-full max-w-7xl px-4 sm:px-6 sm:pb-10 lg:px-8 xl:max-w-[96rem]","pb-10",ne.bulkMode&&"pb-56 sm:pb-44"),children:[e.jsx("div",{className:"relative",children:cs&&e.jsx(lg,{atCap:sn,overCap:Go,totalCount:Pe})}),ds?e.jsx(cg,{pending:K.pending,error:K.error,onDismiss:K.dismiss}):null,null,null,_t?e.jsxs(xg,{stickyChromeRef:Zn,sticky:s,stickyTopClass:s?"top-0":"top-[54px]",runtime:an,chromeState:rs,showFilters:q,visibleCount:Me,onCloseFilters:V.closeSheet,mobileFiltersHeader:nl,mobileFiltersBody:sl,mobileFiltersFooter:rl,filtersPanel:q?e.jsx(As,{storyUpdatesEnabled:Tt,id:"filters-panel-overlay",variant:"overlay",filters:W,onChange:ee,onReset:Rt}):null,children:[e.jsx(yu,{storyUpdatesEnabled:Tt,variant:"sticky",totalCount:Pe,resultCount:Me,bulkMode:ne.bulkMode,onToggleBulk:()=>ne.setBulkMode(h=>!h),canAdd:!ne.bulkMode,onAdd:ma,selectedCount:ne.selectedCount,visibleCount:he.length,onShare:()=>{Ga(ne.selectedCount?"selected":"visible"),F("share")},canCreateCollectionFromTags:Le>0,canCreateCollectionFromCurrentFilter:Le>0,onCreateCollectionFromTags:()=>st.openForTags({query:ls,totalCount:Le}),onCreateCollectionFromCurrentFilter:()=>st.openForCurrentFilter({query:ls,totalCount:Le,activeFilterCount:Ct}),searchValue:U,onSearchChange:oe,onClearSearch:()=>{oe(""),G(""),kt()},searchRef:ss,sort:E,onSortChange:X,showFilters:q,onToggleFilters:Ko,activeFilterCount:Ct,filtersPanelId:"filters-panel-overlay",mobileChips:qo,mobileRuntime:an,mobileChromeState:rs,mobilePresentation:s?"nativeCompact":"default",mobileTitle:e.jsxs(e.Fragment,{children:["Library",e.jsx("span",{className:"text-[var(--rust)]",children:"."})]}),mobileTitleAriaLabel:"Library.",mobileStats:Vo,mobileCollapsedStats:Ho,onMobileSearchActiveChange:f,densityMode:le,onDensityModeChange:h=>{ae(h),h==="compact"&&ce(null)},groupingMode:P,onGroupingModeChange:re}),e.jsx("div",{className:L("max-sm:hidden","xl:hidden"),children:e.jsx(Xb,{chips:zo,onClear:zt,onClearAll:is})})]}):null,e.jsxs("div",{className:L("relative",_t&&"xl:grid xl:grid-cols-[minmax(0,1fr)_20.375rem] xl:items-start xl:gap-8 xl:pt-6"),children:[e.jsxs("div",{className:L("min-w-0",ga),children:[!Kt&&!H&&he.length>0&&T.show&&e.jsx(Qb,{step:T.step,pending:T.pending,error:T.error,onAdvance:T.advance,onDismiss:T.dismiss,onComplete:T.complete}),e.jsxs("div",{className:"relative min-w-0",children:[q&&e.jsx("button",{type:"button",className:"absolute inset-0 z-[38] hidden cursor-default border-0 bg-[color-mix(in_oklab,var(--content-primary)_6%,transparent)] p-0 sm:block xl:hidden","aria-label":"Close filters",onClick:V.closeSheet}),e.jsx("div",{className:"relative",children:tn?e.jsx("div",{className:"mx-auto w-full max-w-5xl px-4 pb-28 pt-4 sm:px-1 sm:pb-12 sm:pt-8","aria-busy":"true","aria-label":"Loading library",children:e.jsx("div",{className:"min-h-[32rem] 
6sm:min-h-[28rem]","aria-hidden":"true"})}):e.jsx(Oh,{storyUpdatesEnabled:Tt,gridRef:No,isLoading:Kt,isFetching:ye.fetchStatus==="fetching",isError:H,visible:he,storiesMap:Ee,activeFilterCount:Ct,debouncedSearch:se,bulkMode:ne.bulkMode,isSelected:ne.isSelected,onToggleSelect:ne.toggleOne,onStartBulkSelect:h=>{ce(null),ne.bulkMode||ne.setBulkMode(!0),ne.isSelected(h)||ne.toggleOne(h)},onRemoveEntry:Co,removingEntryId:qa,onOpenDetails:async h=>{ce(null),ve();const w=`${c.pathname}${c.search}`;await gl({entryId:h,source:"library",returnTo:w})||`${window.location.pathname}${window.location.search}`===w&&o(`/library/${h}`,{state:{libraryReturnTo:w}})},onChangeStatus:Zo,onIncrementChapter:Jo,onDecrementChapter:el,onSetChapterValue:al,onChangeRating:(h,w)=>Yt(h,{rating:w}),onChangeNotes:(h,w)=>bt(h,{notes:w}),onChangeTags:(h,w)=>bt(h,{tags:w}),onAddToCollection:h=>{const w=ja(h);w&&st.openForEntry(w,Ee[w.storyId])},onShareStory:Xo,onLayoutPointerLockChange:vo,deferredRecencyReorderIds:yo,onDeferredRecencyEntryExit:wo,mostRecentReadingEntryId:jo,densityMode:le,groupingMode:P,evaluatingEntryId:me,onStartEvaluate:ce,onCloseEvaluate:()=>ce(null),loadMoreRef:ha,hasNextPage:!!Ne,isFetchingNextPage:Ie,onFetchNextPage:Ge,onAddManually:ma,firstStoryCompleted:!!pe?.first_story_completed_at,onRetry:()=>ye.refetch(),splitDetailOpen:ga})})]})]}),ga,_t&&!ga&&e.jsx("aside",{className:L("hidden xl:block xl:self-start",a&&"pt-2"),"aria-label":"Library filters",children:e.jsx(As,{storyUpdatesEnabled:Tt,id:"filters-panel-rail",variant:"rail",filters:W,onChange:ee,onReset:Rt,resultCount:Me,totalCount:Pe,activeChips:rt,onClearActiveFilter:zt,onClearAllActiveFilters:is})})]})]})]}),e.jsx(ui,{open:Te,title:"Add a story manually",onClose:A,variant:"library",size:"lg",desktopPresentation:"sheet",desktopBackdrop:"transparent",hideHeader:!0,hideHeaderClose:!0,hideFooter:!0,panelClassName:pi.addStory,bodyClassName:mi,children:e.jsx(Ql,{onManualAdd:tt,adding:z,addError:te,onClose:A})}),e.jsx(rb,{open:He,onClose:A,selectedCount:ne.selectedCount,visibleCount:he.length,tagShareCount:Za,shareTotalCount:Po,getEntriesForShareBatch:Mo,storiesMap:Ee,shareSource:Xe,onChangeShareSource:Ga,allTags:Qn,shareTags:Qa,onChangeShareTags:_o,shareTagMatchMode:Xa,onChangeShareTagMatchMode:Ro,shareTitle:Lo,onChangeShareTitle:Ao,shareOpts:To,onChangeShareOpts:Eo,onToast:h=>Ce(h)}),Jn,e.jsx(Tc,{open:st.open,target:st.target,onClose:st.close,onSuccess:h=>Ce(h,4500)}),e.jsx($t,{open:es,title:"Remove from library",description:"Remove this story from your library? This can't be undone.",confirmLabel:"Remove",variant:"danger",loading:So,onConfirm:ko,onCancel:()=>ts(!1)}),e.jsx($t,{open:!!Na,title:"Starting a re-read?",description:"This will reset your progress and start a new read-through. Your previous reading history will be saved.",confirmLabel:"Start re-read",onConfirm:()=>{Na&&tl(Na)},onCancel:()=>ms(null)}),e.jsx(Kb,{onCancel:ne.cancelBulkFinished,onConfirm:ne.confirmBulkFinished,open:ne.bulkFinishPending}),e.jsx(Ec,{message:go,action:fo})]})]})}export{qf as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.