From 0735c44f87e20092caba78fd06708d6943136d3e Mon Sep 17 00:00:00 2001 From: Patrick Mead Date: Fri, 10 May 2019 16:16:01 +0930 Subject: [PATCH 1/3] Fix UMD file not being updated for v2.3.2 --- dist/pinch-zoom.umd.js | 46 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/dist/pinch-zoom.umd.js b/dist/pinch-zoom.umd.js index 69c6332..3e723e1 100644 --- a/dist/pinch-zoom.umd.js +++ b/dist/pinch-zoom.umd.js @@ -17,23 +17,23 @@ value: true }); /* - + PinchZoom.js Copyright (c) Manuel Stofer 2013 - today - + Author: Manuel Stofer (mst@rtp.ch) Version: 2.3.2 - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -41,7 +41,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - + */ // polyfills @@ -158,7 +158,14 @@ dragEndEventName: 'pz_dragend', doubleTapEventName: 'pz_doubletap', verticalPadding: 0, - horizontalPadding: 0 + horizontalPadding: 0, + onZoomStart: null, + onZoomEnd: null, + onZoomUpdate: null, + onDragStart: null, + onDragEnd: null, + onDragUpdate: null, + onDoubleTap: null }, /** @@ -167,6 +174,9 @@ */ handleDragStart: function handleDragStart(event) { triggerEvent(this.el, this.options.dragStartEventName); + if (typeof this.options.onDragStart == "function") { + this.options.onDragStart(this, event); + } this.stopAnimation(); this.lastDragPosition = false; this.hasInteraction = true; @@ -186,6 +196,9 @@ handleDragEnd: function handleDragEnd() { triggerEvent(this.el, this.options.dragEndEventName); + if (typeof this.options.onDragEnd == "function") { + this.options.onDragEnd(this, event); + } this.end(); }, @@ -195,6 +208,9 @@ */ handleZoomStart: function handleZoomStart(event) { triggerEvent(this.el, this.options.zoomStartEventName); + if (typeof this.options.onZoomStart == "function") { + this.options.onZoomStart(this, event); + } this.stopAnimation(); this.lastScale = 1; this.nthZoom = 0; @@ -224,6 +240,9 @@ handleZoomEnd: function handleZoomEnd() { triggerEvent(this.el, this.options.zoomEndEventName); + if (typeof this.options.onZoomEnd == "function") { + this.options.onZoomEnd(this, event); + } this.end(); }, @@ -251,6 +270,9 @@ this.animate(this.options.animationDuration, updateProgress, this.swing); triggerEvent(this.el, this.options.doubleTapEventName); + if (typeof this.options.onDoubleTap == "function") { + this.options.onDoubleTap(this, event); + } }, /** @@ -337,6 +359,9 @@ y: (_scale - 1) * (center.y + this.offset.y) }); triggerEvent(this.el, this.options.zoomUpdateEventName); + if (typeof this.options.onZoomUpdate == "function") { + this.options.onZoomUpdate(this, event); + } }, /** @@ -390,6 +415,9 @@ }); } triggerEvent(this.el, this.options.dragUpdateEventName); + if (typeof this.options.onDragUpdate == "function") { + this.options.onDragUpdate(this, event); + } } }, @@ -857,7 +885,9 @@ } else { switch (interaction) { case 'zoom': - target.handleZoom(event, calculateScale(startTouches, targetTouches(event.touches))); + if (startTouches.length == 2 && event.touches.length == 2) { + target.handleZoom(event, calculateScale(startTouches, targetTouches(event.touches))); + } break; case 'drag': target.handleDrag(event); From 46883cdfc7fc1d5ddf63688553931ec9f13ce32d Mon Sep 17 00:00:00 2001 From: Patrick Mead Date: Fri, 10 May 2019 16:16:31 +0930 Subject: [PATCH 2/3] Update build script to create minified versions --- dist/pinch-zoom.min.js | 2 +- dist/pinch-zoom.umd.min.js | 1 + package.json | 1 + script/build.sh | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 dist/pinch-zoom.umd.min.js diff --git a/dist/pinch-zoom.min.js b/dist/pinch-zoom.min.js index 26daab0..93edec4 100644 --- a/dist/pinch-zoom.min.js +++ b/dist/pinch-zoom.min.js @@ -1 +1 @@ -"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(t,i){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n3&&(this.scale(n,e),this.drag(e,this.lastZoomCenter)),this.lastZoomCenter=e},handleZoomEnd:function(){triggerEvent(this.el,this.options.zoomEndEventName),"function"==typeof this.options.onZoomEnd&&this.options.onZoomEnd(this,event),this.end()},handleDoubleTap:function(t){var i=this.getTouches(t)[0],e=this.zoomFactor>1?1:this.options.tapZoomFactor,n=this.zoomFactor,o=function(t){this.scaleTo(n+t*(e-n),i)}.bind(this);this.hasInteraction||(this.isDoubleTap=!0,n>e&&(i=this.getCurrentZoomCenter()),this.animate(this.options.animationDuration,o,this.swing),triggerEvent(this.el,this.options.doubleTapEventName),"function"==typeof this.options.onDoubleTap&&this.options.onDoubleTap(this,t))},computeInitialOffset:function(){this.initialOffset={x:-Math.abs(this.el.offsetWidth*this.getInitialZoomFactor()-this.container.offsetWidth)/2,y:-Math.abs(this.el.offsetHeight*this.getInitialZoomFactor()-this.container.offsetHeight)/2}},resetOffset:function(){this.offset.x=this.initialOffset.x,this.offset.y=this.initialOffset.y},isImageLoaded:function(t){return"IMG"===t.nodeName?t.complete&&0!==t.naturalHeight:Array.from(t.querySelectorAll("img")).every(this.isImageLoaded)},setupOffsets:function(){this.options.setOffsetsOnce&&this._isOffsetsSet||(this._isOffsetsSet=!0,this.computeInitialOffset(),this.resetOffset())},sanitizeOffset:function(t){var i=this.el.offsetWidth*this.getInitialZoomFactor()*this.zoomFactor,e=this.el.offsetHeight*this.getInitialZoomFactor()*this.zoomFactor,n=i-this.getContainerX()+this.options.horizontalPadding,o=e-this.getContainerY()+this.options.verticalPadding,s=Math.max(n,0),a=Math.max(o,0),h=Math.min(n,0)-this.options.horizontalPadding,r=Math.min(o,0)-this.options.verticalPadding;return{x:Math.min(Math.max(t.x,h),s),y:Math.min(Math.max(t.y,r),a)}},scaleTo:function(t,i){this.scale(t/this.zoomFactor,i)},scale:function(t,i){t=this.scaleZoomFactor(t),this.addOffset({x:(t-1)*(i.x+this.offset.x),y:(t-1)*(i.y+this.offset.y)}),triggerEvent(this.el,this.options.zoomUpdateEventName),"function"==typeof this.options.onZoomUpdate&&this.options.onZoomUpdate(this,event)},scaleZoomFactor:function(t){var i=this.zoomFactor;return this.zoomFactor*=t,this.zoomFactor=Math.min(this.options.maxZoom,Math.max(this.zoomFactor,this.options.minZoom)),this.zoomFactor/i},canDrag:function(){return this.options.draggableUnzoomed||!((t=this.zoomFactor)>(i=1)-.01&&tMath.abs(t.y-i.y)?this.addOffset({x:-(t.x-i.x),y:0}):this.addOffset({y:-(t.y-i.y),x:0}):this.addOffset({y:-(t.y-i.y),x:-(t.x-i.x)}),triggerEvent(this.el,this.options.dragUpdateEventName),"function"==typeof this.options.onDragUpdate&&this.options.onDragUpdate(this,event))},getTouchCenter:function(t){return this.getVectorAvg(t)},getVectorAvg:function(t){return{x:t.map(function(t){return t.x}).reduce(i)/t.length,y:t.map(function(t){return t.y}).reduce(i)/t.length}},addOffset:function(t){this.offset={x:this.offset.x+t.x,y:this.offset.y+t.y}},sanitize:function(){this.zoomFactor=t?(i(1),n&&n(),this.update(),this.stopAnimation(),this.update()):(e&&(h=e(h)),i(h),this.update(),requestAnimationFrame(s))}}.bind(this);this.inAnimation=!0,requestAnimationFrame(s)},stopAnimation:function(){this.inAnimation=!1},swing:function(t){return-Math.cos(t*Math.PI)/2+.5},getContainerX:function(){return this.container.offsetWidth},getContainerY:function(){return this.container.offsetHeight},setContainerY:function(t){return this.container.style.height=t+"px"},unsetContainerY:function(){this.container.style.height=null},setupMarkup:function(){this.container=buildElement('
'),this.el.parentNode.insertBefore(this.container,this.el),this.container.appendChild(this.el),this.container.style.overflow="hidden",this.container.style.position="relative",this.el.style.webkitTransformOrigin="0% 0%",this.el.style.mozTransformOrigin="0% 0%",this.el.style.msTransformOrigin="0% 0%",this.el.style.oTransformOrigin="0% 0%",this.el.style.transformOrigin="0% 0%",this.el.style.position="absolute"},end:function(){this.hasInteraction=!1,this.sanitize(),this.update()},bindEvents:function(){var t=this;e(this.container,this),window.addEventListener("resize",this.update.bind(this)),Array.from(this.el.querySelectorAll("img")).forEach(function(i){i.addEventListener("load",t.update.bind(t))}),"IMG"===this.el.nodeName&&this.el.addEventListener("load",this.update.bind(this))},update:function(t){this.updatePlaned||(this.updatePlaned=!0,window.setTimeout(function(){this.updatePlaned=!1,t&&"resize"===t.type&&(this.updateAspectRatio(),this.setupOffsets()),t&&"load"===t.type&&(this.updateAspectRatio(),this.setupOffsets());var i=this.getInitialZoomFactor()*this.zoomFactor,e=-this.offset.x/i,n=-this.offset.y/i,o="scale3d("+i+", "+i+",1) translate3d("+e+"px,"+n+"px,0px)",s="scale("+i+", "+i+") translate("+e+"px,"+n+"px)",a=function(){this.clone&&(this.clone.parentNode.removeChild(this.clone),delete this.clone)}.bind(this);!this.options.use2d||this.hasInteraction||this.inAnimation?(this.is3d=!0,a(),this.el.style.webkitTransform=o,this.el.style.mozTransform=s,this.el.style.msTransform=s,this.el.style.oTransform=s,this.el.style.transform=o):(this.is3d&&(this.clone=this.el.cloneNode(!0),this.clone.style.pointerEvents="none",this.container.appendChild(this.clone),window.setTimeout(a,200)),this.el.style.webkitTransform=s,this.el.style.mozTransform=s,this.el.style.msTransform=s,this.el.style.oTransform=s,this.el.style.transform=s,this.is3d=!1)}.bind(this),0))},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1}};var e=function(t,i){var e=null,n=0,o=null,s=null,a=function(t,n){if(e!==t){if(e&&!t)switch(e){case"zoom":i.handleZoomEnd(n);break;case"drag":i.handleDragEnd(n)}switch(t){case"zoom":i.handleZoomStart(n);break;case"drag":i.handleDragStart(n)}}e=t},h=function(t){2===n?a("zoom"):1===n&&i.canDrag()?a("drag",t):a(null,t)},r=function(t){return Array.from(t).map(function(t){return{x:t.pageX,y:t.pageY}})},f=function(t,i){var e,n;return e=t.x-i.x,n=t.y-i.y,Math.sqrt(e*e+n*n)},l=function(t){t.stopPropagation(),t.preventDefault()},c=!0;t.addEventListener("touchstart",function(t){i.enabled&&(c=!0,n=t.touches.length,function(t){var s=(new Date).getTime();if(n>1&&(o=null),s-o<300)switch(l(t),i.handleDoubleTap(t),e){case"zoom":i.handleZoomEnd(t);break;case"drag":i.handleDragEnd(t)}else i.isDoubleTap=!1;1===n&&(o=s)}(t))}),t.addEventListener("touchmove",function(t){if(i.enabled&&!i.isDoubleTap){if(c)h(t),e&&l(t),s=r(t.touches);else{switch(e){case"zoom":i.handleZoom(t,(n=s,o=r(t.touches),a=f(n[0],n[1]),f(o[0],o[1])/a));break;case"drag":i.handleDrag(t)}e&&(l(t),i.update())}c=!1}var n,o,a}),t.addEventListener("touchend",function(t){i.enabled&&(n=t.touches.length,h(t))})};return t},PinchZoom=definePinchZoom();export default PinchZoom; \ No newline at end of file +"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(a){if(null==a)throw new TypeError("Cannot convert undefined or null to object");for(var b,c=Object(a),d=1;db-.01&&ac&&(b=this.getCurrentZoomCenter()),this.animate(this.options.animationDuration,e,this.swing),triggerEvent(this.el,this.options.doubleTapEventName),"function"==typeof this.options.onDoubleTap&&this.options.onDoubleTap(this,a))},computeInitialOffset:function(){this.initialOffset={x:-c(this.el.offsetWidth*this.getInitialZoomFactor()-this.container.offsetWidth)/2,y:-c(this.el.offsetHeight*this.getInitialZoomFactor()-this.container.offsetHeight)/2}},resetOffset:function(){this.offset.x=this.initialOffset.x,this.offset.y=this.initialOffset.y},isImageLoaded:function(a){return"IMG"===a.nodeName?a.complete&&0!==a.naturalHeight:Array.from(a.querySelectorAll("img")).every(this.isImageLoaded)},setupOffsets:function(){this.options.setOffsetsOnce&&this._isOffsetsSet||(this._isOffsetsSet=!0,this.computeInitialOffset(),this.resetOffset())},sanitizeOffset:function(c){var d=this.el.offsetWidth*this.getInitialZoomFactor()*this.zoomFactor,e=this.el.offsetHeight*this.getInitialZoomFactor()*this.zoomFactor,f=d-this.getContainerX()+this.options.horizontalPadding,g=e-this.getContainerY()+this.options.verticalPadding,h=b(f,0),i=b(g,0),j=a(f,0)-this.options.horizontalPadding,k=a(g,0)-this.options.verticalPadding;return{x:a(b(c.x,j),h),y:a(b(c.y,k),i)}},scaleTo:function(a,b){this.scale(a/this.zoomFactor,b)},scale:function(a,b){a=this.scaleZoomFactor(a),this.addOffset({x:(a-1)*(b.x+this.offset.x),y:(a-1)*(b.y+this.offset.y)}),triggerEvent(this.el,this.options.zoomUpdateEventName),"function"==typeof this.options.onZoomUpdate&&this.options.onZoomUpdate(this,event)},scaleZoomFactor:function(c){var d=this.zoomFactor;return this.zoomFactor*=c,this.zoomFactor=a(this.options.maxZoom,b(this.zoomFactor,this.options.minZoom)),this.zoomFactor/d},canDrag:function(){return this.options.draggableUnzoomed||!f(this.zoomFactor,1)},drag:function(a,b){b&&(this.options.lockDragAxis?c(a.x-b.x)>c(a.y-b.y)?this.addOffset({x:-(a.x-b.x),y:0}):this.addOffset({y:-(a.y-b.y),x:0}):this.addOffset({y:-(a.y-b.y),x:-(a.x-b.x)}),triggerEvent(this.el,this.options.dragUpdateEventName),"function"==typeof this.options.onDragUpdate&&this.options.onDragUpdate(this,event))},getTouchCenter:function(a){return this.getVectorAvg(a)},getVectorAvg:function(a){return{x:a.map(function(a){return a.x}).reduce(e)/a.length,y:a.map(function(a){return a.y}).reduce(e)/a.length}},addOffset:function(a){this.offset={x:this.offset.x+a.x,y:this.offset.y+a.y}},sanitize:function(){this.zoomFactor=a?(b(1),d&&d(),this.update(),this.stopAnimation(),this.update()):(c&&(h=c(h)),b(h),this.update(),requestAnimationFrame(f))}}.bind(this);this.inAnimation=!0,requestAnimationFrame(f)},stopAnimation:function(){this.inAnimation=!1},swing:function(a){return-Math.cos(a*Math.PI)/2+.5},getContainerX:function(){return this.container.offsetWidth},getContainerY:function(){return this.container.offsetHeight},setContainerY:function(a){return this.container.style.height=a+"px"},unsetContainerY:function(){this.container.style.height=null},setupMarkup:function(){this.container=buildElement("
"),this.el.parentNode.insertBefore(this.container,this.el),this.container.appendChild(this.el),this.container.style.overflow="hidden",this.container.style.position="relative",this.el.style.webkitTransformOrigin="0% 0%",this.el.style.mozTransformOrigin="0% 0%",this.el.style.msTransformOrigin="0% 0%",this.el.style.oTransformOrigin="0% 0%",this.el.style.transformOrigin="0% 0%",this.el.style.position="absolute"},end:function(){this.hasInteraction=!1,this.sanitize(),this.update()},bindEvents:function(){var a=this;g(this.container,this),window.addEventListener("resize",this.update.bind(this)),Array.from(this.el.querySelectorAll("img")).forEach(function(b){b.addEventListener("load",a.update.bind(a))}),"IMG"===this.el.nodeName&&this.el.addEventListener("load",this.update.bind(this))},update:function(a){this.updatePlaned||(this.updatePlaned=!0,window.setTimeout(function(){this.updatePlaned=!1,a&&"resize"===a.type&&(this.updateAspectRatio(),this.setupOffsets()),a&&"load"===a.type&&(this.updateAspectRatio(),this.setupOffsets());var b=this.getInitialZoomFactor()*this.zoomFactor,c=-this.offset.x/b,d=-this.offset.y/b,e="scale3d("+b+", "+b+",1) translate3d("+c+"px,"+d+"px,0px)",f="scale("+b+", "+b+") translate("+c+"px,"+d+"px)",g=function(){this.clone&&(this.clone.parentNode.removeChild(this.clone),delete this.clone)}.bind(this);!this.options.use2d||this.hasInteraction||this.inAnimation?(this.is3d=!0,g(),this.el.style.webkitTransform=e,this.el.style.mozTransform=f,this.el.style.msTransform=f,this.el.style.oTransform=f,this.el.style.transform=e):(this.is3d&&(this.clone=this.el.cloneNode(!0),this.clone.style.pointerEvents="none",this.container.appendChild(this.clone),window.setTimeout(g,200)),this.el.style.webkitTransform=f,this.el.style.mozTransform=f,this.el.style.msTransform=f,this.el.style.oTransform=f,this.el.style.transform=f,this.is3d=!1)}.bind(this),0))},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1}};var g=function(a,b){var c=null,d=0,e=null,f=null,g=function(a,d){c!==a&&(c&&!a&&("zoom"===c?b.handleZoomEnd(d):"drag"===c?b.handleDragEnd(d):void 0),"zoom"===a?b.handleZoomStart(d):"drag"===a?b.handleDragStart(d):void 0);c=a},h=function(a){2===d?g("zoom"):1===d&&b.canDrag()?g("drag",a):g(null,a)},i=function(a){return Array.from(a).map(function(a){return{x:a.pageX,y:a.pageY}})},j=function(c,a){var d,e,b=Math.sqrt;return d=c.x-a.x,e=c.y-a.y,b(d*d+e*e)},k=function(a,b){var c=j(a[0],a[1]),d=j(b[0],b[1]);return d/c},l=function(a){a.stopPropagation(),a.preventDefault()},m=function(a){var f=new Date().getTime();1f-e?(l(a),b.handleDoubleTap(a),"zoom"===c?b.handleZoomEnd(a):"drag"===c?b.handleDragEnd(a):void 0):b.isDoubleTap=!1;1===d&&(e=f)},n=!0;a.addEventListener("touchstart",function(a){b.enabled&&(n=!0,d=a.touches.length,m(a))}),a.addEventListener("touchmove",function(a){b.enabled&&!b.isDoubleTap&&(n?(h(a),c&&l(a),f=i(a.touches)):("zoom"===c?2==f.length&&2==a.touches.length&&b.handleZoom(a,k(f,i(a.touches))):"drag"===c?b.handleDrag(a):void 0,c&&(l(a),b.update())),n=!1)}),a.addEventListener("touchend",function(a){b.enabled&&(d=a.touches.length,h(a))})};return d},PinchZoom=definePinchZoom();export default PinchZoom; \ No newline at end of file diff --git a/dist/pinch-zoom.umd.min.js b/dist/pinch-zoom.umd.min.js new file mode 100644 index 0000000..8441fa6 --- /dev/null +++ b/dist/pinch-zoom.umd.min.js @@ -0,0 +1 @@ +(function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(exports);else{var c={exports:{}};b(c.exports),a.PinchZoom=c.exports}})(this,function(a){'use strict';Object.defineProperty(a,"__esModule",{value:!0}),"function"!=typeof Object.assign&&Object.defineProperty(Object,"assign",{value:function(a){if(null==a)throw new TypeError("Cannot convert undefined or null to object");for(var b,c=Object(a),d=1;db-.01&&ad&&(b=this.getCurrentZoomCenter()),this.animate(this.options.animationDuration,f,this.swing),c(this.el,this.options.doubleTapEventName),"function"==typeof this.options.onDoubleTap&&this.options.onDoubleTap(this,a))},computeInitialOffset:function(){this.initialOffset={x:-e(this.el.offsetWidth*this.getInitialZoomFactor()-this.container.offsetWidth)/2,y:-e(this.el.offsetHeight*this.getInitialZoomFactor()-this.container.offsetHeight)/2}},resetOffset:function(){this.offset.x=this.initialOffset.x,this.offset.y=this.initialOffset.y},isImageLoaded:function(a){return"IMG"===a.nodeName?a.complete&&0!==a.naturalHeight:Array.from(a.querySelectorAll("img")).every(this.isImageLoaded)},setupOffsets:function(){this.options.setOffsetsOnce&&this._isOffsetsSet||(this._isOffsetsSet=!0,this.computeInitialOffset(),this.resetOffset())},sanitizeOffset:function(b){var c=this.el.offsetWidth*this.getInitialZoomFactor()*this.zoomFactor,e=this.el.offsetHeight*this.getInitialZoomFactor()*this.zoomFactor,f=c-this.getContainerX()+this.options.horizontalPadding,g=e-this.getContainerY()+this.options.verticalPadding,h=d(f,0),i=d(g,0),j=a(f,0)-this.options.horizontalPadding,k=a(g,0)-this.options.verticalPadding;return{x:a(d(b.x,j),h),y:a(d(b.y,k),i)}},scaleTo:function(a,b){this.scale(a/this.zoomFactor,b)},scale:function(a,b){a=this.scaleZoomFactor(a),this.addOffset({x:(a-1)*(b.x+this.offset.x),y:(a-1)*(b.y+this.offset.y)}),c(this.el,this.options.zoomUpdateEventName),"function"==typeof this.options.onZoomUpdate&&this.options.onZoomUpdate(this,event)},scaleZoomFactor:function(b){var c=this.zoomFactor;return this.zoomFactor*=b,this.zoomFactor=a(this.options.maxZoom,d(this.zoomFactor,this.options.minZoom)),this.zoomFactor/c},canDrag:function(){return this.options.draggableUnzoomed||!h(this.zoomFactor,1)},drag:function(a,b){b&&(this.options.lockDragAxis?e(a.x-b.x)>e(a.y-b.y)?this.addOffset({x:-(a.x-b.x),y:0}):this.addOffset({y:-(a.y-b.y),x:0}):this.addOffset({y:-(a.y-b.y),x:-(a.x-b.x)}),c(this.el,this.options.dragUpdateEventName),"function"==typeof this.options.onDragUpdate&&this.options.onDragUpdate(this,event))},getTouchCenter:function(a){return this.getVectorAvg(a)},getVectorAvg:function(a){return{x:a.map(function(a){return a.x}).reduce(g)/a.length,y:a.map(function(a){return a.y}).reduce(g)/a.length}},addOffset:function(a){this.offset={x:this.offset.x+a.x,y:this.offset.y+a.y}},sanitize:function(){this.zoomFactor=a?(b(1),d&&d(),this.update(),this.stopAnimation(),this.update()):(c&&(h=c(h)),b(h),this.update(),requestAnimationFrame(f))}}.bind(this);this.inAnimation=!0,requestAnimationFrame(f)},stopAnimation:function(){this.inAnimation=!1},swing:function(a){return-Math.cos(a*Math.PI)/2+.5},getContainerX:function(){return this.container.offsetWidth},getContainerY:function(){return this.container.offsetHeight},setContainerY:function(a){return this.container.style.height=a+"px"},unsetContainerY:function(){this.container.style.height=null},setupMarkup:function(){this.container=b("
"),this.el.parentNode.insertBefore(this.container,this.el),this.container.appendChild(this.el),this.container.style.overflow="hidden",this.container.style.position="relative",this.el.style.webkitTransformOrigin="0% 0%",this.el.style.mozTransformOrigin="0% 0%",this.el.style.msTransformOrigin="0% 0%",this.el.style.oTransformOrigin="0% 0%",this.el.style.transformOrigin="0% 0%",this.el.style.position="absolute"},end:function(){this.hasInteraction=!1,this.sanitize(),this.update()},bindEvents:function(){var a=this;i(this.container,this),window.addEventListener("resize",this.update.bind(this)),Array.from(this.el.querySelectorAll("img")).forEach(function(b){b.addEventListener("load",a.update.bind(a))}),"IMG"===this.el.nodeName&&this.el.addEventListener("load",this.update.bind(this))},update:function(a){this.updatePlaned||(this.updatePlaned=!0,window.setTimeout(function(){this.updatePlaned=!1,a&&"resize"===a.type&&(this.updateAspectRatio(),this.setupOffsets()),a&&"load"===a.type&&(this.updateAspectRatio(),this.setupOffsets());var b=this.getInitialZoomFactor()*this.zoomFactor,c=-this.offset.x/b,d=-this.offset.y/b,e="scale3d("+b+", "+b+",1) translate3d("+c+"px,"+d+"px,0px)",f="scale("+b+", "+b+") translate("+c+"px,"+d+"px)",g=function(){this.clone&&(this.clone.parentNode.removeChild(this.clone),delete this.clone)}.bind(this);!this.options.use2d||this.hasInteraction||this.inAnimation?(this.is3d=!0,g(),this.el.style.webkitTransform=e,this.el.style.mozTransform=f,this.el.style.msTransform=f,this.el.style.oTransform=f,this.el.style.transform=e):(this.is3d&&(this.clone=this.el.cloneNode(!0),this.clone.style.pointerEvents="none",this.container.appendChild(this.clone),window.setTimeout(g,200)),this.el.style.webkitTransform=f,this.el.style.mozTransform=f,this.el.style.msTransform=f,this.el.style.oTransform=f,this.el.style.transform=f,this.is3d=!1)}.bind(this),0))},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1}};var i=function(a,b){var c=null,d=0,e=null,f=null,g=function(a,d){c!==a&&(c&&!a&&("zoom"===c?b.handleZoomEnd(d):"drag"===c?b.handleDragEnd(d):void 0),"zoom"===a?b.handleZoomStart(d):"drag"===a?b.handleDragStart(d):void 0);c=a},h=function(a){2===d?g("zoom"):1===d&&b.canDrag()?g("drag",a):g(null,a)},i=function(a){return Array.from(a).map(function(a){return{x:a.pageX,y:a.pageY}})},j=function(c,a){var d,e,b=Math.sqrt;return d=c.x-a.x,e=c.y-a.y,b(d*d+e*e)},k=function(a,b){var c=j(a[0],a[1]),d=j(b[0],b[1]);return d/c},l=function(a){a.stopPropagation(),a.preventDefault()},m=function(a){var f=new Date().getTime();1f-e?(l(a),b.handleDoubleTap(a),"zoom"===c?b.handleZoomEnd(a):"drag"===c?b.handleDragEnd(a):void 0):b.isDoubleTap=!1;1===d&&(e=f)},n=!0;a.addEventListener("touchstart",function(a){b.enabled&&(n=!0,d=a.touches.length,m(a))}),a.addEventListener("touchmove",function(a){b.enabled&&!b.isDoubleTap&&(n?(h(a),c&&l(a),f=i(a.touches)):("zoom"===c?2==f.length&&2==a.touches.length&&b.handleZoom(a,k(f,i(a.touches))):"drag"===c?b.handleDrag(a):void 0,c&&(l(a),b.update())),n=!1)}),a.addEventListener("touchend",function(a){b.enabled&&(d=a.touches.length,h(a))})};return f}();a.default=d}); \ No newline at end of file diff --git a/package.json b/package.json index 440101a..4699346 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "typings": "src/pinch-zoom.d.ts", "devDependencies": { "babel-cli": "~6.26.0", + "babel-minify": "^0.5.0", "babel-preset-env": "~1.6.1" }, "scripts": { diff --git a/script/build.sh b/script/build.sh index 5692479..3fec3ba 100755 --- a/script/build.sh +++ b/script/build.sh @@ -6,3 +6,7 @@ mkdir dist # UMD build babel src/pinch-zoom.js -o dist/pinch-zoom.umd.js + +# Minify +babel-minify --sourceType module src/pinch-zoom.js -o dist/pinch-zoom.min.js +babel-minify dist/pinch-zoom.umd.js -o dist/pinch-zoom.umd.min.js From 6451413dd1e15aa9b13d18e6118170f136d87586 Mon Sep 17 00:00:00 2001 From: Patrick Mead Date: Fri, 10 May 2019 16:17:44 +0930 Subject: [PATCH 3/3] Bump version to v2.3.3 --- dist/pinch-zoom.umd.js | 2 +- package.json | 2 +- src/pinch-zoom.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/pinch-zoom.umd.js b/dist/pinch-zoom.umd.js index 3e723e1..02e1067 100644 --- a/dist/pinch-zoom.umd.js +++ b/dist/pinch-zoom.umd.js @@ -22,7 +22,7 @@ Copyright (c) Manuel Stofer 2013 - today Author: Manuel Stofer (mst@rtp.ch) - Version: 2.3.2 + Version: 2.3.3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index 4699346..e7f21ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pinch-zoom-js", - "version": "2.3.2", + "version": "2.3.3", "description": "Browser library for multi-touch gestures to zoom and drag on any DOM element.", "author": "Manuel Stofer", "license": "MIT", diff --git a/src/pinch-zoom.js b/src/pinch-zoom.js index 20de53d..7f211bb 100644 --- a/src/pinch-zoom.js +++ b/src/pinch-zoom.js @@ -4,7 +4,7 @@ Copyright (c) Manuel Stofer 2013 - today Author: Manuel Stofer (mst@rtp.ch) - Version: 2.3.2 + Version: 2.3.3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal