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

@placeos/svg-viewer

v0.5.4-dev

Published

This library is a Typescript for interacting with SVG files

Downloads

65

Readme

TypeScript SVG Viewer

This library is a Typescript for interacting with SVG files

Compilation

You can build the library from source after installing the dependencies with the command

npm run build

Usage

API docs can be found here

You can install the library with the npm command

npm install --save-dev @placeos/svg-viewer

Before using the SVG you'll need to add the global styles it will need to be initialised.

import { applyGlobalStyles } from '@placeos/svg-viewer';

applyGlobalStyles();

To create a new viewer use the create method. A DOM element and URL are required to create. Available options are the fields defined in the Viewer class.

import { createViewer } from '@placeos/svg-viewer';

const element = document.querySelector('#my-svg-container');
const url = `https://my.domain/path/to/file.svg`;

const view_id = createViewer({
    element,
    url
});

To update the state of the viewer you can use the update method. Available options are the fields defined in the Viewer class.

import { updateViewer } from '@placeos/svg-viewer';

const view_id = 'id-of-my-viewer';
const zoom = 2; // 200% zoom
const center = { x: .75, y: .25 }; // 200% zoom

updateViewer(view_id, {
    zoom,
    center
});

When you are finished with the viewer you can cleanup using the remove method.

import { removeViewer } from '@placeos/svg-viewer';

const view_id = 'id-of-my-viewer';

removeViewer(view_id);

You can change the styles of the SVG by passing them to the update method.

import { updateViewer } from '@placeos/svg-viewer';

const view_id = 'id-of-my-viewer';
const style = {
    'my-css-seletor': {
        'background-color': 'white'
    }
};

updateViewer(view_id, { styles });

You can also listen to user events on the SVG by passing them to the update method.

import { updateViewer } from '@placeos/svg-viewer';

const view_id = 'id-of-my-viewer';
const actions = [
    { id: 'my-element-id', action: 'click', callback: (e) => doSomething() }
];

updateViewer(view_id, { actions });

You can also focus on points and elements in the SVG by passing them to the update method.

import { updateViewer } from '@placeos/svg-viewer';

const view_id = 'id-of-my-viewer';
let focus = { 
    location: { x: .6, y: .2 } 
};

updateViewer(view_id, { focus });

focus = { 
    location: 'my-element-id',
    zoom_level: 1.5
};

updateViewer(view_id, { focus });

Finally, you can also render HTML element over the SVG by passing them to the update method.

import { updateViewer } from '@placeos/svg-viewer';

const view_id = 'id-of-my-viewer';
const element = document.querySelector('#my-element-id');
const features = [
    { location: 'svg-element-id', content: element }
];

updateViewer(view_id, { features });