# @embedpdf/react — ./interaction Cursor [TypeAliasDeclaration] (from packages/plugin/interaction/src/contract.ts): export type Cursor = string; FeedbackPluginOptions [InterfaceDeclaration] (from packages/plugin/interaction/src/feedback.types.ts): export interface FeedbackPluginOptions{ provider?: PlatformFeedback; } FeedbackToken [VariableDeclaration] (from packages/plugin/interaction/src/feedback.types.ts): FeedbackToken = createCapabilityToken('feedback') GestureCancelledEvent [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface GestureCancelledEvent{ readonly toolId: ToolId; readonly page: PageRef | null; readonly pointerType: PointerKind; } GestureEndedEvent [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface GestureEndedEvent{ readonly toolId: ToolId; readonly page: PageRef | null; readonly pointerType: PointerKind; } GestureStartedEvent [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface GestureStartedEvent{ readonly toolId: ToolId; readonly page: PageRef | null; readonly pointerType: PointerKind; } INTERACTION_DEFAULTS [VariableDeclaration] (from packages/plugin/interaction/src/contract.ts): INTERACTION_DEFAULTS: InteractionSettings ={ defaultTool: 'pointer', tools: []} InteractionCapability [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface InteractionCapability extends SettingsApi{ getActiveTool(): Tool; getActiveToolId(): ToolId; getDefaultToolId(): ToolId; listTools(): readonly Tool[]; getTool(id: ToolId): Tool | null; hasTool(id: ToolId): boolean; canUseTool(id: ToolId): boolean; activateTool(id: ToolId): void; activateDefaultTool(): void; pushTool(id: ToolId): void; popTool(): void; setToolCursor(id: ToolId, cursors: ToolCursors | null): void; registerTool(tool: Tool, options?: RegisterToolOptions): Unsubscribe; readonly onToolChanged: EventHook; readonly onGestureStarted: EventHook; readonly onGestureEnded: EventHook; readonly onGestureCancelled: EventHook; } InteractionConfig [TypeAliasDeclaration] (from packages/plugin/interaction/src/contract.ts): export type InteractionConfig = DeepPartial; InteractionSettings [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface InteractionSettings{ readonly defaultTool: ToolId; readonly tools: readonly Tool[]; } InteractionState [InterfaceDeclaration] (from packages/plugin/interaction/src/state.ts): export interface InteractionState{ readonly activeToolId: ToolId | null; readonly tools: readonly Tool[]; } InteractionToken [VariableDeclaration] (from packages/plugin/interaction/src/token.ts): InteractionToken = createCapabilityToken('interaction', { hint: `add interactionPlugin() from '@embedpdf/plugin-interaction' to your plugins list`, } ) Modifiers [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface Modifiers{ readonly shift: boolean; readonly alt: boolean; readonly ctrl: boolean; readonly meta: boolean; } PagePointerSource [FunctionDeclaration]: export function PagePointerSource(){ const page = usePage(); const interaction = useCapability(InteractionHostToken); const cursor = useSelector(InteractionHostToken, (interaction) => interaction.getCursor()); const ref = useRef(null); useEffect(() =>{ const element = ref.current; if (!element) return; return attachPagePointer(element, interaction, () => page); } , [interaction, page]); return
; } PlatformFeedback [InterfaceDeclaration] (from packages/plugin/interaction/src/feedback.types.ts): export interface PlatformFeedback{ selection(): void; impact(weight?: 'light' | 'medium' | 'heavy'): void; notify(kind: 'success' | 'warning' | 'error'): void; } PointerKind [TypeAliasDeclaration] (from packages/plugin/interaction/src/contract.ts): export type PointerKind = 'mouse' | 'pen' | 'touch'; RegisterToolOptions [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface RegisterToolOptions{ readonly replace?: boolean; } SvgCursorOptions [InterfaceDeclaration] (from packages/framework/web/src/cursor.ts): export interface SvgCursorOptions{ svg: string; hotspot?:{ x: number; y: number} ; fallback?: string; } Tool [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface Tool{ readonly id: ToolId; readonly cursor: Cursor; readonly touch?: ToolTouch; canUse?(): boolean; onPointerDown?(event: ToolPointerEvent): boolean | void; onPointerMove?(event: ToolPointerEvent): void; onPointerUp?(event: ToolPointerEvent): void; onHover?(event: ToolPointerEvent): void; } ToolChangedEvent [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface ToolChangedEvent{ readonly toolId: ToolId; readonly previousToolId: ToolId; } ToolCursorImage [TypeAliasDeclaration] (from packages/framework/web/src/cursor.ts): export type ToolCursorImage = SvgCursorOptions | string; ToolCursorSpec [InterfaceDeclaration] (from packages/framework/web/src/cursor.ts): export interface ToolCursorSpec{ toolId: string; cursors: Record; } ToolCursors [TypeAliasDeclaration] (from packages/plugin/interaction/src/contract.ts): export type ToolCursors = Readonly>; ToolId [TypeAliasDeclaration] (from packages/plugin/interaction/src/contract.ts): export type ToolId = string; ToolPointerEvent [InterfaceDeclaration] (from packages/plugin/interaction/src/contract.ts): export interface ToolPointerEvent{ readonly page: PageRef; readonly point: Point; readonly modifiers: Modifiers; readonly pointerType: PointerKind; } ToolTouch [TypeAliasDeclaration] (from packages/plugin/interaction/src/contract.ts): export type ToolTouch = 'draw' | 'tap'; createClickCounter [FunctionDeclaration] (from packages/framework/web/src/page-pointer.ts): export function createClickCounter(maxGapMs = 400, maxDistancePx = 6){ let last = 0; let lastX = 0; let lastY = 0; let count = 0; return (now: number, x: number, y: number): number =>{ count = now - last <= maxGapMs && Math.hypot(x - lastX, y - lastY) <= maxDistancePx ? count + 1 : 1; last = now; lastX = x; lastY = y; return count; } ; } feedbackPlugin [VariableDeclaration] (from packages/plugin/interaction/src/feedback.ts): feedbackPlugin = (options: FeedbackPluginOptions ={ } ) => definePlugin({ id: 'feedback', scope: 'workspace', token: FeedbackToken, create: () => ({ api: options.provider ?? NOOP} ), } ) interactionCommands [VariableDeclaration] (from packages/framework/react/src/command-lists.ts): interactionCommands = createInteractionCommands() interactionPlugin [VariableDeclaration] (from packages/plugin/interaction/src/interaction.plugin.ts): interactionPlugin = (config?: InteractionConfig) => definePlugin({ id: 'interaction', token: InteractionToken, scope: 'document', state: initialInteractionModel, settings:{ defaults: INTERACTION_DEFAULTS, registered: config} , create: (ctx) => createInteractionController(ctx, builtinTools()), } ) interactionState [VariableDeclaration] (from packages/plugin/interaction/src/state.ts): interactionState = defineState(InteractionToken, { read: (interaction): InteractionState => ({ activeToolId: interaction.getActiveToolId(), tools: interaction.listTools(), } ), empty:{ activeToolId: null, tools: []} , } ) svgCursor [FunctionDeclaration] (from packages/framework/web/src/cursor.ts): export function svgCursor({ svg, hotspot, fallback = 'crosshair'} : SvgCursorOptions): string{ const tagStart = svg.indexOf('= 0 ? svg.indexOf('>', tagStart) : -1; const openTag = tagEnd >= 0 ? svg.slice(tagStart, tagEnd + 1) : ''; if (!/\swidth\s*=/.test(openTag) || !/\sheight\s*=/.test(openTag)){ throw new Error( '[web] svgCursor: the needs explicit width/height attributes — ' + 'browsers ignore cursor images without an intrinsic size', ); } const uri = `data:image/svg+xml, ${ encodeURIComponent(svg)} `; const spot = hotspot ? ` ${ Math.round(hotspot.x)} ${ Math.round(hotspot.y)} ` : ''; return `url("${ uri} ")${ spot} , ${ fallback} `; } toolCommand [VariableDeclaration] (from packages/plugin/interaction/src/commands.ts): toolCommand = (toolId: string): Omit => ({ labelKey: `commands.tool.${ toolId} `, label: toolId, icon: toolId, categories: ['tool'], run: (context) => interactionOf(context)?.activateTool(toolId), active: (context) => interactionOf(context)?.getActiveToolId() === toolId, visible: (context) => interactionOf(context)?.hasTool(toolId) ?? false, enabled: (context) => interactionOf(context)?.canUseTool(toolId) ?? true, } ) useInteraction [FunctionDeclaration]: export function useInteraction(): InteractionCapability{ return useCapability(InteractionToken); } useInteractionEvent [FunctionDeclaration]: export function useInteractionEvent( select: (interaction: InteractionCapability) => EventHook, handler: (event: T) => void, ): void{ useCapabilityEvent(InteractionToken, select, handler); } useInteractionSettings [VariableDeclaration]: useInteractionSettings = settingsHook(InteractionToken) useInteractionState [VariableDeclaration]: useInteractionState = stateHook(interactionState) useToolCursor [FunctionDeclaration]: export function useToolCursor(spec: ToolCursorSpec | null): void{ const interaction = useOptionalCapability(InteractionHostToken); const key = spec && JSON.stringify(spec); const ref = useRef(spec); ref.current = spec; useEffect(() =>{ const cursorSpec = ref.current; if (!cursorSpec || !interaction) return; interaction.setToolCursor(cursorSpec.toolId, toolCursorsOf(cursorSpec.cursors)); return () => interaction.setToolCursor(cursorSpec.toolId, null); } , [interaction, key]); } vibrationFeedback [VariableDeclaration] (from packages/framework/web/src/feedback.ts): vibrationFeedback: WebPlatformFeedback ={ selection: () => vibrate(8), impact: (weight = 'light') => vibrate(weight === 'heavy' ? 30 : weight === 'medium' ? 20 : 10), notify: (kind) => vibrate( kind === 'error' ? [12, 60, 12, 60, 12] : kind === 'warning' ? [15, 70, 15] : [10, 50, 10], ), } wkFeedback [VariableDeclaration] (from packages/framework/web/src/feedback.ts): wkFeedback = ( handlerName: string, fallback: WebPlatformFeedback = vibrationFeedback, ): WebPlatformFeedback =>{ const handler = (): WKMessageHandler | undefined =>{ if (typeof window === 'undefined') return undefined; const webkitWindow = window as Window &{ webkit?:{ messageHandlers?: Record} ; } ; return webkitWindow.webkit?.messageHandlers?.[handlerName]; } ; return{ selection: () =>{ const messageHandler = handler(); if (messageHandler) messageHandler.postMessage({ family: 'selection'} ); else fallback.selection(); } , impact: (weight = 'light') =>{ const messageHandler = handler(); if (messageHandler) messageHandler.postMessage({ family: 'impact', weight} ); else fallback.impact(weight); } , notify: (kind) =>{ const messageHandler = handler(); if (messageHandler) messageHandler.postMessage({ family: 'notify', kind} ); else fallback.notify(kind); } , } ; }