@embedpdf/plugin-annotation 1.0.5 → 1.0.7

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/preact/hooks/use-annotation.ts","../../src/preact/components/annotation-layer.tsx","../../../models/src/geometry.ts","../../../models/src/logger.ts","../../../models/src/task.ts","../../../models/src/pdf.ts","../../../models/src/index.ts","../../src/lib/selectors.ts","../../src/preact/components/annotations/highlight.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { AnnotationPlugin } from '@embedpdf/plugin-annotation';\n\nexport const useAnnotationPlugin = () => usePlugin<AnnotationPlugin>(AnnotationPlugin.id);\nexport const useAnnotationCapability = () => useCapability<AnnotationPlugin>(AnnotationPlugin.id);\n","/** @jsxImportSource preact */\nimport { ComponentChildren, Fragment, JSX } from 'preact';\nimport { useEffect, useMemo, useState } from 'preact/hooks';\nimport { useAnnotationCapability } from '../hooks';\nimport { PdfAnnotationObject, PdfAnnotationSubtype, Position } from '@embedpdf/models';\nimport { getAnnotationsByPageIndex } from '../../lib/selectors';\nimport { HighlightAnnotation } from './annotations/highlight';\nimport { usePointerHandlers } from '@embedpdf/plugin-interaction-manager/preact';\nimport { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\n\ntype AnnotationLayerProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: JSX.CSSProperties;\n};\n\nexport function AnnotationLayer({ pageIndex, scale, style, ...props }: AnnotationLayerProps) {\n const { provides: annotationProvides } = useAnnotationCapability();\n const [annotations, setAnnotations] = useState<PdfAnnotationObject[]>([]);\n const { register } = usePointerHandlers({ pageIndex });\n const [selectionState, setSelectionState] = useState<{\n selectedPageIndex: number | undefined;\n selectedAnnotationId: number | undefined;\n }>({ selectedPageIndex: undefined, selectedAnnotationId: undefined });\n\n useEffect(() => {\n if (annotationProvides) {\n annotationProvides.onStateChange((state) => {\n setAnnotations(getAnnotationsByPageIndex(state, pageIndex));\n setSelectionState({\n selectedPageIndex: state.selectedAnnotation?.pageIndex,\n selectedAnnotationId: state.selectedAnnotation?.annotationId,\n });\n });\n }\n }, [annotationProvides]);\n\n const handlers = useMemo(\n (): PointerEventHandlers<MouseEvent> => ({\n onPointerDown: (_, pe) => {\n // Only deselect if clicking directly on the layer (not on an annotation)\n if (pe.target === pe.currentTarget && annotationProvides) {\n annotationProvides.deselectAnnotation();\n }\n },\n }),\n [annotationProvides],\n );\n\n useEffect(() => {\n return register(handlers);\n }, [register, handlers]);\n\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n {annotations.map((annotation) => {\n const isSelected =\n selectionState.selectedPageIndex === pageIndex &&\n selectionState.selectedAnnotationId === annotation.id;\n\n switch (annotation.type) {\n case PdfAnnotationSubtype.HIGHLIGHT:\n return (\n <HighlightAnnotation\n key={annotation.id}\n annotation={annotation}\n scale={scale}\n isSelected={isSelected}\n pageIndex={pageIndex}\n />\n );\n default:\n return null;\n }\n })}\n </div>\n );\n}\n","/**\n * Clockwise direction\n * @public\n */\nexport enum Rotation {\n Degree0 = 0,\n Degree90 = 1,\n Degree180 = 2,\n Degree270 = 3,\n}\n\n/** Clamp a Position to device-pixel integers (floor) */\nexport function toIntPos(p: Position): Position {\n return { x: Math.floor(p.x), y: Math.floor(p.y) };\n}\n\n/** Clamp a Size so it never truncates right / bottom (ceil) */\nexport function toIntSize(s: Size): Size {\n return { width: Math.ceil(s.width), height: Math.ceil(s.height) };\n}\n\n/** Apply both rules to a Rect */\nexport function toIntRect(r: Rect): Rect {\n return {\n origin: toIntPos(r.origin),\n size: toIntSize(r.size),\n };\n}\n\n/**\n * Calculate degree that match the rotation type\n * @param rotation - type of rotation\n * @returns rotated degree\n *\n * @public\n */\nexport function calculateDegree(rotation: Rotation) {\n switch (rotation) {\n case Rotation.Degree0:\n return 0;\n case Rotation.Degree90:\n return 90;\n case Rotation.Degree180:\n return 180;\n case Rotation.Degree270:\n return 270;\n }\n}\n\n/**\n * Calculate angle that match the rotation type\n * @param rotation - type of rotation\n * @returns rotated angle\n *\n * @public\n */\nexport function calculateAngle(rotation: Rotation) {\n return (calculateDegree(rotation) * Math.PI) / 180;\n}\n\n/**\n * Represent the size of object\n *\n * @public\n */\nexport interface Size {\n /**\n * width of the object\n */\n width: number;\n\n /**\n * height of the object\n */\n height: number;\n}\n\n/**\n * Represents a rectangle defined by its left, top, right, and bottom edges\n *\n * @public\n */\nexport interface Box {\n /**\n * The x-coordinate of the left edge\n */\n left: number;\n\n /**\n * The y-coordinate of the top edge\n */\n top: number;\n\n /**\n * The x-coordinate of the right edge\n */\n right: number;\n\n /**\n * The y-coordinate of the bottom edge\n */\n bottom: number;\n}\n\n/**\n * Swap the width and height of the size object\n * @param size - the original size\n * @returns swapped size\n *\n * @public\n */\nexport function swap(size: Size): Size {\n const { width, height } = size;\n\n return {\n width: height,\n height: width,\n };\n}\n\n/**\n * Transform size with specified rotation angle and scale factor\n * @param size - orignal size of rect\n * @param rotation - rotation angle\n * @param scaleFactor - - scale factor\n * @returns size that has been transformed\n *\n * @public\n */\nexport function transformSize(size: Size, rotation: Rotation, scaleFactor: number): Size {\n size = rotation % 2 === 0 ? size : swap(size);\n\n return {\n width: size.width * scaleFactor,\n height: size.height * scaleFactor,\n };\n}\n\n/**\n * position of point\n *\n * @public\n */\nexport interface Position {\n /**\n * x coordinate\n */\n x: number;\n\n /**\n * y coordinate\n */\n y: number;\n}\n\n/**\n * Quadrilateral\n *\n * @public\n */\nexport interface Quad {\n p1: Position;\n p2: Position;\n p3: Position;\n p4: Position;\n}\n\n/**\n * Convert quadrilateral to rectangle\n * @param q - quadrilateral\n * @returns rectangle\n *\n * @public\n */\nexport function quadToRect(q: Quad): Rect {\n const xs = [q.p1.x, q.p2.x, q.p3.x, q.p4.x];\n const ys = [q.p1.y, q.p2.y, q.p3.y, q.p4.y];\n\n return {\n origin: { x: Math.min(...xs), y: Math.min(...ys) },\n size: {\n width: Math.max(...xs) - Math.min(...xs),\n height: Math.max(...ys) - Math.min(...ys),\n },\n };\n}\n\n/**\n * Rotate the container and calculate the new position for a point\n * in specified position\n * @param containerSize - size of the container\n * @param position - position of the point\n * @param rotation - rotated angle\n * @returns new position of the point\n *\n * @public\n */\nexport function rotatePosition(\n containerSize: Size,\n position: Position,\n rotation: Rotation,\n): Position {\n let x = position.x;\n let y = position.y;\n\n switch (rotation) {\n case Rotation.Degree0:\n x = position.x;\n y = position.y;\n break;\n case Rotation.Degree90:\n x = containerSize.height - position.y;\n y = position.x;\n break;\n case Rotation.Degree180:\n x = containerSize.width - position.x;\n y = containerSize.height - position.y;\n break;\n case Rotation.Degree270:\n x = position.y;\n y = containerSize.width - position.x;\n break;\n }\n\n return {\n x,\n y,\n };\n}\n\n/**\n * Calculate the position of point by scaling the container\n * @param position - position of the point\n * @param scaleFactor - factor of scaling\n * @returns new position of point\n *\n * @public\n */\nexport function scalePosition(position: Position, scaleFactor: number): Position {\n return {\n x: position.x * scaleFactor,\n y: position.y * scaleFactor,\n };\n}\n\n/**\n * Calculate the position of the point by applying the specified transformation\n * @param containerSize - size of container\n * @param position - position of the point\n * @param rotation - rotated angle\n * @param scaleFactor - factor of scaling\n * @returns new position of point\n *\n * @public\n */\nexport function transformPosition(\n containerSize: Size,\n position: Position,\n rotation: Rotation,\n scaleFactor: number,\n): Position {\n return scalePosition(rotatePosition(containerSize, position, rotation), scaleFactor);\n}\n\n/**\n * Restore the position in a transformed cotainer\n * @param containerSize - size of the container\n * @param position - position of the point\n * @param rotation - rotated angle\n * @param scaleFactor - factor of scaling\n * @returns the original position of the point\n *\n * @public\n */\nexport function restorePosition(\n containerSize: Size,\n position: Position,\n rotation: Rotation,\n scaleFactor: number,\n): Position {\n return scalePosition(\n rotatePosition(containerSize, position, (4 - rotation) % 4),\n 1 / scaleFactor,\n );\n}\n\n/**\n * representation of rectangle\n *\n * @public\n */\nexport interface Rect {\n /**\n * origin of the rectangle\n */\n origin: Position;\n\n /**\n * size of the rectangle\n */\n size: Size;\n}\n\n/**\n * Calculate the rect after rotated the container\n * @param containerSize - size of container\n * @param rect - target rect\n * @param rotation - rotation angle\n * @returns rotated rect\n *\n * @public\n */\nexport function rotateRect(containerSize: Size, rect: Rect, rotation: Rotation): Rect {\n let x = rect.origin.x;\n let y = rect.origin.y;\n let size = rect.size;\n\n switch (rotation) {\n case Rotation.Degree0:\n break;\n case Rotation.Degree90:\n x = containerSize.height - rect.origin.y - rect.size.height;\n y = rect.origin.x;\n size = swap(rect.size);\n break;\n case Rotation.Degree180:\n x = containerSize.width - rect.origin.x - rect.size.width;\n y = containerSize.height - rect.origin.y - rect.size.height;\n break;\n case Rotation.Degree270:\n x = rect.origin.y;\n y = containerSize.width - rect.origin.x - rect.size.width;\n size = swap(rect.size);\n break;\n }\n\n return {\n origin: {\n x,\n y,\n },\n size: {\n width: size.width,\n height: size.height,\n },\n };\n}\n\n/**\n * Scale the rectangle\n * @param rect - rectangle\n * @param scaleFactor - factor of scaling\n * @returns new rectangle\n *\n * @public\n */\nexport function scaleRect(rect: Rect, scaleFactor: number): Rect {\n return {\n origin: {\n x: rect.origin.x * scaleFactor,\n y: rect.origin.y * scaleFactor,\n },\n size: {\n width: rect.size.width * scaleFactor,\n height: rect.size.height * scaleFactor,\n },\n };\n}\n\n/**\n * Calculate new rectangle after transforming the container\n * @param containerSize - size of the container\n * @param rect - the target rectangle\n * @param rotation - rotated angle\n * @param scaleFactor - factor of scaling\n * @returns new rectangle after transformation\n *\n * @public\n */\nexport function transformRect(\n containerSize: Size,\n rect: Rect,\n rotation: Rotation,\n scaleFactor: number,\n): Rect {\n return scaleRect(rotateRect(containerSize, rect, rotation), scaleFactor);\n}\n\n/**\n * Calculate new rectangle before transforming the container\n * @param containerSize - size of the container\n * @param rect - the target rectangle\n * @param rotation - rotated angle\n * @param scaleFactor - factor of scaling\n * @returns original rectangle before transformation\n *\n * @public\n */\nexport function restoreRect(\n containerSize: Size,\n rect: Rect,\n rotation: Rotation,\n scaleFactor: number,\n): Rect {\n return scaleRect(rotateRect(containerSize, rect, (4 - rotation) % 4), 1 / scaleFactor);\n}\n\n/**\n * Calculate the original offset in a transformed container\n * @param offset - position of the point\n * @param rotation - rotated angle\n * @param scaleFactor - factor of scaling\n * @returns original position of the point\n *\n * @public\n */\nexport function restoreOffset(offset: Position, rotation: Rotation, scaleFactor: number): Position {\n let offsetX = offset.x;\n let offsetY = offset.y;\n switch (rotation) {\n case Rotation.Degree0:\n offsetX = offset.x / scaleFactor;\n offsetY = offset.y / scaleFactor;\n break;\n case Rotation.Degree90:\n offsetX = offset.y / scaleFactor;\n offsetY = -offset.x / scaleFactor;\n break;\n case Rotation.Degree180:\n offsetX = -offset.x / scaleFactor;\n offsetY = -offset.y / scaleFactor;\n break;\n case Rotation.Degree270:\n offsetX = -offset.y / scaleFactor;\n offsetY = offset.x / scaleFactor;\n break;\n }\n\n return {\n x: offsetX,\n y: offsetY,\n };\n}\n\n/**\n * Return the smallest rectangle that encloses *all* `rects`.\n * If the array is empty, returns `null`.\n *\n * @param rects - array of rectangles\n * @returns smallest rectangle that encloses all the rectangles\n *\n * @public\n */\nexport function boundingRect(rects: Rect[]): Rect | null {\n if (rects.length === 0) return null;\n\n let minX = rects[0].origin.x,\n minY = rects[0].origin.y,\n maxX = rects[0].origin.x + rects[0].size.width,\n maxY = rects[0].origin.y + rects[0].size.height;\n\n for (const r of rects) {\n minX = Math.min(minX, r.origin.x);\n minY = Math.min(minY, r.origin.y);\n maxX = Math.max(maxX, r.origin.x + r.size.width);\n maxY = Math.max(maxY, r.origin.y + r.size.height);\n }\n\n return {\n origin: {\n x: minX,\n y: minY,\n },\n size: {\n width: maxX - minX,\n height: maxY - minY,\n },\n };\n}\n","/**\n * logger for logging\n *\n * @public\n */\nexport interface Logger {\n /**\n * Log debug message\n * @param source - source of log\n * @param category - category of log\n * @param args - parameters of log\n * @returns\n *\n * @public\n */\n debug: (source: string, category: string, ...args: any) => void;\n\n /**\n * Log infor message\n * @param source - source of log\n * @param category - category of log\n * @param args - parameters of log\n * @returns\n *\n * @public\n */\n info: (source: string, category: string, ...args: any) => void;\n\n /**\n * Log warning message\n * @param source - source of log\n * @param category - category of log\n * @param args - parameters of log\n * @returns\n *\n * @public\n */\n warn: (source: string, category: string, ...args: any) => void;\n /**\n * Log error message\n * @param source - source of log\n * @param category - category of log\n * @param args - parameters of log\n * @returns\n *\n * @public\n */\n error: (source: string, category: string, ...args: any) => void;\n\n /**\n * Log performance log\n * @param source - source of log\n * @param category - category of log\n * @param event - event of log\n * @param phase - event phase of log\n * @param args - parameters of log\n * @returns\n *\n * @public\n */\n perf: (\n source: string,\n category: string,\n event: string,\n phase: 'Begin' | 'End',\n ...args: any\n ) => void;\n}\n\n/**\n * Logger that log nothing, it will ignore all the logs\n *\n * @public\n */\nexport class NoopLogger implements Logger {\n /** {@inheritDoc Logger.debug} */\n debug() {}\n /** {@inheritDoc Logger.info} */\n info() {}\n /** {@inheritDoc Logger.warn} */\n warn() {}\n /** {@inheritDoc Logger.error} */\n error() {}\n /** {@inheritDoc Logger.perf} */\n perf() {}\n}\n\n/**\n * Logger that use console as the output\n *\n * @public\n */\nexport class ConsoleLogger implements Logger {\n /** {@inheritDoc Logger.debug} */\n debug(source: string, category: string, ...args: any) {\n console.debug(`${source}.${category}`, ...args);\n }\n\n /** {@inheritDoc Logger.info} */\n info(source: string, category: string, ...args: any) {\n console.info(`${source}.${category}`, ...args);\n }\n\n /** {@inheritDoc Logger.warn} */\n warn(source: string, category: string, ...args: any) {\n console.warn(`${source}.${category}`, ...args);\n }\n\n /** {@inheritDoc Logger.error} */\n error(source: string, category: string, ...args: any) {\n console.error(`${source}.${category}`, ...args);\n }\n\n /** {@inheritDoc Logger.perf} */\n perf(source: string, category: string, event: string, phase: 'Begin' | 'End', ...args: any) {\n console.info(`${source}.${category}.${event}.${phase}`, ...args);\n }\n}\n\n/**\n * Level of log\n *\n * @public\n */\nexport enum LogLevel {\n Debug = 0,\n Info,\n Warn,\n Error,\n}\n\n/**\n * Logger that support filtering by log level\n *\n * @public\n */\nexport class LevelLogger implements Logger {\n /**\n * create new LevelLogger\n * @param logger - the original logger\n * @param level - log level that used for filtering, all logs lower than this level will be filtered out\n */\n constructor(\n private logger: Logger,\n private level: LogLevel,\n ) {}\n\n /** {@inheritDoc Logger.debug} */\n debug(source: string, category: string, ...args: any) {\n if (this.level <= LogLevel.Debug) {\n this.logger.debug(source, category, ...args);\n }\n }\n\n /** {@inheritDoc Logger.info} */\n info(source: string, category: string, ...args: any) {\n if (this.level <= LogLevel.Info) {\n this.logger.info(source, category, ...args);\n }\n }\n\n /** {@inheritDoc Logger.warn} */\n warn(source: string, category: string, ...args: any) {\n if (this.level <= LogLevel.Warn) {\n this.logger.warn(source, category, ...args);\n }\n }\n\n /** {@inheritDoc Logger.error} */\n error(source: string, category: string, ...args: any) {\n if (this.level <= LogLevel.Error) {\n this.logger.error(source, category, ...args);\n }\n }\n\n /** {@inheritDoc Logger.perf} */\n perf(source: string, category: string, event: string, phase: 'Begin' | 'End', ...args: any) {\n this.logger.perf(source, category, event, phase, ...args);\n }\n}\n\n/**\n * Logger for performance tracking\n *\n * @public\n */\nexport class PerfLogger implements Logger {\n /**\n * create new PerfLogger\n */\n constructor() {}\n\n /** {@inheritDoc Logger.debug} */\n debug(source: string, category: string, ...args: any) {}\n\n /** {@inheritDoc Logger.info} */\n info(source: string, category: string, ...args: any) {}\n\n /** {@inheritDoc Logger.warn} */\n warn(source: string, category: string, ...args: any) {}\n\n /** {@inheritDoc Logger.error} */\n error(source: string, category: string, ...args: any) {}\n\n /** {@inheritDoc Logger.perf} */\n perf(\n source: string,\n category: string,\n event: string,\n phase: 'Begin' | 'End',\n identifier: string,\n ...args: any\n ) {\n switch (phase) {\n case 'Begin':\n window.performance.mark(`${source}.${category}.${event}.${phase}.${identifier}`, {\n detail: args,\n });\n break;\n case 'End':\n window.performance.mark(`${source}.${category}.${event}.${phase}.${identifier}`, {\n detail: args,\n });\n window.performance.measure(\n `${source}.${category}.${event}.Measure.${identifier}`,\n `${source}.${category}.${event}.Begin.${identifier}`,\n `${source}.${category}.${event}.End.${identifier}`,\n );\n break;\n }\n }\n}\n\n/**\n * Logger that will track and call child loggers\n *\n * @public\n */\nexport class AllLogger implements Logger {\n /**\n * create new PerfLogger\n */\n constructor(private loggers: Logger[]) {}\n\n /** {@inheritDoc Logger.debug} */\n debug(source: string, category: string, ...args: any) {\n for (const logger of this.loggers) {\n logger.debug(source, category, ...args);\n }\n }\n\n /** {@inheritDoc Logger.info} */\n info(source: string, category: string, ...args: any) {\n for (const logger of this.loggers) {\n logger.info(source, category, ...args);\n }\n }\n\n /** {@inheritDoc Logger.warn} */\n warn(source: string, category: string, ...args: any) {\n for (const logger of this.loggers) {\n logger.warn(source, category, ...args);\n }\n }\n\n /** {@inheritDoc Logger.error} */\n error(source: string, category: string, ...args: any) {\n for (const logger of this.loggers) {\n logger.error(source, category, ...args);\n }\n }\n\n /** {@inheritDoc Logger.perf} */\n perf(source: string, category: string, event: string, phase: 'Begin' | 'End', ...args: any) {\n for (const logger of this.loggers) {\n logger.perf(source, category, event, phase, ...args);\n }\n }\n}\n","/**\n * Stage of task\n *\n * @public\n */\nexport enum TaskStage {\n /**\n * Task is pending, means it just start executing\n */\n Pending = 0,\n /**\n * Task is succeed\n */\n Resolved = 1,\n /**\n * Task is failed\n */\n Rejected = 2,\n /**\n * Task is aborted\n */\n Aborted = 3,\n}\n\nexport interface TaskError<D> {\n /**\n * task error type\n */\n type: 'reject' | 'abort';\n /**\n * task error\n */\n reason: D;\n}\n\n/**\n * callback that will be called when task is resolved\n *\n * @public\n */\nexport type ResolvedCallback<R> = (r: R) => void;\n\n/**\n * callback that will be called when task is rejected\n *\n * @public\n */\nexport type RejectedCallback<D> = (e: TaskError<D>) => void;\n\n/**\n * Task state in different stage\n *\n * @public\n */\nexport type TaskState<R, D> =\n | {\n stage: TaskStage.Pending;\n }\n | {\n stage: TaskStage.Resolved;\n result: R;\n }\n | {\n stage: TaskStage.Rejected;\n reason: D;\n }\n | {\n stage: TaskStage.Aborted;\n reason: D;\n };\n\nexport class TaskAbortedError<D> extends Error {\n constructor(reason: D) {\n super(`Task aborted: ${JSON.stringify(reason)}`);\n this.name = 'TaskAbortedError';\n }\n}\n\nexport class TaskRejectedError<D> extends Error {\n constructor(reason: D) {\n super(`Task rejected: ${JSON.stringify(reason)}`);\n this.name = 'TaskRejectedError';\n }\n}\n\n/**\n * Base class of task\n *\n * @public\n */\nexport class Task<R, D> {\n state: TaskState<R, D> = {\n stage: TaskStage.Pending,\n };\n /**\n * callbacks that will be executed when task is resolved\n */\n resolvedCallbacks: ResolvedCallback<R>[] = [];\n /**\n * callbacks that will be executed when task is rejected\n */\n rejectedCallbacks: RejectedCallback<D>[] = [];\n\n /**\n * Promise that will be resolved when task is settled\n */\n private _promise: Promise<R> | null = null;\n\n /**\n * Convert task to promise\n * @returns promise that will be resolved when task is settled\n */\n toPromise(): Promise<R> {\n if (!this._promise) {\n this._promise = new Promise((resolve, reject) => {\n this.wait(\n (result) => resolve(result),\n (error) => {\n if (error.type === 'abort') {\n reject(new TaskAbortedError(error.reason));\n } else {\n reject(new TaskRejectedError(error.reason));\n }\n },\n );\n });\n }\n return this._promise;\n }\n\n /**\n * wait for task to be settled\n * @param resolvedCallback - callback for resolved value\n * @param rejectedCallback - callback for rejected value\n */\n wait(resolvedCallback: ResolvedCallback<R>, rejectedCallback: RejectedCallback<D>) {\n switch (this.state.stage) {\n case TaskStage.Pending:\n this.resolvedCallbacks.push(resolvedCallback);\n this.rejectedCallbacks.push(rejectedCallback);\n break;\n case TaskStage.Resolved:\n resolvedCallback(this.state.result);\n break;\n case TaskStage.Rejected:\n rejectedCallback({\n type: 'reject',\n reason: this.state.reason,\n });\n break;\n case TaskStage.Aborted:\n rejectedCallback({\n type: 'abort',\n reason: this.state.reason,\n });\n break;\n }\n }\n\n /**\n * resolve task with specific result\n * @param result - result value\n */\n resolve(result: R) {\n if (this.state.stage === TaskStage.Pending) {\n this.state = {\n stage: TaskStage.Resolved,\n result,\n };\n for (const resolvedCallback of this.resolvedCallbacks) {\n try {\n resolvedCallback(result);\n } catch (e) {\n /* ignore */\n }\n }\n this.resolvedCallbacks = [];\n this.rejectedCallbacks = [];\n }\n }\n\n /**\n * reject task with specific reason\n * @param reason - abort reason\n *\n */\n reject(reason: D) {\n if (this.state.stage === TaskStage.Pending) {\n this.state = {\n stage: TaskStage.Rejected,\n reason,\n };\n for (const rejectedCallback of this.rejectedCallbacks) {\n try {\n rejectedCallback({\n type: 'reject',\n reason,\n });\n } catch (e) {\n /*ignore */\n }\n }\n this.resolvedCallbacks = [];\n this.rejectedCallbacks = [];\n }\n }\n\n /**\n * abort task with specific reason\n * @param reason - abort reason\n */\n abort(reason: D) {\n if (this.state.stage === TaskStage.Pending) {\n this.state = {\n stage: TaskStage.Aborted,\n reason,\n };\n for (const rejectedCallback of this.rejectedCallbacks) {\n try {\n rejectedCallback({\n type: 'abort',\n reason,\n });\n } catch (e) {\n /* ignore */\n }\n }\n this.resolvedCallbacks = [];\n this.rejectedCallbacks = [];\n }\n }\n\n /**\n * fail task with a TaskError from another task\n * This is a convenience method for error propagation between tasks\n * @param error - TaskError from another task\n */\n fail(error: TaskError<D>) {\n if (error.type === 'abort') {\n this.abort(error.reason);\n } else {\n this.reject(error.reason);\n }\n }\n}\n\n/**\n * Type that represent the result of executing task\n */\nexport type TaskReturn<T extends Task<any, any>> =\n T extends Task<infer R, infer E>\n ? { type: 'result'; value: R } | { type: 'error'; value: TaskError<E> }\n : never;\n","import { Size, Rect, Position, Rotation, Quad } from './geometry';\nimport { Task, TaskError } from './task';\n\n/**\n * Representation of pdf page\n *\n * @public\n */\nexport interface PdfPageObject {\n /**\n * Index of this page, starts from 0\n */\n index: number;\n\n /**\n * Orignal size of this page\n */\n size: Size;\n}\n\n/**\n * Representation of pdf page with rotated size\n *\n * @public\n */\nexport interface PdfPageObjectWithRotatedSize extends PdfPageObject {\n /**\n * Rotated size of this page\n */\n rotatedSize: Size;\n}\n\n/**\n * Representation of pdf document\n *\n * @public\n */\nexport interface PdfDocumentObject {\n /**\n * Identity of document\n */\n id: string;\n\n /**\n * Count of pages in this document\n */\n pageCount: number;\n\n /**\n * Pages in this document\n */\n pages: PdfPageObject[];\n}\n\n/**\n * metadata of pdf document\n *\n * @public\n */\nexport interface PdfMetadataObject {\n /**\n * title of the document\n */\n title: string;\n /**\n * author of the document\n */\n author: string;\n /**\n * subject of the document\n */\n subject: string;\n /**\n * keywords of the document\n */\n keywords: string;\n /**\n * producer of the document\n */\n producer: string;\n /**\n * creator of the document\n */\n creator: string;\n /**\n * creation date of the document\n */\n creationDate: string;\n /**\n * modification date of the document\n */\n modificationDate: string;\n}\n\n/**\n * zoom mode\n *\n * @public\n */\nexport enum PdfZoomMode {\n Unknown = 0,\n /**\n * Zoom level with specified offset.\n */\n XYZ = 1,\n /**\n * Fit both the width and height of the page (whichever smaller).\n */\n FitPage = 2,\n /**\n * Fit the page width.\n */\n FitHorizontal = 3,\n /**\n * Fit the page height.\n */\n FitVertical = 4,\n /**\n * Fit a specific rectangle area within the window.\n */\n FitRectangle = 5,\n}\n\n/**\n * Representation of the linked destination\n *\n * @public\n */\nexport interface PdfDestinationObject {\n /**\n * Index of target page\n */\n pageIndex: number;\n /**\n * zoom config for target destination\n */\n zoom:\n | {\n mode: PdfZoomMode.Unknown;\n }\n | { mode: PdfZoomMode.XYZ; params: { x: number; y: number; zoom: number } }\n | {\n mode: PdfZoomMode.FitPage;\n }\n | {\n mode: PdfZoomMode.FitHorizontal;\n }\n | {\n mode: PdfZoomMode.FitVertical;\n }\n | {\n mode: PdfZoomMode.FitRectangle;\n };\n view: number[];\n}\n\n/**\n * Type of pdf action\n *\n * @public\n */\nexport enum PdfActionType {\n Unsupported = 0,\n /**\n * Goto specified position in this document\n */\n Goto = 1,\n /**\n * Goto specified position in another document\n */\n RemoteGoto = 2,\n /**\n * Goto specified URI\n */\n URI = 3,\n /**\n * Launch specifed application\n */\n LaunchAppOrOpenFile = 4,\n}\n\nexport type PdfImage = {\n data: Uint8ClampedArray;\n width: number;\n height: number;\n};\n\n/**\n * Representation of pdf action\n *\n * @public\n */\nexport type PdfActionObject =\n | {\n type: PdfActionType.Unsupported;\n }\n | {\n type: PdfActionType.Goto;\n destination: PdfDestinationObject;\n }\n | {\n type: PdfActionType.RemoteGoto;\n destination: PdfDestinationObject;\n }\n | {\n type: PdfActionType.URI;\n uri: string;\n }\n | {\n type: PdfActionType.LaunchAppOrOpenFile;\n path: string;\n };\n\n/**\n * target of pdf link\n *\n * @public\n */\nexport type PdfLinkTarget =\n | {\n type: 'action';\n action: PdfActionObject;\n }\n | {\n type: 'destination';\n destination: PdfDestinationObject;\n };\n\n/**\n * PDF bookmark\n *\n * @public\n */\nexport interface PdfBookmarkObject {\n /**\n * title of bookmark\n */\n title: string;\n\n /**\n * target of bookmark\n */\n target?: PdfLinkTarget | undefined;\n\n /**\n * bookmarks in the next level\n */\n children?: PdfBookmarkObject[];\n}\n\n/**\n * Pdf Signature\n *\n * @public\n */\nexport interface PdfSignatureObject {\n /**\n * contents of signature\n */\n contents: ArrayBuffer;\n\n /**\n * byte range of signature\n */\n byteRange: ArrayBuffer;\n\n /**\n * sub filters of signature\n */\n subFilter: ArrayBuffer;\n\n /**\n * reason of signature\n */\n reason: string;\n\n /**\n * creation time of signature\n */\n time: string;\n\n /**\n * MDP\n */\n docMDP: number;\n}\n\n/**\n * Bookmark tree of pdf\n *\n * @public\n */\nexport interface PdfBookmarksObject {\n bookmarks: PdfBookmarkObject[];\n}\n\n/**\n * Text rectangle in pdf page\n *\n * @public\n */\nexport interface PdfTextRectObject {\n /**\n * Font of the text\n */\n font: {\n /**\n * font family\n */\n family: string;\n\n /**\n * font size\n */\n size: number;\n };\n\n /**\n * content in this rectangle area\n */\n content: string;\n\n /**\n * rectangle of the text\n */\n rect: Rect;\n}\n\n/**\n * Color\n *\n * @public\n */\nexport interface PdfAlphaColor {\n /**\n * red\n */\n red: number;\n /**\n * green\n */\n green: number;\n /**\n * blue\n */\n blue: number;\n /**\n * alpha\n */\n alpha: number;\n}\n\n/**\n * Annotation type\n *\n * @public\n */\nexport enum PdfAnnotationSubtype {\n UNKNOWN = 0,\n TEXT,\n LINK,\n FREETEXT,\n LINE,\n SQUARE,\n CIRCLE,\n POLYGON,\n POLYLINE,\n HIGHLIGHT,\n UNDERLINE,\n SQUIGGLY,\n STRIKEOUT,\n STAMP,\n CARET,\n INK,\n POPUP,\n FILEATTACHMENT,\n SOUND,\n MOVIE,\n WIDGET,\n SCREEN,\n PRINTERMARK,\n TRAPNET,\n WATERMARK,\n THREED,\n RICHMEDIA,\n XFAWIDGET,\n REDACT,\n}\n\n/**\n * Name of annotation type\n *\n * @public\n */\nexport const PdfAnnotationSubtypeName: Record<PdfAnnotationSubtype, string> = {\n [PdfAnnotationSubtype.UNKNOWN]: 'unknow',\n [PdfAnnotationSubtype.TEXT]: 'text',\n [PdfAnnotationSubtype.LINK]: 'link',\n [PdfAnnotationSubtype.FREETEXT]: 'freetext',\n [PdfAnnotationSubtype.LINE]: 'line',\n [PdfAnnotationSubtype.SQUARE]: 'square',\n [PdfAnnotationSubtype.CIRCLE]: 'circle',\n [PdfAnnotationSubtype.POLYGON]: 'polygon',\n [PdfAnnotationSubtype.POLYLINE]: 'polyline',\n [PdfAnnotationSubtype.HIGHLIGHT]: 'highlight',\n [PdfAnnotationSubtype.UNDERLINE]: 'underline',\n [PdfAnnotationSubtype.SQUIGGLY]: 'squiggly',\n [PdfAnnotationSubtype.STRIKEOUT]: 'strikeout',\n [PdfAnnotationSubtype.STAMP]: 'stamp',\n [PdfAnnotationSubtype.CARET]: 'caret',\n [PdfAnnotationSubtype.INK]: 'ink',\n [PdfAnnotationSubtype.POPUP]: 'popup',\n [PdfAnnotationSubtype.FILEATTACHMENT]: 'fileattachment',\n [PdfAnnotationSubtype.SOUND]: 'sound',\n [PdfAnnotationSubtype.MOVIE]: 'movie',\n [PdfAnnotationSubtype.WIDGET]: 'widget',\n [PdfAnnotationSubtype.SCREEN]: 'screen',\n [PdfAnnotationSubtype.PRINTERMARK]: 'printermark',\n [PdfAnnotationSubtype.TRAPNET]: 'trapnet',\n [PdfAnnotationSubtype.WATERMARK]: 'watermark',\n [PdfAnnotationSubtype.THREED]: 'threed',\n [PdfAnnotationSubtype.RICHMEDIA]: 'richmedia',\n [PdfAnnotationSubtype.XFAWIDGET]: 'xfawidget',\n [PdfAnnotationSubtype.REDACT]: 'redact',\n};\n\n/**\n * Status of pdf annotation\n *\n * @public\n */\nexport enum PdfAnnotationObjectStatus {\n /**\n * Annotation is created\n */\n Created,\n /**\n * Annotation is committed to PDF file\n */\n Committed,\n}\n\n/**\n * Appearance mode\n *\n * @public\n */\nexport enum AppearanceMode {\n Normal = 0,\n Rollover = 1,\n Down = 2,\n}\n\n/**\n * State of pdf annotation\n *\n * @public\n */\nexport enum PdfAnnotationState {\n /**\n * Annotation is active\n */\n Marked = 'Marked',\n /**\n * Annotation is unmarked\n */\n Unmarked = 'Unmarked',\n /**\n * Annotation is ink\n */\n Accepted = 'Accepted',\n /**\n * Annotation is rejected\n */\n Rejected = 'Rejected',\n /**\n * Annotation is complete\n */\n Complete = 'Complete',\n /**\n * Annotation is cancelled\n */\n Cancelled = 'Cancelled',\n /**\n * Annotation is none\n */\n None = 'None',\n}\n\n/**\n * State model of pdf annotation\n *\n * @public\n */\nexport enum PdfAnnotationStateModel {\n /**\n * Annotation is marked\n */\n Marked = 'Marked',\n /**\n * Annotation is reviewed\n */\n Reviewed = 'Reviewed',\n}\n\n/**\n * Basic information of pdf annotation\n *\n * @public\n */\nexport interface PdfAnnotationObjectBase {\n /**\n * Author of the annotation\n */\n author?: string;\n\n /**\n * Modified date of the annotation\n */\n modified?: string;\n\n /**\n * Sub type of annotation\n */\n type: PdfAnnotationSubtype;\n\n /**\n * Status of pdf annotation\n */\n status: PdfAnnotationObjectStatus;\n\n /**\n * The index of page that this annotation belong to\n */\n pageIndex: number;\n\n /**\n * id of the annotation\n */\n id: number;\n\n /**\n * Rectangle of the annotation\n */\n rect: Rect;\n\n /**\n * Related popup annotation\n */\n popup?: PdfPopupAnnoObject | undefined;\n\n /**\n * Appearences of annotation\n */\n appearances: {\n normal: string;\n rollover: string;\n down: string;\n };\n}\n\n/**\n * Popup annotation\n *\n * @public\n */\nexport interface PdfPopupAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.POPUP;\n /**\n * Contents of the popup\n */\n contents: string;\n\n /**\n * Whether the popup is opened or not\n */\n open: boolean;\n}\n\n/**\n * Pdf Link annotation\n *\n * @public\n */\nexport interface PdfLinkAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.LINK;\n /**\n * Text of the link\n */\n text: string;\n /**\n * target of the link\n */\n target: PdfLinkTarget | undefined;\n}\n\n/**\n * Pdf Text annotation\n *\n * @public\n */\nexport interface PdfTextAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.TEXT;\n /**\n * Text contents of the annotation\n */\n contents: string;\n\n /**\n * Color of the text\n */\n color: PdfAlphaColor;\n\n /**\n * In reply to id\n */\n inReplyToId?: number;\n\n /**\n * State of the text annotation\n */\n state?: PdfAnnotationState;\n\n /**\n * State model of the text annotation\n */\n stateModel?: PdfAnnotationStateModel;\n}\n\n/**\n * Type of form field\n *\n * @public\n */\nexport enum PDF_FORM_FIELD_TYPE {\n /**\n * Unknow\n */\n UNKNOWN = 0,\n /**\n * push button type\n */\n PUSHBUTTON = 1,\n /**\n * check box type.\n */\n CHECKBOX = 2,\n /**\n * radio button type.\n */\n RADIOBUTTON = 3,\n /**\n * combo box type.\n */\n COMBOBOX = 4,\n /**\n * list box type.\n */\n LISTBOX = 5,\n /**\n * text field type\n */\n TEXTFIELD = 6,\n /**\n * signature field type.\n */\n SIGNATURE = 7,\n /**\n * Generic XFA type.\n */\n XFA = 8,\n /**\n * XFA check box type.\n */\n XFA_CHECKBOX = 9,\n /**\n * XFA combo box type.\n */\n XFA_COMBOBOX = 10,\n /**\n * XFA image field type.\n */\n XFA_IMAGEFIELD = 11,\n /**\n * XFA list box type.\n */\n XFA_LISTBOX = 12,\n /**\n * XFA push button type.\n */\n XFA_PUSHBUTTON = 13,\n /**\n * XFA signture field type.\n */\n XFA_SIGNATURE = 14,\n /**\n * XFA text field type.\n */\n XFA_TEXTFIELD = 15,\n}\n\n/**\n * Flag of form field\n *\n * @public\n */\nexport enum PDF_FORM_FIELD_FLAG {\n NONE = 0,\n READONLY = 1 << 0,\n REQUIRED = 1 << 1,\n NOEXPORT = 1 << 2,\n TEXT_MULTIPLINE = 1 << 12,\n TEXT_PASSWORD = 1 << 13,\n CHOICE_COMBO = 1 << 17,\n CHOICE_EDIT = 1 << 18,\n CHOICE_MULTL_SELECT = 1 << 21,\n}\n\n/**\n * Type of pdf object\n *\n * @public\n */\nexport enum PdfPageObjectType {\n UNKNOWN = 0,\n TEXT = 1,\n PATH = 2,\n IMAGE = 3,\n SHADING = 4,\n FORM = 5,\n}\n\n/**\n * Options of pdf widget annotation\n *\n * @public\n */\nexport interface PdfWidgetAnnoOption {\n label: string;\n isSelected: boolean;\n}\n\n/**\n * Field of PDF widget annotation\n *\n * @public\n */\nexport interface PdfWidgetAnnoField {\n /**\n * flag of field\n */\n flag: PDF_FORM_FIELD_FLAG;\n /**\n * name of field\n */\n name: string;\n /**\n * alternate name of field\n */\n alternateName: string;\n /**\n * type of field\n */\n type: PDF_FORM_FIELD_TYPE;\n /**\n * value of field\n */\n value: string;\n /**\n * whether field is checked\n */\n isChecked: boolean;\n /**\n * options of field\n */\n options: PdfWidgetAnnoOption[];\n}\n\n/**\n * PDF widget object\n *\n * @public\n */\nexport interface PdfWidgetAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.WIDGET;\n /**\n * Field of pdf widget object\n */\n field: PdfWidgetAnnoField;\n}\n\n/**\n * Pdf file attachments annotation\n *\n * @public\n */\nexport interface PdfFileAttachmentAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.FILEATTACHMENT;\n}\n\n/**\n * ink list in pdf ink annotation\n *\n * @public\n */\nexport interface PdfInkListObject {\n points: Position[];\n}\n\n/**\n * Pdf ink annotation\n *\n * @public\n */\nexport interface PdfInkAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.INK;\n inkList: PdfInkListObject[];\n}\n\n/**\n * Pdf polygon annotation\n *\n * @public\n */\nexport interface PdfPolygonAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.POLYGON;\n /**\n * vertices of annotation\n */\n vertices: Position[];\n}\n\n/**\n * PDF polyline annotation\n *\n * @public\n */\nexport interface PdfPolylineAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.POLYLINE;\n /**\n * vertices of annotation\n */\n vertices: Position[];\n}\n\n/**\n * PDF line annotation\n *\n * @public\n */\nexport interface PdfLineAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.LINE;\n /**\n * start point of line\n */\n startPoint: Position;\n /**\n * end point of line\n */\n endPoint: Position;\n}\n\n/**\n * PDF highlight annotation\n *\n * @public\n */\nexport interface PdfHighlightAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.HIGHLIGHT;\n\n /**\n * color of highlight area\n */\n color?: PdfAlphaColor;\n\n /**\n * quads of highlight area\n */\n segmentRects: Rect[];\n}\n\n/**\n * Matrix for transformation, in the form [a b c d e f], equivalent to:\n * | a b 0 |\n * | c d 0 |\n * | e f 1 |\n *\n * Translation is performed with [1 0 0 1 tx ty].\n * Scaling is performed with [sx 0 0 sy 0 0].\n * See PDF Reference 1.7, 4.2.2 Common Transformations for more.\n */\nexport interface PdfTransformMatrix {\n a: number;\n b: number;\n c: number;\n d: number;\n e: number;\n f: number;\n}\n\n/**\n * type of segment type in pdf path object\n *\n * @public\n */\nexport enum PdfSegmentObjectType {\n UNKNOWN = -1,\n LINETO = 0,\n BEZIERTO = 1,\n MOVETO = 2,\n}\n\n/**\n * segment of path object\n *\n * @public\n */\nexport interface PdfSegmentObject {\n type: PdfSegmentObjectType;\n /**\n * point of the segment\n */\n point: Position;\n /**\n * whether this segment close the path\n */\n isClosed: boolean;\n}\n\n/**\n * Pdf path object\n *\n * @public\n */\nexport interface PdfPathObject {\n type: PdfPageObjectType.PATH;\n /**\n * bound that contains the path\n */\n bounds: { left: number; bottom: number; right: number; top: number };\n /**\n * segments of the path\n */\n segments: PdfSegmentObject[];\n /**\n * transform matrix\n */\n matrix: PdfTransformMatrix;\n}\n\n/**\n * Pdf image object\n *\n * @public\n */\nexport interface PdfImageObject {\n type: PdfPageObjectType.IMAGE;\n /**\n * data of the image\n */\n imageData: ImageData;\n /**\n * transform matrix\n */\n matrix: PdfTransformMatrix;\n}\n\n/**\n * Pdf form object\n *\n * @public\n */\nexport interface PdfFormObject {\n type: PdfPageObjectType.FORM;\n /**\n * objects that in this form object\n */\n objects: (PdfImageObject | PdfPathObject | PdfFormObject)[];\n /**\n * transform matrix\n */\n matrix: PdfTransformMatrix;\n}\n\n/**\n * Contents type of pdf stamp annotation\n *\n * @public\n */\nexport type PdfStampAnnoObjectContents = Array<PdfPathObject | PdfImageObject | PdfFormObject>;\n\n/**\n * Pdf stamp annotation\n *\n * @public\n */\nexport interface PdfStampAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.STAMP;\n /**\n * contents in this stamp annotation\n */\n contents: PdfStampAnnoObjectContents;\n}\n\n/**\n * Pdf circle annotation\n *\n * @public\n */\nexport interface PdfCircleAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.CIRCLE;\n}\n\n/**\n * Pdf square annotation\n *\n * @public\n */\nexport interface PdfSquareAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.SQUARE;\n}\n\n/**\n * Pdf squiggly annotation\n *\n * @public\n */\nexport interface PdfSquigglyAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.SQUIGGLY;\n}\n\n/**\n * Pdf underline annotation\n *\n * @public\n */\nexport interface PdfUnderlineAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.UNDERLINE;\n}\n\n/**\n * Pdf strike out annotation\n *\n * @public\n */\nexport interface PdfStrikeOutAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.STRIKEOUT;\n}\n\n/**\n * Pdf caret annotation\n *\n * @public\n */\nexport interface PdfCaretAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.CARET;\n}\n\n/**\n * Pdf free text annotation\n *\n * @public\n */\nexport interface PdfFreeTextAnnoObject extends PdfAnnotationObjectBase {\n /** {@inheritDoc PdfAnnotationObjectBase.type} */\n type: PdfAnnotationSubtype.FREETEXT;\n contents: string;\n}\n\n/**\n * All annotation that support\n *\n * @public\n */\nexport type PdfSupportedAnnoObject =\n | PdfInkAnnoObject\n | PdfTextAnnoObject\n | PdfLinkAnnoObject\n | PdfPolygonAnnoObject\n | PdfPolylineAnnoObject\n | PdfHighlightAnnoObject\n | PdfLineAnnoObject\n | PdfWidgetAnnoObject\n | PdfFileAttachmentAnnoObject\n | PdfStampAnnoObject\n | PdfSquareAnnoObject\n | PdfCircleAnnoObject\n | PdfSquigglyAnnoObject\n | PdfUnderlineAnnoObject\n | PdfStrikeOutAnnoObject\n | PdfCaretAnnoObject\n | PdfFreeTextAnnoObject;\n\n/**\n * Pdf annotation that does not support\n *\n * @public\n */\nexport interface PdfUnsupportedAnnoObject extends PdfAnnotationObjectBase {\n type: Exclude<PdfAnnotationSubtype, PdfSupportedAnnoObject['type']>;\n}\n\n/**\n * all annotations\n *\n * @public\n */\nexport type PdfAnnotationObject = PdfSupportedAnnoObject | PdfUnsupportedAnnoObject;\n\n/**\n * Pdf attachment\n *\n * @public\n */\nexport interface PdfAttachmentObject {\n index: number;\n name: string;\n creationDate: string;\n checksum: string;\n}\n\n/**\n * Pdf engine features\n *\n * @public\n */\nexport enum PdfEngineFeature {\n RenderPage,\n RenderPageRect,\n Thumbnails,\n Bookmarks,\n Annotations,\n}\n\n/**\n * All operations for this engine\n *\n * @public\n */\nexport enum PdfEngineOperation {\n Create,\n Read,\n Update,\n Delete,\n}\n\n/**\n * flags to match the text during searching\n *\n * @public\n */\nexport enum MatchFlag {\n None = 0,\n MatchCase = 1,\n MatchWholeWord = 2,\n MatchConsecutive = 4,\n}\n\n/**\n * Union all the flags\n * @param flags - all the flags\n * @returns union of flags\n *\n * @public\n */\nexport function unionFlags(flags: MatchFlag[]) {\n return flags.reduce((flag, currFlag) => {\n return flag | currFlag;\n }, MatchFlag.None);\n}\n\n/**\n * Image conversion types\n *\n * @public\n */\nexport type ImageConversionTypes = 'image/webp' | 'image/png' | 'image/jpeg';\n\n/**\n * Targe for searching\n *\n * @public\n */\nexport interface SearchTarget {\n keyword: string;\n flags: MatchFlag[];\n}\n\n/**\n * compare 2 search target\n * @param targetA - first target for search\n * @param targetB - second target for search\n * @returns whether 2 search target are the same\n *\n * @public\n */\nexport function compareSearchTarget(targetA: SearchTarget, targetB: SearchTarget) {\n const flagA = unionFlags(targetA.flags);\n const flagB = unionFlags(targetB.flags);\n\n return flagA === flagB && targetA.keyword === targetB.keyword;\n}\n\n/** Context of one hit */\nexport interface TextContext {\n /** Complete words that come *before* the hit (no ellipsis) */\n before: string;\n /** Exactly the text that matched (case-preserved) */\n match: string;\n /** Complete words that come *after* the hit (no ellipsis) */\n after: string;\n /** `true` ⇢ there were more words on the left that we cut off */\n truncatedLeft: boolean;\n /** `true` ⇢ there were more words on the right that we cut off */\n truncatedRight: boolean;\n}\n\n/**\n * search result\n *\n * @public\n */\nexport interface SearchResult {\n /**\n * Index of the pdf page\n */\n pageIndex: number;\n /**\n * index of the first character\n */\n charIndex: number;\n /**\n * count of the characters\n */\n charCount: number;\n /**\n * highlight rects\n */\n rects: Rect[];\n /**\n * context of the hit\n */\n context: TextContext;\n}\n\n/**\n * Results of searching through the entire document\n */\nexport interface SearchAllPagesResult {\n /**\n * Array of all search results across all pages\n */\n results: SearchResult[];\n\n /**\n * Total number of results found\n */\n total: number;\n}\n\n/**\n * Glyph object\n *\n * @public\n */\nexport interface PdfGlyphObject {\n /**\n * Origin of the glyph\n */\n origin: { x: number; y: number };\n /**\n * Size of the glyph\n */\n size: { width: number; height: number };\n /**\n * Whether the glyph is a space\n */\n isSpace?: boolean;\n /**\n * Whether the glyph is a empty\n */\n isEmpty?: boolean;\n}\n\n/**\n * Glyph object\n *\n * @public\n */\nexport interface PdfGlyphSlim {\n /**\n * X coordinate of the glyph\n */\n x: number;\n /**\n * Y coordinate of the glyph\n */\n y: number;\n /**\n * Width of the glyph\n */\n width: number;\n /**\n * Height of the glyph\n */\n height: number;\n /**\n * Flags of the glyph\n */\n flags: number;\n}\n\n/**\n * Run object\n *\n * @public\n */\nexport interface PdfRun {\n /**\n * Rectangle of the run\n */\n rect: { x: number; y: number; width: number; height: number };\n /**\n * Start index of the run\n */\n charStart: number;\n /**\n * Glyphs of the run\n */\n glyphs: PdfGlyphSlim[];\n}\n\n/**\n * Page geometry\n *\n * @public\n */\nexport interface PdfPageGeometry {\n /**\n * Runs of the page\n */\n runs: PdfRun[];\n}\n\n/**\n * form field value\n * @public\n */\nexport type FormFieldValue =\n | { kind: 'text'; text: string }\n | { kind: 'selection'; index: number; isSelected: boolean }\n | { kind: 'checked'; isChecked: boolean };\n\n/**\n * Transformation that will be applied to annotation\n *\n * @public\n */\nexport interface PdfAnnotationTransformation {\n /**\n * Translated offset\n */\n offset: Position;\n /**\n * Scaled factors\n */\n scale: Size;\n}\n\n/**\n * Render options\n *\n * @public\n */\nexport interface PdfRenderOptions {\n /**\n * Whether needs to render the page with annotations\n */\n withAnnotations: boolean;\n}\n\n/**\n * source can be byte array contains pdf content\n *\n * @public\n */\nexport type PdfFileContent = ArrayBuffer;\n\nexport enum PdfPermission {\n PrintDocument = 2 ** 3,\n ModifyContent = 2 ** 4,\n CopyOrExtract = 2 ** 5,\n AddOrModifyTextAnnot = 2 ** 6,\n FillInExistingForm = 2 ** 9,\n ExtractTextOrGraphics = 2 ** 10,\n AssembleDocument = 2 ** 11,\n PrintHighQuality = 2 ** 12,\n}\n\nexport enum PdfPageFlattenFlag {\n Display = 0,\n Print = 1,\n}\n\nexport enum PdfPageFlattenResult {\n Fail = 0,\n Success = 1,\n NothingToDo = 2,\n}\n\n/**\n * Pdf File without content\n *\n * @public\n */\nexport interface PdfFileWithoutContent {\n /**\n * id of file\n */\n id: string;\n}\n\nexport interface PdfFileLoader extends PdfFileWithoutContent {\n /**\n * length of file\n */\n fileLength: number;\n /**\n * read block of file\n * @param offset - offset of file\n * @param length - length of file\n * @returns block of file\n */\n callback: (offset: number, length: number) => Uint8Array;\n}\n\n/**\n * Pdf File\n *\n * @public\n */\nexport interface PdfFile extends PdfFileWithoutContent {\n /**\n * content of file\n */\n content: PdfFileContent;\n}\n\nexport interface PdfFileUrl extends PdfFileWithoutContent {\n url: string;\n}\n\nexport interface PdfUrlOptions {\n mode?: 'auto' | 'range-request' | 'full-fetch';\n password?: string;\n}\n\nexport enum PdfErrorCode {\n Ok, // #define FPDF_ERR_SUCCESS 0 // No error.\n Unknown, // #define FPDF_ERR_UNKNOWN 1 // Unknown error.\n NotFound, // #define FPDF_ERR_FILE 2 // File not found or could not be opened.\n WrongFormat, // #define FPDF_ERR_FORMAT 3 // File not in PDF format or corrupted.\n Password, // #define FPDF_ERR_PASSWORD 4 // Password required or incorrect password.\n Security, // #define FPDF_ERR_SECURITY 5 // Unsupported security scheme.\n PageError, // #define FPDF_ERR_PAGE 6 // Page not found or content error.\n XFALoad, // #ifdef PDF_ENABLE_XFA\n XFALayout, //\n Cancelled,\n Initialization,\n NotReady,\n NotSupport,\n LoadDoc,\n DocNotOpen,\n CantCloseDoc,\n CantCreateNewDoc,\n CantImportPages,\n CantCreateAnnot,\n CantSetAnnotRect,\n CantSetAnnotContent,\n CantRemoveInkList,\n CantAddInkStoke,\n CantReadAttachmentSize,\n CantReadAttachmentContent,\n CantFocusAnnot,\n CantSelectText,\n CantSelectOption,\n CantCheckField,\n}\n\nexport interface PdfErrorReason {\n code: PdfErrorCode;\n message: string;\n}\n\nexport type PdfEngineError = TaskError<PdfErrorReason>;\n\nexport type PdfTask<R> = Task<R, PdfErrorReason>;\n\nexport class PdfTaskHelper {\n /**\n * Create a task\n * @returns new task\n */\n static create<R>(): Task<R, PdfErrorReason> {\n return new Task<R, PdfErrorReason>();\n }\n\n /**\n * Create a task that has been resolved with value\n * @param result - resolved value\n * @returns resolved task\n */\n static resolve<R>(result: R): Task<R, PdfErrorReason> {\n const task = new Task<R, PdfErrorReason>();\n task.resolve(result);\n\n return task;\n }\n\n /**\n * Create a task that has been rejected with error\n * @param reason - rejected error\n * @returns rejected task\n */\n static reject<T = any>(reason: PdfErrorReason): Task<T, PdfErrorReason> {\n const task = new Task<T, PdfErrorReason>();\n task.reject(reason);\n\n return task;\n }\n\n /**\n * Create a task that has been aborted with error\n * @param reason - aborted error\n * @returns aborted task\n */\n static abort<T = any>(reason: PdfErrorReason): Task<T, PdfErrorReason> {\n const task = new Task<T, PdfErrorReason>();\n task.reject(reason);\n\n return task;\n }\n}\n\n/**\n * Pdf engine\n *\n * @public\n */\nexport interface PdfEngine<T = Blob> {\n /**\n * Check whether pdf engine supports this feature\n * @param feature - which feature want to check\n * @returns support or not\n */\n isSupport?: (feature: PdfEngineFeature) => PdfTask<PdfEngineOperation[]>;\n /**\n * Initialize the engine\n * @returns task that indicate whether initialization is successful\n */\n initialize?: () => PdfTask<boolean>;\n /**\n * Destroy the engine\n * @returns task that indicate whether destroy is successful\n */\n destroy?: () => PdfTask<boolean>;\n /**\n * Open a PDF from a URL with specified mode\n * @param url - The PDF file URL\n * @param options - Additional options including mode (auto, range-request, full-fetch) and password\n * @returns Task that resolves with the PdfDocumentObject or an error\n */\n openDocumentUrl: (file: PdfFileUrl, options?: PdfUrlOptions) => PdfTask<PdfDocumentObject>;\n /**\n * Open pdf document from buffer\n * @param file - pdf file\n * @param password - protected password for this file\n * @returns task that contains the file or error\n */\n openDocumentFromBuffer: (file: PdfFile, password: string) => PdfTask<PdfDocumentObject>;\n /**\n * Open pdf document from loader\n * @param file - pdf file\n * @param password - protected password for this file\n * @returns task that contains the file or error\n */\n openDocumentFromLoader: (file: PdfFileLoader, password: string) => PdfTask<PdfDocumentObject>;\n /**\n * Get the metadata of the file\n * @param doc - pdf document\n * @returns task that contains the metadata or error\n */\n getMetadata: (doc: PdfDocumentObject) => PdfTask<PdfMetadataObject>;\n /**\n * Get permissions of the file\n * @param doc - pdf document\n * @returns task that contains a 32-bit integer indicating permission flags\n */\n getDocPermissions: (doc: PdfDocumentObject) => PdfTask<number>;\n /**\n * Get the user permissions of the file\n * @param doc - pdf document\n * @returns task that contains a 32-bit integer indicating permission flags\n */\n getDocUserPermissions: (doc: PdfDocumentObject) => PdfTask<number>;\n /**\n * Get the signatures of the file\n * @param doc - pdf document\n * @returns task that contains the signatures or error\n */\n getSignatures: (doc: PdfDocumentObject) => PdfTask<PdfSignatureObject[]>;\n /**\n * Get the bookmarks of the file\n * @param doc - pdf document\n * @returns task that contains the bookmarks or error\n */\n getBookmarks: (doc: PdfDocumentObject) => PdfTask<PdfBookmarksObject>;\n /**\n * Render the specified pdf page\n * @param doc - pdf document\n * @param page - pdf page\n * @param scaleFactor - factor of scaling\n * @param rotation - rotated angle\n * @param dpr - devicePixelRatio\n * @param options - render options\n * @returns task contains the rendered image or error\n */\n renderPage: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n scaleFactor: number,\n rotation: Rotation,\n dpr: number,\n options: PdfRenderOptions,\n imageType?: ImageConversionTypes,\n ) => PdfTask<T>;\n /**\n * Render the specified rect of pdf page\n * @param doc - pdf document\n * @param page - pdf page\n * @param scaleFactor - factor of scaling\n * @param rotation - rotated angle\n * @param dpr - devicePixelRatio\n * @param rect - target rect\n * @param options - render options\n * @returns task contains the rendered image or error\n */\n renderPageRect: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n scaleFactor: number,\n rotation: Rotation,\n dpr: number,\n rect: Rect,\n options: PdfRenderOptions,\n imageType?: ImageConversionTypes,\n ) => PdfTask<T>;\n /**\n * Get annotations of pdf page\n * @param doc - pdf document\n * @param page - pdf page\n * @param scaleFactor - factor of scaling\n * @param rotation - rotated angle\n * @returns task contains the annotations or error\n */\n getPageAnnotations: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n ) => PdfTask<PdfAnnotationObject[]>;\n /**\n * Create a annotation on specified page\n * @param doc - pdf document\n * @param page - pdf page\n * @param annotation - new annotations\n * @returns task whether the annotations is created successfully\n */\n createPageAnnotation: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n ) => PdfTask<boolean>;\n /**\n * Transform the annotation\n * @param doc - pdf document\n * @param page - pdf page\n * @param annotation - new annotations\n * @param transformation - transformation applied on the annotation\n * @returns task whether the annotations is transformed successfully\n */\n transformPageAnnotation: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n transformation: PdfAnnotationTransformation,\n ) => PdfTask<boolean>;\n /**\n * Remove a annotation on specified page\n * @param doc - pdf document\n * @param page - pdf page\n * @param annotation - new annotations\n * @returns task whether the annotations is removed successfully\n */\n removePageAnnotation: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfAnnotationObject,\n ) => PdfTask<boolean>;\n /**\n * get all text rects in pdf page\n * @param doc - pdf document\n * @param page - pdf page\n * @param scaleFactor - factor of scaling\n * @param rotation - rotated angle\n * @returns task contains the text rects or error\n */\n getPageTextRects: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n scaleFactor: number,\n rotation: Rotation,\n ) => PdfTask<PdfTextRectObject[]>;\n /**\n * Render the thumbnail of specified pdf page\n * @param doc - pdf document\n * @param page - pdf page\n * @param scaleFactor - factor of scaling\n * @param rotation - rotated angle\n * @param dpr - devicePixelRatio\n * @param options - render options\n * @returns task contains the rendered image or error\n */\n renderThumbnail: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n scaleFactor: number,\n rotation: Rotation,\n dpr: number,\n ) => PdfTask<T>;\n /**\n * Search across all pages in the document\n * @param doc - pdf document\n * @param keyword - search keyword\n * @param flags - match flags for search\n * @returns Task contains all search results throughout the document\n */\n searchAllPages: (\n doc: PdfDocumentObject,\n keyword: string,\n flags?: MatchFlag[],\n ) => PdfTask<SearchAllPagesResult>;\n /**\n * Get all annotations in this file\n * @param doc - pdf document\n * @returns task that contains the annotations or error\n */\n getAllAnnotations: (doc: PdfDocumentObject) => PdfTask<Record<number, PdfAnnotationObject[]>>;\n /**\n * Get all attachments in this file\n * @param doc - pdf document\n * @returns task that contains the attachments or error\n */\n getAttachments: (doc: PdfDocumentObject) => PdfTask<PdfAttachmentObject[]>;\n /**\n * Read content of pdf attachment\n * @param doc - pdf document\n * @param attachment - pdf attachments\n * @returns task that contains the content of specified attachment or error\n */\n readAttachmentContent: (\n doc: PdfDocumentObject,\n attachment: PdfAttachmentObject,\n ) => PdfTask<ArrayBuffer>;\n /**\n * Set form field value\n * @param doc - pdf document\n * @param page - pdf page\n * @param annotation - pdf annotation\n * @param text - text value\n */\n setFormFieldValue: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n annotation: PdfWidgetAnnoObject,\n value: FormFieldValue,\n ) => PdfTask<boolean>;\n /**\n * Flatten annotations and form fields into the page contents.\n * @param doc - pdf document\n * @param page - pdf page\n * @param flag - flatten flag\n */\n flattenPage: (\n doc: PdfDocumentObject,\n page: PdfPageObject,\n flag: PdfPageFlattenFlag,\n ) => PdfTask<PdfPageFlattenResult>;\n /**\n * Extract pdf pages to a new file\n * @param doc - pdf document\n * @param pageIndexes - indexes of pdf pages\n * @returns task contains the new pdf file content\n */\n extractPages: (doc: PdfDocumentObject, pageIndexes: number[]) => PdfTask<ArrayBuffer>;\n /**\n * Extract text on specified pdf pages\n * @param doc - pdf document\n * @param pageIndexes - indexes of pdf pages\n * @returns task contains the text\n */\n extractText: (doc: PdfDocumentObject, pageIndexes: number[]) => PdfTask<string>;\n /**\n * Get all glyphs in the specified pdf page\n * @param doc - pdf document\n * @param page - pdf page\n * @returns task contains the glyphs\n */\n getPageGlyphs: (doc: PdfDocumentObject, page: PdfPageObject) => PdfTask<PdfGlyphObject[]>;\n /**\n * Get the geometry of the specified pdf page\n * @param doc - pdf document\n * @param page - pdf page\n * @returns task contains the geometry\n */\n getPageGeometry: (doc: PdfDocumentObject, page: PdfPageObject) => PdfTask<PdfPageGeometry>;\n /**\n * Merge multiple pdf documents\n * @param files - all the pdf files\n * @returns task contains the merged pdf file\n */\n merge: (files: PdfFile[]) => PdfTask<PdfFile>;\n /**\n * Merge specific pages from multiple PDF documents in a custom order\n * @param mergeConfigs Array of configurations specifying which pages to merge from which documents\n * @returns A PdfTask that resolves with the merged PDF file\n * @public\n */\n mergePages: (mergeConfigs: Array<{ docId: string; pageIndices: number[] }>) => PdfTask<PdfFile>;\n /**\n * Save a copy of pdf document\n * @param doc - pdf document\n * @returns task contains the new pdf file content\n */\n saveAsCopy: (doc: PdfDocumentObject) => PdfTask<ArrayBuffer>;\n /**\n * Close pdf document\n * @param doc - pdf document\n * @returns task that file is closed or not\n */\n closeDocument: (doc: PdfDocumentObject) => PdfTask<boolean>;\n}\n\n/**\n * Method name of PdfEngine interface\n *\n * @public\n */\nexport type PdfEngineMethodName = keyof Required<PdfEngine>;\n\n/**\n * Arguments of PdfEngine method\n *\n * @public\n */\nexport type PdfEngineMethodArgs<P extends PdfEngineMethodName> = Readonly<\n Parameters<Required<PdfEngine>[P]>\n>;\n\n/**\n * Return type of PdfEngine method\n *\n * @public\n */\nexport type PdfEngineMethodReturnType<P extends PdfEngineMethodName> = ReturnType<\n Required<PdfEngine>[P]\n>;\n","/**\n * Library contains the common definitions of data types and logic\n *\n * @remarks\n * The `@embedpdf/models` defines the interface and classes which are used to\n * handling PDF files.\n *\n * @packageDocumentation\n */\nexport * from './geometry';\nexport * from './logger';\nexport * from './pdf';\nexport * from './task';\n\n/**\n * ignore will do nothing when called.\n *\n * @public\n */\nexport function ignore() {}\n","import { AnnotationState } from './types';\n\nexport const getAnnotationsByPageIndex = (state: AnnotationState, pageIndex: number) => {\n return state.annotations[pageIndex] || [];\n};\n\nexport const getAnnotations = (state: AnnotationState) => {\n return state.annotations;\n};\n\nexport const getSelectedAnnotation = (state: AnnotationState) => {\n return state.selectedAnnotation;\n};\n\nexport const isInAnnotationMode = (state: AnnotationState) => {\n return state.annotationMode !== null;\n};\n\nexport const getSelectedAnnotationMode = (state: AnnotationState) => {\n return state.annotationMode;\n};\n\nexport const isAnnotationSelected = (\n state: AnnotationState,\n pageIndex: number,\n annotationId: number,\n) => {\n const selected = state.selectedAnnotation;\n return selected?.pageIndex === pageIndex && selected?.annotationId === annotationId;\n};\n\nexport const getSelectedAnnotationColor = (state: AnnotationState) => {\n const selected = state.selectedAnnotation;\n if (!selected || !('color' in selected.annotation)) {\n return null;\n }\n return selected.annotation.color;\n};\n","/** @jsxImportSource preact */\nimport { ComponentChildren, Fragment, JSX } from 'preact';\nimport { PdfHighlightAnnoObject } from '@embedpdf/models';\nimport { useCallback } from 'preact/hooks';\nimport { useAnnotationCapability } from '../../hooks';\n\ninterface HighlightAnnotationProps {\n annotation: PdfHighlightAnnoObject;\n scale: number;\n isSelected?: boolean;\n pageIndex: number;\n}\n\nexport function HighlightAnnotation({\n annotation,\n scale,\n isSelected = false,\n pageIndex,\n}: HighlightAnnotationProps) {\n const { provides: annotationProvides } = useAnnotationCapability();\n\n // Default highlight color if none is specified\n const highlightColor = annotation.color || { red: 255, green: 255, blue: 0, alpha: 76 };\n\n // Convert color to CSS rgba format\n const rgbaColor = `rgba(${highlightColor.red}, ${highlightColor.green}, ${highlightColor.blue}, ${highlightColor.alpha / 255})`;\n\n const handleClick = useCallback(\n (e: MouseEvent) => {\n e.stopPropagation();\n if (annotationProvides) {\n annotationProvides.selectAnnotation(pageIndex, annotation.id);\n }\n },\n [annotationProvides, isSelected, pageIndex, annotation.id],\n );\n\n return (\n <>\n <div\n className=\"highlight-annotation\"\n style={{\n position: 'absolute',\n mixBlendMode: 'multiply',\n cursor: 'pointer',\n outline: isSelected ? '2px solid #007ACC' : 'none',\n left: `${annotation.rect.origin.x * scale}px`,\n top: `${annotation.rect.origin.y * scale}px`,\n width: `${annotation.rect.size.width * scale}px`,\n height: `${annotation.rect.size.height * scale}px`,\n }}\n onMouseDown={handleClick}\n >\n {annotation.segmentRects.map((rect, index) => (\n <div\n key={index}\n style={{\n position: 'absolute',\n left: `${(rect.origin.x - annotation.rect.origin.x) * scale}px`,\n top: `${(rect.origin.y - annotation.rect.origin.y) * scale}px`,\n width: `${rect.size.width * scale}px`,\n height: `${rect.size.height * scale}px`,\n backgroundColor: rgbaColor,\n }}\n />\n ))}\n </div>\n </>\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,wBAAwB;AAE1B,IAAM,sBAAsB,MAAM,UAA4B,iBAAiB,EAAE;AACjF,IAAM,0BAA0B,MAAM,cAAg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AAExB,YAAI,GAAG,WAAW,GAAG,iBAAiB,oBAAoB;AACxD,6BAAmB,mBAAmB;AAAA,QACxC;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,kBAAkB;AAAA,EACrB;AAEA,YAAU,MAAM;AACd,WAAO,SAAS,QAAQ;AAAA,EAC1B,GAAG,CAAC,UAAU,QAAQ,CAAC;AAEvB,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEH,sBAAY,IAAI,CAAC,eAAe;AAC/B,cAAM,aACJ,eAAe,sBAAsB,aACrC,eAAe,yBAAyB,WAAW;AAErD,gBAAQ,WAAW,MAAM;AAAA,UACvB,KAAK,qBAAqB;AACxB,mBACE,gBAAAA;AAAA,cAAC;AAAA;AAAA,gBAEC;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA;AAAA,cAJK,WAAW;AAAA,YAKlB;AAAA,UAEJ;AACE,mBAAO;AAAA,QACX;AAAA,MACF,CAAC;AAAA;AAAA,EACH;AAEJ;","names":["PdfAnnotationSubtype","jsx"]}
1
+ {"version":3,"sources":["../../src/preact/hooks/use-annotation.ts","../../src/preact/components/annotations.tsx","../../src/preact/components/selectable-container.tsx","../../src/preact/components/text-markup/highlight.tsx","../../src/preact/components/text-markup/underline.tsx","../../src/preact/components/text-markup/strikeout.tsx","../../src/preact/components/text-markup/squiggly.tsx","../../src/preact/components/text-markup.tsx","../../src/preact/components/annotation-layer.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { AnnotationPlugin } from '@embedpdf/plugin-annotation';\n\nexport const useAnnotationPlugin = () => usePlugin<AnnotationPlugin>(AnnotationPlugin.id);\nexport const useAnnotationCapability = () => useCapability<AnnotationPlugin>(AnnotationPlugin.id);\n","/** @jsxImportSource preact */\nimport { JSX } from 'preact';\nimport { PdfAnnotationObject, PdfAnnotationSubtype } from '@embedpdf/models';\nimport { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\nimport { usePointerHandlers } from '@embedpdf/plugin-interaction-manager/preact';\nimport {\n getAnnotationsByPageIndex,\n getSelectedAnnotationByPageIndex,\n TrackedAnnotation,\n} from '@embedpdf/plugin-annotation';\nimport { useAnnotationCapability } from '../hooks';\nimport { useMemo, useState, useEffect } from 'preact/hooks';\nimport { SelectableAnnotationContainer } from './selectable-container';\nimport { Highlight } from './text-markup/highlight';\nimport { Underline } from './text-markup/underline';\nimport { Strikeout } from './text-markup/strikeout';\nimport { Squiggly } from './text-markup/squiggly';\n\ninterface AnnotationsProps {\n pageIndex: number;\n scale: number;\n}\n\nexport function Annotations({ pageIndex, scale }: AnnotationsProps) {\n const { provides: annotationProvides } = useAnnotationCapability();\n const [annotations, setAnnotations] = useState<TrackedAnnotation[]>([]);\n const { register } = usePointerHandlers({ pageIndex });\n const [selectionState, setSelectionState] = useState<TrackedAnnotation | null>(null);\n\n useEffect(() => {\n if (annotationProvides) {\n annotationProvides.onStateChange((state) => {\n setAnnotations(getAnnotationsByPageIndex(state, pageIndex));\n setSelectionState(getSelectedAnnotationByPageIndex(state, pageIndex));\n });\n }\n }, [annotationProvides]);\n\n const handlers = useMemo(\n (): PointerEventHandlers<MouseEvent> => ({\n onPointerDown: (_, pe) => {\n // Only deselect if clicking directly on the layer (not on an annotation)\n if (pe.target === pe.currentTarget && annotationProvides) {\n annotationProvides.deselectAnnotation();\n }\n },\n }),\n [annotationProvides],\n );\n\n useEffect(() => {\n return register(handlers);\n }, [register, handlers]);\n\n return (\n <>\n {annotations.map((annotation) => {\n const isSelected = selectionState?.localId === annotation.localId;\n\n switch (annotation.object.type) {\n case PdfAnnotationSubtype.UNDERLINE:\n return (\n <SelectableAnnotationContainer\n key={annotation.localId}\n trackedAnnotation={annotation}\n scale={scale}\n isSelected={isSelected}\n pageIndex={pageIndex}\n >\n <Underline\n color={annotation.object.color}\n opacity={annotation.object.opacity}\n rects={annotation.object.segmentRects}\n scale={scale}\n />\n </SelectableAnnotationContainer>\n );\n case PdfAnnotationSubtype.STRIKEOUT:\n return (\n <SelectableAnnotationContainer\n key={annotation.localId}\n trackedAnnotation={annotation}\n scale={scale}\n isSelected={isSelected}\n pageIndex={pageIndex}\n >\n <Strikeout\n color={annotation.object.color}\n opacity={annotation.object.opacity}\n rects={annotation.object.segmentRects}\n scale={scale}\n />\n </SelectableAnnotationContainer>\n );\n case PdfAnnotationSubtype.SQUIGGLY:\n return (\n <SelectableAnnotationContainer\n key={annotation.localId}\n trackedAnnotation={annotation}\n scale={scale}\n isSelected={isSelected}\n pageIndex={pageIndex}\n >\n <Squiggly\n color={annotation.object.color}\n opacity={annotation.object.opacity}\n rects={annotation.object.segmentRects}\n scale={scale}\n />\n </SelectableAnnotationContainer>\n );\n case PdfAnnotationSubtype.HIGHLIGHT:\n return (\n <SelectableAnnotationContainer\n key={annotation.localId}\n trackedAnnotation={annotation}\n scale={scale}\n isSelected={isSelected}\n pageIndex={pageIndex}\n >\n <Highlight\n color={annotation.object.color}\n opacity={annotation.object.opacity}\n rects={annotation.object.segmentRects}\n scale={scale}\n />\n </SelectableAnnotationContainer>\n );\n default:\n return null;\n }\n })}\n </>\n );\n}\n","/** @jsxImportSource preact */\nimport { ComponentChildren } from 'preact';\nimport { useCallback } from 'preact/hooks';\nimport { useAnnotationCapability } from '../hooks';\nimport { useSelectionCapability } from '@embedpdf/plugin-selection/preact';\nimport { TrackedAnnotation } from '@embedpdf/plugin-annotation';\n\ninterface SelectableAnnotationContainerProps {\n trackedAnnotation: TrackedAnnotation;\n scale: number;\n isSelected?: boolean;\n pageIndex: number;\n children: ComponentChildren;\n}\n\nexport function SelectableAnnotationContainer({\n trackedAnnotation,\n scale,\n isSelected = false,\n pageIndex,\n children,\n}: SelectableAnnotationContainerProps) {\n const { provides: annotationProvides } = useAnnotationCapability();\n const { provides: selectionProvides } = useSelectionCapability();\n const handleClick = useCallback(\n (e: MouseEvent) => {\n e.stopPropagation();\n if (annotationProvides && selectionProvides) {\n annotationProvides.selectAnnotation(pageIndex, trackedAnnotation.localId);\n selectionProvides.clear();\n }\n },\n [annotationProvides, selectionProvides, isSelected, pageIndex, trackedAnnotation.localId],\n );\n\n return (\n <>\n {children}\n <div\n className=\"markup-annotation\"\n style={{\n position: 'absolute',\n mixBlendMode: 'multiply',\n cursor: 'pointer',\n outline: isSelected ? '2px solid #007ACC' : 'none',\n outlineOffset: isSelected ? '1px' : '0px',\n left: `${trackedAnnotation.object.rect.origin.x * scale}px`,\n top: `${trackedAnnotation.object.rect.origin.y * scale}px`,\n width: `${trackedAnnotation.object.rect.size.width * scale}px`,\n height: `${trackedAnnotation.object.rect.size.height * scale}px`,\n zIndex: 1,\n }}\n onMouseDown={handleClick}\n />\n </>\n );\n}\n","/** @jsxImportSource preact */\nimport { JSX } from 'preact';\nimport { Rect } from '@embedpdf/models';\n\ninterface HighlightProps {\n color?: string;\n opacity?: number;\n rects: Rect[];\n scale: number;\n}\n\nexport function Highlight({ color = '#FFFF00', opacity = 0.5, rects, scale }: HighlightProps) {\n return (\n <>\n {rects.map((b, i) => (\n <div\n key={i}\n style={{\n position: 'absolute',\n left: b.origin.x * scale,\n top: b.origin.y * scale,\n width: b.size.width * scale,\n height: b.size.height * scale,\n background: color,\n opacity: opacity,\n pointerEvents: 'none',\n }}\n />\n ))}\n </>\n );\n}\n","/** @jsxImportSource preact */\nimport { JSX } from 'preact';\nimport { Rect } from '@embedpdf/models';\n\ninterface UnderlineProps {\n color?: string;\n opacity?: number;\n rects: Rect[];\n scale: number;\n}\n\nexport function Underline({ color = '#FFFF00', opacity = 0.5, rects, scale }: UnderlineProps) {\n const thickness = 2 * scale; // 2 CSS px at 100 % zoom\n\n return (\n <>\n {rects.map((r, i) => (\n <div\n key={i}\n style={{\n position: 'absolute',\n left: r.origin.x * scale,\n top: (r.origin.y + r.size.height) * scale - thickness,\n width: r.size.width * scale,\n height: thickness,\n background: color,\n opacity: opacity,\n pointerEvents: 'none',\n }}\n />\n ))}\n </>\n );\n}\n","/** @jsxImportSource preact */\nimport { JSX } from 'preact';\nimport { Rect } from '@embedpdf/models';\n\ninterface StrikeoutProps {\n color?: string;\n opacity?: number;\n rects: Rect[];\n scale: number;\n}\n\nexport function Strikeout({ color = '#FFFF00', opacity = 0.5, rects, scale }: StrikeoutProps) {\n const thickness = 2 * scale;\n\n return (\n <>\n {rects.map((r, i) => (\n <div\n key={i}\n style={{\n position: 'absolute',\n left: r.origin.x * scale,\n top: (r.origin.y + r.size.height / 2) * scale - thickness / 2,\n width: r.size.width * scale,\n height: thickness,\n background: color,\n opacity: opacity,\n pointerEvents: 'none',\n }}\n />\n ))}\n </>\n );\n}\n","/** @jsxImportSource preact */\nimport { JSX } from 'preact';\nimport { Rect } from '@embedpdf/models';\n\ninterface SquigglyProps {\n color?: string;\n opacity?: number;\n rects: Rect[];\n scale: number;\n}\n\nexport function Squiggly({ color = '#FFFF00', opacity = 0.5, rects, scale }: SquigglyProps) {\n const amplitude = 2 * scale; // wave height\n const period = 6 * scale; // wave length\n\n const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${period}\" height=\"${amplitude * 2}\" viewBox=\"0 0 ${period} ${amplitude * 2}\">\n <path d=\"M0 ${amplitude} Q ${period / 4} 0 ${period / 2} ${amplitude} T ${period} ${amplitude}\"\n fill=\"none\" stroke=\"${color}\" stroke-width=\"${amplitude}\" stroke-linecap=\"round\"/>\n </svg>`;\n\n // Completely escape the SVG markup\n const svgDataUri = `url(\"data:image/svg+xml;utf8,${encodeURIComponent(svg)}\")`;\n\n return (\n <>\n {rects.map((r, i) => (\n <div\n key={i}\n style={{\n position: 'absolute',\n left: r.origin.x * scale,\n top: (r.origin.y + r.size.height) * scale - amplitude,\n width: r.size.width * scale,\n height: amplitude * 2,\n backgroundImage: svgDataUri,\n backgroundRepeat: 'repeat-x',\n backgroundSize: `${period}px ${amplitude * 2}px`,\n opacity: opacity,\n pointerEvents: 'none',\n }}\n />\n ))}\n </>\n );\n}\n","/** @jsxImportSource preact */\nimport { JSX } from 'preact';\nimport { PdfAnnotationSubtype, Rect } from '@embedpdf/models';\nimport { ActiveTool } from '@embedpdf/plugin-annotation';\nimport { useSelectionCapability } from '@embedpdf/plugin-selection/preact';\n\nimport { useEffect, useState } from 'preact/hooks';\nimport { useAnnotationCapability } from '../hooks';\nimport { Highlight } from './text-markup/highlight';\nimport { Squiggly } from './text-markup/squiggly';\nimport { Underline } from './text-markup/underline';\nimport { Strikeout } from './text-markup/strikeout';\n\ninterface TextMarkupProps {\n pageIndex: number;\n scale: number;\n}\n\nexport function TextMarkup({ pageIndex, scale }: TextMarkupProps) {\n const { provides: selectionProvides } = useSelectionCapability();\n const { provides: annotationProvides } = useAnnotationCapability();\n const [rects, setRects] = useState<Array<Rect>>([]);\n const [activeTool, setActiveTool] = useState<ActiveTool>({ mode: null, defaults: null });\n\n useEffect(() => {\n if (!selectionProvides) return;\n\n const off = selectionProvides.onSelectionChange(() => {\n setRects(selectionProvides.getHighlightRectsForPage(pageIndex));\n });\n return off;\n }, [selectionProvides, pageIndex]);\n\n useEffect(() => {\n if (!annotationProvides) return;\n\n const off = annotationProvides.onActiveToolChange(setActiveTool);\n return off;\n }, [annotationProvides]);\n\n switch (activeTool.mode) {\n case PdfAnnotationSubtype.UNDERLINE:\n return (\n <Underline\n color={activeTool.defaults?.color}\n opacity={activeTool.defaults?.opacity}\n rects={rects}\n scale={scale}\n />\n );\n case PdfAnnotationSubtype.HIGHLIGHT:\n return (\n <Highlight\n color={activeTool.defaults?.color}\n opacity={activeTool.defaults?.opacity}\n rects={rects}\n scale={scale}\n />\n );\n case PdfAnnotationSubtype.STRIKEOUT:\n return (\n <Strikeout\n color={activeTool.defaults?.color}\n opacity={activeTool.defaults?.opacity}\n rects={rects}\n scale={scale}\n />\n );\n case PdfAnnotationSubtype.SQUIGGLY:\n return (\n <Squiggly\n color={activeTool.defaults?.color}\n opacity={activeTool.defaults?.opacity}\n rects={rects}\n scale={scale}\n />\n );\n default:\n return null;\n }\n}\n","/** @jsxImportSource preact */\nimport { JSX } from 'preact';\nimport { Annotations } from './annotations';\nimport { TextMarkup } from './text-markup';\n\ntype AnnotationLayerProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, 'style'> & {\n pageIndex: number;\n scale: number;\n style?: JSX.CSSProperties;\n};\n\nexport function AnnotationLayer({ pageIndex, scale, style, ...props }: AnnotationLayerProps) {\n return (\n <div\n style={{\n ...style,\n }}\n {...props}\n >\n <Annotations pageIndex={pageIndex} scale={scale} />\n <TextMarkup pageIndex={pageIndex} scale={scale} />\n </div>\n );\n}\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,wBAAwB;AAE1B,IAAM,sBAAsB,MAAM,UAA4B,iBAAiB,EAAE;AACjF,IAAM,0BAA0B,MAAM,cAAgC,iBAAiB,EAAE;;;ACFhG,SAA8B,4BAA4B;AAE1D,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,SAAS,UAAU,iBAAiB;;;ACT7C,SAAS,mBAAmB;AAE5B,SAAS,8BAA8B;AAgCnC,mBAEE,KAFF;AArBG,SAAS,8BAA8B;AAAA,EAC5C;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AACF,GAAuC;AACrC,QAAM,EAAE,UAAU,mBAAmB,IAAI,wBAAwB;AACjE,QAAM,EAAE,UAAU,kBAAkB,IAAI,uBAAuB;AAC/D,QAAM,cAAc;AAAA,IAClB,CAAC,MAAkB;AACjB,QAAE,gBAAgB;AAClB,UAAI,sBAAsB,mBAAmB;AAC3C,2BAAmB,iBAAiB,WAAW,kBAAkB,OAAO;AACxE,0BAAkB,MAAM;AAAA,MAC1B;AAAA,IACF;AAAA,IACA,CAAC,oBAAoB,mBAAmB,YAAY,WAAW,kBAAkB,OAAO;AAAA,EAC1F;AAEA,SACE,iCACG;AAAA;AAAA,IACD;AAAA,MAAC;AAAA;AAAA,QACC,WAAU;AAAA,QACV,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xB,aACE,gBAAAJ;AAAA,QAAC;AAAA;AAAA,UACC,OAAO,WAAW,UAAU;AAAA,UAC5B,SAAS,WAAW,UAAU;AAAA,UAC9B;AAAA,UACA;AAAA;AAAA,MACF;AAAA,IAEJ,KAAKI,sBAAqB;AACxB,aACE,gBAAAJ;AAAA,QAAC;AAAA;AAAA,UACC,OAAO,WAAW,UAAU;AAAA,UAC5B,SAAS,WAAW,UAAU;AAAA,UAC9B;AAAA,UACA;AAAA;AAAA,MACF;AAAA,IAEJ,KAAKI,sBAAqB;AACxB,aACE,gBAAAJ;AAAA,QAAC;AAAA;AAAA,UACC,OAAO,WAAW,UAAU;AAAA,UAC5B,SAAS,WAAW,UAAU;AAAA,UAC9B;AAAA,UACA;AAAA;AAAA,MACF;AAAA,IAEJ;AACE,aAAO;AAAA,EACX;AACF;;;ACnEI,SAME,OAAAK,MANF,QAAAC,aAAA;AAFG,SAAS,gBAAgB,EAAE,WAAW,OAAO,OAAO,GAAG,MAAM,GAAyB;AAC3F,SACE,gBAAAA;AAAA,IAAC;AAAA;AAAA,MACC,OAAO;AAAA,QACL,GAAG;AAAA,MACL;AAAA,MACC,GAAG;AAAA,MAEJ;AAAA,wBAAAD,KAAC,eAAY,WAAsB,OAAc;AAAA,QACjD,gBAAAA,KAAC,cAAW,WAAsB,OAAc;AAAA;AAAA;AAAA,EAClD;AAEJ;","names":["Fragment","jsx","Fragment","jsx","Fragment","jsx","Fragment","jsx","Fragment","jsx","PdfAnnotationSubtype","useSelectionCapability","useEffect","useState","jsx","useSelectionCapability","useState","useEffect","PdfAnnotationSubtype","jsx","jsxs"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-annotation",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -17,20 +17,24 @@
17
17
  "require": "./dist/preact/index.cjs"
18
18
  }
19
19
  },
20
- "dependencies": {},
20
+ "dependencies": {
21
+ "@embedpdf/models": "1.0.7"
22
+ },
21
23
  "devDependencies": {
22
24
  "@types/react": "^18.2.0",
23
25
  "tsup": "^8.0.0",
24
26
  "typescript": "^5.0.0",
25
- "@embedpdf/models": "1.0.5",
26
- "@embedpdf/plugin-interaction-manager": "1.0.5"
27
+ "@embedpdf/plugin-interaction-manager": "1.0.7",
28
+ "@embedpdf/plugin-selection": "1.0.7",
29
+ "@embedpdf/plugin-history": "1.0.7"
27
30
  },
28
31
  "peerDependencies": {
29
32
  "react": ">=16.8.0",
30
33
  "react-dom": ">=16.8.0",
31
34
  "preact": "^10.26.4",
32
- "@embedpdf/core": "1.0.5",
33
- "@embedpdf/plugin-interaction-manager": "1.0.5"
35
+ "@embedpdf/plugin-interaction-manager": "1.0.7",
36
+ "@embedpdf/core": "1.0.7",
37
+ "@embedpdf/plugin-selection": "1.0.7"
34
38
  },
35
39
  "files": [
36
40
  "dist",