@nmmty/lazycanvas 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/ReadMe.md +20 -0
- package/dist/helpers/Fonts.d.ts +7 -0
- package/dist/helpers/Fonts.js +32 -0
- package/dist/helpers/filters.d.ts +68 -0
- package/dist/helpers/filters.js +91 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +39 -0
- package/dist/structures/LazyCanvas.d.ts +41 -0
- package/dist/structures/LazyCanvas.js +84 -0
- package/dist/structures/components/BaseLayer.d.ts +81 -0
- package/dist/structures/components/BaseLayer.js +157 -0
- package/dist/structures/components/Group.d.ts +50 -0
- package/dist/structures/components/Group.js +87 -0
- package/dist/structures/components/ImageLayer.d.ts +24 -0
- package/dist/structures/components/ImageLayer.js +106 -0
- package/dist/structures/components/MorphLayer.d.ts +39 -0
- package/dist/structures/components/MorphLayer.js +140 -0
- package/dist/structures/components/TextLayer.d.ts +69 -0
- package/dist/structures/components/TextLayer.js +225 -0
- package/dist/structures/helpers/Font.d.ts +35 -0
- package/dist/structures/helpers/Font.js +65 -0
- package/dist/structures/helpers/Gradient.d.ts +29 -0
- package/dist/structures/helpers/Gradient.js +72 -0
- package/dist/structures/helpers/Pattern.d.ts +24 -0
- package/dist/structures/helpers/Pattern.js +76 -0
- package/dist/structures/managers/FontsManager.d.ts +75 -0
- package/dist/structures/managers/FontsManager.js +150 -0
- package/dist/structures/managers/LayersManager.d.ts +71 -0
- package/dist/structures/managers/LayersManager.js +119 -0
- package/dist/structures/managers/RenderManager.d.ts +14 -0
- package/dist/structures/managers/RenderManager.js +44 -0
- package/dist/types/LazyCanvas.d.ts +16 -0
- package/dist/types/components/BaseLayer.d.ts +48 -0
- package/dist/types/components/Group.d.ts +6 -0
- package/dist/types/components/ImageLayer.d.ts +15 -0
- package/dist/types/components/MorphLayer.d.ts +14 -0
- package/dist/types/components/TextLayer.d.ts +26 -0
- package/dist/types/enum.d.ts +88 -0
- package/dist/types/enum.js +104 -0
- package/dist/types/helpers/Font.d.ts +12 -0
- package/dist/types/helpers/Gradient.d.ts +19 -0
- package/dist/types/helpers/Pattern.d.ts +7 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/managers/FontsManager.d.ts +5 -0
- package/dist/types/managers/LayersManager.d.ts +6 -0
- package/dist/types/managers/RenderManager.d.ts +5 -0
- package/dist/types/types.d.ts +12 -0
- package/dist/utils/LazyUtil.d.ts +7 -0
- package/dist/utils/LazyUtil.js +27 -0
- package/dist/utils/utils.d.ts +39 -0
- package/dist/utils/utils.js +261 -0
- package/package.json +51 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Group = void 0;
|
|
4
|
+
const enum_1 = require("../../types/enum");
|
|
5
|
+
const utils_1 = require("../../utils/utils");
|
|
6
|
+
class Group {
|
|
7
|
+
id;
|
|
8
|
+
visible;
|
|
9
|
+
zIndex;
|
|
10
|
+
components;
|
|
11
|
+
constructor() {
|
|
12
|
+
this.id = (0, utils_1.generateID)(enum_1.LayerType.Group);
|
|
13
|
+
this.visible = true;
|
|
14
|
+
this.zIndex = 1;
|
|
15
|
+
this.components = [];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Set the ID of the group
|
|
19
|
+
* @param id {string} - The `id` of the group
|
|
20
|
+
*/
|
|
21
|
+
setID(id) {
|
|
22
|
+
this.id = id;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Set the visibility of the group
|
|
27
|
+
* @param visible {boolean} - The `visibility` of the group
|
|
28
|
+
*/
|
|
29
|
+
setVisible(visible) {
|
|
30
|
+
this.visible = visible;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set the zIndex of the group
|
|
35
|
+
* @param zIndex {number} - The `zIndex` of the group
|
|
36
|
+
*/
|
|
37
|
+
setZIndex(zIndex) {
|
|
38
|
+
this.zIndex = zIndex;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Add a component to the group
|
|
43
|
+
* @param components {any[]} - The `components` to add to the group
|
|
44
|
+
*/
|
|
45
|
+
add(...components) {
|
|
46
|
+
let layersArray = components.flat();
|
|
47
|
+
layersArray = layersArray.filter(l => l !== undefined);
|
|
48
|
+
layersArray = layersArray.sort((a, b) => a.zIndex - b.zIndex);
|
|
49
|
+
this.components.push(...layersArray);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Remove a component from the group
|
|
54
|
+
* @param id {any} - The `id` of the component to remove
|
|
55
|
+
*/
|
|
56
|
+
remove(id) {
|
|
57
|
+
this.components = this.components.filter(c => c.id !== id);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Clear all components from the group
|
|
62
|
+
*/
|
|
63
|
+
clear() {
|
|
64
|
+
this.components = [];
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get a component from the group
|
|
69
|
+
* @param id {string} - The `id` of the component to get
|
|
70
|
+
*/
|
|
71
|
+
get(id) {
|
|
72
|
+
return this.components.find(c => c.id === id);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get all components from the group
|
|
76
|
+
*/
|
|
77
|
+
getAll() {
|
|
78
|
+
return this.components;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the length of the components
|
|
82
|
+
*/
|
|
83
|
+
get length() {
|
|
84
|
+
return this.components.length;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.Group = Group;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BaseLayer } from "./BaseLayer";
|
|
2
|
+
import { IImageLayer, IImageLayerProps, ScaleType } from "../../types";
|
|
3
|
+
import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
4
|
+
export declare class ImageLayer extends BaseLayer<IImageLayerProps> {
|
|
5
|
+
props: IImageLayerProps;
|
|
6
|
+
constructor(props?: IImageLayerProps);
|
|
7
|
+
/**
|
|
8
|
+
* @description Sets the source of the image, it can be like link to website or path to file.
|
|
9
|
+
* @param src {string} - The `src` of the image.
|
|
10
|
+
*/
|
|
11
|
+
setSrc(src: string): this;
|
|
12
|
+
/**
|
|
13
|
+
* @description Set the size of the image. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
14
|
+
* @param width {ScaleType} - The `width` of the image.
|
|
15
|
+
* @param height {ScaleType} - The `height` of the image.
|
|
16
|
+
* @param radius {ScaleType} - The `radius` of the image. (optional)
|
|
17
|
+
*/
|
|
18
|
+
setSize(width: ScaleType, height: ScaleType, radius?: ScaleType): this;
|
|
19
|
+
draw(ctx: SKRSContext2D, canvas: Canvas): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* @returns {IImageLayer}
|
|
22
|
+
*/
|
|
23
|
+
toJSON(): IImageLayer;
|
|
24
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ImageLayer = void 0;
|
|
27
|
+
const BaseLayer_1 = require("./BaseLayer");
|
|
28
|
+
const enum_1 = require("../../types/enum");
|
|
29
|
+
const canvas_1 = require("@napi-rs/canvas");
|
|
30
|
+
const utils_1 = require("../../utils/utils");
|
|
31
|
+
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
32
|
+
const jimp = __importStar(require("jimp"));
|
|
33
|
+
class ImageLayer extends BaseLayer_1.BaseLayer {
|
|
34
|
+
props;
|
|
35
|
+
constructor(props) {
|
|
36
|
+
super(enum_1.LayerType.Image, props);
|
|
37
|
+
this.props = props ? props : {};
|
|
38
|
+
this.props.centring = enum_1.Centring.Center;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @description Sets the source of the image, it can be like link to website or path to file.
|
|
42
|
+
* @param src {string} - The `src` of the image.
|
|
43
|
+
*/
|
|
44
|
+
setSrc(src) {
|
|
45
|
+
if (!(0, utils_1.isImageUrlValid)(src))
|
|
46
|
+
throw new LazyUtil_1.LazyError('The src of the image must be a valid URL');
|
|
47
|
+
this.props.src = src;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @description Set the size of the image. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
52
|
+
* @param width {ScaleType} - The `width` of the image.
|
|
53
|
+
* @param height {ScaleType} - The `height` of the image.
|
|
54
|
+
* @param radius {ScaleType} - The `radius` of the image. (optional)
|
|
55
|
+
*/
|
|
56
|
+
setSize(width, height, radius) {
|
|
57
|
+
this.props.size = {
|
|
58
|
+
width: width,
|
|
59
|
+
height: height,
|
|
60
|
+
radius: radius || 0,
|
|
61
|
+
};
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
async draw(ctx, canvas) {
|
|
65
|
+
let xs = (0, utils_1.parseToNormal)(this.props.x, canvas);
|
|
66
|
+
let ys = (0, utils_1.parseToNormal)(this.props.y, canvas, { width: 0, height: 0 }, { vertical: true });
|
|
67
|
+
let w = (0, utils_1.parseToNormal)(this.props.size.width, canvas);
|
|
68
|
+
let h = (0, utils_1.parseToNormal)(this.props.size.height, canvas, { width: w, height: 0 }, { vertical: true });
|
|
69
|
+
let r = (0, utils_1.parseToNormal)(this.props.size.radius, canvas, { width: w, height: h }, { layer: true });
|
|
70
|
+
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
71
|
+
ctx.save();
|
|
72
|
+
(0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
|
|
73
|
+
(0, utils_1.drawShadow)(ctx, this.props.shadow);
|
|
74
|
+
(0, utils_1.opacity)(ctx, this.props.opacity);
|
|
75
|
+
(0, utils_1.filters)(ctx, this.props.filter);
|
|
76
|
+
let jmp = await jimp.read(this.props.src);
|
|
77
|
+
jmp.resize(w, h);
|
|
78
|
+
let image = await (0, canvas_1.loadImage)(await jmp.getBufferAsync('image/png'));
|
|
79
|
+
if (!image)
|
|
80
|
+
throw new LazyUtil_1.LazyError('The image could not be loaded');
|
|
81
|
+
if (r) {
|
|
82
|
+
ctx.beginPath();
|
|
83
|
+
ctx.moveTo(x + (w / 2), y);
|
|
84
|
+
ctx.arcTo(x + w, y, x + w, y + (h / 2), r);
|
|
85
|
+
ctx.arcTo(x + w, y + h, x + (w / 2), y + h, r);
|
|
86
|
+
ctx.arcTo(x, y + h, x, y + (h / 2), r);
|
|
87
|
+
ctx.arcTo(x, y, x + (w / 2), y, r);
|
|
88
|
+
ctx.closePath();
|
|
89
|
+
ctx.clip();
|
|
90
|
+
ctx.drawImage(image, x, y, w, h);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
ctx.drawImage(image, x, y, w, h);
|
|
94
|
+
}
|
|
95
|
+
ctx.restore();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @returns {IImageLayer}
|
|
99
|
+
*/
|
|
100
|
+
toJSON() {
|
|
101
|
+
let data = super.toJSON();
|
|
102
|
+
data.props = this.props;
|
|
103
|
+
return { ...data };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.ImageLayer = ImageLayer;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BaseLayer } from "./BaseLayer";
|
|
2
|
+
import { IMorphLayer, IMorphLayerProps, ColorType, ScaleType } from "../../types";
|
|
3
|
+
import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
4
|
+
export declare class MorphLayer extends BaseLayer<IMorphLayerProps> {
|
|
5
|
+
props: IMorphLayerProps;
|
|
6
|
+
constructor(props?: IMorphLayerProps);
|
|
7
|
+
/**
|
|
8
|
+
* @description Sets size of the morph layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
9
|
+
* @param width {ScaleType} - The `width` of the morph layer.
|
|
10
|
+
* @param height {ScaleType} - The `height` of the morph layer.
|
|
11
|
+
* @param radius {ScaleType} - The `radius` of the morph layer. (optional)
|
|
12
|
+
*/
|
|
13
|
+
setSize(width: ScaleType, height: ScaleType, radius?: ScaleType): this;
|
|
14
|
+
/**
|
|
15
|
+
* @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
|
|
16
|
+
* @param color {string} - The `color` of the layer.
|
|
17
|
+
*/
|
|
18
|
+
setColor(color: ColorType): this;
|
|
19
|
+
/**
|
|
20
|
+
* @description Sets the stroke of the layer.
|
|
21
|
+
* @param width {number} - The `width` of the stroke.
|
|
22
|
+
* @param cap {string} - The `cap` of the stroke.
|
|
23
|
+
* @param join {string} - The `join` of the stroke.
|
|
24
|
+
* @param dash {number[]} - The `dash` of the stroke.
|
|
25
|
+
* @param dashOffset {number} - The `dashOffset` of the stroke.
|
|
26
|
+
* @param miterLimit {number} - The `miterLimit` of the stroke.
|
|
27
|
+
*/
|
|
28
|
+
setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
|
|
29
|
+
/**
|
|
30
|
+
* @description Sets the fills of the layer. If `true` the layer will be filled, if `false` the layer will be stroked.
|
|
31
|
+
* @param filled {boolean} - The `filled` of the layer.
|
|
32
|
+
*/
|
|
33
|
+
setFilled(filled: boolean): this;
|
|
34
|
+
draw(ctx: SKRSContext2D, canvas: Canvas): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* @returns {IMorphLayer}
|
|
37
|
+
*/
|
|
38
|
+
toJSON(): IMorphLayer;
|
|
39
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MorphLayer = void 0;
|
|
4
|
+
const BaseLayer_1 = require("./BaseLayer");
|
|
5
|
+
const enum_1 = require("../../types/enum");
|
|
6
|
+
const utils_1 = require("../../utils/utils");
|
|
7
|
+
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
8
|
+
const Gradient_1 = require("../helpers/Gradient");
|
|
9
|
+
const Pattern_1 = require("../helpers/Pattern");
|
|
10
|
+
class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
11
|
+
props;
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super(enum_1.LayerType.Morph, props);
|
|
14
|
+
this.props = props ? props : {};
|
|
15
|
+
if (!this.props.fillStyle)
|
|
16
|
+
this.props.fillStyle = '#000000';
|
|
17
|
+
if (!this.props.filled && this.props.filled !== false)
|
|
18
|
+
this.props.filled = true;
|
|
19
|
+
this.props.centring = enum_1.Centring.Center;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @description Sets size of the morph layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
23
|
+
* @param width {ScaleType} - The `width` of the morph layer.
|
|
24
|
+
* @param height {ScaleType} - The `height` of the morph layer.
|
|
25
|
+
* @param radius {ScaleType} - The `radius` of the morph layer. (optional)
|
|
26
|
+
*/
|
|
27
|
+
setSize(width, height, radius) {
|
|
28
|
+
this.props.size = {
|
|
29
|
+
width: width,
|
|
30
|
+
height: height,
|
|
31
|
+
radius: radius || 0,
|
|
32
|
+
};
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
|
|
37
|
+
* @param color {string} - The `color` of the layer.
|
|
38
|
+
*/
|
|
39
|
+
setColor(color) {
|
|
40
|
+
if (!color)
|
|
41
|
+
throw new LazyUtil_1.LazyError('The color of the layer must be provided');
|
|
42
|
+
if (!(0, utils_1.isColor)(color))
|
|
43
|
+
throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
|
|
44
|
+
let fill = (0, utils_1.parseColor)(color);
|
|
45
|
+
if (fill instanceof Gradient_1.Gradient || fill instanceof Pattern_1.Pattern) {
|
|
46
|
+
this.props.fillStyle = fill;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
let arr = fill.split(':');
|
|
50
|
+
this.props.fillStyle = arr[0];
|
|
51
|
+
this.props.opacity = parseFloat(arr[1]) || 1;
|
|
52
|
+
}
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @description Sets the stroke of the layer.
|
|
57
|
+
* @param width {number} - The `width` of the stroke.
|
|
58
|
+
* @param cap {string} - The `cap` of the stroke.
|
|
59
|
+
* @param join {string} - The `join` of the stroke.
|
|
60
|
+
* @param dash {number[]} - The `dash` of the stroke.
|
|
61
|
+
* @param dashOffset {number} - The `dashOffset` of the stroke.
|
|
62
|
+
* @param miterLimit {number} - The `miterLimit` of the stroke.
|
|
63
|
+
*/
|
|
64
|
+
setStroke(width, cap, join, dash, dashOffset, miterLimit) {
|
|
65
|
+
this.props.stroke = {
|
|
66
|
+
width,
|
|
67
|
+
cap: cap || 'butt',
|
|
68
|
+
join: join || 'miter',
|
|
69
|
+
dash: dash || [],
|
|
70
|
+
dashOffset: dashOffset || 0,
|
|
71
|
+
miterLimit: miterLimit || 10,
|
|
72
|
+
};
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @description Sets the fills of the layer. If `true` the layer will be filled, if `false` the layer will be stroked.
|
|
77
|
+
* @param filled {boolean} - The `filled` of the layer.
|
|
78
|
+
*/
|
|
79
|
+
setFilled(filled) {
|
|
80
|
+
this.props.filled = filled;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
async draw(ctx, canvas) {
|
|
84
|
+
const xs = (0, utils_1.parseToNormal)(this.props.x, canvas);
|
|
85
|
+
const ys = (0, utils_1.parseToNormal)(this.props.y, canvas, { width: 0, height: 0 }, { vertical: true });
|
|
86
|
+
const w = (0, utils_1.parseToNormal)(this.props.size.width, canvas);
|
|
87
|
+
const h = (0, utils_1.parseToNormal)(this.props.size.height, canvas, { width: w, height: 0 }, { vertical: true });
|
|
88
|
+
const r = (0, utils_1.parseToNormal)(this.props.size.radius, canvas, { width: w, height: h }, { layer: true });
|
|
89
|
+
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
90
|
+
ctx.save();
|
|
91
|
+
(0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
|
|
92
|
+
ctx.beginPath();
|
|
93
|
+
if (r) {
|
|
94
|
+
ctx.moveTo(x + (w / 2), y);
|
|
95
|
+
ctx.arcTo(x + w, y, x + w, y + (h / 2), r);
|
|
96
|
+
ctx.arcTo(x + w, y + h, x + (w / 2), y + h, r);
|
|
97
|
+
ctx.arcTo(x, y + h, x, y + (h / 2), r);
|
|
98
|
+
ctx.arcTo(x, y, x + (w / 2), y, r);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
ctx.rect(x, y, w, h);
|
|
102
|
+
}
|
|
103
|
+
ctx.closePath();
|
|
104
|
+
(0, utils_1.drawShadow)(ctx, this.props.shadow);
|
|
105
|
+
(0, utils_1.opacity)(ctx, this.props.opacity);
|
|
106
|
+
(0, utils_1.filters)(ctx, this.props.filter);
|
|
107
|
+
let base = (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
|
|
108
|
+
let fillStyle;
|
|
109
|
+
if (base instanceof Promise) {
|
|
110
|
+
fillStyle = await base;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
fillStyle = base;
|
|
114
|
+
}
|
|
115
|
+
if (this.props.filled) {
|
|
116
|
+
ctx.fillStyle = fillStyle;
|
|
117
|
+
ctx.fill();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
ctx.strokeStyle = fillStyle;
|
|
121
|
+
ctx.lineWidth = this.props.stroke?.width || 1;
|
|
122
|
+
ctx.lineCap = this.props.stroke?.cap || 'butt';
|
|
123
|
+
ctx.lineJoin = this.props.stroke?.join || 'miter';
|
|
124
|
+
ctx.miterLimit = this.props.stroke?.miterLimit || 10;
|
|
125
|
+
ctx.lineDashOffset = this.props.stroke?.dashOffset || 0;
|
|
126
|
+
ctx.setLineDash(this.props.stroke?.dash || []);
|
|
127
|
+
ctx.stroke();
|
|
128
|
+
}
|
|
129
|
+
ctx.restore();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @returns {IMorphLayer}
|
|
133
|
+
*/
|
|
134
|
+
toJSON() {
|
|
135
|
+
let data = super.toJSON();
|
|
136
|
+
data.props = this.props;
|
|
137
|
+
return { ...data };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.MorphLayer = MorphLayer;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BaseLayer } from "./BaseLayer";
|
|
2
|
+
import { FontWeight, LineCap, LineJoin, TextAlign, TextBaseline, TextDirection } from "../../types/enum";
|
|
3
|
+
import { ITextLayer, ITextLayerProps, ScaleType, ColorType } from "../../types";
|
|
4
|
+
import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
5
|
+
export declare class TextLayer extends BaseLayer<ITextLayerProps> {
|
|
6
|
+
props: ITextLayerProps;
|
|
7
|
+
constructor(props?: ITextLayerProps);
|
|
8
|
+
/**
|
|
9
|
+
* @description Sets the text of the text layer.
|
|
10
|
+
* @param text {string} - The `text` of the text layer.
|
|
11
|
+
*/
|
|
12
|
+
setText(text: string): this;
|
|
13
|
+
/**
|
|
14
|
+
* @description Set the font of the text layer. You can use `Geist` and `GeistMono`, or you can upload your own font from file/base64 buffer.
|
|
15
|
+
* @param family {string} - The `family` of the font.
|
|
16
|
+
* @param size {number} - The `size` of the font.
|
|
17
|
+
* @param weight {FontWeight} - The `weight` of the font.
|
|
18
|
+
*/
|
|
19
|
+
setFont(family: string, size: number, weight: FontWeight): this;
|
|
20
|
+
/**
|
|
21
|
+
* @description Set the multiline of the text layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
22
|
+
* @param enabled {boolean} - Whether the text is multiline.
|
|
23
|
+
* @param width {ScaleType} - width of "window" the multiline text. Can be used in one line text for text max width.
|
|
24
|
+
* @param height {ScaleType} - height of "window" the multiline text.
|
|
25
|
+
* @param spacing {number} - The space between the lines.
|
|
26
|
+
*/
|
|
27
|
+
setMultiline(enabled: boolean, width: ScaleType, height: ScaleType, spacing?: number): this;
|
|
28
|
+
/**
|
|
29
|
+
* @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
|
|
30
|
+
* @param color {string} - The `color` of the layer.
|
|
31
|
+
*/
|
|
32
|
+
setColor(color: ColorType): this;
|
|
33
|
+
/**
|
|
34
|
+
* @description Set the align of the text layer.
|
|
35
|
+
* @param align {TextAlign} - The `align` of the text layer.
|
|
36
|
+
*/
|
|
37
|
+
setAlign(align: TextAlign): this;
|
|
38
|
+
/**
|
|
39
|
+
* @description Set the baseline of the text layer.
|
|
40
|
+
* @param baseline {TextBaseline} - The `baseline` of the text layer.
|
|
41
|
+
*/
|
|
42
|
+
setBaseline(baseline: TextBaseline): this;
|
|
43
|
+
/**
|
|
44
|
+
* @description Set the direction of the text layer.
|
|
45
|
+
* @param direction {TextDirection} - The `direction` of the text layer.
|
|
46
|
+
*/
|
|
47
|
+
setDirection(direction: TextDirection): this;
|
|
48
|
+
/**
|
|
49
|
+
* @description Set the stroke of the layer.
|
|
50
|
+
* @param width {number} - The `width` of the stroke.
|
|
51
|
+
* @param cap {string} - The `cap` of the stroke.
|
|
52
|
+
* @param join {string} - The `join` of the stroke.
|
|
53
|
+
* @param dash {number[]} - The `dash` of the stroke.
|
|
54
|
+
* @param dashOffset {number} - The `dashOffset` of the stroke.
|
|
55
|
+
* @param miterLimit {number} - The `miterLimit` of the stroke.
|
|
56
|
+
*/
|
|
57
|
+
setStroke(width: number, cap?: LineCap, join?: LineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
|
|
58
|
+
/**
|
|
59
|
+
* @description Sets the fills of the layer. If `true` the layer will be filled, if `false` the layer will be stroked.
|
|
60
|
+
* @param filled {boolean} - The `filled` of the layer.
|
|
61
|
+
*/
|
|
62
|
+
setFilled(filled: boolean): this;
|
|
63
|
+
draw(ctx: SKRSContext2D, canvas: Canvas): Promise<void>;
|
|
64
|
+
private drawText;
|
|
65
|
+
/**
|
|
66
|
+
* @returns {ITextLayer}
|
|
67
|
+
*/
|
|
68
|
+
toJSON(): ITextLayer;
|
|
69
|
+
}
|