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

@hooked74/transform

v1.0.7

Published

The library parses the matrix transformation and modifies the element

Downloads

8

Readme

Build Status npm License codecov Module Size

Table of contents

Overview

This library will parse the matrix transformation of the element into the following properties: scale, translate, rotate, skew. Interface allows to change these properties and generate a matrix from them that will update the transform property. The library also parses and allows you to change the transform-origin property using a special interface.

Has the following constructor signature:

  new Transform(node, options?)

node [HTMLElement|SVGElement] element with which transformations will be performed. Required parameter.
options [Object] described in options. Optional parameter.

Install

npm install @hooked74/transform

Usage

Basic Usage

  import Transform from "@hooked/transform";

  // Use Transformation for HTMLElement
  const transform = new Transform(htmlElement);
  transform.origin = { x: 1, y: 0.5 };
  transform.scaleX = 2;

  // Use Transformation for SVGElement
  const transform = new Transform(svgElement);
  transform.originX = 0.5;
  transform.y = 100;

Inheritance

  import Transform from "@hooked/transform";

  class Entity extends Transform {
    constructor(node) {
      super(node);
    }
    // ...
  }

  const entity = new Entity(htmlElement);
  entity.origin = { x: 0.5, y: 0.5 };
  entity.angle = 10;

Options

Transform has the following options:

transformOrder

This option provides the ability to generate a matrix that will be composed of properties in a given order. By default this order:

  ["skew", "scale", "rotate", "translate"]

This order was selected empirically.

Available orders:

  [
    ["rotate", "scale", "translate", "skew"],
    ["rotate", "scale", "skew", "translate"],
    ["rotate", "skew", "scale", "translate"],
    ["rotate", "skew", "translate", "scale"],
    ["rotate", "translate", "skew", "scale"],
    ["rotate", "translate", "scale", "skew"],

    ["scale", "rotate", "translate", "skew"],
    ["scale", "rotate", "skew", "translate"],
    ["scale", "skew", "rotate", "translate"],
    ["scale", "skew", "translate", "rotate"],
    ["scale", "translate", "skew", "rotate"],
    ["scale", "translate", "rotate", "skew"],

    ["skew", "rotate", "scale", "translate"],
    ["skew", "rotate", "translate", "scale"],
    ["skew", "scale", "rotate", "translate"],
    ["skew", "scale", "translate", "rotate"],
    ["skew", "translate", "rotate", "scale"],
    ["skew", "translate", "scale", "rotate"],

    ["translate", "rotate", "scale", "skew"],
    ["translate", "rotate", "skew", "scale"],
    ["translate", "skew", "rotate", "scale"],
    ["translate", "skew", "scale", "rotate"],
    ["translate", "scale", "skew", "rotate"],
    ["translate", "scale", "rotate", "skew"]
  ]

API

Properties

width [float]

Allow to change the width of the element. Return the width of the element in pixels.

height [float]

Allow to change the height of the element. Return the height of the element in pixels.

styleTransform [string]

Allow to change the transformation property of the element. Return value in transformation matrix format.

styleTransformOrigin [string]

Allow to change transform-origin of the element. Return the value of transform-origin in the format Xpx Ypx.

rotate [{ angle: float }]

Change the state of rotate. The main property of the state is the angle of rotation. Return rotate state.

angle [float]

Element rotation angle. Limited to values from 0 to 360.

scale [{ x: float, y: float }]

Change the state of scale. The main properties of the state is the scale x and scale y. Return scale state.

scaleX [float]

Element scaling by X. Limited to values from 0 to 1 where 1 is 100%.

scaleY [float]

Element scaling by Y. Limited to values from 0 to 1 where 1 is 100%.

skew [{ x: float, y: float }]

Change the state of skew. The main properties of the state is the skew x and skew y. Return skew state.

skewX [float]

Element skewing by X. Value in degrees.

skewY [float]

Element skewing by Y. Value in degrees.

translate [{ x: float, y: float }]

Change the state of translate. The main properties of the state is the translate x and translate y. Return translate state.

x [float]

Element offset by X.

y [float]

Element offset by Y.

origin [{ x: float, y: float }]

Change the state of origin. The main properties of the state is the origin x and origin y. Return origin state.

originX [float]

Set the X coordinate relative to which the element will be transformed.

originY [float]

Set the Y coordinate relative to which the element will be transformed.

Methods

getStyleProperty(property: string): string

Get element style property.

setStyleProperty(property: string, value: string): void

Set element style property.

update(isOrigin: boolean): void

Force update transformation. It’s not worth using without need, since it is called automatically when the class properties change. If isOrigin is true then updates transform-origin otherwise transform.

Development

You can run some built-in commands:

npm run build

Builds the app for production. Your app is ready to be deployed.

npm run test:watch

Runs the test watcher in an interactive mode. By default, runs tests related to files changed since the last commit.