@nmmty/lazycanvas 0.6.5 → 1.0.0-dev.3

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 (80) hide show
  1. package/ReadMe.md +1 -1
  2. package/biome.json +41 -0
  3. package/dist/core/Interpolation.d.ts +30 -0
  4. package/dist/core/Interpolation.js +200 -0
  5. package/dist/core/Scene.d.ts +96 -0
  6. package/dist/core/Scene.js +172 -0
  7. package/dist/core/Signal.d.ts +133 -0
  8. package/dist/core/Signal.js +255 -0
  9. package/dist/core/SignalUtils.d.ts +133 -0
  10. package/dist/core/SignalUtils.js +333 -0
  11. package/dist/core/ThreadScheduler.d.ts +38 -0
  12. package/dist/core/ThreadScheduler.js +74 -0
  13. package/dist/helpers/Filters.js +1 -1
  14. package/dist/helpers/FontsList.js +18 -18
  15. package/dist/helpers/Utlis.d.ts +3 -3
  16. package/dist/helpers/Utlis.js +15 -18
  17. package/dist/helpers/index.d.ts +3 -3
  18. package/dist/index.d.ts +10 -0
  19. package/dist/index.js +10 -0
  20. package/dist/jsx-runtime.d.ts +17 -0
  21. package/dist/jsx-runtime.js +111 -0
  22. package/dist/structures/LazyCanvas.d.ts +3 -45
  23. package/dist/structures/LazyCanvas.js +11 -74
  24. package/dist/structures/components/BaseLayer.d.ts +34 -12
  25. package/dist/structures/components/BaseLayer.js +68 -35
  26. package/dist/structures/components/BezierLayer.d.ts +16 -37
  27. package/dist/structures/components/BezierLayer.js +83 -46
  28. package/dist/structures/components/{Group.d.ts → Div.d.ts} +22 -16
  29. package/dist/structures/components/{Group.js → Div.js} +38 -39
  30. package/dist/structures/components/ImageLayer.d.ts +1 -1
  31. package/dist/structures/components/ImageLayer.js +24 -25
  32. package/dist/structures/components/LineLayer.d.ts +11 -37
  33. package/dist/structures/components/LineLayer.js +42 -42
  34. package/dist/structures/components/MorphLayer.d.ts +3 -32
  35. package/dist/structures/components/MorphLayer.js +32 -46
  36. package/dist/structures/components/Path2DLayer.d.ts +4 -32
  37. package/dist/structures/components/Path2DLayer.js +28 -33
  38. package/dist/structures/components/PolygonLayer.d.ts +2 -31
  39. package/dist/structures/components/PolygonLayer.js +35 -38
  40. package/dist/structures/components/QuadraticLayer.d.ts +16 -33
  41. package/dist/structures/components/QuadraticLayer.js +80 -42
  42. package/dist/structures/components/TextLayer.d.ts +4 -33
  43. package/dist/structures/components/TextLayer.js +60 -62
  44. package/dist/structures/components/index.d.ts +10 -11
  45. package/dist/structures/components/index.js +1 -2
  46. package/dist/structures/helpers/Exporter.d.ts +13 -4
  47. package/dist/structures/helpers/Exporter.js +79 -42
  48. package/dist/structures/helpers/Font.js +1 -17
  49. package/dist/structures/helpers/Gradient.js +32 -45
  50. package/dist/structures/helpers/Link.js +2 -14
  51. package/dist/structures/helpers/Pattern.js +9 -17
  52. package/dist/structures/helpers/index.d.ts +7 -7
  53. package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
  54. package/dist/structures/helpers/readers/JSONReader.js +32 -40
  55. package/dist/structures/helpers/readers/YAMLReader.js +5 -5
  56. package/dist/structures/managers/FontsManager.js +9 -18
  57. package/dist/structures/managers/LayersManager.d.ts +18 -28
  58. package/dist/structures/managers/LayersManager.js +14 -36
  59. package/dist/structures/managers/RenderManager.d.ts +1 -15
  60. package/dist/structures/managers/RenderManager.js +17 -110
  61. package/dist/structures/managers/index.d.ts +3 -5
  62. package/dist/structures/managers/index.js +0 -2
  63. package/dist/types/enum.d.ts +1 -2
  64. package/dist/types/enum.js +1 -2
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/utils/APNGEncoder.d.ts +67 -0
  67. package/dist/utils/APNGEncoder.js +205 -0
  68. package/dist/utils/DrawUtils.d.ts +9 -0
  69. package/dist/utils/DrawUtils.js +42 -0
  70. package/dist/utils/LazyUtil.js +1 -2
  71. package/dist/utils/utils.d.ts +4 -7
  72. package/dist/utils/utils.js +133 -76
  73. package/package.json +62 -59
  74. package/dist/structures/components/ClearLayer.d.ts +0 -147
  75. package/dist/structures/components/ClearLayer.js +0 -158
  76. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  77. package/dist/structures/managers/AnimationManager.js +0 -99
  78. package/dist/structures/managers/PluginManager.d.ts +0 -230
  79. package/dist/structures/managers/PluginManager.js +0 -182
  80. package/dist/types/types.d.ts +0 -107
@@ -0,0 +1,9 @@
1
+ import { SKRSContext2D } from "@napi-rs/canvas";
2
+ import { Signal } from "../core/Signal";
3
+ import { StrokeOptions } from "../types";
4
+ export declare class DrawUtils {
5
+ static drawShadow(ctx: SKRSContext2D, shadow: any): void;
6
+ static opacity(ctx: SKRSContext2D, opacity?: number | Signal<number>): void;
7
+ static filters(ctx: SKRSContext2D, filters: string | null | undefined): void;
8
+ static fillStyle(ctx: SKRSContext2D, color: string | CanvasGradient | CanvasPattern, fillStyle?: StrokeOptions): void;
9
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DrawUtils = void 0;
4
+ const Signal_1 = require("../core/Signal");
5
+ class DrawUtils {
6
+ static drawShadow(ctx, shadow) {
7
+ if (shadow) {
8
+ ctx.shadowColor = shadow.color;
9
+ ctx.shadowBlur = shadow.blur || 0;
10
+ ctx.shadowOffsetX = shadow.offsetX || 0;
11
+ ctx.shadowOffsetY = shadow.offsetY || 0;
12
+ }
13
+ }
14
+ static opacity(ctx, opacity = 1) {
15
+ const opacityValue = (0, Signal_1.unwrap)(opacity);
16
+ if (opacityValue < 1) {
17
+ ctx.globalAlpha = opacityValue;
18
+ }
19
+ }
20
+ static filters(ctx, filters) {
21
+ if (filters) {
22
+ ctx.filter = filters;
23
+ }
24
+ }
25
+ static fillStyle(ctx, color, fillStyle) {
26
+ if (fillStyle) {
27
+ ctx.lineWidth = fillStyle.width;
28
+ ctx.lineCap = fillStyle.cap || "butt";
29
+ ctx.lineJoin = fillStyle.join || "miter";
30
+ ctx.miterLimit = fillStyle.miterLimit || 10;
31
+ if (fillStyle.dash) {
32
+ ctx.setLineDash(fillStyle.dash);
33
+ ctx.lineDashOffset = fillStyle.dashOffset || 0;
34
+ }
35
+ ctx.strokeStyle = color;
36
+ }
37
+ else {
38
+ ctx.fillStyle = color;
39
+ }
40
+ }
41
+ }
42
+ exports.DrawUtils = DrawUtils;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultArg = exports.LazyLog = exports.LazyError = void 0;
4
4
  class LazyError extends Error {
5
- message;
6
5
  constructor(message) {
7
6
  super(message);
8
7
  this.message = "[LazyCanvas] [ERROR] " + message;
@@ -31,5 +30,5 @@ exports.defaultArg = {
31
30
  },
32
31
  vl(vertical, layer) {
33
32
  return { vertical: vertical || false, layer: layer || false };
34
- }
33
+ },
35
34
  };
@@ -1,9 +1,9 @@
1
1
  import { AnyCentring, AnyLayer, AnyTextAlign, ColorType, LayerType, PointNumber, ScaleType, SubStringColor, Transform } from "../types";
2
2
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
3
3
  import { LayersManager } from "../structures/managers";
4
- import { Group } from "../structures/components";
4
+ import { Div } from "../structures/components";
5
5
  export declare function generateID(type: string): string;
6
- export declare function isColor(v: ColorType | SubStringColor): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
6
+ export declare function isColor(v: ColorType | SubStringColor): boolean;
7
7
  export declare function parseToNormal(v: ScaleType, ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, layer?: {
8
8
  width: number;
9
9
  height: number;
@@ -31,9 +31,6 @@ export declare function parser(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, m
31
31
  };
32
32
  }>): Record<string, number>;
33
33
  };
34
- export declare function drawShadow(ctx: SKRSContext2D, shadow: any): void;
35
- export declare function opacity(ctx: SKRSContext2D, opacity?: number): void;
36
- export declare function filters(ctx: SKRSContext2D, filters: string | null | undefined): void;
37
34
  export declare function parseFillStyle(ctx: SKRSContext2D, color: ColorType | SubStringColor, opts: {
38
35
  debug?: boolean;
39
36
  layer?: {
@@ -44,7 +41,7 @@ export declare function parseFillStyle(ctx: SKRSContext2D, color: ColorType | Su
44
41
  align: AnyCentring;
45
42
  };
46
43
  manager?: LayersManager;
47
- }): string | CanvasGradient | Promise<CanvasPattern>;
44
+ }): string | Promise<CanvasPattern> | CanvasGradient;
48
45
  export declare function transform(ctx: SKRSContext2D, transform: Transform, layer?: {
49
46
  width: number;
50
47
  height: number;
@@ -80,4 +77,4 @@ export declare function getBoundingBoxBezier(points: PointNumber[], steps?: numb
80
77
  height: number;
81
78
  };
82
79
  export declare function resize(value: ScaleType, ratio: number): number | string;
83
- export declare function resizeLayers(layers: Array<AnyLayer | Group>, ratio: number): (AnyLayer | Group)[];
80
+ export declare function resizeLayers(layers: Array<AnyLayer | Div>, ratio: number): (AnyLayer | Div)[];
@@ -4,9 +4,6 @@ exports.generateID = generateID;
4
4
  exports.isColor = isColor;
5
5
  exports.parseToNormal = parseToNormal;
6
6
  exports.parser = parser;
7
- exports.drawShadow = drawShadow;
8
- exports.opacity = opacity;
9
- exports.filters = filters;
10
7
  exports.parseFillStyle = parseFillStyle;
11
8
  exports.transform = transform;
12
9
  exports.generateRandomName = generateRandomName;
@@ -20,6 +17,7 @@ const helpers_1 = require("../structures/helpers");
20
17
  const canvas_1 = require("@napi-rs/canvas");
21
18
  const LazyUtil_1 = require("./LazyUtil");
22
19
  const components_1 = require("../structures/components");
20
+ const Signal_1 = require("../core/Signal");
23
21
  function generateID(type) {
24
22
  return `${type}-${Math.random().toString(36).substr(2, 9)}`;
25
23
  }
@@ -33,16 +31,41 @@ let rgbaReg = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(0|0?\.\d+|1(\.0)?)\)$/;
33
31
  let hslReg = /^hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)$/;
34
32
  let hslaReg = /^hsla\((\d+),\s*(\d+)%,\s*(\d+)%,\s*(0|0?\.\d+|1(\.0)?)\)$/;
35
33
  function isColor(v) {
36
- return typeof (v === 'string' && (hexReg.test(v) || rgbReg.test(v) || rgbaReg.test(v) || hslReg.test(v) || hslaReg.test(v))) || v instanceof helpers_1.Gradient || v instanceof helpers_1.Pattern || (typeof v === 'object' && (v.start && v.end && v.color));
34
+ if ((0, Signal_1.isSignal)(v)) {
35
+ return true;
36
+ }
37
+ if (typeof v === "object" &&
38
+ v !== null &&
39
+ !(0, Signal_1.isSignal)(v) &&
40
+ "start" in v &&
41
+ "end" in v &&
42
+ "color" in v) {
43
+ return true;
44
+ }
45
+ if (v instanceof helpers_1.Gradient || v instanceof helpers_1.Pattern) {
46
+ return true;
47
+ }
48
+ if (typeof v === "string") {
49
+ return hexReg.test(v) || rgbReg.test(v) || rgbaReg.test(v) || hslReg.test(v) || hslaReg.test(v);
50
+ }
51
+ return false;
37
52
  }
38
53
  function parseToNormal(v, ctx, canvas, layer = { width: 0, height: 0 }, options = { vertical: false, layer: false }, manager) {
39
- if (typeof v === 'number')
54
+ // Unwrap signal if present
55
+ if ((0, Signal_1.isSignal)(v)) {
56
+ v = (0, Signal_1.unwrap)(v);
57
+ }
58
+ if (typeof v === "number")
40
59
  return v;
41
- if (typeof v === 'string') {
60
+ if (typeof v === "string") {
42
61
  if (percentReg.test(v)) {
43
62
  const base = options.layer
44
- ? options.vertical ? layer.height : layer.width
45
- : options.vertical ? canvas.height : canvas.width;
63
+ ? options.vertical
64
+ ? layer.height
65
+ : layer.width
66
+ : options.vertical
67
+ ? canvas.height
68
+ : canvas.width;
46
69
  return (parseFloat(v) / 100) * base;
47
70
  }
48
71
  if (pxReg.test(v))
@@ -50,10 +73,14 @@ function parseToNormal(v, ctx, canvas, layer = { width: 0, height: 0 }, options
50
73
  if (canvasReg.test(v)) {
51
74
  const base = options.layer ? layer : canvas;
52
75
  switch (v) {
53
- case 'vw': return base.width;
54
- case 'vh': return base.height;
55
- case 'vmin': return Math.min(base.width, base.height);
56
- case 'vmax': return Math.max(base.width, base.height);
76
+ case "vw":
77
+ return base.width;
78
+ case "vh":
79
+ return base.height;
80
+ case "vmin":
81
+ return Math.min(base.width, base.height);
82
+ case "vmax":
83
+ return Math.max(base.width, base.height);
57
84
  }
58
85
  }
59
86
  if (linkReg.test(v)) {
@@ -61,15 +88,19 @@ function parseToNormal(v, ctx, canvas, layer = { width: 0, height: 0 }, options
61
88
  if (!manager)
62
89
  return 0;
63
90
  const anyLayer = manager.get(match[2], true);
64
- if (!anyLayer || anyLayer instanceof components_1.Group || anyLayer instanceof components_1.Path2DLayer)
91
+ if (!anyLayer || anyLayer instanceof components_1.Div || anyLayer instanceof components_1.Path2DLayer)
65
92
  return 0;
66
93
  const parserInstance = parser(ctx, canvas, manager);
67
94
  const additionalSpacing = parseInt(match[3]) || 0;
68
95
  switch (match[1]) {
69
- case 'link-w': return getLayerWidth(anyLayer, ctx, canvas, manager, parserInstance) + additionalSpacing;
70
- case 'link-h': return getLayerHeight(anyLayer, ctx, canvas, manager, parserInstance) + additionalSpacing;
71
- case 'link-x': return parserInstance.parse(anyLayer.props.x) + additionalSpacing;
72
- case 'link-y': return parserInstance.parse(anyLayer.props.y) + additionalSpacing;
96
+ case "link-w":
97
+ return getLayerWidth(anyLayer, ctx, canvas, manager, parserInstance) + additionalSpacing;
98
+ case "link-h":
99
+ return getLayerHeight(anyLayer, ctx, canvas, manager, parserInstance) + additionalSpacing;
100
+ case "link-x":
101
+ return parserInstance.parse(anyLayer.props.position.x) + additionalSpacing;
102
+ case "link-y":
103
+ return parserInstance.parse(anyLayer.props.position.y) + additionalSpacing;
73
104
  }
74
105
  }
75
106
  }
@@ -77,21 +108,27 @@ function parseToNormal(v, ctx, canvas, layer = { width: 0, height: 0 }, options
77
108
  if (!manager)
78
109
  return 0;
79
110
  const anyLayer = manager.get(v.source, true);
80
- if (!anyLayer || anyLayer instanceof components_1.Group || anyLayer instanceof components_1.Path2DLayer)
111
+ if (!anyLayer || anyLayer instanceof components_1.Div || anyLayer instanceof components_1.Path2DLayer)
81
112
  return 0;
82
113
  const parserInstance = parser(ctx, canvas, manager);
83
114
  const additionalSpacing = parserInstance.parse(v.additionalSpacing, LazyUtil_1.defaultArg.wh(layer.width, layer.height), LazyUtil_1.defaultArg.vl(options.vertical, options.layer)) || 0;
84
115
  switch (v.type) {
85
- case types_1.LinkType.Width: return getLayerWidth(anyLayer, ctx, canvas, manager, parserInstance) + additionalSpacing;
86
- case types_1.LinkType.Height: return getLayerHeight(anyLayer, ctx, canvas, manager, parserInstance) + additionalSpacing;
87
- case types_1.LinkType.X: return parserInstance.parse(anyLayer.props.x) + additionalSpacing;
88
- case types_1.LinkType.Y: return parserInstance.parse(anyLayer.props.y) + additionalSpacing;
116
+ case types_1.LinkType.Width:
117
+ return getLayerWidth(anyLayer, ctx, canvas, manager, parserInstance) + additionalSpacing;
118
+ case types_1.LinkType.Height:
119
+ return getLayerHeight(anyLayer, ctx, canvas, manager, parserInstance) + additionalSpacing;
120
+ case types_1.LinkType.X:
121
+ return parserInstance.parse(anyLayer.props.position.x) + additionalSpacing;
122
+ case types_1.LinkType.Y:
123
+ return parserInstance.parse(anyLayer.props.position.y) + additionalSpacing;
89
124
  }
90
125
  }
91
126
  return 0;
92
127
  }
93
128
  function getLayerWidth(anyLayer, ctx, canvas, manager, parserInstance) {
94
- if (anyLayer instanceof components_1.LineLayer || anyLayer instanceof components_1.BezierLayer || anyLayer instanceof components_1.QuadraticLayer) {
129
+ if (anyLayer instanceof components_1.LineLayer ||
130
+ anyLayer instanceof components_1.BezierLayer ||
131
+ anyLayer instanceof components_1.QuadraticLayer) {
95
132
  return anyLayer.getBoundingBox(ctx, canvas, manager).width;
96
133
  }
97
134
  if (anyLayer instanceof components_1.TextLayer) {
@@ -100,13 +137,17 @@ function getLayerWidth(anyLayer, ctx, canvas, manager, parserInstance) {
100
137
  return anyLayer instanceof components_1.Path2DLayer ? 0 : parserInstance.parse(anyLayer.props.size.width) || 0;
101
138
  }
102
139
  function getLayerHeight(anyLayer, ctx, canvas, manager, parserInstance) {
103
- if (anyLayer instanceof components_1.LineLayer || anyLayer instanceof components_1.BezierLayer || anyLayer instanceof components_1.QuadraticLayer) {
140
+ if (anyLayer instanceof components_1.LineLayer ||
141
+ anyLayer instanceof components_1.BezierLayer ||
142
+ anyLayer instanceof components_1.QuadraticLayer) {
104
143
  return anyLayer.getBoundingBox(ctx, canvas, manager).height;
105
144
  }
106
145
  if (anyLayer instanceof components_1.TextLayer) {
107
146
  return anyLayer.measureText(ctx, canvas).height;
108
147
  }
109
- return anyLayer instanceof components_1.Path2DLayer ? 0 : parserInstance.parse(anyLayer.props.size.height) || 0;
148
+ return anyLayer instanceof components_1.Path2DLayer
149
+ ? 0
150
+ : parserInstance.parse(anyLayer.props.size.height) || 0;
110
151
  }
111
152
  function parser(ctx, canvas, manager) {
112
153
  return {
@@ -120,44 +161,44 @@ function parser(ctx, canvas, manager) {
120
161
  result[key] = parseToNormal(v, ctx, canvas, layer ?? LazyUtil_1.defaultArg.wh(), options ?? LazyUtil_1.defaultArg.vl(), manager);
121
162
  }
122
163
  return result;
123
- }
164
+ },
124
165
  };
125
166
  }
126
- function drawShadow(ctx, shadow) {
127
- if (shadow) {
128
- ctx.shadowColor = shadow.color;
129
- ctx.shadowBlur = shadow.blur || 0;
130
- ctx.shadowOffsetX = shadow.offsetX || 0;
131
- ctx.shadowOffsetY = shadow.offsetY || 0;
132
- }
133
- }
134
- function opacity(ctx, opacity = 1) {
135
- if (opacity < 1) {
136
- ctx.globalAlpha = opacity;
137
- }
138
- }
139
- function filters(ctx, filters) {
140
- if (filters) {
141
- ctx.filter = filters;
142
- }
143
- }
144
167
  function parseFillStyle(ctx, color, opts) {
145
168
  if (!ctx)
146
- throw new LazyUtil_1.LazyError('The context is not defined');
169
+ throw new LazyUtil_1.LazyError("The context is not defined");
147
170
  if (!color)
148
- throw new LazyUtil_1.LazyError('The color is not defined');
171
+ throw new LazyUtil_1.LazyError("The color is not defined");
149
172
  if (color instanceof helpers_1.Gradient || color instanceof helpers_1.Pattern) {
150
173
  return color.draw(ctx, opts);
151
174
  }
152
- if (typeof color === 'object' && color.start && color.end && color.color) {
153
- return color.color;
175
+ if ((0, Signal_1.isSignal)(color)) {
176
+ return parseFillStyle(ctx, (0, Signal_1.unwrap)(color), opts);
154
177
  }
155
- else if (typeof color === 'string') {
178
+ if (typeof color === "object" &&
179
+ color !== null &&
180
+ "start" in color &&
181
+ "end" in color &&
182
+ "color" in color) {
183
+ return (0, Signal_1.unwrap)(color.color);
184
+ }
185
+ if (typeof color === "string") {
156
186
  return color;
157
187
  }
158
- return '#000000';
188
+ return "#000000";
159
189
  }
160
- function transform(ctx, transform, layer = { width: 0, height: 0, x: 0, y: 0, type: types_1.LayerType.Morph }, extra = { text: '', textAlign: types_1.TextAlign.Left, fontSize: 0, multiline: false }) {
190
+ function transform(ctx, transform, layer = {
191
+ width: 0,
192
+ height: 0,
193
+ x: 0,
194
+ y: 0,
195
+ type: types_1.LayerType.Morph,
196
+ }, extra = {
197
+ text: "",
198
+ textAlign: types_1.TextAlign.Left,
199
+ fontSize: 0,
200
+ multiline: false,
201
+ }) {
161
202
  if (transform) {
162
203
  if (transform.translate) {
163
204
  ctx.translate(transform.translate.x, transform.translate.y);
@@ -170,15 +211,15 @@ function transform(ctx, transform, layer = { width: 0, height: 0, x: 0, y: 0, ty
170
211
  case types_1.LayerType.QuadraticCurve:
171
212
  case types_1.LayerType.Line:
172
213
  case types_1.LayerType.Polygon:
173
- ctx.translate(layer.x + (layer.width / 2), layer.y + (layer.height / 2));
214
+ ctx.translate(layer.x + layer.width / 2, layer.y + layer.height / 2);
174
215
  ctx.rotate((Math.PI / 180) * transform.rotate);
175
- ctx.translate(-(layer.x + (layer.width / 2)), -(layer.y + (layer.height / 2)));
216
+ ctx.translate(-(layer.x + layer.width / 2), -(layer.y + layer.height / 2));
176
217
  break;
177
218
  case types_1.LayerType.Text:
178
219
  if (extra.multiline) {
179
- ctx.translate(layer.x + (layer.width / 2), layer.y + (layer.height / 2));
220
+ ctx.translate(layer.x + layer.width / 2, layer.y + layer.height / 2);
180
221
  ctx.rotate((Math.PI / 180) * transform.rotate);
181
- ctx.translate(-(layer.x + (layer.width / 2)), -(layer.y + (layer.height / 2)));
222
+ ctx.translate(-(layer.x + layer.width / 2), -(layer.y + layer.height / 2));
182
223
  }
183
224
  else {
184
225
  if (extra.textAlign === types_1.TextAlign.Center) {
@@ -204,8 +245,13 @@ function transform(ctx, transform, layer = { width: 0, height: 0, x: 0, y: 0, ty
204
245
  ctx.scale(transform.scale.x, transform.scale.y);
205
246
  }
206
247
  if (transform.matrix) {
207
- if (!transform.matrix.a || !transform.matrix.b || !transform.matrix.c || !transform.matrix.d || !transform.matrix.e || !transform.matrix.f)
208
- throw new LazyUtil_1.LazyError('The matrix transformation must be a valid matrix');
248
+ if (!transform.matrix.a ||
249
+ !transform.matrix.b ||
250
+ !transform.matrix.c ||
251
+ !transform.matrix.d ||
252
+ !transform.matrix.e ||
253
+ !transform.matrix.f)
254
+ throw new LazyUtil_1.LazyError("The matrix transformation must be a valid matrix");
209
255
  ctx.transform(transform.matrix.a, transform.matrix.b, transform.matrix.c, transform.matrix.d, transform.matrix.e, transform.matrix.f);
210
256
  }
211
257
  }
@@ -354,13 +400,23 @@ function getBoundingBoxBezier(points, steps = 100) {
354
400
  maxX = Math.max(maxX, p.x);
355
401
  maxY = Math.max(maxY, p.y);
356
402
  }
357
- return { min: { x: minX, y: minY }, max: { x: maxX, y: maxY }, center: { x: (minX + maxX) / 2, y: (minY + maxY) / 2 }, width: maxX - minX, height: maxY - minY };
403
+ return {
404
+ min: { x: minX, y: minY },
405
+ max: { x: maxX, y: maxY },
406
+ center: { x: (minX + maxX) / 2, y: (minY + maxY) / 2 },
407
+ width: maxX - minX,
408
+ height: maxY - minY,
409
+ };
358
410
  }
359
411
  function resize(value, ratio) {
360
- if (typeof value === 'number') {
412
+ // Handle Signal - return as is (signals are not resized)
413
+ if ((0, Signal_1.isSignal)(value)) {
414
+ return resize((0, Signal_1.unwrap)(value), ratio);
415
+ }
416
+ if (typeof value === "number") {
361
417
  return value * ratio;
362
418
  }
363
- else if (typeof value === 'string') {
419
+ else if (typeof value === "string") {
364
420
  if (pxReg.test(value)) {
365
421
  return parseFloat(value) * ratio;
366
422
  }
@@ -368,27 +424,28 @@ function resize(value, ratio) {
368
424
  let match = value.match(linkReg);
369
425
  return `${match[1]}-${match[2]}-${parseFloat(match[3]) * ratio}`;
370
426
  }
427
+ return value;
371
428
  }
372
429
  else if (value instanceof helpers_1.Link) {
373
430
  return `${value.type}-${value.source}-${resize(value.additionalSpacing, ratio)}`;
374
431
  }
375
- return value;
432
+ return 0;
376
433
  }
377
434
  function resizeLayers(layers, ratio) {
378
435
  let newLayers = [];
379
436
  if (layers.length > 0) {
380
437
  for (const layer of layers) {
381
- if (!(layer instanceof components_1.Group || layer instanceof components_1.Path2DLayer)) {
382
- layer.props.x = resize(layer.props.x, ratio);
383
- layer.props.y = resize(layer.props.y, ratio);
384
- if ('size' in layer.props) {
438
+ if (!(layer instanceof components_1.Div || layer instanceof components_1.Path2DLayer)) {
439
+ layer.props.position.x = resize(layer.props.position.x, ratio);
440
+ layer.props.position.y = resize(layer.props.position.y, ratio);
441
+ if ("size" in layer.props && layer.props.size) {
385
442
  layer.props.size.width = resize(layer.props.size.width, ratio);
386
443
  layer.props.size.height = resize(layer.props.size.height, ratio);
387
- if ('radius' in layer.props.size) {
388
- if (typeof layer.props.size.radius === 'number') {
444
+ if ("radius" in layer.props.size) {
445
+ if (typeof layer.props.size.radius === "number") {
389
446
  layer.props.size.radius = resize(layer.props.size.radius, ratio);
390
447
  }
391
- else if (typeof layer.props.size.radius === 'object') {
448
+ else if (typeof layer.props.size.radius === "object") {
392
449
  for (const corner in layer.props.size.radius) {
393
450
  // @ts-ignore
394
451
  layer.props.size.radius[corner] = resize(layer.props.size.radius[corner], ratio);
@@ -396,23 +453,23 @@ function resizeLayers(layers, ratio) {
396
453
  }
397
454
  }
398
455
  }
399
- if ('stroke' in layer.props && layer.props.stroke) {
456
+ if ("stroke" in layer.props && layer.props.stroke) {
400
457
  layer.props.stroke.width = resize(layer.props.stroke.width, ratio);
401
458
  }
402
- if ('endPoint' in layer.props) {
403
- layer.props.endPoint.x = resize(layer.props.endPoint.x, ratio);
404
- layer.props.endPoint.y = resize(layer.props.endPoint.y, ratio);
459
+ if ("endX" in layer.props.position && "endY" in layer.props.position) {
460
+ layer.props.position.endX = resize(layer.props.position.endX, ratio);
461
+ layer.props.position.endY = resize(layer.props.position.endY, ratio);
405
462
  }
406
- if ('controlPoints' in layer.props) {
463
+ if ("controlPoints" in layer.props) {
407
464
  for (const point of layer.props.controlPoints) {
408
465
  point.x = resize(point.x, ratio);
409
466
  point.y = resize(point.y, ratio);
410
467
  }
411
468
  }
412
- if ('font' in layer.props) {
469
+ if ("font" in layer.props) {
413
470
  layer.props.font.size = resize(layer.props.font.size, ratio);
414
471
  }
415
- if ('transform' in layer.props) {
472
+ if ("transform" in layer.props && layer.props.transform) {
416
473
  if (layer.props.transform.translate) {
417
474
  layer.props.transform.translate.x = resize(layer.props.transform.translate.x, ratio);
418
475
  layer.props.transform.translate.y = resize(layer.props.transform.translate.y, ratio);
@@ -423,7 +480,7 @@ function resizeLayers(layers, ratio) {
423
480
  }
424
481
  }
425
482
  }
426
- else if (layer instanceof components_1.Group) {
483
+ else if (layer instanceof components_1.Div) {
427
484
  layer.layers = resizeLayers(layer.layers, ratio);
428
485
  }
429
486
  newLayers.push(layer);
package/package.json CHANGED
@@ -1,59 +1,62 @@
1
- {
2
- "name": "@nmmty/lazycanvas",
3
- "version": "0.6.5",
4
- "description": "A simple way to interact with @napi-rs/canvas in an advanced way!",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "scripts": {
8
- "test": "tsc ./test/test.ts && node ./test/test.js",
9
- "centring": "tsc ./test/centring.ts && node ./test/centring.js",
10
- "logo": "tsc ./test/logo.ts && node ./test/logo.js",
11
- "text": "tsc ./test/text.ts && node ./test/text.js",
12
- "animation": "tsc ./test/animation.ts && node ./test/animation.js",
13
- "iotest": "tsc ./test/iotest.ts && node ./test/iotest.js",
14
- "gradient": "tsc ./test/gradient.ts && node ./test/gradient.js",
15
- "docgen": "tsx docgen.ts && tsx ./scripts/post-docgen.ts",
16
- "lint": "eslint ./src --ext .ts",
17
- "lint:fix": "eslint ./src --ext .ts --fix",
18
- "font": "tsx ./scripts/font-gen.ts",
19
- "build": "tsc && tsx ./scripts/post-build.ts"
20
- },
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/NMMTY/LazyCanvas.git"
24
- },
25
- "keywords": [
26
- "canvas",
27
- "@napi-rs/canvas",
28
- "node-canvas",
29
- "easy",
30
- "simple"
31
- ],
32
- "author": "NMMTY",
33
- "license": "MIT",
34
- "bugs": {
35
- "url": "https://github.com/NMMTY/LazyCanvas/issues"
36
- },
37
- "homepage": "https://github.com/NMMTY/LazyCanvas#readme",
38
- "dependencies": {
39
- "@napi-rs/canvas": "^0.1.72",
40
- "gifenc": "^1.0.3",
41
- "js-yaml": "^4.1.0",
42
- "path": "^0.12.7",
43
- "svgson": "^5.3.1"
44
- },
45
- "devDependencies": {
46
- "@hitomihiumi/colors.ts": "^1.0.3",
47
- "@hitomihiumi/micro-docgen": "workspace:*",
48
- "@types/js-yaml": "^4.0.9",
49
- "@types/node": "^22.10.2",
50
- "@typescript-eslint/utils": "^8.39.1",
51
- "ava": "^6.2.0",
52
- "eslint": "^9.23.0",
53
- "eslint-config-neon": "^0.2.7",
54
- "lodash.merge": "^4.6.2",
55
- "tslib": "^2.8.1",
56
- "tsx": "^4.19.2",
57
- "typescript": "^5.4.5"
58
- }
59
- }
1
+ {
2
+ "name": "@nmmty/lazycanvas",
3
+ "version": "1.0.0-dev.3",
4
+ "description": "A simple way to interact with @napi-rs/canvas in an advanced way!",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/NMMTY/LazyCanvas.git"
10
+ },
11
+ "keywords": [
12
+ "canvas",
13
+ "@napi-rs/canvas",
14
+ "node-canvas",
15
+ "easy",
16
+ "simple"
17
+ ],
18
+ "author": "NMMTY",
19
+ "license": "MIT",
20
+ "bugs": {
21
+ "url": "https://github.com/NMMTY/LazyCanvas/issues"
22
+ },
23
+ "homepage": "https://github.com/NMMTY/LazyCanvas#readme",
24
+ "dependencies": {
25
+ "@napi-rs/canvas": "^0.1.88",
26
+ "gifenc": "^1.0.3",
27
+ "js-yaml": "^4.1.0",
28
+ "path": "^0.12.7",
29
+ "svgson": "^5.3.1",
30
+ "zlib": "^1.0.5"
31
+ },
32
+ "devDependencies": {
33
+ "@biomejs/biome": "1.9.4",
34
+ "@hitomihiumi/colors.ts": "^1.0.3",
35
+ "@types/js-yaml": "^4.0.9",
36
+ "@types/node": "^22.10.2",
37
+ "@typescript-eslint/utils": "^8.39.1",
38
+ "ava": "^6.2.0",
39
+ "eslint": "^9.23.0",
40
+ "eslint-config-neon": "^0.2.7",
41
+ "lodash.merge": "^4.6.2",
42
+ "tslib": "^2.8.1",
43
+ "tsx": "^4.19.2",
44
+ "typescript": "^5.4.5",
45
+ "@hitomihiumi/micro-docgen": "0.4.2"
46
+ },
47
+ "scripts": {
48
+ "test": "tsc ./test/test.ts && node ./test/test.js",
49
+ "centring": "tsc ./test/centring.ts && node ./test/centring.js",
50
+ "logo": "tsc ./test/logo.ts && node ./test/logo.js",
51
+ "text": "tsc ./test/text.ts && node ./test/text.js",
52
+ "animation": "tsc ./test/animation.ts && node ./test/animation.js",
53
+ "iotest": "tsc ./test/iotest.ts && node ./test/iotest.js",
54
+ "gradient": "tsc ./test/gradient.ts && node ./test/gradient.js",
55
+ "docgen": "tsx docgen.ts && tsx ./scripts/post-docgen.ts",
56
+ "lint": "eslint ./src --ext .ts",
57
+ "lint:fix": "eslint ./src --ext .ts --fix",
58
+ "font": "tsx ./scripts/font-gen.ts",
59
+ "build": "tsc && tsx ./scripts/post-build.ts",
60
+ "biome-write": "npx @biomejs/biome format --write ."
61
+ }
62
+ }