@nmmty/lazycanvas 1.0.0-dev.3 → 1.0.0-dev.4
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/structures/components/ImageLayer.js +3 -1
- package/dist/structures/components/MorphLayer.js +3 -1
- package/dist/structures/helpers/Exporter.js +1 -1
- package/dist/structures/helpers/readers/JSONReader.js +2 -2
- package/dist/structures/helpers/readers/YAMLReader.js +2 -2
- package/dist/types/types.d.ts +232 -0
- package/dist/utils/APNGEncoder.js +2 -2
- package/dist/utils/utils.js +3 -1
- package/package.json +2 -4
|
@@ -70,7 +70,9 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
|
|
|
70
70
|
if (typeof this.props.size.radius === "object" && this.props.size.radius !== helpers_1.Link) {
|
|
71
71
|
for (const corner in this.props.size.radius) {
|
|
72
72
|
// @ts-ignore
|
|
73
|
-
rad[corner] = parcer.parse(
|
|
73
|
+
rad[corner] = parcer.parse(
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
if (debug)
|
|
@@ -90,7 +90,9 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
90
90
|
if (typeof this.props.size.radius === "object" && this.props.size.radius !== helpers_1.Link) {
|
|
91
91
|
for (const corner in this.props.size.radius) {
|
|
92
92
|
// @ts-ignore
|
|
93
|
-
rad[corner] = parcer.parse(
|
|
93
|
+
rad[corner] = parcer.parse(
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
|
|
94
96
|
}
|
|
95
97
|
}
|
|
96
98
|
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
@@ -39,7 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.Exporter = void 0;
|
|
40
40
|
const types_1 = require("../../types");
|
|
41
41
|
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
42
|
-
const fs = __importStar(require("fs"));
|
|
42
|
+
const fs = __importStar(require("node:fs"));
|
|
43
43
|
const utils_1 = require("../../utils/utils");
|
|
44
44
|
const _yaml = __importStar(require("js-yaml"));
|
|
45
45
|
const APNGEncoder_1 = __importDefault(require("../../utils/APNGEncoder"));
|
|
@@ -38,9 +38,9 @@ const types_1 = require("../../../types");
|
|
|
38
38
|
const components_1 = require("../../components");
|
|
39
39
|
const __1 = require("../");
|
|
40
40
|
const LazyCanvas_1 = require("../../LazyCanvas");
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
41
|
+
const fs = __importStar(require("node:fs"));
|
|
42
42
|
const LazyUtil_1 = require("../../../utils/LazyUtil");
|
|
43
|
-
const path = __importStar(require("path"));
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
44
|
const Signal_1 = require("../../../core/Signal");
|
|
45
45
|
/**
|
|
46
46
|
* Class responsible for reading and parsing JSON data into a LazyCanvas instance.
|
|
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.YAMLReader = void 0;
|
|
37
37
|
const JSONReader_1 = require("./JSONReader");
|
|
38
38
|
const _yaml = __importStar(require("js-yaml"));
|
|
39
|
-
const fs = __importStar(require("fs"));
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
40
|
const LazyUtil_1 = require("../../../utils/LazyUtil");
|
|
41
|
-
const path = __importStar(require("path"));
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
42
|
class YAMLReader {
|
|
43
43
|
/**
|
|
44
44
|
* Reads a YAML string and converts it to a LazyCanvas object.
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { Gradient, Link, Pattern } from "../structures/helpers";
|
|
2
|
+
import {
|
|
3
|
+
MorphLayer,
|
|
4
|
+
ImageLayer,
|
|
5
|
+
TextLayer,
|
|
6
|
+
BezierLayer,
|
|
7
|
+
QuadraticLayer,
|
|
8
|
+
LineLayer,
|
|
9
|
+
Path2DLayer,
|
|
10
|
+
IMorphLayer,
|
|
11
|
+
IBezierLayer,
|
|
12
|
+
IImageLayer,
|
|
13
|
+
ITextLayer,
|
|
14
|
+
IQuadraticLayer,
|
|
15
|
+
ILineLayer,
|
|
16
|
+
IPath2DLayer,
|
|
17
|
+
IPolygonLayer,
|
|
18
|
+
PolygonLayer,
|
|
19
|
+
} from "../structures/components";
|
|
20
|
+
import {
|
|
21
|
+
FontWeight,
|
|
22
|
+
GradientType,
|
|
23
|
+
TextAlign,
|
|
24
|
+
TextBaseline,
|
|
25
|
+
TextDirection,
|
|
26
|
+
LineCap,
|
|
27
|
+
LineJoin,
|
|
28
|
+
Export,
|
|
29
|
+
Centring,
|
|
30
|
+
PatternType,
|
|
31
|
+
LinkType,
|
|
32
|
+
GlobalCompositeOperation,
|
|
33
|
+
ColorSpace,
|
|
34
|
+
} from "./enum";
|
|
35
|
+
import {
|
|
36
|
+
Signal,
|
|
37
|
+
ThreadGenerator,
|
|
38
|
+
SignalOptions,
|
|
39
|
+
TweenConfig,
|
|
40
|
+
unwrap,
|
|
41
|
+
isSignal,
|
|
42
|
+
} from "../core/Signal";
|
|
43
|
+
|
|
44
|
+
// Utility type for signal-enabled values
|
|
45
|
+
export type Signalable<T> = T | Signal<T>;
|
|
46
|
+
|
|
47
|
+
// Re-export for convenience
|
|
48
|
+
export type { ThreadGenerator, SignalOptions, TweenConfig };
|
|
49
|
+
export { unwrap, isSignal };
|
|
50
|
+
|
|
51
|
+
// Core types with Signal support
|
|
52
|
+
export type ScaleType =
|
|
53
|
+
| `link-w-${string}-${number}`
|
|
54
|
+
| `link-h-${string}-${number}`
|
|
55
|
+
| `link-x-${string}-${number}`
|
|
56
|
+
| `link-y-${string}-${number}`
|
|
57
|
+
| `${number}%`
|
|
58
|
+
| `${number}px`
|
|
59
|
+
| number
|
|
60
|
+
| "vw"
|
|
61
|
+
| "vh"
|
|
62
|
+
| "vmin"
|
|
63
|
+
| "vmax"
|
|
64
|
+
| Link
|
|
65
|
+
| Signal<number>;
|
|
66
|
+
|
|
67
|
+
export type StringColorType =
|
|
68
|
+
| `rgba(${number}, ${number}, ${number}, ${number})`
|
|
69
|
+
| `rgb(${number}, ${number}, ${number})`
|
|
70
|
+
| `hsl(${number}, ${number}%, ${number}%)`
|
|
71
|
+
| `hsla(${number}, ${number}%, ${number}%, ${number})`
|
|
72
|
+
| `#${string}`
|
|
73
|
+
| string
|
|
74
|
+
| Signal<string>;
|
|
75
|
+
|
|
76
|
+
export type ColorType = Gradient | Pattern | StringColorType;
|
|
77
|
+
|
|
78
|
+
export type JSONLayer =
|
|
79
|
+
| IMorphLayer
|
|
80
|
+
| IImageLayer
|
|
81
|
+
| ITextLayer
|
|
82
|
+
| IBezierLayer
|
|
83
|
+
| IQuadraticLayer
|
|
84
|
+
| ILineLayer
|
|
85
|
+
| IPath2DLayer
|
|
86
|
+
| IPolygonLayer;
|
|
87
|
+
|
|
88
|
+
export type AnyLayer =
|
|
89
|
+
| MorphLayer
|
|
90
|
+
| ImageLayer
|
|
91
|
+
| TextLayer
|
|
92
|
+
| BezierLayer
|
|
93
|
+
| QuadraticLayer
|
|
94
|
+
| LineLayer
|
|
95
|
+
| Path2DLayer
|
|
96
|
+
| PolygonLayer;
|
|
97
|
+
|
|
98
|
+
export type AnyWeight = FontWeight | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
|
|
99
|
+
|
|
100
|
+
export type AnyGradientType = GradientType | "linear" | "radial" | "conic";
|
|
101
|
+
|
|
102
|
+
export type AnyTextAlign = TextAlign | "left" | "right" | "center" | "start" | "end";
|
|
103
|
+
|
|
104
|
+
export type AnyTextBaseline =
|
|
105
|
+
| TextBaseline
|
|
106
|
+
| "top"
|
|
107
|
+
| "hanging"
|
|
108
|
+
| "middle"
|
|
109
|
+
| "alphabetic"
|
|
110
|
+
| "ideographic"
|
|
111
|
+
| "bottom";
|
|
112
|
+
|
|
113
|
+
export type AnyTextDirection = TextDirection | "ltr" | "rtl" | "inherit";
|
|
114
|
+
|
|
115
|
+
export type AnyLineCap = LineCap | "butt" | "round" | "square";
|
|
116
|
+
|
|
117
|
+
export type AnyLineJoin = LineJoin | "bevel" | "round" | "miter";
|
|
118
|
+
|
|
119
|
+
export type AnyExport =
|
|
120
|
+
| Export
|
|
121
|
+
| "canvas"
|
|
122
|
+
| "ctx"
|
|
123
|
+
| "buffer"
|
|
124
|
+
| "svg"
|
|
125
|
+
| "png"
|
|
126
|
+
| "apng"
|
|
127
|
+
| "jpg"
|
|
128
|
+
| "webp"
|
|
129
|
+
| "yaml"
|
|
130
|
+
| "json";
|
|
131
|
+
|
|
132
|
+
export type AnyCentring =
|
|
133
|
+
| Centring
|
|
134
|
+
| "start"
|
|
135
|
+
| "start-top"
|
|
136
|
+
| "start-bottom"
|
|
137
|
+
| "center"
|
|
138
|
+
| "center-top"
|
|
139
|
+
| "center-bottom"
|
|
140
|
+
| "end"
|
|
141
|
+
| "end-top"
|
|
142
|
+
| "end-bottom"
|
|
143
|
+
| "none";
|
|
144
|
+
|
|
145
|
+
export type AnyPatternType = PatternType | "repeat" | "repeat-x" | "repeat-y" | "no-repeat";
|
|
146
|
+
|
|
147
|
+
export type AnyLinkType = LinkType | "width" | "height" | "x" | "y";
|
|
148
|
+
|
|
149
|
+
export type AnyGlobalCompositeOperation =
|
|
150
|
+
| GlobalCompositeOperation
|
|
151
|
+
| "source-over"
|
|
152
|
+
| "source-in"
|
|
153
|
+
| "source-out"
|
|
154
|
+
| "source-atop"
|
|
155
|
+
| "destination-over"
|
|
156
|
+
| "destination-in"
|
|
157
|
+
| "destination-out"
|
|
158
|
+
| "destination-atop"
|
|
159
|
+
| "lighter"
|
|
160
|
+
| "copy"
|
|
161
|
+
| "xor"
|
|
162
|
+
| "multiply"
|
|
163
|
+
| "screen"
|
|
164
|
+
| "overlay"
|
|
165
|
+
| "darken"
|
|
166
|
+
| "lighten"
|
|
167
|
+
| "color-dodge"
|
|
168
|
+
| "color-burn"
|
|
169
|
+
| "hard-light"
|
|
170
|
+
| "soft-light"
|
|
171
|
+
| "difference"
|
|
172
|
+
| "exclusion"
|
|
173
|
+
| "hue"
|
|
174
|
+
| "saturation"
|
|
175
|
+
| "color"
|
|
176
|
+
| "luminosity";
|
|
177
|
+
|
|
178
|
+
export type AnyColorSpace = ColorSpace | "rgb565" | "rgba4444" | "rgba444";
|
|
179
|
+
|
|
180
|
+
export type AnyFilter =
|
|
181
|
+
| `sepia(${number}%)`
|
|
182
|
+
| `saturate(${number}%)`
|
|
183
|
+
| `opacity(${number}%)`
|
|
184
|
+
| `invert(${number}%)`
|
|
185
|
+
| `hue-rotate(${number}deg)`
|
|
186
|
+
| `grayscale(${number}%)`
|
|
187
|
+
| `drop-shadow(${number}px ${number}px ${number}px ${string})`
|
|
188
|
+
| `contrast(${number}%)`
|
|
189
|
+
| `brightness(${number}%)`
|
|
190
|
+
| `blur(${number}px)`;
|
|
191
|
+
|
|
192
|
+
export type Point = {
|
|
193
|
+
x: ScaleType;
|
|
194
|
+
y: ScaleType;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export type PointNumber = {
|
|
198
|
+
x: number;
|
|
199
|
+
y: number;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export type Extensions = "svg" | "png" | "jpeg" | "jpg" | "gif" | "webp" | "yaml" | "json";
|
|
203
|
+
|
|
204
|
+
export interface Transform {
|
|
205
|
+
rotate?: number;
|
|
206
|
+
scale?: {
|
|
207
|
+
x: number;
|
|
208
|
+
y: number;
|
|
209
|
+
};
|
|
210
|
+
translate?: {
|
|
211
|
+
x: number;
|
|
212
|
+
y: number;
|
|
213
|
+
};
|
|
214
|
+
matrix?: DOMMatrix2DInit;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type RadiusCorner = "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "all";
|
|
218
|
+
|
|
219
|
+
export type SubStringColor = {
|
|
220
|
+
color: StringColorType;
|
|
221
|
+
start: number;
|
|
222
|
+
end: number;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export type StrokeOptions = {
|
|
226
|
+
width: number;
|
|
227
|
+
cap?: CanvasLineCap;
|
|
228
|
+
join?: CanvasLineJoin;
|
|
229
|
+
dashOffset?: number;
|
|
230
|
+
dash?: number[];
|
|
231
|
+
miterLimit?: number;
|
|
232
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.APNGEncoder = void 0;
|
|
4
4
|
exports.createAPNG = createAPNG;
|
|
5
|
-
const
|
|
5
|
+
const node_zlib_1 = require("node:zlib");
|
|
6
6
|
/**
|
|
7
7
|
* APNG Encoder that works directly with Uint8ClampedArray (ImageData)
|
|
8
8
|
* Much faster than encoding each frame to PNG separately
|
|
@@ -148,7 +148,7 @@ class APNGEncoder {
|
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
// Compress with zlib
|
|
151
|
-
return (0,
|
|
151
|
+
return (0, node_zlib_1.deflateSync)(filtered, { level: 6 });
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* Create IEND chunk
|
package/dist/utils/utils.js
CHANGED
|
@@ -448,7 +448,9 @@ function resizeLayers(layers, ratio) {
|
|
|
448
448
|
else if (typeof layer.props.size.radius === "object") {
|
|
449
449
|
for (const corner in layer.props.size.radius) {
|
|
450
450
|
// @ts-ignore
|
|
451
|
-
layer.props.size.radius[corner] = resize(
|
|
451
|
+
layer.props.size.radius[corner] = resize(
|
|
452
|
+
// @ts-ignore
|
|
453
|
+
layer.props.size.radius[corner], ratio);
|
|
452
454
|
}
|
|
453
455
|
}
|
|
454
456
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nmmty/lazycanvas",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.4",
|
|
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",
|
|
@@ -25,9 +25,7 @@
|
|
|
25
25
|
"@napi-rs/canvas": "^0.1.88",
|
|
26
26
|
"gifenc": "^1.0.3",
|
|
27
27
|
"js-yaml": "^4.1.0",
|
|
28
|
-
"
|
|
29
|
-
"svgson": "^5.3.1",
|
|
30
|
-
"zlib": "^1.0.5"
|
|
28
|
+
"svgson": "^5.3.1"
|
|
31
29
|
},
|
|
32
30
|
"devDependencies": {
|
|
33
31
|
"@biomejs/biome": "1.9.4",
|