@nmmty/lazycanvas 0.3.3 → 0.3.5

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 CHANGED
@@ -7,13 +7,14 @@ import { QuadraticLayer } from "./structures/components/QuadraticLayer";
7
7
  import { LineLayer } from "./structures/components/LineLayer";
8
8
  import { BaseLayer } from "./structures/components/BaseLayer";
9
9
  import { Group } from "./structures/components/Group";
10
- import { LayerType, LayerScaleType, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, FontWeight, Export, Centring, PatternType, SaveFormat, GradientType } from "./types/enum";
11
- import type { AnyLayer, AnyCentring, AnyPatternType, AnyGradientType, AnyTextAlign, AnyTextDirection, AnyTextBaseline, AnyWeight, AnyExport, AnyLineCap, AnyLineJoin, AnySaveFormat, ScaleType, ColorType, IFont, IFonts, IGradient, IPattern, IImageLayer, IImageLayerProps, IMorphLayer, IMorphLayerProps, ITextLayer, ITextLayerProps, IBezierLayer, IBezierLayerProps, IQuadraticLayer, IQuadraticLayerProps, ILineLayer, ILineLayerProps, IBaseLayer, IBaseLayerProps, IGroup } from "./types";
10
+ 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";
15
+ import { Link } from "./structures/helpers/Link";
15
16
  import { saveFile } from "./utils/utils";
16
17
  import { Filters } from "./helpers/Filters";
17
18
  import { FontsList } from "./helpers/FontsList";
18
- export { LazyCanvas, ImageLayer, MorphLayer, TextLayer, BezierLayer, QuadraticLayer, LineLayer, BaseLayer, Group, Font, Gradient, Pattern, LayerScaleType, LayerType, FontWeight, GradientType, Export, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, SaveFormat, Centring, PatternType, saveFile, Filters, FontsList, };
19
- export type { IFont, IFonts, IGradient, IPattern, IImageLayer, IImageLayerProps, IMorphLayer, IMorphLayerProps, ITextLayer, ITextLayerProps, IBaseLayer, IBaseLayerProps, IBezierLayer, IBezierLayerProps, IQuadraticLayer, IQuadraticLayerProps, ILineLayer, ILineLayerProps, IGroup, AnyLayer, AnyCentring, AnyPatternType, AnyGradientType, AnyTextAlign, AnyTextDirection, AnyTextBaseline, AnyWeight, AnyExport, AnyLineCap, AnyLineJoin, AnySaveFormat, ScaleType, ColorType };
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 { IFont, IFonts, IGradient, IPattern, IImageLayer, IImageLayerProps, IMorphLayer, IMorphLayerProps, ITextLayer, ITextLayerProps, IBaseLayer, IBaseLayerProps, IBezierLayer, IBezierLayerProps, IQuadraticLayer, IQuadraticLayerProps, ILineLayer, ILineLayerProps, IGroup, AnyLayer, AnyCentring, AnyPatternType, AnyGradientType, AnyTextAlign, AnyTextDirection, AnyTextBaseline, AnyWeight, AnyExport, AnyLineCap, AnyLineJoin, AnySaveFormat, AnyLinkType, ScaleType, ColorType };
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.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.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.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");
@@ -33,12 +33,15 @@ Object.defineProperty(exports, "Centring", { enumerable: true, get: function ()
33
33
  Object.defineProperty(exports, "PatternType", { enumerable: true, get: function () { return enum_1.PatternType; } });
34
34
  Object.defineProperty(exports, "SaveFormat", { enumerable: true, get: function () { return enum_1.SaveFormat; } });
35
35
  Object.defineProperty(exports, "GradientType", { enumerable: true, get: function () { return enum_1.GradientType; } });
36
+ Object.defineProperty(exports, "LinkType", { enumerable: true, get: function () { return enum_1.LinkType; } });
36
37
  const Font_1 = require("./structures/helpers/Font");
37
38
  Object.defineProperty(exports, "Font", { enumerable: true, get: function () { return Font_1.Font; } });
38
39
  const Gradient_1 = require("./structures/helpers/Gradient");
39
40
  Object.defineProperty(exports, "Gradient", { enumerable: true, get: function () { return Gradient_1.Gradient; } });
40
41
  const Pattern_1 = require("./structures/helpers/Pattern");
41
42
  Object.defineProperty(exports, "Pattern", { enumerable: true, get: function () { return Pattern_1.Pattern; } });
43
+ const Link_1 = require("./structures/helpers/Link");
44
+ Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return Link_1.Link; } });
42
45
  const utils_1 = require("./utils/utils");
43
46
  Object.defineProperty(exports, "saveFile", { enumerable: true, get: function () { return utils_1.saveFile; } });
44
47
  const Filters_1 = require("./helpers/Filters");
@@ -34,6 +34,22 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
34
34
  * @param miterLimit {number} - The `miterLimit` of the stroke.
35
35
  */
36
36
  setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
37
+ getBoundingBox(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager): {
38
+ max: {
39
+ x: number;
40
+ y: number;
41
+ };
42
+ min: {
43
+ x: number;
44
+ y: number;
45
+ };
46
+ center: {
47
+ x: number;
48
+ y: number;
49
+ };
50
+ width: number;
51
+ height: number;
52
+ };
37
53
  draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
38
54
  /**
39
55
  * @returns {IBezierLayer}
@@ -75,15 +75,33 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
75
75
  };
76
76
  return this;
77
77
  }
78
+ getBoundingBox(ctx, canvas, manager) {
79
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
80
+ const { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye } = parcer.parseBatch({
81
+ xs: { v: this.props.x },
82
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
83
+ cp1x: { v: this.props.controlPoints[0].x },
84
+ cp1y: { v: this.props.controlPoints[0].y, options: LazyUtil_1.defaultArg.vl(true) },
85
+ cp2x: { v: this.props.controlPoints[1].x },
86
+ cp2y: { v: this.props.controlPoints[1].y, options: LazyUtil_1.defaultArg.vl(true) },
87
+ xe: { v: this.props.endPoint.x },
88
+ ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
89
+ });
90
+ const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cp1x, y: cp1y }, { x: cp2x, y: cp2y }, { x: xe, y: ye }]);
91
+ return { max, min, center, width, height };
92
+ }
78
93
  async draw(ctx, canvas, manager, debug) {
79
- const xs = (0, utils_1.parseToNormal)(this.props.x, ctx, canvas);
80
- const ys = (0, utils_1.parseToNormal)(this.props.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
81
- const cp1x = (0, utils_1.parseToNormal)(this.props.controlPoints[0].x, ctx, canvas);
82
- const cp1y = (0, utils_1.parseToNormal)(this.props.controlPoints[0].y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
83
- const cp2x = (0, utils_1.parseToNormal)(this.props.controlPoints[1].x, ctx, canvas);
84
- const cp2y = (0, utils_1.parseToNormal)(this.props.controlPoints[1].y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
85
- const xe = (0, utils_1.parseToNormal)(this.props.endPoint.x, ctx, canvas);
86
- const ye = (0, utils_1.parseToNormal)(this.props.endPoint.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
94
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
95
+ const { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye } = parcer.parseBatch({
96
+ xs: { v: this.props.x },
97
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
98
+ cp1x: { v: this.props.controlPoints[0].x },
99
+ cp1y: { v: this.props.controlPoints[0].y, options: LazyUtil_1.defaultArg.vl(true) },
100
+ cp2x: { v: this.props.controlPoints[1].x },
101
+ cp2y: { v: this.props.controlPoints[1].y, options: LazyUtil_1.defaultArg.vl(true) },
102
+ xe: { v: this.props.endPoint.x },
103
+ ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
104
+ });
87
105
  const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cp1x, y: cp1y }, { x: cp2x, y: cp2y }, { x: xe, y: ye }]);
88
106
  let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
89
107
  if (debug)
@@ -62,11 +62,14 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
62
62
  return this;
63
63
  }
64
64
  async draw(ctx, canvas, manager, debug) {
65
- let xs = (0, utils_1.parseToNormal)(this.props.x, ctx, canvas);
66
- let ys = (0, utils_1.parseToNormal)(this.props.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
67
- let w = (0, utils_1.parseToNormal)(this.props.size.width, ctx, canvas);
68
- let h = (0, utils_1.parseToNormal)(this.props.size.height, ctx, canvas, { width: w, height: 0 }, { vertical: true });
69
- let r = (0, utils_1.parseToNormal)(this.props.size.radius, ctx, canvas, { width: w, height: h }, { layer: true });
65
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
66
+ const { xs, ys, w, h } = parcer.parseBatch({
67
+ xs: { v: this.props.x },
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) },
71
+ });
72
+ const r = parcer.parse(this.props.size.radius, LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
70
73
  let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
71
74
  if (debug)
72
75
  LazyUtil_1.LazyLog.log('none', `ImageLayer:`, { x, y, w, h, r });
@@ -26,6 +26,14 @@ export declare class LineLayer extends BaseLayer<ILineLayerProps> {
26
26
  * @param miterLimit {number} - The `miterLimit` of the stroke.
27
27
  */
28
28
  setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
29
+ getBoundingBox(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager): {
30
+ xs: number;
31
+ ys: number;
32
+ xe: number;
33
+ ye: number;
34
+ width: number;
35
+ height: number;
36
+ };
29
37
  draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
30
38
  toJSON(): ILineLayer;
31
39
  }
@@ -65,11 +65,26 @@ class LineLayer extends BaseLayer_1.BaseLayer {
65
65
  };
66
66
  return this;
67
67
  }
68
+ getBoundingBox(ctx, canvas, manager) {
69
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
70
+ const { xs, ys, xe, ye } = parcer.parseBatch({
71
+ xs: { v: this.props.x },
72
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
73
+ xe: { v: this.props.endPoint.x },
74
+ ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
75
+ });
76
+ let width = xe - xs;
77
+ let height = ye - ys;
78
+ return { xs, ys, xe, ye, width, height };
79
+ }
68
80
  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 });
81
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
82
+ const { xs, ys, xe, ye } = parcer.parseBatch({
83
+ xs: { v: this.props.x },
84
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
85
+ xe: { v: this.props.endPoint.x },
86
+ ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
87
+ });
73
88
  let width = xe - xs;
74
89
  let height = ye - ys;
75
90
  let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
@@ -81,11 +81,14 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
81
81
  return this;
82
82
  }
83
83
  async draw(ctx, canvas, manager, debug) {
84
- const xs = (0, utils_1.parseToNormal)(this.props.x, ctx, canvas);
85
- const ys = (0, utils_1.parseToNormal)(this.props.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
86
- const w = (0, utils_1.parseToNormal)(this.props.size.width, ctx, canvas, { width: 0, height: 0 }, { vertical: false }, manager);
87
- const h = (0, utils_1.parseToNormal)(this.props.size.height, ctx, canvas, { width: w, height: 0 }, { vertical: true }, manager);
88
- const r = (0, utils_1.parseToNormal)(this.props.size.radius, ctx, canvas, { width: w / 2, height: h / 2 }, { layer: true });
84
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
85
+ const { xs, ys, w, h } = parcer.parseBatch({
86
+ xs: { v: this.props.x },
87
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
88
+ w: { v: this.props.size.width },
89
+ h: { v: this.props.size.height, options: LazyUtil_1.defaultArg.vl(true) },
90
+ });
91
+ const r = parcer.parse(this.props.size.radius, LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
89
92
  let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
90
93
  let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
91
94
  if (debug)
@@ -32,6 +32,22 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
32
32
  * @param miterLimit {number} - The `miterLimit` of the stroke.
33
33
  */
34
34
  setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
35
+ getBoundingBox(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager): {
36
+ max: {
37
+ x: number;
38
+ y: number;
39
+ };
40
+ min: {
41
+ x: number;
42
+ y: number;
43
+ };
44
+ center: {
45
+ x: number;
46
+ y: number;
47
+ };
48
+ width: number;
49
+ height: number;
50
+ };
35
51
  draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
36
52
  /**
37
53
  * @returns {IQuadraticLayer}
@@ -74,13 +74,29 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
74
74
  };
75
75
  return this;
76
76
  }
77
+ getBoundingBox(ctx, canvas, manager) {
78
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
79
+ const { xs, ys, cx, cy, xe, ye } = parcer.parseBatch({
80
+ xs: { v: this.props.x },
81
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
82
+ cx: { v: this.props.controlPoint.x },
83
+ cy: { v: this.props.controlPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
84
+ xe: { v: this.props.endPoint.x },
85
+ ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
86
+ });
87
+ const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cx, y: cy }, { x: xe, y: ye }]);
88
+ return { max, min, center, width, height };
89
+ }
77
90
  async draw(ctx, canvas, manager, debug) {
78
- const xs = (0, utils_1.parseToNormal)(this.props.x, ctx, canvas);
79
- const ys = (0, utils_1.parseToNormal)(this.props.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
80
- const cx = (0, utils_1.parseToNormal)(this.props.controlPoint.x, ctx, canvas);
81
- const cy = (0, utils_1.parseToNormal)(this.props.controlPoint.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
82
- const xe = (0, utils_1.parseToNormal)(this.props.endPoint.x, ctx, canvas);
83
- const ye = (0, utils_1.parseToNormal)(this.props.endPoint.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
91
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
92
+ const { xs, ys, cx, cy, xe, ye } = parcer.parseBatch({
93
+ xs: { v: this.props.x },
94
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
95
+ cx: { v: this.props.controlPoint.x },
96
+ cy: { v: this.props.controlPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
97
+ xe: { v: this.props.endPoint.x },
98
+ ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
99
+ });
84
100
  const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cx, y: cy }, { x: xe, y: ye }]);
85
101
  let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
86
102
  if (debug)
@@ -22,9 +22,11 @@ class TextLayer extends BaseLayer_1.BaseLayer {
22
22
  this.props.filled = true;
23
23
  this.props.multiline = {
24
24
  enabled: false,
25
+ spacing: 1.1,
26
+ };
27
+ this.props.size = {
25
28
  width: 'vw',
26
29
  height: 0,
27
- spacing: 1.1,
28
30
  };
29
31
  this.props.centring = enum_1.Centring.Center;
30
32
  }
@@ -73,10 +75,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
73
75
  setMultiline(enabled, width, height, spacing) {
74
76
  this.props.multiline = {
75
77
  enabled: enabled,
76
- width: width,
77
- height: height,
78
78
  spacing: spacing || 1.1,
79
79
  };
80
+ this.props.size = {
81
+ width,
82
+ height,
83
+ };
80
84
  return this;
81
85
  }
82
86
  /**
@@ -152,8 +156,8 @@ class TextLayer extends BaseLayer_1.BaseLayer {
152
156
  return this;
153
157
  }
154
158
  measureText(ctx, canvas) {
155
- const w = (0, utils_1.parseToNormal)(this.props.multiline?.width, ctx, canvas);
156
- const h = (0, utils_1.parseToNormal)(this.props.multiline?.height, ctx, canvas, { width: w, height: 0 }, { vertical: true });
159
+ const w = (0, utils_1.parseToNormal)(this.props.size?.width, ctx, canvas);
160
+ const h = (0, utils_1.parseToNormal)(this.props.size?.height, ctx, canvas, { width: w, height: 0 }, { vertical: true });
157
161
  if (this.props.multiline.enabled) {
158
162
  return { width: w, height: h };
159
163
  }
@@ -164,10 +168,13 @@ class TextLayer extends BaseLayer_1.BaseLayer {
164
168
  }
165
169
  }
166
170
  async draw(ctx, canvas, manager, debug) {
167
- const x = (0, utils_1.parseToNormal)(this.props.x, ctx, canvas);
168
- const y = (0, utils_1.parseToNormal)(this.props.y, ctx, canvas, { width: 0, height: 0 }, { vertical: true });
169
- const w = (0, utils_1.parseToNormal)(this.props.multiline?.width, ctx, canvas);
170
- const h = (0, utils_1.parseToNormal)(this.props.multiline?.height, ctx, canvas, { width: w, height: 0 }, { vertical: true });
171
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
172
+ const { x, y, w, h } = parcer.parseBatch({
173
+ x: { v: this.props.x },
174
+ y: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
175
+ w: { v: this.props.size?.width },
176
+ h: { v: this.props.size?.height, options: LazyUtil_1.defaultArg.vl(true) },
177
+ });
171
178
  if (debug)
172
179
  LazyUtil_1.LazyLog.log('none', `TextLayer:`, { x, y, w, h });
173
180
  ctx.save();
@@ -0,0 +1,22 @@
1
+ import { AnyLinkType, ILink, ScaleType } from "../../types";
2
+ export declare class Link {
3
+ source: string;
4
+ type: AnyLinkType;
5
+ additionalSpacing: ScaleType;
6
+ constructor(props?: ILink);
7
+ /**
8
+ * @description Sets the source of the link.
9
+ * @param source {string} - The `id` of the layer to link.
10
+ */
11
+ setSource(source: string): this;
12
+ /**
13
+ * @description Sets the type of the link.
14
+ * @param type {AnyLinkType} - The `type` of the link.
15
+ */
16
+ setType(type: AnyLinkType): this;
17
+ /**
18
+ * @description Sets the additional spacing of the link.
19
+ * @param additionalSpacing {ScaleType} - The `additionalSpacing` of the link.
20
+ */
21
+ setSpacing(additionalSpacing: ScaleType): this;
22
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Link = void 0;
4
+ const enum_1 = require("../../types/enum");
5
+ class Link {
6
+ source;
7
+ type;
8
+ additionalSpacing;
9
+ constructor(props) {
10
+ this.source = props?.source || '';
11
+ this.type = props?.type || enum_1.LinkType.Width;
12
+ this.additionalSpacing = props?.additionalSpacing || 0;
13
+ }
14
+ /**
15
+ * @description Sets the source of the link.
16
+ * @param source {string} - The `id` of the layer to link.
17
+ */
18
+ setSource(source) {
19
+ this.source = source;
20
+ return this;
21
+ }
22
+ /**
23
+ * @description Sets the type of the link.
24
+ * @param type {AnyLinkType} - The `type` of the link.
25
+ */
26
+ setType(type) {
27
+ this.type = type;
28
+ return this;
29
+ }
30
+ /**
31
+ * @description Sets the additional spacing of the link.
32
+ * @param additionalSpacing {ScaleType} - The `additionalSpacing` of the link.
33
+ */
34
+ setSpacing(additionalSpacing) {
35
+ this.additionalSpacing = additionalSpacing;
36
+ return this;
37
+ }
38
+ }
39
+ exports.Link = Link;
@@ -7,9 +7,9 @@ export declare class LayersManager implements ILayersManager {
7
7
  constructor(debug?: boolean);
8
8
  /**
9
9
  * Add a layer to the map
10
- * @param layers {AnyLayer[] | Group[]} - The `layer` or `group` to add to the map
10
+ * @param layers {AnyLayer[]} - The `layer` or `group` to add to the map
11
11
  */
12
- add(...layers: AnyLayer[] | Group[]): this;
12
+ add(...layers: AnyLayer[]): this;
13
13
  /**
14
14
  * Remove a layer from the map
15
15
  * @param ids {string[]} - The `id` of the layer or group to remove
@@ -22,8 +22,9 @@ export declare class LayersManager implements ILayersManager {
22
22
  /**
23
23
  * Get a layer from the map
24
24
  * @param id {string} - The `id` of the layer or group to get
25
+ * @param cross {boolean} - Whether to search in groups or not
25
26
  */
26
- get(id: string): AnyLayer | Group | undefined;
27
+ get(id: string, cross?: boolean): AnyLayer | undefined;
27
28
  /**
28
29
  * Check if a layer exists in the map
29
30
  * @param id {string} - The `id` of the layer or group to check
@@ -36,7 +37,7 @@ export declare class LayersManager implements ILayersManager {
36
37
  /**
37
38
  * Get the values of the map
38
39
  */
39
- values(): IterableIterator<AnyLayer | Group>;
40
+ values(): IterableIterator<AnyLayer>;
40
41
  /**
41
42
  * Get the keys of the map
42
43
  */
@@ -44,12 +45,12 @@ export declare class LayersManager implements ILayersManager {
44
45
  /**
45
46
  * Get the entries of the map
46
47
  */
47
- entries(): IterableIterator<[string, AnyLayer | Group]>;
48
+ entries(): IterableIterator<[string, AnyLayer]>;
48
49
  /**
49
50
  * For each layer in the map
50
51
  * @param callbackfn {Function} - The `callback` function to execute
51
52
  */
52
- forEach(callbackfn: (value: AnyLayer | Group, key: string, map: Map<string, AnyLayer | Group>) => void): this;
53
+ forEach(callbackfn: (value: AnyLayer, key: string, map: Map<string, AnyLayer>) => void): this;
53
54
  /**
54
55
  * Convert the map to a JSON object
55
56
  */
@@ -62,11 +63,12 @@ export declare class LayersManager implements ILayersManager {
62
63
  /**
63
64
  * Convert the map to an array
64
65
  */
65
- toArray(): Array<AnyLayer | Group>;
66
+ toArray(): Array<AnyLayer>;
66
67
  /**
67
68
  * Convert an array to the map
68
- * @param array {Array<AnyLayer | Group>} - The `array` to convert
69
+ * @param array {Array<AnyLayer>} - The `array` to convert
69
70
  */
70
- fromArray(array: Array<AnyLayer | Group>): this;
71
+ fromArray(array: Array<AnyLayer>): this;
71
72
  sort(): void;
73
+ private crossSearch;
72
74
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LayersManager = void 0;
4
+ const Group_1 = require("../components/Group");
4
5
  const LazyUtil_1 = require("../../utils/LazyUtil");
5
6
  class LayersManager {
6
7
  map;
@@ -11,7 +12,7 @@ class LayersManager {
11
12
  }
12
13
  /**
13
14
  * Add a layer to the map
14
- * @param layers {AnyLayer[] | Group[]} - The `layer` or `group` to add to the map
15
+ * @param layers {AnyLayer[]} - The `layer` or `group` to add to the map
15
16
  */
16
17
  add(...layers) {
17
18
  if (this.debug)
@@ -48,9 +49,13 @@ class LayersManager {
48
49
  /**
49
50
  * Get a layer from the map
50
51
  * @param id {string} - The `id` of the layer or group to get
52
+ * @param cross {boolean} - Whether to search in groups or not
51
53
  */
52
- get(id) {
53
- return this.map.get(id);
54
+ get(id, cross = false) {
55
+ if (cross)
56
+ return this.crossSearch(id);
57
+ else
58
+ return this.map.get(id);
54
59
  }
55
60
  /**
56
61
  * Check if a layer exists in the map
@@ -113,7 +118,7 @@ class LayersManager {
113
118
  }
114
119
  /**
115
120
  * Convert an array to the map
116
- * @param array {Array<AnyLayer | Group>} - The `array` to convert
121
+ * @param array {Array<AnyLayer>} - The `array` to convert
117
122
  */
118
123
  fromArray(array) {
119
124
  this.map = new Map(array.map(l => [l.id, l]));
@@ -122,5 +127,17 @@ class LayersManager {
122
127
  sort() {
123
128
  this.fromArray(this.toArray().sort((a, b) => a.zIndex - b.zIndex));
124
129
  }
130
+ crossSearch(id) {
131
+ for (const layer of this.map.values()) {
132
+ if (layer.id === id)
133
+ return layer;
134
+ if (layer instanceof Group_1.Group) {
135
+ const result = layer.components.find(l => l.id === id);
136
+ if (result)
137
+ return result;
138
+ }
139
+ }
140
+ return undefined;
141
+ }
125
142
  }
126
143
  exports.LayersManager = LayersManager;
@@ -14,9 +14,11 @@ export interface ITextLayerProps extends IBaseLayerProps {
14
14
  };
15
15
  multiline: {
16
16
  enabled: boolean;
17
+ spacing?: number;
18
+ };
19
+ size: {
17
20
  width: ScaleType;
18
21
  height: ScaleType;
19
- spacing?: number;
20
22
  };
21
23
  align: AnyTextAlign;
22
24
  baseline: AnyTextBaseline;
@@ -94,3 +94,9 @@ export declare enum PatternType {
94
94
  RepeatY = "repeat-y",
95
95
  NoRepeat = "no-repeat"
96
96
  }
97
+ export declare enum LinkType {
98
+ Width = "width",
99
+ Height = "height",
100
+ X = "x",
101
+ Y = "y"
102
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.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";
@@ -110,3 +110,10 @@ var PatternType;
110
110
  PatternType["RepeatY"] = "repeat-y";
111
111
  PatternType["NoRepeat"] = "no-repeat";
112
112
  })(PatternType || (exports.PatternType = PatternType = {}));
113
+ var LinkType;
114
+ (function (LinkType) {
115
+ LinkType["Width"] = "width";
116
+ LinkType["Height"] = "height";
117
+ LinkType["X"] = "x";
118
+ LinkType["Y"] = "y";
119
+ })(LinkType || (exports.LinkType = LinkType = {}));
@@ -0,0 +1,7 @@
1
+ import { AnyLinkType, ScaleType } from "../types";
2
+
3
+ export interface ILink {
4
+ source: string;
5
+ type: AnyLinkType;
6
+ additionalSpacing: ScaleType;
7
+ }
@@ -1,16 +1,17 @@
1
- export * from "./types";
2
- export * from "./components/BaseLayer";
3
- export * from "./components/TextLayer";
4
- export * from "./components/ImageLayer";
5
- export * from "./components/MorphLayer";
6
- export * from "./components/BezierLayer";
7
- export * from "./components/QuadraticLayer";
8
- export * from "./components/LineLayer";
9
- export * from "./components/Group";
10
- export * from "./helpers/Font";
11
- export * from "./helpers/Gradient";
12
- export * from "./helpers/Pattern";
13
- export * from "./managers/LayersManager";
14
- export * from "./managers/RenderManager";
15
- export * from "./managers/FontsManager";
16
- export * from "./LazyCanvas";
1
+ export type * from "./types";
2
+ export type * from "./components/BaseLayer";
3
+ export type * from "./components/TextLayer";
4
+ export type * from "./components/ImageLayer";
5
+ export type * from "./components/MorphLayer";
6
+ export type * from "./components/BezierLayer";
7
+ export type * from "./components/QuadraticLayer";
8
+ export type * from "./components/LineLayer";
9
+ export type * from "./components/Group";
10
+ export type * from "./helpers/Font";
11
+ export type * from "./helpers/Gradient";
12
+ export type * from "./helpers/Pattern";
13
+ export type * from "./helpers/Link";
14
+ export type * from "./managers/LayersManager";
15
+ export type * from "./managers/RenderManager";
16
+ export type * from "./managers/FontsManager";
17
+ export type * from "./LazyCanvas";
@@ -7,9 +7,23 @@ 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 { FontWeight, GradientType, TextAlign, TextBaseline, TextDirection, LineCap, LineJoin, Export, Centring, PatternType, SaveFormat } from "./enum";
11
-
12
- export type ScaleType = string | number | 'vw' | 'vh' | 'vmin' | 'vmax';
10
+ import { Link } from "../structures/helpers/Link";
11
+ import {
12
+ FontWeight,
13
+ GradientType,
14
+ TextAlign,
15
+ TextBaseline,
16
+ TextDirection,
17
+ LineCap,
18
+ LineJoin,
19
+ Export,
20
+ Centring,
21
+ PatternType,
22
+ SaveFormat,
23
+ LinkType
24
+ } from "./enum";
25
+
26
+ export type ScaleType = string | number | 'vw' | 'vh' | 'vmin' | 'vmax' | Link;
13
27
 
14
28
  export type ColorType = string | Gradient | Pattern;
15
29
 
@@ -37,6 +51,8 @@ export type AnyPatternType = PatternType | 'repeat' | 'repeat-x' | 'repeat-y' |
37
51
 
38
52
  export type AnySaveFormat = SaveFormat | 'png' | 'jpeg' | 'jpg' | 'svg';
39
53
 
54
+ export type AnyLinkType = LinkType | 'width' | 'height' | 'x' | 'y';
55
+
40
56
  export type Point = {
41
57
  x: ScaleType;
42
58
  y: ScaleType;
@@ -5,3 +5,13 @@ export declare class LazyError extends Error {
5
5
  export declare class LazyLog {
6
6
  static log(type?: string, ...message: any): void;
7
7
  }
8
+ export declare const defaultArg: {
9
+ wh(w?: number, h?: number): {
10
+ width: number;
11
+ height: number;
12
+ };
13
+ vl(vertical?: boolean, layer?: boolean): {
14
+ vertical: boolean;
15
+ layer: boolean;
16
+ };
17
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LazyLog = exports.LazyError = void 0;
3
+ exports.defaultArg = exports.LazyLog = exports.LazyError = void 0;
4
4
  class LazyError extends Error {
5
5
  message;
6
6
  constructor(message) {
@@ -25,3 +25,11 @@ class LazyLog {
25
25
  }
26
26
  }
27
27
  exports.LazyLog = LazyLog;
28
+ exports.defaultArg = {
29
+ wh(w, h) {
30
+ return { width: w || 0, height: h || 0 };
31
+ },
32
+ vl(vertical, layer) {
33
+ return { vertical: vertical || false, layer: layer || false };
34
+ }
35
+ };
@@ -15,6 +15,26 @@ export declare function parseToNormal(v: ScaleType, ctx: SKRSContext2D, canvas:
15
15
  vertical?: boolean;
16
16
  layer?: boolean;
17
17
  }, manager?: LayersManager): number;
18
+ export declare function parser(ctx: SKRSContext2D, canvas: Canvas, manager?: LayersManager): {
19
+ parse(v: ScaleType, layer?: {
20
+ width: number;
21
+ height: number;
22
+ }, options?: {
23
+ vertical?: boolean;
24
+ layer?: boolean;
25
+ }): number;
26
+ parseBatch(values: Record<string, {
27
+ v: ScaleType;
28
+ layer?: {
29
+ width: number;
30
+ height: number;
31
+ };
32
+ options?: {
33
+ vertical?: boolean;
34
+ layer?: boolean;
35
+ };
36
+ }>): Record<string, number>;
37
+ };
18
38
  export declare function drawShadow(ctx: SKRSContext2D, shadow: any): void;
19
39
  export declare function opacity(ctx: SKRSContext2D, opacity: number): void;
20
40
  export declare function filters(ctx: SKRSContext2D, filters: string): void;
@@ -23,13 +23,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getBoundingBoxBezier = exports.centring = exports.isImageUrlValid = exports.generateRandomName = exports.saveFile = exports.transform = exports.parseFillStyle = exports.filters = exports.opacity = exports.drawShadow = exports.parseToNormal = exports.parseColor = exports.parseHex = exports.isColor = exports.generateID = void 0;
26
+ exports.getBoundingBoxBezier = exports.centring = exports.isImageUrlValid = exports.generateRandomName = exports.saveFile = exports.transform = exports.parseFillStyle = exports.filters = exports.opacity = exports.drawShadow = exports.parser = exports.parseToNormal = exports.parseColor = exports.parseHex = exports.isColor = exports.generateID = void 0;
27
27
  const enum_1 = require("../types/enum");
28
28
  const Gradient_1 = require("../structures/helpers/Gradient");
29
29
  const LazyUtil_1 = require("./LazyUtil");
30
30
  const fs = __importStar(require("fs"));
31
31
  const jimp = __importStar(require("jimp"));
32
32
  const Pattern_1 = require("../structures/helpers/Pattern");
33
+ const Link_1 = require("../structures/helpers/Link");
34
+ const Group_1 = require("../structures/components/Group");
35
+ const LineLayer_1 = require("../structures/components/LineLayer");
36
+ const BezierLayer_1 = require("../structures/components/BezierLayer");
37
+ const QuadraticLayer_1 = require("../structures/components/QuadraticLayer");
33
38
  const TextLayer_1 = require("../structures/components/TextLayer");
34
39
  function generateID(type) {
35
40
  return `${type}-${Math.random().toString(36).substr(2, 9)}`;
@@ -38,7 +43,7 @@ exports.generateID = generateID;
38
43
  let percentReg = /^(\d+)%$/;
39
44
  let pxReg = /^(\d+)px$/;
40
45
  let canvasReg = /^(vw|vh|vmin|vmax)$/;
41
- let linkReg = /^(link-w|link-h)-([A-Za-z0-9_]+)-(\d+)$/;
46
+ let linkReg = /^(link-w|link-h|link-x|link-y)-([A-Za-z0-9_]+)-(\d+)$/;
42
47
  let hexReg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
43
48
  let rgbReg = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/;
44
49
  let rgbaReg = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(0|0?\.\d+|1(\.0)?)\)$/;
@@ -120,47 +125,169 @@ function parseToNormal(v, ctx, canvas, layer = { width: 0, height: 0 }, options
120
125
  if (typeof v === 'number') {
121
126
  return v;
122
127
  }
123
- else if (percentReg.test(v)) {
124
- return (parseFloat(v) / 100) * (options.layer ? (options.vertical ? layer.width : layer.height) : (options.vertical ? canvas.width : canvas.height));
125
- }
126
- else if (pxReg.test(v)) {
127
- return parseFloat(v);
128
- }
129
- else if (canvasReg.test(v)) {
130
- if (v === 'vw') {
131
- return (options.layer ? layer.width : canvas.width);
128
+ else if (typeof v === 'string') {
129
+ if (percentReg.test(v)) {
130
+ return (parseFloat(v) / 100) * (options.layer ? (options.vertical ? layer.width : layer.height) : (options.vertical ? canvas.width : canvas.height));
132
131
  }
133
- else if (v === 'vh') {
134
- return (options.layer ? layer.height : canvas.height);
132
+ else if (pxReg.test(v)) {
133
+ return parseFloat(v);
135
134
  }
136
- else if (v === 'vmin') {
137
- return (options.layer ? Math.max(layer.width, layer.height) : Math.min(canvas.width, canvas.height));
135
+ else if (canvasReg.test(v)) {
136
+ if (v === 'vw') {
137
+ return (options.layer ? layer.width : canvas.width);
138
+ }
139
+ else if (v === 'vh') {
140
+ return (options.layer ? layer.height : canvas.height);
141
+ }
142
+ else if (v === 'vmin') {
143
+ return (options.layer ? Math.max(layer.width, layer.height) : Math.min(canvas.width, canvas.height));
144
+ }
145
+ else if (v === 'vmax') {
146
+ return (options.layer ? Math.max(layer.width, layer.height) : Math.max(canvas.width, canvas.height));
147
+ }
138
148
  }
139
- else if (v === 'vmax') {
140
- return (options.layer ? Math.max(layer.width, layer.height) : Math.max(canvas.width, canvas.height));
149
+ else if (linkReg.test(v)) {
150
+ let match = v.match(linkReg);
151
+ if (!manager)
152
+ return 0;
153
+ let anyLayer = manager.get(match[2], true);
154
+ const parcer = parser(ctx, canvas, manager);
155
+ switch (match[1]) {
156
+ case 'link-w':
157
+ if (anyLayer && !(anyLayer instanceof Group_1.Group)) {
158
+ if (anyLayer instanceof LineLayer_1.LineLayer || anyLayer instanceof BezierLayer_1.BezierLayer || anyLayer instanceof QuadraticLayer_1.QuadraticLayer) {
159
+ return anyLayer.getBoundingBox(ctx, canvas, manager).width + (parseInt(match[3]) || 0);
160
+ }
161
+ else if (anyLayer instanceof TextLayer_1.TextLayer) {
162
+ return anyLayer.measureText(ctx, canvas).width + (parseInt(match[3]) || 0);
163
+ }
164
+ else {
165
+ return (parcer.parse(anyLayer.props.size.width) || 0) + (parseInt(match[3]) || 0);
166
+ }
167
+ }
168
+ else {
169
+ return 0;
170
+ }
171
+ break;
172
+ case 'link-h':
173
+ if (anyLayer && !(anyLayer instanceof Group_1.Group)) {
174
+ if (anyLayer instanceof LineLayer_1.LineLayer || anyLayer instanceof BezierLayer_1.BezierLayer || anyLayer instanceof QuadraticLayer_1.QuadraticLayer) {
175
+ return anyLayer.getBoundingBox(ctx, canvas, manager).height + (parseInt(match[3]) || 0);
176
+ }
177
+ else if (anyLayer instanceof TextLayer_1.TextLayer) {
178
+ return anyLayer.measureText(ctx, canvas).height + (parseInt(match[3]) || 0);
179
+ }
180
+ else {
181
+ return (parcer.parse(anyLayer.props.size.height, LazyUtil_1.defaultArg.wh(parcer.parse(anyLayer.props.size.width)), LazyUtil_1.defaultArg.vl(true)) || 0) + (parseInt(match[3]) || 0);
182
+ }
183
+ }
184
+ else {
185
+ return 0;
186
+ }
187
+ break;
188
+ case 'link-x':
189
+ if (anyLayer && !(anyLayer instanceof Group_1.Group)) {
190
+ return (parcer.parse(anyLayer.props.x) || 0) + (parseInt(match[3]) || 0);
191
+ }
192
+ else {
193
+ return 0;
194
+ }
195
+ break;
196
+ case 'link-y':
197
+ if (anyLayer && !(anyLayer instanceof Group_1.Group)) {
198
+ return (parcer.parse(anyLayer.props.y, LazyUtil_1.defaultArg.wh(), LazyUtil_1.defaultArg.vl(true)) || 0) + (parseInt(match[3]) || 0);
199
+ }
200
+ else {
201
+ return 0;
202
+ }
203
+ break;
204
+ }
141
205
  }
142
206
  }
143
- else if (linkReg.test(v)) {
144
- let match = v.match(linkReg);
207
+ else if (v instanceof Link_1.Link) {
145
208
  if (!manager)
146
209
  return 0;
147
- let layer = manager.get(match[2]);
148
- switch (match[1]) {
149
- case 'link-w':
150
- if (layer instanceof TextLayer_1.TextLayer) {
151
- return layer.measureText(ctx, canvas).width + (parseInt(match[3]) || 0);
210
+ let anyLayer = manager.get(v.source, true);
211
+ const parcer = parser(ctx, canvas, manager);
212
+ switch (v.type) {
213
+ case enum_1.LinkType.Width:
214
+ case 'width':
215
+ if (anyLayer && !(anyLayer instanceof Group_1.Group)) {
216
+ if (anyLayer instanceof LineLayer_1.LineLayer || anyLayer instanceof BezierLayer_1.BezierLayer || anyLayer instanceof QuadraticLayer_1.QuadraticLayer) {
217
+ return anyLayer.getBoundingBox(ctx, canvas, manager).width + (parcer.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0);
218
+ }
219
+ else if (anyLayer instanceof TextLayer_1.TextLayer) {
220
+ return anyLayer.measureText(ctx, canvas).width + (parcer.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0);
221
+ }
222
+ else {
223
+ return (parcer.parse(anyLayer.props.size.width) || 0) + (parcer.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0);
224
+ }
225
+ }
226
+ else {
227
+ return 0;
152
228
  }
153
229
  break;
154
- case 'link-h':
155
- if (layer instanceof TextLayer_1.TextLayer) {
156
- return layer.measureText(ctx, canvas).height + (parseInt(match[3]) || 0);
230
+ case enum_1.LinkType.Height:
231
+ case 'height':
232
+ if (anyLayer && !(anyLayer instanceof Group_1.Group)) {
233
+ if (anyLayer instanceof LineLayer_1.LineLayer || anyLayer instanceof BezierLayer_1.BezierLayer || anyLayer instanceof QuadraticLayer_1.QuadraticLayer) {
234
+ return anyLayer.getBoundingBox(ctx, canvas, manager).height + (parcer.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0);
235
+ }
236
+ else if (anyLayer instanceof TextLayer_1.TextLayer) {
237
+ return anyLayer.measureText(ctx, canvas).height + (parcer.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0);
238
+ }
239
+ else {
240
+ return (parcer.parse(anyLayer.props.size.height, LazyUtil_1.defaultArg.wh(parcer.parse(anyLayer.props.size.width)), LazyUtil_1.defaultArg.vl(true)) || 0) + (parcer.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0);
241
+ }
242
+ }
243
+ else {
244
+ return 0;
245
+ }
246
+ break;
247
+ case enum_1.LinkType.X:
248
+ case 'x':
249
+ if (anyLayer && !(anyLayer instanceof Group_1.Group)) {
250
+ return (parcer.parse(anyLayer.props.x) || 0) + (parcer.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0);
251
+ }
252
+ else {
253
+ return 0;
254
+ }
255
+ break;
256
+ case enum_1.LinkType.Y:
257
+ case 'y':
258
+ if (anyLayer && !(anyLayer instanceof Group_1.Group)) {
259
+ return (parcer.parse(anyLayer.props.y) || 0) + (parcer.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0);
260
+ }
261
+ else {
262
+ return 0;
157
263
  }
158
264
  break;
265
+ default:
266
+ return 0;
159
267
  }
160
268
  }
269
+ else {
270
+ return 0;
271
+ }
161
272
  return 0;
162
273
  }
163
274
  exports.parseToNormal = parseToNormal;
275
+ function parser(ctx, canvas, manager) {
276
+ return {
277
+ parse(v, layer = LazyUtil_1.defaultArg.wh(), options = LazyUtil_1.defaultArg.vl()) {
278
+ return parseToNormal(v, ctx, canvas, layer, options, manager);
279
+ },
280
+ parseBatch(values) {
281
+ const result = {};
282
+ for (const key in values) {
283
+ const { v, layer, options } = values[key];
284
+ result[key] = parseToNormal(v, ctx, canvas, layer ?? LazyUtil_1.defaultArg.wh(), options ?? LazyUtil_1.defaultArg.vl(), manager);
285
+ }
286
+ return result;
287
+ }
288
+ };
289
+ }
290
+ exports.parser = parser;
164
291
  function drawShadow(ctx, shadow) {
165
292
  if (shadow) {
166
293
  ctx.shadowColor = shadow.color;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmmty/lazycanvas",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
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",