ding-image-editor 3.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (374) hide show
  1. package/README.md +193 -0
  2. package/dist/svg/icon-a.svg +376 -0
  3. package/dist/svg/icon-b.svg +369 -0
  4. package/dist/svg/icon-c.svg +369 -0
  5. package/dist/svg/icon-d.svg +369 -0
  6. package/dist/tui-image-editor.css +6 -0
  7. package/dist/tui-image-editor.js +62329 -0
  8. package/dist/tui-image-editor.min.css +5 -0
  9. package/dist/tui-image-editor.min.js +15 -0
  10. package/index.d.ts +334 -0
  11. package/package.json +52 -0
  12. package/src/css/buttons.styl +102 -0
  13. package/src/css/checkbox.styl +86 -0
  14. package/src/css/colorpicker.styl +98 -0
  15. package/src/css/gridtable.styl +45 -0
  16. package/src/css/icon.styl +44 -0
  17. package/src/css/index.styl +17 -0
  18. package/src/css/main.styl +163 -0
  19. package/src/css/position.styl +309 -0
  20. package/src/css/range.styl +91 -0
  21. package/src/css/submenu.styl +168 -0
  22. package/src/index.js +29 -0
  23. package/src/js/action.js +686 -0
  24. package/src/js/command/addIcon.js +42 -0
  25. package/src/js/command/addImageObject.js +34 -0
  26. package/src/js/command/addObject.js +43 -0
  27. package/src/js/command/addShape.js +51 -0
  28. package/src/js/command/addText.js +73 -0
  29. package/src/js/command/applyFilter.js +95 -0
  30. package/src/js/command/changeIconColor.js +48 -0
  31. package/src/js/command/changeSelection.js +31 -0
  32. package/src/js/command/changeShape.js +84 -0
  33. package/src/js/command/changeText.js +44 -0
  34. package/src/js/command/changeTextStyle.js +80 -0
  35. package/src/js/command/clearObjects.js +33 -0
  36. package/src/js/command/flip.js +36 -0
  37. package/src/js/command/loadImage.js +58 -0
  38. package/src/js/command/removeFilter.js +38 -0
  39. package/src/js/command/removeObject.js +37 -0
  40. package/src/js/command/resize.js +41 -0
  41. package/src/js/command/resizeCanvasDimension.js +40 -0
  42. package/src/js/command/rotate.js +64 -0
  43. package/src/js/command/setObjectPosition.js +50 -0
  44. package/src/js/command/setObjectProperties.js +55 -0
  45. package/src/js/component/cropper.js +407 -0
  46. package/src/js/component/filter.js +229 -0
  47. package/src/js/component/flip.js +146 -0
  48. package/src/js/component/freeDrawing.js +144 -0
  49. package/src/js/component/icon.js +246 -0
  50. package/src/js/component/imageLoader.js +84 -0
  51. package/src/js/component/line.js +205 -0
  52. package/src/js/component/resize.js +103 -0
  53. package/src/js/component/rotation.js +91 -0
  54. package/src/js/component/shape.js +601 -0
  55. package/src/js/component/text.js +572 -0
  56. package/src/js/component/zoom.js +708 -0
  57. package/src/js/consts.js +404 -0
  58. package/src/js/drawingMode/cropper.js +35 -0
  59. package/src/js/drawingMode/freeDrawing.js +36 -0
  60. package/src/js/drawingMode/icon.js +35 -0
  61. package/src/js/drawingMode/lineDrawing.js +36 -0
  62. package/src/js/drawingMode/resize.js +35 -0
  63. package/src/js/drawingMode/shape.js +35 -0
  64. package/src/js/drawingMode/text.js +35 -0
  65. package/src/js/drawingMode/zoom.js +37 -0
  66. package/src/js/extension/arrowLine.js +172 -0
  67. package/src/js/extension/blur.js +29 -0
  68. package/src/js/extension/colorFilter.js +104 -0
  69. package/src/js/extension/cropzone.js +568 -0
  70. package/src/js/extension/emboss.js +29 -0
  71. package/src/js/extension/mask.js +90 -0
  72. package/src/js/extension/sharpen.js +29 -0
  73. package/src/js/factory/command.js +36 -0
  74. package/src/js/factory/errorMessage.js +27 -0
  75. package/src/js/graphics.js +1539 -0
  76. package/src/js/helper/imagetracer.js +1396 -0
  77. package/src/js/helper/selectionModifyHelper.js +86 -0
  78. package/src/js/helper/shapeFilterFillHelper.js +564 -0
  79. package/src/js/helper/shapeResizeHelper.js +237 -0
  80. package/src/js/imageEditor.js +1795 -0
  81. package/src/js/interface/command.js +131 -0
  82. package/src/js/interface/component.js +127 -0
  83. package/src/js/interface/drawingMode.js +47 -0
  84. package/src/js/invoker.js +292 -0
  85. package/src/js/polyfill.js +498 -0
  86. package/src/js/ui/crop.js +139 -0
  87. package/src/js/ui/draw.js +187 -0
  88. package/src/js/ui/filter.js +510 -0
  89. package/src/js/ui/flip.js +87 -0
  90. package/src/js/ui/history.js +171 -0
  91. package/src/js/ui/icon.js +191 -0
  92. package/src/js/ui/locale/locale.js +19 -0
  93. package/src/js/ui/mask.js +96 -0
  94. package/src/js/ui/panelMenu.js +130 -0
  95. package/src/js/ui/resize.js +241 -0
  96. package/src/js/ui/rotate.js +123 -0
  97. package/src/js/ui/shape.js +265 -0
  98. package/src/js/ui/submenuBase.js +122 -0
  99. package/src/js/ui/template/controls.js +21 -0
  100. package/src/js/ui/template/mainContainer.js +38 -0
  101. package/src/js/ui/template/style.js +146 -0
  102. package/src/js/ui/template/submenu/crop.js +73 -0
  103. package/src/js/ui/template/submenu/draw.js +42 -0
  104. package/src/js/ui/template/submenu/filter.js +157 -0
  105. package/src/js/ui/template/submenu/flip.js +41 -0
  106. package/src/js/ui/template/submenu/history.js +22 -0
  107. package/src/js/ui/template/submenu/icon.js +108 -0
  108. package/src/js/ui/template/submenu/mask.js +30 -0
  109. package/src/js/ui/template/submenu/resize.js +54 -0
  110. package/src/js/ui/template/submenu/rotate.js +32 -0
  111. package/src/js/ui/template/submenu/shape.js +45 -0
  112. package/src/js/ui/template/submenu/text.js +67 -0
  113. package/src/js/ui/template/submenu/zoom.js +41 -0
  114. package/src/js/ui/text.js +279 -0
  115. package/src/js/ui/theme/standard.js +220 -0
  116. package/src/js/ui/theme/theme.js +249 -0
  117. package/src/js/ui/tools/colorpicker.js +250 -0
  118. package/src/js/ui/tools/range.js +390 -0
  119. package/src/js/ui.js +858 -0
  120. package/src/js/util.js +551 -0
  121. package/src/svg/default.svg +335 -0
  122. package/src/svg/icon-a/ic-apply.svg +6 -0
  123. package/src/svg/icon-a/ic-cancel.svg +6 -0
  124. package/src/svg/icon-a/ic-color-transparent-w.svg +12 -0
  125. package/src/svg/icon-a/ic-crop.svg +7 -0
  126. package/src/svg/icon-a/ic-delete-all.svg +6 -0
  127. package/src/svg/icon-a/ic-delete.svg +6 -0
  128. package/src/svg/icon-a/ic-draw-free.svg +5 -0
  129. package/src/svg/icon-a/ic-draw-line.svg +5 -0
  130. package/src/svg/icon-a/ic-draw.svg +6 -0
  131. package/src/svg/icon-a/ic-filter.svg +7 -0
  132. package/src/svg/icon-a/ic-flip-reset.svg +7 -0
  133. package/src/svg/icon-a/ic-flip-x.svg +6 -0
  134. package/src/svg/icon-a/ic-flip-y.svg +6 -0
  135. package/src/svg/icon-a/ic-flip.svg +6 -0
  136. package/src/svg/icon-a/ic-history-check.svg +5 -0
  137. package/src/svg/icon-a/ic-history-crop.svg +7 -0
  138. package/src/svg/icon-a/ic-history-delete.svg +9 -0
  139. package/src/svg/icon-a/ic-history-draw.svg +7 -0
  140. package/src/svg/icon-a/ic-history-filter.svg +8 -0
  141. package/src/svg/icon-a/ic-history-flip.svg +6 -0
  142. package/src/svg/icon-a/ic-history-group.svg +9 -0
  143. package/src/svg/icon-a/ic-history-icon.svg +6 -0
  144. package/src/svg/icon-a/ic-history-load.svg +7 -0
  145. package/src/svg/icon-a/ic-history-mask.svg +9 -0
  146. package/src/svg/icon-a/ic-history-resize.svg +12 -0
  147. package/src/svg/icon-a/ic-history-rotate.svg +16 -0
  148. package/src/svg/icon-a/ic-history-shape.svg +7 -0
  149. package/src/svg/icon-a/ic-history-text.svg +8 -0
  150. package/src/svg/icon-a/ic-history.svg +6 -0
  151. package/src/svg/icon-a/ic-icon-arrow-2.svg +5 -0
  152. package/src/svg/icon-a/ic-icon-arrow-3.svg +5 -0
  153. package/src/svg/icon-a/ic-icon-arrow.svg +5 -0
  154. package/src/svg/icon-a/ic-icon-bubble.svg +5 -0
  155. package/src/svg/icon-a/ic-icon-heart.svg +5 -0
  156. package/src/svg/icon-a/ic-icon-load.svg +8 -0
  157. package/src/svg/icon-a/ic-icon-location.svg +8 -0
  158. package/src/svg/icon-a/ic-icon-polygon.svg +5 -0
  159. package/src/svg/icon-a/ic-icon-star-2.svg +5 -0
  160. package/src/svg/icon-a/ic-icon-star.svg +5 -0
  161. package/src/svg/icon-a/ic-icon.svg +5 -0
  162. package/src/svg/icon-a/ic-mask-load.svg +8 -0
  163. package/src/svg/icon-a/ic-mask.svg +6 -0
  164. package/src/svg/icon-a/ic-redo.svg +7 -0
  165. package/src/svg/icon-a/ic-reset.svg +7 -0
  166. package/src/svg/icon-a/ic-resize.svg +13 -0
  167. package/src/svg/icon-a/ic-rotate-clockwise.svg +7 -0
  168. package/src/svg/icon-a/ic-rotate-counterclockwise.svg +7 -0
  169. package/src/svg/icon-a/ic-rotate.svg +7 -0
  170. package/src/svg/icon-a/ic-shape-circle.svg +5 -0
  171. package/src/svg/icon-a/ic-shape-rectangle.svg +5 -0
  172. package/src/svg/icon-a/ic-shape-triangle.svg +5 -0
  173. package/src/svg/icon-a/ic-shape.svg +6 -0
  174. package/src/svg/icon-a/ic-text-align-center.svg +6 -0
  175. package/src/svg/icon-a/ic-text-align-left.svg +6 -0
  176. package/src/svg/icon-a/ic-text-align-right.svg +6 -0
  177. package/src/svg/icon-a/ic-text-bold.svg +7 -0
  178. package/src/svg/icon-a/ic-text-italic.svg +6 -0
  179. package/src/svg/icon-a/ic-text-underline.svg +7 -0
  180. package/src/svg/icon-a/ic-text.svg +7 -0
  181. package/src/svg/icon-a/ic-undo.svg +7 -0
  182. package/src/svg/icon-a/ic-zoom-hand.svg +8 -0
  183. package/src/svg/icon-a/ic-zoom-zoom-in.svg +10 -0
  184. package/src/svg/icon-a/ic-zoom-zoom-out.svg +9 -0
  185. package/src/svg/icon-a/img-bi.svg +5 -0
  186. package/src/svg/icon-b/ic-apply.svg +6 -0
  187. package/src/svg/icon-b/ic-cancel.svg +6 -0
  188. package/src/svg/icon-b/ic-crop.svg +7 -0
  189. package/src/svg/icon-b/ic-delete-all.svg +6 -0
  190. package/src/svg/icon-b/ic-delete.svg +6 -0
  191. package/src/svg/icon-b/ic-draw-free.svg +5 -0
  192. package/src/svg/icon-b/ic-draw-line.svg +5 -0
  193. package/src/svg/icon-b/ic-draw.svg +6 -0
  194. package/src/svg/icon-b/ic-filter.svg +7 -0
  195. package/src/svg/icon-b/ic-flip-reset.svg +7 -0
  196. package/src/svg/icon-b/ic-flip-x.svg +6 -0
  197. package/src/svg/icon-b/ic-flip-y.svg +6 -0
  198. package/src/svg/icon-b/ic-flip.svg +6 -0
  199. package/src/svg/icon-b/ic-history-check.svg +5 -0
  200. package/src/svg/icon-b/ic-history-crop.svg +7 -0
  201. package/src/svg/icon-b/ic-history-delete.svg +9 -0
  202. package/src/svg/icon-b/ic-history-draw.svg +7 -0
  203. package/src/svg/icon-b/ic-history-filter.svg +8 -0
  204. package/src/svg/icon-b/ic-history-flip.svg +6 -0
  205. package/src/svg/icon-b/ic-history-group.svg +9 -0
  206. package/src/svg/icon-b/ic-history-icon.svg +6 -0
  207. package/src/svg/icon-b/ic-history-load.svg +7 -0
  208. package/src/svg/icon-b/ic-history-mask.svg +9 -0
  209. package/src/svg/icon-b/ic-history-resize.svg +12 -0
  210. package/src/svg/icon-b/ic-history-rotate.svg +16 -0
  211. package/src/svg/icon-b/ic-history-shape.svg +7 -0
  212. package/src/svg/icon-b/ic-history-text.svg +8 -0
  213. package/src/svg/icon-b/ic-history.svg +6 -0
  214. package/src/svg/icon-b/ic-icon-arrow-2.svg +5 -0
  215. package/src/svg/icon-b/ic-icon-arrow-3.svg +5 -0
  216. package/src/svg/icon-b/ic-icon-arrow.svg +5 -0
  217. package/src/svg/icon-b/ic-icon-bubble.svg +5 -0
  218. package/src/svg/icon-b/ic-icon-heart.svg +5 -0
  219. package/src/svg/icon-b/ic-icon-load.svg +8 -0
  220. package/src/svg/icon-b/ic-icon-location.svg +8 -0
  221. package/src/svg/icon-b/ic-icon-polygon.svg +5 -0
  222. package/src/svg/icon-b/ic-icon-star-2.svg +5 -0
  223. package/src/svg/icon-b/ic-icon-star.svg +5 -0
  224. package/src/svg/icon-b/ic-icon.svg +5 -0
  225. package/src/svg/icon-b/ic-mask-load.svg +8 -0
  226. package/src/svg/icon-b/ic-mask.svg +6 -0
  227. package/src/svg/icon-b/ic-redo.svg +7 -0
  228. package/src/svg/icon-b/ic-reset.svg +7 -0
  229. package/src/svg/icon-b/ic-resize.svg +13 -0
  230. package/src/svg/icon-b/ic-rotate-clockwise.svg +7 -0
  231. package/src/svg/icon-b/ic-rotate-counterclockwise.svg +7 -0
  232. package/src/svg/icon-b/ic-rotate.svg +7 -0
  233. package/src/svg/icon-b/ic-shape-circle.svg +5 -0
  234. package/src/svg/icon-b/ic-shape-rectangle.svg +5 -0
  235. package/src/svg/icon-b/ic-shape-triangle.svg +5 -0
  236. package/src/svg/icon-b/ic-shape.svg +6 -0
  237. package/src/svg/icon-b/ic-text-align-center.svg +6 -0
  238. package/src/svg/icon-b/ic-text-align-left.svg +6 -0
  239. package/src/svg/icon-b/ic-text-align-right.svg +6 -0
  240. package/src/svg/icon-b/ic-text-bold.svg +7 -0
  241. package/src/svg/icon-b/ic-text-italic.svg +6 -0
  242. package/src/svg/icon-b/ic-text-underline.svg +7 -0
  243. package/src/svg/icon-b/ic-text.svg +7 -0
  244. package/src/svg/icon-b/ic-undo.svg +7 -0
  245. package/src/svg/icon-b/ic-zoom-hand.svg +8 -0
  246. package/src/svg/icon-b/ic-zoom-zoom-in.svg +12 -0
  247. package/src/svg/icon-b/ic-zoom-zoom-out.svg +11 -0
  248. package/src/svg/icon-b/img-bi.svg +5 -0
  249. package/src/svg/icon-c/ic-apply.svg +6 -0
  250. package/src/svg/icon-c/ic-cancel.svg +6 -0
  251. package/src/svg/icon-c/ic-crop.svg +7 -0
  252. package/src/svg/icon-c/ic-delete-all.svg +6 -0
  253. package/src/svg/icon-c/ic-delete.svg +6 -0
  254. package/src/svg/icon-c/ic-draw-free.svg +5 -0
  255. package/src/svg/icon-c/ic-draw-line.svg +5 -0
  256. package/src/svg/icon-c/ic-draw.svg +6 -0
  257. package/src/svg/icon-c/ic-filter.svg +7 -0
  258. package/src/svg/icon-c/ic-flip-reset.svg +7 -0
  259. package/src/svg/icon-c/ic-flip-x.svg +6 -0
  260. package/src/svg/icon-c/ic-flip-y.svg +6 -0
  261. package/src/svg/icon-c/ic-flip.svg +6 -0
  262. package/src/svg/icon-c/ic-history-check.svg +5 -0
  263. package/src/svg/icon-c/ic-history-crop.svg +7 -0
  264. package/src/svg/icon-c/ic-history-delete.svg +9 -0
  265. package/src/svg/icon-c/ic-history-draw.svg +7 -0
  266. package/src/svg/icon-c/ic-history-filter.svg +8 -0
  267. package/src/svg/icon-c/ic-history-flip.svg +6 -0
  268. package/src/svg/icon-c/ic-history-group.svg +9 -0
  269. package/src/svg/icon-c/ic-history-icon.svg +6 -0
  270. package/src/svg/icon-c/ic-history-load.svg +7 -0
  271. package/src/svg/icon-c/ic-history-mask.svg +9 -0
  272. package/src/svg/icon-c/ic-history-resize.svg +12 -0
  273. package/src/svg/icon-c/ic-history-rotate.svg +16 -0
  274. package/src/svg/icon-c/ic-history-shape.svg +7 -0
  275. package/src/svg/icon-c/ic-history-text.svg +8 -0
  276. package/src/svg/icon-c/ic-history.svg +6 -0
  277. package/src/svg/icon-c/ic-icon-arrow-2.svg +5 -0
  278. package/src/svg/icon-c/ic-icon-arrow-3.svg +5 -0
  279. package/src/svg/icon-c/ic-icon-arrow.svg +5 -0
  280. package/src/svg/icon-c/ic-icon-bubble.svg +5 -0
  281. package/src/svg/icon-c/ic-icon-heart.svg +5 -0
  282. package/src/svg/icon-c/ic-icon-load.svg +8 -0
  283. package/src/svg/icon-c/ic-icon-location.svg +8 -0
  284. package/src/svg/icon-c/ic-icon-polygon.svg +5 -0
  285. package/src/svg/icon-c/ic-icon-star-2.svg +5 -0
  286. package/src/svg/icon-c/ic-icon-star.svg +5 -0
  287. package/src/svg/icon-c/ic-icon.svg +5 -0
  288. package/src/svg/icon-c/ic-mask-load.svg +8 -0
  289. package/src/svg/icon-c/ic-mask.svg +6 -0
  290. package/src/svg/icon-c/ic-redo.svg +7 -0
  291. package/src/svg/icon-c/ic-reset.svg +7 -0
  292. package/src/svg/icon-c/ic-resize.svg +13 -0
  293. package/src/svg/icon-c/ic-rotate-clockwise.svg +7 -0
  294. package/src/svg/icon-c/ic-rotate-counterclockwise.svg +7 -0
  295. package/src/svg/icon-c/ic-rotate.svg +7 -0
  296. package/src/svg/icon-c/ic-shape-circle.svg +5 -0
  297. package/src/svg/icon-c/ic-shape-rectangle.svg +5 -0
  298. package/src/svg/icon-c/ic-shape-triangle.svg +5 -0
  299. package/src/svg/icon-c/ic-shape.svg +6 -0
  300. package/src/svg/icon-c/ic-text-align-center.svg +6 -0
  301. package/src/svg/icon-c/ic-text-align-left.svg +6 -0
  302. package/src/svg/icon-c/ic-text-align-right.svg +6 -0
  303. package/src/svg/icon-c/ic-text-bold.svg +7 -0
  304. package/src/svg/icon-c/ic-text-italic.svg +6 -0
  305. package/src/svg/icon-c/ic-text-underline.svg +7 -0
  306. package/src/svg/icon-c/ic-text.svg +7 -0
  307. package/src/svg/icon-c/ic-undo.svg +7 -0
  308. package/src/svg/icon-c/ic-zoom-hand.svg +8 -0
  309. package/src/svg/icon-c/ic-zoom-zoom-in.svg +12 -0
  310. package/src/svg/icon-c/ic-zoom-zoom-out.svg +11 -0
  311. package/src/svg/icon-c/img-bi.svg +5 -0
  312. package/src/svg/icon-d/ic-apply.svg +6 -0
  313. package/src/svg/icon-d/ic-cancel.svg +6 -0
  314. package/src/svg/icon-d/ic-crop.svg +7 -0
  315. package/src/svg/icon-d/ic-delete-all.svg +6 -0
  316. package/src/svg/icon-d/ic-delete.svg +6 -0
  317. package/src/svg/icon-d/ic-draw-free.svg +5 -0
  318. package/src/svg/icon-d/ic-draw-line.svg +5 -0
  319. package/src/svg/icon-d/ic-draw.svg +6 -0
  320. package/src/svg/icon-d/ic-filter.svg +7 -0
  321. package/src/svg/icon-d/ic-flip-reset.svg +7 -0
  322. package/src/svg/icon-d/ic-flip-x.svg +6 -0
  323. package/src/svg/icon-d/ic-flip-y.svg +6 -0
  324. package/src/svg/icon-d/ic-flip.svg +6 -0
  325. package/src/svg/icon-d/ic-history-check.svg +5 -0
  326. package/src/svg/icon-d/ic-history-crop.svg +7 -0
  327. package/src/svg/icon-d/ic-history-delete.svg +9 -0
  328. package/src/svg/icon-d/ic-history-draw.svg +7 -0
  329. package/src/svg/icon-d/ic-history-filter.svg +8 -0
  330. package/src/svg/icon-d/ic-history-flip.svg +6 -0
  331. package/src/svg/icon-d/ic-history-group.svg +9 -0
  332. package/src/svg/icon-d/ic-history-icon.svg +6 -0
  333. package/src/svg/icon-d/ic-history-load.svg +7 -0
  334. package/src/svg/icon-d/ic-history-mask.svg +9 -0
  335. package/src/svg/icon-d/ic-history-resize.svg +12 -0
  336. package/src/svg/icon-d/ic-history-rotate.svg +16 -0
  337. package/src/svg/icon-d/ic-history-shape.svg +7 -0
  338. package/src/svg/icon-d/ic-history-text.svg +8 -0
  339. package/src/svg/icon-d/ic-history.svg +6 -0
  340. package/src/svg/icon-d/ic-icon-arrow-2.svg +5 -0
  341. package/src/svg/icon-d/ic-icon-arrow-3.svg +5 -0
  342. package/src/svg/icon-d/ic-icon-arrow.svg +5 -0
  343. package/src/svg/icon-d/ic-icon-bubble.svg +5 -0
  344. package/src/svg/icon-d/ic-icon-heart.svg +5 -0
  345. package/src/svg/icon-d/ic-icon-load.svg +8 -0
  346. package/src/svg/icon-d/ic-icon-location.svg +8 -0
  347. package/src/svg/icon-d/ic-icon-polygon.svg +5 -0
  348. package/src/svg/icon-d/ic-icon-star-2.svg +5 -0
  349. package/src/svg/icon-d/ic-icon-star.svg +5 -0
  350. package/src/svg/icon-d/ic-icon.svg +5 -0
  351. package/src/svg/icon-d/ic-mask-load.svg +8 -0
  352. package/src/svg/icon-d/ic-mask.svg +6 -0
  353. package/src/svg/icon-d/ic-redo.svg +7 -0
  354. package/src/svg/icon-d/ic-reset.svg +7 -0
  355. package/src/svg/icon-d/ic-resize.svg +13 -0
  356. package/src/svg/icon-d/ic-rotate-clockwise.svg +7 -0
  357. package/src/svg/icon-d/ic-rotate-counterclockwise.svg +7 -0
  358. package/src/svg/icon-d/ic-rotate.svg +7 -0
  359. package/src/svg/icon-d/ic-shape-circle.svg +5 -0
  360. package/src/svg/icon-d/ic-shape-rectangle.svg +5 -0
  361. package/src/svg/icon-d/ic-shape-triangle.svg +5 -0
  362. package/src/svg/icon-d/ic-shape.svg +6 -0
  363. package/src/svg/icon-d/ic-text-align-center.svg +6 -0
  364. package/src/svg/icon-d/ic-text-align-left.svg +6 -0
  365. package/src/svg/icon-d/ic-text-align-right.svg +6 -0
  366. package/src/svg/icon-d/ic-text-bold.svg +7 -0
  367. package/src/svg/icon-d/ic-text-italic.svg +6 -0
  368. package/src/svg/icon-d/ic-text-underline.svg +7 -0
  369. package/src/svg/icon-d/ic-text.svg +7 -0
  370. package/src/svg/icon-d/ic-undo.svg +7 -0
  371. package/src/svg/icon-d/ic-zoom-hand.svg +8 -0
  372. package/src/svg/icon-d/ic-zoom-zoom-in.svg +12 -0
  373. package/src/svg/icon-d/ic-zoom-zoom-out.svg +11 -0
  374. package/src/svg/icon-d/img-bi.svg +5 -0
@@ -0,0 +1,601 @@
1
+ import { fabric } from 'fabric';
2
+ import extend from 'tui-code-snippet/object/extend';
3
+ import Component from '@/interface/component';
4
+ import resizeHelper from '@/helper/shapeResizeHelper';
5
+ import {
6
+ getFillImageFromShape,
7
+ rePositionFilterTypeFillImage,
8
+ reMakePatternImageSource,
9
+ makeFillPatternForFilter,
10
+ makeFilterOptionFromFabricImage,
11
+ resetFillPatternCanvas,
12
+ } from '@/helper/shapeFilterFillHelper';
13
+ import {
14
+ changeOrigin,
15
+ getCustomProperty,
16
+ getFillTypeFromOption,
17
+ getFillTypeFromObject,
18
+ isShape,
19
+ } from '@/util';
20
+ import {
21
+ rejectMessages,
22
+ eventNames,
23
+ keyCodes as KEY_CODES,
24
+ componentNames,
25
+ fObjectOptions,
26
+ SHAPE_DEFAULT_OPTIONS,
27
+ SHAPE_FILL_TYPE,
28
+ } from '@/consts';
29
+
30
+ const SHAPE_INIT_OPTIONS = extend(
31
+ {
32
+ strokeWidth: 1,
33
+ stroke: '#000000',
34
+ fill: '#ffffff',
35
+ width: 1,
36
+ height: 1,
37
+ rx: 0,
38
+ ry: 0,
39
+ },
40
+ SHAPE_DEFAULT_OPTIONS
41
+ );
42
+ const DEFAULT_TYPE = 'rect';
43
+ const DEFAULT_WIDTH = 20;
44
+ const DEFAULT_HEIGHT = 20;
45
+
46
+ /**
47
+ * Make fill option
48
+ * @param {Object} options - Options to create the shape
49
+ * @param {Object.Image} canvasImage - canvas background image
50
+ * @param {Function} createStaticCanvas - static canvas creater
51
+ * @returns {Object} - shape option
52
+ * @private
53
+ */
54
+ function makeFabricFillOption(options, canvasImage, createStaticCanvas) {
55
+ const fillOption = options.fill;
56
+ const fillType = getFillTypeFromOption(options.fill);
57
+ let fill = fillOption;
58
+
59
+ if (fillOption.color) {
60
+ fill = fillOption.color;
61
+ }
62
+
63
+ let extOption = null;
64
+ if (fillType === 'filter') {
65
+ const newStaticCanvas = createStaticCanvas();
66
+ extOption = makeFillPatternForFilter(canvasImage, fillOption.filter, newStaticCanvas);
67
+ } else {
68
+ extOption = { fill };
69
+ }
70
+
71
+ return extend({}, options, extOption);
72
+ }
73
+
74
+ /**
75
+ * Shape
76
+ * @class Shape
77
+ * @param {Graphics} graphics - Graphics instance
78
+ * @extends {Component}
79
+ * @ignore
80
+ */
81
+ export default class Shape extends Component {
82
+ constructor(graphics) {
83
+ super(componentNames.SHAPE, graphics);
84
+
85
+ /**
86
+ * Object of The drawing shape
87
+ * @type {fabric.Object}
88
+ * @private
89
+ */
90
+ this._shapeObj = null;
91
+
92
+ /**
93
+ * Type of the drawing shape
94
+ * @type {string}
95
+ * @private
96
+ */
97
+ this._type = DEFAULT_TYPE;
98
+
99
+ /**
100
+ * Options to draw the shape
101
+ * @type {Object}
102
+ * @private
103
+ */
104
+ this._options = extend({}, SHAPE_INIT_OPTIONS);
105
+
106
+ /**
107
+ * Whether the shape object is selected or not
108
+ * @type {boolean}
109
+ * @private
110
+ */
111
+ this._isSelected = false;
112
+
113
+ /**
114
+ * Pointer for drawing shape (x, y)
115
+ * @type {Object}
116
+ * @private
117
+ */
118
+ this._startPoint = {};
119
+
120
+ /**
121
+ * Using shortcut on drawing shape
122
+ * @type {boolean}
123
+ * @private
124
+ */
125
+ this._withShiftKey = false;
126
+
127
+ /**
128
+ * Event handler list
129
+ * @type {Object}
130
+ * @private
131
+ */
132
+ this._handlers = {
133
+ mousedown: this._onFabricMouseDown.bind(this),
134
+ mousemove: this._onFabricMouseMove.bind(this),
135
+ mouseup: this._onFabricMouseUp.bind(this),
136
+ keydown: this._onKeyDown.bind(this),
137
+ keyup: this._onKeyUp.bind(this),
138
+ };
139
+ }
140
+
141
+ /**
142
+ * Start to draw the shape on canvas
143
+ * @ignore
144
+ */
145
+ start() {
146
+ const canvas = this.getCanvas();
147
+
148
+ this._isSelected = false;
149
+
150
+ canvas.defaultCursor = 'crosshair';
151
+ canvas.selection = false;
152
+ canvas.uniformScaling = true;
153
+ canvas.on({
154
+ 'mouse:down': this._handlers.mousedown,
155
+ });
156
+
157
+ fabric.util.addListener(document, 'keydown', this._handlers.keydown);
158
+ fabric.util.addListener(document, 'keyup', this._handlers.keyup);
159
+ }
160
+
161
+ /**
162
+ * End to draw the shape on canvas
163
+ * @ignore
164
+ */
165
+ end() {
166
+ const canvas = this.getCanvas();
167
+
168
+ this._isSelected = false;
169
+
170
+ canvas.defaultCursor = 'default';
171
+
172
+ canvas.selection = true;
173
+ canvas.uniformScaling = false;
174
+ canvas.off({
175
+ 'mouse:down': this._handlers.mousedown,
176
+ });
177
+
178
+ fabric.util.removeListener(document, 'keydown', this._handlers.keydown);
179
+ fabric.util.removeListener(document, 'keyup', this._handlers.keyup);
180
+ }
181
+
182
+ /**
183
+ * Set states of the current drawing shape
184
+ * @ignore
185
+ * @param {string} type - Shape type (ex: 'rect', 'circle')
186
+ * @param {Object} [options] - Shape options
187
+ * @param {(ShapeFillOption | string)} [options.fill] - {@link ShapeFillOption} or
188
+ * Shape foreground color (ex: '#fff', 'transparent')
189
+ * @param {string} [options.stoke] - Shape outline color
190
+ * @param {number} [options.strokeWidth] - Shape outline width
191
+ * @param {number} [options.width] - Width value (When type option is 'rect', this options can use)
192
+ * @param {number} [options.height] - Height value (When type option is 'rect', this options can use)
193
+ * @param {number} [options.rx] - Radius x value (When type option is 'circle', this options can use)
194
+ * @param {number} [options.ry] - Radius y value (When type option is 'circle', this options can use)
195
+ */
196
+ setStates(type, options) {
197
+ this._type = type;
198
+
199
+ if (options) {
200
+ this._options = extend(this._options, options);
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Add the shape
206
+ * @ignore
207
+ * @param {string} type - Shape type (ex: 'rect', 'circle')
208
+ * @param {Object} options - Shape options
209
+ * @param {(ShapeFillOption | string)} [options.fill] - ShapeFillOption or Shape foreground color (ex: '#fff', 'transparent') or ShapeFillOption object
210
+ * @param {string} [options.stroke] - Shape outline color
211
+ * @param {number} [options.strokeWidth] - Shape outline width
212
+ * @param {number} [options.width] - Width value (When type option is 'rect', this options can use)
213
+ * @param {number} [options.height] - Height value (When type option is 'rect', this options can use)
214
+ * @param {number} [options.rx] - Radius x value (When type option is 'circle', this options can use)
215
+ * @param {number} [options.ry] - Radius y value (When type option is 'circle', this options can use)
216
+ * @param {number} [options.isRegular] - Whether scaling shape has 1:1 ratio or not
217
+ * @returns {Promise}
218
+ */
219
+ add(type, options) {
220
+ return new Promise((resolve) => {
221
+ const canvas = this.getCanvas();
222
+ const extendOption = this._extendOptions(options);
223
+
224
+ const shapeObj = this._createInstance(type, extendOption);
225
+ const objectProperties = this.graphics.createObjectProperties(shapeObj);
226
+
227
+ this._bindEventOnShape(shapeObj);
228
+
229
+ canvas.add(shapeObj).setActiveObject(shapeObj);
230
+
231
+ this._resetPositionFillFilter(shapeObj);
232
+
233
+ resolve(objectProperties);
234
+ });
235
+ }
236
+
237
+ /**
238
+ * Change the shape
239
+ * @ignore
240
+ * @param {fabric.Object} shapeObj - Selected shape object on canvas
241
+ * @param {Object} options - Shape options
242
+ * @param {(ShapeFillOption | string)} [options.fill] - {@link ShapeFillOption} or
243
+ * Shape foreground color (ex: '#fff', 'transparent')
244
+ * @param {string} [options.stroke] - Shape outline color
245
+ * @param {number} [options.strokeWidth] - Shape outline width
246
+ * @param {number} [options.width] - Width value (When type option is 'rect', this options can use)
247
+ * @param {number} [options.height] - Height value (When type option is 'rect', this options can use)
248
+ * @param {number} [options.rx] - Radius x value (When type option is 'circle', this options can use)
249
+ * @param {number} [options.ry] - Radius y value (When type option is 'circle', this options can use)
250
+ * @param {number} [options.isRegular] - Whether scaling shape has 1:1 ratio or not
251
+ * @returns {Promise}
252
+ */
253
+ change(shapeObj, options) {
254
+ return new Promise((resolve, reject) => {
255
+ if (!isShape(shapeObj)) {
256
+ reject(rejectMessages.unsupportedType);
257
+ }
258
+ const hasFillOption = getFillTypeFromOption(options.fill) === 'filter';
259
+ const { canvasImage, createStaticCanvas } = this.graphics;
260
+
261
+ shapeObj.set(
262
+ hasFillOption ? makeFabricFillOption(options, canvasImage, createStaticCanvas) : options
263
+ );
264
+
265
+ if (hasFillOption) {
266
+ this._resetPositionFillFilter(shapeObj);
267
+ }
268
+
269
+ this.getCanvas().renderAll();
270
+ resolve();
271
+ });
272
+ }
273
+
274
+ /**
275
+ * make fill property for user event
276
+ * @param {fabric.Object} shapeObj - fabric object
277
+ * @returns {Object}
278
+ */
279
+ makeFillPropertyForUserEvent(shapeObj) {
280
+ const fillType = getFillTypeFromObject(shapeObj);
281
+ const fillProp = {};
282
+
283
+ if (fillType === SHAPE_FILL_TYPE.FILTER) {
284
+ const fillImage = getFillImageFromShape(shapeObj);
285
+ const filterOption = makeFilterOptionFromFabricImage(fillImage);
286
+
287
+ fillProp.type = fillType;
288
+ fillProp.filter = filterOption;
289
+ } else {
290
+ fillProp.type = SHAPE_FILL_TYPE.COLOR;
291
+ fillProp.color = shapeObj.fill || 'transparent';
292
+ }
293
+
294
+ return fillProp;
295
+ }
296
+
297
+ /**
298
+ * Copy object handling.
299
+ * @param {fabric.Object} shapeObj - Shape object
300
+ * @param {fabric.Object} originalShapeObj - Shape object
301
+ */
302
+ processForCopiedObject(shapeObj, originalShapeObj) {
303
+ this._bindEventOnShape(shapeObj);
304
+
305
+ if (getFillTypeFromObject(shapeObj) === 'filter') {
306
+ const fillImage = getFillImageFromShape(originalShapeObj);
307
+ const filterOption = makeFilterOptionFromFabricImage(fillImage);
308
+ const newStaticCanvas = this.graphics.createStaticCanvas();
309
+
310
+ shapeObj.set(
311
+ makeFillPatternForFilter(this.graphics.canvasImage, filterOption, newStaticCanvas)
312
+ );
313
+ this._resetPositionFillFilter(shapeObj);
314
+ }
315
+ }
316
+
317
+ /**
318
+ * Create the instance of shape
319
+ * @param {string} type - Shape type
320
+ * @param {Object} options - Options to creat the shape
321
+ * @returns {fabric.Object} Shape instance
322
+ * @private
323
+ */
324
+ _createInstance(type, options) {
325
+ let instance;
326
+
327
+ switch (type) {
328
+ case 'rect':
329
+ instance = new fabric.Rect(options);
330
+ break;
331
+ case 'circle':
332
+ instance = new fabric.Ellipse(
333
+ extend(
334
+ {
335
+ type: 'circle',
336
+ },
337
+ options
338
+ )
339
+ );
340
+ break;
341
+ case 'triangle':
342
+ instance = new fabric.Triangle(options);
343
+ break;
344
+ default:
345
+ instance = {};
346
+ }
347
+
348
+ return instance;
349
+ }
350
+
351
+ /**
352
+ * Get the options to create the shape
353
+ * @param {Object} options - Options to creat the shape
354
+ * @returns {Object} Shape options
355
+ * @private
356
+ */
357
+ _extendOptions(options) {
358
+ const selectionStyles = fObjectOptions.SELECTION_STYLE;
359
+ const { canvasImage, createStaticCanvas } = this.graphics;
360
+
361
+ options = extend({}, SHAPE_INIT_OPTIONS, this._options, selectionStyles, options);
362
+
363
+ return makeFabricFillOption(options, canvasImage, createStaticCanvas);
364
+ }
365
+
366
+ /**
367
+ * Bind fabric events on the creating shape object
368
+ * @param {fabric.Object} shapeObj - Shape object
369
+ * @private
370
+ */
371
+ _bindEventOnShape(shapeObj) {
372
+ const self = this;
373
+ const canvas = this.getCanvas();
374
+
375
+ shapeObj.on({
376
+ added() {
377
+ self._shapeObj = this;
378
+ resizeHelper.setOrigins(self._shapeObj);
379
+ },
380
+ selected() {
381
+ self._isSelected = true;
382
+ self._shapeObj = this;
383
+ canvas.uniformScaling = true;
384
+ canvas.defaultCursor = 'default';
385
+ resizeHelper.setOrigins(self._shapeObj);
386
+ },
387
+ deselected() {
388
+ self._isSelected = false;
389
+ self._shapeObj = null;
390
+ canvas.defaultCursor = 'crosshair';
391
+ canvas.uniformScaling = false;
392
+ },
393
+ modified() {
394
+ const currentObj = self._shapeObj;
395
+
396
+ resizeHelper.adjustOriginToCenter(currentObj);
397
+ resizeHelper.setOrigins(currentObj);
398
+ },
399
+ modifiedInGroup(activeSelection) {
400
+ self._fillFilterRePositionInGroupSelection(shapeObj, activeSelection);
401
+ },
402
+ moving() {
403
+ self._resetPositionFillFilter(this);
404
+ },
405
+ rotating() {
406
+ self._resetPositionFillFilter(this);
407
+ },
408
+ scaling(fEvent) {
409
+ const pointer = canvas.getPointer(fEvent.e);
410
+ const currentObj = self._shapeObj;
411
+
412
+ canvas.setCursor('crosshair');
413
+ resizeHelper.resize(currentObj, pointer, true);
414
+
415
+ self._resetPositionFillFilter(this);
416
+ },
417
+ });
418
+ }
419
+
420
+ /**
421
+ * MouseDown event handler on canvas
422
+ * @param {{target: fabric.Object, e: MouseEvent}} fEvent - Fabric event object
423
+ * @private
424
+ */
425
+ _onFabricMouseDown(fEvent) {
426
+ if (!fEvent.target) {
427
+ this._isSelected = false;
428
+ this._shapeObj = false;
429
+ }
430
+
431
+ if (!this._isSelected && !this._shapeObj) {
432
+ const canvas = this.getCanvas();
433
+ this._startPoint = canvas.getPointer(fEvent.e);
434
+
435
+ canvas.on({
436
+ 'mouse:move': this._handlers.mousemove,
437
+ 'mouse:up': this._handlers.mouseup,
438
+ });
439
+ }
440
+ }
441
+
442
+ /**
443
+ * MouseDown event handler on canvas
444
+ * @param {{target: fabric.Object, e: MouseEvent}} fEvent - Fabric event object
445
+ * @private
446
+ */
447
+ _onFabricMouseMove(fEvent) {
448
+ const canvas = this.getCanvas();
449
+ const pointer = canvas.getPointer(fEvent.e);
450
+ const startPointX = this._startPoint.x;
451
+ const startPointY = this._startPoint.y;
452
+ const width = startPointX - pointer.x;
453
+ const height = startPointY - pointer.y;
454
+ const shape = this._shapeObj;
455
+
456
+ if (!shape) {
457
+ this.add(this._type, {
458
+ left: startPointX,
459
+ top: startPointY,
460
+ width,
461
+ height,
462
+ }).then((objectProps) => {
463
+ this.fire(eventNames.ADD_OBJECT, objectProps);
464
+ });
465
+ } else {
466
+ this._shapeObj.set({
467
+ isRegular: this._withShiftKey,
468
+ });
469
+
470
+ resizeHelper.resize(shape, pointer);
471
+ canvas.renderAll();
472
+
473
+ this._resetPositionFillFilter(shape);
474
+ }
475
+ }
476
+
477
+ /**
478
+ * MouseUp event handler on canvas
479
+ * @private
480
+ */
481
+ _onFabricMouseUp() {
482
+ const canvas = this.getCanvas();
483
+ const startPointX = this._startPoint.x;
484
+ const startPointY = this._startPoint.y;
485
+ const shape = this._shapeObj;
486
+
487
+ if (!shape) {
488
+ this.add(this._type, {
489
+ left: startPointX,
490
+ top: startPointY,
491
+ width: DEFAULT_WIDTH,
492
+ height: DEFAULT_HEIGHT,
493
+ }).then((objectProps) => {
494
+ this.fire(eventNames.ADD_OBJECT, objectProps);
495
+ });
496
+ } else if (shape) {
497
+ resizeHelper.adjustOriginToCenter(shape);
498
+ this.fire(eventNames.OBJECT_ADDED, this.graphics.createObjectProperties(shape));
499
+ }
500
+
501
+ canvas.off({
502
+ 'mouse:move': this._handlers.mousemove,
503
+ 'mouse:up': this._handlers.mouseup,
504
+ });
505
+ }
506
+
507
+ /**
508
+ * Keydown event handler on document
509
+ * @param {KeyboardEvent} e - Event object
510
+ * @private
511
+ */
512
+ _onKeyDown(e) {
513
+ if (e.keyCode === KEY_CODES.SHIFT) {
514
+ this._withShiftKey = true;
515
+
516
+ if (this._shapeObj) {
517
+ this._shapeObj.isRegular = true;
518
+ }
519
+ }
520
+ }
521
+
522
+ /**
523
+ * Keyup event handler on document
524
+ * @param {KeyboardEvent} e - Event object
525
+ * @private
526
+ */
527
+ _onKeyUp(e) {
528
+ if (e.keyCode === KEY_CODES.SHIFT) {
529
+ this._withShiftKey = false;
530
+
531
+ if (this._shapeObj) {
532
+ this._shapeObj.isRegular = false;
533
+ }
534
+ }
535
+ }
536
+
537
+ /**
538
+ * Reset shape position and internal proportions in the filter type fill area.
539
+ * @param {fabric.Object} shapeObj - Shape object
540
+ * @private
541
+ */
542
+ _resetPositionFillFilter(shapeObj) {
543
+ if (getFillTypeFromObject(shapeObj) !== 'filter') {
544
+ return;
545
+ }
546
+
547
+ const { patternSourceCanvas } = getCustomProperty(shapeObj, 'patternSourceCanvas');
548
+
549
+ const fillImage = getFillImageFromShape(shapeObj);
550
+ const { originalAngle } = getCustomProperty(fillImage, 'originalAngle');
551
+
552
+ if (this.graphics.canvasImage.angle !== originalAngle) {
553
+ reMakePatternImageSource(shapeObj, this.graphics.canvasImage);
554
+ }
555
+ const { originX, originY } = shapeObj;
556
+
557
+ resizeHelper.adjustOriginToCenter(shapeObj);
558
+
559
+ shapeObj.width *= shapeObj.scaleX;
560
+ shapeObj.height *= shapeObj.scaleY;
561
+ shapeObj.rx *= shapeObj.scaleX;
562
+ shapeObj.ry *= shapeObj.scaleY;
563
+ shapeObj.scaleX = 1;
564
+ shapeObj.scaleY = 1;
565
+
566
+ rePositionFilterTypeFillImage(shapeObj);
567
+
568
+ changeOrigin(shapeObj, {
569
+ originX,
570
+ originY,
571
+ });
572
+
573
+ resetFillPatternCanvas(patternSourceCanvas);
574
+ }
575
+
576
+ /**
577
+ * Reset filter area position within group selection.
578
+ * @param {fabric.Object} shapeObj - Shape object
579
+ * @param {fabric.ActiveSelection} activeSelection - Shape object
580
+ * @private
581
+ */
582
+ _fillFilterRePositionInGroupSelection(shapeObj, activeSelection) {
583
+ if (activeSelection.scaleX !== 1 || activeSelection.scaleY !== 1) {
584
+ // This is necessary because the group's scale transition state affects the relative size of the fill area.
585
+ // The only way to reset the object transformation scale state to neutral.
586
+ // {@link https://github.com/fabricjs/fabric.js/issues/5372}
587
+ activeSelection.addWithUpdate();
588
+ }
589
+
590
+ const { angle, left, top } = shapeObj;
591
+
592
+ fabric.util.addTransformToObject(shapeObj, activeSelection.calcTransformMatrix());
593
+ this._resetPositionFillFilter(shapeObj);
594
+
595
+ shapeObj.set({
596
+ angle,
597
+ left,
598
+ top,
599
+ });
600
+ }
601
+ }