index.d.ts 2.2 KB

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