index.d.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { metas as fMetas } from './shape'
  2. import type { BoardData, BoardShapeData } from 'store'
  3. import type { Emitter } from 'mitt'
  4. type Metas = typeof fMetas
  5. export type ShapeType = keyof Metas
  6. export interface Pos {
  7. x: number
  8. y: number
  9. }
  10. // 形状通用对象
  11. export type BoardShape<T = BoardShapeData, K = keyof T> = IntersectionFromUnion<
  12. K extends 'type'
  13. ? { data: { [key in K]: T[K]} }
  14. : { data: { [key in K]: T[K] } } & { [key in `set${Capitalize<K>}`]: (val: T[K]) => void }
  15. >
  16. export type ExtractShape<T extends string, D = BoardShapeData> = BoardShape<
  17. D extends object
  18. ? T extends keyof D ? D : never
  19. : never
  20. >
  21. export type Board = {
  22. el: HTMLCanvasElement
  23. bus: Emitter<{
  24. storeChange: undefined
  25. selectShape: BoardShape | null
  26. }>
  27. setImage(url: string): void
  28. readyAddShape(type: ShapeType, onFinish?: () => void): () => void
  29. getCurrentStore(): BoardData
  30. drawStore(store: BoardData): void
  31. export(): Promise<Blob>
  32. destroy(): void
  33. }
  34. function create (store: BoardData, canvas: HTMLCanvasElement): Board
  35. export { BoardShapeData }
  36. export const metas: Metas
  37. export const images: ShapeType[]
  38. export const labels: ShapeType[]
  39. export {
  40. brokenLine,
  41. text,
  42. table,
  43. rect,
  44. circular,
  45. arrow,
  46. icon,
  47. cigarette,
  48. fireoint,
  49. footPrint,
  50. shoePrint,
  51. fingerPrint,
  52. corpse,
  53. theBlood,
  54. } from './shape'
  55. export default create