elements.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import {ImageHit} from "@/api/static/types"
  2. import {XY} from "fabric"
  3. import {ImageElement} from "./canvas"
  4. export const enum ElementNames {
  5. TEXTBOX = 'textbox',
  6. TEXT = 'text',
  7. ITEXT = 'i-text',
  8. INPUTTEXT = 'itext',
  9. ARCTEXT = 'arctext',
  10. VERTICALTEXT = 'verticaltext',
  11. IMAGE = 'image',
  12. SVGIMAGE = 'svgimage',
  13. CROPIMAGE = 'cropimage',
  14. MASK = 'mask',
  15. PATH = 'path',
  16. RECT = 'rect',
  17. LINE = 'line',
  18. ARROW = 'arrow',
  19. POLYLINE = 'polyline',
  20. ELLIPSE = 'ellipse',
  21. QRCODE = 'qrcode',
  22. BARCODE = 'barcode',
  23. GROUP = 'group',
  24. ACTIVE = 'activeselection',
  25. CIRCLE = 'circle',
  26. REFERENCELINE = 'referenceline',
  27. DOT = 'dot',
  28. }
  29. export const SupportEffects = [
  30. 'group',
  31. 'activeselection',
  32. 'itext',
  33. 'text',
  34. 'textbox',
  35. 'image',
  36. ]
  37. export interface ColorStop {
  38. color: string
  39. offset: number
  40. opacity?: number
  41. }
  42. /**
  43. * 形状渐变
  44. *
  45. * type: 渐变类型(径向、线性)
  46. *
  47. * color: 渐变颜色
  48. *
  49. * rotate: 渐变角度(线性渐变)
  50. */
  51. export interface PathGradient {
  52. type: 'linear' | 'radial'
  53. name: string
  54. color: string[]
  55. rotate: number
  56. }
  57. export type LinePoint = '' | 'arrow' | 'dot'
  58. export interface Mask extends ImageElement {
  59. src: string
  60. defaultColor: number
  61. }
  62. export interface LinePoolItem {
  63. path: string
  64. style: 'solid' | 'dashed'
  65. points: [LinePoint, LinePoint]
  66. data: XY[]
  67. isBroken?: boolean
  68. isCurve?: boolean
  69. isCubic?: boolean
  70. }
  71. export const enum ShapePathFormulasKeys {
  72. ROUND_RECT = 'roundRect',
  73. ROUND_RECT_DIAGONAL = 'roundRectDiagonal',
  74. ROUND_RECT_SINGLE = 'roundRectSingle',
  75. ROUND_RECT_SAMESIDE = 'roundRectSameSide',
  76. CUT_RECT_DIAGONAL = 'cutRectDiagonal',
  77. CUT_RECT_SINGLE = 'cutRectSingle',
  78. CUT_RECT_SAMESIDE = 'cutRectSameSide',
  79. MESSAGE = 'message',
  80. ROUND_MESSAGE = 'roundMessage',
  81. L = 'L',
  82. RING_RECT = 'ringRect',
  83. PLUS = 'plus',
  84. TRIANGLE = 'triangle',
  85. PARALLELOGRAM_LEFT = 'parallelogramLeft',
  86. PARALLELOGRAM_RIGHT = 'parallelogramRight',
  87. TRAPEZOID = 'trapezoid',
  88. BULLET = 'bullet',
  89. INDICATOR = 'indicator',
  90. }
  91. export interface PathPoolItem {
  92. viewBox: [number, number]
  93. path: string
  94. special?: boolean
  95. pathFormula?: ShapePathFormulasKeys
  96. outlined?: boolean
  97. }
  98. export interface PathListItem {
  99. type: string
  100. children: PathPoolItem[]
  101. }
  102. export interface verticalLine {
  103. x: number
  104. y1: number
  105. y2: number
  106. }
  107. export interface horizontalLine {
  108. y: number
  109. x1: number
  110. x2: number
  111. }
  112. // 边框矩形
  113. export interface StrokeRect {
  114. x: number,
  115. y: number,
  116. w: number,
  117. h: number
  118. }
  119. export interface AngleRect {
  120. x: number
  121. y: number
  122. w: number
  123. h: number
  124. }
  125. export interface ElementStrokeRect {
  126. id: string
  127. strokeRect: StrokeRect
  128. }
  129. // 渐变背景填充坐标
  130. export interface GradientCoords {
  131. x1: number
  132. y1: number
  133. x2: number
  134. y2: number,
  135. r1?: number,
  136. r2?: number
  137. }
  138. export interface PointElement {
  139. x: number,
  140. y: number
  141. }
  142. export const enum RightStates {
  143. ELEMENT_CANVAS = 'design',
  144. ELEMENT_TEXT = 'text',
  145. ELEMENT_SVG = 'path',
  146. ELEMENT_IMAGE = 'image',
  147. ELEMENT_CODE = 'code',
  148. ELEMENT_STYLE = 'style',
  149. ELEMENT_POSITION = 'position',
  150. ELEMENT_LAYER = 'layer',
  151. ELEMENT_EFFECT = 'effect',
  152. }
  153. // 底纹背景元素
  154. export interface ShadingColorLib {
  155. title: string
  156. slug: string
  157. mode: string
  158. colors: number
  159. maxStroke: number
  160. maxScale: number
  161. maxSpacing: number[]
  162. width: number
  163. height: number
  164. vHeight: number
  165. tags?: string[]
  166. path: string
  167. }
  168. // 底纹背景填充
  169. export interface ShadingBackground {
  170. id: number
  171. colors: string[]
  172. colorCounts: number
  173. stroke: number
  174. scale: number
  175. spacing: number[]
  176. angle: number
  177. join: number
  178. moveLeft: number
  179. moveTop: number
  180. }
  181. // 字体类型
  182. export interface FontOption {
  183. label: string
  184. value: string
  185. }
  186. // 字体分组
  187. export interface FontGroupOption {
  188. type: number
  189. label: string
  190. options: any[]
  191. }
  192. // 条形码参数
  193. export interface BarCodeOption {
  194. format: string
  195. width?: number
  196. height?: number
  197. displayValue?: boolean // 是否在条形码显示文字
  198. fontOptions?: string // 设置条形码文本的粗体和斜体样式 bold / italic / bold italic
  199. font?: string // 设置条形码显示文本的字体
  200. fontSize?: number // 设置条形码文本的字体大小
  201. textAlign?: string // 条形码文本的水平对齐方式,和css中的类似: left / center / right
  202. textPosition?: string // 条形码文本的位置 bottom / top
  203. textMargin?: string // 条形码文本 和 条形码之间的间隙大小
  204. background?: string // 整个条形码容器的背景颜色
  205. lineColor?: string // 条形码和文本的颜色
  206. margin?: number // 整个条形码的外面距
  207. marginTop?: number
  208. marginBottom?: number
  209. marginLeft?: number
  210. marginRight?: number
  211. }
  212. export const enum AlignCommand {
  213. LEFT = 'left',
  214. RIGHT = 'right',
  215. HORIZONTAL = 'horizontal',
  216. VERTICAL = 'vertical',
  217. CENTER = 'center',
  218. TOP = 'top',
  219. BOTTOM = 'bottom',
  220. }
  221. export const enum LayerCommand {
  222. UP = 'left',
  223. DOWN = 'right',
  224. TOP = 'top',
  225. BOTTOM = 'bottom',
  226. }
  227. export interface ImageCategoryData {
  228. id: number
  229. type: string
  230. name: string
  231. category: ImageHit[]
  232. total: ImageHit[]
  233. }