Skip to main content

Class: default

Defined in: src/lib/classes/CustomPresets/index.ts:54

The user's own and imported brush presets, shared by the brush and eraser. They are kept in a store when one is used (otherwise only until the page closes).

Dispatches a change event when presets are loaded, saved or removed.

Example​

const custom = new CustomPresets(new IndexedDbAssetStore("brushes"));
await custom.load();
await custom.save({ "@type": BRUSH_PRESET_TYPE, id: crypto.randomUUID(), name: "My brush",
author: { name: "Ada", handle }, content: { width: 10 } });

Extends​

  • EventTarget

Constructors​

Constructor​

new default(store?, author?): CustomPresets

Defined in: src/lib/classes/CustomPresets/index.ts:67

Parameters​

store?​

AssetStoreLike<BrushPreset>

where the presets are kept

author?​

() => AssetAuthor

gives the author of presets of version 1 with none (default UNKNOWN_AUTHOR)

Returns​

CustomPresets

Overrides​

EventTarget.constructor

Properties​

presets​

presets: BrushPreset[] = []

Defined in: src/lib/classes/CustomPresets/index.ts:56

Presets, in the order they were added

Methods​

addEventListener()​

addEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14380

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | AddEventListenerOptions

Returns​

void

Inherited from​

EventTarget.addEventListener


dispatchEvent()​

dispatchEvent(event): boolean

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14386

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

MDN Reference

Parameters​

event​

Event

Returns​

boolean

Inherited from​

EventTarget.dispatchEvent


findOwn()​

findOwn(name, handle, unknownName?): BrushPreset | undefined

Defined in: src/lib/classes/CustomPresets/index.ts:122

One of the user's own presets with a name (ignoring case), to ask before replacing it.

Parameters​

name​

string

handle​

string

the user's handle (empty if they have none)

unknownName?​

string

the author name of presets made by a user without a handle (see isOwnAuthor)

Returns​

BrushPreset | undefined


get()​

get(id): BrushPreset | undefined

Defined in: src/lib/classes/CustomPresets/index.ts:112

A preset by ID.

Parameters​

id​

string

Returns​

BrushPreset | undefined


load()​

load(): Promise<void>

Defined in: src/lib/classes/CustomPresets/index.ts:96

Load the user's presets from the store, upgrading ones of version 1 (and saving them again) and leaving out invalid ones.

Returns​

Promise<void>


remove()​

remove(id): Promise<void>

Defined in: src/lib/classes/CustomPresets/index.ts:154

Delete a preset.

Parameters​

id​

string

Returns​

Promise<void>


removeEventListener()​

removeEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14392

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | EventListenerOptions

Returns​

void

Inherited from​

EventTarget.removeEventListener


save()​

save(...presets): Promise<void>

Defined in: src/lib/classes/CustomPresets/index.ts:138

Add presets, replacing any with the same ID, and keep them.

Parameters​

presets​

...BrushPreset[]

Returns​

Promise<void>


useStore()​

useStore(store): Promise<void>

Defined in: src/lib/classes/CustomPresets/index.ts:83

Keep the presets in another store (or in memory only, without one), loading the presets saved there in place of the current ones.

Parameters​

store​

AssetStoreLike<BrushPreset> | undefined

Returns​

Promise<void>

Example​

await custom.useStore(new IndexedDbAssetStore("brushes", "my-app"));