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,568 @@
1
+ import { fabric } from 'fabric';
2
+ import extend from 'tui-code-snippet/object/extend';
3
+ import { clamp } from '@/util';
4
+ import { eventNames as events, keyCodes } from '@/consts';
5
+
6
+ const CORNER_TYPE_TOP_LEFT = 'tl';
7
+ const CORNER_TYPE_TOP_RIGHT = 'tr';
8
+ const CORNER_TYPE_MIDDLE_TOP = 'mt';
9
+ const CORNER_TYPE_MIDDLE_LEFT = 'ml';
10
+ const CORNER_TYPE_MIDDLE_RIGHT = 'mr';
11
+ const CORNER_TYPE_MIDDLE_BOTTOM = 'mb';
12
+ const CORNER_TYPE_BOTTOM_LEFT = 'bl';
13
+ const CORNER_TYPE_BOTTOM_RIGHT = 'br';
14
+ const CORNER_TYPE_LIST = [
15
+ CORNER_TYPE_TOP_LEFT,
16
+ CORNER_TYPE_TOP_RIGHT,
17
+ CORNER_TYPE_MIDDLE_TOP,
18
+ CORNER_TYPE_MIDDLE_LEFT,
19
+ CORNER_TYPE_MIDDLE_RIGHT,
20
+ CORNER_TYPE_MIDDLE_BOTTOM,
21
+ CORNER_TYPE_BOTTOM_LEFT,
22
+ CORNER_TYPE_BOTTOM_RIGHT,
23
+ ];
24
+ const NOOP_FUNCTION = () => {};
25
+
26
+ /**
27
+ * Align with cropzone ratio
28
+ * @param {string} selectedCorner - selected corner type
29
+ * @returns {{width: number, height: number}}
30
+ * @private
31
+ */
32
+ function cornerTypeValid(selectedCorner) {
33
+ return CORNER_TYPE_LIST.indexOf(selectedCorner) >= 0;
34
+ }
35
+
36
+ /**
37
+ * return scale basis type
38
+ * @param {number} diffX - X distance of the cursor and corner.
39
+ * @param {number} diffY - Y distance of the cursor and corner.
40
+ * @returns {string}
41
+ * @private
42
+ */
43
+ function getScaleBasis(diffX, diffY) {
44
+ return diffX > diffY ? 'width' : 'height';
45
+ }
46
+
47
+ /**
48
+ * Cropzone object
49
+ * Issue: IE7, 8(with excanvas)
50
+ * - Cropzone is a black zone without transparency.
51
+ * @class Cropzone
52
+ * @extends {fabric.Rect}
53
+ * @ignore
54
+ */
55
+ const Cropzone = fabric.util.createClass(
56
+ fabric.Rect,
57
+ /** @lends Cropzone.prototype */ {
58
+ /**
59
+ * Constructor
60
+ * @param {Object} canvas canvas
61
+ * @param {Object} options Options object
62
+ * @param {Object} extendsOptions object for extends "options"
63
+ * @override
64
+ */
65
+ initialize(canvas, options, extendsOptions) {
66
+ options = extend(options, extendsOptions);
67
+ options.type = 'cropzone';
68
+
69
+ this.callSuper('initialize', options);
70
+ this._addEventHandler();
71
+
72
+ this.canvas = canvas;
73
+ this.options = options;
74
+ },
75
+ canvasEventDelegation(eventName) {
76
+ let delegationState = 'unregistered';
77
+ const isRegistered = this.canvasEventTrigger[eventName] !== NOOP_FUNCTION;
78
+ if (isRegistered) {
79
+ delegationState = 'registered';
80
+ } else if ([events.OBJECT_MOVED, events.OBJECT_SCALED].indexOf(eventName) < 0) {
81
+ delegationState = 'none';
82
+ }
83
+
84
+ return delegationState;
85
+ },
86
+ canvasEventRegister(eventName, eventTrigger) {
87
+ this.canvasEventTrigger[eventName] = eventTrigger;
88
+ },
89
+ _addEventHandler() {
90
+ this.canvasEventTrigger = {
91
+ [events.OBJECT_MOVED]: NOOP_FUNCTION,
92
+ [events.OBJECT_SCALED]: NOOP_FUNCTION,
93
+ };
94
+ this.on({
95
+ moving: this._onMoving.bind(this),
96
+ scaling: this._onScaling.bind(this),
97
+ });
98
+ fabric.util.addListener(document, 'keydown', this._onKeyDown.bind(this));
99
+ fabric.util.addListener(document, 'keyup', this._onKeyUp.bind(this));
100
+ },
101
+ _renderCropzone(ctx) {
102
+ const cropzoneDashLineWidth = 7;
103
+ const cropzoneDashLineOffset = 7;
104
+
105
+ // Calc original scale
106
+ const originalFlipX = this.flipX ? -1 : 1;
107
+ const originalFlipY = this.flipY ? -1 : 1;
108
+ const originalScaleX = originalFlipX / this.scaleX;
109
+ const originalScaleY = originalFlipY / this.scaleY;
110
+
111
+ // Set original scale
112
+ ctx.scale(originalScaleX, originalScaleY);
113
+
114
+ // Render outer rect
115
+ this._fillOuterRect(ctx, 'rgba(0, 0, 0, 0.5)');
116
+
117
+ if (this.options.lineWidth) {
118
+ this._fillInnerRect(ctx);
119
+ this._strokeBorder(ctx, 'rgb(255, 255, 255)', {
120
+ lineWidth: this.options.lineWidth,
121
+ });
122
+ } else {
123
+ // Black dash line
124
+ this._strokeBorder(ctx, 'rgb(0, 0, 0)', {
125
+ lineDashWidth: cropzoneDashLineWidth,
126
+ });
127
+
128
+ // White dash line
129
+ this._strokeBorder(ctx, 'rgb(255, 255, 255)', {
130
+ lineDashWidth: cropzoneDashLineWidth,
131
+ lineDashOffset: cropzoneDashLineOffset,
132
+ });
133
+ }
134
+
135
+ // Reset scale
136
+ ctx.scale(1 / originalScaleX, 1 / originalScaleY);
137
+ },
138
+
139
+ /**
140
+ * Render Crop-zone
141
+ * @private
142
+ * @override
143
+ */
144
+ _render(ctx) {
145
+ this.callSuper('_render', ctx);
146
+
147
+ this._renderCropzone(ctx);
148
+ },
149
+
150
+ /**
151
+ * Cropzone-coordinates with outer rectangle
152
+ *
153
+ * x0 x1 x2 x3
154
+ * y0 +--------------------------+
155
+ * |///////|//////////|///////| // <--- "Outer-rectangle"
156
+ * |///////|//////////|///////|
157
+ * y1 +-------+----------+-------+
158
+ * |///////| Cropzone |///////| Cropzone is the "Inner-rectangle"
159
+ * |///////| (0, 0) |///////| Center point (0, 0)
160
+ * y2 +-------+----------+-------+
161
+ * |///////|//////////|///////|
162
+ * |///////|//////////|///////|
163
+ * y3 +--------------------------+
164
+ *
165
+ * @typedef {{x: Array<number>, y: Array<number>}} cropzoneCoordinates
166
+ * @ignore
167
+ */
168
+
169
+ /**
170
+ * Fill outer rectangle
171
+ * @param {CanvasRenderingContext2D} ctx - Context
172
+ * @param {string|CanvasGradient|CanvasPattern} fillStyle - Fill-style
173
+ * @private
174
+ */
175
+ _fillOuterRect(ctx, fillStyle) {
176
+ const { x, y } = this._getCoordinates();
177
+
178
+ ctx.save();
179
+ ctx.fillStyle = fillStyle;
180
+ ctx.beginPath();
181
+
182
+ // Outer rectangle
183
+ // Numbers are +/-1 so that overlay edges don't get blurry.
184
+ ctx.moveTo(x[0] - 1, y[0] - 1);
185
+ ctx.lineTo(x[3] + 1, y[0] - 1);
186
+ ctx.lineTo(x[3] + 1, y[3] + 1);
187
+ ctx.lineTo(x[0] - 1, y[3] + 1);
188
+ ctx.lineTo(x[0] - 1, y[0] - 1);
189
+ ctx.closePath();
190
+
191
+ // Inner rectangle
192
+ ctx.moveTo(x[1], y[1]);
193
+ ctx.lineTo(x[1], y[2]);
194
+ ctx.lineTo(x[2], y[2]);
195
+ ctx.lineTo(x[2], y[1]);
196
+ ctx.lineTo(x[1], y[1]);
197
+ ctx.closePath();
198
+
199
+ ctx.fill();
200
+ ctx.restore();
201
+ },
202
+
203
+ /**
204
+ * Draw Inner grid line
205
+ * @param {CanvasRenderingContext2D} ctx - Context
206
+ * @private
207
+ */
208
+ _fillInnerRect(ctx) {
209
+ const { x: outerX, y: outerY } = this._getCoordinates();
210
+ const x = this._caculateInnerPosition(outerX, (outerX[2] - outerX[1]) / 3);
211
+ const y = this._caculateInnerPosition(outerY, (outerY[2] - outerY[1]) / 3);
212
+
213
+ ctx.save();
214
+ ctx.strokeStyle = 'rgba(255, 255, 255, 0.7)';
215
+ ctx.lineWidth = this.options.lineWidth;
216
+ ctx.beginPath();
217
+
218
+ ctx.moveTo(x[0], y[1]);
219
+ ctx.lineTo(x[3], y[1]);
220
+
221
+ ctx.moveTo(x[0], y[2]);
222
+ ctx.lineTo(x[3], y[2]);
223
+
224
+ ctx.moveTo(x[1], y[0]);
225
+ ctx.lineTo(x[1], y[3]);
226
+
227
+ ctx.moveTo(x[2], y[0]);
228
+ ctx.lineTo(x[2], y[3]);
229
+ ctx.stroke();
230
+ ctx.closePath();
231
+
232
+ ctx.restore();
233
+ },
234
+
235
+ /**
236
+ * Calculate Inner Position
237
+ * @param {Array} outer - outer position
238
+ * @param {number} size - interval for calculate
239
+ * @returns {Array} - inner position
240
+ * @private
241
+ */
242
+ _caculateInnerPosition(outer, size) {
243
+ const position = [];
244
+ position[0] = outer[1];
245
+ position[1] = outer[1] + size;
246
+ position[2] = outer[1] + size * 2;
247
+ position[3] = outer[2];
248
+
249
+ return position;
250
+ },
251
+
252
+ /**
253
+ * Get coordinates
254
+ * @returns {cropzoneCoordinates} - {@link cropzoneCoordinates}
255
+ * @private
256
+ */
257
+ _getCoordinates() {
258
+ const { canvas, width, height, left, top } = this;
259
+ const halfWidth = width / 2;
260
+ const halfHeight = height / 2;
261
+ const canvasHeight = canvas.getHeight(); // fabric object
262
+ const canvasWidth = canvas.getWidth(); // fabric object
263
+
264
+ return {
265
+ x: [
266
+ -(halfWidth + left), // x0
267
+ -halfWidth, // x1
268
+ halfWidth, // x2
269
+ halfWidth + (canvasWidth - left - width), // x3
270
+ ].map(Math.ceil),
271
+ y: [
272
+ -(halfHeight + top), // y0
273
+ -halfHeight, // y1
274
+ halfHeight, // y2
275
+ halfHeight + (canvasHeight - top - height), // y3
276
+ ].map(Math.ceil),
277
+ };
278
+ },
279
+
280
+ /**
281
+ * Stroke border
282
+ * @param {CanvasRenderingContext2D} ctx - Context
283
+ * @param {string|CanvasGradient|CanvasPattern} strokeStyle - Stroke-style
284
+ * @param {number} lineDashWidth - Dash width
285
+ * @param {number} [lineDashOffset] - Dash offset
286
+ * @param {number} [lineWidth] - line width
287
+ * @private
288
+ */
289
+ _strokeBorder(ctx, strokeStyle, { lineDashWidth, lineDashOffset, lineWidth }) {
290
+ const halfWidth = this.width / 2;
291
+ const halfHeight = this.height / 2;
292
+
293
+ ctx.save();
294
+ ctx.strokeStyle = strokeStyle;
295
+
296
+ if (ctx.setLineDash) {
297
+ ctx.setLineDash([lineDashWidth, lineDashWidth]);
298
+ }
299
+ if (lineDashOffset) {
300
+ ctx.lineDashOffset = lineDashOffset;
301
+ }
302
+ if (lineWidth) {
303
+ ctx.lineWidth = lineWidth;
304
+ }
305
+
306
+ ctx.beginPath();
307
+ ctx.moveTo(-halfWidth, -halfHeight);
308
+ ctx.lineTo(halfWidth, -halfHeight);
309
+ ctx.lineTo(halfWidth, halfHeight);
310
+ ctx.lineTo(-halfWidth, halfHeight);
311
+ ctx.lineTo(-halfWidth, -halfHeight);
312
+ ctx.stroke();
313
+
314
+ ctx.restore();
315
+ },
316
+
317
+ /**
318
+ * onMoving event listener
319
+ * @private
320
+ */
321
+ _onMoving() {
322
+ const { height, width, left, top } = this;
323
+ const maxLeft = this.canvas.getWidth() - width;
324
+ const maxTop = this.canvas.getHeight() - height;
325
+
326
+ this.left = clamp(left, 0, maxLeft);
327
+ this.top = clamp(top, 0, maxTop);
328
+
329
+ this.canvasEventTrigger[events.OBJECT_MOVED](this);
330
+ },
331
+
332
+ /**
333
+ * onScaling event listener
334
+ * @param {{e: MouseEvent}} fEvent - Fabric event
335
+ * @private
336
+ */
337
+ _onScaling(fEvent) {
338
+ const selectedCorner = fEvent.transform.corner;
339
+ const pointer = this.canvas.getPointer(fEvent.e);
340
+ const settings = this._calcScalingSizeFromPointer(pointer, selectedCorner);
341
+
342
+ // On scaling cropzone,
343
+ // change real width and height and fix scaleFactor to 1
344
+ this.scale(1).set(settings);
345
+
346
+ this.canvasEventTrigger[events.OBJECT_SCALED](this);
347
+ },
348
+
349
+ /**
350
+ * Calc scaled size from mouse pointer with selected corner
351
+ * @param {{x: number, y: number}} pointer - Mouse position
352
+ * @param {string} selectedCorner - selected corner type
353
+ * @returns {Object} Having left or(and) top or(and) width or(and) height.
354
+ * @private
355
+ */
356
+ _calcScalingSizeFromPointer(pointer, selectedCorner) {
357
+ const isCornerTypeValid = cornerTypeValid(selectedCorner);
358
+
359
+ return isCornerTypeValid && this._resizeCropZone(pointer, selectedCorner);
360
+ },
361
+
362
+ /**
363
+ * Align with cropzone ratio
364
+ * @param {number} width - cropzone width
365
+ * @param {number} height - cropzone height
366
+ * @param {number} maxWidth - limit max width
367
+ * @param {number} maxHeight - limit max height
368
+ * @param {number} scaleTo - cropzone ratio
369
+ * @returns {{width: number, height: number}}
370
+ * @private
371
+ */
372
+ adjustRatioCropzoneSize({ width, height, leftMaker, topMaker, maxWidth, maxHeight, scaleTo }) {
373
+ width = maxWidth ? clamp(width, 1, maxWidth) : width;
374
+ height = maxHeight ? clamp(height, 1, maxHeight) : height;
375
+
376
+ if (!this.presetRatio) {
377
+ if (this._withShiftKey) {
378
+ // make fixed ratio cropzone
379
+ if (width > height) {
380
+ height = width;
381
+ } else if (height > width) {
382
+ width = height;
383
+ }
384
+ }
385
+
386
+ return {
387
+ width,
388
+ height,
389
+ left: leftMaker(width),
390
+ top: topMaker(height),
391
+ };
392
+ }
393
+
394
+ if (scaleTo === 'width') {
395
+ height = width / this.presetRatio;
396
+ } else {
397
+ width = height * this.presetRatio;
398
+ }
399
+
400
+ const maxScaleFactor = Math.min(maxWidth / width, maxHeight / height);
401
+ if (maxScaleFactor <= 1) {
402
+ [width, height] = [width, height].map((v) => v * maxScaleFactor);
403
+ }
404
+
405
+ return {
406
+ width,
407
+ height,
408
+ left: leftMaker(width),
409
+ top: topMaker(height),
410
+ };
411
+ },
412
+
413
+ /**
414
+ * Get dimension last state cropzone
415
+ * @returns {{rectTop: number, rectLeft: number, rectWidth: number, rectHeight: number}}
416
+ * @private
417
+ */
418
+ _getCropzoneRectInfo() {
419
+ const { width: canvasWidth, height: canvasHeight } = this.canvas;
420
+ const {
421
+ top: rectTop,
422
+ left: rectLeft,
423
+ width: rectWidth,
424
+ height: rectHeight,
425
+ } = this.getBoundingRect(false, true);
426
+
427
+ return {
428
+ rectTop,
429
+ rectLeft,
430
+ rectWidth,
431
+ rectHeight,
432
+ rectRight: rectLeft + rectWidth,
433
+ rectBottom: rectTop + rectHeight,
434
+ canvasWidth,
435
+ canvasHeight,
436
+ };
437
+ },
438
+
439
+ /**
440
+ * Calc scaling dimension
441
+ * @param {Object} position - Mouse position
442
+ * @param {string} corner - corner type
443
+ * @returns {{left: number, top: number, width: number, height: number}}
444
+ * @private
445
+ */
446
+ _resizeCropZone({ x, y }, corner) {
447
+ const {
448
+ rectWidth,
449
+ rectHeight,
450
+ rectTop,
451
+ rectLeft,
452
+ rectBottom,
453
+ rectRight,
454
+ canvasWidth,
455
+ canvasHeight,
456
+ } = this._getCropzoneRectInfo();
457
+
458
+ const resizeInfoMap = {
459
+ tl: {
460
+ width: rectRight - x,
461
+ height: rectBottom - y,
462
+ leftMaker: (newWidth) => rectRight - newWidth,
463
+ topMaker: (newHeight) => rectBottom - newHeight,
464
+ maxWidth: rectRight,
465
+ maxHeight: rectBottom,
466
+ scaleTo: getScaleBasis(rectLeft - x, rectTop - y),
467
+ },
468
+ tr: {
469
+ width: x - rectLeft,
470
+ height: rectBottom - y,
471
+ leftMaker: () => rectLeft,
472
+ topMaker: (newHeight) => rectBottom - newHeight,
473
+ maxWidth: canvasWidth - rectLeft,
474
+ maxHeight: rectBottom,
475
+ scaleTo: getScaleBasis(x - rectRight, rectTop - y),
476
+ },
477
+ mt: {
478
+ width: rectWidth,
479
+ height: rectBottom - y,
480
+ leftMaker: () => rectLeft,
481
+ topMaker: (newHeight) => rectBottom - newHeight,
482
+ maxWidth: canvasWidth - rectLeft,
483
+ maxHeight: rectBottom,
484
+ scaleTo: 'height',
485
+ },
486
+ ml: {
487
+ width: rectRight - x,
488
+ height: rectHeight,
489
+ leftMaker: (newWidth) => rectRight - newWidth,
490
+ topMaker: () => rectTop,
491
+ maxWidth: rectRight,
492
+ maxHeight: canvasHeight - rectTop,
493
+ scaleTo: 'width',
494
+ },
495
+ mr: {
496
+ width: x - rectLeft,
497
+ height: rectHeight,
498
+ leftMaker: () => rectLeft,
499
+ topMaker: () => rectTop,
500
+ maxWidth: canvasWidth - rectLeft,
501
+ maxHeight: canvasHeight - rectTop,
502
+ scaleTo: 'width',
503
+ },
504
+ mb: {
505
+ width: rectWidth,
506
+ height: y - rectTop,
507
+ leftMaker: () => rectLeft,
508
+ topMaker: () => rectTop,
509
+ maxWidth: canvasWidth - rectLeft,
510
+ maxHeight: canvasHeight - rectTop,
511
+ scaleTo: 'height',
512
+ },
513
+ bl: {
514
+ width: rectRight - x,
515
+ height: y - rectTop,
516
+ leftMaker: (newWidth) => rectRight - newWidth,
517
+ topMaker: () => rectTop,
518
+ maxWidth: rectRight,
519
+ maxHeight: canvasHeight - rectTop,
520
+ scaleTo: getScaleBasis(rectLeft - x, y - rectBottom),
521
+ },
522
+ br: {
523
+ width: x - rectLeft,
524
+ height: y - rectTop,
525
+ leftMaker: () => rectLeft,
526
+ topMaker: () => rectTop,
527
+ maxWidth: canvasWidth - rectLeft,
528
+ maxHeight: canvasHeight - rectTop,
529
+ scaleTo: getScaleBasis(x - rectRight, y - rectBottom),
530
+ },
531
+ };
532
+
533
+ return this.adjustRatioCropzoneSize(resizeInfoMap[corner]);
534
+ },
535
+
536
+ /**
537
+ * Return the whether this cropzone is valid
538
+ * @returns {boolean}
539
+ */
540
+ isValid() {
541
+ return this.left >= 0 && this.top >= 0 && this.width > 0 && this.height > 0;
542
+ },
543
+
544
+ /**
545
+ * Keydown event handler
546
+ * @param {{number}} keyCode - Event keyCode
547
+ * @private
548
+ */
549
+ _onKeyDown({ keyCode }) {
550
+ if (keyCode === keyCodes.SHIFT) {
551
+ this._withShiftKey = true;
552
+ }
553
+ },
554
+
555
+ /**
556
+ * Keyup event handler
557
+ * @param {{number}} keyCode - Event keyCode
558
+ * @private
559
+ */
560
+ _onKeyUp({ keyCode }) {
561
+ if (keyCode === keyCodes.SHIFT) {
562
+ this._withShiftKey = false;
563
+ }
564
+ },
565
+ }
566
+ );
567
+
568
+ export default Cropzone;
@@ -0,0 +1,29 @@
1
+ import { fabric } from 'fabric';
2
+
3
+ /**
4
+ * Emboss object
5
+ * @class Emboss
6
+ * @extends {fabric.Image.filters.Convolute}
7
+ * @ignore
8
+ */
9
+ const Emboss = fabric.util.createClass(
10
+ fabric.Image.filters.Convolute,
11
+ /** @lends Convolute.prototype */ {
12
+ /**
13
+ * Filter type
14
+ * @param {String} type
15
+ * @default
16
+ */
17
+ type: 'Emboss',
18
+
19
+ /**
20
+ * constructor
21
+ * @override
22
+ */
23
+ initialize() {
24
+ this.matrix = [1, 1, 1, 1, 0.7, -1, -1, -1, -1];
25
+ },
26
+ }
27
+ );
28
+
29
+ export default Emboss;
@@ -0,0 +1,90 @@
1
+ import { fabric } from 'fabric';
2
+
3
+ /**
4
+ * Mask object
5
+ * @class Mask
6
+ * @extends {fabric.Image.filters.BlendImage}
7
+ * @ignore
8
+ */
9
+ const Mask = fabric.util.createClass(
10
+ fabric.Image.filters.BlendImage,
11
+ /** @lends Mask.prototype */ {
12
+ /**
13
+ * Apply filter to canvas element
14
+ * @param {Object} pipelineState - Canvas element to apply filter
15
+ * @override
16
+ */
17
+ applyTo(pipelineState) {
18
+ if (!this.mask) {
19
+ return;
20
+ }
21
+
22
+ const canvas = pipelineState.canvasEl;
23
+ const { width, height } = canvas;
24
+ const maskCanvasEl = this._createCanvasOfMask(width, height);
25
+ const ctx = canvas.getContext('2d');
26
+ const maskCtx = maskCanvasEl.getContext('2d');
27
+ const imageData = ctx.getImageData(0, 0, width, height);
28
+
29
+ this._drawMask(maskCtx, canvas, ctx);
30
+ this._mapData(maskCtx, imageData, width, height);
31
+
32
+ pipelineState.imageData = imageData;
33
+ },
34
+
35
+ /**
36
+ * Create canvas of mask image
37
+ * @param {number} width - Width of main canvas
38
+ * @param {number} height - Height of main canvas
39
+ * @returns {HTMLElement} Canvas element
40
+ * @private
41
+ */
42
+ _createCanvasOfMask(width, height) {
43
+ const maskCanvasEl = fabric.util.createCanvasElement();
44
+
45
+ maskCanvasEl.width = width;
46
+ maskCanvasEl.height = height;
47
+
48
+ return maskCanvasEl;
49
+ },
50
+
51
+ /**
52
+ * Draw mask image on canvas element
53
+ * @param {Object} maskCtx - Context of mask canvas
54
+ * @private
55
+ */
56
+ _drawMask(maskCtx) {
57
+ const { mask } = this;
58
+ const maskImg = mask.getElement();
59
+ const { angle, left, scaleX, scaleY, top } = mask;
60
+
61
+ maskCtx.save();
62
+ maskCtx.translate(left, top);
63
+ maskCtx.rotate((angle * Math.PI) / 180);
64
+ maskCtx.scale(scaleX, scaleY);
65
+ maskCtx.drawImage(maskImg, -maskImg.width / 2, -maskImg.height / 2);
66
+ maskCtx.restore();
67
+ },
68
+
69
+ /**
70
+ * Map mask image data to source image data
71
+ * @param {Object} maskCtx - Context of mask canvas
72
+ * @param {Object} imageData - Data of source image
73
+ * @param {number} width - Width of main canvas
74
+ * @param {number} height - Height of main canvas
75
+ * @private
76
+ */
77
+ _mapData(maskCtx, imageData, width, height) {
78
+ const { data, height: imgHeight, width: imgWidth } = imageData;
79
+ const sourceData = data;
80
+ const len = imgWidth * imgHeight * 4;
81
+ const maskData = maskCtx.getImageData(0, 0, width, height).data;
82
+
83
+ for (let i = 0; i < len; i += 4) {
84
+ sourceData[i + 3] = maskData[i]; // adjust value of alpha data
85
+ }
86
+ },
87
+ }
88
+ );
89
+
90
+ export default Mask;
@@ -0,0 +1,29 @@
1
+ import { fabric } from 'fabric';
2
+
3
+ /**
4
+ * Sharpen object
5
+ * @class Sharpen
6
+ * @extends {fabric.Image.filters.Convolute}
7
+ * @ignore
8
+ */
9
+ const Sharpen = fabric.util.createClass(
10
+ fabric.Image.filters.Convolute,
11
+ /** @lends Convolute.prototype */ {
12
+ /**
13
+ * Filter type
14
+ * @param {String} type
15
+ * @default
16
+ */
17
+ type: 'Sharpen',
18
+
19
+ /**
20
+ * constructor
21
+ * @override
22
+ */
23
+ initialize() {
24
+ this.matrix = [0, -1, 0, -1, 5, -1, 0, -1, 0];
25
+ },
26
+ }
27
+ );
28
+
29
+ export default Sharpen;