@embedpdf/svelte 0.0.0-stage → 3.0.0-next.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +192 -0
- package/README.md +312 -2
- package/dist/actions/readers.svelte.d.ts +29 -0
- package/dist/actions/readers.svelte.js +55 -0
- package/dist/actions.d.ts +13 -0
- package/dist/actions.js +13 -0
- package/dist/anchored/Anchored.svelte +24 -0
- package/dist/anchored/Anchored.svelte.d.ts +4 -0
- package/dist/anchored/PlacedAnchored.svelte +97 -0
- package/dist/anchored/PlacedAnchored.svelte.d.ts +4 -0
- package/dist/anchored/context.d.ts +31 -0
- package/dist/anchored/context.js +36 -0
- package/dist/anchored/props.d.ts +29 -0
- package/dist/anchored/props.js +1 -0
- package/dist/anchored.d.ts +12 -0
- package/dist/anchored.js +2 -0
- package/dist/annotation/AnnotationChrome.svelte +173 -0
- package/dist/annotation/AnnotationChrome.svelte.d.ts +11 -0
- package/dist/annotation/AnnotationDraftMenu.svelte +27 -0
- package/dist/annotation/AnnotationDraftMenu.svelte.d.ts +4 -0
- package/dist/annotation/AnnotationFrame.svelte +46 -0
- package/dist/annotation/AnnotationFrame.svelte.d.ts +15 -0
- package/dist/annotation/AnnotationLayer.svelte +241 -0
- package/dist/annotation/AnnotationLayer.svelte.d.ts +4 -0
- package/dist/annotation/AnnotationLook.svelte +67 -0
- package/dist/annotation/AnnotationLook.svelte.d.ts +21 -0
- package/dist/annotation/AnnotationMenu.svelte +47 -0
- package/dist/annotation/AnnotationMenu.svelte.d.ts +4 -0
- package/dist/annotation/AnnotationRotationBadge.svelte +52 -0
- package/dist/annotation/AnnotationRotationBadge.svelte.d.ts +4 -0
- package/dist/annotation/AnnotationScene.svelte +27 -0
- package/dist/annotation/AnnotationScene.svelte.d.ts +7 -0
- package/dist/annotation/FreeTextBox.svelte +51 -0
- package/dist/annotation/FreeTextBox.svelte.d.ts +9 -0
- package/dist/annotation/NativeDrawing.svelte +61 -0
- package/dist/annotation/NativeDrawing.svelte.d.ts +10 -0
- package/dist/annotation/StampGhost.svelte +79 -0
- package/dist/annotation/StampGhost.svelte.d.ts +7 -0
- package/dist/annotation/chrome-paint.svelte.d.ts +30 -0
- package/dist/annotation/chrome-paint.svelte.js +27 -0
- package/dist/annotation/props.d.ts +181 -0
- package/dist/annotation/props.js +1 -0
- package/dist/annotation/readers.svelte.d.ts +59 -0
- package/dist/annotation/readers.svelte.js +136 -0
- package/dist/annotation/state.d.ts +18 -0
- package/dist/annotation/state.js +20 -0
- package/dist/annotation/text-box.svelte.d.ts +28 -0
- package/dist/annotation/text-box.svelte.js +87 -0
- package/dist/annotation.d.ts +32 -0
- package/dist/annotation.js +31 -0
- package/dist/attachment/readers.d.ts +23 -0
- package/dist/attachment/readers.js +21 -0
- package/dist/attachment.d.ts +13 -0
- package/dist/attachment.js +14 -0
- package/dist/commands/readers.svelte.d.ts +50 -0
- package/dist/commands/readers.svelte.js +83 -0
- package/dist/commands.d.ts +9 -0
- package/dist/commands.js +9 -0
- package/dist/form/ButtonControl.svelte +38 -0
- package/dist/form/ButtonControl.svelte.d.ts +11 -0
- package/dist/form/ComboControl.svelte +52 -0
- package/dist/form/ComboControl.svelte.d.ts +11 -0
- package/dist/form/FieldPictures.svelte +145 -0
- package/dist/form/FieldPictures.svelte.d.ts +3 -0
- package/dist/form/FormFocusRing.svelte +25 -0
- package/dist/form/FormFocusRing.svelte.d.ts +8 -0
- package/dist/form/FormLayer.svelte +98 -0
- package/dist/form/FormLayer.svelte.d.ts +3 -0
- package/dist/form/ListControl.svelte +49 -0
- package/dist/form/ListControl.svelte.d.ts +11 -0
- package/dist/form/NativeListBox.svelte +57 -0
- package/dist/form/NativeListBox.svelte.d.ts +4 -0
- package/dist/form/SignatureControl.svelte +53 -0
- package/dist/form/SignatureControl.svelte.d.ts +11 -0
- package/dist/form/TextControl.svelte +107 -0
- package/dist/form/TextControl.svelte.d.ts +11 -0
- package/dist/form/ToggleControl.svelte +50 -0
- package/dist/form/ToggleControl.svelte.d.ts +11 -0
- package/dist/form/WidgetBox.svelte +82 -0
- package/dist/form/WidgetBox.svelte.d.ts +15 -0
- package/dist/form/props.d.ts +21 -0
- package/dist/form/props.js +1 -0
- package/dist/form/readers.svelte.d.ts +46 -0
- package/dist/form/readers.svelte.js +52 -0
- package/dist/form/widget.d.ts +16 -0
- package/dist/form/widget.js +20 -0
- package/dist/form.d.ts +11 -0
- package/dist/form.js +12 -0
- package/dist/history/readers.d.ts +22 -0
- package/dist/history/readers.js +21 -0
- package/dist/history.d.ts +10 -0
- package/dist/history.js +11 -0
- package/dist/i18n/readers.svelte.d.ts +32 -0
- package/dist/i18n/readers.svelte.js +30 -0
- package/dist/i18n.d.ts +8 -0
- package/dist/i18n.js +9 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +30 -0
- package/dist/interaction/PagePointerSource.svelte +37 -0
- package/dist/interaction/PagePointerSource.svelte.d.ts +3 -0
- package/dist/interaction/readers.svelte.d.ts +26 -0
- package/dist/interaction/readers.svelte.js +47 -0
- package/dist/interaction.d.ts +11 -0
- package/dist/interaction.js +13 -0
- package/dist/link/LinkLayer.svelte +164 -0
- package/dist/link/LinkLayer.svelte.d.ts +4 -0
- package/dist/link/props.d.ts +17 -0
- package/dist/link/props.js +1 -0
- package/dist/link/readers.svelte.d.ts +18 -0
- package/dist/link/readers.svelte.js +38 -0
- package/dist/link.d.ts +11 -0
- package/dist/link.js +11 -0
- package/dist/measurement/readers.d.ts +44 -0
- package/dist/measurement/readers.js +46 -0
- package/dist/measurement.d.ts +12 -0
- package/dist/measurement.js +13 -0
- package/dist/metadata/readers.d.ts +22 -0
- package/dist/metadata/readers.js +22 -0
- package/dist/metadata.d.ts +12 -0
- package/dist/metadata.js +13 -0
- package/dist/outline/readers.d.ts +26 -0
- package/dist/outline/readers.js +22 -0
- package/dist/outline.d.ts +12 -0
- package/dist/outline.js +13 -0
- package/dist/page-edit/readers.d.ts +17 -0
- package/dist/page-edit/readers.js +18 -0
- package/dist/page-edit.d.ts +12 -0
- package/dist/page-edit.js +13 -0
- package/dist/page-view/PageView.svelte +192 -0
- package/dist/page-view/PageView.svelte.d.ts +4 -0
- package/dist/page-view/props.d.ts +32 -0
- package/dist/page-view/props.js +1 -0
- package/dist/page-view.d.ts +8 -0
- package/dist/page-view.js +7 -0
- package/dist/redaction/readers.d.ts +37 -0
- package/dist/redaction/readers.js +38 -0
- package/dist/redaction.d.ts +12 -0
- package/dist/redaction.js +13 -0
- package/dist/render/RenderLayer.svelte +116 -0
- package/dist/render/RenderLayer.svelte.d.ts +4 -0
- package/dist/render/TileImage.svelte +65 -0
- package/dist/render/TileImage.svelte.d.ts +11 -0
- package/dist/render/TilePlane.svelte +88 -0
- package/dist/render/TilePlane.svelte.d.ts +7 -0
- package/dist/render/props.d.ts +16 -0
- package/dist/render/props.js +1 -0
- package/dist/render/readers.svelte.d.ts +9 -0
- package/dist/render/readers.svelte.js +13 -0
- package/dist/render.d.ts +10 -0
- package/dist/render.js +10 -0
- package/dist/runtime/DocumentGate.svelte +26 -0
- package/dist/runtime/DocumentGate.svelte.d.ts +4 -0
- package/dist/runtime/DocumentScope.svelte +14 -0
- package/dist/runtime/DocumentScope.svelte.d.ts +4 -0
- package/dist/runtime/KernelProvider.svelte +33 -0
- package/dist/runtime/KernelProvider.svelte.d.ts +4 -0
- package/dist/runtime/SvgShapes.svelte +30 -0
- package/dist/runtime/SvgShapes.svelte.d.ts +8 -0
- package/dist/runtime/Viewer.svelte +130 -0
- package/dist/runtime/Viewer.svelte.d.ts +4 -0
- package/dist/runtime/binding.svelte.d.ts +33 -0
- package/dist/runtime/binding.svelte.js +71 -0
- package/dist/runtime/capability-handle.d.ts +6 -0
- package/dist/runtime/capability-handle.js +71 -0
- package/dist/runtime/dev.d.ts +10 -0
- package/dist/runtime/dev.js +23 -0
- package/dist/runtime/documents.svelte.d.ts +34 -0
- package/dist/runtime/documents.svelte.js +49 -0
- package/dist/runtime/page-layers.svelte.d.ts +20 -0
- package/dist/runtime/page-layers.svelte.js +40 -0
- package/dist/runtime/page.d.ts +10 -0
- package/dist/runtime/page.js +23 -0
- package/dist/runtime/props.d.ts +63 -0
- package/dist/runtime/props.js +1 -0
- package/dist/runtime/readers.svelte.d.ts +47 -0
- package/dist/runtime/readers.svelte.js +122 -0
- package/dist/runtime/state.svelte.d.ts +35 -0
- package/dist/runtime/state.svelte.js +90 -0
- package/dist/runtime/theme.d.ts +12 -0
- package/dist/runtime/theme.js +15 -0
- package/dist/runtime/values.svelte.d.ts +28 -0
- package/dist/runtime/values.svelte.js +51 -0
- package/dist/runtime.d.ts +26 -0
- package/dist/runtime.js +25 -0
- package/dist/search/SearchLayer.svelte +94 -0
- package/dist/search/SearchLayer.svelte.d.ts +4 -0
- package/dist/search/props.d.ts +11 -0
- package/dist/search/props.js +1 -0
- package/dist/search/readers.svelte.d.ts +41 -0
- package/dist/search/readers.svelte.js +40 -0
- package/dist/search.d.ts +11 -0
- package/dist/search.js +11 -0
- package/dist/selection/SelectionClipboard.svelte +35 -0
- package/dist/selection/SelectionClipboard.svelte.d.ts +4 -0
- package/dist/selection/SelectionHandles.svelte +192 -0
- package/dist/selection/SelectionHandles.svelte.d.ts +4 -0
- package/dist/selection/SelectionLayer.svelte +67 -0
- package/dist/selection/SelectionLayer.svelte.d.ts +3 -0
- package/dist/selection/SelectionMenu.svelte +36 -0
- package/dist/selection/SelectionMenu.svelte.d.ts +4 -0
- package/dist/selection/props.d.ts +26 -0
- package/dist/selection/props.js +1 -0
- package/dist/selection/readers.svelte.d.ts +31 -0
- package/dist/selection/readers.svelte.js +26 -0
- package/dist/selection.d.ts +16 -0
- package/dist/selection.js +18 -0
- package/dist/shell/readers.svelte.d.ts +40 -0
- package/dist/shell/readers.svelte.js +40 -0
- package/dist/shell/surface-focus.svelte.d.ts +16 -0
- package/dist/shell/surface-focus.svelte.js +33 -0
- package/dist/shell.d.ts +12 -0
- package/dist/shell.js +11 -0
- package/dist/signature/readers.svelte.d.ts +43 -0
- package/dist/signature/readers.svelte.js +46 -0
- package/dist/signature.d.ts +15 -0
- package/dist/signature.js +16 -0
- package/dist/stage/PageSurface.svelte +126 -0
- package/dist/stage/PageSurface.svelte.d.ts +18 -0
- package/dist/stage/Scrollbar.svelte +148 -0
- package/dist/stage/Scrollbar.svelte.d.ts +4 -0
- package/dist/stage/Stage.svelte +181 -0
- package/dist/stage/Stage.svelte.d.ts +4 -0
- package/dist/stage/StageScope.svelte +14 -0
- package/dist/stage/StageScope.svelte.d.ts +9 -0
- package/dist/stage/props.d.ts +71 -0
- package/dist/stage/props.js +1 -0
- package/dist/stage/readers.svelte.d.ts +39 -0
- package/dist/stage/readers.svelte.js +84 -0
- package/dist/stage/stage-scope.d.ts +18 -0
- package/dist/stage/stage-scope.js +35 -0
- package/dist/stage/two-way.svelte.d.ts +13 -0
- package/dist/stage/two-way.svelte.js +26 -0
- package/dist/stage.d.ts +17 -0
- package/dist/stage.js +15 -0
- package/dist/stamp/readers.svelte.d.ts +50 -0
- package/dist/stamp/readers.svelte.js +76 -0
- package/dist/stamp.d.ts +16 -0
- package/dist/stamp.js +18 -0
- package/dist/toolbar/DefaultCollapsed.svelte +39 -0
- package/dist/toolbar/DefaultCollapsed.svelte.d.ts +9 -0
- package/dist/toolbar/DefaultCommand.svelte +33 -0
- package/dist/toolbar/DefaultCommand.svelte.d.ts +8 -0
- package/dist/toolbar/DefaultGroupTrigger.svelte +39 -0
- package/dist/toolbar/DefaultGroupTrigger.svelte.d.ts +9 -0
- package/dist/toolbar/DefaultOverflowMenu.svelte +106 -0
- package/dist/toolbar/DefaultOverflowMenu.svelte.d.ts +9 -0
- package/dist/toolbar/DefaultOverflowTrigger.svelte +25 -0
- package/dist/toolbar/DefaultOverflowTrigger.svelte.d.ts +7 -0
- package/dist/toolbar/Measured.svelte +46 -0
- package/dist/toolbar/Measured.svelte.d.ts +11 -0
- package/dist/toolbar/NativeSlotSocket.svelte +43 -0
- package/dist/toolbar/NativeSlotSocket.svelte.d.ts +11 -0
- package/dist/toolbar/Toolbar.svelte +314 -0
- package/dist/toolbar/Toolbar.svelte.d.ts +4 -0
- package/dist/toolbar/paint.d.ts +3 -0
- package/dist/toolbar/paint.js +9 -0
- package/dist/toolbar/props.d.ts +48 -0
- package/dist/toolbar/props.js +1 -0
- package/dist/toolbar/strip.svelte.d.ts +14 -0
- package/dist/toolbar/strip.svelte.js +35 -0
- package/dist/toolbar/views.d.ts +14 -0
- package/dist/toolbar/views.js +1 -0
- package/dist/toolbar.d.ts +16 -0
- package/dist/toolbar.js +12 -0
- package/dist/view-manager/readers.d.ts +19 -0
- package/dist/view-manager/readers.js +17 -0
- package/dist/view-manager.d.ts +11 -0
- package/dist/view-manager.js +12 -0
- package/package.json +207 -3
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Svelte side of `@embedpdf/web`'s page layers: a layer says, for as long as it lives, which
|
|
3
|
+
* part of its page it paints, and the render layer reads which parts are painted, to leave them
|
|
4
|
+
* out of the page's picture.
|
|
5
|
+
*/
|
|
6
|
+
import { type PagePart, type PaintedParts } from '@embedpdf/web';
|
|
7
|
+
/**
|
|
8
|
+
* Say, for as long as this component lives, that it paints `part` of its page (`pageRef()`, the
|
|
9
|
+
* page context's `ref`; `null` while it paints nothing). Said as the component starts, so a render
|
|
10
|
+
* layer started alongside knows it by the time it's mounted.
|
|
11
|
+
*/
|
|
12
|
+
export declare function usePaintsPagePart(pageRef: () => object | null, part: PagePart): void;
|
|
13
|
+
/**
|
|
14
|
+
* Which parts of the page (`pageRef()`, the page context's `ref`) the layers on it paint: `null`
|
|
15
|
+
* until this component is mounted, when every layer started with it has said what it paints, so
|
|
16
|
+
* the page's picture is never asked for with a part another layer is about to take.
|
|
17
|
+
*/
|
|
18
|
+
export declare function usePaintedParts(pageRef: () => object): {
|
|
19
|
+
readonly current: PaintedParts | null;
|
|
20
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Svelte side of `@embedpdf/web`'s page layers: a layer says, for as long as it lives, which
|
|
3
|
+
* part of its page it paints, and the render layer reads which parts are painted, to leave them
|
|
4
|
+
* out of the page's picture.
|
|
5
|
+
*/
|
|
6
|
+
import { pageLayersOf } from '@embedpdf/web';
|
|
7
|
+
import { untrack } from 'svelte';
|
|
8
|
+
/**
|
|
9
|
+
* Say, for as long as this component lives, that it paints `part` of its page (`pageRef()`, the
|
|
10
|
+
* page context's `ref`; `null` while it paints nothing). Said as the component starts, so a render
|
|
11
|
+
* layer started alongside knows it by the time it's mounted.
|
|
12
|
+
*/
|
|
13
|
+
export function usePaintsPagePart(pageRef, part) {
|
|
14
|
+
$effect.pre(() => {
|
|
15
|
+
const ref = pageRef();
|
|
16
|
+
if (!ref)
|
|
17
|
+
return;
|
|
18
|
+
return untrack(() => pageLayersOf(ref).paint(part));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Which parts of the page (`pageRef()`, the page context's `ref`) the layers on it paint: `null`
|
|
23
|
+
* until this component is mounted, when every layer started with it has said what it paints, so
|
|
24
|
+
* the page's picture is never asked for with a part another layer is about to take.
|
|
25
|
+
*/
|
|
26
|
+
export function usePaintedParts(pageRef) {
|
|
27
|
+
let painted = $state.raw(null);
|
|
28
|
+
$effect(() => {
|
|
29
|
+
const layers = pageLayersOf(pageRef());
|
|
30
|
+
return untrack(() => {
|
|
31
|
+
painted = layers.painted();
|
|
32
|
+
return layers.subscribe(() => (painted = layers.painted()));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
get current() {
|
|
37
|
+
return painted;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PageTransform } from '@embedpdf/core-geometry';
|
|
2
|
+
import type { PageViewDemand } from '@embedpdf/plugin-render/contract';
|
|
3
|
+
import type { PageContext } from '@embedpdf/web';
|
|
4
|
+
export { livePageContext, makePageContext } from '@embedpdf/web';
|
|
5
|
+
/** The page context. Its members are documented on `PageContext` in `@embedpdf/web`. */
|
|
6
|
+
export type PageContextValue = PageContext<PageTransform, PageViewDemand>;
|
|
7
|
+
/** For page surfaces (`<Stage>`'s pages, `<PageView>`): provide the page to everything inside. */
|
|
8
|
+
export declare function setPageContext(page: PageContextValue): void;
|
|
9
|
+
/** The page this layer draws on. Throws outside a page surface. */
|
|
10
|
+
export declare function usePage(): PageContextValue;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page context: what a layer knows about the page it draws on. A layer depends only on this,
|
|
3
|
+
* never on the Stage, so the same layer works on a Stage page and on a single `<PageView>`.
|
|
4
|
+
*
|
|
5
|
+
* A page surface provides it as a function that returns the current value; `usePage()` gives a
|
|
6
|
+
* layer an object that reads through that function on every access, so `page.transform` in a
|
|
7
|
+
* template or a `$derived` follows the zoom.
|
|
8
|
+
*/
|
|
9
|
+
import { getContext, hasContext, setContext } from 'svelte';
|
|
10
|
+
// Built by `makePageContext`, and kept current by `livePageContext`, from `@embedpdf/web`.
|
|
11
|
+
export { livePageContext, makePageContext } from '@embedpdf/web';
|
|
12
|
+
const PAGE = Symbol('embedpdf.page');
|
|
13
|
+
/** For page surfaces (`<Stage>`'s pages, `<PageView>`): provide the page to everything inside. */
|
|
14
|
+
export function setPageContext(page) {
|
|
15
|
+
setContext(PAGE, page);
|
|
16
|
+
}
|
|
17
|
+
/** The page this layer draws on. Throws outside a page surface. */
|
|
18
|
+
export function usePage() {
|
|
19
|
+
if (!hasContext(PAGE)) {
|
|
20
|
+
throw new Error('[embedpdf] usePage() must be used inside <PageView> or a <Stage> page.');
|
|
21
|
+
}
|
|
22
|
+
return getContext(PAGE);
|
|
23
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The props of the runtime's components: `<Viewer>`, `<KernelProvider>`, `<DocumentGate>` and
|
|
3
|
+
* `<DocumentScope>`.
|
|
4
|
+
*/
|
|
5
|
+
import type { Snippet } from 'svelte';
|
|
6
|
+
import type { AnyPlugin, Engine, EngineFactory, FailedDocumentInfo, Identity, InitialDocument, Kernel, LockedDocumentInfo, ViewerPageSettings } from '@embedpdf/core';
|
|
7
|
+
export interface ViewerProps {
|
|
8
|
+
/**
|
|
9
|
+
* The engine, as an instance or a function. An instance (`{engine}`) is borrowed: the viewer
|
|
10
|
+
* uses it and never destroys it, so one engine made at module scope serves every viewer; a
|
|
11
|
+
* local engine is warmed up on mount. A function (`engine={() => localEngine()}`) is the
|
|
12
|
+
* viewer's own: called on mount, destroyed on unmount. Read once, when the viewer mounts.
|
|
13
|
+
*/
|
|
14
|
+
engine: Engine | EngineFactory;
|
|
15
|
+
/** The plugins. Read once, when the viewer mounts. */
|
|
16
|
+
plugins: AnyPlugin[];
|
|
17
|
+
/** Documents to open on startup, with optional tab names. Read once. */
|
|
18
|
+
initialDocuments?: InitialDocument[];
|
|
19
|
+
/**
|
|
20
|
+
* Called once the viewer has started, before the content mounts and before `initialDocuments`
|
|
21
|
+
* open: the door for code that isn't a component (register commands, subscribe to events).
|
|
22
|
+
*/
|
|
23
|
+
onReady?: (kernel: Kernel) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Who the user is, for every document opened without an `identity` of its own. Documents
|
|
26
|
+
* opened after a change use the new value; open ones keep theirs. The local engine only: the
|
|
27
|
+
* cloud engine reads it from the document's token.
|
|
28
|
+
*/
|
|
29
|
+
identity?: Identity;
|
|
30
|
+
/**
|
|
31
|
+
* What the user may do, as permissions, in every document opened without a `scope` of its own.
|
|
32
|
+
* Left out, they may do everything. Changes reach the documents opened after them.
|
|
33
|
+
*/
|
|
34
|
+
scope?: readonly string[];
|
|
35
|
+
/** The color every part without a color of its own follows. CSS `--epdf-accent` wins over it. */
|
|
36
|
+
accent?: string;
|
|
37
|
+
/** How pages look: `background` before the picture arrives, and the `shadow` under each page. */
|
|
38
|
+
page?: Partial<ViewerPageSettings>;
|
|
39
|
+
/** Shown while the viewer starts. */
|
|
40
|
+
fallback?: Snippet;
|
|
41
|
+
/** Shown when the viewer couldn't start, with why. Without it, a failed start shows nothing. */
|
|
42
|
+
error?: Snippet<[error: unknown]>;
|
|
43
|
+
children?: Snippet;
|
|
44
|
+
}
|
|
45
|
+
export interface KernelProviderProps {
|
|
46
|
+
/** The kernel everything inside reads. Read once: a new kernel takes a new provider. */
|
|
47
|
+
kernel: Kernel;
|
|
48
|
+
children?: Snippet;
|
|
49
|
+
}
|
|
50
|
+
export interface DocumentGateProps {
|
|
51
|
+
/** Shown while this subtree has no document: none is open, or it's still opening. */
|
|
52
|
+
fallback?: Snippet;
|
|
53
|
+
/** Shown while the document waits for its password; `fallback` without it. */
|
|
54
|
+
locked?: Snippet<[document: LockedDocumentInfo]>;
|
|
55
|
+
/** Shown when the document couldn't be opened, with why; `fallback` without it. */
|
|
56
|
+
error?: Snippet<[document: FailedDocumentInfo]>;
|
|
57
|
+
children?: Snippet;
|
|
58
|
+
}
|
|
59
|
+
export interface DocumentScopeProps {
|
|
60
|
+
/** The document everything inside talks to. */
|
|
61
|
+
id: string;
|
|
62
|
+
children?: Snippet;
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CapabilityToken, EventHook, Kernel } from '@embedpdf/core';
|
|
2
|
+
import { type CurrentValue, type MaybeGetter } from './values.svelte.js';
|
|
3
|
+
/** Equal when the two arrays hold the same items in the same order. */
|
|
4
|
+
export declare const shallowArray: <T>(left: readonly T[], right: readonly T[]) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* A value derived from the kernel, computed again after every kernel change and passed on only
|
|
7
|
+
* when `isEqual` says it changed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useKernelValue<R>(select: (kernel: Kernel) => R, isEqual?: (left: R, right: R) => boolean): CurrentValue<R>;
|
|
10
|
+
/** The active document's id, or null with none open. */
|
|
11
|
+
export declare function useActiveDocumentId(): CurrentValue<string | null>;
|
|
12
|
+
/** The document the nearest `<DocumentScope>` names, or null when this subtree follows the active one. */
|
|
13
|
+
export declare function useDocumentScope(): CurrentValue<string | null>;
|
|
14
|
+
/** The document this subtree talks to: the nearest `<DocumentScope>`'s, else the active one. */
|
|
15
|
+
export declare function useDocumentId(): CurrentValue<string | null>;
|
|
16
|
+
/**
|
|
17
|
+
* A plugin's capability, as a handle that is always the capability of the document in scope
|
|
18
|
+
* (see `./capability-handle.ts`). Outside a ready document a document plugin's calls refuse with
|
|
19
|
+
* `not-ready` (a method that returns a promise rejects), and its settings calls still work. A token no plugin provides throws now: a setup
|
|
20
|
+
* mistake. The token may be a function, for a component whose token is a prop.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useCapability<T>(token: MaybeGetter<CapabilityToken<T>>): T;
|
|
23
|
+
/**
|
|
24
|
+
* The capability itself, or null while the token can't resolve (no plugin, no document, or a
|
|
25
|
+
* document that isn't ready yet). The object is the plugin's own, so it can be handed to code
|
|
26
|
+
* that keeps it, such as an effect that registers something with it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useOptionalCapability<T>(token: MaybeGetter<CapabilityToken<T>>): CurrentValue<T | null>;
|
|
29
|
+
/**
|
|
30
|
+
* A value selected from a capability. Strict: while the token can't resolve, reading it throws
|
|
31
|
+
* the kernel's reason (no document, the document is loading), for code that knows a document
|
|
32
|
+
* exists, such as anything inside a `<DocumentGate>`. {@link useOptionalSelector} is its total twin.
|
|
33
|
+
*/
|
|
34
|
+
export declare function useSelector<C, R>(token: MaybeGetter<CapabilityToken<C>>, select: (capability: C) => R, isEqual?: (left: R, right: R) => boolean): CurrentValue<R>;
|
|
35
|
+
/**
|
|
36
|
+
* A value selected from a capability, or `fallback` while the token can't resolve: for chrome
|
|
37
|
+
* that stays mounted while no document is open (a zoom readout). A read through a capability
|
|
38
|
+
* whose document closed a moment ago gives `fallback` too.
|
|
39
|
+
*/
|
|
40
|
+
export declare function useOptionalSelector<C, R>(token: MaybeGetter<CapabilityToken<C>>, select: (capability: C) => R, fallback: R, isEqual?: (left: R, right: R) => boolean): CurrentValue<R>;
|
|
41
|
+
/**
|
|
42
|
+
* Subscribe to one of a capability's events while the component lives:
|
|
43
|
+
* `useCapabilityEvent(StageToken, (stage) => stage.onZoomChanged, handler)`. It subscribes again
|
|
44
|
+
* when the document in scope changes, and not at all without one. Events say what happened;
|
|
45
|
+
* the current value is a state reader's.
|
|
46
|
+
*/
|
|
47
|
+
export declare function useCapabilityEvent<C, T>(token: MaybeGetter<CapabilityToken<C>>, select: (capability: C) => EventHook<T>, handler: (event: T) => void): void;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The generic readers every plugin binding is built from: a value derived from the kernel, a
|
|
3
|
+
* plugin's capability (as a handle, or the raw object), a value selected from it, and its events.
|
|
4
|
+
*
|
|
5
|
+
* Call them while a component is created, like every `use…()` function: they read the viewer and
|
|
6
|
+
* the document scope from context, and the event readers clean up when the component goes away.
|
|
7
|
+
*/
|
|
8
|
+
import { untrack } from 'svelte';
|
|
9
|
+
import { standInFor } from '@embedpdf/core';
|
|
10
|
+
import { documentScopeOf, useKernelBinding } from './binding.svelte.js';
|
|
11
|
+
import { capabilityHandle } from './capability-handle.js';
|
|
12
|
+
import { currentOf, derivedValue, valueOf, } from './values.svelte.js';
|
|
13
|
+
/** Equal when the two arrays hold the same items in the same order. */
|
|
14
|
+
export const shallowArray = (left, right) => left === right || (left.length === right.length && left.every((item, i) => item === right[i]));
|
|
15
|
+
/**
|
|
16
|
+
* A value derived from the kernel, computed again after every kernel change and passed on only
|
|
17
|
+
* when `isEqual` says it changed.
|
|
18
|
+
*/
|
|
19
|
+
export function useKernelValue(select, isEqual = Object.is) {
|
|
20
|
+
const binding = useKernelBinding();
|
|
21
|
+
return currentOf(derivedValue(() => {
|
|
22
|
+
binding.track();
|
|
23
|
+
return select(binding.kernel);
|
|
24
|
+
}, isEqual));
|
|
25
|
+
}
|
|
26
|
+
/** The active document's id, or null with none open. */
|
|
27
|
+
export function useActiveDocumentId() {
|
|
28
|
+
return useKernelValue((kernel) => kernel.documents.getActiveId());
|
|
29
|
+
}
|
|
30
|
+
/** The document the nearest `<DocumentScope>` names, or null when this subtree follows the active one. */
|
|
31
|
+
export function useDocumentScope() {
|
|
32
|
+
return currentOf(documentScopeOf());
|
|
33
|
+
}
|
|
34
|
+
/** The document this subtree talks to: the nearest `<DocumentScope>`'s, else the active one. */
|
|
35
|
+
export function useDocumentId() {
|
|
36
|
+
const scoped = documentScopeOf();
|
|
37
|
+
return useKernelValue((kernel) => scoped() ?? kernel.documents.getActiveId());
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A plugin's capability, as a handle that is always the capability of the document in scope
|
|
41
|
+
* (see `./capability-handle.ts`). Outside a ready document a document plugin's calls refuse with
|
|
42
|
+
* `not-ready` (a method that returns a promise rejects), and its settings calls still work. A token no plugin provides throws now: a setup
|
|
43
|
+
* mistake. The token may be a function, for a component whose token is a prop.
|
|
44
|
+
*/
|
|
45
|
+
export function useCapability(token) {
|
|
46
|
+
const binding = useKernelBinding();
|
|
47
|
+
const { kernel } = binding;
|
|
48
|
+
const scoped = documentScopeOf();
|
|
49
|
+
const initial = untrack(() => valueOf(token));
|
|
50
|
+
if (kernel.scopeOf(initial) !== 'document')
|
|
51
|
+
kernel.capability(initial);
|
|
52
|
+
return capabilityHandle(() => {
|
|
53
|
+
const current = valueOf(token);
|
|
54
|
+
return kernel.tryCapability(current, scoped() ?? undefined) ?? standInFor(kernel, current);
|
|
55
|
+
}, () => binding.track());
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The capability itself, or null while the token can't resolve (no plugin, no document, or a
|
|
59
|
+
* document that isn't ready yet). The object is the plugin's own, so it can be handed to code
|
|
60
|
+
* that keeps it, such as an effect that registers something with it.
|
|
61
|
+
*/
|
|
62
|
+
export function useOptionalCapability(token) {
|
|
63
|
+
const binding = useKernelBinding();
|
|
64
|
+
const scoped = documentScopeOf();
|
|
65
|
+
return currentOf(derivedValue(() => {
|
|
66
|
+
binding.track();
|
|
67
|
+
return binding.kernel.tryCapability(valueOf(token), scoped() ?? undefined);
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A value selected from a capability. Strict: while the token can't resolve, reading it throws
|
|
72
|
+
* the kernel's reason (no document, the document is loading), for code that knows a document
|
|
73
|
+
* exists, such as anything inside a `<DocumentGate>`. {@link useOptionalSelector} is its total twin.
|
|
74
|
+
*/
|
|
75
|
+
export function useSelector(token, select, isEqual = Object.is) {
|
|
76
|
+
const binding = useKernelBinding();
|
|
77
|
+
const scoped = documentScopeOf();
|
|
78
|
+
return currentOf(derivedValue(() => {
|
|
79
|
+
binding.track();
|
|
80
|
+
const current = valueOf(token);
|
|
81
|
+
const documentId = scoped() ?? undefined;
|
|
82
|
+
const capability = binding.kernel.tryCapability(current, documentId) ??
|
|
83
|
+
binding.kernel.capability(current, documentId);
|
|
84
|
+
return select(capability);
|
|
85
|
+
}, isEqual));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A value selected from a capability, or `fallback` while the token can't resolve: for chrome
|
|
89
|
+
* that stays mounted while no document is open (a zoom readout). A read through a capability
|
|
90
|
+
* whose document closed a moment ago gives `fallback` too.
|
|
91
|
+
*/
|
|
92
|
+
export function useOptionalSelector(token, select, fallback, isEqual = Object.is) {
|
|
93
|
+
const binding = useKernelBinding();
|
|
94
|
+
const scoped = documentScopeOf();
|
|
95
|
+
return currentOf(derivedValue(() => {
|
|
96
|
+
binding.track();
|
|
97
|
+
const capability = binding.kernel.tryCapability(valueOf(token), scoped() ?? undefined);
|
|
98
|
+
if (capability === null)
|
|
99
|
+
return fallback;
|
|
100
|
+
try {
|
|
101
|
+
return select(capability);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return fallback;
|
|
105
|
+
}
|
|
106
|
+
}, isEqual));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Subscribe to one of a capability's events while the component lives:
|
|
110
|
+
* `useCapabilityEvent(StageToken, (stage) => stage.onZoomChanged, handler)`. It subscribes again
|
|
111
|
+
* when the document in scope changes, and not at all without one. Events say what happened;
|
|
112
|
+
* the current value is a state reader's.
|
|
113
|
+
*/
|
|
114
|
+
export function useCapabilityEvent(token, select, handler) {
|
|
115
|
+
const capability = useOptionalCapability(token);
|
|
116
|
+
$effect(() => {
|
|
117
|
+
const current = capability.current;
|
|
118
|
+
if (!current)
|
|
119
|
+
return;
|
|
120
|
+
return untrack(() => select(current)((event) => handler(event)));
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CapabilityToken, SettingsOf, StateDeclaration } from '@embedpdf/core';
|
|
2
|
+
import { type KernelBinding } from './binding.svelte.js';
|
|
3
|
+
import { type CurrentValue, type MaybeGetter } from './values.svelte.js';
|
|
4
|
+
/** A declared state's reader: the whole state, or the value `select` picks from it. */
|
|
5
|
+
export interface StateReader<State extends object> {
|
|
6
|
+
(): Readonly<State>;
|
|
7
|
+
<Selected>(select: (state: State) => Selected): CurrentValue<Selected>;
|
|
8
|
+
}
|
|
9
|
+
/** A plugin's settings reader: the settings, or the value `select` picks from them. */
|
|
10
|
+
export interface SettingsReader<Settings extends object> {
|
|
11
|
+
(): Readonly<Settings>;
|
|
12
|
+
<Selected>(select: (settings: Settings) => Selected): CurrentValue<Selected>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The whole state, read through the capability `token` resolves for this subtree's document, or
|
|
16
|
+
* `empty` while it can't resolve. Resolved on every read: a document that closes reads as `empty`,
|
|
17
|
+
* never through its closed capability.
|
|
18
|
+
*/
|
|
19
|
+
export declare function declaredState<Capability, State extends object>(binding: KernelBinding, token: MaybeGetter<CapabilityToken<Capability>>, read: (capability: Capability) => State, empty: State): () => State;
|
|
20
|
+
/** The reader's two forms over one getter: a reactive object with `keys`, or a selected value. */
|
|
21
|
+
export declare function readRecord<Record extends object, Selected>(whole: () => Record, keys: readonly (keyof Record)[], select: ((record: Record) => Selected) | undefined): Readonly<Record> | CurrentValue<Selected>;
|
|
22
|
+
/**
|
|
23
|
+
* Turn a state declaration into its reader. It reads this subtree's document (the nearest
|
|
24
|
+
* `<DocumentScope>`, else the active one) and gives the declaration's `empty` while that
|
|
25
|
+
* document is missing or not ready, so it works anywhere. State the plugin loads on demand
|
|
26
|
+
* (the declaration's `ensure`) loads once a ready document's capability is in scope.
|
|
27
|
+
*/
|
|
28
|
+
export declare function stateReader<Capability, State extends object>(declaration: StateDeclaration<Capability, State>): StateReader<State>;
|
|
29
|
+
/**
|
|
30
|
+
* Turn a plugin's token into its settings reader. A plugin's settings belong to the plugin as
|
|
31
|
+
* the app registered it, not to a document, so the reader works before the first document opens
|
|
32
|
+
* and every document shows the same settings. `getSettings()` keeps its object until a setting
|
|
33
|
+
* changes. A token whose plugin isn't installed, or has no settings, throws: a setup mistake.
|
|
34
|
+
*/
|
|
35
|
+
export declare function settingsReader<Capability>(token: CapabilityToken<Capability>): SettingsReader<SettingsOf<Capability> & object>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declared state and settings as Svelte readers. A plugin declares its state once with
|
|
3
|
+
* `defineState` and its settings once in its definition (both in `@embedpdf/core`), and its
|
|
4
|
+
* Svelte bindings are one line each:
|
|
5
|
+
*
|
|
6
|
+
* export const useSearchState = stateReader(searchState);
|
|
7
|
+
* export const useSearchSettings = settingsReader(SearchToken);
|
|
8
|
+
*
|
|
9
|
+
* Called with no argument, a reader returns a reactive object (`state.hitCount`), one derived
|
|
10
|
+
* value per field. Called with a selector, it returns the value the selector picks as
|
|
11
|
+
* `{ current }`, compared field by field so a fresh object passes nothing on until a field changes.
|
|
12
|
+
*/
|
|
13
|
+
import { untrack } from 'svelte';
|
|
14
|
+
import { shallowEqual } from '@embedpdf/core';
|
|
15
|
+
import { documentScopeOf, useKernelBinding } from './binding.svelte.js';
|
|
16
|
+
import { currentOf, derivedValue, reactiveRecord, valueOf, } from './values.svelte.js';
|
|
17
|
+
/**
|
|
18
|
+
* The whole state, read through the capability `token` resolves for this subtree's document, or
|
|
19
|
+
* `empty` while it can't resolve. Resolved on every read: a document that closes reads as `empty`,
|
|
20
|
+
* never through its closed capability.
|
|
21
|
+
*/
|
|
22
|
+
export function declaredState(binding, token, read, empty) {
|
|
23
|
+
const scoped = documentScopeOf();
|
|
24
|
+
return derivedValue(() => {
|
|
25
|
+
binding.track();
|
|
26
|
+
const capability = binding.kernel.tryCapability(valueOf(token), scoped() ?? undefined);
|
|
27
|
+
return capability ? read(capability) : empty;
|
|
28
|
+
}, shallowEqual);
|
|
29
|
+
}
|
|
30
|
+
/** The reader's two forms over one getter: a reactive object with `keys`, or a selected value. */
|
|
31
|
+
export function readRecord(whole, keys, select) {
|
|
32
|
+
if (!select)
|
|
33
|
+
return reactiveRecord(whole, keys);
|
|
34
|
+
return currentOf(derivedValue(() => select(whole()), shallowEqual));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Load state the plugin loads on demand (`ensure`) for each capability the reader comes to read:
|
|
38
|
+
* once a ready document's capability is in scope, and again for the next document's.
|
|
39
|
+
*/
|
|
40
|
+
function ensureWhileRead(binding, token, ensure) {
|
|
41
|
+
const scoped = documentScopeOf();
|
|
42
|
+
let ensured = null;
|
|
43
|
+
$effect(() => {
|
|
44
|
+
binding.track();
|
|
45
|
+
const capability = binding.kernel.tryCapability(token, scoped() ?? undefined);
|
|
46
|
+
if (!capability || capability === ensured)
|
|
47
|
+
return;
|
|
48
|
+
ensured = capability;
|
|
49
|
+
// The state says when the load fails (its status), so the rejection has nothing to add.
|
|
50
|
+
untrack(() => ensure(capability).catch(() => { }));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Turn a state declaration into its reader. It reads this subtree's document (the nearest
|
|
55
|
+
* `<DocumentScope>`, else the active one) and gives the declaration's `empty` while that
|
|
56
|
+
* document is missing or not ready, so it works anywhere. State the plugin loads on demand
|
|
57
|
+
* (the declaration's `ensure`) loads once a ready document's capability is in scope.
|
|
58
|
+
*/
|
|
59
|
+
export function stateReader(declaration) {
|
|
60
|
+
const keys = Object.keys(declaration.empty);
|
|
61
|
+
const { ensure } = declaration;
|
|
62
|
+
return function useDeclaredState(select) {
|
|
63
|
+
const binding = useKernelBinding();
|
|
64
|
+
const whole = declaredState(binding, declaration.token, declaration.read, declaration.empty);
|
|
65
|
+
if (ensure)
|
|
66
|
+
ensureWhileRead(binding, declaration.token, ensure);
|
|
67
|
+
return readRecord(whole, keys, select);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** A plugin's settings through the kernel: the same with or without a document. */
|
|
71
|
+
function settingsOf(kernel, token) {
|
|
72
|
+
return kernel.settingsOf(token).getSettings();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Turn a plugin's token into its settings reader. A plugin's settings belong to the plugin as
|
|
76
|
+
* the app registered it, not to a document, so the reader works before the first document opens
|
|
77
|
+
* and every document shows the same settings. `getSettings()` keeps its object until a setting
|
|
78
|
+
* changes. A token whose plugin isn't installed, or has no settings, throws: a setup mistake.
|
|
79
|
+
*/
|
|
80
|
+
export function settingsReader(token) {
|
|
81
|
+
return function useSettings(select) {
|
|
82
|
+
const binding = useKernelBinding();
|
|
83
|
+
const initial = settingsOf(binding.kernel, token);
|
|
84
|
+
const whole = derivedValue(() => {
|
|
85
|
+
binding.track();
|
|
86
|
+
return settingsOf(binding.kernel, token);
|
|
87
|
+
}, shallowEqual);
|
|
88
|
+
return readRecord(whole, Object.keys(initial), select);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `epdfTheme()`: a theme written with setting names, as a `style` for the element around your
|
|
3
|
+
* viewer. The variables and their lookup are framework-free (`@embedpdf/web`); this writes them
|
|
4
|
+
* as the CSS text a Svelte `style` attribute takes.
|
|
5
|
+
*/
|
|
6
|
+
import { type EpdfTheme } from '@embedpdf/web';
|
|
7
|
+
export type { EpdfTheme } from '@embedpdf/web';
|
|
8
|
+
/**
|
|
9
|
+
* The CSS variables of a theme, for a `style` attribute: `<div style={epdfTheme({ accent })}>`.
|
|
10
|
+
* Everything inside the element follows them, and a CSS variable wins over any setting.
|
|
11
|
+
*/
|
|
12
|
+
export declare function epdfTheme(theme: EpdfTheme): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `epdfTheme()`: a theme written with setting names, as a `style` for the element around your
|
|
3
|
+
* viewer. The variables and their lookup are framework-free (`@embedpdf/web`); this writes them
|
|
4
|
+
* as the CSS text a Svelte `style` attribute takes.
|
|
5
|
+
*/
|
|
6
|
+
import { epdfThemeVariables } from '@embedpdf/web';
|
|
7
|
+
/**
|
|
8
|
+
* The CSS variables of a theme, for a `style` attribute: `<div style={epdfTheme({ accent })}>`.
|
|
9
|
+
* Everything inside the element follows them, and a CSS variable wins over any setting.
|
|
10
|
+
*/
|
|
11
|
+
export function epdfTheme(theme) {
|
|
12
|
+
return Object.entries(epdfThemeVariables(theme))
|
|
13
|
+
.map(([name, value]) => `${name}: ${value};`)
|
|
14
|
+
.join(' ');
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two shapes a reader returns, and the derived value both are made of.
|
|
3
|
+
*
|
|
4
|
+
* - One value is `{ current }`, like Svelte's own `MediaQuery`: `pages.current`.
|
|
5
|
+
* - A record of named values (a plugin's state, its settings) is a reactive object whose fields
|
|
6
|
+
* are getters: `state.zoomLevel`. Each field is its own `$derived`, so a template or an effect
|
|
7
|
+
* that reads `zoomLevel` runs again only when `zoomLevel` changes.
|
|
8
|
+
*/
|
|
9
|
+
/** A value that changes: read `current` in a template, a `$derived` or an effect. */
|
|
10
|
+
export interface CurrentValue<T> {
|
|
11
|
+
readonly current: T;
|
|
12
|
+
}
|
|
13
|
+
/** An argument that may change: the value, or a function that returns it (`() => note.ref`). */
|
|
14
|
+
export type MaybeGetter<T> = T | (() => T);
|
|
15
|
+
/** The value of a {@link MaybeGetter}. Only for values that are never functions themselves. */
|
|
16
|
+
export declare function valueOf<T>(value: MaybeGetter<T>): T;
|
|
17
|
+
/**
|
|
18
|
+
* A `$derived` that keeps its last value while `isEqual` says the new one is the same, so a value
|
|
19
|
+
* built fresh on every read (an object a selector returns) passes nothing on until a field changes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function derivedValue<T>(compute: () => T, isEqual?: (left: T, right: T) => boolean): () => T;
|
|
22
|
+
/** `{ current }` over a getter. */
|
|
23
|
+
export declare function currentOf<T>(read: () => T): CurrentValue<T>;
|
|
24
|
+
/**
|
|
25
|
+
* A reactive object with `keys` as getters over `whole()`, each its own derived value. The keys
|
|
26
|
+
* are fixed when it is made: a declared state's `empty`, or the settings it starts with.
|
|
27
|
+
*/
|
|
28
|
+
export declare function reactiveRecord<Record extends object>(whole: () => Record, keys: readonly (keyof Record)[]): Readonly<Record>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two shapes a reader returns, and the derived value both are made of.
|
|
3
|
+
*
|
|
4
|
+
* - One value is `{ current }`, like Svelte's own `MediaQuery`: `pages.current`.
|
|
5
|
+
* - A record of named values (a plugin's state, its settings) is a reactive object whose fields
|
|
6
|
+
* are getters: `state.zoomLevel`. Each field is its own `$derived`, so a template or an effect
|
|
7
|
+
* that reads `zoomLevel` runs again only when `zoomLevel` changes.
|
|
8
|
+
*/
|
|
9
|
+
/** The value of a {@link MaybeGetter}. Only for values that are never functions themselves. */
|
|
10
|
+
export function valueOf(value) {
|
|
11
|
+
return typeof value === 'function' ? value() : value;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A `$derived` that keeps its last value while `isEqual` says the new one is the same, so a value
|
|
15
|
+
* built fresh on every read (an object a selector returns) passes nothing on until a field changes.
|
|
16
|
+
*/
|
|
17
|
+
export function derivedValue(compute, isEqual = Object.is) {
|
|
18
|
+
let last = null;
|
|
19
|
+
const value = $derived.by(() => {
|
|
20
|
+
const next = compute();
|
|
21
|
+
if (last !== null && isEqual(last.value, next))
|
|
22
|
+
return last.value;
|
|
23
|
+
last = { value: next };
|
|
24
|
+
return next;
|
|
25
|
+
});
|
|
26
|
+
return () => value;
|
|
27
|
+
}
|
|
28
|
+
/** `{ current }` over a getter. */
|
|
29
|
+
export function currentOf(read) {
|
|
30
|
+
return {
|
|
31
|
+
get current() {
|
|
32
|
+
return read();
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** One field of a record, as its own `$derived`: it passes a change on only when the field changed. */
|
|
37
|
+
function fieldOf(whole, key) {
|
|
38
|
+
const field = $derived(whole()[key]);
|
|
39
|
+
return () => field;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A reactive object with `keys` as getters over `whole()`, each its own derived value. The keys
|
|
43
|
+
* are fixed when it is made: a declared state's `empty`, or the settings it starts with.
|
|
44
|
+
*/
|
|
45
|
+
export function reactiveRecord(whole, keys) {
|
|
46
|
+
const record = {};
|
|
47
|
+
for (const key of keys) {
|
|
48
|
+
Object.defineProperty(record, key, { get: fieldOf(whole, key), enumerable: true });
|
|
49
|
+
}
|
|
50
|
+
return record;
|
|
51
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @embedpdf/svelte/runtime — the generic binding.
|
|
3
|
+
*
|
|
4
|
+
* `<Viewer>` owns the kernel, and `<KernelProvider>` gives a subtree a kernel someone else owns;
|
|
5
|
+
* the readers turn its one change stream into Svelte reactivity and resolve capabilities against
|
|
6
|
+
* the document in scope (the active one, or a `<DocumentScope>`'s), with a stand-in while there is
|
|
7
|
+
* none; the page context is the seam every layer draws through. Every plugin binding is built from
|
|
8
|
+
* these. How to add one: this package's README.
|
|
9
|
+
*/
|
|
10
|
+
export * from '@embedpdf/core';
|
|
11
|
+
export { mountWebFont, saveFile } from '@embedpdf/web';
|
|
12
|
+
export { default as Viewer } from './runtime/Viewer.svelte';
|
|
13
|
+
export { default as KernelProvider } from './runtime/KernelProvider.svelte';
|
|
14
|
+
export { default as DocumentGate } from './runtime/DocumentGate.svelte';
|
|
15
|
+
export { default as DocumentScope } from './runtime/DocumentScope.svelte';
|
|
16
|
+
export type { DocumentGateProps, DocumentScopeProps, KernelProviderProps, ViewerProps, } from './runtime/props.js';
|
|
17
|
+
export { useKernel } from './runtime/binding.svelte.js';
|
|
18
|
+
export { shallowArray, useActiveDocumentId, useCapability, useCapabilityEvent, useDocumentId, useDocumentScope, useKernelValue, useOptionalCapability, useOptionalSelector, useSelector, } from './runtime/readers.svelte.js';
|
|
19
|
+
export { useDocument, useDocuments, useDocumentsEvent, useDocumentsState, usePageList, useViewerSettings, } from './runtime/documents.svelte.js';
|
|
20
|
+
export { settingsReader, stateReader } from './runtime/state.svelte.js';
|
|
21
|
+
export type { SettingsReader, StateReader } from './runtime/state.svelte.js';
|
|
22
|
+
export type { CurrentValue, MaybeGetter } from './runtime/values.svelte.js';
|
|
23
|
+
export { makePageContext, setPageContext, usePage } from './runtime/page.js';
|
|
24
|
+
export type { PageContextValue } from './runtime/page.js';
|
|
25
|
+
export { epdfTheme } from './runtime/theme.js';
|
|
26
|
+
export type { EpdfTheme } from './runtime/theme.js';
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @embedpdf/svelte/runtime — the generic binding.
|
|
3
|
+
*
|
|
4
|
+
* `<Viewer>` owns the kernel, and `<KernelProvider>` gives a subtree a kernel someone else owns;
|
|
5
|
+
* the readers turn its one change stream into Svelte reactivity and resolve capabilities against
|
|
6
|
+
* the document in scope (the active one, or a `<DocumentScope>`'s), with a stand-in while there is
|
|
7
|
+
* none; the page context is the seam every layer draws through. Every plugin binding is built from
|
|
8
|
+
* these. How to add one: this package's README.
|
|
9
|
+
*/
|
|
10
|
+
// Registration travels with the UI: the kernel's types, tokens and helpers come from here too.
|
|
11
|
+
export * from '@embedpdf/core';
|
|
12
|
+
// What a page with a viewer needs from the browser: handing bytes to the user as a download,
|
|
13
|
+
// and a font the engine draws with, for text you draw yourself.
|
|
14
|
+
export { mountWebFont, saveFile } from '@embedpdf/web';
|
|
15
|
+
export { default as Viewer } from './runtime/Viewer.svelte';
|
|
16
|
+
export { default as KernelProvider } from './runtime/KernelProvider.svelte';
|
|
17
|
+
export { default as DocumentGate } from './runtime/DocumentGate.svelte';
|
|
18
|
+
export { default as DocumentScope } from './runtime/DocumentScope.svelte';
|
|
19
|
+
export { useKernel } from './runtime/binding.svelte.js';
|
|
20
|
+
export { shallowArray, useActiveDocumentId, useCapability, useCapabilityEvent, useDocumentId, useDocumentScope, useKernelValue, useOptionalCapability, useOptionalSelector, useSelector, } from './runtime/readers.svelte.js';
|
|
21
|
+
export { useDocument, useDocuments, useDocumentsEvent, useDocumentsState, usePageList, useViewerSettings, } from './runtime/documents.svelte.js';
|
|
22
|
+
export { settingsReader, stateReader } from './runtime/state.svelte.js';
|
|
23
|
+
export { makePageContext, setPageContext, usePage } from './runtime/page.js';
|
|
24
|
+
// A theme written with setting names, as the style for the element around a viewer.
|
|
25
|
+
export { epdfTheme } from './runtime/theme.js';
|