@embedpdf/core 1.0.17 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +53 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/base/base-plugin.d.ts +3 -0
- package/dist/lib/registry/plugin-registry.d.ts +6 -1
- package/dist/lib/store/actions.d.ts +14 -2
- package/dist/lib/types/plugin.d.ts +3 -2
- package/dist/preact/adapter.d.ts +8 -2
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +62 -3
- package/dist/preact/index.js.map +1 -1
- package/dist/react/adapter.d.ts +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +62 -3
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/counter-rotate-container.d.ts +33 -0
- package/dist/shared-preact/components/embed-pdf.d.ts +3 -2
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-react/components/counter-rotate-container.d.ts +33 -0
- package/dist/shared-react/components/embed-pdf.d.ts +3 -2
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/vue/components/embed-pdf.vue.d.ts +2 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +2 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Rect, Rotation } from '@embedpdf/models';
|
|
2
|
+
import { ReactNode, CSSProperties, PointerEvent, TouchEvent } from '../../react/adapter.ts';
|
|
3
|
+
interface CounterRotateProps {
|
|
4
|
+
rect: Rect;
|
|
5
|
+
rotation: Rotation;
|
|
6
|
+
}
|
|
7
|
+
interface CounterTransformResult {
|
|
8
|
+
matrix: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Given an already-placed rect (left/top/width/height in px) and the page rotation,
|
|
14
|
+
* return the counter-rotation matrix + adjusted width/height.
|
|
15
|
+
*
|
|
16
|
+
* transform-origin is expected to be "0 0".
|
|
17
|
+
* left/top DO NOT change, apply them as-is.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getCounterRotation(rect: Rect, rotation: Rotation): CounterTransformResult;
|
|
20
|
+
export interface MenuWrapperProps {
|
|
21
|
+
style: CSSProperties;
|
|
22
|
+
onPointerDown: (e: PointerEvent<HTMLDivElement>) => void;
|
|
23
|
+
onTouchStart: (e: TouchEvent<HTMLDivElement>) => void;
|
|
24
|
+
}
|
|
25
|
+
interface CounterRotateComponentProps extends CounterRotateProps {
|
|
26
|
+
children: (props: {
|
|
27
|
+
matrix: string;
|
|
28
|
+
rect: Rect;
|
|
29
|
+
menuWrapperProps: MenuWrapperProps;
|
|
30
|
+
}) => ReactNode;
|
|
31
|
+
}
|
|
32
|
+
export declare function CounterRotate({ children, ...props }: CounterRotateComponentProps): import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
export {};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from '../../react/adapter.ts';
|
|
2
|
-
import { PdfEngine } from '@embedpdf/models';
|
|
2
|
+
import { Logger, PdfEngine } from '@embedpdf/models';
|
|
3
3
|
import { PluginRegistry, IPlugin, PluginBatchRegistration } from '../../lib/index.ts';
|
|
4
4
|
import { PDFContextState } from '../context';
|
|
5
5
|
interface EmbedPDFProps {
|
|
6
6
|
engine: PdfEngine;
|
|
7
|
+
logger?: Logger;
|
|
7
8
|
onInitialized?: (registry: PluginRegistry) => Promise<void>;
|
|
8
9
|
plugins: PluginBatchRegistration<IPlugin<any>, any>[];
|
|
9
10
|
children: ReactNode | ((state: PDFContextState) => ReactNode);
|
|
10
11
|
}
|
|
11
|
-
export declare function EmbedPDF({ engine, onInitialized, plugins, children }: EmbedPDFProps): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare function EmbedPDF({ engine, logger, onInitialized, plugins, children }: EmbedPDFProps): import("react/jsx-runtime").JSX.Element;
|
|
12
13
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { PluginRegistry, PluginBatchRegistration } from '../../lib/index.ts';
|
|
2
|
-
import { PdfEngine } from '@embedpdf/models';
|
|
2
|
+
import { Logger, PdfEngine } from '@embedpdf/models';
|
|
3
3
|
type __VLS_Props = {
|
|
4
4
|
engine: PdfEngine;
|
|
5
|
+
logger?: Logger;
|
|
5
6
|
plugins: PluginBatchRegistration<any, any>[];
|
|
6
7
|
onInitialized?: (registry: PluginRegistry) => Promise<void>;
|
|
7
8
|
};
|
package/dist/vue/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/core"),r=Symbol("pdfKey");function t(){const n=e.inject(r);if(!n)throw new Error("useRegistry must be used inside <EmbedPDF>");return n}function o(n){const{registry:r}=t(),o=e.shallowRef(null),i=e.ref(!0),u=e.ref(new Promise((()=>{}))),l=()=>{var e;if(!r.value)return;const t=r.value.getPlugin(n);if(!t)throw new Error(`Plugin ${n} not found`);o.value=t,i.value=!1,u.value=(null==(e=t.ready)?void 0:e.call(t))??Promise.resolve()};return e.onMounted(l),e.watch(r,l),{plugin:o,isLoading:i,ready:u}}const i=e.defineComponent({__name:"embed-pdf",props:{engine:{},plugins:{},onInitialized:{type:Function}},setup(t){const o=t,i=e.shallowRef(null),u=e.ref(!0),l=e.ref(!1);return e.provide(r,{registry:i,isInitializing:u,pluginsReady:l}),e.onMounted((async()=>{var e;const r=new n.PluginRegistry(o.engine);r.registerPluginBatch(o.plugins),await r.initialize(),await(null==(e=o.onInitialized)?void 0:e.call(o,r)),i.value=r,u.value=!1,r.pluginsReady().then((()=>l.value=!0))})),e.onBeforeUnmount((()=>{var e;return null==(e=i.value)?void 0:e.destroy()})),(n,r)=>e.renderSlot(n.$slots,"default",{registry:i.value,isInitializing:u.value,pluginsReady:l.value})}});exports.EmbedPDF=i,exports.useCapability=function(n){const{plugin:r,isLoading:t,ready:i}=o(n);return{provides:e.computed((()=>{if(!r.value)return null;if(!r.value.provides)throw new Error(`Plugin ${n} does not implement provides()`);return r.value.provides()})),isLoading:t,ready:i}},exports.useCoreState=function(){const{registry:r}=t(),o=e.ref();return e.onMounted((()=>{const t=r.value.getStore();o.value=t.getState().core;const i=t.subscribe(((e,r,i)=>{t.isCoreAction(e)&&!n.arePropsEqual(r.core,i.core)&&(o.value=r.core)}));e.onBeforeUnmount(i)})),o},exports.usePlugin=o,exports.useRegistry=t,exports.useStoreState=function(){const{registry:n}=t(),r=e.ref();function o(){return n.value?(r.value=n.value.getStore().getState(),n.value.getStore().subscribe(((e,n)=>r.value=n))):()=>{}}let i=o();return e.watch(n,(()=>{null==i||i(),i=o()})),e.onBeforeUnmount((()=>null==i?void 0:i())),r};
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),n=require("@embedpdf/core"),r=Symbol("pdfKey");function t(){const n=e.inject(r);if(!n)throw new Error("useRegistry must be used inside <EmbedPDF>");return n}function o(n){const{registry:r}=t(),o=e.shallowRef(null),i=e.ref(!0),u=e.ref(new Promise((()=>{}))),l=()=>{var e;if(!r.value)return;const t=r.value.getPlugin(n);if(!t)throw new Error(`Plugin ${n} not found`);o.value=t,i.value=!1,u.value=(null==(e=t.ready)?void 0:e.call(t))??Promise.resolve()};return e.onMounted(l),e.watch(r,l),{plugin:o,isLoading:i,ready:u}}const i=e.defineComponent({__name:"embed-pdf",props:{engine:{},logger:{},plugins:{},onInitialized:{type:Function}},setup(t){const o=t,i=e.shallowRef(null),u=e.ref(!0),l=e.ref(!1);return e.provide(r,{registry:i,isInitializing:u,pluginsReady:l}),e.onMounted((async()=>{var e;const r=new n.PluginRegistry(o.engine,{logger:o.logger});r.registerPluginBatch(o.plugins),await r.initialize(),await(null==(e=o.onInitialized)?void 0:e.call(o,r)),i.value=r,u.value=!1,r.pluginsReady().then((()=>l.value=!0))})),e.onBeforeUnmount((()=>{var e;return null==(e=i.value)?void 0:e.destroy()})),(n,r)=>e.renderSlot(n.$slots,"default",{registry:i.value,isInitializing:u.value,pluginsReady:l.value})}});exports.EmbedPDF=i,exports.useCapability=function(n){const{plugin:r,isLoading:t,ready:i}=o(n);return{provides:e.computed((()=>{if(!r.value)return null;if(!r.value.provides)throw new Error(`Plugin ${n} does not implement provides()`);return r.value.provides()})),isLoading:t,ready:i}},exports.useCoreState=function(){const{registry:r}=t(),o=e.ref();return e.onMounted((()=>{const t=r.value.getStore();o.value=t.getState().core;const i=t.subscribe(((e,r,i)=>{t.isCoreAction(e)&&!n.arePropsEqual(r.core,i.core)&&(o.value=r.core)}));e.onBeforeUnmount(i)})),o},exports.usePlugin=o,exports.useRegistry=t,exports.useStoreState=function(){const{registry:n}=t(),r=e.ref();function o(){return n.value?(r.value=n.value.getStore().getState(),n.value.getStore().subscribe(((e,n)=>r.value=n))):()=>{}}let i=o();return e.watch(n,(()=>{null==i||i(),i=o()})),e.onBeforeUnmount((()=>null==i?void 0:i())),r};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/vue/index.cjs.map
CHANGED
|
@@ -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/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\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistration } from '@embedpdf/core';\nimport { PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\n\nconst props = defineProps<{\n engine: PdfEngine;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n}>();\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit
|
|
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/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\">\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';\n\nconst props = defineProps<{\n engine: PdfEngine;\n logger?: Logger;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\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 <!-- scoped slot keeps API parity with React version -->\n <slot :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","props","__props","isInit","pluginsOk","provide","isInitializing","pluginsReady","async","reg","PluginRegistry","engine","logger","registerPluginBatch","plugins","initialize","onInitialized","then","onBeforeUnmount","destroy","_renderSlot","_ctx","$slots","provides","computed","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,MAA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IACf+C,EAAOrC,EAAAA,MAcNqC,OAZP3B,EAAAA,WAAU,KACF,MAAA4B,EAAQ1C,EAASQ,MAAOmC,WACzBC,EAAApC,MAAQkC,EAAMG,WAAWJ,KAE9B,MAAMK,EAAQJ,EAAMK,WAAU,CAACC,EAAQC,EAAOC,KACxCR,EAAMS,aAAaH,KAAYI,gBAAcH,EAAMR,KAAMS,EAAMT,QACjEA,EAAKjC,MAAQyC,EAAMR,KAAA,IAGvBP,EAAAA,gBAAgBY,EAAK,IAGhBL,CACT,kECTO,WACC,MAAAzC,SAAEA,GAAaN,IACf2D,EAAQjD,EAAAA,MAEd,SAASkD,IACP,OAAKtD,EAASQ,OAGd6C,EAAM7C,MAAQR,EAASQ,MAAMmC,WAAWE,WAGjC7C,EAASQ,MACbmC,WACAI,WAAU,CAACQ,EAASC,IAAcH,EAAM7C,MAAQgD,KARvB,MAQiD,CAI/E,IAAIC,EAAcH,IAQX,OAPPvC,EAAAC,MAAMhB,GAAU,KACA,MAAAyD,GAAAA,IACdA,EAAcH,GAAO,IAGPvC,EAAAmB,iBAAA,IAAqB,MAAfuB,OAAe,EAAAA,MAE9BJ,CACT"}
|
package/dist/vue/index.js
CHANGED
|
@@ -72,6 +72,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
72
72
|
__name: "embed-pdf",
|
|
73
73
|
props: {
|
|
74
74
|
engine: {},
|
|
75
|
+
logger: {},
|
|
75
76
|
plugins: {},
|
|
76
77
|
onInitialized: { type: Function }
|
|
77
78
|
},
|
|
@@ -83,7 +84,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
83
84
|
provide(pdfKey, { registry, isInitializing: isInit, pluginsReady: pluginsOk });
|
|
84
85
|
onMounted(async () => {
|
|
85
86
|
var _a;
|
|
86
|
-
const reg = new PluginRegistry(props.engine);
|
|
87
|
+
const reg = new PluginRegistry(props.engine, { logger: props.logger });
|
|
87
88
|
reg.registerPluginBatch(props.plugins);
|
|
88
89
|
await reg.initialize();
|
|
89
90
|
await ((_a = props.onInitialized) == null ? void 0 : _a.call(props, reg));
|
package/dist/vue/index.js.map
CHANGED
|
@@ -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/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\">\nimport { ref, provide, onMounted, onBeforeUnmount, shallowRef } from 'vue';\nimport { PluginRegistry, PluginBatchRegistration } from '@embedpdf/core';\nimport { PdfEngine } from '@embedpdf/models';\nimport { pdfKey, PDFContextState } from '../context';\n\nconst props = defineProps<{\n engine: PdfEngine;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\n}>();\n\n/* reactive state */\nconst registry = shallowRef<PluginRegistry | null>(null);\nconst isInit
|
|
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/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\">\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';\n\nconst props = defineProps<{\n engine: PdfEngine;\n logger?: Logger;\n plugins: PluginBatchRegistration<any, any>[];\n onInitialized?: (registry: PluginRegistry) => Promise<void>;\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 <!-- scoped slot keeps API parity with React version -->\n <slot :registry=\"registry\" :isInitializing=\"isInit\" :pluginsReady=\"pluginsOk\" />\n</template>\n"],"names":["_renderSlot"],"mappings":";;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AAU,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.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@embedpdf/build": "1.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@embedpdf/
|
|
37
|
-
"@embedpdf/
|
|
36
|
+
"@embedpdf/models": "1.0.19",
|
|
37
|
+
"@embedpdf/engines": "1.0.19"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"preact": "^10.26.4",
|