@embedpdf/svelte 0.0.0-stage → 3.0.0-next.15
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 +55 -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 +27 -0
- package/dist/annotation/text-box.svelte.js +94 -0
- package/dist/annotation.d.ts +32 -0
- package/dist/annotation.js +31 -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 +28 -0
- package/dist/index.js +28 -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/page-edit/readers.d.ts +7 -0
- package/dist/page-edit/readers.js +11 -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 +124 -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 +195 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** The props of the Stage's components: `<Stage>` and `<Scrollbar>`. */
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { PageContextValue } from '../runtime/page.js';
|
|
4
|
+
import type { StageTokenProp } from './stage-scope.js';
|
|
5
|
+
export interface StageProps {
|
|
6
|
+
/**
|
|
7
|
+
* Page-space content for each visible page (`<RenderLayer>`, annotations, markers): what you
|
|
8
|
+
* write between `<Stage>` and `</Stage>`, or `{#snippet children(page)}` when it needs the page.
|
|
9
|
+
* It's drawn inside the page's content frame, so it turns with the page, and positions are PDF
|
|
10
|
+
* points.
|
|
11
|
+
*/
|
|
12
|
+
children: Snippet<[page: PageContextValue]>;
|
|
13
|
+
/**
|
|
14
|
+
* Box-space chrome for each visible page (a page number, a selection border, a per-page
|
|
15
|
+
* button), drawn into the outer box (content and the reserved `pageFrame`). It never turns,
|
|
16
|
+
* and the reserved bands are plain regions: `bottom: 0; height: page.frame.bottom`.
|
|
17
|
+
*/
|
|
18
|
+
pageChrome?: Snippet<[page: PageContextValue]>;
|
|
19
|
+
/** Viewport-space UI (menus, controls, `<Scrollbar>`), drawn above the pages. */
|
|
20
|
+
overlay?: Snippet;
|
|
21
|
+
/**
|
|
22
|
+
* The active tool, two-way (`bind:tool`): while it's set, the interaction plugin's active tool
|
|
23
|
+
* follows it, and a tool chosen elsewhere is written back. Leave it out for the default
|
|
24
|
+
* (`useInteraction().activateTool()`).
|
|
25
|
+
*/
|
|
26
|
+
tool?: string;
|
|
27
|
+
/** Called on every tool change of this stage's document. */
|
|
28
|
+
onToolChange?: (toolId: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* The current page's index, from 0, two-way (`bind:page`): the Stage writes it as the reader
|
|
31
|
+
* moves, and goes to the page when you change it.
|
|
32
|
+
*/
|
|
33
|
+
page?: number;
|
|
34
|
+
/**
|
|
35
|
+
* The zoom level, two-way (`bind:zoom`): `1` is 100%. The Stage writes it as the zoom changes,
|
|
36
|
+
* and zooms to it when you change it.
|
|
37
|
+
*/
|
|
38
|
+
zoom?: number;
|
|
39
|
+
/** The stage lens to drive: the nearest `<StageScope>`'s, else the main view. */
|
|
40
|
+
token?: StageTokenProp;
|
|
41
|
+
class?: string;
|
|
42
|
+
style?: string;
|
|
43
|
+
}
|
|
44
|
+
export type ScrollbarAxis = 'x' | 'y';
|
|
45
|
+
export interface ScrollbarProps {
|
|
46
|
+
axis: ScrollbarAxis;
|
|
47
|
+
/** The stage lens to scroll: the nearest `<StageScope>` / `<Stage>`'s, else the main view. */
|
|
48
|
+
token?: StageTokenProp;
|
|
49
|
+
/**
|
|
50
|
+
* Hide `autoHide` milliseconds after the view stops moving (a drag or the pointer over it
|
|
51
|
+
* keeps it shown; a hidden bar ignores the pointer, like macOS). `false` always shows it.
|
|
52
|
+
* Published as `data-state="visible|hidden"`. Default 1200.
|
|
53
|
+
*/
|
|
54
|
+
autoHide?: number | false;
|
|
55
|
+
/** The smallest thumb, in pixels, so it never vanishes on a long document. Default 24. */
|
|
56
|
+
minThumbSize?: number;
|
|
57
|
+
/**
|
|
58
|
+
* A press on the track: `'page'` steps 90% of a view toward the pointer and repeats while
|
|
59
|
+
* held, stopping at the pointer; `'jump'` centers the thumb at the pointer and drags from
|
|
60
|
+
* there. Default `'page'`.
|
|
61
|
+
*/
|
|
62
|
+
trackPress?: 'page' | 'jump';
|
|
63
|
+
/**
|
|
64
|
+
* The track's class and style. The default style pins it to the right (y) or bottom (x) edge
|
|
65
|
+
* of the nearest positioned ancestor: the Stage, when it's in the overlay.
|
|
66
|
+
*/
|
|
67
|
+
class?: string;
|
|
68
|
+
style?: string;
|
|
69
|
+
thumbClass?: string;
|
|
70
|
+
thumbStyle?: string;
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CapabilityToken, EventHook } from '@embedpdf/core';
|
|
2
|
+
import { stageState } from '@embedpdf/plugin-stage';
|
|
3
|
+
import type { StageCapability, StageSettings } from '@embedpdf/plugin-stage';
|
|
4
|
+
import type { ScrollMetrics, StageHostCapability } from '@embedpdf/plugin-stage/contract/host';
|
|
5
|
+
import { type CurrentValue, type MaybeGetter } from '../runtime/values.svelte.js';
|
|
6
|
+
import { type StageTokenProp } from './stage-scope.js';
|
|
7
|
+
/** What `useStageState()` gives: the Stage page's State table. */
|
|
8
|
+
export type StageStateValue = (typeof stageState)['empty'];
|
|
9
|
+
/** A lens argument: a token, a function that returns one, or none (the scope's, else the main view). */
|
|
10
|
+
type LensArgument = MaybeGetter<StageTokenProp | undefined>;
|
|
11
|
+
/** The Stage's API (zoom, navigation, reveal, settings), for app chrome. */
|
|
12
|
+
export declare function useStage(token?: LensArgument): StageCapability;
|
|
13
|
+
/** Subscribe to one stage event while the component lives: `useStageEvent((stage) => stage.onZoomChanged, handler)`. */
|
|
14
|
+
export declare function useStageEvent<T>(select: (stage: StageCapability) => EventHook<T>, handler: (event: T) => void, token?: LensArgument): void;
|
|
15
|
+
/**
|
|
16
|
+
* The view's state: the zoom, the current page, the page count, the view rotation and the
|
|
17
|
+
* responsive rules that apply (declared once in `stageState`), as a reactive object
|
|
18
|
+
* (`state.zoomLevel`). With a selector, the value it picks as `{ current }`. Without a document
|
|
19
|
+
* it is `stageState.empty`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useStageState(token?: StageTokenProp): Readonly<StageStateValue>;
|
|
22
|
+
export declare function useStageState<Selected>(select: (state: StageStateValue) => Selected, token?: LensArgument): CurrentValue<Selected>;
|
|
23
|
+
/**
|
|
24
|
+
* The view's settings, as a reactive object, or the value a selector picks as `{ current }`. They
|
|
25
|
+
* belong to the view, so without a document there is none yet and this reads the defaults.
|
|
26
|
+
* Change them with `useStage().updateSettings()`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useStageSettings(token?: StageTokenProp): Readonly<StageSettings>;
|
|
29
|
+
export declare function useStageSettings<Selected>(select: (settings: StageSettings) => Selected, token?: LensArgument): CurrentValue<Selected>;
|
|
30
|
+
export declare const asHost: (token: CapabilityToken<StageCapability>) => CapabilityToken<StageHostCapability>;
|
|
31
|
+
/**
|
|
32
|
+
* The view's scroll position as a scrolling element has it: `scrollTop`, `scrollHeight`,
|
|
33
|
+
* `clientHeight` and their horizontal twins, in screen pixels, as a reactive object. The raw
|
|
34
|
+
* material for scroll UI of your own; all zero without a document.
|
|
35
|
+
*/
|
|
36
|
+
export declare function useScrollMetrics(token?: LensArgument): Readonly<ScrollMetrics>;
|
|
37
|
+
/** {@link useScrollMetrics} for the lens `lens()` names now, for a component whose token is a prop. */
|
|
38
|
+
export declare function scrollMetricsOf(lens: () => StageTokenProp): Readonly<ScrollMetrics>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Stage's readers: `useStage()` (the API), `useStageState()`, `useStageSettings()`,
|
|
3
|
+
* `useStageEvent()` and `useScrollMetrics()`. Each takes an optional token; without one it binds
|
|
4
|
+
* to the nearest `<StageScope>` / `<Stage>`, else the main view. A token that changes (a prop) is
|
|
5
|
+
* passed as a function: `useStage(() => token)`, and after a selector,
|
|
6
|
+
* `useStageState((state) => state.zoomLevel, () => token)`.
|
|
7
|
+
*/
|
|
8
|
+
import { shallowEqual } from '@embedpdf/core';
|
|
9
|
+
import { DEFAULT_SETTINGS, stageState } from '@embedpdf/plugin-stage';
|
|
10
|
+
import { documentScopeOf, useKernelBinding } from '../runtime/binding.svelte.js';
|
|
11
|
+
import { useCapability, useCapabilityEvent } from '../runtime/readers.svelte.js';
|
|
12
|
+
import { declaredState, readRecord } from '../runtime/state.svelte.js';
|
|
13
|
+
import { derivedValue, valueOf, } from '../runtime/values.svelte.js';
|
|
14
|
+
import { stageTokenOf } from './stage-scope.js';
|
|
15
|
+
/** The lens a reader with this argument binds to, read on every use. */
|
|
16
|
+
const lensOf = (token) => stageTokenOf(() => valueOf(token));
|
|
17
|
+
/** The Stage's API (zoom, navigation, reveal, settings), for app chrome. */
|
|
18
|
+
export function useStage(token) {
|
|
19
|
+
return useCapability(lensOf(token));
|
|
20
|
+
}
|
|
21
|
+
/** Subscribe to one stage event while the component lives: `useStageEvent((stage) => stage.onZoomChanged, handler)`. */
|
|
22
|
+
export function useStageEvent(select, handler, token) {
|
|
23
|
+
useCapabilityEvent(lensOf(token), select, handler);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A reader's arguments: a selector, then an optional lens; or just a token. A function first is
|
|
27
|
+
* always the selector, so a token that changes goes second, as a function.
|
|
28
|
+
*/
|
|
29
|
+
function selectorAndLens(first, second) {
|
|
30
|
+
return typeof first === 'function' ? [first, second] : [undefined, first ?? second];
|
|
31
|
+
}
|
|
32
|
+
export function useStageState(first, second) {
|
|
33
|
+
const [select, token] = selectorAndLens(first, second);
|
|
34
|
+
const binding = useKernelBinding();
|
|
35
|
+
const lens = lensOf(token);
|
|
36
|
+
const whole = declaredState(binding, lens, stageState.read, stageState.empty);
|
|
37
|
+
return readRecord(whole, Object.keys(stageState.empty), select);
|
|
38
|
+
}
|
|
39
|
+
export function useStageSettings(first, second) {
|
|
40
|
+
const [select, token] = selectorAndLens(first, second);
|
|
41
|
+
const binding = useKernelBinding();
|
|
42
|
+
const lens = lensOf(token);
|
|
43
|
+
const scoped = documentScopeOf();
|
|
44
|
+
const whole = derivedValue(() => {
|
|
45
|
+
binding.track();
|
|
46
|
+
const stage = binding.kernel.tryCapability(lens(), scoped() ?? undefined);
|
|
47
|
+
return stage?.getSettings() ?? DEFAULT_SETTINGS;
|
|
48
|
+
}, shallowEqual);
|
|
49
|
+
return readRecord(whole, Object.keys(DEFAULT_SETTINGS), select);
|
|
50
|
+
}
|
|
51
|
+
/** What a view with nothing to scroll measures: no document, or not placed yet. */
|
|
52
|
+
const NO_SCROLL = Object.freeze({
|
|
53
|
+
scrollLeft: 0,
|
|
54
|
+
scrollTop: 0,
|
|
55
|
+
scrollWidth: 0,
|
|
56
|
+
scrollHeight: 0,
|
|
57
|
+
clientWidth: 0,
|
|
58
|
+
clientHeight: 0,
|
|
59
|
+
scrollableX: false,
|
|
60
|
+
scrollableY: false,
|
|
61
|
+
});
|
|
62
|
+
// Scroll metrics live on the host lens (the same runtime token, typed wider): a scrollbar is
|
|
63
|
+
// chrome that drives the camera, not a document-level consumer.
|
|
64
|
+
export const asHost = (token) => token;
|
|
65
|
+
/**
|
|
66
|
+
* The view's scroll position as a scrolling element has it: `scrollTop`, `scrollHeight`,
|
|
67
|
+
* `clientHeight` and their horizontal twins, in screen pixels, as a reactive object. The raw
|
|
68
|
+
* material for scroll UI of your own; all zero without a document.
|
|
69
|
+
*/
|
|
70
|
+
export function useScrollMetrics(token) {
|
|
71
|
+
return scrollMetricsOf(lensOf(token));
|
|
72
|
+
}
|
|
73
|
+
/** {@link useScrollMetrics} for the lens `lens()` names now, for a component whose token is a prop. */
|
|
74
|
+
export function scrollMetricsOf(lens) {
|
|
75
|
+
const binding = useKernelBinding();
|
|
76
|
+
const scoped = documentScopeOf();
|
|
77
|
+
// The capability keeps the same metrics object until a number moves.
|
|
78
|
+
const whole = derivedValue(() => {
|
|
79
|
+
binding.track();
|
|
80
|
+
const stage = binding.kernel.tryCapability(asHost(lens()), scoped() ?? undefined);
|
|
81
|
+
return stage?.getScrollMetrics() ?? NO_SCROLL;
|
|
82
|
+
});
|
|
83
|
+
return readRecord(whole, Object.keys(NO_SCROLL), undefined);
|
|
84
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CapabilityToken } from '@embedpdf/core';
|
|
2
|
+
import type { StageCapability } from '@embedpdf/plugin-stage/contract';
|
|
3
|
+
/** Which stage lens to bind to: the main `StageToken`, or a second view's own token. */
|
|
4
|
+
export type StageTokenProp = CapabilityToken<StageCapability>;
|
|
5
|
+
/** For `<Stage>` and `<StageScope>`: bind everything inside to the lens `token()` names. */
|
|
6
|
+
export declare function setStageToken(token: () => StageTokenProp): void;
|
|
7
|
+
/**
|
|
8
|
+
* The lens a stage reader binds to, as a function read on every use: the explicit token, else
|
|
9
|
+
* the nearest `<StageScope>` / `<Stage>`, else the main lens.
|
|
10
|
+
*/
|
|
11
|
+
export declare function stageTokenOf(explicit?: () => StageTokenProp | undefined): () => StageTokenProp;
|
|
12
|
+
/**
|
|
13
|
+
* The lens stage chrome of your own binds to, as `{ current }`: `token`, else the nearest
|
|
14
|
+
* `<StageScope>` / `<Stage>`, else the main lens.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useStageToken(token?: StageTokenProp): {
|
|
17
|
+
readonly current: StageTokenProp;
|
|
18
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stage lens a subtree binds to, so the stage readers and the stage-bound chrome
|
|
3
|
+
* (`<Scrollbar>`, `<SelectionHandles>`) need no token. `<Stage>` provides its own lens to its
|
|
4
|
+
* pages and overlay; an app wraps a second lens (a thumbnail rail) in `<StageScope token>`. An
|
|
5
|
+
* explicit token still wins everywhere.
|
|
6
|
+
*
|
|
7
|
+
* Apart from `./Stage.svelte`, so entries that only need the scope never pull the stage surface.
|
|
8
|
+
*/
|
|
9
|
+
import { getContext, hasContext, setContext } from 'svelte';
|
|
10
|
+
import { StageToken } from '@embedpdf/plugin-stage/contract';
|
|
11
|
+
const STAGE_TOKEN = Symbol('embedpdf.stage-token');
|
|
12
|
+
/** For `<Stage>` and `<StageScope>`: bind everything inside to the lens `token()` names. */
|
|
13
|
+
export function setStageToken(token) {
|
|
14
|
+
setContext(STAGE_TOKEN, token);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The lens a stage reader binds to, as a function read on every use: the explicit token, else
|
|
18
|
+
* the nearest `<StageScope>` / `<Stage>`, else the main lens.
|
|
19
|
+
*/
|
|
20
|
+
export function stageTokenOf(explicit) {
|
|
21
|
+
const scoped = hasContext(STAGE_TOKEN) ? getContext(STAGE_TOKEN) : null;
|
|
22
|
+
return () => explicit?.() ?? scoped?.() ?? StageToken;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The lens stage chrome of your own binds to, as `{ current }`: `token`, else the nearest
|
|
26
|
+
* `<StageScope>` / `<Stage>`, else the main lens.
|
|
27
|
+
*/
|
|
28
|
+
export function useStageToken(token) {
|
|
29
|
+
const lens = stageTokenOf(() => token);
|
|
30
|
+
return {
|
|
31
|
+
get current() {
|
|
32
|
+
return lens();
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface TwoWayValue<T> {
|
|
2
|
+
/** The Stage's value now. */
|
|
3
|
+
stage: () => T;
|
|
4
|
+
/** The bound prop now; undefined while the owner gives none. */
|
|
5
|
+
bound: () => T | undefined;
|
|
6
|
+
/** Whether the Stage can take a value yet (it has a document). */
|
|
7
|
+
ready: () => boolean;
|
|
8
|
+
/** Write the Stage's value to the bound prop. */
|
|
9
|
+
write: (value: T) => void;
|
|
10
|
+
/** Move the Stage to the owner's value. */
|
|
11
|
+
apply: (value: T) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function syncTwoWay<T>(value: TwoWayValue<T>): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value the Stage and its owner both write, for `bind:page` and `bind:zoom`: the owner's
|
|
3
|
+
* value goes in when it differs from the Stage's, and the Stage's goes out when it changes.
|
|
4
|
+
*/
|
|
5
|
+
import { untrack } from 'svelte';
|
|
6
|
+
export function syncTwoWay(value) {
|
|
7
|
+
// In first: on mount, the owner's value is where the Stage goes, and only then does the
|
|
8
|
+
// Stage's own value come back out.
|
|
9
|
+
$effect(() => {
|
|
10
|
+
const wanted = value.bound();
|
|
11
|
+
if (wanted === undefined || !value.ready())
|
|
12
|
+
return;
|
|
13
|
+
untrack(() => {
|
|
14
|
+
if (!Object.is(wanted, value.stage()))
|
|
15
|
+
value.apply(wanted);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
let last = untrack(value.stage);
|
|
19
|
+
$effect(() => {
|
|
20
|
+
const current = value.stage();
|
|
21
|
+
if (Object.is(current, last))
|
|
22
|
+
return;
|
|
23
|
+
last = current;
|
|
24
|
+
untrack(() => value.write(current));
|
|
25
|
+
});
|
|
26
|
+
}
|
package/dist/stage.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @embedpdf/svelte/stage — the Stage and its readers.
|
|
3
|
+
*
|
|
4
|
+
* `<Stage>` lays out and positions the visible pages by the camera, and hands each one to its
|
|
5
|
+
* content: you bring the layers. The readers are the plugin's four, `useStage()` (the API),
|
|
6
|
+
* `useStageState()`, `useStageSettings()` and `useStageEvent()`; `<Scrollbar>` and
|
|
7
|
+
* `useScrollMetrics()` are the Stage's too.
|
|
8
|
+
*/
|
|
9
|
+
export * from '@embedpdf/plugin-stage';
|
|
10
|
+
export { default as Stage } from './stage/Stage.svelte';
|
|
11
|
+
export { default as StageScope } from './stage/StageScope.svelte';
|
|
12
|
+
export { default as Scrollbar } from './stage/Scrollbar.svelte';
|
|
13
|
+
export type { ScrollbarAxis, ScrollbarProps, StageProps } from './stage/props.js';
|
|
14
|
+
export { useStageToken } from './stage/stage-scope.js';
|
|
15
|
+
export type { StageTokenProp } from './stage/stage-scope.js';
|
|
16
|
+
export { useScrollMetrics, useStage, useStageEvent, useStageSettings, useStageState, } from './stage/readers.svelte.js';
|
|
17
|
+
export type { StageStateValue } from './stage/readers.svelte.js';
|
package/dist/stage.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @embedpdf/svelte/stage — the Stage and its readers.
|
|
3
|
+
*
|
|
4
|
+
* `<Stage>` lays out and positions the visible pages by the camera, and hands each one to its
|
|
5
|
+
* content: you bring the layers. The readers are the plugin's four, `useStage()` (the API),
|
|
6
|
+
* `useStageState()`, `useStageSettings()` and `useStageEvent()`; `<Scrollbar>` and
|
|
7
|
+
* `useScrollMetrics()` are the Stage's too.
|
|
8
|
+
*/
|
|
9
|
+
// Registration travels with the UI.
|
|
10
|
+
export * from '@embedpdf/plugin-stage';
|
|
11
|
+
export { default as Stage } from './stage/Stage.svelte';
|
|
12
|
+
export { default as StageScope } from './stage/StageScope.svelte';
|
|
13
|
+
export { default as Scrollbar } from './stage/Scrollbar.svelte';
|
|
14
|
+
export { useStageToken } from './stage/stage-scope.js';
|
|
15
|
+
export { useScrollMetrics, useStage, useStageEvent, useStageSettings, useStageState, } from './stage/readers.svelte.js';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stamp plugin's readers: `useStamp()` (the API), `useStampState()`, `useStampSettings()`,
|
|
3
|
+
* `useStampEvent()`, and the three a picker is built from: `useStampLibraries()`,
|
|
4
|
+
* `useStampAssets()` and `useStampAssetPreviewUrl()`.
|
|
5
|
+
*
|
|
6
|
+
* The plugin owns the libraries, their stamps and the cached previews; the one thing made here is
|
|
7
|
+
* the DOM resource a picker shows, the object URL of a stamp's preview.
|
|
8
|
+
*/
|
|
9
|
+
import type { EventHook } from '@embedpdf/core';
|
|
10
|
+
import type { StampAsset, StampAssetFilter, StampCapability, StampLibrary, StampLibraryFilter } from '@embedpdf/plugin-stamp';
|
|
11
|
+
import { type CurrentValue, type MaybeGetter } from '../runtime/values.svelte.js';
|
|
12
|
+
/**
|
|
13
|
+
* The stamp API. Libraries are shared by every document; the placing verbs (`armAsset`,
|
|
14
|
+
* `placeAsset`, …) act on the nearest `<DocumentScope>`'s document, else the active one. A handle:
|
|
15
|
+
* keep it whole and call through it, `stamp.armAsset(id)`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useStamp(): StampCapability;
|
|
18
|
+
/** Subscribe to one stamp event while the component lives: `useStampEvent((stamp) => stamp.onLibraryChanged, handler)`. */
|
|
19
|
+
export declare function useStampEvent<T>(select: (stamp: StampCapability) => EventHook<T>, handler: (event: T) => void): void;
|
|
20
|
+
/**
|
|
21
|
+
* The stamps' state for this component's document: the armed stamp (the page's State table,
|
|
22
|
+
* declared once in `stampState`), as a reactive object (`stampState.armedAsset`). With a
|
|
23
|
+
* selector, the value it picks as `{ current }`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const useStampState: import("../index.js").StateReader<{
|
|
26
|
+
armedAsset: StampAsset | null;
|
|
27
|
+
}>;
|
|
28
|
+
/** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. */
|
|
29
|
+
export declare const useStampSettings: import("../index.js").SettingsReader<import("@embedpdf/plugin-stamp").StampSettings & object>;
|
|
30
|
+
/**
|
|
31
|
+
* The libraries as `{ current }`, optionally of one kind or several (`{ kind: 'stamps' }`,
|
|
32
|
+
* `{ kind: ['stamps', 'legal-seals'] }`; a function to follow a prop). Every read is a new array,
|
|
33
|
+
* compared item by item, so the value changes only when a library is added, renamed or removed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useStampLibraries(filter?: MaybeGetter<StampLibraryFilter | undefined>): CurrentValue<readonly StampLibrary[]>;
|
|
36
|
+
/**
|
|
37
|
+
* The stamps as `{ current }`: one library's (`{ libraryId }`), one kind's or category's, or every
|
|
38
|
+
* stamp, in the order a picker shows them. A filter that changes is a function:
|
|
39
|
+
* `useStampAssets(() => ({ libraryId }))`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function useStampAssets(filter?: MaybeGetter<StampAssetFilter | undefined>): CurrentValue<readonly StampAsset[]>;
|
|
42
|
+
/**
|
|
43
|
+
* An image URL for a stamp's cached preview (a gallery thumbnail) as `{ current }`, or null while
|
|
44
|
+
* there is none. An id that changes is a function: `useStampAssetPreviewUrl(() => assetId)`.
|
|
45
|
+
*
|
|
46
|
+
* The plugin holds the preview's bytes; the URL is a DOM resource, so it is made here and revoked
|
|
47
|
+
* when the preview changes or the component goes away, the rule `<AnnotationLayer>` follows for
|
|
48
|
+
* the pictures it shows.
|
|
49
|
+
*/
|
|
50
|
+
export declare function useStampAssetPreviewUrl(assetId: MaybeGetter<string | null>): CurrentValue<string | null>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { StampToken, stampState } from '@embedpdf/plugin-stamp';
|
|
2
|
+
import { objectUrlOf } from '@embedpdf/web';
|
|
3
|
+
import { shallowArray, useCapability, useCapabilityEvent, useOptionalSelector, useSelector, } from '../runtime/readers.svelte.js';
|
|
4
|
+
import { settingsReader, stateReader } from '../runtime/state.svelte.js';
|
|
5
|
+
import { valueOf } from '../runtime/values.svelte.js';
|
|
6
|
+
/**
|
|
7
|
+
* The stamp API. Libraries are shared by every document; the placing verbs (`armAsset`,
|
|
8
|
+
* `placeAsset`, …) act on the nearest `<DocumentScope>`'s document, else the active one. A handle:
|
|
9
|
+
* keep it whole and call through it, `stamp.armAsset(id)`.
|
|
10
|
+
*/
|
|
11
|
+
export function useStamp() {
|
|
12
|
+
return useCapability(StampToken);
|
|
13
|
+
}
|
|
14
|
+
/** Subscribe to one stamp event while the component lives: `useStampEvent((stamp) => stamp.onLibraryChanged, handler)`. */
|
|
15
|
+
export function useStampEvent(select, handler) {
|
|
16
|
+
useCapabilityEvent(StampToken, select, handler);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The stamps' state for this component's document: the armed stamp (the page's State table,
|
|
20
|
+
* declared once in `stampState`), as a reactive object (`stampState.armedAsset`). With a
|
|
21
|
+
* selector, the value it picks as `{ current }`.
|
|
22
|
+
*/
|
|
23
|
+
export const useStampState = stateReader(stampState);
|
|
24
|
+
/** The stamp settings (`assetEngine`, `previewWidth`, `dynamic`), with or without a document. */
|
|
25
|
+
export const useStampSettings = settingsReader(StampToken);
|
|
26
|
+
/**
|
|
27
|
+
* The libraries as `{ current }`, optionally of one kind or several (`{ kind: 'stamps' }`,
|
|
28
|
+
* `{ kind: ['stamps', 'legal-seals'] }`; a function to follow a prop). Every read is a new array,
|
|
29
|
+
* compared item by item, so the value changes only when a library is added, renamed or removed.
|
|
30
|
+
*/
|
|
31
|
+
export function useStampLibraries(filter) {
|
|
32
|
+
return useSelector(StampToken, (stamp) => stamp.listLibraries(valueOf(filter)), shallowArray);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The stamps as `{ current }`: one library's (`{ libraryId }`), one kind's or category's, or every
|
|
36
|
+
* stamp, in the order a picker shows them. A filter that changes is a function:
|
|
37
|
+
* `useStampAssets(() => ({ libraryId }))`.
|
|
38
|
+
*/
|
|
39
|
+
export function useStampAssets(filter) {
|
|
40
|
+
return useSelector(StampToken, (stamp) => stamp.listAssets(valueOf(filter)), shallowArray);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An image URL for a stamp's cached preview (a gallery thumbnail) as `{ current }`, or null while
|
|
44
|
+
* there is none. An id that changes is a function: `useStampAssetPreviewUrl(() => assetId)`.
|
|
45
|
+
*
|
|
46
|
+
* The plugin holds the preview's bytes; the URL is a DOM resource, so it is made here and revoked
|
|
47
|
+
* when the preview changes or the component goes away, the rule `<AnnotationLayer>` follows for
|
|
48
|
+
* the pictures it shows.
|
|
49
|
+
*/
|
|
50
|
+
export function useStampAssetPreviewUrl(assetId) {
|
|
51
|
+
// The preview itself, read on every change: it follows the id, and a preview that arrives
|
|
52
|
+
// after the stamp does.
|
|
53
|
+
const preview = useOptionalSelector(StampToken, (stamp) => {
|
|
54
|
+
const id = valueOf(assetId);
|
|
55
|
+
return id ? stamp.getAssetPreview(id) : null;
|
|
56
|
+
}, null);
|
|
57
|
+
let url = $state(null);
|
|
58
|
+
$effect(() => {
|
|
59
|
+
const current = preview.current;
|
|
60
|
+
if (!current) {
|
|
61
|
+
url = null;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const objectUrl = objectUrlOf(current);
|
|
65
|
+
url = objectUrl.url;
|
|
66
|
+
return () => {
|
|
67
|
+
objectUrl.revoke();
|
|
68
|
+
url = null;
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
get current() {
|
|
73
|
+
return url;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
package/dist/stamp.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @embedpdf/svelte/stamp — stamps: libraries of marks you pick from and place.
|
|
3
|
+
*
|
|
4
|
+
* Thin by design: the plugin owns the libraries, their stamps and the cached previews. Placing
|
|
5
|
+
* needs no component here: an armed stamp rides the annotation plugin, whose `<AnnotationLayer>`
|
|
6
|
+
* draws the ghost under the pointer.
|
|
7
|
+
*
|
|
8
|
+
* const stamp = useStamp();
|
|
9
|
+
* const assets = useStampAssets(() => ({ libraryId })); // assets.current
|
|
10
|
+
* const stampState = useStampState(); // stampState.armedAsset
|
|
11
|
+
* await stamp.armAsset(assetId); // the next click places it
|
|
12
|
+
*/
|
|
13
|
+
export * from '@embedpdf/plugin-stamp';
|
|
14
|
+
export { indexedDbByteStore } from '@embedpdf/web';
|
|
15
|
+
export type { ByteStore } from '@embedpdf/web';
|
|
16
|
+
export { useStamp, useStampAssetPreviewUrl, useStampAssets, useStampEvent, useStampLibraries, useStampSettings, useStampState, } from './stamp/readers.svelte.js';
|
package/dist/stamp.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @embedpdf/svelte/stamp — stamps: libraries of marks you pick from and place.
|
|
3
|
+
*
|
|
4
|
+
* Thin by design: the plugin owns the libraries, their stamps and the cached previews. Placing
|
|
5
|
+
* needs no component here: an armed stamp rides the annotation plugin, whose `<AnnotationLayer>`
|
|
6
|
+
* draws the ghost under the pointer.
|
|
7
|
+
*
|
|
8
|
+
* const stamp = useStamp();
|
|
9
|
+
* const assets = useStampAssets(() => ({ libraryId })); // assets.current
|
|
10
|
+
* const stampState = useStampState(); // stampState.armedAsset
|
|
11
|
+
* await stamp.armAsset(assetId); // the next click places it
|
|
12
|
+
*/
|
|
13
|
+
// Registration travels with the UI.
|
|
14
|
+
export * from '@embedpdf/plugin-stamp';
|
|
15
|
+
// The browser store for `persistStampLibraries` / `restoreStampLibraries` (structurally the
|
|
16
|
+
// plugin's `StampLibraryStore`), written once in `@embedpdf/web`.
|
|
17
|
+
export { indexedDbByteStore } from '@embedpdf/web';
|
|
18
|
+
export { useStamp, useStampAssetPreviewUrl, useStampAssets, useStampEvent, useStampLibraries, useStampSettings, useStampState, } from './stamp/readers.svelte.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The default folded group: a <select> for `collapse: 'select'`, else a "More"-style button with a
|
|
3
|
+
menu of the group's commands.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import DefaultOverflowMenu from './DefaultOverflowMenu.svelte';
|
|
7
|
+
import DefaultOverflowTrigger from './DefaultOverflowTrigger.svelte';
|
|
8
|
+
import { groupMenuView } from '@embedpdf/core-ui';
|
|
9
|
+
import type { Orientation } from '@embedpdf/web';
|
|
10
|
+
import type { CollapsedGroupView } from './views.js';
|
|
11
|
+
import { BORDER, SURFACE } from './paint.js';
|
|
12
|
+
|
|
13
|
+
let { view, orientation }: { view: CollapsedGroupView; orientation: Orientation } = $props();
|
|
14
|
+
|
|
15
|
+
let isOpen = $state(false);
|
|
16
|
+
const active = $derived(view.commands.find((command) => command.active)?.id ?? '');
|
|
17
|
+
const menu = $derived(groupMenuView(view, isOpen, () => (isOpen = false)));
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
{#if view.collapse === 'select'}
|
|
21
|
+
<select
|
|
22
|
+
value={active}
|
|
23
|
+
onchange={(event) => view.execute(event.currentTarget.value)}
|
|
24
|
+
style:padding="4px 6px"
|
|
25
|
+
style:font="inherit"
|
|
26
|
+
style:border-radius="4px"
|
|
27
|
+
style:border="1px solid {BORDER}"
|
|
28
|
+
style:background={SURFACE}
|
|
29
|
+
>
|
|
30
|
+
{#each view.commands as command (command.id)}
|
|
31
|
+
<option value={command.id} disabled={!command.enabled}>{command.label}</option>
|
|
32
|
+
{/each}
|
|
33
|
+
</select>
|
|
34
|
+
{:else}
|
|
35
|
+
<span style="position: relative; display: inline-flex">
|
|
36
|
+
<DefaultOverflowTrigger {isOpen} toggle={() => (isOpen = !isOpen)} />
|
|
37
|
+
<DefaultOverflowMenu view={menu} {orientation} />
|
|
38
|
+
</span>
|
|
39
|
+
{/if}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Orientation } from '@embedpdf/web';
|
|
2
|
+
import type { CollapsedGroupView } from './views.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
view: CollapsedGroupView;
|
|
5
|
+
orientation: Orientation;
|
|
6
|
+
};
|
|
7
|
+
declare const DefaultCollapsed: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type DefaultCollapsed = ReturnType<typeof DefaultCollapsed>;
|
|
9
|
+
export default DefaultCollapsed;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The default command button: the command's label in every variant (icons are the app's), pressed
|
|
3
|
+
when the command is active.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import type { ResolvedCommand } from '@embedpdf/plugin-commands/contract';
|
|
7
|
+
import { ACTIVE, BORDER } from './paint.js';
|
|
8
|
+
|
|
9
|
+
let { command, run }: { command: ResolvedCommand; run: () => void } = $props();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<button
|
|
13
|
+
type="button"
|
|
14
|
+
onclick={run}
|
|
15
|
+
disabled={!command.enabled}
|
|
16
|
+
aria-pressed={command.active || undefined}
|
|
17
|
+
aria-haspopup={command.menu ? 'menu' : undefined}
|
|
18
|
+
title={command.label}
|
|
19
|
+
style:display="inline-flex"
|
|
20
|
+
style:align-items="center"
|
|
21
|
+
style:gap="4px"
|
|
22
|
+
style:padding="4px 8px"
|
|
23
|
+
style:white-space="nowrap"
|
|
24
|
+
style:color="inherit"
|
|
25
|
+
style:font="inherit"
|
|
26
|
+
style:background={command.active ? ACTIVE : 'transparent'}
|
|
27
|
+
style:border="1px solid {BORDER}"
|
|
28
|
+
style:border-radius="4px"
|
|
29
|
+
style:cursor={command.enabled ? 'pointer' : 'default'}
|
|
30
|
+
style:opacity={command.enabled ? 1 : 0.4}
|
|
31
|
+
>
|
|
32
|
+
{command.label}
|
|
33
|
+
</button>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ResolvedCommand } from '@embedpdf/plugin-commands/contract';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
command: ResolvedCommand;
|
|
4
|
+
run: () => void;
|
|
5
|
+
};
|
|
6
|
+
declare const DefaultCommand: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type DefaultCommand = ReturnType<typeof DefaultCommand>;
|
|
8
|
+
export default DefaultCommand;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The default button of a group that shed items: a chevron opening a menu of what it shed, lit
|
|
3
|
+
while the active item is in there.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import DefaultOverflowMenu from './DefaultOverflowMenu.svelte';
|
|
7
|
+
import { groupMenuView } from '@embedpdf/core-ui';
|
|
8
|
+
import type { Orientation } from '@embedpdf/web';
|
|
9
|
+
import type { GroupDisclosureView } from './views.js';
|
|
10
|
+
import { ACTIVE, BORDER } from './paint.js';
|
|
11
|
+
|
|
12
|
+
let { view, orientation }: { view: GroupDisclosureView; orientation: Orientation } = $props();
|
|
13
|
+
|
|
14
|
+
let isOpen = $state(false);
|
|
15
|
+
const someActive = $derived(view.commands.some((command) => command.active));
|
|
16
|
+
const menu = $derived(groupMenuView(view, isOpen, () => (isOpen = false)));
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<span style="position: relative; display: inline-flex">
|
|
20
|
+
<button
|
|
21
|
+
type="button"
|
|
22
|
+
onclick={() => (isOpen = !isOpen)}
|
|
23
|
+
aria-haspopup="menu"
|
|
24
|
+
aria-expanded={isOpen}
|
|
25
|
+
title="More"
|
|
26
|
+
style:display="inline-flex"
|
|
27
|
+
style:align-items="center"
|
|
28
|
+
style:padding="4px 6px"
|
|
29
|
+
style:color="inherit"
|
|
30
|
+
style:font="inherit"
|
|
31
|
+
style:border="1px solid {BORDER}"
|
|
32
|
+
style:border-radius="4px"
|
|
33
|
+
style:background={isOpen || someActive ? ACTIVE : 'transparent'}
|
|
34
|
+
style:cursor="pointer"
|
|
35
|
+
>
|
|
36
|
+
▾
|
|
37
|
+
</button>
|
|
38
|
+
<DefaultOverflowMenu view={menu} {orientation} />
|
|
39
|
+
</span>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Orientation } from '@embedpdf/web';
|
|
2
|
+
import type { GroupDisclosureView } from './views.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
view: GroupDisclosureView;
|
|
5
|
+
orientation: Orientation;
|
|
6
|
+
};
|
|
7
|
+
declare const DefaultGroupTrigger: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type DefaultGroupTrigger = ReturnType<typeof DefaultGroupTrigger>;
|
|
9
|
+
export default DefaultGroupTrigger;
|