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

@sketch-paper/core

v1.0.12

Published

A web component for creating drawing applications

Downloads

16

Readme

🖍️ Sketch Paper

Sketch Paper is a web-component for creating drawing applications. It's the software behind crayon.town.

Check out the live demo at sketchpaper.ink to see Sketch Paper in action.

Installation

npm i @sketch-paper/core

Usage

Sketch-paper is a web component, meaning you use it like this:

// import the library
import '@sketch-paper/core';
<!-- add it to your html -->
<sketch-paper ...></sketch-paper>
// once <sketch-paper/> is mounted, you must initialize the component.
const sketchPaperElement = getElementsByTagName('sketch-paper')[0];
sketchPaperElement.initialize(settings);

Simple Example

Sketch paper works with all frameworks. Here's an example showing it with Vue.js.

<script setup lang="ts">
  import { ref, onMounted } from 'vue';

  import { BrushKinds } from '@sketch-paper/core';

  const sketchPaperRef = ref();
  onMounted(() => {
    sketchPaperRef.value?.initialize({
      tileCountX: 0, // 0 means infinite
      tileCountY: 0, // 0 means infinite
      brushes: [BrushKinds.Crayon],
    });
  });
</script>

<template>
  <sketch-paper
    ref="sketchPaperRef"
    style="width: 100vw; height: 100vh"
    :brush-color="brush.color"
    :brush-kind="brush.kind"
    :brush-size="brush.size"
  >
  </sketch-paper>
</template>

Check out /examples for more.

Settings

// Settings are passed to the component via
sketchPaperElement.initialize(settings);

All settings are optional.

| field | Default | Description | | ---------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | brushes | [BrushKinds.Crayon] | An array of brushes to load. | | minZoom | 0.25 | How far out the camera can zoom. | | maxZoom | 10 | How far in the camera can zoom. | | startX | 0 | Camera starting position X. | | startY | 0 | Camera starting position Y. | | tileCountX | 1 | Number of tiles in the x direction. 0 means infinite* tiles | | tileCountY | 1 | Number of tiles in the y direction. 0 means infinite* tiles | | tileWidth | 2048 | The tile width in pixels. | | tileHeight | 2048 | The tile height in pixels. | | baseUrl | '' | Defines where Sketch Paper looks for tile images. Must be a public URL with the format${baseUrl}/${tileX}_${tileY}.png (tileX, tileY are the tile indices). Empty string means Sketch Paper will not try to load the tiles from remote images. | | baseColor | #C2BCB0 | Default color of the tiles. | | backgroundColor | #FFFFFF | Color outside of the drawing surface. | | allowUndo | true | Boolean for undo/redo functionality. undo = ctrl+z, redo = ctrl+y or ctrl+shift+z | | tileLoadingConcurrency | 3 | How many tiles can be loading at once, useful when you're using "baseUrl". | | maxTiles | 20 | How many tiles can be loaded in memory at once. | | loadingImg | '' | A URL pointing to an image to show while a tile is loading. The loading image doesn't have to be the same resolution as the tile. | | maxSegmentLength | 0 | How long a segment is a allowed to be. 0 means infinte. |

* Infinite actually means 2^32 pixels, the canvas will loop after that.

Attributes

Add attributes directly to the HTML directive.

<sketch-paper ... brush-color="#ff0000" brush-size="50"></sketch-paper>

<sketch-paper> uses the following attributes. Unlike the settings, these can be updated during runtime. | Attribute | Default | Description | | -------- | ------- | ------- | | brush-color | #000000 | Hex string, it can also include opacity value, eg: #00000000 | brush-kind | BrushKinds.None | None, Crayon, Marker, Paint | brush-size | 10 | The width and height in pixels of the brush tip | action-left-mouse | PointerActions.Draw | None, Draw, Pan | action-middle-mouse | PointerActions.Pan | None, Draw, Pan | action-right-mouse | PointerActions.Pan | None, Draw, Pan | action-wheel | WheelActions.Zoom | None, Zoom, Scroll

Events

Stay informed by listening for events.

<sketch-paper ... @sp-move="handleMove" />
function handleMove(event: SpMoveEvent) {
    console.log(event.detail) // { x: 123; y: 456 }
}

The <sketch-paper> component emits the following events:

| Event | Payload | Description | | ------------ | ------------------------ | -------------------------------------------------------------------------------------------------------------------- | | sp-draw | DrawSegment[] | Emitted each frame when a new segment is drawn. The payload includes a draw segment for each tile that was drawn on. | | sp-move | { x: number; y: number } | Emitted when the camera is translated. | | sp-zoom | { zoom: number } | Emitted when the camera is zoomed. | | sp-tile-load | index: [number, number] | Emitted when a tile image is loaded. |