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

react-projection-mapping

v1.98.1

Published

<a href="https://react-projection-mapping.vercel.app"> <img src="https://raw.githubusercontent.com/wirewirewirewire/react-projection-mapping/main/packages/docs/src/app/github-image.png" data-canonical-src="https://raw.githubusercontent.com/wirewirewirewir

Downloads

678

Readme

react-projection-mapping

Distort a container by using css 3D transforms for projection mapping and software keystone for react.

Demo application ℹ️

Features 🌟

  • Distort any container by using a rectangle
  • Centralized control and update of multiple containers
  • Split up containers into tiles

Usage 🖼️

Install via npm

npm install react-projection-mapping --save

Wrap your application with Projection.

import { Projection } from "react-projection-mapping";

<Projection data={data} onChange={update} editing={true} enabled={true}>
  Your containers
</Projection>;

Saving values 💾

Use the onChange prop to save the current values.

const update = ({ values, action }) => {
  if (action === "onEnd") {
    localStorage.setItem("projection", JSON.stringify(values));
  }
};

Get values 🔋

data allows you to load the values from an endpoint.

const [items, setItems] = useState();

useEffect(() => {
  const data = JSON.parse(localStorage.getItem("projection"));
  if (data) {
    setItems(data);
  }
}, []);

Layer

Each Element you want to distort should wrapped with Layer. Make sure to add an unique id.

import { Layer } from "react-projection-mapping";

<Layer id="total">Element</Layer>;

SplitLayer

Use the SplitLayer component to separate the Layer into multiple other layers. It renders the same component multiple times and uses clip-path to split it. It can take all settings from Layer.

import { Projection, SplitLayer } from "react-projection-mapping";

<Projection data={data} onChange={update} edit={true} enabled={true}>
  {[...Array(2)].map((y, index) => (
    <SplitLayer
      key={index}
      id={`tile-${index}`}
      clip={[0, index === 0 ? 50 : 0, 0, index === 0 ? 0 : 50]}
    >
      Content
    </SplitLayer>
  ))}
</Projection>;

useProjection() hook

Hook to get the current distort status or manually set it from any place inside Projection.

import { useProjection } from "react-projection-mapping";

const {
  data,
  edit,
  enabled,
  selectedCorner,
  selectedLayer,
  setSelectedCorner,
  setSelectedLayer,
} = useProjection();

Results from the useProjection() hook

{
  "data": {
    "id-of-layer": {
      "corners": [
        -326, 175, -212, 93, -184, 236, -73, 157
      ],
      "zIndex": 3
    }
  },
  "edit": true,
  "enabled": true,
  "selectedCorner": 0,
  "selectedLayer": "id-of-layer",
  "setSelectedCorner": () => { return number},
  "setSelectedLayer": () => {return "id-of-layer" }
}       

Keyboard control

While in editing mode you can use the keyboard shortcuts for fine adjustments.

  • Q move to next corner
  • W move to previous corner
  • A move z-index downwards
  • S move z-index upwards
  • Move corner
  • + Move corner 10px

Inspired by

  • https://github.com/alex3165/react-mapping
  • http://franklinta.com/2014/09/08/computing-css-matrix3d-transforms/
  • https://bl.ocks.org/mbostock/10571478
  • https://github.com/glowbox/maptasticjs