.attheme-preview
A JavaScript package for generating previews of .attheme's, created by @AlexStrNik & @SnejUgal.
Installing
$npm i attheme-preview
Example β
;;;;; const theme = `windowBackgroundWhite=-328966`; const preview = ; preview;preview; preview ;
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 β
;; ; ; ;
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