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.
Files changed (122) hide show
  1. package/dist/cjs/ai/functions/readFiles.js +1 -1
  2. package/dist/cjs/ai/functions/readFiles.js.map +1 -1
  3. package/dist/cjs/ai/modals-chat/electronHub/chatmodels.d.ts.map +1 -1
  4. package/dist/cjs/ai/modals-chat/electronHub/chatmodels.js +2 -1
  5. package/dist/cjs/ai/modals-chat/electronHub/chatmodels.js.map +1 -1
  6. package/dist/cjs/ai/modals-chat/electronHub/speechModels.d.ts.map +1 -1
  7. package/dist/cjs/ai/modals-chat/electronHub/speechModels.js +1 -1
  8. package/dist/cjs/ai/modals-chat/electronHub/speechModels.js.map +1 -1
  9. package/dist/cjs/canvas/ApexPainter.d.ts.map +1 -1
  10. package/dist/cjs/canvas/ApexPainter.js +27 -28
  11. package/dist/cjs/canvas/ApexPainter.js.map +1 -1
  12. package/dist/cjs/canvas/Themes/Level-Up/levelup.d.ts +11 -0
  13. package/dist/cjs/canvas/Themes/Level-Up/levelup.d.ts.map +1 -0
  14. package/dist/cjs/canvas/Themes/Level-Up/levelup.js +163 -0
  15. package/dist/cjs/canvas/Themes/Level-Up/levelup.js.map +1 -0
  16. package/dist/cjs/canvas/utils/Background/bg.d.ts +17 -10
  17. package/dist/cjs/canvas/utils/Background/bg.d.ts.map +1 -1
  18. package/dist/cjs/canvas/utils/Background/bg.js +102 -27
  19. package/dist/cjs/canvas/utils/Background/bg.js.map +1 -1
  20. package/dist/cjs/canvas/utils/Custom/customLines.d.ts.map +1 -1
  21. package/dist/cjs/canvas/utils/Custom/customLines.js +43 -19
  22. package/dist/cjs/canvas/utils/Custom/customLines.js.map +1 -1
  23. package/dist/cjs/canvas/utils/General/general functions.d.ts +6 -1
  24. package/dist/cjs/canvas/utils/General/general functions.d.ts.map +1 -1
  25. package/dist/cjs/canvas/utils/General/general functions.js +19 -20
  26. package/dist/cjs/canvas/utils/General/general functions.js.map +1 -1
  27. package/dist/cjs/canvas/utils/Image/imageProperties.d.ts +3 -9
  28. package/dist/cjs/canvas/utils/Image/imageProperties.d.ts.map +1 -1
  29. package/dist/cjs/canvas/utils/Image/imageProperties.js +220 -214
  30. package/dist/cjs/canvas/utils/Image/imageProperties.js.map +1 -1
  31. package/dist/cjs/canvas/utils/Texts/textProperties.d.ts +12 -14
  32. package/dist/cjs/canvas/utils/Texts/textProperties.d.ts.map +1 -1
  33. package/dist/cjs/canvas/utils/Texts/textProperties.js +100 -91
  34. package/dist/cjs/canvas/utils/Texts/textProperties.js.map +1 -1
  35. package/dist/cjs/canvas/utils/types.d.ts +89 -109
  36. package/dist/cjs/canvas/utils/types.d.ts.map +1 -1
  37. package/dist/cjs/canvas/utils/types.js.map +1 -1
  38. package/dist/cjs/canvas/utils/utils.d.ts +2 -4
  39. package/dist/cjs/canvas/utils/utils.d.ts.map +1 -1
  40. package/dist/cjs/canvas/utils/utils.js +2 -5
  41. package/dist/cjs/canvas/utils/utils.js.map +1 -1
  42. package/dist/cjs/index.d.ts.map +1 -1
  43. package/dist/cjs/index.js +31 -3
  44. package/dist/cjs/index.js.map +1 -1
  45. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  46. package/dist/esm/ai/functions/readFiles.js +1 -1
  47. package/dist/esm/ai/functions/readFiles.js.map +1 -1
  48. package/dist/esm/ai/modals-chat/electronHub/chatmodels.d.ts.map +1 -1
  49. package/dist/esm/ai/modals-chat/electronHub/chatmodels.js +2 -1
  50. package/dist/esm/ai/modals-chat/electronHub/chatmodels.js.map +1 -1
  51. package/dist/esm/ai/modals-chat/electronHub/speechModels.d.ts.map +1 -1
  52. package/dist/esm/ai/modals-chat/electronHub/speechModels.js +1 -1
  53. package/dist/esm/ai/modals-chat/electronHub/speechModels.js.map +1 -1
  54. package/dist/esm/canvas/ApexPainter.d.ts.map +1 -1
  55. package/dist/esm/canvas/ApexPainter.js +27 -28
  56. package/dist/esm/canvas/ApexPainter.js.map +1 -1
  57. package/dist/esm/canvas/Themes/Level-Up/levelup.d.ts +11 -0
  58. package/dist/esm/canvas/Themes/Level-Up/levelup.d.ts.map +1 -0
  59. package/dist/esm/canvas/Themes/Level-Up/levelup.js +163 -0
  60. package/dist/esm/canvas/Themes/Level-Up/levelup.js.map +1 -0
  61. package/dist/esm/canvas/utils/Background/bg.d.ts +17 -10
  62. package/dist/esm/canvas/utils/Background/bg.d.ts.map +1 -1
  63. package/dist/esm/canvas/utils/Background/bg.js +102 -27
  64. package/dist/esm/canvas/utils/Background/bg.js.map +1 -1
  65. package/dist/esm/canvas/utils/Custom/customLines.d.ts.map +1 -1
  66. package/dist/esm/canvas/utils/Custom/customLines.js +43 -19
  67. package/dist/esm/canvas/utils/Custom/customLines.js.map +1 -1
  68. package/dist/esm/canvas/utils/General/general functions.d.ts +6 -1
  69. package/dist/esm/canvas/utils/General/general functions.d.ts.map +1 -1
  70. package/dist/esm/canvas/utils/General/general functions.js +19 -20
  71. package/dist/esm/canvas/utils/General/general functions.js.map +1 -1
  72. package/dist/esm/canvas/utils/Image/imageProperties.d.ts +3 -9
  73. package/dist/esm/canvas/utils/Image/imageProperties.d.ts.map +1 -1
  74. package/dist/esm/canvas/utils/Image/imageProperties.js +220 -214
  75. package/dist/esm/canvas/utils/Image/imageProperties.js.map +1 -1
  76. package/dist/esm/canvas/utils/Texts/textProperties.d.ts +12 -14
  77. package/dist/esm/canvas/utils/Texts/textProperties.d.ts.map +1 -1
  78. package/dist/esm/canvas/utils/Texts/textProperties.js +100 -91
  79. package/dist/esm/canvas/utils/Texts/textProperties.js.map +1 -1
  80. package/dist/esm/canvas/utils/types.d.ts +89 -109
  81. package/dist/esm/canvas/utils/types.d.ts.map +1 -1
  82. package/dist/esm/canvas/utils/types.js.map +1 -1
  83. package/dist/esm/canvas/utils/utils.d.ts +2 -4
  84. package/dist/esm/canvas/utils/utils.d.ts.map +1 -1
  85. package/dist/esm/canvas/utils/utils.js +2 -5
  86. package/dist/esm/canvas/utils/utils.js.map +1 -1
  87. package/dist/esm/index.d.ts.map +1 -1
  88. package/dist/esm/index.js +31 -3
  89. package/dist/esm/index.js.map +1 -1
  90. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  91. package/lib/ai/functions/readFiles.ts +1 -1
  92. package/lib/ai/modals-chat/electronHub/chatmodels.ts +4 -2
  93. package/lib/ai/modals-chat/electronHub/speechModels.ts +2 -1
  94. package/lib/canvas/ApexPainter.ts +52 -61
  95. package/lib/canvas/Themes/Level-Up/levelup.ts +183 -0
  96. package/lib/canvas/utils/Background/bg.ts +179 -65
  97. package/lib/canvas/utils/Custom/customLines.ts +53 -20
  98. package/lib/canvas/utils/General/general functions.ts +21 -29
  99. package/lib/canvas/utils/Image/imageProperties.ts +399 -318
  100. package/lib/canvas/utils/Texts/textProperties.ts +213 -162
  101. package/lib/canvas/utils/types.ts +74 -107
  102. package/lib/canvas/utils/utils.ts +2 -5
  103. package/lib/index.ts +38 -10
  104. package/package.json +2 -2
  105. package/dist/cjs/canvas/utils/Background/circular.d.ts +0 -3
  106. package/dist/cjs/canvas/utils/Background/circular.d.ts.map +0 -1
  107. package/dist/cjs/canvas/utils/Background/circular.js +0 -13
  108. package/dist/cjs/canvas/utils/Background/circular.js.map +0 -1
  109. package/dist/cjs/canvas/utils/Background/radius.d.ts +0 -18
  110. package/dist/cjs/canvas/utils/Background/radius.d.ts.map +0 -1
  111. package/dist/cjs/canvas/utils/Background/radius.js +0 -104
  112. package/dist/cjs/canvas/utils/Background/radius.js.map +0 -1
  113. package/dist/esm/canvas/utils/Background/circular.d.ts +0 -3
  114. package/dist/esm/canvas/utils/Background/circular.d.ts.map +0 -1
  115. package/dist/esm/canvas/utils/Background/circular.js +0 -13
  116. package/dist/esm/canvas/utils/Background/circular.js.map +0 -1
  117. package/dist/esm/canvas/utils/Background/radius.d.ts +0 -18
  118. package/dist/esm/canvas/utils/Background/radius.d.ts.map +0 -1
  119. package/dist/esm/canvas/utils/Background/radius.js +0 -104
  120. package/dist/esm/canvas/utils/Background/radius.js.map +0 -1
  121. package/lib/canvas/utils/Background/circular.ts +0 -17
  122. 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
- applyAdditionalStroke(ctx, currentStyle);
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
- ctx.strokeStyle = appliedStyle?.color || 'black';
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 borderRadius = appliedStyle.lineRadius;
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
- const offsetX = Math.cos(angle) * borderRadius;
57
- const offsetY = Math.sin(angle) * borderRadius;
58
- ctx.moveTo(start.x + offsetX, start.y + offsetY);
59
- ctx.lineTo(endCoordinates.x - offsetX, endCoordinates.y - offsetY);
60
- } else if (appliedStyle?.lineRadius === 'circular') {
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
- const angle = Math.atan2(dy, dx);
65
- const halfWidth = appliedStyle.width ? appliedStyle.width / 2 : 1;
66
- ctx.moveTo(start.x + Math.cos(angle - Math.PI / 2) * halfWidth, start.y + Math.sin(angle - Math.PI / 2) * halfWidth);
67
- ctx.arc(start.x, start.y, length / 2, angle - Math.PI / 2, angle + Math.PI / 2);
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
- applyAdditionalStroke(ctx, appliedStyle);
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 applyAdditionalStroke(ctx: any, style: any) {
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 = color || 'black';
91
- ctx.lineWidth = width || 1;
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
- let absoluteImagePath: string;
45
- if (resizeOptions.imagePath.startsWith("http")) {
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 = await image
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.join(process.cwd(), imagePath);
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') as any;
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 red = data[i];
412
- const green = data[i + 1];
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
- .filter(([color, frequency]: [string, number]) => (frequency / totalPixels) * 100 >= 2)
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('Error:', error);
423
+ console.error("❌ Error detecting colors:", error);
432
424
  return [];
433
425
  }
434
426
  }