Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@daybrush/drag

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@daybrush/drag - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

2

declaration/index.d.ts

@@ -1,2 +0,2 @@

export * from "./drag";
export { default as drag } from "./drag";
export * from "./types";

@@ -9,1 +9,69 @@ /*

*/
function setDrag(el, options) {
var flag = false;
var startX = 0;
var startY = 0;
var datas = {};
var _a = options.container,
container = _a === void 0 ? el : _a,
dragstart = options.dragstart,
drag = options.drag,
dragend = options.dragend;
function getPosition(e) {
return e.touches && e.touches.length ? e.touches[0] : e;
}
function onDragStart(e) {
flag = true;
var _a = getPosition(e),
clientX = _a.clientX,
clientY = _a.clientY;
startX = clientX;
startY = clientY;
datas = {};
(dragstart && dragstart({
datas: datas
})) === false && (flag = false);
flag && e.preventDefault();
}
function onDrag(e) {
if (!flag) {
return;
}
var _a = getPosition(e),
clientX = _a.clientX,
clientY = _a.clientY;
drag && drag({
deltaX: clientX - startX,
deltaY: clientY - startY,
datas: datas
});
}
function onDragEnd() {
if (!flag) {
return;
}
flag = false;
dragend && dragend({
datas: datas
});
}
el.addEventListener("mousedown", onDragStart);
el.addEventListener("touchstart", onDragStart);
container.addEventListener("mousemove", onDrag);
container.addEventListener("touchmove", onDrag);
container.addEventListener("mouseup", onDragEnd);
container.addEventListener("mouseleave", onDragEnd);
container.addEventListener("touchend", onDragEnd);
}
export { setDrag as drag };

@@ -9,9 +9,77 @@ /*

*/
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
}(function () { 'use strict';
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.utils = {}));
}(this, function (exports) { 'use strict';
function setDrag(el, options) {
var flag = false;
var startX = 0;
var startY = 0;
var datas = {};
var _a = options.container,
container = _a === void 0 ? el : _a,
dragstart = options.dragstart,
drag = options.drag,
dragend = options.dragend;
function getPosition(e) {
return e.touches && e.touches.length ? e.touches[0] : e;
}
function onDragStart(e) {
flag = true;
var _a = getPosition(e),
clientX = _a.clientX,
clientY = _a.clientY;
startX = clientX;
startY = clientY;
datas = {};
(dragstart && dragstart({
datas: datas
})) === false && (flag = false);
flag && e.preventDefault();
}
function onDrag(e) {
if (!flag) {
return;
}
var _a = getPosition(e),
clientX = _a.clientX,
clientY = _a.clientY;
drag && drag({
deltaX: clientX - startX,
deltaY: clientY - startY,
datas: datas
});
}
function onDragEnd() {
if (!flag) {
return;
}
flag = false;
dragend && dragend({
datas: datas
});
}
el.addEventListener("mousedown", onDragStart);
el.addEventListener("touchstart", onDragStart);
container.addEventListener("mousemove", onDrag);
container.addEventListener("touchmove", onDrag);
container.addEventListener("mouseup", onDragEnd);
container.addEventListener("mouseleave", onDragEnd);
container.addEventListener("touchend", onDragEnd);
}
exports.drag = setDrag;
}));

@@ -9,2 +9,2 @@ /*

*/
!function(n){"function"==typeof define&&define.amd?define(n):n()}(function(){});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).utils={})}(this,function(e){"use strict";e.drag=function(e,t){var o=!1,i=0,a=0,s={},n=t.container,d=void 0===n?e:n,u=t.dragstart,r=t.drag,c=t.dragend;function f(e){return e.touches&&e.touches.length?e.touches[0]:e}function v(e){o=!0;var t=f(e),n=t.clientX,d=t.clientY;i=n,a=d,!(s={})===(u&&u({datas:s}))&&(o=!1),o&&e.preventDefault()}function l(e){if(o){var t=f(e),n=t.clientX,d=t.clientY;r&&r({deltaX:n-i,deltaY:d-a,datas:s})}}function h(){o&&(o=!1,c&&c({datas:s}))}e.addEventListener("mousedown",v),e.addEventListener("touchstart",v),d.addEventListener("mousemove",l),d.addEventListener("touchmove",l),d.addEventListener("mouseup",h),d.addEventListener("mouseleave",h),d.addEventListener("touchend",h)}});
{
"name": "@daybrush/drag",
"version": "0.0.1",
"version": "0.0.2",
"description": "add drag event",

@@ -5,0 +5,0 @@ "main": "./dist/drag.js",

export * from "./drag";
export {default as drag} from "./drag";
export * from "./types";
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc