型
リファレンスと例には ExportedImage や ToolId などの型が登場します。このページでは各型の中身を示すので、自分のコードに型を付けられます。各型から、それを説明するページにリンクしています。
型はインストールしたパッケージからインポートします。@paperpic/vue と @paperpic/react は @paperpic/core のすべての型をエクスポートしているため、@paperpic/core をインストールする必要はありません。
import type { ExportedImage, PaperPicState, ToolId } from '@paperpic/core'Nuxt のアプリでは、@paperpic/vue のすべての型をエクスポートしている @paperpic/nuxt からインポートします。
オプション
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
}コンストラクターと setOptions() が受け取るもの。Vue と React ではコンポーネントの props です。各項目はオプションで説明しています。
PaperPicSource
type PaperPicSource = string | Blobsrc の画像。URL か、File または Blob です。PaperPicDownload の source も同じ型です。
PaperPicOutput
interface PaperPicOutput {
quality?: number
type?: string
}output で指定する、編集後の画像の形式。
ToolId
type ToolId = 'adjust' | 'crop' | 'finish' | 'flip' | 'perspective' | 'redact' | 'rotate'編集バーのツール。tools、openTool()、状態の activeTool で使います。各ツールのボタンは tools にあります。
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
}labels で指定する、インターフェースのすべてのテキスト。ズーム倍率のように値を含むテキストは関数です。各テキストの英語の文言はラベルにあります。
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
}インターフェースのすべてのアイコンを、1 つの要素のマークアップとして icons で指定します。各アイコンを使うボタンもそこにあります。
状態
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
}getState() が返し、change イベントが渡すもの。各フィールドは状態で説明しています。
FinishMode
type FinishMode = 'original' | 'gray' | 'mono'クリーンアップの仕上げ。元の色調、グレー、または 'mono' の白黒です。setFinish() が受け取り、状態の finish が保持します。
PaperSize
type PaperSize = 'auto' | 'a4' | 'letter' | 'card'傾き補正の結果に縦横比を与える用紙。setPaper() が受け取り、状態の paper が保持します。
RedactColor
type RedactColor = 'black' | 'white'塗りつぶしで覆う色。setRedaction() が受け取り、状態の redaction が保持します。
Fit
type Fit = 'image' | 'width' | 'height'画像をビューアーに合わせる方法。全体、幅、高さのいずれかです。fit() が受け取り、状態の fit が保持します。
Rotation
type Rotation = 0 | 90 | 180 | 270表示中の画像の回転角度。時計回りの度数で、状態の rotation にあります。
Size
interface Size {
height: number
width: number
}ピクセル単位の幅と高さ。状態の image や、load イベントが渡すものなどで使います。
イベント
PaperPicEvents
interface PaperPicEvents {
apply: ExportedImage
change: PaperPicState
download: PaperPicDownload
error: { error: Error, phase: 'load' | 'preview' | 'apply' }
load: Size
}on() で使う、各イベントとそれが渡すもの。各イベントはイベントで説明しています。
ExportedImage
interface ExportedImage {
blob: Blob
height: number
type: string
width: number
}apply イベントが渡す、編集後の画像。type は blob の形式で、output で選べます。
PaperPicDownload
interface PaperPicDownload {
filename: string
preventDefault: () => void
source: PaperPicSource
}download イベントが渡すもの。別の方法でファイルを保存するには preventDefault() を呼び出します。
メソッド
ViewPoint
interface ViewPoint {
x: number
y: number
}ビューアーの左上隅からの CSS ピクセル単位の位置。zoomTo() で使います。
Vue と React
@paperpic/vue と @paperpic/react は、コンポーネントの型もエクスポートしています。@paperpic/nuxt も、@paperpic/vue と同じ型をエクスポートしています。使い方は Vue と React を参照してください。
PaperPicInstance
type PaperPicInstance = PaperPicコンポーネントが渡すビューアー。Vue では instance、React では ref が受け取るものです。@paperpic/core のクラス PaperPic で、すべてのメソッドを持ちます。
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
}React でのコンポーネントの props。オプションに加えて、要素のクラスとスタイル、各イベントのコールバック、ref を持ちます。Vue では、props は PaperPicOptions と同じフィールドを持ち、イベントはコンポーネントのイベントです。