Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
  2. import React from 'react'
  3. /* -------------------------------------------------- */
  4. /* Client State */
  5. /* -------------------------------------------------- */
  6. export interface Data {
  7. isReadOnly: boolean
  8. settings: {
  9. fontSize: number
  10. isDarkMode: boolean
  11. isCodeOpen: boolean
  12. isStyleOpen: boolean
  13. nudgeDistanceSmall: number
  14. nudgeDistanceLarge: number
  15. isToolLocked: boolean
  16. isPenLocked: boolean
  17. }
  18. currentStyle: ShapeStyles
  19. camera: {
  20. point: number[]
  21. zoom: number
  22. }
  23. brush?: Bounds
  24. boundsRotation: number
  25. selectedIds: Set<string>
  26. pointedId?: string
  27. hoveredId?: string
  28. currentPageId: string
  29. currentCodeFileId: string
  30. codeControls: Record<string, CodeControl>
  31. document: {
  32. pages: Record<string, Page>
  33. code: Record<string, CodeFile>
  34. }
  35. }
  36. /* -------------------------------------------------- */
  37. /* Document */
  38. /* -------------------------------------------------- */
  39. export interface Page {
  40. id: string
  41. type: 'page'
  42. childIndex: number
  43. name: string
  44. shapes: Record<string, Shape>
  45. }
  46. export enum ShapeType {
  47. Dot = 'dot',
  48. Circle = 'circle',
  49. Ellipse = 'ellipse',
  50. Line = 'line',
  51. Ray = 'ray',
  52. Polyline = 'polyline',
  53. Rectangle = 'rectangle',
  54. Draw = 'draw',
  55. }
  56. // Consider:
  57. // Glob = "glob",
  58. // Spline = "spline",
  59. // Cubic = "cubic",
  60. // Conic = "conic",
  61. export type ShapeStyles = Partial<React.SVGProps<SVGUseElement>>
  62. export interface BaseShape {
  63. id: string
  64. type: ShapeType
  65. parentId: string
  66. childIndex: number
  67. isGenerated: boolean
  68. name: string
  69. point: number[]
  70. rotation: number
  71. style: ShapeStyles
  72. isLocked: boolean
  73. isHidden: boolean
  74. isAspectRatioLocked: boolean
  75. }
  76. export interface DotShape extends BaseShape {
  77. type: ShapeType.Dot
  78. }
  79. export interface CircleShape extends BaseShape {
  80. type: ShapeType.Circle
  81. radius: number
  82. }
  83. export interface EllipseShape extends BaseShape {
  84. type: ShapeType.Ellipse
  85. radiusX: number
  86. radiusY: number
  87. }
  88. export interface LineShape extends BaseShape {
  89. type: ShapeType.Line
  90. direction: number[]
  91. }
  92. export interface RayShape extends BaseShape {
  93. type: ShapeType.Ray
  94. direction: number[]
  95. }
  96. export interface PolylineShape extends BaseShape {
  97. type: ShapeType.Polyline
  98. points: number[][]
  99. }
  100. export interface RectangleShape extends BaseShape {
  101. type: ShapeType.Rectangle
  102. size: number[]
  103. radius: number
  104. }
  105. export interface DrawShape extends BaseShape {
  106. type: ShapeType.Draw
  107. points: number[][]
  108. }
  109. export type MutableShape =
  110. | DotShape
  111. | CircleShape
  112. | EllipseShape
  113. | LineShape
  114. | RayShape
  115. | PolylineShape
  116. | DrawShape
  117. | RectangleShape
  118. export type Shape = Readonly<MutableShape>
  119. export interface Shapes {
  120. [ShapeType.Dot]: Readonly<DotShape>
  121. [ShapeType.Circle]: Readonly<CircleShape>
  122. [ShapeType.Ellipse]: Readonly<EllipseShape>
  123. [ShapeType.Line]: Readonly<LineShape>
  124. [ShapeType.Ray]: Readonly<RayShape>
  125. [ShapeType.Polyline]: Readonly<PolylineShape>
  126. [ShapeType.Draw]: Readonly<DrawShape>
  127. [ShapeType.Rectangle]: Readonly<RectangleShape>
  128. }
  129. export type ShapeByType<T extends ShapeType> = Shapes[T]
  130. export interface CodeFile {
  131. id: string
  132. name: string
  133. code: string
  134. }
  135. /* -------------------------------------------------- */
  136. /* Editor UI */
  137. /* -------------------------------------------------- */
  138. export interface PointerInfo {
  139. target: string
  140. pointerId: number
  141. origin: number[]
  142. point: number[]
  143. shiftKey: boolean
  144. ctrlKey: boolean
  145. metaKey: boolean
  146. altKey: boolean
  147. }
  148. export enum Edge {
  149. Top = 'top_edge',
  150. Right = 'right_edge',
  151. Bottom = 'bottom_edge',
  152. Left = 'left_edge',
  153. }
  154. export enum Corner {
  155. TopLeft = 'top_left_corner',
  156. TopRight = 'top_right_corner',
  157. BottomRight = 'bottom_right_corner',
  158. BottomLeft = 'bottom_left_corner',
  159. }
  160. export interface Bounds {
  161. minX: number
  162. minY: number
  163. maxX: number
  164. maxY: number
  165. width: number
  166. height: number
  167. }
  168. export interface RotatedBounds extends Bounds {
  169. rotation: number
  170. }
  171. export interface ShapeBounds extends Bounds {
  172. id: string
  173. }
  174. export interface PointSnapshot extends Bounds {
  175. nx: number
  176. nmx: number
  177. ny: number
  178. nmy: number
  179. }
  180. export interface BoundsSnapshot extends PointSnapshot {
  181. nw: number
  182. nh: number
  183. }
  184. export type Difference<A, B> = A extends B ? never : A
  185. export type ShapeSpecificProps<T extends Shape> = Pick<
  186. T,
  187. Difference<keyof T, keyof BaseShape>
  188. >
  189. export type ShapeIndicatorProps<T extends Shape> = ShapeSpecificProps<T>
  190. export type ShapeUtil<K extends Shape> = {
  191. create(props: Partial<K>): K
  192. getBounds(shape: K): Bounds
  193. hitTest(shape: K, test: number[]): boolean
  194. hitTestBounds(shape: K, bounds: Bounds): boolean
  195. rotate(shape: K): K
  196. translate(shape: K, delta: number[]): K
  197. scale(shape: K, scale: number): K
  198. stretch(shape: K, scaleX: number, scaleY: number): K
  199. render(shape: K): JSX.Element
  200. }
  201. export enum MoveType {
  202. Backward,
  203. Forward,
  204. ToFront,
  205. ToBack,
  206. }
  207. export enum AlignType {
  208. Top,
  209. CenterVertical,
  210. Bottom,
  211. Left,
  212. CenterHorizontal,
  213. Right,
  214. }
  215. export enum StretchType {
  216. Horizontal,
  217. Vertical,
  218. }
  219. export enum DistributeType {
  220. Horizontal,
  221. Vertical,
  222. }
  223. /* -------------------------------------------------- */
  224. /* Code Editor */
  225. /* -------------------------------------------------- */
  226. export type IMonaco = typeof monaco
  227. export type IMonacoEditor = monaco.editor.IStandaloneCodeEditor
  228. export enum ControlType {
  229. Number = 'number',
  230. Vector = 'vector',
  231. Text = 'text',
  232. Select = 'select',
  233. }
  234. export interface BaseCodeControl {
  235. id: string
  236. type: ControlType
  237. label: string
  238. }
  239. export interface NumberCodeControl extends BaseCodeControl {
  240. type: ControlType.Number
  241. min?: number
  242. max?: number
  243. value: number
  244. step: number
  245. format?: (value: number) => number
  246. }
  247. export interface VectorCodeControl extends BaseCodeControl {
  248. type: ControlType.Vector
  249. value: number[]
  250. isNormalized: boolean
  251. format?: (value: number[]) => number[]
  252. }
  253. export interface TextCodeControl extends BaseCodeControl {
  254. type: ControlType.Text
  255. value: string
  256. format?: (value: string) => string
  257. }
  258. export interface SelectCodeControl<T extends string = ''>
  259. extends BaseCodeControl {
  260. type: ControlType.Select
  261. value: T
  262. options: T[]
  263. format?: (string: T) => string
  264. }
  265. export type CodeControl =
  266. | NumberCodeControl
  267. | VectorCodeControl
  268. | TextCodeControl
  269. | SelectCodeControl
  270. export type PropsOfType<T extends object, K> = {
  271. [K in keyof T]: T[K] extends boolean ? K : never
  272. }[keyof T]