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

pointer3000

v1.0.6

Published

✨ A little utility that makes it easy to work with trig values calculated from the pointer's location relative to reference points

Downloads

7

Readme

Pointer3000

A simple little utility that makes it easy to work with values calculated from the pointer's location relative to one or multiple defined points. 🙋🏼

🍒 VISIT THE PROJECT (MINI DEMO) WEBSITE

Why?

I experiment a lot with interactive graphics and interaction in general, and have found that I often have to calculate this and that, particularly the distance and angle from (a) specific point(s). I decided to make this little utility so I can just plop it in and start trying things out. This is meant to be used in compositions with just regular DOM elements– the constraint of what can be done with just a 'regular' page I find to be a very welcome creative challenge.

While the output is very 'basic', I found that what can be done with them when used to manipulate things are endless. I hope you find this stirring your creativity and imagination. Lots of possibilities!

💅🏾 THE PROJECT SITE IS A MINI DEMO

More demos coming soon (mocking 3d, AppleTV rotating cards, etc)

How?

Simply call Pointer3000. This will create a global variable Pointer3k which contains points. Values are updated onMouseMove by default (see available settings below). Download the script or npm install pointer3000.

  // Initialize
  Pointer3k();

While the utility registers events on mousemove by default, you can use values via requestAnimationFrame so you don't have to register another mousemove listener to update the view.

If initialised without arguments it will simply register the center of the viewport as its one and only reference point. The default name of this auto-created point is pointA. If you do a console.log(Pointer3k('pointA') after initialisation, you will find that a point object contains the following data:

  // Sample data
  pointA: {
    cx: 640, // (centerX, reference)
    cy: 333, // (centerY, reference)
    deg: 43.42633594589745, // (degrees),
    dist: 426.8480408763756 // (distance from reference)
    rad: 0.7579325443330766, // (radians)
    x: 187 // (positionX),
    y: 177 // (positionY)
  }

fig

But you probably want to define specific points of reference, have multiple and even name them for convenience, so you'd want to initialize it like so:

  // We initialize with multiple points
  Pointer3k({
    points: {
      aNicelyNamedPoint: {
        cx: 200, // coordinate in pixels relative to viewport
        cy: 200
      },
      anotherPoint: {
        cx: 'center', // you can just pass 'center' for center of viewport
        cy: 'center' // you can just pass 'center' for center of viewport
      },
      goCrazy: {
        cx: 450
        cy: 620
      }
    },
    initialPos: { pageX: 200, pageY: 200 }, // (optional) registered 'mouse position' immediately on init. defaults to center
    listener: 'mousemove', // (optional, default: mousemove) event to listen to when updating values
    console: true // (optional) set to true if you want a console with values to be shown
  });

So how do you get a specific point's particular value? You just do: Pointer3k(pointName).propertyKey

  // Get a specific point's value
  var distanceFromReference = Pointer3k('aNicelyNamedPoint').dist;
  var angleInDegrees = Pointer3k('aNicelyNamedPoint').deg;
  // ... so on

If you want to pause updating values (basically just having an empty mousemove listener, performance gains or what have you) e.g. you only want values to be updated if a button has been clicked, then you use:

  // passing true or false as argument will enable/disable the listener
  Pointer3k(boolean);

  // Sample usage, toggle pointer update
  var updatePointer = false;

  button.addEventListener(function() {
    updatePointer = !updatePointer;

    Pointer3k(updatePointer);
  });

You can also access all points via Pointer3k.points.

Notes

  • If manipulating DOM elements, it is still best to use transforms as they are way more performant than manipulating e.g. width and height.
  • If you are going to be doing something relatively complex graphic wise then I think you should be looking at canvas or other drawing libraries. Those would be more performant, and have more math methods at your disposal. e.g. paperJS, raphael, svg.js
  • Having console: true or having inspector open (as you already know) will reduce performance as it will be updating values, recording timelines, highlighting updated DOM elements what have you.

Plans

  • More values e.g. adjacent, opposite and corresponding angles
  • point relative to a parent element
  • any suggestions?

Say Hi!

Please do. If you have any comments or suggestions, i'd love to hear them. This utility is completely free but if you have used it for something cool please do let me know, let me see what you've made! Drop me a line at [email protected] or via @the_ezekiel or Share this on Twitter!

P.S. Follow me on twitter!

License

This project is licensed under the MIT License - see the LICENSE.md file for details