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

openseadragon-paperjs-overlay

v0.1.2

Published

An OpenSeadragon plugin that adds Paper.js canvas overlay capability.

Downloads

25

Readme

OpenSeadragonPaperjsOverlay

This fork of the OpenSeadragonPaperjsOverlay adds webpack and nodejs support along with a few improvements. You still MUST require OpenSeadragon before this module as OpenSeadragon loads on to the window object.

An OpenSeadragon plugin that adds Paper.js overlay capability.

Compatible with OpenSeadragon 2.0.0 or greater.

Experiencing disappearing paper objects on OSD viewport change? Use paperjs version 0.9.5 and manually trigger redraws instead.

License: The BSD 3-Clause License. The software was forked from [OpenseadragonPaperjsOverlay]https://github.com/eriksjolund/OpenSeadragonPaperjsOverlay), that also is licensed under the BSD 3-Clause License.

Modifications

  • Fixed compatiblity with node and webpack.
  • Fixed resizecanvas() errors when canvas is empty.
  • Implemented clear function on overlay.

Demo web page

See the online demo where some Paper.js circles are shown on top of an OpenSeadragon window. The circles can be dragged with the mouse.

Introduction

To use, include the openseadragon-paperjs-overlay.js file after openseadragon.js on your web page.

To add Paper.js overlay capability to your OpenSeadragon Viewer, call paperjsOverlay() on it.

    var viewer = new OpenSeadragon.Viewer(...);
    var overlay = viewer.paperjsOverlay();

This will return a new object with the following methods:

  • paperjsCanvas(): Returns Paper.js canvas that you can add elements to
  • resize(): If your viewer changes size, you'll need to resize the Paper.js overlay by calling this method.

##Add drag support Functionality for dragging Paper.js objects can be added by using OpenSeadragon.MouseTracker

    new OpenSeadragon.MouseTracker({
        element: viewer.canvas,
        pressHandler: press_handler,
        dragHandler: drag_handler,
        dragEndHandler: dragEnd_handler
    }).setTracking(true);

together with these callbacks

var hit_item = null;
var drag_handler = function(event) {
    if (hit_item) {
	var transformed_point1 = paper.view.viewToProject(new paper.Point(0,0));
        var transformed_point2 = paper.view.viewToProject(new paper.Point(event.delta.x, event.delta.y));
        hit_item.position = hit_item.position.add(transformed_point2.subtract(transformed_point1));
	window.viewer.setMouseNavEnabled(false);
	paper.view.draw();
    }
};
var dragEnd_handler = function(event) {
    if (hit_item) {
        window.viewer.setMouseNavEnabled(true);
    }
    hit_item = null;
};
var press_handler = function(event) {
    hit_item = null;
    var transformed_point = paper.view.viewToProject(new paper.Point(event.position.x, event.position.y));
    var hit_test_result = paper.project.hitTest(transformed_point);
    if (hit_test_result) {
        hit_item = hit_test_result.item;
    }
};

As a side-note: My first attempt to implement drag support failed. During that attempt I didn't use OpenSeadragon.MouseTracker but instead the mouse event callbacks inside Paper.js. I noticed, though, that the onMouseUp callback was never called and the onMouseDrag callback was called at the wrong time. The failed approach looked something like this:

var x_coord = 100;
var y_coord = 100;
var radius = 20;
var circle = new paper.Path.Circle(new paper.Point(x_coord, y_coord), radius);
circle.onMouseDown = function(event) {
  ...
}
circle.onMouseUp = function(event) {
  ...
}
circle.onMouseDrag = function(event) {
  ...
}

Note: The file package.json was modified to reflect the change from Fabric.js to Paper.js. But the file has not been tested.