@embedpdf/core 1.4.0 → 1.4.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/dist/svelte/hooks/use-capability.svelte.d.ts +5 -7
- package/dist/svelte/hooks/use-core-state.svelte.d.ts +1 -1
- package/dist/svelte/hooks/use-plugin.svelte.d.ts +5 -7
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.js +35 -25
- package/dist/svelte/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { BasePlugin } from '../../lib/index.ts';
|
|
2
|
-
type CapabilityState<T extends BasePlugin> = {
|
|
3
|
-
provides: ReturnType<NonNullable<T['provides']>> | null;
|
|
4
|
-
isLoading: boolean;
|
|
5
|
-
ready: Promise<void>;
|
|
6
|
-
};
|
|
7
2
|
/**
|
|
8
3
|
* Hook to access a plugin's capability.
|
|
9
4
|
* @param pluginId The ID of the plugin to access
|
|
@@ -12,5 +7,8 @@ type CapabilityState<T extends BasePlugin> = {
|
|
|
12
7
|
* // Get zoom capability
|
|
13
8
|
* const zoom = useCapability<ZoomPlugin>(ZoomPlugin.id);
|
|
14
9
|
*/
|
|
15
|
-
export declare function useCapability<T extends BasePlugin>(pluginId: T['id']):
|
|
16
|
-
|
|
10
|
+
export declare function useCapability<T extends BasePlugin>(pluginId: T['id']): {
|
|
11
|
+
provides: ReturnType<NonNullable<T["provides"]>> | null;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
ready: Promise<void>;
|
|
14
|
+
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { BasePlugin } from '../../lib/index.ts';
|
|
2
|
-
type PluginState<T extends BasePlugin> = {
|
|
3
|
-
plugin: T | null;
|
|
4
|
-
isLoading: boolean;
|
|
5
|
-
ready: Promise<void>;
|
|
6
|
-
};
|
|
7
2
|
/**
|
|
8
3
|
* Hook to access a plugin.
|
|
9
4
|
* @param pluginId The ID of the plugin to access
|
|
@@ -12,5 +7,8 @@ type PluginState<T extends BasePlugin> = {
|
|
|
12
7
|
* // Get zoom plugin
|
|
13
8
|
* const zoom = usePlugin<ZoomPlugin>(ZoomPlugin.id);
|
|
14
9
|
*/
|
|
15
|
-
export declare function usePlugin<T extends BasePlugin>(pluginId: T['id']):
|
|
16
|
-
|
|
10
|
+
export declare function usePlugin<T extends BasePlugin>(pluginId: T['id']): {
|
|
11
|
+
plugin: T | null;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
ready: Promise<void>;
|
|
14
|
+
};
|
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"),t=require("@embedpdf/core");function n(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}require("svelte/internal/disclose-version");const r=n(e),i=r.proxy({registry:null,isInitializing:!0,pluginsReady:!1}),o=()=>i;function s(e){const{registry:t}=i
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/core");function n(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const n in e)if("default"!==n){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}return t.default=e,Object.freeze(t)}require("svelte/internal/disclose-version");const r=n(e),i=r.proxy({registry:null,isInitializing:!0,pluginsReady:!1}),o=()=>i;function s(e){const{registry:t}=i,n=r.proxy({plugin:null,isLoading:!0,ready:new Promise((()=>{}))});if(null===t)return n;const o=t.getPlugin(e);if(!o)throw new Error(`Plugin ${e} not found`);return n.plugin=o,n.isLoading=!1,n.ready=o.ready(),n}function l(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)));l(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 a(e,n){r.push(n,!0);let i=r.state(r.proxy([])),o=r.state(r.proxy([]));r.user_effect((()=>{var e;const s=[],l=[];for(const r of n.plugins){const n=r.package;if(t.hasAutoMountElements(n)){const t=(null==(e=n.autoMountElements)?void 0:e.call(n))??[];for(const e of t)"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(),a=r.first_child(s),c=e=>{l(e,{get wrappers(){return r.get(o)},get children(){return n.children}})},d=e=>{var t=r.comment(),i=r.first_child(t);r.snippet(i,(()=>n.children??r.noop)),r.append(e,t)};r.if(a,(e=>{r.get(o).length>0?e(c):e(d,!1)}));var u=r.sibling(a,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,n){r.push(n,!0);let o=r.prop(n,"autoMountDomElements",3,!0),s=n.onInitialized;r.user_effect((()=>{n.onInitialized&&(s=n.onInitialized)})),r.user_effect((()=>{if(n.engine||n.engine&&n.plugins){const e=new t.PluginRegistry(n.engine,{logger:n.logger});e.registerPluginBatch(n.plugins);return(async()=>{await e.initialize(),e.isDestroyed()||(await(null==s?void 0:s(e)),e.isDestroyed()||(e.pluginsReady().then((()=>{e.isDestroyed()||(i.pluginsReady=!0)})),i.registry=e,i.isInitializing=!1))})().catch(console.error),()=>{e.destroy(),i.registry=null,i.isInitializing=!1,i.pluginsReady=!1}}}));var l=r.comment(),p=r.first_child(l),c=e=>{a(e,{get plugins(){return n.plugins},children:(e,t)=>{var o=r.comment(),s=r.first_child(o);r.snippet(s,(()=>n.children),(()=>i)),r.append(e,o)},$$slots:{default:!0}})},d=e=>{var t=r.comment(),o=r.first_child(t);r.snippet(o,(()=>n.children),(()=>i)),r.append(e,t)};r.if(p,(e=>{i.pluginsReady&&o()?e(c):e(d,!1)})),r.append(e,l),r.pop()},exports.pdfContext=i,exports.useCapability=function(e){const t=s(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=function(){const{registry:e}=o(),n=r.proxy({coreState:null});return r.user_effect((()=>{if(!e)return;const r=e.getStore();return n.coreState=r.getState().core,r.subscribe(((e,i,o)=>{r.isCoreAction(e)&&!t.arePropsEqual(i.core,o.core)&&(n.coreState=i.core)}))})),n},exports.usePlugin=s,exports.useRegistry=o;
|
|
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/components/NestedWrapper.svelte","../../src/svelte/components/AutoMount.svelte","../../src/svelte/components/EmbedPDF.svelte","../../src/svelte/hooks/use-capability.svelte.ts","../../src/svelte/hooks/use-core-state.svelte.ts"],"sourcesContent":["import type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const pdfContext = $state<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\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;","import type { BasePlugin } from '@embedpdf/core';\nimport { pdfContext } from './use-registry.svelte.js';\n\ntype PluginState<T extends BasePlugin> = {\n plugin: T | null;\n isLoading: boolean;\n ready: Promise<void>;\n};\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']): PluginState<T> {\n const { registry } = pdfContext;\n if (registry === null) {\n return {\n plugin: null,\n isLoading: true,\n ready: new Promise(() => {})\n };\n }\n\n const plugin = registry.getPlugin<T>(pluginId);\n\n if (!plugin) {\n throw new Error(`Plugin ${pluginId} not found`);\n }\n\n return {\n plugin,\n isLoading: false,\n ready: plugin.ready()\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 /* 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 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 initialize().catch(console.error);\n\n return () => {\n reg.destroy();\n pdfContext.registry = null;\n pdfContext.isInitializing = false;\n pdfContext.pluginsReady = false;\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\ntype CapabilityState<T extends BasePlugin> = {\n provides: ReturnType<NonNullable<T['provides']>> | null;\n isLoading: boolean;\n ready: Promise<void>;\n};\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']): CapabilityState<T> {\n const p = usePlugin<T>(pluginId);\n\n if (!p.plugin) {\n return {\n provides: null,\n isLoading: p.isLoading,\n ready: p.ready\n };\n }\n\n if (!p.plugin.provides) {\n throw new Error(`Plugin ${pluginId} does not provide a capability`);\n }\n\n return {\n provides: p.plugin.provides() as ReturnType<NonNullable<T['provides']>>,\n isLoading: p.isLoading,\n ready: p.ready\n };\n}\n","import { type CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry.svelte';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState() {\n const { registry } = $derived(useRegistry());\n let coreState = $state<CoreState | null>(null);\n\n $effect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n coreState = store.getState().core;\n\n // Create a single subscription that handles all core actions\n return store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && !arePropsEqual(newState.core, oldState.core)) {\n coreState = newState.core;\n }\n });\n });\n return {\n get coreState() {\n return coreState;\n },\n };\n}\n"],"names":["pdfContext","registry","isInitializing","pluginsReady","useRegistry","usePlugin","pluginId","plugin","isLoading","ready","Promise","getPlugin","Error","Wrapper","$0","$","derived","$$props","wrappers","slice","length","consequent","$$render","alternate","utilities","state","proxy","user_effect","nextUtilities","nextWrappers","reg","plugins","pkg","package","hasAutoMountElements","elements","_a","autoMountElements","call","element","type","push","component","$__namespace","set","each","node_2","get","Utility","i","autoMountDomElements","latestInit","onInitialized","engine","PluginRegistry","logger","registerPluginBatch","async","initialize","isDestroyed","then","catch","console","error","destroy","p","provides","coreState","store","getStore","getState","core","subscribe","action","newState","oldState","isCoreAction","arePropsEqual"],"mappings":"0dAQaA,WACXC,SAAU,KACVC,gBAAgB,EAChBC,cAAc,IAQHC,MAAoBJ,WCFjBK,EAAgCC,GACtC,MAAAL,SAAAA,GAAaD,KACJ,OAAbC,EAEA,MAAA,CAAAM,OAAQ,KACRC,WAAW,EACXC,MAAW,IAAAC,SAAc,UAIvB,MAAAH,EAASN,EAASU,UAAaL,GAEhC,IAAAC,EACO,MAAA,IAAAK,gBAAgBN,sBAI1BC,SACAC,WAAW,EACXC,MAAOF,EAAOE,QAElB,yECzBU,MAAAI,4BAA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EAAArB,IAGfA,EAAI6B,gBAIJ7B,EAAA3B,eAAeyD,MAAW,KACvB9B,EAAI6B,gBACP3D,EAAWG,cAAe,EAC5B,IAIFH,EAAWC,SAAW6B,EACtB9B,EAAWE,gBAAiB,GAAA,KAEjB2D,MAAMC,QAAQC,OAEd,KACXjC,EAAIkC,UACJhE,EAAWC,SAAW,KACtBD,EAAWE,gBAAiB,EAC5BF,EAAWG,cAAe,CAAA,CAE9B,6KAKqCH,wHAErBA,+BAHfA,EAAWG,cAAgB+C,MAAoB7B,GAAAC,EAAAC,GAAA,EAAA,yBAFpD,sDC9EoDjB,GAC5C,MAAA2D,EAAI5D,EAAaC,OAElB2D,EAAE1D,OAEH,MAAA,CAAA2D,SAAU,KACV1D,UAAWyD,EAAEzD,UACbC,MAAOwD,EAAExD,OAIR,IAAAwD,EAAE1D,OAAO2D,SACF,MAAA,IAAAtD,gBAAgBN,0CAI1B4D,SAAUD,EAAE1D,OAAO2D,WACnB1D,UAAWyD,EAAEzD,UACbC,MAAOwD,EAAExD,MAEb,uBC9BgB,6BACgBL,GAAtBH,0BAAAA,WACJ,IAAAkE,UAAqC,aAEzCpD,EAAAY,4BACO1B,GAAU,aAETmE,EAAArD,EAAAgC,IAAQ9C,GAASoE,kBAGXtD,EAAA6B,IAAAuB,EAAAC,EAAME,WAAWC,MAAA,GAGtBH,EAAMI,WAAW,CAAAC,EAAQC,EAAUC,KAEpCP,EAAMQ,aAAaH,KAAYI,gBAAcH,EAASH,KAAMI,EAASJ,aACvEJ,EAAYO,EAASH,MAAA,KAExB,KAGG,aAAAJ,gBACKA,IAGb"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.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-core-state.svelte.ts"],"sourcesContent":["import type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const pdfContext = $state<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\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;","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","<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 /* 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 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 initialize().catch(console.error);\n\n return () => {\n reg.destroy();\n pdfContext.registry = null;\n pdfContext.isInitializing = false;\n pdfContext.pluginsReady = false;\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 { type CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry.svelte';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState() {\n const { registry } = useRegistry();\n\n const state = $state({\n coreState: null as CoreState | null,\n });\n\n $effect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n state.coreState = store.getState().core;\n\n // Create a single subscription that handles all core actions\n return store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && !arePropsEqual(newState.core, oldState.core)) {\n state.coreState = newState.core;\n }\n });\n });\n\n return state;\n}\n"],"names":["pdfContext","registry","isInitializing","pluginsReady","useRegistry","usePlugin","pluginId","state","$","proxy","plugin","isLoading","ready","Promise","getPlugin","Error","Wrapper","$0","derived","$$props","wrappers","slice","length","consequent","$$render","alternate","utilities","user_effect","nextUtilities","nextWrappers","reg","plugins","pkg","package","hasAutoMountElements","elements","_a","autoMountElements","call","element","type","push","component","$__namespace","set","each","node_2","get","Utility","i","autoMountDomElements","latestInit","onInitialized","engine","PluginRegistry","logger","registerPluginBatch","async","initialize","isDestroyed","then","catch","console","error","destroy","p","provides","coreState","store","getStore","getState","core","subscribe","action","newState","oldState","isCoreAction","arePropsEqual"],"mappings":"0dAQaA,WACXC,SAAU,KACVC,gBAAgB,EAChBC,cAAc,IAQHC,MAAoBJ,WCRjBK,EAAgCC,GACtC,MAAAL,SAAAA,GAAaD,EAEfO,EACJC,EAAAC,MAAA,CAAAC,OAAQ,KACRC,WAAW,EACXC,MAAW,IAAAC,SAAoB,cAGhB,OAAbZ,EACK,OAAAM,EAGH,MAAAG,EAAST,EAASa,UAAaR,GAEhC,IAAAI,EACO,MAAA,IAAAK,gBAAgBT,eAOrB,OAJPC,EAAMG,OAASA,EACfH,EAAMI,WAAY,EACZJ,EAAAK,MAAQF,EAAOE,QAEdL,CACT,yECtBU,MAAAS,4BAAmB,uGAES,IAAAC,EAAAT,EAAAU,SAAA,IAAAC,EAAAC,SAAAC,MAAM,6NAKlC,MAAAL,4BAAmB,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D,EAAWG,cAAe,EAC5B,IAIFH,EAAWC,SAAW6B,EACtB9B,EAAWE,gBAAiB,GAAA,KAEjB2D,MAAMC,QAAQC,OAEd,KACXjC,EAAIkC,UACJhE,EAAWC,SAAW,KACtBD,EAAWE,gBAAiB,EAC5BF,EAAWG,cAAe,CAAA,CAE9B,6KAKqCH,wHAErBA,+BAHfA,EAAWG,cAAgB+C,MAAoB3B,GAAAC,EAAAC,GAAA,EAAA,yBAFpD,sDCpFoDnB,GAC5C,MAAA2D,EAAI5D,EAAaC,GAEjBC,WACJ2D,SAAU,KACVvD,WAAW,EACXC,MAAW,IAAAC,SAAoB,WAqB1B,OAjBPL,EAAAmB,sBACOsC,EAAEvD,cACLH,EAAM2D,SAAW,KACjB3D,EAAMI,UAAYsD,EAAEtD,eACpBJ,EAAMK,MAAQqD,EAAErD,OAIb,IAAAqD,EAAEvD,OAAOwD,SACF,MAAA,IAAAnD,gBAAgBT,mCAGtBC,EAAA2D,SAAWD,EAAEvD,OAAOwD,WAC1B3D,EAAMI,UAAYsD,EAAEtD,UACpBJ,EAAMK,MAAQqD,EAAErD,KAAA,IAGXL,CACT,uBChCgB,WACN,MAAAN,SAAAA,GAAaG,IAEfG,WACJ4D,UAAW,OAoBN,OAjBP3D,EAAAmB,sBACO1B,EAAU,OAET,MAAAmE,EAAQnE,EAASoE,kBAGjB9D,EAAA4D,UAAYC,EAAME,WAAWC,KAG5BH,EAAMI,WAAW,CAAAC,EAAQC,EAAUC,KAEpCP,EAAMQ,aAAaH,KAAYI,gBAAcH,EAASH,KAAMI,EAASJ,QACvEhE,EAAM4D,UAAYO,EAASH,QAE9B,IAGIhE,CACT"}
|
package/dist/svelte/index.js
CHANGED
|
@@ -5,48 +5,58 @@ const pdfContext = $.proxy({ registry: null, isInitializing: true, pluginsReady:
|
|
|
5
5
|
const useRegistry = () => pdfContext;
|
|
6
6
|
function usePlugin(pluginId) {
|
|
7
7
|
const { registry } = pdfContext;
|
|
8
|
+
const state = $.proxy({ plugin: null, isLoading: true, ready: new Promise(() => {
|
|
9
|
+
}) });
|
|
8
10
|
if (registry === null) {
|
|
9
|
-
return
|
|
10
|
-
}) };
|
|
11
|
+
return state;
|
|
11
12
|
}
|
|
12
13
|
const plugin = registry.getPlugin(pluginId);
|
|
13
14
|
if (!plugin) {
|
|
14
15
|
throw new Error(`Plugin ${pluginId} not found`);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
state.plugin = plugin;
|
|
18
|
+
state.isLoading = false;
|
|
19
|
+
state.ready = plugin.ready();
|
|
20
|
+
return state;
|
|
17
21
|
}
|
|
18
22
|
function useCapability(pluginId) {
|
|
19
23
|
const p = usePlugin(pluginId);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
const state = $.proxy({
|
|
25
|
+
provides: null,
|
|
26
|
+
isLoading: true,
|
|
27
|
+
ready: new Promise(() => {
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
$.user_effect(() => {
|
|
31
|
+
if (!p.plugin) {
|
|
32
|
+
state.provides = null;
|
|
33
|
+
state.isLoading = p.isLoading;
|
|
34
|
+
state.ready = p.ready;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!p.plugin.provides) {
|
|
38
|
+
throw new Error(`Plugin ${pluginId} does not provide a capability`);
|
|
39
|
+
}
|
|
40
|
+
state.provides = p.plugin.provides();
|
|
41
|
+
state.isLoading = p.isLoading;
|
|
42
|
+
state.ready = p.ready;
|
|
43
|
+
});
|
|
44
|
+
return state;
|
|
31
45
|
}
|
|
32
46
|
function useCoreState() {
|
|
33
|
-
const
|
|
34
|
-
|
|
47
|
+
const { registry } = useRegistry();
|
|
48
|
+
const state = $.proxy({ coreState: null });
|
|
35
49
|
$.user_effect(() => {
|
|
36
|
-
if (
|
|
37
|
-
const store =
|
|
38
|
-
|
|
50
|
+
if (!registry) return;
|
|
51
|
+
const store = registry.getStore();
|
|
52
|
+
state.coreState = store.getState().core;
|
|
39
53
|
return store.subscribe((action, newState, oldState) => {
|
|
40
54
|
if (store.isCoreAction(action) && !arePropsEqual(newState.core, oldState.core)) {
|
|
41
|
-
|
|
55
|
+
state.coreState = newState.core;
|
|
42
56
|
}
|
|
43
57
|
});
|
|
44
58
|
});
|
|
45
|
-
return
|
|
46
|
-
get coreState() {
|
|
47
|
-
return $.get(coreState);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
59
|
+
return state;
|
|
50
60
|
}
|
|
51
61
|
function NestedWrapper_1($$anchor, $$props) {
|
|
52
62
|
$.push($$props, true);
|
package/dist/svelte/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.svelte.ts","../../src/svelte/hooks/use-capability.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"],"sourcesContent":["import type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const pdfContext = $state<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\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;","import type { BasePlugin } from '@embedpdf/core';\nimport { pdfContext } from './use-registry.svelte.js';\n\ntype PluginState<T extends BasePlugin> = {\n plugin: T | null;\n isLoading: boolean;\n ready: Promise<void>;\n};\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']): PluginState<T> {\n const { registry } = pdfContext;\n if (registry === null) {\n return {\n plugin: null,\n isLoading: true,\n ready: new Promise(() => {})\n };\n }\n\n const plugin = registry.getPlugin<T>(pluginId);\n\n if (!plugin) {\n throw new Error(`Plugin ${pluginId} not found`);\n }\n\n return {\n plugin,\n isLoading: false,\n ready: plugin.ready()\n };\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { usePlugin } from './use-plugin.svelte.js';\n\ntype CapabilityState<T extends BasePlugin> = {\n provides: ReturnType<NonNullable<T['provides']>> | null;\n isLoading: boolean;\n ready: Promise<void>;\n};\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']): CapabilityState<T> {\n const p = usePlugin<T>(pluginId);\n\n if (!p.plugin) {\n return {\n provides: null,\n isLoading: p.isLoading,\n ready: p.ready\n };\n }\n\n if (!p.plugin.provides) {\n throw new Error(`Plugin ${pluginId} does not provide a capability`);\n }\n\n return {\n provides: p.plugin.provides() as ReturnType<NonNullable<T['provides']>>,\n isLoading: p.isLoading,\n ready: p.ready\n };\n}\n","import { type CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry.svelte';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState() {\n const { registry } = $derived(useRegistry());\n let coreState = $state<CoreState | null>(null);\n\n $effect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n coreState = store.getState().core;\n\n // Create a single subscription that handles all core actions\n return store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && !arePropsEqual(newState.core, oldState.core)) {\n coreState = newState.core;\n }\n });\n });\n return {\n get coreState() {\n return 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 /* 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 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 initialize().catch(console.error);\n\n return () => {\n reg.destroy();\n pdfContext.registry = null;\n pdfContext.isInitializing = false;\n pdfContext.pluginsReady = false;\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"],"names":[],"mappings":";;;MAQa,uBACX,UAAU,MACV,gBAAgB,MAChB,cAAc,MAAA,CAAA;AAQH,MAAA,oBAAoB;SCFjB,UAAgC,UAAmC;AACzE,QAAA,EAAA,aAAa;MACjB,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YAGhB,IAAI,eAAe;;QAEvB;AAGM,eAAA,yCAAa;YAGf,IAAI,eAAe;;QAEvB;AAEA,YAAI,eAAe,KAAW,MAAA;eACvB,IAAI,eAAe;AACtB,uBAAW,eAAe;AAAA,UAC5B;AAAA,SACD;AAGD,mBAAW,WAAW;AACtB,mBAAW,iBAAiB;AAAA,MAC7B;AACD,mBAAa,MAAM,QAAQ,KAAK;AAEnB,aAAA,MAAA;AACX,YAAI,QAAO;AACX,mBAAW,WAAW;AACtB,mBAAW,iBAAiB;AAC5B,mBAAW,eAAe;AAAA,MAC3B;AAAA,IACH;AAAA,GACD;;;;;;;;;;;;0DAIsC,UAAU;;;;;;;;;sDAE/B,UAAU;;;;UAHzB,WAAW,gBAAgB,uBAAoB,UAAA,UAAA;AAAA,UAAA,UAAA,WAAA,KAAA;AAAA;;;;AAFpD;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-registry.svelte.ts","../../src/svelte/hooks/use-plugin.svelte.ts","../../src/svelte/hooks/use-capability.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"],"sourcesContent":["import type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: PluginRegistry | null;\n isInitializing: boolean;\n pluginsReady: boolean;\n}\n\nexport const pdfContext = $state<PDFContextState>({\n registry: null,\n isInitializing: true,\n pluginsReady: false,\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;","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 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 { type CoreState, arePropsEqual } from '@embedpdf/core';\nimport { useRegistry } from './use-registry.svelte';\n\n/**\n * Hook that provides access to the current core state\n * and re-renders the component only when the core state changes\n */\nexport function useCoreState() {\n const { registry } = useRegistry();\n\n const state = $state({\n coreState: null as CoreState | null,\n });\n\n $effect(() => {\n if (!registry) return;\n\n const store = registry.getStore();\n\n // Get initial core state\n state.coreState = store.getState().core;\n\n // Create a single subscription that handles all core actions\n return store.subscribe((action, newState, oldState) => {\n // Only update if it's a core action and the core state changed\n if (store.isCoreAction(action) && !arePropsEqual(newState.core, oldState.core)) {\n state.coreState = newState.core;\n }\n });\n });\n\n return state;\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 /* 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 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 initialize().catch(console.error);\n\n return () => {\n reg.destroy();\n pdfContext.registry = null;\n pdfContext.isInitializing = false;\n pdfContext.pluginsReady = false;\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"],"names":[],"mappings":";;;MAQa,uBACX,UAAU,MACV,gBAAgB,MAChB,cAAc,MAAA,CAAA;AAQH,MAAA,oBAAoB;SCRjB,UAAgC,UAAmB;AACzD,Q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;YAC3B,MAAG,IAAO,eAAc,QAAA,QAAA,EAAW,QAAM,QAAA,QAAA;AAC/C,UAAI,oBAAmB,QAAA,OAAA;AAEjB,YAAA,aAAyB,YAAA;AACvB,cAAA,IAAI,WAAU;YAGhB,IAAI,eAAe;;QAEvB;AAGM,eAAA,yCAAa;YAGf,IAAI,eAAe;;QAEvB;AAEA,YAAI,eAAe,KAAW,MAAA;eACvB,IAAI,eAAe;AACtB,uBAAW,eAAe;AAAA,UAC5B;AAAA,SACD;AAGD,mBAAW,WAAW;AACtB,mBAAW,iBAAiB;AAAA,MAC7B;AACD,mBAAa,MAAM,QAAQ,KAAK;AAEnB,aAAA,MAAA;AACX,YAAI,QAAO;AACX,mBAAW,WAAW;AACtB,mBAAW,iBAAiB;AAC5B,mBAAW,eAAe;AAAA,MAC3B;AAAA,IACH;AAAA,GACD;;;;;;;;;;;;0DAIsC,UAAU;;;;;;;;;sDAE/B,UAAU;;;;UAHzB,WAAW,gBAAgB,uBAAoB,UAAA,UAAA;AAAA,UAAA,UAAA,WAAA,KAAA;AAAA;;;;AAFpD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@embedpdf/build": "1.1.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@embedpdf/engines": "1.4.
|
|
44
|
-
"@embedpdf/models": "1.4.
|
|
43
|
+
"@embedpdf/engines": "1.4.1",
|
|
44
|
+
"@embedpdf/models": "1.4.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"preact": "^10.26.4",
|