"use strict";var _defaults,_baseComponent=_interopRequireDefault(require("../helpers/baseComponent")),_classNames=_interopRequireDefault(require("../helpers/classNames")),_gestures=require("../helpers/gestures");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(n,!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var defaults=(_defineProperty(_defaults={prefixCls:"wux-gallery",classNames:"wux-animate--slideInRight",indicatorDots:!1,indicatorColor:"rgba(0, 0, 0, .3)",indicatorActiveColor:"#000000",autoplay:!1,interval:5e3,duration:500,circular:!1,vertical:!1,icon:"",showDelete:!0,allowScale:!0,current:0,urls:[]},"delete",function(){}),_defineProperty(_defaults,"cancel",function(){}),_defineProperty(_defaults,"onChange",function(){}),_defineProperty(_defaults,"onTap",function(){return!0}),_defaults),MIN_RATIO=1,MAX_RATIO=1.2,defaultTouchOptions={scale:1,offset:[.5,3]},getImages=function(t){return(0<arguments.length&&void 0!==t?t:[]).map(function(t){return"object"!==_typeof(t)?{image:t,remark:"",touch:_objectSpread({},defaultTouchOptions)}:_objectSpread({},t,{touch:_objectSpread({},defaultTouchOptions)})})};(0,_baseComponent.default)({useFunc:!0,data:defaults,computed:{classes:["prefixCls",function(t){return{swiper:"".concat(t,"__swiper"),item:"".concat(t,"__item"),img:"".concat(t,"__img"),remark:"".concat(t,"__remark"),opr:"".concat(t,"__opr"),del:"".concat(t,"__del"),icon:"".concat(t,"__icon")}}]},methods:{hide:function(){this.$$setData({in:!1}),"function"==typeof this.fns.cancel&&this.fns.cancel()},show:function(t){var e=0<arguments.length&&void 0!==t?t:{},n=this.$$mergeOptionsAndBindMethods(Object.assign({},defaults,e,{images:getImages(e.urls)}));this.$$setData(_objectSpread({in:!0},n))},onTap:function(t){if(this.allowItemClick){var e=t.currentTarget.dataset.index;!0===this.fns.onTap(e,this.data.urls)&&this.hide()}},onTouchStart:function(t){if(this.allowItemClick=!0,!this.data.allowScale||1===(0,_gestures.getPointsNumber)(t)||this.touching)return!1;var e=(0,_gestures.getTouchPoints)(t),n=(0,_gestures.getTouchPoints)(t,1),r=(0,_gestures.getPointsDistance)(e,n);this.touching=!1,this.prevDistance=r,this.$$setData({transition:"none"})},onTouchMove:function(t){var e=this;if(!this.data.allowScale||1===(0,_gestures.getPointsNumber)(t)||this.isRendered)return!1;var n=(0,_gestures.getTouchPoints)(t),r=(0,_gestures.getTouchPoints)(t,1),i=(0,_gestures.getPointsDistance)(n,r),o=t.currentTarget.dataset,s=o.touch,a=o.index,c=i-this.prevDistance,u=s.scale+.005*c;if(a!==this.data.current)return!1;u<=s.offset[0]*MIN_RATIO?u=s.offset[0]*MIN_RATIO:u>=s.offset[1]*MAX_RATIO&&(u=s.offset[1]*MAX_RATIO);var l=_defineProperty({},"images[".concat(a,"].touch.scale"),u);this.touching||(this.touching=!0),this.prevDistance=i,this.allowItemClick=!1,this.isRendered=!0,this.$$setData(l).then(function(){return e.isRendered=!1})},onTouchEnd:function(t){var e,n=this;if(!this.data.allowScale||!this.touching)return!1;var r=t.currentTarget.dataset,i=r.touch,o=r.index,s=i.scale;s<=1?s=1:s>=i.offset[1]*MAX_RATIO&&(s=i.offset[1]);var a=(_defineProperty(e={},"images[".concat(o,"].touch.scale"),s),_defineProperty(e,"transition","transform .3s"),e);this.touching=!1,this.$$setData(a).then(function(){setTimeout(function(){return n.allowItemClick=!0},400)})},onDelete:function(t){"function"==typeof this.fns.delete&&!0===this.fns.delete(this.data.current,this.data.urls)&&this.hide()},onChange:function(t){this.$$setData({current:t.detail.current}),"function"==typeof this.fns.onChange&&this.fns.onChange.call(this,t)},slideTo:function(t,e){var n=this,r=0<arguments.length&&void 0!==t?t:0,i=1<arguments.length&&void 0!==e?e:0,o=this.data,s=o.urls,a=o.circular,c=s.length-1;return r<0?r=a?c:0:c<r&&(r=a?0:c),0<i?this.$$requestAnimationFrame(function(){return n.$$setData({current:r})},i):this.$$setData({current:r})},slideNext:function(t){return this.slideTo(this.data.current+1,t)},slidePrev:function(t){return this.slideTo(this.data.current-1,t)}}});
|