@nmmty/lazycanvas 0.3.5 → 0.4.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/dist/index.d.ts +3 -3
- package/dist/index.js +3 -1
- package/dist/structures/LazyCanvas.d.ts +2 -0
- package/dist/structures/LazyCanvas.js +3 -0
- package/dist/structures/components/BaseLayer.d.ts +6 -1
- package/dist/structures/components/BaseLayer.js +8 -0
- package/dist/structures/components/ClearLayer.d.ts +39 -0
- package/dist/structures/components/ClearLayer.js +91 -0
- package/dist/structures/components/Group.d.ts +1 -1
- package/dist/structures/components/Group.js +1 -1
- package/dist/structures/components/ImageLayer.js +3 -3
- package/dist/structures/components/MorphLayer.js +2 -2
- package/dist/structures/components/TextLayer.d.ts +10 -0
- package/dist/structures/components/TextLayer.js +22 -2
- package/dist/structures/managers/AnimationManager.d.ts +44 -0
- package/dist/structures/managers/AnimationManager.js +71 -0
- package/dist/structures/managers/FontsManager.d.ts +1 -1
- package/dist/structures/managers/FontsManager.js +1 -1
- package/dist/structures/managers/LayersManager.d.ts +1 -1
- package/dist/structures/managers/LayersManager.js +2 -2
- package/dist/structures/managers/RenderManager.d.ts +3 -0
- package/dist/structures/managers/RenderManager.js +76 -19
- package/dist/types/LazyCanvas.d.ts +2 -0
- package/dist/types/components/BaseLayer.d.ts +2 -1
- package/dist/types/components/ClearLayer.d.ts +19 -0
- package/dist/types/components/TextLayer.d.ts +2 -0
- package/dist/types/enum.d.ts +38 -2
- package/dist/types/enum.js +39 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/managers/AnimationManager.d.ts +14 -0
- package/dist/types/types.d.ts +10 -3
- package/dist/utils/utils.d.ts +3 -3
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ import { TextLayer } from "./structures/components/TextLayer";
|
|
|
5
5
|
import { BezierLayer } from "./structures/components/BezierLayer";
|
|
6
6
|
import { QuadraticLayer } from "./structures/components/QuadraticLayer";
|
|
7
7
|
import { LineLayer } from "./structures/components/LineLayer";
|
|
8
|
+
import { ClearLayer } from "./structures/components/ClearLayer";
|
|
8
9
|
import { BaseLayer } from "./structures/components/BaseLayer";
|
|
9
10
|
import { Group } from "./structures/components/Group";
|
|
10
11
|
import { LayerType, LayerScaleType, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, FontWeight, Export, Centring, PatternType, SaveFormat, GradientType, LinkType } from "./types/enum";
|
|
11
|
-
import type { AnyLayer, AnyCentring, AnyPatternType, AnyGradientType, AnyTextAlign, AnyTextDirection, AnyTextBaseline, AnyWeight, AnyExport, AnyLineCap, AnyLineJoin, AnySaveFormat, AnyLinkType, ScaleType, ColorType, IFont, IFonts, IGradient, IPattern, IImageLayer, IImageLayerProps, IMorphLayer, IMorphLayerProps, ITextLayer, ITextLayerProps, IBezierLayer, IBezierLayerProps, IQuadraticLayer, IQuadraticLayerProps, ILineLayer, ILineLayerProps, IBaseLayer, IBaseLayerProps, IGroup } from "./types";
|
|
12
12
|
import { Font } from "./structures/helpers/Font";
|
|
13
13
|
import { Gradient } from "./structures/helpers/Gradient";
|
|
14
14
|
import { Pattern } from "./structures/helpers/Pattern";
|
|
@@ -16,5 +16,5 @@ import { Link } from "./structures/helpers/Link";
|
|
|
16
16
|
import { saveFile } from "./utils/utils";
|
|
17
17
|
import { Filters } from "./helpers/Filters";
|
|
18
18
|
import { FontsList } from "./helpers/FontsList";
|
|
19
|
-
export { LazyCanvas, ImageLayer, MorphLayer, TextLayer, BezierLayer, QuadraticLayer, LineLayer, BaseLayer, Group, Font, Gradient, Pattern, Link, LayerScaleType, LayerType, FontWeight, GradientType, Export, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, SaveFormat, Centring, PatternType, LinkType, saveFile, Filters, FontsList, };
|
|
20
|
-
export type {
|
|
19
|
+
export { LazyCanvas, ImageLayer, MorphLayer, TextLayer, BezierLayer, QuadraticLayer, LineLayer, ClearLayer, BaseLayer, Group, Font, Gradient, Pattern, Link, LayerScaleType, LayerType, FontWeight, GradientType, Export, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, SaveFormat, Centring, PatternType, LinkType, saveFile, Filters, FontsList, };
|
|
20
|
+
export type { AnyLayer, AnyCentring, AnyPatternType, AnyGradientType, AnyTextAlign, AnyTextDirection, AnyTextBaseline, AnyWeight, AnyExport, AnyLineCap, AnyLineJoin, AnySaveFormat, AnyLinkType, AnyGlobalCompositeOperation, AnyColorSpace, ScaleType, ColorType, Point, PointNumber, GradientPoint, GradientColorStop, Transform, ILazyCanvas, IFont, IFonts, IGradient, IPattern, IImageLayer, IImageLayerProps, IMorphLayer, IMorphLayerProps, ITextLayer, ITextLayerProps, IBezierLayer, IBezierLayerProps, IQuadraticLayer, IQuadraticLayerProps, ILineLayer, ILineLayerProps, IBaseLayer, IBaseLayerProps, IGroup, ILink, IFontsManager, ILayersManager, IRenderManager } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FontsList = exports.Filters = exports.saveFile = exports.LinkType = exports.PatternType = exports.Centring = exports.SaveFormat = exports.TextBaseline = exports.TextDirection = exports.TextAlign = exports.LineJoin = exports.LineCap = exports.Export = exports.GradientType = exports.FontWeight = exports.LayerType = exports.LayerScaleType = exports.Link = exports.Pattern = exports.Gradient = exports.Font = exports.Group = exports.BaseLayer = exports.LineLayer = exports.QuadraticLayer = exports.BezierLayer = exports.TextLayer = exports.MorphLayer = exports.ImageLayer = exports.LazyCanvas = void 0;
|
|
3
|
+
exports.FontsList = exports.Filters = exports.saveFile = exports.LinkType = exports.PatternType = exports.Centring = exports.SaveFormat = exports.TextBaseline = exports.TextDirection = exports.TextAlign = exports.LineJoin = exports.LineCap = exports.Export = exports.GradientType = exports.FontWeight = exports.LayerType = exports.LayerScaleType = exports.Link = exports.Pattern = exports.Gradient = exports.Font = exports.Group = exports.BaseLayer = exports.ClearLayer = exports.LineLayer = exports.QuadraticLayer = exports.BezierLayer = exports.TextLayer = exports.MorphLayer = exports.ImageLayer = exports.LazyCanvas = void 0;
|
|
4
4
|
const LazyCanvas_1 = require("./structures/LazyCanvas");
|
|
5
5
|
Object.defineProperty(exports, "LazyCanvas", { enumerable: true, get: function () { return LazyCanvas_1.LazyCanvas; } });
|
|
6
6
|
const ImageLayer_1 = require("./structures/components/ImageLayer");
|
|
@@ -15,6 +15,8 @@ const QuadraticLayer_1 = require("./structures/components/QuadraticLayer");
|
|
|
15
15
|
Object.defineProperty(exports, "QuadraticLayer", { enumerable: true, get: function () { return QuadraticLayer_1.QuadraticLayer; } });
|
|
16
16
|
const LineLayer_1 = require("./structures/components/LineLayer");
|
|
17
17
|
Object.defineProperty(exports, "LineLayer", { enumerable: true, get: function () { return LineLayer_1.LineLayer; } });
|
|
18
|
+
const ClearLayer_1 = require("./structures/components/ClearLayer");
|
|
19
|
+
Object.defineProperty(exports, "ClearLayer", { enumerable: true, get: function () { return ClearLayer_1.ClearLayer; } });
|
|
18
20
|
const BaseLayer_1 = require("./structures/components/BaseLayer");
|
|
19
21
|
Object.defineProperty(exports, "BaseLayer", { enumerable: true, get: function () { return BaseLayer_1.BaseLayer; } });
|
|
20
22
|
const Group_1 = require("./structures/components/Group");
|
|
@@ -3,6 +3,7 @@ import { Canvas, SKRSContext2D, SvgExportFlag } from "@napi-rs/canvas";
|
|
|
3
3
|
import { LayersManager } from "./managers/LayersManager";
|
|
4
4
|
import { RenderManager } from "./managers/RenderManager";
|
|
5
5
|
import { FontsManager } from "./managers/FontsManager";
|
|
6
|
+
import { AnimationManager } from "./managers/AnimationManager";
|
|
6
7
|
export declare class LazyCanvas implements ILazyCanvas {
|
|
7
8
|
width: number | 0;
|
|
8
9
|
height: number | 0;
|
|
@@ -11,6 +12,7 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
11
12
|
layers: LayersManager;
|
|
12
13
|
render: RenderManager;
|
|
13
14
|
fonts: FontsManager;
|
|
15
|
+
animation: AnimationManager;
|
|
14
16
|
exportType: AnyExport;
|
|
15
17
|
constructor(debug?: boolean);
|
|
16
18
|
/**
|
|
@@ -6,6 +6,7 @@ const canvas_1 = require("@napi-rs/canvas");
|
|
|
6
6
|
const LayersManager_1 = require("./managers/LayersManager");
|
|
7
7
|
const RenderManager_1 = require("./managers/RenderManager");
|
|
8
8
|
const FontsManager_1 = require("./managers/FontsManager");
|
|
9
|
+
const AnimationManager_1 = require("./managers/AnimationManager");
|
|
9
10
|
class LazyCanvas {
|
|
10
11
|
width;
|
|
11
12
|
height;
|
|
@@ -14,6 +15,7 @@ class LazyCanvas {
|
|
|
14
15
|
layers;
|
|
15
16
|
render;
|
|
16
17
|
fonts;
|
|
18
|
+
animation;
|
|
17
19
|
exportType;
|
|
18
20
|
constructor(debug = false) {
|
|
19
21
|
this.width = 0;
|
|
@@ -23,6 +25,7 @@ class LazyCanvas {
|
|
|
23
25
|
this.layers = new LayersManager_1.LayersManager(debug);
|
|
24
26
|
this.render = new RenderManager_1.RenderManager(this, debug);
|
|
25
27
|
this.fonts = new FontsManager_1.FontsManager(debug);
|
|
28
|
+
this.animation = new AnimationManager_1.AnimationManager(debug);
|
|
26
29
|
this.exportType = enum_1.Export.Buffer;
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ScaleType, IBaseLayer, IBaseLayerProps, AnyCentring } from "../../types";
|
|
1
|
+
import { ScaleType, IBaseLayer, IBaseLayerProps, AnyCentring, AnyGlobalCompositeOperation } from "../../types";
|
|
2
2
|
import { LayerType } from "../../types/enum";
|
|
3
3
|
export declare class BaseLayer<T extends IBaseLayerProps> {
|
|
4
4
|
id: string;
|
|
@@ -74,6 +74,11 @@ export declare class BaseLayer<T extends IBaseLayerProps> {
|
|
|
74
74
|
* @param zIndex {number} - The `zIndex` of the layer
|
|
75
75
|
*/
|
|
76
76
|
setZIndex(zIndex: number): this;
|
|
77
|
+
/**
|
|
78
|
+
* @description Sets global composite operation of the layer.
|
|
79
|
+
* @param operation {AnyGlobalCompositeOperation} - The `operation` of the layer
|
|
80
|
+
*/
|
|
81
|
+
setGlobalCompositeOperation(operation: AnyGlobalCompositeOperation): this;
|
|
77
82
|
/**
|
|
78
83
|
* @returns {IBaseLayer}
|
|
79
84
|
*/
|
|
@@ -141,6 +141,14 @@ class BaseLayer {
|
|
|
141
141
|
this.zIndex = zIndex;
|
|
142
142
|
return this;
|
|
143
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* @description Sets global composite operation of the layer.
|
|
146
|
+
* @param operation {AnyGlobalCompositeOperation} - The `operation` of the layer
|
|
147
|
+
*/
|
|
148
|
+
setGlobalCompositeOperation(operation) {
|
|
149
|
+
this.props.globalComposite = operation;
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
144
152
|
/**
|
|
145
153
|
* @returns {IBaseLayer}
|
|
146
154
|
*/
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IClearLayer, IClearLayerProps, ScaleType } from "../../types";
|
|
2
|
+
import { LayerType } from "../../types/enum";
|
|
3
|
+
import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
4
|
+
import { LayersManager } from "../managers/LayersManager";
|
|
5
|
+
export declare class ClearLayer implements IClearLayer {
|
|
6
|
+
id: string;
|
|
7
|
+
type: LayerType;
|
|
8
|
+
zIndex: number;
|
|
9
|
+
visible: boolean;
|
|
10
|
+
props: IClearLayerProps;
|
|
11
|
+
constructor(props?: IClearLayerProps);
|
|
12
|
+
/**
|
|
13
|
+
* @description Position of the layer in the 2D plane. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
14
|
+
* @param x {ScaleType} - The `x` position of the layer
|
|
15
|
+
* @param y {ScaleType} - The `y` position of the layer
|
|
16
|
+
*/
|
|
17
|
+
setPosition(x: ScaleType, y: ScaleType): this;
|
|
18
|
+
/**
|
|
19
|
+
* @description Sets the size of the layer.
|
|
20
|
+
* @param width {ScaleType} - The `width` of the layer
|
|
21
|
+
* @param height {ScaleType} - The `height` of the
|
|
22
|
+
*/
|
|
23
|
+
setSize(width: ScaleType, height: ScaleType): this;
|
|
24
|
+
/**
|
|
25
|
+
* @description Sets the visibility of the layer.
|
|
26
|
+
* @param visible {boolean} - The `visibility` of the layer
|
|
27
|
+
*/
|
|
28
|
+
setVisible(visible: boolean): this;
|
|
29
|
+
/**
|
|
30
|
+
* @description Sets zIndex of the layer.
|
|
31
|
+
* @param zIndex {number} - The `zIndex` of the layer
|
|
32
|
+
*/
|
|
33
|
+
setZIndex(zIndex: number): this;
|
|
34
|
+
draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* @returns {IClearLayer}
|
|
37
|
+
*/
|
|
38
|
+
toJSON(): IClearLayer;
|
|
39
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClearLayer = void 0;
|
|
4
|
+
const enum_1 = require("../../types/enum");
|
|
5
|
+
const utils_1 = require("../../utils/utils");
|
|
6
|
+
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
7
|
+
const utils_2 = require("../../utils/utils");
|
|
8
|
+
class ClearLayer {
|
|
9
|
+
id;
|
|
10
|
+
type;
|
|
11
|
+
zIndex;
|
|
12
|
+
visible;
|
|
13
|
+
props;
|
|
14
|
+
constructor(props) {
|
|
15
|
+
this.id = (0, utils_2.generateID)(enum_1.LayerType.Clear);
|
|
16
|
+
this.type = enum_1.LayerType.Clear;
|
|
17
|
+
this.zIndex = 1;
|
|
18
|
+
this.visible = true;
|
|
19
|
+
this.props = props ? props : {
|
|
20
|
+
x: 0,
|
|
21
|
+
y: 0,
|
|
22
|
+
size: {
|
|
23
|
+
width: 0,
|
|
24
|
+
height: 0
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @description Position of the layer in the 2D plane. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
|
|
30
|
+
* @param x {ScaleType} - The `x` position of the layer
|
|
31
|
+
* @param y {ScaleType} - The `y` position of the layer
|
|
32
|
+
*/
|
|
33
|
+
setPosition(x, y) {
|
|
34
|
+
this.props.x = x;
|
|
35
|
+
this.props.y = y;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @description Sets the size of the layer.
|
|
40
|
+
* @param width {ScaleType} - The `width` of the layer
|
|
41
|
+
* @param height {ScaleType} - The `height` of the
|
|
42
|
+
*/
|
|
43
|
+
setSize(width, height) {
|
|
44
|
+
this.props.size = {
|
|
45
|
+
width,
|
|
46
|
+
height
|
|
47
|
+
};
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @description Sets the visibility of the layer.
|
|
52
|
+
* @param visible {boolean} - The `visibility` of the layer
|
|
53
|
+
*/
|
|
54
|
+
setVisible(visible) {
|
|
55
|
+
this.visible = visible;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @description Sets zIndex of the layer.
|
|
60
|
+
* @param zIndex {number} - The `zIndex` of the layer
|
|
61
|
+
*/
|
|
62
|
+
setZIndex(zIndex) {
|
|
63
|
+
this.zIndex = zIndex;
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
async draw(ctx, canvas, manager, debug) {
|
|
67
|
+
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
68
|
+
const { x, y, w } = parcer.parseBatch({
|
|
69
|
+
x: { v: this.props.x },
|
|
70
|
+
y: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
|
|
71
|
+
w: { v: this.props.size.width },
|
|
72
|
+
});
|
|
73
|
+
const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
|
|
74
|
+
if (debug)
|
|
75
|
+
LazyUtil_1.LazyLog.log('none', `ClearLayer:`, { x, y, w, h });
|
|
76
|
+
ctx.clearRect(x, y, w, h);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @returns {IClearLayer}
|
|
80
|
+
*/
|
|
81
|
+
toJSON() {
|
|
82
|
+
return {
|
|
83
|
+
id: this.id,
|
|
84
|
+
type: this.type,
|
|
85
|
+
zIndex: this.zIndex,
|
|
86
|
+
visible: this.visible,
|
|
87
|
+
props: this.props,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.ClearLayer = ClearLayer;
|
|
@@ -63,12 +63,12 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
|
|
|
63
63
|
}
|
|
64
64
|
async draw(ctx, canvas, manager, debug) {
|
|
65
65
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
66
|
-
const { xs, ys, w
|
|
66
|
+
const { xs, ys, w } = parcer.parseBatch({
|
|
67
67
|
xs: { v: this.props.x },
|
|
68
68
|
ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
|
|
69
|
-
w: { v: this.props.size.width }
|
|
70
|
-
h: { v: this.props.size.height, options: LazyUtil_1.defaultArg.vl(true) },
|
|
69
|
+
w: { v: this.props.size.width }
|
|
71
70
|
});
|
|
71
|
+
const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
|
|
72
72
|
const r = parcer.parse(this.props.size.radius, LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
|
|
73
73
|
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
74
74
|
if (debug)
|
|
@@ -82,12 +82,12 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
82
82
|
}
|
|
83
83
|
async draw(ctx, canvas, manager, debug) {
|
|
84
84
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
85
|
-
const { xs, ys, w
|
|
85
|
+
const { xs, ys, w } = parcer.parseBatch({
|
|
86
86
|
xs: { v: this.props.x },
|
|
87
87
|
ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
|
|
88
88
|
w: { v: this.props.size.width },
|
|
89
|
-
h: { v: this.props.size.height, options: LazyUtil_1.defaultArg.vl(true) },
|
|
90
89
|
});
|
|
90
|
+
const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
|
|
91
91
|
const r = parcer.parse(this.props.size.radius, LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
|
|
92
92
|
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
93
93
|
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
|
|
@@ -65,6 +65,16 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
|
|
|
65
65
|
* @param filled {boolean} - The `filled` of the layer.
|
|
66
66
|
*/
|
|
67
67
|
setFilled(filled: boolean): this;
|
|
68
|
+
/**
|
|
69
|
+
* @description Sets the spacing between the words.
|
|
70
|
+
* @param wordSpacing {number} - The `wordSpacing` of the text layer.
|
|
71
|
+
*/
|
|
72
|
+
setWordSpacing(wordSpacing: number): this;
|
|
73
|
+
/**
|
|
74
|
+
* @description Sets the letter spacing.
|
|
75
|
+
* @param letterSpacing {number} - The `letterSpacing` of the text layer.
|
|
76
|
+
*/
|
|
77
|
+
setLetterSpacing(letterSpacing: number): this;
|
|
68
78
|
measureText(ctx: SKRSContext2D, canvas: Canvas): {
|
|
69
79
|
width: number;
|
|
70
80
|
height: number;
|
|
@@ -29,6 +29,8 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
29
29
|
height: 0,
|
|
30
30
|
};
|
|
31
31
|
this.props.centring = enum_1.Centring.Center;
|
|
32
|
+
this.props.wordSpacing = 0;
|
|
33
|
+
this.props.letterSpacing = 0;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* @description Sets the text of the text layer.
|
|
@@ -155,6 +157,22 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
155
157
|
this.props.filled = filled;
|
|
156
158
|
return this;
|
|
157
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* @description Sets the spacing between the words.
|
|
162
|
+
* @param wordSpacing {number} - The `wordSpacing` of the text layer.
|
|
163
|
+
*/
|
|
164
|
+
setWordSpacing(wordSpacing) {
|
|
165
|
+
this.props.wordSpacing = wordSpacing;
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* @description Sets the letter spacing.
|
|
170
|
+
* @param letterSpacing {number} - The `letterSpacing` of the text layer.
|
|
171
|
+
*/
|
|
172
|
+
setLetterSpacing(letterSpacing) {
|
|
173
|
+
this.props.letterSpacing = letterSpacing;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
158
176
|
measureText(ctx, canvas) {
|
|
159
177
|
const w = (0, utils_1.parseToNormal)(this.props.size?.width, ctx, canvas);
|
|
160
178
|
const h = (0, utils_1.parseToNormal)(this.props.size?.height, ctx, canvas, { width: w, height: 0 }, { vertical: true });
|
|
@@ -169,12 +187,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
169
187
|
}
|
|
170
188
|
async draw(ctx, canvas, manager, debug) {
|
|
171
189
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
172
|
-
const { x, y, w
|
|
190
|
+
const { x, y, w } = parcer.parseBatch({
|
|
173
191
|
x: { v: this.props.x },
|
|
174
192
|
y: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
|
|
175
193
|
w: { v: this.props.size?.width },
|
|
176
|
-
h: { v: this.props.size?.height, options: LazyUtil_1.defaultArg.vl(true) },
|
|
177
194
|
});
|
|
195
|
+
const h = parcer.parse(this.props.size?.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
|
|
178
196
|
if (debug)
|
|
179
197
|
LazyUtil_1.LazyLog.log('none', `TextLayer:`, { x, y, w, h });
|
|
180
198
|
ctx.save();
|
|
@@ -184,6 +202,8 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
184
202
|
(0, utils_1.opacity)(ctx, this.props.opacity);
|
|
185
203
|
(0, utils_1.filters)(ctx, this.props.filter);
|
|
186
204
|
ctx.textAlign = this.props.align;
|
|
205
|
+
ctx.letterSpacing = `${this.props.letterSpacing}px`;
|
|
206
|
+
ctx.wordSpacing = `${this.props.wordSpacing}px`;
|
|
187
207
|
if (this.props.baseline)
|
|
188
208
|
ctx.textBaseline = this.props.baseline;
|
|
189
209
|
if (this.props.direction)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { IAnimationManager, AnyColorSpace } from "../../types";
|
|
2
|
+
export declare class AnimationManager implements IAnimationManager {
|
|
3
|
+
opts: {
|
|
4
|
+
frameRate: number;
|
|
5
|
+
maxColors: number;
|
|
6
|
+
colorSpace: AnyColorSpace;
|
|
7
|
+
loop: boolean;
|
|
8
|
+
transparency: boolean;
|
|
9
|
+
clear: boolean;
|
|
10
|
+
};
|
|
11
|
+
animated: boolean;
|
|
12
|
+
debug: boolean;
|
|
13
|
+
constructor(debug?: boolean);
|
|
14
|
+
/**
|
|
15
|
+
* Sets the frame rate of the animation.
|
|
16
|
+
* @param frameRate {number} - The frame rate of the animation (by default 30).
|
|
17
|
+
*/
|
|
18
|
+
setFrameRate(frameRate: number): this;
|
|
19
|
+
/**
|
|
20
|
+
* Sets the loop of the animation.
|
|
21
|
+
* @param loop {boolean} - Whether the animation should loop or not (by default true).
|
|
22
|
+
*/
|
|
23
|
+
setLoop(loop: boolean): this;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the transparency of the animation.
|
|
26
|
+
* @param transparency {boolean} - Whether the animation should have transparency or not (by default true).
|
|
27
|
+
*/
|
|
28
|
+
setTransparent(transparency: boolean): this;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the RGB format of the animation.
|
|
31
|
+
* @param rgb {ColorSpace} - The RGB format of the animation (by default RGB565).
|
|
32
|
+
*/
|
|
33
|
+
setRGBFormat(rgb: AnyColorSpace): this;
|
|
34
|
+
/**
|
|
35
|
+
* Sets the maximum colors of the animation.
|
|
36
|
+
* @param maxColors {number} - The maximum colors of the animation (by default 256).
|
|
37
|
+
*/
|
|
38
|
+
setMaxColors(maxColors: number): this;
|
|
39
|
+
/**
|
|
40
|
+
* Sets whether the content of previous frames will be cleared.
|
|
41
|
+
* @param clear {boolean} - Whether the animation should clear or not (by default true).
|
|
42
|
+
*/
|
|
43
|
+
setClear(clear: boolean): this;
|
|
44
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AnimationManager = void 0;
|
|
4
|
+
const enum_1 = require("../../types/enum");
|
|
5
|
+
class AnimationManager {
|
|
6
|
+
opts;
|
|
7
|
+
animated;
|
|
8
|
+
debug;
|
|
9
|
+
constructor(debug = false) {
|
|
10
|
+
this.opts = {
|
|
11
|
+
frameRate: 30,
|
|
12
|
+
maxColors: 256,
|
|
13
|
+
colorSpace: enum_1.ColorSpace.RGB565,
|
|
14
|
+
loop: true,
|
|
15
|
+
transparency: true,
|
|
16
|
+
clear: true
|
|
17
|
+
};
|
|
18
|
+
this.animated = false;
|
|
19
|
+
this.debug = debug;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sets the frame rate of the animation.
|
|
23
|
+
* @param frameRate {number} - The frame rate of the animation (by default 30).
|
|
24
|
+
*/
|
|
25
|
+
setFrameRate(frameRate) {
|
|
26
|
+
this.opts.frameRate = frameRate;
|
|
27
|
+
this.animated = true;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sets the loop of the animation.
|
|
32
|
+
* @param loop {boolean} - Whether the animation should loop or not (by default true).
|
|
33
|
+
*/
|
|
34
|
+
setLoop(loop) {
|
|
35
|
+
this.opts.loop = loop;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Sets the transparency of the animation.
|
|
40
|
+
* @param transparency {boolean} - Whether the animation should have transparency or not (by default true).
|
|
41
|
+
*/
|
|
42
|
+
setTransparent(transparency) {
|
|
43
|
+
this.opts.transparency = transparency;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sets the RGB format of the animation.
|
|
48
|
+
* @param rgb {ColorSpace} - The RGB format of the animation (by default RGB565).
|
|
49
|
+
*/
|
|
50
|
+
setRGBFormat(rgb) {
|
|
51
|
+
this.opts.colorSpace = rgb;
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sets the maximum colors of the animation.
|
|
56
|
+
* @param maxColors {number} - The maximum colors of the animation (by default 256).
|
|
57
|
+
*/
|
|
58
|
+
setMaxColors(maxColors) {
|
|
59
|
+
this.opts.maxColors = maxColors;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Sets whether the content of previous frames will be cleared.
|
|
64
|
+
* @param clear {boolean} - Whether the animation should clear or not (by default true).
|
|
65
|
+
*/
|
|
66
|
+
setClear(clear) {
|
|
67
|
+
this.opts.clear = clear;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.AnimationManager = AnimationManager;
|
|
@@ -40,7 +40,7 @@ class LayersManager {
|
|
|
40
40
|
return this;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* ClearLayer all layers from the map
|
|
44
44
|
*/
|
|
45
45
|
clear() {
|
|
46
46
|
this.map.clear();
|
|
@@ -128,7 +128,7 @@ class LayersManager {
|
|
|
128
128
|
this.fromArray(this.toArray().sort((a, b) => a.zIndex - b.zIndex));
|
|
129
129
|
}
|
|
130
130
|
crossSearch(id) {
|
|
131
|
-
for (const layer of this.map.values()) {
|
|
131
|
+
for (const layer of Array.from(this.map.values())) {
|
|
132
132
|
if (layer.id === id)
|
|
133
133
|
return layer;
|
|
134
134
|
if (layer instanceof Group_1.Group) {
|
|
@@ -7,6 +7,9 @@ export declare class RenderManager implements IRenderManager {
|
|
|
7
7
|
lazyCanvas: LazyCanvas;
|
|
8
8
|
debug: boolean;
|
|
9
9
|
constructor(lazyCanvas: LazyCanvas, debug?: boolean);
|
|
10
|
+
private renderLayer;
|
|
11
|
+
private renderStatic;
|
|
12
|
+
private renderAnimation;
|
|
10
13
|
/**
|
|
11
14
|
* This will render all the layers and return the rendered canvas buffer or ctx.
|
|
12
15
|
* @returns {Promise<Buffer | SKRSContext2D>}
|
|
@@ -4,6 +4,8 @@ exports.RenderManager = void 0;
|
|
|
4
4
|
const enum_1 = require("../../types/enum");
|
|
5
5
|
const Group_1 = require("../components/Group");
|
|
6
6
|
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const gifenc_1 = require("gifenc");
|
|
7
9
|
class RenderManager {
|
|
8
10
|
lazyCanvas;
|
|
9
11
|
debug;
|
|
@@ -11,29 +13,39 @@ class RenderManager {
|
|
|
11
13
|
this.lazyCanvas = lazyCanvas;
|
|
12
14
|
this.debug = debug;
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
await subLayer.draw(this.lazyCanvas.ctx, this.lazyCanvas.canvas, this.lazyCanvas.layers, this.debug);
|
|
27
|
-
}
|
|
16
|
+
async renderLayer(layer) {
|
|
17
|
+
if (this.debug)
|
|
18
|
+
LazyUtil_1.LazyLog.log('info', `Rendering ${layer.id}...\nData:`, layer.toJSON());
|
|
19
|
+
if (layer.visible) {
|
|
20
|
+
if (layer instanceof Group_1.Group) {
|
|
21
|
+
for (const subLayer of layer.components) {
|
|
22
|
+
if (subLayer.visible) {
|
|
23
|
+
if ('globalComposite' in subLayer.props && subLayer.props.globalComposite)
|
|
24
|
+
this.lazyCanvas.ctx.globalCompositeOperation = subLayer.props.globalComposite;
|
|
25
|
+
else
|
|
26
|
+
this.lazyCanvas.ctx.globalCompositeOperation = 'source-over';
|
|
27
|
+
await subLayer.draw(this.lazyCanvas.ctx, this.lazyCanvas.canvas, this.lazyCanvas.layers, this.debug);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
else {
|
|
31
|
-
await layer.draw(this.lazyCanvas.ctx, this.lazyCanvas.canvas, this.lazyCanvas.layers, this.debug);
|
|
32
|
-
}
|
|
33
|
-
this.lazyCanvas.ctx.shadowColor = 'transparent';
|
|
34
30
|
}
|
|
31
|
+
else {
|
|
32
|
+
if ('globalComposite' in layer.props && layer.props.globalComposite)
|
|
33
|
+
this.lazyCanvas.ctx.globalCompositeOperation = layer.props.globalComposite;
|
|
34
|
+
else
|
|
35
|
+
this.lazyCanvas.ctx.globalCompositeOperation = 'source-over';
|
|
36
|
+
await layer.draw(this.lazyCanvas.ctx, this.lazyCanvas.canvas, this.lazyCanvas.layers, this.debug);
|
|
37
|
+
}
|
|
38
|
+
this.lazyCanvas.ctx.shadowColor = 'transparent';
|
|
35
39
|
}
|
|
36
|
-
|
|
40
|
+
return this.lazyCanvas.ctx;
|
|
41
|
+
}
|
|
42
|
+
async renderStatic(exportType) {
|
|
43
|
+
if (this.debug)
|
|
44
|
+
LazyUtil_1.LazyLog.log('info', `Rendering static...`);
|
|
45
|
+
for (const layer of this.lazyCanvas.layers.toArray()) {
|
|
46
|
+
await this.renderLayer(layer);
|
|
47
|
+
}
|
|
48
|
+
switch (exportType) {
|
|
37
49
|
case enum_1.Export.Buffer:
|
|
38
50
|
case "buffer":
|
|
39
51
|
return this.lazyCanvas.canvas.toBuffer('image/png');
|
|
@@ -48,5 +60,50 @@ class RenderManager {
|
|
|
48
60
|
return this.lazyCanvas.canvas.toBuffer('image/png');
|
|
49
61
|
}
|
|
50
62
|
}
|
|
63
|
+
async renderAnimation() {
|
|
64
|
+
const encoder = new gifenc_1.GIFEncoder();
|
|
65
|
+
if (this.debug)
|
|
66
|
+
LazyUtil_1.LazyLog.log('info', `Rendering animation...\nData:`, this.lazyCanvas.animation.opts);
|
|
67
|
+
for (const layer of this.lazyCanvas.layers.toArray()) {
|
|
68
|
+
const ctx = await this.renderLayer(layer);
|
|
69
|
+
let { data, width, height } = ctx.getImageData(0, 0, this.lazyCanvas.width, this.lazyCanvas.height);
|
|
70
|
+
const palette = (0, gifenc_1.quantize)(data, this.lazyCanvas.animation.opts.maxColors, { format: this.lazyCanvas.animation.opts.colorSpace });
|
|
71
|
+
const index = (0, gifenc_1.applyPalette)(data, palette, this.lazyCanvas.animation.opts.colorSpace);
|
|
72
|
+
encoder.writeFrame(index, width, height, {
|
|
73
|
+
palette,
|
|
74
|
+
transparent: this.lazyCanvas.animation.opts.transparency,
|
|
75
|
+
delay: 1000 / this.lazyCanvas.animation.opts.frameRate,
|
|
76
|
+
loop: this.lazyCanvas.animation.opts.loop
|
|
77
|
+
});
|
|
78
|
+
if (this.lazyCanvas.animation.opts.clear)
|
|
79
|
+
ctx.clearRect(0, 0, this.lazyCanvas.width, this.lazyCanvas.height);
|
|
80
|
+
}
|
|
81
|
+
encoder.finish();
|
|
82
|
+
return encoder.bytesView();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* This will render all the layers and return the rendered canvas buffer or ctx.
|
|
86
|
+
* @returns {Promise<Buffer | SKRSContext2D>}
|
|
87
|
+
*/
|
|
88
|
+
async render() {
|
|
89
|
+
switch (this.lazyCanvas.exportType) {
|
|
90
|
+
case enum_1.Export.Buffer:
|
|
91
|
+
case "buffer":
|
|
92
|
+
if (this.lazyCanvas.animation.animated) {
|
|
93
|
+
return await this.renderAnimation();
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return await this.renderStatic(enum_1.Export.Buffer);
|
|
97
|
+
}
|
|
98
|
+
case enum_1.Export.CTX:
|
|
99
|
+
case "ctx":
|
|
100
|
+
return this.lazyCanvas.ctx;
|
|
101
|
+
case enum_1.Export.SVG:
|
|
102
|
+
case "svg":
|
|
103
|
+
return this.renderStatic(enum_1.Export.SVG);
|
|
104
|
+
default:
|
|
105
|
+
return this.renderStatic(enum_1.Export.Buffer);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
51
108
|
}
|
|
52
109
|
exports.RenderManager = RenderManager;
|
|
@@ -2,6 +2,7 @@ import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
|
2
2
|
import { LayersManager } from "../structures/managers/LayersManager";
|
|
3
3
|
import { RenderManager } from "../structures/managers/RenderManager";
|
|
4
4
|
import { FontsManager } from "../structures/managers/FontsManager";
|
|
5
|
+
import { AnimationManager } from "../structures/managers/AnimationManager";
|
|
5
6
|
import { AnyExport } from "../";
|
|
6
7
|
|
|
7
8
|
export interface ILazyCanvas {
|
|
@@ -12,5 +13,6 @@ export interface ILazyCanvas {
|
|
|
12
13
|
layers: LayersManager;
|
|
13
14
|
render: RenderManager;
|
|
14
15
|
fonts: FontsManager;
|
|
16
|
+
animation: AnimationManager;
|
|
15
17
|
exportType: AnyExport;
|
|
16
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColorType, ScaleType, AnyCentring } from "../";
|
|
1
|
+
import { ColorType, ScaleType, AnyCentring, AnyGlobalCompositeOperation } from "../";
|
|
2
2
|
import { LayerType } from "../enum";
|
|
3
3
|
|
|
4
4
|
export interface IBaseLayer {
|
|
@@ -32,6 +32,7 @@ export interface IBaseLayerProps {
|
|
|
32
32
|
offsetY: number;
|
|
33
33
|
};
|
|
34
34
|
transform: Transform;
|
|
35
|
+
globalComposite: AnyGlobalCompositeOperation;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export interface Transform {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ScaleType } from "../types";
|
|
2
|
+
import { LayerType } from "../enum";
|
|
3
|
+
|
|
4
|
+
export interface IClearLayer {
|
|
5
|
+
id: string;
|
|
6
|
+
type: LayerType;
|
|
7
|
+
zIndex: number;
|
|
8
|
+
visible: boolean;
|
|
9
|
+
props: IClearLayerProps;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IClearLayerProps {
|
|
13
|
+
x: ScaleType;
|
|
14
|
+
y: ScaleType;
|
|
15
|
+
size: {
|
|
16
|
+
width: ScaleType;
|
|
17
|
+
height: ScaleType;
|
|
18
|
+
};
|
|
19
|
+
}
|
package/dist/types/enum.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ export declare enum LayerType {
|
|
|
10
10
|
QuadraticCurve = "quadraticCurve",
|
|
11
11
|
Morph = "morph",
|
|
12
12
|
Text = "text",
|
|
13
|
-
Group = "group"
|
|
13
|
+
Group = "group",
|
|
14
|
+
Clear = "clear"
|
|
14
15
|
}
|
|
15
16
|
export declare enum LayerScaleType {
|
|
16
17
|
Pixel = "px",
|
|
@@ -74,7 +75,9 @@ export declare enum SaveFormat {
|
|
|
74
75
|
PNG = "png",
|
|
75
76
|
JPEG = "jpeg",
|
|
76
77
|
JPG = "jpg",
|
|
77
|
-
SVG = "svg"
|
|
78
|
+
SVG = "svg",
|
|
79
|
+
GIF = "gif",
|
|
80
|
+
WEBP = "webp"
|
|
78
81
|
}
|
|
79
82
|
export declare enum Centring {
|
|
80
83
|
Start = "start",
|
|
@@ -100,3 +103,36 @@ export declare enum LinkType {
|
|
|
100
103
|
X = "x",
|
|
101
104
|
Y = "y"
|
|
102
105
|
}
|
|
106
|
+
export declare enum GlobalCompositeOperation {
|
|
107
|
+
SourceOver = "source-over",
|
|
108
|
+
SourceIn = "source-in",
|
|
109
|
+
SourceOut = "source-out",
|
|
110
|
+
SourceAtop = "source-atop",
|
|
111
|
+
DestinationOver = "destination-over",
|
|
112
|
+
DestinationIn = "destination-in",
|
|
113
|
+
DestinationOut = "destination-out",
|
|
114
|
+
DestinationAtop = "destination-atop",
|
|
115
|
+
Lighter = "lighter",
|
|
116
|
+
Copy = "copy",
|
|
117
|
+
Xor = "xor",
|
|
118
|
+
Multiply = "multiply",
|
|
119
|
+
Screen = "screen",
|
|
120
|
+
Overlay = "overlay",
|
|
121
|
+
Darken = "darken",
|
|
122
|
+
Lighten = "lighten",
|
|
123
|
+
ColorDodge = "color-dodge",
|
|
124
|
+
ColorBurn = "color-burn",
|
|
125
|
+
HardLight = "hard-light",
|
|
126
|
+
SoftLight = "soft-light",
|
|
127
|
+
Difference = "difference",
|
|
128
|
+
Exclusion = "exclusion",
|
|
129
|
+
Hue = "hue",
|
|
130
|
+
Saturation = "saturation",
|
|
131
|
+
Color = "color",
|
|
132
|
+
Luminosity = "luminosity"
|
|
133
|
+
}
|
|
134
|
+
export declare enum ColorSpace {
|
|
135
|
+
RGB565 = "rgb565",
|
|
136
|
+
RGBA4444 = "rgba4444",
|
|
137
|
+
RGBA444 = "rgba444"
|
|
138
|
+
}
|
package/dist/types/enum.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LinkType = exports.PatternType = exports.Centring = exports.SaveFormat = exports.Export = exports.LineJoin = exports.LineCap = exports.TextDirection = exports.TextBaseline = exports.TextAlign = exports.FontWeight = exports.GradientType = exports.LayerScaleType = exports.LayerType = void 0;
|
|
3
|
+
exports.ColorSpace = exports.GlobalCompositeOperation = exports.LinkType = exports.PatternType = exports.Centring = exports.SaveFormat = exports.Export = exports.LineJoin = exports.LineCap = exports.TextDirection = exports.TextBaseline = exports.TextAlign = exports.FontWeight = exports.GradientType = exports.LayerScaleType = exports.LayerType = void 0;
|
|
4
4
|
var LayerType;
|
|
5
5
|
(function (LayerType) {
|
|
6
6
|
LayerType["Base"] = "base";
|
|
@@ -15,6 +15,7 @@ var LayerType;
|
|
|
15
15
|
LayerType["Morph"] = "morph";
|
|
16
16
|
LayerType["Text"] = "text";
|
|
17
17
|
LayerType["Group"] = "group";
|
|
18
|
+
LayerType["Clear"] = "clear";
|
|
18
19
|
})(LayerType || (exports.LayerType = LayerType = {}));
|
|
19
20
|
var LayerScaleType;
|
|
20
21
|
(function (LayerScaleType) {
|
|
@@ -89,6 +90,8 @@ var SaveFormat;
|
|
|
89
90
|
SaveFormat["JPEG"] = "jpeg";
|
|
90
91
|
SaveFormat["JPG"] = "jpg";
|
|
91
92
|
SaveFormat["SVG"] = "svg";
|
|
93
|
+
SaveFormat["GIF"] = "gif";
|
|
94
|
+
SaveFormat["WEBP"] = "webp";
|
|
92
95
|
})(SaveFormat || (exports.SaveFormat = SaveFormat = {}));
|
|
93
96
|
var Centring;
|
|
94
97
|
(function (Centring) {
|
|
@@ -117,3 +120,38 @@ var LinkType;
|
|
|
117
120
|
LinkType["X"] = "x";
|
|
118
121
|
LinkType["Y"] = "y";
|
|
119
122
|
})(LinkType || (exports.LinkType = LinkType = {}));
|
|
123
|
+
var GlobalCompositeOperation;
|
|
124
|
+
(function (GlobalCompositeOperation) {
|
|
125
|
+
GlobalCompositeOperation["SourceOver"] = "source-over";
|
|
126
|
+
GlobalCompositeOperation["SourceIn"] = "source-in";
|
|
127
|
+
GlobalCompositeOperation["SourceOut"] = "source-out";
|
|
128
|
+
GlobalCompositeOperation["SourceAtop"] = "source-atop";
|
|
129
|
+
GlobalCompositeOperation["DestinationOver"] = "destination-over";
|
|
130
|
+
GlobalCompositeOperation["DestinationIn"] = "destination-in";
|
|
131
|
+
GlobalCompositeOperation["DestinationOut"] = "destination-out";
|
|
132
|
+
GlobalCompositeOperation["DestinationAtop"] = "destination-atop";
|
|
133
|
+
GlobalCompositeOperation["Lighter"] = "lighter";
|
|
134
|
+
GlobalCompositeOperation["Copy"] = "copy";
|
|
135
|
+
GlobalCompositeOperation["Xor"] = "xor";
|
|
136
|
+
GlobalCompositeOperation["Multiply"] = "multiply";
|
|
137
|
+
GlobalCompositeOperation["Screen"] = "screen";
|
|
138
|
+
GlobalCompositeOperation["Overlay"] = "overlay";
|
|
139
|
+
GlobalCompositeOperation["Darken"] = "darken";
|
|
140
|
+
GlobalCompositeOperation["Lighten"] = "lighten";
|
|
141
|
+
GlobalCompositeOperation["ColorDodge"] = "color-dodge";
|
|
142
|
+
GlobalCompositeOperation["ColorBurn"] = "color-burn";
|
|
143
|
+
GlobalCompositeOperation["HardLight"] = "hard-light";
|
|
144
|
+
GlobalCompositeOperation["SoftLight"] = "soft-light";
|
|
145
|
+
GlobalCompositeOperation["Difference"] = "difference";
|
|
146
|
+
GlobalCompositeOperation["Exclusion"] = "exclusion";
|
|
147
|
+
GlobalCompositeOperation["Hue"] = "hue";
|
|
148
|
+
GlobalCompositeOperation["Saturation"] = "saturation";
|
|
149
|
+
GlobalCompositeOperation["Color"] = "color";
|
|
150
|
+
GlobalCompositeOperation["Luminosity"] = "luminosity";
|
|
151
|
+
})(GlobalCompositeOperation || (exports.GlobalCompositeOperation = GlobalCompositeOperation = {}));
|
|
152
|
+
var ColorSpace;
|
|
153
|
+
(function (ColorSpace) {
|
|
154
|
+
ColorSpace["RGB565"] = "rgb565";
|
|
155
|
+
ColorSpace["RGBA4444"] = "rgba4444";
|
|
156
|
+
ColorSpace["RGBA444"] = "rgba444";
|
|
157
|
+
})(ColorSpace || (exports.ColorSpace = ColorSpace = {}));
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type * from "./components/BezierLayer";
|
|
|
7
7
|
export type * from "./components/QuadraticLayer";
|
|
8
8
|
export type * from "./components/LineLayer";
|
|
9
9
|
export type * from "./components/Group";
|
|
10
|
+
export type * from "./components/ClearLayer";
|
|
10
11
|
export type * from "./helpers/Font";
|
|
11
12
|
export type * from "./helpers/Gradient";
|
|
12
13
|
export type * from "./helpers/Pattern";
|
|
@@ -14,4 +15,5 @@ export type * from "./helpers/Link";
|
|
|
14
15
|
export type * from "./managers/LayersManager";
|
|
15
16
|
export type * from "./managers/RenderManager";
|
|
16
17
|
export type * from "./managers/FontsManager";
|
|
18
|
+
export type * from "./managers/AnimationManager";
|
|
17
19
|
export type * from "./LazyCanvas";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AnyColorSpace } from "../types";
|
|
2
|
+
|
|
3
|
+
export interface IAnimationManager {
|
|
4
|
+
opts: {
|
|
5
|
+
frameRate: number;
|
|
6
|
+
maxColors: number;
|
|
7
|
+
colorSpace: AnyColorSpace;
|
|
8
|
+
loop: boolean;
|
|
9
|
+
transparency: boolean;
|
|
10
|
+
clear: boolean;
|
|
11
|
+
};
|
|
12
|
+
animated: boolean;
|
|
13
|
+
debug: boolean;
|
|
14
|
+
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { BezierLayer } from "../structures/components/BezierLayer";
|
|
|
7
7
|
import { QuadraticLayer } from "../structures/components/QuadraticLayer";
|
|
8
8
|
import { LineLayer } from "../structures/components/LineLayer";
|
|
9
9
|
import { Group } from "../structures/components/Group";
|
|
10
|
+
import { ClearLayer } from "../structures/components/ClearLayer";
|
|
10
11
|
import { Link } from "../structures/helpers/Link";
|
|
11
12
|
import {
|
|
12
13
|
FontWeight,
|
|
@@ -20,14 +21,16 @@ import {
|
|
|
20
21
|
Centring,
|
|
21
22
|
PatternType,
|
|
22
23
|
SaveFormat,
|
|
23
|
-
LinkType
|
|
24
|
+
LinkType,
|
|
25
|
+
GlobalCompositeOperation,
|
|
26
|
+
ColorSpace
|
|
24
27
|
} from "./enum";
|
|
25
28
|
|
|
26
29
|
export type ScaleType = string | number | 'vw' | 'vh' | 'vmin' | 'vmax' | Link;
|
|
27
30
|
|
|
28
31
|
export type ColorType = string | Gradient | Pattern;
|
|
29
32
|
|
|
30
|
-
export type AnyLayer = MorphLayer | ImageLayer | TextLayer | BezierLayer | QuadraticLayer | LineLayer | Group;
|
|
33
|
+
export type AnyLayer = MorphLayer | ImageLayer | TextLayer | BezierLayer | QuadraticLayer | LineLayer | ClearLayer | Group;
|
|
31
34
|
|
|
32
35
|
export type AnyWeight = FontWeight | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
|
|
33
36
|
|
|
@@ -49,10 +52,14 @@ export type AnyCentring = Centring | 'start' | 'start-top' | 'start-bottom' | 'c
|
|
|
49
52
|
|
|
50
53
|
export type AnyPatternType = PatternType | 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';
|
|
51
54
|
|
|
52
|
-
export type AnySaveFormat = SaveFormat | 'png' | 'jpeg' | 'jpg' | 'svg';
|
|
55
|
+
export type AnySaveFormat = SaveFormat | 'png' | 'jpeg' | 'jpg' | 'svg' | 'gif' | 'webp';
|
|
53
56
|
|
|
54
57
|
export type AnyLinkType = LinkType | 'width' | 'height' | 'x' | 'y';
|
|
55
58
|
|
|
59
|
+
export type AnyGlobalCompositeOperation = GlobalCompositeOperation | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
|
|
60
|
+
|
|
61
|
+
export type AnyColorSpace = ColorSpace | 'rgb565' | 'rgba4444' | 'rgba444';
|
|
62
|
+
|
|
56
63
|
export type Point = {
|
|
57
64
|
x: ScaleType;
|
|
58
65
|
y: ScaleType;
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { LayerType
|
|
2
|
-
import { Transform, ScaleType, ColorType, PointNumber, AnyCentring, AnyTextAlign } from "../types";
|
|
1
|
+
import { LayerType } from "../types/enum";
|
|
2
|
+
import { Transform, ScaleType, ColorType, PointNumber, AnyCentring, AnyTextAlign, AnySaveFormat } from "../types";
|
|
3
3
|
import { Gradient } from "../structures/helpers/Gradient";
|
|
4
4
|
import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
5
5
|
import { Pattern } from "../structures/helpers/Pattern";
|
|
@@ -51,7 +51,7 @@ export declare function transform(ctx: SKRSContext2D, transform: Transform, laye
|
|
|
51
51
|
fontSize: number;
|
|
52
52
|
multiline: boolean;
|
|
53
53
|
}): void;
|
|
54
|
-
export declare function saveFile(buffer: any, extension:
|
|
54
|
+
export declare function saveFile(buffer: any, extension: AnySaveFormat, name: string): Promise<void>;
|
|
55
55
|
export declare function generateRandomName(): string;
|
|
56
56
|
export declare function isImageUrlValid(src: string): boolean;
|
|
57
57
|
export declare function centring(centring: AnyCentring, type: LayerType, width: number, height: number, x: number, y: number): {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nmmty/lazycanvas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A simple way to interact with @napi-rs/canvas in an advanced way!",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"centring": "tsc ./test/centring.ts && node ./test/centring.js",
|
|
10
10
|
"logo": "tsc ./test/logo.ts && node ./test/logo.js",
|
|
11
11
|
"text": "tsc ./test/text.ts && node ./test/text.js",
|
|
12
|
+
"animation": "tsc ./test/animation.ts && node ./test/animation.js",
|
|
12
13
|
"doc": "tsx docgen.ts",
|
|
13
14
|
"font": "tsc ./scripts/font-gen.ts && node ./scripts/font-gen.js",
|
|
14
15
|
"build": "tsc"
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
"homepage": "https://github.com/NMMTY/LazyCanvas#readme",
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@napi-rs/canvas": "^0.1.68",
|
|
36
|
+
"gifenc": "^1.0.3",
|
|
35
37
|
"jimp": "0.22.12",
|
|
36
38
|
"path": "^0.12.7",
|
|
37
39
|
"svgson": "^5.3.1"
|
|
@@ -43,7 +45,10 @@
|
|
|
43
45
|
"@types/node": "^22.10.2",
|
|
44
46
|
"@types/react": "^19.0.2",
|
|
45
47
|
"ava": "^6.2.0",
|
|
48
|
+
"eslint": "^9.23.0",
|
|
49
|
+
"eslint-config-neon": "^0.2.7",
|
|
46
50
|
"globals": "^15.14.0",
|
|
51
|
+
"lodash.merge": "^4.6.2",
|
|
47
52
|
"tslib": "^2.8.1",
|
|
48
53
|
"tsx": "^4.19.2",
|
|
49
54
|
"typescript": "^5.4.5"
|