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

@jscadui/html-gizmo

v0.1.1

Published

JSCAD html gizmo controls

Downloads

5

Readme

Cube camera gizmo Web Component

| gizmo in action | Check the demo at: https://hrgdavor.github.io/jscadui/html-gizmo/ | | ---- | ---- |

Install

Add the gizmo dependency to your node project

npm i --save-dev @jscadui/html-gizmo

Use

You need to import the gizmo and register custom html element jscadui-gizmo.

import { Gizmo } from '@jscadui/html-gizmo'
Gizmo.define()

After that you can add the gizmo either in html

<div class="myContent">
    <jscadui-gizmo id="myGizmo"/>
</div>
<script>
        const gizmo = document.getElementById('myGizmo')
</script>

or you can add the gizmo in JS

<div class="myContent" id="myContent">
</div>
<script>
        const myContent = document.getElementById('myContent')
        const gizmo = new Gizmo()
        myContent.appendChild(gizmo)
</script>

NOTICE!: if you are only creating the gizmo vi JS you do not need to call Gizmo.define(), as it will be automaticall called during class static initialization

Styling

The gizmo uses shadow DOM to avoid issue with your own CSS leaking into it, but opens some variables that you can use to customize the look.

jscadui-gizmo{
  /** colored axes */
  --cube-z-color: #00f;
  --cube-x-color: #f00;
  --cube-y-color: #0f0;
 /* these are the default values for configurable variables. 
  Keep only those that you change */
  --cube-size: 100px;
  --cube-line-color: #fff;
  --cube-bg: #ccc;
  --cube-fg: #444;
  --cube-bg-hover: #eee9;
  --cube-fg-hover: #444;
  --cube-corner-radius: 5px;
}

To limit number of variables some things you can style further via ::part. In this example change the font style and font family:

jscadui-gizmo::part(face){
  font-size: 18px;
  font-family: Monospace;
}

Styling from JavaScript

If you have theme information in your JavaScript you can easily set any of these variables that way

gizmo.style.setProperty("--cube-line-color", #fff)

Example dark theme

dark theme

jscadui-gizmo{
  --cube-line-color: #666;
  --cube-bg: #222;
  --cube-fg: #aaa;
  --cube-bg-hover: #4449;
  --cube-fg-hover: #aaa;
}

you can also add axes colors, but lower intensity will look better for dark theme:

  --cube-z-color: #00a;
  --cube-x-color: #900;
  --cube-y-color: #090;

dark theme

Resize the gizmo

You can set the size other than 100px via css variable --cube-size or use the API method setSize(size)

gizmo.setSize(150)

Moving the gizmo (in sync with your camera)

To move the gizmo you can use the css variable --cube-transform or use the API method rotateXZ(rx,rz) . The api method will aside from the rotation also set the default scale of the cube that is 0.8, so if you call gizmo.rotateXZ(0.712704, 0.785398) you will get :

<jscadui-gizmo style="--cube-transform:scale3d(0.8,0.8,0.8) rotateX(0.712704rad) rotateZ(0.785398rad);">

If you know look-at position target and camera location position you can calculate the angles from that

const x = position[0] - target[0]
const y = position[1] - target[1]
const z = position[2] - target[2]
let len = Math.hypot(x, y, z)
let lenXY = Math.hypot(x, y)
let rz = lenXY == 0 ? 0 : acos(x / lenXY)
let rx = lenXY == 0 ? 0 : acos(lenXY / len)
if (z < 0) rx *= -1 // negative side is lost during sqr/sqrt hypot
if (y > 0) rz *= -1 // negative side is lost during sqr/sqrt hypot

gizmo.rotateXZ(rx,rz)

Change labels

You can provide your own text for the gizmo in the constructor or later on too (font size is not automatic, you need to change it to accomodate your labels ).

custom names

const gizmo = new Gizmo({T:'T',B:'B',N:'N',S:'S',E:'E',W:'W'})
// OR 
gizmo.setNames({T:'T',B:'B',N:'N',S:'S',E:'E',W:'W'})

Listen to camera location clicks

gizmo.oncam = e=>console.log('Camera location: ', e.cam)

With default translations the e.cam values will be:

  • T - TOP
  • B - BOTTOM
  • N - BACK
  • S - FRONT
  • W - LEFT
  • E - RIGHT

The world compass sides were chosen for short name because if we just take first letter of the translations on the right we have a conflict with BOTTOM and BACK.

For the sides and corners the e.cam returns values like: TS TSE TE SE BNW ...