apexify.js 4.8.2 → 4.8.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.
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/ai/ApexAI.ts +4 -4
- package/lib/ai/ApexModules.ts +8 -8
- package/lib/ai/modals/electronHub/chatmodels.ts +1 -1
- package/lib/ai/modals/electronHub/imageModels.ts +2 -2
- package/lib/ai/modals/electronHub/speechModels.ts +1 -1
- package/lib/ai/utils.ts +3 -3
- package/lib/canvas/ApexPainter.ts +1 -1
- package/lib/canvas/utils/Background/bg.ts +1 -1
- package/lib/canvas/utils/Charts/charts.ts +1 -1
- package/lib/canvas/utils/Custom/customLines.ts +2 -2
- package/lib/canvas/utils/General/general functions.ts +1 -1
- package/lib/canvas/utils/Image/imageProperties.ts +1 -1
- package/lib/canvas/utils/Texts/textProperties.ts +1 -1
- package/lib/canvas/utils/utils.ts +8 -8
- package/lib/index.ts +5 -5
- package/lib/utils.ts +3 -3
- package/package.json +5 -5
- package/dist/cjs/ai/ApexAI.d.ts +0 -144
- package/dist/cjs/ai/ApexAI.js +0 -486
- package/dist/cjs/ai/ApexModules.d.ts +0 -52
- package/dist/cjs/ai/ApexModules.js +0 -811
- package/dist/cjs/ai/functions/readFiles.d.ts +0 -1
- package/dist/cjs/ai/functions/readFiles.js +0 -56
- package/dist/cjs/ai/functions/tokenizer.d.ts +0 -9
- package/dist/cjs/ai/functions/tokenizer.js +0 -60
- package/dist/cjs/ai/functions/validOptions.d.ts +0 -21
- package/dist/cjs/ai/functions/validOptions.js +0 -93
- package/dist/cjs/ai/modals/electronHub/chatmodels.d.ts +0 -6
- package/dist/cjs/ai/modals/electronHub/chatmodels.js +0 -44
- package/dist/cjs/ai/modals/electronHub/imageModels.d.ts +0 -11
- package/dist/cjs/ai/modals/electronHub/imageModels.js +0 -85
- package/dist/cjs/ai/modals/electronHub/songModels.d.ts +0 -1
- package/dist/cjs/ai/modals/electronHub/songModels.js +0 -1
- package/dist/cjs/ai/modals/electronHub/speechModels.d.ts +0 -6
- package/dist/cjs/ai/modals/electronHub/speechModels.js +0 -56
- package/dist/cjs/ai/modals/electronHub/videoModels.d.ts +0 -5
- package/dist/cjs/ai/modals/electronHub/videoModels.js +0 -56
- package/dist/cjs/ai/modals/groq/chatgroq.d.ts +0 -8
- package/dist/cjs/ai/modals/groq/chatgroq.js +0 -57
- package/dist/cjs/ai/modals/groq/imageAnalyzer.d.ts +0 -7
- package/dist/cjs/ai/modals/groq/imageAnalyzer.js +0 -75
- package/dist/cjs/ai/modals/groq/whisper.d.ts +0 -4
- package/dist/cjs/ai/modals/groq/whisper.js +0 -101
- package/dist/cjs/ai/modals/hercai/chatModels.d.ts +0 -6
- package/dist/cjs/ai/modals/hercai/chatModels.js +0 -19
- package/dist/cjs/ai/utils.d.ts +0 -4
- package/dist/cjs/ai/utils.js +0 -4
- package/dist/cjs/canvas/ApexPainter.d.ts +0 -144
- package/dist/cjs/canvas/ApexPainter.js +0 -900
- package/dist/cjs/canvas/utils/Background/bg.d.ts +0 -30
- package/dist/cjs/canvas/utils/Background/bg.js +0 -151
- package/dist/cjs/canvas/utils/Charts/charts.d.ts +0 -7
- package/dist/cjs/canvas/utils/Charts/charts.js +0 -455
- package/dist/cjs/canvas/utils/Custom/customLines.d.ts +0 -2
- package/dist/cjs/canvas/utils/Custom/customLines.js +0 -105
- package/dist/cjs/canvas/utils/General/conversion.d.ts +0 -5
- package/dist/cjs/canvas/utils/General/conversion.js +0 -26
- package/dist/cjs/canvas/utils/General/general functions.d.ts +0 -38
- package/dist/cjs/canvas/utils/General/general functions.js +0 -590
- package/dist/cjs/canvas/utils/Image/imageProperties.d.ts +0 -114
- package/dist/cjs/canvas/utils/Image/imageProperties.js +0 -590
- package/dist/cjs/canvas/utils/Texts/textProperties.d.ts +0 -16
- package/dist/cjs/canvas/utils/Texts/textProperties.js +0 -154
- package/dist/cjs/canvas/utils/types.d.ts +0 -621
- package/dist/cjs/canvas/utils/types.js +0 -5
- package/dist/cjs/canvas/utils/utils.d.ts +0 -18
- package/dist/cjs/canvas/utils/utils.js +0 -17
- package/dist/cjs/index.d.ts +0 -28
- package/dist/cjs/index.js +0 -67
- package/dist/cjs/utils.d.ts +0 -4
- package/dist/cjs/utils.js +0 -4
- package/dist/esm/ai/ApexAI.d.ts +0 -144
- package/dist/esm/ai/ApexAI.js +0 -486
- package/dist/esm/ai/ApexModules.d.ts +0 -52
- package/dist/esm/ai/ApexModules.js +0 -811
- package/dist/esm/ai/functions/readFiles.d.ts +0 -1
- package/dist/esm/ai/functions/readFiles.js +0 -56
- package/dist/esm/ai/functions/tokenizer.d.ts +0 -9
- package/dist/esm/ai/functions/tokenizer.js +0 -60
- package/dist/esm/ai/functions/validOptions.d.ts +0 -21
- package/dist/esm/ai/functions/validOptions.js +0 -93
- package/dist/esm/ai/modals/electronHub/chatmodels.d.ts +0 -6
- package/dist/esm/ai/modals/electronHub/chatmodels.js +0 -44
- package/dist/esm/ai/modals/electronHub/imageModels.d.ts +0 -11
- package/dist/esm/ai/modals/electronHub/imageModels.js +0 -85
- package/dist/esm/ai/modals/electronHub/songModels.d.ts +0 -1
- package/dist/esm/ai/modals/electronHub/songModels.js +0 -1
- package/dist/esm/ai/modals/electronHub/speechModels.d.ts +0 -6
- package/dist/esm/ai/modals/electronHub/speechModels.js +0 -56
- package/dist/esm/ai/modals/electronHub/videoModels.d.ts +0 -5
- package/dist/esm/ai/modals/electronHub/videoModels.js +0 -56
- package/dist/esm/ai/modals/groq/chatgroq.d.ts +0 -8
- package/dist/esm/ai/modals/groq/chatgroq.js +0 -57
- package/dist/esm/ai/modals/groq/imageAnalyzer.d.ts +0 -7
- package/dist/esm/ai/modals/groq/imageAnalyzer.js +0 -75
- package/dist/esm/ai/modals/groq/whisper.d.ts +0 -4
- package/dist/esm/ai/modals/groq/whisper.js +0 -101
- package/dist/esm/ai/modals/hercai/chatModels.d.ts +0 -6
- package/dist/esm/ai/modals/hercai/chatModels.js +0 -19
- package/dist/esm/ai/utils.d.ts +0 -4
- package/dist/esm/ai/utils.js +0 -4
- package/dist/esm/canvas/ApexPainter.d.ts +0 -144
- package/dist/esm/canvas/ApexPainter.js +0 -900
- package/dist/esm/canvas/utils/Background/bg.d.ts +0 -30
- package/dist/esm/canvas/utils/Background/bg.js +0 -151
- package/dist/esm/canvas/utils/Charts/charts.d.ts +0 -7
- package/dist/esm/canvas/utils/Charts/charts.js +0 -455
- package/dist/esm/canvas/utils/Custom/customLines.d.ts +0 -2
- package/dist/esm/canvas/utils/Custom/customLines.js +0 -105
- package/dist/esm/canvas/utils/General/conversion.d.ts +0 -5
- package/dist/esm/canvas/utils/General/conversion.js +0 -26
- package/dist/esm/canvas/utils/General/general functions.d.ts +0 -38
- package/dist/esm/canvas/utils/General/general functions.js +0 -590
- package/dist/esm/canvas/utils/Image/imageProperties.d.ts +0 -114
- package/dist/esm/canvas/utils/Image/imageProperties.js +0 -590
- package/dist/esm/canvas/utils/Texts/textProperties.d.ts +0 -16
- package/dist/esm/canvas/utils/Texts/textProperties.js +0 -154
- package/dist/esm/canvas/utils/types.d.ts +0 -621
- package/dist/esm/canvas/utils/types.js +0 -5
- package/dist/esm/canvas/utils/utils.d.ts +0 -18
- package/dist/esm/canvas/utils/utils.js +0 -17
- package/dist/esm/index.d.ts +0 -28
- package/dist/esm/index.js +0 -67
- package/dist/esm/utils.d.ts +0 -4
- package/dist/esm/utils.js +0 -4
- package/lib/ai/modals/electronHub/songModels.ts +0 -0
|
@@ -1,590 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Applies shadow to the canvas context.
|
|
3
|
-
* @param ctx The canvas rendering context.
|
|
4
|
-
* @param shadow The shadow properties.
|
|
5
|
-
* @param x The x-coordinate of the shape.
|
|
6
|
-
* @param y The y-coordinate of the shape.
|
|
7
|
-
* @param width The width of the shape.
|
|
8
|
-
* @param height The height of the shape.
|
|
9
|
-
*/
|
|
10
|
-
export function applyShadow(ctx, shadow, x, y, width, height) {
|
|
11
|
-
ctx.save();
|
|
12
|
-
if (shadow) {
|
|
13
|
-
ctx.globalAlpha = shadow.opacity ?? 1;
|
|
14
|
-
ctx.filter = `blur(${shadow.blur ?? 0}px)`;
|
|
15
|
-
const shadowX = x + (shadow.offsetX ?? 0);
|
|
16
|
-
const shadowY = y + (shadow.offsetY ?? 0);
|
|
17
|
-
objectRadius(ctx, shadowX, shadowY, width, height, shadow.borderRadius ?? 2);
|
|
18
|
-
ctx.fillStyle = shadow.gradient
|
|
19
|
-
? createGradient(ctx, shadow.gradient, shadowX, shadowY, shadowX + width, shadowY + height)
|
|
20
|
-
: shadow.color || "transparent";
|
|
21
|
-
ctx.fill();
|
|
22
|
-
}
|
|
23
|
-
ctx.filter = "none";
|
|
24
|
-
ctx.globalAlpha = 1;
|
|
25
|
-
ctx.restore();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Applies zoom (scaling) to the canvas context around a specified point.
|
|
29
|
-
* @param ctx The canvas rendering context.
|
|
30
|
-
* @param zoom An object with scale (zoom factor) and the x/y coordinates that act as the zoom origin.
|
|
31
|
-
*/
|
|
32
|
-
export function applyZoom(ctx, zoom) {
|
|
33
|
-
if (!zoom)
|
|
34
|
-
return;
|
|
35
|
-
const scale = zoom.scale ?? 1;
|
|
36
|
-
const zoomX = zoom.x ?? 0;
|
|
37
|
-
const zoomY = zoom.y ?? 0;
|
|
38
|
-
ctx.translate(zoomX, zoomY);
|
|
39
|
-
ctx.scale(scale, scale);
|
|
40
|
-
ctx.translate(-zoomX, -zoomY);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Applies stroke to the canvas context with support for selective side strokes.
|
|
44
|
-
* Supports optional blur effect on the stroke.
|
|
45
|
-
*
|
|
46
|
-
* @param ctx The canvas rendering context.
|
|
47
|
-
* @param stroke The stroke properties.
|
|
48
|
-
* @param x The x-coordinate of the shape.
|
|
49
|
-
* @param y The y-coordinate of the shape.
|
|
50
|
-
* @param width The width of the shape.
|
|
51
|
-
* @param height The height of the shape.
|
|
52
|
-
* @param blur Optional blur effect on the stroke.
|
|
53
|
-
*/
|
|
54
|
-
export function applyStroke(ctx, stroke, x, y, width, height, shapeName) {
|
|
55
|
-
if (!stroke)
|
|
56
|
-
return;
|
|
57
|
-
ctx.save();
|
|
58
|
-
if (stroke.blur && stroke.blur > 0) {
|
|
59
|
-
ctx.filter = `blur(${stroke.blur}px)`;
|
|
60
|
-
}
|
|
61
|
-
ctx.strokeStyle = stroke.gradient
|
|
62
|
-
? createGradient(ctx, stroke.gradient, x, y, x + width, y + height)
|
|
63
|
-
: stroke.color || "transparent";
|
|
64
|
-
ctx.lineWidth = stroke.width && stroke.width > 0 ? stroke.width : 2;
|
|
65
|
-
ctx.beginPath();
|
|
66
|
-
const borderPos = stroke.position || 0;
|
|
67
|
-
// Adjust the bounding box by borderPos
|
|
68
|
-
// - Positive borderPos moves stroke outward
|
|
69
|
-
// - Negative borderPos moves stroke inward
|
|
70
|
-
const offsetX = x - borderPos;
|
|
71
|
-
const offsetY = y - borderPos;
|
|
72
|
-
const offsetW = width + 2 * borderPos;
|
|
73
|
-
const offsetH = height + 2 * borderPos;
|
|
74
|
-
ctx.beginPath();
|
|
75
|
-
// For known shapes (circle, star, etc.), re-draw with adjusted bounding box
|
|
76
|
-
if ([
|
|
77
|
-
"heart", "arrow", "circle", "star",
|
|
78
|
-
"pentagon", "hexagon", "heptagon", "octagon",
|
|
79
|
-
"diamond", "trapezoid", "kite",
|
|
80
|
-
].includes(shapeName)) {
|
|
81
|
-
switch (shapeName) {
|
|
82
|
-
case "circle":
|
|
83
|
-
// Circle centered in the new bounding box
|
|
84
|
-
ctx.arc(offsetX + offsetW / 2, offsetY + offsetH / 2, offsetW / 2, // radius
|
|
85
|
-
0, Math.PI * 2);
|
|
86
|
-
break;
|
|
87
|
-
case "star":
|
|
88
|
-
drawStar(ctx, offsetX, offsetY, offsetW, offsetH);
|
|
89
|
-
break;
|
|
90
|
-
case "arrow":
|
|
91
|
-
drawArrow(ctx, offsetX, offsetY, offsetW, offsetH);
|
|
92
|
-
break;
|
|
93
|
-
case "pentagon":
|
|
94
|
-
case "hexagon":
|
|
95
|
-
case "heptagon":
|
|
96
|
-
case "octagon": {
|
|
97
|
-
const sides = parseInt(shapeName.replace(/\D/g, ""), 10);
|
|
98
|
-
drawPolygon(ctx, offsetX, offsetY, offsetW, offsetH, sides);
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
case "diamond":
|
|
102
|
-
ctx.moveTo(offsetX + offsetW / 2, offsetY);
|
|
103
|
-
ctx.lineTo(offsetX + offsetW, offsetY + offsetH / 2);
|
|
104
|
-
ctx.lineTo(offsetX + offsetW / 2, offsetY + offsetH);
|
|
105
|
-
ctx.lineTo(offsetX, offsetY + offsetH / 2);
|
|
106
|
-
ctx.closePath();
|
|
107
|
-
break;
|
|
108
|
-
case "trapezoid": {
|
|
109
|
-
const topWidth = offsetW * 0.6;
|
|
110
|
-
const offsetVal = (offsetW - topWidth) / 2;
|
|
111
|
-
ctx.moveTo(offsetX + offsetVal, offsetY);
|
|
112
|
-
ctx.lineTo(offsetX + offsetVal + topWidth, offsetY);
|
|
113
|
-
ctx.lineTo(offsetX + offsetW, offsetY + offsetH);
|
|
114
|
-
ctx.lineTo(offsetX, offsetY + offsetH);
|
|
115
|
-
ctx.closePath();
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case "heart":
|
|
119
|
-
drawHeart(ctx, offsetX, offsetY, offsetW, offsetH);
|
|
120
|
-
break;
|
|
121
|
-
case "kite":
|
|
122
|
-
ctx.moveTo(offsetX + offsetW / 2, offsetY);
|
|
123
|
-
ctx.lineTo(offsetX + offsetW, offsetY + offsetH / 2);
|
|
124
|
-
ctx.lineTo(offsetX + offsetW / 2, offsetY + offsetH);
|
|
125
|
-
ctx.lineTo(offsetX, offsetY + offsetH / 2);
|
|
126
|
-
ctx.closePath();
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
ctx.globalCompositeOperation = "source-atop";
|
|
132
|
-
objectRadius(ctx, offsetX, offsetY, offsetW, offsetH, stroke.borderRadius || 2, stroke.borderPosition);
|
|
133
|
-
}
|
|
134
|
-
ctx.stroke();
|
|
135
|
-
ctx.filter = "none";
|
|
136
|
-
ctx.restore();
|
|
137
|
-
}
|
|
138
|
-
export function drawShape(ctx, shapeSettings) {
|
|
139
|
-
const { source, x, y, width, height, opacity, rotation = 0, borderRadius = 0, borderPosition = 'all', stroke, shadow, isFilled = false, color = "transparent", gradient, filling, } = shapeSettings;
|
|
140
|
-
const shapeName = source.toLowerCase();
|
|
141
|
-
ctx.save();
|
|
142
|
-
applyRotation(ctx, rotation, x, y, width, height);
|
|
143
|
-
applyShadow(ctx, shadow, x, y, width, height);
|
|
144
|
-
ctx.beginPath();
|
|
145
|
-
ctx.globalAlpha = opacity;
|
|
146
|
-
switch (shapeName) {
|
|
147
|
-
case 'circle': {
|
|
148
|
-
ctx.arc(x + width / 2, y + height / 2, width / 2, 0, Math.PI * 2);
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
case 'square': {
|
|
152
|
-
ctx.rect(x, y, width, height);
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
case 'triangle': {
|
|
156
|
-
ctx.moveTo(x + width / 2, y);
|
|
157
|
-
ctx.lineTo(x, y + height);
|
|
158
|
-
ctx.lineTo(x + width, y + height);
|
|
159
|
-
ctx.closePath();
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
case 'pentagon':
|
|
163
|
-
case 'hexagon':
|
|
164
|
-
case 'heptagon':
|
|
165
|
-
case 'octagon': {
|
|
166
|
-
const sides = parseInt(shapeName.replace(/\D/g, ""), 10);
|
|
167
|
-
drawPolygon(ctx, x, y, width, height, sides);
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
case 'star': {
|
|
171
|
-
drawStar(ctx, x, y, width, height);
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
case 'kite': {
|
|
175
|
-
ctx.moveTo(x + width / 2, y);
|
|
176
|
-
ctx.lineTo(x + width, y + height / 2);
|
|
177
|
-
ctx.lineTo(x + width / 2, y + height);
|
|
178
|
-
ctx.lineTo(x, y + height / 2);
|
|
179
|
-
ctx.closePath();
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
case 'oval': {
|
|
183
|
-
ctx.ellipse(x + width / 2, y + height / 2, width / 2, height / 2, 0, 0, Math.PI * 2);
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
case 'arrow': {
|
|
187
|
-
drawArrow(ctx, x, y, width, height);
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
case 'heart': {
|
|
191
|
-
drawHeart(ctx, x, y, width, height);
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
case 'diamond': {
|
|
195
|
-
ctx.moveTo(x + width / 2, y);
|
|
196
|
-
ctx.lineTo(x + width, y + height / 2);
|
|
197
|
-
ctx.lineTo(x + width / 2, y + height);
|
|
198
|
-
ctx.lineTo(x, y + height / 2);
|
|
199
|
-
ctx.closePath();
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
case 'trapezoid': {
|
|
203
|
-
const topWidth = width * 0.6;
|
|
204
|
-
const offset = (width - topWidth) / 2;
|
|
205
|
-
ctx.moveTo(x + offset, y);
|
|
206
|
-
ctx.lineTo(x + offset + topWidth, y);
|
|
207
|
-
ctx.lineTo(x + width, y + height);
|
|
208
|
-
ctx.lineTo(x, y + height);
|
|
209
|
-
ctx.closePath();
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
default: {
|
|
213
|
-
ctx.restore();
|
|
214
|
-
throw new Error(`Unsupported shape: ${shapeName}`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
if (isFilled) {
|
|
218
|
-
if (borderRadius && shapeName !== 'circle' && shapeName !== 'oval') {
|
|
219
|
-
objectRadius(ctx, x, y, width, height, borderRadius, borderPosition);
|
|
220
|
-
}
|
|
221
|
-
let fillStyle = color;
|
|
222
|
-
if (gradient) {
|
|
223
|
-
fillStyle = createGradient(ctx, gradient, x, y, x + width, y + height);
|
|
224
|
-
}
|
|
225
|
-
if (filling && filling.percentage <= 100) {
|
|
226
|
-
ctx.save();
|
|
227
|
-
const isCustomShape = ["heart", "arrow", "star", "pentagon", "hexagon", "heptagon", "octagon", "diamond", "trapezoid", "kite", "oval", "circle"].includes(shapeName);
|
|
228
|
-
if (isCustomShape) {
|
|
229
|
-
ctx.clip();
|
|
230
|
-
}
|
|
231
|
-
let fillX = x;
|
|
232
|
-
let fillY = y;
|
|
233
|
-
let fillWidth = width;
|
|
234
|
-
let fillHeight = height;
|
|
235
|
-
switch (filling.rotation) {
|
|
236
|
-
case 0:
|
|
237
|
-
fillHeight = (filling.percentage / 100) * height;
|
|
238
|
-
fillY = y + height - fillHeight;
|
|
239
|
-
break;
|
|
240
|
-
case 180:
|
|
241
|
-
fillHeight = (filling.percentage / 100) * height;
|
|
242
|
-
break;
|
|
243
|
-
case 90:
|
|
244
|
-
fillWidth = (filling.percentage / 100) * width;
|
|
245
|
-
break;
|
|
246
|
-
case 270:
|
|
247
|
-
fillWidth = (filling.percentage / 100) * width;
|
|
248
|
-
fillX = x + width - fillWidth;
|
|
249
|
-
break;
|
|
250
|
-
default:
|
|
251
|
-
console.warn(`Unsupported filling rotation: ${filling.rotation}, defaulting to 0 (Bottom to Top).`);
|
|
252
|
-
fillHeight = (filling.percentage / 100) * height;
|
|
253
|
-
fillY = y + height - fillHeight;
|
|
254
|
-
}
|
|
255
|
-
ctx.beginPath();
|
|
256
|
-
ctx.rect(fillX, fillY, fillWidth, fillHeight);
|
|
257
|
-
ctx.fillStyle = fillStyle;
|
|
258
|
-
ctx.fill();
|
|
259
|
-
ctx.restore();
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
ctx.fillStyle = fillStyle;
|
|
263
|
-
ctx.fill();
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
ctx.globalAlpha = 1.0;
|
|
267
|
-
if (stroke) {
|
|
268
|
-
if (stroke?.opacity)
|
|
269
|
-
ctx.globalAlpha = stroke.opacity;
|
|
270
|
-
applyStroke(ctx, stroke, x, y, width, height, shapeName);
|
|
271
|
-
ctx.globalAlpha = 1.0;
|
|
272
|
-
}
|
|
273
|
-
ctx.restore();
|
|
274
|
-
}
|
|
275
|
-
function drawHeart(ctx, x, y, width, height) {
|
|
276
|
-
ctx.beginPath();
|
|
277
|
-
ctx.moveTo(x + width / 2, y + height * 0.9);
|
|
278
|
-
ctx.bezierCurveTo(x + (width * 35) / 100, y + (height * 60) / 100, x + (width * 10) / 100, y + (height * 55) / 100, x + (width * 10) / 100, y + (height * 33.33) / 100);
|
|
279
|
-
ctx.bezierCurveTo(x + (width * 10) / 100, y + (height * 10) / 100, x + (width * 50) / 100, y + (height * 5) / 100, x + (width * 50) / 100, y + (height * 33.33) / 100);
|
|
280
|
-
ctx.bezierCurveTo(x + (width * 50) / 100, y + (height * 5) / 100, x + (width * 90) / 100, y + (height * 10) / 100, x + (width * 90) / 100, y + (height * 33.33) / 100);
|
|
281
|
-
ctx.bezierCurveTo(x + (width * 90) / 100, y + (height * 55) / 100, x + (width * 65) / 100, y + (height * 60) / 100, x + width / 2, y + height * 0.9);
|
|
282
|
-
ctx.closePath();
|
|
283
|
-
}
|
|
284
|
-
/** Draws a polygon with a given number of sides */
|
|
285
|
-
function drawPolygon(ctx, x, y, width, height, sides) {
|
|
286
|
-
const cx = x + width / 2;
|
|
287
|
-
const cy = y + height / 2;
|
|
288
|
-
const radius = Math.min(width, height) / 2;
|
|
289
|
-
ctx.moveTo(cx + radius, cy);
|
|
290
|
-
for (let i = 1; i <= sides; i++) {
|
|
291
|
-
const angle = (Math.PI * 2 * i) / sides;
|
|
292
|
-
ctx.lineTo(cx + radius * Math.cos(angle), cy + radius * Math.sin(angle));
|
|
293
|
-
}
|
|
294
|
-
ctx.closePath();
|
|
295
|
-
}
|
|
296
|
-
function drawArrow(ctx, x, y, width, height) {
|
|
297
|
-
const shaftWidth = width * 0.25;
|
|
298
|
-
const headWidth = width * 0.5;
|
|
299
|
-
const headHeight = height * 0.6;
|
|
300
|
-
ctx.beginPath();
|
|
301
|
-
ctx.moveTo(x, y + height / 2 - shaftWidth / 2);
|
|
302
|
-
ctx.lineTo(x + width - headWidth, y + height / 2 - shaftWidth / 2);
|
|
303
|
-
ctx.lineTo(x + width - headWidth, y);
|
|
304
|
-
ctx.lineTo(x + width, y + height / 2);
|
|
305
|
-
ctx.lineTo(x + width - headWidth, y + height);
|
|
306
|
-
ctx.lineTo(x + width - headWidth, y + height / 2 + shaftWidth / 2);
|
|
307
|
-
ctx.lineTo(x, y + height / 2 + shaftWidth / 2);
|
|
308
|
-
ctx.closePath();
|
|
309
|
-
}
|
|
310
|
-
function drawStar(ctx, x, y, width, height) {
|
|
311
|
-
const cx = x + width / 2;
|
|
312
|
-
const cy = y + height / 2;
|
|
313
|
-
const size = Math.min(width, height);
|
|
314
|
-
const outerRadius = size / 2;
|
|
315
|
-
const innerRadius = outerRadius * 0.5;
|
|
316
|
-
const rotationOffset = -Math.PI / 2;
|
|
317
|
-
ctx.beginPath();
|
|
318
|
-
for (let i = 0; i < 5; i++) {
|
|
319
|
-
let angle = (i * (Math.PI * 2)) / 5 + rotationOffset;
|
|
320
|
-
ctx.lineTo(cx + outerRadius * Math.cos(angle), cy + outerRadius * Math.sin(angle));
|
|
321
|
-
angle += Math.PI / 5;
|
|
322
|
-
ctx.lineTo(cx + innerRadius * Math.cos(angle), cy + innerRadius * Math.sin(angle));
|
|
323
|
-
}
|
|
324
|
-
ctx.closePath();
|
|
325
|
-
}
|
|
326
|
-
export function createGradient(ctx, gradientOptions, startX, startY, endX, endY) {
|
|
327
|
-
if (!gradientOptions || !gradientOptions.type || !gradientOptions.colors) {
|
|
328
|
-
throw new Error("Invalid gradient options. Provide a valid object with type and colors properties.");
|
|
329
|
-
}
|
|
330
|
-
if (!Array.isArray(gradientOptions.colors)) {
|
|
331
|
-
throw new Error("Invalid gradient options. The colors property should be an array of color stops.");
|
|
332
|
-
}
|
|
333
|
-
if (gradientOptions.type === "linear") {
|
|
334
|
-
if (typeof startX !== "number" ||
|
|
335
|
-
typeof startY !== "number" ||
|
|
336
|
-
typeof endX !== "number" ||
|
|
337
|
-
typeof endY !== "number") {
|
|
338
|
-
throw new Error("Invalid gradient options for linear gradient. Numeric values are required for startX, startY, endX, and endY.");
|
|
339
|
-
}
|
|
340
|
-
if (typeof gradientOptions.rotate === "number") {
|
|
341
|
-
const centerX = (startX + endX) / 2;
|
|
342
|
-
const centerY = (startY + endY) / 2;
|
|
343
|
-
const dx = endX - startX;
|
|
344
|
-
const dy = endY - startY;
|
|
345
|
-
const length = Math.sqrt(dx * dx + dy * dy);
|
|
346
|
-
const angleRad = (gradientOptions.rotate * Math.PI) / 180;
|
|
347
|
-
startX = centerX - (length / 2) * Math.cos(angleRad);
|
|
348
|
-
startY = centerY - (length / 2) * Math.sin(angleRad);
|
|
349
|
-
endX = centerX + (length / 2) * Math.cos(angleRad);
|
|
350
|
-
endY = centerY + (length / 2) * Math.sin(angleRad);
|
|
351
|
-
}
|
|
352
|
-
const gradient = ctx.createLinearGradient(startX, startY, endX, endY);
|
|
353
|
-
for (const colorStop of gradientOptions.colors) {
|
|
354
|
-
if (typeof colorStop.stop !== "number" ||
|
|
355
|
-
typeof colorStop.color !== "string") {
|
|
356
|
-
throw new Error("Invalid color stop. Each color stop should have a numeric stop value and a color string.");
|
|
357
|
-
}
|
|
358
|
-
gradient.addColorStop(colorStop.stop, colorStop.color);
|
|
359
|
-
}
|
|
360
|
-
return gradient;
|
|
361
|
-
}
|
|
362
|
-
else if (gradientOptions.type === "radial") {
|
|
363
|
-
if (typeof gradientOptions.startX !== "number" ||
|
|
364
|
-
typeof gradientOptions.startY !== "number" ||
|
|
365
|
-
typeof gradientOptions.startRadius !== "number" ||
|
|
366
|
-
typeof gradientOptions.endX !== "number" ||
|
|
367
|
-
typeof gradientOptions.endY !== "number" ||
|
|
368
|
-
typeof gradientOptions.endRadius !== "number") {
|
|
369
|
-
throw new Error("Invalid gradient options for radial gradient. Numeric values are required for startX, startY, startRadius, endX, endY, and endRadius.");
|
|
370
|
-
}
|
|
371
|
-
const gradient = ctx.createRadialGradient(gradientOptions.startX, gradientOptions.startY, gradientOptions.startRadius, gradientOptions.endX, gradientOptions.endY, gradientOptions.endRadius);
|
|
372
|
-
for (const colorStop of gradientOptions.colors) {
|
|
373
|
-
if (typeof colorStop.stop !== "number" ||
|
|
374
|
-
typeof colorStop.color !== "string") {
|
|
375
|
-
throw new Error("Invalid color stop. Each color stop should have a numeric stop value and a color string.");
|
|
376
|
-
}
|
|
377
|
-
gradient.addColorStop(colorStop.stop, colorStop.color);
|
|
378
|
-
}
|
|
379
|
-
return gradient;
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
throw new Error('Unsupported gradient type. Use "linear" or "radial".');
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Applies rotation to the canvas context.
|
|
387
|
-
* @param ctx The canvas rendering context.
|
|
388
|
-
* @param rotation The rotation angle in degrees.
|
|
389
|
-
* @param x The x-coordinate of the center of rotation.
|
|
390
|
-
* @param y The y-coordinate of the center of rotation.
|
|
391
|
-
* @param width The width of the shape.
|
|
392
|
-
* @param height The height of the shape.
|
|
393
|
-
*/
|
|
394
|
-
export function applyRotation(ctx, rotation, x, y, width, height) {
|
|
395
|
-
const rotationX = x + width / 2;
|
|
396
|
-
const rotationY = y + height / 2;
|
|
397
|
-
ctx.translate(rotationX, rotationY);
|
|
398
|
-
ctx.rotate((rotation * Math.PI) / 180);
|
|
399
|
-
ctx.translate(-rotationX, -rotationY);
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Applies border radius to the canvas context with selective corner support.
|
|
403
|
-
*
|
|
404
|
-
* @param ctx The canvas rendering context.
|
|
405
|
-
* @param image The image to be drawn (will be drawn after clipping).
|
|
406
|
-
* @param x The x-coordinate of the shape.
|
|
407
|
-
* @param y The y-coordinate of the shape.
|
|
408
|
-
* @param width The width of the shape.
|
|
409
|
-
* @param height The height of the shape.
|
|
410
|
-
* @param borderRadius The border radius value (number or "circular").
|
|
411
|
-
* @param borderPosition The sides or corners to round.
|
|
412
|
-
* Valid values include:
|
|
413
|
-
* - "all"
|
|
414
|
-
* - "top", "bottom", "left", "right"
|
|
415
|
-
* - "top-left", "top-right", "bottom-left", "bottom-right"
|
|
416
|
-
* - Or a comma‑separated list (e.g., "top, left, bottom")
|
|
417
|
-
*/
|
|
418
|
-
export function imageRadius(ctx, image, x, y, width, height, borderRadius, borderPosition = "all") {
|
|
419
|
-
ctx.save();
|
|
420
|
-
ctx.beginPath();
|
|
421
|
-
if (borderRadius === "circular") {
|
|
422
|
-
const circleRadius = Math.min(width, height) / 2;
|
|
423
|
-
ctx.arc(x + width / 2, y + height / 2, circleRadius, 0, 2 * Math.PI);
|
|
424
|
-
ctx.clip();
|
|
425
|
-
}
|
|
426
|
-
else if (typeof borderRadius === "number" && borderRadius > 0) {
|
|
427
|
-
const br = Math.min(borderRadius, width / 2, height / 2);
|
|
428
|
-
const selectedPositions = new Set(borderPosition.toLowerCase().split(",").map((s) => s.trim()));
|
|
429
|
-
const roundTopLeft = selectedPositions.has("all") || selectedPositions.has("top-left") || (selectedPositions.has("top") && selectedPositions.has("left"));
|
|
430
|
-
const roundTopRight = selectedPositions.has("all") || selectedPositions.has("top-right") || (selectedPositions.has("top") && selectedPositions.has("right"));
|
|
431
|
-
const roundBottomRight = selectedPositions.has("all") || selectedPositions.has("bottom-right") || (selectedPositions.has("bottom") && selectedPositions.has("right"));
|
|
432
|
-
const roundBottomLeft = selectedPositions.has("all") || selectedPositions.has("bottom-left") || (selectedPositions.has("bottom") && selectedPositions.has("left"));
|
|
433
|
-
const tl = roundTopLeft ? br : 0;
|
|
434
|
-
const tr = roundTopRight ? br : 0;
|
|
435
|
-
const brR = roundBottomRight ? br : 0;
|
|
436
|
-
const bl = roundBottomLeft ? br : 0;
|
|
437
|
-
ctx.moveTo(x + tl, y);
|
|
438
|
-
ctx.lineTo(x + width - tr, y);
|
|
439
|
-
if (tr > 0)
|
|
440
|
-
ctx.arc(x + width - tr, y + tr, tr, -Math.PI / 2, 0, false);
|
|
441
|
-
ctx.lineTo(x + width, y + height - brR);
|
|
442
|
-
if (brR > 0)
|
|
443
|
-
ctx.arc(x + width - brR, y + height - brR, brR, 0, Math.PI / 2, false);
|
|
444
|
-
ctx.lineTo(x + bl, y + height);
|
|
445
|
-
if (bl > 0)
|
|
446
|
-
ctx.arc(x + bl, y + height - bl, bl, Math.PI / 2, Math.PI, false);
|
|
447
|
-
ctx.lineTo(x, y + tl);
|
|
448
|
-
if (tl > 0)
|
|
449
|
-
ctx.arc(x + tl, y + tl, tl, Math.PI, -Math.PI / 2, false);
|
|
450
|
-
ctx.closePath();
|
|
451
|
-
ctx.clip();
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
ctx.rect(x, y, width, height);
|
|
455
|
-
ctx.clip();
|
|
456
|
-
}
|
|
457
|
-
ctx.drawImage(image, x, y, width, height);
|
|
458
|
-
ctx.restore();
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Creates a rounded rectangle (or circular) path on the canvas context.
|
|
462
|
-
*
|
|
463
|
-
* @param ctx The canvas rendering context.
|
|
464
|
-
* @param x The x-coordinate of the rectangle.
|
|
465
|
-
* @param y The y-coordinate of the rectangle.
|
|
466
|
-
* @param width The width of the rectangle.
|
|
467
|
-
* @param height The height of the rectangle.
|
|
468
|
-
* @param borderRadius The radius for rounding. Use a number (or string "circular" for a circle).
|
|
469
|
-
* @param borderPosition Which sides/corners to round. Valid values include:
|
|
470
|
-
* - "all" (default)
|
|
471
|
-
* - "top", "bottom", "left", "right"
|
|
472
|
-
* - "top-left", "top-right", "bottom-left", "bottom-right"
|
|
473
|
-
* - Or a comma-separated list, e.g. "top-left, bottom-right" or "top, left, bottom"
|
|
474
|
-
*/
|
|
475
|
-
export function objectRadius(ctx, x, y, width, height, borderRadius = 0.1, borderPosition = "all") {
|
|
476
|
-
ctx.beginPath();
|
|
477
|
-
if (borderRadius === "circular") {
|
|
478
|
-
// Draw a circular shape
|
|
479
|
-
const circleRadius = Math.min(width, height) / 2;
|
|
480
|
-
ctx.arc(x + width / 2, y + height / 2, circleRadius, 0, 2 * Math.PI);
|
|
481
|
-
}
|
|
482
|
-
else if (borderRadius > 0) {
|
|
483
|
-
const br = Math.min(borderRadius, width / 2, height / 2);
|
|
484
|
-
const selectedPositions = new Set(borderPosition.toLowerCase().split(",").map((s) => s.trim()));
|
|
485
|
-
// **Correct Grouping**
|
|
486
|
-
const roundTopLeft = selectedPositions.has("all") ||
|
|
487
|
-
selectedPositions.has("top-left") ||
|
|
488
|
-
selectedPositions.has("top") ||
|
|
489
|
-
selectedPositions.has("left");
|
|
490
|
-
const roundTopRight = selectedPositions.has("all") ||
|
|
491
|
-
selectedPositions.has("top-right") ||
|
|
492
|
-
selectedPositions.has("top") ||
|
|
493
|
-
selectedPositions.has("right");
|
|
494
|
-
const roundBottomRight = selectedPositions.has("all") ||
|
|
495
|
-
selectedPositions.has("bottom-right") ||
|
|
496
|
-
selectedPositions.has("bottom") ||
|
|
497
|
-
selectedPositions.has("right");
|
|
498
|
-
const roundBottomLeft = selectedPositions.has("all") ||
|
|
499
|
-
selectedPositions.has("bottom-left") ||
|
|
500
|
-
selectedPositions.has("bottom") ||
|
|
501
|
-
selectedPositions.has("left");
|
|
502
|
-
// **Assign correct radii**
|
|
503
|
-
const tl = roundTopLeft ? br : 0;
|
|
504
|
-
const tr = roundTopRight ? br : 0;
|
|
505
|
-
const brR = roundBottomRight ? br : 0;
|
|
506
|
-
const bl = roundBottomLeft ? br : 0;
|
|
507
|
-
// **Draw rounded rectangle**
|
|
508
|
-
ctx.moveTo(x + tl, y);
|
|
509
|
-
ctx.lineTo(x + width - tr, y);
|
|
510
|
-
if (tr > 0)
|
|
511
|
-
ctx.arc(x + width - tr, y + tr, tr, -Math.PI / 2, 0, false);
|
|
512
|
-
ctx.lineTo(x + width, y + height - brR);
|
|
513
|
-
if (brR > 0)
|
|
514
|
-
ctx.arc(x + width - brR, y + height - brR, brR, 0, Math.PI / 2, false);
|
|
515
|
-
ctx.lineTo(x + bl, y + height);
|
|
516
|
-
if (bl > 0)
|
|
517
|
-
ctx.arc(x + bl, y + height - bl, bl, Math.PI / 2, Math.PI, false);
|
|
518
|
-
ctx.lineTo(x, y + tl);
|
|
519
|
-
if (tl > 0)
|
|
520
|
-
ctx.arc(x + tl, y + tl, tl, Math.PI, -Math.PI / 2, false);
|
|
521
|
-
}
|
|
522
|
-
else {
|
|
523
|
-
// Default: Draw normal rectangle
|
|
524
|
-
ctx.rect(x, y, width, height);
|
|
525
|
-
}
|
|
526
|
-
ctx.closePath();
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Performs bilinear interpolation on four corners.
|
|
530
|
-
* @param corners The four corners (topLeft, topRight, bottomRight, bottomLeft).
|
|
531
|
-
* @param t Horizontal interpolation factor (0 to 1).
|
|
532
|
-
* @param u Vertical interpolation factor (0 to 1).
|
|
533
|
-
* @returns The interpolated point.
|
|
534
|
-
*/
|
|
535
|
-
function bilinearInterpolate(corners, t, u) {
|
|
536
|
-
const top = {
|
|
537
|
-
x: corners[0].x * (1 - t) + corners[1].x * t,
|
|
538
|
-
y: corners[0].y * (1 - t) + corners[1].y * t,
|
|
539
|
-
};
|
|
540
|
-
const bottom = {
|
|
541
|
-
x: corners[3].x * (1 - t) + corners[2].x * t,
|
|
542
|
-
y: corners[3].y * (1 - t) + corners[2].y * t,
|
|
543
|
-
};
|
|
544
|
-
return {
|
|
545
|
-
x: top.x * (1 - u) + bottom.x * u,
|
|
546
|
-
y: top.y * (1 - u) + bottom.y * u,
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* Applies a perspective warp to the given image by subdividing the source rectangle
|
|
551
|
-
* and drawing each cell with an affine transform approximating the local perspective.
|
|
552
|
-
*
|
|
553
|
-
* @param ctx The canvas rendering context.
|
|
554
|
-
* @param image The source image.
|
|
555
|
-
* @param x The x-coordinate where the image is drawn.
|
|
556
|
-
* @param y The y-coordinate where the image is drawn.
|
|
557
|
-
* @param width The width of the region to draw.
|
|
558
|
-
* @param height The height of the region to draw.
|
|
559
|
-
* @param perspective An object containing four destination corners:
|
|
560
|
-
* { topLeft, topRight, bottomRight, bottomLeft }.
|
|
561
|
-
* @param gridCols Number of columns to subdivide (default: 10).
|
|
562
|
-
* @param gridRows Number of rows to subdivide (default: 10).
|
|
563
|
-
*/
|
|
564
|
-
export async function applyPerspective(ctx, image, x, y, width, height, perspective, gridCols = 10, gridRows = 10) {
|
|
565
|
-
const cellWidth = width / gridCols;
|
|
566
|
-
const cellHeight = height / gridRows;
|
|
567
|
-
for (let row = 0; row < gridRows; row++) {
|
|
568
|
-
for (let col = 0; col < gridCols; col++) {
|
|
569
|
-
const sx = x + col * cellWidth;
|
|
570
|
-
const sy = y + row * cellHeight;
|
|
571
|
-
const t0 = col / gridCols;
|
|
572
|
-
const t1 = (col + 1) / gridCols;
|
|
573
|
-
const u0 = row / gridRows;
|
|
574
|
-
const u1 = (row + 1) / gridRows;
|
|
575
|
-
const destTL = bilinearInterpolate([perspective.topLeft, perspective.topRight, perspective.bottomRight, perspective.bottomLeft], t0, u0);
|
|
576
|
-
const destTR = bilinearInterpolate([perspective.topLeft, perspective.topRight, perspective.bottomRight, perspective.bottomLeft], t1, u0);
|
|
577
|
-
const destBL = bilinearInterpolate([perspective.topLeft, perspective.topRight, perspective.bottomRight, perspective.bottomLeft], t0, u1);
|
|
578
|
-
const a = (destTR.x - destTL.x) / cellWidth;
|
|
579
|
-
const b = (destTR.y - destTL.y) / cellWidth;
|
|
580
|
-
const c = (destBL.x - destTL.x) / cellHeight;
|
|
581
|
-
const d = (destBL.y - destTL.y) / cellHeight;
|
|
582
|
-
const e = destTL.x;
|
|
583
|
-
const f = destTL.y;
|
|
584
|
-
ctx.save();
|
|
585
|
-
ctx.setTransform(a, b, c, d, e, f);
|
|
586
|
-
ctx.drawImage(image, sx, sy, cellWidth, cellHeight, 0, 0, cellWidth, cellHeight);
|
|
587
|
-
ctx.restore();
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SKRSContext2D } from '@napi-rs/canvas';
|
|
2
|
-
import { TextObject } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* The main function that draws text with optional wrapping.
|
|
5
|
-
* @param ctx CanvasRenderingContext2D
|
|
6
|
-
* @param textOptions TextObject
|
|
7
|
-
*/
|
|
8
|
-
export declare function drawText(ctx: SKRSContext2D, textOptions: TextObject): void;
|
|
9
|
-
/**
|
|
10
|
-
* Handles word-based wrapping. Then draws each line with stroke, fill, gradient, etc.
|
|
11
|
-
*/
|
|
12
|
-
export declare function WrappedText(ctx: SKRSContext2D, text: string, startX: number, startY: number, maxWidth: number, options: TextObject): void;
|
|
13
|
-
/**
|
|
14
|
-
* Creates a linear or radial gradient for fill/stroke.
|
|
15
|
-
*/
|
|
16
|
-
export declare function createGradient(ctx: SKRSContext2D, gradientOptions: any, startX: number, startY: number, endX: number, endY: number): CanvasGradient;
|