New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@solid-primitives/mouse

Package Overview
Dependencies
Maintainers
2
Versions
29
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 1.0.0 to 1.0.1

23

dist/index.d.ts

@@ -1,3 +0,4 @@

import { Fn, MaybeAccessor } from '@solid-primitives/utils';
import { ClearListeners } from '@solid-primitives/event-listener';
import { Accessor } from 'solid-js';
import { MaybeAccessor, Fn } from '@solid-primitives/utils';

@@ -39,6 +40,3 @@ interface MouseOptions {

},
actions: {
start: Fn;
stop: Fn;
}
clear: ClearListeners
];

@@ -68,10 +66,4 @@

*/
declare function createMouseOnScreen(initialValue?: boolean): [onScreen: Accessor<boolean>, actions: {
stop: Fn;
start: Fn;
}];
declare function createMouseOnScreen(options?: MouseOnScreenOptions): [onScreen: Accessor<boolean>, actions: {
stop: Fn;
start: Fn;
}];
declare function createMouseOnScreen(initialValue?: boolean): [onScreen: Accessor<boolean>, clear: ClearListeners];
declare function createMouseOnScreen(options?: MouseOnScreenOptions): [onScreen: Accessor<boolean>, clear: ClearListeners];

@@ -97,6 +89,3 @@ /**

},
actions: {
stop: Fn;
start: Fn;
}
clear: ClearListeners
];

@@ -103,0 +92,0 @@

// src/mousePosition.ts
import { isClient } from "@solid-primitives/utils";
import { isClient, createCallbackStack } from "@solid-primitives/utils";
import { batch, createSignal } from "solid-js";
// src/common.ts
import { onCleanup } from "solid-js";
var addListener = (el, ev, cb, options = { passive: true }) => {
el.addEventListener(ev, cb, options);
let disposed = false;
const cleanup = () => {
if (disposed)
return;
disposed = true;
el.removeEventListener(ev, cb, options);
};
onCleanup(cleanup);
return cleanup;
};
import { createEventListener } from "@solid-primitives/event-listener";
var addListener = (el, ev, cb, options = { passive: true }) => createEventListener(el, ev, cb, options);

@@ -40,19 +29,15 @@ // src/mousePosition.ts

};
let cleanupList = [];
const toCleanup = createCallbackStack();
const start = () => {
stop();
if (isClient) {
cleanupList.push(addListener(window, "mousemove", mouseHandler));
cleanupList.push(addListener(window, "dragover", mouseHandler));
if (touch) {
cleanupList.push(addListener(window, "touchstart", touchHandler));
if (followTouch)
cleanupList.push(addListener(window, "touchmove", touchHandler));
}
if (!isClient)
return;
toCleanup.execute();
toCleanup.push(addListener(window, "mousemove", mouseHandler));
toCleanup.push(addListener(window, "dragover", mouseHandler));
if (touch) {
toCleanup.push(addListener(window, "touchstart", touchHandler));
if (followTouch)
toCleanup.push(addListener(window, "touchmove", touchHandler));
}
};
const stop = () => {
cleanupList.forEach((fn) => fn());
cleanupList = [];
};
start();

@@ -65,6 +50,3 @@ return [

},
{
start,
stop
}
toCleanup.execute
];

@@ -74,3 +56,3 @@ }

// src/mouseOnScreen.ts
import { isClient as isClient2 } from "@solid-primitives/utils";
import { isClient as isClient2, createCallbackStack as createCallbackStack2 } from "@solid-primitives/utils";
import { createMemo, createSignal as createSignal2 } from "solid-js";

@@ -91,25 +73,21 @@ function createMouseOnScreen(a = {}) {

const onScreen = createMemo(touch ? () => mouseOnScreen() || touchOnScreen() : () => mouseOnScreen());
let cleanupList = [];
const toCleanup = createCallbackStack2();
const start = () => {
stop();
if (isClient2) {
cleanupList.push(addListener(document, "mouseenter", () => setMouseOnScreen(true)), addListener(document, "mousemove", () => setMouseOnScreen(true), {
passive: true,
once: true
}), addListener(document, "mouseleave", () => setMouseOnScreen(false)));
if (touch)
cleanupList.push(addListener(window, "touchstart", () => setTouchOnScreen(true)), addListener(window, "touchend", () => setTouchOnScreen(false)));
}
if (!isClient2)
return;
toCleanup.execute();
toCleanup.push(addListener(document, "mouseenter", () => setMouseOnScreen(true)), addListener(document, "mousemove", () => setMouseOnScreen(true), {
passive: true,
once: true
}), addListener(document, "mouseleave", () => setMouseOnScreen(false)));
if (touch)
toCleanup.push(addListener(window, "touchstart", () => setTouchOnScreen(true)), addListener(window, "touchend", () => setTouchOnScreen(false)));
};
const stop = () => {
cleanupList.forEach((fn) => fn());
cleanupList = [];
};
start();
return [onScreen, { start, stop }];
return [onScreen, toCleanup.execute];
}
// src/mouseInElement.ts
import { access, isClient as isClient3 } from "@solid-primitives/utils";
import { createEffect, createSignal as createSignal3, onMount } from "solid-js";
import { access, createCallbackStack as createCallbackStack3 } from "@solid-primitives/utils";
import { createComputed, createSignal as createSignal3, onMount } from "solid-js";
function createMouseInElement(element, options = {}) {

@@ -135,26 +113,18 @@ const { touch = true, followTouch = true, initialValue = { x: 0, y: 0 } } = options;

};
let cleanupList = [];
const toCleanup = createCallbackStack3();
const start = (el = access(element)) => {
stop();
if (isClient3) {
cleanupList.push(addListener(el, "mouseover", () => setIsInside(true)), addListener(el, "mouseout", () => setIsInside(false)), addListener(el, "mousemove", (e) => handleMouseMove(e, el)));
if (touch) {
cleanupList.push(addListener(el, "touchstart", (e) => {
setIsInside(true);
handleTouchMove(e, el);
}), addListener(el, "touchend", () => setIsInside(false)));
if (followTouch)
cleanupList.push(addListener(el, "touchmove", (e) => handleTouchMove(e, el)));
}
toCleanup.execute();
if (!el)
return;
toCleanup.push(addListener(el, "mouseover", () => setIsInside(true)), addListener(el, "mouseout", () => setIsInside(false)), addListener(el, "mousemove", (e) => handleMouseMove(e, el)));
if (touch) {
toCleanup.push(addListener(el, "touchstart", (e) => {
setIsInside(true);
handleTouchMove(e, el);
}), addListener(el, "touchend", () => setIsInside(false)));
if (followTouch)
toCleanup.push(addListener(el, "touchmove", (e) => handleTouchMove(e, el)));
}
};
const stop = () => {
cleanupList.forEach((fn) => fn());
cleanupList = [];
};
const setup = () => createEffect(() => start(access(element)));
if (access(element))
setup();
else
onMount(setup);
access(element) ? createComputed(() => start()) : onMount(() => createComputed(() => start()));
return [

@@ -167,3 +137,3 @@ {

},
{ stop, start }
toCleanup.execute
];

@@ -173,4 +143,4 @@ }

// src/mouseToElement.ts
import { access as access2, isClient as isClient4, objectOmit } from "@solid-primitives/utils";
import { batch as batch2, createComputed, createMemo as createMemo2, createSignal as createSignal4, onMount as onMount2 } from "solid-js";
import { access as access2, objectOmit } from "@solid-primitives/utils";
import { batch as batch2, createComputed as createComputed2, createMemo as createMemo2, createSignal as createSignal4, onMount as onMount2 } from "solid-js";
function createMouseToElement(element, pos, options = {}) {

@@ -213,4 +183,3 @@ var _a, _b, _c, _d, _e, _f;

};
if (isClient4)
onMount2(() => createComputed(update));
access2(element) ? createComputed2(update) : onMount2(() => createComputed2(update));
return [

@@ -217,0 +186,0 @@ {

{
"name": "@solid-primitives/mouse",
"version": "1.0.0",
"version": "1.0.1",
"description": "A collection of Solid Primitives, that capture current mouse cursor position, and help to deal with common related usecases.",

@@ -46,9 +46,9 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",

"@solid-primitives/raf": "^1.0.5",
"jsdom": "^18.1.1",
"jsdom": "^19.0.0",
"prettier": "^2.4.1",
"solid-register": "^0.0.18",
"tslib": "^2.3.1",
"tsup": "^5.10.0",
"unocss": "^0.12.4",
"uvu": "^0.5.2",
"tsup": "^5.10.0",
"vite": "2.6.14",

@@ -61,4 +61,5 @@ "vite-plugin-solid": "2.1.2"

"dependencies": {
"@solid-primitives/utils": "^0.0.250"
"@solid-primitives/event-listener": "^1.3.8",
"@solid-primitives/utils": "0.0.260"
}
}

@@ -6,2 +6,3 @@ # @solid-primitives/mouse

[![size](https://img.shields.io/npm/v/@solid-primitives/mouse?style=for-the-badge)](https://www.npmjs.com/package/@solid-primitives/mouse)
[![stage](https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fraw.githubusercontent.com%2Fdavedbase%2Fsolid-primitives%2Fstage-badges%2Fassets%2Fbadges%2Fstage-2.json)](https://github.com/davedbase/solid-primitives#contribution-process)

@@ -15,2 +16,10 @@ A collection of primitives, capturing current mouse cursor position, and helping to deal with common usecases:

## Installation
```bash
npm install @solid-primitives/mouse
# or
yarn add @solid-primitives/mouse
```
## `createMousePosition`

@@ -23,4 +32,9 @@

```ts
const [{ x, y, sourceType }, { stop, start }] = createMousePosition({ touch: false });
import { createMousePosition } from "@solid-primitives/mouse";
const [{ x, y, sourceType }, clear] = createMousePosition({ touch: false });
// listening to touch events is enabled by default
// to clear all event listeners
clear();
```

@@ -37,6 +51,3 @@

},
actions: {
start: Fn;
stop: Fn;
}
clear: ClearListeners
];

@@ -74,2 +85,4 @@ interface MouseOptions {

```ts
import { createMouseToElement } from "@solid-primitives/mouse";
const [{ x, y, top, left, width, height, isInside }, manualUpdate] = createMouseToElement(

@@ -135,3 +148,5 @@ () => myRef

```ts
const [{ x, y, sourceType, isInside }, { stop, start }] = createMouseInElement(() => myRef, {
import { createMouseInElement } from "@solid-primitives/mouse";
const [{ x, y, sourceType, isInside }, clear] = createMouseInElement(() => myRef, {
followTouch: false

@@ -141,2 +156,5 @@ });

// the "touch", and "foullowTouch" settings are enabled by default
// to clear all event listeners
clear();
```

@@ -157,6 +175,3 @@

},
actions: {
stop: Fn;
start: Fn;
}
clear: ClearListeners
];

@@ -173,3 +188,8 @@ type MouseSourceType = "mouse" | "touch" | null;

```ts
const [isMouseOnScreen, { start, stop }] = createMouseOnScreen(true);
import { createMouseOnScreen } from "@solid-primitives/mouse";
const [isMouseOnScreen, clear] = createMouseOnScreen(true);
// to clear all event listeners
clear();
```

@@ -182,6 +202,6 @@

initialValue?: boolean
): [onScreen: Accessor<boolean>, actions: { stop: Fn; start: Fn }];
): [onScreen: Accessor<boolean>, clear: ClearListeners];
function createMouseOnScreen(
options?: MouseOnScreenOptions
): [onScreen: Accessor<boolean>, actions: { stop: Fn; start: Fn }];
): [onScreen: Accessor<boolean>, clear: ClearListeners];

@@ -213,4 +233,8 @@ interface MouseOnScreenOptions {

Eelease as a Stage-2 primitive.
Release as a Stage-2 primitive.
1.0.1
Updated util and event-listener dependencies.
</details>

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