index.d.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { metas as fMetas } from './shape'
  2. import type { BoardData, BoardShapeData } from 'api'
  3. import type { Emitter } from 'mitt'
  4. import {
  5. brokenLine,
  6. text,
  7. table,
  8. rect,
  9. circular,
  10. arrow,
  11. icon,
  12. cigarette,
  13. fireoint,
  14. footPrint,
  15. shoePrint,
  16. fingerPrint,
  17. corpse,
  18. theBlood,
  19. compass,
  20. title,
  21. bgImage
  22. } from './shape'
  23. type Metas = typeof fMetas
  24. export type ShapeType = brokenLine | text | table | rect | circular | arrow | icon | cigarette |
  25. fireoint | footPrint | shoePrint | fingerPrint | corpse | theBlood | compass | title | bgImage
  26. export type MetaShapeType = keyof Metas
  27. export interface Pos {
  28. x: number
  29. y: number
  30. }
  31. // 形状通用对象
  32. export type BoardShape<T = BoardShapeData, K = keyof T> = IntersectionFromUnion<
  33. K extends 'type'
  34. ? { data: { [key in K]: T[K]} }
  35. : { data: { [key in K]: T[K] } } & { [key in `set${Capitalize<K>}`]: (val: T[K]) => void }
  36. > & { delete: () => void }
  37. export type ExtractShape<T extends string, D = BoardShapeData> = BoardShape<
  38. D extends object
  39. ? T extends keyof D ? D : never
  40. : never
  41. >
  42. export type Board = {
  43. el: HTMLCanvasElement
  44. bus: Emitter<{
  45. storeChange: undefined
  46. selectShape: BoardShape | null
  47. backDisabled: boolean
  48. forwardDisabled: boolean
  49. }>
  50. unSelectShape(): void,
  51. readyAddShape(type: ShapeType, onFinish?: () => void): () => void
  52. back(): void
  53. forward(): void
  54. setImage(url: string): void
  55. getCurrentStore(): BoardData
  56. drawStore(store: BoardData): void
  57. getStore(): BoardData
  58. export(): Promise<Blob>
  59. destroy(): void
  60. }
  61. function create (store: BoardData, canvas: HTMLCanvasElement): Board
  62. export { BoardShapeData }
  63. export const metas: Metas
  64. export const images: ShapeType[]
  65. export const labels: ShapeType[]
  66. export {
  67. brokenLine,
  68. text,
  69. table,
  70. rect,
  71. circular,
  72. arrow,
  73. icon,
  74. cigarette,
  75. fireoint,
  76. footPrint,
  77. shoePrint,
  78. fingerPrint,
  79. corpse,
  80. theBlood,
  81. compass,
  82. title,
  83. bgImage
  84. } from './shape'
  85. export default create