vendor.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. (global["webpackJsonp"] = global["webpackJsonp"] || []).push([["pages_basics/common/vendor"],{
  2. /***/ 957:
  3. /*!**************************************************************************************!*\
  4. !*** E:/git/2021项目/v3-H5/pages_basics/component/cropper.js?vue&type=script&lang=js& ***!
  5. \**************************************************************************************/
  6. /*! no static exports found */
  7. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  8. "use strict";
  9. __webpack_require__.r(__webpack_exports__);
  10. /* harmony import */ var _D_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_13_1_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_cropper_js_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!./node_modules/babel-loader/lib!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader??ref--13-1!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js!./cropper.js?vue&type=script&lang=js& */ 958);
  11. /* harmony import */ var _D_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_13_1_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_cropper_js_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_D_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_13_1_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_cropper_js_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__);
  12. /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _D_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_13_1_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_cropper_js_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__) if(["default"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _D_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_13_1_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_cropper_js_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0__[key]; }) }(__WEBPACK_IMPORT_KEY__));
  13. /* harmony default export */ __webpack_exports__["default"] = (_D_HBuilderX_plugins_uniapp_cli_node_modules_babel_loader_lib_index_js_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_vue_cli_plugin_uni_packages_webpack_preprocess_loader_index_js_ref_13_1_D_HBuilderX_plugins_uniapp_cli_node_modules_dcloudio_webpack_uni_mp_loader_lib_script_js_cropper_js_vue_type_script_lang_js___WEBPACK_IMPORTED_MODULE_0___default.a);
  14. /***/ }),
  15. /***/ 958:
  16. /*!*****************************************************************************************************************************************************************************************************************************************************************************!*\
  17. !*** ./node_modules/babel-loader/lib!./node_modules/@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader??ref--13-1!./node_modules/@dcloudio/webpack-uni-mp-loader/lib/script.js!E:/git/2021项目/v3-H5/pages_basics/component/cropper.js?vue&type=script&lang=js& ***!
  18. \*****************************************************************************************************************************************************************************************************************************************************************************/
  19. /*! no static exports found */
  20. /***/ (function(module, exports, __webpack_require__) {
  21. "use strict";
  22. /* WEBPACK VAR INJECTION */(function(uni) {
  23. var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
  24. Object.defineProperty(exports, "__esModule", {
  25. value: true
  26. });
  27. exports.default = void 0;
  28. var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ 50));
  29. var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ 52));
  30. var ABS = Math.abs;
  31. var calcLen = function calcLen(v) {
  32. // distance between two coordinate
  33. return Math.sqrt(v.x * v.x + v.y * v.y);
  34. };
  35. var calcAngle = function calcAngle(a, b) {
  36. // angle of the two vectors
  37. var l = calcLen(a) * calcLen(b);
  38. var cosValue;
  39. var angle;
  40. if (l) {
  41. cosValue = (a.x * b.x + a.y * b.y) / l;
  42. angle = Math.acos(Math.min(cosValue, 1));
  43. angle = a.x * b.y - b.x * a.y > 0 ? -angle : angle;
  44. return angle * 180 / Math.PI;
  45. }
  46. return 0;
  47. };
  48. var generateCanvasId = function generateCanvasId() {
  49. // generate a random string
  50. var seeds = 'abcdefghijklmnopqrstuvwxyz';
  51. var arr = seeds.split('').concat(seeds.toUpperCase().split('')).concat('0123456789'.split(''));
  52. var m = arr.length;
  53. var i;
  54. while (m) {
  55. i = Math.floor(Math.random() * m--);
  56. var temp = arr[m];
  57. arr[m] = arr[i];
  58. arr[i] = temp;
  59. }
  60. return arr.slice(0, 16).join('');
  61. };
  62. var _default2 = {
  63. props: {
  64. width: {
  65. // width of the container
  66. type: [String, Number],
  67. default: '100%'
  68. },
  69. height: {
  70. // height of the container
  71. type: [String, Number],
  72. default: '100%'
  73. },
  74. cutWidth: {
  75. // cutter width
  76. type: [String, Number],
  77. default: '50%'
  78. },
  79. cutHeight: {
  80. // cutter height
  81. type: [String, Number],
  82. default: 0
  83. },
  84. minWidth: {
  85. // minWidth of the cutter
  86. type: Number,
  87. default: 50
  88. },
  89. minHeight: {
  90. // minHeight of the cutter
  91. type: Number,
  92. default: 50
  93. },
  94. center: {
  95. // autoCenter
  96. type: Boolean,
  97. default: true
  98. },
  99. src: String,
  100. disableScale: Boolean,
  101. // disable to zoom
  102. disableRotate: Boolean,
  103. disableTranslate: Boolean,
  104. disableCtrl: Boolean,
  105. // disable to resize the cutter
  106. boundDetect: Boolean,
  107. // open boundary detection
  108. freeBoundDetect: Boolean,
  109. // open boundary detection while doing rotation
  110. keepRatio: Boolean,
  111. // keep the ratio of the cutter
  112. disablePreview: Boolean,
  113. // disable preview after cutting
  114. showCtrlBorder: Boolean,
  115. // show cutter border
  116. resetCut: Boolean,
  117. // reset cut while img change
  118. fit: {
  119. type: Boolean,
  120. default: true
  121. },
  122. imageCenter: Boolean,
  123. // auto center/middle for image
  124. maxZoom: {
  125. // maximum scaling factor
  126. type: Number,
  127. default: 10 // can not be Infinity in baidu-MiniProgram
  128. },
  129. minZoom: {
  130. // minimum scaling factor
  131. type: Number,
  132. default: 1
  133. },
  134. angle: {
  135. // initial angle of rotation
  136. type: Number,
  137. default: 0
  138. },
  139. zoom: {
  140. // initial scaling factor
  141. type: Number,
  142. default: 1
  143. },
  144. offset: {
  145. // initial offset relative to the cutter left border
  146. type: Array,
  147. default: function _default() {
  148. return [0, 0];
  149. }
  150. },
  151. background: {
  152. type: String,
  153. default: '#000'
  154. },
  155. canvasBackground: {
  156. // background for the exported image
  157. type: String,
  158. default: '#fff'
  159. },
  160. canvasZoom: {
  161. // export multiples of the cutter size
  162. type: Number,
  163. default: 1
  164. },
  165. fileType: {
  166. type: String,
  167. default: 'png',
  168. validator: function validator(t) {
  169. return ['png', 'jpg'].includes(t);
  170. }
  171. },
  172. quality: {
  173. type: Number,
  174. default: 1
  175. },
  176. maskType: {
  177. // type for mask
  178. type: String,
  179. default: "shadow"
  180. },
  181. circleView: Boolean // circle clip view
  182. },
  183. data: function data() {
  184. return {
  185. transform: {
  186. angle: 0,
  187. translate: {
  188. x: 0,
  189. y: 0
  190. },
  191. zoom: 1
  192. },
  193. corner: {
  194. left: 50,
  195. right: 50,
  196. bottom: 50,
  197. top: 50
  198. },
  199. image: {
  200. originWidth: 0,
  201. originHeight: 0,
  202. width: 0,
  203. height: 0
  204. },
  205. ctrlWidth: 0,
  206. ctrlHeight: 0,
  207. view: false,
  208. canvasId: ''
  209. };
  210. },
  211. computed: {
  212. transformMeta: function transformMeta() {
  213. var transform = this.transform;
  214. return "translate3d(".concat(transform.translate.x, "px, ").concat(transform.translate.y, "px, 0) rotate(").concat(transform.angle, "deg) scale(").concat(transform.zoom, ")");
  215. },
  216. ctrlStyle: function ctrlStyle() {
  217. var corner = this.corner;
  218. var cssStr = "left: ".concat(corner.left, "px;top: ").concat(corner.top, "px;right: ").concat(corner.right, "px;bottom: ").concat(corner.bottom, "px;");
  219. if (this.maskType !== 'outline') {
  220. cssStr += "box-shadow: 0 0 0 50000rpx rgba(0,0,0, ".concat(this.view ? 0.8 : 0.4, ")");
  221. } else {
  222. cssStr += "outline: rgba(0,0,0, ".concat(this.view ? 0.8 : 0.4, ") solid 5000px");
  223. }
  224. return cssStr;
  225. }
  226. },
  227. watch: {
  228. src: function src() {
  229. if (this.resetCut) this.resetCutReact();
  230. this.initImage();
  231. }
  232. },
  233. created: function created() {
  234. var _this = this;
  235. this.canvasId = generateCanvasId();
  236. uni.getSystemInfo().then(function (result) {
  237. result = result[1] || {
  238. windowWidth: 375,
  239. windowHeight: 736
  240. };
  241. _this.ratio = result.windowWidth / 750;
  242. _this.windowHeight = result.windowHeight;
  243. _this.init();
  244. _this.initCanvas();
  245. });
  246. },
  247. methods: {
  248. toPx: function toPx(str) {
  249. if (str.indexOf('%') !== -1) {
  250. return Math.floor(Number(str.replace('%', '')) / 100 * this.containerWidth);
  251. }
  252. if (str.indexOf('rpx') !== -1) {
  253. return Math.floor(Number(str.replace('rpx', '')) * this.ratio);
  254. }
  255. return Math.floor(Number(str.replace('px', '')));
  256. },
  257. initCanvas: function initCanvas() {
  258. var _this2 = this;
  259. var context = uni.createSelectorQuery().in(this);
  260. // get contianer size
  261. context.select('.nice-cropper').boundingClientRect();
  262. context.exec(function (res) {
  263. _this2.containerWidth = res[0].width;
  264. _this2.containerHeight = res[0].height;
  265. _this2.initCut();
  266. });
  267. },
  268. resetCutReact: function resetCutReact() {
  269. // init size and position of the cutter
  270. this.ctrlWidth = Math.min(this.toPx(this.cutWidth), this.containerWidth);
  271. if (this.cutHeight) {
  272. this.ctrlHeight = Math.min(this.toPx(this.cutHeight), this.containerHeight);
  273. } else {
  274. // 默认为正方形
  275. this.ctrlHeight = Math.min(this.ctrlWidth, this.containerHeight);
  276. }
  277. var cornerStartX = this.center ? Math.floor((this.containerWidth - this.ctrlWidth) / 2) : 0;
  278. var cornerStartY = this.center ? Math.floor((this.containerHeight - this.ctrlHeight) / 2) : 0;
  279. this.cutRatio = this.ctrlHeight / this.ctrlWidth;
  280. this.corner = {
  281. left: cornerStartX,
  282. right: this.containerWidth - this.ctrlWidth - cornerStartX,
  283. top: cornerStartY,
  284. bottom: this.containerHeight - this.ctrlHeight - cornerStartY
  285. };
  286. },
  287. initCut: function initCut() {
  288. this.resetCutReact();
  289. this.initImage();
  290. },
  291. initImage: function initImage() {
  292. var _this3 = this;
  293. return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
  294. var res, offset;
  295. return _regenerator.default.wrap(function _callee$(_context) {
  296. while (1) {
  297. switch (_context.prev = _context.next) {
  298. case 0:
  299. if (_this3.src) {
  300. _context.next = 2;
  301. break;
  302. }
  303. return _context.abrupt("return");
  304. case 2:
  305. _context.prev = 2;
  306. _context.next = 5;
  307. return uni.getImageInfo({
  308. src: _this3.src
  309. });
  310. case 5:
  311. res = _context.sent;
  312. _this3.$emit('load', res);
  313. _this3.image.originWidth = res.width;
  314. _this3.image.originHeight = res.height;
  315. _this3.image.width = _this3.fit ? _this3.ctrlWidth : res.width;
  316. _this3.image.height = res.height / res.width * _this3.image.width;
  317. _this3.img = res.path;
  318. _context.next = 23;
  319. break;
  320. case 14:
  321. _context.prev = 14;
  322. _context.t0 = _context["catch"](2);
  323. console.error("图片信息获取失败:", _context.t0);
  324. _this3.$emit("error", _context.t0);
  325. // 使用控件尺寸作为默认值
  326. _this3.image.originWidth = _this3.ctrlWidth;
  327. _this3.image.originHeight = _this3.ctrlHeight;
  328. _this3.image.width = _this3.ctrlWidth;
  329. _this3.image.height = _this3.ctrlHeight;
  330. _this3.img = null;
  331. case 23:
  332. offset = [0, 0];
  333. if (_this3.imageCenter) {
  334. offset[0] = (_this3.ctrlWidth - _this3.image.width) / 2;
  335. offset[1] = (_this3.ctrlHeight - _this3.image.height) / 2;
  336. }
  337. if (Array.isArray(_this3.offset)) {
  338. offset[0] += _this3.offset[0] || 0;
  339. offset[1] += _this3.offset[1] || 0;
  340. }
  341. _this3.setTranslate(offset);
  342. _this3.setZoom(_this3.zoom);
  343. _this3.transform.angle = _this3.freeBoundDetect || !_this3.disableRotate ? _this3.angle : 0;
  344. _this3.setBoundary();
  345. _this3.preview();
  346. _this3.draw();
  347. case 32:
  348. case "end":
  349. return _context.stop();
  350. }
  351. }
  352. }, _callee, null, [[2, 14]]);
  353. }))();
  354. },
  355. init: function init() {
  356. this.pretouch = {};
  357. this.handles = {};
  358. this.preVector = {
  359. x: 0,
  360. y: 0
  361. };
  362. this.distance = 30;
  363. this.touch = {};
  364. this.movetouch = {};
  365. this.cutMode = false;
  366. this.params = {
  367. zoom: 1,
  368. deltaX: 0,
  369. deltaY: 0,
  370. diffX: 0,
  371. diffY: 0,
  372. angle: 0
  373. };
  374. },
  375. start: function start(e) {
  376. if (!this.src) e.preventDefault();
  377. var point = e.touches ? e.touches[0] : e;
  378. var touch = this.touch;
  379. var now = Date.now();
  380. touch.startX = point.pageX;
  381. touch.startY = point.pageY;
  382. touch.startTime = now;
  383. this.doubleTap = false;
  384. this.view = false;
  385. clearTimeout(this.previewTimer);
  386. if (e.touches.length > 1) {
  387. var point2 = e.touches[1];
  388. this.preVector = {
  389. x: point2.pageX - this.touch.startX,
  390. y: point2.pageY - this.touch.startY
  391. };
  392. this.startDistance = calcLen(this.preVector);
  393. } else {
  394. var pretouch = this.pretouch;
  395. this.doubleTap = this.pretouch.time && now - this.pretouch.time < 300 && ABS(touch.startX - pretouch.startX) < 30 && ABS(touch.startY - pretouch.startY) < 30 && ABS(touch.startTime - pretouch.time) < 300;
  396. pretouch = {
  397. // reserve the last touch
  398. startX: this.touch.startX,
  399. startY: this.touch.startY,
  400. time: this.touch.startTime
  401. };
  402. }
  403. },
  404. move: function move(e) {
  405. if (!this.src) return;
  406. var point = e.touches ? e.touches[0] : e;
  407. if (e.touches.length > 1) {
  408. // multi touch
  409. var point2 = e.touches[1];
  410. var v = {
  411. x: point2.pageX - point.pageX,
  412. y: point2.pageY - point.pageY
  413. };
  414. if (this.preVector.x !== null) {
  415. if (this.startDistance) {
  416. // zoom
  417. var len = calcLen(v);
  418. this.params.zoom = calcLen(v) / this.startDistance;
  419. this.startDistance = len;
  420. this.cutMode && !this.disableCtrl ? this.setCut() : !this.disableScale && this.pinch();
  421. }
  422. // rotate
  423. this.params.angle = calcAngle(v, this.preVector);
  424. this.cutMode && !this.disableCtrl ? this.setCut() : !this.disableRotate && this.rotate();
  425. }
  426. this.preVector.x = v.x;
  427. this.preVector.y = v.y;
  428. } else {
  429. // translate
  430. var diffX = point.pageX - this.touch.startX;
  431. var diffY = point.pageY - this.touch.startY;
  432. this.params.diffY = diffY;
  433. this.params.diffX = diffX;
  434. if (this.movetouch.x) {
  435. this.params.deltaX = point.pageX - this.movetouch.x;
  436. this.params.deltaY = point.pageY - this.movetouch.y;
  437. } else {
  438. this.params.deltaX = this.params.deltaY = 0;
  439. }
  440. if (ABS(diffX) > 30 || ABS(diffY) > 30) {
  441. this.doubleTap = false;
  442. }
  443. this.cutMode && !this.disableCtrl ? this.setCut() : !this.disableTranslate && this.translate();
  444. this.movetouch.x = point.pageX;
  445. this.movetouch.y = point.pageY;
  446. }
  447. !this.cutMode && this.setBoundary();
  448. if (e.touches.length > 1) {
  449. e.preventDefault();
  450. }
  451. },
  452. end: function end() {
  453. this.doubleTap && this.$emit('doubleTap');
  454. this.cutMode && this.setBoundary();
  455. this.init();
  456. !this.disablePreview && this.preview();
  457. this.draw();
  458. },
  459. translate: function translate() {
  460. var transform = this.transform.translate;
  461. var meta = this.params;
  462. transform.x += meta.deltaX;
  463. transform.y += meta.deltaY;
  464. },
  465. pinch: function pinch() {
  466. this.transform.zoom *= this.params.zoom;
  467. },
  468. rotate: function rotate() {
  469. this.transform.angle += this.params.angle;
  470. },
  471. setZoom: function setZoom(scale) {
  472. scale = Math.min(Math.max(Number(scale) || 1, this.minZoom), this.maxZoom);
  473. this.transform.zoom = scale;
  474. },
  475. setTranslate: function setTranslate(offset) {
  476. if (Array.isArray(offset)) {
  477. var x = Number(offset[0]);
  478. var y = Number(offset[1]);
  479. this.transform.translate.x = isNaN(x) ? this.transform.translate.x : this.corner.left + x;
  480. this.transform.translate.y = isNaN(y) ? this.transform.translate.y : this.corner.top + y;
  481. }
  482. },
  483. setRotate: function setRotate(angle) {
  484. this.transform.angle = Number(angle) || 0;
  485. },
  486. setTransform: function setTransform(x, y, angle, scale) {
  487. this.setTranslate([x, y]);
  488. this.setZoom(scale);
  489. this.setRotate(angle);
  490. },
  491. setCutMode: function setCutMode(type) {
  492. if (!this.src) return;
  493. this.cutMode = true;
  494. this.cutDirection = type;
  495. },
  496. setCut: function setCut() {
  497. var corner = this.corner;
  498. var meta = this.params;
  499. this.setMeta(this.cutDirection, meta); // correct cutter position
  500. if (this.keepRatio) {
  501. if (this.cutDirection === 'lt' || this.cutDirection === 'rb') {
  502. meta.deltaY = meta.deltaX * this.cutRatio;
  503. } else {
  504. meta.deltaX = meta.deltaY / this.cutRatio;
  505. }
  506. }
  507. switch (this.cutDirection) {
  508. case 'lt':
  509. corner.top += meta.deltaY;
  510. corner.left += meta.deltaX;
  511. break;
  512. case 'rt':
  513. corner.top += meta.deltaY;
  514. corner.right -= this.keepRatio ? -meta.deltaX : meta.deltaX;
  515. break;
  516. case 'rb':
  517. corner.right -= meta.deltaX;
  518. corner.bottom -= meta.deltaY;
  519. break;
  520. case 'lb':
  521. corner.bottom -= meta.deltaY;
  522. corner.left += this.keepRatio ? -meta.deltaX : meta.deltaX;
  523. break;
  524. }
  525. this.ctrlWidth = this.containerWidth - corner.left - corner.right;
  526. this.ctrlHeight = this.containerHeight - corner.top - corner.bottom;
  527. },
  528. setMeta: function setMeta(direction, meta) {
  529. var ctrlWidth = this.ctrlWidth,
  530. ctrlHeight = this.ctrlHeight,
  531. minWidth = this.minWidth,
  532. minHeight = this.minHeight;
  533. switch (direction) {
  534. case 'lt':
  535. if (meta.deltaX > 0 || meta.deltaY > 0) {
  536. meta.deltaX = Math.min(meta.deltaX, ctrlWidth - minWidth);
  537. meta.deltaY = Math.min(meta.deltaY, ctrlHeight - minHeight);
  538. }
  539. break;
  540. case 'rt':
  541. if (meta.deltaX < 0 || meta.deltaY > 0) {
  542. meta.deltaX = Math.max(meta.deltaX, minWidth - ctrlWidth);
  543. meta.deltaY = Math.min(meta.deltaY, ctrlHeight - minHeight);
  544. }
  545. break;
  546. case 'rb':
  547. if (meta.deltaX < 0 || meta.deltaY < 0) {
  548. meta.deltaX = Math.max(meta.deltaX, minWidth - ctrlWidth);
  549. meta.deltaY = Math.max(meta.deltaY, minHeight - ctrlHeight);
  550. }
  551. break;
  552. case 'lb':
  553. if (meta.deltaX > 0 || meta.deltaY < 0) {
  554. meta.deltaX = Math.min(meta.deltaX, ctrlWidth - minWidth);
  555. meta.deltaY = Math.max(meta.deltaY, minHeight - ctrlHeight);
  556. }
  557. break;
  558. }
  559. },
  560. setBoundary: function setBoundary() {
  561. var zoom = this.transform.zoom;
  562. zoom = zoom < this.minZoom ? this.minZoom : zoom > this.maxZoom ? this.maxZoom : zoom;
  563. this.transform.zoom = zoom;
  564. if (!this.boundDetect || !this.disableRotate && !this.freeBoundDetect) return true;
  565. var translate = this.transform.translate;
  566. var corner = this.corner;
  567. var minX = corner.left - this.image.width + this.ctrlWidth - this.image.width * (zoom - 1) / 2;
  568. var maxX = corner.left + this.image.width * (zoom - 1) / 2;
  569. var minY = corner.top - this.image.height + this.ctrlHeight - this.image.height * (zoom - 1) / 2;
  570. var maxY = corner.top + this.image.height * (zoom - 1) / 2;
  571. translate.x = Math.floor(translate.x < minX ? minX : translate.x > maxX ? maxX : translate.x);
  572. translate.y = Math.floor(translate.y < minY ? minY : translate.y > maxY ? maxY : translate.y);
  573. },
  574. preview: function preview() {
  575. var _this4 = this;
  576. clearTimeout(this.previewTimer);
  577. this.previewTimer = setTimeout(function () {
  578. _this4.view = true;
  579. }, 500);
  580. },
  581. draw: function draw() {
  582. var _this5 = this;
  583. var context = uni.createCanvasContext(this.canvasId, this);
  584. var transform = this.transform;
  585. var corner = this.corner;
  586. var canvasZoom = this.canvasZoom;
  587. var img = this.image;
  588. context.save();
  589. context.setFillStyle(this.canvasBackground);
  590. this.$emit('beforeDraw', context, transform); // beforeDraw hook
  591. var zoom = transform.zoom;
  592. context.fillRect(0, 0, this.ctrlWidth * canvasZoom, this.ctrlHeight * canvasZoom); // clear canvas
  593. context.translate((transform.translate.x - corner.left + img.width / 2) * canvasZoom, (transform.translate.y - corner.top + img.height / 2) * canvasZoom); // translate the canvas's orgin to the image center
  594. context.rotate(transform.angle * Math.PI / 180);
  595. context.translate(-img.width * zoom * 0.5 * canvasZoom, -img.height * zoom * 0.5 * canvasZoom);
  596. context.drawImage(this.img, 0, 0, img.width * zoom * canvasZoom, img.height * zoom * canvasZoom);
  597. context.restore();
  598. this.$emit('afterDraw', context, {
  599. width: this.ctrlWidth * canvasZoom,
  600. height: this.ctrlHeight * canvasZoom
  601. }); // afterDraw hook
  602. context.draw(false, function () {
  603. uni.canvasToTempFilePath({
  604. canvasId: _this5.canvasId,
  605. quality: _this5.quality || 1,
  606. fileType: _this5.fileType,
  607. success: function success(res) {
  608. _this5.$emit('cropped', res.tempFilePath, {
  609. originWidth: _this5.image.originWidth,
  610. originHeight: _this5.image.originHeight,
  611. width: _this5.ctrlWidth * canvasZoom,
  612. height: _this5.ctrlHeight * canvasZoom,
  613. scale: zoom,
  614. translate: {
  615. x: transform.translate.x,
  616. y: transform.translate.y
  617. },
  618. rotate: transform.angle
  619. }); // draw callback
  620. }
  621. }, _this5);
  622. });
  623. }
  624. }
  625. };
  626. exports.default = _default2;
  627. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"]))
  628. /***/ })
  629. }]);
  630. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages_basics/common/vendor.js.map