npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zouloux/virtual-mouse

v0.2.5

Published

Move a virtual mouse on your website to show features in video.

Downloads

1,297

Readme

Virtual Mouse

Move a virtual cursor on your website to show features in screencasts with a smooth cursor interaction.

It can be loaded on any website, without access to the source code.

Virtual Mouse also has its own studio to create scene from user actions.


How it works

It creates a virtual cursor on the screen, over your website. You can move it, scroll and click on elements to simulate user interactions. It can be useful to create screen captures of your website with a super smooth mouse move.

Hovers

Javascript cannot trigger CSS :hover pseudo state on DOM elements, It can work thanks to this lib which permit virtual mouse to trigger CSS :hover like the user's cursor.

It has a known issue when the :hover is inside a media query, it can't be triggered.

@media (min-width: 200px) {
	.test:hover {
		// Will not work
	}
}

To use it : await mouse.initHoversHack()

React

React has its own (and now totally useless) SyntheticEvents integration. Which prevents javascript based events to be converted to React elements. I found a hack to trigger handlers directly on React elements, it may not work on future react version. Simply give any React node and the code will find how to communicate SyntheticEvents on all React nodes.

To use it : mouse.initReactEvents( document.body.firstChild ) // any react node will do

Scrolls

Its compatible with vertical and horizontal scrolls. Horizontal scroll is not supported by the studio but can be used with the scroll and scrollTo commands.

Dependencies

It has gsap as only dependency. Loaded from esm.sh if directly in a browser environment.


Use it, even on websites you don't own

You can use it on websites loaded in chrome, without having to build anything.

Simply open the developer console and load this lib using :

const { createVirtualMousePlayer } = await import('https://esm.sh/@zouloux/virtual-mouse')

When loaded, you can start to use it

const mouse = createVirtualMousePlayer()
await mouse.delay(.2)
await mouse.move(400, 400)
await mouse.delay(.2)
await mouse.click()
await mouse.delay(.2)
await mouse.hide()
mouse.dispose()

Example

This and example you can copy and paste in any website's console.

const { createVirtualMousePlayer } = await import('https://esm.sh/@zouloux/virtual-mouse')
const mouse = createVirtualMousePlayer({
	// Hide scroll bar, even if moving, can break rendering
	hideScrollbar: true,
	// Hide user cursor
	hideCursor: true,
	// Print actions and parameters in console
	verbose: false,
	// Block user mouse wheel inputs
	preventMouseWheel: false,
	// Default animation parameters
	defaultAnimate: {
		duration: 1.0,
		ease: 'power4.inOut', // gsap easings
	},
  	// Apply custom style on cursor
	mouseStyle: {
		transform: "translate(-50%, -50%) scale(2)",
		border: "2px solid red",
	},
})

// Enable hovers hack
await mouse.initHoversHack()

// Enable React synthetic events compatibility
mouse.initReactEvents()

// Move mouse to an absolute position in the screen ( not the viewport )
await mouse.to(250, 250)

// Move mouse relatively to its current position
await mouse.move(-100, 0)

// Scroll relatively
await mouse.scroll(0, 200)

// Hide virtual mouse
await mouse.hide()

// Scroll to an absolute position
await mouse.scrollTo(0, 0)

// Show virtual mouse
await mouse.hide()

// Wait 1 second
await delay(1)

// Click on element under virtual mouse
await mouse.click()

// Scroll and move mouse in the same time
mouse.to(500, 500, { duration: 1 }) // no await
await mouse.scroll(0, 500, { duration: 1 })

// Dispose and go back to normal
mouse.dispose()

Viewport size

Because all positions are absolute to the viewport : When you create a virtual mouse scene, you have to save remember the actual viewport size.

The Studio will add a comment with the actual viewport size

// Url /virtual-mouse-demo.html
// Viewport: 1440x720
import { createVirtualMousePlayer } from "@zouloux/virtual-mouse"
const mouse = createVirtualMousePlayer({})
// ...

Virtual Mouse Studio

The studio can be helpful to record user actions and convert them to a Virtual Mouse Scene.

Paste this in the developer console on the website you want to animate :

const { createVirtualMouseStudio } = await import('https://esm.sh/@zouloux/virtual-mouse')
createVirtualMouseStudio()

Then, move your cursor on the website, and click around.

  • To register a scroll, use [CMD].
  • To finish your scene, hit [CMD] + [Escape] key on your keyboard.

The scene will be copied to your clipboard and ready to be pasted to play the scene.


NPM

Available on npm.

npm i @zouloux/virtual-mouse
import { createVirtualMousePlayer, createVirtualMouseStudio } from "@zouloux/virtual-mouse"
// ...

Test it

Clone
Build
  • npm run build
Start demo on port 8080
  • npm run demo

Next features

Move cursor to an element, centered into it
  • mouse.toElement( element:Element )
  • mouse.toSelector( selector:string )
Type on keyboard
await mouse.toElement('input')
await mouse.click()
await mouse.type("Hello world", 2) // speed
await mouse.key("enter")
Sounds

Sounds in WebAudio

  • Move sound
  • Click sound
  • Scroll sound
  • Type sound
  • Key sound
Studio

Create a tool to register clicks and moves and create code. It will have to smooth everything out. Maybe by hitting a specific key binding to create a new record.

Dependencies

Remove gsap as a dependency and make it a unique file.