apexify.js 4.6.2 → 4.6.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/cjs/ai/functions/readFiles.js +1 -1
- package/dist/cjs/ai/functions/readFiles.js.map +1 -1
- package/dist/cjs/ai/modals-chat/electronHub/chatmodels.d.ts.map +1 -1
- package/dist/cjs/ai/modals-chat/electronHub/chatmodels.js +2 -1
- package/dist/cjs/ai/modals-chat/electronHub/chatmodels.js.map +1 -1
- package/dist/cjs/ai/modals-chat/electronHub/speechModels.d.ts.map +1 -1
- package/dist/cjs/ai/modals-chat/electronHub/speechModels.js +1 -1
- package/dist/cjs/ai/modals-chat/electronHub/speechModels.js.map +1 -1
- package/dist/cjs/canvas/ApexPainter.d.ts.map +1 -1
- package/dist/cjs/canvas/ApexPainter.js +27 -28
- package/dist/cjs/canvas/ApexPainter.js.map +1 -1
- package/dist/cjs/canvas/Themes/Level-Up/levelup.d.ts +11 -0
- package/dist/cjs/canvas/Themes/Level-Up/levelup.d.ts.map +1 -0
- package/dist/cjs/canvas/Themes/Level-Up/levelup.js +163 -0
- package/dist/cjs/canvas/Themes/Level-Up/levelup.js.map +1 -0
- package/dist/cjs/canvas/utils/Background/bg.d.ts +17 -10
- package/dist/cjs/canvas/utils/Background/bg.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/Background/bg.js +102 -27
- package/dist/cjs/canvas/utils/Background/bg.js.map +1 -1
- package/dist/cjs/canvas/utils/Custom/customLines.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/Custom/customLines.js +43 -19
- package/dist/cjs/canvas/utils/Custom/customLines.js.map +1 -1
- package/dist/cjs/canvas/utils/General/general functions.d.ts +6 -1
- package/dist/cjs/canvas/utils/General/general functions.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/General/general functions.js +19 -20
- package/dist/cjs/canvas/utils/General/general functions.js.map +1 -1
- package/dist/cjs/canvas/utils/Image/imageProperties.d.ts +3 -9
- package/dist/cjs/canvas/utils/Image/imageProperties.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/Image/imageProperties.js +220 -214
- package/dist/cjs/canvas/utils/Image/imageProperties.js.map +1 -1
- package/dist/cjs/canvas/utils/Texts/textProperties.d.ts +12 -14
- package/dist/cjs/canvas/utils/Texts/textProperties.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/Texts/textProperties.js +100 -91
- package/dist/cjs/canvas/utils/Texts/textProperties.js.map +1 -1
- package/dist/cjs/canvas/utils/types.d.ts +89 -109
- package/dist/cjs/canvas/utils/types.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/types.js.map +1 -1
- package/dist/cjs/canvas/utils/utils.d.ts +2 -4
- package/dist/cjs/canvas/utils/utils.d.ts.map +1 -1
- package/dist/cjs/canvas/utils/utils.js +2 -5
- package/dist/cjs/canvas/utils/utils.js.map +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +31 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/ai/functions/readFiles.js +1 -1
- package/dist/esm/ai/functions/readFiles.js.map +1 -1
- package/dist/esm/ai/modals-chat/electronHub/chatmodels.d.ts.map +1 -1
- package/dist/esm/ai/modals-chat/electronHub/chatmodels.js +2 -1
- package/dist/esm/ai/modals-chat/electronHub/chatmodels.js.map +1 -1
- package/dist/esm/ai/modals-chat/electronHub/speechModels.d.ts.map +1 -1
- package/dist/esm/ai/modals-chat/electronHub/speechModels.js +1 -1
- package/dist/esm/ai/modals-chat/electronHub/speechModels.js.map +1 -1
- package/dist/esm/canvas/ApexPainter.d.ts.map +1 -1
- package/dist/esm/canvas/ApexPainter.js +27 -28
- package/dist/esm/canvas/ApexPainter.js.map +1 -1
- package/dist/esm/canvas/Themes/Level-Up/levelup.d.ts +11 -0
- package/dist/esm/canvas/Themes/Level-Up/levelup.d.ts.map +1 -0
- package/dist/esm/canvas/Themes/Level-Up/levelup.js +163 -0
- package/dist/esm/canvas/Themes/Level-Up/levelup.js.map +1 -0
- package/dist/esm/canvas/utils/Background/bg.d.ts +17 -10
- package/dist/esm/canvas/utils/Background/bg.d.ts.map +1 -1
- package/dist/esm/canvas/utils/Background/bg.js +102 -27
- package/dist/esm/canvas/utils/Background/bg.js.map +1 -1
- package/dist/esm/canvas/utils/Custom/customLines.d.ts.map +1 -1
- package/dist/esm/canvas/utils/Custom/customLines.js +43 -19
- package/dist/esm/canvas/utils/Custom/customLines.js.map +1 -1
- package/dist/esm/canvas/utils/General/general functions.d.ts +6 -1
- package/dist/esm/canvas/utils/General/general functions.d.ts.map +1 -1
- package/dist/esm/canvas/utils/General/general functions.js +19 -20
- package/dist/esm/canvas/utils/General/general functions.js.map +1 -1
- package/dist/esm/canvas/utils/Image/imageProperties.d.ts +3 -9
- package/dist/esm/canvas/utils/Image/imageProperties.d.ts.map +1 -1
- package/dist/esm/canvas/utils/Image/imageProperties.js +220 -214
- package/dist/esm/canvas/utils/Image/imageProperties.js.map +1 -1
- package/dist/esm/canvas/utils/Texts/textProperties.d.ts +12 -14
- package/dist/esm/canvas/utils/Texts/textProperties.d.ts.map +1 -1
- package/dist/esm/canvas/utils/Texts/textProperties.js +100 -91
- package/dist/esm/canvas/utils/Texts/textProperties.js.map +1 -1
- package/dist/esm/canvas/utils/types.d.ts +89 -109
- package/dist/esm/canvas/utils/types.d.ts.map +1 -1
- package/dist/esm/canvas/utils/types.js.map +1 -1
- package/dist/esm/canvas/utils/utils.d.ts +2 -4
- package/dist/esm/canvas/utils/utils.d.ts.map +1 -1
- package/dist/esm/canvas/utils/utils.js +2 -5
- package/dist/esm/canvas/utils/utils.js.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +31 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/ai/functions/readFiles.ts +1 -1
- package/lib/ai/modals-chat/electronHub/chatmodels.ts +4 -2
- package/lib/ai/modals-chat/electronHub/speechModels.ts +2 -1
- package/lib/canvas/ApexPainter.ts +52 -61
- package/lib/canvas/Themes/Level-Up/levelup.ts +183 -0
- package/lib/canvas/utils/Background/bg.ts +179 -65
- package/lib/canvas/utils/Custom/customLines.ts +53 -20
- package/lib/canvas/utils/General/general functions.ts +21 -29
- package/lib/canvas/utils/Image/imageProperties.ts +399 -318
- package/lib/canvas/utils/Texts/textProperties.ts +213 -162
- package/lib/canvas/utils/types.ts +74 -107
- package/lib/canvas/utils/utils.ts +2 -5
- package/lib/index.ts +38 -10
- package/package.json +2 -2
- package/dist/cjs/canvas/utils/Background/circular.d.ts +0 -3
- package/dist/cjs/canvas/utils/Background/circular.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/Background/circular.js +0 -13
- package/dist/cjs/canvas/utils/Background/circular.js.map +0 -1
- package/dist/cjs/canvas/utils/Background/radius.d.ts +0 -18
- package/dist/cjs/canvas/utils/Background/radius.d.ts.map +0 -1
- package/dist/cjs/canvas/utils/Background/radius.js +0 -104
- package/dist/cjs/canvas/utils/Background/radius.js.map +0 -1
- package/dist/esm/canvas/utils/Background/circular.d.ts +0 -3
- package/dist/esm/canvas/utils/Background/circular.d.ts.map +0 -1
- package/dist/esm/canvas/utils/Background/circular.js +0 -13
- package/dist/esm/canvas/utils/Background/circular.js.map +0 -1
- package/dist/esm/canvas/utils/Background/radius.d.ts +0 -18
- package/dist/esm/canvas/utils/Background/radius.d.ts.map +0 -1
- package/dist/esm/canvas/utils/Background/radius.js +0 -104
- package/dist/esm/canvas/utils/Background/radius.js.map +0 -1
- package/lib/canvas/utils/Background/circular.ts +0 -17
- package/lib/canvas/utils/Background/radius.ts +0 -102
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createGradient } from "../Image/imageProperties";
|
|
1
2
|
import { CustomOptions } from "../types";
|
|
2
3
|
|
|
3
4
|
export function customLines(ctx: any, options: CustomOptions[]) {
|
|
@@ -19,7 +20,7 @@ export function customLines(ctx: any, options: CustomOptions[]) {
|
|
|
19
20
|
|
|
20
21
|
if (!isSingleLine && inSingleLineSequence) {
|
|
21
22
|
ctx.stroke();
|
|
22
|
-
|
|
23
|
+
applyStroke(ctx, currentStyle, startCoordinates, endCoordinates);
|
|
23
24
|
inSingleLineSequence = false;
|
|
24
25
|
currentStyle = null;
|
|
25
26
|
}
|
|
@@ -37,7 +38,13 @@ export function customLines(ctx: any, options: CustomOptions[]) {
|
|
|
37
38
|
|
|
38
39
|
const appliedStyle = inSingleLineSequence ? currentStyle : lineStyle;
|
|
39
40
|
ctx.lineWidth = appliedStyle?.width || 1;
|
|
40
|
-
|
|
41
|
+
|
|
42
|
+
if (appliedStyle?.gradient) {
|
|
43
|
+
ctx.strokeStyle = createGradient(ctx, appliedStyle.gradient, start.x, start.y, endCoordinates.x, endCoordinates.y);
|
|
44
|
+
} else {
|
|
45
|
+
ctx.strokeStyle = appliedStyle?.color || 'black';
|
|
46
|
+
}
|
|
47
|
+
|
|
41
48
|
ctx.lineJoin = appliedStyle?.lineJoin || 'miter';
|
|
42
49
|
ctx.lineCap = appliedStyle?.lineCap || 'butt';
|
|
43
50
|
|
|
@@ -48,31 +55,36 @@ export function customLines(ctx: any, options: CustomOptions[]) {
|
|
|
48
55
|
ctx.setLineDash([]);
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
if (typeof appliedStyle?.lineRadius === 'number') {
|
|
52
|
-
const
|
|
58
|
+
if (typeof appliedStyle?.lineRadius === 'number' && appliedStyle.lineRadius > 0) {
|
|
59
|
+
const radius = appliedStyle.lineRadius;
|
|
53
60
|
const dx = endCoordinates.x - start.x;
|
|
54
61
|
const dy = endCoordinates.y - start.y;
|
|
55
62
|
const angle = Math.atan2(dy, dx);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
ctx.
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
|
|
64
|
+
ctx.lineCap = "round";
|
|
65
|
+
ctx.stroke();
|
|
66
|
+
|
|
67
|
+
ctx.beginPath();
|
|
68
|
+
ctx.arc(start.x, start.y, radius, angle + Math.PI / 2, angle - Math.PI / 2, true);
|
|
69
|
+
ctx.arc(endCoordinates.x, endCoordinates.y, radius, angle - Math.PI / 2, angle + Math.PI / 2, false);
|
|
70
|
+
ctx.fill();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
else if (appliedStyle?.lineRadius === 'circular') {
|
|
61
74
|
const dx = endCoordinates.x - start.x;
|
|
62
75
|
const dy = endCoordinates.y - start.y;
|
|
63
76
|
const length = Math.sqrt(dx * dx + dy * dy);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
ctx.
|
|
67
|
-
ctx.
|
|
68
|
-
ctx.lineTo(endCoordinates.x + Math.cos(angle + Math.PI / 2) * halfWidth, endCoordinates.y + Math.sin(angle + Math.PI / 2) * halfWidth);
|
|
69
|
-
ctx.arc(endCoordinates.x, endCoordinates.y, length / 2, angle + Math.PI / 2, angle - Math.PI / 2, true);
|
|
77
|
+
|
|
78
|
+
ctx.beginPath();
|
|
79
|
+
ctx.arcTo(start.x, start.y, endCoordinates.x, endCoordinates.y, length / 2);
|
|
80
|
+
ctx.arcTo(endCoordinates.x, endCoordinates.y, start.x, start.y, length / 2);
|
|
70
81
|
ctx.closePath();
|
|
82
|
+
ctx.stroke();
|
|
71
83
|
}
|
|
72
84
|
|
|
73
85
|
if (!inSingleLineSequence || i === options.length - 1) {
|
|
74
86
|
ctx.stroke();
|
|
75
|
-
|
|
87
|
+
applyStroke(ctx, appliedStyle, startCoordinates, endCoordinates);
|
|
76
88
|
}
|
|
77
89
|
|
|
78
90
|
previousEndCoordinates = endCoordinates;
|
|
@@ -84,11 +96,32 @@ export function customLines(ctx: any, options: CustomOptions[]) {
|
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
98
|
|
|
87
|
-
function
|
|
99
|
+
function applyStroke(ctx: any, style: any, start: any, end: any) {
|
|
88
100
|
if (style.stroke) {
|
|
89
|
-
const { color, width } = style.stroke;
|
|
90
|
-
ctx.strokeStyle
|
|
91
|
-
ctx.lineWidth
|
|
101
|
+
const { color, width, gradient, lineRadius, lineCap } = style.stroke;
|
|
102
|
+
const prevStrokeStyle = ctx.strokeStyle;
|
|
103
|
+
const prevLineWidth = ctx.lineWidth;
|
|
104
|
+
const prevLineCap = ctx.lineCap;
|
|
105
|
+
|
|
106
|
+
if (gradient) {
|
|
107
|
+
ctx.strokeStyle = createGradient(ctx, gradient, start.x, start.y, end.x, end.y);
|
|
108
|
+
} else {
|
|
109
|
+
ctx.strokeStyle = color || prevStrokeStyle;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
ctx.lineWidth = width || prevLineWidth;
|
|
113
|
+
ctx.lineCap = lineCap || prevLineCap;
|
|
92
114
|
ctx.stroke();
|
|
115
|
+
|
|
116
|
+
if (typeof lineRadius === 'number' && lineRadius > 0) {
|
|
117
|
+
ctx.beginPath();
|
|
118
|
+
ctx.arc(start.x, start.y, lineRadius, 0, Math.PI * 2);
|
|
119
|
+
ctx.arc(end.x, end.y, lineRadius, 0, Math.PI * 2);
|
|
120
|
+
ctx.fill();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
ctx.strokeStyle = prevStrokeStyle;
|
|
124
|
+
ctx.lineWidth = prevLineWidth;
|
|
125
|
+
ctx.lineCap = prevLineCap;
|
|
93
126
|
}
|
|
94
127
|
}
|
|
@@ -31,7 +31,6 @@ export async function loadImages(imagePath: string) {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Resizes an image using Sharp with additional options for quality, kernel, and withoutEnlargement.
|
|
34
|
-
*
|
|
35
34
|
* @param resizeOptions - The options for resizing.
|
|
36
35
|
* @returns A Promise that resolves with the resized image as a Buffer.
|
|
37
36
|
*/
|
|
@@ -41,14 +40,8 @@ export async function resizingImg(resizeOptions: ResizeOptions): Promise<Buffer>
|
|
|
41
40
|
throw new Error("Image path is required for resizing.");
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
absoluteImagePath = resizeOptions.imagePath;
|
|
47
|
-
} else {
|
|
48
|
-
absoluteImagePath = path.join(process.cwd(), resizeOptions.imagePath);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const image = sharp(absoluteImagePath);
|
|
43
|
+
// ✅ Use `loadImages()` instead of handling the fetch manually
|
|
44
|
+
const image = await loadImages(resizeOptions.imagePath);
|
|
52
45
|
|
|
53
46
|
const resizeOptionsForSharp: sharp.ResizeOptions = {
|
|
54
47
|
width: resizeOptions.size?.width || 500,
|
|
@@ -60,21 +53,18 @@ export async function resizingImg(resizeOptions: ResizeOptions): Promise<Buffer>
|
|
|
60
53
|
|
|
61
54
|
const quality = resizeOptions.quality ?? 90;
|
|
62
55
|
|
|
63
|
-
const resizedBuffer: Buffer =
|
|
56
|
+
const resizedBuffer: Buffer = await image
|
|
64
57
|
.resize(resizeOptionsForSharp)
|
|
65
58
|
.png({ quality })
|
|
66
59
|
.toBuffer();
|
|
67
|
-
|
|
68
60
|
|
|
69
61
|
return resizedBuffer;
|
|
70
|
-
|
|
71
62
|
} catch (error) {
|
|
72
63
|
console.error("Error resizing image:", error);
|
|
73
64
|
throw new Error("Failed to resize image");
|
|
74
65
|
}
|
|
75
66
|
}
|
|
76
67
|
|
|
77
|
-
|
|
78
68
|
export async function converter(imagePath: string, newExtension: string) {
|
|
79
69
|
try {
|
|
80
70
|
const validExtensions: (keyof sharp.FormatEnum)[] = ['jpeg', 'png', 'webp', 'tiff', 'gif', 'avif', 'heif', 'raw', 'pdf', 'svg'];
|
|
@@ -382,53 +372,55 @@ export async function cropOuter(options: cropOptions): Promise<Buffer> {
|
|
|
382
372
|
}
|
|
383
373
|
|
|
384
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Detects dominant colors from an image.
|
|
377
|
+
*
|
|
378
|
+
* @param imagePath - Local path or URL of the image.
|
|
379
|
+
* @returns A sorted array of dominant colors with their frequency.
|
|
380
|
+
*/
|
|
385
381
|
export async function detectColors(imagePath: string): Promise<{ color: string; frequency: string }[]> {
|
|
386
382
|
try {
|
|
387
383
|
let image: any;
|
|
384
|
+
|
|
388
385
|
if (imagePath.startsWith('http')) {
|
|
389
386
|
const response = await fetch(imagePath);
|
|
390
|
-
if (!response.ok) {
|
|
391
|
-
throw new Error("Failed to fetch image.");
|
|
392
|
-
}
|
|
387
|
+
if (!response.ok) throw new Error(`Failed to fetch image: ${response.statusText}`);
|
|
393
388
|
const buffer = await response.arrayBuffer();
|
|
394
389
|
image = await loadImage(Buffer.from(buffer));
|
|
395
390
|
} else {
|
|
396
|
-
const localImagePath = path.
|
|
391
|
+
const localImagePath = path.resolve(imagePath);
|
|
397
392
|
image = await loadImage(localImagePath);
|
|
398
393
|
}
|
|
399
394
|
|
|
400
395
|
const canvas = createCanvas(image.width, image.height);
|
|
401
|
-
const ctx = canvas.getContext('2d')
|
|
402
|
-
|
|
396
|
+
const ctx = canvas.getContext('2d');
|
|
403
397
|
ctx.drawImage(image, 0, 0, image.width, image.height);
|
|
404
398
|
|
|
405
399
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
406
400
|
const data = imageData.data;
|
|
407
401
|
|
|
408
402
|
const colorFrequency: { [color: string]: number } = {};
|
|
409
|
-
|
|
410
403
|
for (let i = 0; i < data.length; i += 4) {
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
const blue = data[i + 2];
|
|
414
|
-
|
|
415
|
-
const color = `${red},${green},${blue}`;
|
|
404
|
+
const [r, g, b, a] = [data[i], data[i + 1], data[i + 2], data[i + 3]];
|
|
405
|
+
if (a < 50) continue;
|
|
416
406
|
|
|
407
|
+
const color = `${r},${g},${b}`;
|
|
417
408
|
colorFrequency[color] = (colorFrequency[color] || 0) + 1;
|
|
418
409
|
}
|
|
419
410
|
|
|
420
411
|
const totalPixels = canvas.width * canvas.height;
|
|
421
412
|
|
|
422
413
|
const dominantColors = Object.entries(colorFrequency)
|
|
423
|
-
.
|
|
424
|
-
.map(([color, frequency]: [string, number]) => ({
|
|
414
|
+
.map(([color, frequency]) => ({
|
|
425
415
|
color,
|
|
426
416
|
frequency: ((frequency / totalPixels) * 100).toFixed(2),
|
|
427
|
-
}))
|
|
417
|
+
}))
|
|
418
|
+
.filter(colorObj => parseFloat(colorObj.frequency) >= 0.1)
|
|
419
|
+
.sort((a, b) => parseFloat(b.frequency) - parseFloat(a.frequency));
|
|
428
420
|
|
|
429
421
|
return dominantColors;
|
|
430
422
|
} catch (error) {
|
|
431
|
-
console.error(
|
|
423
|
+
console.error("❌ Error detecting colors:", error);
|
|
432
424
|
return [];
|
|
433
425
|
}
|
|
434
426
|
}
|