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 🙏

© 2026 – Pkg Stats / Ryan Hefner

portyl

v1.0.1

Published

A flexible, framework-agnostic library for rendering any file to canvas directly in the browser.

Downloads

5

Readme

Portyl

Portyl is a lightweight, framework-agnostic TypeScript library for rendering files in the browser through a unified canvas-based viewer.

Live Example

View the Portyl demo on GitHub Pages

Features

  • View JPEG, PNG, GIF, WebP, SVG, BMP, TIFF
  • High-performance canvas rendering
  • Framework-agnostic & TypeScript support
  • Responsive and customizable
  • File info & error handling

Installation

npm install portyl

Quick Start

import { BrowserFileViewer } from 'portyl';

const viewer = new BrowserFileViewer();
const container = document.getElementById('viewer-container');

const fileInput = document.getElementById('file-input') as HTMLInputElement;
fileInput.addEventListener('change', async (e) => {
  const file = e.target.files?.[0];
  if (file) {
    await viewer.view(file, { container });
  }
});

CommonJS

const { BrowserFileViewer } = require('portyl');

Browser Script Tag

<script src="node_modules/portyl/dist/index.umd.js"></script>
<script>
  const viewer = new BrowserFileViewer.BrowserFileViewer();
</script>

API Reference

BrowserFileViewer

Constructor

new BrowserFileViewer()

Methods

canView(file: File): boolean

Check if a file can be viewed by the library.

view(file: File, options: ViewerOptions): Promise<ViewerResult>

View a file in the specified container.

Parameters:

  • file: The file to view
  • options: Viewer configuration options

Returns: Promise resolving to a ViewerResult

getSupportedTypes(): string[]

Get an array of supported MIME types.

getFileInfo(file: File): FileInfo

Extract file information from a File object.

formatFileSize(bytes: number): string

Format file size in human-readable format.

destroy(): void

Clean up resources and event listeners.

ViewerOptions

interface ViewerOptions {
  container: HTMLElement;    // Required: Container element to render in
  maxWidth?: number;         // Optional: Maximum width in pixels
  maxHeight?: number;        // Optional: Maximum height in pixels
  showFileInfo?: boolean;    // Optional: Show file information
  className?: string;        // Optional: Custom CSS class
}

ViewerResult

interface ViewerResult {
  success: boolean;          // Whether viewing was successful
  error?: string;           // Error message if unsuccessful
  element?: HTMLElement;    // The created viewer element
}

Examples

Basic Image Viewer

import { BrowserFileViewer } from 'portyl';

const viewer = new BrowserFileViewer();
const container = document.getElementById('image-container');

async function viewImage(file: File) {
  const result = await viewer.view(file, {
    container,
    showFileInfo: true
  });
  
  if (result.success) {
    console.log('Image loaded successfully');
  } else {
    console.error('Failed to load image:', result.error);
  }
}

Drag and Drop Support

const dropZone = document.getElementById('drop-zone');

dropZone.addEventListener('dragover', (e) => {
  e.preventDefault();
});

dropZone.addEventListener('drop', async (e) => {
  e.preventDefault();
  
  const files = Array.from(e.dataTransfer.files);
  const file = files[0];
  
  if (file && viewer.canView(file)) {
    await viewImage(file);
  } else {
    console.log('Unsupported file type');
  }
});

File Type Validation

const supportedTypes = viewer.getSupportedTypes();
console.log('Supported types:', supportedTypes);

// Check if specific file is supported
if (viewer.canView(file)) {
  // File can be viewed
} else {
  // Show error or alternative action
}

Styling

The library adds CSS classes that you can style:

.portyl {
  /* Main viewer container */
}

.portyl.image-viewer {
  /* Image viewer specific styles */
}

.portyl .file-info {
  /* File information panel */
}

Supported File Types

Images

  • JPEG (image/jpeg)
  • PNG (image/png)
  • GIF (image/gif)
  • WebP (image/webp)
  • SVG (image/svg+xml)
  • BMP (image/bmp)
  • TIFF (image/tiff, image/tif) - Single and multi-page support*

*Multi-page TIFF navigation is ready for enhancement with advanced TIFF parsing

Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

License

MIT License - see LICENSE file for details.