@nmmty/lazycanvas 0.5.1 → 0.5.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 (35) hide show
  1. package/animation.gif +0 -0
  2. package/dist/structures/components/ClearLayer.d.ts +5 -1
  3. package/dist/structures/components/Group.d.ts +15 -1
  4. package/dist/structures/components/Group.js +19 -0
  5. package/dist/structures/components/ImageLayer.d.ts +8 -4
  6. package/dist/structures/components/ImageLayer.js +16 -9
  7. package/dist/structures/components/MorphLayer.d.ts +8 -4
  8. package/dist/structures/components/MorphLayer.js +16 -9
  9. package/dist/structures/managers/RenderManager.js +2 -23
  10. package/dist/types/types.d.ts +48 -20
  11. package/dist/utils/utils.js +6 -2
  12. package/package.json +1 -1
  13. package/test.png +0 -0
  14. package/dist/structures/helpers/readers/SVGReader.d.ts +0 -20
  15. package/dist/structures/helpers/readers/SVGReader.js +0 -577
  16. package/dist/structures/helpers/readers/YAMLReader.d.ts +0 -0
  17. package/dist/structures/helpers/readers/YAMLReader.js +0 -1
  18. package/dist/types/LazyCanvas.d.ts +0 -18
  19. package/dist/types/components/BaseLayer.d.ts +0 -49
  20. package/dist/types/components/BezierLayer.d.ts +0 -11
  21. package/dist/types/components/ClearLayer.d.ts +0 -19
  22. package/dist/types/components/Group.d.ts +0 -8
  23. package/dist/types/components/ImageLayer.d.ts +0 -15
  24. package/dist/types/components/LineLayer.d.ts +0 -12
  25. package/dist/types/components/MorphLayer.d.ts +0 -14
  26. package/dist/types/components/QuadraticLayer.d.ts +0 -11
  27. package/dist/types/components/TextLayer.d.ts +0 -28
  28. package/dist/types/helpers/Font.d.ts +0 -12
  29. package/dist/types/helpers/Gradient.d.ts +0 -19
  30. package/dist/types/helpers/Link.d.ts +0 -7
  31. package/dist/types/helpers/Pattern.d.ts +0 -7
  32. package/dist/types/managers/AnimationManager.d.ts +0 -14
  33. package/dist/types/managers/FontsManager.d.ts +0 -6
  34. package/dist/types/managers/LayersManager.d.ts +0 -7
  35. package/dist/types/managers/RenderManager.d.ts +0 -6
package/animation.gif ADDED
Binary file
@@ -1,4 +1,4 @@
1
- import { ScaleType, LayerType, AnyCentring } from "../../types";
1
+ import { ScaleType, LayerType, AnyCentring, AnyGlobalCompositeOperation } from "../../types";
2
2
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
3
3
  import { LayersManager } from "../managers/LayersManager";
4
4
  import { IBaseLayerMisc } from "./BaseLayer";
@@ -56,6 +56,10 @@ export interface IClearLayerProps {
56
56
  * The centring type of the layer.
57
57
  */
58
58
  centring: AnyCentring;
59
+ /**
60
+ * Don't use, this is just for compatibility.
61
+ */
62
+ globalComposite: AnyGlobalCompositeOperation;
59
63
  }
60
64
  /**
61
65
  * Class representing a Clear Layer.
@@ -1,4 +1,6 @@
1
- import { AnyLayer, LayerType } from "../../types";
1
+ import { AnyGlobalCompositeOperation, AnyLayer, LayerType } from "../../types";
2
+ import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
3
+ import { LayersManager } from "../managers/LayersManager";
2
4
  /**
3
5
  * Interface representing a group of layers.
4
6
  */
@@ -23,6 +25,16 @@ export interface IGroup {
23
25
  * The layers contained within the group.
24
26
  */
25
27
  layers: Array<AnyLayer>;
28
+ /**
29
+ *
30
+ */
31
+ props?: IGroupProps;
32
+ }
33
+ export interface IGroupProps {
34
+ /**
35
+ * Don't use, this is just for compatibility.
36
+ */
37
+ globalComposite: AnyGlobalCompositeOperation;
26
38
  }
27
39
  /**
28
40
  * Class representing a group of layers.
@@ -48,6 +60,7 @@ export declare class Group implements IGroup {
48
60
  * The layers contained within the group.
49
61
  */
50
62
  layers: Array<any>;
63
+ props?: IGroupProps;
51
64
  /**
52
65
  * Constructs a new Group instance.
53
66
  * @param opts {Object} - Optional parameters for the group.
@@ -111,6 +124,7 @@ export declare class Group implements IGroup {
111
124
  * @returns {number} The number of components in the group.
112
125
  */
113
126
  get length(): number;
127
+ draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
114
128
  /**
115
129
  * Converts the group to a JSON representation.
116
130
  * @returns {IGroup} The JSON representation of the group.
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Group = void 0;
4
4
  const types_1 = require("../../types");
5
5
  const utils_1 = require("../../utils/utils");
6
+ const LazyUtil_1 = require("../../utils/LazyUtil");
6
7
  /**
7
8
  * Class representing a group of layers.
8
9
  */
@@ -27,6 +28,7 @@ class Group {
27
28
  * The layers contained within the group.
28
29
  */
29
30
  layers;
31
+ props;
30
32
  /**
31
33
  * Constructs a new Group instance.
32
34
  * @param opts {Object} - Optional parameters for the group.
@@ -39,6 +41,7 @@ class Group {
39
41
  this.visible = opts?.visible || true;
40
42
  this.zIndex = opts?.zIndex || 1;
41
43
  this.layers = [];
44
+ this.props = {};
42
45
  }
43
46
  /**
44
47
  * Sets the ID of the group.
@@ -118,6 +121,22 @@ class Group {
118
121
  get length() {
119
122
  return this.layers.length;
120
123
  }
124
+ async draw(ctx, canvas, manager, debug) {
125
+ for (const subLayer of this.layers) {
126
+ if (debug)
127
+ LazyUtil_1.LazyLog.log('info', `Rendering ${subLayer.id}...\nData:`, subLayer.toJSON());
128
+ if (subLayer.visible) {
129
+ if ('globalComposite' in subLayer.props && subLayer.props.globalComposite) {
130
+ ctx.globalCompositeOperation = subLayer.props.globalComposite;
131
+ }
132
+ else {
133
+ ctx.globalCompositeOperation = 'source-over';
134
+ }
135
+ await subLayer.draw(ctx, canvas, manager, debug);
136
+ ctx.shadowColor = 'transparent';
137
+ }
138
+ }
139
+ }
121
140
  /**
122
141
  * Converts the group to a JSON representation.
123
142
  * @returns {IGroup} The JSON representation of the group.
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
4
- import { ScaleType, LayerType } from "../../types";
4
+ import { ScaleType, LayerType, radiusCorner } from "../../types";
5
5
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
6
6
  import { LayersManager } from "../managers/LayersManager";
7
7
  /**
@@ -40,7 +40,9 @@ export interface IImageLayerProps extends IBaseLayerProps {
40
40
  /**
41
41
  * The radius of the image.
42
42
  */
43
- radius: ScaleType;
43
+ radius: {
44
+ [corner in radiusCorner]?: ScaleType;
45
+ };
44
46
  };
45
47
  }
46
48
  /**
@@ -68,10 +70,12 @@ export declare class ImageLayer extends BaseLayer<IImageLayerProps> {
68
70
  * Sets the size of the image.
69
71
  * @param width {ScaleType} - The width of the image.
70
72
  * @param height {ScaleType} - The height of the image.
71
- * @param radius {ScaleType} - The radius of the image (optional).
73
+ * @param radius {{ [corner in radiusCorner]?: ScaleType }} - The radius of the image (optional).
72
74
  * @returns {this} The current instance for chaining.
73
75
  */
74
- setSize(width: ScaleType, height: ScaleType, radius?: ScaleType): this;
76
+ setSize(width: ScaleType, height: ScaleType, radius?: {
77
+ [corner in radiusCorner]?: ScaleType;
78
+ }): this;
75
79
  /**
76
80
  * Draws the Image Layer on the canvas.
77
81
  * @param ctx {SKRSContext2D} - The canvas rendering context.
@@ -6,6 +6,7 @@ const types_1 = require("../../types");
6
6
  const canvas_1 = require("@napi-rs/canvas");
7
7
  const utils_1 = require("../../utils/utils");
8
8
  const LazyUtil_1 = require("../../utils/LazyUtil");
9
+ const helpers_1 = require("../helpers");
9
10
  /**
10
11
  * Class representing an Image Layer, extending the BaseLayer class.
11
12
  */
@@ -40,14 +41,14 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
40
41
  * Sets the size of the image.
41
42
  * @param width {ScaleType} - The width of the image.
42
43
  * @param height {ScaleType} - The height of the image.
43
- * @param radius {ScaleType} - The radius of the image (optional).
44
+ * @param radius {{ [corner in radiusCorner]?: ScaleType }} - The radius of the image (optional).
44
45
  * @returns {this} The current instance for chaining.
45
46
  */
46
47
  setSize(width, height, radius) {
47
48
  this.props.size = {
48
49
  width: width,
49
50
  height: height,
50
- radius: radius || 0,
51
+ radius: radius || { all: 0 },
51
52
  };
52
53
  return this;
53
54
  }
@@ -67,10 +68,16 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
67
68
  w: { v: this.props.size.width }
68
69
  });
69
70
  const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
70
- const r = parcer.parse(this.props.size.radius, LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
71
71
  let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
72
+ const rad = {};
73
+ if (typeof this.props.size.radius === 'object' && this.props.size.radius !== helpers_1.Link) {
74
+ for (const corner in this.props.size.radius) {
75
+ // @ts-ignore
76
+ rad[corner] = parcer.parse(this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
77
+ }
78
+ }
72
79
  if (debug)
73
- LazyUtil_1.LazyLog.log('none', `ImageLayer:`, { x, y, w, h, r });
80
+ LazyUtil_1.LazyLog.log('none', `ImageLayer:`, { x, y, w, h, rad });
74
81
  ctx.save();
75
82
  (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
76
83
  (0, utils_1.drawShadow)(ctx, this.props.shadow);
@@ -81,13 +88,13 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
81
88
  image.height = h;
82
89
  if (!image)
83
90
  throw new LazyUtil_1.LazyError('The image could not be loaded');
84
- if (r) {
91
+ if (Object.keys(rad).length > 0) {
85
92
  ctx.beginPath();
86
93
  ctx.moveTo(x + (w / 2), y);
87
- ctx.arcTo(x + w, y, x + w, y + (h / 2), r);
88
- ctx.arcTo(x + w, y + h, x + (w / 2), y + h, r);
89
- ctx.arcTo(x, y + h, x, y + (h / 2), r);
90
- ctx.arcTo(x, y, x + (w / 2), y, r);
94
+ ctx.arcTo(x + w, y, x + w, y + (h / 2), rad.rightTop || rad.all || 0);
95
+ ctx.arcTo(x + w, y + h, x + (w / 2), y + h, rad.rightBottom || rad.all || 0);
96
+ ctx.arcTo(x, y + h, x, y + (h / 2), rad.leftBottom || rad.all || 0);
97
+ ctx.arcTo(x, y, x + (w / 2), y, rad.leftTop || rad.all || 0);
91
98
  ctx.closePath();
92
99
  ctx.clip();
93
100
  ctx.drawImage(image, x, y, w, h);
@@ -1,5 +1,5 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { ColorType, ScaleType, LayerType } from "../../types";
2
+ import { ColorType, ScaleType, LayerType, radiusCorner } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
4
  import { LayersManager } from "../managers/LayersManager";
5
5
  /**
@@ -34,7 +34,9 @@ export interface IMorphLayerProps extends IBaseLayerProps {
34
34
  /**
35
35
  * The radius of the Morph Layer.
36
36
  */
37
- radius: ScaleType;
37
+ radius: {
38
+ [corner in radiusCorner]?: ScaleType;
39
+ };
38
40
  };
39
41
  /**
40
42
  * The stroke properties of the morph.
@@ -84,10 +86,12 @@ export declare class MorphLayer extends BaseLayer<IMorphLayerProps> {
84
86
  * Sets the size of the Morph Layer.
85
87
  * @param width {ScaleType} - The width of the Morph Layer.
86
88
  * @param height {ScaleType} - The height of the Morph Layer.
87
- * @param radius {ScaleType} - The radius of the Morph Layer (optional).
89
+ * @param radius {{ [corner in radiusCorner]?: ScaleType }} - The radius of the Morph Layer (optional).
88
90
  * @returns {this} The current instance for chaining.
89
91
  */
90
- setSize(width: ScaleType, height: ScaleType, radius?: ScaleType): this;
92
+ setSize(width: ScaleType, height: ScaleType, radius?: {
93
+ [corner in radiusCorner]?: ScaleType;
94
+ }): this;
91
95
  /**
92
96
  * Sets the color of the Morph Layer.
93
97
  * @param color {string} - The color of the Morph Layer.
@@ -5,6 +5,7 @@ const BaseLayer_1 = require("./BaseLayer");
5
5
  const types_1 = require("../../types");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const LazyUtil_1 = require("../../utils/LazyUtil");
8
+ const helpers_1 = require("../helpers");
8
9
  /**
9
10
  * Class representing a Morph Layer, extending the BaseLayer class.
10
11
  */
@@ -31,14 +32,14 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
31
32
  * Sets the size of the Morph Layer.
32
33
  * @param width {ScaleType} - The width of the Morph Layer.
33
34
  * @param height {ScaleType} - The height of the Morph Layer.
34
- * @param radius {ScaleType} - The radius of the Morph Layer (optional).
35
+ * @param radius {{ [corner in radiusCorner]?: ScaleType }} - The radius of the Morph Layer (optional).
35
36
  * @returns {this} The current instance for chaining.
36
37
  */
37
38
  setSize(width, height, radius) {
38
39
  this.props.size = {
39
40
  width: width,
40
41
  height: height,
41
- radius: radius || 0,
42
+ radius: radius || { all: 0 },
42
43
  };
43
44
  return this;
44
45
  }
@@ -101,20 +102,26 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
101
102
  w: { v: this.props.size.width },
102
103
  });
103
104
  const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
104
- const r = parcer.parse(this.props.size.radius, LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
105
+ const rad = {};
106
+ if (typeof this.props.size.radius === 'object' && this.props.size.radius !== helpers_1.Link) {
107
+ for (const corner in this.props.size.radius) {
108
+ // @ts-ignore
109
+ rad[corner] = parcer.parse(this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
110
+ }
111
+ }
105
112
  let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
106
113
  let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
107
114
  if (debug)
108
- LazyUtil_1.LazyLog.log('none', `MorphLayer:`, { x, y, w, h, r });
115
+ LazyUtil_1.LazyLog.log('none', `MorphLayer:`, { x, y, w, h, rad });
109
116
  ctx.save();
110
117
  (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
111
118
  ctx.beginPath();
112
- if (r) {
119
+ if (Object.keys(rad).length > 0) {
113
120
  ctx.moveTo(x + (w / 2), y);
114
- ctx.arcTo(x + w, y, x + w, y + (h / 2), r);
115
- ctx.arcTo(x + w, y + h, x + (w / 2), y + h, r);
116
- ctx.arcTo(x, y + h, x, y + (h / 2), r);
117
- ctx.arcTo(x, y, x + (w / 2), y, r);
121
+ ctx.arcTo(x + w, y, x + w, y + (h / 2), rad.rightTop || rad.all || 0);
122
+ ctx.arcTo(x + w, y + h, x + (w / 2), y + h, rad.rightBottom || rad.all || 0);
123
+ ctx.arcTo(x, y + h, x, y + (h / 2), rad.leftBottom || rad.all || 0);
124
+ ctx.arcTo(x, y, x + (w / 2), y, rad.leftTop || rad.all || 0);
118
125
  }
119
126
  else {
120
127
  ctx.rect(x, y, w, h);
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RenderManager = void 0;
4
4
  const types_1 = require("../../types");
5
- const components_1 = require("../components");
6
5
  const LazyUtil_1 = require("../../utils/LazyUtil");
7
6
  // @ts-ignore
8
7
  const gifenc_1 = require("gifenc");
@@ -67,28 +66,8 @@ class RenderManager {
67
66
  if (this.debug)
68
67
  LazyUtil_1.LazyLog.log('info', `Rendering ${layer.id}...\nData:`, layer.toJSON());
69
68
  if (layer.visible) {
70
- if (layer instanceof components_1.Group) {
71
- for (const subLayer of layer.layers) {
72
- if (subLayer.visible) {
73
- if ('globalComposite' in subLayer.props && subLayer.props.globalComposite) {
74
- this.lazyCanvas.ctx.globalCompositeOperation = subLayer.props.globalComposite;
75
- }
76
- else {
77
- this.lazyCanvas.ctx.globalCompositeOperation = 'source-over';
78
- }
79
- await subLayer.draw(this.lazyCanvas.ctx, this.lazyCanvas.canvas, this.lazyCanvas.manager.layers, this.debug);
80
- }
81
- }
82
- }
83
- else {
84
- if ('globalComposite' in layer.props && layer.props.globalComposite) {
85
- this.lazyCanvas.ctx.globalCompositeOperation = layer.props.globalComposite;
86
- }
87
- else {
88
- this.lazyCanvas.ctx.globalCompositeOperation = 'source-over';
89
- }
90
- await layer.draw(this.lazyCanvas.ctx, this.lazyCanvas.canvas, this.lazyCanvas.manager.layers, this.debug);
91
- }
69
+ this.lazyCanvas.ctx.globalCompositeOperation = layer.props?.globalComposite || 'source-over';
70
+ await layer.draw(this.lazyCanvas.ctx, this.lazyCanvas.canvas, this.lazyCanvas.manager.layers, this.debug);
92
71
  this.lazyCanvas.ctx.shadowColor = 'transparent';
93
72
  }
94
73
  return this.lazyCanvas.ctx;
@@ -1,14 +1,22 @@
1
- import { Gradient } from "../structures/helpers/Gradient";
2
- import { Pattern } from "../structures/helpers/Pattern";
3
- import { MorphLayer } from "../structures/components/MorphLayer";
4
- import { ImageLayer } from "../structures/components/ImageLayer";
5
- import { TextLayer } from "../structures/components/TextLayer";
6
- import { BezierLayer } from "../structures/components/BezierLayer";
7
- import { QuadraticLayer } from "../structures/components/QuadraticLayer";
8
- import { LineLayer } from "../structures/components/LineLayer";
9
- import { Group } from "../structures/components/Group";
10
- import { ClearLayer } from "../structures/components/ClearLayer";
11
- import { Link } from "../structures/helpers/Link";
1
+ import { Gradient, Link, Pattern } from "../structures/helpers";
2
+ import {
3
+ MorphLayer,
4
+ ImageLayer,
5
+ TextLayer,
6
+ BezierLayer,
7
+ QuadraticLayer,
8
+ LineLayer,
9
+ ClearLayer,
10
+ Path2DLayer,
11
+ IMorphLayer,
12
+ IBezierLayer,
13
+ IClearLayer,
14
+ IImageLayer,
15
+ ITextLayer,
16
+ IQuadraticLayer,
17
+ ILineLayer,
18
+ IPath2DLayer
19
+ } from "../structures/components";
12
20
  import {
13
21
  FontWeight,
14
22
  GradientType,
@@ -20,17 +28,20 @@ import {
20
28
  Export,
21
29
  Centring,
22
30
  PatternType,
23
- SaveFormat,
24
31
  LinkType,
25
32
  GlobalCompositeOperation,
26
- ColorSpace
33
+ ColorSpace,
27
34
  } from "./enum";
28
35
 
29
- export type ScaleType = string | number | 'vw' | 'vh' | 'vmin' | 'vmax' | Link;
36
+ export type ScaleType = `link-w-${string}-${number}` | `link-h-${string}-${number}` | `link-x-${string}-${number}` | `link-y-${string}-${number}` | `${number}%` | `${number}px` | number | 'vw' | 'vh' | 'vmin' | 'vmax' | Link;
37
+
38
+ export type StringColorType = `rgba(${number}, ${number}, ${number}, ${number})` | `rgb(${number}, ${number}, ${number})` | `hsl(${number}, ${number}%, ${number}%)` | `hsla(${number}, ${number}%, ${number}%, ${number})` | `#${string}` | string;
30
39
 
31
- export type ColorType = string | Gradient | Pattern;
40
+ export type ColorType = Gradient | Pattern | StringColorType;
32
41
 
33
- export type AnyLayer = MorphLayer | ImageLayer | TextLayer | BezierLayer | QuadraticLayer | LineLayer | ClearLayer | Group;
42
+ export type JSONLayer = IMorphLayer | IImageLayer | ITextLayer | IBezierLayer | IQuadraticLayer | ILineLayer | IClearLayer | IPath2DLayer;
43
+
44
+ export type AnyLayer = MorphLayer | ImageLayer | TextLayer | BezierLayer | QuadraticLayer | LineLayer | ClearLayer | Path2DLayer;
34
45
 
35
46
  export type AnyWeight = FontWeight | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
36
47
 
@@ -46,20 +57,20 @@ export type AnyLineCap = LineCap | 'butt' | 'round' | 'square';
46
57
 
47
58
  export type AnyLineJoin = LineJoin | 'bevel' | 'round' | 'miter';
48
59
 
49
- export type AnyExport = Export | 'buffer' | 'svg' | 'ctx';
60
+ export type AnyExport = Export | 'canvas' | 'ctx' | 'buffer' | 'svg' | 'png' | 'jpeg' | 'jpg' | 'gif' | 'webp' | 'yaml' | 'json';
50
61
 
51
62
  export type AnyCentring = Centring | 'start' | 'start-top' | 'start-bottom' | 'center' | 'center-top' | 'center-bottom' | 'end' | 'end-top' | 'end-bottom' | 'none';
52
63
 
53
64
  export type AnyPatternType = PatternType | 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat';
54
65
 
55
- export type AnySaveFormat = SaveFormat | 'png' | 'jpeg' | 'jpg' | 'svg' | 'gif' | 'webp';
56
-
57
66
  export type AnyLinkType = LinkType | 'width' | 'height' | 'x' | 'y';
58
67
 
59
68
  export type AnyGlobalCompositeOperation = GlobalCompositeOperation | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
60
69
 
61
70
  export type AnyColorSpace = ColorSpace | 'rgb565' | 'rgba4444' | 'rgba444';
62
71
 
72
+ export type AnyFilter = `sepia(${number}%)` | `saturate(${number}%)` | `opacity(${number}%)` | `invert(${number}%)` | `hue-rotate(${number}deg)` | `grayscale(${number}%)` | `drop-shadow(${number}px ${number}px ${number}px ${string})` | `contrast(${number}%)` | `brightness(${number}%)` | `blur(${number}px)`;
73
+
63
74
  export type Point = {
64
75
  x: ScaleType;
65
76
  y: ScaleType;
@@ -68,4 +79,21 @@ export type Point = {
68
79
  export type PointNumber = {
69
80
  x: number;
70
81
  y: number;
71
- };
82
+ };
83
+
84
+ export type Extensions = 'svg' | 'png' | 'jpeg' | 'jpg' | 'gif' | 'webp' | 'yaml' | 'json';
85
+
86
+ export interface Transform {
87
+ rotate: number;
88
+ scale: {
89
+ x: number;
90
+ y: number;
91
+ };
92
+ translate: {
93
+ x: number;
94
+ y: number;
95
+ };
96
+ matrix: DOMMatrix2DInit;
97
+ }
98
+
99
+ export type radiusCorner = 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom' | 'all';
@@ -29,7 +29,8 @@ function parseToNormal(v, ctx, canvas, layer = { width: 0, height: 0 }, options
29
29
  }
30
30
  else if (typeof v === 'string') {
31
31
  if (percentReg.test(v)) {
32
- return (parseFloat(v) / 100) * (options.layer ? (options.vertical ? layer.width : layer.height) : (options.vertical ? canvas.width : canvas.height));
32
+ console.log(options, layer, canvas.width, canvas.height, parseFloat(v));
33
+ return (parseFloat(v) / 100) * (options.layer ? (options.vertical ? layer.height : layer.width) : (options.vertical ? canvas.height : canvas.width));
33
34
  }
34
35
  else if (pxReg.test(v)) {
35
36
  return parseFloat(v);
@@ -402,7 +403,10 @@ function resizeLayers(layers, ratio) {
402
403
  layer.props.size.width = resize(layer.props.size.width, ratio);
403
404
  layer.props.size.height = resize(layer.props.size.height, ratio);
404
405
  if ('radius' in layer.props.size) {
405
- layer.props.size.radius = resize(layer.props.size.radius, ratio);
406
+ for (const corner in layer.props.size.radius) {
407
+ // @ts-ignore
408
+ layer.props.size.radius[corner] = resize(layer.props.size.radius[corner], ratio);
409
+ }
406
410
  }
407
411
  }
408
412
  if ('stroke' in layer.props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmmty/lazycanvas",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
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",
package/test.png ADDED
Binary file
@@ -1,20 +0,0 @@
1
- export declare class SVGReader {
2
- private static parseSVG;
3
- private static createImageLayer;
4
- private static createEllipseImageLayer;
5
- private static createRectLayer;
6
- private static createEllipseLayer;
7
- private static createCircleLayer;
8
- private static createLineLayer;
9
- private static createGradient;
10
- private static createPattern;
11
- private static createPath2DLayer;
12
- private static createClipPathLayer;
13
- private static createGroupLayer;
14
- private static applyTransform;
15
- private static findElementById;
16
- private static extractIdFromUrl;
17
- private fillStyle;
18
- private static handleUseElement;
19
- static readSVG(svg: string): Promise<any>;
20
- }