apexify.js 5.1.1 → 5.2.0

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 (236) hide show
  1. package/CHANGELOG.md +240 -0
  2. package/README.md +248 -1105
  3. package/dist/cjs/Canvas/ApexPainter.d.ts +182 -204
  4. package/dist/cjs/Canvas/ApexPainter.d.ts.map +1 -1
  5. package/dist/cjs/Canvas/ApexPainter.js +482 -1286
  6. package/dist/cjs/Canvas/ApexPainter.js.map +1 -1
  7. package/dist/cjs/Canvas/extended/CanvasCreator.d.ts +33 -0
  8. package/dist/cjs/Canvas/extended/CanvasCreator.d.ts.map +1 -0
  9. package/dist/cjs/Canvas/extended/CanvasCreator.js +223 -0
  10. package/dist/cjs/Canvas/extended/CanvasCreator.js.map +1 -0
  11. package/dist/cjs/Canvas/extended/ChartCreator.d.ts +26 -0
  12. package/dist/cjs/Canvas/extended/ChartCreator.d.ts.map +1 -0
  13. package/dist/cjs/Canvas/extended/ChartCreator.js +50 -0
  14. package/dist/cjs/Canvas/extended/ChartCreator.js.map +1 -0
  15. package/dist/cjs/Canvas/extended/GIFCreator.d.ts +43 -0
  16. package/dist/cjs/Canvas/extended/GIFCreator.d.ts.map +1 -0
  17. package/dist/cjs/Canvas/extended/GIFCreator.js +157 -0
  18. package/dist/cjs/Canvas/extended/GIFCreator.js.map +1 -0
  19. package/dist/cjs/Canvas/extended/ImageCreator.d.ts +83 -0
  20. package/dist/cjs/Canvas/extended/ImageCreator.d.ts.map +1 -0
  21. package/dist/cjs/Canvas/extended/ImageCreator.js +479 -0
  22. package/dist/cjs/Canvas/extended/ImageCreator.js.map +1 -0
  23. package/dist/cjs/Canvas/extended/TextCreator.d.ts +35 -0
  24. package/dist/cjs/Canvas/extended/TextCreator.d.ts.map +1 -0
  25. package/dist/cjs/Canvas/extended/TextCreator.js +98 -0
  26. package/dist/cjs/Canvas/extended/TextCreator.js.map +1 -0
  27. package/dist/cjs/Canvas/extended/VideoCreator.d.ts +370 -0
  28. package/dist/cjs/Canvas/extended/VideoCreator.d.ts.map +1 -0
  29. package/dist/cjs/Canvas/extended/VideoCreator.js +478 -0
  30. package/dist/cjs/Canvas/extended/VideoCreator.js.map +1 -0
  31. package/dist/cjs/Canvas/utils/Background/bg.d.ts +1 -1
  32. package/dist/cjs/Canvas/utils/Background/bg.d.ts.map +1 -1
  33. package/dist/cjs/Canvas/utils/Background/bg.js +43 -7
  34. package/dist/cjs/Canvas/utils/Background/bg.js.map +1 -1
  35. package/dist/cjs/Canvas/utils/Charts/barchart.d.ts +230 -0
  36. package/dist/cjs/Canvas/utils/Charts/barchart.d.ts.map +1 -0
  37. package/dist/cjs/Canvas/utils/Charts/barchart.js +1891 -0
  38. package/dist/cjs/Canvas/utils/Charts/barchart.js.map +1 -0
  39. package/dist/cjs/Canvas/utils/Charts/comparisonchart.d.ts +103 -0
  40. package/dist/cjs/Canvas/utils/Charts/comparisonchart.d.ts.map +1 -0
  41. package/dist/cjs/Canvas/utils/Charts/comparisonchart.js +368 -0
  42. package/dist/cjs/Canvas/utils/Charts/comparisonchart.js.map +1 -0
  43. package/dist/cjs/Canvas/utils/Charts/horizontalbarchart.d.ts +178 -0
  44. package/dist/cjs/Canvas/utils/Charts/horizontalbarchart.d.ts.map +1 -0
  45. package/dist/cjs/Canvas/utils/Charts/horizontalbarchart.js +1389 -0
  46. package/dist/cjs/Canvas/utils/Charts/horizontalbarchart.js.map +1 -0
  47. package/dist/cjs/Canvas/utils/Charts/index.d.ts +45 -0
  48. package/dist/cjs/Canvas/utils/Charts/index.d.ts.map +1 -0
  49. package/dist/cjs/Canvas/utils/Charts/index.js +17 -0
  50. package/dist/cjs/Canvas/utils/Charts/index.js.map +1 -0
  51. package/dist/cjs/Canvas/utils/Charts/linechart.d.ts +216 -0
  52. package/dist/cjs/Canvas/utils/Charts/linechart.d.ts.map +1 -0
  53. package/dist/cjs/Canvas/utils/Charts/linechart.js +1761 -0
  54. package/dist/cjs/Canvas/utils/Charts/linechart.js.map +1 -0
  55. package/dist/cjs/Canvas/utils/Charts/piechart.d.ts +167 -0
  56. package/dist/cjs/Canvas/utils/Charts/piechart.d.ts.map +1 -0
  57. package/dist/cjs/Canvas/utils/Charts/piechart.js +794 -0
  58. package/dist/cjs/Canvas/utils/Charts/piechart.js.map +1 -0
  59. package/dist/cjs/Canvas/utils/General/batchOperations.d.ts.map +1 -1
  60. package/dist/cjs/Canvas/utils/General/batchOperations.js +3 -4
  61. package/dist/cjs/Canvas/utils/General/batchOperations.js.map +1 -1
  62. package/dist/cjs/Canvas/utils/General/general functions.d.ts.map +1 -1
  63. package/dist/cjs/Canvas/utils/General/general functions.js +62 -33
  64. package/dist/cjs/Canvas/utils/General/general functions.js.map +1 -1
  65. package/dist/cjs/Canvas/utils/General/imageStitching.d.ts.map +1 -1
  66. package/dist/cjs/Canvas/utils/General/imageStitching.js +3 -6
  67. package/dist/cjs/Canvas/utils/General/imageStitching.js.map +1 -1
  68. package/dist/cjs/Canvas/utils/Image/imageMasking.d.ts.map +1 -1
  69. package/dist/cjs/Canvas/utils/Image/imageMasking.js +5 -12
  70. package/dist/cjs/Canvas/utils/Image/imageMasking.js.map +1 -1
  71. package/dist/cjs/Canvas/utils/Image/imageProperties.d.ts +4 -4
  72. package/dist/cjs/Canvas/utils/Image/imageProperties.d.ts.map +1 -1
  73. package/dist/cjs/Canvas/utils/Image/imageProperties.js +44 -9
  74. package/dist/cjs/Canvas/utils/Image/imageProperties.js.map +1 -1
  75. package/dist/cjs/Canvas/utils/Texts/enhancedTextRenderer.d.ts +5 -0
  76. package/dist/cjs/Canvas/utils/Texts/enhancedTextRenderer.d.ts.map +1 -1
  77. package/dist/cjs/Canvas/utils/Texts/enhancedTextRenderer.js +48 -5
  78. package/dist/cjs/Canvas/utils/Texts/enhancedTextRenderer.js.map +1 -1
  79. package/dist/cjs/Canvas/utils/Texts/textProperties.d.ts +1 -1
  80. package/dist/cjs/Canvas/utils/Texts/textProperties.d.ts.map +1 -1
  81. package/dist/cjs/Canvas/utils/Texts/textProperties.js +48 -5
  82. package/dist/cjs/Canvas/utils/Texts/textProperties.js.map +1 -1
  83. package/dist/cjs/Canvas/utils/Video/videoHelpers.d.ts +489 -0
  84. package/dist/cjs/Canvas/utils/Video/videoHelpers.d.ts.map +1 -0
  85. package/dist/cjs/Canvas/utils/Video/videoHelpers.js +1835 -0
  86. package/dist/cjs/Canvas/utils/Video/videoHelpers.js.map +1 -0
  87. package/dist/cjs/Canvas/utils/errorUtils.d.ts +15 -0
  88. package/dist/cjs/Canvas/utils/errorUtils.d.ts.map +1 -0
  89. package/dist/cjs/Canvas/utils/errorUtils.js +26 -0
  90. package/dist/cjs/Canvas/utils/errorUtils.js.map +1 -0
  91. package/dist/cjs/Canvas/utils/types.d.ts +17 -178
  92. package/dist/cjs/Canvas/utils/types.d.ts.map +1 -1
  93. package/dist/cjs/Canvas/utils/types.js.map +1 -1
  94. package/dist/cjs/Canvas/utils/utils.d.ts +4 -3
  95. package/dist/cjs/Canvas/utils/utils.d.ts.map +1 -1
  96. package/dist/cjs/Canvas/utils/utils.js +40 -6
  97. package/dist/cjs/Canvas/utils/utils.js.map +1 -1
  98. package/dist/cjs/index.d.ts +1 -8
  99. package/dist/cjs/index.d.ts.map +1 -1
  100. package/dist/cjs/index.js +14 -45
  101. package/dist/cjs/index.js.map +1 -1
  102. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  103. package/dist/esm/Canvas/ApexPainter.d.ts +182 -204
  104. package/dist/esm/Canvas/ApexPainter.d.ts.map +1 -1
  105. package/dist/esm/Canvas/ApexPainter.js +482 -1286
  106. package/dist/esm/Canvas/ApexPainter.js.map +1 -1
  107. package/dist/esm/Canvas/extended/CanvasCreator.d.ts +33 -0
  108. package/dist/esm/Canvas/extended/CanvasCreator.d.ts.map +1 -0
  109. package/dist/esm/Canvas/extended/CanvasCreator.js +223 -0
  110. package/dist/esm/Canvas/extended/CanvasCreator.js.map +1 -0
  111. package/dist/esm/Canvas/extended/ChartCreator.d.ts +26 -0
  112. package/dist/esm/Canvas/extended/ChartCreator.d.ts.map +1 -0
  113. package/dist/esm/Canvas/extended/ChartCreator.js +50 -0
  114. package/dist/esm/Canvas/extended/ChartCreator.js.map +1 -0
  115. package/dist/esm/Canvas/extended/GIFCreator.d.ts +43 -0
  116. package/dist/esm/Canvas/extended/GIFCreator.d.ts.map +1 -0
  117. package/dist/esm/Canvas/extended/GIFCreator.js +157 -0
  118. package/dist/esm/Canvas/extended/GIFCreator.js.map +1 -0
  119. package/dist/esm/Canvas/extended/ImageCreator.d.ts +83 -0
  120. package/dist/esm/Canvas/extended/ImageCreator.d.ts.map +1 -0
  121. package/dist/esm/Canvas/extended/ImageCreator.js +479 -0
  122. package/dist/esm/Canvas/extended/ImageCreator.js.map +1 -0
  123. package/dist/esm/Canvas/extended/TextCreator.d.ts +35 -0
  124. package/dist/esm/Canvas/extended/TextCreator.d.ts.map +1 -0
  125. package/dist/esm/Canvas/extended/TextCreator.js +98 -0
  126. package/dist/esm/Canvas/extended/TextCreator.js.map +1 -0
  127. package/dist/esm/Canvas/extended/VideoCreator.d.ts +370 -0
  128. package/dist/esm/Canvas/extended/VideoCreator.d.ts.map +1 -0
  129. package/dist/esm/Canvas/extended/VideoCreator.js +478 -0
  130. package/dist/esm/Canvas/extended/VideoCreator.js.map +1 -0
  131. package/dist/esm/Canvas/utils/Background/bg.d.ts +1 -1
  132. package/dist/esm/Canvas/utils/Background/bg.d.ts.map +1 -1
  133. package/dist/esm/Canvas/utils/Background/bg.js +43 -7
  134. package/dist/esm/Canvas/utils/Background/bg.js.map +1 -1
  135. package/dist/esm/Canvas/utils/Charts/barchart.d.ts +230 -0
  136. package/dist/esm/Canvas/utils/Charts/barchart.d.ts.map +1 -0
  137. package/dist/esm/Canvas/utils/Charts/barchart.js +1891 -0
  138. package/dist/esm/Canvas/utils/Charts/barchart.js.map +1 -0
  139. package/dist/esm/Canvas/utils/Charts/comparisonchart.d.ts +103 -0
  140. package/dist/esm/Canvas/utils/Charts/comparisonchart.d.ts.map +1 -0
  141. package/dist/esm/Canvas/utils/Charts/comparisonchart.js +368 -0
  142. package/dist/esm/Canvas/utils/Charts/comparisonchart.js.map +1 -0
  143. package/dist/esm/Canvas/utils/Charts/horizontalbarchart.d.ts +178 -0
  144. package/dist/esm/Canvas/utils/Charts/horizontalbarchart.d.ts.map +1 -0
  145. package/dist/esm/Canvas/utils/Charts/horizontalbarchart.js +1389 -0
  146. package/dist/esm/Canvas/utils/Charts/horizontalbarchart.js.map +1 -0
  147. package/dist/esm/Canvas/utils/Charts/index.d.ts +45 -0
  148. package/dist/esm/Canvas/utils/Charts/index.d.ts.map +1 -0
  149. package/dist/esm/Canvas/utils/Charts/index.js +17 -0
  150. package/dist/esm/Canvas/utils/Charts/index.js.map +1 -0
  151. package/dist/esm/Canvas/utils/Charts/linechart.d.ts +216 -0
  152. package/dist/esm/Canvas/utils/Charts/linechart.d.ts.map +1 -0
  153. package/dist/esm/Canvas/utils/Charts/linechart.js +1761 -0
  154. package/dist/esm/Canvas/utils/Charts/linechart.js.map +1 -0
  155. package/dist/esm/Canvas/utils/Charts/piechart.d.ts +167 -0
  156. package/dist/esm/Canvas/utils/Charts/piechart.d.ts.map +1 -0
  157. package/dist/esm/Canvas/utils/Charts/piechart.js +794 -0
  158. package/dist/esm/Canvas/utils/Charts/piechart.js.map +1 -0
  159. package/dist/esm/Canvas/utils/General/batchOperations.d.ts.map +1 -1
  160. package/dist/esm/Canvas/utils/General/batchOperations.js +3 -4
  161. package/dist/esm/Canvas/utils/General/batchOperations.js.map +1 -1
  162. package/dist/esm/Canvas/utils/General/general functions.d.ts.map +1 -1
  163. package/dist/esm/Canvas/utils/General/general functions.js +62 -33
  164. package/dist/esm/Canvas/utils/General/general functions.js.map +1 -1
  165. package/dist/esm/Canvas/utils/General/imageStitching.d.ts.map +1 -1
  166. package/dist/esm/Canvas/utils/General/imageStitching.js +3 -6
  167. package/dist/esm/Canvas/utils/General/imageStitching.js.map +1 -1
  168. package/dist/esm/Canvas/utils/Image/imageMasking.d.ts.map +1 -1
  169. package/dist/esm/Canvas/utils/Image/imageMasking.js +5 -12
  170. package/dist/esm/Canvas/utils/Image/imageMasking.js.map +1 -1
  171. package/dist/esm/Canvas/utils/Image/imageProperties.d.ts +4 -4
  172. package/dist/esm/Canvas/utils/Image/imageProperties.d.ts.map +1 -1
  173. package/dist/esm/Canvas/utils/Image/imageProperties.js +44 -9
  174. package/dist/esm/Canvas/utils/Image/imageProperties.js.map +1 -1
  175. package/dist/esm/Canvas/utils/Texts/enhancedTextRenderer.d.ts +5 -0
  176. package/dist/esm/Canvas/utils/Texts/enhancedTextRenderer.d.ts.map +1 -1
  177. package/dist/esm/Canvas/utils/Texts/enhancedTextRenderer.js +48 -5
  178. package/dist/esm/Canvas/utils/Texts/enhancedTextRenderer.js.map +1 -1
  179. package/dist/esm/Canvas/utils/Texts/textProperties.d.ts +1 -1
  180. package/dist/esm/Canvas/utils/Texts/textProperties.d.ts.map +1 -1
  181. package/dist/esm/Canvas/utils/Texts/textProperties.js +48 -5
  182. package/dist/esm/Canvas/utils/Texts/textProperties.js.map +1 -1
  183. package/dist/esm/Canvas/utils/Video/videoHelpers.d.ts +489 -0
  184. package/dist/esm/Canvas/utils/Video/videoHelpers.d.ts.map +1 -0
  185. package/dist/esm/Canvas/utils/Video/videoHelpers.js +1835 -0
  186. package/dist/esm/Canvas/utils/Video/videoHelpers.js.map +1 -0
  187. package/dist/esm/Canvas/utils/errorUtils.d.ts +15 -0
  188. package/dist/esm/Canvas/utils/errorUtils.d.ts.map +1 -0
  189. package/dist/esm/Canvas/utils/errorUtils.js +26 -0
  190. package/dist/esm/Canvas/utils/errorUtils.js.map +1 -0
  191. package/dist/esm/Canvas/utils/types.d.ts +17 -178
  192. package/dist/esm/Canvas/utils/types.d.ts.map +1 -1
  193. package/dist/esm/Canvas/utils/types.js.map +1 -1
  194. package/dist/esm/Canvas/utils/utils.d.ts +4 -3
  195. package/dist/esm/Canvas/utils/utils.d.ts.map +1 -1
  196. package/dist/esm/Canvas/utils/utils.js +40 -6
  197. package/dist/esm/Canvas/utils/utils.js.map +1 -1
  198. package/dist/esm/index.d.ts +1 -8
  199. package/dist/esm/index.d.ts.map +1 -1
  200. package/dist/esm/index.js +14 -45
  201. package/dist/esm/index.js.map +1 -1
  202. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  203. package/package.json +234 -198
  204. package/dist/cjs/Canvas/utils/Charts/charts.d.ts +0 -13
  205. package/dist/cjs/Canvas/utils/Charts/charts.d.ts.map +0 -1
  206. package/dist/cjs/Canvas/utils/Charts/charts.js +0 -466
  207. package/dist/cjs/Canvas/utils/Charts/charts.js.map +0 -1
  208. package/dist/esm/Canvas/utils/Charts/charts.d.ts +0 -13
  209. package/dist/esm/Canvas/utils/Charts/charts.d.ts.map +0 -1
  210. package/dist/esm/Canvas/utils/Charts/charts.js +0 -466
  211. package/dist/esm/Canvas/utils/Charts/charts.js.map +0 -1
  212. package/lib/Canvas/ApexPainter.ts +0 -5414
  213. package/lib/Canvas/utils/Background/bg.ts +0 -285
  214. package/lib/Canvas/utils/Charts/charts.ts +0 -548
  215. package/lib/Canvas/utils/Custom/advancedLines.ts +0 -387
  216. package/lib/Canvas/utils/Custom/customLines.ts +0 -206
  217. package/lib/Canvas/utils/General/batchOperations.ts +0 -103
  218. package/lib/Canvas/utils/General/conversion.ts +0 -34
  219. package/lib/Canvas/utils/General/general functions.ts +0 -726
  220. package/lib/Canvas/utils/General/imageCompression.ts +0 -316
  221. package/lib/Canvas/utils/General/imageStitching.ts +0 -252
  222. package/lib/Canvas/utils/Image/imageEffects.ts +0 -175
  223. package/lib/Canvas/utils/Image/imageFilters.ts +0 -356
  224. package/lib/Canvas/utils/Image/imageMasking.ts +0 -335
  225. package/lib/Canvas/utils/Image/imageProperties.ts +0 -587
  226. package/lib/Canvas/utils/Image/professionalImageFilters.ts +0 -391
  227. package/lib/Canvas/utils/Image/simpleProfessionalFilters.ts +0 -229
  228. package/lib/Canvas/utils/Patterns/enhancedPatternRenderer.ts +0 -455
  229. package/lib/Canvas/utils/Shapes/shapes.ts +0 -528
  230. package/lib/Canvas/utils/Texts/enhancedTextRenderer.ts +0 -716
  231. package/lib/Canvas/utils/Texts/textPathRenderer.ts +0 -320
  232. package/lib/Canvas/utils/Texts/textProperties.ts +0 -231
  233. package/lib/Canvas/utils/types.ts +0 -983
  234. package/lib/Canvas/utils/utils.ts +0 -135
  235. package/lib/index.ts +0 -81
  236. package/lib/utils.ts +0 -5
@@ -1,387 +0,0 @@
1
- import { SKRSContext2D, Image, loadImage } from '@napi-rs/canvas';
2
- import path from 'path';
3
- import fs from 'fs';
4
-
5
- /**
6
- * Draws an arrow at the end of a line
7
- * @param ctx - Canvas 2D context
8
- * @param x - Arrow tip X
9
- * @param y - Arrow tip Y
10
- * @param angle - Arrow angle in radians
11
- * @param size - Arrow size
12
- * @param style - Arrow style
13
- * @param color - Arrow color
14
- */
15
- export function drawArrow(
16
- ctx: SKRSContext2D,
17
- x: number,
18
- y: number,
19
- angle: number,
20
- size: number,
21
- style: 'filled' | 'outline',
22
- color: string
23
- ): void {
24
- ctx.save();
25
- ctx.translate(x, y);
26
- ctx.rotate(angle);
27
-
28
- const arrowHeadLength = size;
29
- const arrowHeadWidth = size * 0.6;
30
-
31
- ctx.beginPath();
32
- ctx.moveTo(0, 0);
33
- ctx.lineTo(-arrowHeadLength, -arrowHeadWidth);
34
- ctx.lineTo(-arrowHeadLength * 0.7, 0);
35
- ctx.lineTo(-arrowHeadLength, arrowHeadWidth);
36
- ctx.closePath();
37
-
38
- if (style === 'filled') {
39
- ctx.fillStyle = color;
40
- ctx.fill();
41
- } else {
42
- ctx.strokeStyle = color;
43
- ctx.lineWidth = 2;
44
- ctx.stroke();
45
- }
46
-
47
- ctx.restore();
48
- }
49
-
50
- /**
51
- * Draws a marker on a path
52
- * @param ctx - Canvas 2D context
53
- * @param x - Marker X position
54
- * @param y - Marker Y position
55
- * @param shape - Marker shape
56
- * @param size - Marker size
57
- * @param color - Marker color
58
- */
59
- export function drawMarker(
60
- ctx: SKRSContext2D,
61
- x: number,
62
- y: number,
63
- shape: 'circle' | 'square' | 'diamond' | 'arrow',
64
- size: number,
65
- color: string
66
- ): void {
67
- ctx.save();
68
- ctx.fillStyle = color;
69
- ctx.translate(x, y);
70
-
71
- switch (shape) {
72
- case 'circle':
73
- ctx.beginPath();
74
- ctx.arc(0, 0, size / 2, 0, Math.PI * 2);
75
- ctx.fill();
76
- break;
77
-
78
- case 'square':
79
- ctx.fillRect(-size / 2, -size / 2, size, size);
80
- break;
81
-
82
- case 'diamond':
83
- ctx.beginPath();
84
- ctx.moveTo(0, -size / 2);
85
- ctx.lineTo(size / 2, 0);
86
- ctx.lineTo(0, size / 2);
87
- ctx.lineTo(-size / 2, 0);
88
- ctx.closePath();
89
- ctx.fill();
90
- break;
91
-
92
- case 'arrow':
93
- ctx.beginPath();
94
- ctx.moveTo(0, -size / 2);
95
- ctx.lineTo(size / 2, size / 2);
96
- ctx.lineTo(-size / 2, size / 2);
97
- ctx.closePath();
98
- ctx.fill();
99
- break;
100
- }
101
-
102
- ctx.restore();
103
- }
104
-
105
- /**
106
- * Creates a smooth path from points using Cardinal Spline (graph-like smoothness)
107
- * @param ctx - Canvas 2D context
108
- * @param points - Array of points
109
- * @param tension - Smoothness (0-1, default 0.5, lower = smoother)
110
- * @param closed - Whether path is closed
111
- */
112
- export function createSmoothPath(
113
- ctx: SKRSContext2D,
114
- points: Array<{ x: number; y: number }>,
115
- tension: number = 0.5,
116
- closed: boolean = false
117
- ): void {
118
- if (points.length < 2) return;
119
-
120
- // Enable anti-aliasing for smoother rendering
121
- ctx.imageSmoothingEnabled = true;
122
- ctx.imageSmoothingQuality = 'high';
123
-
124
- ctx.beginPath();
125
- ctx.moveTo(points[0].x, points[0].y);
126
-
127
- if (points.length === 2) {
128
- ctx.lineTo(points[1].x, points[1].y);
129
- return;
130
- }
131
-
132
- // Cardinal spline - produces graph-like smooth curves
133
- // Ultra-high resolution for maximum smoothness (like professional graphing libraries)
134
- const segmentsPerCurve = 50; // Increased to 50 for ultra-smooth curves
135
-
136
- for (let i = 0; i < points.length - 1; i++) {
137
- const p0 = i > 0 ? points[i - 1] : (closed ? points[points.length - 1] : points[i]);
138
- const p1 = points[i];
139
- const p2 = points[i + 1];
140
- const p3 = i < points.length - 2 ? points[i + 2] : (closed ? points[0] : p2);
141
-
142
- // Cardinal spline control points (optimized for maximum smoothness)
143
- const t = (1 - tension) * 0.5; // Convert tension to cardinal spline parameter
144
-
145
- const cp1x = p1.x + t * (p2.x - p0.x);
146
- const cp1y = p1.y + t * (p2.y - p0.y);
147
- const cp2x = p2.x - t * (p3.x - p1.x);
148
- const cp2y = p2.y - t * (p3.y - p1.y);
149
-
150
- // Draw ultra-smooth curve with many segments for graph-like quality
151
- for (let s = 0; s <= segmentsPerCurve; s++) {
152
- const t = s / segmentsPerCurve;
153
- const point = cubicBezier(p1, { x: cp1x, y: cp1y }, { x: cp2x, y: cp2y }, p2, t);
154
-
155
- if (s === 0 && i === 0) {
156
- ctx.moveTo(point.x, point.y);
157
- } else {
158
- ctx.lineTo(point.x, point.y);
159
- }
160
- }
161
- }
162
-
163
- if (closed) {
164
- ctx.closePath();
165
- }
166
- }
167
-
168
- /**
169
- * Cubic Bezier interpolation helper
170
- */
171
- function cubicBezier(
172
- p0: { x: number; y: number },
173
- p1: { x: number; y: number },
174
- p2: { x: number; y: number },
175
- p3: { x: number; y: number },
176
- t: number
177
- ): { x: number; y: number } {
178
- const mt = 1 - t;
179
- const mt2 = mt * mt;
180
- const mt3 = mt2 * mt;
181
- const t2 = t * t;
182
- const t3 = t2 * t;
183
-
184
- return {
185
- x: mt3 * p0.x + 3 * mt2 * t * p1.x + 3 * mt * t2 * p2.x + t3 * p3.x,
186
- y: mt3 * p0.y + 3 * mt2 * t * p1.y + 3 * mt * t2 * p2.y + t3 * p3.y
187
- };
188
- }
189
-
190
- /**
191
- * Creates a Catmull-Rom spline path (ultra-smooth, passes through all points - best for graphs)
192
- * @param ctx - Canvas 2D context
193
- * @param points - Array of points
194
- * @param tension - Tension (0-1, default 0.5, lower = tighter curves)
195
- * @param closed - Whether path is closed
196
- */
197
- export function createCatmullRomPath(
198
- ctx: SKRSContext2D,
199
- points: Array<{ x: number; y: number }>,
200
- tension: number = 0.5,
201
- closed: boolean = false
202
- ): void {
203
- if (points.length < 2) return;
204
-
205
- // Enable anti-aliasing for smoother rendering
206
- ctx.imageSmoothingEnabled = true;
207
- ctx.imageSmoothingQuality = 'high';
208
-
209
- ctx.beginPath();
210
- ctx.moveTo(points[0].x, points[0].y);
211
-
212
- if (points.length === 2) {
213
- ctx.lineTo(points[1].x, points[1].y);
214
- return;
215
- }
216
-
217
- const segments = closed ? points.length : points.length - 1;
218
- const segmentsPerCurve = 60; // Ultra-high resolution for maximum smoothness (graph quality)
219
-
220
- for (let i = 0; i < segments; i++) {
221
- const p0 = closed && i === 0 ? points[points.length - 1] : (i > 0 ? points[i - 1] : points[i]);
222
- const p1 = points[i];
223
- const p2 = points[(i + 1) % points.length];
224
- const p3 = closed && i === segments - 1 ? points[0] : (i < points.length - 2 ? points[i + 2] : p2);
225
-
226
- // Draw ultra-smooth curve with maximum resolution for graph-like quality
227
- for (let s = 0; s <= segmentsPerCurve; s++) {
228
- const t = s / segmentsPerCurve;
229
- const point = catmullRom(p0, p1, p2, p3, t, tension);
230
-
231
- if (s === 0 && i === 0) {
232
- ctx.moveTo(point.x, point.y);
233
- } else {
234
- ctx.lineTo(point.x, point.y);
235
- }
236
- }
237
- }
238
-
239
- if (closed) {
240
- ctx.closePath();
241
- }
242
- }
243
-
244
- /**
245
- * Catmull-Rom spline interpolation (corrected formula)
246
- * This creates curves that pass through all control points
247
- */
248
- function catmullRom(
249
- p0: { x: number; y: number },
250
- p1: { x: number; y: number },
251
- p2: { x: number; y: number },
252
- p3: { x: number; y: number },
253
- t: number,
254
- tension: number
255
- ): { x: number; y: number } {
256
- const t2 = t * t;
257
- const t3 = t2 * t;
258
-
259
- // Proper Catmull-Rom spline formula with tension
260
- // Tension typically ranges from 0 (tight) to 1 (loose)
261
- const s = (1 - tension) * 0.5;
262
-
263
- const x = (2 * p1.x) +
264
- s * ((-p0.x + p2.x) * t +
265
- (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 +
266
- (-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t3);
267
-
268
- const y = (2 * p1.y) +
269
- s * ((-p0.y + p2.y) * t +
270
- (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 +
271
- (-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t3);
272
-
273
- return { x: x * 0.5, y: y * 0.5 };
274
- }
275
-
276
- /**
277
- * Applies line pattern
278
- * @param ctx - Canvas 2D context
279
- * @param pattern - Pattern configuration
280
- */
281
- export function applyLinePattern(
282
- ctx: SKRSContext2D,
283
- pattern: {
284
- type: 'dots' | 'dashes' | 'custom';
285
- segments?: number[];
286
- offset?: number;
287
- }
288
- ): void {
289
- switch (pattern.type) {
290
- case 'dots':
291
- ctx.setLineDash([2, 4]);
292
- break;
293
-
294
- case 'dashes':
295
- ctx.setLineDash([10, 5]);
296
- break;
297
-
298
- case 'custom':
299
- if (pattern.segments && pattern.segments.length > 0) {
300
- ctx.setLineDash(pattern.segments);
301
- }
302
- break;
303
- }
304
-
305
- if (pattern.offset !== undefined) {
306
- ctx.lineDashOffset = pattern.offset;
307
- }
308
- }
309
-
310
- /**
311
- * Applies texture to line
312
- * @param ctx - Canvas 2D context
313
- * @param textureSource - Texture image source
314
- * @param lineWidth - Line width
315
- * @param lineLength - Approximate line length
316
- */
317
- export async function applyLineTexture(
318
- ctx: SKRSContext2D,
319
- textureSource: string | Buffer,
320
- lineWidth: number,
321
- lineLength: number
322
- ): Promise<void> {
323
- try {
324
- let textureImage: Image;
325
- if (Buffer.isBuffer(textureSource)) {
326
- textureImage = await loadImage(textureSource);
327
- } else if (textureSource.startsWith('http')) {
328
- textureImage = await loadImage(textureSource);
329
- } else {
330
- const texturePath = path.join(process.cwd(), textureSource);
331
- textureImage = await loadImage(fs.readFileSync(texturePath));
332
- }
333
-
334
- // Create pattern from texture
335
- const pattern = ctx.createPattern(textureImage, 'repeat');
336
- if (pattern) {
337
- ctx.strokeStyle = pattern;
338
- }
339
- } catch (error) {
340
- console.error('Error applying line texture:', error);
341
- // Fallback to current stroke style
342
- }
343
- }
344
-
345
- /**
346
- * Gets points along a path for marker placement
347
- * @param points - Path points
348
- * @param position - Position along path (0-1)
349
- */
350
- export function getPointOnLinePath(
351
- points: Array<{ x: number; y: number }>,
352
- position: number
353
- ): { x: number; y: number } {
354
- if (points.length < 2) return points[0] || { x: 0, y: 0 };
355
-
356
- // Calculate total path length
357
- let totalLength = 0;
358
- const segmentLengths: number[] = [];
359
-
360
- for (let i = 0; i < points.length - 1; i++) {
361
- const dx = points[i + 1].x - points[i].x;
362
- const dy = points[i + 1].y - points[i].y;
363
- const length = Math.sqrt(dx * dx + dy * dy);
364
- segmentLengths.push(length);
365
- totalLength += length;
366
- }
367
-
368
- // Find target position
369
- const targetLength = totalLength * Math.max(0, Math.min(1, position));
370
- let currentLength = 0;
371
-
372
- for (let i = 0; i < segmentLengths.length; i++) {
373
- if (currentLength + segmentLengths[i] >= targetLength) {
374
- const segmentT = (targetLength - currentLength) / segmentLengths[i];
375
- const dx = points[i + 1].x - points[i].x;
376
- const dy = points[i + 1].y - points[i].y;
377
- return {
378
- x: points[i].x + dx * segmentT,
379
- y: points[i].y + dy * segmentT
380
- };
381
- }
382
- currentLength += segmentLengths[i];
383
- }
384
-
385
- return points[points.length - 1];
386
- }
387
-
@@ -1,206 +0,0 @@
1
- import { SKRSContext2D } from '@napi-rs/canvas';
2
- import { createGradientFill } from "../Image/imageProperties";
3
- import { CustomOptions } from "../types";
4
- import { drawArrow, drawMarker, createSmoothPath, createCatmullRomPath, applyLinePattern, applyLineTexture, getPointOnLinePath } from "./advancedLines";
5
-
6
-
7
- export async function customLines(ctx: SKRSContext2D, options: CustomOptions[]): Promise<void> {
8
- // Enable high-quality anti-aliasing for ultra-smooth lines (graph quality)
9
- ctx.imageSmoothingEnabled = true;
10
- ctx.imageSmoothingQuality = 'high';
11
-
12
- let previousEndCoordinates: { x: number; y: number } | null = null;
13
- let currentStyle: CustomOptions['lineStyle'] | null = null;
14
- let inSingleLineSequence = false;
15
-
16
- for (let i = 0; i < options.length; i++) {
17
- const customOption = options[i];
18
- const { startCoordinates, endCoordinates, lineStyle, path, arrow, markers } = customOption;
19
- const isSingleLine = lineStyle?.singleLine;
20
-
21
- // Collect all points for path rendering
22
- const allPoints: Array<{ x: number; y: number }> = [];
23
- if (i === 0 || !isSingleLine) {
24
- allPoints.push(startCoordinates);
25
- }
26
- allPoints.push(endCoordinates);
27
-
28
- if (isSingleLine && !inSingleLineSequence) {
29
- currentStyle = lineStyle;
30
- inSingleLineSequence = true;
31
- ctx.beginPath();
32
- ctx.moveTo(startCoordinates.x, startCoordinates.y);
33
- }
34
-
35
- if (!isSingleLine && inSingleLineSequence) {
36
- ctx.stroke();
37
- if (currentStyle) {
38
- applyStroke(ctx, currentStyle, startCoordinates, endCoordinates);
39
- }
40
- inSingleLineSequence = false;
41
- currentStyle = null;
42
- }
43
-
44
- const start = inSingleLineSequence && previousEndCoordinates
45
- ? previousEndCoordinates
46
- : startCoordinates;
47
-
48
- if (!inSingleLineSequence) {
49
- ctx.beginPath();
50
- ctx.moveTo(start.x, start.y);
51
- }
52
-
53
- // Apply path smoothing if specified
54
- if (path && allPoints.length >= 2) {
55
- ctx.beginPath();
56
- if (path.type === 'smooth') {
57
- createSmoothPath(ctx, allPoints, path.tension ?? 0.5, path.closed ?? false);
58
- } else if (path.type === 'catmull-rom') {
59
- createCatmullRomPath(ctx, allPoints, path.tension ?? 0.5, path.closed ?? false);
60
- } else if (path.type === 'bezier' && allPoints.length >= 4) {
61
- ctx.moveTo(allPoints[0].x, allPoints[0].y);
62
- for (let j = 1; j < allPoints.length - 2; j += 3) {
63
- if (j + 2 < allPoints.length) {
64
- ctx.bezierCurveTo(
65
- allPoints[j].x, allPoints[j].y,
66
- allPoints[j + 1].x, allPoints[j + 1].y,
67
- allPoints[j + 2].x, allPoints[j + 2].y
68
- );
69
- }
70
- }
71
- } else {
72
- ctx.lineTo(endCoordinates.x, endCoordinates.y);
73
- }
74
- } else {
75
- ctx.lineTo(endCoordinates.x, endCoordinates.y);
76
- }
77
-
78
- const appliedStyle = inSingleLineSequence ? currentStyle : lineStyle;
79
- ctx.lineWidth = appliedStyle?.width || 1;
80
-
81
- if (appliedStyle?.gradient) {
82
- ctx.strokeStyle = createGradientFill(ctx, appliedStyle.gradient, { x: start.x, y: start.y, w: endCoordinates.x - start.x, h: endCoordinates.y - start.y });
83
- } else {
84
- ctx.strokeStyle = appliedStyle?.color || 'black';
85
- }
86
-
87
- ctx.lineJoin = appliedStyle?.lineJoin || 'miter';
88
- ctx.lineCap = appliedStyle?.lineCap || 'butt';
89
-
90
- // Apply line patterns
91
- if (appliedStyle?.pattern) {
92
- applyLinePattern(ctx, appliedStyle.pattern);
93
- } else if (appliedStyle?.lineDash) {
94
- ctx.setLineDash(appliedStyle.lineDash.dashArray || []);
95
- ctx.lineDashOffset = appliedStyle.lineDash.offset || 0;
96
- } else {
97
- ctx.setLineDash([]);
98
- }
99
-
100
- // Apply line texture if specified
101
- if (appliedStyle?.texture) {
102
- await applyLineTexture(ctx, appliedStyle.texture, appliedStyle.width || 1,
103
- Math.sqrt(Math.pow(endCoordinates.x - start.x, 2) + Math.pow(endCoordinates.y - start.y, 2)));
104
- }
105
-
106
- if (typeof appliedStyle?.lineRadius === 'number' && appliedStyle.lineRadius > 0) {
107
- const radius = appliedStyle.lineRadius;
108
- const dx = endCoordinates.x - start.x;
109
- const dy = endCoordinates.y - start.y;
110
- const angle = Math.atan2(dy, dx);
111
-
112
- ctx.lineCap = "round";
113
- ctx.stroke();
114
-
115
- ctx.beginPath();
116
- ctx.arc(start.x, start.y, radius, angle + Math.PI / 2, angle - Math.PI / 2, true);
117
- ctx.arc(endCoordinates.x, endCoordinates.y, radius, angle - Math.PI / 2, angle + Math.PI / 2, false);
118
- ctx.fill();
119
- }
120
-
121
- else if (appliedStyle?.lineRadius === 'circular') {
122
- const dx = endCoordinates.x - start.x;
123
- const dy = endCoordinates.y - start.y;
124
- const length = Math.sqrt(dx * dx + dy * dy);
125
-
126
- ctx.beginPath();
127
- ctx.arcTo(start.x, start.y, endCoordinates.x, endCoordinates.y, length / 2);
128
- ctx.arcTo(endCoordinates.x, endCoordinates.y, start.x, start.y, length / 2);
129
- ctx.closePath();
130
- ctx.stroke();
131
- }
132
-
133
- if (!inSingleLineSequence || i === options.length - 1) {
134
- ctx.stroke();
135
- if (appliedStyle) {
136
- applyStroke(ctx, appliedStyle, startCoordinates, endCoordinates);
137
- }
138
- }
139
-
140
- // Draw arrows if specified
141
- if (arrow) {
142
- const dx = endCoordinates.x - start.x;
143
- const dy = endCoordinates.y - start.y;
144
- const angle = Math.atan2(dy, dx);
145
- const arrowColor = arrow.color || appliedStyle?.color || 'black';
146
- const arrowSize = arrow.size || 10;
147
-
148
- if (arrow.start) {
149
- drawArrow(ctx, start.x, start.y, angle + Math.PI, arrowSize, arrow.style || 'filled', arrowColor);
150
- }
151
- if (arrow.end) {
152
- drawArrow(ctx, endCoordinates.x, endCoordinates.y, angle, arrowSize, arrow.style || 'filled', arrowColor);
153
- }
154
- }
155
-
156
- // Draw markers if specified
157
- if (markers && markers.length > 0) {
158
- const linePoints = [start, endCoordinates];
159
- for (const marker of markers) {
160
- const point = getPointOnLinePath(linePoints, marker.position);
161
- drawMarker(ctx, point.x, point.y, marker.shape, marker.size, marker.color);
162
- }
163
- }
164
-
165
- previousEndCoordinates = endCoordinates;
166
-
167
- if (!isSingleLine) {
168
- currentStyle = null;
169
- inSingleLineSequence = false;
170
- }
171
- }
172
- }
173
-
174
- function applyStroke(ctx: SKRSContext2D, style: CustomOptions['lineStyle'] | undefined, start: { x: number; y: number }, end: { x: number; y: number }): void {
175
- if (!style || !style.stroke) {
176
- return;
177
- }
178
-
179
- if (style.stroke) {
180
- const { color, width, gradient, lineRadius, lineCap } = style.stroke;
181
- const prevStrokeStyle = ctx.strokeStyle;
182
- const prevLineWidth = ctx.lineWidth;
183
- const prevLineCap = ctx.lineCap;
184
-
185
- if (gradient) {
186
- ctx.strokeStyle = createGradientFill(ctx, gradient, { x: start.x, y: start.y, w: end.x - start.x, h: end.y - start.y });
187
- } else {
188
- ctx.strokeStyle = color || prevStrokeStyle;
189
- }
190
-
191
- ctx.lineWidth = width || prevLineWidth;
192
- ctx.lineCap = lineCap || prevLineCap;
193
- ctx.stroke();
194
-
195
- if (typeof lineRadius === 'number' && lineRadius > 0) {
196
- ctx.beginPath();
197
- ctx.arc(start.x, start.y, lineRadius, 0, Math.PI * 2);
198
- ctx.arc(end.x, end.y, lineRadius, 0, Math.PI * 2);
199
- ctx.fill();
200
- }
201
-
202
- ctx.strokeStyle = prevStrokeStyle;
203
- ctx.lineWidth = prevLineWidth;
204
- ctx.lineCap = prevLineCap;
205
- }
206
- }
@@ -1,103 +0,0 @@
1
- import { ApexPainter } from '../../ApexPainter';
2
- import { BatchOperation, ChainOperation, CanvasConfig, ImageProperties, TextProperties } from '../types';
3
-
4
- /**
5
- * Processes multiple operations in parallel
6
- * @param painter - ApexPainter instance
7
- * @param operations - Array of operations to process
8
- * @returns Array of result buffers
9
- */
10
- export async function batchOperations(
11
- painter: ApexPainter,
12
- operations: BatchOperation[]
13
- ): Promise<Buffer[]> {
14
- if (!operations || operations.length === 0) {
15
- throw new Error('batch: operations array is required');
16
- }
17
-
18
- const promises = operations.map(async (op) => {
19
- try {
20
- switch (op.type) {
21
- case 'canvas':
22
- const canvasResult = await painter.createCanvas(op.config as CanvasConfig);
23
- return canvasResult.buffer;
24
-
25
- case 'image':
26
- // For image operations, we need a base canvas
27
- const baseCanvas = await painter.createCanvas({ width: 800, height: 600 });
28
- return await painter.createImage(op.config as ImageProperties | ImageProperties[], baseCanvas);
29
-
30
- case 'text':
31
- // For text operations, we need a base canvas
32
- const textBaseCanvas = await painter.createCanvas({ width: 800, height: 600 });
33
- return await painter.createText(op.config as TextProperties | TextProperties[], textBaseCanvas);
34
-
35
- case 'chart':
36
- return await painter.createChart(op.config, { chartType: 'bar', chartNumber: 1 });
37
-
38
- default:
39
- throw new Error(`batch: Unknown operation type: ${op.type}`);
40
- }
41
- } catch (error) {
42
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
43
- throw new Error(`batch: Failed to process ${op.type} operation: ${errorMessage}`);
44
- }
45
- });
46
-
47
- return Promise.all(promises);
48
- }
49
-
50
- /**
51
- * Chains multiple operations sequentially
52
- * @param painter - ApexPainter instance
53
- * @param operations - Array of operations to chain
54
- * @returns Final result buffer
55
- */
56
- export async function chainOperations(
57
- painter: ApexPainter,
58
- operations: ChainOperation[]
59
- ): Promise<Buffer> {
60
- if (!operations || operations.length === 0) {
61
- throw new Error('chain: operations array is required');
62
- }
63
-
64
- let currentBuffer: Buffer | undefined;
65
-
66
- for (const op of operations) {
67
- try {
68
- const method = (painter as any)[op.method];
69
- if (typeof method !== 'function') {
70
- throw new Error(`chain: Method "${op.method}" does not exist on ApexPainter`);
71
- }
72
-
73
- // Prepare arguments - replace 'current' with current buffer
74
- const args = op.args.map(arg => {
75
- if (arg === 'current' || (typeof arg === 'object' && arg !== null && (arg as any).__isCurrentBuffer)) {
76
- return currentBuffer;
77
- }
78
- return arg;
79
- });
80
-
81
- const result = await method.apply(painter, args);
82
-
83
- // Update current buffer
84
- if (Buffer.isBuffer(result)) {
85
- currentBuffer = result;
86
- } else if (result && typeof result === 'object' && 'buffer' in result) {
87
- currentBuffer = (result as any).buffer;
88
- } else {
89
- throw new Error(`chain: Operation "${op.method}" did not return a buffer`);
90
- }
91
- } catch (error) {
92
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
93
- throw new Error(`chain: Failed to execute "${op.method}": ${errorMessage}`);
94
- }
95
- }
96
-
97
- if (!currentBuffer) {
98
- throw new Error('chain: No buffer was produced from operations');
99
- }
100
-
101
- return currentBuffer;
102
- }
103
-