@ntlab/ntjs-assets 2.0.2 → 2.0.4

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 (241) hide show
  1. package/assets/js/bootstrap-icons/bootstrap-icons.svg +1 -1
  2. package/assets/js/bootstrap-icons/folder-plus.svg +2 -2
  3. package/assets/js/bootstrap-icons/font/bootstrap-icons.css +1981 -0
  4. package/assets/js/bootstrap-icons/font/bootstrap-icons.json +1955 -0
  5. package/assets/js/bootstrap-icons/font/bootstrap-icons.min.css +5 -0
  6. package/assets/js/bootstrap-icons/font/bootstrap-icons.scss +1993 -0
  7. package/assets/js/bootstrap-icons/font/fonts/bootstrap-icons.woff +0 -0
  8. package/assets/js/bootstrap-icons/font/fonts/bootstrap-icons.woff2 +0 -0
  9. package/assets/js/bootstrap-icons/postcard-heart-fill.svg +1 -1
  10. package/assets/js/bootstrap-icons/trash.svg +2 -2
  11. package/assets/js/cropper/cropper.common.js +3253 -0
  12. package/assets/js/cropper/cropper.css +166 -236
  13. package/assets/js/cropper/cropper.esm.js +3251 -0
  14. package/assets/js/cropper/cropper.js +2499 -2237
  15. package/assets/js/cropper/cropper.min.css +5 -5
  16. package/assets/js/cropper/cropper.min.js +5 -5
  17. package/assets/js/jquery/jquery.js +840 -1045
  18. package/assets/js/jquery/jquery.min.js +2 -2
  19. package/assets/js/jquery/jquery.min.map +1 -1
  20. package/assets/js/jquery/jquery.slim.js +834 -1039
  21. package/assets/js/jquery/jquery.slim.min.js +2 -2
  22. package/assets/js/jquery/jquery.slim.min.map +1 -1
  23. package/assets/js/popper.js/cjs/enums.js +1 -1
  24. package/assets/js/popper.js/cjs/popper-base.js +12 -170
  25. package/assets/js/popper.js/cjs/popper-base.js.map +1 -1
  26. package/assets/js/popper.js/cjs/popper-lite.js +14 -184
  27. package/assets/js/popper.js/cjs/popper-lite.js.map +1 -1
  28. package/assets/js/popper.js/cjs/popper.js +14 -197
  29. package/assets/js/popper.js/cjs/popper.js.map +1 -1
  30. package/assets/js/popper.js/esm/createPopper.js +6 -66
  31. package/assets/js/popper.js/esm/modifiers/arrow.js +1 -12
  32. package/assets/js/popper.js/esm/modifiers/computeStyles.js +2 -14
  33. package/assets/js/popper.js/esm/utils/computeAutoPlacement.js +0 -4
  34. package/assets/js/popper.js/esm/utils/userAgent.js +1 -1
  35. package/assets/js/popper.js/umd/enums.js +1 -1
  36. package/assets/js/popper.js/umd/enums.min.js +1 -1
  37. package/assets/js/popper.js/umd/popper-base.js +12 -170
  38. package/assets/js/popper.js/umd/popper-base.js.map +1 -1
  39. package/assets/js/popper.js/umd/popper-base.min.js +2 -2
  40. package/assets/js/popper.js/umd/popper-base.min.js.map +1 -1
  41. package/assets/js/popper.js/umd/popper-lite.js +14 -184
  42. package/assets/js/popper.js/umd/popper-lite.js.map +1 -1
  43. package/assets/js/popper.js/umd/popper-lite.min.js +2 -2
  44. package/assets/js/popper.js/umd/popper-lite.min.js.map +1 -1
  45. package/assets/js/popper.js/umd/popper.js +14 -197
  46. package/assets/js/popper.js/umd/popper.js.map +1 -1
  47. package/assets/js/popper.js/umd/popper.min.js +2 -2
  48. package/assets/js/popper.js/umd/popper.min.js.map +1 -1
  49. package/assets/js/semantic-ui/components/accordion.css +196 -74
  50. package/assets/js/semantic-ui/components/accordion.js +570 -591
  51. package/assets/js/semantic-ui/components/accordion.min.css +4 -4
  52. package/assets/js/semantic-ui/components/accordion.min.js +6 -6
  53. package/assets/js/semantic-ui/components/ad.css +40 -51
  54. package/assets/js/semantic-ui/components/ad.min.css +4 -4
  55. package/assets/js/semantic-ui/components/api.js +1154 -1117
  56. package/assets/js/semantic-ui/components/api.min.js +6 -6
  57. package/assets/js/semantic-ui/components/breadcrumb.css +7 -7
  58. package/assets/js/semantic-ui/components/breadcrumb.min.css +4 -4
  59. package/assets/js/semantic-ui/components/button.css +895 -1227
  60. package/assets/js/semantic-ui/components/button.min.css +4 -4
  61. package/assets/js/semantic-ui/components/calendar.css +60 -33
  62. package/assets/js/semantic-ui/components/calendar.js +1952 -1575
  63. package/assets/js/semantic-ui/components/calendar.min.css +4 -4
  64. package/assets/js/semantic-ui/components/calendar.min.js +6 -6
  65. package/assets/js/semantic-ui/components/card.css +1004 -441
  66. package/assets/js/semantic-ui/components/card.min.css +4 -4
  67. package/assets/js/semantic-ui/components/checkbox.css +275 -303
  68. package/assets/js/semantic-ui/components/checkbox.js +863 -855
  69. package/assets/js/semantic-ui/components/checkbox.min.css +4 -4
  70. package/assets/js/semantic-ui/components/checkbox.min.js +6 -6
  71. package/assets/js/semantic-ui/components/comment.css +45 -63
  72. package/assets/js/semantic-ui/components/comment.min.css +4 -4
  73. package/assets/js/semantic-ui/components/container.css +98 -4
  74. package/assets/js/semantic-ui/components/container.min.css +4 -4
  75. package/assets/js/semantic-ui/components/dimmer.css +95 -196
  76. package/assets/js/semantic-ui/components/dimmer.js +698 -717
  77. package/assets/js/semantic-ui/components/dimmer.min.css +4 -4
  78. package/assets/js/semantic-ui/components/dimmer.min.js +6 -6
  79. package/assets/js/semantic-ui/components/divider.css +75 -93
  80. package/assets/js/semantic-ui/components/divider.min.css +4 -4
  81. package/assets/js/semantic-ui/components/dropdown.css +490 -413
  82. package/assets/js/semantic-ui/components/dropdown.js +4203 -4068
  83. package/assets/js/semantic-ui/components/dropdown.min.css +4 -4
  84. package/assets/js/semantic-ui/components/dropdown.min.js +6 -6
  85. package/assets/js/semantic-ui/components/embed.css +27 -38
  86. package/assets/js/semantic-ui/components/embed.js +647 -673
  87. package/assets/js/semantic-ui/components/embed.min.css +4 -4
  88. package/assets/js/semantic-ui/components/embed.min.js +6 -6
  89. package/assets/js/semantic-ui/components/emoji.css +11156 -9192
  90. package/assets/js/semantic-ui/components/emoji.min.css +3 -3
  91. package/assets/js/semantic-ui/components/feed.css +56 -78
  92. package/assets/js/semantic-ui/components/feed.min.css +4 -4
  93. package/assets/js/semantic-ui/components/flag.css +1037 -929
  94. package/assets/js/semantic-ui/components/flag.min.css +4 -4
  95. package/assets/js/semantic-ui/components/flyout.css +552 -0
  96. package/assets/js/semantic-ui/components/flyout.js +1567 -0
  97. package/assets/js/semantic-ui/components/flyout.min.css +9 -0
  98. package/assets/js/semantic-ui/components/flyout.min.js +11 -0
  99. package/assets/js/semantic-ui/components/form.css +536 -530
  100. package/assets/js/semantic-ui/components/form.js +2037 -1945
  101. package/assets/js/semantic-ui/components/form.min.css +4 -4
  102. package/assets/js/semantic-ui/components/form.min.js +6 -6
  103. package/assets/js/semantic-ui/components/grid.css +218 -345
  104. package/assets/js/semantic-ui/components/grid.min.css +4 -4
  105. package/assets/js/semantic-ui/components/header.css +137 -154
  106. package/assets/js/semantic-ui/components/header.min.css +4 -4
  107. package/assets/js/semantic-ui/components/icon.css +3000 -2750
  108. package/assets/js/semantic-ui/components/icon.min.css +4 -4
  109. package/assets/js/semantic-ui/components/image.css +54 -49
  110. package/assets/js/semantic-ui/components/image.min.css +4 -4
  111. package/assets/js/semantic-ui/components/input.css +1081 -227
  112. package/assets/js/semantic-ui/components/input.min.css +4 -4
  113. package/assets/js/semantic-ui/components/item.css +91 -138
  114. package/assets/js/semantic-ui/components/item.min.css +4 -4
  115. package/assets/js/semantic-ui/components/label.css +470 -481
  116. package/assets/js/semantic-ui/components/label.min.css +4 -4
  117. package/assets/js/semantic-ui/components/list.css +93 -114
  118. package/assets/js/semantic-ui/components/list.min.css +4 -4
  119. package/assets/js/semantic-ui/components/loader.css +452 -536
  120. package/assets/js/semantic-ui/components/loader.min.css +4 -4
  121. package/assets/js/semantic-ui/components/menu.css +408 -510
  122. package/assets/js/semantic-ui/components/menu.min.css +9 -1
  123. package/assets/js/semantic-ui/components/message.css +188 -213
  124. package/assets/js/semantic-ui/components/message.min.css +4 -4
  125. package/assets/js/semantic-ui/components/modal.css +174 -166
  126. package/assets/js/semantic-ui/components/modal.js +1558 -1146
  127. package/assets/js/semantic-ui/components/modal.min.css +4 -4
  128. package/assets/js/semantic-ui/components/modal.min.js +6 -6
  129. package/assets/js/semantic-ui/components/nag.css +183 -41
  130. package/assets/js/semantic-ui/components/nag.js +527 -467
  131. package/assets/js/semantic-ui/components/nag.min.css +4 -4
  132. package/assets/js/semantic-ui/components/nag.min.js +6 -6
  133. package/assets/js/semantic-ui/components/placeholder.css +62 -76
  134. package/assets/js/semantic-ui/components/placeholder.min.css +4 -4
  135. package/assets/js/semantic-ui/components/popup.css +681 -312
  136. package/assets/js/semantic-ui/components/popup.js +1470 -1463
  137. package/assets/js/semantic-ui/components/popup.min.css +4 -4
  138. package/assets/js/semantic-ui/components/popup.min.js +6 -6
  139. package/assets/js/semantic-ui/components/progress.css +149 -217
  140. package/assets/js/semantic-ui/components/progress.js +945 -1002
  141. package/assets/js/semantic-ui/components/progress.min.css +4 -4
  142. package/assets/js/semantic-ui/components/progress.min.js +6 -6
  143. package/assets/js/semantic-ui/components/rail.css +17 -22
  144. package/assets/js/semantic-ui/components/rail.min.css +3 -3
  145. package/assets/js/semantic-ui/components/rating.css +89 -184
  146. package/assets/js/semantic-ui/components/rating.js +509 -521
  147. package/assets/js/semantic-ui/components/rating.min.css +4 -4
  148. package/assets/js/semantic-ui/components/rating.min.js +6 -6
  149. package/assets/js/semantic-ui/components/reset.css +12 -17
  150. package/assets/js/semantic-ui/components/reset.min.css +4 -4
  151. package/assets/js/semantic-ui/components/reveal.css +46 -85
  152. package/assets/js/semantic-ui/components/reveal.min.css +4 -4
  153. package/assets/js/semantic-ui/components/search.css +157 -96
  154. package/assets/js/semantic-ui/components/search.js +1522 -1479
  155. package/assets/js/semantic-ui/components/search.min.css +4 -4
  156. package/assets/js/semantic-ui/components/search.min.js +6 -6
  157. package/assets/js/semantic-ui/components/segment.css +317 -249
  158. package/assets/js/semantic-ui/components/segment.min.css +4 -4
  159. package/assets/js/semantic-ui/components/shape.css +16 -32
  160. package/assets/js/semantic-ui/components/shape.js +763 -812
  161. package/assets/js/semantic-ui/components/shape.min.css +4 -4
  162. package/assets/js/semantic-ui/components/shape.min.js +6 -6
  163. package/assets/js/semantic-ui/components/sidebar.css +128 -216
  164. package/assets/js/semantic-ui/components/sidebar.js +1042 -1003
  165. package/assets/js/semantic-ui/components/sidebar.min.css +4 -4
  166. package/assets/js/semantic-ui/components/sidebar.min.js +6 -6
  167. package/assets/js/semantic-ui/components/site.css +123 -48
  168. package/assets/js/semantic-ui/components/site.js +438 -478
  169. package/assets/js/semantic-ui/components/site.min.css +4 -4
  170. package/assets/js/semantic-ui/components/site.min.js +6 -6
  171. package/assets/js/semantic-ui/components/slider.css +133 -141
  172. package/assets/js/semantic-ui/components/slider.js +1312 -1274
  173. package/assets/js/semantic-ui/components/slider.min.css +9 -1
  174. package/assets/js/semantic-ui/components/slider.min.js +6 -6
  175. package/assets/js/semantic-ui/components/state.js +640 -659
  176. package/assets/js/semantic-ui/components/state.min.js +6 -6
  177. package/assets/js/semantic-ui/components/statistic.css +83 -124
  178. package/assets/js/semantic-ui/components/statistic.min.css +4 -4
  179. package/assets/js/semantic-ui/components/step.css +118 -184
  180. package/assets/js/semantic-ui/components/step.min.css +4 -4
  181. package/assets/js/semantic-ui/components/sticky.css +3 -8
  182. package/assets/js/semantic-ui/components/sticky.js +849 -892
  183. package/assets/js/semantic-ui/components/sticky.min.css +4 -4
  184. package/assets/js/semantic-ui/components/sticky.min.js +6 -6
  185. package/assets/js/semantic-ui/components/tab.css +16 -20
  186. package/assets/js/semantic-ui/components/tab.js +896 -941
  187. package/assets/js/semantic-ui/components/tab.min.css +4 -4
  188. package/assets/js/semantic-ui/components/tab.min.js +6 -6
  189. package/assets/js/semantic-ui/components/table.css +2073 -884
  190. package/assets/js/semantic-ui/components/table.min.css +4 -4
  191. package/assets/js/semantic-ui/components/text.css +51 -30
  192. package/assets/js/semantic-ui/components/text.min.css +4 -4
  193. package/assets/js/semantic-ui/components/toast.css +200 -137
  194. package/assets/js/semantic-ui/components/toast.js +912 -832
  195. package/assets/js/semantic-ui/components/toast.min.css +4 -4
  196. package/assets/js/semantic-ui/components/toast.min.js +6 -6
  197. package/assets/js/semantic-ui/components/transition.css +371 -1282
  198. package/assets/js/semantic-ui/components/transition.js +999 -1074
  199. package/assets/js/semantic-ui/components/transition.min.css +4 -4
  200. package/assets/js/semantic-ui/components/transition.min.js +6 -6
  201. package/assets/js/semantic-ui/components/visibility.js +1215 -1247
  202. package/assets/js/semantic-ui/components/visibility.min.js +6 -6
  203. package/assets/js/semantic-ui/semantic.css +43777 -37429
  204. package/assets/js/semantic-ui/semantic.js +29152 -26694
  205. package/assets/js/semantic-ui/semantic.min.css +6 -399
  206. package/assets/js/semantic-ui/semantic.min.js +6 -6
  207. package/assets/js/semantic-ui/themes/basic/assets/fonts/icons.woff2 +0 -0
  208. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Bold.woff +0 -0
  209. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Bold.woff2 +0 -0
  210. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-BoldItalic.woff +0 -0
  211. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-BoldItalic.woff2 +0 -0
  212. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Italic.woff +0 -0
  213. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Italic.woff2 +0 -0
  214. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Regular.woff +0 -0
  215. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Regular.woff2 +0 -0
  216. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Bold.woff +0 -0
  217. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Bold.woff2 +0 -0
  218. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-BoldItalic.woff +0 -0
  219. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-BoldItalic.woff2 +0 -0
  220. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Italic.woff +0 -0
  221. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Italic.woff2 +0 -0
  222. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Regular.woff +0 -0
  223. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Regular.woff2 +0 -0
  224. package/assets/js/semantic-ui/themes/default/assets/fonts/brand-icons.woff +0 -0
  225. package/assets/js/semantic-ui/themes/default/assets/fonts/brand-icons.woff2 +0 -0
  226. package/assets/js/semantic-ui/themes/default/assets/fonts/icons.woff +0 -0
  227. package/assets/js/semantic-ui/themes/default/assets/fonts/icons.woff2 +0 -0
  228. package/assets/js/semantic-ui/themes/default/assets/fonts/outline-icons.woff +0 -0
  229. package/assets/js/semantic-ui/themes/default/assets/fonts/outline-icons.woff2 +0 -0
  230. package/assets/js/semantic-ui/themes/famfamfam/assets/images/flags.png +0 -0
  231. package/assets/js/semantic-ui/themes/github/assets/fonts/octicons.woff2 +0 -0
  232. package/assets/js/socket.io/socket.io.esm.min.js +3 -3
  233. package/assets/js/socket.io/socket.io.esm.min.js.map +1 -1
  234. package/assets/js/socket.io/socket.io.js +988 -1143
  235. package/assets/js/socket.io/socket.io.js.map +1 -1
  236. package/assets/js/socket.io/socket.io.min.js +3 -3
  237. package/assets/js/socket.io/socket.io.min.js.map +1 -1
  238. package/assets/js/socket.io/socket.io.msgpack.min.js +3 -3
  239. package/assets/js/socket.io/socket.io.msgpack.min.js.map +1 -1
  240. package/cdn.json +19 -4
  241. package/package.json +1 -1
@@ -0,0 +1,3251 @@
1
+ /*!
2
+ * Cropper.js v1.5.13
3
+ * https://fengyuanchen.github.io/cropperjs
4
+ *
5
+ * Copyright 2015-present Chen Fengyuan
6
+ * Released under the MIT license
7
+ *
8
+ * Date: 2022-11-20T05:30:46.114Z
9
+ */
10
+
11
+ function ownKeys(object, enumerableOnly) {
12
+ var keys = Object.keys(object);
13
+ if (Object.getOwnPropertySymbols) {
14
+ var symbols = Object.getOwnPropertySymbols(object);
15
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
16
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
17
+ })), keys.push.apply(keys, symbols);
18
+ }
19
+ return keys;
20
+ }
21
+ function _objectSpread2(target) {
22
+ for (var i = 1; i < arguments.length; i++) {
23
+ var source = null != arguments[i] ? arguments[i] : {};
24
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
25
+ _defineProperty(target, key, source[key]);
26
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
27
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
28
+ });
29
+ }
30
+ return target;
31
+ }
32
+ function _typeof(obj) {
33
+ "@babel/helpers - typeof";
34
+
35
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
36
+ return typeof obj;
37
+ } : function (obj) {
38
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
39
+ }, _typeof(obj);
40
+ }
41
+ function _classCallCheck(instance, Constructor) {
42
+ if (!(instance instanceof Constructor)) {
43
+ throw new TypeError("Cannot call a class as a function");
44
+ }
45
+ }
46
+ function _defineProperties(target, props) {
47
+ for (var i = 0; i < props.length; i++) {
48
+ var descriptor = props[i];
49
+ descriptor.enumerable = descriptor.enumerable || false;
50
+ descriptor.configurable = true;
51
+ if ("value" in descriptor) descriptor.writable = true;
52
+ Object.defineProperty(target, descriptor.key, descriptor);
53
+ }
54
+ }
55
+ function _createClass(Constructor, protoProps, staticProps) {
56
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
57
+ if (staticProps) _defineProperties(Constructor, staticProps);
58
+ Object.defineProperty(Constructor, "prototype", {
59
+ writable: false
60
+ });
61
+ return Constructor;
62
+ }
63
+ function _defineProperty(obj, key, value) {
64
+ if (key in obj) {
65
+ Object.defineProperty(obj, key, {
66
+ value: value,
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true
70
+ });
71
+ } else {
72
+ obj[key] = value;
73
+ }
74
+ return obj;
75
+ }
76
+ function _toConsumableArray(arr) {
77
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
78
+ }
79
+ function _arrayWithoutHoles(arr) {
80
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
81
+ }
82
+ function _iterableToArray(iter) {
83
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
84
+ }
85
+ function _unsupportedIterableToArray(o, minLen) {
86
+ if (!o) return;
87
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
88
+ var n = Object.prototype.toString.call(o).slice(8, -1);
89
+ if (n === "Object" && o.constructor) n = o.constructor.name;
90
+ if (n === "Map" || n === "Set") return Array.from(o);
91
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
92
+ }
93
+ function _arrayLikeToArray(arr, len) {
94
+ if (len == null || len > arr.length) len = arr.length;
95
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
96
+ return arr2;
97
+ }
98
+ function _nonIterableSpread() {
99
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
100
+ }
101
+
102
+ var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
103
+ var WINDOW = IS_BROWSER ? window : {};
104
+ var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false;
105
+ var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false;
106
+ var NAMESPACE = 'cropper';
107
+
108
+ // Actions
109
+ var ACTION_ALL = 'all';
110
+ var ACTION_CROP = 'crop';
111
+ var ACTION_MOVE = 'move';
112
+ var ACTION_ZOOM = 'zoom';
113
+ var ACTION_EAST = 'e';
114
+ var ACTION_WEST = 'w';
115
+ var ACTION_SOUTH = 's';
116
+ var ACTION_NORTH = 'n';
117
+ var ACTION_NORTH_EAST = 'ne';
118
+ var ACTION_NORTH_WEST = 'nw';
119
+ var ACTION_SOUTH_EAST = 'se';
120
+ var ACTION_SOUTH_WEST = 'sw';
121
+
122
+ // Classes
123
+ var CLASS_CROP = "".concat(NAMESPACE, "-crop");
124
+ var CLASS_DISABLED = "".concat(NAMESPACE, "-disabled");
125
+ var CLASS_HIDDEN = "".concat(NAMESPACE, "-hidden");
126
+ var CLASS_HIDE = "".concat(NAMESPACE, "-hide");
127
+ var CLASS_INVISIBLE = "".concat(NAMESPACE, "-invisible");
128
+ var CLASS_MODAL = "".concat(NAMESPACE, "-modal");
129
+ var CLASS_MOVE = "".concat(NAMESPACE, "-move");
130
+
131
+ // Data keys
132
+ var DATA_ACTION = "".concat(NAMESPACE, "Action");
133
+ var DATA_PREVIEW = "".concat(NAMESPACE, "Preview");
134
+
135
+ // Drag modes
136
+ var DRAG_MODE_CROP = 'crop';
137
+ var DRAG_MODE_MOVE = 'move';
138
+ var DRAG_MODE_NONE = 'none';
139
+
140
+ // Events
141
+ var EVENT_CROP = 'crop';
142
+ var EVENT_CROP_END = 'cropend';
143
+ var EVENT_CROP_MOVE = 'cropmove';
144
+ var EVENT_CROP_START = 'cropstart';
145
+ var EVENT_DBLCLICK = 'dblclick';
146
+ var EVENT_TOUCH_START = IS_TOUCH_DEVICE ? 'touchstart' : 'mousedown';
147
+ var EVENT_TOUCH_MOVE = IS_TOUCH_DEVICE ? 'touchmove' : 'mousemove';
148
+ var EVENT_TOUCH_END = IS_TOUCH_DEVICE ? 'touchend touchcancel' : 'mouseup';
149
+ var EVENT_POINTER_DOWN = HAS_POINTER_EVENT ? 'pointerdown' : EVENT_TOUCH_START;
150
+ var EVENT_POINTER_MOVE = HAS_POINTER_EVENT ? 'pointermove' : EVENT_TOUCH_MOVE;
151
+ var EVENT_POINTER_UP = HAS_POINTER_EVENT ? 'pointerup pointercancel' : EVENT_TOUCH_END;
152
+ var EVENT_READY = 'ready';
153
+ var EVENT_RESIZE = 'resize';
154
+ var EVENT_WHEEL = 'wheel';
155
+ var EVENT_ZOOM = 'zoom';
156
+
157
+ // Mime types
158
+ var MIME_TYPE_JPEG = 'image/jpeg';
159
+
160
+ // RegExps
161
+ var REGEXP_ACTIONS = /^e|w|s|n|se|sw|ne|nw|all|crop|move|zoom$/;
162
+ var REGEXP_DATA_URL = /^data:/;
163
+ var REGEXP_DATA_URL_JPEG = /^data:image\/jpeg;base64,/;
164
+ var REGEXP_TAG_NAME = /^img|canvas$/i;
165
+
166
+ // Misc
167
+ // Inspired by the default width and height of a canvas element.
168
+ var MIN_CONTAINER_WIDTH = 200;
169
+ var MIN_CONTAINER_HEIGHT = 100;
170
+
171
+ var DEFAULTS = {
172
+ // Define the view mode of the cropper
173
+ viewMode: 0,
174
+ // 0, 1, 2, 3
175
+
176
+ // Define the dragging mode of the cropper
177
+ dragMode: DRAG_MODE_CROP,
178
+ // 'crop', 'move' or 'none'
179
+
180
+ // Define the initial aspect ratio of the crop box
181
+ initialAspectRatio: NaN,
182
+ // Define the aspect ratio of the crop box
183
+ aspectRatio: NaN,
184
+ // An object with the previous cropping result data
185
+ data: null,
186
+ // A selector for adding extra containers to preview
187
+ preview: '',
188
+ // Re-render the cropper when resize the window
189
+ responsive: true,
190
+ // Restore the cropped area after resize the window
191
+ restore: true,
192
+ // Check if the current image is a cross-origin image
193
+ checkCrossOrigin: true,
194
+ // Check the current image's Exif Orientation information
195
+ checkOrientation: true,
196
+ // Show the black modal
197
+ modal: true,
198
+ // Show the dashed lines for guiding
199
+ guides: true,
200
+ // Show the center indicator for guiding
201
+ center: true,
202
+ // Show the white modal to highlight the crop box
203
+ highlight: true,
204
+ // Show the grid background
205
+ background: true,
206
+ // Enable to crop the image automatically when initialize
207
+ autoCrop: true,
208
+ // Define the percentage of automatic cropping area when initializes
209
+ autoCropArea: 0.8,
210
+ // Enable to move the image
211
+ movable: true,
212
+ // Enable to rotate the image
213
+ rotatable: true,
214
+ // Enable to scale the image
215
+ scalable: true,
216
+ // Enable to zoom the image
217
+ zoomable: true,
218
+ // Enable to zoom the image by dragging touch
219
+ zoomOnTouch: true,
220
+ // Enable to zoom the image by wheeling mouse
221
+ zoomOnWheel: true,
222
+ // Define zoom ratio when zoom the image by wheeling mouse
223
+ wheelZoomRatio: 0.1,
224
+ // Enable to move the crop box
225
+ cropBoxMovable: true,
226
+ // Enable to resize the crop box
227
+ cropBoxResizable: true,
228
+ // Toggle drag mode between "crop" and "move" when click twice on the cropper
229
+ toggleDragModeOnDblclick: true,
230
+ // Size limitation
231
+ minCanvasWidth: 0,
232
+ minCanvasHeight: 0,
233
+ minCropBoxWidth: 0,
234
+ minCropBoxHeight: 0,
235
+ minContainerWidth: MIN_CONTAINER_WIDTH,
236
+ minContainerHeight: MIN_CONTAINER_HEIGHT,
237
+ // Shortcuts of events
238
+ ready: null,
239
+ cropstart: null,
240
+ cropmove: null,
241
+ cropend: null,
242
+ crop: null,
243
+ zoom: null
244
+ };
245
+
246
+ var TEMPLATE = '<div class="cropper-container" touch-action="none">' + '<div class="cropper-wrap-box">' + '<div class="cropper-canvas"></div>' + '</div>' + '<div class="cropper-drag-box"></div>' + '<div class="cropper-crop-box">' + '<span class="cropper-view-box"></span>' + '<span class="cropper-dashed dashed-h"></span>' + '<span class="cropper-dashed dashed-v"></span>' + '<span class="cropper-center"></span>' + '<span class="cropper-face"></span>' + '<span class="cropper-line line-e" data-cropper-action="e"></span>' + '<span class="cropper-line line-n" data-cropper-action="n"></span>' + '<span class="cropper-line line-w" data-cropper-action="w"></span>' + '<span class="cropper-line line-s" data-cropper-action="s"></span>' + '<span class="cropper-point point-e" data-cropper-action="e"></span>' + '<span class="cropper-point point-n" data-cropper-action="n"></span>' + '<span class="cropper-point point-w" data-cropper-action="w"></span>' + '<span class="cropper-point point-s" data-cropper-action="s"></span>' + '<span class="cropper-point point-ne" data-cropper-action="ne"></span>' + '<span class="cropper-point point-nw" data-cropper-action="nw"></span>' + '<span class="cropper-point point-sw" data-cropper-action="sw"></span>' + '<span class="cropper-point point-se" data-cropper-action="se"></span>' + '</div>' + '</div>';
247
+
248
+ /**
249
+ * Check if the given value is not a number.
250
+ */
251
+ var isNaN = Number.isNaN || WINDOW.isNaN;
252
+
253
+ /**
254
+ * Check if the given value is a number.
255
+ * @param {*} value - The value to check.
256
+ * @returns {boolean} Returns `true` if the given value is a number, else `false`.
257
+ */
258
+ function isNumber(value) {
259
+ return typeof value === 'number' && !isNaN(value);
260
+ }
261
+
262
+ /**
263
+ * Check if the given value is a positive number.
264
+ * @param {*} value - The value to check.
265
+ * @returns {boolean} Returns `true` if the given value is a positive number, else `false`.
266
+ */
267
+ var isPositiveNumber = function isPositiveNumber(value) {
268
+ return value > 0 && value < Infinity;
269
+ };
270
+
271
+ /**
272
+ * Check if the given value is undefined.
273
+ * @param {*} value - The value to check.
274
+ * @returns {boolean} Returns `true` if the given value is undefined, else `false`.
275
+ */
276
+ function isUndefined(value) {
277
+ return typeof value === 'undefined';
278
+ }
279
+
280
+ /**
281
+ * Check if the given value is an object.
282
+ * @param {*} value - The value to check.
283
+ * @returns {boolean} Returns `true` if the given value is an object, else `false`.
284
+ */
285
+ function isObject(value) {
286
+ return _typeof(value) === 'object' && value !== null;
287
+ }
288
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
289
+
290
+ /**
291
+ * Check if the given value is a plain object.
292
+ * @param {*} value - The value to check.
293
+ * @returns {boolean} Returns `true` if the given value is a plain object, else `false`.
294
+ */
295
+ function isPlainObject(value) {
296
+ if (!isObject(value)) {
297
+ return false;
298
+ }
299
+ try {
300
+ var _constructor = value.constructor;
301
+ var prototype = _constructor.prototype;
302
+ return _constructor && prototype && hasOwnProperty.call(prototype, 'isPrototypeOf');
303
+ } catch (error) {
304
+ return false;
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Check if the given value is a function.
310
+ * @param {*} value - The value to check.
311
+ * @returns {boolean} Returns `true` if the given value is a function, else `false`.
312
+ */
313
+ function isFunction(value) {
314
+ return typeof value === 'function';
315
+ }
316
+ var slice = Array.prototype.slice;
317
+
318
+ /**
319
+ * Convert array-like or iterable object to an array.
320
+ * @param {*} value - The value to convert.
321
+ * @returns {Array} Returns a new array.
322
+ */
323
+ function toArray(value) {
324
+ return Array.from ? Array.from(value) : slice.call(value);
325
+ }
326
+
327
+ /**
328
+ * Iterate the given data.
329
+ * @param {*} data - The data to iterate.
330
+ * @param {Function} callback - The process function for each element.
331
+ * @returns {*} The original data.
332
+ */
333
+ function forEach(data, callback) {
334
+ if (data && isFunction(callback)) {
335
+ if (Array.isArray(data) || isNumber(data.length) /* array-like */) {
336
+ toArray(data).forEach(function (value, key) {
337
+ callback.call(data, value, key, data);
338
+ });
339
+ } else if (isObject(data)) {
340
+ Object.keys(data).forEach(function (key) {
341
+ callback.call(data, data[key], key, data);
342
+ });
343
+ }
344
+ }
345
+ return data;
346
+ }
347
+
348
+ /**
349
+ * Extend the given object.
350
+ * @param {*} target - The target object to extend.
351
+ * @param {*} args - The rest objects for merging to the target object.
352
+ * @returns {Object} The extended object.
353
+ */
354
+ var assign = Object.assign || function assign(target) {
355
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
356
+ args[_key - 1] = arguments[_key];
357
+ }
358
+ if (isObject(target) && args.length > 0) {
359
+ args.forEach(function (arg) {
360
+ if (isObject(arg)) {
361
+ Object.keys(arg).forEach(function (key) {
362
+ target[key] = arg[key];
363
+ });
364
+ }
365
+ });
366
+ }
367
+ return target;
368
+ };
369
+ var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/;
370
+
371
+ /**
372
+ * Normalize decimal number.
373
+ * Check out {@link https://0.30000000000000004.com/}
374
+ * @param {number} value - The value to normalize.
375
+ * @param {number} [times=100000000000] - The times for normalizing.
376
+ * @returns {number} Returns the normalized number.
377
+ */
378
+ function normalizeDecimalNumber(value) {
379
+ var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100000000000;
380
+ return REGEXP_DECIMALS.test(value) ? Math.round(value * times) / times : value;
381
+ }
382
+ var REGEXP_SUFFIX = /^width|height|left|top|marginLeft|marginTop$/;
383
+
384
+ /**
385
+ * Apply styles to the given element.
386
+ * @param {Element} element - The target element.
387
+ * @param {Object} styles - The styles for applying.
388
+ */
389
+ function setStyle(element, styles) {
390
+ var style = element.style;
391
+ forEach(styles, function (value, property) {
392
+ if (REGEXP_SUFFIX.test(property) && isNumber(value)) {
393
+ value = "".concat(value, "px");
394
+ }
395
+ style[property] = value;
396
+ });
397
+ }
398
+
399
+ /**
400
+ * Check if the given element has a special class.
401
+ * @param {Element} element - The element to check.
402
+ * @param {string} value - The class to search.
403
+ * @returns {boolean} Returns `true` if the special class was found.
404
+ */
405
+ function hasClass(element, value) {
406
+ return element.classList ? element.classList.contains(value) : element.className.indexOf(value) > -1;
407
+ }
408
+
409
+ /**
410
+ * Add classes to the given element.
411
+ * @param {Element} element - The target element.
412
+ * @param {string} value - The classes to be added.
413
+ */
414
+ function addClass(element, value) {
415
+ if (!value) {
416
+ return;
417
+ }
418
+ if (isNumber(element.length)) {
419
+ forEach(element, function (elem) {
420
+ addClass(elem, value);
421
+ });
422
+ return;
423
+ }
424
+ if (element.classList) {
425
+ element.classList.add(value);
426
+ return;
427
+ }
428
+ var className = element.className.trim();
429
+ if (!className) {
430
+ element.className = value;
431
+ } else if (className.indexOf(value) < 0) {
432
+ element.className = "".concat(className, " ").concat(value);
433
+ }
434
+ }
435
+
436
+ /**
437
+ * Remove classes from the given element.
438
+ * @param {Element} element - The target element.
439
+ * @param {string} value - The classes to be removed.
440
+ */
441
+ function removeClass(element, value) {
442
+ if (!value) {
443
+ return;
444
+ }
445
+ if (isNumber(element.length)) {
446
+ forEach(element, function (elem) {
447
+ removeClass(elem, value);
448
+ });
449
+ return;
450
+ }
451
+ if (element.classList) {
452
+ element.classList.remove(value);
453
+ return;
454
+ }
455
+ if (element.className.indexOf(value) >= 0) {
456
+ element.className = element.className.replace(value, '');
457
+ }
458
+ }
459
+
460
+ /**
461
+ * Add or remove classes from the given element.
462
+ * @param {Element} element - The target element.
463
+ * @param {string} value - The classes to be toggled.
464
+ * @param {boolean} added - Add only.
465
+ */
466
+ function toggleClass(element, value, added) {
467
+ if (!value) {
468
+ return;
469
+ }
470
+ if (isNumber(element.length)) {
471
+ forEach(element, function (elem) {
472
+ toggleClass(elem, value, added);
473
+ });
474
+ return;
475
+ }
476
+
477
+ // IE10-11 doesn't support the second parameter of `classList.toggle`
478
+ if (added) {
479
+ addClass(element, value);
480
+ } else {
481
+ removeClass(element, value);
482
+ }
483
+ }
484
+ var REGEXP_CAMEL_CASE = /([a-z\d])([A-Z])/g;
485
+
486
+ /**
487
+ * Transform the given string from camelCase to kebab-case
488
+ * @param {string} value - The value to transform.
489
+ * @returns {string} The transformed value.
490
+ */
491
+ function toParamCase(value) {
492
+ return value.replace(REGEXP_CAMEL_CASE, '$1-$2').toLowerCase();
493
+ }
494
+
495
+ /**
496
+ * Get data from the given element.
497
+ * @param {Element} element - The target element.
498
+ * @param {string} name - The data key to get.
499
+ * @returns {string} The data value.
500
+ */
501
+ function getData(element, name) {
502
+ if (isObject(element[name])) {
503
+ return element[name];
504
+ }
505
+ if (element.dataset) {
506
+ return element.dataset[name];
507
+ }
508
+ return element.getAttribute("data-".concat(toParamCase(name)));
509
+ }
510
+
511
+ /**
512
+ * Set data to the given element.
513
+ * @param {Element} element - The target element.
514
+ * @param {string} name - The data key to set.
515
+ * @param {string} data - The data value.
516
+ */
517
+ function setData(element, name, data) {
518
+ if (isObject(data)) {
519
+ element[name] = data;
520
+ } else if (element.dataset) {
521
+ element.dataset[name] = data;
522
+ } else {
523
+ element.setAttribute("data-".concat(toParamCase(name)), data);
524
+ }
525
+ }
526
+
527
+ /**
528
+ * Remove data from the given element.
529
+ * @param {Element} element - The target element.
530
+ * @param {string} name - The data key to remove.
531
+ */
532
+ function removeData(element, name) {
533
+ if (isObject(element[name])) {
534
+ try {
535
+ delete element[name];
536
+ } catch (error) {
537
+ element[name] = undefined;
538
+ }
539
+ } else if (element.dataset) {
540
+ // #128 Safari not allows to delete dataset property
541
+ try {
542
+ delete element.dataset[name];
543
+ } catch (error) {
544
+ element.dataset[name] = undefined;
545
+ }
546
+ } else {
547
+ element.removeAttribute("data-".concat(toParamCase(name)));
548
+ }
549
+ }
550
+ var REGEXP_SPACES = /\s\s*/;
551
+ var onceSupported = function () {
552
+ var supported = false;
553
+ if (IS_BROWSER) {
554
+ var once = false;
555
+ var listener = function listener() {};
556
+ var options = Object.defineProperty({}, 'once', {
557
+ get: function get() {
558
+ supported = true;
559
+ return once;
560
+ },
561
+ /**
562
+ * This setter can fix a `TypeError` in strict mode
563
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only}
564
+ * @param {boolean} value - The value to set
565
+ */
566
+ set: function set(value) {
567
+ once = value;
568
+ }
569
+ });
570
+ WINDOW.addEventListener('test', listener, options);
571
+ WINDOW.removeEventListener('test', listener, options);
572
+ }
573
+ return supported;
574
+ }();
575
+
576
+ /**
577
+ * Remove event listener from the target element.
578
+ * @param {Element} element - The event target.
579
+ * @param {string} type - The event type(s).
580
+ * @param {Function} listener - The event listener.
581
+ * @param {Object} options - The event options.
582
+ */
583
+ function removeListener(element, type, listener) {
584
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
585
+ var handler = listener;
586
+ type.trim().split(REGEXP_SPACES).forEach(function (event) {
587
+ if (!onceSupported) {
588
+ var listeners = element.listeners;
589
+ if (listeners && listeners[event] && listeners[event][listener]) {
590
+ handler = listeners[event][listener];
591
+ delete listeners[event][listener];
592
+ if (Object.keys(listeners[event]).length === 0) {
593
+ delete listeners[event];
594
+ }
595
+ if (Object.keys(listeners).length === 0) {
596
+ delete element.listeners;
597
+ }
598
+ }
599
+ }
600
+ element.removeEventListener(event, handler, options);
601
+ });
602
+ }
603
+
604
+ /**
605
+ * Add event listener to the target element.
606
+ * @param {Element} element - The event target.
607
+ * @param {string} type - The event type(s).
608
+ * @param {Function} listener - The event listener.
609
+ * @param {Object} options - The event options.
610
+ */
611
+ function addListener(element, type, listener) {
612
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
613
+ var _handler = listener;
614
+ type.trim().split(REGEXP_SPACES).forEach(function (event) {
615
+ if (options.once && !onceSupported) {
616
+ var _element$listeners = element.listeners,
617
+ listeners = _element$listeners === void 0 ? {} : _element$listeners;
618
+ _handler = function handler() {
619
+ delete listeners[event][listener];
620
+ element.removeEventListener(event, _handler, options);
621
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
622
+ args[_key2] = arguments[_key2];
623
+ }
624
+ listener.apply(element, args);
625
+ };
626
+ if (!listeners[event]) {
627
+ listeners[event] = {};
628
+ }
629
+ if (listeners[event][listener]) {
630
+ element.removeEventListener(event, listeners[event][listener], options);
631
+ }
632
+ listeners[event][listener] = _handler;
633
+ element.listeners = listeners;
634
+ }
635
+ element.addEventListener(event, _handler, options);
636
+ });
637
+ }
638
+
639
+ /**
640
+ * Dispatch event on the target element.
641
+ * @param {Element} element - The event target.
642
+ * @param {string} type - The event type(s).
643
+ * @param {Object} data - The additional event data.
644
+ * @returns {boolean} Indicate if the event is default prevented or not.
645
+ */
646
+ function dispatchEvent(element, type, data) {
647
+ var event;
648
+
649
+ // Event and CustomEvent on IE9-11 are global objects, not constructors
650
+ if (isFunction(Event) && isFunction(CustomEvent)) {
651
+ event = new CustomEvent(type, {
652
+ detail: data,
653
+ bubbles: true,
654
+ cancelable: true
655
+ });
656
+ } else {
657
+ event = document.createEvent('CustomEvent');
658
+ event.initCustomEvent(type, true, true, data);
659
+ }
660
+ return element.dispatchEvent(event);
661
+ }
662
+
663
+ /**
664
+ * Get the offset base on the document.
665
+ * @param {Element} element - The target element.
666
+ * @returns {Object} The offset data.
667
+ */
668
+ function getOffset(element) {
669
+ var box = element.getBoundingClientRect();
670
+ return {
671
+ left: box.left + (window.pageXOffset - document.documentElement.clientLeft),
672
+ top: box.top + (window.pageYOffset - document.documentElement.clientTop)
673
+ };
674
+ }
675
+ var location = WINDOW.location;
676
+ var REGEXP_ORIGINS = /^(\w+:)\/\/([^:/?#]*):?(\d*)/i;
677
+
678
+ /**
679
+ * Check if the given URL is a cross origin URL.
680
+ * @param {string} url - The target URL.
681
+ * @returns {boolean} Returns `true` if the given URL is a cross origin URL, else `false`.
682
+ */
683
+ function isCrossOriginURL(url) {
684
+ var parts = url.match(REGEXP_ORIGINS);
685
+ return parts !== null && (parts[1] !== location.protocol || parts[2] !== location.hostname || parts[3] !== location.port);
686
+ }
687
+
688
+ /**
689
+ * Add timestamp to the given URL.
690
+ * @param {string} url - The target URL.
691
+ * @returns {string} The result URL.
692
+ */
693
+ function addTimestamp(url) {
694
+ var timestamp = "timestamp=".concat(new Date().getTime());
695
+ return url + (url.indexOf('?') === -1 ? '?' : '&') + timestamp;
696
+ }
697
+
698
+ /**
699
+ * Get transforms base on the given object.
700
+ * @param {Object} obj - The target object.
701
+ * @returns {string} A string contains transform values.
702
+ */
703
+ function getTransforms(_ref) {
704
+ var rotate = _ref.rotate,
705
+ scaleX = _ref.scaleX,
706
+ scaleY = _ref.scaleY,
707
+ translateX = _ref.translateX,
708
+ translateY = _ref.translateY;
709
+ var values = [];
710
+ if (isNumber(translateX) && translateX !== 0) {
711
+ values.push("translateX(".concat(translateX, "px)"));
712
+ }
713
+ if (isNumber(translateY) && translateY !== 0) {
714
+ values.push("translateY(".concat(translateY, "px)"));
715
+ }
716
+
717
+ // Rotate should come first before scale to match orientation transform
718
+ if (isNumber(rotate) && rotate !== 0) {
719
+ values.push("rotate(".concat(rotate, "deg)"));
720
+ }
721
+ if (isNumber(scaleX) && scaleX !== 1) {
722
+ values.push("scaleX(".concat(scaleX, ")"));
723
+ }
724
+ if (isNumber(scaleY) && scaleY !== 1) {
725
+ values.push("scaleY(".concat(scaleY, ")"));
726
+ }
727
+ var transform = values.length ? values.join(' ') : 'none';
728
+ return {
729
+ WebkitTransform: transform,
730
+ msTransform: transform,
731
+ transform: transform
732
+ };
733
+ }
734
+
735
+ /**
736
+ * Get the max ratio of a group of pointers.
737
+ * @param {string} pointers - The target pointers.
738
+ * @returns {number} The result ratio.
739
+ */
740
+ function getMaxZoomRatio(pointers) {
741
+ var pointers2 = _objectSpread2({}, pointers);
742
+ var maxRatio = 0;
743
+ forEach(pointers, function (pointer, pointerId) {
744
+ delete pointers2[pointerId];
745
+ forEach(pointers2, function (pointer2) {
746
+ var x1 = Math.abs(pointer.startX - pointer2.startX);
747
+ var y1 = Math.abs(pointer.startY - pointer2.startY);
748
+ var x2 = Math.abs(pointer.endX - pointer2.endX);
749
+ var y2 = Math.abs(pointer.endY - pointer2.endY);
750
+ var z1 = Math.sqrt(x1 * x1 + y1 * y1);
751
+ var z2 = Math.sqrt(x2 * x2 + y2 * y2);
752
+ var ratio = (z2 - z1) / z1;
753
+ if (Math.abs(ratio) > Math.abs(maxRatio)) {
754
+ maxRatio = ratio;
755
+ }
756
+ });
757
+ });
758
+ return maxRatio;
759
+ }
760
+
761
+ /**
762
+ * Get a pointer from an event object.
763
+ * @param {Object} event - The target event object.
764
+ * @param {boolean} endOnly - Indicates if only returns the end point coordinate or not.
765
+ * @returns {Object} The result pointer contains start and/or end point coordinates.
766
+ */
767
+ function getPointer(_ref2, endOnly) {
768
+ var pageX = _ref2.pageX,
769
+ pageY = _ref2.pageY;
770
+ var end = {
771
+ endX: pageX,
772
+ endY: pageY
773
+ };
774
+ return endOnly ? end : _objectSpread2({
775
+ startX: pageX,
776
+ startY: pageY
777
+ }, end);
778
+ }
779
+
780
+ /**
781
+ * Get the center point coordinate of a group of pointers.
782
+ * @param {Object} pointers - The target pointers.
783
+ * @returns {Object} The center point coordinate.
784
+ */
785
+ function getPointersCenter(pointers) {
786
+ var pageX = 0;
787
+ var pageY = 0;
788
+ var count = 0;
789
+ forEach(pointers, function (_ref3) {
790
+ var startX = _ref3.startX,
791
+ startY = _ref3.startY;
792
+ pageX += startX;
793
+ pageY += startY;
794
+ count += 1;
795
+ });
796
+ pageX /= count;
797
+ pageY /= count;
798
+ return {
799
+ pageX: pageX,
800
+ pageY: pageY
801
+ };
802
+ }
803
+
804
+ /**
805
+ * Get the max sizes in a rectangle under the given aspect ratio.
806
+ * @param {Object} data - The original sizes.
807
+ * @param {string} [type='contain'] - The adjust type.
808
+ * @returns {Object} The result sizes.
809
+ */
810
+ function getAdjustedSizes(_ref4) {
811
+ var aspectRatio = _ref4.aspectRatio,
812
+ height = _ref4.height,
813
+ width = _ref4.width;
814
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'contain';
815
+ var isValidWidth = isPositiveNumber(width);
816
+ var isValidHeight = isPositiveNumber(height);
817
+ if (isValidWidth && isValidHeight) {
818
+ var adjustedWidth = height * aspectRatio;
819
+ if (type === 'contain' && adjustedWidth > width || type === 'cover' && adjustedWidth < width) {
820
+ height = width / aspectRatio;
821
+ } else {
822
+ width = height * aspectRatio;
823
+ }
824
+ } else if (isValidWidth) {
825
+ height = width / aspectRatio;
826
+ } else if (isValidHeight) {
827
+ width = height * aspectRatio;
828
+ }
829
+ return {
830
+ width: width,
831
+ height: height
832
+ };
833
+ }
834
+
835
+ /**
836
+ * Get the new sizes of a rectangle after rotated.
837
+ * @param {Object} data - The original sizes.
838
+ * @returns {Object} The result sizes.
839
+ */
840
+ function getRotatedSizes(_ref5) {
841
+ var width = _ref5.width,
842
+ height = _ref5.height,
843
+ degree = _ref5.degree;
844
+ degree = Math.abs(degree) % 180;
845
+ if (degree === 90) {
846
+ return {
847
+ width: height,
848
+ height: width
849
+ };
850
+ }
851
+ var arc = degree % 90 * Math.PI / 180;
852
+ var sinArc = Math.sin(arc);
853
+ var cosArc = Math.cos(arc);
854
+ var newWidth = width * cosArc + height * sinArc;
855
+ var newHeight = width * sinArc + height * cosArc;
856
+ return degree > 90 ? {
857
+ width: newHeight,
858
+ height: newWidth
859
+ } : {
860
+ width: newWidth,
861
+ height: newHeight
862
+ };
863
+ }
864
+
865
+ /**
866
+ * Get a canvas which drew the given image.
867
+ * @param {HTMLImageElement} image - The image for drawing.
868
+ * @param {Object} imageData - The image data.
869
+ * @param {Object} canvasData - The canvas data.
870
+ * @param {Object} options - The options.
871
+ * @returns {HTMLCanvasElement} The result canvas.
872
+ */
873
+ function getSourceCanvas(image, _ref6, _ref7, _ref8) {
874
+ var imageAspectRatio = _ref6.aspectRatio,
875
+ imageNaturalWidth = _ref6.naturalWidth,
876
+ imageNaturalHeight = _ref6.naturalHeight,
877
+ _ref6$rotate = _ref6.rotate,
878
+ rotate = _ref6$rotate === void 0 ? 0 : _ref6$rotate,
879
+ _ref6$scaleX = _ref6.scaleX,
880
+ scaleX = _ref6$scaleX === void 0 ? 1 : _ref6$scaleX,
881
+ _ref6$scaleY = _ref6.scaleY,
882
+ scaleY = _ref6$scaleY === void 0 ? 1 : _ref6$scaleY;
883
+ var aspectRatio = _ref7.aspectRatio,
884
+ naturalWidth = _ref7.naturalWidth,
885
+ naturalHeight = _ref7.naturalHeight;
886
+ var _ref8$fillColor = _ref8.fillColor,
887
+ fillColor = _ref8$fillColor === void 0 ? 'transparent' : _ref8$fillColor,
888
+ _ref8$imageSmoothingE = _ref8.imageSmoothingEnabled,
889
+ imageSmoothingEnabled = _ref8$imageSmoothingE === void 0 ? true : _ref8$imageSmoothingE,
890
+ _ref8$imageSmoothingQ = _ref8.imageSmoothingQuality,
891
+ imageSmoothingQuality = _ref8$imageSmoothingQ === void 0 ? 'low' : _ref8$imageSmoothingQ,
892
+ _ref8$maxWidth = _ref8.maxWidth,
893
+ maxWidth = _ref8$maxWidth === void 0 ? Infinity : _ref8$maxWidth,
894
+ _ref8$maxHeight = _ref8.maxHeight,
895
+ maxHeight = _ref8$maxHeight === void 0 ? Infinity : _ref8$maxHeight,
896
+ _ref8$minWidth = _ref8.minWidth,
897
+ minWidth = _ref8$minWidth === void 0 ? 0 : _ref8$minWidth,
898
+ _ref8$minHeight = _ref8.minHeight,
899
+ minHeight = _ref8$minHeight === void 0 ? 0 : _ref8$minHeight;
900
+ var canvas = document.createElement('canvas');
901
+ var context = canvas.getContext('2d');
902
+ var maxSizes = getAdjustedSizes({
903
+ aspectRatio: aspectRatio,
904
+ width: maxWidth,
905
+ height: maxHeight
906
+ });
907
+ var minSizes = getAdjustedSizes({
908
+ aspectRatio: aspectRatio,
909
+ width: minWidth,
910
+ height: minHeight
911
+ }, 'cover');
912
+ var width = Math.min(maxSizes.width, Math.max(minSizes.width, naturalWidth));
913
+ var height = Math.min(maxSizes.height, Math.max(minSizes.height, naturalHeight));
914
+
915
+ // Note: should always use image's natural sizes for drawing as
916
+ // imageData.naturalWidth === canvasData.naturalHeight when rotate % 180 === 90
917
+ var destMaxSizes = getAdjustedSizes({
918
+ aspectRatio: imageAspectRatio,
919
+ width: maxWidth,
920
+ height: maxHeight
921
+ });
922
+ var destMinSizes = getAdjustedSizes({
923
+ aspectRatio: imageAspectRatio,
924
+ width: minWidth,
925
+ height: minHeight
926
+ }, 'cover');
927
+ var destWidth = Math.min(destMaxSizes.width, Math.max(destMinSizes.width, imageNaturalWidth));
928
+ var destHeight = Math.min(destMaxSizes.height, Math.max(destMinSizes.height, imageNaturalHeight));
929
+ var params = [-destWidth / 2, -destHeight / 2, destWidth, destHeight];
930
+ canvas.width = normalizeDecimalNumber(width);
931
+ canvas.height = normalizeDecimalNumber(height);
932
+ context.fillStyle = fillColor;
933
+ context.fillRect(0, 0, width, height);
934
+ context.save();
935
+ context.translate(width / 2, height / 2);
936
+ context.rotate(rotate * Math.PI / 180);
937
+ context.scale(scaleX, scaleY);
938
+ context.imageSmoothingEnabled = imageSmoothingEnabled;
939
+ context.imageSmoothingQuality = imageSmoothingQuality;
940
+ context.drawImage.apply(context, [image].concat(_toConsumableArray(params.map(function (param) {
941
+ return Math.floor(normalizeDecimalNumber(param));
942
+ }))));
943
+ context.restore();
944
+ return canvas;
945
+ }
946
+ var fromCharCode = String.fromCharCode;
947
+
948
+ /**
949
+ * Get string from char code in data view.
950
+ * @param {DataView} dataView - The data view for read.
951
+ * @param {number} start - The start index.
952
+ * @param {number} length - The read length.
953
+ * @returns {string} The read result.
954
+ */
955
+ function getStringFromCharCode(dataView, start, length) {
956
+ var str = '';
957
+ length += start;
958
+ for (var i = start; i < length; i += 1) {
959
+ str += fromCharCode(dataView.getUint8(i));
960
+ }
961
+ return str;
962
+ }
963
+ var REGEXP_DATA_URL_HEAD = /^data:.*,/;
964
+
965
+ /**
966
+ * Transform Data URL to array buffer.
967
+ * @param {string} dataURL - The Data URL to transform.
968
+ * @returns {ArrayBuffer} The result array buffer.
969
+ */
970
+ function dataURLToArrayBuffer(dataURL) {
971
+ var base64 = dataURL.replace(REGEXP_DATA_URL_HEAD, '');
972
+ var binary = atob(base64);
973
+ var arrayBuffer = new ArrayBuffer(binary.length);
974
+ var uint8 = new Uint8Array(arrayBuffer);
975
+ forEach(uint8, function (value, i) {
976
+ uint8[i] = binary.charCodeAt(i);
977
+ });
978
+ return arrayBuffer;
979
+ }
980
+
981
+ /**
982
+ * Transform array buffer to Data URL.
983
+ * @param {ArrayBuffer} arrayBuffer - The array buffer to transform.
984
+ * @param {string} mimeType - The mime type of the Data URL.
985
+ * @returns {string} The result Data URL.
986
+ */
987
+ function arrayBufferToDataURL(arrayBuffer, mimeType) {
988
+ var chunks = [];
989
+
990
+ // Chunk Typed Array for better performance (#435)
991
+ var chunkSize = 8192;
992
+ var uint8 = new Uint8Array(arrayBuffer);
993
+ while (uint8.length > 0) {
994
+ // XXX: Babel's `toConsumableArray` helper will throw error in IE or Safari 9
995
+ // eslint-disable-next-line prefer-spread
996
+ chunks.push(fromCharCode.apply(null, toArray(uint8.subarray(0, chunkSize))));
997
+ uint8 = uint8.subarray(chunkSize);
998
+ }
999
+ return "data:".concat(mimeType, ";base64,").concat(btoa(chunks.join('')));
1000
+ }
1001
+
1002
+ /**
1003
+ * Get orientation value from given array buffer.
1004
+ * @param {ArrayBuffer} arrayBuffer - The array buffer to read.
1005
+ * @returns {number} The read orientation value.
1006
+ */
1007
+ function resetAndGetOrientation(arrayBuffer) {
1008
+ var dataView = new DataView(arrayBuffer);
1009
+ var orientation;
1010
+
1011
+ // Ignores range error when the image does not have correct Exif information
1012
+ try {
1013
+ var littleEndian;
1014
+ var app1Start;
1015
+ var ifdStart;
1016
+
1017
+ // Only handle JPEG image (start by 0xFFD8)
1018
+ if (dataView.getUint8(0) === 0xFF && dataView.getUint8(1) === 0xD8) {
1019
+ var length = dataView.byteLength;
1020
+ var offset = 2;
1021
+ while (offset + 1 < length) {
1022
+ if (dataView.getUint8(offset) === 0xFF && dataView.getUint8(offset + 1) === 0xE1) {
1023
+ app1Start = offset;
1024
+ break;
1025
+ }
1026
+ offset += 1;
1027
+ }
1028
+ }
1029
+ if (app1Start) {
1030
+ var exifIDCode = app1Start + 4;
1031
+ var tiffOffset = app1Start + 10;
1032
+ if (getStringFromCharCode(dataView, exifIDCode, 4) === 'Exif') {
1033
+ var endianness = dataView.getUint16(tiffOffset);
1034
+ littleEndian = endianness === 0x4949;
1035
+ if (littleEndian || endianness === 0x4D4D /* bigEndian */) {
1036
+ if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) {
1037
+ var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian);
1038
+ if (firstIFDOffset >= 0x00000008) {
1039
+ ifdStart = tiffOffset + firstIFDOffset;
1040
+ }
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+ if (ifdStart) {
1046
+ var _length = dataView.getUint16(ifdStart, littleEndian);
1047
+ var _offset;
1048
+ var i;
1049
+ for (i = 0; i < _length; i += 1) {
1050
+ _offset = ifdStart + i * 12 + 2;
1051
+ if (dataView.getUint16(_offset, littleEndian) === 0x0112 /* Orientation */) {
1052
+ // 8 is the offset of the current tag's value
1053
+ _offset += 8;
1054
+
1055
+ // Get the original orientation value
1056
+ orientation = dataView.getUint16(_offset, littleEndian);
1057
+
1058
+ // Override the orientation with its default value
1059
+ dataView.setUint16(_offset, 1, littleEndian);
1060
+ break;
1061
+ }
1062
+ }
1063
+ }
1064
+ } catch (error) {
1065
+ orientation = 1;
1066
+ }
1067
+ return orientation;
1068
+ }
1069
+
1070
+ /**
1071
+ * Parse Exif Orientation value.
1072
+ * @param {number} orientation - The orientation to parse.
1073
+ * @returns {Object} The parsed result.
1074
+ */
1075
+ function parseOrientation(orientation) {
1076
+ var rotate = 0;
1077
+ var scaleX = 1;
1078
+ var scaleY = 1;
1079
+ switch (orientation) {
1080
+ // Flip horizontal
1081
+ case 2:
1082
+ scaleX = -1;
1083
+ break;
1084
+
1085
+ // Rotate left 180°
1086
+ case 3:
1087
+ rotate = -180;
1088
+ break;
1089
+
1090
+ // Flip vertical
1091
+ case 4:
1092
+ scaleY = -1;
1093
+ break;
1094
+
1095
+ // Flip vertical and rotate right 90°
1096
+ case 5:
1097
+ rotate = 90;
1098
+ scaleY = -1;
1099
+ break;
1100
+
1101
+ // Rotate right 90°
1102
+ case 6:
1103
+ rotate = 90;
1104
+ break;
1105
+
1106
+ // Flip horizontal and rotate right 90°
1107
+ case 7:
1108
+ rotate = 90;
1109
+ scaleX = -1;
1110
+ break;
1111
+
1112
+ // Rotate left 90°
1113
+ case 8:
1114
+ rotate = -90;
1115
+ break;
1116
+ }
1117
+ return {
1118
+ rotate: rotate,
1119
+ scaleX: scaleX,
1120
+ scaleY: scaleY
1121
+ };
1122
+ }
1123
+
1124
+ var render = {
1125
+ render: function render() {
1126
+ this.initContainer();
1127
+ this.initCanvas();
1128
+ this.initCropBox();
1129
+ this.renderCanvas();
1130
+ if (this.cropped) {
1131
+ this.renderCropBox();
1132
+ }
1133
+ },
1134
+ initContainer: function initContainer() {
1135
+ var element = this.element,
1136
+ options = this.options,
1137
+ container = this.container,
1138
+ cropper = this.cropper;
1139
+ var minWidth = Number(options.minContainerWidth);
1140
+ var minHeight = Number(options.minContainerHeight);
1141
+ addClass(cropper, CLASS_HIDDEN);
1142
+ removeClass(element, CLASS_HIDDEN);
1143
+ var containerData = {
1144
+ width: Math.max(container.offsetWidth, minWidth >= 0 ? minWidth : MIN_CONTAINER_WIDTH),
1145
+ height: Math.max(container.offsetHeight, minHeight >= 0 ? minHeight : MIN_CONTAINER_HEIGHT)
1146
+ };
1147
+ this.containerData = containerData;
1148
+ setStyle(cropper, {
1149
+ width: containerData.width,
1150
+ height: containerData.height
1151
+ });
1152
+ addClass(element, CLASS_HIDDEN);
1153
+ removeClass(cropper, CLASS_HIDDEN);
1154
+ },
1155
+ // Canvas (image wrapper)
1156
+ initCanvas: function initCanvas() {
1157
+ var containerData = this.containerData,
1158
+ imageData = this.imageData;
1159
+ var viewMode = this.options.viewMode;
1160
+ var rotated = Math.abs(imageData.rotate) % 180 === 90;
1161
+ var naturalWidth = rotated ? imageData.naturalHeight : imageData.naturalWidth;
1162
+ var naturalHeight = rotated ? imageData.naturalWidth : imageData.naturalHeight;
1163
+ var aspectRatio = naturalWidth / naturalHeight;
1164
+ var canvasWidth = containerData.width;
1165
+ var canvasHeight = containerData.height;
1166
+ if (containerData.height * aspectRatio > containerData.width) {
1167
+ if (viewMode === 3) {
1168
+ canvasWidth = containerData.height * aspectRatio;
1169
+ } else {
1170
+ canvasHeight = containerData.width / aspectRatio;
1171
+ }
1172
+ } else if (viewMode === 3) {
1173
+ canvasHeight = containerData.width / aspectRatio;
1174
+ } else {
1175
+ canvasWidth = containerData.height * aspectRatio;
1176
+ }
1177
+ var canvasData = {
1178
+ aspectRatio: aspectRatio,
1179
+ naturalWidth: naturalWidth,
1180
+ naturalHeight: naturalHeight,
1181
+ width: canvasWidth,
1182
+ height: canvasHeight
1183
+ };
1184
+ this.canvasData = canvasData;
1185
+ this.limited = viewMode === 1 || viewMode === 2;
1186
+ this.limitCanvas(true, true);
1187
+ canvasData.width = Math.min(Math.max(canvasData.width, canvasData.minWidth), canvasData.maxWidth);
1188
+ canvasData.height = Math.min(Math.max(canvasData.height, canvasData.minHeight), canvasData.maxHeight);
1189
+ canvasData.left = (containerData.width - canvasData.width) / 2;
1190
+ canvasData.top = (containerData.height - canvasData.height) / 2;
1191
+ canvasData.oldLeft = canvasData.left;
1192
+ canvasData.oldTop = canvasData.top;
1193
+ this.initialCanvasData = assign({}, canvasData);
1194
+ },
1195
+ limitCanvas: function limitCanvas(sizeLimited, positionLimited) {
1196
+ var options = this.options,
1197
+ containerData = this.containerData,
1198
+ canvasData = this.canvasData,
1199
+ cropBoxData = this.cropBoxData;
1200
+ var viewMode = options.viewMode;
1201
+ var aspectRatio = canvasData.aspectRatio;
1202
+ var cropped = this.cropped && cropBoxData;
1203
+ if (sizeLimited) {
1204
+ var minCanvasWidth = Number(options.minCanvasWidth) || 0;
1205
+ var minCanvasHeight = Number(options.minCanvasHeight) || 0;
1206
+ if (viewMode > 1) {
1207
+ minCanvasWidth = Math.max(minCanvasWidth, containerData.width);
1208
+ minCanvasHeight = Math.max(minCanvasHeight, containerData.height);
1209
+ if (viewMode === 3) {
1210
+ if (minCanvasHeight * aspectRatio > minCanvasWidth) {
1211
+ minCanvasWidth = minCanvasHeight * aspectRatio;
1212
+ } else {
1213
+ minCanvasHeight = minCanvasWidth / aspectRatio;
1214
+ }
1215
+ }
1216
+ } else if (viewMode > 0) {
1217
+ if (minCanvasWidth) {
1218
+ minCanvasWidth = Math.max(minCanvasWidth, cropped ? cropBoxData.width : 0);
1219
+ } else if (minCanvasHeight) {
1220
+ minCanvasHeight = Math.max(minCanvasHeight, cropped ? cropBoxData.height : 0);
1221
+ } else if (cropped) {
1222
+ minCanvasWidth = cropBoxData.width;
1223
+ minCanvasHeight = cropBoxData.height;
1224
+ if (minCanvasHeight * aspectRatio > minCanvasWidth) {
1225
+ minCanvasWidth = minCanvasHeight * aspectRatio;
1226
+ } else {
1227
+ minCanvasHeight = minCanvasWidth / aspectRatio;
1228
+ }
1229
+ }
1230
+ }
1231
+ var _getAdjustedSizes = getAdjustedSizes({
1232
+ aspectRatio: aspectRatio,
1233
+ width: minCanvasWidth,
1234
+ height: minCanvasHeight
1235
+ });
1236
+ minCanvasWidth = _getAdjustedSizes.width;
1237
+ minCanvasHeight = _getAdjustedSizes.height;
1238
+ canvasData.minWidth = minCanvasWidth;
1239
+ canvasData.minHeight = minCanvasHeight;
1240
+ canvasData.maxWidth = Infinity;
1241
+ canvasData.maxHeight = Infinity;
1242
+ }
1243
+ if (positionLimited) {
1244
+ if (viewMode > (cropped ? 0 : 1)) {
1245
+ var newCanvasLeft = containerData.width - canvasData.width;
1246
+ var newCanvasTop = containerData.height - canvasData.height;
1247
+ canvasData.minLeft = Math.min(0, newCanvasLeft);
1248
+ canvasData.minTop = Math.min(0, newCanvasTop);
1249
+ canvasData.maxLeft = Math.max(0, newCanvasLeft);
1250
+ canvasData.maxTop = Math.max(0, newCanvasTop);
1251
+ if (cropped && this.limited) {
1252
+ canvasData.minLeft = Math.min(cropBoxData.left, cropBoxData.left + (cropBoxData.width - canvasData.width));
1253
+ canvasData.minTop = Math.min(cropBoxData.top, cropBoxData.top + (cropBoxData.height - canvasData.height));
1254
+ canvasData.maxLeft = cropBoxData.left;
1255
+ canvasData.maxTop = cropBoxData.top;
1256
+ if (viewMode === 2) {
1257
+ if (canvasData.width >= containerData.width) {
1258
+ canvasData.minLeft = Math.min(0, newCanvasLeft);
1259
+ canvasData.maxLeft = Math.max(0, newCanvasLeft);
1260
+ }
1261
+ if (canvasData.height >= containerData.height) {
1262
+ canvasData.minTop = Math.min(0, newCanvasTop);
1263
+ canvasData.maxTop = Math.max(0, newCanvasTop);
1264
+ }
1265
+ }
1266
+ }
1267
+ } else {
1268
+ canvasData.minLeft = -canvasData.width;
1269
+ canvasData.minTop = -canvasData.height;
1270
+ canvasData.maxLeft = containerData.width;
1271
+ canvasData.maxTop = containerData.height;
1272
+ }
1273
+ }
1274
+ },
1275
+ renderCanvas: function renderCanvas(changed, transformed) {
1276
+ var canvasData = this.canvasData,
1277
+ imageData = this.imageData;
1278
+ if (transformed) {
1279
+ var _getRotatedSizes = getRotatedSizes({
1280
+ width: imageData.naturalWidth * Math.abs(imageData.scaleX || 1),
1281
+ height: imageData.naturalHeight * Math.abs(imageData.scaleY || 1),
1282
+ degree: imageData.rotate || 0
1283
+ }),
1284
+ naturalWidth = _getRotatedSizes.width,
1285
+ naturalHeight = _getRotatedSizes.height;
1286
+ var width = canvasData.width * (naturalWidth / canvasData.naturalWidth);
1287
+ var height = canvasData.height * (naturalHeight / canvasData.naturalHeight);
1288
+ canvasData.left -= (width - canvasData.width) / 2;
1289
+ canvasData.top -= (height - canvasData.height) / 2;
1290
+ canvasData.width = width;
1291
+ canvasData.height = height;
1292
+ canvasData.aspectRatio = naturalWidth / naturalHeight;
1293
+ canvasData.naturalWidth = naturalWidth;
1294
+ canvasData.naturalHeight = naturalHeight;
1295
+ this.limitCanvas(true, false);
1296
+ }
1297
+ if (canvasData.width > canvasData.maxWidth || canvasData.width < canvasData.minWidth) {
1298
+ canvasData.left = canvasData.oldLeft;
1299
+ }
1300
+ if (canvasData.height > canvasData.maxHeight || canvasData.height < canvasData.minHeight) {
1301
+ canvasData.top = canvasData.oldTop;
1302
+ }
1303
+ canvasData.width = Math.min(Math.max(canvasData.width, canvasData.minWidth), canvasData.maxWidth);
1304
+ canvasData.height = Math.min(Math.max(canvasData.height, canvasData.minHeight), canvasData.maxHeight);
1305
+ this.limitCanvas(false, true);
1306
+ canvasData.left = Math.min(Math.max(canvasData.left, canvasData.minLeft), canvasData.maxLeft);
1307
+ canvasData.top = Math.min(Math.max(canvasData.top, canvasData.minTop), canvasData.maxTop);
1308
+ canvasData.oldLeft = canvasData.left;
1309
+ canvasData.oldTop = canvasData.top;
1310
+ setStyle(this.canvas, assign({
1311
+ width: canvasData.width,
1312
+ height: canvasData.height
1313
+ }, getTransforms({
1314
+ translateX: canvasData.left,
1315
+ translateY: canvasData.top
1316
+ })));
1317
+ this.renderImage(changed);
1318
+ if (this.cropped && this.limited) {
1319
+ this.limitCropBox(true, true);
1320
+ }
1321
+ },
1322
+ renderImage: function renderImage(changed) {
1323
+ var canvasData = this.canvasData,
1324
+ imageData = this.imageData;
1325
+ var width = imageData.naturalWidth * (canvasData.width / canvasData.naturalWidth);
1326
+ var height = imageData.naturalHeight * (canvasData.height / canvasData.naturalHeight);
1327
+ assign(imageData, {
1328
+ width: width,
1329
+ height: height,
1330
+ left: (canvasData.width - width) / 2,
1331
+ top: (canvasData.height - height) / 2
1332
+ });
1333
+ setStyle(this.image, assign({
1334
+ width: imageData.width,
1335
+ height: imageData.height
1336
+ }, getTransforms(assign({
1337
+ translateX: imageData.left,
1338
+ translateY: imageData.top
1339
+ }, imageData))));
1340
+ if (changed) {
1341
+ this.output();
1342
+ }
1343
+ },
1344
+ initCropBox: function initCropBox() {
1345
+ var options = this.options,
1346
+ canvasData = this.canvasData;
1347
+ var aspectRatio = options.aspectRatio || options.initialAspectRatio;
1348
+ var autoCropArea = Number(options.autoCropArea) || 0.8;
1349
+ var cropBoxData = {
1350
+ width: canvasData.width,
1351
+ height: canvasData.height
1352
+ };
1353
+ if (aspectRatio) {
1354
+ if (canvasData.height * aspectRatio > canvasData.width) {
1355
+ cropBoxData.height = cropBoxData.width / aspectRatio;
1356
+ } else {
1357
+ cropBoxData.width = cropBoxData.height * aspectRatio;
1358
+ }
1359
+ }
1360
+ this.cropBoxData = cropBoxData;
1361
+ this.limitCropBox(true, true);
1362
+
1363
+ // Initialize auto crop area
1364
+ cropBoxData.width = Math.min(Math.max(cropBoxData.width, cropBoxData.minWidth), cropBoxData.maxWidth);
1365
+ cropBoxData.height = Math.min(Math.max(cropBoxData.height, cropBoxData.minHeight), cropBoxData.maxHeight);
1366
+
1367
+ // The width/height of auto crop area must large than "minWidth/Height"
1368
+ cropBoxData.width = Math.max(cropBoxData.minWidth, cropBoxData.width * autoCropArea);
1369
+ cropBoxData.height = Math.max(cropBoxData.minHeight, cropBoxData.height * autoCropArea);
1370
+ cropBoxData.left = canvasData.left + (canvasData.width - cropBoxData.width) / 2;
1371
+ cropBoxData.top = canvasData.top + (canvasData.height - cropBoxData.height) / 2;
1372
+ cropBoxData.oldLeft = cropBoxData.left;
1373
+ cropBoxData.oldTop = cropBoxData.top;
1374
+ this.initialCropBoxData = assign({}, cropBoxData);
1375
+ },
1376
+ limitCropBox: function limitCropBox(sizeLimited, positionLimited) {
1377
+ var options = this.options,
1378
+ containerData = this.containerData,
1379
+ canvasData = this.canvasData,
1380
+ cropBoxData = this.cropBoxData,
1381
+ limited = this.limited;
1382
+ var aspectRatio = options.aspectRatio;
1383
+ if (sizeLimited) {
1384
+ var minCropBoxWidth = Number(options.minCropBoxWidth) || 0;
1385
+ var minCropBoxHeight = Number(options.minCropBoxHeight) || 0;
1386
+ var maxCropBoxWidth = limited ? Math.min(containerData.width, canvasData.width, canvasData.width + canvasData.left, containerData.width - canvasData.left) : containerData.width;
1387
+ var maxCropBoxHeight = limited ? Math.min(containerData.height, canvasData.height, canvasData.height + canvasData.top, containerData.height - canvasData.top) : containerData.height;
1388
+
1389
+ // The min/maxCropBoxWidth/Height must be less than container's width/height
1390
+ minCropBoxWidth = Math.min(minCropBoxWidth, containerData.width);
1391
+ minCropBoxHeight = Math.min(minCropBoxHeight, containerData.height);
1392
+ if (aspectRatio) {
1393
+ if (minCropBoxWidth && minCropBoxHeight) {
1394
+ if (minCropBoxHeight * aspectRatio > minCropBoxWidth) {
1395
+ minCropBoxHeight = minCropBoxWidth / aspectRatio;
1396
+ } else {
1397
+ minCropBoxWidth = minCropBoxHeight * aspectRatio;
1398
+ }
1399
+ } else if (minCropBoxWidth) {
1400
+ minCropBoxHeight = minCropBoxWidth / aspectRatio;
1401
+ } else if (minCropBoxHeight) {
1402
+ minCropBoxWidth = minCropBoxHeight * aspectRatio;
1403
+ }
1404
+ if (maxCropBoxHeight * aspectRatio > maxCropBoxWidth) {
1405
+ maxCropBoxHeight = maxCropBoxWidth / aspectRatio;
1406
+ } else {
1407
+ maxCropBoxWidth = maxCropBoxHeight * aspectRatio;
1408
+ }
1409
+ }
1410
+
1411
+ // The minWidth/Height must be less than maxWidth/Height
1412
+ cropBoxData.minWidth = Math.min(minCropBoxWidth, maxCropBoxWidth);
1413
+ cropBoxData.minHeight = Math.min(minCropBoxHeight, maxCropBoxHeight);
1414
+ cropBoxData.maxWidth = maxCropBoxWidth;
1415
+ cropBoxData.maxHeight = maxCropBoxHeight;
1416
+ }
1417
+ if (positionLimited) {
1418
+ if (limited) {
1419
+ cropBoxData.minLeft = Math.max(0, canvasData.left);
1420
+ cropBoxData.minTop = Math.max(0, canvasData.top);
1421
+ cropBoxData.maxLeft = Math.min(containerData.width, canvasData.left + canvasData.width) - cropBoxData.width;
1422
+ cropBoxData.maxTop = Math.min(containerData.height, canvasData.top + canvasData.height) - cropBoxData.height;
1423
+ } else {
1424
+ cropBoxData.minLeft = 0;
1425
+ cropBoxData.minTop = 0;
1426
+ cropBoxData.maxLeft = containerData.width - cropBoxData.width;
1427
+ cropBoxData.maxTop = containerData.height - cropBoxData.height;
1428
+ }
1429
+ }
1430
+ },
1431
+ renderCropBox: function renderCropBox() {
1432
+ var options = this.options,
1433
+ containerData = this.containerData,
1434
+ cropBoxData = this.cropBoxData;
1435
+ if (cropBoxData.width > cropBoxData.maxWidth || cropBoxData.width < cropBoxData.minWidth) {
1436
+ cropBoxData.left = cropBoxData.oldLeft;
1437
+ }
1438
+ if (cropBoxData.height > cropBoxData.maxHeight || cropBoxData.height < cropBoxData.minHeight) {
1439
+ cropBoxData.top = cropBoxData.oldTop;
1440
+ }
1441
+ cropBoxData.width = Math.min(Math.max(cropBoxData.width, cropBoxData.minWidth), cropBoxData.maxWidth);
1442
+ cropBoxData.height = Math.min(Math.max(cropBoxData.height, cropBoxData.minHeight), cropBoxData.maxHeight);
1443
+ this.limitCropBox(false, true);
1444
+ cropBoxData.left = Math.min(Math.max(cropBoxData.left, cropBoxData.minLeft), cropBoxData.maxLeft);
1445
+ cropBoxData.top = Math.min(Math.max(cropBoxData.top, cropBoxData.minTop), cropBoxData.maxTop);
1446
+ cropBoxData.oldLeft = cropBoxData.left;
1447
+ cropBoxData.oldTop = cropBoxData.top;
1448
+ if (options.movable && options.cropBoxMovable) {
1449
+ // Turn to move the canvas when the crop box is equal to the container
1450
+ setData(this.face, DATA_ACTION, cropBoxData.width >= containerData.width && cropBoxData.height >= containerData.height ? ACTION_MOVE : ACTION_ALL);
1451
+ }
1452
+ setStyle(this.cropBox, assign({
1453
+ width: cropBoxData.width,
1454
+ height: cropBoxData.height
1455
+ }, getTransforms({
1456
+ translateX: cropBoxData.left,
1457
+ translateY: cropBoxData.top
1458
+ })));
1459
+ if (this.cropped && this.limited) {
1460
+ this.limitCanvas(true, true);
1461
+ }
1462
+ if (!this.disabled) {
1463
+ this.output();
1464
+ }
1465
+ },
1466
+ output: function output() {
1467
+ this.preview();
1468
+ dispatchEvent(this.element, EVENT_CROP, this.getData());
1469
+ }
1470
+ };
1471
+
1472
+ var preview = {
1473
+ initPreview: function initPreview() {
1474
+ var element = this.element,
1475
+ crossOrigin = this.crossOrigin;
1476
+ var preview = this.options.preview;
1477
+ var url = crossOrigin ? this.crossOriginUrl : this.url;
1478
+ var alt = element.alt || 'The image to preview';
1479
+ var image = document.createElement('img');
1480
+ if (crossOrigin) {
1481
+ image.crossOrigin = crossOrigin;
1482
+ }
1483
+ image.src = url;
1484
+ image.alt = alt;
1485
+ this.viewBox.appendChild(image);
1486
+ this.viewBoxImage = image;
1487
+ if (!preview) {
1488
+ return;
1489
+ }
1490
+ var previews = preview;
1491
+ if (typeof preview === 'string') {
1492
+ previews = element.ownerDocument.querySelectorAll(preview);
1493
+ } else if (preview.querySelector) {
1494
+ previews = [preview];
1495
+ }
1496
+ this.previews = previews;
1497
+ forEach(previews, function (el) {
1498
+ var img = document.createElement('img');
1499
+
1500
+ // Save the original size for recover
1501
+ setData(el, DATA_PREVIEW, {
1502
+ width: el.offsetWidth,
1503
+ height: el.offsetHeight,
1504
+ html: el.innerHTML
1505
+ });
1506
+ if (crossOrigin) {
1507
+ img.crossOrigin = crossOrigin;
1508
+ }
1509
+ img.src = url;
1510
+ img.alt = alt;
1511
+
1512
+ /**
1513
+ * Override img element styles
1514
+ * Add `display:block` to avoid margin top issue
1515
+ * Add `height:auto` to override `height` attribute on IE8
1516
+ * (Occur only when margin-top <= -height)
1517
+ */
1518
+ img.style.cssText = 'display:block;' + 'width:100%;' + 'height:auto;' + 'min-width:0!important;' + 'min-height:0!important;' + 'max-width:none!important;' + 'max-height:none!important;' + 'image-orientation:0deg!important;"';
1519
+ el.innerHTML = '';
1520
+ el.appendChild(img);
1521
+ });
1522
+ },
1523
+ resetPreview: function resetPreview() {
1524
+ forEach(this.previews, function (element) {
1525
+ var data = getData(element, DATA_PREVIEW);
1526
+ setStyle(element, {
1527
+ width: data.width,
1528
+ height: data.height
1529
+ });
1530
+ element.innerHTML = data.html;
1531
+ removeData(element, DATA_PREVIEW);
1532
+ });
1533
+ },
1534
+ preview: function preview() {
1535
+ var imageData = this.imageData,
1536
+ canvasData = this.canvasData,
1537
+ cropBoxData = this.cropBoxData;
1538
+ var cropBoxWidth = cropBoxData.width,
1539
+ cropBoxHeight = cropBoxData.height;
1540
+ var width = imageData.width,
1541
+ height = imageData.height;
1542
+ var left = cropBoxData.left - canvasData.left - imageData.left;
1543
+ var top = cropBoxData.top - canvasData.top - imageData.top;
1544
+ if (!this.cropped || this.disabled) {
1545
+ return;
1546
+ }
1547
+ setStyle(this.viewBoxImage, assign({
1548
+ width: width,
1549
+ height: height
1550
+ }, getTransforms(assign({
1551
+ translateX: -left,
1552
+ translateY: -top
1553
+ }, imageData))));
1554
+ forEach(this.previews, function (element) {
1555
+ var data = getData(element, DATA_PREVIEW);
1556
+ var originalWidth = data.width;
1557
+ var originalHeight = data.height;
1558
+ var newWidth = originalWidth;
1559
+ var newHeight = originalHeight;
1560
+ var ratio = 1;
1561
+ if (cropBoxWidth) {
1562
+ ratio = originalWidth / cropBoxWidth;
1563
+ newHeight = cropBoxHeight * ratio;
1564
+ }
1565
+ if (cropBoxHeight && newHeight > originalHeight) {
1566
+ ratio = originalHeight / cropBoxHeight;
1567
+ newWidth = cropBoxWidth * ratio;
1568
+ newHeight = originalHeight;
1569
+ }
1570
+ setStyle(element, {
1571
+ width: newWidth,
1572
+ height: newHeight
1573
+ });
1574
+ setStyle(element.getElementsByTagName('img')[0], assign({
1575
+ width: width * ratio,
1576
+ height: height * ratio
1577
+ }, getTransforms(assign({
1578
+ translateX: -left * ratio,
1579
+ translateY: -top * ratio
1580
+ }, imageData))));
1581
+ });
1582
+ }
1583
+ };
1584
+
1585
+ var events = {
1586
+ bind: function bind() {
1587
+ var element = this.element,
1588
+ options = this.options,
1589
+ cropper = this.cropper;
1590
+ if (isFunction(options.cropstart)) {
1591
+ addListener(element, EVENT_CROP_START, options.cropstart);
1592
+ }
1593
+ if (isFunction(options.cropmove)) {
1594
+ addListener(element, EVENT_CROP_MOVE, options.cropmove);
1595
+ }
1596
+ if (isFunction(options.cropend)) {
1597
+ addListener(element, EVENT_CROP_END, options.cropend);
1598
+ }
1599
+ if (isFunction(options.crop)) {
1600
+ addListener(element, EVENT_CROP, options.crop);
1601
+ }
1602
+ if (isFunction(options.zoom)) {
1603
+ addListener(element, EVENT_ZOOM, options.zoom);
1604
+ }
1605
+ addListener(cropper, EVENT_POINTER_DOWN, this.onCropStart = this.cropStart.bind(this));
1606
+ if (options.zoomable && options.zoomOnWheel) {
1607
+ addListener(cropper, EVENT_WHEEL, this.onWheel = this.wheel.bind(this), {
1608
+ passive: false,
1609
+ capture: true
1610
+ });
1611
+ }
1612
+ if (options.toggleDragModeOnDblclick) {
1613
+ addListener(cropper, EVENT_DBLCLICK, this.onDblclick = this.dblclick.bind(this));
1614
+ }
1615
+ addListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onCropMove = this.cropMove.bind(this));
1616
+ addListener(element.ownerDocument, EVENT_POINTER_UP, this.onCropEnd = this.cropEnd.bind(this));
1617
+ if (options.responsive) {
1618
+ addListener(window, EVENT_RESIZE, this.onResize = this.resize.bind(this));
1619
+ }
1620
+ },
1621
+ unbind: function unbind() {
1622
+ var element = this.element,
1623
+ options = this.options,
1624
+ cropper = this.cropper;
1625
+ if (isFunction(options.cropstart)) {
1626
+ removeListener(element, EVENT_CROP_START, options.cropstart);
1627
+ }
1628
+ if (isFunction(options.cropmove)) {
1629
+ removeListener(element, EVENT_CROP_MOVE, options.cropmove);
1630
+ }
1631
+ if (isFunction(options.cropend)) {
1632
+ removeListener(element, EVENT_CROP_END, options.cropend);
1633
+ }
1634
+ if (isFunction(options.crop)) {
1635
+ removeListener(element, EVENT_CROP, options.crop);
1636
+ }
1637
+ if (isFunction(options.zoom)) {
1638
+ removeListener(element, EVENT_ZOOM, options.zoom);
1639
+ }
1640
+ removeListener(cropper, EVENT_POINTER_DOWN, this.onCropStart);
1641
+ if (options.zoomable && options.zoomOnWheel) {
1642
+ removeListener(cropper, EVENT_WHEEL, this.onWheel, {
1643
+ passive: false,
1644
+ capture: true
1645
+ });
1646
+ }
1647
+ if (options.toggleDragModeOnDblclick) {
1648
+ removeListener(cropper, EVENT_DBLCLICK, this.onDblclick);
1649
+ }
1650
+ removeListener(element.ownerDocument, EVENT_POINTER_MOVE, this.onCropMove);
1651
+ removeListener(element.ownerDocument, EVENT_POINTER_UP, this.onCropEnd);
1652
+ if (options.responsive) {
1653
+ removeListener(window, EVENT_RESIZE, this.onResize);
1654
+ }
1655
+ }
1656
+ };
1657
+
1658
+ var handlers = {
1659
+ resize: function resize() {
1660
+ if (this.disabled) {
1661
+ return;
1662
+ }
1663
+ var options = this.options,
1664
+ container = this.container,
1665
+ containerData = this.containerData;
1666
+ var ratioX = container.offsetWidth / containerData.width;
1667
+ var ratioY = container.offsetHeight / containerData.height;
1668
+ var ratio = Math.abs(ratioX - 1) > Math.abs(ratioY - 1) ? ratioX : ratioY;
1669
+
1670
+ // Resize when width changed or height changed
1671
+ if (ratio !== 1) {
1672
+ var canvasData;
1673
+ var cropBoxData;
1674
+ if (options.restore) {
1675
+ canvasData = this.getCanvasData();
1676
+ cropBoxData = this.getCropBoxData();
1677
+ }
1678
+ this.render();
1679
+ if (options.restore) {
1680
+ this.setCanvasData(forEach(canvasData, function (n, i) {
1681
+ canvasData[i] = n * ratio;
1682
+ }));
1683
+ this.setCropBoxData(forEach(cropBoxData, function (n, i) {
1684
+ cropBoxData[i] = n * ratio;
1685
+ }));
1686
+ }
1687
+ }
1688
+ },
1689
+ dblclick: function dblclick() {
1690
+ if (this.disabled || this.options.dragMode === DRAG_MODE_NONE) {
1691
+ return;
1692
+ }
1693
+ this.setDragMode(hasClass(this.dragBox, CLASS_CROP) ? DRAG_MODE_MOVE : DRAG_MODE_CROP);
1694
+ },
1695
+ wheel: function wheel(event) {
1696
+ var _this = this;
1697
+ var ratio = Number(this.options.wheelZoomRatio) || 0.1;
1698
+ var delta = 1;
1699
+ if (this.disabled) {
1700
+ return;
1701
+ }
1702
+ event.preventDefault();
1703
+
1704
+ // Limit wheel speed to prevent zoom too fast (#21)
1705
+ if (this.wheeling) {
1706
+ return;
1707
+ }
1708
+ this.wheeling = true;
1709
+ setTimeout(function () {
1710
+ _this.wheeling = false;
1711
+ }, 50);
1712
+ if (event.deltaY) {
1713
+ delta = event.deltaY > 0 ? 1 : -1;
1714
+ } else if (event.wheelDelta) {
1715
+ delta = -event.wheelDelta / 120;
1716
+ } else if (event.detail) {
1717
+ delta = event.detail > 0 ? 1 : -1;
1718
+ }
1719
+ this.zoom(-delta * ratio, event);
1720
+ },
1721
+ cropStart: function cropStart(event) {
1722
+ var buttons = event.buttons,
1723
+ button = event.button;
1724
+ if (this.disabled
1725
+
1726
+ // Handle mouse event and pointer event and ignore touch event
1727
+ || (event.type === 'mousedown' || event.type === 'pointerdown' && event.pointerType === 'mouse') && (
1728
+ // No primary button (Usually the left button)
1729
+ isNumber(buttons) && buttons !== 1 || isNumber(button) && button !== 0
1730
+
1731
+ // Open context menu
1732
+ || event.ctrlKey)) {
1733
+ return;
1734
+ }
1735
+ var options = this.options,
1736
+ pointers = this.pointers;
1737
+ var action;
1738
+ if (event.changedTouches) {
1739
+ // Handle touch event
1740
+ forEach(event.changedTouches, function (touch) {
1741
+ pointers[touch.identifier] = getPointer(touch);
1742
+ });
1743
+ } else {
1744
+ // Handle mouse event and pointer event
1745
+ pointers[event.pointerId || 0] = getPointer(event);
1746
+ }
1747
+ if (Object.keys(pointers).length > 1 && options.zoomable && options.zoomOnTouch) {
1748
+ action = ACTION_ZOOM;
1749
+ } else {
1750
+ action = getData(event.target, DATA_ACTION);
1751
+ }
1752
+ if (!REGEXP_ACTIONS.test(action)) {
1753
+ return;
1754
+ }
1755
+ if (dispatchEvent(this.element, EVENT_CROP_START, {
1756
+ originalEvent: event,
1757
+ action: action
1758
+ }) === false) {
1759
+ return;
1760
+ }
1761
+
1762
+ // This line is required for preventing page zooming in iOS browsers
1763
+ event.preventDefault();
1764
+ this.action = action;
1765
+ this.cropping = false;
1766
+ if (action === ACTION_CROP) {
1767
+ this.cropping = true;
1768
+ addClass(this.dragBox, CLASS_MODAL);
1769
+ }
1770
+ },
1771
+ cropMove: function cropMove(event) {
1772
+ var action = this.action;
1773
+ if (this.disabled || !action) {
1774
+ return;
1775
+ }
1776
+ var pointers = this.pointers;
1777
+ event.preventDefault();
1778
+ if (dispatchEvent(this.element, EVENT_CROP_MOVE, {
1779
+ originalEvent: event,
1780
+ action: action
1781
+ }) === false) {
1782
+ return;
1783
+ }
1784
+ if (event.changedTouches) {
1785
+ forEach(event.changedTouches, function (touch) {
1786
+ // The first parameter should not be undefined (#432)
1787
+ assign(pointers[touch.identifier] || {}, getPointer(touch, true));
1788
+ });
1789
+ } else {
1790
+ assign(pointers[event.pointerId || 0] || {}, getPointer(event, true));
1791
+ }
1792
+ this.change(event);
1793
+ },
1794
+ cropEnd: function cropEnd(event) {
1795
+ if (this.disabled) {
1796
+ return;
1797
+ }
1798
+ var action = this.action,
1799
+ pointers = this.pointers;
1800
+ if (event.changedTouches) {
1801
+ forEach(event.changedTouches, function (touch) {
1802
+ delete pointers[touch.identifier];
1803
+ });
1804
+ } else {
1805
+ delete pointers[event.pointerId || 0];
1806
+ }
1807
+ if (!action) {
1808
+ return;
1809
+ }
1810
+ event.preventDefault();
1811
+ if (!Object.keys(pointers).length) {
1812
+ this.action = '';
1813
+ }
1814
+ if (this.cropping) {
1815
+ this.cropping = false;
1816
+ toggleClass(this.dragBox, CLASS_MODAL, this.cropped && this.options.modal);
1817
+ }
1818
+ dispatchEvent(this.element, EVENT_CROP_END, {
1819
+ originalEvent: event,
1820
+ action: action
1821
+ });
1822
+ }
1823
+ };
1824
+
1825
+ var change = {
1826
+ change: function change(event) {
1827
+ var options = this.options,
1828
+ canvasData = this.canvasData,
1829
+ containerData = this.containerData,
1830
+ cropBoxData = this.cropBoxData,
1831
+ pointers = this.pointers;
1832
+ var action = this.action;
1833
+ var aspectRatio = options.aspectRatio;
1834
+ var left = cropBoxData.left,
1835
+ top = cropBoxData.top,
1836
+ width = cropBoxData.width,
1837
+ height = cropBoxData.height;
1838
+ var right = left + width;
1839
+ var bottom = top + height;
1840
+ var minLeft = 0;
1841
+ var minTop = 0;
1842
+ var maxWidth = containerData.width;
1843
+ var maxHeight = containerData.height;
1844
+ var renderable = true;
1845
+ var offset;
1846
+
1847
+ // Locking aspect ratio in "free mode" by holding shift key
1848
+ if (!aspectRatio && event.shiftKey) {
1849
+ aspectRatio = width && height ? width / height : 1;
1850
+ }
1851
+ if (this.limited) {
1852
+ minLeft = cropBoxData.minLeft;
1853
+ minTop = cropBoxData.minTop;
1854
+ maxWidth = minLeft + Math.min(containerData.width, canvasData.width, canvasData.left + canvasData.width);
1855
+ maxHeight = minTop + Math.min(containerData.height, canvasData.height, canvasData.top + canvasData.height);
1856
+ }
1857
+ var pointer = pointers[Object.keys(pointers)[0]];
1858
+ var range = {
1859
+ x: pointer.endX - pointer.startX,
1860
+ y: pointer.endY - pointer.startY
1861
+ };
1862
+ var check = function check(side) {
1863
+ switch (side) {
1864
+ case ACTION_EAST:
1865
+ if (right + range.x > maxWidth) {
1866
+ range.x = maxWidth - right;
1867
+ }
1868
+ break;
1869
+ case ACTION_WEST:
1870
+ if (left + range.x < minLeft) {
1871
+ range.x = minLeft - left;
1872
+ }
1873
+ break;
1874
+ case ACTION_NORTH:
1875
+ if (top + range.y < minTop) {
1876
+ range.y = minTop - top;
1877
+ }
1878
+ break;
1879
+ case ACTION_SOUTH:
1880
+ if (bottom + range.y > maxHeight) {
1881
+ range.y = maxHeight - bottom;
1882
+ }
1883
+ break;
1884
+ }
1885
+ };
1886
+ switch (action) {
1887
+ // Move crop box
1888
+ case ACTION_ALL:
1889
+ left += range.x;
1890
+ top += range.y;
1891
+ break;
1892
+
1893
+ // Resize crop box
1894
+ case ACTION_EAST:
1895
+ if (range.x >= 0 && (right >= maxWidth || aspectRatio && (top <= minTop || bottom >= maxHeight))) {
1896
+ renderable = false;
1897
+ break;
1898
+ }
1899
+ check(ACTION_EAST);
1900
+ width += range.x;
1901
+ if (width < 0) {
1902
+ action = ACTION_WEST;
1903
+ width = -width;
1904
+ left -= width;
1905
+ }
1906
+ if (aspectRatio) {
1907
+ height = width / aspectRatio;
1908
+ top += (cropBoxData.height - height) / 2;
1909
+ }
1910
+ break;
1911
+ case ACTION_NORTH:
1912
+ if (range.y <= 0 && (top <= minTop || aspectRatio && (left <= minLeft || right >= maxWidth))) {
1913
+ renderable = false;
1914
+ break;
1915
+ }
1916
+ check(ACTION_NORTH);
1917
+ height -= range.y;
1918
+ top += range.y;
1919
+ if (height < 0) {
1920
+ action = ACTION_SOUTH;
1921
+ height = -height;
1922
+ top -= height;
1923
+ }
1924
+ if (aspectRatio) {
1925
+ width = height * aspectRatio;
1926
+ left += (cropBoxData.width - width) / 2;
1927
+ }
1928
+ break;
1929
+ case ACTION_WEST:
1930
+ if (range.x <= 0 && (left <= minLeft || aspectRatio && (top <= minTop || bottom >= maxHeight))) {
1931
+ renderable = false;
1932
+ break;
1933
+ }
1934
+ check(ACTION_WEST);
1935
+ width -= range.x;
1936
+ left += range.x;
1937
+ if (width < 0) {
1938
+ action = ACTION_EAST;
1939
+ width = -width;
1940
+ left -= width;
1941
+ }
1942
+ if (aspectRatio) {
1943
+ height = width / aspectRatio;
1944
+ top += (cropBoxData.height - height) / 2;
1945
+ }
1946
+ break;
1947
+ case ACTION_SOUTH:
1948
+ if (range.y >= 0 && (bottom >= maxHeight || aspectRatio && (left <= minLeft || right >= maxWidth))) {
1949
+ renderable = false;
1950
+ break;
1951
+ }
1952
+ check(ACTION_SOUTH);
1953
+ height += range.y;
1954
+ if (height < 0) {
1955
+ action = ACTION_NORTH;
1956
+ height = -height;
1957
+ top -= height;
1958
+ }
1959
+ if (aspectRatio) {
1960
+ width = height * aspectRatio;
1961
+ left += (cropBoxData.width - width) / 2;
1962
+ }
1963
+ break;
1964
+ case ACTION_NORTH_EAST:
1965
+ if (aspectRatio) {
1966
+ if (range.y <= 0 && (top <= minTop || right >= maxWidth)) {
1967
+ renderable = false;
1968
+ break;
1969
+ }
1970
+ check(ACTION_NORTH);
1971
+ height -= range.y;
1972
+ top += range.y;
1973
+ width = height * aspectRatio;
1974
+ } else {
1975
+ check(ACTION_NORTH);
1976
+ check(ACTION_EAST);
1977
+ if (range.x >= 0) {
1978
+ if (right < maxWidth) {
1979
+ width += range.x;
1980
+ } else if (range.y <= 0 && top <= minTop) {
1981
+ renderable = false;
1982
+ }
1983
+ } else {
1984
+ width += range.x;
1985
+ }
1986
+ if (range.y <= 0) {
1987
+ if (top > minTop) {
1988
+ height -= range.y;
1989
+ top += range.y;
1990
+ }
1991
+ } else {
1992
+ height -= range.y;
1993
+ top += range.y;
1994
+ }
1995
+ }
1996
+ if (width < 0 && height < 0) {
1997
+ action = ACTION_SOUTH_WEST;
1998
+ height = -height;
1999
+ width = -width;
2000
+ top -= height;
2001
+ left -= width;
2002
+ } else if (width < 0) {
2003
+ action = ACTION_NORTH_WEST;
2004
+ width = -width;
2005
+ left -= width;
2006
+ } else if (height < 0) {
2007
+ action = ACTION_SOUTH_EAST;
2008
+ height = -height;
2009
+ top -= height;
2010
+ }
2011
+ break;
2012
+ case ACTION_NORTH_WEST:
2013
+ if (aspectRatio) {
2014
+ if (range.y <= 0 && (top <= minTop || left <= minLeft)) {
2015
+ renderable = false;
2016
+ break;
2017
+ }
2018
+ check(ACTION_NORTH);
2019
+ height -= range.y;
2020
+ top += range.y;
2021
+ width = height * aspectRatio;
2022
+ left += cropBoxData.width - width;
2023
+ } else {
2024
+ check(ACTION_NORTH);
2025
+ check(ACTION_WEST);
2026
+ if (range.x <= 0) {
2027
+ if (left > minLeft) {
2028
+ width -= range.x;
2029
+ left += range.x;
2030
+ } else if (range.y <= 0 && top <= minTop) {
2031
+ renderable = false;
2032
+ }
2033
+ } else {
2034
+ width -= range.x;
2035
+ left += range.x;
2036
+ }
2037
+ if (range.y <= 0) {
2038
+ if (top > minTop) {
2039
+ height -= range.y;
2040
+ top += range.y;
2041
+ }
2042
+ } else {
2043
+ height -= range.y;
2044
+ top += range.y;
2045
+ }
2046
+ }
2047
+ if (width < 0 && height < 0) {
2048
+ action = ACTION_SOUTH_EAST;
2049
+ height = -height;
2050
+ width = -width;
2051
+ top -= height;
2052
+ left -= width;
2053
+ } else if (width < 0) {
2054
+ action = ACTION_NORTH_EAST;
2055
+ width = -width;
2056
+ left -= width;
2057
+ } else if (height < 0) {
2058
+ action = ACTION_SOUTH_WEST;
2059
+ height = -height;
2060
+ top -= height;
2061
+ }
2062
+ break;
2063
+ case ACTION_SOUTH_WEST:
2064
+ if (aspectRatio) {
2065
+ if (range.x <= 0 && (left <= minLeft || bottom >= maxHeight)) {
2066
+ renderable = false;
2067
+ break;
2068
+ }
2069
+ check(ACTION_WEST);
2070
+ width -= range.x;
2071
+ left += range.x;
2072
+ height = width / aspectRatio;
2073
+ } else {
2074
+ check(ACTION_SOUTH);
2075
+ check(ACTION_WEST);
2076
+ if (range.x <= 0) {
2077
+ if (left > minLeft) {
2078
+ width -= range.x;
2079
+ left += range.x;
2080
+ } else if (range.y >= 0 && bottom >= maxHeight) {
2081
+ renderable = false;
2082
+ }
2083
+ } else {
2084
+ width -= range.x;
2085
+ left += range.x;
2086
+ }
2087
+ if (range.y >= 0) {
2088
+ if (bottom < maxHeight) {
2089
+ height += range.y;
2090
+ }
2091
+ } else {
2092
+ height += range.y;
2093
+ }
2094
+ }
2095
+ if (width < 0 && height < 0) {
2096
+ action = ACTION_NORTH_EAST;
2097
+ height = -height;
2098
+ width = -width;
2099
+ top -= height;
2100
+ left -= width;
2101
+ } else if (width < 0) {
2102
+ action = ACTION_SOUTH_EAST;
2103
+ width = -width;
2104
+ left -= width;
2105
+ } else if (height < 0) {
2106
+ action = ACTION_NORTH_WEST;
2107
+ height = -height;
2108
+ top -= height;
2109
+ }
2110
+ break;
2111
+ case ACTION_SOUTH_EAST:
2112
+ if (aspectRatio) {
2113
+ if (range.x >= 0 && (right >= maxWidth || bottom >= maxHeight)) {
2114
+ renderable = false;
2115
+ break;
2116
+ }
2117
+ check(ACTION_EAST);
2118
+ width += range.x;
2119
+ height = width / aspectRatio;
2120
+ } else {
2121
+ check(ACTION_SOUTH);
2122
+ check(ACTION_EAST);
2123
+ if (range.x >= 0) {
2124
+ if (right < maxWidth) {
2125
+ width += range.x;
2126
+ } else if (range.y >= 0 && bottom >= maxHeight) {
2127
+ renderable = false;
2128
+ }
2129
+ } else {
2130
+ width += range.x;
2131
+ }
2132
+ if (range.y >= 0) {
2133
+ if (bottom < maxHeight) {
2134
+ height += range.y;
2135
+ }
2136
+ } else {
2137
+ height += range.y;
2138
+ }
2139
+ }
2140
+ if (width < 0 && height < 0) {
2141
+ action = ACTION_NORTH_WEST;
2142
+ height = -height;
2143
+ width = -width;
2144
+ top -= height;
2145
+ left -= width;
2146
+ } else if (width < 0) {
2147
+ action = ACTION_SOUTH_WEST;
2148
+ width = -width;
2149
+ left -= width;
2150
+ } else if (height < 0) {
2151
+ action = ACTION_NORTH_EAST;
2152
+ height = -height;
2153
+ top -= height;
2154
+ }
2155
+ break;
2156
+
2157
+ // Move canvas
2158
+ case ACTION_MOVE:
2159
+ this.move(range.x, range.y);
2160
+ renderable = false;
2161
+ break;
2162
+
2163
+ // Zoom canvas
2164
+ case ACTION_ZOOM:
2165
+ this.zoom(getMaxZoomRatio(pointers), event);
2166
+ renderable = false;
2167
+ break;
2168
+
2169
+ // Create crop box
2170
+ case ACTION_CROP:
2171
+ if (!range.x || !range.y) {
2172
+ renderable = false;
2173
+ break;
2174
+ }
2175
+ offset = getOffset(this.cropper);
2176
+ left = pointer.startX - offset.left;
2177
+ top = pointer.startY - offset.top;
2178
+ width = cropBoxData.minWidth;
2179
+ height = cropBoxData.minHeight;
2180
+ if (range.x > 0) {
2181
+ action = range.y > 0 ? ACTION_SOUTH_EAST : ACTION_NORTH_EAST;
2182
+ } else if (range.x < 0) {
2183
+ left -= width;
2184
+ action = range.y > 0 ? ACTION_SOUTH_WEST : ACTION_NORTH_WEST;
2185
+ }
2186
+ if (range.y < 0) {
2187
+ top -= height;
2188
+ }
2189
+
2190
+ // Show the crop box if is hidden
2191
+ if (!this.cropped) {
2192
+ removeClass(this.cropBox, CLASS_HIDDEN);
2193
+ this.cropped = true;
2194
+ if (this.limited) {
2195
+ this.limitCropBox(true, true);
2196
+ }
2197
+ }
2198
+ break;
2199
+ }
2200
+ if (renderable) {
2201
+ cropBoxData.width = width;
2202
+ cropBoxData.height = height;
2203
+ cropBoxData.left = left;
2204
+ cropBoxData.top = top;
2205
+ this.action = action;
2206
+ this.renderCropBox();
2207
+ }
2208
+
2209
+ // Override
2210
+ forEach(pointers, function (p) {
2211
+ p.startX = p.endX;
2212
+ p.startY = p.endY;
2213
+ });
2214
+ }
2215
+ };
2216
+
2217
+ var methods = {
2218
+ // Show the crop box manually
2219
+ crop: function crop() {
2220
+ if (this.ready && !this.cropped && !this.disabled) {
2221
+ this.cropped = true;
2222
+ this.limitCropBox(true, true);
2223
+ if (this.options.modal) {
2224
+ addClass(this.dragBox, CLASS_MODAL);
2225
+ }
2226
+ removeClass(this.cropBox, CLASS_HIDDEN);
2227
+ this.setCropBoxData(this.initialCropBoxData);
2228
+ }
2229
+ return this;
2230
+ },
2231
+ // Reset the image and crop box to their initial states
2232
+ reset: function reset() {
2233
+ if (this.ready && !this.disabled) {
2234
+ this.imageData = assign({}, this.initialImageData);
2235
+ this.canvasData = assign({}, this.initialCanvasData);
2236
+ this.cropBoxData = assign({}, this.initialCropBoxData);
2237
+ this.renderCanvas();
2238
+ if (this.cropped) {
2239
+ this.renderCropBox();
2240
+ }
2241
+ }
2242
+ return this;
2243
+ },
2244
+ // Clear the crop box
2245
+ clear: function clear() {
2246
+ if (this.cropped && !this.disabled) {
2247
+ assign(this.cropBoxData, {
2248
+ left: 0,
2249
+ top: 0,
2250
+ width: 0,
2251
+ height: 0
2252
+ });
2253
+ this.cropped = false;
2254
+ this.renderCropBox();
2255
+ this.limitCanvas(true, true);
2256
+
2257
+ // Render canvas after crop box rendered
2258
+ this.renderCanvas();
2259
+ removeClass(this.dragBox, CLASS_MODAL);
2260
+ addClass(this.cropBox, CLASS_HIDDEN);
2261
+ }
2262
+ return this;
2263
+ },
2264
+ /**
2265
+ * Replace the image's src and rebuild the cropper
2266
+ * @param {string} url - The new URL.
2267
+ * @param {boolean} [hasSameSize] - Indicate if the new image has the same size as the old one.
2268
+ * @returns {Cropper} this
2269
+ */
2270
+ replace: function replace(url) {
2271
+ var hasSameSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
2272
+ if (!this.disabled && url) {
2273
+ if (this.isImg) {
2274
+ this.element.src = url;
2275
+ }
2276
+ if (hasSameSize) {
2277
+ this.url = url;
2278
+ this.image.src = url;
2279
+ if (this.ready) {
2280
+ this.viewBoxImage.src = url;
2281
+ forEach(this.previews, function (element) {
2282
+ element.getElementsByTagName('img')[0].src = url;
2283
+ });
2284
+ }
2285
+ } else {
2286
+ if (this.isImg) {
2287
+ this.replaced = true;
2288
+ }
2289
+ this.options.data = null;
2290
+ this.uncreate();
2291
+ this.load(url);
2292
+ }
2293
+ }
2294
+ return this;
2295
+ },
2296
+ // Enable (unfreeze) the cropper
2297
+ enable: function enable() {
2298
+ if (this.ready && this.disabled) {
2299
+ this.disabled = false;
2300
+ removeClass(this.cropper, CLASS_DISABLED);
2301
+ }
2302
+ return this;
2303
+ },
2304
+ // Disable (freeze) the cropper
2305
+ disable: function disable() {
2306
+ if (this.ready && !this.disabled) {
2307
+ this.disabled = true;
2308
+ addClass(this.cropper, CLASS_DISABLED);
2309
+ }
2310
+ return this;
2311
+ },
2312
+ /**
2313
+ * Destroy the cropper and remove the instance from the image
2314
+ * @returns {Cropper} this
2315
+ */
2316
+ destroy: function destroy() {
2317
+ var element = this.element;
2318
+ if (!element[NAMESPACE]) {
2319
+ return this;
2320
+ }
2321
+ element[NAMESPACE] = undefined;
2322
+ if (this.isImg && this.replaced) {
2323
+ element.src = this.originalUrl;
2324
+ }
2325
+ this.uncreate();
2326
+ return this;
2327
+ },
2328
+ /**
2329
+ * Move the canvas with relative offsets
2330
+ * @param {number} offsetX - The relative offset distance on the x-axis.
2331
+ * @param {number} [offsetY=offsetX] - The relative offset distance on the y-axis.
2332
+ * @returns {Cropper} this
2333
+ */
2334
+ move: function move(offsetX) {
2335
+ var offsetY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : offsetX;
2336
+ var _this$canvasData = this.canvasData,
2337
+ left = _this$canvasData.left,
2338
+ top = _this$canvasData.top;
2339
+ return this.moveTo(isUndefined(offsetX) ? offsetX : left + Number(offsetX), isUndefined(offsetY) ? offsetY : top + Number(offsetY));
2340
+ },
2341
+ /**
2342
+ * Move the canvas to an absolute point
2343
+ * @param {number} x - The x-axis coordinate.
2344
+ * @param {number} [y=x] - The y-axis coordinate.
2345
+ * @returns {Cropper} this
2346
+ */
2347
+ moveTo: function moveTo(x) {
2348
+ var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x;
2349
+ var canvasData = this.canvasData;
2350
+ var changed = false;
2351
+ x = Number(x);
2352
+ y = Number(y);
2353
+ if (this.ready && !this.disabled && this.options.movable) {
2354
+ if (isNumber(x)) {
2355
+ canvasData.left = x;
2356
+ changed = true;
2357
+ }
2358
+ if (isNumber(y)) {
2359
+ canvasData.top = y;
2360
+ changed = true;
2361
+ }
2362
+ if (changed) {
2363
+ this.renderCanvas(true);
2364
+ }
2365
+ }
2366
+ return this;
2367
+ },
2368
+ /**
2369
+ * Zoom the canvas with a relative ratio
2370
+ * @param {number} ratio - The target ratio.
2371
+ * @param {Event} _originalEvent - The original event if any.
2372
+ * @returns {Cropper} this
2373
+ */
2374
+ zoom: function zoom(ratio, _originalEvent) {
2375
+ var canvasData = this.canvasData;
2376
+ ratio = Number(ratio);
2377
+ if (ratio < 0) {
2378
+ ratio = 1 / (1 - ratio);
2379
+ } else {
2380
+ ratio = 1 + ratio;
2381
+ }
2382
+ return this.zoomTo(canvasData.width * ratio / canvasData.naturalWidth, null, _originalEvent);
2383
+ },
2384
+ /**
2385
+ * Zoom the canvas to an absolute ratio
2386
+ * @param {number} ratio - The target ratio.
2387
+ * @param {Object} pivot - The zoom pivot point coordinate.
2388
+ * @param {Event} _originalEvent - The original event if any.
2389
+ * @returns {Cropper} this
2390
+ */
2391
+ zoomTo: function zoomTo(ratio, pivot, _originalEvent) {
2392
+ var options = this.options,
2393
+ canvasData = this.canvasData;
2394
+ var width = canvasData.width,
2395
+ height = canvasData.height,
2396
+ naturalWidth = canvasData.naturalWidth,
2397
+ naturalHeight = canvasData.naturalHeight;
2398
+ ratio = Number(ratio);
2399
+ if (ratio >= 0 && this.ready && !this.disabled && options.zoomable) {
2400
+ var newWidth = naturalWidth * ratio;
2401
+ var newHeight = naturalHeight * ratio;
2402
+ if (dispatchEvent(this.element, EVENT_ZOOM, {
2403
+ ratio: ratio,
2404
+ oldRatio: width / naturalWidth,
2405
+ originalEvent: _originalEvent
2406
+ }) === false) {
2407
+ return this;
2408
+ }
2409
+ if (_originalEvent) {
2410
+ var pointers = this.pointers;
2411
+ var offset = getOffset(this.cropper);
2412
+ var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : {
2413
+ pageX: _originalEvent.pageX,
2414
+ pageY: _originalEvent.pageY
2415
+ };
2416
+
2417
+ // Zoom from the triggering point of the event
2418
+ canvasData.left -= (newWidth - width) * ((center.pageX - offset.left - canvasData.left) / width);
2419
+ canvasData.top -= (newHeight - height) * ((center.pageY - offset.top - canvasData.top) / height);
2420
+ } else if (isPlainObject(pivot) && isNumber(pivot.x) && isNumber(pivot.y)) {
2421
+ canvasData.left -= (newWidth - width) * ((pivot.x - canvasData.left) / width);
2422
+ canvasData.top -= (newHeight - height) * ((pivot.y - canvasData.top) / height);
2423
+ } else {
2424
+ // Zoom from the center of the canvas
2425
+ canvasData.left -= (newWidth - width) / 2;
2426
+ canvasData.top -= (newHeight - height) / 2;
2427
+ }
2428
+ canvasData.width = newWidth;
2429
+ canvasData.height = newHeight;
2430
+ this.renderCanvas(true);
2431
+ }
2432
+ return this;
2433
+ },
2434
+ /**
2435
+ * Rotate the canvas with a relative degree
2436
+ * @param {number} degree - The rotate degree.
2437
+ * @returns {Cropper} this
2438
+ */
2439
+ rotate: function rotate(degree) {
2440
+ return this.rotateTo((this.imageData.rotate || 0) + Number(degree));
2441
+ },
2442
+ /**
2443
+ * Rotate the canvas to an absolute degree
2444
+ * @param {number} degree - The rotate degree.
2445
+ * @returns {Cropper} this
2446
+ */
2447
+ rotateTo: function rotateTo(degree) {
2448
+ degree = Number(degree);
2449
+ if (isNumber(degree) && this.ready && !this.disabled && this.options.rotatable) {
2450
+ this.imageData.rotate = degree % 360;
2451
+ this.renderCanvas(true, true);
2452
+ }
2453
+ return this;
2454
+ },
2455
+ /**
2456
+ * Scale the image on the x-axis.
2457
+ * @param {number} scaleX - The scale ratio on the x-axis.
2458
+ * @returns {Cropper} this
2459
+ */
2460
+ scaleX: function scaleX(_scaleX) {
2461
+ var scaleY = this.imageData.scaleY;
2462
+ return this.scale(_scaleX, isNumber(scaleY) ? scaleY : 1);
2463
+ },
2464
+ /**
2465
+ * Scale the image on the y-axis.
2466
+ * @param {number} scaleY - The scale ratio on the y-axis.
2467
+ * @returns {Cropper} this
2468
+ */
2469
+ scaleY: function scaleY(_scaleY) {
2470
+ var scaleX = this.imageData.scaleX;
2471
+ return this.scale(isNumber(scaleX) ? scaleX : 1, _scaleY);
2472
+ },
2473
+ /**
2474
+ * Scale the image
2475
+ * @param {number} scaleX - The scale ratio on the x-axis.
2476
+ * @param {number} [scaleY=scaleX] - The scale ratio on the y-axis.
2477
+ * @returns {Cropper} this
2478
+ */
2479
+ scale: function scale(scaleX) {
2480
+ var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX;
2481
+ var imageData = this.imageData;
2482
+ var transformed = false;
2483
+ scaleX = Number(scaleX);
2484
+ scaleY = Number(scaleY);
2485
+ if (this.ready && !this.disabled && this.options.scalable) {
2486
+ if (isNumber(scaleX)) {
2487
+ imageData.scaleX = scaleX;
2488
+ transformed = true;
2489
+ }
2490
+ if (isNumber(scaleY)) {
2491
+ imageData.scaleY = scaleY;
2492
+ transformed = true;
2493
+ }
2494
+ if (transformed) {
2495
+ this.renderCanvas(true, true);
2496
+ }
2497
+ }
2498
+ return this;
2499
+ },
2500
+ /**
2501
+ * Get the cropped area position and size data (base on the original image)
2502
+ * @param {boolean} [rounded=false] - Indicate if round the data values or not.
2503
+ * @returns {Object} The result cropped data.
2504
+ */
2505
+ getData: function getData() {
2506
+ var rounded = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
2507
+ var options = this.options,
2508
+ imageData = this.imageData,
2509
+ canvasData = this.canvasData,
2510
+ cropBoxData = this.cropBoxData;
2511
+ var data;
2512
+ if (this.ready && this.cropped) {
2513
+ data = {
2514
+ x: cropBoxData.left - canvasData.left,
2515
+ y: cropBoxData.top - canvasData.top,
2516
+ width: cropBoxData.width,
2517
+ height: cropBoxData.height
2518
+ };
2519
+ var ratio = imageData.width / imageData.naturalWidth;
2520
+ forEach(data, function (n, i) {
2521
+ data[i] = n / ratio;
2522
+ });
2523
+ if (rounded) {
2524
+ // In case rounding off leads to extra 1px in right or bottom border
2525
+ // we should round the top-left corner and the dimension (#343).
2526
+ var bottom = Math.round(data.y + data.height);
2527
+ var right = Math.round(data.x + data.width);
2528
+ data.x = Math.round(data.x);
2529
+ data.y = Math.round(data.y);
2530
+ data.width = right - data.x;
2531
+ data.height = bottom - data.y;
2532
+ }
2533
+ } else {
2534
+ data = {
2535
+ x: 0,
2536
+ y: 0,
2537
+ width: 0,
2538
+ height: 0
2539
+ };
2540
+ }
2541
+ if (options.rotatable) {
2542
+ data.rotate = imageData.rotate || 0;
2543
+ }
2544
+ if (options.scalable) {
2545
+ data.scaleX = imageData.scaleX || 1;
2546
+ data.scaleY = imageData.scaleY || 1;
2547
+ }
2548
+ return data;
2549
+ },
2550
+ /**
2551
+ * Set the cropped area position and size with new data
2552
+ * @param {Object} data - The new data.
2553
+ * @returns {Cropper} this
2554
+ */
2555
+ setData: function setData(data) {
2556
+ var options = this.options,
2557
+ imageData = this.imageData,
2558
+ canvasData = this.canvasData;
2559
+ var cropBoxData = {};
2560
+ if (this.ready && !this.disabled && isPlainObject(data)) {
2561
+ var transformed = false;
2562
+ if (options.rotatable) {
2563
+ if (isNumber(data.rotate) && data.rotate !== imageData.rotate) {
2564
+ imageData.rotate = data.rotate;
2565
+ transformed = true;
2566
+ }
2567
+ }
2568
+ if (options.scalable) {
2569
+ if (isNumber(data.scaleX) && data.scaleX !== imageData.scaleX) {
2570
+ imageData.scaleX = data.scaleX;
2571
+ transformed = true;
2572
+ }
2573
+ if (isNumber(data.scaleY) && data.scaleY !== imageData.scaleY) {
2574
+ imageData.scaleY = data.scaleY;
2575
+ transformed = true;
2576
+ }
2577
+ }
2578
+ if (transformed) {
2579
+ this.renderCanvas(true, true);
2580
+ }
2581
+ var ratio = imageData.width / imageData.naturalWidth;
2582
+ if (isNumber(data.x)) {
2583
+ cropBoxData.left = data.x * ratio + canvasData.left;
2584
+ }
2585
+ if (isNumber(data.y)) {
2586
+ cropBoxData.top = data.y * ratio + canvasData.top;
2587
+ }
2588
+ if (isNumber(data.width)) {
2589
+ cropBoxData.width = data.width * ratio;
2590
+ }
2591
+ if (isNumber(data.height)) {
2592
+ cropBoxData.height = data.height * ratio;
2593
+ }
2594
+ this.setCropBoxData(cropBoxData);
2595
+ }
2596
+ return this;
2597
+ },
2598
+ /**
2599
+ * Get the container size data.
2600
+ * @returns {Object} The result container data.
2601
+ */
2602
+ getContainerData: function getContainerData() {
2603
+ return this.ready ? assign({}, this.containerData) : {};
2604
+ },
2605
+ /**
2606
+ * Get the image position and size data.
2607
+ * @returns {Object} The result image data.
2608
+ */
2609
+ getImageData: function getImageData() {
2610
+ return this.sized ? assign({}, this.imageData) : {};
2611
+ },
2612
+ /**
2613
+ * Get the canvas position and size data.
2614
+ * @returns {Object} The result canvas data.
2615
+ */
2616
+ getCanvasData: function getCanvasData() {
2617
+ var canvasData = this.canvasData;
2618
+ var data = {};
2619
+ if (this.ready) {
2620
+ forEach(['left', 'top', 'width', 'height', 'naturalWidth', 'naturalHeight'], function (n) {
2621
+ data[n] = canvasData[n];
2622
+ });
2623
+ }
2624
+ return data;
2625
+ },
2626
+ /**
2627
+ * Set the canvas position and size with new data.
2628
+ * @param {Object} data - The new canvas data.
2629
+ * @returns {Cropper} this
2630
+ */
2631
+ setCanvasData: function setCanvasData(data) {
2632
+ var canvasData = this.canvasData;
2633
+ var aspectRatio = canvasData.aspectRatio;
2634
+ if (this.ready && !this.disabled && isPlainObject(data)) {
2635
+ if (isNumber(data.left)) {
2636
+ canvasData.left = data.left;
2637
+ }
2638
+ if (isNumber(data.top)) {
2639
+ canvasData.top = data.top;
2640
+ }
2641
+ if (isNumber(data.width)) {
2642
+ canvasData.width = data.width;
2643
+ canvasData.height = data.width / aspectRatio;
2644
+ } else if (isNumber(data.height)) {
2645
+ canvasData.height = data.height;
2646
+ canvasData.width = data.height * aspectRatio;
2647
+ }
2648
+ this.renderCanvas(true);
2649
+ }
2650
+ return this;
2651
+ },
2652
+ /**
2653
+ * Get the crop box position and size data.
2654
+ * @returns {Object} The result crop box data.
2655
+ */
2656
+ getCropBoxData: function getCropBoxData() {
2657
+ var cropBoxData = this.cropBoxData;
2658
+ var data;
2659
+ if (this.ready && this.cropped) {
2660
+ data = {
2661
+ left: cropBoxData.left,
2662
+ top: cropBoxData.top,
2663
+ width: cropBoxData.width,
2664
+ height: cropBoxData.height
2665
+ };
2666
+ }
2667
+ return data || {};
2668
+ },
2669
+ /**
2670
+ * Set the crop box position and size with new data.
2671
+ * @param {Object} data - The new crop box data.
2672
+ * @returns {Cropper} this
2673
+ */
2674
+ setCropBoxData: function setCropBoxData(data) {
2675
+ var cropBoxData = this.cropBoxData;
2676
+ var aspectRatio = this.options.aspectRatio;
2677
+ var widthChanged;
2678
+ var heightChanged;
2679
+ if (this.ready && this.cropped && !this.disabled && isPlainObject(data)) {
2680
+ if (isNumber(data.left)) {
2681
+ cropBoxData.left = data.left;
2682
+ }
2683
+ if (isNumber(data.top)) {
2684
+ cropBoxData.top = data.top;
2685
+ }
2686
+ if (isNumber(data.width) && data.width !== cropBoxData.width) {
2687
+ widthChanged = true;
2688
+ cropBoxData.width = data.width;
2689
+ }
2690
+ if (isNumber(data.height) && data.height !== cropBoxData.height) {
2691
+ heightChanged = true;
2692
+ cropBoxData.height = data.height;
2693
+ }
2694
+ if (aspectRatio) {
2695
+ if (widthChanged) {
2696
+ cropBoxData.height = cropBoxData.width / aspectRatio;
2697
+ } else if (heightChanged) {
2698
+ cropBoxData.width = cropBoxData.height * aspectRatio;
2699
+ }
2700
+ }
2701
+ this.renderCropBox();
2702
+ }
2703
+ return this;
2704
+ },
2705
+ /**
2706
+ * Get a canvas drawn the cropped image.
2707
+ * @param {Object} [options={}] - The config options.
2708
+ * @returns {HTMLCanvasElement} - The result canvas.
2709
+ */
2710
+ getCroppedCanvas: function getCroppedCanvas() {
2711
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2712
+ if (!this.ready || !window.HTMLCanvasElement) {
2713
+ return null;
2714
+ }
2715
+ var canvasData = this.canvasData;
2716
+ var source = getSourceCanvas(this.image, this.imageData, canvasData, options);
2717
+
2718
+ // Returns the source canvas if it is not cropped.
2719
+ if (!this.cropped) {
2720
+ return source;
2721
+ }
2722
+ var _this$getData = this.getData(),
2723
+ initialX = _this$getData.x,
2724
+ initialY = _this$getData.y,
2725
+ initialWidth = _this$getData.width,
2726
+ initialHeight = _this$getData.height;
2727
+ var ratio = source.width / Math.floor(canvasData.naturalWidth);
2728
+ if (ratio !== 1) {
2729
+ initialX *= ratio;
2730
+ initialY *= ratio;
2731
+ initialWidth *= ratio;
2732
+ initialHeight *= ratio;
2733
+ }
2734
+ var aspectRatio = initialWidth / initialHeight;
2735
+ var maxSizes = getAdjustedSizes({
2736
+ aspectRatio: aspectRatio,
2737
+ width: options.maxWidth || Infinity,
2738
+ height: options.maxHeight || Infinity
2739
+ });
2740
+ var minSizes = getAdjustedSizes({
2741
+ aspectRatio: aspectRatio,
2742
+ width: options.minWidth || 0,
2743
+ height: options.minHeight || 0
2744
+ }, 'cover');
2745
+ var _getAdjustedSizes = getAdjustedSizes({
2746
+ aspectRatio: aspectRatio,
2747
+ width: options.width || (ratio !== 1 ? source.width : initialWidth),
2748
+ height: options.height || (ratio !== 1 ? source.height : initialHeight)
2749
+ }),
2750
+ width = _getAdjustedSizes.width,
2751
+ height = _getAdjustedSizes.height;
2752
+ width = Math.min(maxSizes.width, Math.max(minSizes.width, width));
2753
+ height = Math.min(maxSizes.height, Math.max(minSizes.height, height));
2754
+ var canvas = document.createElement('canvas');
2755
+ var context = canvas.getContext('2d');
2756
+ canvas.width = normalizeDecimalNumber(width);
2757
+ canvas.height = normalizeDecimalNumber(height);
2758
+ context.fillStyle = options.fillColor || 'transparent';
2759
+ context.fillRect(0, 0, width, height);
2760
+ var _options$imageSmoothi = options.imageSmoothingEnabled,
2761
+ imageSmoothingEnabled = _options$imageSmoothi === void 0 ? true : _options$imageSmoothi,
2762
+ imageSmoothingQuality = options.imageSmoothingQuality;
2763
+ context.imageSmoothingEnabled = imageSmoothingEnabled;
2764
+ if (imageSmoothingQuality) {
2765
+ context.imageSmoothingQuality = imageSmoothingQuality;
2766
+ }
2767
+
2768
+ // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D.drawImage
2769
+ var sourceWidth = source.width;
2770
+ var sourceHeight = source.height;
2771
+
2772
+ // Source canvas parameters
2773
+ var srcX = initialX;
2774
+ var srcY = initialY;
2775
+ var srcWidth;
2776
+ var srcHeight;
2777
+
2778
+ // Destination canvas parameters
2779
+ var dstX;
2780
+ var dstY;
2781
+ var dstWidth;
2782
+ var dstHeight;
2783
+ if (srcX <= -initialWidth || srcX > sourceWidth) {
2784
+ srcX = 0;
2785
+ srcWidth = 0;
2786
+ dstX = 0;
2787
+ dstWidth = 0;
2788
+ } else if (srcX <= 0) {
2789
+ dstX = -srcX;
2790
+ srcX = 0;
2791
+ srcWidth = Math.min(sourceWidth, initialWidth + srcX);
2792
+ dstWidth = srcWidth;
2793
+ } else if (srcX <= sourceWidth) {
2794
+ dstX = 0;
2795
+ srcWidth = Math.min(initialWidth, sourceWidth - srcX);
2796
+ dstWidth = srcWidth;
2797
+ }
2798
+ if (srcWidth <= 0 || srcY <= -initialHeight || srcY > sourceHeight) {
2799
+ srcY = 0;
2800
+ srcHeight = 0;
2801
+ dstY = 0;
2802
+ dstHeight = 0;
2803
+ } else if (srcY <= 0) {
2804
+ dstY = -srcY;
2805
+ srcY = 0;
2806
+ srcHeight = Math.min(sourceHeight, initialHeight + srcY);
2807
+ dstHeight = srcHeight;
2808
+ } else if (srcY <= sourceHeight) {
2809
+ dstY = 0;
2810
+ srcHeight = Math.min(initialHeight, sourceHeight - srcY);
2811
+ dstHeight = srcHeight;
2812
+ }
2813
+ var params = [srcX, srcY, srcWidth, srcHeight];
2814
+
2815
+ // Avoid "IndexSizeError"
2816
+ if (dstWidth > 0 && dstHeight > 0) {
2817
+ var scale = width / initialWidth;
2818
+ params.push(dstX * scale, dstY * scale, dstWidth * scale, dstHeight * scale);
2819
+ }
2820
+
2821
+ // All the numerical parameters should be integer for `drawImage`
2822
+ // https://github.com/fengyuanchen/cropper/issues/476
2823
+ context.drawImage.apply(context, [source].concat(_toConsumableArray(params.map(function (param) {
2824
+ return Math.floor(normalizeDecimalNumber(param));
2825
+ }))));
2826
+ return canvas;
2827
+ },
2828
+ /**
2829
+ * Change the aspect ratio of the crop box.
2830
+ * @param {number} aspectRatio - The new aspect ratio.
2831
+ * @returns {Cropper} this
2832
+ */
2833
+ setAspectRatio: function setAspectRatio(aspectRatio) {
2834
+ var options = this.options;
2835
+ if (!this.disabled && !isUndefined(aspectRatio)) {
2836
+ // 0 -> NaN
2837
+ options.aspectRatio = Math.max(0, aspectRatio) || NaN;
2838
+ if (this.ready) {
2839
+ this.initCropBox();
2840
+ if (this.cropped) {
2841
+ this.renderCropBox();
2842
+ }
2843
+ }
2844
+ }
2845
+ return this;
2846
+ },
2847
+ /**
2848
+ * Change the drag mode.
2849
+ * @param {string} mode - The new drag mode.
2850
+ * @returns {Cropper} this
2851
+ */
2852
+ setDragMode: function setDragMode(mode) {
2853
+ var options = this.options,
2854
+ dragBox = this.dragBox,
2855
+ face = this.face;
2856
+ if (this.ready && !this.disabled) {
2857
+ var croppable = mode === DRAG_MODE_CROP;
2858
+ var movable = options.movable && mode === DRAG_MODE_MOVE;
2859
+ mode = croppable || movable ? mode : DRAG_MODE_NONE;
2860
+ options.dragMode = mode;
2861
+ setData(dragBox, DATA_ACTION, mode);
2862
+ toggleClass(dragBox, CLASS_CROP, croppable);
2863
+ toggleClass(dragBox, CLASS_MOVE, movable);
2864
+ if (!options.cropBoxMovable) {
2865
+ // Sync drag mode to crop box when it is not movable
2866
+ setData(face, DATA_ACTION, mode);
2867
+ toggleClass(face, CLASS_CROP, croppable);
2868
+ toggleClass(face, CLASS_MOVE, movable);
2869
+ }
2870
+ }
2871
+ return this;
2872
+ }
2873
+ };
2874
+
2875
+ var AnotherCropper = WINDOW.Cropper;
2876
+ var Cropper = /*#__PURE__*/function () {
2877
+ /**
2878
+ * Create a new Cropper.
2879
+ * @param {Element} element - The target element for cropping.
2880
+ * @param {Object} [options={}] - The configuration options.
2881
+ */
2882
+ function Cropper(element) {
2883
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2884
+ _classCallCheck(this, Cropper);
2885
+ if (!element || !REGEXP_TAG_NAME.test(element.tagName)) {
2886
+ throw new Error('The first argument is required and must be an <img> or <canvas> element.');
2887
+ }
2888
+ this.element = element;
2889
+ this.options = assign({}, DEFAULTS, isPlainObject(options) && options);
2890
+ this.cropped = false;
2891
+ this.disabled = false;
2892
+ this.pointers = {};
2893
+ this.ready = false;
2894
+ this.reloading = false;
2895
+ this.replaced = false;
2896
+ this.sized = false;
2897
+ this.sizing = false;
2898
+ this.init();
2899
+ }
2900
+ _createClass(Cropper, [{
2901
+ key: "init",
2902
+ value: function init() {
2903
+ var element = this.element;
2904
+ var tagName = element.tagName.toLowerCase();
2905
+ var url;
2906
+ if (element[NAMESPACE]) {
2907
+ return;
2908
+ }
2909
+ element[NAMESPACE] = this;
2910
+ if (tagName === 'img') {
2911
+ this.isImg = true;
2912
+
2913
+ // e.g.: "img/picture.jpg"
2914
+ url = element.getAttribute('src') || '';
2915
+ this.originalUrl = url;
2916
+
2917
+ // Stop when it's a blank image
2918
+ if (!url) {
2919
+ return;
2920
+ }
2921
+
2922
+ // e.g.: "https://example.com/img/picture.jpg"
2923
+ url = element.src;
2924
+ } else if (tagName === 'canvas' && window.HTMLCanvasElement) {
2925
+ url = element.toDataURL();
2926
+ }
2927
+ this.load(url);
2928
+ }
2929
+ }, {
2930
+ key: "load",
2931
+ value: function load(url) {
2932
+ var _this = this;
2933
+ if (!url) {
2934
+ return;
2935
+ }
2936
+ this.url = url;
2937
+ this.imageData = {};
2938
+ var element = this.element,
2939
+ options = this.options;
2940
+ if (!options.rotatable && !options.scalable) {
2941
+ options.checkOrientation = false;
2942
+ }
2943
+
2944
+ // Only IE10+ supports Typed Arrays
2945
+ if (!options.checkOrientation || !window.ArrayBuffer) {
2946
+ this.clone();
2947
+ return;
2948
+ }
2949
+
2950
+ // Detect the mime type of the image directly if it is a Data URL
2951
+ if (REGEXP_DATA_URL.test(url)) {
2952
+ // Read ArrayBuffer from Data URL of JPEG images directly for better performance
2953
+ if (REGEXP_DATA_URL_JPEG.test(url)) {
2954
+ this.read(dataURLToArrayBuffer(url));
2955
+ } else {
2956
+ // Only a JPEG image may contains Exif Orientation information,
2957
+ // the rest types of Data URLs are not necessary to check orientation at all.
2958
+ this.clone();
2959
+ }
2960
+ return;
2961
+ }
2962
+
2963
+ // 1. Detect the mime type of the image by a XMLHttpRequest.
2964
+ // 2. Load the image as ArrayBuffer for reading orientation if its a JPEG image.
2965
+ var xhr = new XMLHttpRequest();
2966
+ var clone = this.clone.bind(this);
2967
+ this.reloading = true;
2968
+ this.xhr = xhr;
2969
+
2970
+ // 1. Cross origin requests are only supported for protocol schemes:
2971
+ // http, https, data, chrome, chrome-extension.
2972
+ // 2. Access to XMLHttpRequest from a Data URL will be blocked by CORS policy
2973
+ // in some browsers as IE11 and Safari.
2974
+ xhr.onabort = clone;
2975
+ xhr.onerror = clone;
2976
+ xhr.ontimeout = clone;
2977
+ xhr.onprogress = function () {
2978
+ // Abort the request directly if it not a JPEG image for better performance
2979
+ if (xhr.getResponseHeader('content-type') !== MIME_TYPE_JPEG) {
2980
+ xhr.abort();
2981
+ }
2982
+ };
2983
+ xhr.onload = function () {
2984
+ _this.read(xhr.response);
2985
+ };
2986
+ xhr.onloadend = function () {
2987
+ _this.reloading = false;
2988
+ _this.xhr = null;
2989
+ };
2990
+
2991
+ // Bust cache when there is a "crossOrigin" property to avoid browser cache error
2992
+ if (options.checkCrossOrigin && isCrossOriginURL(url) && element.crossOrigin) {
2993
+ url = addTimestamp(url);
2994
+ }
2995
+
2996
+ // The third parameter is required for avoiding side-effect (#682)
2997
+ xhr.open('GET', url, true);
2998
+ xhr.responseType = 'arraybuffer';
2999
+ xhr.withCredentials = element.crossOrigin === 'use-credentials';
3000
+ xhr.send();
3001
+ }
3002
+ }, {
3003
+ key: "read",
3004
+ value: function read(arrayBuffer) {
3005
+ var options = this.options,
3006
+ imageData = this.imageData;
3007
+
3008
+ // Reset the orientation value to its default value 1
3009
+ // as some iOS browsers will render image with its orientation
3010
+ var orientation = resetAndGetOrientation(arrayBuffer);
3011
+ var rotate = 0;
3012
+ var scaleX = 1;
3013
+ var scaleY = 1;
3014
+ if (orientation > 1) {
3015
+ // Generate a new URL which has the default orientation value
3016
+ this.url = arrayBufferToDataURL(arrayBuffer, MIME_TYPE_JPEG);
3017
+ var _parseOrientation = parseOrientation(orientation);
3018
+ rotate = _parseOrientation.rotate;
3019
+ scaleX = _parseOrientation.scaleX;
3020
+ scaleY = _parseOrientation.scaleY;
3021
+ }
3022
+ if (options.rotatable) {
3023
+ imageData.rotate = rotate;
3024
+ }
3025
+ if (options.scalable) {
3026
+ imageData.scaleX = scaleX;
3027
+ imageData.scaleY = scaleY;
3028
+ }
3029
+ this.clone();
3030
+ }
3031
+ }, {
3032
+ key: "clone",
3033
+ value: function clone() {
3034
+ var element = this.element,
3035
+ url = this.url;
3036
+ var crossOrigin = element.crossOrigin;
3037
+ var crossOriginUrl = url;
3038
+ if (this.options.checkCrossOrigin && isCrossOriginURL(url)) {
3039
+ if (!crossOrigin) {
3040
+ crossOrigin = 'anonymous';
3041
+ }
3042
+
3043
+ // Bust cache when there is not a "crossOrigin" property (#519)
3044
+ crossOriginUrl = addTimestamp(url);
3045
+ }
3046
+ this.crossOrigin = crossOrigin;
3047
+ this.crossOriginUrl = crossOriginUrl;
3048
+ var image = document.createElement('img');
3049
+ if (crossOrigin) {
3050
+ image.crossOrigin = crossOrigin;
3051
+ }
3052
+ image.src = crossOriginUrl || url;
3053
+ image.alt = element.alt || 'The image to crop';
3054
+ this.image = image;
3055
+ image.onload = this.start.bind(this);
3056
+ image.onerror = this.stop.bind(this);
3057
+ addClass(image, CLASS_HIDE);
3058
+ element.parentNode.insertBefore(image, element.nextSibling);
3059
+ }
3060
+ }, {
3061
+ key: "start",
3062
+ value: function start() {
3063
+ var _this2 = this;
3064
+ var image = this.image;
3065
+ image.onload = null;
3066
+ image.onerror = null;
3067
+ this.sizing = true;
3068
+
3069
+ // Match all browsers that use WebKit as the layout engine in iOS devices,
3070
+ // such as Safari for iOS, Chrome for iOS, and in-app browsers.
3071
+ var isIOSWebKit = WINDOW.navigator && /(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(WINDOW.navigator.userAgent);
3072
+ var done = function done(naturalWidth, naturalHeight) {
3073
+ assign(_this2.imageData, {
3074
+ naturalWidth: naturalWidth,
3075
+ naturalHeight: naturalHeight,
3076
+ aspectRatio: naturalWidth / naturalHeight
3077
+ });
3078
+ _this2.initialImageData = assign({}, _this2.imageData);
3079
+ _this2.sizing = false;
3080
+ _this2.sized = true;
3081
+ _this2.build();
3082
+ };
3083
+
3084
+ // Most modern browsers (excepts iOS WebKit)
3085
+ if (image.naturalWidth && !isIOSWebKit) {
3086
+ done(image.naturalWidth, image.naturalHeight);
3087
+ return;
3088
+ }
3089
+ var sizingImage = document.createElement('img');
3090
+ var body = document.body || document.documentElement;
3091
+ this.sizingImage = sizingImage;
3092
+ sizingImage.onload = function () {
3093
+ done(sizingImage.width, sizingImage.height);
3094
+ if (!isIOSWebKit) {
3095
+ body.removeChild(sizingImage);
3096
+ }
3097
+ };
3098
+ sizingImage.src = image.src;
3099
+
3100
+ // iOS WebKit will convert the image automatically
3101
+ // with its orientation once append it into DOM (#279)
3102
+ if (!isIOSWebKit) {
3103
+ sizingImage.style.cssText = 'left:0;' + 'max-height:none!important;' + 'max-width:none!important;' + 'min-height:0!important;' + 'min-width:0!important;' + 'opacity:0;' + 'position:absolute;' + 'top:0;' + 'z-index:-1;';
3104
+ body.appendChild(sizingImage);
3105
+ }
3106
+ }
3107
+ }, {
3108
+ key: "stop",
3109
+ value: function stop() {
3110
+ var image = this.image;
3111
+ image.onload = null;
3112
+ image.onerror = null;
3113
+ image.parentNode.removeChild(image);
3114
+ this.image = null;
3115
+ }
3116
+ }, {
3117
+ key: "build",
3118
+ value: function build() {
3119
+ if (!this.sized || this.ready) {
3120
+ return;
3121
+ }
3122
+ var element = this.element,
3123
+ options = this.options,
3124
+ image = this.image;
3125
+
3126
+ // Create cropper elements
3127
+ var container = element.parentNode;
3128
+ var template = document.createElement('div');
3129
+ template.innerHTML = TEMPLATE;
3130
+ var cropper = template.querySelector(".".concat(NAMESPACE, "-container"));
3131
+ var canvas = cropper.querySelector(".".concat(NAMESPACE, "-canvas"));
3132
+ var dragBox = cropper.querySelector(".".concat(NAMESPACE, "-drag-box"));
3133
+ var cropBox = cropper.querySelector(".".concat(NAMESPACE, "-crop-box"));
3134
+ var face = cropBox.querySelector(".".concat(NAMESPACE, "-face"));
3135
+ this.container = container;
3136
+ this.cropper = cropper;
3137
+ this.canvas = canvas;
3138
+ this.dragBox = dragBox;
3139
+ this.cropBox = cropBox;
3140
+ this.viewBox = cropper.querySelector(".".concat(NAMESPACE, "-view-box"));
3141
+ this.face = face;
3142
+ canvas.appendChild(image);
3143
+
3144
+ // Hide the original image
3145
+ addClass(element, CLASS_HIDDEN);
3146
+
3147
+ // Inserts the cropper after to the current image
3148
+ container.insertBefore(cropper, element.nextSibling);
3149
+
3150
+ // Show the hidden image
3151
+ removeClass(image, CLASS_HIDE);
3152
+ this.initPreview();
3153
+ this.bind();
3154
+ options.initialAspectRatio = Math.max(0, options.initialAspectRatio) || NaN;
3155
+ options.aspectRatio = Math.max(0, options.aspectRatio) || NaN;
3156
+ options.viewMode = Math.max(0, Math.min(3, Math.round(options.viewMode))) || 0;
3157
+ addClass(cropBox, CLASS_HIDDEN);
3158
+ if (!options.guides) {
3159
+ addClass(cropBox.getElementsByClassName("".concat(NAMESPACE, "-dashed")), CLASS_HIDDEN);
3160
+ }
3161
+ if (!options.center) {
3162
+ addClass(cropBox.getElementsByClassName("".concat(NAMESPACE, "-center")), CLASS_HIDDEN);
3163
+ }
3164
+ if (options.background) {
3165
+ addClass(cropper, "".concat(NAMESPACE, "-bg"));
3166
+ }
3167
+ if (!options.highlight) {
3168
+ addClass(face, CLASS_INVISIBLE);
3169
+ }
3170
+ if (options.cropBoxMovable) {
3171
+ addClass(face, CLASS_MOVE);
3172
+ setData(face, DATA_ACTION, ACTION_ALL);
3173
+ }
3174
+ if (!options.cropBoxResizable) {
3175
+ addClass(cropBox.getElementsByClassName("".concat(NAMESPACE, "-line")), CLASS_HIDDEN);
3176
+ addClass(cropBox.getElementsByClassName("".concat(NAMESPACE, "-point")), CLASS_HIDDEN);
3177
+ }
3178
+ this.render();
3179
+ this.ready = true;
3180
+ this.setDragMode(options.dragMode);
3181
+ if (options.autoCrop) {
3182
+ this.crop();
3183
+ }
3184
+ this.setData(options.data);
3185
+ if (isFunction(options.ready)) {
3186
+ addListener(element, EVENT_READY, options.ready, {
3187
+ once: true
3188
+ });
3189
+ }
3190
+ dispatchEvent(element, EVENT_READY);
3191
+ }
3192
+ }, {
3193
+ key: "unbuild",
3194
+ value: function unbuild() {
3195
+ if (!this.ready) {
3196
+ return;
3197
+ }
3198
+ this.ready = false;
3199
+ this.unbind();
3200
+ this.resetPreview();
3201
+ var parentNode = this.cropper.parentNode;
3202
+ if (parentNode) {
3203
+ parentNode.removeChild(this.cropper);
3204
+ }
3205
+ removeClass(this.element, CLASS_HIDDEN);
3206
+ }
3207
+ }, {
3208
+ key: "uncreate",
3209
+ value: function uncreate() {
3210
+ if (this.ready) {
3211
+ this.unbuild();
3212
+ this.ready = false;
3213
+ this.cropped = false;
3214
+ } else if (this.sizing) {
3215
+ this.sizingImage.onload = null;
3216
+ this.sizing = false;
3217
+ this.sized = false;
3218
+ } else if (this.reloading) {
3219
+ this.xhr.onabort = null;
3220
+ this.xhr.abort();
3221
+ } else if (this.image) {
3222
+ this.stop();
3223
+ }
3224
+ }
3225
+
3226
+ /**
3227
+ * Get the no conflict cropper class.
3228
+ * @returns {Cropper} The cropper class.
3229
+ */
3230
+ }], [{
3231
+ key: "noConflict",
3232
+ value: function noConflict() {
3233
+ window.Cropper = AnotherCropper;
3234
+ return Cropper;
3235
+ }
3236
+
3237
+ /**
3238
+ * Change the default options.
3239
+ * @param {Object} options - The new default options.
3240
+ */
3241
+ }, {
3242
+ key: "setDefaults",
3243
+ value: function setDefaults(options) {
3244
+ assign(DEFAULTS, isPlainObject(options) && options);
3245
+ }
3246
+ }]);
3247
+ return Cropper;
3248
+ }();
3249
+ assign(Cropper.prototype, render, preview, events, handlers, change, methods);
3250
+
3251
+ export { Cropper as default };