본문으로 건너뛰기

타입 ​

레퍼런스와 예제에는 ExportedImage나 ToolId 같은 타입이 나옵니다. 이 페이지는 각 타입에 무엇이 들어 있는지 보여 주므로, 직접 작성하는 코드에 타입을 지정할 수 있습니다. 각 타입은 그것을 설명하는 페이지로 연결됩니다.

타입은 설치한 패키지에서 가져옵니다. @paperpic/vue와 @paperpic/react는 @paperpic/core의 모든 타입을 내보내므로 @paperpic/core를 설치할 필요가 없습니다.

ts
import type { ExportedImage, PaperPicState, ToolId } from '@paperpic/core'

Nuxt 앱에서는 @paperpic/vue의 모든 타입을 내보내는 @paperpic/nuxt에서 가져옵니다.

옵션 ​

PaperPicOptions ​

ts
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 ​

ts
type PaperPicSource = string | Blob

src의 이미지입니다. URL이거나 File 또는 Blob입니다. PaperPicDownload의 source도 같은 타입입니다.

PaperPicOutput ​

ts
interface PaperPicOutput {
  quality?: number
  type?: string
}

output에서 지정하는 편집된 이미지의 형식입니다.

ToolId ​

ts
type ToolId = 'adjust' | 'crop' | 'finish' | 'flip' | 'perspective' | 'redact' | 'rotate'

편집 바의 도구입니다. tools, openTool(), 상태의 activeTool에서 쓰입니다. 각 도구의 버튼은 tools에 나와 있습니다.

PaperPicLabels ​

ts
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 ​

ts
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
}

인터페이스의 모든 아이콘을 요소 하나의 마크업으로 icons에서 지정합니다. 각 아이콘을 쓰는 버튼도 그곳에 나와 있습니다.

상태 ​

PaperPicState ​

ts
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 ​

ts
type FinishMode = 'original' | 'gray' | 'mono'

정리의 마무리입니다. 원래 색조, 회색, 또는 'mono'의 흑백 중 하나입니다. setFinish()가 받고, 상태의 finish에 담깁니다.

PaperSize ​

ts
type PaperSize = 'auto' | 'a4' | 'letter' | 'card'

기울기 보정의 결과에 비율을 주는 용지입니다. setPaper()가 받고, 상태의 paper에 담깁니다.

RedactColor ​

ts
type RedactColor = 'black' | 'white'

가리기가 덮는 색입니다. setRedaction()이 받고, 상태의 redaction에 담깁니다.

Fit ​

ts
type Fit = 'image' | 'width' | 'height'

이미지를 뷰어에 맞추는 방식입니다. 전체, 너비, 높이 중 하나입니다. fit()이 받고, 상태의 fit에 담깁니다.

Rotation ​

ts
type Rotation = 0 | 90 | 180 | 270

표시된 이미지가 시계 방향으로 회전한 각도이며, 상태의 rotation에 담깁니다.

Size ​

ts
interface Size {
  height: number
  width: number
}

픽셀 단위의 너비와 높이입니다. 상태의 image나 load 이벤트가 전달하는 값 등에서 쓰입니다.

이벤트 ​

PaperPicEvents ​

ts
interface PaperPicEvents {
  apply: ExportedImage
  change: PaperPicState
  download: PaperPicDownload
  error: { error: Error, phase: 'load' | 'preview' | 'apply' }
  load: Size
}

on()에서 쓰는 각 이벤트와 그 이벤트가 전달하는 값입니다. 각 이벤트는 이벤트에서 설명합니다.

ExportedImage ​

ts
interface ExportedImage {
  blob: Blob
  height: number
  type: string
  width: number
}

apply 이벤트가 전달하는 편집된 이미지입니다. type은 blob의 형식이며, output에서 고릅니다.

PaperPicDownload ​

ts
interface PaperPicDownload {
  filename: string
  preventDefault: () => void
  source: PaperPicSource
}

download 이벤트가 전달하는 값입니다. 다른 방식으로 파일을 저장하려면 preventDefault()를 호출하세요.

메서드 ​

ViewPoint ​

ts
interface ViewPoint {
  x: number
  y: number
}

뷰어의 왼쪽 위 모서리에서 잰 CSS 픽셀 단위의 위치이며, zoomTo()에서 쓰입니다.

Vue와 React ​

@paperpic/vue와 @paperpic/react는 컴포넌트의 타입도 내보내고, @paperpic/nuxt는 @paperpic/vue와 같은 타입을 내보냅니다. 사용 방법은 Vue와 React를 참고하세요.

PaperPicInstance ​

ts
type PaperPicInstance = PaperPic

컴포넌트가 제공하는 뷰어입니다. Vue에서는 instance, React에서는 ref가 받는 값입니다. @paperpic/core의 클래스 PaperPic이며, 모든 메서드를 가집니다.

PaperPicProps ​

ts
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와 같은 필드를 가지며, 이벤트는 컴포넌트 이벤트입니다.

MIT 라이선스로 배포됩니다.