@nmmty/lazycanvas 0.3.1 → 0.3.2
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/dist/helpers/filters.d.ts +1 -1
- package/dist/helpers/filters.js +1 -1
- package/dist/structures/components/BaseLayer.d.ts +2 -2
- package/dist/structures/components/BaseLayer.js +3 -3
- package/dist/structures/components/BezierLayer.d.ts +1 -1
- package/dist/structures/components/BezierLayer.js +2 -2
- package/dist/structures/components/ImageLayer.js +1 -1
- package/dist/structures/components/LineLayer.d.ts +31 -0
- package/dist/structures/components/LineLayer.js +101 -0
- package/dist/structures/components/MorphLayer.js +1 -1
- package/dist/structures/components/QuadraticLayer.d.ts +1 -1
- package/dist/structures/components/QuadraticLayer.js +2 -2
- package/dist/structures/components/TextLayer.js +1 -1
- package/dist/types/components/LineLayer.d.ts +12 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/utils.js +1 -0
- package/example.png +0 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* List of CSS [`filters`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) that can be used with the `filter` property. Use this functions to `
|
|
2
|
+
* List of CSS [`filters`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) that can be used with the `filter` property. Use this functions to `setFilters` on the layer.
|
|
3
3
|
*/
|
|
4
4
|
export declare const Filters: {
|
|
5
5
|
/**
|
package/dist/helpers/filters.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Filters = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* List of CSS [`filters`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) that can be used with the `filter` property. Use this functions to `
|
|
5
|
+
* List of CSS [`filters`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) that can be used with the `filter` property. Use this functions to `setFilters` on the layer.
|
|
6
6
|
*/
|
|
7
7
|
exports.Filters = {
|
|
8
8
|
/**
|
|
@@ -56,9 +56,9 @@ export declare class BaseLayer<T extends IBaseLayerProps> {
|
|
|
56
56
|
/**
|
|
57
57
|
* @description The **`CanvasRenderingContext2D`**. filter property of the Canvas 2D API provides filter effects such as blurring and grayscaling.
|
|
58
58
|
* It is similar to the CSS [`filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) property and accepts the same values.
|
|
59
|
-
* @param filter {string} - The `filter` of the layer.
|
|
59
|
+
* @param filter {string} - The `filter` of the layer. Multiple filters are supported.
|
|
60
60
|
*/
|
|
61
|
-
|
|
61
|
+
setFilters(...filter: string[]): this;
|
|
62
62
|
/**
|
|
63
63
|
* @description Sets type of centring of the layer.
|
|
64
64
|
* @param centring {Centring} - The `centring` of the layer
|
|
@@ -111,10 +111,10 @@ class BaseLayer {
|
|
|
111
111
|
/**
|
|
112
112
|
* @description The **`CanvasRenderingContext2D`**. filter property of the Canvas 2D API provides filter effects such as blurring and grayscaling.
|
|
113
113
|
* It is similar to the CSS [`filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) property and accepts the same values.
|
|
114
|
-
* @param filter {string} - The `filter` of the layer.
|
|
114
|
+
* @param filter {string} - The `filter` of the layer. Multiple filters are supported.
|
|
115
115
|
*/
|
|
116
|
-
|
|
117
|
-
this.props.filter = filter;
|
|
116
|
+
setFilters(...filter) {
|
|
117
|
+
this.props.filter = filter.join(' ');
|
|
118
118
|
return this;
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
@@ -18,7 +18,7 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
|
|
|
18
18
|
* @param x {ScaleType} - The end `x` of the bezier layer.
|
|
19
19
|
* @param y {ScaleType} - The end `y` of the bezier layer.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
setEndPosition(x: ScaleType, y: ScaleType): this;
|
|
22
22
|
/**
|
|
23
23
|
* @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
|
|
24
24
|
* @param color {string} - The `color` of the layer.
|
|
@@ -10,7 +10,7 @@ const Pattern_1 = require("../helpers/Pattern");
|
|
|
10
10
|
class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
11
11
|
props;
|
|
12
12
|
constructor(props) {
|
|
13
|
-
super(enum_1.LayerType.BezierCurve, props);
|
|
13
|
+
super(enum_1.LayerType.BezierCurve, props || {});
|
|
14
14
|
this.props = props ? props : {};
|
|
15
15
|
if (!this.props.fillStyle)
|
|
16
16
|
this.props.fillStyle = '#000000';
|
|
@@ -31,7 +31,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
31
31
|
* @param x {ScaleType} - The end `x` of the bezier layer.
|
|
32
32
|
* @param y {ScaleType} - The end `y` of the bezier layer.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
setEndPosition(x, y) {
|
|
35
35
|
this.props.endPoint = { x, y };
|
|
36
36
|
return this;
|
|
37
37
|
}
|
|
@@ -33,7 +33,7 @@ const jimp = __importStar(require("jimp"));
|
|
|
33
33
|
class ImageLayer extends BaseLayer_1.BaseLayer {
|
|
34
34
|
props;
|
|
35
35
|
constructor(props) {
|
|
36
|
-
super(enum_1.LayerType.Image, props);
|
|
36
|
+
super(enum_1.LayerType.Image, props || {});
|
|
37
37
|
this.props = props ? props : {};
|
|
38
38
|
this.props.centring = enum_1.Centring.Center;
|
|
39
39
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseLayer } from "./BaseLayer";
|
|
2
|
+
import { ColorType, ILineLayer, ILineLayerProps, ScaleType } from "../../types/";
|
|
3
|
+
import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
4
|
+
import { LayersManager } from "../managers/LayersManager";
|
|
5
|
+
export declare class LineLayer extends BaseLayer<ILineLayerProps> {
|
|
6
|
+
props: ILineLayerProps;
|
|
7
|
+
constructor(props?: ILineLayerProps);
|
|
8
|
+
/**
|
|
9
|
+
* @description Sets the end point of the line layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
10
|
+
* @param x {ScaleType} - The end `x` of the line layer.
|
|
11
|
+
* @param y {ScaleType} - The end `y` of the line layer.
|
|
12
|
+
*/
|
|
13
|
+
setEndPosition(x: ScaleType, y: 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
|
+
draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
|
|
30
|
+
toJSON(): ILineLayer;
|
|
31
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LineLayer = void 0;
|
|
4
|
+
const BaseLayer_1 = require("./BaseLayer");
|
|
5
|
+
const enum_1 = require("../../types/enum");
|
|
6
|
+
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
7
|
+
const utils_1 = require("../../utils/utils");
|
|
8
|
+
const Gradient_1 = require("../helpers/Gradient");
|
|
9
|
+
const Pattern_1 = require("../helpers/Pattern");
|
|
10
|
+
class LineLayer extends BaseLayer_1.BaseLayer {
|
|
11
|
+
props;
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super(enum_1.LayerType.Line, props || {});
|
|
14
|
+
this.props = props ? props : {};
|
|
15
|
+
if (!this.props.fillStyle)
|
|
16
|
+
this.props.fillStyle = '#000000';
|
|
17
|
+
this.props.centring = enum_1.Centring.None;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @description Sets the end point of the line layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
21
|
+
* @param x {ScaleType} - The end `x` of the line layer.
|
|
22
|
+
* @param y {ScaleType} - The end `y` of the line layer.
|
|
23
|
+
*/
|
|
24
|
+
setEndPosition(x, y) {
|
|
25
|
+
this.props.endPoint = { x, y };
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
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) {
|
|
33
|
+
if (!color)
|
|
34
|
+
throw new LazyUtil_1.LazyError('The color of the layer must be provided');
|
|
35
|
+
if (!(0, utils_1.isColor)(color))
|
|
36
|
+
throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
|
|
37
|
+
let fill = (0, utils_1.parseColor)(color);
|
|
38
|
+
if (fill instanceof Gradient_1.Gradient || fill instanceof Pattern_1.Pattern) {
|
|
39
|
+
this.props.fillStyle = fill;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
let arr = fill.split(':');
|
|
43
|
+
this.props.fillStyle = arr[0];
|
|
44
|
+
this.props.opacity = parseFloat(arr[1]) || 1;
|
|
45
|
+
}
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @description Sets 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, cap, join, dash, dashOffset, miterLimit) {
|
|
58
|
+
this.props.stroke = {
|
|
59
|
+
width,
|
|
60
|
+
cap: cap || 'butt',
|
|
61
|
+
join: join || 'miter',
|
|
62
|
+
dash: dash || [],
|
|
63
|
+
dashOffset: dashOffset || 0,
|
|
64
|
+
miterLimit: miterLimit || 10,
|
|
65
|
+
};
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
async draw(ctx, canvas, manager, debug) {
|
|
69
|
+
const xs = (0, utils_1.parseToNormal)(this.props.x, ctx, canvas);
|
|
70
|
+
const ys = (0, utils_1.parseToNormal)(this.props.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
|
|
71
|
+
const xe = (0, utils_1.parseToNormal)(this.props.endPoint.x, ctx, canvas);
|
|
72
|
+
const ye = (0, utils_1.parseToNormal)(this.props.endPoint.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
|
|
73
|
+
let width = xe - xs;
|
|
74
|
+
let height = ye - ys;
|
|
75
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
|
|
76
|
+
if (debug)
|
|
77
|
+
LazyUtil_1.LazyLog.log('none', `LineLayer:`, { xs, ys, xe, ye, width, height });
|
|
78
|
+
ctx.save();
|
|
79
|
+
(0, utils_1.transform)(ctx, this.props.transform, { x: xs, y: ys, width, height, type: this.type });
|
|
80
|
+
(0, utils_1.drawShadow)(ctx, this.props.shadow);
|
|
81
|
+
(0, utils_1.opacity)(ctx, this.props.opacity);
|
|
82
|
+
(0, utils_1.filters)(ctx, this.props.filter);
|
|
83
|
+
ctx.beginPath();
|
|
84
|
+
ctx.moveTo(xs, ys);
|
|
85
|
+
ctx.strokeStyle = fillStyle;
|
|
86
|
+
ctx.lineWidth = this.props.stroke?.width || 1;
|
|
87
|
+
ctx.lineCap = this.props.stroke?.cap || 'butt';
|
|
88
|
+
ctx.lineJoin = this.props.stroke?.join || 'miter';
|
|
89
|
+
ctx.miterLimit = this.props.stroke?.miterLimit || 10;
|
|
90
|
+
ctx.lineDashOffset = this.props.stroke?.dashOffset || 0;
|
|
91
|
+
ctx.setLineDash(this.props.stroke?.dash || []);
|
|
92
|
+
ctx.lineTo(xe, ye);
|
|
93
|
+
ctx.closePath();
|
|
94
|
+
}
|
|
95
|
+
toJSON() {
|
|
96
|
+
let data = super.toJSON();
|
|
97
|
+
data.props = this.props;
|
|
98
|
+
return { ...data };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.LineLayer = LineLayer;
|
|
@@ -10,7 +10,7 @@ const Pattern_1 = require("../helpers/Pattern");
|
|
|
10
10
|
class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
11
11
|
props;
|
|
12
12
|
constructor(props) {
|
|
13
|
-
super(enum_1.LayerType.Morph, props);
|
|
13
|
+
super(enum_1.LayerType.Morph, props || {});
|
|
14
14
|
this.props = props ? props : {};
|
|
15
15
|
if (!this.props.fillStyle)
|
|
16
16
|
this.props.fillStyle = '#000000';
|
|
@@ -16,7 +16,7 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
|
|
|
16
16
|
* @param x {ScaleType} - The end `x` of the quadratic layer.
|
|
17
17
|
* @param y {ScaleType} - The end `y` of the quadratic layer.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
setEndPosition(x: ScaleType, y: ScaleType): this;
|
|
20
20
|
/**
|
|
21
21
|
* @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
|
|
22
22
|
* @param color {string} - The `color` of the layer.
|
|
@@ -10,7 +10,7 @@ const Pattern_1 = require("../helpers/Pattern");
|
|
|
10
10
|
class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
11
11
|
props;
|
|
12
12
|
constructor(props) {
|
|
13
|
-
super(enum_1.LayerType.QuadraticCurve, props);
|
|
13
|
+
super(enum_1.LayerType.QuadraticCurve, props || {});
|
|
14
14
|
this.props = props ? props : {};
|
|
15
15
|
if (!this.props.fillStyle)
|
|
16
16
|
this.props.fillStyle = '#000000';
|
|
@@ -30,7 +30,7 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
30
30
|
* @param x {ScaleType} - The end `x` of the quadratic layer.
|
|
31
31
|
* @param y {ScaleType} - The end `y` of the quadratic layer.
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
setEndPosition(x, y) {
|
|
34
34
|
this.props.endPoint = { x, y };
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
@@ -10,7 +10,7 @@ const Pattern_1 = require("../helpers/Pattern");
|
|
|
10
10
|
class TextLayer extends BaseLayer_1.BaseLayer {
|
|
11
11
|
props;
|
|
12
12
|
constructor(props) {
|
|
13
|
-
super(enum_1.LayerType.Text, props);
|
|
13
|
+
super(enum_1.LayerType.Text, props || {});
|
|
14
14
|
this.props = props ? props : {};
|
|
15
15
|
this.props.align = enum_1.TextAlign.Left;
|
|
16
16
|
this.props.font = {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IBaseLayer, IBaseLayerProps, ScaleType } from "../";
|
|
2
|
+
|
|
3
|
+
export interface ILineLayer extends IBaseLayer {
|
|
4
|
+
props: ILineLayerProps;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ILineLayerProps extends IBaseLayerProps {
|
|
8
|
+
endPoint: {
|
|
9
|
+
x: ScaleType,
|
|
10
|
+
y: ScaleType
|
|
11
|
+
}
|
|
12
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./components/ImageLayer";
|
|
|
5
5
|
export * from "./components/MorphLayer";
|
|
6
6
|
export * from "./components/BezierLayer";
|
|
7
7
|
export * from "./components/QuadraticLayer";
|
|
8
|
+
export * from "./components/LineLayer";
|
|
8
9
|
export * from "./components/Group";
|
|
9
10
|
export * from "./helpers/Font";
|
|
10
11
|
export * from "./helpers/Gradient";
|
package/dist/utils/utils.js
CHANGED
|
@@ -202,6 +202,7 @@ function transform(ctx, transform, layer = { width: 0, height: 0, x: 0, y: 0, ty
|
|
|
202
202
|
case enum_1.LayerType.Morph:
|
|
203
203
|
case enum_1.LayerType.BezierCurve:
|
|
204
204
|
case enum_1.LayerType.QuadraticCurve:
|
|
205
|
+
case enum_1.LayerType.Line:
|
|
205
206
|
ctx.translate(layer.x + (layer.width / 2), layer.y + (layer.height / 2));
|
|
206
207
|
ctx.rotate((Math.PI / 180) * transform.rotate);
|
|
207
208
|
ctx.translate(-(layer.x + (layer.width / 2)), -(layer.y + (layer.height / 2)));
|
package/example.png
ADDED
|
Binary file
|