src/toolbox/filters/Filter.ts
Properties |
Methods |
|
| Public autoClear |
Default value : false
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:9
|
| Public history |
Type : HistoryCallback[]
|
Default value : []
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:8
|
| Public Readonly layer |
Type : Layer
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:9
|
| Public applyFilter | ||||||
applyFilter(filters: FilterArgs[])
|
||||||
|
Defined in src/toolbox/filters/Filter.ts:6
|
||||||
|
Parameters :
Returns :
this
|
| Public brightness | ||||||
brightness(amount: number)
|
||||||
|
Defined in src/toolbox/filters/Filter.ts:24
|
||||||
|
Parameters :
Returns :
this
|
| Public contrast | ||||||
contrast(amount: number)
|
||||||
|
Defined in src/toolbox/filters/Filter.ts:34
|
||||||
|
Parameters :
Returns :
this
|
| Public dropShadow | |||||||||||||||
dropShadow(x: string | number, y: string | number, radius: number, color: string)
|
|||||||||||||||
|
Defined in src/toolbox/filters/Filter.ts:44
|
|||||||||||||||
|
Parameters :
Returns :
this
|
| Public gaussianBlur | ||||||||
gaussianBlur(amount: number)
|
||||||||
|
Defined in src/toolbox/filters/Filter.ts:14
|
||||||||
|
Parameters :
Returns :
this
|
| Public grayscale | ||||||||
grayscale(amount: number)
|
||||||||
|
Defined in src/toolbox/filters/Filter.ts:53
|
||||||||
|
Parameters :
Returns :
this
|
| Public hueRotate | ||||||
hueRotate(angle: number)
|
||||||
|
Defined in src/toolbox/filters/Filter.ts:63
|
||||||
|
Parameters :
Returns :
this
|
| Public invert | ||||||||
invert(amount: number)
|
||||||||
|
Defined in src/toolbox/filters/Filter.ts:73
|
||||||||
|
Parameters :
Returns :
this
|
| Public opacity | ||||||
opacity(amount: number)
|
||||||
|
Defined in src/toolbox/filters/Filter.ts:83
|
||||||
|
Parameters :
Returns :
this
|
| Public saturate | ||||||
saturate(amount: number)
|
||||||
|
Defined in src/toolbox/filters/Filter.ts:93
|
||||||
|
Parameters :
Returns :
this
|
| Public sepia | ||||||||
sepia(amount: number)
|
||||||||
|
Defined in src/toolbox/filters/Filter.ts:103
|
||||||||
|
Parameters :
Returns :
this
|
| Public render |
render()
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:27
|
|
Returns :
void
|
| Public restore |
restore()
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:19
|
|
Returns :
this
|
| Public save |
save()
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:11
|
|
Returns :
this
|
import { ToolBox } from "../base/ToolBox";
export type FilterArgs = { name: string; value: string | number };
export class FilterTool extends ToolBox {
public applyFilter(filters: FilterArgs[]) {
if (!Array.isArray(filters) || !filters.length) return this;
this.history.push((ctx) => {
ctx.filter = filters.map((m) => `${m.name}(${m.value})`).join(" ");
});
return this;
}
public gaussianBlur(amount = 1) {
if (typeof amount !== "number") throw new TypeError("gaussian blur amount must be a number");
return this.applyFilter([
{
name: "blur",
value: amount
}
]);
}
public brightness(amount: number) {
if (typeof amount !== "number") throw new TypeError("brightness amount must be a number");
return this.applyFilter([
{
name: "brightness",
value: `${amount}%`
}
]);
}
public contrast(amount: number) {
if (typeof amount !== "number") throw new TypeError("contrast amount must be a number");
return this.applyFilter([
{
name: "contrast",
value: `${amount}%`
}
]);
}
public dropShadow(x: string | number, y: string | number, radius: number, color: string) {
return this.applyFilter([
{
name: "drop-shadow",
value: `${x} ${y} ${radius} ${color}`
}
]);
}
public grayscale(amount = 100) {
if (typeof amount !== "number") throw new TypeError("grayscale amount must be a number");
return this.applyFilter([
{
name: "grayscale",
value: `${amount}%`
}
]);
}
public hueRotate(angle: number) {
if (typeof angle !== "number") throw new TypeError("hue rotate angle must be a number");
return this.applyFilter([
{
name: "hue-rotate",
value: `${angle}deg`
}
]);
}
public invert(amount = 100) {
if (typeof amount !== "number") throw new TypeError("invert amount must be a number");
return this.applyFilter([
{
name: "invert",
value: `${amount}%`
}
]);
}
public opacity(amount: number) {
if (typeof amount !== "number") throw new TypeError("opacity amount must be a number");
return this.applyFilter([
{
name: "opacity",
value: `${amount}%`
}
]);
}
public saturate(amount: number) {
if (typeof amount !== "number") throw new TypeError("saturation amount must be a number");
return this.applyFilter([
{
name: "saturate",
value: `${amount}%`
}
]);
}
public sepia(amount = 100) {
if (typeof amount !== "number") throw new TypeError("sepia amount must be a number");
return this.applyFilter([
{
name: "sepia",
value: `${amount}%`
}
]);
}
}