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
package/src/js/util.js ADDED
@@ -0,0 +1,551 @@
1
+ import isUndefined from 'tui-code-snippet/type/isUndefined';
2
+ import forEach from 'tui-code-snippet/collection/forEach';
3
+ import sendHostname from 'tui-code-snippet/request/sendHostname';
4
+ import extend from 'tui-code-snippet/object/extend';
5
+ import isString from 'tui-code-snippet/type/isString';
6
+ import pick from 'tui-code-snippet/object/pick';
7
+ import inArray from 'tui-code-snippet/array/inArray';
8
+ import {
9
+ commandNames,
10
+ filterType,
11
+ historyNames,
12
+ SHAPE_FILL_TYPE,
13
+ SHAPE_TYPE,
14
+ emptyCropRectValues,
15
+ } from '@/consts';
16
+
17
+ const FLOATING_POINT_DIGIT = 2;
18
+ const CSS_PREFIX = 'tui-image-editor-';
19
+ const { min, max } = Math;
20
+ let hostnameSent = false;
21
+ let lastId = 0;
22
+
23
+ export function stamp(obj) {
24
+ if (!obj.__fe_id) {
25
+ lastId += 1;
26
+ // eslint-disable-next-line camelcase
27
+ obj.__fe_id = lastId;
28
+ }
29
+
30
+ return obj.__fe_id;
31
+ }
32
+
33
+ export function hasStamp(obj) {
34
+ return !isNil(obj?.__fe_id);
35
+ }
36
+
37
+ export function isNil(value) {
38
+ return isUndefined(value) || value === null;
39
+ }
40
+
41
+ export function isFunction(value) {
42
+ return typeof value === 'function';
43
+ }
44
+
45
+ /**
46
+ * Clamp value
47
+ * @param {number} value - Value
48
+ * @param {number} minValue - Minimum value
49
+ * @param {number} maxValue - Maximum value
50
+ * @returns {number} clamped value
51
+ */
52
+ export function clamp(value, minValue, maxValue) {
53
+ if (minValue > maxValue) {
54
+ [minValue, maxValue] = [maxValue, minValue];
55
+ }
56
+
57
+ return max(minValue, min(value, maxValue));
58
+ }
59
+
60
+ /**
61
+ * Make key-value object from arguments
62
+ * @returns {object.<string, string>}
63
+ */
64
+ export function keyMirror(...args) {
65
+ const obj = {};
66
+
67
+ forEach(args, (key) => {
68
+ obj[key] = key;
69
+ });
70
+
71
+ return obj;
72
+ }
73
+
74
+ /**
75
+ * Make CSSText
76
+ * @param {Object} styleObj - Style info object
77
+ * @returns {string} Connected string of style
78
+ */
79
+ export function makeStyleText(styleObj) {
80
+ let styleStr = '';
81
+
82
+ forEach(styleObj, (value, prop) => {
83
+ styleStr += `${prop}: ${value};`;
84
+ });
85
+
86
+ return styleStr;
87
+ }
88
+
89
+ /**
90
+ * Get object's properties
91
+ * @param {Object} obj - object
92
+ * @param {Array} keys - keys
93
+ * @returns {Object} properties object
94
+ */
95
+ export function getProperties(obj, keys) {
96
+ const props = {};
97
+ const { length } = keys;
98
+ let i = 0;
99
+ let key;
100
+
101
+ for (i = 0; i < length; i += 1) {
102
+ key = keys[i];
103
+ props[key] = obj[key];
104
+ }
105
+
106
+ return props;
107
+ }
108
+
109
+ /**
110
+ * ParseInt simpliment
111
+ * @param {number} value - Value
112
+ * @returns {number}
113
+ */
114
+ export function toInteger(value) {
115
+ return parseInt(value, 10);
116
+ }
117
+
118
+ /**
119
+ * String to camelcase string
120
+ * @param {string} targetString - change target
121
+ * @returns {string}
122
+ * @private
123
+ */
124
+ export function toCamelCase(targetString) {
125
+ return targetString.replace(/-([a-z])/g, ($0, $1) => $1.toUpperCase());
126
+ }
127
+
128
+ /**
129
+ * Check browser file api support
130
+ * @returns {boolean}
131
+ * @private
132
+ */
133
+ export function isSupportFileApi() {
134
+ return !!(window.File && window.FileList && window.FileReader);
135
+ }
136
+
137
+ /**
138
+ * hex to rgb
139
+ * @param {string} color - hex color
140
+ * @param {string} alpha - color alpha value
141
+ * @returns {string} rgb expression
142
+ */
143
+ export function getRgb(color, alpha) {
144
+ if (color.length === 4) {
145
+ color = `${color}${color.slice(1, 4)}`;
146
+ }
147
+ const r = parseInt(color.slice(1, 3), 16);
148
+ const g = parseInt(color.slice(3, 5), 16);
149
+ const b = parseInt(color.slice(5, 7), 16);
150
+ const a = alpha || 1;
151
+
152
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
153
+ }
154
+
155
+ /**
156
+ * send hostname
157
+ */
158
+ export function sendHostName() {
159
+ if (hostnameSent) {
160
+ return;
161
+ }
162
+ hostnameSent = true;
163
+
164
+ sendHostname('image-editor', 'UA-129999381-1');
165
+ }
166
+
167
+ /**
168
+ * Apply css resource
169
+ * @param {string} styleBuffer - serialized css text
170
+ * @param {string} tagId - style tag id
171
+ */
172
+ export function styleLoad(styleBuffer, tagId) {
173
+ const [head] = document.getElementsByTagName('head');
174
+ const linkElement = document.createElement('link');
175
+ const styleData = encodeURIComponent(styleBuffer);
176
+ if (tagId) {
177
+ linkElement.id = tagId;
178
+ // linkElement.id = 'tui-image-editor-theme-style';
179
+ }
180
+ linkElement.setAttribute('rel', 'stylesheet');
181
+ linkElement.setAttribute('type', 'text/css');
182
+ linkElement.setAttribute('href', `data:text/css;charset=UTF-8,${styleData}`);
183
+ head.appendChild(linkElement);
184
+ }
185
+
186
+ /**
187
+ * Get selector
188
+ * @param {HTMLElement} targetElement - target element
189
+ * @returns {Function} selector
190
+ */
191
+ export function getSelector(targetElement) {
192
+ return (str) => targetElement.querySelector(str);
193
+ }
194
+
195
+ /**
196
+ * Change base64 to blob
197
+ * @param {String} data - base64 string data
198
+ * @returns {Blob} Blob Data
199
+ */
200
+ export function base64ToBlob(data) {
201
+ const rImageType = /data:(image\/.+);base64,/;
202
+ let mimeString = '';
203
+ let raw, uInt8Array, i;
204
+
205
+ raw = data.replace(rImageType, (header, imageType) => {
206
+ mimeString = imageType;
207
+
208
+ return '';
209
+ });
210
+
211
+ raw = atob(raw);
212
+ const rawLength = raw.length;
213
+ uInt8Array = new Uint8Array(rawLength); // eslint-disable-line
214
+
215
+ for (i = 0; i < rawLength; i += 1) {
216
+ uInt8Array[i] = raw.charCodeAt(i);
217
+ }
218
+
219
+ return new Blob([uInt8Array], { type: mimeString });
220
+ }
221
+
222
+ /**
223
+ * Fix floating point diff.
224
+ * @param {number} value - original value
225
+ * @returns {number} fixed value
226
+ */
227
+ export function fixFloatingPoint(value) {
228
+ return Number(value.toFixed(FLOATING_POINT_DIGIT));
229
+ }
230
+
231
+ /**
232
+ * Assignment for destroying objects.
233
+ * @param {Object} targetObject - object to be removed.
234
+ */
235
+ export function assignmentForDestroy(targetObject) {
236
+ forEach(targetObject, (value, key) => {
237
+ targetObject[key] = null;
238
+ });
239
+ }
240
+
241
+ /**
242
+ * Make class name for ui
243
+ * @param {String} str - main string of className
244
+ * @param {String} prefix - prefix string of className
245
+ * @returns {String} class name
246
+ */
247
+ export function cls(str = '', prefix = '') {
248
+ if (str.charAt(0) === '.') {
249
+ return `.${CSS_PREFIX}${prefix}${str.slice(1)}`;
250
+ }
251
+
252
+ return `${CSS_PREFIX}${prefix}${str}`;
253
+ }
254
+
255
+ /**
256
+ * Change object origin
257
+ * @param {fabric.Object} fObject - fabric object
258
+ * @param {Object} origin - origin of fabric object
259
+ * @param {string} originX - horizontal basis.
260
+ * @param {string} originY - vertical basis.
261
+ */
262
+ export function changeOrigin(fObject, origin) {
263
+ const { originX, originY } = origin;
264
+ const { x: left, y: top } = fObject.getPointByOrigin(originX, originY);
265
+
266
+ fObject.set({
267
+ left,
268
+ top,
269
+ originX,
270
+ originY,
271
+ });
272
+
273
+ fObject.setCoords();
274
+ }
275
+
276
+ /**
277
+ * Object key value flip
278
+ * @param {Object} targetObject - The data object of the key value.
279
+ * @returns {Object}
280
+ */
281
+ export function flipObject(targetObject) {
282
+ const result = {};
283
+
284
+ Object.keys(targetObject).forEach((key) => {
285
+ result[targetObject[key]] = key;
286
+ });
287
+
288
+ return result;
289
+ }
290
+
291
+ /**
292
+ * Set custom properties
293
+ * @param {Object} targetObject - target object
294
+ * @param {Object} props - custom props object
295
+ */
296
+ export function setCustomProperty(targetObject, props) {
297
+ targetObject.customProps = targetObject.customProps || {};
298
+ extend(targetObject.customProps, props);
299
+ }
300
+
301
+ /**
302
+ * Get custom property
303
+ * @param {fabric.Object} fObject - fabric object
304
+ * @param {Array|string} propNames - prop name array
305
+ * @returns {object | number | string}
306
+ */
307
+ export function getCustomProperty(fObject, propNames) {
308
+ const resultObject = {};
309
+ if (isString(propNames)) {
310
+ propNames = [propNames];
311
+ }
312
+ forEach(propNames, (propName) => {
313
+ resultObject[propName] = fObject.customProps[propName];
314
+ });
315
+
316
+ return resultObject;
317
+ }
318
+
319
+ /**
320
+ * Capitalize string
321
+ * @param {string} targetString - target string
322
+ * @returns {string}
323
+ */
324
+ export function capitalizeString(targetString) {
325
+ return targetString.charAt(0).toUpperCase() + targetString.slice(1);
326
+ }
327
+
328
+ /**
329
+ * Array includes check
330
+ * @param {Array} targetArray - target array
331
+ * @param {string|number} compareValue - compare value
332
+ * @returns {boolean}
333
+ */
334
+ export function includes(targetArray, compareValue) {
335
+ return targetArray.indexOf(compareValue) >= 0;
336
+ }
337
+
338
+ /**
339
+ * Get fill type
340
+ * @param {Object | string} fillOption - shape fill option
341
+ * @returns {string} 'color' or 'filter'
342
+ */
343
+ export function getFillTypeFromOption(fillOption = {}) {
344
+ return pick(fillOption, 'type') || SHAPE_FILL_TYPE.COLOR;
345
+ }
346
+
347
+ /**
348
+ * Get fill type of shape type object
349
+ * @param {fabric.Object} shapeObj - fabric object
350
+ * @returns {string} 'transparent' or 'color' or 'filter'
351
+ */
352
+ export function getFillTypeFromObject(shapeObj) {
353
+ const { fill = {} } = shapeObj;
354
+ if (fill.source) {
355
+ return SHAPE_FILL_TYPE.FILTER;
356
+ }
357
+
358
+ return SHAPE_FILL_TYPE.COLOR;
359
+ }
360
+
361
+ /**
362
+ * Check if the object is a shape object.
363
+ * @param {fabric.Object} obj - fabric object
364
+ * @returns {boolean}
365
+ */
366
+ export function isShape(obj) {
367
+ return inArray(obj.get('type'), SHAPE_TYPE) >= 0;
368
+ }
369
+
370
+ /**
371
+ * Get object type
372
+ * @param {string} type - fabric object type
373
+ * @returns {string} type of object (ex: shape, icon, ...)
374
+ */
375
+ export function getObjectType(type) {
376
+ if (includes(SHAPE_TYPE, type)) {
377
+ return 'Shape';
378
+ }
379
+
380
+ switch (type) {
381
+ case 'i-text':
382
+ return 'Text';
383
+ case 'path':
384
+ case 'line':
385
+ return 'Draw';
386
+ case 'activeSelection':
387
+ return 'Group';
388
+ default:
389
+ return toStartOfCapital(type);
390
+ }
391
+ }
392
+
393
+ /**
394
+ * Get filter type
395
+ * @param {string} type - fabric filter type
396
+ * @param {object} [options] - filter type options
397
+ * @param {boolean} [options.useAlpha=true] - usage of alpha(true is 'color filter', false is 'remove white')
398
+ * @param {string} [options.mode] - mode of blendColor
399
+ * @returns {string} type of filter (ex: sepia, blur, ...)
400
+ */
401
+ function getFilterType(type, { useAlpha = true, mode } = {}) {
402
+ const { VINTAGE, REMOVE_COLOR, BLEND_COLOR, SEPIA2, COLOR_FILTER, REMOVE_WHITE, BLEND } =
403
+ filterType;
404
+
405
+ let filterName;
406
+
407
+ switch (type) {
408
+ case VINTAGE:
409
+ filterName = SEPIA2;
410
+ break;
411
+ case REMOVE_COLOR:
412
+ filterName = useAlpha ? COLOR_FILTER : REMOVE_WHITE;
413
+ break;
414
+ case BLEND_COLOR:
415
+ filterName = mode === 'add' ? BLEND : mode;
416
+ break;
417
+ default:
418
+ filterName = type;
419
+ }
420
+
421
+ return toStartOfCapital(filterName);
422
+ }
423
+
424
+ /**
425
+ * Check if command is silent command
426
+ * @param {Command|string} command - command or command name
427
+ * @returns {boolean}
428
+ */
429
+ export function isSilentCommand(command) {
430
+ const { LOAD_IMAGE } = commandNames;
431
+
432
+ return typeof command === 'string' ? LOAD_IMAGE === command : LOAD_IMAGE === command.name;
433
+ }
434
+
435
+ /**
436
+ * Get command name
437
+ * @param {Command|string} command - command or command name
438
+ * @returns {{name: string, ?detail: string}}
439
+ */
440
+ // eslint-disable-next-line complexity, require-jsdoc
441
+ export function getHistoryTitle(command) {
442
+ const {
443
+ FLIP_IMAGE,
444
+ ROTATE_IMAGE,
445
+ ADD_TEXT,
446
+ APPLY_FILTER,
447
+ REMOVE_FILTER,
448
+ CHANGE_SHAPE,
449
+ CHANGE_ICON_COLOR,
450
+ CHANGE_TEXT_STYLE,
451
+ CLEAR_OBJECTS,
452
+ ADD_IMAGE_OBJECT,
453
+ REMOVE_OBJECT,
454
+ RESIZE_IMAGE,
455
+ } = commandNames;
456
+ const { name, args } = command;
457
+ let historyInfo;
458
+
459
+ switch (name) {
460
+ case FLIP_IMAGE:
461
+ historyInfo = { name, detail: args[1] === 'reset' ? args[1] : args[1].slice(4) };
462
+ break;
463
+ case ROTATE_IMAGE:
464
+ historyInfo = { name, detail: args[2] };
465
+ break;
466
+ case APPLY_FILTER:
467
+ historyInfo = { name: historyNames.APPLY_FILTER, detail: getFilterType(args[1], args[2]) };
468
+ break;
469
+ case REMOVE_FILTER:
470
+ historyInfo = { name: historyNames.REMOVE_FILTER, detail: 'Remove' };
471
+ break;
472
+ case CHANGE_SHAPE:
473
+ historyInfo = { name: historyNames.CHANGE_SHAPE, detail: 'Change' };
474
+ break;
475
+ case CHANGE_ICON_COLOR:
476
+ historyInfo = { name: historyNames.CHANGE_ICON_COLOR, detail: 'Change' };
477
+ break;
478
+ case CHANGE_TEXT_STYLE:
479
+ historyInfo = { name: historyNames.CHANGE_TEXT_STYLE, detail: 'Change' };
480
+ break;
481
+ case REMOVE_OBJECT:
482
+ historyInfo = { name: historyNames.REMOVE_OBJECT, detail: args[2] };
483
+ break;
484
+ case CLEAR_OBJECTS:
485
+ historyInfo = { name: historyNames.CLEAR_OBJECTS, detail: 'All' };
486
+ break;
487
+ case ADD_IMAGE_OBJECT:
488
+ historyInfo = { name: historyNames.ADD_IMAGE_OBJECT, detail: 'Add' };
489
+ break;
490
+ case ADD_TEXT:
491
+ historyInfo = { name: historyNames.ADD_TEXT };
492
+ break;
493
+ case RESIZE_IMAGE:
494
+ historyInfo = { name: historyNames.RESIZE, detail: `${~~args[1].width}x${~~args[1].height}` };
495
+ break;
496
+
497
+ default:
498
+ historyInfo = { name };
499
+ break;
500
+ }
501
+
502
+ if (args[1] === 'mask') {
503
+ historyInfo = { name: historyNames.LOAD_MASK_IMAGE, detail: 'Apply' };
504
+ }
505
+
506
+ return historyInfo;
507
+ }
508
+
509
+ /**
510
+ * Get help menubar position(opposite of menubar)
511
+ * @param {string} position - position of menubar
512
+ * @returns {string} position of help menubar
513
+ */
514
+ export function getHelpMenuBarPosition(position) {
515
+ if (position === 'top') {
516
+ return 'bottom';
517
+ }
518
+ if (position === 'left') {
519
+ return 'right';
520
+ }
521
+ if (position === 'right') {
522
+ return 'left';
523
+ }
524
+
525
+ return 'top';
526
+ }
527
+
528
+ /**
529
+ * Change to capital start letter
530
+ * @param {string} str - string to change
531
+ * @returns {string}
532
+ */
533
+ function toStartOfCapital(str) {
534
+ return str.replace(/[a-z]/, (first) => first.toUpperCase());
535
+ }
536
+
537
+ /**
538
+ * Check if cropRect is Empty.
539
+ * @param {Object} cropRect - cropRect object
540
+ * @param {Number} cropRect.left - cropRect left position value
541
+ * @param {Number} cropRect.top - cropRect top position value
542
+ * @param {Number} cropRect.width - cropRect width value
543
+ * @param {Number} cropRect.height - cropRect height value
544
+ * @returns {boolean}
545
+ */
546
+ export function isEmptyCropzone(cropRect) {
547
+ const { left, top, width, height } = cropRect;
548
+ const { LEFT, TOP, WIDTH, HEIGHT } = emptyCropRectValues;
549
+
550
+ return left === LEFT && top === TOP && width === WIDTH && height === HEIGHT;
551
+ }