Types
The reference and the examples name types such as ExportedImage or ToolId. This page shows what each one holds, so you can type your own code. Each type links to the page that explains it.
Import the types from the package you installed. @paperpic/vue and @paperpic/react export every type of @paperpic/core, so you do not need to install it:
import type { ExportedImage, PaperPicState, ToolId } from '@paperpic/core'In a Nuxt app, import them from @paperpic/nuxt, which exports every type of @paperpic/vue.
Options
PaperPicOptions
interface PaperPicOptions {
alt?: string
aspectRatio?: number
download?: boolean
editable?: boolean
filename?: string
icons?: Partial<PaperPicIcons>
labels?: Partial<PaperPicLabels>
maxOutputSize?: number
output?: PaperPicOutput
softness?: number
src?: PaperPicSource
toolbar?: boolean
tools?: readonly ToolId[]
wheelZoom?: boolean
}What the constructor and setOptions() take. In Vue and React, these are the props of the component. Options explains each one.
PaperPicSource
type PaperPicSource = string | BlobThe image in src: a URL, or a File or a Blob. The source of PaperPicDownload has the same type.
PaperPicOutput
interface PaperPicOutput {
quality?: number
type?: string
}The format of the edited image, in output.
ToolId
type ToolId = 'adjust' | 'crop' | 'finish' | 'flip' | 'perspective' | 'redact' | 'rotate'A tool of the edit bar, in tools, openTool() and the activeTool of the state. tools gives the button of each one.
PaperPicLabels
interface PaperPicLabels {
adjust: string
adjustmentLevel: (name: string, value: number) => string
adjustUnavailable: string
applied: string
apply: string
applyError: string
brightness: string
cancel: string
cancelTool: string
confirm: string
contrast: string
cornerBottomLeft: string
cornerBottomRight: string
cornerKeys: string
cornerMoved: (corner: string, x: number, y: number) => string
cornerSelected: (corner: string) => string
cornerTopLeft: string
cornerTopRight: string
crop: string
cropHint: string
discard: string
discardQuestion: string
download: string
edit: string
editBar: string
editing: string
finish: string
finishGray: string
finishLevel: (percent: number) => string
finishMono: string
finishOriginal: string
finishSensitivity: string
fitHeight: string
fitWidth: string
flip: string
inUse: string
keepEditing: string
loadError: string
loading: string
paper: string
paperA4: string
paperAuto: string
paperCard: string
paperLetter: string
perspective: string
perspectiveFound: string
perspectiveHint: string
previewError: string
processing: string
redact: string
redactAngle: (degrees: number) => string
redactArea: string
redactBlack: string
redactHint: string
redactTurn: string
redactTurnKeys: string
redactWhite: string
redo: string
rotateLeft: string
rotateRight: string
toolbar: string
undo: string
viewer: string
zoomIn: string
zoomLevel: (percent: number) => string
zoomOut: string
}Every text of the interface, in labels. The texts that include a value, such as the zoom level, are functions. Labels gives the English text of each one.
PaperPicIcons
interface PaperPicIcons {
adjust: string
apply: string
brightness: string
cancel: string
contrast: string
crop: string
download: string
edit: string
finish: string
fitHeight: string
fitWidth: string
flip: string
perspective: string
redact: string
redo: string
rotateDocument: string
rotateLeft: string
rotateRight: string
undo: string
zoomIn: string
zoomOut: string
}Every icon of the interface, as the markup of one element, in icons, which gives the buttons of each one.
State
PaperPicState
interface PaperPicState {
activeTool: ToolId | null
adjustments: { brightness: number, contrast: number }
busy: boolean
canApply: boolean
canConfirm: boolean
canRedo: boolean
canUndo: boolean
finish: { mode: FinishMode, sensitivity: number }
fit: Fit | null
hint: string | null
image: Size | null
mode: 'view' | 'edit'
paper: { size: PaperSize }
redaction: { color: RedactColor }
rotation: Rotation
status: 'empty' | 'loading' | 'ready' | 'error'
zoom: number
}What getState() returns and the change event carries. State explains each field.
FinishMode
type FinishMode = 'original' | 'gray' | 'mono'The finish of Clean up: the original tones, gray, or black and white with 'mono'. setFinish() takes it, and the finish of the state holds it.
PaperSize
type PaperSize = 'auto' | 'a4' | 'letter' | 'card'The paper that gives its proportions to the result of Straighten. setPaper() takes it, and the paper of the state holds it.
RedactColor
type RedactColor = 'black' | 'white'The color that Redact covers with. setRedaction() takes it, and the redaction of the state holds it.
Fit
type Fit = 'image' | 'width' | 'height'How the image fits the viewer: whole, by its width or by its height. fit() takes it, and the fit of the state holds it.
Rotation
type Rotation = 0 | 90 | 180 | 270How far the image on display is turned, in degrees clockwise, in the rotation of the state.
Size
interface Size {
height: number
width: number
}A width and a height in pixels, such as the image of the state or what the load event carries.
Events
PaperPicEvents
interface PaperPicEvents {
apply: ExportedImage
change: PaperPicState
download: PaperPicDownload
error: { error: Error, phase: 'load' | 'preview' | 'apply' }
load: Size
}Each event with what it carries, for on(). Events explains each one.
ExportedImage
interface ExportedImage {
blob: Blob
height: number
type: string
width: number
}The edited image, which the apply event carries. type is the format of blob, which output chooses.
PaperPicDownload
interface PaperPicDownload {
filename: string
preventDefault: () => void
source: PaperPicSource
}What the download event carries. Call preventDefault() to save the file another way.
Methods
ViewPoint
interface ViewPoint {
x: number
y: number
}A point in CSS pixels from the top left corner of the viewer, for zoomTo().
Vue and React
@paperpic/vue and @paperpic/react also export the types of their component, and @paperpic/nuxt exports the same ones as @paperpic/vue. Vue and React show how to use it.
PaperPicInstance
type PaperPicInstance = PaperPicThe viewer that the component gives you: instance in Vue, and what ref receives in React. It is the class PaperPic of @paperpic/core, with every method.
PaperPicProps
interface PaperPicProps extends PaperPicOptions {
className?: string
onApply?: (result: PaperPicEvents['apply']) => void
onChange?: (state: PaperPicEvents['change']) => void
onDownload?: (download: PaperPicEvents['download']) => void
onError?: (failure: PaperPicEvents['error']) => void
onLoad?: (size: PaperPicEvents['load']) => void
ref?: Ref<PaperPicInstance>
style?: CSSProperties
}The props of the component in React: the options, plus the classes and styles of its element, a callback for each event, and ref. In Vue, the props have the same fields as PaperPicOptions, and the events are component events.