apexify.js 4.5.44 → 4.5.50

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 (438) hide show
  1. package/dist/cjs/ai/ApexAI.d.ts.map +1 -0
  2. package/dist/cjs/ai/ApexAI.js.map +1 -0
  3. package/dist/{ai → cjs/ai}/ApexModules.d.ts +12 -1
  4. package/dist/cjs/ai/ApexModules.d.ts.map +1 -0
  5. package/dist/{ai → cjs/ai}/ApexModules.js +10 -0
  6. package/dist/cjs/ai/ApexModules.js.map +1 -0
  7. package/dist/cjs/ai/buttons/drawMenu.d.ts.map +1 -0
  8. package/dist/cjs/ai/buttons/drawMenu.js.map +1 -0
  9. package/dist/cjs/ai/buttons/tools.d.ts.map +1 -0
  10. package/dist/cjs/ai/buttons/tools.js.map +1 -0
  11. package/dist/cjs/ai/functions/chunkString.d.ts.map +1 -0
  12. package/dist/cjs/ai/functions/chunkString.js.map +1 -0
  13. package/dist/cjs/ai/functions/draw.d.ts.map +1 -0
  14. package/dist/cjs/ai/functions/draw.js.map +1 -0
  15. package/dist/cjs/ai/functions/generateVoiceResponse.d.ts.map +1 -0
  16. package/dist/cjs/ai/functions/generateVoiceResponse.js.map +1 -0
  17. package/dist/cjs/ai/functions/imageReader.d.ts.map +1 -0
  18. package/dist/cjs/ai/functions/imageReader.js.map +1 -0
  19. package/dist/cjs/ai/functions/readFiles.d.ts.map +1 -0
  20. package/dist/{ai → cjs/ai}/functions/readFiles.js +17 -7
  21. package/dist/cjs/ai/functions/readFiles.js.map +1 -0
  22. package/dist/cjs/ai/functions/shouldDrawImage.d.ts.map +1 -0
  23. package/dist/cjs/ai/functions/shouldDrawImage.js.map +1 -0
  24. package/dist/cjs/ai/functions/typeWriter.d.ts.map +1 -0
  25. package/dist/cjs/ai/functions/typeWriter.js.map +1 -0
  26. package/dist/cjs/ai/functions/validOptions.d.ts.map +1 -0
  27. package/dist/cjs/ai/functions/validOptions.js.map +1 -0
  28. package/dist/cjs/ai/modals-chat/electronHub/chatmodels.d.ts.map +1 -0
  29. package/dist/{ai → cjs/ai}/modals-chat/electronHub/chatmodels.js +0 -1
  30. package/dist/cjs/ai/modals-chat/electronHub/chatmodels.js.map +1 -0
  31. package/dist/cjs/ai/modals-chat/electronHub/imageModels.d.ts.map +1 -0
  32. package/dist/cjs/ai/modals-chat/electronHub/imageModels.js.map +1 -0
  33. package/dist/cjs/ai/modals-chat/electronHub/songModels.d.ts +1 -0
  34. package/dist/cjs/ai/modals-chat/electronHub/songModels.d.ts.map +1 -0
  35. package/dist/cjs/ai/modals-chat/electronHub/songModels.js +2 -0
  36. package/dist/cjs/ai/modals-chat/electronHub/songModels.js.map +1 -0
  37. package/dist/cjs/ai/modals-chat/electronHub/speechModels.d.ts +7 -0
  38. package/dist/cjs/ai/modals-chat/electronHub/speechModels.d.ts.map +1 -0
  39. package/dist/cjs/ai/modals-chat/electronHub/speechModels.js +60 -0
  40. package/dist/cjs/ai/modals-chat/electronHub/speechModels.js.map +1 -0
  41. package/dist/cjs/ai/modals-chat/electronHub/videoModels.d.ts +6 -0
  42. package/dist/cjs/ai/modals-chat/electronHub/videoModels.d.ts.map +1 -0
  43. package/dist/cjs/ai/modals-chat/electronHub/videoModels.js +63 -0
  44. package/dist/cjs/ai/modals-chat/electronHub/videoModels.js.map +1 -0
  45. package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.d.ts.map +1 -0
  46. package/dist/cjs/ai/modals-chat/gemini/Gemini-flash.js.map +1 -0
  47. package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.d.ts.map +1 -0
  48. package/dist/cjs/ai/modals-chat/gemini/Gemini-pro.js.map +1 -0
  49. package/dist/cjs/ai/modals-chat/gemini/config.d.ts.map +1 -0
  50. package/dist/cjs/ai/modals-chat/gemini/config.js.map +1 -0
  51. package/dist/cjs/ai/modals-chat/gemini/geminiFast.d.ts.map +1 -0
  52. package/dist/cjs/ai/modals-chat/gemini/geminiFast.js.map +1 -0
  53. package/dist/cjs/ai/modals-chat/groq/chatgroq.d.ts.map +1 -0
  54. package/dist/cjs/ai/modals-chat/groq/chatgroq.js.map +1 -0
  55. package/dist/cjs/ai/modals-chat/groq/imageAnalyzer.d.ts.map +1 -0
  56. package/dist/cjs/ai/modals-chat/groq/imageAnalyzer.js.map +1 -0
  57. package/dist/cjs/ai/modals-chat/groq/whisper.d.ts.map +1 -0
  58. package/dist/cjs/ai/modals-chat/groq/whisper.js.map +1 -0
  59. package/dist/cjs/ai/modals-chat/hercai/chatModels.d.ts.map +1 -0
  60. package/dist/cjs/ai/modals-chat/hercai/chatModels.js.map +1 -0
  61. package/dist/cjs/ai/modals-chat/others/otherModels.d.ts.map +1 -0
  62. package/dist/cjs/ai/modals-chat/others/otherModels.js.map +1 -0
  63. package/dist/cjs/ai/utils.d.ts +13 -0
  64. package/dist/cjs/ai/utils.d.ts.map +1 -0
  65. package/dist/{ai → cjs/ai}/utils.js +3 -1
  66. package/dist/cjs/ai/utils.js.map +1 -0
  67. package/dist/{canvas → cjs/canvas}/ApexPainter.d.ts +7 -7
  68. package/dist/cjs/canvas/ApexPainter.d.ts.map +1 -0
  69. package/dist/cjs/canvas/ApexPainter.js.map +1 -0
  70. package/dist/cjs/canvas/utils/bg.d.ts.map +1 -0
  71. package/dist/cjs/canvas/utils/bg.js.map +1 -0
  72. package/dist/{canvas → cjs/canvas}/utils/charts.d.ts +1 -1
  73. package/dist/cjs/canvas/utils/charts.d.ts.map +1 -0
  74. package/dist/cjs/canvas/utils/charts.js.map +1 -0
  75. package/dist/cjs/canvas/utils/circular.d.ts.map +1 -0
  76. package/dist/cjs/canvas/utils/circular.js.map +1 -0
  77. package/dist/{canvas → cjs/canvas}/utils/conversion.d.ts +1 -1
  78. package/dist/cjs/canvas/utils/conversion.d.ts.map +1 -0
  79. package/dist/{canvas → cjs/canvas}/utils/conversion.js +0 -1
  80. package/dist/cjs/canvas/utils/conversion.js.map +1 -0
  81. package/dist/cjs/canvas/utils/customLines.d.ts.map +1 -0
  82. package/dist/cjs/canvas/utils/customLines.js.map +1 -0
  83. package/dist/{canvas → cjs/canvas}/utils/general functions.d.ts +2 -2
  84. package/dist/cjs/canvas/utils/general functions.d.ts.map +1 -0
  85. package/dist/cjs/canvas/utils/general functions.js.map +1 -0
  86. package/dist/cjs/canvas/utils/imageProperties.d.ts.map +1 -0
  87. package/dist/cjs/canvas/utils/imageProperties.js.map +1 -0
  88. package/dist/cjs/canvas/utils/radius.d.ts.map +1 -0
  89. package/dist/cjs/canvas/utils/radius.js.map +1 -0
  90. package/dist/cjs/canvas/utils/textProperties.d.ts.map +1 -0
  91. package/dist/cjs/canvas/utils/textProperties.js.map +1 -0
  92. package/dist/cjs/canvas/utils/types.d.ts.map +1 -0
  93. package/dist/cjs/canvas/utils/types.js.map +1 -0
  94. package/dist/cjs/canvas/utils/utils.d.ts.map +1 -0
  95. package/dist/cjs/canvas/utils/utils.js.map +1 -0
  96. package/dist/{index.d.ts → cjs/index.d.ts} +4 -2
  97. package/dist/cjs/index.d.ts.map +1 -0
  98. package/dist/{index.js → cjs/index.js} +21 -9
  99. package/dist/cjs/index.js.map +1 -0
  100. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  101. package/dist/cjs/utils.d.ts +5 -0
  102. package/dist/cjs/utils.d.ts.map +1 -0
  103. package/dist/{utils.js → cjs/utils.js} +3 -1
  104. package/dist/cjs/utils.js.map +1 -0
  105. package/dist/esm/ai/ApexAI.d.ts +163 -0
  106. package/dist/esm/ai/ApexAI.d.ts.map +1 -0
  107. package/dist/esm/ai/ApexAI.js +376 -0
  108. package/dist/esm/ai/ApexAI.js.map +1 -0
  109. package/dist/esm/ai/ApexModules.d.ts +46 -0
  110. package/dist/esm/ai/ApexModules.d.ts.map +1 -0
  111. package/dist/esm/ai/ApexModules.js +722 -0
  112. package/dist/esm/ai/ApexModules.js.map +1 -0
  113. package/dist/esm/ai/buttons/drawMenu.d.ts +3 -0
  114. package/dist/esm/ai/buttons/drawMenu.d.ts.map +1 -0
  115. package/dist/esm/ai/buttons/drawMenu.js +271 -0
  116. package/dist/esm/ai/buttons/drawMenu.js.map +1 -0
  117. package/dist/esm/ai/buttons/tools.d.ts +3 -0
  118. package/dist/esm/ai/buttons/tools.d.ts.map +1 -0
  119. package/dist/esm/ai/buttons/tools.js +442 -0
  120. package/dist/esm/ai/buttons/tools.js.map +1 -0
  121. package/dist/esm/ai/functions/chunkString.d.ts +2 -0
  122. package/dist/esm/ai/functions/chunkString.d.ts.map +1 -0
  123. package/dist/esm/ai/functions/chunkString.js +4 -0
  124. package/dist/esm/ai/functions/chunkString.js.map +1 -0
  125. package/dist/esm/ai/functions/draw.d.ts +9 -0
  126. package/dist/esm/ai/functions/draw.d.ts.map +1 -0
  127. package/dist/esm/ai/functions/draw.js +593 -0
  128. package/dist/esm/ai/functions/draw.js.map +1 -0
  129. package/dist/esm/ai/functions/generateVoiceResponse.d.ts +10 -0
  130. package/dist/esm/ai/functions/generateVoiceResponse.d.ts.map +1 -0
  131. package/dist/esm/ai/functions/generateVoiceResponse.js +156 -0
  132. package/dist/esm/ai/functions/generateVoiceResponse.js.map +1 -0
  133. package/dist/esm/ai/functions/imageReader.d.ts +3 -0
  134. package/dist/esm/ai/functions/imageReader.d.ts.map +1 -0
  135. package/dist/esm/ai/functions/imageReader.js +20 -0
  136. package/dist/esm/ai/functions/imageReader.js.map +1 -0
  137. package/dist/esm/ai/functions/readFiles.d.ts +2 -0
  138. package/dist/esm/ai/functions/readFiles.d.ts.map +1 -0
  139. package/dist/esm/ai/functions/readFiles.js +72 -0
  140. package/dist/esm/ai/functions/readFiles.js.map +1 -0
  141. package/dist/esm/ai/functions/shouldDrawImage.d.ts +2 -0
  142. package/dist/esm/ai/functions/shouldDrawImage.d.ts.map +1 -0
  143. package/dist/esm/ai/functions/shouldDrawImage.js +7 -0
  144. package/dist/esm/ai/functions/shouldDrawImage.js.map +1 -0
  145. package/dist/esm/ai/functions/typeWriter.d.ts +2 -0
  146. package/dist/esm/ai/functions/typeWriter.d.ts.map +1 -0
  147. package/dist/esm/ai/functions/typeWriter.js +21 -0
  148. package/dist/{ai → esm/ai}/functions/typeWriter.js.map +1 -1
  149. package/dist/esm/ai/functions/validOptions.d.ts +14 -0
  150. package/dist/esm/ai/functions/validOptions.d.ts.map +1 -0
  151. package/dist/esm/ai/functions/validOptions.js +56 -0
  152. package/dist/esm/ai/functions/validOptions.js.map +1 -0
  153. package/dist/esm/ai/modals-chat/electronHub/chatmodels.d.ts +7 -0
  154. package/dist/esm/ai/modals-chat/electronHub/chatmodels.d.ts.map +1 -0
  155. package/dist/esm/ai/modals-chat/electronHub/chatmodels.js +48 -0
  156. package/dist/esm/ai/modals-chat/electronHub/chatmodels.js.map +1 -0
  157. package/dist/esm/ai/modals-chat/electronHub/imageModels.d.ts +6 -0
  158. package/dist/esm/ai/modals-chat/electronHub/imageModels.d.ts.map +1 -0
  159. package/dist/esm/ai/modals-chat/electronHub/imageModels.js +43 -0
  160. package/dist/esm/ai/modals-chat/electronHub/imageModels.js.map +1 -0
  161. package/dist/esm/ai/modals-chat/electronHub/songModels.d.ts +1 -0
  162. package/dist/esm/ai/modals-chat/electronHub/songModels.d.ts.map +1 -0
  163. package/dist/esm/ai/modals-chat/electronHub/songModels.js +2 -0
  164. package/dist/esm/ai/modals-chat/electronHub/songModels.js.map +1 -0
  165. package/dist/esm/ai/modals-chat/electronHub/speechModels.d.ts +7 -0
  166. package/dist/esm/ai/modals-chat/electronHub/speechModels.d.ts.map +1 -0
  167. package/dist/esm/ai/modals-chat/electronHub/speechModels.js +54 -0
  168. package/dist/esm/ai/modals-chat/electronHub/speechModels.js.map +1 -0
  169. package/dist/esm/ai/modals-chat/electronHub/videoModels.d.ts +6 -0
  170. package/dist/esm/ai/modals-chat/electronHub/videoModels.d.ts.map +1 -0
  171. package/dist/esm/ai/modals-chat/electronHub/videoModels.js +57 -0
  172. package/dist/esm/ai/modals-chat/electronHub/videoModels.js.map +1 -0
  173. package/dist/esm/ai/modals-chat/gemini/Gemini-flash.d.ts +13 -0
  174. package/dist/esm/ai/modals-chat/gemini/Gemini-flash.d.ts.map +1 -0
  175. package/dist/esm/ai/modals-chat/gemini/Gemini-flash.js +179 -0
  176. package/dist/esm/ai/modals-chat/gemini/Gemini-flash.js.map +1 -0
  177. package/dist/esm/ai/modals-chat/gemini/Gemini-pro.d.ts +13 -0
  178. package/dist/esm/ai/modals-chat/gemini/Gemini-pro.d.ts.map +1 -0
  179. package/dist/esm/ai/modals-chat/gemini/Gemini-pro.js +179 -0
  180. package/dist/esm/ai/modals-chat/gemini/Gemini-pro.js.map +1 -0
  181. package/dist/esm/ai/modals-chat/gemini/config.d.ts +5 -0
  182. package/dist/esm/ai/modals-chat/gemini/config.d.ts.map +1 -0
  183. package/dist/esm/ai/modals-chat/gemini/config.js +11 -0
  184. package/dist/esm/ai/modals-chat/gemini/config.js.map +1 -0
  185. package/dist/esm/ai/modals-chat/gemini/geminiFast.d.ts +15 -0
  186. package/dist/esm/ai/modals-chat/gemini/geminiFast.d.ts.map +1 -0
  187. package/dist/esm/ai/modals-chat/gemini/geminiFast.js +140 -0
  188. package/dist/esm/ai/modals-chat/gemini/geminiFast.js.map +1 -0
  189. package/dist/esm/ai/modals-chat/groq/chatgroq.d.ts +9 -0
  190. package/dist/esm/ai/modals-chat/groq/chatgroq.d.ts.map +1 -0
  191. package/dist/esm/ai/modals-chat/groq/chatgroq.js +58 -0
  192. package/dist/esm/ai/modals-chat/groq/chatgroq.js.map +1 -0
  193. package/dist/esm/ai/modals-chat/groq/imageAnalyzer.d.ts +8 -0
  194. package/dist/esm/ai/modals-chat/groq/imageAnalyzer.d.ts.map +1 -0
  195. package/dist/esm/ai/modals-chat/groq/imageAnalyzer.js +53 -0
  196. package/dist/esm/ai/modals-chat/groq/imageAnalyzer.js.map +1 -0
  197. package/dist/esm/ai/modals-chat/groq/whisper.d.ts +2 -0
  198. package/dist/esm/ai/modals-chat/groq/whisper.d.ts.map +1 -0
  199. package/dist/esm/ai/modals-chat/groq/whisper.js +92 -0
  200. package/dist/esm/ai/modals-chat/groq/whisper.js.map +1 -0
  201. package/dist/esm/ai/modals-chat/hercai/chatModels.d.ts +7 -0
  202. package/dist/esm/ai/modals-chat/hercai/chatModels.d.ts.map +1 -0
  203. package/dist/esm/ai/modals-chat/hercai/chatModels.js +20 -0
  204. package/dist/esm/ai/modals-chat/hercai/chatModels.js.map +1 -0
  205. package/dist/esm/ai/modals-chat/others/otherModels.d.ts +9 -0
  206. package/dist/esm/ai/modals-chat/others/otherModels.d.ts.map +1 -0
  207. package/dist/esm/ai/modals-chat/others/otherModels.js +95 -0
  208. package/dist/esm/ai/modals-chat/others/otherModels.js.map +1 -0
  209. package/dist/esm/ai/utils.d.ts +13 -0
  210. package/dist/esm/ai/utils.d.ts.map +1 -0
  211. package/dist/{ai/utils.d.ts → esm/ai/utils.js} +3 -3
  212. package/dist/esm/ai/utils.js.map +1 -0
  213. package/dist/esm/canvas/ApexPainter.d.ts +131 -0
  214. package/dist/esm/canvas/ApexPainter.d.ts.map +1 -0
  215. package/dist/esm/canvas/ApexPainter.js +769 -0
  216. package/dist/esm/canvas/ApexPainter.js.map +1 -0
  217. package/dist/esm/canvas/utils/bg.d.ts +23 -0
  218. package/dist/esm/canvas/utils/bg.d.ts.map +1 -0
  219. package/dist/esm/canvas/utils/bg.js +103 -0
  220. package/dist/esm/canvas/utils/bg.js.map +1 -0
  221. package/dist/esm/canvas/utils/charts.d.ts +8 -0
  222. package/dist/esm/canvas/utils/charts.d.ts.map +1 -0
  223. package/dist/esm/canvas/utils/charts.js +456 -0
  224. package/dist/esm/canvas/utils/charts.js.map +1 -0
  225. package/dist/esm/canvas/utils/circular.d.ts +10 -0
  226. package/dist/esm/canvas/utils/circular.d.ts.map +1 -0
  227. package/dist/esm/canvas/utils/circular.js +18 -0
  228. package/dist/esm/canvas/utils/circular.js.map +1 -0
  229. package/dist/esm/canvas/utils/conversion.d.ts +6 -0
  230. package/dist/esm/canvas/utils/conversion.d.ts.map +1 -0
  231. package/dist/esm/canvas/utils/conversion.js +27 -0
  232. package/dist/esm/canvas/utils/conversion.js.map +1 -0
  233. package/dist/esm/canvas/utils/customLines.d.ts +3 -0
  234. package/dist/esm/canvas/utils/customLines.d.ts.map +1 -0
  235. package/dist/esm/canvas/utils/customLines.js +82 -0
  236. package/dist/esm/canvas/utils/customLines.js.map +1 -0
  237. package/dist/esm/canvas/utils/general functions.d.ts +20 -0
  238. package/dist/esm/canvas/utils/general functions.d.ts.map +1 -0
  239. package/dist/esm/canvas/utils/general functions.js +427 -0
  240. package/dist/esm/canvas/utils/general functions.js.map +1 -0
  241. package/dist/esm/canvas/utils/imageProperties.d.ts +62 -0
  242. package/dist/esm/canvas/utils/imageProperties.d.ts.map +1 -0
  243. package/dist/esm/canvas/utils/imageProperties.js +332 -0
  244. package/dist/esm/canvas/utils/imageProperties.js.map +1 -0
  245. package/dist/esm/canvas/utils/radius.d.ts +10 -0
  246. package/dist/esm/canvas/utils/radius.d.ts.map +1 -0
  247. package/dist/esm/canvas/utils/radius.js +27 -0
  248. package/dist/esm/canvas/utils/radius.js.map +1 -0
  249. package/dist/esm/canvas/utils/textProperties.d.ts +19 -0
  250. package/dist/esm/canvas/utils/textProperties.d.ts.map +1 -0
  251. package/dist/esm/canvas/utils/textProperties.js +146 -0
  252. package/dist/esm/canvas/utils/textProperties.js.map +1 -0
  253. package/dist/esm/canvas/utils/types.d.ts +536 -0
  254. package/dist/esm/canvas/utils/types.d.ts.map +1 -0
  255. package/dist/esm/canvas/utils/types.js +6 -0
  256. package/dist/esm/canvas/utils/types.js.map +1 -0
  257. package/dist/esm/canvas/utils/utils.d.ts +21 -0
  258. package/dist/esm/canvas/utils/utils.d.ts.map +1 -0
  259. package/dist/esm/canvas/utils/utils.js +20 -0
  260. package/dist/esm/canvas/utils/utils.js.map +1 -0
  261. package/dist/esm/index.d.ts +32 -0
  262. package/dist/esm/index.d.ts.map +1 -0
  263. package/dist/esm/index.js +39 -0
  264. package/dist/esm/index.js.map +1 -0
  265. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  266. package/dist/esm/utils.d.ts +5 -0
  267. package/dist/esm/utils.d.ts.map +1 -0
  268. package/dist/{utils.d.ts → esm/utils.js} +3 -3
  269. package/dist/esm/utils.js.map +1 -0
  270. package/lib/ai/ApexModules.ts +20 -1
  271. package/lib/ai/modals-chat/electronHub/chatmodels.ts +0 -1
  272. package/lib/ai/modals-chat/electronHub/songModels.ts +0 -0
  273. package/lib/ai/modals-chat/electronHub/speechModels.ts +70 -0
  274. package/lib/ai/modals-chat/electronHub/videoModels.ts +75 -0
  275. package/lib/ai/utils.ts +4 -2
  276. package/lib/canvas/utils/conversion.ts +0 -1
  277. package/lib/index.ts +3 -3
  278. package/lib/utils.ts +2 -2
  279. package/package.json +23 -7
  280. package/dist/ai/ApexAI.d.ts.map +0 -1
  281. package/dist/ai/ApexAI.js.map +0 -1
  282. package/dist/ai/ApexModules.d.ts.map +0 -1
  283. package/dist/ai/ApexModules.js.map +0 -1
  284. package/dist/ai/buttons/drawMenu.d.ts.map +0 -1
  285. package/dist/ai/buttons/drawMenu.js.map +0 -1
  286. package/dist/ai/buttons/tools.d.ts.map +0 -1
  287. package/dist/ai/buttons/tools.js.map +0 -1
  288. package/dist/ai/functions/chunkString.d.ts.map +0 -1
  289. package/dist/ai/functions/chunkString.js.map +0 -1
  290. package/dist/ai/functions/draw.d.ts.map +0 -1
  291. package/dist/ai/functions/draw.js.map +0 -1
  292. package/dist/ai/functions/generateVoiceResponse.d.ts.map +0 -1
  293. package/dist/ai/functions/generateVoiceResponse.js.map +0 -1
  294. package/dist/ai/functions/imageReader.d.ts.map +0 -1
  295. package/dist/ai/functions/imageReader.js.map +0 -1
  296. package/dist/ai/functions/readFiles.d.ts.map +0 -1
  297. package/dist/ai/functions/readFiles.js.map +0 -1
  298. package/dist/ai/functions/shouldDrawImage.d.ts.map +0 -1
  299. package/dist/ai/functions/shouldDrawImage.js.map +0 -1
  300. package/dist/ai/functions/typeWriter.d.ts.map +0 -1
  301. package/dist/ai/functions/validOptions.d.ts.map +0 -1
  302. package/dist/ai/functions/validOptions.js.map +0 -1
  303. package/dist/ai/modals-chat/electronHub/chatmodels.d.ts.map +0 -1
  304. package/dist/ai/modals-chat/electronHub/chatmodels.js.map +0 -1
  305. package/dist/ai/modals-chat/electronHub/imageModels.d.ts.map +0 -1
  306. package/dist/ai/modals-chat/electronHub/imageModels.js.map +0 -1
  307. package/dist/ai/modals-chat/freesedgpt/cartoon.d.ts +0 -2
  308. package/dist/ai/modals-chat/freesedgpt/cartoon.d.ts.map +0 -1
  309. package/dist/ai/modals-chat/freesedgpt/cartoon.js +0 -26
  310. package/dist/ai/modals-chat/freesedgpt/cartoon.js.map +0 -1
  311. package/dist/ai/modals-chat/freesedgpt/chat.d.ts +0 -5
  312. package/dist/ai/modals-chat/freesedgpt/chat.d.ts.map +0 -1
  313. package/dist/ai/modals-chat/freesedgpt/chat.js +0 -30
  314. package/dist/ai/modals-chat/freesedgpt/chat.js.map +0 -1
  315. package/dist/ai/modals-chat/freesedgpt/flux.d.ts +0 -2
  316. package/dist/ai/modals-chat/freesedgpt/flux.d.ts.map +0 -1
  317. package/dist/ai/modals-chat/freesedgpt/flux.js +0 -26
  318. package/dist/ai/modals-chat/freesedgpt/flux.js.map +0 -1
  319. package/dist/ai/modals-chat/freesedgpt/fresedImagine.d.ts +0 -2
  320. package/dist/ai/modals-chat/freesedgpt/fresedImagine.d.ts.map +0 -1
  321. package/dist/ai/modals-chat/freesedgpt/fresedImagine.js +0 -26
  322. package/dist/ai/modals-chat/freesedgpt/fresedImagine.js.map +0 -1
  323. package/dist/ai/modals-chat/gemini/Gemini-flash.d.ts.map +0 -1
  324. package/dist/ai/modals-chat/gemini/Gemini-flash.js.map +0 -1
  325. package/dist/ai/modals-chat/gemini/Gemini-pro.d.ts.map +0 -1
  326. package/dist/ai/modals-chat/gemini/Gemini-pro.js.map +0 -1
  327. package/dist/ai/modals-chat/gemini/config.d.ts.map +0 -1
  328. package/dist/ai/modals-chat/gemini/config.js.map +0 -1
  329. package/dist/ai/modals-chat/gemini/geminiFast.d.ts.map +0 -1
  330. package/dist/ai/modals-chat/gemini/geminiFast.js.map +0 -1
  331. package/dist/ai/modals-chat/groq/chatgroq.d.ts.map +0 -1
  332. package/dist/ai/modals-chat/groq/chatgroq.js.map +0 -1
  333. package/dist/ai/modals-chat/groq/imageAnalyzer.d.ts.map +0 -1
  334. package/dist/ai/modals-chat/groq/imageAnalyzer.js.map +0 -1
  335. package/dist/ai/modals-chat/groq/whisper.d.ts.map +0 -1
  336. package/dist/ai/modals-chat/groq/whisper.js.map +0 -1
  337. package/dist/ai/modals-chat/hercai/chatModels.d.ts.map +0 -1
  338. package/dist/ai/modals-chat/hercai/chatModels.js.map +0 -1
  339. package/dist/ai/modals-chat/others/otherModels.d.ts.map +0 -1
  340. package/dist/ai/modals-chat/others/otherModels.js.map +0 -1
  341. package/dist/ai/modals-chat/rsn/rsnChat.d.ts +0 -8
  342. package/dist/ai/modals-chat/rsn/rsnChat.d.ts.map +0 -1
  343. package/dist/ai/modals-chat/rsn/rsnChat.js +0 -69
  344. package/dist/ai/modals-chat/rsn/rsnChat.js.map +0 -1
  345. package/dist/ai/utils.d.ts.map +0 -1
  346. package/dist/ai/utils.js.map +0 -1
  347. package/dist/canvas/ApexPainter.d.ts.map +0 -1
  348. package/dist/canvas/ApexPainter.js.map +0 -1
  349. package/dist/canvas/utils/bg.d.ts.map +0 -1
  350. package/dist/canvas/utils/bg.js.map +0 -1
  351. package/dist/canvas/utils/charts.d.ts.map +0 -1
  352. package/dist/canvas/utils/charts.js.map +0 -1
  353. package/dist/canvas/utils/circular.d.ts.map +0 -1
  354. package/dist/canvas/utils/circular.js.map +0 -1
  355. package/dist/canvas/utils/conversion.d.ts.map +0 -1
  356. package/dist/canvas/utils/conversion.js.map +0 -1
  357. package/dist/canvas/utils/customLines.d.ts.map +0 -1
  358. package/dist/canvas/utils/customLines.js.map +0 -1
  359. package/dist/canvas/utils/general functions.d.ts.map +0 -1
  360. package/dist/canvas/utils/general functions.js.map +0 -1
  361. package/dist/canvas/utils/imageProperties.d.ts.map +0 -1
  362. package/dist/canvas/utils/imageProperties.js.map +0 -1
  363. package/dist/canvas/utils/radius.d.ts.map +0 -1
  364. package/dist/canvas/utils/radius.js.map +0 -1
  365. package/dist/canvas/utils/textProperties.d.ts.map +0 -1
  366. package/dist/canvas/utils/textProperties.js.map +0 -1
  367. package/dist/canvas/utils/types.d.ts.map +0 -1
  368. package/dist/canvas/utils/types.js.map +0 -1
  369. package/dist/canvas/utils/utils.d.ts.map +0 -1
  370. package/dist/canvas/utils/utils.js.map +0 -1
  371. package/dist/index.d.ts.map +0 -1
  372. package/dist/index.js.map +0 -1
  373. package/dist/utils.d.ts.map +0 -1
  374. package/dist/utils.js.map +0 -1
  375. package/examples/barchart.txt +0 -71
  376. package/examples/linechart.txt +0 -93
  377. package/examples/piechart.txt +0 -67
  378. /package/dist/{ai → cjs/ai}/ApexAI.d.ts +0 -0
  379. /package/dist/{ai → cjs/ai}/ApexAI.js +0 -0
  380. /package/dist/{ai → cjs/ai}/buttons/drawMenu.d.ts +0 -0
  381. /package/dist/{ai → cjs/ai}/buttons/drawMenu.js +0 -0
  382. /package/dist/{ai → cjs/ai}/buttons/tools.d.ts +0 -0
  383. /package/dist/{ai → cjs/ai}/buttons/tools.js +0 -0
  384. /package/dist/{ai → cjs/ai}/functions/chunkString.d.ts +0 -0
  385. /package/dist/{ai → cjs/ai}/functions/chunkString.js +0 -0
  386. /package/dist/{ai → cjs/ai}/functions/draw.d.ts +0 -0
  387. /package/dist/{ai → cjs/ai}/functions/draw.js +0 -0
  388. /package/dist/{ai → cjs/ai}/functions/generateVoiceResponse.d.ts +0 -0
  389. /package/dist/{ai → cjs/ai}/functions/generateVoiceResponse.js +0 -0
  390. /package/dist/{ai → cjs/ai}/functions/imageReader.d.ts +0 -0
  391. /package/dist/{ai → cjs/ai}/functions/imageReader.js +0 -0
  392. /package/dist/{ai → cjs/ai}/functions/readFiles.d.ts +0 -0
  393. /package/dist/{ai → cjs/ai}/functions/shouldDrawImage.d.ts +0 -0
  394. /package/dist/{ai → cjs/ai}/functions/shouldDrawImage.js +0 -0
  395. /package/dist/{ai → cjs/ai}/functions/typeWriter.d.ts +0 -0
  396. /package/dist/{ai → cjs/ai}/functions/typeWriter.js +0 -0
  397. /package/dist/{ai → cjs/ai}/functions/validOptions.d.ts +0 -0
  398. /package/dist/{ai → cjs/ai}/functions/validOptions.js +0 -0
  399. /package/dist/{ai → cjs/ai}/modals-chat/electronHub/chatmodels.d.ts +0 -0
  400. /package/dist/{ai → cjs/ai}/modals-chat/electronHub/imageModels.d.ts +0 -0
  401. /package/dist/{ai → cjs/ai}/modals-chat/electronHub/imageModels.js +0 -0
  402. /package/dist/{ai → cjs/ai}/modals-chat/gemini/Gemini-flash.d.ts +0 -0
  403. /package/dist/{ai → cjs/ai}/modals-chat/gemini/Gemini-flash.js +0 -0
  404. /package/dist/{ai → cjs/ai}/modals-chat/gemini/Gemini-pro.d.ts +0 -0
  405. /package/dist/{ai → cjs/ai}/modals-chat/gemini/Gemini-pro.js +0 -0
  406. /package/dist/{ai → cjs/ai}/modals-chat/gemini/config.d.ts +0 -0
  407. /package/dist/{ai → cjs/ai}/modals-chat/gemini/config.js +0 -0
  408. /package/dist/{ai → cjs/ai}/modals-chat/gemini/geminiFast.d.ts +0 -0
  409. /package/dist/{ai → cjs/ai}/modals-chat/gemini/geminiFast.js +0 -0
  410. /package/dist/{ai → cjs/ai}/modals-chat/groq/chatgroq.d.ts +0 -0
  411. /package/dist/{ai → cjs/ai}/modals-chat/groq/chatgroq.js +0 -0
  412. /package/dist/{ai → cjs/ai}/modals-chat/groq/imageAnalyzer.d.ts +0 -0
  413. /package/dist/{ai → cjs/ai}/modals-chat/groq/imageAnalyzer.js +0 -0
  414. /package/dist/{ai → cjs/ai}/modals-chat/groq/whisper.d.ts +0 -0
  415. /package/dist/{ai → cjs/ai}/modals-chat/groq/whisper.js +0 -0
  416. /package/dist/{ai → cjs/ai}/modals-chat/hercai/chatModels.d.ts +0 -0
  417. /package/dist/{ai → cjs/ai}/modals-chat/hercai/chatModels.js +0 -0
  418. /package/dist/{ai → cjs/ai}/modals-chat/others/otherModels.d.ts +0 -0
  419. /package/dist/{ai → cjs/ai}/modals-chat/others/otherModels.js +0 -0
  420. /package/dist/{canvas → cjs/canvas}/ApexPainter.js +0 -0
  421. /package/dist/{canvas → cjs/canvas}/utils/bg.d.ts +0 -0
  422. /package/dist/{canvas → cjs/canvas}/utils/bg.js +0 -0
  423. /package/dist/{canvas → cjs/canvas}/utils/charts.js +0 -0
  424. /package/dist/{canvas → cjs/canvas}/utils/circular.d.ts +0 -0
  425. /package/dist/{canvas → cjs/canvas}/utils/circular.js +0 -0
  426. /package/dist/{canvas → cjs/canvas}/utils/customLines.d.ts +0 -0
  427. /package/dist/{canvas → cjs/canvas}/utils/customLines.js +0 -0
  428. /package/dist/{canvas → cjs/canvas}/utils/general functions.js +0 -0
  429. /package/dist/{canvas → cjs/canvas}/utils/imageProperties.d.ts +0 -0
  430. /package/dist/{canvas → cjs/canvas}/utils/imageProperties.js +0 -0
  431. /package/dist/{canvas → cjs/canvas}/utils/radius.d.ts +0 -0
  432. /package/dist/{canvas → cjs/canvas}/utils/radius.js +0 -0
  433. /package/dist/{canvas → cjs/canvas}/utils/textProperties.d.ts +0 -0
  434. /package/dist/{canvas → cjs/canvas}/utils/textProperties.js +0 -0
  435. /package/dist/{canvas → cjs/canvas}/utils/types.d.ts +0 -0
  436. /package/dist/{canvas → cjs/canvas}/utils/types.js +0 -0
  437. /package/dist/{canvas → cjs/canvas}/utils/utils.d.ts +0 -0
  438. /package/dist/{canvas → cjs/canvas}/utils/utils.js +0 -0
@@ -0,0 +1,769 @@
1
+ import { createCanvas, loadImage, GlobalFonts } from "@napi-rs/canvas";
2
+ import GIFEncoder from "gifencoder";
3
+ import ffmpeg from 'fluent-ffmpeg';
4
+ import { PassThrough } from "stream";
5
+ import axios from 'axios';
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import { drawBackgroundGradient, drawBackgroundColor, customBackground, circularBorder, radiusBorder, customLines, applyRotation, applyStroke, applyShadow, imageRadius, drawShape, drawText, converter, resizingImg, applyColorFilters, imgEffects, verticalBarChart, pieChart, lineChart, cropInner, cropOuter, bgRemoval, detectColors, removeColor, dataURL, base64, arrayBuffer, blob, url } from "./utils/utils";
9
+ export class ApexPainter {
10
+ format;
11
+ constructor({ type } = { type: 'buffer' }) {
12
+ this.format = { type: type || 'buffer' };
13
+ }
14
+ async createCanvas(canvas) {
15
+ let canvasWidth = canvas.width || 500;
16
+ let canvasHeight = canvas.height || 500;
17
+ let borderRadius = canvas.borderRadius || 0;
18
+ const canvasInstance = createCanvas(canvasWidth, canvasHeight);
19
+ const ctx = canvasInstance.getContext('2d');
20
+ if (!ctx) {
21
+ throw new Error('Unable to get 2D rendering context from canvas');
22
+ }
23
+ applyRotation(ctx, canvas.rotation || 0, canvas.x || 0, canvas.y || 0, canvasWidth, canvasHeight);
24
+ applyShadow(ctx, canvas.shadow, canvas.x || 0, canvas.y || 0, canvasWidth, canvasHeight);
25
+ if (typeof borderRadius === 'string') {
26
+ circularBorder(ctx, canvasWidth, canvasHeight);
27
+ }
28
+ else if (typeof borderRadius === 'number') {
29
+ radiusBorder(ctx, canvas.x || 0, canvas.y || 0, canvasWidth, canvasHeight, borderRadius);
30
+ }
31
+ if (canvas.customBg) {
32
+ await customBackground(ctx, canvas);
33
+ }
34
+ else if (canvas.gradientBg) {
35
+ await drawBackgroundGradient(ctx, canvas);
36
+ }
37
+ else {
38
+ await drawBackgroundColor(ctx, canvas);
39
+ }
40
+ applyStroke(ctx, canvas.stroke, canvas.x || 0, canvas.y || 0, canvasWidth, canvasHeight);
41
+ return { buffer: canvasInstance.toBuffer('image/png'), canvas };
42
+ }
43
+ async createImage(images, canvasBuffer) {
44
+ if (!Array.isArray(images)) {
45
+ images = [images];
46
+ }
47
+ let existingCanvas;
48
+ if (Buffer.isBuffer(canvasBuffer)) {
49
+ existingCanvas = await loadImage(canvasBuffer);
50
+ }
51
+ else if (canvasBuffer && canvasBuffer.buffer) {
52
+ existingCanvas = await loadImage(canvasBuffer.buffer);
53
+ }
54
+ else {
55
+ throw new Error('Invalid canvasBuffer provided, should be Buffer or CanvasResults object with buffer');
56
+ }
57
+ if (!existingCanvas) {
58
+ throw new Error('Unable to load image from buffer');
59
+ }
60
+ const canvas = createCanvas(existingCanvas.width, existingCanvas.height);
61
+ const ctx = canvas.getContext('2d');
62
+ if (!ctx) {
63
+ throw new Error('Unable to get 2D rendering context from canvas');
64
+ }
65
+ ctx.drawImage(existingCanvas, 0, 0);
66
+ for (const image of images) {
67
+ await this.drawImage(ctx, image);
68
+ }
69
+ return canvas.toBuffer('image/png');
70
+ }
71
+ async createText(textOptionsArray, buffer) {
72
+ try {
73
+ if (!Array.isArray(textOptionsArray)) {
74
+ textOptionsArray = [textOptionsArray];
75
+ }
76
+ let existingImage;
77
+ if (Buffer.isBuffer(buffer)) {
78
+ existingImage = await loadImage(buffer);
79
+ }
80
+ else if (buffer && buffer.buffer) {
81
+ existingImage = await loadImage(buffer.buffer);
82
+ }
83
+ else {
84
+ throw new Error('Invalid canvasBuffer provided. It should be a Buffer or CanvasResults object with a buffer');
85
+ }
86
+ if (!existingImage) {
87
+ throw new Error('Unable to load image from buffer');
88
+ }
89
+ const canvas = createCanvas(existingImage.width, existingImage.height);
90
+ const ctx = canvas.getContext("2d");
91
+ ctx.drawImage(existingImage, 0, 0);
92
+ for (const textOptions of textOptionsArray) {
93
+ const mergedTextOptions = textOptions;
94
+ if (mergedTextOptions.fontPath) {
95
+ GlobalFonts.registerFromPath(path.join(process.cwd(), mergedTextOptions.fontPath), mergedTextOptions.fontName);
96
+ }
97
+ const size = { width: existingImage.width, height: existingImage.height };
98
+ drawText(ctx, mergedTextOptions, size);
99
+ }
100
+ return canvas.toBuffer("image/png");
101
+ }
102
+ catch (error) {
103
+ console.error("Error loading existing image:", error);
104
+ throw new Error("Invalid image buffer");
105
+ }
106
+ }
107
+ async createCustom(options, buffer) {
108
+ try {
109
+ if (!Array.isArray(options)) {
110
+ options = [options];
111
+ }
112
+ let existingImage;
113
+ if (Buffer.isBuffer(buffer)) {
114
+ existingImage = await loadImage(buffer);
115
+ }
116
+ else if (buffer && buffer.buffer) {
117
+ existingImage = await loadImage(buffer.buffer);
118
+ }
119
+ else {
120
+ throw new Error('Invalid canvasBuffer provided. It should be a Buffer or CanvasResults object with a buffer');
121
+ }
122
+ if (!existingImage) {
123
+ throw new Error('Unable to load image from buffer');
124
+ }
125
+ const canvas = createCanvas(existingImage.width, existingImage.height);
126
+ const ctx = canvas.getContext("2d");
127
+ ctx.drawImage(existingImage, 0, 0);
128
+ customLines(ctx, options);
129
+ return canvas.toBuffer("image/png");
130
+ }
131
+ catch (error) {
132
+ console.error("Error creating custom image:", error);
133
+ throw new Error("Failed to create custom image");
134
+ }
135
+ }
136
+ async createGIF(gifFrames, options) {
137
+ async function resizeImage(image, targetWidth, targetHeight) {
138
+ const canvas = createCanvas(targetWidth, targetHeight);
139
+ const ctx = canvas.getContext("2d");
140
+ ctx.drawImage(image, 0, 0, targetWidth, targetHeight);
141
+ return canvas;
142
+ }
143
+ function createOutputStream(outputFile) {
144
+ return fs.createWriteStream(outputFile);
145
+ }
146
+ function createBufferStream() {
147
+ const bufferStream = new PassThrough();
148
+ const chunks = [];
149
+ bufferStream.on('data', (chunk) => {
150
+ chunks.push(chunk);
151
+ });
152
+ return {
153
+ ...bufferStream,
154
+ getBuffer: function () {
155
+ return Buffer.concat(chunks);
156
+ }
157
+ };
158
+ }
159
+ function validateOptions(options) {
160
+ if (options.outputFormat === "file" && !options.outputFile) {
161
+ throw new Error("Output file path is required when using file output format.");
162
+ }
163
+ if (options.repeat !== undefined && (typeof options.repeat !== "number" || options.repeat < 0)) {
164
+ throw new Error("Repeat must be a non-negative number or undefined.");
165
+ }
166
+ if (options.quality !== undefined && (typeof options.quality !== "number" || options.quality < 1 || options.quality > 20)) {
167
+ throw new Error("Quality must be a number between 1 and 20 or undefined.");
168
+ }
169
+ if (options.watermark && typeof options.watermark.enable !== "boolean") {
170
+ throw new Error("Watermark must be a boolean or undefined.");
171
+ }
172
+ if (options.textOverlay) {
173
+ const textOptions = options.textOverlay;
174
+ if (!textOptions.text || typeof textOptions.text !== "string") {
175
+ throw new Error("Text overlay text is required and must be a string.");
176
+ }
177
+ if (textOptions.fontSize !== undefined && (!Number.isInteger(textOptions.fontSize) || textOptions.fontSize <= 0)) {
178
+ throw new Error("Text overlay fontSize must be a positive integer or undefined.");
179
+ }
180
+ if (textOptions.fontColor !== undefined && typeof textOptions.fontColor !== "string") {
181
+ throw new Error("Text overlay fontColor must be a string or undefined.");
182
+ }
183
+ }
184
+ }
185
+ try {
186
+ validateOptions(options);
187
+ const canvasWidth = options.width || 1200;
188
+ const canvasHeight = options.height || 1200;
189
+ const encoder = new GIFEncoder(canvasWidth, canvasHeight);
190
+ const outputStream = options.outputFile ? createOutputStream(options.outputFile) : createBufferStream();
191
+ encoder.createReadStream().pipe(outputStream);
192
+ encoder.start();
193
+ encoder.setRepeat(options.repeat || 0);
194
+ encoder.setQuality(options.quality || 10);
195
+ const canvas = createCanvas(canvasWidth, canvasHeight);
196
+ const ctx = canvas.getContext("2d");
197
+ for (const frame of gifFrames) {
198
+ const image = await loadImage(frame.background);
199
+ const resizedImage = await resizeImage(image, canvasWidth, canvasHeight);
200
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
201
+ ctx.drawImage(resizedImage, 0, 0);
202
+ if (options.watermark?.enable) {
203
+ const watermark = await loadImage(options.watermark.url);
204
+ ctx.drawImage(watermark, 10, canvasHeight - watermark.height - 10);
205
+ }
206
+ if (options.textOverlay) {
207
+ ctx.font = `${options.textOverlay.fontSize || 20}px Arial`;
208
+ ctx.fillStyle = options.textOverlay.fontColor || "white";
209
+ ctx.fillText(options.textOverlay.text, options.textOverlay.x || 10, options.textOverlay.y || 30);
210
+ }
211
+ encoder.setDelay(frame.duration);
212
+ encoder.addFrame(ctx);
213
+ }
214
+ encoder.finish();
215
+ outputStream.end();
216
+ if (options.outputFormat === "file") {
217
+ await new Promise((resolve) => outputStream.on("finish", resolve));
218
+ }
219
+ else if (options.outputFormat === "base64") {
220
+ if ('getBuffer' in outputStream) {
221
+ return outputStream.getBuffer().toString("base64");
222
+ }
223
+ }
224
+ else if (options.outputFormat === "attachment") {
225
+ const gifStream = encoder.createReadStream();
226
+ return [{ attachment: gifStream, name: "gif.js" }];
227
+ }
228
+ else if (options.outputFormat === "buffer") {
229
+ if ('getBuffer' in outputStream) {
230
+ return outputStream.getBuffer();
231
+ }
232
+ }
233
+ else {
234
+ throw new Error("Invalid output format. Supported formats are 'file', 'base64', 'attachment', and 'buffer'.");
235
+ }
236
+ }
237
+ catch (e) {
238
+ console.error(e.message);
239
+ throw e; // Re-throw the error after logging
240
+ }
241
+ }
242
+ async resize(resizeOptions) {
243
+ return resizingImg(resizeOptions);
244
+ }
245
+ async imgConverter(imagePath, newExtension) {
246
+ return converter(imagePath, newExtension);
247
+ }
248
+ async processImage(imagePath, filters) {
249
+ return imgEffects(imagePath, filters);
250
+ }
251
+ async colorsFilter(imagePath, filterColor, opacity) {
252
+ return applyColorFilters(imagePath, filterColor, opacity);
253
+ }
254
+ async colorAnalysis(imagePath) {
255
+ return detectColors(imagePath);
256
+ }
257
+ async colorsRemover(imagePath, colorToRemove) {
258
+ return removeColor(imagePath, colorToRemove);
259
+ }
260
+ async removeBackground(imageURL, apiKey) {
261
+ return bgRemoval(imageURL, apiKey);
262
+ }
263
+ async blend(layers, baseImageBuffer) {
264
+ try {
265
+ // Load the base image
266
+ const baseImage = await loadImage(baseImageBuffer);
267
+ const canvas = createCanvas(baseImage.width, baseImage.height);
268
+ const ctx = canvas.getContext('2d');
269
+ // Draw the base image
270
+ ctx.drawImage(baseImage, 0, 0);
271
+ // Process each layer
272
+ for (const layer of layers) {
273
+ const layerImage = await loadImage(layer.image);
274
+ ctx.globalAlpha = layer.opacity !== undefined ? layer.opacity : 1.0;
275
+ ctx.globalCompositeOperation = layer.blendMode;
276
+ ctx.drawImage(layerImage, layer.position?.x || 0, layer.position?.y || 0);
277
+ }
278
+ ctx.globalAlpha = 1.0;
279
+ ctx.globalCompositeOperation = 'source-over';
280
+ return canvas.toBuffer('image/png');
281
+ }
282
+ catch (error) {
283
+ console.error('Error creating layered composition:', error);
284
+ throw new Error('Failed to create layered composition');
285
+ }
286
+ }
287
+ async createChart(data, type) {
288
+ if (!data || Object.keys(data).length === 0) {
289
+ throw new Error('You need to provide datasets to create charts.');
290
+ }
291
+ if (!type || !type.chartNumber || !type.chartType) {
292
+ throw new Error('Type arguments are missing.');
293
+ }
294
+ const { chartType, chartNumber } = type;
295
+ switch (chartType.toLowerCase()) {
296
+ case 'bar':
297
+ switch (chartNumber) {
298
+ case 1:
299
+ return await verticalBarChart(data);
300
+ case 2:
301
+ throw new Error('Type 2 is still under development.');
302
+ default:
303
+ throw new Error('Invalid chart number for chart type "bar".');
304
+ }
305
+ case 'line':
306
+ switch (chartNumber) {
307
+ case 1:
308
+ return await lineChart(data);
309
+ case 2:
310
+ throw new Error('Type 2 is still under development.');
311
+ default:
312
+ throw new Error('Invalid chart number for chart type "line".');
313
+ }
314
+ case 'pie':
315
+ switch (chartNumber) {
316
+ case 1:
317
+ return await pieChart(data);
318
+ case 2:
319
+ throw new Error('Type 2 is still under development.');
320
+ default:
321
+ throw new Error('Invalid chart number for chart type "pie".');
322
+ }
323
+ default:
324
+ throw new Error(`Unsupported chart type "${chartType}".`);
325
+ }
326
+ }
327
+ async cropImage(options) {
328
+ try {
329
+ if (!options.imageSource)
330
+ throw new Error('The "imageSource" option is needed. Please provide the path to the image to crop.');
331
+ if (!options.coordinates || options.coordinates.length < 3)
332
+ throw new Error('The "coordinates" option is needed. Please provide coordinates to crop the image.');
333
+ if (options.crop === 'outer') {
334
+ return await cropOuter(options);
335
+ }
336
+ else if (options.crop === 'inner') {
337
+ return await cropInner(options);
338
+ }
339
+ else {
340
+ throw new Error('Invalid crop option. Please specify "inner" or "outer".');
341
+ }
342
+ }
343
+ catch (error) {
344
+ console.error('An error occurred:', error);
345
+ throw error;
346
+ }
347
+ }
348
+ async drawImage(ctx, image) {
349
+ const { source, x, y, width, height, rotation, borderRadius, stroke, shadow, isFilled, color, gradient, borderPosition, opacity } = image;
350
+ if (!source || typeof x !== 'number' || typeof y !== 'number' || typeof width !== 'number' || typeof height !== 'number') {
351
+ throw new Error('Invalid image properties');
352
+ }
353
+ let img = undefined;
354
+ try {
355
+ const shapeNames = ['circle', 'square', 'triangle', 'pentagon', 'hexagon', 'heptagon', 'octagon', 'star', 'kite'];
356
+ const isShape = shapeNames.includes(source.toLowerCase());
357
+ if (opacity) {
358
+ ctx.globalAlpha = opacity;
359
+ }
360
+ if (source.startsWith('http')) {
361
+ img = await loadImage(source);
362
+ }
363
+ else if (isShape) {
364
+ drawShape(ctx, { source, x, y, width, height, rotation, borderRadius, stroke, shadow, isFilled, color, gradient, borderPosition });
365
+ }
366
+ else {
367
+ const imagePath = path.join(process.cwd(), source);
368
+ try {
369
+ img = await loadImage(imagePath);
370
+ }
371
+ catch (e) {
372
+ throw new Error(`Error loading image: ${e.message}`);
373
+ }
374
+ }
375
+ if (img) {
376
+ ctx.save();
377
+ applyRotation(ctx, rotation || 0, x, y, width, height);
378
+ applyShadow(ctx, shadow, x, y, width, height);
379
+ imageRadius(ctx, img, x, y, width, height, borderRadius || 0, borderPosition);
380
+ applyStroke(ctx, stroke, x, y, width, height);
381
+ ctx.restore();
382
+ }
383
+ else if (!isShape) {
384
+ throw new Error('Invalid image source or shape name');
385
+ }
386
+ }
387
+ catch (error) {
388
+ throw new Error(error.message);
389
+ }
390
+ finally {
391
+ ctx.globalAlpha = 1.0;
392
+ }
393
+ }
394
+ async extractFrames(videoSource, options) {
395
+ const frames = [];
396
+ const frameDir = path.join(__dirname, 'frames');
397
+ if (!fs.existsSync(frameDir)) {
398
+ fs.mkdirSync(frameDir);
399
+ }
400
+ const videoPath = typeof videoSource === 'string' ? videoSource : path.join(frameDir, 'temp-video.mp4');
401
+ if (Buffer.isBuffer(videoSource)) {
402
+ fs.writeFileSync(videoPath, videoSource);
403
+ }
404
+ else if (videoSource.startsWith('http')) {
405
+ await axios({
406
+ method: 'get',
407
+ url: videoSource,
408
+ responseType: 'arraybuffer'
409
+ })
410
+ .then((response) => {
411
+ fs.writeFileSync(videoPath, response.data);
412
+ })
413
+ .catch(err => {
414
+ throw new Error(`Error downloading video: ${err.message}`);
415
+ });
416
+ }
417
+ else if (!fs.existsSync(videoPath)) {
418
+ throw new Error("Video file not found at specified path.");
419
+ }
420
+ function processVideoExtraction(videoPath, frames, options, resolve, reject) {
421
+ const outputFormat = options.outputFormat || 'jpg';
422
+ const outputFileTemplate = `frame-%03d.${outputFormat}`;
423
+ ffmpeg(videoPath)
424
+ .on('end', () => {
425
+ console.log('Frames extracted successfully.');
426
+ resolve(frames);
427
+ })
428
+ .on('error', (err) => {
429
+ console.error('Error extracting frames:', err.message);
430
+ reject(err);
431
+ })
432
+ .outputOptions([`-vf fps=1/${options.interval / 1000}`, `-q:v 2`]) // Set frame rate
433
+ .saveToFile(path.join(frameDir, outputFileTemplate)); // Save frames with a sequence number
434
+ ffmpeg.ffprobe(videoPath, (err, metadata) => {
435
+ if (err) {
436
+ return reject(err);
437
+ }
438
+ const duration = metadata?.format?.duration;
439
+ if (duration === undefined) {
440
+ return reject(new Error("Video duration not found in metadata."));
441
+ }
442
+ const totalFrames = Math.floor(duration * 1000 / options.interval);
443
+ for (let i = 0; i < totalFrames; i++) {
444
+ if (options.frameSelection && (i < (options.frameSelection.start || 0) || i > (options.frameSelection.end || totalFrames - 1))) {
445
+ continue;
446
+ }
447
+ frames.push({
448
+ source: path.join(frameDir, `frame-${String(i).padStart(3, '0')}.${outputFormat}`),
449
+ isRemote: false
450
+ });
451
+ }
452
+ });
453
+ }
454
+ return new Promise((resolve, reject) => {
455
+ processVideoExtraction(videoPath, frames, options, resolve, reject);
456
+ });
457
+ }
458
+ /**
459
+ * Sets a pattern on a specific area of a buffered image.
460
+ * @param {Buffer} buffer - The source image buffer.
461
+ * @param {Object} options - Options to customize the pattern.
462
+ * @returns {Promise<Buffer>} - The adjusted image buffer.
463
+ */
464
+ async setPatternBackground(buffer, options) {
465
+ // Load the buffered image onto a canvas
466
+ const img = await loadImage(buffer);
467
+ const canvas = createCanvas(img.width, img.height);
468
+ const ctx = canvas.getContext('2d');
469
+ ctx.drawImage(img, 0, 0);
470
+ // Set up the area to cover (default to full image if not specified)
471
+ const x = options.x || 0;
472
+ const y = options.y || 0;
473
+ const width = options.width || img.width;
474
+ const height = options.height || img.height;
475
+ ctx.save();
476
+ ctx.beginPath();
477
+ ctx.rect(x, y, width, height);
478
+ ctx.clip();
479
+ if (options.gradient) {
480
+ await this.fillWithGradient(ctx, width, height, options.gradient, x, y);
481
+ }
482
+ else if (options.backgroundColor) {
483
+ ctx.fillStyle = options.backgroundColor;
484
+ ctx.fillRect(x, y, width, height);
485
+ }
486
+ switch (options.type) {
487
+ case 'dots':
488
+ await this.drawDotsPattern(ctx, width, height, options, x, y);
489
+ break;
490
+ case 'stripes':
491
+ await this.drawStripesPattern(ctx, width, height, options, x, y);
492
+ break;
493
+ case 'grid':
494
+ await this.drawGridPattern(ctx, width, height, options, x, y);
495
+ break;
496
+ case 'checkerboard':
497
+ await this.drawCheckerboardPattern(ctx, width, height, options, x, y);
498
+ break;
499
+ case 'custom':
500
+ await this.drawCustomPattern(ctx, width, height, options, x, y);
501
+ break;
502
+ default:
503
+ throw new Error('Invalid pattern type specified.');
504
+ }
505
+ ctx.restore();
506
+ return canvas.toBuffer('image/png');
507
+ }
508
+ /**
509
+ * Fills the specified area with a gradient.
510
+ * @param ctx The rendering context of the canvas.
511
+ * @param width The width of the area to fill.
512
+ * @param height The height of the area to fill.
513
+ * @param gradient The gradient options.
514
+ * @param x The x offset of the area.
515
+ * @param y The y offset of the area.
516
+ */
517
+ async fillWithGradient(ctx, width, height, gradient, x = 0, y = 0) {
518
+ let grad;
519
+ if (gradient.type === 'linear') {
520
+ grad = ctx.createLinearGradient((gradient.startX || 0) + x, (gradient.startY || 0) + y, (gradient.endX || width) + x, (gradient.endY || height) + y);
521
+ }
522
+ else {
523
+ grad = ctx.createRadialGradient((gradient.startX || width / 2) + x, (gradient.startY || height / 2) + y, gradient.startRadius || 0, (gradient.endX || width / 2) + x, (gradient.endY || height / 2) + y, gradient.endRadius || Math.max(width, height));
524
+ }
525
+ gradient.colors.forEach(stop => {
526
+ grad.addColorStop(stop.stop, stop.color);
527
+ });
528
+ ctx.fillStyle = grad;
529
+ ctx.fillRect(x, y, width, height);
530
+ }
531
+ /**
532
+ * Draws a dots pattern in the specified area.
533
+ * @param ctx The rendering context of the canvas.
534
+ * @param width The width of the area.
535
+ * @param height The height of the area.
536
+ * @param options Options to customize the dot pattern.
537
+ * @param x The x offset of the area.
538
+ * @param y The y offset of the area.
539
+ */
540
+ async drawDotsPattern(ctx, width, height, options, x = 0, y = 0) {
541
+ const color = options.color || 'black';
542
+ const radius = options.size || 5;
543
+ const spacing = options.spacing || 10;
544
+ ctx.fillStyle = color;
545
+ for (let posY = y; posY < y + height; posY += spacing) {
546
+ for (let posX = x; posX < x + width; posX += spacing) {
547
+ ctx.beginPath();
548
+ ctx.arc(posX, posY, radius, 0, Math.PI * 2);
549
+ ctx.fill();
550
+ }
551
+ }
552
+ }
553
+ /**
554
+ * Draws a stripes pattern in the specified area.
555
+ * @param ctx The rendering context of the canvas.
556
+ * @param width The width of the area.
557
+ * @param height The height of the area.
558
+ * @param options Options to customize the stripes pattern.
559
+ * @param x The x offset of the area.
560
+ * @param y The y offset of the area.
561
+ */
562
+ async drawStripesPattern(ctx, width, height, options, x = 0, y = 0) {
563
+ const color = options.color || 'black';
564
+ const stripeWidth = options.size || 10;
565
+ const spacing = options.spacing || 20;
566
+ const angle = options.angle || 0;
567
+ ctx.fillStyle = color;
568
+ // Save the context to apply transformations and restore later
569
+ ctx.save();
570
+ // Translate and rotate the canvas
571
+ ctx.translate(x + width / 2, y + height / 2); // Move to the center of the area
572
+ ctx.rotate((angle * Math.PI) / 180); // Rotate by the specified angle
573
+ ctx.translate(-width / 2, -height / 2); // Translate back to top-left
574
+ // Draw the stripes pattern with the current transformations
575
+ for (let posX = 0; posX < width; posX += stripeWidth + spacing) {
576
+ ctx.fillRect(posX, 0, stripeWidth, height);
577
+ }
578
+ // Restore the original context to prevent transformations affecting other drawings
579
+ ctx.restore();
580
+ }
581
+ /**
582
+ * Draws a grid pattern in the specified area.
583
+ * @param ctx The rendering context of the canvas.
584
+ * @param width The width of the area.
585
+ * @param height The height of the area.
586
+ * @param options Options to customize the grid pattern.
587
+ * @param x The x offset of the area.
588
+ * @param y The y offset of the area.
589
+ */
590
+ async drawGridPattern(ctx, width, height, options, x = 0, y = 0) {
591
+ const color = options.color || 'black';
592
+ const size = options.size || 20;
593
+ ctx.strokeStyle = color;
594
+ ctx.lineWidth = 1;
595
+ for (let posX = x; posX <= x + width; posX += size) {
596
+ ctx.beginPath();
597
+ ctx.moveTo(posX, y);
598
+ ctx.lineTo(posX, y + height);
599
+ ctx.stroke();
600
+ }
601
+ for (let posY = y; posY <= y + height; posY += size) {
602
+ ctx.beginPath();
603
+ ctx.moveTo(x, posY);
604
+ ctx.lineTo(x + width, posY);
605
+ ctx.stroke();
606
+ }
607
+ }
608
+ /**
609
+ * Draws a checkerboard pattern in the specified area.
610
+ * @param ctx The rendering context of the canvas.
611
+ * @param width The width of the area.
612
+ * @param height The height of the area.
613
+ * @param options Options to customize the checkerboard pattern.
614
+ * @param x The x offset of the area.
615
+ * @param y The y offset of the area.
616
+ */
617
+ async drawCheckerboardPattern(ctx, width, height, options, x = 0, y = 0) {
618
+ const color1 = options.color || 'black';
619
+ const color2 = options.secondaryColor || 'white';
620
+ const size = options.size || 20;
621
+ for (let posY = y; posY < y + height; posY += size) {
622
+ for (let posX = x; posX < x + width; posX += size) {
623
+ ctx.fillStyle = (Math.floor(posX / size) + Math.floor(posY / size)) % 2 === 0 ? color1 : color2;
624
+ ctx.fillRect(posX, posY, size, size);
625
+ }
626
+ }
627
+ }
628
+ /**
629
+ * Draws a custom image pattern in the specified area.
630
+ * @param ctx The rendering context of the canvas.
631
+ * @param width The width of the area.
632
+ * @param height The height of the area.
633
+ * @param options Options to customize the custom pattern.
634
+ * @param x The x offset of the area.
635
+ * @param y The y offset of the area.
636
+ */
637
+ async drawCustomPattern(ctx, width, height, options, x = 0, y = 0) {
638
+ if (!options.customPatternImage) {
639
+ throw new Error('Custom pattern image path is required for custom patterns.');
640
+ }
641
+ const patternImage = await loadImage(options.customPatternImage);
642
+ const pattern = ctx.createPattern(patternImage, 'repeat');
643
+ ctx.fillStyle = pattern;
644
+ ctx.translate(x, y);
645
+ ctx.fillRect(0, 0, width, height);
646
+ ctx.resetTransform();
647
+ }
648
+ async animate(frames, defaultDuration, defaultWidth = 800, defaultHeight = 600, options) {
649
+ const buffers = [];
650
+ const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
651
+ if (options?.onStart)
652
+ options.onStart();
653
+ let encoder = null;
654
+ let gifStream = null;
655
+ if (options?.gif) {
656
+ if (!options.gifPath) {
657
+ throw new Error("GIF generation enabled but no gifPath provided.");
658
+ }
659
+ encoder = new GIFEncoder(defaultWidth, defaultHeight);
660
+ gifStream = fs.createWriteStream(options.gifPath);
661
+ encoder.createReadStream().pipe(gifStream);
662
+ encoder.start();
663
+ encoder.setRepeat(0);
664
+ encoder.setQuality(10);
665
+ }
666
+ for (let i = 0; i < frames.length; i++) {
667
+ const frame = frames[i];
668
+ const width = frame.width || defaultWidth;
669
+ const height = frame.height || defaultHeight;
670
+ const canvas = createCanvas(width, height);
671
+ const ctx = canvas.getContext('2d');
672
+ if (!isNode) {
673
+ canvas.width = width;
674
+ canvas.height = height;
675
+ document.body.appendChild(canvas);
676
+ }
677
+ ctx.clearRect(0, 0, width, height);
678
+ if (frame.transformations) {
679
+ const { scaleX = 1, scaleY = 1, rotate = 0, translateX = 0, translateY = 0 } = frame.transformations;
680
+ ctx.save();
681
+ ctx.translate(translateX, translateY);
682
+ ctx.rotate((rotate * Math.PI) / 180);
683
+ ctx.scale(scaleX, scaleY);
684
+ }
685
+ let fillStyle = null;
686
+ if (frame.gradient) {
687
+ const { type, startX, startY, endX, endY, startRadius, endRadius, colors } = frame.gradient;
688
+ let gradient = null;
689
+ if (type === 'linear') {
690
+ gradient = ctx.createLinearGradient(startX || 0, startY || 0, endX || width, endY || height);
691
+ }
692
+ else if (type === 'radial') {
693
+ gradient = ctx.createRadialGradient(startX || width / 2, startY || height / 2, startRadius || 0, endX || width / 2, endY || height / 2, endRadius || Math.max(width, height));
694
+ }
695
+ colors.forEach(colorStop => {
696
+ if (gradient)
697
+ gradient.addColorStop(colorStop.stop, colorStop.color);
698
+ });
699
+ fillStyle = gradient;
700
+ }
701
+ if (frame.pattern) {
702
+ const patternImage = await loadImage(frame.pattern.imagePath);
703
+ const pattern = ctx.createPattern(patternImage, frame.pattern.repeat || 'repeat');
704
+ fillStyle = pattern;
705
+ }
706
+ if (!fillStyle && frame.backgroundColor) {
707
+ fillStyle = frame.backgroundColor;
708
+ }
709
+ if (fillStyle) {
710
+ ctx.fillStyle = fillStyle;
711
+ ctx.fillRect(0, 0, width, height);
712
+ }
713
+ if (frame.imagePath) {
714
+ const image = await loadImage(frame.imagePath);
715
+ ctx.globalCompositeOperation = frame.blendMode || 'source-over';
716
+ ctx.drawImage(image, 0, 0, width, height);
717
+ }
718
+ if (frame.onDrawCustom) {
719
+ frame.onDrawCustom(ctx, canvas);
720
+ }
721
+ if (frame.transformations) {
722
+ ctx.restore();
723
+ }
724
+ const buffer = canvas.toBuffer('image/png');
725
+ buffers.push(buffer);
726
+ if (encoder) {
727
+ const frameDuration = frame.duration || defaultDuration;
728
+ encoder.setDelay(frameDuration);
729
+ encoder.addFrame(ctx);
730
+ }
731
+ if (options?.onFrame)
732
+ options.onFrame(i);
733
+ await new Promise(resolve => setTimeout(resolve, frame.duration || defaultDuration));
734
+ }
735
+ if (encoder) {
736
+ encoder.finish();
737
+ }
738
+ if (options?.onEnd)
739
+ options.onEnd();
740
+ return options?.gif ? undefined : buffers;
741
+ }
742
+ validHex(hexColor) {
743
+ const hexPattern = /^#[0-9a-fA-F]{6}$/;
744
+ if (!hexPattern.test(hexColor)) {
745
+ throw new Error("Invalid hexadecimal color format. It should be in the format '#RRGGBB'.");
746
+ }
747
+ return true;
748
+ }
749
+ async outPut(results) {
750
+ const formatType = this.format?.type || 'buffer';
751
+ switch (formatType) {
752
+ case 'buffer':
753
+ return results;
754
+ case 'url':
755
+ return await url(results);
756
+ case 'dataURL':
757
+ return dataURL(results);
758
+ case 'blob':
759
+ return blob(results);
760
+ case 'base64':
761
+ return base64(results);
762
+ case 'arraybuffer':
763
+ return arrayBuffer(results);
764
+ default:
765
+ throw new Error('Unsupported format');
766
+ }
767
+ }
768
+ }
769
+ //# sourceMappingURL=ApexPainter.js.map