@embedpdf/core 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +165 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/base/base-plugin.d.ts +24 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/store/actions.d.ts +15 -3
- package/dist/lib/store/initial-state.d.ts +4 -0
- package/dist/lib/store/selectors.d.ts +20 -0
- package/dist/lib/types/permissions.d.ts +55 -0
- package/dist/lib/types/plugin.d.ts +6 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +113 -1
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +113 -1
- package/dist/react/index.js.map +1 -1
- package/dist/shared/components/embed-pdf.d.ts +7 -3
- package/dist/shared/hooks/index.d.ts +1 -0
- package/dist/shared/hooks/use-document-permissions.d.ts +35 -0
- package/dist/shared-preact/components/embed-pdf.d.ts +7 -3
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-document-permissions.d.ts +35 -0
- package/dist/shared-react/components/embed-pdf.d.ts +7 -3
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-document-permissions.d.ts +35 -0
- package/dist/svelte/components/EmbedPDF.svelte.d.ts +6 -2
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-document-permissions.svelte.d.ts +35 -0
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +118 -1
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/components/embed-pdf.vue.d.ts +48 -1
- package/dist/vue/composables/index.d.ts +1 -0
- package/dist/vue/composables/use-document-permissions.d.ts +36 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +116 -3
- package/dist/vue/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PdfPermissionFlag } from '@embedpdf/models';
|
|
2
|
+
export interface DocumentPermissions {
|
|
3
|
+
/** Effective permission flags after applying overrides */
|
|
4
|
+
permissions: number;
|
|
5
|
+
/** Raw PDF permission flags (before overrides) */
|
|
6
|
+
pdfPermissions: number;
|
|
7
|
+
/** Check if a specific permission flag is effectively allowed */
|
|
8
|
+
hasPermission: (flag: PdfPermissionFlag) => boolean;
|
|
9
|
+
/** Check if all specified flags are effectively allowed */
|
|
10
|
+
hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;
|
|
11
|
+
/** Can print (possibly degraded quality) */
|
|
12
|
+
canPrint: boolean;
|
|
13
|
+
/** Can modify document contents */
|
|
14
|
+
canModifyContents: boolean;
|
|
15
|
+
/** Can copy/extract text and graphics */
|
|
16
|
+
canCopyContents: boolean;
|
|
17
|
+
/** Can add/modify annotations and fill forms */
|
|
18
|
+
canModifyAnnotations: boolean;
|
|
19
|
+
/** Can fill in existing form fields */
|
|
20
|
+
canFillForms: boolean;
|
|
21
|
+
/** Can extract for accessibility */
|
|
22
|
+
canExtractForAccessibility: boolean;
|
|
23
|
+
/** Can assemble document (insert, rotate, delete pages) */
|
|
24
|
+
canAssembleDocument: boolean;
|
|
25
|
+
/** Can print high quality */
|
|
26
|
+
canPrintHighQuality: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hook that provides reactive access to a document's effective permission flags.
|
|
30
|
+
* Applies layered resolution: per-document override → global override → PDF permission.
|
|
31
|
+
*
|
|
32
|
+
* @param documentId The ID of the document to check permissions for.
|
|
33
|
+
* @returns An object with effective permissions, raw PDF permissions, helper functions, and shorthand booleans.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useDocumentPermissions(documentId: string): DocumentPermissions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from '../../preact/adapter.ts';
|
|
2
2
|
import { Logger, PdfEngine } from '@embedpdf/models';
|
|
3
|
-
import { PluginRegistry, PluginBatchRegistrations } from '../../lib/index.ts';
|
|
3
|
+
import { PluginRegistry, PluginRegistryConfig, PluginBatchRegistrations } from '../../lib/index.ts';
|
|
4
4
|
import { PDFContextState } from '../context';
|
|
5
5
|
export type { PluginBatchRegistrations };
|
|
6
6
|
interface EmbedPDFProps {
|
|
@@ -9,7 +9,11 @@ interface EmbedPDFProps {
|
|
|
9
9
|
*/
|
|
10
10
|
engine: PdfEngine;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Registry configuration including logger, permissions, and defaults.
|
|
13
|
+
*/
|
|
14
|
+
config?: PluginRegistryConfig;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use config.logger instead. Will be removed in next major version.
|
|
13
17
|
*/
|
|
14
18
|
logger?: Logger;
|
|
15
19
|
/**
|
|
@@ -30,4 +34,4 @@ interface EmbedPDFProps {
|
|
|
30
34
|
*/
|
|
31
35
|
autoMountDomElements?: boolean;
|
|
32
36
|
}
|
|
33
|
-
export declare function EmbedPDF({ engine, logger, onInitialized, plugins, children, autoMountDomElements, }: EmbedPDFProps): import("preact").JSX.Element;
|
|
37
|
+
export declare function EmbedPDF({ engine, config, logger, onInitialized, plugins, children, autoMountDomElements, }: EmbedPDFProps): import("preact").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PdfPermissionFlag } from '@embedpdf/models';
|
|
2
|
+
export interface DocumentPermissions {
|
|
3
|
+
/** Effective permission flags after applying overrides */
|
|
4
|
+
permissions: number;
|
|
5
|
+
/** Raw PDF permission flags (before overrides) */
|
|
6
|
+
pdfPermissions: number;
|
|
7
|
+
/** Check if a specific permission flag is effectively allowed */
|
|
8
|
+
hasPermission: (flag: PdfPermissionFlag) => boolean;
|
|
9
|
+
/** Check if all specified flags are effectively allowed */
|
|
10
|
+
hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;
|
|
11
|
+
/** Can print (possibly degraded quality) */
|
|
12
|
+
canPrint: boolean;
|
|
13
|
+
/** Can modify document contents */
|
|
14
|
+
canModifyContents: boolean;
|
|
15
|
+
/** Can copy/extract text and graphics */
|
|
16
|
+
canCopyContents: boolean;
|
|
17
|
+
/** Can add/modify annotations and fill forms */
|
|
18
|
+
canModifyAnnotations: boolean;
|
|
19
|
+
/** Can fill in existing form fields */
|
|
20
|
+
canFillForms: boolean;
|
|
21
|
+
/** Can extract for accessibility */
|
|
22
|
+
canExtractForAccessibility: boolean;
|
|
23
|
+
/** Can assemble document (insert, rotate, delete pages) */
|
|
24
|
+
canAssembleDocument: boolean;
|
|
25
|
+
/** Can print high quality */
|
|
26
|
+
canPrintHighQuality: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hook that provides reactive access to a document's effective permission flags.
|
|
30
|
+
* Applies layered resolution: per-document override → global override → PDF permission.
|
|
31
|
+
*
|
|
32
|
+
* @param documentId The ID of the document to check permissions for.
|
|
33
|
+
* @returns An object with effective permissions, raw PDF permissions, helper functions, and shorthand booleans.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useDocumentPermissions(documentId: string): DocumentPermissions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from '../../react/adapter.ts';
|
|
2
2
|
import { Logger, PdfEngine } from '@embedpdf/models';
|
|
3
|
-
import { PluginRegistry, PluginBatchRegistrations } from '../../lib/index.ts';
|
|
3
|
+
import { PluginRegistry, PluginRegistryConfig, PluginBatchRegistrations } from '../../lib/index.ts';
|
|
4
4
|
import { PDFContextState } from '../context';
|
|
5
5
|
export type { PluginBatchRegistrations };
|
|
6
6
|
interface EmbedPDFProps {
|
|
@@ -9,7 +9,11 @@ interface EmbedPDFProps {
|
|
|
9
9
|
*/
|
|
10
10
|
engine: PdfEngine;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Registry configuration including logger, permissions, and defaults.
|
|
13
|
+
*/
|
|
14
|
+
config?: PluginRegistryConfig;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use config.logger instead. Will be removed in next major version.
|
|
13
17
|
*/
|
|
14
18
|
logger?: Logger;
|
|
15
19
|
/**
|
|
@@ -30,4 +34,4 @@ interface EmbedPDFProps {
|
|
|
30
34
|
*/
|
|
31
35
|
autoMountDomElements?: boolean;
|
|
32
36
|
}
|
|
33
|
-
export declare function EmbedPDF({ engine, logger, onInitialized, plugins, children, autoMountDomElements, }: EmbedPDFProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
export declare function EmbedPDF({ engine, config, logger, onInitialized, plugins, children, autoMountDomElements, }: EmbedPDFProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PdfPermissionFlag } from '@embedpdf/models';
|
|
2
|
+
export interface DocumentPermissions {
|
|
3
|
+
/** Effective permission flags after applying overrides */
|
|
4
|
+
permissions: number;
|
|
5
|
+
/** Raw PDF permission flags (before overrides) */
|
|
6
|
+
pdfPermissions: number;
|
|
7
|
+
/** Check if a specific permission flag is effectively allowed */
|
|
8
|
+
hasPermission: (flag: PdfPermissionFlag) => boolean;
|
|
9
|
+
/** Check if all specified flags are effectively allowed */
|
|
10
|
+
hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;
|
|
11
|
+
/** Can print (possibly degraded quality) */
|
|
12
|
+
canPrint: boolean;
|
|
13
|
+
/** Can modify document contents */
|
|
14
|
+
canModifyContents: boolean;
|
|
15
|
+
/** Can copy/extract text and graphics */
|
|
16
|
+
canCopyContents: boolean;
|
|
17
|
+
/** Can add/modify annotations and fill forms */
|
|
18
|
+
canModifyAnnotations: boolean;
|
|
19
|
+
/** Can fill in existing form fields */
|
|
20
|
+
canFillForms: boolean;
|
|
21
|
+
/** Can extract for accessibility */
|
|
22
|
+
canExtractForAccessibility: boolean;
|
|
23
|
+
/** Can assemble document (insert, rotate, delete pages) */
|
|
24
|
+
canAssembleDocument: boolean;
|
|
25
|
+
/** Can print high quality */
|
|
26
|
+
canPrintHighQuality: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hook that provides reactive access to a document's effective permission flags.
|
|
30
|
+
* Applies layered resolution: per-document override → global override → PDF permission.
|
|
31
|
+
*
|
|
32
|
+
* @param documentId The ID of the document to check permissions for.
|
|
33
|
+
* @returns An object with effective permissions, raw PDF permissions, helper functions, and shorthand booleans.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useDocumentPermissions(documentId: string): DocumentPermissions;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger, PdfEngine } from '@embedpdf/models';
|
|
2
|
-
import { PluginBatchRegistrations, PluginRegistry } from '../../lib/index.ts';
|
|
2
|
+
import { PluginBatchRegistrations, PluginRegistryConfig, PluginRegistry } from '../../lib/index.ts';
|
|
3
3
|
import { Snippet } from 'svelte';
|
|
4
4
|
import { PDFContextState } from '../hooks';
|
|
5
5
|
interface EmbedPDFProps {
|
|
@@ -8,7 +8,11 @@ interface EmbedPDFProps {
|
|
|
8
8
|
*/
|
|
9
9
|
engine: PdfEngine;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Registry configuration including logger, permissions, and defaults.
|
|
12
|
+
*/
|
|
13
|
+
config?: PluginRegistryConfig;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use config.logger instead. Will be removed in next major version.
|
|
12
16
|
*/
|
|
13
17
|
logger?: Logger;
|
|
14
18
|
/**
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PdfPermissionFlag } from '@embedpdf/models';
|
|
2
|
+
export interface DocumentPermissions {
|
|
3
|
+
/** Effective permission flags after applying overrides */
|
|
4
|
+
permissions: number;
|
|
5
|
+
/** Raw PDF permission flags (before overrides) */
|
|
6
|
+
pdfPermissions: number;
|
|
7
|
+
/** Check if a specific permission flag is effectively allowed */
|
|
8
|
+
hasPermission: (flag: PdfPermissionFlag) => boolean;
|
|
9
|
+
/** Check if all specified flags are effectively allowed */
|
|
10
|
+
hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;
|
|
11
|
+
/** Can print (possibly degraded quality) */
|
|
12
|
+
canPrint: boolean;
|
|
13
|
+
/** Can modify document contents */
|
|
14
|
+
canModifyContents: boolean;
|
|
15
|
+
/** Can copy/extract text and graphics */
|
|
16
|
+
canCopyContents: boolean;
|
|
17
|
+
/** Can add/modify annotations and fill forms */
|
|
18
|
+
canModifyAnnotations: boolean;
|
|
19
|
+
/** Can fill in existing form fields */
|
|
20
|
+
canFillForms: boolean;
|
|
21
|
+
/** Can extract for accessibility */
|
|
22
|
+
canExtractForAccessibility: boolean;
|
|
23
|
+
/** Can assemble document (insert, rotate, delete pages) */
|
|
24
|
+
canAssembleDocument: boolean;
|
|
25
|
+
/** Can print high quality */
|
|
26
|
+
canPrintHighQuality: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hook that provides reactive access to a document's effective permission flags.
|
|
30
|
+
* Applies layered resolution: per-document override → global override → PDF permission.
|
|
31
|
+
*
|
|
32
|
+
* @param getDocumentId Function that returns the document ID
|
|
33
|
+
* @returns An object with reactive permission properties.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useDocumentPermissions(getDocumentId: () => string): DocumentPermissions;
|
package/dist/svelte/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client");require("svelte/internal/disclose-version");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/models");require("svelte/internal/disclose-version");const n=require("@embedpdf/core");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}const r=i(e),o=r.proxy({registry:null,coreState:null,isInitializing:!0,pluginsReady:!1,activeDocumentId:null,activeDocument:null,documents:{},documentStates:[]}),s=()=>o;function l(e){const{registry:t}=o,n=r.proxy({plugin:null,isLoading:!0,ready:new Promise(()=>{})});if(null===t)return n;const i=t.getPlugin(e);if(!i)throw new Error(`Plugin ${e} not found`);return n.plugin=i,n.isLoading=!1,n.ready=i.ready(),n}function d(){const e=s();return{get current(){return e.coreState}}}t.PdfPermissionFlag.Print,t.PdfPermissionFlag.ModifyContents,t.PdfPermissionFlag.CopyContents,t.PdfPermissionFlag.ModifyAnnotations,t.PdfPermissionFlag.FillForms,t.PdfPermissionFlag.ExtractForAccessibility,t.PdfPermissionFlag.AssembleDocument,t.PdfPermissionFlag.PrintHighQuality;const c=[t.PdfPermissionFlag.Print,t.PdfPermissionFlag.ModifyContents,t.PdfPermissionFlag.CopyContents,t.PdfPermissionFlag.ModifyAnnotations,t.PdfPermissionFlag.FillForms,t.PdfPermissionFlag.ExtractForAccessibility,t.PdfPermissionFlag.AssembleDocument,t.PdfPermissionFlag.PrintHighQuality],u={[t.PdfPermissionFlag.Print]:"print",[t.PdfPermissionFlag.ModifyContents]:"modifyContents",[t.PdfPermissionFlag.CopyContents]:"copyContents",[t.PdfPermissionFlag.ModifyAnnotations]:"modifyAnnotations",[t.PdfPermissionFlag.FillForms]:"fillForms",[t.PdfPermissionFlag.ExtractForAccessibility]:"extractForAccessibility",[t.PdfPermissionFlag.AssembleDocument]:"assembleDocument",[t.PdfPermissionFlag.PrintHighQuality]:"printHighQuality"};function a(e,t){if(!e)return;if(t in e)return e[t];const n=u[t];return n&&n in e?e[n]:void 0}function g(e,n,i){var r;const o=e.documents[n],s=null==o?void 0:o.permissions,l=e.globalPermissions,d=(null==(r=null==o?void 0:o.document)?void 0:r.permissions)??t.PdfPermissionFlag.AllowAll,c=a(null==s?void 0:s.overrides,i);if(void 0!==c)return c;const u=a(null==l?void 0:l.overrides,i);if(void 0!==u)return u;return!((null==s?void 0:s.enforceDocumentPermissions)??(null==l?void 0:l.enforceDocumentPermissions)??!0)||0!==(d&i)}function m(e,t){r.push(t,!0);var n=r.comment(),i=r.first_child(n),o=e=>{const n=r.derived(()=>t.wrappers[0]);var i=r.comment(),o=r.first_child(i);r.component(o,()=>r.get(n),(e,n)=>{n(e,{children:(e,n)=>{{let n=r.derived(()=>t.wrappers.slice(1));m(e,{get wrappers(){return r.get(n)},children:(e,n)=>{var i=r.comment(),o=r.first_child(i);r.snippet(o,()=>t.children??r.noop),r.append(e,i)},$$slots:{default:!0}})}},$$slots:{default:!0}})}),r.append(e,i)},s=e=>{const n=r.derived(()=>t.wrappers[0]);var i=r.comment(),o=r.first_child(i);r.component(o,()=>r.get(n),(e,n)=>{n(e,{children:(e,n)=>{var i=r.comment(),o=r.first_child(i);r.snippet(o,()=>t.children??r.noop),r.append(e,i)},$$slots:{default:!0}})}),r.append(e,i)};r.if(i,e=>{t.wrappers.length>1?e(o):e(s,!1)}),r.append(e,n),r.pop()}var p=r.from_html("<!> <!>",1);function f(e,t){r.push(t,!0);let i=r.state(r.proxy([])),o=r.state(r.proxy([]));r.user_effect(()=>{var e;const s=[],l=[];for(const i of t.plugins){const t=i.package;if(n.hasAutoMountElements(t)){const n=(null==(e=t.autoMountElements)?void 0:e.call(t))??[];for(const e of n)"utility"===e.type?s.push(e.component):"wrapper"===e.type&&l.push(e.component)}}r.set(i,s,!0),r.set(o,l,!0)});var s=p(),l=r.first_child(s),d=e=>{m(e,{get wrappers(){return r.get(o)},get children(){return t.children}})},c=e=>{var n=r.comment(),i=r.first_child(n);r.snippet(i,()=>t.children??r.noop),r.append(e,n)};r.if(l,e=>{r.get(o).length>0?e(d):e(c,!1)});var u=r.sibling(l,2);r.each(u,19,()=>r.get(i),(e,t)=>`utility-${t}`,(e,t)=>{var n=r.comment(),i=r.first_child(n);r.component(i,()=>r.get(t),(e,t)=>{t(e,{})}),r.append(e,n)}),r.append(e,s),r.pop()}exports.EmbedPDF=function(e,t){r.push(t,!0);let i=r.prop(t,"autoMountDomElements",3,!0),s=t.onInitialized;r.user_effect(()=>{t.onInitialized&&(s=t.onInitialized)}),r.user_effect(()=>{var e;if(t.engine||t.engine&&t.plugins){const i={...t.config,logger:(null==(e=t.config)?void 0:e.logger)??t.logger},r=new n.PluginRegistry(t.engine,i);r.registerPluginBatch(t.plugins);let l;return(async()=>{if(await r.initialize(),r.isDestroyed())return;const e=r.getStore();o.coreState=e.getState().core;const t=e.subscribe((t,n,i)=>{if(e.isCoreAction(t)&&n.core!==i.core){o.coreState=n.core;const e=n.core.activeDocumentId??null,t=n.core.documents??{},i=n.core.documentOrder??[];o.activeDocumentId=e,o.activeDocument=e&&t[e]?t[e]:null,o.documents=t,o.documentStates=i.map(e=>t[e]).filter(e=>null!=e)}});if(await(null==s?void 0:s(r)),!r.isDestroyed())return r.pluginsReady().then(()=>{r.isDestroyed()||(o.pluginsReady=!0)}),o.registry=r,o.isInitializing=!1,t;t()})().then(e=>{l=e}).catch(console.error),()=>{null==l||l(),r.destroy(),o.registry=null,o.coreState=null,o.isInitializing=!0,o.pluginsReady=!1,o.activeDocumentId=null,o.activeDocument=null,o.documents={},o.documentStates=[]}}});var l=r.comment(),d=r.first_child(l),c=e=>{f(e,{get plugins(){return t.plugins},children:(e,n)=>{var i=r.comment(),s=r.first_child(i);r.snippet(s,()=>t.children,()=>o),r.append(e,i)},$$slots:{default:!0}})},u=e=>{var n=r.comment(),i=r.first_child(n);r.snippet(i,()=>t.children,()=>o),r.append(e,n)};r.if(d,e=>{o.pluginsReady&&i()?e(c):e(u,!1)}),r.append(e,l),r.pop()},exports.pdfContext=o,exports.useCapability=function(e){const t=l(e),n=r.proxy({provides:null,isLoading:!0,ready:new Promise(()=>{})});return r.user_effect(()=>{if(!t.plugin)return n.provides=null,n.isLoading=t.isLoading,void(n.ready=t.ready);if(!t.plugin.provides)throw new Error(`Plugin ${e} does not provide a capability`);n.provides=t.plugin.provides(),n.isLoading=t.isLoading,n.ready=t.ready}),n},exports.useCoreState=d,exports.useDocumentPermissions=function(e){const n=d(),i=r.derived(e),o=r.derived(()=>n.current),s=r.derived(()=>r.get(o)?function(e,t){return c.reduce((n,i)=>g(e,t,i)?n|i:n,0)}(r.get(o),r.get(i)):t.PdfPermissionFlag.AllowAll),l=r.derived(()=>{var e,n,s;return(null==(s=null==(n=null==(e=r.get(o))?void 0:e.documents[r.get(i)])?void 0:n.document)?void 0:s.permissions)??t.PdfPermissionFlag.AllowAll});return{get permissions(){return r.get(s)},get pdfPermissions(){return r.get(l)},hasPermission:e=>!r.get(o)||g(r.get(o),r.get(i),e),hasAllPermissions:(...e)=>e.every(e=>!r.get(o)||g(r.get(o),r.get(i),e)),get canPrint(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.Print)},get canModifyContents(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.ModifyContents)},get canCopyContents(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.CopyContents)},get canModifyAnnotations(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.ModifyAnnotations)},get canFillForms(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.FillForms)},get canExtractForAccessibility(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.ExtractForAccessibility)},get canAssembleDocument(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.AssembleDocument)},get canPrintHighQuality(){return!r.get(o)||g(r.get(o),r.get(i),t.PdfPermissionFlag.PrintHighQuality)}}},exports.useDocumentState=function(e){const t=d(),n=r.derived(e),i=r.derived(()=>t.current&&r.get(n)?t.current.documents[r.get(n)]??null:null);return{get current(){return r.get(i)}}},exports.usePlugin=l,exports.useRegistry=s;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.svelte.ts","../../src/svelte/hooks/use-core-state.svelte.ts","../../src/svelte/components/NestedWrapper.svelte","../../src/svelte/components/AutoMount.svelte","../../src/svelte/components/EmbedPDF.svelte","../../src/svelte/hooks/use-capability.svelte.ts","../../src/svelte/hooks/use-document-state.svelte.ts"],"sourcesContent":["import type { PluginRegistry, CoreState, DocumentState } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n coreState: CoreState | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: string | null;\n activeDocument: DocumentState | null;\n documents: Record<string, DocumentState>;\n documentStates: DocumentState[];\n}\n\nexport const pdfContext = $state<PDFContextState>({\n registry: null,\n coreState: null,\n isInitializing: true,\n pluginsReady: false,\n activeDocumentId: null,\n activeDocument: null,\n documents: {},\n documentStates: [],\n});\n\n/**\n * Hook to access the PDF registry context.\n * @returns The PDF registry or null during initialization\n */\n\nexport const useRegistry = () => pdfContext;\n","import type { BasePlugin } from '@embedpdf/core';\nimport { pdfContext } from './use-registry.svelte.js';\n\n/**\n * Hook to access a plugin.\n * @param pluginId The ID of the plugin to access\n * @returns The plugin or null during initialization\n * @example\n * // Get zoom plugin\n * const zoom = usePlugin<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']) {\n const { registry } = pdfContext;\n\n const state = $state({\n plugin: null as T | null,\n isLoading: true,\n ready: new Promise<void>(() => {}),\n });\n\n if (registry === null) {\n return state;\n }\n\n const plugin = registry.getPlugin<T>(pluginId);\n\n if (!plugin) {\n throw new Error(`Plugin ${pluginId} not found`);\n }\n\n state.plugin = plugin;\n state.isLoading = false;\n state.ready = plugin.ready();\n\n return state;\n}\n","import { useRegistry } from './use-registry.svelte';\n\n/**\n * Hook that provides access to the current core state.\n *\n * Note: This reads from the context which is already subscribed to core state changes\n * in the EmbedPDF component, so there's no additional subscription overhead.\n */\nexport function useCoreState() {\n const context = useRegistry();\n\n return {\n get current() {\n return context.coreState;\n },\n };\n}\n","<script lang=\"ts\">\n import { type Component, type Snippet } from 'svelte';\n import NestedWrapper from './NestedWrapper.svelte';\n\n interface Props {\n wrappers: Component[];\n children?: Snippet;\n }\n\n let { wrappers, children }: Props = $props();\n</script>\n\n{#if wrappers.length > 1}\n {@const Wrapper = wrappers[0]}\n <Wrapper>\n <NestedWrapper wrappers={wrappers.slice(1)}>\n {@render children?.()}\n </NestedWrapper>\n </Wrapper>\n{:else}\n {@const Wrapper = wrappers[0]}\n <Wrapper>\n {@render children?.()}\n </Wrapper>\n{/if}\n","<script lang=\"ts\">\n import { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\n import NestedWrapper from './NestedWrapper.svelte';\n import type { Snippet } from 'svelte';\n\n type Props = {\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: Snippet;\n };\n\n let { plugins, children }: Props = $props();\n let utilities: any[] = $state([]);\n let wrappers: any[] = $state([]);\n\n // recompute when plugins change\n $effect(() => {\n const nextUtilities: any[] = [];\n const nextWrappers: any[] = [];\n\n for (const reg of plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements?.() ?? [];\n for (const element of elements) {\n if (element.type === 'utility') {\n nextUtilities.push(element.component);\n } else if (element.type === 'wrapper') {\n nextWrappers.push(element.component);\n }\n }\n }\n }\n\n utilities = nextUtilities;\n wrappers = nextWrappers;\n });\n</script>\n\n{#if wrappers.length > 0}\n <!-- wrap slot content inside all wrappers -->\n <NestedWrapper {wrappers} {children} />\n{:else}\n {@render children?.()}\n{/if}\n\n<!-- mount all utilities -->\n{#each utilities as Utility, i (`utility-${i}`)}\n <Utility />\n{/each}\n","<script lang=\"ts\">\n import type { Logger, PdfEngine } from '@embedpdf/models';\n import { type IPlugin, type PluginBatchRegistrations, PluginRegistry } from '@embedpdf/core';\n import { type Snippet } from 'svelte';\n import AutoMount from './AutoMount.svelte';\n import { pdfContext, type PDFContextState } from '../hooks';\n\n export type { PluginBatchRegistrations };\n\n interface EmbedPDFProps {\n /**\n * The PDF engine to use for the PDF viewer.\n */\n engine: PdfEngine;\n /**\n * The logger to use for the PDF viewer.\n */\n logger?: Logger;\n /**\n * The callback to call when the PDF viewer is initialized.\n */\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n /**\n * The plugins to use for the PDF viewer.\n */\n plugins: PluginBatchRegistrations;\n /**\n * The children to render for the PDF viewer.\n */\n children: Snippet<[PDFContextState]>;\n /**\n * Whether to auto-mount specific non-visual DOM elements from plugins.\n * @default true\n */\n autoMountDomElements?: boolean;\n }\n\n let {\n engine,\n logger,\n onInitialized,\n plugins,\n children,\n autoMountDomElements = true,\n }: EmbedPDFProps = $props();\n\n let latestInit = onInitialized;\n\n $effect(() => {\n if (onInitialized) {\n latestInit = onInitialized;\n }\n });\n\n $effect(() => {\n if (engine || (engine && plugins)) {\n const reg = new PluginRegistry(engine, { logger });\n reg.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await reg.initialize();\n\n // if the registry is destroyed, don't do anything\n if (reg.isDestroyed()) {\n return;\n }\n\n const store = reg.getStore();\n pdfContext.coreState = store.getState().core;\n\n const unsubscribe = store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && newState.core !== oldState.core) {\n pdfContext.coreState = newState.core;\n\n // Update convenience accessors\n const activeDocumentId = newState.core.activeDocumentId ?? null;\n const documents = newState.core.documents ?? {};\n const documentOrder = newState.core.documentOrder ?? [];\n\n pdfContext.activeDocumentId = activeDocumentId;\n pdfContext.activeDocument =\n activeDocumentId && documents[activeDocumentId] ? documents[activeDocumentId] : null;\n pdfContext.documents = documents;\n pdfContext.documentStates = documentOrder\n .map((docId) => documents[docId])\n .filter(\n (doc): doc is import('@embedpdf/core').DocumentState =>\n doc !== null && doc !== undefined,\n );\n }\n });\n\n /* always call the *latest* callback */\n await latestInit?.(reg);\n\n // if the registry is destroyed, don't do anything\n if (reg.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n reg.pluginsReady().then(() => {\n if (!reg.isDestroyed()) {\n pdfContext.pluginsReady = true;\n }\n });\n\n // Provide the registry to children via context\n pdfContext.registry = reg;\n pdfContext.isInitializing = false;\n\n return unsubscribe;\n };\n\n let cleanup: (() => void) | undefined;\n initialize()\n .then((unsub) => {\n cleanup = unsub;\n })\n .catch(console.error);\n\n return () => {\n cleanup?.();\n reg.destroy();\n pdfContext.registry = null;\n pdfContext.coreState = null;\n pdfContext.isInitializing = true;\n pdfContext.pluginsReady = false;\n pdfContext.activeDocumentId = null;\n pdfContext.activeDocument = null;\n pdfContext.documents = {};\n pdfContext.documentStates = [];\n };\n }\n });\n</script>\n\n{#if pdfContext.pluginsReady && autoMountDomElements}\n <AutoMount {plugins}>{@render children(pdfContext)}</AutoMount>\n{:else}\n {@render children(pdfContext)}\n{/if}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { usePlugin } from './use-plugin.svelte.js';\n\n/**\n * Hook to access a plugin's capability.\n * @param pluginId The ID of the plugin to access\n * @returns The capability provided by the plugin or null during initialization\n * @example\n * // Get zoom capability\n * const zoom = useCapability<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function useCapability<T extends BasePlugin>(pluginId: T['id']) {\n const p = usePlugin<T>(pluginId);\n\n const state = $state({\n provides: null as ReturnType<NonNullable<T['provides']>> | null,\n isLoading: true,\n ready: new Promise<void>(() => {}),\n });\n\n // Use $effect to reactively update when plugin loads\n $effect(() => {\n if (!p.plugin) {\n state.provides = null;\n state.isLoading = p.isLoading;\n state.ready = p.ready;\n return;\n }\n\n if (!p.plugin.provides) {\n throw new Error(`Plugin ${pluginId} does not provide a capability`);\n }\n\n state.provides = p.plugin.provides() as ReturnType<NonNullable<T['provides']>>;\n state.isLoading = p.isLoading;\n state.ready = p.ready;\n });\n\n return state;\n}\n","import { useCoreState } from './use-core-state.svelte';\n\n/**\n * Hook that provides reactive access to a specific document's state from the core store.\n *\n * @param getDocumentId Function that returns the document ID\n * @returns The reactive DocumentState object or null if not found.\n */\nexport function useDocumentState(getDocumentId: () => string | null) {\n const coreStateRef = useCoreState();\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n const documentState = $derived(\n coreStateRef.current && documentId\n ? (coreStateRef.current.documents[documentId] ?? null)\n : null,\n );\n\n return {\n get current() {\n return documentState;\n },\n };\n}\n"],"names":["pdfContext","registry","coreState","isInitializing","pluginsReady","activeDocumentId","activeDocument","documents","documentStates","useRegistry","usePlugin","pluginId","state","plugin","isLoading","ready","Promise","getPlugin","Error","useCoreState","context","current","Wrapper","Wrapper_1","$$anchor","$0","$","derived","$$props","wrappers","slice","NestedWrapper","Wrapper_2","length","consequent","$$render","alternate","utilities","proxy","user_effect","nextUtilities","nextWrappers","reg","plugins","pkg","package","hasAutoMountElements","elements","_a","autoMountElements","call","element","type","push","component","set","each","node_2","get","Utility","i","Utility_1","autoMountDomElements","latestInit","onInitialized","engine","PluginRegistry","logger","registerPluginBatch","cleanup","async","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","documentOrder","map","docId","filter","doc","then","unsub","catch","console","error","destroy","AutoMount","p","provides","getDocumentId","coreStateRef","documentId","documentState"],"mappings":"geAeaA,WACXC,SAAU,KACVC,UAAW,KACXC,gBAAgB,EAChBC,cAAc,EACdC,iBAAkB,KAClBC,eAAgB,KAChBC,aACAC,oBAQWC,MAAoBT,WCpBjBU,EAAgCC,GACtC,MAAAV,SAAAA,GAAaD,EAEfY,WACJC,OAAQ,KACRC,WAAW,EACXC,MAAA,IAAWC,QAAA,aAGI,OAAbf,SACKW,EAGH,MAAAC,EAASZ,EAASgB,UAAaN,GAEhC,IAAAE,EACO,MAAA,IAAAK,gBAAgBP,sBAG5BC,EAAMC,OAASA,EACfD,EAAME,WAAY,EAClBF,EAAMG,MAAQF,EAAOE,QAE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AHfA,EAAWI,cAAgB0D,MAAoB5B,GAAAC,EAAAC,GAAA,0BAFpD,sDC7HoDzB,SAC5CoF,EAAIrF,EAAaC,GAEjBC,WACJoF,SAAU,KACVlF,WAAW,EACXC,MAAA,IAAWC,QAAA,iBAIbU,EAAAa,qBACOwD,EAAElF,cACLD,EAAMoF,SAAW,KACjBpF,EAAME,UAAYiF,EAAEjF,eACpBF,EAAMG,MAAQgF,EAAEhF,OAIb,IAAAgF,EAAElF,OAAOmF,SACF,MAAA,IAAA9E,gBAAgBP,mCAG5BC,EAAMoF,SAAWD,EAAElF,OAAOmF,WAC1BpF,EAAME,UAAYiF,EAAEjF,UACpBF,EAAMG,MAAQgF,EAAEhF,QAGXH,CACT,2DC/BiCqF,GACzB,MAAAC,EAAe/E,IAGfgF,YAAsBF,GAEtBG,EAAA1E,EAAAC,QAAA,IACJuE,EAAa7E,eAAW8E,GACnBD,EAAa7E,QAAQd,UAAAmB,EAAAgC,IAAUyC,KAAe,KAC/C,aAIA,WAAA9E,gBACK+E,EACT,EAEJ"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.svelte.ts","../../src/svelte/hooks/use-core-state.svelte.ts","../../src/lib/types/permissions.ts","../../src/lib/store/selectors.ts","../../src/svelte/components/NestedWrapper.svelte","../../src/svelte/components/AutoMount.svelte","../../src/svelte/components/EmbedPDF.svelte","../../src/svelte/hooks/use-capability.svelte.ts","../../src/svelte/hooks/use-document-permissions.svelte.ts","../../src/svelte/hooks/use-document-state.svelte.ts"],"sourcesContent":["import type { PluginRegistry, CoreState, DocumentState } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n coreState: CoreState | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n\n // Convenience accessors (always safe to use)\n activeDocumentId: string | null;\n activeDocument: DocumentState | null;\n documents: Record<string, DocumentState>;\n documentStates: DocumentState[];\n}\n\nexport const pdfContext = $state<PDFContextState>({\n registry: null,\n coreState: null,\n isInitializing: true,\n pluginsReady: false,\n activeDocumentId: null,\n activeDocument: null,\n documents: {},\n documentStates: [],\n});\n\n/**\n * Hook to access the PDF registry context.\n * @returns The PDF registry or null during initialization\n */\n\nexport const useRegistry = () => pdfContext;\n","import type { BasePlugin } from '@embedpdf/core';\nimport { pdfContext } from './use-registry.svelte.js';\n\n/**\n * Hook to access a plugin.\n * @param pluginId The ID of the plugin to access\n * @returns The plugin or null during initialization\n * @example\n * // Get zoom plugin\n * const zoom = usePlugin<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']) {\n const { registry } = pdfContext;\n\n const state = $state({\n plugin: null as T | null,\n isLoading: true,\n ready: new Promise<void>(() => {}),\n });\n\n if (registry === null) {\n return state;\n }\n\n const plugin = registry.getPlugin<T>(pluginId);\n\n if (!plugin) {\n throw new Error(`Plugin ${pluginId} not found`);\n }\n\n state.plugin = plugin;\n state.isLoading = false;\n state.ready = plugin.ready();\n\n return state;\n}\n","import { useRegistry } from './use-registry.svelte';\n\n/**\n * Hook that provides access to the current core state.\n *\n * Note: This reads from the context which is already subscribed to core state changes\n * in the EmbedPDF component, so there's no additional subscription overhead.\n */\nexport function useCoreState() {\n const context = useRegistry();\n\n return {\n get current() {\n return context.coreState;\n },\n };\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\n\n/**\n * Human-readable permission names for use in configuration.\n */\nexport type PermissionName =\n | 'print'\n | 'modifyContents'\n | 'copyContents'\n | 'modifyAnnotations'\n | 'fillForms'\n | 'extractForAccessibility'\n | 'assembleDocument'\n | 'printHighQuality';\n\n/**\n * Map from human-readable names to PdfPermissionFlag values.\n */\nexport const PERMISSION_NAME_TO_FLAG: Record<PermissionName, PdfPermissionFlag> = {\n print: PdfPermissionFlag.Print,\n modifyContents: PdfPermissionFlag.ModifyContents,\n copyContents: PdfPermissionFlag.CopyContents,\n modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,\n fillForms: PdfPermissionFlag.FillForms,\n extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,\n assembleDocument: PdfPermissionFlag.AssembleDocument,\n printHighQuality: PdfPermissionFlag.PrintHighQuality,\n};\n\n/**\n * Permission overrides can use either numeric flags or human-readable string names.\n */\nexport type PermissionOverrides = Partial<\n Record<PdfPermissionFlag, boolean> & Record<PermissionName, boolean>\n>;\n\n/**\n * Configuration for overriding document permissions.\n * Can be applied globally (at PluginRegistry level) or per-document (when opening).\n */\nexport interface PermissionConfig {\n /**\n * When true (default): use PDF's permissions as the base, then apply overrides.\n * When false: treat document as having all permissions allowed, then apply overrides.\n */\n enforceDocumentPermissions?: boolean;\n\n /**\n * Explicit per-flag overrides. Supports both numeric flags and string names.\n * - true = force allow (even if PDF denies)\n * - false = force deny (even if PDF allows)\n * - undefined = use base permissions\n *\n * @example\n * // Using string names (recommended)\n * overrides: { print: false, modifyAnnotations: true }\n *\n * @example\n * // Using numeric flags\n * overrides: { [PdfPermissionFlag.Print]: false }\n */\n overrides?: PermissionOverrides;\n}\n\n/**\n * All permission flags for iteration when computing effective permissions.\n */\nexport const ALL_PERMISSION_FLAGS: PdfPermissionFlag[] = [\n PdfPermissionFlag.Print,\n PdfPermissionFlag.ModifyContents,\n PdfPermissionFlag.CopyContents,\n PdfPermissionFlag.ModifyAnnotations,\n PdfPermissionFlag.FillForms,\n PdfPermissionFlag.ExtractForAccessibility,\n PdfPermissionFlag.AssembleDocument,\n PdfPermissionFlag.PrintHighQuality,\n];\n\n/**\n * All permission names for iteration.\n */\nexport const ALL_PERMISSION_NAMES: PermissionName[] = [\n 'print',\n 'modifyContents',\n 'copyContents',\n 'modifyAnnotations',\n 'fillForms',\n 'extractForAccessibility',\n 'assembleDocument',\n 'printHighQuality',\n];\n\n/**\n * Map from PdfPermissionFlag to human-readable name.\n */\nexport const PERMISSION_FLAG_TO_NAME: Record<PdfPermissionFlag, PermissionName> = {\n [PdfPermissionFlag.Print]: 'print',\n [PdfPermissionFlag.ModifyContents]: 'modifyContents',\n [PdfPermissionFlag.CopyContents]: 'copyContents',\n [PdfPermissionFlag.ModifyAnnotations]: 'modifyAnnotations',\n [PdfPermissionFlag.FillForms]: 'fillForms',\n [PdfPermissionFlag.ExtractForAccessibility]: 'extractForAccessibility',\n [PdfPermissionFlag.AssembleDocument]: 'assembleDocument',\n [PdfPermissionFlag.PrintHighQuality]: 'printHighQuality',\n};\n\n/**\n * Helper to get the override value for a permission flag, checking both numeric and string keys.\n */\nexport function getPermissionOverride(\n overrides: PermissionOverrides | undefined,\n flag: PdfPermissionFlag,\n): boolean | undefined {\n if (!overrides) return undefined;\n\n // Check numeric key first\n if (flag in overrides) {\n return (overrides as Record<PdfPermissionFlag, boolean>)[flag];\n }\n\n // Check string key\n const name = PERMISSION_FLAG_TO_NAME[flag];\n if (name && name in overrides) {\n return (overrides as Record<PermissionName, boolean>)[name];\n }\n\n return undefined;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\nimport { CoreState, DocumentState } from './initial-state';\nimport { ALL_PERMISSION_FLAGS, getPermissionOverride } from '../types/permissions';\n\n/**\n * Get the active document state\n */\nexport const getActiveDocumentState = (state: CoreState): DocumentState | null => {\n if (!state.activeDocumentId) return null;\n return state.documents[state.activeDocumentId] ?? null;\n};\n\n/**\n * Get document state by ID\n */\nexport const getDocumentState = (state: CoreState, documentId: string): DocumentState | null => {\n return state.documents[documentId] ?? null;\n};\n\n/**\n * Get all document IDs\n */\nexport const getDocumentIds = (state: CoreState): string[] => {\n return Object.keys(state.documents);\n};\n\n/**\n * Check if a document is loaded\n */\nexport const isDocumentLoaded = (state: CoreState, documentId: string): boolean => {\n return !!state.documents[documentId];\n};\n\n/**\n * Get the number of open documents\n */\nexport const getDocumentCount = (state: CoreState): number => {\n return Object.keys(state.documents).length;\n};\n\n// ─────────────────────────────────────────────────────────\n// Permission Selectors\n// ─────────────────────────────────────────────────────────\n\n/**\n * Check if a specific permission flag is effectively allowed for a document.\n * Applies layered resolution: per-document override → global override → enforceDocumentPermissions → PDF permission.\n *\n * @param state - The core state\n * @param documentId - The document ID to check permissions for\n * @param flag - The permission flag to check\n * @returns true if the permission is allowed, false otherwise\n */\nexport function getEffectivePermission(\n state: CoreState,\n documentId: string,\n flag: PdfPermissionFlag,\n): boolean {\n const docState = state.documents[documentId];\n const docConfig = docState?.permissions;\n const globalConfig = state.globalPermissions;\n const pdfPermissions = docState?.document?.permissions ?? PdfPermissionFlag.AllowAll;\n\n // 1. Per-document override wins (supports both numeric and string keys)\n const docOverride = getPermissionOverride(docConfig?.overrides, flag);\n if (docOverride !== undefined) {\n return docOverride;\n }\n\n // 2. Global override (supports both numeric and string keys)\n const globalOverride = getPermissionOverride(globalConfig?.overrides, flag);\n if (globalOverride !== undefined) {\n return globalOverride;\n }\n\n // 3. Check enforce setting (per-doc takes precedence over global)\n const enforce =\n docConfig?.enforceDocumentPermissions ?? globalConfig?.enforceDocumentPermissions ?? true;\n\n if (!enforce) return true; // Not enforcing = allow all\n\n // 4. Use PDF permission\n return (pdfPermissions & flag) !== 0;\n}\n\n/**\n * Get all effective permissions as a bitmask for a document.\n * Combines all individual permission checks into a single bitmask.\n *\n * @param state - The core state\n * @param documentId - The document ID to get permissions for\n * @returns A bitmask of all effective permissions\n */\nexport function getEffectivePermissions(state: CoreState, documentId: string): number {\n return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {\n return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;\n }, 0);\n}\n","<script lang=\"ts\">\n import { type Component, type Snippet } from 'svelte';\n import NestedWrapper from './NestedWrapper.svelte';\n\n interface Props {\n wrappers: Component[];\n children?: Snippet;\n }\n\n let { wrappers, children }: Props = $props();\n</script>\n\n{#if wrappers.length > 1}\n {@const Wrapper = wrappers[0]}\n <Wrapper>\n <NestedWrapper wrappers={wrappers.slice(1)}>\n {@render children?.()}\n </NestedWrapper>\n </Wrapper>\n{:else}\n {@const Wrapper = wrappers[0]}\n <Wrapper>\n {@render children?.()}\n </Wrapper>\n{/if}\n","<script lang=\"ts\">\n import { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\n import NestedWrapper from './NestedWrapper.svelte';\n import type { Snippet } from 'svelte';\n\n type Props = {\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n children: Snippet;\n };\n\n let { plugins, children }: Props = $props();\n let utilities: any[] = $state([]);\n let wrappers: any[] = $state([]);\n\n // recompute when plugins change\n $effect(() => {\n const nextUtilities: any[] = [];\n const nextWrappers: any[] = [];\n\n for (const reg of plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements?.() ?? [];\n for (const element of elements) {\n if (element.type === 'utility') {\n nextUtilities.push(element.component);\n } else if (element.type === 'wrapper') {\n nextWrappers.push(element.component);\n }\n }\n }\n }\n\n utilities = nextUtilities;\n wrappers = nextWrappers;\n });\n</script>\n\n{#if wrappers.length > 0}\n <!-- wrap slot content inside all wrappers -->\n <NestedWrapper {wrappers} {children} />\n{:else}\n {@render children?.()}\n{/if}\n\n<!-- mount all utilities -->\n{#each utilities as Utility, i (`utility-${i}`)}\n <Utility />\n{/each}\n","<script lang=\"ts\">\n import type { Logger, PdfEngine } from '@embedpdf/models';\n import {\n type IPlugin,\n type PluginBatchRegistrations,\n type PluginRegistryConfig,\n PluginRegistry,\n } from '@embedpdf/core';\n import { type Snippet } from 'svelte';\n import AutoMount from './AutoMount.svelte';\n import { pdfContext, type PDFContextState } from '../hooks';\n\n export type { PluginBatchRegistrations };\n\n interface EmbedPDFProps {\n /**\n * The PDF engine to use for the PDF viewer.\n */\n engine: PdfEngine;\n /**\n * Registry configuration including logger, permissions, and defaults.\n */\n config?: PluginRegistryConfig;\n /**\n * @deprecated Use config.logger instead. Will be removed in next major version.\n */\n logger?: Logger;\n /**\n * The callback to call when the PDF viewer is initialized.\n */\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n /**\n * The plugins to use for the PDF viewer.\n */\n plugins: PluginBatchRegistrations;\n /**\n * The children to render for the PDF viewer.\n */\n children: Snippet<[PDFContextState]>;\n /**\n * Whether to auto-mount specific non-visual DOM elements from plugins.\n * @default true\n */\n autoMountDomElements?: boolean;\n }\n\n let {\n engine,\n config,\n logger,\n onInitialized,\n plugins,\n children,\n autoMountDomElements = true,\n }: EmbedPDFProps = $props();\n\n let latestInit = onInitialized;\n\n $effect(() => {\n if (onInitialized) {\n latestInit = onInitialized;\n }\n });\n\n $effect(() => {\n if (engine || (engine && plugins)) {\n // Merge deprecated logger prop into config (config.logger takes precedence)\n const finalConfig: PluginRegistryConfig = {\n ...config,\n logger: config?.logger ?? logger,\n };\n const reg = new PluginRegistry(engine, finalConfig);\n reg.registerPluginBatch(plugins);\n\n const initialize = async () => {\n await reg.initialize();\n\n // if the registry is destroyed, don't do anything\n if (reg.isDestroyed()) {\n return;\n }\n\n const store = reg.getStore();\n pdfContext.coreState = store.getState().core;\n\n const unsubscribe = store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && newState.core !== oldState.core) {\n pdfContext.coreState = newState.core;\n\n // Update convenience accessors\n const activeDocumentId = newState.core.activeDocumentId ?? null;\n const documents = newState.core.documents ?? {};\n const documentOrder = newState.core.documentOrder ?? [];\n\n pdfContext.activeDocumentId = activeDocumentId;\n pdfContext.activeDocument =\n activeDocumentId && documents[activeDocumentId] ? documents[activeDocumentId] : null;\n pdfContext.documents = documents;\n pdfContext.documentStates = documentOrder\n .map((docId) => documents[docId])\n .filter(\n (doc): doc is import('@embedpdf/core').DocumentState =>\n doc !== null && doc !== undefined,\n );\n }\n });\n\n /* always call the *latest* callback */\n await latestInit?.(reg);\n\n // if the registry is destroyed, don't do anything\n if (reg.isDestroyed()) {\n unsubscribe();\n return;\n }\n\n reg.pluginsReady().then(() => {\n if (!reg.isDestroyed()) {\n pdfContext.pluginsReady = true;\n }\n });\n\n // Provide the registry to children via context\n pdfContext.registry = reg;\n pdfContext.isInitializing = false;\n\n return unsubscribe;\n };\n\n let cleanup: (() => void) | undefined;\n initialize()\n .then((unsub) => {\n cleanup = unsub;\n })\n .catch(console.error);\n\n return () => {\n cleanup?.();\n reg.destroy();\n pdfContext.registry = null;\n pdfContext.coreState = null;\n pdfContext.isInitializing = true;\n pdfContext.pluginsReady = false;\n pdfContext.activeDocumentId = null;\n pdfContext.activeDocument = null;\n pdfContext.documents = {};\n pdfContext.documentStates = [];\n };\n }\n });\n</script>\n\n{#if pdfContext.pluginsReady && autoMountDomElements}\n <AutoMount {plugins}>{@render children(pdfContext)}</AutoMount>\n{:else}\n {@render children(pdfContext)}\n{/if}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { usePlugin } from './use-plugin.svelte.js';\n\n/**\n * Hook to access a plugin's capability.\n * @param pluginId The ID of the plugin to access\n * @returns The capability provided by the plugin or null during initialization\n * @example\n * // Get zoom capability\n * const zoom = useCapability<ZoomPlugin>(ZoomPlugin.id);\n */\nexport function useCapability<T extends BasePlugin>(pluginId: T['id']) {\n const p = usePlugin<T>(pluginId);\n\n const state = $state({\n provides: null as ReturnType<NonNullable<T['provides']>> | null,\n isLoading: true,\n ready: new Promise<void>(() => {}),\n });\n\n // Use $effect to reactively update when plugin loads\n $effect(() => {\n if (!p.plugin) {\n state.provides = null;\n state.isLoading = p.isLoading;\n state.ready = p.ready;\n return;\n }\n\n if (!p.plugin.provides) {\n throw new Error(`Plugin ${pluginId} does not provide a capability`);\n }\n\n state.provides = p.plugin.provides() as ReturnType<NonNullable<T['provides']>>;\n state.isLoading = p.isLoading;\n state.ready = p.ready;\n });\n\n return state;\n}\n","import { PdfPermissionFlag } from '@embedpdf/models';\nimport { useCoreState } from './use-core-state.svelte';\nimport { getEffectivePermission, getEffectivePermissions } from '../../lib/store/selectors';\n\nexport interface DocumentPermissions {\n /** Effective permission flags after applying overrides */\n permissions: number;\n /** Raw PDF permission flags (before overrides) */\n pdfPermissions: number;\n /** Check if a specific permission flag is effectively allowed */\n hasPermission: (flag: PdfPermissionFlag) => boolean;\n /** Check if all specified flags are effectively allowed */\n hasAllPermissions: (...flags: PdfPermissionFlag[]) => boolean;\n\n // Shorthand booleans for all permission flags (using effective permissions):\n /** Can print (possibly degraded quality) */\n canPrint: boolean;\n /** Can modify document contents */\n canModifyContents: boolean;\n /** Can copy/extract text and graphics */\n canCopyContents: boolean;\n /** Can add/modify annotations and fill forms */\n canModifyAnnotations: boolean;\n /** Can fill in existing form fields */\n canFillForms: boolean;\n /** Can extract for accessibility */\n canExtractForAccessibility: boolean;\n /** Can assemble document (insert, rotate, delete pages) */\n canAssembleDocument: boolean;\n /** Can print high quality */\n canPrintHighQuality: boolean;\n}\n\n/**\n * Hook that provides reactive access to a document's effective permission flags.\n * Applies layered resolution: per-document override → global override → PDF permission.\n *\n * @param getDocumentId Function that returns the document ID\n * @returns An object with reactive permission properties.\n */\nexport function useDocumentPermissions(getDocumentId: () => string): DocumentPermissions {\n const coreStateRef = useCoreState();\n\n const documentId = $derived(getDocumentId());\n const coreState = $derived(coreStateRef.current);\n\n const effectivePermissions = $derived(\n coreState ? getEffectivePermissions(coreState, documentId) : PdfPermissionFlag.AllowAll,\n );\n\n const pdfPermissions = $derived(\n coreState?.documents[documentId]?.document?.permissions ?? PdfPermissionFlag.AllowAll,\n );\n\n const hasPermission = (flag: PdfPermissionFlag) =>\n coreState ? getEffectivePermission(coreState, documentId, flag) : true;\n\n const hasAllPermissions = (...flags: PdfPermissionFlag[]) =>\n flags.every((flag) => (coreState ? getEffectivePermission(coreState, documentId, flag) : true));\n\n return {\n get permissions() {\n return effectivePermissions;\n },\n get pdfPermissions() {\n return pdfPermissions;\n },\n hasPermission,\n hasAllPermissions,\n get canPrint() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.Print)\n : true;\n },\n get canModifyContents() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ModifyContents)\n : true;\n },\n get canCopyContents() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.CopyContents)\n : true;\n },\n get canModifyAnnotations() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ModifyAnnotations)\n : true;\n },\n get canFillForms() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.FillForms)\n : true;\n },\n get canExtractForAccessibility() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.ExtractForAccessibility)\n : true;\n },\n get canAssembleDocument() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.AssembleDocument)\n : true;\n },\n get canPrintHighQuality() {\n return coreState\n ? getEffectivePermission(coreState, documentId, PdfPermissionFlag.PrintHighQuality)\n : true;\n },\n };\n}\n","import { useCoreState } from './use-core-state.svelte';\n\n/**\n * Hook that provides reactive access to a specific document's state from the core store.\n *\n * @param getDocumentId Function that returns the document ID\n * @returns The reactive DocumentState object or null if not found.\n */\nexport function useDocumentState(getDocumentId: () => string | null) {\n const coreStateRef = useCoreState();\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n const documentState = $derived(\n coreStateRef.current && documentId\n ? (coreStateRef.current.documents[documentId] ?? null)\n : null,\n );\n\n return {\n get current() {\n return documentState;\n },\n };\n}\n"],"names":["pdfContext","registry","coreState","isInitializing","pluginsReady","activeDocumentId","activeDocument","documents","documentStates","useRegistry","usePlugin","pluginId","state","plugin","isLoading","ready","Promise","getPlugin","Error","useCoreState","context","current","PdfPermissionFlag","Print","ModifyContents","CopyContents","ModifyAnnotations","FillForms","ExtractForAccessibility","AssembleDocument","PrintHighQuality","ALL_PERMISSION_FLAGS","PERMISSION_FLAG_TO_NAME","getPermissionOverride","overrides","flag","name","getEffectivePermission","documentId","docState","docConfig","permissions","globalConfig","globalPermissions","pdfPermissions","_a","document","AllowAll","docOverride","globalOverride","enforceDocumentPermissions","Wrapper","Wrapper_1","$$anchor","$0","$","derived","$$props","wrappers","slice","NestedWrapper","Wrapper_2","length","consequent","$$render","alternate","utilities","proxy","user_effect","nextUtilities","nextWrappers","reg","plugins","pkg","package","hasAutoMountElements","elements","autoMountElements","call","element","type","push","component","set","each","node_2","get","Utility","i","Utility_1","autoMountDomElements","latestInit","onInitialized","engine","finalConfig","logger","PluginRegistry","registerPluginBatch","cleanup","async","initialize","isDestroyed","store","getStore","getState","core","unsubscribe","subscribe","action","newState","oldState","isCoreAction","documentOrder","map","docId","filter","doc","then","unsub","catch","console","error","destroy","AutoMount","p","provides","getDocumentId","coreStateRef","effectivePermissions","reduce","acc","getEffectivePermissions","hasPermission","hasAllPermissions","flags","every","canPrint","canModifyContents","canCopyContents","canModifyAnnotations","canFillForms","canExtractForAccessibility","canAssembleDocument","canPrintHighQuality","documentState"],"mappings":"8fAeaA,WACXC,SAAU,KACVC,UAAW,KACXC,gBAAgB,EAChBC,cAAc,EACdC,iBAAkB,KAClBC,eAAgB,KAChBC,aACAC,oBAQWC,MAAoBT,WCpBjBU,EAAgCC,GACtC,MAAAV,SAAAA,GAAaD,EAEfY,WACJC,OAAQ,KACRC,WAAW,EACXC,MAAA,IAAWC,QAAA,aAGI,OAAbf,SACKW,EAGH,MAAAC,EAASZ,EAASgB,UAAaN,GAEhC,IAAAE,EACO,MAAA,IAAAK,gBAAgBP,sBAG5BC,EAAMC,OAASA,EACfD,EAAME,WAAY,EAClBF,EAAMG,MAAQF,EAAOE,QAEdH,CACT,CC3BgB,SAAAO,IACR,MAAAC,EAAUX,WAGV,WAAAY,GACK,OAAAD,EAAQlB,SACjB,EAEJ,CCGSoB,EAAAA,kBAAkBC,MACTD,EAAAA,kBAAkBE,eACpBF,EAAAA,kBAAkBG,aACbH,EAAAA,kBAAkBI,kBAC1BJ,EAAAA,kBAAkBK,UACJL,EAAAA,kBAAkBM,wBACzBN,EAAAA,kBAAkBO,iBAClBP,EAAAA,kBAAkBQ,iBAyC/B,MAAMC,EAA4C,CACvDT,EAAAA,kBAAkBC,MAClBD,EAAAA,kBAAkBE,eAClBF,EAAAA,kBAAkBG,aAClBH,EAAAA,kB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B,EAAAA,kBAAkBC,MAEtE,EACI,qBAAAkH,gBACKvI,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBE,eAEtE,EACI,mBAAAkH,gBACKxI,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBG,aAEtE,EACI,wBAAAkH,gBACKzI,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBI,kBAEtE,EACI,gBAAAkH,gBACK1I,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBK,UAEtE,EACI,8BAAAkH,gBACK3I,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBM,wBAEtE,EACI,uBAAAkH,gBACK5I,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBO,iBAEtE,EACI,uBAAAkH,gBACK7I,IACHmC,QAAuBnC,GAAAqD,EAAA+B,IAAWhD,GAAYhB,EAAAA,kBAAkBQ,iBAEtE,EAEJ,oCCtGiCgG,GACzB,MAAAC,EAAe5G,IAGfmB,YAAsBwF,GAEtBkB,EAAAzF,EAAAC,QAAA,IACJuE,EAAa1G,eAAWiB,GACnByF,EAAa1G,QAAQd,UAAAgD,EAAA+B,IAAUhD,KAAe,KAC/C,aAIA,WAAAjB,gBACK2H,EACT,EAEJ"}
|
package/dist/svelte/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as $ from "svelte/internal/client";
|
|
2
|
+
import { PdfPermissionFlag } from "@embedpdf/models";
|
|
2
3
|
import "svelte/internal/disclose-version";
|
|
3
4
|
import { hasAutoMountElements, PluginRegistry } from "@embedpdf/core";
|
|
4
5
|
const pdfContext = $.proxy({
|
|
@@ -70,6 +71,116 @@ function useDocumentState(getDocumentId) {
|
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
73
|
}
|
|
74
|
+
({
|
|
75
|
+
print: PdfPermissionFlag.Print,
|
|
76
|
+
modifyContents: PdfPermissionFlag.ModifyContents,
|
|
77
|
+
copyContents: PdfPermissionFlag.CopyContents,
|
|
78
|
+
modifyAnnotations: PdfPermissionFlag.ModifyAnnotations,
|
|
79
|
+
fillForms: PdfPermissionFlag.FillForms,
|
|
80
|
+
extractForAccessibility: PdfPermissionFlag.ExtractForAccessibility,
|
|
81
|
+
assembleDocument: PdfPermissionFlag.AssembleDocument,
|
|
82
|
+
printHighQuality: PdfPermissionFlag.PrintHighQuality
|
|
83
|
+
});
|
|
84
|
+
const ALL_PERMISSION_FLAGS = [
|
|
85
|
+
PdfPermissionFlag.Print,
|
|
86
|
+
PdfPermissionFlag.ModifyContents,
|
|
87
|
+
PdfPermissionFlag.CopyContents,
|
|
88
|
+
PdfPermissionFlag.ModifyAnnotations,
|
|
89
|
+
PdfPermissionFlag.FillForms,
|
|
90
|
+
PdfPermissionFlag.ExtractForAccessibility,
|
|
91
|
+
PdfPermissionFlag.AssembleDocument,
|
|
92
|
+
PdfPermissionFlag.PrintHighQuality
|
|
93
|
+
];
|
|
94
|
+
const PERMISSION_FLAG_TO_NAME = {
|
|
95
|
+
[PdfPermissionFlag.Print]: "print",
|
|
96
|
+
[PdfPermissionFlag.ModifyContents]: "modifyContents",
|
|
97
|
+
[PdfPermissionFlag.CopyContents]: "copyContents",
|
|
98
|
+
[PdfPermissionFlag.ModifyAnnotations]: "modifyAnnotations",
|
|
99
|
+
[PdfPermissionFlag.FillForms]: "fillForms",
|
|
100
|
+
[PdfPermissionFlag.ExtractForAccessibility]: "extractForAccessibility",
|
|
101
|
+
[PdfPermissionFlag.AssembleDocument]: "assembleDocument",
|
|
102
|
+
[PdfPermissionFlag.PrintHighQuality]: "printHighQuality"
|
|
103
|
+
};
|
|
104
|
+
function getPermissionOverride(overrides, flag) {
|
|
105
|
+
if (!overrides) return void 0;
|
|
106
|
+
if (flag in overrides) {
|
|
107
|
+
return overrides[flag];
|
|
108
|
+
}
|
|
109
|
+
const name = PERMISSION_FLAG_TO_NAME[flag];
|
|
110
|
+
if (name && name in overrides) {
|
|
111
|
+
return overrides[name];
|
|
112
|
+
}
|
|
113
|
+
return void 0;
|
|
114
|
+
}
|
|
115
|
+
function getEffectivePermission(state, documentId, flag) {
|
|
116
|
+
var _a;
|
|
117
|
+
const docState = state.documents[documentId];
|
|
118
|
+
const docConfig = docState == null ? void 0 : docState.permissions;
|
|
119
|
+
const globalConfig = state.globalPermissions;
|
|
120
|
+
const pdfPermissions = ((_a = docState == null ? void 0 : docState.document) == null ? void 0 : _a.permissions) ?? PdfPermissionFlag.AllowAll;
|
|
121
|
+
const docOverride = getPermissionOverride(docConfig == null ? void 0 : docConfig.overrides, flag);
|
|
122
|
+
if (docOverride !== void 0) {
|
|
123
|
+
return docOverride;
|
|
124
|
+
}
|
|
125
|
+
const globalOverride = getPermissionOverride(globalConfig == null ? void 0 : globalConfig.overrides, flag);
|
|
126
|
+
if (globalOverride !== void 0) {
|
|
127
|
+
return globalOverride;
|
|
128
|
+
}
|
|
129
|
+
const enforce = (docConfig == null ? void 0 : docConfig.enforceDocumentPermissions) ?? (globalConfig == null ? void 0 : globalConfig.enforceDocumentPermissions) ?? true;
|
|
130
|
+
if (!enforce) return true;
|
|
131
|
+
return (pdfPermissions & flag) !== 0;
|
|
132
|
+
}
|
|
133
|
+
function getEffectivePermissions(state, documentId) {
|
|
134
|
+
return ALL_PERMISSION_FLAGS.reduce((acc, flag) => {
|
|
135
|
+
return getEffectivePermission(state, documentId, flag) ? acc | flag : acc;
|
|
136
|
+
}, 0);
|
|
137
|
+
}
|
|
138
|
+
function useDocumentPermissions(getDocumentId) {
|
|
139
|
+
const coreStateRef = useCoreState();
|
|
140
|
+
const documentId = $.derived(getDocumentId);
|
|
141
|
+
const coreState = $.derived(() => coreStateRef.current);
|
|
142
|
+
const effectivePermissions = $.derived(() => $.get(coreState) ? getEffectivePermissions($.get(coreState), $.get(documentId)) : PdfPermissionFlag.AllowAll);
|
|
143
|
+
const pdfPermissions = $.derived(() => {
|
|
144
|
+
var _a, _b, _c;
|
|
145
|
+
return ((_c = (_b = (_a = $.get(coreState)) == null ? void 0 : _a.documents[$.get(documentId)]) == null ? void 0 : _b.document) == null ? void 0 : _c.permissions) ?? PdfPermissionFlag.AllowAll;
|
|
146
|
+
});
|
|
147
|
+
const hasPermission = (flag) => $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), flag) : true;
|
|
148
|
+
const hasAllPermissions = (...flags) => flags.every((flag) => $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), flag) : true);
|
|
149
|
+
return {
|
|
150
|
+
get permissions() {
|
|
151
|
+
return $.get(effectivePermissions);
|
|
152
|
+
},
|
|
153
|
+
get pdfPermissions() {
|
|
154
|
+
return $.get(pdfPermissions);
|
|
155
|
+
},
|
|
156
|
+
hasPermission,
|
|
157
|
+
hasAllPermissions,
|
|
158
|
+
get canPrint() {
|
|
159
|
+
return $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), PdfPermissionFlag.Print) : true;
|
|
160
|
+
},
|
|
161
|
+
get canModifyContents() {
|
|
162
|
+
return $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), PdfPermissionFlag.ModifyContents) : true;
|
|
163
|
+
},
|
|
164
|
+
get canCopyContents() {
|
|
165
|
+
return $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), PdfPermissionFlag.CopyContents) : true;
|
|
166
|
+
},
|
|
167
|
+
get canModifyAnnotations() {
|
|
168
|
+
return $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), PdfPermissionFlag.ModifyAnnotations) : true;
|
|
169
|
+
},
|
|
170
|
+
get canFillForms() {
|
|
171
|
+
return $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), PdfPermissionFlag.FillForms) : true;
|
|
172
|
+
},
|
|
173
|
+
get canExtractForAccessibility() {
|
|
174
|
+
return $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), PdfPermissionFlag.ExtractForAccessibility) : true;
|
|
175
|
+
},
|
|
176
|
+
get canAssembleDocument() {
|
|
177
|
+
return $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), PdfPermissionFlag.AssembleDocument) : true;
|
|
178
|
+
},
|
|
179
|
+
get canPrintHighQuality() {
|
|
180
|
+
return $.get(coreState) ? getEffectivePermission($.get(coreState), $.get(documentId), PdfPermissionFlag.PrintHighQuality) : true;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
73
184
|
function NestedWrapper_1($$anchor, $$props) {
|
|
74
185
|
$.push($$props, true);
|
|
75
186
|
var fragment = $.comment();
|
|
@@ -199,8 +310,13 @@ function EmbedPDF($$anchor, $$props) {
|
|
|
199
310
|
}
|
|
200
311
|
});
|
|
201
312
|
$.user_effect(() => {
|
|
313
|
+
var _a;
|
|
202
314
|
if ($$props.engine || $$props.engine && $$props.plugins) {
|
|
203
|
-
const
|
|
315
|
+
const finalConfig = {
|
|
316
|
+
...$$props.config,
|
|
317
|
+
logger: ((_a = $$props.config) == null ? void 0 : _a.logger) ?? $$props.logger
|
|
318
|
+
};
|
|
319
|
+
const reg = new PluginRegistry($$props.engine, finalConfig);
|
|
204
320
|
reg.registerPluginBatch($$props.plugins);
|
|
205
321
|
const initialize = async () => {
|
|
206
322
|
await reg.initialize();
|
|
@@ -289,6 +405,7 @@ export {
|
|
|
289
405
|
pdfContext,
|
|
290
406
|
useCapability,
|
|
291
407
|
useCoreState,
|
|
408
|
+
useDocumentPermissions,
|
|
292
409
|
useDocumentState,
|
|
293
410
|
usePlugin,
|
|
294
411
|
useRegistry
|