├── .babelrc ├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── dist └── vue-swipeable-bottom-sheet.js ├── example ├── example.vue ├── index.html ├── index.js └── vue-swipeable-bottom-sheet.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── src ├── components │ └── SwipeableBottomSheet.vue └── index.js ├── vue-swipeable-bottom-sheet.gif ├── webpack.config.js └── webpack.example.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"] 3 | } 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | custom: # Replace with a single custom sponsorship URL 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (C) 2019 by [atsutopia](https://github.com/atsutopia) 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 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. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vue Swipeable Bottom Sheet 2 | 3 | ![NPM](https://nodei.co/npm/vue-swipeable-bottom-sheet.png) 4 | [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/atsutopia/vue-swipeable-bottom-sheet) 5 | 6 | A swipeable material's bottom sheet implementation, that uses [hammerjs](https://github.com/hammerjs/hammer.js). 7 | 8 | ![vue-swipeable-bottom-sheet.gif](vue-swipeable-bottom-sheet.gif) 9 | 10 | ## Installation 11 | 12 | #### NPM 13 | 14 | ``` 15 | npm install --save vue-swipeable-bottom-sheet 16 | ``` 17 | 18 | or 19 | 20 | #### Yarn 21 | 22 | ``` 23 | yarn add vue-swipeable-bottom-sheet 24 | ``` 25 | 26 | ## Usage 27 | 28 | ``` 29 | 38 | 39 | 48 | ``` 49 | 50 | #### mount with ssr 51 | 52 | ``` 53 | 64 | 65 | if (process.browser) { 66 | const SwipeableBottomSheet = require('vue-swipeable-bottom-sheet') 67 | Vue.component("swipeable-bottom-sheet", SwipeableBottomSheet) 68 | } 69 | ``` 70 | 71 | ## License 72 | 73 | [MIT](LICENSE) 74 | -------------------------------------------------------------------------------- /dist/vue-swipeable-bottom-sheet.js: -------------------------------------------------------------------------------- 1 | module.exports=function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=4)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i,r=n(10),s=(i=r)&&i.__esModule?i:{default:i};e.default={props:{openY:{type:Number,default:.1},halfY:{type:Number,default:.8},defaultState:{type:String,default:"close"},barColor:{type:String,default:"rgba(0, 0, 0, .3)"}},data:function(){return{mc:null,y:0,startY:0,isMove:!1,state:this.defaultState,rect:{}}},mounted:function(){var t=this;window.onresize=function(){t.rect=t.$refs.card.getBoundingClientRect()},this.rect=this.$refs.card.getBoundingClientRect(),this.mc=new s.default(this.$refs.pan),this.mc.get("pan").set({direction:s.default.DIRECTION_ALL}),this.mc.on("panup pandown",function(e){t.y=e.center.y-16}),this.mc.on("panstart",function(e){t.startY=e.center.y,t.isMove=!0}),this.mc.on("panend",function(e){switch(t.isMove=!1,t.state){case"close":case"half":if("close"==t.state){t.startY-e.center.y>120&&(t.state="half"),t.startY-e.center.y>320&&(t.state="open");break}t.startY-e.center.y>120&&(t.state="open"),t.startY-e.center.y<-50&&(t.state="close");break;case"open":t.startY-e.center.y<-120&&(t.state="half")}})},beforeDestroy:function(){this.mc.destroy(),window.onresize=null},methods:{calcY:function(){switch(this.state){case"close":return this.rect.height;case"open":return this.rect.height*this.openY;case"half":return this.rect.height*this.halfY;default:return this.y}},setState:function(t){this.state=t}}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){for(var n=[],i={},r=0;rn.parts.length&&(i.parts.length=n.parts.length)}else{var s=[];for(r=0;r\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",r=s.console&&(s.console.warn||s.console.log);return r&&r.call(s.console,i,n),t.apply(this,arguments)}}c="function"!=typeof Object.assign?function(t){if(t===u||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n-1}function P(t){return t.trim().split(/\s+/g)}function O(t,e,n){if(t.indexOf&&!n)return t.indexOf(e);for(var i=0;in[e]}):i.sort()),i}function N(t,e){for(var n,i,r=e[0].toUpperCase()+e.slice(1),s=0;s1&&!n.firstMultiple?n.firstMultiple=it(e):1===r&&(n.firstMultiple=!1);var s=n.firstInput,o=n.firstMultiple,a=o?o.center:s.center,c=e.center=rt(i);e.timeStamp=v(),e.deltaTime=e.timeStamp-s.timeStamp,e.angle=ut(a,c),e.distance=at(a,c),function(t,e){var n=e.center,i=t.offsetDelta||{},r=t.prevDelta||{},s=t.prevInput||{};e.eventType!==L&&s.eventType!==W||(r=t.prevDelta={x:s.deltaX||0,y:s.deltaY||0},i=t.offsetDelta={x:n.x,y:n.y});e.deltaX=r.x+(n.x-i.x),e.deltaY=r.y+(n.y-i.y)}(n,e),e.offsetDirection=ot(e.deltaX,e.deltaY);var h=st(e.deltaTime,e.deltaX,e.deltaY);e.overallVelocityX=h.x,e.overallVelocityY=h.y,e.overallVelocity=d(h.x)>d(h.y)?h.x:h.y,e.scale=o?(l=o.pointers,p=i,at(p[0],p[1],tt)/at(l[0],l[1],tt)):1,e.rotation=o?function(t,e){return ut(e[1],e[0],tt)+ut(t[1],t[0],tt)}(o.pointers,i):0,e.maxPointers=n.prevInput?e.pointers.length>n.prevInput.maxPointers?e.pointers.length:n.prevInput.maxPointers:e.pointers.length,function(t,e){var n,i,r,s,o=t.lastInterval||e,a=e.timeStamp-o.timeStamp;if(e.eventType!=q&&(a>F||o.velocity===u)){var c=e.deltaX-o.deltaX,h=e.deltaY-o.deltaY,l=st(a,c,h);i=l.x,r=l.y,n=d(l.x)>d(l.y)?l.x:l.y,s=ot(c,h),t.lastInterval=e}else n=o.velocity,i=o.velocityX,r=o.velocityY,s=o.direction;e.velocity=n,e.velocityX=i,e.velocityY=r,e.direction=s}(n,e);var l,p;var f=t.element;A(e.srcEvent.target,f)&&(f=e.srcEvent.target);e.target=f}(t,n),t.emit("hammer.input",n),t.recognize(n),t.session.prevInput=n}function it(t){for(var e=[],n=0;n=d(e)?t<0?B:V:e<0?$:G}function at(t,e,n){n||(n=Q);var i=e[n[0]]-t[n[0]],r=e[n[1]]-t[n[1]];return Math.sqrt(i*i+r*r)}function ut(t,e,n){n||(n=Q);var i=e[n[0]]-t[n[0]],r=e[n[1]]-t[n[1]];return 180*Math.atan2(r,i)/Math.PI}et.prototype={handler:function(){},init:function(){this.evEl&&w(this.element,this.evEl,this.domHandler),this.evTarget&&w(this.target,this.evTarget,this.domHandler),this.evWin&&w(z(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&I(this.element,this.evEl,this.domHandler),this.evTarget&&I(this.target,this.evTarget,this.domHandler),this.evWin&&I(z(this.element),this.evWin,this.domHandler)}};var ct={mousedown:L,mousemove:U,mouseup:W},ht="mousedown",lt="mousemove mouseup";function pt(){this.evEl=ht,this.evWin=lt,this.pressed=!1,et.apply(this,arguments)}_(pt,et,{handler:function(t){var e=ct[t.type];e&L&&0===t.button&&(this.pressed=!0),e&U&&1!==t.which&&(e=W),this.pressed&&(e&W&&(this.pressed=!1),this.callback(this.manager,e,{pointers:[t],changedPointers:[t],pointerType:"mouse",srcEvent:t}))}});var ft={pointerdown:L,pointermove:U,pointerup:W,pointercancel:q,pointerout:q},dt={2:"touch",3:"pen",4:"mouse",5:"kinect"},vt="pointerdown",mt="pointermove pointerup pointercancel";function gt(){this.evEl=vt,this.evWin=mt,et.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}s.MSPointerEvent&&!s.PointerEvent&&(vt="MSPointerDown",mt="MSPointerMove MSPointerUp MSPointerCancel"),_(gt,et,{handler:function(t){var e=this.store,n=!1,i=t.type.toLowerCase().replace("ms",""),r=ft[i],s=dt[t.pointerType]||t.pointerType,o="touch"==s,a=O(e,t.pointerId,"pointerId");r&L&&(0===t.button||o)?a<0&&(e.push(t),a=e.length-1):r&(W|q)&&(n=!0),a<0||(e[a]=t,this.callback(this.manager,r,{pointers:e,changedPointers:[t],pointerType:s,srcEvent:t}),n&&e.splice(a,1))}});var yt={touchstart:L,touchmove:U,touchend:W,touchcancel:q},bt="touchstart",Tt="touchstart touchmove touchend touchcancel";function Et(){this.evTarget=bt,this.evWin=Tt,this.started=!1,et.apply(this,arguments)}_(Et,et,{handler:function(t){var e=yt[t.type];if(e===L&&(this.started=!0),this.started){var n=function(t,e){var n=R(t.touches),i=R(t.changedTouches);e&(W|q)&&(n=D(n.concat(i),"identifier",!0));return[n,i]}.call(this,t,e);e&(W|q)&&n[0].length-n[1].length==0&&(this.started=!1),this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:"touch",srcEvent:t})}}});var _t={touchstart:L,touchmove:U,touchend:W,touchcancel:q},St="touchstart touchmove touchend touchcancel";function Ct(){this.evTarget=St,this.targetIds={},et.apply(this,arguments)}_(Ct,et,{handler:function(t){var e=_t[t.type],n=function(t,e){var n=R(t.touches),i=this.targetIds;if(e&(L|U)&&1===n.length)return i[n[0].identifier]=!0,[n,n];var r,s,o=R(t.changedTouches),a=[],u=this.target;if(s=n.filter(function(t){return A(t.target,u)}),e===L)for(r=0;r-1&&i.splice(t,1)},xt)}}_(It,et,{handler:function(t,e,n){var i="touch"==n.pointerType,r="mouse"==n.pointerType;if(!(r&&n.sourceCapabilities&&n.sourceCapabilities.firesTouchEvents)){if(i)(function(t,e){t&L?(this.primaryTouch=e.changedPointers[0].identifier,At.call(this,e)):t&(W|q)&&At.call(this,e)}).call(this,e,n);else if(r&&function(t){for(var e=t.srcEvent.clientX,n=t.srcEvent.clientY,i=0;i-1&&this.requireFail.splice(e,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(t){return!!this.simultaneous[t.id]},emit:function(t){var e=this,n=this.state;function i(n){e.manager.emit(n,t)}n=Lt&&i(e.options.event+Ht(n))},tryEmit:function(t){if(this.canEmit())return this.emit(t);this.state=32},canEmit:function(){for(var t=0;te.threshold&&r&e.direction},attrTest:function(t){return $t.prototype.attrTest.call(this,t)&&(this.state&kt||!(this.state&kt)&&this.directionTest(t))},emit:function(t){this.pX=t.deltaX,this.pY=t.deltaY;var e=Bt(t.direction);e&&(t.additionalEvent=this.options.event+e),this._super.emit.call(this,t)}}),_(Zt,$t,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[Dt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.scale-1)>this.options.threshold||this.state&kt)},emit:function(t){if(1!==t.scale){var e=t.scale<1?"in":"out";t.additionalEvent=this.options.event+e}this._super.emit.call(this,t)}}),_(Jt,qt,{defaults:{event:"press",pointers:1,time:251,threshold:9},getTouchAction:function(){return[Ot]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distancee.time;if(this._input=t,!i||!n||t.eventType&(W|q)&&!r)this.reset();else if(t.eventType&L)this.reset(),this._timer=m(function(){this.state=Ut,this.tryEmit()},e.time,this);else if(t.eventType&W)return Ut;return 32},reset:function(){clearTimeout(this._timer)},emit:function(t){this.state===Ut&&(t&&t.eventType&W?this.manager.emit(this.options.event+"up",t):(this._input.timeStamp=v(),this.manager.emit(this.options.event,this._input)))}}),_(Kt,$t,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[Dt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.rotation)>this.options.threshold||this.state&kt)}}),_(Qt,$t,{defaults:{event:"swipe",threshold:10,velocity:.3,direction:Z|J,pointers:1},getTouchAction:function(){return Gt.prototype.getTouchAction.call(this)},attrTest:function(t){var e,n=this.options.direction;return n&(Z|J)?e=t.overallVelocity:n&Z?e=t.overallVelocityX:n&J&&(e=t.overallVelocityY),this._super.attrTest.call(this,t)&&n&t.offsetDirection&&t.distance>this.options.threshold&&t.maxPointers==this.options.pointers&&d(e)>this.options.velocity&&t.eventType&W},emit:function(t){var e=Bt(t.offsetDirection);e&&this.manager.emit(this.options.event+e,t),this.manager.emit(this.options.event,t)}}),_(te,qt,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:9,posThreshold:10},getTouchAction:function(){return[Rt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance 2 |
3 |

Vue Swipeable Bottom Sheet

4 | 5 | 6 | 7 | 8 |

Lorem Ipsum

9 |

What is Lorem Ipsum?

10 |

11 | Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 12 |

13 |

Where does it come from?

14 |

15 | Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. 16 |

17 |

Why do we use it?

18 |

19 | It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). 20 |

21 | 22 |
23 |
24 | 25 | 26 | 46 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | example 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Example from './example.vue'; 3 | 4 | new Vue({ 5 | el: '#app', 6 | render: h => h(Example) 7 | }); 8 | -------------------------------------------------------------------------------- /example/vue-swipeable-bottom-sheet.js: -------------------------------------------------------------------------------- 1 | module.exports=function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=4)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i,r=n(10),s=(i=r)&&i.__esModule?i:{default:i};e.default={data:function(){return{mc:null,y:0,startY:0,isMove:!1,state:"half",rect:{}}},mounted:function(){var t=this;console.log("init"),window.onresize=function(){t.rect=t.$refs.card.getBoundingClientRect()},this.rect=this.$refs.card.getBoundingClientRect(),this.mc=new s.default(this.$refs.pan),this.y=.8*this.rect.height,this.mc.get("pan").set({direction:s.default.DIRECTION_ALL}),this.mc.on("panup pandown",function(e){t.y=e.center.y-16}),this.mc.on("panstart",function(e){t.startY=e.center.y,t.isMove=!0}),this.mc.on("panend",function(e){switch(t.isMove=!1,t.state){case"half":t.startY-e.center.y>120&&(t.state="open"),t.startY-e.center.y<-50&&(t.state="close");break;case"open":t.startY-e.center.y<-120&&(t.state="half")}})},beforeDestroy:function(){this.mc.destroy(),window.onresize=null},methods:{calcY:function(){switch(this.state){case"close":return this.rect.height;case"open":return.13*this.rect.height;case"half":return.8*this.rect.height;default:return this.y}},setState:function(t){this.state=t}}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){for(var n=[],i={},r=0;rn.parts.length&&(i.parts.length=n.parts.length)}else{var s=[];for(r=0;r\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",r=s.console&&(s.console.warn||s.console.log);return r&&r.call(s.console,i,n),t.apply(this,arguments)}}c="function"!=typeof Object.assign?function(t){if(t===u||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n-1}function P(t){return t.trim().split(/\s+/g)}function O(t,e,n){if(t.indexOf&&!n)return t.indexOf(e);for(var i=0;in[e]}):i.sort()),i}function N(t,e){for(var n,i,r=e[0].toUpperCase()+e.slice(1),s=0;s1&&!n.firstMultiple?n.firstMultiple=it(e):1===r&&(n.firstMultiple=!1);var s=n.firstInput,o=n.firstMultiple,a=o?o.center:s.center,c=e.center=rt(i);e.timeStamp=v(),e.deltaTime=e.timeStamp-s.timeStamp,e.angle=ut(a,c),e.distance=at(a,c),function(t,e){var n=e.center,i=t.offsetDelta||{},r=t.prevDelta||{},s=t.prevInput||{};e.eventType!==L&&s.eventType!==W||(r=t.prevDelta={x:s.deltaX||0,y:s.deltaY||0},i=t.offsetDelta={x:n.x,y:n.y});e.deltaX=r.x+(n.x-i.x),e.deltaY=r.y+(n.y-i.y)}(n,e),e.offsetDirection=ot(e.deltaX,e.deltaY);var h=st(e.deltaTime,e.deltaX,e.deltaY);e.overallVelocityX=h.x,e.overallVelocityY=h.y,e.overallVelocity=d(h.x)>d(h.y)?h.x:h.y,e.scale=o?(l=o.pointers,p=i,at(p[0],p[1],tt)/at(l[0],l[1],tt)):1,e.rotation=o?function(t,e){return ut(e[1],e[0],tt)+ut(t[1],t[0],tt)}(o.pointers,i):0,e.maxPointers=n.prevInput?e.pointers.length>n.prevInput.maxPointers?e.pointers.length:n.prevInput.maxPointers:e.pointers.length,function(t,e){var n,i,r,s,o=t.lastInterval||e,a=e.timeStamp-o.timeStamp;if(e.eventType!=q&&(a>F||o.velocity===u)){var c=e.deltaX-o.deltaX,h=e.deltaY-o.deltaY,l=st(a,c,h);i=l.x,r=l.y,n=d(l.x)>d(l.y)?l.x:l.y,s=ot(c,h),t.lastInterval=e}else n=o.velocity,i=o.velocityX,r=o.velocityY,s=o.direction;e.velocity=n,e.velocityX=i,e.velocityY=r,e.direction=s}(n,e);var l,p;var f=t.element;A(e.srcEvent.target,f)&&(f=e.srcEvent.target);e.target=f}(t,n),t.emit("hammer.input",n),t.recognize(n),t.session.prevInput=n}function it(t){for(var e=[],n=0;n=d(e)?t<0?B:V:e<0?$:G}function at(t,e,n){n||(n=Q);var i=e[n[0]]-t[n[0]],r=e[n[1]]-t[n[1]];return Math.sqrt(i*i+r*r)}function ut(t,e,n){n||(n=Q);var i=e[n[0]]-t[n[0]],r=e[n[1]]-t[n[1]];return 180*Math.atan2(r,i)/Math.PI}et.prototype={handler:function(){},init:function(){this.evEl&&w(this.element,this.evEl,this.domHandler),this.evTarget&&w(this.target,this.evTarget,this.domHandler),this.evWin&&w(z(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&I(this.element,this.evEl,this.domHandler),this.evTarget&&I(this.target,this.evTarget,this.domHandler),this.evWin&&I(z(this.element),this.evWin,this.domHandler)}};var ct={mousedown:L,mousemove:U,mouseup:W},ht="mousedown",lt="mousemove mouseup";function pt(){this.evEl=ht,this.evWin=lt,this.pressed=!1,et.apply(this,arguments)}_(pt,et,{handler:function(t){var e=ct[t.type];e&L&&0===t.button&&(this.pressed=!0),e&U&&1!==t.which&&(e=W),this.pressed&&(e&W&&(this.pressed=!1),this.callback(this.manager,e,{pointers:[t],changedPointers:[t],pointerType:"mouse",srcEvent:t}))}});var ft={pointerdown:L,pointermove:U,pointerup:W,pointercancel:q,pointerout:q},dt={2:"touch",3:"pen",4:"mouse",5:"kinect"},vt="pointerdown",mt="pointermove pointerup pointercancel";function gt(){this.evEl=vt,this.evWin=mt,et.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}s.MSPointerEvent&&!s.PointerEvent&&(vt="MSPointerDown",mt="MSPointerMove MSPointerUp MSPointerCancel"),_(gt,et,{handler:function(t){var e=this.store,n=!1,i=t.type.toLowerCase().replace("ms",""),r=ft[i],s=dt[t.pointerType]||t.pointerType,o="touch"==s,a=O(e,t.pointerId,"pointerId");r&L&&(0===t.button||o)?a<0&&(e.push(t),a=e.length-1):r&(W|q)&&(n=!0),a<0||(e[a]=t,this.callback(this.manager,r,{pointers:e,changedPointers:[t],pointerType:s,srcEvent:t}),n&&e.splice(a,1))}});var yt={touchstart:L,touchmove:U,touchend:W,touchcancel:q},Tt="touchstart",bt="touchstart touchmove touchend touchcancel";function Et(){this.evTarget=Tt,this.evWin=bt,this.started=!1,et.apply(this,arguments)}_(Et,et,{handler:function(t){var e=yt[t.type];if(e===L&&(this.started=!0),this.started){var n=function(t,e){var n=R(t.touches),i=R(t.changedTouches);e&(W|q)&&(n=D(n.concat(i),"identifier",!0));return[n,i]}.call(this,t,e);e&(W|q)&&n[0].length-n[1].length==0&&(this.started=!1),this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:"touch",srcEvent:t})}}});var _t={touchstart:L,touchmove:U,touchend:W,touchcancel:q},St="touchstart touchmove touchend touchcancel";function xt(){this.evTarget=St,this.targetIds={},et.apply(this,arguments)}_(xt,et,{handler:function(t){var e=_t[t.type],n=function(t,e){var n=R(t.touches),i=this.targetIds;if(e&(L|U)&&1===n.length)return i[n[0].identifier]=!0,[n,n];var r,s,o=R(t.changedTouches),a=[],u=this.target;if(s=n.filter(function(t){return A(t.target,u)}),e===L)for(r=0;r-1&&i.splice(t,1)},Ct)}}_(It,et,{handler:function(t,e,n){var i="touch"==n.pointerType,r="mouse"==n.pointerType;if(!(r&&n.sourceCapabilities&&n.sourceCapabilities.firesTouchEvents)){if(i)(function(t,e){t&L?(this.primaryTouch=e.changedPointers[0].identifier,At.call(this,e)):t&(W|q)&&At.call(this,e)}).call(this,e,n);else if(r&&function(t){for(var e=t.srcEvent.clientX,n=t.srcEvent.clientY,i=0;i-1&&this.requireFail.splice(e,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(t){return!!this.simultaneous[t.id]},emit:function(t){var e=this,n=this.state;function i(n){e.manager.emit(n,t)}n=Lt&&i(e.options.event+Ht(n))},tryEmit:function(t){if(this.canEmit())return this.emit(t);this.state=32},canEmit:function(){for(var t=0;te.threshold&&r&e.direction},attrTest:function(t){return $t.prototype.attrTest.call(this,t)&&(this.state&kt||!(this.state&kt)&&this.directionTest(t))},emit:function(t){this.pX=t.deltaX,this.pY=t.deltaY;var e=Bt(t.direction);e&&(t.additionalEvent=this.options.event+e),this._super.emit.call(this,t)}}),_(Zt,$t,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[Dt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.scale-1)>this.options.threshold||this.state&kt)},emit:function(t){if(1!==t.scale){var e=t.scale<1?"in":"out";t.additionalEvent=this.options.event+e}this._super.emit.call(this,t)}}),_(Jt,qt,{defaults:{event:"press",pointers:1,time:251,threshold:9},getTouchAction:function(){return[Ot]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distancee.time;if(this._input=t,!i||!n||t.eventType&(W|q)&&!r)this.reset();else if(t.eventType&L)this.reset(),this._timer=m(function(){this.state=Ut,this.tryEmit()},e.time,this);else if(t.eventType&W)return Ut;return 32},reset:function(){clearTimeout(this._timer)},emit:function(t){this.state===Ut&&(t&&t.eventType&W?this.manager.emit(this.options.event+"up",t):(this._input.timeStamp=v(),this.manager.emit(this.options.event,this._input)))}}),_(Kt,$t,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[Dt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.rotation)>this.options.threshold||this.state&kt)}}),_(Qt,$t,{defaults:{event:"swipe",threshold:10,velocity:.3,direction:Z|J,pointers:1},getTouchAction:function(){return Gt.prototype.getTouchAction.call(this)},attrTest:function(t){var e,n=this.options.direction;return n&(Z|J)?e=t.overallVelocity:n&Z?e=t.overallVelocityX:n&J&&(e=t.overallVelocityY),this._super.attrTest.call(this,t)&&n&t.offsetDirection&&t.distance>this.options.threshold&&t.maxPointers==this.options.pointers&&d(e)>this.options.velocity&&t.eventType&W},emit:function(t){var e=Bt(t.offsetDirection);e&&this.manager.emit(this.options.event+e,t),this.manager.emit(this.options.event,t)}}),_(te,qt,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:9,posThreshold:10},getTouchAction:function(){return[Rt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance 2 |
3 |
4 |
10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 | 18 | 126 | 127 | 200 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import SwipeableBottomSheet from './components/SwipeableBottomSheet.vue' 2 | 3 | // Why don't you export default? 4 | // https://github.com/webpack/webpack/issues/3560 5 | export { SwipeableBottomSheet } 6 | -------------------------------------------------------------------------------- /vue-swipeable-bottom-sheet.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/axtutuu/vue-swipeable-bottom-sheet/80f1c50838f73ab6fcde64bfb5206617d0ffef3b/vue-swipeable-bottom-sheet.gif -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const { resolve } = require('path'); 2 | 3 | module.exports = { 4 | mode: 'production', 5 | entry: './src/', 6 | output: { 7 | library: 'SwipeableBottomSheet', 8 | libraryTarget: 'commonjs2', 9 | filename: 'vue-swipeable-bottom-sheet.js', 10 | path: resolve('dist'), 11 | }, 12 | module: { 13 | rules: [ 14 | { 15 | test: /\.vue$/, 16 | loader: 'vue-loader' 17 | }, 18 | { test: /\.js$/, 19 | loader: 'babel-loader' 20 | }, 21 | { 22 | test: /\.scss$/, 23 | loader: ['postcss-loader'] 24 | } 25 | ] 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /webpack.example.config.js: -------------------------------------------------------------------------------- 1 | const {resolve} = require('path'); 2 | const options = require('./webpack.config'); 3 | 4 | options.mode = 'development'; 5 | options.entry = './example/'; 6 | 7 | options.output.filename = 'example.js'; 8 | options.output.libraryTarget = 'var'; 9 | options.output.publicPath = "/dist"; 10 | 11 | options.devServer = { 12 | contentBase: [ 13 | resolve(__dirname, "example"), 14 | ], 15 | host: "0.0.0.0", 16 | publicPath: "/dist" 17 | }; 18 | 19 | module.exports = options; 20 | --------------------------------------------------------------------------------