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

@spoonconsulting/drawing

v2.0.5-beta16

Published

Convert position relative to a html element.

Downloads

2,402

Readme

Building

  1. Clone the repository
  2. npm install
  3. npm run build

This will generate drawing.min.js which is ready to be used in your web page.

Developing

Execute npm run start to launch the development server with livereload.

Usage

Creating a Drawing Experience

const drawingExperience = await DrawingExperience.create(background, {
  inputSvg: '<svg xmlns="http://www.w3.org/2000/svg">...</svg>
  contextMenu: false,
  actions: [
    {
      id: "save",
      icon: "M433.1 129.1l-83.9-83.9C342.3 38.32 327.1 32 316.1 32H64C28.65 32 0 60.65 0 96v320c0 35.35 28.65 64 64 64h320c35.35 0 64-28.65 64-64V163.9C448 152.9 441.7 137.7 433.1 129.1zM224 416c-35.34 0-64-28.66-64-64s28.66-64 64-64s64 28.66 64 64S259.3 416 224 416zM320 208C320 216.8 312.8 224 304 224h-224C71.16 224 64 216.8 64 208v-96C64 103.2 71.16 96 80 96h224C312.8 96 320 103.2 320 112V208z",
      label: "Save",
      action: () => {
        alert("DOWNLOAD ANNOTATION !!");
      },
    },
    {
      id: "close",
      icon: "m406.59 361.4c12.5 12.5 12.5 32.75 0 45.25-6.2 6.25-14.4 9.35-22.6 9.35s-16.38-3.125-22.62-9.375l-105.38-105.32-105.37 105.3c-6.25 6.3-14.44 9.4-22.63 9.4s-16.37-3.1-22.625-9.4c-12.5-12.5-12.5-32.75 0-45.25l105.4-105.4-105.4-105.35c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l105.38 105.45 105.4-105.4c12.5-12.5 32.75-12.5 45.25 0s12.5 32.75 0 45.25l-105.4 105.4z",
      label: "Close",
      action: () => {
        drawingExperience.destroy();
      },
    },
  ],
});

Exporting Foreground SVG

cosnt svg = drawingExperience.drawing.export();
console.log(svg);

Can also be acessed directly from DrawingExperience

cosnt svg = drawingExperience.export();
console.log(svg);

Using Marker Expperience

var markerExperience = drawingExperience.markerExperience;
console.log(markerExperience.export());
console.log(markerExperience.jsonToSVG(markerExperience.export()));

Can also be acessed directly from DrawingExperience

console.log(drawingExperience.export());
console.log(drawingExperience.jsonToSVG(drawingExperience.export()));

export() - Get SVG with updatedAt svgToJSON() - Convert SVG to JSON jsonToSVG() - Convert JSON to SVG

Options

inputSvg - Text SVG as Input. Can be used if you have a foreground svg to display on top of background (Optional)

container - Container to append Drawing (Optional)

sizeMenu - Shows size menu(True/False) (False by default) (Optional)

contextMenu - Shows context menu(True/False) (False by default) (Optional)

toolMenu - Shows tool menu(True/False) (True by default) (Optional)

colorMenu - Shows color menu(True/False) (False by default) (Optional)

undoRedo - Shows undo redo menu(True/False) (False by default) (Optional)

gridMenu - Shows grid menu(True/False) (False by default) (Optional)

commentsMenu - Show comment menu(True/False or Object(with readOnly)) (False by default) (Optional)

commentsMenu: false
// OR
commentsMenu: {
  readOnly: true
}

tools - Add tools to tool menu (Optional)

tools: [
  "path",
  "line",
  "circle",
  "rect",
  "marker",
  "double-arrow"
]
  • Add tool with options
tools: [
  "path",
  {
    type: "text",
    textStyleBold: true,
    textStyleUnderline: true,
    textStyleFontFamily: "monospace",
  },
  {
    name: "circle",
    type: "circle",
    colors: "#00ff00",
    lineStyle: "dashed",
    gridSize: [100, 100, 100, 100],
  },
  {
    name: "circleRed",
    type: "circle",
    colors: "#ff0000",
    size: 10,
  },
  {
    name: "highlighter",
    type: "path",
    colors: "#f1c40f60",
    size: 80,
    iconUrl: `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAY...`,
  },
]
  • Adding stickers
tools: [
  ...,
  "double-arrow",
  {
    "name": "sticker",
    "width": 426,
    "height": 426,
    "scale": 1,
    "dataUrl": `data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iM...`,
  },
  ...
]

edits - Add edit tools to tool menu (Optional)

edits: [
  "marker",
  "double-arrow"
]

colors - Add custom colors to color menu (Optional)

colors: [
  { name: "red", colors: "#e74c3c" },
  { name: "redFilled", colors: ["#e74c3c", "#e74c3c66"] },
  { name: "redOpaque", colors: ["#e74c3c", "#e74c3cff"] },
  { name: "redTransparent", colors: "#e74c3c20" },
  { name: "orange", colors: "#f39c12" },
  { name: "green", colors: "#2ecc71" },
  { name: "greenTransparent", colors: "#2ecc7120" },
  { name: "blue", colors: "#3498db" },
  { name: "blueTransparent", colors: "#3498db20" },
  { name: "purple", colors: "#8e44ad" },
  { name: "pink", colors: "#fc6ffc" },
  { name: "yellow", colors: "#f1c40f" },
  { name: "white", colors: "#ecf0f1" },
  { name: "black", colors: "#2c3e50" },
],

actions - Shows drawing actions (Optional)

actions: [
  {
    id: "save",
    icon: "", // path of icon
    label: "Save",
    action: () => {
      alert("DOWNLOAD ANNOTATION !!");
    },
  },
  {
    id: "download",
    icon: "", // path of icon
    label: "Close",
    action: () => {
      drawingExperience.destroy();
    },
  },
],

resizeElementsOnZoom - Enable resizing of elements when zooming on canvas (This is currently only done for markers) (True/False) (False by default)

promptText - Setup custom parameters and metrics for prompt text menu

promptText: {
  metrics: ["mm", "cm", "m"]
},

Documentation

See static/preview.html for an example usage.

More to come.