Class: default
Defined in: src/lib/classes/ColourPalettes/index.ts:100
The user's own colour palettes, each named and with its own colours (as lowercase #rrggbb, each once, up to
MAX_PALETTE_COLOURS), alongside the palette PaintCanvas comes with (the canvas's palette). Kept in memory; a
palette store keeps them (see PaintCanvas.useAssetStores).
Dispatches a change event when the palettes change.
Example
const palettes = new ColourPalettes();
const sunset = palettes.create("Sunset");
palettes.addColour(sunset.id, "#ff7700");
Extends
EventTarget
Constructors
Constructor
new default():
ColourPalettes
Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14397
Returns
ColourPalettes
Inherited from
EventTarget.constructor
Accessors
items
Get Signature
get items(): readonly
ColourPalette[]
Defined in: src/lib/classes/ColourPalettes/index.ts:104
The palettes, in the order they were made
Returns
readonly ColourPalette[]
Methods
addColour()
addColour(
id,colour):boolean
Defined in: src/lib/classes/ColourPalettes/index.ts:165
Add a colour at the end of a palette. Returns whether it was added: not if it's already there, the palette is full,
or it isn't a #rrggbb colour.
Parameters
id
string
colour
string
Returns
boolean
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.
Parameters
type
string
callback
EventListenerOrEventListenerObject | null
options?
boolean | AddEventListenerOptions
Returns
void
Inherited from
EventTarget.addEventListener
create()
create(
name,colours?,author?):ColourPalette|undefined
Defined in: src/lib/classes/ColourPalettes/index.ts:120
Make a palette with a name (trimmed) and colours, made now (updatedAt). Returns it, or undefined if the name isn't valid or there's no
room.
Parameters
name
string
colours?
readonly string[] = []
author?
AssetAuthor = UNKNOWN_AUTHOR
Returns
ColourPalette | undefined
Example
palettes.create("Sunset", ["#ff7700"], { name: "Ada" });
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().
Parameters
event
Event
Returns
boolean
Inherited from
EventTarget.dispatchEvent
get()
get(
id):ColourPalette|undefined
Defined in: src/lib/classes/ColourPalettes/index.ts:109
A palette by ID
Parameters
id
string
Returns
ColourPalette | undefined
merge()
merge(
palettes,author?):number
Defined in: src/lib/classes/ColourPalettes/index.ts:197
Add palettes (e.g. loaded from a store or imported), replacing the ones with the same IDs and keeping the others,
up to MAX_SAVED_PALETTES. Invalid palettes are left out (see sanitiseColourPalettes). Returns how many were
added or replaced.
Parameters
palettes
unknown
author?
the author of palettes with none (e.g. older ones)
Returns
number
Example
palettes.merge(colourPaletteFile.parse(text));
remove()
remove(
id):boolean
Defined in: src/lib/classes/ColourPalettes/index.ts:154
Delete a palette. Returns whether it was deleted.
Parameters
id
string
Returns
boolean
removeColour()
removeColour(
id,index):boolean
Defined in: src/lib/classes/ColourPalettes/index.ts:179
Remove the colour at a position in a palette. Returns whether it was removed.
Parameters
id
string
index
number
Returns
boolean
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.
Parameters
type
string
callback
EventListenerOrEventListenerObject | null
options?
boolean | EventListenerOptions
Returns
void
Inherited from
EventTarget.removeEventListener
rename()
rename(
id,name):boolean
Defined in: src/lib/classes/ColourPalettes/index.ts:146
Rename a palette. Returns whether it was renamed.
Parameters
id
string
name
string
Returns
boolean
set()
set(
palettes,author?):void
Defined in: src/lib/classes/ColourPalettes/index.ts:213
Replace all the palettes (e.g. when restoring saved ones), keeping only valid ones.
Parameters
palettes
unknown
author?
the author of palettes with none (e.g. older ones)
Returns
void