index.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. initHistory(): void;
  60. setDefaultTable(bottomData: TableShapeData['content'] | null, topData: setDefaultTable['content'] | null)
  61. export(): Promise<Blob>
  62. destroy(): void
  63. }
  64. function create (store: BoardData, canvas: HTMLCanvasElement): Board
  65. export { BoardShapeData }
  66. export const metas: Metas
  67. export const images: MetaShapeType[]
  68. export const labels: MetaShapeType[]
  69. export {
  70. brokenLine,
  71. text,
  72. table,
  73. rect,
  74. circular,
  75. arrow,
  76. icon,
  77. cigarette,
  78. fireoint,
  79. footPrint,
  80. shoePrint,
  81. fingerPrint,
  82. corpse,
  83. theBlood,
  84. compass,
  85. title,
  86. bgImage
  87. } from './shape'
  88. export default create