@embedpdf/react 3.0.0-next.13 → 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/dist/AnnotationList-CkijRHet-HEFNUIZe.d.cts +877 -0
- package/dist/AnnotationList-CkijRHet-HEFNUIZe.d.ts +877 -0
- package/dist/actions.cjs +25 -5
- package/dist/actions.cjs.map +1 -1
- package/dist/actions.d.cts +18 -5
- package/dist/actions.d.ts +18 -5
- package/dist/actions.js +22 -6
- package/dist/actions.js.map +1 -1
- package/dist/anchored-DeX95xSd.d.ts +85 -0
- package/dist/anchored-DzN3JywS.d.cts +85 -0
- package/dist/anchored.cjs +71 -28
- package/dist/anchored.cjs.map +1 -1
- package/dist/anchored.d.cts +2 -45
- package/dist/anchored.d.ts +2 -45
- package/dist/anchored.js +56 -19
- package/dist/anchored.js.map +1 -1
- package/dist/annotation-B48UT2ln.d.ts +302 -0
- package/dist/annotation-C1ttM8Wj.js +708 -0
- package/dist/annotation-C1ttM8Wj.js.map +1 -0
- package/dist/annotation-C9dVwo9b.d.cts +302 -0
- package/dist/annotation-Dex5EBda.cjs +830 -0
- package/dist/annotation-Dex5EBda.cjs.map +1 -0
- package/dist/annotation.cjs +20 -783
- package/dist/annotation.d.cts +2 -2
- package/dist/annotation.d.ts +2 -2
- package/dist/annotation.js +2 -768
- package/dist/commands.cjs +68 -28
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +37 -10
- package/dist/commands.d.ts +37 -10
- package/dist/commands.js +68 -31
- package/dist/commands.js.map +1 -1
- package/dist/form-55izw0jS.js +511 -0
- package/dist/form-55izw0jS.js.map +1 -0
- package/dist/form-BNqQfGGH.cjs +548 -0
- package/dist/form-BNqQfGGH.cjs.map +1 -0
- package/dist/form.cjs +5 -5
- package/dist/form.d.cts +32 -25
- package/dist/form.d.ts +32 -25
- package/dist/form.js +2 -3
- package/dist/history.cjs +38 -0
- package/dist/history.cjs.map +1 -0
- package/dist/history.d.cts +27 -0
- package/dist/history.d.ts +27 -0
- package/dist/history.js +27 -0
- package/dist/history.js.map +1 -0
- package/dist/i18n.cjs +26 -30
- package/dist/i18n.cjs.map +1 -1
- package/dist/i18n.d.cts +24 -21
- package/dist/i18n.d.ts +24 -21
- package/dist/i18n.js +24 -31
- package/dist/i18n.js.map +1 -1
- package/dist/index.cjs +213 -57
- package/dist/index.d.cts +32 -31
- package/dist/index.d.ts +32 -31
- package/dist/index.js +33 -29
- package/dist/inert-CmBEbKCn.cjs +19 -0
- package/dist/inert-CmBEbKCn.cjs.map +1 -0
- package/dist/inert-D8fkennb.js +14 -0
- package/dist/inert-D8fkennb.js.map +1 -0
- package/dist/interaction.cjs +48 -102
- package/dist/interaction.cjs.map +1 -1
- package/dist/interaction.d.cts +23 -32
- package/dist/interaction.d.ts +23 -32
- package/dist/interaction.js +33 -102
- package/dist/interaction.js.map +1 -1
- package/dist/link.cjs +65 -104
- package/dist/link.cjs.map +1 -1
- package/dist/link.d.cts +21 -16
- package/dist/link.d.ts +22 -17
- package/dist/link.js +67 -107
- package/dist/link.js.map +1 -1
- package/dist/measurement.cjs +56 -0
- package/dist/measurement.cjs.map +1 -0
- package/dist/measurement.d.cts +38 -0
- package/dist/measurement.d.ts +38 -0
- package/dist/measurement.js +42 -0
- package/dist/measurement.js.map +1 -0
- package/dist/metadata.cjs +20 -7
- package/dist/metadata.cjs.map +1 -1
- package/dist/metadata.d.cts +22 -7
- package/dist/metadata.d.ts +22 -7
- package/dist/metadata.js +20 -10
- package/dist/metadata.js.map +1 -1
- package/dist/page-edit.cjs +7 -3
- package/dist/page-edit.cjs.map +1 -1
- package/dist/page-edit.d.cts +6 -2
- package/dist/page-edit.d.ts +6 -2
- package/dist/page-edit.js +7 -4
- package/dist/page-edit.js.map +1 -1
- package/dist/page-layers-Bkaaz8Zf.js +26 -0
- package/dist/page-layers-Bkaaz8Zf.js.map +1 -0
- package/dist/page-layers-BloZDoOV.cjs +37 -0
- package/dist/page-layers-BloZDoOV.cjs.map +1 -0
- package/dist/page-view.cjs +89 -82
- package/dist/page-view.cjs.map +1 -1
- package/dist/page-view.d.cts +14 -7
- package/dist/page-view.d.ts +18 -11
- package/dist/page-view.js +86 -81
- package/dist/page-view.js.map +1 -1
- package/dist/redaction.cjs +30 -15
- package/dist/redaction.cjs.map +1 -1
- package/dist/redaction.d.cts +27 -9
- package/dist/redaction.d.ts +27 -9
- package/dist/redaction.js +29 -18
- package/dist/redaction.js.map +1 -1
- package/dist/render.cjs +71 -46
- package/dist/render.cjs.map +1 -1
- package/dist/render.d.cts +17 -5
- package/dist/render.d.ts +17 -5
- package/dist/render.js +70 -49
- package/dist/render.js.map +1 -1
- package/dist/runtime-B6xcPsEb.js +398 -0
- package/dist/runtime-B6xcPsEb.js.map +1 -0
- package/dist/runtime-DBEBlpQV.d.cts +237 -0
- package/dist/runtime-V3MVMb91.d.ts +237 -0
- package/dist/runtime-fzpGv78v.cjs +555 -0
- package/dist/runtime-fzpGv78v.cjs.map +1 -0
- package/dist/runtime.cjs +45 -324
- package/dist/runtime.d.cts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +2 -306
- package/dist/search.cjs +81 -50
- package/dist/search.cjs.map +1 -1
- package/dist/search.d.cts +36 -24
- package/dist/search.d.ts +36 -24
- package/dist/search.js +81 -53
- package/dist/search.js.map +1 -1
- package/dist/selection.cjs +105 -108
- package/dist/selection.cjs.map +1 -1
- package/dist/selection.d.cts +54 -26
- package/dist/selection.d.ts +56 -28
- package/dist/selection.js +103 -110
- package/dist/selection.js.map +1 -1
- package/dist/shell.cjs +36 -21
- package/dist/shell.cjs.map +1 -1
- package/dist/shell.d.cts +32 -17
- package/dist/shell.d.ts +32 -17
- package/dist/shell.js +36 -24
- package/dist/shell.js.map +1 -1
- package/dist/signature.cjs +29 -48
- package/dist/signature.cjs.map +1 -1
- package/dist/signature.d.cts +26 -26
- package/dist/signature.d.ts +26 -26
- package/dist/signature.js +30 -48
- package/dist/signature.js.map +1 -1
- package/dist/stage-BIG6aeVd.cjs +369 -0
- package/dist/stage-BIG6aeVd.cjs.map +1 -0
- package/dist/stage-ByFPD-Fv.d.cts +117 -0
- package/dist/stage-DaboaheR.d.ts +117 -0
- package/dist/stage-DoVekb83.js +302 -0
- package/dist/stage-DoVekb83.js.map +1 -0
- package/dist/stage-scope-CQgCuf1w.cjs +46 -0
- package/dist/stage-scope-CQgCuf1w.cjs.map +1 -0
- package/dist/stage-scope-D7ZeNduT.js +23 -0
- package/dist/stage-scope-D7ZeNduT.js.map +1 -0
- package/dist/stage.cjs +12 -235
- package/dist/stage.d.cts +2 -116
- package/dist/stage.d.ts +2 -116
- package/dist/stage.js +3 -228
- package/dist/stamp.cjs +41 -35
- package/dist/stamp.cjs.map +1 -1
- package/dist/stamp.d.cts +25 -18
- package/dist/stamp.d.ts +25 -18
- package/dist/stamp.js +40 -37
- package/dist/stamp.js.map +1 -1
- package/dist/state-0K1I5cM4.d.cts +29 -0
- package/dist/state-0K1I5cM4.d.ts +29 -0
- package/dist/state-CbgxhwLA.js +62 -0
- package/dist/state-CbgxhwLA.js.map +1 -0
- package/dist/state-CsfZy_Eq.cjs +73 -0
- package/dist/state-CsfZy_Eq.cjs.map +1 -0
- package/dist/svg-shapes-Dm1yTR1b.js +40 -0
- package/dist/svg-shapes-Dm1yTR1b.js.map +1 -0
- package/dist/svg-shapes-zo0GNkc9.cjs +53 -0
- package/dist/svg-shapes-zo0GNkc9.cjs.map +1 -0
- package/dist/toolbar.cjs +297 -295
- package/dist/toolbar.cjs.map +1 -1
- package/dist/toolbar.d.cts +58 -68
- package/dist/toolbar.d.ts +67 -77
- package/dist/toolbar.js +271 -293
- package/dist/toolbar.js.map +1 -1
- package/dist/view-manager.cjs +34 -0
- package/dist/view-manager.cjs.map +1 -0
- package/dist/view-manager.d.cts +21 -0
- package/dist/view-manager.d.ts +21 -0
- package/dist/view-manager.js +23 -0
- package/dist/view-manager.js.map +1 -0
- package/package.json +41 -38
- package/dist/AnnotationListSnapshot-D3mFut1e-C_GMpK25.d.cts +0 -546
- package/dist/AnnotationListSnapshot-D3mFut1e-C_GMpK25.d.ts +0 -546
- package/dist/annotation-BCED_p9H.d.cts +0 -160
- package/dist/annotation-anchors-CetwM1g7.js +0 -15
- package/dist/annotation-anchors-CetwM1g7.js.map +0 -1
- package/dist/annotation-anchors-DuYRBJLl.cjs +0 -26
- package/dist/annotation-anchors-DuYRBJLl.cjs.map +0 -1
- package/dist/annotation-hooks-BB5ZhPpf.cjs +0 -16
- package/dist/annotation-hooks-BB5ZhPpf.cjs.map +0 -1
- package/dist/annotation-hooks-Df8EmzDO.js +0 -11
- package/dist/annotation-hooks-Df8EmzDO.js.map +0 -1
- package/dist/annotation-k38KDlIZ.d.ts +0 -160
- package/dist/annotation-menu.cjs +0 -64
- package/dist/annotation-menu.cjs.map +0 -1
- package/dist/annotation-menu.d.cts +0 -33
- package/dist/annotation-menu.d.ts +0 -33
- package/dist/annotation-menu.js +0 -48
- package/dist/annotation-menu.js.map +0 -1
- package/dist/annotation.cjs.map +0 -1
- package/dist/annotation.js.map +0 -1
- package/dist/form-BVumS7up.cjs +0 -926
- package/dist/form-BVumS7up.cjs.map +0 -1
- package/dist/form-CK3mp99m.js +0 -895
- package/dist/form-CK3mp99m.js.map +0 -1
- package/dist/rolldown-runtime-BBjsoOtd.js +0 -27
- package/dist/runtime-DE76hlnl.d.ts +0 -216
- package/dist/runtime-umHA_xHt.d.cts +0 -216
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.js.map +0 -1
- package/dist/scrollbar.cjs +0 -241
- package/dist/scrollbar.cjs.map +0 -1
- package/dist/scrollbar.d.cts +0 -42
- package/dist/scrollbar.d.ts +0 -42
- package/dist/scrollbar.js +0 -213
- package/dist/scrollbar.js.map +0 -1
- package/dist/stage.cjs.map +0 -1
- package/dist/stage.js.map +0 -1
- package/dist/views.cjs +0 -35
- package/dist/views.cjs.map +0 -1
- package/dist/views.d.cts +0 -21
- package/dist/views.d.ts +0 -21
- package/dist/views.js +0 -27
- package/dist/views.js.map +0 -1
package/dist/selection.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.cjs","names":["usePage","useCapability","SelectionHostToken","useSelector","shallowArray","SelectionToken","Anchored","StageToken","useOptionalCapability","HANDLE_PAD","HANDLE_HEAD","HANDLE_BAR"],"sources":["../src/selection.tsx"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-selection.\n *\n * <SelectionLayer> is a dumb renderer: it warms the page's geometry on mount,\n * reads the content-space highlight rects from the capability, and paints them —\n * mapping each rect through PageContext.toPixels (the same path markers use).\n * Zero pointer handling here; that's the PagePointerSource + the hub.\n *\n * The layer resolves the HOST lens (`/internal`: geometry warming, the\n * highlight handshake) — the adapter is exactly what that entry exists for.\n * `useSelection()` hands app code the PUBLIC lens only.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-selection';\n// The clipboard side effect lives in @embedpdf/web (the plugin is DOM-free);\n// re-exported here so app code has one import for the whole feature.\nexport { copySelection } from '@embedpdf/web';\nimport * as React from 'react';\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { textQuadEquals } from '@embedpdf/core-geometry';\nimport type { CapabilityToken } from '@embedpdf/core';\nimport {\n HANDLE_BAR,\n HANDLE_HEAD,\n HANDLE_PAD,\n SelectionToken,\n createSelectionHandleDrag,\n selectionHandleGeom,\n type SelectionHandleEndpoint,\n type SelectionHandleView,\n type SelectionMenuAnchor,\n} from '@embedpdf/plugin-selection';\nimport { SelectionToken as SelectionHostToken } from '@embedpdf/plugin-selection/internal';\nimport { StageToken, type StageCapability } from '@embedpdf/plugin-stage/contract';\nimport {\n attachSelectionHandle,\n wireSelectionClipboard,\n type SelectionClipboardOptions,\n} from '@embedpdf/web';\nimport { Anchored, type AnchoredPlacement } from './anchored';\nimport {\n shallowArray,\n useCapability,\n useKernelValue,\n useOptionalCapability,\n usePage,\n useSelector,\n} from './runtime';\n\nexport interface SelectionLayerProps {\n /** Highlight colour (default: translucent blue). */\n color?: string;\n}\n\nexport function SelectionLayer({ color = 'rgba(33, 150, 243, 0.35)' }: SelectionLayerProps) {\n const page = usePage();\n const selection = useCapability(SelectionHostToken);\n const segments = useSelector(\n SelectionHostToken,\n (c) => c.segmentsForPage(page.pon),\n shallowArray,\n );\n // A consumer (e.g. a markup tool drawing its own preview) can take over the\n // selection visual; when it does, we render nothing so the two never overlap.\n const visible = useSelector(SelectionHostToken, (c) => c.highlightVisible());\n\n // Warm this page's text geometry as soon as it's on screen, so the first\n // pointer-down can hit-test without waiting on the engine round-trip.\n // (A no-op without doc.text.select — nothing warms, nothing renders.)\n useEffect(() => {\n selection.ensurePage(page.pon);\n }, [selection, page.pon]);\n\n if (!visible) return null;\n\n return (\n <svg\n style={{\n position: 'absolute',\n inset: 0,\n width: '100%',\n height: '100%',\n overflow: 'visible',\n pointerEvents: 'none',\n }}\n >\n {segments.map((s, i) => {\n // content space → un-rotated content view px (rides the page's CSS\n // rotation). An affine map, so mapping the four corners is exact —\n // upright segments render pixel-identical to the old div-per-rect.\n const ring = [s.quad.upperStart, s.quad.upperEnd, s.quad.lowerEnd, s.quad.lowerStart].map(\n (p) => page.transform.toPixels(p),\n );\n return (\n <polygon key={i} points={ring.map((p) => `${p.x},${p.y}`).join(' ')} fill={color} />\n );\n })}\n </svg>\n );\n}\n\n/** The PUBLIC selection capability (select(), readText(), canCopy(), …) for\n * app chrome — toolbars, context menus, automation. */\nexport function useSelection() {\n return useCapability(SelectionToken);\n}\n\n/** Structural equality for the selection's menu anchor — keeps the menu from\n * re-rendering on unrelated dispatches (the capability returns a fresh\n * object each call). */\nconst sameMenuAnchor = (\n a: SelectionMenuAnchor | null,\n b: SelectionMenuAnchor | null,\n): boolean => {\n if (a === b) return true;\n if (!a || !b) return false;\n return (\n a.pon === b.pon &&\n a.bounds.x === b.bounds.x &&\n a.bounds.y === b.bounds.y &&\n a.bounds.width === b.bounds.width &&\n a.bounds.height === b.bounds.height\n );\n};\n\nexport interface SelectionMenuProps {\n children: React.ReactNode;\n /** Gap in screen px between the selection and the menu (default 8). */\n gap?: number;\n /** Where to place the menu relative to the selection. Default 'top'. */\n placement?: AnchoredPlacement;\n}\n\n/**\n * Floats over the current TEXT selection (one anchor regardless of\n * cross-page selection; it rides the gesture's end page) — and only once the\n * selection SETTLES: hidden while `isSelecting()` (mid-drag), it appears at\n * pointer-up; programmatic selections show immediately (born settled). Works\n * under `<Stage>` (mount in the overlay slot) and `<PageView>` alike — the\n * surface provides the projection. Compose the contents from hooks:\n * `useSelection()` for copy/clear, `useAnnotation()` for\n * `markupFromSelection('highlight')`, `copySelection` for the clipboard.\n * For live-follow UI during the drag, compose `<Anchored>` with\n * `menuAnchor()` yourself — the primitive carries no policy.\n */\nexport function SelectionMenu({ children, gap = 8, placement = 'top' }: SelectionMenuProps) {\n const selecting = useSelector(SelectionToken, (c) => c.isSelecting());\n const anchor = useSelector(SelectionToken, (c) => c.menuAnchor(), sameMenuAnchor);\n if (selecting || !anchor) return null;\n return (\n <Anchored anchor={anchor} placement={placement} gap={gap}>\n {children}\n </Anchored>\n );\n}\n\n// ── selection handles (the touch affordance) ────────────────────────────────\n//\n// Policy lives out of this file, per the layering razor: the geometry and the\n// drag session are `@embedpdf/plugin-selection`'s pure `handles` module (one\n// source for every adapter), the native listener mechanics are\n// `@embedpdf/web`'s `attachSelectionHandle` (the down-shield timing subtlety\n// lives ONCE), and this component keeps what only React can do —\n// subscriptions, markup, theming.\n\ninterface Endpoints {\n start: SelectionHandleEndpoint;\n end: SelectionHandleEndpoint;\n}\nconst sameEndpoints = (a: Endpoints | null, b: Endpoints | null): boolean => {\n if (a === b) return true;\n if (!a || !b) return false;\n return (\n a.start.pon === b.start.pon &&\n a.end.pon === b.end.pon &&\n a.start.advance === b.start.advance &&\n a.end.advance === b.end.advance &&\n // corner-wise, so a boundary that ROTATES without moving its bounding box\n // still re-renders (an AABB comparison would call that \"unchanged\")\n textQuadEquals(a.start.glyphQuad, b.start.glyphQuad) &&\n textQuadEquals(a.end.glyphQuad, b.end.glyphQuad)\n );\n};\n\n/** The plugin's structural view over this Stage: point-exact projection in,\n * page resolution out. (`pageRectToScreen` is the AABB projector — upright\n * overlays only — and would collapse exactly the orientation handles need.) */\nconst handleView = (stage: StageCapability): SelectionHandleView => ({\n toOverlay: (pon, pt) => {\n const world = stage.pageToWorld(pon, pt);\n return world ? stage.toScreen(world) : null;\n },\n pageAt: (overlay) => stage.pageAt(overlay),\n pointOnPage: (pon, overlay) => stage.pointOnPage(pon, overlay),\n});\n\nexport interface SelectionHandlesProps {\n /** Handle colour (default: the selection blue). */\n color?: string;\n /** The stage lens hosting this overlay (default: the main StageToken). */\n token?: CapabilityToken<StageCapability>;\n}\n\n/**\n * iOS-style draggable selection handles. Each is drawn the way the platform\n * draws them: a thin caret BAR that forms the selection's own start/end edge\n * — the boundary glyph's oriented edge, so rotated text and rotated pages\n * carry the handle with them — capped by a screen-constant circle, above the\n * first line at the start, below the last line at the end.\n *\n * On touch, where a caret drag isn't available, the handles ARE the way to\n * grow or shrink a selection: a long-press selects a word, then each handle\n * extends from the OPPOSITE endpoint, snapping to glyphs and crossing pages\n * exactly like a pointer drag — it rides the same `beginAt`/`extendTo`\n * gesture path, so highlights, menus, and commit signals all behave\n * identically. Mount in the `<Stage>` overlay slot next to `<SelectionMenu>`;\n * outside a Stage it renders nothing (a `PageView` has no camera to project\n * through). Pointer-isolated, so grabbing a handle never pans the stage.\n */\nexport function SelectionHandles({ color = '#2196f3', token = StageToken }: SelectionHandlesProps) {\n const host = useCapability(SelectionHostToken);\n const stage = useOptionalCapability(token);\n const selecting = useSelector(SelectionToken, (c) => c.isSelecting());\n const visible = useSelector(SelectionHostToken, (c) => c.highlightVisible());\n const endpoints = useSelector(\n SelectionHostToken,\n (c): Endpoints | null => {\n const s = c.snapshot();\n if (!s.start || !s.end) return null;\n return {\n start: { pon: s.start.pon, glyphQuad: s.start.glyphQuad, advance: s.start.advance },\n end: { pon: s.end.pon, glyphQuad: s.end.glyphQuad, advance: s.end.advance },\n };\n },\n sameEndpoints,\n );\n // The handles are positioned by PROJECTING the endpoint corners through the\n // camera, so they must re-render whenever the camera moves — visiblePages is\n // the stage's reference-stable revision for exactly that (the same value the\n // page surfaces re-render on, so handle and highlight move in one commit).\n useKernelValue(() => stage?.visiblePages() ?? null);\n const [dragging, setDragging] = useState<'start' | 'end' | null>(null);\n // The web binder's `arm` must read the CURRENT endpoints/stage at pointer\n // down, not the ones captured when the listener attached — a stable ref\n // callback with a live arm-source is the standard escape from that.\n const armSource = useRef<{ stage: StageCapability; endpoints: Endpoints } | null>(null);\n armSource.current = stage && endpoints ? { stage, endpoints } : null;\n const bindHandle = useMemo(() => {\n const detach: Partial<Record<'start' | 'end', () => void>> = {};\n const make = (role: 'start' | 'end') => (el: HTMLDivElement | null) => {\n detach[role]?.();\n delete detach[role];\n if (!el) return;\n detach[role] = attachSelectionHandle(el, {\n arm: () => {\n const src = armSource.current;\n if (!src) return null;\n const view = handleView(src.stage);\n const geom = selectionHandleGeom(view, src.endpoints[role], role);\n if (!geom) return null;\n const opposite = src.endpoints[role === 'start' ? 'end' : 'start'];\n const drag = createSelectionHandleDrag(\n host,\n view,\n opposite,\n src.endpoints[role].pon,\n );\n setDragging(role);\n return {\n // the point the user grabbed: the bar's midpoint\n base: {\n x: (geom.bar.from.x + geom.bar.to.x) / 2,\n y: (geom.bar.from.y + geom.bar.to.y) / 2,\n },\n session: {\n move: drag.move,\n end: () => {\n drag.end(); // settle → menu reappears, onCommit fires\n setDragging(null);\n },\n },\n };\n },\n });\n };\n return { start: make('start'), end: make('end') };\n }, [host]);\n\n if (!stage || !endpoints || !visible) return null;\n // Hidden while a pointer drag-select is in flight (like the menu) — but a\n // HANDLE drag is itself a selection gesture, so it keeps its handles.\n if (selecting && !dragging) return null;\n const view = handleView(stage);\n\n const renderHandle = (role: 'start' | 'end') => {\n const geom = selectionHandleGeom(view, endpoints[role], role);\n if (!geom) return null; // endpoint page not laid out right now\n // The shell is laid out UPRIGHT in its own frame — bar of the edge's\n // length, head stacked above (start) or below (end) — then rotated onto\n // the projected edge. The pivot is the bar's ascent-side tip, the one\n // point that must land exactly on the glyph corner.\n const barTop = HANDLE_PAD + (role === 'start' ? HANDLE_HEAD : 0);\n const pivotX = HANDLE_PAD + HANDLE_BAR / 2;\n return (\n <div\n key={role}\n ref={bindHandle[role]}\n style={{\n position: 'absolute',\n left: geom.bar.from.x - pivotX,\n top: geom.bar.from.y - barTop,\n width: HANDLE_BAR + 2 * HANDLE_PAD,\n height: geom.length + HANDLE_HEAD + 2 * HANDLE_PAD,\n // Upright text carries NO transform — pixel-identical to an\n // axis-aligned box (the geometry's float-noise guard decides).\n ...(geom.upright\n ? null\n : {\n transform: `rotate(${geom.rotation}deg)`,\n transformOrigin: `${pivotX}px ${barTop}px`,\n }),\n touchAction: 'none',\n cursor: 'grab',\n pointerEvents: 'auto',\n }}\n >\n {/* the caret bar — the selection's own edge, spanning the glyph's ink\n height (which is why it stays the text's height at any tilt) */}\n <div\n style={{\n position: 'absolute',\n left: HANDLE_PAD,\n top: barTop,\n width: HANDLE_BAR,\n height: geom.length,\n background: color,\n borderRadius: HANDLE_BAR / 2,\n }}\n />\n {/* the head — flush against the bar, beyond the ascent at the start and\n past the baseline at the end, in the TEXT's frame */}\n <div\n style={{\n position: 'absolute',\n left: pivotX - HANDLE_HEAD / 2,\n top: role === 'start' ? HANDLE_PAD : HANDLE_PAD + geom.length,\n width: HANDLE_HEAD,\n height: HANDLE_HEAD,\n borderRadius: '50%',\n background: color,\n boxShadow: '0 1px 4px rgba(0, 0, 0, 0.35)',\n }}\n />\n </div>\n );\n };\n\n return (\n <>\n {renderHandle('start')}\n {renderHandle('end')}\n </>\n );\n}\n\n\nexport type SelectionClipboardProps = Pick<SelectionClipboardOptions, 'prefetch'>;\n\n/**\n * Mount ONCE per viewer to wire clipboard copy: prefetches the selected text\n * when the selection settles, answers the native `copy` event synchronously,\n * and falls back to the async Clipboard API for ctrl/cmd+C when the page has\n * no DOM selection. Renders nothing. For a toolbar Copy button, call\n * `copySelection(useSelection())` from its click handler instead.\n */\nexport function SelectionClipboard({ prefetch }: SelectionClipboardProps = {}) {\n const selection = useCapability(SelectionToken);\n useEffect(\n () => wireSelectionClipboard(selection, prefetch === undefined ? {} : { prefetch }),\n [selection, prefetch],\n );\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;AAuDA,SAAgB,eAAe,EAAE,QAAQ,8BAAmD;CAC1F,MAAM,OAAOA,gBAAAA,QAAQ;CACrB,MAAM,YAAYC,gBAAAA,cAAcC,oCAAAA,cAAkB;CAClD,MAAM,WAAWC,gBAAAA,YACfD,oCAAAA,iBACC,MAAM,EAAE,gBAAgB,KAAK,GAAG,GACjCE,gBAAAA,YACF;CAGA,MAAM,UAAUD,gBAAAA,YAAYD,oCAAAA,iBAAqB,MAAM,EAAE,iBAAiB,CAAC;CAK3E,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,UAAU,WAAW,KAAK,GAAG;CAC/B,GAAG,CAAC,WAAW,KAAK,GAAG,CAAC;CAExB,IAAI,CAAC,SAAS,OAAO;CAErB,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EACE,OAAO;GACL,UAAU;GACV,OAAO;GACP,OAAO;GACP,QAAQ;GACR,UAAU;GACV,eAAe;EACjB;EAEC,UAAA,SAAS,KAAK,GAAG,MAAM;GAOtB,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,WAAD;IAAiB,QAJN;KAAC,EAAE,KAAK;KAAY,EAAE,KAAK;KAAU,EAAE,KAAK;KAAU,EAAE,KAAK;IAAU,CAAC,CAAC,KACnF,MAAM,KAAK,UAAU,SAAS,CAAC,CAGJ,CAAC,CAAC,KAAK,MAAM,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,GAAG;IAAG,MAAM;GAAQ,GAArE,CAAqE;EAEvF,CAAC;CACE,CAAA;AAET;;;AAIA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,KAAK,IAAI,KAAK,IAAI;IACvB,OAAOA,2BAAAA,aAAa,IAAIF,2BAAAA;IACxB,QAAQ,KAAK,SAASC,2BAAAA,cAAc,IAAID,2BAAAA;IAGxC,GAAI,KAAK,UACL,OACA;KACE,WAAW,UAAU,KAAK,SAAS;KACnC,iBAAiB,GAAG,OAAO,KAAK,OAAO;IACzC;IACJ,aAAa;IACb,QAAQ;IACR,eAAe;GACjB;GApBF,UAAA,CAwBE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD,EACE,OAAO;IACL,UAAU;IACV,MAAMA,2BAAAA;IACN,KAAK;IACL,OAAOE,2BAAAA;IACP,QAAQ,KAAK;IACb,YAAY;IACZ,cAAcA,2BAAAA,aAAa;GAC7B,EACD,CAAA,GAGD,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD,EACE,OAAO;IACL,UAAU;IACV,MAAM,SAASD,2BAAAA,cAAc;IAC7B,KAAK,SAAS,UAAUD,2BAAAA,aAAaA,2BAAAA,aAAa,KAAK;IACvD,OAAOC,2BAAAA;IACP,QAAQA,2BAAAA;IACR,cAAc;IACd,YAAY;IACZ,WAAW;GACb,EACD,CAAA,CACE;EAhDE,GAAA,IAgDF;CAET;CAEA,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA,CACG,aAAa,OAAO,GACpB,aAAa,KAAK,CACnB,EAAA,CAAA;AAEN;;;;;;;;AAYA,SAAgB,mBAAmB,EAAE,aAAsC,CAAC,GAAG;CAC7E,MAAM,YAAYT,gBAAAA,cAAcI,2BAAAA,cAAc;CAC9C,CAAA,GAAA,MAAA,UAAA,QAAA,GAAA,cAAA,uBAAA,CAC+B,WAAW,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS,CAAC,GAClF,CAAC,WAAW,QAAQ,CACtB;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"selection.cjs","names":["usePage","useCapability","SelectionHostToken","useSelector","shallowArray","useViewerSettings","SelectionToken","stateHook","selectionState","settingsHook","samePageBounds","Anchored","useStageToken","useOptionalCapability","useOptionalProjectorBinding","sameSelectionEndpoints","HANDLE_PAD","HANDLE_HEAD","HANDLE_BAR"],"sources":["../src/selection.tsx"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-selection.\n *\n * <SelectionLayer> is a dumb renderer: it warms the page's geometry on mount,\n * reads the page-space highlight rects from the capability, and paints them —\n * mapping each rect through PageContext.toPixels (the same path markers use),\n * in the plugin's `color` setting, which the `--epdf-text-selection` CSS\n * variable overrides. Zero pointer handling here; that's the\n * PagePointerSource + the hub.\n *\n * The layer resolves the host lens (`/contract/host`: geometry warming, the\n * highlight handshake) — the adapter is exactly what that entry exists for.\n * `useSelection()` hands app code the public lens only.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-selection';\n// The clipboard side effect lives in @embedpdf/web (the plugin is DOM-free);\n// re-exported here so app code has one import for the whole feature.\nexport { copySelection } from '@embedpdf/web';\nimport * as React from 'react';\nimport { useEffect, useMemo, useRef, useState, type RefObject } from 'react';\nimport type { CapabilityToken, EventHook } from '@embedpdf/core';\nimport {\n HANDLE_BAR,\n HANDLE_HEAD,\n HANDLE_PAD,\n SelectionToken,\n armSelectionHandle,\n selectionHandleEndpointsOf,\n selectionHandleGeom,\n selectionHandleViewOf,\n selectionState,\n type SelectionHandleEndpoints,\n type SelectionCapability,\n} from '@embedpdf/plugin-selection';\nimport { SelectionToken as SelectionHostToken } from '@embedpdf/plugin-selection/contract/host';\nimport type { StageCapability } from '@embedpdf/plugin-stage/contract';\nimport {\n attachSelectionHandle,\n mixAccent,\n paint,\n quadInPixels,\n samePageBounds,\n sameSelectionEndpoints,\n svgPoints,\n wireSelectionClipboard,\n type SelectionClipboardOptions,\n} from '@embedpdf/web';\nimport { Anchored, useOptionalProjectorBinding, type AnchoredPlacement } from './anchored';\nimport { devWarn } from './dev';\nimport { useStageToken } from './stage-scope';\nimport {\n shallowArray,\n useCapability,\n useCapabilityEvent,\n useKernelValue,\n useOptionalCapability,\n usePage,\n useSelector,\n useViewerSettings,\n} from './runtime';\nimport { settingsHook, stateHook } from './state';\n\n/**\n * The highlight of the selected text on one page, in the selection plugin's\n * `color` setting; the `--epdf-text-selection` CSS variable wins over it.\n */\nexport function SelectionLayer() {\n const page = usePage();\n const selection = useCapability(SelectionHostToken);\n const segments = useSelector(\n SelectionHostToken,\n (selection) => selection.listSegments(page.ref),\n shallowArray,\n );\n // A consumer (e.g. a markup tool drawing its own preview) can take over the\n // selection visual; when it does, we render nothing so the two never overlap.\n const visible = useSelector(SelectionHostToken, (selection) => selection.isHighlightVisible());\n const color = useSelectionSettings((settings) => settings.color);\n // An unset color follows the viewer's accent, behind the `--epdf-accent` variable.\n const accent = useViewerSettings((settings) => settings.accent);\n\n // Warm this page's text geometry as soon as it's on screen, so the first\n // pointer-down can hit-test without waiting on the engine round-trip.\n // (A no-op without doc.text.select — nothing warms, nothing renders.)\n useEffect(() => {\n void selection.ensureLoaded(page.ref);\n }, [selection, page.ref]);\n\n if (!visible) return null;\n\n // Unset, the color is the accent at 35%, the accent variables included.\n const fill = paint('text-selection', color ?? mixAccent('text-selection', accent));\n\n return (\n <svg\n style={{\n position: 'absolute',\n inset: 0,\n width: '100%',\n height: '100%',\n overflow: 'visible',\n pointerEvents: 'none',\n }}\n >\n {segments.map((segment, i) => (\n // Page space → the page layer's pixels, which ride the page's CSS\n // rotation: mapping the four corners is exact, for turned text too.\n <polygon\n key={i}\n points={svgPoints(quadInPixels(segment.quad, page.transform))}\n // In `style`: an SVG attribute doesn't read var().\n style={{ fill }}\n />\n ))}\n </svg>\n );\n}\n\n/** The public selection capability (select(), readText(), canCopy(), …) for\n * app chrome — toolbars, context menus, automation. */\nexport function useSelection() {\n return useCapability(SelectionToken);\n}\n\n/** Subscribe to one selection event for the mounted lifetime: `useSelectionEvent((selection) => selection.onCommitted, handler)`. */\nexport function useSelectionEvent<T>(\n select: (selection: SelectionCapability) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n useCapabilityEvent(SelectionToken, select, handler);\n}\n\n/**\n * The selection's state: whether anything is selected, whether the user is\n * still selecting, the character range and the pages it's on (the page's State\n * table, declared once in `selectionState`). Takes a selector, re-renders only\n * when what it returns changes, and returns the empty state without a document.\n */\nexport const useSelectionState = stateHook(selectionState);\n\n/** The selection settings (`dragThreshold`, `color`, `handles`), with or without a document. Takes a selector. */\nexport const useSelectionSettings = settingsHook(SelectionToken);\n\nexport interface SelectionMenuProps {\n children: React.ReactNode;\n /** Gap in screen px between the selection and the menu (default 8). */\n gap?: number;\n /** Where to place the menu relative to the selection. Default 'top'. */\n placement?: AnchoredPlacement;\n}\n\n/**\n * Floats over the current text selection (one anchor regardless of\n * cross-page selection; it rides the gesture's end page) — and only once the\n * selection settles: hidden while a gesture is active (mid-drag), it appears at\n * pointer-up; programmatic selections show immediately (born settled). Works\n * under `<Stage>` (mount in the overlay slot) and `<PageView>` alike — the\n * surface provides the projection. Compose the contents from hooks:\n * `useSelection()` for copy/clear, `useAnnotation()` for\n * `markupFromSelection('highlight')`, `copySelection` for the clipboard.\n * For live-follow UI during the drag, compose `<Anchored>` with\n * `getAnchor()` yourself — the primitive carries no policy.\n */\nexport function SelectionMenu({ children, gap = 8, placement = 'top' }: SelectionMenuProps) {\n const selecting = useSelectionState((state) => state.isSelecting);\n // The capability returns a fresh anchor on every read: compare by value, so\n // the menu re-renders only when the selection moved.\n const anchor = useSelector(SelectionToken, (selection) => selection.getAnchor(), samePageBounds);\n if (selecting || !anchor) return null;\n return (\n <Anchored anchor={anchor} placement={placement} gap={gap}>\n {children}\n </Anchored>\n );\n}\n\n// ── selection handles (the touch affordance) ────────────────────────────────\n//\n// Policy lives out of this file, per the layering razor: the view over the\n// Stage, the endpoints, the geometry and the armed drag are\n// `@embedpdf/plugin-selection`'s pure `handles` module (one source for every\n// adapter), the native listener mechanics are\n// `@embedpdf/web`'s `attachSelectionHandle` (the down-shield timing subtlety\n// lives once), and this component keeps what only React can do —\n// subscriptions, markup, theming.\n\nexport interface SelectionHandlesProps {\n /** The stage lens hosting this overlay (default: the enclosing `<Stage>`'s lens). */\n token?: CapabilityToken<StageCapability>;\n}\n\n/**\n * iOS-style draggable selection handles. Each is drawn the way the platform\n * draws them: a thin caret bar that forms the selection's own start/end edge\n * — the boundary glyph's oriented edge, so rotated text and rotated pages\n * carry the handle with them — capped by a screen-constant circle, above the\n * first line at the start, below the last line at the end.\n *\n * On touch, where a caret drag isn't available, the handles are the way to\n * grow or shrink a selection: a long-press selects a word, then each handle\n * extends from the opposite endpoint, snapping to glyphs and crossing pages\n * exactly like a pointer drag — it rides the same `beginGestureAt`/`extendTo`\n * gesture path, so highlights, menus, and commit signals all behave\n * identically. Mount in the `<Stage>` overlay slot next to `<SelectionMenu>`;\n * outside a Stage it renders nothing (a `PageView` has no camera to project\n * through). Pointer-isolated, so grabbing a handle never pans the stage.\n * Painted in the plugin's `handles` setting, which the\n * `--epdf-text-selection-handle` and `--epdf-text-selection-handle-shadow` CSS\n * variables override.\n */\nexport function SelectionHandles({ token: explicitToken }: SelectionHandlesProps = {}) {\n const token = useStageToken(explicitToken);\n const host = useCapability(SelectionHostToken);\n const stage = useOptionalCapability(token);\n // Outside a Stage there is no camera to project through: say so instead of\n // rendering nothing silently.\n const surface = useOptionalProjectorBinding();\n if (!surface || surface.projector.space !== 'overlay') {\n devWarn(\n 'selection-handles-outside-stage',\n '<SelectionHandles> renders nothing here: mount it in the <Stage> overlay slot ' +\n '(a <PageView> has no camera to project the handles through).',\n );\n }\n const selecting = useSelectionState((state) => state.isSelecting);\n const visible = useSelector(SelectionHostToken, (selection) => selection.isHighlightVisible());\n const handles = useSelectionSettings((settings) => settings.handles);\n const accent = useViewerSettings((settings) => settings.accent);\n const endpoints = useSelector(\n SelectionHostToken,\n (selection) => selectionHandleEndpointsOf(selection.getSnapshot()),\n sameSelectionEndpoints,\n );\n // The handles are positioned by projecting the endpoint corners through the\n // camera, so they must re-render whenever the camera moves — visiblePages is\n // the stage's reference-stable revision for exactly that (the same value the\n // page surfaces re-render on, so handle and highlight move in one commit).\n useKernelValue(() => stage?.listVisiblePages() ?? null);\n const [dragging, setDragging] = useState<'start' | 'end' | null>(null);\n // The web binder's `arm` must read the current endpoints/stage at pointer\n // down, not the ones captured when the listener attached — a stable ref\n // callback with a live arm-source is the standard escape from that.\n const armSource = useRef<{ stage: StageCapability; endpoints: SelectionHandleEndpoints } | null>(\n null,\n );\n armSource.current = stage && endpoints ? { stage, endpoints } : null;\n const bindHandle = useMemo(() => {\n const detach: Partial<Record<'start' | 'end', () => void>> = {};\n const make = (role: 'start' | 'end') => (element: HTMLDivElement | null) => {\n detach[role]?.();\n delete detach[role];\n if (!element) return;\n detach[role] = attachSelectionHandle(element, {\n arm: () => {\n const src = armSource.current;\n if (!src) return null;\n const armed = armSelectionHandle(\n host,\n selectionHandleViewOf(src.stage),\n src.endpoints,\n role,\n );\n if (!armed) return null;\n setDragging(role);\n return {\n // the point the user grabbed: the bar's midpoint\n base: armed.base,\n session: {\n move: armed.drag.move,\n end: () => {\n armed.drag.end(); // settle → menu reappears, onCommitted fires\n setDragging(null);\n },\n },\n };\n },\n });\n };\n return { start: make('start'), end: make('end') };\n }, [host]);\n\n if (!stage || !endpoints || !visible) return null;\n // Hidden while a pointer drag-select is in flight (like the menu) — but a\n // handle drag is itself a selection gesture, so it keeps its handles.\n if (selecting && !dragging) return null;\n const view = selectionHandleViewOf(stage);\n // Each is its CSS variable first, then the setting; an unset color is the accent.\n const color = paint('text-selection-handle', handles.color ?? accent);\n const shadow = paint('text-selection-handle-shadow', handles.shadow);\n\n const renderHandle = (role: 'start' | 'end') => {\n const geometry = selectionHandleGeom(view, endpoints[role], role);\n if (!geometry) return null; // endpoint page not laid out right now\n // The shell is laid out upright in its own frame — bar of the edge's\n // length, head stacked above (start) or below (end) — then rotated onto\n // the projected edge. The pivot is the bar's ascent-side tip, the one\n // point that must land exactly on the glyph corner.\n const barTop = HANDLE_PAD + (role === 'start' ? HANDLE_HEAD : 0);\n const pivotX = HANDLE_PAD + HANDLE_BAR / 2;\n return (\n <div\n key={role}\n ref={bindHandle[role]}\n style={{\n position: 'absolute',\n left: geometry.bar.from.x - pivotX,\n top: geometry.bar.from.y - barTop,\n width: HANDLE_BAR + 2 * HANDLE_PAD,\n height: geometry.length + HANDLE_HEAD + 2 * HANDLE_PAD,\n // Upright text carries no transform — pixel-identical to an\n // axis-aligned box (the geometry's float-noise guard decides).\n ...(geometry.upright\n ? null\n : {\n transform: `rotate(${geometry.rotation}deg)`,\n transformOrigin: `${pivotX}px ${barTop}px`,\n }),\n touchAction: 'none',\n cursor: 'grab',\n pointerEvents: 'auto',\n }}\n >\n {/* the caret bar — the selection's own edge, spanning the glyph's ink\n height (which is why it stays the text's height at any tilt) */}\n <div\n style={{\n position: 'absolute',\n left: HANDLE_PAD,\n top: barTop,\n width: HANDLE_BAR,\n height: geometry.length,\n background: color,\n borderRadius: HANDLE_BAR / 2,\n }}\n />\n {/* the head — flush against the bar, beyond the ascent at the start and\n past the baseline at the end, in the TEXT's frame */}\n <div\n style={{\n position: 'absolute',\n left: pivotX - HANDLE_HEAD / 2,\n top: role === 'start' ? HANDLE_PAD : HANDLE_PAD + geometry.length,\n width: HANDLE_HEAD,\n height: HANDLE_HEAD,\n borderRadius: '50%',\n background: color,\n boxShadow: shadow,\n }}\n />\n </div>\n );\n };\n\n return (\n <>\n {renderHandle('start')}\n {renderHandle('end')}\n </>\n );\n}\n\nexport interface SelectionClipboardProps\n extends Pick<SelectionClipboardOptions, 'prefetch' | 'onRefused'> {\n /**\n * Copy only while focus is inside this element, for a page with more than one viewer.\n * Default: anywhere on the page.\n */\n target?: RefObject<HTMLElement | null>;\n}\n\n/**\n * Mount once per viewer to wire clipboard copy: prefetches the selected text\n * when the selection settles, answers the native `copy` event synchronously,\n * and falls back to the async Clipboard API for ctrl/cmd+C when the page has\n * no DOM selection. A selection the user may not copy isn't copied, and\n * `onRefused` is called. Renders nothing, and wires nothing until a document\n * is ready. For a toolbar Copy button, call `copySelection(useSelection())`\n * from its click handler instead.\n */\nexport function SelectionClipboard({ prefetch, onRefused, target }: SelectionClipboardProps = {}) {\n const selection = useOptionalCapability(SelectionToken);\n // The latest callback, so a new function each render doesn't wire the clipboard again.\n const refused = useRef(onRefused);\n refused.current = onRefused;\n useEffect(() => {\n // The element mounts before this effect runs, so its ref is set by now.\n const element = target ? target.current : undefined;\n if (!selection || element === null) return;\n return wireSelectionClipboard(selection, {\n ...(prefetch === undefined ? {} : { prefetch }),\n ...(element ? { target: element } : {}),\n onRefused: () => refused.current?.(),\n });\n }, [selection, prefetch, target]);\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAoEA,SAAgB,iBAAiB;CAC/B,MAAM,OAAOA,gBAAAA,QAAQ;CACrB,MAAM,YAAYC,gBAAAA,cAAcC,yCAAAA,cAAkB;CAClD,MAAM,WAAWC,gBAAAA,YACfD,yCAAAA,iBACC,cAAc,UAAU,aAAa,KAAK,GAAG,GAC9CE,gBAAAA,YACF;CAGA,MAAM,UAAUD,gBAAAA,YAAYD,yCAAAA,iBAAqB,cAAc,UAAU,mBAAmB,CAAC;CAC7F,MAAM,QAAQ,sBAAsB,aAAa,SAAS,KAAK;CAE/D,MAAM,SAASG,gBAAAA,mBAAmB,aAAa,SAAS,MAAM;CAK9D,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,UAAe,aAAa,KAAK,GAAG;CACtC,GAAG,CAAC,WAAW,KAAK,GAAG,CAAC;CAExB,IAAI,CAAC,SAAS,OAAO;CAGrB,MAAM,QAAA,GAAA,cAAA,MAAA,CAAa,kBAAkB,UAAA,GAAA,cAAA,UAAA,CAAmB,kBAAkB,MAAM,CAAC;CAEjF,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;EACE,OAAO;GACL,UAAU;GACV,OAAO;GACP,OAAO;GACP,QAAQ;GACR,UAAU;GACV,eAAe;EACjB;EAEC,UAAA,SAAS,KAAK,SAA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AAOC,2BAAAA;IACP,QAAQA,2BAAAA;IACR,cAAc;IACd,YAAY;IACZ,WAAW;GACb,EACD,CAAA,CACE;EAhDE,GAAA,IAgDF;CAET;CAEA,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA,CACG,aAAa,OAAO,GACpB,aAAa,KAAK,CACnB,EAAA,CAAA;AAEN;;;;;;;;;;AAoBA,SAAgB,mBAAmB,EAAE,UAAU,WAAW,WAAoC,CAAC,GAAG;CAChG,MAAM,YAAYJ,gBAAAA,sBAAsBP,2BAAAA,cAAc;CAEtD,MAAM,WAAA,GAAA,MAAA,OAAA,CAAiB,SAAS;CAChC,QAAQ,UAAU;CAClB,CAAA,GAAA,MAAA,UAAA,OAAgB;EAEd,MAAM,UAAU,SAAS,OAAO,UAAU,KAAA;EAC1C,IAAI,CAAC,aAAa,YAAY,MAAM;EACpC,QAAA,GAAA,cAAA,uBAAA,CAA8B,WAAW;GACvC,GAAI,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC7C,GAAI,UAAU,EAAE,QAAQ,QAAQ,IAAI,CAAC;GACrC,iBAAiB,QAAQ,UAAU;EACrC,CAAC;CACH,GAAG;EAAC;EAAW;EAAU;CAAM,CAAC;CAChC,OAAO;AACT"}
|
package/dist/selection.d.cts
CHANGED
|
@@ -1,18 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as StateHook, t as SettingsHook } from "./state-0K1I5cM4.cjs";
|
|
2
|
+
import { r as AnchoredPlacement$1 } from "./anchored-DzN3JywS.cjs";
|
|
3
|
+
import { CapabilityToken, EventHook } from "@embedpdf/core";
|
|
2
4
|
import * as React from "react";
|
|
5
|
+
import { RefObject } from "react";
|
|
3
6
|
import { SelectionClipboardOptions, copySelection } from "@embedpdf/web";
|
|
4
|
-
import { CapabilityToken } from "@embedpdf/core";
|
|
5
7
|
import { StageCapability } from "@embedpdf/plugin-stage/contract";
|
|
8
|
+
import { SelectionCapability } from "@embedpdf/plugin-selection";
|
|
6
9
|
export * from "@embedpdf/plugin-selection";
|
|
7
10
|
//#region src/selection.d.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
declare function SelectionLayer(
|
|
13
|
-
/** The
|
|
11
|
+
/**
|
|
12
|
+
* The highlight of the selected text on one page, in the selection plugin's
|
|
13
|
+
* `color` setting; the `--epdf-text-selection` CSS variable wins over it.
|
|
14
|
+
*/
|
|
15
|
+
declare function SelectionLayer(): import("react/jsx-runtime").JSX.Element | null;
|
|
16
|
+
/** The public selection capability (select(), readText(), canCopy(), …) for
|
|
14
17
|
* app chrome — toolbars, context menus, automation. */
|
|
15
|
-
declare function useSelection():
|
|
18
|
+
declare function useSelection(): SelectionCapability;
|
|
19
|
+
/** Subscribe to one selection event for the mounted lifetime: `useSelectionEvent((selection) => selection.onCommitted, handler)`. */
|
|
20
|
+
declare function useSelectionEvent<T>(select: (selection: SelectionCapability) => EventHook<T>, handler: (event: T) => void): void;
|
|
21
|
+
/**
|
|
22
|
+
* The selection's state: whether anything is selected, whether the user is
|
|
23
|
+
* still selecting, the character range and the pages it's on (the page's State
|
|
24
|
+
* table, declared once in `selectionState`). Takes a selector, re-renders only
|
|
25
|
+
* when what it returns changes, and returns the empty state without a document.
|
|
26
|
+
*/
|
|
27
|
+
declare const useSelectionState: StateHook<{
|
|
28
|
+
hasSelection: boolean;
|
|
29
|
+
isSelecting: boolean;
|
|
30
|
+
range: import("@embedpdf/plugin-selection").TextRange | null;
|
|
31
|
+
pages: readonly import("@embedpdf/core").PageRef[];
|
|
32
|
+
}>;
|
|
33
|
+
/** The selection settings (`dragThreshold`, `color`, `handles`), with or without a document. Takes a selector. */
|
|
34
|
+
declare const useSelectionSettings: SettingsHook<import("@embedpdf/plugin-selection").SelectionSettings>;
|
|
16
35
|
interface SelectionMenuProps {
|
|
17
36
|
children: React.ReactNode;
|
|
18
37
|
/** Gap in screen px between the selection and the menu (default 8). */
|
|
@@ -21,50 +40,59 @@ interface SelectionMenuProps {
|
|
|
21
40
|
placement?: AnchoredPlacement$1;
|
|
22
41
|
}
|
|
23
42
|
/**
|
|
24
|
-
* Floats over the current
|
|
43
|
+
* Floats over the current text selection (one anchor regardless of
|
|
25
44
|
* cross-page selection; it rides the gesture's end page) — and only once the
|
|
26
|
-
* selection
|
|
45
|
+
* selection settles: hidden while a gesture is active (mid-drag), it appears at
|
|
27
46
|
* pointer-up; programmatic selections show immediately (born settled). Works
|
|
28
47
|
* under `<Stage>` (mount in the overlay slot) and `<PageView>` alike — the
|
|
29
48
|
* surface provides the projection. Compose the contents from hooks:
|
|
30
49
|
* `useSelection()` for copy/clear, `useAnnotation()` for
|
|
31
50
|
* `markupFromSelection('highlight')`, `copySelection` for the clipboard.
|
|
32
51
|
* For live-follow UI during the drag, compose `<Anchored>` with
|
|
33
|
-
* `
|
|
52
|
+
* `getAnchor()` yourself — the primitive carries no policy.
|
|
34
53
|
*/
|
|
35
54
|
declare function SelectionMenu({ children, gap, placement }: SelectionMenuProps): import("react/jsx-runtime").JSX.Element | null;
|
|
36
55
|
interface SelectionHandlesProps {
|
|
37
|
-
/**
|
|
38
|
-
color?: string;
|
|
39
|
-
/** The stage lens hosting this overlay (default: the main StageToken). */
|
|
56
|
+
/** The stage lens hosting this overlay (default: the enclosing `<Stage>`'s lens). */
|
|
40
57
|
token?: CapabilityToken<StageCapability>;
|
|
41
58
|
}
|
|
42
59
|
/**
|
|
43
60
|
* iOS-style draggable selection handles. Each is drawn the way the platform
|
|
44
|
-
* draws them: a thin caret
|
|
61
|
+
* draws them: a thin caret bar that forms the selection's own start/end edge
|
|
45
62
|
* — the boundary glyph's oriented edge, so rotated text and rotated pages
|
|
46
63
|
* carry the handle with them — capped by a screen-constant circle, above the
|
|
47
64
|
* first line at the start, below the last line at the end.
|
|
48
65
|
*
|
|
49
|
-
* On touch, where a caret drag isn't available, the handles
|
|
66
|
+
* On touch, where a caret drag isn't available, the handles are the way to
|
|
50
67
|
* grow or shrink a selection: a long-press selects a word, then each handle
|
|
51
|
-
* extends from the
|
|
52
|
-
* exactly like a pointer drag — it rides the same `
|
|
68
|
+
* extends from the opposite endpoint, snapping to glyphs and crossing pages
|
|
69
|
+
* exactly like a pointer drag — it rides the same `beginGestureAt`/`extendTo`
|
|
53
70
|
* gesture path, so highlights, menus, and commit signals all behave
|
|
54
71
|
* identically. Mount in the `<Stage>` overlay slot next to `<SelectionMenu>`;
|
|
55
72
|
* outside a Stage it renders nothing (a `PageView` has no camera to project
|
|
56
73
|
* through). Pointer-isolated, so grabbing a handle never pans the stage.
|
|
74
|
+
* Painted in the plugin's `handles` setting, which the
|
|
75
|
+
* `--epdf-text-selection-handle` and `--epdf-text-selection-handle-shadow` CSS
|
|
76
|
+
* variables override.
|
|
57
77
|
*/
|
|
58
|
-
declare function SelectionHandles({
|
|
59
|
-
|
|
78
|
+
declare function SelectionHandles({ token: explicitToken }?: SelectionHandlesProps): import("react/jsx-runtime").JSX.Element | null;
|
|
79
|
+
interface SelectionClipboardProps extends Pick<SelectionClipboardOptions, 'prefetch' | 'onRefused'> {
|
|
80
|
+
/**
|
|
81
|
+
* Copy only while focus is inside this element, for a page with more than one viewer.
|
|
82
|
+
* Default: anywhere on the page.
|
|
83
|
+
*/
|
|
84
|
+
target?: RefObject<HTMLElement | null>;
|
|
85
|
+
}
|
|
60
86
|
/**
|
|
61
|
-
* Mount
|
|
87
|
+
* Mount once per viewer to wire clipboard copy: prefetches the selected text
|
|
62
88
|
* when the selection settles, answers the native `copy` event synchronously,
|
|
63
89
|
* and falls back to the async Clipboard API for ctrl/cmd+C when the page has
|
|
64
|
-
* no DOM selection.
|
|
65
|
-
* `
|
|
90
|
+
* no DOM selection. A selection the user may not copy isn't copied, and
|
|
91
|
+
* `onRefused` is called. Renders nothing, and wires nothing until a document
|
|
92
|
+
* is ready. For a toolbar Copy button, call `copySelection(useSelection())`
|
|
93
|
+
* from its click handler instead.
|
|
66
94
|
*/
|
|
67
|
-
declare function SelectionClipboard({ prefetch }?: SelectionClipboardProps): null;
|
|
95
|
+
declare function SelectionClipboard({ prefetch, onRefused, target }?: SelectionClipboardProps): null;
|
|
68
96
|
//#endregion
|
|
69
|
-
export { SelectionClipboard, SelectionClipboardProps, SelectionHandles, SelectionHandlesProps, SelectionLayer,
|
|
97
|
+
export { SelectionClipboard, SelectionClipboardProps, SelectionHandles, SelectionHandlesProps, SelectionLayer, SelectionMenu, SelectionMenuProps, copySelection, useSelection, useSelectionEvent, useSelectionSettings, useSelectionState };
|
|
70
98
|
//# sourceMappingURL=selection.d.cts.map
|
package/dist/selection.d.ts
CHANGED
|
@@ -1,70 +1,98 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { n as StateHook, t as SettingsHook } from "./state-0K1I5cM4.js";
|
|
2
|
+
import { r as AnchoredPlacement$1 } from "./anchored-DeX95xSd.js";
|
|
3
|
+
import { CapabilityToken, EventHook } from "@embedpdf/core";
|
|
4
4
|
import { SelectionClipboardOptions, copySelection } from "@embedpdf/web";
|
|
5
|
+
import * as React$1 from "react";
|
|
6
|
+
import { RefObject } from "react";
|
|
5
7
|
import { StageCapability } from "@embedpdf/plugin-stage/contract";
|
|
8
|
+
import { SelectionCapability } from "@embedpdf/plugin-selection";
|
|
6
9
|
export * from "@embedpdf/plugin-selection";
|
|
7
10
|
//#region src/selection.d.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
declare function SelectionLayer(
|
|
13
|
-
/** The
|
|
11
|
+
/**
|
|
12
|
+
* The highlight of the selected text on one page, in the selection plugin's
|
|
13
|
+
* `color` setting; the `--epdf-text-selection` CSS variable wins over it.
|
|
14
|
+
*/
|
|
15
|
+
declare function SelectionLayer(): import("react/jsx-runtime").JSX.Element | null;
|
|
16
|
+
/** The public selection capability (select(), readText(), canCopy(), …) for
|
|
14
17
|
* app chrome — toolbars, context menus, automation. */
|
|
15
|
-
declare function useSelection():
|
|
18
|
+
declare function useSelection(): SelectionCapability;
|
|
19
|
+
/** Subscribe to one selection event for the mounted lifetime: `useSelectionEvent((selection) => selection.onCommitted, handler)`. */
|
|
20
|
+
declare function useSelectionEvent<T>(select: (selection: SelectionCapability) => EventHook<T>, handler: (event: T) => void): void;
|
|
21
|
+
/**
|
|
22
|
+
* The selection's state: whether anything is selected, whether the user is
|
|
23
|
+
* still selecting, the character range and the pages it's on (the page's State
|
|
24
|
+
* table, declared once in `selectionState`). Takes a selector, re-renders only
|
|
25
|
+
* when what it returns changes, and returns the empty state without a document.
|
|
26
|
+
*/
|
|
27
|
+
declare const useSelectionState: StateHook<{
|
|
28
|
+
hasSelection: boolean;
|
|
29
|
+
isSelecting: boolean;
|
|
30
|
+
range: import("@embedpdf/plugin-selection").TextRange | null;
|
|
31
|
+
pages: readonly import("@embedpdf/core").PageRef[];
|
|
32
|
+
}>;
|
|
33
|
+
/** The selection settings (`dragThreshold`, `color`, `handles`), with or without a document. Takes a selector. */
|
|
34
|
+
declare const useSelectionSettings: SettingsHook<import("@embedpdf/plugin-selection").SelectionSettings>;
|
|
16
35
|
interface SelectionMenuProps {
|
|
17
|
-
children: React.ReactNode;
|
|
36
|
+
children: React$1.ReactNode;
|
|
18
37
|
/** Gap in screen px between the selection and the menu (default 8). */
|
|
19
38
|
gap?: number;
|
|
20
39
|
/** Where to place the menu relative to the selection. Default 'top'. */
|
|
21
40
|
placement?: AnchoredPlacement$1;
|
|
22
41
|
}
|
|
23
42
|
/**
|
|
24
|
-
* Floats over the current
|
|
43
|
+
* Floats over the current text selection (one anchor regardless of
|
|
25
44
|
* cross-page selection; it rides the gesture's end page) — and only once the
|
|
26
|
-
* selection
|
|
45
|
+
* selection settles: hidden while a gesture is active (mid-drag), it appears at
|
|
27
46
|
* pointer-up; programmatic selections show immediately (born settled). Works
|
|
28
47
|
* under `<Stage>` (mount in the overlay slot) and `<PageView>` alike — the
|
|
29
48
|
* surface provides the projection. Compose the contents from hooks:
|
|
30
49
|
* `useSelection()` for copy/clear, `useAnnotation()` for
|
|
31
50
|
* `markupFromSelection('highlight')`, `copySelection` for the clipboard.
|
|
32
51
|
* For live-follow UI during the drag, compose `<Anchored>` with
|
|
33
|
-
* `
|
|
52
|
+
* `getAnchor()` yourself — the primitive carries no policy.
|
|
34
53
|
*/
|
|
35
54
|
declare function SelectionMenu({ children, gap, placement }: SelectionMenuProps): import("react/jsx-runtime").JSX.Element | null;
|
|
36
55
|
interface SelectionHandlesProps {
|
|
37
|
-
/**
|
|
38
|
-
color?: string;
|
|
39
|
-
/** The stage lens hosting this overlay (default: the main StageToken). */
|
|
56
|
+
/** The stage lens hosting this overlay (default: the enclosing `<Stage>`'s lens). */
|
|
40
57
|
token?: CapabilityToken<StageCapability>;
|
|
41
58
|
}
|
|
42
59
|
/**
|
|
43
60
|
* iOS-style draggable selection handles. Each is drawn the way the platform
|
|
44
|
-
* draws them: a thin caret
|
|
61
|
+
* draws them: a thin caret bar that forms the selection's own start/end edge
|
|
45
62
|
* — the boundary glyph's oriented edge, so rotated text and rotated pages
|
|
46
63
|
* carry the handle with them — capped by a screen-constant circle, above the
|
|
47
64
|
* first line at the start, below the last line at the end.
|
|
48
65
|
*
|
|
49
|
-
* On touch, where a caret drag isn't available, the handles
|
|
66
|
+
* On touch, where a caret drag isn't available, the handles are the way to
|
|
50
67
|
* grow or shrink a selection: a long-press selects a word, then each handle
|
|
51
|
-
* extends from the
|
|
52
|
-
* exactly like a pointer drag — it rides the same `
|
|
68
|
+
* extends from the opposite endpoint, snapping to glyphs and crossing pages
|
|
69
|
+
* exactly like a pointer drag — it rides the same `beginGestureAt`/`extendTo`
|
|
53
70
|
* gesture path, so highlights, menus, and commit signals all behave
|
|
54
71
|
* identically. Mount in the `<Stage>` overlay slot next to `<SelectionMenu>`;
|
|
55
72
|
* outside a Stage it renders nothing (a `PageView` has no camera to project
|
|
56
73
|
* through). Pointer-isolated, so grabbing a handle never pans the stage.
|
|
74
|
+
* Painted in the plugin's `handles` setting, which the
|
|
75
|
+
* `--epdf-text-selection-handle` and `--epdf-text-selection-handle-shadow` CSS
|
|
76
|
+
* variables override.
|
|
57
77
|
*/
|
|
58
|
-
declare function SelectionHandles({
|
|
59
|
-
|
|
78
|
+
declare function SelectionHandles({ token: explicitToken }?: SelectionHandlesProps): import("react/jsx-runtime").JSX.Element | null;
|
|
79
|
+
interface SelectionClipboardProps extends Pick<SelectionClipboardOptions, 'prefetch' | 'onRefused'> {
|
|
80
|
+
/**
|
|
81
|
+
* Copy only while focus is inside this element, for a page with more than one viewer.
|
|
82
|
+
* Default: anywhere on the page.
|
|
83
|
+
*/
|
|
84
|
+
target?: RefObject<HTMLElement | null>;
|
|
85
|
+
}
|
|
60
86
|
/**
|
|
61
|
-
* Mount
|
|
87
|
+
* Mount once per viewer to wire clipboard copy: prefetches the selected text
|
|
62
88
|
* when the selection settles, answers the native `copy` event synchronously,
|
|
63
89
|
* and falls back to the async Clipboard API for ctrl/cmd+C when the page has
|
|
64
|
-
* no DOM selection.
|
|
65
|
-
* `
|
|
90
|
+
* no DOM selection. A selection the user may not copy isn't copied, and
|
|
91
|
+
* `onRefused` is called. Renders nothing, and wires nothing until a document
|
|
92
|
+
* is ready. For a toolbar Copy button, call `copySelection(useSelection())`
|
|
93
|
+
* from its click handler instead.
|
|
66
94
|
*/
|
|
67
|
-
declare function SelectionClipboard({ prefetch }?: SelectionClipboardProps): null;
|
|
95
|
+
declare function SelectionClipboard({ prefetch, onRefused, target }?: SelectionClipboardProps): null;
|
|
68
96
|
//#endregion
|
|
69
|
-
export { SelectionClipboard, SelectionClipboardProps, SelectionHandles, SelectionHandlesProps, SelectionLayer,
|
|
97
|
+
export { SelectionClipboard, SelectionClipboardProps, SelectionHandles, SelectionHandlesProps, SelectionLayer, SelectionMenu, SelectionMenuProps, copySelection, useSelection, useSelectionEvent, useSelectionSettings, useSelectionState };
|
|
70
98
|
//# sourceMappingURL=selection.d.ts.map
|