illustrator.js
Version:
JavaScript image processing library
114 lines (113 loc) • 3.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FilterTool = void 0;
const ToolBox_1 = require("../base/ToolBox");
class FilterTool extends ToolBox_1.ToolBox {
applyFilter(filters) {
if (!Array.isArray(filters) || !filters.length)
return this;
this.history.push((ctx) => {
ctx.filter = filters.map((m) => `${m.name}(${m.value})`).join(" ");
});
return this;
}
gaussianBlur(amount = 1) {
if (typeof amount !== "number")
throw new TypeError("gaussian blur amount must be a number");
return this.applyFilter([
{
name: "blur",
value: amount
}
]);
}
brightness(amount) {
if (typeof amount !== "number")
throw new TypeError("brightness amount must be a number");
return this.applyFilter([
{
name: "brightness",
value: `${amount}%`
}
]);
}
contrast(amount) {
if (typeof amount !== "number")
throw new TypeError("contrast amount must be a number");
return this.applyFilter([
{
name: "contrast",
value: `${amount}%`
}
]);
}
dropShadow(x, y, radius, color) {
return this.applyFilter([
{
name: "drop-shadow",
value: `${x} ${y} ${radius} ${color}`
}
]);
}
grayscale(amount = 100) {
if (typeof amount !== "number")
throw new TypeError("grayscale amount must be a number");
return this.applyFilter([
{
name: "grayscale",
value: `${amount}%`
}
]);
}
hueRotate(angle) {
if (typeof angle !== "number")
throw new TypeError("hue rotate angle must be a number");
return this.applyFilter([
{
name: "hue-rotate",
value: `${angle}deg`
}
]);
}
invert(amount = 100) {
if (typeof amount !== "number")
throw new TypeError("invert amount must be a number");
return this.applyFilter([
{
name: "invert",
value: `${amount}%`
}
]);
}
opacity(amount) {
if (typeof amount !== "number")
throw new TypeError("opacity amount must be a number");
return this.applyFilter([
{
name: "opacity",
value: `${amount}%`
}
]);
}
saturate(amount) {
if (typeof amount !== "number")
throw new TypeError("saturation amount must be a number");
return this.applyFilter([
{
name: "saturate",
value: `${amount}%`
}
]);
}
sepia(amount = 100) {
if (typeof amount !== "number")
throw new TypeError("sepia amount must be a number");
return this.applyFilter([
{
name: "sepia",
value: `${amount}%`
}
]);
}
}
exports.FilterTool = FilterTool;