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

@hhenrichsen/canvas-commons

v0.10.2

Published

Common utilities for working with Motion Canvas

Downloads

155

Readme

Canvas Commons

npm GitHub Static Badge

Warning ⚠️ This library is still under construction. Breaking changes are possible until I release version 1.0.0. Update versions with caution and only after reading the commit log. ⚠️

If you use this in your videos, I would appreciate credit via a link to this repo, or a mention by name. I would also love to see them; feel free to show me on the motion canvas discord (I'm @Hunter on there).

If you want to support the development of this and other libraries, feel free to donate on Ko-fi.

Preview

Code for this GIF can be found here

Using this library

From git

  1. Clone this repo.
  2. Run npm install <path to this repo> in your motion canvas project

From npm

  1. Run npm install @hhenrichsen/canvas-commons

Components

Scrollable

The Scrollable node is a custom component designed to allow for scrolling within a container. Its size represents the viewports size, and it can be scrolled to any position within its content.

Props

  • activeOpacity - the opacity of the scrollbars when they are active
  • handleFadeoutDuration - how long it takes for the scrollbars to fade out
  • handleFadeoutHang - how long the scrollbars stay visible after the last scroll event
  • handleInset - the amount to inset the scrollbar handles
  • handleProps - the props to pass to the scrollbar handles
  • handleWidth - the width of the scrollbar handles
  • inactiveOpacity - the opacity of the scrollbars when they are inactive
  • scrollOffset - the initial offset to use for the scrollable
  • scrollPadding - the amount of extra space to add when scrolling to preset positions
  • zoom - the zoom level of the scrollable

Example

import {Scrollable} from '@hhenrichsen/canvas-commons';
import {makeScene2D, Rect} from '@motion-canvas/2d';
import {createRef, waitFor} from '@motion-canvas/core';

export default makeScene2D(function* (view) {
  const scrollable = createRef<Scrollable>();
  const rect = createRef<Rect>();
  view.add(
    <Scrollable ref={scrollable}>
      <Rect fill={'blue'} radius={5} ref={rect} size={40}></Rect>
    </Scrollable>,
  );

  yield* scrollable().scrollTo([150, 150], 2);
  yield* scrollable().scrollToLeft(1);
  yield* scrollable().scrollToTop(1);
  yield* scrollable().scrollTo(0, 1);
  yield* waitFor(1);

  yield rect().fill('seagreen', 1);
  yield* rect().size(600, 2);
  yield* waitFor(1);

  yield* scrollable().scrollToBottom(1);
  yield* scrollable().scrollToRight(1);
  yield* scrollable().scrollBy(-100, 1);
  yield* waitFor(5);
});

Window

The Window node is custom component designed to look like a window on either a MacOS system or a Windows 98 system.

Props

  • bodyColor - the color of the body
  • headerColor - the color of the header
  • titleProps - the props to pass to the title's <Txt> node
  • title - the title of the window
  • windowStyle - the style of the window, either WindowStyle.Windows98 or WindowStyle.MacOS

Example

import {Window, Scrollable, WindowStyle} from '@hhenrichsen/canvas-commons';
import {makeScene2D, Rect} from '@motion-canvas/2d';
import {createRef, waitFor} from '@motion-canvas/core';

export default makeScene2D(function* (view) {
  const window = createRef<Window>();
  const rect = createRef<Rect>();
  view.add(
    <>
      <Window windowStyle={WindowStyle.Windows98} ref={window}>
        <Rect fill={'blue'} radius={5} ref={rect} size={40}></Rect>
      </Window>
    </>,
  );

  yield* window.open(view, 1);
  yield* waitFor(1);
});

FileTree

The FileTree node is a custom component designed to look like a file tree. It supports highlighting and selection of files and folders.

Props

  • assetColor - the color of the asset icon
  • fileColor - the color of the file icon
  • folderColor - the color of the folder icon
  • indentAmount - the amount to indent each level of the tree
  • labelColor - the color of the label
  • rowSize - the size of each row in the tree
  • structure - the structure of the file tree

Example

import {FileTree, FileType} from '@hhenrichsen/canvas-commons';
import {makeScene2D} from '@motion-canvas/2d';
import {createRef, waitFor} from '@motion-canvas/core';

export default makeScene2D(function* (view) {
  const fileStructure = createRef<FileTree>();
  view.add(
    <>
      <FileTree
        rowSize={50}
        ref={fileStructure}
        structure={{
          name: '/',
          type: FileType.Folder,
          children: [
            {
              name: 'src',
              type: FileType.Folder,
              children: [
                {
                  name: 'data',
                  id: 'db',
                  type: FileType.Folder,
                  children: [
                    {
                      name: 'queries',
                      type: FileType.Folder,
                      children: [
                        {
                          name: 'userQueries.ts',
                          type: FileType.File,
                        },
                        {
                          name: 'postQueries.ts',
                          type: FileType.File,
                        },
                      ],
                    },
                    {
                      name: 'connection.ts',
                      type: FileType.File,
                    },
                  ],
                },
                {
                  name: 'model',
                  id: 'model',
                  type: FileType.Folder,
                  children: [
                    {
                      name: 'user.ts',
                      type: FileType.File,
                    },
                    {
                      name: 'post.ts',
                      type: FileType.File,
                    },
                  ],
                },
                {
                  name: 'view',
                  id: 'view',
                  type: FileType.Folder,
                  children: [
                    {
                      name: 'home.component.ts',
                      type: FileType.File,
                    },
                    {
                      name: 'profile.component.ts',
                      type: FileType.File,
                    },
                  ],
                },
              ],
            },
          ],
        }}
      ></FileTree>
    </>,
  );

  yield* fileStructure().emphasize('db', 1);
});

Functional Components

I also have a collection of functional components that I use to automate using some of these components:

  • ImgWindow - a window that contains an image
  • Body - a Txt component that wraps text
  • Title - a Txt component that is bold and large
  • Em - a Txt component that is emphasized
  • Bold - a Txt component that is bold
  • ErrorBox - a Windows 98-style error message
  • Windows98Button - a button with a bevel, like in Windows 98