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

@solid-primitives/mouse

Package Overview
Dependencies
Maintainers
3
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-primitives/mouse - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

dist/dev.cjs

2

dist/index.d.ts

@@ -66,3 +66,3 @@ import { Position, MaybeAccessor } from '@solid-primitives/utils';

*/
declare const getPositionToScreen: (pageX: number, pageY: number) => Position;
declare const getPositionToScreen: (_pageX: number, _pageY: number) => Position;

@@ -69,0 +69,0 @@ interface MousePositionOptions extends UseTouchOptions, FollowTouchOptions {

@@ -1,20 +0,120 @@

import {
createMousePosition,
createPositionToElement,
getPositionInElement,
getPositionToElement,
getPositionToScreen,
makeMouseInsideListener,
makeMousePositionListener,
useMousePosition
} from "./chunk-GJM65HMJ.js";
export {
createMousePosition,
createPositionToElement,
getPositionInElement,
getPositionToElement,
getPositionToScreen,
makeMouseInsideListener,
makeMousePositionListener,
useMousePosition
import { makeEventListenerStack } from '@solid-primitives/event-listener';
import { clamp, createStaticStore } from '@solid-primitives/utils';
import { createSharedRoot } from '@solid-primitives/rootless';
import { createEffect, createComputed, onMount } from 'solid-js';
// src/common.ts
var PASSIVE = { passive: true };
var DEFAULT_MOUSE_POSITION = {
x: 0,
y: 0,
isInside: false,
sourceType: null
};
var DEFAULT_RELATIVE_ELEMENT_POSITION = {
x: 0,
y: 0,
top: 0,
left: 0,
width: 0,
height: 0,
isInside: false
};
function makeMousePositionListener(target = window, callback, options = {}) {
const { touch = true, followTouch = true } = options;
const [listen, clear] = makeEventListenerStack(target, PASSIVE);
const handleMouse = (e) => callback({ x: e.pageX, y: e.pageY, sourceType: "mouse" });
listen("mousemove", handleMouse);
listen("dragover", handleMouse);
if (touch) {
const handleTouch = (e) => {
if (e.touches.length)
callback({ x: e.touches[0].clientX, y: e.touches[0].clientY, sourceType: "touch" });
};
listen("touchstart", handleTouch);
if (followTouch)
listen("touchmove", handleTouch);
}
return clear;
}
function makeMouseInsideListener(target = window, callback, options = {}) {
const { touch = true } = options;
const [listen, clear] = makeEventListenerStack(target, PASSIVE);
let mouseIn = false;
let touchIn = !touch;
function handleChange(isInside) {
this === "mouse" ? mouseIn = isInside : touchIn = isInside;
callback(mouseIn || touchIn);
}
listen("mouseover", handleChange.bind("mouse", true));
listen("mouseout", handleChange.bind("mouse", false));
listen("mousemove", handleChange.bind("mouse", true), { passive: true, once: true });
if (touch) {
listen("touchstart", handleChange.bind("touch", true));
listen("touchend", handleChange.bind("touch", false));
}
return clear;
}
var getPositionToElement = (pageX, pageY, el) => {
const bounds = el.getBoundingClientRect(), top = bounds.top + window.scrollY, left = bounds.left + window.scrollX, x = pageX - left, y = pageY - top, { width, height } = bounds;
return {
x,
y,
top,
left,
width,
height,
isInside: x >= 0 && y >= 0 && x <= width && y <= height
};
};
var getPositionInElement = (pageX, pageY, el) => {
const relative = getPositionToElement(pageX, pageY, el);
return {
...relative,
x: clamp(relative.x, 0, relative.width),
y: clamp(relative.y, 0, relative.height)
};
};
var getPositionToScreen = (pageX, pageY) => ({
x: pageX - window.scrollX,
y: pageY - window.screenY
});
function createMousePosition(target, options = {}) {
const [state, setState] = createStaticStore({
...DEFAULT_MOUSE_POSITION,
...options.initialValue
});
const attachListeners = (el) => {
makeMousePositionListener(el, setState, options);
makeMouseInsideListener(el, setState.bind(void 0, "isInside"), options);
};
if (typeof target !== "function")
attachListeners(target);
else
createEffect(() => attachListeners(target()));
return state;
}
var useMousePosition = /* @__PURE__ */ createSharedRoot(
createMousePosition.bind(void 0, void 0, void 0)
);
function createPositionToElement(element, pos, options = {}) {
const fallback = {
...DEFAULT_RELATIVE_ELEMENT_POSITION,
...options.initialValue
};
const calcState = (el) => {
const { x, y } = pos();
return getPositionToElement(x, y, el);
};
const getState = typeof element === "function" ? () => {
const el = element();
return el ? calcState(el) : fallback;
} : calcState.bind(void 0, element);
const [state, setState] = createStaticStore(fallback);
createComputed(() => setState(getState()));
if (typeof element === "function")
onMount(() => setState(getState()));
return state;
}
export { createMousePosition, createPositionToElement, getPositionInElement, getPositionToElement, getPositionToScreen, makeMouseInsideListener, makeMousePositionListener, useMousePosition };

@@ -1,25 +0,61 @@

import {
DEFAULT_MOUSE_POSITION,
DEFAULT_RELATIVE_ELEMENT_POSITION,
getPositionInElement,
getPositionToElement,
getPositionToScreen
} from "./chunk-GJM65HMJ.js";
import '@solid-primitives/event-listener';
import { noop } from '@solid-primitives/utils';
import { createSharedRoot } from '@solid-primitives/rootless';
import 'solid-js';
// src/server.ts
import { noop } from "@solid-primitives/utils";
var makeMousePositionListener = () => noop;
var makeMouseInsideListener = () => noop;
var createMousePosition = () => DEFAULT_MOUSE_POSITION;
var useMousePosition = () => DEFAULT_MOUSE_POSITION;
var createPositionToElement = () => DEFAULT_RELATIVE_ELEMENT_POSITION;
export {
createMousePosition,
createPositionToElement,
getPositionInElement,
getPositionToElement,
getPositionToScreen,
makeMouseInsideListener,
makeMousePositionListener,
useMousePosition
// src/common.ts
var DEFAULT_MOUSE_POSITION = {
x: 0,
y: 0,
isInside: false,
sourceType: null
};
var DEFAULT_RELATIVE_ELEMENT_POSITION = {
x: 0,
y: 0,
top: 0,
left: 0,
width: 0,
height: 0,
isInside: false
};
function makeMousePositionListener(target = window, callback, options = {}) {
{
return noop;
}
}
function makeMouseInsideListener(target = window, callback, options = {}) {
{
return noop;
}
}
var getPositionToElement = (pageX, pageY, el) => {
{
return DEFAULT_RELATIVE_ELEMENT_POSITION;
}
};
var getPositionInElement = (pageX, pageY, el) => {
{
return DEFAULT_RELATIVE_ELEMENT_POSITION;
}
};
var getPositionToScreen = (_pageX, _pageY) => DEFAULT_MOUSE_POSITION ;
function createMousePosition(target, options = {}) {
{
return DEFAULT_MOUSE_POSITION;
}
}
var useMousePosition = /* @__PURE__ */ createSharedRoot(
createMousePosition.bind(void 0, void 0, void 0)
);
function createPositionToElement(element, pos, options = {}) {
const fallback = {
...DEFAULT_RELATIVE_ELEMENT_POSITION,
...options.initialValue
};
{
return fallback;
}
}
export { createMousePosition, createPositionToElement, getPositionInElement, getPositionToElement, getPositionToScreen, makeMouseInsideListener, makeMousePositionListener, useMousePosition };
{
"name": "@solid-primitives/mouse",
"version": "2.0.2",
"version": "2.0.3",
"description": "A collection of Solid Primitives, that capture current mouse cursor position, and help to deal with common related usecases.",

@@ -25,5 +25,21 @@ "author": "Damian Tarnawski <gthetarnav@gmail.com>",

"main": "./dist/server.cjs",
"module": "./dist/index.js",
"module": "./dist/server.js",
"types": "./dist/index.d.ts",
"exports": {
"worker": {
"import": "./dist/server.js",
"require": "./dist/server.cjs"
},
"browser": {
"development": {
"import": "./dist/dev.js",
"require": "./dist/dev.cjs"
},
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"deno": {
"import": "./dist/server.js",
"require": "./dist/server.cjs"
},
"node": {

@@ -33,2 +49,6 @@ "import": "./dist/server.js",

},
"development": {
"import": "./dist/dev.js",
"require": "./dist/dev.cjs"
},
"import": "./dist/index.js",

@@ -48,30 +68,25 @@ "require": "./dist/index.cjs"

"devDependencies": {
"@solid-primitives/raf": "^2.1.2",
"jsdom": "^20.0.0",
"prettier": "^2.7.1",
"solid-js": "^1.5.1",
"solid-register": "^0.2.5",
"tslib": "^2.4.0",
"tsup": "^6.2.2",
"unocss": "^0.44.7",
"uvu": "^0.5.6",
"vite": "^3.0.7",
"vite-plugin-solid": "^2.3.0",
"watchlist": "^0.3.1"
"@solid-primitives/raf": "^2.1.3",
"solid-js": "^1.5.0"
},
"dependencies": {
"@solid-primitives/event-listener": "^2.2.3",
"@solid-primitives/rootless": "^1.2.0",
"@solid-primitives/utils": "^3.1.0"
},
"browser": {
"./dist/server.cjs": "./dist/index.cjs",
"./dist/server.js": "./dist/index.js"
},
"peerDependencies": {
"solid-js": "^1.3.1"
"solid-js": "^1.5.0"
},
"dependencies": {
"@solid-primitives/event-listener": "^2.2.2",
"@solid-primitives/rootless": "^1.1.3",
"@solid-primitives/utils": "^3.0.2"
},
"scripts": {
"start": "vite serve dev --host",
"dev": "npm run start",
"build": "tsup",
"test": "uvu -r solid-register",
"build": "jiti ../../scripts/build.ts --ssr --dev",
"test": "vitest -c ../../configs/vitest.config.ts",
"test:ssr": "pnpm run test --mode ssr",
"test:watch": "watchlist src test -- npm test"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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