Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"presets": ["es2015"],
"plugins": ["transform-runtime"]
}
"presets": [
"@babel/preset-env"
],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"corejs": 3,
"proposals": true
}
]
]
}
241 changes: 240 additions & 1 deletion index.min.js
Original file line number Diff line number Diff line change
@@ -1 +1,240 @@
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.VueHammer=undefined;var _keys=require("babel-runtime/core-js/object/keys");var _keys2=_interopRequireDefault(_keys);var _hammerjs=require("hammerjs");var _hammerjs2=_interopRequireDefault(_hammerjs);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var gestures=["tap","pan","pinch","press","rotate","swipe"];var subGestures=["panstart","panend","panmove","pancancel","pinchstart","pinchmove","pinchend","pinchcancel","pinchin","pinchout","pressup","rotatestart","rotatemove","rotateend","rotatecancel"];var directions=["up","down","left","right","horizontal","vertical","all"];var VueHammer=exports.VueHammer={config:{},customEvents:{},install:function install(Vue){var _this=this;Vue.directive("hammer",{bind:function bind(el,binding){if(!el.hammer){el.hammer=new _hammerjs2.default.Manager(el)}var mc=el.hammer;var event=binding.arg;if(!event){console.warn("[vue-hammer] event type argument is required.")}el.__hammerConfig=el.__hammerConfig||{};el.__hammerConfig[event]={};var direction=binding.modifiers;el.__hammerConfig[event].direction=el.__hammerConfig[event].direction||[];if((0,_keys2.default)(direction).length){(0,_keys2.default)(direction).filter(function(keyName){return binding.modifiers[keyName]}).forEach(function(keyName){var elDirectionArray=el.__hammerConfig[event].direction;if(elDirectionArray.indexOf(keyName)===-1){elDirectionArray.push(String(keyName))}})}var recognizerType=void 0,recognizer=void 0;if(_this.customEvents[event]){var custom=_this.customEvents[event];recognizerType=custom.type;recognizer=new(_hammerjs2.default[_this.capitalize(recognizerType)])(custom);recognizer.recognizeWith(mc.recognizers);mc.add(recognizer)}else{recognizerType=gestures.find(function(gesture){return gesture===event});var subGesturesType=subGestures.find(function(gesture){return gesture===event});if(!recognizerType&&!subGesturesType){console.warn("[vue-hammer] invalid event type: "+event);return}if(subGesturesType&&el.__hammerConfig[subGesturesType].direction.length!==0){console.warn("[vue-hammer] "+subGesturesType+" should not have directions")}if(!recognizerType){return}if(recognizerType==="tap"||recognizerType==="pinch"||recognizerType==="press"||recognizerType==="rotate"){if(el.__hammerConfig[recognizerType].direction.length!==0){throw Error("[vue-hammer] "+recognizerType+" should not have directions")}}recognizer=mc.get(recognizerType);if(!recognizer){recognizer=new(_hammerjs2.default[_this.capitalize(recognizerType)]);recognizer.recognizeWith(mc.recognizers);mc.add(recognizer)}var globalOptions=_this.config[recognizerType];if(globalOptions){_this.guardDirections(globalOptions);recognizer.set(globalOptions)}var localOptions=el.hammerOptions&&el.hammerOptions[recognizerType];if(localOptions){_this.guardDirections(localOptions);recognizer.set(localOptions)}}},inserted:function inserted(el,binding){var mc=el.hammer;var event=binding.arg;var eventWithDir=subGestures.find(function(subGes){return subGes===event})?event:_this.buildEventWithDirections(event,el.__hammerConfig[event].direction);if(mc.handler){mc.off(eventWithDir,mc.handler)}if(typeof binding.value!=="function"){mc.handler=null;console.warn("[vue-hammer] invalid handler function for v-hammer: "+binding.arg)}else{mc.on(eventWithDir,mc.handler=binding.value)}},componentUpdated:function componentUpdated(el,binding){var mc=el.hammer;var event=binding.arg;var eventWithDir=subGestures.find(function(subGes){return subGes===event})?event:_this.buildEventWithDirections(event,el.__hammerConfig[event].direction);if(mc.handler){mc.off(eventWithDir,mc.handler)}if(typeof binding.value!=="function"){mc.handler=null;console.warn("[vue-hammer] invalid handler function for v-hammer: "+binding.arg)}else{mc.on(eventWithDir,mc.handler=binding.value)}},unbind:function unbind(el,binding){var mc=el.hammer;var event=binding.arg;var eventWithDir=subGestures.find(function(subGes){return subGes===event})?event:_this.buildEventWithDirections(event,el.__hammerConfig[event].direction);if(mc.handler){el.hammer.off(eventWithDir,mc.handler)}if(!(0,_keys2.default)(mc.handlers).length){el.hammer.destroy();el.hammer=null}}})},guardDirections:function guardDirections(options){var dir=options.direction;if(typeof dir==="string"){var hammerDirection="DIRECTION_"+dir.toUpperCase();if(directions.indexOf(dir)>-1&&_hammerjs2.default.hasOwnProperty(hammerDirection)){options.direction=_hammerjs2.default[hammerDirection]}else{console.warn("[vue-hammer] invalid direction: "+dir)}}},buildEventWithDirections:function buildEventWithDirections(eventName,directionArray){var f={};directionArray.forEach(function(dir){dir=dir.toLowerCase();if(dir==="horizontal"){f.left=1;f.right=1}else if(dir==="vertical"){f.up=1;f.down=1}else if(dir==="all"){f.left=1;f.right=1;f.up=1;f.down=1}else{f[dir]=1}});var _directionArray=(0,_keys2.default)(f);if(_directionArray.length===0){return eventName}var eventWithDirArray=_directionArray.map(function(dir){return eventName+dir});return eventWithDirArray.join(" ")},capitalize:function capitalize(str){return str.charAt(0).toUpperCase()+str.slice(1)}};
"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");

_Object$defineProperty(exports, "__esModule", {
value: true
});

exports.VueHammer = void 0;

var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));

var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));

var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));

var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));

var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));

var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));

var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));

var _hammerjs = _interopRequireDefault(require("hammerjs"));

var gestures = ['tap', 'pan', 'pinch', 'press', 'rotate', 'swipe'];
var subGestures = ['panstart', 'panend', 'panmove', 'pancancel', 'pinchstart', 'pinchmove', 'pinchend', 'pinchcancel', 'pinchin', 'pinchout', 'pressup', 'rotatestart', 'rotatemove', 'rotateend', 'rotatecancel'];
var directions = ['up', 'down', 'left', 'right', 'horizontal', 'vertical', 'all'];
var VueHammer = {
config: {},
customEvents: {},
install: function install(Vue) {
var _this = this;

Vue.directive('hammer', {
bind: function bind(el, binding) {
if (!el.hammer) {
el.hammer = new _hammerjs["default"].Manager(el);
}

var mc = el.hammer; // determine event type

var event = binding.arg;

if (!event) {
console.warn('[vue-hammer] event type argument is required.');
}

el.__hammerConfig = el.__hammerConfig || {};
el.__hammerConfig[event] = {};
var direction = binding.modifiers;
el.__hammerConfig[event].direction = el.__hammerConfig[event].direction || [];

if ((0, _keys["default"])(direction).length) {
var _context, _context2;

(0, _forEach["default"])(_context = (0, _filter["default"])(_context2 = (0, _keys["default"])(direction)).call(_context2, function (keyName) {
return binding.modifiers[keyName];
})).call(_context, function (keyName) {
var elDirectionArray = el.__hammerConfig[event].direction;

if ((0, _indexOf["default"])(elDirectionArray).call(elDirectionArray, keyName) === -1) {
elDirectionArray.push(String(keyName));
}
});
}

var recognizerType, recognizer;

if (_this.customEvents[event]) {
// custom event
var custom = _this.customEvents[event];
recognizerType = custom.type;
recognizer = new _hammerjs["default"][_this.capitalize(recognizerType)](custom);
recognizer.recognizeWith(mc.recognizers);
mc.add(recognizer);
} else {
// built-in event
recognizerType = (0, _find["default"])(gestures).call(gestures, function (gesture) {
return gesture === event;
});
var subGesturesType = (0, _find["default"])(subGestures).call(subGestures, function (gesture) {
return gesture === event;
});

if (!recognizerType && !subGesturesType) {
console.warn('[vue-hammer] invalid event type: ' + event);
return;
}

if (subGesturesType && el.__hammerConfig[subGesturesType].direction.length !== 0) {
console.warn('[vue-hammer] ' + subGesturesType + ' should not have directions');
}

if (!recognizerType) {
return;
}

if (recognizerType === 'tap' || recognizerType === 'pinch' || recognizerType === 'press' || recognizerType === 'rotate') {
if (el.__hammerConfig[recognizerType].direction.length !== 0) {
throw Error('[vue-hammer] ' + recognizerType + ' should not have directions');
}
}

recognizer = mc.get(recognizerType);

if (!recognizer) {
// add recognizer
recognizer = new _hammerjs["default"][_this.capitalize(recognizerType)](); // make sure multiple recognizers work together...

recognizer.recognizeWith(mc.recognizers);
mc.add(recognizer);
} // apply global options


var globalOptions = _this.config[recognizerType];

if (globalOptions) {
_this.guardDirections(globalOptions);

recognizer.set(globalOptions);
} // apply local options


var localOptions = el.hammerOptions && el.hammerOptions[recognizerType];

if (localOptions) {
_this.guardDirections(localOptions);

recognizer.set(localOptions);
}
}
},
inserted: function inserted(el, binding) {
var mc = el.hammer;
var event = binding.arg;
var eventWithDir = (0, _find["default"])(subGestures).call(subGestures, function (subGes) {
return subGes === event;
}) ? event : _this.buildEventWithDirections(event, el.__hammerConfig[event].direction);

if (mc.handler) {
mc.off(eventWithDir, mc.handler);
}

if (typeof binding.value !== 'function') {
mc.handler = null;
console.warn('[vue-hammer] invalid handler function for v-hammer: ' + binding.arg);
} else {
mc.on(eventWithDir, mc.handler = binding.value);
}
},
componentUpdated: function componentUpdated(el, binding) {
var mc = el.hammer;
var event = binding.arg;
var eventWithDir = (0, _find["default"])(subGestures).call(subGestures, function (subGes) {
return subGes === event;
}) ? event : _this.buildEventWithDirections(event, el.__hammerConfig[event].direction); // teardown old handler

if (mc.handler) {
mc.off(eventWithDir, mc.handler);
}

if (typeof binding.value !== 'function') {
mc.handler = null;
console.warn('[vue-hammer] invalid handler function for v-hammer: ' + binding.arg);
} else {
mc.on(eventWithDir, mc.handler = binding.value);
}
},
unbind: function unbind(el, binding) {
var mc = el.hammer;
var event = binding.arg;
var eventWithDir = (0, _find["default"])(subGestures).call(subGestures, function (subGes) {
return subGes === event;
}) ? event : _this.buildEventWithDirections(event, el.__hammerConfig[event].direction);

if (mc.handler) {
el.hammer.off(eventWithDir, mc.handler);
}

if (!(0, _keys["default"])(mc.handlers).length) {
el.hammer.destroy();
el.hammer = null;
}
}
});
},
guardDirections: function guardDirections(options) {
var dir = options.direction;

if (typeof dir === 'string') {
var hammerDirection = 'DIRECTION_' + dir.toUpperCase();

if ((0, _indexOf["default"])(directions).call(directions, dir) > -1 && _hammerjs["default"].hasOwnProperty(hammerDirection)) {
options.direction = _hammerjs["default"][hammerDirection];
} else {
console.warn('[vue-hammer] invalid direction: ' + dir);
}
}
},
buildEventWithDirections: function buildEventWithDirections(eventName, directionArray) {
var f = {};
(0, _forEach["default"])(directionArray).call(directionArray, function (dir) {
dir = dir.toLowerCase();

if (dir === 'horizontal') {
f.left = 1;
f.right = 1;
} else if (dir === 'vertical') {
f.up = 1;
f.down = 1;
} else if (dir === 'all') {
f.left = 1;
f.right = 1;
f.up = 1;
f.down = 1;
} else {
f[dir] = 1;
}
});

var _directionArray = (0, _keys["default"])(f);

if (_directionArray.length === 0) {
return eventName;
}

var eventWithDirArray = (0, _map["default"])(_directionArray).call(_directionArray, function (dir) {
return eventName + dir;
});
return eventWithDirArray.join(' ');
},
capitalize: function capitalize(str) {
return str.charAt(0).toUpperCase() + (0, _slice["default"])(str).call(str, 1);
}
};
exports.VueHammer = VueHammer;
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
"version": "2.1.2",
"author": "[email protected]",
"main": "index.min.js",
"engines": {
"node": ">=8"
},
"scripts": {
"build": "./node_modules/.bin/webpack --config webpack.config.js",
"prepub": "babel index.js --out-file index.min.js && uglifyjs index.min.js -o index.min.js"
"prepub": "babel index.js --out-file index.min.js"
},
"dependencies": {
"hammerjs": "^2.0.8",
"babel-runtime": "^6.26.0"
"@babel/runtime-corejs3": "^7.0.0",
"hammerjs": "^2.0.8"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-loader": "^8.0.0",
"css-loader": "^1.0.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"terser-webpack-plugin": "^4.0.0",
"vue": "^2.4.2",
"vue-loader": "^15.3.0",
"vue-style-loader": "^4.1.1",
Expand All @@ -40,4 +43,4 @@
"url": "https://github.com/bsdfzzzy/vue2-hammer/issues"
},
"homepage": "https://github.com/bsdfzzzy/vue2-hammer#readme"
}
}
5 changes: 3 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const TerserPlugin = require("terser-webpack-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const path = require('path')

Expand Down Expand Up @@ -36,8 +36,9 @@ module.exports = {
new VueLoaderPlugin()
],
optimization: {
minimize: true,
minimizer: [
new UglifyJsPlugin()
new TerserPlugin()
]
}
}