@nice2dev/ui-graphics 1.0.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 (511) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/LICENSE +21 -0
  3. package/README.md +339 -0
  4. package/dist/cjs/animation/AnimatedPerson.js +153 -0
  5. package/dist/cjs/animation/AnimatedPerson.js.map +1 -0
  6. package/dist/cjs/animation/AnimationEditor.js +106 -0
  7. package/dist/cjs/animation/AnimationEditor.js.map +1 -0
  8. package/dist/cjs/animation/Audience.js +59 -0
  9. package/dist/cjs/animation/Audience.js.map +1 -0
  10. package/dist/cjs/animation/BodyRenderer.js +33 -0
  11. package/dist/cjs/animation/BodyRenderer.js.map +1 -0
  12. package/dist/cjs/animation/animationHelper.js +272 -0
  13. package/dist/cjs/animation/animationHelper.js.map +1 -0
  14. package/dist/cjs/animation/characterTypes.js +75 -0
  15. package/dist/cjs/animation/characterTypes.js.map +1 -0
  16. package/dist/cjs/animation/choreoDSL.js +190 -0
  17. package/dist/cjs/animation/choreoDSL.js.map +1 -0
  18. package/dist/cjs/animation/choreography.js +41 -0
  19. package/dist/cjs/animation/choreography.js.map +1 -0
  20. package/dist/cjs/animation/karaokeIntegration.js +98 -0
  21. package/dist/cjs/animation/karaokeIntegration.js.map +1 -0
  22. package/dist/cjs/animation/lottieExport.js +128 -0
  23. package/dist/cjs/animation/lottieExport.js.map +1 -0
  24. package/dist/cjs/animation/motionPath.js +196 -0
  25. package/dist/cjs/animation/motionPath.js.map +1 -0
  26. package/dist/cjs/animation/physics.js +201 -0
  27. package/dist/cjs/animation/physics.js.map +1 -0
  28. package/dist/cjs/animation/rig/RigPlayer.js +63 -0
  29. package/dist/cjs/animation/rig/RigPlayer.js.map +1 -0
  30. package/dist/cjs/animation/rig/RiggedBody.js +30 -0
  31. package/dist/cjs/animation/rig/RiggedBody.js.map +1 -0
  32. package/dist/cjs/animation/rig/choreoRigBridge.js +63 -0
  33. package/dist/cjs/animation/rig/choreoRigBridge.js.map +1 -0
  34. package/dist/cjs/animation/rig/ik.js +22 -0
  35. package/dist/cjs/animation/rig/ik.js.map +1 -0
  36. package/dist/cjs/animation/rig/poseOps.js +49 -0
  37. package/dist/cjs/animation/rig/poseOps.js.map +1 -0
  38. package/dist/cjs/animation/rig/presets.js +60 -0
  39. package/dist/cjs/animation/rig/presets.js.map +1 -0
  40. package/dist/cjs/animation/rig/rigMath.js +41 -0
  41. package/dist/cjs/animation/rig/rigMath.js.map +1 -0
  42. package/dist/cjs/animation/rig/rigTypes.js +44 -0
  43. package/dist/cjs/animation/rig/rigTypes.js.map +1 -0
  44. package/dist/cjs/animation/shapes/arms.js +15 -0
  45. package/dist/cjs/animation/shapes/arms.js.map +1 -0
  46. package/dist/cjs/animation/shapes/eyes.js +52 -0
  47. package/dist/cjs/animation/shapes/eyes.js.map +1 -0
  48. package/dist/cjs/animation/shapes/hair.js +55 -0
  49. package/dist/cjs/animation/shapes/hair.js.map +1 -0
  50. package/dist/cjs/animation/shapes/heads.js +62 -0
  51. package/dist/cjs/animation/shapes/heads.js.map +1 -0
  52. package/dist/cjs/animation/shapes/headwear.js +44 -0
  53. package/dist/cjs/animation/shapes/headwear.js.map +1 -0
  54. package/dist/cjs/animation/shapes/legs.js +15 -0
  55. package/dist/cjs/animation/shapes/legs.js.map +1 -0
  56. package/dist/cjs/animation/shapes/mouths.js +53 -0
  57. package/dist/cjs/animation/shapes/mouths.js.map +1 -0
  58. package/dist/cjs/animation/shapes/noses.js +31 -0
  59. package/dist/cjs/animation/shapes/noses.js.map +1 -0
  60. package/dist/cjs/animation/shapes/outfits.js +43 -0
  61. package/dist/cjs/animation/shapes/outfits.js.map +1 -0
  62. package/dist/cjs/animation/shapes/torsos.js +13 -0
  63. package/dist/cjs/animation/shapes/torsos.js.map +1 -0
  64. package/dist/cjs/animation/spineExport.js +132 -0
  65. package/dist/cjs/animation/spineExport.js.map +1 -0
  66. package/dist/cjs/core/LocalUI.js +54 -0
  67. package/dist/cjs/core/LocalUI.js.map +1 -0
  68. package/dist/cjs/core/collaboration.js +259 -0
  69. package/dist/cjs/core/collaboration.js.map +1 -0
  70. package/dist/cjs/core/colorBlindness.js +97 -0
  71. package/dist/cjs/core/colorBlindness.js.map +1 -0
  72. package/dist/cjs/core/dragDrop.js +168 -0
  73. package/dist/cjs/core/dragDrop.js.map +1 -0
  74. package/dist/cjs/core/fixes.js +185 -0
  75. package/dist/cjs/core/fixes.js.map +1 -0
  76. package/dist/cjs/core/gridGuides.js +245 -0
  77. package/dist/cjs/core/gridGuides.js.map +1 -0
  78. package/dist/cjs/core/historyVisual.js +124 -0
  79. package/dist/cjs/core/historyVisual.js.map +1 -0
  80. package/dist/cjs/core/i18n.js +16 -0
  81. package/dist/cjs/core/i18n.js.map +1 -0
  82. package/dist/cjs/core/integrations.js +261 -0
  83. package/dist/cjs/core/integrations.js.map +1 -0
  84. package/dist/cjs/core/minimap.js +142 -0
  85. package/dist/cjs/core/minimap.js.map +1 -0
  86. package/dist/cjs/core/plugins.js +129 -0
  87. package/dist/cjs/core/plugins.js.map +1 -0
  88. package/dist/cjs/core/rtl.js +102 -0
  89. package/dist/cjs/core/rtl.js.map +1 -0
  90. package/dist/cjs/core/shortcuts.js +205 -0
  91. package/dist/cjs/core/shortcuts.js.map +1 -0
  92. package/dist/cjs/core/theme.js +171 -0
  93. package/dist/cjs/core/theme.js.map +1 -0
  94. package/dist/cjs/font/NiceFontEditor.js +193 -0
  95. package/dist/cjs/font/NiceFontEditor.js.map +1 -0
  96. package/dist/cjs/game/GameAsset2dEditor.js +371 -0
  97. package/dist/cjs/game/GameAsset2dEditor.js.map +1 -0
  98. package/dist/cjs/game/GameAsset2dEditor.module.css.js +6 -0
  99. package/dist/cjs/game/GameAsset2dEditor.module.css.js.map +1 -0
  100. package/dist/cjs/game/gameAssetTypes.js +20 -0
  101. package/dist/cjs/game/gameAssetTypes.js.map +1 -0
  102. package/dist/cjs/game/gameAssetUtils.js +475 -0
  103. package/dist/cjs/game/gameAssetUtils.js.map +1 -0
  104. package/dist/cjs/game/useGameAssetEditor.js +761 -0
  105. package/dist/cjs/game/useGameAssetEditor.js.map +1 -0
  106. package/dist/cjs/icon/NiceIconEditor.js +249 -0
  107. package/dist/cjs/icon/NiceIconEditor.js.map +1 -0
  108. package/dist/cjs/index.js +264 -0
  109. package/dist/cjs/index.js.map +1 -0
  110. package/dist/cjs/nice2dev-ui/dist/index.js +32070 -0
  111. package/dist/cjs/nice2dev-ui/dist/index.js.map +1 -0
  112. package/dist/cjs/nice2dev-ui-graphics.css +1 -0
  113. package/dist/cjs/photo/FilterThumb.js +29 -0
  114. package/dist/cjs/photo/FilterThumb.js.map +1 -0
  115. package/dist/cjs/photo/PhotoEditor.js +20 -0
  116. package/dist/cjs/photo/PhotoEditor.js.map +1 -0
  117. package/dist/cjs/photo/PhotoEditor.module.css.js +6 -0
  118. package/dist/cjs/photo/PhotoEditor.module.css.js.map +1 -0
  119. package/dist/cjs/photo/PhotoEditorCanvas.js +59 -0
  120. package/dist/cjs/photo/PhotoEditorCanvas.js.map +1 -0
  121. package/dist/cjs/photo/PhotoEditorLeftPanel.js +174 -0
  122. package/dist/cjs/photo/PhotoEditorLeftPanel.js.map +1 -0
  123. package/dist/cjs/photo/PhotoEditorToolbar.js +15 -0
  124. package/dist/cjs/photo/PhotoEditorToolbar.js.map +1 -0
  125. package/dist/cjs/photo/photoEditorActions.js +80 -0
  126. package/dist/cjs/photo/photoEditorActions.js.map +1 -0
  127. package/dist/cjs/photo/photoEditorTypes.js +40 -0
  128. package/dist/cjs/photo/photoEditorTypes.js.map +1 -0
  129. package/dist/cjs/photo/photoFilters.js +880 -0
  130. package/dist/cjs/photo/photoFilters.js.map +1 -0
  131. package/dist/cjs/photo/photoOverlays.js +651 -0
  132. package/dist/cjs/photo/photoOverlays.js.map +1 -0
  133. package/dist/cjs/photo/photoSelection.js +547 -0
  134. package/dist/cjs/photo/photoSelection.js.map +1 -0
  135. package/dist/cjs/photo/usePhotoEditor.js +640 -0
  136. package/dist/cjs/photo/usePhotoEditor.js.map +1 -0
  137. package/dist/cjs/pixel/HSVPicker.js +173 -0
  138. package/dist/cjs/pixel/HSVPicker.js.map +1 -0
  139. package/dist/cjs/pixel/PixelEditor.js +28 -0
  140. package/dist/cjs/pixel/PixelEditor.js.map +1 -0
  141. package/dist/cjs/pixel/PixelEditor.module.css.js +6 -0
  142. package/dist/cjs/pixel/PixelEditor.module.css.js.map +1 -0
  143. package/dist/cjs/pixel/PixelEditorCanvas.js +15 -0
  144. package/dist/cjs/pixel/PixelEditorCanvas.js.map +1 -0
  145. package/dist/cjs/pixel/PixelEditorMenuBar.js +11 -0
  146. package/dist/cjs/pixel/PixelEditorMenuBar.js.map +1 -0
  147. package/dist/cjs/pixel/PixelEditorRightPanel.js +15 -0
  148. package/dist/cjs/pixel/PixelEditorRightPanel.js.map +1 -0
  149. package/dist/cjs/pixel/PixelEditorStatusBar.js +15 -0
  150. package/dist/cjs/pixel/PixelEditorStatusBar.js.map +1 -0
  151. package/dist/cjs/pixel/PixelEditorTimeline.js +11 -0
  152. package/dist/cjs/pixel/PixelEditorTimeline.js.map +1 -0
  153. package/dist/cjs/pixel/PixelEditorToolbar.js +16 -0
  154. package/dist/cjs/pixel/PixelEditorToolbar.js.map +1 -0
  155. package/dist/cjs/pixel/asepriteFormat.js +512 -0
  156. package/dist/cjs/pixel/asepriteFormat.js.map +1 -0
  157. package/dist/cjs/pixel/pixelEditorExports.js +471 -0
  158. package/dist/cjs/pixel/pixelEditorExports.js.map +1 -0
  159. package/dist/cjs/pixel/pixelEditorTypes.js +102 -0
  160. package/dist/cjs/pixel/pixelEditorTypes.js.map +1 -0
  161. package/dist/cjs/pixel/pixelEditorUtils.js +664 -0
  162. package/dist/cjs/pixel/pixelEditorUtils.js.map +1 -0
  163. package/dist/cjs/pixel/usePixelEditor.js +1112 -0
  164. package/dist/cjs/pixel/usePixelEditor.js.map +1 -0
  165. package/dist/cjs/texture/Nice3DTexturePainter.js +236 -0
  166. package/dist/cjs/texture/Nice3DTexturePainter.js.map +1 -0
  167. package/dist/cjs/ui/NiceUIDesigner.js +191 -0
  168. package/dist/cjs/ui/NiceUIDesigner.js.map +1 -0
  169. package/dist/cjs/vector/VectorEditor.js +31 -0
  170. package/dist/cjs/vector/VectorEditor.js.map +1 -0
  171. package/dist/cjs/vector/VectorEditor.module.css.js +6 -0
  172. package/dist/cjs/vector/VectorEditor.module.css.js.map +1 -0
  173. package/dist/cjs/vector/VectorEditorMenuBar.js +16 -0
  174. package/dist/cjs/vector/VectorEditorMenuBar.js.map +1 -0
  175. package/dist/cjs/vector/VectorEditorRightPanel.js +126 -0
  176. package/dist/cjs/vector/VectorEditorRightPanel.js.map +1 -0
  177. package/dist/cjs/vector/VectorEditorShapeRenderer.js +55 -0
  178. package/dist/cjs/vector/VectorEditorShapeRenderer.js.map +1 -0
  179. package/dist/cjs/vector/VectorEditorStatusBar.js +14 -0
  180. package/dist/cjs/vector/VectorEditorStatusBar.js.map +1 -0
  181. package/dist/cjs/vector/useVectorEditor.js +613 -0
  182. package/dist/cjs/vector/useVectorEditor.js.map +1 -0
  183. package/dist/cjs/vector/vectorBooleanOps.js +511 -0
  184. package/dist/cjs/vector/vectorBooleanOps.js.map +1 -0
  185. package/dist/cjs/vector/vectorEditorExport.js +159 -0
  186. package/dist/cjs/vector/vectorEditorExport.js.map +1 -0
  187. package/dist/cjs/vector/vectorEditorImport.js +150 -0
  188. package/dist/cjs/vector/vectorEditorImport.js.map +1 -0
  189. package/dist/cjs/vector/vectorEditorTypes.js +72 -0
  190. package/dist/cjs/vector/vectorEditorTypes.js.map +1 -0
  191. package/dist/cjs/vector/vectorGradients.js +201 -0
  192. package/dist/cjs/vector/vectorGradients.js.map +1 -0
  193. package/dist/esm/animation/AnimatedPerson.js +151 -0
  194. package/dist/esm/animation/AnimatedPerson.js.map +1 -0
  195. package/dist/esm/animation/AnimationEditor.js +104 -0
  196. package/dist/esm/animation/AnimationEditor.js.map +1 -0
  197. package/dist/esm/animation/Audience.js +57 -0
  198. package/dist/esm/animation/Audience.js.map +1 -0
  199. package/dist/esm/animation/BodyRenderer.js +28 -0
  200. package/dist/esm/animation/BodyRenderer.js.map +1 -0
  201. package/dist/esm/animation/animationHelper.js +268 -0
  202. package/dist/esm/animation/animationHelper.js.map +1 -0
  203. package/dist/esm/animation/characterTypes.js +70 -0
  204. package/dist/esm/animation/characterTypes.js.map +1 -0
  205. package/dist/esm/animation/choreoDSL.js +182 -0
  206. package/dist/esm/animation/choreoDSL.js.map +1 -0
  207. package/dist/esm/animation/choreography.js +36 -0
  208. package/dist/esm/animation/choreography.js.map +1 -0
  209. package/dist/esm/animation/karaokeIntegration.js +91 -0
  210. package/dist/esm/animation/karaokeIntegration.js.map +1 -0
  211. package/dist/esm/animation/lottieExport.js +123 -0
  212. package/dist/esm/animation/lottieExport.js.map +1 -0
  213. package/dist/esm/animation/motionPath.js +185 -0
  214. package/dist/esm/animation/motionPath.js.map +1 -0
  215. package/dist/esm/animation/physics.js +192 -0
  216. package/dist/esm/animation/physics.js.map +1 -0
  217. package/dist/esm/animation/rig/RigPlayer.js +61 -0
  218. package/dist/esm/animation/rig/RigPlayer.js.map +1 -0
  219. package/dist/esm/animation/rig/RiggedBody.js +28 -0
  220. package/dist/esm/animation/rig/RiggedBody.js.map +1 -0
  221. package/dist/esm/animation/rig/choreoRigBridge.js +60 -0
  222. package/dist/esm/animation/rig/choreoRigBridge.js.map +1 -0
  223. package/dist/esm/animation/rig/ik.js +20 -0
  224. package/dist/esm/animation/rig/ik.js.map +1 -0
  225. package/dist/esm/animation/rig/poseOps.js +45 -0
  226. package/dist/esm/animation/rig/poseOps.js.map +1 -0
  227. package/dist/esm/animation/rig/presets.js +53 -0
  228. package/dist/esm/animation/rig/presets.js.map +1 -0
  229. package/dist/esm/animation/rig/rigMath.js +37 -0
  230. package/dist/esm/animation/rig/rigMath.js.map +1 -0
  231. package/dist/esm/animation/rig/rigTypes.js +40 -0
  232. package/dist/esm/animation/rig/rigTypes.js.map +1 -0
  233. package/dist/esm/animation/shapes/arms.js +13 -0
  234. package/dist/esm/animation/shapes/arms.js.map +1 -0
  235. package/dist/esm/animation/shapes/eyes.js +45 -0
  236. package/dist/esm/animation/shapes/eyes.js.map +1 -0
  237. package/dist/esm/animation/shapes/hair.js +46 -0
  238. package/dist/esm/animation/shapes/hair.js.map +1 -0
  239. package/dist/esm/animation/shapes/heads.js +52 -0
  240. package/dist/esm/animation/shapes/heads.js.map +1 -0
  241. package/dist/esm/animation/shapes/headwear.js +36 -0
  242. package/dist/esm/animation/shapes/headwear.js.map +1 -0
  243. package/dist/esm/animation/shapes/legs.js +13 -0
  244. package/dist/esm/animation/shapes/legs.js.map +1 -0
  245. package/dist/esm/animation/shapes/mouths.js +45 -0
  246. package/dist/esm/animation/shapes/mouths.js.map +1 -0
  247. package/dist/esm/animation/shapes/noses.js +23 -0
  248. package/dist/esm/animation/shapes/noses.js.map +1 -0
  249. package/dist/esm/animation/shapes/outfits.js +37 -0
  250. package/dist/esm/animation/shapes/outfits.js.map +1 -0
  251. package/dist/esm/animation/shapes/torsos.js +11 -0
  252. package/dist/esm/animation/shapes/torsos.js.map +1 -0
  253. package/dist/esm/animation/spineExport.js +128 -0
  254. package/dist/esm/animation/spineExport.js.map +1 -0
  255. package/dist/esm/core/LocalUI.js +50 -0
  256. package/dist/esm/core/LocalUI.js.map +1 -0
  257. package/dist/esm/core/collaboration.js +252 -0
  258. package/dist/esm/core/collaboration.js.map +1 -0
  259. package/dist/esm/core/colorBlindness.js +90 -0
  260. package/dist/esm/core/colorBlindness.js.map +1 -0
  261. package/dist/esm/core/dragDrop.js +165 -0
  262. package/dist/esm/core/dragDrop.js.map +1 -0
  263. package/dist/esm/core/fixes.js +179 -0
  264. package/dist/esm/core/fixes.js.map +1 -0
  265. package/dist/esm/core/gridGuides.js +232 -0
  266. package/dist/esm/core/gridGuides.js.map +1 -0
  267. package/dist/esm/core/historyVisual.js +121 -0
  268. package/dist/esm/core/historyVisual.js.map +1 -0
  269. package/dist/esm/core/i18n.js +13 -0
  270. package/dist/esm/core/i18n.js.map +1 -0
  271. package/dist/esm/core/integrations.js +254 -0
  272. package/dist/esm/core/integrations.js.map +1 -0
  273. package/dist/esm/core/minimap.js +139 -0
  274. package/dist/esm/core/minimap.js.map +1 -0
  275. package/dist/esm/core/plugins.js +124 -0
  276. package/dist/esm/core/plugins.js.map +1 -0
  277. package/dist/esm/core/rtl.js +95 -0
  278. package/dist/esm/core/rtl.js.map +1 -0
  279. package/dist/esm/core/shortcuts.js +200 -0
  280. package/dist/esm/core/shortcuts.js.map +1 -0
  281. package/dist/esm/core/theme.js +162 -0
  282. package/dist/esm/core/theme.js.map +1 -0
  283. package/dist/esm/font/NiceFontEditor.js +189 -0
  284. package/dist/esm/font/NiceFontEditor.js.map +1 -0
  285. package/dist/esm/game/GameAsset2dEditor.js +369 -0
  286. package/dist/esm/game/GameAsset2dEditor.js.map +1 -0
  287. package/dist/esm/game/GameAsset2dEditor.module.css.js +4 -0
  288. package/dist/esm/game/GameAsset2dEditor.module.css.js.map +1 -0
  289. package/dist/esm/game/gameAssetTypes.js +18 -0
  290. package/dist/esm/game/gameAssetTypes.js.map +1 -0
  291. package/dist/esm/game/gameAssetUtils.js +456 -0
  292. package/dist/esm/game/gameAssetUtils.js.map +1 -0
  293. package/dist/esm/game/useGameAssetEditor.js +759 -0
  294. package/dist/esm/game/useGameAssetEditor.js.map +1 -0
  295. package/dist/esm/icon/NiceIconEditor.js +246 -0
  296. package/dist/esm/icon/NiceIconEditor.js.map +1 -0
  297. package/dist/esm/index.js +59 -0
  298. package/dist/esm/index.js.map +1 -0
  299. package/dist/esm/nice2dev-ui/dist/index.js +31720 -0
  300. package/dist/esm/nice2dev-ui/dist/index.js.map +1 -0
  301. package/dist/esm/nice2dev-ui-graphics.css +1 -0
  302. package/dist/esm/photo/FilterThumb.js +27 -0
  303. package/dist/esm/photo/FilterThumb.js.map +1 -0
  304. package/dist/esm/photo/PhotoEditor.js +18 -0
  305. package/dist/esm/photo/PhotoEditor.js.map +1 -0
  306. package/dist/esm/photo/PhotoEditor.module.css.js +4 -0
  307. package/dist/esm/photo/PhotoEditor.module.css.js.map +1 -0
  308. package/dist/esm/photo/PhotoEditorCanvas.js +57 -0
  309. package/dist/esm/photo/PhotoEditorCanvas.js.map +1 -0
  310. package/dist/esm/photo/PhotoEditorLeftPanel.js +172 -0
  311. package/dist/esm/photo/PhotoEditorLeftPanel.js.map +1 -0
  312. package/dist/esm/photo/PhotoEditorToolbar.js +13 -0
  313. package/dist/esm/photo/PhotoEditorToolbar.js.map +1 -0
  314. package/dist/esm/photo/photoEditorActions.js +75 -0
  315. package/dist/esm/photo/photoEditorActions.js.map +1 -0
  316. package/dist/esm/photo/photoEditorTypes.js +36 -0
  317. package/dist/esm/photo/photoEditorTypes.js.map +1 -0
  318. package/dist/esm/photo/photoFilters.js +871 -0
  319. package/dist/esm/photo/photoFilters.js.map +1 -0
  320. package/dist/esm/photo/photoOverlays.js +636 -0
  321. package/dist/esm/photo/photoOverlays.js.map +1 -0
  322. package/dist/esm/photo/photoSelection.js +535 -0
  323. package/dist/esm/photo/photoSelection.js.map +1 -0
  324. package/dist/esm/photo/usePhotoEditor.js +638 -0
  325. package/dist/esm/photo/usePhotoEditor.js.map +1 -0
  326. package/dist/esm/pixel/HSVPicker.js +171 -0
  327. package/dist/esm/pixel/HSVPicker.js.map +1 -0
  328. package/dist/esm/pixel/PixelEditor.js +26 -0
  329. package/dist/esm/pixel/PixelEditor.js.map +1 -0
  330. package/dist/esm/pixel/PixelEditor.module.css.js +4 -0
  331. package/dist/esm/pixel/PixelEditor.module.css.js.map +1 -0
  332. package/dist/esm/pixel/PixelEditorCanvas.js +13 -0
  333. package/dist/esm/pixel/PixelEditorCanvas.js.map +1 -0
  334. package/dist/esm/pixel/PixelEditorMenuBar.js +9 -0
  335. package/dist/esm/pixel/PixelEditorMenuBar.js.map +1 -0
  336. package/dist/esm/pixel/PixelEditorRightPanel.js +13 -0
  337. package/dist/esm/pixel/PixelEditorRightPanel.js.map +1 -0
  338. package/dist/esm/pixel/PixelEditorStatusBar.js +13 -0
  339. package/dist/esm/pixel/PixelEditorStatusBar.js.map +1 -0
  340. package/dist/esm/pixel/PixelEditorTimeline.js +9 -0
  341. package/dist/esm/pixel/PixelEditorTimeline.js.map +1 -0
  342. package/dist/esm/pixel/PixelEditorToolbar.js +14 -0
  343. package/dist/esm/pixel/PixelEditorToolbar.js.map +1 -0
  344. package/dist/esm/pixel/asepriteFormat.js +505 -0
  345. package/dist/esm/pixel/asepriteFormat.js.map +1 -0
  346. package/dist/esm/pixel/pixelEditorExports.js +461 -0
  347. package/dist/esm/pixel/pixelEditorExports.js.map +1 -0
  348. package/dist/esm/pixel/pixelEditorTypes.js +90 -0
  349. package/dist/esm/pixel/pixelEditorTypes.js.map +1 -0
  350. package/dist/esm/pixel/pixelEditorUtils.js +631 -0
  351. package/dist/esm/pixel/pixelEditorUtils.js.map +1 -0
  352. package/dist/esm/pixel/usePixelEditor.js +1110 -0
  353. package/dist/esm/pixel/usePixelEditor.js.map +1 -0
  354. package/dist/esm/texture/Nice3DTexturePainter.js +233 -0
  355. package/dist/esm/texture/Nice3DTexturePainter.js.map +1 -0
  356. package/dist/esm/ui/NiceUIDesigner.js +187 -0
  357. package/dist/esm/ui/NiceUIDesigner.js.map +1 -0
  358. package/dist/esm/vector/VectorEditor.js +29 -0
  359. package/dist/esm/vector/VectorEditor.js.map +1 -0
  360. package/dist/esm/vector/VectorEditor.module.css.js +4 -0
  361. package/dist/esm/vector/VectorEditor.module.css.js.map +1 -0
  362. package/dist/esm/vector/VectorEditorMenuBar.js +14 -0
  363. package/dist/esm/vector/VectorEditorMenuBar.js.map +1 -0
  364. package/dist/esm/vector/VectorEditorRightPanel.js +124 -0
  365. package/dist/esm/vector/VectorEditorRightPanel.js.map +1 -0
  366. package/dist/esm/vector/VectorEditorShapeRenderer.js +53 -0
  367. package/dist/esm/vector/VectorEditorShapeRenderer.js.map +1 -0
  368. package/dist/esm/vector/VectorEditorStatusBar.js +12 -0
  369. package/dist/esm/vector/VectorEditorStatusBar.js.map +1 -0
  370. package/dist/esm/vector/useVectorEditor.js +611 -0
  371. package/dist/esm/vector/useVectorEditor.js.map +1 -0
  372. package/dist/esm/vector/vectorBooleanOps.js +507 -0
  373. package/dist/esm/vector/vectorBooleanOps.js.map +1 -0
  374. package/dist/esm/vector/vectorEditorExport.js +152 -0
  375. package/dist/esm/vector/vectorEditorExport.js.map +1 -0
  376. package/dist/esm/vector/vectorEditorImport.js +148 -0
  377. package/dist/esm/vector/vectorEditorImport.js.map +1 -0
  378. package/dist/esm/vector/vectorEditorTypes.js +63 -0
  379. package/dist/esm/vector/vectorEditorTypes.js.map +1 -0
  380. package/dist/esm/vector/vectorGradients.js +193 -0
  381. package/dist/esm/vector/vectorGradients.js.map +1 -0
  382. package/dist/types/__benchmarks__/bench.d.ts +13 -0
  383. package/dist/types/__tests__/setup.d.ts +4 -0
  384. package/dist/types/animation/AnimatedPerson.d.ts +14 -0
  385. package/dist/types/animation/AnimationEditor.d.ts +20 -0
  386. package/dist/types/animation/Audience.d.ts +11 -0
  387. package/dist/types/animation/BodyRenderer.d.ts +12 -0
  388. package/dist/types/animation/animationHelper.d.ts +28 -0
  389. package/dist/types/animation/characterTypes.d.ts +37 -0
  390. package/dist/types/animation/choreoDSL.d.ts +88 -0
  391. package/dist/types/animation/choreography.d.ts +8 -0
  392. package/dist/types/animation/karaokeIntegration.d.ts +31 -0
  393. package/dist/types/animation/lottieExport.d.ts +77 -0
  394. package/dist/types/animation/motionPath.d.ts +60 -0
  395. package/dist/types/animation/physics.d.ts +73 -0
  396. package/dist/types/animation/rig/RigPlayer.d.ts +32 -0
  397. package/dist/types/animation/rig/RiggedBody.d.ts +19 -0
  398. package/dist/types/animation/rig/choreoRigBridge.d.ts +9 -0
  399. package/dist/types/animation/rig/ik.d.ts +8 -0
  400. package/dist/types/animation/rig/poseOps.d.ts +14 -0
  401. package/dist/types/animation/rig/presets.d.ts +13 -0
  402. package/dist/types/animation/rig/rigMath.d.ts +7 -0
  403. package/dist/types/animation/rig/rigTypes.d.ts +38 -0
  404. package/dist/types/animation/shapes/arms.d.ts +10 -0
  405. package/dist/types/animation/shapes/eyes.d.ts +17 -0
  406. package/dist/types/animation/shapes/hair.d.ts +17 -0
  407. package/dist/types/animation/shapes/heads.d.ts +18 -0
  408. package/dist/types/animation/shapes/headwear.d.ts +16 -0
  409. package/dist/types/animation/shapes/legs.d.ts +10 -0
  410. package/dist/types/animation/shapes/mouths.d.ts +17 -0
  411. package/dist/types/animation/shapes/noses.d.ts +17 -0
  412. package/dist/types/animation/shapes/outfits.d.ts +14 -0
  413. package/dist/types/animation/shapes/torsos.d.ts +9 -0
  414. package/dist/types/animation/spineExport.d.ts +66 -0
  415. package/dist/types/core/LocalUI.d.ts +21 -0
  416. package/dist/types/core/collaboration.d.ts +164 -0
  417. package/dist/types/core/colorBlindness.d.ts +24 -0
  418. package/dist/types/core/dragDrop.d.ts +46 -0
  419. package/dist/types/core/fixes.d.ts +80 -0
  420. package/dist/types/core/gridGuides.d.ts +70 -0
  421. package/dist/types/core/historyVisual.d.ts +915 -0
  422. package/dist/types/core/i18n.d.ts +27 -0
  423. package/dist/types/core/integrations.d.ts +103 -0
  424. package/dist/types/core/minimap.d.ts +49 -0
  425. package/dist/types/core/plugins.d.ts +111 -0
  426. package/dist/types/core/rtl.d.ts +32 -0
  427. package/dist/types/core/shortcuts.d.ts +150 -0
  428. package/dist/types/core/theme.d.ts +78 -0
  429. package/dist/types/core/useGamepad.d.ts +64 -0
  430. package/dist/types/core/usePointerPressure.d.ts +88 -0
  431. package/dist/types/font/NiceFontEditor.d.ts +62 -0
  432. package/dist/types/game/AnimationPreviewPlayer.d.ts +29 -0
  433. package/dist/types/game/CollisionEditor.d.ts +101 -0
  434. package/dist/types/game/GameAsset2dEditor.d.ts +17 -0
  435. package/dist/types/game/GameAssetExportPanel.d.ts +20 -0
  436. package/dist/types/game/IsometricEditor.d.ts +22 -0
  437. package/dist/types/game/IsometricTilePanel.d.ts +18 -0
  438. package/dist/types/game/gameAssetExport.d.ts +160 -0
  439. package/dist/types/game/gameAssetTypes.d.ts +238 -0
  440. package/dist/types/game/gameAssetUtils.d.ts +23 -0
  441. package/dist/types/game/index.d.ts +8 -0
  442. package/dist/types/game/isometricTiles.d.ts +250 -0
  443. package/dist/types/game/useAnimationPreview.d.ts +63 -0
  444. package/dist/types/game/useCollisionEditor.d.ts +96 -0
  445. package/dist/types/game/useGameAssetEditor.d.ts +79 -0
  446. package/dist/types/game/useGameAssetExport.d.ts +82 -0
  447. package/dist/types/icon/NiceIconEditor.d.ts +79 -0
  448. package/dist/types/index.d.ts +85 -0
  449. package/dist/types/photo/BatchProcessingPanel.d.ts +13 -0
  450. package/dist/types/photo/FaceDetectionPanel.d.ts +18 -0
  451. package/dist/types/photo/FilterThumb.d.ts +14 -0
  452. package/dist/types/photo/PerspectiveCorrectionPanel.d.ts +17 -0
  453. package/dist/types/photo/PhotoEditor.d.ts +2 -0
  454. package/dist/types/photo/PhotoEditorCanvas.d.ts +14 -0
  455. package/dist/types/photo/PhotoEditorLeftPanel.d.ts +13 -0
  456. package/dist/types/photo/PhotoEditorToolbar.d.ts +13 -0
  457. package/dist/types/photo/RawFilePanel.d.ts +14 -0
  458. package/dist/types/photo/StyleTransferPanel.d.ts +15 -0
  459. package/dist/types/photo/aiStyleTransfer.d.ts +58 -0
  460. package/dist/types/photo/batchProcessing.d.ts +95 -0
  461. package/dist/types/photo/faceDetection.d.ts +103 -0
  462. package/dist/types/photo/index.d.ts +17 -0
  463. package/dist/types/photo/perspectiveCorrection.d.ts +134 -0
  464. package/dist/types/photo/photoEditorActions.d.ts +40 -0
  465. package/dist/types/photo/photoEditorTypes.d.ts +34 -0
  466. package/dist/types/photo/photoFilters.d.ts +55 -0
  467. package/dist/types/photo/photoOverlays.d.ts +126 -0
  468. package/dist/types/photo/photoSelection.d.ts +56 -0
  469. package/dist/types/photo/rawFileSupport.d.ts +124 -0
  470. package/dist/types/photo/usePhotoEditor.d.ts +123 -0
  471. package/dist/types/pixel/HSVPicker.d.ts +11 -0
  472. package/dist/types/pixel/PaletteExtractorPanel.d.ts +16 -0
  473. package/dist/types/pixel/PixelEditor.d.ts +17 -0
  474. package/dist/types/pixel/PixelEditorCanvas.d.ts +10 -0
  475. package/dist/types/pixel/PixelEditorMenuBar.d.ts +11 -0
  476. package/dist/types/pixel/PixelEditorRightPanel.d.ts +11 -0
  477. package/dist/types/pixel/PixelEditorStatusBar.d.ts +11 -0
  478. package/dist/types/pixel/PixelEditorTimeline.d.ts +11 -0
  479. package/dist/types/pixel/PixelEditorToolbar.d.ts +11 -0
  480. package/dist/types/pixel/TileMapPanel.d.ts +14 -0
  481. package/dist/types/pixel/asepriteFormat.d.ts +62 -0
  482. package/dist/types/pixel/paletteExtractor.d.ts +73 -0
  483. package/dist/types/pixel/pixelEditorExports.d.ts +31 -0
  484. package/dist/types/pixel/pixelEditorTypes.d.ts +51 -0
  485. package/dist/types/pixel/pixelEditorUtils.d.ts +136 -0
  486. package/dist/types/pixel/tileMapMode.d.ts +122 -0
  487. package/dist/types/pixel/usePixelEditor.d.ts +114 -0
  488. package/dist/types/texture/Nice3DTexturePainter.d.ts +55 -0
  489. package/dist/types/ui/NiceUIDesigner.d.ts +43 -0
  490. package/dist/types/vector/PathSimplificationPanel.d.ts +15 -0
  491. package/dist/types/vector/PdfExportPanel.d.ts +20 -0
  492. package/dist/types/vector/TextOnPathPanel.d.ts +26 -0
  493. package/dist/types/vector/VectorEditor.d.ts +32 -0
  494. package/dist/types/vector/VectorEditorMenuBar.d.ts +8 -0
  495. package/dist/types/vector/VectorEditorRightPanel.d.ts +7 -0
  496. package/dist/types/vector/VectorEditorShapeRenderer.d.ts +9 -0
  497. package/dist/types/vector/VectorEditorStatusBar.d.ts +9 -0
  498. package/dist/types/vector/VectorFilterPanel.d.ts +19 -0
  499. package/dist/types/vector/VectorPatternPanel.d.ts +21 -0
  500. package/dist/types/vector/pathSimplification.d.ts +135 -0
  501. package/dist/types/vector/pdfExport.d.ts +65 -0
  502. package/dist/types/vector/textOnPath.d.ts +145 -0
  503. package/dist/types/vector/useVectorEditor.d.ts +90 -0
  504. package/dist/types/vector/vectorBooleanOps.d.ts +22 -0
  505. package/dist/types/vector/vectorEditorExport.d.ts +8 -0
  506. package/dist/types/vector/vectorEditorImport.d.ts +7 -0
  507. package/dist/types/vector/vectorEditorTypes.d.ts +47 -0
  508. package/dist/types/vector/vectorGradients.d.ts +64 -0
  509. package/dist/types/vector/vectorPatternFills.d.ts +101 -0
  510. package/dist/types/vector/vectorSvgFilters.d.ts +134 -0
  511. package/package.json +93 -0
@@ -0,0 +1,1112 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var asepriteFormat = require('./asepriteFormat.js');
5
+ var pixelEditorUtils = require('./pixelEditorUtils.js');
6
+ var pixelEditorTypes = require('./pixelEditorTypes.js');
7
+ var pixelEditorExports = require('./pixelEditorExports.js');
8
+
9
+ /**
10
+ * usePixelEditor — custom hook encapsulating ALL state, refs, callbacks,
11
+ * side-effects and memos for the PixelEditor component.
12
+ */
13
+ const log = { warn: console.warn, error: console.error, info: console.info, debug: console.debug };
14
+ /* ═══════════════════════════════════════════
15
+ Hook
16
+ ═══════════════════════════════════════════ */
17
+ function usePixelEditor({ initialWidth = 64, initialHeight = 64, onSaveToLibrary, }) {
18
+ /* ── state ── */
19
+ const [dw, setDw] = React.useState(initialWidth);
20
+ const [dh, setDh] = React.useState(initialHeight);
21
+ const [layers, setLayers] = React.useState(() => [
22
+ { id: pixelEditorTypes.lid(), name: "Background", visible: true, opacity: 255, locked: false, blendMode: "normal" },
23
+ ]);
24
+ const [aLi, setALi] = React.useState(0);
25
+ const [fc, setFc] = React.useState(1);
26
+ const [afi, setAfi] = React.useState(0);
27
+ const [fDur, setFDur] = React.useState([100]);
28
+ const [tool, setTool] = React.useState("pencil");
29
+ const [col1, setCol1] = React.useState("#000000");
30
+ const [col2, setCol2] = React.useState("#ffffff");
31
+ const [brush, setBrush] = React.useState({ ...pixelEditorUtils.DEFAULT_BRUSH });
32
+ const [zoom, setZoom] = React.useState(8);
33
+ const [px, setPx] = React.useState(0);
34
+ const [py, setPy] = React.useState(0);
35
+ const [grid, setGrid] = React.useState(true);
36
+ const [onion, setOnion] = React.useState(false);
37
+ const [fps, setFps] = React.useState(8);
38
+ const [playing, setPlaying] = React.useState(false);
39
+ const [pal, setPal] = React.useState(pixelEditorTypes.DEFAULT_PALETTE);
40
+ const [cursor, setCursor] = React.useState(null);
41
+ const [dlgNew, setDlgNew] = React.useState(false);
42
+ const [nw, setNw] = React.useState(64);
43
+ const [nh, setNh] = React.useState(64);
44
+ const [sel, setSel] = React.useState(null);
45
+ const [tick, setTick] = React.useState(0);
46
+ const [symmetry, setSymmetry] = React.useState("none");
47
+ const [shapeFilled, setShapeFilled] = React.useState(false);
48
+ const [pressure, setPressure] = React.useState(0.5);
49
+ const [showHSV, setShowHSV] = React.useState(false);
50
+ const [editingLayerName, setEditingLayerName] = React.useState(null);
51
+ /* ── refs ── */
52
+ const cvRef = React.useRef(null);
53
+ const boxRef = React.useRef(null);
54
+ const cels = React.useRef(new Map());
55
+ const hist = React.useRef([]);
56
+ const hIdx = React.useRef(-1);
57
+ const drawing = React.useRef(false);
58
+ const lastPx = React.useRef(null);
59
+ const tStart = React.useRef(null);
60
+ const preview = React.useRef(null);
61
+ const panning = React.useRef(false);
62
+ const panSt = React.useRef({ mx: 0, my: 0, px: 0, py: 0 });
63
+ const fInp = React.useRef(null);
64
+ const btn = React.useRef(0);
65
+ const curPressure = React.useRef(0.5);
66
+ const clipboard = React.useRef(null);
67
+ const brushDist = React.useRef(0);
68
+ /* ── cel access ── */
69
+ const getCel = React.useCallback((f, l) => {
70
+ const k = pixelEditorTypes.celKey(f, l);
71
+ let c = cels.current.get(k);
72
+ if (!c) {
73
+ c = pixelEditorUtils.createBlankImageData(dw, dh);
74
+ cels.current.set(k, c);
75
+ }
76
+ return c;
77
+ }, [dw, dh]);
78
+ /* ── coordinate transform ── */
79
+ const scr2art = React.useCallback((cx, cy) => {
80
+ var _a;
81
+ const r = (_a = boxRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
82
+ if (!r)
83
+ return { x: 0, y: 0 };
84
+ return {
85
+ x: Math.floor((cx - r.left - px - r.width / 2) / zoom + dw / 2),
86
+ y: Math.floor((cy - r.top - py - r.height / 2) / zoom + dh / 2),
87
+ };
88
+ }, [px, py, zoom, dw, dh]);
89
+ /* ── history ── */
90
+ const snap = React.useCallback((desc) => {
91
+ const m = new Map();
92
+ cels.current.forEach((v, k) => m.set(k, pixelEditorUtils.cloneImageData(v)));
93
+ hist.current = hist.current.slice(0, hIdx.current + 1);
94
+ hist.current.push({
95
+ desc,
96
+ cels: m,
97
+ layers: JSON.parse(JSON.stringify(layers)),
98
+ frameCount: fc,
99
+ });
100
+ if (hist.current.length > 50)
101
+ hist.current.shift();
102
+ hIdx.current = hist.current.length - 1;
103
+ }, [layers, fc]);
104
+ const restoreEntry = React.useCallback((e) => {
105
+ cels.current = new Map();
106
+ e.cels.forEach((v, k) => cels.current.set(k, pixelEditorUtils.cloneImageData(v)));
107
+ setLayers(JSON.parse(JSON.stringify(e.layers)));
108
+ setFc(e.frameCount);
109
+ setTick((t) => t + 1);
110
+ }, []);
111
+ const undo = React.useCallback(() => {
112
+ if (hIdx.current <= 0)
113
+ return;
114
+ hIdx.current--;
115
+ restoreEntry(hist.current[hIdx.current]);
116
+ }, [restoreEntry]);
117
+ const redo = React.useCallback(() => {
118
+ if (hIdx.current >= hist.current.length - 1)
119
+ return;
120
+ hIdx.current++;
121
+ restoreEntry(hist.current[hIdx.current]);
122
+ }, [restoreEntry]);
123
+ /* Push initial snapshot so first undo works */
124
+ React.useEffect(() => {
125
+ if (hist.current.length === 0) {
126
+ snap("initial");
127
+ }
128
+ }, [snap]);
129
+ /* ── composite a frame ── */
130
+ const compFrame = React.useCallback((fi) => {
131
+ const cv = new OffscreenCanvas(dw, dh);
132
+ const ctx = cv.getContext("2d");
133
+ for (let li = 0; li < layers.length; li++) {
134
+ if (!layers[li].visible)
135
+ continue;
136
+ const c = cels.current.get(pixelEditorTypes.celKey(fi, li));
137
+ if (!c)
138
+ continue;
139
+ const t = new OffscreenCanvas(dw, dh);
140
+ t.getContext("2d").putImageData(c, 0, 0);
141
+ ctx.globalAlpha = layers[li].opacity / 255;
142
+ const bm = layers[li].blendMode;
143
+ if (bm !== "normal") {
144
+ ctx.globalCompositeOperation = bm;
145
+ }
146
+ else {
147
+ ctx.globalCompositeOperation = "source-over";
148
+ }
149
+ ctx.drawImage(t, 0, 0);
150
+ }
151
+ ctx.globalCompositeOperation = "source-over";
152
+ return ctx.getImageData(0, 0, dw, dh);
153
+ }, [dw, dh, layers]);
154
+ /* ── rendering ── */
155
+ const render = React.useCallback(() => {
156
+ const canvas = cvRef.current;
157
+ const box = boxRef.current;
158
+ if (!canvas || !box)
159
+ return;
160
+ const cw = box.clientWidth;
161
+ const ch = box.clientHeight;
162
+ if (canvas.width !== cw || canvas.height !== ch) {
163
+ canvas.width = cw;
164
+ canvas.height = ch;
165
+ }
166
+ const ctx = canvas.getContext("2d");
167
+ ctx.clearRect(0, 0, cw, ch);
168
+ ctx.imageSmoothingEnabled = false;
169
+ ctx.save();
170
+ ctx.translate(cw / 2 + px, ch / 2 + py);
171
+ ctx.scale(zoom, zoom);
172
+ ctx.translate(-dw / 2, -dh / 2);
173
+ // checkerboard
174
+ for (let y = 0; y < dh; y++)
175
+ for (let x = 0; x < dw; x++) {
176
+ ctx.fillStyle = (x + y) % 2 === 0 ? "#3c3c3c" : "#2c2c2c";
177
+ ctx.fillRect(x, y, 1, 1);
178
+ }
179
+ // onion skin (prev frame)
180
+ if (onion && afi > 0) {
181
+ const oc = new OffscreenCanvas(dw, dh);
182
+ const ox = oc.getContext("2d");
183
+ for (let li = 0; li < layers.length; li++) {
184
+ if (!layers[li].visible)
185
+ continue;
186
+ const c = cels.current.get(pixelEditorTypes.celKey(afi - 1, li));
187
+ if (!c)
188
+ continue;
189
+ const t = new OffscreenCanvas(dw, dh);
190
+ t.getContext("2d").putImageData(c, 0, 0);
191
+ ox.globalAlpha = (layers[li].opacity / 255) * 0.25;
192
+ ox.drawImage(t, 0, 0);
193
+ }
194
+ ctx.drawImage(oc, 0, 0);
195
+ }
196
+ // current frame composite
197
+ const comp = new OffscreenCanvas(dw, dh);
198
+ const cc = comp.getContext("2d");
199
+ for (let li = 0; li < layers.length; li++) {
200
+ if (!layers[li].visible)
201
+ continue;
202
+ const c = cels.current.get(pixelEditorTypes.celKey(afi, li));
203
+ if (!c)
204
+ continue;
205
+ const t = new OffscreenCanvas(dw, dh);
206
+ t.getContext("2d").putImageData(c, 0, 0);
207
+ cc.globalAlpha = layers[li].opacity / 255;
208
+ const bm = layers[li].blendMode;
209
+ if (bm !== "normal") {
210
+ cc.globalCompositeOperation = bm;
211
+ }
212
+ else {
213
+ cc.globalCompositeOperation = "source-over";
214
+ }
215
+ cc.drawImage(t, 0, 0);
216
+ }
217
+ cc.globalCompositeOperation = "source-over";
218
+ ctx.drawImage(comp, 0, 0);
219
+ // tool preview (line / rect / ellipse while dragging)
220
+ if (preview.current && drawing.current) {
221
+ const pv = preview.current;
222
+ const clr = btn.current === 2 ? pixelEditorTypes.hex2t(col2) : pixelEditorTypes.hex2t(col1);
223
+ const pvData = pixelEditorUtils.cloneImageData(getCel(afi, aLi));
224
+ if (tool === "line") {
225
+ pixelEditorUtils.bresenhamLine(pv.fr.x, pv.fr.y, pv.to.x, pv.to.y, (bx, by) => {
226
+ if (pixelEditorTypes.inB(bx, by, dw, dh))
227
+ pixelEditorUtils.setPixel(pvData, bx, by, clr);
228
+ });
229
+ }
230
+ else if (tool === "rect") {
231
+ const x1 = Math.min(pv.fr.x, pv.to.x), y1 = Math.min(pv.fr.y, pv.to.y);
232
+ const x2 = Math.max(pv.fr.x, pv.to.x), y2 = Math.max(pv.fr.y, pv.to.y);
233
+ if (shapeFilled) {
234
+ for (let y = y1; y <= y2; y++)
235
+ for (let x = x1; x <= x2; x++)
236
+ if (pixelEditorTypes.inB(x, y, dw, dh))
237
+ pixelEditorUtils.setPixel(pvData, x, y, clr);
238
+ }
239
+ else {
240
+ for (let x = x1; x <= x2; x++) {
241
+ if (pixelEditorTypes.inB(x, y1, dw, dh))
242
+ pixelEditorUtils.setPixel(pvData, x, y1, clr);
243
+ if (pixelEditorTypes.inB(x, y2, dw, dh))
244
+ pixelEditorUtils.setPixel(pvData, x, y2, clr);
245
+ }
246
+ for (let y = y1 + 1; y < y2; y++) {
247
+ if (pixelEditorTypes.inB(x1, y, dw, dh))
248
+ pixelEditorUtils.setPixel(pvData, x1, y, clr);
249
+ if (pixelEditorTypes.inB(x2, y, dw, dh))
250
+ pixelEditorUtils.setPixel(pvData, x2, y, clr);
251
+ }
252
+ }
253
+ }
254
+ else if (tool === "ellipse") {
255
+ const cx2 = (pv.fr.x + pv.to.x) / 2, cy2 = (pv.fr.y + pv.to.y) / 2;
256
+ const rx = Math.abs(pv.to.x - pv.fr.x) / 2, ry = Math.abs(pv.to.y - pv.fr.y) / 2;
257
+ pixelEditorTypes.plotEllipse(pvData, cx2, cy2, rx, ry, clr, dw, dh, shapeFilled);
258
+ }
259
+ else if (tool === "gradient") {
260
+ const c2 = btn.current === 2 ? pixelEditorTypes.hex2t(col1) : pixelEditorTypes.hex2t(col2);
261
+ pixelEditorUtils.drawGradient(pvData, pv.fr.x, pv.fr.y, pv.to.x, pv.to.y, clr, c2, sel);
262
+ }
263
+ const pcv = new OffscreenCanvas(dw, dh);
264
+ pcv.getContext("2d").putImageData(pvData, 0, 0);
265
+ ctx.globalAlpha = layers[aLi].opacity / 255;
266
+ ctx.drawImage(pcv, 0, 0);
267
+ ctx.globalAlpha = 1;
268
+ }
269
+ // symmetry guides
270
+ if (symmetry !== "none") {
271
+ ctx.strokeStyle = "rgba(255,100,100,0.3)";
272
+ ctx.lineWidth = 1 / zoom;
273
+ ctx.setLineDash([4 / zoom, 4 / zoom]);
274
+ if (symmetry === "h" || symmetry === "both") {
275
+ ctx.beginPath();
276
+ ctx.moveTo(dw / 2, 0);
277
+ ctx.lineTo(dw / 2, dh);
278
+ ctx.stroke();
279
+ }
280
+ if (symmetry === "v" || symmetry === "both") {
281
+ ctx.beginPath();
282
+ ctx.moveTo(0, dh / 2);
283
+ ctx.lineTo(dw, dh / 2);
284
+ ctx.stroke();
285
+ }
286
+ if (symmetry === "radial4") {
287
+ ctx.beginPath();
288
+ ctx.moveTo(dw / 2, 0);
289
+ ctx.lineTo(dw / 2, dh);
290
+ ctx.moveTo(0, dh / 2);
291
+ ctx.lineTo(dw, dh / 2);
292
+ ctx.stroke();
293
+ }
294
+ ctx.setLineDash([]);
295
+ }
296
+ // selection marching ants
297
+ if (sel) {
298
+ ctx.strokeStyle = "rgba(255,255,255,0.8)";
299
+ ctx.lineWidth = 1 / zoom;
300
+ ctx.setLineDash([4 / zoom, 4 / zoom]);
301
+ ctx.strokeRect(sel.x, sel.y, sel.w, sel.h);
302
+ ctx.setLineDash([]);
303
+ }
304
+ // grid
305
+ if (grid && zoom >= 4) {
306
+ ctx.strokeStyle = "rgba(255,255,255,0.07)";
307
+ ctx.lineWidth = 1 / zoom;
308
+ for (let x = 0; x <= dw; x++) {
309
+ ctx.beginPath();
310
+ ctx.moveTo(x, 0);
311
+ ctx.lineTo(x, dh);
312
+ ctx.stroke();
313
+ }
314
+ for (let y = 0; y <= dh; y++) {
315
+ ctx.beginPath();
316
+ ctx.moveTo(0, y);
317
+ ctx.lineTo(dw, y);
318
+ ctx.stroke();
319
+ }
320
+ }
321
+ // border
322
+ ctx.strokeStyle = "rgba(80,100,200,0.4)";
323
+ ctx.lineWidth = 1 / zoom;
324
+ ctx.strokeRect(-0.5 / zoom, -0.5 / zoom, dw + 1 / zoom, dh + 1 / zoom);
325
+ // brush cursor preview
326
+ if (cursor && pixelEditorTypes.inB(cursor.x, cursor.y, dw, dh) && (tool === "pencil" || tool === "eraser" || tool === "dither")) {
327
+ const sz = brush.pressureSize ? Math.max(1, Math.round(brush.size * curPressure.current)) : brush.size;
328
+ const half = Math.floor(sz / 2);
329
+ ctx.strokeStyle = "rgba(255,255,255,0.5)";
330
+ ctx.lineWidth = 1 / zoom;
331
+ if (brush.shape === "circle") {
332
+ ctx.beginPath();
333
+ ctx.arc(cursor.x + 0.5, cursor.y + 0.5, half + 0.5, 0, Math.PI * 2);
334
+ ctx.stroke();
335
+ }
336
+ else {
337
+ ctx.strokeRect(cursor.x - half, cursor.y - half, sz, sz);
338
+ }
339
+ }
340
+ ctx.restore();
341
+ }, [dw, dh, zoom, px, py, layers, afi, aLi, grid, onion, tool, col1, col2, sel, getCel, symmetry, shapeFilled, brush, cursor]);
342
+ /* ── brush drawing with symmetry ── */
343
+ const applyBrushAt = React.useCallback((x, y, erase, pr) => {
344
+ const cel = getCel(afi, aLi);
345
+ const clr = erase ? [0, 0, 0, 0] : pixelEditorTypes.hex2t(btn.current === 2 ? col2 : col1);
346
+ const pts = pixelEditorUtils.getSymmetryPoints(x, y, dw, dh, symmetry);
347
+ for (const pt of pts) {
348
+ if (tool === "dither") {
349
+ pixelEditorUtils.applyDitherStamp(cel, pt.x, pt.y, clr, brush.size, pr);
350
+ }
351
+ else {
352
+ pixelEditorUtils.applyBrushStamp(cel, pt.x, pt.y, clr, brush, pr, erase);
353
+ }
354
+ }
355
+ }, [getCel, afi, aLi, col1, col2, brush, dw, dh, symmetry, tool]);
356
+ /* ── pointer events (pressure-aware) ── */
357
+ const onDown = React.useCallback((e) => {
358
+ var _a, _b, _c;
359
+ e.preventDefault();
360
+ (_b = (_a = e.target).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, e.pointerId);
361
+ btn.current = e.button;
362
+ const pr = e.pressure > 0 ? e.pressure : 0.5;
363
+ curPressure.current = pr;
364
+ setPressure(pr);
365
+ if (e.button === 1) {
366
+ panning.current = true;
367
+ panSt.current = { mx: e.clientX, my: e.clientY, px, py };
368
+ return;
369
+ }
370
+ const p = scr2art(e.clientX, e.clientY);
371
+ setCursor(p);
372
+ if ((_c = layers[aLi]) === null || _c === void 0 ? void 0 : _c.locked)
373
+ return;
374
+ switch (tool) {
375
+ case "pencil":
376
+ case "eraser":
377
+ case "dither":
378
+ snap(tool === "pencil" ? "Draw" : tool === "eraser" ? "Erase" : "Dither");
379
+ drawing.current = true;
380
+ lastPx.current = p;
381
+ brushDist.current = 0;
382
+ applyBrushAt(p.x, p.y, tool === "eraser", pr);
383
+ setTick((t) => t + 1);
384
+ break;
385
+ case "fill":
386
+ if (pixelEditorTypes.inB(p.x, p.y, dw, dh)) {
387
+ snap("Fill");
388
+ const clr = pixelEditorTypes.hex2t(e.button === 2 ? col2 : col1);
389
+ const pts = pixelEditorUtils.getSymmetryPoints(p.x, p.y, dw, dh, symmetry);
390
+ const cel = getCel(afi, aLi);
391
+ for (const pt of pts) {
392
+ if (pixelEditorTypes.inB(pt.x, pt.y, dw, dh)) {
393
+ pixelEditorUtils.floodFill(cel, pt.x, pt.y, clr);
394
+ }
395
+ }
396
+ setTick((t) => t + 1);
397
+ }
398
+ break;
399
+ case "eyedropper": {
400
+ if (pixelEditorTypes.inB(p.x, p.y, dw, dh)) {
401
+ const c = pixelEditorUtils.getPixel(getCel(afi, aLi), p.x, p.y);
402
+ const hex = pixelEditorUtils.rgbaToHex(c);
403
+ if (e.button === 2)
404
+ setCol2(hex);
405
+ else
406
+ setCol1(hex);
407
+ }
408
+ break;
409
+ }
410
+ case "line":
411
+ case "rect":
412
+ case "ellipse":
413
+ case "gradient":
414
+ snap(tool[0].toUpperCase() + tool.slice(1));
415
+ drawing.current = true;
416
+ tStart.current = p;
417
+ preview.current = { fr: p, to: p };
418
+ break;
419
+ case "select":
420
+ drawing.current = true;
421
+ tStart.current = p;
422
+ break;
423
+ case "move":
424
+ drawing.current = true;
425
+ lastPx.current = p;
426
+ break;
427
+ }
428
+ }, [tool, aLi, layers, px, py, scr2art, snap, applyBrushAt, getCel, afi, col1, col2, dw, dh, symmetry]);
429
+ const onMove = React.useCallback((e) => {
430
+ const pr = e.pressure > 0 ? e.pressure : 0.5;
431
+ curPressure.current = pr;
432
+ setPressure(pr);
433
+ if (panning.current) {
434
+ setPx(panSt.current.px + (e.clientX - panSt.current.mx));
435
+ setPy(panSt.current.py + (e.clientY - panSt.current.my));
436
+ return;
437
+ }
438
+ const p = scr2art(e.clientX, e.clientY);
439
+ setCursor(p);
440
+ if (!drawing.current)
441
+ return;
442
+ if (tool === "pencil" || tool === "eraser" || tool === "dither") {
443
+ const last = lastPx.current || p;
444
+ const spacing = Math.max(1, brush.size * (brush.spacing / 100));
445
+ const ddx = p.x - last.x, ddy = p.y - last.y;
446
+ const dist = Math.sqrt(ddx * ddx + ddy * ddy);
447
+ if (dist < 0.5)
448
+ return;
449
+ brushDist.current += dist;
450
+ if (brushDist.current >= spacing) {
451
+ pixelEditorUtils.bresenhamLine(last.x, last.y, p.x, p.y, (bx, by) => {
452
+ applyBrushAt(bx, by, tool === "eraser", pr);
453
+ });
454
+ brushDist.current = 0;
455
+ }
456
+ lastPx.current = p;
457
+ setTick((t) => t + 1);
458
+ }
459
+ else if (tool === "line" || tool === "rect" || tool === "ellipse" || tool === "gradient") {
460
+ preview.current = { fr: tStart.current, to: p };
461
+ setTick((t) => t + 1);
462
+ }
463
+ else if (tool === "select") {
464
+ const s = tStart.current;
465
+ setSel({
466
+ x: Math.min(s.x, p.x),
467
+ y: Math.min(s.y, p.y),
468
+ w: Math.abs(p.x - s.x) + 1,
469
+ h: Math.abs(p.y - s.y) + 1,
470
+ });
471
+ }
472
+ else if (tool === "move" && sel) {
473
+ const last2 = lastPx.current || p;
474
+ const ddx = p.x - last2.x, ddy = p.y - last2.y;
475
+ if (ddx !== 0 || ddy !== 0) {
476
+ setSel((prev) => (prev ? { ...prev, x: prev.x + ddx, y: prev.y + ddy } : null));
477
+ }
478
+ lastPx.current = p;
479
+ }
480
+ }, [tool, scr2art, applyBrushAt, brush, sel]);
481
+ const onUp = React.useCallback((e) => {
482
+ if (panning.current) {
483
+ panning.current = false;
484
+ return;
485
+ }
486
+ if (!drawing.current)
487
+ return;
488
+ drawing.current = false;
489
+ const p = scr2art(e.clientX, e.clientY);
490
+ const clr = btn.current === 2 ? pixelEditorTypes.hex2t(col2) : pixelEditorTypes.hex2t(col1);
491
+ if (tool === "line" && tStart.current) {
492
+ const cel = getCel(afi, aLi);
493
+ pixelEditorUtils.getSymmetryPoints(0, 0, dw, dh, symmetry);
494
+ if (symmetry === "none") {
495
+ pixelEditorUtils.bresenhamLine(tStart.current.x, tStart.current.y, p.x, p.y, (bx, by) => {
496
+ if (pixelEditorTypes.inB(bx, by, dw, dh))
497
+ pixelEditorUtils.setPixel(cel, bx, by, clr);
498
+ });
499
+ }
500
+ else {
501
+ const fromPts = pixelEditorUtils.getSymmetryPoints(tStart.current.x, tStart.current.y, dw, dh, symmetry);
502
+ const toPts = pixelEditorUtils.getSymmetryPoints(p.x, p.y, dw, dh, symmetry);
503
+ for (let i = 0; i < fromPts.length; i++) {
504
+ pixelEditorUtils.bresenhamLine(fromPts[i].x, fromPts[i].y, toPts[i].x, toPts[i].y, (bx, by) => {
505
+ if (pixelEditorTypes.inB(bx, by, dw, dh))
506
+ pixelEditorUtils.setPixel(cel, bx, by, clr);
507
+ });
508
+ }
509
+ }
510
+ preview.current = null;
511
+ setTick((t) => t + 1);
512
+ }
513
+ else if (tool === "rect" && tStart.current) {
514
+ const cel = getCel(afi, aLi);
515
+ const x1 = Math.min(tStart.current.x, p.x), y1 = Math.min(tStart.current.y, p.y);
516
+ const x2 = Math.max(tStart.current.x, p.x), y2 = Math.max(tStart.current.y, p.y);
517
+ if (shapeFilled) {
518
+ for (let y = y1; y <= y2; y++)
519
+ for (let x = x1; x <= x2; x++)
520
+ if (pixelEditorTypes.inB(x, y, dw, dh))
521
+ pixelEditorUtils.setPixel(cel, x, y, clr);
522
+ }
523
+ else {
524
+ for (let x = x1; x <= x2; x++) {
525
+ if (pixelEditorTypes.inB(x, y1, dw, dh))
526
+ pixelEditorUtils.setPixel(cel, x, y1, clr);
527
+ if (pixelEditorTypes.inB(x, y2, dw, dh))
528
+ pixelEditorUtils.setPixel(cel, x, y2, clr);
529
+ }
530
+ for (let y = y1 + 1; y < y2; y++) {
531
+ if (pixelEditorTypes.inB(x1, y, dw, dh))
532
+ pixelEditorUtils.setPixel(cel, x1, y, clr);
533
+ if (pixelEditorTypes.inB(x2, y, dw, dh))
534
+ pixelEditorUtils.setPixel(cel, x2, y, clr);
535
+ }
536
+ }
537
+ preview.current = null;
538
+ setTick((t) => t + 1);
539
+ }
540
+ else if (tool === "ellipse" && tStart.current) {
541
+ const cel = getCel(afi, aLi);
542
+ const cx2 = (tStart.current.x + p.x) / 2;
543
+ const cy2 = (tStart.current.y + p.y) / 2;
544
+ const rx = Math.abs(p.x - tStart.current.x) / 2;
545
+ const ry = Math.abs(p.y - tStart.current.y) / 2;
546
+ pixelEditorTypes.plotEllipse(cel, cx2, cy2, rx, ry, clr, dw, dh, shapeFilled);
547
+ preview.current = null;
548
+ setTick((t) => t + 1);
549
+ }
550
+ else if (tool === "gradient" && tStart.current) {
551
+ const cel = getCel(afi, aLi);
552
+ const c2 = btn.current === 2 ? pixelEditorTypes.hex2t(col1) : pixelEditorTypes.hex2t(col2);
553
+ pixelEditorUtils.drawGradient(cel, tStart.current.x, tStart.current.y, p.x, p.y, clr, c2, sel);
554
+ preview.current = null;
555
+ setTick((t) => t + 1);
556
+ }
557
+ lastPx.current = null;
558
+ tStart.current = null;
559
+ }, [tool, scr2art, getCel, afi, aLi, col1, col2, dw, dh, shapeFilled, symmetry, sel]);
560
+ const onWheel = React.useCallback((e) => {
561
+ e.preventDefault();
562
+ setZoom((z) => {
563
+ const n = e.deltaY < 0 ? z * 1.2 : z / 1.2;
564
+ return Math.max(0.5, Math.min(64, n));
565
+ });
566
+ }, []);
567
+ /* ── clipboard operations ── */
568
+ const doCopy = React.useCallback(() => {
569
+ if (!sel)
570
+ return;
571
+ clipboard.current = pixelEditorUtils.copySelection(getCel(afi, aLi), sel);
572
+ }, [sel, getCel, afi, aLi]);
573
+ const doCut = React.useCallback(() => {
574
+ if (!sel)
575
+ return;
576
+ snap("Cut");
577
+ const cel = getCel(afi, aLi);
578
+ clipboard.current = pixelEditorUtils.copySelection(cel, sel);
579
+ pixelEditorUtils.clearSelection(cel, sel);
580
+ setTick((t) => t + 1);
581
+ }, [sel, getCel, afi, aLi, snap]);
582
+ const doPaste = React.useCallback(() => {
583
+ var _a, _b;
584
+ if (!clipboard.current)
585
+ return;
586
+ snap("Paste");
587
+ const cel = getCel(afi, aLi);
588
+ pixelEditorUtils.pasteAt(cel, clipboard.current, (_a = sel === null || sel === void 0 ? void 0 : sel.x) !== null && _a !== void 0 ? _a : 0, (_b = sel === null || sel === void 0 ? void 0 : sel.y) !== null && _b !== void 0 ? _b : 0);
589
+ setTick((t) => t + 1);
590
+ }, [getCel, afi, aLi, snap, sel]);
591
+ const doDeleteSel = React.useCallback(() => {
592
+ if (!sel)
593
+ return;
594
+ snap("Delete Selection");
595
+ pixelEditorUtils.clearSelection(getCel(afi, aLi), sel);
596
+ setTick((t) => t + 1);
597
+ }, [sel, getCel, afi, aLi, snap]);
598
+ const doSelectAll = React.useCallback(() => {
599
+ setSel({ x: 0, y: 0, w: dw, h: dh });
600
+ }, [dw, dh]);
601
+ const doDeselectAll = React.useCallback(() => {
602
+ setSel(null);
603
+ }, []);
604
+ /* ── file I/O ── */
605
+ const loadAseDoc = React.useCallback((doc) => {
606
+ setDw(doc.width);
607
+ setDh(doc.height);
608
+ cels.current = new Map();
609
+ const lrs = doc.layers.map((l, i) => ({
610
+ id: pixelEditorTypes.lid(),
611
+ name: l.name || `Layer ${i + 1}`,
612
+ visible: l.visible,
613
+ opacity: l.opacity,
614
+ locked: false,
615
+ blendMode: "normal",
616
+ }));
617
+ setLayers(lrs.length
618
+ ? lrs
619
+ : [{ id: pixelEditorTypes.lid(), name: "Layer 1", visible: true, opacity: 255, locked: false, blendMode: "normal" }]);
620
+ setALi(0);
621
+ setFc(doc.frames.length || 1);
622
+ setAfi(0);
623
+ setFDur(doc.frames.map((f) => f.duration || 100));
624
+ doc.frames.forEach((frame, fi) => {
625
+ frame.cels.forEach((cel) => {
626
+ const data = pixelEditorUtils.createBlankImageData(doc.width, doc.height);
627
+ if (cel.pixels && cel.width > 0 && cel.height > 0) {
628
+ for (let y = 0; y < cel.height; y++)
629
+ for (let x = 0; x < cel.width; x++) {
630
+ const dx = cel.x + x, dy = cel.y + y;
631
+ if (dx >= 0 && dy >= 0 && dx < doc.width && dy < doc.height) {
632
+ const si = (y * cel.width + x) * 4;
633
+ pixelEditorUtils.setPixel(data, dx, dy, [
634
+ cel.pixels[si], cel.pixels[si + 1], cel.pixels[si + 2], cel.pixels[si + 3],
635
+ ]);
636
+ }
637
+ }
638
+ }
639
+ cels.current.set(pixelEditorTypes.celKey(fi, cel.layerIndex), data);
640
+ });
641
+ });
642
+ if (doc.palette.length)
643
+ setPal(doc.palette.map(asepriteFormat.aseColorToHex));
644
+ setZoom(Math.max(1, Math.floor(Math.min(512 / doc.width, 512 / doc.height))));
645
+ setPx(0);
646
+ setPy(0);
647
+ hist.current = [];
648
+ hIdx.current = -1;
649
+ setTick((t) => t + 1);
650
+ }, []);
651
+ const openFile = React.useCallback(async (file) => {
652
+ if (file.name.match(/\.ase(prite)?$/i)) {
653
+ try {
654
+ const doc = await asepriteFormat.parseAseFile(await file.arrayBuffer());
655
+ loadAseDoc(doc);
656
+ }
657
+ catch (err) {
658
+ log.error("ASE parse error", err);
659
+ alert("Failed to parse Aseprite file.");
660
+ }
661
+ }
662
+ else {
663
+ const img = new Image();
664
+ img.onload = () => {
665
+ const w2 = img.naturalWidth, h2 = img.naturalHeight;
666
+ const cv = new OffscreenCanvas(w2, h2);
667
+ cv.getContext("2d").drawImage(img, 0, 0);
668
+ const data = cv.getContext("2d").getImageData(0, 0, w2, h2);
669
+ setDw(w2);
670
+ setDh(h2);
671
+ cels.current = new Map([[pixelEditorTypes.celKey(0, 0), data]]);
672
+ setLayers([{ id: pixelEditorTypes.lid(), name: "Layer 1", visible: true, opacity: 255, locked: false, blendMode: "normal" }]);
673
+ setALi(0);
674
+ setFc(1);
675
+ setAfi(0);
676
+ setFDur([100]);
677
+ setZoom(Math.max(1, Math.floor(Math.min(512 / w2, 512 / h2))));
678
+ setPx(0);
679
+ setPy(0);
680
+ hist.current = [];
681
+ hIdx.current = -1;
682
+ setTick((t) => t + 1);
683
+ };
684
+ img.src = URL.createObjectURL(file);
685
+ }
686
+ }, [loadAseDoc]);
687
+ const exportAse = React.useCallback(async () => {
688
+ await pixelEditorExports.exportAse({ dw, dh, layers, fc, fDur, pal, cels: cels.current });
689
+ }, [dw, dh, layers, fc, fDur, pal]);
690
+ const exportPNG = React.useCallback(() => {
691
+ pixelEditorExports.exportPNG(afi, dw, dh, compFrame);
692
+ }, [afi, dw, dh, compFrame]);
693
+ const exportJPG = React.useCallback(() => {
694
+ pixelEditorExports.exportJPG(afi, dw, dh, compFrame);
695
+ }, [afi, dw, dh, compFrame]);
696
+ const exportWebP = React.useCallback(() => {
697
+ pixelEditorExports.exportWebP(afi, dw, dh, compFrame);
698
+ }, [afi, dw, dh, compFrame]);
699
+ const exportBMP = React.useCallback(() => {
700
+ pixelEditorExports.exportBMP(afi, dw, dh, compFrame);
701
+ }, [afi, dw, dh, compFrame]);
702
+ const exportSVG = React.useCallback(() => {
703
+ pixelEditorExports.exportSVG(afi, dw, dh, compFrame);
704
+ }, [afi, dw, dh, compFrame]);
705
+ const exportSheet = React.useCallback(() => {
706
+ pixelEditorExports.exportSheet(dw, dh, fc, compFrame);
707
+ }, [dw, dh, fc, compFrame]);
708
+ /* ── save to library ── */
709
+ const saveToLibrary = React.useCallback(() => {
710
+ if (!onSaveToLibrary)
711
+ return;
712
+ const data = compFrame(afi);
713
+ const cv = document.createElement("canvas");
714
+ cv.width = dw;
715
+ cv.height = dh;
716
+ cv.getContext("2d").putImageData(data, 0, 0);
717
+ const dataUrl = cv.toDataURL("image/png");
718
+ const defaultName = `sprite-${dw}x${dh}.png`;
719
+ const name = window.prompt("Save to library as:", defaultName);
720
+ if (!name || !name.trim())
721
+ return;
722
+ onSaveToLibrary(dataUrl, name.trim(), "image/png");
723
+ }, [onSaveToLibrary, afi, dw, dh, compFrame]);
724
+ /* ── layer management ── */
725
+ const addLayer = React.useCallback(() => {
726
+ snap("Add Layer");
727
+ setLayers((ls) => [
728
+ ...ls,
729
+ { id: pixelEditorTypes.lid(), name: `Layer ${ls.length + 1}`, visible: true, opacity: 255, locked: false, blendMode: "normal" },
730
+ ]);
731
+ setALi(layers.length);
732
+ setTick((t) => t + 1);
733
+ }, [layers, snap]);
734
+ const rmLayer = React.useCallback(() => {
735
+ if (layers.length <= 1)
736
+ return;
737
+ snap("Remove Layer");
738
+ const idx = aLi;
739
+ for (let fi = 0; fi < fc; fi++) {
740
+ cels.current.delete(pixelEditorTypes.celKey(fi, idx));
741
+ for (let li = idx + 1; li < layers.length; li++) {
742
+ const c = cels.current.get(pixelEditorTypes.celKey(fi, li));
743
+ if (c) {
744
+ cels.current.set(pixelEditorTypes.celKey(fi, li - 1), c);
745
+ cels.current.delete(pixelEditorTypes.celKey(fi, li));
746
+ }
747
+ }
748
+ }
749
+ setLayers((ls) => ls.filter((_, i) => i !== idx));
750
+ setALi(Math.min(idx, layers.length - 2));
751
+ setTick((t) => t + 1);
752
+ }, [layers, aLi, fc, snap]);
753
+ const toggleVis = React.useCallback((i) => {
754
+ setLayers((ls) => ls.map((l, j) => (j === i ? { ...l, visible: !l.visible } : l)));
755
+ setTick((t) => t + 1);
756
+ }, []);
757
+ const toggleLock = React.useCallback((i) => {
758
+ setLayers((ls) => ls.map((l, j) => (j === i ? { ...l, locked: !l.locked } : l)));
759
+ }, []);
760
+ const setLayerOpacity = React.useCallback((i, op) => {
761
+ setLayers((ls) => ls.map((l, j) => (j === i ? { ...l, opacity: op } : l)));
762
+ setTick((t) => t + 1);
763
+ }, []);
764
+ const setLayerBlendMode = React.useCallback((i, mode) => {
765
+ setLayers((ls) => ls.map((l, j) => (j === i ? { ...l, blendMode: mode } : l)));
766
+ setTick((t) => t + 1);
767
+ }, []);
768
+ const renameLayer = React.useCallback((i, name) => {
769
+ setLayers((ls) => ls.map((l, j) => (j === i ? { ...l, name } : l)));
770
+ }, []);
771
+ const moveLayerUp = React.useCallback(() => {
772
+ if (aLi >= layers.length - 1)
773
+ return;
774
+ snap("Move Layer Up");
775
+ setLayers((ls) => {
776
+ const n = [...ls];
777
+ [n[aLi], n[aLi + 1]] = [n[aLi + 1], n[aLi]];
778
+ return n;
779
+ });
780
+ for (let fi = 0; fi < fc; fi++) {
781
+ const a = cels.current.get(pixelEditorTypes.celKey(fi, aLi));
782
+ const b = cels.current.get(pixelEditorTypes.celKey(fi, aLi + 1));
783
+ if (a)
784
+ cels.current.set(pixelEditorTypes.celKey(fi, aLi + 1), a);
785
+ else
786
+ cels.current.delete(pixelEditorTypes.celKey(fi, aLi + 1));
787
+ if (b)
788
+ cels.current.set(pixelEditorTypes.celKey(fi, aLi), b);
789
+ else
790
+ cels.current.delete(pixelEditorTypes.celKey(fi, aLi));
791
+ }
792
+ setALi(aLi + 1);
793
+ setTick((t) => t + 1);
794
+ }, [aLi, layers, fc, snap]);
795
+ const moveLayerDown = React.useCallback(() => {
796
+ if (aLi <= 0)
797
+ return;
798
+ snap("Move Layer Down");
799
+ setLayers((ls) => {
800
+ const n = [...ls];
801
+ [n[aLi], n[aLi - 1]] = [n[aLi - 1], n[aLi]];
802
+ return n;
803
+ });
804
+ for (let fi = 0; fi < fc; fi++) {
805
+ const a = cels.current.get(pixelEditorTypes.celKey(fi, aLi));
806
+ const b = cels.current.get(pixelEditorTypes.celKey(fi, aLi - 1));
807
+ if (a)
808
+ cels.current.set(pixelEditorTypes.celKey(fi, aLi - 1), a);
809
+ else
810
+ cels.current.delete(pixelEditorTypes.celKey(fi, aLi - 1));
811
+ if (b)
812
+ cels.current.set(pixelEditorTypes.celKey(fi, aLi), b);
813
+ else
814
+ cels.current.delete(pixelEditorTypes.celKey(fi, aLi));
815
+ }
816
+ setALi(aLi - 1);
817
+ setTick((t) => t + 1);
818
+ }, [aLi, fc, snap]);
819
+ const mergeDown = React.useCallback(() => {
820
+ if (aLi <= 0)
821
+ return;
822
+ snap("Merge Down");
823
+ for (let fi = 0; fi < fc; fi++) {
824
+ const top = cels.current.get(pixelEditorTypes.celKey(fi, aLi));
825
+ const bot = getCel(fi, aLi - 1);
826
+ if (top) {
827
+ const cv = new OffscreenCanvas(dw, dh);
828
+ const ctx = cv.getContext("2d");
829
+ ctx.putImageData(bot, 0, 0);
830
+ const t = new OffscreenCanvas(dw, dh);
831
+ t.getContext("2d").putImageData(top, 0, 0);
832
+ ctx.globalAlpha = layers[aLi].opacity / 255;
833
+ ctx.drawImage(t, 0, 0);
834
+ cels.current.set(pixelEditorTypes.celKey(fi, aLi - 1), ctx.getImageData(0, 0, dw, dh));
835
+ }
836
+ }
837
+ for (let fi = 0; fi < fc; fi++) {
838
+ cels.current.delete(pixelEditorTypes.celKey(fi, aLi));
839
+ for (let li = aLi + 1; li < layers.length; li++) {
840
+ const c = cels.current.get(pixelEditorTypes.celKey(fi, li));
841
+ if (c) {
842
+ cels.current.set(pixelEditorTypes.celKey(fi, li - 1), c);
843
+ cels.current.delete(pixelEditorTypes.celKey(fi, li));
844
+ }
845
+ }
846
+ }
847
+ setLayers((ls) => ls.filter((_, i) => i !== aLi));
848
+ setALi(aLi - 1);
849
+ setTick((t) => t + 1);
850
+ }, [aLi, fc, layers, getCel, dw, dh, snap]);
851
+ const dupLayer = React.useCallback(() => {
852
+ snap("Duplicate Layer");
853
+ const newL = { ...layers[aLi], id: pixelEditorTypes.lid(), name: layers[aLi].name + " copy" };
854
+ setLayers((ls) => [...ls.slice(0, aLi + 1), newL, ...ls.slice(aLi + 1)]);
855
+ for (let fi = 0; fi < fc; fi++) {
856
+ for (let li = layers.length; li > aLi; li--) {
857
+ const c = cels.current.get(pixelEditorTypes.celKey(fi, li));
858
+ if (c) {
859
+ cels.current.set(pixelEditorTypes.celKey(fi, li + 1), c);
860
+ cels.current.delete(pixelEditorTypes.celKey(fi, li));
861
+ }
862
+ }
863
+ const src = cels.current.get(pixelEditorTypes.celKey(fi, aLi));
864
+ if (src)
865
+ cels.current.set(pixelEditorTypes.celKey(fi, aLi + 1), pixelEditorUtils.cloneImageData(src));
866
+ }
867
+ setALi(aLi + 1);
868
+ setTick((t) => t + 1);
869
+ }, [aLi, layers, fc, snap]);
870
+ /* ── frame management ── */
871
+ const addFrame = React.useCallback(() => {
872
+ snap("Add Frame");
873
+ setFc((n) => n + 1);
874
+ setFDur((d) => [...d, 100]);
875
+ setAfi(fc);
876
+ setTick((t) => t + 1);
877
+ }, [fc, snap]);
878
+ const dupFrame = React.useCallback(() => {
879
+ snap("Dup Frame");
880
+ const ni = fc;
881
+ for (let li = 0; li < layers.length; li++) {
882
+ const c = cels.current.get(pixelEditorTypes.celKey(afi, li));
883
+ if (c)
884
+ cels.current.set(pixelEditorTypes.celKey(ni, li), pixelEditorUtils.cloneImageData(c));
885
+ }
886
+ setFc((n) => n + 1);
887
+ setFDur((d) => [...d, fDur[afi] || 100]);
888
+ setAfi(ni);
889
+ setTick((t) => t + 1);
890
+ }, [fc, afi, layers, fDur, snap]);
891
+ const rmFrame = React.useCallback(() => {
892
+ if (fc <= 1)
893
+ return;
894
+ snap("Remove Frame");
895
+ for (let li = 0; li < layers.length; li++) {
896
+ cels.current.delete(pixelEditorTypes.celKey(afi, li));
897
+ for (let f = afi + 1; f < fc; f++) {
898
+ const c = cels.current.get(pixelEditorTypes.celKey(f, li));
899
+ if (c) {
900
+ cels.current.set(pixelEditorTypes.celKey(f - 1, li), c);
901
+ cels.current.delete(pixelEditorTypes.celKey(f, li));
902
+ }
903
+ }
904
+ }
905
+ setFc((n) => n - 1);
906
+ setFDur((d) => d.filter((_, i) => i !== afi));
907
+ setAfi(Math.min(afi, fc - 2));
908
+ setTick((t) => t + 1);
909
+ }, [fc, afi, layers, snap]);
910
+ /* ── canvas ops ── */
911
+ const flipCv = React.useCallback((dir) => {
912
+ snap(`Flip ${dir === "h" ? "H" : "V"}`);
913
+ cels.current.forEach((c, k) => cels.current.set(k, dir === "h" ? pixelEditorUtils.flipH(c) : pixelEditorUtils.flipV(c)));
914
+ setTick((t) => t + 1);
915
+ }, [snap]);
916
+ const rotateCv = React.useCallback(() => {
917
+ snap("Rotate 90°");
918
+ const n = new Map();
919
+ cels.current.forEach((c, k) => n.set(k, pixelEditorUtils.rotateCW(c)));
920
+ cels.current = n;
921
+ setDw(dh);
922
+ setDh(dw);
923
+ setTick((t) => t + 1);
924
+ }, [dw, dh, snap]);
925
+ const clearCv = React.useCallback(() => {
926
+ snap("Clear");
927
+ cels.current.set(pixelEditorTypes.celKey(afi, aLi), pixelEditorUtils.createBlankImageData(dw, dh));
928
+ setTick((t) => t + 1);
929
+ }, [afi, aLi, dw, dh, snap]);
930
+ const newDoc = React.useCallback((w, h) => {
931
+ setDw(w);
932
+ setDh(h);
933
+ cels.current = new Map();
934
+ setLayers([{ id: pixelEditorTypes.lid(), name: "Background", visible: true, opacity: 255, locked: false, blendMode: "normal" }]);
935
+ setALi(0);
936
+ setFc(1);
937
+ setAfi(0);
938
+ setFDur([100]);
939
+ setSel(null);
940
+ setZoom(Math.max(1, Math.floor(Math.min(512 / w, 512 / h))));
941
+ setPx(0);
942
+ setPy(0);
943
+ hist.current = [];
944
+ hIdx.current = -1;
945
+ setDlgNew(false);
946
+ setTick((t) => t + 1);
947
+ }, []);
948
+ /* ── effects ── */
949
+ // render every tick / state change
950
+ React.useEffect(() => {
951
+ render();
952
+ });
953
+ // keyboard shortcuts
954
+ React.useEffect(() => {
955
+ const h = (e) => {
956
+ if (dlgNew)
957
+ return;
958
+ const tgt = e.target;
959
+ if (tgt.tagName === "INPUT" || tgt.tagName === "TEXTAREA" || tgt.tagName === "SELECT")
960
+ return;
961
+ if (e.ctrlKey && e.key === "z") {
962
+ e.preventDefault();
963
+ undo();
964
+ return;
965
+ }
966
+ if (e.ctrlKey && (e.key === "y" || (e.shiftKey && e.key === "Z"))) {
967
+ e.preventDefault();
968
+ redo();
969
+ return;
970
+ }
971
+ if (e.ctrlKey && e.key === "c") {
972
+ e.preventDefault();
973
+ doCopy();
974
+ return;
975
+ }
976
+ if (e.ctrlKey && e.key === "x") {
977
+ e.preventDefault();
978
+ doCut();
979
+ return;
980
+ }
981
+ if (e.ctrlKey && e.key === "v") {
982
+ e.preventDefault();
983
+ doPaste();
984
+ return;
985
+ }
986
+ if (e.ctrlKey && e.key === "a") {
987
+ e.preventDefault();
988
+ doSelectAll();
989
+ return;
990
+ }
991
+ if (e.ctrlKey && e.key === "d") {
992
+ e.preventDefault();
993
+ doDeselectAll();
994
+ return;
995
+ }
996
+ const km = {
997
+ b: "pencil", e: "eraser", g: "fill", l: "line", u: "rect",
998
+ o: "ellipse", i: "eyedropper", m: "select", v: "move", h: "gradient", d: "dither",
999
+ };
1000
+ const k = e.key.toLowerCase();
1001
+ if (km[k]) {
1002
+ setTool(km[k]);
1003
+ return;
1004
+ }
1005
+ switch (k) {
1006
+ case "+":
1007
+ case "=":
1008
+ setZoom((z) => Math.min(64, z * 1.5));
1009
+ break;
1010
+ case "-":
1011
+ setZoom((z) => Math.max(0.5, z / 1.5));
1012
+ break;
1013
+ case "arrowleft":
1014
+ setAfi((f) => Math.max(0, f - 1));
1015
+ break;
1016
+ case "arrowright":
1017
+ setAfi((f) => Math.min(fc - 1, f + 1));
1018
+ break;
1019
+ case "n":
1020
+ if (!e.ctrlKey)
1021
+ addFrame();
1022
+ break;
1023
+ case "delete":
1024
+ if (sel)
1025
+ doDeleteSel();
1026
+ else
1027
+ clearCv();
1028
+ break;
1029
+ case "x": {
1030
+ setCol1((c) => { setCol2(c); return col2; });
1031
+ break;
1032
+ }
1033
+ case "[":
1034
+ setBrush((b) => ({ ...b, size: Math.max(1, b.size - 1) }));
1035
+ break;
1036
+ case "]":
1037
+ setBrush((b) => ({ ...b, size: Math.min(64, b.size + 1) }));
1038
+ break;
1039
+ case "f":
1040
+ setShapeFilled((f) => !f);
1041
+ break;
1042
+ }
1043
+ };
1044
+ window.addEventListener("keydown", h);
1045
+ return () => window.removeEventListener("keydown", h);
1046
+ }, [dlgNew, undo, redo, fc, addFrame, clearCv, col2, doCopy, doCut, doPaste, doSelectAll, doDeselectAll, doDeleteSel, sel]);
1047
+ // animation playback
1048
+ React.useEffect(() => {
1049
+ if (!playing)
1050
+ return;
1051
+ const iv = setInterval(() => setAfi((f) => (f + 1) % fc), 1000 / fps);
1052
+ return () => clearInterval(iv);
1053
+ }, [playing, fc, fps]);
1054
+ // resize observer
1055
+ React.useEffect(() => {
1056
+ const el = boxRef.current;
1057
+ if (!el)
1058
+ return;
1059
+ const obs = new ResizeObserver(() => setTick((t) => t + 1));
1060
+ obs.observe(el);
1061
+ return () => obs.disconnect();
1062
+ }, []);
1063
+ /* ── frame thumbnails ── */
1064
+ const thumbs = React.useMemo(() => {
1065
+ const out = [];
1066
+ for (let fi = 0; fi < fc; fi++) {
1067
+ const cv = document.createElement("canvas");
1068
+ cv.width = dw;
1069
+ cv.height = dh;
1070
+ const ctx = cv.getContext("2d");
1071
+ for (let li = 0; li < layers.length; li++) {
1072
+ if (!layers[li].visible)
1073
+ continue;
1074
+ const c = cels.current.get(pixelEditorTypes.celKey(fi, li));
1075
+ if (!c)
1076
+ continue;
1077
+ const t = document.createElement("canvas");
1078
+ t.width = dw;
1079
+ t.height = dh;
1080
+ t.getContext("2d").putImageData(c, 0, 0);
1081
+ ctx.globalAlpha = layers[li].opacity / 255;
1082
+ ctx.drawImage(t, 0, 0);
1083
+ }
1084
+ out.push(cv.toDataURL());
1085
+ }
1086
+ return out;
1087
+ }, [fc, dw, dh, layers, tick]);
1088
+ /* ── return API ── */
1089
+ return {
1090
+ dw, dh, layers, aLi, setALi, fc, afi, setAfi, fDur,
1091
+ tool, setTool, col1, setCol1, col2, setCol2,
1092
+ brush, setBrush, zoom, setZoom, grid, setGrid, onion, setOnion,
1093
+ fps, setFps, playing, setPlaying, pal, setPal,
1094
+ cursor, setCursor, dlgNew, setDlgNew, nw, setNw, nh, setNh,
1095
+ sel, setSel, symmetry, setSymmetry, shapeFilled, setShapeFilled,
1096
+ pressure, showHSV, setShowHSV, editingLayerName, setEditingLayerName,
1097
+ cvRef, boxRef, fInp, clipboard, drawing, panning,
1098
+ undo, redo, openFile,
1099
+ exportAse, exportPNG, exportJPG, exportWebP, exportBMP, exportSVG, exportSheet,
1100
+ saveToLibrary,
1101
+ addLayer, rmLayer, toggleVis, toggleLock, setLayerOpacity, setLayerBlendMode,
1102
+ renameLayer, moveLayerUp, moveLayerDown, mergeDown, dupLayer,
1103
+ addFrame, dupFrame, rmFrame,
1104
+ flipCv, rotateCv, clearCv, newDoc,
1105
+ doCopy, doCut, doPaste, doDeleteSel, doSelectAll, doDeselectAll,
1106
+ onDown, onMove, onUp, onWheel,
1107
+ thumbs,
1108
+ };
1109
+ }
1110
+
1111
+ exports.usePixelEditor = usePixelEditor;
1112
+ //# sourceMappingURL=usePixelEditor.js.map