@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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/ReadMe.md +20 -0
  3. package/dist/helpers/Fonts.d.ts +7 -0
  4. package/dist/helpers/Fonts.js +32 -0
  5. package/dist/helpers/filters.d.ts +68 -0
  6. package/dist/helpers/filters.js +91 -0
  7. package/dist/index.d.ts +14 -0
  8. package/dist/index.js +39 -0
  9. package/dist/structures/LazyCanvas.d.ts +41 -0
  10. package/dist/structures/LazyCanvas.js +84 -0
  11. package/dist/structures/components/BaseLayer.d.ts +81 -0
  12. package/dist/structures/components/BaseLayer.js +157 -0
  13. package/dist/structures/components/Group.d.ts +50 -0
  14. package/dist/structures/components/Group.js +87 -0
  15. package/dist/structures/components/ImageLayer.d.ts +24 -0
  16. package/dist/structures/components/ImageLayer.js +106 -0
  17. package/dist/structures/components/MorphLayer.d.ts +39 -0
  18. package/dist/structures/components/MorphLayer.js +140 -0
  19. package/dist/structures/components/TextLayer.d.ts +69 -0
  20. package/dist/structures/components/TextLayer.js +225 -0
  21. package/dist/structures/helpers/Font.d.ts +35 -0
  22. package/dist/structures/helpers/Font.js +65 -0
  23. package/dist/structures/helpers/Gradient.d.ts +29 -0
  24. package/dist/structures/helpers/Gradient.js +72 -0
  25. package/dist/structures/helpers/Pattern.d.ts +24 -0
  26. package/dist/structures/helpers/Pattern.js +76 -0
  27. package/dist/structures/managers/FontsManager.d.ts +75 -0
  28. package/dist/structures/managers/FontsManager.js +150 -0
  29. package/dist/structures/managers/LayersManager.d.ts +71 -0
  30. package/dist/structures/managers/LayersManager.js +119 -0
  31. package/dist/structures/managers/RenderManager.d.ts +14 -0
  32. package/dist/structures/managers/RenderManager.js +44 -0
  33. package/dist/types/LazyCanvas.d.ts +16 -0
  34. package/dist/types/components/BaseLayer.d.ts +48 -0
  35. package/dist/types/components/Group.d.ts +6 -0
  36. package/dist/types/components/ImageLayer.d.ts +15 -0
  37. package/dist/types/components/MorphLayer.d.ts +14 -0
  38. package/dist/types/components/TextLayer.d.ts +26 -0
  39. package/dist/types/enum.d.ts +88 -0
  40. package/dist/types/enum.js +104 -0
  41. package/dist/types/helpers/Font.d.ts +12 -0
  42. package/dist/types/helpers/Gradient.d.ts +19 -0
  43. package/dist/types/helpers/Pattern.d.ts +7 -0
  44. package/dist/types/index.d.ts +13 -0
  45. package/dist/types/managers/FontsManager.d.ts +5 -0
  46. package/dist/types/managers/LayersManager.d.ts +6 -0
  47. package/dist/types/managers/RenderManager.d.ts +5 -0
  48. package/dist/types/types.d.ts +12 -0
  49. package/dist/utils/LazyUtil.d.ts +7 -0
  50. package/dist/utils/LazyUtil.js +27 -0
  51. package/dist/utils/utils.d.ts +39 -0
  52. package/dist/utils/utils.js +261 -0
  53. package/package.json +51 -0
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextLayer = void 0;
4
+ const BaseLayer_1 = require("./BaseLayer");
5
+ const enum_1 = require("../../types/enum");
6
+ const LazyUtil_1 = require("../../utils/LazyUtil");
7
+ const Gradient_1 = require("../helpers/Gradient");
8
+ const utils_1 = require("../../utils/utils");
9
+ const Pattern_1 = require("../helpers/Pattern");
10
+ class TextLayer extends BaseLayer_1.BaseLayer {
11
+ props;
12
+ constructor(props) {
13
+ super(enum_1.LayerType.Text, props);
14
+ this.props = props ? props : {};
15
+ this.props.align = enum_1.TextAlign.Left;
16
+ this.props.font = {
17
+ family: 'Geist',
18
+ size: 16,
19
+ weight: enum_1.FontWeight.Normal,
20
+ };
21
+ this.props.fillStyle = '#ffffff';
22
+ this.props.filled = true;
23
+ this.props.multiline = {
24
+ enabled: false,
25
+ width: 'vw',
26
+ height: 0,
27
+ spacing: 1.1,
28
+ };
29
+ this.props.centring = enum_1.Centring.Center;
30
+ }
31
+ /**
32
+ * @description Sets the text of the text layer.
33
+ * @param text {string} - The `text` of the text layer.
34
+ */
35
+ setText(text) {
36
+ this.props.text = text;
37
+ return this;
38
+ }
39
+ /**
40
+ * @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.
41
+ * @param family {string} - The `family` of the font.
42
+ * @param size {number} - The `size` of the font.
43
+ * @param weight {FontWeight} - The `weight` of the font.
44
+ */
45
+ setFont(family, size, weight) {
46
+ if (!family)
47
+ throw new LazyUtil_1.LazyError('The family of the font must be provided');
48
+ if (!size)
49
+ throw new LazyUtil_1.LazyError('The size of the font must be provided');
50
+ if (!weight)
51
+ throw new LazyUtil_1.LazyError('The weight of the font must be provided');
52
+ this.props.font = {
53
+ family: family,
54
+ size: size,
55
+ weight: weight,
56
+ };
57
+ return this;
58
+ }
59
+ /**
60
+ * @description Set the multiline of the text layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
61
+ * @param enabled {boolean} - Whether the text is multiline.
62
+ * @param width {ScaleType} - width of "window" the multiline text. Can be used in one line text for text max width.
63
+ * @param height {ScaleType} - height of "window" the multiline text.
64
+ * @param spacing {number} - The space between the lines.
65
+ */
66
+ setMultiline(enabled, width, height, spacing) {
67
+ this.props.multiline = {
68
+ enabled: enabled,
69
+ width: width,
70
+ height: height,
71
+ spacing: spacing || 1.1,
72
+ };
73
+ return this;
74
+ }
75
+ /**
76
+ * @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
77
+ * @param color {string} - The `color` of the layer.
78
+ */
79
+ setColor(color) {
80
+ if (!color)
81
+ throw new LazyUtil_1.LazyError('The color of the layer must be provided');
82
+ if (!(0, utils_1.isColor)(color))
83
+ throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
84
+ let fill = (0, utils_1.parseColor)(color);
85
+ if (fill instanceof Gradient_1.Gradient || fill instanceof Pattern_1.Pattern) {
86
+ this.props.fillStyle = fill;
87
+ }
88
+ else {
89
+ let arr = fill.split(':');
90
+ this.props.fillStyle = arr[0];
91
+ this.props.opacity = parseFloat(arr[1]) || 1;
92
+ }
93
+ return this;
94
+ }
95
+ /**
96
+ * @description Set the align of the text layer.
97
+ * @param align {TextAlign} - The `align` of the text layer.
98
+ */
99
+ setAlign(align) {
100
+ this.props.align = align;
101
+ return this;
102
+ }
103
+ /**
104
+ * @description Set the baseline of the text layer.
105
+ * @param baseline {TextBaseline} - The `baseline` of the text layer.
106
+ */
107
+ setBaseline(baseline) {
108
+ this.props.baseline = baseline;
109
+ return this;
110
+ }
111
+ /**
112
+ * @description Set the direction of the text layer.
113
+ * @param direction {TextDirection} - The `direction` of the text layer.
114
+ */
115
+ setDirection(direction) {
116
+ this.props.direction = direction;
117
+ return this;
118
+ }
119
+ /**
120
+ * @description Set the stroke of the layer.
121
+ * @param width {number} - The `width` of the stroke.
122
+ * @param cap {string} - The `cap` of the stroke.
123
+ * @param join {string} - The `join` of the stroke.
124
+ * @param dash {number[]} - The `dash` of the stroke.
125
+ * @param dashOffset {number} - The `dashOffset` of the stroke.
126
+ * @param miterLimit {number} - The `miterLimit` of the stroke.
127
+ */
128
+ setStroke(width, cap, join, dash, dashOffset, miterLimit) {
129
+ this.props.stroke = {
130
+ width,
131
+ cap: cap || 'butt',
132
+ join: join || 'miter',
133
+ dash: dash || [],
134
+ dashOffset: dashOffset || 0,
135
+ miterLimit: miterLimit || 10,
136
+ };
137
+ return this;
138
+ }
139
+ /**
140
+ * @description Sets the fills of the layer. If `true` the layer will be filled, if `false` the layer will be stroked.
141
+ * @param filled {boolean} - The `filled` of the layer.
142
+ */
143
+ setFilled(filled) {
144
+ this.props.filled = filled;
145
+ return this;
146
+ }
147
+ async draw(ctx, canvas) {
148
+ const x = (0, utils_1.parseToNormal)(this.props.x, canvas);
149
+ const y = (0, utils_1.parseToNormal)(this.props.y, canvas, { width: 0, height: 0 }, { vertical: true });
150
+ const w = (0, utils_1.parseToNormal)(this.props.multiline?.width, canvas);
151
+ const h = (0, utils_1.parseToNormal)(this.props.multiline?.height, canvas, { width: w, height: 0 }, { vertical: true });
152
+ ctx.save();
153
+ console.log(this.props);
154
+ (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type }, { text: this.props.text, textAlign: this.props.align, fontSize: this.props.font.size, multiline: this.props.multiline.enabled });
155
+ ctx.beginPath();
156
+ (0, utils_1.drawShadow)(ctx, this.props.shadow);
157
+ (0, utils_1.opacity)(ctx, this.props.opacity);
158
+ (0, utils_1.filters)(ctx, this.props.filter);
159
+ ctx.textAlign = this.props.align;
160
+ if (this.props.baseline)
161
+ ctx.textBaseline = this.props.baseline;
162
+ if (this.props.direction)
163
+ ctx.direction = this.props.direction;
164
+ if (this.props.multiline.enabled) {
165
+ const words = this.props.text.split(' ');
166
+ let lines = [];
167
+ for (let fontSize = 1; fontSize <= this.props.font.size; fontSize++) {
168
+ let lineHeight = fontSize * (this.props.multiline.spacing || 1.1);
169
+ ctx.font = `${this.props.font.weight} ${fontSize}px ${this.props.font.family}`;
170
+ let xm = x;
171
+ let ym = y;
172
+ lines = [];
173
+ let line = '';
174
+ for (let word of words) {
175
+ let linePlus = line + word + ' ';
176
+ if (ctx.measureText(linePlus).width > w) {
177
+ lines.push({ text: line, x: xm, y: ym });
178
+ line = word + ' ';
179
+ ym += lineHeight;
180
+ }
181
+ else {
182
+ line = linePlus;
183
+ }
184
+ }
185
+ lines.push({ text: line, x: xm, y: ym });
186
+ if (ym > ym + h)
187
+ break;
188
+ }
189
+ for (let line of lines) {
190
+ this.drawText(this.props, ctx, await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle), line.text, line.x, line.y, w, h);
191
+ }
192
+ }
193
+ else {
194
+ ctx.font = `${this.props.font.weight} ${this.props.font.size}px ${this.props.font.family}`;
195
+ this.drawText(this.props, ctx, await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle), this.props.text, x, y, w, h);
196
+ }
197
+ ctx.closePath();
198
+ ctx.restore();
199
+ }
200
+ drawText(props, ctx, fillStyle, text, x, y, w, h) {
201
+ if (props.filled) {
202
+ ctx.fillStyle = fillStyle;
203
+ ctx.fillText(text, x, y, w);
204
+ }
205
+ else {
206
+ ctx.strokeStyle = fillStyle;
207
+ ctx.lineWidth = props.stroke?.width || 1;
208
+ ctx.lineCap = props.stroke?.cap || 'butt';
209
+ ctx.lineJoin = props.stroke?.join || 'miter';
210
+ ctx.miterLimit = props.stroke?.miterLimit || 10;
211
+ ctx.lineDashOffset = props.stroke?.dashOffset || 0;
212
+ ctx.setLineDash(props.stroke?.dash || []);
213
+ ctx.strokeText(text, x, y, w);
214
+ }
215
+ }
216
+ /**
217
+ * @returns {ITextLayer}
218
+ */
219
+ toJSON() {
220
+ let data = super.toJSON();
221
+ data.props = this.props;
222
+ return { ...data };
223
+ }
224
+ }
225
+ exports.TextLayer = TextLayer;
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { FontWeight } from "../../types/enum";
4
+ import { IFont } from "../../types";
5
+ export declare class Font implements IFont {
6
+ family: string;
7
+ weight: FontWeight;
8
+ path?: string;
9
+ base64?: Buffer;
10
+ constructor();
11
+ /**
12
+ * Set the font family
13
+ * @param family {string} - The `family` of the font
14
+ */
15
+ setFamily(family: string): this;
16
+ /**
17
+ * Set the font weight
18
+ * @param weight {FontWeight} - The `weight` of the font
19
+ */
20
+ setWeight(weight: FontWeight): this;
21
+ /**
22
+ * Set the path of the font
23
+ * @param path {string} - The `path` of the font
24
+ */
25
+ setPath(path: string): this;
26
+ /**
27
+ * Set the base64 of the font
28
+ * @param base64 {string} - The `base64` of the font
29
+ */
30
+ setBase64(base64: Buffer): this;
31
+ /**
32
+ * @returns {IFont}
33
+ */
34
+ toJSON(): IFont;
35
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Font = void 0;
4
+ const enum_1 = require("../../types/enum");
5
+ class Font {
6
+ family;
7
+ weight;
8
+ path;
9
+ base64;
10
+ constructor() {
11
+ this.family = "Arial";
12
+ this.weight = enum_1.FontWeight.Normal;
13
+ }
14
+ /**
15
+ * Set the font family
16
+ * @param family {string} - The `family` of the font
17
+ */
18
+ setFamily(family) {
19
+ if (!family)
20
+ throw new Error("Family must be provided");
21
+ this.family = family;
22
+ return this;
23
+ }
24
+ /**
25
+ * Set the font weight
26
+ * @param weight {FontWeight} - The `weight` of the font
27
+ */
28
+ setWeight(weight) {
29
+ if (!weight)
30
+ throw new Error("Weight must be provided");
31
+ this.weight = weight;
32
+ return this;
33
+ }
34
+ /**
35
+ * Set the path of the font
36
+ * @param path {string} - The `path` of the font
37
+ */
38
+ setPath(path) {
39
+ if (!path)
40
+ throw new Error("Path must be provided");
41
+ this.path = path;
42
+ return this;
43
+ }
44
+ /**
45
+ * Set the base64 of the font
46
+ * @param base64 {string} - The `base64` of the font
47
+ */
48
+ setBase64(base64) {
49
+ if (!base64)
50
+ throw new Error("Base64 must be provided");
51
+ this.base64 = base64;
52
+ return this;
53
+ }
54
+ /**
55
+ * @returns {IFont}
56
+ */
57
+ toJSON() {
58
+ return {
59
+ family: this.family,
60
+ weight: this.weight,
61
+ path: this.path
62
+ };
63
+ }
64
+ }
65
+ exports.Font = Font;
@@ -0,0 +1,29 @@
1
+ import { GradientType } from "../../types/enum";
2
+ import { IGradient, GradientPoint, GradientColorStop } from "../../types";
3
+ import { SKRSContext2D } from "@napi-rs/canvas";
4
+ export declare class Gradient implements IGradient {
5
+ type: GradientType;
6
+ points: Array<GradientPoint>;
7
+ stops: Array<GradientColorStop>;
8
+ constructor();
9
+ /**
10
+ * Set the type of the gradient
11
+ * @param type {GradientType} - The `type` of the gradient. Can be `linear`, `radial`, or `conic`
12
+ */
13
+ setType(type: GradientType): this;
14
+ /**
15
+ * Add a point to the gradient
16
+ * @param points {GradientPoint[]} - The `points` to add to the gradient. `{ x: number, y: number }`
17
+ */
18
+ addPoints(...points: GradientPoint[]): this;
19
+ /**
20
+ * Add a stop to the gradient
21
+ * @param stops {GradientColorStop[]} - The `stops` to add to the gradient. `{ color: string, position: number }`
22
+ */
23
+ addStops(...stops: GradientColorStop[]): this;
24
+ draw(ctx: SKRSContext2D): CanvasGradient;
25
+ /**
26
+ * @returns {IGradient}
27
+ */
28
+ toJSON(): IGradient;
29
+ }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Gradient = void 0;
4
+ const enum_1 = require("../../types/enum");
5
+ const utils_1 = require("../../utils/utils");
6
+ class Gradient {
7
+ type;
8
+ points;
9
+ stops;
10
+ constructor() {
11
+ this.type = enum_1.GradientType.Linear;
12
+ this.points = [];
13
+ this.stops = [];
14
+ }
15
+ /**
16
+ * Set the type of the gradient
17
+ * @param type {GradientType} - The `type` of the gradient. Can be `linear`, `radial`, or `conic`
18
+ */
19
+ setType(type) {
20
+ this.type = type;
21
+ return this;
22
+ }
23
+ /**
24
+ * Add a point to the gradient
25
+ * @param points {GradientPoint[]} - The `points` to add to the gradient. `{ x: number, y: number }`
26
+ */
27
+ addPoints(...points) {
28
+ this.points.push(...points);
29
+ return this;
30
+ }
31
+ /**
32
+ * Add a stop to the gradient
33
+ * @param stops {GradientColorStop[]} - The `stops` to add to the gradient. `{ color: string, position: number }`
34
+ */
35
+ addStops(...stops) {
36
+ this.stops.push(...stops);
37
+ return this;
38
+ }
39
+ draw(ctx) {
40
+ let gradientData = this.toJSON();
41
+ let gradient;
42
+ switch (gradientData.type) {
43
+ case enum_1.GradientType.Linear:
44
+ gradient = ctx.createLinearGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[1].x, gradientData.points[1].y);
45
+ break;
46
+ case enum_1.GradientType.Radial:
47
+ gradient = ctx.createRadialGradient(gradientData.points[0].x, gradientData.points[0].y, (gradientData.points[0].r || 0), (gradientData.points[1].x || gradientData.points[0].x), (gradientData.points[1].y || gradientData.points[0].y), (gradientData.points[1].r || 0));
48
+ break;
49
+ case enum_1.GradientType.Conic:
50
+ gradient = ctx.createConicGradient((gradientData.points[0].startAngle || 0), gradientData.points[0].x, gradientData.points[0].y);
51
+ break;
52
+ default:
53
+ gradient = ctx.createLinearGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[1].x, gradientData.points[1].y);
54
+ break;
55
+ }
56
+ for (let stop of gradientData.stops) {
57
+ gradient.addColorStop(stop.offset, (0, utils_1.parseHex)(stop.color));
58
+ }
59
+ return gradient;
60
+ }
61
+ /**
62
+ * @returns {IGradient}
63
+ */
64
+ toJSON() {
65
+ return {
66
+ type: this.type,
67
+ points: this.points,
68
+ stops: this.stops,
69
+ };
70
+ }
71
+ }
72
+ exports.Gradient = Gradient;
@@ -0,0 +1,24 @@
1
+ import { PatternType } from "../../types/enum";
2
+ import { IPattern } from "../../types";
3
+ import { LazyCanvas } from "../LazyCanvas";
4
+ import { SKRSContext2D } from "@napi-rs/canvas";
5
+ export declare class Pattern implements IPattern {
6
+ type: PatternType;
7
+ src: string | LazyCanvas;
8
+ constructor();
9
+ /**
10
+ * Set the type of the pattern
11
+ * @param type {PatternType} - The `type` of the pattern
12
+ */
13
+ setType(type: PatternType): this;
14
+ /**
15
+ * Set the source of the pattern
16
+ * @param src {string | LazyCanvas} - The `src` of the pattern
17
+ */
18
+ setSrc(src: string | LazyCanvas): this;
19
+ draw(ctx: SKRSContext2D): Promise<CanvasPattern>;
20
+ /**
21
+ * @returns {IPattern}
22
+ */
23
+ toJSON(): IPattern;
24
+ }
@@ -0,0 +1,76 @@
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.Pattern = void 0;
27
+ const enum_1 = require("../../types/enum");
28
+ const LazyCanvas_1 = require("../LazyCanvas");
29
+ const canvas_1 = require("@napi-rs/canvas");
30
+ const jimp = __importStar(require("jimp"));
31
+ class Pattern {
32
+ type;
33
+ src;
34
+ constructor() {
35
+ this.type = enum_1.PatternType.Repeat;
36
+ this.src = '';
37
+ }
38
+ /**
39
+ * Set the type of the pattern
40
+ * @param type {PatternType} - The `type` of the pattern
41
+ */
42
+ setType(type) {
43
+ this.type = type;
44
+ return this;
45
+ }
46
+ /**
47
+ * Set the source of the pattern
48
+ * @param src {string | LazyCanvas} - The `src` of the pattern
49
+ */
50
+ setSrc(src) {
51
+ this.src = src;
52
+ return this;
53
+ }
54
+ async draw(ctx) {
55
+ if (this.src instanceof LazyCanvas_1.LazyCanvas) {
56
+ let jmp = await this.src.render.render();
57
+ let image = await (0, canvas_1.loadImage)(jmp);
58
+ return ctx.createPattern(image, this.type);
59
+ }
60
+ else {
61
+ let jmp = await jimp.read(this.src);
62
+ let image = await (0, canvas_1.loadImage)(await jmp.getBufferAsync('image/png'));
63
+ return ctx.createPattern(image, this.type);
64
+ }
65
+ }
66
+ /**
67
+ * @returns {IPattern}
68
+ */
69
+ toJSON() {
70
+ return {
71
+ type: this.type,
72
+ src: this.src
73
+ };
74
+ }
75
+ }
76
+ exports.Pattern = Pattern;
@@ -0,0 +1,75 @@
1
+ import { IFontsManager, IFonts } from "../../types";
2
+ import { Font } from "../helpers/Font";
3
+ export declare class FontsManager implements IFontsManager {
4
+ map: Map<string, Font>;
5
+ constructor(fonts?: IFonts);
6
+ /**
7
+ * Add a font to the map
8
+ * @param fonts {Font[]} - The `font` to add to the map
9
+ */
10
+ add(...fonts: Font[]): this;
11
+ /**
12
+ * Remove a font from the map
13
+ * @param array {Array<{ family: string, weight: string }>} - The `family` and `weight` of the font to remove
14
+ */
15
+ remove(...array: Array<{
16
+ family: string;
17
+ weight: string;
18
+ }>): this;
19
+ /**
20
+ * Clear all fonts from the map
21
+ */
22
+ clear(): this;
23
+ /**
24
+ * Get a font from the map
25
+ * @param family {string} - The `family` of the font to get
26
+ * @param weight {string} - The `weight` of the font to get
27
+ */
28
+ get(family: string, weight?: string): Font | Font[] | undefined;
29
+ /**
30
+ * Check if a font exists in the map
31
+ * @param family {string} - The `family` of the font to check
32
+ * @param weight {string} - The `weight` of the font to check
33
+ */
34
+ has(family: string, weight?: string): boolean;
35
+ /**
36
+ * Get the size of the map
37
+ */
38
+ size(): number;
39
+ /**
40
+ * Get the values of the map
41
+ */
42
+ values(): IterableIterator<Font>;
43
+ /**
44
+ * Get the keys of the map
45
+ */
46
+ keys(): IterableIterator<string>;
47
+ /**
48
+ * Get the entries of the map
49
+ */
50
+ entries(): IterableIterator<[string, Font]>;
51
+ /**
52
+ * Iterate over the map
53
+ * @param callbackfn {Function} - The function to execute on each font
54
+ * @param thisArg {any} - The `this` context to use
55
+ */
56
+ forEach(callbackfn: (value: Font, key: string, map: Map<string, Font>) => void, thisArg?: any): this;
57
+ /**
58
+ * Convert the map to a JSON object
59
+ */
60
+ toJSON(): object;
61
+ /**
62
+ * Convert the map from a JSON object
63
+ * @param json {object} - The JSON object to convert
64
+ */
65
+ fromJSON(json: object): this;
66
+ /**
67
+ * Convert the map to an array
68
+ */
69
+ toArray(): Font[];
70
+ /**
71
+ * Convert an array to the map
72
+ * @param array {Font[]} - The `array` to convert
73
+ */
74
+ fromArray(array: Font[]): this;
75
+ }