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

kubefont

v0.1.1

Published

A React + Three.js component showing text and cubes

Downloads

1

Readme

Kubefont

Example image

A simple React component (written in Typescript) using Three.js to show a text and a number of random-positioned cubes. It exploits the normal hover event to move the camera while on desktop, and the gyroscope on mobile devices.

This is an experiment I made to test the integration between React and Three.js. It is not remotely tested enough or fit for a production environment.

Live example here!

Usage

Install the component using your favourite package manager:

# npm
npm install kubefont

# yarn
yarn add kubefont

Then use it as simple as:

import React from 'react';
import Kubefont from 'kubefont';

const App = () => (
  <div style={{ width: '100vw', height: '100vh' }}>
    <Kubefont text="Hello World" textFontUrl="/font.json" />
  </div>
);

The textFontUrl prop takes the path to your JSON font. This font must be served as a static file from your app. To create a JSON font you can use Facetype.js.

This component takes the same size of its parent container.

API

These are the props accepted by the Kubefont component:

| Prop name | Type | Description | Required | Default | | ----------------------------- | -------- | ----------------------------------------------------------------------- | -------- | ----------- | | text | String | The string to display | Yes | - | | textFontUrl | String | The path to the JSON font file (served statically from the webserver) | Yes | - | | textColor | String | The text color in HEX | No | "#dddddd" | | cameraDistance | Number | The text distance from the camera | No | 400 | | cubesColor | String | The cubes color in HEX | No | "#dddddd" | | particlesNumber | Number | The number of cubes to display | No | 50 | | scattering | Number | The cubes' scattering level | No | 1.5 | | backgroundColor | String | The environment background color in HEX | No | "#000000" | | useGyroscope | Boolean | Whether to use the gyroscope or the hover event | No | false | | GyroscopeRequestComponent | Function | Takes a function as a parameter and return a new React node (see below) | No | - |

Gyroscope

To use the gyroscope you HAVE to set this prop!

This component supports the DeviceOrientationEvent (W3C Documentation). In iOS13 you have to ask for permission to use the gyroscope and this permission must be granted "manually" (E.g. from a onClick event) from the user. To handle this particular case this component supports the GyroscopeRequestComponent prop, which takes a function as the only parameter and return a new React node. This new React node will be added over the Three.js canvas (you can even position it absolute) and triggering the passed function from there will try to obtain the permission.

import React from 'react';
import Kubefont from 'kubefont';

const App = () => (
  <div style={{ width: '100vw', height: '100vh' }}>
    <Kubefont
      text="Hello World"
      textFontUrl="/font.json"
      useGyroscope={true}
      GyroscopeRequestComponent={request => (
        <a onClick={request} style={{ color: '#ffffff' }}>
          Enable Gyroscope
        </a>
      )}
    />
  </div>
);