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

attheme-preview

v2.0.1

Published

.attheme preview module

Downloads

6

Readme

.attheme-preview

A JavaScript package for generating previews of .attheme's, created by @AlexStrNik & @SnejUgal.

Installing

$npm i attheme-preview

Example β

import Attheme from "attheme-js";
import Preview from "attheme-preview";
import {
  randomWallpaperHandler,
  chatWallpaperHandler,
} from "attheme-preview/handlers";
import defaultTemplate from "attheme-preview/default-template";
import { writeFile } from "fs";

const theme = new Attheme(`
windowBackgroundWhite=-328966
`);

const preview = new Preview();

preview.setVariableHandler(Attheme.IMAGE_KEY, randomWallpaperHandler);
preview.addCustomHandler(chatWallpaperHandler);

preview.createPreview(theme, defaultTemplate)
  .then(async (previewBuffer) => {
      await fs.writeFile(`./preview.png`, previewBuffer);
      console.log(`Done!`);
  });

Fonts α

Not implented yet..

Params β

Params.sharp.density: number = 150

Density the preview should be rendered with.

Params.sharp.extension: "jpeg" | "png" | "webp" | "tiff" = "png"

The image type the rendered preview should be of.

Params.sharp.imageOptions: WebpOptions | JpegOptions | PngOptions | TiffOptions = {}

The rendering params that are passed to sharp directly.

JS / TS API β

import { JSDOM } from "jsdom";
import { JpegOptions, PngOptions, TiffOptions, WebpOptions } from "sharp";

const IMAGE_KEY = Symbol.for(`image`);

type RawTheme = Theme | Buffer | string;

type Template = JSDOM | string;

interface SharpParams {
  density?: number;
  extension?: "jpeg" | "png" | "webp" | "tiff";
  imageOptions?: WebpOptions | JpegOptions | PngOptions | TiffOptions;
}

interface Params {
  sharp?: SharpParams;
}

interface Color {
  red: number;
  green: number;
  blue: number;
  alpha: number;
}

interface Theme {
  [key: string]: Color;
  [IMAGE_KEY]?: string;
}

interface VariableHandler {
  (theme: Theme, params: Params): Color;
}

interface ClassHandler {
  (element: SVGElement, theme: Theme, params: Params): void;
}

interface CustomHandler {
  (preview: JSDOM, theme: Theme, params: Params): void;
}

new Preview()

Creates a new instance of Preview.

preview.setVariableHandler(variable: string | IMAGE_KEY, handler: VariableHandler)

Registers a new getter for variable. It isn't a usual property getter; it receives the theme and the passed params from preview.createPreview.

preview.setClassHandler(className: string, handler: ClassHandler)

Registers a new handler for elements with className class. After it's dome with coloring the template, attheme-preview calls registered handlers for each element of the className class. For example, if you register a handler for divider, and there are six elements with class="divider", then the handler is called six times, receiving another class="divider" element each time.

It is run after attheme-preview filled the preview template with colors, but before custom ones.

preview.addCustomHandler(handler: CunstomHandler)

Registers a new handler that's run after the class ones. It receives the whole colored template tree.

preview.createPreview(theme: RawTheme, template: Template, params?: Params): Promise<Buffer>

Generates a new preview, and returns a buffer of a .png image (by Default).

The params argument isn't used by this method, but it is passed to the handlers.

XML API α

<path class="className"/> or rect or circle

Sets the fill attribute to preview.getVariable(className, ...).

<image class="IMG" width="width" height="height"/> @deprecated

Sets the xlink:href attribute to preview.getVariable(Attheme.IMAGE_KEY, ...).

The handler require(`attheme-preview/handlers/chatWallpaperHandler.js`) must be added to make it work.

TODO

Remove deprecated code

e.g: xlink:href

Add custom fonts support

check puggo:cairo bindings

Add more default Handlers

e.g: gradient support, text support

RORO (“Receive object, return object” pattern)

implent RORO everewhere