@fudanda/admin-antd 1.20261015.1-beta.1 → 2.20261024.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +58 -42
- package/THIRD_PARTY_NOTICES.md +55 -55
- package/dist/automation.js +3 -3
- package/dist/chunks/App-DNjXLysb.js +79 -0
- package/dist/chunks/{AppModal-B_xvSaeq.js → AppModal-DJzQA6FR.js} +1 -1
- package/dist/chunks/ArcBaseAdmin-BZrHGq2f.js +1 -0
- package/dist/chunks/ConfigurableTable-DzmZDd8F.js +55 -0
- package/dist/chunks/{DashboardPage-BTLufKzi.js → DashboardPage-BohGodSl.js} +1 -1
- package/dist/chunks/DataScopePanel-B2-x8Jcz.js +1 -0
- package/dist/chunks/{DateTimeText-rk9NeYgA.js → DateTimeText-CIt0Qy45.js} +1 -1
- package/dist/chunks/DepartmentsPage-DMWY__Y_.js +1 -0
- package/dist/chunks/DictTag-2-adKbYg.js +1 -0
- package/dist/chunks/DictsPage-DILDyHi-.js +15 -0
- package/dist/chunks/EditFormModal-DNHOZHxM.js +1 -0
- package/dist/chunks/EntityContextRuntime-DMklAv-k.js +1 -0
- package/dist/chunks/{EntityContextRuntime-BrAz-aCV.js → EntityContextRuntime-sslBZqYD.js} +1 -1
- package/dist/chunks/{EntityRelationButton-C8Cl8wyh.js → EntityRelationButton-DWn1rC2J.js} +2 -2
- package/dist/chunks/{ExportButton-D4IvZKHy.js → ExportButton-AzH4D0oW.js} +1 -1
- package/dist/chunks/FileNameCell-DPyi64Rv.js +1 -0
- package/dist/chunks/FileStorageConfigsPage-CzuOgeK0.js +15 -0
- package/dist/chunks/FileTypeIcon-DIih3XQG.js +1 -0
- package/dist/chunks/{FileViewerPreviewPanel-wbXzgqxc.js → FileViewerPreviewPanel-CMqVtGCr.js} +2 -2
- package/dist/chunks/FilesPage-BaEBCOCs.js +43 -0
- package/dist/chunks/IdentitySecurityPage-BO7nY8id.js +1 -0
- package/dist/chunks/{JsonPreviewPanel-D8YpZD1A.js → JsonPreviewPanel-Dhbza-Uu.js} +1 -1
- package/dist/chunks/LogStatsScaffold-CLycj3da.js +1 -0
- package/dist/chunks/LoginLogsPage-DTmHi8u0.js +1 -0
- package/dist/chunks/LoginLogsTable-DVmHnC6V.js +1 -0
- package/dist/chunks/{MasterDetailLayout-DDVFodpX.js → MasterDetailLayout-sjPWw8BI.js} +2 -2
- package/dist/chunks/{MemberAssignmentSheet-NWm5vThg.js → MemberAssignmentSheet-Czbt6_zv.js} +1 -1
- package/dist/chunks/MenuCommandPalette-BCOzf-Kq.js +8 -0
- package/dist/chunks/MenusPage-DN8DTGB1.js +1 -0
- package/dist/chunks/{ModalFooter-vXDpmYTM.js → ModalFooter-RMlvqrO9.js} +1 -1
- package/dist/chunks/NavListPanel-vjIOIqK0.js +1 -0
- package/dist/chunks/OnlineSessionsPage-FoHYZKlR.js +1 -0
- package/dist/chunks/OperationLogsPage-BeRnGcBJ.js +1 -0
- package/dist/chunks/OperationLogsTable-COI-Lp-y.js +1 -0
- package/dist/chunks/PDFPreviewPanel-BIQuBnZZ.js +37 -0
- package/dist/chunks/PasswordInput-DGEJO9yx.js +1 -0
- package/dist/chunks/PositionsPage-DohI0luX.js +1 -0
- package/dist/chunks/PreferencesSheetBody-B9niQABW.js +43 -0
- package/dist/chunks/ProfilePage-CVTRv7xb.js +15 -0
- package/dist/chunks/RelationPanel-B1X6AVaM.js +36 -0
- package/dist/chunks/RolesPage-CtUw93L8.js +1 -0
- package/dist/chunks/{SearchToolbar-BAh56OAa.js → SearchToolbar-CvgYKUjr.js} +1 -1
- package/dist/chunks/{SessionClientTag-DafwXf-o.js → SessionClientTag-DIwnYodW.js} +2 -2
- package/dist/chunks/SessionConflictModal-BLNuDsN_.js +1 -0
- package/dist/chunks/SettingRow-DVNmTJWC.js +1 -0
- package/dist/chunks/SettingsPage-BRnCxYQm.js +26 -0
- package/dist/chunks/StatCard-Czjfs0fa.js +4 -0
- package/dist/chunks/{UserDisplay-BYhcfa84.js → UserDisplay-J0Re8z-7.js} +1 -1
- package/dist/chunks/UserGroupsPage-CNwbejx-.js +1 -0
- package/dist/chunks/{UserLogsPanels-3ZlKQsCu.js → UserLogsPanels-BHeSxWrk.js} +2 -2
- package/dist/chunks/UserTransferSelect-CAeyxdor.js +22 -0
- package/dist/chunks/UsersPage-BXt9fOru.js +36 -0
- package/dist/chunks/{archive-D0BSMQmn.js → archive-B_IKvysI.js} +4 -4
- package/dist/chunks/chart-data-DImT_Mzn.js +5 -0
- package/dist/chunks/{chart-renderer-BWLqOvLF.js → chart-renderer-k-Rd8vdL.js} +1 -1
- package/dist/chunks/{user-cC0uCe3d.js → chevron-right-EBApfX6q.js} +2 -2
- package/dist/chunks/{clipboard-BKPNFY58.js → clipboard-ERcMSMRH.js} +1 -1
- package/dist/chunks/{confirm-CC2F8XXe.js → confirm-BtBBEqk8.js} +1 -1
- package/dist/chunks/{data-DPCozzrG.js → data-B05HzECj.js} +1 -1
- package/dist/chunks/{deleteAction-NGTDhZud.js → deleteAction-CCocr5uV.js} +1 -1
- package/dist/chunks/{diagram-vBbcsoK2.js → diagram-D9cwc7QH.js} +3 -3
- package/dist/chunks/dist-Bauqz5on.js +1 -0
- package/dist/chunks/{drawing-CUAfa3D5.js → drawing-D2Qrun-P.js} +2 -2
- package/dist/chunks/{email-U025DuXM.js → email-ByshRsFv.js} +2 -2
- package/dist/chunks/{export-CCaKk9VN.js → export-DlTz5dc2.js} +5 -5
- package/dist/chunks/{eye-DNBTmA6c.js → eye-off-BtJoIT5n.js} +1 -8
- package/dist/chunks/feedback-BnjMKZpz.js +1 -0
- package/dist/chunks/file-utils-DyvnVEoH.js +1 -0
- package/dist/chunks/fit-CsnhEncA.js +1 -0
- package/dist/chunks/{form-DhQiOMvp.js → form-CQutQFiD.js} +1 -1
- package/dist/chunks/geo-DR0fL7r2.js +38 -0
- package/dist/chunks/{image-C52XMTxg.js → image-ez9hvzKT.js} +1 -1
- package/dist/chunks/{lib-DZsU27Fn.js → lib-BlRm3nk1.js} +4 -4
- package/dist/chunks/line-BV7qVRkM.js +1 -0
- package/dist/chunks/{msg-DNXH9mKo.js → msg-BzZbudMm.js} +1 -1
- package/dist/chunks/{ofd-B0_-rey2.js → ofd-C7DKqJ6Z.js} +1 -1
- package/dist/chunks/{openDocument-DW7w0HpR.js → openDocument-DGzqlyJg.js} +1 -1
- package/dist/chunks/parse-6ZQGx714.js +1 -0
- package/dist/chunks/{parser-BFNqF7wU.js → parser-DC3PvpL4.js} +1 -1
- package/dist/chunks/ppt-B0WY5Gks.js +30 -0
- package/dist/chunks/pptx-DX5KDFZ7.js +109 -0
- package/dist/chunks/{print-mask-DTiml6Ox.js → print-mask-Dguzv0rv.js} +2 -2
- package/dist/chunks/{psd-yU36O76Y.js → psd-hjeNFQZ-.js} +1 -1
- package/dist/chunks/{search-filters-BoRMIesR.js → search-filters-CRIhZ0gL.js} +1 -1
- package/dist/chunks/spreadsheet-BzbBEhmY.js +1 -0
- package/dist/chunks/{spreadsheet-DiZ31XlH.js → spreadsheet-LR3SOG-x.js} +3 -3
- package/dist/chunks/toolbar-controls-CThS0xuP.js +15 -0
- package/dist/chunks/ui-BFsHoY7a.js +1 -0
- package/dist/chunks/{useCrudOperationColumn-PObQMk2y.js → useCrudOperationColumn-D935tixd.js} +1 -1
- package/dist/chunks/useListPage-CbcOQG4m.js +1 -0
- package/dist/chunks/{useStatusToggle-B7KSIN75.js → useStatusToggle-B2qZaoc-.js} +1 -1
- package/dist/chunks/wordDoc-BZY3ZnxN.js +152 -0
- package/dist/chunks/wordDocx-Bt2mlB3C.js +77 -0
- package/dist/chunks/{xmind-B9BtGBNI.js → xmind-CF9YwkOD.js} +2 -2
- package/dist/file-viewer/flyfish-viewer-assets.json +5 -5
- package/dist/file-viewer/vendor/docx/jszip.min.js +0 -0
- package/dist/file-viewer/wasm/data/sql-wasm.wasm +0 -0
- package/dist/index.js +1 -1
- package/dist/{src-DVwjbBTf.js → src-LbWcrSWe.js} +1 -1
- package/dist/styles.css +1 -1
- package/package.json +7 -7
- package/dist/chunks/App-DX7JOOmP.js +0 -79
- package/dist/chunks/ArcBaseAdmin-CdB_roNY.js +0 -1
- package/dist/chunks/ConfigurableTable-CyfZLgG0.js +0 -55
- package/dist/chunks/DataScopePanel-CubtBhTT.js +0 -1
- package/dist/chunks/DepartmentsPage-ECexbzsK.js +0 -1
- package/dist/chunks/DictTag-BerYvaUM.js +0 -1
- package/dist/chunks/DictsPage-65kAxYFd.js +0 -15
- package/dist/chunks/DirectoryLoginModal-rRXvoqV7.js +0 -1
- package/dist/chunks/EditFormModal-D68dOnaj.js +0 -1
- package/dist/chunks/EntityContextRuntime-D9mWi5xC.js +0 -1
- package/dist/chunks/FileNameCell-C_V1k0q-.js +0 -1
- package/dist/chunks/FilePreviewModal-D7v5seXB.js +0 -1
- package/dist/chunks/FileStorageConfigsPage-D2UYESb5.js +0 -15
- package/dist/chunks/FileTypeIcon-C77EVWXZ.js +0 -1
- package/dist/chunks/FilesPage-By81A2i7.js +0 -43
- package/dist/chunks/ForgotPasswordModal-DTlunJpM.js +0 -1
- package/dist/chunks/IdentitySecurityPage-Dp5EP7aT.js +0 -1
- package/dist/chunks/LogStatsScaffold-BFwbN_MU.js +0 -1
- package/dist/chunks/LoginField-Bu4C0-Mk.js +0 -1
- package/dist/chunks/LoginLogsPage-BuMJ6U8I.js +0 -1
- package/dist/chunks/LoginLogsTable-DfAlWPZb.js +0 -1
- package/dist/chunks/MenuCommandPalette-BvW2kEU4.js +0 -8
- package/dist/chunks/MenusPage-DT3kxAfi.js +0 -1
- package/dist/chunks/NavListPanel-agMt2kc6.js +0 -1
- package/dist/chunks/OnlineSessionsPage-BJJAB2pV.js +0 -1
- package/dist/chunks/OperationLogsPage-CP-wUt_N.js +0 -1
- package/dist/chunks/OperationLogsTable-BX0vV3fT.js +0 -1
- package/dist/chunks/PDFPreviewPanel-D8-74Zqs.js +0 -30
- package/dist/chunks/PasswordInput--G8GKd5g.js +0 -1
- package/dist/chunks/PositionsPage-Cs7xq89s.js +0 -1
- package/dist/chunks/PreferencesSheetBody-CdA4Ig_g.js +0 -43
- package/dist/chunks/ProfilePage-Bt3yP6D-.js +0 -15
- package/dist/chunks/RelationPanel-B-KAfl9B.js +0 -36
- package/dist/chunks/RolesPage-DDNGkGAq.js +0 -1
- package/dist/chunks/SessionConflictModal-DgFNCU3j.js +0 -1
- package/dist/chunks/SettingRow-BIb1ruW2.js +0 -1
- package/dist/chunks/SettingsPage-rhqkPOJ9.js +0 -16
- package/dist/chunks/StatCard-BwhGDWpE.js +0 -4
- package/dist/chunks/UserGroupsPage-D3_aji58.js +0 -1
- package/dist/chunks/UserTransferSelect-S-GUw2Y9.js +0 -1
- package/dist/chunks/UsersPage-CLRJX-V9.js +0 -29
- package/dist/chunks/WorkflowPrintButton-BVa-xw-8.js +0 -1
- package/dist/chunks/chart-data-DOMSCLwj.js +0 -5
- package/dist/chunks/chevron-left-DnDEG_PI.js +0 -8
- package/dist/chunks/chevron-right-CzizTV5i.js +0 -8
- package/dist/chunks/dist-BqNhxPp5.js +0 -1
- package/dist/chunks/feedback-D4BIfDNd.js +0 -1
- package/dist/chunks/file-utils-DJ9ksj-g.js +0 -1
- package/dist/chunks/geo-Bf8ymo43.js +0 -38
- package/dist/chunks/line-DSFA8EqT.js +0 -1
- package/dist/chunks/mail-Cduf1OFr.js +0 -8
- package/dist/chunks/mono-icons-CxCoktev.js +0 -1
- package/dist/chunks/plus-Bvdn6bx1.js +0 -8
- package/dist/chunks/ppt-C9RgrmNU.js +0 -30
- package/dist/chunks/pptx-_T8ZPVQn.js +0 -109
- package/dist/chunks/printer-DL8WQci4.js +0 -8
- package/dist/chunks/shield-check-DZGK8n9u.js +0 -8
- package/dist/chunks/spreadsheet-CHFSQY8j.js +0 -1
- package/dist/chunks/table-columns-XaoxVUJN.js +0 -1
- package/dist/chunks/toolbar-controls-BFOuV86W.js +0 -8
- package/dist/chunks/ui-DoIHGuTR.js +0 -1
- package/dist/chunks/useDebouncedValue-DFoJN77o.js +0 -22
- package/dist/chunks/useListPage-1Upr_ala.js +0 -1
- package/dist/chunks/wordDoc-CtetBfzo.js +0 -152
- package/dist/chunks/wordDocx-8ak39HcF.js +0 -77
- package/dist/chunks/zoom-8Eo2fTNd.js +0 -1
- package/dist/public/monaco/vs/editor/editor.worker.js +0 -1
- package/dist/public/monaco/vs/language/css/css.worker.js +0 -66
- package/dist/public/monaco/vs/language/html/html.worker.js +0 -443
- package/dist/public/monaco/vs/language/json/json.worker.js +0 -17
- package/dist/public/monaco/vs/language/typescript/ts.worker.js +0 -67693
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-BKuNeK48.js";import{n as t,t as n}from"./preload-helper-C-73SErw.js";import{o as r}from"./controls-C5dPckUT.js";import{t as i}from"./typography-DKK_iHcj.js";import{n as a,t as o}from"./createLucideIcon-BtwfYE6A.js";import{n as s,t as c}from"./chevron-left-DnDEG_PI.js";import{n as l,t as u}from"./chevron-right-CzizTV5i.js";import{n as d,t as f}from"./download--5IybXxz.js";import{n as p,t as m}from"./printer-DL8WQci4.js";import{n as h,t as g}from"./rotate-cw-BSTVLlWY.js";import{n as _,t as v}from"./x-Ak9hw1R9.js";import{a as y,w as b}from"./ui-DoIHGuTR.js";import{C as x,D as S,E as ee,F as C,H as te,J as ne,O as w,P as T,U as re,W as ie,X as ae,Y as oe,b as E,h as D,k as se,r as ce}from"./dist-CWj_XYki.js";import{n as le,r as ue}from"./theme-controller-D-ATwFal.js";import{n as de,t as fe}from"./FileTypeIcon-C77EVWXZ.js";import{Fragment as pe,createContext as me,useCallback as he,useContext as ge,useEffect as O,useId as _e,useLayoutEffect as ve,useMemo as k,useRef as A,useState as j}from"react";import{Fragment as ye,jsx as M,jsxs as N}from"react/jsx-runtime";import be from"react-dom";var xe,Se;function Ce(){return(Ce=e((()=>{
|
|
2
|
-
/**
|
|
3
|
-
* @license lucide-react v1.53.0 - ISC
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the ISC license.
|
|
6
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
a(),xe={name:`hand`,size:24,node:[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]},xe.node,Se=o(xe)})))()}var we,Te;function Ee(){return(Ee=e((()=>{
|
|
9
|
-
/**
|
|
10
|
-
* @license lucide-react v1.53.0 - ISC
|
|
11
|
-
*
|
|
12
|
-
* This source code is licensed under the ISC license.
|
|
13
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
14
|
-
*/
|
|
15
|
-
a(),we={name:`maximize-2`,size:24,node:[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`m21 3-7 7`,key:`1l2asr`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M9 21H3v-6`,key:`wtvkvv`}]]},we.node,Te=o(we)})))()}var De,Oe;function ke(){return(ke=e((()=>{
|
|
16
|
-
/**
|
|
17
|
-
* @license lucide-react v1.53.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/
|
|
22
|
-
a(),De={name:`minimize-2`,size:24,node:[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]},De.node,Oe=o(De)})))()}var Ae,je;function Me(){return(Me=e((()=>{
|
|
23
|
-
/**
|
|
24
|
-
* @license lucide-react v1.53.0 - ISC
|
|
25
|
-
*
|
|
26
|
-
* This source code is licensed under the ISC license.
|
|
27
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
28
|
-
*/
|
|
29
|
-
a(),Ae={name:`panel-left`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]],aliases:[`sidebar`]},Ae.node,je=o(Ae)})))()}function Ne(e,t){if(!e)return;if(t in e)return e[t];let n=Dt[t];if(n&&n in e)return e[n]}function Pe(e,t,n){let r=e.documents[t],i=r?.permissions,a=e.globalPermissions,o=r?.document?.permissions??E.AllowAll,s=Ne(i?.overrides,n);if(s!==void 0)return s;let c=Ne(a?.overrides,n);return c===void 0?i?.enforceDocumentPermissions??a?.enforceDocumentPermissions??!0?(o&n)!==0:!0:c}function Fe(e,t){return Et.reduce((n,r)=>Pe(e,t,r)?n|r:n,0)}function Ie(e,t,n){let r=e.activeDocumentId;if(r!==t)return r;if(n!==void 0)return n&&e.documents[n]?n:null;let i=e.documentOrder.indexOf(t);return i===-1?null:i>0?e.documentOrder[i-1]:i<e.documentOrder.length-1?e.documentOrder[i+1]:null}function Le(e,t,n){let r=e.indexOf(t);if(r===-1||n<0||n>=e.length||r===n)return null;let i=[...e];return i.splice(r,1),i.splice(n,0,t),i}function P(e,t){return{package:e,config:t}}function Re(e){return`autoMountElements`in e&&typeof e.autoMountElements==`function`}function ze(e){return`keyExtractor`in e}function F(e,t,n){return e<t?t:e>n?n:e}function Be(e,t,n){if(e===t)return!0;if(e==null||t==null)return e===t;let r=typeof e;if(r!==typeof t)return!1;if(r===`object`){n||=/* @__PURE__ */ new Set;let r=Ve(e,t);if(n.has(r))return!0;n.add(r);let i=Array.isArray(e),a=Array.isArray(t);return i&&a?Ue(e,t,n):!i&&!a&&We(e,t,n)}return!1}function Ve(e,t){return`${He(e)}__${He(t)}`}function He(e){return Nt.has(e)||Nt.set(e,++Mt),Nt.get(e)}function Ue(e,t,n){if(e.length!==t.length)return!1;let r=Array(t.length).fill(!1);outer:for(let i=0;i<e.length;i++){let a=e[i];for(let e=0;e<t.length;e++)if(!r[e]&&Be(a,t[e],n)){r[e]=!0;continue outer}return!1}return!0}function We(e,t,n){let r=Object.keys(e).sort(),i=Object.keys(t).sort();if(r.length!==i.length)return!1;for(let e=0;e<r.length;e++)if(r[e]!==i[e])return!1;for(let i of r){let r=e[i],a=t[i];if(!Be(r,a,n))return!1}return!0}function I(){let e=/* @__PURE__ */ new Set;return{emit:(t=void 0)=>e.forEach(e=>e(t)),on:t=>(e.add(t),()=>e.delete(t)),off:t=>e.delete(t),clear:()=>e.clear()}}function L(e,t=Be){let n=/* @__PURE__ */ new Set,r=/* @__PURE__ */ new Map,i=e,a=e=>n.forEach(t=>t(e)),o=(e,t)=>{let a=e,o=()=>{};if(t){if(ze(t)){let n=new jt(e,t);a=n.handle,o=()=>n.destroy()}else{let n=new At(e,t);a=n.handle,o=()=>n.destroy()}r.set(e,{wrapped:a,destroy:o})}return i!==void 0&&a(i),n.add(a),()=>{n.delete(a),o(),r.delete(e)}};return{get value(){return i},emit(e=void 0){(i===void 0||!t(i,e))&&(i=e,a(e))},on:o,off(e){let t=r.get(e);t?(n.delete(t.wrapped),t.destroy(),r.delete(e)):n.delete(e)},clear(){n.clear(),r.forEach(e=>e.destroy()),r.clear()},select(e,t=Be){return(n,r)=>{let a;if(i!==void 0){let t=e(i);a=t,n(t)}return o(r=>{let i=e(r);(a===void 0||!t(a,i))&&(a=i,n(i))},r)}}}}function R(e,t){let n=t?.cache??!0,r=t?.equality??Be,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Set,c=/* @__PURE__ */ new Map,l=e=>String(e),u=e=>{let t=a.get(e);return t||(t=/* @__PURE__ */ new Set,a.set(e,t)),t},d=e=>{let t=o.get(e);return t||(t=/* @__PURE__ */ new Map,o.set(e,t)),t};return{emit(t,o){let c=l(t);if(n){let e=i.get(c);if(e!==void 0&&r(e,o))return;i.set(c,o)}let u=a.get(c);u&&u.forEach(e=>e(o));let d=e(t,o);s.forEach(e=>e(d))},forScope(e){let t=l(e);return(e,r)=>{let s=u(t),c=d(t),l=e,f=()=>{};if(r){if(ze(r)){let t=new jt(e,r);l=t.handle,f=()=>t.destroy()}else{let t=new At(e,r);l=t.handle,f=()=>t.destroy()}c.set(e,{wrapped:l,destroy:f})}if(n){let e=i.get(t);e!==void 0&&l(e)}return s.add(l),()=>{s.delete(l),f(),c.delete(e),s.size===0&&a.delete(t),c.size===0&&o.delete(t)}}},onGlobal:(e,t)=>{let n=e,r=()=>{};if(t){if(ze(t)){let i=new jt(e,t);n=i.handle,r=()=>i.destroy()}else{let i=new At(e,t);n=i.handle,r=()=>i.destroy()}c.set(e,{wrapped:n,destroy:r})}return s.add(n),()=>{s.delete(n),r(),c.delete(e)}},getValue(e){return n?i.get(l(e)):void 0},getScopes(){return n?Array.from(i.keys()):Array.from(a.keys())},clearScope(e){let t=l(e);n&&i.delete(t);let r=a.get(t);r&&(r.clear(),a.delete(t));let s=o.get(t);s&&(s.forEach(e=>e.destroy()),s.clear(),o.delete(t))},clear(){n&&i.clear(),a.forEach(e=>e.clear()),a.clear(),o.forEach(e=>{e.forEach(e=>e.destroy()),e.clear()}),o.clear(),s.clear(),c.forEach(e=>e.destroy()),c.clear()}}}function Ge(e){return new Pt(e)}var Ke,z,B,qe,Je,Ye,V,Xe,Ze,Qe,$e,et,tt,nt,rt,it,at,ot,st,ct,lt,ut,dt,ft,pt,mt,ht,gt,_t,vt,yt,bt,xt,St,Ct,wt,Tt,Et,Dt,Ot,kt,H,At,jt,Mt,Nt,Pt;function U(){return(U=e((()=>{C(),Ke=class{constructor(){this.dependencyGraph=/* @__PURE__ */ new Map}addNode(e,t=[]){this.dependencyGraph.set(e,new Set(t))}hasCircularDependencies(){let e=/* @__PURE__ */ new Set,t=/* @__PURE__ */ new Set,n=r=>{e.add(r),t.add(r);let i=this.dependencyGraph.get(r)||/* @__PURE__ */ new Set;for(let r of i)if(!e.has(r)){if(n(r))return!0}else if(t.has(r))return!0;return t.delete(r),!1};for(let t of this.dependencyGraph.keys())if(!e.has(t)&&n(t))return!0;return!1}resolveLoadOrder(){if(this.hasCircularDependencies())throw Error(`Circular dependencies detected`);let e=[],t=/* @__PURE__ */ new Set,n=/* @__PURE__ */ new Set,r=i=>{if(n.has(i))throw Error(`Circular dependency`);if(t.has(i))return;n.add(i);let a=this.dependencyGraph.get(i)||/* @__PURE__ */ new Set;for(let e of a)r(e);n.delete(i),t.add(i),e.push(i)};for(let e of this.dependencyGraph.keys())t.has(e)||r(e);return e}},z=class extends Error{constructor(e){super(e),this.name=`PluginRegistrationError`}},B=class extends Error{constructor(e){super(e),this.name=`PluginNotFoundError`}},qe=class extends Error{constructor(e){super(e),this.name=`CircularDependencyError`}},Je=class extends Error{constructor(e){super(e),this.name=`PluginConfigurationError`}},Ye=class{constructor(e,t){this.store=e,this.pluginId=t}getState(){return this.store.getState().plugins[this.pluginId]}dispatch(e){return this.store.dispatchToPlugin(this.pluginId,e)}subscribeToState(e){return this.store.subscribeToPlugin(this.pluginId,(t,n,r)=>{e(t,n,r)})}onAction(e,t){return this.store.onAction(e,(e,n,r)=>{t(e,n.plugins[this.pluginId],r.plugins[this.pluginId])})}},V=`START_LOADING_DOCUMENT`,Xe=`UPDATE_DOCUMENT_LOADING_PROGRESS`,Ze=`SET_DOCUMENT_LOADED`,Qe=`SET_DOCUMENT_ERROR`,$e=`RETRY_LOADING_DOCUMENT`,et=`CLOSE_DOCUMENT`,tt=`SET_ACTIVE_DOCUMENT`,nt=`REORDER_DOCUMENTS`,rt=`MOVE_DOCUMENT`,it=`UPDATE_DOCUMENT_SECURITY`,at=`REFRESH_DOCUMENT`,ot=`REFRESH_PAGES`,st=`SET_PAGES`,ct=`SET_SCALE`,lt=`SET_ROTATION`,ut=`SET_DEFAULT_SCALE`,dt=`SET_DEFAULT_ROTATION`,ft=[V,Xe,Ze,et,tt,Qe,$e,at,ot,st,ct,lt,ut,dt,nt,rt,it],pt=(e,t,n,r,i,a,o)=>({type:V,payload:{documentId:e,name:t,scale:n,rotation:r,passwordProvided:i,autoActivate:a,permissions:o}}),mt=(e,t)=>({type:Ze,payload:{documentId:e,document:t}}),ht=(e,t,n,r)=>({type:Qe,payload:{documentId:e,error:t,errorCode:n,errorDetails:r}}),gt=(e,t)=>({type:$e,payload:{documentId:e,passwordProvided:t}}),_t=(e,t)=>({type:et,payload:{documentId:e,nextActiveDocumentId:t}}),vt=e=>({type:tt,payload:e}),yt=(e,t)=>({type:ct,payload:{scale:e,documentId:t}}),bt=(e,t)=>({type:lt,payload:{rotation:e,documentId:t}}),xt=e=>({type:nt,payload:e}),St=(e,t)=>({type:rt,payload:{documentId:e,toIndex:t}}),Ct=(e,t,n)=>({type:it,payload:{documentId:e,permissions:t,isOwnerUnlocked:n}}),wt=class{constructor(e,t){this.initialCoreState=t,this.pluginReducers={},this.listeners=[],this.pluginListeners={},this.isDispatching=!1,this.state={core:t,plugins:{}},this.coreReducer=e}addPluginReducer(e,t,n){this.state.plugins[e]=n,this.pluginReducers[e]=t}dispatchToCore(e){if(!this.coreReducer)return this.getState();if(this.isDispatching)throw Error(`Reducers may not dispatch actions. To trigger cascading actions, dispatch from a listener callback instead.`);let t=this.getState();try{this.isDispatching=!0,this.state.core=this.coreReducer(this.state.core,e)}finally{this.isDispatching=!1}return this.listeners.forEach(n=>{n(e,this.getState(),t)}),this.getState()}dispatchToPlugin(e,t,n=!0){if(this.isDispatching)throw Error(`Reducers may not dispatch actions. To trigger cascading actions, dispatch from a listener callback instead.`);let r=this.getState(),i=this.pluginReducers[e];if(!i)return r.plugins[e];let a=r.plugins[e];try{this.isDispatching=!0;let n=i(a,t);this.state.plugins[e]=n}finally{this.isDispatching=!1}return n&&this.listeners.forEach(e=>{e(t,this.getState(),r)}),this.pluginListeners[e]&&this.pluginListeners[e].forEach(n=>{let r=this.getState().plugins[e];n(t,r,a)}),this.getState().plugins[e]}dispatch(e){if(this.isDispatching)throw Error(`Reducers may not dispatch actions. To trigger cascading actions, dispatch from a listener callback instead.`);let t=this.getState();try{this.isDispatching=!0,this.isCoreAction(e)&&(this.state.core=this.coreReducer(this.state.core,e));for(let n in this.pluginReducers){let r=this.pluginReducers[n],i=t.plugins[n];r&&(this.state.plugins[n]=r(i,e))}}finally{this.isDispatching=!1}return this.listeners.forEach(n=>{n(e,this.getState(),t)}),this.getState()}getState(){if(this.isDispatching)throw Error(`You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store.`);return{core:{...this.state.core},plugins:{...this.state.plugins}}}subscribe(e){if(this.isDispatching)throw Error(`You may not call store.subscribe() while the reducer is executing. If you would like to be notified after the store has been updated, subscribe from a component and invoke store.getState() in the callback to access the latest state.`);return this.listeners.push(e),()=>{if(this.isDispatching)throw Error(`You may not unsubscribe from a store listener while the reducer is executing.`);this.listeners=this.listeners.filter(t=>t!==e)}}subscribeToPlugin(e,t){if(!(e in this.state.plugins))throw Error(`Plugin state not found for plugin "${e}". Did you forget to call addPluginReducer?`);if(this.isDispatching)throw Error(`You may not call store.subscribeToPlugin() while the reducer is executing.`);return this.pluginListeners[e]||(this.pluginListeners[e]=[]),this.pluginListeners[e].push(t),()=>{if(this.isDispatching)throw Error(`You may not unsubscribe from a store listener while the reducer is executing.`);this.pluginListeners[e]=this.pluginListeners[e].filter(e=>e!==t),this.pluginListeners[e].length===0&&delete this.pluginListeners[e]}}onAction(e,t){return this.subscribe((n,r,i)=>{n.type===e&&t(n,r,i)})}getPluginStore(e){if(!(e in this.state.plugins))throw Error(`Plugin state not found for plugin "${e}". Did you forget to call addPluginReducer?`);return new Ye(this,e)}isCoreAction(e){return ft.includes(e.type)}destroy(){var e,t;this.listeners.length=0;for(let n in this.pluginListeners)(t=(e=this.pluginListeners[n])?.splice)==null||t.call(e,0);this.pluginListeners={},this.pluginReducers={},this.state.plugins={},this.state.core={...this.initialCoreState}}},Tt=e=>({documents:{},documentOrder:[],activeDocumentId:null,defaultScale:e?.defaultScale??1,defaultRotation:e?.defaultRotation??S.Degree0,globalPermissions:e?.permissions}),E.Print,E.ModifyContents,E.CopyContents,E.ModifyAnnotations,E.FillForms,E.ExtractForAccessibility,E.AssembleDocument,E.PrintHighQuality,Et=[E.Print,E.ModifyContents,E.CopyContents,E.ModifyAnnotations,E.FillForms,E.ExtractForAccessibility,E.AssembleDocument,E.PrintHighQuality],Dt={[E.Print]:`print`,[E.ModifyContents]:`modifyContents`,[E.CopyContents]:`copyContents`,[E.ModifyAnnotations]:`modifyAnnotations`,[E.FillForms]:`fillForms`,[E.ExtractForAccessibility]:`extractForAccessibility`,[E.AssembleDocument]:`assembleDocument`,[E.PrintHighQuality]:`printHighQuality`},Ot=(e,t)=>{switch(t.type){case V:{let{documentId:n,name:r,scale:i,rotation:a,passwordProvided:o,autoActivate:s=!0,permissions:c}=t.payload,l={id:n,name:r,status:`loading`,loadingProgress:0,error:null,document:null,scale:i??e.defaultScale,rotation:a??e.defaultRotation,passwordProvided:o??!1,pageRefreshVersions:{},permissions:c,loadStartedAt:Date.now()};return{...e,documents:{...e.documents,[n]:l},documentOrder:[...e.documentOrder,n],activeDocumentId:s||!e.activeDocumentId?n:e.activeDocumentId}}case Xe:{let{documentId:n,progress:r}=t.payload,i=e.documents[n];return!i||i.status!==`loading`?e:{...e,documents:{...e.documents,[n]:{...i,loadingProgress:r}}}}case Ze:{let{documentId:n,document:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,status:`loaded`,document:r,error:null,errorCode:void 0,errorDetails:void 0,passwordProvided:void 0,loadedAt:Date.now()}}}:e}case Qe:{let{documentId:n,error:r,errorCode:i,errorDetails:a}=t.payload,o=e.documents[n];return o?{...e,documents:{...e.documents,[n]:{...o,status:`error`,error:r,errorCode:i,errorDetails:a}}}:e}case $e:{let{documentId:n,passwordProvided:r}=t.payload,i=e.documents[n];return!i||i.status!==`error`?e:{...e,documents:{...e.documents,[n]:{...i,status:`loading`,loadingProgress:0,error:null,errorCode:void 0,errorDetails:void 0,passwordProvided:r??!1,loadStartedAt:Date.now()}}}}case et:{let{documentId:n,nextActiveDocumentId:r}=t.payload,{[n]:i,...a}=e.documents;return{...e,documents:a,documentOrder:e.documentOrder.filter(e=>e!==n),activeDocumentId:Ie(e,n,r)}}case rt:{let{documentId:n,toIndex:r}=t.payload,i=Le(e.documentOrder,n,r);return i?{...e,documentOrder:i}:e}case nt:return{...e,documentOrder:t.payload};case tt:return{...e,activeDocumentId:t.payload};case ct:{let{scale:n,documentId:r}=t.payload,i=r??e.activeDocumentId;if(!i)return e;let a=e.documents[i];return a?{...e,documents:{...e.documents,[i]:{...a,scale:n}}}:e}case lt:{let{rotation:n,documentId:r}=t.payload,i=r??e.activeDocumentId;if(!i)return e;let a=e.documents[i];return a?{...e,documents:{...e.documents,[i]:{...a,rotation:n}}}:e}case ot:{let{documentId:n,pageIndexes:r}=t.payload,i=e.documents[n];if(!i)return e;let a={...i.pageRefreshVersions};for(let e of r)a[e]=(a[e]||0)+1;return{...e,documents:{...e.documents,[n]:{...i,pageRefreshVersions:a}}}}case it:{let{documentId:n,permissions:r,isOwnerUnlocked:i}=t.payload,a=e.documents[n];return a?.document?{...e,documents:{...e.documents,[n]:{...a,document:{...a.document,permissions:r,isOwnerUnlocked:i}}}}:e}default:return e}},kt=class{constructor(e,t){this.plugins=/* @__PURE__ */ new Map,this.manifests=/* @__PURE__ */ new Map,this.capabilities=/* @__PURE__ */ new Map,this.status=/* @__PURE__ */ new Map,this.configurations=/* @__PURE__ */ new Map,this.initPromise=null,this.pendingRegistrations=[],this.processingRegistrations=[],this.initialized=!1,this.isInitializing=!1,this.pluginsReadyPromise=null,this.destroyed=!1,this.resolver=new Ke,this.engine=e,this.initialCoreState=Tt(t),this.store=new wt(Ot,this.initialCoreState),this.logger=t?.logger??new ce}getLogger(){return this.logger}registerPlugin(e,t){if(this.initialized&&!this.isInitializing)throw new z(`Cannot register plugins after initialization`);this.validateManifest(e.manifest),this.store.addPluginReducer(e.manifest.id,e.reducer,typeof e.initialState==`function`?e.initialState(this.initialCoreState,{...e.manifest.defaultConfig,...t}):e.initialState),this.pendingRegistrations.push({package:e,config:t})}getStore(){return this.store}getEngine(){return this.engine}pluginsReady(){return this.pluginsReadyPromise||=(async()=>{this.initialized||await this.initialize();let e=Array.from(this.plugins.values()).map(e=>typeof e.ready==`function`?e.ready():Promise.resolve());await Promise.all(e)})(),this.pluginsReadyPromise}async initialize(){if(this.destroyed)throw new z(`Registry has been destroyed`);return this.initPromise||=(async()=>{if(this.initialized)throw new z(`Registry is already initialized`);this.isInitializing=!0;try{if(this.destroyed)return;for(;this.pendingRegistrations.length>0;){if(this.destroyed)return;this.processingRegistrations=[...this.pendingRegistrations],this.pendingRegistrations=[];for(let e of this.processingRegistrations){let t=/* @__PURE__ */ new Set,n=[...e.package.manifest.requires,...e.package.manifest.optional];for(let e of n){let n=this.processingRegistrations.find(t=>t.package.manifest.provides.includes(e));n&&t.add(n.package.manifest.id)}this.resolver.addNode(e.package.manifest.id,[...t])}let e=this.resolver.resolveLoadOrder();for(let t of e){let e=this.processingRegistrations.find(e=>e.package.manifest.id===t);this.instantiatePlugin(e.package.manifest,e.package.create,e.config)}for(let t of e)await this.runPluginInitialization(t);this.processingRegistrations=[],this.resolver=new Ke}this.initialized=!0}catch(e){throw e instanceof Error?new qe(`Failed to resolve plugin dependencies: ${e.message}`):e}finally{this.isInitializing=!1}})(),this.initPromise}instantiatePlugin(e,t,n){let r={...e.defaultConfig,...n};this.validateConfig(e.id,r,e.defaultConfig);let i=t(this,r);this.validatePlugin(i);for(let t of e.provides){if(this.capabilities.has(t))throw new z(`Capability ${t} is already provided by plugin ${this.capabilities.get(t)}`);this.capabilities.set(t,e.id)}this.plugins.set(e.id,i),this.manifests.set(e.id,e),this.status.set(e.id,`registered`),this.configurations.set(e.id,r)}async runPluginInitialization(e){let t=this.plugins.get(e);if(!t)return;let n=this.manifests.get(e),r=this.configurations.get(e);for(let t of n.requires)if(!this.capabilities.has(t))throw new z(`Missing required capability: ${t} for plugin ${e}`);this.logger.debug(`PluginRegistry`,`InitializePlugin`,`Initializing plugin ${e}`);try{t.initialize&&await t.initialize(r),this.status.set(e,`active`),this.logger.info(`PluginRegistry`,`PluginInitialized`,`Plugin ${e} initialized successfully`)}catch(t){throw this.status.set(e,`error`),this.logger.error(`PluginRegistry`,`InitializationFailed`,`Plugin ${e} initialization failed`,{error:t}),t}}getPluginConfig(e){let t=this.configurations.get(e);if(!t)throw new B(`Configuration for plugin ${e} not found`);return t}validateConfig(e,t,n){let r=Object.keys(n).filter(e=>!t.hasOwnProperty(e));if(r.length>0)throw new Je(`Missing required configuration keys for plugin ${e}: ${r.join(`, `)}`)}async updatePluginConfig(e,t){let n=this.getPlugin(e);if(!n)throw new B(`Plugin ${e} not found`);let r=this.manifests.get(e),i=this.configurations.get(e);if(!r||!i)throw new B(`Plugin ${e} not found`);let a={...i,...t};this.validateConfig(e,a,r.defaultConfig),this.configurations.set(e,a),n.initialize&&await n.initialize(a)}registerPluginBatch(e){for(let t of e)this.registerPlugin(t.package,t.config)}async unregisterPlugin(e){let t=this.plugins.get(e);if(!t)throw new B(`Plugin ${e} is not registered`);let n=this.manifests.get(e);if(!n)throw new B(`Manifest for plugin ${e} not found`);for(let[t,r]of this.manifests.entries())if(t!==e&&[...r.requires,...r.optional].some(e=>n.provides.includes(e)))throw new z(`Cannot unregister plugin ${e}: plugin ${t} depends on it`);try{t.destroy&&await t.destroy();for(let e of n.provides)this.capabilities.delete(e);this.plugins.delete(e),this.manifests.delete(e),this.status.delete(e)}catch(t){throw t instanceof Error?Error(`Failed to unregister plugin ${e}: ${t.message}`):t}}getPlugin(e){return this.plugins.get(e)||null}getCapabilityProvider(e){let t=this.capabilities.get(e);return t?this.getPlugin(t):null}hasCapability(e){return this.capabilities.has(e)}getAllPlugins(){return Array.from(this.plugins.values())}getPluginStatus(e){let t=this.status.get(e);if(!t)throw new B(`Plugin ${e} not found`);return t}validatePlugin(e){if(!e.id)throw new z(`Plugin must have an id`)}validateManifest(e){if(!e.id)throw new z(`Manifest must have an id`);if(!e.name)throw new z(`Manifest must have a name`);if(!e.version)throw new z(`Manifest must have a version`);if(!Array.isArray(e.provides))throw new z(`Manifest must have a provides array`);if(!Array.isArray(e.requires))throw new z(`Manifest must have a requires array`);if(!Array.isArray(e.optional))throw new z(`Manifest must have an optional array`)}isDestroyed(){return this.destroyed}async destroy(){if(this.destroyed)throw new z(`Registry has already been destroyed`);this.destroyed=!0;try{await this.initPromise}catch{}for(let e of Array.from(this.plugins.values()).reverse())await e.destroy?.call(e);this.store.destroy(),this.plugins.clear(),this.manifests.clear(),this.capabilities.clear(),this.status.clear(),this.pendingRegistrations.length=0,this.processingRegistrations.length=0}},H=class{constructor(e,t){if(this.id=e,this.registry=t,this.cooldownActions={},this.debouncedTimeouts={},this.unsubscribeFromState=null,this.unsubscribeFromCoreStore=null,this.unsubscribeFromStartLoadingDocument=null,this.unsubscribeFromSetDocumentLoaded=null,this.unsubscribeFromCloseDocument=null,this.unsubscribeFromSetScale=null,this.unsubscribeFromSetRotation=null,e!==this.constructor.id)throw Error(`Plugin ID mismatch: ${e} !== ${this.constructor.id}`);this.engine=this.registry.getEngine(),this.logger=this.registry.getLogger(),this.coreStore=this.registry.getStore(),this.pluginStore=this.coreStore.getPluginStore(this.id),this.unsubscribeFromState=this.pluginStore.subscribeToState((e,t,n)=>{this.onStoreUpdated(n,t)}),this.unsubscribeFromCoreStore=this.coreStore.subscribe((e,t,n)=>{this.onCoreStoreUpdated(n,t),t.core.activeDocumentId!==n.core.activeDocumentId&&this.onActiveDocumentChanged(n.core.activeDocumentId,t.core.activeDocumentId)}),this.unsubscribeFromStartLoadingDocument=this.coreStore.onAction(V,e=>{this.onDocumentLoadingStarted(e.payload.documentId)}),this.unsubscribeFromSetDocumentLoaded=this.coreStore.onAction(Ze,e=>{this.onDocumentLoaded(e.payload.documentId)}),this.unsubscribeFromCloseDocument=this.coreStore.onAction(et,e=>{this.onDocumentClosed(e.payload.documentId)}),this.unsubscribeFromSetScale=this.coreStore.onAction(ct,(e,t)=>{let n=e.payload.documentId??t.core.activeDocumentId;n&&this.onScaleChanged(n,e.payload.scale)}),this.unsubscribeFromSetRotation=this.coreStore.onAction(lt,(e,t)=>{let n=e.payload.documentId??t.core.activeDocumentId;n&&this.onRotationChanged(n,e.payload.rotation)}),this.readyPromise=new Promise(e=>{this.readyResolve=e}),this.readyResolve()}provides(){if(!this._capability){let e=this.buildCapability();this._capability=Object.freeze(e)}return this._capability}get state(){return this.pluginStore.getState()}get coreState(){return this.coreStore.getState()}getState(){return this.pluginStore.getState()}getCoreState(){return this.coreStore.getState()}dispatchCoreAction(e){return this.coreStore.dispatchToCore(e)}dispatchToAllPlugins(e){return this.coreStore.dispatch(e)}dispatch(e){return this.pluginStore.dispatch(e)}cooldownDispatch(e,t=100){let n=Date.now();return n-(this.cooldownActions[e.type]||0)>=t&&(this.cooldownActions[e.type]=n,this.dispatch(e),!0)}debouncedDispatch(e,t=100){let n=e.type;this.debouncedTimeouts[n]&&clearTimeout(this.debouncedTimeouts[n]),this.debouncedTimeouts[n]=setTimeout(()=>{this.dispatch(e),delete this.debouncedTimeouts[n]},t)}cancelDebouncedDispatch(e){this.debouncedTimeouts[e]&&(clearTimeout(this.debouncedTimeouts[e]),delete this.debouncedTimeouts[e])}subscribe(e){return this.pluginStore.subscribeToState(e)}subscribeToCoreStore(e){return this.coreStore.subscribe(e)}onStoreUpdated(e,t){}onCoreStoreUpdated(e,t){}onDocumentLoadingStarted(e){}onDocumentLoaded(e){}onDocumentClosed(e){}onActiveDocumentChanged(e,t){}onScaleChanged(e,t){}onRotationChanged(e,t){}destroy(){Object.values(this.debouncedTimeouts).forEach(e=>{clearTimeout(e)}),this.debouncedTimeouts={},this.unsubscribeFromState&&=(this.unsubscribeFromState(),null),this.unsubscribeFromCoreStore&&=(this.unsubscribeFromCoreStore(),null),this.unsubscribeFromStartLoadingDocument&&=(this.unsubscribeFromStartLoadingDocument(),null),this.unsubscribeFromSetDocumentLoaded&&=(this.unsubscribeFromSetDocumentLoaded(),null),this.unsubscribeFromCloseDocument&&=(this.unsubscribeFromCloseDocument(),null),this.unsubscribeFromSetScale&&=(this.unsubscribeFromSetScale(),null),this.unsubscribeFromSetRotation&&=(this.unsubscribeFromSetRotation(),null)}ready(){return this.readyPromise}markReady(){this.readyResolve()}resetReady(){this.readyPromise=new Promise(e=>{this.readyResolve=e})}getActiveDocumentId(){let e=this.coreState.core.activeDocumentId;if(!e)throw Error(`No active document`);return e}getActiveDocumentIdOrNull(){return this.coreState.core.activeDocumentId}getCoreDocument(e){let t=e??this.getActiveDocumentIdOrNull();return t?this.coreState.core.documents[t]??null:null}getCoreDocumentOrThrow(e){let t=this.getCoreDocument(e);if(!t)throw Error(`Document not found: ${e??`active`}`);return t}getDocumentPermissions(e){let t=e??this.coreState.core.activeDocumentId;return t?Fe(this.coreState.core,t):E.AllowAll}checkPermission(e,...t){let n=e??this.coreState.core.activeDocumentId;return!n||t.every(e=>Pe(this.coreState.core,n,e))}requirePermission(e,...t){let n=e??this.coreState.core.activeDocumentId;if(!n)return;let r=[];for(let e of t)Pe(this.coreState.core,n,e)||r.push(e);if(r.length>0){let e=Fe(this.coreState.core,n);throw new ee(r,e)}}},At=class{constructor(e,t){this.handler=e,this.options=t,this.lastRun=0,this.handle=e=>{this.options.mode===`debounce`?this.debounce(e):this.throttle(e)}}debounce(e){this.timeoutId&&window.clearTimeout(this.timeoutId),this.timeoutId=window.setTimeout(()=>{this.handler(e),this.timeoutId=void 0},this.options.wait)}throttle(e){if(this.options.mode===`debounce`)return;let t=Date.now(),n=this.options.throttleMode||`leading-trailing`;t-this.lastRun>=this.options.wait&&(n===`leading-trailing`&&this.handler(e),this.lastRun=t),this.timeoutId&&window.clearTimeout(this.timeoutId),this.timeoutId=window.setTimeout(()=>{this.handler(e),this.lastRun=Date.now(),this.timeoutId=void 0},this.options.wait-(t-this.lastRun))}destroy(){this.timeoutId&&window.clearTimeout(this.timeoutId)}},jt=class{constructor(e,t){this.handler=e,this.options=t,this.controls=/* @__PURE__ */ new Map,this.handle=e=>{let t=String(this.options.keyExtractor(e)),n=this.controls.get(t);n||(n=new At(this.handler,this.baseOptions),this.controls.set(t,n)),n.handle(e)},this.baseOptions={mode:t.mode,wait:t.wait,...t.mode===`throttle`&&`throttleMode`in t?{throttleMode:t.throttleMode}:{}}}destroy(){for(let e of this.controls.values())e.destroy();this.controls.clear()}},Mt=0,Nt=/* @__PURE__ */ new WeakMap,Pt=class{constructor(e){this.autoMountElements=[],this.package=e}addUtility(e){return this.autoMountElements.push({component:e,type:`utility`}),this}addWrapper(e){return this.autoMountElements.push({component:e,type:`wrapper`}),this}build(){return{...this.package,autoMountElements:()=>this.autoMountElements}}}})))()}function Ft({plugins:e,children:t}){let{utilities:n,wrappers:r}=k(()=>{let t=[],n=[];for(let r of e){let e=r.package;if(Re(e)){let r=e.autoMountElements()||[];for(let e of r)e.type===`utility`?t.push(e.component):e.type===`wrapper`&&n.push(e.component)}}return{utilities:t,wrappers:n}},[e]),i=/* @__PURE__ */ N(pe,{children:[t,n.map((e,t)=>/* @__PURE__ */ M(e,{},`utility-${t}`))]}),a=r.reduce((e,t)=>/* @__PURE__ */ M(t,{children:e}),i);return/* @__PURE__ */ M(pe,{children:a})}function It({engine:e,config:t,logger:n,onInitialized:r,plugins:i,children:a,autoMountDomElements:o=!0}){let[s,c]=j(null),[l,u]=j(null),[d,f]=j(!0),[p,m]=j(!1),h=A(r);O(()=>{h.current=r},[r]),O(()=>{let r={...t,logger:t?.logger??n},a=new kt(e,r);a.registerPluginBatch(i);let o=async()=>{if(await a.initialize(),a.isDestroyed())return;let e=a.getStore();u(e.getState().core);let t=e.subscribe((t,n,r)=>{e.isCoreAction(t)&&n.core!==r.core&&u(n.core)});if(await h.current?.call(h,a),a.isDestroyed())t();else return a.pluginsReady().then(()=>{a.isDestroyed()||m(!0)}),c(a),f(!1),t},s;return o().then(e=>{s=e}).catch(console.error),()=>{s?.(),a.destroy(),c(null),u(null),f(!0),m(!1)}},[e,i]);let g=k(()=>{let e=l?.activeDocumentId??null,t=l?.documents??{},n=l?.documentOrder??[],r=e&&t[e]?t[e]:null,i=n.map(e=>t[e]).filter(e=>e!=null);return{registry:s,coreState:l,isInitializing:d,pluginsReady:p,activeDocumentId:e,activeDocument:r,documents:t,documentStates:i}},[s,l,d,p]),_=typeof a==`function`?a(g):a;return/* @__PURE__ */ M(zt.Provider,{value:g,children:p&&o?/* @__PURE__ */ M(Ft,{plugins:i,children:_}):_})}function Lt(){let e=ge(zt);if(e===void 0)throw Error(`useCapability must be used within a PDFContext.Provider`);let{registry:t,isInitializing:n}=e;if(n)return e;if(t===null)throw Error(`PDF registry failed to initialize properly`);return e}function W(e){let{registry:t}=Lt();if(t===null)return{plugin:null,isLoading:!0,ready:new Promise(()=>{})};let n=t.getPlugin(e);if(!n)throw Error(`Plugin ${e} not found`);return{plugin:n,isLoading:!1,ready:n.ready()}}function G(e){let{plugin:t,isLoading:n,ready:r}=W(e);if(!t)return{provides:null,isLoading:n,ready:r};if(!t.provides)throw Error(`Plugin ${e} does not provide a capability`);return{provides:t.provides(),isLoading:n,ready:r}}function Rt(){let{coreState:e}=ge(zt);return e}function K(e){let t=Rt();return k(()=>!t||!e?null:t.documents[e]??null,[t,e])}var zt;function q(){return(q=e((()=>{U(),C(),zt=me({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]}),E.Print,E.ModifyContents,E.CopyContents,E.ModifyAnnotations,E.FillForms,E.ExtractForAccessibility,E.AssembleDocument,E.PrintHighQuality,E.Print,E.ModifyContents,E.CopyContents,E.ModifyAnnotations,E.FillForms,E.ExtractForAccessibility,E.AssembleDocument,E.PrintHighQuality,E.Print,E.ModifyContents,E.CopyContents,E.ModifyAnnotations,E.FillForms,E.ExtractForAccessibility,E.AssembleDocument,E.PrintHighQuality})))()}function Bt(e){let{wasmUrl:t=Vt,worker:r=!0,logger:i,encoderPoolSize:a,fontFallback:o}=e??{},[s,c]=j(null),[l,u]=j(!0),[d,f]=j(null),p=A(null);return O(()=>{let e=!1;return(async()=>{try{let{createPdfiumEngine:e}=r?await n(()=>import(`./worker-engine-B4e92GsN.js`),[],import.meta.url):await n(()=>import(`./direct-engine-thps0u7R.js`),[],import.meta.url),s=await e(t,{logger:i,encoderPoolSize:a,fontFallback:o});p.current=s,c(s),u(!1)}catch(t){e||(f(t),u(!1))}})(),()=>{var t,n;e=!0,(n=(t=p.current)?.closeAllDocuments)==null||n.call(t).wait(()=>{var e,t;(t=(e=p.current)?.destroy)==null||t.call(e),p.current=null},T)}},[t,r,i,o]),{engine:s,isLoading:l,error:d}}var Vt;function Ht(){return(Ht=e((()=>{C(),t(),Vt=`https://cdn.jsdelivr.net/npm/@embedpdf/pdfium@2.15.1/dist/pdfium.wasm`,me(void 0)})))()}var Ut,Wt,Gt,Kt,qt;function Jt(){return(Jt=e((()=>{U(),C(),Ut=class extends H{constructor(e,t,n){super(e,t),this.id=e,this.documentOpened$=L(),this.documentClosed$=L(),this.activeDocumentChanged$=L(),this.documentError$=L(),this.documentOrderChanged$=L(),this.openFileRequest$=I(),this.loadOptions=/* @__PURE__ */ new Map,this.maxDocuments=n?.maxDocuments}buildCapability(){return{openFileDialog:e=>this.openFileDialog(e),openDocumentUrl:e=>this.openDocumentUrl(e),openDocumentBuffer:e=>this.openDocumentBuffer(e),retryDocument:(e,t)=>this.retryDocument(e,t),closeDocument:e=>this.closeDocument(e),closeAllDocuments:()=>this.closeAllDocuments(),setActiveDocument:e=>{if(!this.isDocumentOpen(e))throw Error(`Cannot set active document: ${e} is not open`);this.dispatchCoreAction(vt(e))},getActiveDocumentId:()=>this.coreState.core.activeDocumentId,getActiveDocument:()=>{let e=this.coreState.core.activeDocumentId;return e?this.coreState.core.documents[e]?.document??null:null},getDocumentOrder:()=>this.coreState.core.documentOrder,moveDocument:(e,t)=>{this.dispatchCoreAction(St(e,t))},swapDocuments:(e,t)=>{let n=this.coreState.core.documentOrder,r=n.indexOf(e),i=n.indexOf(t);if(r===-1||i===-1)throw Error(`One or both documents not found in order`);let a=[...n];[a[r],a[i]]=[a[i],a[r]],this.dispatchCoreAction(xt(a))},getDocument:e=>this.coreState.core.documents[e]?.document??null,getDocumentState:e=>this.coreState.core.documents[e]??null,getOpenDocuments:()=>this.coreState.core.documentOrder.map(e=>this.coreState.core.documents[e]).filter(e=>e!==null),isDocumentOpen:e=>this.isDocumentOpen(e),getDocumentCount:()=>Object.keys(this.coreState.core.documents).length,getDocumentIndex:e=>this.coreState.core.documentOrder.indexOf(e),setDocumentEncryption:(e,t)=>this.setDocumentEncryption(e,t),unlockOwnerPermissions:(e,t)=>this.unlockOwnerPermissions(e,t),removeEncryption:e=>this.removeEncryption(e),onDocumentOpened:this.documentOpened$.on,onDocumentClosed:this.documentClosed$.on,onDocumentError:this.documentError$.on,onActiveDocumentChanged:this.activeDocumentChanged$.on,onDocumentOrderChanged:this.documentOrderChanged$.on}}isDocumentOpen(e){return!!this.coreState.core.documents[e]}onDocumentLoaded(e){let t=this.coreState.core.documents[e];t&&t.status===`loaded`&&(this.loadOptions.delete(e),this.documentOpened$.emit(t),this.logger.info(`DocumentManagerPlugin`,`DocumentOpened`,`Document ${e} opened successfully`,{name:t.name}))}onDocumentClosed(e){this.loadOptions.delete(e),this.documentClosed$.emit(e),this.logger.info(`DocumentManagerPlugin`,`DocumentClosed`,`Document ${e} closed`)}onActiveDocumentChanged(e,t){this.activeDocumentChanged$.emit({previousDocumentId:e,currentDocumentId:t}),this.logger.info(`DocumentManagerPlugin`,`ActiveDocumentChanged`,`Active document changed from ${e} to ${t}`)}onCoreStoreUpdated(e,t){e.core.documentOrder!==t.core.documentOrder&&this.documentOrderChanged$.emit({order:t.core.documentOrder})}onOpenFileRequest(e){return this.openFileRequest$.on(e)}openDocumentUrl(e){let t=new w,n=e.documentId||this.generateDocumentId(),r=this.checkDocumentLimit();if(r)return t.reject(r),t;let i=e.name??this.extractNameFromUrl(e.url);this.loadOptions.set(n,e),this.dispatchCoreAction(pt(n,i,e.scale,e.rotation,!!e.password,e.autoActivate,e.permissions)),this.logger.info(`DocumentManagerPlugin`,`OpenDocumentUrl`,`Starting to load document from URL: ${e.url}`,{documentId:n,passwordProvided:!!e.password});let a={id:n,url:e.url},o=this.engine.openDocumentUrl(a,{password:e.password,mode:e.mode,requestOptions:e.requestOptions,normalizeRotation:!0});return t.resolve({documentId:n,task:o}),this.handleLoadTask(n,o,`OpenDocumentUrl`),t}openDocumentBuffer(e){let t=new w,n=this.checkDocumentLimit();if(n)return t.reject(n),t;let r=e.documentId||this.generateDocumentId();this.loadOptions.set(r,e),this.dispatchCoreAction(pt(r,e.name,e.scale,e.rotation,!!e.password,e.autoActivate,e.permissions)),this.logger.info(`DocumentManagerPlugin`,`OpenDocumentBuffer`,`Starting to load document from buffer: ${e.name}`,{documentId:r,passwordProvided:!!e.password});let i={id:r,content:e.buffer},a=this.engine.openDocumentBuffer(i,{password:e.password,normalizeRotation:!0});return t.resolve({documentId:r,task:a}),this.handleLoadTask(r,a,`OpenDocumentBuffer`),t}retryDocument(e,t){let n=new w,r=this.validateRetry(e);if(!r.valid)return n.reject(r.error),n;let i={...this.loadOptions.get(e),...t?.password&&{password:t.password}};this.loadOptions.set(e,i),this.dispatchCoreAction(gt(e,!!t?.password)),this.logger.info(`DocumentManagerPlugin`,`RetryDocument`,`Retrying to load document ${e}`,{passwordProvided:!!t?.password});let a=`url`in i?this.retryUrlDocument(e,i):this.retryBufferDocument(e,i);return n.resolve({documentId:e,task:a}),this.handleLoadTask(e,a,`RetryDocument`),n}openFileDialog(e){let t=new w;return this.openFileRequest$.emit({task:t,options:e}),t}closeDocument(e){let t=new w,n=this.coreState.core.documents[e];return n?(n.status===`loaded`&&n.document?this.engine.closeDocument(n.document).wait(()=>{this.dispatchCoreAction(_t(e)),t.resolve()},n=>{this.logger.error(`DocumentManagerPlugin`,`CloseDocument`,`Failed to close document ${e}`,n),t.fail(n)}):(this.logger.info(`DocumentManagerPlugin`,`CloseDocument`,`Closing document ${e} in ${n.status} state (skipping engine close)`),this.dispatchCoreAction(_t(e)),t.resolve()),t):(this.logger.warn(`DocumentManagerPlugin`,`CloseDocument`,`Cannot close document ${e}: not found in state`),t.resolve(),t)}closeAllDocuments(){let e=Object.keys(this.coreState.core.documents),t=e.map(e=>this.closeDocument(e));return this.logger.info(`DocumentManagerPlugin`,`CloseAllDocuments`,`Closing ${e.length} documents`),w.all(t)}setDocumentEncryption(e,t){let n=new w,r=this.coreState.core.documents[e];return r?.document?(this.logger.info(`DocumentManagerPlugin`,`SetDocumentEncryption`,`Setting encryption on document ${e}`,{hasUserPassword:!!t.userPassword,allowedFlags:t.allowedFlags}),this.engine.setDocumentEncryption(r.document,t.userPassword??``,t.ownerPassword,t.allowedFlags).wait(t=>{t&&this.logger.info(`DocumentManagerPlugin`,`SetDocumentEncryption`,`Encryption set successfully on document ${e}`),n.resolve(t)},t=>{this.logger.error(`DocumentManagerPlugin`,`SetDocumentEncryption`,`Failed to set encryption on document ${e}`,t),n.fail(t)}),n):(n.reject({code:D.DocNotOpen,message:`Document ${e} is not open`}),n)}unlockOwnerPermissions(e,t){let n=new w,r=this.coreState.core.documents[e];if(!r?.document)return n.reject({code:D.DocNotOpen,message:`Document ${e} is not open`}),n;let i=r.document;return this.logger.info(`DocumentManagerPlugin`,`UnlockOwnerPermissions`,`Attempting to unlock owner permissions on document ${e}`),this.engine.unlockOwnerPermissions(i,t).wait(t=>{t&&(this.logger.info(`DocumentManagerPlugin`,`UnlockOwnerPermissions`,`Owner permissions unlocked on document ${e}`),this.dispatchCoreAction(Ct(e,4294967295,!0))),n.resolve(t)},t=>{this.logger.error(`DocumentManagerPlugin`,`UnlockOwnerPermissions`,`Failed to unlock owner permissions on document ${e}`,t),n.fail(t)}),n}removeEncryption(e){let t=new w,n=this.coreState.core.documents[e];return n?.document?(this.logger.info(`DocumentManagerPlugin`,`RemoveEncryption`,`Marking document ${e} for encryption removal on save`),this.engine.removeEncryption(n.document).wait(n=>{n&&this.logger.info(`DocumentManagerPlugin`,`RemoveEncryption`,`Document ${e} marked for encryption removal`),t.resolve(n)},n=>{this.logger.error(`DocumentManagerPlugin`,`RemoveEncryption`,`Failed to mark document ${e} for encryption removal`,n),t.fail(n)}),t):(t.reject({code:D.DocNotOpen,message:`Document ${e} is not open`}),t)}checkDocumentLimit(){return this.maxDocuments&&Object.keys(this.coreState.core.documents).length>=this.maxDocuments?{code:D.Unknown,message:`Maximum number of documents (${this.maxDocuments}) reached`}:null}validateRetry(e){let t=this.coreState.core.documents[e];return t?t.status===`loaded`?{valid:!1,error:{code:D.Unknown,message:`Document ${e} is already loaded successfully`}}:t.status===`error`?this.loadOptions.has(e)?{valid:!0}:{valid:!1,error:{code:D.Unknown,message:`No retry information available for document ${e}`}}:{valid:!1,error:{code:D.Unknown,message:`Document ${e} is not in error state (current state: ${t.status})`}}:{valid:!1,error:{code:D.NotFound,message:`Document ${e} not found`}}}retryUrlDocument(e,t){let n={id:e,url:t.url};return this.engine.openDocumentUrl(n,{password:t.password,mode:t.mode,requestOptions:t.requestOptions})}retryBufferDocument(e,t){let n={id:e,content:t.buffer};return this.engine.openDocumentBuffer(n,{password:t.password,normalizeRotation:!0})}handleLoadTask(e,t,n){t.wait(t=>{this.dispatchCoreAction(mt(e,t))},t=>{this.handleLoadError(e,t,n)})}handleLoadError(e,t,n){let r=t.reason?.message||`Failed to load document`;this.logger.error(`DocumentManagerPlugin`,n,`Failed to load document`,t),this.dispatchCoreAction(ht(e,r,t.reason?.code,t.reason)),this.documentError$.emit({documentId:e,message:r,code:t.reason?.code,reason:t.reason})}generateDocumentId(){return`doc-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}extractNameFromUrl(e){try{let t=new URL(e).pathname.split(`/`).pop();if(!t)return;let n=decodeURIComponent(t);return n.toLowerCase().endsWith(`.pdf`)||(n+=`.pdf`),n}catch{return}}async initialize(e){if(this.logger.info(`DocumentManagerPlugin`,`Initialize`,`Document Manager Plugin initialized`,{maxDocuments:this.maxDocuments,initialDocumentsCount:e.initialDocuments?.length??0}),e.initialDocuments&&e.initialDocuments.length>0)for(let t of e.initialDocuments)try{`buffer`in t?this.openDocumentBuffer(t):`url`in t&&this.openDocumentUrl(t)}catch(e){this.logger.error(`DocumentManagerPlugin`,`Initialize`,`Failed to initiate initial document load`,e)}}async destroy(){await this.closeAllDocuments().toPromise(),this.loadOptions.clear(),this.documentOpened$.clear(),this.documentClosed$.clear(),this.activeDocumentChanged$.clear(),this.documentOrderChanged$.clear(),this.documentError$.clear(),super.destroy()}},Ut.id=`document-manager`,Wt=Ut,Gt=`document-manager`,Kt={id:Gt,name:`Document Manager Plugin`,version:`1.0.0`,provides:[`document-manager`],requires:[],optional:[],defaultConfig:{maxDocuments:10}},qt={manifest:Kt,create:(e,t)=>new Wt(Gt,e,t),reducer:e=>e,initialState:{}}})))()}function Yt({documentId:e,children:t}){let n=K(e);if(!n)return null;let r=n.status===`loading`,i=n.status===`error`,a=n.status===`loaded`;return/* @__PURE__ */ M(ye,{children:t({documentState:n,isLoading:r,isError:i,isLoaded:a})})}function Xt(){let{plugin:e}=Zt(),{provides:t}=Qt(),n=A(null),r=A(null),i=A(void 0);return O(()=>{if(e?.onOpenFileRequest)return e.onOpenFileRequest(({task:e,options:t})=>{var a;r.current=e,i.current=t,(a=n.current)==null||a.click()})},[e]),/* @__PURE__ */ M(`input`,{ref:n,type:`file`,accept:`application/pdf`,style:{display:`none`},onChange:async e=>{let n=e.currentTarget.files?.[0];if(!n||!t)return;let a=await n.arrayBuffer();t.openDocumentBuffer({name:n.name,buffer:a,documentId:i.current?.documentId,scale:i.current?.scale,rotation:i.current?.rotation,autoActivate:i.current?.autoActivate}).wait(e=>{var t;(t=r.current)==null||t.resolve(e)},e=>{var t;(t=r.current)==null||t.fail(e)})}})}var Zt,Qt,$t;function en(){return(en=e((()=>{U(),Jt(),q(),Zt=()=>W(Wt.id),Qt=()=>G(Wt.id),$t=Ge(qt).addUtility(Xt).build()})))()}function tn(e){return{type:hn,payload:{documentId:e}}}function nn(e){return{type:gn,payload:{documentId:e}}}function rn(e){return{type:_n,payload:{documentId:e}}}function an(e){return{type:vn,payload:{documentId:e}}}function on(e){return{type:xn,payload:e}}function sn(e,t){return{type:yn,payload:{documentId:e,metrics:t}}}function cn(e,t){return{type:bn,payload:{documentId:e,scrollMetrics:t}}}function ln(e,t){return{type:Sn,payload:{documentId:e,isScrolling:t}}}function un(e,t){return{type:Cn,payload:{documentId:e,isSmoothScrolling:t}}}function dn(e,t){return{type:Tn,payload:{documentId:e,key:t}}}function fn(e,t){return{type:En,payload:{documentId:e,key:t}}}var pn,mn,hn,gn,_n,vn,yn,bn,xn,Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn,Mn;function Nn(){return(Nn=e((()=>{U(),pn=`viewport`,mn={id:pn,name:`Viewport Plugin`,version:`1.0.0`,provides:[`viewport`],requires:[],optional:[],defaultConfig:{viewportGap:10,scrollEndDelay:300}},hn=`INIT_VIEWPORT_STATE`,gn=`CLEANUP_VIEWPORT_STATE`,_n=`REGISTER_VIEWPORT`,vn=`UNREGISTER_VIEWPORT`,yn=`SET_VIEWPORT_METRICS`,bn=`SET_VIEWPORT_SCROLL_METRICS`,xn=`SET_VIEWPORT_GAP`,Sn=`SET_SCROLL_ACTIVITY`,Cn=`SET_SMOOTH_SCROLL_ACTIVITY`,wn=`SET_ACTIVE_VIEWPORT_DOCUMENT`,Tn=`ADD_VIEWPORT_GATE`,En=`REMOVE_VIEWPORT_GATE`,Dn={viewportMetrics:{width:0,height:0,scrollTop:0,scrollLeft:0,clientWidth:0,clientHeight:0,scrollWidth:0,scrollHeight:0,clientLeft:0,clientTop:0,relativePosition:{x:0,y:0}},isScrolling:!1,isSmoothScrolling:!1,gates:/* @__PURE__ */ new Set},On={viewportGap:0,documents:{},activeViewports:/* @__PURE__ */ new Set,activeDocumentId:null},kn=(e=On,t)=>{switch(t.type){case hn:{let{documentId:n}=t.payload;return{...e,documents:{...e.documents,[n]:{...Dn,gates:/* @__PURE__ */ new Set}}}}case gn:{let{documentId:n}=t.payload,{[n]:r,...i}=e.documents,a=new Set(e.activeViewports);return a.delete(n),{...e,documents:i,activeViewports:a,activeDocumentId:e.activeDocumentId===n?null:e.activeDocumentId}}case _n:{let{documentId:n}=t.payload,r=new Set(e.activeViewports);return r.add(n),{...e,activeViewports:r,activeDocumentId:e.activeDocumentId??n}}case vn:{let{documentId:n}=t.payload,r=new Set(e.activeViewports);return r.delete(n),{...e,activeViewports:r}}case wn:return{...e,activeDocumentId:t.payload};case xn:return{...e,viewportGap:t.payload};case yn:{let{documentId:n,metrics:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,viewportMetrics:{width:r.width,height:r.height,scrollTop:r.scrollTop,scrollLeft:r.scrollLeft,clientWidth:r.clientWidth,clientHeight:r.clientHeight,scrollWidth:r.scrollWidth,scrollHeight:r.scrollHeight,clientLeft:r.clientLeft,clientTop:r.clientTop,relativePosition:{x:r.scrollWidth<=r.clientWidth?0:r.scrollLeft/(r.scrollWidth-r.clientWidth),y:r.scrollHeight<=r.clientHeight?0:r.scrollTop/(r.scrollHeight-r.clientHeight)}}}}}:e}case bn:{let{documentId:n,scrollMetrics:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,viewportMetrics:{...i.viewportMetrics,scrollTop:r.scrollTop,scrollLeft:r.scrollLeft},isScrolling:!0}}}:e}case Sn:{let{documentId:n,isScrolling:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,isScrolling:r}}}:e}case Cn:{let{documentId:n,isSmoothScrolling:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,isSmoothScrolling:r}}}:e}case Tn:{let{documentId:n,key:r}=t.payload,i=e.documents[n];if(!i)return e;let a=new Set(i.gates);return a.add(r),{...e,documents:{...e.documents,[n]:{...i,gates:a}}}}case En:{let{documentId:n,key:r}=t.payload,i=e.documents[n];if(!i)return e;let a=new Set(i.gates);return a.delete(r),{...e,documents:{...e.documents,[n]:{...i,gates:a}}}}default:return e}},An=class extends H{constructor(e,t,n){super(e,t),this.id=e,this.viewportResize$=L(),this.viewportMetrics$=L(),this.scrollMetrics$=L(),this.scrollActivity$=L(),this.gateState$=L(),this.scrollRequests$=/* @__PURE__ */ new Map,n.viewportGap&&this.dispatch(on(n.viewportGap)),this.scrollEndDelay=n.scrollEndDelay||100}onDocumentLoadingStarted(e){this.dispatch(tn(e)),this.scrollRequests$.set(e,I()),this.logger.debug(`ViewportPlugin`,`DocumentOpened`,`Initialized viewport state for document: ${e}`)}onDocumentClosed(e){var t;this.dispatch(nn(e)),(t=this.scrollRequests$.get(e))==null||t.clear(),this.scrollRequests$.delete(e),this.logger.debug(`ViewportPlugin`,`DocumentClosed`,`Cleaned up viewport state for document: ${e}`)}buildCapability(){return{getViewportGap:()=>this.state.viewportGap,getMetrics:()=>this.getMetrics(),scrollTo:e=>this.scrollTo(e),isScrolling:()=>this.isScrolling(),isSmoothScrolling:()=>this.isSmoothScrolling(),isGated:e=>this.isGated(e),hasGate:(e,t)=>this.hasGate(e,t),getGates:e=>this.getGates(e),forDocument:e=>this.createViewportScope(e),gate:(e,t)=>this.gate(e,t),releaseGate:(e,t)=>this.releaseGate(e,t),isViewportMounted:e=>this.state.activeViewports.has(e),onViewportChange:this.viewportMetrics$.on,onViewportResize:this.viewportResize$.on,onScrollChange:this.scrollMetrics$.on,onScrollActivity:this.scrollActivity$.on,onGateChange:this.gateState$.on}}createViewportScope(e){return{getMetrics:()=>this.getMetrics(e),scrollTo:t=>this.scrollTo(t,e),isScrolling:()=>this.isScrolling(e),isSmoothScrolling:()=>this.isSmoothScrolling(e),isGated:()=>this.isGated(e),hasGate:t=>this.hasGate(t,e),getGates:()=>this.getGates(e),gate:t=>this.gate(t,e),releaseGate:t=>this.releaseGate(t,e),onViewportChange:t=>this.viewportMetrics$.on(n=>{n.documentId===e&&t(n.metrics)}),onScrollChange:t=>this.scrollMetrics$.on(n=>{n.documentId===e&&t(n.scrollMetrics)}),onScrollActivity:t=>this.scrollActivity$.on(n=>{n.documentId===e&&t(n.activity)}),onGateChange:t=>this.gateState$.on(n=>{n?.documentId===e&&t(n)})}}registerViewport(e){if(!this.state.documents[e])throw Error(`Cannot register viewport for ${e}: document state not found. Document must be opened before registering viewport.`);this.state.activeViewports.has(e)||(this.dispatch(rn(e)),this.logger.debug(`ViewportPlugin`,`RegisterViewport`,`Registered viewport (DOM mounted) for document: ${e}`))}unregisterViewport(e){this.registry.isDestroyed()||this.state.activeViewports.has(e)&&(this.dispatch(an(e)),this.logger.debug(`ViewportPlugin`,`UnregisterViewport`,`Unregistered viewport (DOM unmounted) for document: ${e}. State preserved.`))}setViewportResizeMetrics(e,t){if(this.registry.isDestroyed())return;this.dispatch(sn(e,t));let n=this.state.documents[e];n&&this.viewportResize$.emit({documentId:e,metrics:n.viewportMetrics})}setViewportScrollMetrics(e,t){if(this.registry.isDestroyed())return;let n=this.state.documents[e];n&&(t.scrollTop!==n.viewportMetrics.scrollTop||t.scrollLeft!==n.viewportMetrics.scrollLeft)&&(this.dispatch(cn(e,t)),this.bumpScrollActivity(e),this.scrollMetrics$.emit({documentId:e,scrollMetrics:t}))}onScrollRequest(e,t){let n=this.scrollRequests$.get(e);if(!n)throw Error(`Cannot subscribe to scroll requests for ${e}: document state not initialized`);return n.on(t)}gate(e,t){let n=this.state.documents[t];n?n.gates.has(e)||(this.dispatch(dn(t,e)),this.logger.debug(`ViewportPlugin`,`GateAdded`,`Added gate '${e}' for document: ${t}. Total gates: ${n.gates.size+1}`)):this.logger.warn(`ViewportPlugin`,`GateViewport`,`Cannot gate viewport for ${t}: document not found`)}releaseGate(e,t){let n=this.state.documents[t];n?n.gates.has(e)&&(this.dispatch(fn(t,e)),this.logger.debug(`ViewportPlugin`,`GateReleased`,`Released gate '${e}' for document: ${t}. Remaining gates: ${n.gates.size-1}`)):this.logger.warn(`ViewportPlugin`,`ReleaseGate`,`Cannot release gate for ${t}: document not found`)}getViewportState(e){let t=e??this.getActiveDocumentId(),n=this.state.documents[t];if(!n)throw Error(`Viewport state not found for document: ${t}`);return n}getMetrics(e){return this.getViewportState(e).viewportMetrics}isScrolling(e){return this.getViewportState(e).isScrolling}isSmoothScrolling(e){return this.getViewportState(e).isSmoothScrolling}isGated(e){return this.getViewportState(e).gates.size>0}hasGate(e,t){return this.getViewportState(t).gates.has(e)}getGates(e){let t=this.getViewportState(e);return Array.from(t.gates)}scrollTo(e,t){let n=t??this.getActiveDocumentId(),r=this.getViewportState(n),{x:i,y:a,alignX:o,alignY:s,behavior:c=`auto`}=e;c===`smooth`&&this.dispatch(un(n,!0));let l=r.viewportMetrics,u=i,d=a;o!==void 0&&(u=i-l.clientWidth*(o/100)),s!==void 0&&(d=a-l.clientHeight*(s/100));let f=this.scrollRequests$.get(n);f&&f.emit({x:u,y:d,behavior:c})}bumpScrollActivity(e){this.debouncedDispatch(ln(e,!1),this.scrollEndDelay),this.debouncedDispatch(un(e,!1),this.scrollEndDelay)}onStoreUpdated(e,t){for(let n in t.documents){let r=e.documents[n],i=t.documents[n];if(r!==i&&(this.viewportMetrics$.emit({documentId:n,metrics:i.viewportMetrics}),r&&(r.isScrolling!==i.isScrolling||r.isSmoothScrolling!==i.isSmoothScrolling)&&this.scrollActivity$.emit({documentId:n,activity:{isScrolling:i.isScrolling,isSmoothScrolling:i.isSmoothScrolling}}),r&&r.gates!==i.gates)){let e=Array.from(r.gates),t=Array.from(i.gates),a=t.find(t=>!e.includes(t)),o=e.find(e=>!t.includes(e));this.gateState$.emit({documentId:n,isGated:i.gates.size>0,gates:t,addedGate:a,removedGate:o}),this.logger.debug(`ViewportPlugin`,`GateStateChanged`,`Gate state changed for document ${n}. Gates: [${t.join(`, `)}], Gated: ${i.gates.size>0}`)}}}async initialize(e){this.logger.info(`ViewportPlugin`,`Initialize`,`Viewport plugin initialized`)}async destroy(){this.viewportMetrics$.clear(),this.viewportResize$.clear(),this.scrollMetrics$.clear(),this.scrollActivity$.clear(),this.gateState$.clear(),this.scrollRequests$.forEach(e=>e.clear()),this.scrollRequests$.clear(),super.destroy()}},An.id=`viewport`,jn=An,Mn={manifest:mn,create:(e,t)=>new jn(pn,e,t),reducer:kn,initialState:On}})))()}function Pn(e){let{plugin:t}=Ln(),n=A(null);return ve(()=>{if(!t)return;let r=n.current;if(!r)return;try{t.registerViewport(e)}catch(t){console.error(`Failed to register viewport for document ${e}:`,t);return}let i=()=>{t.setViewportScrollMetrics(e,{scrollTop:r.scrollTop,scrollLeft:r.scrollLeft})};r.addEventListener(`scroll`,i);let a=new ResizeObserver(()=>{t.setViewportResizeMetrics(e,{width:r.offsetWidth,height:r.offsetHeight,clientWidth:r.clientWidth,clientHeight:r.clientHeight,scrollTop:r.scrollTop,scrollLeft:r.scrollLeft,scrollWidth:r.scrollWidth,scrollHeight:r.scrollHeight,clientLeft:r.clientLeft,clientTop:r.clientTop})});a.observe(r);let o=t.onScrollRequest(e,({x:e,y:t,behavior:n=`auto`})=>{requestAnimationFrame(()=>{r.scrollTo({left:e,top:t,behavior:n})})});return()=>{t.unregisterViewport(e),a.disconnect(),r.removeEventListener(`scroll`,i),o()}},[t,e]),n}function Fn({children:e,documentId:t,...n}){let[r,i]=j(0),a=Pn(t),{provides:o}=Rn(),s=zn(t);O(()=>{o&&i(o.getViewportGap())},[o]);let{style:c,...l}=n;return/* @__PURE__ */ M(In.Provider,{value:a,children:/* @__PURE__ */ M(`div`,{...l,ref:a,style:{width:`100%`,height:`100%`,overflow:`auto`,...typeof c==`object`?c:{},padding:`${r}px`},children:!s&&e})})}var In,Ln,Rn,zn;function Bn(){return(Bn=e((()=>{q(),Nn(),In=me(null),Ln=()=>W(jn.id),Rn=()=>G(jn.id),zn=e=>{let{provides:t}=Rn(),[n,r]=j(t?.isGated(e)??!1);return O(()=>{if(t)return r(t.isGated(e)),t.onGateChange(t=>{t.documentId===e&&r(t.isGated)})},[t,e]),n}})))()}function Vn(e,t){return{type:Jn,payload:{documentId:e,state:t}}}function Hn(e){return{type:Yn,payload:e}}function Un(e,t){return{type:Xn,payload:{documentId:e,state:t}}}function Wn(e,t){return{type:Zn,payload:{documentId:e,strategy:t}}}var J,Gn,Kn,qn,Jn,Yn,Xn,Zn,Qn,$n,er,tr,nr,rr,ir,ar,or;function sr(){return(sr=e((()=>{U(),C(),J=/* @__PURE__ */ (e=>(e.Vertical=`vertical`,e.Horizontal=`horizontal`,e))(J||{}),Gn=class{constructor(e){this.pageGap=e.pageGap??20,this.viewportGap=e.viewportGap??20,this.bufferSize=e.bufferSize??2}getCenteringOffsetX(e,t){return!t||e.width>=t.width?0:(t.width-e.width)/2}getCenteringOffsetY(e,t){return 0}getVisibleRange(e,t,n){let r=this.getScrollOffset(e),i=this.getClientSize(e),a=r,o=r+i,s=0;for(;s<t.length&&(t[s].offset+this.getItemSizeAlongScrollAxis(t[s]))*n<=a;)s++;let c=s;for(;c<t.length&&t[c].offset*n<=o;)c++;return{start:Math.max(0,s-this.bufferSize),end:Math.min(t.length-1,c+this.bufferSize-1)}}handleScroll(e,t,n){let r=this.getVisibleRange(e,t,n),i=t.slice(r.start,r.end+1),a=this.getTotalContentSize(t),o=this.calculatePageVisibility(i,e,n,a),s=o.map(e=>e.pageNumber),c=t.slice(r.start,r.end+1).flatMap(e=>e.index),l=this.determineCurrentPage(o),u=t[r.start],d=t[r.end],f=u?u.offset*n:0,p=t[t.length-1],m=d?(p.offset+this.getItemSizeAlongScrollAxis(p))*n-(d.offset+this.getItemSizeAlongScrollAxis(d))*n:0;return{currentPage:l,visiblePages:s,pageVisibilityMetrics:o,renderedPageIndexes:c,scrollOffset:{x:e.scrollLeft,y:e.scrollTop},startSpacing:f,endSpacing:m}}calculatePageVisibility(e,t,n,r){let i=[];return e.forEach(e=>{let a=this.getCenteringOffsetX(e,r),o=this.getCenteringOffsetY(e,r);e.pageLayouts.forEach(r=>{let s=(e.x+a)*n,c=(e.y+o)*n,l=s+r.x*n,u=c+r.y*n,d=r.rotatedWidth*n,f=r.rotatedHeight*n,p=t.scrollLeft,m=t.scrollTop,h=p+t.clientWidth,g=m+t.clientHeight,_=Math.max(l,p),v=Math.max(u,m),y=Math.min(l+d,h),b=Math.min(u+f,g);if(_<y&&v<b){let e=y-_,t=b-v,a=d*f,o=e*t;i.push({pageNumber:r.pageNumber,viewportX:_-p,viewportY:v-m,visiblePercentage:o/a*100,original:{pageX:(_-l)/n,pageY:(v-u)/n,visibleWidth:e/n,visibleHeight:t/n,scale:1},scaled:{pageX:_-l,pageY:v-u,visibleWidth:e,visibleHeight:t,scale:n}})}})}),i}determineCurrentPage(e){if(e.length===0)return 1;let t=Math.max(...e.map(e=>e.visiblePercentage)),n=e.filter(e=>e.visiblePercentage===t);return n.length===1?n[0].pageNumber:n.sort((e,t)=>e.pageNumber-t.pageNumber)[0].pageNumber}getRectLocationForPage(e,t,n){let r=t.find(t=>t.pageNumbers.includes(e));if(!r)return null;let i=r.pageLayouts.find(t=>t.pageNumber===e);if(!i)return null;let a=this.getCenteringOffsetX(r,n),o=this.getCenteringOffsetY(r,n);return{origin:{x:r.x+i.x+a,y:r.y+i.y+o},size:{width:i.width,height:i.height}}}getScrollPositionForPage(e,t,n,r,i){let a=this.getTotalContentSize(t),o=this.getRectLocationForPage(e,t,a);if(!o)return null;let s=ie(o.origin,n);if(i){let e=ne({width:o.size.width,height:o.size.height},{x:i.x,y:i.y},r,n);return{x:s.x+e.x+this.viewportGap,y:s.y+e.y+this.viewportGap}}return{x:s.x+this.viewportGap,y:s.y+this.viewportGap}}getRectPositionForPage(e,t,n,r,i){let a=this.getTotalContentSize(t),o=this.getRectLocationForPage(e,t,a);if(!o)return null;let s=ie(o.origin,n),c=oe({width:o.size.width,height:o.size.height},i,r,n);return{origin:{x:s.x+c.origin.x,y:s.y+c.origin.y},size:c.size}}},Kn=class extends Gn{constructor(e){super(e)}createVirtualItems(e){let t=0;return e.map((e,n)=>{let r=0,i=e.map(e=>{let t={pageNumber:e.index+1,pageIndex:e.index,x:r,y:0,width:e.size.width,height:e.size.height,rotatedWidth:e.rotatedSize.width,rotatedHeight:e.rotatedSize.height,elevated:!1};return r+=e.rotatedSize.width+this.pageGap,t}),a=e.reduce((t,n,r)=>t+n.rotatedSize.width+(r<e.length-1?this.pageGap:0),0),o=Math.max(...e.map(e=>e.rotatedSize.height)),s={id:`item-${n}`,x:0,y:t,offset:t,width:a,height:o,pageLayouts:i,pageNumbers:e.map(e=>e.index+1),index:n};return t+=o+this.pageGap,s})}getTotalContentSize(e){return e.length===0?{width:0,height:0}:{width:Math.max(...e.map(e=>e.width)),height:e[e.length-1].y+e[e.length-1].height}}getScrollOffset(e){return e.scrollTop}getClientSize(e){return e.clientHeight}getItemSizeAlongScrollAxis(e){return e.height}},qn=class extends Gn{constructor(e){super(e)}createVirtualItems(e){let t=0;return e.map((e,n)=>{let r=0,i=e.map(e=>{let t={pageNumber:e.index+1,pageIndex:e.index,x:r,y:0,width:e.size.width,height:e.size.height,rotatedWidth:e.rotatedSize.width,rotatedHeight:e.rotatedSize.height,elevated:!1};return r+=e.rotatedSize.width+this.pageGap,t}),a=e.reduce((t,n,r)=>t+n.rotatedSize.width+(r<e.length-1?this.pageGap:0),0),o=Math.max(...e.map(e=>e.rotatedSize.height)),s={id:`item-${n}`,x:t,y:0,offset:t,width:a,height:o,pageLayouts:i,pageNumbers:e.map(e=>e.index+1),index:n};return t+=a+this.pageGap,s})}getTotalContentSize(e){return e.length===0?{width:0,height:0}:{width:e[e.length-1].x+e[e.length-1].width,height:Math.max(...e.map(e=>e.height))}}getScrollOffset(e){return e.scrollLeft}getClientSize(e){return e.clientWidth}getItemSizeAlongScrollAxis(e){return e.width}getCenteringOffsetX(e,t){return 0}getCenteringOffsetY(e,t){return!t||e.height>=t.height?0:(t.height-e.height)/2}},Jn=`INIT_SCROLL_STATE`,Yn=`CLEANUP_SCROLL_STATE`,Xn=`UPDATE_DOCUMENT_SCROLL_STATE`,Zn=`SET_SCROLL_STRATEGY`,Qn={isChanging:!1,targetPage:1,fromPage:1,startTime:0},$n=(e,t)=>({defaultStrategy:t.defaultStrategy??J.Vertical,defaultPageGap:t.defaultPageGap??10,defaultBufferSize:t.defaultBufferSize??2,documents:{}}),er=(e,t)=>{switch(t.type){case Jn:{let{documentId:n,state:r}=t.payload;return{...e,documents:{...e.documents,[n]:r}}}case Yn:{let{[t.payload]:n,...r}=e.documents;return{...e,documents:r}}case Xn:{let{documentId:n,state:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,...r}}}:e}case Zn:{let{documentId:n,strategy:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,strategy:r}}}:e}default:return e}},tr=(e,t,n)=>({startSpacing:e.startSpacing,endSpacing:e.endSpacing,totalWidth:e.totalContentSize.width*t,totalHeight:e.totalContentSize.height*t,pageGap:e.pageGap*t,strategy:e.strategy,items:e.renderedPageIndexes.map(r=>({...e.virtualItems[r],pageLayouts:e.virtualItems[r].pageLayouts.map(e=>({...e,rotatedWidth:e.rotatedWidth*t,rotatedHeight:e.rotatedHeight*t,width:e.width*t,height:e.height*t,elevated:n?.has(e.pageIndex)??!1}))}))}),nr=class extends H{constructor(e,t,n){var r;super(e,t),this.id=e,this.config=n,this.elevatedPages=/* @__PURE__ */ new Map,this.strategies=/* @__PURE__ */ new Map,this.layoutReady=/* @__PURE__ */ new Set,this.initialLayoutFired=/* @__PURE__ */ new Set,this.scrollerLayoutEmitters=/* @__PURE__ */ new Map,this.pageChange$=L(),this.scroll$=L(),this.layoutChange$=L(),this.pageChangeState$=L(),this.layoutReady$=L(),this.state$=L(),this.viewport=this.registry.getPlugin(`viewport`).provides(),this.spread=this.registry.getPlugin(`spread`)?.provides()??null,this.viewport.onScrollActivity(e=>{this.getDocumentState(e.documentId)?.pageChangeState.isChanging&&!e.activity.isSmoothScrolling&&this.completePageChange(e.documentId)}),(r=this.spread)==null||r.onSpreadChange(e=>{this.refreshDocumentLayout(e.documentId)});let i=this.registry.getPlugin(`interaction-manager`)?.provides();i&&i.onPageActivityChange(e=>{let t=this.elevatedPages.get(e.documentId);e.hasActivity?(t||(t=/* @__PURE__ */ new Set,this.elevatedPages.set(e.documentId,t)),t.add(e.pageIndex)):t?.delete(e.pageIndex),this.pushScrollerLayout(e.documentId)}),this.viewport.onViewportChange(e=>{let t=this.getDocumentState(e.documentId);if(!t)return;let n=this.computeMetrics(e.documentId,e.metrics);this.layoutReady.has(e.documentId)?this.commitMetrics(e.documentId,n):this.commitMetrics(e.documentId,{...n,scrollOffset:t.scrollOffset})})}onDocumentLoadingStarted(e){let t=this.getCoreDocument(e);if(!t)return;let n=this.createDocumentState(t);this.dispatch(Vn(e,n));let r=this.createStrategy(n.strategy);this.strategies.set(e,r),this.scrollerLayoutEmitters.set(e,L())}onDocumentLoaded(e){let t=this.getCoreDocument(e);t&&(this.dispatch(Un(e,{totalPages:t.document?.pageCount??0})),this.refreshDocumentLayout(e),this.logger.debug(`ScrollPlugin`,`DocumentOpened`,`Initialized scroll state for document: ${e}`))}onDocumentClosed(e){this.strategies.delete(e),this.layoutReady.delete(e),this.initialLayoutFired.delete(e),this.elevatedPages.delete(e);let t=this.scrollerLayoutEmitters.get(e);t&&(t.clear(),this.scrollerLayoutEmitters.delete(e)),this.dispatch(Hn(e)),this.logger.debug(`ScrollPlugin`,`DocumentClosed`,`Cleaned up scroll state for document: ${e}`)}onScaleChanged(e){let t=this.coreState.core.documents[e];if(!t||t.status!==`loaded`)return;let n=this.viewport.forDocument(e),r=this.computeMetrics(e,n.getMetrics());this.commitMetrics(e,r)}onRotationChanged(e){this.refreshDocumentLayout(e)}onScrollerData(e,t){let n=this.scrollerLayoutEmitters.get(e);if(!n)throw Error(`No scroller layout emitter found for document: ${e}`);return n.on(t)}getScrollerLayout(e){let t=this.getDocumentState(e),n=this.getCoreDocumentOrThrow(e);if(!t||!n)throw Error(`Cannot get scroller layout for document: ${e}`);return tr(t,n.scale,this.elevatedPages.get(e))}setLayoutReady(e){if(this.layoutReady.has(e))return;let t=this.getDocumentState(e);if(!t)return;this.layoutReady.add(e);let n=!this.initialLayoutFired.has(e);n&&this.initialLayoutFired.add(e),this.viewport.forDocument(e).scrollTo({...t.scrollOffset,behavior:`instant`}),this.layoutReady$.emit({documentId:e,isInitial:n,pageNumber:t.currentPage,totalPages:t.totalPages})}clearLayoutReady(e){this.layoutReady.delete(e)}buildCapability(){return{getCurrentPage:()=>this.getCurrentPage(),getTotalPages:()=>this.getTotalPages(),getPageChangeState:()=>this.getPageChangeState(),scrollToPage:e=>this.scrollToPage(e),scrollToNextPage:e=>this.scrollToNextPage(e),scrollToPreviousPage:e=>this.scrollToPreviousPage(e),getMetrics:e=>this.getMetrics(e),getLayout:()=>this.getLayout(),getRectPositionForPage:(e,t,n,r)=>this.getRectPositionForPage(e,t,n,r),forDocument:e=>this.createScrollScope(e),setScrollStrategy:(e,t)=>this.setScrollStrategyForDocument(e,t),getPageGap:()=>this.state.defaultPageGap,onPageChange:this.pageChange$.on,onScroll:this.scroll$.on,onLayoutChange:this.layoutChange$.on,onLayoutReady:this.layoutReady$.on,onPageChangeState:this.pageChangeState$.on,onStateChange:this.state$.on}}createScrollScope(e){return{getCurrentPage:()=>this.getCurrentPage(e),getTotalPages:()=>this.getTotalPages(e),getPageChangeState:()=>this.getPageChangeState(e),scrollToPage:t=>this.scrollToPage(t,e),scrollToNextPage:t=>this.scrollToNextPage(t,e),scrollToPreviousPage:t=>this.scrollToPreviousPage(t,e),getSpreadPagesWithRotatedSize:()=>this.getSpreadPagesWithRotatedSize(e),getMetrics:t=>this.getMetrics(t,e),getLayout:()=>this.getLayout(e),getRectPositionForPage:(t,n,r,i)=>this.getRectPositionForPage(t,n,r,i,e),setScrollStrategy:t=>this.setScrollStrategyForDocument(t,e),onPageChange:t=>this.pageChange$.on(n=>{n.documentId===e&&t(n)}),onScroll:t=>this.scroll$.on(n=>{n.documentId===e&&t(n.metrics)}),onLayoutChange:t=>this.layoutChange$.on(n=>{n.documentId===e&&t(n.layout)})}}getDocumentState(e){let t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){let t=this.getDocumentState(e);if(!t)throw Error(`Scroll state not found for document: ${e??`active`}`);return t}getStrategy(e){let t=e??this.getActiveDocumentId(),n=this.strategies.get(t);if(!n)throw Error(`Strategy not found for document: ${t}`);return n}createStrategy(e){let t={pageGap:this.state.defaultPageGap,viewportGap:this.viewport.getViewportGap(),bufferSize:this.state.defaultBufferSize};return e===J.Horizontal?new qn(t):new Kn(t)}createDocumentState(e){return{virtualItems:[],totalPages:e.document?.pageCount??0,currentPage:1,totalContentSize:{width:0,height:0},strategy:this.state.defaultStrategy,pageGap:this.state.defaultPageGap,visiblePages:[],pageVisibilityMetrics:[],renderedPageIndexes:[],scrollOffset:{x:0,y:0},startSpacing:0,endSpacing:0,pageChangeState:Qn}}startPageChange(e,t,n=`smooth`){let r=this.getDocumentState(e);if(!r)return;let i={isChanging:!0,targetPage:t,fromPage:r.currentPage,startTime:Date.now()};this.dispatch(Un(e,{pageChangeState:i,currentPage:t})),this.pageChange$.emit({documentId:e,pageNumber:t,totalPages:r.totalPages}),n===`instant`&&this.completePageChange(e)}completePageChange(e){let t=this.getDocumentState(e);if(!t||!t.pageChangeState.isChanging)return;let n={isChanging:!1,targetPage:t.pageChangeState.targetPage,fromPage:t.pageChangeState.fromPage,startTime:t.pageChangeState.startTime};this.dispatch(Un(e,{pageChangeState:n}))}computeLayout(e,t){let n=this.getStrategy(e),r=n.createVirtualItems(t);return{virtualItems:r,totalContentSize:n.getTotalContentSize(r)}}computeMetrics(e,t,n){let r=this.getCoreDocumentOrThrow(e),i=this.getDocumentState(e),a=this.getStrategy(e);if(!i)throw Error(`Document state not found: ${e}`);return a.handleScroll(t,n??i.virtualItems,r.scale)}commitMetrics(e,t){let n=this.getDocumentState(e);if(!n)return;let r=n.pageChangeState.isChanging,i=r&&t.currentPage!==n.currentPage?{...t,currentPage:n.currentPage}:t;this.dispatch(Un(e,i)),this.scroll$.emit({documentId:e,metrics:i}),!r&&t.currentPage!==n.currentPage&&this.pageChange$.emit({documentId:e,pageNumber:t.currentPage,totalPages:n.totalPages}),this.pushScrollerLayout(e)}pushScrollerLayout(e){let t=this.scrollerLayoutEmitters.get(e);if(t)try{let n=this.getScrollerLayout(e);t.emit(n)}catch{}}refreshDocumentLayout(e){let t=this.coreState.core.documents[e],n=this.getDocumentState(e);if(!t||!n||t.status!==`loaded`)return;let r=this.getSpreadPagesWithRotatedSize(e),i=this.computeLayout(e,r),a=this.viewport.forDocument(e),o=this.computeMetrics(e,a.getMetrics(),i.virtualItems);this.dispatch(Un(e,{...i,...o})),this.layoutChange$.emit({documentId:e,layout:i}),this.pushScrollerLayout(e)}getSpreadPagesWithRotatedSize(e){let t=e??this.getActiveDocumentId(),n=this.coreState.core.documents[t];if(!n)throw Error(`Document ${t} not loaded`);return(this.spread?.forDocument(t).getSpreadPages()||n.document?.pages.map(e=>[e])||[]).map(e=>e.map(e=>{let t=((e.rotation??0)+n.rotation)%4;return{...e,rotatedSize:ae(e.size,t,1)}}))}getCurrentPage(e){return this.getDocumentStateOrThrow(e).currentPage}getTotalPages(e){return this.getDocumentStateOrThrow(e).totalPages}getPageChangeState(e){return this.getDocumentStateOrThrow(e).pageChangeState}scrollToPage(e,t){let n=t??this.getActiveDocumentId(),r=this.getDocumentStateOrThrow(n),i=this.getStrategy(n),a=this.getCoreDocumentOrThrow(n),{pageNumber:o,behavior:s=`smooth`,pageCoordinates:c,alignX:l,alignY:u}=e;this.startPageChange(n,o,s);let d=((a.document?.pages[o-1]?.rotation??0)+a.rotation)%4,f=i.getScrollPositionForPage(o,r.virtualItems,a.scale,d,c);f?this.viewport.forDocument(n).scrollTo({...f,behavior:s,alignX:l,alignY:u}):this.completePageChange(n)}scrollToNextPage(e=`smooth`,t){let n=t??this.getActiveDocumentId(),r=this.getDocumentStateOrThrow(n),i=this.getStrategy(n),a=this.getCoreDocumentOrThrow(n),o=r.virtualItems.findIndex(e=>e.pageNumbers.includes(r.currentPage));if(o>=0&&o<r.virtualItems.length-1){let t=r.virtualItems[o+1].pageNumbers[0];this.startPageChange(n,t,e);let s=i.getScrollPositionForPage(t,r.virtualItems,a.scale,a.rotation);s?this.viewport.forDocument(n).scrollTo({...s,behavior:e}):this.completePageChange(n)}}scrollToPreviousPage(e=`smooth`,t){let n=t??this.getActiveDocumentId(),r=this.getDocumentStateOrThrow(n),i=this.getStrategy(n),a=this.coreState.core.documents[n],o=r.virtualItems.findIndex(e=>e.pageNumbers.includes(r.currentPage));if(o>0){let t=r.virtualItems[o-1].pageNumbers[0];this.startPageChange(n,t,e);let s=i.getScrollPositionForPage(t,r.virtualItems,a.scale,a.rotation);s?this.viewport.forDocument(n).scrollTo({...s,behavior:e}):this.completePageChange(n)}}getMetrics(e,t){let n=t??this.getActiveDocumentId();if(e)return this.computeMetrics(n,e);let r=this.viewport.forDocument(n);return this.computeMetrics(n,r.getMetrics())}getLayout(e){let t=this.getDocumentStateOrThrow(e);return{virtualItems:t.virtualItems,totalContentSize:t.totalContentSize}}getRectPositionForPage(e,t,n,r,i){let a=i??this.getActiveDocumentId(),o=this.getDocumentStateOrThrow(a),s=this.getStrategy(a),c=this.getCoreDocumentOrThrow(a),l=r;return l===void 0&&(l=((c.document?.pages[e]?.rotation??0)+c.rotation)%4),s.getRectPositionForPage(e+1,o.virtualItems,n??c.scale,l,t)}setScrollStrategyForDocument(e,t){let n=t??this.getActiveDocumentId(),r=this.getDocumentState(n);if(!r||r.strategy===e)return;let i=this.createStrategy(e);this.strategies.set(n,i),this.dispatch(Wn(n,e)),this.refreshDocumentLayout(n)}onStoreUpdated(e,t){for(let n in t.documents){let r=e.documents[n],i=t.documents[n];r!==i&&(this.state$.emit(i),r?.pageChangeState!==i.pageChangeState&&this.pageChangeState$.emit({documentId:n,state:i.pageChangeState}),this.pushScrollerLayout(n))}}async initialize(){this.logger.info(`ScrollPlugin`,`Initialize`,`Scroll plugin initialized`)}async destroy(){this.strategies.clear(),this.layoutReady.clear(),this.initialLayoutFired.clear(),this.elevatedPages.clear();for(let e of this.scrollerLayoutEmitters.values())e.clear();this.scrollerLayoutEmitters.clear(),this.pageChange$.clear(),this.scroll$.clear(),this.layoutChange$.clear(),this.pageChangeState$.clear(),this.layoutReady$.clear(),this.state$.clear(),super.destroy()}},nr.id=`scroll`,rr=nr,ir=`scroll`,ar={id:ir,name:`Scroll Plugin`,version:`1.0.0`,provides:[`scroll`],requires:[`viewport`],optional:[`spread`,`interaction-manager`],defaultConfig:{defaultPageGap:10,defaultBufferSize:4,defaultStrategy:J.Vertical}},or={manifest:ar,create:(e,t)=>new rr(ir,e,t),reducer:er,initialState:(e,t)=>$n(e,t)}})))()}function cr({documentId:e,renderPage:t,...n}){let{plugin:r}=lr(),[i,a]=j({layout:null,docId:null});O(()=>{if(!r||!e)return;let t=r.onScrollerData(e,t=>{a({layout:t,docId:e})});return()=>{t(),a({layout:null,docId:null}),r.clearLayoutReady(e)}},[r,e]);let o=i.docId===e?i.layout:null;return ve(()=>{r&&e&&o&&r.setLayoutReady(e)},[r,e,o]),o?/* @__PURE__ */ N(`div`,{...n,style:{width:`${o.totalWidth}px`,height:`${o.totalHeight}px`,position:`relative`,boxSizing:`border-box`,margin:`0 auto`,...o.strategy===J.Horizontal&&{display:`flex`,flexDirection:`row`}},children:[/* @__PURE__ */ M(`div`,{style:{...o.strategy===J.Horizontal?{width:o.startSpacing,height:`100%`,flexShrink:0}:{height:o.startSpacing,width:`100%`}}}),/* @__PURE__ */ M(`div`,{style:{gap:o.pageGap,display:`flex`,alignItems:`center`,position:`relative`,boxSizing:`border-box`,...o.strategy===J.Horizontal?{flexDirection:`row`,minHeight:`100%`}:{flexDirection:`column`,minWidth:`fit-content`}},children:o.items.map(e=>/* @__PURE__ */ M(`div`,{style:{display:`flex`,justifyContent:`center`,gap:o.pageGap},children:e.pageLayouts.map(e=>/* @__PURE__ */ M(`div`,{style:{width:`${e.rotatedWidth}px`,height:`${e.rotatedHeight}px`,position:`relative`,zIndex:e.elevated?1:void 0},children:t({...e})},e.pageNumber))},e.pageNumbers[0]))}),/* @__PURE__ */ M(`div`,{style:{...o.strategy===J.Horizontal?{width:o.endSpacing,height:`100%`,flexShrink:0}:{height:o.endSpacing,width:`100%`}}})]}):null}var lr,ur,dr;function fr(){return(fr=e((()=>{q(),sr(),lr=()=>W(rr.id),ur=()=>G(rr.id),dr=e=>{let{provides:t}=ur(),[n,r]=j(1),[i,a]=j(1);return O(()=>{if(!t||!e)return;let n=t.forDocument(e);return r(n.getCurrentPage()),a(n.getTotalPages()),t.onPageChange(t=>{t.documentId===e&&(r(t.pageNumber),a(t.totalPages))})},[t,e]),{provides:t?.forDocument(e)??null,state:{currentPage:n,totalPages:i}}}})))()}var pr,mr,hr,gr;function _r(){return(_r=e((()=>{U(),pr=class extends H{constructor(e,t,n){super(e,t),this.config=n}buildCapability(){return{renderPage:e=>this.renderPage(e),renderPageRect:e=>this.renderPageRect(e),renderPageRaw:e=>this.renderPageRaw(e),renderPageRectRaw:e=>this.renderPageRectRaw(e),forDocument:e=>this.createRenderScope(e)}}createRenderScope(e){return{renderPage:t=>this.renderPage(t,e),renderPageRect:t=>this.renderPageRect(t,e),renderPageRaw:t=>this.renderPageRaw(t,e),renderPageRectRaw:t=>this.renderPageRectRaw(t,e)}}renderPage({pageIndex:e,options:t},n){let r=n??this.getActiveDocumentId(),i=this.coreState.core.documents[r];if(!i?.document)throw Error(`Document ${r} not loaded`);let a=i.document.pages.find(t=>t.index===e);if(!a)throw Error(`Page ${e} not found in document ${r}`);let o={...t??{},withForms:t?.withForms??this.config.withForms??!1,withAnnotations:t?.withAnnotations??this.config.withAnnotations??!1,imageType:t?.imageType??this.config.defaultImageType??`image/png`,imageQuality:t?.imageQuality??this.config.defaultImageQuality??.92};return this.engine.renderPage(i.document,a,o)}renderPageRect({pageIndex:e,rect:t,options:n},r){let i=r??this.getActiveDocumentId(),a=this.coreState.core.documents[i];if(!a?.document)throw Error(`Document ${i} not loaded`);let o=a.document.pages.find(t=>t.index===e);if(!o)throw Error(`Page ${e} not found in document ${i}`);let s={...n??{},withForms:n?.withForms??this.config.withForms??!1,withAnnotations:n?.withAnnotations??this.config.withAnnotations??!1,imageType:n?.imageType??this.config.defaultImageType??`image/png`,imageQuality:n?.imageQuality??this.config.defaultImageQuality??.92};return this.engine.renderPageRect(a.document,o,t,s)}renderPageRaw({pageIndex:e,options:t},n){let r=n??this.getActiveDocumentId(),i=this.coreState.core.documents[r];if(!i?.document)throw Error(`Document ${r} not loaded`);let a=i.document.pages.find(t=>t.index===e);if(!a)throw Error(`Page ${e} not found in document ${r}`);let o={...t??{},withForms:t?.withForms??this.config.withForms??!1,withAnnotations:t?.withAnnotations??this.config.withAnnotations??!1};return this.engine.renderPageRaw(i.document,a,o)}renderPageRectRaw({pageIndex:e,rect:t,options:n},r){let i=r??this.getActiveDocumentId(),a=this.coreState.core.documents[i];if(!a?.document)throw Error(`Document ${i} not loaded`);let o=a.document.pages.find(t=>t.index===e);if(!o)throw Error(`Page ${e} not found in document ${i}`);let s={...n??{},withForms:n?.withForms??this.config.withForms??!1,withAnnotations:n?.withAnnotations??this.config.withAnnotations??!1};return this.engine.renderPageRectRaw(a.document,o,t,s)}async initialize(e){this.logger.info(`RenderPlugin`,`Initialize`,`Render plugin initialized`)}async destroy(){super.destroy()}},pr.id=`render`,mr=pr,hr=`render`,gr={manifest:{id:hr,name:`Render Plugin`,version:`1.0.0`,provides:[`render`],requires:[],optional:[],defaultConfig:{}},create:(e,t)=>new mr(hr,e,t),reducer:()=>{},initialState:{}}})))()}function vr({documentId:e,pageIndex:t,scale:n,dpr:r,style:i,...a}){let{provides:o}=yr(),s=K(e),[c,l]=j(null),u=A(null),d=k(()=>s&&s.pageRefreshVersions[t]||0,[s,t]),f=k(()=>n===void 0?s?.scale??1:n,[n,s?.scale]),p=k(()=>r===void 0?window.devicePixelRatio:r,[r]);return O(()=>{if(!o)return;let n=o.forDocument(e).renderPage({pageIndex:t,options:{scaleFactor:f,dpr:p}});return n.wait(e=>{let t=URL.createObjectURL(e);l(t),u.current=t},T),()=>{u.current?(URL.revokeObjectURL(u.current),u.current=null):n.abort({code:D.Cancelled,message:`canceled render task`})}},[e,t,f,p,o,d]),/* @__PURE__ */ M(pe,{children:c&&/* @__PURE__ */ M(`img`,{src:c,onLoad:()=>{u.current&&=(URL.revokeObjectURL(u.current),null)},...a,style:{width:`100%`,height:`100%`,...i||{}}})})}var yr;function br(){return(br=e((()=>{C(),q(),_r(),yr=()=>G(mr.id)})))()}function xr(e,t){return{type:Or,payload:{documentId:e,state:t}}}function Sr(e){return{type:kr,payload:e}}function Cr(e,t,n){return{type:jr,payload:{documentId:e,zoomLevel:t,currentZoomLevel:n}}}function wr(e,t){return{type:Mr,payload:{documentId:e,isActive:t}}}function Tr(e){let{pageSize:t,scale:n,minDragPx:r=5,onPreview:i,onCommit:a,onSmallDrag:o}=e,s=null,c=null;return{onPointerDown:(e,t)=>{var n;s=e,c={origin:{x:e.x,y:e.y},size:{width:0,height:0}},i?.(c),(n=t.setPointerCapture)==null||n.call(t)},onPointerMove:e=>{if(!s)return;let n=F(e.x,0,t.width),r=F(e.y,0,t.height);c={origin:{x:Math.min(s.x,n),y:Math.min(s.y,r)},size:{width:Math.abs(n-s.x),height:Math.abs(r-s.y)}},i?.(c)},onPointerUp:(e,t)=>{var l;c&&(Math.max(c.size.width,c.size.height)*n>r?a?.(c):o?.()),s=null,c=null,i?.(null),(l=t.releasePointerCapture)==null||l.call(t)},onPointerCancel:(e,t)=>{var n;s=null,c=null,i?.(null),(n=t.releasePointerCapture)==null||n.call(t)}}}var Y,X,Er,Dr,Or,kr,Ar,jr,Mr,Nr,Pr,Fr,Ir,Lr,Rr;function zr(){return(zr=e((()=>{U(),C(),Y=/* @__PURE__ */ (e=>(e.Automatic=`automatic`,e.FitPage=`fit-page`,e.FitWidth=`fit-width`,e))(Y||{}),X=/* @__PURE__ */ (e=>(e[e.Center=0]=`Center`,e[e.Top=1]=`Top`,e))(X||{}),Er=`zoom`,Dr={id:Er,name:`Zoom Plugin`,version:`1.0.0`,provides:[`zoom`],requires:[`viewport`,`scroll`],optional:[`interaction-manager`,`spread`],defaultConfig:{defaultZoomLevel:Y.Automatic,minZoom:.2,maxZoom:60,zoomStep:.1,zoomRanges:[{min:.2,max:.5,step:.05},{min:.5,max:1,step:.1},{min:1,max:2,step:.2},{min:2,max:4,step:.4},{min:4,max:10,step:.8},{min:10,max:20,step:1.6},{min:20,max:40,step:3.2},{min:40,max:60,step:6.4}],presets:[{name:`Fit Page`,value:Y.FitPage},{name:`Fit Width`,value:Y.FitWidth},{name:`Automatic`,value:Y.Automatic},{name:`25%`,value:.25},{name:`50%`,value:.5},{name:`100%`,value:1},{name:`125%`,value:1.25},{name:`150%`,value:1.5},{name:`200%`,value:2},{name:`400%`,value:4},{name:`800%`,value:8},{name:`1600%`,value:16}]}},Or=`ZOOM/INIT_STATE`,kr=`ZOOM/CLEANUP_STATE`,Ar=`ZOOM/SET_ACTIVE_DOCUMENT`,jr=`ZOOM/SET_ZOOM_LEVEL`,Mr=`ZOOM/SET_MARQUEE_ZOOM_ACTIVE`,Nr={zoomLevel:Y.Automatic,currentZoomLevel:1,isMarqueeZoomActive:!1},Pr={documents:{},activeDocumentId:null},Fr=(e=Pr,t)=>{switch(t.type){case Or:{let{documentId:n,state:r}=t.payload;return{...e,documents:{...e.documents,[n]:r},activeDocumentId:e.activeDocumentId??n}}case kr:{let n=t.payload,{[n]:r,...i}=e.documents;return{...e,documents:i,activeDocumentId:e.activeDocumentId===n?null:e.activeDocumentId}}case Ar:return{...e,activeDocumentId:t.payload};case jr:{let{documentId:n,zoomLevel:r,currentZoomLevel:i}=t.payload,a=e.documents[n];return a?{...e,documents:{...e.documents,[n]:{...a,zoomLevel:r,currentZoomLevel:i}}}:e}case Mr:{let{documentId:n,isActive:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,isMarqueeZoomActive:r}}}:e}default:return e}},Ir=class extends H{constructor(e,t,n){var r,i,a;super(e,t),this.zoom$=I(),this.state$=L(),this.viewportPlugin=t.getPlugin(`viewport`),this.viewport=this.viewportPlugin.provides(),this.scroll=t.getPlugin(`scroll`).provides();let o=t.getPlugin(`interaction-manager`);this.interactionManager=o?.provides()??null;let s=t.getPlugin(`spread`);this.spread=s?.provides()??null,this.minZoom=n.minZoom??.25,this.maxZoom=n.maxZoom??10,this.zoomStep=n.zoomStep??.1,this.defaultZoomLevel=n.defaultZoomLevel,this.presets=n.presets??[],this.zoomRanges=this.normalizeRanges(n.zoomRanges??[]),this.viewport.onViewportResize(e=>this.recalcAuto(e.documentId,X.Top),{mode:`debounce`,wait:150,keyExtractor:e=>e.documentId}),(r=this.spread)==null||r.onSpreadChange(e=>{this.recalcAuto(e.documentId,X.Top)}),(i=this.interactionManager)==null||i.registerMode({id:`marqueeZoom`,scope:`page`,exclusive:!0,cursor:`zoom-in`}),(a=this.interactionManager)==null||a.onModeChange(e=>{let t=e.activeMode===`marqueeZoom`,n=this.getDocumentState(e.documentId);n&&n.isMarqueeZoomActive!==t&&this.dispatch(wr(e.documentId,t))})}onDocumentLoadingStarted(e){this.viewport.gate(`zoom`,e);let t={...Nr,zoomLevel:this.defaultZoomLevel};this.dispatch(xr(e,t)),this.logger.debug(`ZoomPlugin`,`DocumentOpened`,`Initialized zoom state for document: ${e}`)}onDocumentLoaded(e){this.recalcAuto(e,X.Top)}onDocumentClosed(e){this.dispatch(Sr(e)),this.logger.debug(`ZoomPlugin`,`DocumentClosed`,`Cleaned up zoom state for document: ${e}`)}onRotationChanged(e){this.recalcAuto(e,X.Top)}buildCapability(){return{requestZoom:(e,t)=>this.requestZoom(e,t),requestZoomBy:(e,t)=>this.requestZoomBy(e,t),zoomIn:()=>this.zoomIn(),zoomOut:()=>this.zoomOut(),zoomToArea:(e,t)=>this.zoomToArea(e,t),enableMarqueeZoom:()=>this.enableMarqueeZoom(),disableMarqueeZoom:()=>this.disableMarqueeZoom(),toggleMarqueeZoom:()=>this.toggleMarqueeZoom(),isMarqueeZoomActive:()=>this.isMarqueeZoomActive(),getState:()=>this.getDocumentStateOrThrow(),forDocument:e=>this.createZoomScope(e),registerMarqueeOnPage:e=>this.registerMarqueeOnPage(e),getPresets:()=>this.presets,onZoomChange:this.zoom$.on,onStateChange:this.state$.on}}createZoomScope(e){return{requestZoom:(t,n)=>this.requestZoom(t,n,e),requestZoomBy:(t,n)=>this.requestZoomBy(t,n,e),zoomIn:()=>this.zoomIn(e),zoomOut:()=>this.zoomOut(e),zoomToArea:(t,n)=>this.zoomToArea(t,n,e),enableMarqueeZoom:()=>this.enableMarqueeZoom(e),disableMarqueeZoom:()=>this.disableMarqueeZoom(e),toggleMarqueeZoom:()=>this.toggleMarqueeZoom(e),isMarqueeZoomActive:()=>this.isMarqueeZoomActive(e),getState:()=>this.getDocumentStateOrThrow(e),onZoomChange:t=>this.zoom$.on(n=>{n.documentId===e&&t(n)}),onStateChange:t=>this.state$.on(n=>{n.documentId===e&&t(n.state)})}}getDocumentState(e){let t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){let t=this.getDocumentState(e);if(!t)throw Error(`Zoom state not found for document: ${e??`active`}`);return t}requestZoom(e,t,n){this.handleRequest({level:e,center:t},n)}requestZoomBy(e,t,n){let r=n??this.getActiveDocumentId(),i=this.getDocumentStateOrThrow(r).currentZoomLevel,a=this.toZoom(i+e);this.handleRequest({level:a,center:t},r)}zoomIn(e){let t=e??this.getActiveDocumentId(),n=this.getDocumentStateOrThrow(t).currentZoomLevel;this.handleRequest({level:n,delta:this.stepFor(n)},t)}zoomOut(e){let t=e??this.getActiveDocumentId(),n=this.getDocumentStateOrThrow(t).currentZoomLevel;this.handleRequest({level:n,delta:-this.stepFor(n)},t)}zoomToArea(e,t,n){let r=n??this.getActiveDocumentId();this.handleZoomToArea(r,e,t)}enableMarqueeZoom(e){var t;let n=e??this.getActiveDocumentId();(t=this.interactionManager)==null||t.forDocument(n).activate(`marqueeZoom`)}disableMarqueeZoom(e){var t;let n=e??this.getActiveDocumentId();(t=this.interactionManager)==null||t.forDocument(n).activateDefaultMode()}toggleMarqueeZoom(e){let t=e??this.getActiveDocumentId(),n=this.interactionManager?.forDocument(t);n?.getActiveMode()===`marqueeZoom`?n.activateDefaultMode():n?.activate(`marqueeZoom`)}isMarqueeZoomActive(e){let t=e??this.getActiveDocumentId();return this.interactionManager?.forDocument(t).getActiveMode()===`marqueeZoom`}handleRequest({level:e,delta:t=0,center:n,focus:r=X.Center,align:i=`keep`},a){let o=a??this.getActiveDocumentId(),s=this.getDocumentStateOrThrow(o);if(!this.coreState.core.documents[o])return;let c=this.viewport.forDocument(o),l=c.getMetrics(),u=s.currentZoomLevel;if(l.clientWidth===0||l.clientHeight===0)return;let d=typeof e==`number`?e:this.computeZoomForMode(o,e,l);if(d===!1)return;let f=F(d+t,this.minZoom,this.maxZoom),p=Math.floor(f*1e3)/1e3,m=n??{vx:l.clientWidth/2,vy:r===X.Top?0:l.clientHeight/2},{desiredScrollLeft:h,desiredScrollTop:g}=this.computeScrollForZoomChange(o,l,u,p,m,i);!isNaN(h)&&!isNaN(g)&&this.viewportPlugin.setViewportScrollMetrics(o,{scrollLeft:h,scrollTop:g}),this.dispatch(Cr(o,typeof e==`number`?p:e,p)),this.dispatchCoreAction(yt(p,o)),this.viewport.isGated(o)&&this.viewport.releaseGate(`zoom`,o),c.scrollTo({x:h,y:g,behavior:`instant`});let _={documentId:o,oldZoom:u,newZoom:p,level:e,center:m,desiredScrollLeft:h,desiredScrollTop:g,viewport:l};this.zoom$.emit(_)}computeZoomForMode(e,t,n){if(!this.coreState.core.documents[e])return!1;let r=this.scroll.forDocument(e),i=r?this.scroll.getPageGap():0,a=this.viewport.getViewportGap(),o=r.getSpreadPagesWithRotatedSize();if(!o.length||n.clientWidth===0||n.clientHeight===0)return!1;let s=n.clientWidth-2*a,c=n.clientHeight-2*a;if(s<=0||c<=0)return!1;let l=0,u=0;switch(o.forEach(e=>{let t=e.reduce((e,t,n)=>e+t.rotatedSize.width+(n?i:0),0),n=Math.max(...e.map(e=>e.rotatedSize.height));l=Math.max(l,t),u=Math.max(u,n)}),t){case Y.FitWidth:return s/l;case Y.FitPage:return Math.min(s/l,c/u);case Y.Automatic:return Math.min(s/l,1);default:return 1}}computeScrollForZoomChange(e,t,n,r,i,a=`keep`){let o=this.scroll.forDocument(e).getLayout(),s=this.viewport.getViewportGap(),c=o.totalContentSize.width,l=o.totalContentSize.height,u=t.clientWidth-2*s,d=t.clientHeight-2*s,f=(e,t,n)=>t*n<e?(e-t*n)/2:0,p=f(u,c,n),m=f(d,l,n),h=f(u,c,r),g=f(d,l,r),_=(t.scrollLeft+i.vx-s-p)/n,v=(t.scrollTop+i.vy-s-m)/n,y=_*r+s+h,b=v*r+s+g,x=a===`center`?y-t.clientWidth/2:y-i.vx,S=a===`center`?b-t.clientHeight/2:b-i.vy;return{desiredScrollLeft:Math.max(0,x),desiredScrollTop:Math.max(0,S)}}handleZoomToArea(e,t,n){let r=this.coreState.core.documents[e];if(!r)return;let i=r.rotation,a=this.viewport.forDocument(e).getMetrics(),o=this.viewport.getViewportGap(),s=this.getDocumentStateOrThrow(e).currentZoomLevel,c=a.clientWidth-2*o,l=a.clientHeight-2*o,u=this.scroll.forDocument(e).getLayout(),d=u.virtualItems.find(e=>e.pageLayouts.some(e=>e.pageIndex===t));if(!d)return;let f=d.pageLayouts.find(e=>e.pageIndex===t),p=re({width:f.width,height:f.height},n,i),m=this.toZoom(Math.min(c/p.size.width,l/p.size.height)),h=d.x+f.x,g=d.y+f.y,_=h+p.origin.x+p.size.width/2,v=g+p.origin.y+p.size.height/2,y=(e,t,n)=>t*n<e?(e-t*n)/2:0,b=y(c,u.totalContentSize.width,s),x=y(l,u.totalContentSize.height,s),S=o+b+_*s-a.scrollLeft,ee=o+x+v*s-a.scrollTop;this.handleRequest({level:m,center:{vx:S,vy:ee},align:`center`},e)}recalcAuto(e,t){let n=this.getDocumentState(e);n&&(n.zoomLevel===Y.Automatic||n.zoomLevel===Y.FitPage||n.zoomLevel===Y.FitWidth)&&this.handleRequest({level:n.zoomLevel,focus:t},e)}normalizeRanges(e){return[...e].filter(e=>e.step>0&&e.max>e.min).sort((e,t)=>e.min-t.min)}stepFor(e){let t=this.zoomRanges.find(t=>e>=t.min&&e<t.max);return t?t.step:this.zoomStep}toZoom(e){return parseFloat(F(e,this.minZoom,this.maxZoom).toFixed(2))}registerMarqueeOnPage(e){if(!this.interactionManager)return this.logger.warn(`ZoomPlugin`,`MissingDependency`,`Interaction manager plugin not loaded, marquee zoom disabled`),()=>{};let t=this.coreState.core.documents[e.documentId];if(!t||!t.document)return this.logger.warn(`ZoomPlugin`,`DocumentNotFound`,`Document not found`),()=>{};let n=t.document.pages[e.pageIndex];if(!n)return this.logger.warn(`ZoomPlugin`,`PageNotFound`,`Page ${e.pageIndex} not found`),()=>{};let r=Tr({pageSize:n.size,scale:e.scale,onPreview:e.callback.onPreview,onCommit:t=>{var n,r;this.zoomToArea(e.pageIndex,t,e.documentId),(r=(n=e.callback).onCommit)==null||r.call(n,t)},onSmallDrag:()=>{var t,n;this.zoomIn(e.documentId),(n=(t=e.callback).onSmallDrag)==null||n.call(t)}});return this.interactionManager.registerHandlers({documentId:e.documentId,modeId:`marqueeZoom`,handlers:r,pageIndex:e.pageIndex})}onStoreUpdated(e,t){for(let n in t.documents){let r=e.documents[n],i=t.documents[n];r&&i&&(r.currentZoomLevel!==i.currentZoomLevel||r.zoomLevel!==i.zoomLevel||r.isMarqueeZoomActive!==i.isMarqueeZoomActive)&&this.state$.emit({documentId:n,state:i})}}async initialize(){this.logger.info(`ZoomPlugin`,`Initialize`,`Zoom plugin initialized`)}async destroy(){this.zoom$.clear(),this.state$.clear(),super.destroy()}},Ir.id=`zoom`,Lr=Ir,Rr={manifest:Dr,create:(e,t)=>new Lr(Er,e,t),reducer:Fr,initialState:Pr}})))()}var Br,Vr;function Hr(){return(Hr=e((()=>{q(),zr(),Bn(),Br=()=>G(Lr.id),Vr=e=>{let{provides:t}=Br(),[n,r]=j(Nr);return O(()=>{if(!t)return;let n=t.forDocument(e);return r(n.getState()),n.onStateChange(e=>{r(e)})},[t,e]),{state:n,provides:t?.forDocument(e)??null}}})))()}function Ur(e,t){return{type:$r,payload:{documentId:e,state:t}}}function Wr(e){return{type:ei,payload:e}}function Gr(e){return{type:ti,payload:{documentId:e}}}function Kr(e){return{type:ni,payload:{documentId:e}}}function qr(e,t){return{type:ri,payload:{documentId:e,flags:t}}}function Jr(e,t){return{type:ii,payload:{documentId:e,showAll:t}}}function Yr(e,t){return{type:ai,payload:{documentId:e,query:t}}}function Xr(e,t,n,r){return{type:oi,payload:{documentId:e,results:t,total:n,activeResultIndex:r}}}function Zr(e,t){return{type:si,payload:{documentId:e,results:t}}}function Qr(e,t){return{type:ci,payload:{documentId:e,index:t}}}var $r,ei,ti,ni,ri,ii,ai,oi,si,ci,li,ui,Z,di,fi,pi,mi,hi,gi;function _i(){return(_i=e((()=>{U(),C(),$r=`SEARCH/INIT_STATE`,ei=`SEARCH/CLEANUP_STATE`,ti=`SEARCH/START_SEARCH_SESSION`,ni=`SEARCH/STOP_SEARCH_SESSION`,ri=`SEARCH/SET_SEARCH_FLAGS`,ii=`SEARCH/SET_SHOW_ALL_RESULTS`,ai=`SEARCH/START_SEARCH`,oi=`SEARCH/SET_SEARCH_RESULTS`,si=`SEARCH/APPEND_SEARCH_RESULTS`,ci=`SEARCH/SET_ACTIVE_RESULT_INDEX`,li={flags:[],results:[],total:0,activeResultIndex:-1,showAllResults:!0,query:``,loading:!1,active:!1},ui={documents:{}},Z=(e,t,n)=>{let r=e.documents[t]||li;return{...e,documents:{...e.documents,[t]:{...r,...n}}}},di=(e=ui,t)=>{switch(t.type){case $r:return{...e,documents:{...e.documents,[t.payload.documentId]:t.payload.state}};case ei:{let n=t.payload,{[n]:r,...i}=e.documents;return{...e,documents:i}}case ti:return Z(e,t.payload.documentId,{active:!0});case ni:return Z(e,t.payload.documentId,{results:[],total:0,activeResultIndex:-1,query:``,loading:!1,active:!1});case ri:return Z(e,t.payload.documentId,{flags:t.payload.flags});case ii:return Z(e,t.payload.documentId,{showAllResults:t.payload.showAll});case ai:return Z(e,t.payload.documentId,{loading:!0,query:t.payload.query,results:[],total:0,activeResultIndex:-1});case si:{let{documentId:n,results:r}=t.payload,i=e.documents[n];if(!i)return e;let a=[...i.results,...r],o=i.activeResultIndex===-1&&a.length>0?0:i.activeResultIndex;return Z(e,n,{results:a,total:a.length,activeResultIndex:o,loading:!0})}case oi:{let{documentId:n,results:r,total:i,activeResultIndex:a}=t.payload;return Z(e,n,{results:r,total:i,activeResultIndex:a,loading:!1})}case ci:return Z(e,t.payload.documentId,{activeResultIndex:t.payload.index});default:return e}},fi=class extends H{constructor(e,t,n){super(e,t),this.searchStop$=L(),this.searchStart$=L(),this.searchResult$=L(),this.searchActiveResultChange$=L(),this.searchResultState$=L(),this.searchState$=L(),this.currentTask=/* @__PURE__ */ new Map,this.pluginConfig=n}onDocumentLoadingStarted(e){let t={...li,flags:this.pluginConfig.flags||[],showAllResults:this.pluginConfig.showAllResults??!0};this.dispatch(Ur(e,t))}onDocumentClosed(e){this.stopSearchSession(e),this.dispatch(Wr(e)),this.currentTask.delete(e)}async initialize(){}onStoreUpdated(e,t){for(let n in t.documents){let r=e.documents[n],i=t.documents[n];r!==i&&(this.searchState$.emit({documentId:n,state:i}),(!r||r.results!==i.results||r.activeResultIndex!==i.activeResultIndex||r.showAllResults!==i.showAllResults||r.active!==i.active)&&this.searchResultState$.emit({documentId:n,state:{results:i.results,activeResultIndex:i.activeResultIndex,showAllResults:i.showAllResults,active:i.active}}))}}buildCapability(){let e=e=>e??this.getActiveDocumentId(),t=t=>{let n=e(t),r=this.state.documents[n];if(!r)throw Error(`Search state not found for document ${n}`);return r};return{startSearch:t=>this.startSearchSession(e(t)),stopSearch:t=>this.stopSearchSession(e(t)),searchAllPages:(t,n)=>this.searchAllPages(t,e(n)),nextResult:t=>this.nextResult(e(t)),previousResult:t=>this.previousResult(e(t)),goToResult:(t,n)=>this.goToResult(t,e(n)),setShowAllResults:(t,n)=>this.dispatch(Jr(e(n),t)),getShowAllResults:e=>t(e).showAllResults,getFlags:e=>t(e).flags,setFlags:(t,n)=>this.setFlags(t,e(n)),getState:e=>t(e),forDocument:this.createSearchScope.bind(this),onSearchResult:this.searchResult$.on,onSearchStart:this.searchStart$.on,onSearchStop:this.searchStop$.on,onActiveResultChange:this.searchActiveResultChange$.on,onSearchResultStateChange:this.searchResultState$.on,onStateChange:this.searchState$.on}}createSearchScope(e){let t=()=>{let t=this.state.documents[e];if(!t)throw Error(`Search state not found for document ${e}`);return t};return{startSearch:()=>this.startSearchSession(e),stopSearch:()=>this.stopSearchSession(e),searchAllPages:t=>this.searchAllPages(t,e),nextResult:()=>this.nextResult(e),previousResult:()=>this.previousResult(e),goToResult:t=>this.goToResult(t,e),setShowAllResults:t=>this.dispatch(Jr(e,t)),getShowAllResults:()=>t().showAllResults,getFlags:()=>t().flags,setFlags:t=>this.setFlags(t,e),getState:t,onSearchResult:t=>this.searchResult$.on(n=>{n.documentId===e&&t(n.results)}),onSearchStart:t=>this.searchStart$.on(n=>{n.documentId===e&&t()}),onSearchStop:t=>this.searchStop$.on(n=>{n.documentId===e&&t()}),onActiveResultChange:t=>this.searchActiveResultChange$.on(n=>{n.documentId===e&&t(n.index)}),onSearchResultStateChange:t=>this.searchResultState$.on(n=>{n.documentId===e&&t(n.state)}),onStateChange:t=>this.searchState$.on(n=>{n.documentId===e&&t(n.state)})}}setFlags(e,t){this.dispatch(qr(t,e));let n=this.state.documents[t];n?.active&&this.searchAllPages(n.query,t,!0)}notifySearchStart(e){this.searchStart$.emit({documentId:e})}notifySearchStop(e){this.searchStop$.emit({documentId:e})}notifyActiveResultChange(e,t){this.searchActiveResultChange$.emit({documentId:e,index:t})}startSearchSession(e){this.getCoreDocument(e)&&(this.dispatch(Gr(e)),this.notifySearchStart(e))}stopSearchSession(e){var t;if(!this.state.documents[e]?.active)return;let n=this.currentTask.get(e);if(n){try{(t=n.abort)==null||t.call(n,{code:D.Cancelled,message:`search stopped`})}catch{}this.currentTask.delete(e)}this.dispatch(Kr(e)),this.notifySearchStop(e)}searchAllPages(e,t,n=!1){var r;let i=this.state.documents[t];if(!i)return x.reject({code:D.NotFound,message:`Search state not initialized`});let a=this.getCoreDocument(t);if(!a?.document)return x.reject({code:D.NotFound,message:`Document not loaded`});let o=e.trim();if(i.query===o&&!n)return x.resolve({results:i.results,total:i.total});let s=this.currentTask.get(t);if(s){try{(r=s.abort)==null||r.call(s,{code:D.Cancelled,message:`new search`})}catch{}this.currentTask.delete(t)}if(this.dispatch(Yr(t,o)),!o)return this.dispatch(Xr(t,[],0,-1)),x.resolve({results:[],total:0});i.active||this.startSearchSession(t);let c=this.engine.searchAllPages(a.document,o,{flags:i.flags});return this.currentTask.set(t,c),c.onProgress(e=>{e?.results?.length&&this.currentTask.get(t)===c&&(this.dispatch(Zr(t,e.results)),this.state.documents[t].activeResultIndex===-1&&(this.dispatch(Qr(t,0)),this.notifyActiveResultChange(t,0)))}),c.wait(e=>{this.currentTask.delete(t);let n=e.total>0?0:-1;this.dispatch(Xr(t,e.results,e.total,n)),this.searchResult$.emit({documentId:t,results:e}),e.total>0&&this.notifyActiveResultChange(t,0)},e=>{e?.reason?.code!==D.Cancelled&&(console.error(`Error during search:`,e),this.dispatch(Xr(t,[],0,-1))),this.currentTask.delete(t)}),c}nextResult(e){let t=this.state.documents[e];if(!t||t.results.length===0)return-1;let n=t.activeResultIndex>=t.results.length-1?0:t.activeResultIndex+1;return this.goToResult(n,e)}previousResult(e){let t=this.state.documents[e];if(!t||t.results.length===0)return-1;let n=t.activeResultIndex<=0?t.results.length-1:t.activeResultIndex-1;return this.goToResult(n,e)}goToResult(e,t){let n=this.state.documents[t];return!n||n.results.length===0||e<0||e>=n.results.length?-1:(this.dispatch(Qr(t,e)),this.notifyActiveResultChange(t,e),e)}async destroy(){for(let e of Object.keys(this.state.documents))this.stopSearchSession(e);this.searchResult$.clear(),this.searchStart$.clear(),this.searchStop$.clear(),this.searchActiveResultChange$.clear(),this.searchResultState$.clear(),this.searchState$.clear(),super.destroy()}},fi.id=`search`,pi=fi,mi=`search`,hi={id:mi,name:`Search Plugin`,version:`1.0.0`,provides:[`search`],requires:[],optional:[],defaultConfig:{flags:[]}},gi={manifest:hi,create:(e,t)=>new pi(mi,e,t),reducer:di,initialState:ui}})))()}function vi({documentId:e,pageIndex:t,scale:n,style:r,highlightColor:i=`#FFFF00`,activeHighlightColor:a=`#FFBF00`,...o}){let{provides:s}=yi(),[c,l]=j(null),u=K(e),d=k(()=>s?.forDocument(e),[s,e]),f=k(()=>n===void 0?u?.scale??1:n,[n,u?.scale]);if(O(()=>{if(!d){l(null);return}let e=d.getState();return l({results:e.results,activeResultIndex:e.activeResultIndex,showAllResults:e.showAllResults,active:e.active}),d.onSearchResultStateChange(e=>{l(e)})},[d]),!c||!c.active)return null;let p=c.results.map((e,t)=>({result:e,originalIndex:t})).filter(({result:e})=>e.pageIndex===t).filter(({originalIndex:e})=>c.showAllResults||e===c.activeResultIndex);return/* @__PURE__ */ M(`div`,{style:{...r,pointerEvents:`none`},...o,children:p.map(({result:e,originalIndex:t})=>e.rects.map((e,n)=>/* @__PURE__ */ M(`div`,{style:{position:`absolute`,top:e.origin.y*f,left:e.origin.x*f,width:e.size.width*f,height:e.size.height*f,backgroundColor:t===c.activeResultIndex?a:i,mixBlendMode:`multiply`,transform:`scale(1.02)`,transformOrigin:`center`,transition:`opacity .3s ease-in-out`,opacity:1}},`${t}-${n}`)))})}var yi,bi;function xi(){return(xi=e((()=>{q(),_i(),yi=()=>G(pi.id),bi=e=>{let{provides:t}=yi(),[n,r]=j(li),i=k(()=>t?.forDocument(e),[t,e]);return O(()=>{if(!i)r(li);else return r(i.getState()),i.onStateChange(e=>r(e))},[i]),{state:n,provides:i??null}}})))()}function Si(e,t){return e.rects[t]??[]}function Q(e,t){return se(Si(e,t))}function Ci(e){let t=[],n=e.rects;for(let e in n){let r=Number(e),i=se(n[r]);i&&t.push({page:r,rect:i})}return t}function wi(e,t){let n=e.rects[t]||[];if(n.length===0)return null;let r=Q(e,t);return r?{pageIndex:t,rect:r,segmentRects:n}:null}function Ti(e){let t=[],n=Object.keys(e.rects).map(Number);for(let r of n){let n=e.rects[r]||[];if(n.length===0)continue;let i=Q(e,r);i&&t.push({pageIndex:r,rect:i,segmentRects:n})}return t}function Ei(e,t,n=1.5){for(let n of e.runs){if(!(t.y>=n.rect.y&&t.y<=n.rect.y+n.rect.height&&t.x>=n.rect.x&&t.x<=n.rect.x+n.rect.width))continue;let e=n.glyphs.findIndex(e=>{let n=e.tightX??e.x,r=e.tightY??e.y,i=e.tightWidth??e.width,a=e.tightHeight??e.height;return t.x>=n&&t.x<=n+i&&t.y>=r&&t.y<=r+a});if(e!==-1)return n.charStart+e}if(n<=0)return-1;let r=Di(e,n)/2,i=-1,a=1/0;for(let n of e.runs)if(!(t.y<n.rect.y-r||t.y>n.rect.y+n.rect.height+r||t.x<n.rect.x-r||t.x>n.rect.x+n.rect.width+r))for(let e=0;e<n.glyphs.length;e++){let o=n.glyphs[e];if(o.flags===2)continue;let s=o.tightX??o.x,c=o.tightY??o.y,l=o.tightWidth??o.width,u=o.tightHeight??o.height,d=s-r,f=s+l+r,p=c-r,m=c+u+r;if(t.x<d||t.x>f||t.y<p||t.y>m)continue;let h=Math.min(Math.abs(t.x-s),Math.abs(t.x-(s+l)))+Math.min(Math.abs(t.y-c),Math.abs(t.y-(c+u)));h<a&&(a=h,i=n.charStart+e)}return i}function Di(e,t){let n=0,r=0;for(let t of e.runs)for(let e of t.glyphs)e.flags!==2&&(n+=e.height,r++);return r===0?0:n/r*t}function Oi(e,t,n){if(!e||!t||n<e.start.page||n>e.end.page)return null;let r=n===e.start.page?e.start.index:0,i=t.runs[t.runs.length-1],a=i.charStart+i.glyphs.length-1;return{from:r,to:n===e.end.page?e.end.index:a}}function ki(e,t,n,r=!0){let i=[];for(let r of e.runs){let e=r.charStart,a=e+r.glyphs.length-1;if(a<t||e>n)continue;let o=Math.max(t,e)-e,s=Math.min(n,a)-e,c=1/0,l=-1/0,u=1/0,d=-1/0,f=0,p=0,m=-1/0,h=()=>{c!==1/0&&f>0&&i.push({rect:{origin:{x:c,y:u},size:{width:l-c,height:d-u}},charCount:f,fontSize:r.fontSize}),c=1/0,l=-1/0,u=1/0,d=-1/0,f=0,p=0,m=-1/0};for(let e=o;e<=s;e++){let t=r.glyphs[e];if(t.flags!==2){if(f>0&&m>-1/0){let e=Math.abs(t.x-m),n=p/f;n>0&&e>2.5*n&&h()}c=Math.min(c,t.x),l=Math.max(l,t.x+t.width),u=Math.min(u,t.y),d=Math.max(d,t.y+t.height),f++,p+=t.width,m=t.x+t.width}}h()}return r?Fi(i):i.map(e=>e.rect)}function Ai(e,t){let n=Math.min(e.origin.x,t.origin.x),r=Math.min(e.origin.y,t.origin.y),i=Math.max(e.origin.x+e.size.width,t.origin.x+t.size.width),a=Math.max(e.origin.y+e.size.height,t.origin.y+t.size.height);return{origin:{x:n,y:r},size:{width:i-n,height:a-r}}}function ji(e,t){let n=Math.max(e.origin.x,t.origin.x),r=Math.max(e.origin.y,t.origin.y),i=Math.min(e.origin.x+e.size.width,t.origin.x+t.size.width),a=Math.min(e.origin.y+e.size.height,t.origin.y+t.size.height),o=Math.max(0,i-n),s=Math.max(0,a-r);return{origin:{x:n,y:r},size:{width:o,height:s}}}function Mi(e){return e.size.width<=0||e.size.height<=0}function Ni(e,t){if(Mi(e)||Mi(t))return 0;let n=Ai(e,t);return n.size.height===e.size.height||n.size.height===t.size.height?1:ji(e,t).size.height/n.size.height}function Pi(e,t){if(e.fontSize!=null&&t.fontSize!=null&&e.fontSize>0&&t.fontSize>0&&Math.max(e.fontSize,t.fontSize)/Math.min(e.fontSize,t.fontSize)>1.5)return!1;let n=e.rect,r=t.rect;if(Ni(n,r)<.8)return!1;let i=1*n.size.width/e.charCount,a=1*r.size.width/t.charCount,o=n.origin.x-i,s=n.origin.x+n.size.width+i,c=r.origin.x-a;return o<r.origin.x+r.size.width+a&&s>c}function Fi(e){let t=[],n=null,r=null;for(let i of e)n&&r?Pi(n,i)?r=Ai(r,i.rect):(t.push(r),r=i.rect):r=i.rect,n=i;return r&&!Mi(r)&&t.push(r),t}function Ii(e,t){for(let n=0;n<e.runs.length;n++){let r=e.runs[n],i=t-r.charStart;if(i>=0&&i<r.glyphs.length)return{runIdx:n,localIdx:i}}return null}function Li(e){return e===1||e===2}function Ri(e,t){if(!Ii(e,t))return null;let n=Hi(e);if(n===0)return null;let r=t;for(;r>0;){let t=Ii(e,r-1);if(!t||Li(e.runs[t.runIdx].glyphs[t.localIdx].flags))break;r--}let i=t;for(;i<n-1;){let t=Ii(e,i+1);if(!t||Li(e.runs[t.runIdx].glyphs[t.localIdx].flags))break;i++}return{from:r,to:i}}function zi(e,t){let n=Ii(e,t);if(!n)return null;let r=e.runs[n.runIdx],i=r.rect.y,a=r.rect.y+r.rect.height,o=r.charStart,s=r.charStart+r.glyphs.length-1;for(let t=n.runIdx-1;t>=0;t--){let n=e.runs[t];if(!Bi(n)){if(!Vi(n.rect.y,n.rect.y+n.rect.height,i,a))break;o=n.charStart}}for(let t=n.runIdx+1;t<e.runs.length;t++){let n=e.runs[t];if(!Bi(n)){if(!Vi(n.rect.y,n.rect.y+n.rect.height,i,a))break;s=n.charStart+n.glyphs.length-1}}return{from:o,to:s}}function Bi(e){return e.rect.width===0&&e.rect.height===0}function Vi(e,t,n,r){let i=Math.max(t,r)-Math.min(e,n),a=Math.max(0,Math.min(t,r)-Math.max(e,n));return i!==0&&a/i>=_a}function Hi(e){if(e.runs.length===0)return 0;let t=e.runs[e.runs.length-1];return t.charStart+t.glyphs.length}function Ui(e){let t=e.minDragDistance??3,n=e.toleranceFactor??1.5,r=null,i=null,a=!1,o=0;function s(){var t;r=null,i=null,a=!1,(t=e.setHasTextAnchor)==null||t.call(e,!1)}return{onPointerDown:(t,s,c)=>{var l,u;if(s.target===s.currentTarget&&((l=e.onEmptySpaceClick)==null||l.call(e,c)),!e.isEnabled(c))return;(o===0||Date.now()-o>=va)&&e.onClear(c);let d=e.getGeometry();if(!d)return;let f=Ei(d,t,n);f!==-1&&(r=f,i=t,a=!1,(u=e.setHasTextAnchor)==null||u.call(e,!0))},onPointerMove:(o,s,c)=>{if(!e.isEnabled(c))return;let l=e.getGeometry();if(!l)return;let u=Ei(l,o,n);if(e.setCursor(u===-1?null:`text`),r!==null&&i&&!a){let n=o.x-i.x,s=o.y-i.y;Math.sqrt(n*n+s*s)>=t&&(a=!0,e.onBegin(r,c),u!==-1&&e.onUpdate(u,c))}else e.isSelecting()&&u!==-1&&e.onUpdate(u,c)},onPointerUp:(t,n,r)=>{e.isEnabled(r)&&a&&e.onEnd(r),s()},onDoubleClick:(t,r,i)=>{var a;if(!e.isEnabled(i))return;let s=e.getGeometry();if(!s)return;let c=Ei(s,t,n);c!==-1&&(o=Date.now(),(a=e.onWordSelect)==null||a.call(e,c,i))},onClick:(t,r,i)=>{var a;if(!e.isEnabled(i)||o===0)return;if(Date.now()-o>va){o=0;return}o=0;let s=e.getGeometry();if(!s)return;let c=Ei(s,t,n);c!==-1&&((a=e.onLineSelect)==null||a.call(e,c,i))},onHandlerActiveEnd:t=>{s(),e.isEnabled(t)&&e.onClear(t)}}}function Wi(e){let{pageSize:t,scale:n,minDragPx:r=5}=e,i=null,a=null;return{onPointerDown:(t,n,r)=>{var o;e.isEnabled(r)&&(e.isTextSelecting?.call(e)||(i=t,a={origin:{x:t.x,y:t.y},size:{width:0,height:0}},e.onBegin(t,r),(o=n.setPointerCapture)==null||o.call(n)))},onPointerMove:(n,r,o)=>{if(!i||!e.isEnabled(o))return;let s=F(n.x,0,t.width),c=F(n.y,0,t.height);a={origin:{x:Math.min(i.x,s),y:Math.min(i.y,c)},size:{width:Math.abs(s-i.x),height:Math.abs(c-i.y)}},e.onChange(a,o)},onPointerUp:(t,o,s)=>{var c;e.isEnabled(s)&&(a&&i&&(Math.max(a.size.width,a.size.height)*n>r?e.onEnd(a,s):e.onCancel(s)),i=null,a=null,(c=o.releasePointerCapture)==null||c.call(o))},onPointerCancel:(t,n,r)=>{var o;e.isEnabled(r)&&(i=null,a=null,e.onCancel(r),(o=n.releasePointerCapture)==null||o.call(n))}}}var Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,$,ga,_a,va,ya,ba,xa;function Sa(){return(Sa=e((()=>{U(),C(),Gi=`selection`,Ki={id:Gi,name:`Selection Plugin`,version:`1.0.0`,provides:[`selection`],requires:[`interaction-manager`],optional:[`viewport`,`scroll`],defaultConfig:{menuHeight:40}},qi=`SELECTION/INIT_STATE`,Ji=`SELECTION/CLEANUP_STATE`,Yi=`SELECTION/CACHE_PAGE_GEOMETRY`,Xi=`SELECTION/SET_SELECTION`,Zi=`SELECTION/START_SELECTION`,Qi=`SELECTION/END_SELECTION`,$i=`SELECTION/CLEAR_SELECTION`,ea=`SELECTION/SET_RECTS`,ta=`SELECTION/SET_SLICES`,na=`SELECTION/EVICT_PAGE_GEOMETRY`,ra=`SELECTION/RESET`,ia=(e,t)=>({type:qi,payload:{documentId:e,state:t}}),aa=e=>({type:Ji,payload:e}),oa=(e,t,n)=>({type:Yi,payload:{documentId:e,page:t,geo:n}}),sa=(e,t)=>({type:Xi,payload:{documentId:e,selection:t}}),ca=e=>({type:Zi,payload:{documentId:e}}),la=e=>({type:Qi,payload:{documentId:e}}),ua=e=>({type:$i,payload:{documentId:e}}),da=(e,t)=>({type:ea,payload:{documentId:e,rects:t}}),fa=(e,t)=>({type:ta,payload:{documentId:e,slices:t}}),pa=(e,t)=>({type:na,payload:{documentId:e,pages:t}}),ma={geometry:{},rects:{},slices:{},selection:null,active:!1,selecting:!1},ha={documents:{}},$=(e,t,n)=>({...e,documents:{...e.documents,[t]:n}}),ga=(e=ha,t)=>{switch(t.type){case qi:{let{documentId:n,state:r}=t.payload;return $(e,n,r)}case Ji:{let n=t.payload,{[n]:r,...i}=e.documents;return{...e,documents:i}}case Yi:{let{documentId:n,page:r,geo:i}=t.payload,a=e.documents[n];return a?$(e,n,{...a,geometry:{...a.geometry,[r]:i}}):e}case Xi:{let{documentId:n,selection:r}=t.payload,i=e.documents[n];return i?$(e,n,{...i,selection:r,active:!0}):e}case Zi:{let{documentId:n}=t.payload,r=e.documents[n];return r?$(e,n,{...r,selecting:!0,selection:null,rects:{}}):e}case Qi:{let{documentId:n}=t.payload,r=e.documents[n];return r?$(e,n,{...r,selecting:!1}):e}case $i:{let{documentId:n}=t.payload,r=e.documents[n];return r?$(e,n,{...r,selecting:!1,selection:null,rects:{},active:!1}):e}case ea:{let{documentId:n,rects:r}=t.payload,i=e.documents[n];return i?$(e,n,{...i,rects:r}):e}case ta:{let{documentId:n,slices:r}=t.payload,i=e.documents[n];return i?$(e,n,{...i,slices:r}):e}case na:{let{documentId:n,pages:r}=t.payload,i=e.documents[n];if(!i)return e;let a={...i.geometry},o={...i.rects},s={...i.slices};for(let e of r)delete a[e],delete o[e],delete s[e];return $(e,n,{...i,geometry:a,rects:o,slices:s})}case ra:{let{documentId:n}=t.payload;return e.documents[n]?$(e,n,ma):e}default:return e}},_a=.5,va=500,ya=class extends H{constructor(e,t,n){var r;super(e,t),this.enabledModesPerDoc=/* @__PURE__ */ new Map,this.selecting=/* @__PURE__ */ new Map,this.anchor=/* @__PURE__ */ new Map,this.hasTextAnchor=/* @__PURE__ */ new Map,this.marqueePage=/* @__PURE__ */ new Map,this.pageCallbacks=/* @__PURE__ */ new Map,this.geoAccessOrder=/* @__PURE__ */ new Map,this.menuPlacement$=R((e,t)=>({documentId:e,placement:t})),this.selChange$=R((e,t)=>({documentId:e,selection:t,modeId:this.interactionManagerCapability.forDocument(e).getActiveMode()})),this.textRetrieved$=R((e,t)=>({documentId:e,text:t})),this.copyToClipboard$=R((e,t)=>({documentId:e,text:t}),{cache:!1}),this.beginSelection$=R((e,t)=>({documentId:e,page:t.page,index:t.index,modeId:t.modeId}),{cache:!1}),this.endSelection$=R((e,t)=>({documentId:e,modeId:t.modeId}),{cache:!1}),this.marqueeChange$=R((e,t)=>({documentId:e,pageIndex:t.pageIndex,rect:t.rect,modeId:t.modeId}),{cache:!1}),this.marqueeEnd$=R((e,t)=>({documentId:e,pageIndex:t.pageIndex,rect:t.rect,modeId:t.modeId}),{cache:!1}),this.emptySpaceClick$=R((e,t)=>({documentId:e,pageIndex:t.pageIndex,modeId:t.modeId}),{cache:!1}),this.viewportCapability=null,this.scrollCapability=null,this.config=n,this.menuHeight=n.menuHeight??40;let i=t.getPlugin(`interaction-manager`);if(!i)throw Error(`SelectionPlugin: InteractionManagerPlugin is required.`);this.interactionManagerCapability=i.provides(),this.viewportCapability=t.getPlugin(`viewport`)?.provides()??null,this.scrollCapability=t.getPlugin(`scroll`)?.provides()??null,this.coreStore.onAction(ot,e=>{let{documentId:t,pageIndexes:n}=e.payload,r=n.map(e=>this.getNewPageGeometryAndCache(t,e));w.all(r).wait(()=>{n.forEach(e=>{this.notifyPage(t,e)})},T)}),(r=this.viewportCapability)==null||r.onViewportChange(e=>{this.recalculateMenuPlacement(e.documentId)},{mode:`throttle`,wait:100})}onDocumentLoadingStarted(e){this.dispatch(ia(e,ma));let t=this.config.marquee?.enabled!==!1;this.enabledModesPerDoc.set(e,/* @__PURE__ */ new Map([[`pointerMode`,{enableSelection:!0,showSelectionRects:!0,enableMarquee:t,showMarqueeRects:!0}]])),this.pageCallbacks.set(e,/* @__PURE__ */ new Map),this.geoAccessOrder.set(e,[]),this.selecting.set(e,!1),this.anchor.set(e,void 0),this.hasTextAnchor.set(e,!1)}onDocumentClosed(e){this.dispatch(aa(e)),this.enabledModesPerDoc.delete(e),this.pageCallbacks.delete(e),this.geoAccessOrder.delete(e),this.selecting.delete(e),this.hasTextAnchor.delete(e),this.anchor.delete(e),this.marqueePage.delete(e),this.selChange$.clearScope(e),this.textRetrieved$.clearScope(e),this.copyToClipboard$.clearScope(e),this.beginSelection$.clearScope(e),this.endSelection$.clearScope(e),this.menuPlacement$.clearScope(e),this.marqueeChange$.clearScope(e),this.marqueeEnd$.clearScope(e),this.emptySpaceClick$.clearScope(e)}async initialize(){}async destroy(){this.selChange$.clear(),this.textRetrieved$.clear(),this.copyToClipboard$.clear(),this.beginSelection$.clear(),this.endSelection$.clear(),this.menuPlacement$.clear(),this.marqueeChange$.clear(),this.marqueeEnd$.clear(),this.emptySpaceClick$.clear(),super.destroy()}buildCapability(){let e=e=>e??this.getActiveDocumentId();return{getFormattedSelection:t=>Ti(this.getDocumentState(e(t))),getFormattedSelectionForPage:(t,n)=>wi(this.getDocumentState(e(n)),t),getHighlightRectsForPage:(t,n)=>Si(this.getDocumentState(e(n)),t),getHighlightRects:t=>this.getDocumentState(e(t)).rects,getBoundingRectForPage:(t,n)=>Q(this.getDocumentState(e(n)),t),getBoundingRects:t=>Ci(this.getDocumentState(e(t))),getSelectedText:t=>this.getSelectedText(e(t)),setSelection:(t,n)=>this.applySelection(e(n),t),clear:t=>this.clearSelection(e(t)),copyToClipboard:t=>this.copyToClipboard(e(t)),getState:t=>this.getDocumentState(e(t)),enableForMode:(t,n,r)=>this.enabledModesPerDoc.get(e(r))?.set(t,{...n}),isEnabledForMode:(t,n)=>this.enabledModesPerDoc.get(e(n))?.has(t)??!1,setMarqueeEnabled:(t,n)=>this.setMarqueeEnabled(e(n),t),isMarqueeEnabled:t=>this.isMarqueeEnabled(e(t)),forDocument:this.createSelectionScope.bind(this),onCopyToClipboard:this.copyToClipboard$.onGlobal,onSelectionChange:this.selChange$.onGlobal,onTextRetrieved:this.textRetrieved$.onGlobal,onBeginSelection:this.beginSelection$.onGlobal,onEndSelection:this.endSelection$.onGlobal,onMarqueeChange:this.marqueeChange$.onGlobal,onMarqueeEnd:this.marqueeEnd$.onGlobal,onEmptySpaceClick:this.emptySpaceClick$.onGlobal}}createSelectionScope(e){return{getFormattedSelection:()=>Ti(this.getDocumentState(e)),getFormattedSelectionForPage:t=>wi(this.getDocumentState(e),t),getHighlightRectsForPage:t=>Si(this.getDocumentState(e),t),getHighlightRects:()=>this.getDocumentState(e).rects,getBoundingRectForPage:t=>Q(this.getDocumentState(e),t),getBoundingRects:()=>Ci(this.getDocumentState(e)),getSelectedText:()=>this.getSelectedText(e),setSelection:t=>this.applySelection(e,t),clear:()=>this.clearSelection(e),copyToClipboard:()=>this.copyToClipboard(e),getState:()=>this.getDocumentState(e),setMarqueeEnabled:t=>this.setMarqueeEnabled(e,t),isMarqueeEnabled:()=>this.isMarqueeEnabled(e),onSelectionChange:this.selChange$.forScope(e),onTextRetrieved:this.textRetrieved$.forScope(e),onCopyToClipboard:this.copyToClipboard$.forScope(e),onBeginSelection:this.beginSelection$.forScope(e),onEndSelection:this.endSelection$.forScope(e),onMarqueeChange:this.marqueeChange$.forScope(e),onMarqueeEnd:this.marqueeEnd$.forScope(e),onEmptySpaceClick:this.emptySpaceClick$.forScope(e)}}getDocumentState(e){let t=this.state.documents[e];if(!t)throw Error(`Selection state not found for document: ${e}`);return t}onMenuPlacement(e,t){return this.menuPlacement$.forScope(e)(t)}registerSelectionOnPage(e){var t;let{documentId:n,pageIndex:r,onRectsChange:i}=e,a=this.state.documents[n];if(!a)return this.logger.warn(`SelectionPlugin`,`RegisterFailed`,`Cannot register selection on page ${r} for document ${n}: document state not initialized.`),()=>{};(t=this.pageCallbacks.get(n))==null||t.set(r,i);let o=this.getOrLoadGeometry(n,r),s=this.interactionManagerCapability.forDocument(n),c=this.enabledModesPerDoc.get(n);i({rects:Si(a,r),boundingRect:Q(a,r)}),o.wait(e=>{let t=this.getDocumentState(n),i=t.selection;if(!i||r<i.start.page||r>i.end.page)return;let a=Oi(i,e,r);if(!a)return;let o=ki(e,a.from,a.to);this.dispatch(da(n,{...t.rects,[r]:o})),this.dispatch(fa(n,{...t.slices,[r]:{start:a.from,count:a.to-a.from+1}})),this.notifyPage(n,r)},T);let l=Ui({getGeometry:()=>this.getDocumentState(n).geometry[r],isEnabled:e=>{let t=c?.get(e);return t?t.enableSelection!==!1:!1},onBegin:(e,t)=>this.beginSelection(n,r,e,t),onUpdate:(e,t)=>this.updateSelection(n,r,e,t),onEnd:e=>this.endSelection(n,e),onClear:e=>this.clearSelection(n,e),isSelecting:()=>this.selecting.get(n)??!1,setCursor:e=>e?s.setCursor(`selection-text`,e,10):s.removeCursor(`selection-text`),onEmptySpaceClick:e=>this.emptySpaceClick$.emit(n,{pageIndex:r,modeId:e}),onWordSelect:(e,t)=>this.selectWord(n,r,e,t),onLineSelect:(e,t)=>this.selectLine(n,r,e,t),setHasTextAnchor:e=>this.hasTextAnchor.set(n,e),minDragDistance:this.config.minSelectionDragDistance,toleranceFactor:this.config.toleranceFactor}),u=this.interactionManagerCapability.registerAlways({scope:{type:`page`,documentId:n,pageIndex:r},handlers:l});return()=>{var e;u(),(e=this.pageCallbacks.get(n))==null||e.delete(r),o.abort({code:D.Cancelled,message:`Cleanup`})}}registerMarqueeOnPage(e){let{documentId:t,pageIndex:n,scale:r,onRectChange:i}=e;if(!this.state.documents[t])return this.logger.warn(`SelectionPlugin`,`RegisterMarqueeFailed`,`Cannot register marquee on page ${n} for document ${t}: document state not initialized.`),()=>{};let a=this.coreState.core.documents[t];if(!a||!a.document)return this.logger.warn(`SelectionPlugin`,`DocumentNotFound`,`Cannot register marquee on page ${n}: document not found`),()=>{};let o=a.document.pages[n];if(!o)return this.logger.warn(`SelectionPlugin`,`PageNotFound`,`Cannot register marquee on page ${n}: page not found`),()=>{};let s=o.size,c=this.config.marquee?.minDragPx??5,l=()=>{let e=this.interactionManagerCapability.forDocument(t).getActiveMode();return this.enabledModesPerDoc.get(t)?.get(e)?.showMarqueeRects!==!1},u=Wi({pageSize:s,scale:r,minDragPx:c,isEnabled:e=>this.enabledModesPerDoc.get(t)?.get(e)?.enableMarquee===!0,isTextSelecting:()=>(this.selecting.get(t)??!1)||(this.hasTextAnchor.get(t)??!1),onBegin:(e,r)=>this.beginMarquee(t,n,e,r),onChange:(e,r)=>{this.updateMarquee(t,n,e,r),i(l()?e:null)},onEnd:(e,r)=>{this.endMarquee(t,n,e,r),i(null)},onCancel:e=>{this.cancelMarquee(t,e),i(null)}});return this.interactionManagerCapability.registerAlways({scope:{type:`page`,documentId:t,pageIndex:n},handlers:u})}getPlacementMetrics(e,t,n,r){let i=(this.scrollCapability?.forDocument(e))?.getRectPositionForPage(t,n);if(!i)return null;let a=i.origin.y-r.scrollTop,o=i.origin.y+i.size.height-r.scrollTop;return{pageIndex:t,rect:n,spaceAbove:a,spaceBelow:r.clientHeight-o,isBottomVisible:o>0&&o<=r.clientHeight,isTopVisible:a>=0&&a<r.clientHeight}}emitMenuPlacement(e,t){this.menuPlacement$.emit(e,t),t?this.interactionManagerCapability.claimPageActivity(e,`selection-menu`,t.pageIndex):this.interactionManagerCapability.releasePageActivity(e,`selection-menu`)}recalculateMenuPlacement(e){let t=this.state.documents[e];if(!t)return;if(t.selecting||t.selection===null){this.emitMenuPlacement(e,null);return}let n=Ci(t);if(n.length===0){this.emitMenuPlacement(e,null);return}let r=n[n.length-1];if(!this.viewportCapability||!this.scrollCapability){this.emitMenuPlacement(e,{pageIndex:r.page,rect:r.rect,spaceAbove:0,spaceBelow:1/0,suggestTop:!1,isVisible:!0});return}let i=this.viewportCapability.forDocument(e).getMetrics(),a=n[0],o=this.getPlacementMetrics(e,r.page,r.rect,i),s=this.getPlacementMetrics(e,a.page,a.rect,i);o&&o.isBottomVisible&&o.spaceBelow>this.menuHeight?this.emitMenuPlacement(e,{...o,suggestTop:!1,isVisible:!0}):s&&s.isTopVisible?this.emitMenuPlacement(e,{...s,suggestTop:!0,isVisible:!0}):o&&o.isBottomVisible?this.emitMenuPlacement(e,{...o,suggestTop:!1,isVisible:!0}):this.emitMenuPlacement(e,null)}notifyPage(e,t){let n=this.pageCallbacks.get(e)?.get(t);if(n){let r=this.getDocumentState(e),i=this.interactionManagerCapability.forDocument(e).getActiveMode(),a=this.enabledModesPerDoc.get(e)?.get(i);a&&(a.showSelectionRects??a.showRects)!==!1?n({rects:Si(r,t),boundingRect:Q(r,t)}):n({rects:[],boundingRect:null})}}notifyAllPages(e){var t;(t=this.pageCallbacks.get(e))==null||t.forEach((t,n)=>{this.notifyPage(e,n)})}getNewPageGeometryAndCache(e,t){let n=this.getCoreDocument(e);if(!n||!n.document)return x.reject({code:D.NotFound,message:`Doc Not Found`});let r=n.document.pages.find(e=>e.index===t),i=this.engine.getPageGeometry(n.document,r);return i.wait(n=>{this.dispatch(oa(e,t,n)),this.touchGeometry(e,t)},T),i}getOrLoadGeometry(e,t){let n=this.getDocumentState(e).geometry[t];return n?(this.touchGeometry(e,t),x.resolve(n)):this.getNewPageGeometryAndCache(e,t)}touchGeometry(e,t){let n=this.geoAccessOrder.get(e);if(!n)return;let r=n.indexOf(t);r>-1&&n.splice(r,1),n.push(t),this.evictGeometryIfNeeded(e)}evictGeometryIfNeeded(e){let t=this.config.maxCachedGeometries??50,n=this.geoAccessOrder.get(e);if(!n||n.length<=t)return;let r=this.pageCallbacks.get(e),i=[];for(;n.length-i.length>t;){let e=n.find(e=>!i.includes(e)&&!r?.has(e));if(e===void 0)break;i.push(e)}if(i.length!==0){for(let e of i){let t=n.indexOf(e);t>-1&&n.splice(t,1)}this.dispatch(pa(e,i))}}beginSelection(e,t,n,r){this.selecting.set(e,!0),this.anchor.set(e,{page:t,index:n}),this.dispatch(ca(e)),this.beginSelection$.emit(e,{page:t,index:n,modeId:r}),this.recalculateMenuPlacement(e)}endSelection(e,t){this.selecting.set(e,!1),this.anchor.set(e,void 0),this.dispatch(la(e)),this.endSelection$.emit(e,{modeId:t}),this.recalculateMenuPlacement(e)}clearSelection(e,t){this.selecting.set(e,!1),this.anchor.set(e,void 0),this.dispatch(ua(e)),this.selChange$.emit(e,null),this.emitMenuPlacement(e,null),this.notifyAllPages(e)}applySelection(e,t){if(!this.state.documents[e])return x.reject({code:D.NotFound,message:`Selection state not found for document: ${e}`});if(t===null)return this.clearSelection(e),x.resolve(void 0);let n=this.validateRange(e,t);if(n)return x.reject(n);let r=this.normalizeRange(t),i=[];for(let e=r.start.page;e<=r.end.page;e++)i.push(e);let a=i.map(t=>this.getOrLoadGeometry(e,t)),o=x.create();return w.all(a).wait(()=>{if(!this.state.documents[e]){o.reject({code:D.NotFound,message:`Selection state not found for document: ${e}`});return}let t=this.clampRangeToGeometry(e,r);if(!t){o.reject({code:D.NotFound,message:`Cannot apply selection: page(s) ${r.start.page}-${r.end.page} have no text geometry`});return}this.selecting.set(e,!1),this.anchor.set(e,void 0);let n=Object.keys(this.getDocumentState(e).rects).map(Number);this.dispatch(ca(e)),this.dispatch(sa(e,t)),this.updateRectsAndSlices(e,t),this.dispatch(la(e)),this.selChange$.emit(e,t);let i=new Set(n);for(let e=t.start.page;e<=t.end.page;e++)i.add(e);i.forEach(t=>this.notifyPage(e,t)),this.recalculateMenuPlacement(e),o.resolve(void 0)},e=>o.reject(e.reason)),o}validateRange(e,t){let n=e=>!!e&&typeof e==`object`&&Number.isInteger(e.page)&&Number.isInteger(e.index);if(!t||typeof t!=`object`||!t.start||!t.end)return{code:D.Unknown,message:`Invalid selection range: expected { start, end }`};if(!n(t.start)||!n(t.end))return{code:D.Unknown,message:`Invalid selection range: start/end must have integer page and index`};if(t.start.index<0||t.end.index<0)return{code:D.Unknown,message:`Invalid selection range: glyph index cannot be negative`};let r=this.getCoreDocument(e)?.document?.pageCount??0,i=Math.min(t.start.page,t.end.page),a=Math.max(t.start.page,t.end.page);return i<0||a>=r?{code:D.NotFound,message:`Invalid selection range: page ${i<0?i:a} out of bounds [0, ${r})`}:null}clampRangeToGeometry(e,t){let n=this.getDocumentState(e),r=e=>{let t=n.geometry[e];if(!t||t.runs.length===0)return-1;let r=t.runs[t.runs.length-1];return r.charStart+r.glyphs.length-1},i=r(t.start.page),a=r(t.end.page);if(i<0&&a<0)return null;let o=(e,t)=>t<0?0:Math.min(Math.max(e,0),t);return{start:{page:t.start.page,index:o(t.start.index,i)},end:{page:t.end.page,index:o(t.end.index,a)}}}normalizeRange(e){let{start:t,end:n}=e;return n.page>t.page||n.page===t.page&&n.index>=t.index?{start:t,end:n}:{start:n,end:t}}selectWord(e,t,n,r){let i=this.getDocumentState(e).geometry[t];if(!i)return;let a=Ri(i,n);a&&this.applyInstantSelection(e,t,a.from,a.to,r)}selectLine(e,t,n,r){let i=this.getDocumentState(e).geometry[t];if(!i)return;let a=zi(i,n);a&&this.applyInstantSelection(e,t,a.from,a.to,r)}applyInstantSelection(e,t,n,r,i){let a={start:{page:t,index:n},end:{page:t,index:r}};this.selecting.set(e,!1),this.anchor.set(e,void 0),this.dispatch(ca(e)),this.dispatch(sa(e,a)),this.updateRectsAndSlices(e,a),this.dispatch(la(e)),this.selChange$.emit(e,a),this.beginSelection$.emit(e,{page:t,index:n,modeId:i}),this.endSelection$.emit(e,{modeId:i});for(let t=a.start.page;t<=a.end.page;t++)this.notifyPage(e,t);this.recalculateMenuPlacement(e)}updateSelection(e,t,n,r){if(!this.selecting.get(e)||!this.anchor.get(e))return;let i=this.anchor.get(e),a=t>i.page||t===i.page&&n>=i.index,o={start:a?i:{page:t,index:n},end:a?{page:t,index:n}:i};this.dispatch(sa(e,o)),this.updateRectsAndSlices(e,o),this.selChange$.emit(e,o);for(let t=o.start.page;t<=o.end.page;t++)this.notifyPage(e,t)}updateRectsAndSlices(e,t){let n=this.getDocumentState(e),r={},i={};for(let e=t.start.page;e<=t.end.page;e++){let a=n.geometry[e],o=Oi(t,a,e);o&&(r[e]=ki(a,o.from,o.to),i[e]={start:o.from,count:o.to-o.from+1})}this.dispatch(da(e,r)),this.dispatch(fa(e,i))}getSelectedText(e){if(!this.checkPermission(e,E.CopyContents))return this.logger.debug(`SelectionPlugin`,`GetSelectedText`,`Cannot get selected text: document ${e} lacks CopyContents permission`),x.reject({code:D.Security,message:`Document lacks CopyContents permission`});let t=this.getCoreDocument(e),n=this.getDocumentState(e);if(!t?.document||!n.selection)return x.reject({code:D.NotFound,message:`Doc Not Found or No Selection`});let r=n.selection,i=[];for(let e=r.start.page;e<=r.end.page;e++){let t=n.slices[e];t&&i.push({pageIndex:e,charIndex:t.start,charCount:t.count})}if(i.length===0)return x.resolve([]);let a=this.engine.getTextSlices(t.document,i);return a.wait(t=>{this.textRetrieved$.emit(e,t)},T),a}copyToClipboard(e){this.checkPermission(e,E.CopyContents)?this.getSelectedText(e).wait(t=>{this.copyToClipboard$.emit(e,t.join(`
|
|
30
|
-
`))},T):this.logger.debug(`SelectionPlugin`,`CopyToClipboard`,`Cannot copy to clipboard: document ${e} lacks CopyContents permission`)}beginMarquee(e,t,n,r){this.marqueePage.set(e,t)}updateMarquee(e,t,n,r){this.marqueeChange$.emit(e,{pageIndex:t,rect:n,modeId:r})}endMarquee(e,t,n,r){this.marqueeEnd$.emit(e,{pageIndex:t,rect:n,modeId:r}),this.marqueeChange$.emit(e,{pageIndex:t,rect:null,modeId:r}),this.marqueePage.delete(e)}cancelMarquee(e,t){let n=this.marqueePage.get(e);n!==void 0&&(this.marqueeChange$.emit(e,{pageIndex:n,rect:null,modeId:t}),this.marqueePage.delete(e))}setMarqueeEnabled(e,t){let n=this.enabledModesPerDoc.get(e);if(!n)return;let r=n.get(`pointerMode`);r?r.enableMarquee=t:t&&n.set(`pointerMode`,{enableMarquee:!0})}isMarqueeEnabled(e){return this.enabledModesPerDoc.get(e)?.get(`pointerMode`)?.enableMarquee!==!1}},ya.id=`selection`,ba=ya,xa={manifest:Ki,create:(e,t)=>new ba(Gi,e,t),reducer:ga,initialState:ha}})))()}function Ca(e,t){let{width:n,height:r}=e.size;switch(t%4){case 1:return{matrix:`matrix(0, -1, 1, 0, 0, ${r})`,width:r,height:n};case 2:return{matrix:`matrix(-1, 0, 0, -1, ${n}, ${r})`,width:n,height:r};case 3:return{matrix:`matrix(0, 1, -1, 0, ${n}, 0)`,width:r,height:n};default:return{matrix:`matrix(1, 0, 0, 1, 0, 0)`,width:n,height:r}}}function wa({children:e,...t}){let{rect:n,rotation:r}=t,{matrix:i,width:a,height:o}=Ca(n,r),s=A(null);O(()=>{let e=s.current;if(!e)return;let t=e=>{e.stopPropagation()},n=e=>{e.stopPropagation()};return e.addEventListener(`pointerdown`,t,{capture:!0}),e.addEventListener(`touchstart`,n,{capture:!0,passive:!0}),()=>{e.removeEventListener(`pointerdown`,t,{capture:!0}),e.removeEventListener(`touchstart`,n,{capture:!0})}},[]);let c={style:{position:`absolute`,left:n.origin.x,top:n.origin.y,transform:i,transformOrigin:`0 0`,width:a,height:o,pointerEvents:`none`,zIndex:3},ref:e=>{s.current=e}};return/* @__PURE__ */ M(pe,{children:e({menuWrapperProps:c,matrix:i,rect:{origin:{x:n.origin.x,y:n.origin.y},size:{width:a,height:o}}})})}function Ta(){return(Ta=e((()=>{C()})))()}function Ea({documentId:e,pageIndex:t,scale:n,rotation:r,background:i=`rgba(33,150,243)`,selectionMenu:a}){let{plugin:o}=Aa(),s=K(e),c=s?.document?.pages?.[t],[l,u]=j([]),[d,f]=j(null),[p,m]=j(null);O(()=>{if(o&&e)return o.registerSelectionOnPage({documentId:e,pageIndex:t,onRectsChange:({rects:e,boundingRect:t})=>{u(e),f(t)}})},[o,e,t]),O(()=>{if(o&&e)return o.onMenuPlacement(e,e=>{m(e)})},[o,e]);let h=k(()=>n===void 0?s?.scale??1:n,[n,s?.scale]),g=k(()=>r===void 0?((c?.rotation??0)+(s?.rotation??0))%4:r,[r,c?.rotation,s?.rotation]),_=a&&p&&p.pageIndex===t&&p.isVisible;return d?/* @__PURE__ */ N(ye,{children:[/* @__PURE__ */ M(`div`,{style:{position:`absolute`,left:d.origin.x*h,top:d.origin.y*h,width:d.size.width*h,height:d.size.height*h,mixBlendMode:`multiply`,isolation:`isolate`,pointerEvents:`none`},children:l.map((e,t)=>/* @__PURE__ */ M(`div`,{style:{position:`absolute`,left:(e.origin.x-d.origin.x)*h,top:(e.origin.y-d.origin.y)*h,width:e.size.width*h,height:e.size.height*h,background:i}},t))}),_&&/* @__PURE__ */ M(wa,{rect:{origin:{x:p.rect.origin.x*h,y:p.rect.origin.y*h},size:{width:p.rect.size.width*h,height:p.rect.size.height*h}},rotation:g,children:e=>a({...e,context:{type:`selection`,pageIndex:t},selected:!0,placement:p})})]}):null}function Da({documentId:e,pageIndex:t,scale:n,rotation:r,background:i,textStyle:a,marqueeStyle:o,marqueeClassName:s,selectionMenu:c}){return/* @__PURE__ */ N(pe,{children:[/* @__PURE__ */ M(Ea,{documentId:e,pageIndex:t,scale:n,rotation:r,background:a?.background??i,selectionMenu:c}),/* @__PURE__ */ M(ja,{documentId:e,pageIndex:t,scale:n,background:o?.background,borderColor:o?.borderColor,borderStyle:o?.borderStyle,className:s})]})}function Oa(){let{provides:e}=ka();return O(()=>{if(e)return e.onCopyToClipboard(({text:e})=>{navigator.clipboard.writeText(e)})},[e]),null}var ka,Aa,ja,Ma;function Na(){return(Na=e((()=>{U(),Sa(),q(),Ta(),ka=()=>G(ba.id),Aa=()=>W(ba.id),ja=({documentId:e,pageIndex:t,scale:n,className:r,background:i,borderColor:a,borderStyle:o=`dashed`,stroke:s,fill:c})=>{let{plugin:l}=Aa(),u=K(e),[d,f]=j(null),p=a??s??`rgba(0,122,204,0.8)`,m=i??c??`rgba(0,122,204,0.15)`,h=k(()=>n===void 0?u?.scale??1:n,[n,u?.scale]);return O(()=>{if(l&&e)return l.registerMarqueeOnPage({documentId:e,pageIndex:t,scale:h,onRectChange:f})},[l,e,t,h]),d?/* @__PURE__ */ M(`div`,{style:{position:`absolute`,pointerEvents:`none`,left:d.origin.x*h,top:d.origin.y*h,width:d.size.width*h,height:d.size.height*h,border:`1px ${o} ${p}`,background:m,boxSizing:`border-box`,zIndex:1e3},className:r}):null},Ma=Ge(xa).addUtility(Oa).build()})))()}function Pa(e,t){return{type:qa,payload:{documentId:e,state:t}}}function Fa(e){return{type:Ja,payload:e}}function Ia(e,t){return{type:Ya,payload:{documentId:e,mode:t}}}function La(e){return{type:Xa,payload:e}}function Ra(e){return{type:Za,payload:e}}function za(e,t){return{type:Qa,payload:{documentId:e,cursor:t}}}function Ba(e){return{type:eo,payload:{mode:e}}}function Va(e){return{type:to,payload:{rules:e}}}function Ha(e){return{type:no,payload:{className:e}}}function Ua(e){return{type:ro,payload:{className:e}}}function Wa(e){return{type:io,payload:{attribute:e}}}function Ga(e){return{type:ao,payload:{attribute:e}}}function Ka(e){let t=[`onPointerDown`,`onPointerUp`,`onPointerMove`,`onPointerEnter`,`onPointerLeave`,`onPointerCancel`,`onMouseDown`,`onMouseUp`,`onMouseMove`,`onMouseEnter`,`onMouseLeave`,`onMouseCancel`,`onClick`,`onDoubleClick`],n={};for(let r of t)n[r]=(t,n,i)=>{var a;for(let o of e){if(n.isImmediatePropagationStopped())break;(a=o[r])==null||a.call(o,t,n,i)}};return n}var qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no,ro,io,ao,oo,so,co,lo,uo,fo,po,mo,ho;function go(){return(go=e((()=>{U(),qa=`INTERACTION/INIT_STATE`,Ja=`INTERACTION/CLEANUP_STATE`,Ya=`INTERACTION/ACTIVATE_MODE`,Xa=`INTERACTION/PAUSE`,Za=`INTERACTION/RESUME`,Qa=`INTERACTION/SET_CURSOR`,$a=`INTERACTION/SET_ACTIVE_DOCUMENT`,eo=`INTERACTION/SET_DEFAULT_MODE`,to=`INTERACTION/SET_EXCLUSION_RULES`,no=`INTERACTION/ADD_EXCLUSION_CLASS`,ro=`INTERACTION/REMOVE_EXCLUSION_CLASS`,io=`INTERACTION/ADD_EXCLUSION_ATTRIBUTE`,ao=`INTERACTION/REMOVE_EXCLUSION_ATTRIBUTE`,oo=`pointerMode`,so=class extends H{constructor(e,t,n){super(e,t),this.modes=/* @__PURE__ */ new Map,this.cursorClaims=/* @__PURE__ */ new Map,this.buckets=/* @__PURE__ */ new Map,this.alwaysGlobal=/* @__PURE__ */ new Map,this.alwaysPage=/* @__PURE__ */ new Map,this.pageActivities=/* @__PURE__ */ new Map,this.onModeChange$=I(),this.onHandlerChange$=I(),this.onCursorChange$=I(),this.onStateChange$=L(),this.onPageActivityChange$=I(),this.registerMode({id:oo,scope:`page`,exclusive:!1,cursor:`auto`}),this.dispatch(Ba(oo)),n.exclusionRules&&this.dispatch(Va(n.exclusionRules))}onDocumentLoadingStarted(e){let t={activeMode:this.state.defaultMode,cursor:`auto`,paused:!1};this.dispatch(Pa(e,t)),this.cursorClaims.set(e,/* @__PURE__ */ new Map),this.buckets.set(e,/* @__PURE__ */ new Map),this.alwaysGlobal.set(e,/* @__PURE__ */ new Set),this.alwaysPage.set(e,/* @__PURE__ */ new Map),this.pageActivities.set(e,/* @__PURE__ */ new Map);let n=this.buckets.get(e);for(let e of this.modes.keys())n.set(e,{global:/* @__PURE__ */ new Set,page:/* @__PURE__ */ new Map});this.logger.debug(`InteractionManagerPlugin`,`DocumentOpened`,`Initialized interaction state for document: ${e}`)}onDocumentClosed(e){let t=this.pageActivities.get(e);if(t){let n=new Set(t.values());t.clear();for(let t of n)this.onPageActivityChange$.emit({documentId:e,pageIndex:t,hasActivity:!1})}this.cursorClaims.delete(e),this.buckets.delete(e),this.alwaysGlobal.delete(e),this.alwaysPage.delete(e),this.pageActivities.delete(e),this.dispatch(Fa(e)),this.logger.debug(`InteractionManagerPlugin`,`DocumentClosed`,`Cleaned up interaction state for document: ${e}`)}buildCapability(){return{getActiveMode:()=>this.getActiveMode(),getActiveInteractionMode:()=>this.getActiveInteractionMode(),activate:e=>this.activate(e),activateDefaultMode:()=>this.activateDefaultMode(),setCursor:(e,t,n)=>this.setCursor(e,t,n),getCurrentCursor:()=>this.getCurrentCursor(),removeCursor:e=>this.removeCursor(e),getHandlersForScope:e=>this.getHandlersForScope(e),activeModeIsExclusive:()=>this.activeModeIsExclusive(),pause:()=>this.pause(),resume:()=>this.resume(),isPaused:()=>this.registry.isDestroyed()||this.isPaused(),getState:()=>this.getDocumentStateOrThrow(),forDocument:e=>this.createInteractionScope(e),registerMode:e=>this.registerMode(e),registerHandlers:e=>this.registerHandlers(e),registerAlways:e=>this.registerAlways(e),setDefaultMode:e=>this.setDefaultMode(e),getDefaultMode:()=>this.state.defaultMode,getExclusionRules:()=>this.state.exclusionRules,setExclusionRules:e=>this.dispatch(Va(e)),addExclusionClass:e=>this.dispatch(Ha(e)),removeExclusionClass:e=>this.dispatch(Ua(e)),addExclusionAttribute:e=>this.dispatch(Wa(e)),removeExclusionAttribute:e=>this.dispatch(Ga(e)),claimPageActivity:(e,t,n)=>this.claimPageActivity(e,t,n),releasePageActivity:(e,t)=>this.releasePageActivity(e,t),hasPageActivity:(e,t)=>this.hasPageActivity(e,t),onModeChange:this.onModeChange$.on,onCursorChange:this.onCursorChange$.on,onHandlerChange:this.onHandlerChange$.on,onStateChange:this.onStateChange$.on,onPageActivityChange:this.onPageActivityChange$.on}}createInteractionScope(e){return{getActiveMode:()=>this.getActiveMode(e),getActiveInteractionMode:()=>this.getActiveInteractionMode(e),activate:t=>this.activate(t,e),activateDefaultMode:()=>this.activateDefaultMode(e),setCursor:(t,n,r)=>this.setCursor(t,n,r,e),getCurrentCursor:()=>this.getCurrentCursor(e),removeCursor:t=>this.removeCursor(t,e),getHandlersForScope:e=>this.getHandlersForScope(e),activeModeIsExclusive:()=>this.activeModeIsExclusive(e),pause:()=>this.pause(e),resume:()=>this.resume(e),isPaused:()=>this.isPaused(e),getState:()=>this.getDocumentStateOrThrow(e),claimPageActivity:(t,n)=>this.claimPageActivity(e,t,n),releasePageActivity:t=>this.releasePageActivity(e,t),hasPageActivity:t=>this.hasPageActivity(e,t),onModeChange:t=>this.onModeChange$.on(n=>{n.documentId===e&&t(n.activeMode)}),onCursorChange:t=>this.onCursorChange$.on(n=>{n.documentId===e&&t(n.cursor)}),onStateChange:t=>this.onStateChange$.on(n=>{n.documentId===e&&t(n.state)}),onPageActivityChange:t=>this.onPageActivityChange$.on(n=>{n.documentId===e&&t({pageIndex:n.pageIndex,hasActivity:n.hasActivity})})}}getDocumentState(e){let t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){let t=this.getDocumentState(e);if(!t)throw Error(`Interaction state not found for document: ${e??`active`}`);return t}activate(e,t){var n;let r=t??this.getActiveDocumentId(),i=this.getDocumentStateOrThrow(r);if(!this.modes.has(e))throw Error(`[interaction] unknown mode '${e}'`);if(e===i.activeMode)return;let a=i.activeMode;(n=this.cursorClaims.get(r))==null||n.clear(),this.notifyHandlersInactive(r,a),this.dispatch(Ia(r,e)),this.emitCursor(r),this.notifyHandlersActive(r,e),this.onModeChange$.emit({documentId:r,activeMode:e,previousMode:a})}activateDefaultMode(e){let t=e??this.getActiveDocumentIdOrNull();t&&this.activate(this.state.defaultMode,t)}setDefaultMode(e){if(!this.modes.has(e))throw Error(`[interaction] cannot set unknown mode '${e}' as default`);this.dispatch(Ba(e))}getActiveMode(e){return this.getDocumentStateOrThrow(e).activeMode}getActiveInteractionMode(e){let t=this.getDocumentState(e);return t?this.modes.get(t.activeMode)??null:null}activeModeIsExclusive(e){return!!this.getActiveInteractionMode(e)?.exclusive}pause(e){let t=e??this.getActiveDocumentId();this.dispatch(La(t))}resume(e){let t=e??this.getActiveDocumentId();this.dispatch(Ra(t))}isPaused(e){return this.getDocumentStateOrThrow(e).paused}registerMode(e){this.modes.set(e.id,e);for(let t of this.buckets.keys()){let n=this.buckets.get(t);n.has(e.id)||n.set(e.id,{global:/* @__PURE__ */ new Set,page:/* @__PURE__ */ new Map})}}registerHandlers({documentId:e,modeId:t,handlers:n,pageIndex:r}){let i=Array.isArray(t)?t:[t],a=[],o=this.buckets.get(e);if(!o)throw Error(`No buckets found for document: ${e}`);for(let e of i){let t=o.get(e);if(!t)throw Error(`unknown mode '${e}'`);if(r==null)t.global.add(n);else{let e=t.page.get(r)??/* @__PURE__ */ new Set;e.add(n),t.page.set(r,e)}a.push(()=>{if(r==null)t.global.delete(n);else{let e=t.page.get(r);e&&(e.delete(n),e.size===0&&t.page.delete(r))}})}return this.onHandlerChange$.emit({...this.state}),()=>{a.forEach(e=>e()),this.onHandlerChange$.emit({...this.state})}}registerAlways({scope:e,handlers:t}){if(e.type===`global`){let n=this.alwaysGlobal.get(e.documentId)??/* @__PURE__ */ new Set;return n.add(t),this.alwaysGlobal.set(e.documentId,n),this.onHandlerChange$.emit({...this.state}),()=>{n.delete(t),this.onHandlerChange$.emit({...this.state})}}let n=this.alwaysPage.get(e.documentId)??/* @__PURE__ */ new Map,r=n.get(e.pageIndex)??/* @__PURE__ */ new Set;return r.add(t),n.set(e.pageIndex,r),this.alwaysPage.set(e.documentId,n),this.onHandlerChange$.emit({...this.state}),()=>{r.delete(t),this.onHandlerChange$.emit({...this.state})}}getHandlersForScope(e){let t=this.getDocumentState(e.documentId);if(!t)return null;let n=this.modes.get(t.activeMode);if(!n)return null;let r=this.buckets.get(e.documentId);if(!r)return null;let i=r.get(n.id);if(!i)return null;let a=(e,t)=>e.size||t.size?Ka([...e,...t]):null;return e.type===`global`?a(this.alwaysGlobal.get(e.documentId)??/* @__PURE__ */ new Set,n.scope===`global`?i.global:/* @__PURE__ */ new Set):a(this.alwaysPage.get(e.documentId)?.get(e.pageIndex)??/* @__PURE__ */ new Set,n.scope===`page`?i.page.get(e.pageIndex)??/* @__PURE__ */ new Set:/* @__PURE__ */ new Set)}setCursor(e,t,n=0,r){let i=r??this.getActiveDocumentId(),a=this.cursorClaims.get(i);a&&(a.set(e,{cursor:t,priority:n}),this.emitCursor(i))}removeCursor(e,t){let n=t??this.getActiveDocumentId(),r=this.cursorClaims.get(n);r&&(r.delete(e),this.emitCursor(n))}getCurrentCursor(e){return this.getDocumentStateOrThrow(e).cursor}emitCursor(e){let t=this.cursorClaims.get(e);if(!t)return;let n=this.getDocumentState(e);if(!n)return;let r=[...t.values()].sort((e,t)=>t.priority-e.priority)[0]??{cursor:this.modes.get(n.activeMode)?.cursor??`auto`};r.cursor!==n.cursor&&(this.dispatch(za(e,r.cursor)),this.onCursorChange$.emit({documentId:e,cursor:r.cursor}))}claimPageActivity(e,t,n){let r=this.pageActivities.get(e);r||(r=/* @__PURE__ */ new Map,this.pageActivities.set(e,r));let i=r.get(t);i!==n&&(r.set(t,n),i!==void 0&&!this.pageHasAnyTopic(e,i)&&this.onPageActivityChange$.emit({documentId:e,pageIndex:i,hasActivity:!1}),this.countTopicsOnPage(e,n)===1&&this.onPageActivityChange$.emit({documentId:e,pageIndex:n,hasActivity:!0}))}releasePageActivity(e,t){let n=this.pageActivities.get(e);if(!n)return;let r=n.get(t);r!==void 0&&(n.delete(t),this.pageHasAnyTopic(e,r)||this.onPageActivityChange$.emit({documentId:e,pageIndex:r,hasActivity:!1}))}hasPageActivity(e,t){return this.pageHasAnyTopic(e,t)}pageHasAnyTopic(e,t){let n=this.pageActivities.get(e);if(!n)return!1;for(let e of n.values())if(e===t)return!0;return!1}countTopicsOnPage(e,t){let n=this.pageActivities.get(e);if(!n)return 0;let r=0;for(let e of n.values())e===t&&r++;return r}notifyHandlersActive(e,t){var n,r;(n=this.alwaysGlobal.get(e))==null||n.forEach(e=>{var n;(n=e.onHandlerActiveStart)==null||n.call(e,t)}),(r=this.alwaysPage.get(e))==null||r.forEach(e=>{e.forEach(e=>{var n;(n=e.onHandlerActiveStart)==null||n.call(e,t)})});let i=this.modes.get(t);if(!i)return;let a=this.buckets.get(e);if(!a)return;let o=a.get(t);o&&(i.scope===`global`&&o.global.forEach(e=>{var n;(n=e.onHandlerActiveStart)==null||n.call(e,t)}),i.scope===`page`&&o.page.forEach(e=>{e.forEach(e=>{var n;(n=e.onHandlerActiveStart)==null||n.call(e,t)})}))}notifyHandlersInactive(e,t){var n,r;(n=this.alwaysGlobal.get(e))==null||n.forEach(e=>{var n;(n=e.onHandlerActiveEnd)==null||n.call(e,t)}),(r=this.alwaysPage.get(e))==null||r.forEach(e=>{e.forEach(e=>{var n;(n=e.onHandlerActiveEnd)==null||n.call(e,t)})});let i=this.modes.get(t);if(!i)return;let a=this.buckets.get(e);if(!a)return;let o=a.get(t);o&&(i.scope===`global`&&o.global.forEach(e=>{var n;(n=e.onHandlerActiveEnd)==null||n.call(e,t)}),i.scope===`page`&&o.page.forEach(e=>{e.forEach(e=>{var n;(n=e.onHandlerActiveEnd)==null||n.call(e,t)})}))}onStoreUpdated(e,t){for(let n in t.documents){let r=e.documents[n],i=t.documents[n];r!==i&&this.onStateChange$.emit({documentId:n,state:i})}}async initialize(e){this.logger.info(`InteractionManagerPlugin`,`Initialize`,`Interaction Manager Plugin initialized`)}async destroy(){this.pageActivities.clear(),this.onModeChange$.clear(),this.onCursorChange$.clear(),this.onHandlerChange$.clear(),this.onStateChange$.clear(),this.onPageActivityChange$.clear(),await super.destroy()}},so.id=`interaction-manager`,co=so,lo=`interaction-manager`,uo={id:lo,name:`Interaction Manager Plugin`,version:`1.0.0`,provides:[`interaction-manager`],requires:[],optional:[],defaultConfig:{exclusionRules:{classes:[],dataAttributes:[`data-no-interaction`]}}},fo=`pointerMode`,po={defaultMode:fo,exclusionRules:{classes:[],dataAttributes:[`data-no-interaction`]},documents:{},activeDocumentId:null},mo=(e=po,t)=>{switch(t.type){case qa:{let{documentId:n,state:r}=t.payload;return{...e,documents:{...e.documents,[n]:r},activeDocumentId:e.activeDocumentId??n}}case Ja:{let n=t.payload,{[n]:r,...i}=e.documents;return{...e,documents:i,activeDocumentId:e.activeDocumentId===n?null:e.activeDocumentId}}case $a:return{...e,activeDocumentId:t.payload};case Ya:{let{documentId:n,mode:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,activeMode:r}}}:e}case Qa:{let{documentId:n,cursor:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,cursor:r}}}:e}case Xa:{let n=t.payload,r=e.documents[n];return r?{...e,documents:{...e.documents,[n]:{...r,paused:!0}}}:e}case Za:{let n=t.payload,r=e.documents[n];return r?{...e,documents:{...e.documents,[n]:{...r,paused:!1}}}:e}case eo:return{...e,defaultMode:t.payload.mode};case to:return{...e,exclusionRules:t.payload.rules};case no:return{...e,exclusionRules:{...e.exclusionRules,classes:[...e.exclusionRules.classes||[],t.payload.className].filter((e,t,n)=>n.indexOf(e)===t)}};case ro:return{...e,exclusionRules:{...e.exclusionRules,classes:(e.exclusionRules.classes||[]).filter(e=>e!==t.payload.className)}};case io:return{...e,exclusionRules:{...e.exclusionRules,dataAttributes:[...e.exclusionRules.dataAttributes||[],t.payload.attribute].filter((e,t,n)=>n.indexOf(e)===t)}};case ao:return{...e,exclusionRules:{...e.exclusionRules,dataAttributes:(e.exclusionRules.dataAttributes||[]).filter(e=>e!==t.payload.attribute)}};default:return e}},ho={manifest:uo,create:(e,t)=>new co(lo,e,t),reducer:mo,initialState:po}})))()}function _o(e){let{provides:t}=So(),[n,r]=j(()=>{if(!t)return!1;let n=t.forDocument(e).getActiveInteractionMode();return n?.scope===`page`&&!!n.exclusive});return O(()=>{if(!t)return;let n=t.forDocument(e);return n.onModeChange(()=>{let e=n.getActiveInteractionMode();r(e?.scope===`page`&&!!e?.exclusive)})},[t,e]),n}function vo(e,t){return e.startsWith(`touch`)?{passive:!t}:{passive:!1}}function yo(e){return typeof TouchEvent<`u`&&e instanceof TouchEvent}function bo(e,t){if(!e)return!1;let n=e;for(;n;){if(t.classes?.length){for(let e of t.classes)if(n.classList?.contains(e))return!0}if(t.dataAttributes?.length){for(let e of t.dataAttributes)if(n.hasAttribute(e))return!0}n=n.parentElement}return!1}function xo(e,t,n,r){let i=e.forDocument(t.documentId),a=e.getHandlersForScope(t),o=()=>i.getActiveInteractionMode()?.wantsRawTouch!==!1,s={},c=o(),l=e=>{Eo.forEach(t=>{let r=s[t]??(s[t]=_);n.addEventListener(t,r,vo(t,e))})},u=()=>{Eo.forEach(e=>{let t=s[e];t&&n.removeEventListener(e,t)})};l(c),n.style.touchAction=c?`none`:``;let d=i.onModeChange(()=>{if(t.type===`global`){let e=i.getActiveInteractionMode();n.style.cursor=e?.scope===`global`?e.cursor??`auto`:`auto`}a=e.getHandlersForScope(t);let r=o();r!==c&&(u(),l(r),c=r,n.style.touchAction=c?`none`:``)}),f=e.onHandlerChange(()=>{a=e.getHandlersForScope(t)}),p=i.getActiveInteractionMode(),m=i.getCurrentCursor();n.style.cursor=t.type===`global`&&p?.scope!==`global`?`auto`:m;let h=i.onCursorChange(e=>{(t.type!==`global`||i.getActiveInteractionMode()?.scope===`global`)&&(n.style.cursor=e)}),g=(e,t)=>{if(r)return r(e,t);let n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top}};function _(t){var r;if(e.isPaused())return;let o=e.getExclusionRules();if(t.target&&bo(t.target,o))return;let s=Co[t.type];if(!s||!a?.[s])return;yo(t)&&c&&(t.type===`touchmove`||t.type===`touchcancel`)&&t.preventDefault();let l,u,d=!1;if(yo(t)){let e=t.type===`touchend`||t.type===`touchcancel`?t.changedTouches[0]:t.touches[0];if(!e)return;l=g(e,n),u={clientX:e.clientX,clientY:e.clientY,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,target:t.target,currentTarget:t.currentTarget,setPointerCapture:()=>{},releasePointerCapture:()=>{},stopImmediatePropagation:()=>{d=!0},isImmediatePropagationStopped:()=>d}}else{let e=t;l=g(e,n),u={clientX:e.clientX,clientY:e.clientY,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,altKey:e.altKey,metaKey:e.metaKey,target:e.target,currentTarget:e.currentTarget,setPointerCapture:()=>{var t,n;(n=(t=e.target)?.setPointerCapture)==null||n.call(t,e.pointerId)},releasePointerCapture:()=>{var t,n;(n=(t=e.target)?.releasePointerCapture)==null||n.call(t,e.pointerId)},stopImmediatePropagation:()=>{d=!0},isImmediatePropagationStopped:()=>d}}(r=a[s])==null||r.call(a,l,u,i.getActiveMode())}return()=>{u(),d(),h(),f()}}var So,Co,wo,To,Eo,Do;function Oo(){return(Oo=e((()=>{q(),go(),C(),So=()=>G(co.id),Co={pointerdown:`onPointerDown`,pointerup:`onPointerUp`,pointermove:`onPointerMove`,pointerenter:`onPointerEnter`,pointerleave:`onPointerLeave`,pointercancel:`onPointerCancel`,mousedown:`onMouseDown`,mouseup:`onMouseUp`,mousemove:`onMouseMove`,mouseenter:`onMouseEnter`,mouseleave:`onMouseLeave`,mousecancel:`onMouseCancel`,click:`onClick`,dblclick:`onDoubleClick`,touchstart:`onPointerDown`,touchend:`onPointerUp`,touchmove:`onPointerMove`,touchcancel:`onPointerCancel`},wo=[`pointerdown`,`pointerup`,`pointermove`,`pointerenter`,`pointerleave`,`pointercancel`,`mousedown`,`mouseup`,`mousemove`,`mouseenter`,`mouseleave`,`mousecancel`,`click`,`dblclick`],To=[`touchstart`,`touchend`,`touchmove`,`touchcancel`],Eo=typeof PointerEvent<`u`?wo:[...wo,...To],Do=({documentId:e,pageIndex:t,children:n,rotation:r,scale:i,convertEventToPoint:a,style:o,...s})=>{let c=A(null),{provides:l}=So(),u=_o(e),d=K(e),f=d?.document?.pages?.[t],p=f?.size??{width:0,height:0},m=f?.rotation??0,h=d?.rotation??0,g=r===void 0?(m+h)%4:r,_=i??d?.scale??1,v=ae(p,0,_),y=he((e,t)=>{let n=t.getBoundingClientRect(),r={x:e.clientX-n.left,y:e.clientY-n.top},i=ae({width:v.width,height:v.height},g,1);return te(i,r,g,_)},[p,g,_]);return O(()=>{if(l&&c.current)return xo(l,{type:`page`,documentId:e,pageIndex:t},c.current,a||y)},[l,e,t,a,y]),/* @__PURE__ */ N(`div`,{ref:c,style:{position:`relative`,width:v.width,height:v.height,...o},...s,children:[n,u&&/* @__PURE__ */ M(`div`,{style:{position:`absolute`,top:0,left:0,right:0,bottom:0,zIndex:10}})]})}})))()}function ko(e,t,n){let r=1,i=0,a=0,o=1,s=0,c=0;switch(e){case 1:r=0,i=1,a=-1,o=0,s=n;break;case 2:r=-1,i=0,a=0,o=-1,s=t,c=n;break;case 3:r=0,i=-1,a=1,o=0,c=t}return[r,i,a,o,s,c]}function Ao(e,t,n){let[r,i,a,o,s,c]=ko(e,t,n);return`matrix(${r},${i},${a},${o},${s},${c})`}function jo(e){return(e+1)%4}function Mo(e){return(e+3)%4}function No(e,t){return{type:Ro,payload:{documentId:e,state:t}}}function Po(e){return{type:zo,payload:e}}function Fo(e,t){return{type:Vo,payload:{documentId:e,rotation:t}}}var Io,Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo;function Jo(){return(Jo=e((()=>{U(),Io=`rotate`,Lo={id:Io,name:`Rotate Plugin`,version:`1.0.0`,provides:[`rotate`],requires:[],optional:[],defaultConfig:{}},Ro=`ROTATE/INIT_STATE`,zo=`ROTATE/CLEANUP_STATE`,Bo=`ROTATE/SET_ACTIVE_DOCUMENT`,Vo=`ROTATE/SET_ROTATION`,Ho=class extends H{constructor(e,t,n){super(e,t),this.rotate$=L(),this.defaultRotation=n.defaultRotation??0}onDocumentLoadingStarted(e){let t={rotation:this.defaultRotation};this.dispatch(No(e,t)),this.dispatchCoreAction(bt(this.defaultRotation,e)),this.logger.debug(`RotatePlugin`,`DocumentOpened`,`Initialized rotation state for document: ${e}`)}onDocumentClosed(e){this.dispatch(Po(e)),this.logger.debug(`RotatePlugin`,`DocumentClosed`,`Cleaned up rotation state for document: ${e}`)}buildCapability(){return{setRotation:e=>this.setRotationForDocument(e),getRotation:()=>this.getRotationForDocument(),rotateForward:()=>this.rotateForward(),rotateBackward:()=>this.rotateBackward(),forDocument:e=>this.createRotateScope(e),onRotateChange:this.rotate$.on}}createRotateScope(e){return{setRotation:t=>this.setRotationForDocument(t,e),getRotation:()=>this.getRotationForDocument(e),rotateForward:()=>this.rotateForward(e),rotateBackward:()=>this.rotateBackward(e),onRotateChange:t=>this.rotate$.on(n=>{n.documentId===e&&t(n.rotation)})}}getDocumentState(e){let t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){let t=this.getDocumentState(e);if(!t)throw Error(`Rotation state not found for document: ${e??`active`}`);return t}setRotationForDocument(e,t){let n=t??this.getActiveDocumentId();if(!this.coreState.core.documents[n]?.document)throw Error(`Document ${n} not loaded`);this.dispatch(Fo(n,e)),this.dispatchCoreAction(bt(e,n)),this.rotate$.emit({documentId:n,rotation:e})}getRotationForDocument(e){return this.getDocumentStateOrThrow(e).rotation}rotateForward(e){let t=e??this.getActiveDocumentId(),n=jo(this.getRotationForDocument(t));this.setRotationForDocument(n,t)}rotateBackward(e){let t=e??this.getActiveDocumentId(),n=Mo(this.getRotationForDocument(t));this.setRotationForDocument(n,t)}getMatrixAsString(e){return Ao(e.rotation,e.width,e.height)}onStoreUpdated(e,t){for(let n in t.documents){let r=e.documents[n],i=t.documents[n];r?.rotation!==i.rotation&&this.logger.debug(`RotatePlugin`,`RotationChanged`,`Rotation changed for document ${n}: ${r?.rotation??0} -> ${i.rotation}`)}}async initialize(e){this.logger.info(`RotatePlugin`,`Initialize`,`Rotate plugin initialized`)}async destroy(){this.rotate$.clear(),super.destroy()}},Ho.id=`rotate`,Uo=Ho,Wo={rotation:0},Go={documents:{},activeDocumentId:null},Ko=(e=Go,t)=>{switch(t.type){case Ro:{let{documentId:n,state:r}=t.payload;return{...e,documents:{...e.documents,[n]:r},activeDocumentId:e.activeDocumentId??n}}case zo:{let n=t.payload,{[n]:r,...i}=e.documents;return{...e,documents:i,activeDocumentId:e.activeDocumentId===n?null:e.activeDocumentId}}case Bo:return{...e,activeDocumentId:t.payload};case Vo:{let{documentId:n,rotation:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,rotation:r}}}:e}default:return e}},qo={manifest:Lo,create:(e,t)=>new Uo(Io,e,t),reducer:Ko,initialState:Go}})))()}var Yo,Xo;function Zo(){return(Zo=e((()=>{q(),Jo(),Yo=()=>G(Uo.id),Xo=e=>{let{provides:t}=Yo(),[n,r]=j(Wo.rotation);return O(()=>{if(!t)return;let n=t.forDocument(e);return r(n.getRotation()),n.onRotateChange(e=>{r(e)})},[t,e]),{rotation:n,provides:t?.forDocument(e)??null}}})))()}function Qo(e,t){return{type:ts,payload:{documentId:e,state:t}}}function $o(e){return{type:ns,payload:e}}function es(e,t){return{type:is,payload:{documentId:e,isPanMode:t}}}var ts,ns,rs,is,as,os,ss,cs,ls,us,ds;function fs(){return(fs=e((()=>{U(),go(),Nn(),ts=`PAN/INIT_STATE`,ns=`PAN/CLEANUP_STATE`,rs=`PAN/SET_ACTIVE_DOCUMENT`,is=`PAN/SET_PAN_MODE`,as=class extends H{constructor(e,t,n){var r;super(e,t),this.panMode$=L(),this.documentHandlers=/* @__PURE__ */ new Map,this.config=n,this.interactionManager=t.getPlugin(co.id)?.provides(),this.viewport=t.getPlugin(jn.id)?.provides(),this.interactionManager&&(this.interactionManager.registerMode({id:`panMode`,scope:`global`,exclusive:!1,cursor:`grab`,wantsRawTouch:!1}),(r=this.interactionManager)==null||r.onModeChange(e=>{let t=e.activeMode===`panMode`,n=this.getDocumentState(e.documentId);n&&n.isPanMode!==t&&this.dispatch(es(e.documentId,t))}))}onDocumentLoadingStarted(e){this.dispatch(Qo(e,{isPanMode:!1})),this.registerPanHandlersForDocument(e),this.config.defaultMode===`always`&&this.makePanDefault(!0),this.logger.debug(`PanPlugin`,`DocumentOpened`,`Initialized pan state for document: ${e}`)}onDocumentClosed(e){let t=this.documentHandlers.get(e);t&&(t(),this.documentHandlers.delete(e)),this.dispatch($o(e)),this.logger.debug(`PanPlugin`,`DocumentClosed`,`Cleaned up pan state for document: ${e}`)}buildCapability(){return{enablePan:()=>this.enablePan(),disablePan:()=>this.disablePan(),togglePan:()=>this.togglePan(),makePanDefault:e=>this.makePanDefault(e),isPanMode:()=>this.isPanMode(),forDocument:e=>this.createPanScope(e),onPanModeChange:this.panMode$.on}}createPanScope(e){return{enablePan:()=>this.enablePan(e),disablePan:()=>this.disablePan(e),togglePan:()=>this.togglePan(e),isPanMode:()=>this.isPanMode(e),onPanModeChange:t=>this.panMode$.on(n=>{n.documentId===e&&t(n.isPanMode)})}}getDocumentState(e){let t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){let t=this.getDocumentState(e);if(!t)throw Error(`Pan state not found for document: ${e??`active`}`);return t}enablePan(e){let t=e??this.getActiveDocumentId();this.interactionManager.forDocument(t).activate(`panMode`)}disablePan(e){let t=e??this.getActiveDocumentId();this.interactionManager.forDocument(t).activateDefaultMode()}togglePan(e){let t=e??this.getActiveDocumentId(),n=this.interactionManager.forDocument(t);n.getActiveMode()===`panMode`?n.activateDefaultMode():n.activate(`panMode`)}makePanDefault(e=!0){this.interactionManager&&(this.interactionManager.setDefaultMode(`panMode`),e&&this.interactionManager.activateDefaultMode())}isPanMode(e){return this.getDocumentStateOrThrow(e).isPanMode}registerPanHandlersForDocument(e){if(!this.interactionManager||!this.viewport)return;let t=null,n=this.interactionManager.forDocument(e),r=this.viewport.forDocument(e),i=this.interactionManager.registerHandlers({documentId:e,modeId:`panMode`,handlers:{onMouseDown:(e,i)=>{let a=r.getMetrics();t={startX:i.clientX,startY:i.clientY,startLeft:a.scrollLeft,startTop:a.scrollTop},n.setCursor(`panMode`,`grabbing`,10)},onMouseMove:(e,n)=>{if(!t)return;let i=n.clientX-t.startX,a=n.clientY-t.startY;r.scrollTo({x:t.startLeft-i,y:t.startTop-a})},onMouseUp:()=>{t&&(t=null,n.removeCursor(`panMode`))},onMouseLeave:()=>{t&&(t=null,n.removeCursor(`panMode`))},onMouseCancel:()=>{t&&(t=null,n.removeCursor(`panMode`))}}});this.documentHandlers.set(e,i)}onStoreUpdated(e,t){for(let n in t.documents){let r=e.documents[n],i=t.documents[n];r?.isPanMode!==i.isPanMode&&(this.panMode$.emit({documentId:n,isPanMode:i.isPanMode}),this.logger.debug(`PanPlugin`,`PanModeChanged`,`Pan mode changed for document ${n}: ${r?.isPanMode??!1} -> ${i.isPanMode}`))}}async initialize(e){this.logger.info(`PanPlugin`,`Initialize`,`Pan plugin initialized`)}async destroy(){this.documentHandlers.forEach(e=>e()),this.documentHandlers.clear(),this.panMode$.clear(),await super.destroy()}},as.id=`pan`,os=as,ss={id:`pan`,name:`Pan Plugin`,version:`1.0.0`,provides:[`pan`],requires:[`interaction-manager`,`viewport`],optional:[],defaultConfig:{defaultMode:`mobile`}},cs={isPanMode:!1},ls={documents:{},activeDocumentId:null},us=(e=ls,t)=>{switch(t.type){case ts:{let{documentId:n,state:r}=t.payload;return{...e,documents:{...e.documents,[n]:r},activeDocumentId:e.activeDocumentId??n}}case ns:{let n=t.payload,{[n]:r,...i}=e.documents;return{...e,documents:i,activeDocumentId:e.activeDocumentId===n?null:e.activeDocumentId}}case rs:return{...e,activeDocumentId:t.payload};case is:{let{documentId:n,isPanMode:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,isPanMode:r}}}:e}default:return e}},ds={manifest:ss,create:(e,t)=>new os(`pan`,e,t),reducer:us,initialState:ls}})))()}var ps,ms,hs,gs,_s;function vs(){return(vs=e((()=>{U(),fs(),q(),ps=()=>W(os.id),ms=()=>G(os.id),hs=e=>{let{provides:t}=ms(),[n,r]=j(cs.isPanMode);return O(()=>{if(!t)return;let n=t.forDocument(e);return r(n.isPanMode()),n.onPanModeChange(e=>{r(e)})},[t,e]),{provides:t?.forDocument(e)??null,isPanning:n}},gs=()=>{let{provides:e}=ms(),{plugin:t}=ps();return O(()=>{if(!e||!t)return;let n=t.config?.defaultMode??`never`,r=typeof window<`u`&&(`ontouchstart`in window||navigator.maxTouchPoints>0);n===`mobile`&&r&&e.makePanDefault()},[e,t]),null},_s=Ge(ds).addUtility(gs).build()})))()}function ys(e,t){return{type:Ts,payload:{documentId:e,state:t}}}function bs(e){return{type:Es,payload:e}}function xs(e,t){return{type:Os,payload:{documentId:e,window:t}}}function Ss(e,t,n){return{type:ks,payload:{documentId:e,scrollY:t,viewportH:n}}}var Cs,ws,Ts,Es,Ds,Os,ks,As,js,Ms,Ns,Ps,Fs;function Is(){return(Is=e((()=>{U(),C(),Cs=`thumbnail`,ws={id:Cs,name:`Thumbnail Plugin`,version:`1.0.0`,provides:[`thumbnail`],requires:[`render`],optional:[`scroll`],defaultConfig:{width:150,gap:10,buffer:3,labelHeight:16,autoScroll:!0,scrollBehavior:`smooth`,imagePadding:0,paddingY:0}},Ts=`THUMBNAIL/INIT_STATE`,Es=`THUMBNAIL/CLEANUP_STATE`,Ds=`THUMBNAIL/SET_ACTIVE_DOCUMENT`,Os=`THUMBNAIL/SET_WINDOW_STATE`,ks=`THUMBNAIL/UPDATE_VIEWPORT_METRICS`,As={thumbs:[],window:null,viewportH:0,scrollY:0},js={documents:{},activeDocumentId:null},Ms=(e=js,t)=>{switch(t.type){case Ts:{let{documentId:n,state:r}=t.payload;return{...e,documents:{...e.documents,[n]:r},activeDocumentId:e.activeDocumentId??n}}case Es:{let n=t.payload,{[n]:r,...i}=e.documents;return{...e,documents:i,activeDocumentId:e.activeDocumentId===n?null:e.activeDocumentId}}case Ds:return{...e,activeDocumentId:t.payload};case Os:{let{documentId:n,window:r}=t.payload,i=e.documents[n];return i?{...e,documents:{...e.documents,[n]:{...i,window:r}}}:e}case ks:{let{documentId:n,scrollY:r,viewportH:i}=t.payload,a=e.documents[n];return a?{...e,documents:{...e.documents,[n]:{...a,scrollY:r,viewportH:i}}}:e}default:return e}},Ns=class extends H{constructor(e,t,n){super(e,t),this.cfg=n,this.scrollCapability=null,this.taskCaches=/* @__PURE__ */ new Map,this.canAutoScroll=/* @__PURE__ */ new Map,this.window$=R((e,t)=>({documentId:e,window:t})),this.scrollTo$=R((e,t)=>({documentId:e,options:t})),this.refreshPages$=R((e,t)=>({documentId:e,pages:t}),{cache:!1}),this.renderCapability=this.registry.getPlugin(`render`).provides(),this.scrollCapability=this.registry.getPlugin(`scroll`)?.provides()??null,this.coreStore.onAction(ot,e=>{let t=e.payload.documentId??this.getActiveDocumentId(),n=e.payload.pageIndexes;this.refreshPages$.emit(t,n);let r=this.taskCaches.get(t);if(r)for(let e of n)r.delete(e)}),this.scrollCapability&&this.cfg.autoScroll!==!1&&(this.scrollCapability.onPageChangeState(({documentId:e,state:t})=>{this.canAutoScroll.set(e,!t.isChanging),t.isChanging||this.scrollToThumb(t.targetPage-1,e)}),this.scrollCapability.onPageChange(({documentId:e,pageNumber:t})=>{this.canAutoScroll.get(e)!==!1&&this.scrollToThumb(t-1,e)}))}onDocumentLoadingStarted(e){this.dispatch(ys(e,{...As})),this.taskCaches.set(e,/* @__PURE__ */ new Map),this.canAutoScroll.set(e,!0),this.logger.debug(`ThumbnailPlugin`,`DocumentOpened`,`Initialized thumbnail state for document: ${e}`)}onDocumentLoaded(e){this.calculateWindowState(e)}onDocumentClosed(e){this.dispatch(bs(e));let t=this.taskCaches.get(e);t&&(t.forEach(e=>{e.abort({code:`cancelled`,message:`Document closed`})}),t.clear(),this.taskCaches.delete(e)),this.canAutoScroll.delete(e),this.window$.clearScope(e),this.scrollTo$.clearScope(e),this.refreshPages$.clearScope(e),this.logger.debug(`ThumbnailPlugin`,`DocumentClosed`,`Cleaned up thumbnail state for document: ${e}`)}onRotationChanged(e){this.calculateWindowState(e)}buildCapability(){return{scrollToThumb:e=>this.scrollToThumb(e),renderThumb:(e,t)=>this.renderThumb(e,t),updateWindow:(e,t)=>this.updateWindow(e,t),getWindow:()=>this.getWindow(),forDocument:e=>this.createThumbnailScope(e),onWindow:this.window$.onGlobal,onScrollTo:this.scrollTo$.onGlobal,onRefreshPages:this.refreshPages$.onGlobal}}createThumbnailScope(e){return{scrollToThumb:t=>this.scrollToThumb(t,e),renderThumb:(t,n)=>this.renderThumb(t,n,e),updateWindow:(t,n)=>this.updateWindow(t,n,e),getWindow:()=>this.getWindow(e),onWindow:this.window$.forScope(e),onScrollTo:this.scrollTo$.forScope(e),onRefreshPages:this.refreshPages$.forScope(e)}}getDocumentState(e){let t=e??this.getActiveDocumentId();return this.state.documents[t]??null}calculateWindowState(e){let t=this.coreState.core.documents[e];if(!t?.document)return;let n=this.cfg.width??120,r=this.cfg.labelHeight??16,i=this.cfg.gap??8,a=this.cfg.imagePadding??0,o=this.cfg.paddingY??0,s=Math.max(1,n-2*a),c=o,l=t.document.pages.map(e=>{let t=e.rotation%2==1,n=t?e.size.height:e.size.width,o=(t?e.size.width:e.size.height)/n,l=Math.round(s*o),u=a+l+a+r,d={pageIndex:e.index,width:s,height:l,wrapperHeight:u,top:c,labelHeight:r,padding:a};return c+=u+i,d}),u={start:-1,end:-1,items:[],totalHeight:c-i+o},d=this.getDocumentState(e);d&&(this.dispatch(ys(e,{...d,thumbs:l,window:u})),d.viewportH>0?this.updateWindow(d.scrollY,d.viewportH,e):this.window$.emit(e,u))}updateWindow(e,t,n){let r=n??this.getActiveDocumentId(),i=this.getDocumentState(r);if(!i||!i.window||i.thumbs.length===0)return;let a=this.cfg.buffer??3;this.dispatch(Ss(r,e,t));let o=0,s=i.thumbs.length-1,c=0;for(;o<=s;){let t=o+s>>1,n=i.thumbs[t];n.top+n.wrapperHeight<e?o=t+1:(c=t,s=t-1)}let l=c,u=e+t;for(;l+1<i.thumbs.length&&i.thumbs[l].top<u;)l++;l=Math.min(i.thumbs.length-1,l+a);let d=Math.max(0,c-a);if(d===i.window.start&&l===i.window.end)return;let f={start:d,end:l,items:i.thumbs.slice(d,l+1),totalHeight:i.window.totalHeight};this.dispatch(xs(r,f)),this.window$.emit(r,f)}getWindow(e){return this.getDocumentState(e)?.window??null}scrollToThumb(e,t){let n=t??this.getActiveDocumentId(),r=this.getDocumentState(n);if(!r||!r.window)return;let i=r.thumbs[e];if(!i)return;let a=this.cfg.scrollBehavior??`smooth`,o=this.cfg.paddingY??0;if(r.viewportH<=0){let e=Math.max(o,i.top-i.wrapperHeight);this.scrollTo$.emit(n,{top:e,behavior:a});return}let s=i.top,c=i.top+i.wrapperHeight,l=s<r.scrollY+8+o,u=c>r.scrollY+r.viewportH-8;l?this.scrollTo$.emit(n,{top:Math.max(0,s-o),behavior:a}):u&&this.scrollTo$.emit(n,{top:Math.max(0,c-r.viewportH+o),behavior:a})}renderThumb(e,t,n){let r=n??this.getActiveDocumentId(),i=this.taskCaches.get(r);if(!i)throw Error(`Task cache not found for document: ${r}`);if(i.has(e))return i.get(e);let a=this.coreState.core.documents[r];if(!a?.document)throw Error(`Document not found: ${r}`);let o=a.document.pages[e];if(!o)throw Error(`Page ${e} not found in document: ${r}`);let s=this.cfg.width??120,c=this.cfg.imagePadding??0,l=Math.max(1,s-2*c)/o.size.width,u=this.renderCapability.forDocument(r).renderPageRect({pageIndex:e,rect:{origin:{x:0,y:0},size:o.size},options:{scaleFactor:l,dpr:t,rotation:o.rotation}});return i.set(e,u),u.wait(T,()=>i.delete(e)),u}async initialize(){this.logger.info(`ThumbnailPlugin`,`Initialize`,`Thumbnail plugin initialized`)}async destroy(){this.window$.clear(),this.refreshPages$.clear(),this.scrollTo$.clear(),this.taskCaches.forEach(e=>{e.forEach(e=>{e.abort({code:`cancelled`,message:`Plugin destroyed`})}),e.clear()}),this.taskCaches.clear(),this.canAutoScroll.clear(),super.destroy()}},Ns.id=`thumbnail`,Ps=Ns,Fs={manifest:ws,create:(e,t)=>new Ps(Cs,e,t),reducer:Ms,initialState:js}})))()}function Ls({documentId:e,style:t,children:n,...r}){let{plugin:i}=zs(),a=A(null),[o,s]=j({window:null,docId:null}),c=o.docId===e?o.window:null;O(()=>{if(!i)return;let t=i.provides().forDocument(e),n=t.getWindow();n&&s({window:n,docId:e});let r=t.onWindow(t=>{s({window:t,docId:e})});return()=>{r(),s({window:null,docId:null})}},[i,e]),O(()=>{let t=a.current;if(!t||!i)return;let n=i.provides().forDocument(e),r=()=>n.updateWindow(t.scrollTop,t.clientHeight);return t.addEventListener(`scroll`,r),()=>t.removeEventListener(`scroll`,r)},[i,e]),O(()=>{let t=a.current;if(!t||!i)return;let n=i.provides().forDocument(e),r=new ResizeObserver(()=>{n.updateWindow(t.scrollTop,t.clientHeight)});return r.observe(t),()=>r.disconnect()},[i,e]),O(()=>{let t=a.current;t&&i&&i.provides().forDocument(e).updateWindow(t.scrollTop,t.clientHeight)},[c,i,e]),O(()=>{let t=a.current;if(t&&i&&c)return i.provides().forDocument(e).onScrollTo(({top:e,behavior:n})=>{t.scrollTo({top:e,behavior:n})})},[i,e,!!c]);let l=i?.cfg.paddingY??0;return/* @__PURE__ */ M(`div`,{ref:a,style:{overflowY:`auto`,position:`relative`,paddingTop:l,paddingBottom:l,height:`100%`,...t},...r,children:/* @__PURE__ */ M(`div`,{style:{height:c?.totalHeight??0,position:`relative`},children:c?.items.map(e=>n(e))})})}function Rs({documentId:e,meta:t,style:n,...r}){let{provides:i}=Bs(),{plugin:a}=zs(),[o,s]=j(),c=A(null),[l,u]=j(0);return O(()=>{if(a)return a.provides().forDocument(e).onRefreshPages(e=>{e.includes(t.pageIndex)&&u(e=>e+1)})},[a,e,t.pageIndex]),O(()=>{let n=(i?.forDocument(e))?.renderThumb(t.pageIndex,window.devicePixelRatio);return n?.wait(e=>{let t=URL.createObjectURL(e);c.current=t,s(t)},T),()=>{c.current?(URL.revokeObjectURL(c.current),c.current=null):n?.abort({code:D.Cancelled,message:`canceled render task`})}},[i,e,t.pageIndex,l]),o?/* @__PURE__ */ M(`img`,{src:o,onLoad:()=>{c.current&&=(URL.revokeObjectURL(c.current),null)},style:n,...r}):null}var zs,Bs;function Vs(){return(Vs=e((()=>{q(),Is(),C(),zs=()=>W(Ps.id),Bs=()=>G(Ps.id)})))()}var Hs,Us,Ws,Gs,Ks;function qs(){return(qs=e((()=>{U(),C(),Hs=`print`,Us={id:Hs,name:`Print Plugin`,version:`1.0.0`,provides:[`print`],requires:[],optional:[],defaultConfig:{}},Ws=class extends H{constructor(e,t,n){super(e,t),this.printReady$=I()}buildCapability(){return{print:e=>this.print(e),forDocument:e=>this.createPrintScope(e)}}createPrintScope(e){return{print:t=>this.print(t,e)}}print(e,t){let n=t??this.getActiveDocumentId();if(!this.checkPermission(n,E.Print))return this.logger.debug(`PrintPlugin`,`Print`,`Cannot print: document ${n} lacks Print permission`),x.reject({code:D.Security,message:`Document lacks Print permission`});let r=e??{},i=new w;return i.progress({stage:`preparing`,message:`Preparing document...`}),this.preparePrintDocument(r,n).wait(e=>{i.progress({stage:`document-ready`,message:`Document prepared successfully`}),this.printReady$.emit({documentId:n,options:r,buffer:e,task:i})},e=>i.fail(e)),i}preparePrintDocument(e,t){let n=this.coreState.core.documents[t];return n?.document?this.engine.preparePrintDocument(n.document,e):x.reject({code:D.DocNotOpen,message:`Document ${t} not found`})}onPrintRequest(e){return this.printReady$.on(e)}async initialize(e){this.logger.info(`PrintPlugin`,`Initialize`,`Print plugin initialized`)}async destroy(){this.printReady$.clear(),await super.destroy()}},Ws.id=`print`,Gs=Ws,Ks={manifest:Us,create:(e,t)=>new Gs(Hs,e,t),reducer:()=>{},initialState:{}}})))()}function Js(){if(Zs)return Xs;Zs=1;var e=be;return Xs.createRoot=e.createRoot,Xs.hydrateRoot=e.hydrateRoot,Xs}function Ys(){let{provides:e}=$s(),{plugin:t}=Qs(),n=A(null),r=A(null);return O(()=>{if(!e||!t)return;let i=t.onPrintRequest(({buffer:e,task:t})=>{let i=n.current;if(!i)return;r.current&&=(URL.revokeObjectURL(r.current),null);let a=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));r.current=a,i.onload=()=>{var n,r;i.src===a&&(t.progress({stage:`iframe-ready`,message:`Ready to print`}),(n=i.contentWindow)==null||n.focus(),(r=i.contentWindow)==null||r.print(),t.progress({stage:`printing`,message:`Print dialog opened`}),t.resolve(e))},i.src=a});return()=>{i(),r.current&&URL.revokeObjectURL(r.current)}},[e,t]),/* @__PURE__ */ M(`iframe`,{ref:n,style:{position:`absolute`,display:`none`},title:`Print Document`,src:`about:blank`})}var Xs,Zs,Qs,$s,ec,tc;function nc(){return(nc=e((()=>{U(),qs(),q(),Xs={},Js(),Qs=()=>W(Gs.id),$s=()=>G(Gs.id),ec=e=>{let{provides:t}=$s();return{provides:t?.forDocument(e)??null}},tc=Ge(Ks).addUtility(Ys).build()})))()}var rc;function ic(){return(ic=e((()=>{rc=new URL(`../assets/pdfium-BJ2Yip8Q.wasm`,import.meta.url).href})))()}function ac({documentId:e,url:t,fileName:n}){let{provides:i,state:a}=dr(e),{provides:o}=Vr(e),{provides:s,state:l}=bi(e),{provides:d}=Xo(e),{provides:p,isPanning:h}=hs(e),{provides:_}=ec(e),v=_e(),[b,x]=j(Y.FitWidth),[S,ee]=j(``),[C,te]=j(!1);return/* @__PURE__ */ N(ye,{children:[/* @__PURE__ */ N(`div`,{role:`toolbar`,"aria-label":`PDF 工具栏`,style:{display:`flex`,flexWrap:`wrap`,alignItems:`center`,gap:6,padding:8,borderBottom:`1px solid var(--color-border)`},children:[/* @__PURE__ */ M(y,{"aria-label":`缩略图`,theme:`borderless`,icon:/* @__PURE__ */ M(je,{size:16}),onClick:()=>te(!C)}),/* @__PURE__ */ M(y,{"aria-label":`上一页`,disabled:a.currentPage<=1,theme:`borderless`,icon:/* @__PURE__ */ M(c,{size:16}),onClick:()=>i?.scrollToPreviousPage()}),/* @__PURE__ */ N(`span`,{"aria-label":`PDF 页码`,children:[a.currentPage,` / `,a.totalPages]}),/* @__PURE__ */ M(y,{"aria-label":`下一页`,disabled:a.currentPage>=a.totalPages,theme:`borderless`,icon:/* @__PURE__ */ M(u,{size:16}),onClick:()=>i?.scrollToNextPage()}),/* @__PURE__ */ M(`span`,{id:v,className:`sr-only`,children:`PDF 缩放`}),/* @__PURE__ */ M(r,{"aria-labelledby":v,size:`small`,value:String(b),style:{width:110},optionList:uc,onChange:e=>{let t=e===`1`?1:e;x(t),o?.requestZoom(t)}}),/* @__PURE__ */ M(y,{"aria-label":`旋转`,theme:`borderless`,icon:/* @__PURE__ */ M(g,{size:16}),onClick:()=>d?.rotateForward()}),/* @__PURE__ */ M(y,{"aria-label":`拖动页面`,"aria-pressed":h,theme:h?`solid`:`borderless`,icon:/* @__PURE__ */ M(Se,{size:16}),onClick:()=>p?.togglePan()}),/* @__PURE__ */ N(`form`,{"aria-label":`PDF 搜索`,style:{display:`flex`,gap:4},onSubmit:e=>{e.preventDefault(),S.trim()?(s?.startSearch(),s?.searchAllPages(S)):s?.stopSearch()},children:[/* @__PURE__ */ M(`input`,{"aria-label":`搜索 PDF 文本`,placeholder:`搜索 PDF 文本`,value:S,style:{width:120,color:`inherit`,background:`transparent`,border:`1px solid var(--color-border)`,borderRadius:`var(--semi-border-radius-small)`},onChange:e=>{ee(e.target.value),e.target.value||s?.stopSearch()}}),/* @__PURE__ */ M(y,{htmlType:`submit`,size:`small`,children:`搜索`})]}),l.active&&/* @__PURE__ */ N(ye,{children:[/* @__PURE__ */ N(`span`,{role:`status`,"aria-label":`搜索结果`,children:[l.total?l.activeResultIndex+1:0,` / `,l.total]}),/* @__PURE__ */ M(y,{"aria-label":`上个结果`,size:`small`,disabled:!l.total,onClick:()=>s?.previousResult(),children:`↑`}),/* @__PURE__ */ M(y,{"aria-label":`下个结果`,size:`small`,disabled:!l.total,onClick:()=>s?.nextResult(),children:`↓`})]}),/* @__PURE__ */ M(y,{"aria-label":`打印 PDF`,theme:`borderless`,icon:/* @__PURE__ */ M(m,{size:16}),onClick:()=>_?.print()}),/* @__PURE__ */ M(`a`,{href:t,download:n,"aria-label":`下载 PDF`,children:/* @__PURE__ */ M(f,{size:16})})]}),/* @__PURE__ */ N(`div`,{style:{display:`flex`,flex:1,minHeight:0},children:[C&&/* @__PURE__ */ M(Ls,{documentId:e,"aria-label":`PDF 缩略图`,style:{width:140,flexShrink:0},children:t=>/* @__PURE__ */ N(`button`,{"aria-label":`跳到第 `+(t.pageIndex+1)+` 页`,style:{position:`absolute`,top:t.top,height:t.wrapperHeight,width:`100%`,border:0,background:`transparent`,color:`inherit`},onClick:()=>i?.scrollToPage({pageNumber:t.pageIndex+1}),children:[/* @__PURE__ */ M(Rs,{documentId:e,meta:t,style:{display:`block`,margin:`auto`}}),t.pageIndex+1]},t.pageIndex)}),/* @__PURE__ */ M(Fn,{documentId:e,style:{flex:1,minWidth:0,height:`100%`,background:`var(--color-content-bg)`},children:/* @__PURE__ */ M(cr,{documentId:e,renderPage:({width:t,height:n,pageIndex:r})=>/* @__PURE__ */ N(Do,{documentId:e,pageIndex:r,style:{width:t,height:n,position:`relative`},children:[/* @__PURE__ */ M(vr,{documentId:e,pageIndex:r}),/* @__PURE__ */ M(vi,{documentId:e,pageIndex:r}),/* @__PURE__ */ M(Da,{documentId:e,pageIndex:r})]})})})]})]})}function oc({documentId:e,message:t}){let{provides:n}=Qt(),[r,i]=j(``);return/* @__PURE__ */ N(`form`,{role:`alert`,style:{padding:16},onSubmit:t=>{t.preventDefault(),n?.retryDocument(e,{password:r})},children:[/* @__PURE__ */ N(`p`,{children:[`PDF 加载失败:`,t]}),/* @__PURE__ */ M(`input`,{"aria-label":`PDF 密码`,placeholder:`加密 PDF 密码`,type:`password`,value:r,onChange:e=>i(e.target.value)}),/* @__PURE__ */ M(y,{htmlType:`submit`,children:`重试`})]})}function sc({file:e}){let t=new URL(rc,globalThis.location.href).href,{engine:n,error:r}=Bt({wasmUrl:t}),[i,a]=j(null);O(()=>{let t=URL.createObjectURL(e);return a({file:e,url:t}),()=>URL.revokeObjectURL(t)},[e]);let o=i?.file===e?i.url:null,s=k(()=>[P($t,{initialDocuments:o?[{url:o,name:e.name}]:[]}),P(Mn),P(or),P(gr),P(ho),P(Rr,{defaultZoomLevel:Y.FitWidth}),P(gi),P(Ma),P(qo),P(_s),P(Fs),P(tc)],[o,e.name]);return r?/* @__PURE__ */ N(`div`,{role:`alert`,children:[`PDF 引擎加载失败:`,r.message]}):!n||!o?/* @__PURE__ */ M(`div`,{role:`status`,children:`正在加载 PDF…`}):/* @__PURE__ */ M(It,{engine:n,plugins:s,children:({activeDocumentId:t})=>t?/* @__PURE__ */ N(ye,{children:[/* @__PURE__ */ M(gs,{}),/* @__PURE__ */ M(Yt,{documentId:t,children:({isLoaded:n,isError:r,documentState:i})=>n?/* @__PURE__ */ M(ac,{documentId:t,url:o,fileName:e.name}):r?/* @__PURE__ */ M(oc,{documentId:t,message:i.error}):/* @__PURE__ */ M(`div`,{role:`status`,children:`正在加载 PDF…`})})]}):null},o)}function cc({file:e,onClose:t,fullscreen:n,onToggleFullscreen:r,style:i,actions:a}){let{isDark:o}=ue();return/* @__PURE__ */ N(`div`,{style:{width:`50%`,minWidth:320,display:`flex`,flexDirection:`column`,borderLeft:`1px solid var(--color-border)`,overflow:`hidden`,flexShrink:0,colorScheme:o?`dark`:`light`,...i},children:[/* @__PURE__ */ N(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,padding:`10px 16px`,borderBottom:`1px solid var(--color-border)`,flexShrink:0},children:[/* @__PURE__ */ M(fe,{icon:`vscode-icons:file-type-pdf2`,size:15}),/* @__PURE__ */ M(lc,{ellipsis:{showTooltip:!0},style:{flex:1,fontSize:13,fontWeight:500,minWidth:0},children:e.name}),a,r&&/* @__PURE__ */ M(y,{"aria-label":n?`退出全屏`:`全屏`,theme:`borderless`,size:`small`,icon:M(n?Oe:Te,{size:14}),onClick:r}),/* @__PURE__ */ M(y,{"aria-label":`关闭预览`,theme:`borderless`,size:`small`,icon:/* @__PURE__ */ M(v,{size:14}),onClick:t})]}),/* @__PURE__ */ M(sc,{file:e})]})}var lc,uc;function dc(){return(dc=e((()=>{U(),q(),Ht(),en(),Bn(),fr(),br(),Hr(),xi(),Na(),Oo(),Zo(),vs(),Vs(),nc(),ic(),b(),s(),l(),d(),Ce(),Ee(),ke(),Me(),p(),h(),_(),de(),le(),{Text:lc}=i,uc=[{value:Y.Automatic,label:`自动缩放`},{value:Y.FitPage,label:`适合页高`},{value:Y.FitWidth,label:`适合页宽`},{value:`1`,label:`实际大小`}]})))()}dc();export{cc as PDFPreviewPanel};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-BKuNeK48.js";import{FormPasswordInput as t,PasswordInput as n}from"@fudanda/elements-antd";function r(){return(r=e((()=>{})))()}export{n,r,t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-BKuNeK48.js";import{c as t,l as n,n as r,t as i}from"./ConfigurableTable-CyfZLgG0.js";import{r as ee,s as a,t as o}from"./toolbar-controls-BFOuV86W.js";import{t as s}from"./form-DhQiOMvp.js";import{w as c}from"./ui-DoIHGuTR.js";import{n as l,t as u}from"./useStatusToggle-B7KSIN75.js";import{r as d,t as f}from"./deleteAction-NGTDhZud.js";import{n as p,t as m}from"./useCrudOperationColumn-PObQMk2y.js";import{n as te,t as h}from"./useRowSelection-4GOMFmjG.js";import{n as g,t as _}from"./useListPage-1Upr_ala.js";import{i as v,n as y,s as b}from"./table-columns-XaoxVUJN.js";import{a as x,i as S,r as C,t as w}from"./EditFormModal-D68dOnaj.js";import{n as T,t as E}from"./ExportButton-D4IvZKHy.js";import{n as D,r as O,t as k}from"./MemberAssignmentSheet-NWm5vThg.js";import{useEffect as A,useState as j}from"react";import{Fragment as M,jsx as N,jsxs as P}from"react/jsx-runtime";import{useDictItems as F}from"@fudanda/react-core/hooks/useDictItems";import{usePermission as I}from"@fudanda/react-core/hooks/usePermission";import{useAllUsers as L}from"@fudanda/react-core/hooks/queries/users";import{positionContract as R}from"@fudanda/shared/identity";import{useFlatDepartments as z}from"@fudanda/react-core/hooks/queries/departments";import{useAssignPositionMembers as B,useDeletePositions as V,usePositionDetail as H,usePositionList as U,usePositionMembers as ne,useSavePosition as W}from"@fudanda/react-core/hooks/queries/positions";function G(){let{hasPermission:e}=I(),{selectedRowKeys:n,clear:r,rowSelection:a}=te(),c=g({contract:R,useList:U,table:{empty:`暂无数据`,rowSelection:a}}),{tableProps:u,filterQuery:d}=c,{options:m}=F(`common_status`),h=L(),_=z(),v=h.data??[],S=_.data??[],[C,T]=j(!1),[D,G]=j(null),[K,q]=j([]),J=ne(D?.id,C),Y=W(),X=x({entityName:`岗位`,save:Y,useDetail:H,defaults:{sort:0,status:`enabled`},toValues:e=>({name:e.name,code:e.code,sort:e.sort,status:e.status,remark:e.remark??void 0})}),Z=W(),Q=V(),$=B(),re=l({toggle:(e,t)=>Z.mutateAsync({id:e.id,values:{status:t?`enabled`:`disabled`}}),confirmDisable:e=>({danger:!0,title:`确认停用岗位「${e.name}」?`,content:`停用后该岗位将不可选择。`,okText:`确认停用`}),disabled:!e(`system:position:update`)});A(()=>{C&&q((J.data??[]).map(e=>e.id))},[C,J.data]);let ie=()=>{n.length&&f({title:`确认删除选中的 ${n.length} 个岗位?`,content:`删除后无法恢复,请确认操作`,run:()=>Q.mutateAsync(n),onDeleted:r})},ae=e=>{G(e),T(!0)},oe=async()=>{D&&(await $.mutateAsync({params:{id:D.id},body:{userIds:K}}),T(!1))},se=p({permission:`system:position`,edit:e=>{X.openEdit(e)},remove:Q,title:`确定要删除该岗位吗?`,extraBetween:t=>[{key:`members`,label:`成员`,hidden:!e(`system:position:update`),onClick:()=>{ae(t)}}],width:210}),ce=[{title:`岗位名称`,dataIndex:`name`,minWidth:200,render:b},{title:`岗位编码`,dataIndex:`code`,width:180,render:b},{title:`排序`,dataIndex:`sort`,width:90},O({dataIndex:`userPreview`,width:150,getPreview:e=>e.userPreview,getCount:e=>e.userCount,getScope:e=>({type:`position`,id:e.id,name:e.name})}),{title:`备注`,dataIndex:`remark`,width:200,render:b},y,re.column(),se];return/* @__PURE__ */ P(`div`,{className:`page-container`,children:[/* @__PURE__ */ N(i,{searchConfig:t({page:c,filters:[`keyword`,`status`,[`startTime`,`endTime`]],create:/* @__PURE__ */ N(ee,{permission:`system:position:create`,onClick:X.openCreate}),actions:/* @__PURE__ */ P(M,{children:[/* @__PURE__ */ N(E,{entity:`system.positions`,query:d}),n.length>0&&e(`system:position:delete`)&&/* @__PURE__ */ N(o,{count:n.length,onClick:ie})]}),filterTitle:`岗位筛选`}),columns:ce,...u}),/* @__PURE__ */ P(w,{modal:X,width:520,children:[/* @__PURE__ */ N(s.Input,{field:`name`,label:`岗位名称`,placeholder:`请输入岗位名称`,rules:[{required:!0,message:`请输入岗位名称`}]}),/* @__PURE__ */ N(s.Input,{field:`code`,label:`岗位编码`,placeholder:`请输入岗位编码`,rules:[{required:!0,message:`请输入岗位编码`}]}),/* @__PURE__ */ N(s.InputNumber,{field:`sort`,label:`排序`,placeholder:`请输入排序`,min:0,style:{width:`100%`}}),/* @__PURE__ */ N(s.Select,{field:`status`,label:`状态`,optionList:m,style:{width:`100%`},placeholder:`请选择状态`}),/* @__PURE__ */ N(s.TextArea,{field:`remark`,label:`备注`,placeholder:`请输入备注`,maxCount:256})]}),/* @__PURE__ */ N(k,{title:`成员管理 - ${D?.name??``}`,visible:C,onCancel:()=>T(!1),users:v,value:K,onChange:q,departments:S,canSave:J.isSuccess,saveLoading:$.isPending,onSave:oe})]})}function K(){return(K=e((()=>{c(),T(),r(),v(),S(),a(),d(),n(),h(),u(),m(),D(),_(),C()})))()}K();export{G as default};
|