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

grading-pyramid

v0.4.3

Published

> A simple 3D pyramid shape only use vanilla js & css.

Downloads

36

Readme

3D Grading Pyramid

A simple 3D pyramid shape only use vanilla js & css.

npm

Features

  • [ ] dynamic height & width
  • [x] customizable styles: color, text
  • [x] customizable number of grades
  • [x] customizable gap between grades
  • [x] animation speed & control
  • [x] some mouse interactions
  • [x] simple toolbar
  • [ ] more styles dynamically

Preview

https://clordweel.github.io/grading-pyramid/example

https://github.com/clordweel/grading-pyramid/assets/95267940/23736c82-da05-4752-b903-8e690de0450c

Usage

Install

# install by pnpm
pnpm add grading-pyramid

# install by npm
npm install grading-pyramid

ES Import

// import package
import GradingPyramid from "grading-pyramid";

// create a one grade pyramid
new GradingPyramid("#app");

CDN Import

<body>
  <!-- ... -->
  <div id="app"></div>

  <script src="https://unpkg.com/[email protected]/dist/index.umd.cjs"></script>
  <script>
    new GradingPyramid("#app");
  </script>
</body>

Example

import GradingPyramid from "grading-pyramid";

// create a pyramid have five grades and gap is 10px
const gp = new GradingPyramid(
  // target parent container selector
  // or document.querySelector("#app")
  "#app",
  // optional, type: GradingPyramidOptions
  {
    // should be unique, if need multiple pyramid, use this to distinguish
    scope: "another-one",

    height: 500,
    width: 400,

    gradesNumber: 5,
    gap: 10,

    // show toolbar
    toolbar: true,

    // @param data { level: number, side: string }
    // @param event MouseEvent
    onClick(data, event) {
      alert(`clicked: ${data.level}-${data.side}`); // such as: clicked: 2-front
    },
  }
);

// render custom grades
gp.render([
  {},
  {},
  {
    front: { text: "Front" },
    back: { text: "Back" },
    left: { text: "Left" },
    right: { text: "Right" },
  },
]);

Methods

// control animation
// @param updateState whether update state or not, default true
play(updateState?: boolean): void;
pause(updateState?: boolean): void;

// set grades data
setGrades(grades: Grade[]): void;

// set grades number
setGradesNumber(number: number): void;

// remove mounted pyramid's root element
prune(): void;

// mount pyramid's root element
mount(): void;

// get rendered pyramid's root element
render(): HTMLElement;

Typing

export type SideEventData = {
  // which one level grade is clicked
  level: number;

  // clicked side name
  side: Side;
};

type Store = {
  paused: boolean;
  speed: number;
  perspective: number;

  grades: Grade[];

  gradesNumber: number;
  height: number;
  width: number;
  gap: number;

  hideSides: Side[];

  toolbar: boolean;
};

type Side = "top" | "bottom" | "left" | "right" | "front" | "back";

export type Grade = Partial<
  Record<
    Side,
    {
      // text on the side
      text?: string;
      textColor?: string;

      // the side's color
      color?: string;

      // whether hide the side or not
      hide?: boolean;
    }
  >
>;

export type GradingPyramidOptions = {
  // style's working scope, for multiple instances
  scope?: string;

  // mount immediately, default true
  immediate?: boolean;

  // how many grades need, default 1
  gradesNumber?: number;

  // https://developer.mozilla.org/en-US/docs/Web/CSS/perspective
  perspective?: number;

  // whole height & width
  height?: number;
  width?: number;

  // gap of each grade
  gap?: number;

  // base grade style options
  baseGrade?: Grade;

  // auto play animation, default true
  running?: boolean;
  // animation speed: ms, default 6000
  speed?: number;

  // hide unnecessary sides
  hideSides?: Side[];

  // whether show toolbar or not, default false
  toolbar?: boolean;

  // handle click event with each grade
  onClick?: (data: SideEventData, event: MouseEvent) => void;
};

Build

# install dependencies
pnpm install

# for development
pnpm dev

# for build
pnpm build

Dependencies

nanostores: A tiny (298 bytes) state manager.