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