canvacord
Advanced tools
Comparing version 6.0.0-dev.f3ae696.1628209226 to 6.0.0
1475
dist/index.d.ts
@@ -1,136 +0,1391 @@ | ||
/// <reference types="node" /> | ||
import { Font as Font$1, SatoriOptions } from 'satori'; | ||
import * as stream from 'stream'; | ||
import { Readable } from 'stream'; | ||
import * as _napi_rs_canvas from '@napi-rs/canvas'; | ||
import { Image, Canvas, SKRSContext2D } from '@napi-rs/canvas'; | ||
import { Readable } from 'stream'; | ||
import { Canvas, AvifConfig, SKRSContext2D, Image } from '@napi-rs/canvas'; | ||
import { EncoderOptions } from '@skyra/gifenc'; | ||
import * as http from 'http'; | ||
import { PngEncodeOptions, AvifConfig as AvifConfig$1 } from '@napi-rs/image'; | ||
import * as React$1 from 'react'; | ||
import { CSSProperties } from 'react'; | ||
import { ClassNameValue } from 'tailwind-merge'; | ||
declare type CanvacordOutputFormat = "png" | "jpeg" | "webp"; | ||
declare type ImageSourceType = string | Buffer | Image; | ||
declare class Font { | ||
data: Buffer; | ||
alias: string; | ||
/** | ||
* Creates and registers a new Font instance for both canvas and builder apis. | ||
* @param data The font data | ||
* @param [alias] The font alias. If not provided, a random UUID will be used. | ||
* | ||
* const data = await readFile('path/to/font.ttf'); | ||
* const font = new Font(data, 'my-font'); | ||
*/ | ||
constructor(data: Buffer, alias?: string); | ||
/** | ||
* The alias for this font. | ||
*/ | ||
get name(): string; | ||
/** | ||
* Returns the font data that includes information such as the font name, weight, data, and style. | ||
*/ | ||
getData(): Font$1; | ||
/** | ||
* String representation of this font. | ||
*/ | ||
toString(): string; | ||
/** | ||
* JSON representation of this font. | ||
*/ | ||
toJSON(): Font$1; | ||
/** | ||
* Creates a new Font instance from a file. | ||
* @param path The path to the font file | ||
* @param [alias] The font alias. If not provided, a random UUID will be used. | ||
* | ||
* const font = await Font.fromFile('path/to/font.ttf', 'my-font'); | ||
*/ | ||
static fromFile(path: string, alias?: string): Promise<Font>; | ||
/** | ||
* Creates a new Font instance from a file synchronously. | ||
* @param path The path to the font file | ||
* @param [alias] The font alias. If not provided, a random UUID will be used. | ||
* | ||
* const font = Font.fromFileSync('path/to/font.ttf', 'my-font'); | ||
*/ | ||
static fromFileSync(path: string, alias?: string): Font; | ||
/** | ||
* Creates a new Font instance from a buffer. | ||
* @param buffer The buffer containing the font data | ||
* @param [alias] The font alias. If not provided, a random UUID will be used. | ||
* | ||
* const buffer = await readFile('path/to/font.ttf'); | ||
* const font = Font.fromBuffer(buffer, 'my-font'); | ||
*/ | ||
static fromBuffer(buffer: Buffer, alias?: string): Font; | ||
/** | ||
* Loads the default font bundled with this package. | ||
* | ||
* const font = Font.loadDefault(); | ||
*/ | ||
static loadDefault(): Font; | ||
} | ||
declare const FontFactory: Map<string, Font>; | ||
/** | ||
* Utility function to load images | ||
* @param source Image source | ||
* The image assets factory. | ||
*/ | ||
declare function loadImage(source: ImageSourceType, createSkImage?: true): Promise<Image>; | ||
declare function loadImage(source: ImageSourceType, createSkImage?: false): Promise<Buffer>; | ||
declare const ImageFactory: { | ||
AFFECT: string; | ||
BATSLAP: string; | ||
BEAUTIFUL: string; | ||
BED: string; | ||
BOTBADGE: string; | ||
CAPTCHA: string; | ||
CHANGEMYMIND: string; | ||
CLYDE: string; | ||
DELETE: string; | ||
DISCORD: string; | ||
DISTRACTED: string; | ||
DND: string; | ||
FACEPALM: string; | ||
RAINBOW: string; | ||
HITLER: string; | ||
IDLE: string; | ||
IMPOSTER: string; | ||
IMPOSTERWITH: string; | ||
JAIL: string; | ||
JOKEOVERHEAD: string; | ||
KICK: string; | ||
KISS: string; | ||
KO: string; | ||
OFFLINE: string; | ||
OHNO: string; | ||
ONLINE: string; | ||
OPINION: string; | ||
PHUB: string; | ||
PUNCH: string; | ||
RIP: string; | ||
SHIT: string; | ||
SNOWFLAKE: string; | ||
SPANK: string; | ||
TOBECONTINUED: string; | ||
TRASH: string; | ||
TRIGGERED: string; | ||
WANTED: string; | ||
WASTED: string; | ||
WELCOMEBG: string; | ||
YOUTUBE: string; | ||
}; | ||
declare class BaseCanvas { | ||
private _mimeType; | ||
loadImage: typeof loadImage; | ||
get mimeType(): CanvacordOutputFormat; | ||
set mimeType(value: CanvacordOutputFormat); | ||
makeCanvas(width: number, height: number): { | ||
canvas: Canvas; | ||
ctx: _napi_rs_canvas.SKRSContext2D; | ||
type EncodingFormat = "png" | "jpeg" | "webp" | "avif"; | ||
declare abstract class Encodable { | ||
/** | ||
* Returns the canvas instance by applying the steps. | ||
*/ | ||
abstract getFinalCanvas(): Promise<Canvas>; | ||
/** | ||
* Encodes the canvas to a buffer. | ||
*/ | ||
encode(): Promise<Buffer>; | ||
/** | ||
* Encodes the canvas to a png buffer. | ||
* @param format The encoding format - `png` | ||
*/ | ||
encode(format: "png"): Promise<Buffer>; | ||
/** | ||
* Encodes the canvas to a jpeg or webp buffer. | ||
* @param format The encoding format - `jpeg` or `webp` | ||
* @param [options] The quality of the image | ||
*/ | ||
encode(format: "jpeg" | "webp", options?: number): Promise<Buffer>; | ||
/** | ||
* Encodes the canvas to an avif buffer. | ||
* @param format The encoding format - `avif` | ||
* @param [options] The encoding options | ||
*/ | ||
encode(format: "avif", options?: AvifConfig): Promise<Buffer>; | ||
} | ||
interface ImageGenerationStep { | ||
/** | ||
* The image to render. | ||
*/ | ||
image?: ImgenStep[]; | ||
/** | ||
* The text to render. | ||
*/ | ||
text?: TextGenerationStep[]; | ||
/** | ||
* The custom steps to apply to the canvas. | ||
*/ | ||
custom?: CustomGenerationStep[]; | ||
/** | ||
* The function to call before processing this step. | ||
*/ | ||
preprocess?: (canvas: Canvas, ctx: SKRSContext2D, step: ImageGenerationStep) => Awaited<void>; | ||
/** | ||
* The function to call when processing this step. | ||
*/ | ||
process?: (canvas: Canvas, ctx: SKRSContext2D, step: ImageGenerationStep) => Awaited<void>; | ||
/** | ||
* The function to call after processing has finished. | ||
*/ | ||
postprocess?: (canvas: Canvas, ctx: SKRSContext2D, step: ImageGenerationStep) => Awaited<void>; | ||
} | ||
interface CustomGenerationStep { | ||
/** | ||
* The function to call when processing this step. | ||
*/ | ||
process: (canvas: Canvas, ctx: SKRSContext2D, step: ImageGenerationStep) => Awaited<void>; | ||
} | ||
interface ImgenStep { | ||
/** | ||
* The image to render. | ||
*/ | ||
source: TemplateImage; | ||
/** | ||
* The x position of the image. | ||
*/ | ||
x: number; | ||
/** | ||
* The y position of the image. | ||
*/ | ||
y: number; | ||
/** | ||
* The width of the image. | ||
*/ | ||
width?: number; | ||
/** | ||
* The height of the image. | ||
*/ | ||
height?: number; | ||
/** | ||
* The function to call before processing this step. | ||
*/ | ||
preprocess?: (canvas: Canvas, ctx: SKRSContext2D, source: ImgenStep) => Awaited<void>; | ||
/** | ||
* The function to call when processing this step. | ||
*/ | ||
process?: (canvas: Canvas, ctx: SKRSContext2D, source: ImgenStep) => Awaited<void>; | ||
/** | ||
* The function to call after processing has finished. | ||
*/ | ||
postprocess?: (canvas: Canvas, ctx: SKRSContext2D, source: ImgenStep) => Awaited<void>; | ||
} | ||
interface TextGenerationStep { | ||
/** | ||
* The text to render. | ||
*/ | ||
value: string; | ||
/** | ||
* The font of the text. | ||
*/ | ||
font: string; | ||
/** | ||
* The color of the text. | ||
*/ | ||
color: string; | ||
/** | ||
* Whether to stroke the text. | ||
*/ | ||
stroke?: boolean; | ||
/** | ||
* The x position of the text. | ||
*/ | ||
x: number; | ||
/** | ||
* The y position of the text. | ||
*/ | ||
y: number; | ||
/** | ||
* The maximum width of the text. | ||
*/ | ||
maxWidth?: number; | ||
/** | ||
* The line height of the text. | ||
*/ | ||
lineHeight?: number; | ||
/** | ||
* The line width of the text. | ||
*/ | ||
lineWidth?: number; | ||
/** | ||
* The alignment of the text. | ||
*/ | ||
align?: "left" | "center" | "right"; | ||
/** | ||
* The baseline of the text. | ||
*/ | ||
baseline?: "top" | "middle" | "bottom"; | ||
/** | ||
* The directionality of the text. | ||
*/ | ||
direction?: "inherit" | "ltr" | "rtl"; | ||
/** | ||
* The function to call before processing this step. | ||
*/ | ||
preprocess?: (canvas: Canvas, ctx: SKRSContext2D, text: TextGenerationStep) => Awaited<void>; | ||
/** | ||
* The function to call when processing this step. | ||
*/ | ||
process?: (canvas: Canvas, ctx: SKRSContext2D, text: TextGenerationStep) => Awaited<void>; | ||
/** | ||
* The function to call after processing has finished. | ||
*/ | ||
postprocess?: (canvas: Canvas, ctx: SKRSContext2D, text: TextGenerationStep) => Awaited<void>; | ||
} | ||
/** | ||
* The template to use for image generation. | ||
*/ | ||
interface IImageGenerationTemplate { | ||
/** | ||
* The width of the template. | ||
*/ | ||
width?: number; | ||
/** | ||
* The height of the template. | ||
*/ | ||
height?: number; | ||
/** | ||
* The steps to apply to the canvas. | ||
*/ | ||
steps: ImageGenerationStep[]; | ||
/** | ||
* The gif options. | ||
*/ | ||
gif?: EncoderOptions; | ||
} | ||
declare class ImageGenerationTemplate implements IImageGenerationTemplate { | ||
readonly width?: number | undefined; | ||
readonly height?: number | undefined; | ||
/** | ||
* The steps to apply to the canvas. | ||
*/ | ||
steps: ImageGenerationStep[]; | ||
/** | ||
* The gif options. | ||
*/ | ||
gif?: EncoderOptions; | ||
/** | ||
* Creates a new ImageGenerationTemplate instance from a template. | ||
* @param template The template to use | ||
* @returns The created template | ||
*/ | ||
static from(template: IImageGenerationTemplate): ImageGenerationTemplate; | ||
/** | ||
* Creates a new ImageGenerationTemplate instance. | ||
* @param width The width of the template | ||
* @param height The height of the template | ||
*/ | ||
constructor(width?: number | undefined, height?: number | undefined); | ||
/** | ||
* Sets the steps. This will overwrite any existing steps. | ||
* @param steps The steps to set | ||
*/ | ||
setSteps(steps: ImageGenerationStep[]): this; | ||
/** | ||
* Sets the gif options. | ||
* @param options The gif options | ||
*/ | ||
setGifOptions(options?: EncoderOptions): this; | ||
/** | ||
* Returns whether the template is a gif. | ||
*/ | ||
isGif(): boolean; | ||
/** | ||
* Adds a step to the template. | ||
* @param step The step to add | ||
*/ | ||
addStep(step: ImageGenerationStep): this; | ||
/** | ||
* Adds steps to the template. | ||
* @param steps The steps to add | ||
*/ | ||
addSteps(steps: ImageGenerationStep[]): this; | ||
/** | ||
* Clears the steps. | ||
*/ | ||
clearSteps(): this; | ||
/** | ||
* Returns whether the size is inferrable. | ||
*/ | ||
isInferrable(): boolean; | ||
/** | ||
* Returns the width of the template. | ||
*/ | ||
getWidth(): number | undefined; | ||
/** | ||
* Returns the height of the template. | ||
*/ | ||
getHeight(): number | undefined; | ||
/** | ||
* Returns the JSON representation of the template. | ||
*/ | ||
toJSON(): IImageGenerationTemplate; | ||
} | ||
declare class ImageGen extends Encodable { | ||
#private; | ||
template: ImageGenerationTemplate; | ||
private _canvas; | ||
/** | ||
* Creates a new ImageGen instance. | ||
* @param template The template to use | ||
*/ | ||
constructor(template: ImageGenerationTemplate); | ||
/** | ||
* Adds a step to the template. | ||
* @param step The step to add | ||
*/ | ||
addStep(step: ImageGenerationStep): this; | ||
/** | ||
* Adds steps to the template. | ||
* @param steps The steps to add | ||
*/ | ||
addSteps(steps: ImageGenerationStep[]): this; | ||
/** | ||
* Sets the gif options. | ||
* @param options The gif options | ||
*/ | ||
setGifOptions(options?: EncoderOptions): this; | ||
/** | ||
* Returns whether the template is a gif. | ||
*/ | ||
isGif(): boolean; | ||
/** | ||
* Generates a readable stream containing GIF data by applying the steps. | ||
*/ | ||
generateGif(): Promise<stream.Readable>; | ||
/** | ||
* Renders the image by applying the steps. | ||
*/ | ||
render(): Promise<this>; | ||
/** | ||
* Returns the canvas instance by applying the steps. | ||
*/ | ||
getFinalCanvas(): Promise<Canvas>; | ||
} | ||
/** | ||
* Creates a new image generator. | ||
* @param template The template to use | ||
*/ | ||
declare function createImageGenerator(template: ImageGenerationTemplate): ImageGen; | ||
/** | ||
* The element initialization options. | ||
*/ | ||
type ElementInit = { | ||
type: string; | ||
props: Record<string, unknown>; | ||
key?: React$1.Key | null; | ||
children?: any; | ||
}; | ||
/** | ||
* The JSX element. | ||
*/ | ||
declare class Element { | ||
/** | ||
* The type of the element. | ||
*/ | ||
type: string; | ||
/** | ||
* The props of the element. | ||
*/ | ||
props: Record<string, unknown>; | ||
/** | ||
* The key of the element. | ||
*/ | ||
key: React$1.Key | null; | ||
/** | ||
* The children of the element. | ||
*/ | ||
children?: any; | ||
/** | ||
* Creates a new JSX element. | ||
* @param _init The initialization options | ||
*/ | ||
constructor(_init: ElementInit); | ||
} | ||
/** | ||
* The JSX factory for canvacord jsx. | ||
*/ | ||
declare const JSX$1: { | ||
/** | ||
* The JSX element instance. | ||
*/ | ||
Element: typeof Element; | ||
/** | ||
* Creates a new JSX element. | ||
* @param type The type of the element | ||
* @param props The props of the element | ||
* @param children The children of the element | ||
* @returns The created element | ||
*/ | ||
createElement(type: string | Element, props: Record<string, unknown>, ...children: Element[]): Element; | ||
/** | ||
* Creates a new JSX fragment. | ||
* @param children The children of the fragment | ||
*/ | ||
Fragment({ children }: { | ||
children: Element[] | string; | ||
}): Element; | ||
}; | ||
/** | ||
* Renders the components. | ||
*/ | ||
declare function render(components: (Node | Element | unknown)[]): Element[]; | ||
type Stylable = { | ||
style: CSSPropertiesLike; | ||
className?: string; | ||
} | string; | ||
/** | ||
* The CSS properties like object. | ||
*/ | ||
type CSSPropertiesLike<K extends string | number | symbol = string> = Record<K, CSSProperties>; | ||
/** | ||
* Performs object cleanup by deleting all undefined properties that could interfere with builder methods. | ||
*/ | ||
declare const performObjectCleanup: (obj: Record<string, any>, deep?: boolean) => void; | ||
declare class StyleSheet extends null { | ||
private constructor(); | ||
/** | ||
* Creates a new CSSPropertiesLike object. | ||
*/ | ||
static create<O extends CSSPropertiesLike, K extends keyof O>(styles: CSSPropertiesLike<K>): CSSPropertiesLike<K>; | ||
/** | ||
* Composes two CSSPropertiesLike objects. | ||
*/ | ||
static compose(style1: CSSProperties, style2: CSSProperties): CSSProperties; | ||
/** | ||
* Flattens an array of CSSPropertiesLike objects. | ||
*/ | ||
static flatten(style: CSSProperties[]): CSSProperties; | ||
/** | ||
* Merges multiple tailwind-like class names into appropriate class names. | ||
*/ | ||
static cn(...classes: ClassNameValue[]): string; | ||
/** | ||
* Returns the className string from stylable data. | ||
*/ | ||
static tw(data?: Stylable): string; | ||
/** | ||
* Returns the style object from stylable data. | ||
*/ | ||
static css(data?: Stylable): CSSPropertiesLike<string>; | ||
} | ||
/** | ||
* The options for rendering the svg. | ||
*/ | ||
type RenderSvgOptions = PngEncodeOptions | AvifConfig$1 | number | null; | ||
declare class CanvacordImage { | ||
data: Buffer; | ||
mime: string; | ||
constructor(data: Buffer, mime: string); | ||
toBase64(): string; | ||
toDataURL(): string; | ||
} | ||
/** | ||
* The supported image sources. It can be a buffer, a readable stream, a string, a URL instance or an Image instance. | ||
*/ | ||
type ImageSource = CanvacordImage | Buffer | ArrayBuffer | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray | SharedArrayBuffer | Readable | string | URL | Image; | ||
/** | ||
* The options for loading an image. | ||
*/ | ||
interface LoadImageOptions { | ||
/** | ||
* The headers to use when downloading the image. | ||
*/ | ||
headers?: Record<string, string>; | ||
/** | ||
* The maximum number of redirects to follow. | ||
*/ | ||
maxRedirects?: number; | ||
/** | ||
* Other request options to use when downloading the image. | ||
*/ | ||
requestOptions?: http.RequestOptions; | ||
} | ||
/** | ||
* Loads an image from the specified source. | ||
* @param source The image source | ||
* @param [options] The options for loading the image | ||
*/ | ||
declare function loadImage(source: ImageSource, options?: LoadImageOptions): Promise<CanvacordImage>; | ||
declare class TemplateImage { | ||
#private; | ||
source: ImageSource; | ||
/** | ||
* Creates a new TemplateImage instance. | ||
* @param source The image source | ||
* | ||
* const image = new TemplateImage('https://example.com/image.png'); | ||
*/ | ||
constructor(source: ImageSource); | ||
/** | ||
* Whether this image has been resolved. | ||
*/ | ||
resolved(): boolean; | ||
/** | ||
* Resolves this image to consumable form. | ||
*/ | ||
resolve(): Promise<Image>; | ||
} | ||
/** | ||
* Creates a new template from the provided template. | ||
* @param template The template to create from | ||
*/ | ||
declare const createTemplate: <F extends (...args: any[]) => any, P extends Parameters<F>>(cb: (...args: P) => IImageGenerationTemplate) => (...args: P) => ImageGenerationTemplate; | ||
/** | ||
* The built-in template factory. | ||
*/ | ||
declare const TemplateFactory: { | ||
Affect: (image: ImageSource) => ImageGenerationTemplate; | ||
Triggered: (image: ImageSource) => ImageGenerationTemplate; | ||
Fuse: (destination: ImageSource, source: ImageSource) => ImageGenerationTemplate; | ||
Kiss: (image1: ImageSource, image2: ImageSource) => ImageGenerationTemplate; | ||
Spank: (image1: ImageSource, image2: ImageSource) => ImageGenerationTemplate; | ||
Slap: (image1: ImageSource, image2: ImageSource) => ImageGenerationTemplate; | ||
Beautiful: (image: ImageSource) => ImageGenerationTemplate; | ||
Facepalm: (image: ImageSource) => ImageGenerationTemplate; | ||
Rainbow: (image: ImageSource) => ImageGenerationTemplate; | ||
Rip: (image: ImageSource) => ImageGenerationTemplate; | ||
Trash: (image: ImageSource) => ImageGenerationTemplate; | ||
Hitler: (image: ImageSource) => ImageGenerationTemplate; | ||
Distracted: (image1: ImageSource, image2: ImageSource, image3?: ImageSource | null | undefined) => ImageGenerationTemplate; | ||
Colorfy: (image: ImageSource, color: string) => ImageGenerationTemplate; | ||
Jail: (image: ImageSource, greyscale?: boolean | undefined) => ImageGenerationTemplate; | ||
Bed: (image1: ImageSource, image2: ImageSource) => ImageGenerationTemplate; | ||
JokeOverHead: (image: ImageSource) => ImageGenerationTemplate; | ||
Delete: (image: ImageSource) => ImageGenerationTemplate; | ||
Wanted: (image: ImageSource) => ImageGenerationTemplate; | ||
Wasted: (image: ImageSource) => ImageGenerationTemplate; | ||
Shit: (image: ImageSource) => ImageGenerationTemplate; | ||
}; | ||
/** | ||
* The bundled fonts in this package. | ||
*/ | ||
declare const Fonts: { | ||
/** | ||
* Geist sans font | ||
* @see https://vercel.com/font/sans | ||
*/ | ||
readonly Geist: Buffer; | ||
}; | ||
declare class BuilderOptionsManager<T extends Record<string, any>> { | ||
private options; | ||
/** | ||
* Creates a new builder options manager. | ||
* @param options The options to use | ||
*/ | ||
constructor(options?: T); | ||
/** | ||
* Returns the options. | ||
*/ | ||
getOptions(): T; | ||
/** | ||
* Sets the options. This will override the previous options. | ||
* @param options The options to use | ||
*/ | ||
setOptions(options: T): void; | ||
/** | ||
* Get an option by name. | ||
* @param key The option name | ||
* @returns The option value | ||
*/ | ||
get<K extends keyof T>(key: K): T[K]; | ||
/** | ||
* Set an option by name. | ||
* @param key The option name | ||
* @param value The option value | ||
*/ | ||
set<K extends keyof T>(key: K, value: T[K]): void; | ||
/** | ||
* Merge new data to old data on an option by name. | ||
*/ | ||
merge<K extends keyof T>(key: K, value: Partial<T[K]>): void; | ||
} | ||
type GraphemeProvider = Record<string, string>; | ||
declare const createEmojiProvider: (builder: (code: string) => string) => GraphemeProvider; | ||
declare const BuiltInGraphemeProvider: { | ||
Twemoji: GraphemeProvider; | ||
FluentEmojiHighContrast: GraphemeProvider; | ||
FluentEmojiFlat: GraphemeProvider; | ||
FluentEmojiColor: GraphemeProvider; | ||
Openmoji: GraphemeProvider; | ||
Noto: GraphemeProvider; | ||
Blobmoji: GraphemeProvider; | ||
None: GraphemeProvider; | ||
}; | ||
declare const EmojiCache: Map<string, string>; | ||
/** | ||
* The builder template. | ||
*/ | ||
interface BuilderTemplate { | ||
/** | ||
* The components of this template. | ||
*/ | ||
components: Array<Node | Element>; | ||
/** | ||
* The width of this template. | ||
*/ | ||
width: number; | ||
/** | ||
* The height of this template. | ||
*/ | ||
height: number; | ||
/** | ||
* The style of this template. | ||
*/ | ||
style?: CSSProperties; | ||
} | ||
/** | ||
* The build output format. | ||
*/ | ||
type BuildFormat = "svg" | "png" | "avif" | "jpeg" | "webp"; | ||
/** | ||
* The builder build options. | ||
*/ | ||
type BuilderBuildOptions = { | ||
/** | ||
* The output format. | ||
*/ | ||
format?: BuildFormat; | ||
/** | ||
* The options for this build. | ||
*/ | ||
options?: RenderSvgOptions; | ||
/** | ||
* The abort signal. | ||
*/ | ||
signal?: AbortSignal; | ||
} & SatoriOptions; | ||
/** | ||
* The builder node. | ||
*/ | ||
interface Node { | ||
/** | ||
* Convert this node to element. | ||
*/ | ||
toElement(): Element; | ||
} | ||
declare class Builder<T extends Record<string, any> = Record<string, unknown>> { | ||
#private; | ||
width: number; | ||
height: number; | ||
/** | ||
* The tailwind subset to apply to this builder. | ||
*/ | ||
tw: string; | ||
/** | ||
* The components of this builder. | ||
*/ | ||
components: (Node | Element)[]; | ||
/** | ||
* The options manager of this builder. | ||
*/ | ||
options: BuilderOptionsManager<T>; | ||
/** | ||
* The grapheme provider of this builder. | ||
*/ | ||
graphemeProvider: GraphemeProvider; | ||
/** | ||
* Create a new builder. | ||
* @param width the width of this builder. | ||
* @param height the height of this builder. | ||
*/ | ||
constructor(width: number, height: number); | ||
/** | ||
* Bootstrap this builder with data. | ||
*/ | ||
bootstrap(data: T): void; | ||
/** | ||
* Adjust the canvas size. | ||
*/ | ||
adjustCanvas(): this; | ||
/** | ||
* Get the style of this builder. | ||
*/ | ||
get style(): CSSProperties; | ||
/** | ||
* Set the style of this builder. | ||
*/ | ||
set style(newStyle: CSSProperties); | ||
/** | ||
* Add component to this builder. | ||
* @param component the component to add. | ||
*/ | ||
addComponent<T extends Node | Element>(component: T | T[]): this; | ||
/** | ||
* Set grapheme image provider for this builder. | ||
*/ | ||
setGraphemeProvider(provider: GraphemeProvider): this; | ||
/** | ||
* Set the style of this builder. | ||
* @param newStyle the new style. | ||
*/ | ||
setStyle(newStyle: CSSProperties): this; | ||
private _render; | ||
/** | ||
* Render this builder. | ||
*/ | ||
render(): Promise<React.ReactNode>; | ||
/** | ||
* Convert this builder into an image. | ||
* @param options the build options. | ||
* @returns the image buffer or svg string. | ||
*/ | ||
build(options?: Partial<BuilderBuildOptions>): Promise<string | Buffer>; | ||
/** | ||
* Create a builder from builder template. | ||
*/ | ||
static from(template: BuilderTemplate): Builder<Record<string, unknown>>; | ||
} | ||
interface LeaderboardProps { | ||
/** | ||
* The background image. | ||
*/ | ||
background: ImageSource | null; | ||
/** | ||
* The background color. | ||
*/ | ||
backgroundColor: string; | ||
/** | ||
* The header of this leaderboard ui. | ||
*/ | ||
header?: { | ||
/** | ||
* The title of this leaderboard ui. | ||
*/ | ||
title: string; | ||
/** | ||
* The subtitle of this leaderboard ui. | ||
*/ | ||
subtitle: string; | ||
/** | ||
* The image of this leaderboard ui. | ||
*/ | ||
image: ImageSource; | ||
}; | ||
buildImage(canvas: Canvas): Promise<Buffer>; | ||
buildImageSync(canvas: Canvas): Buffer; | ||
getImageInfo(image: ImageSourceType): Promise<{ | ||
/** | ||
* The players of this leaderboard ui. | ||
*/ | ||
players: { | ||
/** | ||
* The display name of this player. | ||
*/ | ||
displayName: string; | ||
/** | ||
* The username of this player. | ||
*/ | ||
username: string; | ||
/** | ||
* The level of this player. | ||
*/ | ||
level: number; | ||
/** | ||
* The xp of this player. | ||
*/ | ||
xp: number; | ||
/** | ||
* The rank of this player. | ||
*/ | ||
rank: number; | ||
/** | ||
* The avatar of this player. | ||
*/ | ||
avatar: ImageSource; | ||
}[]; | ||
/** | ||
* The text values of this leaderboard ui. | ||
*/ | ||
text: { | ||
level: string; | ||
xp: string; | ||
rank: string; | ||
}; | ||
/** | ||
* Whether or not to abbreviate the numeric values. | ||
*/ | ||
abbreviate: boolean; | ||
} | ||
declare class LeaderboardBuilder extends Builder<LeaderboardProps> { | ||
/** | ||
* Create a new leaderboard ui builder | ||
*/ | ||
constructor(); | ||
/** | ||
* Set background for this leaderboard ui | ||
* @param background background image | ||
*/ | ||
setBackground(background: ImageSource): this; | ||
/** | ||
* Set background color for this leaderboard ui | ||
* @param color background color | ||
*/ | ||
setBackgroundColor(color: string): this; | ||
/** | ||
* Set header for this leaderboard ui | ||
* @param data header data | ||
*/ | ||
setHeader(data: LeaderboardProps["header"] & {}): this; | ||
/** | ||
* Set players for this leaderboard ui. The canvas size will be adjusted automatically based on the number of players. | ||
* @param players players data | ||
*/ | ||
setPlayers(players: LeaderboardProps["players"]): this; | ||
/** | ||
* Configures the text renderer for this leaderboard. | ||
* @param config The configuration for this leaderboard. | ||
*/ | ||
setTextStyles(config: Partial<LeaderboardProps["text"]>): this; | ||
/** | ||
* Render this leaderboard ui on the canvas | ||
*/ | ||
render(): Promise<JSX.Element>; | ||
/** | ||
* Render players ui on the canvas | ||
*/ | ||
renderPlayers(players: JSX.Element[]): JSX.Element; | ||
/** | ||
* Render top players ui on the canvas | ||
*/ | ||
renderTop({ avatar, displayName, level, rank, username, xp, }: LeaderboardProps["players"][number]): Promise<JSX.Element>; | ||
/** | ||
* Render player ui on the canvas | ||
*/ | ||
renderPlayer({ avatar, displayName, level, rank, username, xp, }: LeaderboardProps["players"][number]): Promise<JSX.Element>; | ||
} | ||
declare enum RankCardUserStatus { | ||
Online = "online", | ||
Idle = "idle", | ||
DoNotDisturb = "dnd", | ||
Offline = "offline", | ||
Streaming = "streaming", | ||
None = "none" | ||
} | ||
type StatusData = "online" | "idle" | "dnd" | "offline" | "streaming" | "none"; | ||
interface RankCardProps { | ||
handle: string | null; | ||
username: string | null; | ||
avatar: string; | ||
status: RankCardUserStatus | StatusData | null; | ||
currentXP: number | null; | ||
requiredXP: number | null; | ||
rank: number | null; | ||
level: number | null; | ||
backgroundColor: string; | ||
overlay: boolean | number | string; | ||
abbreviate: boolean; | ||
calculateProgress: (current: number, required: number) => number; | ||
texts: Partial<{ | ||
level: string; | ||
xp: string; | ||
rank: string; | ||
}>; | ||
styles: Partial<{ | ||
container: Stylable; | ||
background: Stylable; | ||
overlay: Stylable; | ||
avatar: Partial<{ | ||
container: Stylable; | ||
image: Stylable; | ||
status: Stylable; | ||
}>; | ||
username: Partial<{ | ||
container: Stylable; | ||
name: Stylable; | ||
handle: Stylable; | ||
}>; | ||
progressbar: Partial<{ | ||
container: Stylable; | ||
thumb: Stylable; | ||
track: Stylable; | ||
}>; | ||
statistics: Partial<{ | ||
container: Stylable; | ||
level: Partial<{ | ||
container: Stylable; | ||
text: Stylable; | ||
value: Stylable; | ||
}>; | ||
xp: Partial<{ | ||
container: Stylable; | ||
text: Stylable; | ||
value: Stylable; | ||
}>; | ||
rank: Partial<{ | ||
container: Stylable; | ||
text: Stylable; | ||
value: Stylable; | ||
}>; | ||
}>; | ||
}>; | ||
} | ||
/** | ||
* The rank card builder props. | ||
*/ | ||
interface RankCardBuilderProps extends Omit<RankCardProps, "avatar" | "backgroundColor"> { | ||
avatar: ImageSource; | ||
background: ImageSource; | ||
backgroundCrop?: Partial<{ | ||
x: number; | ||
y: number; | ||
width: number; | ||
height: number; | ||
source: Buffer; | ||
}>; | ||
fonts: Partial<{ | ||
username: Partial<{ | ||
name: string; | ||
handle: string; | ||
}>; | ||
progress: Partial<{ | ||
level: Partial<{ | ||
text: string; | ||
value: string; | ||
}>; | ||
xp: Partial<{ | ||
text: string; | ||
value: string; | ||
}>; | ||
rank: Partial<{ | ||
text: string; | ||
value: string; | ||
}>; | ||
}>; | ||
}>; | ||
} | ||
declare class RankCardBuilder extends Builder<RankCardBuilderProps> { | ||
/** | ||
* Creates a new rank card builder. | ||
* @example | ||
* const card = new RankCardBuilder() | ||
* .setUsername('kiki') | ||
* .setDisplayName('Kiki') | ||
* .setDiscriminator('1234') | ||
* .setAvatar('...') | ||
* .setCurrentXP(300) | ||
* .setRequiredXP(600) | ||
* .setLevel(2) | ||
* .setRank(5) | ||
* .setStatus('online'); | ||
* | ||
* const pngBuffer = await card.build({ | ||
* format: 'png' | ||
* }); | ||
*/ | ||
constructor(); | ||
/** | ||
* Sets the fonts to be used for this rank card. | ||
* @param fontConfig The fonts to be used for this rank card. | ||
*/ | ||
setFonts(fontConfig: Required<RankCardBuilderProps["fonts"]>): this; | ||
/** | ||
* Sets the avatar for this rank card. | ||
* @param image The avatar for this rank card. | ||
*/ | ||
setAvatar(image: ImageSource): this; | ||
/** | ||
* Sets the background for this rank card. | ||
* @param image The background for this rank card. | ||
*/ | ||
setBackground(image: ImageSource): this; | ||
/** | ||
* Sets the status for this rank card. | ||
* @param status The status for this rank card. | ||
*/ | ||
setStatus(status: RankCardUserStatus | StatusData): this; | ||
/** | ||
* Sets the username for this rank card. | ||
* @param name The username for this rank card. | ||
*/ | ||
setDisplayName(name: string): this; | ||
/** | ||
* Sets the handle name for this rank card. | ||
* @param name The handle name for this rank card. | ||
*/ | ||
setUsername(name: string): this; | ||
/** | ||
* Set overlay for this rank card. | ||
*/ | ||
setOverlay(overlay: RankCardProps["overlay"]): this; | ||
/** | ||
* Sets the current xp for this rank card. | ||
* @param xp The current xp for this rank card. | ||
*/ | ||
setCurrentXP(xp: number): this; | ||
/** | ||
* Sets the required xp for this rank card. | ||
* @param xp The required xp for this rank card. | ||
*/ | ||
setRequiredXP(xp: number): this; | ||
/** | ||
* Sets the level of this rank card. | ||
* @param level The level of this rank card. | ||
*/ | ||
setLevel(level: number): this; | ||
/** | ||
* Sets the rank of this rank card. | ||
* @param rank The rank of this rank card. | ||
*/ | ||
setRank(rank: number): this; | ||
/** | ||
* Configures the renderer for this rank card. | ||
* @param config The configuration for this rank card. | ||
*/ | ||
setStyles(config: Partial<RankCardBuilderProps["styles"]>): this; | ||
/** | ||
* Set background crop for this rank card. | ||
*/ | ||
setBackgroundCrop(pos: Partial<RankCardBuilderProps["backgroundCrop"]>): this; | ||
/** | ||
* Configures the texts for this rank card. | ||
* @param config The configuration for this rank card. | ||
*/ | ||
setTextStyles(config: Partial<RankCardBuilderProps["texts"]>): this; | ||
/** | ||
* Sets the progress calculator for this rank card. The value returned by this calculator defines the width of the progress bar. | ||
* Valid range is 0-100. Returning a number less than 0 or greater than 100 will be clamped within this range, or invalid values will result in 0% width. | ||
* @param calc The progress calculator for this rank card. | ||
*/ | ||
setProgressCalculator(calc: RankCardProps["calculateProgress"]): this; | ||
/** | ||
* Renders this rank card into the canvas. | ||
*/ | ||
render(): Promise<JSX.Element>; | ||
} | ||
declare enum BuilderReadyState { | ||
NOT_READY = 0, | ||
READY = 1 | ||
/** | ||
* Creates a canvas image from the image source. | ||
* @param img The image source | ||
* @returns The canvas image | ||
* | ||
* const image = await createCanvasImage('https://example.com/image.png'); | ||
*/ | ||
declare const createCanvasImage: (img: ImageSource) => Promise<_napi_rs_canvas.Image>; | ||
/** | ||
* The steps to apply to the canvas. | ||
* @param ctx The canvas context | ||
*/ | ||
type ContextManipulationStep = (ctx: SKRSContext2D) => Awaited<void>; | ||
declare abstract class CanvasHelper extends Encodable { | ||
width: number; | ||
height: number; | ||
/** | ||
* The steps to apply to the canvas. | ||
*/ | ||
steps: ContextManipulationStep[]; | ||
private _canvas; | ||
/** | ||
* Creates a new CanvasHelper instance. | ||
* @param width The width of the canvas | ||
* @param height The height of the canvas | ||
*/ | ||
constructor(width: number, height: number); | ||
/** | ||
* Returns the canvas instance by applying the steps. | ||
*/ | ||
getFinalCanvas(): Promise<Canvas>; | ||
/** | ||
* Processes the steps and applies them to the canvas. | ||
*/ | ||
abstract process(canvas: Canvas, ctx: SKRSContext2D): Promise<void>; | ||
} | ||
declare class CanvasBuilder2D extends BaseCanvas { | ||
readonly width: number; | ||
readonly height: number; | ||
private _canvas; | ||
private _ctx; | ||
readonly engine = "skia"; | ||
constructor(width: number, height: number, autoInstance?: boolean); | ||
get canvas(): Canvas; | ||
get ctx(): SKRSContext2D; | ||
get readyState(): BuilderReadyState; | ||
instantiate(): this; | ||
drawImage(image: Image, dx: number, dy: number, dw?: number, dh?: number): CanvasBuilder2D; | ||
clearRect(x: number, y: number, w: number, h: number): this; | ||
drawRect(x: number, y: number, width: number, height: number): this; | ||
strokeRect(x: number, y: number, width: number, height: number): this; | ||
setColorFill(color: string): this; | ||
setColorStroke(color: string): this; | ||
toBuffer(format?: CanvacordOutputFormat): Buffer; | ||
toBufferAsync(format?: CanvacordOutputFormat): Promise<Buffer>; | ||
declare class ImageFilterer extends CanvasHelper { | ||
#private; | ||
/** | ||
* Draws the image to the canvas. | ||
* @param image The image to draw | ||
* @param x The x position to draw the image | ||
* @param y The y position to draw the image | ||
* @param [width] The width of the image | ||
* @param [height] The height of the image | ||
*/ | ||
drawImage(image: ImageSource, x?: number, y?: number, width?: number, height?: number): this; | ||
/** | ||
* Applies invert filter to the image. | ||
* @param value The filter intensity | ||
*/ | ||
invert(value: number): this; | ||
/** | ||
* Applies grayscale filter to the image. | ||
* @param value The filter intensity | ||
*/ | ||
grayscale(value?: number): this; | ||
/** | ||
* Applies sepia filter to the image. | ||
* @param value The filter intensity | ||
*/ | ||
sepia(value: number): this; | ||
/** | ||
* Applies opacity filter to the image. | ||
* @param value The filter intensity | ||
*/ | ||
opacity(value: number): this; | ||
/** | ||
* Applies saturate filter to the image. | ||
* @param value The filter intensity | ||
*/ | ||
saturate(value: number): this; | ||
/** | ||
* Applies hue-rotate filter to the image. | ||
* @param value The degrees to rotate | ||
*/ | ||
hueRotate(value: number): this; | ||
/** | ||
* Applies contrast filter to the image. | ||
* @param value The filter intensity | ||
*/ | ||
contrast(value: number): this; | ||
/** | ||
* Applies brightness filter to the image. | ||
* @param value The filter intensity | ||
*/ | ||
brightness(value: number): this; | ||
/** | ||
* Applies blur filter to the image. | ||
* @param value The filter intensity | ||
*/ | ||
blur(value: number): this; | ||
/** | ||
* Applies drop-shadow filter to the image. | ||
* @param config The drop-shadow config | ||
* @param config.x The x offset of the shadow | ||
* @param config.y The y offset of the shadow | ||
* @param config.radius The blur radius of the shadow | ||
* @param config.color The color of the shadow | ||
*/ | ||
dropShadow(config: DropShadowConfig): this; | ||
/** | ||
* Renders the applied filters to the canvas. | ||
* @param canvas The canvas to render the filters to | ||
* @param ctx The canvas context | ||
*/ | ||
process(canvas: Canvas, ctx: SKRSContext2D): Promise<void>; | ||
} | ||
interface DropShadowConfig { | ||
x: number; | ||
y: number; | ||
radius: number; | ||
color: string; | ||
} | ||
declare class CanvasImage extends ImageFilterer { | ||
#private; | ||
source: ImageSource; | ||
/** | ||
* Creates a new CanvasImage instance. | ||
* @param source The image source | ||
* @param [width] The width of the image | ||
* @param [height] The height of the image | ||
*/ | ||
constructor(source: ImageSource, width?: number, height?: number); | ||
/** | ||
* Draws the image to the canvas. | ||
* @param x The x position to draw the image | ||
* @param y The y position to draw the image | ||
* @param [width] The width of the image | ||
* @param [height] The height of the image | ||
*/ | ||
draw(x?: number, y?: number, width?: number, height?: number): this; | ||
/** | ||
* Draws the image to the canvas with a circle clip. | ||
* @param [width] The width of the image | ||
* @param [height] The height of the image | ||
*/ | ||
circle(width?: number, height?: number): this; | ||
/** | ||
* Draws pixelated image to the canvas. | ||
* @param [pixels=5] The amount of pixels to use | ||
*/ | ||
pixelate(pixels?: number): this; | ||
/** | ||
* Saves the canvas context state. | ||
*/ | ||
save(): this; | ||
/** | ||
* Restores the last saved canvas context state. | ||
*/ | ||
restore(): this; | ||
valueOf(): { | ||
canvas: Canvas; | ||
ctx: SKRSContext2D; | ||
}; | ||
toString(): string; | ||
/** | ||
* Returns the canvas instance by applying the steps. | ||
*/ | ||
getFinalCanvas(): Promise<Canvas>; | ||
} | ||
declare class MemeCanvas extends BaseCanvas { | ||
trigger(image: ImageSourceType): Promise<Buffer>; | ||
triggered(image: ImageSourceType): Promise<Buffer>; | ||
kiss(image1: ImageSourceType, image2: ImageSourceType): Promise<Buffer>; | ||
spank(image1: ImageSourceType, image2: ImageSourceType): Promise<Buffer>; | ||
slap(image1: ImageSourceType, image2: ImageSourceType): Promise<Buffer>; | ||
beautiful(image: ImageSourceType): Promise<Buffer>; | ||
facepalm(image: ImageSourceType): Promise<Buffer>; | ||
rainbow(image: ImageSourceType): Promise<Buffer>; | ||
rip(image: ImageSourceType): Promise<Buffer>; | ||
trash(image: ImageSourceType): Promise<Buffer>; | ||
hitler(image: ImageSourceType): Promise<Buffer>; | ||
jokeOverHead(image: ImageSourceType): Promise<Buffer>; | ||
distracted(image1: ImageSourceType, image2: ImageSourceType, image3?: ImageSourceType): Promise<Buffer>; | ||
affect(image: ImageSourceType): Promise<Buffer>; | ||
jail(image: ImageSourceType, greyscale?: boolean): Promise<Buffer>; | ||
bed(image1: ImageSourceType, image2: ImageSourceType): Promise<Buffer>; | ||
delete(image: ImageSourceType, dark?: boolean): Promise<Buffer>; | ||
wanted(image: ImageSourceType): Promise<Buffer>; | ||
wasted(image: ImageSourceType): Promise<Buffer>; | ||
shit(image: ImageSourceType): Promise<Buffer>; | ||
declare class ImageManipulator extends CanvasImage { | ||
#private; | ||
/** | ||
* Rotates the canvas. | ||
*/ | ||
rotate(degrees: number): this; | ||
/** | ||
* Flips the canvas. | ||
* @param axis The axis to flip, `x` or `y`. | ||
*/ | ||
flip(axis: "x" | "y"): void; | ||
/** | ||
* Scales the canvas. | ||
* @param x The x scale | ||
* @param y The y scale | ||
*/ | ||
scale(x: number, y: number): void; | ||
/** | ||
* Translates the canvas. | ||
* @param x The x position to translate | ||
* @param y The y position to translate | ||
*/ | ||
translate(x: number, y: number): void; | ||
/** | ||
* Erases a part of the canvas. | ||
* @param x The x position to erase | ||
* @param y The y position to erase | ||
* @param width The width of the area to erase | ||
* @param height The height of the area to erase | ||
*/ | ||
erase(x: number, y: number, width: number, height: number): void; | ||
/** | ||
* Applies a transform to the canvas. | ||
*/ | ||
transform(a: number, b: number, c: number, d: number, e: number, f: number): void; | ||
/** | ||
* Resets the transform of the canvas. | ||
*/ | ||
resetTransform(): void; | ||
/** | ||
* Applies a circular clip to the image. | ||
* @param width The width of the image | ||
* @param height The height of the image | ||
*/ | ||
circularize(width: number, height: number): void; | ||
/** | ||
* Processes the steps and applies them to the canvas. | ||
* @param canvas The canvas to apply the steps to | ||
* @param ctx The canvas context to apply the steps to | ||
*/ | ||
process(canvas: Canvas, ctx: SKRSContext2D): Promise<void>; | ||
} | ||
declare class UtilityCanvas extends BaseCanvas { | ||
blur(image: ImageSourceType, pixels?: number): Promise<Buffer>; | ||
brighten(img: ImageSourceType, amount?: number): Promise<Buffer>; | ||
darken(img: ImageSourceType, amount?: number): Promise<Buffer>; | ||
greyscale(img: ImageSourceType): Promise<Buffer>; | ||
grayscale(img: ImageSourceType): Promise<Buffer>; | ||
invert(img: ImageSourceType): Promise<Buffer>; | ||
sepia(img: ImageSourceType): Promise<Buffer>; | ||
threshold(img: ImageSourceType, amount: number): Promise<Buffer>; | ||
circle(image: ImageSourceType): Promise<Buffer>; | ||
convolute(ctx: SKRSContext2D, canvas: Canvas, matrix: number[], opaque?: boolean): Promise<SKRSContext2D>; | ||
colorfy(image: ImageSourceType, color: string): Promise<Buffer>; | ||
colourfy(image: ImageSourceType, colour: string): Promise<Buffer>; | ||
color(color: string, width: number, height: number): Promise<Buffer>; | ||
colour(colour: string, width: number, height: number): Promise<Buffer>; | ||
type ImageGeneratorImplementor = { | ||
[K in Lowercase<Exclude<keyof typeof TemplateFactory, "Triggered">>]: (...args: Parameters<(typeof TemplateFactory)[Capitalize<K>]>) => Promise<Buffer>; | ||
}; | ||
interface CanvacordFactory extends ImageGeneratorImplementor { | ||
/** | ||
* Creates a new ImageFilterer instance. | ||
* @param width The width of the image | ||
* @param height The height of the image | ||
*/ | ||
filters(width: number, height: number): ImageFilterer; | ||
/** | ||
* Generates Triggered gif with the provided image. | ||
* @param image The image to use | ||
* @param [asBuffer] Whether to return a buffer instead of a stream | ||
* @returns The generated gif | ||
*/ | ||
triggered(image: ImageSource): Promise<Readable>; | ||
/** | ||
* Generates Triggered gif with the provided image. | ||
* @param image The image to use | ||
* @param [asBuffer] Whether to return a buffer instead of a stream | ||
* @returns The generated gif | ||
*/ | ||
triggered(image: ImageSource, asBuffer: false): Promise<Readable>; | ||
/** | ||
* Generates Triggered gif with the provided image. | ||
* @param image The image to use | ||
* @param [asBuffer] Whether to return a buffer instead of a stream | ||
* @returns The generated gif | ||
*/ | ||
triggered(image: ImageSource, asBuffer: true): Promise<Buffer>; | ||
/** | ||
* Generates Triggered gif with the provided image. | ||
* @param image The image to use | ||
* @param [asBuffer] Whether to return a buffer instead of a stream | ||
* @returns The generated gif | ||
*/ | ||
triggered(image: ImageSource, asBuffer?: boolean): Promise<Readable | Buffer>; | ||
} | ||
/** | ||
* Canvacord Utils | ||
*/ | ||
declare class Util { | ||
static loadImage: typeof loadImage; | ||
constructor(); | ||
static createImage(src: Buffer): void; | ||
interface CanvacordInit { | ||
/** | ||
* Renders emoji in canvas | ||
* @param ctx Canvas rendering context | ||
* @param message message to render | ||
* @param x x co-ordinate | ||
* @param y y co-ordinate | ||
* The width of the image. Defaults to `-1` (auto). | ||
*/ | ||
static renderEmoji(ctx: SKRSContext2D, message: string, x: number, y: number): Promise<void>; | ||
width?: number; | ||
/** | ||
* Abbreviate the given number | ||
* @param num The number to abbreviate | ||
* The height of the image. Defaults to `-1` (auto). | ||
*/ | ||
static toAbbrev(num: number): string; | ||
static get assets(): { | ||
font(name: string): Promise<string>; | ||
image(name: string): Promise<string>; | ||
}; | ||
static cleanText(text: string): string; | ||
static is(prop: any, propType: string): boolean; | ||
static streamToBuffer(stream: Readable): Promise<Buffer>; | ||
static noop(): void; | ||
height?: number; | ||
} | ||
/** | ||
* Creates a new Canvacord image processor. | ||
* @param source The image source to use | ||
* @param options The options to use | ||
* @returns The image processor | ||
*/ | ||
declare function CanvacordConstructor(source: ImageSource, options?: CanvacordInit): CanvasImage; | ||
type Canvacord = CanvacordFactory & typeof CanvacordConstructor; | ||
/** | ||
* Creates a new Canvacord image processor. | ||
* @param source The image source to use | ||
* @param options The options to use | ||
* @returns The image processor | ||
*/ | ||
declare const canvacord: Canvacord; | ||
export { BaseCanvas, BuilderReadyState, CanvasBuilder2D, MemeCanvas, Util, UtilityCanvas }; | ||
export { BuildFormat, Builder, BuilderBuildOptions, BuilderOptionsManager, BuilderTemplate, BuiltInGraphemeProvider, CSSPropertiesLike, Canvacord, CanvacordFactory, CanvacordInit, CanvasHelper, CanvasImage, ContextManipulationStep, CustomGenerationStep, DropShadowConfig, Element, ElementInit, EmojiCache, Encodable, EncodingFormat, Font, FontFactory, Fonts, GraphemeProvider, IImageGenerationTemplate, ImageFactory, ImageFilterer, ImageGen, ImageGenerationStep, ImageGenerationTemplate, ImageGeneratorImplementor, ImageManipulator, ImageSource, ImgenStep, JSX$1 as JSX, LeaderboardBuilder, LeaderboardProps, LoadImageOptions, Node, RankCardBuilder, Stylable, StyleSheet, TemplateFactory, TemplateImage, TextGenerationStep, canvacord, createCanvasImage, createEmojiProvider, createImageGenerator, createTemplate, loadImage, performObjectCleanup, render }; |
151
package.json
{ | ||
"name": "canvacord", | ||
"version": "6.0.0-dev.f3ae696.1628209226", | ||
"description": "Simple & easy to use image manipulation module for beginners.", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/" | ||
], | ||
"exports": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"scripts": { | ||
"build": "rimraf dist && tsc && npm run build:esm", | ||
"build:check": "tsc --noEmit --incremental false", | ||
"build:esm": "gen-esm-wrapper ./dist/index.js ./dist/index.mjs", | ||
"build:bundle": "npm run build && rollup-type-bundler -e stream", | ||
"docs": "docgen --source src/*.ts src/**/*.ts --custom docs/index.yml --output docs/docs.json", | ||
"docs:test": "docgen --source src/*.ts src/**/*.ts --custom docs/index.yml", | ||
"test": "jest", | ||
"dev": "cd test && node index.js", | ||
"format": "prettier --write **/*.{ts,js,json,yaml,yml}", | ||
"lint": "eslint src --ext .ts", | ||
"lint:fix": "eslint src --ext .ts --fix", | ||
"deps:update": "npx npm-check-updates -u && yarn install", | ||
"prepublishOnly": "npm run build:bundle" | ||
}, | ||
"homepage": "https://canvacord.js.org", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/DevSnowflake/Canvacord.git" | ||
}, | ||
"keywords": [ | ||
"Canvacord", | ||
"discord-canvas", | ||
"discord.js-canvas", | ||
"discord.js-image", | ||
"memes", | ||
"rank", | ||
"rank-card", | ||
"welcomer", | ||
"leaver", | ||
"dank-memer", | ||
"imagen", | ||
"imgen", | ||
"imagegen", | ||
"canvas", | ||
"jimp", | ||
"api" | ||
], | ||
"author": "DevAndromeda <devandromeda@snowflakedev.org>", | ||
"funding": { | ||
"type": "individual", | ||
"url": "https://paypal.me/devsnowflake" | ||
}, | ||
"license": "GPL-3.0", | ||
"dependencies": { | ||
"@canvacord/assets": "^2.0.5", | ||
"@canvacord/emoji-parser": "^1.0.1", | ||
"@canvacord/gif": "^1.0.2", | ||
"@napi-rs/canvas": "^0.1.1", | ||
"gifencoder": "^2.0.1", | ||
"node-fetch": "^2.6.1", | ||
"weird-to-normal-chars": "^1.5.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.14.9", | ||
"@babel/preset-typescript": "^7.14.5", | ||
"@devsnowflake/docgen": "DevSnowflake/docgen#ts-patch", | ||
"@favware/rollup-type-bundler": "^1.0.3", | ||
"@types/gifencoder": "^2.0.1", | ||
"@types/jest": "^26.0.24", | ||
"@types/node": "^16.4.10", | ||
"@types/node-fetch": "^2.5.12", | ||
"@typescript-eslint/eslint-plugin": "^4.29.0", | ||
"@typescript-eslint/parser": "^4.29.0", | ||
"eslint": "^7.32.0", | ||
"file-type": "^16.5.2", | ||
"gen-esm-wrapper": "^1.1.2", | ||
"husky": "^7.0.1", | ||
"jest": "^27.0.6", | ||
"prettier": "^2.3.2", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^10.1.0", | ||
"typescript": "^4.3.5" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/DevSnowflake/Canvacord/issues" | ||
} | ||
} | ||
"name": "canvacord", | ||
"description": "Easily generate images using html and css in nodejs. Canvacord is suitable for creating dynamic images such as social media posts, greetings cards, memes, etc. It is also possible to create your own templates and builders to generate images. You are only limited by your imagination.", | ||
"version": "6.0.0", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"module": "./dist/index.mjs", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"format": "yarn dlx @biomejs/biome format src --write", | ||
"build": "tsup", | ||
"test": "tsx ./test/index.ts", | ||
"test:lb": "tsx ./test/leaderboard.ts", | ||
"test:jsx": "tsx ./test/jsxTest.tsx", | ||
"test:demo": "tsx ./test/demo.tsx", | ||
"bench": "cd ./benchmark && node jsx-renderer.mjs", | ||
"lint": "yarn dlx @biomejs/biome lint src" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/neplextech/canvacord.git" | ||
}, | ||
"keywords": [ | ||
"canavcord", | ||
"image", | ||
"api", | ||
"manipulation", | ||
"nodejs", | ||
"typescript" | ||
], | ||
"author": "twlite", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/neplextech/canvacord/issues" | ||
}, | ||
"homepage": "https://canvacord.js.org", | ||
"packageManager": "yarn@3.6.0", | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.4.1", | ||
"@types/node": "^20.3.1", | ||
"@types/react": "^18.2.12", | ||
"benny": "^3.7.1", | ||
"biome": "^0.0.0", | ||
"tailwindcss": "^3.3.3", | ||
"tsconfig": "^0.0.0", | ||
"tsup": "^7.2.0", | ||
"tsx": "^3.12.7", | ||
"typescript": "^5.1.3" | ||
}, | ||
"dependencies": { | ||
"@napi-rs/canvas": "^0.1.44", | ||
"@napi-rs/image": "^1.7.0", | ||
"@resvg/resvg-js": "^2.6.0", | ||
"@skyra/gifenc": "^1.0.1", | ||
"file-type": "16.5.4", | ||
"satori": "^0.10.11", | ||
"tailwind-merge": "^2.0.0" | ||
} | ||
} |
@@ -0,21 +1,41 @@ | ||
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine) | ||
# Canvacord | ||
Simple & easy to use image manipulation module. | ||
# v6 WIP | ||
Easily generate images using html and css in nodejs. Canvacord is suitable for creating dynamic images such as social media posts, greetings cards, memes, etc. It is also possible to create your own templates and builders to generate images. You are only limited by your imagination. | ||
> [https://canvacord.js.org](https://canvacord.js.org) | ||
## Features | ||
- 🪟 **Open source, no privacy issues, 100% transparent** - Canvacord is completely open source and free to use. This makes everything transparent and you can even contribute to the project. Best of all, you dont have to worry about privacy issues 😊. | ||
- 💪 **Easy to use** - Canvacord provides a simple api to generate images on-the-fly. | ||
- 🎨 **Customizable** - You can create your own templates and builders to generate images. Canvacord allows you to define how your image should look using html and css. No more hassle learning complicated canvas api. | ||
- 🚀 **Fast** - Canvacord is powered by highly optimized, battle tested libraries, which makes it fast and reliable. | ||
- 🔒 **Typescript support** - Canvacord is written in typescript and provides type definitions out of the box. | ||
- 📸 **Wide formats support** - Canvacord supports many image formats such as png, jpeg, webp, gif, svg, etc. | ||
- 📄 **Wide range of templates** - Canvacord provides many built-in templates to generate images such as triggered gif, beautiful image, facepalm image, etc. to quickly generate that meme you saw on reddit 🤡. No need to touch complicated canvas api, just a simple schema object is enough. | ||
# Example | ||
## Triggered | ||
```js | ||
import { MemeCanvas } from "canvacord"; | ||
import { promises as fs } from "fs"; | ||
## Installation | ||
const memegen = new MemeCanvas(); | ||
const image = getImageSomehow(); | ||
const triggered = await memegen.trigger(image); | ||
await fs.writeFile("./triggered.gif", triggered); | ||
```sh | ||
$ npm install canvacord | ||
``` | ||
![img](https://i.imgur.com/tes5yE2.gif) | ||
Canvacord stays away from node-gyp based dependencies, so you don't have to worry about weird errors while installing the library. Although canvacord utilizes [@napi-rs/canvas](https://npm.im/@napi-rs/canvas) under the hood, it is recommended to use the builder api for image generation. Only utilize the canvas api if you need to perform image manipulation. | ||
# Documentation | ||
[https://canvacord.js.org](https://canvacord.js.org) | ||
# Discord support server | ||
[https://neplextech.com/discord](https://neplextech.com/discord) | ||
# Support the project | ||
You can support the project by donating on [patreon](https://www.patreon.com/twlite) or [buymeacoffee](https://www.buymeacoffee.com/twlite). This will help us to keep the project alive and maintain it regularly. You can also contribute to the project by submitting a pull request or reporting a bug. | ||
<a href="https://www.buymeacoffee.com/twlite"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy me a coffee" width="200" height="50"></a> <a href="https://www.patreon.com/twlite"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" width="200" height="50"></a> | ||
#### GPL-3.0 License - [Neplex Technologies](https://neplextech.com) | ||
Mail to [info@neplextech.com](mailto:info@neplextech.com) for any questions or suggestions. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
1019341
10
0
100
8022
0
0
42
6
13
9
+ Added@napi-rs/image@^1.7.0
+ Added@resvg/resvg-js@^2.6.0
+ Added@skyra/gifenc@^1.0.1
+ Addedfile-type@16.5.4
+ Addedsatori@^0.10.11
+ Addedtailwind-merge@^2.0.0
+ Added@emnapi/core@1.3.1(transitive)
+ Added@emnapi/runtime@1.3.1(transitive)
+ Added@emnapi/wasi-threads@1.0.1(transitive)
+ Added@napi-rs/image@1.9.2(transitive)
+ Added@napi-rs/image-android-arm64@1.9.2(transitive)
+ Added@napi-rs/image-darwin-arm64@1.9.2(transitive)
+ Added@napi-rs/image-darwin-x64@1.9.2(transitive)
+ Added@napi-rs/image-freebsd-x64@1.9.2(transitive)
+ Added@napi-rs/image-linux-arm-gnueabihf@1.9.2(transitive)
+ Added@napi-rs/image-linux-arm64-gnu@1.9.2(transitive)
+ Added@napi-rs/image-linux-arm64-musl@1.9.2(transitive)
+ Added@napi-rs/image-linux-x64-gnu@1.9.2(transitive)
+ Added@napi-rs/image-linux-x64-musl@1.9.2(transitive)
+ Added@napi-rs/image-wasm32-wasi@1.9.2(transitive)
+ Added@napi-rs/image-win32-ia32-msvc@1.9.2(transitive)
+ Added@napi-rs/image-win32-x64-msvc@1.9.2(transitive)
+ Added@napi-rs/wasm-runtime@0.2.5(transitive)
+ Added@resvg/resvg-js@2.6.2(transitive)
+ Added@resvg/resvg-js-android-arm-eabi@2.6.2(transitive)
+ Added@resvg/resvg-js-android-arm64@2.6.2(transitive)
+ Added@resvg/resvg-js-darwin-arm64@2.6.2(transitive)
+ Added@resvg/resvg-js-darwin-x64@2.6.2(transitive)
+ Added@resvg/resvg-js-linux-arm-gnueabihf@2.6.2(transitive)
+ Added@resvg/resvg-js-linux-arm64-gnu@2.6.2(transitive)
+ Added@resvg/resvg-js-linux-arm64-musl@2.6.2(transitive)
+ Added@resvg/resvg-js-linux-x64-gnu@2.6.2(transitive)
+ Added@resvg/resvg-js-linux-x64-musl@2.6.2(transitive)
+ Added@resvg/resvg-js-win32-arm64-msvc@2.6.2(transitive)
+ Added@resvg/resvg-js-win32-ia32-msvc@2.6.2(transitive)
+ Added@resvg/resvg-js-win32-x64-msvc@2.6.2(transitive)
+ Added@shuding/opentype.js@1.4.0-beta.0(transitive)
+ Added@skyra/gifenc@1.0.1(transitive)
+ Added@tokenizer/token@0.3.0(transitive)
+ Added@tybys/wasm-util@0.9.0(transitive)
+ Addedbase64-js@0.0.8(transitive)
+ Addedcamelize@1.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcss-background-parser@0.1.0(transitive)
+ Addedcss-box-shadow@1.0.0-3(transitive)
+ Addedcss-color-keywords@1.0.0(transitive)
+ Addedcss-to-react-native@3.2.0(transitive)
+ Addedemoji-regex@10.4.0(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedfflate@0.7.4(transitive)
+ Addedfile-type@16.5.4(transitive)
+ Addedhex-rgb@4.3.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedlinebreak@1.1.0(transitive)
+ Addedpako@0.2.9(transitive)
+ Addedparse-css-color@0.2.1(transitive)
+ Addedpeek-readable@4.1.0(transitive)
+ Addedpostcss-value-parser@4.2.0(transitive)
+ Addedreadable-web-to-node-stream@3.0.2(transitive)
+ Addedsatori@0.10.14(transitive)
+ Addedstring.prototype.codepointat@0.2.1(transitive)
+ Addedstrtok3@6.3.0(transitive)
+ Addedtailwind-merge@2.5.5(transitive)
+ Addedtiny-inflate@1.0.3(transitive)
+ Addedtoken-types@4.2.1(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedunicode-trie@2.0.0(transitive)
+ Addedyoga-wasm-web@0.3.3(transitive)
- Removed@canvacord/assets@^2.0.5
- Removed@canvacord/emoji-parser@^1.0.1
- Removed@canvacord/gif@^1.0.2
- Removedgifencoder@^2.0.1
- Removednode-fetch@^2.6.1
- Removedweird-to-normal-chars@^1.5.1
- Removed@canvacord/assets@2.1.0(transitive)
- Removed@canvacord/emoji-parser@1.0.1(transitive)
- Removed@canvacord/gif@1.0.2(transitive)
- Removed@mapbox/node-pre-gyp@1.0.11(transitive)
- Removedabbrev@1.1.1(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedaproba@2.0.0(transitive)
- Removedare-we-there-yet@2.0.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedcanvas@2.11.2(transitive)
- Removedchownr@2.0.0(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcwise-compiler@1.1.3(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddecompress-response@4.2.1(transitive)
- Removeddelegates@1.0.0(transitive)
- Removeddetect-libc@2.0.3(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedfs-minipass@2.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedgauge@3.0.2(transitive)
- Removedgif-encoder@0.7.2(transitive)
- Removedgifencoder@2.0.1(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
- Removedinflight@1.0.6(transitive)
- Removediota-array@1.0.0(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedmimic-response@2.1.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminipass@3.3.65.0.0(transitive)
- Removedminizlib@2.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedms@2.1.3(transitive)
- Removednan@2.22.0(transitive)
- Removedndarray@1.0.19(transitive)
- Removedndarray-ops@1.2.2(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removednopt@5.0.0(transitive)
- Removednpmlog@5.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedomggif@1.0.10(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpngjs-nozlib@1.0.0(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedsemver@6.3.17.6.3(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@3.1.1(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedtar@6.2.1(transitive)
- Removedtr46@0.0.3(transitive)
- Removedtwemoji-parser@13.1.0(transitive)
- Removeduniq@1.0.1(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedweird-to-normal-chars@1.8.3(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedwide-align@1.1.5(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedyallist@4.0.0(transitive)
Updated@napi-rs/canvas@^0.1.44