lesca-click
Advanced tools
Comparing version 4.3.2 to 4.3.3
396
lib/index.js
@@ -1,206 +0,198 @@ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.setPreventDefault = exports.setEnabled = exports.remove = exports.install = exports["default"] = exports.dataset = exports.clear = exports.addPreventExcept = exports.add = void 0; | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _misc = require("./misc"); | ||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
var dataset = exports.dataset = {}; | ||
var mousePropertyDown = { | ||
x: 0, | ||
y: 0 | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
var mousePropertyMove = { | ||
x: mousePropertyDown.x, | ||
y: mousePropertyDown.y | ||
}; | ||
var moveOffsetProperty = { | ||
x: 0, | ||
y: 0 | ||
}; | ||
var extraEvent = { | ||
down: function down(e) {}, | ||
move: function move(e) {}, | ||
up: function up(e) {} | ||
}; | ||
var state = { | ||
device: '', | ||
isPress: false, | ||
deviation: 30, | ||
preventDefault: true, | ||
enabled: true | ||
}; | ||
var eventProperty = { | ||
passive: false, | ||
capture: false | ||
}; | ||
var exceptParentClassIDDataset = []; | ||
var rootElement = ''; | ||
var checkDataset = function checkDataset(e) { | ||
var target = e.target; | ||
if (target) { | ||
if (target instanceof Element) { | ||
["".concat(target.id, "_id"), "".concat(target.className, "_class")].forEach(function (name) { | ||
var _dataset$name, _dataset; | ||
(_dataset$name = (_dataset = dataset)[name]) === null || _dataset$name === void 0 || _dataset$name.call(_dataset, e); | ||
}); | ||
} | ||
} | ||
}; | ||
var eventTransform = function eventTransform() { | ||
var device = state.device; | ||
var d = (0, _misc.GET_DEVICE)(); | ||
if (!device) { | ||
state.device = d; | ||
addListener(d); | ||
} else if (device !== d) { | ||
state.device = d; | ||
removeListener(d); | ||
addListener(d); | ||
} | ||
}; | ||
var areWePreventDefault = function areWePreventDefault(e) { | ||
var preventDefault = state.preventDefault, | ||
enabled = state.enabled; | ||
if (!enabled) return; | ||
var root = (0, _misc.FIND_ROOT)(e); | ||
var isRoot = false; | ||
if (root) { | ||
if (rootElement) { | ||
if (rootElement.indexOf('.') >= 0) { | ||
isRoot = rootElement === ".".concat(root.className); | ||
} else if (rootElement.indexOf('#') >= 0) { | ||
isRoot = rootElement === "#".concat(root.id); | ||
} | ||
} | ||
} | ||
if (isRoot) { | ||
var hasClassID = (0, _misc.CHECK_PARENT_HAS_CLASS)(e, exceptParentClassIDDataset); | ||
if (preventDefault && !hasClassID && e.cancelable && !e.defaultPrevented) { | ||
if (e.target instanceof Element) { | ||
var localName = e.target.localName; | ||
if (localName != 'input' && localName != 'button' && localName != 'select') { | ||
e.preventDefault(); | ||
} | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
} | ||
}; | ||
define(["require", "exports", "./constants"], function (require, exports, constants_1) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setEnabled = exports.setPreventDefault = exports.addPreventExcept = exports.clear = exports.install = exports.remove = exports.add = exports.dataset = void 0; | ||
exports.dataset = {}; | ||
var mousePropertyDown = { x: 0, y: 0 }; | ||
var mousePropertyMove = { x: mousePropertyDown.x, y: mousePropertyDown.y }; | ||
var moveOffsetProperty = { x: 0, y: 0 }; | ||
var extraEvent = { | ||
down: function (e) { }, | ||
move: function (e) { }, | ||
up: function (e) { }, | ||
}; | ||
var state = { device: '', isPress: false, deviation: 30, preventDefault: true, enabled: true }; | ||
var eventProperty = { passive: false, capture: false }; | ||
var exceptParentClassIDDataset = []; | ||
var rootElement = ''; | ||
var checkDataset = function (e) { | ||
var target = e.target; | ||
if (target) { | ||
if (target instanceof Element) { | ||
["".concat(target.id, "_id"), "".concat(target.className, "_class")].forEach(function (name) { | ||
var _a; | ||
(_a = exports.dataset[name]) === null || _a === void 0 ? void 0 : _a.call(exports.dataset, e); | ||
}); | ||
} | ||
} | ||
}; | ||
var eventTransform = function () { | ||
var device = state.device; | ||
var d = (0, constants_1.GET_DEVICE)(); | ||
if (!device) { | ||
state.device = d; | ||
addListener(d); | ||
} | ||
else if (device !== d) { | ||
state.device = d; | ||
removeListener(d); | ||
addListener(d); | ||
} | ||
}; | ||
var areWePreventDefault = function (e) { | ||
var preventDefault = state.preventDefault, enabled = state.enabled; | ||
if (!enabled) | ||
return; | ||
var root = (0, constants_1.FIND_ROOT)(e); | ||
var isRoot = false; | ||
if (root) { | ||
if (rootElement) { | ||
if (rootElement.indexOf('.') >= 0) { | ||
isRoot = rootElement === ".".concat(root.className); | ||
} | ||
else if (rootElement.indexOf('#') >= 0) { | ||
isRoot = rootElement === "#".concat(root.id); | ||
} | ||
} | ||
} | ||
if (isRoot) { | ||
var hasClassID = (0, constants_1.CHECK_PARENT_HAS_CLASS)(e, exceptParentClassIDDataset); | ||
if (preventDefault && !hasClassID && e.cancelable && !e.defaultPrevented) { | ||
if (e.target instanceof Element) { | ||
var localName = e.target.localName; | ||
if (localName != 'input' && localName != 'button' && localName != 'select') { | ||
e.preventDefault(); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
var down = function (e) { | ||
state.isPress = true; | ||
var x = e instanceof MouseEvent ? e.clientX : e.targetTouches[0].clientX || false; | ||
var y = e instanceof MouseEvent ? e.clientY : e.targetTouches[0].clientY || false; | ||
if (!x || !y) | ||
return; | ||
areWePreventDefault(e); | ||
mousePropertyDown.x = x; | ||
mousePropertyDown.y = y; | ||
mousePropertyMove.x = x; | ||
mousePropertyMove.y = y; | ||
extraEvent.down(e); | ||
}; | ||
var move = function (e) { | ||
if (!state.isPress) | ||
return; | ||
var x = e instanceof MouseEvent ? e.clientX : e.targetTouches[0].clientX || false; | ||
var y = e instanceof MouseEvent ? e.clientY : e.targetTouches[0].clientY || false; | ||
if (!x || !y) | ||
return; | ||
areWePreventDefault(e); | ||
var dx = mousePropertyDown.x, dy = mousePropertyDown.y; | ||
moveOffsetProperty.x = x - dx; | ||
moveOffsetProperty.y = y - dy; | ||
mousePropertyMove.x = x; | ||
mousePropertyMove.y = y; | ||
extraEvent.move(__assign(__assign({}, e), { moveOffsetProperty: moveOffsetProperty })); | ||
}; | ||
var up = function (e) { | ||
state.isPress = false; | ||
var dx = mousePropertyDown.x, dy = mousePropertyDown.y; | ||
var mx = mousePropertyMove.x, my = mousePropertyMove.y; | ||
var deviation = state.deviation; | ||
var m = Math.sqrt(Math.pow((mx - dx), 2) + Math.pow((my - dy), 2)); | ||
if (m < deviation) | ||
checkDataset(e); | ||
extraEvent.up(e); | ||
}; | ||
var addListener = function (device) { | ||
if (device === 'mobile') { | ||
document.addEventListener('touchstart', down, eventProperty); | ||
document.addEventListener('touchmove', move, eventProperty); | ||
document.addEventListener('touchend', up); | ||
} | ||
else { | ||
document.addEventListener('mousedown', down); | ||
document.addEventListener('mousemove', move); | ||
document.addEventListener('mouseup', up); | ||
} | ||
}; | ||
var removeListener = function (device) { | ||
if (device === 'mobile') { | ||
document.removeEventListener('mousedown', down); | ||
document.removeEventListener('mousemove', move); | ||
document.removeEventListener('mouseup', up); | ||
} | ||
else { | ||
document.removeEventListener('touchstart', down); | ||
document.removeEventListener('touchmove', move); | ||
document.removeEventListener('touchend', up); | ||
} | ||
}; | ||
var add = function (query, callback) { | ||
if (!callback) | ||
return; | ||
var type = query.slice(0, 1) === '.' ? '_class' : '_id'; | ||
var name = query.slice(1); | ||
var key = name + type; | ||
exports.dataset[String(key)] = callback; | ||
}; | ||
exports.add = add; | ||
var remove = function (query) { | ||
var type = query.slice(0, 1) == '.' ? '_class' : '_id'; | ||
var name = query.slice(1); | ||
var key = name + type; | ||
delete exports.dataset[key]; | ||
}; | ||
exports.remove = remove; | ||
var install = function (app) { | ||
if (app === void 0) { app = '#app'; } | ||
rootElement = app; | ||
eventTransform(); | ||
window.addEventListener('resize', eventTransform); | ||
}; | ||
exports.install = install; | ||
var clear = function () { | ||
exports.dataset = {}; | ||
}; | ||
exports.clear = clear; | ||
var addPreventExcept = function (query) { | ||
if (Array.isArray(query)) { | ||
exceptParentClassIDDataset = __spreadArray([], query, true); | ||
} | ||
else | ||
exceptParentClassIDDataset.push(query); | ||
}; | ||
exports.addPreventExcept = addPreventExcept; | ||
var setPreventDefault = function (value) { | ||
state.preventDefault = value; | ||
}; | ||
exports.setPreventDefault = setPreventDefault; | ||
var setEnabled = function (value) { | ||
state.enabled = value; | ||
}; | ||
exports.setEnabled = setEnabled; | ||
var Click = { | ||
install: exports.install, | ||
dataset: exports.dataset, | ||
addPreventExcept: exports.addPreventExcept, | ||
setPreventDefault: exports.setPreventDefault, | ||
add: exports.add, | ||
clear: exports.clear, | ||
remove: exports.remove, | ||
setEnabled: exports.setEnabled, | ||
}; | ||
exports.default = Click; | ||
}); | ||
var down = function down(e) { | ||
state.isPress = true; | ||
var x = e instanceof MouseEvent ? e.clientX : e.targetTouches[0].clientX || false; | ||
var y = e instanceof MouseEvent ? e.clientY : e.targetTouches[0].clientY || false; | ||
if (!x || !y) return; | ||
areWePreventDefault(e); | ||
mousePropertyDown.x = x; | ||
mousePropertyDown.y = y; | ||
mousePropertyMove.x = x; | ||
mousePropertyMove.y = y; | ||
extraEvent.down(e); | ||
}; | ||
var move = function move(e) { | ||
if (!state.isPress) return; | ||
var x = e instanceof MouseEvent ? e.clientX : e.targetTouches[0].clientX || false; | ||
var y = e instanceof MouseEvent ? e.clientY : e.targetTouches[0].clientY || false; | ||
if (!x || !y) return; | ||
areWePreventDefault(e); | ||
var dx = mousePropertyDown.x, | ||
dy = mousePropertyDown.y; | ||
moveOffsetProperty.x = x - dx; | ||
moveOffsetProperty.y = y - dy; | ||
mousePropertyMove.x = x; | ||
mousePropertyMove.y = y; | ||
extraEvent.move(_objectSpread(_objectSpread({}, e), {}, { | ||
moveOffsetProperty: moveOffsetProperty | ||
})); | ||
}; | ||
var up = function up(e) { | ||
state.isPress = false; | ||
var dx = mousePropertyDown.x, | ||
dy = mousePropertyDown.y; | ||
var mx = mousePropertyMove.x, | ||
my = mousePropertyMove.y; | ||
var deviation = state.deviation; | ||
var m = Math.sqrt(Math.pow(mx - dx, 2) + Math.pow(my - dy, 2)); | ||
if (m < deviation) checkDataset(e); | ||
extraEvent.up(e); | ||
}; | ||
var addListener = function addListener(device) { | ||
if (device === 'mobile') { | ||
document.addEventListener('touchstart', down, eventProperty); | ||
document.addEventListener('touchmove', move, eventProperty); | ||
document.addEventListener('touchend', up); | ||
} else { | ||
document.addEventListener('mousedown', down); | ||
document.addEventListener('mousemove', move); | ||
document.addEventListener('mouseup', up); | ||
} | ||
}; | ||
var removeListener = function removeListener(device) { | ||
if (device === 'mobile') { | ||
document.removeEventListener('mousedown', down); | ||
document.removeEventListener('mousemove', move); | ||
document.removeEventListener('mouseup', up); | ||
} else { | ||
document.removeEventListener('touchstart', down); | ||
document.removeEventListener('touchmove', move); | ||
document.removeEventListener('touchend', up); | ||
} | ||
}; | ||
var add = exports.add = function add(query, callback) { | ||
if (!callback) return; | ||
var type = query.slice(0, 1) === '.' ? '_class' : '_id'; | ||
var name = query.slice(1); | ||
var key = name + type; | ||
dataset[String(key)] = callback; | ||
}; | ||
var remove = exports.remove = function remove(query) { | ||
var type = query.slice(0, 1) == '.' ? '_class' : '_id'; | ||
var name = query.slice(1); | ||
var key = name + type; | ||
delete dataset[key]; | ||
}; | ||
var install = exports.install = function install() { | ||
var app = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '#app'; | ||
rootElement = app; | ||
eventTransform(); | ||
window.addEventListener('resize', eventTransform); | ||
}; | ||
var clear = exports.clear = function clear() { | ||
exports.dataset = dataset = {}; | ||
}; | ||
var addPreventExcept = exports.addPreventExcept = function addPreventExcept(query) { | ||
if (Array.isArray(query)) { | ||
exceptParentClassIDDataset = (0, _toConsumableArray2["default"])(query); | ||
} else exceptParentClassIDDataset.push(query); | ||
}; | ||
var setPreventDefault = exports.setPreventDefault = function setPreventDefault(value) { | ||
state.preventDefault = value; | ||
}; | ||
var setEnabled = exports.setEnabled = function setEnabled(value) { | ||
state.enabled = value; | ||
}; | ||
var Click = { | ||
install: install, | ||
dataset: dataset, | ||
addPreventExcept: addPreventExcept, | ||
setPreventDefault: setPreventDefault, | ||
add: add, | ||
clear: clear, | ||
remove: remove, | ||
setEnabled: setEnabled | ||
}; | ||
var _default = exports["default"] = Click; |
{ | ||
"name": "lesca-click", | ||
"version": "4.3.2", | ||
"version": "4.3.3", | ||
"description": "use for prevent browser default behavior. usually used in web without scroll app.", | ||
@@ -24,43 +24,44 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/cli": "^7.19.3", | ||
"@babel/core": "^7.20.2", | ||
"@babel/cli": "^7.23.0", | ||
"@babel/core": "^7.23.2", | ||
"@babel/plugin-proposal-class-properties": "^7.18.6", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.20.2", | ||
"@babel/plugin-transform-modules-amd": "^7.19.6", | ||
"@babel/plugin-transform-runtime": "^7.19.6", | ||
"@babel/preset-env": "^7.20.2", | ||
"@babel/preset-react": "^7.18.6", | ||
"@babel/preset-typescript": "^7.18.6", | ||
"@emotion/react": "^11.10.5", | ||
"@emotion/styled": "^11.10.5", | ||
"@mui/icons-material": "^5.10.15", | ||
"@mui/material": "^5.10.15", | ||
"autoprefixer": "^10.4.13", | ||
"babel-loader": "^9.1.0", | ||
"concurrently": "^7.6.0", | ||
"css-loader": "^6.7.2", | ||
"@babel/plugin-transform-modules-amd": "^7.23.0", | ||
"@babel/plugin-transform-runtime": "^7.23.2", | ||
"@babel/preset-env": "^7.23.2", | ||
"@babel/preset-react": "^7.22.15", | ||
"@babel/preset-typescript": "^7.23.2", | ||
"@emotion/react": "^11.11.1", | ||
"@emotion/styled": "^11.11.0", | ||
"@mui/icons-material": "^5.14.13", | ||
"@mui/material": "^5.14.13", | ||
"autoprefixer": "^10.4.16", | ||
"babel-loader": "^9.1.3", | ||
"concurrently": "^8.2.1", | ||
"css-loader": "^6.8.1", | ||
"file-loader": "^6.2.0", | ||
"gh-pages": "^4.0.0", | ||
"html-react-parser": "^3.0.4", | ||
"html-webpack-plugin": "^5.5.0", | ||
"gh-pages": "^6.0.0", | ||
"html-react-parser": "^4.2.4", | ||
"html-webpack-plugin": "^5.5.3", | ||
"lesca-react-qrcode": "^1.1.0", | ||
"less": "^4.1.3", | ||
"less-loader": "^11.1.0", | ||
"less": "^4.2.0", | ||
"less-loader": "^11.1.3", | ||
"less-vars-to-js": "^1.3.0", | ||
"postcss": "^8.4.19", | ||
"postcss-loader": "^7.0.1", | ||
"postcss": "^8.4.31", | ||
"postcss-loader": "^7.3.3", | ||
"prismjs": "^1.29.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"style-loader": "^3.3.1", | ||
"ts-loader": "^9.4.1", | ||
"typescript": "^4.9.3", | ||
"webpack": "^5.75.0", | ||
"webpack-cli": "^5.0.0", | ||
"webpack-dev-server": "^4.11.1" | ||
"style-loader": "^3.3.3", | ||
"ts-loader": "^9.5.0", | ||
"typescript": "^5.2.2", | ||
"webpack": "^5.89.0", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^4.15.1" | ||
}, | ||
"author": "jamehsu1125 <jameshsu1125@gmail.com>", | ||
"dependencies": { | ||
"@babel/runtime": "^7.23.2", | ||
"mobile-detect": "^1.4.5" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { GET_DEVICE, CHECK_PARENT_HAS_CLASS, FIND_ROOT } from './constants'; | ||
import { GET_DEVICE, CHECK_PARENT_HAS_CLASS, FIND_ROOT } from './misc'; | ||
@@ -3,0 +3,0 @@ interface TriggerTouch extends TouchEvent { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
355179
2
1970
+ Added@babel/runtime@^7.23.2
+ Added@babel/runtime@7.26.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)