@embedpdf/core 1.3.15 → 1.4.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.
Files changed (42) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +84 -23
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/registry/plugin-registry.d.ts +2 -2
  6. package/dist/lib/store/store.d.ts +2 -1
  7. package/dist/lib/types/plugin.d.ts +1 -0
  8. package/dist/preact/index.cjs.map +1 -1
  9. package/dist/preact/index.js.map +1 -1
  10. package/dist/react/index.cjs.map +1 -1
  11. package/dist/react/index.js.map +1 -1
  12. package/dist/shared/components/auto-mount.d.ts +8 -0
  13. package/dist/shared/components/embed-pdf.d.ts +33 -0
  14. package/dist/shared/components/index.d.ts +1 -0
  15. package/dist/shared/context.d.ts +7 -0
  16. package/dist/shared/hooks/index.d.ts +5 -0
  17. package/dist/shared/hooks/use-capability.d.ts +16 -0
  18. package/dist/shared/hooks/use-core-state.d.ts +6 -0
  19. package/dist/shared/hooks/use-plugin.d.ts +16 -0
  20. package/dist/shared/hooks/use-registry.d.ts +6 -0
  21. package/dist/shared/hooks/use-store-state.d.ts +6 -0
  22. package/dist/shared/index.d.ts +3 -0
  23. package/dist/shared-preact/components/embed-pdf.d.ts +3 -3
  24. package/dist/shared-react/components/embed-pdf.d.ts +3 -3
  25. package/dist/svelte/components/AutoMount.svelte.d.ts +9 -0
  26. package/dist/svelte/components/EmbedPDF.svelte.d.ts +36 -0
  27. package/dist/svelte/components/NestedWrapper.svelte.d.ts +9 -0
  28. package/dist/svelte/components/index.d.ts +1 -0
  29. package/dist/svelte/hooks/index.d.ts +4 -0
  30. package/dist/svelte/hooks/use-capability.svelte.d.ts +16 -0
  31. package/dist/svelte/hooks/use-core-state.svelte.d.ts +8 -0
  32. package/dist/svelte/hooks/use-plugin.svelte.d.ts +16 -0
  33. package/dist/svelte/hooks/use-registry.svelte.d.ts +12 -0
  34. package/dist/svelte/index.cjs +2 -0
  35. package/dist/svelte/index.cjs.map +1 -0
  36. package/dist/svelte/index.d.ts +2 -0
  37. package/dist/svelte/index.js +248 -0
  38. package/dist/svelte/index.js.map +1 -0
  39. package/dist/vue/components/embed-pdf.vue.d.ts +3 -2
  40. package/dist/vue/index.cjs.map +1 -1
  41. package/dist/vue/index.js.map +1 -1
  42. package/package.json +13 -5
@@ -0,0 +1,16 @@
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
+ /**
8
+ * Hook to access a plugin.
9
+ * @param pluginId The ID of the plugin to access
10
+ * @returns The plugin or null during initialization
11
+ * @example
12
+ * // Get zoom plugin
13
+ * const zoom = usePlugin<ZoomPlugin>(ZoomPlugin.id);
14
+ */
15
+ export declare function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T>;
16
+ export {};
@@ -0,0 +1,12 @@
1
+ import { PluginRegistry } from '../../lib/index.ts';
2
+ export interface PDFContextState {
3
+ registry: PluginRegistry | null;
4
+ isInitializing: boolean;
5
+ pluginsReady: boolean;
6
+ }
7
+ export declare const pdfContext: PDFContextState;
8
+ /**
9
+ * Hook to access the PDF registry context.
10
+ * @returns The PDF registry or null during initialization
11
+ */
12
+ export declare const useRegistry: () => PDFContextState;
@@ -0,0 +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;if(null===t)return{plugin:null,isLoading:!0,ready:new Promise((()=>{}))};const n=t.getPlugin(e);if(!n)throw new Error(`Plugin ${e} not found`);return{plugin:n,isLoading:!1,ready:n.ready()}}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);if(!t.plugin)return{provides:null,isLoading:t.isLoading,ready:t.ready};if(!t.plugin.provides)throw new Error(`Plugin ${e} does not provide a capability`);return{provides:t.plugin.provides(),isLoading:t.isLoading,ready:t.ready}},exports.useCoreState=function(){const e=r.derived(o),n=r.derived((()=>r.get(e).registry));let i=r.state(null);return r.user_effect((()=>{if(!r.get(n))return;const e=r.get(n).getStore();return r.set(i,e.getState().core,!0),e.subscribe(((n,o,s)=>{e.isCoreAction(n)&&!t.arePropsEqual(o.core,s.core)&&r.set(i,o.core,!0)}))})),{get coreState(){return r.get(i)}}},exports.usePlugin=s,exports.useRegistry=o;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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,WA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I4B,aAGN5B,EAAI6B,sBAKW,MAAbR,OAAa,EAAAA,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"}
@@ -0,0 +1,2 @@
1
+ export * from './hooks';
2
+ export { EmbedPDF } from './components';
@@ -0,0 +1,248 @@
1
+ import * as $ from "svelte/internal/client";
2
+ import { arePropsEqual, hasAutoMountElements, PluginRegistry } from "@embedpdf/core";
3
+ import "svelte/internal/disclose-version";
4
+ const pdfContext = $.proxy({ registry: null, isInitializing: true, pluginsReady: false });
5
+ const useRegistry = () => pdfContext;
6
+ function usePlugin(pluginId) {
7
+ const { registry } = pdfContext;
8
+ if (registry === null) {
9
+ return { plugin: null, isLoading: true, ready: new Promise(() => {
10
+ }) };
11
+ }
12
+ const plugin = registry.getPlugin(pluginId);
13
+ if (!plugin) {
14
+ throw new Error(`Plugin ${pluginId} not found`);
15
+ }
16
+ return { plugin, isLoading: false, ready: plugin.ready() };
17
+ }
18
+ function useCapability(pluginId) {
19
+ const p = usePlugin(pluginId);
20
+ if (!p.plugin) {
21
+ return { provides: null, isLoading: p.isLoading, ready: p.ready };
22
+ }
23
+ if (!p.plugin.provides) {
24
+ throw new Error(`Plugin ${pluginId} does not provide a capability`);
25
+ }
26
+ return {
27
+ provides: p.plugin.provides(),
28
+ isLoading: p.isLoading,
29
+ ready: p.ready
30
+ };
31
+ }
32
+ function useCoreState() {
33
+ const $$d = $.derived(useRegistry), registry = $.derived(() => $.get($$d).registry);
34
+ let coreState = $.state(null);
35
+ $.user_effect(() => {
36
+ if (!$.get(registry)) return;
37
+ const store = $.get(registry).getStore();
38
+ $.set(coreState, store.getState().core, true);
39
+ return store.subscribe((action, newState, oldState) => {
40
+ if (store.isCoreAction(action) && !arePropsEqual(newState.core, oldState.core)) {
41
+ $.set(coreState, newState.core, true);
42
+ }
43
+ });
44
+ });
45
+ return {
46
+ get coreState() {
47
+ return $.get(coreState);
48
+ }
49
+ };
50
+ }
51
+ function NestedWrapper_1($$anchor, $$props) {
52
+ $.push($$props, true);
53
+ var fragment = $.comment();
54
+ var node = $.first_child(fragment);
55
+ {
56
+ var consequent = ($$anchor2) => {
57
+ const Wrapper = $.derived(() => $$props.wrappers[0]);
58
+ var fragment_1 = $.comment();
59
+ var node_1 = $.first_child(fragment_1);
60
+ $.component(node_1, () => $.get(Wrapper), ($$anchor3, Wrapper_1) => {
61
+ Wrapper_1($$anchor3, {
62
+ children: ($$anchor4, $$slotProps) => {
63
+ {
64
+ let $0 = $.derived(() => $$props.wrappers.slice(1));
65
+ NestedWrapper_1($$anchor4, {
66
+ get wrappers() {
67
+ return $.get($0);
68
+ },
69
+ children: ($$anchor5, $$slotProps2) => {
70
+ var fragment_3 = $.comment();
71
+ var node_2 = $.first_child(fragment_3);
72
+ $.snippet(node_2, () => $$props.children ?? $.noop);
73
+ $.append($$anchor5, fragment_3);
74
+ },
75
+ $$slots: { default: true }
76
+ });
77
+ }
78
+ },
79
+ $$slots: { default: true }
80
+ });
81
+ });
82
+ $.append($$anchor2, fragment_1);
83
+ };
84
+ var alternate = ($$anchor2) => {
85
+ const Wrapper = $.derived(() => $$props.wrappers[0]);
86
+ var fragment_4 = $.comment();
87
+ var node_3 = $.first_child(fragment_4);
88
+ $.component(node_3, () => $.get(Wrapper), ($$anchor3, Wrapper_2) => {
89
+ Wrapper_2($$anchor3, {
90
+ children: ($$anchor4, $$slotProps) => {
91
+ var fragment_5 = $.comment();
92
+ var node_4 = $.first_child(fragment_5);
93
+ $.snippet(node_4, () => $$props.children ?? $.noop);
94
+ $.append($$anchor4, fragment_5);
95
+ },
96
+ $$slots: { default: true }
97
+ });
98
+ });
99
+ $.append($$anchor2, fragment_4);
100
+ };
101
+ $.if(node, ($$render) => {
102
+ if ($$props.wrappers.length > 1) $$render(consequent);
103
+ else $$render(alternate, false);
104
+ });
105
+ }
106
+ $.append($$anchor, fragment);
107
+ $.pop();
108
+ }
109
+ var root = $.from_html(`<!> <!>`, 1);
110
+ function AutoMount($$anchor, $$props) {
111
+ $.push($$props, true);
112
+ let utilities = $.state($.proxy([]));
113
+ let wrappers = $.state($.proxy([]));
114
+ $.user_effect(() => {
115
+ var _a;
116
+ const nextUtilities = [];
117
+ const nextWrappers = [];
118
+ for (const reg of $$props.plugins) {
119
+ const pkg = reg.package;
120
+ if (hasAutoMountElements(pkg)) {
121
+ const elements = ((_a = pkg.autoMountElements) == null ? void 0 : _a.call(pkg)) ?? [];
122
+ for (const element of elements) {
123
+ if (element.type === "utility") {
124
+ nextUtilities.push(element.component);
125
+ } else if (element.type === "wrapper") {
126
+ nextWrappers.push(element.component);
127
+ }
128
+ }
129
+ }
130
+ }
131
+ $.set(utilities, nextUtilities, true);
132
+ $.set(wrappers, nextWrappers, true);
133
+ });
134
+ var fragment = root();
135
+ var node = $.first_child(fragment);
136
+ {
137
+ var consequent = ($$anchor2) => {
138
+ NestedWrapper_1($$anchor2, {
139
+ get wrappers() {
140
+ return $.get(wrappers);
141
+ },
142
+ get children() {
143
+ return $$props.children;
144
+ }
145
+ });
146
+ };
147
+ var alternate = ($$anchor2) => {
148
+ var fragment_2 = $.comment();
149
+ var node_1 = $.first_child(fragment_2);
150
+ $.snippet(node_1, () => $$props.children ?? $.noop);
151
+ $.append($$anchor2, fragment_2);
152
+ };
153
+ $.if(node, ($$render) => {
154
+ if ($.get(wrappers).length > 0) $$render(consequent);
155
+ else $$render(alternate, false);
156
+ });
157
+ }
158
+ var node_2 = $.sibling(node, 2);
159
+ $.each(node_2, 19, () => $.get(utilities), (Utility, i) => `utility-${i}`, ($$anchor2, Utility) => {
160
+ var fragment_3 = $.comment();
161
+ var node_3 = $.first_child(fragment_3);
162
+ $.component(node_3, () => $.get(Utility), ($$anchor3, Utility_1) => {
163
+ Utility_1($$anchor3, {});
164
+ });
165
+ $.append($$anchor2, fragment_3);
166
+ });
167
+ $.append($$anchor, fragment);
168
+ $.pop();
169
+ }
170
+ function EmbedPDF($$anchor, $$props) {
171
+ $.push($$props, true);
172
+ let autoMountDomElements = $.prop($$props, "autoMountDomElements", 3, true);
173
+ let latestInit = $$props.onInitialized;
174
+ $.user_effect(() => {
175
+ if ($$props.onInitialized) {
176
+ latestInit = $$props.onInitialized;
177
+ }
178
+ });
179
+ $.user_effect(() => {
180
+ if ($$props.engine || $$props.engine && $$props.plugins) {
181
+ const reg = new PluginRegistry($$props.engine, { logger: $$props.logger });
182
+ reg.registerPluginBatch($$props.plugins);
183
+ const initialize = async () => {
184
+ await reg.initialize();
185
+ if (reg.isDestroyed()) {
186
+ return;
187
+ }
188
+ await (latestInit == null ? void 0 : latestInit(reg));
189
+ if (reg.isDestroyed()) {
190
+ return;
191
+ }
192
+ reg.pluginsReady().then(() => {
193
+ if (!reg.isDestroyed()) {
194
+ pdfContext.pluginsReady = true;
195
+ }
196
+ });
197
+ pdfContext.registry = reg;
198
+ pdfContext.isInitializing = false;
199
+ };
200
+ initialize().catch(console.error);
201
+ return () => {
202
+ reg.destroy();
203
+ pdfContext.registry = null;
204
+ pdfContext.isInitializing = false;
205
+ pdfContext.pluginsReady = false;
206
+ };
207
+ }
208
+ });
209
+ var fragment = $.comment();
210
+ var node = $.first_child(fragment);
211
+ {
212
+ var consequent = ($$anchor2) => {
213
+ AutoMount($$anchor2, {
214
+ get plugins() {
215
+ return $$props.plugins;
216
+ },
217
+ children: ($$anchor3, $$slotProps) => {
218
+ var fragment_2 = $.comment();
219
+ var node_1 = $.first_child(fragment_2);
220
+ $.snippet(node_1, () => $$props.children, () => pdfContext);
221
+ $.append($$anchor3, fragment_2);
222
+ },
223
+ $$slots: { default: true }
224
+ });
225
+ };
226
+ var alternate = ($$anchor2) => {
227
+ var fragment_3 = $.comment();
228
+ var node_2 = $.first_child(fragment_3);
229
+ $.snippet(node_2, () => $$props.children, () => pdfContext);
230
+ $.append($$anchor2, fragment_3);
231
+ };
232
+ $.if(node, ($$render) => {
233
+ if (pdfContext.pluginsReady && autoMountDomElements()) $$render(consequent);
234
+ else $$render(alternate, false);
235
+ });
236
+ }
237
+ $.append($$anchor, fragment);
238
+ $.pop();
239
+ }
240
+ export {
241
+ EmbedPDF,
242
+ pdfContext,
243
+ useCapability,
244
+ useCoreState,
245
+ usePlugin,
246
+ useRegistry
247
+ };
248
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,aAAa,MAAM;AAEnB,WAAA,EAAA,QAAQ,MACR,WAAW,MACX,OAAW,IAAA,QAAc,MAAA;AAAA,IAAA,CAAE,EAAA;AAAA;AAIzB,QAAA,SAAS,SAAS,UAAa,QAAQ;AAExC,MAAA,CAAA,QAAQ;AACD,UAAA,IAAA,gBAAgB,QAAQ,YAAA;AAAA;WAIlC,QACA,WAAW,OACX,OAAO,OAAO,QAAM;AAExB;SCrBgB,cAAoC,UAAuC;QACnF,IAAI,UAAa,QAAQ;OAE1B,EAAE,QAAQ;AAEX,WAAA,EAAA,UAAU,MACV,WAAW,EAAE,WACb,OAAO,EAAE,MAAA;AAAA;AAIR,MAAA,CAAA,EAAE,OAAO,UAAU;AACZ,UAAA,IAAA,gBAAgB,QAAQ,gCAAA;AAAA;;IAIlC,UAAU,EAAE,OAAO,SAAS;AAAA,IAC5B,WAAW,EAAE;AAAA,IACb,OAAO,EAAE;AAAA;AAEb;AC9BgB,SAAA,eAAe;wBACC,cAAtB,sCAA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chRegistrations } from '../../lib/index.ts';
2
2
  import { Logger, PdfEngine } from '@embedpdf/models';
3
+ export type { PluginBatchRegistrations };
3
4
  type __VLS_Props = {
4
5
  engine: PdfEngine;
5
6
  logger?: Logger;
6
- plugins: PluginBatchRegistration<any, any>[];
7
+ plugins: PluginBatchRegistrations;
7
8
  onInitialized?: (registry: PluginRegistry) => Promise<void>;
8
9
  autoMountDomElements?: boolean;
9
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/components/nested-wrapper.vue","../../src/vue/components/auto-mount.vue","../../src/vue/components/embed-pdf.vue","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-core-state.ts","../../src/vue/composables/use-store-state.ts"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\n}\n\nexport const pdfKey: InjectionKey<PDFContextState> = Symbol('pdfKey');\n","import { inject } from 'vue';\nimport { pdfKey } from '../context';\n\nexport function useRegistry() {\n const ctx = inject(pdfKey);\n if (!ctx) throw new Error('useRegistry must be used inside <EmbedPDF>');\n return ctx;\n}\n","import { shallowRef, ref, onMounted, watch, type ShallowRef, type Ref } from 'vue';\nimport type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport interface PluginState<T extends BasePlugin> {\n plugin: ShallowRef<T | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n const plugin = shallowRef(null) as ShallowRef<T | null>;\n\n const isLoading = ref(true);\n const ready = ref<Promise<void>>(new Promise(() => {}));\n\n const load = () => {\n if (!registry.value) return;\n\n const p = registry.value.getPlugin<T>(pluginId);\n if (!p) throw new Error(`Plugin ${pluginId} not found`);\n\n plugin.value = p;\n isLoading.value = false;\n ready.value = p.ready?.() ?? Promise.resolve();\n };\n\n onMounted(load);\n watch(registry, load);\n\n return { plugin, isLoading, ready };\n}\n","<script setup lang=\"ts\">\ndefineProps<{\n wrappers: any[];\n}>();\n</script>\n\n<template>\n <component :is=\"wrappers[0]\">\n <NestedWrapper v-if=\"wrappers.length > 1\" :wrappers=\"wrappers.slice(1)\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n </component>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\nimport NestedWrapper from './nested-wrapper.vue';\n\nconst props = defineProps<{\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n}>();\n\nconst elements = computed(() => {\n const utilities: any[] = [];\n const wrappers: any[] = [];\n\n for (const reg of props.plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements() || [];\n\n for (const element of elements) {\n if (element.type === 'utility') {\n utilities.push(element.component);\n } else if (element.type === 'wrapper') {\n wrappers.push(element.component);\n }\n }\n }\n }\n\n return { utilities, wrappers };\n});\n</script>\n\n<template>\n <NestedWrapper v-if=\"elements.wrappers.length > 0\" :wrappers=\"elements.wrappers\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n\n <component\n v-for=\"(utility, index) in elements.utilities\"\n :key=\"`utility-${index}`\"\n :is=\"utility\"\n />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistration } from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\nimport AutoMount from './auto-mount.vue';\n\nconst props = withDefaults(\n defineProps<{\n engine: PdfEngine;\n logger?: Logger;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n autoMountDomElements?: boolean;\n }>(),\n {\n autoMountDomElements: true,\n },\n);\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });\n\nonMounted(async () => {\n const reg = new PluginRegistry(props.engine, { logger: props.logger });\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n await props.onInitialized?.(reg);\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => (pluginsOk.value = true));\n});\n\nonBeforeUnmount(() => registry.value?.destroy());\n</script>\n\n<template>\n <AutoMount v-if=\"pluginsOk && autoMountDomElements\" :plugins=\"plugins\">\n <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n </AutoMount>\n\n <!-- No auto-mount or not ready yet -->\n <slot v-else :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n</template>\n","import type { BasePlugin } from '@embedpdf/core';\nimport { computed, type Ref } from 'vue';\nimport { usePlugin } from './use-plugin';\n\nexport interface CapabilityState<C> {\n provides: Ref<C | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\n/**\n * Access the public capability exposed by a plugin.\n *\n * @example\n * const { provides: zoom } = useCapability<ZoomPlugin>(ZoomPlugin.id);\n * zoom.value?.zoomIn();\n */\nexport function useCapability<T extends BasePlugin>(\n pluginId: T['id'],\n): CapabilityState<ReturnType<NonNullable<T['provides']>>> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n const provides = computed(() => {\n if (!plugin.value) return null;\n if (!plugin.value.provides) {\n throw new Error(`Plugin ${pluginId} does not implement provides()`);\n }\n return plugin.value.provides() as ReturnType<NonNullable<T['provides']>>;\n });\n\n return { provides, isLoading, ready };\n}\n","import { ref, onMounted, onBeforeUnmount } from 'vue';\nimport { arePropsEqual, type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport function useCoreState() {\n const { registry } = useRegistry();\n const core = ref<CoreState>();\n\n onMounted(() => {\n const store = registry.value!.getStore();\n core.value = store.getState().core;\n\n const unsub = store.subscribe((action, newSt, oldSt) => {\n if (store.isCoreAction(action) && !arePropsEqual(newSt.core, oldSt.core)) {\n core.value = newSt.core;\n }\n });\n onBeforeUnmount(unsub);\n });\n\n return core;\n}\n","import { ref, onMounted, onBeforeUnmount, watch } from 'vue';\nimport type { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Reactive getter for the *entire* global store.\n * Re‑emits whenever any slice changes.\n *\n * @example\n * const state = useStoreState(); // Ref<StoreState<CoreState>>\n * console.log(state.value.core.scale);\n */\nexport function useStoreState<T = CoreState>() {\n const { registry } = useRegistry();\n const state = ref<StoreState<T>>();\n\n function attach() {\n if (!registry.value) return () => {};\n\n // initial snapshot\n state.value = registry.value.getStore().getState() as StoreState<T>;\n\n // live updates\n return registry.value\n .getStore()\n .subscribe((_action, newState) => (state.value = newState as StoreState<T>));\n }\n\n /* attach now and re‑attach if registry instance ever changes */\n let unsubscribe = attach();\n watch(registry, () => {\n unsubscribe?.();\n unsubscribe = attach();\n });\n\n onBeforeUnmount(() => unsubscribe?.());\n\n return state;\n}\n"],"names":["pdfKey","Symbol","useRegistry","ctx","inject","Error","usePlugin","pluginId","registry","plugin","shallowRef","isLoading","ref","ready","Promise","load","value","p","getPlugin","_a","call","resolve","onMounted","vue","watch","_openBlock","openBlock","_createBlock","_resolveDynamicComponent","resolveDynamicComponent","wrappers","length","_component_NestedWrapper","slice","_renderSlot","_ctx","$slots","renderSlot","key","props","__props","elements","computed","utilities","reg","plugins","pkg","package","hasAutoMountElements","autoMountElements","element","type","push","component","NestedWrapper","_createElementBlock","createElementBlock","_Fragment","utility","index","isInit","pluginsOk","provide","isInitializing","pluginsReady","async","PluginRegistry","engine","logger","registerPluginBatch","initialize","onInitialized","then","onBeforeUnmount","destroy","autoMountDomElements","AutoMount","provides","core","store","getStore","core$1","getState","unsub","subscribe","action","newSt","oldSt","isCoreAction","arePropsEqual","state","attach","_action","newState","unsubscribe"],"mappings":"mIASaA,EAAwCC,OAAO,UCNrD,SAASC,IACR,MAAAC,EAAMC,SAAOJ,GACnB,IAAKG,EAAW,MAAA,IAAIE,MAAM,8CACnB,OAAAF,CACT,CCGO,SAASG,EAAgCC,GACxC,MAAAC,SAAEA,GAAaN,IAEfO,EAASC,aAAW,MAEpBC,EAAYC,OAAI,GAChBC,EAAQD,EAAAA,IAAmB,IAAIE,SAAQ,UAEvCC,EAAO,WACP,IAACP,EAASQ,MAAO,OAErB,MAAMC,EAAIT,EAASQ,MAAME,UAAaX,GACtC,IAAKU,EAAG,MAAM,IAAIZ,MAAM,UAAUE,eAElCE,EAAOO,MAAQC,EACfN,EAAUK,OAAQ,EAClBH,EAAMG,OAAQ,OAAAG,EAAAF,EAAEJ,YAAF,EAAAM,EAAAC,KAAAH,KAAeH,QAAQO,SAAQ,EAMxC,OAHPC,EAAAA,UAAUP,GACVQ,EAAAC,MAAMhB,EAAUO,GAET,CAAEN,SAAQE,YAAWE,QAC9B,wIC1BE,OAAAY,EAAAC,YAAAC,EAAAA,YAKYC,EAAAC,wBALIC,EAAQA,SAAA,IAAA,KAAA,oBACtB,IAEgB,CAFKA,EAAAA,SAASC,OAAM,iBAApCJ,cAEgBK,EAAA,OAF2BF,SAAUA,EAAQA,SAACG,MAAK,wBACjE,IAAQ,CAARC,aAAQC,EAAAC,OAAA,oCAEVF,EAAeG,WAAAF,EAAAC,OAAA,UAAA,CAAAE,IAAA,qFCNnB,MAAMC,EAAQC,EAIRC,EAAWC,EAAAA,UAAS,KACxB,MAAMC,EAAmB,GACnBb,EAAkB,GAEb,IAAA,MAAAc,KAAOL,EAAMM,QAAS,CAC/B,MAAMC,EAAMF,EAAIG,QACZC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,EAAcH,GAAO,IAGPpE,EAAAkD,iBAAA,IAAqB,MAAfqB,OAAe,EAAAA,MAE9BJ,CACT"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/components/nested-wrapper.vue","../../src/vue/components/auto-mount.vue","../../src/vue/components/embed-pdf.vue","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-core-state.ts","../../src/vue/composables/use-store-state.ts"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\n}\n\nexport const pdfKey: InjectionKey<PDFContextState> = Symbol('pdfKey');\n","import { inject } from 'vue';\nimport { pdfKey } from '../context';\n\nexport function useRegistry() {\n const ctx = inject(pdfKey);\n if (!ctx) throw new Error('useRegistry must be used inside <EmbedPDF>');\n return ctx;\n}\n","import { shallowRef, ref, onMounted, watch, type ShallowRef, type Ref } from 'vue';\nimport type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport interface PluginState<T extends BasePlugin> {\n plugin: ShallowRef<T | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n const plugin = shallowRef(null) as ShallowRef<T | null>;\n\n const isLoading = ref(true);\n const ready = ref<Promise<void>>(new Promise(() => {}));\n\n const load = () => {\n if (!registry.value) return;\n\n const p = registry.value.getPlugin<T>(pluginId);\n if (!p) throw new Error(`Plugin ${pluginId} not found`);\n\n plugin.value = p;\n isLoading.value = false;\n ready.value = p.ready?.() ?? Promise.resolve();\n };\n\n onMounted(load);\n watch(registry, load);\n\n return { plugin, isLoading, ready };\n}\n","<script setup lang=\"ts\">\ndefineProps<{\n wrappers: any[];\n}>();\n</script>\n\n<template>\n <component :is=\"wrappers[0]\">\n <NestedWrapper v-if=\"wrappers.length > 1\" :wrappers=\"wrappers.slice(1)\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n </component>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\nimport NestedWrapper from './nested-wrapper.vue';\n\nconst props = defineProps<{\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n}>();\n\nconst elements = computed(() => {\n const utilities: any[] = [];\n const wrappers: any[] = [];\n\n for (const reg of props.plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements() || [];\n\n for (const element of elements) {\n if (element.type === 'utility') {\n utilities.push(element.component);\n } else if (element.type === 'wrapper') {\n wrappers.push(element.component);\n }\n }\n }\n }\n\n return { utilities, wrappers };\n});\n</script>\n\n<template>\n <NestedWrapper v-if=\"elements.wrappers.length > 0\" :wrappers=\"elements.wrappers\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n\n <component\n v-for=\"(utility, index) in elements.utilities\"\n :key=\"`utility-${index}`\"\n :is=\"utility\"\n />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistrations } from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\nimport AutoMount from './auto-mount.vue';\n\nexport type { PluginBatchRegistrations };\n\nconst props = withDefaults(\n defineProps<{\n engine: PdfEngine;\n logger?: Logger;\n plugins: PluginBatchRegistrations;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n autoMountDomElements?: boolean;\n }>(),\n {\n autoMountDomElements: true,\n },\n);\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });\n\nonMounted(async () => {\n const reg = new PluginRegistry(props.engine, { logger: props.logger });\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n await props.onInitialized?.(reg);\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => (pluginsOk.value = true));\n});\n\nonBeforeUnmount(() => registry.value?.destroy());\n</script>\n\n<template>\n <AutoMount v-if=\"pluginsOk && autoMountDomElements\" :plugins=\"plugins\">\n <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n </AutoMount>\n\n <!-- No auto-mount or not ready yet -->\n <slot v-else :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n</template>\n","import type { BasePlugin } from '@embedpdf/core';\nimport { computed, type Ref } from 'vue';\nimport { usePlugin } from './use-plugin';\n\nexport interface CapabilityState<C> {\n provides: Ref<C | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\n/**\n * Access the public capability exposed by a plugin.\n *\n * @example\n * const { provides: zoom } = useCapability<ZoomPlugin>(ZoomPlugin.id);\n * zoom.value?.zoomIn();\n */\nexport function useCapability<T extends BasePlugin>(\n pluginId: T['id'],\n): CapabilityState<ReturnType<NonNullable<T['provides']>>> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n const provides = computed(() => {\n if (!plugin.value) return null;\n if (!plugin.value.provides) {\n throw new Error(`Plugin ${pluginId} does not implement provides()`);\n }\n return plugin.value.provides() as ReturnType<NonNullable<T['provides']>>;\n });\n\n return { provides, isLoading, ready };\n}\n","import { ref, onMounted, onBeforeUnmount } from 'vue';\nimport { arePropsEqual, type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport function useCoreState() {\n const { registry } = useRegistry();\n const core = ref<CoreState>();\n\n onMounted(() => {\n const store = registry.value!.getStore();\n core.value = store.getState().core;\n\n const unsub = store.subscribe((action, newSt, oldSt) => {\n if (store.isCoreAction(action) && !arePropsEqual(newSt.core, oldSt.core)) {\n core.value = newSt.core;\n }\n });\n onBeforeUnmount(unsub);\n });\n\n return core;\n}\n","import { ref, onMounted, onBeforeUnmount, watch } from 'vue';\nimport type { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Reactive getter for the *entire* global store.\n * Re‑emits whenever any slice changes.\n *\n * @example\n * const state = useStoreState(); // Ref<StoreState<CoreState>>\n * console.log(state.value.core.scale);\n */\nexport function useStoreState<T = CoreState>() {\n const { registry } = useRegistry();\n const state = ref<StoreState<T>>();\n\n function attach() {\n if (!registry.value) return () => {};\n\n // initial snapshot\n state.value = registry.value.getStore().getState() as StoreState<T>;\n\n // live updates\n return registry.value\n .getStore()\n .subscribe((_action, newState) => (state.value = newState as StoreState<T>));\n }\n\n /* attach now and re‑attach if registry instance ever changes */\n let unsubscribe = attach();\n watch(registry, () => {\n unsubscribe?.();\n unsubscribe = attach();\n });\n\n onBeforeUnmount(() => unsubscribe?.());\n\n return state;\n}\n"],"names":["pdfKey","Symbol","useRegistry","ctx","inject","Error","usePlugin","pluginId","registry","plugin","shallowRef","isLoading","ref","ready","Promise","load","value","p","getPlugin","_a","call","resolve","onMounted","vue","watch","_openBlock","openBlock","_createBlock","_resolveDynamicComponent","resolveDynamicComponent","wrappers","length","_component_NestedWrapper","slice","_renderSlot","_ctx","$slots","renderSlot","key","props","__props","elements","computed","utilities","reg","plugins","pkg","package","hasAutoMountElements","autoMountElements","element","type","push","component","NestedWrapper","_createElementBlock","createElementBlock","_Fragment","utility","index","isInit","pluginsOk","provide","isInitializing","pluginsReady","async","PluginRegistry","engine","logger","registerPluginBatch","initialize","onInitialized","then","onBeforeUnmount","destroy","autoMountDomElements","AutoMount","provides","core","store","getStore","core$1","getState","unsub","subscribe","action","newSt","oldSt","isCoreAction","arePropsEqual","state","attach","_action","newState","unsubscribe"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EAAAA,WAAuFC,EAAAC,OAAA,UAAA,OAAzE5B,SAAUA,EAAQQ,MAAG+C,eAAgBH,EAAM5C,MAAGgD,aAAcH,EAAS7C,oDCnC9E,SACLT,GAEA,MAAME,OAAEA,EAAQE,UAAAA,EAAAE,MAAWA,GAAUP,EAAaC,GAU3C,MAAA,CAAEsE,SARQnC,EAAAA,UAAS,KACpB,IAACjC,EAAOO,MAAc,OAAA,KACtB,IAACP,EAAOO,MAAM6D,SAChB,MAAM,IAAIxE,MAAM,UAAUE,mCAErB,OAAAE,EAAOO,MAAM6D,UAAS,IAGZlE,YAAWE,QAChC,uBC3BO,WACC,MAAAL,SAAEA,GAAaN,IACf4E,EAAOlE,EAAAA,MAcNkE,OAZPxD,EAAAA,WAAU,KACF,MAAAyD,EAAQvE,EAASQ,MAAOgE,WACzBC,EAAAjE,MAAQ+D,EAAMG,WAAWJ,KAE9B,MAAMK,EAAQJ,EAAMK,WAAU,CAACC,EAAQC,EAAOC,KACxCR,EAAMS,aAAaH,KAAYI,gBAAcH,EAAMR,KAAMS,EAAMT,QACjEA,EAAK9D,MAAQsE,EAAMR,KAAA,IAGvBL,EAAAA,gBAAgBU,EAAK,IAGhBL,CACT,kECTO,WACC,MAAAtE,SAAEA,GAAaN,IACfwF,EAAQ9E,EAAAA,MAEd,SAAS+E,IACP,OAAKnF,EAASQ,OAGd0E,EAAM1E,MAAQR,EAASQ,MAAMgE,WAAWE,WAGjC1E,EAASQ,MACbgE,WACAI,WAAU,CAACQ,EAASC,IAAcH,EAAM1E,MAAQ6E,KARvB,MAQiD,CAI/E,IAAIC,EAAcH,IAQX,OAPPpE,EAAAC,MAAMhB,GAAU,KACA,MAAAsF,GAAAA,IACdA,EAAcH,GAAO,IAGPpE,EAAAkD,iBAAA,IAAqB,MAAfqB,OAAe,EAAAA,MAE9BJ,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-core-state.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-store-state.ts","../../src/vue/components/nested-wrapper.vue","../../src/vue/components/auto-mount.vue","../../src/vue/components/embed-pdf.vue"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\n}\n\nexport const pdfKey: InjectionKey<PDFContextState> = Symbol('pdfKey');\n","import { inject } from 'vue';\nimport { pdfKey } from '../context';\n\nexport function useRegistry() {\n const ctx = inject(pdfKey);\n if (!ctx) throw new Error('useRegistry must be used inside <EmbedPDF>');\n return ctx;\n}\n","import { ref, onMounted, onBeforeUnmount } from 'vue';\nimport { arePropsEqual, type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport function useCoreState() {\n const { registry } = useRegistry();\n const core = ref<CoreState>();\n\n onMounted(() => {\n const store = registry.value!.getStore();\n core.value = store.getState().core;\n\n const unsub = store.subscribe((action, newSt, oldSt) => {\n if (store.isCoreAction(action) && !arePropsEqual(newSt.core, oldSt.core)) {\n core.value = newSt.core;\n }\n });\n onBeforeUnmount(unsub);\n });\n\n return core;\n}\n","import { shallowRef, ref, onMounted, watch, type ShallowRef, type Ref } from 'vue';\nimport type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport interface PluginState<T extends BasePlugin> {\n plugin: ShallowRef<T | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n const plugin = shallowRef(null) as ShallowRef<T | null>;\n\n const isLoading = ref(true);\n const ready = ref<Promise<void>>(new Promise(() => {}));\n\n const load = () => {\n if (!registry.value) return;\n\n const p = registry.value.getPlugin<T>(pluginId);\n if (!p) throw new Error(`Plugin ${pluginId} not found`);\n\n plugin.value = p;\n isLoading.value = false;\n ready.value = p.ready?.() ?? Promise.resolve();\n };\n\n onMounted(load);\n watch(registry, load);\n\n return { plugin, isLoading, ready };\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { computed, type Ref } from 'vue';\nimport { usePlugin } from './use-plugin';\n\nexport interface CapabilityState<C> {\n provides: Ref<C | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\n/**\n * Access the public capability exposed by a plugin.\n *\n * @example\n * const { provides: zoom } = useCapability<ZoomPlugin>(ZoomPlugin.id);\n * zoom.value?.zoomIn();\n */\nexport function useCapability<T extends BasePlugin>(\n pluginId: T['id'],\n): CapabilityState<ReturnType<NonNullable<T['provides']>>> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n const provides = computed(() => {\n if (!plugin.value) return null;\n if (!plugin.value.provides) {\n throw new Error(`Plugin ${pluginId} does not implement provides()`);\n }\n return plugin.value.provides() as ReturnType<NonNullable<T['provides']>>;\n });\n\n return { provides, isLoading, ready };\n}\n","import { ref, onMounted, onBeforeUnmount, watch } from 'vue';\nimport type { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Reactive getter for the *entire* global store.\n * Re‑emits whenever any slice changes.\n *\n * @example\n * const state = useStoreState(); // Ref<StoreState<CoreState>>\n * console.log(state.value.core.scale);\n */\nexport function useStoreState<T = CoreState>() {\n const { registry } = useRegistry();\n const state = ref<StoreState<T>>();\n\n function attach() {\n if (!registry.value) return () => {};\n\n // initial snapshot\n state.value = registry.value.getStore().getState() as StoreState<T>;\n\n // live updates\n return registry.value\n .getStore()\n .subscribe((_action, newState) => (state.value = newState as StoreState<T>));\n }\n\n /* attach now and re‑attach if registry instance ever changes */\n let unsubscribe = attach();\n watch(registry, () => {\n unsubscribe?.();\n unsubscribe = attach();\n });\n\n onBeforeUnmount(() => unsubscribe?.());\n\n return state;\n}\n","<script setup lang=\"ts\">\ndefineProps<{\n wrappers: any[];\n}>();\n</script>\n\n<template>\n <component :is=\"wrappers[0]\">\n <NestedWrapper v-if=\"wrappers.length > 1\" :wrappers=\"wrappers.slice(1)\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n </component>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\nimport NestedWrapper from './nested-wrapper.vue';\n\nconst props = defineProps<{\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n}>();\n\nconst elements = computed(() => {\n const utilities: any[] = [];\n const wrappers: any[] = [];\n\n for (const reg of props.plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements() || [];\n\n for (const element of elements) {\n if (element.type === 'utility') {\n utilities.push(element.component);\n } else if (element.type === 'wrapper') {\n wrappers.push(element.component);\n }\n }\n }\n }\n\n return { utilities, wrappers };\n});\n</script>\n\n<template>\n <NestedWrapper v-if=\"elements.wrappers.length > 0\" :wrappers=\"elements.wrappers\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n\n <component\n v-for=\"(utility, index) in elements.utilities\"\n :key=\"`utility-${index}`\"\n :is=\"utility\"\n />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistration } from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\nimport AutoMount from './auto-mount.vue';\n\nconst props = withDefaults(\n defineProps<{\n engine: PdfEngine;\n logger?: Logger;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n autoMountDomElements?: boolean;\n }>(),\n {\n autoMountDomElements: true,\n },\n);\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });\n\nonMounted(async () => {\n const reg = new PluginRegistry(props.engine, { logger: props.logger });\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n await props.onInitialized?.(reg);\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => (pluginsOk.value = true));\n});\n\nonBeforeUnmount(() => registry.value?.destroy());\n</script>\n\n<template>\n <AutoMount v-if=\"pluginsOk && autoMountDomElements\" :plugins=\"plugins\">\n <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n </AutoMount>\n\n <!-- No auto-mount or not ready yet -->\n <slot v-else :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n</template>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","wrappers","_renderSlot","elements","NestedWrapper","_createElementBlock","_Fragment","autoMountDomElements","AutoMount","plugins"],"mappings":";;AASa,MAAA,SAAwC,OAAO,QAAQ;ACN7D,SAAS,cAAc;AACtB,QAAA,MAAM,OAAO,MAAM;AACzB,MAAI,CAAC,IAAW,OAAA,IAAI,MAAM,4CAA4C;AAC/D,SAAA;AACT;ACHO,SAAS,eAAe;AACvB,QAAA,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,OAAO,IAAe;AAE5B,YAAU,MAAM;AACR,UAAA,QAAQ,SAAS,MAAO,SAAS;AAClC,SAAA,QAAQ,MAAM,SAAW,EAAA;AAE9B,UAAM,QAAQ,MAAM,UAAU,CAAC,QAAQ,OAAO,UAAU;AAClD,UAAA,MAAM,aAAa,MAAM,KAAK,CAAC,cAAc,MAAM,MAAM,MAAM,IAAI,GAAG;AACxE,aAAK,QAAQ,MAAM;AAAA,MAAA;AAAA,IACrB,CACD;AACD,oBAAgB,KAAK;AAAA,EAAA,CACtB;AAEM,SAAA;AACT;ACXO,SAAS,UAAgC,UAAmC;AAC3E,QAA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iBAAAR,UAAA,GAAAC,YAIEC,wBADK,OAAO,GAAA;AAAA,YADX,gBAAgB,KAAK;AAAA,UAAA;;;;;;;;;;;;;;;;ACjC1B,UAAM,QAAQ;AAcR,UAAA,WAAW,WAAkC,IAAI;AACjD,UAAA,SAAS,IAAI,IAAI;AACjB,UAAA,YAAY,IAAI,KAAK;AAG3B,YAAyB,QAAQ,EAAE,UAAU,gBAAgB,QAAQ,cAAc,WAAW;AAE9F,cAAU,YAAY;;AACd,YAAA,MAAM,IAAI,eAAe,MAAM,QAAQ,EAAE,QAAQ,MAAM,QAAQ;AACjE,UAAA,oBAAoB,MAAM,OAAO;AACrC,YAAM,IAAI,WAAW;AACf,cAAA,WAAM,kBAAN,+BAAsB;AAE5B,eAAS,QAAQ;AACjB,aAAO,QAAQ;AAEf,UAAI,eAAe,KAAK,MAAO,UAAU,QAAQ,IAAK;AAAA,IAAA,CACvD;AAED,oBAAgB,MAAM;;AAAA,4BAAS,UAAT,mBAAgB;AAAA,KAAS;;AAI5B,aAAA,UAAA,SAAaO,KAAoB,qCAAlDR,YAGYS,aAAA;AAAA;QAHyC,SAASC,KAAO;AAAA,MAAA;yBAEnE,MAAgF;AAAA,UAAhFP,WAAgF,KAAA,QAAA,WAAA;AAAA,YAAzE,UAAU,SAAQ;AAAA,YAAG,gBAAgB,OAAM;AAAA,YAAG,cAAc,UAAS;AAAA;;;4BAI9EA,WAAuF,KAAA,QAAA,WAAA;AAAA;QAAzE,UAAU,SAAQ;AAAA,QAAG,gBAAgB,OAAM;AAAA,QAAG,cAAc,UAAS;AAAA,MAAA;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/vue/context.ts","../../src/vue/composables/use-registry.ts","../../src/vue/composables/use-core-state.ts","../../src/vue/composables/use-plugin.ts","../../src/vue/composables/use-capability.ts","../../src/vue/composables/use-store-state.ts","../../src/vue/components/nested-wrapper.vue","../../src/vue/components/auto-mount.vue","../../src/vue/components/embed-pdf.vue"],"sourcesContent":["import { InjectionKey, Ref, ShallowRef } from 'vue';\nimport type { PluginRegistry } from '@embedpdf/core';\n\nexport interface PDFContextState {\n registry: ShallowRef<PluginRegistry | null>;\n isInitializing: Ref<boolean>;\n pluginsReady: Ref<boolean>;\n}\n\nexport const pdfKey: InjectionKey<PDFContextState> = Symbol('pdfKey');\n","import { inject } from 'vue';\nimport { pdfKey } from '../context';\n\nexport function useRegistry() {\n const ctx = inject(pdfKey);\n if (!ctx) throw new Error('useRegistry must be used inside <EmbedPDF>');\n return ctx;\n}\n","import { ref, onMounted, onBeforeUnmount } from 'vue';\nimport { arePropsEqual, type CoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport function useCoreState() {\n const { registry } = useRegistry();\n const core = ref<CoreState>();\n\n onMounted(() => {\n const store = registry.value!.getStore();\n core.value = store.getState().core;\n\n const unsub = store.subscribe((action, newSt, oldSt) => {\n if (store.isCoreAction(action) && !arePropsEqual(newSt.core, oldSt.core)) {\n core.value = newSt.core;\n }\n });\n onBeforeUnmount(unsub);\n });\n\n return core;\n}\n","import { shallowRef, ref, onMounted, watch, type ShallowRef, type Ref } from 'vue';\nimport type { BasePlugin } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\nexport interface PluginState<T extends BasePlugin> {\n plugin: ShallowRef<T | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\nexport function usePlugin<T extends BasePlugin>(pluginId: T['id']): PluginState<T> {\n const { registry } = useRegistry();\n\n const plugin = shallowRef(null) as ShallowRef<T | null>;\n\n const isLoading = ref(true);\n const ready = ref<Promise<void>>(new Promise(() => {}));\n\n const load = () => {\n if (!registry.value) return;\n\n const p = registry.value.getPlugin<T>(pluginId);\n if (!p) throw new Error(`Plugin ${pluginId} not found`);\n\n plugin.value = p;\n isLoading.value = false;\n ready.value = p.ready?.() ?? Promise.resolve();\n };\n\n onMounted(load);\n watch(registry, load);\n\n return { plugin, isLoading, ready };\n}\n","import type { BasePlugin } from '@embedpdf/core';\nimport { computed, type Ref } from 'vue';\nimport { usePlugin } from './use-plugin';\n\nexport interface CapabilityState<C> {\n provides: Ref<C | null>;\n isLoading: Ref<boolean>;\n ready: Ref<Promise<void>>;\n}\n\n/**\n * Access the public capability exposed by a plugin.\n *\n * @example\n * const { provides: zoom } = useCapability<ZoomPlugin>(ZoomPlugin.id);\n * zoom.value?.zoomIn();\n */\nexport function useCapability<T extends BasePlugin>(\n pluginId: T['id'],\n): CapabilityState<ReturnType<NonNullable<T['provides']>>> {\n const { plugin, isLoading, ready } = usePlugin<T>(pluginId);\n\n const provides = computed(() => {\n if (!plugin.value) return null;\n if (!plugin.value.provides) {\n throw new Error(`Plugin ${pluginId} does not implement provides()`);\n }\n return plugin.value.provides() as ReturnType<NonNullable<T['provides']>>;\n });\n\n return { provides, isLoading, ready };\n}\n","import { ref, onMounted, onBeforeUnmount, watch } from 'vue';\nimport type { CoreState, StoreState } from '@embedpdf/core';\nimport { useRegistry } from './use-registry';\n\n/**\n * Reactive getter for the *entire* global store.\n * Re‑emits whenever any slice changes.\n *\n * @example\n * const state = useStoreState(); // Ref<StoreState<CoreState>>\n * console.log(state.value.core.scale);\n */\nexport function useStoreState<T = CoreState>() {\n const { registry } = useRegistry();\n const state = ref<StoreState<T>>();\n\n function attach() {\n if (!registry.value) return () => {};\n\n // initial snapshot\n state.value = registry.value.getStore().getState() as StoreState<T>;\n\n // live updates\n return registry.value\n .getStore()\n .subscribe((_action, newState) => (state.value = newState as StoreState<T>));\n }\n\n /* attach now and re‑attach if registry instance ever changes */\n let unsubscribe = attach();\n watch(registry, () => {\n unsubscribe?.();\n unsubscribe = attach();\n });\n\n onBeforeUnmount(() => unsubscribe?.());\n\n return state;\n}\n","<script setup lang=\"ts\">\ndefineProps<{\n wrappers: any[];\n}>();\n</script>\n\n<template>\n <component :is=\"wrappers[0]\">\n <NestedWrapper v-if=\"wrappers.length > 1\" :wrappers=\"wrappers.slice(1)\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n </component>\n</template>\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { hasAutoMountElements, type PluginBatchRegistration, type IPlugin } from '@embedpdf/core';\nimport NestedWrapper from './nested-wrapper.vue';\n\nconst props = defineProps<{\n plugins: PluginBatchRegistration<IPlugin<any>, any>[];\n}>();\n\nconst elements = computed(() => {\n const utilities: any[] = [];\n const wrappers: any[] = [];\n\n for (const reg of props.plugins) {\n const pkg = reg.package;\n if (hasAutoMountElements(pkg)) {\n const elements = pkg.autoMountElements() || [];\n\n for (const element of elements) {\n if (element.type === 'utility') {\n utilities.push(element.component);\n } else if (element.type === 'wrapper') {\n wrappers.push(element.component);\n }\n }\n }\n }\n\n return { utilities, wrappers };\n});\n</script>\n\n<template>\n <NestedWrapper v-if=\"elements.wrappers.length > 0\" :wrappers=\"elements.wrappers\">\n <slot />\n </NestedWrapper>\n <slot v-else />\n\n <component\n v-for=\"(utility, index) in elements.utilities\"\n :key=\"`utility-${index}`\"\n :is=\"utility\"\n />\n</template>\n","<script setup lang=\"ts\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistrations } from '@embedpdf/core';\nimport { Logger, PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\nimport AutoMount from './auto-mount.vue';\n\nexport type { PluginBatchRegistrations };\n\nconst props = withDefaults(\n defineProps<{\n engine: PdfEngine;\n logger?: Logger;\n plugins: PluginBatchRegistrations;\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n autoMountDomElements?: boolean;\n }>(),\n {\n autoMountDomElements: true,\n },\n);\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit = ref(true);\nconst pluginsOk = ref(false);\n\n/* expose to children */\nprovide<PDFContextState>(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });\n\nonMounted(async () => {\n const reg = new PluginRegistry(props.engine, { logger: props.logger });\n reg.registerPluginBatch(props.plugins);\n await reg.initialize();\n await props.onInitialized?.(reg);\n\n registry.value = reg;\n isInit.value = false;\n\n reg.pluginsReady().then(() => (pluginsOk.value = true));\n});\n\nonBeforeUnmount(() => registry.value?.destroy());\n</script>\n\n<template>\n <AutoMount v-if=\"pluginsOk && autoMountDomElements\" :plugins=\"plugins\">\n <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n </AutoMount>\n\n <!-- No auto-mount or not ready yet -->\n <slot v-else :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n</template>\n"],"names":["_openBlock","_createBlock","_resolveDynamicComponent","wrappers","_renderSlot","elements","NestedWrapper","_createElementBlock","_Fragment","autoMountDomElements","AutoMount","plugins"],"mappings":";;AASa,MAAA,SAAwC,OAAO,QAAQ;ACN7D,SAAS,cAAc;AACtB,QAAA,MAAM,OAAO,MAAM;AACzB,MAAI,CAAC,IAAW,OAAA,IAAI,MAAM,4CAA4C;AAC/D,SAAA;AACT;ACHO,SAAS,eAAe;AACvB,QAAA,EAAE,SAAS,IAAI,YAAY;AACjC,QAAM,OAAO,IAAe;AAE5B,YAAU,MAAM;AACR,UAAA,QAAQ,SAAS,MAAO,SAAS;AAClC,SAAA,QAAQ,MAAM,SAAW,EAAA;AAE9B,UAAM,QAAQ,MAAM,UAAU,CAAC,QAAQ,OAAO,UAAU;AAClD,UAAA,MAAM,aAAa,MAAM,KAAK,CAAC,cAAc,MAAM,MAAM,MAAM,IAAI,GAAG;AACxE,aAAK,QAAQ,MAAM;AAAA,MAAA;AAAA,IACrB,CACD;AACD,oBAAgB,KAAK;AAAA,EAAA,CACtB;AAEM,SAAA;AACT;ACXO,SAAS,UAAgC,UAAmC;AAC3E,QAAA,EAAE,SAAS,IAAI,YAAY;AAE3B,QAAA,SAAS,WAAW,IAAI;AAExB,QAAA,YAAY,IAAI,IAAI;AAC1B,QAAM,QAAQ,IAAmB,IAAI,QAAQ,MAAM;AAAA,EAA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AkC,IAAI;AACjD,UAAA,SAAS,IAAI,IAAI;AACjB,UAAA,YAAY,IAAI,KAAK;AAG3B,YAAyB,QAAQ,EAAE,UAAU,gBAAgB,QAAQ,cAAc,WAAW;AAE9F,cAAU,YAAY;;AACd,YAAA,MAAM,IAAI,eAAe,MAAM,QAAQ,EAAE,QAAQ,MAAM,QAAQ;AACjE,UAAA,oBAAoB,MAAM,OAAO;AACrC,YAAM,IAAI,WAAW;AACf,cAAA,WAAM,kBAAN,+BAAsB;AAE5B,eAAS,QAAQ;AACjB,aAAO,QAAQ;AAEf,UAAI,eAAe,KAAK,MAAO,UAAU,QAAQ,IAAK;AAAA,IAAA,CACvD;AAED,oBAAgB,MAAM;;AAAA,4BAAS,UAAT,mBAAgB;AAAA,KAAS;;AAI5B,aAAA,UAAA,SAAaO,KAAoB,qCAAlDR,YAGYS,aAAA;AAAA;QAHyC,SAASC,KAAO;AAAA,MAAA;yBAEnE,MAAgF;AAAA,UAAhFP,WAAgF,KAAA,QAAA,WAAA;AAAA,YAAzE,UAAU,SAAQ;AAAA,YAAG,gBAAgB,OAAM;AAAA,YAAG,cAAc,UAAS;AAAA;;;4BAI9EA,WAAuF,KAAA,QAAA,WAAA;AAAA;QAAzE,UAAU,SAAQ;AAAA,QAAG,gBAAgB,OAAM;AAAA,QAAG,cAAc,UAAS;AAAA,MAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/core",
3
- "version": "1.3.15",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -26,21 +26,28 @@
26
26
  "types": "./dist/vue/index.d.ts",
27
27
  "import": "./dist/vue/index.js",
28
28
  "require": "./dist/vue/index.cjs"
29
+ },
30
+ "./svelte": {
31
+ "types": "./dist/svelte/index.d.ts",
32
+ "import": "./dist/svelte/index.js",
33
+ "svelte": "./dist/svelte/index.js",
34
+ "require": "./dist/svelte/index.cjs"
29
35
  }
30
36
  },
31
37
  "devDependencies": {
32
38
  "@types/react": "^18.2.0",
33
39
  "typescript": "^5.0.0",
34
- "@embedpdf/build": "1.0.1"
40
+ "@embedpdf/build": "1.1.0"
35
41
  },
36
42
  "dependencies": {
37
- "@embedpdf/engines": "1.3.15",
38
- "@embedpdf/models": "1.3.15"
43
+ "@embedpdf/engines": "1.4.0",
44
+ "@embedpdf/models": "1.4.0"
39
45
  },
40
46
  "peerDependencies": {
41
47
  "preact": "^10.26.4",
42
48
  "react": ">=16.8.0",
43
49
  "react-dom": ">=16.8.0",
50
+ "svelte": ">=5 <6",
44
51
  "vue": ">=3.2.0"
45
52
  },
46
53
  "files": [
@@ -55,7 +62,8 @@
55
62
  "build:react": "vite build --mode react",
56
63
  "build:preact": "vite build --mode preact",
57
64
  "build:vue": "vite build --mode vue",
58
- "build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\"",
65
+ "build:svelte": "vite build --mode svelte",
66
+ "build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue,svelte \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\" \"vite build --mode svelte\"",
59
67
  "clean": "rimraf dist",
60
68
  "lint": "eslint src --color",
61
69
  "lint:fix": "eslint src --color --fix"